repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
symphonycms/symphony-2 | symphony/lib/toolkit/class.page.php | Page.addHeaderToPage | public function addHeaderToPage($name, $value = null, $response_code = null)
{
$this->_headers[strtolower($name)] = array(
'header' => $name . (is_null($value) ? null : ":{$value}"),
'response_code' => $response_code
);
} | php | public function addHeaderToPage($name, $value = null, $response_code = null)
{
$this->_headers[strtolower($name)] = array(
'header' => $name . (is_null($value) ? null : ":{$value}"),
'response_code' => $response_code
);
} | [
"public",
"function",
"addHeaderToPage",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
",",
"$",
"response_code",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"_headers",
"[",
"strtolower",
"(",
"$",
"name",
")",
"]",
"=",
"array",
"(",
"'header'",
"=>",
"$",
"name",
".",
"(",
"is_null",
"(",
"$",
"value",
")",
"?",
"null",
":",
"\":{$value}\"",
")",
",",
"'response_code'",
"=>",
"$",
"response_code",
")",
";",
"}"
] | Adds a header to the $_headers array using the $name
as the key.
@param string $name
The header name, eg. Content-Type.
@param string $value (optional)
The value for the header, eg. text/xml. Defaults to null.
@param integer $response_code (optional)
The HTTP response code that should be set by PHP with this header, eg. 200 | [
"Adds",
"a",
"header",
"to",
"the",
"$_headers",
"array",
"using",
"the",
"$name",
"as",
"the",
"key",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.page.php#L210-L216 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.page.php | Page.getHttpStatusCode | public function getHttpStatusCode()
{
// Legacy check
if ($this->_status != null) {
$this->setHttpStatus($this->_status);
}
if (isset($this->_headers['status'])) {
return $this->_headers['status']['response_code'];
}
return self::HTTP_STATUS_OK;
} | php | public function getHttpStatusCode()
{
// Legacy check
if ($this->_status != null) {
$this->setHttpStatus($this->_status);
}
if (isset($this->_headers['status'])) {
return $this->_headers['status']['response_code'];
}
return self::HTTP_STATUS_OK;
} | [
"public",
"function",
"getHttpStatusCode",
"(",
")",
"{",
"// Legacy check",
"if",
"(",
"$",
"this",
"->",
"_status",
"!=",
"null",
")",
"{",
"$",
"this",
"->",
"setHttpStatus",
"(",
"$",
"this",
"->",
"_status",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_headers",
"[",
"'status'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_headers",
"[",
"'status'",
"]",
"[",
"'response_code'",
"]",
";",
"}",
"return",
"self",
"::",
"HTTP_STATUS_OK",
";",
"}"
] | Gets the current HTTP Status.
If none is set, it assumes HTTP_STATUS_OK
@since Symphony 2.3.2
@return integer | [
"Gets",
"the",
"current",
"HTTP",
"Status",
".",
"If",
"none",
"is",
"set",
"it",
"assumes",
"HTTP_STATUS_OK"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.page.php#L254-L266 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.page.php | Page.__renderHeaders | protected function __renderHeaders()
{
if (!is_array($this->_headers) || empty($this->_headers)) {
return;
}
// Legacy check
if ($this->_status != null) {
$this->setHttpStatus($this->_status);
}
foreach ($this->_headers as $key => $value) {
// If this is the http status
if ($key == 'status' && isset($value['response_code'])) {
$res_code = intval($value['response_code']);
self::renderStatusCode($res_code);
} else {
header($value['header']);
}
}
} | php | protected function __renderHeaders()
{
if (!is_array($this->_headers) || empty($this->_headers)) {
return;
}
// Legacy check
if ($this->_status != null) {
$this->setHttpStatus($this->_status);
}
foreach ($this->_headers as $key => $value) {
// If this is the http status
if ($key == 'status' && isset($value['response_code'])) {
$res_code = intval($value['response_code']);
self::renderStatusCode($res_code);
} else {
header($value['header']);
}
}
} | [
"protected",
"function",
"__renderHeaders",
"(",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"_headers",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"_headers",
")",
")",
"{",
"return",
";",
"}",
"// Legacy check",
"if",
"(",
"$",
"this",
"->",
"_status",
"!=",
"null",
")",
"{",
"$",
"this",
"->",
"setHttpStatus",
"(",
"$",
"this",
"->",
"_status",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_headers",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// If this is the http status",
"if",
"(",
"$",
"key",
"==",
"'status'",
"&&",
"isset",
"(",
"$",
"value",
"[",
"'response_code'",
"]",
")",
")",
"{",
"$",
"res_code",
"=",
"intval",
"(",
"$",
"value",
"[",
"'response_code'",
"]",
")",
";",
"self",
"::",
"renderStatusCode",
"(",
"$",
"res_code",
")",
";",
"}",
"else",
"{",
"header",
"(",
"$",
"value",
"[",
"'header'",
"]",
")",
";",
"}",
"}",
"}"
] | Iterates over the `$_headers` for this page
and outputs them using PHP's header() function. | [
"Iterates",
"over",
"the",
"$_headers",
"for",
"this",
"page",
"and",
"outputs",
"them",
"using",
"PHP",
"s",
"header",
"()",
"function",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.page.php#L305-L325 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.page.php | Page.isRequestValid | public function isRequestValid()
{
$max_size = @ini_get('post_max_size');
if (!$max_size) {
return true;
}
if (server_safe('REQUEST_METHOD') === 'POST' && (int)server_safe('CONTENT_LENGTH') > General::convertHumanFileSizeToBytes($max_size)) {
return false;
}
return true;
} | php | public function isRequestValid()
{
$max_size = @ini_get('post_max_size');
if (!$max_size) {
return true;
}
if (server_safe('REQUEST_METHOD') === 'POST' && (int)server_safe('CONTENT_LENGTH') > General::convertHumanFileSizeToBytes($max_size)) {
return false;
}
return true;
} | [
"public",
"function",
"isRequestValid",
"(",
")",
"{",
"$",
"max_size",
"=",
"@",
"ini_get",
"(",
"'post_max_size'",
")",
";",
"if",
"(",
"!",
"$",
"max_size",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"server_safe",
"(",
"'REQUEST_METHOD'",
")",
"===",
"'POST'",
"&&",
"(",
"int",
")",
"server_safe",
"(",
"'CONTENT_LENGTH'",
")",
">",
"General",
"::",
"convertHumanFileSizeToBytes",
"(",
"$",
"max_size",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | This function will check to ensure that this post request is not larger than
what the server is set to handle. If it is, a notice is shown.
@link https://github.com/symphonycms/symphony-2/issues/1187
@since Symphony 2.5.2 | [
"This",
"function",
"will",
"check",
"to",
"ensure",
"that",
"this",
"post",
"request",
"is",
"not",
"larger",
"than",
"what",
"the",
"server",
"is",
"set",
"to",
"handle",
".",
"If",
"it",
"is",
"a",
"notice",
"is",
"shown",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.page.php#L334-L346 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.section.php | Section.get | public function get($setting = null)
{
if (is_null($setting)) {
return $this->_data;
}
return $this->_data[$setting];
} | php | public function get($setting = null)
{
if (is_null($setting)) {
return $this->_data;
}
return $this->_data[$setting];
} | [
"public",
"function",
"get",
"(",
"$",
"setting",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"setting",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_data",
";",
"}",
"return",
"$",
"this",
"->",
"_data",
"[",
"$",
"setting",
"]",
";",
"}"
] | An accessor function for this Section's settings. If the
$setting param is omitted, an array of all settings will
be returned. Otherwise it will return the data for
the setting given.
@param null|string $setting
@return array|string
If setting is provided, returns a string, if setting is omitted
returns an associative array of this Section's settings | [
"An",
"accessor",
"function",
"for",
"this",
"Section",
"s",
"settings",
".",
"If",
"the",
"$setting",
"param",
"is",
"omitted",
"an",
"array",
"of",
"all",
"settings",
"will",
"be",
"returned",
".",
"Otherwise",
"it",
"will",
"return",
"the",
"data",
"for",
"the",
"setting",
"given",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.section.php#L47-L54 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.section.php | Section.getDefaultSortingField | public function getDefaultSortingField()
{
$fields = $this->fetchVisibleColumns();
foreach ($fields as $field) {
if (!$field->isSortable()) {
continue;
}
return $field->get('id');
}
return 'id';
} | php | public function getDefaultSortingField()
{
$fields = $this->fetchVisibleColumns();
foreach ($fields as $field) {
if (!$field->isSortable()) {
continue;
}
return $field->get('id');
}
return 'id';
} | [
"public",
"function",
"getDefaultSortingField",
"(",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"fetchVisibleColumns",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"$",
"field",
"->",
"isSortable",
"(",
")",
")",
"{",
"continue",
";",
"}",
"return",
"$",
"field",
"->",
"get",
"(",
"'id'",
")",
";",
"}",
"return",
"'id'",
";",
"}"
] | Returns the default field this Section will be sorted by.
This is determined by the first visible field that is allowed to
to be sorted (defined by the field's `isSortable()` function).
If no fields exist or none of them are visible in the entries table,
'id' is returned instead.
@since Symphony 2.3
@throws Exception
@return string
Either the field ID or the string 'id'. | [
"Returns",
"the",
"default",
"field",
"this",
"Section",
"will",
"be",
"sorted",
"by",
".",
"This",
"is",
"determined",
"by",
"the",
"first",
"visible",
"field",
"that",
"is",
"allowed",
"to",
"to",
"be",
"sorted",
"(",
"defined",
"by",
"the",
"field",
"s",
"isSortable",
"()",
"function",
")",
".",
"If",
"no",
"fields",
"exist",
"or",
"none",
"of",
"them",
"are",
"visible",
"in",
"the",
"entries",
"table",
"id",
"is",
"returned",
"instead",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.section.php#L68-L81 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.section.php | Section.getSortingField | public function getSortingField()
{
$result = Symphony::Configuration()->get('section_' . $this->get('handle') . '_sortby', 'sorting');
return (is_null($result) ? $this->getDefaultSortingField() : $result);
} | php | public function getSortingField()
{
$result = Symphony::Configuration()->get('section_' . $this->get('handle') . '_sortby', 'sorting');
return (is_null($result) ? $this->getDefaultSortingField() : $result);
} | [
"public",
"function",
"getSortingField",
"(",
")",
"{",
"$",
"result",
"=",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'section_'",
".",
"$",
"this",
"->",
"get",
"(",
"'handle'",
")",
".",
"'_sortby'",
",",
"'sorting'",
")",
";",
"return",
"(",
"is_null",
"(",
"$",
"result",
")",
"?",
"$",
"this",
"->",
"getDefaultSortingField",
"(",
")",
":",
"$",
"result",
")",
";",
"}"
] | Returns the field this Section will be sorted by, or calls
`getDefaultSortingField()` if the configuration file doesn't
contain any settings for that Section.
@since Symphony 2.3
@throws Exception
@return string
Either the field ID or the string 'id'. | [
"Returns",
"the",
"field",
"this",
"Section",
"will",
"be",
"sorted",
"by",
"or",
"calls",
"getDefaultSortingField",
"()",
"if",
"the",
"configuration",
"file",
"doesn",
"t",
"contain",
"any",
"settings",
"for",
"that",
"Section",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.section.php#L93-L98 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.section.php | Section.getSortingOrder | public function getSortingOrder()
{
$result = Symphony::Configuration()->get('section_' . $this->get('handle') . '_order', 'sorting');
return (is_null($result) ? 'asc' : $result);
} | php | public function getSortingOrder()
{
$result = Symphony::Configuration()->get('section_' . $this->get('handle') . '_order', 'sorting');
return (is_null($result) ? 'asc' : $result);
} | [
"public",
"function",
"getSortingOrder",
"(",
")",
"{",
"$",
"result",
"=",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'section_'",
".",
"$",
"this",
"->",
"get",
"(",
"'handle'",
")",
".",
"'_order'",
",",
"'sorting'",
")",
";",
"return",
"(",
"is_null",
"(",
"$",
"result",
")",
"?",
"'asc'",
":",
"$",
"result",
")",
";",
"}"
] | Returns the sort order for this Section. Defaults to 'asc'.
@since Symphony 2.3
@return string
Either 'asc' or 'desc'. | [
"Returns",
"the",
"sort",
"order",
"for",
"this",
"Section",
".",
"Defaults",
"to",
"asc",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.section.php#L107-L112 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.section.php | Section.setSortingField | public function setSortingField($sort, $write = true)
{
Symphony::Configuration()->set('section_' . $this->get('handle') . '_sortby', $sort, 'sorting');
if ($write) {
Symphony::Configuration()->write();
}
} | php | public function setSortingField($sort, $write = true)
{
Symphony::Configuration()->set('section_' . $this->get('handle') . '_sortby', $sort, 'sorting');
if ($write) {
Symphony::Configuration()->write();
}
} | [
"public",
"function",
"setSortingField",
"(",
"$",
"sort",
",",
"$",
"write",
"=",
"true",
")",
"{",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"set",
"(",
"'section_'",
".",
"$",
"this",
"->",
"get",
"(",
"'handle'",
")",
".",
"'_sortby'",
",",
"$",
"sort",
",",
"'sorting'",
")",
";",
"if",
"(",
"$",
"write",
")",
"{",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"write",
"(",
")",
";",
"}",
"}"
] | Saves the new field this Section will be sorted by.
@since Symphony 2.3
@param string $sort
The field ID or the string 'id'.
@param boolean $write
If false, the new settings won't be written on the configuration file.
Defaults to true. | [
"Saves",
"the",
"new",
"field",
"this",
"Section",
"will",
"be",
"sorted",
"by",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.section.php#L124-L131 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.section.php | Section.setSortingOrder | public function setSortingOrder($order, $write = true)
{
Symphony::Configuration()->set('section_' . $this->get('handle') . '_order', $order, 'sorting');
if ($write) {
Symphony::Configuration()->write();
}
} | php | public function setSortingOrder($order, $write = true)
{
Symphony::Configuration()->set('section_' . $this->get('handle') . '_order', $order, 'sorting');
if ($write) {
Symphony::Configuration()->write();
}
} | [
"public",
"function",
"setSortingOrder",
"(",
"$",
"order",
",",
"$",
"write",
"=",
"true",
")",
"{",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"set",
"(",
"'section_'",
".",
"$",
"this",
"->",
"get",
"(",
"'handle'",
")",
".",
"'_order'",
",",
"$",
"order",
",",
"'sorting'",
")",
";",
"if",
"(",
"$",
"write",
")",
"{",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"write",
"(",
")",
";",
"}",
"}"
] | Saves the new sort order for this Section.
@since Symphony 2.3
@param string $order
Either 'asc' or 'desc'.
@param boolean $write
If false, the new settings won't be written on the configuration file.
Defaults to true. | [
"Saves",
"the",
"new",
"sort",
"order",
"for",
"this",
"Section",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.section.php#L143-L150 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.section.php | Section.fetchAssociatedSections | public function fetchAssociatedSections($respect_visibility = false)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('Section::fetchAssociatedSections()', 'SectionManager::fetchChildAssociations()');
}
return SectionManager::fetchChildAssociations($this->get('id'), $respect_visibility);
} | php | public function fetchAssociatedSections($respect_visibility = false)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('Section::fetchAssociatedSections()', 'SectionManager::fetchChildAssociations()');
}
return SectionManager::fetchChildAssociations($this->get('id'), $respect_visibility);
} | [
"public",
"function",
"fetchAssociatedSections",
"(",
"$",
"respect_visibility",
"=",
"false",
")",
"{",
"if",
"(",
"Symphony",
"::",
"Log",
"(",
")",
")",
"{",
"Symphony",
"::",
"Log",
"(",
")",
"->",
"pushDeprecateWarningToLog",
"(",
"'Section::fetchAssociatedSections()'",
",",
"'SectionManager::fetchChildAssociations()'",
")",
";",
"}",
"return",
"SectionManager",
"::",
"fetchChildAssociations",
"(",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"respect_visibility",
")",
";",
"}"
] | Returns any section associations this section has with other sections
linked using fields. Has an optional parameter, `$respect_visibility` that
will only return associations that are deemed visible by a field that
created the association. eg. An articles section may link to the authors
section, but the field that links these sections has hidden this association
so an Articles column will not appear on the Author's Publish Index
@deprecated This function will be removed in Symphony 3.0. Use `SectionManager::fetchChildAssociations` instead.
@param boolean $respect_visibility
Whether to return all the section associations regardless of if they
are deemed visible or not. Defaults to false, which will return all
associations.
@return array | [
"Returns",
"any",
"section",
"associations",
"this",
"section",
"has",
"with",
"other",
"sections",
"linked",
"using",
"fields",
".",
"Has",
"an",
"optional",
"parameter",
"$respect_visibility",
"that",
"will",
"only",
"return",
"associations",
"that",
"are",
"deemed",
"visible",
"by",
"a",
"field",
"that",
"created",
"the",
"association",
".",
"eg",
".",
"An",
"articles",
"section",
"may",
"link",
"to",
"the",
"authors",
"section",
"but",
"the",
"field",
"that",
"links",
"these",
"sections",
"has",
"hidden",
"this",
"association",
"so",
"an",
"Articles",
"column",
"will",
"not",
"appear",
"on",
"the",
"Author",
"s",
"Publish",
"Index"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.section.php#L167-L173 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.section.php | Section.fetchFields | public function fetchFields($type = null, $location = null)
{
return FieldManager::fetch(null, $this->get('id'), 'ASC', 'sortorder', $type, $location);
} | php | public function fetchFields($type = null, $location = null)
{
return FieldManager::fetch(null, $this->get('id'), 'ASC', 'sortorder', $type, $location);
} | [
"public",
"function",
"fetchFields",
"(",
"$",
"type",
"=",
"null",
",",
"$",
"location",
"=",
"null",
")",
"{",
"return",
"FieldManager",
"::",
"fetch",
"(",
"null",
",",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
",",
"'ASC'",
",",
"'sortorder'",
",",
"$",
"type",
",",
"$",
"location",
")",
";",
"}"
] | Returns an array of all the fields in this section optionally filtered by
the field type or it's location within the section.
@param string $type
The field type (it's handle as returned by `$field->handle()`)
@param string $location
The location of the fields in the entry creator, whether they are
'main' or 'sidebar'
@throws Exception
@return array | [
"Returns",
"an",
"array",
"of",
"all",
"the",
"fields",
"in",
"this",
"section",
"optionally",
"filtered",
"by",
"the",
"field",
"type",
"or",
"it",
"s",
"location",
"within",
"the",
"section",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.section.php#L242-L245 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.section.php | Section.fetchFilterableFields | public function fetchFilterableFields($location = null)
{
return FieldManager::fetch(null, $this->get('id'), 'ASC', 'sortorder', null, $location, null, Field::__FILTERABLE_ONLY__);
} | php | public function fetchFilterableFields($location = null)
{
return FieldManager::fetch(null, $this->get('id'), 'ASC', 'sortorder', null, $location, null, Field::__FILTERABLE_ONLY__);
} | [
"public",
"function",
"fetchFilterableFields",
"(",
"$",
"location",
"=",
"null",
")",
"{",
"return",
"FieldManager",
"::",
"fetch",
"(",
"null",
",",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
",",
"'ASC'",
",",
"'sortorder'",
",",
"null",
",",
"$",
"location",
",",
"null",
",",
"Field",
"::",
"__FILTERABLE_ONLY__",
")",
";",
"}"
] | Returns an array of all the fields that can be filtered.
@param string $location
The location of the fields in the entry creator, whether they are
'main' or 'sidebar'
@throws Exception
@return array | [
"Returns",
"an",
"array",
"of",
"all",
"the",
"fields",
"that",
"can",
"be",
"filtered",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.section.php#L256-L259 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.section.php | Section.fetchToggleableFields | public function fetchToggleableFields($location = null)
{
return FieldManager::fetch(null, $this->get('id'), 'ASC', 'sortorder', null, $location, null, Field::__TOGGLEABLE_ONLY__);
} | php | public function fetchToggleableFields($location = null)
{
return FieldManager::fetch(null, $this->get('id'), 'ASC', 'sortorder', null, $location, null, Field::__TOGGLEABLE_ONLY__);
} | [
"public",
"function",
"fetchToggleableFields",
"(",
"$",
"location",
"=",
"null",
")",
"{",
"return",
"FieldManager",
"::",
"fetch",
"(",
"null",
",",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
",",
"'ASC'",
",",
"'sortorder'",
",",
"null",
",",
"$",
"location",
",",
"null",
",",
"Field",
"::",
"__TOGGLEABLE_ONLY__",
")",
";",
"}"
] | Returns an array of all the fields that can be toggled. This function
is used to help build the With Selected drop downs on the Publish
Index pages
@param string $location
The location of the fields in the entry creator, whether they are
'main' or 'sidebar'
@throws Exception
@return array | [
"Returns",
"an",
"array",
"of",
"all",
"the",
"fields",
"that",
"can",
"be",
"toggled",
".",
"This",
"function",
"is",
"used",
"to",
"help",
"build",
"the",
"With",
"Selected",
"drop",
"downs",
"on",
"the",
"Publish",
"Index",
"pages"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.section.php#L272-L275 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.section.php | Section.commit | public function commit()
{
$settings = $this->_data;
if (isset($settings['id'])) {
$id = $settings['id'];
unset($settings['id']);
$section_id = SectionManager::edit($id, $settings);
if ($section_id) {
$section_id = $id;
}
} else {
$section_id = SectionManager::add($settings);
}
if (is_numeric($section_id) && $section_id !== false) {
for ($ii = 0, $length = count($this->_fields); $ii < $length; $ii++) {
$this->_fields[$ii]->set('parent_section', $section_id);
$this->_fields[$ii]->commit();
}
}
} | php | public function commit()
{
$settings = $this->_data;
if (isset($settings['id'])) {
$id = $settings['id'];
unset($settings['id']);
$section_id = SectionManager::edit($id, $settings);
if ($section_id) {
$section_id = $id;
}
} else {
$section_id = SectionManager::add($settings);
}
if (is_numeric($section_id) && $section_id !== false) {
for ($ii = 0, $length = count($this->_fields); $ii < $length; $ii++) {
$this->_fields[$ii]->set('parent_section', $section_id);
$this->_fields[$ii]->commit();
}
}
} | [
"public",
"function",
"commit",
"(",
")",
"{",
"$",
"settings",
"=",
"$",
"this",
"->",
"_data",
";",
"if",
"(",
"isset",
"(",
"$",
"settings",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"id",
"=",
"$",
"settings",
"[",
"'id'",
"]",
";",
"unset",
"(",
"$",
"settings",
"[",
"'id'",
"]",
")",
";",
"$",
"section_id",
"=",
"SectionManager",
"::",
"edit",
"(",
"$",
"id",
",",
"$",
"settings",
")",
";",
"if",
"(",
"$",
"section_id",
")",
"{",
"$",
"section_id",
"=",
"$",
"id",
";",
"}",
"}",
"else",
"{",
"$",
"section_id",
"=",
"SectionManager",
"::",
"add",
"(",
"$",
"settings",
")",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"section_id",
")",
"&&",
"$",
"section_id",
"!==",
"false",
")",
"{",
"for",
"(",
"$",
"ii",
"=",
"0",
",",
"$",
"length",
"=",
"count",
"(",
"$",
"this",
"->",
"_fields",
")",
";",
"$",
"ii",
"<",
"$",
"length",
";",
"$",
"ii",
"++",
")",
"{",
"$",
"this",
"->",
"_fields",
"[",
"$",
"ii",
"]",
"->",
"set",
"(",
"'parent_section'",
",",
"$",
"section_id",
")",
";",
"$",
"this",
"->",
"_fields",
"[",
"$",
"ii",
"]",
"->",
"commit",
"(",
")",
";",
"}",
"}",
"}"
] | Commit the settings of this section from the section editor to
create an instance of this section in `tbl_sections`. This function
loops of each of the fields in this section and calls their commit
function.
@see toolkit.Field#commit()
@return boolean
true if the commit was successful, false otherwise. | [
"Commit",
"the",
"settings",
"of",
"this",
"section",
"from",
"the",
"section",
"editor",
"to",
"create",
"an",
"instance",
"of",
"this",
"section",
"in",
"tbl_sections",
".",
"This",
"function",
"loops",
"of",
"each",
"of",
"the",
"fields",
"in",
"this",
"section",
"and",
"calls",
"their",
"commit",
"function",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.section.php#L298-L320 |
symphonycms/symphony-2 | symphony/lib/core/class.frontend.php | Frontend.isLoggedIn | public static function isLoggedIn()
{
if (isset($_REQUEST['auth-token']) && $_REQUEST['auth-token'] && strlen($_REQUEST['auth-token']) == 8) {
return self::loginFromToken($_REQUEST['auth-token']);
}
return Symphony::isLoggedIn();
} | php | public static function isLoggedIn()
{
if (isset($_REQUEST['auth-token']) && $_REQUEST['auth-token'] && strlen($_REQUEST['auth-token']) == 8) {
return self::loginFromToken($_REQUEST['auth-token']);
}
return Symphony::isLoggedIn();
} | [
"public",
"static",
"function",
"isLoggedIn",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_REQUEST",
"[",
"'auth-token'",
"]",
")",
"&&",
"$",
"_REQUEST",
"[",
"'auth-token'",
"]",
"&&",
"strlen",
"(",
"$",
"_REQUEST",
"[",
"'auth-token'",
"]",
")",
"==",
"8",
")",
"{",
"return",
"self",
"::",
"loginFromToken",
"(",
"$",
"_REQUEST",
"[",
"'auth-token'",
"]",
")",
";",
"}",
"return",
"Symphony",
"::",
"isLoggedIn",
"(",
")",
";",
"}"
] | Overrides the Symphony `isLoggedIn()` function to allow Authors
to become logged into the frontend when `$_REQUEST['auth-token']`
is present. This logs an Author in using the loginFromToken function.
This function allows the use of 'admin' type pages, where a Frontend
page requires that the viewer be a Symphony Author
@see core.Symphony#loginFromToken()
@see core.Symphony#isLoggedIn()
@return boolean | [
"Overrides",
"the",
"Symphony",
"isLoggedIn",
"()",
"function",
"to",
"allow",
"Authors",
"to",
"become",
"logged",
"into",
"the",
"frontend",
"when",
"$_REQUEST",
"[",
"auth",
"-",
"token",
"]",
"is",
"present",
".",
"This",
"logs",
"an",
"Author",
"in",
"using",
"the",
"loginFromToken",
"function",
".",
"This",
"function",
"allows",
"the",
"use",
"of",
"admin",
"type",
"pages",
"where",
"a",
"Frontend",
"page",
"requires",
"that",
"the",
"viewer",
"be",
"a",
"Symphony",
"Author"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.frontend.php#L69-L76 |
symphonycms/symphony-2 | symphony/lib/core/class.frontend.php | Frontend.display | public function display($page)
{
self::$_page = new FrontendPage;
/**
* `FrontendInitialised` is fired just after the `$_page` variable has been
* created with an instance of the `FrontendPage` class. This delegate is
* fired just before the `FrontendPage->generate()`.
*
* @delegate FrontendInitialised
* @param string $context
* '/frontend/'
*/
Symphony::ExtensionManager()->notifyMembers('FrontendInitialised', '/frontend/');
$output = self::$_page->generate($page);
return $output;
} | php | public function display($page)
{
self::$_page = new FrontendPage;
/**
* `FrontendInitialised` is fired just after the `$_page` variable has been
* created with an instance of the `FrontendPage` class. This delegate is
* fired just before the `FrontendPage->generate()`.
*
* @delegate FrontendInitialised
* @param string $context
* '/frontend/'
*/
Symphony::ExtensionManager()->notifyMembers('FrontendInitialised', '/frontend/');
$output = self::$_page->generate($page);
return $output;
} | [
"public",
"function",
"display",
"(",
"$",
"page",
")",
"{",
"self",
"::",
"$",
"_page",
"=",
"new",
"FrontendPage",
";",
"/**\n * `FrontendInitialised` is fired just after the `$_page` variable has been\n * created with an instance of the `FrontendPage` class. This delegate is\n * fired just before the `FrontendPage->generate()`.\n *\n * @delegate FrontendInitialised\n * @param string $context\n * '/frontend/'\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'FrontendInitialised'",
",",
"'/frontend/'",
")",
";",
"$",
"output",
"=",
"self",
"::",
"$",
"_page",
"->",
"generate",
"(",
"$",
"page",
")",
";",
"return",
"$",
"output",
";",
"}"
] | Called by index.php, this function is responsible for rendering the current
page on the Frontend. One delegate is fired, `FrontendInitialised`
@uses FrontendInitialised
@see boot.getCurrentPage()
@param string $page
The result of getCurrentPage, which returns the `$_GET['symphony-page']`
@throws FrontendPageNotFoundException
@throws SymphonyErrorPage
@return string
The HTML of the page to return | [
"Called",
"by",
"index",
".",
"php",
"this",
"function",
"is",
"responsible",
"for",
"rendering",
"the",
"current",
"page",
"on",
"the",
"Frontend",
".",
"One",
"delegate",
"is",
"fired",
"FrontendInitialised"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.frontend.php#L91-L109 |
symphonycms/symphony-2 | symphony/lib/core/class.frontend.php | FrontendPageNotFoundExceptionHandler.render | public static function render($e)
{
$page = PageManager::fetchPageByType('404');
$previous_exception = Frontend::instance()->getException();
// No 404 detected, throw default Symphony error page
if (is_null($page['id'])) {
parent::render(new SymphonyErrorPage(
$e->getMessage(),
__('Page Not Found'),
'generic',
array(),
Page::HTTP_STATUS_NOT_FOUND
));
// Recursive 404
} elseif (isset($previous_exception)) {
parent::render(new SymphonyErrorPage(
__('This error occurred whilst attempting to resolve the 404 page for the original request.') . ' ' . $e->getMessage(),
__('Page Not Found'),
'generic',
array(),
Page::HTTP_STATUS_NOT_FOUND
));
// Handle 404 page
} else {
$url = '/' . PageManager::resolvePagePath($page['id']) . '/';
Frontend::instance()->setException($e);
$output = Frontend::instance()->display($url);
echo $output;
exit;
}
} | php | public static function render($e)
{
$page = PageManager::fetchPageByType('404');
$previous_exception = Frontend::instance()->getException();
// No 404 detected, throw default Symphony error page
if (is_null($page['id'])) {
parent::render(new SymphonyErrorPage(
$e->getMessage(),
__('Page Not Found'),
'generic',
array(),
Page::HTTP_STATUS_NOT_FOUND
));
// Recursive 404
} elseif (isset($previous_exception)) {
parent::render(new SymphonyErrorPage(
__('This error occurred whilst attempting to resolve the 404 page for the original request.') . ' ' . $e->getMessage(),
__('Page Not Found'),
'generic',
array(),
Page::HTTP_STATUS_NOT_FOUND
));
// Handle 404 page
} else {
$url = '/' . PageManager::resolvePagePath($page['id']) . '/';
Frontend::instance()->setException($e);
$output = Frontend::instance()->display($url);
echo $output;
exit;
}
} | [
"public",
"static",
"function",
"render",
"(",
"$",
"e",
")",
"{",
"$",
"page",
"=",
"PageManager",
"::",
"fetchPageByType",
"(",
"'404'",
")",
";",
"$",
"previous_exception",
"=",
"Frontend",
"::",
"instance",
"(",
")",
"->",
"getException",
"(",
")",
";",
"// No 404 detected, throw default Symphony error page",
"if",
"(",
"is_null",
"(",
"$",
"page",
"[",
"'id'",
"]",
")",
")",
"{",
"parent",
"::",
"render",
"(",
"new",
"SymphonyErrorPage",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"__",
"(",
"'Page Not Found'",
")",
",",
"'generic'",
",",
"array",
"(",
")",
",",
"Page",
"::",
"HTTP_STATUS_NOT_FOUND",
")",
")",
";",
"// Recursive 404",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"previous_exception",
")",
")",
"{",
"parent",
"::",
"render",
"(",
"new",
"SymphonyErrorPage",
"(",
"__",
"(",
"'This error occurred whilst attempting to resolve the 404 page for the original request.'",
")",
".",
"' '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"__",
"(",
"'Page Not Found'",
")",
",",
"'generic'",
",",
"array",
"(",
")",
",",
"Page",
"::",
"HTTP_STATUS_NOT_FOUND",
")",
")",
";",
"// Handle 404 page",
"}",
"else",
"{",
"$",
"url",
"=",
"'/'",
".",
"PageManager",
"::",
"resolvePagePath",
"(",
"$",
"page",
"[",
"'id'",
"]",
")",
".",
"'/'",
";",
"Frontend",
"::",
"instance",
"(",
")",
"->",
"setException",
"(",
"$",
"e",
")",
";",
"$",
"output",
"=",
"Frontend",
"::",
"instance",
"(",
")",
"->",
"display",
"(",
"$",
"url",
")",
";",
"echo",
"$",
"output",
";",
"exit",
";",
"}",
"}"
] | The render function will take a `FrontendPageNotFoundException` Exception and
output a HTML page. This function first checks to see if their is a page in Symphony
that has been given the '404' page type, otherwise it will just use the default
Symphony error page template to output the exception
@param Throwable $e
The Throwable object
@throws FrontendPageNotFoundException
@throws SymphonyErrorPage
@return string
An HTML string | [
"The",
"render",
"function",
"will",
"take",
"a",
"FrontendPageNotFoundException",
"Exception",
"and",
"output",
"a",
"HTML",
"page",
".",
"This",
"function",
"first",
"checks",
"to",
"see",
"if",
"their",
"is",
"a",
"page",
"in",
"Symphony",
"that",
"has",
"been",
"given",
"the",
"404",
"page",
"type",
"otherwise",
"it",
"will",
"just",
"use",
"the",
"default",
"Symphony",
"error",
"page",
"template",
"to",
"output",
"the",
"exception"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.frontend.php#L159-L194 |
symphonycms/symphony-2 | install/lib/class.installer.php | Installer.initialiseLang | public static function initialiseLang()
{
$lang = !empty($_REQUEST['lang']) ? preg_replace('/[^a-zA-Z\-]/', null, $_REQUEST['lang']) : 'en';
Lang::initialize();
Lang::set($lang, false);
} | php | public static function initialiseLang()
{
$lang = !empty($_REQUEST['lang']) ? preg_replace('/[^a-zA-Z\-]/', null, $_REQUEST['lang']) : 'en';
Lang::initialize();
Lang::set($lang, false);
} | [
"public",
"static",
"function",
"initialiseLang",
"(",
")",
"{",
"$",
"lang",
"=",
"!",
"empty",
"(",
"$",
"_REQUEST",
"[",
"'lang'",
"]",
")",
"?",
"preg_replace",
"(",
"'/[^a-zA-Z\\-]/'",
",",
"null",
",",
"$",
"_REQUEST",
"[",
"'lang'",
"]",
")",
":",
"'en'",
";",
"Lang",
"::",
"initialize",
"(",
")",
";",
"Lang",
"::",
"set",
"(",
"$",
"lang",
",",
"false",
")",
";",
"}"
] | Initialises the language by looking at the `lang` key,
passed via GET or POST | [
"Initialises",
"the",
"language",
"by",
"looking",
"at",
"the",
"lang",
"key",
"passed",
"via",
"GET",
"or",
"POST"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/install/lib/class.installer.php#L69-L74 |
symphonycms/symphony-2 | install/lib/class.installer.php | Installer.__checkRequirements | private static function __checkRequirements()
{
$errors = array();
// Check for PHP 5.3+
if (version_compare(phpversion(), '5.3', '<=')) {
$errors[] = array(
'msg' => __('PHP Version is not correct'),
'details' => __('Symphony requires %1$s or greater to work, however version %2$s was detected.', array('<code><abbr title="PHP: Hypertext Pre-processor">PHP</abbr> 5.3</code>', '<code>' . phpversion() . '</code>'))
);
}
// Make sure the install.sql file exists
if (!file_exists(INSTALL . '/includes/install.sql') || !is_readable(INSTALL . '/includes/install.sql')) {
$errors[] = array(
'msg' => __('Missing install.sql file'),
'details' => __('It appears that %s is either missing or not readable. This is required to populate the database and must be uploaded before installation can commence. Ensure that PHP has read permissions.', array('<code>install.sql</code>'))
);
}
// Is MySQL available?
if (!function_exists('mysqli_connect')) {
$errors[] = array(
'msg' => __('MySQLi extension not present'),
'details' => __('Symphony requires PHP to be configured with MySQLi to work.')
);
}
// Is ZLib available?
if (!extension_loaded('zlib')) {
$errors[] = array(
'msg' => __('ZLib extension not present'),
'details' => __('Symphony uses the ZLib compression library for log rotation.')
);
}
// Is libxml available?
if (!extension_loaded('xml') && !extension_loaded('libxml')) {
$errors[] = array(
'msg' => __('XML extension not present'),
'details' => __('Symphony needs the XML extension to pass data to the site frontend.')
);
}
// Is libxslt available?
if (!extension_loaded('xsl') && !extension_loaded('xslt') && !function_exists('domxml_xslt_stylesheet')) {
$errors[] = array(
'msg' => __('XSLT extension not present'),
'details' => __('Symphony needs an XSLT processor such as %s or Sablotron to build pages.', array('Lib<abbr title="eXtensible Stylesheet Language Transformation">XSLT</abbr>'))
);
}
// Is json_encode available?
if (!function_exists('json_decode')) {
$errors[] = array(
'msg' => __('JSON functionality is not present'),
'details' => __('Symphony uses JSON functionality throughout the backend for translations and the interface.')
);
}
// Cannot write to root folder.
if (!is_writable(DOCROOT)) {
$errors['no-write-permission-root'] = array(
'msg' => 'Root folder not writable: ' . DOCROOT,
'details' => __('Symphony does not have write permission to the root directory. Please modify permission settings on %s. This can be reverted once installation is complete.', array('<code>' . DOCROOT . '</code>'))
);
}
// Cannot write to workspace
if (is_dir(DOCROOT . '/workspace') && !is_writable(DOCROOT . '/workspace')) {
$errors['no-write-permission-workspace'] = array(
'msg' => 'Workspace folder not writable: ' . DOCROOT . '/workspace',
'details' => __('Symphony does not have write permission to the existing %1$s directory. Please modify permission settings on this directory and its contents to allow this, such as with a recursive %2$s command.', array('<code>/workspace</code>', '<code>chmod -R</code>'))
);
}
return $errors;
} | php | private static function __checkRequirements()
{
$errors = array();
// Check for PHP 5.3+
if (version_compare(phpversion(), '5.3', '<=')) {
$errors[] = array(
'msg' => __('PHP Version is not correct'),
'details' => __('Symphony requires %1$s or greater to work, however version %2$s was detected.', array('<code><abbr title="PHP: Hypertext Pre-processor">PHP</abbr> 5.3</code>', '<code>' . phpversion() . '</code>'))
);
}
// Make sure the install.sql file exists
if (!file_exists(INSTALL . '/includes/install.sql') || !is_readable(INSTALL . '/includes/install.sql')) {
$errors[] = array(
'msg' => __('Missing install.sql file'),
'details' => __('It appears that %s is either missing or not readable. This is required to populate the database and must be uploaded before installation can commence. Ensure that PHP has read permissions.', array('<code>install.sql</code>'))
);
}
// Is MySQL available?
if (!function_exists('mysqli_connect')) {
$errors[] = array(
'msg' => __('MySQLi extension not present'),
'details' => __('Symphony requires PHP to be configured with MySQLi to work.')
);
}
// Is ZLib available?
if (!extension_loaded('zlib')) {
$errors[] = array(
'msg' => __('ZLib extension not present'),
'details' => __('Symphony uses the ZLib compression library for log rotation.')
);
}
// Is libxml available?
if (!extension_loaded('xml') && !extension_loaded('libxml')) {
$errors[] = array(
'msg' => __('XML extension not present'),
'details' => __('Symphony needs the XML extension to pass data to the site frontend.')
);
}
// Is libxslt available?
if (!extension_loaded('xsl') && !extension_loaded('xslt') && !function_exists('domxml_xslt_stylesheet')) {
$errors[] = array(
'msg' => __('XSLT extension not present'),
'details' => __('Symphony needs an XSLT processor such as %s or Sablotron to build pages.', array('Lib<abbr title="eXtensible Stylesheet Language Transformation">XSLT</abbr>'))
);
}
// Is json_encode available?
if (!function_exists('json_decode')) {
$errors[] = array(
'msg' => __('JSON functionality is not present'),
'details' => __('Symphony uses JSON functionality throughout the backend for translations and the interface.')
);
}
// Cannot write to root folder.
if (!is_writable(DOCROOT)) {
$errors['no-write-permission-root'] = array(
'msg' => 'Root folder not writable: ' . DOCROOT,
'details' => __('Symphony does not have write permission to the root directory. Please modify permission settings on %s. This can be reverted once installation is complete.', array('<code>' . DOCROOT . '</code>'))
);
}
// Cannot write to workspace
if (is_dir(DOCROOT . '/workspace') && !is_writable(DOCROOT . '/workspace')) {
$errors['no-write-permission-workspace'] = array(
'msg' => 'Workspace folder not writable: ' . DOCROOT . '/workspace',
'details' => __('Symphony does not have write permission to the existing %1$s directory. Please modify permission settings on this directory and its contents to allow this, such as with a recursive %2$s command.', array('<code>/workspace</code>', '<code>chmod -R</code>'))
);
}
return $errors;
} | [
"private",
"static",
"function",
"__checkRequirements",
"(",
")",
"{",
"$",
"errors",
"=",
"array",
"(",
")",
";",
"// Check for PHP 5.3+",
"if",
"(",
"version_compare",
"(",
"phpversion",
"(",
")",
",",
"'5.3'",
",",
"'<='",
")",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"__",
"(",
"'PHP Version is not correct'",
")",
",",
"'details'",
"=>",
"__",
"(",
"'Symphony requires %1$s or greater to work, however version %2$s was detected.'",
",",
"array",
"(",
"'<code><abbr title=\"PHP: Hypertext Pre-processor\">PHP</abbr> 5.3</code>'",
",",
"'<code>'",
".",
"phpversion",
"(",
")",
".",
"'</code>'",
")",
")",
")",
";",
"}",
"// Make sure the install.sql file exists",
"if",
"(",
"!",
"file_exists",
"(",
"INSTALL",
".",
"'/includes/install.sql'",
")",
"||",
"!",
"is_readable",
"(",
"INSTALL",
".",
"'/includes/install.sql'",
")",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"__",
"(",
"'Missing install.sql file'",
")",
",",
"'details'",
"=>",
"__",
"(",
"'It appears that %s is either missing or not readable. This is required to populate the database and must be uploaded before installation can commence. Ensure that PHP has read permissions.'",
",",
"array",
"(",
"'<code>install.sql</code>'",
")",
")",
")",
";",
"}",
"// Is MySQL available?",
"if",
"(",
"!",
"function_exists",
"(",
"'mysqli_connect'",
")",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"__",
"(",
"'MySQLi extension not present'",
")",
",",
"'details'",
"=>",
"__",
"(",
"'Symphony requires PHP to be configured with MySQLi to work.'",
")",
")",
";",
"}",
"// Is ZLib available?",
"if",
"(",
"!",
"extension_loaded",
"(",
"'zlib'",
")",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"__",
"(",
"'ZLib extension not present'",
")",
",",
"'details'",
"=>",
"__",
"(",
"'Symphony uses the ZLib compression library for log rotation.'",
")",
")",
";",
"}",
"// Is libxml available?",
"if",
"(",
"!",
"extension_loaded",
"(",
"'xml'",
")",
"&&",
"!",
"extension_loaded",
"(",
"'libxml'",
")",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"__",
"(",
"'XML extension not present'",
")",
",",
"'details'",
"=>",
"__",
"(",
"'Symphony needs the XML extension to pass data to the site frontend.'",
")",
")",
";",
"}",
"// Is libxslt available?",
"if",
"(",
"!",
"extension_loaded",
"(",
"'xsl'",
")",
"&&",
"!",
"extension_loaded",
"(",
"'xslt'",
")",
"&&",
"!",
"function_exists",
"(",
"'domxml_xslt_stylesheet'",
")",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"__",
"(",
"'XSLT extension not present'",
")",
",",
"'details'",
"=>",
"__",
"(",
"'Symphony needs an XSLT processor such as %s or Sablotron to build pages.'",
",",
"array",
"(",
"'Lib<abbr title=\"eXtensible Stylesheet Language Transformation\">XSLT</abbr>'",
")",
")",
")",
";",
"}",
"// Is json_encode available?",
"if",
"(",
"!",
"function_exists",
"(",
"'json_decode'",
")",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"__",
"(",
"'JSON functionality is not present'",
")",
",",
"'details'",
"=>",
"__",
"(",
"'Symphony uses JSON functionality throughout the backend for translations and the interface.'",
")",
")",
";",
"}",
"// Cannot write to root folder.",
"if",
"(",
"!",
"is_writable",
"(",
"DOCROOT",
")",
")",
"{",
"$",
"errors",
"[",
"'no-write-permission-root'",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"'Root folder not writable: '",
".",
"DOCROOT",
",",
"'details'",
"=>",
"__",
"(",
"'Symphony does not have write permission to the root directory. Please modify permission settings on %s. This can be reverted once installation is complete.'",
",",
"array",
"(",
"'<code>'",
".",
"DOCROOT",
".",
"'</code>'",
")",
")",
")",
";",
"}",
"// Cannot write to workspace",
"if",
"(",
"is_dir",
"(",
"DOCROOT",
".",
"'/workspace'",
")",
"&&",
"!",
"is_writable",
"(",
"DOCROOT",
".",
"'/workspace'",
")",
")",
"{",
"$",
"errors",
"[",
"'no-write-permission-workspace'",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"'Workspace folder not writable: '",
".",
"DOCROOT",
".",
"'/workspace'",
",",
"'details'",
"=>",
"__",
"(",
"'Symphony does not have write permission to the existing %1$s directory. Please modify permission settings on this directory and its contents to allow this, such as with a recursive %2$s command.'",
",",
"array",
"(",
"'<code>/workspace</code>'",
",",
"'<code>chmod -R</code>'",
")",
")",
")",
";",
"}",
"return",
"$",
"errors",
";",
"}"
] | This function checks the server can support a Symphony installation.
It checks that PHP is 5.2+, MySQL, Zlib, LibXML, XSLT modules are enabled
and a `install.sql` file exists.
If any of these requirements fail the installation will not proceed.
@return array
An associative array of errors, with `msg` and `details` keys | [
"This",
"function",
"checks",
"the",
"server",
"can",
"support",
"a",
"Symphony",
"installation",
".",
"It",
"checks",
"that",
"PHP",
"is",
"5",
".",
"2",
"+",
"MySQL",
"Zlib",
"LibXML",
"XSLT",
"modules",
"are",
"enabled",
"and",
"a",
"install",
".",
"sql",
"file",
"exists",
".",
"If",
"any",
"of",
"these",
"requirements",
"fail",
"the",
"installation",
"will",
"not",
"proceed",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/install/lib/class.installer.php#L175-L252 |
symphonycms/symphony-2 | install/lib/class.installer.php | Installer.__checkConfiguration | private static function __checkConfiguration()
{
$errors = array();
$fields = self::$POST['fields'];
// Testing the database connection
try {
Symphony::Database()->connect(
$fields['database']['host'],
$fields['database']['user'],
$fields['database']['password'],
$fields['database']['port'],
$fields['database']['db']
);
} catch (DatabaseException $e) {
// Invalid credentials
// @link http://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
if ($e->getDatabaseErrorCode() === 1044 || $e->getDatabaseErrorCode() === 1045) {
$errors['database-invalid-credentials'] = array(
'msg' => 'Database credentials were denied',
'details' => __('Symphony was unable to access the database with these credentials.')
);
}
// Connection related
else {
$errors['no-database-connection'] = array(
'msg' => 'Could not establish database connection.',
'details' => __('Symphony was unable to establish a valid database connection. You may need to modify host or port settings.')
);
}
}
try {
// Check the database table prefix is legal. #1815
if (!preg_match('/^[0-9a-zA-Z\$_]*$/', $fields['database']['tbl_prefix'])) {
$errors['database-table-prefix'] = array(
'msg' => 'Invalid database table prefix: ‘' . $fields['database']['tbl_prefix'] . '’',
'details' => __('The table prefix %s is invalid. The table prefix must only contain numbers, letters or underscore characters.', array('<code>' . $fields['database']['tbl_prefix'] . '</code>'))
);
}
// Check the database credentials
elseif (Symphony::Database()->isConnected()) {
// Incorrect MySQL version
$version = Symphony::Database()->fetchVar('version', 0, "SELECT VERSION() AS `version`;");
if (version_compare($version, '5.5', '<')) {
$errors['database-incorrect-version'] = array(
'msg' => 'MySQL Version is not correct. '. $version . ' detected.',
'details' => __('Symphony requires %1$s or greater to work, however version %2$s was detected. This requirement must be met before installation can proceed.', array('<code>MySQL 5.5</code>', '<code>' . $version . '</code>'))
);
} else {
// Existing table prefix
$tables = Symphony::Database()->fetch(sprintf(
"SHOW TABLES FROM `%s` LIKE '%s'",
mysqli_real_escape_string(Symphony::Database()->getConnectionResource(), $fields['database']['db']),
mysqli_real_escape_string(Symphony::Database()->getConnectionResource(), $fields['database']['tbl_prefix']) . '%'
));
if (is_array($tables) && !empty($tables)) {
$errors['database-table-prefix'] = array(
'msg' => 'Database table prefix clash with ‘' . $fields['database']['db'] . '’',
'details' => __('The table prefix %s is already in use. Please choose a different prefix to use with Symphony.', array('<code>' . $fields['database']['tbl_prefix'] . '</code>'))
);
}
}
}
} catch (DatabaseException $e) {
$errors['unknown-database'] = array(
'msg' => 'Database ‘' . $fields['database']['db'] . '’ not found.',
'details' => __('Symphony was unable to connect to the specified database.')
);
}
// Website name not entered
if (trim($fields['general']['sitename']) == '') {
$errors['general-no-sitename'] = array(
'msg' => 'No sitename entered.',
'details' => __('You must enter a Site name. This will be shown at the top of your backend.')
);
}
// Username Not Entered
if (trim($fields['user']['username']) == '') {
$errors['user-no-username'] = array(
'msg' => 'No username entered.',
'details' => __('You must enter a Username. This will be your Symphony login information.')
);
}
// Password Not Entered
if (trim($fields['user']['password']) == '') {
$errors['user-no-password'] = array(
'msg' => 'No password entered.',
'details' => __('You must enter a Password. This will be your Symphony login information.')
);
}
// Password mismatch
elseif ($fields['user']['password'] != $fields['user']['confirm-password']) {
$errors['user-password-mismatch'] = array(
'msg' => 'Passwords did not match.',
'details' => __('The password and confirmation did not match. Please retype your password.')
);
}
// No Name entered
if (trim($fields['user']['firstname']) == '' || trim($fields['user']['lastname']) == '') {
$errors['user-no-name'] = array(
'msg' => 'Did not enter First and Last names.',
'details' => __('You must enter your name.')
);
}
// Invalid Email
if (!preg_match('/^\w(?:\.?[\w%+-]+)*@\w(?:[\w-]*\.)+?[a-z]{2,}$/i', $fields['user']['email'])) {
$errors['user-invalid-email'] = array(
'msg' => 'Invalid email address supplied.',
'details' => __('This is not a valid email address. You must provide an email address since you will need it if you forget your password.')
);
}
// Admin path not entered
if (trim($fields['symphony']['admin-path']) == '') {
$errors['no-symphony-path'] = array(
'msg' => 'No Symphony path entered.',
'details' => __('You must enter a path for accessing Symphony, or leave the default. This will be used to access Symphony\'s backend.')
);
}
return $errors;
} | php | private static function __checkConfiguration()
{
$errors = array();
$fields = self::$POST['fields'];
// Testing the database connection
try {
Symphony::Database()->connect(
$fields['database']['host'],
$fields['database']['user'],
$fields['database']['password'],
$fields['database']['port'],
$fields['database']['db']
);
} catch (DatabaseException $e) {
// Invalid credentials
// @link http://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
if ($e->getDatabaseErrorCode() === 1044 || $e->getDatabaseErrorCode() === 1045) {
$errors['database-invalid-credentials'] = array(
'msg' => 'Database credentials were denied',
'details' => __('Symphony was unable to access the database with these credentials.')
);
}
// Connection related
else {
$errors['no-database-connection'] = array(
'msg' => 'Could not establish database connection.',
'details' => __('Symphony was unable to establish a valid database connection. You may need to modify host or port settings.')
);
}
}
try {
// Check the database table prefix is legal. #1815
if (!preg_match('/^[0-9a-zA-Z\$_]*$/', $fields['database']['tbl_prefix'])) {
$errors['database-table-prefix'] = array(
'msg' => 'Invalid database table prefix: ‘' . $fields['database']['tbl_prefix'] . '’',
'details' => __('The table prefix %s is invalid. The table prefix must only contain numbers, letters or underscore characters.', array('<code>' . $fields['database']['tbl_prefix'] . '</code>'))
);
}
// Check the database credentials
elseif (Symphony::Database()->isConnected()) {
// Incorrect MySQL version
$version = Symphony::Database()->fetchVar('version', 0, "SELECT VERSION() AS `version`;");
if (version_compare($version, '5.5', '<')) {
$errors['database-incorrect-version'] = array(
'msg' => 'MySQL Version is not correct. '. $version . ' detected.',
'details' => __('Symphony requires %1$s or greater to work, however version %2$s was detected. This requirement must be met before installation can proceed.', array('<code>MySQL 5.5</code>', '<code>' . $version . '</code>'))
);
} else {
// Existing table prefix
$tables = Symphony::Database()->fetch(sprintf(
"SHOW TABLES FROM `%s` LIKE '%s'",
mysqli_real_escape_string(Symphony::Database()->getConnectionResource(), $fields['database']['db']),
mysqli_real_escape_string(Symphony::Database()->getConnectionResource(), $fields['database']['tbl_prefix']) . '%'
));
if (is_array($tables) && !empty($tables)) {
$errors['database-table-prefix'] = array(
'msg' => 'Database table prefix clash with ‘' . $fields['database']['db'] . '’',
'details' => __('The table prefix %s is already in use. Please choose a different prefix to use with Symphony.', array('<code>' . $fields['database']['tbl_prefix'] . '</code>'))
);
}
}
}
} catch (DatabaseException $e) {
$errors['unknown-database'] = array(
'msg' => 'Database ‘' . $fields['database']['db'] . '’ not found.',
'details' => __('Symphony was unable to connect to the specified database.')
);
}
// Website name not entered
if (trim($fields['general']['sitename']) == '') {
$errors['general-no-sitename'] = array(
'msg' => 'No sitename entered.',
'details' => __('You must enter a Site name. This will be shown at the top of your backend.')
);
}
// Username Not Entered
if (trim($fields['user']['username']) == '') {
$errors['user-no-username'] = array(
'msg' => 'No username entered.',
'details' => __('You must enter a Username. This will be your Symphony login information.')
);
}
// Password Not Entered
if (trim($fields['user']['password']) == '') {
$errors['user-no-password'] = array(
'msg' => 'No password entered.',
'details' => __('You must enter a Password. This will be your Symphony login information.')
);
}
// Password mismatch
elseif ($fields['user']['password'] != $fields['user']['confirm-password']) {
$errors['user-password-mismatch'] = array(
'msg' => 'Passwords did not match.',
'details' => __('The password and confirmation did not match. Please retype your password.')
);
}
// No Name entered
if (trim($fields['user']['firstname']) == '' || trim($fields['user']['lastname']) == '') {
$errors['user-no-name'] = array(
'msg' => 'Did not enter First and Last names.',
'details' => __('You must enter your name.')
);
}
// Invalid Email
if (!preg_match('/^\w(?:\.?[\w%+-]+)*@\w(?:[\w-]*\.)+?[a-z]{2,}$/i', $fields['user']['email'])) {
$errors['user-invalid-email'] = array(
'msg' => 'Invalid email address supplied.',
'details' => __('This is not a valid email address. You must provide an email address since you will need it if you forget your password.')
);
}
// Admin path not entered
if (trim($fields['symphony']['admin-path']) == '') {
$errors['no-symphony-path'] = array(
'msg' => 'No Symphony path entered.',
'details' => __('You must enter a path for accessing Symphony, or leave the default. This will be used to access Symphony\'s backend.')
);
}
return $errors;
} | [
"private",
"static",
"function",
"__checkConfiguration",
"(",
")",
"{",
"$",
"errors",
"=",
"array",
"(",
")",
";",
"$",
"fields",
"=",
"self",
"::",
"$",
"POST",
"[",
"'fields'",
"]",
";",
"// Testing the database connection",
"try",
"{",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"connect",
"(",
"$",
"fields",
"[",
"'database'",
"]",
"[",
"'host'",
"]",
",",
"$",
"fields",
"[",
"'database'",
"]",
"[",
"'user'",
"]",
",",
"$",
"fields",
"[",
"'database'",
"]",
"[",
"'password'",
"]",
",",
"$",
"fields",
"[",
"'database'",
"]",
"[",
"'port'",
"]",
",",
"$",
"fields",
"[",
"'database'",
"]",
"[",
"'db'",
"]",
")",
";",
"}",
"catch",
"(",
"DatabaseException",
"$",
"e",
")",
"{",
"// Invalid credentials",
"// @link http://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html",
"if",
"(",
"$",
"e",
"->",
"getDatabaseErrorCode",
"(",
")",
"===",
"1044",
"||",
"$",
"e",
"->",
"getDatabaseErrorCode",
"(",
")",
"===",
"1045",
")",
"{",
"$",
"errors",
"[",
"'database-invalid-credentials'",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"'Database credentials were denied'",
",",
"'details'",
"=>",
"__",
"(",
"'Symphony was unable to access the database with these credentials.'",
")",
")",
";",
"}",
"// Connection related",
"else",
"{",
"$",
"errors",
"[",
"'no-database-connection'",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"'Could not establish database connection.'",
",",
"'details'",
"=>",
"__",
"(",
"'Symphony was unable to establish a valid database connection. You may need to modify host or port settings.'",
")",
")",
";",
"}",
"}",
"try",
"{",
"// Check the database table prefix is legal. #1815",
"if",
"(",
"!",
"preg_match",
"(",
"'/^[0-9a-zA-Z\\$_]*$/'",
",",
"$",
"fields",
"[",
"'database'",
"]",
"[",
"'tbl_prefix'",
"]",
")",
")",
"{",
"$",
"errors",
"[",
"'database-table-prefix'",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"'Invalid database table prefix: ‘' .",
"$",
"i",
"elds['",
"d",
"atabase'][",
"'",
"t",
"bl_prefix'] ",
".",
"'",
"',",
"",
"'details'",
"=>",
"__",
"(",
"'The table prefix %s is invalid. The table prefix must only contain numbers, letters or underscore characters.'",
",",
"array",
"(",
"'<code>'",
".",
"$",
"fields",
"[",
"'database'",
"]",
"[",
"'tbl_prefix'",
"]",
".",
"'</code>'",
")",
")",
")",
";",
"}",
"// Check the database credentials",
"elseif",
"(",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"isConnected",
"(",
")",
")",
"{",
"// Incorrect MySQL version",
"$",
"version",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchVar",
"(",
"'version'",
",",
"0",
",",
"\"SELECT VERSION() AS `version`;\"",
")",
";",
"if",
"(",
"version_compare",
"(",
"$",
"version",
",",
"'5.5'",
",",
"'<'",
")",
")",
"{",
"$",
"errors",
"[",
"'database-incorrect-version'",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"'MySQL Version is not correct. '",
".",
"$",
"version",
".",
"' detected.'",
",",
"'details'",
"=>",
"__",
"(",
"'Symphony requires %1$s or greater to work, however version %2$s was detected. This requirement must be met before installation can proceed.'",
",",
"array",
"(",
"'<code>MySQL 5.5</code>'",
",",
"'<code>'",
".",
"$",
"version",
".",
"'</code>'",
")",
")",
")",
";",
"}",
"else",
"{",
"// Existing table prefix",
"$",
"tables",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetch",
"(",
"sprintf",
"(",
"\"SHOW TABLES FROM `%s` LIKE '%s'\"",
",",
"mysqli_real_escape_string",
"(",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"getConnectionResource",
"(",
")",
",",
"$",
"fields",
"[",
"'database'",
"]",
"[",
"'db'",
"]",
")",
",",
"mysqli_real_escape_string",
"(",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"getConnectionResource",
"(",
")",
",",
"$",
"fields",
"[",
"'database'",
"]",
"[",
"'tbl_prefix'",
"]",
")",
".",
"'%'",
")",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"tables",
")",
"&&",
"!",
"empty",
"(",
"$",
"tables",
")",
")",
"{",
"$",
"errors",
"[",
"'database-table-prefix'",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"'Database table prefix clash with ‘' .",
"$",
"i",
"elds['",
"d",
"atabase'][",
"'",
"d",
"b'] ",
".",
"'",
"',",
"",
"'details'",
"=>",
"__",
"(",
"'The table prefix %s is already in use. Please choose a different prefix to use with Symphony.'",
",",
"array",
"(",
"'<code>'",
".",
"$",
"fields",
"[",
"'database'",
"]",
"[",
"'tbl_prefix'",
"]",
".",
"'</code>'",
")",
")",
")",
";",
"}",
"}",
"}",
"}",
"catch",
"(",
"DatabaseException",
"$",
"e",
")",
"{",
"$",
"errors",
"[",
"'unknown-database'",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"'Database ‘' .",
"$",
"i",
"elds['",
"d",
"atabase'][",
"'",
"d",
"b'] ",
".",
"'",
" not found.',",
"",
"'details'",
"=>",
"__",
"(",
"'Symphony was unable to connect to the specified database.'",
")",
")",
";",
"}",
"// Website name not entered",
"if",
"(",
"trim",
"(",
"$",
"fields",
"[",
"'general'",
"]",
"[",
"'sitename'",
"]",
")",
"==",
"''",
")",
"{",
"$",
"errors",
"[",
"'general-no-sitename'",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"'No sitename entered.'",
",",
"'details'",
"=>",
"__",
"(",
"'You must enter a Site name. This will be shown at the top of your backend.'",
")",
")",
";",
"}",
"// Username Not Entered",
"if",
"(",
"trim",
"(",
"$",
"fields",
"[",
"'user'",
"]",
"[",
"'username'",
"]",
")",
"==",
"''",
")",
"{",
"$",
"errors",
"[",
"'user-no-username'",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"'No username entered.'",
",",
"'details'",
"=>",
"__",
"(",
"'You must enter a Username. This will be your Symphony login information.'",
")",
")",
";",
"}",
"// Password Not Entered",
"if",
"(",
"trim",
"(",
"$",
"fields",
"[",
"'user'",
"]",
"[",
"'password'",
"]",
")",
"==",
"''",
")",
"{",
"$",
"errors",
"[",
"'user-no-password'",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"'No password entered.'",
",",
"'details'",
"=>",
"__",
"(",
"'You must enter a Password. This will be your Symphony login information.'",
")",
")",
";",
"}",
"// Password mismatch",
"elseif",
"(",
"$",
"fields",
"[",
"'user'",
"]",
"[",
"'password'",
"]",
"!=",
"$",
"fields",
"[",
"'user'",
"]",
"[",
"'confirm-password'",
"]",
")",
"{",
"$",
"errors",
"[",
"'user-password-mismatch'",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"'Passwords did not match.'",
",",
"'details'",
"=>",
"__",
"(",
"'The password and confirmation did not match. Please retype your password.'",
")",
")",
";",
"}",
"// No Name entered",
"if",
"(",
"trim",
"(",
"$",
"fields",
"[",
"'user'",
"]",
"[",
"'firstname'",
"]",
")",
"==",
"''",
"||",
"trim",
"(",
"$",
"fields",
"[",
"'user'",
"]",
"[",
"'lastname'",
"]",
")",
"==",
"''",
")",
"{",
"$",
"errors",
"[",
"'user-no-name'",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"'Did not enter First and Last names.'",
",",
"'details'",
"=>",
"__",
"(",
"'You must enter your name.'",
")",
")",
";",
"}",
"// Invalid Email",
"if",
"(",
"!",
"preg_match",
"(",
"'/^\\w(?:\\.?[\\w%+-]+)*@\\w(?:[\\w-]*\\.)+?[a-z]{2,}$/i'",
",",
"$",
"fields",
"[",
"'user'",
"]",
"[",
"'email'",
"]",
")",
")",
"{",
"$",
"errors",
"[",
"'user-invalid-email'",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"'Invalid email address supplied.'",
",",
"'details'",
"=>",
"__",
"(",
"'This is not a valid email address. You must provide an email address since you will need it if you forget your password.'",
")",
")",
";",
"}",
"// Admin path not entered",
"if",
"(",
"trim",
"(",
"$",
"fields",
"[",
"'symphony'",
"]",
"[",
"'admin-path'",
"]",
")",
"==",
"''",
")",
"{",
"$",
"errors",
"[",
"'no-symphony-path'",
"]",
"=",
"array",
"(",
"'msg'",
"=>",
"'No Symphony path entered.'",
",",
"'details'",
"=>",
"__",
"(",
"'You must enter a path for accessing Symphony, or leave the default. This will be used to access Symphony\\'s backend.'",
")",
")",
";",
"}",
"return",
"$",
"errors",
";",
"}"
] | This function checks the current Configuration (which is the values entered
by the user on the installation form) to ensure that `/symphony` and `/workspace`
folders exist and are writable and that the Database credentials are correct.
Once those initial checks pass, the rest of the form values are validated.
@return
An associative array of errors if something went wrong, otherwise an empty array. | [
"This",
"function",
"checks",
"the",
"current",
"Configuration",
"(",
"which",
"is",
"the",
"values",
"entered",
"by",
"the",
"user",
"on",
"the",
"installation",
"form",
")",
"to",
"ensure",
"that",
"/",
"symphony",
"and",
"/",
"workspace",
"folders",
"exist",
"and",
"are",
"writable",
"and",
"that",
"the",
"Database",
"credentials",
"are",
"correct",
".",
"Once",
"those",
"initial",
"checks",
"pass",
"the",
"rest",
"of",
"the",
"form",
"values",
"are",
"validated",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/install/lib/class.installer.php#L263-L392 |
symphonycms/symphony-2 | install/lib/class.installer.php | Installer.__checkUnattended | private static function __checkUnattended()
{
$filepath = MANIFEST . '/unattend.php';
if (!@file_exists($filepath) || !@is_readable($filepath)) {
return false;
}
try {
include $filepath;
if (!isset($settings) || !is_array($settings) || !isset($settings['fields'])) {
return false;
}
// Merge with default values
$settings['fields'] = array_replace_recursive(Symphony::Configuration()->get(), $settings['fields']);
// Special case for the password
if (isset($settings['fields']['user']) && isset($settings['fields']['user']['password'])) {
$settings['fields']['user']['confirm-password'] = $settings['fields']['user']['password'];
}
return $settings;
} catch (Exception $ex) {
Symphony::Log()->pushExceptionToLog($ex, true);
}
return false;
} | php | private static function __checkUnattended()
{
$filepath = MANIFEST . '/unattend.php';
if (!@file_exists($filepath) || !@is_readable($filepath)) {
return false;
}
try {
include $filepath;
if (!isset($settings) || !is_array($settings) || !isset($settings['fields'])) {
return false;
}
// Merge with default values
$settings['fields'] = array_replace_recursive(Symphony::Configuration()->get(), $settings['fields']);
// Special case for the password
if (isset($settings['fields']['user']) && isset($settings['fields']['user']['password'])) {
$settings['fields']['user']['confirm-password'] = $settings['fields']['user']['password'];
}
return $settings;
} catch (Exception $ex) {
Symphony::Log()->pushExceptionToLog($ex, true);
}
return false;
} | [
"private",
"static",
"function",
"__checkUnattended",
"(",
")",
"{",
"$",
"filepath",
"=",
"MANIFEST",
".",
"'/unattend.php'",
";",
"if",
"(",
"!",
"@",
"file_exists",
"(",
"$",
"filepath",
")",
"||",
"!",
"@",
"is_readable",
"(",
"$",
"filepath",
")",
")",
"{",
"return",
"false",
";",
"}",
"try",
"{",
"include",
"$",
"filepath",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"settings",
")",
"||",
"!",
"is_array",
"(",
"$",
"settings",
")",
"||",
"!",
"isset",
"(",
"$",
"settings",
"[",
"'fields'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Merge with default values",
"$",
"settings",
"[",
"'fields'",
"]",
"=",
"array_replace_recursive",
"(",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
")",
",",
"$",
"settings",
"[",
"'fields'",
"]",
")",
";",
"// Special case for the password",
"if",
"(",
"isset",
"(",
"$",
"settings",
"[",
"'fields'",
"]",
"[",
"'user'",
"]",
")",
"&&",
"isset",
"(",
"$",
"settings",
"[",
"'fields'",
"]",
"[",
"'user'",
"]",
"[",
"'password'",
"]",
")",
")",
"{",
"$",
"settings",
"[",
"'fields'",
"]",
"[",
"'user'",
"]",
"[",
"'confirm-password'",
"]",
"=",
"$",
"settings",
"[",
"'fields'",
"]",
"[",
"'user'",
"]",
"[",
"'password'",
"]",
";",
"}",
"return",
"$",
"settings",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"Symphony",
"::",
"Log",
"(",
")",
"->",
"pushExceptionToLog",
"(",
"$",
"ex",
",",
"true",
")",
";",
"}",
"return",
"false",
";",
"}"
] | This function checks if there is a unattend.php file in the MANIFEST folder.
If it finds one, it will load it and check for the $settings variable.
It will also merge the default config values into the 'fields' array.
You can find an empty version at install/include/unattend.php
@return array
An associative array of values, as if it was submitted by a POST | [
"This",
"function",
"checks",
"if",
"there",
"is",
"a",
"unattend",
".",
"php",
"file",
"in",
"the",
"MANIFEST",
"folder",
".",
"If",
"it",
"finds",
"one",
"it",
"will",
"load",
"it",
"and",
"check",
"for",
"the",
"$settings",
"variable",
".",
"It",
"will",
"also",
"merge",
"the",
"default",
"config",
"values",
"into",
"the",
"fields",
"array",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/install/lib/class.installer.php#L404-L426 |
symphonycms/symphony-2 | install/lib/class.installer.php | Installer.__abort | protected static function __abort($message, $start)
{
$result = Symphony::Log()->pushToLog($message, E_ERROR, true);
if ($result) {
Symphony::Log()->writeToLog('============================================', true);
Symphony::Log()->writeToLog(sprintf('INSTALLATION ABORTED: Execution Time - %d sec (%s)',
max(1, time() - $start),
date('d.m.y H:i:s')
), true);
Symphony::Log()->writeToLog('============================================' . PHP_EOL . PHP_EOL . PHP_EOL, true);
}
self::__render(new InstallerPage('failure'));
} | php | protected static function __abort($message, $start)
{
$result = Symphony::Log()->pushToLog($message, E_ERROR, true);
if ($result) {
Symphony::Log()->writeToLog('============================================', true);
Symphony::Log()->writeToLog(sprintf('INSTALLATION ABORTED: Execution Time - %d sec (%s)',
max(1, time() - $start),
date('d.m.y H:i:s')
), true);
Symphony::Log()->writeToLog('============================================' . PHP_EOL . PHP_EOL . PHP_EOL, true);
}
self::__render(new InstallerPage('failure'));
} | [
"protected",
"static",
"function",
"__abort",
"(",
"$",
"message",
",",
"$",
"start",
")",
"{",
"$",
"result",
"=",
"Symphony",
"::",
"Log",
"(",
")",
"->",
"pushToLog",
"(",
"$",
"message",
",",
"E_ERROR",
",",
"true",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"Symphony",
"::",
"Log",
"(",
")",
"->",
"writeToLog",
"(",
"'============================================'",
",",
"true",
")",
";",
"Symphony",
"::",
"Log",
"(",
")",
"->",
"writeToLog",
"(",
"sprintf",
"(",
"'INSTALLATION ABORTED: Execution Time - %d sec (%s)'",
",",
"max",
"(",
"1",
",",
"time",
"(",
")",
"-",
"$",
"start",
")",
",",
"date",
"(",
"'d.m.y H:i:s'",
")",
")",
",",
"true",
")",
";",
"Symphony",
"::",
"Log",
"(",
")",
"->",
"writeToLog",
"(",
"'============================================'",
".",
"PHP_EOL",
".",
"PHP_EOL",
".",
"PHP_EOL",
",",
"true",
")",
";",
"}",
"self",
"::",
"__render",
"(",
"new",
"InstallerPage",
"(",
"'failure'",
")",
")",
";",
"}"
] | If something went wrong, the `__abort` function will write an entry to the Log
file and display the failure page to the user.
@todo: Resume installation after an error has been fixed. | [
"If",
"something",
"went",
"wrong",
"the",
"__abort",
"function",
"will",
"write",
"an",
"entry",
"to",
"the",
"Log",
"file",
"and",
"display",
"the",
"failure",
"page",
"to",
"the",
"user",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/install/lib/class.installer.php#L433-L447 |
symphonycms/symphony-2 | symphony/content/content.ajaxparameters.php | contentAjaxParameters.__getEnvParams | private function __getEnvParams()
{
$params = array();
$env = array('today', 'current-time', 'this-year', 'this-month', 'this-day', 'timezone', 'website-name', 'page-title', 'root', 'workspace', 'root-page', 'current-page', 'current-page-id', 'current-path', 'current-query-string', 'current-url', 'cookie-username', 'cookie-pass', 'page-types', 'upload-limit');
foreach ($env as $param) {
$params[] = sprintf($this->template, $param);
}
return $params;
} | php | private function __getEnvParams()
{
$params = array();
$env = array('today', 'current-time', 'this-year', 'this-month', 'this-day', 'timezone', 'website-name', 'page-title', 'root', 'workspace', 'root-page', 'current-page', 'current-page-id', 'current-path', 'current-query-string', 'current-url', 'cookie-username', 'cookie-pass', 'page-types', 'upload-limit');
foreach ($env as $param) {
$params[] = sprintf($this->template, $param);
}
return $params;
} | [
"private",
"function",
"__getEnvParams",
"(",
")",
"{",
"$",
"params",
"=",
"array",
"(",
")",
";",
"$",
"env",
"=",
"array",
"(",
"'today'",
",",
"'current-time'",
",",
"'this-year'",
",",
"'this-month'",
",",
"'this-day'",
",",
"'timezone'",
",",
"'website-name'",
",",
"'page-title'",
",",
"'root'",
",",
"'workspace'",
",",
"'root-page'",
",",
"'current-page'",
",",
"'current-page-id'",
",",
"'current-path'",
",",
"'current-query-string'",
",",
"'current-url'",
",",
"'cookie-username'",
",",
"'cookie-pass'",
",",
"'page-types'",
",",
"'upload-limit'",
")",
";",
"foreach",
"(",
"$",
"env",
"as",
"$",
"param",
")",
"{",
"$",
"params",
"[",
"]",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"template",
",",
"$",
"param",
")",
";",
"}",
"return",
"$",
"params",
";",
"}"
] | Utilities | [
"Utilities"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/content/content.ajaxparameters.php#L53-L63 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.input.php | FieldInput.__applyValidationRules | private function __applyValidationRules($data)
{
$rule = $this->get('validator');
return ($rule ? General::validateString($data, $rule) : true);
} | php | private function __applyValidationRules($data)
{
$rule = $this->get('validator');
return ($rule ? General::validateString($data, $rule) : true);
} | [
"private",
"function",
"__applyValidationRules",
"(",
"$",
"data",
")",
"{",
"$",
"rule",
"=",
"$",
"this",
"->",
"get",
"(",
"'validator'",
")",
";",
"return",
"(",
"$",
"rule",
"?",
"General",
"::",
"validateString",
"(",
"$",
"data",
",",
"$",
"rule",
")",
":",
"true",
")",
";",
"}"
] | /*-------------------------------------------------------------------------
Utilities:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Utilities",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.input.php#L74-L79 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.input.php | FieldInput.displayPublishPanel | public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null)
{
$value = General::sanitize(isset($data['value']) ? $data['value'] : null);
$label = Widget::Label($this->get('label'));
if ($this->get('required') !== 'yes') {
$label->appendChild(new XMLElement('i', __('Optional')));
}
$label->appendChild(Widget::Input('fields'.$fieldnamePrefix.'['.$this->get('element_name').']'.$fieldnamePostfix, (strlen($value) != 0 ? $value : null)));
if ($flagWithError != null) {
$wrapper->appendChild(Widget::Error($label, $flagWithError));
} else {
$wrapper->appendChild($label);
}
} | php | public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null)
{
$value = General::sanitize(isset($data['value']) ? $data['value'] : null);
$label = Widget::Label($this->get('label'));
if ($this->get('required') !== 'yes') {
$label->appendChild(new XMLElement('i', __('Optional')));
}
$label->appendChild(Widget::Input('fields'.$fieldnamePrefix.'['.$this->get('element_name').']'.$fieldnamePostfix, (strlen($value) != 0 ? $value : null)));
if ($flagWithError != null) {
$wrapper->appendChild(Widget::Error($label, $flagWithError));
} else {
$wrapper->appendChild($label);
}
} | [
"public",
"function",
"displayPublishPanel",
"(",
"XMLElement",
"&",
"$",
"wrapper",
",",
"$",
"data",
"=",
"null",
",",
"$",
"flagWithError",
"=",
"null",
",",
"$",
"fieldnamePrefix",
"=",
"null",
",",
"$",
"fieldnamePostfix",
"=",
"null",
",",
"$",
"entry_id",
"=",
"null",
")",
"{",
"$",
"value",
"=",
"General",
"::",
"sanitize",
"(",
"isset",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
"?",
"$",
"data",
"[",
"'value'",
"]",
":",
"null",
")",
";",
"$",
"label",
"=",
"Widget",
"::",
"Label",
"(",
"$",
"this",
"->",
"get",
"(",
"'label'",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'required'",
")",
"!==",
"'yes'",
")",
"{",
"$",
"label",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'i'",
",",
"__",
"(",
"'Optional'",
")",
")",
")",
";",
"}",
"$",
"label",
"->",
"appendChild",
"(",
"Widget",
"::",
"Input",
"(",
"'fields'",
".",
"$",
"fieldnamePrefix",
".",
"'['",
".",
"$",
"this",
"->",
"get",
"(",
"'element_name'",
")",
".",
"']'",
".",
"$",
"fieldnamePostfix",
",",
"(",
"strlen",
"(",
"$",
"value",
")",
"!=",
"0",
"?",
"$",
"value",
":",
"null",
")",
")",
")",
";",
"if",
"(",
"$",
"flagWithError",
"!=",
"null",
")",
"{",
"$",
"wrapper",
"->",
"appendChild",
"(",
"Widget",
"::",
"Error",
"(",
"$",
"label",
",",
"$",
"flagWithError",
")",
")",
";",
"}",
"else",
"{",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"label",
")",
";",
"}",
"}"
] | /*-------------------------------------------------------------------------
Publish:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Publish",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.input.php#L133-L149 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.input.php | FieldInput.appendFormattedElement | public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null)
{
$value = $data['value'];
if ($encode === true) {
$value = General::sanitize($value);
} else {
if (!General::validateXML($data['value'], $errors, false, new XsltProcess)) {
$value = html_entity_decode($data['value'], ENT_QUOTES, 'UTF-8');
$value = $this->__replaceAmpersands($value);
if (!General::validateXML($value, $errors, false, new XsltProcess)) {
$value = General::sanitize($data['value']);
}
}
}
$wrapper->appendChild(
new XMLElement($this->get('element_name'), $value, array('handle' => $data['handle']))
);
} | php | public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null)
{
$value = $data['value'];
if ($encode === true) {
$value = General::sanitize($value);
} else {
if (!General::validateXML($data['value'], $errors, false, new XsltProcess)) {
$value = html_entity_decode($data['value'], ENT_QUOTES, 'UTF-8');
$value = $this->__replaceAmpersands($value);
if (!General::validateXML($value, $errors, false, new XsltProcess)) {
$value = General::sanitize($data['value']);
}
}
}
$wrapper->appendChild(
new XMLElement($this->get('element_name'), $value, array('handle' => $data['handle']))
);
} | [
"public",
"function",
"appendFormattedElement",
"(",
"XMLElement",
"&",
"$",
"wrapper",
",",
"$",
"data",
",",
"$",
"encode",
"=",
"false",
",",
"$",
"mode",
"=",
"null",
",",
"$",
"entry_id",
"=",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"data",
"[",
"'value'",
"]",
";",
"if",
"(",
"$",
"encode",
"===",
"true",
")",
"{",
"$",
"value",
"=",
"General",
"::",
"sanitize",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"General",
"::",
"validateXML",
"(",
"$",
"data",
"[",
"'value'",
"]",
",",
"$",
"errors",
",",
"false",
",",
"new",
"XsltProcess",
")",
")",
"{",
"$",
"value",
"=",
"html_entity_decode",
"(",
"$",
"data",
"[",
"'value'",
"]",
",",
"ENT_QUOTES",
",",
"'UTF-8'",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"__replaceAmpersands",
"(",
"$",
"value",
")",
";",
"if",
"(",
"!",
"General",
"::",
"validateXML",
"(",
"$",
"value",
",",
"$",
"errors",
",",
"false",
",",
"new",
"XsltProcess",
")",
")",
"{",
"$",
"value",
"=",
"General",
"::",
"sanitize",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
";",
"}",
"}",
"}",
"$",
"wrapper",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"$",
"this",
"->",
"get",
"(",
"'element_name'",
")",
",",
"$",
"value",
",",
"array",
"(",
"'handle'",
"=>",
"$",
"data",
"[",
"'handle'",
"]",
")",
")",
")",
";",
"}"
] | /*-------------------------------------------------------------------------
Output:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Output",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.input.php#L193-L213 |
symphonycms/symphony-2 | symphony/lib/toolkit/events/class.event.section.php | SectionEvent.buildFilterElement | public static function buildFilterElement($name, $status, $message = null, array $attributes = null)
{
$filter = new XMLElement('filter', (!$message || is_object($message) ? null : $message), array('name' => $name, 'status' => $status));
if ($message instanceof XMLElement) {
$filter->appendChild($message);
}
if (is_array($attributes)) {
$filter->setAttributeArray($attributes);
}
return $filter;
} | php | public static function buildFilterElement($name, $status, $message = null, array $attributes = null)
{
$filter = new XMLElement('filter', (!$message || is_object($message) ? null : $message), array('name' => $name, 'status' => $status));
if ($message instanceof XMLElement) {
$filter->appendChild($message);
}
if (is_array($attributes)) {
$filter->setAttributeArray($attributes);
}
return $filter;
} | [
"public",
"static",
"function",
"buildFilterElement",
"(",
"$",
"name",
",",
"$",
"status",
",",
"$",
"message",
"=",
"null",
",",
"array",
"$",
"attributes",
"=",
"null",
")",
"{",
"$",
"filter",
"=",
"new",
"XMLElement",
"(",
"'filter'",
",",
"(",
"!",
"$",
"message",
"||",
"is_object",
"(",
"$",
"message",
")",
"?",
"null",
":",
"$",
"message",
")",
",",
"array",
"(",
"'name'",
"=>",
"$",
"name",
",",
"'status'",
"=>",
"$",
"status",
")",
")",
";",
"if",
"(",
"$",
"message",
"instanceof",
"XMLElement",
")",
"{",
"$",
"filter",
"->",
"appendChild",
"(",
"$",
"message",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"attributes",
")",
")",
"{",
"$",
"filter",
"->",
"setAttributeArray",
"(",
"$",
"attributes",
")",
";",
"}",
"return",
"$",
"filter",
";",
"}"
] | This method will construct XML that represents the result of
an Event filter.
@param string $name
The name of the filter
@param string $status
The status of the filter, either passed or failed.
@param XMLElement|string $message
Optionally, an XMLElement or string to be appended to this
`<filter>` element. XMLElement allows for more complex return
types.
@param array $attributes
An associative array of additional attributes to add to this
`<filter>` element
@return XMLElement | [
"This",
"method",
"will",
"construct",
"XML",
"that",
"represents",
"the",
"result",
"of",
"an",
"Event",
"filter",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/events/class.event.section.php#L47-L60 |
symphonycms/symphony-2 | symphony/lib/toolkit/events/class.event.section.php | SectionEvent.appendErrors | public static function appendErrors(XMLElement $result, array $fields, $errors, $post_values)
{
$result->setAttribute('result', 'error');
$result->appendChild(new XMLElement('message', __('Entry encountered errors when saving.'), array(
'message-id' => EventMessages::ENTRY_ERRORS
)));
foreach ($errors as $field_id => $message) {
$field = FieldManager::fetch($field_id);
// Do a little bit of a check for files so that we can correctly show
// whether they are 'missing' or 'invalid'. If it's missing, then we
// want to remove the data so `__reduceType` will correctly resolve to
// missing instead of invalid.
// @see https://github.com/symphonists/s3upload_field/issues/17
if (isset($_FILES['fields']['error'][$field->get('element_name')])) {
$upload = $_FILES['fields']['error'][$field->get('element_name')];
if ($upload === UPLOAD_ERR_NO_FILE) {
unset($fields[$field->get('element_name')]);
}
}
if (is_array($fields[$field->get('element_name')])) {
$type = array_reduce($fields[$field->get('element_name')], array('SectionEvent', '__reduceType'));
} else {
$type = ($fields[$field->get('element_name')] == '') ? 'missing' : 'invalid';
}
$error = self::createError($field, $type, $message);
$result->appendChild($error);
}
if (isset($post_values) && is_object($post_values)) {
$result->appendChild($post_values);
}
return $result;
} | php | public static function appendErrors(XMLElement $result, array $fields, $errors, $post_values)
{
$result->setAttribute('result', 'error');
$result->appendChild(new XMLElement('message', __('Entry encountered errors when saving.'), array(
'message-id' => EventMessages::ENTRY_ERRORS
)));
foreach ($errors as $field_id => $message) {
$field = FieldManager::fetch($field_id);
// Do a little bit of a check for files so that we can correctly show
// whether they are 'missing' or 'invalid'. If it's missing, then we
// want to remove the data so `__reduceType` will correctly resolve to
// missing instead of invalid.
// @see https://github.com/symphonists/s3upload_field/issues/17
if (isset($_FILES['fields']['error'][$field->get('element_name')])) {
$upload = $_FILES['fields']['error'][$field->get('element_name')];
if ($upload === UPLOAD_ERR_NO_FILE) {
unset($fields[$field->get('element_name')]);
}
}
if (is_array($fields[$field->get('element_name')])) {
$type = array_reduce($fields[$field->get('element_name')], array('SectionEvent', '__reduceType'));
} else {
$type = ($fields[$field->get('element_name')] == '') ? 'missing' : 'invalid';
}
$error = self::createError($field, $type, $message);
$result->appendChild($error);
}
if (isset($post_values) && is_object($post_values)) {
$result->appendChild($post_values);
}
return $result;
} | [
"public",
"static",
"function",
"appendErrors",
"(",
"XMLElement",
"$",
"result",
",",
"array",
"$",
"fields",
",",
"$",
"errors",
",",
"$",
"post_values",
")",
"{",
"$",
"result",
"->",
"setAttribute",
"(",
"'result'",
",",
"'error'",
")",
";",
"$",
"result",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'message'",
",",
"__",
"(",
"'Entry encountered errors when saving.'",
")",
",",
"array",
"(",
"'message-id'",
"=>",
"EventMessages",
"::",
"ENTRY_ERRORS",
")",
")",
")",
";",
"foreach",
"(",
"$",
"errors",
"as",
"$",
"field_id",
"=>",
"$",
"message",
")",
"{",
"$",
"field",
"=",
"FieldManager",
"::",
"fetch",
"(",
"$",
"field_id",
")",
";",
"// Do a little bit of a check for files so that we can correctly show",
"// whether they are 'missing' or 'invalid'. If it's missing, then we",
"// want to remove the data so `__reduceType` will correctly resolve to",
"// missing instead of invalid.",
"// @see https://github.com/symphonists/s3upload_field/issues/17",
"if",
"(",
"isset",
"(",
"$",
"_FILES",
"[",
"'fields'",
"]",
"[",
"'error'",
"]",
"[",
"$",
"field",
"->",
"get",
"(",
"'element_name'",
")",
"]",
")",
")",
"{",
"$",
"upload",
"=",
"$",
"_FILES",
"[",
"'fields'",
"]",
"[",
"'error'",
"]",
"[",
"$",
"field",
"->",
"get",
"(",
"'element_name'",
")",
"]",
";",
"if",
"(",
"$",
"upload",
"===",
"UPLOAD_ERR_NO_FILE",
")",
"{",
"unset",
"(",
"$",
"fields",
"[",
"$",
"field",
"->",
"get",
"(",
"'element_name'",
")",
"]",
")",
";",
"}",
"}",
"if",
"(",
"is_array",
"(",
"$",
"fields",
"[",
"$",
"field",
"->",
"get",
"(",
"'element_name'",
")",
"]",
")",
")",
"{",
"$",
"type",
"=",
"array_reduce",
"(",
"$",
"fields",
"[",
"$",
"field",
"->",
"get",
"(",
"'element_name'",
")",
"]",
",",
"array",
"(",
"'SectionEvent'",
",",
"'__reduceType'",
")",
")",
";",
"}",
"else",
"{",
"$",
"type",
"=",
"(",
"$",
"fields",
"[",
"$",
"field",
"->",
"get",
"(",
"'element_name'",
")",
"]",
"==",
"''",
")",
"?",
"'missing'",
":",
"'invalid'",
";",
"}",
"$",
"error",
"=",
"self",
"::",
"createError",
"(",
"$",
"field",
",",
"$",
"type",
",",
"$",
"message",
")",
";",
"$",
"result",
"->",
"appendChild",
"(",
"$",
"error",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"post_values",
")",
"&&",
"is_object",
"(",
"$",
"post_values",
")",
")",
"{",
"$",
"result",
"->",
"appendChild",
"(",
"$",
"post_values",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Appends errors generated from fields during the execution of an Event
@param XMLElement $result
@param array $fields
@param array $errors
@param object $post_values
@throws Exception
@return XMLElement | [
"Appends",
"errors",
"generated",
"from",
"fields",
"during",
"the",
"execution",
"of",
"an",
"Event"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/events/class.event.section.php#L72-L110 |
symphonycms/symphony-2 | symphony/lib/toolkit/events/class.event.section.php | SectionEvent.createError | public static function createError(Field $field, $type, $message = null)
{
$error = new XMLElement($field->get('element_name'), null, array(
'label' => General::sanitize($field->get('label')),
'type' => $type,
'message-id' => ($type === 'missing') ? EventMessages::FIELD_MISSING : EventMessages::FIELD_INVALID,
'message' => General::sanitize($message)
));
return $error;
} | php | public static function createError(Field $field, $type, $message = null)
{
$error = new XMLElement($field->get('element_name'), null, array(
'label' => General::sanitize($field->get('label')),
'type' => $type,
'message-id' => ($type === 'missing') ? EventMessages::FIELD_MISSING : EventMessages::FIELD_INVALID,
'message' => General::sanitize($message)
));
return $error;
} | [
"public",
"static",
"function",
"createError",
"(",
"Field",
"$",
"field",
",",
"$",
"type",
",",
"$",
"message",
"=",
"null",
")",
"{",
"$",
"error",
"=",
"new",
"XMLElement",
"(",
"$",
"field",
"->",
"get",
"(",
"'element_name'",
")",
",",
"null",
",",
"array",
"(",
"'label'",
"=>",
"General",
"::",
"sanitize",
"(",
"$",
"field",
"->",
"get",
"(",
"'label'",
")",
")",
",",
"'type'",
"=>",
"$",
"type",
",",
"'message-id'",
"=>",
"(",
"$",
"type",
"===",
"'missing'",
")",
"?",
"EventMessages",
"::",
"FIELD_MISSING",
":",
"EventMessages",
"::",
"FIELD_INVALID",
",",
"'message'",
"=>",
"General",
"::",
"sanitize",
"(",
"$",
"message",
")",
")",
")",
";",
"return",
"$",
"error",
";",
"}"
] | Given a Field instance, the type of error, and the message, this function
creates an XMLElement node so that it can be added to the `?debug` for the
Event
@since Symphony 2.5.0
@param Field $field
@param string $type
At the moment 'missing' or 'invalid' accepted
@param string $message
@return XMLElement | [
"Given",
"a",
"Field",
"instance",
"the",
"type",
"of",
"error",
"and",
"the",
"message",
"this",
"function",
"creates",
"an",
"XMLElement",
"node",
"so",
"that",
"it",
"can",
"be",
"added",
"to",
"the",
"?debug",
"for",
"the",
"Event"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/events/class.event.section.php#L124-L134 |
symphonycms/symphony-2 | symphony/lib/toolkit/events/class.event.section.php | SectionEvent.replaceFieldToken | public static function replaceFieldToken($needle, $haystack, $default = null, $discard_field_name = true, $collapse = true)
{
if (preg_match('/^(fields\[[^\]]+\],?)+$/i', $needle)) {
$parts = preg_split('/\,/i', $needle, -1, PREG_SPLIT_NO_EMPTY);
$parts = array_map('trim', $parts);
$stack = array();
foreach ($parts as $p) {
$field = str_replace(array('fields[', ']'), '', $p);
($discard_field_name ? $stack[] = $haystack[$field] : $stack[$field] = $haystack[$field]);
}
if (is_array($stack) && !empty($stack)) {
return $collapse ? implode(' ', $stack) : $stack;
} else {
$needle = null;
}
}
$needle = trim($needle);
if (empty($needle)) {
return $default;
} else {
return $needle;
}
} | php | public static function replaceFieldToken($needle, $haystack, $default = null, $discard_field_name = true, $collapse = true)
{
if (preg_match('/^(fields\[[^\]]+\],?)+$/i', $needle)) {
$parts = preg_split('/\,/i', $needle, -1, PREG_SPLIT_NO_EMPTY);
$parts = array_map('trim', $parts);
$stack = array();
foreach ($parts as $p) {
$field = str_replace(array('fields[', ']'), '', $p);
($discard_field_name ? $stack[] = $haystack[$field] : $stack[$field] = $haystack[$field]);
}
if (is_array($stack) && !empty($stack)) {
return $collapse ? implode(' ', $stack) : $stack;
} else {
$needle = null;
}
}
$needle = trim($needle);
if (empty($needle)) {
return $default;
} else {
return $needle;
}
} | [
"public",
"static",
"function",
"replaceFieldToken",
"(",
"$",
"needle",
",",
"$",
"haystack",
",",
"$",
"default",
"=",
"null",
",",
"$",
"discard_field_name",
"=",
"true",
",",
"$",
"collapse",
"=",
"true",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^(fields\\[[^\\]]+\\],?)+$/i'",
",",
"$",
"needle",
")",
")",
"{",
"$",
"parts",
"=",
"preg_split",
"(",
"'/\\,/i'",
",",
"$",
"needle",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"$",
"parts",
"=",
"array_map",
"(",
"'trim'",
",",
"$",
"parts",
")",
";",
"$",
"stack",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"p",
")",
"{",
"$",
"field",
"=",
"str_replace",
"(",
"array",
"(",
"'fields['",
",",
"']'",
")",
",",
"''",
",",
"$",
"p",
")",
";",
"(",
"$",
"discard_field_name",
"?",
"$",
"stack",
"[",
"]",
"=",
"$",
"haystack",
"[",
"$",
"field",
"]",
":",
"$",
"stack",
"[",
"$",
"field",
"]",
"=",
"$",
"haystack",
"[",
"$",
"field",
"]",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"stack",
")",
"&&",
"!",
"empty",
"(",
"$",
"stack",
")",
")",
"{",
"return",
"$",
"collapse",
"?",
"implode",
"(",
"' '",
",",
"$",
"stack",
")",
":",
"$",
"stack",
";",
"}",
"else",
"{",
"$",
"needle",
"=",
"null",
";",
"}",
"}",
"$",
"needle",
"=",
"trim",
"(",
"$",
"needle",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"needle",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"else",
"{",
"return",
"$",
"needle",
";",
"}",
"}"
] | This function searches the `$haystack` for the given `$needle`,
where the needle is a string representation of where the desired
value exists in the `$haystack` array. For example `fields[name]`
would look in the `$haystack` for the key of `fields` that has the
key `name` and return the value.
@param string $needle
The needle, ie. `fields[name]`.
@param array $haystack
Associative array to find the needle, ie.
`array('fields' => array(
'name' => 'Bob',
'age' => '10'
))`
@param string $default
If the `$needle` is not found, return this value. Defaults to null.
@param boolean $discard_field_name
When matches are found in the `$haystack`, they are added to results
array. This parameter defines if this should be an associative array
or just an array of the matches. Used in conjunction with `$collapse`
@param boolean $collapse
If multiple values are found, this will cause them to be reduced
to single string with ' ' as the separator. Defaults to true.
@return string|array | [
"This",
"function",
"searches",
"the",
"$haystack",
"for",
"the",
"given",
"$needle",
"where",
"the",
"needle",
"is",
"a",
"string",
"representation",
"of",
"where",
"the",
"desired",
"value",
"exists",
"in",
"the",
"$haystack",
"array",
".",
"For",
"example",
"fields",
"[",
"name",
"]",
"would",
"look",
"in",
"the",
"$haystack",
"for",
"the",
"key",
"of",
"fields",
"that",
"has",
"the",
"key",
"name",
"and",
"return",
"the",
"value",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/events/class.event.section.php#L162-L189 |
symphonycms/symphony-2 | symphony/lib/toolkit/events/class.event.section.php | SectionEvent.__reduceType | public static function __reduceType($a, $b)
{
if (is_array($b)) {
return array_reduce($b, array('SectionEvent', '__reduceType'));
}
return (strlen(trim($b)) === 0) ? 'missing' : 'invalid';
} | php | public static function __reduceType($a, $b)
{
if (is_array($b)) {
return array_reduce($b, array('SectionEvent', '__reduceType'));
}
return (strlen(trim($b)) === 0) ? 'missing' : 'invalid';
} | [
"public",
"static",
"function",
"__reduceType",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"b",
")",
")",
"{",
"return",
"array_reduce",
"(",
"$",
"b",
",",
"array",
"(",
"'SectionEvent'",
",",
"'__reduceType'",
")",
")",
";",
"}",
"return",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"b",
")",
")",
"===",
"0",
")",
"?",
"'missing'",
":",
"'invalid'",
";",
"}"
] | Helper method to determine if a field is missing, or if the data
provided was invalid. Used in conjunction with `array_reduce`.
@param array $a,
@param array $b
@return string
'missing' or 'invalid' | [
"Helper",
"method",
"to",
"determine",
"if",
"a",
"field",
"is",
"missing",
"or",
"if",
"the",
"data",
"provided",
"was",
"invalid",
".",
"Used",
"in",
"conjunction",
"with",
"array_reduce",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/events/class.event.section.php#L200-L207 |
symphonycms/symphony-2 | symphony/lib/toolkit/events/class.event.section.php | SectionEvent.execute | public function execute()
{
if (!isset($this->eParamFILTERS) || !is_array($this->eParamFILTERS)) {
$this->eParamFILTERS = array();
}
$result = new XMLElement($this->ROOTELEMENT);
if (in_array('admin-only', $this->eParamFILTERS) && !Symphony::Engine()->isLoggedIn()) {
$result->setAttribute('result', 'error');
$result->appendChild(new XMLElement('message', __('Entry encountered errors when saving.'), array(
'message-id' => EventMessages::ENTRY_ERRORS
)));
$result->appendChild(self::buildFilterElement('admin-only', 'failed'));
return $result;
}
$entry_id = $position = $fields = null;
$post = General::getPostData();
$success = true;
if (!is_array($post['fields'])) {
$post['fields'] = array();
}
if (in_array('expect-multiple', $this->eParamFILTERS)) {
foreach ($post['fields'] as $position => $fields) {
if (isset($post['id'][$position]) && is_numeric($post['id'][$position])) {
$entry_id = $post['id'][$position];
} else {
$entry_id = null;
}
$entry = new XMLElement('entry', null, array('position' => $position));
// Reset errors for each entry execution
$this->filter_results = $this->filter_errors = array();
// Ensure that we are always dealing with an array.
if (!is_array($fields)) {
$fields = array();
}
// Execute the event for this entry
if (!$this->__doit($fields, $entry, $position, $entry_id)) {
$success = false;
}
$result->appendChild($entry);
}
} else {
$fields = $post['fields'];
if (isset($post['id']) && is_numeric($post['id'])) {
$entry_id = $post['id'];
}
$success = $this->__doit($fields, $result, null, $entry_id);
}
if ($success && isset($_REQUEST['redirect'])) {
redirect($_REQUEST['redirect']);
}
return $result;
} | php | public function execute()
{
if (!isset($this->eParamFILTERS) || !is_array($this->eParamFILTERS)) {
$this->eParamFILTERS = array();
}
$result = new XMLElement($this->ROOTELEMENT);
if (in_array('admin-only', $this->eParamFILTERS) && !Symphony::Engine()->isLoggedIn()) {
$result->setAttribute('result', 'error');
$result->appendChild(new XMLElement('message', __('Entry encountered errors when saving.'), array(
'message-id' => EventMessages::ENTRY_ERRORS
)));
$result->appendChild(self::buildFilterElement('admin-only', 'failed'));
return $result;
}
$entry_id = $position = $fields = null;
$post = General::getPostData();
$success = true;
if (!is_array($post['fields'])) {
$post['fields'] = array();
}
if (in_array('expect-multiple', $this->eParamFILTERS)) {
foreach ($post['fields'] as $position => $fields) {
if (isset($post['id'][$position]) && is_numeric($post['id'][$position])) {
$entry_id = $post['id'][$position];
} else {
$entry_id = null;
}
$entry = new XMLElement('entry', null, array('position' => $position));
// Reset errors for each entry execution
$this->filter_results = $this->filter_errors = array();
// Ensure that we are always dealing with an array.
if (!is_array($fields)) {
$fields = array();
}
// Execute the event for this entry
if (!$this->__doit($fields, $entry, $position, $entry_id)) {
$success = false;
}
$result->appendChild($entry);
}
} else {
$fields = $post['fields'];
if (isset($post['id']) && is_numeric($post['id'])) {
$entry_id = $post['id'];
}
$success = $this->__doit($fields, $result, null, $entry_id);
}
if ($success && isset($_REQUEST['redirect'])) {
redirect($_REQUEST['redirect']);
}
return $result;
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"eParamFILTERS",
")",
"||",
"!",
"is_array",
"(",
"$",
"this",
"->",
"eParamFILTERS",
")",
")",
"{",
"$",
"this",
"->",
"eParamFILTERS",
"=",
"array",
"(",
")",
";",
"}",
"$",
"result",
"=",
"new",
"XMLElement",
"(",
"$",
"this",
"->",
"ROOTELEMENT",
")",
";",
"if",
"(",
"in_array",
"(",
"'admin-only'",
",",
"$",
"this",
"->",
"eParamFILTERS",
")",
"&&",
"!",
"Symphony",
"::",
"Engine",
"(",
")",
"->",
"isLoggedIn",
"(",
")",
")",
"{",
"$",
"result",
"->",
"setAttribute",
"(",
"'result'",
",",
"'error'",
")",
";",
"$",
"result",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'message'",
",",
"__",
"(",
"'Entry encountered errors when saving.'",
")",
",",
"array",
"(",
"'message-id'",
"=>",
"EventMessages",
"::",
"ENTRY_ERRORS",
")",
")",
")",
";",
"$",
"result",
"->",
"appendChild",
"(",
"self",
"::",
"buildFilterElement",
"(",
"'admin-only'",
",",
"'failed'",
")",
")",
";",
"return",
"$",
"result",
";",
"}",
"$",
"entry_id",
"=",
"$",
"position",
"=",
"$",
"fields",
"=",
"null",
";",
"$",
"post",
"=",
"General",
"::",
"getPostData",
"(",
")",
";",
"$",
"success",
"=",
"true",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"post",
"[",
"'fields'",
"]",
")",
")",
"{",
"$",
"post",
"[",
"'fields'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"'expect-multiple'",
",",
"$",
"this",
"->",
"eParamFILTERS",
")",
")",
"{",
"foreach",
"(",
"$",
"post",
"[",
"'fields'",
"]",
"as",
"$",
"position",
"=>",
"$",
"fields",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"post",
"[",
"'id'",
"]",
"[",
"$",
"position",
"]",
")",
"&&",
"is_numeric",
"(",
"$",
"post",
"[",
"'id'",
"]",
"[",
"$",
"position",
"]",
")",
")",
"{",
"$",
"entry_id",
"=",
"$",
"post",
"[",
"'id'",
"]",
"[",
"$",
"position",
"]",
";",
"}",
"else",
"{",
"$",
"entry_id",
"=",
"null",
";",
"}",
"$",
"entry",
"=",
"new",
"XMLElement",
"(",
"'entry'",
",",
"null",
",",
"array",
"(",
"'position'",
"=>",
"$",
"position",
")",
")",
";",
"// Reset errors for each entry execution",
"$",
"this",
"->",
"filter_results",
"=",
"$",
"this",
"->",
"filter_errors",
"=",
"array",
"(",
")",
";",
"// Ensure that we are always dealing with an array.",
"if",
"(",
"!",
"is_array",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"}",
"// Execute the event for this entry",
"if",
"(",
"!",
"$",
"this",
"->",
"__doit",
"(",
"$",
"fields",
",",
"$",
"entry",
",",
"$",
"position",
",",
"$",
"entry_id",
")",
")",
"{",
"$",
"success",
"=",
"false",
";",
"}",
"$",
"result",
"->",
"appendChild",
"(",
"$",
"entry",
")",
";",
"}",
"}",
"else",
"{",
"$",
"fields",
"=",
"$",
"post",
"[",
"'fields'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"post",
"[",
"'id'",
"]",
")",
"&&",
"is_numeric",
"(",
"$",
"post",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"entry_id",
"=",
"$",
"post",
"[",
"'id'",
"]",
";",
"}",
"$",
"success",
"=",
"$",
"this",
"->",
"__doit",
"(",
"$",
"fields",
",",
"$",
"result",
",",
"null",
",",
"$",
"entry_id",
")",
";",
"}",
"if",
"(",
"$",
"success",
"&&",
"isset",
"(",
"$",
"_REQUEST",
"[",
"'redirect'",
"]",
")",
")",
"{",
"redirect",
"(",
"$",
"_REQUEST",
"[",
"'redirect'",
"]",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | This function will process the core Filters, Admin Only and Expect
Multiple, before invoking the `__doit` function, which actually
processes the Event. Once the Event has executed, this function will
determine if the user should be redirected to a URL, or to just return
the XML.
@throws Exception
@return XMLElement|void
If `$_REQUEST{'redirect']` is set, and the Event executed successfully,
the user will be redirected to the given location. If `$_REQUEST['redirect']`
is not set, or the Event encountered errors, an XMLElement of the Event
result will be returned. | [
"This",
"function",
"will",
"process",
"the",
"core",
"Filters",
"Admin",
"Only",
"and",
"Expect",
"Multiple",
"before",
"invoking",
"the",
"__doit",
"function",
"which",
"actually",
"processes",
"the",
"Event",
".",
"Once",
"the",
"Event",
"has",
"executed",
"this",
"function",
"will",
"determine",
"if",
"the",
"user",
"should",
"be",
"redirected",
"to",
"a",
"URL",
"or",
"to",
"just",
"return",
"the",
"XML",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/events/class.event.section.php#L223-L287 |
symphonycms/symphony-2 | symphony/lib/toolkit/events/class.event.section.php | SectionEvent.__doit | public function __doit(array $fields = array(), XMLElement &$result, $position = null, $entry_id = null)
{
$post_values = new XMLElement('post-values');
if (!is_array($this->eParamFILTERS)) {
$this->eParamFILTERS = array();
}
// Check to see if the Section of this Event is valid.
if (!$section = SectionManager::fetch($this->getSource())) {
$result->setAttribute('result', 'error');
$result->appendChild(new XMLElement('message', __('The Section, %s, could not be found.', array($this->getSource())), array(
'message-id' => EventMessages::SECTION_MISSING
)));
return false;
}
// Create the post data element
if (!empty($fields)) {
General::array_to_xml($post_values, $fields, true);
}
// If the EventPreSaveFilter fails, return early
if ($this->processPreSaveFilters($result, $fields, $post_values, $entry_id) === false) {
return false;
}
// If the `$entry_id` is provided, check to see if it exists.
// @todo If this was moved above PreSaveFilters, we can pass the
// Entry object to the delegate meaning extensions don't have to
// do that step.
if (isset($entry_id)) {
$entry = EntryManager::fetch($entry_id);
$entry = $entry[0];
if (!is_object($entry)) {
$result->setAttribute('result', 'error');
$result->appendChild(new XMLElement('message', __('The Entry, %s, could not be found.', array($entry_id)), array(
'message-id' => EventMessages::ENTRY_MISSING
)));
return false;
}
// `$entry_id` wasn't provided, create a new Entry object.
} else {
$entry = EntryManager::create();
$entry->set('section_id', $this->getSource());
}
// Validate the data. `$entry->checkPostData` loops over all fields calling
// their `checkPostFieldData` function. If the return of the function is
// `Entry::__ENTRY_FIELD_ERROR__` then abort the event and add the error
// messages to the `$result`.
if (Entry::__ENTRY_FIELD_ERROR__ == $entry->checkPostData($fields, $errors, ($entry->get('id') ? true : false))) {
$result = self::appendErrors($result, $fields, $errors, $post_values);
return false;
// If the data is good, process the data, almost ready to save it to the
// Database. If processing fails, abort the event and display the errors
} elseif (Entry::__ENTRY_OK__ != $entry->setDataFromPost($fields, $errors, false, ($entry->get('id') ? true : false))) {
$result = self::appendErrors($result, $fields, $errors, $post_values);
return false;
// Data is checked, data has been processed, by trying to save the
// Entry caused an error to occur, so abort and return.
} elseif ($entry->commit() === false) {
$result->setAttribute('result', 'error');
$result->appendChild(new XMLElement('message', __('Unknown errors where encountered when saving.'), array(
'message-id' => EventMessages::ENTRY_UNKNOWN
)));
if (isset($post_values) && is_object($post_values)) {
$result->appendChild($post_values);
}
return false;
// Entry was created, add the good news to the return `$result`
} else {
$result->setAttributeArray(array(
'result' => 'success',
'type' => (isset($entry_id) ? 'edited' : 'created'),
'id' => $entry->get('id')
));
if (isset($entry_id)) {
$result->appendChild(new XMLElement('message', __('Entry edited successfully.'), array(
'message-id' => EventMessages::ENTRY_EDITED_SUCCESS
)));
} else {
$result->appendChild(new XMLElement('message', __('Entry created successfully.'), array(
'message-id' => EventMessages::ENTRY_CREATED_SUCCESS
)));
}
}
// PASSIVE FILTERS ONLY AT THIS STAGE. ENTRY HAS ALREADY BEEN CREATED.
if (in_array('send-email', $this->eParamFILTERS) && !in_array('expect-multiple', $this->eParamFILTERS)) {
$result = $this->processSendMailFilter($result, $_POST['send-email'], $fields, $section, $entry);
}
$result = $this->processPostSaveFilters($result, $fields, $entry);
$result = $this->processFinalSaveFilters($result, $fields, $entry);
if (isset($post_values) && is_object($post_values)) {
$result->appendChild($post_values);
}
return true;
} | php | public function __doit(array $fields = array(), XMLElement &$result, $position = null, $entry_id = null)
{
$post_values = new XMLElement('post-values');
if (!is_array($this->eParamFILTERS)) {
$this->eParamFILTERS = array();
}
// Check to see if the Section of this Event is valid.
if (!$section = SectionManager::fetch($this->getSource())) {
$result->setAttribute('result', 'error');
$result->appendChild(new XMLElement('message', __('The Section, %s, could not be found.', array($this->getSource())), array(
'message-id' => EventMessages::SECTION_MISSING
)));
return false;
}
// Create the post data element
if (!empty($fields)) {
General::array_to_xml($post_values, $fields, true);
}
// If the EventPreSaveFilter fails, return early
if ($this->processPreSaveFilters($result, $fields, $post_values, $entry_id) === false) {
return false;
}
// If the `$entry_id` is provided, check to see if it exists.
// @todo If this was moved above PreSaveFilters, we can pass the
// Entry object to the delegate meaning extensions don't have to
// do that step.
if (isset($entry_id)) {
$entry = EntryManager::fetch($entry_id);
$entry = $entry[0];
if (!is_object($entry)) {
$result->setAttribute('result', 'error');
$result->appendChild(new XMLElement('message', __('The Entry, %s, could not be found.', array($entry_id)), array(
'message-id' => EventMessages::ENTRY_MISSING
)));
return false;
}
// `$entry_id` wasn't provided, create a new Entry object.
} else {
$entry = EntryManager::create();
$entry->set('section_id', $this->getSource());
}
// Validate the data. `$entry->checkPostData` loops over all fields calling
// their `checkPostFieldData` function. If the return of the function is
// `Entry::__ENTRY_FIELD_ERROR__` then abort the event and add the error
// messages to the `$result`.
if (Entry::__ENTRY_FIELD_ERROR__ == $entry->checkPostData($fields, $errors, ($entry->get('id') ? true : false))) {
$result = self::appendErrors($result, $fields, $errors, $post_values);
return false;
// If the data is good, process the data, almost ready to save it to the
// Database. If processing fails, abort the event and display the errors
} elseif (Entry::__ENTRY_OK__ != $entry->setDataFromPost($fields, $errors, false, ($entry->get('id') ? true : false))) {
$result = self::appendErrors($result, $fields, $errors, $post_values);
return false;
// Data is checked, data has been processed, by trying to save the
// Entry caused an error to occur, so abort and return.
} elseif ($entry->commit() === false) {
$result->setAttribute('result', 'error');
$result->appendChild(new XMLElement('message', __('Unknown errors where encountered when saving.'), array(
'message-id' => EventMessages::ENTRY_UNKNOWN
)));
if (isset($post_values) && is_object($post_values)) {
$result->appendChild($post_values);
}
return false;
// Entry was created, add the good news to the return `$result`
} else {
$result->setAttributeArray(array(
'result' => 'success',
'type' => (isset($entry_id) ? 'edited' : 'created'),
'id' => $entry->get('id')
));
if (isset($entry_id)) {
$result->appendChild(new XMLElement('message', __('Entry edited successfully.'), array(
'message-id' => EventMessages::ENTRY_EDITED_SUCCESS
)));
} else {
$result->appendChild(new XMLElement('message', __('Entry created successfully.'), array(
'message-id' => EventMessages::ENTRY_CREATED_SUCCESS
)));
}
}
// PASSIVE FILTERS ONLY AT THIS STAGE. ENTRY HAS ALREADY BEEN CREATED.
if (in_array('send-email', $this->eParamFILTERS) && !in_array('expect-multiple', $this->eParamFILTERS)) {
$result = $this->processSendMailFilter($result, $_POST['send-email'], $fields, $section, $entry);
}
$result = $this->processPostSaveFilters($result, $fields, $entry);
$result = $this->processFinalSaveFilters($result, $fields, $entry);
if (isset($post_values) && is_object($post_values)) {
$result->appendChild($post_values);
}
return true;
} | [
"public",
"function",
"__doit",
"(",
"array",
"$",
"fields",
"=",
"array",
"(",
")",
",",
"XMLElement",
"&",
"$",
"result",
",",
"$",
"position",
"=",
"null",
",",
"$",
"entry_id",
"=",
"null",
")",
"{",
"$",
"post_values",
"=",
"new",
"XMLElement",
"(",
"'post-values'",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"eParamFILTERS",
")",
")",
"{",
"$",
"this",
"->",
"eParamFILTERS",
"=",
"array",
"(",
")",
";",
"}",
"// Check to see if the Section of this Event is valid.",
"if",
"(",
"!",
"$",
"section",
"=",
"SectionManager",
"::",
"fetch",
"(",
"$",
"this",
"->",
"getSource",
"(",
")",
")",
")",
"{",
"$",
"result",
"->",
"setAttribute",
"(",
"'result'",
",",
"'error'",
")",
";",
"$",
"result",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'message'",
",",
"__",
"(",
"'The Section, %s, could not be found.'",
",",
"array",
"(",
"$",
"this",
"->",
"getSource",
"(",
")",
")",
")",
",",
"array",
"(",
"'message-id'",
"=>",
"EventMessages",
"::",
"SECTION_MISSING",
")",
")",
")",
";",
"return",
"false",
";",
"}",
"// Create the post data element",
"if",
"(",
"!",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"General",
"::",
"array_to_xml",
"(",
"$",
"post_values",
",",
"$",
"fields",
",",
"true",
")",
";",
"}",
"// If the EventPreSaveFilter fails, return early",
"if",
"(",
"$",
"this",
"->",
"processPreSaveFilters",
"(",
"$",
"result",
",",
"$",
"fields",
",",
"$",
"post_values",
",",
"$",
"entry_id",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"// If the `$entry_id` is provided, check to see if it exists.",
"// @todo If this was moved above PreSaveFilters, we can pass the",
"// Entry object to the delegate meaning extensions don't have to",
"// do that step.",
"if",
"(",
"isset",
"(",
"$",
"entry_id",
")",
")",
"{",
"$",
"entry",
"=",
"EntryManager",
"::",
"fetch",
"(",
"$",
"entry_id",
")",
";",
"$",
"entry",
"=",
"$",
"entry",
"[",
"0",
"]",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"entry",
")",
")",
"{",
"$",
"result",
"->",
"setAttribute",
"(",
"'result'",
",",
"'error'",
")",
";",
"$",
"result",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'message'",
",",
"__",
"(",
"'The Entry, %s, could not be found.'",
",",
"array",
"(",
"$",
"entry_id",
")",
")",
",",
"array",
"(",
"'message-id'",
"=>",
"EventMessages",
"::",
"ENTRY_MISSING",
")",
")",
")",
";",
"return",
"false",
";",
"}",
"// `$entry_id` wasn't provided, create a new Entry object.",
"}",
"else",
"{",
"$",
"entry",
"=",
"EntryManager",
"::",
"create",
"(",
")",
";",
"$",
"entry",
"->",
"set",
"(",
"'section_id'",
",",
"$",
"this",
"->",
"getSource",
"(",
")",
")",
";",
"}",
"// Validate the data. `$entry->checkPostData` loops over all fields calling",
"// their `checkPostFieldData` function. If the return of the function is",
"// `Entry::__ENTRY_FIELD_ERROR__` then abort the event and add the error",
"// messages to the `$result`.",
"if",
"(",
"Entry",
"::",
"__ENTRY_FIELD_ERROR__",
"==",
"$",
"entry",
"->",
"checkPostData",
"(",
"$",
"fields",
",",
"$",
"errors",
",",
"(",
"$",
"entry",
"->",
"get",
"(",
"'id'",
")",
"?",
"true",
":",
"false",
")",
")",
")",
"{",
"$",
"result",
"=",
"self",
"::",
"appendErrors",
"(",
"$",
"result",
",",
"$",
"fields",
",",
"$",
"errors",
",",
"$",
"post_values",
")",
";",
"return",
"false",
";",
"// If the data is good, process the data, almost ready to save it to the",
"// Database. If processing fails, abort the event and display the errors",
"}",
"elseif",
"(",
"Entry",
"::",
"__ENTRY_OK__",
"!=",
"$",
"entry",
"->",
"setDataFromPost",
"(",
"$",
"fields",
",",
"$",
"errors",
",",
"false",
",",
"(",
"$",
"entry",
"->",
"get",
"(",
"'id'",
")",
"?",
"true",
":",
"false",
")",
")",
")",
"{",
"$",
"result",
"=",
"self",
"::",
"appendErrors",
"(",
"$",
"result",
",",
"$",
"fields",
",",
"$",
"errors",
",",
"$",
"post_values",
")",
";",
"return",
"false",
";",
"// Data is checked, data has been processed, by trying to save the",
"// Entry caused an error to occur, so abort and return.",
"}",
"elseif",
"(",
"$",
"entry",
"->",
"commit",
"(",
")",
"===",
"false",
")",
"{",
"$",
"result",
"->",
"setAttribute",
"(",
"'result'",
",",
"'error'",
")",
";",
"$",
"result",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'message'",
",",
"__",
"(",
"'Unknown errors where encountered when saving.'",
")",
",",
"array",
"(",
"'message-id'",
"=>",
"EventMessages",
"::",
"ENTRY_UNKNOWN",
")",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"post_values",
")",
"&&",
"is_object",
"(",
"$",
"post_values",
")",
")",
"{",
"$",
"result",
"->",
"appendChild",
"(",
"$",
"post_values",
")",
";",
"}",
"return",
"false",
";",
"// Entry was created, add the good news to the return `$result`",
"}",
"else",
"{",
"$",
"result",
"->",
"setAttributeArray",
"(",
"array",
"(",
"'result'",
"=>",
"'success'",
",",
"'type'",
"=>",
"(",
"isset",
"(",
"$",
"entry_id",
")",
"?",
"'edited'",
":",
"'created'",
")",
",",
"'id'",
"=>",
"$",
"entry",
"->",
"get",
"(",
"'id'",
")",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"entry_id",
")",
")",
"{",
"$",
"result",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'message'",
",",
"__",
"(",
"'Entry edited successfully.'",
")",
",",
"array",
"(",
"'message-id'",
"=>",
"EventMessages",
"::",
"ENTRY_EDITED_SUCCESS",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"result",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'message'",
",",
"__",
"(",
"'Entry created successfully.'",
")",
",",
"array",
"(",
"'message-id'",
"=>",
"EventMessages",
"::",
"ENTRY_CREATED_SUCCESS",
")",
")",
")",
";",
"}",
"}",
"// PASSIVE FILTERS ONLY AT THIS STAGE. ENTRY HAS ALREADY BEEN CREATED.",
"if",
"(",
"in_array",
"(",
"'send-email'",
",",
"$",
"this",
"->",
"eParamFILTERS",
")",
"&&",
"!",
"in_array",
"(",
"'expect-multiple'",
",",
"$",
"this",
"->",
"eParamFILTERS",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"processSendMailFilter",
"(",
"$",
"result",
",",
"$",
"_POST",
"[",
"'send-email'",
"]",
",",
"$",
"fields",
",",
"$",
"section",
",",
"$",
"entry",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"processPostSaveFilters",
"(",
"$",
"result",
",",
"$",
"fields",
",",
"$",
"entry",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"processFinalSaveFilters",
"(",
"$",
"result",
",",
"$",
"fields",
",",
"$",
"entry",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"post_values",
")",
"&&",
"is_object",
"(",
"$",
"post_values",
")",
")",
"{",
"$",
"result",
"->",
"appendChild",
"(",
"$",
"post_values",
")",
";",
"}",
"return",
"true",
";",
"}"
] | This function does the bulk of processing the Event, from running the delegates
to validating the data and eventually saving the data into Symphony. The result
of the Event is returned via the `$result` parameter.
@param array $fields
An array of $_POST data, to process and add/edit an entry.
@param XMLElement $result
The XMLElement contains the result of the Event, it is passed by
reference.
@param integer $position
When the Expect Multiple filter is added, this event should expect
to deal with adding (or editing) multiple entries at once.
@param integer $entry_id
If this Event is editing an existing entry, that Entry ID will
be passed to this function.
@throws Exception
@return XMLElement
The result of the Event | [
"This",
"function",
"does",
"the",
"bulk",
"of",
"processing",
"the",
"Event",
"from",
"running",
"the",
"delegates",
"to",
"validating",
"the",
"data",
"and",
"eventually",
"saving",
"the",
"data",
"into",
"Symphony",
".",
"The",
"result",
"of",
"the",
"Event",
"is",
"returned",
"via",
"the",
"$result",
"parameter",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/events/class.event.section.php#L309-L419 |
symphonycms/symphony-2 | symphony/lib/toolkit/events/class.event.section.php | SectionEvent.processPreSaveFilters | protected function processPreSaveFilters(XMLElement $result, array &$fields, XMLElement &$post_values, $entry_id = null)
{
$can_proceed = true;
/**
* Prior to saving entry from the front-end. This delegate will
* force the Event to terminate if it populates the `$filter_results`
* array. All parameters are passed by reference.
*
* @delegate EventPreSaveFilter
* @param string $context
* '/frontend/'
* @param array $fields
* @param Event $this
* @param array $messages
* An associative array of array's which contain 4 values,
* the name of the filter (string), the status (boolean),
* the message (string) an optionally an associative array
* of additional attributes to add to the filter element.
* @param XMLElement $post_values
* @param integer $entry_id
* If editing an entry, this parameter will be an integer,
* otherwise null.
*/
Symphony::ExtensionManager()->notifyMembers(
'EventPreSaveFilter',
'/frontend/',
array(
'fields' => &$fields,
'event' => &$this,
'messages' => &$this->filter_results,
'post_values' => &$post_values,
'entry_id' => $entry_id
)
);
// Logic taken from `event.section.php` to fail should any `$this->filter_results`
// be returned. This delegate can cause the event to exit early.
if (is_array($this->filter_results) && !empty($this->filter_results)) {
$can_proceed = true;
foreach ($this->filter_results as $fr) {
list($name, $status, $message, $attributes) = array_pad($fr, 4, null);
$result->appendChild(
self::buildFilterElement($name, ($status ? 'passed' : 'failed'), $message, $attributes)
);
if ($status === false) {
$can_proceed = false;
}
}
if ($can_proceed !== true) {
$result->appendChild($post_values);
$result->setAttribute('result', 'error');
$result->appendChild(new XMLElement('message', __('Entry encountered errors when saving.'), array(
'message-id' => EventMessages::FILTER_FAILED
)));
}
}
// Reset the filter results to prevent duplicates. RE: #2179
$this->filter_results = array();
return $can_proceed;
} | php | protected function processPreSaveFilters(XMLElement $result, array &$fields, XMLElement &$post_values, $entry_id = null)
{
$can_proceed = true;
/**
* Prior to saving entry from the front-end. This delegate will
* force the Event to terminate if it populates the `$filter_results`
* array. All parameters are passed by reference.
*
* @delegate EventPreSaveFilter
* @param string $context
* '/frontend/'
* @param array $fields
* @param Event $this
* @param array $messages
* An associative array of array's which contain 4 values,
* the name of the filter (string), the status (boolean),
* the message (string) an optionally an associative array
* of additional attributes to add to the filter element.
* @param XMLElement $post_values
* @param integer $entry_id
* If editing an entry, this parameter will be an integer,
* otherwise null.
*/
Symphony::ExtensionManager()->notifyMembers(
'EventPreSaveFilter',
'/frontend/',
array(
'fields' => &$fields,
'event' => &$this,
'messages' => &$this->filter_results,
'post_values' => &$post_values,
'entry_id' => $entry_id
)
);
// Logic taken from `event.section.php` to fail should any `$this->filter_results`
// be returned. This delegate can cause the event to exit early.
if (is_array($this->filter_results) && !empty($this->filter_results)) {
$can_proceed = true;
foreach ($this->filter_results as $fr) {
list($name, $status, $message, $attributes) = array_pad($fr, 4, null);
$result->appendChild(
self::buildFilterElement($name, ($status ? 'passed' : 'failed'), $message, $attributes)
);
if ($status === false) {
$can_proceed = false;
}
}
if ($can_proceed !== true) {
$result->appendChild($post_values);
$result->setAttribute('result', 'error');
$result->appendChild(new XMLElement('message', __('Entry encountered errors when saving.'), array(
'message-id' => EventMessages::FILTER_FAILED
)));
}
}
// Reset the filter results to prevent duplicates. RE: #2179
$this->filter_results = array();
return $can_proceed;
} | [
"protected",
"function",
"processPreSaveFilters",
"(",
"XMLElement",
"$",
"result",
",",
"array",
"&",
"$",
"fields",
",",
"XMLElement",
"&",
"$",
"post_values",
",",
"$",
"entry_id",
"=",
"null",
")",
"{",
"$",
"can_proceed",
"=",
"true",
";",
"/**\n * Prior to saving entry from the front-end. This delegate will\n * force the Event to terminate if it populates the `$filter_results`\n * array. All parameters are passed by reference.\n *\n * @delegate EventPreSaveFilter\n * @param string $context\n * '/frontend/'\n * @param array $fields\n * @param Event $this\n * @param array $messages\n * An associative array of array's which contain 4 values,\n * the name of the filter (string), the status (boolean),\n * the message (string) an optionally an associative array\n * of additional attributes to add to the filter element.\n * @param XMLElement $post_values\n * @param integer $entry_id\n * If editing an entry, this parameter will be an integer,\n * otherwise null.\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'EventPreSaveFilter'",
",",
"'/frontend/'",
",",
"array",
"(",
"'fields'",
"=>",
"&",
"$",
"fields",
",",
"'event'",
"=>",
"&",
"$",
"this",
",",
"'messages'",
"=>",
"&",
"$",
"this",
"->",
"filter_results",
",",
"'post_values'",
"=>",
"&",
"$",
"post_values",
",",
"'entry_id'",
"=>",
"$",
"entry_id",
")",
")",
";",
"// Logic taken from `event.section.php` to fail should any `$this->filter_results`",
"// be returned. This delegate can cause the event to exit early.",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"filter_results",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"filter_results",
")",
")",
"{",
"$",
"can_proceed",
"=",
"true",
";",
"foreach",
"(",
"$",
"this",
"->",
"filter_results",
"as",
"$",
"fr",
")",
"{",
"list",
"(",
"$",
"name",
",",
"$",
"status",
",",
"$",
"message",
",",
"$",
"attributes",
")",
"=",
"array_pad",
"(",
"$",
"fr",
",",
"4",
",",
"null",
")",
";",
"$",
"result",
"->",
"appendChild",
"(",
"self",
"::",
"buildFilterElement",
"(",
"$",
"name",
",",
"(",
"$",
"status",
"?",
"'passed'",
":",
"'failed'",
")",
",",
"$",
"message",
",",
"$",
"attributes",
")",
")",
";",
"if",
"(",
"$",
"status",
"===",
"false",
")",
"{",
"$",
"can_proceed",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"$",
"can_proceed",
"!==",
"true",
")",
"{",
"$",
"result",
"->",
"appendChild",
"(",
"$",
"post_values",
")",
";",
"$",
"result",
"->",
"setAttribute",
"(",
"'result'",
",",
"'error'",
")",
";",
"$",
"result",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'message'",
",",
"__",
"(",
"'Entry encountered errors when saving.'",
")",
",",
"array",
"(",
"'message-id'",
"=>",
"EventMessages",
"::",
"FILTER_FAILED",
")",
")",
")",
";",
"}",
"}",
"// Reset the filter results to prevent duplicates. RE: #2179",
"$",
"this",
"->",
"filter_results",
"=",
"array",
"(",
")",
";",
"return",
"$",
"can_proceed",
";",
"}"
] | Processes all extensions attached to the `EventPreSaveFilter` delegate
@uses EventPreSaveFilter
@param XMLElement $result
@param array $fields
@param XMLElement $post_values
@param integer $entry_id
@return boolean | [
"Processes",
"all",
"extensions",
"attached",
"to",
"the",
"EventPreSaveFilter",
"delegate"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/events/class.event.section.php#L432-L497 |
symphonycms/symphony-2 | symphony/lib/toolkit/events/class.event.section.php | SectionEvent.processPostSaveFilters | protected function processPostSaveFilters(XMLElement $result, array $fields, Entry $entry = null)
{
/**
* After saving entry from the front-end. This delegate will not force
* the Events to terminate if it populates the `$filter_results` array.
* Provided with references to this object, the `$_POST` data and also
* the error array
*
* @delegate EventPostSaveFilter
* @param string $context
* '/frontend/'
* @param integer $entry_id
* @param array $fields
* @param Entry $entry
* @param Event $this
* @param array $messages
* An associative array of array's which contain 4 values,
* the name of the filter (string), the status (boolean),
* the message (string) an optionally an associative array
* of additional attributes to add to the filter element.
*/
Symphony::ExtensionManager()->notifyMembers('EventPostSaveFilter', '/frontend/', array(
'entry_id' => $entry->get('id'),
'fields' => $fields,
'entry' => $entry,
'event' => &$this,
'messages' => &$this->filter_results
));
if (is_array($this->filter_results) && !empty($this->filter_results)) {
foreach ($this->filter_results as $fr) {
list($name, $status, $message, $attributes) = $fr;
$result->appendChild(
self::buildFilterElement($name, ($status ? 'passed' : 'failed'), $message, $attributes)
);
}
}
// Reset the filter results to prevent duplicates. RE: #2179
$this->filter_results = array();
return $result;
} | php | protected function processPostSaveFilters(XMLElement $result, array $fields, Entry $entry = null)
{
/**
* After saving entry from the front-end. This delegate will not force
* the Events to terminate if it populates the `$filter_results` array.
* Provided with references to this object, the `$_POST` data and also
* the error array
*
* @delegate EventPostSaveFilter
* @param string $context
* '/frontend/'
* @param integer $entry_id
* @param array $fields
* @param Entry $entry
* @param Event $this
* @param array $messages
* An associative array of array's which contain 4 values,
* the name of the filter (string), the status (boolean),
* the message (string) an optionally an associative array
* of additional attributes to add to the filter element.
*/
Symphony::ExtensionManager()->notifyMembers('EventPostSaveFilter', '/frontend/', array(
'entry_id' => $entry->get('id'),
'fields' => $fields,
'entry' => $entry,
'event' => &$this,
'messages' => &$this->filter_results
));
if (is_array($this->filter_results) && !empty($this->filter_results)) {
foreach ($this->filter_results as $fr) {
list($name, $status, $message, $attributes) = $fr;
$result->appendChild(
self::buildFilterElement($name, ($status ? 'passed' : 'failed'), $message, $attributes)
);
}
}
// Reset the filter results to prevent duplicates. RE: #2179
$this->filter_results = array();
return $result;
} | [
"protected",
"function",
"processPostSaveFilters",
"(",
"XMLElement",
"$",
"result",
",",
"array",
"$",
"fields",
",",
"Entry",
"$",
"entry",
"=",
"null",
")",
"{",
"/**\n * After saving entry from the front-end. This delegate will not force\n * the Events to terminate if it populates the `$filter_results` array.\n * Provided with references to this object, the `$_POST` data and also\n * the error array\n *\n * @delegate EventPostSaveFilter\n * @param string $context\n * '/frontend/'\n * @param integer $entry_id\n * @param array $fields\n * @param Entry $entry\n * @param Event $this\n * @param array $messages\n * An associative array of array's which contain 4 values,\n * the name of the filter (string), the status (boolean),\n * the message (string) an optionally an associative array\n * of additional attributes to add to the filter element.\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'EventPostSaveFilter'",
",",
"'/frontend/'",
",",
"array",
"(",
"'entry_id'",
"=>",
"$",
"entry",
"->",
"get",
"(",
"'id'",
")",
",",
"'fields'",
"=>",
"$",
"fields",
",",
"'entry'",
"=>",
"$",
"entry",
",",
"'event'",
"=>",
"&",
"$",
"this",
",",
"'messages'",
"=>",
"&",
"$",
"this",
"->",
"filter_results",
")",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"filter_results",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"filter_results",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"filter_results",
"as",
"$",
"fr",
")",
"{",
"list",
"(",
"$",
"name",
",",
"$",
"status",
",",
"$",
"message",
",",
"$",
"attributes",
")",
"=",
"$",
"fr",
";",
"$",
"result",
"->",
"appendChild",
"(",
"self",
"::",
"buildFilterElement",
"(",
"$",
"name",
",",
"(",
"$",
"status",
"?",
"'passed'",
":",
"'failed'",
")",
",",
"$",
"message",
",",
"$",
"attributes",
")",
")",
";",
"}",
"}",
"// Reset the filter results to prevent duplicates. RE: #2179",
"$",
"this",
"->",
"filter_results",
"=",
"array",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Processes all extensions attached to the `EventPostSaveFilter` delegate
@uses EventPostSaveFilter
@param XMLElement $result
@param array $fields
@param Entry $entry
@return XMLElement | [
"Processes",
"all",
"extensions",
"attached",
"to",
"the",
"EventPostSaveFilter",
"delegate"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/events/class.event.section.php#L509-L551 |
symphonycms/symphony-2 | symphony/lib/toolkit/events/class.event.section.php | SectionEvent.processSendMailFilter | public function processSendMailFilter(XMLElement $result, array $send_email, array &$fields, Section $section, Entry $entry)
{
$fields['recipient'] = self::replaceFieldToken($send_email['recipient'], $fields);
$fields['recipient'] = preg_split('/\,/i', $fields['recipient'], -1, PREG_SPLIT_NO_EMPTY);
$fields['recipient'] = array_map('trim', $fields['recipient']);
$fields['subject'] = self::replaceFieldToken($send_email['subject'], $fields, __('[Symphony] A new entry was created on %s', array(Symphony::Configuration()->get('sitename', 'general'))));
$fields['body'] = self::replaceFieldToken($send_email['body'], $fields, null, false, false);
$fields['sender-email'] = self::replaceFieldToken($send_email['sender-email'], $fields);
$fields['sender-name'] = self::replaceFieldToken($send_email['sender-name'], $fields);
$fields['reply-to-name'] = self::replaceFieldToken($send_email['reply-to-name'], $fields);
$fields['reply-to-email'] = self::replaceFieldToken($send_email['reply-to-email'], $fields);
$edit_link = SYMPHONY_URL . '/publish/' . $section->get('handle') . '/edit/' . $entry->get('id').'/';
$language = Symphony::Configuration()->get('lang', 'symphony');
$template_path = Event::getNotificationTemplate($language);
$body = sprintf(file_get_contents($template_path), $section->get('name'), $edit_link);
if (is_array($fields['body'])) {
foreach ($fields['body'] as $field_handle => $value) {
$body .= "// $field_handle" . PHP_EOL . $value . PHP_EOL . PHP_EOL;
}
} else {
$body .= $fields['body'];
}
// Loop over all the recipients and attempt to send them an email
// Errors will be appended to the Event XML
$errors = array();
foreach ($fields['recipient'] as $recipient) {
$author = AuthorManager::fetchByUsername($recipient);
if (empty($author)) {
$errors['recipient'][$recipient] = __('Recipient not found');
continue;
}
$email = Email::create();
// Exceptions are also thrown in the settings functions, not only in the send function.
// Those Exceptions should be caught too.
try {
$email->recipients = array(
$author->get('first_name') => $author->get('email')
);
if ($fields['sender-name'] != null) {
$email->sender_name = $fields['sender-name'];
}
if ($fields['sender-email'] != null) {
$email->sender_email_address = $fields['sender-email'];
}
if ($fields['reply-to-name'] != null) {
$email->reply_to_name = $fields['reply-to-name'];
}
if ($fields['reply-to-email'] != null) {
$email->reply_to_email_address = $fields['reply-to-email'];
}
$email->text_plain = str_replace('<!-- RECIPIENT NAME -->', $author->get('first_name'), $body);
$email->subject = $fields['subject'];
$email->send();
} catch (EmailValidationException $e) {
$errors['address'][$author->get('email')] = $e->getMessage();
// The current error array does not permit custom tags.
// Therefore, it is impossible to set a "proper" error message.
// Will return the failed email address instead.
} catch (EmailGatewayException $e) {
$errors['gateway'][$author->get('email')] = $e->getMessage();
// Because we don't want symphony to break because it can not send emails,
// all exceptions are logged silently.
// Any custom event can change this behaviour.
} catch (EmailException $e) {
$errors['email'][$author->get('email')] = $e->getMessage();
}
}
// If there were errors, output them to the event
if (!empty($errors)) {
$xml = self::buildFilterElement('send-email', 'failed');
foreach ($errors as $type => $messages) {
$xType = new XMLElement('error');
$xType->setAttribute('error-type', $type);
foreach ($messages as $recipient => $message) {
$xType->appendChild(
new XMLElement('message', General::wrapInCDATA($message), array(
'recipient' => $recipient
))
);
}
$xml->appendChild($xType);
}
$result->appendChild($xml);
} else {
$result->appendChild(
self::buildFilterElement('send-email', 'passed')
);
}
return $result;
} | php | public function processSendMailFilter(XMLElement $result, array $send_email, array &$fields, Section $section, Entry $entry)
{
$fields['recipient'] = self::replaceFieldToken($send_email['recipient'], $fields);
$fields['recipient'] = preg_split('/\,/i', $fields['recipient'], -1, PREG_SPLIT_NO_EMPTY);
$fields['recipient'] = array_map('trim', $fields['recipient']);
$fields['subject'] = self::replaceFieldToken($send_email['subject'], $fields, __('[Symphony] A new entry was created on %s', array(Symphony::Configuration()->get('sitename', 'general'))));
$fields['body'] = self::replaceFieldToken($send_email['body'], $fields, null, false, false);
$fields['sender-email'] = self::replaceFieldToken($send_email['sender-email'], $fields);
$fields['sender-name'] = self::replaceFieldToken($send_email['sender-name'], $fields);
$fields['reply-to-name'] = self::replaceFieldToken($send_email['reply-to-name'], $fields);
$fields['reply-to-email'] = self::replaceFieldToken($send_email['reply-to-email'], $fields);
$edit_link = SYMPHONY_URL . '/publish/' . $section->get('handle') . '/edit/' . $entry->get('id').'/';
$language = Symphony::Configuration()->get('lang', 'symphony');
$template_path = Event::getNotificationTemplate($language);
$body = sprintf(file_get_contents($template_path), $section->get('name'), $edit_link);
if (is_array($fields['body'])) {
foreach ($fields['body'] as $field_handle => $value) {
$body .= "// $field_handle" . PHP_EOL . $value . PHP_EOL . PHP_EOL;
}
} else {
$body .= $fields['body'];
}
// Loop over all the recipients and attempt to send them an email
// Errors will be appended to the Event XML
$errors = array();
foreach ($fields['recipient'] as $recipient) {
$author = AuthorManager::fetchByUsername($recipient);
if (empty($author)) {
$errors['recipient'][$recipient] = __('Recipient not found');
continue;
}
$email = Email::create();
// Exceptions are also thrown in the settings functions, not only in the send function.
// Those Exceptions should be caught too.
try {
$email->recipients = array(
$author->get('first_name') => $author->get('email')
);
if ($fields['sender-name'] != null) {
$email->sender_name = $fields['sender-name'];
}
if ($fields['sender-email'] != null) {
$email->sender_email_address = $fields['sender-email'];
}
if ($fields['reply-to-name'] != null) {
$email->reply_to_name = $fields['reply-to-name'];
}
if ($fields['reply-to-email'] != null) {
$email->reply_to_email_address = $fields['reply-to-email'];
}
$email->text_plain = str_replace('<!-- RECIPIENT NAME -->', $author->get('first_name'), $body);
$email->subject = $fields['subject'];
$email->send();
} catch (EmailValidationException $e) {
$errors['address'][$author->get('email')] = $e->getMessage();
// The current error array does not permit custom tags.
// Therefore, it is impossible to set a "proper" error message.
// Will return the failed email address instead.
} catch (EmailGatewayException $e) {
$errors['gateway'][$author->get('email')] = $e->getMessage();
// Because we don't want symphony to break because it can not send emails,
// all exceptions are logged silently.
// Any custom event can change this behaviour.
} catch (EmailException $e) {
$errors['email'][$author->get('email')] = $e->getMessage();
}
}
// If there were errors, output them to the event
if (!empty($errors)) {
$xml = self::buildFilterElement('send-email', 'failed');
foreach ($errors as $type => $messages) {
$xType = new XMLElement('error');
$xType->setAttribute('error-type', $type);
foreach ($messages as $recipient => $message) {
$xType->appendChild(
new XMLElement('message', General::wrapInCDATA($message), array(
'recipient' => $recipient
))
);
}
$xml->appendChild($xType);
}
$result->appendChild($xml);
} else {
$result->appendChild(
self::buildFilterElement('send-email', 'passed')
);
}
return $result;
} | [
"public",
"function",
"processSendMailFilter",
"(",
"XMLElement",
"$",
"result",
",",
"array",
"$",
"send_email",
",",
"array",
"&",
"$",
"fields",
",",
"Section",
"$",
"section",
",",
"Entry",
"$",
"entry",
")",
"{",
"$",
"fields",
"[",
"'recipient'",
"]",
"=",
"self",
"::",
"replaceFieldToken",
"(",
"$",
"send_email",
"[",
"'recipient'",
"]",
",",
"$",
"fields",
")",
";",
"$",
"fields",
"[",
"'recipient'",
"]",
"=",
"preg_split",
"(",
"'/\\,/i'",
",",
"$",
"fields",
"[",
"'recipient'",
"]",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"$",
"fields",
"[",
"'recipient'",
"]",
"=",
"array_map",
"(",
"'trim'",
",",
"$",
"fields",
"[",
"'recipient'",
"]",
")",
";",
"$",
"fields",
"[",
"'subject'",
"]",
"=",
"self",
"::",
"replaceFieldToken",
"(",
"$",
"send_email",
"[",
"'subject'",
"]",
",",
"$",
"fields",
",",
"__",
"(",
"'[Symphony] A new entry was created on %s'",
",",
"array",
"(",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'sitename'",
",",
"'general'",
")",
")",
")",
")",
";",
"$",
"fields",
"[",
"'body'",
"]",
"=",
"self",
"::",
"replaceFieldToken",
"(",
"$",
"send_email",
"[",
"'body'",
"]",
",",
"$",
"fields",
",",
"null",
",",
"false",
",",
"false",
")",
";",
"$",
"fields",
"[",
"'sender-email'",
"]",
"=",
"self",
"::",
"replaceFieldToken",
"(",
"$",
"send_email",
"[",
"'sender-email'",
"]",
",",
"$",
"fields",
")",
";",
"$",
"fields",
"[",
"'sender-name'",
"]",
"=",
"self",
"::",
"replaceFieldToken",
"(",
"$",
"send_email",
"[",
"'sender-name'",
"]",
",",
"$",
"fields",
")",
";",
"$",
"fields",
"[",
"'reply-to-name'",
"]",
"=",
"self",
"::",
"replaceFieldToken",
"(",
"$",
"send_email",
"[",
"'reply-to-name'",
"]",
",",
"$",
"fields",
")",
";",
"$",
"fields",
"[",
"'reply-to-email'",
"]",
"=",
"self",
"::",
"replaceFieldToken",
"(",
"$",
"send_email",
"[",
"'reply-to-email'",
"]",
",",
"$",
"fields",
")",
";",
"$",
"edit_link",
"=",
"SYMPHONY_URL",
".",
"'/publish/'",
".",
"$",
"section",
"->",
"get",
"(",
"'handle'",
")",
".",
"'/edit/'",
".",
"$",
"entry",
"->",
"get",
"(",
"'id'",
")",
".",
"'/'",
";",
"$",
"language",
"=",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'lang'",
",",
"'symphony'",
")",
";",
"$",
"template_path",
"=",
"Event",
"::",
"getNotificationTemplate",
"(",
"$",
"language",
")",
";",
"$",
"body",
"=",
"sprintf",
"(",
"file_get_contents",
"(",
"$",
"template_path",
")",
",",
"$",
"section",
"->",
"get",
"(",
"'name'",
")",
",",
"$",
"edit_link",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"fields",
"[",
"'body'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"fields",
"[",
"'body'",
"]",
"as",
"$",
"field_handle",
"=>",
"$",
"value",
")",
"{",
"$",
"body",
".=",
"\"// $field_handle\"",
".",
"PHP_EOL",
".",
"$",
"value",
".",
"PHP_EOL",
".",
"PHP_EOL",
";",
"}",
"}",
"else",
"{",
"$",
"body",
".=",
"$",
"fields",
"[",
"'body'",
"]",
";",
"}",
"// Loop over all the recipients and attempt to send them an email",
"// Errors will be appended to the Event XML",
"$",
"errors",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"[",
"'recipient'",
"]",
"as",
"$",
"recipient",
")",
"{",
"$",
"author",
"=",
"AuthorManager",
"::",
"fetchByUsername",
"(",
"$",
"recipient",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"author",
")",
")",
"{",
"$",
"errors",
"[",
"'recipient'",
"]",
"[",
"$",
"recipient",
"]",
"=",
"__",
"(",
"'Recipient not found'",
")",
";",
"continue",
";",
"}",
"$",
"email",
"=",
"Email",
"::",
"create",
"(",
")",
";",
"// Exceptions are also thrown in the settings functions, not only in the send function.",
"// Those Exceptions should be caught too.",
"try",
"{",
"$",
"email",
"->",
"recipients",
"=",
"array",
"(",
"$",
"author",
"->",
"get",
"(",
"'first_name'",
")",
"=>",
"$",
"author",
"->",
"get",
"(",
"'email'",
")",
")",
";",
"if",
"(",
"$",
"fields",
"[",
"'sender-name'",
"]",
"!=",
"null",
")",
"{",
"$",
"email",
"->",
"sender_name",
"=",
"$",
"fields",
"[",
"'sender-name'",
"]",
";",
"}",
"if",
"(",
"$",
"fields",
"[",
"'sender-email'",
"]",
"!=",
"null",
")",
"{",
"$",
"email",
"->",
"sender_email_address",
"=",
"$",
"fields",
"[",
"'sender-email'",
"]",
";",
"}",
"if",
"(",
"$",
"fields",
"[",
"'reply-to-name'",
"]",
"!=",
"null",
")",
"{",
"$",
"email",
"->",
"reply_to_name",
"=",
"$",
"fields",
"[",
"'reply-to-name'",
"]",
";",
"}",
"if",
"(",
"$",
"fields",
"[",
"'reply-to-email'",
"]",
"!=",
"null",
")",
"{",
"$",
"email",
"->",
"reply_to_email_address",
"=",
"$",
"fields",
"[",
"'reply-to-email'",
"]",
";",
"}",
"$",
"email",
"->",
"text_plain",
"=",
"str_replace",
"(",
"'<!-- RECIPIENT NAME -->'",
",",
"$",
"author",
"->",
"get",
"(",
"'first_name'",
")",
",",
"$",
"body",
")",
";",
"$",
"email",
"->",
"subject",
"=",
"$",
"fields",
"[",
"'subject'",
"]",
";",
"$",
"email",
"->",
"send",
"(",
")",
";",
"}",
"catch",
"(",
"EmailValidationException",
"$",
"e",
")",
"{",
"$",
"errors",
"[",
"'address'",
"]",
"[",
"$",
"author",
"->",
"get",
"(",
"'email'",
")",
"]",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"// The current error array does not permit custom tags.",
"// Therefore, it is impossible to set a \"proper\" error message.",
"// Will return the failed email address instead.",
"}",
"catch",
"(",
"EmailGatewayException",
"$",
"e",
")",
"{",
"$",
"errors",
"[",
"'gateway'",
"]",
"[",
"$",
"author",
"->",
"get",
"(",
"'email'",
")",
"]",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"// Because we don't want symphony to break because it can not send emails,",
"// all exceptions are logged silently.",
"// Any custom event can change this behaviour.",
"}",
"catch",
"(",
"EmailException",
"$",
"e",
")",
"{",
"$",
"errors",
"[",
"'email'",
"]",
"[",
"$",
"author",
"->",
"get",
"(",
"'email'",
")",
"]",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"}",
"// If there were errors, output them to the event",
"if",
"(",
"!",
"empty",
"(",
"$",
"errors",
")",
")",
"{",
"$",
"xml",
"=",
"self",
"::",
"buildFilterElement",
"(",
"'send-email'",
",",
"'failed'",
")",
";",
"foreach",
"(",
"$",
"errors",
"as",
"$",
"type",
"=>",
"$",
"messages",
")",
"{",
"$",
"xType",
"=",
"new",
"XMLElement",
"(",
"'error'",
")",
";",
"$",
"xType",
"->",
"setAttribute",
"(",
"'error-type'",
",",
"$",
"type",
")",
";",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"recipient",
"=>",
"$",
"message",
")",
"{",
"$",
"xType",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'message'",
",",
"General",
"::",
"wrapInCDATA",
"(",
"$",
"message",
")",
",",
"array",
"(",
"'recipient'",
"=>",
"$",
"recipient",
")",
")",
")",
";",
"}",
"$",
"xml",
"->",
"appendChild",
"(",
"$",
"xType",
")",
";",
"}",
"$",
"result",
"->",
"appendChild",
"(",
"$",
"xml",
")",
";",
"}",
"else",
"{",
"$",
"result",
"->",
"appendChild",
"(",
"self",
"::",
"buildFilterElement",
"(",
"'send-email'",
",",
"'passed'",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | This function handles the Send Mail filter which will send an email
to each specified recipient informing them that an Entry has been
created.
@param XMLElement $result
The XMLElement of the XML that is going to be returned as part
of this event to the page.
@param array $send_email
Associative array of `send-mail` parameters.* Associative array of `send-mail` parameters.
@param array $fields
Array of post data to extract the values from
@param Section $section
This current Entry that has just been updated or created
@param Entry $entry
@throws Exception
@return XMLElement
The modified `$result` with the results of the filter. | [
"This",
"function",
"handles",
"the",
"Send",
"Mail",
"filter",
"which",
"will",
"send",
"an",
"email",
"to",
"each",
"specified",
"recipient",
"informing",
"them",
"that",
"an",
"Entry",
"has",
"been",
"created",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/events/class.event.section.php#L633-L744 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.date.php | FieldDate.parseDate | public static function parseDate($string, $direction = null, $equal_to = false)
{
$parts = array(
'start' => null,
'end' => null
);
// Year
if (preg_match('/^\d{1,4}$/', $string, $matches)) {
$year = current($matches);
$parts['start'] = "$year-01-01 00:00:00";
$parts['end'] = "$year-12-31 23:59:59";
$parts = self::isEqualTo($parts, $direction, $equal_to);
// Year/Month/Day/Time
} elseif (preg_match('/^\d{1,4}[-\/]\d{1,2}[-\/]\d{1,2}\s\d{1,2}:\d{2}/', $string, $matches)) {
// Handles the case of `to` filters
if ($equal_to || is_null($direction)) {
$parts['start'] = $parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string);
} else {
$parts['start'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' - 1 second');
$parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' + 1 second');
}
// Year/Month/Day
} elseif (preg_match('/^\d{1,4}[-\/]\d{1,2}[-\/]\d{1,2}$/', $string, $matches)) {
$year_month_day = current($matches);
$parts['start'] = "$year_month_day 00:00:00";
$parts['end'] = "$year_month_day 23:59:59";
$parts = self::isEqualTo($parts, $direction, $equal_to);
// Year/Month
} elseif (preg_match('/^\d{1,4}[-\/]\d{1,2}$/', $string, $matches)) {
$year_month = current($matches);
$parts['start'] = "$year_month-01 00:00:00";
$parts['end'] = DateTimeObj::get('Y-m-t', $parts['start']) . " 23:59:59";
$parts = self::isEqualTo($parts, $direction, $equal_to);
// Relative date, aka '+ 3 weeks'
} else {
// Handles the case of `to` filters
if ($equal_to || is_null($direction)) {
$parts['start'] = $parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string);
} else {
$parts['start'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' - 1 second');
$parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' + 1 second');
}
}
return $parts;
} | php | public static function parseDate($string, $direction = null, $equal_to = false)
{
$parts = array(
'start' => null,
'end' => null
);
// Year
if (preg_match('/^\d{1,4}$/', $string, $matches)) {
$year = current($matches);
$parts['start'] = "$year-01-01 00:00:00";
$parts['end'] = "$year-12-31 23:59:59";
$parts = self::isEqualTo($parts, $direction, $equal_to);
// Year/Month/Day/Time
} elseif (preg_match('/^\d{1,4}[-\/]\d{1,2}[-\/]\d{1,2}\s\d{1,2}:\d{2}/', $string, $matches)) {
// Handles the case of `to` filters
if ($equal_to || is_null($direction)) {
$parts['start'] = $parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string);
} else {
$parts['start'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' - 1 second');
$parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' + 1 second');
}
// Year/Month/Day
} elseif (preg_match('/^\d{1,4}[-\/]\d{1,2}[-\/]\d{1,2}$/', $string, $matches)) {
$year_month_day = current($matches);
$parts['start'] = "$year_month_day 00:00:00";
$parts['end'] = "$year_month_day 23:59:59";
$parts = self::isEqualTo($parts, $direction, $equal_to);
// Year/Month
} elseif (preg_match('/^\d{1,4}[-\/]\d{1,2}$/', $string, $matches)) {
$year_month = current($matches);
$parts['start'] = "$year_month-01 00:00:00";
$parts['end'] = DateTimeObj::get('Y-m-t', $parts['start']) . " 23:59:59";
$parts = self::isEqualTo($parts, $direction, $equal_to);
// Relative date, aka '+ 3 weeks'
} else {
// Handles the case of `to` filters
if ($equal_to || is_null($direction)) {
$parts['start'] = $parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string);
} else {
$parts['start'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' - 1 second');
$parts['end'] = DateTimeObj::get('Y-m-d H:i:s', $string . ' + 1 second');
}
}
return $parts;
} | [
"public",
"static",
"function",
"parseDate",
"(",
"$",
"string",
",",
"$",
"direction",
"=",
"null",
",",
"$",
"equal_to",
"=",
"false",
")",
"{",
"$",
"parts",
"=",
"array",
"(",
"'start'",
"=>",
"null",
",",
"'end'",
"=>",
"null",
")",
";",
"// Year",
"if",
"(",
"preg_match",
"(",
"'/^\\d{1,4}$/'",
",",
"$",
"string",
",",
"$",
"matches",
")",
")",
"{",
"$",
"year",
"=",
"current",
"(",
"$",
"matches",
")",
";",
"$",
"parts",
"[",
"'start'",
"]",
"=",
"\"$year-01-01 00:00:00\"",
";",
"$",
"parts",
"[",
"'end'",
"]",
"=",
"\"$year-12-31 23:59:59\"",
";",
"$",
"parts",
"=",
"self",
"::",
"isEqualTo",
"(",
"$",
"parts",
",",
"$",
"direction",
",",
"$",
"equal_to",
")",
";",
"// Year/Month/Day/Time",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/^\\d{1,4}[-\\/]\\d{1,2}[-\\/]\\d{1,2}\\s\\d{1,2}:\\d{2}/'",
",",
"$",
"string",
",",
"$",
"matches",
")",
")",
"{",
"// Handles the case of `to` filters",
"if",
"(",
"$",
"equal_to",
"||",
"is_null",
"(",
"$",
"direction",
")",
")",
"{",
"$",
"parts",
"[",
"'start'",
"]",
"=",
"$",
"parts",
"[",
"'end'",
"]",
"=",
"DateTimeObj",
"::",
"get",
"(",
"'Y-m-d H:i:s'",
",",
"$",
"string",
")",
";",
"}",
"else",
"{",
"$",
"parts",
"[",
"'start'",
"]",
"=",
"DateTimeObj",
"::",
"get",
"(",
"'Y-m-d H:i:s'",
",",
"$",
"string",
".",
"' - 1 second'",
")",
";",
"$",
"parts",
"[",
"'end'",
"]",
"=",
"DateTimeObj",
"::",
"get",
"(",
"'Y-m-d H:i:s'",
",",
"$",
"string",
".",
"' + 1 second'",
")",
";",
"}",
"// Year/Month/Day",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/^\\d{1,4}[-\\/]\\d{1,2}[-\\/]\\d{1,2}$/'",
",",
"$",
"string",
",",
"$",
"matches",
")",
")",
"{",
"$",
"year_month_day",
"=",
"current",
"(",
"$",
"matches",
")",
";",
"$",
"parts",
"[",
"'start'",
"]",
"=",
"\"$year_month_day 00:00:00\"",
";",
"$",
"parts",
"[",
"'end'",
"]",
"=",
"\"$year_month_day 23:59:59\"",
";",
"$",
"parts",
"=",
"self",
"::",
"isEqualTo",
"(",
"$",
"parts",
",",
"$",
"direction",
",",
"$",
"equal_to",
")",
";",
"// Year/Month",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/^\\d{1,4}[-\\/]\\d{1,2}$/'",
",",
"$",
"string",
",",
"$",
"matches",
")",
")",
"{",
"$",
"year_month",
"=",
"current",
"(",
"$",
"matches",
")",
";",
"$",
"parts",
"[",
"'start'",
"]",
"=",
"\"$year_month-01 00:00:00\"",
";",
"$",
"parts",
"[",
"'end'",
"]",
"=",
"DateTimeObj",
"::",
"get",
"(",
"'Y-m-t'",
",",
"$",
"parts",
"[",
"'start'",
"]",
")",
".",
"\" 23:59:59\"",
";",
"$",
"parts",
"=",
"self",
"::",
"isEqualTo",
"(",
"$",
"parts",
",",
"$",
"direction",
",",
"$",
"equal_to",
")",
";",
"// Relative date, aka '+ 3 weeks'",
"}",
"else",
"{",
"// Handles the case of `to` filters",
"if",
"(",
"$",
"equal_to",
"||",
"is_null",
"(",
"$",
"direction",
")",
")",
"{",
"$",
"parts",
"[",
"'start'",
"]",
"=",
"$",
"parts",
"[",
"'end'",
"]",
"=",
"DateTimeObj",
"::",
"get",
"(",
"'Y-m-d H:i:s'",
",",
"$",
"string",
")",
";",
"}",
"else",
"{",
"$",
"parts",
"[",
"'start'",
"]",
"=",
"DateTimeObj",
"::",
"get",
"(",
"'Y-m-d H:i:s'",
",",
"$",
"string",
".",
"' - 1 second'",
")",
";",
"$",
"parts",
"[",
"'end'",
"]",
"=",
"DateTimeObj",
"::",
"get",
"(",
"'Y-m-d H:i:s'",
",",
"$",
"string",
".",
"' + 1 second'",
")",
";",
"}",
"}",
"return",
"$",
"parts",
";",
"}"
] | Given a string, this function builds the range of dates that match it.
The strings should be in ISO8601 style format, or a natural date, such
as 'last week' etc.
@since Symphony 2.2.2
@param array $string
The date string to be parsed
@param string $direction
Either later or earlier, defaults to null.
@param boolean $equal_to
If the filter is equal_to or not, defaults to false.
@return array
An associative array containing a date in ISO8601 format (or natural)
with two keys, start and end. | [
"Given",
"a",
"string",
"this",
"function",
"builds",
"the",
"range",
"of",
"dates",
"that",
"match",
"it",
".",
"The",
"strings",
"should",
"be",
"in",
"ISO8601",
"style",
"format",
"or",
"a",
"natural",
"date",
"such",
"as",
"last",
"week",
"etc",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.date.php#L162-L219 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.date.php | FieldDate.isEqualTo | public static function isEqualTo(array $parts, $direction, $equal_to = false)
{
if (!$equal_to) {
return $parts;
}
if ($direction == 'later') {
$parts['end'] = $parts['start'];
} else {
$parts['start'] = $parts['end'];
}
return $parts;
} | php | public static function isEqualTo(array $parts, $direction, $equal_to = false)
{
if (!$equal_to) {
return $parts;
}
if ($direction == 'later') {
$parts['end'] = $parts['start'];
} else {
$parts['start'] = $parts['end'];
}
return $parts;
} | [
"public",
"static",
"function",
"isEqualTo",
"(",
"array",
"$",
"parts",
",",
"$",
"direction",
",",
"$",
"equal_to",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"equal_to",
")",
"{",
"return",
"$",
"parts",
";",
"}",
"if",
"(",
"$",
"direction",
"==",
"'later'",
")",
"{",
"$",
"parts",
"[",
"'end'",
"]",
"=",
"$",
"parts",
"[",
"'start'",
"]",
";",
"}",
"else",
"{",
"$",
"parts",
"[",
"'start'",
"]",
"=",
"$",
"parts",
"[",
"'end'",
"]",
";",
"}",
"return",
"$",
"parts",
";",
"}"
] | Builds the correct date array depending if the filter should include
the filter as well, ie. later than 2011, is effectively the same as
equal to or later than 2012.
@since Symphony 2.2.2
@param array $parts
An associative array containing a date in ISO8601 format (or natural)
with two keys, start and end.
@param string $direction
Either later or earlier, defaults to null.
@param boolean $equal_to
If the filter is equal_to or not, defaults to false.
@return array | [
"Builds",
"the",
"correct",
"date",
"array",
"depending",
"if",
"the",
"filter",
"should",
"include",
"the",
"filter",
"as",
"well",
"ie",
".",
"later",
"than",
"2011",
"is",
"effectively",
"the",
"same",
"as",
"equal",
"to",
"or",
"later",
"than",
"2012",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.date.php#L236-L249 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.date.php | FieldDate.formatDate | public function formatDate($date)
{
// Get format
$format = 'date_format';
if ($this->get('time') === 'yes') {
$format = 'datetime_format';
}
return DateTimeObj::format($date, DateTimeObj::getSetting($format));
} | php | public function formatDate($date)
{
// Get format
$format = 'date_format';
if ($this->get('time') === 'yes') {
$format = 'datetime_format';
}
return DateTimeObj::format($date, DateTimeObj::getSetting($format));
} | [
"public",
"function",
"formatDate",
"(",
"$",
"date",
")",
"{",
"// Get format",
"$",
"format",
"=",
"'date_format'",
";",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'time'",
")",
"===",
"'yes'",
")",
"{",
"$",
"format",
"=",
"'datetime_format'",
";",
"}",
"return",
"DateTimeObj",
"::",
"format",
"(",
"$",
"date",
",",
"DateTimeObj",
"::",
"getSetting",
"(",
"$",
"format",
")",
")",
";",
"}"
] | Format the $data parameter according to this field's settings.
@since Symphony 2.6.0
@param array $date
The date to format
@return string | [
"Format",
"the",
"$data",
"parameter",
"according",
"to",
"this",
"field",
"s",
"settings",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.date.php#L388-L396 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.date.php | FieldDate.displayPublishPanel | public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null)
{
$name = $this->get('element_name');
$value = null;
// New entry
if (empty($data) && is_null($flagWithError) && !is_null($this->get('pre_populate'))) {
$prepopulate = $this->get('pre_populate');
$date = self::parseDate($prepopulate);
$date = $date['start'];
$value = $this->formatDate($date);
// Error entry, display original data
} elseif (!is_null($flagWithError)) {
$value = $_POST['fields'][$name];
// Empty entry
} elseif (isset($data['value'])) {
$value = $this->formatDate($data['value']);
}
$label = Widget::Label($this->get('label'));
if ($this->get('required') !== 'yes') {
$label->appendChild(new XMLElement('i', __('Optional')));
}
// Input
$label->appendChild(Widget::Input("fields{$fieldnamePrefix}[{$name}]", $value));
$label->setAttribute('class', 'date');
// Calendar
if ($this->get('calendar') === 'yes') {
$wrapper->setAttribute('data-interactive', 'data-interactive');
$ul = new XMLElement('ul');
$ul->setAttribute('class', 'suggestions');
$ul->setAttribute('data-field-id', $this->get('id'));
$ul->setAttribute('data-search-types', 'date');
$calendar = new XMLElement('li');
$calendar->appendChild(Widget::Calendar(($this->get('time') === 'yes')));
$ul->appendChild($calendar);
$label->appendChild($ul);
}
// Wrap label in error
if (!is_null($flagWithError)) {
$label = Widget::Error($label, $flagWithError);
}
$wrapper->appendChild($label);
} | php | public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null)
{
$name = $this->get('element_name');
$value = null;
// New entry
if (empty($data) && is_null($flagWithError) && !is_null($this->get('pre_populate'))) {
$prepopulate = $this->get('pre_populate');
$date = self::parseDate($prepopulate);
$date = $date['start'];
$value = $this->formatDate($date);
// Error entry, display original data
} elseif (!is_null($flagWithError)) {
$value = $_POST['fields'][$name];
// Empty entry
} elseif (isset($data['value'])) {
$value = $this->formatDate($data['value']);
}
$label = Widget::Label($this->get('label'));
if ($this->get('required') !== 'yes') {
$label->appendChild(new XMLElement('i', __('Optional')));
}
// Input
$label->appendChild(Widget::Input("fields{$fieldnamePrefix}[{$name}]", $value));
$label->setAttribute('class', 'date');
// Calendar
if ($this->get('calendar') === 'yes') {
$wrapper->setAttribute('data-interactive', 'data-interactive');
$ul = new XMLElement('ul');
$ul->setAttribute('class', 'suggestions');
$ul->setAttribute('data-field-id', $this->get('id'));
$ul->setAttribute('data-search-types', 'date');
$calendar = new XMLElement('li');
$calendar->appendChild(Widget::Calendar(($this->get('time') === 'yes')));
$ul->appendChild($calendar);
$label->appendChild($ul);
}
// Wrap label in error
if (!is_null($flagWithError)) {
$label = Widget::Error($label, $flagWithError);
}
$wrapper->appendChild($label);
} | [
"public",
"function",
"displayPublishPanel",
"(",
"XMLElement",
"&",
"$",
"wrapper",
",",
"$",
"data",
"=",
"null",
",",
"$",
"flagWithError",
"=",
"null",
",",
"$",
"fieldnamePrefix",
"=",
"null",
",",
"$",
"fieldnamePostfix",
"=",
"null",
",",
"$",
"entry_id",
"=",
"null",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"get",
"(",
"'element_name'",
")",
";",
"$",
"value",
"=",
"null",
";",
"// New entry",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
"&&",
"is_null",
"(",
"$",
"flagWithError",
")",
"&&",
"!",
"is_null",
"(",
"$",
"this",
"->",
"get",
"(",
"'pre_populate'",
")",
")",
")",
"{",
"$",
"prepopulate",
"=",
"$",
"this",
"->",
"get",
"(",
"'pre_populate'",
")",
";",
"$",
"date",
"=",
"self",
"::",
"parseDate",
"(",
"$",
"prepopulate",
")",
";",
"$",
"date",
"=",
"$",
"date",
"[",
"'start'",
"]",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"formatDate",
"(",
"$",
"date",
")",
";",
"// Error entry, display original data",
"}",
"elseif",
"(",
"!",
"is_null",
"(",
"$",
"flagWithError",
")",
")",
"{",
"$",
"value",
"=",
"$",
"_POST",
"[",
"'fields'",
"]",
"[",
"$",
"name",
"]",
";",
"// Empty entry",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"formatDate",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
";",
"}",
"$",
"label",
"=",
"Widget",
"::",
"Label",
"(",
"$",
"this",
"->",
"get",
"(",
"'label'",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'required'",
")",
"!==",
"'yes'",
")",
"{",
"$",
"label",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'i'",
",",
"__",
"(",
"'Optional'",
")",
")",
")",
";",
"}",
"// Input",
"$",
"label",
"->",
"appendChild",
"(",
"Widget",
"::",
"Input",
"(",
"\"fields{$fieldnamePrefix}[{$name}]\"",
",",
"$",
"value",
")",
")",
";",
"$",
"label",
"->",
"setAttribute",
"(",
"'class'",
",",
"'date'",
")",
";",
"// Calendar",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'calendar'",
")",
"===",
"'yes'",
")",
"{",
"$",
"wrapper",
"->",
"setAttribute",
"(",
"'data-interactive'",
",",
"'data-interactive'",
")",
";",
"$",
"ul",
"=",
"new",
"XMLElement",
"(",
"'ul'",
")",
";",
"$",
"ul",
"->",
"setAttribute",
"(",
"'class'",
",",
"'suggestions'",
")",
";",
"$",
"ul",
"->",
"setAttribute",
"(",
"'data-field-id'",
",",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"$",
"ul",
"->",
"setAttribute",
"(",
"'data-search-types'",
",",
"'date'",
")",
";",
"$",
"calendar",
"=",
"new",
"XMLElement",
"(",
"'li'",
")",
";",
"$",
"calendar",
"->",
"appendChild",
"(",
"Widget",
"::",
"Calendar",
"(",
"(",
"$",
"this",
"->",
"get",
"(",
"'time'",
")",
"===",
"'yes'",
")",
")",
")",
";",
"$",
"ul",
"->",
"appendChild",
"(",
"$",
"calendar",
")",
";",
"$",
"label",
"->",
"appendChild",
"(",
"$",
"ul",
")",
";",
"}",
"// Wrap label in error",
"if",
"(",
"!",
"is_null",
"(",
"$",
"flagWithError",
")",
")",
"{",
"$",
"label",
"=",
"Widget",
"::",
"Error",
"(",
"$",
"label",
",",
"$",
"flagWithError",
")",
";",
"}",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"label",
")",
";",
"}"
] | /*-------------------------------------------------------------------------
Publish:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Publish",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.date.php#L456-L509 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.date.php | FieldDate.appendFormattedElement | public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null)
{
if (isset($data['value'])) {
// Get date
if (is_array($data['value'])) {
$date = current($data['value']);
} else {
$date = $data['value'];
}
$wrapper->appendChild(General::createXMLDateObject($date, $this->get('element_name')));
}
} | php | public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null)
{
if (isset($data['value'])) {
// Get date
if (is_array($data['value'])) {
$date = current($data['value']);
} else {
$date = $data['value'];
}
$wrapper->appendChild(General::createXMLDateObject($date, $this->get('element_name')));
}
} | [
"public",
"function",
"appendFormattedElement",
"(",
"XMLElement",
"&",
"$",
"wrapper",
",",
"$",
"data",
",",
"$",
"encode",
"=",
"false",
",",
"$",
"mode",
"=",
"null",
",",
"$",
"entry_id",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
")",
"{",
"// Get date",
"if",
"(",
"is_array",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"date",
"=",
"current",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"date",
"=",
"$",
"data",
"[",
"'value'",
"]",
";",
"}",
"$",
"wrapper",
"->",
"appendChild",
"(",
"General",
"::",
"createXMLDateObject",
"(",
"$",
"date",
",",
"$",
"this",
"->",
"get",
"(",
"'element_name'",
")",
")",
")",
";",
"}",
"}"
] | /*-------------------------------------------------------------------------
Output:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Output",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.date.php#L570-L583 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.date.php | FieldDate.prepareExportValue | public function prepareExportValue($data, $mode, $entry_id = null)
{
$modes = (object)$this->getExportModes();
if ($mode === $modes->getValue) {
return $this->formatDate(
isset($data['value']) ? $data['value'] : null
);
}
if ($mode === $modes->getObject) {
$timezone = Symphony::Configuration()->get('timezone', 'region');
$date = new DateTime(
isset($data['value']) ? $data['value'] : 'now'
);
$date->setTimezone(new DateTimeZone($timezone));
return $date;
} elseif ($mode === $modes->getPostdata) {
return isset($data['value'])
? $data['value']
: null;
}
return null;
} | php | public function prepareExportValue($data, $mode, $entry_id = null)
{
$modes = (object)$this->getExportModes();
if ($mode === $modes->getValue) {
return $this->formatDate(
isset($data['value']) ? $data['value'] : null
);
}
if ($mode === $modes->getObject) {
$timezone = Symphony::Configuration()->get('timezone', 'region');
$date = new DateTime(
isset($data['value']) ? $data['value'] : 'now'
);
$date->setTimezone(new DateTimeZone($timezone));
return $date;
} elseif ($mode === $modes->getPostdata) {
return isset($data['value'])
? $data['value']
: null;
}
return null;
} | [
"public",
"function",
"prepareExportValue",
"(",
"$",
"data",
",",
"$",
"mode",
",",
"$",
"entry_id",
"=",
"null",
")",
"{",
"$",
"modes",
"=",
"(",
"object",
")",
"$",
"this",
"->",
"getExportModes",
"(",
")",
";",
"if",
"(",
"$",
"mode",
"===",
"$",
"modes",
"->",
"getValue",
")",
"{",
"return",
"$",
"this",
"->",
"formatDate",
"(",
"isset",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
"?",
"$",
"data",
"[",
"'value'",
"]",
":",
"null",
")",
";",
"}",
"if",
"(",
"$",
"mode",
"===",
"$",
"modes",
"->",
"getObject",
")",
"{",
"$",
"timezone",
"=",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'timezone'",
",",
"'region'",
")",
";",
"$",
"date",
"=",
"new",
"DateTime",
"(",
"isset",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
"?",
"$",
"data",
"[",
"'value'",
"]",
":",
"'now'",
")",
";",
"$",
"date",
"->",
"setTimezone",
"(",
"new",
"DateTimeZone",
"(",
"$",
"timezone",
")",
")",
";",
"return",
"$",
"date",
";",
"}",
"elseif",
"(",
"$",
"mode",
"===",
"$",
"modes",
"->",
"getPostdata",
")",
"{",
"return",
"isset",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
"?",
"$",
"data",
"[",
"'value'",
"]",
":",
"null",
";",
"}",
"return",
"null",
";",
"}"
] | Give the field some data and ask it to return a value using one of many
possible modes.
@param mixed $data
@param integer $mode
@param integer $entry_id
@return DateTime|null | [
"Give",
"the",
"field",
"some",
"data",
"and",
"ask",
"it",
"to",
"return",
"a",
"value",
"using",
"one",
"of",
"many",
"possible",
"modes",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.date.php#L675-L703 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.date.php | FieldDate.buildDSRetrievalSQL | public function buildDSRetrievalSQL($data, &$joins, &$where, $andOperation = false)
{
if (self::isFilterRegex($data[0])) {
$this->buildRegexSQL($data[0], array('value'), $joins, $where);
} elseif (self::isFilterSQL($data[0])) {
$this->buildFilterSQL($data[0], array('value'), $joins, $where);
} else {
$parsed = array();
// For the filter provided, loop over each piece
foreach ($data as $string) {
$type = self::parseFilter($string);
if ($type == self::ERROR) {
return false;
}
if (!is_array($parsed[$type])) {
$parsed[$type] = array();
}
$parsed[$type][] = $string;
}
foreach ($parsed as $value) {
$this->buildRangeFilterSQL($value, $joins, $where, $andOperation);
}
}
return true;
} | php | public function buildDSRetrievalSQL($data, &$joins, &$where, $andOperation = false)
{
if (self::isFilterRegex($data[0])) {
$this->buildRegexSQL($data[0], array('value'), $joins, $where);
} elseif (self::isFilterSQL($data[0])) {
$this->buildFilterSQL($data[0], array('value'), $joins, $where);
} else {
$parsed = array();
// For the filter provided, loop over each piece
foreach ($data as $string) {
$type = self::parseFilter($string);
if ($type == self::ERROR) {
return false;
}
if (!is_array($parsed[$type])) {
$parsed[$type] = array();
}
$parsed[$type][] = $string;
}
foreach ($parsed as $value) {
$this->buildRangeFilterSQL($value, $joins, $where, $andOperation);
}
}
return true;
} | [
"public",
"function",
"buildDSRetrievalSQL",
"(",
"$",
"data",
",",
"&",
"$",
"joins",
",",
"&",
"$",
"where",
",",
"$",
"andOperation",
"=",
"false",
")",
"{",
"if",
"(",
"self",
"::",
"isFilterRegex",
"(",
"$",
"data",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"buildRegexSQL",
"(",
"$",
"data",
"[",
"0",
"]",
",",
"array",
"(",
"'value'",
")",
",",
"$",
"joins",
",",
"$",
"where",
")",
";",
"}",
"elseif",
"(",
"self",
"::",
"isFilterSQL",
"(",
"$",
"data",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"buildFilterSQL",
"(",
"$",
"data",
"[",
"0",
"]",
",",
"array",
"(",
"'value'",
")",
",",
"$",
"joins",
",",
"$",
"where",
")",
";",
"}",
"else",
"{",
"$",
"parsed",
"=",
"array",
"(",
")",
";",
"// For the filter provided, loop over each piece",
"foreach",
"(",
"$",
"data",
"as",
"$",
"string",
")",
"{",
"$",
"type",
"=",
"self",
"::",
"parseFilter",
"(",
"$",
"string",
")",
";",
"if",
"(",
"$",
"type",
"==",
"self",
"::",
"ERROR",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"parsed",
"[",
"$",
"type",
"]",
")",
")",
"{",
"$",
"parsed",
"[",
"$",
"type",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"parsed",
"[",
"$",
"type",
"]",
"[",
"]",
"=",
"$",
"string",
";",
"}",
"foreach",
"(",
"$",
"parsed",
"as",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"buildRangeFilterSQL",
"(",
"$",
"value",
",",
"$",
"joins",
",",
"$",
"where",
",",
"$",
"andOperation",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | /*-------------------------------------------------------------------------
Filtering:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Filtering",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.date.php#L709-L739 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.date.php | FieldDate.buildSortingSQL | public function buildSortingSQL(&$joins, &$where, &$sort, $order = 'ASC')
{
if ($this->isRandomOrder($order)) {
$sort = 'ORDER BY RAND()';
} else {
$sort = sprintf(
'ORDER BY (
SELECT %s
FROM tbl_entries_data_%d AS `ed`
WHERE entry_id = e.id
) %s, `e`.`id` %s',
'`ed`.date',
$this->get('id'),
$order,
$order
);
}
} | php | public function buildSortingSQL(&$joins, &$where, &$sort, $order = 'ASC')
{
if ($this->isRandomOrder($order)) {
$sort = 'ORDER BY RAND()';
} else {
$sort = sprintf(
'ORDER BY (
SELECT %s
FROM tbl_entries_data_%d AS `ed`
WHERE entry_id = e.id
) %s, `e`.`id` %s',
'`ed`.date',
$this->get('id'),
$order,
$order
);
}
} | [
"public",
"function",
"buildSortingSQL",
"(",
"&",
"$",
"joins",
",",
"&",
"$",
"where",
",",
"&",
"$",
"sort",
",",
"$",
"order",
"=",
"'ASC'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isRandomOrder",
"(",
"$",
"order",
")",
")",
"{",
"$",
"sort",
"=",
"'ORDER BY RAND()'",
";",
"}",
"else",
"{",
"$",
"sort",
"=",
"sprintf",
"(",
"'ORDER BY (\n SELECT %s\n FROM tbl_entries_data_%d AS `ed`\n WHERE entry_id = e.id\n ) %s, `e`.`id` %s'",
",",
"'`ed`.date'",
",",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"order",
",",
"$",
"order",
")",
";",
"}",
"}"
] | /*-------------------------------------------------------------------------
Sorting:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Sorting",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.date.php#L745-L762 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.date.php | FieldDate.groupRecords | public function groupRecords($records)
{
if (!is_array($records) || empty($records)) {
return;
}
$groups = array('year' => array());
foreach ($records as $r) {
$data = $r->getData($this->get('id'));
$timestamp = DateTimeObj::get('U', $data['value']);
$info = getdate($timestamp);
$year = $info['year'];
$month = ($info['mon'] < 10 ? '0' . $info['mon'] : $info['mon']);
if (!isset($groups['year'][$year])) {
$groups['year'][$year] = array(
'attr' => array('value' => $year),
'records' => array(),
'groups' => array()
);
}
if (!isset($groups['year'][$year]['groups']['month'])) {
$groups['year'][$year]['groups']['month'] = array();
}
if (!isset($groups['year'][$year]['groups']['month'][$month])) {
$groups['year'][$year]['groups']['month'][$month] = array(
'attr' => array('value' => $month),
'records' => array(),
'groups' => array()
);
}
$groups['year'][$year]['groups']['month'][$month]['records'][] = $r;
}
return $groups;
} | php | public function groupRecords($records)
{
if (!is_array($records) || empty($records)) {
return;
}
$groups = array('year' => array());
foreach ($records as $r) {
$data = $r->getData($this->get('id'));
$timestamp = DateTimeObj::get('U', $data['value']);
$info = getdate($timestamp);
$year = $info['year'];
$month = ($info['mon'] < 10 ? '0' . $info['mon'] : $info['mon']);
if (!isset($groups['year'][$year])) {
$groups['year'][$year] = array(
'attr' => array('value' => $year),
'records' => array(),
'groups' => array()
);
}
if (!isset($groups['year'][$year]['groups']['month'])) {
$groups['year'][$year]['groups']['month'] = array();
}
if (!isset($groups['year'][$year]['groups']['month'][$month])) {
$groups['year'][$year]['groups']['month'][$month] = array(
'attr' => array('value' => $month),
'records' => array(),
'groups' => array()
);
}
$groups['year'][$year]['groups']['month'][$month]['records'][] = $r;
}
return $groups;
} | [
"public",
"function",
"groupRecords",
"(",
"$",
"records",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"records",
")",
"||",
"empty",
"(",
"$",
"records",
")",
")",
"{",
"return",
";",
"}",
"$",
"groups",
"=",
"array",
"(",
"'year'",
"=>",
"array",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"r",
")",
"{",
"$",
"data",
"=",
"$",
"r",
"->",
"getData",
"(",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"$",
"timestamp",
"=",
"DateTimeObj",
"::",
"get",
"(",
"'U'",
",",
"$",
"data",
"[",
"'value'",
"]",
")",
";",
"$",
"info",
"=",
"getdate",
"(",
"$",
"timestamp",
")",
";",
"$",
"year",
"=",
"$",
"info",
"[",
"'year'",
"]",
";",
"$",
"month",
"=",
"(",
"$",
"info",
"[",
"'mon'",
"]",
"<",
"10",
"?",
"'0'",
".",
"$",
"info",
"[",
"'mon'",
"]",
":",
"$",
"info",
"[",
"'mon'",
"]",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"groups",
"[",
"'year'",
"]",
"[",
"$",
"year",
"]",
")",
")",
"{",
"$",
"groups",
"[",
"'year'",
"]",
"[",
"$",
"year",
"]",
"=",
"array",
"(",
"'attr'",
"=>",
"array",
"(",
"'value'",
"=>",
"$",
"year",
")",
",",
"'records'",
"=>",
"array",
"(",
")",
",",
"'groups'",
"=>",
"array",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"groups",
"[",
"'year'",
"]",
"[",
"$",
"year",
"]",
"[",
"'groups'",
"]",
"[",
"'month'",
"]",
")",
")",
"{",
"$",
"groups",
"[",
"'year'",
"]",
"[",
"$",
"year",
"]",
"[",
"'groups'",
"]",
"[",
"'month'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"groups",
"[",
"'year'",
"]",
"[",
"$",
"year",
"]",
"[",
"'groups'",
"]",
"[",
"'month'",
"]",
"[",
"$",
"month",
"]",
")",
")",
"{",
"$",
"groups",
"[",
"'year'",
"]",
"[",
"$",
"year",
"]",
"[",
"'groups'",
"]",
"[",
"'month'",
"]",
"[",
"$",
"month",
"]",
"=",
"array",
"(",
"'attr'",
"=>",
"array",
"(",
"'value'",
"=>",
"$",
"month",
")",
",",
"'records'",
"=>",
"array",
"(",
")",
",",
"'groups'",
"=>",
"array",
"(",
")",
")",
";",
"}",
"$",
"groups",
"[",
"'year'",
"]",
"[",
"$",
"year",
"]",
"[",
"'groups'",
"]",
"[",
"'month'",
"]",
"[",
"$",
"month",
"]",
"[",
"'records'",
"]",
"[",
"]",
"=",
"$",
"r",
";",
"}",
"return",
"$",
"groups",
";",
"}"
] | /*-------------------------------------------------------------------------
Grouping:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Grouping",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.date.php#L773-L814 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.pageAlert | public function pageAlert($message = null, $type = Alert::NOTICE)
{
if (is_null($message) && $type == Alert::ERROR) {
$message = __('There was a problem rendering this page. Please check the activity log for more details.');
} else {
$message = __($message);
}
if (strlen(trim($message)) == 0) {
throw new Exception(__('A message must be supplied unless the alert is of type Alert::ERROR'));
}
$this->Alert[] = new Alert($message, $type);
} | php | public function pageAlert($message = null, $type = Alert::NOTICE)
{
if (is_null($message) && $type == Alert::ERROR) {
$message = __('There was a problem rendering this page. Please check the activity log for more details.');
} else {
$message = __($message);
}
if (strlen(trim($message)) == 0) {
throw new Exception(__('A message must be supplied unless the alert is of type Alert::ERROR'));
}
$this->Alert[] = new Alert($message, $type);
} | [
"public",
"function",
"pageAlert",
"(",
"$",
"message",
"=",
"null",
",",
"$",
"type",
"=",
"Alert",
"::",
"NOTICE",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"message",
")",
"&&",
"$",
"type",
"==",
"Alert",
"::",
"ERROR",
")",
"{",
"$",
"message",
"=",
"__",
"(",
"'There was a problem rendering this page. Please check the activity log for more details.'",
")",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"__",
"(",
"$",
"message",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"message",
")",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"Exception",
"(",
"__",
"(",
"'A message must be supplied unless the alert is of type Alert::ERROR'",
")",
")",
";",
"}",
"$",
"this",
"->",
"Alert",
"[",
"]",
"=",
"new",
"Alert",
"(",
"$",
"message",
",",
"$",
"type",
")",
";",
"}"
] | Given a `$message` and an optional `$type`, this function will
add an Alert instance into this page's `$this->Alert` property.
Since Symphony 2.3, there may be more than one `Alert` per page.
Unless the Alert is an Error, it is required the `$message` be
passed to this function.
@param string $message
The message to display to users
@param string $type
An Alert constant, being `Alert::NOTICE`, `Alert::ERROR` or
`Alert::SUCCESS`. The differing types will show the error
in a different style in the backend. If omitted, this defaults
to `Alert::NOTICE`.
@throws Exception | [
"Given",
"a",
"$message",
"and",
"an",
"optional",
"$type",
"this",
"function",
"will",
"add",
"an",
"Alert",
"instance",
"into",
"this",
"page",
"s",
"$this",
"-",
">",
"Alert",
"property",
".",
"Since",
"Symphony",
"2",
".",
"3",
"there",
"may",
"be",
"more",
"than",
"one",
"Alert",
"per",
"page",
".",
"Unless",
"the",
"Alert",
"is",
"an",
"Error",
"it",
"is",
"required",
"the",
"$message",
"be",
"passed",
"to",
"this",
"function",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L174-L187 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.appendSubheading | public function appendSubheading($value, $actions = null)
{
if (!is_array($actions) && $actions) { // Backward compatibility
$actions = array($actions);
}
if (!empty($actions)) {
foreach ($actions as $a) {
$this->insertAction($a);
}
}
$this->Breadcrumbs->appendChild(new XMLElement('h2', $value, array('role' => 'heading', 'id' => 'symphony-subheading')));
} | php | public function appendSubheading($value, $actions = null)
{
if (!is_array($actions) && $actions) { // Backward compatibility
$actions = array($actions);
}
if (!empty($actions)) {
foreach ($actions as $a) {
$this->insertAction($a);
}
}
$this->Breadcrumbs->appendChild(new XMLElement('h2', $value, array('role' => 'heading', 'id' => 'symphony-subheading')));
} | [
"public",
"function",
"appendSubheading",
"(",
"$",
"value",
",",
"$",
"actions",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"actions",
")",
"&&",
"$",
"actions",
")",
"{",
"// Backward compatibility",
"$",
"actions",
"=",
"array",
"(",
"$",
"actions",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"actions",
")",
")",
"{",
"foreach",
"(",
"$",
"actions",
"as",
"$",
"a",
")",
"{",
"$",
"this",
"->",
"insertAction",
"(",
"$",
"a",
")",
";",
"}",
"}",
"$",
"this",
"->",
"Breadcrumbs",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'h2'",
",",
"$",
"value",
",",
"array",
"(",
"'role'",
"=>",
"'heading'",
",",
"'id'",
"=>",
"'symphony-subheading'",
")",
")",
")",
";",
"}"
] | Appends the heading of this Symphony page to the Context element.
Action buttons can be provided (e.g. "Create new") as second parameter.
@since Symphony 2.3
@param string $value
The heading text
@param array|XMLElement|string $actions
Some contextual actions to append to the heading, they can be provided as
an array of XMLElements or strings. Traditionally Symphony uses this to append
a "Create new" link to the Context div. | [
"Appends",
"the",
"heading",
"of",
"this",
"Symphony",
"page",
"to",
"the",
"Context",
"element",
".",
"Action",
"buttons",
"can",
"be",
"provided",
"(",
"e",
".",
"g",
".",
"Create",
"new",
")",
"as",
"second",
"parameter",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L201-L214 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.insertAction | public function insertAction(XMLElement $action, $append = true)
{
$actions = $this->Context->getChildrenByName('ul');
// Actions haven't be added yet, create the element
if (empty($actions)) {
$ul = new XMLElement('ul', null, array('class' => 'actions'));
$this->Context->appendChild($ul);
} else {
$ul = current($actions);
$this->Context->replaceChildAt(1, $ul);
}
$li = new XMLElement('li', $action);
if ($append) {
$ul->prependChild($li);
} else {
$ul->appendChild($li);
}
} | php | public function insertAction(XMLElement $action, $append = true)
{
$actions = $this->Context->getChildrenByName('ul');
// Actions haven't be added yet, create the element
if (empty($actions)) {
$ul = new XMLElement('ul', null, array('class' => 'actions'));
$this->Context->appendChild($ul);
} else {
$ul = current($actions);
$this->Context->replaceChildAt(1, $ul);
}
$li = new XMLElement('li', $action);
if ($append) {
$ul->prependChild($li);
} else {
$ul->appendChild($li);
}
} | [
"public",
"function",
"insertAction",
"(",
"XMLElement",
"$",
"action",
",",
"$",
"append",
"=",
"true",
")",
"{",
"$",
"actions",
"=",
"$",
"this",
"->",
"Context",
"->",
"getChildrenByName",
"(",
"'ul'",
")",
";",
"// Actions haven't be added yet, create the element",
"if",
"(",
"empty",
"(",
"$",
"actions",
")",
")",
"{",
"$",
"ul",
"=",
"new",
"XMLElement",
"(",
"'ul'",
",",
"null",
",",
"array",
"(",
"'class'",
"=>",
"'actions'",
")",
")",
";",
"$",
"this",
"->",
"Context",
"->",
"appendChild",
"(",
"$",
"ul",
")",
";",
"}",
"else",
"{",
"$",
"ul",
"=",
"current",
"(",
"$",
"actions",
")",
";",
"$",
"this",
"->",
"Context",
"->",
"replaceChildAt",
"(",
"1",
",",
"$",
"ul",
")",
";",
"}",
"$",
"li",
"=",
"new",
"XMLElement",
"(",
"'li'",
",",
"$",
"action",
")",
";",
"if",
"(",
"$",
"append",
")",
"{",
"$",
"ul",
"->",
"prependChild",
"(",
"$",
"li",
")",
";",
"}",
"else",
"{",
"$",
"ul",
"->",
"appendChild",
"(",
"$",
"li",
")",
";",
"}",
"}"
] | This function allows a user to insert an Action button to the page.
It accepts an `XMLElement` (which should be of the `Anchor` type),
an optional parameter `$prepend`, which when `true` will add this
action before any existing actions.
@since Symphony 2.3
@see core.Widget#Anchor
@param XMLElement $action
An Anchor element to add to the top of the page.
@param boolean $append
If true, this will add the `$action` after existing actions, otherwise
it will be added before existing actions. By default this is `true`,
which will add the `$action` after current actions. | [
"This",
"function",
"allows",
"a",
"user",
"to",
"insert",
"an",
"Action",
"button",
"to",
"the",
"page",
".",
"It",
"accepts",
"an",
"XMLElement",
"(",
"which",
"should",
"be",
"of",
"the",
"Anchor",
"type",
")",
"an",
"optional",
"parameter",
"$prepend",
"which",
"when",
"true",
"will",
"add",
"this",
"action",
"before",
"any",
"existing",
"actions",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L231-L251 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.insertBreadcrumbs | public function insertBreadcrumbs(array $values)
{
if (empty($values)) {
return;
}
if ($this->Breadcrumbs instanceof XMLElement && count($this->Breadcrumbs->getChildrenByName('nav')) === 1) {
$nav = $this->Breadcrumbs->getChildrenByName('nav');
$nav = $nav[0];
$p = $nav->getChild(0);
} else {
$p = new XMLElement('p');
$nav = new XMLElement('nav');
$nav->appendChild($p);
$this->Breadcrumbs->prependChild($nav);
}
foreach ($values as $v) {
$p->appendChild($v);
$p->appendChild(new XMLElement('span', '›', array('class' => 'sep')));
}
} | php | public function insertBreadcrumbs(array $values)
{
if (empty($values)) {
return;
}
if ($this->Breadcrumbs instanceof XMLElement && count($this->Breadcrumbs->getChildrenByName('nav')) === 1) {
$nav = $this->Breadcrumbs->getChildrenByName('nav');
$nav = $nav[0];
$p = $nav->getChild(0);
} else {
$p = new XMLElement('p');
$nav = new XMLElement('nav');
$nav->appendChild($p);
$this->Breadcrumbs->prependChild($nav);
}
foreach ($values as $v) {
$p->appendChild($v);
$p->appendChild(new XMLElement('span', '›', array('class' => 'sep')));
}
} | [
"public",
"function",
"insertBreadcrumbs",
"(",
"array",
"$",
"values",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"values",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"Breadcrumbs",
"instanceof",
"XMLElement",
"&&",
"count",
"(",
"$",
"this",
"->",
"Breadcrumbs",
"->",
"getChildrenByName",
"(",
"'nav'",
")",
")",
"===",
"1",
")",
"{",
"$",
"nav",
"=",
"$",
"this",
"->",
"Breadcrumbs",
"->",
"getChildrenByName",
"(",
"'nav'",
")",
";",
"$",
"nav",
"=",
"$",
"nav",
"[",
"0",
"]",
";",
"$",
"p",
"=",
"$",
"nav",
"->",
"getChild",
"(",
"0",
")",
";",
"}",
"else",
"{",
"$",
"p",
"=",
"new",
"XMLElement",
"(",
"'p'",
")",
";",
"$",
"nav",
"=",
"new",
"XMLElement",
"(",
"'nav'",
")",
";",
"$",
"nav",
"->",
"appendChild",
"(",
"$",
"p",
")",
";",
"$",
"this",
"->",
"Breadcrumbs",
"->",
"prependChild",
"(",
"$",
"nav",
")",
";",
"}",
"foreach",
"(",
"$",
"values",
"as",
"$",
"v",
")",
"{",
"$",
"p",
"->",
"appendChild",
"(",
"$",
"v",
")",
";",
"$",
"p",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'span'",
",",
"'›'",
",",
"array",
"(",
"'class'",
"=>",
"'sep'",
")",
")",
")",
";",
"}",
"}"
] | Allows developers to specify a list of nav items that build the
path to the current page or, in jargon, "breadcrumbs".
@since Symphony 2.3
@param array $values
An array of `XMLElement`'s or strings that compose the path. If breadcrumbs
already exist, any new item will be appended to the rightmost part of the
path. | [
"Allows",
"developers",
"to",
"specify",
"a",
"list",
"of",
"nav",
"items",
"that",
"build",
"the",
"path",
"to",
"the",
"current",
"page",
"or",
"in",
"jargon",
"breadcrumbs",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L263-L286 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.insertDrawer | public function insertDrawer(XMLElement $drawer, $position = 'horizontal', $button = 'append')
{
$drawer->addClass($position);
$drawer->setAttribute('data-position', $position);
$drawer->setAttribute('role', 'complementary');
$this->Drawer[$position][] = $drawer;
if (in_array($button, array('prepend', 'append'))) {
$this->insertAction(
Widget::Anchor(
$drawer->getAttribute('data-label'),
'#' . $drawer->getAttribute('id'),
null,
'button drawer ' . $position
),
($button === 'append' ? true : false)
);
}
} | php | public function insertDrawer(XMLElement $drawer, $position = 'horizontal', $button = 'append')
{
$drawer->addClass($position);
$drawer->setAttribute('data-position', $position);
$drawer->setAttribute('role', 'complementary');
$this->Drawer[$position][] = $drawer;
if (in_array($button, array('prepend', 'append'))) {
$this->insertAction(
Widget::Anchor(
$drawer->getAttribute('data-label'),
'#' . $drawer->getAttribute('id'),
null,
'button drawer ' . $position
),
($button === 'append' ? true : false)
);
}
} | [
"public",
"function",
"insertDrawer",
"(",
"XMLElement",
"$",
"drawer",
",",
"$",
"position",
"=",
"'horizontal'",
",",
"$",
"button",
"=",
"'append'",
")",
"{",
"$",
"drawer",
"->",
"addClass",
"(",
"$",
"position",
")",
";",
"$",
"drawer",
"->",
"setAttribute",
"(",
"'data-position'",
",",
"$",
"position",
")",
";",
"$",
"drawer",
"->",
"setAttribute",
"(",
"'role'",
",",
"'complementary'",
")",
";",
"$",
"this",
"->",
"Drawer",
"[",
"$",
"position",
"]",
"[",
"]",
"=",
"$",
"drawer",
";",
"if",
"(",
"in_array",
"(",
"$",
"button",
",",
"array",
"(",
"'prepend'",
",",
"'append'",
")",
")",
")",
"{",
"$",
"this",
"->",
"insertAction",
"(",
"Widget",
"::",
"Anchor",
"(",
"$",
"drawer",
"->",
"getAttribute",
"(",
"'data-label'",
")",
",",
"'#'",
".",
"$",
"drawer",
"->",
"getAttribute",
"(",
"'id'",
")",
",",
"null",
",",
"'button drawer '",
".",
"$",
"position",
")",
",",
"(",
"$",
"button",
"===",
"'append'",
"?",
"true",
":",
"false",
")",
")",
";",
"}",
"}"
] | Allows a Drawer element to added to the backend page in one of three
positions, `horizontal`, `vertical-left` or `vertical-right`. The button
to trigger the visibility of the drawer will be added after existing
actions by default.
@since Symphony 2.3
@see core.Widget#Drawer
@param XMLElement $drawer
An XMLElement representing the drawer, use `Widget::Drawer` to construct
@param string $position
Where `$position` can be `horizontal`, `vertical-left` or
`vertical-right`. Defaults to `horizontal`.
@param string $button
If not passed, a button to open/close the drawer will not be added
to the interface. Accepts 'prepend' or 'append' values, which will
add the button before or after existing buttons. Defaults to `prepend`.
If any other value is passed, no button will be added.
@throws InvalidArgumentException | [
"Allows",
"a",
"Drawer",
"element",
"to",
"added",
"to",
"the",
"backend",
"page",
"in",
"one",
"of",
"three",
"positions",
"horizontal",
"vertical",
"-",
"left",
"or",
"vertical",
"-",
"right",
".",
"The",
"button",
"to",
"trigger",
"the",
"visibility",
"of",
"the",
"drawer",
"will",
"be",
"added",
"after",
"existing",
"actions",
"by",
"default",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L308-L326 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.build | public function build(array $context = array())
{
$this->_context = $context;
if (!$this->canAccessPage()) {
Administration::instance()->throwCustomError(
__('You are not authorised to access this page.'),
__('Access Denied'),
Page::HTTP_STATUS_UNAUTHORIZED
);
}
$this->Html->setDTD('<!DOCTYPE html>');
$this->Html->setAttribute('lang', Lang::get());
$this->addElementToHead(new XMLElement('meta', null, array('charset' => 'UTF-8')), 0);
$this->addElementToHead(new XMLElement('meta', null, array('http-equiv' => 'X-UA-Compatible', 'content' => 'IE=edge,chrome=1')), 1);
$this->addElementToHead(new XMLElement('meta', null, array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1')), 2);
// Add styles
$this->addStylesheetToHead(ASSETS_URL . '/css/symphony.min.css', 'screen', 2, false);
// Calculate timezone offset from UTC
$timezone = new DateTimeZone(DateTimeObj::getSetting('timezone'));
$datetime = new DateTime('now', $timezone);
$timezoneOffset = intval($timezone->getOffset($datetime)) / 60;
// Add scripts
$environment = array(
'root' => URL,
'symphony' => SYMPHONY_URL,
'path' => '/' . Symphony::Configuration()->get('admin-path', 'symphony'),
'route' => getCurrentPage(),
'version' => Symphony::Configuration()->get('version', 'symphony'),
'lang' => Lang::get(),
'user' => array(
'fullname' => Symphony::Author()->getFullName(),
'name' => Symphony::Author()->get('first_name'),
'type' => Symphony::Author()->get('user_type'),
'id' => Symphony::Author()->get('id')
),
'datetime' => array(
'formats' => DateTimeObj::getDateFormatMappings(),
'timezone-offset' => $timezoneOffset
),
'env' => array_merge(
array('page-namespace' => Symphony::getPageNamespace()),
$this->_context
)
);
$envJsonOptions = 0;
// Those are PHP 5.4+
if (defined('JSON_UNESCAPED_SLASHES') && defined('JSON_UNESCAPED_UNICODE')) {
$envJsonOptions = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
}
$this->addElementToHead(
new XMLElement('script', json_encode($environment, $envJsonOptions), array(
'type' => 'application/json',
'id' => 'environment'
)),
4
);
$this->addScriptToHead(ASSETS_URL . '/js/symphony.min.js', 6, false);
// Initialise page containers
$this->Wrapper = new XMLElement('div', null, array('id' => 'wrapper'));
$this->Header = new XMLElement('header', null, array('id' => 'header'));
$this->Context = new XMLElement('div', null, array('id' => 'context'));
$this->Breadcrumbs = new XMLElement('div', null, array('id' => 'breadcrumbs'));
$this->Contents = new XMLElement('div', null, array('id' => 'contents', 'role' => 'main'));
$this->Form = Widget::Form(Administration::instance()->getCurrentPageURL(), 'post', null, null, array('role' => 'form'));
/**
* Allows developers to insert items into the page HEAD. Use
* `Administration::instance()->Page` for access to the page object.
*
* @since In Symphony 2.3.2 this delegate was renamed from
* `InitaliseAdminPageHead` to the correct spelling of
* `InitialiseAdminPageHead`. The old delegate is supported
* until Symphony 3.0
*
* @delegate InitialiseAdminPageHead
* @param string $context
* '/backend/'
*/
Symphony::ExtensionManager()->notifyMembers('InitialiseAdminPageHead', '/backend/');
Symphony::ExtensionManager()->notifyMembers('InitaliseAdminPageHead', '/backend/');
$this->addHeaderToPage('Content-Type', 'text/html; charset=UTF-8');
$this->addHeaderToPage('Cache-Control', 'no-cache, must-revalidate, max-age=0');
$this->addHeaderToPage('Expires', 'Mon, 12 Dec 1982 06:14:00 GMT');
$this->addHeaderToPage('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT');
$this->addHeaderToPage('Pragma', 'no-cache');
// If not set by another extension, lock down the backend
if (!array_key_exists('x-frame-options', $this->headers())) {
$this->addHeaderToPage('X-Frame-Options', 'SAMEORIGIN');
}
if (!array_key_exists('x-content-type-options', $this->headers())) {
$this->addHeaderToPage('X-Content-Type-Options', 'nosniff');
}
if (!array_key_exists('x-xss-protection', $this->headers())) {
$this->addHeaderToPage('X-XSS-Protection', '1; mode=block');
}
if (!array_key_exists('referrer-policy', $this->headers())) {
$this->addHeaderToPage('Referrer-Policy', 'same-origin');
}
if (isset($_REQUEST['action'])) {
$this->action();
Symphony::Profiler()->sample('Page action run', PROFILE_LAP);
}
$h1 = new XMLElement('h1');
$h1->appendChild(Widget::Anchor(Symphony::Configuration()->get('sitename', 'general'), rtrim(URL, '/') . '/'));
$this->Header->appendChild($h1);
$this->appendUserLinks();
$this->appendNavigation();
// Add Breadcrumbs
$this->Context->prependChild($this->Breadcrumbs);
$this->Contents->appendChild($this->Form);
// Validate date time config
$dateFormat = defined('__SYM_DATE_FORMAT__') ? __SYM_DATE_FORMAT__ : null;
if (empty($dateFormat)) {
$this->pageAlert(
__('Your <code>%s</code> file does not define a date format', array(basename(CONFIG))),
Alert::NOTICE
);
}
$timeFormat = defined('__SYM_TIME_FORMAT__') ? __SYM_TIME_FORMAT__ : null;
if (empty($timeFormat)) {
$this->pageAlert(
__('Your <code>%s</code> file does not define a time format.', array(basename(CONFIG))),
Alert::NOTICE
);
}
$this->view();
$this->appendAlert();
Symphony::Profiler()->sample('Page content created', PROFILE_LAP);
} | php | public function build(array $context = array())
{
$this->_context = $context;
if (!$this->canAccessPage()) {
Administration::instance()->throwCustomError(
__('You are not authorised to access this page.'),
__('Access Denied'),
Page::HTTP_STATUS_UNAUTHORIZED
);
}
$this->Html->setDTD('<!DOCTYPE html>');
$this->Html->setAttribute('lang', Lang::get());
$this->addElementToHead(new XMLElement('meta', null, array('charset' => 'UTF-8')), 0);
$this->addElementToHead(new XMLElement('meta', null, array('http-equiv' => 'X-UA-Compatible', 'content' => 'IE=edge,chrome=1')), 1);
$this->addElementToHead(new XMLElement('meta', null, array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1')), 2);
// Add styles
$this->addStylesheetToHead(ASSETS_URL . '/css/symphony.min.css', 'screen', 2, false);
// Calculate timezone offset from UTC
$timezone = new DateTimeZone(DateTimeObj::getSetting('timezone'));
$datetime = new DateTime('now', $timezone);
$timezoneOffset = intval($timezone->getOffset($datetime)) / 60;
// Add scripts
$environment = array(
'root' => URL,
'symphony' => SYMPHONY_URL,
'path' => '/' . Symphony::Configuration()->get('admin-path', 'symphony'),
'route' => getCurrentPage(),
'version' => Symphony::Configuration()->get('version', 'symphony'),
'lang' => Lang::get(),
'user' => array(
'fullname' => Symphony::Author()->getFullName(),
'name' => Symphony::Author()->get('first_name'),
'type' => Symphony::Author()->get('user_type'),
'id' => Symphony::Author()->get('id')
),
'datetime' => array(
'formats' => DateTimeObj::getDateFormatMappings(),
'timezone-offset' => $timezoneOffset
),
'env' => array_merge(
array('page-namespace' => Symphony::getPageNamespace()),
$this->_context
)
);
$envJsonOptions = 0;
// Those are PHP 5.4+
if (defined('JSON_UNESCAPED_SLASHES') && defined('JSON_UNESCAPED_UNICODE')) {
$envJsonOptions = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
}
$this->addElementToHead(
new XMLElement('script', json_encode($environment, $envJsonOptions), array(
'type' => 'application/json',
'id' => 'environment'
)),
4
);
$this->addScriptToHead(ASSETS_URL . '/js/symphony.min.js', 6, false);
// Initialise page containers
$this->Wrapper = new XMLElement('div', null, array('id' => 'wrapper'));
$this->Header = new XMLElement('header', null, array('id' => 'header'));
$this->Context = new XMLElement('div', null, array('id' => 'context'));
$this->Breadcrumbs = new XMLElement('div', null, array('id' => 'breadcrumbs'));
$this->Contents = new XMLElement('div', null, array('id' => 'contents', 'role' => 'main'));
$this->Form = Widget::Form(Administration::instance()->getCurrentPageURL(), 'post', null, null, array('role' => 'form'));
/**
* Allows developers to insert items into the page HEAD. Use
* `Administration::instance()->Page` for access to the page object.
*
* @since In Symphony 2.3.2 this delegate was renamed from
* `InitaliseAdminPageHead` to the correct spelling of
* `InitialiseAdminPageHead`. The old delegate is supported
* until Symphony 3.0
*
* @delegate InitialiseAdminPageHead
* @param string $context
* '/backend/'
*/
Symphony::ExtensionManager()->notifyMembers('InitialiseAdminPageHead', '/backend/');
Symphony::ExtensionManager()->notifyMembers('InitaliseAdminPageHead', '/backend/');
$this->addHeaderToPage('Content-Type', 'text/html; charset=UTF-8');
$this->addHeaderToPage('Cache-Control', 'no-cache, must-revalidate, max-age=0');
$this->addHeaderToPage('Expires', 'Mon, 12 Dec 1982 06:14:00 GMT');
$this->addHeaderToPage('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT');
$this->addHeaderToPage('Pragma', 'no-cache');
// If not set by another extension, lock down the backend
if (!array_key_exists('x-frame-options', $this->headers())) {
$this->addHeaderToPage('X-Frame-Options', 'SAMEORIGIN');
}
if (!array_key_exists('x-content-type-options', $this->headers())) {
$this->addHeaderToPage('X-Content-Type-Options', 'nosniff');
}
if (!array_key_exists('x-xss-protection', $this->headers())) {
$this->addHeaderToPage('X-XSS-Protection', '1; mode=block');
}
if (!array_key_exists('referrer-policy', $this->headers())) {
$this->addHeaderToPage('Referrer-Policy', 'same-origin');
}
if (isset($_REQUEST['action'])) {
$this->action();
Symphony::Profiler()->sample('Page action run', PROFILE_LAP);
}
$h1 = new XMLElement('h1');
$h1->appendChild(Widget::Anchor(Symphony::Configuration()->get('sitename', 'general'), rtrim(URL, '/') . '/'));
$this->Header->appendChild($h1);
$this->appendUserLinks();
$this->appendNavigation();
// Add Breadcrumbs
$this->Context->prependChild($this->Breadcrumbs);
$this->Contents->appendChild($this->Form);
// Validate date time config
$dateFormat = defined('__SYM_DATE_FORMAT__') ? __SYM_DATE_FORMAT__ : null;
if (empty($dateFormat)) {
$this->pageAlert(
__('Your <code>%s</code> file does not define a date format', array(basename(CONFIG))),
Alert::NOTICE
);
}
$timeFormat = defined('__SYM_TIME_FORMAT__') ? __SYM_TIME_FORMAT__ : null;
if (empty($timeFormat)) {
$this->pageAlert(
__('Your <code>%s</code> file does not define a time format.', array(basename(CONFIG))),
Alert::NOTICE
);
}
$this->view();
$this->appendAlert();
Symphony::Profiler()->sample('Page content created', PROFILE_LAP);
} | [
"public",
"function",
"build",
"(",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"_context",
"=",
"$",
"context",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"canAccessPage",
"(",
")",
")",
"{",
"Administration",
"::",
"instance",
"(",
")",
"->",
"throwCustomError",
"(",
"__",
"(",
"'You are not authorised to access this page.'",
")",
",",
"__",
"(",
"'Access Denied'",
")",
",",
"Page",
"::",
"HTTP_STATUS_UNAUTHORIZED",
")",
";",
"}",
"$",
"this",
"->",
"Html",
"->",
"setDTD",
"(",
"'<!DOCTYPE html>'",
")",
";",
"$",
"this",
"->",
"Html",
"->",
"setAttribute",
"(",
"'lang'",
",",
"Lang",
"::",
"get",
"(",
")",
")",
";",
"$",
"this",
"->",
"addElementToHead",
"(",
"new",
"XMLElement",
"(",
"'meta'",
",",
"null",
",",
"array",
"(",
"'charset'",
"=>",
"'UTF-8'",
")",
")",
",",
"0",
")",
";",
"$",
"this",
"->",
"addElementToHead",
"(",
"new",
"XMLElement",
"(",
"'meta'",
",",
"null",
",",
"array",
"(",
"'http-equiv'",
"=>",
"'X-UA-Compatible'",
",",
"'content'",
"=>",
"'IE=edge,chrome=1'",
")",
")",
",",
"1",
")",
";",
"$",
"this",
"->",
"addElementToHead",
"(",
"new",
"XMLElement",
"(",
"'meta'",
",",
"null",
",",
"array",
"(",
"'name'",
"=>",
"'viewport'",
",",
"'content'",
"=>",
"'width=device-width, initial-scale=1'",
")",
")",
",",
"2",
")",
";",
"// Add styles",
"$",
"this",
"->",
"addStylesheetToHead",
"(",
"ASSETS_URL",
".",
"'/css/symphony.min.css'",
",",
"'screen'",
",",
"2",
",",
"false",
")",
";",
"// Calculate timezone offset from UTC",
"$",
"timezone",
"=",
"new",
"DateTimeZone",
"(",
"DateTimeObj",
"::",
"getSetting",
"(",
"'timezone'",
")",
")",
";",
"$",
"datetime",
"=",
"new",
"DateTime",
"(",
"'now'",
",",
"$",
"timezone",
")",
";",
"$",
"timezoneOffset",
"=",
"intval",
"(",
"$",
"timezone",
"->",
"getOffset",
"(",
"$",
"datetime",
")",
")",
"/",
"60",
";",
"// Add scripts",
"$",
"environment",
"=",
"array",
"(",
"'root'",
"=>",
"URL",
",",
"'symphony'",
"=>",
"SYMPHONY_URL",
",",
"'path'",
"=>",
"'/'",
".",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'admin-path'",
",",
"'symphony'",
")",
",",
"'route'",
"=>",
"getCurrentPage",
"(",
")",
",",
"'version'",
"=>",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'version'",
",",
"'symphony'",
")",
",",
"'lang'",
"=>",
"Lang",
"::",
"get",
"(",
")",
",",
"'user'",
"=>",
"array",
"(",
"'fullname'",
"=>",
"Symphony",
"::",
"Author",
"(",
")",
"->",
"getFullName",
"(",
")",
",",
"'name'",
"=>",
"Symphony",
"::",
"Author",
"(",
")",
"->",
"get",
"(",
"'first_name'",
")",
",",
"'type'",
"=>",
"Symphony",
"::",
"Author",
"(",
")",
"->",
"get",
"(",
"'user_type'",
")",
",",
"'id'",
"=>",
"Symphony",
"::",
"Author",
"(",
")",
"->",
"get",
"(",
"'id'",
")",
")",
",",
"'datetime'",
"=>",
"array",
"(",
"'formats'",
"=>",
"DateTimeObj",
"::",
"getDateFormatMappings",
"(",
")",
",",
"'timezone-offset'",
"=>",
"$",
"timezoneOffset",
")",
",",
"'env'",
"=>",
"array_merge",
"(",
"array",
"(",
"'page-namespace'",
"=>",
"Symphony",
"::",
"getPageNamespace",
"(",
")",
")",
",",
"$",
"this",
"->",
"_context",
")",
")",
";",
"$",
"envJsonOptions",
"=",
"0",
";",
"// Those are PHP 5.4+",
"if",
"(",
"defined",
"(",
"'JSON_UNESCAPED_SLASHES'",
")",
"&&",
"defined",
"(",
"'JSON_UNESCAPED_UNICODE'",
")",
")",
"{",
"$",
"envJsonOptions",
"=",
"JSON_UNESCAPED_SLASHES",
"|",
"JSON_UNESCAPED_UNICODE",
";",
"}",
"$",
"this",
"->",
"addElementToHead",
"(",
"new",
"XMLElement",
"(",
"'script'",
",",
"json_encode",
"(",
"$",
"environment",
",",
"$",
"envJsonOptions",
")",
",",
"array",
"(",
"'type'",
"=>",
"'application/json'",
",",
"'id'",
"=>",
"'environment'",
")",
")",
",",
"4",
")",
";",
"$",
"this",
"->",
"addScriptToHead",
"(",
"ASSETS_URL",
".",
"'/js/symphony.min.js'",
",",
"6",
",",
"false",
")",
";",
"// Initialise page containers",
"$",
"this",
"->",
"Wrapper",
"=",
"new",
"XMLElement",
"(",
"'div'",
",",
"null",
",",
"array",
"(",
"'id'",
"=>",
"'wrapper'",
")",
")",
";",
"$",
"this",
"->",
"Header",
"=",
"new",
"XMLElement",
"(",
"'header'",
",",
"null",
",",
"array",
"(",
"'id'",
"=>",
"'header'",
")",
")",
";",
"$",
"this",
"->",
"Context",
"=",
"new",
"XMLElement",
"(",
"'div'",
",",
"null",
",",
"array",
"(",
"'id'",
"=>",
"'context'",
")",
")",
";",
"$",
"this",
"->",
"Breadcrumbs",
"=",
"new",
"XMLElement",
"(",
"'div'",
",",
"null",
",",
"array",
"(",
"'id'",
"=>",
"'breadcrumbs'",
")",
")",
";",
"$",
"this",
"->",
"Contents",
"=",
"new",
"XMLElement",
"(",
"'div'",
",",
"null",
",",
"array",
"(",
"'id'",
"=>",
"'contents'",
",",
"'role'",
"=>",
"'main'",
")",
")",
";",
"$",
"this",
"->",
"Form",
"=",
"Widget",
"::",
"Form",
"(",
"Administration",
"::",
"instance",
"(",
")",
"->",
"getCurrentPageURL",
"(",
")",
",",
"'post'",
",",
"null",
",",
"null",
",",
"array",
"(",
"'role'",
"=>",
"'form'",
")",
")",
";",
"/**\n * Allows developers to insert items into the page HEAD. Use\n * `Administration::instance()->Page` for access to the page object.\n *\n * @since In Symphony 2.3.2 this delegate was renamed from\n * `InitaliseAdminPageHead` to the correct spelling of\n * `InitialiseAdminPageHead`. The old delegate is supported\n * until Symphony 3.0\n *\n * @delegate InitialiseAdminPageHead\n * @param string $context\n * '/backend/'\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'InitialiseAdminPageHead'",
",",
"'/backend/'",
")",
";",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'InitaliseAdminPageHead'",
",",
"'/backend/'",
")",
";",
"$",
"this",
"->",
"addHeaderToPage",
"(",
"'Content-Type'",
",",
"'text/html; charset=UTF-8'",
")",
";",
"$",
"this",
"->",
"addHeaderToPage",
"(",
"'Cache-Control'",
",",
"'no-cache, must-revalidate, max-age=0'",
")",
";",
"$",
"this",
"->",
"addHeaderToPage",
"(",
"'Expires'",
",",
"'Mon, 12 Dec 1982 06:14:00 GMT'",
")",
";",
"$",
"this",
"->",
"addHeaderToPage",
"(",
"'Last-Modified'",
",",
"gmdate",
"(",
"'D, d M Y H:i:s'",
")",
".",
"' GMT'",
")",
";",
"$",
"this",
"->",
"addHeaderToPage",
"(",
"'Pragma'",
",",
"'no-cache'",
")",
";",
"// If not set by another extension, lock down the backend",
"if",
"(",
"!",
"array_key_exists",
"(",
"'x-frame-options'",
",",
"$",
"this",
"->",
"headers",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"addHeaderToPage",
"(",
"'X-Frame-Options'",
",",
"'SAMEORIGIN'",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'x-content-type-options'",
",",
"$",
"this",
"->",
"headers",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"addHeaderToPage",
"(",
"'X-Content-Type-Options'",
",",
"'nosniff'",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'x-xss-protection'",
",",
"$",
"this",
"->",
"headers",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"addHeaderToPage",
"(",
"'X-XSS-Protection'",
",",
"'1; mode=block'",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'referrer-policy'",
",",
"$",
"this",
"->",
"headers",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"addHeaderToPage",
"(",
"'Referrer-Policy'",
",",
"'same-origin'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_REQUEST",
"[",
"'action'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"action",
"(",
")",
";",
"Symphony",
"::",
"Profiler",
"(",
")",
"->",
"sample",
"(",
"'Page action run'",
",",
"PROFILE_LAP",
")",
";",
"}",
"$",
"h1",
"=",
"new",
"XMLElement",
"(",
"'h1'",
")",
";",
"$",
"h1",
"->",
"appendChild",
"(",
"Widget",
"::",
"Anchor",
"(",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'sitename'",
",",
"'general'",
")",
",",
"rtrim",
"(",
"URL",
",",
"'/'",
")",
".",
"'/'",
")",
")",
";",
"$",
"this",
"->",
"Header",
"->",
"appendChild",
"(",
"$",
"h1",
")",
";",
"$",
"this",
"->",
"appendUserLinks",
"(",
")",
";",
"$",
"this",
"->",
"appendNavigation",
"(",
")",
";",
"// Add Breadcrumbs",
"$",
"this",
"->",
"Context",
"->",
"prependChild",
"(",
"$",
"this",
"->",
"Breadcrumbs",
")",
";",
"$",
"this",
"->",
"Contents",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"Form",
")",
";",
"// Validate date time config",
"$",
"dateFormat",
"=",
"defined",
"(",
"'__SYM_DATE_FORMAT__'",
")",
"?",
"__SYM_DATE_FORMAT__",
":",
"null",
";",
"if",
"(",
"empty",
"(",
"$",
"dateFormat",
")",
")",
"{",
"$",
"this",
"->",
"pageAlert",
"(",
"__",
"(",
"'Your <code>%s</code> file does not define a date format'",
",",
"array",
"(",
"basename",
"(",
"CONFIG",
")",
")",
")",
",",
"Alert",
"::",
"NOTICE",
")",
";",
"}",
"$",
"timeFormat",
"=",
"defined",
"(",
"'__SYM_TIME_FORMAT__'",
")",
"?",
"__SYM_TIME_FORMAT__",
":",
"null",
";",
"if",
"(",
"empty",
"(",
"$",
"timeFormat",
")",
")",
"{",
"$",
"this",
"->",
"pageAlert",
"(",
"__",
"(",
"'Your <code>%s</code> file does not define a time format.'",
",",
"array",
"(",
"basename",
"(",
"CONFIG",
")",
")",
")",
",",
"Alert",
"::",
"NOTICE",
")",
";",
"}",
"$",
"this",
"->",
"view",
"(",
")",
";",
"$",
"this",
"->",
"appendAlert",
"(",
")",
";",
"Symphony",
"::",
"Profiler",
"(",
")",
"->",
"sample",
"(",
"'Page content created'",
",",
"PROFILE_LAP",
")",
";",
"}"
] | This function initialises a lot of the basic elements that make up a Symphony
backend page such as the default stylesheets and scripts, the navigation and
the footer. Any alerts are also appended by this function. `view()` is called to
build the actual content of the page. The `InitialiseAdminPageHead` delegate
allows extensions to add elements to the `<head>`. The `CanAccessPage` delegate
allows extensions to restrict access to pages.
@see view()
@uses InitialiseAdminPageHead
@uses CanAccessPage
@param array $context
An associative array describing this pages context. This
can include the section handle, the current entry_id, the page
name and any flags such as 'saved' or 'created'. This list is not exhaustive
and extensions can add their own keys to the array.
@throws InvalidArgumentException
@throws SymphonyErrorPage | [
"This",
"function",
"initialises",
"a",
"lot",
"of",
"the",
"basic",
"elements",
"that",
"make",
"up",
"a",
"Symphony",
"backend",
"page",
"such",
"as",
"the",
"default",
"stylesheets",
"and",
"scripts",
"the",
"navigation",
"and",
"the",
"footer",
".",
"Any",
"alerts",
"are",
"also",
"appended",
"by",
"this",
"function",
".",
"view",
"()",
"is",
"called",
"to",
"build",
"the",
"actual",
"content",
"of",
"the",
"page",
".",
"The",
"InitialiseAdminPageHead",
"delegate",
"allows",
"extensions",
"to",
"add",
"elements",
"to",
"the",
"<head",
">",
".",
"The",
"CanAccessPage",
"delegate",
"allows",
"extensions",
"to",
"restrict",
"access",
"to",
"pages",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L347-L501 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.canAccessPage | public function canAccessPage()
{
$nav = $this->getNavigationArray();
$page = '/' . trim(getCurrentPage(), '/') . '/';
$page_limit = 'author';
foreach ($nav as $item) {
if (
// If page directly matches one of the children
General::in_array_multi($page, $item['children'])
// If the page namespace matches one of the children (this will usually drop query
// string parameters such as /edit/1/)
|| General::in_array_multi(Symphony::getPageNamespace() . '/', $item['children'])
) {
if (is_array($item['children'])) {
foreach ($item['children'] as $c) {
if ($c['link'] === $page && isset($c['limit'])) {
$page_limit = $c['limit'];
// TODO: break out of the loop here in Symphony 3.0.0
}
}
}
if (isset($item['limit']) && $page_limit !== 'primary') {
if ($page_limit === 'author' && $item['limit'] === 'developer') {
$page_limit = 'developer';
}
}
} elseif (isset($item['link']) && $page === $item['link'] && isset($item['limit'])) {
$page_limit = $item['limit'];
}
}
$hasAccess = $this->doesAuthorHaveAccess($page_limit);
if ($hasAccess) {
$page_context = $this->getContext();
$section_handle = !isset($page_context['section_handle']) ? null : $page_context['section_handle'];
/**
* Immediately after the core access rules allowed access to this page
* (i.e. not called if the core rules denied it).
* Extension developers must only further restrict access to it.
* Extension developers must also take care of checking the current value
* of the allowed parameter in order to prevent conflicts with other extensions.
* `$context['allowed'] = $context['allowed'] && customLogic();`
*
* @delegate CanAccessPage
* @since Symphony 2.7.0
* @see doesAuthorHaveAccess()
* @param string $context
* '/backend/'
* @param bool $allowed
* A flag to further restrict access to the page, passed by reference
* @param string $page_limit
* The computed page limit for the current page
* @param string $page_url
* The computed page url for the current page
* @param int $section.id
* The id of the section for this url
* @param string $section.handle
* The handle of the section for this url
*/
Symphony::ExtensionManager()->notifyMembers('CanAccessPage', '/backend/', array(
'allowed' => &$hasAccess,
'page_limit' => $page_limit,
'page_url' => $page,
'section' => array(
'id' => !$section_handle ? 0 : SectionManager::fetchIDFromHandle($section_handle),
'handle' => $section_handle
),
));
}
return $hasAccess;
} | php | public function canAccessPage()
{
$nav = $this->getNavigationArray();
$page = '/' . trim(getCurrentPage(), '/') . '/';
$page_limit = 'author';
foreach ($nav as $item) {
if (
// If page directly matches one of the children
General::in_array_multi($page, $item['children'])
// If the page namespace matches one of the children (this will usually drop query
// string parameters such as /edit/1/)
|| General::in_array_multi(Symphony::getPageNamespace() . '/', $item['children'])
) {
if (is_array($item['children'])) {
foreach ($item['children'] as $c) {
if ($c['link'] === $page && isset($c['limit'])) {
$page_limit = $c['limit'];
// TODO: break out of the loop here in Symphony 3.0.0
}
}
}
if (isset($item['limit']) && $page_limit !== 'primary') {
if ($page_limit === 'author' && $item['limit'] === 'developer') {
$page_limit = 'developer';
}
}
} elseif (isset($item['link']) && $page === $item['link'] && isset($item['limit'])) {
$page_limit = $item['limit'];
}
}
$hasAccess = $this->doesAuthorHaveAccess($page_limit);
if ($hasAccess) {
$page_context = $this->getContext();
$section_handle = !isset($page_context['section_handle']) ? null : $page_context['section_handle'];
/**
* Immediately after the core access rules allowed access to this page
* (i.e. not called if the core rules denied it).
* Extension developers must only further restrict access to it.
* Extension developers must also take care of checking the current value
* of the allowed parameter in order to prevent conflicts with other extensions.
* `$context['allowed'] = $context['allowed'] && customLogic();`
*
* @delegate CanAccessPage
* @since Symphony 2.7.0
* @see doesAuthorHaveAccess()
* @param string $context
* '/backend/'
* @param bool $allowed
* A flag to further restrict access to the page, passed by reference
* @param string $page_limit
* The computed page limit for the current page
* @param string $page_url
* The computed page url for the current page
* @param int $section.id
* The id of the section for this url
* @param string $section.handle
* The handle of the section for this url
*/
Symphony::ExtensionManager()->notifyMembers('CanAccessPage', '/backend/', array(
'allowed' => &$hasAccess,
'page_limit' => $page_limit,
'page_url' => $page,
'section' => array(
'id' => !$section_handle ? 0 : SectionManager::fetchIDFromHandle($section_handle),
'handle' => $section_handle
),
));
}
return $hasAccess;
} | [
"public",
"function",
"canAccessPage",
"(",
")",
"{",
"$",
"nav",
"=",
"$",
"this",
"->",
"getNavigationArray",
"(",
")",
";",
"$",
"page",
"=",
"'/'",
".",
"trim",
"(",
"getCurrentPage",
"(",
")",
",",
"'/'",
")",
".",
"'/'",
";",
"$",
"page_limit",
"=",
"'author'",
";",
"foreach",
"(",
"$",
"nav",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"// If page directly matches one of the children",
"General",
"::",
"in_array_multi",
"(",
"$",
"page",
",",
"$",
"item",
"[",
"'children'",
"]",
")",
"// If the page namespace matches one of the children (this will usually drop query",
"// string parameters such as /edit/1/)",
"||",
"General",
"::",
"in_array_multi",
"(",
"Symphony",
"::",
"getPageNamespace",
"(",
")",
".",
"'/'",
",",
"$",
"item",
"[",
"'children'",
"]",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"item",
"[",
"'children'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"item",
"[",
"'children'",
"]",
"as",
"$",
"c",
")",
"{",
"if",
"(",
"$",
"c",
"[",
"'link'",
"]",
"===",
"$",
"page",
"&&",
"isset",
"(",
"$",
"c",
"[",
"'limit'",
"]",
")",
")",
"{",
"$",
"page_limit",
"=",
"$",
"c",
"[",
"'limit'",
"]",
";",
"// TODO: break out of the loop here in Symphony 3.0.0",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"item",
"[",
"'limit'",
"]",
")",
"&&",
"$",
"page_limit",
"!==",
"'primary'",
")",
"{",
"if",
"(",
"$",
"page_limit",
"===",
"'author'",
"&&",
"$",
"item",
"[",
"'limit'",
"]",
"===",
"'developer'",
")",
"{",
"$",
"page_limit",
"=",
"'developer'",
";",
"}",
"}",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"item",
"[",
"'link'",
"]",
")",
"&&",
"$",
"page",
"===",
"$",
"item",
"[",
"'link'",
"]",
"&&",
"isset",
"(",
"$",
"item",
"[",
"'limit'",
"]",
")",
")",
"{",
"$",
"page_limit",
"=",
"$",
"item",
"[",
"'limit'",
"]",
";",
"}",
"}",
"$",
"hasAccess",
"=",
"$",
"this",
"->",
"doesAuthorHaveAccess",
"(",
"$",
"page_limit",
")",
";",
"if",
"(",
"$",
"hasAccess",
")",
"{",
"$",
"page_context",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
";",
"$",
"section_handle",
"=",
"!",
"isset",
"(",
"$",
"page_context",
"[",
"'section_handle'",
"]",
")",
"?",
"null",
":",
"$",
"page_context",
"[",
"'section_handle'",
"]",
";",
"/**\n * Immediately after the core access rules allowed access to this page\n * (i.e. not called if the core rules denied it).\n * Extension developers must only further restrict access to it.\n * Extension developers must also take care of checking the current value\n * of the allowed parameter in order to prevent conflicts with other extensions.\n * `$context['allowed'] = $context['allowed'] && customLogic();`\n *\n * @delegate CanAccessPage\n * @since Symphony 2.7.0\n * @see doesAuthorHaveAccess()\n * @param string $context\n * '/backend/'\n * @param bool $allowed\n * A flag to further restrict access to the page, passed by reference\n * @param string $page_limit\n * The computed page limit for the current page\n * @param string $page_url\n * The computed page url for the current page\n * @param int $section.id\n * The id of the section for this url\n * @param string $section.handle\n * The handle of the section for this url\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'CanAccessPage'",
",",
"'/backend/'",
",",
"array",
"(",
"'allowed'",
"=>",
"&",
"$",
"hasAccess",
",",
"'page_limit'",
"=>",
"$",
"page_limit",
",",
"'page_url'",
"=>",
"$",
"page",
",",
"'section'",
"=>",
"array",
"(",
"'id'",
"=>",
"!",
"$",
"section_handle",
"?",
"0",
":",
"SectionManager",
"::",
"fetchIDFromHandle",
"(",
"$",
"section_handle",
")",
",",
"'handle'",
"=>",
"$",
"section_handle",
")",
",",
")",
")",
";",
"}",
"return",
"$",
"hasAccess",
";",
"}"
] | Checks the current Symphony Author can access the current page.
This check uses the `ASSETS . /xml/navigation.xml` file to determine
if the current page (or the current page namespace) can be viewed
by the currently logged in Author.
@since Symphony 2.7.0
It fires a delegate, CanAccessPage, to allow extensions to restrict access
to the current page
@uses CanAccessPage
@link http://github.com/symphonycms/symphony-2/blob/master/symphony/assets/xml/navigation.xml
@return boolean
true if the Author can access the current page, false otherwise | [
"Checks",
"the",
"current",
"Symphony",
"Author",
"can",
"access",
"the",
"current",
"page",
".",
"This",
"check",
"uses",
"the",
"ASSETS",
".",
"/",
"xml",
"/",
"navigation",
".",
"xml",
"file",
"to",
"determine",
"if",
"the",
"current",
"page",
"(",
"or",
"the",
"current",
"page",
"namespace",
")",
"can",
"be",
"viewed",
"by",
"the",
"currently",
"logged",
"in",
"Author",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L519-L594 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.doesAuthorHaveAccess | public function doesAuthorHaveAccess($item_limit = null)
{
$can_access = false;
if (!isset($item_limit) || $item_limit === 'author') {
$can_access = true;
} elseif ($item_limit === 'developer' && Symphony::Author()->isDeveloper()) {
$can_access = true;
} elseif ($item_limit === 'manager' && (Symphony::Author()->isManager() || Symphony::Author()->isDeveloper())) {
$can_access = true;
} elseif ($item_limit === 'primary' && Symphony::Author()->isPrimaryAccount()) {
$can_access = true;
}
return $can_access;
} | php | public function doesAuthorHaveAccess($item_limit = null)
{
$can_access = false;
if (!isset($item_limit) || $item_limit === 'author') {
$can_access = true;
} elseif ($item_limit === 'developer' && Symphony::Author()->isDeveloper()) {
$can_access = true;
} elseif ($item_limit === 'manager' && (Symphony::Author()->isManager() || Symphony::Author()->isDeveloper())) {
$can_access = true;
} elseif ($item_limit === 'primary' && Symphony::Author()->isPrimaryAccount()) {
$can_access = true;
}
return $can_access;
} | [
"public",
"function",
"doesAuthorHaveAccess",
"(",
"$",
"item_limit",
"=",
"null",
")",
"{",
"$",
"can_access",
"=",
"false",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"item_limit",
")",
"||",
"$",
"item_limit",
"===",
"'author'",
")",
"{",
"$",
"can_access",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"item_limit",
"===",
"'developer'",
"&&",
"Symphony",
"::",
"Author",
"(",
")",
"->",
"isDeveloper",
"(",
")",
")",
"{",
"$",
"can_access",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"item_limit",
"===",
"'manager'",
"&&",
"(",
"Symphony",
"::",
"Author",
"(",
")",
"->",
"isManager",
"(",
")",
"||",
"Symphony",
"::",
"Author",
"(",
")",
"->",
"isDeveloper",
"(",
")",
")",
")",
"{",
"$",
"can_access",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"item_limit",
"===",
"'primary'",
"&&",
"Symphony",
"::",
"Author",
"(",
")",
"->",
"isPrimaryAccount",
"(",
")",
")",
"{",
"$",
"can_access",
"=",
"true",
";",
"}",
"return",
"$",
"can_access",
";",
"}"
] | Given the limit of the current navigation item or page, this function
returns if the current Author can access that item or not.
@since Symphony 2.5.1
@param string $item_limit
@return boolean | [
"Given",
"the",
"limit",
"of",
"the",
"current",
"navigation",
"item",
"or",
"page",
"this",
"function",
"returns",
"if",
"the",
"current",
"Author",
"can",
"access",
"that",
"item",
"or",
"not",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L604-L619 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.generate | public function generate($page = null)
{
$this->Wrapper->appendChild($this->Header);
// Add horizontal drawers (inside #context)
if (isset($this->Drawer['horizontal'])) {
$this->Context->appendChildArray($this->Drawer['horizontal']);
}
$this->Wrapper->appendChild($this->Context);
// Add vertical-left drawers (between #context and #contents)
if (isset($this->Drawer['vertical-left'])) {
$this->Contents->appendChildArray($this->Drawer['vertical-left']);
}
// Add vertical-right drawers (after #contents)
if (isset($this->Drawer['vertical-right'])) {
$this->Contents->appendChildArray($this->Drawer['vertical-right']);
}
$this->Wrapper->appendChild($this->Contents);
$this->Body->appendChild($this->Wrapper);
$this->__appendBodyId();
$this->__appendBodyClass($this->_context);
/**
* This is just prior to the page headers being rendered, and is suitable for changing them
* @delegate PreRenderHeaders
* @since Symphony 2.7.0
* @param string $context
* '/backend/'
*/
Symphony::ExtensionManager()->notifyMembers('PreRenderHeaders', '/backend/');
return parent::generate($page);
} | php | public function generate($page = null)
{
$this->Wrapper->appendChild($this->Header);
// Add horizontal drawers (inside #context)
if (isset($this->Drawer['horizontal'])) {
$this->Context->appendChildArray($this->Drawer['horizontal']);
}
$this->Wrapper->appendChild($this->Context);
// Add vertical-left drawers (between #context and #contents)
if (isset($this->Drawer['vertical-left'])) {
$this->Contents->appendChildArray($this->Drawer['vertical-left']);
}
// Add vertical-right drawers (after #contents)
if (isset($this->Drawer['vertical-right'])) {
$this->Contents->appendChildArray($this->Drawer['vertical-right']);
}
$this->Wrapper->appendChild($this->Contents);
$this->Body->appendChild($this->Wrapper);
$this->__appendBodyId();
$this->__appendBodyClass($this->_context);
/**
* This is just prior to the page headers being rendered, and is suitable for changing them
* @delegate PreRenderHeaders
* @since Symphony 2.7.0
* @param string $context
* '/backend/'
*/
Symphony::ExtensionManager()->notifyMembers('PreRenderHeaders', '/backend/');
return parent::generate($page);
} | [
"public",
"function",
"generate",
"(",
"$",
"page",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"Wrapper",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"Header",
")",
";",
"// Add horizontal drawers (inside #context)",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"Drawer",
"[",
"'horizontal'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"Context",
"->",
"appendChildArray",
"(",
"$",
"this",
"->",
"Drawer",
"[",
"'horizontal'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"Wrapper",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"Context",
")",
";",
"// Add vertical-left drawers (between #context and #contents)",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"Drawer",
"[",
"'vertical-left'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"Contents",
"->",
"appendChildArray",
"(",
"$",
"this",
"->",
"Drawer",
"[",
"'vertical-left'",
"]",
")",
";",
"}",
"// Add vertical-right drawers (after #contents)",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"Drawer",
"[",
"'vertical-right'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"Contents",
"->",
"appendChildArray",
"(",
"$",
"this",
"->",
"Drawer",
"[",
"'vertical-right'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"Wrapper",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"Contents",
")",
";",
"$",
"this",
"->",
"Body",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"Wrapper",
")",
";",
"$",
"this",
"->",
"__appendBodyId",
"(",
")",
";",
"$",
"this",
"->",
"__appendBodyClass",
"(",
"$",
"this",
"->",
"_context",
")",
";",
"/**\n * This is just prior to the page headers being rendered, and is suitable for changing them\n * @delegate PreRenderHeaders\n * @since Symphony 2.7.0\n * @param string $context\n * '/backend/'\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'PreRenderHeaders'",
",",
"'/backend/'",
")",
";",
"return",
"parent",
"::",
"generate",
"(",
"$",
"page",
")",
";",
"}"
] | Appends the `$this->Header`, `$this->Context` and `$this->Contents`
to `$this->Wrapper` before adding the ID and class attributes for
the `<body>` element. This function will also place any Drawer elements
in their relevant positions in the page. After this has completed the
parent `generate()` is called which will convert the `XMLElement`'s
into strings ready for output.
@see core.HTMLPage#generate()
@param null $page
@return string | [
"Appends",
"the",
"$this",
"-",
">",
"Header",
"$this",
"-",
">",
"Context",
"and",
"$this",
"-",
">",
"Contents",
"to",
"$this",
"-",
">",
"Wrapper",
"before",
"adding",
"the",
"ID",
"and",
"class",
"attributes",
"for",
"the",
"<body",
">",
"element",
".",
"This",
"function",
"will",
"also",
"place",
"any",
"Drawer",
"elements",
"in",
"their",
"relevant",
"positions",
"in",
"the",
"page",
".",
"After",
"this",
"has",
"completed",
"the",
"parent",
"generate",
"()",
"is",
"called",
"which",
"will",
"convert",
"the",
"XMLElement",
"s",
"into",
"strings",
"ready",
"for",
"output",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L633-L671 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.__appendBodyId | private function __appendBodyId()
{
// trim "content" from beginning of class name
$body_id = preg_replace("/^content/", '', get_class($this));
// lowercase any uppercase letters and prefix with a hyphen
$body_id = trim(
preg_replace_callback(
"/([A-Z])/",
function($id) {
return "-" . strtolower($id[0]);
},
$body_id
),
'-'
);
if (!empty($body_id)) {
$this->Body->setAttribute('id', trim($body_id));
}
} | php | private function __appendBodyId()
{
// trim "content" from beginning of class name
$body_id = preg_replace("/^content/", '', get_class($this));
// lowercase any uppercase letters and prefix with a hyphen
$body_id = trim(
preg_replace_callback(
"/([A-Z])/",
function($id) {
return "-" . strtolower($id[0]);
},
$body_id
),
'-'
);
if (!empty($body_id)) {
$this->Body->setAttribute('id', trim($body_id));
}
} | [
"private",
"function",
"__appendBodyId",
"(",
")",
"{",
"// trim \"content\" from beginning of class name",
"$",
"body_id",
"=",
"preg_replace",
"(",
"\"/^content/\"",
",",
"''",
",",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"// lowercase any uppercase letters and prefix with a hyphen",
"$",
"body_id",
"=",
"trim",
"(",
"preg_replace_callback",
"(",
"\"/([A-Z])/\"",
",",
"function",
"(",
"$",
"id",
")",
"{",
"return",
"\"-\"",
".",
"strtolower",
"(",
"$",
"id",
"[",
"0",
"]",
")",
";",
"}",
",",
"$",
"body_id",
")",
",",
"'-'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"body_id",
")",
")",
"{",
"$",
"this",
"->",
"Body",
"->",
"setAttribute",
"(",
"'id'",
",",
"trim",
"(",
"$",
"body_id",
")",
")",
";",
"}",
"}"
] | Uses this pages PHP classname as the `<body>` ID attribute.
This function removes 'content' from the start of the classname
and converts all uppercase letters to lowercase and prefixes them
with a hyphen. | [
"Uses",
"this",
"pages",
"PHP",
"classname",
"as",
"the",
"<body",
">",
"ID",
"attribute",
".",
"This",
"function",
"removes",
"content",
"from",
"the",
"start",
"of",
"the",
"classname",
"and",
"converts",
"all",
"uppercase",
"letters",
"to",
"lowercase",
"and",
"prefixes",
"them",
"with",
"a",
"hyphen",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L679-L699 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.__appendBodyClass | private function __appendBodyClass(array $context = array())
{
$body_class = '';
foreach ($context as $key => $value) {
if (is_numeric($value)) {
$value = 'id-' . $value;
// Add prefixes to all context values by making the
// class be {key}-{value}. #1397 ^BA
} elseif (!is_numeric($key) && isset($value)) {
// Skip arrays
if (is_array($value)) {
$value = null;
} else {
$value = str_replace('_', '-', $key) . '-'. $value;
}
}
if ($value !== null) {
$body_class .= trim($value) . ' ';
}
}
$classes = array_merge(explode(' ', trim($body_class)), explode(' ', trim($this->_body_class)));
$body_class = trim(implode(' ', $classes));
if (!empty($body_class)) {
$this->Body->setAttribute('class', $body_class);
}
} | php | private function __appendBodyClass(array $context = array())
{
$body_class = '';
foreach ($context as $key => $value) {
if (is_numeric($value)) {
$value = 'id-' . $value;
// Add prefixes to all context values by making the
// class be {key}-{value}. #1397 ^BA
} elseif (!is_numeric($key) && isset($value)) {
// Skip arrays
if (is_array($value)) {
$value = null;
} else {
$value = str_replace('_', '-', $key) . '-'. $value;
}
}
if ($value !== null) {
$body_class .= trim($value) . ' ';
}
}
$classes = array_merge(explode(' ', trim($body_class)), explode(' ', trim($this->_body_class)));
$body_class = trim(implode(' ', $classes));
if (!empty($body_class)) {
$this->Body->setAttribute('class', $body_class);
}
} | [
"private",
"function",
"__appendBodyClass",
"(",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"$",
"body_class",
"=",
"''",
";",
"foreach",
"(",
"$",
"context",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"'id-'",
".",
"$",
"value",
";",
"// Add prefixes to all context values by making the",
"// class be {key}-{value}. #1397 ^BA",
"}",
"elseif",
"(",
"!",
"is_numeric",
"(",
"$",
"key",
")",
"&&",
"isset",
"(",
"$",
"value",
")",
")",
"{",
"// Skip arrays",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"str_replace",
"(",
"'_'",
",",
"'-'",
",",
"$",
"key",
")",
".",
"'-'",
".",
"$",
"value",
";",
"}",
"}",
"if",
"(",
"$",
"value",
"!==",
"null",
")",
"{",
"$",
"body_class",
".=",
"trim",
"(",
"$",
"value",
")",
".",
"' '",
";",
"}",
"}",
"$",
"classes",
"=",
"array_merge",
"(",
"explode",
"(",
"' '",
",",
"trim",
"(",
"$",
"body_class",
")",
")",
",",
"explode",
"(",
"' '",
",",
"trim",
"(",
"$",
"this",
"->",
"_body_class",
")",
")",
")",
";",
"$",
"body_class",
"=",
"trim",
"(",
"implode",
"(",
"' '",
",",
"$",
"classes",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"body_class",
")",
")",
"{",
"$",
"this",
"->",
"Body",
"->",
"setAttribute",
"(",
"'class'",
",",
"$",
"body_class",
")",
";",
"}",
"}"
] | Given the context of the current page, which is an associative
array, this function will append the values to the page's body as
classes. If an context value is numeric it will be prepended by 'id-',
otherwise all classes will be prefixed by the context key.
@param array $context | [
"Given",
"the",
"context",
"of",
"the",
"current",
"page",
"which",
"is",
"an",
"associative",
"array",
"this",
"function",
"will",
"append",
"the",
"values",
"to",
"the",
"page",
"s",
"body",
"as",
"classes",
".",
"If",
"an",
"context",
"value",
"is",
"numeric",
"it",
"will",
"be",
"prepended",
"by",
"id",
"-",
"otherwise",
"all",
"classes",
"will",
"be",
"prefixed",
"by",
"the",
"context",
"key",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L709-L739 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.__switchboard | public function __switchboard($type = 'view')
{
if (!isset($this->_context[0]) || trim($this->_context[0]) === '') {
$context = 'index';
} else {
$context = $this->_context[0];
}
$function = ($type == 'action' ? '__action' : '__view') . ucfirst($context);
if (!method_exists($this, $function)) {
// If there is no action function, just return without doing anything
if ($type == 'action') {
return;
}
Administration::instance()->errorPageNotFound();
}
$this->$function(null);
} | php | public function __switchboard($type = 'view')
{
if (!isset($this->_context[0]) || trim($this->_context[0]) === '') {
$context = 'index';
} else {
$context = $this->_context[0];
}
$function = ($type == 'action' ? '__action' : '__view') . ucfirst($context);
if (!method_exists($this, $function)) {
// If there is no action function, just return without doing anything
if ($type == 'action') {
return;
}
Administration::instance()->errorPageNotFound();
}
$this->$function(null);
} | [
"public",
"function",
"__switchboard",
"(",
"$",
"type",
"=",
"'view'",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_context",
"[",
"0",
"]",
")",
"||",
"trim",
"(",
"$",
"this",
"->",
"_context",
"[",
"0",
"]",
")",
"===",
"''",
")",
"{",
"$",
"context",
"=",
"'index'",
";",
"}",
"else",
"{",
"$",
"context",
"=",
"$",
"this",
"->",
"_context",
"[",
"0",
"]",
";",
"}",
"$",
"function",
"=",
"(",
"$",
"type",
"==",
"'action'",
"?",
"'__action'",
":",
"'__view'",
")",
".",
"ucfirst",
"(",
"$",
"context",
")",
";",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
",",
"$",
"function",
")",
")",
"{",
"// If there is no action function, just return without doing anything",
"if",
"(",
"$",
"type",
"==",
"'action'",
")",
"{",
"return",
";",
"}",
"Administration",
"::",
"instance",
"(",
")",
"->",
"errorPageNotFound",
"(",
")",
";",
"}",
"$",
"this",
"->",
"$",
"function",
"(",
"null",
")",
";",
"}"
] | The `__switchboard` function acts as a controller to display content
based off the $type. By default, the `$type` is 'view' but it can be set
also set to 'action'. The `$type` is prepended by __ and the context is
append to the $type to create the name of the function that will provide
that logic. For example, if the $type was action and the context of the
current page was new, the resulting function to be called would be named
`__actionNew()`. If an action function is not provided by the Page, this function
returns nothing, however if a view function is not provided, a 404 page
will be returned.
@param string $type
Either 'view' or 'action', by default this will be 'view'
@throws SymphonyErrorPage | [
"The",
"__switchboard",
"function",
"acts",
"as",
"a",
"controller",
"to",
"display",
"content",
"based",
"off",
"the",
"$type",
".",
"By",
"default",
"the",
"$type",
"is",
"view",
"but",
"it",
"can",
"be",
"set",
"also",
"set",
"to",
"action",
".",
"The",
"$type",
"is",
"prepended",
"by",
"__",
"and",
"the",
"context",
"is",
"append",
"to",
"the",
"$type",
"to",
"create",
"the",
"name",
"of",
"the",
"function",
"that",
"will",
"provide",
"that",
"logic",
".",
"For",
"example",
"if",
"the",
"$type",
"was",
"action",
"and",
"the",
"context",
"of",
"the",
"current",
"page",
"was",
"new",
"the",
"resulting",
"function",
"to",
"be",
"called",
"would",
"be",
"named",
"__actionNew",
"()",
".",
"If",
"an",
"action",
"function",
"is",
"not",
"provided",
"by",
"the",
"Page",
"this",
"function",
"returns",
"nothing",
"however",
"if",
"a",
"view",
"function",
"is",
"not",
"provided",
"a",
"404",
"page",
"will",
"be",
"returned",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L782-L802 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.appendAlert | public function appendAlert()
{
/**
* Allows for appending of alerts. Administration::instance()->Page->Alert is way to tell what
* is currently in the system
*
* @delegate AppendPageAlert
* @param string $context
* '/backend/'
*/
Symphony::ExtensionManager()->notifyMembers('AppendPageAlert', '/backend/');
if (!is_array($this->Alert) || empty($this->Alert)) {
return;
}
usort($this->Alert, array($this, 'sortAlerts'));
// Using prependChild ruins our order (it's backwards, but with most
// recent notices coming after oldest notices), so reversing the array
// fixes this. We need to prepend so that without Javascript the notices
// are at the top of the markup. See #1312
$this->Alert = array_reverse($this->Alert);
foreach ($this->Alert as $alert) {
$this->Header->prependChild($alert->asXML());
}
} | php | public function appendAlert()
{
/**
* Allows for appending of alerts. Administration::instance()->Page->Alert is way to tell what
* is currently in the system
*
* @delegate AppendPageAlert
* @param string $context
* '/backend/'
*/
Symphony::ExtensionManager()->notifyMembers('AppendPageAlert', '/backend/');
if (!is_array($this->Alert) || empty($this->Alert)) {
return;
}
usort($this->Alert, array($this, 'sortAlerts'));
// Using prependChild ruins our order (it's backwards, but with most
// recent notices coming after oldest notices), so reversing the array
// fixes this. We need to prepend so that without Javascript the notices
// are at the top of the markup. See #1312
$this->Alert = array_reverse($this->Alert);
foreach ($this->Alert as $alert) {
$this->Header->prependChild($alert->asXML());
}
} | [
"public",
"function",
"appendAlert",
"(",
")",
"{",
"/**\n * Allows for appending of alerts. Administration::instance()->Page->Alert is way to tell what\n * is currently in the system\n *\n * @delegate AppendPageAlert\n * @param string $context\n * '/backend/'\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'AppendPageAlert'",
",",
"'/backend/'",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"Alert",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"Alert",
")",
")",
"{",
"return",
";",
"}",
"usort",
"(",
"$",
"this",
"->",
"Alert",
",",
"array",
"(",
"$",
"this",
",",
"'sortAlerts'",
")",
")",
";",
"// Using prependChild ruins our order (it's backwards, but with most",
"// recent notices coming after oldest notices), so reversing the array",
"// fixes this. We need to prepend so that without Javascript the notices",
"// are at the top of the markup. See #1312",
"$",
"this",
"->",
"Alert",
"=",
"array_reverse",
"(",
"$",
"this",
"->",
"Alert",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"Alert",
"as",
"$",
"alert",
")",
"{",
"$",
"this",
"->",
"Header",
"->",
"prependChild",
"(",
"$",
"alert",
"->",
"asXML",
"(",
")",
")",
";",
"}",
"}"
] | If `$this->Alert` is set, it will be added to this page. The
`AppendPageAlert` delegate is fired to allow extensions to provide their
their own Alert messages for this page. Since Symphony 2.3, there may be
more than one `Alert` per page. Alerts are displayed in the order of
severity, with Errors first, then Success alerts followed by Notices.
@uses AppendPageAlert | [
"If",
"$this",
"-",
">",
"Alert",
"is",
"set",
"it",
"will",
"be",
"added",
"to",
"this",
"page",
".",
"The",
"AppendPageAlert",
"delegate",
"is",
"fired",
"to",
"allow",
"extensions",
"to",
"provide",
"their",
"their",
"own",
"Alert",
"messages",
"for",
"this",
"page",
".",
"Since",
"Symphony",
"2",
".",
"3",
"there",
"may",
"be",
"more",
"than",
"one",
"Alert",
"per",
"page",
".",
"Alerts",
"are",
"displayed",
"in",
"the",
"order",
"of",
"severity",
"with",
"Errors",
"first",
"then",
"Success",
"alerts",
"followed",
"by",
"Notices",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L813-L841 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.sortAlerts | public function sortAlerts($a, $b)
{
if ($a->{'type'} === $b->{'type'}) {
return 0;
}
if (
($a->{'type'} === Alert::ERROR && $a->{'type'} !== $b->{'type'})
|| ($a->{'type'} === Alert::SUCCESS && $b->{'type'} === Alert::NOTICE)
) {
return -1;
}
return 1;
} | php | public function sortAlerts($a, $b)
{
if ($a->{'type'} === $b->{'type'}) {
return 0;
}
if (
($a->{'type'} === Alert::ERROR && $a->{'type'} !== $b->{'type'})
|| ($a->{'type'} === Alert::SUCCESS && $b->{'type'} === Alert::NOTICE)
) {
return -1;
}
return 1;
} | [
"public",
"function",
"sortAlerts",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"a",
"->",
"{",
"'type'",
"}",
"===",
"$",
"b",
"->",
"{",
"'type'",
"}",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"(",
"$",
"a",
"->",
"{",
"'type'",
"}",
"===",
"Alert",
"::",
"ERROR",
"&&",
"$",
"a",
"->",
"{",
"'type'",
"}",
"!==",
"$",
"b",
"->",
"{",
"'type'",
"}",
")",
"||",
"(",
"$",
"a",
"->",
"{",
"'type'",
"}",
"===",
"Alert",
"::",
"SUCCESS",
"&&",
"$",
"b",
"->",
"{",
"'type'",
"}",
"===",
"Alert",
"::",
"NOTICE",
")",
")",
"{",
"return",
"-",
"1",
";",
"}",
"return",
"1",
";",
"}"
] | Errors first, success next, then notices. | [
"Errors",
"first",
"success",
"next",
"then",
"notices",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L844-L858 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.appendNavigation | public function appendNavigation()
{
$nav = $this->getNavigationArray();
/**
* Immediately before displaying the admin navigation. Provided with the
* navigation array. Manipulating it will alter the navigation for all pages.
*
* @delegate NavigationPreRender
* @param string $context
* '/backend/'
* @param array $nav
* An associative array of the current navigation, passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('NavigationPreRender', '/backend/', array(
'navigation' => &$nav,
));
$navElement = new XMLElement('nav', null, array('id' => 'nav', 'role' => 'navigation'));
$contentNav = new XMLElement('ul', null, array('class' => 'content', 'role' => 'menubar'));
$structureNav = new XMLElement('ul', null, array('class' => 'structure', 'role' => 'menubar'));
foreach ($nav as $n) {
if (isset($n['visible']) && $n['visible'] === 'no') {
continue;
}
$item_limit = isset($n['limit']) ? $n['limit'] : null;
if ($this->doesAuthorHaveAccess($item_limit)) {
$xGroup = new XMLElement('li', General::sanitize($n['name']), array('role' => 'presentation'));
if (isset($n['class']) && trim($n['name']) !== '') {
$xGroup->setAttribute('class', $n['class']);
}
$hasChildren = false;
$xChildren = new XMLElement('ul', null, array('role' => 'menu'));
if (is_array($n['children']) && !empty($n['children'])) {
foreach ($n['children'] as $c) {
// adapt for Yes and yes
if (strtolower($c['visible']) !== 'yes') {
continue;
}
$child_item_limit = isset($c['limit']) ? $c['limit'] : null;
if ($this->doesAuthorHaveAccess($child_item_limit)) {
$xChild = new XMLElement('li');
$xChild->setAttribute('role', 'menuitem');
$linkChild = Widget::Anchor(General::sanitize($c['name']), SYMPHONY_URL . $c['link']);
if (isset($c['target'])) {
$linkChild->setAttribute('target', $c['target']);
}
$xChild->appendChild($linkChild);
$xChildren->appendChild($xChild);
$hasChildren = true;
}
}
if ($hasChildren) {
$xGroup->setAttribute('aria-haspopup', 'true');
$xGroup->appendChild($xChildren);
if ($n['type'] === 'content') {
$contentNav->appendChild($xGroup);
} elseif ($n['type'] === 'structure') {
$structureNav->prependChild($xGroup);
}
}
}
}
}
$navElement->appendChild($contentNav);
$navElement->appendChild($structureNav);
$this->Header->appendChild($navElement);
Symphony::Profiler()->sample('Navigation Built', PROFILE_LAP);
} | php | public function appendNavigation()
{
$nav = $this->getNavigationArray();
/**
* Immediately before displaying the admin navigation. Provided with the
* navigation array. Manipulating it will alter the navigation for all pages.
*
* @delegate NavigationPreRender
* @param string $context
* '/backend/'
* @param array $nav
* An associative array of the current navigation, passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('NavigationPreRender', '/backend/', array(
'navigation' => &$nav,
));
$navElement = new XMLElement('nav', null, array('id' => 'nav', 'role' => 'navigation'));
$contentNav = new XMLElement('ul', null, array('class' => 'content', 'role' => 'menubar'));
$structureNav = new XMLElement('ul', null, array('class' => 'structure', 'role' => 'menubar'));
foreach ($nav as $n) {
if (isset($n['visible']) && $n['visible'] === 'no') {
continue;
}
$item_limit = isset($n['limit']) ? $n['limit'] : null;
if ($this->doesAuthorHaveAccess($item_limit)) {
$xGroup = new XMLElement('li', General::sanitize($n['name']), array('role' => 'presentation'));
if (isset($n['class']) && trim($n['name']) !== '') {
$xGroup->setAttribute('class', $n['class']);
}
$hasChildren = false;
$xChildren = new XMLElement('ul', null, array('role' => 'menu'));
if (is_array($n['children']) && !empty($n['children'])) {
foreach ($n['children'] as $c) {
// adapt for Yes and yes
if (strtolower($c['visible']) !== 'yes') {
continue;
}
$child_item_limit = isset($c['limit']) ? $c['limit'] : null;
if ($this->doesAuthorHaveAccess($child_item_limit)) {
$xChild = new XMLElement('li');
$xChild->setAttribute('role', 'menuitem');
$linkChild = Widget::Anchor(General::sanitize($c['name']), SYMPHONY_URL . $c['link']);
if (isset($c['target'])) {
$linkChild->setAttribute('target', $c['target']);
}
$xChild->appendChild($linkChild);
$xChildren->appendChild($xChild);
$hasChildren = true;
}
}
if ($hasChildren) {
$xGroup->setAttribute('aria-haspopup', 'true');
$xGroup->appendChild($xChildren);
if ($n['type'] === 'content') {
$contentNav->appendChild($xGroup);
} elseif ($n['type'] === 'structure') {
$structureNav->prependChild($xGroup);
}
}
}
}
}
$navElement->appendChild($contentNav);
$navElement->appendChild($structureNav);
$this->Header->appendChild($navElement);
Symphony::Profiler()->sample('Navigation Built', PROFILE_LAP);
} | [
"public",
"function",
"appendNavigation",
"(",
")",
"{",
"$",
"nav",
"=",
"$",
"this",
"->",
"getNavigationArray",
"(",
")",
";",
"/**\n * Immediately before displaying the admin navigation. Provided with the\n * navigation array. Manipulating it will alter the navigation for all pages.\n *\n * @delegate NavigationPreRender\n * @param string $context\n * '/backend/'\n * @param array $nav\n * An associative array of the current navigation, passed by reference\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'NavigationPreRender'",
",",
"'/backend/'",
",",
"array",
"(",
"'navigation'",
"=>",
"&",
"$",
"nav",
",",
")",
")",
";",
"$",
"navElement",
"=",
"new",
"XMLElement",
"(",
"'nav'",
",",
"null",
",",
"array",
"(",
"'id'",
"=>",
"'nav'",
",",
"'role'",
"=>",
"'navigation'",
")",
")",
";",
"$",
"contentNav",
"=",
"new",
"XMLElement",
"(",
"'ul'",
",",
"null",
",",
"array",
"(",
"'class'",
"=>",
"'content'",
",",
"'role'",
"=>",
"'menubar'",
")",
")",
";",
"$",
"structureNav",
"=",
"new",
"XMLElement",
"(",
"'ul'",
",",
"null",
",",
"array",
"(",
"'class'",
"=>",
"'structure'",
",",
"'role'",
"=>",
"'menubar'",
")",
")",
";",
"foreach",
"(",
"$",
"nav",
"as",
"$",
"n",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"n",
"[",
"'visible'",
"]",
")",
"&&",
"$",
"n",
"[",
"'visible'",
"]",
"===",
"'no'",
")",
"{",
"continue",
";",
"}",
"$",
"item_limit",
"=",
"isset",
"(",
"$",
"n",
"[",
"'limit'",
"]",
")",
"?",
"$",
"n",
"[",
"'limit'",
"]",
":",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"doesAuthorHaveAccess",
"(",
"$",
"item_limit",
")",
")",
"{",
"$",
"xGroup",
"=",
"new",
"XMLElement",
"(",
"'li'",
",",
"General",
"::",
"sanitize",
"(",
"$",
"n",
"[",
"'name'",
"]",
")",
",",
"array",
"(",
"'role'",
"=>",
"'presentation'",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"n",
"[",
"'class'",
"]",
")",
"&&",
"trim",
"(",
"$",
"n",
"[",
"'name'",
"]",
")",
"!==",
"''",
")",
"{",
"$",
"xGroup",
"->",
"setAttribute",
"(",
"'class'",
",",
"$",
"n",
"[",
"'class'",
"]",
")",
";",
"}",
"$",
"hasChildren",
"=",
"false",
";",
"$",
"xChildren",
"=",
"new",
"XMLElement",
"(",
"'ul'",
",",
"null",
",",
"array",
"(",
"'role'",
"=>",
"'menu'",
")",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"n",
"[",
"'children'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"n",
"[",
"'children'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"n",
"[",
"'children'",
"]",
"as",
"$",
"c",
")",
"{",
"// adapt for Yes and yes",
"if",
"(",
"strtolower",
"(",
"$",
"c",
"[",
"'visible'",
"]",
")",
"!==",
"'yes'",
")",
"{",
"continue",
";",
"}",
"$",
"child_item_limit",
"=",
"isset",
"(",
"$",
"c",
"[",
"'limit'",
"]",
")",
"?",
"$",
"c",
"[",
"'limit'",
"]",
":",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"doesAuthorHaveAccess",
"(",
"$",
"child_item_limit",
")",
")",
"{",
"$",
"xChild",
"=",
"new",
"XMLElement",
"(",
"'li'",
")",
";",
"$",
"xChild",
"->",
"setAttribute",
"(",
"'role'",
",",
"'menuitem'",
")",
";",
"$",
"linkChild",
"=",
"Widget",
"::",
"Anchor",
"(",
"General",
"::",
"sanitize",
"(",
"$",
"c",
"[",
"'name'",
"]",
")",
",",
"SYMPHONY_URL",
".",
"$",
"c",
"[",
"'link'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"c",
"[",
"'target'",
"]",
")",
")",
"{",
"$",
"linkChild",
"->",
"setAttribute",
"(",
"'target'",
",",
"$",
"c",
"[",
"'target'",
"]",
")",
";",
"}",
"$",
"xChild",
"->",
"appendChild",
"(",
"$",
"linkChild",
")",
";",
"$",
"xChildren",
"->",
"appendChild",
"(",
"$",
"xChild",
")",
";",
"$",
"hasChildren",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"$",
"hasChildren",
")",
"{",
"$",
"xGroup",
"->",
"setAttribute",
"(",
"'aria-haspopup'",
",",
"'true'",
")",
";",
"$",
"xGroup",
"->",
"appendChild",
"(",
"$",
"xChildren",
")",
";",
"if",
"(",
"$",
"n",
"[",
"'type'",
"]",
"===",
"'content'",
")",
"{",
"$",
"contentNav",
"->",
"appendChild",
"(",
"$",
"xGroup",
")",
";",
"}",
"elseif",
"(",
"$",
"n",
"[",
"'type'",
"]",
"===",
"'structure'",
")",
"{",
"$",
"structureNav",
"->",
"prependChild",
"(",
"$",
"xGroup",
")",
";",
"}",
"}",
"}",
"}",
"}",
"$",
"navElement",
"->",
"appendChild",
"(",
"$",
"contentNav",
")",
";",
"$",
"navElement",
"->",
"appendChild",
"(",
"$",
"structureNav",
")",
";",
"$",
"this",
"->",
"Header",
"->",
"appendChild",
"(",
"$",
"navElement",
")",
";",
"Symphony",
"::",
"Profiler",
"(",
")",
"->",
"sample",
"(",
"'Navigation Built'",
",",
"PROFILE_LAP",
")",
";",
"}"
] | This function will append the Navigation to the AdministrationPage.
It fires a delegate, NavigationPreRender, to allow extensions to manipulate
the navigation. Extensions should not use this to add their own navigation,
they should provide the navigation through their fetchNavigation function.
Note with the Section navigation groups, if there is only one section in a group
and that section is set to visible, the group will not appear in the navigation.
@uses NavigationPreRender
@see getNavigationArray()
@see toolkit.Extension#fetchNavigation() | [
"This",
"function",
"will",
"append",
"the",
"Navigation",
"to",
"the",
"AdministrationPage",
".",
"It",
"fires",
"a",
"delegate",
"NavigationPreRender",
"to",
"allow",
"extensions",
"to",
"manipulate",
"the",
"navigation",
".",
"Extensions",
"should",
"not",
"use",
"this",
"to",
"add",
"their",
"own",
"navigation",
"they",
"should",
"provide",
"the",
"navigation",
"through",
"their",
"fetchNavigation",
"function",
".",
"Note",
"with",
"the",
"Section",
"navigation",
"groups",
"if",
"there",
"is",
"only",
"one",
"section",
"in",
"a",
"group",
"and",
"that",
"section",
"is",
"set",
"to",
"visible",
"the",
"group",
"will",
"not",
"appear",
"in",
"the",
"navigation",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L872-L951 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.buildXmlNavigation | private function buildXmlNavigation(&$nav)
{
$xml = simplexml_load_file(ASSETS . '/xml/navigation.xml');
// Loop over the default Symphony navigation file, converting
// it into an associative array representation
foreach ($xml->xpath('/navigation/group') as $n) {
$index = (string)$n->attributes()->index;
$children = $n->xpath('children/item');
$content = $n->attributes();
// If the index is already set, increment the index and check again.
// Rinse and repeat until the index is not set.
if (isset($nav[$index])) {
do {
$index++;
} while (isset($nav[$index]));
}
$nav[$index] = array(
'name' => __(strval($content->name)),
'type' => 'structure',
'index' => $index,
'children' => array()
);
if (strlen(trim((string)$content->limit)) > 0) {
$nav[$index]['limit'] = (string)$content->limit;
}
if (count($children) > 0) {
foreach ($children as $child) {
$item = array(
'link' => (string)$child->attributes()->link,
'name' => __(strval($child->attributes()->name)),
'visible' => ((string)$child->attributes()->visible == 'no' ? 'no' : 'yes'),
);
$limit = (string)$child->attributes()->limit;
if (strlen(trim($limit)) > 0) {
$item['limit'] = $limit;
}
$nav[$index]['children'][] = $item;
}
}
}
} | php | private function buildXmlNavigation(&$nav)
{
$xml = simplexml_load_file(ASSETS . '/xml/navigation.xml');
// Loop over the default Symphony navigation file, converting
// it into an associative array representation
foreach ($xml->xpath('/navigation/group') as $n) {
$index = (string)$n->attributes()->index;
$children = $n->xpath('children/item');
$content = $n->attributes();
// If the index is already set, increment the index and check again.
// Rinse and repeat until the index is not set.
if (isset($nav[$index])) {
do {
$index++;
} while (isset($nav[$index]));
}
$nav[$index] = array(
'name' => __(strval($content->name)),
'type' => 'structure',
'index' => $index,
'children' => array()
);
if (strlen(trim((string)$content->limit)) > 0) {
$nav[$index]['limit'] = (string)$content->limit;
}
if (count($children) > 0) {
foreach ($children as $child) {
$item = array(
'link' => (string)$child->attributes()->link,
'name' => __(strval($child->attributes()->name)),
'visible' => ((string)$child->attributes()->visible == 'no' ? 'no' : 'yes'),
);
$limit = (string)$child->attributes()->limit;
if (strlen(trim($limit)) > 0) {
$item['limit'] = $limit;
}
$nav[$index]['children'][] = $item;
}
}
}
} | [
"private",
"function",
"buildXmlNavigation",
"(",
"&",
"$",
"nav",
")",
"{",
"$",
"xml",
"=",
"simplexml_load_file",
"(",
"ASSETS",
".",
"'/xml/navigation.xml'",
")",
";",
"// Loop over the default Symphony navigation file, converting",
"// it into an associative array representation",
"foreach",
"(",
"$",
"xml",
"->",
"xpath",
"(",
"'/navigation/group'",
")",
"as",
"$",
"n",
")",
"{",
"$",
"index",
"=",
"(",
"string",
")",
"$",
"n",
"->",
"attributes",
"(",
")",
"->",
"index",
";",
"$",
"children",
"=",
"$",
"n",
"->",
"xpath",
"(",
"'children/item'",
")",
";",
"$",
"content",
"=",
"$",
"n",
"->",
"attributes",
"(",
")",
";",
"// If the index is already set, increment the index and check again.",
"// Rinse and repeat until the index is not set.",
"if",
"(",
"isset",
"(",
"$",
"nav",
"[",
"$",
"index",
"]",
")",
")",
"{",
"do",
"{",
"$",
"index",
"++",
";",
"}",
"while",
"(",
"isset",
"(",
"$",
"nav",
"[",
"$",
"index",
"]",
")",
")",
";",
"}",
"$",
"nav",
"[",
"$",
"index",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"__",
"(",
"strval",
"(",
"$",
"content",
"->",
"name",
")",
")",
",",
"'type'",
"=>",
"'structure'",
",",
"'index'",
"=>",
"$",
"index",
",",
"'children'",
"=>",
"array",
"(",
")",
")",
";",
"if",
"(",
"strlen",
"(",
"trim",
"(",
"(",
"string",
")",
"$",
"content",
"->",
"limit",
")",
")",
">",
"0",
")",
"{",
"$",
"nav",
"[",
"$",
"index",
"]",
"[",
"'limit'",
"]",
"=",
"(",
"string",
")",
"$",
"content",
"->",
"limit",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"children",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"item",
"=",
"array",
"(",
"'link'",
"=>",
"(",
"string",
")",
"$",
"child",
"->",
"attributes",
"(",
")",
"->",
"link",
",",
"'name'",
"=>",
"__",
"(",
"strval",
"(",
"$",
"child",
"->",
"attributes",
"(",
")",
"->",
"name",
")",
")",
",",
"'visible'",
"=>",
"(",
"(",
"string",
")",
"$",
"child",
"->",
"attributes",
"(",
")",
"->",
"visible",
"==",
"'no'",
"?",
"'no'",
":",
"'yes'",
")",
",",
")",
";",
"$",
"limit",
"=",
"(",
"string",
")",
"$",
"child",
"->",
"attributes",
"(",
")",
"->",
"limit",
";",
"if",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"limit",
")",
")",
">",
"0",
")",
"{",
"$",
"item",
"[",
"'limit'",
"]",
"=",
"$",
"limit",
";",
"}",
"$",
"nav",
"[",
"$",
"index",
"]",
"[",
"'children'",
"]",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"}",
"}"
] | This method fills the `$nav` array with value
from the `ASSETS/xml/navigation.xml` file
@link http://github.com/symphonycms/symphony-2/blob/master/symphony/assets/xml/navigation.xml
@since Symphony 2.3.2
@param array $nav
The navigation array that will receive nav nodes | [
"This",
"method",
"fills",
"the",
"$nav",
"array",
"with",
"value",
"from",
"the",
"ASSETS",
"/",
"xml",
"/",
"navigation",
".",
"xml",
"file"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L984-L1032 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.buildSectionNavigation | private function buildSectionNavigation(&$nav)
{
// Build the section navigation, grouped by their navigation groups
$sections = SectionManager::fetch(null, 'asc', 'sortorder');
if (is_array($sections) && !empty($sections)) {
foreach ($sections as $s) {
$group_index = self::__navigationFindGroupIndex($nav, $s->get('navigation_group'));
if ($group_index === false) {
$group_index = General::array_find_available_index($nav, 0);
$nav[$group_index] = array(
'name' => $s->get('navigation_group'),
'type' => 'content',
'index' => $group_index,
'children' => array()
);
}
$hasAccess = true;
$url = '/publish/' . $s->get('handle') . '/';
/**
* Immediately after the core access rules allowed access to this page
* (i.e. not called if the core rules denied it).
* Extension developers must only further restrict access to it.
* Extension developers must also take care of checking the current value
* of the allowed parameter in order to prevent conflicts with other extensions.
* `$context['allowed'] = $context['allowed'] && customLogic();`
*
* @delegate CanAccessPage
* @since Symphony 2.7.0
* @see doesAuthorHaveAccess()
* @param string $context
* '/backend/'
* @param bool $allowed
* A flag to further restrict access to the page, passed by reference
* @param string $page_limit
* The computed page limit for the current page
* @param string $page_url
* The computed page url for the current page
* @param int $section.id
* The id of the section for this url
* @param string $section.handle
* The handle of the section for this url
*/
Symphony::ExtensionManager()->notifyMembers('CanAccessPage', '/backend/', array(
'allowed' => &$hasAccess,
'page_limit' => 'author',
'page_url' => $url,
'section' => array(
'id' => $s->get('id'),
'handle' => $s->get('handle')
),
));
if ($hasAccess) {
$nav[$group_index]['children'][] = array(
'link' => $url,
'name' => $s->get('name'),
'type' => 'section',
'section' => array(
'id' => $s->get('id'),
'handle' => $s->get('handle')
),
'visible' => ($s->get('hidden') == 'no' ? 'yes' : 'no')
);
}
}
}
} | php | private function buildSectionNavigation(&$nav)
{
// Build the section navigation, grouped by their navigation groups
$sections = SectionManager::fetch(null, 'asc', 'sortorder');
if (is_array($sections) && !empty($sections)) {
foreach ($sections as $s) {
$group_index = self::__navigationFindGroupIndex($nav, $s->get('navigation_group'));
if ($group_index === false) {
$group_index = General::array_find_available_index($nav, 0);
$nav[$group_index] = array(
'name' => $s->get('navigation_group'),
'type' => 'content',
'index' => $group_index,
'children' => array()
);
}
$hasAccess = true;
$url = '/publish/' . $s->get('handle') . '/';
/**
* Immediately after the core access rules allowed access to this page
* (i.e. not called if the core rules denied it).
* Extension developers must only further restrict access to it.
* Extension developers must also take care of checking the current value
* of the allowed parameter in order to prevent conflicts with other extensions.
* `$context['allowed'] = $context['allowed'] && customLogic();`
*
* @delegate CanAccessPage
* @since Symphony 2.7.0
* @see doesAuthorHaveAccess()
* @param string $context
* '/backend/'
* @param bool $allowed
* A flag to further restrict access to the page, passed by reference
* @param string $page_limit
* The computed page limit for the current page
* @param string $page_url
* The computed page url for the current page
* @param int $section.id
* The id of the section for this url
* @param string $section.handle
* The handle of the section for this url
*/
Symphony::ExtensionManager()->notifyMembers('CanAccessPage', '/backend/', array(
'allowed' => &$hasAccess,
'page_limit' => 'author',
'page_url' => $url,
'section' => array(
'id' => $s->get('id'),
'handle' => $s->get('handle')
),
));
if ($hasAccess) {
$nav[$group_index]['children'][] = array(
'link' => $url,
'name' => $s->get('name'),
'type' => 'section',
'section' => array(
'id' => $s->get('id'),
'handle' => $s->get('handle')
),
'visible' => ($s->get('hidden') == 'no' ? 'yes' : 'no')
);
}
}
}
} | [
"private",
"function",
"buildSectionNavigation",
"(",
"&",
"$",
"nav",
")",
"{",
"// Build the section navigation, grouped by their navigation groups",
"$",
"sections",
"=",
"SectionManager",
"::",
"fetch",
"(",
"null",
",",
"'asc'",
",",
"'sortorder'",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"sections",
")",
"&&",
"!",
"empty",
"(",
"$",
"sections",
")",
")",
"{",
"foreach",
"(",
"$",
"sections",
"as",
"$",
"s",
")",
"{",
"$",
"group_index",
"=",
"self",
"::",
"__navigationFindGroupIndex",
"(",
"$",
"nav",
",",
"$",
"s",
"->",
"get",
"(",
"'navigation_group'",
")",
")",
";",
"if",
"(",
"$",
"group_index",
"===",
"false",
")",
"{",
"$",
"group_index",
"=",
"General",
"::",
"array_find_available_index",
"(",
"$",
"nav",
",",
"0",
")",
";",
"$",
"nav",
"[",
"$",
"group_index",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"s",
"->",
"get",
"(",
"'navigation_group'",
")",
",",
"'type'",
"=>",
"'content'",
",",
"'index'",
"=>",
"$",
"group_index",
",",
"'children'",
"=>",
"array",
"(",
")",
")",
";",
"}",
"$",
"hasAccess",
"=",
"true",
";",
"$",
"url",
"=",
"'/publish/'",
".",
"$",
"s",
"->",
"get",
"(",
"'handle'",
")",
".",
"'/'",
";",
"/**\n * Immediately after the core access rules allowed access to this page\n * (i.e. not called if the core rules denied it).\n * Extension developers must only further restrict access to it.\n * Extension developers must also take care of checking the current value\n * of the allowed parameter in order to prevent conflicts with other extensions.\n * `$context['allowed'] = $context['allowed'] && customLogic();`\n *\n * @delegate CanAccessPage\n * @since Symphony 2.7.0\n * @see doesAuthorHaveAccess()\n * @param string $context\n * '/backend/'\n * @param bool $allowed\n * A flag to further restrict access to the page, passed by reference\n * @param string $page_limit\n * The computed page limit for the current page\n * @param string $page_url\n * The computed page url for the current page\n * @param int $section.id\n * The id of the section for this url\n * @param string $section.handle\n * The handle of the section for this url\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'CanAccessPage'",
",",
"'/backend/'",
",",
"array",
"(",
"'allowed'",
"=>",
"&",
"$",
"hasAccess",
",",
"'page_limit'",
"=>",
"'author'",
",",
"'page_url'",
"=>",
"$",
"url",
",",
"'section'",
"=>",
"array",
"(",
"'id'",
"=>",
"$",
"s",
"->",
"get",
"(",
"'id'",
")",
",",
"'handle'",
"=>",
"$",
"s",
"->",
"get",
"(",
"'handle'",
")",
")",
",",
")",
")",
";",
"if",
"(",
"$",
"hasAccess",
")",
"{",
"$",
"nav",
"[",
"$",
"group_index",
"]",
"[",
"'children'",
"]",
"[",
"]",
"=",
"array",
"(",
"'link'",
"=>",
"$",
"url",
",",
"'name'",
"=>",
"$",
"s",
"->",
"get",
"(",
"'name'",
")",
",",
"'type'",
"=>",
"'section'",
",",
"'section'",
"=>",
"array",
"(",
"'id'",
"=>",
"$",
"s",
"->",
"get",
"(",
"'id'",
")",
",",
"'handle'",
"=>",
"$",
"s",
"->",
"get",
"(",
"'handle'",
")",
")",
",",
"'visible'",
"=>",
"(",
"$",
"s",
"->",
"get",
"(",
"'hidden'",
")",
"==",
"'no'",
"?",
"'yes'",
":",
"'no'",
")",
")",
";",
"}",
"}",
"}",
"}"
] | This method fills the `$nav` array with value
from each Section
@since Symphony 2.3.2
@param array $nav
The navigation array that will receive nav nodes | [
"This",
"method",
"fills",
"the",
"$nav",
"array",
"with",
"value",
"from",
"each",
"Section"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L1043-L1113 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.buildExtensionsNavigation | private function buildExtensionsNavigation(&$nav)
{
// Loop over all the installed extensions to add in other navigation items
$extensions = Symphony::ExtensionManager()->listInstalledHandles();
foreach ($extensions as $e) {
$extension = Symphony::ExtensionManager()->getInstance($e);
$extension_navigation = $extension->fetchNavigation();
if (is_array($extension_navigation) && !empty($extension_navigation)) {
foreach ($extension_navigation as $item) {
$type = isset($item['children']) ? Extension::NAV_GROUP : Extension::NAV_CHILD;
switch ($type) {
case Extension::NAV_GROUP:
$index = General::array_find_available_index($nav, $item['location']);
// Actual group
$nav[$index] = self::createParentNavItem($index, $item);
// Render its children
foreach ($item['children'] as $child) {
$nav[$index]['children'][] = self::createChildNavItem($child, $e);
}
break;
case Extension::NAV_CHILD:
if (!is_numeric($item['location'])) {
// is a navigation group
$group_name = $item['location'];
$group_index = self::__navigationFindGroupIndex($nav, $item['location']);
} else {
// is a legacy numeric index
$group_index = $item['location'];
}
$child = self::createChildNavItem($item, $e);
if ($group_index === false) {
$group_index = General::array_find_available_index($nav, 0);
$nav_parent = self::createParentNavItem($group_index, $item);
$nav_parent['name'] = $group_name;
$nav_parent['children'] = array($child);
// add new navigation group
$nav[$group_index] = $nav_parent;
} else {
// add new location by index
$nav[$group_index]['children'][] = $child;
}
break;
}
}
}
}
} | php | private function buildExtensionsNavigation(&$nav)
{
// Loop over all the installed extensions to add in other navigation items
$extensions = Symphony::ExtensionManager()->listInstalledHandles();
foreach ($extensions as $e) {
$extension = Symphony::ExtensionManager()->getInstance($e);
$extension_navigation = $extension->fetchNavigation();
if (is_array($extension_navigation) && !empty($extension_navigation)) {
foreach ($extension_navigation as $item) {
$type = isset($item['children']) ? Extension::NAV_GROUP : Extension::NAV_CHILD;
switch ($type) {
case Extension::NAV_GROUP:
$index = General::array_find_available_index($nav, $item['location']);
// Actual group
$nav[$index] = self::createParentNavItem($index, $item);
// Render its children
foreach ($item['children'] as $child) {
$nav[$index]['children'][] = self::createChildNavItem($child, $e);
}
break;
case Extension::NAV_CHILD:
if (!is_numeric($item['location'])) {
// is a navigation group
$group_name = $item['location'];
$group_index = self::__navigationFindGroupIndex($nav, $item['location']);
} else {
// is a legacy numeric index
$group_index = $item['location'];
}
$child = self::createChildNavItem($item, $e);
if ($group_index === false) {
$group_index = General::array_find_available_index($nav, 0);
$nav_parent = self::createParentNavItem($group_index, $item);
$nav_parent['name'] = $group_name;
$nav_parent['children'] = array($child);
// add new navigation group
$nav[$group_index] = $nav_parent;
} else {
// add new location by index
$nav[$group_index]['children'][] = $child;
}
break;
}
}
}
}
} | [
"private",
"function",
"buildExtensionsNavigation",
"(",
"&",
"$",
"nav",
")",
"{",
"// Loop over all the installed extensions to add in other navigation items",
"$",
"extensions",
"=",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"listInstalledHandles",
"(",
")",
";",
"foreach",
"(",
"$",
"extensions",
"as",
"$",
"e",
")",
"{",
"$",
"extension",
"=",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"getInstance",
"(",
"$",
"e",
")",
";",
"$",
"extension_navigation",
"=",
"$",
"extension",
"->",
"fetchNavigation",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"extension_navigation",
")",
"&&",
"!",
"empty",
"(",
"$",
"extension_navigation",
")",
")",
"{",
"foreach",
"(",
"$",
"extension_navigation",
"as",
"$",
"item",
")",
"{",
"$",
"type",
"=",
"isset",
"(",
"$",
"item",
"[",
"'children'",
"]",
")",
"?",
"Extension",
"::",
"NAV_GROUP",
":",
"Extension",
"::",
"NAV_CHILD",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"Extension",
"::",
"NAV_GROUP",
":",
"$",
"index",
"=",
"General",
"::",
"array_find_available_index",
"(",
"$",
"nav",
",",
"$",
"item",
"[",
"'location'",
"]",
")",
";",
"// Actual group",
"$",
"nav",
"[",
"$",
"index",
"]",
"=",
"self",
"::",
"createParentNavItem",
"(",
"$",
"index",
",",
"$",
"item",
")",
";",
"// Render its children",
"foreach",
"(",
"$",
"item",
"[",
"'children'",
"]",
"as",
"$",
"child",
")",
"{",
"$",
"nav",
"[",
"$",
"index",
"]",
"[",
"'children'",
"]",
"[",
"]",
"=",
"self",
"::",
"createChildNavItem",
"(",
"$",
"child",
",",
"$",
"e",
")",
";",
"}",
"break",
";",
"case",
"Extension",
"::",
"NAV_CHILD",
":",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"item",
"[",
"'location'",
"]",
")",
")",
"{",
"// is a navigation group",
"$",
"group_name",
"=",
"$",
"item",
"[",
"'location'",
"]",
";",
"$",
"group_index",
"=",
"self",
"::",
"__navigationFindGroupIndex",
"(",
"$",
"nav",
",",
"$",
"item",
"[",
"'location'",
"]",
")",
";",
"}",
"else",
"{",
"// is a legacy numeric index",
"$",
"group_index",
"=",
"$",
"item",
"[",
"'location'",
"]",
";",
"}",
"$",
"child",
"=",
"self",
"::",
"createChildNavItem",
"(",
"$",
"item",
",",
"$",
"e",
")",
";",
"if",
"(",
"$",
"group_index",
"===",
"false",
")",
"{",
"$",
"group_index",
"=",
"General",
"::",
"array_find_available_index",
"(",
"$",
"nav",
",",
"0",
")",
";",
"$",
"nav_parent",
"=",
"self",
"::",
"createParentNavItem",
"(",
"$",
"group_index",
",",
"$",
"item",
")",
";",
"$",
"nav_parent",
"[",
"'name'",
"]",
"=",
"$",
"group_name",
";",
"$",
"nav_parent",
"[",
"'children'",
"]",
"=",
"array",
"(",
"$",
"child",
")",
";",
"// add new navigation group",
"$",
"nav",
"[",
"$",
"group_index",
"]",
"=",
"$",
"nav_parent",
";",
"}",
"else",
"{",
"// add new location by index",
"$",
"nav",
"[",
"$",
"group_index",
"]",
"[",
"'children'",
"]",
"[",
"]",
"=",
"$",
"child",
";",
"}",
"break",
";",
"}",
"}",
"}",
"}",
"}"
] | This method fills the `$nav` array with value
from each Extension's `fetchNavigation` method
@since Symphony 2.3.2
@param array $nav
The navigation array that will receive nav nodes
@throws Exception
@throws SymphonyErrorPage | [
"This",
"method",
"fills",
"the",
"$nav",
"array",
"with",
"value",
"from",
"each",
"Extension",
"s",
"fetchNavigation",
"method"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L1126-L1184 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.createParentNavItem | private static function createParentNavItem($index, $item)
{
$nav_item = array(
'name' => $item['name'],
'type' => isset($item['type']) ? $item['type'] : 'structure',
'index' => $index,
'children' => array(),
'limit' => isset($item['limit']) ? $item['limit'] : null
);
return $nav_item;
} | php | private static function createParentNavItem($index, $item)
{
$nav_item = array(
'name' => $item['name'],
'type' => isset($item['type']) ? $item['type'] : 'structure',
'index' => $index,
'children' => array(),
'limit' => isset($item['limit']) ? $item['limit'] : null
);
return $nav_item;
} | [
"private",
"static",
"function",
"createParentNavItem",
"(",
"$",
"index",
",",
"$",
"item",
")",
"{",
"$",
"nav_item",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"item",
"[",
"'name'",
"]",
",",
"'type'",
"=>",
"isset",
"(",
"$",
"item",
"[",
"'type'",
"]",
")",
"?",
"$",
"item",
"[",
"'type'",
"]",
":",
"'structure'",
",",
"'index'",
"=>",
"$",
"index",
",",
"'children'",
"=>",
"array",
"(",
")",
",",
"'limit'",
"=>",
"isset",
"(",
"$",
"item",
"[",
"'limit'",
"]",
")",
"?",
"$",
"item",
"[",
"'limit'",
"]",
":",
"null",
")",
";",
"return",
"$",
"nav_item",
";",
"}"
] | This function builds out a navigation menu item for parents. Parents display
in the top level navigation of the backend and may have children (dropdown menus)
@since Symphony 2.5.1
@param integer $index
@param array $item
@return array | [
"This",
"function",
"builds",
"out",
"a",
"navigation",
"menu",
"item",
"for",
"parents",
".",
"Parents",
"display",
"in",
"the",
"top",
"level",
"navigation",
"of",
"the",
"backend",
"and",
"may",
"have",
"children",
"(",
"dropdown",
"menus",
")"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L1195-L1206 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.createChildNavItem | private static function createChildNavItem($item, $extension_handle)
{
if (!isset($item['relative']) || $item['relative'] === true) {
$link = '/extension/' . $extension_handle . '/' . ltrim($item['link'], '/');
} else {
$link = '/' . ltrim($item['link'], '/');
}
$nav_item = array(
'link' => $link,
'name' => $item['name'],
'visible' => (isset($item['visible']) && $item['visible'] == 'no') ? 'no' : 'yes',
'limit' => isset($item['limit']) ? $item['limit'] : null,
'target' => isset($item['target']) ? $item['target'] : null
);
return $nav_item;
} | php | private static function createChildNavItem($item, $extension_handle)
{
if (!isset($item['relative']) || $item['relative'] === true) {
$link = '/extension/' . $extension_handle . '/' . ltrim($item['link'], '/');
} else {
$link = '/' . ltrim($item['link'], '/');
}
$nav_item = array(
'link' => $link,
'name' => $item['name'],
'visible' => (isset($item['visible']) && $item['visible'] == 'no') ? 'no' : 'yes',
'limit' => isset($item['limit']) ? $item['limit'] : null,
'target' => isset($item['target']) ? $item['target'] : null
);
return $nav_item;
} | [
"private",
"static",
"function",
"createChildNavItem",
"(",
"$",
"item",
",",
"$",
"extension_handle",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"item",
"[",
"'relative'",
"]",
")",
"||",
"$",
"item",
"[",
"'relative'",
"]",
"===",
"true",
")",
"{",
"$",
"link",
"=",
"'/extension/'",
".",
"$",
"extension_handle",
".",
"'/'",
".",
"ltrim",
"(",
"$",
"item",
"[",
"'link'",
"]",
",",
"'/'",
")",
";",
"}",
"else",
"{",
"$",
"link",
"=",
"'/'",
".",
"ltrim",
"(",
"$",
"item",
"[",
"'link'",
"]",
",",
"'/'",
")",
";",
"}",
"$",
"nav_item",
"=",
"array",
"(",
"'link'",
"=>",
"$",
"link",
",",
"'name'",
"=>",
"$",
"item",
"[",
"'name'",
"]",
",",
"'visible'",
"=>",
"(",
"isset",
"(",
"$",
"item",
"[",
"'visible'",
"]",
")",
"&&",
"$",
"item",
"[",
"'visible'",
"]",
"==",
"'no'",
")",
"?",
"'no'",
":",
"'yes'",
",",
"'limit'",
"=>",
"isset",
"(",
"$",
"item",
"[",
"'limit'",
"]",
")",
"?",
"$",
"item",
"[",
"'limit'",
"]",
":",
"null",
",",
"'target'",
"=>",
"isset",
"(",
"$",
"item",
"[",
"'target'",
"]",
")",
"?",
"$",
"item",
"[",
"'target'",
"]",
":",
"null",
")",
";",
"return",
"$",
"nav_item",
";",
"}"
] | This function builds out a navigation menu item for children. Children
live under a parent navigation item and are shown on hover.
@since Symphony 2.5.1
@param array $item
@param string $extension_handle
@return array | [
"This",
"function",
"builds",
"out",
"a",
"navigation",
"menu",
"item",
"for",
"children",
".",
"Children",
"live",
"under",
"a",
"parent",
"navigation",
"item",
"and",
"are",
"shown",
"on",
"hover",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L1217-L1234 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.__buildNavigation | public function __buildNavigation()
{
$nav = array();
$this->buildXmlNavigation($nav);
$this->buildSectionNavigation($nav);
$this->buildExtensionsNavigation($nav);
$pageCallback = Administration::instance()->getPageCallback();
$pageRoot = $pageCallback['pageroot'] . (isset($pageCallback['context'][0]) ? $pageCallback['context'][0] . '/' : '');
$found = self::__findActiveNavigationGroup($nav, $pageRoot);
// Normal searches failed. Use a regular expression using the page root. This is less
// efficient and should never really get invoked unless something weird is going on
if (!$found) {
self::__findActiveNavigationGroup($nav, '/^' . str_replace('/', '\/', $pageCallback['pageroot']) . '/i', true);
}
ksort($nav);
$this->_navigation = $nav;
/**
* Immediately after the navigation array as been built. Provided with the
* navigation array. Manipulating it will alter the navigation for all pages.
* Developers can also alter the 'limit' property of each page to allow more
* or less access to them.
* Preventing a user from accessing the page affects both the navigation and the
* page access rights: user will get a 403 Forbidden error if not authorized.
*
* @delegate NavigationPostBuild
* @since Symphony 2.7.0
* @param string $context
* '/backend/'
* @param array $nav
* An associative array of the current navigation, passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('NavigationPostBuild', '/backend/', array(
'navigation' => &$this->_navigation,
));
} | php | public function __buildNavigation()
{
$nav = array();
$this->buildXmlNavigation($nav);
$this->buildSectionNavigation($nav);
$this->buildExtensionsNavigation($nav);
$pageCallback = Administration::instance()->getPageCallback();
$pageRoot = $pageCallback['pageroot'] . (isset($pageCallback['context'][0]) ? $pageCallback['context'][0] . '/' : '');
$found = self::__findActiveNavigationGroup($nav, $pageRoot);
// Normal searches failed. Use a regular expression using the page root. This is less
// efficient and should never really get invoked unless something weird is going on
if (!$found) {
self::__findActiveNavigationGroup($nav, '/^' . str_replace('/', '\/', $pageCallback['pageroot']) . '/i', true);
}
ksort($nav);
$this->_navigation = $nav;
/**
* Immediately after the navigation array as been built. Provided with the
* navigation array. Manipulating it will alter the navigation for all pages.
* Developers can also alter the 'limit' property of each page to allow more
* or less access to them.
* Preventing a user from accessing the page affects both the navigation and the
* page access rights: user will get a 403 Forbidden error if not authorized.
*
* @delegate NavigationPostBuild
* @since Symphony 2.7.0
* @param string $context
* '/backend/'
* @param array $nav
* An associative array of the current navigation, passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('NavigationPostBuild', '/backend/', array(
'navigation' => &$this->_navigation,
));
} | [
"public",
"function",
"__buildNavigation",
"(",
")",
"{",
"$",
"nav",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"buildXmlNavigation",
"(",
"$",
"nav",
")",
";",
"$",
"this",
"->",
"buildSectionNavigation",
"(",
"$",
"nav",
")",
";",
"$",
"this",
"->",
"buildExtensionsNavigation",
"(",
"$",
"nav",
")",
";",
"$",
"pageCallback",
"=",
"Administration",
"::",
"instance",
"(",
")",
"->",
"getPageCallback",
"(",
")",
";",
"$",
"pageRoot",
"=",
"$",
"pageCallback",
"[",
"'pageroot'",
"]",
".",
"(",
"isset",
"(",
"$",
"pageCallback",
"[",
"'context'",
"]",
"[",
"0",
"]",
")",
"?",
"$",
"pageCallback",
"[",
"'context'",
"]",
"[",
"0",
"]",
".",
"'/'",
":",
"''",
")",
";",
"$",
"found",
"=",
"self",
"::",
"__findActiveNavigationGroup",
"(",
"$",
"nav",
",",
"$",
"pageRoot",
")",
";",
"// Normal searches failed. Use a regular expression using the page root. This is less",
"// efficient and should never really get invoked unless something weird is going on",
"if",
"(",
"!",
"$",
"found",
")",
"{",
"self",
"::",
"__findActiveNavigationGroup",
"(",
"$",
"nav",
",",
"'/^'",
".",
"str_replace",
"(",
"'/'",
",",
"'\\/'",
",",
"$",
"pageCallback",
"[",
"'pageroot'",
"]",
")",
".",
"'/i'",
",",
"true",
")",
";",
"}",
"ksort",
"(",
"$",
"nav",
")",
";",
"$",
"this",
"->",
"_navigation",
"=",
"$",
"nav",
";",
"/**\n * Immediately after the navigation array as been built. Provided with the\n * navigation array. Manipulating it will alter the navigation for all pages.\n * Developers can also alter the 'limit' property of each page to allow more\n * or less access to them.\n * Preventing a user from accessing the page affects both the navigation and the\n * page access rights: user will get a 403 Forbidden error if not authorized.\n *\n * @delegate NavigationPostBuild\n * @since Symphony 2.7.0\n * @param string $context\n * '/backend/'\n * @param array $nav\n * An associative array of the current navigation, passed by reference\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'NavigationPostBuild'",
",",
"'/backend/'",
",",
"array",
"(",
"'navigation'",
"=>",
"&",
"$",
"this",
"->",
"_navigation",
",",
")",
")",
";",
"}"
] | This function populates the `$_navigation` array with an associative array
of all the navigation groups and their links. Symphony only supports one
level of navigation, so children links cannot have children links. The default
Symphony navigation is found in the `ASSETS/xml/navigation.xml` folder. This is
loaded first, and then the Section navigation is built, followed by the Extension
navigation. Additionally, this function will set the active group of the navigation
by checking the current page against the array of links.
It fires a delegate, NavigationPostBuild, to allow extensions to manipulate
the navigation.
@uses NavigationPostBuild
@link https://github.com/symphonycms/symphony-2/blob/master/symphony/assets/xml/navigation.xml
@link https://github.com/symphonycms/symphony-2/blob/master/symphony/lib/toolkit/class.extension.php | [
"This",
"function",
"populates",
"the",
"$_navigation",
"array",
"with",
"an",
"associative",
"array",
"of",
"all",
"the",
"navigation",
"groups",
"and",
"their",
"links",
".",
"Symphony",
"only",
"supports",
"one",
"level",
"of",
"navigation",
"so",
"children",
"links",
"cannot",
"have",
"children",
"links",
".",
"The",
"default",
"Symphony",
"navigation",
"is",
"found",
"in",
"the",
"ASSETS",
"/",
"xml",
"/",
"navigation",
".",
"xml",
"folder",
".",
"This",
"is",
"loaded",
"first",
"and",
"then",
"the",
"Section",
"navigation",
"is",
"built",
"followed",
"by",
"the",
"Extension",
"navigation",
".",
"Additionally",
"this",
"function",
"will",
"set",
"the",
"active",
"group",
"of",
"the",
"navigation",
"by",
"checking",
"the",
"current",
"page",
"against",
"the",
"array",
"of",
"links",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L1252-L1292 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.__navigationFindGroupIndex | private static function __navigationFindGroupIndex(array $nav, $group)
{
foreach ($nav as $index => $item) {
if ($item['name'] === $group) {
return $index;
}
}
return false;
} | php | private static function __navigationFindGroupIndex(array $nav, $group)
{
foreach ($nav as $index => $item) {
if ($item['name'] === $group) {
return $index;
}
}
return false;
} | [
"private",
"static",
"function",
"__navigationFindGroupIndex",
"(",
"array",
"$",
"nav",
",",
"$",
"group",
")",
"{",
"foreach",
"(",
"$",
"nav",
"as",
"$",
"index",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"[",
"'name'",
"]",
"===",
"$",
"group",
")",
"{",
"return",
"$",
"index",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Given an associative array representing the navigation, and a group,
this function will attempt to return the index of the group in the navigation
array. If it is found, it will return the index, otherwise it will return false.
@param array $nav
An associative array of the navigation where the key is the group
index, and the value is an associative array of 'name', 'index' and
'children'. Name is the name of the this group, index is the same as
the key and children is an associative array of navigation items containing
the keys 'link', 'name' and 'visible'. The 'haystack'.
@param string $group
The group name to find, the 'needle'.
@return integer|boolean
If the group is found, the index will be returned, otherwise false. | [
"Given",
"an",
"associative",
"array",
"representing",
"the",
"navigation",
"and",
"a",
"group",
"this",
"function",
"will",
"attempt",
"to",
"return",
"the",
"index",
"of",
"the",
"group",
"in",
"the",
"navigation",
"array",
".",
"If",
"it",
"is",
"found",
"it",
"will",
"return",
"the",
"index",
"otherwise",
"it",
"will",
"return",
"false",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L1310-L1319 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.__findActiveNavigationGroup | private static function __findActiveNavigationGroup(array &$nav, $pageroot, $pattern = false)
{
foreach ($nav as $index => $contents) {
if (is_array($contents['children']) && !empty($contents['children'])) {
foreach ($contents['children'] as $item) {
if ($pattern && preg_match($pageroot, $item['link'])) {
$nav[$index]['class'] = 'active';
return true;
} elseif ($item['link'] == $pageroot) {
$nav[$index]['class'] = 'active';
return true;
}
}
}
}
return false;
} | php | private static function __findActiveNavigationGroup(array &$nav, $pageroot, $pattern = false)
{
foreach ($nav as $index => $contents) {
if (is_array($contents['children']) && !empty($contents['children'])) {
foreach ($contents['children'] as $item) {
if ($pattern && preg_match($pageroot, $item['link'])) {
$nav[$index]['class'] = 'active';
return true;
} elseif ($item['link'] == $pageroot) {
$nav[$index]['class'] = 'active';
return true;
}
}
}
}
return false;
} | [
"private",
"static",
"function",
"__findActiveNavigationGroup",
"(",
"array",
"&",
"$",
"nav",
",",
"$",
"pageroot",
",",
"$",
"pattern",
"=",
"false",
")",
"{",
"foreach",
"(",
"$",
"nav",
"as",
"$",
"index",
"=>",
"$",
"contents",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"contents",
"[",
"'children'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"contents",
"[",
"'children'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"contents",
"[",
"'children'",
"]",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"pattern",
"&&",
"preg_match",
"(",
"$",
"pageroot",
",",
"$",
"item",
"[",
"'link'",
"]",
")",
")",
"{",
"$",
"nav",
"[",
"$",
"index",
"]",
"[",
"'class'",
"]",
"=",
"'active'",
";",
"return",
"true",
";",
"}",
"elseif",
"(",
"$",
"item",
"[",
"'link'",
"]",
"==",
"$",
"pageroot",
")",
"{",
"$",
"nav",
"[",
"$",
"index",
"]",
"[",
"'class'",
"]",
"=",
"'active'",
";",
"return",
"true",
";",
"}",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Given the navigation array, this function will loop over all the items
to determine which is the 'active' navigation group, or in other words,
what group best represents the current page `$this->Author` is viewing.
This is done by checking the current page's link against all the links
provided in the `$nav`, and then flagging the group of the found link
with an 'active' CSS class. The current page's link omits any flags or
URL parameters and just uses the root page URL.
@param array $nav
An associative array of the navigation where the key is the group
index, and the value is an associative array of 'name', 'index' and
'children'. Name is the name of the this group, index is the same as
the key and children is an associative array of navigation items containing
the keys 'link', 'name' and 'visible'. The 'haystack'. This parameter is passed
by reference to this function.
@param string $pageroot
The current page the Author is the viewing, minus any flags or URL
parameters such as a Symphony object ID. eg. Section ID, Entry ID. This
parameter is also be a regular expression, but this is highly unlikely.
@param boolean $pattern
If set to true, the `$pageroot` represents a regular expression which will
determine if the active navigation item
@return boolean
Returns true if an active link was found, false otherwise. If true, the
navigation group of the active link will be given the CSS class 'active' | [
"Given",
"the",
"navigation",
"array",
"this",
"function",
"will",
"loop",
"over",
"all",
"the",
"items",
"to",
"determine",
"which",
"is",
"the",
"active",
"navigation",
"group",
"or",
"in",
"other",
"words",
"what",
"group",
"best",
"represents",
"the",
"current",
"page",
"$this",
"-",
">",
"Author",
"is",
"viewing",
".",
"This",
"is",
"done",
"by",
"checking",
"the",
"current",
"page",
"s",
"link",
"against",
"all",
"the",
"links",
"provided",
"in",
"the",
"$nav",
"and",
"then",
"flagging",
"the",
"group",
"of",
"the",
"found",
"link",
"with",
"an",
"active",
"CSS",
"class",
".",
"The",
"current",
"page",
"s",
"link",
"omits",
"any",
"flags",
"or",
"URL",
"parameters",
"and",
"just",
"uses",
"the",
"root",
"page",
"URL",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L1348-L1365 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.appendUserLinks | public function appendUserLinks()
{
$ul = new XMLElement('ul', null, array('id' => 'session'));
$li = new XMLElement('li');
$li->appendChild(
Widget::Anchor(
Symphony::Author()->getFullName(),
SYMPHONY_URL . '/system/authors/edit/' . Symphony::Author()->get('id') . '/'
)
);
$ul->appendChild($li);
$li = new XMLElement('li');
$li->appendChild(Widget::Anchor(__('Log out'), SYMPHONY_URL . '/logout/', null, null, null, array('accesskey' => 'l')));
$ul->appendChild($li);
$this->Header->appendChild($ul);
} | php | public function appendUserLinks()
{
$ul = new XMLElement('ul', null, array('id' => 'session'));
$li = new XMLElement('li');
$li->appendChild(
Widget::Anchor(
Symphony::Author()->getFullName(),
SYMPHONY_URL . '/system/authors/edit/' . Symphony::Author()->get('id') . '/'
)
);
$ul->appendChild($li);
$li = new XMLElement('li');
$li->appendChild(Widget::Anchor(__('Log out'), SYMPHONY_URL . '/logout/', null, null, null, array('accesskey' => 'l')));
$ul->appendChild($li);
$this->Header->appendChild($ul);
} | [
"public",
"function",
"appendUserLinks",
"(",
")",
"{",
"$",
"ul",
"=",
"new",
"XMLElement",
"(",
"'ul'",
",",
"null",
",",
"array",
"(",
"'id'",
"=>",
"'session'",
")",
")",
";",
"$",
"li",
"=",
"new",
"XMLElement",
"(",
"'li'",
")",
";",
"$",
"li",
"->",
"appendChild",
"(",
"Widget",
"::",
"Anchor",
"(",
"Symphony",
"::",
"Author",
"(",
")",
"->",
"getFullName",
"(",
")",
",",
"SYMPHONY_URL",
".",
"'/system/authors/edit/'",
".",
"Symphony",
"::",
"Author",
"(",
")",
"->",
"get",
"(",
"'id'",
")",
".",
"'/'",
")",
")",
";",
"$",
"ul",
"->",
"appendChild",
"(",
"$",
"li",
")",
";",
"$",
"li",
"=",
"new",
"XMLElement",
"(",
"'li'",
")",
";",
"$",
"li",
"->",
"appendChild",
"(",
"Widget",
"::",
"Anchor",
"(",
"__",
"(",
"'Log out'",
")",
",",
"SYMPHONY_URL",
".",
"'/logout/'",
",",
"null",
",",
"null",
",",
"null",
",",
"array",
"(",
"'accesskey'",
"=>",
"'l'",
")",
")",
")",
";",
"$",
"ul",
"->",
"appendChild",
"(",
"$",
"li",
")",
";",
"$",
"this",
"->",
"Header",
"->",
"appendChild",
"(",
"$",
"ul",
")",
";",
"}"
] | Creates the Symphony footer for an Administration page. By default
this includes the installed Symphony version and the currently logged
in Author. A delegate is provided to allow extensions to manipulate the
footer HTML, which is an XMLElement of a `<ul>` element.
Since Symphony 2.3, it no longer uses the `AddElementToFooter` delegate. | [
"Creates",
"the",
"Symphony",
"footer",
"for",
"an",
"Administration",
"page",
".",
"By",
"default",
"this",
"includes",
"the",
"installed",
"Symphony",
"version",
"and",
"the",
"currently",
"logged",
"in",
"Author",
".",
"A",
"delegate",
"is",
"provided",
"to",
"allow",
"extensions",
"to",
"manipulate",
"the",
"footer",
"HTML",
"which",
"is",
"an",
"XMLElement",
"of",
"a",
"<ul",
">",
"element",
".",
"Since",
"Symphony",
"2",
".",
"3",
"it",
"no",
"longer",
"uses",
"the",
"AddElementToFooter",
"delegate",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L1374-L1392 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.administrationpage.php | AdministrationPage.addTimestampValidationPageAlert | public function addTimestampValidationPageAlert($errorMessage, $existingObject, $action)
{
$authorId = $existingObject->get('modification_author_id');
if (!$authorId) {
$authorId = $existingObject->get('author_id');
}
$author = AuthorManager::fetchByID($authorId);
$formatteAuthorName = $authorId === Symphony::Author()->get('id')
? __('yourself')
: (!$author
? __('an unknown user')
: $author->get('first_name') . ' ' . $author->get('last_name'));
$msg = $this->_errors['timestamp'] . ' ' . __(
'made by %s at %s.', array(
$formatteAuthorName,
Widget::Time($existingObject->get('modification_date'))->generate(),
)
);
$currentUrl = Administration::instance()->getCurrentPageURL();
$overwritelink = Widget::Anchor(
__('Replace changes?'),
$currentUrl,
__('Overwrite'),
'js-tv-overwrite',
null,
array(
'data-action' => General::sanitize($action)
)
);
$ignorelink = Widget::Anchor(
__('View changes.'),
$currentUrl,
__('View the updated entry')
);
$actions = $overwritelink->generate() . ' ' . $ignorelink->generate();
$this->pageAlert("$msg $actions", Alert::ERROR);
} | php | public function addTimestampValidationPageAlert($errorMessage, $existingObject, $action)
{
$authorId = $existingObject->get('modification_author_id');
if (!$authorId) {
$authorId = $existingObject->get('author_id');
}
$author = AuthorManager::fetchByID($authorId);
$formatteAuthorName = $authorId === Symphony::Author()->get('id')
? __('yourself')
: (!$author
? __('an unknown user')
: $author->get('first_name') . ' ' . $author->get('last_name'));
$msg = $this->_errors['timestamp'] . ' ' . __(
'made by %s at %s.', array(
$formatteAuthorName,
Widget::Time($existingObject->get('modification_date'))->generate(),
)
);
$currentUrl = Administration::instance()->getCurrentPageURL();
$overwritelink = Widget::Anchor(
__('Replace changes?'),
$currentUrl,
__('Overwrite'),
'js-tv-overwrite',
null,
array(
'data-action' => General::sanitize($action)
)
);
$ignorelink = Widget::Anchor(
__('View changes.'),
$currentUrl,
__('View the updated entry')
);
$actions = $overwritelink->generate() . ' ' . $ignorelink->generate();
$this->pageAlert("$msg $actions", Alert::ERROR);
} | [
"public",
"function",
"addTimestampValidationPageAlert",
"(",
"$",
"errorMessage",
",",
"$",
"existingObject",
",",
"$",
"action",
")",
"{",
"$",
"authorId",
"=",
"$",
"existingObject",
"->",
"get",
"(",
"'modification_author_id'",
")",
";",
"if",
"(",
"!",
"$",
"authorId",
")",
"{",
"$",
"authorId",
"=",
"$",
"existingObject",
"->",
"get",
"(",
"'author_id'",
")",
";",
"}",
"$",
"author",
"=",
"AuthorManager",
"::",
"fetchByID",
"(",
"$",
"authorId",
")",
";",
"$",
"formatteAuthorName",
"=",
"$",
"authorId",
"===",
"Symphony",
"::",
"Author",
"(",
")",
"->",
"get",
"(",
"'id'",
")",
"?",
"__",
"(",
"'yourself'",
")",
":",
"(",
"!",
"$",
"author",
"?",
"__",
"(",
"'an unknown user'",
")",
":",
"$",
"author",
"->",
"get",
"(",
"'first_name'",
")",
".",
"' '",
".",
"$",
"author",
"->",
"get",
"(",
"'last_name'",
")",
")",
";",
"$",
"msg",
"=",
"$",
"this",
"->",
"_errors",
"[",
"'timestamp'",
"]",
".",
"' '",
".",
"__",
"(",
"'made by %s at %s.'",
",",
"array",
"(",
"$",
"formatteAuthorName",
",",
"Widget",
"::",
"Time",
"(",
"$",
"existingObject",
"->",
"get",
"(",
"'modification_date'",
")",
")",
"->",
"generate",
"(",
")",
",",
")",
")",
";",
"$",
"currentUrl",
"=",
"Administration",
"::",
"instance",
"(",
")",
"->",
"getCurrentPageURL",
"(",
")",
";",
"$",
"overwritelink",
"=",
"Widget",
"::",
"Anchor",
"(",
"__",
"(",
"'Replace changes?'",
")",
",",
"$",
"currentUrl",
",",
"__",
"(",
"'Overwrite'",
")",
",",
"'js-tv-overwrite'",
",",
"null",
",",
"array",
"(",
"'data-action'",
"=>",
"General",
"::",
"sanitize",
"(",
"$",
"action",
")",
")",
")",
";",
"$",
"ignorelink",
"=",
"Widget",
"::",
"Anchor",
"(",
"__",
"(",
"'View changes.'",
")",
",",
"$",
"currentUrl",
",",
"__",
"(",
"'View the updated entry'",
")",
")",
";",
"$",
"actions",
"=",
"$",
"overwritelink",
"->",
"generate",
"(",
")",
".",
"' '",
".",
"$",
"ignorelink",
"->",
"generate",
"(",
")",
";",
"$",
"this",
"->",
"pageAlert",
"(",
"\"$msg $actions\"",
",",
"Alert",
"::",
"ERROR",
")",
";",
"}"
] | Adds a localized Alert message for failed timestamp validations.
It also adds meta information about the last author and timestamp.
@since Symphony 2.7.0
@param string $errorMessage
The error message to display.
@param Entry|Section $existingObject
The Entry or section object that failed validation.
@param string $action
The requested action. | [
"Adds",
"a",
"localized",
"Alert",
"message",
"for",
"failed",
"timestamp",
"validations",
".",
"It",
"also",
"adds",
"meta",
"information",
"about",
"the",
"last",
"author",
"and",
"timestamp",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.administrationpage.php#L1406-L1445 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlpage.php | XMLPage.generate | public function generate($page = null)
{
// Set the actual status code in the xml response
$this->_Result->setAttribute('status', $this->getHttpStatusCode());
parent::generate($page);
return $this->_Result->generate(true);
} | php | public function generate($page = null)
{
// Set the actual status code in the xml response
$this->_Result->setAttribute('status', $this->getHttpStatusCode());
parent::generate($page);
return $this->_Result->generate(true);
} | [
"public",
"function",
"generate",
"(",
"$",
"page",
"=",
"null",
")",
"{",
"// Set the actual status code in the xml response",
"$",
"this",
"->",
"_Result",
"->",
"setAttribute",
"(",
"'status'",
",",
"$",
"this",
"->",
"getHttpStatusCode",
"(",
")",
")",
";",
"parent",
"::",
"generate",
"(",
"$",
"page",
")",
";",
"return",
"$",
"this",
"->",
"_Result",
"->",
"generate",
"(",
"true",
")",
";",
"}"
] | The generate functions outputs the correct headers for
this `XMLPage`, adds `$this->getHttpStatusCode()` code to the root attribute
before calling the parent generate function and generating
the `$this->_Result` XMLElement
@param null $page
@return string | [
"The",
"generate",
"functions",
"outputs",
"the",
"correct",
"headers",
"for",
"this",
"XMLPage",
"adds",
"$this",
"-",
">",
"getHttpStatusCode",
"()",
"code",
"to",
"the",
"root",
"attribute",
"before",
"calling",
"the",
"parent",
"generate",
"function",
"and",
"generating",
"the",
"$this",
"-",
">",
"_Result",
"XMLElement"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlpage.php#L57-L65 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.lang.php | Lang.initialize | public static function initialize()
{
self::$_dictionary = array();
// Load default datetime strings
if (empty(self::$_datetime_dictionary)) {
self::$_datetime_dictionary = include LANG . '/datetime.php';
}
// Load default transliterations
if (empty(self::$_transliterations)) {
self::$_transliterations = include LANG . '/transliterations.php';
}
// Load default English language
if (empty(self::$_languages)) {
self::$_languages = self::createLanguage('en', 'English', 'english');
}
// Fetch all available languages
self::fetch();
} | php | public static function initialize()
{
self::$_dictionary = array();
// Load default datetime strings
if (empty(self::$_datetime_dictionary)) {
self::$_datetime_dictionary = include LANG . '/datetime.php';
}
// Load default transliterations
if (empty(self::$_transliterations)) {
self::$_transliterations = include LANG . '/transliterations.php';
}
// Load default English language
if (empty(self::$_languages)) {
self::$_languages = self::createLanguage('en', 'English', 'english');
}
// Fetch all available languages
self::fetch();
} | [
"public",
"static",
"function",
"initialize",
"(",
")",
"{",
"self",
"::",
"$",
"_dictionary",
"=",
"array",
"(",
")",
";",
"// Load default datetime strings",
"if",
"(",
"empty",
"(",
"self",
"::",
"$",
"_datetime_dictionary",
")",
")",
"{",
"self",
"::",
"$",
"_datetime_dictionary",
"=",
"include",
"LANG",
".",
"'/datetime.php'",
";",
"}",
"// Load default transliterations",
"if",
"(",
"empty",
"(",
"self",
"::",
"$",
"_transliterations",
")",
")",
"{",
"self",
"::",
"$",
"_transliterations",
"=",
"include",
"LANG",
".",
"'/transliterations.php'",
";",
"}",
"// Load default English language",
"if",
"(",
"empty",
"(",
"self",
"::",
"$",
"_languages",
")",
")",
"{",
"self",
"::",
"$",
"_languages",
"=",
"self",
"::",
"createLanguage",
"(",
"'en'",
",",
"'English'",
",",
"'english'",
")",
";",
"}",
"// Fetch all available languages",
"self",
"::",
"fetch",
"(",
")",
";",
"}"
] | Initialize transliterations, datetime dictionary and languages array. | [
"Initialize",
"transliterations",
"datetime",
"dictionary",
"and",
"languages",
"array",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.lang.php#L99-L120 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.lang.php | Lang.createLanguage | private static function createLanguage($code, $name, $handle = null, array $extensions = array())
{
return array(
$code => array(
'name' => $name,
'handle' => $handle,
'extensions' => $extensions
)
);
} | php | private static function createLanguage($code, $name, $handle = null, array $extensions = array())
{
return array(
$code => array(
'name' => $name,
'handle' => $handle,
'extensions' => $extensions
)
);
} | [
"private",
"static",
"function",
"createLanguage",
"(",
"$",
"code",
",",
"$",
"name",
",",
"$",
"handle",
"=",
"null",
",",
"array",
"$",
"extensions",
"=",
"array",
"(",
")",
")",
"{",
"return",
"array",
"(",
"$",
"code",
"=>",
"array",
"(",
"'name'",
"=>",
"$",
"name",
",",
"'handle'",
"=>",
"$",
"handle",
",",
"'extensions'",
"=>",
"$",
"extensions",
")",
")",
";",
"}"
] | Create an array of Language information for internal use.
@since Symphony 2.3
@param string $code
Language code, e. g. 'en' or 'pt-br'
@param string $name
Language name
@param string $handle (optional)
Handle for the given language, used to build a valid 'lang_$handle' extension's handle.
Defaults to null.
@param array $extensions (optional)
An array of extensions that support the given language.
@return array
An array of Language information. | [
"Create",
"an",
"array",
"of",
"Language",
"information",
"for",
"internal",
"use",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.lang.php#L138-L147 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.lang.php | Lang.fetch | private static function fetch()
{
if (!@is_readable(EXTENSIONS)) {
return;
}
// Fetch extensions
$extensions = new FilesystemIterator(EXTENSIONS);
// Language extensions
foreach ($extensions as $extension) {
if ($extension->isFile()) {
continue;
}
// Core translations
$core_handle = (strpos($extension->getFilename(), 'lang_') !== false)
? str_replace('lang_', '', $extension->getFilename())
: null;
// Loop over the `/lang` directory of this `$extension` searching for language
// files. If `/lang` isn't a directory, `UnexpectedValueException` will be
// thrown.
try {
$path = $extension->getPathname() . '/lang';
if (!is_dir($path)) {
continue;
}
$directory = new GlobIterator($path . '/lang.*.php');
foreach ($directory as $file) {
include($file->getPathname());
// Get language code (chars between lang. and .php)
$code = substr($file->getFilename(), 5, -4);
$lang = null;
$handle = null;
$extensions = array();
// Set lang, handle and extensions if defined.
if (isset(self::$_languages[$code])) {
$lang = self::$_languages[$code];
$handle = $lang['handle'];
$extensions = $lang['extensions'];
}
// Core translations
if ($core_handle) {
$handle = $core_handle;
// Extension translations
} else {
$extensions = array_merge(array($extension->getFilename()), $extensions);
}
// Merge languages ($about is declared inside the included $file)
$temp = self::createLanguage($code, $about['name'], $handle, $extensions);
if (isset($lang)) {
foreach ($lang as $key => $value) {
// Prevent missing or nulled values overwriting existing values
// which can occur if a translation file is not correct.
if (!isset($temp[$code][$key]) || empty($temp[$code][$key])) {
continue;
}
self::$_languages[$code][$key] = $temp[$code][$key];
}
} else {
self::$_languages[$code] = $temp[$code];
}
}
} catch (Exception $ex) {
continue;
}
}
} | php | private static function fetch()
{
if (!@is_readable(EXTENSIONS)) {
return;
}
// Fetch extensions
$extensions = new FilesystemIterator(EXTENSIONS);
// Language extensions
foreach ($extensions as $extension) {
if ($extension->isFile()) {
continue;
}
// Core translations
$core_handle = (strpos($extension->getFilename(), 'lang_') !== false)
? str_replace('lang_', '', $extension->getFilename())
: null;
// Loop over the `/lang` directory of this `$extension` searching for language
// files. If `/lang` isn't a directory, `UnexpectedValueException` will be
// thrown.
try {
$path = $extension->getPathname() . '/lang';
if (!is_dir($path)) {
continue;
}
$directory = new GlobIterator($path . '/lang.*.php');
foreach ($directory as $file) {
include($file->getPathname());
// Get language code (chars between lang. and .php)
$code = substr($file->getFilename(), 5, -4);
$lang = null;
$handle = null;
$extensions = array();
// Set lang, handle and extensions if defined.
if (isset(self::$_languages[$code])) {
$lang = self::$_languages[$code];
$handle = $lang['handle'];
$extensions = $lang['extensions'];
}
// Core translations
if ($core_handle) {
$handle = $core_handle;
// Extension translations
} else {
$extensions = array_merge(array($extension->getFilename()), $extensions);
}
// Merge languages ($about is declared inside the included $file)
$temp = self::createLanguage($code, $about['name'], $handle, $extensions);
if (isset($lang)) {
foreach ($lang as $key => $value) {
// Prevent missing or nulled values overwriting existing values
// which can occur if a translation file is not correct.
if (!isset($temp[$code][$key]) || empty($temp[$code][$key])) {
continue;
}
self::$_languages[$code][$key] = $temp[$code][$key];
}
} else {
self::$_languages[$code] = $temp[$code];
}
}
} catch (Exception $ex) {
continue;
}
}
} | [
"private",
"static",
"function",
"fetch",
"(",
")",
"{",
"if",
"(",
"!",
"@",
"is_readable",
"(",
"EXTENSIONS",
")",
")",
"{",
"return",
";",
"}",
"// Fetch extensions",
"$",
"extensions",
"=",
"new",
"FilesystemIterator",
"(",
"EXTENSIONS",
")",
";",
"// Language extensions",
"foreach",
"(",
"$",
"extensions",
"as",
"$",
"extension",
")",
"{",
"if",
"(",
"$",
"extension",
"->",
"isFile",
"(",
")",
")",
"{",
"continue",
";",
"}",
"// Core translations",
"$",
"core_handle",
"=",
"(",
"strpos",
"(",
"$",
"extension",
"->",
"getFilename",
"(",
")",
",",
"'lang_'",
")",
"!==",
"false",
")",
"?",
"str_replace",
"(",
"'lang_'",
",",
"''",
",",
"$",
"extension",
"->",
"getFilename",
"(",
")",
")",
":",
"null",
";",
"// Loop over the `/lang` directory of this `$extension` searching for language",
"// files. If `/lang` isn't a directory, `UnexpectedValueException` will be",
"// thrown.",
"try",
"{",
"$",
"path",
"=",
"$",
"extension",
"->",
"getPathname",
"(",
")",
".",
"'/lang'",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"continue",
";",
"}",
"$",
"directory",
"=",
"new",
"GlobIterator",
"(",
"$",
"path",
".",
"'/lang.*.php'",
")",
";",
"foreach",
"(",
"$",
"directory",
"as",
"$",
"file",
")",
"{",
"include",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
";",
"// Get language code (chars between lang. and .php)",
"$",
"code",
"=",
"substr",
"(",
"$",
"file",
"->",
"getFilename",
"(",
")",
",",
"5",
",",
"-",
"4",
")",
";",
"$",
"lang",
"=",
"null",
";",
"$",
"handle",
"=",
"null",
";",
"$",
"extensions",
"=",
"array",
"(",
")",
";",
"// Set lang, handle and extensions if defined.",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"_languages",
"[",
"$",
"code",
"]",
")",
")",
"{",
"$",
"lang",
"=",
"self",
"::",
"$",
"_languages",
"[",
"$",
"code",
"]",
";",
"$",
"handle",
"=",
"$",
"lang",
"[",
"'handle'",
"]",
";",
"$",
"extensions",
"=",
"$",
"lang",
"[",
"'extensions'",
"]",
";",
"}",
"// Core translations",
"if",
"(",
"$",
"core_handle",
")",
"{",
"$",
"handle",
"=",
"$",
"core_handle",
";",
"// Extension translations",
"}",
"else",
"{",
"$",
"extensions",
"=",
"array_merge",
"(",
"array",
"(",
"$",
"extension",
"->",
"getFilename",
"(",
")",
")",
",",
"$",
"extensions",
")",
";",
"}",
"// Merge languages ($about is declared inside the included $file)",
"$",
"temp",
"=",
"self",
"::",
"createLanguage",
"(",
"$",
"code",
",",
"$",
"about",
"[",
"'name'",
"]",
",",
"$",
"handle",
",",
"$",
"extensions",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"lang",
")",
")",
"{",
"foreach",
"(",
"$",
"lang",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// Prevent missing or nulled values overwriting existing values",
"// which can occur if a translation file is not correct.",
"if",
"(",
"!",
"isset",
"(",
"$",
"temp",
"[",
"$",
"code",
"]",
"[",
"$",
"key",
"]",
")",
"||",
"empty",
"(",
"$",
"temp",
"[",
"$",
"code",
"]",
"[",
"$",
"key",
"]",
")",
")",
"{",
"continue",
";",
"}",
"self",
"::",
"$",
"_languages",
"[",
"$",
"code",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"temp",
"[",
"$",
"code",
"]",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"else",
"{",
"self",
"::",
"$",
"_languages",
"[",
"$",
"code",
"]",
"=",
"$",
"temp",
"[",
"$",
"code",
"]",
";",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"continue",
";",
"}",
"}",
"}"
] | Fetch all languages available in the core language folder and the language extensions.
The function stores all language information in the private variable `$_languages`.
It contains an array with the name and handle of each language and an array of all
extensions available in that language.
@throws UnexpectedValueException
@throws RuntimeException | [
"Fetch",
"all",
"languages",
"available",
"in",
"the",
"core",
"language",
"folder",
"and",
"the",
"language",
"extensions",
".",
"The",
"function",
"stores",
"all",
"language",
"information",
"in",
"the",
"private",
"variable",
"$_languages",
".",
"It",
"contains",
"an",
"array",
"with",
"the",
"name",
"and",
"handle",
"of",
"each",
"language",
"and",
"an",
"array",
"of",
"all",
"extensions",
"available",
"in",
"that",
"language",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.lang.php#L158-L234 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.lang.php | Lang.set | public static function set($code, $checkStatus = true)
{
if (!$code || $code == self::get()) {
return;
}
// Language file available
if ($code !== 'en' && (self::isLanguageEnabled($code) || $checkStatus === false)) {
// Store desired language code
self::$_lang = $code;
// Clear dictionary
self::$_dictionary = array();
// Load core translations
self::load(vsprintf('%s/lang_%s/lang/lang.%s.php', array(
EXTENSIONS, self::$_languages[$code]['handle'], $code
)));
// Load extension translations
if (is_array(self::$_languages[$code]['extensions'])) {
foreach (self::$_languages[$code]['extensions'] as $extension) {
self::load(vsprintf('%s/%s/lang/lang.%s.php', array(
EXTENSIONS, $extension, $code
)));
}
}
// Language file unavailable, use default language
} else {
self::$_lang = 'en';
// Log error, if possible
if ($code !== 'en' && class_exists('Symphony', false) && Symphony::Log() instanceof Log) {
Symphony::Log()->pushToLog(
__('The selected language, %s, could not be found. Using default English dictionary instead.', array($code)),
E_ERROR,
true
);
}
}
} | php | public static function set($code, $checkStatus = true)
{
if (!$code || $code == self::get()) {
return;
}
// Language file available
if ($code !== 'en' && (self::isLanguageEnabled($code) || $checkStatus === false)) {
// Store desired language code
self::$_lang = $code;
// Clear dictionary
self::$_dictionary = array();
// Load core translations
self::load(vsprintf('%s/lang_%s/lang/lang.%s.php', array(
EXTENSIONS, self::$_languages[$code]['handle'], $code
)));
// Load extension translations
if (is_array(self::$_languages[$code]['extensions'])) {
foreach (self::$_languages[$code]['extensions'] as $extension) {
self::load(vsprintf('%s/%s/lang/lang.%s.php', array(
EXTENSIONS, $extension, $code
)));
}
}
// Language file unavailable, use default language
} else {
self::$_lang = 'en';
// Log error, if possible
if ($code !== 'en' && class_exists('Symphony', false) && Symphony::Log() instanceof Log) {
Symphony::Log()->pushToLog(
__('The selected language, %s, could not be found. Using default English dictionary instead.', array($code)),
E_ERROR,
true
);
}
}
} | [
"public",
"static",
"function",
"set",
"(",
"$",
"code",
",",
"$",
"checkStatus",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"code",
"||",
"$",
"code",
"==",
"self",
"::",
"get",
"(",
")",
")",
"{",
"return",
";",
"}",
"// Language file available",
"if",
"(",
"$",
"code",
"!==",
"'en'",
"&&",
"(",
"self",
"::",
"isLanguageEnabled",
"(",
"$",
"code",
")",
"||",
"$",
"checkStatus",
"===",
"false",
")",
")",
"{",
"// Store desired language code",
"self",
"::",
"$",
"_lang",
"=",
"$",
"code",
";",
"// Clear dictionary",
"self",
"::",
"$",
"_dictionary",
"=",
"array",
"(",
")",
";",
"// Load core translations",
"self",
"::",
"load",
"(",
"vsprintf",
"(",
"'%s/lang_%s/lang/lang.%s.php'",
",",
"array",
"(",
"EXTENSIONS",
",",
"self",
"::",
"$",
"_languages",
"[",
"$",
"code",
"]",
"[",
"'handle'",
"]",
",",
"$",
"code",
")",
")",
")",
";",
"// Load extension translations",
"if",
"(",
"is_array",
"(",
"self",
"::",
"$",
"_languages",
"[",
"$",
"code",
"]",
"[",
"'extensions'",
"]",
")",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"_languages",
"[",
"$",
"code",
"]",
"[",
"'extensions'",
"]",
"as",
"$",
"extension",
")",
"{",
"self",
"::",
"load",
"(",
"vsprintf",
"(",
"'%s/%s/lang/lang.%s.php'",
",",
"array",
"(",
"EXTENSIONS",
",",
"$",
"extension",
",",
"$",
"code",
")",
")",
")",
";",
"}",
"}",
"// Language file unavailable, use default language",
"}",
"else",
"{",
"self",
"::",
"$",
"_lang",
"=",
"'en'",
";",
"// Log error, if possible",
"if",
"(",
"$",
"code",
"!==",
"'en'",
"&&",
"class_exists",
"(",
"'Symphony'",
",",
"false",
")",
"&&",
"Symphony",
"::",
"Log",
"(",
")",
"instanceof",
"Log",
")",
"{",
"Symphony",
"::",
"Log",
"(",
")",
"->",
"pushToLog",
"(",
"__",
"(",
"'The selected language, %s, could not be found. Using default English dictionary instead.'",
",",
"array",
"(",
"$",
"code",
")",
")",
",",
"E_ERROR",
",",
"true",
")",
";",
"}",
"}",
"}"
] | Set system language, load translations for core and extensions. If the specified language
cannot be found, Symphony will default to English.
Note: Beginning with Symphony 2.2 translations bundled with extensions will only be loaded
when the core dictionary of the specific language is available.
@param string $code
Language code, e. g. 'en' or 'pt-br'
@param boolean $checkStatus (optional)
If false, set the language even if it's not enabled. Defaults to true. | [
"Set",
"system",
"language",
"load",
"translations",
"for",
"core",
"and",
"extensions",
".",
"If",
"the",
"specified",
"language",
"cannot",
"be",
"found",
"Symphony",
"will",
"default",
"to",
"English",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.lang.php#L248-L289 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.lang.php | Lang.isLanguageEnabled | public static function isLanguageEnabled($code)
{
if ($code == 'en') {
return true;
}
$handle = (isset(self::$_languages[$code])) ? self::$_languages[$code]['handle'] : '';
$enabled_extensions = array();
// Fetch list of active extensions
if (class_exists('Symphony', false) && (!is_null(Symphony::ExtensionManager()))) {
$enabled_extensions = Symphony::ExtensionManager()->listInstalledHandles();
}
return in_array('lang_' . $handle, $enabled_extensions);
} | php | public static function isLanguageEnabled($code)
{
if ($code == 'en') {
return true;
}
$handle = (isset(self::$_languages[$code])) ? self::$_languages[$code]['handle'] : '';
$enabled_extensions = array();
// Fetch list of active extensions
if (class_exists('Symphony', false) && (!is_null(Symphony::ExtensionManager()))) {
$enabled_extensions = Symphony::ExtensionManager()->listInstalledHandles();
}
return in_array('lang_' . $handle, $enabled_extensions);
} | [
"public",
"static",
"function",
"isLanguageEnabled",
"(",
"$",
"code",
")",
"{",
"if",
"(",
"$",
"code",
"==",
"'en'",
")",
"{",
"return",
"true",
";",
"}",
"$",
"handle",
"=",
"(",
"isset",
"(",
"self",
"::",
"$",
"_languages",
"[",
"$",
"code",
"]",
")",
")",
"?",
"self",
"::",
"$",
"_languages",
"[",
"$",
"code",
"]",
"[",
"'handle'",
"]",
":",
"''",
";",
"$",
"enabled_extensions",
"=",
"array",
"(",
")",
";",
"// Fetch list of active extensions",
"if",
"(",
"class_exists",
"(",
"'Symphony'",
",",
"false",
")",
"&&",
"(",
"!",
"is_null",
"(",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
")",
")",
")",
"{",
"$",
"enabled_extensions",
"=",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"listInstalledHandles",
"(",
")",
";",
"}",
"return",
"in_array",
"(",
"'lang_'",
".",
"$",
"handle",
",",
"$",
"enabled_extensions",
")",
";",
"}"
] | Given a valid language code, this function checks if the language is enabled.
@since Symphony 2.3
@param string $code
Language code, e. g. 'en' or 'pt-br'
@return boolean
If true, the language is enabled. | [
"Given",
"a",
"valid",
"language",
"code",
"this",
"function",
"checks",
"if",
"the",
"language",
"is",
"enabled",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.lang.php#L300-L315 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.lang.php | Lang.load | private static function load($path)
{
// Load language file
if (file_exists($path)) {
require($path);
}
// Populate dictionary ($dictionary is declared inside $path)
if (isset($dictionary) && is_array($dictionary)) {
self::$_dictionary = array_merge(self::$_dictionary, $dictionary);
}
// Populate transliterations ($transliterations is declared inside $path)
if (isset($transliterations) && is_array($transliterations)) {
self::$_transliterations = array_merge(self::$_transliterations, $transliterations);
}
} | php | private static function load($path)
{
// Load language file
if (file_exists($path)) {
require($path);
}
// Populate dictionary ($dictionary is declared inside $path)
if (isset($dictionary) && is_array($dictionary)) {
self::$_dictionary = array_merge(self::$_dictionary, $dictionary);
}
// Populate transliterations ($transliterations is declared inside $path)
if (isset($transliterations) && is_array($transliterations)) {
self::$_transliterations = array_merge(self::$_transliterations, $transliterations);
}
} | [
"private",
"static",
"function",
"load",
"(",
"$",
"path",
")",
"{",
"// Load language file",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"require",
"(",
"$",
"path",
")",
";",
"}",
"// Populate dictionary ($dictionary is declared inside $path)",
"if",
"(",
"isset",
"(",
"$",
"dictionary",
")",
"&&",
"is_array",
"(",
"$",
"dictionary",
")",
")",
"{",
"self",
"::",
"$",
"_dictionary",
"=",
"array_merge",
"(",
"self",
"::",
"$",
"_dictionary",
",",
"$",
"dictionary",
")",
";",
"}",
"// Populate transliterations ($transliterations is declared inside $path)",
"if",
"(",
"isset",
"(",
"$",
"transliterations",
")",
"&&",
"is_array",
"(",
"$",
"transliterations",
")",
")",
"{",
"self",
"::",
"$",
"_transliterations",
"=",
"array_merge",
"(",
"self",
"::",
"$",
"_transliterations",
",",
"$",
"transliterations",
")",
";",
"}",
"}"
] | Load language file. Each language file contains three arrays:
about, dictionary and transliterations.
@param string $path
Path of the language file that should be loaded | [
"Load",
"language",
"file",
".",
"Each",
"language",
"file",
"contains",
"three",
"arrays",
":",
"about",
"dictionary",
"and",
"transliterations",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.lang.php#L324-L340 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.lang.php | Lang.translate | public static function translate($string, array $inserts = null, $namespace = null)
{
if (is_null($namespace) && class_exists('Symphony', false)) {
$namespace = Symphony::getPageNamespace();
}
if (isset($namespace, self::$_dictionary[$namespace][$string])) {
$translated = self::$_dictionary[$namespace][$string];
} elseif (isset(self::$_dictionary[$string])) {
$translated = self::$_dictionary[$string];
} else {
$translated = $string;
}
$translated = empty($translated) ? $string : $translated;
// Replace translation placeholders
if (is_array($inserts) && !empty($inserts)) {
$translated = vsprintf($translated, $inserts);
}
return $translated;
} | php | public static function translate($string, array $inserts = null, $namespace = null)
{
if (is_null($namespace) && class_exists('Symphony', false)) {
$namespace = Symphony::getPageNamespace();
}
if (isset($namespace, self::$_dictionary[$namespace][$string])) {
$translated = self::$_dictionary[$namespace][$string];
} elseif (isset(self::$_dictionary[$string])) {
$translated = self::$_dictionary[$string];
} else {
$translated = $string;
}
$translated = empty($translated) ? $string : $translated;
// Replace translation placeholders
if (is_array($inserts) && !empty($inserts)) {
$translated = vsprintf($translated, $inserts);
}
return $translated;
} | [
"public",
"static",
"function",
"translate",
"(",
"$",
"string",
",",
"array",
"$",
"inserts",
"=",
"null",
",",
"$",
"namespace",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"namespace",
")",
"&&",
"class_exists",
"(",
"'Symphony'",
",",
"false",
")",
")",
"{",
"$",
"namespace",
"=",
"Symphony",
"::",
"getPageNamespace",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"namespace",
",",
"self",
"::",
"$",
"_dictionary",
"[",
"$",
"namespace",
"]",
"[",
"$",
"string",
"]",
")",
")",
"{",
"$",
"translated",
"=",
"self",
"::",
"$",
"_dictionary",
"[",
"$",
"namespace",
"]",
"[",
"$",
"string",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"self",
"::",
"$",
"_dictionary",
"[",
"$",
"string",
"]",
")",
")",
"{",
"$",
"translated",
"=",
"self",
"::",
"$",
"_dictionary",
"[",
"$",
"string",
"]",
";",
"}",
"else",
"{",
"$",
"translated",
"=",
"$",
"string",
";",
"}",
"$",
"translated",
"=",
"empty",
"(",
"$",
"translated",
")",
"?",
"$",
"string",
":",
"$",
"translated",
";",
"// Replace translation placeholders",
"if",
"(",
"is_array",
"(",
"$",
"inserts",
")",
"&&",
"!",
"empty",
"(",
"$",
"inserts",
")",
")",
"{",
"$",
"translated",
"=",
"vsprintf",
"(",
"$",
"translated",
",",
"$",
"inserts",
")",
";",
"}",
"return",
"$",
"translated",
";",
"}"
] | This function is an internal alias for `__()`.
@since Symphony 2.3
@see toolkit.__()
@param string $string
The string that should be translated
@param array $inserts (optional)
Optional array used to replace translation placeholders, defaults to NULL
@param string $namespace (optional)
Optional string used to define the namespace, defaults to NULL.
@return string
Returns the translated string | [
"This",
"function",
"is",
"an",
"internal",
"alias",
"for",
"__",
"()",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.lang.php#L366-L388 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.lang.php | Lang.getAvailableLanguages | public static function getAvailableLanguages($checkStatus = true)
{
$languages = array();
// Get available languages
foreach (self::$_languages as $key => $language) {
if (self::isLanguageEnabled($key) || ($checkStatus === false && isset($language['handle']))) {
$languages[$key] = $language['name'];
}
}
// Return languages codes
return $languages;
} | php | public static function getAvailableLanguages($checkStatus = true)
{
$languages = array();
// Get available languages
foreach (self::$_languages as $key => $language) {
if (self::isLanguageEnabled($key) || ($checkStatus === false && isset($language['handle']))) {
$languages[$key] = $language['name'];
}
}
// Return languages codes
return $languages;
} | [
"public",
"static",
"function",
"getAvailableLanguages",
"(",
"$",
"checkStatus",
"=",
"true",
")",
"{",
"$",
"languages",
"=",
"array",
"(",
")",
";",
"// Get available languages",
"foreach",
"(",
"self",
"::",
"$",
"_languages",
"as",
"$",
"key",
"=>",
"$",
"language",
")",
"{",
"if",
"(",
"self",
"::",
"isLanguageEnabled",
"(",
"$",
"key",
")",
"||",
"(",
"$",
"checkStatus",
"===",
"false",
"&&",
"isset",
"(",
"$",
"language",
"[",
"'handle'",
"]",
")",
")",
")",
"{",
"$",
"languages",
"[",
"$",
"key",
"]",
"=",
"$",
"language",
"[",
"'name'",
"]",
";",
"}",
"}",
"// Return languages codes",
"return",
"$",
"languages",
";",
"}"
] | Get an array of the codes and names of all languages that are available system wide.
Note: Beginning with Symphony 2.2 language files are only available
when the language extension is explicitly enabled.
@param boolean $checkStatus (optional)
If false, retrieves a list a languages that support core translation.
@return array
Returns an associative array of language codes and names, e. g. 'en' => 'English' | [
"Get",
"an",
"array",
"of",
"the",
"codes",
"and",
"names",
"of",
"all",
"languages",
"that",
"are",
"available",
"system",
"wide",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.lang.php#L401-L414 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.lang.php | Lang.localizeDate | public static function localizeDate($string)
{
// Only translate dates in localized environments
if (self::isLocalized()) {
foreach (self::$_datetime_dictionary as $value) {
$string = preg_replace('/\b' . $value . '\b/i', self::translate($value), $string);
}
}
return $string;
} | php | public static function localizeDate($string)
{
// Only translate dates in localized environments
if (self::isLocalized()) {
foreach (self::$_datetime_dictionary as $value) {
$string = preg_replace('/\b' . $value . '\b/i', self::translate($value), $string);
}
}
return $string;
} | [
"public",
"static",
"function",
"localizeDate",
"(",
"$",
"string",
")",
"{",
"// Only translate dates in localized environments",
"if",
"(",
"self",
"::",
"isLocalized",
"(",
")",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"_datetime_dictionary",
"as",
"$",
"value",
")",
"{",
"$",
"string",
"=",
"preg_replace",
"(",
"'/\\b'",
".",
"$",
"value",
".",
"'\\b/i'",
",",
"self",
"::",
"translate",
"(",
"$",
"value",
")",
",",
"$",
"string",
")",
";",
"}",
"}",
"return",
"$",
"string",
";",
"}"
] | Localize dates.
@param string $string
Standard date that should be localized
@return string
Return the given date with translated month and day names | [
"Localize",
"dates",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.lang.php#L435-L445 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.lang.php | Lang.standardizeDate | public static function standardizeDate($string)
{
// Only standardize dates in localized environments
if (self::isLocalized()) {
// Translate names to English
foreach (self::$_datetime_dictionary as $values) {
$string = preg_replace('/\b' . self::translate($values) . '\b/i' . (self::isUnicodeCompiled() === true ? 'u' : null), $values, $string);
}
// Replace custom date and time separator with space:
// This is important, otherwise the `DateTime` constructor may break
// @todo Test if this separator is still required. It's a hidden setting
// and users are only aware of it if they go digging/pointed in the right direction
$separator = Symphony::Configuration()->get('datetime_separator', 'region');
if ($separator !== ' ') {
$string = str_replace($separator, ' ', $string);
}
}
return $string;
} | php | public static function standardizeDate($string)
{
// Only standardize dates in localized environments
if (self::isLocalized()) {
// Translate names to English
foreach (self::$_datetime_dictionary as $values) {
$string = preg_replace('/\b' . self::translate($values) . '\b/i' . (self::isUnicodeCompiled() === true ? 'u' : null), $values, $string);
}
// Replace custom date and time separator with space:
// This is important, otherwise the `DateTime` constructor may break
// @todo Test if this separator is still required. It's a hidden setting
// and users are only aware of it if they go digging/pointed in the right direction
$separator = Symphony::Configuration()->get('datetime_separator', 'region');
if ($separator !== ' ') {
$string = str_replace($separator, ' ', $string);
}
}
return $string;
} | [
"public",
"static",
"function",
"standardizeDate",
"(",
"$",
"string",
")",
"{",
"// Only standardize dates in localized environments",
"if",
"(",
"self",
"::",
"isLocalized",
"(",
")",
")",
"{",
"// Translate names to English",
"foreach",
"(",
"self",
"::",
"$",
"_datetime_dictionary",
"as",
"$",
"values",
")",
"{",
"$",
"string",
"=",
"preg_replace",
"(",
"'/\\b'",
".",
"self",
"::",
"translate",
"(",
"$",
"values",
")",
".",
"'\\b/i'",
".",
"(",
"self",
"::",
"isUnicodeCompiled",
"(",
")",
"===",
"true",
"?",
"'u'",
":",
"null",
")",
",",
"$",
"values",
",",
"$",
"string",
")",
";",
"}",
"// Replace custom date and time separator with space:",
"// This is important, otherwise the `DateTime` constructor may break",
"// @todo Test if this separator is still required. It's a hidden setting",
"// and users are only aware of it if they go digging/pointed in the right direction",
"$",
"separator",
"=",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'datetime_separator'",
",",
"'region'",
")",
";",
"if",
"(",
"$",
"separator",
"!==",
"' '",
")",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"$",
"separator",
",",
"' '",
",",
"$",
"string",
")",
";",
"}",
"}",
"return",
"$",
"string",
";",
"}"
] | Standardize dates.
@param string $string
Localized date that should be standardized
@return string
Returns the given date with English month and day names | [
"Standardize",
"dates",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.lang.php#L455-L476 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.lang.php | Lang.createHandle | public static function createHandle($string, $max_length = 255, $delim = '-', $uriencode = false, $apply_transliteration = true, $additional_rule_set = null)
{
// Use the transliteration table if provided
if ($apply_transliteration === true) {
$string = self::applyTransliterations($string);
}
return General::createHandle($string, $max_length, $delim, $uriencode, $additional_rule_set);
} | php | public static function createHandle($string, $max_length = 255, $delim = '-', $uriencode = false, $apply_transliteration = true, $additional_rule_set = null)
{
// Use the transliteration table if provided
if ($apply_transliteration === true) {
$string = self::applyTransliterations($string);
}
return General::createHandle($string, $max_length, $delim, $uriencode, $additional_rule_set);
} | [
"public",
"static",
"function",
"createHandle",
"(",
"$",
"string",
",",
"$",
"max_length",
"=",
"255",
",",
"$",
"delim",
"=",
"'-'",
",",
"$",
"uriencode",
"=",
"false",
",",
"$",
"apply_transliteration",
"=",
"true",
",",
"$",
"additional_rule_set",
"=",
"null",
")",
"{",
"// Use the transliteration table if provided",
"if",
"(",
"$",
"apply_transliteration",
"===",
"true",
")",
"{",
"$",
"string",
"=",
"self",
"::",
"applyTransliterations",
"(",
"$",
"string",
")",
";",
"}",
"return",
"General",
"::",
"createHandle",
"(",
"$",
"string",
",",
"$",
"max_length",
",",
"$",
"delim",
",",
"$",
"uriencode",
",",
"$",
"additional_rule_set",
")",
";",
"}"
] | Given a string, this will clean it for use as a Symphony handle. Preserves multi-byte characters.
@param string $string
String to be cleaned up
@param integer $max_length
The maximum number of characters in the handle
@param string $delim
All non-valid characters will be replaced with this
@param boolean $uriencode
Force the resultant string to be uri encoded making it safe for URLs
@param boolean $apply_transliteration
If true, this will run the string through an array of substitution characters
@param array $additional_rule_set
An array of REGEX patterns that should be applied to the `$string`. This
occurs after the string has been trimmed and joined with the `$delim`
@return string
Returns resultant handle | [
"Given",
"a",
"string",
"this",
"will",
"clean",
"it",
"for",
"use",
"as",
"a",
"Symphony",
"handle",
".",
"Preserves",
"multi",
"-",
"byte",
"characters",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.lang.php#L497-L505 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.lang.php | Lang.createFilename | public static function createFilename($string, $delim='-', $apply_transliteration = true)
{
// Use the transliteration table if provided
if ($apply_transliteration === true) {
$file = pathinfo($string);
$string = self::applyTransliterations($file['filename']) . '.' . $file['extension'];
}
return General::createFilename($string, $delim);
} | php | public static function createFilename($string, $delim='-', $apply_transliteration = true)
{
// Use the transliteration table if provided
if ($apply_transliteration === true) {
$file = pathinfo($string);
$string = self::applyTransliterations($file['filename']) . '.' . $file['extension'];
}
return General::createFilename($string, $delim);
} | [
"public",
"static",
"function",
"createFilename",
"(",
"$",
"string",
",",
"$",
"delim",
"=",
"'-'",
",",
"$",
"apply_transliteration",
"=",
"true",
")",
"{",
"// Use the transliteration table if provided",
"if",
"(",
"$",
"apply_transliteration",
"===",
"true",
")",
"{",
"$",
"file",
"=",
"pathinfo",
"(",
"$",
"string",
")",
";",
"$",
"string",
"=",
"self",
"::",
"applyTransliterations",
"(",
"$",
"file",
"[",
"'filename'",
"]",
")",
".",
"'.'",
".",
"$",
"file",
"[",
"'extension'",
"]",
";",
"}",
"return",
"General",
"::",
"createFilename",
"(",
"$",
"string",
",",
"$",
"delim",
")",
";",
"}"
] | Given a string, this will clean it for use as a filename. Preserves multi-byte characters.
@param string $string
String to be cleaned up
@param string $delim
Replacement for invalid characters
@param boolean $apply_transliteration
If true, umlauts and special characters will be substituted
@return string
Returns created filename | [
"Given",
"a",
"string",
"this",
"will",
"clean",
"it",
"for",
"use",
"as",
"a",
"filename",
".",
"Preserves",
"multi",
"-",
"byte",
"characters",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.lang.php#L519-L528 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.lang.php | Lang.applyTransliterations | private static function applyTransliterations($string)
{
// Apply the straight transliterations with strtr as it's much faster
$string = strtr($string, self::$_transliterations['straight']);
// Apply the regex rules over the resulting $string
return preg_replace(
array_keys(self::$_transliterations['regexp']),
array_values(self::$_transliterations['regexp']),
$string
);
} | php | private static function applyTransliterations($string)
{
// Apply the straight transliterations with strtr as it's much faster
$string = strtr($string, self::$_transliterations['straight']);
// Apply the regex rules over the resulting $string
return preg_replace(
array_keys(self::$_transliterations['regexp']),
array_values(self::$_transliterations['regexp']),
$string
);
} | [
"private",
"static",
"function",
"applyTransliterations",
"(",
"$",
"string",
")",
"{",
"// Apply the straight transliterations with strtr as it's much faster",
"$",
"string",
"=",
"strtr",
"(",
"$",
"string",
",",
"self",
"::",
"$",
"_transliterations",
"[",
"'straight'",
"]",
")",
";",
"// Apply the regex rules over the resulting $string",
"return",
"preg_replace",
"(",
"array_keys",
"(",
"self",
"::",
"$",
"_transliterations",
"[",
"'regexp'",
"]",
")",
",",
"array_values",
"(",
"self",
"::",
"$",
"_transliterations",
"[",
"'regexp'",
"]",
")",
",",
"$",
"string",
")",
";",
"}"
] | This function replaces special characters according to the values stored inside
`$_transliterations`.
@since Symphony 2.3
@param string $string
The string that should be cleaned-up
@return mixed
Returns the transliterated string | [
"This",
"function",
"replaces",
"special",
"characters",
"according",
"to",
"the",
"values",
"stored",
"inside",
"$_transliterations",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.lang.php#L540-L551 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/StringMatchMarshaller.php | StringMatchMarshaller.unmarshallChildrenKnown | protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children)
{
if (($caseSensitive = $this->getDOMElementAttributeAs($element, 'caseSensitive', 'boolean')) !== null) {
$object = new StringMatch($children, $caseSensitive);
if (($substring = $this->getDOMElementAttributeAs($element, 'substring', 'boolean')) !== null) {
$object->setSubstring($substring);
}
return $object;
} else {
$msg = "The mandatory attribute 'caseSensitive' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children)
{
if (($caseSensitive = $this->getDOMElementAttributeAs($element, 'caseSensitive', 'boolean')) !== null) {
$object = new StringMatch($children, $caseSensitive);
if (($substring = $this->getDOMElementAttributeAs($element, 'substring', 'boolean')) !== null) {
$object->setSubstring($substring);
}
return $object;
} else {
$msg = "The mandatory attribute 'caseSensitive' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshallChildrenKnown",
"(",
"DOMElement",
"$",
"element",
",",
"QtiComponentCollection",
"$",
"children",
")",
"{",
"if",
"(",
"(",
"$",
"caseSensitive",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'caseSensitive'",
",",
"'boolean'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"=",
"new",
"StringMatch",
"(",
"$",
"children",
",",
"$",
"caseSensitive",
")",
";",
"if",
"(",
"(",
"$",
"substring",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'substring'",
",",
"'boolean'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setSubstring",
"(",
"$",
"substring",
")",
";",
"}",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'caseSensitive' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a QTI stringMatch operator element into an StringMatch object.
@param \DOMElement The stringMatch element to unmarshall.
@param \qtism\data\QtiComponentCollection A collection containing the child Expression objects composing the Operator.
@return \qtism\data\QtiComponent An StringMatch object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"QTI",
"stringMatch",
"operator",
"element",
"into",
"an",
"StringMatch",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/StringMatchMarshaller.php#L67-L82 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/XmlDocument.php | XmlDocument.load | public function load($uri, $validate = false)
{
$this->loadImplementation($uri, $validate, false);
// We now are sure that the URI is valid.
$this->setUrl($uri);
} | php | public function load($uri, $validate = false)
{
$this->loadImplementation($uri, $validate, false);
// We now are sure that the URI is valid.
$this->setUrl($uri);
} | [
"public",
"function",
"load",
"(",
"$",
"uri",
",",
"$",
"validate",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"loadImplementation",
"(",
"$",
"uri",
",",
"$",
"validate",
",",
"false",
")",
";",
"// We now are sure that the URI is valid.",
"$",
"this",
"->",
"setUrl",
"(",
"$",
"uri",
")",
";",
"}"
] | Load a QTI-XML assessment file. The file will be loaded and represented in
an AssessmentTest object.
If the XmlDocument object was previously with a QTI version which does not
correspond to version in use in the loaded file, the version found into
the file will supersede the version specified at instantiation time.
@param string $uri The Uniform Resource Identifier that identifies/locate the file.
@param boolean $validate Whether or not the file must be validated unsing XML Schema? Default is false.
@throws \qtism\data\storage\xml\XmlStorageException If an error occurs while loading the QTI-XML file. | [
"Load",
"a",
"QTI",
"-",
"XML",
"assessment",
"file",
".",
"The",
"file",
"will",
"be",
"loaded",
"and",
"represented",
"in",
"an",
"AssessmentTest",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/XmlDocument.php#L114-L120 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/XmlDocument.php | XmlDocument.loadImplementation | protected function loadImplementation($data, $validate = false, $fromString = false)
{
try {
$this->setDomDocument(new DOMDocument('1.0', 'UTF-8'));
$this->getDomDocument()->preserveWhiteSpace = true;
// Disable xml warnings and errors and fetch error information as needed.
$oldErrorConfig = libxml_use_internal_errors(true);
// Determine which way to load (from string or from file).
$loadMethod = ($fromString === true) ? 'loadXML' : 'load';
$doc = $this->getDomDocument();
if ($loadMethod === 'loadXML' && empty($data) === true) {
// Pre-check to throw an appropriate exception when load from an empty string.
$msg = "Cannot load QTI from an empty string.";
throw new XmlStorageException($msg, XmlStorageException::READ);
} else if ($loadMethod === 'load') {
// Pre-check to throw an appropriate exception when loading from a non-resolvable file.
if (is_readable($data) === false) {
$msg = "Cannot load QTI file '${data}'. It does not exist or is not readable.";
throw new XmlStorageException($msg, XmlStorageException::RESOLUTION);
}
}
if (@call_user_func_array(array($doc, $loadMethod), array($data, LIBXML_COMPACT|LIBXML_NONET|LIBXML_XINCLUDE))) {
// Infer the QTI version.
if ($fromString === false) {
// When loaded from a file, the version infered from
// that filed always supersedes the one specified
// when the XmlDocument object is instantiated.
if (($version = $this->inferVersion()) !== false) {
$this->setVersion($version);
} else {
$msg = "Cannot infer QTI version. Check namespaces and schema locations in XML file.";
throw new XmlStorageException($msg, XmlStorageException::VERSION);
}
} else {
// When loaded from a string, the version to be used
// is the one specified when the XmlDocument object
// is instantiated.
}
if ($validate === true) {
$this->schemaValidate();
}
try {
// Get the root element and unmarshall.
$element = $this->getDomDocument()->documentElement;
$factory = $this->createMarshallerFactory();
$marshaller = $factory->createMarshaller($element);
$this->setDocumentComponent($marshaller->unmarshall($element));
} catch (UnmarshallingException $e) {
$line = $e->getDOMElement()->getLineNo();
$msg = "An error occured while processing QTI-XML at line ${line}.";
throw new XmlStorageException($msg, XmlStorageException::READ, $e);
} catch (MarshallerNotFoundException $e) {
$version = $this->getVersion();
$problematicQtiClassName = $e->getQtiClassName();
$msg = "'${problematicQtiClassName}' components are not supported in QTI version '${version}'.";
throw new XmlStorageException($msg, XmlStorageException::VERSION, $e);
}
} else {
$libXmlErrors = libxml_get_errors();
$formattedErrors = self::formatLibXmlErrors($libXmlErrors);
libxml_clear_errors();
libxml_use_internal_errors($oldErrorConfig);
$msg = "An internal error occured while parsing QTI-XML:\n${formattedErrors}";
throw new XmlStorageException($msg, XmlStorageException::READ, null, new LibXmlErrorCollection($libXmlErrors));
}
} catch (DOMException $e) {
$line = $e->getLine();
$msg = "An error occured while parsing QTI-XML at line ${line}.";
throw new XmlStorageException($msg, XmlStorageException::READ, $e);
}
} | php | protected function loadImplementation($data, $validate = false, $fromString = false)
{
try {
$this->setDomDocument(new DOMDocument('1.0', 'UTF-8'));
$this->getDomDocument()->preserveWhiteSpace = true;
// Disable xml warnings and errors and fetch error information as needed.
$oldErrorConfig = libxml_use_internal_errors(true);
// Determine which way to load (from string or from file).
$loadMethod = ($fromString === true) ? 'loadXML' : 'load';
$doc = $this->getDomDocument();
if ($loadMethod === 'loadXML' && empty($data) === true) {
// Pre-check to throw an appropriate exception when load from an empty string.
$msg = "Cannot load QTI from an empty string.";
throw new XmlStorageException($msg, XmlStorageException::READ);
} else if ($loadMethod === 'load') {
// Pre-check to throw an appropriate exception when loading from a non-resolvable file.
if (is_readable($data) === false) {
$msg = "Cannot load QTI file '${data}'. It does not exist or is not readable.";
throw new XmlStorageException($msg, XmlStorageException::RESOLUTION);
}
}
if (@call_user_func_array(array($doc, $loadMethod), array($data, LIBXML_COMPACT|LIBXML_NONET|LIBXML_XINCLUDE))) {
// Infer the QTI version.
if ($fromString === false) {
// When loaded from a file, the version infered from
// that filed always supersedes the one specified
// when the XmlDocument object is instantiated.
if (($version = $this->inferVersion()) !== false) {
$this->setVersion($version);
} else {
$msg = "Cannot infer QTI version. Check namespaces and schema locations in XML file.";
throw new XmlStorageException($msg, XmlStorageException::VERSION);
}
} else {
// When loaded from a string, the version to be used
// is the one specified when the XmlDocument object
// is instantiated.
}
if ($validate === true) {
$this->schemaValidate();
}
try {
// Get the root element and unmarshall.
$element = $this->getDomDocument()->documentElement;
$factory = $this->createMarshallerFactory();
$marshaller = $factory->createMarshaller($element);
$this->setDocumentComponent($marshaller->unmarshall($element));
} catch (UnmarshallingException $e) {
$line = $e->getDOMElement()->getLineNo();
$msg = "An error occured while processing QTI-XML at line ${line}.";
throw new XmlStorageException($msg, XmlStorageException::READ, $e);
} catch (MarshallerNotFoundException $e) {
$version = $this->getVersion();
$problematicQtiClassName = $e->getQtiClassName();
$msg = "'${problematicQtiClassName}' components are not supported in QTI version '${version}'.";
throw new XmlStorageException($msg, XmlStorageException::VERSION, $e);
}
} else {
$libXmlErrors = libxml_get_errors();
$formattedErrors = self::formatLibXmlErrors($libXmlErrors);
libxml_clear_errors();
libxml_use_internal_errors($oldErrorConfig);
$msg = "An internal error occured while parsing QTI-XML:\n${formattedErrors}";
throw new XmlStorageException($msg, XmlStorageException::READ, null, new LibXmlErrorCollection($libXmlErrors));
}
} catch (DOMException $e) {
$line = $e->getLine();
$msg = "An error occured while parsing QTI-XML at line ${line}.";
throw new XmlStorageException($msg, XmlStorageException::READ, $e);
}
} | [
"protected",
"function",
"loadImplementation",
"(",
"$",
"data",
",",
"$",
"validate",
"=",
"false",
",",
"$",
"fromString",
"=",
"false",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"setDomDocument",
"(",
"new",
"DOMDocument",
"(",
"'1.0'",
",",
"'UTF-8'",
")",
")",
";",
"$",
"this",
"->",
"getDomDocument",
"(",
")",
"->",
"preserveWhiteSpace",
"=",
"true",
";",
"// Disable xml warnings and errors and fetch error information as needed.",
"$",
"oldErrorConfig",
"=",
"libxml_use_internal_errors",
"(",
"true",
")",
";",
"// Determine which way to load (from string or from file).",
"$",
"loadMethod",
"=",
"(",
"$",
"fromString",
"===",
"true",
")",
"?",
"'loadXML'",
":",
"'load'",
";",
"$",
"doc",
"=",
"$",
"this",
"->",
"getDomDocument",
"(",
")",
";",
"if",
"(",
"$",
"loadMethod",
"===",
"'loadXML'",
"&&",
"empty",
"(",
"$",
"data",
")",
"===",
"true",
")",
"{",
"// Pre-check to throw an appropriate exception when load from an empty string.",
"$",
"msg",
"=",
"\"Cannot load QTI from an empty string.\"",
";",
"throw",
"new",
"XmlStorageException",
"(",
"$",
"msg",
",",
"XmlStorageException",
"::",
"READ",
")",
";",
"}",
"else",
"if",
"(",
"$",
"loadMethod",
"===",
"'load'",
")",
"{",
"// Pre-check to throw an appropriate exception when loading from a non-resolvable file.",
"if",
"(",
"is_readable",
"(",
"$",
"data",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"Cannot load QTI file '${data}'. It does not exist or is not readable.\"",
";",
"throw",
"new",
"XmlStorageException",
"(",
"$",
"msg",
",",
"XmlStorageException",
"::",
"RESOLUTION",
")",
";",
"}",
"}",
"if",
"(",
"@",
"call_user_func_array",
"(",
"array",
"(",
"$",
"doc",
",",
"$",
"loadMethod",
")",
",",
"array",
"(",
"$",
"data",
",",
"LIBXML_COMPACT",
"|",
"LIBXML_NONET",
"|",
"LIBXML_XINCLUDE",
")",
")",
")",
"{",
"// Infer the QTI version.",
"if",
"(",
"$",
"fromString",
"===",
"false",
")",
"{",
"// When loaded from a file, the version infered from",
"// that filed always supersedes the one specified",
"// when the XmlDocument object is instantiated.",
"if",
"(",
"(",
"$",
"version",
"=",
"$",
"this",
"->",
"inferVersion",
"(",
")",
")",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"setVersion",
"(",
"$",
"version",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Cannot infer QTI version. Check namespaces and schema locations in XML file.\"",
";",
"throw",
"new",
"XmlStorageException",
"(",
"$",
"msg",
",",
"XmlStorageException",
"::",
"VERSION",
")",
";",
"}",
"}",
"else",
"{",
"// When loaded from a string, the version to be used",
"// is the one specified when the XmlDocument object",
"// is instantiated.",
"}",
"if",
"(",
"$",
"validate",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"schemaValidate",
"(",
")",
";",
"}",
"try",
"{",
"// Get the root element and unmarshall.",
"$",
"element",
"=",
"$",
"this",
"->",
"getDomDocument",
"(",
")",
"->",
"documentElement",
";",
"$",
"factory",
"=",
"$",
"this",
"->",
"createMarshallerFactory",
"(",
")",
";",
"$",
"marshaller",
"=",
"$",
"factory",
"->",
"createMarshaller",
"(",
"$",
"element",
")",
";",
"$",
"this",
"->",
"setDocumentComponent",
"(",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"element",
")",
")",
";",
"}",
"catch",
"(",
"UnmarshallingException",
"$",
"e",
")",
"{",
"$",
"line",
"=",
"$",
"e",
"->",
"getDOMElement",
"(",
")",
"->",
"getLineNo",
"(",
")",
";",
"$",
"msg",
"=",
"\"An error occured while processing QTI-XML at line ${line}.\"",
";",
"throw",
"new",
"XmlStorageException",
"(",
"$",
"msg",
",",
"XmlStorageException",
"::",
"READ",
",",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"MarshallerNotFoundException",
"$",
"e",
")",
"{",
"$",
"version",
"=",
"$",
"this",
"->",
"getVersion",
"(",
")",
";",
"$",
"problematicQtiClassName",
"=",
"$",
"e",
"->",
"getQtiClassName",
"(",
")",
";",
"$",
"msg",
"=",
"\"'${problematicQtiClassName}' components are not supported in QTI version '${version}'.\"",
";",
"throw",
"new",
"XmlStorageException",
"(",
"$",
"msg",
",",
"XmlStorageException",
"::",
"VERSION",
",",
"$",
"e",
")",
";",
"}",
"}",
"else",
"{",
"$",
"libXmlErrors",
"=",
"libxml_get_errors",
"(",
")",
";",
"$",
"formattedErrors",
"=",
"self",
"::",
"formatLibXmlErrors",
"(",
"$",
"libXmlErrors",
")",
";",
"libxml_clear_errors",
"(",
")",
";",
"libxml_use_internal_errors",
"(",
"$",
"oldErrorConfig",
")",
";",
"$",
"msg",
"=",
"\"An internal error occured while parsing QTI-XML:\\n${formattedErrors}\"",
";",
"throw",
"new",
"XmlStorageException",
"(",
"$",
"msg",
",",
"XmlStorageException",
"::",
"READ",
",",
"null",
",",
"new",
"LibXmlErrorCollection",
"(",
"$",
"libXmlErrors",
")",
")",
";",
"}",
"}",
"catch",
"(",
"DOMException",
"$",
"e",
")",
"{",
"$",
"line",
"=",
"$",
"e",
"->",
"getLine",
"(",
")",
";",
"$",
"msg",
"=",
"\"An error occured while parsing QTI-XML at line ${line}.\"",
";",
"throw",
"new",
"XmlStorageException",
"(",
"$",
"msg",
",",
"XmlStorageException",
"::",
"READ",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Implementation of load.
@param mixed $data
@param boolean $validate
@param boolean $fromString
@throws \qtism\data\storage\xml\XmlStorageException | [
"Implementation",
"of",
"load",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/XmlDocument.php#L142-L222 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/XmlDocument.php | XmlDocument.saveImplementation | protected function saveImplementation($uri = '', $formatOutput = true)
{
$qtiComponent = $this->getDocumentComponent();
if (!empty($qtiComponent)) {
$this->setDomDocument(new DOMDocument('1.0', 'UTF-8'));
if ($formatOutput == true) {
$this->getDomDocument()->formatOutput = true;
}
try {
// If overriden, beforeSave may alter a last time
// the documentComponent prior serialization.
// Note: in use only when saving to a file.
if (empty($uri) === false) {
$this->beforeSave($this->getDocumentComponent(), $uri);
}
$factory = $this->createMarshallerFactory();
$marshaller = $factory->createMarshaller($this->getDocumentComponent());
$element = $marshaller->marshall($this->getDocumentComponent());
$rootElement = $this->getDomDocument()->importNode($element, true);
$this->getDomDocument()->appendChild($rootElement);
$this->decorateRootElement($rootElement);
if (empty($uri) === false) {
if (@$this->getDomDocument()->save($uri) === false) {
// An error occured while saving.
$msg = "An error occured while saving QTI-XML file at '${uri}'. Maybe the save location is not reachable?";
throw new XmlStorageException($msg, XmlStorageException::WRITE);
}
} else {
if (($strXml = $this->getDomDocument()->saveXML()) !== false) {
return $strXml;
} else {
// An error occured while saving.
$msg = "An internal error occured while exporting QTI-XML as string.";
throw new XmlStorageException($msg, XmlStorageException::WRITE);
}
}
} catch (DOMException $e) {
$msg = "An internal error occured while saving QTI-XML data.";
throw new XmlStorageException($msg, XmlStorageException::UNKNOWN, $e);
} catch (MarshallerNotFoundException $e) {
$version = $this->getVersion();
$problematicQtiClassName = $e->getQtiClassName();
$msg = "'${problematicQtiClassName}' components are not supported in QTI version '${version}'.";
throw new XmlStorageException($msg, XmlStorageException::VERSION, $e);
}
} else {
$msg = "The document cannot be saved. No document component object to be saved.";
throw new XmlStorageException($msg, XmlStorageException::WRITE);
}
} | php | protected function saveImplementation($uri = '', $formatOutput = true)
{
$qtiComponent = $this->getDocumentComponent();
if (!empty($qtiComponent)) {
$this->setDomDocument(new DOMDocument('1.0', 'UTF-8'));
if ($formatOutput == true) {
$this->getDomDocument()->formatOutput = true;
}
try {
// If overriden, beforeSave may alter a last time
// the documentComponent prior serialization.
// Note: in use only when saving to a file.
if (empty($uri) === false) {
$this->beforeSave($this->getDocumentComponent(), $uri);
}
$factory = $this->createMarshallerFactory();
$marshaller = $factory->createMarshaller($this->getDocumentComponent());
$element = $marshaller->marshall($this->getDocumentComponent());
$rootElement = $this->getDomDocument()->importNode($element, true);
$this->getDomDocument()->appendChild($rootElement);
$this->decorateRootElement($rootElement);
if (empty($uri) === false) {
if (@$this->getDomDocument()->save($uri) === false) {
// An error occured while saving.
$msg = "An error occured while saving QTI-XML file at '${uri}'. Maybe the save location is not reachable?";
throw new XmlStorageException($msg, XmlStorageException::WRITE);
}
} else {
if (($strXml = $this->getDomDocument()->saveXML()) !== false) {
return $strXml;
} else {
// An error occured while saving.
$msg = "An internal error occured while exporting QTI-XML as string.";
throw new XmlStorageException($msg, XmlStorageException::WRITE);
}
}
} catch (DOMException $e) {
$msg = "An internal error occured while saving QTI-XML data.";
throw new XmlStorageException($msg, XmlStorageException::UNKNOWN, $e);
} catch (MarshallerNotFoundException $e) {
$version = $this->getVersion();
$problematicQtiClassName = $e->getQtiClassName();
$msg = "'${problematicQtiClassName}' components are not supported in QTI version '${version}'.";
throw new XmlStorageException($msg, XmlStorageException::VERSION, $e);
}
} else {
$msg = "The document cannot be saved. No document component object to be saved.";
throw new XmlStorageException($msg, XmlStorageException::WRITE);
}
} | [
"protected",
"function",
"saveImplementation",
"(",
"$",
"uri",
"=",
"''",
",",
"$",
"formatOutput",
"=",
"true",
")",
"{",
"$",
"qtiComponent",
"=",
"$",
"this",
"->",
"getDocumentComponent",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"qtiComponent",
")",
")",
"{",
"$",
"this",
"->",
"setDomDocument",
"(",
"new",
"DOMDocument",
"(",
"'1.0'",
",",
"'UTF-8'",
")",
")",
";",
"if",
"(",
"$",
"formatOutput",
"==",
"true",
")",
"{",
"$",
"this",
"->",
"getDomDocument",
"(",
")",
"->",
"formatOutput",
"=",
"true",
";",
"}",
"try",
"{",
"// If overriden, beforeSave may alter a last time",
"// the documentComponent prior serialization.",
"// Note: in use only when saving to a file.",
"if",
"(",
"empty",
"(",
"$",
"uri",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"beforeSave",
"(",
"$",
"this",
"->",
"getDocumentComponent",
"(",
")",
",",
"$",
"uri",
")",
";",
"}",
"$",
"factory",
"=",
"$",
"this",
"->",
"createMarshallerFactory",
"(",
")",
";",
"$",
"marshaller",
"=",
"$",
"factory",
"->",
"createMarshaller",
"(",
"$",
"this",
"->",
"getDocumentComponent",
"(",
")",
")",
";",
"$",
"element",
"=",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"this",
"->",
"getDocumentComponent",
"(",
")",
")",
";",
"$",
"rootElement",
"=",
"$",
"this",
"->",
"getDomDocument",
"(",
")",
"->",
"importNode",
"(",
"$",
"element",
",",
"true",
")",
";",
"$",
"this",
"->",
"getDomDocument",
"(",
")",
"->",
"appendChild",
"(",
"$",
"rootElement",
")",
";",
"$",
"this",
"->",
"decorateRootElement",
"(",
"$",
"rootElement",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"uri",
")",
"===",
"false",
")",
"{",
"if",
"(",
"@",
"$",
"this",
"->",
"getDomDocument",
"(",
")",
"->",
"save",
"(",
"$",
"uri",
")",
"===",
"false",
")",
"{",
"// An error occured while saving.",
"$",
"msg",
"=",
"\"An error occured while saving QTI-XML file at '${uri}'. Maybe the save location is not reachable?\"",
";",
"throw",
"new",
"XmlStorageException",
"(",
"$",
"msg",
",",
"XmlStorageException",
"::",
"WRITE",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"(",
"$",
"strXml",
"=",
"$",
"this",
"->",
"getDomDocument",
"(",
")",
"->",
"saveXML",
"(",
")",
")",
"!==",
"false",
")",
"{",
"return",
"$",
"strXml",
";",
"}",
"else",
"{",
"// An error occured while saving.",
"$",
"msg",
"=",
"\"An internal error occured while exporting QTI-XML as string.\"",
";",
"throw",
"new",
"XmlStorageException",
"(",
"$",
"msg",
",",
"XmlStorageException",
"::",
"WRITE",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"DOMException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An internal error occured while saving QTI-XML data.\"",
";",
"throw",
"new",
"XmlStorageException",
"(",
"$",
"msg",
",",
"XmlStorageException",
"::",
"UNKNOWN",
",",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"MarshallerNotFoundException",
"$",
"e",
")",
"{",
"$",
"version",
"=",
"$",
"this",
"->",
"getVersion",
"(",
")",
";",
"$",
"problematicQtiClassName",
"=",
"$",
"e",
"->",
"getQtiClassName",
"(",
")",
";",
"$",
"msg",
"=",
"\"'${problematicQtiClassName}' components are not supported in QTI version '${version}'.\"",
";",
"throw",
"new",
"XmlStorageException",
"(",
"$",
"msg",
",",
"XmlStorageException",
"::",
"VERSION",
",",
"$",
"e",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The document cannot be saved. No document component object to be saved.\"",
";",
"throw",
"new",
"XmlStorageException",
"(",
"$",
"msg",
",",
"XmlStorageException",
"::",
"WRITE",
")",
";",
"}",
"}"
] | Implementation of save.
@param string $uri
@param boolean $formatOutput
@throws \qtism\data\storage\xml\XmlStorageException
@return string | [
"Implementation",
"of",
"save",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/XmlDocument.php#L270-L326 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/XmlDocument.php | XmlDocument.schemaValidate | public function schemaValidate($filename = '')
{
if (empty($filename)) {
$filename = XmlUtils::getSchemaLocation($this->getVersion());
}
if (is_readable($filename)) {
$oldErrorConfig = libxml_use_internal_errors(true);
$doc = $this->getDomDocument();
if (@$doc->schemaValidate($filename) === false) {
$libXmlErrors = libxml_get_errors();
$formattedErrors = self::formatLibXmlErrors($libXmlErrors);
libxml_clear_errors();
libxml_use_internal_errors($oldErrorConfig);
$msg = "The document could not be validated with XML Schema:\n${formattedErrors}";
throw new XmlStorageException($msg, XmlStorageException::XSD_VALIDATION, null, new LibXmlErrorCollection($libXmlErrors));
}
} else {
$msg = "Schema '${filename}' cannot be read. Does this file exist? Is it readable?";
throw new InvalidArgumentException($msg);
}
} | php | public function schemaValidate($filename = '')
{
if (empty($filename)) {
$filename = XmlUtils::getSchemaLocation($this->getVersion());
}
if (is_readable($filename)) {
$oldErrorConfig = libxml_use_internal_errors(true);
$doc = $this->getDomDocument();
if (@$doc->schemaValidate($filename) === false) {
$libXmlErrors = libxml_get_errors();
$formattedErrors = self::formatLibXmlErrors($libXmlErrors);
libxml_clear_errors();
libxml_use_internal_errors($oldErrorConfig);
$msg = "The document could not be validated with XML Schema:\n${formattedErrors}";
throw new XmlStorageException($msg, XmlStorageException::XSD_VALIDATION, null, new LibXmlErrorCollection($libXmlErrors));
}
} else {
$msg = "Schema '${filename}' cannot be read. Does this file exist? Is it readable?";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"schemaValidate",
"(",
"$",
"filename",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"filename",
")",
")",
"{",
"$",
"filename",
"=",
"XmlUtils",
"::",
"getSchemaLocation",
"(",
"$",
"this",
"->",
"getVersion",
"(",
")",
")",
";",
"}",
"if",
"(",
"is_readable",
"(",
"$",
"filename",
")",
")",
"{",
"$",
"oldErrorConfig",
"=",
"libxml_use_internal_errors",
"(",
"true",
")",
";",
"$",
"doc",
"=",
"$",
"this",
"->",
"getDomDocument",
"(",
")",
";",
"if",
"(",
"@",
"$",
"doc",
"->",
"schemaValidate",
"(",
"$",
"filename",
")",
"===",
"false",
")",
"{",
"$",
"libXmlErrors",
"=",
"libxml_get_errors",
"(",
")",
";",
"$",
"formattedErrors",
"=",
"self",
"::",
"formatLibXmlErrors",
"(",
"$",
"libXmlErrors",
")",
";",
"libxml_clear_errors",
"(",
")",
";",
"libxml_use_internal_errors",
"(",
"$",
"oldErrorConfig",
")",
";",
"$",
"msg",
"=",
"\"The document could not be validated with XML Schema:\\n${formattedErrors}\"",
";",
"throw",
"new",
"XmlStorageException",
"(",
"$",
"msg",
",",
"XmlStorageException",
"::",
"XSD_VALIDATION",
",",
"null",
",",
"new",
"LibXmlErrorCollection",
"(",
"$",
"libXmlErrors",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Schema '${filename}' cannot be read. Does this file exist? Is it readable?\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Validate the document against a schema.
@param string $filename An optional filename of a given schema the document should validate against.
@throws \qtism\data\storage\xml\XmlStorageException
@throws \InvalidArgumentException | [
"Validate",
"the",
"document",
"against",
"a",
"schema",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/XmlDocument.php#L335-L361 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/XmlDocument.php | XmlDocument.xInclude | public function xInclude($validate = false) {
if (($root = $this->getDocumentComponent()) !== null) {
$baseUri = str_replace('\\', '/', $this->getDomDocument()->documentElement->baseURI);
$pathinfo = pathinfo($baseUri);
$basePath = $pathinfo['dirname'];
$iterator = new QtiComponentIterator($root, array('include'));
foreach ($iterator as $include) {
$parent = $iterator->parent();
// Is the parent something we can deal with for replacement?
$reflection = new ReflectionClass($parent);
if ($reflection->hasMethod('getContent') === true && $parent->getContent() instanceof QtiComponentCollection) {
$href = $include->getHref();
if (Url::isRelative($href) === true) {
$href = Url::rtrim($basePath) . '/' . Url::ltrim($href);
$doc = new XmlDocument();
$doc->load($href, $validate);
$includeRoot = $doc->getDocumentComponent();
if ($includeRoot instanceof Flow) {
// Derive xml:base...
$xmlBase = Url::ltrim(str_replace($basePath, '', $href));
$xmlBasePathInfo = pathinfo($xmlBase);
if ($xmlBasePathInfo['dirname'] !== '.') {
$includeRoot->setXmlBase($xmlBasePathInfo['dirname'] . '/');
}
}
$parent->getContent()->replace($include, $includeRoot);
}
}
}
} else {
$msg = "Cannot include fragments via XInclude before loading any file.";
throw new LogicException($msg);
}
} | php | public function xInclude($validate = false) {
if (($root = $this->getDocumentComponent()) !== null) {
$baseUri = str_replace('\\', '/', $this->getDomDocument()->documentElement->baseURI);
$pathinfo = pathinfo($baseUri);
$basePath = $pathinfo['dirname'];
$iterator = new QtiComponentIterator($root, array('include'));
foreach ($iterator as $include) {
$parent = $iterator->parent();
// Is the parent something we can deal with for replacement?
$reflection = new ReflectionClass($parent);
if ($reflection->hasMethod('getContent') === true && $parent->getContent() instanceof QtiComponentCollection) {
$href = $include->getHref();
if (Url::isRelative($href) === true) {
$href = Url::rtrim($basePath) . '/' . Url::ltrim($href);
$doc = new XmlDocument();
$doc->load($href, $validate);
$includeRoot = $doc->getDocumentComponent();
if ($includeRoot instanceof Flow) {
// Derive xml:base...
$xmlBase = Url::ltrim(str_replace($basePath, '', $href));
$xmlBasePathInfo = pathinfo($xmlBase);
if ($xmlBasePathInfo['dirname'] !== '.') {
$includeRoot->setXmlBase($xmlBasePathInfo['dirname'] . '/');
}
}
$parent->getContent()->replace($include, $includeRoot);
}
}
}
} else {
$msg = "Cannot include fragments via XInclude before loading any file.";
throw new LogicException($msg);
}
} | [
"public",
"function",
"xInclude",
"(",
"$",
"validate",
"=",
"false",
")",
"{",
"if",
"(",
"(",
"$",
"root",
"=",
"$",
"this",
"->",
"getDocumentComponent",
"(",
")",
")",
"!==",
"null",
")",
"{",
"$",
"baseUri",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"this",
"->",
"getDomDocument",
"(",
")",
"->",
"documentElement",
"->",
"baseURI",
")",
";",
"$",
"pathinfo",
"=",
"pathinfo",
"(",
"$",
"baseUri",
")",
";",
"$",
"basePath",
"=",
"$",
"pathinfo",
"[",
"'dirname'",
"]",
";",
"$",
"iterator",
"=",
"new",
"QtiComponentIterator",
"(",
"$",
"root",
",",
"array",
"(",
"'include'",
")",
")",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"include",
")",
"{",
"$",
"parent",
"=",
"$",
"iterator",
"->",
"parent",
"(",
")",
";",
"// Is the parent something we can deal with for replacement?",
"$",
"reflection",
"=",
"new",
"ReflectionClass",
"(",
"$",
"parent",
")",
";",
"if",
"(",
"$",
"reflection",
"->",
"hasMethod",
"(",
"'getContent'",
")",
"===",
"true",
"&&",
"$",
"parent",
"->",
"getContent",
"(",
")",
"instanceof",
"QtiComponentCollection",
")",
"{",
"$",
"href",
"=",
"$",
"include",
"->",
"getHref",
"(",
")",
";",
"if",
"(",
"Url",
"::",
"isRelative",
"(",
"$",
"href",
")",
"===",
"true",
")",
"{",
"$",
"href",
"=",
"Url",
"::",
"rtrim",
"(",
"$",
"basePath",
")",
".",
"'/'",
".",
"Url",
"::",
"ltrim",
"(",
"$",
"href",
")",
";",
"$",
"doc",
"=",
"new",
"XmlDocument",
"(",
")",
";",
"$",
"doc",
"->",
"load",
"(",
"$",
"href",
",",
"$",
"validate",
")",
";",
"$",
"includeRoot",
"=",
"$",
"doc",
"->",
"getDocumentComponent",
"(",
")",
";",
"if",
"(",
"$",
"includeRoot",
"instanceof",
"Flow",
")",
"{",
"// Derive xml:base...",
"$",
"xmlBase",
"=",
"Url",
"::",
"ltrim",
"(",
"str_replace",
"(",
"$",
"basePath",
",",
"''",
",",
"$",
"href",
")",
")",
";",
"$",
"xmlBasePathInfo",
"=",
"pathinfo",
"(",
"$",
"xmlBase",
")",
";",
"if",
"(",
"$",
"xmlBasePathInfo",
"[",
"'dirname'",
"]",
"!==",
"'.'",
")",
"{",
"$",
"includeRoot",
"->",
"setXmlBase",
"(",
"$",
"xmlBasePathInfo",
"[",
"'dirname'",
"]",
".",
"'/'",
")",
";",
"}",
"}",
"$",
"parent",
"->",
"getContent",
"(",
")",
"->",
"replace",
"(",
"$",
"include",
",",
"$",
"includeRoot",
")",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Cannot include fragments via XInclude before loading any file.\"",
";",
"throw",
"new",
"LogicException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Resolve include components.
After the item has been loaded using the load or loadFromString method,
the include components can be resolved by calling this method. Files will
be included following the rules described by the XInclude specification.
@param boolean $validate Whether or not validate files being included. Default is false.
@throws \LogicException If the method is called prior the load or loadFromString method was called.
@throws \qtism\data\storage\xml\XmlStorageException If an error occured while parsing or validating files to be included. | [
"Resolve",
"include",
"components",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/XmlDocument.php#L374-L417 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/XmlDocument.php | XmlDocument.resolveTemplateLocation | public function resolveTemplateLocation($validate = false)
{
if (($root = $this->getDocumentComponent()) !== null) {
if ($root instanceof AssessmentItem && ($responseProcessing = $root->getResponseProcessing()) !== null && ($templateLocation = $responseProcessing->getTemplateLocation()) !== '') {
if (Url::isRelative($templateLocation) === true) {
$baseUri = str_replace('\\', '/', $this->getDomDocument()->documentElement->baseURI);
$pathinfo = pathinfo($baseUri);
$basePath = $pathinfo['dirname'];
$templateLocation = Url::rtrim($basePath) . '/' . Url::ltrim($templateLocation);
$doc = new XmlDocument();
$doc->load($templateLocation, $validate);
$newResponseProcessing = $doc->getDocumentComponent();
if ($newResponseProcessing instanceof ResponseProcessing) {
$root->setResponseProcessing($newResponseProcessing);
} else {
$msg = "The template at location '${templateLocation}' is not a document containing a QTI responseProcessing element.";
throw new XmlStorageException($msg, XmlStorageException::RESOLUTION);
}
}
}
} else {
$msg = "Cannot resolve template location before loading any file.";
throw new LogicException($msg);
}
} | php | public function resolveTemplateLocation($validate = false)
{
if (($root = $this->getDocumentComponent()) !== null) {
if ($root instanceof AssessmentItem && ($responseProcessing = $root->getResponseProcessing()) !== null && ($templateLocation = $responseProcessing->getTemplateLocation()) !== '') {
if (Url::isRelative($templateLocation) === true) {
$baseUri = str_replace('\\', '/', $this->getDomDocument()->documentElement->baseURI);
$pathinfo = pathinfo($baseUri);
$basePath = $pathinfo['dirname'];
$templateLocation = Url::rtrim($basePath) . '/' . Url::ltrim($templateLocation);
$doc = new XmlDocument();
$doc->load($templateLocation, $validate);
$newResponseProcessing = $doc->getDocumentComponent();
if ($newResponseProcessing instanceof ResponseProcessing) {
$root->setResponseProcessing($newResponseProcessing);
} else {
$msg = "The template at location '${templateLocation}' is not a document containing a QTI responseProcessing element.";
throw new XmlStorageException($msg, XmlStorageException::RESOLUTION);
}
}
}
} else {
$msg = "Cannot resolve template location before loading any file.";
throw new LogicException($msg);
}
} | [
"public",
"function",
"resolveTemplateLocation",
"(",
"$",
"validate",
"=",
"false",
")",
"{",
"if",
"(",
"(",
"$",
"root",
"=",
"$",
"this",
"->",
"getDocumentComponent",
"(",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"$",
"root",
"instanceof",
"AssessmentItem",
"&&",
"(",
"$",
"responseProcessing",
"=",
"$",
"root",
"->",
"getResponseProcessing",
"(",
")",
")",
"!==",
"null",
"&&",
"(",
"$",
"templateLocation",
"=",
"$",
"responseProcessing",
"->",
"getTemplateLocation",
"(",
")",
")",
"!==",
"''",
")",
"{",
"if",
"(",
"Url",
"::",
"isRelative",
"(",
"$",
"templateLocation",
")",
"===",
"true",
")",
"{",
"$",
"baseUri",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"this",
"->",
"getDomDocument",
"(",
")",
"->",
"documentElement",
"->",
"baseURI",
")",
";",
"$",
"pathinfo",
"=",
"pathinfo",
"(",
"$",
"baseUri",
")",
";",
"$",
"basePath",
"=",
"$",
"pathinfo",
"[",
"'dirname'",
"]",
";",
"$",
"templateLocation",
"=",
"Url",
"::",
"rtrim",
"(",
"$",
"basePath",
")",
".",
"'/'",
".",
"Url",
"::",
"ltrim",
"(",
"$",
"templateLocation",
")",
";",
"$",
"doc",
"=",
"new",
"XmlDocument",
"(",
")",
";",
"$",
"doc",
"->",
"load",
"(",
"$",
"templateLocation",
",",
"$",
"validate",
")",
";",
"$",
"newResponseProcessing",
"=",
"$",
"doc",
"->",
"getDocumentComponent",
"(",
")",
";",
"if",
"(",
"$",
"newResponseProcessing",
"instanceof",
"ResponseProcessing",
")",
"{",
"$",
"root",
"->",
"setResponseProcessing",
"(",
"$",
"newResponseProcessing",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The template at location '${templateLocation}' is not a document containing a QTI responseProcessing element.\"",
";",
"throw",
"new",
"XmlStorageException",
"(",
"$",
"msg",
",",
"XmlStorageException",
"::",
"RESOLUTION",
")",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Cannot resolve template location before loading any file.\"",
";",
"throw",
"new",
"LogicException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Resolve responseProcessing elements with template location.
If the root element of the currently loaded QTI file is an assessmentItem element,
this method will try to resolve responseProcessing fragments referenced by responseProcessing
elements having a templateLocation attribute.
@param boolean $validate Whether or not validate files being included. Default is false.
@throws \LogicException If the method is called prior the load or loadFromString method was called.
@throws \qtism\data\storage\xml\XmlStorageException If an error occured while parsing or validating files to be included. | [
"Resolve",
"responseProcessing",
"elements",
"with",
"template",
"location",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/XmlDocument.php#L430-L460 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/XmlDocument.php | XmlDocument.includeAssessmentSectionRefs | public function includeAssessmentSectionRefs($validate = false)
{
if (($root = $this->getDocumentComponent()) !== null) {
$baseUri = str_replace('\\', '/', $this->getDomDocument()->documentElement->baseURI);
$pathinfo = pathinfo($baseUri);
$basePath = $pathinfo['dirname'];
$count = count($root->getComponentsByClassName('assessmentSectionRef'));
while ($count > 0) {
$iterator = new QtiComponentIterator($root, array('assessmentSectionRef'));
foreach ($iterator as $assessmentSectionRef) {
$parent = $iterator->parent();
$href = $assessmentSectionRef->getHref();
if (Url::isRelative($href) === true) {
$href = Url::rtrim($basePath) . '/' . Url::ltrim($href);
$doc = new XmlDocument();
$doc->load($href, $validate);
$sectionRoot = $doc->getDocumentComponent();
foreach ($sectionRoot->getComponentsByClassName(array('assessmentSectionRef', 'assessmentItemRef')) as $sectionPart) {
$newBasePath = Url::ltrim(str_replace($basePath, '', $href));
$pathinfo = pathinfo($newBasePath);
$newHref = $pathinfo['dirname'] . '/' . Url::ltrim($sectionPart->getHref());
$sectionPart->setHref($newHref);
}
if ($parent instanceof TestPart) {
$collection = $parent->getAssessmentSections();
} else {
$collection = $parent->getSectionParts();
}
$collection->replace($assessmentSectionRef, $sectionRoot);
}
}
$count = count($root->getComponentsByClassName('assessmentSectionRef'));
}
} else {
$msg = "Cannot resolve assessmentSectionRefs before loading any file.";
throw new LogicException($msg);
}
} | php | public function includeAssessmentSectionRefs($validate = false)
{
if (($root = $this->getDocumentComponent()) !== null) {
$baseUri = str_replace('\\', '/', $this->getDomDocument()->documentElement->baseURI);
$pathinfo = pathinfo($baseUri);
$basePath = $pathinfo['dirname'];
$count = count($root->getComponentsByClassName('assessmentSectionRef'));
while ($count > 0) {
$iterator = new QtiComponentIterator($root, array('assessmentSectionRef'));
foreach ($iterator as $assessmentSectionRef) {
$parent = $iterator->parent();
$href = $assessmentSectionRef->getHref();
if (Url::isRelative($href) === true) {
$href = Url::rtrim($basePath) . '/' . Url::ltrim($href);
$doc = new XmlDocument();
$doc->load($href, $validate);
$sectionRoot = $doc->getDocumentComponent();
foreach ($sectionRoot->getComponentsByClassName(array('assessmentSectionRef', 'assessmentItemRef')) as $sectionPart) {
$newBasePath = Url::ltrim(str_replace($basePath, '', $href));
$pathinfo = pathinfo($newBasePath);
$newHref = $pathinfo['dirname'] . '/' . Url::ltrim($sectionPart->getHref());
$sectionPart->setHref($newHref);
}
if ($parent instanceof TestPart) {
$collection = $parent->getAssessmentSections();
} else {
$collection = $parent->getSectionParts();
}
$collection->replace($assessmentSectionRef, $sectionRoot);
}
}
$count = count($root->getComponentsByClassName('assessmentSectionRef'));
}
} else {
$msg = "Cannot resolve assessmentSectionRefs before loading any file.";
throw new LogicException($msg);
}
} | [
"public",
"function",
"includeAssessmentSectionRefs",
"(",
"$",
"validate",
"=",
"false",
")",
"{",
"if",
"(",
"(",
"$",
"root",
"=",
"$",
"this",
"->",
"getDocumentComponent",
"(",
")",
")",
"!==",
"null",
")",
"{",
"$",
"baseUri",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"this",
"->",
"getDomDocument",
"(",
")",
"->",
"documentElement",
"->",
"baseURI",
")",
";",
"$",
"pathinfo",
"=",
"pathinfo",
"(",
"$",
"baseUri",
")",
";",
"$",
"basePath",
"=",
"$",
"pathinfo",
"[",
"'dirname'",
"]",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"root",
"->",
"getComponentsByClassName",
"(",
"'assessmentSectionRef'",
")",
")",
";",
"while",
"(",
"$",
"count",
">",
"0",
")",
"{",
"$",
"iterator",
"=",
"new",
"QtiComponentIterator",
"(",
"$",
"root",
",",
"array",
"(",
"'assessmentSectionRef'",
")",
")",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"assessmentSectionRef",
")",
"{",
"$",
"parent",
"=",
"$",
"iterator",
"->",
"parent",
"(",
")",
";",
"$",
"href",
"=",
"$",
"assessmentSectionRef",
"->",
"getHref",
"(",
")",
";",
"if",
"(",
"Url",
"::",
"isRelative",
"(",
"$",
"href",
")",
"===",
"true",
")",
"{",
"$",
"href",
"=",
"Url",
"::",
"rtrim",
"(",
"$",
"basePath",
")",
".",
"'/'",
".",
"Url",
"::",
"ltrim",
"(",
"$",
"href",
")",
";",
"$",
"doc",
"=",
"new",
"XmlDocument",
"(",
")",
";",
"$",
"doc",
"->",
"load",
"(",
"$",
"href",
",",
"$",
"validate",
")",
";",
"$",
"sectionRoot",
"=",
"$",
"doc",
"->",
"getDocumentComponent",
"(",
")",
";",
"foreach",
"(",
"$",
"sectionRoot",
"->",
"getComponentsByClassName",
"(",
"array",
"(",
"'assessmentSectionRef'",
",",
"'assessmentItemRef'",
")",
")",
"as",
"$",
"sectionPart",
")",
"{",
"$",
"newBasePath",
"=",
"Url",
"::",
"ltrim",
"(",
"str_replace",
"(",
"$",
"basePath",
",",
"''",
",",
"$",
"href",
")",
")",
";",
"$",
"pathinfo",
"=",
"pathinfo",
"(",
"$",
"newBasePath",
")",
";",
"$",
"newHref",
"=",
"$",
"pathinfo",
"[",
"'dirname'",
"]",
".",
"'/'",
".",
"Url",
"::",
"ltrim",
"(",
"$",
"sectionPart",
"->",
"getHref",
"(",
")",
")",
";",
"$",
"sectionPart",
"->",
"setHref",
"(",
"$",
"newHref",
")",
";",
"}",
"if",
"(",
"$",
"parent",
"instanceof",
"TestPart",
")",
"{",
"$",
"collection",
"=",
"$",
"parent",
"->",
"getAssessmentSections",
"(",
")",
";",
"}",
"else",
"{",
"$",
"collection",
"=",
"$",
"parent",
"->",
"getSectionParts",
"(",
")",
";",
"}",
"$",
"collection",
"->",
"replace",
"(",
"$",
"assessmentSectionRef",
",",
"$",
"sectionRoot",
")",
";",
"}",
"}",
"$",
"count",
"=",
"count",
"(",
"$",
"root",
"->",
"getComponentsByClassName",
"(",
"'assessmentSectionRef'",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Cannot resolve assessmentSectionRefs before loading any file.\"",
";",
"throw",
"new",
"LogicException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Include assessmentSectionRefs component in the current document.
This method includes the assessmentSectionRefs components in the current document. The references
to assessmentSections are resolved. assessmentSectionRefs will be replaced with their assessmentSection
content.
@param boolean $validate (optional) Whether or not validate the content of included assessmentSectionRefs.
@throws \LogicException If the method is called prior the load or loadFromString method was called.
@throws \qtism\data\storage\xml\XmlStorageException If an error occured while parsing or validating files to be included. | [
"Include",
"assessmentSectionRefs",
"component",
"in",
"the",
"current",
"document",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/XmlDocument.php#L473-L518 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/XmlDocument.php | XmlDocument.decorateRootElement | protected function decorateRootElement(DOMElement $rootElement)
{
$xsdLocation = 'http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1.xsd';
$xmlns = "http://www.imsglobal.org/xsd/imsqti_v2p1";
switch (trim($this->getVersion())) {
case '2.0.0':
$xsdLocation = 'http://www.imsglobal.org/xsd/imsqti_v2p0.xsd';
$xmlns = "http://www.imsglobal.org/xsd/imsqti_v2p0";
break;
case '2.1.1':
$xsdLocation = 'http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1p1.xsd';
$xmlns = "http://www.imsglobal.org/xsd/imsqti_v2p1";
break;
case '2.2.0':
$xsdLocation = 'http://www.imsglobal.org/xsd/qti/qtiv2p2/imsqti_v2p2.xsd';
$xmlns = "http://www.imsglobal.org/xsd/imsqti_v2p2";
break;
case '2.2.1':
$xsdLocation = 'http://www.imsglobal.org/xsd/qti/qtiv2p2/imsqti_v2p2p1.xsd';
$xmlns = "http://www.imsglobal.org/xsd/imsqti_v2p2";
break;
case '3.0.0':
$xsdLocation = 'http://www.imsglobal.org/xsd/qti/aqtiv1p0/imsaqti_itemv1p0_v1p0.xsd';
$xmlns = "http://www.imsglobal.org/xsd/imsaqti_item_v1p0";
break;
}
$rootElement->setAttribute('xmlns', $xmlns);
$rootElement->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$rootElement->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation', "${xmlns} ${xsdLocation}");
} | php | protected function decorateRootElement(DOMElement $rootElement)
{
$xsdLocation = 'http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1.xsd';
$xmlns = "http://www.imsglobal.org/xsd/imsqti_v2p1";
switch (trim($this->getVersion())) {
case '2.0.0':
$xsdLocation = 'http://www.imsglobal.org/xsd/imsqti_v2p0.xsd';
$xmlns = "http://www.imsglobal.org/xsd/imsqti_v2p0";
break;
case '2.1.1':
$xsdLocation = 'http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1p1.xsd';
$xmlns = "http://www.imsglobal.org/xsd/imsqti_v2p1";
break;
case '2.2.0':
$xsdLocation = 'http://www.imsglobal.org/xsd/qti/qtiv2p2/imsqti_v2p2.xsd';
$xmlns = "http://www.imsglobal.org/xsd/imsqti_v2p2";
break;
case '2.2.1':
$xsdLocation = 'http://www.imsglobal.org/xsd/qti/qtiv2p2/imsqti_v2p2p1.xsd';
$xmlns = "http://www.imsglobal.org/xsd/imsqti_v2p2";
break;
case '3.0.0':
$xsdLocation = 'http://www.imsglobal.org/xsd/qti/aqtiv1p0/imsaqti_itemv1p0_v1p0.xsd';
$xmlns = "http://www.imsglobal.org/xsd/imsaqti_item_v1p0";
break;
}
$rootElement->setAttribute('xmlns', $xmlns);
$rootElement->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$rootElement->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation', "${xmlns} ${xsdLocation}");
} | [
"protected",
"function",
"decorateRootElement",
"(",
"DOMElement",
"$",
"rootElement",
")",
"{",
"$",
"xsdLocation",
"=",
"'http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1.xsd'",
";",
"$",
"xmlns",
"=",
"\"http://www.imsglobal.org/xsd/imsqti_v2p1\"",
";",
"switch",
"(",
"trim",
"(",
"$",
"this",
"->",
"getVersion",
"(",
")",
")",
")",
"{",
"case",
"'2.0.0'",
":",
"$",
"xsdLocation",
"=",
"'http://www.imsglobal.org/xsd/imsqti_v2p0.xsd'",
";",
"$",
"xmlns",
"=",
"\"http://www.imsglobal.org/xsd/imsqti_v2p0\"",
";",
"break",
";",
"case",
"'2.1.1'",
":",
"$",
"xsdLocation",
"=",
"'http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1p1.xsd'",
";",
"$",
"xmlns",
"=",
"\"http://www.imsglobal.org/xsd/imsqti_v2p1\"",
";",
"break",
";",
"case",
"'2.2.0'",
":",
"$",
"xsdLocation",
"=",
"'http://www.imsglobal.org/xsd/qti/qtiv2p2/imsqti_v2p2.xsd'",
";",
"$",
"xmlns",
"=",
"\"http://www.imsglobal.org/xsd/imsqti_v2p2\"",
";",
"break",
";",
"case",
"'2.2.1'",
":",
"$",
"xsdLocation",
"=",
"'http://www.imsglobal.org/xsd/qti/qtiv2p2/imsqti_v2p2p1.xsd'",
";",
"$",
"xmlns",
"=",
"\"http://www.imsglobal.org/xsd/imsqti_v2p2\"",
";",
"break",
";",
"case",
"'3.0.0'",
":",
"$",
"xsdLocation",
"=",
"'http://www.imsglobal.org/xsd/qti/aqtiv1p0/imsaqti_itemv1p0_v1p0.xsd'",
";",
"$",
"xmlns",
"=",
"\"http://www.imsglobal.org/xsd/imsaqti_item_v1p0\"",
";",
"break",
";",
"}",
"$",
"rootElement",
"->",
"setAttribute",
"(",
"'xmlns'",
",",
"$",
"xmlns",
")",
";",
"$",
"rootElement",
"->",
"setAttributeNS",
"(",
"'http://www.w3.org/2000/xmlns/'",
",",
"'xmlns:xsi'",
",",
"'http://www.w3.org/2001/XMLSchema-instance'",
")",
";",
"$",
"rootElement",
"->",
"setAttributeNS",
"(",
"'http://www.w3.org/2001/XMLSchema-instance'",
",",
"'xsi:schemaLocation'",
",",
"\"${xmlns} ${xsdLocation}\"",
")",
";",
"}"
] | Decorate the root element of the XmlAssessmentDocument with the appropriate
namespaces and schema definition.
@param \DOMElement $rootElement The root DOMElement object of the document to decorate. | [
"Decorate",
"the",
"root",
"element",
"of",
"the",
"XmlAssessmentDocument",
"with",
"the",
"appropriate",
"namespaces",
"and",
"schema",
"definition",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/XmlDocument.php#L526-L561 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/XmlDocument.php | XmlDocument.formatLibXmlErrors | protected static function formatLibXmlErrors(array $libXmlErrors)
{
$formattedErrors = array();
foreach ($libXmlErrors as $error) {
switch ($error->level) {
case LIBXML_ERR_WARNING:
// Since QTI 2.2, some schemas are imported multiple times.
// Xerces does not produce errors, but libxml does...
if (preg_match('/Skipping import of schema located/ui', $error->message) === 0) {
$formattedErrors[] = "Warning: " . trim($error->message) . " at " . $error->line . ":" . $error->column . ".";
}
break;
case LIBXML_ERR_ERROR:
$formattedErrors[] = "Error: " . trim($error->message) . " at " . $error->line . ":" . $error->column . ".";
break;
case LIBXML_ERR_FATAL:
$formattedErrors[] = "Fatal Error: " . trim($error->message) . " at " . $error->line . ":" . $error->column . ".";
break;
}
}
$formattedErrors = implode("\n", $formattedErrors);
return $formattedErrors;
} | php | protected static function formatLibXmlErrors(array $libXmlErrors)
{
$formattedErrors = array();
foreach ($libXmlErrors as $error) {
switch ($error->level) {
case LIBXML_ERR_WARNING:
// Since QTI 2.2, some schemas are imported multiple times.
// Xerces does not produce errors, but libxml does...
if (preg_match('/Skipping import of schema located/ui', $error->message) === 0) {
$formattedErrors[] = "Warning: " . trim($error->message) . " at " . $error->line . ":" . $error->column . ".";
}
break;
case LIBXML_ERR_ERROR:
$formattedErrors[] = "Error: " . trim($error->message) . " at " . $error->line . ":" . $error->column . ".";
break;
case LIBXML_ERR_FATAL:
$formattedErrors[] = "Fatal Error: " . trim($error->message) . " at " . $error->line . ":" . $error->column . ".";
break;
}
}
$formattedErrors = implode("\n", $formattedErrors);
return $formattedErrors;
} | [
"protected",
"static",
"function",
"formatLibXmlErrors",
"(",
"array",
"$",
"libXmlErrors",
")",
"{",
"$",
"formattedErrors",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"libXmlErrors",
"as",
"$",
"error",
")",
"{",
"switch",
"(",
"$",
"error",
"->",
"level",
")",
"{",
"case",
"LIBXML_ERR_WARNING",
":",
"// Since QTI 2.2, some schemas are imported multiple times.",
"// Xerces does not produce errors, but libxml does...",
"if",
"(",
"preg_match",
"(",
"'/Skipping import of schema located/ui'",
",",
"$",
"error",
"->",
"message",
")",
"===",
"0",
")",
"{",
"$",
"formattedErrors",
"[",
"]",
"=",
"\"Warning: \"",
".",
"trim",
"(",
"$",
"error",
"->",
"message",
")",
".",
"\" at \"",
".",
"$",
"error",
"->",
"line",
".",
"\":\"",
".",
"$",
"error",
"->",
"column",
".",
"\".\"",
";",
"}",
"break",
";",
"case",
"LIBXML_ERR_ERROR",
":",
"$",
"formattedErrors",
"[",
"]",
"=",
"\"Error: \"",
".",
"trim",
"(",
"$",
"error",
"->",
"message",
")",
".",
"\" at \"",
".",
"$",
"error",
"->",
"line",
".",
"\":\"",
".",
"$",
"error",
"->",
"column",
".",
"\".\"",
";",
"break",
";",
"case",
"LIBXML_ERR_FATAL",
":",
"$",
"formattedErrors",
"[",
"]",
"=",
"\"Fatal Error: \"",
".",
"trim",
"(",
"$",
"error",
"->",
"message",
")",
".",
"\" at \"",
".",
"$",
"error",
"->",
"line",
".",
"\":\"",
".",
"$",
"error",
"->",
"column",
".",
"\".\"",
";",
"break",
";",
"}",
"}",
"$",
"formattedErrors",
"=",
"implode",
"(",
"\"\\n\"",
",",
"$",
"formattedErrors",
")",
";",
"return",
"$",
"formattedErrors",
";",
"}"
] | Format some $libXmlErrors into an array of strings instead of an array of arrays.
@param \LibXMLError[] $libXmlErrors
@return string | [
"Format",
"some",
"$libXmlErrors",
"into",
"an",
"array",
"of",
"strings",
"instead",
"of",
"an",
"array",
"of",
"arrays",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/XmlDocument.php#L569-L597 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/XmlDocument.php | XmlDocument.createMarshallerFactory | protected function createMarshallerFactory()
{
$version = $this->getVersion();
if ($version === '2.0.0') {
return new Qti20MarshallerFactory();
} elseif ($version === '2.1.0') {
return new Qti21MarshallerFactory();
} elseif ($version === '2.1.1') {
return new Qti211MarshallerFactory();
} elseif ($version === '2.2.0') {
return new Qti22MarshallerFactory();
} elseif ($version === '2.2.1') {
return new Qti221MarshallerFactory();
} elseif ($version === '3.0.0') {
return new Qti30MarshallerFactory();
} else {
$msg = "No MarshallerFactory implementation found for QTI version '${version}'.";
throw new RuntimeException($msg);
}
} | php | protected function createMarshallerFactory()
{
$version = $this->getVersion();
if ($version === '2.0.0') {
return new Qti20MarshallerFactory();
} elseif ($version === '2.1.0') {
return new Qti21MarshallerFactory();
} elseif ($version === '2.1.1') {
return new Qti211MarshallerFactory();
} elseif ($version === '2.2.0') {
return new Qti22MarshallerFactory();
} elseif ($version === '2.2.1') {
return new Qti221MarshallerFactory();
} elseif ($version === '3.0.0') {
return new Qti30MarshallerFactory();
} else {
$msg = "No MarshallerFactory implementation found for QTI version '${version}'.";
throw new RuntimeException($msg);
}
} | [
"protected",
"function",
"createMarshallerFactory",
"(",
")",
"{",
"$",
"version",
"=",
"$",
"this",
"->",
"getVersion",
"(",
")",
";",
"if",
"(",
"$",
"version",
"===",
"'2.0.0'",
")",
"{",
"return",
"new",
"Qti20MarshallerFactory",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"version",
"===",
"'2.1.0'",
")",
"{",
"return",
"new",
"Qti21MarshallerFactory",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"version",
"===",
"'2.1.1'",
")",
"{",
"return",
"new",
"Qti211MarshallerFactory",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"version",
"===",
"'2.2.0'",
")",
"{",
"return",
"new",
"Qti22MarshallerFactory",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"version",
"===",
"'2.2.1'",
")",
"{",
"return",
"new",
"Qti221MarshallerFactory",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"version",
"===",
"'3.0.0'",
")",
"{",
"return",
"new",
"Qti30MarshallerFactory",
"(",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"No MarshallerFactory implementation found for QTI version '${version}'.\"",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | MarshallerFactory factory method (see gang of four).
@return \qtism\data\storage\xml\marshalling\MarshallerFactory An appropriate MarshallerFactory object.
@throws \RuntimeException If no suitable MarshallerFactory implementation is found. | [
"MarshallerFactory",
"factory",
"method",
"(",
"see",
"gang",
"of",
"four",
")",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/XmlDocument.php#L605-L624 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/ExpressionProcessingException.php | ExpressionProcessingException.setSource | public function setSource(Processable $source)
{
if ($source instanceof ExpressionProcessor) {
parent::setSource($source);
} else {
$msg = "ExpressionProcessingException::setSource only accept ExpressionProcessor objects.";
throw new InvalidArgumentException($msg);
}
} | php | public function setSource(Processable $source)
{
if ($source instanceof ExpressionProcessor) {
parent::setSource($source);
} else {
$msg = "ExpressionProcessingException::setSource only accept ExpressionProcessor objects.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setSource",
"(",
"Processable",
"$",
"source",
")",
"{",
"if",
"(",
"$",
"source",
"instanceof",
"ExpressionProcessor",
")",
"{",
"parent",
"::",
"setSource",
"(",
"$",
"source",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"ExpressionProcessingException::setSource only accept ExpressionProcessor objects.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the source of the error.
@param \qtism\runtime\common\Processable $source The source of the error.
@throws \InvalidArgumentException If $source is not an ExpressionProcessor object. | [
"Set",
"the",
"source",
"of",
"the",
"error",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/ExpressionProcessingException.php#L44-L52 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/PatternMatchProcessor.php | PatternMatchProcessor.process | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->exclusivelySingle() === false) {
$msg = "The PatternMatch operator only accepts operands with a single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyString() === false) {
$msg = "The PatternMatch operator only accepts operands with a string baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$rawPattern = $this->getExpression()->getPattern();
$pattern = OperatorUtils::prepareXsdPatternForPcre($rawPattern);
$result = @preg_match($pattern, $operands[0]->getValue());
if ($result === 1) {
return new QtiBoolean(true);
} elseif ($result === 0) {
return new QtiBoolean(false);
} else {
$errorType = OperatorUtils::lastPregErrorMessage();
$msg = "An internal error occured while processing the regular expression '${rawPattern}': ${errorType}.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::RUNTIME_ERROR);
}
} | php | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->exclusivelySingle() === false) {
$msg = "The PatternMatch operator only accepts operands with a single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyString() === false) {
$msg = "The PatternMatch operator only accepts operands with a string baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$rawPattern = $this->getExpression()->getPattern();
$pattern = OperatorUtils::prepareXsdPatternForPcre($rawPattern);
$result = @preg_match($pattern, $operands[0]->getValue());
if ($result === 1) {
return new QtiBoolean(true);
} elseif ($result === 0) {
return new QtiBoolean(false);
} else {
$errorType = OperatorUtils::lastPregErrorMessage();
$msg = "An internal error occured while processing the regular expression '${rawPattern}': ${errorType}.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::RUNTIME_ERROR);
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"if",
"(",
"$",
"operands",
"->",
"containsNull",
"(",
")",
"===",
"true",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelySingle",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The PatternMatch operator only accepts operands with a single cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelyString",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The PatternMatch operator only accepts operands with a string baseType.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_BASETYPE",
")",
";",
"}",
"$",
"rawPattern",
"=",
"$",
"this",
"->",
"getExpression",
"(",
")",
"->",
"getPattern",
"(",
")",
";",
"$",
"pattern",
"=",
"OperatorUtils",
"::",
"prepareXsdPatternForPcre",
"(",
"$",
"rawPattern",
")",
";",
"$",
"result",
"=",
"@",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"operands",
"[",
"0",
"]",
"->",
"getValue",
"(",
")",
")",
";",
"if",
"(",
"$",
"result",
"===",
"1",
")",
"{",
"return",
"new",
"QtiBoolean",
"(",
"true",
")",
";",
"}",
"elseif",
"(",
"$",
"result",
"===",
"0",
")",
"{",
"return",
"new",
"QtiBoolean",
"(",
"false",
")",
";",
"}",
"else",
"{",
"$",
"errorType",
"=",
"OperatorUtils",
"::",
"lastPregErrorMessage",
"(",
")",
";",
"$",
"msg",
"=",
"\"An internal error occured while processing the regular expression '${rawPattern}': ${errorType}.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"RUNTIME_ERROR",
")",
";",
"}",
"}"
] | Process the PatternMatch.
@return boolean|null A single boolean with a value of true if the sub-expression matches the pattern and false if it does not. If the sub-expression is NULL, the the operator results in NULL.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException | [
"Process",
"the",
"PatternMatch",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/PatternMatchProcessor.php#L58-L89 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/CorrectProcessor.php | CorrectProcessor.process | public function process()
{
$expr = $this->getExpression();
$state = $this->getState();
$identifier= $expr->getIdentifier();
$var = $state->getVariable($identifier);
if (is_null($var)) {
return null;
} elseif ($var instanceof ResponseVariable) {
return $var->getCorrectResponse();
} else {
$msg = "The variable with identifier '${identifier}' is not a ResponseVariable object.";
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_TYPE);
}
} | php | public function process()
{
$expr = $this->getExpression();
$state = $this->getState();
$identifier= $expr->getIdentifier();
$var = $state->getVariable($identifier);
if (is_null($var)) {
return null;
} elseif ($var instanceof ResponseVariable) {
return $var->getCorrectResponse();
} else {
$msg = "The variable with identifier '${identifier}' is not a ResponseVariable object.";
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_TYPE);
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"expr",
"=",
"$",
"this",
"->",
"getExpression",
"(",
")",
";",
"$",
"state",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"$",
"identifier",
"=",
"$",
"expr",
"->",
"getIdentifier",
"(",
")",
";",
"$",
"var",
"=",
"$",
"state",
"->",
"getVariable",
"(",
"$",
"identifier",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"var",
")",
")",
"{",
"return",
"null",
";",
"}",
"elseif",
"(",
"$",
"var",
"instanceof",
"ResponseVariable",
")",
"{",
"return",
"$",
"var",
"->",
"getCorrectResponse",
"(",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The variable with identifier '${identifier}' is not a ResponseVariable object.\"",
";",
"throw",
"new",
"ExpressionProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"ExpressionProcessingException",
"::",
"WRONG_VARIABLE_TYPE",
")",
";",
"}",
"}"
] | Returns the related correstResponse as a QTI Runtime compliant value.
* If no variable can be matched, null is returned.
* If the target variable has no correctResponse, null is returned.
An ExpressionProcessingException is thrown if:
* The targeted variable is not a ResponseVariable.
@return mixed A QTI Runtime compliant value or null.
@throws \qtism\runtime\expressions\ExpressionProcessingException | [
"Returns",
"the",
"related",
"correstResponse",
"as",
"a",
"QTI",
"Runtime",
"compliant",
"value",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/CorrectProcessor.php#L59-L75 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/Choice.php | Choice.setTemplateIdentifier | public function setTemplateIdentifier($templateIdentifier)
{
if (is_string($templateIdentifier) === true && (empty($templateIdentifier) === true) || Format::isIdentifier($templateIdentifier, false) === true) {
$this->templateIdentifier = $templateIdentifier;
} else {
$msg = "The 'templateIdentifier' must be an empty string or a valid QTI identifier, '" . gettype($templateIdentifier) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setTemplateIdentifier($templateIdentifier)
{
if (is_string($templateIdentifier) === true && (empty($templateIdentifier) === true) || Format::isIdentifier($templateIdentifier, false) === true) {
$this->templateIdentifier = $templateIdentifier;
} else {
$msg = "The 'templateIdentifier' must be an empty string or a valid QTI identifier, '" . gettype($templateIdentifier) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setTemplateIdentifier",
"(",
"$",
"templateIdentifier",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"templateIdentifier",
")",
"===",
"true",
"&&",
"(",
"empty",
"(",
"$",
"templateIdentifier",
")",
"===",
"true",
")",
"||",
"Format",
"::",
"isIdentifier",
"(",
"$",
"templateIdentifier",
",",
"false",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"templateIdentifier",
"=",
"$",
"templateIdentifier",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'templateIdentifier' must be an empty string or a valid QTI identifier, '\"",
".",
"gettype",
"(",
"$",
"templateIdentifier",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the template identifier of the choice.
@param string $templateIdentifier An empty string if no identifier is provided or a QTI identifier.
@throws \InvalidArgumentException If the given $templateIdentifier is not a valid QTI identifier. | [
"Set",
"the",
"template",
"identifier",
"of",
"the",
"choice",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/Choice.php#L176-L184 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.