id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
30,700
BKWLD/decoy
classes/Observers/ManyToManyChecklist.php
ManyToManyChecklist.updateRelationship
private function updateRelationship($model, $relationship) { // Make sure the relationship exists on the model. This also prevents the // wrong model (who might also have an `saved` callback) from trying to have // this data saved on it if (!method_exists($model, $relationship)) { return; } // Strip all the "0"s from the input. These exist because push checkboxes // is globally set for all of Decoy; $ids = request(self::PREFIX.$relationship); $ids = array_filter($ids, function ($id) { return $id > 0; }); // Allow a single listener to transform the list of ids to, for instance, // add pivot data. $prefix = 'decoy::many-to-many-checklist.'; if ($mutated = Event::until($prefix."syncing: $relationship", [$ids])) { $ids = $mutated; } // Attach just the ones mentioned in the input. This blows away the // previous joins $model->$relationship()->sync($ids); // Fire completion event Event::fire($prefix."synced: $relationship"); }
php
private function updateRelationship($model, $relationship) { // Make sure the relationship exists on the model. This also prevents the // wrong model (who might also have an `saved` callback) from trying to have // this data saved on it if (!method_exists($model, $relationship)) { return; } // Strip all the "0"s from the input. These exist because push checkboxes // is globally set for all of Decoy; $ids = request(self::PREFIX.$relationship); $ids = array_filter($ids, function ($id) { return $id > 0; }); // Allow a single listener to transform the list of ids to, for instance, // add pivot data. $prefix = 'decoy::many-to-many-checklist.'; if ($mutated = Event::until($prefix."syncing: $relationship", [$ids])) { $ids = $mutated; } // Attach just the ones mentioned in the input. This blows away the // previous joins $model->$relationship()->sync($ids); // Fire completion event Event::fire($prefix."synced: $relationship"); }
[ "private", "function", "updateRelationship", "(", "$", "model", ",", "$", "relationship", ")", "{", "// Make sure the relationship exists on the model. This also prevents the", "// wrong model (who might also have an `saved` callback) from trying to have", "// this data saved on it", "if", "(", "!", "method_exists", "(", "$", "model", ",", "$", "relationship", ")", ")", "{", "return", ";", "}", "// Strip all the \"0\"s from the input. These exist because push checkboxes", "// is globally set for all of Decoy;", "$", "ids", "=", "request", "(", "self", "::", "PREFIX", ".", "$", "relationship", ")", ";", "$", "ids", "=", "array_filter", "(", "$", "ids", ",", "function", "(", "$", "id", ")", "{", "return", "$", "id", ">", "0", ";", "}", ")", ";", "// Allow a single listener to transform the list of ids to, for instance,", "// add pivot data.", "$", "prefix", "=", "'decoy::many-to-many-checklist.'", ";", "if", "(", "$", "mutated", "=", "Event", "::", "until", "(", "$", "prefix", ".", "\"syncing: $relationship\"", ",", "[", "$", "ids", "]", ")", ")", "{", "$", "ids", "=", "$", "mutated", ";", "}", "// Attach just the ones mentioned in the input. This blows away the", "// previous joins", "$", "model", "->", "$", "relationship", "(", ")", "->", "sync", "(", "$", "ids", ")", ";", "// Fire completion event", "Event", "::", "fire", "(", "$", "prefix", ".", "\"synced: $relationship\"", ")", ";", "}" ]
Process a particular input instance @param Bkwld\Decoy\Models\Base $model A model instance @param string $relationship The relationship name
[ "Process", "a", "particular", "input", "instance" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Observers/ManyToManyChecklist.php#L46-L75
30,701
BKWLD/decoy
classes/Input/ModelValidator.php
ModelValidator.validate
public function validate(BaseModel $model, $rules = null, $messages = []) { return $this->validateAndPrefixErrors(null, $model, $rules, $messages); }
php
public function validate(BaseModel $model, $rules = null, $messages = []) { return $this->validateAndPrefixErrors(null, $model, $rules, $messages); }
[ "public", "function", "validate", "(", "BaseModel", "$", "model", ",", "$", "rules", "=", "null", ",", "$", "messages", "=", "[", "]", ")", "{", "return", "$", "this", "->", "validateAndPrefixErrors", "(", "null", ",", "$", "model", ",", "$", "rules", ",", "$", "messages", ")", ";", "}" ]
Validate a model, firing Decoy events @param BaseModel $data @param array $rules A Laravel rules array. If null, will be pulled from model @param array $messages Special error messages @return Validator
[ "Validate", "a", "model", "firing", "Decoy", "events" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/ModelValidator.php#L25-L28
30,702
BKWLD/decoy
classes/Input/ModelValidator.php
ModelValidator.handleImageRules
public function handleImageRules($model, $rules) { // If the model is an image, the rules were passed in by NestedModels // and are good to go if (is_a($model, Image::class)) { return $rules; } // Otherwise, remove any image rules because this is a non-Image and // these rules will get applied by NestedModels return array_where($rules, function ($val, $key) { return !starts_with($key, 'images.'); }); }
php
public function handleImageRules($model, $rules) { // If the model is an image, the rules were passed in by NestedModels // and are good to go if (is_a($model, Image::class)) { return $rules; } // Otherwise, remove any image rules because this is a non-Image and // these rules will get applied by NestedModels return array_where($rules, function ($val, $key) { return !starts_with($key, 'images.'); }); }
[ "public", "function", "handleImageRules", "(", "$", "model", ",", "$", "rules", ")", "{", "// If the model is an image, the rules were passed in by NestedModels", "// and are good to go", "if", "(", "is_a", "(", "$", "model", ",", "Image", "::", "class", ")", ")", "{", "return", "$", "rules", ";", "}", "// Otherwise, remove any image rules because this is a non-Image and", "// these rules will get applied by NestedModels", "return", "array_where", "(", "$", "rules", ",", "function", "(", "$", "val", ",", "$", "key", ")", "{", "return", "!", "starts_with", "(", "$", "key", ",", "'images.'", ")", ";", "}", ")", ";", "}" ]
Handle the Images feature, which is special because you define the rules on the parent model. @param BaseModel $data @param array $rules A Laravel rules array. If null, will be pulled from model @return array
[ "Handle", "the", "Images", "feature", "which", "is", "special", "because", "you", "define", "the", "rules", "on", "the", "parent", "model", "." ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/ModelValidator.php#L96-L110
30,703
BKWLD/decoy
classes/Input/ModelValidator.php
ModelValidator.nestArray
public function nestArray($prefix, $array) { $data = []; foreach($array as $key => $value) { array_set($data, $prefix.$key, $value); } return $data; }
php
public function nestArray($prefix, $array) { $data = []; foreach($array as $key => $value) { array_set($data, $prefix.$key, $value); } return $data; }
[ "public", "function", "nestArray", "(", "$", "prefix", ",", "$", "array", ")", "{", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "array_set", "(", "$", "data", ",", "$", "prefix", ".", "$", "key", ",", "$", "value", ")", ";", "}", "return", "$", "data", ";", "}" ]
Nest an array at another depth using the prefix @param string $prefix @param array $array @return array
[ "Nest", "an", "array", "at", "another", "depth", "using", "the", "prefix" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/ModelValidator.php#L119-L126
30,704
BKWLD/decoy
classes/Input/ModelValidator.php
ModelValidator.prefixArrayKeys
public function prefixArrayKeys($prefix, $array) { return array_combine(array_map(function ($key) use ($prefix) { return $prefix.$key; }, array_keys($array)), array_values($array)); }
php
public function prefixArrayKeys($prefix, $array) { return array_combine(array_map(function ($key) use ($prefix) { return $prefix.$key; }, array_keys($array)), array_values($array)); }
[ "public", "function", "prefixArrayKeys", "(", "$", "prefix", ",", "$", "array", ")", "{", "return", "array_combine", "(", "array_map", "(", "function", "(", "$", "key", ")", "use", "(", "$", "prefix", ")", "{", "return", "$", "prefix", ".", "$", "key", ";", "}", ",", "array_keys", "(", "$", "array", ")", ")", ",", "array_values", "(", "$", "array", ")", ")", ";", "}" ]
Apply a prefix to the keys of an array @param string $prefix @param array $array @return array
[ "Apply", "a", "prefix", "to", "the", "keys", "of", "an", "array" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/ModelValidator.php#L135-L140
30,705
BKWLD/decoy
classes/Input/ModelValidator.php
ModelValidator.removePrefixFromMessages
protected function removePrefixFromMessages($prefix, $validator) { // Get all the rules in a single flat array $rules = array_flatten($validator->getRules()); // Get just the rules, not rule modifiers $rules = array_map(function($rule) { preg_match('#^([^:]+)#', $rule, $matches); return $matches[1]; }, $rules); // Callback that removes isntances of the prefix from a message. Laravel // will have already replaced underscores with spaces, so we need to // reverse that. $prefix = str_replace('_', ' ', $prefix); $replacer = function ($message) use ($prefix) { return str_replace($prefix, '', $message); }; // Create an array of identical replacer functions $replacers = array_fill(0, count($rules), $replacer); // Add the replacers to the validtor $validator->addReplacers(array_combine($rules, $replacers)); }
php
protected function removePrefixFromMessages($prefix, $validator) { // Get all the rules in a single flat array $rules = array_flatten($validator->getRules()); // Get just the rules, not rule modifiers $rules = array_map(function($rule) { preg_match('#^([^:]+)#', $rule, $matches); return $matches[1]; }, $rules); // Callback that removes isntances of the prefix from a message. Laravel // will have already replaced underscores with spaces, so we need to // reverse that. $prefix = str_replace('_', ' ', $prefix); $replacer = function ($message) use ($prefix) { return str_replace($prefix, '', $message); }; // Create an array of identical replacer functions $replacers = array_fill(0, count($rules), $replacer); // Add the replacers to the validtor $validator->addReplacers(array_combine($rules, $replacers)); }
[ "protected", "function", "removePrefixFromMessages", "(", "$", "prefix", ",", "$", "validator", ")", "{", "// Get all the rules in a single flat array", "$", "rules", "=", "array_flatten", "(", "$", "validator", "->", "getRules", "(", ")", ")", ";", "// Get just the rules, not rule modifiers", "$", "rules", "=", "array_map", "(", "function", "(", "$", "rule", ")", "{", "preg_match", "(", "'#^([^:]+)#'", ",", "$", "rule", ",", "$", "matches", ")", ";", "return", "$", "matches", "[", "1", "]", ";", "}", ",", "$", "rules", ")", ";", "// Callback that removes isntances of the prefix from a message. Laravel", "// will have already replaced underscores with spaces, so we need to", "// reverse that.", "$", "prefix", "=", "str_replace", "(", "'_'", ",", "' '", ",", "$", "prefix", ")", ";", "$", "replacer", "=", "function", "(", "$", "message", ")", "use", "(", "$", "prefix", ")", "{", "return", "str_replace", "(", "$", "prefix", ",", "''", ",", "$", "message", ")", ";", "}", ";", "// Create an array of identical replacer functions", "$", "replacers", "=", "array_fill", "(", "0", ",", "count", "(", "$", "rules", ")", ",", "$", "replacer", ")", ";", "// Add the replacers to the validtor", "$", "validator", "->", "addReplacers", "(", "array_combine", "(", "$", "rules", ",", "$", "replacers", ")", ")", ";", "}" ]
Add replacers to the validator that strip back out the prefix @param string $prefix @param Illuminate\Validation\Validator $validator @return void
[ "Add", "replacers", "to", "the", "validator", "that", "strip", "back", "out", "the", "prefix" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/ModelValidator.php#L149-L173
30,706
BKWLD/decoy
classes/Input/Search.php
Search.query
public static function query($terms) { return 'query='.urlencode(json_encode(array_map(function ($input, $field) { return [$field, '=', $input]; }, $terms, array_keys($terms)))); }
php
public static function query($terms) { return 'query='.urlencode(json_encode(array_map(function ($input, $field) { return [$field, '=', $input]; }, $terms, array_keys($terms)))); }
[ "public", "static", "function", "query", "(", "$", "terms", ")", "{", "return", "'query='", ".", "urlencode", "(", "json_encode", "(", "array_map", "(", "function", "(", "$", "input", ",", "$", "field", ")", "{", "return", "[", "$", "field", ",", "'='", ",", "$", "input", "]", ";", "}", ",", "$", "terms", ",", "array_keys", "(", "$", "terms", ")", ")", ")", ")", ";", "}" ]
Utility method to generate a query string that applies the condition provided in the args @param array $terms An associative array where the keys are "fields" and the values are "inputs" @return string
[ "Utility", "method", "to", "generate", "a", "query", "string", "that", "applies", "the", "condition", "provided", "in", "the", "args" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Search.php#L27-L32
30,707
BKWLD/decoy
classes/Input/Search.php
Search.condition
private function condition($query, $field, $comparison, $input, $type) { // Convert date formats if ($type == 'date') { $field = $this->convertDateField($field); $input = Carbon::createFromFormat(__('decoy::form.date.format'), $input) ->format('Y-m-d'); } // Apply the where switch ($comparison) { // NULL safe equals and not equals case '=': case '!=': return $this->applyEquality($comparison, $query, $field, $input); // Not Like case '!%*%': $comparison = substr($comparison, 1); $input = str_replace('*', $input, $comparison); return $query->where($field, 'NOT LIKE', $input); // Like case '*%': case '%*': case '%*%': $input = str_replace('*', $input, $comparison); return $query->where($field, 'LIKE', $input); // Defaults default: return $query->where($field, $comparison, $input); } }
php
private function condition($query, $field, $comparison, $input, $type) { // Convert date formats if ($type == 'date') { $field = $this->convertDateField($field); $input = Carbon::createFromFormat(__('decoy::form.date.format'), $input) ->format('Y-m-d'); } // Apply the where switch ($comparison) { // NULL safe equals and not equals case '=': case '!=': return $this->applyEquality($comparison, $query, $field, $input); // Not Like case '!%*%': $comparison = substr($comparison, 1); $input = str_replace('*', $input, $comparison); return $query->where($field, 'NOT LIKE', $input); // Like case '*%': case '%*': case '%*%': $input = str_replace('*', $input, $comparison); return $query->where($field, 'LIKE', $input); // Defaults default: return $query->where($field, $comparison, $input); } }
[ "private", "function", "condition", "(", "$", "query", ",", "$", "field", ",", "$", "comparison", ",", "$", "input", ",", "$", "type", ")", "{", "// Convert date formats", "if", "(", "$", "type", "==", "'date'", ")", "{", "$", "field", "=", "$", "this", "->", "convertDateField", "(", "$", "field", ")", ";", "$", "input", "=", "Carbon", "::", "createFromFormat", "(", "__", "(", "'decoy::form.date.format'", ")", ",", "$", "input", ")", "->", "format", "(", "'Y-m-d'", ")", ";", "}", "// Apply the where", "switch", "(", "$", "comparison", ")", "{", "// NULL safe equals and not equals", "case", "'='", ":", "case", "'!='", ":", "return", "$", "this", "->", "applyEquality", "(", "$", "comparison", ",", "$", "query", ",", "$", "field", ",", "$", "input", ")", ";", "// Not Like", "case", "'!%*%'", ":", "$", "comparison", "=", "substr", "(", "$", "comparison", ",", "1", ")", ";", "$", "input", "=", "str_replace", "(", "'*'", ",", "$", "input", ",", "$", "comparison", ")", ";", "return", "$", "query", "->", "where", "(", "$", "field", ",", "'NOT LIKE'", ",", "$", "input", ")", ";", "// Like", "case", "'*%'", ":", "case", "'%*'", ":", "case", "'%*%'", ":", "$", "input", "=", "str_replace", "(", "'*'", ",", "$", "input", ",", "$", "comparison", ")", ";", "return", "$", "query", "->", "where", "(", "$", "field", ",", "'LIKE'", ",", "$", "input", ")", ";", "// Defaults", "default", ":", "return", "$", "query", "->", "where", "(", "$", "field", ",", "$", "comparison", ",", "$", "input", ")", ";", "}", "}" ]
Add a condition to a query @param Illuminate\Database\Query\Builder $query @param string $field The field name from search config @param string $comparison The operator string from the search UI @param string $input The input for the field @param string $type The type of the field @return Illuminate\Database\Query\Builder
[ "Add", "a", "condition", "to", "a", "query" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Search.php#L93-L127
30,708
BKWLD/decoy
classes/Input/Search.php
Search.applyEquality
protected function applyEquality($comparison, $query, $field, $input) { // Make SQL safe values $safe_field = $this->makeSafeField($field); $safe_input = $input == '' ? 'NULL' : DB::connection()->getPdo()->quote($input); // Different engines have different APIs switch(DB::getDriverName()) { case 'mysql': return $this->applyMysqlEquality( $comparison, $query, $safe_field, $safe_input); case 'sqlite': return $this->applySqliteEquality( $comparison, $query, $safe_field, $safe_input); case 'sqlsrv': return $this->applySqlServerEquality( $comparison, $query, $safe_field, $safe_input); } }
php
protected function applyEquality($comparison, $query, $field, $input) { // Make SQL safe values $safe_field = $this->makeSafeField($field); $safe_input = $input == '' ? 'NULL' : DB::connection()->getPdo()->quote($input); // Different engines have different APIs switch(DB::getDriverName()) { case 'mysql': return $this->applyMysqlEquality( $comparison, $query, $safe_field, $safe_input); case 'sqlite': return $this->applySqliteEquality( $comparison, $query, $safe_field, $safe_input); case 'sqlsrv': return $this->applySqlServerEquality( $comparison, $query, $safe_field, $safe_input); } }
[ "protected", "function", "applyEquality", "(", "$", "comparison", ",", "$", "query", ",", "$", "field", ",", "$", "input", ")", "{", "// Make SQL safe values", "$", "safe_field", "=", "$", "this", "->", "makeSafeField", "(", "$", "field", ")", ";", "$", "safe_input", "=", "$", "input", "==", "''", "?", "'NULL'", ":", "DB", "::", "connection", "(", ")", "->", "getPdo", "(", ")", "->", "quote", "(", "$", "input", ")", ";", "// Different engines have different APIs", "switch", "(", "DB", "::", "getDriverName", "(", ")", ")", "{", "case", "'mysql'", ":", "return", "$", "this", "->", "applyMysqlEquality", "(", "$", "comparison", ",", "$", "query", ",", "$", "safe_field", ",", "$", "safe_input", ")", ";", "case", "'sqlite'", ":", "return", "$", "this", "->", "applySqliteEquality", "(", "$", "comparison", ",", "$", "query", ",", "$", "safe_field", ",", "$", "safe_input", ")", ";", "case", "'sqlsrv'", ":", "return", "$", "this", "->", "applySqlServerEquality", "(", "$", "comparison", ",", "$", "query", ",", "$", "safe_field", ",", "$", "safe_input", ")", ";", "}", "}" ]
Make the NULL-safe equals query @param string $comparison @param Builder $query @param string $field @param string $input @return Builder
[ "Make", "the", "NULL", "-", "safe", "equals", "query" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Search.php#L154-L171
30,709
BKWLD/decoy
classes/Input/Search.php
Search.longhand
public function longhand($config) { $search = []; foreach ($config as $key => $val) { // Make locale menu if ($val == 'locale') { $search['locale'] = [ 'type' => 'select', 'label' => 'Locale', 'options' => Config::get('decoy.site.locales'), ]; // Not associative assume it's a text field } elseif (is_numeric($key)) { $search[$val] = ['type' => 'text', 'label' => Text::titleFromKey($val)]; // If value isn't an array, make a default label } elseif (!is_array($val)) { $search[$key] = ['type' => $val, 'label' => Text::titleFromKey($key)]; // Add the meta array } else { // Make a default label if (empty($val['label'])) { $val['label'] = Text::titleFromKey($key); } // Support class static method or variable as options for a select if (!empty($val['type']) && $val['type'] == 'select' && !empty($val['options']) && is_string($val['options'])) { $val['options'] = $this->longhandOptions($val['options']); } // Apply the meta data $search[$key] = $val; } } return $search; }
php
public function longhand($config) { $search = []; foreach ($config as $key => $val) { // Make locale menu if ($val == 'locale') { $search['locale'] = [ 'type' => 'select', 'label' => 'Locale', 'options' => Config::get('decoy.site.locales'), ]; // Not associative assume it's a text field } elseif (is_numeric($key)) { $search[$val] = ['type' => 'text', 'label' => Text::titleFromKey($val)]; // If value isn't an array, make a default label } elseif (!is_array($val)) { $search[$key] = ['type' => $val, 'label' => Text::titleFromKey($key)]; // Add the meta array } else { // Make a default label if (empty($val['label'])) { $val['label'] = Text::titleFromKey($key); } // Support class static method or variable as options for a select if (!empty($val['type']) && $val['type'] == 'select' && !empty($val['options']) && is_string($val['options'])) { $val['options'] = $this->longhandOptions($val['options']); } // Apply the meta data $search[$key] = $val; } } return $search; }
[ "public", "function", "longhand", "(", "$", "config", ")", "{", "$", "search", "=", "[", "]", ";", "foreach", "(", "$", "config", "as", "$", "key", "=>", "$", "val", ")", "{", "// Make locale menu", "if", "(", "$", "val", "==", "'locale'", ")", "{", "$", "search", "[", "'locale'", "]", "=", "[", "'type'", "=>", "'select'", ",", "'label'", "=>", "'Locale'", ",", "'options'", "=>", "Config", "::", "get", "(", "'decoy.site.locales'", ")", ",", "]", ";", "// Not associative assume it's a text field", "}", "elseif", "(", "is_numeric", "(", "$", "key", ")", ")", "{", "$", "search", "[", "$", "val", "]", "=", "[", "'type'", "=>", "'text'", ",", "'label'", "=>", "Text", "::", "titleFromKey", "(", "$", "val", ")", "]", ";", "// If value isn't an array, make a default label", "}", "elseif", "(", "!", "is_array", "(", "$", "val", ")", ")", "{", "$", "search", "[", "$", "key", "]", "=", "[", "'type'", "=>", "$", "val", ",", "'label'", "=>", "Text", "::", "titleFromKey", "(", "$", "key", ")", "]", ";", "// Add the meta array", "}", "else", "{", "// Make a default label", "if", "(", "empty", "(", "$", "val", "[", "'label'", "]", ")", ")", "{", "$", "val", "[", "'label'", "]", "=", "Text", "::", "titleFromKey", "(", "$", "key", ")", ";", "}", "// Support class static method or variable as options for a select", "if", "(", "!", "empty", "(", "$", "val", "[", "'type'", "]", ")", "&&", "$", "val", "[", "'type'", "]", "==", "'select'", "&&", "!", "empty", "(", "$", "val", "[", "'options'", "]", ")", "&&", "is_string", "(", "$", "val", "[", "'options'", "]", ")", ")", "{", "$", "val", "[", "'options'", "]", "=", "$", "this", "->", "longhandOptions", "(", "$", "val", "[", "'options'", "]", ")", ";", "}", "// Apply the meta data", "$", "search", "[", "$", "key", "]", "=", "$", "val", ";", "}", "}", "return", "$", "search", ";", "}" ]
Make the shorthand options of the search config explicit @param array $config Search config from the controller class definition @return array
[ "Make", "the", "shorthand", "options", "of", "the", "search", "config", "explicit" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Search.php#L261-L304
30,710
BKWLD/decoy
classes/Input/Search.php
Search.longhandOptions
private function longhandOptions($options) { // Call static method. You don't pass the paranethesis // to static calls if (preg_match('#::.+\(\)#', $options)) { return call_user_func(substr($options, 0, strlen($options) - 2)); } // Return static variable if (preg_match('#::\$#', $options)) { list($class, $var) = explode('::$', $options); return $class::$$var; } // Unknown format throw new Exception('Could not parse option: '.$options); }
php
private function longhandOptions($options) { // Call static method. You don't pass the paranethesis // to static calls if (preg_match('#::.+\(\)#', $options)) { return call_user_func(substr($options, 0, strlen($options) - 2)); } // Return static variable if (preg_match('#::\$#', $options)) { list($class, $var) = explode('::$', $options); return $class::$$var; } // Unknown format throw new Exception('Could not parse option: '.$options); }
[ "private", "function", "longhandOptions", "(", "$", "options", ")", "{", "// Call static method. You don't pass the paranethesis", "// to static calls", "if", "(", "preg_match", "(", "'#::.+\\(\\)#'", ",", "$", "options", ")", ")", "{", "return", "call_user_func", "(", "substr", "(", "$", "options", ",", "0", ",", "strlen", "(", "$", "options", ")", "-", "2", ")", ")", ";", "}", "// Return static variable", "if", "(", "preg_match", "(", "'#::\\$#'", ",", "$", "options", ")", ")", "{", "list", "(", "$", "class", ",", "$", "var", ")", "=", "explode", "(", "'::$'", ",", "$", "options", ")", ";", "return", "$", "class", "::", "$", "$", "var", ";", "}", "// Unknown format", "throw", "new", "Exception", "(", "'Could not parse option: '", ".", "$", "options", ")", ";", "}" ]
Parse select options, returning a transformed array with static arrays or callbacks executed @param array $options @return array
[ "Parse", "select", "options", "returning", "a", "transformed", "array", "with", "static", "arrays", "or", "callbacks", "executed" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Search.php#L313-L330
30,711
BKWLD/decoy
classes/Input/Search.php
Search.makeSoftDeletesCondition
public function makeSoftDeletesCondition($controller) { if (!$controller->withTrashed()) return []; return [ 'deleted_at' => [ 'type' => 'select', 'label' => 'status', 'options' => [ 'exists' => 'exists', 'deleted' => 'deleted' ], 'query' => function($query, $condition, $input) { // If not deleted... if (($input == 'exists' && $condition == '=') || ($input == 'deleted' && $condition == '!=')) { $query->whereNull('deleted_at'); // If deleted... } else if (($input == 'deleted' && $condition == '=') || ($input == 'exists' && $condition == '!=')) { $query->whereNotNull('deleted_at'); } }, ] ]; }
php
public function makeSoftDeletesCondition($controller) { if (!$controller->withTrashed()) return []; return [ 'deleted_at' => [ 'type' => 'select', 'label' => 'status', 'options' => [ 'exists' => 'exists', 'deleted' => 'deleted' ], 'query' => function($query, $condition, $input) { // If not deleted... if (($input == 'exists' && $condition == '=') || ($input == 'deleted' && $condition == '!=')) { $query->whereNull('deleted_at'); // If deleted... } else if (($input == 'deleted' && $condition == '=') || ($input == 'exists' && $condition == '!=')) { $query->whereNotNull('deleted_at'); } }, ] ]; }
[ "public", "function", "makeSoftDeletesCondition", "(", "$", "controller", ")", "{", "if", "(", "!", "$", "controller", "->", "withTrashed", "(", ")", ")", "return", "[", "]", ";", "return", "[", "'deleted_at'", "=>", "[", "'type'", "=>", "'select'", ",", "'label'", "=>", "'status'", ",", "'options'", "=>", "[", "'exists'", "=>", "'exists'", ",", "'deleted'", "=>", "'deleted'", "]", ",", "'query'", "=>", "function", "(", "$", "query", ",", "$", "condition", ",", "$", "input", ")", "{", "// If not deleted...", "if", "(", "(", "$", "input", "==", "'exists'", "&&", "$", "condition", "==", "'='", ")", "||", "(", "$", "input", "==", "'deleted'", "&&", "$", "condition", "==", "'!='", ")", ")", "{", "$", "query", "->", "whereNull", "(", "'deleted_at'", ")", ";", "// If deleted...", "}", "else", "if", "(", "(", "$", "input", "==", "'deleted'", "&&", "$", "condition", "==", "'='", ")", "||", "(", "$", "input", "==", "'exists'", "&&", "$", "condition", "==", "'!='", ")", ")", "{", "$", "query", "->", "whereNotNull", "(", "'deleted_at'", ")", ";", "}", "}", ",", "]", "]", ";", "}" ]
Make soft deletes condition if the controller supports trashed records. Returns an array so it can be easily merged into exisitng configs. @param Controller\Base $controller @return array
[ "Make", "soft", "deletes", "condition", "if", "the", "controller", "supports", "trashed", "records", ".", "Returns", "an", "array", "so", "it", "can", "be", "easily", "merged", "into", "exisitng", "configs", "." ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Search.php#L339-L365
30,712
BKWLD/decoy
classes/Models/Encoding.php
Encoding.onCreating
public function onCreating() { // Delete any other encoding jobs for the same parent and field self::where('encodable_type', '=', $this->encodable_type) ->where('encodable_id', '=', $this->encodable_id) ->where('encodable_attribute', '=', $this->encodable_attribute) ->delete(); // Default values $this->status = 'pending'; }
php
public function onCreating() { // Delete any other encoding jobs for the same parent and field self::where('encodable_type', '=', $this->encodable_type) ->where('encodable_id', '=', $this->encodable_id) ->where('encodable_attribute', '=', $this->encodable_attribute) ->delete(); // Default values $this->status = 'pending'; }
[ "public", "function", "onCreating", "(", ")", "{", "// Delete any other encoding jobs for the same parent and field", "self", "::", "where", "(", "'encodable_type'", ",", "'='", ",", "$", "this", "->", "encodable_type", ")", "->", "where", "(", "'encodable_id'", ",", "'='", ",", "$", "this", "->", "encodable_id", ")", "->", "where", "(", "'encodable_attribute'", ",", "'='", ",", "$", "this", "->", "encodable_attribute", ")", "->", "delete", "(", ")", ";", "// Default values", "$", "this", "->", "status", "=", "'pending'", ";", "}" ]
Set default fields and delete any old encodings for the same source. @return void
[ "Set", "default", "fields", "and", "delete", "any", "old", "encodings", "for", "the", "same", "source", "." ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Encoding.php#L69-L79
30,713
BKWLD/decoy
classes/Models/Encoding.php
Encoding.onDeleted
public function onDeleted() { // Get the directory of an output if (($sources = (array) $this->outputs) // Convert sources to an array && count($sources) // If there are sources && ($first = array_pop($sources)) // Get the last source && preg_match('#^/(?!/)#', $first) // Make sure it's a local path && ($dir = public_path().dirname($first)) // Get the path of the filename && is_dir($dir)) { // Make sure it's a directory File::deleteDir($dir); } }
php
public function onDeleted() { // Get the directory of an output if (($sources = (array) $this->outputs) // Convert sources to an array && count($sources) // If there are sources && ($first = array_pop($sources)) // Get the last source && preg_match('#^/(?!/)#', $first) // Make sure it's a local path && ($dir = public_path().dirname($first)) // Get the path of the filename && is_dir($dir)) { // Make sure it's a directory File::deleteDir($dir); } }
[ "public", "function", "onDeleted", "(", ")", "{", "// Get the directory of an output", "if", "(", "(", "$", "sources", "=", "(", "array", ")", "$", "this", "->", "outputs", ")", "// Convert sources to an array", "&&", "count", "(", "$", "sources", ")", "// If there are sources", "&&", "(", "$", "first", "=", "array_pop", "(", "$", "sources", ")", ")", "// Get the last source", "&&", "preg_match", "(", "'#^/(?!/)#'", ",", "$", "first", ")", "// Make sure it's a local path", "&&", "(", "$", "dir", "=", "public_path", "(", ")", ".", "dirname", "(", "$", "first", ")", ")", "// Get the path of the filename", "&&", "is_dir", "(", "$", "dir", ")", ")", "{", "// Make sure it's a directory", "File", "::", "deleteDir", "(", "$", "dir", ")", ";", "}", "}" ]
Delete encoded files that are local to this filesystem
[ "Delete", "encoded", "files", "that", "are", "local", "to", "this", "filesystem" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Encoding.php#L97-L108
30,714
BKWLD/decoy
classes/Models/Encoding.php
Encoding.source
public function source() { $val = $this->encodable->{$this->encodable_attribute}; if (preg_match('#^http#', $val)) { return $val; } return URL::asset($val); }
php
public function source() { $val = $this->encodable->{$this->encodable_attribute}; if (preg_match('#^http#', $val)) { return $val; } return URL::asset($val); }
[ "public", "function", "source", "(", ")", "{", "$", "val", "=", "$", "this", "->", "encodable", "->", "{", "$", "this", "->", "encodable_attribute", "}", ";", "if", "(", "preg_match", "(", "'#^http#'", ",", "$", "val", ")", ")", "{", "return", "$", "val", ";", "}", "return", "URL", "::", "asset", "(", "$", "val", ")", ";", "}" ]
Get the source video for the encode @return string The path to the video relative to the document root
[ "Get", "the", "source", "video", "for", "the", "encode" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Encoding.php#L150-L158
30,715
BKWLD/decoy
classes/Models/Encoding.php
Encoding.storeJob
public function storeJob($job_id, $outputs = null) { $this->status = 'queued'; $this->job_id = $job_id; $this->outputs = $outputs; $this->save(); }
php
public function storeJob($job_id, $outputs = null) { $this->status = 'queued'; $this->job_id = $job_id; $this->outputs = $outputs; $this->save(); }
[ "public", "function", "storeJob", "(", "$", "job_id", ",", "$", "outputs", "=", "null", ")", "{", "$", "this", "->", "status", "=", "'queued'", ";", "$", "this", "->", "job_id", "=", "$", "job_id", ";", "$", "this", "->", "outputs", "=", "$", "outputs", ";", "$", "this", "->", "save", "(", ")", ";", "}" ]
Store a record of the encoding job @param string $job_id A unique id generated by the service @param mixed $outputs An optional assoc array where the keys are labels for the outputs and the values are absolute paths of where the output will be saved @return void
[ "Store", "a", "record", "of", "the", "encoding", "job" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Encoding.php#L169-L175
30,716
BKWLD/decoy
classes/Models/Encoding.php
Encoding.status
public function status($status, $message = null) { if (!in_array($status, static::$states)) { throw new Exception('Unknown state: '.$status); } // If the current status is complete, don't update again. I have seen cases of a late // processing call on a HLS stream file after it's already been set to complete. I think // it could just be weird internet delays. if ($this->complete == 'complete') { return; } // Append messages if ($this->message) { $this->message .= ' '; } if ($message) { $this->message .= $message; } // If a job is errored, don't unset it. Thus, if one output fails, a notification // from a later output succeeding still means an overall failure. if ($this->status != 'error') { $this->status = $status; } // Save it $this->save(); }
php
public function status($status, $message = null) { if (!in_array($status, static::$states)) { throw new Exception('Unknown state: '.$status); } // If the current status is complete, don't update again. I have seen cases of a late // processing call on a HLS stream file after it's already been set to complete. I think // it could just be weird internet delays. if ($this->complete == 'complete') { return; } // Append messages if ($this->message) { $this->message .= ' '; } if ($message) { $this->message .= $message; } // If a job is errored, don't unset it. Thus, if one output fails, a notification // from a later output succeeding still means an overall failure. if ($this->status != 'error') { $this->status = $status; } // Save it $this->save(); }
[ "public", "function", "status", "(", "$", "status", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "in_array", "(", "$", "status", ",", "static", "::", "$", "states", ")", ")", "{", "throw", "new", "Exception", "(", "'Unknown state: '", ".", "$", "status", ")", ";", "}", "// If the current status is complete, don't update again. I have seen cases of a late", "// processing call on a HLS stream file after it's already been set to complete. I think", "// it could just be weird internet delays.", "if", "(", "$", "this", "->", "complete", "==", "'complete'", ")", "{", "return", ";", "}", "// Append messages", "if", "(", "$", "this", "->", "message", ")", "{", "$", "this", "->", "message", ".=", "' '", ";", "}", "if", "(", "$", "message", ")", "{", "$", "this", "->", "message", ".=", "$", "message", ";", "}", "// If a job is errored, don't unset it. Thus, if one output fails, a notification", "// from a later output succeeding still means an overall failure.", "if", "(", "$", "this", "->", "status", "!=", "'error'", ")", "{", "$", "this", "->", "status", "=", "$", "status", ";", "}", "// Save it", "$", "this", "->", "save", "(", ")", ";", "}" ]
Update the status of the encode @param string status @param string $message @return void
[ "Update", "the", "status", "of", "the", "encode" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Encoding.php#L184-L214
30,717
BKWLD/decoy
classes/Models/Encoding.php
Encoding.getAdminVideoTagAttribute
public function getAdminVideoTagAttribute() { if (!$tag = $this->getTagAttribute()) { return; } $tag->controls(); if (isset($this->response->output->width)) { $tag->width($this->response->output->width); } return $tag->render(); }
php
public function getAdminVideoTagAttribute() { if (!$tag = $this->getTagAttribute()) { return; } $tag->controls(); if (isset($this->response->output->width)) { $tag->width($this->response->output->width); } return $tag->render(); }
[ "public", "function", "getAdminVideoTagAttribute", "(", ")", "{", "if", "(", "!", "$", "tag", "=", "$", "this", "->", "getTagAttribute", "(", ")", ")", "{", "return", ";", "}", "$", "tag", "->", "controls", "(", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "response", "->", "output", "->", "width", ")", ")", "{", "$", "tag", "->", "width", "(", "$", "this", "->", "response", "->", "output", "->", "width", ")", ";", "}", "return", "$", "tag", "->", "render", "(", ")", ";", "}" ]
Generate an HTML5 video tag with extra elements for displaying in the admin @return string html
[ "Generate", "an", "HTML5", "video", "tag", "with", "extra", "elements", "for", "displaying", "in", "the", "admin" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Encoding.php#L234-L246
30,718
BKWLD/decoy
classes/Models/Encoding.php
Encoding.getAdminStatsMarkupAttribute
protected function getAdminStatsMarkupAttribute() { if (!$stats = $this->getStatsAttribute()) { return ''; } return '<div class="stats">' .implode('', array_map(function ($val, $key) { return sprintf('<span class="label"> <span>%s</span> <span class="badge">%s</span> </span>', $key, $val); }, $stats, array_keys($stats))) .'</div>'; }
php
protected function getAdminStatsMarkupAttribute() { if (!$stats = $this->getStatsAttribute()) { return ''; } return '<div class="stats">' .implode('', array_map(function ($val, $key) { return sprintf('<span class="label"> <span>%s</span> <span class="badge">%s</span> </span>', $key, $val); }, $stats, array_keys($stats))) .'</div>'; }
[ "protected", "function", "getAdminStatsMarkupAttribute", "(", ")", "{", "if", "(", "!", "$", "stats", "=", "$", "this", "->", "getStatsAttribute", "(", ")", ")", "{", "return", "''", ";", "}", "return", "'<div class=\"stats\">'", ".", "implode", "(", "''", ",", "array_map", "(", "function", "(", "$", "val", ",", "$", "key", ")", "{", "return", "sprintf", "(", "'<span class=\"label\">\n <span>%s</span>\n <span class=\"badge\">%s</span>\n </span>'", ",", "$", "key", ",", "$", "val", ")", ";", "}", ",", "$", "stats", ",", "array_keys", "(", "$", "stats", ")", ")", ")", ".", "'</div>'", ";", "}" ]
Get stats as labels with badges @return string html
[ "Get", "stats", "as", "labels", "with", "badges" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Encoding.php#L253-L268
30,719
BKWLD/decoy
classes/Models/Encoding.php
Encoding.getStatsAttribute
protected function getStatsAttribute() { if (empty($this->response->output)) { return; } $o = $this->response->output; return array_filter([ 'Bitrate' => number_format($o->video_bitrate_in_kbps + $o->audio_bitrate_in_kbps).' kbps', 'Filesize' => number_format($o->file_size_in_bytes/1024/1024, 1).' mb', 'Duration' => number_format($o->duration_in_ms/1000, 1).' s', 'Dimensions' => number_format($o->width).' x '.number_format($o->height), 'Download' => '<a href="'.$this->outputs->mp4.'" target="_blank">MP4</a>' ]); }
php
protected function getStatsAttribute() { if (empty($this->response->output)) { return; } $o = $this->response->output; return array_filter([ 'Bitrate' => number_format($o->video_bitrate_in_kbps + $o->audio_bitrate_in_kbps).' kbps', 'Filesize' => number_format($o->file_size_in_bytes/1024/1024, 1).' mb', 'Duration' => number_format($o->duration_in_ms/1000, 1).' s', 'Dimensions' => number_format($o->width).' x '.number_format($o->height), 'Download' => '<a href="'.$this->outputs->mp4.'" target="_blank">MP4</a>' ]); }
[ "protected", "function", "getStatsAttribute", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "response", "->", "output", ")", ")", "{", "return", ";", "}", "$", "o", "=", "$", "this", "->", "response", "->", "output", ";", "return", "array_filter", "(", "[", "'Bitrate'", "=>", "number_format", "(", "$", "o", "->", "video_bitrate_in_kbps", "+", "$", "o", "->", "audio_bitrate_in_kbps", ")", ".", "' kbps'", ",", "'Filesize'", "=>", "number_format", "(", "$", "o", "->", "file_size_in_bytes", "/", "1024", "/", "1024", ",", "1", ")", ".", "' mb'", ",", "'Duration'", "=>", "number_format", "(", "$", "o", "->", "duration_in_ms", "/", "1000", ",", "1", ")", ".", "' s'", ",", "'Dimensions'", "=>", "number_format", "(", "$", "o", "->", "width", ")", ".", "' x '", ".", "number_format", "(", "$", "o", "->", "height", ")", ",", "'Download'", "=>", "'<a href=\"'", ".", "$", "this", "->", "outputs", "->", "mp4", ".", "'\" target=\"_blank\">MP4</a>'", "]", ")", ";", "}" ]
Read an array of stats from the response @return array|void
[ "Read", "an", "array", "of", "stats", "from", "the", "response" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Encoding.php#L275-L290
30,720
BKWLD/decoy
classes/Models/Encoding.php
Encoding.getTagAttribute
public function getTagAttribute() { // Require sources and for the encoding to be complete if (!$sources = $this->getOutputsValue()) { return; } // Start the tag $tag = HtmlElement::video(); $tag->value('Your browser does not support the video tag. You should <a href="http://whatbrowser.org/">consider updating</a>.'); // Loop through the outputs and add them as sources $types = ['mp4', 'webm', 'ogg', 'playlist']; foreach ($sources as $type => $src) { // Only allow basic output types if (!in_array($type, $types)) { continue; } // Make the source $source = HtmlElement::source()->src($src); if ($type == 'playlist') { $source->type('application/x-mpegurl'); } else { $source->type('video/'.$type); } // Add a source to the video tag $tag->appendChild($source); } // Return the tag return $tag; }
php
public function getTagAttribute() { // Require sources and for the encoding to be complete if (!$sources = $this->getOutputsValue()) { return; } // Start the tag $tag = HtmlElement::video(); $tag->value('Your browser does not support the video tag. You should <a href="http://whatbrowser.org/">consider updating</a>.'); // Loop through the outputs and add them as sources $types = ['mp4', 'webm', 'ogg', 'playlist']; foreach ($sources as $type => $src) { // Only allow basic output types if (!in_array($type, $types)) { continue; } // Make the source $source = HtmlElement::source()->src($src); if ($type == 'playlist') { $source->type('application/x-mpegurl'); } else { $source->type('video/'.$type); } // Add a source to the video tag $tag->appendChild($source); } // Return the tag return $tag; }
[ "public", "function", "getTagAttribute", "(", ")", "{", "// Require sources and for the encoding to be complete", "if", "(", "!", "$", "sources", "=", "$", "this", "->", "getOutputsValue", "(", ")", ")", "{", "return", ";", "}", "// Start the tag", "$", "tag", "=", "HtmlElement", "::", "video", "(", ")", ";", "$", "tag", "->", "value", "(", "'Your browser does not support the video tag. You should <a href=\"http://whatbrowser.org/\">consider updating</a>.'", ")", ";", "// Loop through the outputs and add them as sources", "$", "types", "=", "[", "'mp4'", ",", "'webm'", ",", "'ogg'", ",", "'playlist'", "]", ";", "foreach", "(", "$", "sources", "as", "$", "type", "=>", "$", "src", ")", "{", "// Only allow basic output types", "if", "(", "!", "in_array", "(", "$", "type", ",", "$", "types", ")", ")", "{", "continue", ";", "}", "// Make the source", "$", "source", "=", "HtmlElement", "::", "source", "(", ")", "->", "src", "(", "$", "src", ")", ";", "if", "(", "$", "type", "==", "'playlist'", ")", "{", "$", "source", "->", "type", "(", "'application/x-mpegurl'", ")", ";", "}", "else", "{", "$", "source", "->", "type", "(", "'video/'", ".", "$", "type", ")", ";", "}", "// Add a source to the video tag", "$", "tag", "->", "appendChild", "(", "$", "source", ")", ";", "}", "// Return the tag", "return", "$", "tag", ";", "}" ]
Generate an HTML5 video tag via Former's HtmlObject for the outputs @return HtmlObject\Element
[ "Generate", "an", "HTML5", "video", "tag", "via", "Former", "s", "HtmlObject", "for", "the", "outputs" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Encoding.php#L316-L350
30,721
BKWLD/decoy
classes/Models/Encoding.php
Encoding.getOutputsValue
public function getOutputsValue() { if ($this->status != 'complete') { return; } $val = $this->getAttributeFromArray('outputs'); if (is_string($val)) { return $this->outputs; } return $val; }
php
public function getOutputsValue() { if ($this->status != 'complete') { return; } $val = $this->getAttributeFromArray('outputs'); if (is_string($val)) { return $this->outputs; } return $val; }
[ "public", "function", "getOutputsValue", "(", ")", "{", "if", "(", "$", "this", "->", "status", "!=", "'complete'", ")", "{", "return", ";", "}", "$", "val", "=", "$", "this", "->", "getAttributeFromArray", "(", "'outputs'", ")", ";", "if", "(", "is_string", "(", "$", "val", ")", ")", "{", "return", "$", "this", "->", "outputs", ";", "}", "return", "$", "val", ";", "}" ]
Get the outputs value. I made this to work around an issue where Laravel was double casting the outputs. I'm not sure why this was happening after some lengthy digging but it seemed unique to Encodings on Elements. So I'm testing whether the attribute value has already been casted. @return object
[ "Get", "the", "outputs", "value", ".", "I", "made", "this", "to", "work", "around", "an", "issue", "where", "Laravel", "was", "double", "casting", "the", "outputs", ".", "I", "m", "not", "sure", "why", "this", "was", "happening", "after", "some", "lengthy", "digging", "but", "it", "seemed", "unique", "to", "Encodings", "on", "Elements", ".", "So", "I", "m", "testing", "whether", "the", "attribute", "value", "has", "already", "been", "casted", "." ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Encoding.php#L360-L372
30,722
BKWLD/decoy
classes/Markup/ImageElement.php
ImageElement.render
public function render() { // Different conditions for different types of tags switch ($this->element) { // Img tags use the src case 'img': if (empty($this->getAttribute('src'))) { return ''; } break; // Divs have the image as a background-image // https://regex101.com/r/eF0oD0/1 default: if (!preg_match('#background-image:\s*url\([\'"]?[\w\/]#', $this->getAttribute('style'))) { return ''; } } // Carry on with normal rendering return parent::render(); }
php
public function render() { // Different conditions for different types of tags switch ($this->element) { // Img tags use the src case 'img': if (empty($this->getAttribute('src'))) { return ''; } break; // Divs have the image as a background-image // https://regex101.com/r/eF0oD0/1 default: if (!preg_match('#background-image:\s*url\([\'"]?[\w\/]#', $this->getAttribute('style'))) { return ''; } } // Carry on with normal rendering return parent::render(); }
[ "public", "function", "render", "(", ")", "{", "// Different conditions for different types of tags", "switch", "(", "$", "this", "->", "element", ")", "{", "// Img tags use the src", "case", "'img'", ":", "if", "(", "empty", "(", "$", "this", "->", "getAttribute", "(", "'src'", ")", ")", ")", "{", "return", "''", ";", "}", "break", ";", "// Divs have the image as a background-image", "// https://regex101.com/r/eF0oD0/1", "default", ":", "if", "(", "!", "preg_match", "(", "'#background-image:\\s*url\\([\\'\"]?[\\w\\/]#'", ",", "$", "this", "->", "getAttribute", "(", "'style'", ")", ")", ")", "{", "return", "''", ";", "}", "}", "// Carry on with normal rendering", "return", "parent", "::", "render", "(", ")", ";", "}" ]
Check that an image URL exists before allowing the tag to render @return string
[ "Check", "that", "an", "image", "URL", "exists", "before", "allowing", "the", "tag", "to", "render" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Markup/ImageElement.php#L30-L53
30,723
BKWLD/decoy
classes/Routing/UrlGenerator.php
UrlGenerator.relative
public function relative($action = 'index', $id = null, $child = null) { // Get the current path, adding a leading slash that should be missing $path = '/'.$this->path; // Get the URL up to and including the last controller. If we're not linking // to a child, also remove the id, which may be replaced by a passed id $actions = implode('|', $this->actions); if ($child) { $pattern = '#(/('.$actions.'))?/?$#'; } else { $pattern = '#(/\d+)?(/('.$actions.'))?/?$#'; } $path = preg_replace($pattern, '', $path); // If there is an id and we're not linking to a child, add that id if (!$child && $id) { $path .= '/'.$id; } // If there is a child controller, add that now if ($child) { // If the child has a backslash, it's a namespaced class name, so convert to just name if (strpos($child, '\\') !== false) { $child = $this->slugController($child); } // If currently on an edit view (where we always respect child parameters literally), // or if the link is to an index view (for many to many to self) or if the child // is different than the current path, appened the child controller slug. if (preg_match('#edit$#', $this->path) || $action == 'index' || !preg_match('#'.$child.'(/\d+)?$#', $path) ) { $path .= '/'.$child; } // If the action was not index and there was an id, add it if ($action != 'index' && $id) { $path .= '/'.$id; } } // Now, add actions (except for index, which is implied by the lack of an action) if ($action && $action != 'index') { $path .= '/'.$action; } // Done, return it return $path; }
php
public function relative($action = 'index', $id = null, $child = null) { // Get the current path, adding a leading slash that should be missing $path = '/'.$this->path; // Get the URL up to and including the last controller. If we're not linking // to a child, also remove the id, which may be replaced by a passed id $actions = implode('|', $this->actions); if ($child) { $pattern = '#(/('.$actions.'))?/?$#'; } else { $pattern = '#(/\d+)?(/('.$actions.'))?/?$#'; } $path = preg_replace($pattern, '', $path); // If there is an id and we're not linking to a child, add that id if (!$child && $id) { $path .= '/'.$id; } // If there is a child controller, add that now if ($child) { // If the child has a backslash, it's a namespaced class name, so convert to just name if (strpos($child, '\\') !== false) { $child = $this->slugController($child); } // If currently on an edit view (where we always respect child parameters literally), // or if the link is to an index view (for many to many to self) or if the child // is different than the current path, appened the child controller slug. if (preg_match('#edit$#', $this->path) || $action == 'index' || !preg_match('#'.$child.'(/\d+)?$#', $path) ) { $path .= '/'.$child; } // If the action was not index and there was an id, add it if ($action != 'index' && $id) { $path .= '/'.$id; } } // Now, add actions (except for index, which is implied by the lack of an action) if ($action && $action != 'index') { $path .= '/'.$action; } // Done, return it return $path; }
[ "public", "function", "relative", "(", "$", "action", "=", "'index'", ",", "$", "id", "=", "null", ",", "$", "child", "=", "null", ")", "{", "// Get the current path, adding a leading slash that should be missing", "$", "path", "=", "'/'", ".", "$", "this", "->", "path", ";", "// Get the URL up to and including the last controller. If we're not linking", "// to a child, also remove the id, which may be replaced by a passed id", "$", "actions", "=", "implode", "(", "'|'", ",", "$", "this", "->", "actions", ")", ";", "if", "(", "$", "child", ")", "{", "$", "pattern", "=", "'#(/('", ".", "$", "actions", ".", "'))?/?$#'", ";", "}", "else", "{", "$", "pattern", "=", "'#(/\\d+)?(/('", ".", "$", "actions", ".", "'))?/?$#'", ";", "}", "$", "path", "=", "preg_replace", "(", "$", "pattern", ",", "''", ",", "$", "path", ")", ";", "// If there is an id and we're not linking to a child, add that id", "if", "(", "!", "$", "child", "&&", "$", "id", ")", "{", "$", "path", ".=", "'/'", ".", "$", "id", ";", "}", "// If there is a child controller, add that now", "if", "(", "$", "child", ")", "{", "// If the child has a backslash, it's a namespaced class name, so convert to just name", "if", "(", "strpos", "(", "$", "child", ",", "'\\\\'", ")", "!==", "false", ")", "{", "$", "child", "=", "$", "this", "->", "slugController", "(", "$", "child", ")", ";", "}", "// If currently on an edit view (where we always respect child parameters literally),", "// or if the link is to an index view (for many to many to self) or if the child", "// is different than the current path, appened the child controller slug.", "if", "(", "preg_match", "(", "'#edit$#'", ",", "$", "this", "->", "path", ")", "||", "$", "action", "==", "'index'", "||", "!", "preg_match", "(", "'#'", ".", "$", "child", ".", "'(/\\d+)?$#'", ",", "$", "path", ")", ")", "{", "$", "path", ".=", "'/'", ".", "$", "child", ";", "}", "// If the action was not index and there was an id, add it", "if", "(", "$", "action", "!=", "'index'", "&&", "$", "id", ")", "{", "$", "path", ".=", "'/'", ".", "$", "id", ";", "}", "}", "// Now, add actions (except for index, which is implied by the lack of an action)", "if", "(", "$", "action", "&&", "$", "action", "!=", "'index'", ")", "{", "$", "path", ".=", "'/'", ".", "$", "action", ";", "}", "// Done, return it", "return", "$", "path", ";", "}" ]
Construct a route that takes into account the current url path as well as the function arguments @param string $action The action we're linking to: index/edit/etc @param integer $id Optional id that we're linking to. Required for actions like edit. @param string $child The name (or full class) of a child controller of the current path: 'slides', 'Admin\SlidesController' @return string '/admin/articles'
[ "Construct", "a", "route", "that", "takes", "into", "account", "the", "current", "url", "path", "as", "well", "as", "the", "function", "arguments" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Routing/UrlGenerator.php#L49-L100
30,724
BKWLD/decoy
classes/Routing/UrlGenerator.php
UrlGenerator.action
public function action($controller = null, $id = null) { // Assume that the current, first path segment is the directory decoy is // running in preg_match('#[a-z-]+#i', $this->path, $matches); $decoy = $matches[0]; // Strip the action from the controller $action = ''; if (preg_match('#@\w+$#', $controller, $matches)) { $action = substr($matches[0], 1); $controller = substr($controller, 0, -strlen($matches[0])); } // Convert controller for URL $controller = $this->slugController($controller); // Begin the url $path = '/'.$decoy.'/'.$controller; // If there is an id, add it now if ($id) { $path .= '/'.$id; } // Now, add actions (except for index, which is implied by the lack of an action) if ($action && $action != 'index') { $path .= '/'.$action; } // Done, return it return $path; }
php
public function action($controller = null, $id = null) { // Assume that the current, first path segment is the directory decoy is // running in preg_match('#[a-z-]+#i', $this->path, $matches); $decoy = $matches[0]; // Strip the action from the controller $action = ''; if (preg_match('#@\w+$#', $controller, $matches)) { $action = substr($matches[0], 1); $controller = substr($controller, 0, -strlen($matches[0])); } // Convert controller for URL $controller = $this->slugController($controller); // Begin the url $path = '/'.$decoy.'/'.$controller; // If there is an id, add it now if ($id) { $path .= '/'.$id; } // Now, add actions (except for index, which is implied by the lack of an action) if ($action && $action != 'index') { $path .= '/'.$action; } // Done, return it return $path; }
[ "public", "function", "action", "(", "$", "controller", "=", "null", ",", "$", "id", "=", "null", ")", "{", "// Assume that the current, first path segment is the directory decoy is", "// running in", "preg_match", "(", "'#[a-z-]+#i'", ",", "$", "this", "->", "path", ",", "$", "matches", ")", ";", "$", "decoy", "=", "$", "matches", "[", "0", "]", ";", "// Strip the action from the controller", "$", "action", "=", "''", ";", "if", "(", "preg_match", "(", "'#@\\w+$#'", ",", "$", "controller", ",", "$", "matches", ")", ")", "{", "$", "action", "=", "substr", "(", "$", "matches", "[", "0", "]", ",", "1", ")", ";", "$", "controller", "=", "substr", "(", "$", "controller", ",", "0", ",", "-", "strlen", "(", "$", "matches", "[", "0", "]", ")", ")", ";", "}", "// Convert controller for URL", "$", "controller", "=", "$", "this", "->", "slugController", "(", "$", "controller", ")", ";", "// Begin the url", "$", "path", "=", "'/'", ".", "$", "decoy", ".", "'/'", ".", "$", "controller", ";", "// If there is an id, add it now", "if", "(", "$", "id", ")", "{", "$", "path", ".=", "'/'", ".", "$", "id", ";", "}", "// Now, add actions (except for index, which is implied by the lack of an action)", "if", "(", "$", "action", "&&", "$", "action", "!=", "'index'", ")", "{", "$", "path", ".=", "'/'", ".", "$", "action", ";", "}", "// Done, return it", "return", "$", "path", ";", "}" ]
Make a URL given a fully namespaced controller. This only generates routes as if the controller is in the root level; as if it has no parents. @param string $controller ex: Bkwld\Decoy\Controllers\Admins@create @param integer $id @return string ex: http://admin/admins/create
[ "Make", "a", "URL", "given", "a", "fully", "namespaced", "controller", ".", "This", "only", "generates", "routes", "as", "if", "the", "controller", "is", "in", "the", "root", "level", ";", "as", "if", "it", "has", "no", "parents", "." ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Routing/UrlGenerator.php#L110-L142
30,725
BKWLD/decoy
classes/Routing/UrlGenerator.php
UrlGenerator.slugController
public function slugController($controller) { // Get the controller name $controller = preg_replace('#^('.preg_quote('Bkwld\Decoy\Controllers\\') .'|'.preg_quote('App\Http\Controllers\Admin\\').')#', '', $controller); // Convert study caps to dashes $controller = Str::snake($controller, '-'); // Done return $controller; }
php
public function slugController($controller) { // Get the controller name $controller = preg_replace('#^('.preg_quote('Bkwld\Decoy\Controllers\\') .'|'.preg_quote('App\Http\Controllers\Admin\\').')#', '', $controller); // Convert study caps to dashes $controller = Str::snake($controller, '-'); // Done return $controller; }
[ "public", "function", "slugController", "(", "$", "controller", ")", "{", "// Get the controller name", "$", "controller", "=", "preg_replace", "(", "'#^('", ".", "preg_quote", "(", "'Bkwld\\Decoy\\Controllers\\\\'", ")", ".", "'|'", ".", "preg_quote", "(", "'App\\Http\\Controllers\\Admin\\\\'", ")", ".", "')#'", ",", "''", ",", "$", "controller", ")", ";", "// Convert study caps to dashes", "$", "controller", "=", "Str", "::", "snake", "(", "$", "controller", ",", "'-'", ")", ";", "// Done", "return", "$", "controller", ";", "}" ]
Convert a controller to how it is referenced in a url @param string $controller ex: Admin\ArticlesAreCoolController @return string ex: articles-are-cool
[ "Convert", "a", "controller", "to", "how", "it", "is", "referenced", "in", "a", "url" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Routing/UrlGenerator.php#L150-L161
30,726
BKWLD/decoy
classes/Observers/Changes.php
Changes.handle
public function handle($event, $payload) { list($model) = $payload; // Don't log changes to pivot models. Even though a user may have initiated // this, it's kind of meaningless to them. These events can happen when a // user messes with drag and drop positioning. if (is_a($model, \Illuminate\Database\Eloquent\Relations\Pivot::class)) { return; } // Get the action of the event preg_match('#eloquent\.(\w+)#', $event, $matches); $action = $matches[1]; if (!in_array($action, $this->supported)) { return; } // Get the admin acting on the record $admin = app('decoy.user'); // If `log_changes` was configed as a callable, see if this model event // should not be logged if ($check = config('decoy.site.log_changes')) { if (is_bool($check) && !$check) { return; } if (is_callable($check)) { \Log::error('Callable log_changes have been deprecated'); if (!call_user_func($check, $model, $action, $admin)) { return; } } } else { return; } // Check with the model itself to see if it should be logged if (method_exists($model, 'shouldLogChange')) { if (!$model->shouldLogChange($action)) { return; } // Default to not logging changes if there is no shouldLogChange() } else { return; } // Log the event Change::log($model, $action, $admin); }
php
public function handle($event, $payload) { list($model) = $payload; // Don't log changes to pivot models. Even though a user may have initiated // this, it's kind of meaningless to them. These events can happen when a // user messes with drag and drop positioning. if (is_a($model, \Illuminate\Database\Eloquent\Relations\Pivot::class)) { return; } // Get the action of the event preg_match('#eloquent\.(\w+)#', $event, $matches); $action = $matches[1]; if (!in_array($action, $this->supported)) { return; } // Get the admin acting on the record $admin = app('decoy.user'); // If `log_changes` was configed as a callable, see if this model event // should not be logged if ($check = config('decoy.site.log_changes')) { if (is_bool($check) && !$check) { return; } if (is_callable($check)) { \Log::error('Callable log_changes have been deprecated'); if (!call_user_func($check, $model, $action, $admin)) { return; } } } else { return; } // Check with the model itself to see if it should be logged if (method_exists($model, 'shouldLogChange')) { if (!$model->shouldLogChange($action)) { return; } // Default to not logging changes if there is no shouldLogChange() } else { return; } // Log the event Change::log($model, $action, $admin); }
[ "public", "function", "handle", "(", "$", "event", ",", "$", "payload", ")", "{", "list", "(", "$", "model", ")", "=", "$", "payload", ";", "// Don't log changes to pivot models. Even though a user may have initiated", "// this, it's kind of meaningless to them. These events can happen when a", "// user messes with drag and drop positioning.", "if", "(", "is_a", "(", "$", "model", ",", "\\", "Illuminate", "\\", "Database", "\\", "Eloquent", "\\", "Relations", "\\", "Pivot", "::", "class", ")", ")", "{", "return", ";", "}", "// Get the action of the event", "preg_match", "(", "'#eloquent\\.(\\w+)#'", ",", "$", "event", ",", "$", "matches", ")", ";", "$", "action", "=", "$", "matches", "[", "1", "]", ";", "if", "(", "!", "in_array", "(", "$", "action", ",", "$", "this", "->", "supported", ")", ")", "{", "return", ";", "}", "// Get the admin acting on the record", "$", "admin", "=", "app", "(", "'decoy.user'", ")", ";", "// If `log_changes` was configed as a callable, see if this model event", "// should not be logged", "if", "(", "$", "check", "=", "config", "(", "'decoy.site.log_changes'", ")", ")", "{", "if", "(", "is_bool", "(", "$", "check", ")", "&&", "!", "$", "check", ")", "{", "return", ";", "}", "if", "(", "is_callable", "(", "$", "check", ")", ")", "{", "\\", "Log", "::", "error", "(", "'Callable log_changes have been deprecated'", ")", ";", "if", "(", "!", "call_user_func", "(", "$", "check", ",", "$", "model", ",", "$", "action", ",", "$", "admin", ")", ")", "{", "return", ";", "}", "}", "}", "else", "{", "return", ";", "}", "// Check with the model itself to see if it should be logged", "if", "(", "method_exists", "(", "$", "model", ",", "'shouldLogChange'", ")", ")", "{", "if", "(", "!", "$", "model", "->", "shouldLogChange", "(", "$", "action", ")", ")", "{", "return", ";", "}", "// Default to not logging changes if there is no shouldLogChange()", "}", "else", "{", "return", ";", "}", "// Log the event", "Change", "::", "log", "(", "$", "model", ",", "$", "action", ",", "$", "admin", ")", ";", "}" ]
Handle all Eloquent model events @param string $event @param array $payload Contains: - Bkwld\Decoy\Models\Base $model
[ "Handle", "all", "Eloquent", "model", "events" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Observers/Changes.php#L30-L80
30,727
BKWLD/decoy
classes/Layout/Breadcrumbs.php
Breadcrumbs.parseURL
public function parseURL() { $breadcrumbs = []; // Get the segments $path = Request::path(); $segments = explode('/', $path); // Loop through them in blocks of 2: [list, detail] $url = $segments[0]; for ($i=1; $i<count($segments); $i+=2) { // If an action URL, you're at the end of the URL if (in_array($segments[$i], ['edit'])) { break; } // Figure out the controller given the url partial $url .= '/' . $segments[$i]; $router = new Wildcard($segments[0], 'GET', $url); if (!($controller = $router->detectController())) { continue; } $controller = new $controller; // Add controller to breadcrumbs $breadcrumbs[URL::to($url)] = strip_tags($controller->title(), '<img>'); // Add a detail if it exists if (!isset($segments[$i+1])) { break; } $id = $segments[$i+1]; // On a "new" page if ($id == 'create') { $url .= '/' . $id; $breadcrumbs[URL::to($url)] = __('decoy::breadcrumbs.new'); // On an edit page } elseif (is_numeric($id)) { $url .= '/' . $id; $item = $this->find($controller, $id); $title = $item->getAdminTitleAttribute(); $breadcrumbs[URL::to($url.'/edit')] = $title; } } // Return the full list return $breadcrumbs; }
php
public function parseURL() { $breadcrumbs = []; // Get the segments $path = Request::path(); $segments = explode('/', $path); // Loop through them in blocks of 2: [list, detail] $url = $segments[0]; for ($i=1; $i<count($segments); $i+=2) { // If an action URL, you're at the end of the URL if (in_array($segments[$i], ['edit'])) { break; } // Figure out the controller given the url partial $url .= '/' . $segments[$i]; $router = new Wildcard($segments[0], 'GET', $url); if (!($controller = $router->detectController())) { continue; } $controller = new $controller; // Add controller to breadcrumbs $breadcrumbs[URL::to($url)] = strip_tags($controller->title(), '<img>'); // Add a detail if it exists if (!isset($segments[$i+1])) { break; } $id = $segments[$i+1]; // On a "new" page if ($id == 'create') { $url .= '/' . $id; $breadcrumbs[URL::to($url)] = __('decoy::breadcrumbs.new'); // On an edit page } elseif (is_numeric($id)) { $url .= '/' . $id; $item = $this->find($controller, $id); $title = $item->getAdminTitleAttribute(); $breadcrumbs[URL::to($url.'/edit')] = $title; } } // Return the full list return $breadcrumbs; }
[ "public", "function", "parseURL", "(", ")", "{", "$", "breadcrumbs", "=", "[", "]", ";", "// Get the segments", "$", "path", "=", "Request", "::", "path", "(", ")", ";", "$", "segments", "=", "explode", "(", "'/'", ",", "$", "path", ")", ";", "// Loop through them in blocks of 2: [list, detail]", "$", "url", "=", "$", "segments", "[", "0", "]", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<", "count", "(", "$", "segments", ")", ";", "$", "i", "+=", "2", ")", "{", "// If an action URL, you're at the end of the URL", "if", "(", "in_array", "(", "$", "segments", "[", "$", "i", "]", ",", "[", "'edit'", "]", ")", ")", "{", "break", ";", "}", "// Figure out the controller given the url partial", "$", "url", ".=", "'/'", ".", "$", "segments", "[", "$", "i", "]", ";", "$", "router", "=", "new", "Wildcard", "(", "$", "segments", "[", "0", "]", ",", "'GET'", ",", "$", "url", ")", ";", "if", "(", "!", "(", "$", "controller", "=", "$", "router", "->", "detectController", "(", ")", ")", ")", "{", "continue", ";", "}", "$", "controller", "=", "new", "$", "controller", ";", "// Add controller to breadcrumbs", "$", "breadcrumbs", "[", "URL", "::", "to", "(", "$", "url", ")", "]", "=", "strip_tags", "(", "$", "controller", "->", "title", "(", ")", ",", "'<img>'", ")", ";", "// Add a detail if it exists", "if", "(", "!", "isset", "(", "$", "segments", "[", "$", "i", "+", "1", "]", ")", ")", "{", "break", ";", "}", "$", "id", "=", "$", "segments", "[", "$", "i", "+", "1", "]", ";", "// On a \"new\" page", "if", "(", "$", "id", "==", "'create'", ")", "{", "$", "url", ".=", "'/'", ".", "$", "id", ";", "$", "breadcrumbs", "[", "URL", "::", "to", "(", "$", "url", ")", "]", "=", "__", "(", "'decoy::breadcrumbs.new'", ")", ";", "// On an edit page", "}", "elseif", "(", "is_numeric", "(", "$", "id", ")", ")", "{", "$", "url", ".=", "'/'", ".", "$", "id", ";", "$", "item", "=", "$", "this", "->", "find", "(", "$", "controller", ",", "$", "id", ")", ";", "$", "title", "=", "$", "item", "->", "getAdminTitleAttribute", "(", ")", ";", "$", "breadcrumbs", "[", "URL", "::", "to", "(", "$", "url", ".", "'/edit'", ")", "]", "=", "$", "title", ";", "}", "}", "// Return the full list", "return", "$", "breadcrumbs", ";", "}" ]
Step through the URL, creating controller and model objects for relevant segments to populate richer data in the breadcrumbs, automatically @return array
[ "Step", "through", "the", "URL", "creating", "controller", "and", "model", "objects", "for", "relevant", "segments", "to", "populate", "richer", "data", "in", "the", "breadcrumbs", "automatically" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Layout/Breadcrumbs.php#L50-L100
30,728
BKWLD/decoy
classes/Layout/Breadcrumbs.php
Breadcrumbs.find
public function find($controller, $id) { $model = $controller->model(); if ($controller->withTrashed()) { return $model::withTrashed()->find($id); } else { return $model::find($id); } }
php
public function find($controller, $id) { $model = $controller->model(); if ($controller->withTrashed()) { return $model::withTrashed()->find($id); } else { return $model::find($id); } }
[ "public", "function", "find", "(", "$", "controller", ",", "$", "id", ")", "{", "$", "model", "=", "$", "controller", "->", "model", "(", ")", ";", "if", "(", "$", "controller", "->", "withTrashed", "(", ")", ")", "{", "return", "$", "model", "::", "withTrashed", "(", ")", "->", "find", "(", "$", "id", ")", ";", "}", "else", "{", "return", "$", "model", "::", "find", "(", "$", "id", ")", ";", "}", "}" ]
Lookup a model instance given the controller and id, including any trashed models in case the controller should show trashed models @param Controller\Base $controller @param integer $id @return Model
[ "Lookup", "a", "model", "instance", "given", "the", "controller", "and", "id", "including", "any", "trashed", "models", "in", "case", "the", "controller", "should", "show", "trashed", "models" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Layout/Breadcrumbs.php#L110-L118
30,729
BKWLD/decoy
classes/Layout/Breadcrumbs.php
Breadcrumbs.back
public function back() { // If there aren't enough breadcrumbs for a back URL, report false if (count($this->links) < 2) { return; } // Get the URL from two back from the end in the breadcrumbs array $urls = array_keys($this->links); return $urls[count($urls) - 2]; }
php
public function back() { // If there aren't enough breadcrumbs for a back URL, report false if (count($this->links) < 2) { return; } // Get the URL from two back from the end in the breadcrumbs array $urls = array_keys($this->links); return $urls[count($urls) - 2]; }
[ "public", "function", "back", "(", ")", "{", "// If there aren't enough breadcrumbs for a back URL, report false", "if", "(", "count", "(", "$", "this", "->", "links", ")", "<", "2", ")", "{", "return", ";", "}", "// Get the URL from two back from the end in the breadcrumbs array", "$", "urls", "=", "array_keys", "(", "$", "this", "->", "links", ")", ";", "return", "$", "urls", "[", "count", "(", "$", "urls", ")", "-", "2", "]", ";", "}" ]
Get the url for a back button given a breadcrumbs array. Or return false if there is no where to go back to. @return string|void
[ "Get", "the", "url", "for", "a", "back", "button", "given", "a", "breadcrumbs", "array", ".", "Or", "return", "false", "if", "there", "is", "no", "where", "to", "go", "back", "to", "." ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Layout/Breadcrumbs.php#L146-L158
30,730
BKWLD/decoy
classes/Layout/Breadcrumbs.php
Breadcrumbs.smartBack
public function smartBack() { // If we are on a listing page (an odd length), do the normal stuff // http://stackoverflow.com/a/9153969/59160 if (count($this->links) & 1) { return $this->back(); } // If we're on the first level detail page, do normal stuff if (count($this->links) === 2) { return $this->back(); } // Otherwise, skip the previous (the listing) and go direct to the previous detail $urls = array_keys($this->links); return $urls[count($urls) - 3]; }
php
public function smartBack() { // If we are on a listing page (an odd length), do the normal stuff // http://stackoverflow.com/a/9153969/59160 if (count($this->links) & 1) { return $this->back(); } // If we're on the first level detail page, do normal stuff if (count($this->links) === 2) { return $this->back(); } // Otherwise, skip the previous (the listing) and go direct to the previous detail $urls = array_keys($this->links); return $urls[count($urls) - 3]; }
[ "public", "function", "smartBack", "(", ")", "{", "// If we are on a listing page (an odd length), do the normal stuff", "// http://stackoverflow.com/a/9153969/59160", "if", "(", "count", "(", "$", "this", "->", "links", ")", "&", "1", ")", "{", "return", "$", "this", "->", "back", "(", ")", ";", "}", "// If we're on the first level detail page, do normal stuff", "if", "(", "count", "(", "$", "this", "->", "links", ")", "===", "2", ")", "{", "return", "$", "this", "->", "back", "(", ")", ";", "}", "// Otherwise, skip the previous (the listing) and go direct to the previous detail", "$", "urls", "=", "array_keys", "(", "$", "this", "->", "links", ")", ";", "return", "$", "urls", "[", "count", "(", "$", "urls", ")", "-", "3", "]", ";", "}" ]
If hitting back from a child detail page, goes to the parent detail page rather than to the child listing page. For instance, if you are editing the slides of a news page, when you go "back", it's back to the news page and not the listing of the news slides @return string
[ "If", "hitting", "back", "from", "a", "child", "detail", "page", "goes", "to", "the", "parent", "detail", "page", "rather", "than", "to", "the", "child", "listing", "page", ".", "For", "instance", "if", "you", "are", "editing", "the", "slides", "of", "a", "news", "page", "when", "you", "go", "back", "it", "s", "back", "to", "the", "news", "page", "and", "not", "the", "listing", "of", "the", "news", "slides" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Layout/Breadcrumbs.php#L168-L186
30,731
BKWLD/decoy
classes/Input/EncodingProviders/Zencoder.php
Zencoder.encode
public function encode($source, $preset) { // Tell the Zencoder SDK to create a job try { $outputs = $this->outputsConfig($preset); $job = $this->sdk()->jobs->create([ 'input' => $source, 'output' => $outputs, ]); // Store the response from the SDK $this->model->storeJob($job->id, $this->outputsToHash($job->outputs)); // Report an error with the encode } catch (Services_Zencoder_Exception $e) { $this->model->status('error', implode(' ', $this->zencoderArray($e->getErrors()))); } catch (Exception $e) { $this->model->status('error', $e->getMessage()); } }
php
public function encode($source, $preset) { // Tell the Zencoder SDK to create a job try { $outputs = $this->outputsConfig($preset); $job = $this->sdk()->jobs->create([ 'input' => $source, 'output' => $outputs, ]); // Store the response from the SDK $this->model->storeJob($job->id, $this->outputsToHash($job->outputs)); // Report an error with the encode } catch (Services_Zencoder_Exception $e) { $this->model->status('error', implode(' ', $this->zencoderArray($e->getErrors()))); } catch (Exception $e) { $this->model->status('error', $e->getMessage()); } }
[ "public", "function", "encode", "(", "$", "source", ",", "$", "preset", ")", "{", "// Tell the Zencoder SDK to create a job", "try", "{", "$", "outputs", "=", "$", "this", "->", "outputsConfig", "(", "$", "preset", ")", ";", "$", "job", "=", "$", "this", "->", "sdk", "(", ")", "->", "jobs", "->", "create", "(", "[", "'input'", "=>", "$", "source", ",", "'output'", "=>", "$", "outputs", ",", "]", ")", ";", "// Store the response from the SDK", "$", "this", "->", "model", "->", "storeJob", "(", "$", "job", "->", "id", ",", "$", "this", "->", "outputsToHash", "(", "$", "job", "->", "outputs", ")", ")", ";", "// Report an error with the encode", "}", "catch", "(", "Services_Zencoder_Exception", "$", "e", ")", "{", "$", "this", "->", "model", "->", "status", "(", "'error'", ",", "implode", "(", "' '", ",", "$", "this", "->", "zencoderArray", "(", "$", "e", "->", "getErrors", "(", ")", ")", ")", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "this", "->", "model", "->", "status", "(", "'error'", ",", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}" ]
Tell the service to encode an asset it's source @param string $source A full URL for the source asset @param string $preset The key to the preset function @return void
[ "Tell", "the", "service", "to", "encode", "an", "asset", "it", "s", "source" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/EncodingProviders/Zencoder.php#L58-L77
30,732
BKWLD/decoy
classes/Input/EncodingProviders/Zencoder.php
Zencoder.filterHLS
protected function filterHLS($config) { // Do not allow any outputs that have a type of "segmented" or "playlist" if (empty($config['playlist'])) { return array_filter($config, function ($output) { return !(isset($output['type']) && in_array($output['type'], ['segmented', 'playlist'])); }); } // Else, passthrough the config return $config; }
php
protected function filterHLS($config) { // Do not allow any outputs that have a type of "segmented" or "playlist" if (empty($config['playlist'])) { return array_filter($config, function ($output) { return !(isset($output['type']) && in_array($output['type'], ['segmented', 'playlist'])); }); } // Else, passthrough the config return $config; }
[ "protected", "function", "filterHLS", "(", "$", "config", ")", "{", "// Do not allow any outputs that have a type of \"segmented\" or \"playlist\"", "if", "(", "empty", "(", "$", "config", "[", "'playlist'", "]", ")", ")", "{", "return", "array_filter", "(", "$", "config", ",", "function", "(", "$", "output", ")", "{", "return", "!", "(", "isset", "(", "$", "output", "[", "'type'", "]", ")", "&&", "in_array", "(", "$", "output", "[", "'type'", "]", ",", "[", "'segmented'", ",", "'playlist'", "]", ")", ")", ";", "}", ")", ";", "}", "// Else, passthrough the config", "return", "$", "config", ";", "}" ]
If the playlist is set to `false` then remove all the HLS encodings. HLS is the "http live streaming" outputs that let us serve a video that can adjust quality levels in response to the bandwidth of the clietn. Works only on iPhone, Android, and Safari right now. @param array $config A config assoc array @return array
[ "If", "the", "playlist", "is", "set", "to", "false", "then", "remove", "all", "the", "HLS", "encodings", ".", "HLS", "is", "the", "http", "live", "streaming", "outputs", "that", "let", "us", "serve", "a", "video", "that", "can", "adjust", "quality", "levels", "in", "response", "to", "the", "bandwidth", "of", "the", "clietn", ".", "Works", "only", "on", "iPhone", "Android", "and", "Safari", "right", "now", "." ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/EncodingProviders/Zencoder.php#L104-L115
30,733
BKWLD/decoy
classes/Input/EncodingProviders/Zencoder.php
Zencoder.addCommonProps
protected function addCommonProps($outputs) { // Decoy settings $common = [ // Destination location as a directory 'base_url' => $this->destination(), // Register for notifications for when the conding is done. If testing // from CLI, just set the app.url config to a ngork domain. 'notifications' => [route('decoy::encode@notify')], ]; // Apply common settings ontop of the passed config foreach ($outputs as $label => &$config) { $common['label'] = $label; // Make the filename from the label $common['filename'] = $label.'.'.$config['format']; // Do the merge $config = array_merge($common, $config); } // Strip the keys from the array at this point, Zencoder doesn't like them return array_values($outputs); }
php
protected function addCommonProps($outputs) { // Decoy settings $common = [ // Destination location as a directory 'base_url' => $this->destination(), // Register for notifications for when the conding is done. If testing // from CLI, just set the app.url config to a ngork domain. 'notifications' => [route('decoy::encode@notify')], ]; // Apply common settings ontop of the passed config foreach ($outputs as $label => &$config) { $common['label'] = $label; // Make the filename from the label $common['filename'] = $label.'.'.$config['format']; // Do the merge $config = array_merge($common, $config); } // Strip the keys from the array at this point, Zencoder doesn't like them return array_values($outputs); }
[ "protected", "function", "addCommonProps", "(", "$", "outputs", ")", "{", "// Decoy settings", "$", "common", "=", "[", "// Destination location as a directory", "'base_url'", "=>", "$", "this", "->", "destination", "(", ")", ",", "// Register for notifications for when the conding is done. If testing", "// from CLI, just set the app.url config to a ngork domain.", "'notifications'", "=>", "[", "route", "(", "'decoy::encode@notify'", ")", "]", ",", "]", ";", "// Apply common settings ontop of the passed config", "foreach", "(", "$", "outputs", "as", "$", "label", "=>", "&", "$", "config", ")", "{", "$", "common", "[", "'label'", "]", "=", "$", "label", ";", "// Make the filename from the label", "$", "common", "[", "'filename'", "]", "=", "$", "label", ".", "'.'", ".", "$", "config", "[", "'format'", "]", ";", "// Do the merge", "$", "config", "=", "array_merge", "(", "$", "common", ",", "$", "config", ")", ";", "}", "// Strip the keys from the array at this point, Zencoder doesn't like them", "return", "array_values", "(", "$", "outputs", ")", ";", "}" ]
Update the config with properties that are common to all outputs @param array $config @return array
[ "Update", "the", "config", "with", "properties", "that", "are", "common", "to", "all", "outputs" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/EncodingProviders/Zencoder.php#L123-L150
30,734
BKWLD/decoy
classes/Input/EncodingProviders/Zencoder.php
Zencoder.outputsToHash
protected function outputsToHash($outputs) { return array_map(function ($output) { // If a destination_root was set, subsitute that in for the destination // in the retured URL if ($root = Config::get('decoy.encode.destination_root')) { return str_replace(Config::get('decoy.encode.destination'), $root, $output->url); } // Else just return the URL return $output->url; }, $this->zencoderArray($outputs)); }
php
protected function outputsToHash($outputs) { return array_map(function ($output) { // If a destination_root was set, subsitute that in for the destination // in the retured URL if ($root = Config::get('decoy.encode.destination_root')) { return str_replace(Config::get('decoy.encode.destination'), $root, $output->url); } // Else just return the URL return $output->url; }, $this->zencoderArray($outputs)); }
[ "protected", "function", "outputsToHash", "(", "$", "outputs", ")", "{", "return", "array_map", "(", "function", "(", "$", "output", ")", "{", "// If a destination_root was set, subsitute that in for the destination", "// in the retured URL", "if", "(", "$", "root", "=", "Config", "::", "get", "(", "'decoy.encode.destination_root'", ")", ")", "{", "return", "str_replace", "(", "Config", "::", "get", "(", "'decoy.encode.destination'", ")", ",", "$", "root", ",", "$", "output", "->", "url", ")", ";", "}", "// Else just return the URL", "return", "$", "output", "->", "url", ";", "}", ",", "$", "this", "->", "zencoderArray", "(", "$", "outputs", ")", ")", ";", "}" ]
Massage the outputs from Zencoder into a key-val associative array @param array $outputs @return array
[ "Massage", "the", "outputs", "from", "Zencoder", "into", "a", "key", "-", "val", "associative", "array" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/EncodingProviders/Zencoder.php#L158-L171
30,735
BKWLD/decoy
classes/Input/EncodingProviders/Zencoder.php
Zencoder.handleNotification
public function handleNotification($input) { // Parse the input $job = $this->sdk()->notifications->parseIncoming()->job; // Find the encoding model instance. If it's not found, then just // ignore it. This can easily happen if someone replaces a video // while one is being uploaded. if (!$model = Encoding::where('job_id', '=', $job->id)->first()) { return; } // Loop through the jobs and look for error messages. A job may recieve a // seperate notification for each output that has failed though the job // is still processessing. $errors = trim(implode(' ', array_map(function ($output) { return isset($output->error_message) ? '(Output '.$output->label.') '.$output->error_message : null; }, $this->zencoderArray($job->outputs)))); // If there were any messages, treat the job as errored. This also tries // to fix an issue I saw where a final "error" notifcation wasn't fired even // though multiple jobs failed. $state = empty($errors) ? $job->state : 'failed'; // Update the model switch ($state) { // Simple passthru of status case 'processing': case 'cancelled': $model->status($job->state); break; // Massage name case 'finished': $model->response = $input; $model->status('complete'); break; // Find error messages on the output case 'failed': $model->status('error', $errors); break; // Default default: $model->status('error', 'Unkown Zencoder state: '.$job->state); } }
php
public function handleNotification($input) { // Parse the input $job = $this->sdk()->notifications->parseIncoming()->job; // Find the encoding model instance. If it's not found, then just // ignore it. This can easily happen if someone replaces a video // while one is being uploaded. if (!$model = Encoding::where('job_id', '=', $job->id)->first()) { return; } // Loop through the jobs and look for error messages. A job may recieve a // seperate notification for each output that has failed though the job // is still processessing. $errors = trim(implode(' ', array_map(function ($output) { return isset($output->error_message) ? '(Output '.$output->label.') '.$output->error_message : null; }, $this->zencoderArray($job->outputs)))); // If there were any messages, treat the job as errored. This also tries // to fix an issue I saw where a final "error" notifcation wasn't fired even // though multiple jobs failed. $state = empty($errors) ? $job->state : 'failed'; // Update the model switch ($state) { // Simple passthru of status case 'processing': case 'cancelled': $model->status($job->state); break; // Massage name case 'finished': $model->response = $input; $model->status('complete'); break; // Find error messages on the output case 'failed': $model->status('error', $errors); break; // Default default: $model->status('error', 'Unkown Zencoder state: '.$job->state); } }
[ "public", "function", "handleNotification", "(", "$", "input", ")", "{", "// Parse the input", "$", "job", "=", "$", "this", "->", "sdk", "(", ")", "->", "notifications", "->", "parseIncoming", "(", ")", "->", "job", ";", "// Find the encoding model instance. If it's not found, then just", "// ignore it. This can easily happen if someone replaces a video", "// while one is being uploaded.", "if", "(", "!", "$", "model", "=", "Encoding", "::", "where", "(", "'job_id'", ",", "'='", ",", "$", "job", "->", "id", ")", "->", "first", "(", ")", ")", "{", "return", ";", "}", "// Loop through the jobs and look for error messages. A job may recieve a", "// seperate notification for each output that has failed though the job", "// is still processessing.", "$", "errors", "=", "trim", "(", "implode", "(", "' '", ",", "array_map", "(", "function", "(", "$", "output", ")", "{", "return", "isset", "(", "$", "output", "->", "error_message", ")", "?", "'(Output '", ".", "$", "output", "->", "label", ".", "') '", ".", "$", "output", "->", "error_message", ":", "null", ";", "}", ",", "$", "this", "->", "zencoderArray", "(", "$", "job", "->", "outputs", ")", ")", ")", ")", ";", "// If there were any messages, treat the job as errored. This also tries", "// to fix an issue I saw where a final \"error\" notifcation wasn't fired even", "// though multiple jobs failed.", "$", "state", "=", "empty", "(", "$", "errors", ")", "?", "$", "job", "->", "state", ":", "'failed'", ";", "// Update the model", "switch", "(", "$", "state", ")", "{", "// Simple passthru of status", "case", "'processing'", ":", "case", "'cancelled'", ":", "$", "model", "->", "status", "(", "$", "job", "->", "state", ")", ";", "break", ";", "// Massage name", "case", "'finished'", ":", "$", "model", "->", "response", "=", "$", "input", ";", "$", "model", "->", "status", "(", "'complete'", ")", ";", "break", ";", "// Find error messages on the output", "case", "'failed'", ":", "$", "model", "->", "status", "(", "'error'", ",", "$", "errors", ")", ";", "break", ";", "// Default", "default", ":", "$", "model", "->", "status", "(", "'error'", ",", "'Unkown Zencoder state: '", ".", "$", "job", "->", "state", ")", ";", "}", "}" ]
Handle notification requests from the SDK @param array $input Request::input() @return mixed Reponse to the API
[ "Handle", "notification", "requests", "from", "the", "SDK" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/EncodingProviders/Zencoder.php#L179-L227
30,736
BKWLD/decoy
classes/Input/EncodingProviders/Zencoder.php
Zencoder.progress
public function progress() { try { $progress = $this->sdk()->jobs->progress($this->model->job_id); if ($progress->state == 'finished') { return 100; } return $progress->progress; } catch (\Exception $e) { return 0; } }
php
public function progress() { try { $progress = $this->sdk()->jobs->progress($this->model->job_id); if ($progress->state == 'finished') { return 100; } return $progress->progress; } catch (\Exception $e) { return 0; } }
[ "public", "function", "progress", "(", ")", "{", "try", "{", "$", "progress", "=", "$", "this", "->", "sdk", "(", ")", "->", "jobs", "->", "progress", "(", "$", "this", "->", "model", "->", "job_id", ")", ";", "if", "(", "$", "progress", "->", "state", "==", "'finished'", ")", "{", "return", "100", ";", "}", "return", "$", "progress", "->", "progress", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "return", "0", ";", "}", "}" ]
Return the encoding percentage as an int @return int 0-100
[ "Return", "the", "encoding", "percentage", "as", "an", "int" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/EncodingProviders/Zencoder.php#L234-L246
30,737
BKWLD/decoy
classes/Input/EncodingProviders/Zencoder.php
Zencoder.zencoderArray
public function zencoderArray($obj) { if (is_array($obj)) { return $obj; } if (is_a($obj, 'Services_Zencoder_Object')) { return get_object_vars($obj); } throw new Exception('Unexpected object: '.get_class($obj)); }
php
public function zencoderArray($obj) { if (is_array($obj)) { return $obj; } if (is_a($obj, 'Services_Zencoder_Object')) { return get_object_vars($obj); } throw new Exception('Unexpected object: '.get_class($obj)); }
[ "public", "function", "zencoderArray", "(", "$", "obj", ")", "{", "if", "(", "is_array", "(", "$", "obj", ")", ")", "{", "return", "$", "obj", ";", "}", "if", "(", "is_a", "(", "$", "obj", ",", "'Services_Zencoder_Object'", ")", ")", "{", "return", "get_object_vars", "(", "$", "obj", ")", ";", "}", "throw", "new", "Exception", "(", "'Unexpected object: '", ".", "get_class", "(", "$", "obj", ")", ")", ";", "}" ]
Convert a Services_Zencoder_Object object to an array @param Services_Zencoder_Object|array $obj @return array
[ "Convert", "a", "Services_Zencoder_Object", "object", "to", "an", "array" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/EncodingProviders/Zencoder.php#L264-L275
30,738
BKWLD/decoy
classes/Exceptions/Handler.php
Handler.handle404s
protected function handle404s($request, BaseException $e) { // Check for right exception if (!is_a($e, ModelNotFoundException::class) && !is_a($e, NotFoundHttpException::class)) { return; } // Check for a valid redirect if ($rule = RedirectRule::matchUsingRequest()->first()) { return redirect($rule->to, $rule->code); } // Return header only on AJAX if ($request->ajax()) { return response(null, 404); } }
php
protected function handle404s($request, BaseException $e) { // Check for right exception if (!is_a($e, ModelNotFoundException::class) && !is_a($e, NotFoundHttpException::class)) { return; } // Check for a valid redirect if ($rule = RedirectRule::matchUsingRequest()->first()) { return redirect($rule->to, $rule->code); } // Return header only on AJAX if ($request->ajax()) { return response(null, 404); } }
[ "protected", "function", "handle404s", "(", "$", "request", ",", "BaseException", "$", "e", ")", "{", "// Check for right exception", "if", "(", "!", "is_a", "(", "$", "e", ",", "ModelNotFoundException", "::", "class", ")", "&&", "!", "is_a", "(", "$", "e", ",", "NotFoundHttpException", "::", "class", ")", ")", "{", "return", ";", "}", "// Check for a valid redirect", "if", "(", "$", "rule", "=", "RedirectRule", "::", "matchUsingRequest", "(", ")", "->", "first", "(", ")", ")", "{", "return", "redirect", "(", "$", "rule", "->", "to", ",", "$", "rule", "->", "code", ")", ";", "}", "// Return header only on AJAX", "if", "(", "$", "request", "->", "ajax", "(", ")", ")", "{", "return", "response", "(", "null", ",", "404", ")", ";", "}", "}" ]
If a 404 exception, check if there is a redirect rule. Or return a simple header if an AJAX request. @param \Illuminate\Http\Request $request @param \Exception $e @return \Illuminate\Http\RedirectResponse
[ "If", "a", "404", "exception", "check", "if", "there", "is", "a", "redirect", "rule", ".", "Or", "return", "a", "simple", "header", "if", "an", "AJAX", "request", "." ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Exceptions/Handler.php#L51-L67
30,739
BKWLD/decoy
classes/Exceptions/Handler.php
Handler.handleValidation
protected function handleValidation($request, BaseException $e) { if (!is_a($e, ValidationFail::class)) { return; } // Log validation errors so Reporter will output them // if (Config::get('app.debug')) Log::debug(print_r($e->validation->messages(), true)); // Respond if ($request->ajax()) { return response()->json($e->validation->messages(), 400); } return back()->withInput()->withErrors($e->validation); }
php
protected function handleValidation($request, BaseException $e) { if (!is_a($e, ValidationFail::class)) { return; } // Log validation errors so Reporter will output them // if (Config::get('app.debug')) Log::debug(print_r($e->validation->messages(), true)); // Respond if ($request->ajax()) { return response()->json($e->validation->messages(), 400); } return back()->withInput()->withErrors($e->validation); }
[ "protected", "function", "handleValidation", "(", "$", "request", ",", "BaseException", "$", "e", ")", "{", "if", "(", "!", "is_a", "(", "$", "e", ",", "ValidationFail", "::", "class", ")", ")", "{", "return", ";", "}", "// Log validation errors so Reporter will output them", "// if (Config::get('app.debug')) Log::debug(print_r($e->validation->messages(), true));", "// Respond", "if", "(", "$", "request", "->", "ajax", "(", ")", ")", "{", "return", "response", "(", ")", "->", "json", "(", "$", "e", "->", "validation", "->", "messages", "(", ")", ",", "400", ")", ";", "}", "return", "back", "(", ")", "->", "withInput", "(", ")", "->", "withErrors", "(", "$", "e", "->", "validation", ")", ";", "}" ]
Redirect users to the previous page with validation errors @param \Illuminate\Http\Request $request @param \Exception $e @return \Illuminate\Http\Response
[ "Redirect", "users", "to", "the", "previous", "page", "with", "validation", "errors" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Exceptions/Handler.php#L91-L106
30,740
BKWLD/decoy
classes/Controllers/Traits/Exportable.php
Exportable.makeCsvFileTitle
protected function makeCsvFileTitle() { return vsprintf('%s %s as of %s at %s.csv', [ Decoy::site(), $this->title(), Carbon::now()->format('n.j.y'), Carbon::now()->format('g:i A'), ]); }
php
protected function makeCsvFileTitle() { return vsprintf('%s %s as of %s at %s.csv', [ Decoy::site(), $this->title(), Carbon::now()->format('n.j.y'), Carbon::now()->format('g:i A'), ]); }
[ "protected", "function", "makeCsvFileTitle", "(", ")", "{", "return", "vsprintf", "(", "'%s %s as of %s at %s.csv'", ",", "[", "Decoy", "::", "site", "(", ")", ",", "$", "this", "->", "title", "(", ")", ",", "Carbon", "::", "now", "(", ")", "->", "format", "(", "'n.j.y'", ")", ",", "Carbon", "::", "now", "(", ")", "->", "format", "(", "'g:i A'", ")", ",", "]", ")", ";", "}" ]
Make the title of the CSV @return string
[ "Make", "the", "title", "of", "the", "CSV" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Traits/Exportable.php#L86-L94
30,741
BKWLD/decoy
classes/Observers/Encoding.php
Encoding.onSaving
public function onSaving($event, $payload) { list($model) = $payload; if (!$this->isEncodable($model)) { return; } foreach ($model->getDirtyEncodableAttributes() as $attribute) { // If the attribute has a value, encode the attribute if ($model->getAttribute($attribute)) { $model->encodeOnSave($attribute); } // Otherwise delete encoding references elseif ($encoding = $model->encoding($attribute)) { $encoding->delete(); } } }
php
public function onSaving($event, $payload) { list($model) = $payload; if (!$this->isEncodable($model)) { return; } foreach ($model->getDirtyEncodableAttributes() as $attribute) { // If the attribute has a value, encode the attribute if ($model->getAttribute($attribute)) { $model->encodeOnSave($attribute); } // Otherwise delete encoding references elseif ($encoding = $model->encoding($attribute)) { $encoding->delete(); } } }
[ "public", "function", "onSaving", "(", "$", "event", ",", "$", "payload", ")", "{", "list", "(", "$", "model", ")", "=", "$", "payload", ";", "if", "(", "!", "$", "this", "->", "isEncodable", "(", "$", "model", ")", ")", "{", "return", ";", "}", "foreach", "(", "$", "model", "->", "getDirtyEncodableAttributes", "(", ")", "as", "$", "attribute", ")", "{", "// If the attribute has a value, encode the attribute", "if", "(", "$", "model", "->", "getAttribute", "(", "$", "attribute", ")", ")", "{", "$", "model", "->", "encodeOnSave", "(", "$", "attribute", ")", ";", "}", "// Otherwise delete encoding references", "elseif", "(", "$", "encoding", "=", "$", "model", "->", "encoding", "(", "$", "attribute", ")", ")", "{", "$", "encoding", "->", "delete", "(", ")", ";", "}", "}", "}" ]
Start a new encode if a new encodable file was uploaded @param string $event @param array $payload Contains: - Bkwld\Decoy\Models\Base $model @return void
[ "Start", "a", "new", "encode", "if", "a", "new", "encodable", "file", "was", "uploaded" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Observers/Encoding.php#L18-L38
30,742
BKWLD/decoy
classes/Observers/Encoding.php
Encoding.isEncodable
public function isEncodable($model) { if (!method_exists($model, 'getDirtyEncodableAttributes')) { return false; } if (is_a($model, 'Bkwld\Decoy\Models\Element') && $model->getAttribute('type') != 'video-encoder') { return false; } return true; }
php
public function isEncodable($model) { if (!method_exists($model, 'getDirtyEncodableAttributes')) { return false; } if (is_a($model, 'Bkwld\Decoy\Models\Element') && $model->getAttribute('type') != 'video-encoder') { return false; } return true; }
[ "public", "function", "isEncodable", "(", "$", "model", ")", "{", "if", "(", "!", "method_exists", "(", "$", "model", ",", "'getDirtyEncodableAttributes'", ")", ")", "{", "return", "false", ";", "}", "if", "(", "is_a", "(", "$", "model", ",", "'Bkwld\\Decoy\\Models\\Element'", ")", "&&", "$", "model", "->", "getAttribute", "(", "'type'", ")", "!=", "'video-encoder'", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Check if a model should be encoded @param Bkwld\Decoy\Models\Base $model @return boolean
[ "Check", "if", "a", "model", "should", "be", "encoded" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Observers/Encoding.php#L62-L73
30,743
BKWLD/decoy
classes/Observers/Localize.php
Localize.handle
public function handle($event, $payload) { list($model) = $payload; if (!empty($model->locale) && empty($model->locale_group) && !is_a($model, Element::class) // Elements don't have groups && ($locales = Config::get('decoy.site.locales')) && count($locales) > 1) { $model->setAttribute('locale_group', Str::random()); } }
php
public function handle($event, $payload) { list($model) = $payload; if (!empty($model->locale) && empty($model->locale_group) && !is_a($model, Element::class) // Elements don't have groups && ($locales = Config::get('decoy.site.locales')) && count($locales) > 1) { $model->setAttribute('locale_group', Str::random()); } }
[ "public", "function", "handle", "(", "$", "event", ",", "$", "payload", ")", "{", "list", "(", "$", "model", ")", "=", "$", "payload", ";", "if", "(", "!", "empty", "(", "$", "model", "->", "locale", ")", "&&", "empty", "(", "$", "model", "->", "locale_group", ")", "&&", "!", "is_a", "(", "$", "model", ",", "Element", "::", "class", ")", "// Elements don't have groups", "&&", "(", "$", "locales", "=", "Config", "::", "get", "(", "'decoy.site.locales'", ")", ")", "&&", "count", "(", "$", "locales", ")", ">", "1", ")", "{", "$", "model", "->", "setAttribute", "(", "'locale_group'", ",", "Str", "::", "random", "(", ")", ")", ";", "}", "}" ]
Called on model saving @param string $event @param array $payload Contains: - Bkwld\Decoy\Models\Base $model @return void
[ "Called", "on", "model", "saving" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Observers/Localize.php#L23-L34
30,744
BKWLD/decoy
classes/Middleware/Auth.php
Auth.dectectFromExplicitRoute
protected function dectectFromExplicitRoute() { // Get the action $action = Route::current()->getActionName(); if ($action == 'Closure') { throw new \Exception('decoy.auth requires routing to controllers.'); } // Get parse the `uses` from the route definition preg_match('#(.+)@(.+)#', Route::current()->getActionName(), $matches); $controller = $matches[1]; $action = $matches[2]; // Further mapping of the action $action = $this->mapActionToPermission($action); // Return the detected action and controller return [$action, $controller]; }
php
protected function dectectFromExplicitRoute() { // Get the action $action = Route::current()->getActionName(); if ($action == 'Closure') { throw new \Exception('decoy.auth requires routing to controllers.'); } // Get parse the `uses` from the route definition preg_match('#(.+)@(.+)#', Route::current()->getActionName(), $matches); $controller = $matches[1]; $action = $matches[2]; // Further mapping of the action $action = $this->mapActionToPermission($action); // Return the detected action and controller return [$action, $controller]; }
[ "protected", "function", "dectectFromExplicitRoute", "(", ")", "{", "// Get the action", "$", "action", "=", "Route", "::", "current", "(", ")", "->", "getActionName", "(", ")", ";", "if", "(", "$", "action", "==", "'Closure'", ")", "{", "throw", "new", "\\", "Exception", "(", "'decoy.auth requires routing to controllers.'", ")", ";", "}", "// Get parse the `uses` from the route definition", "preg_match", "(", "'#(.+)@(.+)#'", ",", "Route", "::", "current", "(", ")", "->", "getActionName", "(", ")", ",", "$", "matches", ")", ";", "$", "controller", "=", "$", "matches", "[", "1", "]", ";", "$", "action", "=", "$", "matches", "[", "2", "]", ";", "// Further mapping of the action", "$", "action", "=", "$", "this", "->", "mapActionToPermission", "(", "$", "action", ")", ";", "// Return the detected action and controller", "return", "[", "$", "action", ",", "$", "controller", "]", ";", "}" ]
Get the action and controller from an explicilty defined route @return array action,controller @throws Exception
[ "Get", "the", "action", "and", "controller", "from", "an", "explicilty", "defined", "route" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Middleware/Auth.php#L57-L75
30,745
BKWLD/decoy
classes/Middleware/Auth.php
Auth.dectectFromWildcardRouter
protected function dectectFromWildcardRouter() { $wildcard = App::make('decoy.wildcard'); // Attach / detach are ACL-ed by the parent controller. It's the one being // touched, $action = $wildcard->detectAction(); if (in_array($action, ['attach', 'remove'])) { $controller = request('parent_controller'); $action = 'update'; // Otherwise, use the controller from the route } else { $controller = $wildcard->detectControllerName(); } // Further mapping of the action $action = $this->mapActionToPermission($action); // Return the detected action and controller return [$action, $controller]; }
php
protected function dectectFromWildcardRouter() { $wildcard = App::make('decoy.wildcard'); // Attach / detach are ACL-ed by the parent controller. It's the one being // touched, $action = $wildcard->detectAction(); if (in_array($action, ['attach', 'remove'])) { $controller = request('parent_controller'); $action = 'update'; // Otherwise, use the controller from the route } else { $controller = $wildcard->detectControllerName(); } // Further mapping of the action $action = $this->mapActionToPermission($action); // Return the detected action and controller return [$action, $controller]; }
[ "protected", "function", "dectectFromWildcardRouter", "(", ")", "{", "$", "wildcard", "=", "App", "::", "make", "(", "'decoy.wildcard'", ")", ";", "// Attach / detach are ACL-ed by the parent controller. It's the one being", "// touched,", "$", "action", "=", "$", "wildcard", "->", "detectAction", "(", ")", ";", "if", "(", "in_array", "(", "$", "action", ",", "[", "'attach'", ",", "'remove'", "]", ")", ")", "{", "$", "controller", "=", "request", "(", "'parent_controller'", ")", ";", "$", "action", "=", "'update'", ";", "// Otherwise, use the controller from the route", "}", "else", "{", "$", "controller", "=", "$", "wildcard", "->", "detectControllerName", "(", ")", ";", "}", "// Further mapping of the action", "$", "action", "=", "$", "this", "->", "mapActionToPermission", "(", "$", "action", ")", ";", "// Return the detected action and controller", "return", "[", "$", "action", ",", "$", "controller", "]", ";", "}" ]
Get the action and controller from the wildcard router @return array action,controller
[ "Get", "the", "action", "and", "controller", "from", "the", "wildcard", "router" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Middleware/Auth.php#L82-L103
30,746
BKWLD/decoy
classes/Models/Admin.php
Admin.onValidating
public function onValidating($validation) { // Only apply mods when editing an existing record if (!$this->exists) { return; } $rules = self::$rules; // Make password optional $rules = array_except($rules, 'password'); // Ignore the current record when validating email $rules['email'] .= ','.$this->id; // Update rules $validation->setRules($rules); }
php
public function onValidating($validation) { // Only apply mods when editing an existing record if (!$this->exists) { return; } $rules = self::$rules; // Make password optional $rules = array_except($rules, 'password'); // Ignore the current record when validating email $rules['email'] .= ','.$this->id; // Update rules $validation->setRules($rules); }
[ "public", "function", "onValidating", "(", "$", "validation", ")", "{", "// Only apply mods when editing an existing record", "if", "(", "!", "$", "this", "->", "exists", ")", "{", "return", ";", "}", "$", "rules", "=", "self", "::", "$", "rules", ";", "// Make password optional", "$", "rules", "=", "array_except", "(", "$", "rules", ",", "'password'", ")", ";", "// Ignore the current record when validating email", "$", "rules", "[", "'email'", "]", ".=", "','", ".", "$", "this", "->", "id", ";", "// Update rules", "$", "validation", "->", "setRules", "(", "$", "rules", ")", ";", "}" ]
Tweak some validation rules @param Illuminate\Validation\Validator $validation
[ "Tweak", "some", "validation", "rules" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Admin.php#L84-L101
30,747
BKWLD/decoy
classes/Models/Admin.php
Admin.onCreating
public function onCreating() { // Send out email if (Request::has('_send_email')) { $this->sendCreateEmail(); } // Make them active $this->active = 1; // If the current user can't grant permissions, make the new admin // have the same role as themselves. Admins created from the CLI (like as // part of a migration) won't be logged in. if (($admin = app('decoy.user')) && !app('decoy.user')->can('grant', 'admins')) { $this->role = $admin->role; // Otherwise, give the admin a default role if none was defined } elseif (empty($this->role)) { $this->role = 'admin'; } }
php
public function onCreating() { // Send out email if (Request::has('_send_email')) { $this->sendCreateEmail(); } // Make them active $this->active = 1; // If the current user can't grant permissions, make the new admin // have the same role as themselves. Admins created from the CLI (like as // part of a migration) won't be logged in. if (($admin = app('decoy.user')) && !app('decoy.user')->can('grant', 'admins')) { $this->role = $admin->role; // Otherwise, give the admin a default role if none was defined } elseif (empty($this->role)) { $this->role = 'admin'; } }
[ "public", "function", "onCreating", "(", ")", "{", "// Send out email", "if", "(", "Request", "::", "has", "(", "'_send_email'", ")", ")", "{", "$", "this", "->", "sendCreateEmail", "(", ")", ";", "}", "// Make them active", "$", "this", "->", "active", "=", "1", ";", "// If the current user can't grant permissions, make the new admin", "// have the same role as themselves. Admins created from the CLI (like as", "// part of a migration) won't be logged in.", "if", "(", "(", "$", "admin", "=", "app", "(", "'decoy.user'", ")", ")", "&&", "!", "app", "(", "'decoy.user'", ")", "->", "can", "(", "'grant'", ",", "'admins'", ")", ")", "{", "$", "this", "->", "role", "=", "$", "admin", "->", "role", ";", "// Otherwise, give the admin a default role if none was defined", "}", "elseif", "(", "empty", "(", "$", "this", "->", "role", ")", ")", "{", "$", "this", "->", "role", "=", "'admin'", ";", "}", "}" ]
New admin callbacks @return void
[ "New", "admin", "callbacks" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Admin.php#L108-L129
30,748
BKWLD/decoy
classes/Models/Admin.php
Admin.onSaving
public function onSaving() { // If the password is changing, hash it if ($this->isDirty('password')) { $this->password = bcrypt($this->password); } // Save or clear permission choices if the form had a "custom permissions" // pushed checkbox if (Request::exists('_custom_permissions')) { $this->permissions = request('_custom_permissions') ? json_encode(request('_permission')) : null; } }
php
public function onSaving() { // If the password is changing, hash it if ($this->isDirty('password')) { $this->password = bcrypt($this->password); } // Save or clear permission choices if the form had a "custom permissions" // pushed checkbox if (Request::exists('_custom_permissions')) { $this->permissions = request('_custom_permissions') ? json_encode(request('_permission')) : null; } }
[ "public", "function", "onSaving", "(", ")", "{", "// If the password is changing, hash it", "if", "(", "$", "this", "->", "isDirty", "(", "'password'", ")", ")", "{", "$", "this", "->", "password", "=", "bcrypt", "(", "$", "this", "->", "password", ")", ";", "}", "// Save or clear permission choices if the form had a \"custom permissions\"", "// pushed checkbox", "if", "(", "Request", "::", "exists", "(", "'_custom_permissions'", ")", ")", "{", "$", "this", "->", "permissions", "=", "request", "(", "'_custom_permissions'", ")", "?", "json_encode", "(", "request", "(", "'_permission'", ")", ")", ":", "null", ";", "}", "}" ]
Callbacks regardless of new or old @return void
[ "Callbacks", "regardless", "of", "new", "or", "old" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Admin.php#L148-L161
30,749
BKWLD/decoy
classes/Models/Admin.php
Admin.sendUpdateEmail
public function sendUpdateEmail() { // Prepare data for mail $admin = app('decoy.user'); $email = [ 'editor_first_name' => $admin->first_name, 'editor_last_name' => $admin->last_name, 'first_name' =>request('first_name'), 'last_name' =>request('last_name'), 'email' => request('email'), 'password' =>request('password'), 'url' => Request::root().'/'.Config::get('decoy.core.dir'), 'root' => Request::root(), ]; // Send the email Mail::send('decoy::emails.update', $email, function ($m) use ($email) { $m->to($email['email'], $email['first_name'].' '.$email['last_name']); $m->subject('Your '.Decoy::site().' admin account info has been updated'); }); }
php
public function sendUpdateEmail() { // Prepare data for mail $admin = app('decoy.user'); $email = [ 'editor_first_name' => $admin->first_name, 'editor_last_name' => $admin->last_name, 'first_name' =>request('first_name'), 'last_name' =>request('last_name'), 'email' => request('email'), 'password' =>request('password'), 'url' => Request::root().'/'.Config::get('decoy.core.dir'), 'root' => Request::root(), ]; // Send the email Mail::send('decoy::emails.update', $email, function ($m) use ($email) { $m->to($email['email'], $email['first_name'].' '.$email['last_name']); $m->subject('Your '.Decoy::site().' admin account info has been updated'); }); }
[ "public", "function", "sendUpdateEmail", "(", ")", "{", "// Prepare data for mail", "$", "admin", "=", "app", "(", "'decoy.user'", ")", ";", "$", "email", "=", "[", "'editor_first_name'", "=>", "$", "admin", "->", "first_name", ",", "'editor_last_name'", "=>", "$", "admin", "->", "last_name", ",", "'first_name'", "=>", "request", "(", "'first_name'", ")", ",", "'last_name'", "=>", "request", "(", "'last_name'", ")", ",", "'email'", "=>", "request", "(", "'email'", ")", ",", "'password'", "=>", "request", "(", "'password'", ")", ",", "'url'", "=>", "Request", "::", "root", "(", ")", ".", "'/'", ".", "Config", "::", "get", "(", "'decoy.core.dir'", ")", ",", "'root'", "=>", "Request", "::", "root", "(", ")", ",", "]", ";", "// Send the email", "Mail", "::", "send", "(", "'decoy::emails.update'", ",", "$", "email", ",", "function", "(", "$", "m", ")", "use", "(", "$", "email", ")", "{", "$", "m", "->", "to", "(", "$", "email", "[", "'email'", "]", ",", "$", "email", "[", "'first_name'", "]", ".", "' '", ".", "$", "email", "[", "'last_name'", "]", ")", ";", "$", "m", "->", "subject", "(", "'Your '", ".", "Decoy", "::", "site", "(", ")", ".", "' admin account info has been updated'", ")", ";", "}", ")", ";", "}" ]
Send update email @return void
[ "Send", "update", "email" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Admin.php#L193-L213
30,750
BKWLD/decoy
classes/Models/Admin.php
Admin.shouldLogChange
public function shouldLogChange($action) { if ($action != 'deleted' && count($this->getDirty()) == 1 && $this->isDirty('remember_token')) { return false; } return parent::shouldLogChange($action); }
php
public function shouldLogChange($action) { if ($action != 'deleted' && count($this->getDirty()) == 1 && $this->isDirty('remember_token')) { return false; } return parent::shouldLogChange($action); }
[ "public", "function", "shouldLogChange", "(", "$", "action", ")", "{", "if", "(", "$", "action", "!=", "'deleted'", "&&", "count", "(", "$", "this", "->", "getDirty", "(", ")", ")", "==", "1", "&&", "$", "this", "->", "isDirty", "(", "'remember_token'", ")", ")", "{", "return", "false", ";", "}", "return", "parent", "::", "shouldLogChange", "(", "$", "action", ")", ";", "}" ]
Don't log if admin is logging in and out @param string $action @return boolean
[ "Don", "t", "log", "if", "admin", "is", "logging", "in", "and", "out" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Admin.php#L259-L267
30,751
BKWLD/decoy
classes/Models/Admin.php
Admin.getAdminStatusAttribute
public function getAdminStatusAttribute() { $html =''; // Add the role if (($roles = static::getRoleTitles()) && count($roles)) { $html .= '<span class="label label-primary">'.$roles[$this->role].'</span>'; } // If row is you if ($this->id == app('decoy.user')->id) { $html .= '<span class="label label-info">' . __('decoy::admins.standard_list.you') . '</span>'; } // If row is disabled if ($this->disabled()) { $html .= '<a href="' . URL::to(DecoyURL::relative('enable', $this->id)) . '" class="label label-warning js-tooltip" title="' . __('decoy::admins.standard_list.click') . '">' . __('decoy::admins.standard_list.disabled') . '</a>'; } // Return HTML return $html; }
php
public function getAdminStatusAttribute() { $html =''; // Add the role if (($roles = static::getRoleTitles()) && count($roles)) { $html .= '<span class="label label-primary">'.$roles[$this->role].'</span>'; } // If row is you if ($this->id == app('decoy.user')->id) { $html .= '<span class="label label-info">' . __('decoy::admins.standard_list.you') . '</span>'; } // If row is disabled if ($this->disabled()) { $html .= '<a href="' . URL::to(DecoyURL::relative('enable', $this->id)) . '" class="label label-warning js-tooltip" title="' . __('decoy::admins.standard_list.click') . '">' . __('decoy::admins.standard_list.disabled') . '</a>'; } // Return HTML return $html; }
[ "public", "function", "getAdminStatusAttribute", "(", ")", "{", "$", "html", "=", "''", ";", "// Add the role", "if", "(", "(", "$", "roles", "=", "static", "::", "getRoleTitles", "(", ")", ")", "&&", "count", "(", "$", "roles", ")", ")", "{", "$", "html", ".=", "'<span class=\"label label-primary\">'", ".", "$", "roles", "[", "$", "this", "->", "role", "]", ".", "'</span>'", ";", "}", "// If row is you", "if", "(", "$", "this", "->", "id", "==", "app", "(", "'decoy.user'", ")", "->", "id", ")", "{", "$", "html", ".=", "'<span class=\"label label-info\">'", ".", "__", "(", "'decoy::admins.standard_list.you'", ")", ".", "'</span>'", ";", "}", "// If row is disabled", "if", "(", "$", "this", "->", "disabled", "(", ")", ")", "{", "$", "html", ".=", "'<a href=\"'", ".", "URL", "::", "to", "(", "DecoyURL", "::", "relative", "(", "'enable'", ",", "$", "this", "->", "id", ")", ")", ".", "'\" class=\"label label-warning\n js-tooltip\" title=\"'", ".", "__", "(", "'decoy::admins.standard_list.click'", ")", ".", "'\">'", ".", "__", "(", "'decoy::admins.standard_list.disabled'", ")", ".", "'</a>'", ";", "}", "// Return HTML", "return", "$", "html", ";", "}" ]
Show a badge if the user is the currently logged in @return string
[ "Show", "a", "badge", "if", "the", "user", "is", "the", "currently", "logged", "in" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Admin.php#L319-L342
30,752
BKWLD/decoy
classes/Models/Admin.php
Admin.getPermissionOptions
public static function getPermissionOptions($admin = null) { // Get all the app controllers $controllers = array_map(function($path) { return 'App\Http\Controllers\Admin\\'.basename($path, '.php'); }, glob(app_path('/Http/Controllers/Admin/*.php'))); // Add some Decoy controllers $controllers[] = 'Bkwld\Decoy\Controllers\Admins'; $controllers[] = 'Bkwld\Decoy\Controllers\Changes'; $controllers[] = 'Bkwld\Decoy\Controllers\Elements'; $controllers[] = 'Bkwld\Decoy\Controllers\RedirectRules'; // Alphabetize the controller classes usort($controllers, function ($a, $b) { return substr($a, strrpos($a, '\\') + 1) > substr($b, strrpos($b, '\\') + 1); }); // Convert the list of controller classes into the shorthand strings used // by Decoy Auth as well as english name and desciption return array_map(function ($class) use ($admin) { $obj = new $class; $permissions = $obj->getPermissionOptions(); if (!is_array($permissions)) { $permissions = []; } // Build the controller-level node return (object) [ // Add controller information 'slug' => DecoyURL::slugController($class), 'title' => $obj->title(), 'description' => $obj->description(), // Add permission options for the controller 'permissions' => array_map(function ($value, $action) use ($class, $admin) { $roles = array_keys(Config::get('decoy.site.roles')); return (object) [ 'slug' => $action, 'title' => is_array($value) ? $value[0] : Text::titleFromKey($action), 'description' => is_array($value) ? $value[1] : $value, // Set the initial checked state based on the admin's permissions, if // one is set. Or based on the first role. 'checked' => $admin ? $admin->can($action, $class) : with(new Admin(['role' => $roles[0]]))->can($action, $class), // Filter the list of roles to just the roles that allow the // permission currently being iterated through 'roles' => array_filter($roles, function ($role) use ($action, $class) { return with(new Admin(['role' => $role]))->can($action, $class); }), ]; }, $permissions, array_keys($permissions)), ]; }, $controllers); }
php
public static function getPermissionOptions($admin = null) { // Get all the app controllers $controllers = array_map(function($path) { return 'App\Http\Controllers\Admin\\'.basename($path, '.php'); }, glob(app_path('/Http/Controllers/Admin/*.php'))); // Add some Decoy controllers $controllers[] = 'Bkwld\Decoy\Controllers\Admins'; $controllers[] = 'Bkwld\Decoy\Controllers\Changes'; $controllers[] = 'Bkwld\Decoy\Controllers\Elements'; $controllers[] = 'Bkwld\Decoy\Controllers\RedirectRules'; // Alphabetize the controller classes usort($controllers, function ($a, $b) { return substr($a, strrpos($a, '\\') + 1) > substr($b, strrpos($b, '\\') + 1); }); // Convert the list of controller classes into the shorthand strings used // by Decoy Auth as well as english name and desciption return array_map(function ($class) use ($admin) { $obj = new $class; $permissions = $obj->getPermissionOptions(); if (!is_array($permissions)) { $permissions = []; } // Build the controller-level node return (object) [ // Add controller information 'slug' => DecoyURL::slugController($class), 'title' => $obj->title(), 'description' => $obj->description(), // Add permission options for the controller 'permissions' => array_map(function ($value, $action) use ($class, $admin) { $roles = array_keys(Config::get('decoy.site.roles')); return (object) [ 'slug' => $action, 'title' => is_array($value) ? $value[0] : Text::titleFromKey($action), 'description' => is_array($value) ? $value[1] : $value, // Set the initial checked state based on the admin's permissions, if // one is set. Or based on the first role. 'checked' => $admin ? $admin->can($action, $class) : with(new Admin(['role' => $roles[0]]))->can($action, $class), // Filter the list of roles to just the roles that allow the // permission currently being iterated through 'roles' => array_filter($roles, function ($role) use ($action, $class) { return with(new Admin(['role' => $role]))->can($action, $class); }), ]; }, $permissions, array_keys($permissions)), ]; }, $controllers); }
[ "public", "static", "function", "getPermissionOptions", "(", "$", "admin", "=", "null", ")", "{", "// Get all the app controllers", "$", "controllers", "=", "array_map", "(", "function", "(", "$", "path", ")", "{", "return", "'App\\Http\\Controllers\\Admin\\\\'", ".", "basename", "(", "$", "path", ",", "'.php'", ")", ";", "}", ",", "glob", "(", "app_path", "(", "'/Http/Controllers/Admin/*.php'", ")", ")", ")", ";", "// Add some Decoy controllers", "$", "controllers", "[", "]", "=", "'Bkwld\\Decoy\\Controllers\\Admins'", ";", "$", "controllers", "[", "]", "=", "'Bkwld\\Decoy\\Controllers\\Changes'", ";", "$", "controllers", "[", "]", "=", "'Bkwld\\Decoy\\Controllers\\Elements'", ";", "$", "controllers", "[", "]", "=", "'Bkwld\\Decoy\\Controllers\\RedirectRules'", ";", "// Alphabetize the controller classes", "usort", "(", "$", "controllers", ",", "function", "(", "$", "a", ",", "$", "b", ")", "{", "return", "substr", "(", "$", "a", ",", "strrpos", "(", "$", "a", ",", "'\\\\'", ")", "+", "1", ")", ">", "substr", "(", "$", "b", ",", "strrpos", "(", "$", "b", ",", "'\\\\'", ")", "+", "1", ")", ";", "}", ")", ";", "// Convert the list of controller classes into the shorthand strings used", "// by Decoy Auth as well as english name and desciption", "return", "array_map", "(", "function", "(", "$", "class", ")", "use", "(", "$", "admin", ")", "{", "$", "obj", "=", "new", "$", "class", ";", "$", "permissions", "=", "$", "obj", "->", "getPermissionOptions", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "permissions", ")", ")", "{", "$", "permissions", "=", "[", "]", ";", "}", "// Build the controller-level node", "return", "(", "object", ")", "[", "// Add controller information", "'slug'", "=>", "DecoyURL", "::", "slugController", "(", "$", "class", ")", ",", "'title'", "=>", "$", "obj", "->", "title", "(", ")", ",", "'description'", "=>", "$", "obj", "->", "description", "(", ")", ",", "// Add permission options for the controller", "'permissions'", "=>", "array_map", "(", "function", "(", "$", "value", ",", "$", "action", ")", "use", "(", "$", "class", ",", "$", "admin", ")", "{", "$", "roles", "=", "array_keys", "(", "Config", "::", "get", "(", "'decoy.site.roles'", ")", ")", ";", "return", "(", "object", ")", "[", "'slug'", "=>", "$", "action", ",", "'title'", "=>", "is_array", "(", "$", "value", ")", "?", "$", "value", "[", "0", "]", ":", "Text", "::", "titleFromKey", "(", "$", "action", ")", ",", "'description'", "=>", "is_array", "(", "$", "value", ")", "?", "$", "value", "[", "1", "]", ":", "$", "value", ",", "// Set the initial checked state based on the admin's permissions, if", "// one is set. Or based on the first role.", "'checked'", "=>", "$", "admin", "?", "$", "admin", "->", "can", "(", "$", "action", ",", "$", "class", ")", ":", "with", "(", "new", "Admin", "(", "[", "'role'", "=>", "$", "roles", "[", "0", "]", "]", ")", ")", "->", "can", "(", "$", "action", ",", "$", "class", ")", ",", "// Filter the list of roles to just the roles that allow the", "// permission currently being iterated through", "'roles'", "=>", "array_filter", "(", "$", "roles", ",", "function", "(", "$", "role", ")", "use", "(", "$", "action", ",", "$", "class", ")", "{", "return", "with", "(", "new", "Admin", "(", "[", "'role'", "=>", "$", "role", "]", ")", ")", "->", "can", "(", "$", "action", ",", "$", "class", ")", ";", "}", ")", ",", "]", ";", "}", ",", "$", "permissions", ",", "array_keys", "(", "$", "permissions", ")", ")", ",", "]", ";", "}", ",", "$", "controllers", ")", ";", "}" ]
Get the list of all permissions @param Admin|null $admin @return array
[ "Get", "the", "list", "of", "all", "permissions" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Admin.php#L391-L451
30,753
BKWLD/decoy
classes/Models/Traits/SerializeWithImages.php
SerializeWithImages.withDefaultImage
public function withDefaultImage( $width = null, $height = null, $options = null) { $this->withRenamedImage(null, null, $width, $height, $options); return $this; }
php
public function withDefaultImage( $width = null, $height = null, $options = null) { $this->withRenamedImage(null, null, $width, $height, $options); return $this; }
[ "public", "function", "withDefaultImage", "(", "$", "width", "=", "null", ",", "$", "height", "=", "null", ",", "$", "options", "=", "null", ")", "{", "$", "this", "->", "withRenamedImage", "(", "null", ",", "null", ",", "$", "width", ",", "$", "height", ",", "$", "options", ")", ";", "return", "$", "this", ";", "}" ]
Convenience method for adding the default, null, named image crop @param integer $width @param integer $height @param array $options @return $this
[ "Convenience", "method", "for", "adding", "the", "default", "null", "named", "image", "crop" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/SerializeWithImages.php#L24-L32
30,754
BKWLD/decoy
classes/Models/Traits/SerializeWithImages.php
SerializeWithImages.withImage
public function withImage( $name = null, $width = null, $height = null, $options = null) { $this->withRenamedImage($name, $name, $width, $height, $options); return $this; }
php
public function withImage( $name = null, $width = null, $height = null, $options = null) { $this->withRenamedImage($name, $name, $width, $height, $options); return $this; }
[ "public", "function", "withImage", "(", "$", "name", "=", "null", ",", "$", "width", "=", "null", ",", "$", "height", "=", "null", ",", "$", "options", "=", "null", ")", "{", "$", "this", "->", "withRenamedImage", "(", "$", "name", ",", "$", "name", ",", "$", "width", ",", "$", "height", ",", "$", "options", ")", ";", "return", "$", "this", ";", "}" ]
Convenience method for specifying the name of the image to add @param string $name @param integer $width @param integer $height @param array $options @return $this
[ "Convenience", "method", "for", "specifying", "the", "name", "of", "the", "image", "to", "add" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/SerializeWithImages.php#L43-L52
30,755
BKWLD/decoy
classes/Models/Traits/SerializeWithImages.php
SerializeWithImages.withRenamedImage
public function withRenamedImage( $name = null, $property = null, $width = null, $height = null, $options = null) { // The json needs a property name if (empty($property)) { $property = 'default'; } // Add a transform that adds and whitelisted the attribute as named $this->serializeTransform(function (Model $model) use ( $name, $property, $width, $height, $options) { // Make sure that the model uses the HasImages trait if (!method_exists($model, 'img')) { throw new Exception(get_class($model).' needs HasImages trait'); } // Prepare for future applying $transforming_model = $model; $models = [$model]; // If the name contains a period, treat it as dot notation to get at an // image on a related model if (strpos($name, '.') > -1) { $relations = explode('.', $name); // If the name and property are identical, use just the image name for // the property. if ($name == $property) { $name = $property = array_pop($relations); } else { $name = array_pop($relations); } // If the name is "default", look for it with a NULL name if ($name == 'default') { $name = null; } // Step through the relationship chain until we have an array of all // of the children models. foreach ($relations as $relation) { $models = $this->getRelatedModelsWithImages($models, $relation); } } // For each model that shoudl be touched, append the named image to it's // `imgs` attribute, keyed by $proprety foreach ($models as $model) { $image = $model->img($name)->crop($width, $height, $options); $model->appendToImgs($image, $property); } // Return the model being transformed return $transforming_model; }); // Support chaining return $this; }
php
public function withRenamedImage( $name = null, $property = null, $width = null, $height = null, $options = null) { // The json needs a property name if (empty($property)) { $property = 'default'; } // Add a transform that adds and whitelisted the attribute as named $this->serializeTransform(function (Model $model) use ( $name, $property, $width, $height, $options) { // Make sure that the model uses the HasImages trait if (!method_exists($model, 'img')) { throw new Exception(get_class($model).' needs HasImages trait'); } // Prepare for future applying $transforming_model = $model; $models = [$model]; // If the name contains a period, treat it as dot notation to get at an // image on a related model if (strpos($name, '.') > -1) { $relations = explode('.', $name); // If the name and property are identical, use just the image name for // the property. if ($name == $property) { $name = $property = array_pop($relations); } else { $name = array_pop($relations); } // If the name is "default", look for it with a NULL name if ($name == 'default') { $name = null; } // Step through the relationship chain until we have an array of all // of the children models. foreach ($relations as $relation) { $models = $this->getRelatedModelsWithImages($models, $relation); } } // For each model that shoudl be touched, append the named image to it's // `imgs` attribute, keyed by $proprety foreach ($models as $model) { $image = $model->img($name)->crop($width, $height, $options); $model->appendToImgs($image, $property); } // Return the model being transformed return $transforming_model; }); // Support chaining return $this; }
[ "public", "function", "withRenamedImage", "(", "$", "name", "=", "null", ",", "$", "property", "=", "null", ",", "$", "width", "=", "null", ",", "$", "height", "=", "null", ",", "$", "options", "=", "null", ")", "{", "// The json needs a property name", "if", "(", "empty", "(", "$", "property", ")", ")", "{", "$", "property", "=", "'default'", ";", "}", "// Add a transform that adds and whitelisted the attribute as named", "$", "this", "->", "serializeTransform", "(", "function", "(", "Model", "$", "model", ")", "use", "(", "$", "name", ",", "$", "property", ",", "$", "width", ",", "$", "height", ",", "$", "options", ")", "{", "// Make sure that the model uses the HasImages trait", "if", "(", "!", "method_exists", "(", "$", "model", ",", "'img'", ")", ")", "{", "throw", "new", "Exception", "(", "get_class", "(", "$", "model", ")", ".", "' needs HasImages trait'", ")", ";", "}", "// Prepare for future applying", "$", "transforming_model", "=", "$", "model", ";", "$", "models", "=", "[", "$", "model", "]", ";", "// If the name contains a period, treat it as dot notation to get at an", "// image on a related model", "if", "(", "strpos", "(", "$", "name", ",", "'.'", ")", ">", "-", "1", ")", "{", "$", "relations", "=", "explode", "(", "'.'", ",", "$", "name", ")", ";", "// If the name and property are identical, use just the image name for", "// the property.", "if", "(", "$", "name", "==", "$", "property", ")", "{", "$", "name", "=", "$", "property", "=", "array_pop", "(", "$", "relations", ")", ";", "}", "else", "{", "$", "name", "=", "array_pop", "(", "$", "relations", ")", ";", "}", "// If the name is \"default\", look for it with a NULL name", "if", "(", "$", "name", "==", "'default'", ")", "{", "$", "name", "=", "null", ";", "}", "// Step through the relationship chain until we have an array of all", "// of the children models.", "foreach", "(", "$", "relations", "as", "$", "relation", ")", "{", "$", "models", "=", "$", "this", "->", "getRelatedModelsWithImages", "(", "$", "models", ",", "$", "relation", ")", ";", "}", "}", "// For each model that shoudl be touched, append the named image to it's", "// `imgs` attribute, keyed by $proprety", "foreach", "(", "$", "models", "as", "$", "model", ")", "{", "$", "image", "=", "$", "model", "->", "img", "(", "$", "name", ")", "->", "crop", "(", "$", "width", ",", "$", "height", ",", "$", "options", ")", ";", "$", "model", "->", "appendToImgs", "(", "$", "image", ",", "$", "property", ")", ";", "}", "// Return the model being transformed", "return", "$", "transforming_model", ";", "}", ")", ";", "// Support chaining", "return", "$", "this", ";", "}" ]
Add an Image instance with the provided crop in instructions to every item in the collection. @param string $name The `name` attribute to look for in Images @param string $property The property name to use in the JSON output @param integer $width @param integer $height @param array $options @return $this @throws Exception
[ "Add", "an", "Image", "instance", "with", "the", "provided", "crop", "in", "instructions", "to", "every", "item", "in", "the", "collection", "." ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/SerializeWithImages.php#L67-L130
30,756
BKWLD/decoy
classes/Models/Traits/SerializeWithImages.php
SerializeWithImages.getRelatedModelsWithImages
protected function getRelatedModelsWithImages($parents, $relation) { $models = []; foreach ($parents as $parent) { // Get the related object $related = $parent->$relation; // The related object is a model (like in a belongsTo setup), add it to // the array if (is_a($related, Model::class)) { $models[] = $related; } // Otherwise, if the relation returns a collection (like a hasMany), add // all the related models to the growing array. elseif (is_a($related, Collection::class)) { $models = array_merge($models, $related->all()); } } return $models; }
php
protected function getRelatedModelsWithImages($parents, $relation) { $models = []; foreach ($parents as $parent) { // Get the related object $related = $parent->$relation; // The related object is a model (like in a belongsTo setup), add it to // the array if (is_a($related, Model::class)) { $models[] = $related; } // Otherwise, if the relation returns a collection (like a hasMany), add // all the related models to the growing array. elseif (is_a($related, Collection::class)) { $models = array_merge($models, $related->all()); } } return $models; }
[ "protected", "function", "getRelatedModelsWithImages", "(", "$", "parents", ",", "$", "relation", ")", "{", "$", "models", "=", "[", "]", ";", "foreach", "(", "$", "parents", "as", "$", "parent", ")", "{", "// Get the related object", "$", "related", "=", "$", "parent", "->", "$", "relation", ";", "// The related object is a model (like in a belongsTo setup), add it to", "// the array", "if", "(", "is_a", "(", "$", "related", ",", "Model", "::", "class", ")", ")", "{", "$", "models", "[", "]", "=", "$", "related", ";", "}", "// Otherwise, if the relation returns a collection (like a hasMany), add", "// all the related models to the growing array.", "elseif", "(", "is_a", "(", "$", "related", ",", "Collection", "::", "class", ")", ")", "{", "$", "models", "=", "array_merge", "(", "$", "models", ",", "$", "related", "->", "all", "(", ")", ")", ";", "}", "}", "return", "$", "models", ";", "}" ]
Take an array of parent models and return a new array of the children of all parents in one array @param array $parents Array of eloquent models @param string $relation Relation name @return array
[ "Take", "an", "array", "of", "parent", "models", "and", "return", "a", "new", "array", "of", "the", "children", "of", "all", "parents", "in", "one", "array" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/SerializeWithImages.php#L140-L162
30,757
BKWLD/decoy
classes/Models/Change.php
Change.log
public static function log(Model $model, $action, Admin $admin = null) { // Create a new change instance if (static::shouldWriteChange($model, $action)) { $changed = static::getChanged($model, $action); $change = static::createLog($model, $action, $admin, $changed); } // Log published / unpblished changes static::logPublishingChange($model, $action, $admin); // If the action was a deletion, mark all of the records for this model as // deleted if ($action == 'deleted') { DB::table('changes') ->where('model', get_class($model)) ->where('key', $model->getKey()) ->update(['deleted' => 1]); } // Return the changed instance if (isset($change)) { return $change; } }
php
public static function log(Model $model, $action, Admin $admin = null) { // Create a new change instance if (static::shouldWriteChange($model, $action)) { $changed = static::getChanged($model, $action); $change = static::createLog($model, $action, $admin, $changed); } // Log published / unpblished changes static::logPublishingChange($model, $action, $admin); // If the action was a deletion, mark all of the records for this model as // deleted if ($action == 'deleted') { DB::table('changes') ->where('model', get_class($model)) ->where('key', $model->getKey()) ->update(['deleted' => 1]); } // Return the changed instance if (isset($change)) { return $change; } }
[ "public", "static", "function", "log", "(", "Model", "$", "model", ",", "$", "action", ",", "Admin", "$", "admin", "=", "null", ")", "{", "// Create a new change instance", "if", "(", "static", "::", "shouldWriteChange", "(", "$", "model", ",", "$", "action", ")", ")", "{", "$", "changed", "=", "static", "::", "getChanged", "(", "$", "model", ",", "$", "action", ")", ";", "$", "change", "=", "static", "::", "createLog", "(", "$", "model", ",", "$", "action", ",", "$", "admin", ",", "$", "changed", ")", ";", "}", "// Log published / unpblished changes", "static", "::", "logPublishingChange", "(", "$", "model", ",", "$", "action", ",", "$", "admin", ")", ";", "// If the action was a deletion, mark all of the records for this model as", "// deleted", "if", "(", "$", "action", "==", "'deleted'", ")", "{", "DB", "::", "table", "(", "'changes'", ")", "->", "where", "(", "'model'", ",", "get_class", "(", "$", "model", ")", ")", "->", "where", "(", "'key'", ",", "$", "model", "->", "getKey", "(", ")", ")", "->", "update", "(", "[", "'deleted'", "=>", "1", "]", ")", ";", "}", "// Return the changed instance", "if", "(", "isset", "(", "$", "change", ")", ")", "{", "return", "$", "change", ";", "}", "}" ]
A convenience method for saving a change instance @param Model $model The model being touched @param string $action Generally a CRUD verb: "created", "updated", "deleted" @param Admin $admin The admin acting on the record @return static|void
[ "A", "convenience", "method", "for", "saving", "a", "change", "instance" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L96-L120
30,758
BKWLD/decoy
classes/Models/Change.php
Change.shouldWriteChange
static private function shouldWriteChange(Model $model, $action) { if (in_array($action, ['created', 'deleted'])) return true; $changed_attributes = array_keys($model->getDirty()); $ignored = ['updated_at', 'public']; $loggable = array_diff($changed_attributes, $ignored); return count($loggable) > 0; }
php
static private function shouldWriteChange(Model $model, $action) { if (in_array($action, ['created', 'deleted'])) return true; $changed_attributes = array_keys($model->getDirty()); $ignored = ['updated_at', 'public']; $loggable = array_diff($changed_attributes, $ignored); return count($loggable) > 0; }
[ "static", "private", "function", "shouldWriteChange", "(", "Model", "$", "model", ",", "$", "action", ")", "{", "if", "(", "in_array", "(", "$", "action", ",", "[", "'created'", ",", "'deleted'", "]", ")", ")", "return", "true", ";", "$", "changed_attributes", "=", "array_keys", "(", "$", "model", "->", "getDirty", "(", ")", ")", ";", "$", "ignored", "=", "[", "'updated_at'", ",", "'public'", "]", ";", "$", "loggable", "=", "array_diff", "(", "$", "changed_attributes", ",", "$", "ignored", ")", ";", "return", "count", "(", "$", "loggable", ")", ">", "0", ";", "}" ]
Don't log changes when the only thing that changed was the published state or updated timestamp. We check if there are any attributes besides these that changed. @param Model $model The model being touched @param string $action @return boolean
[ "Don", "t", "log", "changes", "when", "the", "only", "thing", "that", "changed", "was", "the", "published", "state", "or", "updated", "timestamp", ".", "We", "check", "if", "there", "are", "any", "attributes", "besides", "these", "that", "changed", "." ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L131-L138
30,759
BKWLD/decoy
classes/Models/Change.php
Change.getChanged
static private function getChanged(Model $model, $action) { $changed = $model->getDirty(); if ($action == 'deleted' || empty($changed)) { $changed = null; } return $changed; }
php
static private function getChanged(Model $model, $action) { $changed = $model->getDirty(); if ($action == 'deleted' || empty($changed)) { $changed = null; } return $changed; }
[ "static", "private", "function", "getChanged", "(", "Model", "$", "model", ",", "$", "action", ")", "{", "$", "changed", "=", "$", "model", "->", "getDirty", "(", ")", ";", "if", "(", "$", "action", "==", "'deleted'", "||", "empty", "(", "$", "changed", ")", ")", "{", "$", "changed", "=", "null", ";", "}", "return", "$", "changed", ";", "}" ]
Get the changes attributes @param Model $model The model being touched @param string $action @return array|null
[ "Get", "the", "changes", "attributes" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L147-L154
30,760
BKWLD/decoy
classes/Models/Change.php
Change.createLog
static protected function createLog( Model $model, $action, Admin $admin = null, $changed = null) { return static::create([ 'model' => get_class($model), 'key' => $model->getKey(), 'action' => $action, 'title' => static::getModelTitle($model), 'changed' => $changed, 'admin_id' => static::getAdminId($admin), ]); }
php
static protected function createLog( Model $model, $action, Admin $admin = null, $changed = null) { return static::create([ 'model' => get_class($model), 'key' => $model->getKey(), 'action' => $action, 'title' => static::getModelTitle($model), 'changed' => $changed, 'admin_id' => static::getAdminId($admin), ]); }
[ "static", "protected", "function", "createLog", "(", "Model", "$", "model", ",", "$", "action", ",", "Admin", "$", "admin", "=", "null", ",", "$", "changed", "=", "null", ")", "{", "return", "static", "::", "create", "(", "[", "'model'", "=>", "get_class", "(", "$", "model", ")", ",", "'key'", "=>", "$", "model", "->", "getKey", "(", ")", ",", "'action'", "=>", "$", "action", ",", "'title'", "=>", "static", "::", "getModelTitle", "(", "$", "model", ")", ",", "'changed'", "=>", "$", "changed", ",", "'admin_id'", "=>", "static", "::", "getAdminId", "(", "$", "admin", ")", ",", "]", ")", ";", "}" ]
Create a change entry @param Model $model Th @param string $action @param Admin $admin
[ "Create", "a", "change", "entry" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L163-L177
30,761
BKWLD/decoy
classes/Models/Change.php
Change.getAdminId
static protected function getAdminId(Admin $admin = null) { if (!$admin) { $admin = app('decoy.user'); } return $admin ? $admin->getKey() : null; }
php
static protected function getAdminId(Admin $admin = null) { if (!$admin) { $admin = app('decoy.user'); } return $admin ? $admin->getKey() : null; }
[ "static", "protected", "function", "getAdminId", "(", "Admin", "$", "admin", "=", "null", ")", "{", "if", "(", "!", "$", "admin", ")", "{", "$", "admin", "=", "app", "(", "'decoy.user'", ")", ";", "}", "return", "$", "admin", "?", "$", "admin", "->", "getKey", "(", ")", ":", "null", ";", "}" ]
Get the admin id @param Admin $admin @return integer
[ "Get", "the", "admin", "id" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L197-L203
30,762
BKWLD/decoy
classes/Models/Change.php
Change.logPublishingChange
static public function logPublishingChange( Model $model, $action, Admin $admin = null) { if ($model->isDirty('public')) { if ($model->public) { static::createLog($model, 'published', $admin); } else if (!$model->public && $action != 'created') { static::createLog($model, 'unpublished', $admin); } } }
php
static public function logPublishingChange( Model $model, $action, Admin $admin = null) { if ($model->isDirty('public')) { if ($model->public) { static::createLog($model, 'published', $admin); } else if (!$model->public && $action != 'created') { static::createLog($model, 'unpublished', $admin); } } }
[ "static", "public", "function", "logPublishingChange", "(", "Model", "$", "model", ",", "$", "action", ",", "Admin", "$", "admin", "=", "null", ")", "{", "if", "(", "$", "model", "->", "isDirty", "(", "'public'", ")", ")", "{", "if", "(", "$", "model", "->", "public", ")", "{", "static", "::", "createLog", "(", "$", "model", ",", "'published'", ",", "$", "admin", ")", ";", "}", "else", "if", "(", "!", "$", "model", "->", "public", "&&", "$", "action", "!=", "'created'", ")", "{", "static", "::", "createLog", "(", "$", "model", ",", "'unpublished'", ",", "$", "admin", ")", ";", "}", "}", "}" ]
Log changes to publishing state. The initial publish should be logged but not an initil unpublished state. @param Model $model @param string $action @param Admin $admin @return void
[ "Log", "changes", "to", "publishing", "state", ".", "The", "initial", "publish", "should", "be", "logged", "but", "not", "an", "initil", "unpublished", "state", "." ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L214-L226
30,763
BKWLD/decoy
classes/Models/Change.php
Change.getAdminTitleHtmlAttribute
public function getAdminTitleHtmlAttribute() { return __('decoy::changes.admin_title', [ 'admin' => $this->getAdminLinkAttribute(), 'action' => $this->getActionLabelAttribute(), 'model' => $this->getModelNameHtmlAttribute(), 'model_title' => $this->getLinkedTitleAttribute(), 'date' => $this->getDateAttribute() ]); }
php
public function getAdminTitleHtmlAttribute() { return __('decoy::changes.admin_title', [ 'admin' => $this->getAdminLinkAttribute(), 'action' => $this->getActionLabelAttribute(), 'model' => $this->getModelNameHtmlAttribute(), 'model_title' => $this->getLinkedTitleAttribute(), 'date' => $this->getDateAttribute() ]); }
[ "public", "function", "getAdminTitleHtmlAttribute", "(", ")", "{", "return", "__", "(", "'decoy::changes.admin_title'", ",", "[", "'admin'", "=>", "$", "this", "->", "getAdminLinkAttribute", "(", ")", ",", "'action'", "=>", "$", "this", "->", "getActionLabelAttribute", "(", ")", ",", "'model'", "=>", "$", "this", "->", "getModelNameHtmlAttribute", "(", ")", ",", "'model_title'", "=>", "$", "this", "->", "getLinkedTitleAttribute", "(", ")", ",", "'date'", "=>", "$", "this", "->", "getDateAttribute", "(", ")", "]", ")", ";", "}" ]
Format the the activity like a sentence @return string HTML
[ "Format", "the", "the", "activity", "like", "a", "sentence" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L257-L266
30,764
BKWLD/decoy
classes/Models/Change.php
Change.getAdminLinkAttribute
public function getAdminLinkAttribute() { if ($this->admin_id) { return sprintf('<a href="%s">%s</a>', $this->filterUrl(['admin_id' => $this->admin_id]), $this->admin->getAdminTitleHtmlAttribute()); } else { return 'Someone'; } }
php
public function getAdminLinkAttribute() { if ($this->admin_id) { return sprintf('<a href="%s">%s</a>', $this->filterUrl(['admin_id' => $this->admin_id]), $this->admin->getAdminTitleHtmlAttribute()); } else { return 'Someone'; } }
[ "public", "function", "getAdminLinkAttribute", "(", ")", "{", "if", "(", "$", "this", "->", "admin_id", ")", "{", "return", "sprintf", "(", "'<a href=\"%s\">%s</a>'", ",", "$", "this", "->", "filterUrl", "(", "[", "'admin_id'", "=>", "$", "this", "->", "admin_id", "]", ")", ",", "$", "this", "->", "admin", "->", "getAdminTitleHtmlAttribute", "(", ")", ")", ";", "}", "else", "{", "return", "'Someone'", ";", "}", "}" ]
Get the admin name and link @return string HTML
[ "Get", "the", "admin", "name", "and", "link" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L273-L282
30,765
BKWLD/decoy
classes/Models/Change.php
Change.getActionLabelAttribute
public function getActionLabelAttribute() { $map = [ 'created' => 'success', 'updated' => 'warning', 'deleted' => 'danger', 'published' => 'info', 'unpublished' => 'default', ]; return sprintf('<a href="%s" class="label label-%s">%s</a>', $this->filterUrl(['action' => $this->action]), isset($map[$this->action]) ? $map[$this->action] : 'info', __("decoy::changes.actions.$this->action")); }
php
public function getActionLabelAttribute() { $map = [ 'created' => 'success', 'updated' => 'warning', 'deleted' => 'danger', 'published' => 'info', 'unpublished' => 'default', ]; return sprintf('<a href="%s" class="label label-%s">%s</a>', $this->filterUrl(['action' => $this->action]), isset($map[$this->action]) ? $map[$this->action] : 'info', __("decoy::changes.actions.$this->action")); }
[ "public", "function", "getActionLabelAttribute", "(", ")", "{", "$", "map", "=", "[", "'created'", "=>", "'success'", ",", "'updated'", "=>", "'warning'", ",", "'deleted'", "=>", "'danger'", ",", "'published'", "=>", "'info'", ",", "'unpublished'", "=>", "'default'", ",", "]", ";", "return", "sprintf", "(", "'<a href=\"%s\" class=\"label label-%s\">%s</a>'", ",", "$", "this", "->", "filterUrl", "(", "[", "'action'", "=>", "$", "this", "->", "action", "]", ")", ",", "isset", "(", "$", "map", "[", "$", "this", "->", "action", "]", ")", "?", "$", "map", "[", "$", "this", "->", "action", "]", ":", "'info'", ",", "__", "(", "\"decoy::changes.actions.$this->action\"", ")", ")", ";", "}" ]
Format the activity as a colored label @return string HTML
[ "Format", "the", "activity", "as", "a", "colored", "label" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L289-L303
30,766
BKWLD/decoy
classes/Models/Change.php
Change.getModelNameHtmlAttribute
public function getModelNameHtmlAttribute() { $class = Decoy::controllerForModel($this->model); // There is not a controller for the model if (!$class || !class_exists($class)) { return sprintf('<b><a href="%s">%s</a></b>', $this->filterUrl(['model' => $this->model]), preg_replace('#(?<!\ )[A-Z]#', ' $0', $this->model)); } // There is a corresponding controller class $controller = new $class; return sprintf('<b class="js-tooltip" title="%s"><a href="%s">%s</a></b>', htmlentities($controller->description()), $this->filterUrl(['model' => $this->model]), Str::singular($controller->title())); }
php
public function getModelNameHtmlAttribute() { $class = Decoy::controllerForModel($this->model); // There is not a controller for the model if (!$class || !class_exists($class)) { return sprintf('<b><a href="%s">%s</a></b>', $this->filterUrl(['model' => $this->model]), preg_replace('#(?<!\ )[A-Z]#', ' $0', $this->model)); } // There is a corresponding controller class $controller = new $class; return sprintf('<b class="js-tooltip" title="%s"><a href="%s">%s</a></b>', htmlentities($controller->description()), $this->filterUrl(['model' => $this->model]), Str::singular($controller->title())); }
[ "public", "function", "getModelNameHtmlAttribute", "(", ")", "{", "$", "class", "=", "Decoy", "::", "controllerForModel", "(", "$", "this", "->", "model", ")", ";", "// There is not a controller for the model", "if", "(", "!", "$", "class", "||", "!", "class_exists", "(", "$", "class", ")", ")", "{", "return", "sprintf", "(", "'<b><a href=\"%s\">%s</a></b>'", ",", "$", "this", "->", "filterUrl", "(", "[", "'model'", "=>", "$", "this", "->", "model", "]", ")", ",", "preg_replace", "(", "'#(?<!\\ )[A-Z]#'", ",", "' $0'", ",", "$", "this", "->", "model", ")", ")", ";", "}", "// There is a corresponding controller class", "$", "controller", "=", "new", "$", "class", ";", "return", "sprintf", "(", "'<b class=\"js-tooltip\" title=\"%s\"><a href=\"%s\">%s</a></b>'", ",", "htmlentities", "(", "$", "controller", "->", "description", "(", ")", ")", ",", "$", "this", "->", "filterUrl", "(", "[", "'model'", "=>", "$", "this", "->", "model", "]", ")", ",", "Str", "::", "singular", "(", "$", "controller", "->", "title", "(", ")", ")", ")", ";", "}" ]
Format the model name by translating it through the controllers's defined title @return string HTML
[ "Format", "the", "model", "name", "by", "translating", "it", "through", "the", "controllers", "s", "defined", "title" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L311-L328
30,767
BKWLD/decoy
classes/Models/Change.php
Change.getLinkedTitleAttribute
public function getLinkedTitleAttribute() { if (!$this->title) return; return sprintf('<a href="%s">"%s"</a>', $this->filterUrl(['model' => $this->model, 'key' => $this->key]), $this->title); }
php
public function getLinkedTitleAttribute() { if (!$this->title) return; return sprintf('<a href="%s">"%s"</a>', $this->filterUrl(['model' => $this->model, 'key' => $this->key]), $this->title); }
[ "public", "function", "getLinkedTitleAttribute", "(", ")", "{", "if", "(", "!", "$", "this", "->", "title", ")", "return", ";", "return", "sprintf", "(", "'<a href=\"%s\">\"%s\"</a>'", ",", "$", "this", "->", "filterUrl", "(", "[", "'model'", "=>", "$", "this", "->", "model", ",", "'key'", "=>", "$", "this", "->", "key", "]", ")", ",", "$", "this", "->", "title", ")", ";", "}" ]
Get the title of the model. Perhaps in the future there will be more smarts here, like generating a link to the edit view @return string HTML
[ "Get", "the", "title", "of", "the", "model", ".", "Perhaps", "in", "the", "future", "there", "will", "be", "more", "smarts", "here", "like", "generating", "a", "link", "to", "the", "edit", "view" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L336-L342
30,768
BKWLD/decoy
classes/Models/Change.php
Change.getDateAttribute
public function getDateAttribute() { \Carbon\Carbon::setLocale(Decoy::locale()); return sprintf('<a href="%s" class="js-tooltip" title="%s">%s</a>', $this->filterUrl(['created_at' => $this->created_at->format('m/d/Y')]), $this->getHumanDateAttribute(), $this->created_at->diffForHumans()); }
php
public function getDateAttribute() { \Carbon\Carbon::setLocale(Decoy::locale()); return sprintf('<a href="%s" class="js-tooltip" title="%s">%s</a>', $this->filterUrl(['created_at' => $this->created_at->format('m/d/Y')]), $this->getHumanDateAttribute(), $this->created_at->diffForHumans()); }
[ "public", "function", "getDateAttribute", "(", ")", "{", "\\", "Carbon", "\\", "Carbon", "::", "setLocale", "(", "Decoy", "::", "locale", "(", ")", ")", ";", "return", "sprintf", "(", "'<a href=\"%s\" class=\"js-tooltip\" title=\"%s\">%s</a>'", ",", "$", "this", "->", "filterUrl", "(", "[", "'created_at'", "=>", "$", "this", "->", "created_at", "->", "format", "(", "'m/d/Y'", ")", "]", ")", ",", "$", "this", "->", "getHumanDateAttribute", "(", ")", ",", "$", "this", "->", "created_at", "->", "diffForHumans", "(", ")", ")", ";", "}" ]
Get the date of the change @return string HTML
[ "Get", "the", "date", "of", "the", "change" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L349-L356
30,769
BKWLD/decoy
classes/Models/Change.php
Change.getFilterActionAttribute
public function getFilterActionAttribute() { return sprintf('<a href="%s" class="glyphicon glyphicon-filter js-tooltip" title="' . __('decoy::changes.standard_list.filter') . '" data-placement="left"></a>', $this->filterUrl(['model' => $this->model, 'key' => $this->key]), strip_tags($this->getModelNameHtmlAttribute())); }
php
public function getFilterActionAttribute() { return sprintf('<a href="%s" class="glyphicon glyphicon-filter js-tooltip" title="' . __('decoy::changes.standard_list.filter') . '" data-placement="left"></a>', $this->filterUrl(['model' => $this->model, 'key' => $this->key]), strip_tags($this->getModelNameHtmlAttribute())); }
[ "public", "function", "getFilterActionAttribute", "(", ")", "{", "return", "sprintf", "(", "'<a href=\"%s\"\n class=\"glyphicon glyphicon-filter js-tooltip\"\n title=\"'", ".", "__", "(", "'decoy::changes.standard_list.filter'", ")", ".", "'\"\n data-placement=\"left\"></a>'", ",", "$", "this", "->", "filterUrl", "(", "[", "'model'", "=>", "$", "this", "->", "model", ",", "'key'", "=>", "$", "this", "->", "key", "]", ")", ",", "strip_tags", "(", "$", "this", "->", "getModelNameHtmlAttribute", "(", ")", ")", ")", ";", "}" ]
Make the preview filter icon @return string
[ "Make", "the", "preview", "filter", "icon" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L388-L396
30,770
BKWLD/decoy
classes/Models/Change.php
Change.getChangesActionAttribute
public function getChangesActionAttribute() { // If there are changes, add the modal button if ($this->changed) { return sprintf('<a href="%s" class="glyphicon glyphicon-export js-tooltip changes-modal-link" title="%s" data-placement="left"></a>', DecoyURL::action('changes@edit', $this->id), __('decoy::changes.standard_list.view')); } // Else, show a disabled button else { return sprintf('<span class="glyphicon glyphicon-export js-tooltip" title="%s" data-placement="left"></span>', __('decoy::changes.standard_list.no_changed')); } }
php
public function getChangesActionAttribute() { // If there are changes, add the modal button if ($this->changed) { return sprintf('<a href="%s" class="glyphicon glyphicon-export js-tooltip changes-modal-link" title="%s" data-placement="left"></a>', DecoyURL::action('changes@edit', $this->id), __('decoy::changes.standard_list.view')); } // Else, show a disabled button else { return sprintf('<span class="glyphicon glyphicon-export js-tooltip" title="%s" data-placement="left"></span>', __('decoy::changes.standard_list.no_changed')); } }
[ "public", "function", "getChangesActionAttribute", "(", ")", "{", "// If there are changes, add the modal button", "if", "(", "$", "this", "->", "changed", ")", "{", "return", "sprintf", "(", "'<a href=\"%s\"\n class=\"glyphicon glyphicon-export js-tooltip changes-modal-link\"\n title=\"%s\" data-placement=\"left\"></a>'", ",", "DecoyURL", "::", "action", "(", "'changes@edit'", ",", "$", "this", "->", "id", ")", ",", "__", "(", "'decoy::changes.standard_list.view'", ")", ")", ";", "}", "// Else, show a disabled button", "else", "{", "return", "sprintf", "(", "'<span\n class=\"glyphicon glyphicon-export js-tooltip\"\n title=\"%s\" data-placement=\"left\"></span>'", ",", "__", "(", "'decoy::changes.standard_list.no_changed'", ")", ")", ";", "}", "}" ]
Make the changes icon @return string
[ "Make", "the", "changes", "icon" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L413-L430
30,771
BKWLD/decoy
classes/Models/Change.php
Change.getPreviewActionAttribute
public function getPreviewActionAttribute() { if ($this->changedModel && $this->changedModel->uri && $this->action != 'deleted') { return sprintf('<a href="%s" target="_blank" class="glyphicon glyphicon-bookmark js-tooltip" title="%s" data-placement="left"></a>', $this->preview_url, __('decoy::changes.standard_list.preview')); } else { return '<span class="glyphicon glyphicon-bookmark disabled"></span>'; } }
php
public function getPreviewActionAttribute() { if ($this->changedModel && $this->changedModel->uri && $this->action != 'deleted') { return sprintf('<a href="%s" target="_blank" class="glyphicon glyphicon-bookmark js-tooltip" title="%s" data-placement="left"></a>', $this->preview_url, __('decoy::changes.standard_list.preview')); } else { return '<span class="glyphicon glyphicon-bookmark disabled"></span>'; } }
[ "public", "function", "getPreviewActionAttribute", "(", ")", "{", "if", "(", "$", "this", "->", "changedModel", "&&", "$", "this", "->", "changedModel", "->", "uri", "&&", "$", "this", "->", "action", "!=", "'deleted'", ")", "{", "return", "sprintf", "(", "'<a href=\"%s\" target=\"_blank\"\n class=\"glyphicon glyphicon-bookmark js-tooltip\"\n title=\"%s\" data-placement=\"left\"></a>'", ",", "$", "this", "->", "preview_url", ",", "__", "(", "'decoy::changes.standard_list.preview'", ")", ")", ";", "}", "else", "{", "return", "'<span class=\"glyphicon glyphicon-bookmark disabled\"></span>'", ";", "}", "}" ]
Make link to preview a version as long as the model has a URI and the action wasn't a delete action. @return string
[ "Make", "link", "to", "preview", "a", "version", "as", "long", "as", "the", "model", "has", "a", "URI", "and", "the", "action", "wasn", "t", "a", "delete", "action", "." ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L438-L451
30,772
BKWLD/decoy
classes/Models/Change.php
Change.attributesForModal
public function attributesForModal() { // Remove some specific attributes. Leaving empties in there so the updating // of values to NULL is displayed. $attributes = array_except($this->changed, [ 'id', 'updated_at', 'created_at', 'password', 'remember_token', ]); // Make more readable titles $out = []; foreach ($attributes as $key => $val) { $out[Text::titleFromKey($key)] = $val; } return $out; }
php
public function attributesForModal() { // Remove some specific attributes. Leaving empties in there so the updating // of values to NULL is displayed. $attributes = array_except($this->changed, [ 'id', 'updated_at', 'created_at', 'password', 'remember_token', ]); // Make more readable titles $out = []; foreach ($attributes as $key => $val) { $out[Text::titleFromKey($key)] = $val; } return $out; }
[ "public", "function", "attributesForModal", "(", ")", "{", "// Remove some specific attributes. Leaving empties in there so the updating", "// of values to NULL is displayed.", "$", "attributes", "=", "array_except", "(", "$", "this", "->", "changed", ",", "[", "'id'", ",", "'updated_at'", ",", "'created_at'", ",", "'password'", ",", "'remember_token'", ",", "]", ")", ";", "// Make more readable titles", "$", "out", "=", "[", "]", ";", "foreach", "(", "$", "attributes", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "out", "[", "Text", "::", "titleFromKey", "(", "$", "key", ")", "]", "=", "$", "val", ";", "}", "return", "$", "out", ";", "}" ]
Get just the attributes that should be displayed in the admin modal. @return array
[ "Get", "just", "the", "attributes", "that", "should", "be", "displayed", "in", "the", "admin", "modal", "." ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L472-L487
30,773
BKWLD/decoy
classes/Models/Traits/HasImages.php
HasImages.croppedImages
public function croppedImages($width = null, $height = null, $options = null) { return array_combine( // Keys $this->images->map(function ($image) { return $image->name ?: 'default'; })->toArray(), // Values $this->images->map(function ($image) use ($width, $height, $options) { return $image->crop($width, $height, $options)->url; })->toArray() ); }
php
public function croppedImages($width = null, $height = null, $options = null) { return array_combine( // Keys $this->images->map(function ($image) { return $image->name ?: 'default'; })->toArray(), // Values $this->images->map(function ($image) use ($width, $height, $options) { return $image->crop($width, $height, $options)->url; })->toArray() ); }
[ "public", "function", "croppedImages", "(", "$", "width", "=", "null", ",", "$", "height", "=", "null", ",", "$", "options", "=", "null", ")", "{", "return", "array_combine", "(", "// Keys", "$", "this", "->", "images", "->", "map", "(", "function", "(", "$", "image", ")", "{", "return", "$", "image", "->", "name", "?", ":", "'default'", ";", "}", ")", "->", "toArray", "(", ")", ",", "// Values", "$", "this", "->", "images", "->", "map", "(", "function", "(", "$", "image", ")", "use", "(", "$", "width", ",", "$", "height", ",", "$", "options", ")", "{", "return", "$", "image", "->", "crop", "(", "$", "width", ",", "$", "height", ",", "$", "options", ")", "->", "url", ";", "}", ")", "->", "toArray", "(", ")", ")", ";", "}" ]
Return an array of all images associated with the model, keyed by their name, while optionally applying a crop to them
[ "Return", "an", "array", "of", "all", "images", "associated", "with", "the", "model", "keyed", "by", "their", "name", "while", "optionally", "applying", "a", "crop", "to", "them" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/HasImages.php#L92-L106
30,774
BKWLD/decoy
classes/Models/Traits/HasImages.php
HasImages.appendToImgs
public function appendToImgs(Image $image, $property) { // Create or fetch the container for all images on the model. The // container could not be "images" because that is used by the // relationship function and leads to trouble. if (!$this->getAttribute('imgs')) { $imgs = []; $this->addVisible('imgs'); } else { $imgs = $this->getAttribute('imgs'); } // Add the image to the container and set it. Then return the model. It // must be explicitly converted to an array because Laravel won't // automatically do it during collection serialization. Another, more // complicated approach could have been to use the Decoy Base model to add // a cast type of "model" and then call toArray() on it when casting the // attribute. $imgs[$property] = $image->toArray(); $this->setAttribute('imgs', $imgs); return $this; }
php
public function appendToImgs(Image $image, $property) { // Create or fetch the container for all images on the model. The // container could not be "images" because that is used by the // relationship function and leads to trouble. if (!$this->getAttribute('imgs')) { $imgs = []; $this->addVisible('imgs'); } else { $imgs = $this->getAttribute('imgs'); } // Add the image to the container and set it. Then return the model. It // must be explicitly converted to an array because Laravel won't // automatically do it during collection serialization. Another, more // complicated approach could have been to use the Decoy Base model to add // a cast type of "model" and then call toArray() on it when casting the // attribute. $imgs[$property] = $image->toArray(); $this->setAttribute('imgs', $imgs); return $this; }
[ "public", "function", "appendToImgs", "(", "Image", "$", "image", ",", "$", "property", ")", "{", "// Create or fetch the container for all images on the model. The", "// container could not be \"images\" because that is used by the", "// relationship function and leads to trouble.", "if", "(", "!", "$", "this", "->", "getAttribute", "(", "'imgs'", ")", ")", "{", "$", "imgs", "=", "[", "]", ";", "$", "this", "->", "addVisible", "(", "'imgs'", ")", ";", "}", "else", "{", "$", "imgs", "=", "$", "this", "->", "getAttribute", "(", "'imgs'", ")", ";", "}", "// Add the image to the container and set it. Then return the model. It", "// must be explicitly converted to an array because Laravel won't", "// automatically do it during collection serialization. Another, more", "// complicated approach could have been to use the Decoy Base model to add", "// a cast type of \"model\" and then call toArray() on it when casting the", "// attribute.", "$", "imgs", "[", "$", "property", "]", "=", "$", "image", "->", "toArray", "(", ")", ";", "$", "this", "->", "setAttribute", "(", "'imgs'", ",", "$", "imgs", ")", ";", "return", "$", "this", ";", "}" ]
Add an Image to the `imgs` attribute of the model for the purpose of exposing it when serialized. @param Image $image @param string $property @return $this
[ "Add", "an", "Image", "to", "the", "imgs", "attribute", "of", "the", "model", "for", "the", "purpose", "of", "exposing", "it", "when", "serialized", "." ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/HasImages.php#L116-L138
30,775
BKWLD/decoy
classes/Routing/Router.php
Router.registerAll
public function registerAll() { // Public routes Route::group([ 'prefix' => $this->dir, 'middleware' => 'decoy.public', ], function () { $this->registerLogin(); $this->registerResetPassword(); }); // Routes that don't require auth or CSRF Route::group([ 'prefix' => $this->dir, 'middleware' => 'decoy.endpoint', ], function () { $this->registerExternalEndpoints(); }); // Protected, admin routes Route::group([ 'prefix' => $this->dir, 'middleware' => 'decoy.protected', ], function () { $this->registerAdmins(); $this->registerCommands(); $this->registerElements(); $this->registerEncode(); $this->registerRedactor(); $this->registerWorkers(); $this->registerWildcard(); // Must be last }); }
php
public function registerAll() { // Public routes Route::group([ 'prefix' => $this->dir, 'middleware' => 'decoy.public', ], function () { $this->registerLogin(); $this->registerResetPassword(); }); // Routes that don't require auth or CSRF Route::group([ 'prefix' => $this->dir, 'middleware' => 'decoy.endpoint', ], function () { $this->registerExternalEndpoints(); }); // Protected, admin routes Route::group([ 'prefix' => $this->dir, 'middleware' => 'decoy.protected', ], function () { $this->registerAdmins(); $this->registerCommands(); $this->registerElements(); $this->registerEncode(); $this->registerRedactor(); $this->registerWorkers(); $this->registerWildcard(); // Must be last }); }
[ "public", "function", "registerAll", "(", ")", "{", "// Public routes", "Route", "::", "group", "(", "[", "'prefix'", "=>", "$", "this", "->", "dir", ",", "'middleware'", "=>", "'decoy.public'", ",", "]", ",", "function", "(", ")", "{", "$", "this", "->", "registerLogin", "(", ")", ";", "$", "this", "->", "registerResetPassword", "(", ")", ";", "}", ")", ";", "// Routes that don't require auth or CSRF", "Route", "::", "group", "(", "[", "'prefix'", "=>", "$", "this", "->", "dir", ",", "'middleware'", "=>", "'decoy.endpoint'", ",", "]", ",", "function", "(", ")", "{", "$", "this", "->", "registerExternalEndpoints", "(", ")", ";", "}", ")", ";", "// Protected, admin routes", "Route", "::", "group", "(", "[", "'prefix'", "=>", "$", "this", "->", "dir", ",", "'middleware'", "=>", "'decoy.protected'", ",", "]", ",", "function", "(", ")", "{", "$", "this", "->", "registerAdmins", "(", ")", ";", "$", "this", "->", "registerCommands", "(", ")", ";", "$", "this", "->", "registerElements", "(", ")", ";", "$", "this", "->", "registerEncode", "(", ")", ";", "$", "this", "->", "registerRedactor", "(", ")", ";", "$", "this", "->", "registerWorkers", "(", ")", ";", "$", "this", "->", "registerWildcard", "(", ")", ";", "// Must be last", "}", ")", ";", "}" ]
Register all routes @return void
[ "Register", "all", "routes" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Routing/Router.php#L43-L75
30,776
BKWLD/decoy
classes/Routing/Router.php
Router.registerWildcard
public function registerWildcard() { // Setup a wildcarded catch all route Route::any('{path}', ['as' => 'decoy::wildcard', function ($path) { // Remember the detected route App::make('events')->listen('wildcard.detection', function ($controller, $action) { $this->action($controller.'@'.$action); }); // Do the detection $router = App::make('decoy.wildcard'); $response = $router->detectAndExecute(); if (is_a($response, 'Symfony\Component\HttpFoundation\Response') || is_a($response, 'Illuminate\View\View')) { // Possible when layout is involved return $response; } else { App::abort(404); } }])->where('path', '.*'); }
php
public function registerWildcard() { // Setup a wildcarded catch all route Route::any('{path}', ['as' => 'decoy::wildcard', function ($path) { // Remember the detected route App::make('events')->listen('wildcard.detection', function ($controller, $action) { $this->action($controller.'@'.$action); }); // Do the detection $router = App::make('decoy.wildcard'); $response = $router->detectAndExecute(); if (is_a($response, 'Symfony\Component\HttpFoundation\Response') || is_a($response, 'Illuminate\View\View')) { // Possible when layout is involved return $response; } else { App::abort(404); } }])->where('path', '.*'); }
[ "public", "function", "registerWildcard", "(", ")", "{", "// Setup a wildcarded catch all route", "Route", "::", "any", "(", "'{path}'", ",", "[", "'as'", "=>", "'decoy::wildcard'", ",", "function", "(", "$", "path", ")", "{", "// Remember the detected route", "App", "::", "make", "(", "'events'", ")", "->", "listen", "(", "'wildcard.detection'", ",", "function", "(", "$", "controller", ",", "$", "action", ")", "{", "$", "this", "->", "action", "(", "$", "controller", ".", "'@'", ".", "$", "action", ")", ";", "}", ")", ";", "// Do the detection", "$", "router", "=", "App", "::", "make", "(", "'decoy.wildcard'", ")", ";", "$", "response", "=", "$", "router", "->", "detectAndExecute", "(", ")", ";", "if", "(", "is_a", "(", "$", "response", ",", "'Symfony\\Component\\HttpFoundation\\Response'", ")", "||", "is_a", "(", "$", "response", ",", "'Illuminate\\View\\View'", ")", ")", "{", "// Possible when layout is involved", "return", "$", "response", ";", "}", "else", "{", "App", "::", "abort", "(", "404", ")", ";", "}", "}", "]", ")", "->", "where", "(", "'path'", ",", "'.*'", ")", ";", "}" ]
Setup wilcard routing @return void
[ "Setup", "wilcard", "routing" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Routing/Router.php#L129-L149
30,777
BKWLD/decoy
classes/Routing/Router.php
Router.action
public function action($name = null) { if ($name) { $this->action = $name; } if ($this->action) { return $this->action; } // Wildcard return Route::currentRouteAction(); }
php
public function action($name = null) { if ($name) { $this->action = $name; } if ($this->action) { return $this->action; } // Wildcard return Route::currentRouteAction(); }
[ "public", "function", "action", "(", "$", "name", "=", "null", ")", "{", "if", "(", "$", "name", ")", "{", "$", "this", "->", "action", "=", "$", "name", ";", "}", "if", "(", "$", "this", "->", "action", ")", "{", "return", "$", "this", "->", "action", ";", "}", "// Wildcard", "return", "Route", "::", "currentRouteAction", "(", ")", ";", "}" ]
Set and get the action for this request @return string '\Bkwld\Decoy\Controllers\Account@forgot'
[ "Set", "and", "get", "the", "action", "for", "this", "request" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Routing/Router.php#L275-L287
30,778
BKWLD/decoy
classes/Input/Position.php
Position.has
public function has() { if (!Request::has('position')) { return false; } if (isset($this->item->position)) { return true; } if (!empty($this->pivot) && isset($this->pivot->position)) { return true; } return false; }
php
public function has() { if (!Request::has('position')) { return false; } if (isset($this->item->position)) { return true; } if (!empty($this->pivot) && isset($this->pivot->position)) { return true; } return false; }
[ "public", "function", "has", "(", ")", "{", "if", "(", "!", "Request", "::", "has", "(", "'position'", ")", ")", "{", "return", "false", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "item", "->", "position", ")", ")", "{", "return", "true", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "pivot", ")", "&&", "isset", "(", "$", "this", "->", "pivot", "->", "position", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Check if we have all dependencies for an position change
[ "Check", "if", "we", "have", "all", "dependencies", "for", "an", "position", "change" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Position.php#L36-L51
30,779
BKWLD/decoy
classes/Input/Position.php
Position.fill
public function fill() { // Write the position value to the pivot table if (isset($this->pivot->position)) { $this->pivot->position = request('position'); $this->pivot->save(); // Write position value to the item } elseif (isset($this->item->position)) { // Visiblity may be set at the same time and would be ignored otherwise if (Request::has('public')) { $this->item->public = request('public'); } // Do position $this->item->position = request('position'); } }
php
public function fill() { // Write the position value to the pivot table if (isset($this->pivot->position)) { $this->pivot->position = request('position'); $this->pivot->save(); // Write position value to the item } elseif (isset($this->item->position)) { // Visiblity may be set at the same time and would be ignored otherwise if (Request::has('public')) { $this->item->public = request('public'); } // Do position $this->item->position = request('position'); } }
[ "public", "function", "fill", "(", ")", "{", "// Write the position value to the pivot table", "if", "(", "isset", "(", "$", "this", "->", "pivot", "->", "position", ")", ")", "{", "$", "this", "->", "pivot", "->", "position", "=", "request", "(", "'position'", ")", ";", "$", "this", "->", "pivot", "->", "save", "(", ")", ";", "// Write position value to the item", "}", "elseif", "(", "isset", "(", "$", "this", "->", "item", "->", "position", ")", ")", "{", "// Visiblity may be set at the same time and would be ignored otherwise", "if", "(", "Request", "::", "has", "(", "'public'", ")", ")", "{", "$", "this", "->", "item", "->", "public", "=", "request", "(", "'public'", ")", ";", "}", "// Do position", "$", "this", "->", "item", "->", "position", "=", "request", "(", "'position'", ")", ";", "}", "}" ]
Set new position
[ "Set", "new", "position" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Position.php#L56-L74
30,780
BKWLD/decoy
classes/Fields/Traits/CaptureHelp.php
CaptureHelp.help
public function help($help, $attributes = []) { $this->help = $help; return parent::help($help, $attributes); }
php
public function help($help, $attributes = []) { $this->help = $help; return parent::help($help, $attributes); }
[ "public", "function", "help", "(", "$", "help", ",", "$", "attributes", "=", "[", "]", ")", "{", "$", "this", "->", "help", "=", "$", "help", ";", "return", "parent", "::", "help", "(", "$", "help", ",", "$", "attributes", ")", ";", "}" ]
Store the help locally @param string $help The help text @param array $attributes Facultative attributes @return $this
[ "Store", "the", "help", "locally" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Traits/CaptureHelp.php#L32-L37
30,781
BKWLD/decoy
classes/Fields/Traits/CaptureHelp.php
CaptureHelp.blockhelp
public function blockhelp($help, $attributes = []) { $this->blockhelp = $help; return parent::help($help, $attributes); }
php
public function blockhelp($help, $attributes = []) { $this->blockhelp = $help; return parent::help($help, $attributes); }
[ "public", "function", "blockhelp", "(", "$", "help", ",", "$", "attributes", "=", "[", "]", ")", "{", "$", "this", "->", "blockhelp", "=", "$", "help", ";", "return", "parent", "::", "help", "(", "$", "help", ",", "$", "attributes", ")", ";", "}" ]
Store the block help locally @param string $help The help text @param array $attributes Facultative attributes @return $this
[ "Store", "the", "block", "help", "locally" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Traits/CaptureHelp.php#L46-L51
30,782
BKWLD/decoy
classes/Middleware/Guest.php
Guest.getHome
public function getHome() { // Vars $config = config('decoy.site.post_login_redirect'); $auth = app('decoy.user'); // Make the config optional if ($config) { // Support the config being a colsure if (is_callable($config)) { $config = call_user_func($config); } // Make sure the user has permission before redirecting if ($auth->can('read', $config)) { return $config; } } // If the user doesn't have permission, iterate through the navigation // options until one is permissible foreach ($this->getNavUrls() as $url) { if ($auth->can('read', $url)) { return $url; } } // Default to their account page, which all can access return $auth->getUserUrl(); }
php
public function getHome() { // Vars $config = config('decoy.site.post_login_redirect'); $auth = app('decoy.user'); // Make the config optional if ($config) { // Support the config being a colsure if (is_callable($config)) { $config = call_user_func($config); } // Make sure the user has permission before redirecting if ($auth->can('read', $config)) { return $config; } } // If the user doesn't have permission, iterate through the navigation // options until one is permissible foreach ($this->getNavUrls() as $url) { if ($auth->can('read', $url)) { return $url; } } // Default to their account page, which all can access return $auth->getUserUrl(); }
[ "public", "function", "getHome", "(", ")", "{", "// Vars", "$", "config", "=", "config", "(", "'decoy.site.post_login_redirect'", ")", ";", "$", "auth", "=", "app", "(", "'decoy.user'", ")", ";", "// Make the config optional", "if", "(", "$", "config", ")", "{", "// Support the config being a colsure", "if", "(", "is_callable", "(", "$", "config", ")", ")", "{", "$", "config", "=", "call_user_func", "(", "$", "config", ")", ";", "}", "// Make sure the user has permission before redirecting", "if", "(", "$", "auth", "->", "can", "(", "'read'", ",", "$", "config", ")", ")", "{", "return", "$", "config", ";", "}", "}", "// If the user doesn't have permission, iterate through the navigation", "// options until one is permissible", "foreach", "(", "$", "this", "->", "getNavUrls", "(", ")", "as", "$", "url", ")", "{", "if", "(", "$", "auth", "->", "can", "(", "'read'", ",", "$", "url", ")", ")", "{", "return", "$", "url", ";", "}", "}", "// Default to their account page, which all can access", "return", "$", "auth", "->", "getUserUrl", "(", ")", ";", "}" ]
Determine what the dashboard URL should be, where the user is redirected after login. @return string
[ "Determine", "what", "the", "dashboard", "URL", "should", "be", "where", "the", "user", "is", "redirected", "after", "login", "." ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Middleware/Guest.php#L37-L67
30,783
BKWLD/decoy
classes/Middleware/Guest.php
Guest.getNavUrls
public function getNavUrls($nav = null) { // If no nav passed, as it would be for a sub navs, get the configed nav if (empty($nav)) { $nav = config('decoy.site.nav'); } // Allow for the nav to be acallable if (is_callable($nav)) { $nav = call_user_func($nav); } // Loop through the nav $flat = []; foreach ($nav as $val) { if (is_array($val)) { $flat = array_merge($flat, $this->getNavUrls($val)); } else { $flat[] = $val; } } return $flat; }
php
public function getNavUrls($nav = null) { // If no nav passed, as it would be for a sub navs, get the configed nav if (empty($nav)) { $nav = config('decoy.site.nav'); } // Allow for the nav to be acallable if (is_callable($nav)) { $nav = call_user_func($nav); } // Loop through the nav $flat = []; foreach ($nav as $val) { if (is_array($val)) { $flat = array_merge($flat, $this->getNavUrls($val)); } else { $flat[] = $val; } } return $flat; }
[ "public", "function", "getNavUrls", "(", "$", "nav", "=", "null", ")", "{", "// If no nav passed, as it would be for a sub navs, get the configed nav", "if", "(", "empty", "(", "$", "nav", ")", ")", "{", "$", "nav", "=", "config", "(", "'decoy.site.nav'", ")", ";", "}", "// Allow for the nav to be acallable", "if", "(", "is_callable", "(", "$", "nav", ")", ")", "{", "$", "nav", "=", "call_user_func", "(", "$", "nav", ")", ";", "}", "// Loop through the nav", "$", "flat", "=", "[", "]", ";", "foreach", "(", "$", "nav", "as", "$", "val", ")", "{", "if", "(", "is_array", "(", "$", "val", ")", ")", "{", "$", "flat", "=", "array_merge", "(", "$", "flat", ",", "$", "this", "->", "getNavUrls", "(", "$", "val", ")", ")", ";", "}", "else", "{", "$", "flat", "[", "]", "=", "$", "val", ";", "}", "}", "return", "$", "flat", ";", "}" ]
Return a flat list of all the URLs in the nav. This doesn't include ones automatically added by Decoy @param array $nav @return array
[ "Return", "a", "flat", "list", "of", "all", "the", "URLs", "in", "the", "nav", ".", "This", "doesn", "t", "include", "ones", "automatically", "added", "by", "Decoy" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Middleware/Guest.php#L76-L99
30,784
BKWLD/decoy
classes/Fields/VideoEncoder.php
VideoEncoder.wrapAndRender
public function wrapAndRender() { // Check if the model has encodings if (($item = $this->getModel()) && method_exists($item, 'encodings')) { // If so, get it's encoding model instance $this->encoding = $item->encodings() ->where('encodable_attribute', $this->model_attribute) ->first(); // Add the data attributes for JS view if ($this->encoding) { $this->group->data_encode($this->encoding->id); } } // Continue rendering return parent::wrapAndRender(); }
php
public function wrapAndRender() { // Check if the model has encodings if (($item = $this->getModel()) && method_exists($item, 'encodings')) { // If so, get it's encoding model instance $this->encoding = $item->encodings() ->where('encodable_attribute', $this->model_attribute) ->first(); // Add the data attributes for JS view if ($this->encoding) { $this->group->data_encode($this->encoding->id); } } // Continue rendering return parent::wrapAndRender(); }
[ "public", "function", "wrapAndRender", "(", ")", "{", "// Check if the model has encodings", "if", "(", "(", "$", "item", "=", "$", "this", "->", "getModel", "(", ")", ")", "&&", "method_exists", "(", "$", "item", ",", "'encodings'", ")", ")", "{", "// If so, get it's encoding model instance", "$", "this", "->", "encoding", "=", "$", "item", "->", "encodings", "(", ")", "->", "where", "(", "'encodable_attribute'", ",", "$", "this", "->", "model_attribute", ")", "->", "first", "(", ")", ";", "// Add the data attributes for JS view", "if", "(", "$", "this", "->", "encoding", ")", "{", "$", "this", "->", "group", "->", "data_encode", "(", "$", "this", "->", "encoding", "->", "id", ")", ";", "}", "}", "// Continue rendering", "return", "parent", "::", "wrapAndRender", "(", ")", ";", "}" ]
Prints out the field, wrapped in its group. @return string
[ "Prints", "out", "the", "field", "wrapped", "in", "its", "group", "." ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/VideoEncoder.php#L101-L119
30,785
BKWLD/decoy
classes/Fields/VideoEncoder.php
VideoEncoder.renderPresets
protected function renderPresets() { // Create the dropdown menu options $config = config('decoy.encode.presets'); $presets = array_keys($config); $dropdown = implode('', array_map(function ($config, $preset) { return '<li> <a href="#" data-val="'.$preset.'"> '.$config['title'].' </a> </li>'; }, $config, $presets)); // Make the hidden field $hidden = '<input type="hidden" name="_preset['.$this->name.']" value="'.$this->presetValue().'">'; // Renturn the total markup return '<div class="input-group-btn js-tooltip" title="<b>Encoding quality.</b><br>Change to re-encode videos."> '.$hidden.' <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" > <span class="selected">Presets</span> <span class="caret"></span> </button> <ul class="dropdown-menu dropdown-menu-right presets"> '.$dropdown.' </ul> </div>'; }
php
protected function renderPresets() { // Create the dropdown menu options $config = config('decoy.encode.presets'); $presets = array_keys($config); $dropdown = implode('', array_map(function ($config, $preset) { return '<li> <a href="#" data-val="'.$preset.'"> '.$config['title'].' </a> </li>'; }, $config, $presets)); // Make the hidden field $hidden = '<input type="hidden" name="_preset['.$this->name.']" value="'.$this->presetValue().'">'; // Renturn the total markup return '<div class="input-group-btn js-tooltip" title="<b>Encoding quality.</b><br>Change to re-encode videos."> '.$hidden.' <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" > <span class="selected">Presets</span> <span class="caret"></span> </button> <ul class="dropdown-menu dropdown-menu-right presets"> '.$dropdown.' </ul> </div>'; }
[ "protected", "function", "renderPresets", "(", ")", "{", "// Create the dropdown menu options", "$", "config", "=", "config", "(", "'decoy.encode.presets'", ")", ";", "$", "presets", "=", "array_keys", "(", "$", "config", ")", ";", "$", "dropdown", "=", "implode", "(", "''", ",", "array_map", "(", "function", "(", "$", "config", ",", "$", "preset", ")", "{", "return", "'<li>\n <a href=\"#\" data-val=\"'", ".", "$", "preset", ".", "'\">\n '", ".", "$", "config", "[", "'title'", "]", ".", "'\n </a>\n </li>'", ";", "}", ",", "$", "config", ",", "$", "presets", ")", ")", ";", "// Make the hidden field", "$", "hidden", "=", "'<input type=\"hidden\"\n name=\"_preset['", ".", "$", "this", "->", "name", ".", "']\"\n value=\"'", ".", "$", "this", "->", "presetValue", "(", ")", ".", "'\">'", ";", "// Renturn the total markup", "return", "'<div class=\"input-group-btn js-tooltip\"\n title=\"<b>Encoding quality.</b><br>Change to re-encode videos.\">\n '", ".", "$", "hidden", ".", "'\n <button type=\"button\"\n class=\"btn btn-default dropdown-toggle\"\n data-toggle=\"dropdown\" >\n <span class=\"selected\">Presets</span>\n <span class=\"caret\"></span>\n </button>\n <ul class=\"dropdown-menu dropdown-menu-right presets\">\n '", ".", "$", "dropdown", ".", "'\n </ul>\n </div>'", ";", "}" ]
Render the presets select menu @return string
[ "Render", "the", "presets", "select", "menu" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/VideoEncoder.php#L126-L158
30,786
BKWLD/decoy
classes/Fields/VideoEncoder.php
VideoEncoder.presetValue
protected function presetValue() { if ($this->encoding) { return $this->encoding->preset; } if ($this->preset) { return $this->preset; } return array_keys(config('decoy.encode.presets'))[0]; }
php
protected function presetValue() { if ($this->encoding) { return $this->encoding->preset; } if ($this->preset) { return $this->preset; } return array_keys(config('decoy.encode.presets'))[0]; }
[ "protected", "function", "presetValue", "(", ")", "{", "if", "(", "$", "this", "->", "encoding", ")", "{", "return", "$", "this", "->", "encoding", "->", "preset", ";", "}", "if", "(", "$", "this", "->", "preset", ")", "{", "return", "$", "this", "->", "preset", ";", "}", "return", "array_keys", "(", "config", "(", "'decoy.encode.presets'", ")", ")", "[", "0", "]", ";", "}" ]
Get the preset value @return string
[ "Get", "the", "preset", "value" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/VideoEncoder.php#L165-L176
30,787
BKWLD/decoy
classes/Fields/VideoEncoder.php
VideoEncoder.renderIndestructibleReview
protected function renderIndestructibleReview() { if ($this->encoding && $this->encoding->status == 'complete') { return $this->renderPlayerOrStatus(); } return $this->renderPlayerOrStatus().parent::renderIndestructibleReview(); }
php
protected function renderIndestructibleReview() { if ($this->encoding && $this->encoding->status == 'complete') { return $this->renderPlayerOrStatus(); } return $this->renderPlayerOrStatus().parent::renderIndestructibleReview(); }
[ "protected", "function", "renderIndestructibleReview", "(", ")", "{", "if", "(", "$", "this", "->", "encoding", "&&", "$", "this", "->", "encoding", "->", "status", "==", "'complete'", ")", "{", "return", "$", "this", "->", "renderPlayerOrStatus", "(", ")", ";", "}", "return", "$", "this", "->", "renderPlayerOrStatus", "(", ")", ".", "parent", "::", "renderIndestructibleReview", "(", ")", ";", "}" ]
Should only the video player with no checkbox @return string HTML
[ "Should", "only", "the", "video", "player", "with", "no", "checkbox" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/VideoEncoder.php#L193-L200
30,788
BKWLD/decoy
classes/Fields/VideoEncoder.php
VideoEncoder.renderPlayerOrStatus
protected function renderPlayerOrStatus() { if (!$this->encoding) { return $this->renderError('No encoding instance found.'); } switch ($this->encoding->status) { case 'complete': return $this->renderPlayer(); case 'error': return $this->renderError($this->encoding->message); case 'cancelled': return $this->renderError('The encoding job was manually cancelled'); case 'pending': return $this->renderProgress(''); case 'queued': return $this->renderProgress($this->encoding->status); case 'processing': return $this->renderProgress($this->encoding->status); } }
php
protected function renderPlayerOrStatus() { if (!$this->encoding) { return $this->renderError('No encoding instance found.'); } switch ($this->encoding->status) { case 'complete': return $this->renderPlayer(); case 'error': return $this->renderError($this->encoding->message); case 'cancelled': return $this->renderError('The encoding job was manually cancelled'); case 'pending': return $this->renderProgress(''); case 'queued': return $this->renderProgress($this->encoding->status); case 'processing': return $this->renderProgress($this->encoding->status); } }
[ "protected", "function", "renderPlayerOrStatus", "(", ")", "{", "if", "(", "!", "$", "this", "->", "encoding", ")", "{", "return", "$", "this", "->", "renderError", "(", "'No encoding instance found.'", ")", ";", "}", "switch", "(", "$", "this", "->", "encoding", "->", "status", ")", "{", "case", "'complete'", ":", "return", "$", "this", "->", "renderPlayer", "(", ")", ";", "case", "'error'", ":", "return", "$", "this", "->", "renderError", "(", "$", "this", "->", "encoding", "->", "message", ")", ";", "case", "'cancelled'", ":", "return", "$", "this", "->", "renderError", "(", "'The encoding job was manually cancelled'", ")", ";", "case", "'pending'", ":", "return", "$", "this", "->", "renderProgress", "(", "''", ")", ";", "case", "'queued'", ":", "return", "$", "this", "->", "renderProgress", "(", "$", "this", "->", "encoding", "->", "status", ")", ";", "case", "'processing'", ":", "return", "$", "this", "->", "renderProgress", "(", "$", "this", "->", "encoding", "->", "status", ")", ";", "}", "}" ]
Render the player if the encoding is complete. Otherwise, show progress @return string HTML
[ "Render", "the", "player", "if", "the", "encoding", "is", "complete", ".", "Otherwise", "show", "progress" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/VideoEncoder.php#L207-L233
30,789
BKWLD/decoy
classes/Controllers/Workers.php
Workers.tail
public function tail($worker) { // Form the path to the file $file = Model::logPath(urldecode($worker)); if (!file_exists($file)) { throw new Exception('Log not found: '.$file); } $size = 1024 * 100; // in bytes to get // Read from the end of the file clearstatcache(); $fp = fopen($file, 'r'); fseek($fp, -$size, SEEK_END); $contents = explode("\n", fread($fp, $size)); fclose($fp); // Reverse the contents and return $contents = array_reverse($contents); if (empty($contents[0])) { array_shift($contents); } die(implode("\n", $contents)); }
php
public function tail($worker) { // Form the path to the file $file = Model::logPath(urldecode($worker)); if (!file_exists($file)) { throw new Exception('Log not found: '.$file); } $size = 1024 * 100; // in bytes to get // Read from the end of the file clearstatcache(); $fp = fopen($file, 'r'); fseek($fp, -$size, SEEK_END); $contents = explode("\n", fread($fp, $size)); fclose($fp); // Reverse the contents and return $contents = array_reverse($contents); if (empty($contents[0])) { array_shift($contents); } die(implode("\n", $contents)); }
[ "public", "function", "tail", "(", "$", "worker", ")", "{", "// Form the path to the file", "$", "file", "=", "Model", "::", "logPath", "(", "urldecode", "(", "$", "worker", ")", ")", ";", "if", "(", "!", "file_exists", "(", "$", "file", ")", ")", "{", "throw", "new", "Exception", "(", "'Log not found: '", ".", "$", "file", ")", ";", "}", "$", "size", "=", "1024", "*", "100", ";", "// in bytes to get", "// Read from the end of the file", "clearstatcache", "(", ")", ";", "$", "fp", "=", "fopen", "(", "$", "file", ",", "'r'", ")", ";", "fseek", "(", "$", "fp", ",", "-", "$", "size", ",", "SEEK_END", ")", ";", "$", "contents", "=", "explode", "(", "\"\\n\"", ",", "fread", "(", "$", "fp", ",", "$", "size", ")", ")", ";", "fclose", "(", "$", "fp", ")", ";", "// Reverse the contents and return", "$", "contents", "=", "array_reverse", "(", "$", "contents", ")", ";", "if", "(", "empty", "(", "$", "contents", "[", "0", "]", ")", ")", "{", "array_shift", "(", "$", "contents", ")", ";", "}", "die", "(", "implode", "(", "\"\\n\"", ",", "$", "contents", ")", ")", ";", "}" ]
Ajax service that tails the log file for the selected worker @param $worker
[ "Ajax", "service", "that", "tails", "the", "log", "file", "for", "the", "selected", "worker" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Workers.php#L34-L56
30,790
BKWLD/decoy
classes/Auth/Policy.php
Policy.check
public function check(Admin $admin, $action, $controller) { // Convert controller instance to its string name if (is_object($controller)) { $controller = get_class($controller); } // Get the slug version of the controller. Test if a URL was passed first // and, if not, treat it like a full controller name. URLs are used in the // nav. Also, an already slugified controller name will work fine too. $pattern = '#/'.Config::get('decoy.core.dir').'/([^/]+)#'; if (preg_match($pattern, $controller, $matches)) { $controller = $matches[1]; } else { $controller = DecoyURL::slugController($controller); } // Allow all admins to upload to redactor if ($controller == 'redactor') { return true; } // Always allow an admin to edit themselves for changing password. Other // features will be disabled from the view file. if ($controller == 'admins' && ($action == 'read' || ($action == 'update' && Request::segment(3) == $admin->id))) { return true; } // Don't allow creation on Decoy controlers that don't allow it if ($action == 'create' && in_array($controller, [ 'commands', 'changes', 'elements', 'workers', ])) { return false; } // Always let developers access workers and commands if (in_array($controller, ['workers', 'commands']) && $admin->isDeveloper()) { return true; } // If the admin has permissions, test if they have access to the action using // the array of permitted actions. if ($permissions = $admin->getPermissionsAttribute()) { // Check that the controller was defined in the permissions if (!isset($permissions->$controller) || !is_array($permissions->$controller)) { return false; } // When interacting with elements, allow as long as there is at least one // page they have access to. Rely on the elements controller to enforce // additional restrictions. if ($controller == 'elements' && in_array($action, ['read', 'create'])) { return count($permissions->elements) > 0; } // Default behavior checks that the action was checked in the permissions // UI for the controller. return in_array($action, $permissions->$controller); } // If there are "can" rules, then apply them as a whitelist. Only those // actions are allowed. $can = Config::get('decoy.site.permissions.'.$admin->role.'.can'); if (is_callable($can)) { $can = call_user_func($can, $action, $controller); } if (is_array($can) && !in_array($action.'.'.$controller, $can) && !in_array('manage.'.$controller, $can)) { return false; } // If the action is listed as "can't" then immediately deny. Also check for // "manage" which means they can't do ANYTHING $cant = Config::get('decoy.site.permissions.'.$admin->role.'.cant'); if (is_callable($cant)) { $cant = call_user_func($cant, $action, $controller); } if (is_array($cant) && ( in_array($action.'.'.$controller, $cant) || in_array('manage.'.$controller, $cant))) { return false; } // I guess we're good to go return true; }
php
public function check(Admin $admin, $action, $controller) { // Convert controller instance to its string name if (is_object($controller)) { $controller = get_class($controller); } // Get the slug version of the controller. Test if a URL was passed first // and, if not, treat it like a full controller name. URLs are used in the // nav. Also, an already slugified controller name will work fine too. $pattern = '#/'.Config::get('decoy.core.dir').'/([^/]+)#'; if (preg_match($pattern, $controller, $matches)) { $controller = $matches[1]; } else { $controller = DecoyURL::slugController($controller); } // Allow all admins to upload to redactor if ($controller == 'redactor') { return true; } // Always allow an admin to edit themselves for changing password. Other // features will be disabled from the view file. if ($controller == 'admins' && ($action == 'read' || ($action == 'update' && Request::segment(3) == $admin->id))) { return true; } // Don't allow creation on Decoy controlers that don't allow it if ($action == 'create' && in_array($controller, [ 'commands', 'changes', 'elements', 'workers', ])) { return false; } // Always let developers access workers and commands if (in_array($controller, ['workers', 'commands']) && $admin->isDeveloper()) { return true; } // If the admin has permissions, test if they have access to the action using // the array of permitted actions. if ($permissions = $admin->getPermissionsAttribute()) { // Check that the controller was defined in the permissions if (!isset($permissions->$controller) || !is_array($permissions->$controller)) { return false; } // When interacting with elements, allow as long as there is at least one // page they have access to. Rely on the elements controller to enforce // additional restrictions. if ($controller == 'elements' && in_array($action, ['read', 'create'])) { return count($permissions->elements) > 0; } // Default behavior checks that the action was checked in the permissions // UI for the controller. return in_array($action, $permissions->$controller); } // If there are "can" rules, then apply them as a whitelist. Only those // actions are allowed. $can = Config::get('decoy.site.permissions.'.$admin->role.'.can'); if (is_callable($can)) { $can = call_user_func($can, $action, $controller); } if (is_array($can) && !in_array($action.'.'.$controller, $can) && !in_array('manage.'.$controller, $can)) { return false; } // If the action is listed as "can't" then immediately deny. Also check for // "manage" which means they can't do ANYTHING $cant = Config::get('decoy.site.permissions.'.$admin->role.'.cant'); if (is_callable($cant)) { $cant = call_user_func($cant, $action, $controller); } if (is_array($cant) && ( in_array($action.'.'.$controller, $cant) || in_array('manage.'.$controller, $cant))) { return false; } // I guess we're good to go return true; }
[ "public", "function", "check", "(", "Admin", "$", "admin", ",", "$", "action", ",", "$", "controller", ")", "{", "// Convert controller instance to its string name", "if", "(", "is_object", "(", "$", "controller", ")", ")", "{", "$", "controller", "=", "get_class", "(", "$", "controller", ")", ";", "}", "// Get the slug version of the controller. Test if a URL was passed first", "// and, if not, treat it like a full controller name. URLs are used in the", "// nav. Also, an already slugified controller name will work fine too.", "$", "pattern", "=", "'#/'", ".", "Config", "::", "get", "(", "'decoy.core.dir'", ")", ".", "'/([^/]+)#'", ";", "if", "(", "preg_match", "(", "$", "pattern", ",", "$", "controller", ",", "$", "matches", ")", ")", "{", "$", "controller", "=", "$", "matches", "[", "1", "]", ";", "}", "else", "{", "$", "controller", "=", "DecoyURL", "::", "slugController", "(", "$", "controller", ")", ";", "}", "// Allow all admins to upload to redactor", "if", "(", "$", "controller", "==", "'redactor'", ")", "{", "return", "true", ";", "}", "// Always allow an admin to edit themselves for changing password. Other", "// features will be disabled from the view file.", "if", "(", "$", "controller", "==", "'admins'", "&&", "(", "$", "action", "==", "'read'", "||", "(", "$", "action", "==", "'update'", "&&", "Request", "::", "segment", "(", "3", ")", "==", "$", "admin", "->", "id", ")", ")", ")", "{", "return", "true", ";", "}", "// Don't allow creation on Decoy controlers that don't allow it", "if", "(", "$", "action", "==", "'create'", "&&", "in_array", "(", "$", "controller", ",", "[", "'commands'", ",", "'changes'", ",", "'elements'", ",", "'workers'", ",", "]", ")", ")", "{", "return", "false", ";", "}", "// Always let developers access workers and commands", "if", "(", "in_array", "(", "$", "controller", ",", "[", "'workers'", ",", "'commands'", "]", ")", "&&", "$", "admin", "->", "isDeveloper", "(", ")", ")", "{", "return", "true", ";", "}", "// If the admin has permissions, test if they have access to the action using", "// the array of permitted actions.", "if", "(", "$", "permissions", "=", "$", "admin", "->", "getPermissionsAttribute", "(", ")", ")", "{", "// Check that the controller was defined in the permissions", "if", "(", "!", "isset", "(", "$", "permissions", "->", "$", "controller", ")", "||", "!", "is_array", "(", "$", "permissions", "->", "$", "controller", ")", ")", "{", "return", "false", ";", "}", "// When interacting with elements, allow as long as there is at least one", "// page they have access to. Rely on the elements controller to enforce", "// additional restrictions.", "if", "(", "$", "controller", "==", "'elements'", "&&", "in_array", "(", "$", "action", ",", "[", "'read'", ",", "'create'", "]", ")", ")", "{", "return", "count", "(", "$", "permissions", "->", "elements", ")", ">", "0", ";", "}", "// Default behavior checks that the action was checked in the permissions", "// UI for the controller.", "return", "in_array", "(", "$", "action", ",", "$", "permissions", "->", "$", "controller", ")", ";", "}", "// If there are \"can\" rules, then apply them as a whitelist. Only those", "// actions are allowed.", "$", "can", "=", "Config", "::", "get", "(", "'decoy.site.permissions.'", ".", "$", "admin", "->", "role", ".", "'.can'", ")", ";", "if", "(", "is_callable", "(", "$", "can", ")", ")", "{", "$", "can", "=", "call_user_func", "(", "$", "can", ",", "$", "action", ",", "$", "controller", ")", ";", "}", "if", "(", "is_array", "(", "$", "can", ")", "&&", "!", "in_array", "(", "$", "action", ".", "'.'", ".", "$", "controller", ",", "$", "can", ")", "&&", "!", "in_array", "(", "'manage.'", ".", "$", "controller", ",", "$", "can", ")", ")", "{", "return", "false", ";", "}", "// If the action is listed as \"can't\" then immediately deny. Also check for", "// \"manage\" which means they can't do ANYTHING", "$", "cant", "=", "Config", "::", "get", "(", "'decoy.site.permissions.'", ".", "$", "admin", "->", "role", ".", "'.cant'", ")", ";", "if", "(", "is_callable", "(", "$", "cant", ")", ")", "{", "$", "cant", "=", "call_user_func", "(", "$", "cant", ",", "$", "action", ",", "$", "controller", ")", ";", "}", "if", "(", "is_array", "(", "$", "cant", ")", "&&", "(", "in_array", "(", "$", "action", ".", "'.'", ".", "$", "controller", ",", "$", "cant", ")", "||", "in_array", "(", "'manage.'", ".", "$", "controller", ",", "$", "cant", ")", ")", ")", "{", "return", "false", ";", "}", "// I guess we're good to go", "return", "true", ";", "}" ]
Check an Admin model against an action performed on a controller against permissions from the config. @param Admin $admin @param string $action The verb we're checking. Examples: - create - read - update - destroy - manage - publish @param string $controller - controller instance - controller name (Admin\ArticlesController) - URL (/admin/articles) - slug (articles) @return boolean
[ "Check", "an", "Admin", "model", "against", "an", "action", "performed", "on", "a", "controller", "against", "permissions", "from", "the", "config", "." ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Auth/Policy.php#L34-L124
30,791
BKWLD/decoy
classes/Models/Base.php
Base.hasGetMutator
public function hasGetMutator($key) { if (!Decoy::handling() || !array_key_exists($key, $this->attributes) || in_array($key, $this->admin_mutators)) { return parent::hasGetMutator($key); } }
php
public function hasGetMutator($key) { if (!Decoy::handling() || !array_key_exists($key, $this->attributes) || in_array($key, $this->admin_mutators)) { return parent::hasGetMutator($key); } }
[ "public", "function", "hasGetMutator", "(", "$", "key", ")", "{", "if", "(", "!", "Decoy", "::", "handling", "(", ")", "||", "!", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "attributes", ")", "||", "in_array", "(", "$", "key", ",", "$", "this", "->", "admin_mutators", ")", ")", "{", "return", "parent", "::", "hasGetMutator", "(", "$", "key", ")", ";", "}", "}" ]
Disable mutators unless the active request isn't for the admin, the key doesn't reference a true database-backed attribute, or the key was expressly whitelisted in the admin_mutators property. @param string $key @return mixed
[ "Disable", "mutators", "unless", "the", "active", "request", "isn", "t", "for", "the", "admin", "the", "key", "doesn", "t", "reference", "a", "true", "database", "-", "backed", "attribute", "or", "the", "key", "was", "expressly", "whitelisted", "in", "the", "admin_mutators", "property", "." ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L124-L131
30,792
BKWLD/decoy
classes/Models/Base.php
Base.getAdminThumbAttribute
public function getAdminThumbAttribute($width = 40, $height = 40) { // Check if there are images for the model if (!method_exists($this, 'images')) { return; } $images = $this->images; if ($images->isEmpty()) { return; } // Get null-named (default) images first return $images->sortBy('name')->first()->crop($width, $height)->url; }
php
public function getAdminThumbAttribute($width = 40, $height = 40) { // Check if there are images for the model if (!method_exists($this, 'images')) { return; } $images = $this->images; if ($images->isEmpty()) { return; } // Get null-named (default) images first return $images->sortBy('name')->first()->crop($width, $height)->url; }
[ "public", "function", "getAdminThumbAttribute", "(", "$", "width", "=", "40", ",", "$", "height", "=", "40", ")", "{", "// Check if there are images for the model", "if", "(", "!", "method_exists", "(", "$", "this", ",", "'images'", ")", ")", "{", "return", ";", "}", "$", "images", "=", "$", "this", "->", "images", ";", "if", "(", "$", "images", "->", "isEmpty", "(", ")", ")", "{", "return", ";", "}", "// Get null-named (default) images first", "return", "$", "images", "->", "sortBy", "(", "'name'", ")", "->", "first", "(", ")", "->", "crop", "(", "$", "width", ",", "$", "height", ")", "->", "url", ";", "}" ]
The URL for the thumbnail @return string URL
[ "The", "URL", "for", "the", "thumbnail" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L290-L305
30,793
BKWLD/decoy
classes/Models/Base.php
Base.getFileAttributesAttribute
public function getFileAttributesAttribute() { // Get all the file validation rule keys $attributes = array_keys(array_filter(static::$rules, function ($rules) { return preg_match('#file|image|mimes|video|dimensions#i', $rules); })); // Get all the model attributes from upchuck if (method_exists($this, 'getUploadMap')) { $attributes = array_unique(array_merge($attributes, array_values($this->getUploadMap()))); } // Return array of attributes return $attributes; }
php
public function getFileAttributesAttribute() { // Get all the file validation rule keys $attributes = array_keys(array_filter(static::$rules, function ($rules) { return preg_match('#file|image|mimes|video|dimensions#i', $rules); })); // Get all the model attributes from upchuck if (method_exists($this, 'getUploadMap')) { $attributes = array_unique(array_merge($attributes, array_values($this->getUploadMap()))); } // Return array of attributes return $attributes; }
[ "public", "function", "getFileAttributesAttribute", "(", ")", "{", "// Get all the file validation rule keys", "$", "attributes", "=", "array_keys", "(", "array_filter", "(", "static", "::", "$", "rules", ",", "function", "(", "$", "rules", ")", "{", "return", "preg_match", "(", "'#file|image|mimes|video|dimensions#i'", ",", "$", "rules", ")", ";", "}", ")", ")", ";", "// Get all the model attributes from upchuck", "if", "(", "method_exists", "(", "$", "this", ",", "'getUploadMap'", ")", ")", "{", "$", "attributes", "=", "array_unique", "(", "array_merge", "(", "$", "attributes", ",", "array_values", "(", "$", "this", "->", "getUploadMap", "(", ")", ")", ")", ")", ";", "}", "// Return array of attributes", "return", "$", "attributes", ";", "}" ]
Get all file fields by looking at Upchuck config and validation rules @return array The keys of all the attributes that store file references
[ "Get", "all", "file", "fields", "by", "looking", "at", "Upchuck", "config", "and", "validation", "rules" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L329-L345
30,794
BKWLD/decoy
classes/Models/Base.php
Base.getAdminRowClassAttribute
public function getAdminRowClassAttribute() { $classes = []; // Add a visbility classs if ($this->public) { $classes[] = 'is-public'; } // Add a soft-deleted class if (method_exists($this, 'trashed') && $this->trashed()) { $classes[] = 'is-trashed'; } // Return all classes return implode(' ', $classes); }
php
public function getAdminRowClassAttribute() { $classes = []; // Add a visbility classs if ($this->public) { $classes[] = 'is-public'; } // Add a soft-deleted class if (method_exists($this, 'trashed') && $this->trashed()) { $classes[] = 'is-trashed'; } // Return all classes return implode(' ', $classes); }
[ "public", "function", "getAdminRowClassAttribute", "(", ")", "{", "$", "classes", "=", "[", "]", ";", "// Add a visbility classs", "if", "(", "$", "this", "->", "public", ")", "{", "$", "classes", "[", "]", "=", "'is-public'", ";", "}", "// Add a soft-deleted class", "if", "(", "method_exists", "(", "$", "this", ",", "'trashed'", ")", "&&", "$", "this", "->", "trashed", "(", ")", ")", "{", "$", "classes", "[", "]", "=", "'is-trashed'", ";", "}", "// Return all classes", "return", "implode", "(", "' '", ",", "$", "classes", ")", ";", "}" ]
Automatically add classes to rows in listing tables in the admin @return string
[ "Automatically", "add", "classes", "to", "rows", "in", "listing", "tables", "in", "the", "admin" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L367-L382
30,795
BKWLD/decoy
classes/Models/Base.php
Base.getAttributesForLocalizationComparisonAttribute
public function getAttributesForLocalizationComparisonAttribute() { $attributes = $this->getAttributes(); if (method_exists($this, 'croppedImages')) { $attributes['images'] = $this->croppedImages(300); } return $attributes; }
php
public function getAttributesForLocalizationComparisonAttribute() { $attributes = $this->getAttributes(); if (method_exists($this, 'croppedImages')) { $attributes['images'] = $this->croppedImages(300); } return $attributes; }
[ "public", "function", "getAttributesForLocalizationComparisonAttribute", "(", ")", "{", "$", "attributes", "=", "$", "this", "->", "getAttributes", "(", ")", ";", "if", "(", "method_exists", "(", "$", "this", ",", "'croppedImages'", ")", ")", "{", "$", "attributes", "[", "'images'", "]", "=", "$", "this", "->", "croppedImages", "(", "300", ")", ";", "}", "return", "$", "attributes", ";", "}" ]
Expose model attributes for comparison by the localization sidebar @return array
[ "Expose", "model", "attributes", "for", "comparison", "by", "the", "localization", "sidebar" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L389-L396
30,796
BKWLD/decoy
classes/Models/Base.php
Base.makeAdminActions
public function makeAdminActions($data) { $actions = []; if ($html = $this->makeVisibilityAction($data)) { $actions['visibility'] = $html; } if ($html = $this->makeEditAction($data)) { $actions['edit'] = $html; } if ($html = $this->makeViewAction($data)) { $actions['view'] = $html; } if ($html = $this->makeDeleteAction($data)) { $actions['delete'] = $html; } return $actions; }
php
public function makeAdminActions($data) { $actions = []; if ($html = $this->makeVisibilityAction($data)) { $actions['visibility'] = $html; } if ($html = $this->makeEditAction($data)) { $actions['edit'] = $html; } if ($html = $this->makeViewAction($data)) { $actions['view'] = $html; } if ($html = $this->makeDeleteAction($data)) { $actions['delete'] = $html; } return $actions; }
[ "public", "function", "makeAdminActions", "(", "$", "data", ")", "{", "$", "actions", "=", "[", "]", ";", "if", "(", "$", "html", "=", "$", "this", "->", "makeVisibilityAction", "(", "$", "data", ")", ")", "{", "$", "actions", "[", "'visibility'", "]", "=", "$", "html", ";", "}", "if", "(", "$", "html", "=", "$", "this", "->", "makeEditAction", "(", "$", "data", ")", ")", "{", "$", "actions", "[", "'edit'", "]", "=", "$", "html", ";", "}", "if", "(", "$", "html", "=", "$", "this", "->", "makeViewAction", "(", "$", "data", ")", ")", "{", "$", "actions", "[", "'view'", "]", "=", "$", "html", ";", "}", "if", "(", "$", "html", "=", "$", "this", "->", "makeDeleteAction", "(", "$", "data", ")", ")", "{", "$", "actions", "[", "'delete'", "]", "=", "$", "html", ";", "}", "return", "$", "actions", ";", "}" ]
Make the markup for the actions column of the admin listing view. The indivudal actions are stored in an array that is iterted through in the view @param array $data The data passed to a listing view @return array
[ "Make", "the", "markup", "for", "the", "actions", "column", "of", "the", "admin", "listing", "view", ".", "The", "indivudal", "actions", "are", "stored", "in", "an", "array", "that", "is", "iterted", "through", "in", "the", "view" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L410-L431
30,797
BKWLD/decoy
classes/Models/Base.php
Base.makeVisibilityAction
protected function makeVisibilityAction($data) { extract($data); // Check if this model supports editing the visibility if ($many_to_many || !app('decoy.user')->can('publish', $controller) || !array_key_exists('public', $this->attributes)) { return; } // Create the markup $public = $this->getAttribute('public'); return sprintf('<a class="visibility js-tooltip" data-placement="left" title="%s"> <span class="glyphicon glyphicon-eye-%s"></span> </a>', $public ? __('decoy::base.standard_list.private') : __('decoy::base.standard_list.publish'), $public ? 'open' : 'close' ); }
php
protected function makeVisibilityAction($data) { extract($data); // Check if this model supports editing the visibility if ($many_to_many || !app('decoy.user')->can('publish', $controller) || !array_key_exists('public', $this->attributes)) { return; } // Create the markup $public = $this->getAttribute('public'); return sprintf('<a class="visibility js-tooltip" data-placement="left" title="%s"> <span class="glyphicon glyphicon-eye-%s"></span> </a>', $public ? __('decoy::base.standard_list.private') : __('decoy::base.standard_list.publish'), $public ? 'open' : 'close' ); }
[ "protected", "function", "makeVisibilityAction", "(", "$", "data", ")", "{", "extract", "(", "$", "data", ")", ";", "// Check if this model supports editing the visibility", "if", "(", "$", "many_to_many", "||", "!", "app", "(", "'decoy.user'", ")", "->", "can", "(", "'publish'", ",", "$", "controller", ")", "||", "!", "array_key_exists", "(", "'public'", ",", "$", "this", "->", "attributes", ")", ")", "{", "return", ";", "}", "// Create the markup", "$", "public", "=", "$", "this", "->", "getAttribute", "(", "'public'", ")", ";", "return", "sprintf", "(", "'<a class=\"visibility js-tooltip\" data-placement=\"left\" title=\"%s\">\n <span class=\"glyphicon glyphicon-eye-%s\"></span>\n </a>'", ",", "$", "public", "?", "__", "(", "'decoy::base.standard_list.private'", ")", ":", "__", "(", "'decoy::base.standard_list.publish'", ")", ",", "$", "public", "?", "'open'", ":", "'close'", ")", ";", "}" ]
Make the visibility state action @param array $data The data passed to a listing view @return string
[ "Make", "the", "visibility", "state", "action" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L439-L458
30,798
BKWLD/decoy
classes/Models/Base.php
Base.makeEditAction
protected function makeEditAction($data) { extract($data); // Make markup $editable = app('decoy.user')->can('update', $controller); return sprintf('<a href="%s" class="action-edit js-tooltip" data-placement="left" title="%s"> <span class="glyphicon glyphicon-%s"></span> </a>', $this->getAdminEditUri($controller, $many_to_many), // URL $editable ? // Label __('decoy::base.action.edit') : __('decoy::base.action.read') , $editable ? 'pencil' : 'zoom-in' // Icon ); }
php
protected function makeEditAction($data) { extract($data); // Make markup $editable = app('decoy.user')->can('update', $controller); return sprintf('<a href="%s" class="action-edit js-tooltip" data-placement="left" title="%s"> <span class="glyphicon glyphicon-%s"></span> </a>', $this->getAdminEditUri($controller, $many_to_many), // URL $editable ? // Label __('decoy::base.action.edit') : __('decoy::base.action.read') , $editable ? 'pencil' : 'zoom-in' // Icon ); }
[ "protected", "function", "makeEditAction", "(", "$", "data", ")", "{", "extract", "(", "$", "data", ")", ";", "// Make markup", "$", "editable", "=", "app", "(", "'decoy.user'", ")", "->", "can", "(", "'update'", ",", "$", "controller", ")", ";", "return", "sprintf", "(", "'<a href=\"%s\" class=\"action-edit js-tooltip\"\n data-placement=\"left\" title=\"%s\">\n <span class=\"glyphicon glyphicon-%s\"></span>\n </a>'", ",", "$", "this", "->", "getAdminEditUri", "(", "$", "controller", ",", "$", "many_to_many", ")", ",", "// URL", "$", "editable", "?", "// Label", "__", "(", "'decoy::base.action.edit'", ")", ":", "__", "(", "'decoy::base.action.read'", ")", ",", "$", "editable", "?", "'pencil'", ":", "'zoom-in'", "// Icon", ")", ";", "}" ]
Make the edit or view action. @param array $data The data passed to a listing view @return string
[ "Make", "the", "edit", "or", "view", "action", "." ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L466-L482
30,799
BKWLD/decoy
classes/Models/Base.php
Base.getAdminEditUri
public function getAdminEditUri($controller, $many_to_many = false) { if ($many_to_many) { return URL::to(DecoyURL::action($controller.'@edit', $this->getKey())); } return URL::to(DecoyURL::relative('edit', $this->getKey(), $controller)); }
php
public function getAdminEditUri($controller, $many_to_many = false) { if ($many_to_many) { return URL::to(DecoyURL::action($controller.'@edit', $this->getKey())); } return URL::to(DecoyURL::relative('edit', $this->getKey(), $controller)); }
[ "public", "function", "getAdminEditUri", "(", "$", "controller", ",", "$", "many_to_many", "=", "false", ")", "{", "if", "(", "$", "many_to_many", ")", "{", "return", "URL", "::", "to", "(", "DecoyURL", "::", "action", "(", "$", "controller", ".", "'@edit'", ",", "$", "this", "->", "getKey", "(", ")", ")", ")", ";", "}", "return", "URL", "::", "to", "(", "DecoyURL", "::", "relative", "(", "'edit'", ",", "$", "this", "->", "getKey", "(", ")", ",", "$", "controller", ")", ")", ";", "}" ]
Get the admin edit URL assuming you know the controller and whether it's being listed as a many to many @param string $controller ex: Admin\ArticlesController @param boolean $many_to_many @return string
[ "Get", "the", "admin", "edit", "URL", "assuming", "you", "know", "the", "controller", "and", "whether", "it", "s", "being", "listed", "as", "a", "many", "to", "many" ]
7a4acfa8e00cdca7ef4d82672a6547bae61f8e73
https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L492-L499