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 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
concrete5/concrete5 | concrete/src/Entity/LocaleTrait.php | LocaleTrait.getLanguageText | public function getLanguageText($locale = null)
{
try {
$text = PunicLanguage::getName($this->getLanguage(), $locale ?: '');
} catch (Exception $e) {
$text = $this->getLanguage();
} catch (Throwable $e) {
$text = $this->getLanguage();
}
return $text;
} | php | public function getLanguageText($locale = null)
{
try {
$text = PunicLanguage::getName($this->getLanguage(), $locale ?: '');
} catch (Exception $e) {
$text = $this->getLanguage();
} catch (Throwable $e) {
$text = $this->getLanguage();
}
return $text;
} | [
"public",
"function",
"getLanguageText",
"(",
"$",
"locale",
"=",
"null",
")",
"{",
"try",
"{",
"$",
"text",
"=",
"PunicLanguage",
"::",
"getName",
"(",
"$",
"this",
"->",
"getLanguage",
"(",
")",
",",
"$",
"locale",
"?",
":",
"''",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"text",
"=",
"$",
"this",
"->",
"getLanguage",
"(",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"e",
")",
"{",
"$",
"text",
"=",
"$",
"this",
"->",
"getLanguage",
"(",
")",
";",
"}",
"return",
"$",
"text",
";",
"}"
] | Get the display name of this locale.
@param string|null $locale The locale to be used to localize the locale name
@return string
@example <code>getLanguage('en_US')</code> returns the display name of this locale in American English
@example <code>getLanguage('it_IT')</code> returns the display name of this locale in Italian
@example <code>getLanguage()</code> returns the display name of this locale in the currently active locale | [
"Get",
"the",
"display",
"name",
"of",
"this",
"locale",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/LocaleTrait.php#L214-L225 | train |
concrete5/concrete5 | concrete/src/Workflow/Request/Request.php | Request.triggerRequest | protected function triggerRequest(\PermissionKey $pk)
{
if (!$this->wrID) {
$this->save();
}
if (!$pk->canPermissionKeyTriggerWorkflow()) {
throw new \Exception(t('This permission key cannot start a workflow.'));
}
$pa = $pk->getPermissionAccessObject();
$skipWorkflow = true;
if (is_object($pa)) {
$workflows = $pa->getWorkflows();
foreach ($workflows as $wf) {
if ($wf->validateTrigger($this)) {
$wp = $this->addWorkflowProgress($wf);
$response = $wp->getWorkflowProgressResponseObject();
if ($response instanceof SkippedResponse) {
// Since the response was skipped, we delete the workflow progress operation and keep moving.
$wp->delete();
} else {
$skipWorkflow = false;
}
$event = new GenericEvent();
$event->setArgument('progress', $wp);
Events::dispatch('workflow_triggered', $event);
}
}
}
if ($skipWorkflow) {
$defaultWorkflow = new EmptyWorkflow();
$wp = $this->addWorkflowProgress($defaultWorkflow);
$event = new GenericEvent();
$event->setArgument('progress', $wp);
Events::dispatch('workflow_triggered', $event);
return $wp->getWorkflowProgressResponseObject();
}
} | php | protected function triggerRequest(\PermissionKey $pk)
{
if (!$this->wrID) {
$this->save();
}
if (!$pk->canPermissionKeyTriggerWorkflow()) {
throw new \Exception(t('This permission key cannot start a workflow.'));
}
$pa = $pk->getPermissionAccessObject();
$skipWorkflow = true;
if (is_object($pa)) {
$workflows = $pa->getWorkflows();
foreach ($workflows as $wf) {
if ($wf->validateTrigger($this)) {
$wp = $this->addWorkflowProgress($wf);
$response = $wp->getWorkflowProgressResponseObject();
if ($response instanceof SkippedResponse) {
// Since the response was skipped, we delete the workflow progress operation and keep moving.
$wp->delete();
} else {
$skipWorkflow = false;
}
$event = new GenericEvent();
$event->setArgument('progress', $wp);
Events::dispatch('workflow_triggered', $event);
}
}
}
if ($skipWorkflow) {
$defaultWorkflow = new EmptyWorkflow();
$wp = $this->addWorkflowProgress($defaultWorkflow);
$event = new GenericEvent();
$event->setArgument('progress', $wp);
Events::dispatch('workflow_triggered', $event);
return $wp->getWorkflowProgressResponseObject();
}
} | [
"protected",
"function",
"triggerRequest",
"(",
"\\",
"PermissionKey",
"$",
"pk",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"wrID",
")",
"{",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"pk",
"->",
"canPermissionKeyTriggerWorkflow",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"t",
"(",
"'This permission key cannot start a workflow.'",
")",
")",
";",
"}",
"$",
"pa",
"=",
"$",
"pk",
"->",
"getPermissionAccessObject",
"(",
")",
";",
"$",
"skipWorkflow",
"=",
"true",
";",
"if",
"(",
"is_object",
"(",
"$",
"pa",
")",
")",
"{",
"$",
"workflows",
"=",
"$",
"pa",
"->",
"getWorkflows",
"(",
")",
";",
"foreach",
"(",
"$",
"workflows",
"as",
"$",
"wf",
")",
"{",
"if",
"(",
"$",
"wf",
"->",
"validateTrigger",
"(",
"$",
"this",
")",
")",
"{",
"$",
"wp",
"=",
"$",
"this",
"->",
"addWorkflowProgress",
"(",
"$",
"wf",
")",
";",
"$",
"response",
"=",
"$",
"wp",
"->",
"getWorkflowProgressResponseObject",
"(",
")",
";",
"if",
"(",
"$",
"response",
"instanceof",
"SkippedResponse",
")",
"{",
"// Since the response was skipped, we delete the workflow progress operation and keep moving.",
"$",
"wp",
"->",
"delete",
"(",
")",
";",
"}",
"else",
"{",
"$",
"skipWorkflow",
"=",
"false",
";",
"}",
"$",
"event",
"=",
"new",
"GenericEvent",
"(",
")",
";",
"$",
"event",
"->",
"setArgument",
"(",
"'progress'",
",",
"$",
"wp",
")",
";",
"Events",
"::",
"dispatch",
"(",
"'workflow_triggered'",
",",
"$",
"event",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"skipWorkflow",
")",
"{",
"$",
"defaultWorkflow",
"=",
"new",
"EmptyWorkflow",
"(",
")",
";",
"$",
"wp",
"=",
"$",
"this",
"->",
"addWorkflowProgress",
"(",
"$",
"defaultWorkflow",
")",
";",
"$",
"event",
"=",
"new",
"GenericEvent",
"(",
")",
";",
"$",
"event",
"->",
"setArgument",
"(",
"'progress'",
",",
"$",
"wp",
")",
";",
"Events",
"::",
"dispatch",
"(",
"'workflow_triggered'",
",",
"$",
"event",
")",
";",
"return",
"$",
"wp",
"->",
"getWorkflowProgressResponseObject",
"(",
")",
";",
"}",
"}"
] | Triggers a workflow request, queries a permission key to see what workflows are attached to it
and initiates them.
@param \PermissionKey $pk
@return optional WorkflowProgress | [
"Triggers",
"a",
"workflow",
"request",
"queries",
"a",
"permission",
"key",
"to",
"see",
"what",
"workflows",
"are",
"attached",
"to",
"it",
"and",
"initiates",
"them",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Workflow/Request/Request.php#L109-L150 | train |
concrete5/concrete5 | concrete/src/Entity/Attribute/Value/AbstractValue.php | AbstractValue.getPlainTextValue | public function getPlainTextValue()
{
$controller = $this->getController();
if (method_exists($controller, 'getPlainTextValue')) {
return $controller->getPlainTextValue();
}
if ($this->getValueObject()) {
return (string) $this->getValueObject();
}
// Legacy support.
if (method_exists($controller, 'getValue')) {
return $controller->getValue();
}
return '';
} | php | public function getPlainTextValue()
{
$controller = $this->getController();
if (method_exists($controller, 'getPlainTextValue')) {
return $controller->getPlainTextValue();
}
if ($this->getValueObject()) {
return (string) $this->getValueObject();
}
// Legacy support.
if (method_exists($controller, 'getValue')) {
return $controller->getValue();
}
return '';
} | [
"public",
"function",
"getPlainTextValue",
"(",
")",
"{",
"$",
"controller",
"=",
"$",
"this",
"->",
"getController",
"(",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"controller",
",",
"'getPlainTextValue'",
")",
")",
"{",
"return",
"$",
"controller",
"->",
"getPlainTextValue",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getValueObject",
"(",
")",
")",
"{",
"return",
"(",
"string",
")",
"$",
"this",
"->",
"getValueObject",
"(",
")",
";",
"}",
"// Legacy support.",
"if",
"(",
"method_exists",
"(",
"$",
"controller",
",",
"'getValue'",
")",
")",
"{",
"return",
"$",
"controller",
"->",
"getValue",
"(",
")",
";",
"}",
"return",
"''",
";",
"}"
] | Returns content that is useful in plain text contexts.
@return string | [
"Returns",
"content",
"that",
"is",
"useful",
"in",
"plain",
"text",
"contexts",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/Attribute/Value/AbstractValue.php#L163-L181 | train |
concrete5/concrete5 | concrete/src/Application/UserInterface/Sitemap/TreeCollection/TreeCollectionTransformer.php | TreeCollectionTransformer.transformEntry | private function transformEntry(Entry\EntryInterface $entry)
{
return [
'id' => $entry->getID(),
'name' => $entry->getLabel(),
'icon' => (string) $entry->getIcon()
];
} | php | private function transformEntry(Entry\EntryInterface $entry)
{
return [
'id' => $entry->getID(),
'name' => $entry->getLabel(),
'icon' => (string) $entry->getIcon()
];
} | [
"private",
"function",
"transformEntry",
"(",
"Entry",
"\\",
"EntryInterface",
"$",
"entry",
")",
"{",
"return",
"[",
"'id'",
"=>",
"$",
"entry",
"->",
"getID",
"(",
")",
",",
"'name'",
"=>",
"$",
"entry",
"->",
"getLabel",
"(",
")",
",",
"'icon'",
"=>",
"(",
"string",
")",
"$",
"entry",
"->",
"getIcon",
"(",
")",
"]",
";",
"}"
] | Convert an entry to an array
@param \Concrete\Core\Application\UserInterface\Sitemap\TreeCollection\Entry\EntryInterface $entry
@return array | [
"Convert",
"an",
"entry",
"to",
"an",
"array"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/UserInterface/Sitemap/TreeCollection/TreeCollectionTransformer.php#L14-L21 | train |
concrete5/concrete5 | concrete/src/Validator/String/EmailValidator.php | EmailValidator.checkEmail | protected function checkEmail($mixed)
{
$result = false;
if (is_string($mixed) && $mixed !== '') {
$eev = $this->getEguliasEmailValidator();
$testMX = $this->isTestMXRecord();
if ($eev->isValid($mixed, $testMX, $this->isStrict())) {
if ($testMX) {
$result = !in_array(EguliasEmailValidator::DNSWARN_NO_RECORD, $eev->getWarnings(), true);
} else {
$result = true;
}
}
}
return $result;
} | php | protected function checkEmail($mixed)
{
$result = false;
if (is_string($mixed) && $mixed !== '') {
$eev = $this->getEguliasEmailValidator();
$testMX = $this->isTestMXRecord();
if ($eev->isValid($mixed, $testMX, $this->isStrict())) {
if ($testMX) {
$result = !in_array(EguliasEmailValidator::DNSWARN_NO_RECORD, $eev->getWarnings(), true);
} else {
$result = true;
}
}
}
return $result;
} | [
"protected",
"function",
"checkEmail",
"(",
"$",
"mixed",
")",
"{",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"is_string",
"(",
"$",
"mixed",
")",
"&&",
"$",
"mixed",
"!==",
"''",
")",
"{",
"$",
"eev",
"=",
"$",
"this",
"->",
"getEguliasEmailValidator",
"(",
")",
";",
"$",
"testMX",
"=",
"$",
"this",
"->",
"isTestMXRecord",
"(",
")",
";",
"if",
"(",
"$",
"eev",
"->",
"isValid",
"(",
"$",
"mixed",
",",
"$",
"testMX",
",",
"$",
"this",
"->",
"isStrict",
"(",
")",
")",
")",
"{",
"if",
"(",
"$",
"testMX",
")",
"{",
"$",
"result",
"=",
"!",
"in_array",
"(",
"EguliasEmailValidator",
"::",
"DNSWARN_NO_RECORD",
",",
"$",
"eev",
"->",
"getWarnings",
"(",
")",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"true",
";",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Actually check if an email address is valid.
@param string|mixed $mixed
@return bool | [
"Actually",
"check",
"if",
"an",
"email",
"address",
"is",
"valid",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Validator/String/EmailValidator.php#L146-L162 | train |
concrete5/concrete5 | concrete/src/Html/Service/Navigation.php | Navigation.getTrailToCollection | public function getTrailToCollection($c)
{
$db = Database::connection();
$cArray = array();
$currentcParentID = $c->getCollectionParentID();
if ($currentcParentID > 0) {
while (is_numeric($currentcParentID) && $currentcParentID > 0 && $currentcParentID) {
$q = "select cID, cParentID from Pages where cID = '{$currentcParentID}'";
$r = $db->query($q);
$row = $r->fetchRow();
if ($row['cID']) {
$cArray[] = Page::getByID($row['cID'], 'ACTIVE');
}
$currentcParentID = $row['cParentID']; // moving up the tree until we hit 1
}
}
return $cArray;
} | php | public function getTrailToCollection($c)
{
$db = Database::connection();
$cArray = array();
$currentcParentID = $c->getCollectionParentID();
if ($currentcParentID > 0) {
while (is_numeric($currentcParentID) && $currentcParentID > 0 && $currentcParentID) {
$q = "select cID, cParentID from Pages where cID = '{$currentcParentID}'";
$r = $db->query($q);
$row = $r->fetchRow();
if ($row['cID']) {
$cArray[] = Page::getByID($row['cID'], 'ACTIVE');
}
$currentcParentID = $row['cParentID']; // moving up the tree until we hit 1
}
}
return $cArray;
} | [
"public",
"function",
"getTrailToCollection",
"(",
"$",
"c",
")",
"{",
"$",
"db",
"=",
"Database",
"::",
"connection",
"(",
")",
";",
"$",
"cArray",
"=",
"array",
"(",
")",
";",
"$",
"currentcParentID",
"=",
"$",
"c",
"->",
"getCollectionParentID",
"(",
")",
";",
"if",
"(",
"$",
"currentcParentID",
">",
"0",
")",
"{",
"while",
"(",
"is_numeric",
"(",
"$",
"currentcParentID",
")",
"&&",
"$",
"currentcParentID",
">",
"0",
"&&",
"$",
"currentcParentID",
")",
"{",
"$",
"q",
"=",
"\"select cID, cParentID from Pages where cID = '{$currentcParentID}'\"",
";",
"$",
"r",
"=",
"$",
"db",
"->",
"query",
"(",
"$",
"q",
")",
";",
"$",
"row",
"=",
"$",
"r",
"->",
"fetchRow",
"(",
")",
";",
"if",
"(",
"$",
"row",
"[",
"'cID'",
"]",
")",
"{",
"$",
"cArray",
"[",
"]",
"=",
"Page",
"::",
"getByID",
"(",
"$",
"row",
"[",
"'cID'",
"]",
",",
"'ACTIVE'",
")",
";",
"}",
"$",
"currentcParentID",
"=",
"$",
"row",
"[",
"'cParentID'",
"]",
";",
"// moving up the tree until we hit 1",
"}",
"}",
"return",
"$",
"cArray",
";",
"}"
] | Returns an array of collections as a breadcrumb to the current page.
@param Page $c
@return Page[] | [
"Returns",
"an",
"array",
"of",
"collections",
"as",
"a",
"breadcrumb",
"to",
"the",
"current",
"page",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Html/Service/Navigation.php#L33-L53 | train |
concrete5/concrete5 | concrete/src/Cache/OpCache.php | OpCache.clear | public static function clear($file = null)
{
if (static::hasEAccelerator()) {
if (function_exists('eeaccelerator_clear')) {
$paths = @ini_get('eaccelerator.allowed_admin_path');
if (is_string($paths) && ($paths !== '')) {
$myPath = str_replace(DIRECTORY_SEPARATOR, '/', __DIR__);
foreach (explode(PATH_SEPARATOR, $paths) as $path) {
$path = str_replace(DIRECTORY_SEPARATOR, '/', $path);
if ($path !== '') {
$path = rtrim($path, '/');
if (($path === $myPath) || (strpos($myPath, $path.'/') === 0)) {
@eeaccelerator_clear();
break;
}
}
}
}
}
}
if (static::hasAPC()) {
if (function_exists('apc_clear_cache')) {
@apc_clear_cache('system');
}
}
if (static::hasXCache()) {
if (function_exists('xcache_clear_cache') && ini_get('xcache.admin.user') && ini_get('xcache.admin.pass')) {
@xcache_clear_cache(XC_TYPE_PHP, 0);
}
}
if (static::hasWinCache()) {
if (function_exists('wincache_refresh_if_changed')) {
if ($file) {
@wincache_refresh_if_changed((array) $file);
} else {
@wincache_refresh_if_changed();
}
}
}
if (static::hasZendOpCache()) {
if ($file && function_exists('opcache_invalidate')) {
@opcache_invalidate($file, true);
} elseif (function_exists('opcache_reset')) {
@opcache_reset();
}
}
} | php | public static function clear($file = null)
{
if (static::hasEAccelerator()) {
if (function_exists('eeaccelerator_clear')) {
$paths = @ini_get('eaccelerator.allowed_admin_path');
if (is_string($paths) && ($paths !== '')) {
$myPath = str_replace(DIRECTORY_SEPARATOR, '/', __DIR__);
foreach (explode(PATH_SEPARATOR, $paths) as $path) {
$path = str_replace(DIRECTORY_SEPARATOR, '/', $path);
if ($path !== '') {
$path = rtrim($path, '/');
if (($path === $myPath) || (strpos($myPath, $path.'/') === 0)) {
@eeaccelerator_clear();
break;
}
}
}
}
}
}
if (static::hasAPC()) {
if (function_exists('apc_clear_cache')) {
@apc_clear_cache('system');
}
}
if (static::hasXCache()) {
if (function_exists('xcache_clear_cache') && ini_get('xcache.admin.user') && ini_get('xcache.admin.pass')) {
@xcache_clear_cache(XC_TYPE_PHP, 0);
}
}
if (static::hasWinCache()) {
if (function_exists('wincache_refresh_if_changed')) {
if ($file) {
@wincache_refresh_if_changed((array) $file);
} else {
@wincache_refresh_if_changed();
}
}
}
if (static::hasZendOpCache()) {
if ($file && function_exists('opcache_invalidate')) {
@opcache_invalidate($file, true);
} elseif (function_exists('opcache_reset')) {
@opcache_reset();
}
}
} | [
"public",
"static",
"function",
"clear",
"(",
"$",
"file",
"=",
"null",
")",
"{",
"if",
"(",
"static",
"::",
"hasEAccelerator",
"(",
")",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'eeaccelerator_clear'",
")",
")",
"{",
"$",
"paths",
"=",
"@",
"ini_get",
"(",
"'eaccelerator.allowed_admin_path'",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"paths",
")",
"&&",
"(",
"$",
"paths",
"!==",
"''",
")",
")",
"{",
"$",
"myPath",
"=",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"'/'",
",",
"__DIR__",
")",
";",
"foreach",
"(",
"explode",
"(",
"PATH_SEPARATOR",
",",
"$",
"paths",
")",
"as",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"'/'",
",",
"$",
"path",
")",
";",
"if",
"(",
"$",
"path",
"!==",
"''",
")",
"{",
"$",
"path",
"=",
"rtrim",
"(",
"$",
"path",
",",
"'/'",
")",
";",
"if",
"(",
"(",
"$",
"path",
"===",
"$",
"myPath",
")",
"||",
"(",
"strpos",
"(",
"$",
"myPath",
",",
"$",
"path",
".",
"'/'",
")",
"===",
"0",
")",
")",
"{",
"@",
"eeaccelerator_clear",
"(",
")",
";",
"break",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"if",
"(",
"static",
"::",
"hasAPC",
"(",
")",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'apc_clear_cache'",
")",
")",
"{",
"@",
"apc_clear_cache",
"(",
"'system'",
")",
";",
"}",
"}",
"if",
"(",
"static",
"::",
"hasXCache",
"(",
")",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'xcache_clear_cache'",
")",
"&&",
"ini_get",
"(",
"'xcache.admin.user'",
")",
"&&",
"ini_get",
"(",
"'xcache.admin.pass'",
")",
")",
"{",
"@",
"xcache_clear_cache",
"(",
"XC_TYPE_PHP",
",",
"0",
")",
";",
"}",
"}",
"if",
"(",
"static",
"::",
"hasWinCache",
"(",
")",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'wincache_refresh_if_changed'",
")",
")",
"{",
"if",
"(",
"$",
"file",
")",
"{",
"@",
"wincache_refresh_if_changed",
"(",
"(",
"array",
")",
"$",
"file",
")",
";",
"}",
"else",
"{",
"@",
"wincache_refresh_if_changed",
"(",
")",
";",
"}",
"}",
"}",
"if",
"(",
"static",
"::",
"hasZendOpCache",
"(",
")",
")",
"{",
"if",
"(",
"$",
"file",
"&&",
"function_exists",
"(",
"'opcache_invalidate'",
")",
")",
"{",
"@",
"opcache_invalidate",
"(",
"$",
"file",
",",
"true",
")",
";",
"}",
"elseif",
"(",
"function_exists",
"(",
"'opcache_reset'",
")",
")",
"{",
"@",
"opcache_reset",
"(",
")",
";",
"}",
"}",
"}"
] | Clear the opcache.
@param string|null $file If it's specified, we'll try to clear the cache only for this file | [
"Clear",
"the",
"opcache",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Cache/OpCache.php#L14-L60 | train |
concrete5/concrete5 | concrete/src/User/Notification/UserNotificationEventHandler.php | UserNotificationEventHandler.deactivated | public function deactivated(DeactivateUser $event)
{
/** @var UserDeactivatedType $type */
$type = $this->notificationManager->driver(UserDeactivatedType::IDENTIFIER);
$notifier = $type->getNotifier();
if (method_exists($notifier, 'notify')) {
$subscription = $type->getSubscription($event);
$users = $notifier->getUsersToNotify($subscription, $event);
$notification = new UserDeactivatedNotification($event);
$notifier->notify($users, $notification);
}
} | php | public function deactivated(DeactivateUser $event)
{
/** @var UserDeactivatedType $type */
$type = $this->notificationManager->driver(UserDeactivatedType::IDENTIFIER);
$notifier = $type->getNotifier();
if (method_exists($notifier, 'notify')) {
$subscription = $type->getSubscription($event);
$users = $notifier->getUsersToNotify($subscription, $event);
$notification = new UserDeactivatedNotification($event);
$notifier->notify($users, $notification);
}
} | [
"public",
"function",
"deactivated",
"(",
"DeactivateUser",
"$",
"event",
")",
"{",
"/** @var UserDeactivatedType $type */",
"$",
"type",
"=",
"$",
"this",
"->",
"notificationManager",
"->",
"driver",
"(",
"UserDeactivatedType",
"::",
"IDENTIFIER",
")",
";",
"$",
"notifier",
"=",
"$",
"type",
"->",
"getNotifier",
"(",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"notifier",
",",
"'notify'",
")",
")",
"{",
"$",
"subscription",
"=",
"$",
"type",
"->",
"getSubscription",
"(",
"$",
"event",
")",
";",
"$",
"users",
"=",
"$",
"notifier",
"->",
"getUsersToNotify",
"(",
"$",
"subscription",
",",
"$",
"event",
")",
";",
"$",
"notification",
"=",
"new",
"UserDeactivatedNotification",
"(",
"$",
"event",
")",
";",
"$",
"notifier",
"->",
"notify",
"(",
"$",
"users",
",",
"$",
"notification",
")",
";",
"}",
"}"
] | Handle deactivated user events
@param \Concrete\Core\User\Event\DeactivateUser $event | [
"Handle",
"deactivated",
"user",
"events"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/User/Notification/UserNotificationEventHandler.php#L34-L46 | train |
concrete5/concrete5 | concrete/src/Permission/Response/Response.php | Response.getResponse | public static function getResponse($object)
{
$cache = Core::make('cache/request');
$identifier = sprintf('permission/response/%s/%s', get_class($object), $object->getPermissionObjectIdentifier());
$item = $cache->getItem($identifier);
if (!$item->isMiss()) {
return $item->get();
}
$className = $object->getPermissionResponseClassName();
/** @var \Concrete\Core\Permission\Response\Response $pr */
$pr = Core::make($className);
if ($object->getPermissionObjectKeyCategoryHandle()) {
$category = PermissionKeyCategory::getByHandle($object->getPermissionObjectKeyCategoryHandle());
$pr->setPermissionCategoryObject($category);
}
$pr->setPermissionObject($object);
$cache->save($item->set($pr));
return $pr;
} | php | public static function getResponse($object)
{
$cache = Core::make('cache/request');
$identifier = sprintf('permission/response/%s/%s', get_class($object), $object->getPermissionObjectIdentifier());
$item = $cache->getItem($identifier);
if (!$item->isMiss()) {
return $item->get();
}
$className = $object->getPermissionResponseClassName();
/** @var \Concrete\Core\Permission\Response\Response $pr */
$pr = Core::make($className);
if ($object->getPermissionObjectKeyCategoryHandle()) {
$category = PermissionKeyCategory::getByHandle($object->getPermissionObjectKeyCategoryHandle());
$pr->setPermissionCategoryObject($category);
}
$pr->setPermissionObject($object);
$cache->save($item->set($pr));
return $pr;
} | [
"public",
"static",
"function",
"getResponse",
"(",
"$",
"object",
")",
"{",
"$",
"cache",
"=",
"Core",
"::",
"make",
"(",
"'cache/request'",
")",
";",
"$",
"identifier",
"=",
"sprintf",
"(",
"'permission/response/%s/%s'",
",",
"get_class",
"(",
"$",
"object",
")",
",",
"$",
"object",
"->",
"getPermissionObjectIdentifier",
"(",
")",
")",
";",
"$",
"item",
"=",
"$",
"cache",
"->",
"getItem",
"(",
"$",
"identifier",
")",
";",
"if",
"(",
"!",
"$",
"item",
"->",
"isMiss",
"(",
")",
")",
"{",
"return",
"$",
"item",
"->",
"get",
"(",
")",
";",
"}",
"$",
"className",
"=",
"$",
"object",
"->",
"getPermissionResponseClassName",
"(",
")",
";",
"/** @var \\Concrete\\Core\\Permission\\Response\\Response $pr */",
"$",
"pr",
"=",
"Core",
"::",
"make",
"(",
"$",
"className",
")",
";",
"if",
"(",
"$",
"object",
"->",
"getPermissionObjectKeyCategoryHandle",
"(",
")",
")",
"{",
"$",
"category",
"=",
"PermissionKeyCategory",
"::",
"getByHandle",
"(",
"$",
"object",
"->",
"getPermissionObjectKeyCategoryHandle",
"(",
")",
")",
";",
"$",
"pr",
"->",
"setPermissionCategoryObject",
"(",
"$",
"category",
")",
";",
"}",
"$",
"pr",
"->",
"setPermissionObject",
"(",
"$",
"object",
")",
";",
"$",
"cache",
"->",
"save",
"(",
"$",
"item",
"->",
"set",
"(",
"$",
"pr",
")",
")",
";",
"return",
"$",
"pr",
";",
"}"
] | Passing in any object that implements the ObjectInterface, retrieve the Permission Response object.
@param \Concrete\Core\Permission\ObjectInterface $object
@return \Concrete\Core\Permission\Response\Response | [
"Passing",
"in",
"any",
"object",
"that",
"implements",
"the",
"ObjectInterface",
"retrieve",
"the",
"Permission",
"Response",
"object",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Response/Response.php#L62-L82 | train |
concrete5/concrete5 | concrete/src/Permission/Response/Response.php | Response.validate | public function validate($permissionHandle, $args = array())
{
$u = new User();
if ($u->isSuperUser()) {
return true;
}
if (!is_object($this->category)) {
throw new Exception(t('Unable to get category for permission %s', $permissionHandle));
}
$pk = $this->category->getPermissionKeyByHandle($permissionHandle);
if (!$pk) {
throw new Exception(t('Unable to get permission key for %s', $permissionHandle));
}
$pk->setPermissionObject($this->object);
return call_user_func_array(array($pk, 'validate'), $args);
} | php | public function validate($permissionHandle, $args = array())
{
$u = new User();
if ($u->isSuperUser()) {
return true;
}
if (!is_object($this->category)) {
throw new Exception(t('Unable to get category for permission %s', $permissionHandle));
}
$pk = $this->category->getPermissionKeyByHandle($permissionHandle);
if (!$pk) {
throw new Exception(t('Unable to get permission key for %s', $permissionHandle));
}
$pk->setPermissionObject($this->object);
return call_user_func_array(array($pk, 'validate'), $args);
} | [
"public",
"function",
"validate",
"(",
"$",
"permissionHandle",
",",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"$",
"u",
"=",
"new",
"User",
"(",
")",
";",
"if",
"(",
"$",
"u",
"->",
"isSuperUser",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"is_object",
"(",
"$",
"this",
"->",
"category",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"t",
"(",
"'Unable to get category for permission %s'",
",",
"$",
"permissionHandle",
")",
")",
";",
"}",
"$",
"pk",
"=",
"$",
"this",
"->",
"category",
"->",
"getPermissionKeyByHandle",
"(",
"$",
"permissionHandle",
")",
";",
"if",
"(",
"!",
"$",
"pk",
")",
"{",
"throw",
"new",
"Exception",
"(",
"t",
"(",
"'Unable to get permission key for %s'",
",",
"$",
"permissionHandle",
")",
")",
";",
"}",
"$",
"pk",
"->",
"setPermissionObject",
"(",
"$",
"this",
"->",
"object",
")",
";",
"return",
"call_user_func_array",
"(",
"array",
"(",
"$",
"pk",
",",
"'validate'",
")",
",",
"$",
"args",
")",
";",
"}"
] | This function returns true if the user has permission to the object, or false if they do not have access.
@param string $permissionHandle A Permission Key Handle
@param array $args Arguments to pass to the PermissionKey object's validate function
@return bool
@throws Exception | [
"This",
"function",
"returns",
"true",
"if",
"the",
"user",
"has",
"permission",
"to",
"the",
"object",
"or",
"false",
"if",
"they",
"do",
"not",
"have",
"access",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Response/Response.php#L94-L110 | train |
concrete5/concrete5 | concrete/src/Block/BlockController.php | BlockController.performSave | protected function performSave($args, $loadExisting = false)
{
//$argsMerged = array_merge($_POST, $args);
if ($this->btTable) {
$db = Database::connection();
$columns = $db->MetaColumnNames($this->btTable);
$this->record = new BlockRecord($this->btTable);
$this->record->bID = $this->bID;
if ($loadExisting) {
$this->record->Load('bID=' . $this->bID);
}
if ($this->supportSavingNullValues) {
foreach ($columns as $key) {
if (array_key_exists($key, $args)) {
$this->record->{$key} = $args[$key];
}
}
} else {
foreach ($columns as $key) {
if (isset($args[$key])) {
$this->record->{$key} = $args[$key];
}
}
}
$this->record->Replace();
if ($this->cacheBlockRecord() && Config::get('concrete.cache.blocks')) {
$record = base64_encode(serialize($this->record));
$db = Database::connection();
$db->Execute('update Blocks set btCachedBlockRecord = ? where bID = ?', [$record, $this->bID]);
}
}
} | php | protected function performSave($args, $loadExisting = false)
{
//$argsMerged = array_merge($_POST, $args);
if ($this->btTable) {
$db = Database::connection();
$columns = $db->MetaColumnNames($this->btTable);
$this->record = new BlockRecord($this->btTable);
$this->record->bID = $this->bID;
if ($loadExisting) {
$this->record->Load('bID=' . $this->bID);
}
if ($this->supportSavingNullValues) {
foreach ($columns as $key) {
if (array_key_exists($key, $args)) {
$this->record->{$key} = $args[$key];
}
}
} else {
foreach ($columns as $key) {
if (isset($args[$key])) {
$this->record->{$key} = $args[$key];
}
}
}
$this->record->Replace();
if ($this->cacheBlockRecord() && Config::get('concrete.cache.blocks')) {
$record = base64_encode(serialize($this->record));
$db = Database::connection();
$db->Execute('update Blocks set btCachedBlockRecord = ? where bID = ?', [$record, $this->bID]);
}
}
} | [
"protected",
"function",
"performSave",
"(",
"$",
"args",
",",
"$",
"loadExisting",
"=",
"false",
")",
"{",
"//$argsMerged = array_merge($_POST, $args);",
"if",
"(",
"$",
"this",
"->",
"btTable",
")",
"{",
"$",
"db",
"=",
"Database",
"::",
"connection",
"(",
")",
";",
"$",
"columns",
"=",
"$",
"db",
"->",
"MetaColumnNames",
"(",
"$",
"this",
"->",
"btTable",
")",
";",
"$",
"this",
"->",
"record",
"=",
"new",
"BlockRecord",
"(",
"$",
"this",
"->",
"btTable",
")",
";",
"$",
"this",
"->",
"record",
"->",
"bID",
"=",
"$",
"this",
"->",
"bID",
";",
"if",
"(",
"$",
"loadExisting",
")",
"{",
"$",
"this",
"->",
"record",
"->",
"Load",
"(",
"'bID='",
".",
"$",
"this",
"->",
"bID",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"supportSavingNullValues",
")",
"{",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"args",
")",
")",
"{",
"$",
"this",
"->",
"record",
"->",
"{",
"$",
"key",
"}",
"=",
"$",
"args",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"args",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"record",
"->",
"{",
"$",
"key",
"}",
"=",
"$",
"args",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"record",
"->",
"Replace",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"cacheBlockRecord",
"(",
")",
"&&",
"Config",
"::",
"get",
"(",
"'concrete.cache.blocks'",
")",
")",
"{",
"$",
"record",
"=",
"base64_encode",
"(",
"serialize",
"(",
"$",
"this",
"->",
"record",
")",
")",
";",
"$",
"db",
"=",
"Database",
"::",
"connection",
"(",
")",
";",
"$",
"db",
"->",
"Execute",
"(",
"'update Blocks set btCachedBlockRecord = ? where bID = ?'",
",",
"[",
"$",
"record",
",",
"$",
"this",
"->",
"bID",
"]",
")",
";",
"}",
"}",
"}"
] | Persist the block options.
@param array $args An array that contains the block options
@param bool $loadExisting Shall we initialize the record to be saved with the current data? | [
"Persist",
"the",
"block",
"options",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Block/BlockController.php#L168-L201 | train |
concrete5/concrete5 | concrete/src/Block/BlockController.php | BlockController.load | protected function load()
{
if ($this->btTable) {
if ($this->btCacheBlockRecord && $this->btCachedBlockRecord && Config::get('concrete.cache.blocks')) {
$this->record = unserialize(base64_decode($this->btCachedBlockRecord));
} else {
$this->record = new BlockRecord($this->btTable);
$this->record->bID = $this->bID;
$this->record->Load('bID=' . $this->bID);
if ($this->btCacheBlockRecord && Config::get('concrete.cache.blocks')) {
// this is the first time we're loading
$record = base64_encode(serialize($this->record));
$db = Database::connection();
$db->Execute('update Blocks set btCachedBlockRecord = ? where bID = ?', [$record, $this->bID]);
}
}
}
$event = new \Symfony\Component\EventDispatcher\GenericEvent();
$event->setArgument('record', $this->record);
$event->setArgument('btHandle', $this->btHandle);
$event->setArgument('bID', $this->bID);
$ret = Events::dispatch('on_block_load', $event);
$this->record = $ret->getArgument('record');
if (is_object($this->record)) {
foreach ($this->record as $key => $value) {
$this->{$key} = $value;
$this->set($key, $value);
}
}
} | php | protected function load()
{
if ($this->btTable) {
if ($this->btCacheBlockRecord && $this->btCachedBlockRecord && Config::get('concrete.cache.blocks')) {
$this->record = unserialize(base64_decode($this->btCachedBlockRecord));
} else {
$this->record = new BlockRecord($this->btTable);
$this->record->bID = $this->bID;
$this->record->Load('bID=' . $this->bID);
if ($this->btCacheBlockRecord && Config::get('concrete.cache.blocks')) {
// this is the first time we're loading
$record = base64_encode(serialize($this->record));
$db = Database::connection();
$db->Execute('update Blocks set btCachedBlockRecord = ? where bID = ?', [$record, $this->bID]);
}
}
}
$event = new \Symfony\Component\EventDispatcher\GenericEvent();
$event->setArgument('record', $this->record);
$event->setArgument('btHandle', $this->btHandle);
$event->setArgument('bID', $this->bID);
$ret = Events::dispatch('on_block_load', $event);
$this->record = $ret->getArgument('record');
if (is_object($this->record)) {
foreach ($this->record as $key => $value) {
$this->{$key} = $value;
$this->set($key, $value);
}
}
} | [
"protected",
"function",
"load",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"btTable",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"btCacheBlockRecord",
"&&",
"$",
"this",
"->",
"btCachedBlockRecord",
"&&",
"Config",
"::",
"get",
"(",
"'concrete.cache.blocks'",
")",
")",
"{",
"$",
"this",
"->",
"record",
"=",
"unserialize",
"(",
"base64_decode",
"(",
"$",
"this",
"->",
"btCachedBlockRecord",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"record",
"=",
"new",
"BlockRecord",
"(",
"$",
"this",
"->",
"btTable",
")",
";",
"$",
"this",
"->",
"record",
"->",
"bID",
"=",
"$",
"this",
"->",
"bID",
";",
"$",
"this",
"->",
"record",
"->",
"Load",
"(",
"'bID='",
".",
"$",
"this",
"->",
"bID",
")",
";",
"if",
"(",
"$",
"this",
"->",
"btCacheBlockRecord",
"&&",
"Config",
"::",
"get",
"(",
"'concrete.cache.blocks'",
")",
")",
"{",
"// this is the first time we're loading",
"$",
"record",
"=",
"base64_encode",
"(",
"serialize",
"(",
"$",
"this",
"->",
"record",
")",
")",
";",
"$",
"db",
"=",
"Database",
"::",
"connection",
"(",
")",
";",
"$",
"db",
"->",
"Execute",
"(",
"'update Blocks set btCachedBlockRecord = ? where bID = ?'",
",",
"[",
"$",
"record",
",",
"$",
"this",
"->",
"bID",
"]",
")",
";",
"}",
"}",
"}",
"$",
"event",
"=",
"new",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"EventDispatcher",
"\\",
"GenericEvent",
"(",
")",
";",
"$",
"event",
"->",
"setArgument",
"(",
"'record'",
",",
"$",
"this",
"->",
"record",
")",
";",
"$",
"event",
"->",
"setArgument",
"(",
"'btHandle'",
",",
"$",
"this",
"->",
"btHandle",
")",
";",
"$",
"event",
"->",
"setArgument",
"(",
"'bID'",
",",
"$",
"this",
"->",
"bID",
")",
";",
"$",
"ret",
"=",
"Events",
"::",
"dispatch",
"(",
"'on_block_load'",
",",
"$",
"event",
")",
";",
"$",
"this",
"->",
"record",
"=",
"$",
"ret",
"->",
"getArgument",
"(",
"'record'",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"this",
"->",
"record",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"record",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"{",
"$",
"key",
"}",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"}"
] | Loads the BlockRecord class based on its attribute names. | [
"Loads",
"the",
"BlockRecord",
"class",
"based",
"on",
"its",
"attribute",
"names",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Block/BlockController.php#L305-L336 | train |
concrete5/concrete5 | concrete/src/Block/BlockController.php | BlockController.getActionURL | public function getActionURL($task)
{
try {
if (is_object($this->block)) {
if (is_object($this->block->getProxyBlock())) {
$b = $this->block->getProxyBlock();
} else {
$b = $this->block;
}
$action = $this->getAction();
if ($action === 'view' || strpos($action, 'action_') === 0) {
$c = Page::getCurrentPage();
if (is_object($b) && is_object($c)) {
$arguments = func_get_args();
$arguments[] = $b->getBlockID();
array_unshift($arguments, $c);
return call_user_func_array(array('\URL', 'page'), $arguments);
}
} else {
$c = $this->getCollectionObject();
$arguments = array_merge(array('/ccm/system/block/action/edit',
$c->getCollectionID(),
urlencode($this->getAreaObject()->getAreaHandle()),
$this->block->getBlockID(),
), func_get_args());
return call_user_func_array(array('\URL', 'to'), $arguments);
}
} else {
$c = \Page::getCurrentPage();
$arguments = array_merge(array('/ccm/system/block/action/add',
$c->getCollectionID(),
urlencode($this->getAreaObject()->getAreaHandle()),
$this->getBlockTypeID(),
), func_get_args());
return call_user_func_array(array('\URL', 'to'), $arguments);
}
} catch (\Exception $e) {
}
} | php | public function getActionURL($task)
{
try {
if (is_object($this->block)) {
if (is_object($this->block->getProxyBlock())) {
$b = $this->block->getProxyBlock();
} else {
$b = $this->block;
}
$action = $this->getAction();
if ($action === 'view' || strpos($action, 'action_') === 0) {
$c = Page::getCurrentPage();
if (is_object($b) && is_object($c)) {
$arguments = func_get_args();
$arguments[] = $b->getBlockID();
array_unshift($arguments, $c);
return call_user_func_array(array('\URL', 'page'), $arguments);
}
} else {
$c = $this->getCollectionObject();
$arguments = array_merge(array('/ccm/system/block/action/edit',
$c->getCollectionID(),
urlencode($this->getAreaObject()->getAreaHandle()),
$this->block->getBlockID(),
), func_get_args());
return call_user_func_array(array('\URL', 'to'), $arguments);
}
} else {
$c = \Page::getCurrentPage();
$arguments = array_merge(array('/ccm/system/block/action/add',
$c->getCollectionID(),
urlencode($this->getAreaObject()->getAreaHandle()),
$this->getBlockTypeID(),
), func_get_args());
return call_user_func_array(array('\URL', 'to'), $arguments);
}
} catch (\Exception $e) {
}
} | [
"public",
"function",
"getActionURL",
"(",
"$",
"task",
")",
"{",
"try",
"{",
"if",
"(",
"is_object",
"(",
"$",
"this",
"->",
"block",
")",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"this",
"->",
"block",
"->",
"getProxyBlock",
"(",
")",
")",
")",
"{",
"$",
"b",
"=",
"$",
"this",
"->",
"block",
"->",
"getProxyBlock",
"(",
")",
";",
"}",
"else",
"{",
"$",
"b",
"=",
"$",
"this",
"->",
"block",
";",
"}",
"$",
"action",
"=",
"$",
"this",
"->",
"getAction",
"(",
")",
";",
"if",
"(",
"$",
"action",
"===",
"'view'",
"||",
"strpos",
"(",
"$",
"action",
",",
"'action_'",
")",
"===",
"0",
")",
"{",
"$",
"c",
"=",
"Page",
"::",
"getCurrentPage",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"b",
")",
"&&",
"is_object",
"(",
"$",
"c",
")",
")",
"{",
"$",
"arguments",
"=",
"func_get_args",
"(",
")",
";",
"$",
"arguments",
"[",
"]",
"=",
"$",
"b",
"->",
"getBlockID",
"(",
")",
";",
"array_unshift",
"(",
"$",
"arguments",
",",
"$",
"c",
")",
";",
"return",
"call_user_func_array",
"(",
"array",
"(",
"'\\URL'",
",",
"'page'",
")",
",",
"$",
"arguments",
")",
";",
"}",
"}",
"else",
"{",
"$",
"c",
"=",
"$",
"this",
"->",
"getCollectionObject",
"(",
")",
";",
"$",
"arguments",
"=",
"array_merge",
"(",
"array",
"(",
"'/ccm/system/block/action/edit'",
",",
"$",
"c",
"->",
"getCollectionID",
"(",
")",
",",
"urlencode",
"(",
"$",
"this",
"->",
"getAreaObject",
"(",
")",
"->",
"getAreaHandle",
"(",
")",
")",
",",
"$",
"this",
"->",
"block",
"->",
"getBlockID",
"(",
")",
",",
")",
",",
"func_get_args",
"(",
")",
")",
";",
"return",
"call_user_func_array",
"(",
"array",
"(",
"'\\URL'",
",",
"'to'",
")",
",",
"$",
"arguments",
")",
";",
"}",
"}",
"else",
"{",
"$",
"c",
"=",
"\\",
"Page",
"::",
"getCurrentPage",
"(",
")",
";",
"$",
"arguments",
"=",
"array_merge",
"(",
"array",
"(",
"'/ccm/system/block/action/add'",
",",
"$",
"c",
"->",
"getCollectionID",
"(",
")",
",",
"urlencode",
"(",
"$",
"this",
"->",
"getAreaObject",
"(",
")",
"->",
"getAreaHandle",
"(",
")",
")",
",",
"$",
"this",
"->",
"getBlockTypeID",
"(",
")",
",",
")",
",",
"func_get_args",
"(",
")",
")",
";",
"return",
"call_user_func_array",
"(",
"array",
"(",
"'\\URL'",
",",
"'to'",
")",
",",
"$",
"arguments",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"}",
"}"
] | Creates a URL that can be posted or navigated to that, when done so, will automatically run the corresponding method inside the block's controller.
It can also be used to perform system operations, accordingly to the current action.
@param mixed $task,... The arguments to build the URL (variable number of arguments).
@return \Concrete\Core\Url\UrlImmutable|null Return NULL in case of problems | [
"Creates",
"a",
"URL",
"that",
"can",
"be",
"posted",
"or",
"navigated",
"to",
"that",
"when",
"done",
"so",
"will",
"automatically",
"run",
"the",
"corresponding",
"method",
"inside",
"the",
"block",
"s",
"controller",
".",
"It",
"can",
"also",
"be",
"used",
"to",
"perform",
"system",
"operations",
"accordingly",
"to",
"the",
"current",
"action",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Block/BlockController.php#L546-L592 | train |
concrete5/concrete5 | concrete/src/Block/BlockController.php | BlockController.getBlockObject | public function getBlockObject()
{
if (is_object($this->block)) {
return $this->block;
}
return Block::getByID($this->bID);
} | php | public function getBlockObject()
{
if (is_object($this->block)) {
return $this->block;
}
return Block::getByID($this->bID);
} | [
"public",
"function",
"getBlockObject",
"(",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"this",
"->",
"block",
")",
")",
"{",
"return",
"$",
"this",
"->",
"block",
";",
"}",
"return",
"Block",
"::",
"getByID",
"(",
"$",
"this",
"->",
"bID",
")",
";",
"}"
] | Gets the generic Block object attached to this controller's instance.
@return Block $b | [
"Gets",
"the",
"generic",
"Block",
"object",
"attached",
"to",
"this",
"controller",
"s",
"instance",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Block/BlockController.php#L669-L676 | train |
concrete5/concrete5 | concrete/src/Block/BlockController.php | BlockController.delete | public function delete()
{
if ($this->bID > 0) {
if ($this->btTable) {
$ni = new BlockRecord($this->btTable);
$ni->bID = $this->bID;
$ni->Load('bID=' . $this->bID);
$ni->delete();
}
}
} | php | public function delete()
{
if ($this->bID > 0) {
if ($this->btTable) {
$ni = new BlockRecord($this->btTable);
$ni->bID = $this->bID;
$ni->Load('bID=' . $this->bID);
$ni->delete();
}
}
} | [
"public",
"function",
"delete",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"bID",
">",
"0",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"btTable",
")",
"{",
"$",
"ni",
"=",
"new",
"BlockRecord",
"(",
"$",
"this",
"->",
"btTable",
")",
";",
"$",
"ni",
"->",
"bID",
"=",
"$",
"this",
"->",
"bID",
";",
"$",
"ni",
"->",
"Load",
"(",
"'bID='",
".",
"$",
"this",
"->",
"bID",
")",
";",
"$",
"ni",
"->",
"delete",
"(",
")",
";",
"}",
"}",
"}"
] | Automatically run when a block is deleted. This removes the special data from the block's specific database table. If a block needs to do more than this this method should be overridden.
@return $void | [
"Automatically",
"run",
"when",
"a",
"block",
"is",
"deleted",
".",
"This",
"removes",
"the",
"special",
"data",
"from",
"the",
"block",
"s",
"specific",
"database",
"table",
".",
"If",
"a",
"block",
"needs",
"to",
"do",
"more",
"than",
"this",
"this",
"method",
"should",
"be",
"overridden",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Block/BlockController.php#L708-L718 | train |
concrete5/concrete5 | concrete/controllers/dialog/file/import.php | Import.setViewHelpers | protected function setViewHelpers()
{
$this->set('token', $this->app->make('token'));
$this->set('form', $this->app->make('helper/form'));
$this->set('ui', $this->app->make('helper/concrete/ui'));
$this->set('resolverManager', $this->app->make(ResolverManagerInterface::class));
} | php | protected function setViewHelpers()
{
$this->set('token', $this->app->make('token'));
$this->set('form', $this->app->make('helper/form'));
$this->set('ui', $this->app->make('helper/concrete/ui'));
$this->set('resolverManager', $this->app->make(ResolverManagerInterface::class));
} | [
"protected",
"function",
"setViewHelpers",
"(",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"'token'",
",",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'token'",
")",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'form'",
",",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'helper/form'",
")",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'ui'",
",",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'helper/concrete/ui'",
")",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'resolverManager'",
",",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"ResolverManagerInterface",
"::",
"class",
")",
")",
";",
"}"
] | Set the helpers for the view. | [
"Set",
"the",
"helpers",
"for",
"the",
"view",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/controllers/dialog/file/import.php#L56-L62 | train |
concrete5/concrete5 | concrete/controllers/dialog/file/import.php | Import.setViewSets | protected function setViewSets()
{
$config = $this->app->make('config');
$this->set('formID', 'ccm-file-manager-import-files-' . $this->app->make(Identifier::class)->getString(32));
$this->set('currentFolder', $this->getCurrentFolder());
$this->set('originalPage', $this->getOriginalPage());
$this->set('isChunkingEnabled', (bool) $config->get('concrete.upload.chunking.enabled'));
$chunkSize = (int) $config->get('concrete.upload.chunking.chunkSize');
if ($chunkSize < 1) {
$chunkSize = $this->getAutomaticChunkSize();
}
$this->set('chunkSize', $chunkSize);
$incoming = $this->app->make(Incoming::class);
$this->set('incomingStorageLocation', $incoming->getIncomingStorageLocation());
$this->set('incomingPath', $incoming->getIncomingPath());
try {
$incomingContents = $this->getIncomingFiles();
$incomingContentsError = null;
} catch (Exception $e) {
$incomingContents = [];
$incomingContentsError = $e->getMessage();
$incomingContents = $e;
} catch (Throwable $e) {
$incomingContents = [];
$incomingContentsError = $e->getMessage();
}
$this->set('incomingContents', $incomingContents);
$this->set('incomingContentsError', $incomingContentsError);
$this->set('replacingFile', null);
} | php | protected function setViewSets()
{
$config = $this->app->make('config');
$this->set('formID', 'ccm-file-manager-import-files-' . $this->app->make(Identifier::class)->getString(32));
$this->set('currentFolder', $this->getCurrentFolder());
$this->set('originalPage', $this->getOriginalPage());
$this->set('isChunkingEnabled', (bool) $config->get('concrete.upload.chunking.enabled'));
$chunkSize = (int) $config->get('concrete.upload.chunking.chunkSize');
if ($chunkSize < 1) {
$chunkSize = $this->getAutomaticChunkSize();
}
$this->set('chunkSize', $chunkSize);
$incoming = $this->app->make(Incoming::class);
$this->set('incomingStorageLocation', $incoming->getIncomingStorageLocation());
$this->set('incomingPath', $incoming->getIncomingPath());
try {
$incomingContents = $this->getIncomingFiles();
$incomingContentsError = null;
} catch (Exception $e) {
$incomingContents = [];
$incomingContentsError = $e->getMessage();
$incomingContents = $e;
} catch (Throwable $e) {
$incomingContents = [];
$incomingContentsError = $e->getMessage();
}
$this->set('incomingContents', $incomingContents);
$this->set('incomingContentsError', $incomingContentsError);
$this->set('replacingFile', null);
} | [
"protected",
"function",
"setViewSets",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'config'",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'formID'",
",",
"'ccm-file-manager-import-files-'",
".",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"Identifier",
"::",
"class",
")",
"->",
"getString",
"(",
"32",
")",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'currentFolder'",
",",
"$",
"this",
"->",
"getCurrentFolder",
"(",
")",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'originalPage'",
",",
"$",
"this",
"->",
"getOriginalPage",
"(",
")",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'isChunkingEnabled'",
",",
"(",
"bool",
")",
"$",
"config",
"->",
"get",
"(",
"'concrete.upload.chunking.enabled'",
")",
")",
";",
"$",
"chunkSize",
"=",
"(",
"int",
")",
"$",
"config",
"->",
"get",
"(",
"'concrete.upload.chunking.chunkSize'",
")",
";",
"if",
"(",
"$",
"chunkSize",
"<",
"1",
")",
"{",
"$",
"chunkSize",
"=",
"$",
"this",
"->",
"getAutomaticChunkSize",
"(",
")",
";",
"}",
"$",
"this",
"->",
"set",
"(",
"'chunkSize'",
",",
"$",
"chunkSize",
")",
";",
"$",
"incoming",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"Incoming",
"::",
"class",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'incomingStorageLocation'",
",",
"$",
"incoming",
"->",
"getIncomingStorageLocation",
"(",
")",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'incomingPath'",
",",
"$",
"incoming",
"->",
"getIncomingPath",
"(",
")",
")",
";",
"try",
"{",
"$",
"incomingContents",
"=",
"$",
"this",
"->",
"getIncomingFiles",
"(",
")",
";",
"$",
"incomingContentsError",
"=",
"null",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"incomingContents",
"=",
"[",
"]",
";",
"$",
"incomingContentsError",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"incomingContents",
"=",
"$",
"e",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"e",
")",
"{",
"$",
"incomingContents",
"=",
"[",
"]",
";",
"$",
"incomingContentsError",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"$",
"this",
"->",
"set",
"(",
"'incomingContents'",
",",
"$",
"incomingContents",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'incomingContentsError'",
",",
"$",
"incomingContentsError",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'replacingFile'",
",",
"null",
")",
";",
"}"
] | Set the variables for the view. | [
"Set",
"the",
"variables",
"for",
"the",
"view",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/controllers/dialog/file/import.php#L67-L96 | train |
concrete5/concrete5 | concrete/controllers/dialog/file/import.php | Import.getCurrentFolder | protected function getCurrentFolder()
{
if ($this->currentFolder === false) {
$currentFolder = null;
$fID = $this->request->request->get('currentFolder', $this->request->query->get('currentFolder'));
if ($fID && is_scalar($fID)) {
$fID = (int) $fID;
if ($fID !== 0) {
$node = Node::getByID($fID);
if ($node instanceof FileFolder) {
$currentFolder = $node;
}
}
}
$this->setCurrentFolder($currentFolder);
}
return $this->currentFolder;
} | php | protected function getCurrentFolder()
{
if ($this->currentFolder === false) {
$currentFolder = null;
$fID = $this->request->request->get('currentFolder', $this->request->query->get('currentFolder'));
if ($fID && is_scalar($fID)) {
$fID = (int) $fID;
if ($fID !== 0) {
$node = Node::getByID($fID);
if ($node instanceof FileFolder) {
$currentFolder = $node;
}
}
}
$this->setCurrentFolder($currentFolder);
}
return $this->currentFolder;
} | [
"protected",
"function",
"getCurrentFolder",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"currentFolder",
"===",
"false",
")",
"{",
"$",
"currentFolder",
"=",
"null",
";",
"$",
"fID",
"=",
"$",
"this",
"->",
"request",
"->",
"request",
"->",
"get",
"(",
"'currentFolder'",
",",
"$",
"this",
"->",
"request",
"->",
"query",
"->",
"get",
"(",
"'currentFolder'",
")",
")",
";",
"if",
"(",
"$",
"fID",
"&&",
"is_scalar",
"(",
"$",
"fID",
")",
")",
"{",
"$",
"fID",
"=",
"(",
"int",
")",
"$",
"fID",
";",
"if",
"(",
"$",
"fID",
"!==",
"0",
")",
"{",
"$",
"node",
"=",
"Node",
"::",
"getByID",
"(",
"$",
"fID",
")",
";",
"if",
"(",
"$",
"node",
"instanceof",
"FileFolder",
")",
"{",
"$",
"currentFolder",
"=",
"$",
"node",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"setCurrentFolder",
"(",
"$",
"currentFolder",
")",
";",
"}",
"return",
"$",
"this",
"->",
"currentFolder",
";",
"}"
] | Get the current folder.
@return \Concrete\Core\Tree\Node\Type\FileFolder|null null if global folder, FileFolder instance otherwise | [
"Get",
"the",
"current",
"folder",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/controllers/dialog/file/import.php#L103-L121 | train |
concrete5/concrete5 | concrete/controllers/dialog/file/import.php | Import.setCurrentFolder | protected function setCurrentFolder(FileFolder $value = null)
{
if ($value !== $this->currentFolder) {
$this->currentFolder = $value;
$this->currentFolderPermissions = null;
}
return $this;
} | php | protected function setCurrentFolder(FileFolder $value = null)
{
if ($value !== $this->currentFolder) {
$this->currentFolder = $value;
$this->currentFolderPermissions = null;
}
return $this;
} | [
"protected",
"function",
"setCurrentFolder",
"(",
"FileFolder",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"value",
"!==",
"$",
"this",
"->",
"currentFolder",
")",
"{",
"$",
"this",
"->",
"currentFolder",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"currentFolderPermissions",
"=",
"null",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the current folder.
@param \Concrete\Core\Tree\Node\Type\FileFolder|null $value null if global folder, FileFolder instance otherwise
@return $this | [
"Set",
"the",
"current",
"folder",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/controllers/dialog/file/import.php#L130-L138 | train |
concrete5/concrete5 | concrete/controllers/dialog/file/import.php | Import.getCurrentFolderPermissions | protected function getCurrentFolderPermissions()
{
if ($this->currentFolderPermissions === null) {
$folder = $this->getCurrentFolder();
if ($folder === null) {
$folder = $this->app->make(Filesystem::class)->getRootFolder();
if ($folder === null) {
$folder = new FileFolder();
}
}
$this->currentFolderPermissions = new Checker($folder);
}
return $this->currentFolderPermissions;
} | php | protected function getCurrentFolderPermissions()
{
if ($this->currentFolderPermissions === null) {
$folder = $this->getCurrentFolder();
if ($folder === null) {
$folder = $this->app->make(Filesystem::class)->getRootFolder();
if ($folder === null) {
$folder = new FileFolder();
}
}
$this->currentFolderPermissions = new Checker($folder);
}
return $this->currentFolderPermissions;
} | [
"protected",
"function",
"getCurrentFolderPermissions",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"currentFolderPermissions",
"===",
"null",
")",
"{",
"$",
"folder",
"=",
"$",
"this",
"->",
"getCurrentFolder",
"(",
")",
";",
"if",
"(",
"$",
"folder",
"===",
"null",
")",
"{",
"$",
"folder",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"Filesystem",
"::",
"class",
")",
"->",
"getRootFolder",
"(",
")",
";",
"if",
"(",
"$",
"folder",
"===",
"null",
")",
"{",
"$",
"folder",
"=",
"new",
"FileFolder",
"(",
")",
";",
"}",
"}",
"$",
"this",
"->",
"currentFolderPermissions",
"=",
"new",
"Checker",
"(",
"$",
"folder",
")",
";",
"}",
"return",
"$",
"this",
"->",
"currentFolderPermissions",
";",
"}"
] | Get the permissions for the current folder.
@return \Concrete\Core\Permission\Checker | [
"Get",
"the",
"permissions",
"for",
"the",
"current",
"folder",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/controllers/dialog/file/import.php#L145-L159 | train |
concrete5/concrete5 | concrete/controllers/dialog/file/import.php | Import.getOriginalPage | protected function getOriginalPage()
{
if ($this->originalPage === false) {
$originalPage = null;
$ocID = $this->request->request->get('ocID', $this->request->query->get('ocID'));
if ($ocID && is_scalar($ocID)) {
$ocID = (int) $ocID;
if ($ocID !== 0) {
$originalPage = Page::getByID($ocID);
}
}
$this->setOriginalPage($originalPage);
}
return $this->originalPage;
} | php | protected function getOriginalPage()
{
if ($this->originalPage === false) {
$originalPage = null;
$ocID = $this->request->request->get('ocID', $this->request->query->get('ocID'));
if ($ocID && is_scalar($ocID)) {
$ocID = (int) $ocID;
if ($ocID !== 0) {
$originalPage = Page::getByID($ocID);
}
}
$this->setOriginalPage($originalPage);
}
return $this->originalPage;
} | [
"protected",
"function",
"getOriginalPage",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"originalPage",
"===",
"false",
")",
"{",
"$",
"originalPage",
"=",
"null",
";",
"$",
"ocID",
"=",
"$",
"this",
"->",
"request",
"->",
"request",
"->",
"get",
"(",
"'ocID'",
",",
"$",
"this",
"->",
"request",
"->",
"query",
"->",
"get",
"(",
"'ocID'",
")",
")",
";",
"if",
"(",
"$",
"ocID",
"&&",
"is_scalar",
"(",
"$",
"ocID",
")",
")",
"{",
"$",
"ocID",
"=",
"(",
"int",
")",
"$",
"ocID",
";",
"if",
"(",
"$",
"ocID",
"!==",
"0",
")",
"{",
"$",
"originalPage",
"=",
"Page",
"::",
"getByID",
"(",
"$",
"ocID",
")",
";",
"}",
"}",
"$",
"this",
"->",
"setOriginalPage",
"(",
"$",
"originalPage",
")",
";",
"}",
"return",
"$",
"this",
"->",
"originalPage",
";",
"}"
] | Get the page where the file is originally placed on.
@return \Concrete\Core\Page\Page|null null: none; Page: specific page | [
"Get",
"the",
"page",
"where",
"the",
"file",
"is",
"originally",
"placed",
"on",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/controllers/dialog/file/import.php#L176-L191 | train |
concrete5/concrete5 | concrete/controllers/dialog/file/import.php | Import.setOriginalPage | protected function setOriginalPage(Page $value = null)
{
$this->originalPage = $value === null || $value->isError() ? null : $value;
return $this;
} | php | protected function setOriginalPage(Page $value = null)
{
$this->originalPage = $value === null || $value->isError() ? null : $value;
return $this;
} | [
"protected",
"function",
"setOriginalPage",
"(",
"Page",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"originalPage",
"=",
"$",
"value",
"===",
"null",
"||",
"$",
"value",
"->",
"isError",
"(",
")",
"?",
"null",
":",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Set the page where the file is originally placed on.
@param \Concrete\Core\Page\Page|null $value null: none; Page: specific page
@return $this | [
"Set",
"the",
"page",
"where",
"the",
"file",
"is",
"originally",
"placed",
"on",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/controllers/dialog/file/import.php#L200-L205 | train |
concrete5/concrete5 | concrete/controllers/dialog/file/import.php | Import.getAutomaticChunkSize | protected function getAutomaticChunkSize()
{
$nh = $this->app->make('helper/number');
// Maximum size of an uploaded file, minus a small value (just in case)
$uploadMaxFilesize = (int) $nh->getBytes(ini_get('upload_max_filesize')) - 100;
// Max size of post data allowed, minus enough space to consider other posted fields.
$postMaxSize = (int) $nh->getBytes(ini_get('post_max_size')) - 10000;
if ($uploadMaxFilesize < 1 && $postMaxSize < 1) {
return 2000000;
}
if ($uploadMaxFilesize < 1) {
return $postMaxSize;
}
if ($postMaxSize < 1) {
return $uploadMaxFilesize;
}
return min($uploadMaxFilesize, $postMaxSize);
} | php | protected function getAutomaticChunkSize()
{
$nh = $this->app->make('helper/number');
// Maximum size of an uploaded file, minus a small value (just in case)
$uploadMaxFilesize = (int) $nh->getBytes(ini_get('upload_max_filesize')) - 100;
// Max size of post data allowed, minus enough space to consider other posted fields.
$postMaxSize = (int) $nh->getBytes(ini_get('post_max_size')) - 10000;
if ($uploadMaxFilesize < 1 && $postMaxSize < 1) {
return 2000000;
}
if ($uploadMaxFilesize < 1) {
return $postMaxSize;
}
if ($postMaxSize < 1) {
return $uploadMaxFilesize;
}
return min($uploadMaxFilesize, $postMaxSize);
} | [
"protected",
"function",
"getAutomaticChunkSize",
"(",
")",
"{",
"$",
"nh",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'helper/number'",
")",
";",
"// Maximum size of an uploaded file, minus a small value (just in case)",
"$",
"uploadMaxFilesize",
"=",
"(",
"int",
")",
"$",
"nh",
"->",
"getBytes",
"(",
"ini_get",
"(",
"'upload_max_filesize'",
")",
")",
"-",
"100",
";",
"// Max size of post data allowed, minus enough space to consider other posted fields.",
"$",
"postMaxSize",
"=",
"(",
"int",
")",
"$",
"nh",
"->",
"getBytes",
"(",
"ini_get",
"(",
"'post_max_size'",
")",
")",
"-",
"10000",
";",
"if",
"(",
"$",
"uploadMaxFilesize",
"<",
"1",
"&&",
"$",
"postMaxSize",
"<",
"1",
")",
"{",
"return",
"2000000",
";",
"}",
"if",
"(",
"$",
"uploadMaxFilesize",
"<",
"1",
")",
"{",
"return",
"$",
"postMaxSize",
";",
"}",
"if",
"(",
"$",
"postMaxSize",
"<",
"1",
")",
"{",
"return",
"$",
"uploadMaxFilesize",
";",
"}",
"return",
"min",
"(",
"$",
"uploadMaxFilesize",
",",
"$",
"postMaxSize",
")",
";",
"}"
] | Determine the chunk size for chunked uploads.
@return int | [
"Determine",
"the",
"chunk",
"size",
"for",
"chunked",
"uploads",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/controllers/dialog/file/import.php#L212-L230 | train |
concrete5/concrete5 | concrete/controllers/dialog/file/import.php | Import.getIncomingFiles | protected function getIncomingFiles()
{
$fh = $this->app->make('helper/validation/file');
$nh = $this->app->make('helper/number');
$incoming = $this->app->make(Incoming::class);
$files = $incoming->getIncomingFilesystem()->listContents($incoming->getIncomingPath());
foreach (array_keys($files) as $index) {
$files[$index]['allowed'] = $fh->extension($files[$index]['basename']);
$files[$index]['thumbnail'] = FileTypeList::getType($files[$index]['extension'])->getThumbnail();
$files[$index]['displaySize'] = $nh->formatSize($files[$index]['size'], 'KB');
}
return $files;
} | php | protected function getIncomingFiles()
{
$fh = $this->app->make('helper/validation/file');
$nh = $this->app->make('helper/number');
$incoming = $this->app->make(Incoming::class);
$files = $incoming->getIncomingFilesystem()->listContents($incoming->getIncomingPath());
foreach (array_keys($files) as $index) {
$files[$index]['allowed'] = $fh->extension($files[$index]['basename']);
$files[$index]['thumbnail'] = FileTypeList::getType($files[$index]['extension'])->getThumbnail();
$files[$index]['displaySize'] = $nh->formatSize($files[$index]['size'], 'KB');
}
return $files;
} | [
"protected",
"function",
"getIncomingFiles",
"(",
")",
"{",
"$",
"fh",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'helper/validation/file'",
")",
";",
"$",
"nh",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'helper/number'",
")",
";",
"$",
"incoming",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"Incoming",
"::",
"class",
")",
";",
"$",
"files",
"=",
"$",
"incoming",
"->",
"getIncomingFilesystem",
"(",
")",
"->",
"listContents",
"(",
"$",
"incoming",
"->",
"getIncomingPath",
"(",
")",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"files",
")",
"as",
"$",
"index",
")",
"{",
"$",
"files",
"[",
"$",
"index",
"]",
"[",
"'allowed'",
"]",
"=",
"$",
"fh",
"->",
"extension",
"(",
"$",
"files",
"[",
"$",
"index",
"]",
"[",
"'basename'",
"]",
")",
";",
"$",
"files",
"[",
"$",
"index",
"]",
"[",
"'thumbnail'",
"]",
"=",
"FileTypeList",
"::",
"getType",
"(",
"$",
"files",
"[",
"$",
"index",
"]",
"[",
"'extension'",
"]",
")",
"->",
"getThumbnail",
"(",
")",
";",
"$",
"files",
"[",
"$",
"index",
"]",
"[",
"'displaySize'",
"]",
"=",
"$",
"nh",
"->",
"formatSize",
"(",
"$",
"files",
"[",
"$",
"index",
"]",
"[",
"'size'",
"]",
",",
"'KB'",
")",
";",
"}",
"return",
"$",
"files",
";",
"}"
] | Get the list of files available in the "incoming" directory.
@throws \Exception in case of errors
@return string[] | [
"Get",
"the",
"list",
"of",
"files",
"available",
"in",
"the",
"incoming",
"directory",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/controllers/dialog/file/import.php#L239-L252 | train |
concrete5/concrete5 | concrete/src/Entity/Statistics/UsageTracker/FileUsageRepository.php | FileUsageRepository.findByFile | public function findByFile($file)
{
if ($file instanceof File) {
$file = $file->getFileID();
}
return $this->findBy([
'file_id' => $file
]);
} | php | public function findByFile($file)
{
if ($file instanceof File) {
$file = $file->getFileID();
}
return $this->findBy([
'file_id' => $file
]);
} | [
"public",
"function",
"findByFile",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"instanceof",
"File",
")",
"{",
"$",
"file",
"=",
"$",
"file",
"->",
"getFileID",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"findBy",
"(",
"[",
"'file_id'",
"=>",
"$",
"file",
"]",
")",
";",
"}"
] | Find usage records related to a file
@param File|int $file The file object or the file id
@return FileUsageRecord[] | [
"Find",
"usage",
"records",
"related",
"to",
"a",
"file"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/Statistics/UsageTracker/FileUsageRepository.php#L19-L28 | train |
concrete5/concrete5 | concrete/src/Entity/Statistics/UsageTracker/FileUsageRepository.php | FileUsageRepository.findByCollection | public function findByCollection($collection, $version = null)
{
if ($collection instanceof Collection) {
$collection = $collection->getCollectionID();
}
$criteria = [
'collection_id' => $collection
];
if ($version && $version instanceof Version) {
$version = $version->getVersionID();
}
if ($version) {
$criteria['collection_version_id'] = $version;
}
return $this->findBy($criteria);
} | php | public function findByCollection($collection, $version = null)
{
if ($collection instanceof Collection) {
$collection = $collection->getCollectionID();
}
$criteria = [
'collection_id' => $collection
];
if ($version && $version instanceof Version) {
$version = $version->getVersionID();
}
if ($version) {
$criteria['collection_version_id'] = $version;
}
return $this->findBy($criteria);
} | [
"public",
"function",
"findByCollection",
"(",
"$",
"collection",
",",
"$",
"version",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"collection",
"instanceof",
"Collection",
")",
"{",
"$",
"collection",
"=",
"$",
"collection",
"->",
"getCollectionID",
"(",
")",
";",
"}",
"$",
"criteria",
"=",
"[",
"'collection_id'",
"=>",
"$",
"collection",
"]",
";",
"if",
"(",
"$",
"version",
"&&",
"$",
"version",
"instanceof",
"Version",
")",
"{",
"$",
"version",
"=",
"$",
"version",
"->",
"getVersionID",
"(",
")",
";",
"}",
"if",
"(",
"$",
"version",
")",
"{",
"$",
"criteria",
"[",
"'collection_version_id'",
"]",
"=",
"$",
"version",
";",
"}",
"return",
"$",
"this",
"->",
"findBy",
"(",
"$",
"criteria",
")",
";",
"}"
] | Find FileUsageRecords given a collection and a version
@param Collection|int $collection A collection or a collection ID
@param Version|int|null $version The version, a version ID, or null
@return \Concrete\Core\Entity\Statistics\UsageTracker\FileUsageRecord[] | [
"Find",
"FileUsageRecords",
"given",
"a",
"collection",
"and",
"a",
"version"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/Statistics/UsageTracker/FileUsageRepository.php#L36-L55 | train |
concrete5/concrete5 | concrete/src/Entity/Statistics/UsageTracker/FileUsageRepository.php | FileUsageRepository.findByBlock | public function findByBlock($block)
{
if ($block instanceof Block) {
$block = $block->getBlockID();
} elseif ($block instanceof BlockController) {
$block = $block->getBlockObject()->getBlockID();
}
return $this->findBy([
'block_id' => $block
]);
} | php | public function findByBlock($block)
{
if ($block instanceof Block) {
$block = $block->getBlockID();
} elseif ($block instanceof BlockController) {
$block = $block->getBlockObject()->getBlockID();
}
return $this->findBy([
'block_id' => $block
]);
} | [
"public",
"function",
"findByBlock",
"(",
"$",
"block",
")",
"{",
"if",
"(",
"$",
"block",
"instanceof",
"Block",
")",
"{",
"$",
"block",
"=",
"$",
"block",
"->",
"getBlockID",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"block",
"instanceof",
"BlockController",
")",
"{",
"$",
"block",
"=",
"$",
"block",
"->",
"getBlockObject",
"(",
")",
"->",
"getBlockID",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"findBy",
"(",
"[",
"'block_id'",
"=>",
"$",
"block",
"]",
")",
";",
"}"
] | Find FileUsageRecords given a block
@param $block
@return \Concrete\Core\Entity\Statistics\UsageTracker\FileUsageRecord[] | [
"Find",
"FileUsageRecords",
"given",
"a",
"block"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/Statistics/UsageTracker/FileUsageRepository.php#L62-L73 | train |
concrete5/concrete5 | concrete/src/Config/ConfigServiceProvider.php | ConfigServiceProvider.register | public function register()
{
$this->registerFileConfig();
$this->registerDatabaseConfig();
// Bind the concrete types
$this->app->bind('Concrete\Core\Config\Repository\Repository', 'config');
$this->app->bind('Illuminate\Config\Repository', 'Concrete\Core\Config\Repository\Repository');
} | php | public function register()
{
$this->registerFileConfig();
$this->registerDatabaseConfig();
// Bind the concrete types
$this->app->bind('Concrete\Core\Config\Repository\Repository', 'config');
$this->app->bind('Illuminate\Config\Repository', 'Concrete\Core\Config\Repository\Repository');
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"registerFileConfig",
"(",
")",
";",
"$",
"this",
"->",
"registerDatabaseConfig",
"(",
")",
";",
"// Bind the concrete types",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"'Concrete\\Core\\Config\\Repository\\Repository'",
",",
"'config'",
")",
";",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"'Illuminate\\Config\\Repository'",
",",
"'Concrete\\Core\\Config\\Repository\\Repository'",
")",
";",
"}"
] | Configuration repositories. | [
"Configuration",
"repositories",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Config/ConfigServiceProvider.php#L11-L19 | train |
concrete5/concrete5 | concrete/src/Config/ConfigServiceProvider.php | ConfigServiceProvider.registerFileConfig | private function registerFileConfig()
{
$this->app->singleton('config', function ($app) {
$loader = $app->make('Concrete\Core\Config\FileLoader');
$saver = $app->make('Concrete\Core\Config\FileSaver');
return $app->build('Concrete\Core\Config\Repository\Repository', array($loader, $saver, $app->environment()));
});
} | php | private function registerFileConfig()
{
$this->app->singleton('config', function ($app) {
$loader = $app->make('Concrete\Core\Config\FileLoader');
$saver = $app->make('Concrete\Core\Config\FileSaver');
return $app->build('Concrete\Core\Config\Repository\Repository', array($loader, $saver, $app->environment()));
});
} | [
"private",
"function",
"registerFileConfig",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'config'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"loader",
"=",
"$",
"app",
"->",
"make",
"(",
"'Concrete\\Core\\Config\\FileLoader'",
")",
";",
"$",
"saver",
"=",
"$",
"app",
"->",
"make",
"(",
"'Concrete\\Core\\Config\\FileSaver'",
")",
";",
"return",
"$",
"app",
"->",
"build",
"(",
"'Concrete\\Core\\Config\\Repository\\Repository'",
",",
"array",
"(",
"$",
"loader",
",",
"$",
"saver",
",",
"$",
"app",
"->",
"environment",
"(",
")",
")",
")",
";",
"}",
")",
";",
"}"
] | Create a file config repository. | [
"Create",
"a",
"file",
"config",
"repository",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Config/ConfigServiceProvider.php#L24-L32 | train |
concrete5/concrete5 | concrete/src/Config/ConfigServiceProvider.php | ConfigServiceProvider.registerDatabaseConfig | private function registerDatabaseConfig()
{
$this->app->bindShared('config/database', function ($app) {
$loader = $app->make('Concrete\Core\Config\DatabaseLoader');
$saver = $app->make('Concrete\Core\Config\DatabaseSaver');
return $app->build('Concrete\Core\Config\Repository\Repository', array($loader, $saver, $app->environment()));
});
} | php | private function registerDatabaseConfig()
{
$this->app->bindShared('config/database', function ($app) {
$loader = $app->make('Concrete\Core\Config\DatabaseLoader');
$saver = $app->make('Concrete\Core\Config\DatabaseSaver');
return $app->build('Concrete\Core\Config\Repository\Repository', array($loader, $saver, $app->environment()));
});
} | [
"private",
"function",
"registerDatabaseConfig",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"bindShared",
"(",
"'config/database'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"loader",
"=",
"$",
"app",
"->",
"make",
"(",
"'Concrete\\Core\\Config\\DatabaseLoader'",
")",
";",
"$",
"saver",
"=",
"$",
"app",
"->",
"make",
"(",
"'Concrete\\Core\\Config\\DatabaseSaver'",
")",
";",
"return",
"$",
"app",
"->",
"build",
"(",
"'Concrete\\Core\\Config\\Repository\\Repository'",
",",
"array",
"(",
"$",
"loader",
",",
"$",
"saver",
",",
"$",
"app",
"->",
"environment",
"(",
")",
")",
")",
";",
"}",
")",
";",
"}"
] | Create a database config repository. | [
"Create",
"a",
"database",
"config",
"repository",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Config/ConfigServiceProvider.php#L37-L45 | train |
concrete5/concrete5 | concrete/src/Legacy/DatabaseItemList.php | DatabaseItemList.filter | public function filter($column, $value, $comparison = '=')
{
$foundFilterIndex = -1;
if ($column) {
foreach ($this->filters as $key => $info) {
if ($info[0] == $column) {
$foundFilterIndex = $key;
break;
}
}
}
if ($foundFilterIndex > -1) {
$this->filters[$foundFilterIndex] = array($column, $value, $comparison);
} else {
$this->filters[] = array($column, $value, $comparison);
}
} | php | public function filter($column, $value, $comparison = '=')
{
$foundFilterIndex = -1;
if ($column) {
foreach ($this->filters as $key => $info) {
if ($info[0] == $column) {
$foundFilterIndex = $key;
break;
}
}
}
if ($foundFilterIndex > -1) {
$this->filters[$foundFilterIndex] = array($column, $value, $comparison);
} else {
$this->filters[] = array($column, $value, $comparison);
}
} | [
"public",
"function",
"filter",
"(",
"$",
"column",
",",
"$",
"value",
",",
"$",
"comparison",
"=",
"'='",
")",
"{",
"$",
"foundFilterIndex",
"=",
"-",
"1",
";",
"if",
"(",
"$",
"column",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"filters",
"as",
"$",
"key",
"=>",
"$",
"info",
")",
"{",
"if",
"(",
"$",
"info",
"[",
"0",
"]",
"==",
"$",
"column",
")",
"{",
"$",
"foundFilterIndex",
"=",
"$",
"key",
";",
"break",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"foundFilterIndex",
">",
"-",
"1",
")",
"{",
"$",
"this",
"->",
"filters",
"[",
"$",
"foundFilterIndex",
"]",
"=",
"array",
"(",
"$",
"column",
",",
"$",
"value",
",",
"$",
"comparison",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"filters",
"[",
"]",
"=",
"array",
"(",
"$",
"column",
",",
"$",
"value",
",",
"$",
"comparison",
")",
";",
"}",
"}"
] | Adds a filter to this item list. | [
"Adds",
"a",
"filter",
"to",
"this",
"item",
"list",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Legacy/DatabaseItemList.php#L167-L184 | train |
concrete5/concrete5 | concrete/src/Logging/Configuration/AdvancedConfiguration.php | AdvancedConfiguration.prepareConfig | protected function prepareConfig($config)
{
if (isset($config['loggers']) && is_array($config['loggers'])
&& array_key_exists(Channels::META_CHANNEL_ALL, $config['loggers'])) {
$allConfig = $config['loggers'][Channels::META_CHANNEL_ALL];
$channels = array_merge(Channels::getCoreChannels(), [Channels::CHANNEL_APPLICATION]);
foreach($channels as $channel) {
$config['loggers'][$channel] = $allConfig;
}
unset($config['loggers'][Channels::META_CHANNEL_ALL]);
}
return $config;
} | php | protected function prepareConfig($config)
{
if (isset($config['loggers']) && is_array($config['loggers'])
&& array_key_exists(Channels::META_CHANNEL_ALL, $config['loggers'])) {
$allConfig = $config['loggers'][Channels::META_CHANNEL_ALL];
$channels = array_merge(Channels::getCoreChannels(), [Channels::CHANNEL_APPLICATION]);
foreach($channels as $channel) {
$config['loggers'][$channel] = $allConfig;
}
unset($config['loggers'][Channels::META_CHANNEL_ALL]);
}
return $config;
} | [
"protected",
"function",
"prepareConfig",
"(",
"$",
"config",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'loggers'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"config",
"[",
"'loggers'",
"]",
")",
"&&",
"array_key_exists",
"(",
"Channels",
"::",
"META_CHANNEL_ALL",
",",
"$",
"config",
"[",
"'loggers'",
"]",
")",
")",
"{",
"$",
"allConfig",
"=",
"$",
"config",
"[",
"'loggers'",
"]",
"[",
"Channels",
"::",
"META_CHANNEL_ALL",
"]",
";",
"$",
"channels",
"=",
"array_merge",
"(",
"Channels",
"::",
"getCoreChannels",
"(",
")",
",",
"[",
"Channels",
"::",
"CHANNEL_APPLICATION",
"]",
")",
";",
"foreach",
"(",
"$",
"channels",
"as",
"$",
"channel",
")",
"{",
"$",
"config",
"[",
"'loggers'",
"]",
"[",
"$",
"channel",
"]",
"=",
"$",
"allConfig",
";",
"}",
"unset",
"(",
"$",
"config",
"[",
"'loggers'",
"]",
"[",
"Channels",
"::",
"META_CHANNEL_ALL",
"]",
")",
";",
"}",
"return",
"$",
"config",
";",
"}"
] | Takes the config array we're going to pass to monolog cascade and transforms it a bit. For example, if we have
configuration we need to apply to all channels, we loop through all the channels in the channels class and
add them to the config array.
@param array $config | [
"Takes",
"the",
"config",
"array",
"we",
"re",
"going",
"to",
"pass",
"to",
"monolog",
"cascade",
"and",
"transforms",
"it",
"a",
"bit",
".",
"For",
"example",
"if",
"we",
"have",
"configuration",
"we",
"need",
"to",
"apply",
"to",
"all",
"channels",
"we",
"loop",
"through",
"all",
"the",
"channels",
"in",
"the",
"channels",
"class",
"and",
"add",
"them",
"to",
"the",
"config",
"array",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Logging/Configuration/AdvancedConfiguration.php#L25-L38 | train |
concrete5/concrete5 | concrete/src/File/FolderItemList.php | FolderItemList.filterByExtension | public function filterByExtension($extension)
{
$extensions = is_array($extension) ? $extension : [$extension];
if (count($extensions) > 0) {
$expr = $this->query->expr();
$or = $expr->orX();
foreach ($extensions as $extension) {
$extension = ltrim((string) $extension, '.');
$or->add($expr->eq('fv.fvExtension', $this->query->createNamedParameter($extension)));
if ($extension === '') {
$or->add($expr->isNull('fv.fvExtension'));
}
}
$this->query->andWhere($or);
}
} | php | public function filterByExtension($extension)
{
$extensions = is_array($extension) ? $extension : [$extension];
if (count($extensions) > 0) {
$expr = $this->query->expr();
$or = $expr->orX();
foreach ($extensions as $extension) {
$extension = ltrim((string) $extension, '.');
$or->add($expr->eq('fv.fvExtension', $this->query->createNamedParameter($extension)));
if ($extension === '') {
$or->add($expr->isNull('fv.fvExtension'));
}
}
$this->query->andWhere($or);
}
} | [
"public",
"function",
"filterByExtension",
"(",
"$",
"extension",
")",
"{",
"$",
"extensions",
"=",
"is_array",
"(",
"$",
"extension",
")",
"?",
"$",
"extension",
":",
"[",
"$",
"extension",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"extensions",
")",
">",
"0",
")",
"{",
"$",
"expr",
"=",
"$",
"this",
"->",
"query",
"->",
"expr",
"(",
")",
";",
"$",
"or",
"=",
"$",
"expr",
"->",
"orX",
"(",
")",
";",
"foreach",
"(",
"$",
"extensions",
"as",
"$",
"extension",
")",
"{",
"$",
"extension",
"=",
"ltrim",
"(",
"(",
"string",
")",
"$",
"extension",
",",
"'.'",
")",
";",
"$",
"or",
"->",
"add",
"(",
"$",
"expr",
"->",
"eq",
"(",
"'fv.fvExtension'",
",",
"$",
"this",
"->",
"query",
"->",
"createNamedParameter",
"(",
"$",
"extension",
")",
")",
")",
";",
"if",
"(",
"$",
"extension",
"===",
"''",
")",
"{",
"$",
"or",
"->",
"add",
"(",
"$",
"expr",
"->",
"isNull",
"(",
"'fv.fvExtension'",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"query",
"->",
"andWhere",
"(",
"$",
"or",
")",
";",
"}",
"}"
] | Filter the files by their extension.
@param string|string[] $extension one or more file extensions (with or without leading dot) | [
"Filter",
"the",
"files",
"by",
"their",
"extension",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/FolderItemList.php#L152-L167 | train |
concrete5/concrete5 | concrete/src/Http/RequestBase.php | RequestBase.getPath | public function getPath()
{
$pathInfo = rawurldecode($this->getPathInfo());
$path = '/' . trim($pathInfo, '/');
return ($path == '/') ? '' : $path;
} | php | public function getPath()
{
$pathInfo = rawurldecode($this->getPathInfo());
$path = '/' . trim($pathInfo, '/');
return ($path == '/') ? '' : $path;
} | [
"public",
"function",
"getPath",
"(",
")",
"{",
"$",
"pathInfo",
"=",
"rawurldecode",
"(",
"$",
"this",
"->",
"getPathInfo",
"(",
")",
")",
";",
"$",
"path",
"=",
"'/'",
".",
"trim",
"(",
"$",
"pathInfo",
",",
"'/'",
")",
";",
"return",
"(",
"$",
"path",
"==",
"'/'",
")",
"?",
"''",
":",
"$",
"path",
";",
"}"
] | Returns the full path for a request.
@return string | [
"Returns",
"the",
"full",
"path",
"for",
"a",
"request",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Http/RequestBase.php#L155-L161 | train |
concrete5/concrete5 | concrete/src/Http/RequestBase.php | RequestBase.post | public static function post($key = null, $defaultValue = null)
{
if ($key == null) {
return $_POST;
}
if (isset($_POST[$key])) {
return (is_string($_POST[$key])) ? trim($_POST[$key]) : $_POST[$key];
}
return $defaultValue;
} | php | public static function post($key = null, $defaultValue = null)
{
if ($key == null) {
return $_POST;
}
if (isset($_POST[$key])) {
return (is_string($_POST[$key])) ? trim($_POST[$key]) : $_POST[$key];
}
return $defaultValue;
} | [
"public",
"static",
"function",
"post",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"defaultValue",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"key",
"==",
"null",
")",
"{",
"return",
"$",
"_POST",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_POST",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"(",
"is_string",
"(",
"$",
"_POST",
"[",
"$",
"key",
"]",
")",
")",
"?",
"trim",
"(",
"$",
"_POST",
"[",
"$",
"key",
"]",
")",
":",
"$",
"_POST",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"defaultValue",
";",
"}"
] | If no arguments are passed, returns the post array. If a key is passed, it returns the value as it exists in the post array.
If a default value is provided and the key does not exist in the POST array, the default value is returned.
@param string $key
@param mixed $defaultValue
@return mixed | [
"If",
"no",
"arguments",
"are",
"passed",
"returns",
"the",
"post",
"array",
".",
"If",
"a",
"key",
"is",
"passed",
"it",
"returns",
"the",
"value",
"as",
"it",
"exists",
"in",
"the",
"post",
"array",
".",
"If",
"a",
"default",
"value",
"is",
"provided",
"and",
"the",
"key",
"does",
"not",
"exist",
"in",
"the",
"POST",
"array",
"the",
"default",
"value",
"is",
"returned",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Http/RequestBase.php#L172-L182 | train |
concrete5/concrete5 | concrete/src/Page/Stack/Pile/Pile.php | Pile.delete | public function delete()
{
$db = Loader::db();
$v = array($this->pID);
$q = "delete from Piles where pID = ?";
$db->query($q, $v);
$q2 = "delete from PileContents where pID = ?";
$db->query($q, $v);
return true;
} | php | public function delete()
{
$db = Loader::db();
$v = array($this->pID);
$q = "delete from Piles where pID = ?";
$db->query($q, $v);
$q2 = "delete from PileContents where pID = ?";
$db->query($q, $v);
return true;
} | [
"public",
"function",
"delete",
"(",
")",
"{",
"$",
"db",
"=",
"Loader",
"::",
"db",
"(",
")",
";",
"$",
"v",
"=",
"array",
"(",
"$",
"this",
"->",
"pID",
")",
";",
"$",
"q",
"=",
"\"delete from Piles where pID = ?\"",
";",
"$",
"db",
"->",
"query",
"(",
"$",
"q",
",",
"$",
"v",
")",
";",
"$",
"q2",
"=",
"\"delete from PileContents where pID = ?\"",
";",
"$",
"db",
"->",
"query",
"(",
"$",
"q",
",",
"$",
"v",
")",
";",
"return",
"true",
";",
"}"
] | Delete a pile.
@return bool | [
"Delete",
"a",
"pile",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Page/Stack/Pile/Pile.php#L282-L292 | train |
concrete5/concrete5 | concrete/src/Http/Service/Ajax.php | Ajax.isAjaxRequest | public function isAjaxRequest(Request $request)
{
$result = false;
$requestedWith = $request->server->get('HTTP_X_REQUESTED_WITH');
if (is_string($requestedWith) && strcasecmp($requestedWith, 'XMLHttpRequest') === 0) {
$result = true;
}
return $result;
} | php | public function isAjaxRequest(Request $request)
{
$result = false;
$requestedWith = $request->server->get('HTTP_X_REQUESTED_WITH');
if (is_string($requestedWith) && strcasecmp($requestedWith, 'XMLHttpRequest') === 0) {
$result = true;
}
return $result;
} | [
"public",
"function",
"isAjaxRequest",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"result",
"=",
"false",
";",
"$",
"requestedWith",
"=",
"$",
"request",
"->",
"server",
"->",
"get",
"(",
"'HTTP_X_REQUESTED_WITH'",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"requestedWith",
")",
"&&",
"strcasecmp",
"(",
"$",
"requestedWith",
",",
"'XMLHttpRequest'",
")",
"===",
"0",
")",
"{",
"$",
"result",
"=",
"true",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Check if a request is an Ajax call.
@param Request $request
@return bool | [
"Check",
"if",
"a",
"request",
"is",
"an",
"Ajax",
"call",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Http/Service/Ajax.php#L16-L25 | train |
concrete5/concrete5 | concrete/src/Http/Service/Ajax.php | Ajax.sendResult | public function sendResult($result)
{
if (@ob_get_length()) {
@ob_end_clean();
}
if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false) {
header('Content-Type: application/json; charset=' . APP_CHARSET, true);
} else {
header('Content-Type: text/plain; charset=' . APP_CHARSET, true);
}
echo json_encode($result);
die();
} | php | public function sendResult($result)
{
if (@ob_get_length()) {
@ob_end_clean();
}
if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false) {
header('Content-Type: application/json; charset=' . APP_CHARSET, true);
} else {
header('Content-Type: text/plain; charset=' . APP_CHARSET, true);
}
echo json_encode($result);
die();
} | [
"public",
"function",
"sendResult",
"(",
"$",
"result",
")",
"{",
"if",
"(",
"@",
"ob_get_length",
"(",
")",
")",
"{",
"@",
"ob_end_clean",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
")",
"&&",
"strpos",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
",",
"'application/json'",
")",
"!==",
"false",
")",
"{",
"header",
"(",
"'Content-Type: application/json; charset='",
".",
"APP_CHARSET",
",",
"true",
")",
";",
"}",
"else",
"{",
"header",
"(",
"'Content-Type: text/plain; charset='",
".",
"APP_CHARSET",
",",
"true",
")",
";",
"}",
"echo",
"json_encode",
"(",
"$",
"result",
")",
";",
"die",
"(",
")",
";",
"}"
] | Sends a result to the client and ends the execution.
@param mixed $result
@deprecated You should switch to something like:
return \Core::make(\Concrete\Core\Http\ResponseFactoryInterface::class)->json(...) | [
"Sends",
"a",
"result",
"to",
"the",
"client",
"and",
"ends",
"the",
"execution",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Http/Service/Ajax.php#L35-L47 | train |
concrete5/concrete5 | concrete/src/Http/Service/Ajax.php | Ajax.sendError | public function sendError($error)
{
if (@ob_get_length()) {
@ob_end_clean();
}
if ($error instanceof \Concrete\Core\Error\ErrorList\ErrorList) {
$error->outputJSON();
} else {
header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request', true, 400);
header('Content-Type: text/plain; charset=' . APP_CHARSET, true);
echo($error instanceof Exception) ? $error->getMessage() : $error;
}
die();
} | php | public function sendError($error)
{
if (@ob_get_length()) {
@ob_end_clean();
}
if ($error instanceof \Concrete\Core\Error\ErrorList\ErrorList) {
$error->outputJSON();
} else {
header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request', true, 400);
header('Content-Type: text/plain; charset=' . APP_CHARSET, true);
echo($error instanceof Exception) ? $error->getMessage() : $error;
}
die();
} | [
"public",
"function",
"sendError",
"(",
"$",
"error",
")",
"{",
"if",
"(",
"@",
"ob_get_length",
"(",
")",
")",
"{",
"@",
"ob_end_clean",
"(",
")",
";",
"}",
"if",
"(",
"$",
"error",
"instanceof",
"\\",
"Concrete",
"\\",
"Core",
"\\",
"Error",
"\\",
"ErrorList",
"\\",
"ErrorList",
")",
"{",
"$",
"error",
"->",
"outputJSON",
"(",
")",
";",
"}",
"else",
"{",
"header",
"(",
"$",
"_SERVER",
"[",
"'SERVER_PROTOCOL'",
"]",
".",
"' 400 Bad Request'",
",",
"true",
",",
"400",
")",
";",
"header",
"(",
"'Content-Type: text/plain; charset='",
".",
"APP_CHARSET",
",",
"true",
")",
";",
"echo",
"(",
"$",
"error",
"instanceof",
"Exception",
")",
"?",
"$",
"error",
"->",
"getMessage",
"(",
")",
":",
"$",
"error",
";",
"}",
"die",
"(",
")",
";",
"}"
] | Sends an error to the client and ends the execution.
@param string|Exception|\Concrete\Core\Error\Error $result the error to send to the client
@param mixed $error
@deprecated You should switch to something like:
return \Core::make(\Concrete\Core\Http\ResponseFactoryInterface::class)->json(...) | [
"Sends",
"an",
"error",
"to",
"the",
"client",
"and",
"ends",
"the",
"execution",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Http/Service/Ajax.php#L58-L71 | train |
concrete5/concrete5 | concrete/src/Utility/Service/Validation/Arrays.php | Arrays.containsString | public function containsString($needle, $haystack = array(), $recurse = true)
{
/** @var \Concrete\Core\Utility\Service\Validation\Strings $stringHelper */
$stringHelper = Core::make('helper/validation/strings');
if (!$stringHelper->notempty($needle)) {
return false;
}
$arr = (!is_array($haystack)) ? array($haystack) : $haystack; // turn the string into an array
foreach ($arr as $item) {
if ($stringHelper->notempty($item) && strstr($item, $needle) !== false) {
return true;
} elseif ($recurse && is_array($item) && $this->containsString($needle, $item)) {
return true;
}
}
return false;
} | php | public function containsString($needle, $haystack = array(), $recurse = true)
{
/** @var \Concrete\Core\Utility\Service\Validation\Strings $stringHelper */
$stringHelper = Core::make('helper/validation/strings');
if (!$stringHelper->notempty($needle)) {
return false;
}
$arr = (!is_array($haystack)) ? array($haystack) : $haystack; // turn the string into an array
foreach ($arr as $item) {
if ($stringHelper->notempty($item) && strstr($item, $needle) !== false) {
return true;
} elseif ($recurse && is_array($item) && $this->containsString($needle, $item)) {
return true;
}
}
return false;
} | [
"public",
"function",
"containsString",
"(",
"$",
"needle",
",",
"$",
"haystack",
"=",
"array",
"(",
")",
",",
"$",
"recurse",
"=",
"true",
")",
"{",
"/** @var \\Concrete\\Core\\Utility\\Service\\Validation\\Strings $stringHelper */",
"$",
"stringHelper",
"=",
"Core",
"::",
"make",
"(",
"'helper/validation/strings'",
")",
";",
"if",
"(",
"!",
"$",
"stringHelper",
"->",
"notempty",
"(",
"$",
"needle",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"arr",
"=",
"(",
"!",
"is_array",
"(",
"$",
"haystack",
")",
")",
"?",
"array",
"(",
"$",
"haystack",
")",
":",
"$",
"haystack",
";",
"// turn the string into an array",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"stringHelper",
"->",
"notempty",
"(",
"$",
"item",
")",
"&&",
"strstr",
"(",
"$",
"item",
",",
"$",
"needle",
")",
"!==",
"false",
")",
"{",
"return",
"true",
";",
"}",
"elseif",
"(",
"$",
"recurse",
"&&",
"is_array",
"(",
"$",
"item",
")",
"&&",
"$",
"this",
"->",
"containsString",
"(",
"$",
"needle",
",",
"$",
"item",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Returns true if any string in the "haystack" contains the "needle".
@param string $needle The string to search for
@param string|array $haystack An array of strings to be searched (Can also contain sub arrays)
@param bool $recurse Defaults to true, when enabled this function will check any arrays inside the haystack for
a containing value when false it will only check the first level
@return bool | [
"Returns",
"true",
"if",
"any",
"string",
"in",
"the",
"haystack",
"contains",
"the",
"needle",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Utility/Service/Validation/Arrays.php#L18-L35 | train |
concrete5/concrete5 | concrete/src/Utility/Service/Arrays.php | Arrays.parseKeys | private function parseKeys($keys)
{
if (is_string($keys)) {
if (strpos($keys, '[') !== false) {
$keys = str_replace(']', '', $keys);
$keys = explode('[', trim($keys, '['));
} else {
$keys = (array) $keys;
}
}
return $keys;
} | php | private function parseKeys($keys)
{
if (is_string($keys)) {
if (strpos($keys, '[') !== false) {
$keys = str_replace(']', '', $keys);
$keys = explode('[', trim($keys, '['));
} else {
$keys = (array) $keys;
}
}
return $keys;
} | [
"private",
"function",
"parseKeys",
"(",
"$",
"keys",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"keys",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"keys",
",",
"'['",
")",
"!==",
"false",
")",
"{",
"$",
"keys",
"=",
"str_replace",
"(",
"']'",
",",
"''",
",",
"$",
"keys",
")",
";",
"$",
"keys",
"=",
"explode",
"(",
"'['",
",",
"trim",
"(",
"$",
"keys",
",",
"'['",
")",
")",
";",
"}",
"else",
"{",
"$",
"keys",
"=",
"(",
"array",
")",
"$",
"keys",
";",
"}",
"}",
"return",
"$",
"keys",
";",
"}"
] | Turns the string keys into an array of keys.
@param string|array $keys
@return array | [
"Turns",
"the",
"string",
"keys",
"into",
"an",
"array",
"of",
"keys",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Utility/Service/Arrays.php#L72-L84 | train |
concrete5/concrete5 | concrete/src/Utility/Service/Arrays.php | Arrays.flatten | public function flatten(array $array)
{
$tmp = array();
foreach ($array as $a) {
if (is_array($a)) {
$tmp = array_merge($tmp, array_flat($a));
} else {
$tmp[] = $a;
}
}
return $tmp;
} | php | public function flatten(array $array)
{
$tmp = array();
foreach ($array as $a) {
if (is_array($a)) {
$tmp = array_merge($tmp, array_flat($a));
} else {
$tmp[] = $a;
}
}
return $tmp;
} | [
"public",
"function",
"flatten",
"(",
"array",
"$",
"array",
")",
"{",
"$",
"tmp",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"a",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"a",
")",
")",
"{",
"$",
"tmp",
"=",
"array_merge",
"(",
"$",
"tmp",
",",
"array_flat",
"(",
"$",
"a",
")",
")",
";",
"}",
"else",
"{",
"$",
"tmp",
"[",
"]",
"=",
"$",
"a",
";",
"}",
"}",
"return",
"$",
"tmp",
";",
"}"
] | Takes a multidimensional array and flattens it.
@param array $array
@return array | [
"Takes",
"a",
"multidimensional",
"array",
"and",
"flattens",
"it",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Utility/Service/Arrays.php#L93-L105 | train |
concrete5/concrete5 | concrete/src/File/Image/Svg/Sanitizer.php | Sanitizer.sanitizeFile | public function sanitizeFile($inputFilename, SanitizerOptions $options = null, $outputFilename = '')
{
$data = is_string($inputFilename) && $this->filesystem->isFile($inputFilename) ? $this->filesystem->get($inputFilename) : false;
if ($data === false) {
throw SanitizerException::create(SanitizerException::ERROR_FAILED_TO_READ_FILE);
}
$sanitizedData = $this->sanitizeData($data, $options);
if ((string) $outputFilename === '') {
$outputFilename = $inputFilename;
}
if ($outputFilename !== $inputFilename || $data !== $sanitizedData) {
if ($this->filesystem->put($outputFilename, $sanitizedData) === false) {
throw SanitizerException::create(SanitizerException::ERROR_FAILED_TO_WRITE_FILE);
}
}
} | php | public function sanitizeFile($inputFilename, SanitizerOptions $options = null, $outputFilename = '')
{
$data = is_string($inputFilename) && $this->filesystem->isFile($inputFilename) ? $this->filesystem->get($inputFilename) : false;
if ($data === false) {
throw SanitizerException::create(SanitizerException::ERROR_FAILED_TO_READ_FILE);
}
$sanitizedData = $this->sanitizeData($data, $options);
if ((string) $outputFilename === '') {
$outputFilename = $inputFilename;
}
if ($outputFilename !== $inputFilename || $data !== $sanitizedData) {
if ($this->filesystem->put($outputFilename, $sanitizedData) === false) {
throw SanitizerException::create(SanitizerException::ERROR_FAILED_TO_WRITE_FILE);
}
}
} | [
"public",
"function",
"sanitizeFile",
"(",
"$",
"inputFilename",
",",
"SanitizerOptions",
"$",
"options",
"=",
"null",
",",
"$",
"outputFilename",
"=",
"''",
")",
"{",
"$",
"data",
"=",
"is_string",
"(",
"$",
"inputFilename",
")",
"&&",
"$",
"this",
"->",
"filesystem",
"->",
"isFile",
"(",
"$",
"inputFilename",
")",
"?",
"$",
"this",
"->",
"filesystem",
"->",
"get",
"(",
"$",
"inputFilename",
")",
":",
"false",
";",
"if",
"(",
"$",
"data",
"===",
"false",
")",
"{",
"throw",
"SanitizerException",
"::",
"create",
"(",
"SanitizerException",
"::",
"ERROR_FAILED_TO_READ_FILE",
")",
";",
"}",
"$",
"sanitizedData",
"=",
"$",
"this",
"->",
"sanitizeData",
"(",
"$",
"data",
",",
"$",
"options",
")",
";",
"if",
"(",
"(",
"string",
")",
"$",
"outputFilename",
"===",
"''",
")",
"{",
"$",
"outputFilename",
"=",
"$",
"inputFilename",
";",
"}",
"if",
"(",
"$",
"outputFilename",
"!==",
"$",
"inputFilename",
"||",
"$",
"data",
"!==",
"$",
"sanitizedData",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"filesystem",
"->",
"put",
"(",
"$",
"outputFilename",
",",
"$",
"sanitizedData",
")",
"===",
"false",
")",
"{",
"throw",
"SanitizerException",
"::",
"create",
"(",
"SanitizerException",
"::",
"ERROR_FAILED_TO_WRITE_FILE",
")",
";",
"}",
"}",
"}"
] | Sanitize a file containing an SVG document.
@param string $inputFilename the input filename
@param \Concrete\Core\File\Image\Svg\SanitizerOptions $options the sanitizer options (if NULL, we'll use the default ones)
@param string $outputFilename the output filename (if empty, we'll overwrite $inputFilename)
@throws \Concrete\Core\File\Image\Svg\SanitizerException in case of errors | [
"Sanitize",
"a",
"file",
"containing",
"an",
"SVG",
"document",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Svg/Sanitizer.php#L39-L54 | train |
concrete5/concrete5 | concrete/src/File/Image/Svg/Sanitizer.php | Sanitizer.sanitizeData | public function sanitizeData($data, SanitizerOptions $options = null)
{
$xml = $this->dataToXml($data);
if ($options === null) {
$options = new SanitizerOptions();
}
$this->processNode($xml->documentElement, $options);
return $this->xmlToData($xml);
} | php | public function sanitizeData($data, SanitizerOptions $options = null)
{
$xml = $this->dataToXml($data);
if ($options === null) {
$options = new SanitizerOptions();
}
$this->processNode($xml->documentElement, $options);
return $this->xmlToData($xml);
} | [
"public",
"function",
"sanitizeData",
"(",
"$",
"data",
",",
"SanitizerOptions",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"xml",
"=",
"$",
"this",
"->",
"dataToXml",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"options",
"===",
"null",
")",
"{",
"$",
"options",
"=",
"new",
"SanitizerOptions",
"(",
")",
";",
"}",
"$",
"this",
"->",
"processNode",
"(",
"$",
"xml",
"->",
"documentElement",
",",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"xmlToData",
"(",
"$",
"xml",
")",
";",
"}"
] | Sanitize a string containing an SVG document.
@param string $data the input filename
@param \Concrete\Core\File\Image\Svg\SanitizerOptions $options the sanitizer options (if NULL, we'll use the default ones)
@throws \Concrete\Core\File\Image\Svg\SanitizerException in case of errors
@return string | [
"Sanitize",
"a",
"string",
"containing",
"an",
"SVG",
"document",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Svg/Sanitizer.php#L66-L76 | train |
concrete5/concrete5 | concrete/src/File/Image/Svg/Sanitizer.php | Sanitizer.getLoadFlags | protected function getLoadFlags()
{
$flags = LIBXML_NONET | LIBXML_NOWARNING;
foreach ([
'LIBXML_PARSEHUGE', // libxml >= 2.7.0
'LIBXML_HTML_NOIMPLIED', // libxml >= 2.7.7
'LIBXML_HTML_NODEFDTD', // libxml >= 2.7.8
'LIBXML_BIGLINES', // libxml >= 2.9.0
] as $flagName) {
if (defined($flagName)) {
$flags |= constant($flagName);
}
}
return $flags;
} | php | protected function getLoadFlags()
{
$flags = LIBXML_NONET | LIBXML_NOWARNING;
foreach ([
'LIBXML_PARSEHUGE', // libxml >= 2.7.0
'LIBXML_HTML_NOIMPLIED', // libxml >= 2.7.7
'LIBXML_HTML_NODEFDTD', // libxml >= 2.7.8
'LIBXML_BIGLINES', // libxml >= 2.9.0
] as $flagName) {
if (defined($flagName)) {
$flags |= constant($flagName);
}
}
return $flags;
} | [
"protected",
"function",
"getLoadFlags",
"(",
")",
"{",
"$",
"flags",
"=",
"LIBXML_NONET",
"|",
"LIBXML_NOWARNING",
";",
"foreach",
"(",
"[",
"'LIBXML_PARSEHUGE'",
",",
"// libxml >= 2.7.0",
"'LIBXML_HTML_NOIMPLIED'",
",",
"// libxml >= 2.7.7",
"'LIBXML_HTML_NODEFDTD'",
",",
"// libxml >= 2.7.8",
"'LIBXML_BIGLINES'",
",",
"// libxml >= 2.9.0",
"]",
"as",
"$",
"flagName",
")",
"{",
"if",
"(",
"defined",
"(",
"$",
"flagName",
")",
")",
"{",
"$",
"flags",
"|=",
"constant",
"(",
"$",
"flagName",
")",
";",
"}",
"}",
"return",
"$",
"flags",
";",
"}"
] | Get the flags to be used when loading the XML.
@return int | [
"Get",
"the",
"flags",
"to",
"be",
"used",
"when",
"loading",
"the",
"XML",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Svg/Sanitizer.php#L83-L99 | train |
concrete5/concrete5 | concrete/src/File/Image/Svg/Sanitizer.php | Sanitizer.dataToXml | protected function dataToXml($data)
{
if (!is_string($data)) {
throw SanitizerException::create(SanitizerException::ERROR_FAILED_TO_PARSE_XML);
}
$xml = new DOMDocument();
$error = null;
try {
$loaded = $xml->loadXML($data, $this->getLoadFlags());
} catch (Exception $x) {
$error = $x;
} catch (Throwable $x) {
$error = $x;
}
if ($error !== null || $loaded === false) {
throw SanitizerException::create(SanitizerException::ERROR_FAILED_TO_PARSE_XML, $error ? $error->getMessage() : '');
}
return $xml;
} | php | protected function dataToXml($data)
{
if (!is_string($data)) {
throw SanitizerException::create(SanitizerException::ERROR_FAILED_TO_PARSE_XML);
}
$xml = new DOMDocument();
$error = null;
try {
$loaded = $xml->loadXML($data, $this->getLoadFlags());
} catch (Exception $x) {
$error = $x;
} catch (Throwable $x) {
$error = $x;
}
if ($error !== null || $loaded === false) {
throw SanitizerException::create(SanitizerException::ERROR_FAILED_TO_PARSE_XML, $error ? $error->getMessage() : '');
}
return $xml;
} | [
"protected",
"function",
"dataToXml",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"data",
")",
")",
"{",
"throw",
"SanitizerException",
"::",
"create",
"(",
"SanitizerException",
"::",
"ERROR_FAILED_TO_PARSE_XML",
")",
";",
"}",
"$",
"xml",
"=",
"new",
"DOMDocument",
"(",
")",
";",
"$",
"error",
"=",
"null",
";",
"try",
"{",
"$",
"loaded",
"=",
"$",
"xml",
"->",
"loadXML",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"getLoadFlags",
"(",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"x",
")",
"{",
"$",
"error",
"=",
"$",
"x",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"x",
")",
"{",
"$",
"error",
"=",
"$",
"x",
";",
"}",
"if",
"(",
"$",
"error",
"!==",
"null",
"||",
"$",
"loaded",
"===",
"false",
")",
"{",
"throw",
"SanitizerException",
"::",
"create",
"(",
"SanitizerException",
"::",
"ERROR_FAILED_TO_PARSE_XML",
",",
"$",
"error",
"?",
"$",
"error",
"->",
"getMessage",
"(",
")",
":",
"''",
")",
";",
"}",
"return",
"$",
"xml",
";",
"}"
] | Create a DOMDocument instance from a string.
@param string $data
@throws \Concrete\Core\File\Image\Svg\SanitizerException in case of errors
@return \DOMDocument | [
"Create",
"a",
"DOMDocument",
"instance",
"from",
"a",
"string",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Svg/Sanitizer.php#L110-L129 | train |
concrete5/concrete5 | concrete/src/File/Image/Svg/Sanitizer.php | Sanitizer.xmlToData | protected function xmlToData(DOMDocument $xml)
{
$data = $xml->saveXML();
if ($data === false) {
throw SanitizerException::create(SanitizerException::ERROR_FAILED_TO_GENERATE_XML);
}
return $data;
} | php | protected function xmlToData(DOMDocument $xml)
{
$data = $xml->saveXML();
if ($data === false) {
throw SanitizerException::create(SanitizerException::ERROR_FAILED_TO_GENERATE_XML);
}
return $data;
} | [
"protected",
"function",
"xmlToData",
"(",
"DOMDocument",
"$",
"xml",
")",
"{",
"$",
"data",
"=",
"$",
"xml",
"->",
"saveXML",
"(",
")",
";",
"if",
"(",
"$",
"data",
"===",
"false",
")",
"{",
"throw",
"SanitizerException",
"::",
"create",
"(",
"SanitizerException",
"::",
"ERROR_FAILED_TO_GENERATE_XML",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Render a DOMDocument instance as a string.
@param \DOMDocument $xml
@throws \Concrete\Core\File\Image\Svg\SanitizerException in case of errors
@return string | [
"Render",
"a",
"DOMDocument",
"instance",
"as",
"a",
"string",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Svg/Sanitizer.php#L171-L179 | train |
concrete5/concrete5 | concrete/src/Database/CharacterSetCollation/Resolver.php | Resolver.getDefaultCharacterSet | public function getDefaultCharacterSet()
{
$characterSet = $this->config->get('database.preferred_character_set');
$characterSet = $this->normalizeCharacterSet($characterSet);
return $characterSet;
} | php | public function getDefaultCharacterSet()
{
$characterSet = $this->config->get('database.preferred_character_set');
$characterSet = $this->normalizeCharacterSet($characterSet);
return $characterSet;
} | [
"public",
"function",
"getDefaultCharacterSet",
"(",
")",
"{",
"$",
"characterSet",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'database.preferred_character_set'",
")",
";",
"$",
"characterSet",
"=",
"$",
"this",
"->",
"normalizeCharacterSet",
"(",
"$",
"characterSet",
")",
";",
"return",
"$",
"characterSet",
";",
"}"
] | Get the default character set.
@return string Empty string if not set | [
"Get",
"the",
"default",
"character",
"set",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Database/CharacterSetCollation/Resolver.php#L59-L65 | train |
concrete5/concrete5 | concrete/src/Database/CharacterSetCollation/Resolver.php | Resolver.setCharacterSet | public function setCharacterSet($characterSet)
{
if ($characterSet !== null) {
$characterSet = $this->normalizeCharacterSet($characterSet);
}
$this->characterSet = $characterSet;
return $this;
} | php | public function setCharacterSet($characterSet)
{
if ($characterSet !== null) {
$characterSet = $this->normalizeCharacterSet($characterSet);
}
$this->characterSet = $characterSet;
return $this;
} | [
"public",
"function",
"setCharacterSet",
"(",
"$",
"characterSet",
")",
"{",
"if",
"(",
"$",
"characterSet",
"!==",
"null",
")",
"{",
"$",
"characterSet",
"=",
"$",
"this",
"->",
"normalizeCharacterSet",
"(",
"$",
"characterSet",
")",
";",
"}",
"$",
"this",
"->",
"characterSet",
"=",
"$",
"characterSet",
";",
"return",
"$",
"this",
";",
"}"
] | Set the character set.
@param string|null|mixed $characterSet use NULL to use the default character set
@return $this | [
"Set",
"the",
"character",
"set",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Database/CharacterSetCollation/Resolver.php#L84-L92 | train |
concrete5/concrete5 | concrete/src/Database/CharacterSetCollation/Resolver.php | Resolver.getDefaultCollation | public function getDefaultCollation()
{
$collation = $this->config->get('database.preferred_collation');
$collation = $this->normalizeCollation($collation);
return $collation;
} | php | public function getDefaultCollation()
{
$collation = $this->config->get('database.preferred_collation');
$collation = $this->normalizeCollation($collation);
return $collation;
} | [
"public",
"function",
"getDefaultCollation",
"(",
")",
"{",
"$",
"collation",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'database.preferred_collation'",
")",
";",
"$",
"collation",
"=",
"$",
"this",
"->",
"normalizeCollation",
"(",
"$",
"collation",
")",
";",
"return",
"$",
"collation",
";",
"}"
] | Get the default collation.
@return string Empty string if not set | [
"Get",
"the",
"default",
"collation",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Database/CharacterSetCollation/Resolver.php#L99-L105 | train |
concrete5/concrete5 | concrete/src/Database/CharacterSetCollation/Resolver.php | Resolver.setCollation | public function setCollation($collation)
{
if ($collation !== null) {
$collation = $this->normalizeCollation($collation);
}
$this->collation = $collation;
return $this;
} | php | public function setCollation($collation)
{
if ($collation !== null) {
$collation = $this->normalizeCollation($collation);
}
$this->collation = $collation;
return $this;
} | [
"public",
"function",
"setCollation",
"(",
"$",
"collation",
")",
"{",
"if",
"(",
"$",
"collation",
"!==",
"null",
")",
"{",
"$",
"collation",
"=",
"$",
"this",
"->",
"normalizeCollation",
"(",
"$",
"collation",
")",
";",
"}",
"$",
"this",
"->",
"collation",
"=",
"$",
"collation",
";",
"return",
"$",
"this",
";",
"}"
] | Set the collation.
@param string|null|mixed $collation use NULL to use the default collation
@return $this | [
"Set",
"the",
"collation",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Database/CharacterSetCollation/Resolver.php#L124-L132 | train |
concrete5/concrete5 | concrete/src/Database/CharacterSetCollation/Resolver.php | Resolver.resolveCharacterSetAndCollation | public function resolveCharacterSetAndCollation(Connection $connection)
{
$characterSet = $this->getCharacterSet();
$collation = $this->getCollation();
if ($collation !== '') {
$collations = $connection->getSupportedCollations();
if (!isset($collations[$collation])) {
throw new Exception\UnsupportedCollationException($collation);
}
if ($characterSet === '') {
$characterSet = $collations[$collation];
} elseif ($characterSet !== $collations[$collation]) {
throw new Exception\InvalidCharacterSetCollationCombination($characterSet, $collation, $collations[$characterSet]);
}
} elseif ($characterSet !== '') {
$characterSets = $connection->getSupportedCharsets();
if (!isset($characterSets[$characterSet])) {
throw new Exception\UnsupportedCharacterSetException($characterSet);
}
$collation = $characterSets[$characterSet];
} else {
throw new Exception\NoCharacterSetCollationDefinedException();
}
if (!$connection->isCollationSupportedForKeys($collation, $this->getMaximumStringKeyLength())) {
throw new Exception\LongKeysUnsupportedByCollation($collation, $this->getMaximumStringKeyLength());
}
return [$characterSet, $collation];
} | php | public function resolveCharacterSetAndCollation(Connection $connection)
{
$characterSet = $this->getCharacterSet();
$collation = $this->getCollation();
if ($collation !== '') {
$collations = $connection->getSupportedCollations();
if (!isset($collations[$collation])) {
throw new Exception\UnsupportedCollationException($collation);
}
if ($characterSet === '') {
$characterSet = $collations[$collation];
} elseif ($characterSet !== $collations[$collation]) {
throw new Exception\InvalidCharacterSetCollationCombination($characterSet, $collation, $collations[$characterSet]);
}
} elseif ($characterSet !== '') {
$characterSets = $connection->getSupportedCharsets();
if (!isset($characterSets[$characterSet])) {
throw new Exception\UnsupportedCharacterSetException($characterSet);
}
$collation = $characterSets[$characterSet];
} else {
throw new Exception\NoCharacterSetCollationDefinedException();
}
if (!$connection->isCollationSupportedForKeys($collation, $this->getMaximumStringKeyLength())) {
throw new Exception\LongKeysUnsupportedByCollation($collation, $this->getMaximumStringKeyLength());
}
return [$characterSet, $collation];
} | [
"public",
"function",
"resolveCharacterSetAndCollation",
"(",
"Connection",
"$",
"connection",
")",
"{",
"$",
"characterSet",
"=",
"$",
"this",
"->",
"getCharacterSet",
"(",
")",
";",
"$",
"collation",
"=",
"$",
"this",
"->",
"getCollation",
"(",
")",
";",
"if",
"(",
"$",
"collation",
"!==",
"''",
")",
"{",
"$",
"collations",
"=",
"$",
"connection",
"->",
"getSupportedCollations",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"collations",
"[",
"$",
"collation",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"UnsupportedCollationException",
"(",
"$",
"collation",
")",
";",
"}",
"if",
"(",
"$",
"characterSet",
"===",
"''",
")",
"{",
"$",
"characterSet",
"=",
"$",
"collations",
"[",
"$",
"collation",
"]",
";",
"}",
"elseif",
"(",
"$",
"characterSet",
"!==",
"$",
"collations",
"[",
"$",
"collation",
"]",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidCharacterSetCollationCombination",
"(",
"$",
"characterSet",
",",
"$",
"collation",
",",
"$",
"collations",
"[",
"$",
"characterSet",
"]",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"characterSet",
"!==",
"''",
")",
"{",
"$",
"characterSets",
"=",
"$",
"connection",
"->",
"getSupportedCharsets",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"characterSets",
"[",
"$",
"characterSet",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"UnsupportedCharacterSetException",
"(",
"$",
"characterSet",
")",
";",
"}",
"$",
"collation",
"=",
"$",
"characterSets",
"[",
"$",
"characterSet",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"\\",
"NoCharacterSetCollationDefinedException",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"connection",
"->",
"isCollationSupportedForKeys",
"(",
"$",
"collation",
",",
"$",
"this",
"->",
"getMaximumStringKeyLength",
"(",
")",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"LongKeysUnsupportedByCollation",
"(",
"$",
"collation",
",",
"$",
"this",
"->",
"getMaximumStringKeyLength",
"(",
")",
")",
";",
"}",
"return",
"[",
"$",
"characterSet",
",",
"$",
"collation",
"]",
";",
"}"
] | Resolve the character set and collation.
@param \Concrete\Core\Database\Connection\Connection $connection
@throws \Concrete\Core\Database\CharacterSetCollation\Exception\NoCharacterSetCollationDefinedException
@throws \Concrete\Core\Database\CharacterSetCollation\Exception\UnsupportedCharacterSetException
@throws \Concrete\Core\Database\CharacterSetCollation\Exception\UnsupportedCollationException
@throws \Concrete\Core\Database\CharacterSetCollation\Exception\InvalidCharacterSetCollationCombination
@throws \Concrete\Core\Database\CharacterSetCollation\Exception\LongKeysUnsupportedByCollation
return string[] first value is the character set; the second value is the collation | [
"Resolve",
"the",
"character",
"set",
"and",
"collation",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Database/CharacterSetCollation/Resolver.php#L171-L199 | train |
concrete5/concrete5 | concrete/src/Database/EntityManagerConfigFactory.php | EntityManagerConfigFactory.getConfiguration | public function getConfiguration()
{
$driverChain = $this->getMetadataDriverImpl();
// Inject the driverChain into the doctrine config
$this->configuration->setMetadataDriverImpl($driverChain);
return $this->configuration;
} | php | public function getConfiguration()
{
$driverChain = $this->getMetadataDriverImpl();
// Inject the driverChain into the doctrine config
$this->configuration->setMetadataDriverImpl($driverChain);
return $this->configuration;
} | [
"public",
"function",
"getConfiguration",
"(",
")",
"{",
"$",
"driverChain",
"=",
"$",
"this",
"->",
"getMetadataDriverImpl",
"(",
")",
";",
"// Inject the driverChain into the doctrine config",
"$",
"this",
"->",
"configuration",
"->",
"setMetadataDriverImpl",
"(",
"$",
"driverChain",
")",
";",
"return",
"$",
"this",
"->",
"configuration",
";",
"}"
] | Add driverChain and get orm config
@return \Doctrine\ORM\Configuration | [
"Add",
"driverChain",
"and",
"get",
"orm",
"config"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Database/EntityManagerConfigFactory.php#L73-L79 | train |
concrete5/concrete5 | concrete/blocks/form/mini_survey.php | MiniSurvey.questionCleanup | public static function questionCleanup($qsID = 0, $bID = 0)
{
$db = Database::connection();
//First make sure that the bID column has been set for this questionSetId (for backwards compatibility)
$vals = array(intval($qsID));
$questionsWithBIDs = $db->fetchColumn('SELECT count(*) FROM btFormQuestions WHERE bID!=0 AND questionSetId=? ', $vals);
//form block was just upgraded, so set the bID column
if (!$questionsWithBIDs) {
$vals = array(intval($bID), intval($qsID));
$rs = $db->executeQuery('UPDATE btFormQuestions SET bID=? WHERE bID=0 AND questionSetId=?', $vals);
return;
}
//Then remove all temp/placeholder questions for this questionSetId that haven't been assigned to a block
$vals = array(intval($qsID));
$rs = $db->executeQuery('DELETE FROM btFormQuestions WHERE bID=0 AND questionSetId=?', $vals);
} | php | public static function questionCleanup($qsID = 0, $bID = 0)
{
$db = Database::connection();
//First make sure that the bID column has been set for this questionSetId (for backwards compatibility)
$vals = array(intval($qsID));
$questionsWithBIDs = $db->fetchColumn('SELECT count(*) FROM btFormQuestions WHERE bID!=0 AND questionSetId=? ', $vals);
//form block was just upgraded, so set the bID column
if (!$questionsWithBIDs) {
$vals = array(intval($bID), intval($qsID));
$rs = $db->executeQuery('UPDATE btFormQuestions SET bID=? WHERE bID=0 AND questionSetId=?', $vals);
return;
}
//Then remove all temp/placeholder questions for this questionSetId that haven't been assigned to a block
$vals = array(intval($qsID));
$rs = $db->executeQuery('DELETE FROM btFormQuestions WHERE bID=0 AND questionSetId=?', $vals);
} | [
"public",
"static",
"function",
"questionCleanup",
"(",
"$",
"qsID",
"=",
"0",
",",
"$",
"bID",
"=",
"0",
")",
"{",
"$",
"db",
"=",
"Database",
"::",
"connection",
"(",
")",
";",
"//First make sure that the bID column has been set for this questionSetId (for backwards compatibility)",
"$",
"vals",
"=",
"array",
"(",
"intval",
"(",
"$",
"qsID",
")",
")",
";",
"$",
"questionsWithBIDs",
"=",
"$",
"db",
"->",
"fetchColumn",
"(",
"'SELECT count(*) FROM btFormQuestions WHERE bID!=0 AND questionSetId=? '",
",",
"$",
"vals",
")",
";",
"//form block was just upgraded, so set the bID column",
"if",
"(",
"!",
"$",
"questionsWithBIDs",
")",
"{",
"$",
"vals",
"=",
"array",
"(",
"intval",
"(",
"$",
"bID",
")",
",",
"intval",
"(",
"$",
"qsID",
")",
")",
";",
"$",
"rs",
"=",
"$",
"db",
"->",
"executeQuery",
"(",
"'UPDATE btFormQuestions SET bID=? WHERE bID=0 AND questionSetId=?'",
",",
"$",
"vals",
")",
";",
"return",
";",
"}",
"//Then remove all temp/placeholder questions for this questionSetId that haven't been assigned to a block",
"$",
"vals",
"=",
"array",
"(",
"intval",
"(",
"$",
"qsID",
")",
")",
";",
"$",
"rs",
"=",
"$",
"db",
"->",
"executeQuery",
"(",
"'DELETE FROM btFormQuestions WHERE bID=0 AND questionSetId=?'",
",",
"$",
"vals",
")",
";",
"}"
] | Run on Form block edit | [
"Run",
"on",
"Form",
"block",
"edit"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/blocks/form/mini_survey.php#L392-L411 | train |
concrete5/concrete5 | concrete/src/Config/DatabaseSaver.php | DatabaseSaver.save | public function save($item, $value, $environment, $group, $namespace = null)
{
$builder = $this->getConnection()->createQueryBuilder();
$query = $builder->delete('Config')
->where('configNamespace = :namespace',
'configGroup = :group',
'configItem LIKE :item')
->setParameters(array(
':namespace' => $namespace ?: '',
':group' => $group,
':item' => "{$item}.%",
));
$amount_deleted = $query->execute();
$this->doSave($item, $value, $environment, $group, $namespace);
} | php | public function save($item, $value, $environment, $group, $namespace = null)
{
$builder = $this->getConnection()->createQueryBuilder();
$query = $builder->delete('Config')
->where('configNamespace = :namespace',
'configGroup = :group',
'configItem LIKE :item')
->setParameters(array(
':namespace' => $namespace ?: '',
':group' => $group,
':item' => "{$item}.%",
));
$amount_deleted = $query->execute();
$this->doSave($item, $value, $environment, $group, $namespace);
} | [
"public",
"function",
"save",
"(",
"$",
"item",
",",
"$",
"value",
",",
"$",
"environment",
",",
"$",
"group",
",",
"$",
"namespace",
"=",
"null",
")",
"{",
"$",
"builder",
"=",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"=",
"$",
"builder",
"->",
"delete",
"(",
"'Config'",
")",
"->",
"where",
"(",
"'configNamespace = :namespace'",
",",
"'configGroup = :group'",
",",
"'configItem LIKE :item'",
")",
"->",
"setParameters",
"(",
"array",
"(",
"':namespace'",
"=>",
"$",
"namespace",
"?",
":",
"''",
",",
"':group'",
"=>",
"$",
"group",
",",
"':item'",
"=>",
"\"{$item}.%\"",
",",
")",
")",
";",
"$",
"amount_deleted",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"$",
"this",
"->",
"doSave",
"(",
"$",
"item",
",",
"$",
"value",
",",
"$",
"environment",
",",
"$",
"group",
",",
"$",
"namespace",
")",
";",
"}"
] | Save config item.
@param string $item
@param string $value
@param string $environment
@param string $group
@param string|null $namespace
@return bool | [
"Save",
"config",
"item",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Config/DatabaseSaver.php#L45-L61 | train |
concrete5/concrete5 | concrete/controllers/single_page/dashboard/pages/themes/inspect.php | Inspect.view | public function view($pThemeID = null, $message = false)
{
if (!$pThemeID) {
$this->redirect('/dashboard/pages/themes/');
}
$v = Loader::helper('validation/error');
$pt = PageTheme::getByID($pThemeID);
if (is_object($pt)) {
$files = $pt->getFilesInTheme();
$this->set('files', $files);
$this->set('pThemeID', $pThemeID);
$this->set('pageTheme', $pt);
} else {
$v->add('Invalid Theme');
}
switch ($message) {
case 'install':
$this->set(
'message',
t(
"Theme installed. You may automatically create page templates from template files contained in your theme using the form below."
)
);
break;
case 'activate':
$this->set(
'message',
t(
"Theme activated. You may automatically create page templates from template files contained in your theme using the form below."
)
);
break;
}
if ($v->has()) {
$this->set('error', $v);
}
$this->set('disableThirdLevelNav', true);
} | php | public function view($pThemeID = null, $message = false)
{
if (!$pThemeID) {
$this->redirect('/dashboard/pages/themes/');
}
$v = Loader::helper('validation/error');
$pt = PageTheme::getByID($pThemeID);
if (is_object($pt)) {
$files = $pt->getFilesInTheme();
$this->set('files', $files);
$this->set('pThemeID', $pThemeID);
$this->set('pageTheme', $pt);
} else {
$v->add('Invalid Theme');
}
switch ($message) {
case 'install':
$this->set(
'message',
t(
"Theme installed. You may automatically create page templates from template files contained in your theme using the form below."
)
);
break;
case 'activate':
$this->set(
'message',
t(
"Theme activated. You may automatically create page templates from template files contained in your theme using the form below."
)
);
break;
}
if ($v->has()) {
$this->set('error', $v);
}
$this->set('disableThirdLevelNav', true);
} | [
"public",
"function",
"view",
"(",
"$",
"pThemeID",
"=",
"null",
",",
"$",
"message",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"pThemeID",
")",
"{",
"$",
"this",
"->",
"redirect",
"(",
"'/dashboard/pages/themes/'",
")",
";",
"}",
"$",
"v",
"=",
"Loader",
"::",
"helper",
"(",
"'validation/error'",
")",
";",
"$",
"pt",
"=",
"PageTheme",
"::",
"getByID",
"(",
"$",
"pThemeID",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"pt",
")",
")",
"{",
"$",
"files",
"=",
"$",
"pt",
"->",
"getFilesInTheme",
"(",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'files'",
",",
"$",
"files",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'pThemeID'",
",",
"$",
"pThemeID",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'pageTheme'",
",",
"$",
"pt",
")",
";",
"}",
"else",
"{",
"$",
"v",
"->",
"add",
"(",
"'Invalid Theme'",
")",
";",
"}",
"switch",
"(",
"$",
"message",
")",
"{",
"case",
"'install'",
":",
"$",
"this",
"->",
"set",
"(",
"'message'",
",",
"t",
"(",
"\"Theme installed. You may automatically create page templates from template files contained in your theme using the form below.\"",
")",
")",
";",
"break",
";",
"case",
"'activate'",
":",
"$",
"this",
"->",
"set",
"(",
"'message'",
",",
"t",
"(",
"\"Theme activated. You may automatically create page templates from template files contained in your theme using the form below.\"",
")",
")",
";",
"break",
";",
"}",
"if",
"(",
"$",
"v",
"->",
"has",
"(",
")",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"'error'",
",",
"$",
"v",
")",
";",
"}",
"$",
"this",
"->",
"set",
"(",
"'disableThirdLevelNav'",
",",
"true",
")",
";",
"}"
] | grab all the page types from within a theme | [
"grab",
"all",
"the",
"page",
"types",
"from",
"within",
"a",
"theme"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/controllers/single_page/dashboard/pages/themes/inspect.php#L23-L64 | train |
concrete5/concrete5 | concrete/src/Database/Connection/Connection.php | Connection.createTextIndexes | public function createTextIndexes(array $textIndexes)
{
if (!empty($textIndexes)) {
$sm = $this->getSchemaManager();
foreach ($textIndexes as $tableName => $indexes) {
if ($sm->tablesExist([$tableName])) {
$existingIndexNames = array_map(
function (\Doctrine\DBAL\Schema\Index $index) {
return $index->getShortestName('');
},
$sm->listTableIndexes($tableName)
);
$chunks = [];
foreach ($indexes as $indexName => $indexColumns) {
if (!in_array(strtolower($indexName), $existingIndexNames, true)) {
$newIndexColumns = [];
foreach ((array) $indexColumns as $indexColumn) {
$indexColumn = (array) $indexColumn;
$s = $this->quoteIdentifier($indexColumn[0]);
if (!empty($indexColumn[1])) {
$s .= '(' . (int) $indexColumn[1] . ')';
}
$newIndexColumns[] = $s;
}
$chunks[] = $this->quoteIdentifier($indexName) . ' (' . implode(', ', $newIndexColumns) . ')';
}
}
if (!empty($chunks)) {
$sql = 'ALTER TABLE ' . $this->quoteIdentifier($tableName) . ' ADD INDEX ' . implode(', ADD INDEX ', $chunks);
$this->executeQuery($sql);
}
}
}
}
} | php | public function createTextIndexes(array $textIndexes)
{
if (!empty($textIndexes)) {
$sm = $this->getSchemaManager();
foreach ($textIndexes as $tableName => $indexes) {
if ($sm->tablesExist([$tableName])) {
$existingIndexNames = array_map(
function (\Doctrine\DBAL\Schema\Index $index) {
return $index->getShortestName('');
},
$sm->listTableIndexes($tableName)
);
$chunks = [];
foreach ($indexes as $indexName => $indexColumns) {
if (!in_array(strtolower($indexName), $existingIndexNames, true)) {
$newIndexColumns = [];
foreach ((array) $indexColumns as $indexColumn) {
$indexColumn = (array) $indexColumn;
$s = $this->quoteIdentifier($indexColumn[0]);
if (!empty($indexColumn[1])) {
$s .= '(' . (int) $indexColumn[1] . ')';
}
$newIndexColumns[] = $s;
}
$chunks[] = $this->quoteIdentifier($indexName) . ' (' . implode(', ', $newIndexColumns) . ')';
}
}
if (!empty($chunks)) {
$sql = 'ALTER TABLE ' . $this->quoteIdentifier($tableName) . ' ADD INDEX ' . implode(', ADD INDEX ', $chunks);
$this->executeQuery($sql);
}
}
}
}
} | [
"public",
"function",
"createTextIndexes",
"(",
"array",
"$",
"textIndexes",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"textIndexes",
")",
")",
"{",
"$",
"sm",
"=",
"$",
"this",
"->",
"getSchemaManager",
"(",
")",
";",
"foreach",
"(",
"$",
"textIndexes",
"as",
"$",
"tableName",
"=>",
"$",
"indexes",
")",
"{",
"if",
"(",
"$",
"sm",
"->",
"tablesExist",
"(",
"[",
"$",
"tableName",
"]",
")",
")",
"{",
"$",
"existingIndexNames",
"=",
"array_map",
"(",
"function",
"(",
"\\",
"Doctrine",
"\\",
"DBAL",
"\\",
"Schema",
"\\",
"Index",
"$",
"index",
")",
"{",
"return",
"$",
"index",
"->",
"getShortestName",
"(",
"''",
")",
";",
"}",
",",
"$",
"sm",
"->",
"listTableIndexes",
"(",
"$",
"tableName",
")",
")",
";",
"$",
"chunks",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"indexes",
"as",
"$",
"indexName",
"=>",
"$",
"indexColumns",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"strtolower",
"(",
"$",
"indexName",
")",
",",
"$",
"existingIndexNames",
",",
"true",
")",
")",
"{",
"$",
"newIndexColumns",
"=",
"[",
"]",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"indexColumns",
"as",
"$",
"indexColumn",
")",
"{",
"$",
"indexColumn",
"=",
"(",
"array",
")",
"$",
"indexColumn",
";",
"$",
"s",
"=",
"$",
"this",
"->",
"quoteIdentifier",
"(",
"$",
"indexColumn",
"[",
"0",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"indexColumn",
"[",
"1",
"]",
")",
")",
"{",
"$",
"s",
".=",
"'('",
".",
"(",
"int",
")",
"$",
"indexColumn",
"[",
"1",
"]",
".",
"')'",
";",
"}",
"$",
"newIndexColumns",
"[",
"]",
"=",
"$",
"s",
";",
"}",
"$",
"chunks",
"[",
"]",
"=",
"$",
"this",
"->",
"quoteIdentifier",
"(",
"$",
"indexName",
")",
".",
"' ('",
".",
"implode",
"(",
"', '",
",",
"$",
"newIndexColumns",
")",
".",
"')'",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"chunks",
")",
")",
"{",
"$",
"sql",
"=",
"'ALTER TABLE '",
".",
"$",
"this",
"->",
"quoteIdentifier",
"(",
"$",
"tableName",
")",
".",
"' ADD INDEX '",
".",
"implode",
"(",
"', ADD INDEX '",
",",
"$",
"chunks",
")",
";",
"$",
"this",
"->",
"executeQuery",
"(",
"$",
"sql",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | This is essentially a workaround for not being able to define indexes on TEXT fields with the current version of Doctrine DBAL.
This feature will be removed when DBAL will support it, so don't use this feature.
@param array $textIndexes | [
"This",
"is",
"essentially",
"a",
"workaround",
"for",
"not",
"being",
"able",
"to",
"define",
"indexes",
"on",
"TEXT",
"fields",
"with",
"the",
"current",
"version",
"of",
"Doctrine",
"DBAL",
".",
"This",
"feature",
"will",
"be",
"removed",
"when",
"DBAL",
"will",
"support",
"it",
"so",
"don",
"t",
"use",
"this",
"feature",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Database/Connection/Connection.php#L116-L150 | train |
concrete5/concrete5 | concrete/src/Database/Connection/Connection.php | Connection.replace | public function replace($table, $fieldArray, $keyCol, $autoQuote = true)
{
$qb = $this->createQueryBuilder();
$qb->select('count(*)')->from($table, 't');
$where = $qb->expr()->andX();
$updateKeys = [];
if (!is_array($keyCol)) {
$keyCol = [$keyCol];
}
foreach ($keyCol as $key) {
if (isset($fieldArray[$key])) {
$field = $fieldArray[$key];
} else {
$field = null;
}
$updateKeys[$key] = $field;
if ($autoQuote) {
$field = $qb->expr()->literal($field);
}
$where->add($qb->expr()->eq($key, $field));
}
$qb->where($where);
$sql = $qb->getSql();
$num = parent::query($sql)->fetchColumn();
if ($num) {
$update = true;
} else {
try {
$this->insert($table, $fieldArray);
$update = false;
} catch (UniqueConstraintViolationException $x) {
$update = true;
}
}
if ($update) {
$this->update($table, $fieldArray, $updateKeys);
}
} | php | public function replace($table, $fieldArray, $keyCol, $autoQuote = true)
{
$qb = $this->createQueryBuilder();
$qb->select('count(*)')->from($table, 't');
$where = $qb->expr()->andX();
$updateKeys = [];
if (!is_array($keyCol)) {
$keyCol = [$keyCol];
}
foreach ($keyCol as $key) {
if (isset($fieldArray[$key])) {
$field = $fieldArray[$key];
} else {
$field = null;
}
$updateKeys[$key] = $field;
if ($autoQuote) {
$field = $qb->expr()->literal($field);
}
$where->add($qb->expr()->eq($key, $field));
}
$qb->where($where);
$sql = $qb->getSql();
$num = parent::query($sql)->fetchColumn();
if ($num) {
$update = true;
} else {
try {
$this->insert($table, $fieldArray);
$update = false;
} catch (UniqueConstraintViolationException $x) {
$update = true;
}
}
if ($update) {
$this->update($table, $fieldArray, $updateKeys);
}
} | [
"public",
"function",
"replace",
"(",
"$",
"table",
",",
"$",
"fieldArray",
",",
"$",
"keyCol",
",",
"$",
"autoQuote",
"=",
"true",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"qb",
"->",
"select",
"(",
"'count(*)'",
")",
"->",
"from",
"(",
"$",
"table",
",",
"'t'",
")",
";",
"$",
"where",
"=",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"andX",
"(",
")",
";",
"$",
"updateKeys",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"keyCol",
")",
")",
"{",
"$",
"keyCol",
"=",
"[",
"$",
"keyCol",
"]",
";",
"}",
"foreach",
"(",
"$",
"keyCol",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"fieldArray",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"field",
"=",
"$",
"fieldArray",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"$",
"field",
"=",
"null",
";",
"}",
"$",
"updateKeys",
"[",
"$",
"key",
"]",
"=",
"$",
"field",
";",
"if",
"(",
"$",
"autoQuote",
")",
"{",
"$",
"field",
"=",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"literal",
"(",
"$",
"field",
")",
";",
"}",
"$",
"where",
"->",
"add",
"(",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"$",
"key",
",",
"$",
"field",
")",
")",
";",
"}",
"$",
"qb",
"->",
"where",
"(",
"$",
"where",
")",
";",
"$",
"sql",
"=",
"$",
"qb",
"->",
"getSql",
"(",
")",
";",
"$",
"num",
"=",
"parent",
"::",
"query",
"(",
"$",
"sql",
")",
"->",
"fetchColumn",
"(",
")",
";",
"if",
"(",
"$",
"num",
")",
"{",
"$",
"update",
"=",
"true",
";",
"}",
"else",
"{",
"try",
"{",
"$",
"this",
"->",
"insert",
"(",
"$",
"table",
",",
"$",
"fieldArray",
")",
";",
"$",
"update",
"=",
"false",
";",
"}",
"catch",
"(",
"UniqueConstraintViolationException",
"$",
"x",
")",
"{",
"$",
"update",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"$",
"update",
")",
"{",
"$",
"this",
"->",
"update",
"(",
"$",
"table",
",",
"$",
"fieldArray",
",",
"$",
"updateKeys",
")",
";",
"}",
"}"
] | Insert or update a row in a database table.
@param string $table the name of the database table
@param array $fieldArray array keys are the field names, array values are the field values
@param string|string[] $keyCol the names of the primary key fields
@param bool $autoQuote set to true to quote the field values | [
"Insert",
"or",
"update",
"a",
"row",
"in",
"a",
"database",
"table",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Database/Connection/Connection.php#L280-L317 | train |
concrete5/concrete5 | concrete/src/Database/Connection/Connection.php | Connection.getSupportedCharsets | public function getSupportedCharsets()
{
if ($this->supportedCharsets === null) {
$supportedCharsets = [];
$rs = $this->executeQuery('SHOW CHARACTER SET');
while (($row = $rs->fetch(PDO::FETCH_ASSOC)) !== false) {
if (!isset($row['Charset']) || !isset($row['Default collation'])) {
throw new Exception(t('Unrecognized result of the "%s" database query.', 'SHOW CHARACTER SET'));
}
$supportedCharsets[strtolower($row['Charset'])] = strtolower($row['Default collation']);
}
$this->supportedCharsets = $supportedCharsets;
}
return $this->supportedCharsets;
} | php | public function getSupportedCharsets()
{
if ($this->supportedCharsets === null) {
$supportedCharsets = [];
$rs = $this->executeQuery('SHOW CHARACTER SET');
while (($row = $rs->fetch(PDO::FETCH_ASSOC)) !== false) {
if (!isset($row['Charset']) || !isset($row['Default collation'])) {
throw new Exception(t('Unrecognized result of the "%s" database query.', 'SHOW CHARACTER SET'));
}
$supportedCharsets[strtolower($row['Charset'])] = strtolower($row['Default collation']);
}
$this->supportedCharsets = $supportedCharsets;
}
return $this->supportedCharsets;
} | [
"public",
"function",
"getSupportedCharsets",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"supportedCharsets",
"===",
"null",
")",
"{",
"$",
"supportedCharsets",
"=",
"[",
"]",
";",
"$",
"rs",
"=",
"$",
"this",
"->",
"executeQuery",
"(",
"'SHOW CHARACTER SET'",
")",
";",
"while",
"(",
"(",
"$",
"row",
"=",
"$",
"rs",
"->",
"fetch",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
")",
"!==",
"false",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"row",
"[",
"'Charset'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"row",
"[",
"'Default collation'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"t",
"(",
"'Unrecognized result of the \"%s\" database query.'",
",",
"'SHOW CHARACTER SET'",
")",
")",
";",
"}",
"$",
"supportedCharsets",
"[",
"strtolower",
"(",
"$",
"row",
"[",
"'Charset'",
"]",
")",
"]",
"=",
"strtolower",
"(",
"$",
"row",
"[",
"'Default collation'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"supportedCharsets",
"=",
"$",
"supportedCharsets",
";",
"}",
"return",
"$",
"this",
"->",
"supportedCharsets",
";",
"}"
] | Get the supported character sets and associated default collation.
@throws \Exception throws an exception in case of errors
@return array keys: character set (always lower case); array values: default collation for the character set (always lower case) | [
"Get",
"the",
"supported",
"character",
"sets",
"and",
"associated",
"default",
"collation",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Database/Connection/Connection.php#L442-L457 | train |
concrete5/concrete5 | concrete/src/Database/Connection/Connection.php | Connection.getSupportedCollations | public function getSupportedCollations()
{
if ($this->supportedCollations === null) {
$supportedCollations = [];
$rs = $this->executeQuery('SHOW COLLATION');
while (($row = $rs->fetch(PDO::FETCH_ASSOC)) !== false) {
if (!isset($row['Collation']) || !isset($row['Charset'])) {
throw new Exception(t('Unrecognized result of the "%s" database query.', 'SHOW COLLATION'));
}
$supportedCollations[strtolower($row['Collation'])] = strtolower($row['Charset']);
}
$this->supportedCollations = $supportedCollations;
}
return $this->supportedCollations;
} | php | public function getSupportedCollations()
{
if ($this->supportedCollations === null) {
$supportedCollations = [];
$rs = $this->executeQuery('SHOW COLLATION');
while (($row = $rs->fetch(PDO::FETCH_ASSOC)) !== false) {
if (!isset($row['Collation']) || !isset($row['Charset'])) {
throw new Exception(t('Unrecognized result of the "%s" database query.', 'SHOW COLLATION'));
}
$supportedCollations[strtolower($row['Collation'])] = strtolower($row['Charset']);
}
$this->supportedCollations = $supportedCollations;
}
return $this->supportedCollations;
} | [
"public",
"function",
"getSupportedCollations",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"supportedCollations",
"===",
"null",
")",
"{",
"$",
"supportedCollations",
"=",
"[",
"]",
";",
"$",
"rs",
"=",
"$",
"this",
"->",
"executeQuery",
"(",
"'SHOW COLLATION'",
")",
";",
"while",
"(",
"(",
"$",
"row",
"=",
"$",
"rs",
"->",
"fetch",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
")",
"!==",
"false",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"row",
"[",
"'Collation'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"row",
"[",
"'Charset'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"t",
"(",
"'Unrecognized result of the \"%s\" database query.'",
",",
"'SHOW COLLATION'",
")",
")",
";",
"}",
"$",
"supportedCollations",
"[",
"strtolower",
"(",
"$",
"row",
"[",
"'Collation'",
"]",
")",
"]",
"=",
"strtolower",
"(",
"$",
"row",
"[",
"'Charset'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"supportedCollations",
"=",
"$",
"supportedCollations",
";",
"}",
"return",
"$",
"this",
"->",
"supportedCollations",
";",
"}"
] | Get the supported collations and the associated character sets.
@throws \Exception throws an exception in case of errors
@return array keys: collation (always lower case); array values: associated character set (always lower case) | [
"Get",
"the",
"supported",
"collations",
"and",
"the",
"associated",
"character",
"sets",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Database/Connection/Connection.php#L466-L481 | train |
concrete5/concrete5 | concrete/src/Database/Connection/Connection.php | Connection.isCollationSupportedForKeys | public function isCollationSupportedForKeys($collation, $fieldLength)
{
$sm = $this->getSchemaManager();
$existingTables = array_map('strtolower', $sm->listTableNames());
for ($i = 0; ; ++$i) {
$tableName = 'tmp_checkCollationFieldLength' . $i;
if (!in_array(strtolower($tableName), $existingTables)) {
break;
}
}
$column = new DbalColumn('ColumnName', DbalType::getType(DbalType::STRING), ['length' => (int) $fieldLength]);
$column->setPlatformOption('collation', (string) $collation);
$table = new DbalTable($tableName, [$column]);
$table->setPrimaryKey([$column->getName()]);
try {
$sm->createTable($table);
} catch (Exception $x) {
// SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is XYZ bytes
return false;
}
try {
$sm->dropTable($tableName);
} catch (Exception $x) {
}
return true;
} | php | public function isCollationSupportedForKeys($collation, $fieldLength)
{
$sm = $this->getSchemaManager();
$existingTables = array_map('strtolower', $sm->listTableNames());
for ($i = 0; ; ++$i) {
$tableName = 'tmp_checkCollationFieldLength' . $i;
if (!in_array(strtolower($tableName), $existingTables)) {
break;
}
}
$column = new DbalColumn('ColumnName', DbalType::getType(DbalType::STRING), ['length' => (int) $fieldLength]);
$column->setPlatformOption('collation', (string) $collation);
$table = new DbalTable($tableName, [$column]);
$table->setPrimaryKey([$column->getName()]);
try {
$sm->createTable($table);
} catch (Exception $x) {
// SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is XYZ bytes
return false;
}
try {
$sm->dropTable($tableName);
} catch (Exception $x) {
}
return true;
} | [
"public",
"function",
"isCollationSupportedForKeys",
"(",
"$",
"collation",
",",
"$",
"fieldLength",
")",
"{",
"$",
"sm",
"=",
"$",
"this",
"->",
"getSchemaManager",
"(",
")",
";",
"$",
"existingTables",
"=",
"array_map",
"(",
"'strtolower'",
",",
"$",
"sm",
"->",
"listTableNames",
"(",
")",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
";",
"++",
"$",
"i",
")",
"{",
"$",
"tableName",
"=",
"'tmp_checkCollationFieldLength'",
".",
"$",
"i",
";",
"if",
"(",
"!",
"in_array",
"(",
"strtolower",
"(",
"$",
"tableName",
")",
",",
"$",
"existingTables",
")",
")",
"{",
"break",
";",
"}",
"}",
"$",
"column",
"=",
"new",
"DbalColumn",
"(",
"'ColumnName'",
",",
"DbalType",
"::",
"getType",
"(",
"DbalType",
"::",
"STRING",
")",
",",
"[",
"'length'",
"=>",
"(",
"int",
")",
"$",
"fieldLength",
"]",
")",
";",
"$",
"column",
"->",
"setPlatformOption",
"(",
"'collation'",
",",
"(",
"string",
")",
"$",
"collation",
")",
";",
"$",
"table",
"=",
"new",
"DbalTable",
"(",
"$",
"tableName",
",",
"[",
"$",
"column",
"]",
")",
";",
"$",
"table",
"->",
"setPrimaryKey",
"(",
"[",
"$",
"column",
"->",
"getName",
"(",
")",
"]",
")",
";",
"try",
"{",
"$",
"sm",
"->",
"createTable",
"(",
"$",
"table",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"x",
")",
"{",
"// SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is XYZ bytes",
"return",
"false",
";",
"}",
"try",
"{",
"$",
"sm",
"->",
"dropTable",
"(",
"$",
"tableName",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"x",
")",
"{",
"}",
"return",
"true",
";",
"}"
] | Check if a collation can be used for keys of a specific length.
@param string $collation the name of a collation
@param int $fieldLength the length (in chars) of a field to be used as key/index
@return bool | [
"Check",
"if",
"a",
"collation",
"can",
"be",
"used",
"for",
"keys",
"of",
"a",
"specific",
"length",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Database/Connection/Connection.php#L513-L539 | train |
concrete5/concrete5 | concrete/src/Permission/IPRangesCsvWriter.php | IPRangesCsvWriter.projectRange | private function projectRange(IPRange $range)
{
$result = [
$range->getIpRange()->toString(),
$range->getIpRange()->getComparableStartString(),
$range->getIpRange()->getComparableEndString(),
];
if ($this->type === IPService::IPRANGETYPE_BLACKLIST_AUTOMATIC) {
$dt = $range->getExpires();
if ($dt === null) {
$result[] = '';
} else {
$result[] = $this->dateHelper->formatCustom('c', $dt);
}
}
return $result;
} | php | private function projectRange(IPRange $range)
{
$result = [
$range->getIpRange()->toString(),
$range->getIpRange()->getComparableStartString(),
$range->getIpRange()->getComparableEndString(),
];
if ($this->type === IPService::IPRANGETYPE_BLACKLIST_AUTOMATIC) {
$dt = $range->getExpires();
if ($dt === null) {
$result[] = '';
} else {
$result[] = $this->dateHelper->formatCustom('c', $dt);
}
}
return $result;
} | [
"private",
"function",
"projectRange",
"(",
"IPRange",
"$",
"range",
")",
"{",
"$",
"result",
"=",
"[",
"$",
"range",
"->",
"getIpRange",
"(",
")",
"->",
"toString",
"(",
")",
",",
"$",
"range",
"->",
"getIpRange",
"(",
")",
"->",
"getComparableStartString",
"(",
")",
",",
"$",
"range",
"->",
"getIpRange",
"(",
")",
"->",
"getComparableEndString",
"(",
")",
",",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"type",
"===",
"IPService",
"::",
"IPRANGETYPE_BLACKLIST_AUTOMATIC",
")",
"{",
"$",
"dt",
"=",
"$",
"range",
"->",
"getExpires",
"(",
")",
";",
"if",
"(",
"$",
"dt",
"===",
"null",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"this",
"->",
"dateHelper",
"->",
"formatCustom",
"(",
"'c'",
",",
"$",
"dt",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Turn an IPRange instance into an array.
@param IPRange $range
@return string[] | [
"Turn",
"an",
"IPRange",
"instance",
"into",
"an",
"array",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/IPRangesCsvWriter.php#L91-L108 | train |
concrete5/concrete5 | concrete/src/Permission/IPRangesCsvWriter.php | IPRangesCsvWriter.getHeaders | private function getHeaders()
{
$headers = [t('IP Range'), t('Start address'), t('End address')];
if ($this->type === IPService::IPRANGETYPE_BLACKLIST_AUTOMATIC) {
$headers[] = t('Expiration');
}
return $headers;
} | php | private function getHeaders()
{
$headers = [t('IP Range'), t('Start address'), t('End address')];
if ($this->type === IPService::IPRANGETYPE_BLACKLIST_AUTOMATIC) {
$headers[] = t('Expiration');
}
return $headers;
} | [
"private",
"function",
"getHeaders",
"(",
")",
"{",
"$",
"headers",
"=",
"[",
"t",
"(",
"'IP Range'",
")",
",",
"t",
"(",
"'Start address'",
")",
",",
"t",
"(",
"'End address'",
")",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"type",
"===",
"IPService",
"::",
"IPRANGETYPE_BLACKLIST_AUTOMATIC",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"t",
"(",
"'Expiration'",
")",
";",
"}",
"return",
"$",
"headers",
";",
"}"
] | Get the headers of the CSV.
@return string[] | [
"Get",
"the",
"headers",
"of",
"the",
"CSV",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/IPRangesCsvWriter.php#L115-L123 | train |
concrete5/concrete5 | concrete/src/Area/Area.php | Area.showControls | public function showControls()
{
if ($this->showControls === true || $this->showControls === false) {
return $this->showControls;
} else {
$c = $this->getAreaCollectionObject();
return $c->isEditMode();
}
} | php | public function showControls()
{
if ($this->showControls === true || $this->showControls === false) {
return $this->showControls;
} else {
$c = $this->getAreaCollectionObject();
return $c->isEditMode();
}
} | [
"public",
"function",
"showControls",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"showControls",
"===",
"true",
"||",
"$",
"this",
"->",
"showControls",
"===",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"showControls",
";",
"}",
"else",
"{",
"$",
"c",
"=",
"$",
"this",
"->",
"getAreaCollectionObject",
"(",
")",
";",
"return",
"$",
"c",
"->",
"isEditMode",
"(",
")",
";",
"}",
"}"
] | Returns whether or not controls are to be displayed.
@return bool | [
"Returns",
"whether",
"or",
"not",
"controls",
"are",
"to",
"be",
"displayed",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Area/Area.php#L119-L128 | train |
concrete5/concrete5 | concrete/src/Area/Area.php | Area.getTotalBlocksInArea | public function getTotalBlocksInArea($c = false)
{
if (!$c) {
$c = $this->c;
}
// exclude the area layout proxy block from counting.
$this->load($c);
$db = Database::connection();
$r = $db->fetchColumn(
'select count(b.bID) from CollectionVersionBlocks cvb inner join Blocks b on cvb.bID = b.bID inner join BlockTypes bt on b.btID = bt.btID where cID = ? and cvID = ? and arHandle = ? and btHandle <> ?',
array($c->getCollectionID(), $c->getVersionID(), $this->arHandle, BLOCK_HANDLE_LAYOUT_PROXY)
);
// now grab sub-blocks.
// NOTE: this will only traverse one level. Deal with it.
$arHandles = $db->GetCol('select arHandle from Areas where arParentID = ?', array($this->arID));
if (is_array($arHandles) && count($arHandles) > 0) {
$v = array($c->getCollectionID(), $c->getVersionID());
$q = 'select count(bID) from CollectionVersionBlocks where cID = ? and cvID = ? and arHandle in (';
for ($i = 0; $i < count($arHandles); ++$i) {
$arHandle = $arHandles[$i];
$v[] = $arHandle;
$q .= '?';
if (($i + 1) < count($arHandles)) {
$q .= ',';
}
}
$q .= ')';
$sr = $db->fetchColumn($q, $v);
$r += $sr;
}
return (int) $r;
} | php | public function getTotalBlocksInArea($c = false)
{
if (!$c) {
$c = $this->c;
}
// exclude the area layout proxy block from counting.
$this->load($c);
$db = Database::connection();
$r = $db->fetchColumn(
'select count(b.bID) from CollectionVersionBlocks cvb inner join Blocks b on cvb.bID = b.bID inner join BlockTypes bt on b.btID = bt.btID where cID = ? and cvID = ? and arHandle = ? and btHandle <> ?',
array($c->getCollectionID(), $c->getVersionID(), $this->arHandle, BLOCK_HANDLE_LAYOUT_PROXY)
);
// now grab sub-blocks.
// NOTE: this will only traverse one level. Deal with it.
$arHandles = $db->GetCol('select arHandle from Areas where arParentID = ?', array($this->arID));
if (is_array($arHandles) && count($arHandles) > 0) {
$v = array($c->getCollectionID(), $c->getVersionID());
$q = 'select count(bID) from CollectionVersionBlocks where cID = ? and cvID = ? and arHandle in (';
for ($i = 0; $i < count($arHandles); ++$i) {
$arHandle = $arHandles[$i];
$v[] = $arHandle;
$q .= '?';
if (($i + 1) < count($arHandles)) {
$q .= ',';
}
}
$q .= ')';
$sr = $db->fetchColumn($q, $v);
$r += $sr;
}
return (int) $r;
} | [
"public",
"function",
"getTotalBlocksInArea",
"(",
"$",
"c",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"c",
")",
"{",
"$",
"c",
"=",
"$",
"this",
"->",
"c",
";",
"}",
"// exclude the area layout proxy block from counting.",
"$",
"this",
"->",
"load",
"(",
"$",
"c",
")",
";",
"$",
"db",
"=",
"Database",
"::",
"connection",
"(",
")",
";",
"$",
"r",
"=",
"$",
"db",
"->",
"fetchColumn",
"(",
"'select count(b.bID) from CollectionVersionBlocks cvb inner join Blocks b on cvb.bID = b.bID inner join BlockTypes bt on b.btID = bt.btID where cID = ? and cvID = ? and arHandle = ? and btHandle <> ?'",
",",
"array",
"(",
"$",
"c",
"->",
"getCollectionID",
"(",
")",
",",
"$",
"c",
"->",
"getVersionID",
"(",
")",
",",
"$",
"this",
"->",
"arHandle",
",",
"BLOCK_HANDLE_LAYOUT_PROXY",
")",
")",
";",
"// now grab sub-blocks.",
"// NOTE: this will only traverse one level. Deal with it.",
"$",
"arHandles",
"=",
"$",
"db",
"->",
"GetCol",
"(",
"'select arHandle from Areas where arParentID = ?'",
",",
"array",
"(",
"$",
"this",
"->",
"arID",
")",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"arHandles",
")",
"&&",
"count",
"(",
"$",
"arHandles",
")",
">",
"0",
")",
"{",
"$",
"v",
"=",
"array",
"(",
"$",
"c",
"->",
"getCollectionID",
"(",
")",
",",
"$",
"c",
"->",
"getVersionID",
"(",
")",
")",
";",
"$",
"q",
"=",
"'select count(bID) from CollectionVersionBlocks where cID = ? and cvID = ? and arHandle in ('",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"arHandles",
")",
";",
"++",
"$",
"i",
")",
"{",
"$",
"arHandle",
"=",
"$",
"arHandles",
"[",
"$",
"i",
"]",
";",
"$",
"v",
"[",
"]",
"=",
"$",
"arHandle",
";",
"$",
"q",
".=",
"'?'",
";",
"if",
"(",
"(",
"$",
"i",
"+",
"1",
")",
"<",
"count",
"(",
"$",
"arHandles",
")",
")",
"{",
"$",
"q",
".=",
"','",
";",
"}",
"}",
"$",
"q",
".=",
"')'",
";",
"$",
"sr",
"=",
"$",
"db",
"->",
"fetchColumn",
"(",
"$",
"q",
",",
"$",
"v",
")",
";",
"$",
"r",
"+=",
"$",
"sr",
";",
"}",
"return",
"(",
"int",
")",
"$",
"r",
";",
"}"
] | Returns the total number of blocks in an area.
@param Page $c must be passed if the display() method has not been run on the area object yet.
@return int | [
"Returns",
"the",
"total",
"number",
"of",
"blocks",
"in",
"an",
"area",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Area/Area.php#L304-L338 | train |
concrete5/concrete5 | concrete/src/Area/Area.php | Area.getTotalBlocksInAreaEditMode | public function getTotalBlocksInAreaEditMode()
{
$db = Database::connection();
return (int) $db->fetchColumn(
'select count(b.bID) from CollectionVersionBlocks cvb inner join Blocks b on cvb.bID = b.bID inner join BlockTypes bt on b.btID = bt.btID where cID = ? and cvID = ? and arHandle = ?',
array($this->c->getCollectionID(), $this->c->getVersionID(), $this->arHandle)
);
} | php | public function getTotalBlocksInAreaEditMode()
{
$db = Database::connection();
return (int) $db->fetchColumn(
'select count(b.bID) from CollectionVersionBlocks cvb inner join Blocks b on cvb.bID = b.bID inner join BlockTypes bt on b.btID = bt.btID where cID = ? and cvID = ? and arHandle = ?',
array($this->c->getCollectionID(), $this->c->getVersionID(), $this->arHandle)
);
} | [
"public",
"function",
"getTotalBlocksInAreaEditMode",
"(",
")",
"{",
"$",
"db",
"=",
"Database",
"::",
"connection",
"(",
")",
";",
"return",
"(",
"int",
")",
"$",
"db",
"->",
"fetchColumn",
"(",
"'select count(b.bID) from CollectionVersionBlocks cvb inner join Blocks b on cvb.bID = b.bID inner join BlockTypes bt on b.btID = bt.btID where cID = ? and cvID = ? and arHandle = ?'",
",",
"array",
"(",
"$",
"this",
"->",
"c",
"->",
"getCollectionID",
"(",
")",
",",
"$",
"this",
"->",
"c",
"->",
"getVersionID",
"(",
")",
",",
"$",
"this",
"->",
"arHandle",
")",
")",
";",
"}"
] | Returns the amount of actual blocks in the area, does not exclude core blocks or layouts, does not recurse.
@return int | [
"Returns",
"the",
"amount",
"of",
"actual",
"blocks",
"in",
"the",
"area",
"does",
"not",
"exclude",
"core",
"blocks",
"or",
"layouts",
"does",
"not",
"recurse",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Area/Area.php#L345-L352 | train |
concrete5/concrete5 | concrete/src/Area/Area.php | Area.get | final public static function get($c, $arHandle)
{
if (!is_object($c)) {
return false;
}
$identifier = sprintf('/page/area/%s', $c->getCollectionID());
$cache = \Core::make('cache/request');
$item = $cache->getItem($identifier);
if (!$item->isMiss()) {
$areas = $item->get();
} else {
$areas = array();
$db = Database::connection();
// First, we verify that this is a legitimate area
$v = array($c->getCollectionID());
$q = 'select arID, arHandle, cID, arOverrideCollectionPermissions, arInheritPermissionsFromAreaOnCID, arIsGlobal, arParentID from Areas where cID = ?';
$r = $db->executeQuery($q, $v);
while ($arRow = $r->FetchRow()) {
if ($arRow['arID'] > 0) {
if ($arRow['arIsGlobal']) {
$obj = new GlobalArea($arHandle);
} else {
if ($arRow['arParentID']) {
$arParentHandle = self::getAreaHandleFromID($arRow['arParentID']);
$obj = new SubArea($arHandle, $arParentHandle, $arRow['arParentID']);
} else {
$obj = new self($arHandle);
}
}
$obj->setPropertiesFromArray($arRow);
$obj->c = $c;
$arRowHandle = $arRow['arHandle'];
$areas[$arRowHandle] = $obj;
}
}
$cache->save($item->set($areas));
}
return isset($areas[$arHandle]) ? $areas[$arHandle] : null;
} | php | final public static function get($c, $arHandle)
{
if (!is_object($c)) {
return false;
}
$identifier = sprintf('/page/area/%s', $c->getCollectionID());
$cache = \Core::make('cache/request');
$item = $cache->getItem($identifier);
if (!$item->isMiss()) {
$areas = $item->get();
} else {
$areas = array();
$db = Database::connection();
// First, we verify that this is a legitimate area
$v = array($c->getCollectionID());
$q = 'select arID, arHandle, cID, arOverrideCollectionPermissions, arInheritPermissionsFromAreaOnCID, arIsGlobal, arParentID from Areas where cID = ?';
$r = $db->executeQuery($q, $v);
while ($arRow = $r->FetchRow()) {
if ($arRow['arID'] > 0) {
if ($arRow['arIsGlobal']) {
$obj = new GlobalArea($arHandle);
} else {
if ($arRow['arParentID']) {
$arParentHandle = self::getAreaHandleFromID($arRow['arParentID']);
$obj = new SubArea($arHandle, $arParentHandle, $arRow['arParentID']);
} else {
$obj = new self($arHandle);
}
}
$obj->setPropertiesFromArray($arRow);
$obj->c = $c;
$arRowHandle = $arRow['arHandle'];
$areas[$arRowHandle] = $obj;
}
}
$cache->save($item->set($areas));
}
return isset($areas[$arHandle]) ? $areas[$arHandle] : null;
} | [
"final",
"public",
"static",
"function",
"get",
"(",
"$",
"c",
",",
"$",
"arHandle",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"c",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"identifier",
"=",
"sprintf",
"(",
"'/page/area/%s'",
",",
"$",
"c",
"->",
"getCollectionID",
"(",
")",
")",
";",
"$",
"cache",
"=",
"\\",
"Core",
"::",
"make",
"(",
"'cache/request'",
")",
";",
"$",
"item",
"=",
"$",
"cache",
"->",
"getItem",
"(",
"$",
"identifier",
")",
";",
"if",
"(",
"!",
"$",
"item",
"->",
"isMiss",
"(",
")",
")",
"{",
"$",
"areas",
"=",
"$",
"item",
"->",
"get",
"(",
")",
";",
"}",
"else",
"{",
"$",
"areas",
"=",
"array",
"(",
")",
";",
"$",
"db",
"=",
"Database",
"::",
"connection",
"(",
")",
";",
"// First, we verify that this is a legitimate area",
"$",
"v",
"=",
"array",
"(",
"$",
"c",
"->",
"getCollectionID",
"(",
")",
")",
";",
"$",
"q",
"=",
"'select arID, arHandle, cID, arOverrideCollectionPermissions, arInheritPermissionsFromAreaOnCID, arIsGlobal, arParentID from Areas where cID = ?'",
";",
"$",
"r",
"=",
"$",
"db",
"->",
"executeQuery",
"(",
"$",
"q",
",",
"$",
"v",
")",
";",
"while",
"(",
"$",
"arRow",
"=",
"$",
"r",
"->",
"FetchRow",
"(",
")",
")",
"{",
"if",
"(",
"$",
"arRow",
"[",
"'arID'",
"]",
">",
"0",
")",
"{",
"if",
"(",
"$",
"arRow",
"[",
"'arIsGlobal'",
"]",
")",
"{",
"$",
"obj",
"=",
"new",
"GlobalArea",
"(",
"$",
"arHandle",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"arRow",
"[",
"'arParentID'",
"]",
")",
"{",
"$",
"arParentHandle",
"=",
"self",
"::",
"getAreaHandleFromID",
"(",
"$",
"arRow",
"[",
"'arParentID'",
"]",
")",
";",
"$",
"obj",
"=",
"new",
"SubArea",
"(",
"$",
"arHandle",
",",
"$",
"arParentHandle",
",",
"$",
"arRow",
"[",
"'arParentID'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"obj",
"=",
"new",
"self",
"(",
"$",
"arHandle",
")",
";",
"}",
"}",
"$",
"obj",
"->",
"setPropertiesFromArray",
"(",
"$",
"arRow",
")",
";",
"$",
"obj",
"->",
"c",
"=",
"$",
"c",
";",
"$",
"arRowHandle",
"=",
"$",
"arRow",
"[",
"'arHandle'",
"]",
";",
"$",
"areas",
"[",
"$",
"arRowHandle",
"]",
"=",
"$",
"obj",
";",
"}",
"}",
"$",
"cache",
"->",
"save",
"(",
"$",
"item",
"->",
"set",
"(",
"$",
"areas",
")",
")",
";",
"}",
"return",
"isset",
"(",
"$",
"areas",
"[",
"$",
"arHandle",
"]",
")",
"?",
"$",
"areas",
"[",
"$",
"arHandle",
"]",
":",
"null",
";",
"}"
] | Gets the Area object for the given page and area handle.
@param Page $c
@param string $arHandle
@return Area | [
"Gets",
"the",
"Area",
"object",
"for",
"the",
"given",
"page",
"and",
"area",
"handle",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Area/Area.php#L438-L478 | train |
concrete5/concrete5 | concrete/src/Area/Area.php | Area.create | public function create($c, $arHandle)
{
$db = Database::connection();
$db->Replace(
'Areas',
array('cID' => $c->getCollectionID(), 'arHandle' => $arHandle, 'arIsGlobal' => $this->isGlobalArea() ? 1 : 0),
array('arHandle', 'cID'),
true
);
$this->refreshCache($c);
$area = self::get($c, $arHandle);
$area->rescanAreaPermissionsChain();
return $area;
} | php | public function create($c, $arHandle)
{
$db = Database::connection();
$db->Replace(
'Areas',
array('cID' => $c->getCollectionID(), 'arHandle' => $arHandle, 'arIsGlobal' => $this->isGlobalArea() ? 1 : 0),
array('arHandle', 'cID'),
true
);
$this->refreshCache($c);
$area = self::get($c, $arHandle);
$area->rescanAreaPermissionsChain();
return $area;
} | [
"public",
"function",
"create",
"(",
"$",
"c",
",",
"$",
"arHandle",
")",
"{",
"$",
"db",
"=",
"Database",
"::",
"connection",
"(",
")",
";",
"$",
"db",
"->",
"Replace",
"(",
"'Areas'",
",",
"array",
"(",
"'cID'",
"=>",
"$",
"c",
"->",
"getCollectionID",
"(",
")",
",",
"'arHandle'",
"=>",
"$",
"arHandle",
",",
"'arIsGlobal'",
"=>",
"$",
"this",
"->",
"isGlobalArea",
"(",
")",
"?",
"1",
":",
"0",
")",
",",
"array",
"(",
"'arHandle'",
",",
"'cID'",
")",
",",
"true",
")",
";",
"$",
"this",
"->",
"refreshCache",
"(",
"$",
"c",
")",
";",
"$",
"area",
"=",
"self",
"::",
"get",
"(",
"$",
"c",
",",
"$",
"arHandle",
")",
";",
"$",
"area",
"->",
"rescanAreaPermissionsChain",
"(",
")",
";",
"return",
"$",
"area",
";",
"}"
] | Creates an area in the database. I would like to make this static but PHP pre 5.3 sucks at this stuff.
@param Page $c
@param string $arHandle
@return Area | [
"Creates",
"an",
"area",
"in",
"the",
"database",
".",
"I",
"would",
"like",
"to",
"make",
"this",
"static",
"but",
"PHP",
"pre",
"5",
".",
"3",
"sucks",
"at",
"this",
"stuff",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Area/Area.php#L488-L502 | train |
concrete5/concrete5 | concrete/src/Area/Area.php | Area.getAreaBlocksArray | public function getAreaBlocksArray($c = false)
{
if (!$c) {
$c = $this->c;
}
if (!$this->arIsLoaded) {
$this->load($c);
}
return $this->areaBlocksArray;
} | php | public function getAreaBlocksArray($c = false)
{
if (!$c) {
$c = $this->c;
}
if (!$this->arIsLoaded) {
$this->load($c);
}
return $this->areaBlocksArray;
} | [
"public",
"function",
"getAreaBlocksArray",
"(",
"$",
"c",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"c",
")",
"{",
"$",
"c",
"=",
"$",
"this",
"->",
"c",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"arIsLoaded",
")",
"{",
"$",
"this",
"->",
"load",
"(",
"$",
"c",
")",
";",
"}",
"return",
"$",
"this",
"->",
"areaBlocksArray",
";",
"}"
] | Get all of the blocks within the current area for a given page.
@param Page|bool $c
@return Block[] | [
"Get",
"all",
"of",
"the",
"blocks",
"within",
"the",
"current",
"area",
"for",
"a",
"given",
"page",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Area/Area.php#L533-L543 | train |
concrete5/concrete5 | concrete/src/Area/Area.php | Area.getHandleList | public static function getHandleList()
{
$db = Database::connection();
$r = $db->executeQuery('select distinct arHandle from Areas where arParentID = 0 and arIsGlobal = 0 order by arHandle asc');
$handles = array();
while ($row = $r->FetchRow()) {
$handles[] = $row['arHandle'];
}
$r->Free();
unset($r);
unset($db);
return $handles;
} | php | public static function getHandleList()
{
$db = Database::connection();
$r = $db->executeQuery('select distinct arHandle from Areas where arParentID = 0 and arIsGlobal = 0 order by arHandle asc');
$handles = array();
while ($row = $r->FetchRow()) {
$handles[] = $row['arHandle'];
}
$r->Free();
unset($r);
unset($db);
return $handles;
} | [
"public",
"static",
"function",
"getHandleList",
"(",
")",
"{",
"$",
"db",
"=",
"Database",
"::",
"connection",
"(",
")",
";",
"$",
"r",
"=",
"$",
"db",
"->",
"executeQuery",
"(",
"'select distinct arHandle from Areas where arParentID = 0 and arIsGlobal = 0 order by arHandle asc'",
")",
";",
"$",
"handles",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"r",
"->",
"FetchRow",
"(",
")",
")",
"{",
"$",
"handles",
"[",
"]",
"=",
"$",
"row",
"[",
"'arHandle'",
"]",
";",
"}",
"$",
"r",
"->",
"Free",
"(",
")",
";",
"unset",
"(",
"$",
"r",
")",
";",
"unset",
"(",
"$",
"db",
")",
";",
"return",
"$",
"handles",
";",
"}"
] | Gets a list of all areas.
@return array | [
"Gets",
"a",
"list",
"of",
"all",
"areas",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Area/Area.php#L550-L563 | train |
concrete5/concrete5 | concrete/src/Area/Area.php | Area.revertToPagePermissions | public function revertToPagePermissions()
{
// this function removes all permissions records for a particular area on this page
// and sets it to inherit from the page above
// this function will also need to ensure that pages below it do the same
$db = Database::connection();
$v = array($this->getAreaHandle(), $this->getCollectionID());
$db->executeQuery('delete from AreaPermissionAssignments where arHandle = ? and cID = ?', $v);
$db->executeQuery('update Areas set arOverrideCollectionPermissions = 0 where arID = ?', array($this->getAreaID()));
// now we set rescan this area to determine where it -should- be inheriting from
$this->arOverrideCollectionPermissions = false;
$this->rescanAreaPermissionsChain();
$areac = $this->getAreaCollectionObject();
if ($areac->isMasterCollection()) {
$this->rescanSubAreaPermissionsMasterCollection($areac);
} else {
if ($areac->overrideTemplatePermissions()) {
// now we scan sub areas
$this->rescanSubAreaPermissions();
}
}
} | php | public function revertToPagePermissions()
{
// this function removes all permissions records for a particular area on this page
// and sets it to inherit from the page above
// this function will also need to ensure that pages below it do the same
$db = Database::connection();
$v = array($this->getAreaHandle(), $this->getCollectionID());
$db->executeQuery('delete from AreaPermissionAssignments where arHandle = ? and cID = ?', $v);
$db->executeQuery('update Areas set arOverrideCollectionPermissions = 0 where arID = ?', array($this->getAreaID()));
// now we set rescan this area to determine where it -should- be inheriting from
$this->arOverrideCollectionPermissions = false;
$this->rescanAreaPermissionsChain();
$areac = $this->getAreaCollectionObject();
if ($areac->isMasterCollection()) {
$this->rescanSubAreaPermissionsMasterCollection($areac);
} else {
if ($areac->overrideTemplatePermissions()) {
// now we scan sub areas
$this->rescanSubAreaPermissions();
}
}
} | [
"public",
"function",
"revertToPagePermissions",
"(",
")",
"{",
"// this function removes all permissions records for a particular area on this page",
"// and sets it to inherit from the page above",
"// this function will also need to ensure that pages below it do the same",
"$",
"db",
"=",
"Database",
"::",
"connection",
"(",
")",
";",
"$",
"v",
"=",
"array",
"(",
"$",
"this",
"->",
"getAreaHandle",
"(",
")",
",",
"$",
"this",
"->",
"getCollectionID",
"(",
")",
")",
";",
"$",
"db",
"->",
"executeQuery",
"(",
"'delete from AreaPermissionAssignments where arHandle = ? and cID = ?'",
",",
"$",
"v",
")",
";",
"$",
"db",
"->",
"executeQuery",
"(",
"'update Areas set arOverrideCollectionPermissions = 0 where arID = ?'",
",",
"array",
"(",
"$",
"this",
"->",
"getAreaID",
"(",
")",
")",
")",
";",
"// now we set rescan this area to determine where it -should- be inheriting from",
"$",
"this",
"->",
"arOverrideCollectionPermissions",
"=",
"false",
";",
"$",
"this",
"->",
"rescanAreaPermissionsChain",
"(",
")",
";",
"$",
"areac",
"=",
"$",
"this",
"->",
"getAreaCollectionObject",
"(",
")",
";",
"if",
"(",
"$",
"areac",
"->",
"isMasterCollection",
"(",
")",
")",
"{",
"$",
"this",
"->",
"rescanSubAreaPermissionsMasterCollection",
"(",
"$",
"areac",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"areac",
"->",
"overrideTemplatePermissions",
"(",
")",
")",
"{",
"// now we scan sub areas",
"$",
"this",
"->",
"rescanSubAreaPermissions",
"(",
")",
";",
"}",
"}",
"}"
] | This function removes all permissions records for the current Area
and sets it to inherit from the Page permissions. | [
"This",
"function",
"removes",
"all",
"permissions",
"records",
"for",
"the",
"current",
"Area",
"and",
"sets",
"it",
"to",
"inherit",
"from",
"the",
"Page",
"permissions",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Area/Area.php#L598-L622 | train |
concrete5/concrete5 | concrete/src/Area/Area.php | Area.rescanAreaPermissionsChain | public function rescanAreaPermissionsChain()
{
$db = Database::connection();
if ($this->overrideCollectionPermissions()) {
return false;
}
// first, we obtain the inheritance of permissions for this particular collection
$areac = $this->getAreaCollectionObject();
if (is_a($areac, 'Page')) {
if ($areac->getCollectionInheritance() == 'PARENT') {
$cIDToCheck = $areac->getCollectionParentID();
// first, we temporarily set the arInheritPermissionsFromAreaOnCID to whatever the arInheritPermissionsFromAreaOnCID is set to
// in the immediate parent collection
$arInheritPermissionsFromAreaOnCID = $db->fetchColumn(
'select a.arInheritPermissionsFromAreaOnCID from Pages c inner join Areas a on (c.cID = a.cID) where c.cID = ? and a.arHandle = ?',
array($cIDToCheck, $this->getAreaHandle())
);
if ($arInheritPermissionsFromAreaOnCID > 0) {
$db->executeQuery(
'update Areas set arInheritPermissionsFromAreaOnCID = ? where arID = ?',
array($arInheritPermissionsFromAreaOnCID, $this->getAreaID())
);
}
// now we do the recursive rescan to see if any areas themselves override collection permissions
while ($cIDToCheck > 0) {
$row = $db->fetchAssoc(
'select c.cParentID, c.cID, a.arHandle, a.arOverrideCollectionPermissions, a.arID from Pages c inner join Areas a on (c.cID = a.cID) where c.cID = ? and a.arHandle = ?',
array($cIDToCheck, $this->getAreaHandle())
);
if (empty($row)) {
break;
}
if ($row['arOverrideCollectionPermissions'] == 1) {
if ($row['cID'] > 0) {
// then that means we have successfully found a parent area record that we can inherit from. So we set
// out current area to inherit from that COLLECTION ID (not area ID - from the collection ID)
$db->executeQuery(
'update Areas set arInheritPermissionsFromAreaOnCID = ? where arID = ?',
array($row['cID'], $this->getAreaID())
);
$this->arInheritPermissionsFromAreaOnCID = $row['cID'];
}
break;
}
$cIDToCheck = $row['cParentID'];
}
} else {
if ($areac->getCollectionInheritance() == 'TEMPLATE') {
// we grab an area on the master collection (if it exists)
$doOverride = $db->fetchColumn(
'select arOverrideCollectionPermissions from Pages c inner join Areas a on (c.cID = a.cID) where c.cID = ? and a.arHandle = ?',
array($areac->getPermissionsCollectionID(), $this->getAreaHandle())
);
if ($doOverride && $areac->getPermissionsCollectionID() > 0) {
$db->executeQuery(
'update Areas set arInheritPermissionsFromAreaOnCID = ? where arID = ?',
array($areac->getPermissionsCollectionID(), $this->getAreaID())
);
$this->arInheritPermissionsFromAreaOnCID = $areac->getPermissionsCollectionID();
}
}
}
}
} | php | public function rescanAreaPermissionsChain()
{
$db = Database::connection();
if ($this->overrideCollectionPermissions()) {
return false;
}
// first, we obtain the inheritance of permissions for this particular collection
$areac = $this->getAreaCollectionObject();
if (is_a($areac, 'Page')) {
if ($areac->getCollectionInheritance() == 'PARENT') {
$cIDToCheck = $areac->getCollectionParentID();
// first, we temporarily set the arInheritPermissionsFromAreaOnCID to whatever the arInheritPermissionsFromAreaOnCID is set to
// in the immediate parent collection
$arInheritPermissionsFromAreaOnCID = $db->fetchColumn(
'select a.arInheritPermissionsFromAreaOnCID from Pages c inner join Areas a on (c.cID = a.cID) where c.cID = ? and a.arHandle = ?',
array($cIDToCheck, $this->getAreaHandle())
);
if ($arInheritPermissionsFromAreaOnCID > 0) {
$db->executeQuery(
'update Areas set arInheritPermissionsFromAreaOnCID = ? where arID = ?',
array($arInheritPermissionsFromAreaOnCID, $this->getAreaID())
);
}
// now we do the recursive rescan to see if any areas themselves override collection permissions
while ($cIDToCheck > 0) {
$row = $db->fetchAssoc(
'select c.cParentID, c.cID, a.arHandle, a.arOverrideCollectionPermissions, a.arID from Pages c inner join Areas a on (c.cID = a.cID) where c.cID = ? and a.arHandle = ?',
array($cIDToCheck, $this->getAreaHandle())
);
if (empty($row)) {
break;
}
if ($row['arOverrideCollectionPermissions'] == 1) {
if ($row['cID'] > 0) {
// then that means we have successfully found a parent area record that we can inherit from. So we set
// out current area to inherit from that COLLECTION ID (not area ID - from the collection ID)
$db->executeQuery(
'update Areas set arInheritPermissionsFromAreaOnCID = ? where arID = ?',
array($row['cID'], $this->getAreaID())
);
$this->arInheritPermissionsFromAreaOnCID = $row['cID'];
}
break;
}
$cIDToCheck = $row['cParentID'];
}
} else {
if ($areac->getCollectionInheritance() == 'TEMPLATE') {
// we grab an area on the master collection (if it exists)
$doOverride = $db->fetchColumn(
'select arOverrideCollectionPermissions from Pages c inner join Areas a on (c.cID = a.cID) where c.cID = ? and a.arHandle = ?',
array($areac->getPermissionsCollectionID(), $this->getAreaHandle())
);
if ($doOverride && $areac->getPermissionsCollectionID() > 0) {
$db->executeQuery(
'update Areas set arInheritPermissionsFromAreaOnCID = ? where arID = ?',
array($areac->getPermissionsCollectionID(), $this->getAreaID())
);
$this->arInheritPermissionsFromAreaOnCID = $areac->getPermissionsCollectionID();
}
}
}
}
} | [
"public",
"function",
"rescanAreaPermissionsChain",
"(",
")",
"{",
"$",
"db",
"=",
"Database",
"::",
"connection",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"overrideCollectionPermissions",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"// first, we obtain the inheritance of permissions for this particular collection",
"$",
"areac",
"=",
"$",
"this",
"->",
"getAreaCollectionObject",
"(",
")",
";",
"if",
"(",
"is_a",
"(",
"$",
"areac",
",",
"'Page'",
")",
")",
"{",
"if",
"(",
"$",
"areac",
"->",
"getCollectionInheritance",
"(",
")",
"==",
"'PARENT'",
")",
"{",
"$",
"cIDToCheck",
"=",
"$",
"areac",
"->",
"getCollectionParentID",
"(",
")",
";",
"// first, we temporarily set the arInheritPermissionsFromAreaOnCID to whatever the arInheritPermissionsFromAreaOnCID is set to",
"// in the immediate parent collection",
"$",
"arInheritPermissionsFromAreaOnCID",
"=",
"$",
"db",
"->",
"fetchColumn",
"(",
"'select a.arInheritPermissionsFromAreaOnCID from Pages c inner join Areas a on (c.cID = a.cID) where c.cID = ? and a.arHandle = ?'",
",",
"array",
"(",
"$",
"cIDToCheck",
",",
"$",
"this",
"->",
"getAreaHandle",
"(",
")",
")",
")",
";",
"if",
"(",
"$",
"arInheritPermissionsFromAreaOnCID",
">",
"0",
")",
"{",
"$",
"db",
"->",
"executeQuery",
"(",
"'update Areas set arInheritPermissionsFromAreaOnCID = ? where arID = ?'",
",",
"array",
"(",
"$",
"arInheritPermissionsFromAreaOnCID",
",",
"$",
"this",
"->",
"getAreaID",
"(",
")",
")",
")",
";",
"}",
"// now we do the recursive rescan to see if any areas themselves override collection permissions",
"while",
"(",
"$",
"cIDToCheck",
">",
"0",
")",
"{",
"$",
"row",
"=",
"$",
"db",
"->",
"fetchAssoc",
"(",
"'select c.cParentID, c.cID, a.arHandle, a.arOverrideCollectionPermissions, a.arID from Pages c inner join Areas a on (c.cID = a.cID) where c.cID = ? and a.arHandle = ?'",
",",
"array",
"(",
"$",
"cIDToCheck",
",",
"$",
"this",
"->",
"getAreaHandle",
"(",
")",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"row",
")",
")",
"{",
"break",
";",
"}",
"if",
"(",
"$",
"row",
"[",
"'arOverrideCollectionPermissions'",
"]",
"==",
"1",
")",
"{",
"if",
"(",
"$",
"row",
"[",
"'cID'",
"]",
">",
"0",
")",
"{",
"// then that means we have successfully found a parent area record that we can inherit from. So we set",
"// out current area to inherit from that COLLECTION ID (not area ID - from the collection ID)",
"$",
"db",
"->",
"executeQuery",
"(",
"'update Areas set arInheritPermissionsFromAreaOnCID = ? where arID = ?'",
",",
"array",
"(",
"$",
"row",
"[",
"'cID'",
"]",
",",
"$",
"this",
"->",
"getAreaID",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"arInheritPermissionsFromAreaOnCID",
"=",
"$",
"row",
"[",
"'cID'",
"]",
";",
"}",
"break",
";",
"}",
"$",
"cIDToCheck",
"=",
"$",
"row",
"[",
"'cParentID'",
"]",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"areac",
"->",
"getCollectionInheritance",
"(",
")",
"==",
"'TEMPLATE'",
")",
"{",
"// we grab an area on the master collection (if it exists)",
"$",
"doOverride",
"=",
"$",
"db",
"->",
"fetchColumn",
"(",
"'select arOverrideCollectionPermissions from Pages c inner join Areas a on (c.cID = a.cID) where c.cID = ? and a.arHandle = ?'",
",",
"array",
"(",
"$",
"areac",
"->",
"getPermissionsCollectionID",
"(",
")",
",",
"$",
"this",
"->",
"getAreaHandle",
"(",
")",
")",
")",
";",
"if",
"(",
"$",
"doOverride",
"&&",
"$",
"areac",
"->",
"getPermissionsCollectionID",
"(",
")",
">",
"0",
")",
"{",
"$",
"db",
"->",
"executeQuery",
"(",
"'update Areas set arInheritPermissionsFromAreaOnCID = ? where arID = ?'",
",",
"array",
"(",
"$",
"areac",
"->",
"getPermissionsCollectionID",
"(",
")",
",",
"$",
"this",
"->",
"getAreaID",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"arInheritPermissionsFromAreaOnCID",
"=",
"$",
"areac",
"->",
"getPermissionsCollectionID",
"(",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Rescans the current Area's permissions ensuring that it's inheriting permissions properly up the chain.
@return bool | [
"Rescans",
"the",
"current",
"Area",
"s",
"permissions",
"ensuring",
"that",
"it",
"s",
"inheriting",
"permissions",
"properly",
"up",
"the",
"chain",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Area/Area.php#L634-L699 | train |
concrete5/concrete5 | concrete/src/Area/Area.php | Area.rescanSubAreaPermissionsMasterCollection | public function rescanSubAreaPermissionsMasterCollection($masterCollection)
{
// like above, but for those who have setup their pages to inherit master collection permissions
// this might make more sense in the collection class, but I'm putting it here
if (!$masterCollection->isMasterCollection()) {
return false;
}
// if we're not overriding permissions on the master collection then we set the ID to zero. If we are, then we set it to our own ID
$toSetCID = ($this->overrideCollectionPermissions()) ? $masterCollection->getCollectionID() : 0;
$db = Database::connection();
$v = array($this->getAreaHandle(), 'TEMPLATE', $masterCollection->getCollectionID());
$db->executeQuery(
'update Areas, Pages set Areas.arInheritPermissionsFromAreaOnCID = '.$toSetCID.' where Areas.cID = Pages.cID and Areas.arHandle = ? and cInheritPermissionsFrom = ? and arOverrideCollectionPermissions = 0 and cInheritPermissionsFromCID = ?',
$v
);
} | php | public function rescanSubAreaPermissionsMasterCollection($masterCollection)
{
// like above, but for those who have setup their pages to inherit master collection permissions
// this might make more sense in the collection class, but I'm putting it here
if (!$masterCollection->isMasterCollection()) {
return false;
}
// if we're not overriding permissions on the master collection then we set the ID to zero. If we are, then we set it to our own ID
$toSetCID = ($this->overrideCollectionPermissions()) ? $masterCollection->getCollectionID() : 0;
$db = Database::connection();
$v = array($this->getAreaHandle(), 'TEMPLATE', $masterCollection->getCollectionID());
$db->executeQuery(
'update Areas, Pages set Areas.arInheritPermissionsFromAreaOnCID = '.$toSetCID.' where Areas.cID = Pages.cID and Areas.arHandle = ? and cInheritPermissionsFrom = ? and arOverrideCollectionPermissions = 0 and cInheritPermissionsFromCID = ?',
$v
);
} | [
"public",
"function",
"rescanSubAreaPermissionsMasterCollection",
"(",
"$",
"masterCollection",
")",
"{",
"// like above, but for those who have setup their pages to inherit master collection permissions",
"// this might make more sense in the collection class, but I'm putting it here",
"if",
"(",
"!",
"$",
"masterCollection",
"->",
"isMasterCollection",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"// if we're not overriding permissions on the master collection then we set the ID to zero. If we are, then we set it to our own ID",
"$",
"toSetCID",
"=",
"(",
"$",
"this",
"->",
"overrideCollectionPermissions",
"(",
")",
")",
"?",
"$",
"masterCollection",
"->",
"getCollectionID",
"(",
")",
":",
"0",
";",
"$",
"db",
"=",
"Database",
"::",
"connection",
"(",
")",
";",
"$",
"v",
"=",
"array",
"(",
"$",
"this",
"->",
"getAreaHandle",
"(",
")",
",",
"'TEMPLATE'",
",",
"$",
"masterCollection",
"->",
"getCollectionID",
"(",
")",
")",
";",
"$",
"db",
"->",
"executeQuery",
"(",
"'update Areas, Pages set Areas.arInheritPermissionsFromAreaOnCID = '",
".",
"$",
"toSetCID",
".",
"' where Areas.cID = Pages.cID and Areas.arHandle = ? and cInheritPermissionsFrom = ? and arOverrideCollectionPermissions = 0 and cInheritPermissionsFromCID = ?'",
",",
"$",
"v",
")",
";",
"}"
] | similar to rescanSubAreaPermissions, but for those who have setup their pages to inherit master collection permissions.
@see Area::rescanSubAreaPermissions()
@param Page $masterCollection
@return bool | [
"similar",
"to",
"rescanSubAreaPermissions",
"but",
"for",
"those",
"who",
"have",
"setup",
"their",
"pages",
"to",
"inherit",
"master",
"collection",
"permissions",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Area/Area.php#L744-L761 | train |
concrete5/concrete5 | concrete/src/Area/Area.php | Area.export | public function export($p, $page)
{
$area = $p->addChild('area');
$area->addAttribute('name', $this->getAreaHandle());
$blocks = $page->getBlocks($this->getAreaHandle());
$c = $this->getAreaCollectionObject();
$style = $c->getAreaCustomStyle($this);
if (is_object($style)) {
$set = $style->getStyleSet();
$set->export($area);
}
$wrapper = $area->addChild('blocks');
foreach ($blocks as $bl) {
$bl->export($wrapper);
}
} | php | public function export($p, $page)
{
$area = $p->addChild('area');
$area->addAttribute('name', $this->getAreaHandle());
$blocks = $page->getBlocks($this->getAreaHandle());
$c = $this->getAreaCollectionObject();
$style = $c->getAreaCustomStyle($this);
if (is_object($style)) {
$set = $style->getStyleSet();
$set->export($area);
}
$wrapper = $area->addChild('blocks');
foreach ($blocks as $bl) {
$bl->export($wrapper);
}
} | [
"public",
"function",
"export",
"(",
"$",
"p",
",",
"$",
"page",
")",
"{",
"$",
"area",
"=",
"$",
"p",
"->",
"addChild",
"(",
"'area'",
")",
";",
"$",
"area",
"->",
"addAttribute",
"(",
"'name'",
",",
"$",
"this",
"->",
"getAreaHandle",
"(",
")",
")",
";",
"$",
"blocks",
"=",
"$",
"page",
"->",
"getBlocks",
"(",
"$",
"this",
"->",
"getAreaHandle",
"(",
")",
")",
";",
"$",
"c",
"=",
"$",
"this",
"->",
"getAreaCollectionObject",
"(",
")",
";",
"$",
"style",
"=",
"$",
"c",
"->",
"getAreaCustomStyle",
"(",
"$",
"this",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"style",
")",
")",
"{",
"$",
"set",
"=",
"$",
"style",
"->",
"getStyleSet",
"(",
")",
";",
"$",
"set",
"->",
"export",
"(",
"$",
"area",
")",
";",
"}",
"$",
"wrapper",
"=",
"$",
"area",
"->",
"addChild",
"(",
"'blocks'",
")",
";",
"foreach",
"(",
"$",
"blocks",
"as",
"$",
"bl",
")",
"{",
"$",
"bl",
"->",
"export",
"(",
"$",
"wrapper",
")",
";",
"}",
"}"
] | Exports the area to content format.
@param \SimpleXMLElement $p
@param Page $page | [
"Exports",
"the",
"area",
"to",
"content",
"format",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Area/Area.php#L898-L913 | train |
concrete5/concrete5 | concrete/src/Service/Rule/Option.php | Option.isRequired | public function isRequired()
{
$result = $this->required;
if (is_callable($result)) {
$result = $result($this);
}
return (bool) $result;
} | php | public function isRequired()
{
$result = $this->required;
if (is_callable($result)) {
$result = $result($this);
}
return (bool) $result;
} | [
"public",
"function",
"isRequired",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"required",
";",
"if",
"(",
"is_callable",
"(",
"$",
"result",
")",
")",
"{",
"$",
"result",
"=",
"$",
"result",
"(",
"$",
"this",
")",
";",
"}",
"return",
"(",
"bool",
")",
"$",
"result",
";",
"}"
] | Is this option required?
@return bool | [
"Is",
"this",
"option",
"required?"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Service/Rule/Option.php#L59-L67 | train |
concrete5/concrete5 | concrete/src/Foundation/ClassLoader.php | ClassLoader.enableLegacyNamespace | public function enableLegacyNamespace()
{
$this->enableLegacyNamespace = true;
$this->disable();
$this->activateAutoloaders();
$this->enable();
} | php | public function enableLegacyNamespace()
{
$this->enableLegacyNamespace = true;
$this->disable();
$this->activateAutoloaders();
$this->enable();
} | [
"public",
"function",
"enableLegacyNamespace",
"(",
")",
"{",
"$",
"this",
"->",
"enableLegacyNamespace",
"=",
"true",
";",
"$",
"this",
"->",
"disable",
"(",
")",
";",
"$",
"this",
"->",
"activateAutoloaders",
"(",
")",
";",
"$",
"this",
"->",
"enable",
"(",
")",
";",
"}"
] | Set legacy namespaces to enabled. This method unsets and resets this loader. | [
"Set",
"legacy",
"namespaces",
"to",
"enabled",
".",
"This",
"method",
"unsets",
"and",
"resets",
"this",
"loader",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Foundation/ClassLoader.php#L39-L45 | train |
concrete5/concrete5 | concrete/src/Foundation/ClassLoader.php | ClassLoader.disableLegacyNamespace | public function disableLegacyNamespace()
{
$this->enableLegacyNamespace = false;
$this->disable();
$this->activateAutoloaders();
$this->enable();
} | php | public function disableLegacyNamespace()
{
$this->enableLegacyNamespace = false;
$this->disable();
$this->activateAutoloaders();
$this->enable();
} | [
"public",
"function",
"disableLegacyNamespace",
"(",
")",
"{",
"$",
"this",
"->",
"enableLegacyNamespace",
"=",
"false",
";",
"$",
"this",
"->",
"disable",
"(",
")",
";",
"$",
"this",
"->",
"activateAutoloaders",
"(",
")",
";",
"$",
"this",
"->",
"enable",
"(",
")",
";",
"}"
] | Set legacy namespaces to disabled. This method unsets and resets this loader. | [
"Set",
"legacy",
"namespaces",
"to",
"disabled",
".",
"This",
"method",
"unsets",
"and",
"resets",
"this",
"loader",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Foundation/ClassLoader.php#L50-L56 | train |
concrete5/concrete5 | concrete/src/StyleCustomizer/Stylesheet.php | Stylesheet.getCss | public function getCss()
{
$parser = new \Less_Parser(
array(
'cache_dir' => Config::get('concrete.cache.directory'),
'compress' => (bool) Config::get('concrete.theme.compress_preprocessor_output'),
'sourceMap' => !Config::get('concrete.theme.compress_preprocessor_output') && (bool) Config::get('concrete.theme.generate_less_sourcemap'),
)
);
$parser = $parser->parseFile($this->file, $this->sourceUriRoot);
if (isset($this->valueList) && $this->valueList instanceof \Concrete\Core\StyleCustomizer\Style\ValueList) {
$variables = array();
foreach ($this->valueList->getValues() as $value) {
$variables = array_merge($value->toLessVariablesArray(), $variables);
}
$parser->ModifyVars($variables);
}
$css = $parser->getCss();
return $css;
} | php | public function getCss()
{
$parser = new \Less_Parser(
array(
'cache_dir' => Config::get('concrete.cache.directory'),
'compress' => (bool) Config::get('concrete.theme.compress_preprocessor_output'),
'sourceMap' => !Config::get('concrete.theme.compress_preprocessor_output') && (bool) Config::get('concrete.theme.generate_less_sourcemap'),
)
);
$parser = $parser->parseFile($this->file, $this->sourceUriRoot);
if (isset($this->valueList) && $this->valueList instanceof \Concrete\Core\StyleCustomizer\Style\ValueList) {
$variables = array();
foreach ($this->valueList->getValues() as $value) {
$variables = array_merge($value->toLessVariablesArray(), $variables);
}
$parser->ModifyVars($variables);
}
$css = $parser->getCss();
return $css;
} | [
"public",
"function",
"getCss",
"(",
")",
"{",
"$",
"parser",
"=",
"new",
"\\",
"Less_Parser",
"(",
"array",
"(",
"'cache_dir'",
"=>",
"Config",
"::",
"get",
"(",
"'concrete.cache.directory'",
")",
",",
"'compress'",
"=>",
"(",
"bool",
")",
"Config",
"::",
"get",
"(",
"'concrete.theme.compress_preprocessor_output'",
")",
",",
"'sourceMap'",
"=>",
"!",
"Config",
"::",
"get",
"(",
"'concrete.theme.compress_preprocessor_output'",
")",
"&&",
"(",
"bool",
")",
"Config",
"::",
"get",
"(",
"'concrete.theme.generate_less_sourcemap'",
")",
",",
")",
")",
";",
"$",
"parser",
"=",
"$",
"parser",
"->",
"parseFile",
"(",
"$",
"this",
"->",
"file",
",",
"$",
"this",
"->",
"sourceUriRoot",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"valueList",
")",
"&&",
"$",
"this",
"->",
"valueList",
"instanceof",
"\\",
"Concrete",
"\\",
"Core",
"\\",
"StyleCustomizer",
"\\",
"Style",
"\\",
"ValueList",
")",
"{",
"$",
"variables",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"valueList",
"->",
"getValues",
"(",
")",
"as",
"$",
"value",
")",
"{",
"$",
"variables",
"=",
"array_merge",
"(",
"$",
"value",
"->",
"toLessVariablesArray",
"(",
")",
",",
"$",
"variables",
")",
";",
"}",
"$",
"parser",
"->",
"ModifyVars",
"(",
"$",
"variables",
")",
";",
"}",
"$",
"css",
"=",
"$",
"parser",
"->",
"getCss",
"(",
")",
";",
"return",
"$",
"css",
";",
"}"
] | Compiles the stylesheet using LESS. If a ValueList is provided they are
injected into the stylesheet.
@return string CSS | [
"Compiles",
"the",
"stylesheet",
"using",
"LESS",
".",
"If",
"a",
"ValueList",
"is",
"provided",
"they",
"are",
"injected",
"into",
"the",
"stylesheet",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/StyleCustomizer/Stylesheet.php#L35-L55 | train |
concrete5/concrete5 | concrete/src/Localization/Service/Date.php | Date.getGroupedTimezones | public function getGroupedTimezones()
{
$groups = [];
$generics = [];
$genericGroupName = tc('GenericTimezonesGroupName', 'Others');
foreach ($this->getTimezones() as $id => $fullName) {
$chunks = explode('/', $fullName, 2);
if (!isset($chunks[1])) {
array_unshift($chunks, $genericGroupName);
}
list($groupName, $territoryName) = $chunks;
if ($groupName === $genericGroupName) {
$generics[$id] = $territoryName;
} else {
if (!isset($groups[$groupName])) {
$groups[$groupName] = [];
}
$groups[$groupName][$id] = $territoryName;
}
}
if (!empty($generics)) {
$groups[$genericGroupName] = $generics;
}
return $groups;
} | php | public function getGroupedTimezones()
{
$groups = [];
$generics = [];
$genericGroupName = tc('GenericTimezonesGroupName', 'Others');
foreach ($this->getTimezones() as $id => $fullName) {
$chunks = explode('/', $fullName, 2);
if (!isset($chunks[1])) {
array_unshift($chunks, $genericGroupName);
}
list($groupName, $territoryName) = $chunks;
if ($groupName === $genericGroupName) {
$generics[$id] = $territoryName;
} else {
if (!isset($groups[$groupName])) {
$groups[$groupName] = [];
}
$groups[$groupName][$id] = $territoryName;
}
}
if (!empty($generics)) {
$groups[$genericGroupName] = $generics;
}
return $groups;
} | [
"public",
"function",
"getGroupedTimezones",
"(",
")",
"{",
"$",
"groups",
"=",
"[",
"]",
";",
"$",
"generics",
"=",
"[",
"]",
";",
"$",
"genericGroupName",
"=",
"tc",
"(",
"'GenericTimezonesGroupName'",
",",
"'Others'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getTimezones",
"(",
")",
"as",
"$",
"id",
"=>",
"$",
"fullName",
")",
"{",
"$",
"chunks",
"=",
"explode",
"(",
"'/'",
",",
"$",
"fullName",
",",
"2",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"chunks",
"[",
"1",
"]",
")",
")",
"{",
"array_unshift",
"(",
"$",
"chunks",
",",
"$",
"genericGroupName",
")",
";",
"}",
"list",
"(",
"$",
"groupName",
",",
"$",
"territoryName",
")",
"=",
"$",
"chunks",
";",
"if",
"(",
"$",
"groupName",
"===",
"$",
"genericGroupName",
")",
"{",
"$",
"generics",
"[",
"$",
"id",
"]",
"=",
"$",
"territoryName",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"groups",
"[",
"$",
"groupName",
"]",
")",
")",
"{",
"$",
"groups",
"[",
"$",
"groupName",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"groups",
"[",
"$",
"groupName",
"]",
"[",
"$",
"id",
"]",
"=",
"$",
"territoryName",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"generics",
")",
")",
"{",
"$",
"groups",
"[",
"$",
"genericGroupName",
"]",
"=",
"$",
"generics",
";",
"}",
"return",
"$",
"groups",
";",
"}"
] | Returns the list of timezones with translated names, grouped by region.
@return array
@example
<pre>[
'Africa' => [
'Africa/Abidjan' => 'Abidjan',
'Africa/Addis_Ababa' => 'Addis Abeba',
],
'Americas' => [
'America/North_Dakota/Beulah' => 'Beulah, North Dakota',
],
'Antarctica' => [
'Antarctica/McMurdo' => 'McMurdo',
],
'Arctic' => [
...
],
'Asia' => [
....
],
'Atlantic Ocean' => [
....
],
'Australia' => [
....
],
'Europe' => [
....
],
'Indian Ocean' => [
....
],
'Pacific Ocean' => [
....
],
'Others' => [
'UTC' => 'Greenwich Mean Time (UTC)',
],
]</pre>
@see http://www.php.net/datetimezone.listidentifiers.php | [
"Returns",
"the",
"list",
"of",
"timezones",
"with",
"translated",
"names",
"grouped",
"by",
"region",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Service/Date.php#L279-L304 | train |
concrete5/concrete5 | concrete/src/Localization/Service/Date.php | Date.getTimezoneDisplayName | public function getTimezoneDisplayName($timezone)
{
$displayName = '';
if (is_object($timezone)) {
if ($timezone instanceof \DateTimeZone) {
$displayName = $timezone->getName();
} elseif ($timezone instanceof \DateTime) {
$displayName = $timezone->getTimezone()->getName();
}
} elseif (is_string($timezone)) {
$displayName = $timezone;
}
if (strlen($displayName) > 0) {
$timezones = $this->getTimezones();
if (array_key_exists($displayName, $timezones)) {
$displayName = $timezones[$displayName];
}
}
return $displayName;
} | php | public function getTimezoneDisplayName($timezone)
{
$displayName = '';
if (is_object($timezone)) {
if ($timezone instanceof \DateTimeZone) {
$displayName = $timezone->getName();
} elseif ($timezone instanceof \DateTime) {
$displayName = $timezone->getTimezone()->getName();
}
} elseif (is_string($timezone)) {
$displayName = $timezone;
}
if (strlen($displayName) > 0) {
$timezones = $this->getTimezones();
if (array_key_exists($displayName, $timezones)) {
$displayName = $timezones[$displayName];
}
}
return $displayName;
} | [
"public",
"function",
"getTimezoneDisplayName",
"(",
"$",
"timezone",
")",
"{",
"$",
"displayName",
"=",
"''",
";",
"if",
"(",
"is_object",
"(",
"$",
"timezone",
")",
")",
"{",
"if",
"(",
"$",
"timezone",
"instanceof",
"\\",
"DateTimeZone",
")",
"{",
"$",
"displayName",
"=",
"$",
"timezone",
"->",
"getName",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"timezone",
"instanceof",
"\\",
"DateTime",
")",
"{",
"$",
"displayName",
"=",
"$",
"timezone",
"->",
"getTimezone",
"(",
")",
"->",
"getName",
"(",
")",
";",
"}",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"timezone",
")",
")",
"{",
"$",
"displayName",
"=",
"$",
"timezone",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"displayName",
")",
">",
"0",
")",
"{",
"$",
"timezones",
"=",
"$",
"this",
"->",
"getTimezones",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"displayName",
",",
"$",
"timezones",
")",
")",
"{",
"$",
"displayName",
"=",
"$",
"timezones",
"[",
"$",
"displayName",
"]",
";",
"}",
"}",
"return",
"$",
"displayName",
";",
"}"
] | Returns the display name of a timezone.
@param string|\DateTimeZone|\DateTime $timezone The timezone for which you want the localized display name
@return string | [
"Returns",
"the",
"display",
"name",
"of",
"a",
"timezone",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Service/Date.php#L313-L333 | train |
concrete5/concrete5 | concrete/src/Localization/Service/Date.php | Date.describeInterval | public function describeInterval($diff, $precise = false)
{
$secondsPerMinute = 60;
$secondsPerHour = 60 * $secondsPerMinute;
$secondsPerDay = 24 * $secondsPerHour;
$days = floor($diff / $secondsPerDay);
$diff = $diff - $days * $secondsPerDay;
$hours = floor($diff / $secondsPerHour);
$diff = $diff - $hours * $secondsPerHour;
$minutes = floor($diff / $secondsPerMinute);
$seconds = $diff - $minutes * $secondsPerMinute;
$chunks = [];
if ($days > 0) {
$chunks[] = t2('%d day', '%d days', $days, $days);
if ($precise) {
$chunks[] = t2('%d hour', '%d hours', $hours, $hours);
}
} elseif ($hours > 0) {
$chunks[] = t2('%d hour', '%d hours', $hours, $hours);
if ($precise) {
$chunks[] = t2('%d minute', '%d minutes', $minutes, $minutes);
}
} elseif ($minutes > 0) {
$chunks[] = t2('%d minute', '%d minutes', $minutes, $minutes);
if ($precise) {
$chunks[] = t2('%d second', '%d seconds', $seconds, $seconds);
}
} else {
$chunks[] = t2('%d second', '%d seconds', $seconds, $seconds);
}
return Misc::join($chunks);
} | php | public function describeInterval($diff, $precise = false)
{
$secondsPerMinute = 60;
$secondsPerHour = 60 * $secondsPerMinute;
$secondsPerDay = 24 * $secondsPerHour;
$days = floor($diff / $secondsPerDay);
$diff = $diff - $days * $secondsPerDay;
$hours = floor($diff / $secondsPerHour);
$diff = $diff - $hours * $secondsPerHour;
$minutes = floor($diff / $secondsPerMinute);
$seconds = $diff - $minutes * $secondsPerMinute;
$chunks = [];
if ($days > 0) {
$chunks[] = t2('%d day', '%d days', $days, $days);
if ($precise) {
$chunks[] = t2('%d hour', '%d hours', $hours, $hours);
}
} elseif ($hours > 0) {
$chunks[] = t2('%d hour', '%d hours', $hours, $hours);
if ($precise) {
$chunks[] = t2('%d minute', '%d minutes', $minutes, $minutes);
}
} elseif ($minutes > 0) {
$chunks[] = t2('%d minute', '%d minutes', $minutes, $minutes);
if ($precise) {
$chunks[] = t2('%d second', '%d seconds', $seconds, $seconds);
}
} else {
$chunks[] = t2('%d second', '%d seconds', $seconds, $seconds);
}
return Misc::join($chunks);
} | [
"public",
"function",
"describeInterval",
"(",
"$",
"diff",
",",
"$",
"precise",
"=",
"false",
")",
"{",
"$",
"secondsPerMinute",
"=",
"60",
";",
"$",
"secondsPerHour",
"=",
"60",
"*",
"$",
"secondsPerMinute",
";",
"$",
"secondsPerDay",
"=",
"24",
"*",
"$",
"secondsPerHour",
";",
"$",
"days",
"=",
"floor",
"(",
"$",
"diff",
"/",
"$",
"secondsPerDay",
")",
";",
"$",
"diff",
"=",
"$",
"diff",
"-",
"$",
"days",
"*",
"$",
"secondsPerDay",
";",
"$",
"hours",
"=",
"floor",
"(",
"$",
"diff",
"/",
"$",
"secondsPerHour",
")",
";",
"$",
"diff",
"=",
"$",
"diff",
"-",
"$",
"hours",
"*",
"$",
"secondsPerHour",
";",
"$",
"minutes",
"=",
"floor",
"(",
"$",
"diff",
"/",
"$",
"secondsPerMinute",
")",
";",
"$",
"seconds",
"=",
"$",
"diff",
"-",
"$",
"minutes",
"*",
"$",
"secondsPerMinute",
";",
"$",
"chunks",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"days",
">",
"0",
")",
"{",
"$",
"chunks",
"[",
"]",
"=",
"t2",
"(",
"'%d day'",
",",
"'%d days'",
",",
"$",
"days",
",",
"$",
"days",
")",
";",
"if",
"(",
"$",
"precise",
")",
"{",
"$",
"chunks",
"[",
"]",
"=",
"t2",
"(",
"'%d hour'",
",",
"'%d hours'",
",",
"$",
"hours",
",",
"$",
"hours",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"hours",
">",
"0",
")",
"{",
"$",
"chunks",
"[",
"]",
"=",
"t2",
"(",
"'%d hour'",
",",
"'%d hours'",
",",
"$",
"hours",
",",
"$",
"hours",
")",
";",
"if",
"(",
"$",
"precise",
")",
"{",
"$",
"chunks",
"[",
"]",
"=",
"t2",
"(",
"'%d minute'",
",",
"'%d minutes'",
",",
"$",
"minutes",
",",
"$",
"minutes",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"minutes",
">",
"0",
")",
"{",
"$",
"chunks",
"[",
"]",
"=",
"t2",
"(",
"'%d minute'",
",",
"'%d minutes'",
",",
"$",
"minutes",
",",
"$",
"minutes",
")",
";",
"if",
"(",
"$",
"precise",
")",
"{",
"$",
"chunks",
"[",
"]",
"=",
"t2",
"(",
"'%d second'",
",",
"'%d seconds'",
",",
"$",
"seconds",
",",
"$",
"seconds",
")",
";",
"}",
"}",
"else",
"{",
"$",
"chunks",
"[",
"]",
"=",
"t2",
"(",
"'%d second'",
",",
"'%d seconds'",
",",
"$",
"seconds",
",",
"$",
"seconds",
")",
";",
"}",
"return",
"Misc",
"::",
"join",
"(",
"$",
"chunks",
")",
";",
"}"
] | Returns the localized representation of a time interval specified as seconds.
@param int $diff The time difference in seconds
@param bool $precise = false Set to true to a more verbose and precise result, false for a more rounded result
@return string | [
"Returns",
"the",
"localized",
"representation",
"of",
"a",
"time",
"interval",
"specified",
"as",
"seconds",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Service/Date.php#L364-L396 | train |
concrete5/concrete5 | concrete/src/Localization/Service/Date.php | Date.getTimezoneID | public function getTimezoneID($timezone)
{
$app = Facade::getFacadeApplication();
/** @var Repository $config */
$config = $app->make('config');
switch ($timezone) {
case 'system':
$timezone = $config->get('app.server_timezone', @date_default_timezone_get() ?: 'UTC');
break;
case 'app':
/** @var Site $site */
$site = $app->make('site')->getSite();
$timezone = $site->getConfigRepository()->get('timezone', @date_default_timezone_get() ?: 'UTC');
break;
case 'user':
$tz = null;
if ($config->get('concrete.misc.user_timezones')) {
$u = null;
$request = null;
if (!$app->isRunThroughCommandLineInterface()) {
$request = Request::getInstance();
}
if ($request && $request->hasCustomRequestUser()) {
$u = $request->getCustomRequestUser();
} else {
$u = new User();
}
if (is_object($u) && $u->isRegistered()) {
$tz = $u->getUserTimezone();
}
}
if ($tz) {
$timezone = $tz;
} else {
$timezone = $this->getTimezoneID('app');
}
break;
}
return $timezone;
} | php | public function getTimezoneID($timezone)
{
$app = Facade::getFacadeApplication();
/** @var Repository $config */
$config = $app->make('config');
switch ($timezone) {
case 'system':
$timezone = $config->get('app.server_timezone', @date_default_timezone_get() ?: 'UTC');
break;
case 'app':
/** @var Site $site */
$site = $app->make('site')->getSite();
$timezone = $site->getConfigRepository()->get('timezone', @date_default_timezone_get() ?: 'UTC');
break;
case 'user':
$tz = null;
if ($config->get('concrete.misc.user_timezones')) {
$u = null;
$request = null;
if (!$app->isRunThroughCommandLineInterface()) {
$request = Request::getInstance();
}
if ($request && $request->hasCustomRequestUser()) {
$u = $request->getCustomRequestUser();
} else {
$u = new User();
}
if (is_object($u) && $u->isRegistered()) {
$tz = $u->getUserTimezone();
}
}
if ($tz) {
$timezone = $tz;
} else {
$timezone = $this->getTimezoneID('app');
}
break;
}
return $timezone;
} | [
"public",
"function",
"getTimezoneID",
"(",
"$",
"timezone",
")",
"{",
"$",
"app",
"=",
"Facade",
"::",
"getFacadeApplication",
"(",
")",
";",
"/** @var Repository $config */",
"$",
"config",
"=",
"$",
"app",
"->",
"make",
"(",
"'config'",
")",
";",
"switch",
"(",
"$",
"timezone",
")",
"{",
"case",
"'system'",
":",
"$",
"timezone",
"=",
"$",
"config",
"->",
"get",
"(",
"'app.server_timezone'",
",",
"@",
"date_default_timezone_get",
"(",
")",
"?",
":",
"'UTC'",
")",
";",
"break",
";",
"case",
"'app'",
":",
"/** @var Site $site */",
"$",
"site",
"=",
"$",
"app",
"->",
"make",
"(",
"'site'",
")",
"->",
"getSite",
"(",
")",
";",
"$",
"timezone",
"=",
"$",
"site",
"->",
"getConfigRepository",
"(",
")",
"->",
"get",
"(",
"'timezone'",
",",
"@",
"date_default_timezone_get",
"(",
")",
"?",
":",
"'UTC'",
")",
";",
"break",
";",
"case",
"'user'",
":",
"$",
"tz",
"=",
"null",
";",
"if",
"(",
"$",
"config",
"->",
"get",
"(",
"'concrete.misc.user_timezones'",
")",
")",
"{",
"$",
"u",
"=",
"null",
";",
"$",
"request",
"=",
"null",
";",
"if",
"(",
"!",
"$",
"app",
"->",
"isRunThroughCommandLineInterface",
"(",
")",
")",
"{",
"$",
"request",
"=",
"Request",
"::",
"getInstance",
"(",
")",
";",
"}",
"if",
"(",
"$",
"request",
"&&",
"$",
"request",
"->",
"hasCustomRequestUser",
"(",
")",
")",
"{",
"$",
"u",
"=",
"$",
"request",
"->",
"getCustomRequestUser",
"(",
")",
";",
"}",
"else",
"{",
"$",
"u",
"=",
"new",
"User",
"(",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"u",
")",
"&&",
"$",
"u",
"->",
"isRegistered",
"(",
")",
")",
"{",
"$",
"tz",
"=",
"$",
"u",
"->",
"getUserTimezone",
"(",
")",
";",
"}",
"}",
"if",
"(",
"$",
"tz",
")",
"{",
"$",
"timezone",
"=",
"$",
"tz",
";",
"}",
"else",
"{",
"$",
"timezone",
"=",
"$",
"this",
"->",
"getTimezoneID",
"(",
"'app'",
")",
";",
"}",
"break",
";",
"}",
"return",
"$",
"timezone",
";",
"}"
] | Returns the normalized timezone identifier.
@param string $timezone The timezone to retrieve. Special values are:<ul>
<li>'system' (default) for the current system timezone</li>
<li>'user' for the user's timezone</li>
<li>'app' for the app's timezone</li>
<li>Other values: one of the PHP supported time zones (see http://us1.php.net/manual/en/timezones.php )</li>
</ul>
@return string | [
"Returns",
"the",
"normalized",
"timezone",
"identifier",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Service/Date.php#L410-L451 | train |
concrete5/concrete5 | concrete/src/Localization/Service/Date.php | Date.getTimezone | public function getTimezone($timezone)
{
$tz = null;
$phpTimezone = $this->getTimezoneID($timezone);
if (is_string($phpTimezone) && strlen($phpTimezone)) {
try {
$tz = new \DateTimeZone($phpTimezone);
} catch (\Exception $x) {
}
}
return $tz;
} | php | public function getTimezone($timezone)
{
$tz = null;
$phpTimezone = $this->getTimezoneID($timezone);
if (is_string($phpTimezone) && strlen($phpTimezone)) {
try {
$tz = new \DateTimeZone($phpTimezone);
} catch (\Exception $x) {
}
}
return $tz;
} | [
"public",
"function",
"getTimezone",
"(",
"$",
"timezone",
")",
"{",
"$",
"tz",
"=",
"null",
";",
"$",
"phpTimezone",
"=",
"$",
"this",
"->",
"getTimezoneID",
"(",
"$",
"timezone",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"phpTimezone",
")",
"&&",
"strlen",
"(",
"$",
"phpTimezone",
")",
")",
"{",
"try",
"{",
"$",
"tz",
"=",
"new",
"\\",
"DateTimeZone",
"(",
"$",
"phpTimezone",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"x",
")",
"{",
"}",
"}",
"return",
"$",
"tz",
";",
"}"
] | Returns a \DateTimeZone instance for a specified timezone identifier.
@param string $timezone The timezone to retrieve. Special values are:<ul>
<li>'system' (default) for the current system timezone</li>
<li>'user' for the user's timezone</li>
<li>'app' for the app's timezone</li>
<li>Other values: one of the PHP supported time zones (see http://us1.php.net/manual/en/timezones.php )</li>
</ul>
@return \DateTimeZone|null Returns null if $timezone is invalid or the \DateTimeZone corresponding to $timezone | [
"Returns",
"a",
"\\",
"DateTimeZone",
"instance",
"for",
"a",
"specified",
"timezone",
"identifier",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Service/Date.php#L473-L485 | train |
concrete5/concrete5 | concrete/src/Localization/Service/Date.php | Date.toDateTime | public function toDateTime($value = 'now', $toTimezone = 'system', $fromTimezone = 'system')
{
return Calendar::toDateTime($value, $this->getTimezone($toTimezone), $this->getTimezone($fromTimezone));
} | php | public function toDateTime($value = 'now', $toTimezone = 'system', $fromTimezone = 'system')
{
return Calendar::toDateTime($value, $this->getTimezone($toTimezone), $this->getTimezone($fromTimezone));
} | [
"public",
"function",
"toDateTime",
"(",
"$",
"value",
"=",
"'now'",
",",
"$",
"toTimezone",
"=",
"'system'",
",",
"$",
"fromTimezone",
"=",
"'system'",
")",
"{",
"return",
"Calendar",
"::",
"toDateTime",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"getTimezone",
"(",
"$",
"toTimezone",
")",
",",
"$",
"this",
"->",
"getTimezone",
"(",
"$",
"fromTimezone",
")",
")",
";",
"}"
] | Convert a date to a \DateTime instance.
@param string|\DateTime|int $value It can be:<ul>
<li>the special value 'now' (default) to return the current date/time</li>
<li>a \DateTime instance</li>
<li>a string parsable by strtotime (the $fromTimezone timezone is used)</li>
<li>a timestamp</li>
</ul>
@param string $toTimezone The timezone to set. Special values are:<ul>
<li>'system' (default) for the current system timezone</li>
<li>'user' for the user's timezone</li>
<li>'app' for the app's timezone</li>
<li>Other values: one of the PHP supported time zones (see http://us1.php.net/manual/en/timezones.php )</li>
</ul>
@param string $fromTimezone The original timezone of $value (useful only if $value is a string like '2000-12-31 23:59'); it accepts the same values as $toTimezone
@return \DateTime|null Returns the \DateTime instance (or null if $value couldn't be parsed)
@throws \Punic\Exception\BadArgumentType | [
"Convert",
"a",
"date",
"to",
"a",
"\\",
"DateTime",
"instance",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Service/Date.php#L508-L511 | train |
concrete5/concrete5 | concrete/src/Localization/Service/Date.php | Date.getDeltaDays | public function getDeltaDays($from, $to, $timezone = 'user')
{
$dtFrom = $this->toDateTime($from, $timezone);
$dtTo = $this->toDateTime($to, $timezone);
if (is_null($dtFrom) || is_null($dtTo)) {
return null;
}
// Re-create DateTime objects without time
$dtFrom = $this->toDateTime($dtFrom->format('Y-m-d'), $timezone);
$dtTo = $this->toDateTime($dtTo->format('Y-m-d'), $timezone);
return (int) $dtFrom->diff($dtTo)->format('%r%a');
} | php | public function getDeltaDays($from, $to, $timezone = 'user')
{
$dtFrom = $this->toDateTime($from, $timezone);
$dtTo = $this->toDateTime($to, $timezone);
if (is_null($dtFrom) || is_null($dtTo)) {
return null;
}
// Re-create DateTime objects without time
$dtFrom = $this->toDateTime($dtFrom->format('Y-m-d'), $timezone);
$dtTo = $this->toDateTime($dtTo->format('Y-m-d'), $timezone);
return (int) $dtFrom->diff($dtTo)->format('%r%a');
} | [
"public",
"function",
"getDeltaDays",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"timezone",
"=",
"'user'",
")",
"{",
"$",
"dtFrom",
"=",
"$",
"this",
"->",
"toDateTime",
"(",
"$",
"from",
",",
"$",
"timezone",
")",
";",
"$",
"dtTo",
"=",
"$",
"this",
"->",
"toDateTime",
"(",
"$",
"to",
",",
"$",
"timezone",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"dtFrom",
")",
"||",
"is_null",
"(",
"$",
"dtTo",
")",
")",
"{",
"return",
"null",
";",
"}",
"// Re-create DateTime objects without time",
"$",
"dtFrom",
"=",
"$",
"this",
"->",
"toDateTime",
"(",
"$",
"dtFrom",
"->",
"format",
"(",
"'Y-m-d'",
")",
",",
"$",
"timezone",
")",
";",
"$",
"dtTo",
"=",
"$",
"this",
"->",
"toDateTime",
"(",
"$",
"dtTo",
"->",
"format",
"(",
"'Y-m-d'",
")",
",",
"$",
"timezone",
")",
";",
"return",
"(",
"int",
")",
"$",
"dtFrom",
"->",
"diff",
"(",
"$",
"dtTo",
")",
"->",
"format",
"(",
"'%r%a'",
")",
";",
"}"
] | Returns the difference in days between to dates.
@param mixed $from The start date/time representation (one of the values accepted by toDateTime)
@param mixed $to The end date/time representation (one of the values accepted by toDateTime)
@param string $timezone The timezone to set. Special values are:<ul>
<li>'system' for the current system timezone</li>
<li>'user' (default) for the user's timezone</li>
<li>'app' for the app's timezone</li>
<li>Other values: one of the PHP supported time zones (see http://us1.php.net/manual/en/timezones.php )</li>
</ul>
@return int|null Returns the difference in days (less than zero if $dateFrom if greater than $dateTo).
Returns null if one of both the dates can't be parsed
@throws \Punic\Exception\BadArgumentType | [
"Returns",
"the",
"difference",
"in",
"days",
"between",
"to",
"dates",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Service/Date.php#L530-L543 | train |
concrete5/concrete5 | concrete/src/Localization/Service/Date.php | Date.getPHPTimePattern | public function getPHPTimePattern()
{
$isoFormat = Calendar::getTimeFormat('short');
$result = Calendar::tryConvertIsoToPhpFormat($isoFormat);
if ($result === null) {
$result = t(/*i18n: Short time format: see http://www.php.net/manual/en/function.date.php */ 'g.i A');
}
return $result;
} | php | public function getPHPTimePattern()
{
$isoFormat = Calendar::getTimeFormat('short');
$result = Calendar::tryConvertIsoToPhpFormat($isoFormat);
if ($result === null) {
$result = t(/*i18n: Short time format: see http://www.php.net/manual/en/function.date.php */ 'g.i A');
}
return $result;
} | [
"public",
"function",
"getPHPTimePattern",
"(",
")",
"{",
"$",
"isoFormat",
"=",
"Calendar",
"::",
"getTimeFormat",
"(",
"'short'",
")",
";",
"$",
"result",
"=",
"Calendar",
"::",
"tryConvertIsoToPhpFormat",
"(",
"$",
"isoFormat",
")",
";",
"if",
"(",
"$",
"result",
"===",
"null",
")",
"{",
"$",
"result",
"=",
"t",
"(",
"/*i18n: Short time format: see http://www.php.net/manual/en/function.date.php */",
"'g.i A'",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get the PHP date format string for times.
@return string
@throws \Punic\Exception | [
"Get",
"the",
"PHP",
"date",
"format",
"string",
"for",
"times",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Service/Date.php#L845-L854 | train |
concrete5/concrete5 | concrete/src/Database/CharacterSetCollation/Manager.php | Manager.apply | public function apply($characterSet, $collation, $connectionName = '', $environment = '', callable $messageCallback = null, ErrorList $warnings = null)
{
if ($messageCallback === null) {
$messageCallback = function ($message) { };
}
if ((string) $connectionName === '') {
$connectionName = $this->databaseManager->getDefaultConnection();
}
$connection = $this->databaseManager->connection($connectionName);
list($characterSet, $collation) = $this->resolver
->setCharacterSet((string) $characterSet)
->setCollation((string) $collation)
->resolveCharacterSetAndCollation($connection)
;
$messageCallback(t('Setting character set "%1$s" and collation "%2$s" for connection "%3$s"', $characterSet, $collation, $connectionName));
$this->convertTables($connection, $characterSet, $collation, $messageCallback, $warnings);
$messageCallback(t('Saving connection configuration.'));
$this->persistConfiguration($connectionName, $environment, $characterSet, $collation, $warnings);
$connection->refreshCharactersetCollation($characterSet, $collation);
} | php | public function apply($characterSet, $collation, $connectionName = '', $environment = '', callable $messageCallback = null, ErrorList $warnings = null)
{
if ($messageCallback === null) {
$messageCallback = function ($message) { };
}
if ((string) $connectionName === '') {
$connectionName = $this->databaseManager->getDefaultConnection();
}
$connection = $this->databaseManager->connection($connectionName);
list($characterSet, $collation) = $this->resolver
->setCharacterSet((string) $characterSet)
->setCollation((string) $collation)
->resolveCharacterSetAndCollation($connection)
;
$messageCallback(t('Setting character set "%1$s" and collation "%2$s" for connection "%3$s"', $characterSet, $collation, $connectionName));
$this->convertTables($connection, $characterSet, $collation, $messageCallback, $warnings);
$messageCallback(t('Saving connection configuration.'));
$this->persistConfiguration($connectionName, $environment, $characterSet, $collation, $warnings);
$connection->refreshCharactersetCollation($characterSet, $collation);
} | [
"public",
"function",
"apply",
"(",
"$",
"characterSet",
",",
"$",
"collation",
",",
"$",
"connectionName",
"=",
"''",
",",
"$",
"environment",
"=",
"''",
",",
"callable",
"$",
"messageCallback",
"=",
"null",
",",
"ErrorList",
"$",
"warnings",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"messageCallback",
"===",
"null",
")",
"{",
"$",
"messageCallback",
"=",
"function",
"(",
"$",
"message",
")",
"{",
"}",
";",
"}",
"if",
"(",
"(",
"string",
")",
"$",
"connectionName",
"===",
"''",
")",
"{",
"$",
"connectionName",
"=",
"$",
"this",
"->",
"databaseManager",
"->",
"getDefaultConnection",
"(",
")",
";",
"}",
"$",
"connection",
"=",
"$",
"this",
"->",
"databaseManager",
"->",
"connection",
"(",
"$",
"connectionName",
")",
";",
"list",
"(",
"$",
"characterSet",
",",
"$",
"collation",
")",
"=",
"$",
"this",
"->",
"resolver",
"->",
"setCharacterSet",
"(",
"(",
"string",
")",
"$",
"characterSet",
")",
"->",
"setCollation",
"(",
"(",
"string",
")",
"$",
"collation",
")",
"->",
"resolveCharacterSetAndCollation",
"(",
"$",
"connection",
")",
";",
"$",
"messageCallback",
"(",
"t",
"(",
"'Setting character set \"%1$s\" and collation \"%2$s\" for connection \"%3$s\"'",
",",
"$",
"characterSet",
",",
"$",
"collation",
",",
"$",
"connectionName",
")",
")",
";",
"$",
"this",
"->",
"convertTables",
"(",
"$",
"connection",
",",
"$",
"characterSet",
",",
"$",
"collation",
",",
"$",
"messageCallback",
",",
"$",
"warnings",
")",
";",
"$",
"messageCallback",
"(",
"t",
"(",
"'Saving connection configuration.'",
")",
")",
";",
"$",
"this",
"->",
"persistConfiguration",
"(",
"$",
"connectionName",
",",
"$",
"environment",
",",
"$",
"characterSet",
",",
"$",
"collation",
",",
"$",
"warnings",
")",
";",
"$",
"connection",
"->",
"refreshCharactersetCollation",
"(",
"$",
"characterSet",
",",
"$",
"collation",
")",
";",
"}"
] | Apply the character set and collation to a connection.
@param string $characterSet the character set to be applied (if empty, we'll derive it from the collation)
@param string $collation the collation to be applied (if empty, we'll use the character set default one)
@param string $connectionName the name of the connection (if empty, we'll use the default connection)
@param string $environment
@param callable|null $messageCallback a callback function that will receive progress messages
@param \Concrete\Core\Error\ErrorList\ErrorList|null $warnings if specified, conversion errors will be added to this ErrorList
@throws \Exception | [
"Apply",
"the",
"character",
"set",
"and",
"collation",
"to",
"a",
"connection",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Database/CharacterSetCollation/Manager.php#L58-L77 | train |
concrete5/concrete5 | concrete/src/Calendar/Event/EventService.php | EventService.generateDefaultOccurrences | public function generateDefaultOccurrences(CalendarEventVersion $version)
{
$repetitions = $version->getRepetitionEntityCollection();
$query = $this->entityManager->createQuery('delete from calendar:CalendarEventVersionOccurrence o where o.version = :version');
$query->setParameter('version', $version);
$query->execute();
foreach($repetitions as $repetitionEntity) {
$repetition = $repetitionEntity->getRepetitionObject();
$start = $repetition->getStartDateTimestamp() - 1;
$datetime = new \DateTime('+5 years', $repetition->getTimezone());
$end = $datetime->getTimestamp();
$this->occurrenceFactory->generateOccurrences($version, $repetitionEntity, $start, $end);
}
} | php | public function generateDefaultOccurrences(CalendarEventVersion $version)
{
$repetitions = $version->getRepetitionEntityCollection();
$query = $this->entityManager->createQuery('delete from calendar:CalendarEventVersionOccurrence o where o.version = :version');
$query->setParameter('version', $version);
$query->execute();
foreach($repetitions as $repetitionEntity) {
$repetition = $repetitionEntity->getRepetitionObject();
$start = $repetition->getStartDateTimestamp() - 1;
$datetime = new \DateTime('+5 years', $repetition->getTimezone());
$end = $datetime->getTimestamp();
$this->occurrenceFactory->generateOccurrences($version, $repetitionEntity, $start, $end);
}
} | [
"public",
"function",
"generateDefaultOccurrences",
"(",
"CalendarEventVersion",
"$",
"version",
")",
"{",
"$",
"repetitions",
"=",
"$",
"version",
"->",
"getRepetitionEntityCollection",
"(",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"entityManager",
"->",
"createQuery",
"(",
"'delete from calendar:CalendarEventVersionOccurrence o where o.version = :version'",
")",
";",
"$",
"query",
"->",
"setParameter",
"(",
"'version'",
",",
"$",
"version",
")",
";",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"foreach",
"(",
"$",
"repetitions",
"as",
"$",
"repetitionEntity",
")",
"{",
"$",
"repetition",
"=",
"$",
"repetitionEntity",
"->",
"getRepetitionObject",
"(",
")",
";",
"$",
"start",
"=",
"$",
"repetition",
"->",
"getStartDateTimestamp",
"(",
")",
"-",
"1",
";",
"$",
"datetime",
"=",
"new",
"\\",
"DateTime",
"(",
"'+5 years'",
",",
"$",
"repetition",
"->",
"getTimezone",
"(",
")",
")",
";",
"$",
"end",
"=",
"$",
"datetime",
"->",
"getTimestamp",
"(",
")",
";",
"$",
"this",
"->",
"occurrenceFactory",
"->",
"generateOccurrences",
"(",
"$",
"version",
",",
"$",
"repetitionEntity",
",",
"$",
"start",
",",
"$",
"end",
")",
";",
"}",
"}"
] | Handles generating occurrences with the default start and end times | [
"Handles",
"generating",
"occurrences",
"with",
"the",
"default",
"start",
"and",
"end",
"times"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Calendar/Event/EventService.php#L251-L269 | train |
concrete5/concrete5 | concrete/src/Calendar/Event/EventService.php | EventService.requireOccurrenceRegeneration | public function requireOccurrenceRegeneration($repetitions1, $repetitions2)
{
if (count($repetitions1) != count($repetitions2)) {
return true;
}
$comparator = new Comparator();
for ($i = 0; $i < count($repetitions1); $i++) {
if (!$comparator->areEqual($repetitions1[$i]->getRepetitionObject(), $repetitions2[$i]->getRepetitionObject())) {
return true;
}
}
return false;
} | php | public function requireOccurrenceRegeneration($repetitions1, $repetitions2)
{
if (count($repetitions1) != count($repetitions2)) {
return true;
}
$comparator = new Comparator();
for ($i = 0; $i < count($repetitions1); $i++) {
if (!$comparator->areEqual($repetitions1[$i]->getRepetitionObject(), $repetitions2[$i]->getRepetitionObject())) {
return true;
}
}
return false;
} | [
"public",
"function",
"requireOccurrenceRegeneration",
"(",
"$",
"repetitions1",
",",
"$",
"repetitions2",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"repetitions1",
")",
"!=",
"count",
"(",
"$",
"repetitions2",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"comparator",
"=",
"new",
"Comparator",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"repetitions1",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"$",
"comparator",
"->",
"areEqual",
"(",
"$",
"repetitions1",
"[",
"$",
"i",
"]",
"->",
"getRepetitionObject",
"(",
")",
",",
"$",
"repetitions2",
"[",
"$",
"i",
"]",
"->",
"getRepetitionObject",
"(",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Returns true if the difference between the event versions impacts repetitions and occurrences. | [
"Returns",
"true",
"if",
"the",
"difference",
"between",
"the",
"event",
"versions",
"impacts",
"repetitions",
"and",
"occurrences",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Calendar/Event/EventService.php#L274-L289 | train |
concrete5/concrete5 | concrete/src/Cache/Cache.php | Cache.loadConfig | protected function loadConfig($level)
{
$app = Application::getFacadeApplication();
$drivers = [];
$driverConfigs = $app['config']->get("concrete.cache.levels.{$level}.drivers", []);
$preferredDriverName = $app['config']->get("concrete.cache.levels.{$level}.preferred_driver", null);
// Load the preferred driver(s) first
if (!empty($preferredDriverName)) {
if (is_array($preferredDriverName)) {
foreach ($preferredDriverName as $driverName) {
$preferredDriver = array_get($driverConfigs, $driverName, []);
$drivers[] = $this->buildDriver($preferredDriver);
}
} else {
$preferredDriver = array_get($driverConfigs, $preferredDriverName, []);
$drivers[] = $this->buildDriver($preferredDriver);
}
}
// If we dont have any perferred drivers or preferred drivers available
// Build Everything
if (empty($drivers)) {
foreach ($driverConfigs as $driverConfig) {
if (!$driverConfig) {
continue;
}
$drivers[] = $this->buildDriver($driverConfig);
}
}
// Remove any empty arrays for an accurate count
array_filter($drivers);
$count = count($drivers);
if ($count > 1) {
$driver = new Composite(['drivers' => $drivers]);
} elseif ($count === 1) {
reset($drivers);
$driver = current($drivers);
} else {
$driver = new BlackHole();
}
return $driver;
} | php | protected function loadConfig($level)
{
$app = Application::getFacadeApplication();
$drivers = [];
$driverConfigs = $app['config']->get("concrete.cache.levels.{$level}.drivers", []);
$preferredDriverName = $app['config']->get("concrete.cache.levels.{$level}.preferred_driver", null);
// Load the preferred driver(s) first
if (!empty($preferredDriverName)) {
if (is_array($preferredDriverName)) {
foreach ($preferredDriverName as $driverName) {
$preferredDriver = array_get($driverConfigs, $driverName, []);
$drivers[] = $this->buildDriver($preferredDriver);
}
} else {
$preferredDriver = array_get($driverConfigs, $preferredDriverName, []);
$drivers[] = $this->buildDriver($preferredDriver);
}
}
// If we dont have any perferred drivers or preferred drivers available
// Build Everything
if (empty($drivers)) {
foreach ($driverConfigs as $driverConfig) {
if (!$driverConfig) {
continue;
}
$drivers[] = $this->buildDriver($driverConfig);
}
}
// Remove any empty arrays for an accurate count
array_filter($drivers);
$count = count($drivers);
if ($count > 1) {
$driver = new Composite(['drivers' => $drivers]);
} elseif ($count === 1) {
reset($drivers);
$driver = current($drivers);
} else {
$driver = new BlackHole();
}
return $driver;
} | [
"protected",
"function",
"loadConfig",
"(",
"$",
"level",
")",
"{",
"$",
"app",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"drivers",
"=",
"[",
"]",
";",
"$",
"driverConfigs",
"=",
"$",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"\"concrete.cache.levels.{$level}.drivers\"",
",",
"[",
"]",
")",
";",
"$",
"preferredDriverName",
"=",
"$",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"\"concrete.cache.levels.{$level}.preferred_driver\"",
",",
"null",
")",
";",
"// Load the preferred driver(s) first",
"if",
"(",
"!",
"empty",
"(",
"$",
"preferredDriverName",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"preferredDriverName",
")",
")",
"{",
"foreach",
"(",
"$",
"preferredDriverName",
"as",
"$",
"driverName",
")",
"{",
"$",
"preferredDriver",
"=",
"array_get",
"(",
"$",
"driverConfigs",
",",
"$",
"driverName",
",",
"[",
"]",
")",
";",
"$",
"drivers",
"[",
"]",
"=",
"$",
"this",
"->",
"buildDriver",
"(",
"$",
"preferredDriver",
")",
";",
"}",
"}",
"else",
"{",
"$",
"preferredDriver",
"=",
"array_get",
"(",
"$",
"driverConfigs",
",",
"$",
"preferredDriverName",
",",
"[",
"]",
")",
";",
"$",
"drivers",
"[",
"]",
"=",
"$",
"this",
"->",
"buildDriver",
"(",
"$",
"preferredDriver",
")",
";",
"}",
"}",
"// If we dont have any perferred drivers or preferred drivers available",
"// Build Everything",
"if",
"(",
"empty",
"(",
"$",
"drivers",
")",
")",
"{",
"foreach",
"(",
"$",
"driverConfigs",
"as",
"$",
"driverConfig",
")",
"{",
"if",
"(",
"!",
"$",
"driverConfig",
")",
"{",
"continue",
";",
"}",
"$",
"drivers",
"[",
"]",
"=",
"$",
"this",
"->",
"buildDriver",
"(",
"$",
"driverConfig",
")",
";",
"}",
"}",
"// Remove any empty arrays for an accurate count",
"array_filter",
"(",
"$",
"drivers",
")",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"drivers",
")",
";",
"if",
"(",
"$",
"count",
">",
"1",
")",
"{",
"$",
"driver",
"=",
"new",
"Composite",
"(",
"[",
"'drivers'",
"=>",
"$",
"drivers",
"]",
")",
";",
"}",
"elseif",
"(",
"$",
"count",
"===",
"1",
")",
"{",
"reset",
"(",
"$",
"drivers",
")",
";",
"$",
"driver",
"=",
"current",
"(",
"$",
"drivers",
")",
";",
"}",
"else",
"{",
"$",
"driver",
"=",
"new",
"BlackHole",
"(",
")",
";",
"}",
"return",
"$",
"driver",
";",
"}"
] | Loads the composite driver from constants.
@param $level
@return \Stash\Interfaces\DriverInterface | [
"Loads",
"the",
"composite",
"driver",
"from",
"constants",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Cache/Cache.php#L47-L91 | train |
concrete5/concrete5 | concrete/src/Cache/Cache.php | Cache.buildDriver | private function buildDriver(array $driverConfig)
{
$class = array_get($driverConfig, 'class', '');
if ($class && class_exists($class)) {
$implements = class_implements($class);
// Make sure that the provided class implements the DriverInterface
if (isset($implements['Stash\Interfaces\DriverInterface'])) {
/* @var \Stash\Interfaces\DriverInterface $tempDriver */
// Only add if the driver is available
if ($class::isAvailable()) {
$tempDriver = new $class(array_get($driverConfig, 'options', null));
return $tempDriver;
}
} else {
throw new \RuntimeException('Cache driver class must implement \Stash\Interfaces\DriverInterface.');
}
}
return null;
} | php | private function buildDriver(array $driverConfig)
{
$class = array_get($driverConfig, 'class', '');
if ($class && class_exists($class)) {
$implements = class_implements($class);
// Make sure that the provided class implements the DriverInterface
if (isset($implements['Stash\Interfaces\DriverInterface'])) {
/* @var \Stash\Interfaces\DriverInterface $tempDriver */
// Only add if the driver is available
if ($class::isAvailable()) {
$tempDriver = new $class(array_get($driverConfig, 'options', null));
return $tempDriver;
}
} else {
throw new \RuntimeException('Cache driver class must implement \Stash\Interfaces\DriverInterface.');
}
}
return null;
} | [
"private",
"function",
"buildDriver",
"(",
"array",
"$",
"driverConfig",
")",
"{",
"$",
"class",
"=",
"array_get",
"(",
"$",
"driverConfig",
",",
"'class'",
",",
"''",
")",
";",
"if",
"(",
"$",
"class",
"&&",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"implements",
"=",
"class_implements",
"(",
"$",
"class",
")",
";",
"// Make sure that the provided class implements the DriverInterface",
"if",
"(",
"isset",
"(",
"$",
"implements",
"[",
"'Stash\\Interfaces\\DriverInterface'",
"]",
")",
")",
"{",
"/* @var \\Stash\\Interfaces\\DriverInterface $tempDriver */",
"// Only add if the driver is available",
"if",
"(",
"$",
"class",
"::",
"isAvailable",
"(",
")",
")",
"{",
"$",
"tempDriver",
"=",
"new",
"$",
"class",
"(",
"array_get",
"(",
"$",
"driverConfig",
",",
"'options'",
",",
"null",
")",
")",
";",
"return",
"$",
"tempDriver",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Cache driver class must implement \\Stash\\Interfaces\\DriverInterface.'",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Function used to build a driver from a driverConfig array.
@param array $driverConfig The config item belonging to the driver
@return null|\Stash\Interfaces\DriverInterface | [
"Function",
"used",
"to",
"build",
"a",
"driver",
"from",
"a",
"driverConfig",
"array",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Cache/Cache.php#L100-L122 | train |
concrete5/concrete5 | concrete/src/Cache/Cache.php | Cache.exists | public function exists($key)
{
if ($this->enabled) {
return !$this->pool->getItem($key)->isMiss();
} else {
return false;
}
} | php | public function exists($key)
{
if ($this->enabled) {
return !$this->pool->getItem($key)->isMiss();
} else {
return false;
}
} | [
"public",
"function",
"exists",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"enabled",
")",
"{",
"return",
"!",
"$",
"this",
"->",
"pool",
"->",
"getItem",
"(",
"$",
"key",
")",
"->",
"isMiss",
"(",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Checks if an item exists in the cache.
@param string $key Name of the cache item ID
@return bool True if exists, false if not | [
"Checks",
"if",
"an",
"item",
"exists",
"in",
"the",
"cache",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Cache/Cache.php#L147-L154 | train |
concrete5/concrete5 | concrete/src/Cache/Cache.php | Cache.enable | public function enable()
{
if ($this->driver !== null) {
$this->pool->setDriver($this->driver);
}
$this->enabled = true;
} | php | public function enable()
{
if ($this->driver !== null) {
$this->pool->setDriver($this->driver);
}
$this->enabled = true;
} | [
"public",
"function",
"enable",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"driver",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"pool",
"->",
"setDriver",
"(",
"$",
"this",
"->",
"driver",
")",
";",
"}",
"$",
"this",
"->",
"enabled",
"=",
"true",
";",
"}"
] | Enables the cache. | [
"Enables",
"the",
"cache",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Cache/Cache.php#L184-L190 | train |
concrete5/concrete5 | concrete/src/Cache/Cache.php | Cache.disable | public function disable()
{
// save the current driver if not yet black hole so it can be restored on enable()
if (!($this->pool->getDriver() instanceof BlackHole)) {
$this->driver = $this->pool->getDriver();
}
$this->pool->setDriver(new BlackHole());
$this->enabled = false;
} | php | public function disable()
{
// save the current driver if not yet black hole so it can be restored on enable()
if (!($this->pool->getDriver() instanceof BlackHole)) {
$this->driver = $this->pool->getDriver();
}
$this->pool->setDriver(new BlackHole());
$this->enabled = false;
} | [
"public",
"function",
"disable",
"(",
")",
"{",
"// save the current driver if not yet black hole so it can be restored on enable()",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"pool",
"->",
"getDriver",
"(",
")",
"instanceof",
"BlackHole",
")",
")",
"{",
"$",
"this",
"->",
"driver",
"=",
"$",
"this",
"->",
"pool",
"->",
"getDriver",
"(",
")",
";",
"}",
"$",
"this",
"->",
"pool",
"->",
"setDriver",
"(",
"new",
"BlackHole",
"(",
")",
")",
";",
"$",
"this",
"->",
"enabled",
"=",
"false",
";",
"}"
] | Disables the cache. | [
"Disables",
"the",
"cache",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Cache/Cache.php#L195-L203 | train |
concrete5/concrete5 | concrete/src/Cache/Cache.php | Cache.disableAll | public static function disableAll()
{
$app = Application::getFacadeApplication();
$app->make('cache/request')->disable();
$app->make('cache/expensive')->disable();
$app->make('cache')->disable();
} | php | public static function disableAll()
{
$app = Application::getFacadeApplication();
$app->make('cache/request')->disable();
$app->make('cache/expensive')->disable();
$app->make('cache')->disable();
} | [
"public",
"static",
"function",
"disableAll",
"(",
")",
"{",
"$",
"app",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"app",
"->",
"make",
"(",
"'cache/request'",
")",
"->",
"disable",
"(",
")",
";",
"$",
"app",
"->",
"make",
"(",
"'cache/expensive'",
")",
"->",
"disable",
"(",
")",
";",
"$",
"app",
"->",
"make",
"(",
"'cache'",
")",
"->",
"disable",
"(",
")",
";",
"}"
] | Disables all cache levels. | [
"Disables",
"all",
"cache",
"levels",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Cache/Cache.php#L218-L224 | train |
concrete5/concrete5 | concrete/src/Cache/Cache.php | Cache.enableAll | public static function enableAll()
{
$app = Application::getFacadeApplication();
$app->make('cache/request')->enable();
$app->make('cache/expensive')->enable();
$app->make('cache')->enable();
} | php | public static function enableAll()
{
$app = Application::getFacadeApplication();
$app->make('cache/request')->enable();
$app->make('cache/expensive')->enable();
$app->make('cache')->enable();
} | [
"public",
"static",
"function",
"enableAll",
"(",
")",
"{",
"$",
"app",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"app",
"->",
"make",
"(",
"'cache/request'",
")",
"->",
"enable",
"(",
")",
";",
"$",
"app",
"->",
"make",
"(",
"'cache/expensive'",
")",
"->",
"enable",
"(",
")",
";",
"$",
"app",
"->",
"make",
"(",
"'cache'",
")",
"->",
"enable",
"(",
")",
";",
"}"
] | Enables all cache levels. | [
"Enables",
"all",
"cache",
"levels",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Cache/Cache.php#L229-L235 | train |
concrete5/concrete5 | concrete/src/Api/OAuth/Server/IdTokenResponse.php | IdTokenResponse.getExtraParams | protected function getExtraParams(AccessTokenEntityInterface $accessToken)
{
$params = parent::getExtraParams($accessToken);
// If this is an OIDC request, pack a new id token into it
if ($this->isOidcRequest($accessToken->getScopes())) {
$user = $this->userInfoRepository->getByID($accessToken->getUserIdentifier());
if ($user) {
$params['id_token'] = (string) $this->createIdToken($accessToken, $this->claimFactory->createFromUserInfo($user));
}
}
return $params;
} | php | protected function getExtraParams(AccessTokenEntityInterface $accessToken)
{
$params = parent::getExtraParams($accessToken);
// If this is an OIDC request, pack a new id token into it
if ($this->isOidcRequest($accessToken->getScopes())) {
$user = $this->userInfoRepository->getByID($accessToken->getUserIdentifier());
if ($user) {
$params['id_token'] = (string) $this->createIdToken($accessToken, $this->claimFactory->createFromUserInfo($user));
}
}
return $params;
} | [
"protected",
"function",
"getExtraParams",
"(",
"AccessTokenEntityInterface",
"$",
"accessToken",
")",
"{",
"$",
"params",
"=",
"parent",
"::",
"getExtraParams",
"(",
"$",
"accessToken",
")",
";",
"// If this is an OIDC request, pack a new id token into it",
"if",
"(",
"$",
"this",
"->",
"isOidcRequest",
"(",
"$",
"accessToken",
"->",
"getScopes",
"(",
")",
")",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"userInfoRepository",
"->",
"getByID",
"(",
"$",
"accessToken",
"->",
"getUserIdentifier",
"(",
")",
")",
";",
"if",
"(",
"$",
"user",
")",
"{",
"$",
"params",
"[",
"'id_token'",
"]",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"createIdToken",
"(",
"$",
"accessToken",
",",
"$",
"this",
"->",
"claimFactory",
"->",
"createFromUserInfo",
"(",
"$",
"user",
")",
")",
";",
"}",
"}",
"return",
"$",
"params",
";",
"}"
] | Get the extra params to include
If this is an OIDC request we include the ID token
@param \League\OAuth2\Server\Entities\AccessTokenEntityInterface $accessToken
@return array | [
"Get",
"the",
"extra",
"params",
"to",
"include",
"If",
"this",
"is",
"an",
"OIDC",
"request",
"we",
"include",
"the",
"ID",
"token"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Api/OAuth/Server/IdTokenResponse.php#L56-L70 | train |
concrete5/concrete5 | concrete/src/Api/OAuth/Server/IdTokenResponse.php | IdTokenResponse.createIdToken | protected function createIdToken(AccessTokenEntityInterface $accessToken, ClaimsSet $claims)
{
$issuer = $this->site->getSite();
// Initialize the builder
$builder = (new Builder())
->setAudience($accessToken->getClient()->getIdentifier())
->setIssuer($issuer->getSiteCanonicalURL())
->setIssuedAt(time())
->setNotBefore(time())
->setExpiration($accessToken->getExpiryDateTime()->getTimestamp())
->setSubject($accessToken->getUserIdentifier());
// Apply claims
foreach ($claims->jsonSerialize() as $key => $claim) {
$builder->set($key, $claim);
}
// Return the newly signed token
return $builder
->sign(new Sha256(), new Key($this->privateKey->getKeyPath(), $this->privateKey->getPassPhrase()))
->getToken();
} | php | protected function createIdToken(AccessTokenEntityInterface $accessToken, ClaimsSet $claims)
{
$issuer = $this->site->getSite();
// Initialize the builder
$builder = (new Builder())
->setAudience($accessToken->getClient()->getIdentifier())
->setIssuer($issuer->getSiteCanonicalURL())
->setIssuedAt(time())
->setNotBefore(time())
->setExpiration($accessToken->getExpiryDateTime()->getTimestamp())
->setSubject($accessToken->getUserIdentifier());
// Apply claims
foreach ($claims->jsonSerialize() as $key => $claim) {
$builder->set($key, $claim);
}
// Return the newly signed token
return $builder
->sign(new Sha256(), new Key($this->privateKey->getKeyPath(), $this->privateKey->getPassPhrase()))
->getToken();
} | [
"protected",
"function",
"createIdToken",
"(",
"AccessTokenEntityInterface",
"$",
"accessToken",
",",
"ClaimsSet",
"$",
"claims",
")",
"{",
"$",
"issuer",
"=",
"$",
"this",
"->",
"site",
"->",
"getSite",
"(",
")",
";",
"// Initialize the builder",
"$",
"builder",
"=",
"(",
"new",
"Builder",
"(",
")",
")",
"->",
"setAudience",
"(",
"$",
"accessToken",
"->",
"getClient",
"(",
")",
"->",
"getIdentifier",
"(",
")",
")",
"->",
"setIssuer",
"(",
"$",
"issuer",
"->",
"getSiteCanonicalURL",
"(",
")",
")",
"->",
"setIssuedAt",
"(",
"time",
"(",
")",
")",
"->",
"setNotBefore",
"(",
"time",
"(",
")",
")",
"->",
"setExpiration",
"(",
"$",
"accessToken",
"->",
"getExpiryDateTime",
"(",
")",
"->",
"getTimestamp",
"(",
")",
")",
"->",
"setSubject",
"(",
"$",
"accessToken",
"->",
"getUserIdentifier",
"(",
")",
")",
";",
"// Apply claims",
"foreach",
"(",
"$",
"claims",
"->",
"jsonSerialize",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"claim",
")",
"{",
"$",
"builder",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"claim",
")",
";",
"}",
"// Return the newly signed token",
"return",
"$",
"builder",
"->",
"sign",
"(",
"new",
"Sha256",
"(",
")",
",",
"new",
"Key",
"(",
"$",
"this",
"->",
"privateKey",
"->",
"getKeyPath",
"(",
")",
",",
"$",
"this",
"->",
"privateKey",
"->",
"getPassPhrase",
"(",
")",
")",
")",
"->",
"getToken",
"(",
")",
";",
"}"
] | Create an ID token to include with our response
@param \League\OAuth2\Server\Entities\AccessTokenEntityInterface $accessToken
@param \League\OpenIdConnectClaims\ClaimsSet $claims
@return \Lcobucci\JWT\Token | [
"Create",
"an",
"ID",
"token",
"to",
"include",
"with",
"our",
"response"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Api/OAuth/Server/IdTokenResponse.php#L80-L102 | train |
concrete5/concrete5 | concrete/src/Error/Handler/JsonErrorHandler.php | JsonErrorHandler.clientSupportsJson | private function clientSupportsJson($minWeight = null)
{
try {
$app = Application::getFacadeApplication();
$rmrp = $app->make(RequestMediaTypeParser::class);
return $rmrp->isMediaTypeSupported('application/json', $minWeight);
} catch (Exception $x) {
return null;
} catch (Throwable $x) {
return null;
}
} | php | private function clientSupportsJson($minWeight = null)
{
try {
$app = Application::getFacadeApplication();
$rmrp = $app->make(RequestMediaTypeParser::class);
return $rmrp->isMediaTypeSupported('application/json', $minWeight);
} catch (Exception $x) {
return null;
} catch (Throwable $x) {
return null;
}
} | [
"private",
"function",
"clientSupportsJson",
"(",
"$",
"minWeight",
"=",
"null",
")",
"{",
"try",
"{",
"$",
"app",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"rmrp",
"=",
"$",
"app",
"->",
"make",
"(",
"RequestMediaTypeParser",
"::",
"class",
")",
";",
"return",
"$",
"rmrp",
"->",
"isMediaTypeSupported",
"(",
"'application/json'",
",",
"$",
"minWeight",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"x",
")",
"{",
"return",
"null",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"x",
")",
"{",
"return",
"null",
";",
"}",
"}"
] | Check if the client supports JSON.
@param float $minWeight
@return bool|null true: yes; false: no; NULL: we weren't able to detect it | [
"Check",
"if",
"the",
"client",
"supports",
"JSON",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Error/Handler/JsonErrorHandler.php#L103-L115 | train |
concrete5/concrete5 | concrete/src/File/Importer.php | Importer.getErrorMessage | public static function getErrorMessage($code)
{
$app = Application::getFacadeApplication();
$defaultStorage = $app->make(StorageLocationFactory::class)->fetchDefault()->getName();
$msg = '';
switch ($code) {
case self::E_PHP_NO_FILE:
case self::E_FILE_INVALID:
$msg = t('Invalid file.');
break;
case self::E_FILE_INVALID_EXTENSION:
$msg = t('Invalid file extension.');
break;
case self::E_PHP_FILE_PARTIAL_UPLOAD:
$msg = t('The file was only partially uploaded.');
break;
case self::E_FILE_INVALID_STORAGE_LOCATION:
$msg = t('No default file storage location could be found to store this file.');
break;
case self::E_FILE_EXCEEDS_POST_MAX_FILE_SIZE:
$msg = t('Uploaded file is too large. The current value of post_max_filesize is %s',
ini_get('post_max_size'));
break;
case self::E_PHP_FILE_EXCEEDS_HTML_MAX_FILE_SIZE:
case self::E_PHP_FILE_EXCEEDS_UPLOAD_MAX_FILESIZE:
$msg = t('Uploaded file is too large. The current value of upload_max_filesize is %s',
ini_get('upload_max_filesize'));
break;
case self::E_FILE_UNABLE_TO_STORE:
$msg = t('Unable to copy file to storage location "%s". Please check the settings for the storage location.',
$defaultStorage);
break;
case self::E_FILE_UNABLE_TO_STORE_PREFIX_PROVIDED:
$msg = t('Unable to copy file to storage location "%s". This file already exists in your site, or there is insufficient disk space for this operation.', $defaultStorage);
break;
case self::E_PHP_NO_TMP_DIR:
$msg = t('Missing a temporary folder.');
break;
case self::E_PHP_CANT_WRITE:
$msg = t('Failed to write file to disk.');
break;
case self::E_PHP_CANT_WRITE:
$msg = t('A PHP extension stopped the file upload.');
break;
case self::E_PHP_FILE_ERROR_DEFAULT:
default:
$msg = t("An unknown error occurred while uploading the file. Please check that file uploads are enabled, and that your file does not exceed the size of the post_max_size or upload_max_filesize variables.\n\nFile Uploads: %s\nMax Upload File Size: %s\nPost Max Size: %s",
ini_get('file_uploads'), ini_get('upload_max_filesize'), ini_get('post_max_size'));
break;
}
return $msg;
} | php | public static function getErrorMessage($code)
{
$app = Application::getFacadeApplication();
$defaultStorage = $app->make(StorageLocationFactory::class)->fetchDefault()->getName();
$msg = '';
switch ($code) {
case self::E_PHP_NO_FILE:
case self::E_FILE_INVALID:
$msg = t('Invalid file.');
break;
case self::E_FILE_INVALID_EXTENSION:
$msg = t('Invalid file extension.');
break;
case self::E_PHP_FILE_PARTIAL_UPLOAD:
$msg = t('The file was only partially uploaded.');
break;
case self::E_FILE_INVALID_STORAGE_LOCATION:
$msg = t('No default file storage location could be found to store this file.');
break;
case self::E_FILE_EXCEEDS_POST_MAX_FILE_SIZE:
$msg = t('Uploaded file is too large. The current value of post_max_filesize is %s',
ini_get('post_max_size'));
break;
case self::E_PHP_FILE_EXCEEDS_HTML_MAX_FILE_SIZE:
case self::E_PHP_FILE_EXCEEDS_UPLOAD_MAX_FILESIZE:
$msg = t('Uploaded file is too large. The current value of upload_max_filesize is %s',
ini_get('upload_max_filesize'));
break;
case self::E_FILE_UNABLE_TO_STORE:
$msg = t('Unable to copy file to storage location "%s". Please check the settings for the storage location.',
$defaultStorage);
break;
case self::E_FILE_UNABLE_TO_STORE_PREFIX_PROVIDED:
$msg = t('Unable to copy file to storage location "%s". This file already exists in your site, or there is insufficient disk space for this operation.', $defaultStorage);
break;
case self::E_PHP_NO_TMP_DIR:
$msg = t('Missing a temporary folder.');
break;
case self::E_PHP_CANT_WRITE:
$msg = t('Failed to write file to disk.');
break;
case self::E_PHP_CANT_WRITE:
$msg = t('A PHP extension stopped the file upload.');
break;
case self::E_PHP_FILE_ERROR_DEFAULT:
default:
$msg = t("An unknown error occurred while uploading the file. Please check that file uploads are enabled, and that your file does not exceed the size of the post_max_size or upload_max_filesize variables.\n\nFile Uploads: %s\nMax Upload File Size: %s\nPost Max Size: %s",
ini_get('file_uploads'), ini_get('upload_max_filesize'), ini_get('post_max_size'));
break;
}
return $msg;
} | [
"public",
"static",
"function",
"getErrorMessage",
"(",
"$",
"code",
")",
"{",
"$",
"app",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"defaultStorage",
"=",
"$",
"app",
"->",
"make",
"(",
"StorageLocationFactory",
"::",
"class",
")",
"->",
"fetchDefault",
"(",
")",
"->",
"getName",
"(",
")",
";",
"$",
"msg",
"=",
"''",
";",
"switch",
"(",
"$",
"code",
")",
"{",
"case",
"self",
"::",
"E_PHP_NO_FILE",
":",
"case",
"self",
"::",
"E_FILE_INVALID",
":",
"$",
"msg",
"=",
"t",
"(",
"'Invalid file.'",
")",
";",
"break",
";",
"case",
"self",
"::",
"E_FILE_INVALID_EXTENSION",
":",
"$",
"msg",
"=",
"t",
"(",
"'Invalid file extension.'",
")",
";",
"break",
";",
"case",
"self",
"::",
"E_PHP_FILE_PARTIAL_UPLOAD",
":",
"$",
"msg",
"=",
"t",
"(",
"'The file was only partially uploaded.'",
")",
";",
"break",
";",
"case",
"self",
"::",
"E_FILE_INVALID_STORAGE_LOCATION",
":",
"$",
"msg",
"=",
"t",
"(",
"'No default file storage location could be found to store this file.'",
")",
";",
"break",
";",
"case",
"self",
"::",
"E_FILE_EXCEEDS_POST_MAX_FILE_SIZE",
":",
"$",
"msg",
"=",
"t",
"(",
"'Uploaded file is too large. The current value of post_max_filesize is %s'",
",",
"ini_get",
"(",
"'post_max_size'",
")",
")",
";",
"break",
";",
"case",
"self",
"::",
"E_PHP_FILE_EXCEEDS_HTML_MAX_FILE_SIZE",
":",
"case",
"self",
"::",
"E_PHP_FILE_EXCEEDS_UPLOAD_MAX_FILESIZE",
":",
"$",
"msg",
"=",
"t",
"(",
"'Uploaded file is too large. The current value of upload_max_filesize is %s'",
",",
"ini_get",
"(",
"'upload_max_filesize'",
")",
")",
";",
"break",
";",
"case",
"self",
"::",
"E_FILE_UNABLE_TO_STORE",
":",
"$",
"msg",
"=",
"t",
"(",
"'Unable to copy file to storage location \"%s\". Please check the settings for the storage location.'",
",",
"$",
"defaultStorage",
")",
";",
"break",
";",
"case",
"self",
"::",
"E_FILE_UNABLE_TO_STORE_PREFIX_PROVIDED",
":",
"$",
"msg",
"=",
"t",
"(",
"'Unable to copy file to storage location \"%s\". This file already exists in your site, or there is insufficient disk space for this operation.'",
",",
"$",
"defaultStorage",
")",
";",
"break",
";",
"case",
"self",
"::",
"E_PHP_NO_TMP_DIR",
":",
"$",
"msg",
"=",
"t",
"(",
"'Missing a temporary folder.'",
")",
";",
"break",
";",
"case",
"self",
"::",
"E_PHP_CANT_WRITE",
":",
"$",
"msg",
"=",
"t",
"(",
"'Failed to write file to disk.'",
")",
";",
"break",
";",
"case",
"self",
"::",
"E_PHP_CANT_WRITE",
":",
"$",
"msg",
"=",
"t",
"(",
"'A PHP extension stopped the file upload.'",
")",
";",
"break",
";",
"case",
"self",
"::",
"E_PHP_FILE_ERROR_DEFAULT",
":",
"default",
":",
"$",
"msg",
"=",
"t",
"(",
"\"An unknown error occurred while uploading the file. Please check that file uploads are enabled, and that your file does not exceed the size of the post_max_size or upload_max_filesize variables.\\n\\nFile Uploads: %s\\nMax Upload File Size: %s\\nPost Max Size: %s\"",
",",
"ini_get",
"(",
"'file_uploads'",
")",
",",
"ini_get",
"(",
"'upload_max_filesize'",
")",
",",
"ini_get",
"(",
"'post_max_size'",
")",
")",
";",
"break",
";",
"}",
"return",
"$",
"msg",
";",
"}"
] | Returns a text string explaining the error that was passed.
@param int $code
@return string | [
"Returns",
"a",
"text",
"string",
"explaining",
"the",
"error",
"that",
"was",
"passed",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Importer.php#L165-L217 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.