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
34,600
nails/module-cdn
src/Service/Cdn.php
Cdn.getCountCommonBuckets
public function getCountCommonBuckets($aData = []) { if (!empty($aData['keywords'])) { if (empty($aData['or_like'])) { $aData['or_like'] = []; } $aData['or_like'][] = [ 'column' => 'b.label', 'value' => $aData['keywords'], ]; } $this->getCountCommon($aData); }
php
public function getCountCommonBuckets($aData = []) { if (!empty($aData['keywords'])) { if (empty($aData['or_like'])) { $aData['or_like'] = []; } $aData['or_like'][] = [ 'column' => 'b.label', 'value' => $aData['keywords'], ]; } $this->getCountCommon($aData); }
[ "public", "function", "getCountCommonBuckets", "(", "$", "aData", "=", "[", "]", ")", "{", "if", "(", "!", "empty", "(", "$", "aData", "[", "'keywords'", "]", ")", ")", "{", "if", "(", "empty", "(", "$", "aData", "[", "'or_like'", "]", ")", ")", "{", "$", "aData", "[", "'or_like'", "]", "=", "[", "]", ";", "}", "$", "aData", "[", "'or_like'", "]", "[", "]", "=", "[", "'column'", "=>", "'b.label'", ",", "'value'", "=>", "$", "aData", "[", "'keywords'", "]", ",", "]", ";", "}", "$", "this", "->", "getCountCommon", "(", "$", "aData", ")", ";", "}" ]
Applies keyword searching for buckets @param array $aData Data to pass to parent::getCountCommon
[ "Applies", "keyword", "searching", "for", "buckets" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L1735-L1748
34,601
nails/module-cdn
src/Service/Cdn.php
Cdn.getBucketsFlat
public function getBucketsFlat($page = null, $perPage = null, $data = []) { $aBuckets = $this->getBuckets($page, $perPage, $data); $aOut = []; foreach ($aBuckets as $oBucket) { $aOut[$oBucket->id] = $oBucket->label; } return $aOut; }
php
public function getBucketsFlat($page = null, $perPage = null, $data = []) { $aBuckets = $this->getBuckets($page, $perPage, $data); $aOut = []; foreach ($aBuckets as $oBucket) { $aOut[$oBucket->id] = $oBucket->label; } return $aOut; }
[ "public", "function", "getBucketsFlat", "(", "$", "page", "=", "null", ",", "$", "perPage", "=", "null", ",", "$", "data", "=", "[", "]", ")", "{", "$", "aBuckets", "=", "$", "this", "->", "getBuckets", "(", "$", "page", ",", "$", "perPage", ",", "$", "data", ")", ";", "$", "aOut", "=", "[", "]", ";", "foreach", "(", "$", "aBuckets", "as", "$", "oBucket", ")", "{", "$", "aOut", "[", "$", "oBucket", "->", "id", "]", "=", "$", "oBucket", "->", "label", ";", "}", "return", "$", "aOut", ";", "}" ]
Returns an array of buckets as a flat array @param integer $page The page to return @param integer $perPage The number of items to return per page @param array $data An array of data to pass to getCountCommonBuckets() @return array
[ "Returns", "an", "array", "of", "buckets", "as", "a", "flat", "array" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L1761-L1771
34,602
nails/module-cdn
src/Service/Cdn.php
Cdn.getBucket
public function getBucket($bucketIdSlug) { $aData = ['where' => []]; if (is_numeric($bucketIdSlug)) { $aData['where'][] = ['b.id', $bucketIdSlug]; } else { $aData['where'][] = ['b.slug', $bucketIdSlug]; } $aBuckets = $this->getBuckets(null, null, $aData); if (empty($aBuckets)) { return false; } return $aBuckets[0]; }
php
public function getBucket($bucketIdSlug) { $aData = ['where' => []]; if (is_numeric($bucketIdSlug)) { $aData['where'][] = ['b.id', $bucketIdSlug]; } else { $aData['where'][] = ['b.slug', $bucketIdSlug]; } $aBuckets = $this->getBuckets(null, null, $aData); if (empty($aBuckets)) { return false; } return $aBuckets[0]; }
[ "public", "function", "getBucket", "(", "$", "bucketIdSlug", ")", "{", "$", "aData", "=", "[", "'where'", "=>", "[", "]", "]", ";", "if", "(", "is_numeric", "(", "$", "bucketIdSlug", ")", ")", "{", "$", "aData", "[", "'where'", "]", "[", "]", "=", "[", "'b.id'", ",", "$", "bucketIdSlug", "]", ";", "}", "else", "{", "$", "aData", "[", "'where'", "]", "[", "]", "=", "[", "'b.slug'", ",", "$", "bucketIdSlug", "]", ";", "}", "$", "aBuckets", "=", "$", "this", "->", "getBuckets", "(", "null", ",", "null", ",", "$", "aData", ")", ";", "if", "(", "empty", "(", "$", "aBuckets", ")", ")", "{", "return", "false", ";", "}", "return", "$", "aBuckets", "[", "0", "]", ";", "}" ]
Returns a single bucket object @param string @return \stdClass|false
[ "Returns", "a", "single", "bucket", "object" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L1782-L1799
34,603
nails/module-cdn
src/Service/Cdn.php
Cdn.bucketCreate
public function bucketCreate($sSlug, $sLabel = null, $aAllowedTypes = []) { if (is_array($sSlug)) { $aBucketData = $sSlug; } else { $aBucketData = [ 'slug' => $sSlug, 'label' => $sLabel, 'allowed_types' => $aAllowedTypes, ]; } $sSlug = getFromArray('slug', $aBucketData); // Test if bucket exists, if it does stop, job done. $oBucket = $this->getBucket($sSlug); if ($oBucket) { return $oBucket->id; } // -------------------------------------------------------------------------- $bResult = $this->callDriver('bucketCreate', [$sSlug]); if ($bResult) { $oBucketModel = Factory::model('Bucket', 'nails/module-cdn'); if (empty($aBucketData['label'])) { $aBucketData['label'] = ucwords(str_replace('-', ' ', $sSlug)); } if (!empty($aBucketData['allowed_types'])) { if (!is_array($aBucketData['allowed_types'])) { $aBucketData['allowed_types'] = (array) $aBucketData['allowed_types']; } $aBucketData['allowed_types'] = array_filter($aBucketData['allowed_types']); $aBucketData['allowed_types'] = array_unique($aBucketData['allowed_types']); $aBucketData['allowed_types'] = implode('|', $aBucketData['allowed_types']); } $iBucketId = $oBucketModel->create($aBucketData); if ($iBucketId) { return $iBucketId; } else { $this->callDriver('destroy', [$sSlug]); $this->setError('Failed to create bucket record'); return false; } } else { $this->setError($this->callDriver('lastError')); return false; } }
php
public function bucketCreate($sSlug, $sLabel = null, $aAllowedTypes = []) { if (is_array($sSlug)) { $aBucketData = $sSlug; } else { $aBucketData = [ 'slug' => $sSlug, 'label' => $sLabel, 'allowed_types' => $aAllowedTypes, ]; } $sSlug = getFromArray('slug', $aBucketData); // Test if bucket exists, if it does stop, job done. $oBucket = $this->getBucket($sSlug); if ($oBucket) { return $oBucket->id; } // -------------------------------------------------------------------------- $bResult = $this->callDriver('bucketCreate', [$sSlug]); if ($bResult) { $oBucketModel = Factory::model('Bucket', 'nails/module-cdn'); if (empty($aBucketData['label'])) { $aBucketData['label'] = ucwords(str_replace('-', ' ', $sSlug)); } if (!empty($aBucketData['allowed_types'])) { if (!is_array($aBucketData['allowed_types'])) { $aBucketData['allowed_types'] = (array) $aBucketData['allowed_types']; } $aBucketData['allowed_types'] = array_filter($aBucketData['allowed_types']); $aBucketData['allowed_types'] = array_unique($aBucketData['allowed_types']); $aBucketData['allowed_types'] = implode('|', $aBucketData['allowed_types']); } $iBucketId = $oBucketModel->create($aBucketData); if ($iBucketId) { return $iBucketId; } else { $this->callDriver('destroy', [$sSlug]); $this->setError('Failed to create bucket record'); return false; } } else { $this->setError($this->callDriver('lastError')); return false; } }
[ "public", "function", "bucketCreate", "(", "$", "sSlug", ",", "$", "sLabel", "=", "null", ",", "$", "aAllowedTypes", "=", "[", "]", ")", "{", "if", "(", "is_array", "(", "$", "sSlug", ")", ")", "{", "$", "aBucketData", "=", "$", "sSlug", ";", "}", "else", "{", "$", "aBucketData", "=", "[", "'slug'", "=>", "$", "sSlug", ",", "'label'", "=>", "$", "sLabel", ",", "'allowed_types'", "=>", "$", "aAllowedTypes", ",", "]", ";", "}", "$", "sSlug", "=", "getFromArray", "(", "'slug'", ",", "$", "aBucketData", ")", ";", "// Test if bucket exists, if it does stop, job done.", "$", "oBucket", "=", "$", "this", "->", "getBucket", "(", "$", "sSlug", ")", ";", "if", "(", "$", "oBucket", ")", "{", "return", "$", "oBucket", "->", "id", ";", "}", "// --------------------------------------------------------------------------", "$", "bResult", "=", "$", "this", "->", "callDriver", "(", "'bucketCreate'", ",", "[", "$", "sSlug", "]", ")", ";", "if", "(", "$", "bResult", ")", "{", "$", "oBucketModel", "=", "Factory", "::", "model", "(", "'Bucket'", ",", "'nails/module-cdn'", ")", ";", "if", "(", "empty", "(", "$", "aBucketData", "[", "'label'", "]", ")", ")", "{", "$", "aBucketData", "[", "'label'", "]", "=", "ucwords", "(", "str_replace", "(", "'-'", ",", "' '", ",", "$", "sSlug", ")", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "aBucketData", "[", "'allowed_types'", "]", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "aBucketData", "[", "'allowed_types'", "]", ")", ")", "{", "$", "aBucketData", "[", "'allowed_types'", "]", "=", "(", "array", ")", "$", "aBucketData", "[", "'allowed_types'", "]", ";", "}", "$", "aBucketData", "[", "'allowed_types'", "]", "=", "array_filter", "(", "$", "aBucketData", "[", "'allowed_types'", "]", ")", ";", "$", "aBucketData", "[", "'allowed_types'", "]", "=", "array_unique", "(", "$", "aBucketData", "[", "'allowed_types'", "]", ")", ";", "$", "aBucketData", "[", "'allowed_types'", "]", "=", "implode", "(", "'|'", ",", "$", "aBucketData", "[", "'allowed_types'", "]", ")", ";", "}", "$", "iBucketId", "=", "$", "oBucketModel", "->", "create", "(", "$", "aBucketData", ")", ";", "if", "(", "$", "iBucketId", ")", "{", "return", "$", "iBucketId", ";", "}", "else", "{", "$", "this", "->", "callDriver", "(", "'destroy'", ",", "[", "$", "sSlug", "]", ")", ";", "$", "this", "->", "setError", "(", "'Failed to create bucket record'", ")", ";", "return", "false", ";", "}", "}", "else", "{", "$", "this", "->", "setError", "(", "$", "this", "->", "callDriver", "(", "'lastError'", ")", ")", ";", "return", "false", ";", "}", "}" ]
Create a new bucket @param string $sSlug The slug to give the bucket @param string $sLabel The label to give the bucket @param array $aAllowedTypes An array of file types the bucket will accept @return boolean
[ "Create", "a", "new", "bucket" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L1821-L1877
34,604
nails/module-cdn
src/Service/Cdn.php
Cdn.bucketList
public function bucketList($bucket, $filter_tag = null, $sort_on = null, $sort_order = null) { $data = []; $oDb = Factory::service('Database'); // -------------------------------------------------------------------------- // Sorting? if ($sort_on) { $_sort_order = strtoupper($sort_order) == 'ASC' ? 'ASC' : 'DESC'; switch ($sort_on) { case 'filename': $oDb->order_by('o.filename_display', $_sort_order); break; case 'filesize': $oDb->order_by('o.filesize', $_sort_order); break; case 'created': $oDb->order_by('o.created', $_sort_order); break; case 'type': case 'mime': $oDb->order_by('o.mime', $_sort_order); break; } } // -------------------------------------------------------------------------- // Filter by bucket if (is_numeric($bucket)) { $oDb->where('b.id', $bucket); } else { $oDb->where('b.slug', $bucket); } return $this->getObjects(null, null, $data); }
php
public function bucketList($bucket, $filter_tag = null, $sort_on = null, $sort_order = null) { $data = []; $oDb = Factory::service('Database'); // -------------------------------------------------------------------------- // Sorting? if ($sort_on) { $_sort_order = strtoupper($sort_order) == 'ASC' ? 'ASC' : 'DESC'; switch ($sort_on) { case 'filename': $oDb->order_by('o.filename_display', $_sort_order); break; case 'filesize': $oDb->order_by('o.filesize', $_sort_order); break; case 'created': $oDb->order_by('o.created', $_sort_order); break; case 'type': case 'mime': $oDb->order_by('o.mime', $_sort_order); break; } } // -------------------------------------------------------------------------- // Filter by bucket if (is_numeric($bucket)) { $oDb->where('b.id', $bucket); } else { $oDb->where('b.slug', $bucket); } return $this->getObjects(null, null, $data); }
[ "public", "function", "bucketList", "(", "$", "bucket", ",", "$", "filter_tag", "=", "null", ",", "$", "sort_on", "=", "null", ",", "$", "sort_order", "=", "null", ")", "{", "$", "data", "=", "[", "]", ";", "$", "oDb", "=", "Factory", "::", "service", "(", "'Database'", ")", ";", "// --------------------------------------------------------------------------", "// Sorting?", "if", "(", "$", "sort_on", ")", "{", "$", "_sort_order", "=", "strtoupper", "(", "$", "sort_order", ")", "==", "'ASC'", "?", "'ASC'", ":", "'DESC'", ";", "switch", "(", "$", "sort_on", ")", "{", "case", "'filename'", ":", "$", "oDb", "->", "order_by", "(", "'o.filename_display'", ",", "$", "_sort_order", ")", ";", "break", ";", "case", "'filesize'", ":", "$", "oDb", "->", "order_by", "(", "'o.filesize'", ",", "$", "_sort_order", ")", ";", "break", ";", "case", "'created'", ":", "$", "oDb", "->", "order_by", "(", "'o.created'", ",", "$", "_sort_order", ")", ";", "break", ";", "case", "'type'", ":", "case", "'mime'", ":", "$", "oDb", "->", "order_by", "(", "'o.mime'", ",", "$", "_sort_order", ")", ";", "break", ";", "}", "}", "// --------------------------------------------------------------------------", "// Filter by bucket", "if", "(", "is_numeric", "(", "$", "bucket", ")", ")", "{", "$", "oDb", "->", "where", "(", "'b.id'", ",", "$", "bucket", ")", ";", "}", "else", "{", "$", "oDb", "->", "where", "(", "'b.slug'", ",", "$", "bucket", ")", ";", "}", "return", "$", "this", "->", "getObjects", "(", "null", ",", "null", ",", "$", "data", ")", ";", "}" ]
Lists the contents of a bucket @param int|string $bucket The bucket's ID or slug @param null $filter_tag @param null $sort_on @param null $sort_order @return array
[ "Lists", "the", "contents", "of", "a", "bucket" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L1891-L1933
34,605
nails/module-cdn
src/Service/Cdn.php
Cdn.bucketDestroy
public function bucketDestroy($bucket) { $oBucket = $this->getBucket($bucket); if (!$oBucket) { $this->setError('Not a valid bucket'); return false; } // -------------------------------------------------------------------------- // Destroy any containing objects $errors = 0; foreach ($oBucket->objects as $obj) { if (!$this->objectDestroy($obj->id)) { $this->setError('Unable to delete object "' . $obj->file->name->human . '" (ID:' . $obj->id . ').'); $errors++; } } if ($errors) { $this->setError('Unable to delete bucket, bucket not empty.'); return false; } else { if ($this->callDriver('bucketDestroy', [$oBucket->slug])) { $oDb = Factory::service('Database'); $oDb->where('id', $oBucket->id); $oDb->delete(NAILS_DB_PREFIX . 'cdn_bucket'); return true; } else { $this->setError('Unable to remove empty bucket directory. ' . $this->callDriver('lastError')); return false; } } }
php
public function bucketDestroy($bucket) { $oBucket = $this->getBucket($bucket); if (!$oBucket) { $this->setError('Not a valid bucket'); return false; } // -------------------------------------------------------------------------- // Destroy any containing objects $errors = 0; foreach ($oBucket->objects as $obj) { if (!$this->objectDestroy($obj->id)) { $this->setError('Unable to delete object "' . $obj->file->name->human . '" (ID:' . $obj->id . ').'); $errors++; } } if ($errors) { $this->setError('Unable to delete bucket, bucket not empty.'); return false; } else { if ($this->callDriver('bucketDestroy', [$oBucket->slug])) { $oDb = Factory::service('Database'); $oDb->where('id', $oBucket->id); $oDb->delete(NAILS_DB_PREFIX . 'cdn_bucket'); return true; } else { $this->setError('Unable to remove empty bucket directory. ' . $this->callDriver('lastError')); return false; } } }
[ "public", "function", "bucketDestroy", "(", "$", "bucket", ")", "{", "$", "oBucket", "=", "$", "this", "->", "getBucket", "(", "$", "bucket", ")", ";", "if", "(", "!", "$", "oBucket", ")", "{", "$", "this", "->", "setError", "(", "'Not a valid bucket'", ")", ";", "return", "false", ";", "}", "// --------------------------------------------------------------------------", "// Destroy any containing objects", "$", "errors", "=", "0", ";", "foreach", "(", "$", "oBucket", "->", "objects", "as", "$", "obj", ")", "{", "if", "(", "!", "$", "this", "->", "objectDestroy", "(", "$", "obj", "->", "id", ")", ")", "{", "$", "this", "->", "setError", "(", "'Unable to delete object \"'", ".", "$", "obj", "->", "file", "->", "name", "->", "human", ".", "'\" (ID:'", ".", "$", "obj", "->", "id", ".", "').'", ")", ";", "$", "errors", "++", ";", "}", "}", "if", "(", "$", "errors", ")", "{", "$", "this", "->", "setError", "(", "'Unable to delete bucket, bucket not empty.'", ")", ";", "return", "false", ";", "}", "else", "{", "if", "(", "$", "this", "->", "callDriver", "(", "'bucketDestroy'", ",", "[", "$", "oBucket", "->", "slug", "]", ")", ")", "{", "$", "oDb", "=", "Factory", "::", "service", "(", "'Database'", ")", ";", "$", "oDb", "->", "where", "(", "'id'", ",", "$", "oBucket", "->", "id", ")", ";", "$", "oDb", "->", "delete", "(", "NAILS_DB_PREFIX", ".", "'cdn_bucket'", ")", ";", "return", "true", ";", "}", "else", "{", "$", "this", "->", "setError", "(", "'Unable to remove empty bucket directory. '", ".", "$", "this", "->", "callDriver", "(", "'lastError'", ")", ")", ";", "return", "false", ";", "}", "}", "}" ]
Permanently delete a bucket and its contents @param string @return boolean
[ "Permanently", "delete", "a", "bucket", "and", "its", "contents" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L1944-L1984
34,606
nails/module-cdn
src/Service/Cdn.php
Cdn.formatBucket
protected function formatBucket(&$bucket) { $bucket->id = (int) $bucket->id; $bucket->max_size = (int) $bucket->max_size; $bucket->modified_by = (int) $bucket->modified_by ?: null; // -------------------------------------------------------------------------- if (!empty($bucket->allowed_types)) { if (strpos($bucket->allowed_types, '|') !== false) { $aAllowedTypes = explode('|', $bucket->allowed_types); } else { $aAllowedTypes = explode(',', $bucket->allowed_types); } } else { $aAllowedTypes = $this->aDefaultAllowedTypes; } $aAllowedTypes = array_map( function ($sExt) { return preg_replace('/^\./', '', trim($sExt)); }, $aAllowedTypes ); $aAllowedTypes = array_map([$this, 'sanitiseExtension'], $aAllowedTypes); $aAllowedTypes = array_unique($aAllowedTypes); $aAllowedTypes = array_values($aAllowedTypes); $bucket->allowed_types = $aAllowedTypes; if (isset($bucket->objectCount)) { $bucket->objectCount = (int) $bucket->objectCount; } }
php
protected function formatBucket(&$bucket) { $bucket->id = (int) $bucket->id; $bucket->max_size = (int) $bucket->max_size; $bucket->modified_by = (int) $bucket->modified_by ?: null; // -------------------------------------------------------------------------- if (!empty($bucket->allowed_types)) { if (strpos($bucket->allowed_types, '|') !== false) { $aAllowedTypes = explode('|', $bucket->allowed_types); } else { $aAllowedTypes = explode(',', $bucket->allowed_types); } } else { $aAllowedTypes = $this->aDefaultAllowedTypes; } $aAllowedTypes = array_map( function ($sExt) { return preg_replace('/^\./', '', trim($sExt)); }, $aAllowedTypes ); $aAllowedTypes = array_map([$this, 'sanitiseExtension'], $aAllowedTypes); $aAllowedTypes = array_unique($aAllowedTypes); $aAllowedTypes = array_values($aAllowedTypes); $bucket->allowed_types = $aAllowedTypes; if (isset($bucket->objectCount)) { $bucket->objectCount = (int) $bucket->objectCount; } }
[ "protected", "function", "formatBucket", "(", "&", "$", "bucket", ")", "{", "$", "bucket", "->", "id", "=", "(", "int", ")", "$", "bucket", "->", "id", ";", "$", "bucket", "->", "max_size", "=", "(", "int", ")", "$", "bucket", "->", "max_size", ";", "$", "bucket", "->", "modified_by", "=", "(", "int", ")", "$", "bucket", "->", "modified_by", "?", ":", "null", ";", "// --------------------------------------------------------------------------", "if", "(", "!", "empty", "(", "$", "bucket", "->", "allowed_types", ")", ")", "{", "if", "(", "strpos", "(", "$", "bucket", "->", "allowed_types", ",", "'|'", ")", "!==", "false", ")", "{", "$", "aAllowedTypes", "=", "explode", "(", "'|'", ",", "$", "bucket", "->", "allowed_types", ")", ";", "}", "else", "{", "$", "aAllowedTypes", "=", "explode", "(", "','", ",", "$", "bucket", "->", "allowed_types", ")", ";", "}", "}", "else", "{", "$", "aAllowedTypes", "=", "$", "this", "->", "aDefaultAllowedTypes", ";", "}", "$", "aAllowedTypes", "=", "array_map", "(", "function", "(", "$", "sExt", ")", "{", "return", "preg_replace", "(", "'/^\\./'", ",", "''", ",", "trim", "(", "$", "sExt", ")", ")", ";", "}", ",", "$", "aAllowedTypes", ")", ";", "$", "aAllowedTypes", "=", "array_map", "(", "[", "$", "this", ",", "'sanitiseExtension'", "]", ",", "$", "aAllowedTypes", ")", ";", "$", "aAllowedTypes", "=", "array_unique", "(", "$", "aAllowedTypes", ")", ";", "$", "aAllowedTypes", "=", "array_values", "(", "$", "aAllowedTypes", ")", ";", "$", "bucket", "->", "allowed_types", "=", "$", "aAllowedTypes", ";", "if", "(", "isset", "(", "$", "bucket", "->", "objectCount", ")", ")", "{", "$", "bucket", "->", "objectCount", "=", "(", "int", ")", "$", "bucket", "->", "objectCount", ";", "}", "}" ]
Formats a bucket object @param object $bucket The bucket to format @return void
[ "Formats", "a", "bucket", "object" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L1995-L2029
34,607
nails/module-cdn
src/Service/Cdn.php
Cdn.getExtFromPath
public function getExtFromPath($sPath) { $sExtension = strpos($sPath, '.') !== false ? substr($sPath, (int) strrpos($sPath, '.') + 1) : $sPath; return $this->sanitiseExtension($sExtension); }
php
public function getExtFromPath($sPath) { $sExtension = strpos($sPath, '.') !== false ? substr($sPath, (int) strrpos($sPath, '.') + 1) : $sPath; return $this->sanitiseExtension($sExtension); }
[ "public", "function", "getExtFromPath", "(", "$", "sPath", ")", "{", "$", "sExtension", "=", "strpos", "(", "$", "sPath", ",", "'.'", ")", "!==", "false", "?", "substr", "(", "$", "sPath", ",", "(", "int", ")", "strrpos", "(", "$", "sPath", ",", "'.'", ")", "+", "1", ")", ":", "$", "sPath", ";", "return", "$", "this", "->", "sanitiseExtension", "(", "$", "sExtension", ")", ";", "}" ]
Extract the extension from a path @param string $sPath The path to extract from @return string
[ "Extract", "the", "extension", "from", "a", "path" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L2081-L2085
34,608
nails/module-cdn
src/Service/Cdn.php
Cdn.getMimeFromExt
public function getMimeFromExt($sExt) { $sExt = $this->sanitiseExtension($sExt); $aMimes = $this->oMimeService->getMimesForExtension($sExt); $sMime = reset($aMimes); return !empty($sMime) ? $sMime : 'application/octet-stream'; }
php
public function getMimeFromExt($sExt) { $sExt = $this->sanitiseExtension($sExt); $aMimes = $this->oMimeService->getMimesForExtension($sExt); $sMime = reset($aMimes); return !empty($sMime) ? $sMime : 'application/octet-stream'; }
[ "public", "function", "getMimeFromExt", "(", "$", "sExt", ")", "{", "$", "sExt", "=", "$", "this", "->", "sanitiseExtension", "(", "$", "sExt", ")", ";", "$", "aMimes", "=", "$", "this", "->", "oMimeService", "->", "getMimesForExtension", "(", "$", "sExt", ")", ";", "$", "sMime", "=", "reset", "(", "$", "aMimes", ")", ";", "return", "!", "empty", "(", "$", "sMime", ")", "?", "$", "sMime", ":", "'application/octet-stream'", ";", "}" ]
Gets the mime type from the extension @param string $sExt The extension to return the mime type for @return string
[ "Gets", "the", "mime", "type", "from", "the", "extension" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L2111-L2117
34,609
nails/module-cdn
src/Service/Cdn.php
Cdn.validExtForMime
public function validExtForMime($sExt, $sMime) { $sExt = $this->sanitiseExtension($sExt); return in_array($sExt, $this->oMimeService->getExtensionsForMime($sMime)); }
php
public function validExtForMime($sExt, $sMime) { $sExt = $this->sanitiseExtension($sExt); return in_array($sExt, $this->oMimeService->getExtensionsForMime($sMime)); }
[ "public", "function", "validExtForMime", "(", "$", "sExt", ",", "$", "sMime", ")", "{", "$", "sExt", "=", "$", "this", "->", "sanitiseExtension", "(", "$", "sExt", ")", ";", "return", "in_array", "(", "$", "sExt", ",", "$", "this", "->", "oMimeService", "->", "getExtensionsForMime", "(", "$", "sMime", ")", ")", ";", "}" ]
Determines whether an extension is valid for a specific mime typ @param string $sExt The extension to test, no leading period @param string $sMime The mime type to test against @return bool
[ "Determines", "whether", "an", "extension", "is", "valid", "for", "a", "specific", "mime", "typ" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L2143-L2147
34,610
nails/module-cdn
src/Service/Cdn.php
Cdn.getMimeMappings
protected function getMimeMappings() { $sCacheKey = 'mimes'; $aCache = $this->getCache($sCacheKey); if ($aCache) { return $aCache; } // -------------------------------------------------------------------------- // Try to work it out using Nail's mapping if (file_exists(NAILS_APP_PATH . 'application/config/mimes.php')) { require NAILS_APP_PATH . 'application/config/mimes.php'; } else { require NAILS_COMMON_PATH . 'config/mimes.php'; } // -------------------------------------------------------------------------- // Make sure we at least have an empty array if (!isset($mimes)) { $mimes = []; } // -------------------------------------------------------------------------- $this->setCache($sCacheKey, $mimes); // -------------------------------------------------------------------------- return $mimes; }
php
protected function getMimeMappings() { $sCacheKey = 'mimes'; $aCache = $this->getCache($sCacheKey); if ($aCache) { return $aCache; } // -------------------------------------------------------------------------- // Try to work it out using Nail's mapping if (file_exists(NAILS_APP_PATH . 'application/config/mimes.php')) { require NAILS_APP_PATH . 'application/config/mimes.php'; } else { require NAILS_COMMON_PATH . 'config/mimes.php'; } // -------------------------------------------------------------------------- // Make sure we at least have an empty array if (!isset($mimes)) { $mimes = []; } // -------------------------------------------------------------------------- $this->setCache($sCacheKey, $mimes); // -------------------------------------------------------------------------- return $mimes; }
[ "protected", "function", "getMimeMappings", "(", ")", "{", "$", "sCacheKey", "=", "'mimes'", ";", "$", "aCache", "=", "$", "this", "->", "getCache", "(", "$", "sCacheKey", ")", ";", "if", "(", "$", "aCache", ")", "{", "return", "$", "aCache", ";", "}", "// --------------------------------------------------------------------------", "// Try to work it out using Nail's mapping", "if", "(", "file_exists", "(", "NAILS_APP_PATH", ".", "'application/config/mimes.php'", ")", ")", "{", "require", "NAILS_APP_PATH", ".", "'application/config/mimes.php'", ";", "}", "else", "{", "require", "NAILS_COMMON_PATH", ".", "'config/mimes.php'", ";", "}", "// --------------------------------------------------------------------------", "// Make sure we at least have an empty array", "if", "(", "!", "isset", "(", "$", "mimes", ")", ")", "{", "$", "mimes", "=", "[", "]", ";", "}", "// --------------------------------------------------------------------------", "$", "this", "->", "setCache", "(", "$", "sCacheKey", ",", "$", "mimes", ")", ";", "// --------------------------------------------------------------------------", "return", "$", "mimes", ";", "}" ]
Returns an array of file extension to mime types @return array
[ "Returns", "an", "array", "of", "file", "extension", "to", "mime", "types" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L2156-L2188
34,611
nails/module-cdn
src/Service/Cdn.php
Cdn.urlServe
public function urlServe($objectId, $forceDownload = false) { $isTrashed = false; if (empty($objectId)) { $oObj = $this->emptyObject(); } elseif (is_numeric($objectId)) { $oObj = $this->getObject($objectId); if (!$oObj) { /** * If the user is a logged in admin with can_browse_trash permission then have a look in the trash */ if (userHasPermission('admin:cdn:trash:browse')) { $oObj = $this->getObjectFromTrash($objectId); if (!$oObj) { // Cool, guess it really doesn't exist. Let the renderer show a bad_src graphic $oObj = $this->emptyObject(); } else { $isTrashed = true; } } else { // Let the renderer show a bad_src graphic $oObj = $this->emptyObject(); } } } elseif (is_object($objectId)) { $oObj = $objectId; } else { throw new UrlException('Supplied $objectId must be numeric or an object', 1); } $url = $this->callDriver( 'urlServe', [$oObj->file->name->disk, $oObj->bucket->slug, $forceDownload], $oObj->driver ); $url .= $isTrashed ? '?trashed=1' : ''; return $url; }
php
public function urlServe($objectId, $forceDownload = false) { $isTrashed = false; if (empty($objectId)) { $oObj = $this->emptyObject(); } elseif (is_numeric($objectId)) { $oObj = $this->getObject($objectId); if (!$oObj) { /** * If the user is a logged in admin with can_browse_trash permission then have a look in the trash */ if (userHasPermission('admin:cdn:trash:browse')) { $oObj = $this->getObjectFromTrash($objectId); if (!$oObj) { // Cool, guess it really doesn't exist. Let the renderer show a bad_src graphic $oObj = $this->emptyObject(); } else { $isTrashed = true; } } else { // Let the renderer show a bad_src graphic $oObj = $this->emptyObject(); } } } elseif (is_object($objectId)) { $oObj = $objectId; } else { throw new UrlException('Supplied $objectId must be numeric or an object', 1); } $url = $this->callDriver( 'urlServe', [$oObj->file->name->disk, $oObj->bucket->slug, $forceDownload], $oObj->driver ); $url .= $isTrashed ? '?trashed=1' : ''; return $url; }
[ "public", "function", "urlServe", "(", "$", "objectId", ",", "$", "forceDownload", "=", "false", ")", "{", "$", "isTrashed", "=", "false", ";", "if", "(", "empty", "(", "$", "objectId", ")", ")", "{", "$", "oObj", "=", "$", "this", "->", "emptyObject", "(", ")", ";", "}", "elseif", "(", "is_numeric", "(", "$", "objectId", ")", ")", "{", "$", "oObj", "=", "$", "this", "->", "getObject", "(", "$", "objectId", ")", ";", "if", "(", "!", "$", "oObj", ")", "{", "/**\n * If the user is a logged in admin with can_browse_trash permission then have a look in the trash\n */", "if", "(", "userHasPermission", "(", "'admin:cdn:trash:browse'", ")", ")", "{", "$", "oObj", "=", "$", "this", "->", "getObjectFromTrash", "(", "$", "objectId", ")", ";", "if", "(", "!", "$", "oObj", ")", "{", "// Cool, guess it really doesn't exist. Let the renderer show a bad_src graphic", "$", "oObj", "=", "$", "this", "->", "emptyObject", "(", ")", ";", "}", "else", "{", "$", "isTrashed", "=", "true", ";", "}", "}", "else", "{", "// Let the renderer show a bad_src graphic", "$", "oObj", "=", "$", "this", "->", "emptyObject", "(", ")", ";", "}", "}", "}", "elseif", "(", "is_object", "(", "$", "objectId", ")", ")", "{", "$", "oObj", "=", "$", "objectId", ";", "}", "else", "{", "throw", "new", "UrlException", "(", "'Supplied $objectId must be numeric or an object'", ",", "1", ")", ";", "}", "$", "url", "=", "$", "this", "->", "callDriver", "(", "'urlServe'", ",", "[", "$", "oObj", "->", "file", "->", "name", "->", "disk", ",", "$", "oObj", "->", "bucket", "->", "slug", ",", "$", "forceDownload", "]", ",", "$", "oObj", "->", "driver", ")", ";", "$", "url", ".=", "$", "isTrashed", "?", "'?trashed=1'", ":", "''", ";", "return", "$", "url", ";", "}" ]
Calls the driver's public urlServe method @param int $objectId The ID of the object to serve @param bool $forceDownload Whether or not to force download of the object @return string @throws UrlException
[ "Calls", "the", "driver", "s", "public", "urlServe", "method" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L2203-L2246
34,612
nails/module-cdn
src/Service/Cdn.php
Cdn.urlServeRaw
public function urlServeRaw($iObjectId) { $bIsTrashed = false; if (empty($iObjectId)) { $oObj = $this->emptyObject(); } elseif (is_numeric($iObjectId)) { $oObj = $this->getObject($iObjectId); if (!$oObj) { /** * If the user is a logged in admin with can_browse_trash permission then have a look in the trash */ if (userHasPermission('admin:cdn:trash:browse')) { $oObj = $this->getObjectFromTrash($iObjectId); if (!$oObj) { // Cool, guess it really doesn't exist. Let the renderer show a bad_src graphic $oObj = $this->emptyObject(); } else { $bIsTrashed = true; } } else { // Let the renderer show a bad_src graphic $oObj = $this->emptyObject(); } } } elseif (is_object($iObjectId)) { $oObj = $iObjectId; } else { throw new UrlException('Supplied $iObjectId must be numeric or an object', 1); } $sUrl = $this->callDriver('urlServeRaw', [$oObj->file->name->disk, $oObj->bucket->slug], $oObj->driver); $sUrl .= $bIsTrashed ? '?trashed=1' : ''; return $sUrl; }
php
public function urlServeRaw($iObjectId) { $bIsTrashed = false; if (empty($iObjectId)) { $oObj = $this->emptyObject(); } elseif (is_numeric($iObjectId)) { $oObj = $this->getObject($iObjectId); if (!$oObj) { /** * If the user is a logged in admin with can_browse_trash permission then have a look in the trash */ if (userHasPermission('admin:cdn:trash:browse')) { $oObj = $this->getObjectFromTrash($iObjectId); if (!$oObj) { // Cool, guess it really doesn't exist. Let the renderer show a bad_src graphic $oObj = $this->emptyObject(); } else { $bIsTrashed = true; } } else { // Let the renderer show a bad_src graphic $oObj = $this->emptyObject(); } } } elseif (is_object($iObjectId)) { $oObj = $iObjectId; } else { throw new UrlException('Supplied $iObjectId must be numeric or an object', 1); } $sUrl = $this->callDriver('urlServeRaw', [$oObj->file->name->disk, $oObj->bucket->slug], $oObj->driver); $sUrl .= $bIsTrashed ? '?trashed=1' : ''; return $sUrl; }
[ "public", "function", "urlServeRaw", "(", "$", "iObjectId", ")", "{", "$", "bIsTrashed", "=", "false", ";", "if", "(", "empty", "(", "$", "iObjectId", ")", ")", "{", "$", "oObj", "=", "$", "this", "->", "emptyObject", "(", ")", ";", "}", "elseif", "(", "is_numeric", "(", "$", "iObjectId", ")", ")", "{", "$", "oObj", "=", "$", "this", "->", "getObject", "(", "$", "iObjectId", ")", ";", "if", "(", "!", "$", "oObj", ")", "{", "/**\n * If the user is a logged in admin with can_browse_trash permission then have a look in the trash\n */", "if", "(", "userHasPermission", "(", "'admin:cdn:trash:browse'", ")", ")", "{", "$", "oObj", "=", "$", "this", "->", "getObjectFromTrash", "(", "$", "iObjectId", ")", ";", "if", "(", "!", "$", "oObj", ")", "{", "// Cool, guess it really doesn't exist. Let the renderer show a bad_src graphic", "$", "oObj", "=", "$", "this", "->", "emptyObject", "(", ")", ";", "}", "else", "{", "$", "bIsTrashed", "=", "true", ";", "}", "}", "else", "{", "// Let the renderer show a bad_src graphic", "$", "oObj", "=", "$", "this", "->", "emptyObject", "(", ")", ";", "}", "}", "}", "elseif", "(", "is_object", "(", "$", "iObjectId", ")", ")", "{", "$", "oObj", "=", "$", "iObjectId", ";", "}", "else", "{", "throw", "new", "UrlException", "(", "'Supplied $iObjectId must be numeric or an object'", ",", "1", ")", ";", "}", "$", "sUrl", "=", "$", "this", "->", "callDriver", "(", "'urlServeRaw'", ",", "[", "$", "oObj", "->", "file", "->", "name", "->", "disk", ",", "$", "oObj", "->", "bucket", "->", "slug", "]", ",", "$", "oObj", "->", "driver", ")", ";", "$", "sUrl", ".=", "$", "bIsTrashed", "?", "'?trashed=1'", ":", "''", ";", "return", "$", "sUrl", ";", "}" ]
Returns the URL for serving raw content from the CDN driver's source and not running it through the main CDN @param integer $iObjectId The ID of the object to serve @return string @throws UrlException
[ "Returns", "the", "URL", "for", "serving", "raw", "content", "from", "the", "CDN", "driver", "s", "source", "and", "not", "running", "it", "through", "the", "main", "CDN" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L2258-L2297
34,613
nails/module-cdn
src/Service/Cdn.php
Cdn.urlServeZipped
public function urlServeZipped($objects, $filename = 'download.zip') { $_data = ['where_in' => [['o.id', $objects]]]; $_objects = $this->getObjects(null, null, $_data); $_ids = []; $_ids_hash = []; foreach ($_objects as $obj) { $_ids[] = $obj->id; $_ids_hash[] = $obj->id . $obj->bucket->id; } $_ids = implode('-', $_ids); $_ids_hash = implode('-', $_ids_hash); $_hash = md5(APP_PRIVATE_KEY . $_ids . $_ids_hash . $filename); return $this->callDriver('urlServeZipped', [$_ids, $_hash, $filename]); }
php
public function urlServeZipped($objects, $filename = 'download.zip') { $_data = ['where_in' => [['o.id', $objects]]]; $_objects = $this->getObjects(null, null, $_data); $_ids = []; $_ids_hash = []; foreach ($_objects as $obj) { $_ids[] = $obj->id; $_ids_hash[] = $obj->id . $obj->bucket->id; } $_ids = implode('-', $_ids); $_ids_hash = implode('-', $_ids_hash); $_hash = md5(APP_PRIVATE_KEY . $_ids . $_ids_hash . $filename); return $this->callDriver('urlServeZipped', [$_ids, $_hash, $filename]); }
[ "public", "function", "urlServeZipped", "(", "$", "objects", ",", "$", "filename", "=", "'download.zip'", ")", "{", "$", "_data", "=", "[", "'where_in'", "=>", "[", "[", "'o.id'", ",", "$", "objects", "]", "]", "]", ";", "$", "_objects", "=", "$", "this", "->", "getObjects", "(", "null", ",", "null", ",", "$", "_data", ")", ";", "$", "_ids", "=", "[", "]", ";", "$", "_ids_hash", "=", "[", "]", ";", "foreach", "(", "$", "_objects", "as", "$", "obj", ")", "{", "$", "_ids", "[", "]", "=", "$", "obj", "->", "id", ";", "$", "_ids_hash", "[", "]", "=", "$", "obj", "->", "id", ".", "$", "obj", "->", "bucket", "->", "id", ";", "}", "$", "_ids", "=", "implode", "(", "'-'", ",", "$", "_ids", ")", ";", "$", "_ids_hash", "=", "implode", "(", "'-'", ",", "$", "_ids_hash", ")", ";", "$", "_hash", "=", "md5", "(", "APP_PRIVATE_KEY", ".", "$", "_ids", ".", "$", "_ids_hash", ".", "$", "filename", ")", ";", "return", "$", "this", "->", "callDriver", "(", "'urlServeZipped'", ",", "[", "$", "_ids", ",", "$", "_hash", ",", "$", "filename", "]", ")", ";", "}" ]
Calls the driver's public urlServeZipped method @param array $objects The objects to include in the zip file @param string $filename The name to give the zip file @return string
[ "Calls", "the", "driver", "s", "public", "urlServeZipped", "method" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L2323-L2340
34,614
nails/module-cdn
src/Service/Cdn.php
Cdn.urlCrop
public function urlCrop($iObjectId, $iWidth, $iHeight) { if (!$this->isPermittedDimension($iWidth, $iHeight)) { throw new PermittedDimensionException( 'CDN::urlCrop() - Transformation of image to ' . $iWidth . 'x' . $iHeight . ' is not permitted' ); } // -------------------------------------------------------------------------- $isTrashed = false; if (empty($iObjectId)) { $oObj = $this->emptyObject(); } elseif (is_numeric($iObjectId)) { $oObj = $this->getObject($iObjectId); if (!$oObj) { /** * If the user is a logged in admin with can_browse_trash permission then have a look in the trash */ if (userHasPermission('admin:cdn:trash:browse')) { $oObj = $this->getObjectFromTrash($iObjectId); if (!$oObj) { // Cool, guess it really doesn't exist. Let the renderer show a bad_src graphic $oObj = $this->emptyObject(); } else { $isTrashed = true; } } else { // Let the renderer show a bad_src graphic $oObj = $this->emptyObject(); } } } else { $oObj = $iObjectId; } // -------------------------------------------------------------------------- $sCacheUrl = static::getCacheUrl( $oObj->bucket->slug, $oObj->file->name->disk, $oObj->file->ext, 'CROP', $oObj->img_orientation, $iWidth, $iHeight ); if (!empty($sCacheUrl)) { return $sCacheUrl; } // -------------------------------------------------------------------------- $sUrl = $this->callDriver( 'urlCrop', [$oObj->file->name->disk, $oObj->bucket->slug, $iWidth, $iHeight], $oObj->driver ); $sUrl .= $isTrashed ? '?trashed=1' : ''; return $sUrl; }
php
public function urlCrop($iObjectId, $iWidth, $iHeight) { if (!$this->isPermittedDimension($iWidth, $iHeight)) { throw new PermittedDimensionException( 'CDN::urlCrop() - Transformation of image to ' . $iWidth . 'x' . $iHeight . ' is not permitted' ); } // -------------------------------------------------------------------------- $isTrashed = false; if (empty($iObjectId)) { $oObj = $this->emptyObject(); } elseif (is_numeric($iObjectId)) { $oObj = $this->getObject($iObjectId); if (!$oObj) { /** * If the user is a logged in admin with can_browse_trash permission then have a look in the trash */ if (userHasPermission('admin:cdn:trash:browse')) { $oObj = $this->getObjectFromTrash($iObjectId); if (!$oObj) { // Cool, guess it really doesn't exist. Let the renderer show a bad_src graphic $oObj = $this->emptyObject(); } else { $isTrashed = true; } } else { // Let the renderer show a bad_src graphic $oObj = $this->emptyObject(); } } } else { $oObj = $iObjectId; } // -------------------------------------------------------------------------- $sCacheUrl = static::getCacheUrl( $oObj->bucket->slug, $oObj->file->name->disk, $oObj->file->ext, 'CROP', $oObj->img_orientation, $iWidth, $iHeight ); if (!empty($sCacheUrl)) { return $sCacheUrl; } // -------------------------------------------------------------------------- $sUrl = $this->callDriver( 'urlCrop', [$oObj->file->name->disk, $oObj->bucket->slug, $iWidth, $iHeight], $oObj->driver ); $sUrl .= $isTrashed ? '?trashed=1' : ''; return $sUrl; }
[ "public", "function", "urlCrop", "(", "$", "iObjectId", ",", "$", "iWidth", ",", "$", "iHeight", ")", "{", "if", "(", "!", "$", "this", "->", "isPermittedDimension", "(", "$", "iWidth", ",", "$", "iHeight", ")", ")", "{", "throw", "new", "PermittedDimensionException", "(", "'CDN::urlCrop() - Transformation of image to '", ".", "$", "iWidth", ".", "'x'", ".", "$", "iHeight", ".", "' is not permitted'", ")", ";", "}", "// --------------------------------------------------------------------------", "$", "isTrashed", "=", "false", ";", "if", "(", "empty", "(", "$", "iObjectId", ")", ")", "{", "$", "oObj", "=", "$", "this", "->", "emptyObject", "(", ")", ";", "}", "elseif", "(", "is_numeric", "(", "$", "iObjectId", ")", ")", "{", "$", "oObj", "=", "$", "this", "->", "getObject", "(", "$", "iObjectId", ")", ";", "if", "(", "!", "$", "oObj", ")", "{", "/**\n * If the user is a logged in admin with can_browse_trash permission then have a look in the trash\n */", "if", "(", "userHasPermission", "(", "'admin:cdn:trash:browse'", ")", ")", "{", "$", "oObj", "=", "$", "this", "->", "getObjectFromTrash", "(", "$", "iObjectId", ")", ";", "if", "(", "!", "$", "oObj", ")", "{", "// Cool, guess it really doesn't exist. Let the renderer show a bad_src graphic", "$", "oObj", "=", "$", "this", "->", "emptyObject", "(", ")", ";", "}", "else", "{", "$", "isTrashed", "=", "true", ";", "}", "}", "else", "{", "// Let the renderer show a bad_src graphic", "$", "oObj", "=", "$", "this", "->", "emptyObject", "(", ")", ";", "}", "}", "}", "else", "{", "$", "oObj", "=", "$", "iObjectId", ";", "}", "// --------------------------------------------------------------------------", "$", "sCacheUrl", "=", "static", "::", "getCacheUrl", "(", "$", "oObj", "->", "bucket", "->", "slug", ",", "$", "oObj", "->", "file", "->", "name", "->", "disk", ",", "$", "oObj", "->", "file", "->", "ext", ",", "'CROP'", ",", "$", "oObj", "->", "img_orientation", ",", "$", "iWidth", ",", "$", "iHeight", ")", ";", "if", "(", "!", "empty", "(", "$", "sCacheUrl", ")", ")", "{", "return", "$", "sCacheUrl", ";", "}", "// --------------------------------------------------------------------------", "$", "sUrl", "=", "$", "this", "->", "callDriver", "(", "'urlCrop'", ",", "[", "$", "oObj", "->", "file", "->", "name", "->", "disk", ",", "$", "oObj", "->", "bucket", "->", "slug", ",", "$", "iWidth", ",", "$", "iHeight", "]", ",", "$", "oObj", "->", "driver", ")", ";", "$", "sUrl", ".=", "$", "isTrashed", "?", "'?trashed=1'", ":", "''", ";", "return", "$", "sUrl", ";", "}" ]
Calls the driver's public urlCrop method @param int $iObjectId The ID of the object we're cropping @param int $iWidth The width of the crop @param int $iHeight The height of the crop @return string
[ "Calls", "the", "driver", "s", "public", "urlCrop", "method" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L2398-L2467
34,615
nails/module-cdn
src/Service/Cdn.php
Cdn.getCacheUrl
public static function getCacheUrl( $sBucket, $sObject, $sExtension, $sCropMethod, $sOrientation, $iWidth, $iHeight ) { // Is there a cached version of the file on disk we can serve up instead? // @todo (Pablo - 2018-03-13) - This won't be reliable in multi-server environments unless the cache is shared $sCachePath = static::getCachePath( $sBucket, $sObject, $sExtension, $sCropMethod, $sOrientation, $iWidth, $iHeight ); if (file_exists(static::CACHE_PATH . $sCachePath)) { return static::CACHE_URL . $sCachePath; } return null; }
php
public static function getCacheUrl( $sBucket, $sObject, $sExtension, $sCropMethod, $sOrientation, $iWidth, $iHeight ) { // Is there a cached version of the file on disk we can serve up instead? // @todo (Pablo - 2018-03-13) - This won't be reliable in multi-server environments unless the cache is shared $sCachePath = static::getCachePath( $sBucket, $sObject, $sExtension, $sCropMethod, $sOrientation, $iWidth, $iHeight ); if (file_exists(static::CACHE_PATH . $sCachePath)) { return static::CACHE_URL . $sCachePath; } return null; }
[ "public", "static", "function", "getCacheUrl", "(", "$", "sBucket", ",", "$", "sObject", ",", "$", "sExtension", ",", "$", "sCropMethod", ",", "$", "sOrientation", ",", "$", "iWidth", ",", "$", "iHeight", ")", "{", "// Is there a cached version of the file on disk we can serve up instead?", "// @todo (Pablo - 2018-03-13) - This won't be reliable in multi-server environments unless the cache is shared", "$", "sCachePath", "=", "static", "::", "getCachePath", "(", "$", "sBucket", ",", "$", "sObject", ",", "$", "sExtension", ",", "$", "sCropMethod", ",", "$", "sOrientation", ",", "$", "iWidth", ",", "$", "iHeight", ")", ";", "if", "(", "file_exists", "(", "static", "::", "CACHE_PATH", ".", "$", "sCachePath", ")", ")", "{", "return", "static", "::", "CACHE_URL", ".", "$", "sCachePath", ";", "}", "return", "null", ";", "}" ]
Checks the public cache for an image, and if it's there will return it's URL @param string $sBucket The bucket slug @param string $sObject The name on disk @param string $sExtension The file extension @param string $sCropMethod The crop method @param integer $iWidth The width @param integer $iHeight The height @return null|string
[ "Checks", "the", "public", "cache", "for", "an", "image", "and", "if", "it", "s", "there", "will", "return", "it", "s", "URL" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L2598-L2624
34,616
nails/module-cdn
src/Service/Cdn.php
Cdn.getCachePath
public static function getCachePath( $sBucket, $sObject, $sExtension, $sCropMethod, $sOrientation, $iWidth, $iHeight ) { $sCropQuadrant = static::getCropQuadrant($sOrientation); return implode( '-', array_filter([ $sBucket, substr($sObject, 0, strrpos($sObject, '.')), strtoupper($sCropMethod), $iWidth . 'x' . $iHeight, $sCropQuadrant !== 'C' ? $sCropQuadrant : '', ]) ) . '.' . trim($sExtension, '.'); }
php
public static function getCachePath( $sBucket, $sObject, $sExtension, $sCropMethod, $sOrientation, $iWidth, $iHeight ) { $sCropQuadrant = static::getCropQuadrant($sOrientation); return implode( '-', array_filter([ $sBucket, substr($sObject, 0, strrpos($sObject, '.')), strtoupper($sCropMethod), $iWidth . 'x' . $iHeight, $sCropQuadrant !== 'C' ? $sCropQuadrant : '', ]) ) . '.' . trim($sExtension, '.'); }
[ "public", "static", "function", "getCachePath", "(", "$", "sBucket", ",", "$", "sObject", ",", "$", "sExtension", ",", "$", "sCropMethod", ",", "$", "sOrientation", ",", "$", "iWidth", ",", "$", "iHeight", ")", "{", "$", "sCropQuadrant", "=", "static", "::", "getCropQuadrant", "(", "$", "sOrientation", ")", ";", "return", "implode", "(", "'-'", ",", "array_filter", "(", "[", "$", "sBucket", ",", "substr", "(", "$", "sObject", ",", "0", ",", "strrpos", "(", "$", "sObject", ",", "'.'", ")", ")", ",", "strtoupper", "(", "$", "sCropMethod", ")", ",", "$", "iWidth", ".", "'x'", ".", "$", "iHeight", ",", "$", "sCropQuadrant", "!==", "'C'", "?", "$", "sCropQuadrant", ":", "''", ",", "]", ")", ")", ".", "'.'", ".", "trim", "(", "$", "sExtension", ",", "'.'", ")", ";", "}" ]
Generate the name of the cache file for the image @param string $sBucket The bucket slug @param string $sObject The name on disk @param string $sExtension The file extension @param string $sCropMethod The crop method @param integer $iWidth The width @param integer $iHeight The height @return string
[ "Generate", "the", "name", "of", "the", "cache", "file", "for", "the", "image" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L2640-L2660
34,617
nails/module-cdn
src/Service/Cdn.php
Cdn.getCropQuadrant
public static function getCropQuadrant($sOrientation) { switch ($sOrientation) { case 'PORTRAIT': $sCropQuadrant = defined('APP_CDN_CROP_QUADRANT_PORTRAIT') ? APP_CDN_CROP_QUADRANT_PORTRAIT : 'C'; break; case 'LANDSCAPE': $sCropQuadrant = defined('APP_CDN_CROP_QUADRANT_LANDSCAPE') ? APP_CDN_CROP_QUADRANT_LANDSCAPE : 'C'; break; default: $sCropQuadrant = 'C'; break; } return strtoupper($sCropQuadrant); }
php
public static function getCropQuadrant($sOrientation) { switch ($sOrientation) { case 'PORTRAIT': $sCropQuadrant = defined('APP_CDN_CROP_QUADRANT_PORTRAIT') ? APP_CDN_CROP_QUADRANT_PORTRAIT : 'C'; break; case 'LANDSCAPE': $sCropQuadrant = defined('APP_CDN_CROP_QUADRANT_LANDSCAPE') ? APP_CDN_CROP_QUADRANT_LANDSCAPE : 'C'; break; default: $sCropQuadrant = 'C'; break; } return strtoupper($sCropQuadrant); }
[ "public", "static", "function", "getCropQuadrant", "(", "$", "sOrientation", ")", "{", "switch", "(", "$", "sOrientation", ")", "{", "case", "'PORTRAIT'", ":", "$", "sCropQuadrant", "=", "defined", "(", "'APP_CDN_CROP_QUADRANT_PORTRAIT'", ")", "?", "APP_CDN_CROP_QUADRANT_PORTRAIT", ":", "'C'", ";", "break", ";", "case", "'LANDSCAPE'", ":", "$", "sCropQuadrant", "=", "defined", "(", "'APP_CDN_CROP_QUADRANT_LANDSCAPE'", ")", "?", "APP_CDN_CROP_QUADRANT_LANDSCAPE", ":", "'C'", ";", "break", ";", "default", ":", "$", "sCropQuadrant", "=", "'C'", ";", "break", ";", "}", "return", "strtoupper", "(", "$", "sCropQuadrant", ")", ";", "}" ]
Returns the crop quadrant being used for the orientation @param string $sOrientation The image's orientation @return string
[ "Returns", "the", "crop", "quadrant", "being", "used", "for", "the", "orientation" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L2671-L2688
34,618
nails/module-cdn
src/Service/Cdn.php
Cdn.urlPlaceholder
public function urlPlaceholder($iWidth = 100, $iHeight = 100, $border = 0) { if (!$this->isPermittedDimension($iWidth, $iHeight)) { throw new PermittedDimensionException( 'CDN::urlPlaceholder() - Transformation of image to ' . $iWidth . 'x' . $iHeight . ' is not permitted' ); } // -------------------------------------------------------------------------- return $this->callDriver('urlPlaceholder', [$iWidth, $iHeight, $border]); }
php
public function urlPlaceholder($iWidth = 100, $iHeight = 100, $border = 0) { if (!$this->isPermittedDimension($iWidth, $iHeight)) { throw new PermittedDimensionException( 'CDN::urlPlaceholder() - Transformation of image to ' . $iWidth . 'x' . $iHeight . ' is not permitted' ); } // -------------------------------------------------------------------------- return $this->callDriver('urlPlaceholder', [$iWidth, $iHeight, $border]); }
[ "public", "function", "urlPlaceholder", "(", "$", "iWidth", "=", "100", ",", "$", "iHeight", "=", "100", ",", "$", "border", "=", "0", ")", "{", "if", "(", "!", "$", "this", "->", "isPermittedDimension", "(", "$", "iWidth", ",", "$", "iHeight", ")", ")", "{", "throw", "new", "PermittedDimensionException", "(", "'CDN::urlPlaceholder() - Transformation of image to '", ".", "$", "iWidth", ".", "'x'", ".", "$", "iHeight", ".", "' is not permitted'", ")", ";", "}", "// --------------------------------------------------------------------------", "return", "$", "this", "->", "callDriver", "(", "'urlPlaceholder'", ",", "[", "$", "iWidth", ",", "$", "iHeight", ",", "$", "border", "]", ")", ";", "}" ]
Calls the driver's public urlPlaceholder method @param int $iWidth The width of the placeholder @param int $iHeight The height of the placeholder @param int $border The width of the border round the placeholder @return string
[ "Calls", "the", "driver", "s", "public", "urlPlaceholder", "method" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L2701-L2712
34,619
nails/module-cdn
src/Service/Cdn.php
Cdn.urlBlankAvatar
public function urlBlankAvatar($iWidth = 100, $iHeight = 100, $sex = '') { if (!$this->isPermittedDimension($iWidth, $iHeight)) { throw new PermittedDimensionException( 'CDN::urlBlankAvatar() - Transformation of image to ' . $iWidth . 'x' . $iHeight . ' is not permitted' ); } // -------------------------------------------------------------------------- return $this->callDriver('urlBlankAvatar', [$iWidth, $iHeight, $sex]); }
php
public function urlBlankAvatar($iWidth = 100, $iHeight = 100, $sex = '') { if (!$this->isPermittedDimension($iWidth, $iHeight)) { throw new PermittedDimensionException( 'CDN::urlBlankAvatar() - Transformation of image to ' . $iWidth . 'x' . $iHeight . ' is not permitted' ); } // -------------------------------------------------------------------------- return $this->callDriver('urlBlankAvatar', [$iWidth, $iHeight, $sex]); }
[ "public", "function", "urlBlankAvatar", "(", "$", "iWidth", "=", "100", ",", "$", "iHeight", "=", "100", ",", "$", "sex", "=", "''", ")", "{", "if", "(", "!", "$", "this", "->", "isPermittedDimension", "(", "$", "iWidth", ",", "$", "iHeight", ")", ")", "{", "throw", "new", "PermittedDimensionException", "(", "'CDN::urlBlankAvatar() - Transformation of image to '", ".", "$", "iWidth", ".", "'x'", ".", "$", "iHeight", ".", "' is not permitted'", ")", ";", "}", "// --------------------------------------------------------------------------", "return", "$", "this", "->", "callDriver", "(", "'urlBlankAvatar'", ",", "[", "$", "iWidth", ",", "$", "iHeight", ",", "$", "sex", "]", ")", ";", "}" ]
Calls the driver's public urlBlankAvatar method @param int $iWidth The width of the placeholder @param int $iHeight The height of the placeholder @param mixed $sex The gender of the blank avatar to show @return string
[ "Calls", "the", "driver", "s", "public", "urlBlankAvatar", "method" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L2739-L2750
34,620
nails/module-cdn
src/Service/Cdn.php
Cdn.urlAvatar
public function urlAvatar($iUserId = null, $iWidth = 100, $iHeight = 100) { if (is_null($iUserId)) { $iUserId = activeUser('id'); } if (empty($iUserId)) { $avatarUrl = $this->urlBlankAvatar($iWidth, $iHeight); } else { $oUserModel = Factory::model('User', 'nails/module-auth'); $user = $oUserModel->getById($iUserId); if (empty($user)) { $avatarUrl = $this->urlBlankAvatar($iWidth, $iHeight); } elseif (empty($user->profile_img)) { $avatarUrl = $this->urlBlankAvatar($iWidth, $iHeight, $user->gender); } else { $avatarUrl = $this->urlCrop($user->profile_img, $iWidth, $iHeight); } } return $avatarUrl; }
php
public function urlAvatar($iUserId = null, $iWidth = 100, $iHeight = 100) { if (is_null($iUserId)) { $iUserId = activeUser('id'); } if (empty($iUserId)) { $avatarUrl = $this->urlBlankAvatar($iWidth, $iHeight); } else { $oUserModel = Factory::model('User', 'nails/module-auth'); $user = $oUserModel->getById($iUserId); if (empty($user)) { $avatarUrl = $this->urlBlankAvatar($iWidth, $iHeight); } elseif (empty($user->profile_img)) { $avatarUrl = $this->urlBlankAvatar($iWidth, $iHeight, $user->gender); } else { $avatarUrl = $this->urlCrop($user->profile_img, $iWidth, $iHeight); } } return $avatarUrl; }
[ "public", "function", "urlAvatar", "(", "$", "iUserId", "=", "null", ",", "$", "iWidth", "=", "100", ",", "$", "iHeight", "=", "100", ")", "{", "if", "(", "is_null", "(", "$", "iUserId", ")", ")", "{", "$", "iUserId", "=", "activeUser", "(", "'id'", ")", ";", "}", "if", "(", "empty", "(", "$", "iUserId", ")", ")", "{", "$", "avatarUrl", "=", "$", "this", "->", "urlBlankAvatar", "(", "$", "iWidth", ",", "$", "iHeight", ")", ";", "}", "else", "{", "$", "oUserModel", "=", "Factory", "::", "model", "(", "'User'", ",", "'nails/module-auth'", ")", ";", "$", "user", "=", "$", "oUserModel", "->", "getById", "(", "$", "iUserId", ")", ";", "if", "(", "empty", "(", "$", "user", ")", ")", "{", "$", "avatarUrl", "=", "$", "this", "->", "urlBlankAvatar", "(", "$", "iWidth", ",", "$", "iHeight", ")", ";", "}", "elseif", "(", "empty", "(", "$", "user", "->", "profile_img", ")", ")", "{", "$", "avatarUrl", "=", "$", "this", "->", "urlBlankAvatar", "(", "$", "iWidth", ",", "$", "iHeight", ",", "$", "user", "->", "gender", ")", ";", "}", "else", "{", "$", "avatarUrl", "=", "$", "this", "->", "urlCrop", "(", "$", "user", "->", "profile_img", ",", "$", "iWidth", ",", "$", "iHeight", ")", ";", "}", "}", "return", "$", "avatarUrl", ";", "}" ]
Returns the appropriate avatar for a user @param int $iUserId The user's ID @param int $iWidth The width of the avatar @param int $iHeight The height of the avatar @return string
[ "Returns", "the", "appropriate", "avatar", "for", "a", "user" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L2777-L2798
34,621
nails/module-cdn
src/Service/Cdn.php
Cdn.urlAvatarScheme
public function urlAvatarScheme($iUserId = null) { if (is_null($iUserId)) { $iUserId = activeUser('id'); } if (empty($iUserId)) { $avatarScheme = $this->urlBlankAvatarScheme(); } else { $oUserModel = Factory::model('User', 'nails/module-auth'); $user = $oUserModel->getById($iUserId); if (empty($user->profile_img)) { $avatarScheme = $this->urlBlankAvatarScheme(); } else { $avatarScheme = $this->urlCropScheme(); } } return $avatarScheme; }
php
public function urlAvatarScheme($iUserId = null) { if (is_null($iUserId)) { $iUserId = activeUser('id'); } if (empty($iUserId)) { $avatarScheme = $this->urlBlankAvatarScheme(); } else { $oUserModel = Factory::model('User', 'nails/module-auth'); $user = $oUserModel->getById($iUserId); if (empty($user->profile_img)) { $avatarScheme = $this->urlBlankAvatarScheme(); } else { $avatarScheme = $this->urlCropScheme(); } } return $avatarScheme; }
[ "public", "function", "urlAvatarScheme", "(", "$", "iUserId", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "iUserId", ")", ")", "{", "$", "iUserId", "=", "activeUser", "(", "'id'", ")", ";", "}", "if", "(", "empty", "(", "$", "iUserId", ")", ")", "{", "$", "avatarScheme", "=", "$", "this", "->", "urlBlankAvatarScheme", "(", ")", ";", "}", "else", "{", "$", "oUserModel", "=", "Factory", "::", "model", "(", "'User'", ",", "'nails/module-auth'", ")", ";", "$", "user", "=", "$", "oUserModel", "->", "getById", "(", "$", "iUserId", ")", ";", "if", "(", "empty", "(", "$", "user", "->", "profile_img", ")", ")", "{", "$", "avatarScheme", "=", "$", "this", "->", "urlBlankAvatarScheme", "(", ")", ";", "}", "else", "{", "$", "avatarScheme", "=", "$", "this", "->", "urlCropScheme", "(", ")", ";", "}", "}", "return", "$", "avatarScheme", ";", "}" ]
Determines which scheme to use for a user's avatar and returns the appropriate one @param integer $iUserId The User ID to check @return string
[ "Determines", "which", "scheme", "to", "use", "for", "a", "user", "s", "avatar", "and", "returns", "the", "appropriate", "one" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L2809-L2828
34,622
nails/module-cdn
src/Service/Cdn.php
Cdn.urlExpiring
public function urlExpiring($iObjectId, $expires, $forceDownload = false) { if (is_numeric($iObjectId)) { $oObj = $this->getObject($iObjectId); if (!$oObj) { // Let the renderer show a bad_src graphic $oObj = (object) [ 'file' => (object) [ 'name' => (object) [ 'disk' => '', ], ], 'bucket' => (object) [ 'slug' => '', ], ]; } } else { $oObj = $iObjectId; } return $this->callDriver( 'urlExpiring', [$oObj->file->name->disk, $oObj->bucket->slug, $expires, $forceDownload], $oObj->driver ); }
php
public function urlExpiring($iObjectId, $expires, $forceDownload = false) { if (is_numeric($iObjectId)) { $oObj = $this->getObject($iObjectId); if (!$oObj) { // Let the renderer show a bad_src graphic $oObj = (object) [ 'file' => (object) [ 'name' => (object) [ 'disk' => '', ], ], 'bucket' => (object) [ 'slug' => '', ], ]; } } else { $oObj = $iObjectId; } return $this->callDriver( 'urlExpiring', [$oObj->file->name->disk, $oObj->bucket->slug, $expires, $forceDownload], $oObj->driver ); }
[ "public", "function", "urlExpiring", "(", "$", "iObjectId", ",", "$", "expires", ",", "$", "forceDownload", "=", "false", ")", "{", "if", "(", "is_numeric", "(", "$", "iObjectId", ")", ")", "{", "$", "oObj", "=", "$", "this", "->", "getObject", "(", "$", "iObjectId", ")", ";", "if", "(", "!", "$", "oObj", ")", "{", "// Let the renderer show a bad_src graphic", "$", "oObj", "=", "(", "object", ")", "[", "'file'", "=>", "(", "object", ")", "[", "'name'", "=>", "(", "object", ")", "[", "'disk'", "=>", "''", ",", "]", ",", "]", ",", "'bucket'", "=>", "(", "object", ")", "[", "'slug'", "=>", "''", ",", "]", ",", "]", ";", "}", "}", "else", "{", "$", "oObj", "=", "$", "iObjectId", ";", "}", "return", "$", "this", "->", "callDriver", "(", "'urlExpiring'", ",", "[", "$", "oObj", "->", "file", "->", "name", "->", "disk", ",", "$", "oObj", "->", "bucket", "->", "slug", ",", "$", "expires", ",", "$", "forceDownload", "]", ",", "$", "oObj", "->", "driver", ")", ";", "}" ]
Generates an expiring URL for an object @param integer $iObjectId The object's ID @param integer $expires The length of time the URL should be valid for, in seconds @param boolean $forceDownload Whether to force the download or not @return string
[ "Generates", "an", "expiring", "URL", "for", "an", "object" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L2841-L2870
34,623
nails/module-cdn
src/Service/Cdn.php
Cdn.findOrphanedObjects
public function findOrphanedObjects() { $aOut = ['orphans' => [], 'elapsed_time' => 0]; $oDb = Factory::service('Database'); $oDb->select('o.id, o.filename, o.filename_display, o.mime, o.filesize, o.driver'); $oDb->select('b.slug bucket_slug, b.label bucket'); $oDb->join(NAILS_DB_PREFIX . 'cdn_bucket b', 'o.bucket_id = b.id'); $oDb->order_by('b.label'); $oDb->order_by('o.filename_display'); $oQuery = $oDb->get(NAILS_DB_PREFIX . 'cdn_object o'); while ($oRow = $oQuery->unbuffered_row()) { if (!$this->callDriver('objectExists', [$oRow->filename, $oRow->bucket_slug])) { $aOut['orphans'][] = $oRow; } } return $aOut; }
php
public function findOrphanedObjects() { $aOut = ['orphans' => [], 'elapsed_time' => 0]; $oDb = Factory::service('Database'); $oDb->select('o.id, o.filename, o.filename_display, o.mime, o.filesize, o.driver'); $oDb->select('b.slug bucket_slug, b.label bucket'); $oDb->join(NAILS_DB_PREFIX . 'cdn_bucket b', 'o.bucket_id = b.id'); $oDb->order_by('b.label'); $oDb->order_by('o.filename_display'); $oQuery = $oDb->get(NAILS_DB_PREFIX . 'cdn_object o'); while ($oRow = $oQuery->unbuffered_row()) { if (!$this->callDriver('objectExists', [$oRow->filename, $oRow->bucket_slug])) { $aOut['orphans'][] = $oRow; } } return $aOut; }
[ "public", "function", "findOrphanedObjects", "(", ")", "{", "$", "aOut", "=", "[", "'orphans'", "=>", "[", "]", ",", "'elapsed_time'", "=>", "0", "]", ";", "$", "oDb", "=", "Factory", "::", "service", "(", "'Database'", ")", ";", "$", "oDb", "->", "select", "(", "'o.id, o.filename, o.filename_display, o.mime, o.filesize, o.driver'", ")", ";", "$", "oDb", "->", "select", "(", "'b.slug bucket_slug, b.label bucket'", ")", ";", "$", "oDb", "->", "join", "(", "NAILS_DB_PREFIX", ".", "'cdn_bucket b'", ",", "'o.bucket_id = b.id'", ")", ";", "$", "oDb", "->", "order_by", "(", "'b.label'", ")", ";", "$", "oDb", "->", "order_by", "(", "'o.filename_display'", ")", ";", "$", "oQuery", "=", "$", "oDb", "->", "get", "(", "NAILS_DB_PREFIX", ".", "'cdn_object o'", ")", ";", "while", "(", "$", "oRow", "=", "$", "oQuery", "->", "unbuffered_row", "(", ")", ")", "{", "if", "(", "!", "$", "this", "->", "callDriver", "(", "'objectExists'", ",", "[", "$", "oRow", "->", "filename", ",", "$", "oRow", "->", "bucket_slug", "]", ")", ")", "{", "$", "aOut", "[", "'orphans'", "]", "[", "]", "=", "$", "oRow", ";", "}", "}", "return", "$", "aOut", ";", "}" ]
Finds objects which have no file counterparts @return array
[ "Finds", "objects", "which", "have", "no", "file", "counterparts" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L2893-L2911
34,624
nails/module-cdn
src/Service/Cdn.php
Cdn.isAllowedExt
protected function isAllowedExt($sExtension, array $aAllowedExt) { $aAllowedExt = array_filter($aAllowedExt); if (empty($aAllowedExt)) { return true; } // Sanitise and map common extensions $sExtension = $this->sanitiseExtension($sExtension); // Sanitize allowed types $aAllowedExt = array_map([$this, 'sanitiseExtension'], $aAllowedExt); $aAllowedExt = array_unique($aAllowedExt); $aAllowedExt = array_values($aAllowedExt); // Search return in_array($sExtension, $aAllowedExt); }
php
protected function isAllowedExt($sExtension, array $aAllowedExt) { $aAllowedExt = array_filter($aAllowedExt); if (empty($aAllowedExt)) { return true; } // Sanitise and map common extensions $sExtension = $this->sanitiseExtension($sExtension); // Sanitize allowed types $aAllowedExt = array_map([$this, 'sanitiseExtension'], $aAllowedExt); $aAllowedExt = array_unique($aAllowedExt); $aAllowedExt = array_values($aAllowedExt); // Search return in_array($sExtension, $aAllowedExt); }
[ "protected", "function", "isAllowedExt", "(", "$", "sExtension", ",", "array", "$", "aAllowedExt", ")", "{", "$", "aAllowedExt", "=", "array_filter", "(", "$", "aAllowedExt", ")", ";", "if", "(", "empty", "(", "$", "aAllowedExt", ")", ")", "{", "return", "true", ";", "}", "// Sanitise and map common extensions", "$", "sExtension", "=", "$", "this", "->", "sanitiseExtension", "(", "$", "sExtension", ")", ";", "// Sanitize allowed types", "$", "aAllowedExt", "=", "array_map", "(", "[", "$", "this", ",", "'sanitiseExtension'", "]", ",", "$", "aAllowedExt", ")", ";", "$", "aAllowedExt", "=", "array_unique", "(", "$", "aAllowedExt", ")", ";", "$", "aAllowedExt", "=", "array_values", "(", "$", "aAllowedExt", ")", ";", "// Search", "return", "in_array", "(", "$", "sExtension", ",", "$", "aAllowedExt", ")", ";", "}" ]
Determines whether a supplied extension is valid for a given array of acceptable extensions @param string $sExtension The extension to test @param array $aAllowedExt An array of valid extensions @return boolean
[ "Determines", "whether", "a", "supplied", "extension", "is", "valid", "for", "a", "given", "array", "of", "acceptable", "extensions" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L2936-L2954
34,625
nails/module-cdn
src/Service/Cdn.php
Cdn.sanitiseExtension
public function sanitiseExtension($sExt) { $sExt = trim(strtolower($sExt)); $sExt = preg_replace('/^\./', '', $sExt); switch ($sExt) { case 'jpeg': $sExt = 'jpg'; break; } return $sExt; }
php
public function sanitiseExtension($sExt) { $sExt = trim(strtolower($sExt)); $sExt = preg_replace('/^\./', '', $sExt); switch ($sExt) { case 'jpeg': $sExt = 'jpg'; break; } return $sExt; }
[ "public", "function", "sanitiseExtension", "(", "$", "sExt", ")", "{", "$", "sExt", "=", "trim", "(", "strtolower", "(", "$", "sExt", ")", ")", ";", "$", "sExt", "=", "preg_replace", "(", "'/^\\./'", ",", "''", ",", "$", "sExt", ")", ";", "switch", "(", "$", "sExt", ")", "{", "case", "'jpeg'", ":", "$", "sExt", "=", "'jpg'", ";", "break", ";", "}", "return", "$", "sExt", ";", "}" ]
Maps variants of an extension to a definitive one, for consistency. Can be overloaded by the developer to satisfy any preferences with regards file extensions @param string $sExt The extension to map @return string
[ "Maps", "variants", "of", "an", "extension", "to", "a", "definitive", "one", "for", "consistency", ".", "Can", "be", "overloaded", "by", "the", "developer", "to", "satisfy", "any", "preferences", "with", "regards", "file", "extensions" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L2967-L2979
34,626
nails/module-cdn
src/Service/Cdn.php
Cdn.formatBytes
public static function formatBytes($iBytes, $iPrecision = 2) { $units = ['B', 'KB', 'MB', 'GB', 'TB']; $iBytes = max($iBytes, 0); $pow = floor(($iBytes ? log($iBytes) : 0) / log(1024)); $pow = min($pow, count($units) - 1); // Uncomment one of the following alternatives //$iBytes /= pow(1024, $pow); $iBytes /= (1 << (10 * $pow)); $var = round($iBytes, $iPrecision) . ' ' . $units[$pow]; $pattern = '/(.+?)\.(.*?)/'; return preg_replace_callback( $pattern, function ($matches) { return number_format($matches[1]) . '.' . $matches[2]; }, $var ); }
php
public static function formatBytes($iBytes, $iPrecision = 2) { $units = ['B', 'KB', 'MB', 'GB', 'TB']; $iBytes = max($iBytes, 0); $pow = floor(($iBytes ? log($iBytes) : 0) / log(1024)); $pow = min($pow, count($units) - 1); // Uncomment one of the following alternatives //$iBytes /= pow(1024, $pow); $iBytes /= (1 << (10 * $pow)); $var = round($iBytes, $iPrecision) . ' ' . $units[$pow]; $pattern = '/(.+?)\.(.*?)/'; return preg_replace_callback( $pattern, function ($matches) { return number_format($matches[1]) . '.' . $matches[2]; }, $var ); }
[ "public", "static", "function", "formatBytes", "(", "$", "iBytes", ",", "$", "iPrecision", "=", "2", ")", "{", "$", "units", "=", "[", "'B'", ",", "'KB'", ",", "'MB'", ",", "'GB'", ",", "'TB'", "]", ";", "$", "iBytes", "=", "max", "(", "$", "iBytes", ",", "0", ")", ";", "$", "pow", "=", "floor", "(", "(", "$", "iBytes", "?", "log", "(", "$", "iBytes", ")", ":", "0", ")", "/", "log", "(", "1024", ")", ")", ";", "$", "pow", "=", "min", "(", "$", "pow", ",", "count", "(", "$", "units", ")", "-", "1", ")", ";", "// Uncomment one of the following alternatives", "//$iBytes /= pow(1024, $pow);", "$", "iBytes", "/=", "(", "1", "<<", "(", "10", "*", "$", "pow", ")", ")", ";", "$", "var", "=", "round", "(", "$", "iBytes", ",", "$", "iPrecision", ")", ".", "' '", ".", "$", "units", "[", "$", "pow", "]", ";", "$", "pattern", "=", "'/(.+?)\\.(.*?)/'", ";", "return", "preg_replace_callback", "(", "$", "pattern", ",", "function", "(", "$", "matches", ")", "{", "return", "number_format", "(", "$", "matches", "[", "1", "]", ")", ".", "'.'", ".", "$", "matches", "[", "2", "]", ";", "}", ",", "$", "var", ")", ";", "}" ]
Formats a file size given in bytes into a human-friendly string @param integer $iBytes The file size, in bytes @param integer $iPrecision The precision to use @return string
[ "Formats", "a", "file", "size", "given", "in", "bytes", "into", "a", "human", "-", "friendly", "string" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L3071-L3091
34,627
nails/module-cdn
src/Service/Cdn.php
Cdn.getPermittedDimensions
public function getPermittedDimensions(): array { $aDimensions = array_map(function ($sDimension) { return (object) array_combine( ['width', 'height'], array_map('intval', explode('x', $sDimension)) ); }, $this->aPermittedDimensions); arraySortMulti($aDimensions, 'width'); return array_values($aDimensions); }
php
public function getPermittedDimensions(): array { $aDimensions = array_map(function ($sDimension) { return (object) array_combine( ['width', 'height'], array_map('intval', explode('x', $sDimension)) ); }, $this->aPermittedDimensions); arraySortMulti($aDimensions, 'width'); return array_values($aDimensions); }
[ "public", "function", "getPermittedDimensions", "(", ")", ":", "array", "{", "$", "aDimensions", "=", "array_map", "(", "function", "(", "$", "sDimension", ")", "{", "return", "(", "object", ")", "array_combine", "(", "[", "'width'", ",", "'height'", "]", ",", "array_map", "(", "'intval'", ",", "explode", "(", "'x'", ",", "$", "sDimension", ")", ")", ")", ";", "}", ",", "$", "this", "->", "aPermittedDimensions", ")", ";", "arraySortMulti", "(", "$", "aDimensions", ",", "'width'", ")", ";", "return", "array_values", "(", "$", "aDimensions", ")", ";", "}" ]
Return the permitted dimensions for this installation @return \stdClass[]
[ "Return", "the", "permitted", "dimensions", "for", "this", "installation" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L3154-L3166
34,628
nails/module-cdn
src/Service/Cdn.php
Cdn.isPermittedDimension
public function isPermittedDimension($iWidth, $iHeight): bool { if (Factory::property('allowDangerousImageTransformation', 'nails/module-cdn')) { return true; } else { $sDimension = $iWidth . 'x' . $iHeight; return in_array($sDimension, $this->aPermittedDimensions); } }
php
public function isPermittedDimension($iWidth, $iHeight): bool { if (Factory::property('allowDangerousImageTransformation', 'nails/module-cdn')) { return true; } else { $sDimension = $iWidth . 'x' . $iHeight; return in_array($sDimension, $this->aPermittedDimensions); } }
[ "public", "function", "isPermittedDimension", "(", "$", "iWidth", ",", "$", "iHeight", ")", ":", "bool", "{", "if", "(", "Factory", "::", "property", "(", "'allowDangerousImageTransformation'", ",", "'nails/module-cdn'", ")", ")", "{", "return", "true", ";", "}", "else", "{", "$", "sDimension", "=", "$", "iWidth", ".", "'x'", ".", "$", "iHeight", ";", "return", "in_array", "(", "$", "sDimension", ",", "$", "this", "->", "aPermittedDimensions", ")", ";", "}", "}" ]
Determines whether the dimensions are permitted by the CDN @param int $iWidth The width to check @param int $iHeight The height to check
[ "Determines", "whether", "the", "dimensions", "are", "permitted", "by", "the", "CDN" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L3176-L3184
34,629
pckg/database
src/Pckg/Database/Repository/PDO/Command/GetRecords.php
GetRecords.executeAll
public function executeAll() { $repository = $this->repository; $entity = $this->entity; $prepare = $repository->prepareQuery($entity->getQuery(), $entity->getRecordClass()); $measure = str_replace("\n", " ", $prepare->queryString); $hash = sha1($measure . microtime()); startMeasure('Executing ' . $measure); $execute = $repository->executePrepared($prepare); stopMeasure('Executing ' . $measure); if (!$execute) { return new Collection(); } $results = $repository->fetchAllPrepared($prepare); if (!$results) { return new Collection(); } $collection = new Collection($results); if ($entity->getQuery()->isCounted()) { startMeasure('Counting ' . $hash); $prepareCount = $repository->prepareSQL('SELECT FOUND_ROWS()'); $repository->executePrepared($prepareCount); $collection->setTotal($prepareCount->fetch(PDO::FETCH_COLUMN)); $entity->count(false); stopMeasure('Counting ' . $hash); } startMeasure('Setting original ' . $hash); $collection->setEntity($entity)->setSaved()->setOriginalFromData(); stopMeasure('Setting original ' . $hash); startMeasure('Filling relations ' . $hash); $filled = $entity->fillCollectionWithRelations($collection); stopMeasure('Filling relations ' . $hash); return $filled; }
php
public function executeAll() { $repository = $this->repository; $entity = $this->entity; $prepare = $repository->prepareQuery($entity->getQuery(), $entity->getRecordClass()); $measure = str_replace("\n", " ", $prepare->queryString); $hash = sha1($measure . microtime()); startMeasure('Executing ' . $measure); $execute = $repository->executePrepared($prepare); stopMeasure('Executing ' . $measure); if (!$execute) { return new Collection(); } $results = $repository->fetchAllPrepared($prepare); if (!$results) { return new Collection(); } $collection = new Collection($results); if ($entity->getQuery()->isCounted()) { startMeasure('Counting ' . $hash); $prepareCount = $repository->prepareSQL('SELECT FOUND_ROWS()'); $repository->executePrepared($prepareCount); $collection->setTotal($prepareCount->fetch(PDO::FETCH_COLUMN)); $entity->count(false); stopMeasure('Counting ' . $hash); } startMeasure('Setting original ' . $hash); $collection->setEntity($entity)->setSaved()->setOriginalFromData(); stopMeasure('Setting original ' . $hash); startMeasure('Filling relations ' . $hash); $filled = $entity->fillCollectionWithRelations($collection); stopMeasure('Filling relations ' . $hash); return $filled; }
[ "public", "function", "executeAll", "(", ")", "{", "$", "repository", "=", "$", "this", "->", "repository", ";", "$", "entity", "=", "$", "this", "->", "entity", ";", "$", "prepare", "=", "$", "repository", "->", "prepareQuery", "(", "$", "entity", "->", "getQuery", "(", ")", ",", "$", "entity", "->", "getRecordClass", "(", ")", ")", ";", "$", "measure", "=", "str_replace", "(", "\"\\n\"", ",", "\" \"", ",", "$", "prepare", "->", "queryString", ")", ";", "$", "hash", "=", "sha1", "(", "$", "measure", ".", "microtime", "(", ")", ")", ";", "startMeasure", "(", "'Executing '", ".", "$", "measure", ")", ";", "$", "execute", "=", "$", "repository", "->", "executePrepared", "(", "$", "prepare", ")", ";", "stopMeasure", "(", "'Executing '", ".", "$", "measure", ")", ";", "if", "(", "!", "$", "execute", ")", "{", "return", "new", "Collection", "(", ")", ";", "}", "$", "results", "=", "$", "repository", "->", "fetchAllPrepared", "(", "$", "prepare", ")", ";", "if", "(", "!", "$", "results", ")", "{", "return", "new", "Collection", "(", ")", ";", "}", "$", "collection", "=", "new", "Collection", "(", "$", "results", ")", ";", "if", "(", "$", "entity", "->", "getQuery", "(", ")", "->", "isCounted", "(", ")", ")", "{", "startMeasure", "(", "'Counting '", ".", "$", "hash", ")", ";", "$", "prepareCount", "=", "$", "repository", "->", "prepareSQL", "(", "'SELECT FOUND_ROWS()'", ")", ";", "$", "repository", "->", "executePrepared", "(", "$", "prepareCount", ")", ";", "$", "collection", "->", "setTotal", "(", "$", "prepareCount", "->", "fetch", "(", "PDO", "::", "FETCH_COLUMN", ")", ")", ";", "$", "entity", "->", "count", "(", "false", ")", ";", "stopMeasure", "(", "'Counting '", ".", "$", "hash", ")", ";", "}", "startMeasure", "(", "'Setting original '", ".", "$", "hash", ")", ";", "$", "collection", "->", "setEntity", "(", "$", "entity", ")", "->", "setSaved", "(", ")", "->", "setOriginalFromData", "(", ")", ";", "stopMeasure", "(", "'Setting original '", ".", "$", "hash", ")", ";", "startMeasure", "(", "'Filling relations '", ".", "$", "hash", ")", ";", "$", "filled", "=", "$", "entity", "->", "fillCollectionWithRelations", "(", "$", "collection", ")", ";", "stopMeasure", "(", "'Filling relations '", ".", "$", "hash", ")", ";", "return", "$", "filled", ";", "}" ]
Prepare query from entity, fetch records and fill them with relations. @return CollectionInterface
[ "Prepare", "query", "from", "entity", "fetch", "records", "and", "fill", "them", "with", "relations", "." ]
99b26b4cb2bacc2bbbb83b7341a209c1cf0100d3
https://github.com/pckg/database/blob/99b26b4cb2bacc2bbbb83b7341a209c1cf0100d3/src/Pckg/Database/Repository/PDO/Command/GetRecords.php#L44-L88
34,630
jon48/webtrees-lib
src/Webtrees/ImageBuilder.php
ImageBuilder.renderError
protected function renderError() { $error = I18N::translate('The media file was not found in this family tree.'); $width = (mb_strlen($error) * 6.5 + 50) * 1.15; $height = 60; $im = imagecreatetruecolor($width, $height); /* Create a black image */ $bgc = imagecolorallocate($im, 255, 255, 255); /* set background color */ imagefilledrectangle($im, 2, 2, $width - 4, $height - 4, $bgc); /* create a rectangle, leaving 2 px border */ $this->embedText($im, $error, 100, '255, 0, 0', WT_ROOT . Config::FONT_DEJAVU_SANS_TTF, 'top', 'left'); http_response_code(404); header('Content-Type: image/png'); imagepng($im); imagedestroy($im); }
php
protected function renderError() { $error = I18N::translate('The media file was not found in this family tree.'); $width = (mb_strlen($error) * 6.5 + 50) * 1.15; $height = 60; $im = imagecreatetruecolor($width, $height); /* Create a black image */ $bgc = imagecolorallocate($im, 255, 255, 255); /* set background color */ imagefilledrectangle($im, 2, 2, $width - 4, $height - 4, $bgc); /* create a rectangle, leaving 2 px border */ $this->embedText($im, $error, 100, '255, 0, 0', WT_ROOT . Config::FONT_DEJAVU_SANS_TTF, 'top', 'left'); http_response_code(404); header('Content-Type: image/png'); imagepng($im); imagedestroy($im); }
[ "protected", "function", "renderError", "(", ")", "{", "$", "error", "=", "I18N", "::", "translate", "(", "'The media file was not found in this family tree.'", ")", ";", "$", "width", "=", "(", "mb_strlen", "(", "$", "error", ")", "*", "6.5", "+", "50", ")", "*", "1.15", ";", "$", "height", "=", "60", ";", "$", "im", "=", "imagecreatetruecolor", "(", "$", "width", ",", "$", "height", ")", ";", "/* Create a black image */", "$", "bgc", "=", "imagecolorallocate", "(", "$", "im", ",", "255", ",", "255", ",", "255", ")", ";", "/* set background color */", "imagefilledrectangle", "(", "$", "im", ",", "2", ",", "2", ",", "$", "width", "-", "4", ",", "$", "height", "-", "4", ",", "$", "bgc", ")", ";", "/* create a rectangle, leaving 2 px border */", "$", "this", "->", "embedText", "(", "$", "im", ",", "$", "error", ",", "100", ",", "'255, 0, 0'", ",", "WT_ROOT", ".", "Config", "::", "FONT_DEJAVU_SANS_TTF", ",", "'top'", ",", "'left'", ")", ";", "http_response_code", "(", "404", ")", ";", "header", "(", "'Content-Type: image/png'", ")", ";", "imagepng", "(", "$", "im", ")", ";", "imagedestroy", "(", "$", "im", ")", ";", "}" ]
Render an error as an image.
[ "Render", "an", "error", "as", "an", "image", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/ImageBuilder.php#L274-L289
34,631
jon48/webtrees-lib
src/Webtrees/ImageBuilder.php
ImageBuilder.applyWatermark
protected function applyWatermark($im) { // text to watermark with if(method_exists($this->media, 'getWatermarkText')) { $word1_text = $this->media->getWatermarkText(); } else { $word1_text = $this->media->getTitle(); } $this->embedText( $im, $word1_text, $this->font_max_size, $this->font_color, WT_ROOT . Config::FONT_DEJAVU_SANS_TTF, 'top', 'left' ); return ($im); }
php
protected function applyWatermark($im) { // text to watermark with if(method_exists($this->media, 'getWatermarkText')) { $word1_text = $this->media->getWatermarkText(); } else { $word1_text = $this->media->getTitle(); } $this->embedText( $im, $word1_text, $this->font_max_size, $this->font_color, WT_ROOT . Config::FONT_DEJAVU_SANS_TTF, 'top', 'left' ); return ($im); }
[ "protected", "function", "applyWatermark", "(", "$", "im", ")", "{", "// text to watermark with\t ", "if", "(", "method_exists", "(", "$", "this", "->", "media", ",", "'getWatermarkText'", ")", ")", "{", "$", "word1_text", "=", "$", "this", "->", "media", "->", "getWatermarkText", "(", ")", ";", "}", "else", "{", "$", "word1_text", "=", "$", "this", "->", "media", "->", "getTitle", "(", ")", ";", "}", "$", "this", "->", "embedText", "(", "$", "im", ",", "$", "word1_text", ",", "$", "this", "->", "font_max_size", ",", "$", "this", "->", "font_color", ",", "WT_ROOT", ".", "Config", "::", "FONT_DEJAVU_SANS_TTF", ",", "'top'", ",", "'left'", ")", ";", "return", "(", "$", "im", ")", ";", "}" ]
Returns the entered image with a watermark printed. Similar to the the media firewall function. @param resource $im Certificate image to watermark @return resource Watermarked image
[ "Returns", "the", "entered", "image", "with", "a", "watermark", "printed", ".", "Similar", "to", "the", "the", "media", "firewall", "function", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/ImageBuilder.php#L298-L319
34,632
jon48/webtrees-lib
src/Webtrees/ImageBuilder.php
ImageBuilder.textLength
function textLength($t, $mxl, $text) { $taille_c = $t; $len = mb_strlen($text); while (($taille_c - 2) * $len > $mxl) { $taille_c--; if ($taille_c == 2) { break; } } return $taille_c; }
php
function textLength($t, $mxl, $text) { $taille_c = $t; $len = mb_strlen($text); while (($taille_c - 2) * $len > $mxl) { $taille_c--; if ($taille_c == 2) { break; } } return $taille_c; }
[ "function", "textLength", "(", "$", "t", ",", "$", "mxl", ",", "$", "text", ")", "{", "$", "taille_c", "=", "$", "t", ";", "$", "len", "=", "mb_strlen", "(", "$", "text", ")", ";", "while", "(", "(", "$", "taille_c", "-", "2", ")", "*", "$", "len", ">", "$", "mxl", ")", "{", "$", "taille_c", "--", ";", "if", "(", "$", "taille_c", "==", "2", ")", "{", "break", ";", "}", "}", "return", "$", "taille_c", ";", "}" ]
Generate an approximate length of text, in pixels. @param int $t @param int $mxl @param string $text @return int
[ "Generate", "an", "approximate", "length", "of", "text", "in", "pixels", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/ImageBuilder.php#L450-L461
34,633
jon48/webtrees-lib
src/Webtrees/ImageBuilder.php
ImageBuilder.imageTtfTextErrorHandler
function imageTtfTextErrorHandler($errno, $errstr) { // log the error Log::addErrorLog('Image Builder error: >' . $errno . '/' . $errstr . '< while processing file >' . $this->media->getServerFilename() . '<'); // change value of useTTF to false so the fallback watermarking can be used. $this->use_ttf = false; return true; }
php
function imageTtfTextErrorHandler($errno, $errstr) { // log the error Log::addErrorLog('Image Builder error: >' . $errno . '/' . $errstr . '< while processing file >' . $this->media->getServerFilename() . '<'); // change value of useTTF to false so the fallback watermarking can be used. $this->use_ttf = false; return true; }
[ "function", "imageTtfTextErrorHandler", "(", "$", "errno", ",", "$", "errstr", ")", "{", "// log the error", "Log", "::", "addErrorLog", "(", "'Image Builder error: >'", ".", "$", "errno", ".", "'/'", ".", "$", "errstr", ".", "'< while processing file >'", ".", "$", "this", "->", "media", "->", "getServerFilename", "(", ")", ".", "'<'", ")", ";", "// change value of useTTF to false so the fallback watermarking can be used.", "$", "this", "->", "use_ttf", "=", "false", ";", "return", "true", ";", "}" ]
imagettftext is the function that is most likely to throw an error use this custom error handler to catch and log it @param int $errno @param string $errstr @return bool
[ "imagettftext", "is", "the", "function", "that", "is", "most", "likely", "to", "throw", "an", "error", "use", "this", "custom", "error", "handler", "to", "catch", "and", "log", "it" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/ImageBuilder.php#L472-L480
34,634
c4studio/chronos
src/Chronos/Content/app/Models/ContentField.php
ContentField.getEnableAltAttribute
public function getEnableAltAttribute() { if ($this->attributes['data'] == '' || $this->attributes['type'] != 'image') return null; $data = unserialize($this->attributes['data']); if (!isset($data['enable_alt'])) return null; else { return $data['enable_alt']; } }
php
public function getEnableAltAttribute() { if ($this->attributes['data'] == '' || $this->attributes['type'] != 'image') return null; $data = unserialize($this->attributes['data']); if (!isset($data['enable_alt'])) return null; else { return $data['enable_alt']; } }
[ "public", "function", "getEnableAltAttribute", "(", ")", "{", "if", "(", "$", "this", "->", "attributes", "[", "'data'", "]", "==", "''", "||", "$", "this", "->", "attributes", "[", "'type'", "]", "!=", "'image'", ")", "return", "null", ";", "$", "data", "=", "unserialize", "(", "$", "this", "->", "attributes", "[", "'data'", "]", ")", ";", "if", "(", "!", "isset", "(", "$", "data", "[", "'enable_alt'", "]", ")", ")", "return", "null", ";", "else", "{", "return", "$", "data", "[", "'enable_alt'", "]", ";", "}", "}" ]
Add enable alt tag to model.
[ "Add", "enable", "alt", "tag", "to", "model", "." ]
df7f3a9794afaade3bee8f6be1223c98e4936cb2
https://github.com/c4studio/chronos/blob/df7f3a9794afaade3bee8f6be1223c98e4936cb2/src/Chronos/Content/app/Models/ContentField.php#L56-L68
34,635
c4studio/chronos
src/Chronos/Content/app/Models/ContentField.php
ContentField.getEnableTitleAttribute
public function getEnableTitleAttribute() { if ($this->attributes['data'] == '' || $this->attributes['type'] != 'image') return null; $data = unserialize($this->attributes['data']); if (!isset($data['enable_title'])) return null; else { return $data['enable_title']; } }
php
public function getEnableTitleAttribute() { if ($this->attributes['data'] == '' || $this->attributes['type'] != 'image') return null; $data = unserialize($this->attributes['data']); if (!isset($data['enable_title'])) return null; else { return $data['enable_title']; } }
[ "public", "function", "getEnableTitleAttribute", "(", ")", "{", "if", "(", "$", "this", "->", "attributes", "[", "'data'", "]", "==", "''", "||", "$", "this", "->", "attributes", "[", "'type'", "]", "!=", "'image'", ")", "return", "null", ";", "$", "data", "=", "unserialize", "(", "$", "this", "->", "attributes", "[", "'data'", "]", ")", ";", "if", "(", "!", "isset", "(", "$", "data", "[", "'enable_title'", "]", ")", ")", "return", "null", ";", "else", "{", "return", "$", "data", "[", "'enable_title'", "]", ";", "}", "}" ]
Add enable title tag to model.
[ "Add", "enable", "title", "tag", "to", "model", "." ]
df7f3a9794afaade3bee8f6be1223c98e4936cb2
https://github.com/c4studio/chronos/blob/df7f3a9794afaade3bee8f6be1223c98e4936cb2/src/Chronos/Content/app/Models/ContentField.php#L73-L85
34,636
c4studio/chronos
src/Chronos/Content/app/Models/ContentField.php
ContentField.getStepAttribute
public function getStepAttribute() { if ($this->attributes['data'] == '' || $this->attributes['type'] != 'number') return null; $data = unserialize($this->attributes['data']); if (!isset($data['step'])) return null; else { return $data['step']; } }
php
public function getStepAttribute() { if ($this->attributes['data'] == '' || $this->attributes['type'] != 'number') return null; $data = unserialize($this->attributes['data']); if (!isset($data['step'])) return null; else { return $data['step']; } }
[ "public", "function", "getStepAttribute", "(", ")", "{", "if", "(", "$", "this", "->", "attributes", "[", "'data'", "]", "==", "''", "||", "$", "this", "->", "attributes", "[", "'type'", "]", "!=", "'number'", ")", "return", "null", ";", "$", "data", "=", "unserialize", "(", "$", "this", "->", "attributes", "[", "'data'", "]", ")", ";", "if", "(", "!", "isset", "(", "$", "data", "[", "'step'", "]", ")", ")", "return", "null", ";", "else", "{", "return", "$", "data", "[", "'step'", "]", ";", "}", "}" ]
Add step to model.
[ "Add", "step", "to", "model", "." ]
df7f3a9794afaade3bee8f6be1223c98e4936cb2
https://github.com/c4studio/chronos/blob/df7f3a9794afaade3bee8f6be1223c98e4936cb2/src/Chronos/Content/app/Models/ContentField.php#L150-L162
34,637
c4studio/chronos
src/Chronos/Content/app/Models/ContentField.php
ContentField.getValuesAttribute
public function getValuesAttribute() { if ($this->attributes['data'] == '' || $this->attributes['type'] != 'list') return null; $data = unserialize($this->attributes['data']); if (!isset($data['values'])) return null; else { return $data['values']; } }
php
public function getValuesAttribute() { if ($this->attributes['data'] == '' || $this->attributes['type'] != 'list') return null; $data = unserialize($this->attributes['data']); if (!isset($data['values'])) return null; else { return $data['values']; } }
[ "public", "function", "getValuesAttribute", "(", ")", "{", "if", "(", "$", "this", "->", "attributes", "[", "'data'", "]", "==", "''", "||", "$", "this", "->", "attributes", "[", "'type'", "]", "!=", "'list'", ")", "return", "null", ";", "$", "data", "=", "unserialize", "(", "$", "this", "->", "attributes", "[", "'data'", "]", ")", ";", "if", "(", "!", "isset", "(", "$", "data", "[", "'values'", "]", ")", ")", "return", "null", ";", "else", "{", "return", "$", "data", "[", "'values'", "]", ";", "}", "}" ]
Add values to model.
[ "Add", "values", "to", "model", "." ]
df7f3a9794afaade3bee8f6be1223c98e4936cb2
https://github.com/c4studio/chronos/blob/df7f3a9794afaade3bee8f6be1223c98e4936cb2/src/Chronos/Content/app/Models/ContentField.php#L167-L179
34,638
c4studio/chronos
src/Chronos/Content/app/Models/ContentField.php
ContentField.getValuesParsedAttribute
public function getValuesParsedAttribute() { if ($this->attributes['data'] == '') return null; $data = unserialize($this->attributes['data']); if (!isset($data['values'])) return null; else { $values = preg_split("/\\r\\n|\\r|\\n/", $data['values']); $ret = []; foreach ($values as $item) { if (strpos($item, '=>')) { $item = str_replace(' => ', '=>', $item); list($key, $value) = explode('=>', $item); $ret[$key] = $value; } else { $ret[$item] = $item; } } return $ret; } }
php
public function getValuesParsedAttribute() { if ($this->attributes['data'] == '') return null; $data = unserialize($this->attributes['data']); if (!isset($data['values'])) return null; else { $values = preg_split("/\\r\\n|\\r|\\n/", $data['values']); $ret = []; foreach ($values as $item) { if (strpos($item, '=>')) { $item = str_replace(' => ', '=>', $item); list($key, $value) = explode('=>', $item); $ret[$key] = $value; } else { $ret[$item] = $item; } } return $ret; } }
[ "public", "function", "getValuesParsedAttribute", "(", ")", "{", "if", "(", "$", "this", "->", "attributes", "[", "'data'", "]", "==", "''", ")", "return", "null", ";", "$", "data", "=", "unserialize", "(", "$", "this", "->", "attributes", "[", "'data'", "]", ")", ";", "if", "(", "!", "isset", "(", "$", "data", "[", "'values'", "]", ")", ")", "return", "null", ";", "else", "{", "$", "values", "=", "preg_split", "(", "\"/\\\\r\\\\n|\\\\r|\\\\n/\"", ",", "$", "data", "[", "'values'", "]", ")", ";", "$", "ret", "=", "[", "]", ";", "foreach", "(", "$", "values", "as", "$", "item", ")", "{", "if", "(", "strpos", "(", "$", "item", ",", "'=>'", ")", ")", "{", "$", "item", "=", "str_replace", "(", "' => '", ",", "'=>'", ",", "$", "item", ")", ";", "list", "(", "$", "key", ",", "$", "value", ")", "=", "explode", "(", "'=>'", ",", "$", "item", ")", ";", "$", "ret", "[", "$", "key", "]", "=", "$", "value", ";", "}", "else", "{", "$", "ret", "[", "$", "item", "]", "=", "$", "item", ";", "}", "}", "return", "$", "ret", ";", "}", "}" ]
Add parsed values to model.
[ "Add", "parsed", "values", "to", "model", "." ]
df7f3a9794afaade3bee8f6be1223c98e4936cb2
https://github.com/c4studio/chronos/blob/df7f3a9794afaade3bee8f6be1223c98e4936cb2/src/Chronos/Content/app/Models/ContentField.php#L184-L210
34,639
GrupaZero/cms
src/Gzero/Cms/Handlers/Block/CacheBlockTrait.php
CacheBlockTrait.getFromCache
protected function getFromCache(Block $block, Language $language) { if ($block->is_cacheable) { return cache()->tags(['blocks'])->get('blocks:cache:' . $block->id . ':' . $language->code, null); } return null; }
php
protected function getFromCache(Block $block, Language $language) { if ($block->is_cacheable) { return cache()->tags(['blocks'])->get('blocks:cache:' . $block->id . ':' . $language->code, null); } return null; }
[ "protected", "function", "getFromCache", "(", "Block", "$", "block", ",", "Language", "$", "language", ")", "{", "if", "(", "$", "block", "->", "is_cacheable", ")", "{", "return", "cache", "(", ")", "->", "tags", "(", "[", "'blocks'", "]", ")", "->", "get", "(", "'blocks:cache:'", ".", "$", "block", "->", "id", ".", "':'", ".", "$", "language", "->", "code", ",", "null", ")", ";", "}", "return", "null", ";", "}" ]
Get rendered block from cache @param Block $block Block @param Language $language Language @return string|null
[ "Get", "rendered", "block", "from", "cache" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Handlers/Block/CacheBlockTrait.php#L16-L22
34,640
GrupaZero/cms
src/Gzero/Cms/Handlers/Block/CacheBlockTrait.php
CacheBlockTrait.putInCache
protected function putInCache(Block $block, Language $language, $html) { if ($block->is_cacheable) { cache()->tags(['blocks'])->forever('blocks:cache:' . $block->id . ':' . $language->code, $html); } }
php
protected function putInCache(Block $block, Language $language, $html) { if ($block->is_cacheable) { cache()->tags(['blocks'])->forever('blocks:cache:' . $block->id . ':' . $language->code, $html); } }
[ "protected", "function", "putInCache", "(", "Block", "$", "block", ",", "Language", "$", "language", ",", "$", "html", ")", "{", "if", "(", "$", "block", "->", "is_cacheable", ")", "{", "cache", "(", ")", "->", "tags", "(", "[", "'blocks'", "]", ")", "->", "forever", "(", "'blocks:cache:'", ".", "$", "block", "->", "id", ".", "':'", ".", "$", "language", "->", "code", ",", "$", "html", ")", ";", "}", "}" ]
Put rendered html in to block cache @param Block $block Block @param Language $language Language @param string $html Rendered html @return void
[ "Put", "rendered", "html", "in", "to", "block", "cache" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Handlers/Block/CacheBlockTrait.php#L33-L38
34,641
MetaModels/filter_range
src/EventListener/DcGeneral/Table/FilterSetting/AbstractAbstainingListener.php
AbstractAbstainingListener.isAllowedContext
protected function isAllowedContext($dataDefinition, $propertyName, $model) { // Check the name of the data def. if ('tl_metamodel_filtersetting' !== $dataDefinition->getName()) { return false; } // Check the name of the property. if ('attr_id2' !== $propertyName) { return false; } // Check the type. $property = $model->getProperty('type'); return !('range' !== $property && 'rangedate' !== $property); }
php
protected function isAllowedContext($dataDefinition, $propertyName, $model) { // Check the name of the data def. if ('tl_metamodel_filtersetting' !== $dataDefinition->getName()) { return false; } // Check the name of the property. if ('attr_id2' !== $propertyName) { return false; } // Check the type. $property = $model->getProperty('type'); return !('range' !== $property && 'rangedate' !== $property); }
[ "protected", "function", "isAllowedContext", "(", "$", "dataDefinition", ",", "$", "propertyName", ",", "$", "model", ")", "{", "// Check the name of the data def.", "if", "(", "'tl_metamodel_filtersetting'", "!==", "$", "dataDefinition", "->", "getName", "(", ")", ")", "{", "return", "false", ";", "}", "// Check the name of the property.", "if", "(", "'attr_id2'", "!==", "$", "propertyName", ")", "{", "return", "false", ";", "}", "// Check the type.", "$", "property", "=", "$", "model", "->", "getProperty", "(", "'type'", ")", ";", "return", "!", "(", "'range'", "!==", "$", "property", "&&", "'rangedate'", "!==", "$", "property", ")", ";", "}" ]
Check if the context of the event is a allowed one. @param ContainerInterface $dataDefinition The data definition from the environment. @param string $propertyName The current property name. @param ModelInterface $model The current model. @return bool True => It is a allowed one | False => nope
[ "Check", "if", "the", "context", "of", "the", "event", "is", "a", "allowed", "one", "." ]
1875e4a2206df2c5c98f5b0a7f18feb17b34f393
https://github.com/MetaModels/filter_range/blob/1875e4a2206df2c5c98f5b0a7f18feb17b34f393/src/EventListener/DcGeneral/Table/FilterSetting/AbstractAbstainingListener.php#L63-L78
34,642
MetaModels/filter_range
src/EventListener/DcGeneral/Table/FilterSetting/AbstractAbstainingListener.php
AbstractAbstainingListener.getMetaModel
protected function getMetaModel(ModelInterface $model) { $filterSetting = $this->filterSettingFactory->createCollection($model->getProperty('fid')); return $filterSetting->getMetaModel(); }
php
protected function getMetaModel(ModelInterface $model) { $filterSetting = $this->filterSettingFactory->createCollection($model->getProperty('fid')); return $filterSetting->getMetaModel(); }
[ "protected", "function", "getMetaModel", "(", "ModelInterface", "$", "model", ")", "{", "$", "filterSetting", "=", "$", "this", "->", "filterSettingFactory", "->", "createCollection", "(", "$", "model", "->", "getProperty", "(", "'fid'", ")", ")", ";", "return", "$", "filterSetting", "->", "getMetaModel", "(", ")", ";", "}" ]
Retrieve the MetaModel attached to the model filter setting. @param ModelInterface $model The model for which to retrieve the MetaModel. @return IMetaModel @throws \RuntimeException When the MetaModel can not be determined.
[ "Retrieve", "the", "MetaModel", "attached", "to", "the", "model", "filter", "setting", "." ]
1875e4a2206df2c5c98f5b0a7f18feb17b34f393
https://github.com/MetaModels/filter_range/blob/1875e4a2206df2c5c98f5b0a7f18feb17b34f393/src/EventListener/DcGeneral/Table/FilterSetting/AbstractAbstainingListener.php#L89-L94
34,643
alexislefebvre/AsyncTweetsBundle
src/Controller/DefaultController.php
DefaultController.getTweetsVars
private function getTweetsVars($tweets, $vars) { /** @var string $firstTweetId */ $firstTweetId = $tweets[0]->getId(); $vars['previous'] = $this->tweetRepository ->getPreviousTweetId($firstTweetId); $vars['next'] = $this->tweetRepository ->getNextTweetId($firstTweetId); // Only update the cookie if the last Tweet Id is bigger than // the one in the cookie if ($firstTweetId > $vars['cookieId']) { $vars['cookie'] = $this->createCookie($firstTweetId); $vars['cookieId'] = $firstTweetId; } $vars['number'] = $this->tweetRepository ->countPendingTweets($vars['cookieId']); $vars['first'] = $firstTweetId; return $vars; }
php
private function getTweetsVars($tweets, $vars) { /** @var string $firstTweetId */ $firstTweetId = $tweets[0]->getId(); $vars['previous'] = $this->tweetRepository ->getPreviousTweetId($firstTweetId); $vars['next'] = $this->tweetRepository ->getNextTweetId($firstTweetId); // Only update the cookie if the last Tweet Id is bigger than // the one in the cookie if ($firstTweetId > $vars['cookieId']) { $vars['cookie'] = $this->createCookie($firstTweetId); $vars['cookieId'] = $firstTweetId; } $vars['number'] = $this->tweetRepository ->countPendingTweets($vars['cookieId']); $vars['first'] = $firstTweetId; return $vars; }
[ "private", "function", "getTweetsVars", "(", "$", "tweets", ",", "$", "vars", ")", "{", "/** @var string $firstTweetId */", "$", "firstTweetId", "=", "$", "tweets", "[", "0", "]", "->", "getId", "(", ")", ";", "$", "vars", "[", "'previous'", "]", "=", "$", "this", "->", "tweetRepository", "->", "getPreviousTweetId", "(", "$", "firstTweetId", ")", ";", "$", "vars", "[", "'next'", "]", "=", "$", "this", "->", "tweetRepository", "->", "getNextTweetId", "(", "$", "firstTweetId", ")", ";", "// Only update the cookie if the last Tweet Id is bigger than", "// the one in the cookie", "if", "(", "$", "firstTweetId", ">", "$", "vars", "[", "'cookieId'", "]", ")", "{", "$", "vars", "[", "'cookie'", "]", "=", "$", "this", "->", "createCookie", "(", "$", "firstTweetId", ")", ";", "$", "vars", "[", "'cookieId'", "]", "=", "$", "firstTweetId", ";", "}", "$", "vars", "[", "'number'", "]", "=", "$", "this", "->", "tweetRepository", "->", "countPendingTweets", "(", "$", "vars", "[", "'cookieId'", "]", ")", ";", "$", "vars", "[", "'first'", "]", "=", "$", "firstTweetId", ";", "return", "$", "vars", ";", "}" ]
If a Tweet is displayed, fetch data from repository. @param Tweet[] $tweets @param array $vars @return array $vars
[ "If", "a", "Tweet", "is", "displayed", "fetch", "data", "from", "repository", "." ]
76266fae7de978963e05dadb14c81f8398bb00a6
https://github.com/alexislefebvre/AsyncTweetsBundle/blob/76266fae7de978963e05dadb14c81f8398bb00a6/src/Controller/DefaultController.php#L86-L109
34,644
datalaere/php-http
src/Input.php
Input.toSlug
public static function toSlug($string, $replace = array(), $delimiter = '-') { if (!empty($replace)) { $string = str_replace((array) $replace, ' ', $string); } return preg_replace('/[^A-Za-z0-9-]+/', $delimiter, $string); }
php
public static function toSlug($string, $replace = array(), $delimiter = '-') { if (!empty($replace)) { $string = str_replace((array) $replace, ' ', $string); } return preg_replace('/[^A-Za-z0-9-]+/', $delimiter, $string); }
[ "public", "static", "function", "toSlug", "(", "$", "string", ",", "$", "replace", "=", "array", "(", ")", ",", "$", "delimiter", "=", "'-'", ")", "{", "if", "(", "!", "empty", "(", "$", "replace", ")", ")", "{", "$", "string", "=", "str_replace", "(", "(", "array", ")", "$", "replace", ",", "' '", ",", "$", "string", ")", ";", "}", "return", "preg_replace", "(", "'/[^A-Za-z0-9-]+/'", ",", "$", "delimiter", ",", "$", "string", ")", ";", "}" ]
This function expects the input to be UTF-8 encoded.
[ "This", "function", "expects", "the", "input", "to", "be", "UTF", "-", "8", "encoded", "." ]
575e12aa853465b1430b3f2c5b074937e8819e8b
https://github.com/datalaere/php-http/blob/575e12aa853465b1430b3f2c5b074937e8819e8b/src/Input.php#L38-L45
34,645
GrupaZero/cms
src/Gzero/Cms/Menu/Register.php
Register.addChild
public function addChild($parentUrl, Link $link) { $this->links->each( function ($value) use ($parentUrl, $link) { if ($value->url === $parentUrl) { $value->children->push($link); return false; } } ); }
php
public function addChild($parentUrl, Link $link) { $this->links->each( function ($value) use ($parentUrl, $link) { if ($value->url === $parentUrl) { $value->children->push($link); return false; } } ); }
[ "public", "function", "addChild", "(", "$", "parentUrl", ",", "Link", "$", "link", ")", "{", "$", "this", "->", "links", "->", "each", "(", "function", "(", "$", "value", ")", "use", "(", "$", "parentUrl", ",", "$", "link", ")", "{", "if", "(", "$", "value", "->", "url", "===", "$", "parentUrl", ")", "{", "$", "value", "->", "children", "->", "push", "(", "$", "link", ")", ";", "return", "false", ";", "}", "}", ")", ";", "}" ]
It adds child link to parent specified by url parameter @param string $parentUrl Parent url @param Link $link Menu link @return void
[ "It", "adds", "child", "link", "to", "parent", "specified", "by", "url", "parameter" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Menu/Register.php#L43-L53
34,646
GrupaZero/cms
src/Gzero/Cms/Menu/Register.php
Register.getMenu
public function getMenu() { $this->links->each( function ($link) { if (!$link->children->isEmpty()) { $link->children = $link->children->sortBy('weight')->values(); } } ); return $this->links->sortBy('weight')->values(); }
php
public function getMenu() { $this->links->each( function ($link) { if (!$link->children->isEmpty()) { $link->children = $link->children->sortBy('weight')->values(); } } ); return $this->links->sortBy('weight')->values(); }
[ "public", "function", "getMenu", "(", ")", "{", "$", "this", "->", "links", "->", "each", "(", "function", "(", "$", "link", ")", "{", "if", "(", "!", "$", "link", "->", "children", "->", "isEmpty", "(", ")", ")", "{", "$", "link", "->", "children", "=", "$", "link", "->", "children", "->", "sortBy", "(", "'weight'", ")", "->", "values", "(", ")", ";", "}", "}", ")", ";", "return", "$", "this", "->", "links", "->", "sortBy", "(", "'weight'", ")", "->", "values", "(", ")", ";", "}" ]
It returns whole menu as tree @return Collection
[ "It", "returns", "whole", "menu", "as", "tree" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Menu/Register.php#L60-L70
34,647
jon48/webtrees-lib
src/Webtrees/Module/Sosa/SosaConfigController.php
SosaConfigController.canUpdate
protected function canUpdate() { $user_id = Filter::postInteger('userid', -1) ?: Filter::getInteger('userid', -1); return Auth::check() && ( $user_id == Auth::user()->getUserId() || // Allow update for yourself ($user_id == -1 && Auth::isManager(Globals::getTree())) // Allow a manager to update the default user ); }
php
protected function canUpdate() { $user_id = Filter::postInteger('userid', -1) ?: Filter::getInteger('userid', -1); return Auth::check() && ( $user_id == Auth::user()->getUserId() || // Allow update for yourself ($user_id == -1 && Auth::isManager(Globals::getTree())) // Allow a manager to update the default user ); }
[ "protected", "function", "canUpdate", "(", ")", "{", "$", "user_id", "=", "Filter", "::", "postInteger", "(", "'userid'", ",", "-", "1", ")", "?", ":", "Filter", "::", "getInteger", "(", "'userid'", ",", "-", "1", ")", ";", "return", "Auth", "::", "check", "(", ")", "&&", "(", "$", "user_id", "==", "Auth", "::", "user", "(", ")", "->", "getUserId", "(", ")", "||", "// Allow update for yourself", "(", "$", "user_id", "==", "-", "1", "&&", "Auth", "::", "isManager", "(", "Globals", "::", "getTree", "(", ")", ")", ")", "// Allow a manager to update the default user", ")", ";", "}" ]
Check if the user can update the sosa ancestors list @return bool
[ "Check", "if", "the", "user", "can", "update", "the", "sosa", "ancestors", "list" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/Sosa/SosaConfigController.php#L38-L45
34,648
CESNET/perun-simplesamlphp-module
lib/AdapterRpc.php
AdapterRpc.getMemberByUser
public function getMemberByUser($user, $vo) { $member = $this->connector->get('membersManager', 'getMemberByUser', array( 'user' => $user->getId(), 'vo' => $vo->getId(), )); if (is_null($member)) { throw new Exception( "Member for User with name " . $user->getName() . " and Vo with shortName " . $vo->getShortName() . "does not exist in Perun!" ); } return new Member($member['id'], $member['voId'], $member['status']); }
php
public function getMemberByUser($user, $vo) { $member = $this->connector->get('membersManager', 'getMemberByUser', array( 'user' => $user->getId(), 'vo' => $vo->getId(), )); if (is_null($member)) { throw new Exception( "Member for User with name " . $user->getName() . " and Vo with shortName " . $vo->getShortName() . "does not exist in Perun!" ); } return new Member($member['id'], $member['voId'], $member['status']); }
[ "public", "function", "getMemberByUser", "(", "$", "user", ",", "$", "vo", ")", "{", "$", "member", "=", "$", "this", "->", "connector", "->", "get", "(", "'membersManager'", ",", "'getMemberByUser'", ",", "array", "(", "'user'", "=>", "$", "user", "->", "getId", "(", ")", ",", "'vo'", "=>", "$", "vo", "->", "getId", "(", ")", ",", ")", ")", ";", "if", "(", "is_null", "(", "$", "member", ")", ")", "{", "throw", "new", "Exception", "(", "\"Member for User with name \"", ".", "$", "user", "->", "getName", "(", ")", ".", "\" and Vo with shortName \"", ".", "$", "vo", "->", "getShortName", "(", ")", ".", "\"does not exist in Perun!\"", ")", ";", "}", "return", "new", "Member", "(", "$", "member", "[", "'id'", "]", ",", "$", "member", "[", "'voId'", "]", ",", "$", "member", "[", "'status'", "]", ")", ";", "}" ]
Returns member by User and Vo @param User $user @param Vo $vo @return Member
[ "Returns", "member", "by", "User", "and", "Vo" ]
f1d686f06472053a7cdb31f2b2776f9714779ee1
https://github.com/CESNET/perun-simplesamlphp-module/blob/f1d686f06472053a7cdb31f2b2776f9714779ee1/lib/AdapterRpc.php#L360-L373
34,649
CESNET/perun-simplesamlphp-module
lib/AdapterRpc.php
AdapterRpc.hasRegistrationForm
public function hasRegistrationForm($group) { try { $this->connector->get('registrarManager', 'getApplicationForm', array( 'group' => $group->getId(), )); return true; } catch (\Exception $exception) { return false; } }
php
public function hasRegistrationForm($group) { try { $this->connector->get('registrarManager', 'getApplicationForm', array( 'group' => $group->getId(), )); return true; } catch (\Exception $exception) { return false; } }
[ "public", "function", "hasRegistrationForm", "(", "$", "group", ")", "{", "try", "{", "$", "this", "->", "connector", "->", "get", "(", "'registrarManager'", ",", "'getApplicationForm'", ",", "array", "(", "'group'", "=>", "$", "group", "->", "getId", "(", ")", ",", ")", ")", ";", "return", "true", ";", "}", "catch", "(", "\\", "Exception", "$", "exception", ")", "{", "return", "false", ";", "}", "}" ]
Returns true if group has registration form, false otherwise @param Group $group @return bool
[ "Returns", "true", "if", "group", "has", "registration", "form", "false", "otherwise" ]
f1d686f06472053a7cdb31f2b2776f9714779ee1
https://github.com/CESNET/perun-simplesamlphp-module/blob/f1d686f06472053a7cdb31f2b2776f9714779ee1/lib/AdapterRpc.php#L380-L390
34,650
voslartomas/WebCMS2
libs/Settings.php
Settings.get
public function get($key, $section = 'basic', $type = null, $options = array(), $language = true) { // system settings if (array_key_exists($section, $this->settings)) { if (array_key_exists($key, $this->settings[$section])) { $settings = $this->settings[$section][$key]; if ($settings->getType() === null && $type !== null) { $settings->setType($type); $this->em->flush(); } return $settings; } } return $this->save($key, $section, $type, $options, $language); }
php
public function get($key, $section = 'basic', $type = null, $options = array(), $language = true) { // system settings if (array_key_exists($section, $this->settings)) { if (array_key_exists($key, $this->settings[$section])) { $settings = $this->settings[$section][$key]; if ($settings->getType() === null && $type !== null) { $settings->setType($type); $this->em->flush(); } return $settings; } } return $this->save($key, $section, $type, $options, $language); }
[ "public", "function", "get", "(", "$", "key", ",", "$", "section", "=", "'basic'", ",", "$", "type", "=", "null", ",", "$", "options", "=", "array", "(", ")", ",", "$", "language", "=", "true", ")", "{", "// system settings", "if", "(", "array_key_exists", "(", "$", "section", ",", "$", "this", "->", "settings", ")", ")", "{", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "settings", "[", "$", "section", "]", ")", ")", "{", "$", "settings", "=", "$", "this", "->", "settings", "[", "$", "section", "]", "[", "$", "key", "]", ";", "if", "(", "$", "settings", "->", "getType", "(", ")", "===", "null", "&&", "$", "type", "!==", "null", ")", "{", "$", "settings", "->", "setType", "(", "$", "type", ")", ";", "$", "this", "->", "em", "->", "flush", "(", ")", ";", "}", "return", "$", "settings", ";", "}", "}", "return", "$", "this", "->", "save", "(", "$", "key", ",", "$", "section", ",", "$", "type", ",", "$", "options", ",", "$", "language", ")", ";", "}" ]
Gets settings by key and section. @param String $key @param String $section @param string $type @return String @throws Exception
[ "Gets", "settings", "by", "key", "and", "section", "." ]
b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf
https://github.com/voslartomas/WebCMS2/blob/b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf/libs/Settings.php#L39-L56
34,651
c4studio/chronos
src/Chronos/Scaffolding/app/Traits/ChronosUser.php
ChronosUser.hasOneOfPermissions
public function hasOneOfPermissions($permissions) { if ($this->hasRole('root')) return true; $has = false; foreach ($permissions as $permission) { $has = $has || $this->hasPermission($permission); } return $has; }
php
public function hasOneOfPermissions($permissions) { if ($this->hasRole('root')) return true; $has = false; foreach ($permissions as $permission) { $has = $has || $this->hasPermission($permission); } return $has; }
[ "public", "function", "hasOneOfPermissions", "(", "$", "permissions", ")", "{", "if", "(", "$", "this", "->", "hasRole", "(", "'root'", ")", ")", "return", "true", ";", "$", "has", "=", "false", ";", "foreach", "(", "$", "permissions", "as", "$", "permission", ")", "{", "$", "has", "=", "$", "has", "||", "$", "this", "->", "hasPermission", "(", "$", "permission", ")", ";", "}", "return", "$", "has", ";", "}" ]
Determine if the user has one of the given permissions. @param $permissions @return bool
[ "Determine", "if", "the", "user", "has", "one", "of", "the", "given", "permissions", "." ]
df7f3a9794afaade3bee8f6be1223c98e4936cb2
https://github.com/c4studio/chronos/blob/df7f3a9794afaade3bee8f6be1223c98e4936cb2/src/Chronos/Scaffolding/app/Traits/ChronosUser.php#L62-L74
34,652
CESNET/perun-simplesamlphp-module
lib/IdpListsService.php
IdpListsService.getInstance
public static function getInstance() { $configuration = Configuration::getConfig(self::CONFIG_FILE_NAME); $idpListServiceType = $configuration->getString(self::PROPNAME_IDP_LIST_SERVICE_TYPE, self::CSV); if ($idpListServiceType === self::CSV) { return new IdpListsServiceCsv(); } elseif ($idpListServiceType === self::DB) { return new IdpListsServiceDB(); } else { throw new Exception( 'Unknown idpListService type. Hint: try ' . self::CSV . ' or ' . self::DB ); } }
php
public static function getInstance() { $configuration = Configuration::getConfig(self::CONFIG_FILE_NAME); $idpListServiceType = $configuration->getString(self::PROPNAME_IDP_LIST_SERVICE_TYPE, self::CSV); if ($idpListServiceType === self::CSV) { return new IdpListsServiceCsv(); } elseif ($idpListServiceType === self::DB) { return new IdpListsServiceDB(); } else { throw new Exception( 'Unknown idpListService type. Hint: try ' . self::CSV . ' or ' . self::DB ); } }
[ "public", "static", "function", "getInstance", "(", ")", "{", "$", "configuration", "=", "Configuration", "::", "getConfig", "(", "self", "::", "CONFIG_FILE_NAME", ")", ";", "$", "idpListServiceType", "=", "$", "configuration", "->", "getString", "(", "self", "::", "PROPNAME_IDP_LIST_SERVICE_TYPE", ",", "self", "::", "CSV", ")", ";", "if", "(", "$", "idpListServiceType", "===", "self", "::", "CSV", ")", "{", "return", "new", "IdpListsServiceCsv", "(", ")", ";", "}", "elseif", "(", "$", "idpListServiceType", "===", "self", "::", "DB", ")", "{", "return", "new", "IdpListsServiceDB", "(", ")", ";", "}", "else", "{", "throw", "new", "Exception", "(", "'Unknown idpListService type. Hint: try '", ".", "self", "::", "CSV", ".", "' or '", ".", "self", "::", "DB", ")", ";", "}", "}" ]
Function returns the instance of sspmod_perun_IdPListsService by configuration Default is CSV @return IdpListsServiceCsv|IdpListsServiceDB
[ "Function", "returns", "the", "instance", "of", "sspmod_perun_IdPListsService", "by", "configuration", "Default", "is", "CSV" ]
f1d686f06472053a7cdb31f2b2776f9714779ee1
https://github.com/CESNET/perun-simplesamlphp-module/blob/f1d686f06472053a7cdb31f2b2776f9714779ee1/lib/IdpListsService.php#L35-L48
34,653
GrupaZero/cms
database/migrations/2014_11_16_114113_create_content.php
CreateContent.seedContentTypes
private function seedContentTypes() { ContentType::firstOrCreate(['name' => 'content', 'handler' => Gzero\Cms\Handlers\Content\ContentHandler::class]); ContentType::firstOrCreate(['name' => 'category', 'handler' => Gzero\Cms\Handlers\Content\CategoryHandler::class]); }
php
private function seedContentTypes() { ContentType::firstOrCreate(['name' => 'content', 'handler' => Gzero\Cms\Handlers\Content\ContentHandler::class]); ContentType::firstOrCreate(['name' => 'category', 'handler' => Gzero\Cms\Handlers\Content\CategoryHandler::class]); }
[ "private", "function", "seedContentTypes", "(", ")", "{", "ContentType", "::", "firstOrCreate", "(", "[", "'name'", "=>", "'content'", ",", "'handler'", "=>", "Gzero", "\\", "Cms", "\\", "Handlers", "\\", "Content", "\\", "ContentHandler", "::", "class", "]", ")", ";", "ContentType", "::", "firstOrCreate", "(", "[", "'name'", "=>", "'category'", ",", "'handler'", "=>", "Gzero", "\\", "Cms", "\\", "Handlers", "\\", "Content", "\\", "CategoryHandler", "::", "class", "]", ")", ";", "}" ]
Seed content types @return void
[ "Seed", "content", "types" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/database/migrations/2014_11_16_114113_create_content.php#L93-L97
34,654
locomotivemtl/charcoal-user
src/Charcoal/User/AbstractUser.php
AbstractUser.logout
public function logout() { // Irrelevant call... if (!$this->id()) { return false; } $key = static::sessionKey(); $_SESSION[$key] = null; unset($_SESSION[$key], static::$authenticatedUser[$key]); return true; }
php
public function logout() { // Irrelevant call... if (!$this->id()) { return false; } $key = static::sessionKey(); $_SESSION[$key] = null; unset($_SESSION[$key], static::$authenticatedUser[$key]); return true; }
[ "public", "function", "logout", "(", ")", "{", "// Irrelevant call...", "if", "(", "!", "$", "this", "->", "id", "(", ")", ")", "{", "return", "false", ";", "}", "$", "key", "=", "static", "::", "sessionKey", "(", ")", ";", "$", "_SESSION", "[", "$", "key", "]", "=", "null", ";", "unset", "(", "$", "_SESSION", "[", "$", "key", "]", ",", "static", "::", "$", "authenticatedUser", "[", "$", "key", "]", ")", ";", "return", "true", ";", "}" ]
Empties the session var associated to the session key. @return boolean Logged out or not.
[ "Empties", "the", "session", "var", "associated", "to", "the", "session", "key", "." ]
86405a592379ebc2b77a7a9a7f68a85f2afe85f0
https://github.com/locomotivemtl/charcoal-user/blob/86405a592379ebc2b77a7a9a7f68a85f2afe85f0/src/Charcoal/User/AbstractUser.php#L478-L491
34,655
locomotivemtl/charcoal-user
src/Charcoal/User/AbstractUser.php
AbstractUser.validate
public function validate(ValidatorInterface &$v = null) { $result = parent::validate($v); $objType = self::objType(); $previousModel = $this->modelFactory()->create($objType)->load($this->id()); $email = $this->email(); if (empty($email)) { $this->validator()->error( 'Email is required.', 'email' ); } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $this->validator()->error( 'Email format is incorrect.', 'email' ); /** Check if updating/changing email. */ } elseif ($previousModel->email() !== $email) { $existingModel = $this->modelFactory()->create($objType)->loadFrom('email', $email); /** Check for existing user with given email. */ if (!empty($existingModel->id())) { $this->validator()->error( 'This email is not available.', 'email' ); } } return count($this->validator()->errorResults()) === 0 && $result; }
php
public function validate(ValidatorInterface &$v = null) { $result = parent::validate($v); $objType = self::objType(); $previousModel = $this->modelFactory()->create($objType)->load($this->id()); $email = $this->email(); if (empty($email)) { $this->validator()->error( 'Email is required.', 'email' ); } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $this->validator()->error( 'Email format is incorrect.', 'email' ); /** Check if updating/changing email. */ } elseif ($previousModel->email() !== $email) { $existingModel = $this->modelFactory()->create($objType)->loadFrom('email', $email); /** Check for existing user with given email. */ if (!empty($existingModel->id())) { $this->validator()->error( 'This email is not available.', 'email' ); } } return count($this->validator()->errorResults()) === 0 && $result; }
[ "public", "function", "validate", "(", "ValidatorInterface", "&", "$", "v", "=", "null", ")", "{", "$", "result", "=", "parent", "::", "validate", "(", "$", "v", ")", ";", "$", "objType", "=", "self", "::", "objType", "(", ")", ";", "$", "previousModel", "=", "$", "this", "->", "modelFactory", "(", ")", "->", "create", "(", "$", "objType", ")", "->", "load", "(", "$", "this", "->", "id", "(", ")", ")", ";", "$", "email", "=", "$", "this", "->", "email", "(", ")", ";", "if", "(", "empty", "(", "$", "email", ")", ")", "{", "$", "this", "->", "validator", "(", ")", "->", "error", "(", "'Email is required.'", ",", "'email'", ")", ";", "}", "elseif", "(", "!", "filter_var", "(", "$", "email", ",", "FILTER_VALIDATE_EMAIL", ")", ")", "{", "$", "this", "->", "validator", "(", ")", "->", "error", "(", "'Email format is incorrect.'", ",", "'email'", ")", ";", "/** Check if updating/changing email. */", "}", "elseif", "(", "$", "previousModel", "->", "email", "(", ")", "!==", "$", "email", ")", "{", "$", "existingModel", "=", "$", "this", "->", "modelFactory", "(", ")", "->", "create", "(", "$", "objType", ")", "->", "loadFrom", "(", "'email'", ",", "$", "email", ")", ";", "/** Check for existing user with given email. */", "if", "(", "!", "empty", "(", "$", "existingModel", "->", "id", "(", ")", ")", ")", "{", "$", "this", "->", "validator", "(", ")", "->", "error", "(", "'This email is not available.'", ",", "'email'", ")", ";", "}", "}", "return", "count", "(", "$", "this", "->", "validator", "(", ")", "->", "errorResults", "(", ")", ")", "===", "0", "&&", "$", "result", ";", "}" ]
Validate the model. @see \Charcoal\Validator\ValidatorInterface @param ValidatorInterface $v Optional. A custom validator object to use for validation. If null, use object's. @return boolean
[ "Validate", "the", "model", "." ]
86405a592379ebc2b77a7a9a7f68a85f2afe85f0
https://github.com/locomotivemtl/charcoal-user/blob/86405a592379ebc2b77a7a9a7f68a85f2afe85f0/src/Charcoal/User/AbstractUser.php#L579-L609
34,656
jon48/webtrees-lib
src/Webtrees/Module/PatronymicLineage/Views/LineageView.php
LineageView.printRootLineage
private function printRootLineage(LineageRootNode $node) { print '<div class="patrolin_tree">'; if($node->getIndividual() === null) { $fam_nodes = $node->getFamiliesNodes(); foreach($fam_nodes as $fam){ foreach($fam_nodes[$fam] as $child_node) { if($child_node) { $this->printLineage($child_node); } } } } else { $this->printLineage($node); } echo '</div>'; $places = $node->getPlaces(); if($places && count($places)>0){ echo '<div class="patrolin_places">'; echo \MyArtJaub\Webtrees\Functions\FunctionsPrint::htmlPlacesCloud($places, false, $this->data->get('tree')); echo '</div>'; } }
php
private function printRootLineage(LineageRootNode $node) { print '<div class="patrolin_tree">'; if($node->getIndividual() === null) { $fam_nodes = $node->getFamiliesNodes(); foreach($fam_nodes as $fam){ foreach($fam_nodes[$fam] as $child_node) { if($child_node) { $this->printLineage($child_node); } } } } else { $this->printLineage($node); } echo '</div>'; $places = $node->getPlaces(); if($places && count($places)>0){ echo '<div class="patrolin_places">'; echo \MyArtJaub\Webtrees\Functions\FunctionsPrint::htmlPlacesCloud($places, false, $this->data->get('tree')); echo '</div>'; } }
[ "private", "function", "printRootLineage", "(", "LineageRootNode", "$", "node", ")", "{", "print", "'<div class=\"patrolin_tree\">'", ";", "if", "(", "$", "node", "->", "getIndividual", "(", ")", "===", "null", ")", "{", "$", "fam_nodes", "=", "$", "node", "->", "getFamiliesNodes", "(", ")", ";", "foreach", "(", "$", "fam_nodes", "as", "$", "fam", ")", "{", "foreach", "(", "$", "fam_nodes", "[", "$", "fam", "]", "as", "$", "child_node", ")", "{", "if", "(", "$", "child_node", ")", "{", "$", "this", "->", "printLineage", "(", "$", "child_node", ")", ";", "}", "}", "}", "}", "else", "{", "$", "this", "->", "printLineage", "(", "$", "node", ")", ";", "}", "echo", "'</div>'", ";", "$", "places", "=", "$", "node", "->", "getPlaces", "(", ")", ";", "if", "(", "$", "places", "&&", "count", "(", "$", "places", ")", ">", "0", ")", "{", "echo", "'<div class=\"patrolin_places\">'", ";", "echo", "\\", "MyArtJaub", "\\", "Webtrees", "\\", "Functions", "\\", "FunctionsPrint", "::", "htmlPlacesCloud", "(", "$", "places", ",", "false", ",", "$", "this", "->", "data", "->", "get", "(", "'tree'", ")", ")", ";", "echo", "'</div>'", ";", "}", "}" ]
Print a root lineage node @param LineageRootNode $node
[ "Print", "a", "root", "lineage", "node" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/PatronymicLineage/Views/LineageView.php#L148-L171
34,657
jon48/webtrees-lib
src/Webtrees/Module/PatronymicLineage/Views/LineageView.php
LineageView.printLineage
private function printLineage(LineageNode $node) { echo '<ul>'; $fam_nodes = $node->getFamiliesNodes(); if(count($fam_nodes) > 0) { $is_first_family = true; foreach($fam_nodes as $fam) { $node_indi = $node->getIndividual(); echo '<li>'; if($is_first_family){ echo FunctionsPrint::htmlIndividualForList($node_indi); } else{ echo FunctionsPrint::htmlIndividualForList($node_indi, false); } //Get individual's spouse $dfam = new Family($fam); $spouse=$dfam->getSpouseById($node_indi); //Print the spouse if relevant if($spouse){ $marrdate = I18N::translate('yes'); $marryear = ''; echo '&nbsp;<a href="'.$fam->getHtmlUrl().'">'; if ($fam->getMarriageYear()){ $marrdate = strip_tags($fam->getMarriageDate()->Display()); $marryear = $fam->getMarriageYear(); } echo '<span class="details1" title="'.$marrdate.'"><i class="icon-rings"></i>'.$marryear.'</span></a>&nbsp;'; echo FunctionsPrint::htmlIndividualForList($spouse); } foreach($fam_nodes[$fam] as $child_node) { if($child_node) { $this->printLineage($child_node); } else { echo '<ul><li><strong>&hellip;</strong></li></ul>'; } } $is_first_family = false; } } else { echo '<li>'; echo \MyArtJaub\Webtrees\Functions\FunctionsPrint::htmlIndividualForList($node->getIndividual()); if($node->hasFollowUpSurname()) { $url_base = WT_SCRIPT_NAME . '?mod=' . \MyArtJaub\Webtrees\Constants::MODULE_MAJ_PATROLIN_NAME . '&mod_action=Lineage'; echo '&nbsp;'. '<a href="' . $url_base . '&surname=' . rawurlencode($node->getFollowUpSurname()) . '&amp;ged=' . $this->data->get('tree')->getNameUrl() . '">'. '('.I18N::translate('Go to %s lineages', $node->getFollowUpSurname()).')'. '</a>'; } echo '</li>'; } echo '</ul>'; }
php
private function printLineage(LineageNode $node) { echo '<ul>'; $fam_nodes = $node->getFamiliesNodes(); if(count($fam_nodes) > 0) { $is_first_family = true; foreach($fam_nodes as $fam) { $node_indi = $node->getIndividual(); echo '<li>'; if($is_first_family){ echo FunctionsPrint::htmlIndividualForList($node_indi); } else{ echo FunctionsPrint::htmlIndividualForList($node_indi, false); } //Get individual's spouse $dfam = new Family($fam); $spouse=$dfam->getSpouseById($node_indi); //Print the spouse if relevant if($spouse){ $marrdate = I18N::translate('yes'); $marryear = ''; echo '&nbsp;<a href="'.$fam->getHtmlUrl().'">'; if ($fam->getMarriageYear()){ $marrdate = strip_tags($fam->getMarriageDate()->Display()); $marryear = $fam->getMarriageYear(); } echo '<span class="details1" title="'.$marrdate.'"><i class="icon-rings"></i>'.$marryear.'</span></a>&nbsp;'; echo FunctionsPrint::htmlIndividualForList($spouse); } foreach($fam_nodes[$fam] as $child_node) { if($child_node) { $this->printLineage($child_node); } else { echo '<ul><li><strong>&hellip;</strong></li></ul>'; } } $is_first_family = false; } } else { echo '<li>'; echo \MyArtJaub\Webtrees\Functions\FunctionsPrint::htmlIndividualForList($node->getIndividual()); if($node->hasFollowUpSurname()) { $url_base = WT_SCRIPT_NAME . '?mod=' . \MyArtJaub\Webtrees\Constants::MODULE_MAJ_PATROLIN_NAME . '&mod_action=Lineage'; echo '&nbsp;'. '<a href="' . $url_base . '&surname=' . rawurlencode($node->getFollowUpSurname()) . '&amp;ged=' . $this->data->get('tree')->getNameUrl() . '">'. '('.I18N::translate('Go to %s lineages', $node->getFollowUpSurname()).')'. '</a>'; } echo '</li>'; } echo '</ul>'; }
[ "private", "function", "printLineage", "(", "LineageNode", "$", "node", ")", "{", "echo", "'<ul>'", ";", "$", "fam_nodes", "=", "$", "node", "->", "getFamiliesNodes", "(", ")", ";", "if", "(", "count", "(", "$", "fam_nodes", ")", ">", "0", ")", "{", "$", "is_first_family", "=", "true", ";", "foreach", "(", "$", "fam_nodes", "as", "$", "fam", ")", "{", "$", "node_indi", "=", "$", "node", "->", "getIndividual", "(", ")", ";", "echo", "'<li>'", ";", "if", "(", "$", "is_first_family", ")", "{", "echo", "FunctionsPrint", "::", "htmlIndividualForList", "(", "$", "node_indi", ")", ";", "}", "else", "{", "echo", "FunctionsPrint", "::", "htmlIndividualForList", "(", "$", "node_indi", ",", "false", ")", ";", "}", "//Get individual's spouse", "$", "dfam", "=", "new", "Family", "(", "$", "fam", ")", ";", "$", "spouse", "=", "$", "dfam", "->", "getSpouseById", "(", "$", "node_indi", ")", ";", "//Print the spouse if relevant", "if", "(", "$", "spouse", ")", "{", "$", "marrdate", "=", "I18N", "::", "translate", "(", "'yes'", ")", ";", "$", "marryear", "=", "''", ";", "echo", "'&nbsp;<a href=\"'", ".", "$", "fam", "->", "getHtmlUrl", "(", ")", ".", "'\">'", ";", "if", "(", "$", "fam", "->", "getMarriageYear", "(", ")", ")", "{", "$", "marrdate", "=", "strip_tags", "(", "$", "fam", "->", "getMarriageDate", "(", ")", "->", "Display", "(", ")", ")", ";", "$", "marryear", "=", "$", "fam", "->", "getMarriageYear", "(", ")", ";", "}", "echo", "'<span class=\"details1\" title=\"'", ".", "$", "marrdate", ".", "'\"><i class=\"icon-rings\"></i>'", ".", "$", "marryear", ".", "'</span></a>&nbsp;'", ";", "echo", "FunctionsPrint", "::", "htmlIndividualForList", "(", "$", "spouse", ")", ";", "}", "foreach", "(", "$", "fam_nodes", "[", "$", "fam", "]", "as", "$", "child_node", ")", "{", "if", "(", "$", "child_node", ")", "{", "$", "this", "->", "printLineage", "(", "$", "child_node", ")", ";", "}", "else", "{", "echo", "'<ul><li><strong>&hellip;</strong></li></ul>'", ";", "}", "}", "$", "is_first_family", "=", "false", ";", "}", "}", "else", "{", "echo", "'<li>'", ";", "echo", "\\", "MyArtJaub", "\\", "Webtrees", "\\", "Functions", "\\", "FunctionsPrint", "::", "htmlIndividualForList", "(", "$", "node", "->", "getIndividual", "(", ")", ")", ";", "if", "(", "$", "node", "->", "hasFollowUpSurname", "(", ")", ")", "{", "$", "url_base", "=", "WT_SCRIPT_NAME", ".", "'?mod='", ".", "\\", "MyArtJaub", "\\", "Webtrees", "\\", "Constants", "::", "MODULE_MAJ_PATROLIN_NAME", ".", "'&mod_action=Lineage'", ";", "echo", "'&nbsp;'", ".", "'<a href=\"'", ".", "$", "url_base", ".", "'&surname='", ".", "rawurlencode", "(", "$", "node", "->", "getFollowUpSurname", "(", ")", ")", ".", "'&amp;ged='", ".", "$", "this", "->", "data", "->", "get", "(", "'tree'", ")", "->", "getNameUrl", "(", ")", ".", "'\">'", ".", "'('", ".", "I18N", "::", "translate", "(", "'Go to %s lineages'", ",", "$", "node", "->", "getFollowUpSurname", "(", ")", ")", ".", "')'", ".", "'</a>'", ";", "}", "echo", "'</li>'", ";", "}", "echo", "'</ul>'", ";", "}" ]
Print a lineage node, recursively. @param LineageNode $node
[ "Print", "a", "lineage", "node", "recursively", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/PatronymicLineage/Views/LineageView.php#L177-L232
34,658
jon48/webtrees-lib
src/Webtrees/Module/PatronymicLineage/LineageController.php
LineageController.getSurnamesList
protected function getSurnamesList() { return QueryName::surnames(Globals::getTree(), $this->surname, $this->alpha, false, false); }
php
protected function getSurnamesList() { return QueryName::surnames(Globals::getTree(), $this->surname, $this->alpha, false, false); }
[ "protected", "function", "getSurnamesList", "(", ")", "{", "return", "QueryName", "::", "surnames", "(", "Globals", "::", "getTree", "(", ")", ",", "$", "this", "->", "surname", ",", "$", "this", "->", "alpha", ",", "false", ",", "false", ")", ";", "}" ]
Get list of surnames, starting with the specified initial @return array
[ "Get", "list", "of", "surnames", "starting", "with", "the", "specified", "initial" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/PatronymicLineage/LineageController.php#L132-L134
34,659
jon48/webtrees-lib
src/Webtrees/Module/PatronymicLineage/LineageController.php
LineageController.getLineages
protected function getLineages() { $builder = new LineageBuilder($this->surname, Globals::getTree()); $lineages = $builder->buildLineages(); return $lineages; }
php
protected function getLineages() { $builder = new LineageBuilder($this->surname, Globals::getTree()); $lineages = $builder->buildLineages(); return $lineages; }
[ "protected", "function", "getLineages", "(", ")", "{", "$", "builder", "=", "new", "LineageBuilder", "(", "$", "this", "->", "surname", ",", "Globals", "::", "getTree", "(", ")", ")", ";", "$", "lineages", "=", "$", "builder", "->", "buildLineages", "(", ")", ";", "return", "$", "lineages", ";", "}" ]
Get the lineages for the controller's specified surname
[ "Get", "the", "lineages", "for", "the", "controller", "s", "specified", "surname" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/PatronymicLineage/LineageController.php#L139-L144
34,660
g4code/log
src/Writer.php
Writer.preVarDump
public static function preVarDump($var, $die = false, $color = '#000000', $parsable = false, $output = true, $indirect = false) { // last line of defense ;) if(!defined('DEBUG') || DEBUG !== true) { return false; } $formated = ''; // if ajax or cli, skip preformating $skipFormating = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') || php_sapi_name() == 'cli' || (defined('DEBUG_SKIP_FORMATTING') && DEBUG_SKIP_FORMATTING) || !$output; $skipFormating || $formated .= "<pre style='padding: 5px; background:#ffffff; font: normal 12px \"Lucida Console\", \"Courier\", monospace; position:relative; clear:both; color:{$color}; border:1px solid {$color}; text-align: left !important;'>"; $formated .= self::_preFormat($var, $parsable, intval($indirect) + 1, $skipFormating); $skipFormating || $formated .= "</pre>"; if(!$output) { return $formated; } echo $formated . "\n"; if($die) { die("\n\nDebug terminated\n"); } }
php
public static function preVarDump($var, $die = false, $color = '#000000', $parsable = false, $output = true, $indirect = false) { // last line of defense ;) if(!defined('DEBUG') || DEBUG !== true) { return false; } $formated = ''; // if ajax or cli, skip preformating $skipFormating = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') || php_sapi_name() == 'cli' || (defined('DEBUG_SKIP_FORMATTING') && DEBUG_SKIP_FORMATTING) || !$output; $skipFormating || $formated .= "<pre style='padding: 5px; background:#ffffff; font: normal 12px \"Lucida Console\", \"Courier\", monospace; position:relative; clear:both; color:{$color}; border:1px solid {$color}; text-align: left !important;'>"; $formated .= self::_preFormat($var, $parsable, intval($indirect) + 1, $skipFormating); $skipFormating || $formated .= "</pre>"; if(!$output) { return $formated; } echo $formated . "\n"; if($die) { die("\n\nDebug terminated\n"); } }
[ "public", "static", "function", "preVarDump", "(", "$", "var", ",", "$", "die", "=", "false", ",", "$", "color", "=", "'#000000'", ",", "$", "parsable", "=", "false", ",", "$", "output", "=", "true", ",", "$", "indirect", "=", "false", ")", "{", "// last line of defense ;)", "if", "(", "!", "defined", "(", "'DEBUG'", ")", "||", "DEBUG", "!==", "true", ")", "{", "return", "false", ";", "}", "$", "formated", "=", "''", ";", "// if ajax or cli, skip preformating", "$", "skipFormating", "=", "(", "isset", "(", "$", "_SERVER", "[", "'HTTP_X_REQUESTED_WITH'", "]", ")", "&&", "$", "_SERVER", "[", "'HTTP_X_REQUESTED_WITH'", "]", "==", "'XMLHttpRequest'", ")", "||", "php_sapi_name", "(", ")", "==", "'cli'", "||", "(", "defined", "(", "'DEBUG_SKIP_FORMATTING'", ")", "&&", "DEBUG_SKIP_FORMATTING", ")", "||", "!", "$", "output", ";", "$", "skipFormating", "||", "$", "formated", ".=", "\"<pre style='padding: 5px; background:#ffffff; font: normal 12px \\\"Lucida Console\\\", \\\"Courier\\\",\n monospace; position:relative; clear:both; color:{$color}; border:1px solid {$color}; text-align: left !important;'>\"", ";", "$", "formated", ".=", "self", "::", "_preFormat", "(", "$", "var", ",", "$", "parsable", ",", "intval", "(", "$", "indirect", ")", "+", "1", ",", "$", "skipFormating", ")", ";", "$", "skipFormating", "||", "$", "formated", ".=", "\"</pre>\"", ";", "if", "(", "!", "$", "output", ")", "{", "return", "$", "formated", ";", "}", "echo", "$", "formated", ".", "\"\\n\"", ";", "if", "(", "$", "die", ")", "{", "die", "(", "\"\\n\\nDebug terminated\\n\"", ")", ";", "}", "}" ]
Dump debug variable @author Dejan Samardzija <samardzija.dejan@gmail.com> @param mixed $var - variable @param bool $die - terminate script after dump @param string $color - text color @param bool $parsable - if true it uses var_export that dumps php usable value @param bool $output - if true it will echo formated string, for false it will return and override die part @param bool $indirect - if call is direct or from wrapper function @return void
[ "Dump", "debug", "variable" ]
909d06503abbb21ac6c79a61d1b2b1bd89eb26d7
https://github.com/g4code/log/blob/909d06503abbb21ac6c79a61d1b2b1bd89eb26d7/src/Writer.php#L55-L87
34,661
g4code/log
src/Writer.php
Writer.writeLog
public static function writeLog ($filename, $string) { $logs_path = defined('PATH_LOGS') ? PATH_LOGS : getcwd(); $logs_path_real = realpath($logs_path); if(!$logs_path_real || !is_writable($logs_path_real)) { throw new \Exception("Log path is not accessible or writable"); } $file_name = $logs_path_real . DIRECTORY_SEPARATOR . strtolower(trim($filename)); $file_folder = dirname($file_name); if (!is_dir($file_folder)) { if (!mkdir($file_folder, 0766, true)) { throw new \Exception("Couldn't create logs subfolder"); } } if (!is_file($file_name)) { if (@touch($file_name)) { @chmod($file_name, 0777); } } return file_put_contents($file_name, $string . PHP_EOL, FILE_APPEND | LOCK_EX); }
php
public static function writeLog ($filename, $string) { $logs_path = defined('PATH_LOGS') ? PATH_LOGS : getcwd(); $logs_path_real = realpath($logs_path); if(!$logs_path_real || !is_writable($logs_path_real)) { throw new \Exception("Log path is not accessible or writable"); } $file_name = $logs_path_real . DIRECTORY_SEPARATOR . strtolower(trim($filename)); $file_folder = dirname($file_name); if (!is_dir($file_folder)) { if (!mkdir($file_folder, 0766, true)) { throw new \Exception("Couldn't create logs subfolder"); } } if (!is_file($file_name)) { if (@touch($file_name)) { @chmod($file_name, 0777); } } return file_put_contents($file_name, $string . PHP_EOL, FILE_APPEND | LOCK_EX); }
[ "public", "static", "function", "writeLog", "(", "$", "filename", ",", "$", "string", ")", "{", "$", "logs_path", "=", "defined", "(", "'PATH_LOGS'", ")", "?", "PATH_LOGS", ":", "getcwd", "(", ")", ";", "$", "logs_path_real", "=", "realpath", "(", "$", "logs_path", ")", ";", "if", "(", "!", "$", "logs_path_real", "||", "!", "is_writable", "(", "$", "logs_path_real", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Log path is not accessible or writable\"", ")", ";", "}", "$", "file_name", "=", "$", "logs_path_real", ".", "DIRECTORY_SEPARATOR", ".", "strtolower", "(", "trim", "(", "$", "filename", ")", ")", ";", "$", "file_folder", "=", "dirname", "(", "$", "file_name", ")", ";", "if", "(", "!", "is_dir", "(", "$", "file_folder", ")", ")", "{", "if", "(", "!", "mkdir", "(", "$", "file_folder", ",", "0766", ",", "true", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Couldn't create logs subfolder\"", ")", ";", "}", "}", "if", "(", "!", "is_file", "(", "$", "file_name", ")", ")", "{", "if", "(", "@", "touch", "(", "$", "file_name", ")", ")", "{", "@", "chmod", "(", "$", "file_name", ",", "0777", ")", ";", "}", "}", "return", "file_put_contents", "(", "$", "file_name", ",", "$", "string", ".", "PHP_EOL", ",", "FILE_APPEND", "|", "LOCK_EX", ")", ";", "}" ]
Write to a log file @param string $filename - log file name @param string $string - text to write in log file @return bool
[ "Write", "to", "a", "log", "file" ]
909d06503abbb21ac6c79a61d1b2b1bd89eb26d7
https://github.com/g4code/log/blob/909d06503abbb21ac6c79a61d1b2b1bd89eb26d7/src/Writer.php#L120-L149
34,662
g4code/log
src/Writer.php
Writer._formatFilePath
private static function _formatFilePath($filename, $format, $extras = array(), $addHostname = false) { // we can parse scalars also if(is_scalar($extras)) { $extras = array($extras); } if(!is_array($extras)) { throw new \Exception('Extras parameter must be array'); } $dot_pos = strrpos($filename, '.'); if(!$dot_pos) { $filename .= '.log'; $dot_pos = strrpos($filename, '.'); } $tmp = strlen($filename) - $dot_pos; switch ($format) { case self::LOGPATH_FORMAT_COMPLEX: // add short date and 24 hour format as last parama $extras[] = $addHostname ? substr($filename, 0, $dot_pos) . '_' . gethostname() : substr($filename, 0, $dot_pos); $extras = array_merge($extras, explode('-', date("H-d-m-Y", Tools::ts()))); // reverse order or extras array so that year is first, month etc... $extras = array_reverse($extras); $glue = DIRECTORY_SEPARATOR; break; default: case self::LOGPATH_FORMAT_SIMPLE: // add machine hostname to extra array $extras[] = substr($filename, 0, $dot_pos); if($addHostname) { $extras[] = gethostname(); } $extras[] = date("Y-m-d", Tools::ts()); $glue = '_'; break; } return implode($glue, $extras) . substr($filename, "-{$tmp}", $tmp); }
php
private static function _formatFilePath($filename, $format, $extras = array(), $addHostname = false) { // we can parse scalars also if(is_scalar($extras)) { $extras = array($extras); } if(!is_array($extras)) { throw new \Exception('Extras parameter must be array'); } $dot_pos = strrpos($filename, '.'); if(!$dot_pos) { $filename .= '.log'; $dot_pos = strrpos($filename, '.'); } $tmp = strlen($filename) - $dot_pos; switch ($format) { case self::LOGPATH_FORMAT_COMPLEX: // add short date and 24 hour format as last parama $extras[] = $addHostname ? substr($filename, 0, $dot_pos) . '_' . gethostname() : substr($filename, 0, $dot_pos); $extras = array_merge($extras, explode('-', date("H-d-m-Y", Tools::ts()))); // reverse order or extras array so that year is first, month etc... $extras = array_reverse($extras); $glue = DIRECTORY_SEPARATOR; break; default: case self::LOGPATH_FORMAT_SIMPLE: // add machine hostname to extra array $extras[] = substr($filename, 0, $dot_pos); if($addHostname) { $extras[] = gethostname(); } $extras[] = date("Y-m-d", Tools::ts()); $glue = '_'; break; } return implode($glue, $extras) . substr($filename, "-{$tmp}", $tmp); }
[ "private", "static", "function", "_formatFilePath", "(", "$", "filename", ",", "$", "format", ",", "$", "extras", "=", "array", "(", ")", ",", "$", "addHostname", "=", "false", ")", "{", "// we can parse scalars also", "if", "(", "is_scalar", "(", "$", "extras", ")", ")", "{", "$", "extras", "=", "array", "(", "$", "extras", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "extras", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Extras parameter must be array'", ")", ";", "}", "$", "dot_pos", "=", "strrpos", "(", "$", "filename", ",", "'.'", ")", ";", "if", "(", "!", "$", "dot_pos", ")", "{", "$", "filename", ".=", "'.log'", ";", "$", "dot_pos", "=", "strrpos", "(", "$", "filename", ",", "'.'", ")", ";", "}", "$", "tmp", "=", "strlen", "(", "$", "filename", ")", "-", "$", "dot_pos", ";", "switch", "(", "$", "format", ")", "{", "case", "self", "::", "LOGPATH_FORMAT_COMPLEX", ":", "// add short date and 24 hour format as last parama", "$", "extras", "[", "]", "=", "$", "addHostname", "?", "substr", "(", "$", "filename", ",", "0", ",", "$", "dot_pos", ")", ".", "'_'", ".", "gethostname", "(", ")", ":", "substr", "(", "$", "filename", ",", "0", ",", "$", "dot_pos", ")", ";", "$", "extras", "=", "array_merge", "(", "$", "extras", ",", "explode", "(", "'-'", ",", "date", "(", "\"H-d-m-Y\"", ",", "Tools", "::", "ts", "(", ")", ")", ")", ")", ";", "// reverse order or extras array so that year is first, month etc...", "$", "extras", "=", "array_reverse", "(", "$", "extras", ")", ";", "$", "glue", "=", "DIRECTORY_SEPARATOR", ";", "break", ";", "default", ":", "case", "self", "::", "LOGPATH_FORMAT_SIMPLE", ":", "// add machine hostname to extra array", "$", "extras", "[", "]", "=", "substr", "(", "$", "filename", ",", "0", ",", "$", "dot_pos", ")", ";", "if", "(", "$", "addHostname", ")", "{", "$", "extras", "[", "]", "=", "gethostname", "(", ")", ";", "}", "$", "extras", "[", "]", "=", "date", "(", "\"Y-m-d\"", ",", "Tools", "::", "ts", "(", ")", ")", ";", "$", "glue", "=", "'_'", ";", "break", ";", "}", "return", "implode", "(", "$", "glue", ",", "$", "extras", ")", ".", "substr", "(", "$", "filename", ",", "\"-{$tmp}\"", ",", "$", "tmp", ")", ";", "}" ]
Format file path @param string $filename @param int $format @param array $extras @param bool $addHostname @throws \Exception @return string
[ "Format", "file", "path" ]
909d06503abbb21ac6c79a61d1b2b1bd89eb26d7
https://github.com/g4code/log/blob/909d06503abbb21ac6c79a61d1b2b1bd89eb26d7/src/Writer.php#L176-L220
34,663
g4code/log
src/Writer.php
Writer.writeLogPre
public static function writeLogPre($var, $filename = '__preformated.log', $addRequestData = false, $traceIndex = 1) { $msg = self::_preFormat($var, false, $traceIndex, true); if($addRequestData) { $msg = Debug::formatHeaderWithTime() . $msg . Debug::formatRequestData(); } return self::writeLogVerbose($filename, $msg); }
php
public static function writeLogPre($var, $filename = '__preformated.log', $addRequestData = false, $traceIndex = 1) { $msg = self::_preFormat($var, false, $traceIndex, true); if($addRequestData) { $msg = Debug::formatHeaderWithTime() . $msg . Debug::formatRequestData(); } return self::writeLogVerbose($filename, $msg); }
[ "public", "static", "function", "writeLogPre", "(", "$", "var", ",", "$", "filename", "=", "'__preformated.log'", ",", "$", "addRequestData", "=", "false", ",", "$", "traceIndex", "=", "1", ")", "{", "$", "msg", "=", "self", "::", "_preFormat", "(", "$", "var", ",", "false", ",", "$", "traceIndex", ",", "true", ")", ";", "if", "(", "$", "addRequestData", ")", "{", "$", "msg", "=", "Debug", "::", "formatHeaderWithTime", "(", ")", ".", "$", "msg", ".", "Debug", "::", "formatRequestData", "(", ")", ";", "}", "return", "self", "::", "writeLogVerbose", "(", "$", "filename", ",", "$", "msg", ")", ";", "}" ]
It will use preVarDump to format variable and WriteLogVerbose to log it to file @param mixed $var variable to parse and log @param string $filename log file name @param bool $addRequestData if we want to log more data, request, time... @param int $traceIndex debug trace index so we have where method was called @return bool
[ "It", "will", "use", "preVarDump", "to", "format", "variable", "and", "WriteLogVerbose", "to", "log", "it", "to", "file" ]
909d06503abbb21ac6c79a61d1b2b1bd89eb26d7
https://github.com/g4code/log/blob/909d06503abbb21ac6c79a61d1b2b1bd89eb26d7/src/Writer.php#L231-L240
34,664
nails/module-cdn
admin/controllers/Utilities.php
Utilities.index
public function index() { if (!userHasPermission('admin:cdn:utilities:findOrphan')) { unauthorised(); } // -------------------------------------------------------------------------- $oInput = Factory::service('Input'); if ($oInput::isCli()) { $this->indexCli(); } else { if ($oInput->post()) { // A little form validation $type = $oInput->post('type'); $parser = $oInput->post('parser'); $error = ''; if ($type == 'db' && $parser == 'create') { $error = 'Cannot use "Add to database" results parser when finding orphaned database objects.'; } if (empty($error)) { switch ($type) { case 'db': $oCdn = Factory::service('Cdn', 'nails/module-cdn'); $this->data['orphans'] = $oCdn->findOrphanedObjects(); break; // @TODO case 'file': $this->data['message'] = '<strong>TODO:</strong> find orphaned files.'; break; // Invalid request default: $this->data['error'] = 'Invalid search type.'; break; } if (isset($this->data['orphans'])) { switch ($parser) { case 'list': $this->data['success'] = '<strong>Search complete!</strong> your results are show below.'; break; // @todo: keep the unset(), it prevents the table from rendering case 'purge': $this->data['message'] = '<strong>TODO:</strong> purge results.'; unset($this->data['orphans']); break; case 'create': $this->data['message'] = '<strong>TODO:</strong> create objects using results.'; unset($this->data['orphans']); break; // Invalid request default: $this->data['error'] = 'Invalid result parse selected.'; unset($this->data['orphans']); break; } } } else { $this->data['error'] = 'An error occurred. ' . $error; } } // -------------------------------------------------------------------------- $this->data['page']->title = 'CDN: Find Orphaned Objects'; // -------------------------------------------------------------------------- Helper::loadView('index'); } }
php
public function index() { if (!userHasPermission('admin:cdn:utilities:findOrphan')) { unauthorised(); } // -------------------------------------------------------------------------- $oInput = Factory::service('Input'); if ($oInput::isCli()) { $this->indexCli(); } else { if ($oInput->post()) { // A little form validation $type = $oInput->post('type'); $parser = $oInput->post('parser'); $error = ''; if ($type == 'db' && $parser == 'create') { $error = 'Cannot use "Add to database" results parser when finding orphaned database objects.'; } if (empty($error)) { switch ($type) { case 'db': $oCdn = Factory::service('Cdn', 'nails/module-cdn'); $this->data['orphans'] = $oCdn->findOrphanedObjects(); break; // @TODO case 'file': $this->data['message'] = '<strong>TODO:</strong> find orphaned files.'; break; // Invalid request default: $this->data['error'] = 'Invalid search type.'; break; } if (isset($this->data['orphans'])) { switch ($parser) { case 'list': $this->data['success'] = '<strong>Search complete!</strong> your results are show below.'; break; // @todo: keep the unset(), it prevents the table from rendering case 'purge': $this->data['message'] = '<strong>TODO:</strong> purge results.'; unset($this->data['orphans']); break; case 'create': $this->data['message'] = '<strong>TODO:</strong> create objects using results.'; unset($this->data['orphans']); break; // Invalid request default: $this->data['error'] = 'Invalid result parse selected.'; unset($this->data['orphans']); break; } } } else { $this->data['error'] = 'An error occurred. ' . $error; } } // -------------------------------------------------------------------------- $this->data['page']->title = 'CDN: Find Orphaned Objects'; // -------------------------------------------------------------------------- Helper::loadView('index'); } }
[ "public", "function", "index", "(", ")", "{", "if", "(", "!", "userHasPermission", "(", "'admin:cdn:utilities:findOrphan'", ")", ")", "{", "unauthorised", "(", ")", ";", "}", "// --------------------------------------------------------------------------", "$", "oInput", "=", "Factory", "::", "service", "(", "'Input'", ")", ";", "if", "(", "$", "oInput", "::", "isCli", "(", ")", ")", "{", "$", "this", "->", "indexCli", "(", ")", ";", "}", "else", "{", "if", "(", "$", "oInput", "->", "post", "(", ")", ")", "{", "// A little form validation", "$", "type", "=", "$", "oInput", "->", "post", "(", "'type'", ")", ";", "$", "parser", "=", "$", "oInput", "->", "post", "(", "'parser'", ")", ";", "$", "error", "=", "''", ";", "if", "(", "$", "type", "==", "'db'", "&&", "$", "parser", "==", "'create'", ")", "{", "$", "error", "=", "'Cannot use \"Add to database\" results parser when finding orphaned database objects.'", ";", "}", "if", "(", "empty", "(", "$", "error", ")", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "'db'", ":", "$", "oCdn", "=", "Factory", "::", "service", "(", "'Cdn'", ",", "'nails/module-cdn'", ")", ";", "$", "this", "->", "data", "[", "'orphans'", "]", "=", "$", "oCdn", "->", "findOrphanedObjects", "(", ")", ";", "break", ";", "// @TODO", "case", "'file'", ":", "$", "this", "->", "data", "[", "'message'", "]", "=", "'<strong>TODO:</strong> find orphaned files.'", ";", "break", ";", "// Invalid request", "default", ":", "$", "this", "->", "data", "[", "'error'", "]", "=", "'Invalid search type.'", ";", "break", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "data", "[", "'orphans'", "]", ")", ")", "{", "switch", "(", "$", "parser", ")", "{", "case", "'list'", ":", "$", "this", "->", "data", "[", "'success'", "]", "=", "'<strong>Search complete!</strong> your results are show below.'", ";", "break", ";", "// @todo: keep the unset(), it prevents the table from rendering", "case", "'purge'", ":", "$", "this", "->", "data", "[", "'message'", "]", "=", "'<strong>TODO:</strong> purge results.'", ";", "unset", "(", "$", "this", "->", "data", "[", "'orphans'", "]", ")", ";", "break", ";", "case", "'create'", ":", "$", "this", "->", "data", "[", "'message'", "]", "=", "'<strong>TODO:</strong> create objects using results.'", ";", "unset", "(", "$", "this", "->", "data", "[", "'orphans'", "]", ")", ";", "break", ";", "// Invalid request", "default", ":", "$", "this", "->", "data", "[", "'error'", "]", "=", "'Invalid result parse selected.'", ";", "unset", "(", "$", "this", "->", "data", "[", "'orphans'", "]", ")", ";", "break", ";", "}", "}", "}", "else", "{", "$", "this", "->", "data", "[", "'error'", "]", "=", "'An error occurred. '", ".", "$", "error", ";", "}", "}", "// --------------------------------------------------------------------------", "$", "this", "->", "data", "[", "'page'", "]", "->", "title", "=", "'CDN: Find Orphaned Objects'", ";", "// --------------------------------------------------------------------------", "Helper", "::", "loadView", "(", "'index'", ")", ";", "}", "}" ]
Find orphaned CDN objects @return void
[ "Find", "orphaned", "CDN", "objects" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/admin/controllers/Utilities.php#L57-L149
34,665
Rareloop/primer-core
src/Primer/Templating/View.php
View.render
public static function render($name, $params = array()) { if (is_array($params)) { $params = new ViewData($params); } $templateClass = Primer::$TEMPLATE_CLASS; $template = new $templateClass(Primer::$VIEW_PATH, $name); Event::fire('view.' . $name, $params); return $template->render($params); }
php
public static function render($name, $params = array()) { if (is_array($params)) { $params = new ViewData($params); } $templateClass = Primer::$TEMPLATE_CLASS; $template = new $templateClass(Primer::$VIEW_PATH, $name); Event::fire('view.' . $name, $params); return $template->render($params); }
[ "public", "static", "function", "render", "(", "$", "name", ",", "$", "params", "=", "array", "(", ")", ")", "{", "if", "(", "is_array", "(", "$", "params", ")", ")", "{", "$", "params", "=", "new", "ViewData", "(", "$", "params", ")", ";", "}", "$", "templateClass", "=", "Primer", "::", "$", "TEMPLATE_CLASS", ";", "$", "template", "=", "new", "$", "templateClass", "(", "Primer", "::", "$", "VIEW_PATH", ",", "$", "name", ")", ";", "Event", "::", "fire", "(", "'view.'", ".", "$", "name", ",", "$", "params", ")", ";", "return", "$", "template", "->", "render", "(", "$", "params", ")", ";", "}" ]
Load a template and optionally pass in params @param string $name The name of the template to load (without .handlebars extension) @param Array|ViewData $params An associative array of variables to export into the view @return string HTML text @author Joe Lambert
[ "Load", "a", "template", "and", "optionally", "pass", "in", "params" ]
fe098d6794a4add368f97672397dc93d223a1786
https://github.com/Rareloop/primer-core/blob/fe098d6794a4add368f97672397dc93d223a1786/src/Primer/Templating/View.php#L21-L33
34,666
jon48/webtrees-lib
src/Webtrees/Module/PatronymicLineage/Model/LineageRootNode.php
LineageRootNode.addPlace
public function addPlace(Place $place) { if(!is_null($place) && !$place->isEmpty()){ $place_name = $place->getFullName(); if(isset($this->places[$place_name])){ $this->places[$place_name]+=1; } else{ $this->places[$place_name] = 1; } } }
php
public function addPlace(Place $place) { if(!is_null($place) && !$place->isEmpty()){ $place_name = $place->getFullName(); if(isset($this->places[$place_name])){ $this->places[$place_name]+=1; } else{ $this->places[$place_name] = 1; } } }
[ "public", "function", "addPlace", "(", "Place", "$", "place", ")", "{", "if", "(", "!", "is_null", "(", "$", "place", ")", "&&", "!", "$", "place", "->", "isEmpty", "(", ")", ")", "{", "$", "place_name", "=", "$", "place", "->", "getFullName", "(", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "places", "[", "$", "place_name", "]", ")", ")", "{", "$", "this", "->", "places", "[", "$", "place_name", "]", "+=", "1", ";", "}", "else", "{", "$", "this", "->", "places", "[", "$", "place_name", "]", "=", "1", ";", "}", "}", "}" ]
Adds a place to the list of lineage's place @param Place $place
[ "Adds", "a", "place", "to", "the", "list", "of", "lineage", "s", "place" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/PatronymicLineage/Model/LineageRootNode.php#L39-L49
34,667
voslartomas/WebCMS2
AdminModule/presenters/BasePresenter.php
BasePresenter.createGrid
public function createGrid(Nette\Application\UI\Presenter $presenter, $name, $entity, $order = null, $where = null) { $grid = new \Grido\Grid($presenter, $name); $qb = $this->em->createQueryBuilder(); if ($order) { foreach ($order as $o) { $qb->addOrderBy('l.'.$o['by'], $o['dir']); } } if ($where) { foreach ($where as $w) { $qb->andWhere('l.'.$w); } } if (strpos($entity, 'WebCMS') === false) { $grid->setModel($qb->select('l')->from("WebCMS\Entity\\$entity", 'l')); } else { $grid->setModel($qb->select('l')->from($entity, 'l')); } $grid->setRememberState(true); $grid->setDefaultPerPage(10); $grid->setTranslator($this->translator); $grid->setFilterRenderType(\Grido\Components\Filters\Filter::RENDER_INNER); return $grid; }
php
public function createGrid(Nette\Application\UI\Presenter $presenter, $name, $entity, $order = null, $where = null) { $grid = new \Grido\Grid($presenter, $name); $qb = $this->em->createQueryBuilder(); if ($order) { foreach ($order as $o) { $qb->addOrderBy('l.'.$o['by'], $o['dir']); } } if ($where) { foreach ($where as $w) { $qb->andWhere('l.'.$w); } } if (strpos($entity, 'WebCMS') === false) { $grid->setModel($qb->select('l')->from("WebCMS\Entity\\$entity", 'l')); } else { $grid->setModel($qb->select('l')->from($entity, 'l')); } $grid->setRememberState(true); $grid->setDefaultPerPage(10); $grid->setTranslator($this->translator); $grid->setFilterRenderType(\Grido\Components\Filters\Filter::RENDER_INNER); return $grid; }
[ "public", "function", "createGrid", "(", "Nette", "\\", "Application", "\\", "UI", "\\", "Presenter", "$", "presenter", ",", "$", "name", ",", "$", "entity", ",", "$", "order", "=", "null", ",", "$", "where", "=", "null", ")", "{", "$", "grid", "=", "new", "\\", "Grido", "\\", "Grid", "(", "$", "presenter", ",", "$", "name", ")", ";", "$", "qb", "=", "$", "this", "->", "em", "->", "createQueryBuilder", "(", ")", ";", "if", "(", "$", "order", ")", "{", "foreach", "(", "$", "order", "as", "$", "o", ")", "{", "$", "qb", "->", "addOrderBy", "(", "'l.'", ".", "$", "o", "[", "'by'", "]", ",", "$", "o", "[", "'dir'", "]", ")", ";", "}", "}", "if", "(", "$", "where", ")", "{", "foreach", "(", "$", "where", "as", "$", "w", ")", "{", "$", "qb", "->", "andWhere", "(", "'l.'", ".", "$", "w", ")", ";", "}", "}", "if", "(", "strpos", "(", "$", "entity", ",", "'WebCMS'", ")", "===", "false", ")", "{", "$", "grid", "->", "setModel", "(", "$", "qb", "->", "select", "(", "'l'", ")", "->", "from", "(", "\"WebCMS\\Entity\\\\$entity\"", ",", "'l'", ")", ")", ";", "}", "else", "{", "$", "grid", "->", "setModel", "(", "$", "qb", "->", "select", "(", "'l'", ")", "->", "from", "(", "$", "entity", ",", "'l'", ")", ")", ";", "}", "$", "grid", "->", "setRememberState", "(", "true", ")", ";", "$", "grid", "->", "setDefaultPerPage", "(", "10", ")", ";", "$", "grid", "->", "setTranslator", "(", "$", "this", "->", "translator", ")", ";", "$", "grid", "->", "setFilterRenderType", "(", "\\", "Grido", "\\", "Components", "\\", "Filters", "\\", "Filter", "::", "RENDER_INNER", ")", ";", "return", "$", "grid", ";", "}" ]
Creates default basic grid. @param Nette\Application\UI\Presenter $presenter @param String $name @param String $entity @param string[] $where @return \Grido\Grid
[ "Creates", "default", "basic", "grid", "." ]
b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf
https://github.com/voslartomas/WebCMS2/blob/b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf/AdminModule/presenters/BasePresenter.php#L291-L321
34,668
voslartomas/WebCMS2
AdminModule/presenters/BasePresenter.php
BasePresenter.createForm
public function createForm() { $form = new Nette\Application\UI\Form(); $form->getElementPrototype()->addAttributes(array('class' => 'ajax')); $form->setTranslator($this->translator); $form->setRenderer(new BootstrapRenderer()); return $form; }
php
public function createForm() { $form = new Nette\Application\UI\Form(); $form->getElementPrototype()->addAttributes(array('class' => 'ajax')); $form->setTranslator($this->translator); $form->setRenderer(new BootstrapRenderer()); return $form; }
[ "public", "function", "createForm", "(", ")", "{", "$", "form", "=", "new", "Nette", "\\", "Application", "\\", "UI", "\\", "Form", "(", ")", ";", "$", "form", "->", "getElementPrototype", "(", ")", "->", "addAttributes", "(", "array", "(", "'class'", "=>", "'ajax'", ")", ")", ";", "$", "form", "->", "setTranslator", "(", "$", "this", "->", "translator", ")", ";", "$", "form", "->", "setRenderer", "(", "new", "BootstrapRenderer", "(", ")", ")", ";", "return", "$", "form", ";", "}" ]
Creates form and rewrite renderer for bootstrap. @return UI\Form
[ "Creates", "form", "and", "rewrite", "renderer", "for", "bootstrap", "." ]
b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf
https://github.com/voslartomas/WebCMS2/blob/b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf/AdminModule/presenters/BasePresenter.php#L327-L336
34,669
voslartomas/WebCMS2
AdminModule/presenters/BasePresenter.php
BasePresenter.injectEntityManager
public function injectEntityManager(\Doctrine\ORM\EntityManager $em) { if ($this->em) { throw new \Nette\InvalidStateException('Entity manager has been already set.'); } $this->em = $em; return $this; }
php
public function injectEntityManager(\Doctrine\ORM\EntityManager $em) { if ($this->em) { throw new \Nette\InvalidStateException('Entity manager has been already set.'); } $this->em = $em; return $this; }
[ "public", "function", "injectEntityManager", "(", "\\", "Doctrine", "\\", "ORM", "\\", "EntityManager", "$", "em", ")", "{", "if", "(", "$", "this", "->", "em", ")", "{", "throw", "new", "\\", "Nette", "\\", "InvalidStateException", "(", "'Entity manager has been already set.'", ")", ";", "}", "$", "this", "->", "em", "=", "$", "em", ";", "return", "$", "this", ";", "}" ]
Injects entity manager. @param \Doctrine\ORM\EntityManager $em @return BasePresenter @throws \Nette\InvalidStateException
[ "Injects", "entity", "manager", "." ]
b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf
https://github.com/voslartomas/WebCMS2/blob/b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf/AdminModule/presenters/BasePresenter.php#L344-L353
34,670
voslartomas/WebCMS2
AdminModule/presenters/BasePresenter.php
BasePresenter.checkPermission
private function checkPermission() { // creates system acl $acl = $this->initAcl(); $identity = $this->getUser()->getIdentity(); $permissions = $this->initPermissions($identity); foreach ($permissions as $key => $p) { if ($p && $acl->hasResource($key)) { $acl->allow($identity->roles[0], $key, Nette\Security\Permission::ALL); } } // homepage and login page can access everyone $acl->allow(Nette\Security\Permission::ALL, 'admin:Homepage', Nette\Security\Permission::ALL); $acl->allow(Nette\Security\Permission::ALL, 'admin:Login', Nette\Security\Permission::ALL); // superadmin has access to everywhere $acl->allow('superadmin', Nette\Security\Permission::ALL, Nette\Security\Permission::ALL); $roles = $this->getUser()->getRoles(); if (!$this->checkRights($acl, $roles)) { $this->presenter->flashMessage($this->translation['You do not have a permission to do this operation!'], 'danger'); $this->redirect(":Admin:Homepage:"); } }
php
private function checkPermission() { // creates system acl $acl = $this->initAcl(); $identity = $this->getUser()->getIdentity(); $permissions = $this->initPermissions($identity); foreach ($permissions as $key => $p) { if ($p && $acl->hasResource($key)) { $acl->allow($identity->roles[0], $key, Nette\Security\Permission::ALL); } } // homepage and login page can access everyone $acl->allow(Nette\Security\Permission::ALL, 'admin:Homepage', Nette\Security\Permission::ALL); $acl->allow(Nette\Security\Permission::ALL, 'admin:Login', Nette\Security\Permission::ALL); // superadmin has access to everywhere $acl->allow('superadmin', Nette\Security\Permission::ALL, Nette\Security\Permission::ALL); $roles = $this->getUser()->getRoles(); if (!$this->checkRights($acl, $roles)) { $this->presenter->flashMessage($this->translation['You do not have a permission to do this operation!'], 'danger'); $this->redirect(":Admin:Homepage:"); } }
[ "private", "function", "checkPermission", "(", ")", "{", "// creates system acl", "$", "acl", "=", "$", "this", "->", "initAcl", "(", ")", ";", "$", "identity", "=", "$", "this", "->", "getUser", "(", ")", "->", "getIdentity", "(", ")", ";", "$", "permissions", "=", "$", "this", "->", "initPermissions", "(", "$", "identity", ")", ";", "foreach", "(", "$", "permissions", "as", "$", "key", "=>", "$", "p", ")", "{", "if", "(", "$", "p", "&&", "$", "acl", "->", "hasResource", "(", "$", "key", ")", ")", "{", "$", "acl", "->", "allow", "(", "$", "identity", "->", "roles", "[", "0", "]", ",", "$", "key", ",", "Nette", "\\", "Security", "\\", "Permission", "::", "ALL", ")", ";", "}", "}", "// homepage and login page can access everyone", "$", "acl", "->", "allow", "(", "Nette", "\\", "Security", "\\", "Permission", "::", "ALL", ",", "'admin:Homepage'", ",", "Nette", "\\", "Security", "\\", "Permission", "::", "ALL", ")", ";", "$", "acl", "->", "allow", "(", "Nette", "\\", "Security", "\\", "Permission", "::", "ALL", ",", "'admin:Login'", ",", "Nette", "\\", "Security", "\\", "Permission", "::", "ALL", ")", ";", "// superadmin has access to everywhere", "$", "acl", "->", "allow", "(", "'superadmin'", ",", "Nette", "\\", "Security", "\\", "Permission", "::", "ALL", ",", "Nette", "\\", "Security", "\\", "Permission", "::", "ALL", ")", ";", "$", "roles", "=", "$", "this", "->", "getUser", "(", ")", "->", "getRoles", "(", ")", ";", "if", "(", "!", "$", "this", "->", "checkRights", "(", "$", "acl", ",", "$", "roles", ")", ")", "{", "$", "this", "->", "presenter", "->", "flashMessage", "(", "$", "this", "->", "translation", "[", "'You do not have a permission to do this operation!'", "]", ",", "'danger'", ")", ";", "$", "this", "->", "redirect", "(", "\":Admin:Homepage:\"", ")", ";", "}", "}" ]
Checks user permission. @return void
[ "Checks", "user", "permission", "." ]
b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf
https://github.com/voslartomas/WebCMS2/blob/b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf/AdminModule/presenters/BasePresenter.php#L451-L477
34,671
voslartomas/WebCMS2
AdminModule/presenters/BasePresenter.php
BasePresenter.formatLayoutTemplateFiles
public function formatLayoutTemplateFiles() { $name = $this->getName(); $presenter = substr($name, strrpos(':'.$name, ':')); $layout = $this->layout ? $this->layout : 'layout'; $dir = dirname($this->getReflection()->getFileName()); $dir = is_dir("$dir/templates") ? $dir : dirname($dir); $list = array( APP_DIR."/../libs/webcms2/webcms2/AdminModule/templates/@$layout.latte", ); do { $list[] = "$dir/templates/@$layout.latte"; $list[] = "$dir/templates/@$layout.phtml"; $dir = dirname($dir); } while ($dir && ($name = substr($name, 0, strrpos($name, ':')))); return $list; }
php
public function formatLayoutTemplateFiles() { $name = $this->getName(); $presenter = substr($name, strrpos(':'.$name, ':')); $layout = $this->layout ? $this->layout : 'layout'; $dir = dirname($this->getReflection()->getFileName()); $dir = is_dir("$dir/templates") ? $dir : dirname($dir); $list = array( APP_DIR."/../libs/webcms2/webcms2/AdminModule/templates/@$layout.latte", ); do { $list[] = "$dir/templates/@$layout.latte"; $list[] = "$dir/templates/@$layout.phtml"; $dir = dirname($dir); } while ($dir && ($name = substr($name, 0, strrpos($name, ':')))); return $list; }
[ "public", "function", "formatLayoutTemplateFiles", "(", ")", "{", "$", "name", "=", "$", "this", "->", "getName", "(", ")", ";", "$", "presenter", "=", "substr", "(", "$", "name", ",", "strrpos", "(", "':'", ".", "$", "name", ",", "':'", ")", ")", ";", "$", "layout", "=", "$", "this", "->", "layout", "?", "$", "this", "->", "layout", ":", "'layout'", ";", "$", "dir", "=", "dirname", "(", "$", "this", "->", "getReflection", "(", ")", "->", "getFileName", "(", ")", ")", ";", "$", "dir", "=", "is_dir", "(", "\"$dir/templates\"", ")", "?", "$", "dir", ":", "dirname", "(", "$", "dir", ")", ";", "$", "list", "=", "array", "(", "APP_DIR", ".", "\"/../libs/webcms2/webcms2/AdminModule/templates/@$layout.latte\"", ",", ")", ";", "do", "{", "$", "list", "[", "]", "=", "\"$dir/templates/@$layout.latte\"", ";", "$", "list", "[", "]", "=", "\"$dir/templates/@$layout.phtml\"", ";", "$", "dir", "=", "dirname", "(", "$", "dir", ")", ";", "}", "while", "(", "$", "dir", "&&", "(", "$", "name", "=", "substr", "(", "$", "name", ",", "0", ",", "strrpos", "(", "$", "name", ",", "':'", ")", ")", ")", ")", ";", "return", "$", "list", ";", "}" ]
Formats layout template file names. @return array
[ "Formats", "layout", "template", "file", "names", "." ]
b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf
https://github.com/voslartomas/WebCMS2/blob/b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf/AdminModule/presenters/BasePresenter.php#L700-L719
34,672
voslartomas/WebCMS2
AdminModule/presenters/BasePresenter.php
BasePresenter.collectionToArray
public function collectionToArray($collection, $title = 'title') { $array = array(); foreach ($collection as $item) { $getter = 'get'.ucfirst($title); $array[$item->getId()] = $item->$getter(); } return $array; }
php
public function collectionToArray($collection, $title = 'title') { $array = array(); foreach ($collection as $item) { $getter = 'get'.ucfirst($title); $array[$item->getId()] = $item->$getter(); } return $array; }
[ "public", "function", "collectionToArray", "(", "$", "collection", ",", "$", "title", "=", "'title'", ")", "{", "$", "array", "=", "array", "(", ")", ";", "foreach", "(", "$", "collection", "as", "$", "item", ")", "{", "$", "getter", "=", "'get'", ".", "ucfirst", "(", "$", "title", ")", ";", "$", "array", "[", "$", "item", "->", "getId", "(", ")", "]", "=", "$", "item", "->", "$", "getter", "(", ")", ";", "}", "return", "$", "array", ";", "}" ]
Transfer collection into array. @param [type] $collection [description] @param string $title [description] @return array [description]
[ "Transfer", "collection", "into", "array", "." ]
b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf
https://github.com/voslartomas/WebCMS2/blob/b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf/AdminModule/presenters/BasePresenter.php#L729-L738
34,673
jon48/webtrees-lib
src/Webtrees/Module/Sosa/Views/SosaListView.php
SosaListView.renderSosaHeader
protected function renderSosaHeader() { $selectedgen = $this->data->get('generation'); $max_gen = $this->data->get('max_gen'); ?> <form method="get" name="setgen" action="module.php"> <input type="hidden" name="mod" value="<?php echo $this->data->get('url_module');?>"> <input type="hidden" name="mod_action" value="<?php echo $this->data->get('url_action');?>"> <input type="hidden" name="ged" value="<?php echo $this->data->get('url_ged');?>"> <div class="maj-table"> <div class="maj-row"> <div class="label"><?php echo I18N::translate('Choose generation') ?></div> </div> <div class="maj-row"> <div class="value"> <select name="gen"> <?php for($i=$this->data->get('min_gen'); $i <= $max_gen;$i++) {?> <option value="<?php echo $i; ?>" <?php if($selectedgen && $selectedgen==$i) { ?> selected="true" <?php } ?> ><?php echo I18N::translate('Generation %d', $i); ?> </option> <?php } ?> </select> </div> </div> </div> <input type="submit" value="<?php echo I18N::translate('Show');?>" /> <br /> </form> <?php if($selectedgen > 0) { ?> <h4> <?php if($selectedgen > $this->data->get('min_gen')) { ?> <a href="module.php?mod=<?php echo $this->data->get('url_module');?>&mod_action=<?php echo $this->data->get('url_action');?>&ged=<?php echo $this->data->get('url_ged');?>&gen=<?php echo $selectedgen-1; ?>"> <i class="icon-ldarrow" title="<?php echo I18N::translate('Previous generation'); ?>" ></i> </a> &nbsp;&nbsp; <?php } ?> <?php echo I18N::translate('Generation %d', $selectedgen); ?> <?php if($selectedgen < $max_gen) { ?> &nbsp;&nbsp; <a href="module.php?mod=<?php echo $this->data->get('url_module');?>&mod_action=<?php echo $this->data->get('url_action');?>&ged=<?php echo $this->data->get('url_ged');?>&gen=<?php echo $selectedgen+1; ?>"> <i class="icon-rdarrow" title="<?php echo I18N::translate('Next generation'); ?>" ></i> </a> <?php } ?> </h4> <?php } }
php
protected function renderSosaHeader() { $selectedgen = $this->data->get('generation'); $max_gen = $this->data->get('max_gen'); ?> <form method="get" name="setgen" action="module.php"> <input type="hidden" name="mod" value="<?php echo $this->data->get('url_module');?>"> <input type="hidden" name="mod_action" value="<?php echo $this->data->get('url_action');?>"> <input type="hidden" name="ged" value="<?php echo $this->data->get('url_ged');?>"> <div class="maj-table"> <div class="maj-row"> <div class="label"><?php echo I18N::translate('Choose generation') ?></div> </div> <div class="maj-row"> <div class="value"> <select name="gen"> <?php for($i=$this->data->get('min_gen'); $i <= $max_gen;$i++) {?> <option value="<?php echo $i; ?>" <?php if($selectedgen && $selectedgen==$i) { ?> selected="true" <?php } ?> ><?php echo I18N::translate('Generation %d', $i); ?> </option> <?php } ?> </select> </div> </div> </div> <input type="submit" value="<?php echo I18N::translate('Show');?>" /> <br /> </form> <?php if($selectedgen > 0) { ?> <h4> <?php if($selectedgen > $this->data->get('min_gen')) { ?> <a href="module.php?mod=<?php echo $this->data->get('url_module');?>&mod_action=<?php echo $this->data->get('url_action');?>&ged=<?php echo $this->data->get('url_ged');?>&gen=<?php echo $selectedgen-1; ?>"> <i class="icon-ldarrow" title="<?php echo I18N::translate('Previous generation'); ?>" ></i> </a> &nbsp;&nbsp; <?php } ?> <?php echo I18N::translate('Generation %d', $selectedgen); ?> <?php if($selectedgen < $max_gen) { ?> &nbsp;&nbsp; <a href="module.php?mod=<?php echo $this->data->get('url_module');?>&mod_action=<?php echo $this->data->get('url_action');?>&ged=<?php echo $this->data->get('url_ged');?>&gen=<?php echo $selectedgen+1; ?>"> <i class="icon-rdarrow" title="<?php echo I18N::translate('Next generation'); ?>" ></i> </a> <?php } ?> </h4> <?php } }
[ "protected", "function", "renderSosaHeader", "(", ")", "{", "$", "selectedgen", "=", "$", "this", "->", "data", "->", "get", "(", "'generation'", ")", ";", "$", "max_gen", "=", "$", "this", "->", "data", "->", "get", "(", "'max_gen'", ")", ";", "?>\n \n \t<form method=\"get\" name=\"setgen\" action=\"module.php\">\n\t\t\t<input type=\"hidden\" name=\"mod\" value=\"<?php", "echo", "$", "this", "->", "data", "->", "get", "(", "'url_module'", ")", ";", "?>\">\n\t\t\t<input type=\"hidden\" name=\"mod_action\" value=\"<?php", "echo", "$", "this", "->", "data", "->", "get", "(", "'url_action'", ")", ";", "?>\">\n\t\t\t<input type=\"hidden\" name=\"ged\" value=\"<?php", "echo", "$", "this", "->", "data", "->", "get", "(", "'url_ged'", ")", ";", "?>\">\n\t\t\t<div class=\"maj-table\">\n\t\t\t\t<div class=\"maj-row\">\n\t\t\t\t\t<div class=\"label\"><?php", "echo", "I18N", "::", "translate", "(", "'Choose generation'", ")", "?></div>\n\t\t\t\t</div>\n\t\t\t\t<div class=\"maj-row\">\n\t\t\t\t\t<div class=\"value\">\n\t\t\t\t\t\t<select name=\"gen\">\t\t\t\t\t\t\t\n\t\t\t\t\t\t<?php", "for", "(", "$", "i", "=", "$", "this", "->", "data", "->", "get", "(", "'min_gen'", ")", ";", "$", "i", "<=", "$", "max_gen", ";", "$", "i", "++", ")", "{", "?>\n\t\t\t\t\t\t\t<option value=\"<?php", "echo", "$", "i", ";", "?>\"\n\t\t\t\t\t\t\t<?php", "if", "(", "$", "selectedgen", "&&", "$", "selectedgen", "==", "$", "i", ")", "{", "?> selected=\"true\" <?php", "}", "?>\n \t\t\t><?php", "echo", "I18N", "::", "translate", "(", "'Generation %d'", ",", "$", "i", ")", ";", "?>\n \t\t\t</option>\n \t\t<?php", "}", "?>\n \t\t</select>\n \t</div>\n </div>\n \t\t</div>\n \t\t<input type=\"submit\" value=\"<?php", "echo", "I18N", "::", "translate", "(", "'Show'", ")", ";", "?>\" />\n \t\t<br />\n \t</form>\n \t<?php", "if", "(", "$", "selectedgen", ">", "0", ")", "{", "?>\n\t\t<h4>\n\t\t\t<?php", "if", "(", "$", "selectedgen", ">", "$", "this", "->", "data", "->", "get", "(", "'min_gen'", ")", ")", "{", "?>\n\t\t\t<a href=\"module.php?mod=<?php", "echo", "$", "this", "->", "data", "->", "get", "(", "'url_module'", ")", ";", "?>&mod_action=<?php", "echo", "$", "this", "->", "data", "->", "get", "(", "'url_action'", ")", ";", "?>&ged=<?php", "echo", "$", "this", "->", "data", "->", "get", "(", "'url_ged'", ")", ";", "?>&gen=<?php", "echo", "$", "selectedgen", "-", "1", ";", "?>\">\n\t\t\t\t<i class=\"icon-ldarrow\" title=\"<?php", "echo", "I18N", "::", "translate", "(", "'Previous generation'", ")", ";", "?>\" ></i>\n\t\t\t</a>\n\t\t\t&nbsp;&nbsp;\n\t\t\t<?php", "}", "?>\n\t\t\t<?php", "echo", "I18N", "::", "translate", "(", "'Generation %d'", ",", "$", "selectedgen", ")", ";", "?>\n\t\t\t<?php", "if", "(", "$", "selectedgen", "<", "$", "max_gen", ")", "{", "?>\n\t\t\t&nbsp;&nbsp;\n\t\t\t<a href=\"module.php?mod=<?php", "echo", "$", "this", "->", "data", "->", "get", "(", "'url_module'", ")", ";", "?>&mod_action=<?php", "echo", "$", "this", "->", "data", "->", "get", "(", "'url_action'", ")", ";", "?>&ged=<?php", "echo", "$", "this", "->", "data", "->", "get", "(", "'url_ged'", ")", ";", "?>&gen=<?php", "echo", "$", "selectedgen", "+", "1", ";", "?>\">\n\t\t\t\t<i class=\"icon-rdarrow\" title=\"<?php", "echo", "I18N", "::", "translate", "(", "'Next generation'", ")", ";", "?>\" ></i>\n\t\t\t</a>\n\t\t\t<?php", "}", "?>\n\t\t</h4>\n\t\t\n\t\t<?php", "}", "}" ]
Render the common header to Sosa Lists, made of the generation selector, and the generation navigator
[ "Render", "the", "common", "header", "to", "Sosa", "Lists", "made", "of", "the", "generation", "selector", "and", "the", "generation", "navigator" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/Sosa/Views/SosaListView.php#L71-L119
34,674
nails/module-cdn
admin/controllers/Manager.php
Manager.index
public function index() { if (!userHasPermission('admin:cdn:manager:object:browse')) { unauthorised(); } $oInput = Factory::service('Input'); $this->data['sBucketSlug'] = $oInput->get('bucket'); $oAsset = Factory::service('Asset'); $oAsset->library('KNOCKOUT'); // @todo (Pablo - 2018-12-01) - Update/Remove/Use minified once JS is refactored to be a module $oAsset->load('admin.mediamanager.js', 'nails/module-cdn'); $sBucketSlug = $oInput->get('bucket'); $sCallbackHandler = $oInput->get('CKEditor') ? 'ckeditor' : 'picker'; if ($sCallbackHandler === 'ckeditor') { $aCallback = [$oInput->get('CKEditorFuncNum')]; } else { $aCallback = array_filter((array) $oInput->get('callback')); } $oAsset->inline( 'ko.applyBindings( new MediaManager( "' . $sBucketSlug . '", "' . $sCallbackHandler . '", ' . json_encode($aCallback) . ', ' . json_encode((bool) $oInput->get('isModal')) . ' ) );', 'JS' ); Helper::loadView('index'); }
php
public function index() { if (!userHasPermission('admin:cdn:manager:object:browse')) { unauthorised(); } $oInput = Factory::service('Input'); $this->data['sBucketSlug'] = $oInput->get('bucket'); $oAsset = Factory::service('Asset'); $oAsset->library('KNOCKOUT'); // @todo (Pablo - 2018-12-01) - Update/Remove/Use minified once JS is refactored to be a module $oAsset->load('admin.mediamanager.js', 'nails/module-cdn'); $sBucketSlug = $oInput->get('bucket'); $sCallbackHandler = $oInput->get('CKEditor') ? 'ckeditor' : 'picker'; if ($sCallbackHandler === 'ckeditor') { $aCallback = [$oInput->get('CKEditorFuncNum')]; } else { $aCallback = array_filter((array) $oInput->get('callback')); } $oAsset->inline( 'ko.applyBindings( new MediaManager( "' . $sBucketSlug . '", "' . $sCallbackHandler . '", ' . json_encode($aCallback) . ', ' . json_encode((bool) $oInput->get('isModal')) . ' ) );', 'JS' ); Helper::loadView('index'); }
[ "public", "function", "index", "(", ")", "{", "if", "(", "!", "userHasPermission", "(", "'admin:cdn:manager:object:browse'", ")", ")", "{", "unauthorised", "(", ")", ";", "}", "$", "oInput", "=", "Factory", "::", "service", "(", "'Input'", ")", ";", "$", "this", "->", "data", "[", "'sBucketSlug'", "]", "=", "$", "oInput", "->", "get", "(", "'bucket'", ")", ";", "$", "oAsset", "=", "Factory", "::", "service", "(", "'Asset'", ")", ";", "$", "oAsset", "->", "library", "(", "'KNOCKOUT'", ")", ";", "// @todo (Pablo - 2018-12-01) - Update/Remove/Use minified once JS is refactored to be a module", "$", "oAsset", "->", "load", "(", "'admin.mediamanager.js'", ",", "'nails/module-cdn'", ")", ";", "$", "sBucketSlug", "=", "$", "oInput", "->", "get", "(", "'bucket'", ")", ";", "$", "sCallbackHandler", "=", "$", "oInput", "->", "get", "(", "'CKEditor'", ")", "?", "'ckeditor'", ":", "'picker'", ";", "if", "(", "$", "sCallbackHandler", "===", "'ckeditor'", ")", "{", "$", "aCallback", "=", "[", "$", "oInput", "->", "get", "(", "'CKEditorFuncNum'", ")", "]", ";", "}", "else", "{", "$", "aCallback", "=", "array_filter", "(", "(", "array", ")", "$", "oInput", "->", "get", "(", "'callback'", ")", ")", ";", "}", "$", "oAsset", "->", "inline", "(", "'ko.applyBindings(\n new MediaManager(\n \"'", ".", "$", "sBucketSlug", ".", "'\",\n \"'", ".", "$", "sCallbackHandler", ".", "'\",\n '", ".", "json_encode", "(", "$", "aCallback", ")", ".", "',\n '", ".", "json_encode", "(", "(", "bool", ")", "$", "oInput", "->", "get", "(", "'isModal'", ")", ")", ".", "'\n )\n );'", ",", "'JS'", ")", ";", "Helper", "::", "loadView", "(", "'index'", ")", ";", "}" ]
Browse CDN Objects @return void
[ "Browse", "CDN", "Objects" ]
1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef
https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/admin/controllers/Manager.php#L62-L98
34,675
RobinDev/PHPToJS
src/PHPToJS.php
PHPToJS.render
public static function render($mixed) { if (!is_array($mixed) && !is_object($mixed)) { return strpos(str_replace(' ', '', $mixed), 'function(') === 0 ? $mixed : json_encode($mixed); } $isNumArr = array_keys((array) $mixed) === range(0, count((array) $mixed) - 1); $isObject = is_object($mixed) || (!$isNumArr && !empty($mixed)); $r = array(); $i = 0; foreach ($mixed as $k => $m) { $r[$i] = ($isObject ? self::renderObjectKey($k).':' : '').self::render($m); ++$i; } return ($isObject ? '{' : '[').implode(',', $r).($isObject ? '}' : ']'); }
php
public static function render($mixed) { if (!is_array($mixed) && !is_object($mixed)) { return strpos(str_replace(' ', '', $mixed), 'function(') === 0 ? $mixed : json_encode($mixed); } $isNumArr = array_keys((array) $mixed) === range(0, count((array) $mixed) - 1); $isObject = is_object($mixed) || (!$isNumArr && !empty($mixed)); $r = array(); $i = 0; foreach ($mixed as $k => $m) { $r[$i] = ($isObject ? self::renderObjectKey($k).':' : '').self::render($m); ++$i; } return ($isObject ? '{' : '[').implode(',', $r).($isObject ? '}' : ']'); }
[ "public", "static", "function", "render", "(", "$", "mixed", ")", "{", "if", "(", "!", "is_array", "(", "$", "mixed", ")", "&&", "!", "is_object", "(", "$", "mixed", ")", ")", "{", "return", "strpos", "(", "str_replace", "(", "' '", ",", "''", ",", "$", "mixed", ")", ",", "'function('", ")", "===", "0", "?", "$", "mixed", ":", "json_encode", "(", "$", "mixed", ")", ";", "}", "$", "isNumArr", "=", "array_keys", "(", "(", "array", ")", "$", "mixed", ")", "===", "range", "(", "0", ",", "count", "(", "(", "array", ")", "$", "mixed", ")", "-", "1", ")", ";", "$", "isObject", "=", "is_object", "(", "$", "mixed", ")", "||", "(", "!", "$", "isNumArr", "&&", "!", "empty", "(", "$", "mixed", ")", ")", ";", "$", "r", "=", "array", "(", ")", ";", "$", "i", "=", "0", ";", "foreach", "(", "$", "mixed", "as", "$", "k", "=>", "$", "m", ")", "{", "$", "r", "[", "$", "i", "]", "=", "(", "$", "isObject", "?", "self", "::", "renderObjectKey", "(", "$", "k", ")", ".", "':'", ":", "''", ")", ".", "self", "::", "render", "(", "$", "m", ")", ";", "++", "$", "i", ";", "}", "return", "(", "$", "isObject", "?", "'{'", ":", "'['", ")", ".", "implode", "(", "','", ",", "$", "r", ")", ".", "(", "$", "isObject", "?", "'}'", ":", "']'", ")", ";", "}" ]
Render the variable's content from PHP to Javascript @param mixed $mixed @return string Javascript code
[ "Render", "the", "variable", "s", "content", "from", "PHP", "to", "Javascript" ]
e2ea20b2d75478fb40352be06e69704488a248a1
https://github.com/RobinDev/PHPToJS/blob/e2ea20b2d75478fb40352be06e69704488a248a1/src/PHPToJS.php#L22-L39
34,676
jon48/webtrees-lib
src/Webtrees/Module/WelcomeBlock/PiwikController.php
PiwikController.getNumberOfVisitsPiwik
private function getNumberOfVisitsPiwik($block_id, $period='year'){ $piwik_url = $this->module->getBlockSetting($block_id, 'piwik_url'); $piwik_siteid = $this->module->getBlockSetting($block_id, 'piwik_siteid'); $piwik_token = $this->module->getBlockSetting($block_id, 'piwik_token'); if($piwik_url && strlen($piwik_url) > 0 && $piwik_siteid && strlen($piwik_siteid) > 0 && $piwik_token && strlen($piwik_token) ) { // calling Piwik REST API $url = $piwik_url; $url .= '?module=API&method=VisitsSummary.getVisits'; $url .= '&idSite='.$piwik_siteid.'&period='.$period.'&date=today'; $url .= '&format=PHP'; $url .= '&token_auth='.$piwik_token; if($fetched = File::fetchUrl($url)) { $content = @unserialize($fetched); if(is_numeric($content)) return $content; } } return null; }
php
private function getNumberOfVisitsPiwik($block_id, $period='year'){ $piwik_url = $this->module->getBlockSetting($block_id, 'piwik_url'); $piwik_siteid = $this->module->getBlockSetting($block_id, 'piwik_siteid'); $piwik_token = $this->module->getBlockSetting($block_id, 'piwik_token'); if($piwik_url && strlen($piwik_url) > 0 && $piwik_siteid && strlen($piwik_siteid) > 0 && $piwik_token && strlen($piwik_token) ) { // calling Piwik REST API $url = $piwik_url; $url .= '?module=API&method=VisitsSummary.getVisits'; $url .= '&idSite='.$piwik_siteid.'&period='.$period.'&date=today'; $url .= '&format=PHP'; $url .= '&token_auth='.$piwik_token; if($fetched = File::fetchUrl($url)) { $content = @unserialize($fetched); if(is_numeric($content)) return $content; } } return null; }
[ "private", "function", "getNumberOfVisitsPiwik", "(", "$", "block_id", ",", "$", "period", "=", "'year'", ")", "{", "$", "piwik_url", "=", "$", "this", "->", "module", "->", "getBlockSetting", "(", "$", "block_id", ",", "'piwik_url'", ")", ";", "$", "piwik_siteid", "=", "$", "this", "->", "module", "->", "getBlockSetting", "(", "$", "block_id", ",", "'piwik_siteid'", ")", ";", "$", "piwik_token", "=", "$", "this", "->", "module", "->", "getBlockSetting", "(", "$", "block_id", ",", "'piwik_token'", ")", ";", "if", "(", "$", "piwik_url", "&&", "strlen", "(", "$", "piwik_url", ")", ">", "0", "&&", "$", "piwik_siteid", "&&", "strlen", "(", "$", "piwik_siteid", ")", ">", "0", "&&", "$", "piwik_token", "&&", "strlen", "(", "$", "piwik_token", ")", ")", "{", "// calling Piwik REST API", "$", "url", "=", "$", "piwik_url", ";", "$", "url", ".=", "'?module=API&method=VisitsSummary.getVisits'", ";", "$", "url", ".=", "'&idSite='", ".", "$", "piwik_siteid", ".", "'&period='", ".", "$", "period", ".", "'&date=today'", ";", "$", "url", ".=", "'&format=PHP'", ";", "$", "url", ".=", "'&token_auth='", ".", "$", "piwik_token", ";", "if", "(", "$", "fetched", "=", "File", "::", "fetchUrl", "(", "$", "url", ")", ")", "{", "$", "content", "=", "@", "unserialize", "(", "$", "fetched", ")", ";", "if", "(", "is_numeric", "(", "$", "content", ")", ")", "return", "$", "content", ";", "}", "}", "return", "null", ";", "}" ]
Retrieve the number of visitors from Piwik, for a given period. @param string $block_id @param string $period @param (null|int) Number of visits
[ "Retrieve", "the", "number", "of", "visitors", "from", "Piwik", "for", "a", "given", "period", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/WelcomeBlock/PiwikController.php#L33-L58
34,677
jon48/webtrees-lib
src/Webtrees/Module/PatronymicLineage/Model/LineageBuilder.php
LineageBuilder.buildLineages
public function buildLineages() { $indis = \Fisharebest\Webtrees\Query\QueryName::individuals($this->tree, $this->surname, null, null, false, false); if(count($indis) == 0) return null; $root_lineages = array(); foreach($indis as $indi) { $pid = $indi->getXref(); if(!isset($this->used_indis[$pid])){ //Find the root of the lineage /** @var Fisharebest\Webtrees\Individual $indiFirst */ $indiFirst= $this->getLineageRootIndividual($indi); if($indiFirst){ $this->used_indis[$indiFirst->getXref()] = true; if($indiFirst->canShow()){ //Check if the root individual has brothers and sisters, without parents $indiChildFamily = $indiFirst->getPrimaryChildFamily(); if($indiChildFamily !== null){ $root_node = new LineageRootNode(null); $root_node->addFamily($indiChildFamily); } else{ $root_node = new LineageRootNode($indiFirst); } $root_node = $this->buildLineage($root_node); if($root_node) $root_lineages[] = $root_node; } } } } return $root_lineages; }
php
public function buildLineages() { $indis = \Fisharebest\Webtrees\Query\QueryName::individuals($this->tree, $this->surname, null, null, false, false); if(count($indis) == 0) return null; $root_lineages = array(); foreach($indis as $indi) { $pid = $indi->getXref(); if(!isset($this->used_indis[$pid])){ //Find the root of the lineage /** @var Fisharebest\Webtrees\Individual $indiFirst */ $indiFirst= $this->getLineageRootIndividual($indi); if($indiFirst){ $this->used_indis[$indiFirst->getXref()] = true; if($indiFirst->canShow()){ //Check if the root individual has brothers and sisters, without parents $indiChildFamily = $indiFirst->getPrimaryChildFamily(); if($indiChildFamily !== null){ $root_node = new LineageRootNode(null); $root_node->addFamily($indiChildFamily); } else{ $root_node = new LineageRootNode($indiFirst); } $root_node = $this->buildLineage($root_node); if($root_node) $root_lineages[] = $root_node; } } } } return $root_lineages; }
[ "public", "function", "buildLineages", "(", ")", "{", "$", "indis", "=", "\\", "Fisharebest", "\\", "Webtrees", "\\", "Query", "\\", "QueryName", "::", "individuals", "(", "$", "this", "->", "tree", ",", "$", "this", "->", "surname", ",", "null", ",", "null", ",", "false", ",", "false", ")", ";", "if", "(", "count", "(", "$", "indis", ")", "==", "0", ")", "return", "null", ";", "$", "root_lineages", "=", "array", "(", ")", ";", "foreach", "(", "$", "indis", "as", "$", "indi", ")", "{", "$", "pid", "=", "$", "indi", "->", "getXref", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "used_indis", "[", "$", "pid", "]", ")", ")", "{", "//Find the root of the lineage", "/** @var Fisharebest\\Webtrees\\Individual $indiFirst */", "$", "indiFirst", "=", "$", "this", "->", "getLineageRootIndividual", "(", "$", "indi", ")", ";", "if", "(", "$", "indiFirst", ")", "{", "$", "this", "->", "used_indis", "[", "$", "indiFirst", "->", "getXref", "(", ")", "]", "=", "true", ";", "if", "(", "$", "indiFirst", "->", "canShow", "(", ")", ")", "{", "//Check if the root individual has brothers and sisters, without parents", "$", "indiChildFamily", "=", "$", "indiFirst", "->", "getPrimaryChildFamily", "(", ")", ";", "if", "(", "$", "indiChildFamily", "!==", "null", ")", "{", "$", "root_node", "=", "new", "LineageRootNode", "(", "null", ")", ";", "$", "root_node", "->", "addFamily", "(", "$", "indiChildFamily", ")", ";", "}", "else", "{", "$", "root_node", "=", "new", "LineageRootNode", "(", "$", "indiFirst", ")", ";", "}", "$", "root_node", "=", "$", "this", "->", "buildLineage", "(", "$", "root_node", ")", ";", "if", "(", "$", "root_node", ")", "$", "root_lineages", "[", "]", "=", "$", "root_node", ";", "}", "}", "}", "}", "return", "$", "root_lineages", ";", "}" ]
Build all patronymic lineages for the reference surname. @return array List of root patronymic lineages
[ "Build", "all", "patronymic", "lineages", "for", "the", "reference", "surname", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/PatronymicLineage/Model/LineageBuilder.php#L54-L87
34,678
jon48/webtrees-lib
src/Webtrees/Module/PatronymicLineage/Model/LineageBuilder.php
LineageBuilder.getLineageRootIndividual
protected function getLineageRootIndividual(Individual $indi) { $is_first=false; $dindi = new \MyArtJaub\Webtrees\Individual($indi); $indi_surname=$dindi->getUnprotectedPrimarySurname(); $resIndi = $indi; while(!$is_first){ //Get the individual parents family $fam=$resIndi->getPrimaryChildFamily(); if($fam){ $husb=$fam->getHusband(); $wife=$fam->getWife(); //If the father exists, take him if($husb){ $dhusb = new \MyArtJaub\Webtrees\Individual($husb); $dhusb->isNewAddition() ? $is_first = true : $resIndi=$husb; } //If only a mother exists else if($wife){ $dwife = new \MyArtJaub\Webtrees\Individual($wife); $wife_surname=$dwife->getUnprotectedPrimarySurname(); //Check if the child is a natural child of the mother (based on the surname - Warning : surname must be identical) if(!$dwife->isNewAddition() && I18N::strcasecmp($wife_surname, $indi_surname) == 0){ $resIndi=$wife; } else{ $is_first=true; } } else{ $is_first=true; } } else{ $is_first=true; } } if(isset($this->used_indis[$resIndi->getXref()])){ return null; } else{ return $resIndi; } }
php
protected function getLineageRootIndividual(Individual $indi) { $is_first=false; $dindi = new \MyArtJaub\Webtrees\Individual($indi); $indi_surname=$dindi->getUnprotectedPrimarySurname(); $resIndi = $indi; while(!$is_first){ //Get the individual parents family $fam=$resIndi->getPrimaryChildFamily(); if($fam){ $husb=$fam->getHusband(); $wife=$fam->getWife(); //If the father exists, take him if($husb){ $dhusb = new \MyArtJaub\Webtrees\Individual($husb); $dhusb->isNewAddition() ? $is_first = true : $resIndi=$husb; } //If only a mother exists else if($wife){ $dwife = new \MyArtJaub\Webtrees\Individual($wife); $wife_surname=$dwife->getUnprotectedPrimarySurname(); //Check if the child is a natural child of the mother (based on the surname - Warning : surname must be identical) if(!$dwife->isNewAddition() && I18N::strcasecmp($wife_surname, $indi_surname) == 0){ $resIndi=$wife; } else{ $is_first=true; } } else{ $is_first=true; } } else{ $is_first=true; } } if(isset($this->used_indis[$resIndi->getXref()])){ return null; } else{ return $resIndi; } }
[ "protected", "function", "getLineageRootIndividual", "(", "Individual", "$", "indi", ")", "{", "$", "is_first", "=", "false", ";", "$", "dindi", "=", "new", "\\", "MyArtJaub", "\\", "Webtrees", "\\", "Individual", "(", "$", "indi", ")", ";", "$", "indi_surname", "=", "$", "dindi", "->", "getUnprotectedPrimarySurname", "(", ")", ";", "$", "resIndi", "=", "$", "indi", ";", "while", "(", "!", "$", "is_first", ")", "{", "//Get the individual parents family", "$", "fam", "=", "$", "resIndi", "->", "getPrimaryChildFamily", "(", ")", ";", "if", "(", "$", "fam", ")", "{", "$", "husb", "=", "$", "fam", "->", "getHusband", "(", ")", ";", "$", "wife", "=", "$", "fam", "->", "getWife", "(", ")", ";", "//If the father exists, take him", "if", "(", "$", "husb", ")", "{", "$", "dhusb", "=", "new", "\\", "MyArtJaub", "\\", "Webtrees", "\\", "Individual", "(", "$", "husb", ")", ";", "$", "dhusb", "->", "isNewAddition", "(", ")", "?", "$", "is_first", "=", "true", ":", "$", "resIndi", "=", "$", "husb", ";", "}", "//If only a mother exists", "else", "if", "(", "$", "wife", ")", "{", "$", "dwife", "=", "new", "\\", "MyArtJaub", "\\", "Webtrees", "\\", "Individual", "(", "$", "wife", ")", ";", "$", "wife_surname", "=", "$", "dwife", "->", "getUnprotectedPrimarySurname", "(", ")", ";", "//Check if the child is a natural child of the mother (based on the surname - Warning : surname must be identical)", "if", "(", "!", "$", "dwife", "->", "isNewAddition", "(", ")", "&&", "I18N", "::", "strcasecmp", "(", "$", "wife_surname", ",", "$", "indi_surname", ")", "==", "0", ")", "{", "$", "resIndi", "=", "$", "wife", ";", "}", "else", "{", "$", "is_first", "=", "true", ";", "}", "}", "else", "{", "$", "is_first", "=", "true", ";", "}", "}", "else", "{", "$", "is_first", "=", "true", ";", "}", "}", "if", "(", "isset", "(", "$", "this", "->", "used_indis", "[", "$", "resIndi", "->", "getXref", "(", ")", "]", ")", ")", "{", "return", "null", ";", "}", "else", "{", "return", "$", "resIndi", ";", "}", "}" ]
Retrieve the root individual, from any individual. The Root individual is the individual without a father, or without a mother holding the same name. @param Individual $indi @return (Individual|null) Root individual
[ "Retrieve", "the", "root", "individual", "from", "any", "individual", ".", "The", "Root", "individual", "is", "the", "individual", "without", "a", "father", "or", "without", "a", "mother", "holding", "the", "same", "name", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/PatronymicLineage/Model/LineageBuilder.php#L96-L138
34,679
CESNET/perun-simplesamlphp-module
lib/Auth/Process/PerunIdentity.php
PerunIdentity.register
public function register($request, $vosForRegistration, $registerUrL = null, $dynamicRegistration = null) { if (is_null($registerUrL)) { $registerUrL = $this->registerUrl; } if (is_null($dynamicRegistration)) { $dynamicRegistration = $this->dynamicRegistration; } $request['config'] = array( self::UIDS_ATTR => $this->uidsAttr, self::REGISTER_URL => $registerUrL, self::REGISTER_URL_BASE => $this->registerUrlBase, self::INTERFACE_PROPNAME => $this->interface, self::SOURCE_IDP_ENTITY_ID_ATTR => $this->sourceIdPEntityIDAttr, self::VO_SHORTNAME => $this->voShortName, self::PERUN_FACILITY_ALLOW_REGISTRATION_TO_GROUPS => $this->facilityAllowRegistrationToGroupsAttr, self::PERUN_FACILITY_CHECK_GROUP_MEMBERSHIP_ATTR => $this->facilityCheckGroupMembershipAttr, self::PERUN_FACILITY_DYNAMIC_REGISTRATION_ATTR => $this->facilityDynamicRegistrationAttr, self::PERUN_FACILITY_REGISTER_URL_ATTR => $this->facilityRegisterUrlAttr, self::PERUN_FACILITY_VO_SHORT_NAMES_ATTR => $this->facilityVoShortNamesAttr, ); $stateId = State::saveState($request, 'perun:PerunIdentity'); $callback = Module::getModuleURL('perun/perun_identity_callback.php', array('stateId' => $stateId)); if ($dynamicRegistration) { $this->registerChooseVoAndGroup($callback, $vosForRegistration, $request); } else { $this->registerDirectly($request, $callback, $registerUrL); } }
php
public function register($request, $vosForRegistration, $registerUrL = null, $dynamicRegistration = null) { if (is_null($registerUrL)) { $registerUrL = $this->registerUrl; } if (is_null($dynamicRegistration)) { $dynamicRegistration = $this->dynamicRegistration; } $request['config'] = array( self::UIDS_ATTR => $this->uidsAttr, self::REGISTER_URL => $registerUrL, self::REGISTER_URL_BASE => $this->registerUrlBase, self::INTERFACE_PROPNAME => $this->interface, self::SOURCE_IDP_ENTITY_ID_ATTR => $this->sourceIdPEntityIDAttr, self::VO_SHORTNAME => $this->voShortName, self::PERUN_FACILITY_ALLOW_REGISTRATION_TO_GROUPS => $this->facilityAllowRegistrationToGroupsAttr, self::PERUN_FACILITY_CHECK_GROUP_MEMBERSHIP_ATTR => $this->facilityCheckGroupMembershipAttr, self::PERUN_FACILITY_DYNAMIC_REGISTRATION_ATTR => $this->facilityDynamicRegistrationAttr, self::PERUN_FACILITY_REGISTER_URL_ATTR => $this->facilityRegisterUrlAttr, self::PERUN_FACILITY_VO_SHORT_NAMES_ATTR => $this->facilityVoShortNamesAttr, ); $stateId = State::saveState($request, 'perun:PerunIdentity'); $callback = Module::getModuleURL('perun/perun_identity_callback.php', array('stateId' => $stateId)); if ($dynamicRegistration) { $this->registerChooseVoAndGroup($callback, $vosForRegistration, $request); } else { $this->registerDirectly($request, $callback, $registerUrL); } }
[ "public", "function", "register", "(", "$", "request", ",", "$", "vosForRegistration", ",", "$", "registerUrL", "=", "null", ",", "$", "dynamicRegistration", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "registerUrL", ")", ")", "{", "$", "registerUrL", "=", "$", "this", "->", "registerUrl", ";", "}", "if", "(", "is_null", "(", "$", "dynamicRegistration", ")", ")", "{", "$", "dynamicRegistration", "=", "$", "this", "->", "dynamicRegistration", ";", "}", "$", "request", "[", "'config'", "]", "=", "array", "(", "self", "::", "UIDS_ATTR", "=>", "$", "this", "->", "uidsAttr", ",", "self", "::", "REGISTER_URL", "=>", "$", "registerUrL", ",", "self", "::", "REGISTER_URL_BASE", "=>", "$", "this", "->", "registerUrlBase", ",", "self", "::", "INTERFACE_PROPNAME", "=>", "$", "this", "->", "interface", ",", "self", "::", "SOURCE_IDP_ENTITY_ID_ATTR", "=>", "$", "this", "->", "sourceIdPEntityIDAttr", ",", "self", "::", "VO_SHORTNAME", "=>", "$", "this", "->", "voShortName", ",", "self", "::", "PERUN_FACILITY_ALLOW_REGISTRATION_TO_GROUPS", "=>", "$", "this", "->", "facilityAllowRegistrationToGroupsAttr", ",", "self", "::", "PERUN_FACILITY_CHECK_GROUP_MEMBERSHIP_ATTR", "=>", "$", "this", "->", "facilityCheckGroupMembershipAttr", ",", "self", "::", "PERUN_FACILITY_DYNAMIC_REGISTRATION_ATTR", "=>", "$", "this", "->", "facilityDynamicRegistrationAttr", ",", "self", "::", "PERUN_FACILITY_REGISTER_URL_ATTR", "=>", "$", "this", "->", "facilityRegisterUrlAttr", ",", "self", "::", "PERUN_FACILITY_VO_SHORT_NAMES_ATTR", "=>", "$", "this", "->", "facilityVoShortNamesAttr", ",", ")", ";", "$", "stateId", "=", "State", "::", "saveState", "(", "$", "request", ",", "'perun:PerunIdentity'", ")", ";", "$", "callback", "=", "Module", "::", "getModuleURL", "(", "'perun/perun_identity_callback.php'", ",", "array", "(", "'stateId'", "=>", "$", "stateId", ")", ")", ";", "if", "(", "$", "dynamicRegistration", ")", "{", "$", "this", "->", "registerChooseVoAndGroup", "(", "$", "callback", ",", "$", "vosForRegistration", ",", "$", "request", ")", ";", "}", "else", "{", "$", "this", "->", "registerDirectly", "(", "$", "request", ",", "$", "callback", ",", "$", "registerUrL", ")", ";", "}", "}" ]
Method for register user to Perun @param $request @param $vosForRegistration @param string $registerUrL @param bool $dynamicRegistration
[ "Method", "for", "register", "user", "to", "Perun" ]
f1d686f06472053a7cdb31f2b2776f9714779ee1
https://github.com/CESNET/perun-simplesamlphp-module/blob/f1d686f06472053a7cdb31f2b2776f9714779ee1/lib/Auth/Process/PerunIdentity.php#L262-L294
34,680
CESNET/perun-simplesamlphp-module
lib/Auth/Process/PerunIdentity.php
PerunIdentity.registerDirectly
protected function registerDirectly($request, $callback, $registerUrL, $vo = null, $group = null) { $params = array(); if (!is_null($vo)) { $params['vo'] = $vo->getShortName(); if (!is_null($group)) { $params['group'] = $group->getName(); } } $params[self::TARGET_NEW] = $callback; $params[self::TARGET_EXISTING] = $callback; $params[self::TARGET_EXTENDED] = $callback; $id = State::saveState($request, 'perun:PerunIdentity'); if (in_array($this->spEntityId, $this->listOfSpsWithoutInfoAboutRedirection)) { HTTP::redirectTrustedURL($registerUrL, $params); } $url = Module::getModuleURL('perun/unauthorized_access_go_to_registration.php'); HTTP::redirectTrustedURL( $url, array( 'StateId' => $id, 'SPMetadata' => $request['SPMetadata'], 'registerUrL' => $registerUrL, 'params' => $params ) ); }
php
protected function registerDirectly($request, $callback, $registerUrL, $vo = null, $group = null) { $params = array(); if (!is_null($vo)) { $params['vo'] = $vo->getShortName(); if (!is_null($group)) { $params['group'] = $group->getName(); } } $params[self::TARGET_NEW] = $callback; $params[self::TARGET_EXISTING] = $callback; $params[self::TARGET_EXTENDED] = $callback; $id = State::saveState($request, 'perun:PerunIdentity'); if (in_array($this->spEntityId, $this->listOfSpsWithoutInfoAboutRedirection)) { HTTP::redirectTrustedURL($registerUrL, $params); } $url = Module::getModuleURL('perun/unauthorized_access_go_to_registration.php'); HTTP::redirectTrustedURL( $url, array( 'StateId' => $id, 'SPMetadata' => $request['SPMetadata'], 'registerUrL' => $registerUrL, 'params' => $params ) ); }
[ "protected", "function", "registerDirectly", "(", "$", "request", ",", "$", "callback", ",", "$", "registerUrL", ",", "$", "vo", "=", "null", ",", "$", "group", "=", "null", ")", "{", "$", "params", "=", "array", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "vo", ")", ")", "{", "$", "params", "[", "'vo'", "]", "=", "$", "vo", "->", "getShortName", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "group", ")", ")", "{", "$", "params", "[", "'group'", "]", "=", "$", "group", "->", "getName", "(", ")", ";", "}", "}", "$", "params", "[", "self", "::", "TARGET_NEW", "]", "=", "$", "callback", ";", "$", "params", "[", "self", "::", "TARGET_EXISTING", "]", "=", "$", "callback", ";", "$", "params", "[", "self", "::", "TARGET_EXTENDED", "]", "=", "$", "callback", ";", "$", "id", "=", "State", "::", "saveState", "(", "$", "request", ",", "'perun:PerunIdentity'", ")", ";", "if", "(", "in_array", "(", "$", "this", "->", "spEntityId", ",", "$", "this", "->", "listOfSpsWithoutInfoAboutRedirection", ")", ")", "{", "HTTP", "::", "redirectTrustedURL", "(", "$", "registerUrL", ",", "$", "params", ")", ";", "}", "$", "url", "=", "Module", "::", "getModuleURL", "(", "'perun/unauthorized_access_go_to_registration.php'", ")", ";", "HTTP", "::", "redirectTrustedURL", "(", "$", "url", ",", "array", "(", "'StateId'", "=>", "$", "id", ",", "'SPMetadata'", "=>", "$", "request", "[", "'SPMetadata'", "]", ",", "'registerUrL'", "=>", "$", "registerUrL", ",", "'params'", "=>", "$", "params", ")", ")", ";", "}" ]
Redirect user to registerUrL @param $request @param string $callback @param string $registerUrL @param Vo|null $vo @param Group|null $group
[ "Redirect", "user", "to", "registerUrL" ]
f1d686f06472053a7cdb31f2b2776f9714779ee1
https://github.com/CESNET/perun-simplesamlphp-module/blob/f1d686f06472053a7cdb31f2b2776f9714779ee1/lib/Auth/Process/PerunIdentity.php#L304-L333
34,681
CESNET/perun-simplesamlphp-module
lib/Auth/Process/PerunIdentity.php
PerunIdentity.registerChooseVoAndGroup
protected function registerChooseVoAndGroup($callback, $vosForRegistration, $request) { $vosId = array(); $chooseGroupUrl = Module::getModuleURL('perun/perun_identity_choose_vo_and_group.php'); $stateId = State::saveState($request, 'perun:PerunIdentity'); foreach ($vosForRegistration as $vo) { array_push($vosId, $vo->getId()); } HTTP::redirectTrustedURL( $chooseGroupUrl, array( self::REGISTER_URL_BASE => $this->registerUrlBase, 'spEntityId' => $this->spEntityId, 'vosIdForRegistration' => $vosId, self::INTERFACE_PROPNAME => $this->interface, 'callbackUrl' => $callback, 'SPMetadata' => $request['SPMetadata'], 'stateId' => $stateId ) ); }
php
protected function registerChooseVoAndGroup($callback, $vosForRegistration, $request) { $vosId = array(); $chooseGroupUrl = Module::getModuleURL('perun/perun_identity_choose_vo_and_group.php'); $stateId = State::saveState($request, 'perun:PerunIdentity'); foreach ($vosForRegistration as $vo) { array_push($vosId, $vo->getId()); } HTTP::redirectTrustedURL( $chooseGroupUrl, array( self::REGISTER_URL_BASE => $this->registerUrlBase, 'spEntityId' => $this->spEntityId, 'vosIdForRegistration' => $vosId, self::INTERFACE_PROPNAME => $this->interface, 'callbackUrl' => $callback, 'SPMetadata' => $request['SPMetadata'], 'stateId' => $stateId ) ); }
[ "protected", "function", "registerChooseVoAndGroup", "(", "$", "callback", ",", "$", "vosForRegistration", ",", "$", "request", ")", "{", "$", "vosId", "=", "array", "(", ")", ";", "$", "chooseGroupUrl", "=", "Module", "::", "getModuleURL", "(", "'perun/perun_identity_choose_vo_and_group.php'", ")", ";", "$", "stateId", "=", "State", "::", "saveState", "(", "$", "request", ",", "'perun:PerunIdentity'", ")", ";", "foreach", "(", "$", "vosForRegistration", "as", "$", "vo", ")", "{", "array_push", "(", "$", "vosId", ",", "$", "vo", "->", "getId", "(", ")", ")", ";", "}", "HTTP", "::", "redirectTrustedURL", "(", "$", "chooseGroupUrl", ",", "array", "(", "self", "::", "REGISTER_URL_BASE", "=>", "$", "this", "->", "registerUrlBase", ",", "'spEntityId'", "=>", "$", "this", "->", "spEntityId", ",", "'vosIdForRegistration'", "=>", "$", "vosId", ",", "self", "::", "INTERFACE_PROPNAME", "=>", "$", "this", "->", "interface", ",", "'callbackUrl'", "=>", "$", "callback", ",", "'SPMetadata'", "=>", "$", "request", "[", "'SPMetadata'", "]", ",", "'stateId'", "=>", "$", "stateId", ")", ")", ";", "}" ]
Redirect user to page with selection Vo and Group for registration @param string $callback @param $vosForRegistration @param $request
[ "Redirect", "user", "to", "page", "with", "selection", "Vo", "and", "Group", "for", "registration" ]
f1d686f06472053a7cdb31f2b2776f9714779ee1
https://github.com/CESNET/perun-simplesamlphp-module/blob/f1d686f06472053a7cdb31f2b2776f9714779ee1/lib/Auth/Process/PerunIdentity.php#L341-L365
34,682
CESNET/perun-simplesamlphp-module
lib/Auth/Process/PerunIdentity.php
PerunIdentity.containsMembersGroup
private function containsMembersGroup($entities) { if (empty($entities)) { return false; } foreach ($entities as $entity) { if (preg_match('/[^:]*:members$/', $entity->getName())) { return true; } } return false; }
php
private function containsMembersGroup($entities) { if (empty($entities)) { return false; } foreach ($entities as $entity) { if (preg_match('/[^:]*:members$/', $entity->getName())) { return true; } } return false; }
[ "private", "function", "containsMembersGroup", "(", "$", "entities", ")", "{", "if", "(", "empty", "(", "$", "entities", ")", ")", "{", "return", "false", ";", "}", "foreach", "(", "$", "entities", "as", "$", "entity", ")", "{", "if", "(", "preg_match", "(", "'/[^:]*:members$/'", ",", "$", "entity", "->", "getName", "(", ")", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Returns true, if entities contains VO members group @param Group[] $entities @return bool
[ "Returns", "true", "if", "entities", "contains", "VO", "members", "group" ]
f1d686f06472053a7cdb31f2b2776f9714779ee1
https://github.com/CESNET/perun-simplesamlphp-module/blob/f1d686f06472053a7cdb31f2b2776f9714779ee1/lib/Auth/Process/PerunIdentity.php#L373-L384
34,683
CESNET/perun-simplesamlphp-module
lib/Auth/Process/PerunIdentity.php
PerunIdentity.getSPAttributes
protected function getSPAttributes($spEntityID) { try { $facilities = $this->rpcAdapter->getFacilitiesByEntityId($spEntityID); if (empty($facilities)) { Logger::warning( "perun:PerunIdentity: No facility with entityID '" . $spEntityID . "' found." ); return; } $checkGroupMembership = $this->rpcAdapter->getFacilityAttribute( $facilities[0], $this->facilityCheckGroupMembershipAttr ); if (!is_null($checkGroupMembership)) { $this->checkGroupMembership = $checkGroupMembership; } $facilityVoShortNames = $this->rpcAdapter->getFacilityAttribute( $facilities[0], $this->facilityVoShortNamesAttr ); if (!empty($facilityVoShortNames)) { $this->facilityVoShortNames = $facilityVoShortNames; } $dynamicRegistration = $this->rpcAdapter->getFacilityAttribute( $facilities[0], $this->facilityDynamicRegistrationAttr ); if (!is_null($dynamicRegistration)) { $this->dynamicRegistration = $dynamicRegistration; } $this->registerUrl = $this->rpcAdapter->getFacilityAttribute( $facilities[0], $this->facilityRegisterUrlAttr ); if (is_null($this->registerUrl)) { $this->registerUrl = $this->defaultRegisterUrl; } $allowRegistartionToGroups = $this->rpcAdapter->getFacilityAttribute( $facilities[0], $this->facilityAllowRegistrationToGroupsAttr ); if (!is_null($allowRegistartionToGroups)) { $this->allowRegistrationToGroups = $allowRegistartionToGroups; } } catch (\Exception $ex) { Logger::warning("perun:PerunIdentity: " . $ex); } }
php
protected function getSPAttributes($spEntityID) { try { $facilities = $this->rpcAdapter->getFacilitiesByEntityId($spEntityID); if (empty($facilities)) { Logger::warning( "perun:PerunIdentity: No facility with entityID '" . $spEntityID . "' found." ); return; } $checkGroupMembership = $this->rpcAdapter->getFacilityAttribute( $facilities[0], $this->facilityCheckGroupMembershipAttr ); if (!is_null($checkGroupMembership)) { $this->checkGroupMembership = $checkGroupMembership; } $facilityVoShortNames = $this->rpcAdapter->getFacilityAttribute( $facilities[0], $this->facilityVoShortNamesAttr ); if (!empty($facilityVoShortNames)) { $this->facilityVoShortNames = $facilityVoShortNames; } $dynamicRegistration = $this->rpcAdapter->getFacilityAttribute( $facilities[0], $this->facilityDynamicRegistrationAttr ); if (!is_null($dynamicRegistration)) { $this->dynamicRegistration = $dynamicRegistration; } $this->registerUrl = $this->rpcAdapter->getFacilityAttribute( $facilities[0], $this->facilityRegisterUrlAttr ); if (is_null($this->registerUrl)) { $this->registerUrl = $this->defaultRegisterUrl; } $allowRegistartionToGroups = $this->rpcAdapter->getFacilityAttribute( $facilities[0], $this->facilityAllowRegistrationToGroupsAttr ); if (!is_null($allowRegistartionToGroups)) { $this->allowRegistrationToGroups = $allowRegistartionToGroups; } } catch (\Exception $ex) { Logger::warning("perun:PerunIdentity: " . $ex); } }
[ "protected", "function", "getSPAttributes", "(", "$", "spEntityID", ")", "{", "try", "{", "$", "facilities", "=", "$", "this", "->", "rpcAdapter", "->", "getFacilitiesByEntityId", "(", "$", "spEntityID", ")", ";", "if", "(", "empty", "(", "$", "facilities", ")", ")", "{", "Logger", "::", "warning", "(", "\"perun:PerunIdentity: No facility with entityID '\"", ".", "$", "spEntityID", ".", "\"' found.\"", ")", ";", "return", ";", "}", "$", "checkGroupMembership", "=", "$", "this", "->", "rpcAdapter", "->", "getFacilityAttribute", "(", "$", "facilities", "[", "0", "]", ",", "$", "this", "->", "facilityCheckGroupMembershipAttr", ")", ";", "if", "(", "!", "is_null", "(", "$", "checkGroupMembership", ")", ")", "{", "$", "this", "->", "checkGroupMembership", "=", "$", "checkGroupMembership", ";", "}", "$", "facilityVoShortNames", "=", "$", "this", "->", "rpcAdapter", "->", "getFacilityAttribute", "(", "$", "facilities", "[", "0", "]", ",", "$", "this", "->", "facilityVoShortNamesAttr", ")", ";", "if", "(", "!", "empty", "(", "$", "facilityVoShortNames", ")", ")", "{", "$", "this", "->", "facilityVoShortNames", "=", "$", "facilityVoShortNames", ";", "}", "$", "dynamicRegistration", "=", "$", "this", "->", "rpcAdapter", "->", "getFacilityAttribute", "(", "$", "facilities", "[", "0", "]", ",", "$", "this", "->", "facilityDynamicRegistrationAttr", ")", ";", "if", "(", "!", "is_null", "(", "$", "dynamicRegistration", ")", ")", "{", "$", "this", "->", "dynamicRegistration", "=", "$", "dynamicRegistration", ";", "}", "$", "this", "->", "registerUrl", "=", "$", "this", "->", "rpcAdapter", "->", "getFacilityAttribute", "(", "$", "facilities", "[", "0", "]", ",", "$", "this", "->", "facilityRegisterUrlAttr", ")", ";", "if", "(", "is_null", "(", "$", "this", "->", "registerUrl", ")", ")", "{", "$", "this", "->", "registerUrl", "=", "$", "this", "->", "defaultRegisterUrl", ";", "}", "$", "allowRegistartionToGroups", "=", "$", "this", "->", "rpcAdapter", "->", "getFacilityAttribute", "(", "$", "facilities", "[", "0", "]", ",", "$", "this", "->", "facilityAllowRegistrationToGroupsAttr", ")", ";", "if", "(", "!", "is_null", "(", "$", "allowRegistartionToGroups", ")", ")", "{", "$", "this", "->", "allowRegistrationToGroups", "=", "$", "allowRegistartionToGroups", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "ex", ")", "{", "Logger", "::", "warning", "(", "\"perun:PerunIdentity: \"", ".", "$", "ex", ")", ";", "}", "}" ]
This functions get attributes for facility @param string $spEntityID
[ "This", "functions", "get", "attributes", "for", "facility" ]
f1d686f06472053a7cdb31f2b2776f9714779ee1
https://github.com/CESNET/perun-simplesamlphp-module/blob/f1d686f06472053a7cdb31f2b2776f9714779ee1/lib/Auth/Process/PerunIdentity.php#L428-L481
34,684
CESNET/perun-simplesamlphp-module
lib/Auth/Process/PerunIdentity.php
PerunIdentity.getVosForRegistration
protected function getVosForRegistration($user) { $vos = array(); $members = array(); $vosIdForRegistration = array(); $vosForRegistration = array(); $vos = $this->getVosByFacilityVoShortNames(); foreach ($vos as $vo) { Logger::debug("Vo:" . print_r($vo, true)); try { $member = $this->rpcAdapter->getMemberByUser($user, $vo); Logger::debug("Member:" . print_r($member, true)); array_push($members, $member); } catch (\Exception $exception) { array_push($vosForRegistration, $vo); Logger::warning("perun:PerunIdentity: " . $exception); } } foreach ($members as $member) { if ($member->getStatus() === Member::VALID || $member->getStatus() === Member::EXPIRED) { array_push($vosIdForRegistration, $member->getVoId()); } } foreach ($vos as $vo) { if (in_array($vo->getId(), $vosIdForRegistration)) { array_push($vosForRegistration, $vo); } } Logger::debug("VOs for registration: " . print_r($vosForRegistration, true)); return $vosForRegistration; }
php
protected function getVosForRegistration($user) { $vos = array(); $members = array(); $vosIdForRegistration = array(); $vosForRegistration = array(); $vos = $this->getVosByFacilityVoShortNames(); foreach ($vos as $vo) { Logger::debug("Vo:" . print_r($vo, true)); try { $member = $this->rpcAdapter->getMemberByUser($user, $vo); Logger::debug("Member:" . print_r($member, true)); array_push($members, $member); } catch (\Exception $exception) { array_push($vosForRegistration, $vo); Logger::warning("perun:PerunIdentity: " . $exception); } } foreach ($members as $member) { if ($member->getStatus() === Member::VALID || $member->getStatus() === Member::EXPIRED) { array_push($vosIdForRegistration, $member->getVoId()); } } foreach ($vos as $vo) { if (in_array($vo->getId(), $vosIdForRegistration)) { array_push($vosForRegistration, $vo); } } Logger::debug("VOs for registration: " . print_r($vosForRegistration, true)); return $vosForRegistration; }
[ "protected", "function", "getVosForRegistration", "(", "$", "user", ")", "{", "$", "vos", "=", "array", "(", ")", ";", "$", "members", "=", "array", "(", ")", ";", "$", "vosIdForRegistration", "=", "array", "(", ")", ";", "$", "vosForRegistration", "=", "array", "(", ")", ";", "$", "vos", "=", "$", "this", "->", "getVosByFacilityVoShortNames", "(", ")", ";", "foreach", "(", "$", "vos", "as", "$", "vo", ")", "{", "Logger", "::", "debug", "(", "\"Vo:\"", ".", "print_r", "(", "$", "vo", ",", "true", ")", ")", ";", "try", "{", "$", "member", "=", "$", "this", "->", "rpcAdapter", "->", "getMemberByUser", "(", "$", "user", ",", "$", "vo", ")", ";", "Logger", "::", "debug", "(", "\"Member:\"", ".", "print_r", "(", "$", "member", ",", "true", ")", ")", ";", "array_push", "(", "$", "members", ",", "$", "member", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "exception", ")", "{", "array_push", "(", "$", "vosForRegistration", ",", "$", "vo", ")", ";", "Logger", "::", "warning", "(", "\"perun:PerunIdentity: \"", ".", "$", "exception", ")", ";", "}", "}", "foreach", "(", "$", "members", "as", "$", "member", ")", "{", "if", "(", "$", "member", "->", "getStatus", "(", ")", "===", "Member", "::", "VALID", "||", "$", "member", "->", "getStatus", "(", ")", "===", "Member", "::", "EXPIRED", ")", "{", "array_push", "(", "$", "vosIdForRegistration", ",", "$", "member", "->", "getVoId", "(", ")", ")", ";", "}", "}", "foreach", "(", "$", "vos", "as", "$", "vo", ")", "{", "if", "(", "in_array", "(", "$", "vo", "->", "getId", "(", ")", ",", "$", "vosIdForRegistration", ")", ")", "{", "array_push", "(", "$", "vosForRegistration", ",", "$", "vo", ")", ";", "}", "}", "Logger", "::", "debug", "(", "\"VOs for registration: \"", ".", "print_r", "(", "$", "vosForRegistration", ",", "true", ")", ")", ";", "return", "$", "vosForRegistration", ";", "}" ]
Returns list of sspmod_perun_model_Vo to which the user may register @param User $user @return array of Vo
[ "Returns", "list", "of", "sspmod_perun_model_Vo", "to", "which", "the", "user", "may", "register" ]
f1d686f06472053a7cdb31f2b2776f9714779ee1
https://github.com/CESNET/perun-simplesamlphp-module/blob/f1d686f06472053a7cdb31f2b2776f9714779ee1/lib/Auth/Process/PerunIdentity.php#L551-L585
34,685
jon48/webtrees-lib
src/Webtrees/Module/GeoDispersion/Model/OutlineMap.php
OutlineMap.load
protected function load() { if(file_exists(WT_ROOT.WT_MODULES_DIR.Constants::MODULE_MAJ_GEODISP_NAME.'/maps/'.$this->filename)){ $xml = simplexml_load_file(WT_ROOT.WT_MODULES_DIR.Constants::MODULE_MAJ_GEODISP_NAME.'/maps/'.$this->filename); if($xml){ $this->description = trim($xml->displayName); $this->top_level_name = trim($xml->topLevel); $this->canvas = new OutlineMapCanvas( trim($xml->canvas->width), trim($xml->canvas->height), trim($xml->canvas->maxcolor), trim($xml->canvas->hovercolor), trim($xml->canvas->bgcolor), trim($xml->canvas->bgstroke), trim($xml->canvas->defaultcolor), trim($xml->canvas->defaultstroke) ); foreach($xml->subdivisions->children() as $subdivision){ $attributes = $subdivision->attributes(); $key = I18N::strtolower(trim($attributes['name'])); if(isset($attributes['parent'])) $key .= '@'. I18N::strtolower(trim($attributes['parent'])); $this->subdivisions[$key] = array( 'id' => trim($attributes['id']), 'displayname' => trim($attributes['name']), 'coord' => trim($subdivision[0]) ); } if(isset($xml->mappings)) { foreach($xml->mappings->children() as $mappings){ $attributes = $mappings->attributes(); $this->mappings[I18N::strtolower(trim($attributes['name']))] = I18N::strtolower(trim($attributes['mapto'])); } } $this->is_loaded = true; return; } } throw new \Exception('The Outline Map could not be loaded from XML.'); }
php
protected function load() { if(file_exists(WT_ROOT.WT_MODULES_DIR.Constants::MODULE_MAJ_GEODISP_NAME.'/maps/'.$this->filename)){ $xml = simplexml_load_file(WT_ROOT.WT_MODULES_DIR.Constants::MODULE_MAJ_GEODISP_NAME.'/maps/'.$this->filename); if($xml){ $this->description = trim($xml->displayName); $this->top_level_name = trim($xml->topLevel); $this->canvas = new OutlineMapCanvas( trim($xml->canvas->width), trim($xml->canvas->height), trim($xml->canvas->maxcolor), trim($xml->canvas->hovercolor), trim($xml->canvas->bgcolor), trim($xml->canvas->bgstroke), trim($xml->canvas->defaultcolor), trim($xml->canvas->defaultstroke) ); foreach($xml->subdivisions->children() as $subdivision){ $attributes = $subdivision->attributes(); $key = I18N::strtolower(trim($attributes['name'])); if(isset($attributes['parent'])) $key .= '@'. I18N::strtolower(trim($attributes['parent'])); $this->subdivisions[$key] = array( 'id' => trim($attributes['id']), 'displayname' => trim($attributes['name']), 'coord' => trim($subdivision[0]) ); } if(isset($xml->mappings)) { foreach($xml->mappings->children() as $mappings){ $attributes = $mappings->attributes(); $this->mappings[I18N::strtolower(trim($attributes['name']))] = I18N::strtolower(trim($attributes['mapto'])); } } $this->is_loaded = true; return; } } throw new \Exception('The Outline Map could not be loaded from XML.'); }
[ "protected", "function", "load", "(", ")", "{", "if", "(", "file_exists", "(", "WT_ROOT", ".", "WT_MODULES_DIR", ".", "Constants", "::", "MODULE_MAJ_GEODISP_NAME", ".", "'/maps/'", ".", "$", "this", "->", "filename", ")", ")", "{", "$", "xml", "=", "simplexml_load_file", "(", "WT_ROOT", ".", "WT_MODULES_DIR", ".", "Constants", "::", "MODULE_MAJ_GEODISP_NAME", ".", "'/maps/'", ".", "$", "this", "->", "filename", ")", ";", "if", "(", "$", "xml", ")", "{", "$", "this", "->", "description", "=", "trim", "(", "$", "xml", "->", "displayName", ")", ";", "$", "this", "->", "top_level_name", "=", "trim", "(", "$", "xml", "->", "topLevel", ")", ";", "$", "this", "->", "canvas", "=", "new", "OutlineMapCanvas", "(", "trim", "(", "$", "xml", "->", "canvas", "->", "width", ")", ",", "trim", "(", "$", "xml", "->", "canvas", "->", "height", ")", ",", "trim", "(", "$", "xml", "->", "canvas", "->", "maxcolor", ")", ",", "trim", "(", "$", "xml", "->", "canvas", "->", "hovercolor", ")", ",", "trim", "(", "$", "xml", "->", "canvas", "->", "bgcolor", ")", ",", "trim", "(", "$", "xml", "->", "canvas", "->", "bgstroke", ")", ",", "trim", "(", "$", "xml", "->", "canvas", "->", "defaultcolor", ")", ",", "trim", "(", "$", "xml", "->", "canvas", "->", "defaultstroke", ")", ")", ";", "foreach", "(", "$", "xml", "->", "subdivisions", "->", "children", "(", ")", "as", "$", "subdivision", ")", "{", "$", "attributes", "=", "$", "subdivision", "->", "attributes", "(", ")", ";", "$", "key", "=", "I18N", "::", "strtolower", "(", "trim", "(", "$", "attributes", "[", "'name'", "]", ")", ")", ";", "if", "(", "isset", "(", "$", "attributes", "[", "'parent'", "]", ")", ")", "$", "key", ".=", "'@'", ".", "I18N", "::", "strtolower", "(", "trim", "(", "$", "attributes", "[", "'parent'", "]", ")", ")", ";", "$", "this", "->", "subdivisions", "[", "$", "key", "]", "=", "array", "(", "'id'", "=>", "trim", "(", "$", "attributes", "[", "'id'", "]", ")", ",", "'displayname'", "=>", "trim", "(", "$", "attributes", "[", "'name'", "]", ")", ",", "'coord'", "=>", "trim", "(", "$", "subdivision", "[", "0", "]", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "xml", "->", "mappings", ")", ")", "{", "foreach", "(", "$", "xml", "->", "mappings", "->", "children", "(", ")", "as", "$", "mappings", ")", "{", "$", "attributes", "=", "$", "mappings", "->", "attributes", "(", ")", ";", "$", "this", "->", "mappings", "[", "I18N", "::", "strtolower", "(", "trim", "(", "$", "attributes", "[", "'name'", "]", ")", ")", "]", "=", "I18N", "::", "strtolower", "(", "trim", "(", "$", "attributes", "[", "'mapto'", "]", ")", ")", ";", "}", "}", "$", "this", "->", "is_loaded", "=", "true", ";", "return", ";", "}", "}", "throw", "new", "\\", "Exception", "(", "'The Outline Map could not be loaded from XML.'", ")", ";", "}" ]
Load the map settings contained within its XML representation XML structure : - displayName : Display name of the map - topLevel : Values of the top level subdivisions (separated by commas, if multiple) - canvas : all settings related to the map canvas. - width : canvas width, in px - height : canvas height, in px - maxcolor : color to identify places with ancestors, RGB hexadecimal - hovercolor : same as previous, color when mouse is hovering the place, RGB hexadecimal - bgcolor : map background color, RGB hexadecimal - bgstroke : map stroke color, RGB hexadecimal - defaultcolor : default color of places, RGB hexadecimal - defaultstroke : default stroke color, RGB hexadecimal - subdvisions : for each subdivision : - id : Subdivision id, must be compatible with PHP variable constraints, and unique - name: Display name for the place - parent: if any, describe to which parent level the place if belonging to - <em>Element value<em> : SVG description of the subdvision shape - mapping : for each subdivision : - name : Name of the place to map - mapto: Name of the place to map to
[ "Load", "the", "map", "settings", "contained", "within", "its", "XML", "representation" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/GeoDispersion/Model/OutlineMap.php#L102-L139
34,686
GrupaZero/cms
src/Gzero/Cms/Repositories/BlockReadRepository.php
BlockReadRepository.getVisibleBlocks
public function getVisibleBlocks(array $ids, Language $language, $onlyActive = true) { $query = Block::query()->with(self::$loadRelations); if (!empty($ids)) { $query->where(function ($query) use ($ids) { $query->whereIn('id', $ids) ->orWhere('filter', null); }); } else { // blocks on all pages only $query->where('filter', null); } if ($onlyActive) { $query->whereHas('translations', function ($query) use ($language) { $query->where('block_translations.is_active', true) ->where('language_code', $language->code); })->where('is_active', '=', true); } $blocks = $query->orderBy('weight', 'ASC')->get(); return $blocks; }
php
public function getVisibleBlocks(array $ids, Language $language, $onlyActive = true) { $query = Block::query()->with(self::$loadRelations); if (!empty($ids)) { $query->where(function ($query) use ($ids) { $query->whereIn('id', $ids) ->orWhere('filter', null); }); } else { // blocks on all pages only $query->where('filter', null); } if ($onlyActive) { $query->whereHas('translations', function ($query) use ($language) { $query->where('block_translations.is_active', true) ->where('language_code', $language->code); })->where('is_active', '=', true); } $blocks = $query->orderBy('weight', 'ASC')->get(); return $blocks; }
[ "public", "function", "getVisibleBlocks", "(", "array", "$", "ids", ",", "Language", "$", "language", ",", "$", "onlyActive", "=", "true", ")", "{", "$", "query", "=", "Block", "::", "query", "(", ")", "->", "with", "(", "self", "::", "$", "loadRelations", ")", ";", "if", "(", "!", "empty", "(", "$", "ids", ")", ")", "{", "$", "query", "->", "where", "(", "function", "(", "$", "query", ")", "use", "(", "$", "ids", ")", "{", "$", "query", "->", "whereIn", "(", "'id'", ",", "$", "ids", ")", "->", "orWhere", "(", "'filter'", ",", "null", ")", ";", "}", ")", ";", "}", "else", "{", "// blocks on all pages only", "$", "query", "->", "where", "(", "'filter'", ",", "null", ")", ";", "}", "if", "(", "$", "onlyActive", ")", "{", "$", "query", "->", "whereHas", "(", "'translations'", ",", "function", "(", "$", "query", ")", "use", "(", "$", "language", ")", "{", "$", "query", "->", "where", "(", "'block_translations.is_active'", ",", "true", ")", "->", "where", "(", "'language_code'", ",", "$", "language", "->", "code", ")", ";", "}", ")", "->", "where", "(", "'is_active'", ",", "'='", ",", "true", ")", ";", "}", "$", "blocks", "=", "$", "query", "->", "orderBy", "(", "'weight'", ",", "'ASC'", ")", "->", "get", "(", ")", ";", "return", "$", "blocks", ";", "}" ]
Returns all visible blocks @param array $ids Array with blocks ids returned from block finder @param Language $language Language @param bool $onlyActive Return only active blocks @return Collection
[ "Returns", "all", "visible", "blocks" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Repositories/BlockReadRepository.php#L99-L123
34,687
GrupaZero/cms
src/Gzero/Cms/Repositories/BlockReadRepository.php
BlockReadRepository.getBlocksWithFilter
public function getBlocksWithFilter($onlyActive = true) { $query = Block::query()->with(self::$loadRelations) ->where('filter', '!=', null); if ($onlyActive) { $query->where('is_active', '=', true); } $blocks = $query->orderBy('weight', 'ASC')->get(); return $blocks; }
php
public function getBlocksWithFilter($onlyActive = true) { $query = Block::query()->with(self::$loadRelations) ->where('filter', '!=', null); if ($onlyActive) { $query->where('is_active', '=', true); } $blocks = $query->orderBy('weight', 'ASC')->get(); return $blocks; }
[ "public", "function", "getBlocksWithFilter", "(", "$", "onlyActive", "=", "true", ")", "{", "$", "query", "=", "Block", "::", "query", "(", ")", "->", "with", "(", "self", "::", "$", "loadRelations", ")", "->", "where", "(", "'filter'", ",", "'!='", ",", "null", ")", ";", "if", "(", "$", "onlyActive", ")", "{", "$", "query", "->", "where", "(", "'is_active'", ",", "'='", ",", "true", ")", ";", "}", "$", "blocks", "=", "$", "query", "->", "orderBy", "(", "'weight'", ",", "'ASC'", ")", "->", "get", "(", ")", ";", "return", "$", "blocks", ";", "}" ]
Returns all blocks with filter @param bool $onlyActive Return only active blocks @return Collection
[ "Returns", "all", "blocks", "with", "filter" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Repositories/BlockReadRepository.php#L132-L144
34,688
GrupaZero/cms
src/Gzero/Cms/Repositories/BlockReadRepository.php
BlockReadRepository.getManyTranslations
public function getManyTranslations(Block $block, QueryBuilder $builder): LengthAwarePaginator { $query = $block->translations(false)->newQuery()->getQuery(); $builder->applyFilters($query, 'block_translations'); $builder->applySorts($query, 'block_translations'); $count = clone $query->getQuery(); $results = $query->limit($builder->getPageSize()) ->offset($builder->getPageSize() * ($builder->getPage() - 1)) ->get(['block_translations.*']); return new LengthAwarePaginator( $results, $count->select('block_translations.id')->get()->count(), $builder->getPageSize(), $builder->getPage() ); }
php
public function getManyTranslations(Block $block, QueryBuilder $builder): LengthAwarePaginator { $query = $block->translations(false)->newQuery()->getQuery(); $builder->applyFilters($query, 'block_translations'); $builder->applySorts($query, 'block_translations'); $count = clone $query->getQuery(); $results = $query->limit($builder->getPageSize()) ->offset($builder->getPageSize() * ($builder->getPage() - 1)) ->get(['block_translations.*']); return new LengthAwarePaginator( $results, $count->select('block_translations.id')->get()->count(), $builder->getPageSize(), $builder->getPage() ); }
[ "public", "function", "getManyTranslations", "(", "Block", "$", "block", ",", "QueryBuilder", "$", "builder", ")", ":", "LengthAwarePaginator", "{", "$", "query", "=", "$", "block", "->", "translations", "(", "false", ")", "->", "newQuery", "(", ")", "->", "getQuery", "(", ")", ";", "$", "builder", "->", "applyFilters", "(", "$", "query", ",", "'block_translations'", ")", ";", "$", "builder", "->", "applySorts", "(", "$", "query", ",", "'block_translations'", ")", ";", "$", "count", "=", "clone", "$", "query", "->", "getQuery", "(", ")", ";", "$", "results", "=", "$", "query", "->", "limit", "(", "$", "builder", "->", "getPageSize", "(", ")", ")", "->", "offset", "(", "$", "builder", "->", "getPageSize", "(", ")", "*", "(", "$", "builder", "->", "getPage", "(", ")", "-", "1", ")", ")", "->", "get", "(", "[", "'block_translations.*'", "]", ")", ";", "return", "new", "LengthAwarePaginator", "(", "$", "results", ",", "$", "count", "->", "select", "(", "'block_translations.id'", ")", "->", "get", "(", ")", "->", "count", "(", ")", ",", "$", "builder", "->", "getPageSize", "(", ")", ",", "$", "builder", "->", "getPage", "(", ")", ")", ";", "}" ]
Get all block translations for specified content. @param Block $block Content model @param QueryBuilder $builder Query builder @return Collection|LengthAwarePaginator
[ "Get", "all", "block", "translations", "for", "specified", "content", "." ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Repositories/BlockReadRepository.php#L197-L216
34,689
GrupaZero/cms
src/Gzero/Cms/Repositories/BlockReadRepository.php
BlockReadRepository.getManyFiles
public function getManyFiles(Block $block, QueryBuilder $builder): LengthAwarePaginator { $query = $block->files(false)->with(['type','translations']); $count = clone $query->getQuery(); $results = $query->limit($builder->getPageSize()) ->offset($builder->getPageSize() * ($builder->getPage() - 1)) ->get(['files.*']); return new LengthAwarePaginator( $results, $count->select('files.id')->get()->count(), $builder->getPageSize(), $builder->getPage() ); }
php
public function getManyFiles(Block $block, QueryBuilder $builder): LengthAwarePaginator { $query = $block->files(false)->with(['type','translations']); $count = clone $query->getQuery(); $results = $query->limit($builder->getPageSize()) ->offset($builder->getPageSize() * ($builder->getPage() - 1)) ->get(['files.*']); return new LengthAwarePaginator( $results, $count->select('files.id')->get()->count(), $builder->getPageSize(), $builder->getPage() ); }
[ "public", "function", "getManyFiles", "(", "Block", "$", "block", ",", "QueryBuilder", "$", "builder", ")", ":", "LengthAwarePaginator", "{", "$", "query", "=", "$", "block", "->", "files", "(", "false", ")", "->", "with", "(", "[", "'type'", ",", "'translations'", "]", ")", ";", "$", "count", "=", "clone", "$", "query", "->", "getQuery", "(", ")", ";", "$", "results", "=", "$", "query", "->", "limit", "(", "$", "builder", "->", "getPageSize", "(", ")", ")", "->", "offset", "(", "$", "builder", "->", "getPageSize", "(", ")", "*", "(", "$", "builder", "->", "getPage", "(", ")", "-", "1", ")", ")", "->", "get", "(", "[", "'files.*'", "]", ")", ";", "return", "new", "LengthAwarePaginator", "(", "$", "results", ",", "$", "count", "->", "select", "(", "'files.id'", ")", "->", "get", "(", ")", "->", "count", "(", ")", ",", "$", "builder", "->", "getPageSize", "(", ")", ",", "$", "builder", "->", "getPage", "(", ")", ")", ";", "}" ]
Get all files with translations for specified block. @param Block $block Block model @param QueryBuilder $builder Query builder @return Collection|LengthAwarePaginator
[ "Get", "all", "files", "with", "translations", "for", "specified", "block", "." ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Repositories/BlockReadRepository.php#L226-L242
34,690
CESNET/perun-simplesamlphp-module
lib/Auth/Process/StringifyTargetedID.php
StringifyTargetedID.stringify
private function stringify($attributeValue) { if (is_object($attributeValue) && get_class($attributeValue) == "SAML2\XML\saml\NameID") { return $attributeValue->NameQualifier . '!' . $attributeValue->SPNameQualifier . '!' . $attributeValue->value; } else { return $attributeValue; } }
php
private function stringify($attributeValue) { if (is_object($attributeValue) && get_class($attributeValue) == "SAML2\XML\saml\NameID") { return $attributeValue->NameQualifier . '!' . $attributeValue->SPNameQualifier . '!' . $attributeValue->value; } else { return $attributeValue; } }
[ "private", "function", "stringify", "(", "$", "attributeValue", ")", "{", "if", "(", "is_object", "(", "$", "attributeValue", ")", "&&", "get_class", "(", "$", "attributeValue", ")", "==", "\"SAML2\\XML\\saml\\NameID\"", ")", "{", "return", "$", "attributeValue", "->", "NameQualifier", ".", "'!'", ".", "$", "attributeValue", "->", "SPNameQualifier", ".", "'!'", ".", "$", "attributeValue", "->", "value", ";", "}", "else", "{", "return", "$", "attributeValue", ";", "}", "}" ]
Convert NameID value into the text representation.
[ "Convert", "NameID", "value", "into", "the", "text", "representation", "." ]
f1d686f06472053a7cdb31f2b2776f9714779ee1
https://github.com/CESNET/perun-simplesamlphp-module/blob/f1d686f06472053a7cdb31f2b2776f9714779ee1/lib/Auth/Process/StringifyTargetedID.php#L56-L64
34,691
jon48/webtrees-lib
src/Webtrees/Mvc/MvcException.php
MvcException.setHttpCode
public function setHttpCode($http_code) { if(!in_array($http_code, self::$VALID_HTTP)) throw new \InvalidArgumentException('Invalid HTTP code'); $this->http_code= $http_code; }
php
public function setHttpCode($http_code) { if(!in_array($http_code, self::$VALID_HTTP)) throw new \InvalidArgumentException('Invalid HTTP code'); $this->http_code= $http_code; }
[ "public", "function", "setHttpCode", "(", "$", "http_code", ")", "{", "if", "(", "!", "in_array", "(", "$", "http_code", ",", "self", "::", "$", "VALID_HTTP", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid HTTP code'", ")", ";", "$", "this", "->", "http_code", "=", "$", "http_code", ";", "}" ]
Set the HTTP code @param int $http_code @throws InvalidArgumentException Thrown if not valid Http code
[ "Set", "the", "HTTP", "code" ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Mvc/MvcException.php#L60-L64
34,692
alexislefebvre/AsyncTweetsBundle
src/Utils/PersistTweet.php
PersistTweet.createTweet
protected function createTweet(\stdClass $tweetTmp, $user, $inTimeline) { $tweet = new Tweet(); $tweet ->setId($tweetTmp->id) ->setValues($tweetTmp) ->setUser($user) ->setInTimeline($inTimeline); $this->addMedias($tweetTmp, $tweet); return $tweet; }
php
protected function createTweet(\stdClass $tweetTmp, $user, $inTimeline) { $tweet = new Tweet(); $tweet ->setId($tweetTmp->id) ->setValues($tweetTmp) ->setUser($user) ->setInTimeline($inTimeline); $this->addMedias($tweetTmp, $tweet); return $tweet; }
[ "protected", "function", "createTweet", "(", "\\", "stdClass", "$", "tweetTmp", ",", "$", "user", ",", "$", "inTimeline", ")", "{", "$", "tweet", "=", "new", "Tweet", "(", ")", ";", "$", "tweet", "->", "setId", "(", "$", "tweetTmp", "->", "id", ")", "->", "setValues", "(", "$", "tweetTmp", ")", "->", "setUser", "(", "$", "user", ")", "->", "setInTimeline", "(", "$", "inTimeline", ")", ";", "$", "this", "->", "addMedias", "(", "$", "tweetTmp", ",", "$", "tweet", ")", ";", "return", "$", "tweet", ";", "}" ]
Create a Tweet object and return it. @param \stdClass $tweetTmp @param User $user @param bool $inTimeline @return Tweet
[ "Create", "a", "Tweet", "object", "and", "return", "it", "." ]
76266fae7de978963e05dadb14c81f8398bb00a6
https://github.com/alexislefebvre/AsyncTweetsBundle/blob/76266fae7de978963e05dadb14c81f8398bb00a6/src/Utils/PersistTweet.php#L80-L93
34,693
GrupaZero/cms
src/Gzero/Cms/Http/Controllers/Api/PublicContentController.php
PublicContentController.index
public function index() { $results = $this->repository->getManyPublished(new QueryBuilder()); $results->setPath(apiUrl('public-contents')); return new ContentCollection($results); }
php
public function index() { $results = $this->repository->getManyPublished(new QueryBuilder()); $results->setPath(apiUrl('public-contents')); return new ContentCollection($results); }
[ "public", "function", "index", "(", ")", "{", "$", "results", "=", "$", "this", "->", "repository", "->", "getManyPublished", "(", "new", "QueryBuilder", "(", ")", ")", ";", "$", "results", "->", "setPath", "(", "apiUrl", "(", "'public-contents'", ")", ")", ";", "return", "new", "ContentCollection", "(", "$", "results", ")", ";", "}" ]
Display list of public contents @SWG\Get( path="/public-contents", tags={"content","public"}, summary="List of public contents", description="List of all publicly accessible contents", produces={"application/json"}, @SWG\Response( response=200, description="Successful operation", @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/Content")), ), ) @return ContentCollection
[ "Display", "list", "of", "public", "contents" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Http/Controllers/Api/PublicContentController.php#L50-L56
34,694
jon48/webtrees-lib
src/Webtrees/Module/GeoDispersion/Views/GeoAnalysisTabGenerationsView.php
GeoAnalysisTabGenerationsView.htmlGenerationAllPlacesRow
protected function htmlGenerationAllPlacesRow($data, $analysis_level) { $html = '<table class="geodispersion_bigrow"> <tr>'; $sum_gen = $data['sum']; $unknownother = $data['unknown'] + $data['other']; foreach($data['places'] as $placename=> $dataplace){ $levels = array_map('trim',explode(',', $placename)); $content = ''; if(isset($dataplace['flag'])){ $content .= '<td class="geodispersion_flag">'. FunctionsPrint::htmlPlaceIcon($dataplace['place'], $dataplace['flag']) .'</td><td>'; } else{ $content .= '<td><span title="'.implode(I18N::$list_separator, array_reverse($levels)).'">'.$levels[$analysis_level-1].'</span><br/>'; } $count = $dataplace['count']; $content .= I18N::number($count); $perc = Functions::safeDivision($count, $sum_gen + $unknownother); $perc2= Functions::safeDivision($count, $sum_gen); if($perc2>=0.1) $content.= '<br/><span class="small">('.I18N::percentage($perc2, 1).')</span>'; $content .= '</td>'; $html .= ' <td class="geodispersion_rowitem" width="'.max(round(100*$perc, 0),1).'%"> <table> <tr> <td> <table> <tr>'.$content.'</tr> </table> </td> </tr> </table> </td>'; } if($unknownother>0){ $perc= Functions::safeDivision($unknownother, $sum_gen + $unknownother); $html .='<td class="geodispersion_unknownitem left" >'.I18N::number($unknownother); if($perc>=0.1) $html.= '<br/><span class="small">('.I18N::percentage($perc, 1).')</span>'; $html .='</td>'; } $html .= '</tr> </table>'; return $html; }
php
protected function htmlGenerationAllPlacesRow($data, $analysis_level) { $html = '<table class="geodispersion_bigrow"> <tr>'; $sum_gen = $data['sum']; $unknownother = $data['unknown'] + $data['other']; foreach($data['places'] as $placename=> $dataplace){ $levels = array_map('trim',explode(',', $placename)); $content = ''; if(isset($dataplace['flag'])){ $content .= '<td class="geodispersion_flag">'. FunctionsPrint::htmlPlaceIcon($dataplace['place'], $dataplace['flag']) .'</td><td>'; } else{ $content .= '<td><span title="'.implode(I18N::$list_separator, array_reverse($levels)).'">'.$levels[$analysis_level-1].'</span><br/>'; } $count = $dataplace['count']; $content .= I18N::number($count); $perc = Functions::safeDivision($count, $sum_gen + $unknownother); $perc2= Functions::safeDivision($count, $sum_gen); if($perc2>=0.1) $content.= '<br/><span class="small">('.I18N::percentage($perc2, 1).')</span>'; $content .= '</td>'; $html .= ' <td class="geodispersion_rowitem" width="'.max(round(100*$perc, 0),1).'%"> <table> <tr> <td> <table> <tr>'.$content.'</tr> </table> </td> </tr> </table> </td>'; } if($unknownother>0){ $perc= Functions::safeDivision($unknownother, $sum_gen + $unknownother); $html .='<td class="geodispersion_unknownitem left" >'.I18N::number($unknownother); if($perc>=0.1) $html.= '<br/><span class="small">('.I18N::percentage($perc, 1).')</span>'; $html .='</td>'; } $html .= '</tr> </table>'; return $html; }
[ "protected", "function", "htmlGenerationAllPlacesRow", "(", "$", "data", ",", "$", "analysis_level", ")", "{", "$", "html", "=", "'<table class=\"geodispersion_bigrow\">\n <tr>'", ";", "$", "sum_gen", "=", "$", "data", "[", "'sum'", "]", ";", "$", "unknownother", "=", "$", "data", "[", "'unknown'", "]", "+", "$", "data", "[", "'other'", "]", ";", "foreach", "(", "$", "data", "[", "'places'", "]", "as", "$", "placename", "=>", "$", "dataplace", ")", "{", "$", "levels", "=", "array_map", "(", "'trim'", ",", "explode", "(", "','", ",", "$", "placename", ")", ")", ";", "$", "content", "=", "''", ";", "if", "(", "isset", "(", "$", "dataplace", "[", "'flag'", "]", ")", ")", "{", "$", "content", ".=", "'<td class=\"geodispersion_flag\">'", ".", "FunctionsPrint", "::", "htmlPlaceIcon", "(", "$", "dataplace", "[", "'place'", "]", ",", "$", "dataplace", "[", "'flag'", "]", ")", ".", "'</td><td>'", ";", "}", "else", "{", "$", "content", ".=", "'<td><span title=\"'", ".", "implode", "(", "I18N", "::", "$", "list_separator", ",", "array_reverse", "(", "$", "levels", ")", ")", ".", "'\">'", ".", "$", "levels", "[", "$", "analysis_level", "-", "1", "]", ".", "'</span><br/>'", ";", "}", "$", "count", "=", "$", "dataplace", "[", "'count'", "]", ";", "$", "content", ".=", "I18N", "::", "number", "(", "$", "count", ")", ";", "$", "perc", "=", "Functions", "::", "safeDivision", "(", "$", "count", ",", "$", "sum_gen", "+", "$", "unknownother", ")", ";", "$", "perc2", "=", "Functions", "::", "safeDivision", "(", "$", "count", ",", "$", "sum_gen", ")", ";", "if", "(", "$", "perc2", ">=", "0.1", ")", "$", "content", ".=", "'<br/><span class=\"small\">('", ".", "I18N", "::", "percentage", "(", "$", "perc2", ",", "1", ")", ".", "')</span>'", ";", "$", "content", ".=", "'</td>'", ";", "$", "html", ".=", "'\n <td class=\"geodispersion_rowitem\" width=\"'", ".", "max", "(", "round", "(", "100", "*", "$", "perc", ",", "0", ")", ",", "1", ")", ".", "'%\">\n <table>\n <tr>\n <td>\n <table>\n <tr>'", ".", "$", "content", ".", "'</tr>\n </table>\n </td>\n </tr>\n </table>\n </td>'", ";", "}", "if", "(", "$", "unknownother", ">", "0", ")", "{", "$", "perc", "=", "Functions", "::", "safeDivision", "(", "$", "unknownother", ",", "$", "sum_gen", "+", "$", "unknownother", ")", ";", "$", "html", ".=", "'<td class=\"geodispersion_unknownitem left\" >'", ".", "I18N", "::", "number", "(", "$", "unknownother", ")", ";", "if", "(", "$", "perc", ">=", "0.1", ")", "$", "html", ".=", "'<br/><span class=\"small\">('", ".", "I18N", "::", "percentage", "(", "$", "perc", ",", "1", ")", ".", "')</span>'", ";", "$", "html", ".=", "'</td>'", ";", "}", "$", "html", ".=", "'</tr>\n </table>'", ";", "return", "$", "html", ";", "}" ]
Return the HTML code to display a row with all places found in a generation. @param array $data Data array @param int $analysis_level Level of subdivision of analysis @return string HTML code for all places row
[ "Return", "the", "HTML", "code", "to", "display", "a", "row", "with", "all", "places", "found", "in", "a", "generation", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/GeoDispersion/Views/GeoAnalysisTabGenerationsView.php#L85-L134
34,695
jon48/webtrees-lib
src/Webtrees/Module/GeoDispersion/Views/GeoAnalysisTabGenerationsView.php
GeoAnalysisTabGenerationsView.htmlGenerationTopPlacesRow
protected function htmlGenerationTopPlacesRow($data, $analysis_level) { $tmp_places = array(); $sum_gen = $data['sum']; $other = $data['other']; foreach($data['places'] as $placename => $count) { if($placename != 'other'){ $levels = array_map('trim',explode(',', $placename)); $placename = '<span title="'.implode(I18N::$list_separator, array_reverse($levels)).'">'.$levels[$analysis_level-1].'</span>'; } else{ $placename = I18N::translate('Other places'); } $tmp_places[] = I18N::translate('<strong>%s</strong> [%d - %s]', $placename, $count, I18N::percentage(Functions::safeDivision($count, $sum_gen + $other), 1)); } return implode(I18N::$list_separator, $tmp_places); }
php
protected function htmlGenerationTopPlacesRow($data, $analysis_level) { $tmp_places = array(); $sum_gen = $data['sum']; $other = $data['other']; foreach($data['places'] as $placename => $count) { if($placename != 'other'){ $levels = array_map('trim',explode(',', $placename)); $placename = '<span title="'.implode(I18N::$list_separator, array_reverse($levels)).'">'.$levels[$analysis_level-1].'</span>'; } else{ $placename = I18N::translate('Other places'); } $tmp_places[] = I18N::translate('<strong>%s</strong> [%d - %s]', $placename, $count, I18N::percentage(Functions::safeDivision($count, $sum_gen + $other), 1)); } return implode(I18N::$list_separator, $tmp_places); }
[ "protected", "function", "htmlGenerationTopPlacesRow", "(", "$", "data", ",", "$", "analysis_level", ")", "{", "$", "tmp_places", "=", "array", "(", ")", ";", "$", "sum_gen", "=", "$", "data", "[", "'sum'", "]", ";", "$", "other", "=", "$", "data", "[", "'other'", "]", ";", "foreach", "(", "$", "data", "[", "'places'", "]", "as", "$", "placename", "=>", "$", "count", ")", "{", "if", "(", "$", "placename", "!=", "'other'", ")", "{", "$", "levels", "=", "array_map", "(", "'trim'", ",", "explode", "(", "','", ",", "$", "placename", ")", ")", ";", "$", "placename", "=", "'<span title=\"'", ".", "implode", "(", "I18N", "::", "$", "list_separator", ",", "array_reverse", "(", "$", "levels", ")", ")", ".", "'\">'", ".", "$", "levels", "[", "$", "analysis_level", "-", "1", "]", ".", "'</span>'", ";", "}", "else", "{", "$", "placename", "=", "I18N", "::", "translate", "(", "'Other places'", ")", ";", "}", "$", "tmp_places", "[", "]", "=", "I18N", "::", "translate", "(", "'<strong>%s</strong> [%d - %s]'", ",", "$", "placename", ",", "$", "count", ",", "I18N", "::", "percentage", "(", "Functions", "::", "safeDivision", "(", "$", "count", ",", "$", "sum_gen", "+", "$", "other", ")", ",", "1", ")", ")", ";", "}", "return", "implode", "(", "I18N", "::", "$", "list_separator", ",", "$", "tmp_places", ")", ";", "}" ]
Returns the HTML code fo display a row of the Top Places found for a generation. @param array $data Data array @param int $analysis_level Level of subdivision of analysis @return string HTML code for Top Places row
[ "Returns", "the", "HTML", "code", "fo", "display", "a", "row", "of", "the", "Top", "Places", "found", "for", "a", "generation", "." ]
e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7
https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/GeoDispersion/Views/GeoAnalysisTabGenerationsView.php#L143-L160
34,696
GrupaZero/cms
src/Gzero/Cms/Http/Controllers/Api/ContentTreeController.php
ContentTreeController.index
public function index(UrlParamsProcessor $processor) { $this->authorize('readList', Content::class); // @TODO Implement contents/{id}/tree $processor ->addFilter(new BoolParser('only_categories')) ->process($this->request); Resource::wrap('data'); return (new ContentCollection($this->repository->getTree($processor->buildQueryBuilder()))); }
php
public function index(UrlParamsProcessor $processor) { $this->authorize('readList', Content::class); // @TODO Implement contents/{id}/tree $processor ->addFilter(new BoolParser('only_categories')) ->process($this->request); Resource::wrap('data'); return (new ContentCollection($this->repository->getTree($processor->buildQueryBuilder()))); }
[ "public", "function", "index", "(", "UrlParamsProcessor", "$", "processor", ")", "{", "$", "this", "->", "authorize", "(", "'readList'", ",", "Content", "::", "class", ")", ";", "// @TODO Implement contents/{id}/tree", "$", "processor", "->", "addFilter", "(", "new", "BoolParser", "(", "'only_categories'", ")", ")", "->", "process", "(", "$", "this", "->", "request", ")", ";", "Resource", "::", "wrap", "(", "'data'", ")", ";", "return", "(", "new", "ContentCollection", "(", "$", "this", "->", "repository", "->", "getTree", "(", "$", "processor", "->", "buildQueryBuilder", "(", ")", ")", ")", ")", ";", "}" ]
Fetches all content in a tree structure @SWG\Get( path="/contents-tree", tags={"content"}, summary="Fetches all content in a tree structure", produces={"application/json"}, security={{"AdminAccess": {}}}, @SWG\Parameter( name="only_category", in="query", description="Should fetch only categories?", required=false, type="boolean", default="false" ), @SWG\Response( response=200, description="Successful operation", @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/Content")) ), ), @param UrlParamsProcessor $processor params processor @return string
[ "Fetches", "all", "content", "in", "a", "tree", "structure" ]
a7956966d2edec54fc99ebb61eeb2f01704aa2c2
https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Http/Controllers/Api/ContentTreeController.php#L71-L82
34,697
MetaModels/filter_range
src/EventListener/DcGeneral/Table/FilterSetting/GetPropertyOptionsListener.php
GetPropertyOptionsListener.handle
public function handle(GetPropertyOptionsEvent $event) { $isAllowed = $this->isAllowedContext( $event->getEnvironment()->getDataDefinition(), $event->getPropertyName(), $event->getModel() ); if (!$isAllowed) { return; } $result = []; $model = $event->getModel(); $metaModel = $this->getMetaModel($model); $typeFactory = $this->filterSettingFactory->getTypeFactory($model->getProperty('type')); $typeFilter = null; if ($typeFactory) { $typeFilter = $typeFactory->getKnownAttributeTypes(); } foreach ($metaModel->getAttributes() as $attribute) { $typeName = $attribute->get('type'); if ($typeFilter && (!\in_array($typeName, $typeFilter, true))) { continue; } $strSelectVal = $metaModel->getTableName().'_'.$attribute->getColName(); $result[$strSelectVal] = $attribute->getName().' ['.$typeName.']'; } $event->setOptions($result); }
php
public function handle(GetPropertyOptionsEvent $event) { $isAllowed = $this->isAllowedContext( $event->getEnvironment()->getDataDefinition(), $event->getPropertyName(), $event->getModel() ); if (!$isAllowed) { return; } $result = []; $model = $event->getModel(); $metaModel = $this->getMetaModel($model); $typeFactory = $this->filterSettingFactory->getTypeFactory($model->getProperty('type')); $typeFilter = null; if ($typeFactory) { $typeFilter = $typeFactory->getKnownAttributeTypes(); } foreach ($metaModel->getAttributes() as $attribute) { $typeName = $attribute->get('type'); if ($typeFilter && (!\in_array($typeName, $typeFilter, true))) { continue; } $strSelectVal = $metaModel->getTableName().'_'.$attribute->getColName(); $result[$strSelectVal] = $attribute->getName().' ['.$typeName.']'; } $event->setOptions($result); }
[ "public", "function", "handle", "(", "GetPropertyOptionsEvent", "$", "event", ")", "{", "$", "isAllowed", "=", "$", "this", "->", "isAllowedContext", "(", "$", "event", "->", "getEnvironment", "(", ")", "->", "getDataDefinition", "(", ")", ",", "$", "event", "->", "getPropertyName", "(", ")", ",", "$", "event", "->", "getModel", "(", ")", ")", ";", "if", "(", "!", "$", "isAllowed", ")", "{", "return", ";", "}", "$", "result", "=", "[", "]", ";", "$", "model", "=", "$", "event", "->", "getModel", "(", ")", ";", "$", "metaModel", "=", "$", "this", "->", "getMetaModel", "(", "$", "model", ")", ";", "$", "typeFactory", "=", "$", "this", "->", "filterSettingFactory", "->", "getTypeFactory", "(", "$", "model", "->", "getProperty", "(", "'type'", ")", ")", ";", "$", "typeFilter", "=", "null", ";", "if", "(", "$", "typeFactory", ")", "{", "$", "typeFilter", "=", "$", "typeFactory", "->", "getKnownAttributeTypes", "(", ")", ";", "}", "foreach", "(", "$", "metaModel", "->", "getAttributes", "(", ")", "as", "$", "attribute", ")", "{", "$", "typeName", "=", "$", "attribute", "->", "get", "(", "'type'", ")", ";", "if", "(", "$", "typeFilter", "&&", "(", "!", "\\", "in_array", "(", "$", "typeName", ",", "$", "typeFilter", ",", "true", ")", ")", ")", "{", "continue", ";", "}", "$", "strSelectVal", "=", "$", "metaModel", "->", "getTableName", "(", ")", ".", "'_'", ".", "$", "attribute", "->", "getColName", "(", ")", ";", "$", "result", "[", "$", "strSelectVal", "]", "=", "$", "attribute", "->", "getName", "(", ")", ".", "' ['", ".", "$", "typeName", ".", "']'", ";", "}", "$", "event", "->", "setOptions", "(", "$", "result", ")", ";", "}" ]
Prepares a option list with alias => name connection for all attributes. This is used in the attr_id select box. @param GetPropertyOptionsEvent $event The event. @return void @throws \RuntimeException When the MetaModel can not be determined.
[ "Prepares", "a", "option", "list", "with", "alias", "=", ">", "name", "connection", "for", "all", "attributes", "." ]
1875e4a2206df2c5c98f5b0a7f18feb17b34f393
https://github.com/MetaModels/filter_range/blob/1875e4a2206df2c5c98f5b0a7f18feb17b34f393/src/EventListener/DcGeneral/Table/FilterSetting/GetPropertyOptionsListener.php#L43-L78
34,698
nepttune/nepttune
src/Model/PushNotificationModel.php
PushNotificationModel.sendAll
public function sendAll($msg) : void { foreach ($this->subscriptionTable->findActive() as $row) { $this->sendNotification($row, $msg, false); } if ($flush) { $this->flush(); } }
php
public function sendAll($msg) : void { foreach ($this->subscriptionTable->findActive() as $row) { $this->sendNotification($row, $msg, false); } if ($flush) { $this->flush(); } }
[ "public", "function", "sendAll", "(", "$", "msg", ")", ":", "void", "{", "foreach", "(", "$", "this", "->", "subscriptionTable", "->", "findActive", "(", ")", "as", "$", "row", ")", "{", "$", "this", "->", "sendNotification", "(", "$", "row", ",", "$", "msg", ",", "false", ")", ";", "}", "if", "(", "$", "flush", ")", "{", "$", "this", "->", "flush", "(", ")", ";", "}", "}" ]
Send notification to all active subscriptions. @param string $msg
[ "Send", "notification", "to", "all", "active", "subscriptions", "." ]
63b41f62e0589a0ebac698abd1b8cf65abfcb1d5
https://github.com/nepttune/nepttune/blob/63b41f62e0589a0ebac698abd1b8cf65abfcb1d5/src/Model/PushNotificationModel.php#L61-L72
34,699
nepttune/nepttune
src/Model/PushNotificationModel.php
PushNotificationModel.sendByUserId
public function sendByUserId(int $userId, string $msg, ?string $dest = null, bool $flush = false) : void { $msg = $this->composeMsg($msg, $dest); foreach ($this->subscriptionTable->findActive()->where('user_id', $userId) as $row) { $this->sendNotification($row, $msg, false); } if ($flush) { $this->flush(); } }
php
public function sendByUserId(int $userId, string $msg, ?string $dest = null, bool $flush = false) : void { $msg = $this->composeMsg($msg, $dest); foreach ($this->subscriptionTable->findActive()->where('user_id', $userId) as $row) { $this->sendNotification($row, $msg, false); } if ($flush) { $this->flush(); } }
[ "public", "function", "sendByUserId", "(", "int", "$", "userId", ",", "string", "$", "msg", ",", "?", "string", "$", "dest", "=", "null", ",", "bool", "$", "flush", "=", "false", ")", ":", "void", "{", "$", "msg", "=", "$", "this", "->", "composeMsg", "(", "$", "msg", ",", "$", "dest", ")", ";", "foreach", "(", "$", "this", "->", "subscriptionTable", "->", "findActive", "(", ")", "->", "where", "(", "'user_id'", ",", "$", "userId", ")", "as", "$", "row", ")", "{", "$", "this", "->", "sendNotification", "(", "$", "row", ",", "$", "msg", ",", "false", ")", ";", "}", "if", "(", "$", "flush", ")", "{", "$", "this", "->", "flush", "(", ")", ";", "}", "}" ]
Send notification to all subscriptions paired with specific user. @param int $userId @param string $msg @param string $dest @param bool $flush
[ "Send", "notification", "to", "all", "subscriptions", "paired", "with", "specific", "user", "." ]
63b41f62e0589a0ebac698abd1b8cf65abfcb1d5
https://github.com/nepttune/nepttune/blob/63b41f62e0589a0ebac698abd1b8cf65abfcb1d5/src/Model/PushNotificationModel.php#L81-L94