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.entry.php | Entry.getData | public function getData($field_id = null, $asObject = false)
{
$fieldData = isset($this->_data[$field_id])
? $this->_data[$field_id]
: array();
if (!$field_id) {
return $this->_data;
}
return ($asObject ? (object)$fieldData : $fieldData);
} | php | public function getData($field_id = null, $asObject = false)
{
$fieldData = isset($this->_data[$field_id])
? $this->_data[$field_id]
: array();
if (!$field_id) {
return $this->_data;
}
return ($asObject ? (object)$fieldData : $fieldData);
} | [
"public",
"function",
"getData",
"(",
"$",
"field_id",
"=",
"null",
",",
"$",
"asObject",
"=",
"false",
")",
"{",
"$",
"fieldData",
"=",
"isset",
"(",
"$",
"this",
"->",
"_data",
"[",
"$",
"field_id",
"]",
")",
"?",
"$",
"this",
"->",
"_data",
"[",
"$",
"field_id",
"]",
":",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"field_id",
")",
"{",
"return",
"$",
"this",
"->",
"_data",
";",
"}",
"return",
"(",
"$",
"asObject",
"?",
"(",
"object",
")",
"$",
"fieldData",
":",
"$",
"fieldData",
")",
";",
"}"
] | Accessor function to return data from this Entry for a particular
field. Optional parameter to return this data as an object instead
of an array. If a Field is not provided, an associative array of all data
assigned to this Entry will be returned.
@param integer $field_id
The ID of the Field whose data you want
@param boolean $asObject
If true, the data will be returned as an object instead of an
array. Defaults to false. Note that if a `$field_id` is not provided
the result will always be an array.
@return array|object
Depending on the value of `$asObject`, return the field's data
as either an array or an object. If no data exists, null will be
returned. | [
"Accessor",
"function",
"to",
"return",
"data",
"from",
"this",
"Entry",
"for",
"a",
"particular",
"field",
".",
"Optional",
"parameter",
"to",
"return",
"this",
"data",
"as",
"an",
"object",
"instead",
"of",
"an",
"array",
".",
"If",
"a",
"Field",
"is",
"not",
"provided",
"an",
"associative",
"array",
"of",
"all",
"data",
"assigned",
"to",
"this",
"Entry",
"will",
"be",
"returned",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.entry.php#L218-L229 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.entry.php | Entry.checkPostData | public function checkPostData($data, &$errors = null, $ignore_missing_fields = false)
{
$status = Entry::__ENTRY_OK__;
$section = SectionManager::fetch($this->get('section_id'));
$schema = $section->fetchFieldsSchema();
foreach ($schema as $info) {
$message = null;
$field = FieldManager::fetch($info['id']);
/**
* Prior to checking a field's post data.
*
* @delegate EntryPreCheckPostFieldData
* @since Symphony 2.7.0
* @param string $context
* '/backend/' resp. '/frontend/'
* @param object $section
* The section of the field
* @param object $field
* The field, passed by reference
* @param array $post_data
* All post data, passed by reference
* @param array $errors
* The errors (of fields already checked), passed by reference
*/
Symphony::ExtensionManager()->notifyMembers(
'EntryPreCheckPostFieldData',
class_exists('Administration', false) ? '/backend/' : '/frontend/',
array(
'section' => $section,
'field' => &$field,
'post_data' => &$data,
'errors' => &$errors
)
);
if ($ignore_missing_fields && !isset($data[$field->get('element_name')])) {
continue;
}
if (Field::__OK__ !== $field->checkPostFieldData((isset($data[$info['element_name']]) ? $data[$info['element_name']] : null), $message, $this->get('id'))) {
$status = Entry::__ENTRY_FIELD_ERROR__;
$errors[$info['id']] = $message;
}
}
return $status;
} | php | public function checkPostData($data, &$errors = null, $ignore_missing_fields = false)
{
$status = Entry::__ENTRY_OK__;
$section = SectionManager::fetch($this->get('section_id'));
$schema = $section->fetchFieldsSchema();
foreach ($schema as $info) {
$message = null;
$field = FieldManager::fetch($info['id']);
/**
* Prior to checking a field's post data.
*
* @delegate EntryPreCheckPostFieldData
* @since Symphony 2.7.0
* @param string $context
* '/backend/' resp. '/frontend/'
* @param object $section
* The section of the field
* @param object $field
* The field, passed by reference
* @param array $post_data
* All post data, passed by reference
* @param array $errors
* The errors (of fields already checked), passed by reference
*/
Symphony::ExtensionManager()->notifyMembers(
'EntryPreCheckPostFieldData',
class_exists('Administration', false) ? '/backend/' : '/frontend/',
array(
'section' => $section,
'field' => &$field,
'post_data' => &$data,
'errors' => &$errors
)
);
if ($ignore_missing_fields && !isset($data[$field->get('element_name')])) {
continue;
}
if (Field::__OK__ !== $field->checkPostFieldData((isset($data[$info['element_name']]) ? $data[$info['element_name']] : null), $message, $this->get('id'))) {
$status = Entry::__ENTRY_FIELD_ERROR__;
$errors[$info['id']] = $message;
}
}
return $status;
} | [
"public",
"function",
"checkPostData",
"(",
"$",
"data",
",",
"&",
"$",
"errors",
"=",
"null",
",",
"$",
"ignore_missing_fields",
"=",
"false",
")",
"{",
"$",
"status",
"=",
"Entry",
"::",
"__ENTRY_OK__",
";",
"$",
"section",
"=",
"SectionManager",
"::",
"fetch",
"(",
"$",
"this",
"->",
"get",
"(",
"'section_id'",
")",
")",
";",
"$",
"schema",
"=",
"$",
"section",
"->",
"fetchFieldsSchema",
"(",
")",
";",
"foreach",
"(",
"$",
"schema",
"as",
"$",
"info",
")",
"{",
"$",
"message",
"=",
"null",
";",
"$",
"field",
"=",
"FieldManager",
"::",
"fetch",
"(",
"$",
"info",
"[",
"'id'",
"]",
")",
";",
"/**\n * Prior to checking a field's post data.\n *\n * @delegate EntryPreCheckPostFieldData\n * @since Symphony 2.7.0\n * @param string $context\n * '/backend/' resp. '/frontend/'\n * @param object $section\n * The section of the field\n * @param object $field\n * The field, passed by reference\n * @param array $post_data\n * All post data, passed by reference\n * @param array $errors\n * The errors (of fields already checked), passed by reference\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'EntryPreCheckPostFieldData'",
",",
"class_exists",
"(",
"'Administration'",
",",
"false",
")",
"?",
"'/backend/'",
":",
"'/frontend/'",
",",
"array",
"(",
"'section'",
"=>",
"$",
"section",
",",
"'field'",
"=>",
"&",
"$",
"field",
",",
"'post_data'",
"=>",
"&",
"$",
"data",
",",
"'errors'",
"=>",
"&",
"$",
"errors",
")",
")",
";",
"if",
"(",
"$",
"ignore_missing_fields",
"&&",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"field",
"->",
"get",
"(",
"'element_name'",
")",
"]",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"Field",
"::",
"__OK__",
"!==",
"$",
"field",
"->",
"checkPostFieldData",
"(",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"info",
"[",
"'element_name'",
"]",
"]",
")",
"?",
"$",
"data",
"[",
"$",
"info",
"[",
"'element_name'",
"]",
"]",
":",
"null",
")",
",",
"$",
"message",
",",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
")",
")",
"{",
"$",
"status",
"=",
"Entry",
"::",
"__ENTRY_FIELD_ERROR__",
";",
"$",
"errors",
"[",
"$",
"info",
"[",
"'id'",
"]",
"]",
"=",
"$",
"message",
";",
"}",
"}",
"return",
"$",
"status",
";",
"}"
] | Given a array of data from a form, this function will iterate over all the fields
in this Entry's Section and call their `checkPostFieldData()` function.
@param array $data
An associative array of the data for this entry where they key is the
Field's handle for this Section and the value is the data from the form
@param null|array $errors
An array of errors, by reference. Defaults to empty* An array of errors, by reference.
Defaults to empty
@param boolean $ignore_missing_fields
This parameter allows Entries to be updated, rather than replaced. This is
useful if the input form only contains a couple of the fields for this Entry.
Defaults to false, which will check all Fields even if they are not
provided in the $data
@throws Exception
@return integer
Either `Entry::__ENTRY_OK__` or `Entry::__ENTRY_FIELD_ERROR__` | [
"Given",
"a",
"array",
"of",
"data",
"from",
"a",
"form",
"this",
"function",
"will",
"iterate",
"over",
"all",
"the",
"fields",
"in",
"this",
"Entry",
"s",
"Section",
"and",
"call",
"their",
"checkPostFieldData",
"()",
"function",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.entry.php#L250-L298 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.entry.php | Entry.findDefaultData | public function findDefaultData()
{
$section = SectionManager::fetch($this->get('section_id'));
$schema = $section->fetchFields();
foreach ($schema as $field) {
$field_id = $field->get('field_id');
if (empty($field_id) || isset($this->_data[$field_id])) {
continue;
}
$result = $field->processRawFieldData(null, $status, $message, false, $this->get('id'));
$this->setData($field_id, $result);
}
$this->set('modification_date', DateTimeObj::get('Y-m-d H:i:s'));
$this->set('modification_date_gmt', DateTimeObj::getGMT('Y-m-d H:i:s'));
if (!$this->get('creation_date')) {
$this->set('creation_date', $this->get('modification_date'));
}
if (!$this->get('creation_date_gmt')) {
$this->set('creation_date_gmt', $this->get('modification_date_gmt'));
}
if (!$this->get('author_id')) {
$this->set('author_id', 1);
}
if (!$this->get('modification_author_id')) {
$this->set('modification_author_id', $this->get('author_id'));
}
} | php | public function findDefaultData()
{
$section = SectionManager::fetch($this->get('section_id'));
$schema = $section->fetchFields();
foreach ($schema as $field) {
$field_id = $field->get('field_id');
if (empty($field_id) || isset($this->_data[$field_id])) {
continue;
}
$result = $field->processRawFieldData(null, $status, $message, false, $this->get('id'));
$this->setData($field_id, $result);
}
$this->set('modification_date', DateTimeObj::get('Y-m-d H:i:s'));
$this->set('modification_date_gmt', DateTimeObj::getGMT('Y-m-d H:i:s'));
if (!$this->get('creation_date')) {
$this->set('creation_date', $this->get('modification_date'));
}
if (!$this->get('creation_date_gmt')) {
$this->set('creation_date_gmt', $this->get('modification_date_gmt'));
}
if (!$this->get('author_id')) {
$this->set('author_id', 1);
}
if (!$this->get('modification_author_id')) {
$this->set('modification_author_id', $this->get('author_id'));
}
} | [
"public",
"function",
"findDefaultData",
"(",
")",
"{",
"$",
"section",
"=",
"SectionManager",
"::",
"fetch",
"(",
"$",
"this",
"->",
"get",
"(",
"'section_id'",
")",
")",
";",
"$",
"schema",
"=",
"$",
"section",
"->",
"fetchFields",
"(",
")",
";",
"foreach",
"(",
"$",
"schema",
"as",
"$",
"field",
")",
"{",
"$",
"field_id",
"=",
"$",
"field",
"->",
"get",
"(",
"'field_id'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"field_id",
")",
"||",
"isset",
"(",
"$",
"this",
"->",
"_data",
"[",
"$",
"field_id",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"result",
"=",
"$",
"field",
"->",
"processRawFieldData",
"(",
"null",
",",
"$",
"status",
",",
"$",
"message",
",",
"false",
",",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"$",
"this",
"->",
"setData",
"(",
"$",
"field_id",
",",
"$",
"result",
")",
";",
"}",
"$",
"this",
"->",
"set",
"(",
"'modification_date'",
",",
"DateTimeObj",
"::",
"get",
"(",
"'Y-m-d H:i:s'",
")",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'modification_date_gmt'",
",",
"DateTimeObj",
"::",
"getGMT",
"(",
"'Y-m-d H:i:s'",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"get",
"(",
"'creation_date'",
")",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"'creation_date'",
",",
"$",
"this",
"->",
"get",
"(",
"'modification_date'",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"get",
"(",
"'creation_date_gmt'",
")",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"'creation_date_gmt'",
",",
"$",
"this",
"->",
"get",
"(",
"'modification_date_gmt'",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"get",
"(",
"'author_id'",
")",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"'author_id'",
",",
"1",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"get",
"(",
"'modification_author_id'",
")",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"'modification_author_id'",
",",
"$",
"this",
"->",
"get",
"(",
"'author_id'",
")",
")",
";",
"}",
"}"
] | Iterates over all the Fields in this Entry calling their
`processRawFieldData()` function to set default values for this Entry.
@see toolkit.Field#processRawFieldData() | [
"Iterates",
"over",
"all",
"the",
"Fields",
"in",
"this",
"Entry",
"calling",
"their",
"processRawFieldData",
"()",
"function",
"to",
"set",
"default",
"values",
"for",
"this",
"Entry",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.entry.php#L306-L339 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.entry.php | Entry.commit | public function commit()
{
$this->findDefaultData();
return ($this->get('id') ? EntryManager::edit($this) : EntryManager::add($this));
} | php | public function commit()
{
$this->findDefaultData();
return ($this->get('id') ? EntryManager::edit($this) : EntryManager::add($this));
} | [
"public",
"function",
"commit",
"(",
")",
"{",
"$",
"this",
"->",
"findDefaultData",
"(",
")",
";",
"return",
"(",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
"?",
"EntryManager",
"::",
"edit",
"(",
"$",
"this",
")",
":",
"EntryManager",
"::",
"add",
"(",
"$",
"this",
")",
")",
";",
"}"
] | Commits this Entry's data to the database, by first finding the default
data for this `Entry` and then utilising the `EntryManager`'s
add or edit function. The `EntryManager::edit` function is used if
the current `Entry` object has an ID, otherwise `EntryManager::add`
is used.
@see toolkit.Entry#findDefaultData()
@throws Exception
@return boolean
true if the commit was successful, false otherwise. | [
"Commits",
"this",
"Entry",
"s",
"data",
"to",
"the",
"database",
"by",
"first",
"finding",
"the",
"default",
"data",
"for",
"this",
"Entry",
"and",
"then",
"utilising",
"the",
"EntryManager",
"s",
"add",
"or",
"edit",
"function",
".",
"The",
"EntryManager",
"::",
"edit",
"function",
"is",
"used",
"if",
"the",
"current",
"Entry",
"object",
"has",
"an",
"ID",
"otherwise",
"EntryManager",
"::",
"add",
"is",
"used",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.entry.php#L353-L358 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.entry.php | Entry.fetchAllAssociatedEntryCounts | public function fetchAllAssociatedEntryCounts($associated_sections = null)
{
if (is_null($this->get('section_id'))) {
return null;
}
if (is_null($associated_sections)) {
$section = SectionManager::fetch($this->get('section_id'));
$associated_sections = $section->fetchChildAssociations();
}
if (!is_array($associated_sections) || empty($associated_sections)) {
return null;
}
$counts = array();
foreach ($associated_sections as $as) {
$field = FieldManager::fetch($as['child_section_field_id']);
$parent_section_field_id = $as['parent_section_field_id'];
if (!is_null($parent_section_field_id)) {
$search_value = $field->fetchAssociatedEntrySearchValue(
$this->getData($as['parent_section_field_id']),
$as['parent_section_field_id'],
$this->get('id')
);
} else {
$search_value = $this->get('id');
}
$counts[$as['child_section_id']][$as['child_section_field_id']] = $field->fetchAssociatedEntryCount($search_value);
}
return $counts;
} | php | public function fetchAllAssociatedEntryCounts($associated_sections = null)
{
if (is_null($this->get('section_id'))) {
return null;
}
if (is_null($associated_sections)) {
$section = SectionManager::fetch($this->get('section_id'));
$associated_sections = $section->fetchChildAssociations();
}
if (!is_array($associated_sections) || empty($associated_sections)) {
return null;
}
$counts = array();
foreach ($associated_sections as $as) {
$field = FieldManager::fetch($as['child_section_field_id']);
$parent_section_field_id = $as['parent_section_field_id'];
if (!is_null($parent_section_field_id)) {
$search_value = $field->fetchAssociatedEntrySearchValue(
$this->getData($as['parent_section_field_id']),
$as['parent_section_field_id'],
$this->get('id')
);
} else {
$search_value = $this->get('id');
}
$counts[$as['child_section_id']][$as['child_section_field_id']] = $field->fetchAssociatedEntryCount($search_value);
}
return $counts;
} | [
"public",
"function",
"fetchAllAssociatedEntryCounts",
"(",
"$",
"associated_sections",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"get",
"(",
"'section_id'",
")",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"associated_sections",
")",
")",
"{",
"$",
"section",
"=",
"SectionManager",
"::",
"fetch",
"(",
"$",
"this",
"->",
"get",
"(",
"'section_id'",
")",
")",
";",
"$",
"associated_sections",
"=",
"$",
"section",
"->",
"fetchChildAssociations",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"associated_sections",
")",
"||",
"empty",
"(",
"$",
"associated_sections",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"counts",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"associated_sections",
"as",
"$",
"as",
")",
"{",
"$",
"field",
"=",
"FieldManager",
"::",
"fetch",
"(",
"$",
"as",
"[",
"'child_section_field_id'",
"]",
")",
";",
"$",
"parent_section_field_id",
"=",
"$",
"as",
"[",
"'parent_section_field_id'",
"]",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"parent_section_field_id",
")",
")",
"{",
"$",
"search_value",
"=",
"$",
"field",
"->",
"fetchAssociatedEntrySearchValue",
"(",
"$",
"this",
"->",
"getData",
"(",
"$",
"as",
"[",
"'parent_section_field_id'",
"]",
")",
",",
"$",
"as",
"[",
"'parent_section_field_id'",
"]",
",",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"}",
"else",
"{",
"$",
"search_value",
"=",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
";",
"}",
"$",
"counts",
"[",
"$",
"as",
"[",
"'child_section_id'",
"]",
"]",
"[",
"$",
"as",
"[",
"'child_section_field_id'",
"]",
"]",
"=",
"$",
"field",
"->",
"fetchAssociatedEntryCount",
"(",
"$",
"search_value",
")",
";",
"}",
"return",
"$",
"counts",
";",
"}"
] | Entries may link to other Entries through fields. This function will return the
number of entries that are associated with the current entry as an associative
array. If there are no associated entries, null will be returned.
@param array $associated_sections
An associative array of sections to return the Entry counts from. Defaults to
null, which will fetch all the associations of this Entry.
@throws Exception
@return array
An associative array with the key being the associated Section's ID and the
value being the number of entries associated with this Entry. | [
"Entries",
"may",
"link",
"to",
"other",
"Entries",
"through",
"fields",
".",
"This",
"function",
"will",
"return",
"the",
"number",
"of",
"entries",
"that",
"are",
"associated",
"with",
"the",
"current",
"entry",
"as",
"an",
"associative",
"array",
".",
"If",
"there",
"are",
"no",
"associated",
"entries",
"null",
"will",
"be",
"returned",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.entry.php#L373-L408 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.setFromPOST | public function setFromPOST(array $settings = array())
{
$settings['location'] = (isset($settings['location']) ? $settings['location'] : 'main');
$settings['required'] = (isset($settings['required']) && $settings['required'] === 'yes' ? 'yes' : 'no');
$settings['show_column'] = (isset($settings['show_column']) && $settings['show_column'] === 'yes' ? 'yes' : 'no');
$this->setArray($settings);
} | php | public function setFromPOST(array $settings = array())
{
$settings['location'] = (isset($settings['location']) ? $settings['location'] : 'main');
$settings['required'] = (isset($settings['required']) && $settings['required'] === 'yes' ? 'yes' : 'no');
$settings['show_column'] = (isset($settings['show_column']) && $settings['show_column'] === 'yes' ? 'yes' : 'no');
$this->setArray($settings);
} | [
"public",
"function",
"setFromPOST",
"(",
"array",
"$",
"settings",
"=",
"array",
"(",
")",
")",
"{",
"$",
"settings",
"[",
"'location'",
"]",
"=",
"(",
"isset",
"(",
"$",
"settings",
"[",
"'location'",
"]",
")",
"?",
"$",
"settings",
"[",
"'location'",
"]",
":",
"'main'",
")",
";",
"$",
"settings",
"[",
"'required'",
"]",
"=",
"(",
"isset",
"(",
"$",
"settings",
"[",
"'required'",
"]",
")",
"&&",
"$",
"settings",
"[",
"'required'",
"]",
"===",
"'yes'",
"?",
"'yes'",
":",
"'no'",
")",
";",
"$",
"settings",
"[",
"'show_column'",
"]",
"=",
"(",
"isset",
"(",
"$",
"settings",
"[",
"'show_column'",
"]",
")",
"&&",
"$",
"settings",
"[",
"'show_column'",
"]",
"===",
"'yes'",
"?",
"'yes'",
":",
"'no'",
")",
";",
"$",
"this",
"->",
"setArray",
"(",
"$",
"settings",
")",
";",
"}"
] | Fill the input data array with default values for known keys provided
these settings are not already set. The input array is then used to set
the values of the corresponding settings for this field. This function
is called when a section is saved.
@param array $settings
the data array to initialize if necessary. | [
"Fill",
"the",
"input",
"data",
"array",
"with",
"default",
"values",
"for",
"known",
"keys",
"provided",
"these",
"settings",
"are",
"not",
"already",
"set",
".",
"The",
"input",
"array",
"is",
"then",
"used",
"to",
"set",
"the",
"values",
"of",
"the",
"corresponding",
"settings",
"for",
"this",
"field",
".",
"This",
"function",
"is",
"called",
"when",
"a",
"section",
"is",
"saved",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L394-L401 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.get | public function get($setting = null)
{
if (is_null($setting)) {
return $this->_settings;
}
if (!isset($this->_settings[$setting])) {
return null;
}
return $this->_settings[$setting];
} | php | public function get($setting = null)
{
if (is_null($setting)) {
return $this->_settings;
}
if (!isset($this->_settings[$setting])) {
return null;
}
return $this->_settings[$setting];
} | [
"public",
"function",
"get",
"(",
"$",
"setting",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"setting",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_settings",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_settings",
"[",
"$",
"setting",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"_settings",
"[",
"$",
"setting",
"]",
";",
"}"
] | Accessor to the a setting by name. If no setting is provided all the
settings of this `Field` instance are returned.
@param string $setting (optional)
the name of the setting to access the value for. This is optional and
defaults to null in which case all settings are returned.
@return null|mixed|array
the value of the setting if there is one, all settings if the input setting
was omitted or null if the setting was supplied but there is no value
for that setting. | [
"Accessor",
"to",
"the",
"a",
"setting",
"by",
"name",
".",
"If",
"no",
"setting",
"is",
"provided",
"all",
"the",
"settings",
"of",
"this",
"Field",
"instance",
"are",
"returned",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L415-L426 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.displaySettingsPanel | public function displaySettingsPanel(XMLElement &$wrapper, $errors = null)
{
// Create header
$location = ($this->get('location') ? $this->get('location') : 'main');
$header = new XMLElement('header', null, array(
'class' => 'frame-header ' . $location,
'data-name' => $this->name(),
'title' => $this->get('id'),
));
$label = (($this->get('label')) ? $this->get('label') : __('New Field'));
$header->appendChild(new XMLElement('h4', '<strong>' . $label . '</strong> <span class="type">' . $this->name() . '</span>'));
$wrapper->appendChild($header);
// Create content
$wrapper->appendChild(Widget::Input('fields['.$this->get('sortorder').'][type]', $this->handle(), 'hidden'));
if ($this->get('id')) {
$wrapper->appendChild(Widget::Input('fields['.$this->get('sortorder').'][id]', $this->get('id'), 'hidden'));
}
$wrapper->appendChild($this->buildSummaryBlock($errors));
} | php | public function displaySettingsPanel(XMLElement &$wrapper, $errors = null)
{
// Create header
$location = ($this->get('location') ? $this->get('location') : 'main');
$header = new XMLElement('header', null, array(
'class' => 'frame-header ' . $location,
'data-name' => $this->name(),
'title' => $this->get('id'),
));
$label = (($this->get('label')) ? $this->get('label') : __('New Field'));
$header->appendChild(new XMLElement('h4', '<strong>' . $label . '</strong> <span class="type">' . $this->name() . '</span>'));
$wrapper->appendChild($header);
// Create content
$wrapper->appendChild(Widget::Input('fields['.$this->get('sortorder').'][type]', $this->handle(), 'hidden'));
if ($this->get('id')) {
$wrapper->appendChild(Widget::Input('fields['.$this->get('sortorder').'][id]', $this->get('id'), 'hidden'));
}
$wrapper->appendChild($this->buildSummaryBlock($errors));
} | [
"public",
"function",
"displaySettingsPanel",
"(",
"XMLElement",
"&",
"$",
"wrapper",
",",
"$",
"errors",
"=",
"null",
")",
"{",
"// Create header",
"$",
"location",
"=",
"(",
"$",
"this",
"->",
"get",
"(",
"'location'",
")",
"?",
"$",
"this",
"->",
"get",
"(",
"'location'",
")",
":",
"'main'",
")",
";",
"$",
"header",
"=",
"new",
"XMLElement",
"(",
"'header'",
",",
"null",
",",
"array",
"(",
"'class'",
"=>",
"'frame-header '",
".",
"$",
"location",
",",
"'data-name'",
"=>",
"$",
"this",
"->",
"name",
"(",
")",
",",
"'title'",
"=>",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
",",
")",
")",
";",
"$",
"label",
"=",
"(",
"(",
"$",
"this",
"->",
"get",
"(",
"'label'",
")",
")",
"?",
"$",
"this",
"->",
"get",
"(",
"'label'",
")",
":",
"__",
"(",
"'New Field'",
")",
")",
";",
"$",
"header",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'h4'",
",",
"'<strong>'",
".",
"$",
"label",
".",
"'</strong> <span class=\"type\">'",
".",
"$",
"this",
"->",
"name",
"(",
")",
".",
"'</span>'",
")",
")",
";",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"header",
")",
";",
"// Create content",
"$",
"wrapper",
"->",
"appendChild",
"(",
"Widget",
"::",
"Input",
"(",
"'fields['",
".",
"$",
"this",
"->",
"get",
"(",
"'sortorder'",
")",
".",
"'][type]'",
",",
"$",
"this",
"->",
"handle",
"(",
")",
",",
"'hidden'",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
")",
"{",
"$",
"wrapper",
"->",
"appendChild",
"(",
"Widget",
"::",
"Input",
"(",
"'fields['",
".",
"$",
"this",
"->",
"get",
"(",
"'sortorder'",
")",
".",
"'][id]'",
",",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
",",
"'hidden'",
")",
")",
";",
"}",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"buildSummaryBlock",
"(",
"$",
"errors",
")",
")",
";",
"}"
] | Display the default settings panel, calls the `buildSummaryBlock`
function after basic field settings are added to the wrapper.
@see buildSummaryBlock()
@param XMLElement $wrapper
the input XMLElement to which the display of this will be appended.
@param mixed $errors
the input error collection. this defaults to null.
@throws InvalidArgumentException | [
"Display",
"the",
"default",
"settings",
"panel",
"calls",
"the",
"buildSummaryBlock",
"function",
"after",
"basic",
"field",
"settings",
"are",
"added",
"to",
"the",
"wrapper",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L474-L495 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.buildSummaryBlock | public function buildSummaryBlock($errors = null)
{
$div = new XMLElement('div');
// Publish label
$label = Widget::Label(__('Label'));
$label->appendChild(
Widget::Input('fields['.$this->get('sortorder').'][label]', $this->get('label'))
);
if (isset($errors['label'])) {
$div->appendChild(Widget::Error($label, $errors['label']));
} else {
$div->appendChild($label);
}
// Handle + placement
$group = new XMLElement('div');
$group->setAttribute('class', 'two columns');
$label = Widget::Label(__('Handle'));
$label->setAttribute('class', 'column');
$label->appendChild(Widget::Input('fields['.$this->get('sortorder').'][element_name]', $this->get('element_name')));
if (isset($errors['element_name'])) {
$group->appendChild(Widget::Error($label, $errors['element_name']));
} else {
$group->appendChild($label);
}
// Location
$group->appendChild($this->buildLocationSelect($this->get('location'), 'fields['.$this->get('sortorder').'][location]'));
$div->appendChild($group);
return $div;
} | php | public function buildSummaryBlock($errors = null)
{
$div = new XMLElement('div');
// Publish label
$label = Widget::Label(__('Label'));
$label->appendChild(
Widget::Input('fields['.$this->get('sortorder').'][label]', $this->get('label'))
);
if (isset($errors['label'])) {
$div->appendChild(Widget::Error($label, $errors['label']));
} else {
$div->appendChild($label);
}
// Handle + placement
$group = new XMLElement('div');
$group->setAttribute('class', 'two columns');
$label = Widget::Label(__('Handle'));
$label->setAttribute('class', 'column');
$label->appendChild(Widget::Input('fields['.$this->get('sortorder').'][element_name]', $this->get('element_name')));
if (isset($errors['element_name'])) {
$group->appendChild(Widget::Error($label, $errors['element_name']));
} else {
$group->appendChild($label);
}
// Location
$group->appendChild($this->buildLocationSelect($this->get('location'), 'fields['.$this->get('sortorder').'][location]'));
$div->appendChild($group);
return $div;
} | [
"public",
"function",
"buildSummaryBlock",
"(",
"$",
"errors",
"=",
"null",
")",
"{",
"$",
"div",
"=",
"new",
"XMLElement",
"(",
"'div'",
")",
";",
"// Publish label",
"$",
"label",
"=",
"Widget",
"::",
"Label",
"(",
"__",
"(",
"'Label'",
")",
")",
";",
"$",
"label",
"->",
"appendChild",
"(",
"Widget",
"::",
"Input",
"(",
"'fields['",
".",
"$",
"this",
"->",
"get",
"(",
"'sortorder'",
")",
".",
"'][label]'",
",",
"$",
"this",
"->",
"get",
"(",
"'label'",
")",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"errors",
"[",
"'label'",
"]",
")",
")",
"{",
"$",
"div",
"->",
"appendChild",
"(",
"Widget",
"::",
"Error",
"(",
"$",
"label",
",",
"$",
"errors",
"[",
"'label'",
"]",
")",
")",
";",
"}",
"else",
"{",
"$",
"div",
"->",
"appendChild",
"(",
"$",
"label",
")",
";",
"}",
"// Handle + placement",
"$",
"group",
"=",
"new",
"XMLElement",
"(",
"'div'",
")",
";",
"$",
"group",
"->",
"setAttribute",
"(",
"'class'",
",",
"'two columns'",
")",
";",
"$",
"label",
"=",
"Widget",
"::",
"Label",
"(",
"__",
"(",
"'Handle'",
")",
")",
";",
"$",
"label",
"->",
"setAttribute",
"(",
"'class'",
",",
"'column'",
")",
";",
"$",
"label",
"->",
"appendChild",
"(",
"Widget",
"::",
"Input",
"(",
"'fields['",
".",
"$",
"this",
"->",
"get",
"(",
"'sortorder'",
")",
".",
"'][element_name]'",
",",
"$",
"this",
"->",
"get",
"(",
"'element_name'",
")",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"errors",
"[",
"'element_name'",
"]",
")",
")",
"{",
"$",
"group",
"->",
"appendChild",
"(",
"Widget",
"::",
"Error",
"(",
"$",
"label",
",",
"$",
"errors",
"[",
"'element_name'",
"]",
")",
")",
";",
"}",
"else",
"{",
"$",
"group",
"->",
"appendChild",
"(",
"$",
"label",
")",
";",
"}",
"// Location",
"$",
"group",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"buildLocationSelect",
"(",
"$",
"this",
"->",
"get",
"(",
"'location'",
")",
",",
"'fields['",
".",
"$",
"this",
"->",
"get",
"(",
"'sortorder'",
")",
".",
"'][location]'",
")",
")",
";",
"$",
"div",
"->",
"appendChild",
"(",
"$",
"group",
")",
";",
"return",
"$",
"div",
";",
"}"
] | Construct the html block to display a summary of this field, which is the field
Label and it's location within the section. Any error messages generated are
appended to the optional input error array. This function calls
`buildLocationSelect` once it is completed
@see buildLocationSelect()
@param array $errors (optional)
an array to append html formatted error messages to. this defaults to null.
@throws InvalidArgumentException
@return XMLElement
the root XML element of the html display of this. | [
"Construct",
"the",
"html",
"block",
"to",
"display",
"a",
"summary",
"of",
"this",
"field",
"which",
"is",
"the",
"field",
"Label",
"and",
"it",
"s",
"location",
"within",
"the",
"section",
".",
"Any",
"error",
"messages",
"generated",
"are",
"appended",
"to",
"the",
"optional",
"input",
"error",
"array",
".",
"This",
"function",
"calls",
"buildLocationSelect",
"once",
"it",
"is",
"completed"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L510-L546 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.buildLocationSelect | public function buildLocationSelect($selected = null, $name = 'fields[location]', $label_value = null)
{
if (!$label_value) {
$label_value = __('Placement');
}
$label = Widget::Label($label_value);
$label->setAttribute('class', 'column');
$options = array(
array('main', $selected == 'main', __('Main content')),
array('sidebar', $selected == 'sidebar', __('Sidebar'))
);
$label->appendChild(Widget::Select($name, $options));
return $label;
} | php | public function buildLocationSelect($selected = null, $name = 'fields[location]', $label_value = null)
{
if (!$label_value) {
$label_value = __('Placement');
}
$label = Widget::Label($label_value);
$label->setAttribute('class', 'column');
$options = array(
array('main', $selected == 'main', __('Main content')),
array('sidebar', $selected == 'sidebar', __('Sidebar'))
);
$label->appendChild(Widget::Select($name, $options));
return $label;
} | [
"public",
"function",
"buildLocationSelect",
"(",
"$",
"selected",
"=",
"null",
",",
"$",
"name",
"=",
"'fields[location]'",
",",
"$",
"label_value",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"label_value",
")",
"{",
"$",
"label_value",
"=",
"__",
"(",
"'Placement'",
")",
";",
"}",
"$",
"label",
"=",
"Widget",
"::",
"Label",
"(",
"$",
"label_value",
")",
";",
"$",
"label",
"->",
"setAttribute",
"(",
"'class'",
",",
"'column'",
")",
";",
"$",
"options",
"=",
"array",
"(",
"array",
"(",
"'main'",
",",
"$",
"selected",
"==",
"'main'",
",",
"__",
"(",
"'Main content'",
")",
")",
",",
"array",
"(",
"'sidebar'",
",",
"$",
"selected",
"==",
"'sidebar'",
",",
"__",
"(",
"'Sidebar'",
")",
")",
")",
";",
"$",
"label",
"->",
"appendChild",
"(",
"Widget",
"::",
"Select",
"(",
"$",
"name",
",",
"$",
"options",
")",
")",
";",
"return",
"$",
"label",
";",
"}"
] | Build the location select widget. This widget allows users to select
whether this field will appear in the main content column or in the sidebar
when creating a new entry.
@param string|null $selected (optional)
the currently selected location, if there is one. this defaults to null.
@param string $name (optional)
the name of this field. this is optional and defaults to `fields[location]`.
@param string $label_value (optional)
any predefined label for this widget. this is an optional argument that defaults
to null.
@throws InvalidArgumentException
@return XMLElement
An XMLElement representing a `<select>` field containing the options. | [
"Build",
"the",
"location",
"select",
"widget",
".",
"This",
"widget",
"allows",
"users",
"to",
"select",
"whether",
"this",
"field",
"will",
"appear",
"in",
"the",
"main",
"content",
"column",
"or",
"in",
"the",
"sidebar",
"when",
"creating",
"a",
"new",
"entry",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L564-L580 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.buildFormatterSelect | public function buildFormatterSelect($selected = null, $name = 'fields[format]', $label_value)
{
$formatters = TextformatterManager::listAll();
if (!$label_value) {
$label_value = __('Formatting');
}
$label = Widget::Label($label_value);
$label->setAttribute('class', 'column');
$options = array();
$options[] = array('none', false, __('None'));
if (!empty($formatters) && is_array($formatters)) {
foreach ($formatters as $handle => $about) {
$options[] = array($handle, ($selected == $handle), $about['name']);
}
}
$label->appendChild(Widget::Select($name, $options));
return $label;
} | php | public function buildFormatterSelect($selected = null, $name = 'fields[format]', $label_value)
{
$formatters = TextformatterManager::listAll();
if (!$label_value) {
$label_value = __('Formatting');
}
$label = Widget::Label($label_value);
$label->setAttribute('class', 'column');
$options = array();
$options[] = array('none', false, __('None'));
if (!empty($formatters) && is_array($formatters)) {
foreach ($formatters as $handle => $about) {
$options[] = array($handle, ($selected == $handle), $about['name']);
}
}
$label->appendChild(Widget::Select($name, $options));
return $label;
} | [
"public",
"function",
"buildFormatterSelect",
"(",
"$",
"selected",
"=",
"null",
",",
"$",
"name",
"=",
"'fields[format]'",
",",
"$",
"label_value",
")",
"{",
"$",
"formatters",
"=",
"TextformatterManager",
"::",
"listAll",
"(",
")",
";",
"if",
"(",
"!",
"$",
"label_value",
")",
"{",
"$",
"label_value",
"=",
"__",
"(",
"'Formatting'",
")",
";",
"}",
"$",
"label",
"=",
"Widget",
"::",
"Label",
"(",
"$",
"label_value",
")",
";",
"$",
"label",
"->",
"setAttribute",
"(",
"'class'",
",",
"'column'",
")",
";",
"$",
"options",
"=",
"array",
"(",
")",
";",
"$",
"options",
"[",
"]",
"=",
"array",
"(",
"'none'",
",",
"false",
",",
"__",
"(",
"'None'",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"formatters",
")",
"&&",
"is_array",
"(",
"$",
"formatters",
")",
")",
"{",
"foreach",
"(",
"$",
"formatters",
"as",
"$",
"handle",
"=>",
"$",
"about",
")",
"{",
"$",
"options",
"[",
"]",
"=",
"array",
"(",
"$",
"handle",
",",
"(",
"$",
"selected",
"==",
"$",
"handle",
")",
",",
"$",
"about",
"[",
"'name'",
"]",
")",
";",
"}",
"}",
"$",
"label",
"->",
"appendChild",
"(",
"Widget",
"::",
"Select",
"(",
"$",
"name",
",",
"$",
"options",
")",
")",
";",
"return",
"$",
"label",
";",
"}"
] | Construct the html widget for selecting a text formatter for this field.
@param string $selected (optional)
the currently selected text formatter name if there is one. this defaults
to null.
@param string $name (optional)
the name of this field in the form. this is optional and defaults to
"fields[format]".
@param string $label_value
the default label for the widget to construct. if null is passed in then
this defaults to the localization of "Formatting".
@throws InvalidArgumentException
@return XMLElement
An XMLElement representing a `<select>` field containing the options. | [
"Construct",
"the",
"html",
"widget",
"for",
"selecting",
"a",
"text",
"formatter",
"for",
"this",
"field",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L598-L622 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.buildValidationSelect | public function buildValidationSelect(XMLElement &$wrapper, $selected = null, $name = 'fields[validator]', $type = 'input', array $errors = null)
{
include TOOLKIT . '/util.validators.php';
$rules = ($type == 'upload' ? $upload : $validators);
$label = Widget::Label(__('Validation Rule'));
$label->setAttribute('class', 'column');
$label->appendChild(new XMLElement('i', __('Optional')));
$label->appendChild(Widget::Input($name, $selected));
$ul = new XMLElement('ul', null, array('class' => 'tags singular', 'data-interactive' => 'data-interactive'));
foreach ($rules as $name => $rule) {
$ul->appendChild(new XMLElement('li', $name, array('class' => $rule)));
}
if (isset($errors['validator'])) {
$div = new XMLElement('div');
$div->appendChild($label);
$div->appendChild($ul);
$wrapper->appendChild(Widget::Error($div, $errors['validator']));
} else {
$wrapper->appendChild($label);
$wrapper->appendChild($ul);
}
} | php | public function buildValidationSelect(XMLElement &$wrapper, $selected = null, $name = 'fields[validator]', $type = 'input', array $errors = null)
{
include TOOLKIT . '/util.validators.php';
$rules = ($type == 'upload' ? $upload : $validators);
$label = Widget::Label(__('Validation Rule'));
$label->setAttribute('class', 'column');
$label->appendChild(new XMLElement('i', __('Optional')));
$label->appendChild(Widget::Input($name, $selected));
$ul = new XMLElement('ul', null, array('class' => 'tags singular', 'data-interactive' => 'data-interactive'));
foreach ($rules as $name => $rule) {
$ul->appendChild(new XMLElement('li', $name, array('class' => $rule)));
}
if (isset($errors['validator'])) {
$div = new XMLElement('div');
$div->appendChild($label);
$div->appendChild($ul);
$wrapper->appendChild(Widget::Error($div, $errors['validator']));
} else {
$wrapper->appendChild($label);
$wrapper->appendChild($ul);
}
} | [
"public",
"function",
"buildValidationSelect",
"(",
"XMLElement",
"&",
"$",
"wrapper",
",",
"$",
"selected",
"=",
"null",
",",
"$",
"name",
"=",
"'fields[validator]'",
",",
"$",
"type",
"=",
"'input'",
",",
"array",
"$",
"errors",
"=",
"null",
")",
"{",
"include",
"TOOLKIT",
".",
"'/util.validators.php'",
";",
"$",
"rules",
"=",
"(",
"$",
"type",
"==",
"'upload'",
"?",
"$",
"upload",
":",
"$",
"validators",
")",
";",
"$",
"label",
"=",
"Widget",
"::",
"Label",
"(",
"__",
"(",
"'Validation Rule'",
")",
")",
";",
"$",
"label",
"->",
"setAttribute",
"(",
"'class'",
",",
"'column'",
")",
";",
"$",
"label",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'i'",
",",
"__",
"(",
"'Optional'",
")",
")",
")",
";",
"$",
"label",
"->",
"appendChild",
"(",
"Widget",
"::",
"Input",
"(",
"$",
"name",
",",
"$",
"selected",
")",
")",
";",
"$",
"ul",
"=",
"new",
"XMLElement",
"(",
"'ul'",
",",
"null",
",",
"array",
"(",
"'class'",
"=>",
"'tags singular'",
",",
"'data-interactive'",
"=>",
"'data-interactive'",
")",
")",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"name",
"=>",
"$",
"rule",
")",
"{",
"$",
"ul",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'li'",
",",
"$",
"name",
",",
"array",
"(",
"'class'",
"=>",
"$",
"rule",
")",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"errors",
"[",
"'validator'",
"]",
")",
")",
"{",
"$",
"div",
"=",
"new",
"XMLElement",
"(",
"'div'",
")",
";",
"$",
"div",
"->",
"appendChild",
"(",
"$",
"label",
")",
";",
"$",
"div",
"->",
"appendChild",
"(",
"$",
"ul",
")",
";",
"$",
"wrapper",
"->",
"appendChild",
"(",
"Widget",
"::",
"Error",
"(",
"$",
"div",
",",
"$",
"errors",
"[",
"'validator'",
"]",
")",
")",
";",
"}",
"else",
"{",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"label",
")",
";",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"ul",
")",
";",
"}",
"}"
] | Append a validator selector to a given `XMLElement`. Note that this
function differs from the other two similarly named build functions in
that it takes an `XMLElement` to append the Validator to as a parameter,
and does not return anything.
@param XMLElement $wrapper
the parent element to append the XMLElement of the Validation select to,
passed by reference.
@param string $selected (optional)
the current validator selection if there is one. defaults to null if there
isn't.
@param string $name (optional)
the form element name of this field. this defaults to "fields[validator]".
@param string $type (optional)
the type of input for the validation to apply to. this defaults to 'input'
but also accepts 'upload'.
@param array $errors (optional)
an associative array of errors
@throws InvalidArgumentException | [
"Append",
"a",
"validator",
"selector",
"to",
"a",
"given",
"XMLElement",
".",
"Note",
"that",
"this",
"function",
"differs",
"from",
"the",
"other",
"two",
"similarly",
"named",
"build",
"functions",
"in",
"that",
"it",
"takes",
"an",
"XMLElement",
"to",
"append",
"the",
"Validator",
"to",
"as",
"a",
"parameter",
"and",
"does",
"not",
"return",
"anything",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L645-L671 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.appendAssociationInterfaceSelect | public function appendAssociationInterfaceSelect(XMLElement &$wrapper)
{
$wrapper->setAttribute('data-condition', 'associative');
$interfaces = Symphony::ExtensionManager()->getProvidersOf(iProvider::ASSOCIATION_UI);
$editors = Symphony::ExtensionManager()->getProvidersOf(iProvider::ASSOCIATION_EDITOR);
if (!empty($interfaces) || !empty($editors)) {
$association_context = $this->getAssociationContext();
$group = new XMLElement('div');
if (!empty($interfaces) && !empty($editors)) {
$group->setAttribute('class', 'two columns');
}
// Create interface select
if (!empty($interfaces)) {
$label = Widget::Label(__('Association Interface'), null, 'column');
$label->appendChild(new XMLElement('i', __('Optional')));
$options = array(
array(null, false, __('None'))
);
foreach ($interfaces as $id => $name) {
$options[] = array($id, ($association_context['interface'] === $id), $name);
}
$select = Widget::Select('fields[' . $this->get('sortorder') . '][association_ui]', $options);
$label->appendChild($select);
$group->appendChild($label);
}
// Create editor select
if (!empty($editors)) {
$label = Widget::Label(__('Association Editor'), null, 'column');
$label->appendChild(new XMLElement('i', __('Optional')));
$options = array(
array(null, false, __('None'))
);
foreach ($editors as $id => $name) {
$options[] = array($id, ($association_context['editor'] === $id), $name);
}
$select = Widget::Select('fields[' . $this->get('sortorder') . '][association_editor]', $options);
$label->appendChild($select);
$group->appendChild($label);
}
$wrapper->appendChild($group);
}
} | php | public function appendAssociationInterfaceSelect(XMLElement &$wrapper)
{
$wrapper->setAttribute('data-condition', 'associative');
$interfaces = Symphony::ExtensionManager()->getProvidersOf(iProvider::ASSOCIATION_UI);
$editors = Symphony::ExtensionManager()->getProvidersOf(iProvider::ASSOCIATION_EDITOR);
if (!empty($interfaces) || !empty($editors)) {
$association_context = $this->getAssociationContext();
$group = new XMLElement('div');
if (!empty($interfaces) && !empty($editors)) {
$group->setAttribute('class', 'two columns');
}
// Create interface select
if (!empty($interfaces)) {
$label = Widget::Label(__('Association Interface'), null, 'column');
$label->appendChild(new XMLElement('i', __('Optional')));
$options = array(
array(null, false, __('None'))
);
foreach ($interfaces as $id => $name) {
$options[] = array($id, ($association_context['interface'] === $id), $name);
}
$select = Widget::Select('fields[' . $this->get('sortorder') . '][association_ui]', $options);
$label->appendChild($select);
$group->appendChild($label);
}
// Create editor select
if (!empty($editors)) {
$label = Widget::Label(__('Association Editor'), null, 'column');
$label->appendChild(new XMLElement('i', __('Optional')));
$options = array(
array(null, false, __('None'))
);
foreach ($editors as $id => $name) {
$options[] = array($id, ($association_context['editor'] === $id), $name);
}
$select = Widget::Select('fields[' . $this->get('sortorder') . '][association_editor]', $options);
$label->appendChild($select);
$group->appendChild($label);
}
$wrapper->appendChild($group);
}
} | [
"public",
"function",
"appendAssociationInterfaceSelect",
"(",
"XMLElement",
"&",
"$",
"wrapper",
")",
"{",
"$",
"wrapper",
"->",
"setAttribute",
"(",
"'data-condition'",
",",
"'associative'",
")",
";",
"$",
"interfaces",
"=",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"getProvidersOf",
"(",
"iProvider",
"::",
"ASSOCIATION_UI",
")",
";",
"$",
"editors",
"=",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"getProvidersOf",
"(",
"iProvider",
"::",
"ASSOCIATION_EDITOR",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"interfaces",
")",
"||",
"!",
"empty",
"(",
"$",
"editors",
")",
")",
"{",
"$",
"association_context",
"=",
"$",
"this",
"->",
"getAssociationContext",
"(",
")",
";",
"$",
"group",
"=",
"new",
"XMLElement",
"(",
"'div'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"interfaces",
")",
"&&",
"!",
"empty",
"(",
"$",
"editors",
")",
")",
"{",
"$",
"group",
"->",
"setAttribute",
"(",
"'class'",
",",
"'two columns'",
")",
";",
"}",
"// Create interface select",
"if",
"(",
"!",
"empty",
"(",
"$",
"interfaces",
")",
")",
"{",
"$",
"label",
"=",
"Widget",
"::",
"Label",
"(",
"__",
"(",
"'Association Interface'",
")",
",",
"null",
",",
"'column'",
")",
";",
"$",
"label",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'i'",
",",
"__",
"(",
"'Optional'",
")",
")",
")",
";",
"$",
"options",
"=",
"array",
"(",
"array",
"(",
"null",
",",
"false",
",",
"__",
"(",
"'None'",
")",
")",
")",
";",
"foreach",
"(",
"$",
"interfaces",
"as",
"$",
"id",
"=>",
"$",
"name",
")",
"{",
"$",
"options",
"[",
"]",
"=",
"array",
"(",
"$",
"id",
",",
"(",
"$",
"association_context",
"[",
"'interface'",
"]",
"===",
"$",
"id",
")",
",",
"$",
"name",
")",
";",
"}",
"$",
"select",
"=",
"Widget",
"::",
"Select",
"(",
"'fields['",
".",
"$",
"this",
"->",
"get",
"(",
"'sortorder'",
")",
".",
"'][association_ui]'",
",",
"$",
"options",
")",
";",
"$",
"label",
"->",
"appendChild",
"(",
"$",
"select",
")",
";",
"$",
"group",
"->",
"appendChild",
"(",
"$",
"label",
")",
";",
"}",
"// Create editor select",
"if",
"(",
"!",
"empty",
"(",
"$",
"editors",
")",
")",
"{",
"$",
"label",
"=",
"Widget",
"::",
"Label",
"(",
"__",
"(",
"'Association Editor'",
")",
",",
"null",
",",
"'column'",
")",
";",
"$",
"label",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'i'",
",",
"__",
"(",
"'Optional'",
")",
")",
")",
";",
"$",
"options",
"=",
"array",
"(",
"array",
"(",
"null",
",",
"false",
",",
"__",
"(",
"'None'",
")",
")",
")",
";",
"foreach",
"(",
"$",
"editors",
"as",
"$",
"id",
"=>",
"$",
"name",
")",
"{",
"$",
"options",
"[",
"]",
"=",
"array",
"(",
"$",
"id",
",",
"(",
"$",
"association_context",
"[",
"'editor'",
"]",
"===",
"$",
"id",
")",
",",
"$",
"name",
")",
";",
"}",
"$",
"select",
"=",
"Widget",
"::",
"Select",
"(",
"'fields['",
".",
"$",
"this",
"->",
"get",
"(",
"'sortorder'",
")",
".",
"'][association_editor]'",
",",
"$",
"options",
")",
";",
"$",
"label",
"->",
"appendChild",
"(",
"$",
"select",
")",
";",
"$",
"group",
"->",
"appendChild",
"(",
"$",
"label",
")",
";",
"}",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"group",
")",
";",
"}",
"}"
] | Append the html widget for selecting an association interface and editor
for this field.
@param XMLElement $wrapper
the parent XML element to append the association interface selection to,
if either interfaces or editors are provided to the system.
@since Symphony 2.5.0 | [
"Append",
"the",
"html",
"widget",
"for",
"selecting",
"an",
"association",
"interface",
"and",
"editor",
"for",
"this",
"field",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L682-L733 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.getAssociationContext | public function getAssociationContext()
{
$context = Symphony::Engine()->Page->getContext();
$associations = $context['associations']['parent'];
$field_association = array();
$count = 0;
if (!empty($associations)) {
$associationsCount = count($associations);
for ($i = 0; $i < $associationsCount; $i++) {
if ($associations[$i]['child_section_field_id'] == $this->get('id')) {
if ($count === 0) {
$field_association = $associations[$i];
$count++;
} else {
$field_association['parent_section_id'] .= '|' . $associations[$i]['parent_section_id'];
$field_association['parent_section_field_id'] .= '|' . $associations[$i]['parent_section_field_id'];
}
}
}
}
return $field_association;
} | php | public function getAssociationContext()
{
$context = Symphony::Engine()->Page->getContext();
$associations = $context['associations']['parent'];
$field_association = array();
$count = 0;
if (!empty($associations)) {
$associationsCount = count($associations);
for ($i = 0; $i < $associationsCount; $i++) {
if ($associations[$i]['child_section_field_id'] == $this->get('id')) {
if ($count === 0) {
$field_association = $associations[$i];
$count++;
} else {
$field_association['parent_section_id'] .= '|' . $associations[$i]['parent_section_id'];
$field_association['parent_section_field_id'] .= '|' . $associations[$i]['parent_section_field_id'];
}
}
}
}
return $field_association;
} | [
"public",
"function",
"getAssociationContext",
"(",
")",
"{",
"$",
"context",
"=",
"Symphony",
"::",
"Engine",
"(",
")",
"->",
"Page",
"->",
"getContext",
"(",
")",
";",
"$",
"associations",
"=",
"$",
"context",
"[",
"'associations'",
"]",
"[",
"'parent'",
"]",
";",
"$",
"field_association",
"=",
"array",
"(",
")",
";",
"$",
"count",
"=",
"0",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"associations",
")",
")",
"{",
"$",
"associationsCount",
"=",
"count",
"(",
"$",
"associations",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"associationsCount",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"associations",
"[",
"$",
"i",
"]",
"[",
"'child_section_field_id'",
"]",
"==",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
")",
"{",
"if",
"(",
"$",
"count",
"===",
"0",
")",
"{",
"$",
"field_association",
"=",
"$",
"associations",
"[",
"$",
"i",
"]",
";",
"$",
"count",
"++",
";",
"}",
"else",
"{",
"$",
"field_association",
"[",
"'parent_section_id'",
"]",
".=",
"'|'",
".",
"$",
"associations",
"[",
"$",
"i",
"]",
"[",
"'parent_section_id'",
"]",
";",
"$",
"field_association",
"[",
"'parent_section_field_id'",
"]",
".=",
"'|'",
".",
"$",
"associations",
"[",
"$",
"i",
"]",
"[",
"'parent_section_field_id'",
"]",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"field_association",
";",
"}"
] | Get association data of the current field from the page context.
@since Symphony 2.5.0
@return array | [
"Get",
"association",
"data",
"of",
"the",
"current",
"field",
"from",
"the",
"page",
"context",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L741-L764 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.setAssociationContext | public function setAssociationContext(XMLElement &$wrapper)
{
$association_context = $this->getAssociationContext();
if (!empty($association_context)) {
$wrapper->setAttributeArray(array(
'data-parent-section-id' => $association_context['parent_section_id'],
'data-parent-section-field-id' => $association_context['parent_section_field_id'],
'data-child-section-id' => $association_context['child_section_id'],
'data-child-section-field-id' => $association_context['child_section_field_id'],
'data-interface' => $association_context['interface'],
'data-editor' => $association_context['editor']
));
}
} | php | public function setAssociationContext(XMLElement &$wrapper)
{
$association_context = $this->getAssociationContext();
if (!empty($association_context)) {
$wrapper->setAttributeArray(array(
'data-parent-section-id' => $association_context['parent_section_id'],
'data-parent-section-field-id' => $association_context['parent_section_field_id'],
'data-child-section-id' => $association_context['child_section_id'],
'data-child-section-field-id' => $association_context['child_section_field_id'],
'data-interface' => $association_context['interface'],
'data-editor' => $association_context['editor']
));
}
} | [
"public",
"function",
"setAssociationContext",
"(",
"XMLElement",
"&",
"$",
"wrapper",
")",
"{",
"$",
"association_context",
"=",
"$",
"this",
"->",
"getAssociationContext",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"association_context",
")",
")",
"{",
"$",
"wrapper",
"->",
"setAttributeArray",
"(",
"array",
"(",
"'data-parent-section-id'",
"=>",
"$",
"association_context",
"[",
"'parent_section_id'",
"]",
",",
"'data-parent-section-field-id'",
"=>",
"$",
"association_context",
"[",
"'parent_section_field_id'",
"]",
",",
"'data-child-section-id'",
"=>",
"$",
"association_context",
"[",
"'child_section_id'",
"]",
",",
"'data-child-section-field-id'",
"=>",
"$",
"association_context",
"[",
"'child_section_field_id'",
"]",
",",
"'data-interface'",
"=>",
"$",
"association_context",
"[",
"'interface'",
"]",
",",
"'data-editor'",
"=>",
"$",
"association_context",
"[",
"'editor'",
"]",
")",
")",
";",
"}",
"}"
] | Set association data for the current field.
@since Symphony 2.5.0
@param XMLElement $wrapper | [
"Set",
"association",
"data",
"for",
"the",
"current",
"field",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L772-L786 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.appendShowAssociationCheckbox | public function appendShowAssociationCheckbox(XMLElement &$wrapper, $help = null)
{
if (!$this->_showassociation) {
return;
}
$label = $this->createCheckboxSetting($wrapper, 'show_association', __('Display associations in entries table'), $help);
$label->setAttribute('data-condition', 'associative');
} | php | public function appendShowAssociationCheckbox(XMLElement &$wrapper, $help = null)
{
if (!$this->_showassociation) {
return;
}
$label = $this->createCheckboxSetting($wrapper, 'show_association', __('Display associations in entries table'), $help);
$label->setAttribute('data-condition', 'associative');
} | [
"public",
"function",
"appendShowAssociationCheckbox",
"(",
"XMLElement",
"&",
"$",
"wrapper",
",",
"$",
"help",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_showassociation",
")",
"{",
"return",
";",
"}",
"$",
"label",
"=",
"$",
"this",
"->",
"createCheckboxSetting",
"(",
"$",
"wrapper",
",",
"'show_association'",
",",
"__",
"(",
"'Display associations in entries table'",
")",
",",
"$",
"help",
")",
";",
"$",
"label",
"->",
"setAttribute",
"(",
"'data-condition'",
",",
"'associative'",
")",
";",
"}"
] | Append the show association html widget to the input parent XML element. This
widget allows fields that provide linking to hide or show the column in the linked
section, similar to how the Show Column functionality works, but for the linked
section.
@param XMLElement $wrapper
the parent XML element to append the checkbox to.
@param string $help (optional)
a help message to show below the checkbox.
@throws InvalidArgumentException | [
"Append",
"the",
"show",
"association",
"html",
"widget",
"to",
"the",
"input",
"parent",
"XML",
"element",
".",
"This",
"widget",
"allows",
"fields",
"that",
"provide",
"linking",
"to",
"hide",
"or",
"show",
"the",
"column",
"in",
"the",
"linked",
"section",
"similar",
"to",
"how",
"the",
"Show",
"Column",
"functionality",
"works",
"but",
"for",
"the",
"linked",
"section",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L835-L843 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.createCheckboxSetting | public function createCheckboxSetting(XMLElement &$wrapper, $setting, $label_description, $help = null)
{
$order = $this->get('sortorder');
$name = "fields[$order][$setting]";
$label = Widget::Checkbox($name, $this->get($setting), $label_description, $wrapper, $help);
$label->addClass('column');
return $label;
} | php | public function createCheckboxSetting(XMLElement &$wrapper, $setting, $label_description, $help = null)
{
$order = $this->get('sortorder');
$name = "fields[$order][$setting]";
$label = Widget::Checkbox($name, $this->get($setting), $label_description, $wrapper, $help);
$label->addClass('column');
return $label;
} | [
"public",
"function",
"createCheckboxSetting",
"(",
"XMLElement",
"&",
"$",
"wrapper",
",",
"$",
"setting",
",",
"$",
"label_description",
",",
"$",
"help",
"=",
"null",
")",
"{",
"$",
"order",
"=",
"$",
"this",
"->",
"get",
"(",
"'sortorder'",
")",
";",
"$",
"name",
"=",
"\"fields[$order][$setting]\"",
";",
"$",
"label",
"=",
"Widget",
"::",
"Checkbox",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"get",
"(",
"$",
"setting",
")",
",",
"$",
"label_description",
",",
"$",
"wrapper",
",",
"$",
"help",
")",
";",
"$",
"label",
"->",
"addClass",
"(",
"'column'",
")",
";",
"return",
"$",
"label",
";",
"}"
] | Given the setting name and the label, this helper method will add
the required markup for a checkbox to the given `$wrapper`.
@since Symphony 2.5.2
@param XMLElement $wrapper
Passed by reference, this will have the resulting markup appended to it
@param string $setting
This will be used with $this->get() to get the existing value
@param string $label_description
This will be localisable and displayed after the checkbox when
generated.
@param string $help (optional)
A help message to show below the checkbox.
@return XMLElement
The Label and Checkbox that was just added to the `$wrapper`. | [
"Given",
"the",
"setting",
"name",
"and",
"the",
"label",
"this",
"helper",
"method",
"will",
"add",
"the",
"required",
"markup",
"for",
"a",
"checkbox",
"to",
"the",
"given",
"$wrapper",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L862-L871 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.appendStatusFooter | public function appendStatusFooter(XMLElement &$wrapper)
{
$fieldset = new XMLElement('fieldset');
$div = new XMLElement('div', null, array('class' => 'two columns'));
$this->appendRequiredCheckbox($div);
$this->appendShowColumnCheckbox($div);
$fieldset->appendChild($div);
$wrapper->appendChild($fieldset);
} | php | public function appendStatusFooter(XMLElement &$wrapper)
{
$fieldset = new XMLElement('fieldset');
$div = new XMLElement('div', null, array('class' => 'two columns'));
$this->appendRequiredCheckbox($div);
$this->appendShowColumnCheckbox($div);
$fieldset->appendChild($div);
$wrapper->appendChild($fieldset);
} | [
"public",
"function",
"appendStatusFooter",
"(",
"XMLElement",
"&",
"$",
"wrapper",
")",
"{",
"$",
"fieldset",
"=",
"new",
"XMLElement",
"(",
"'fieldset'",
")",
";",
"$",
"div",
"=",
"new",
"XMLElement",
"(",
"'div'",
",",
"null",
",",
"array",
"(",
"'class'",
"=>",
"'two columns'",
")",
")",
";",
"$",
"this",
"->",
"appendRequiredCheckbox",
"(",
"$",
"div",
")",
";",
"$",
"this",
"->",
"appendShowColumnCheckbox",
"(",
"$",
"div",
")",
";",
"$",
"fieldset",
"->",
"appendChild",
"(",
"$",
"div",
")",
";",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"fieldset",
")",
";",
"}"
] | Append the default status footer to the field settings panel.
Displays the required and show column checkboxes.
@param XMLElement $wrapper
the parent XML element to append the checkbox to.
@throws InvalidArgumentException | [
"Append",
"the",
"default",
"status",
"footer",
"to",
"the",
"field",
"settings",
"panel",
".",
"Displays",
"the",
"required",
"and",
"show",
"column",
"checkboxes",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L881-L891 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.checkFields | public function checkFields(array &$errors, $checkForDuplicates = true)
{
$parent_section = $this->get('parent_section');
$label = $this->get('label');
$element_name = $this->get('element_name');
if (Lang::isUnicodeCompiled()) {
$valid_name = preg_match('/^[\p{L}]([0-9\p{L}\.\-\_]+)?$/u', $element_name);
} else {
$valid_name = preg_match('/^[A-z]([\w\d\-_\.]+)?$/i', $element_name);
}
if ($label === '') {
$errors['label'] = __('This is a required field.');
} elseif (strtolower($label) === 'id') {
$errors['label'] = __('%s is a reserved name used by the system and is not allowed for a field handle. Try using %s instead.', array('<code>ID</code>', '<code>UID</code>'));
}
if ($element_name === '') {
$errors['element_name'] = __('This is a required field.');
} elseif ($element_name === 'id') {
$errors['element_name'] = __('%s is a reserved name used by the system and is not allowed for a field handle. Try using %s instead.', array('<code>id</code>', '<code>uid</code>'));
} elseif (!$valid_name) {
$errors['element_name'] = __('Invalid element name. Must be valid %s.', array('<code>QName</code>'));
} elseif ($checkForDuplicates) {
if (FieldManager::fetchFieldIDFromElementName($element_name, $parent_section) !== $this->get('id')) {
$errors['element_name'] = __('A field with that element name already exists. Please choose another.');
}
}
// Check that if the validator is provided that it's a valid regular expression
if (!is_null($this->get('validator')) && $this->get('validator') !== '') {
if (@preg_match($this->get('validator'), 'teststring') === false) {
$errors['validator'] = __('Validation rule is not a valid regular expression');
}
}
return (!empty($errors) ? self::__ERROR__ : self::__OK__);
} | php | public function checkFields(array &$errors, $checkForDuplicates = true)
{
$parent_section = $this->get('parent_section');
$label = $this->get('label');
$element_name = $this->get('element_name');
if (Lang::isUnicodeCompiled()) {
$valid_name = preg_match('/^[\p{L}]([0-9\p{L}\.\-\_]+)?$/u', $element_name);
} else {
$valid_name = preg_match('/^[A-z]([\w\d\-_\.]+)?$/i', $element_name);
}
if ($label === '') {
$errors['label'] = __('This is a required field.');
} elseif (strtolower($label) === 'id') {
$errors['label'] = __('%s is a reserved name used by the system and is not allowed for a field handle. Try using %s instead.', array('<code>ID</code>', '<code>UID</code>'));
}
if ($element_name === '') {
$errors['element_name'] = __('This is a required field.');
} elseif ($element_name === 'id') {
$errors['element_name'] = __('%s is a reserved name used by the system and is not allowed for a field handle. Try using %s instead.', array('<code>id</code>', '<code>uid</code>'));
} elseif (!$valid_name) {
$errors['element_name'] = __('Invalid element name. Must be valid %s.', array('<code>QName</code>'));
} elseif ($checkForDuplicates) {
if (FieldManager::fetchFieldIDFromElementName($element_name, $parent_section) !== $this->get('id')) {
$errors['element_name'] = __('A field with that element name already exists. Please choose another.');
}
}
// Check that if the validator is provided that it's a valid regular expression
if (!is_null($this->get('validator')) && $this->get('validator') !== '') {
if (@preg_match($this->get('validator'), 'teststring') === false) {
$errors['validator'] = __('Validation rule is not a valid regular expression');
}
}
return (!empty($errors) ? self::__ERROR__ : self::__OK__);
} | [
"public",
"function",
"checkFields",
"(",
"array",
"&",
"$",
"errors",
",",
"$",
"checkForDuplicates",
"=",
"true",
")",
"{",
"$",
"parent_section",
"=",
"$",
"this",
"->",
"get",
"(",
"'parent_section'",
")",
";",
"$",
"label",
"=",
"$",
"this",
"->",
"get",
"(",
"'label'",
")",
";",
"$",
"element_name",
"=",
"$",
"this",
"->",
"get",
"(",
"'element_name'",
")",
";",
"if",
"(",
"Lang",
"::",
"isUnicodeCompiled",
"(",
")",
")",
"{",
"$",
"valid_name",
"=",
"preg_match",
"(",
"'/^[\\p{L}]([0-9\\p{L}\\.\\-\\_]+)?$/u'",
",",
"$",
"element_name",
")",
";",
"}",
"else",
"{",
"$",
"valid_name",
"=",
"preg_match",
"(",
"'/^[A-z]([\\w\\d\\-_\\.]+)?$/i'",
",",
"$",
"element_name",
")",
";",
"}",
"if",
"(",
"$",
"label",
"===",
"''",
")",
"{",
"$",
"errors",
"[",
"'label'",
"]",
"=",
"__",
"(",
"'This is a required field.'",
")",
";",
"}",
"elseif",
"(",
"strtolower",
"(",
"$",
"label",
")",
"===",
"'id'",
")",
"{",
"$",
"errors",
"[",
"'label'",
"]",
"=",
"__",
"(",
"'%s is a reserved name used by the system and is not allowed for a field handle. Try using %s instead.'",
",",
"array",
"(",
"'<code>ID</code>'",
",",
"'<code>UID</code>'",
")",
")",
";",
"}",
"if",
"(",
"$",
"element_name",
"===",
"''",
")",
"{",
"$",
"errors",
"[",
"'element_name'",
"]",
"=",
"__",
"(",
"'This is a required field.'",
")",
";",
"}",
"elseif",
"(",
"$",
"element_name",
"===",
"'id'",
")",
"{",
"$",
"errors",
"[",
"'element_name'",
"]",
"=",
"__",
"(",
"'%s is a reserved name used by the system and is not allowed for a field handle. Try using %s instead.'",
",",
"array",
"(",
"'<code>id</code>'",
",",
"'<code>uid</code>'",
")",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"valid_name",
")",
"{",
"$",
"errors",
"[",
"'element_name'",
"]",
"=",
"__",
"(",
"'Invalid element name. Must be valid %s.'",
",",
"array",
"(",
"'<code>QName</code>'",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"checkForDuplicates",
")",
"{",
"if",
"(",
"FieldManager",
"::",
"fetchFieldIDFromElementName",
"(",
"$",
"element_name",
",",
"$",
"parent_section",
")",
"!==",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
")",
"{",
"$",
"errors",
"[",
"'element_name'",
"]",
"=",
"__",
"(",
"'A field with that element name already exists. Please choose another.'",
")",
";",
"}",
"}",
"// Check that if the validator is provided that it's a valid regular expression",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"get",
"(",
"'validator'",
")",
")",
"&&",
"$",
"this",
"->",
"get",
"(",
"'validator'",
")",
"!==",
"''",
")",
"{",
"if",
"(",
"@",
"preg_match",
"(",
"$",
"this",
"->",
"get",
"(",
"'validator'",
")",
",",
"'teststring'",
")",
"===",
"false",
")",
"{",
"$",
"errors",
"[",
"'validator'",
"]",
"=",
"__",
"(",
"'Validation rule is not a valid regular expression'",
")",
";",
"}",
"}",
"return",
"(",
"!",
"empty",
"(",
"$",
"errors",
")",
"?",
"self",
"::",
"__ERROR__",
":",
"self",
"::",
"__OK__",
")",
";",
"}"
] | Check the field's settings to ensure they are valid on the section
editor
@param array $errors
the array to populate with the errors found.
@param boolean $checkForDuplicates (optional)
if set to true, duplicate Field name's in the same section will be flagged
as errors. Defaults to true.
@return integer
returns the status of the checking. if errors has been populated with
any errors `self::__ERROR__`, `self::__OK__` otherwise. | [
"Check",
"the",
"field",
"s",
"settings",
"to",
"ensure",
"they",
"are",
"valid",
"on",
"the",
"section",
"editor"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L906-L944 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.prepareTableValue | public function prepareTableValue($data, XMLElement $link = null, $entry_id = null)
{
$value = $this->prepareReadableValue($data, $entry_id, true, __('None'));
if ($link) {
$link->setValue($value);
return $link->generate();
}
return $value;
} | php | public function prepareTableValue($data, XMLElement $link = null, $entry_id = null)
{
$value = $this->prepareReadableValue($data, $entry_id, true, __('None'));
if ($link) {
$link->setValue($value);
return $link->generate();
}
return $value;
} | [
"public",
"function",
"prepareTableValue",
"(",
"$",
"data",
",",
"XMLElement",
"$",
"link",
"=",
"null",
",",
"$",
"entry_id",
"=",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"prepareReadableValue",
"(",
"$",
"data",
",",
"$",
"entry_id",
",",
"true",
",",
"__",
"(",
"'None'",
")",
")",
";",
"if",
"(",
"$",
"link",
")",
"{",
"$",
"link",
"->",
"setValue",
"(",
"$",
"value",
")",
";",
"return",
"$",
"link",
"->",
"generate",
"(",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Format this field value for display in the publish index tables.
Since Symphony 2.5.0, this function will call `Field::prepareReadableValue`
in order to get the field's human readable value.
@param array $data
an associative array of data for this string. At minimum this requires a
key of 'value'.
@param XMLElement $link (optional)
an XML link structure to append the content of this to provided it is not
null. it defaults to null.
@param integer $entry_id (optional)
An option entry ID for more intelligent processing. defaults to null
@return string
the formatted string summary of the values of this field instance. | [
"Format",
"this",
"field",
"value",
"for",
"display",
"in",
"the",
"publish",
"index",
"tables",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L963-L974 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.prepareReadableValue | public function prepareReadableValue($data, $entry_id = null, $truncate = false, $defaultValue = null)
{
$value = $this->prepareTextValue($data, $entry_id);
if ($truncate) {
$max_length = Symphony::Configuration()->get('cell_truncation_length', 'symphony');
$max_length = ($max_length ? $max_length : 75);
$value = (General::strlen($value) <= $max_length ? $value : General::substr($value, 0, $max_length) . '…');
}
if (General::strlen($value) == 0 && $defaultValue != null) {
$value = $defaultValue;
}
return $value;
} | php | public function prepareReadableValue($data, $entry_id = null, $truncate = false, $defaultValue = null)
{
$value = $this->prepareTextValue($data, $entry_id);
if ($truncate) {
$max_length = Symphony::Configuration()->get('cell_truncation_length', 'symphony');
$max_length = ($max_length ? $max_length : 75);
$value = (General::strlen($value) <= $max_length ? $value : General::substr($value, 0, $max_length) . '…');
}
if (General::strlen($value) == 0 && $defaultValue != null) {
$value = $defaultValue;
}
return $value;
} | [
"public",
"function",
"prepareReadableValue",
"(",
"$",
"data",
",",
"$",
"entry_id",
"=",
"null",
",",
"$",
"truncate",
"=",
"false",
",",
"$",
"defaultValue",
"=",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"prepareTextValue",
"(",
"$",
"data",
",",
"$",
"entry_id",
")",
";",
"if",
"(",
"$",
"truncate",
")",
"{",
"$",
"max_length",
"=",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'cell_truncation_length'",
",",
"'symphony'",
")",
";",
"$",
"max_length",
"=",
"(",
"$",
"max_length",
"?",
"$",
"max_length",
":",
"75",
")",
";",
"$",
"value",
"=",
"(",
"General",
"::",
"strlen",
"(",
"$",
"value",
")",
"<=",
"$",
"max_length",
"?",
"$",
"value",
":",
"General",
"::",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"$",
"max_length",
")",
".",
"'…');",
"",
"",
"}",
"if",
"(",
"General",
"::",
"strlen",
"(",
"$",
"value",
")",
"==",
"0",
"&&",
"$",
"defaultValue",
"!=",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"defaultValue",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Format this field value for display as readable text value. By default, it
will call `Field::prepareTextValue` to get the raw text value of this field.
If $truncate is set to true, Symphony will truncate the value to the
configuration setting `cell_truncation_length`.
@since Symphony 2.5.0
@param array $data
an associative array of data for this string. At minimum this requires a
key of 'value'.
@param integer $entry_id (optional)
An option entry ID for more intelligent processing. Defaults to null.
@param string $defaultValue (optional)
The value to use when no plain text representation of the field's data
can be made. Defaults to null.
@return string
the readable text summary of the values of this field instance. | [
"Format",
"this",
"field",
"value",
"for",
"display",
"as",
"readable",
"text",
"value",
".",
"By",
"default",
"it",
"will",
"call",
"Field",
"::",
"prepareTextValue",
"to",
"get",
"the",
"raw",
"text",
"value",
"of",
"this",
"field",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L995-L1011 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.createAssociationsDrawerXMLElement | public static function createAssociationsDrawerXMLElement($value, Entry $e, array $parent_association, $prepopulate = '')
{
$li = new XMLElement('li');
$a = new XMLElement('a', $value);
$a->setAttribute('href', SYMPHONY_URL . '/publish/' . $parent_association['handle'] . '/edit/' . $e->get('id') . '/' . $prepopulate);
$li->appendChild($a);
return $li;
} | php | public static function createAssociationsDrawerXMLElement($value, Entry $e, array $parent_association, $prepopulate = '')
{
$li = new XMLElement('li');
$a = new XMLElement('a', $value);
$a->setAttribute('href', SYMPHONY_URL . '/publish/' . $parent_association['handle'] . '/edit/' . $e->get('id') . '/' . $prepopulate);
$li->appendChild($a);
return $li;
} | [
"public",
"static",
"function",
"createAssociationsDrawerXMLElement",
"(",
"$",
"value",
",",
"Entry",
"$",
"e",
",",
"array",
"$",
"parent_association",
",",
"$",
"prepopulate",
"=",
"''",
")",
"{",
"$",
"li",
"=",
"new",
"XMLElement",
"(",
"'li'",
")",
";",
"$",
"a",
"=",
"new",
"XMLElement",
"(",
"'a'",
",",
"$",
"value",
")",
";",
"$",
"a",
"->",
"setAttribute",
"(",
"'href'",
",",
"SYMPHONY_URL",
".",
"'/publish/'",
".",
"$",
"parent_association",
"[",
"'handle'",
"]",
".",
"'/edit/'",
".",
"$",
"e",
"->",
"get",
"(",
"'id'",
")",
".",
"'/'",
".",
"$",
"prepopulate",
")",
";",
"$",
"li",
"->",
"appendChild",
"(",
"$",
"a",
")",
";",
"return",
"$",
"li",
";",
"}"
] | This is general purpose factory method that makes it easier to create the
markup needed in order to create an Associations Drawer XMLElement.
@since Symphony 2.5.0
@param string $value
The value to display in the link
@param Entry $e
The associated entry
@param array $parent_association
An array containing information about the association
@param string $prepopulate
A string containing prepopulate parameter to append to the association url
@return XMLElement
The XMLElement must be a li node, since it will be added an ul node. | [
"This",
"is",
"general",
"purpose",
"factory",
"method",
"that",
"makes",
"it",
"easier",
"to",
"create",
"the",
"markup",
"needed",
"in",
"order",
"to",
"create",
"an",
"Associations",
"Drawer",
"XMLElement",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L1049-L1056 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.prepareAssociationsDrawerXMLElement | public function prepareAssociationsDrawerXMLElement(Entry $e, array $parent_association, $prepopulate = '')
{
$value = $this->prepareReadableValue($e->getData($this->get('id')), $e->get('id'));
// fallback for compatibility since the default
// `preparePlainTextValue` is not compatible with all fields
// this should be removed in Symphony 3.0
if (empty($value)) {
$value = strip_tags($this->prepareTableValue($e->getData($this->get('id')), null, $e->get('id')));
}
// use our factory method to create the html
$li = self::createAssociationsDrawerXMLElement($value, $e, $parent_association, $prepopulate);
$li->setAttribute('class', 'field-' . $this->get('type'));
return $li;
} | php | public function prepareAssociationsDrawerXMLElement(Entry $e, array $parent_association, $prepopulate = '')
{
$value = $this->prepareReadableValue($e->getData($this->get('id')), $e->get('id'));
// fallback for compatibility since the default
// `preparePlainTextValue` is not compatible with all fields
// this should be removed in Symphony 3.0
if (empty($value)) {
$value = strip_tags($this->prepareTableValue($e->getData($this->get('id')), null, $e->get('id')));
}
// use our factory method to create the html
$li = self::createAssociationsDrawerXMLElement($value, $e, $parent_association, $prepopulate);
$li->setAttribute('class', 'field-' . $this->get('type'));
return $li;
} | [
"public",
"function",
"prepareAssociationsDrawerXMLElement",
"(",
"Entry",
"$",
"e",
",",
"array",
"$",
"parent_association",
",",
"$",
"prepopulate",
"=",
"''",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"prepareReadableValue",
"(",
"$",
"e",
"->",
"getData",
"(",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
")",
",",
"$",
"e",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"// fallback for compatibility since the default",
"// `preparePlainTextValue` is not compatible with all fields",
"// this should be removed in Symphony 3.0",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"strip_tags",
"(",
"$",
"this",
"->",
"prepareTableValue",
"(",
"$",
"e",
"->",
"getData",
"(",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
")",
",",
"null",
",",
"$",
"e",
"->",
"get",
"(",
"'id'",
")",
")",
")",
";",
"}",
"// use our factory method to create the html",
"$",
"li",
"=",
"self",
"::",
"createAssociationsDrawerXMLElement",
"(",
"$",
"value",
",",
"$",
"e",
",",
"$",
"parent_association",
",",
"$",
"prepopulate",
")",
";",
"$",
"li",
"->",
"setAttribute",
"(",
"'class'",
",",
"'field-'",
".",
"$",
"this",
"->",
"get",
"(",
"'type'",
")",
")",
";",
"return",
"$",
"li",
";",
"}"
] | Format this field value for display in the Associations Drawer publish index.
By default, Symphony will use the return value of the `prepareReadableValue` function.
@since Symphony 2.4
@since Symphony 2.5.0 The prepopulate parameter was added.
@param Entry $e
The associated entry
@param array $parent_association
An array containing information about the association
@param string $prepopulate
A string containing prepopulate parameter to append to the association url
@return XMLElement
The XMLElement must be a li node, since it will be added an ul node. | [
"Format",
"this",
"field",
"value",
"for",
"display",
"in",
"the",
"Associations",
"Drawer",
"publish",
"index",
".",
"By",
"default",
"Symphony",
"will",
"use",
"the",
"return",
"value",
"of",
"the",
"prepareReadableValue",
"function",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L1075-L1092 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.displayPublishPanel | public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null)
{
} | php | public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null)
{
} | [
"public",
"function",
"displayPublishPanel",
"(",
"XMLElement",
"&",
"$",
"wrapper",
",",
"$",
"data",
"=",
"null",
",",
"$",
"flagWithError",
"=",
"null",
",",
"$",
"fieldnamePrefix",
"=",
"null",
",",
"$",
"fieldnamePostfix",
"=",
"null",
",",
"$",
"entry_id",
"=",
"null",
")",
"{",
"}"
] | Display the publish panel for this field. The display panel is the
interface shown to Authors that allow them to input data into this
field for an `Entry`.
@param XMLElement $wrapper
the XML element to append the html defined user interface to this
field.
@param array $data (optional)
any existing data that has been supplied for this field instance.
this is encoded as an array of columns, each column maps to an
array of row indexes to the contents of that column. this defaults
to null.
@param mixed $flagWithError (optional)
flag with error defaults to null.
@param string $fieldnamePrefix (optional)
the string to be prepended to the display of the name of this field.
this defaults to null.
@param string $fieldnamePostfix (optional)
the string to be appended to the display of the name of this field.
this defaults to null.
@param integer $entry_id (optional)
the entry id of this field. this defaults to null. | [
"Display",
"the",
"publish",
"panel",
"for",
"this",
"field",
".",
"The",
"display",
"panel",
"is",
"the",
"interface",
"shown",
"to",
"Authors",
"that",
"allow",
"them",
"to",
"input",
"data",
"into",
"this",
"field",
"for",
"an",
"Entry",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L1118-L1120 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.checkPostFieldData | public function checkPostFieldData($data, &$message, $entry_id = null)
{
$message = null;
$has_no_value = is_array($data) ? empty($data) : strlen(trim($data)) == 0;
if ($this->get('required') === 'yes' && $has_no_value) {
$message = __('‘%s’ is a required field.', array($this->get('label')));
return self::__MISSING_FIELDS__;
}
return self::__OK__;
} | php | public function checkPostFieldData($data, &$message, $entry_id = null)
{
$message = null;
$has_no_value = is_array($data) ? empty($data) : strlen(trim($data)) == 0;
if ($this->get('required') === 'yes' && $has_no_value) {
$message = __('‘%s’ is a required field.', array($this->get('label')));
return self::__MISSING_FIELDS__;
}
return self::__OK__;
} | [
"public",
"function",
"checkPostFieldData",
"(",
"$",
"data",
",",
"&",
"$",
"message",
",",
"$",
"entry_id",
"=",
"null",
")",
"{",
"$",
"message",
"=",
"null",
";",
"$",
"has_no_value",
"=",
"is_array",
"(",
"$",
"data",
")",
"?",
"empty",
"(",
"$",
"data",
")",
":",
"strlen",
"(",
"trim",
"(",
"$",
"data",
")",
")",
"==",
"0",
";",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'required'",
")",
"===",
"'yes'",
"&&",
"$",
"has_no_value",
")",
"{",
"$",
"message",
"=",
"__",
"(",
"'‘%s’ is a required field.', ar",
"r",
"y($th",
"i",
"s",
"->ge",
"t(",
"'la",
"b",
"el')));",
"",
"",
"",
"",
"return",
"self",
"::",
"__MISSING_FIELDS__",
";",
"}",
"return",
"self",
"::",
"__OK__",
";",
"}"
] | Check the field data that has been posted from a form. This will set the
input message to the error message or to null if there is none. Any existing
message value will be overwritten.
@param array $data
the input data to check.
@param string $message
the place to set any generated error message. any previous value for
this variable will be overwritten.
@param integer $entry_id (optional)
the optional id of this field entry instance. this defaults to null.
@return integer
`self::__MISSING_FIELDS__` if there are any missing required fields,
`self::__OK__` otherwise. | [
"Check",
"the",
"field",
"data",
"that",
"has",
"been",
"posted",
"from",
"a",
"form",
".",
"This",
"will",
"set",
"the",
"input",
"message",
"to",
"the",
"error",
"message",
"or",
"to",
"null",
"if",
"there",
"is",
"none",
".",
"Any",
"existing",
"message",
"value",
"will",
"be",
"overwritten",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L1138-L1151 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.processRawFieldData | public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = null)
{
$status = self::__OK__;
return array(
'value' => $data,
);
} | php | public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = null)
{
$status = self::__OK__;
return array(
'value' => $data,
);
} | [
"public",
"function",
"processRawFieldData",
"(",
"$",
"data",
",",
"&",
"$",
"status",
",",
"&",
"$",
"message",
"=",
"null",
",",
"$",
"simulate",
"=",
"false",
",",
"$",
"entry_id",
"=",
"null",
")",
"{",
"$",
"status",
"=",
"self",
"::",
"__OK__",
";",
"return",
"array",
"(",
"'value'",
"=>",
"$",
"data",
",",
")",
";",
"}"
] | Process the raw field data.
@param mixed $data
post data from the entry form
@param integer $status
the status code resultant from processing the data.
@param string $message
the place to set any generated error message. any previous value for
this variable will be overwritten.
@param boolean $simulate (optional)
true if this will tell the CF's to simulate data creation, false
otherwise. this defaults to false. this is important if clients
will be deleting or adding data outside of the main entry object
commit function.
@param mixed $entry_id (optional)
the current entry. defaults to null.
@return array
the processed field data. | [
"Process",
"the",
"raw",
"field",
"data",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L1173-L1180 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.displayDatasourceFilterPanel | public function displayDatasourceFilterPanel(XMLElement &$wrapper, $data = null, $errors = null, $fieldnamePrefix = null, $fieldnamePostfix = null)
{
$wrapper->appendChild(new XMLElement('header', '<h4>' . $this->get('label') . '</h4> <span>' . $this->name() . '</span>', array(
'data-name' => $this->get('label') . ' (' . $this->name() . ')'
)));
$label = Widget::Label(__('Value'));
$input = Widget::Input('fields[filter]'.($fieldnamePrefix ? '['.$fieldnamePrefix.']' : '').'['.$this->get('id').']'.($fieldnamePostfix ? '['.$fieldnamePostfix.']' : ''), ($data ? General::sanitize($data) : null));
$input->setAttribute('autocomplete', 'off');
$input->setAttribute('data-search-types', 'parameters');
$input->setAttribute('data-trigger', '{$');
$label->appendChild($input);
$wrapper->appendChild($label);
$this->displayFilteringOptions($wrapper);
} | php | public function displayDatasourceFilterPanel(XMLElement &$wrapper, $data = null, $errors = null, $fieldnamePrefix = null, $fieldnamePostfix = null)
{
$wrapper->appendChild(new XMLElement('header', '<h4>' . $this->get('label') . '</h4> <span>' . $this->name() . '</span>', array(
'data-name' => $this->get('label') . ' (' . $this->name() . ')'
)));
$label = Widget::Label(__('Value'));
$input = Widget::Input('fields[filter]'.($fieldnamePrefix ? '['.$fieldnamePrefix.']' : '').'['.$this->get('id').']'.($fieldnamePostfix ? '['.$fieldnamePostfix.']' : ''), ($data ? General::sanitize($data) : null));
$input->setAttribute('autocomplete', 'off');
$input->setAttribute('data-search-types', 'parameters');
$input->setAttribute('data-trigger', '{$');
$label->appendChild($input);
$wrapper->appendChild($label);
$this->displayFilteringOptions($wrapper);
} | [
"public",
"function",
"displayDatasourceFilterPanel",
"(",
"XMLElement",
"&",
"$",
"wrapper",
",",
"$",
"data",
"=",
"null",
",",
"$",
"errors",
"=",
"null",
",",
"$",
"fieldnamePrefix",
"=",
"null",
",",
"$",
"fieldnamePostfix",
"=",
"null",
")",
"{",
"$",
"wrapper",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'header'",
",",
"'<h4>'",
".",
"$",
"this",
"->",
"get",
"(",
"'label'",
")",
".",
"'</h4> <span>'",
".",
"$",
"this",
"->",
"name",
"(",
")",
".",
"'</span>'",
",",
"array",
"(",
"'data-name'",
"=>",
"$",
"this",
"->",
"get",
"(",
"'label'",
")",
".",
"' ('",
".",
"$",
"this",
"->",
"name",
"(",
")",
".",
"')'",
")",
")",
")",
";",
"$",
"label",
"=",
"Widget",
"::",
"Label",
"(",
"__",
"(",
"'Value'",
")",
")",
";",
"$",
"input",
"=",
"Widget",
"::",
"Input",
"(",
"'fields[filter]'",
".",
"(",
"$",
"fieldnamePrefix",
"?",
"'['",
".",
"$",
"fieldnamePrefix",
".",
"']'",
":",
"''",
")",
".",
"'['",
".",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
".",
"']'",
".",
"(",
"$",
"fieldnamePostfix",
"?",
"'['",
".",
"$",
"fieldnamePostfix",
".",
"']'",
":",
"''",
")",
",",
"(",
"$",
"data",
"?",
"General",
"::",
"sanitize",
"(",
"$",
"data",
")",
":",
"null",
")",
")",
";",
"$",
"input",
"->",
"setAttribute",
"(",
"'autocomplete'",
",",
"'off'",
")",
";",
"$",
"input",
"->",
"setAttribute",
"(",
"'data-search-types'",
",",
"'parameters'",
")",
";",
"$",
"input",
"->",
"setAttribute",
"(",
"'data-trigger'",
",",
"'{$'",
")",
";",
"$",
"label",
"->",
"appendChild",
"(",
"$",
"input",
")",
";",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"label",
")",
";",
"$",
"this",
"->",
"displayFilteringOptions",
"(",
"$",
"wrapper",
")",
";",
"}"
] | Display the default data source filter panel.
@param XMLElement $wrapper
the input XMLElement to which the display of this will be appended.
@param mixed $data (optional)
the input data. this defaults to null.
@param null $errors
the input error collection. this defaults to null.
@param string $fieldnamePrefix
the prefix to apply to the display of this.
@param string $fieldnamePostfix
the suffix to apply to the display of this.
@throws InvalidArgumentException | [
"Display",
"the",
"default",
"data",
"source",
"filter",
"panel",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L1259-L1274 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.displayFilteringOptions | public function displayFilteringOptions(XMLElement &$wrapper)
{
// Add filter tags
$filterTags = new XMLElement('ul');
$filterTags->setAttribute('class', 'tags singular');
$filterTags->setAttribute('data-interactive', 'data-interactive');
$filters = $this->fetchFilterableOperators();
foreach ($filters as $value) {
$item = new XMLElement('li', $value['title']);
$item->setAttribute('data-value', $value['filter']);
if (isset($value['help'])) {
$item->setAttribute('data-help', General::sanitize($value['help']));
}
$filterTags->appendChild($item);
}
$wrapper->appendChild($filterTags);
$help = new XMLElement('p');
$help->setAttribute('class', 'help');
$first = array_shift($filters);
$help->setValue($first['help']);
$wrapper->appendChild($help);
} | php | public function displayFilteringOptions(XMLElement &$wrapper)
{
// Add filter tags
$filterTags = new XMLElement('ul');
$filterTags->setAttribute('class', 'tags singular');
$filterTags->setAttribute('data-interactive', 'data-interactive');
$filters = $this->fetchFilterableOperators();
foreach ($filters as $value) {
$item = new XMLElement('li', $value['title']);
$item->setAttribute('data-value', $value['filter']);
if (isset($value['help'])) {
$item->setAttribute('data-help', General::sanitize($value['help']));
}
$filterTags->appendChild($item);
}
$wrapper->appendChild($filterTags);
$help = new XMLElement('p');
$help->setAttribute('class', 'help');
$first = array_shift($filters);
$help->setValue($first['help']);
$wrapper->appendChild($help);
} | [
"public",
"function",
"displayFilteringOptions",
"(",
"XMLElement",
"&",
"$",
"wrapper",
")",
"{",
"// Add filter tags",
"$",
"filterTags",
"=",
"new",
"XMLElement",
"(",
"'ul'",
")",
";",
"$",
"filterTags",
"->",
"setAttribute",
"(",
"'class'",
",",
"'tags singular'",
")",
";",
"$",
"filterTags",
"->",
"setAttribute",
"(",
"'data-interactive'",
",",
"'data-interactive'",
")",
";",
"$",
"filters",
"=",
"$",
"this",
"->",
"fetchFilterableOperators",
"(",
")",
";",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"value",
")",
"{",
"$",
"item",
"=",
"new",
"XMLElement",
"(",
"'li'",
",",
"$",
"value",
"[",
"'title'",
"]",
")",
";",
"$",
"item",
"->",
"setAttribute",
"(",
"'data-value'",
",",
"$",
"value",
"[",
"'filter'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"value",
"[",
"'help'",
"]",
")",
")",
"{",
"$",
"item",
"->",
"setAttribute",
"(",
"'data-help'",
",",
"General",
"::",
"sanitize",
"(",
"$",
"value",
"[",
"'help'",
"]",
")",
")",
";",
"}",
"$",
"filterTags",
"->",
"appendChild",
"(",
"$",
"item",
")",
";",
"}",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"filterTags",
")",
";",
"$",
"help",
"=",
"new",
"XMLElement",
"(",
"'p'",
")",
";",
"$",
"help",
"->",
"setAttribute",
"(",
"'class'",
",",
"'help'",
")",
";",
"$",
"first",
"=",
"array_shift",
"(",
"$",
"filters",
")",
";",
"$",
"help",
"->",
"setValue",
"(",
"$",
"first",
"[",
"'help'",
"]",
")",
";",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"help",
")",
";",
"}"
] | Inserts tags at the bottom of the filter panel
@since Symphony 2.6.0
@param XMLElement $wrapper | [
"Inserts",
"tags",
"at",
"the",
"bottom",
"of",
"the",
"filter",
"panel"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L1282-L1307 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.buildRegexSQL | public function buildRegexSQL($filter, array $columns, &$joins, &$where)
{
$this->_key++;
$field_id = $this->get('id');
$filter = $this->cleanValue($filter);
$op = '';
if (preg_match('/^regexp:\s*/i', $filter)) {
$pattern = preg_replace('/^regexp:\s*/i', null, $filter);
$regex = 'REGEXP';
$op = 'OR';
} elseif (preg_match('/^not-?regexp:\s*/i', $filter)) {
$pattern = preg_replace('/^not-?regexp:\s*/i', null, $filter);
$regex = 'NOT REGEXP';
$op = 'AND';
} else {
throw new Exception("Filter `$filter` is not a Regexp filter");
}
if (strlen($pattern) == 0) {
return;
}
$joins .= "
LEFT JOIN
`tbl_entries_data_{$field_id}` AS t{$field_id}_{$this->_key}
ON (e.id = t{$field_id}_{$this->_key}.entry_id)
";
$where .= "AND ( ";
foreach ($columns as $key => $col) {
$modifier = ($key === 0) ? '' : $op;
$where .= "
{$modifier} t{$field_id}_{$this->_key}.{$col} {$regex} '{$pattern}'
";
}
$where .= ")";
} | php | public function buildRegexSQL($filter, array $columns, &$joins, &$where)
{
$this->_key++;
$field_id = $this->get('id');
$filter = $this->cleanValue($filter);
$op = '';
if (preg_match('/^regexp:\s*/i', $filter)) {
$pattern = preg_replace('/^regexp:\s*/i', null, $filter);
$regex = 'REGEXP';
$op = 'OR';
} elseif (preg_match('/^not-?regexp:\s*/i', $filter)) {
$pattern = preg_replace('/^not-?regexp:\s*/i', null, $filter);
$regex = 'NOT REGEXP';
$op = 'AND';
} else {
throw new Exception("Filter `$filter` is not a Regexp filter");
}
if (strlen($pattern) == 0) {
return;
}
$joins .= "
LEFT JOIN
`tbl_entries_data_{$field_id}` AS t{$field_id}_{$this->_key}
ON (e.id = t{$field_id}_{$this->_key}.entry_id)
";
$where .= "AND ( ";
foreach ($columns as $key => $col) {
$modifier = ($key === 0) ? '' : $op;
$where .= "
{$modifier} t{$field_id}_{$this->_key}.{$col} {$regex} '{$pattern}'
";
}
$where .= ")";
} | [
"public",
"function",
"buildRegexSQL",
"(",
"$",
"filter",
",",
"array",
"$",
"columns",
",",
"&",
"$",
"joins",
",",
"&",
"$",
"where",
")",
"{",
"$",
"this",
"->",
"_key",
"++",
";",
"$",
"field_id",
"=",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
";",
"$",
"filter",
"=",
"$",
"this",
"->",
"cleanValue",
"(",
"$",
"filter",
")",
";",
"$",
"op",
"=",
"''",
";",
"if",
"(",
"preg_match",
"(",
"'/^regexp:\\s*/i'",
",",
"$",
"filter",
")",
")",
"{",
"$",
"pattern",
"=",
"preg_replace",
"(",
"'/^regexp:\\s*/i'",
",",
"null",
",",
"$",
"filter",
")",
";",
"$",
"regex",
"=",
"'REGEXP'",
";",
"$",
"op",
"=",
"'OR'",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/^not-?regexp:\\s*/i'",
",",
"$",
"filter",
")",
")",
"{",
"$",
"pattern",
"=",
"preg_replace",
"(",
"'/^not-?regexp:\\s*/i'",
",",
"null",
",",
"$",
"filter",
")",
";",
"$",
"regex",
"=",
"'NOT REGEXP'",
";",
"$",
"op",
"=",
"'AND'",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"\"Filter `$filter` is not a Regexp filter\"",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"pattern",
")",
"==",
"0",
")",
"{",
"return",
";",
"}",
"$",
"joins",
".=",
"\"\n LEFT JOIN\n `tbl_entries_data_{$field_id}` AS t{$field_id}_{$this->_key}\n ON (e.id = t{$field_id}_{$this->_key}.entry_id)\n \"",
";",
"$",
"where",
".=",
"\"AND ( \"",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"key",
"=>",
"$",
"col",
")",
"{",
"$",
"modifier",
"=",
"(",
"$",
"key",
"===",
"0",
")",
"?",
"''",
":",
"$",
"op",
";",
"$",
"where",
".=",
"\"\n {$modifier} t{$field_id}_{$this->_key}.{$col} {$regex} '{$pattern}'\n \"",
";",
"}",
"$",
"where",
".=",
"\")\"",
";",
"}"
] | Builds a basic REGEXP statement given a `$filter`. This function supports
`regexp:` or `not-regexp:`. Users should keep in mind this function
uses MySQL patterns, not the usual PHP patterns, the syntax between these
flavours differs at times.
@since Symphony 2.3
@link https://dev.mysql.com/doc/refman/en/regexp.html
@param string $filter
The full filter, eg. `regexp: ^[a-d]`
@param array $columns
The array of columns that need the given `$filter` applied to. The conditions
will be added using `OR` when using `regexp:` but they will be added using `AND`
when using `not-regexp:`
@param string $joins
A string containing any table joins for the current SQL fragment. By default
Datasources will always join to the `tbl_entries` table, which has an alias of
`e`. This parameter is passed by reference.
@param string $where
A string containing the WHERE conditions for the current SQL fragment. This
is passed by reference and is expected to be used to add additional conditions
specific to this field | [
"Builds",
"a",
"basic",
"REGEXP",
"statement",
"given",
"a",
"$filter",
".",
"This",
"function",
"supports",
"regexp",
":",
"or",
"not",
"-",
"regexp",
":",
".",
"Users",
"should",
"keep",
"in",
"mind",
"this",
"function",
"uses",
"MySQL",
"patterns",
"not",
"the",
"usual",
"PHP",
"patterns",
"the",
"syntax",
"between",
"these",
"flavours",
"differs",
"at",
"times",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L1363-L1402 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.buildFilterSQL | public function buildFilterSQL($filter, array $columns, &$joins, &$where)
{
$this->_key++;
$field_id = $this->get('id');
$filter = $this->cleanValue($filter);
$pattern = '';
if (preg_match('/^sql:\s*NOT NULL$/i', $filter)) {
$pattern = 'NOT NULL';
} elseif (preg_match('/^sql:\s*NULL$/i', $filter)) {
$pattern = 'NULL';
} else {
// No match, return
return;
}
$joins .= "
LEFT JOIN
`tbl_entries_data_{$field_id}` AS t{$field_id}_{$this->_key}
ON (e.id = t{$field_id}_{$this->_key}.entry_id)
";
$where .= "AND ( ";
foreach ($columns as $key => $col) {
$modifier = ($key === 0) ? '' : 'OR';
$where .= "
{$modifier} t{$field_id}_{$this->_key}.{$col} IS {$pattern}
";
}
$where .= ")";
} | php | public function buildFilterSQL($filter, array $columns, &$joins, &$where)
{
$this->_key++;
$field_id = $this->get('id');
$filter = $this->cleanValue($filter);
$pattern = '';
if (preg_match('/^sql:\s*NOT NULL$/i', $filter)) {
$pattern = 'NOT NULL';
} elseif (preg_match('/^sql:\s*NULL$/i', $filter)) {
$pattern = 'NULL';
} else {
// No match, return
return;
}
$joins .= "
LEFT JOIN
`tbl_entries_data_{$field_id}` AS t{$field_id}_{$this->_key}
ON (e.id = t{$field_id}_{$this->_key}.entry_id)
";
$where .= "AND ( ";
foreach ($columns as $key => $col) {
$modifier = ($key === 0) ? '' : 'OR';
$where .= "
{$modifier} t{$field_id}_{$this->_key}.{$col} IS {$pattern}
";
}
$where .= ")";
} | [
"public",
"function",
"buildFilterSQL",
"(",
"$",
"filter",
",",
"array",
"$",
"columns",
",",
"&",
"$",
"joins",
",",
"&",
"$",
"where",
")",
"{",
"$",
"this",
"->",
"_key",
"++",
";",
"$",
"field_id",
"=",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
";",
"$",
"filter",
"=",
"$",
"this",
"->",
"cleanValue",
"(",
"$",
"filter",
")",
";",
"$",
"pattern",
"=",
"''",
";",
"if",
"(",
"preg_match",
"(",
"'/^sql:\\s*NOT NULL$/i'",
",",
"$",
"filter",
")",
")",
"{",
"$",
"pattern",
"=",
"'NOT NULL'",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/^sql:\\s*NULL$/i'",
",",
"$",
"filter",
")",
")",
"{",
"$",
"pattern",
"=",
"'NULL'",
";",
"}",
"else",
"{",
"// No match, return",
"return",
";",
"}",
"$",
"joins",
".=",
"\"\n LEFT JOIN\n `tbl_entries_data_{$field_id}` AS t{$field_id}_{$this->_key}\n ON (e.id = t{$field_id}_{$this->_key}.entry_id)\n \"",
";",
"$",
"where",
".=",
"\"AND ( \"",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"key",
"=>",
"$",
"col",
")",
"{",
"$",
"modifier",
"=",
"(",
"$",
"key",
"===",
"0",
")",
"?",
"''",
":",
"'OR'",
";",
"$",
"where",
".=",
"\"\n {$modifier} t{$field_id}_{$this->_key}.{$col} IS {$pattern}\n \"",
";",
"}",
"$",
"where",
".=",
"\")\"",
";",
"}"
] | Builds a basic NULL/NOT NULL SQL statement given a `$filter`.
This function supports `sql: NULL` or `sql: NOT NULL`.
@since Symphony 2.7.0
@link https://dev.mysql.com/doc/refman/en/regexp.html
@param string $filter
The full filter, eg. `sql: NULL`
@param array $columns
The array of columns that need the given `$filter` applied to. The conditions
will be added using `OR`.
@param string $joins
A string containing any table joins for the current SQL fragment. By default
Datasources will always join to the `tbl_entries` table, which has an alias of
`e`. This parameter is passed by reference.
@param string $where
A string containing the WHERE conditions for the current SQL fragment. This
is passed by reference and is expected to be used to add additional conditions
specific to this field | [
"Builds",
"a",
"basic",
"NULL",
"/",
"NOT",
"NULL",
"SQL",
"statement",
"given",
"a",
"$filter",
".",
"This",
"function",
"supports",
"sql",
":",
"NULL",
"or",
"sql",
":",
"NOT",
"NULL",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L1441-L1473 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.buildSortingSelectSQL | public function buildSortingSelectSQL($sort, $order = 'ASC')
{
if ($this->isRandomOrder($order)) {
return null;
}
// @deprecated This check should be removed in Symphony 3.0.0
if (strpos($sort, '`ed`.`value`') === false) {
return null;
}
return '`ed`.`value`';
} | php | public function buildSortingSelectSQL($sort, $order = 'ASC')
{
if ($this->isRandomOrder($order)) {
return null;
}
// @deprecated This check should be removed in Symphony 3.0.0
if (strpos($sort, '`ed`.`value`') === false) {
return null;
}
return '`ed`.`value`';
} | [
"public",
"function",
"buildSortingSelectSQL",
"(",
"$",
"sort",
",",
"$",
"order",
"=",
"'ASC'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isRandomOrder",
"(",
"$",
"order",
")",
")",
"{",
"return",
"null",
";",
"}",
"// @deprecated This check should be removed in Symphony 3.0.0",
"if",
"(",
"strpos",
"(",
"$",
"sort",
",",
"'`ed`.`value`'",
")",
"===",
"false",
")",
"{",
"return",
"null",
";",
"}",
"return",
"'`ed`.`value`'",
";",
"}"
] | Build the needed SQL clause command to make `buildSortingSQL()` work on
MySQL 5.7 in strict mode, which requires all columns in the ORDER BY
clause to be included in the SELECT's projection.
If no new projection is needed (like if the order is made via a sub-query),
simply return null.
For backward compatibility, this method checks if the sort expression
contains `ed`.`value`. This check will be removed in Symphony 3.0.0.
Extension developers should make their Fields implement
`buildSortingSelectSQL()` when overriding `buildSortingSQL()`.
@since Symphony 2.7.0
@uses Field::isRandomOrder()
@see Field::buildSortingSQL()
@param string $sort
the existing sort component of the sql query, after it has been passed
to `buildSortingSQL()`
@param string $order (optional)
an optional sorting direction. this defaults to ascending. Should be the
same value that was passed to `buildSortingSQL()`
@return string
an optional select clause to append to the generated SQL query.
This is needed when sorting on a column that is not part of the projection. | [
"Build",
"the",
"needed",
"SQL",
"clause",
"command",
"to",
"make",
"buildSortingSQL",
"()",
"work",
"on",
"MySQL",
"5",
".",
"7",
"in",
"strict",
"mode",
"which",
"requires",
"all",
"columns",
"in",
"the",
"ORDER",
"BY",
"clause",
"to",
"be",
"included",
"in",
"the",
"SELECT",
"s",
"projection",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L1622-L1632 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.appendFormattedElement | public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null)
{
$wrapper->appendChild(new XMLElement($this->get('element_name'), ($encode ?
General::sanitize($this->prepareReadableValue($data, $entry_id)) :
$this->prepareReadableValue($data, $entry_id))));
} | php | public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null)
{
$wrapper->appendChild(new XMLElement($this->get('element_name'), ($encode ?
General::sanitize($this->prepareReadableValue($data, $entry_id)) :
$this->prepareReadableValue($data, $entry_id))));
} | [
"public",
"function",
"appendFormattedElement",
"(",
"XMLElement",
"&",
"$",
"wrapper",
",",
"$",
"data",
",",
"$",
"encode",
"=",
"false",
",",
"$",
"mode",
"=",
"null",
",",
"$",
"entry_id",
"=",
"null",
")",
"{",
"$",
"wrapper",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"$",
"this",
"->",
"get",
"(",
"'element_name'",
")",
",",
"(",
"$",
"encode",
"?",
"General",
"::",
"sanitize",
"(",
"$",
"this",
"->",
"prepareReadableValue",
"(",
"$",
"data",
",",
"$",
"entry_id",
")",
")",
":",
"$",
"this",
"->",
"prepareReadableValue",
"(",
"$",
"data",
",",
"$",
"entry_id",
")",
")",
")",
")",
";",
"}"
] | Append the formatted XML output of this field as utilized as a data source.
Since Symphony 2.5.0, it will defaults to `prepareReadableValue` return value.
@param XMLElement $wrapper
the XML element to append the XML representation of this to.
@param array $data
the current set of values for this field. the values are structured as
for displayPublishPanel.
@param boolean $encode (optional)
flag as to whether this should be html encoded prior to output. this
defaults to false.
@param string $mode
A field can provide ways to output this field's data. For instance a mode
could be 'items' or 'full' and then the function would display the data
in a different way depending on what was selected in the datasource
included elements.
@param integer $entry_id (optional)
the identifier of this field entry instance. defaults to null. | [
"Append",
"the",
"formatted",
"XML",
"output",
"of",
"this",
"field",
"as",
"utilized",
"as",
"a",
"data",
"source",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L1691-L1696 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.commit | public function commit()
{
$fields = array();
$fields['label'] = General::sanitize($this->get('label'));
$fields['element_name'] = ($this->get('element_name') ? $this->get('element_name') : Lang::createHandle($this->get('label')));
$fields['parent_section'] = $this->get('parent_section');
$fields['location'] = $this->get('location');
$fields['required'] = $this->get('required');
$fields['type'] = $this->_handle;
$fields['show_column'] = $this->get('show_column');
$fields['sortorder'] = (string)$this->get('sortorder');
if ($id = $this->get('id')) {
return FieldManager::edit($id, $fields);
} elseif ($id = FieldManager::add($fields)) {
$this->set('id', $id);
if ($this->requiresTable()) {
return $this->createTable();
}
return true;
}
return false;
} | php | public function commit()
{
$fields = array();
$fields['label'] = General::sanitize($this->get('label'));
$fields['element_name'] = ($this->get('element_name') ? $this->get('element_name') : Lang::createHandle($this->get('label')));
$fields['parent_section'] = $this->get('parent_section');
$fields['location'] = $this->get('location');
$fields['required'] = $this->get('required');
$fields['type'] = $this->_handle;
$fields['show_column'] = $this->get('show_column');
$fields['sortorder'] = (string)$this->get('sortorder');
if ($id = $this->get('id')) {
return FieldManager::edit($id, $fields);
} elseif ($id = FieldManager::add($fields)) {
$this->set('id', $id);
if ($this->requiresTable()) {
return $this->createTable();
}
return true;
}
return false;
} | [
"public",
"function",
"commit",
"(",
")",
"{",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"$",
"fields",
"[",
"'label'",
"]",
"=",
"General",
"::",
"sanitize",
"(",
"$",
"this",
"->",
"get",
"(",
"'label'",
")",
")",
";",
"$",
"fields",
"[",
"'element_name'",
"]",
"=",
"(",
"$",
"this",
"->",
"get",
"(",
"'element_name'",
")",
"?",
"$",
"this",
"->",
"get",
"(",
"'element_name'",
")",
":",
"Lang",
"::",
"createHandle",
"(",
"$",
"this",
"->",
"get",
"(",
"'label'",
")",
")",
")",
";",
"$",
"fields",
"[",
"'parent_section'",
"]",
"=",
"$",
"this",
"->",
"get",
"(",
"'parent_section'",
")",
";",
"$",
"fields",
"[",
"'location'",
"]",
"=",
"$",
"this",
"->",
"get",
"(",
"'location'",
")",
";",
"$",
"fields",
"[",
"'required'",
"]",
"=",
"$",
"this",
"->",
"get",
"(",
"'required'",
")",
";",
"$",
"fields",
"[",
"'type'",
"]",
"=",
"$",
"this",
"->",
"_handle",
";",
"$",
"fields",
"[",
"'show_column'",
"]",
"=",
"$",
"this",
"->",
"get",
"(",
"'show_column'",
")",
";",
"$",
"fields",
"[",
"'sortorder'",
"]",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"get",
"(",
"'sortorder'",
")",
";",
"if",
"(",
"$",
"id",
"=",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
")",
"{",
"return",
"FieldManager",
"::",
"edit",
"(",
"$",
"id",
",",
"$",
"fields",
")",
";",
"}",
"elseif",
"(",
"$",
"id",
"=",
"FieldManager",
"::",
"add",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"'id'",
",",
"$",
"id",
")",
";",
"if",
"(",
"$",
"this",
"->",
"requiresTable",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"createTable",
"(",
")",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Commit the settings of this field from the section editor to
create an instance of this field in a section.
@return boolean
true if the commit was successful, false otherwise. | [
"Commit",
"the",
"settings",
"of",
"this",
"field",
"from",
"the",
"section",
"editor",
"to",
"create",
"an",
"instance",
"of",
"this",
"field",
"in",
"a",
"section",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L1723-L1747 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.exists | public function exists()
{
if (!$this->get('id') || !$this->_handle) {
return false;
}
$row = Symphony::Database()->fetch(sprintf(
'SELECT `id` FROM `tbl_fields_%s` WHERE `field_id` = %d',
$this->_handle,
General::intval($this->get('id'))
));
if (empty($row)) {
// Some fields do not create any records in their settings table because they do not
// implement a proper `Field::commit()` method.
// The base implementation of the commit function only deals with the "core"
// `tbl_fields` table.
// The problem with this approach is that it can lead to data corruption when
// saving a field that got deleted by another user.
// The only way a field can live without a commit method is if it does not store any
// settings at all.
// But current version of Symphony assume that the `tbl_fields_$handle` table exists
// with at least a `id` and `field_id` column, so field are required to at least create
// the table to make their field work without SQL errors from the core.
$columns = Symphony::Database()->fetchCol('Field', sprintf(
'DESC `tbl_fields_%s`',
$this->_handle
));
// The table only has the two required columns, tolerate the missing record
$isDefault = count($columns) === 2 &&
in_array('id', $columns) &&
in_array('field_id', $columns);
if ($isDefault) {
Symphony::Log()->pushDeprecateWarningToLog($this->_handle, get_class($this), array(
'message-format' => __('The field `%1$s` does not create settings records in the `tbl_fields_%1$s`.'),
'alternative-format' => __('Please implement the commit function in class `%s`.'),
'removal-format' => __('The compatibility check will will be removed in Symphony %s.'),
'removal-version' => '4.0.0',
));
}
return $isDefault;
}
return true;
} | php | public function exists()
{
if (!$this->get('id') || !$this->_handle) {
return false;
}
$row = Symphony::Database()->fetch(sprintf(
'SELECT `id` FROM `tbl_fields_%s` WHERE `field_id` = %d',
$this->_handle,
General::intval($this->get('id'))
));
if (empty($row)) {
// Some fields do not create any records in their settings table because they do not
// implement a proper `Field::commit()` method.
// The base implementation of the commit function only deals with the "core"
// `tbl_fields` table.
// The problem with this approach is that it can lead to data corruption when
// saving a field that got deleted by another user.
// The only way a field can live without a commit method is if it does not store any
// settings at all.
// But current version of Symphony assume that the `tbl_fields_$handle` table exists
// with at least a `id` and `field_id` column, so field are required to at least create
// the table to make their field work without SQL errors from the core.
$columns = Symphony::Database()->fetchCol('Field', sprintf(
'DESC `tbl_fields_%s`',
$this->_handle
));
// The table only has the two required columns, tolerate the missing record
$isDefault = count($columns) === 2 &&
in_array('id', $columns) &&
in_array('field_id', $columns);
if ($isDefault) {
Symphony::Log()->pushDeprecateWarningToLog($this->_handle, get_class($this), array(
'message-format' => __('The field `%1$s` does not create settings records in the `tbl_fields_%1$s`.'),
'alternative-format' => __('Please implement the commit function in class `%s`.'),
'removal-format' => __('The compatibility check will will be removed in Symphony %s.'),
'removal-version' => '4.0.0',
));
}
return $isDefault;
}
return true;
} | [
"public",
"function",
"exists",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
"||",
"!",
"$",
"this",
"->",
"_handle",
")",
"{",
"return",
"false",
";",
"}",
"$",
"row",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetch",
"(",
"sprintf",
"(",
"'SELECT `id` FROM `tbl_fields_%s` WHERE `field_id` = %d'",
",",
"$",
"this",
"->",
"_handle",
",",
"General",
"::",
"intval",
"(",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
")",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"row",
")",
")",
"{",
"// Some fields do not create any records in their settings table because they do not",
"// implement a proper `Field::commit()` method.",
"// The base implementation of the commit function only deals with the \"core\"",
"// `tbl_fields` table.",
"// The problem with this approach is that it can lead to data corruption when",
"// saving a field that got deleted by another user.",
"// The only way a field can live without a commit method is if it does not store any",
"// settings at all.",
"// But current version of Symphony assume that the `tbl_fields_$handle` table exists",
"// with at least a `id` and `field_id` column, so field are required to at least create",
"// the table to make their field work without SQL errors from the core.",
"$",
"columns",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchCol",
"(",
"'Field'",
",",
"sprintf",
"(",
"'DESC `tbl_fields_%s`'",
",",
"$",
"this",
"->",
"_handle",
")",
")",
";",
"// The table only has the two required columns, tolerate the missing record",
"$",
"isDefault",
"=",
"count",
"(",
"$",
"columns",
")",
"===",
"2",
"&&",
"in_array",
"(",
"'id'",
",",
"$",
"columns",
")",
"&&",
"in_array",
"(",
"'field_id'",
",",
"$",
"columns",
")",
";",
"if",
"(",
"$",
"isDefault",
")",
"{",
"Symphony",
"::",
"Log",
"(",
")",
"->",
"pushDeprecateWarningToLog",
"(",
"$",
"this",
"->",
"_handle",
",",
"get_class",
"(",
"$",
"this",
")",
",",
"array",
"(",
"'message-format'",
"=>",
"__",
"(",
"'The field `%1$s` does not create settings records in the `tbl_fields_%1$s`.'",
")",
",",
"'alternative-format'",
"=>",
"__",
"(",
"'Please implement the commit function in class `%s`.'",
")",
",",
"'removal-format'",
"=>",
"__",
"(",
"'The compatibility check will will be removed in Symphony %s.'",
")",
",",
"'removal-version'",
"=>",
"'4.0.0'",
",",
")",
")",
";",
"}",
"return",
"$",
"isDefault",
";",
"}",
"return",
"true",
";",
"}"
] | Checks that we are working with a valid field handle and field id, and
checks that the field record exists in the settings table.
@since Symphony 2.7.1 It does check if the settings table only contains
default columns and assume those fields do not require a record in the settings table.
When this situation is detected the field is considered as valid even if no records were
found in the settings table.
@since Symphony 2.7.0
@see Field::tableExists()
@return boolean
true if the field id exists in the table, false otherwise | [
"Checks",
"that",
"we",
"are",
"working",
"with",
"a",
"valid",
"field",
"handle",
"and",
"field",
"id",
"and",
"checks",
"that",
"the",
"field",
"record",
"exists",
"in",
"the",
"settings",
"table",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L1822-L1863 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.entryDataCleanup | public function entryDataCleanup($entry_id, $data = null)
{
$where = is_array($entry_id)
? " `entry_id` IN (" . implode(',', $entry_id) . ") "
: " `entry_id` = '$entry_id' ";
Symphony::Database()->delete('tbl_entries_data_' . $this->get('id'), $where);
return true;
} | php | public function entryDataCleanup($entry_id, $data = null)
{
$where = is_array($entry_id)
? " `entry_id` IN (" . implode(',', $entry_id) . ") "
: " `entry_id` = '$entry_id' ";
Symphony::Database()->delete('tbl_entries_data_' . $this->get('id'), $where);
return true;
} | [
"public",
"function",
"entryDataCleanup",
"(",
"$",
"entry_id",
",",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"where",
"=",
"is_array",
"(",
"$",
"entry_id",
")",
"?",
"\" `entry_id` IN (\"",
".",
"implode",
"(",
"','",
",",
"$",
"entry_id",
")",
".",
"\") \"",
":",
"\" `entry_id` = '$entry_id' \"",
";",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"delete",
"(",
"'tbl_entries_data_'",
".",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"where",
")",
";",
"return",
"true",
";",
"}"
] | Remove the entry data of this field from the database.
@param integer|array $entry_id
the ID of the entry, or an array of entry ID's to delete.
@param array $data (optional)
The entry data provided for fields to do additional cleanup
This is an optional argument and defaults to null.
@throws DatabaseException
@return boolean
Returns true after the cleanup has been completed | [
"Remove",
"the",
"entry",
"data",
"of",
"this",
"field",
"from",
"the",
"database",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L1877-L1886 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.field.php | Field.findRelatedEntries | public function findRelatedEntries($entry_id, $parent_field_id)
{
try {
$ids = Symphony::Database()->fetchCol('entry_id', sprintf("
SELECT `entry_id`
FROM `tbl_entries_data_%d`
WHERE `relation_id` = %d
AND `entry_id` IS NOT NULL
", $this->get('id'), $entry_id));
} catch (Exception $e) {
return array();
}
return $ids;
} | php | public function findRelatedEntries($entry_id, $parent_field_id)
{
try {
$ids = Symphony::Database()->fetchCol('entry_id', sprintf("
SELECT `entry_id`
FROM `tbl_entries_data_%d`
WHERE `relation_id` = %d
AND `entry_id` IS NOT NULL
", $this->get('id'), $entry_id));
} catch (Exception $e) {
return array();
}
return $ids;
} | [
"public",
"function",
"findRelatedEntries",
"(",
"$",
"entry_id",
",",
"$",
"parent_field_id",
")",
"{",
"try",
"{",
"$",
"ids",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchCol",
"(",
"'entry_id'",
",",
"sprintf",
"(",
"\"\n SELECT `entry_id`\n FROM `tbl_entries_data_%d`\n WHERE `relation_id` = %d\n AND `entry_id` IS NOT NULL\n \"",
",",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"entry_id",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"return",
"$",
"ids",
";",
"}"
] | Find related entries from a linking field's data table. Default implementation uses
column names `entry_id` and `relation_id` as with the Select Box Link
@since Symphony 2.5.0
@param integer $entry_id
@param integer $parent_field_id
@return array | [
"Find",
"related",
"entries",
"from",
"a",
"linking",
"field",
"s",
"data",
"table",
".",
"Default",
"implementation",
"uses",
"column",
"names",
"entry_id",
"and",
"relation_id",
"as",
"with",
"the",
"Select",
"Box",
"Link"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.field.php#L1954-L1968 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.add | public static function add(array $fields)
{
if (!isset($fields['sortorder'])) {
$fields['sortorder'] = self::fetchNextSortOrder();
}
if (!Symphony::Database()->insert($fields, 'tbl_pages')) {
return false;
}
return Symphony::Database()->getInsertID();
} | php | public static function add(array $fields)
{
if (!isset($fields['sortorder'])) {
$fields['sortorder'] = self::fetchNextSortOrder();
}
if (!Symphony::Database()->insert($fields, 'tbl_pages')) {
return false;
}
return Symphony::Database()->getInsertID();
} | [
"public",
"static",
"function",
"add",
"(",
"array",
"$",
"fields",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"fields",
"[",
"'sortorder'",
"]",
")",
")",
"{",
"$",
"fields",
"[",
"'sortorder'",
"]",
"=",
"self",
"::",
"fetchNextSortOrder",
"(",
")",
";",
"}",
"if",
"(",
"!",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"insert",
"(",
"$",
"fields",
",",
"'tbl_pages'",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"getInsertID",
"(",
")",
";",
"}"
] | Given an associative array of data, where the key is the column name
in `tbl_pages` and the value is the data, this function will create a new
Page and return a Page ID on success.
@param array $fields
Associative array of field names => values for the Page
@throws DatabaseException
@return integer|boolean
Returns the Page ID of the created Page on success, false otherwise. | [
"Given",
"an",
"associative",
"array",
"of",
"data",
"where",
"the",
"key",
"is",
"the",
"column",
"name",
"in",
"tbl_pages",
"and",
"the",
"value",
"is",
"the",
"data",
"this",
"function",
"will",
"create",
"a",
"new",
"Page",
"and",
"return",
"a",
"Page",
"ID",
"on",
"success",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L28-L39 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.fetchTitleFromHandle | public static function fetchTitleFromHandle($handle)
{
return Symphony::Database()->fetchVar('title', 0, sprintf(
"SELECT `title`
FROM `tbl_pages`
WHERE `handle` = '%s'
LIMIT 1",
Symphony::Database()->cleanValue($handle)
));
} | php | public static function fetchTitleFromHandle($handle)
{
return Symphony::Database()->fetchVar('title', 0, sprintf(
"SELECT `title`
FROM `tbl_pages`
WHERE `handle` = '%s'
LIMIT 1",
Symphony::Database()->cleanValue($handle)
));
} | [
"public",
"static",
"function",
"fetchTitleFromHandle",
"(",
"$",
"handle",
")",
"{",
"return",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchVar",
"(",
"'title'",
",",
"0",
",",
"sprintf",
"(",
"\"SELECT `title`\n FROM `tbl_pages`\n WHERE `handle` = '%s'\n LIMIT 1\"",
",",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"cleanValue",
"(",
"$",
"handle",
")",
")",
")",
";",
"}"
] | Return a Page title by the handle
@param string $handle
The handle of the page
@return integer
The Page title | [
"Return",
"a",
"Page",
"title",
"by",
"the",
"handle"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L49-L58 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.fetchIDFromHandle | public static function fetchIDFromHandle($handle)
{
return Symphony::Database()->fetchVar('id', 0, sprintf(
"SELECT `id`
FROM `tbl_pages`
WHERE `handle` = '%s'
LIMIT 1",
Symphony::Database()->cleanValue($handle)
));
} | php | public static function fetchIDFromHandle($handle)
{
return Symphony::Database()->fetchVar('id', 0, sprintf(
"SELECT `id`
FROM `tbl_pages`
WHERE `handle` = '%s'
LIMIT 1",
Symphony::Database()->cleanValue($handle)
));
} | [
"public",
"static",
"function",
"fetchIDFromHandle",
"(",
"$",
"handle",
")",
"{",
"return",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchVar",
"(",
"'id'",
",",
"0",
",",
"sprintf",
"(",
"\"SELECT `id`\n FROM `tbl_pages`\n WHERE `handle` = '%s'\n LIMIT 1\"",
",",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"cleanValue",
"(",
"$",
"handle",
")",
")",
")",
";",
"}"
] | Return a Page ID by the handle
@param string $handle
The handle of the page
@return integer
The Page ID | [
"Return",
"a",
"Page",
"ID",
"by",
"the",
"handle"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L68-L77 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.addPageTypesToPage | public static function addPageTypesToPage($page_id = null, array $types)
{
if (is_null($page_id)) {
return false;
}
PageManager::deletePageTypes($page_id);
foreach ($types as $type) {
Symphony::Database()->insert(
array(
'page_id' => $page_id,
'type' => $type
),
'tbl_pages_types'
);
}
return true;
} | php | public static function addPageTypesToPage($page_id = null, array $types)
{
if (is_null($page_id)) {
return false;
}
PageManager::deletePageTypes($page_id);
foreach ($types as $type) {
Symphony::Database()->insert(
array(
'page_id' => $page_id,
'type' => $type
),
'tbl_pages_types'
);
}
return true;
} | [
"public",
"static",
"function",
"addPageTypesToPage",
"(",
"$",
"page_id",
"=",
"null",
",",
"array",
"$",
"types",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"page_id",
")",
")",
"{",
"return",
"false",
";",
"}",
"PageManager",
"::",
"deletePageTypes",
"(",
"$",
"page_id",
")",
";",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"insert",
"(",
"array",
"(",
"'page_id'",
"=>",
"$",
"page_id",
",",
"'type'",
"=>",
"$",
"type",
")",
",",
"'tbl_pages_types'",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Given a Page ID and an array of types, this function will add Page types
to that Page. If a Page types are stored in `tbl_pages_types`.
@param integer $page_id
The Page ID to add the Types to
@param array $types
An array of page types
@throws DatabaseException
@return boolean | [
"Given",
"a",
"Page",
"ID",
"and",
"an",
"array",
"of",
"types",
"this",
"function",
"will",
"add",
"Page",
"types",
"to",
"that",
"Page",
".",
"If",
"a",
"Page",
"types",
"are",
"stored",
"in",
"tbl_pages_types",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L90-L109 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.createPageFiles | public static function createPageFiles($new_path, $new_handle, $old_path = null, $old_handle = null)
{
$new = PageManager::resolvePageFileLocation($new_path, $new_handle);
$old = PageManager::resolvePageFileLocation($old_path, $old_handle);
// Nothing to do:
if (file_exists($new) && $new == $old) {
return true;
}
// Old file doesn't exist, use template:
if (!file_exists($old)) {
$data = file_get_contents(self::getTemplate('blueprints.page'));
} else {
$data = file_get_contents($old);
}
/**
* Just before a Page Template is about to be created & written to disk
*
* @delegate PageTemplatePreCreate
* @since Symphony 2.2.2
* @param string $context
* '/blueprints/pages/'
* @param string $file
* The path to the Page Template file
* @param string $contents
* The contents of the `$data`, passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('PageTemplatePreCreate', '/blueprints/pages/', array('file' => $new, 'contents' => &$data));
if (PageManager::writePageFiles($new, $data)) {
// Remove the old file, in the case of a rename
General::deleteFile($old);
/**
* Just after a Page Template is saved after been created.
*
* @delegate PageTemplatePostCreate
* @since Symphony 2.2.2
* @param string $context
* '/blueprints/pages/'
* @param string $file
* The path to the Page Template file
*/
Symphony::ExtensionManager()->notifyMembers('PageTemplatePostCreate', '/blueprints/pages/', array('file' => $new));
return true;
}
return false;
} | php | public static function createPageFiles($new_path, $new_handle, $old_path = null, $old_handle = null)
{
$new = PageManager::resolvePageFileLocation($new_path, $new_handle);
$old = PageManager::resolvePageFileLocation($old_path, $old_handle);
// Nothing to do:
if (file_exists($new) && $new == $old) {
return true;
}
// Old file doesn't exist, use template:
if (!file_exists($old)) {
$data = file_get_contents(self::getTemplate('blueprints.page'));
} else {
$data = file_get_contents($old);
}
/**
* Just before a Page Template is about to be created & written to disk
*
* @delegate PageTemplatePreCreate
* @since Symphony 2.2.2
* @param string $context
* '/blueprints/pages/'
* @param string $file
* The path to the Page Template file
* @param string $contents
* The contents of the `$data`, passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('PageTemplatePreCreate', '/blueprints/pages/', array('file' => $new, 'contents' => &$data));
if (PageManager::writePageFiles($new, $data)) {
// Remove the old file, in the case of a rename
General::deleteFile($old);
/**
* Just after a Page Template is saved after been created.
*
* @delegate PageTemplatePostCreate
* @since Symphony 2.2.2
* @param string $context
* '/blueprints/pages/'
* @param string $file
* The path to the Page Template file
*/
Symphony::ExtensionManager()->notifyMembers('PageTemplatePostCreate', '/blueprints/pages/', array('file' => $new));
return true;
}
return false;
} | [
"public",
"static",
"function",
"createPageFiles",
"(",
"$",
"new_path",
",",
"$",
"new_handle",
",",
"$",
"old_path",
"=",
"null",
",",
"$",
"old_handle",
"=",
"null",
")",
"{",
"$",
"new",
"=",
"PageManager",
"::",
"resolvePageFileLocation",
"(",
"$",
"new_path",
",",
"$",
"new_handle",
")",
";",
"$",
"old",
"=",
"PageManager",
"::",
"resolvePageFileLocation",
"(",
"$",
"old_path",
",",
"$",
"old_handle",
")",
";",
"// Nothing to do:",
"if",
"(",
"file_exists",
"(",
"$",
"new",
")",
"&&",
"$",
"new",
"==",
"$",
"old",
")",
"{",
"return",
"true",
";",
"}",
"// Old file doesn't exist, use template:",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"old",
")",
")",
"{",
"$",
"data",
"=",
"file_get_contents",
"(",
"self",
"::",
"getTemplate",
"(",
"'blueprints.page'",
")",
")",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"file_get_contents",
"(",
"$",
"old",
")",
";",
"}",
"/**\n * Just before a Page Template is about to be created & written to disk\n *\n * @delegate PageTemplatePreCreate\n * @since Symphony 2.2.2\n * @param string $context\n * '/blueprints/pages/'\n * @param string $file\n * The path to the Page Template file\n * @param string $contents\n * The contents of the `$data`, passed by reference\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'PageTemplatePreCreate'",
",",
"'/blueprints/pages/'",
",",
"array",
"(",
"'file'",
"=>",
"$",
"new",
",",
"'contents'",
"=>",
"&",
"$",
"data",
")",
")",
";",
"if",
"(",
"PageManager",
"::",
"writePageFiles",
"(",
"$",
"new",
",",
"$",
"data",
")",
")",
"{",
"// Remove the old file, in the case of a rename",
"General",
"::",
"deleteFile",
"(",
"$",
"old",
")",
";",
"/**\n * Just after a Page Template is saved after been created.\n *\n * @delegate PageTemplatePostCreate\n * @since Symphony 2.2.2\n * @param string $context\n * '/blueprints/pages/'\n * @param string $file\n * The path to the Page Template file\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'PageTemplatePostCreate'",
",",
"'/blueprints/pages/'",
",",
"array",
"(",
"'file'",
"=>",
"$",
"new",
")",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | This function creates the initial `.xsl` template for the page, whether
that be from the `TEMPLATES/blueprints.page.xsl` file, or from an existing
template with the same name. This function will handle the renaming of a page
by creating the new files using the old files as the templates then removing
the old template. If a template already exists for a Page, it will not
be overridden and the function will return true.
@see toolkit.PageManager#resolvePageFileLocation()
@see toolkit.PageManager#createHandle()
@param string $new_path
The path of the Page, which is the handles of the Page parents. If the
page has multiple parents, they will be separated by a forward slash.
eg. article/read. If a page has no parents, this parameter should be null.
@param string $new_handle
The new Page handle, generated using `PageManager::createHandle`.
@param string $old_path (optional)
This parameter is only required when renaming a Page. It should be the 'old
path' before the Page was renamed.
@param string $old_handle (optional)
This parameter is only required when renaming a Page. It should be the 'old
handle' before the Page was renamed.
@throws Exception
@return boolean
true when the page files have been created successfully, false otherwise. | [
"This",
"function",
"creates",
"the",
"initial",
".",
"xsl",
"template",
"for",
"the",
"page",
"whether",
"that",
"be",
"from",
"the",
"TEMPLATES",
"/",
"blueprints",
".",
"page",
".",
"xsl",
"file",
"or",
"from",
"an",
"existing",
"template",
"with",
"the",
"same",
"name",
".",
"This",
"function",
"will",
"handle",
"the",
"renaming",
"of",
"a",
"page",
"by",
"creating",
"the",
"new",
"files",
"using",
"the",
"old",
"files",
"as",
"the",
"templates",
"then",
"removing",
"the",
"old",
"template",
".",
"If",
"a",
"template",
"already",
"exists",
"for",
"a",
"Page",
"it",
"will",
"not",
"be",
"overridden",
"and",
"the",
"function",
"will",
"return",
"true",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L163-L214 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.writePageFiles | public static function writePageFiles($path, $data)
{
return General::writeFile($path, $data, Symphony::Configuration()->get('write_mode', 'file'));
} | php | public static function writePageFiles($path, $data)
{
return General::writeFile($path, $data, Symphony::Configuration()->get('write_mode', 'file'));
} | [
"public",
"static",
"function",
"writePageFiles",
"(",
"$",
"path",
",",
"$",
"data",
")",
"{",
"return",
"General",
"::",
"writeFile",
"(",
"$",
"path",
",",
"$",
"data",
",",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'write_mode'",
",",
"'file'",
")",
")",
";",
"}"
] | A wrapper for `General::writeFile`, this function takes a `$path`
and a `$data` and writes the new template to disk.
@param string $path
The path to write the template to
@param string $data
The contents of the template
@return boolean
true when written successfully, false otherwise | [
"A",
"wrapper",
"for",
"General",
"::",
"writeFile",
"this",
"function",
"takes",
"a",
"$path",
"and",
"a",
"$data",
"and",
"writes",
"the",
"new",
"template",
"to",
"disk",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L227-L230 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.edit | public static function edit($page_id, array $fields, $delete_types = false)
{
if (!is_numeric($page_id)) {
return false;
}
if (isset($fields['id'])) {
unset($fields['id']);
}
if (Symphony::Database()->update($fields, 'tbl_pages', sprintf("`id` = %d", $page_id))) {
// If set, this will clear the page's types.
if ($delete_types) {
PageManager::deletePageTypes($page_id);
}
return true;
} else {
return false;
}
} | php | public static function edit($page_id, array $fields, $delete_types = false)
{
if (!is_numeric($page_id)) {
return false;
}
if (isset($fields['id'])) {
unset($fields['id']);
}
if (Symphony::Database()->update($fields, 'tbl_pages', sprintf("`id` = %d", $page_id))) {
// If set, this will clear the page's types.
if ($delete_types) {
PageManager::deletePageTypes($page_id);
}
return true;
} else {
return false;
}
} | [
"public",
"static",
"function",
"edit",
"(",
"$",
"page_id",
",",
"array",
"$",
"fields",
",",
"$",
"delete_types",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"page_id",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"fields",
"[",
"'id'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"fields",
"[",
"'id'",
"]",
")",
";",
"}",
"if",
"(",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"update",
"(",
"$",
"fields",
",",
"'tbl_pages'",
",",
"sprintf",
"(",
"\"`id` = %d\"",
",",
"$",
"page_id",
")",
")",
")",
"{",
"// If set, this will clear the page's types.",
"if",
"(",
"$",
"delete_types",
")",
"{",
"PageManager",
"::",
"deletePageTypes",
"(",
"$",
"page_id",
")",
";",
"}",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | This function will update a Page in `tbl_pages` given a `$page_id`
and an associative array of `$fields`. A third parameter, `$delete_types`
will also delete the Page's associated Page Types if passed true.
@see toolkit.PageManager#addPageTypesToPage()
@param integer $page_id
The ID of the Page that should be updated
@param array $fields
Associative array of field names => values for the Page.
This array does need to contain every value for the Page, it
can just be the changed values.
@param boolean $delete_types
If true, this parameter will cause the Page Types of the Page to
be deleted. By default this is false.
@return boolean | [
"This",
"function",
"will",
"update",
"a",
"Page",
"in",
"tbl_pages",
"given",
"a",
"$page_id",
"and",
"an",
"associative",
"array",
"of",
"$fields",
".",
"A",
"third",
"parameter",
"$delete_types",
"will",
"also",
"delete",
"the",
"Page",
"s",
"associated",
"Page",
"Types",
"if",
"passed",
"true",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L249-L269 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.editPageChildren | public static function editPageChildren($page_id = null, $page_path = null)
{
if (!is_int($page_id)) {
return false;
}
$page_path = trim($page_path, '/');
$children = PageManager::fetchChildPages($page_id);
foreach ($children as $child) {
$child_id = (int)$child['id'];
$fields = array(
'path' => $page_path
);
if (!PageManager::createPageFiles($page_path, $child['handle'], $child['path'], $child['handle'])) {
$success = false;
}
if (!PageManager::edit($child_id, $fields)) {
$success = false;
}
$success = PageManager::editPageChildren($child_id, $page_path . '/' . $child['handle']);
}
return $success;
} | php | public static function editPageChildren($page_id = null, $page_path = null)
{
if (!is_int($page_id)) {
return false;
}
$page_path = trim($page_path, '/');
$children = PageManager::fetchChildPages($page_id);
foreach ($children as $child) {
$child_id = (int)$child['id'];
$fields = array(
'path' => $page_path
);
if (!PageManager::createPageFiles($page_path, $child['handle'], $child['path'], $child['handle'])) {
$success = false;
}
if (!PageManager::edit($child_id, $fields)) {
$success = false;
}
$success = PageManager::editPageChildren($child_id, $page_path . '/' . $child['handle']);
}
return $success;
} | [
"public",
"static",
"function",
"editPageChildren",
"(",
"$",
"page_id",
"=",
"null",
",",
"$",
"page_path",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"page_id",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"page_path",
"=",
"trim",
"(",
"$",
"page_path",
",",
"'/'",
")",
";",
"$",
"children",
"=",
"PageManager",
"::",
"fetchChildPages",
"(",
"$",
"page_id",
")",
";",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"child_id",
"=",
"(",
"int",
")",
"$",
"child",
"[",
"'id'",
"]",
";",
"$",
"fields",
"=",
"array",
"(",
"'path'",
"=>",
"$",
"page_path",
")",
";",
"if",
"(",
"!",
"PageManager",
"::",
"createPageFiles",
"(",
"$",
"page_path",
",",
"$",
"child",
"[",
"'handle'",
"]",
",",
"$",
"child",
"[",
"'path'",
"]",
",",
"$",
"child",
"[",
"'handle'",
"]",
")",
")",
"{",
"$",
"success",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"PageManager",
"::",
"edit",
"(",
"$",
"child_id",
",",
"$",
"fields",
")",
")",
"{",
"$",
"success",
"=",
"false",
";",
"}",
"$",
"success",
"=",
"PageManager",
"::",
"editPageChildren",
"(",
"$",
"child_id",
",",
"$",
"page_path",
".",
"'/'",
".",
"$",
"child",
"[",
"'handle'",
"]",
")",
";",
"}",
"return",
"$",
"success",
";",
"}"
] | This function will update all children of a particular page (if any)
by renaming/moving all related files to their new path and updating
their database information. This is a recursive function and will work
to any depth.
@param integer $page_id
The ID of the Page whose children need to be updated
@param string $page_path
The path of the Page, which is the handles of the Page parents. If the
page has multiple parents, they will be separated by a forward slash.
eg. article/read. If a page has no parents, this parameter should be null.
@throws Exception
@return boolean | [
"This",
"function",
"will",
"update",
"all",
"children",
"of",
"a",
"particular",
"page",
"(",
"if",
"any",
")",
"by",
"renaming",
"/",
"moving",
"all",
"related",
"files",
"to",
"their",
"new",
"path",
"and",
"updating",
"their",
"database",
"information",
".",
"This",
"is",
"a",
"recursive",
"function",
"and",
"will",
"work",
"to",
"any",
"depth",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L286-L313 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.delete | public static function delete($page_id = null, $delete_files = true)
{
if (!is_int($page_id)) {
return false;
}
$can_proceed = true;
// Delete Files (if told to)
if ($delete_files) {
$page = PageManager::fetchPageByID($page_id, array('path', 'handle'));
if (empty($page)) {
return false;
}
$can_proceed = PageManager::deletePageFiles($page['path'], $page['handle']);
}
// Delete from tbl_pages/tbl_page_types
if ($can_proceed) {
PageManager::deletePageTypes($page_id);
Symphony::Database()->delete('tbl_pages', sprintf(" `id` = %d ", $page_id));
Symphony::Database()->query(sprintf(
"UPDATE
tbl_pages
SET
`sortorder` = (`sortorder` + 1)
WHERE
`sortorder` < %d",
$page_id
));
}
return $can_proceed;
} | php | public static function delete($page_id = null, $delete_files = true)
{
if (!is_int($page_id)) {
return false;
}
$can_proceed = true;
// Delete Files (if told to)
if ($delete_files) {
$page = PageManager::fetchPageByID($page_id, array('path', 'handle'));
if (empty($page)) {
return false;
}
$can_proceed = PageManager::deletePageFiles($page['path'], $page['handle']);
}
// Delete from tbl_pages/tbl_page_types
if ($can_proceed) {
PageManager::deletePageTypes($page_id);
Symphony::Database()->delete('tbl_pages', sprintf(" `id` = %d ", $page_id));
Symphony::Database()->query(sprintf(
"UPDATE
tbl_pages
SET
`sortorder` = (`sortorder` + 1)
WHERE
`sortorder` < %d",
$page_id
));
}
return $can_proceed;
} | [
"public",
"static",
"function",
"delete",
"(",
"$",
"page_id",
"=",
"null",
",",
"$",
"delete_files",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"page_id",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"can_proceed",
"=",
"true",
";",
"// Delete Files (if told to)",
"if",
"(",
"$",
"delete_files",
")",
"{",
"$",
"page",
"=",
"PageManager",
"::",
"fetchPageByID",
"(",
"$",
"page_id",
",",
"array",
"(",
"'path'",
",",
"'handle'",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"page",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"can_proceed",
"=",
"PageManager",
"::",
"deletePageFiles",
"(",
"$",
"page",
"[",
"'path'",
"]",
",",
"$",
"page",
"[",
"'handle'",
"]",
")",
";",
"}",
"// Delete from tbl_pages/tbl_page_types",
"if",
"(",
"$",
"can_proceed",
")",
"{",
"PageManager",
"::",
"deletePageTypes",
"(",
"$",
"page_id",
")",
";",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"delete",
"(",
"'tbl_pages'",
",",
"sprintf",
"(",
"\" `id` = %d \"",
",",
"$",
"page_id",
")",
")",
";",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"query",
"(",
"sprintf",
"(",
"\"UPDATE\n tbl_pages\n SET\n `sortorder` = (`sortorder` + 1)\n WHERE\n `sortorder` < %d\"",
",",
"$",
"page_id",
")",
")",
";",
"}",
"return",
"$",
"can_proceed",
";",
"}"
] | This function takes a Page ID and removes the Page from the database
in `tbl_pages` and it's associated Page Types in `tbl_pages_types`.
This function does not delete any of the Page's children.
@see toolkit.PageManager#deletePageTypes
@see toolkit.PageManager#deletePageFiles
@param integer $page_id
The ID of the Page that should be deleted.
@param boolean $delete_files
If true, this parameter will remove the Page's templates from the
the filesystem. By default this is true.
@throws DatabaseException
@throws Exception
@return boolean | [
"This",
"function",
"takes",
"a",
"Page",
"ID",
"and",
"removes",
"the",
"Page",
"from",
"the",
"database",
"in",
"tbl_pages",
"and",
"it",
"s",
"associated",
"Page",
"Types",
"in",
"tbl_pages_types",
".",
"This",
"function",
"does",
"not",
"delete",
"any",
"of",
"the",
"Page",
"s",
"children",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L331-L366 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.deletePageTypes | public static function deletePageTypes($page_id = null)
{
if (is_null($page_id)) {
return false;
}
return Symphony::Database()->delete('tbl_pages_types', sprintf(" `page_id` = %d ", $page_id));
} | php | public static function deletePageTypes($page_id = null)
{
if (is_null($page_id)) {
return false;
}
return Symphony::Database()->delete('tbl_pages_types', sprintf(" `page_id` = %d ", $page_id));
} | [
"public",
"static",
"function",
"deletePageTypes",
"(",
"$",
"page_id",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"page_id",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"delete",
"(",
"'tbl_pages_types'",
",",
"sprintf",
"(",
"\" `page_id` = %d \"",
",",
"$",
"page_id",
")",
")",
";",
"}"
] | Given a `$page_id`, this function will remove all associated
Page Types from `tbl_pages_types`.
@param integer $page_id
The ID of the Page that should be deleted.
@throws DatabaseException
@return boolean | [
"Given",
"a",
"$page_id",
"this",
"function",
"will",
"remove",
"all",
"associated",
"Page",
"Types",
"from",
"tbl_pages_types",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L377-L384 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.deletePageFiles | public static function deletePageFiles($page_path, $handle)
{
$file = PageManager::resolvePageFileLocation($page_path, $handle);
// Nothing to do:
if (!file_exists($file)) {
return true;
}
// Delete it:
if (General::deleteFile($file)) {
return true;
}
return false;
} | php | public static function deletePageFiles($page_path, $handle)
{
$file = PageManager::resolvePageFileLocation($page_path, $handle);
// Nothing to do:
if (!file_exists($file)) {
return true;
}
// Delete it:
if (General::deleteFile($file)) {
return true;
}
return false;
} | [
"public",
"static",
"function",
"deletePageFiles",
"(",
"$",
"page_path",
",",
"$",
"handle",
")",
"{",
"$",
"file",
"=",
"PageManager",
"::",
"resolvePageFileLocation",
"(",
"$",
"page_path",
",",
"$",
"handle",
")",
";",
"// Nothing to do:",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"return",
"true",
";",
"}",
"// Delete it:",
"if",
"(",
"General",
"::",
"deleteFile",
"(",
"$",
"file",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Given a Page's `$path` and `$handle`, this function will remove
it's templates from the `PAGES` directory returning boolean on
completion
@param string $page_path
The path of the Page, which is the handles of the Page parents. If the
page has multiple parents, they will be separated by a forward slash.
eg. article/read. If a page has no parents, this parameter should be null.
@param string $handle
A Page handle, generated using `PageManager::createHandle`.
@throws Exception
@return boolean | [
"Given",
"a",
"Page",
"s",
"$path",
"and",
"$handle",
"this",
"function",
"will",
"remove",
"it",
"s",
"templates",
"from",
"the",
"PAGES",
"directory",
"returning",
"boolean",
"on",
"completion"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L400-L415 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.fetch | public static function fetch($include_types = true, array $select = array(), array $where = array(), $order_by = null, $hierarchical = false)
{
if ($hierarchical) {
$select = array_merge($select, array('id', 'parent'));
}
if (empty($select)) {
$select = array('*');
}
if (is_null($order_by)) {
$order_by = 'sortorder ASC';
}
$pages = Symphony::Database()->fetch(sprintf(
"SELECT
%s
FROM
`tbl_pages` AS p
WHERE
%s
ORDER BY
%s",
implode(',', $select),
empty($where) ? '1' : implode(' AND ', $where),
$order_by
));
// Fetch the Page Types for each page, if required
if ($include_types) {
foreach ($pages as &$page) {
$page['type'] = PageManager::fetchPageTypes($page['id']);
}
}
if ($hierarchical) {
$output = array();
self::__buildTreeView(null, $pages, $output);
$pages = $output;
}
return !empty($pages) ? $pages : array();
} | php | public static function fetch($include_types = true, array $select = array(), array $where = array(), $order_by = null, $hierarchical = false)
{
if ($hierarchical) {
$select = array_merge($select, array('id', 'parent'));
}
if (empty($select)) {
$select = array('*');
}
if (is_null($order_by)) {
$order_by = 'sortorder ASC';
}
$pages = Symphony::Database()->fetch(sprintf(
"SELECT
%s
FROM
`tbl_pages` AS p
WHERE
%s
ORDER BY
%s",
implode(',', $select),
empty($where) ? '1' : implode(' AND ', $where),
$order_by
));
// Fetch the Page Types for each page, if required
if ($include_types) {
foreach ($pages as &$page) {
$page['type'] = PageManager::fetchPageTypes($page['id']);
}
}
if ($hierarchical) {
$output = array();
self::__buildTreeView(null, $pages, $output);
$pages = $output;
}
return !empty($pages) ? $pages : array();
} | [
"public",
"static",
"function",
"fetch",
"(",
"$",
"include_types",
"=",
"true",
",",
"array",
"$",
"select",
"=",
"array",
"(",
")",
",",
"array",
"$",
"where",
"=",
"array",
"(",
")",
",",
"$",
"order_by",
"=",
"null",
",",
"$",
"hierarchical",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"hierarchical",
")",
"{",
"$",
"select",
"=",
"array_merge",
"(",
"$",
"select",
",",
"array",
"(",
"'id'",
",",
"'parent'",
")",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"select",
")",
")",
"{",
"$",
"select",
"=",
"array",
"(",
"'*'",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"order_by",
")",
")",
"{",
"$",
"order_by",
"=",
"'sortorder ASC'",
";",
"}",
"$",
"pages",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetch",
"(",
"sprintf",
"(",
"\"SELECT\n %s\n FROM\n `tbl_pages` AS p\n WHERE\n %s\n ORDER BY\n %s\"",
",",
"implode",
"(",
"','",
",",
"$",
"select",
")",
",",
"empty",
"(",
"$",
"where",
")",
"?",
"'1'",
":",
"implode",
"(",
"' AND '",
",",
"$",
"where",
")",
",",
"$",
"order_by",
")",
")",
";",
"// Fetch the Page Types for each page, if required",
"if",
"(",
"$",
"include_types",
")",
"{",
"foreach",
"(",
"$",
"pages",
"as",
"&",
"$",
"page",
")",
"{",
"$",
"page",
"[",
"'type'",
"]",
"=",
"PageManager",
"::",
"fetchPageTypes",
"(",
"$",
"page",
"[",
"'id'",
"]",
")",
";",
"}",
"}",
"if",
"(",
"$",
"hierarchical",
")",
"{",
"$",
"output",
"=",
"array",
"(",
")",
";",
"self",
"::",
"__buildTreeView",
"(",
"null",
",",
"$",
"pages",
",",
"$",
"output",
")",
";",
"$",
"pages",
"=",
"$",
"output",
";",
"}",
"return",
"!",
"empty",
"(",
"$",
"pages",
")",
"?",
"$",
"pages",
":",
"array",
"(",
")",
";",
"}"
] | This function will return an associative array of Page information. The
information returned is defined by the `$include_types` and `$select`
parameters, which will return the Page Types for the Page and allow
a developer to restrict what information is returned about the Page.
Optionally, `$where` and `$order_by` parameters allow a developer to
further refine their query.
@param boolean $include_types
Whether to include the resulting Page's Page Types in the return array,
under the key `type`. Defaults to true.
@param array $select (optional)
Accepts an array of columns to return from `tbl_pages`. If omitted,
all columns from the table will be returned.
@param array $where (optional)
Accepts an array of WHERE statements that will be appended with AND.
If omitted, all pages will be returned.
@param string $order_by (optional)
Allows a developer to return the Pages in a particular order. The string
passed will be appended to `ORDER BY`. If omitted this will return
Pages ordered by `sortorder`.
@param boolean $hierarchical (optional)
If true, builds a multidimensional array representing the pages hierarchy.
Defaults to false.
@return array|null
An associative array of Page information with the key being the column
name from `tbl_pages` and the value being the data. If requested, the array
can be made multidimensional to reflect the pages hierarchy. If no Pages are
found, null is returned. | [
"This",
"function",
"will",
"return",
"an",
"associative",
"array",
"of",
"Page",
"information",
".",
"The",
"information",
"returned",
"is",
"defined",
"by",
"the",
"$include_types",
"and",
"$select",
"parameters",
"which",
"will",
"return",
"the",
"Page",
"Types",
"for",
"the",
"Page",
"and",
"allow",
"a",
"developer",
"to",
"restrict",
"what",
"information",
"is",
"returned",
"about",
"the",
"Page",
".",
"Optionally",
"$where",
"and",
"$order_by",
"parameters",
"allow",
"a",
"developer",
"to",
"further",
"refine",
"their",
"query",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L447-L490 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.fetchPageByID | public static function fetchPageByID($page_id = null, array $select = array())
{
if (is_null($page_id)) {
return null;
}
if (!is_array($page_id)) {
$page_id = array(
Symphony::Database()->cleanValue($page_id)
);
}
if (empty($select)) {
$select = array('*');
}
$page = PageManager::fetch(true, $select, array(
sprintf("id IN (%s)", implode(',', $page_id))
));
return count($page) == 1 ? array_pop($page) : $page;
} | php | public static function fetchPageByID($page_id = null, array $select = array())
{
if (is_null($page_id)) {
return null;
}
if (!is_array($page_id)) {
$page_id = array(
Symphony::Database()->cleanValue($page_id)
);
}
if (empty($select)) {
$select = array('*');
}
$page = PageManager::fetch(true, $select, array(
sprintf("id IN (%s)", implode(',', $page_id))
));
return count($page) == 1 ? array_pop($page) : $page;
} | [
"public",
"static",
"function",
"fetchPageByID",
"(",
"$",
"page_id",
"=",
"null",
",",
"array",
"$",
"select",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"page_id",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"page_id",
")",
")",
"{",
"$",
"page_id",
"=",
"array",
"(",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"cleanValue",
"(",
"$",
"page_id",
")",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"select",
")",
")",
"{",
"$",
"select",
"=",
"array",
"(",
"'*'",
")",
";",
"}",
"$",
"page",
"=",
"PageManager",
"::",
"fetch",
"(",
"true",
",",
"$",
"select",
",",
"array",
"(",
"sprintf",
"(",
"\"id IN (%s)\"",
",",
"implode",
"(",
"','",
",",
"$",
"page_id",
")",
")",
")",
")",
";",
"return",
"count",
"(",
"$",
"page",
")",
"==",
"1",
"?",
"array_pop",
"(",
"$",
"page",
")",
":",
"$",
"page",
";",
"}"
] | Returns Pages that match the given `$page_id`. Developers can optionally
choose to specify what Page information is returned using the `$select`
parameter.
@param integer|array $page_id
The ID of the Page, or an array of ID's
@param array $select (optional)
Accepts an array of columns to return from `tbl_pages`. If omitted,
all columns from the table will be returned.
@return array|null
An associative array of Page information with the key being the column
name from `tbl_pages` and the value being the data. If multiple Pages
are found, an array of Pages will be returned. If no Pages are found
null is returned. | [
"Returns",
"Pages",
"that",
"match",
"the",
"given",
"$page_id",
".",
"Developers",
"can",
"optionally",
"choose",
"to",
"specify",
"what",
"Page",
"information",
"is",
"returned",
"using",
"the",
"$select",
"parameter",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L523-L544 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.fetchPageByType | public static function fetchPageByType($type = null)
{
if (is_null($type)) {
return PageManager::fetch();
}
$pages = Symphony::Database()->fetch(sprintf(
"SELECT
`p`.*
FROM
`tbl_pages` AS `p`
LEFT JOIN
`tbl_pages_types` AS `pt` ON (p.id = pt.page_id)
WHERE
`pt`.type = '%s'",
Symphony::Database()->cleanValue($type)
));
return count($pages) == 1 ? array_pop($pages) : $pages;
} | php | public static function fetchPageByType($type = null)
{
if (is_null($type)) {
return PageManager::fetch();
}
$pages = Symphony::Database()->fetch(sprintf(
"SELECT
`p`.*
FROM
`tbl_pages` AS `p`
LEFT JOIN
`tbl_pages_types` AS `pt` ON (p.id = pt.page_id)
WHERE
`pt`.type = '%s'",
Symphony::Database()->cleanValue($type)
));
return count($pages) == 1 ? array_pop($pages) : $pages;
} | [
"public",
"static",
"function",
"fetchPageByType",
"(",
"$",
"type",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"type",
")",
")",
"{",
"return",
"PageManager",
"::",
"fetch",
"(",
")",
";",
"}",
"$",
"pages",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetch",
"(",
"sprintf",
"(",
"\"SELECT\n `p`.*\n FROM\n `tbl_pages` AS `p`\n LEFT JOIN\n `tbl_pages_types` AS `pt` ON (p.id = pt.page_id)\n WHERE\n `pt`.type = '%s'\"",
",",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"cleanValue",
"(",
"$",
"type",
")",
")",
")",
";",
"return",
"count",
"(",
"$",
"pages",
")",
"==",
"1",
"?",
"array_pop",
"(",
"$",
"pages",
")",
":",
"$",
"pages",
";",
"}"
] | Returns Pages that match the given `$type`. If no `$type` is provided
the function returns the result of `PageManager::fetch`.
@param string $type
Where the type is one of the available Page Types.
@return array|null
An associative array of Page information with the key being the column
name from `tbl_pages` and the value being the data. If multiple Pages
are found, an array of Pages will be returned. If no Pages are found
null is returned. | [
"Returns",
"Pages",
"that",
"match",
"the",
"given",
"$type",
".",
"If",
"no",
"$type",
"is",
"provided",
"the",
"function",
"returns",
"the",
"result",
"of",
"PageManager",
"::",
"fetch",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L558-L577 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.fetchChildPages | public static function fetchChildPages($page_id = null, array $select = array())
{
if (is_null($page_id)) {
return null;
}
if (empty($select)) {
$select = array('*');
}
return PageManager::fetch(false, $select, array(
sprintf('id != %d', $page_id),
sprintf('parent = %d', $page_id)
));
} | php | public static function fetchChildPages($page_id = null, array $select = array())
{
if (is_null($page_id)) {
return null;
}
if (empty($select)) {
$select = array('*');
}
return PageManager::fetch(false, $select, array(
sprintf('id != %d', $page_id),
sprintf('parent = %d', $page_id)
));
} | [
"public",
"static",
"function",
"fetchChildPages",
"(",
"$",
"page_id",
"=",
"null",
",",
"array",
"$",
"select",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"page_id",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"select",
")",
")",
"{",
"$",
"select",
"=",
"array",
"(",
"'*'",
")",
";",
"}",
"return",
"PageManager",
"::",
"fetch",
"(",
"false",
",",
"$",
"select",
",",
"array",
"(",
"sprintf",
"(",
"'id != %d'",
",",
"$",
"page_id",
")",
",",
"sprintf",
"(",
"'parent = %d'",
",",
"$",
"page_id",
")",
")",
")",
";",
"}"
] | Returns the child Pages (if any) of the given `$page_id`.
@param integer $page_id
The ID of the Page.
@param array $select (optional)
Accepts an array of columns to return from `tbl_pages`. If omitted,
all columns from the table will be returned.
@return array|null
An associative array of Page information with the key being the column
name from `tbl_pages` and the value being the data. If multiple Pages
are found, an array of Pages will be returned. If no Pages are found
null is returned. | [
"Returns",
"the",
"child",
"Pages",
"(",
"if",
"any",
")",
"of",
"the",
"given",
"$page_id",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L593-L607 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.fetchPageTypes | public static function fetchPageTypes($page_id = null)
{
return Symphony::Database()->fetchCol('type', sprintf(
"SELECT
type
FROM
`tbl_pages_types` AS pt
WHERE
%s
GROUP BY
pt.type
ORDER BY
pt.type ASC",
(is_null($page_id) ? '1' : sprintf('pt.page_id = %d', $page_id))
));
} | php | public static function fetchPageTypes($page_id = null)
{
return Symphony::Database()->fetchCol('type', sprintf(
"SELECT
type
FROM
`tbl_pages_types` AS pt
WHERE
%s
GROUP BY
pt.type
ORDER BY
pt.type ASC",
(is_null($page_id) ? '1' : sprintf('pt.page_id = %d', $page_id))
));
} | [
"public",
"static",
"function",
"fetchPageTypes",
"(",
"$",
"page_id",
"=",
"null",
")",
"{",
"return",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchCol",
"(",
"'type'",
",",
"sprintf",
"(",
"\"SELECT\n type\n FROM\n `tbl_pages_types` AS pt\n WHERE\n %s\n GROUP BY\n pt.type\n ORDER BY\n pt.type ASC\"",
",",
"(",
"is_null",
"(",
"$",
"page_id",
")",
"?",
"'1'",
":",
"sprintf",
"(",
"'pt.page_id = %d'",
",",
"$",
"page_id",
")",
")",
")",
")",
";",
"}"
] | This function returns a Page's Page Types. If the `$page_id`
parameter is given, the types returned will be for that Page.
@param integer $page_id
The ID of the Page.
@return array
An array of the Page Types | [
"This",
"function",
"returns",
"a",
"Page",
"s",
"Page",
"Types",
".",
"If",
"the",
"$page_id",
"parameter",
"is",
"given",
"the",
"types",
"returned",
"will",
"be",
"for",
"that",
"Page",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L618-L633 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.fetchAvailablePageTypes | public static function fetchAvailablePageTypes()
{
$system_types = array('index', 'XML', 'JSON', 'admin', '404', '403');
$types = PageManager::fetchPageTypes();
return (!empty($types) ? General::array_remove_duplicates(array_merge($system_types, $types)) : $system_types);
} | php | public static function fetchAvailablePageTypes()
{
$system_types = array('index', 'XML', 'JSON', 'admin', '404', '403');
$types = PageManager::fetchPageTypes();
return (!empty($types) ? General::array_remove_duplicates(array_merge($system_types, $types)) : $system_types);
} | [
"public",
"static",
"function",
"fetchAvailablePageTypes",
"(",
")",
"{",
"$",
"system_types",
"=",
"array",
"(",
"'index'",
",",
"'XML'",
",",
"'JSON'",
",",
"'admin'",
",",
"'404'",
",",
"'403'",
")",
";",
"$",
"types",
"=",
"PageManager",
"::",
"fetchPageTypes",
"(",
")",
";",
"return",
"(",
"!",
"empty",
"(",
"$",
"types",
")",
"?",
"General",
"::",
"array_remove_duplicates",
"(",
"array_merge",
"(",
"$",
"system_types",
",",
"$",
"types",
")",
")",
":",
"$",
"system_types",
")",
";",
"}"
] | Returns all the page types that exist in this Symphony install.
There are 6 default system page types, and new types can be added
by Developers via the Page Editor.
@since Symphony 2.3 introduced the JSON type.
@return array
An array of strings of the page types used in this Symphony
install. At the minimum, this will be an array with the values
'index', 'XML', 'JSON', 'admin', '404' and '403'. | [
"Returns",
"all",
"the",
"page",
"types",
"that",
"exist",
"in",
"this",
"Symphony",
"install",
".",
"There",
"are",
"6",
"default",
"system",
"page",
"types",
"and",
"new",
"types",
"can",
"be",
"added",
"by",
"Developers",
"via",
"the",
"Page",
"Editor",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L646-L653 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.fetchAllPagesPageTypes | public static function fetchAllPagesPageTypes()
{
$types = Symphony::Database()->fetch("SELECT `page_id`,`type` FROM `tbl_pages_types`");
$page_types = array();
if (is_array($types)) {
foreach ($types as $type) {
$page_types[$type['page_id']][] = $type['type'];
}
}
return $page_types;
} | php | public static function fetchAllPagesPageTypes()
{
$types = Symphony::Database()->fetch("SELECT `page_id`,`type` FROM `tbl_pages_types`");
$page_types = array();
if (is_array($types)) {
foreach ($types as $type) {
$page_types[$type['page_id']][] = $type['type'];
}
}
return $page_types;
} | [
"public",
"static",
"function",
"fetchAllPagesPageTypes",
"(",
")",
"{",
"$",
"types",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetch",
"(",
"\"SELECT `page_id`,`type` FROM `tbl_pages_types`\"",
")",
";",
"$",
"page_types",
"=",
"array",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"types",
")",
")",
"{",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"$",
"page_types",
"[",
"$",
"type",
"[",
"'page_id'",
"]",
"]",
"[",
"]",
"=",
"$",
"type",
"[",
"'type'",
"]",
";",
"}",
"}",
"return",
"$",
"page_types",
";",
"}"
] | Fetch an associated array with Page ID's and the types they're using.
@throws DatabaseException
@return array
A 2-dimensional associated array where the key is the page ID. | [
"Fetch",
"an",
"associated",
"array",
"with",
"Page",
"ID",
"s",
"and",
"the",
"types",
"they",
"re",
"using",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L683-L695 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.getChildPagesCount | public static function getChildPagesCount($page_id = null)
{
if (is_null($page_id)) {
return null;
}
$children = PageManager::fetch(false, array('id'), array(
sprintf('parent = %d', $page_id)
));
$count = count($children);
if ($count > 0) {
foreach ($children as $c) {
$count += self::getChildPagesCount($c['id']);
}
}
return $count;
} | php | public static function getChildPagesCount($page_id = null)
{
if (is_null($page_id)) {
return null;
}
$children = PageManager::fetch(false, array('id'), array(
sprintf('parent = %d', $page_id)
));
$count = count($children);
if ($count > 0) {
foreach ($children as $c) {
$count += self::getChildPagesCount($c['id']);
}
}
return $count;
} | [
"public",
"static",
"function",
"getChildPagesCount",
"(",
"$",
"page_id",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"page_id",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"children",
"=",
"PageManager",
"::",
"fetch",
"(",
"false",
",",
"array",
"(",
"'id'",
")",
",",
"array",
"(",
"sprintf",
"(",
"'parent = %d'",
",",
"$",
"page_id",
")",
")",
")",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"children",
")",
";",
"if",
"(",
"$",
"count",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"children",
"as",
"$",
"c",
")",
"{",
"$",
"count",
"+=",
"self",
"::",
"getChildPagesCount",
"(",
"$",
"c",
"[",
"'id'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"count",
";",
"}"
] | This function will return the number of child pages for a given
`$page_id`. This is a recursive function and will return the absolute
count.
@param integer $page_id
The ID of the Page.
@return integer
The number of child pages for the given `$page_id` | [
"This",
"function",
"will",
"return",
"the",
"number",
"of",
"child",
"pages",
"for",
"a",
"given",
"$page_id",
".",
"This",
"is",
"a",
"recursive",
"function",
"and",
"will",
"return",
"the",
"absolute",
"count",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L740-L758 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.hasPageTypeBeenUsed | public static function hasPageTypeBeenUsed($page_id = null, $type)
{
return (boolean)Symphony::Database()->fetchRow(0, sprintf(
"SELECT
pt.id
FROM
`tbl_pages_types` AS pt
WHERE
pt.page_id != %d
AND pt.type = '%s'
LIMIT 1",
$page_id,
Symphony::Database()->cleanValue($type)
));
} | php | public static function hasPageTypeBeenUsed($page_id = null, $type)
{
return (boolean)Symphony::Database()->fetchRow(0, sprintf(
"SELECT
pt.id
FROM
`tbl_pages_types` AS pt
WHERE
pt.page_id != %d
AND pt.type = '%s'
LIMIT 1",
$page_id,
Symphony::Database()->cleanValue($type)
));
} | [
"public",
"static",
"function",
"hasPageTypeBeenUsed",
"(",
"$",
"page_id",
"=",
"null",
",",
"$",
"type",
")",
"{",
"return",
"(",
"boolean",
")",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchRow",
"(",
"0",
",",
"sprintf",
"(",
"\"SELECT\n pt.id\n FROM\n `tbl_pages_types` AS pt\n WHERE\n pt.page_id != %d\n AND pt.type = '%s'\n LIMIT 1\"",
",",
"$",
"page_id",
",",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"cleanValue",
"(",
"$",
"type",
")",
")",
")",
";",
"}"
] | Returns boolean if a the given `$type` has been used by Symphony
for a Page that is not `$page_id`.
@param integer $page_id
The ID of the Page to exclude from the query.
@param string $type
The Page Type to look for in `tbl_page_types`.
@return boolean
true if the type is used, false otherwise | [
"Returns",
"boolean",
"if",
"a",
"the",
"given",
"$type",
"has",
"been",
"used",
"by",
"Symphony",
"for",
"a",
"Page",
"that",
"is",
"not",
"$page_id",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L771-L785 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.resolvePage | public static function resolvePage($page_id, $column)
{
$page = Symphony::Database()->fetchRow(0, sprintf(
"SELECT
p.%s,
p.parent
FROM
`tbl_pages` AS p
WHERE
p.id = %d
OR p.handle = '%s'
LIMIT 1",
$column,
$page_id,
Symphony::Database()->cleanValue($page_id)
));
if (empty($page)) {
return $page;
}
$path = array($page[$column]);
if (!is_null($page['parent'])) {
$next_parent = $page['parent'];
while (
$parent = Symphony::Database()->fetchRow(0, sprintf(
"SELECT
p.%s,
p.parent
FROM
`tbl_pages` AS p
WHERE
p.id = %d",
$column,
$next_parent
))
) {
array_unshift($path, $parent[$column]);
$next_parent = $parent['parent'];
}
}
return $path;
} | php | public static function resolvePage($page_id, $column)
{
$page = Symphony::Database()->fetchRow(0, sprintf(
"SELECT
p.%s,
p.parent
FROM
`tbl_pages` AS p
WHERE
p.id = %d
OR p.handle = '%s'
LIMIT 1",
$column,
$page_id,
Symphony::Database()->cleanValue($page_id)
));
if (empty($page)) {
return $page;
}
$path = array($page[$column]);
if (!is_null($page['parent'])) {
$next_parent = $page['parent'];
while (
$parent = Symphony::Database()->fetchRow(0, sprintf(
"SELECT
p.%s,
p.parent
FROM
`tbl_pages` AS p
WHERE
p.id = %d",
$column,
$next_parent
))
) {
array_unshift($path, $parent[$column]);
$next_parent = $parent['parent'];
}
}
return $path;
} | [
"public",
"static",
"function",
"resolvePage",
"(",
"$",
"page_id",
",",
"$",
"column",
")",
"{",
"$",
"page",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchRow",
"(",
"0",
",",
"sprintf",
"(",
"\"SELECT\n p.%s,\n p.parent\n FROM\n `tbl_pages` AS p\n WHERE\n p.id = %d\n OR p.handle = '%s'\n LIMIT 1\"",
",",
"$",
"column",
",",
"$",
"page_id",
",",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"cleanValue",
"(",
"$",
"page_id",
")",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"page",
")",
")",
"{",
"return",
"$",
"page",
";",
"}",
"$",
"path",
"=",
"array",
"(",
"$",
"page",
"[",
"$",
"column",
"]",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"page",
"[",
"'parent'",
"]",
")",
")",
"{",
"$",
"next_parent",
"=",
"$",
"page",
"[",
"'parent'",
"]",
";",
"while",
"(",
"$",
"parent",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchRow",
"(",
"0",
",",
"sprintf",
"(",
"\"SELECT\n p.%s,\n p.parent\n FROM\n `tbl_pages` AS p\n WHERE\n p.id = %d\"",
",",
"$",
"column",
",",
"$",
"next_parent",
")",
")",
")",
"{",
"array_unshift",
"(",
"$",
"path",
",",
"$",
"parent",
"[",
"$",
"column",
"]",
")",
";",
"$",
"next_parent",
"=",
"$",
"parent",
"[",
"'parent'",
"]",
";",
"}",
"}",
"return",
"$",
"path",
";",
"}"
] | Given the `$page_id` and a `$column`, this function will return an
array of the given `$column` for the Page, including all parents.
@param mixed $page_id
The ID of the Page that currently being viewed, or the handle of the
current Page
@param string $column
@return array
An array of the current Page, containing the `$column`
requested. The current page will be the last item the array, as all
parent pages are prepended to the start of the array | [
"Given",
"the",
"$page_id",
"and",
"a",
"$column",
"this",
"function",
"will",
"return",
"an",
"array",
"of",
"the",
"given",
"$column",
"for",
"the",
"Page",
"including",
"all",
"parents",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L843-L888 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.pagemanager.php | PageManager.resolvePageByPath | public static function resolvePageByPath($handle, $path = false)
{
return Symphony::Database()->fetchRow(0, sprintf(
"SELECT * FROM `tbl_pages` WHERE `path` %s AND `handle` = '%s' LIMIT 1",
($path ? " = '".Symphony::Database()->cleanValue($path)."'" : 'IS NULL'),
Symphony::Database()->cleanValue($handle)
));
} | php | public static function resolvePageByPath($handle, $path = false)
{
return Symphony::Database()->fetchRow(0, sprintf(
"SELECT * FROM `tbl_pages` WHERE `path` %s AND `handle` = '%s' LIMIT 1",
($path ? " = '".Symphony::Database()->cleanValue($path)."'" : 'IS NULL'),
Symphony::Database()->cleanValue($handle)
));
} | [
"public",
"static",
"function",
"resolvePageByPath",
"(",
"$",
"handle",
",",
"$",
"path",
"=",
"false",
")",
"{",
"return",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchRow",
"(",
"0",
",",
"sprintf",
"(",
"\"SELECT * FROM `tbl_pages` WHERE `path` %s AND `handle` = '%s' LIMIT 1\"",
",",
"(",
"$",
"path",
"?",
"\" = '\"",
".",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"cleanValue",
"(",
"$",
"path",
")",
".",
"\"'\"",
":",
"'IS NULL'",
")",
",",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"cleanValue",
"(",
"$",
"handle",
")",
")",
")",
";",
"}"
] | Resolve a page by it's handle and path
@param $handle
The handle of the page
@param boolean $path
The path to the page
@return mixed
Array if found, false if not | [
"Resolve",
"a",
"page",
"by",
"it",
"s",
"handle",
"and",
"path"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.pagemanager.php#L938-L945 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.frontendpage.php | FrontendPage.generate | public function generate($page = null)
{
$full_generate = true;
$devkit = null;
$output = null;
$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 ($this->is_logged_in) {
/**
* Allows a devkit object to be specified, and stop continued execution:
*
* @delegate FrontendDevKitResolve
* @param string $context
* '/frontend/'
* @param boolean $full_generate
* Whether this page will be completely generated (ie. invoke the XSLT transform)
* or not, by default this is true. Passed by reference
* @param mixed $devkit
* Allows a devkit to register to this page
*/
Symphony::ExtensionManager()->notifyMembers('FrontendDevKitResolve', '/frontend/', array(
'full_generate' => &$full_generate,
'devkit' => &$devkit
));
}
Symphony::Profiler()->sample('Page creation started');
$this->_page = $page;
$this->__buildPage();
if ($full_generate) {
/**
* Immediately before generating the page. Provided with the page object, XML and XSLT
* @delegate FrontendOutputPreGenerate
* @param string $context
* '/frontend/'
* @param FrontendPage $page
* This FrontendPage object, by reference
* @param XMLElement $xml
* This pages XML, including the Parameters, Datasource and Event XML, by reference as
* an XMLElement
* @param string $xsl
* This pages XSLT, by reference
*/
Symphony::ExtensionManager()->notifyMembers('FrontendOutputPreGenerate', '/frontend/', array(
'page' => &$this,
'xml' => &$this->_xml,
'xsl' => &$this->_xsl
));
if (is_null($devkit)) {
if (General::in_iarray('XML', $this->_pageData['type'])) {
$this->addHeaderToPage('Content-Type', 'text/xml; charset=utf-8');
} elseif (General::in_iarray('JSON', $this->_pageData['type'])) {
$this->addHeaderToPage('Content-Type', 'application/json; charset=utf-8');
} else {
$this->addHeaderToPage('Content-Type', 'text/html; charset=utf-8');
}
if (in_array('404', $this->_pageData['type'])) {
$this->setHttpStatus(self::HTTP_STATUS_NOT_FOUND);
} elseif (in_array('403', $this->_pageData['type'])) {
$this->setHttpStatus(self::HTTP_STATUS_FORBIDDEN);
}
}
// Lock down the frontend first so that extensions can easily remove these
// headers if desired. RE: #2480
$this->addHeaderToPage('X-Frame-Options', 'SAMEORIGIN');
// Add more http security headers, RE: #2248
$this->addHeaderToPage('X-Content-Type-Options', 'nosniff');
$this->addHeaderToPage('X-XSS-Protection', '1; mode=block');
/**
* This is just prior to the page headers being rendered, and is suitable for changing them
* @delegate FrontendPreRenderHeaders
* @param string $context
* '/frontend/'
*/
Symphony::ExtensionManager()->notifyMembers('FrontendPreRenderHeaders', '/frontend/');
$backup_param = $this->_param;
$this->_param['current-query-string'] = General::wrapInCDATA($this->_param['current-query-string']);
// In Symphony 2.4, the XML structure stays as an object until
// the very last moment.
Symphony::Profiler()->seed(precision_timer());
if ($this->_xml instanceof XMLElement) {
$this->setXML($this->_xml->generate(true, 0));
}
Symphony::Profiler()->sample('XML Generation', PROFILE_LAP);
$output = parent::generate();
$this->_param = $backup_param;
Symphony::Profiler()->sample('XSLT Transformation', PROFILE_LAP);
/**
* Immediately after generating the page. Provided with string containing page source
* @delegate FrontendOutputPostGenerate
* @param string $context
* '/frontend/'
* @param string $output
* The generated output of this page, ie. a string of HTML, passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('FrontendOutputPostGenerate', '/frontend/', array('output' => &$output));
if (is_null($devkit) && !$output) {
$errstr = null;
while (list(, $val) = $this->Proc->getError()) {
$errstr .= 'Line: ' . $val['line'] . ' - ' . $val['message'] . PHP_EOL;
}
Frontend::instance()->throwCustomError(
trim($errstr),
__('XSLT Processing Error'),
Page::HTTP_STATUS_ERROR,
'xslt',
array('proc' => clone $this->Proc)
);
}
Symphony::Profiler()->sample('Page creation complete');
}
if (!is_null($devkit)) {
$devkit->prepare($this, $this->_pageData, $this->_xml, $this->_param, $output);
return $devkit->build();
}
// Display the Event Results in the page source if the user is logged
// into Symphony, the page is not JSON and if it is enabled in the
// configuration.
if ($this->is_logged_in && !General::in_iarray('JSON', $this->_pageData['type']) && Symphony::Configuration()->get('display_event_xml_in_source', 'public') === 'yes') {
$output .= PHP_EOL . '<!-- ' . PHP_EOL . $this->_events_xml->generate(true) . ' -->';
}
return $output;
} | php | public function generate($page = null)
{
$full_generate = true;
$devkit = null;
$output = null;
$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 ($this->is_logged_in) {
/**
* Allows a devkit object to be specified, and stop continued execution:
*
* @delegate FrontendDevKitResolve
* @param string $context
* '/frontend/'
* @param boolean $full_generate
* Whether this page will be completely generated (ie. invoke the XSLT transform)
* or not, by default this is true. Passed by reference
* @param mixed $devkit
* Allows a devkit to register to this page
*/
Symphony::ExtensionManager()->notifyMembers('FrontendDevKitResolve', '/frontend/', array(
'full_generate' => &$full_generate,
'devkit' => &$devkit
));
}
Symphony::Profiler()->sample('Page creation started');
$this->_page = $page;
$this->__buildPage();
if ($full_generate) {
/**
* Immediately before generating the page. Provided with the page object, XML and XSLT
* @delegate FrontendOutputPreGenerate
* @param string $context
* '/frontend/'
* @param FrontendPage $page
* This FrontendPage object, by reference
* @param XMLElement $xml
* This pages XML, including the Parameters, Datasource and Event XML, by reference as
* an XMLElement
* @param string $xsl
* This pages XSLT, by reference
*/
Symphony::ExtensionManager()->notifyMembers('FrontendOutputPreGenerate', '/frontend/', array(
'page' => &$this,
'xml' => &$this->_xml,
'xsl' => &$this->_xsl
));
if (is_null($devkit)) {
if (General::in_iarray('XML', $this->_pageData['type'])) {
$this->addHeaderToPage('Content-Type', 'text/xml; charset=utf-8');
} elseif (General::in_iarray('JSON', $this->_pageData['type'])) {
$this->addHeaderToPage('Content-Type', 'application/json; charset=utf-8');
} else {
$this->addHeaderToPage('Content-Type', 'text/html; charset=utf-8');
}
if (in_array('404', $this->_pageData['type'])) {
$this->setHttpStatus(self::HTTP_STATUS_NOT_FOUND);
} elseif (in_array('403', $this->_pageData['type'])) {
$this->setHttpStatus(self::HTTP_STATUS_FORBIDDEN);
}
}
// Lock down the frontend first so that extensions can easily remove these
// headers if desired. RE: #2480
$this->addHeaderToPage('X-Frame-Options', 'SAMEORIGIN');
// Add more http security headers, RE: #2248
$this->addHeaderToPage('X-Content-Type-Options', 'nosniff');
$this->addHeaderToPage('X-XSS-Protection', '1; mode=block');
/**
* This is just prior to the page headers being rendered, and is suitable for changing them
* @delegate FrontendPreRenderHeaders
* @param string $context
* '/frontend/'
*/
Symphony::ExtensionManager()->notifyMembers('FrontendPreRenderHeaders', '/frontend/');
$backup_param = $this->_param;
$this->_param['current-query-string'] = General::wrapInCDATA($this->_param['current-query-string']);
// In Symphony 2.4, the XML structure stays as an object until
// the very last moment.
Symphony::Profiler()->seed(precision_timer());
if ($this->_xml instanceof XMLElement) {
$this->setXML($this->_xml->generate(true, 0));
}
Symphony::Profiler()->sample('XML Generation', PROFILE_LAP);
$output = parent::generate();
$this->_param = $backup_param;
Symphony::Profiler()->sample('XSLT Transformation', PROFILE_LAP);
/**
* Immediately after generating the page. Provided with string containing page source
* @delegate FrontendOutputPostGenerate
* @param string $context
* '/frontend/'
* @param string $output
* The generated output of this page, ie. a string of HTML, passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('FrontendOutputPostGenerate', '/frontend/', array('output' => &$output));
if (is_null($devkit) && !$output) {
$errstr = null;
while (list(, $val) = $this->Proc->getError()) {
$errstr .= 'Line: ' . $val['line'] . ' - ' . $val['message'] . PHP_EOL;
}
Frontend::instance()->throwCustomError(
trim($errstr),
__('XSLT Processing Error'),
Page::HTTP_STATUS_ERROR,
'xslt',
array('proc' => clone $this->Proc)
);
}
Symphony::Profiler()->sample('Page creation complete');
}
if (!is_null($devkit)) {
$devkit->prepare($this, $this->_pageData, $this->_xml, $this->_param, $output);
return $devkit->build();
}
// Display the Event Results in the page source if the user is logged
// into Symphony, the page is not JSON and if it is enabled in the
// configuration.
if ($this->is_logged_in && !General::in_iarray('JSON', $this->_pageData['type']) && Symphony::Configuration()->get('display_event_xml_in_source', 'public') === 'yes') {
$output .= PHP_EOL . '<!-- ' . PHP_EOL . $this->_events_xml->generate(true) . ' -->';
}
return $output;
} | [
"public",
"function",
"generate",
"(",
"$",
"page",
"=",
"null",
")",
"{",
"$",
"full_generate",
"=",
"true",
";",
"$",
"devkit",
"=",
"null",
";",
"$",
"output",
"=",
"null",
";",
"$",
"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",
"(",
"$",
"this",
"->",
"is_logged_in",
")",
"{",
"/**\n * Allows a devkit object to be specified, and stop continued execution:\n *\n * @delegate FrontendDevKitResolve\n * @param string $context\n * '/frontend/'\n * @param boolean $full_generate\n * Whether this page will be completely generated (ie. invoke the XSLT transform)\n * or not, by default this is true. Passed by reference\n * @param mixed $devkit\n * Allows a devkit to register to this page\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'FrontendDevKitResolve'",
",",
"'/frontend/'",
",",
"array",
"(",
"'full_generate'",
"=>",
"&",
"$",
"full_generate",
",",
"'devkit'",
"=>",
"&",
"$",
"devkit",
")",
")",
";",
"}",
"Symphony",
"::",
"Profiler",
"(",
")",
"->",
"sample",
"(",
"'Page creation started'",
")",
";",
"$",
"this",
"->",
"_page",
"=",
"$",
"page",
";",
"$",
"this",
"->",
"__buildPage",
"(",
")",
";",
"if",
"(",
"$",
"full_generate",
")",
"{",
"/**\n * Immediately before generating the page. Provided with the page object, XML and XSLT\n * @delegate FrontendOutputPreGenerate\n * @param string $context\n * '/frontend/'\n * @param FrontendPage $page\n * This FrontendPage object, by reference\n * @param XMLElement $xml\n * This pages XML, including the Parameters, Datasource and Event XML, by reference as\n * an XMLElement\n * @param string $xsl\n * This pages XSLT, by reference\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'FrontendOutputPreGenerate'",
",",
"'/frontend/'",
",",
"array",
"(",
"'page'",
"=>",
"&",
"$",
"this",
",",
"'xml'",
"=>",
"&",
"$",
"this",
"->",
"_xml",
",",
"'xsl'",
"=>",
"&",
"$",
"this",
"->",
"_xsl",
")",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"devkit",
")",
")",
"{",
"if",
"(",
"General",
"::",
"in_iarray",
"(",
"'XML'",
",",
"$",
"this",
"->",
"_pageData",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addHeaderToPage",
"(",
"'Content-Type'",
",",
"'text/xml; charset=utf-8'",
")",
";",
"}",
"elseif",
"(",
"General",
"::",
"in_iarray",
"(",
"'JSON'",
",",
"$",
"this",
"->",
"_pageData",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addHeaderToPage",
"(",
"'Content-Type'",
",",
"'application/json; charset=utf-8'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addHeaderToPage",
"(",
"'Content-Type'",
",",
"'text/html; charset=utf-8'",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"'404'",
",",
"$",
"this",
"->",
"_pageData",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setHttpStatus",
"(",
"self",
"::",
"HTTP_STATUS_NOT_FOUND",
")",
";",
"}",
"elseif",
"(",
"in_array",
"(",
"'403'",
",",
"$",
"this",
"->",
"_pageData",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setHttpStatus",
"(",
"self",
"::",
"HTTP_STATUS_FORBIDDEN",
")",
";",
"}",
"}",
"// Lock down the frontend first so that extensions can easily remove these",
"// headers if desired. RE: #2480",
"$",
"this",
"->",
"addHeaderToPage",
"(",
"'X-Frame-Options'",
",",
"'SAMEORIGIN'",
")",
";",
"// Add more http security headers, RE: #2248",
"$",
"this",
"->",
"addHeaderToPage",
"(",
"'X-Content-Type-Options'",
",",
"'nosniff'",
")",
";",
"$",
"this",
"->",
"addHeaderToPage",
"(",
"'X-XSS-Protection'",
",",
"'1; mode=block'",
")",
";",
"/**\n * This is just prior to the page headers being rendered, and is suitable for changing them\n * @delegate FrontendPreRenderHeaders\n * @param string $context\n * '/frontend/'\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'FrontendPreRenderHeaders'",
",",
"'/frontend/'",
")",
";",
"$",
"backup_param",
"=",
"$",
"this",
"->",
"_param",
";",
"$",
"this",
"->",
"_param",
"[",
"'current-query-string'",
"]",
"=",
"General",
"::",
"wrapInCDATA",
"(",
"$",
"this",
"->",
"_param",
"[",
"'current-query-string'",
"]",
")",
";",
"// In Symphony 2.4, the XML structure stays as an object until",
"// the very last moment.",
"Symphony",
"::",
"Profiler",
"(",
")",
"->",
"seed",
"(",
"precision_timer",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_xml",
"instanceof",
"XMLElement",
")",
"{",
"$",
"this",
"->",
"setXML",
"(",
"$",
"this",
"->",
"_xml",
"->",
"generate",
"(",
"true",
",",
"0",
")",
")",
";",
"}",
"Symphony",
"::",
"Profiler",
"(",
")",
"->",
"sample",
"(",
"'XML Generation'",
",",
"PROFILE_LAP",
")",
";",
"$",
"output",
"=",
"parent",
"::",
"generate",
"(",
")",
";",
"$",
"this",
"->",
"_param",
"=",
"$",
"backup_param",
";",
"Symphony",
"::",
"Profiler",
"(",
")",
"->",
"sample",
"(",
"'XSLT Transformation'",
",",
"PROFILE_LAP",
")",
";",
"/**\n * Immediately after generating the page. Provided with string containing page source\n * @delegate FrontendOutputPostGenerate\n * @param string $context\n * '/frontend/'\n * @param string $output\n * The generated output of this page, ie. a string of HTML, passed by reference\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'FrontendOutputPostGenerate'",
",",
"'/frontend/'",
",",
"array",
"(",
"'output'",
"=>",
"&",
"$",
"output",
")",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"devkit",
")",
"&&",
"!",
"$",
"output",
")",
"{",
"$",
"errstr",
"=",
"null",
";",
"while",
"(",
"list",
"(",
",",
"$",
"val",
")",
"=",
"$",
"this",
"->",
"Proc",
"->",
"getError",
"(",
")",
")",
"{",
"$",
"errstr",
".=",
"'Line: '",
".",
"$",
"val",
"[",
"'line'",
"]",
".",
"' - '",
".",
"$",
"val",
"[",
"'message'",
"]",
".",
"PHP_EOL",
";",
"}",
"Frontend",
"::",
"instance",
"(",
")",
"->",
"throwCustomError",
"(",
"trim",
"(",
"$",
"errstr",
")",
",",
"__",
"(",
"'XSLT Processing Error'",
")",
",",
"Page",
"::",
"HTTP_STATUS_ERROR",
",",
"'xslt'",
",",
"array",
"(",
"'proc'",
"=>",
"clone",
"$",
"this",
"->",
"Proc",
")",
")",
";",
"}",
"Symphony",
"::",
"Profiler",
"(",
")",
"->",
"sample",
"(",
"'Page creation complete'",
")",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"devkit",
")",
")",
"{",
"$",
"devkit",
"->",
"prepare",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"_pageData",
",",
"$",
"this",
"->",
"_xml",
",",
"$",
"this",
"->",
"_param",
",",
"$",
"output",
")",
";",
"return",
"$",
"devkit",
"->",
"build",
"(",
")",
";",
"}",
"// Display the Event Results in the page source if the user is logged",
"// into Symphony, the page is not JSON and if it is enabled in the",
"// configuration.",
"if",
"(",
"$",
"this",
"->",
"is_logged_in",
"&&",
"!",
"General",
"::",
"in_iarray",
"(",
"'JSON'",
",",
"$",
"this",
"->",
"_pageData",
"[",
"'type'",
"]",
")",
"&&",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'display_event_xml_in_source'",
",",
"'public'",
")",
"===",
"'yes'",
")",
"{",
"$",
"output",
".=",
"PHP_EOL",
".",
"'<!-- '",
".",
"PHP_EOL",
".",
"$",
"this",
"->",
"_events_xml",
"->",
"generate",
"(",
"true",
")",
".",
"' -->'",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | This function is called immediately from the Frontend class passing the current
URL for generation. Generate will resolve the URL to the specific page in the Symphony
and then execute all events and datasources registered to this page so that it can
be rendered. A number of delegates are fired during stages of execution for extensions
to hook into.
@uses FrontendDevKitResolve
@uses FrontendOutputPreGenerate
@uses FrontendPreRenderHeaders
@uses FrontendOutputPostGenerate
@see __buildPage()
@param string $page
The URL of the current page that is being Rendered as returned by getCurrentPage
@throws Exception
@throws FrontendPageNotFoundException
@throws SymphonyErrorPage
@return string
The page source after the XSLT has transformed this page's XML. This would be
exactly the same as the 'view-source' from your browser | [
"This",
"function",
"is",
"called",
"immediately",
"from",
"the",
"Frontend",
"class",
"passing",
"the",
"current",
"URL",
"for",
"generation",
".",
"Generate",
"will",
"resolve",
"the",
"URL",
"to",
"the",
"specific",
"page",
"in",
"the",
"Symphony",
"and",
"then",
"execute",
"all",
"events",
"and",
"datasources",
"registered",
"to",
"this",
"page",
"so",
"that",
"it",
"can",
"be",
"rendered",
".",
"A",
"number",
"of",
"delegates",
"are",
"fired",
"during",
"stages",
"of",
"execution",
"for",
"extensions",
"to",
"hook",
"into",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.frontendpage.php#L161-L305 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.frontendpage.php | FrontendPage.__buildPage | private function __buildPage()
{
$start = precision_timer();
if (!$page = $this->resolvePage()) {
throw new FrontendPageNotFoundException;
}
/**
* Just after having resolved the page, but prior to any commencement of output creation
* @delegate FrontendPageResolved
* @param string $context
* '/frontend/'
* @param FrontendPage $page
* An instance of this class, passed by reference
* @param array $page_data
* An associative array of page data, which is a combination from `tbl_pages` and
* the path of the page on the filesystem. Passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('FrontendPageResolved', '/frontend/', array('page' => &$this, 'page_data' => &$page));
$this->_pageData = $page;
$path = explode('/', $page['path']);
$root_page = is_array($path) ? array_shift($path) : $path;
$current_path = explode(dirname(server_safe('SCRIPT_NAME')), server_safe('REQUEST_URI'), 2);
$current_path = '/' . ltrim(end($current_path), '/');
$split_path = explode('?', $current_path, 3);
$current_path = rtrim(current($split_path), '/');
$querystring = next($split_path);
// Get max upload size from php and symphony config then choose the smallest
$upload_size_php = ini_size_to_bytes(ini_get('upload_max_filesize'));
$upload_size_sym = Symphony::Configuration()->get('max_upload_size', 'admin');
$date = new DateTime();
$this->_param = array(
'today' => $date->format('Y-m-d'),
'current-time' => $date->format('H:i'),
'this-year' => $date->format('Y'),
'this-month' => $date->format('m'),
'this-day' => $date->format('d'),
'timezone' => $date->format('P'),
'website-name' => Symphony::Configuration()->get('sitename', 'general'),
'page-title' => $page['title'],
'root' => URL,
'workspace' => URL . '/workspace',
'workspace-path' => DIRROOT . '/workspace',
'http-host' => HTTP_HOST,
'root-page' => ($root_page ? $root_page : $page['handle']),
'current-page' => $page['handle'],
'current-page-id' => $page['id'],
'current-path' => ($current_path == '') ? '/' : $current_path,
'parent-path' => '/' . $page['path'],
'current-query-string' => self::sanitizeParameter($querystring),
'current-url' => URL . $current_path,
'upload-limit' => min($upload_size_php, $upload_size_sym),
'symphony-version' => Symphony::Configuration()->get('version', 'symphony'),
);
if (isset($this->_env['url']) && is_array($this->_env['url'])) {
foreach ($this->_env['url'] as $key => $val) {
$this->_param[$key] = $val;
}
}
if (is_array($_GET) && !empty($_GET)) {
foreach ($_GET as $key => $val) {
if (in_array($key, array('symphony-page', 'debug', 'profile'))) {
continue;
}
// If the browser sends encoded entities for &, ie. a=1&b=2
// this causes the $_GET to output they key as amp;b, which results in
// $url-amp;b. This pattern will remove amp; allow the correct param
// to be used, $url-b
$key = preg_replace('/(^amp;|\/)/', null, $key);
// If the key gets replaced out then it will break the XML so prevent
// the parameter being set.
$key = General::createHandle($key);
if (!$key) {
continue;
}
// Handle ?foo[bar]=hi as well as straight ?foo=hi RE: #1348
if (is_array($val)) {
$val = General::array_map_recursive(array('FrontendPage', 'sanitizeParameter'), $val);
} else {
$val = self::sanitizeParameter($val);
}
$this->_param['url-' . $key] = $val;
}
}
if (is_array($_COOKIE[__SYM_COOKIE_PREFIX__]) && !empty($_COOKIE[__SYM_COOKIE_PREFIX__])) {
foreach ($_COOKIE[__SYM_COOKIE_PREFIX__] as $key => $val) {
if ($key === 'xsrf-token' && is_array($val)) {
$val = key($val);
}
$this->_param['cookie-' . $key] = $val;
}
}
// Flatten parameters:
General::flattenArray($this->_param);
// Add Page Types to parameters so they are not flattened too early
$this->_param['page-types'] = $page['type'];
// Add Page events the same way
$this->_param['page-events'] = explode(',', trim(str_replace('_', '-', $page['events']), ','));
/**
* Just after having resolved the page params, but prior to any commencement of output creation
* @delegate FrontendParamsResolve
* @param string $context
* '/frontend/'
* @param array $params
* An associative array of this page's parameters
*/
Symphony::ExtensionManager()->notifyMembers('FrontendParamsResolve', '/frontend/', array('params' => &$this->_param));
$xml_build_start = precision_timer();
$xml = new XMLElement('data');
$xml->setIncludeHeader(true);
$events = new XMLElement('events');
$this->processEvents($page['events'], $events);
$xml->appendChild($events);
$this->_events_xml = clone $events;
$this->processDatasources($page['data_sources'], $xml);
Symphony::Profiler()->seed($xml_build_start);
Symphony::Profiler()->sample('XML Built', PROFILE_LAP);
if (isset($this->_env['pool']) && is_array($this->_env['pool']) && !empty($this->_env['pool'])) {
foreach ($this->_env['pool'] as $handle => $p) {
if (!is_array($p)) {
$p = array($p);
}
foreach ($p as $key => $value) {
if (is_array($value) && !empty($value)) {
foreach ($value as $kk => $vv) {
$this->_param[$handle] .= @implode(', ', $vv) . ',';
}
} else {
$this->_param[$handle] = @implode(', ', $p);
}
}
$this->_param[$handle] = trim($this->_param[$handle], ',');
}
}
/**
* Access to the resolved param pool, including additional parameters provided by Data Source outputs
* @delegate FrontendParamsPostResolve
* @param string $context
* '/frontend/'
* @param array $params
* An associative array of this page's parameters
*/
Symphony::ExtensionManager()->notifyMembers('FrontendParamsPostResolve', '/frontend/', array('params' => &$this->_param));
$params = new XMLElement('params');
foreach ($this->_param as $key => $value) {
// To support multiple parameters using the 'datasource.field'
// we will pop off the field handle prior to sanitizing the
// key. This is because of a limitation where General::createHandle
// will strip '.' as it's technically punctuation.
if (strpos($key, '.') !== false) {
$parts = explode('.', $key);
$field_handle = '.' . Lang::createHandle(array_pop($parts));
$key = implode('', $parts);
} else {
$field_handle = '';
}
$key = Lang::createHandle($key) . $field_handle;
$param = new XMLElement($key);
// DS output params get flattened to a string, so get the original pre-flattened array
if (isset($this->_env['pool'][$key])) {
$value = $this->_env['pool'][$key];
}
if (is_array($value) && !(count($value) == 1 && empty($value[0]))) {
foreach ($value as $key => $value) {
$item = new XMLElement('item', General::sanitize($value));
$item->setAttribute('handle', Lang::createHandle($value));
$param->appendChild($item);
}
} elseif (is_array($value)) {
$param->setValue(General::sanitize($value[0]));
} elseif (in_array($key, array('xsrf-token', 'current-query-string'))) {
$param->setValue(General::wrapInCDATA($value));
} else {
$param->setValue(General::sanitize($value));
}
$params->appendChild($param);
}
$xml->prependChild($params);
$this->setXML($xml);
$xsl = '<?xml version="1.0" encoding="UTF-8"?>' .
'<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">' .
' <xsl:import href="/' . rawurlencode(ltrim($page['filelocation'], '/')) . '"/>' .
'</xsl:stylesheet>';
$this->setXSL($xsl, false);
$this->setRuntimeParam($this->_param);
Symphony::Profiler()->seed($start);
Symphony::Profiler()->sample('Page Built', PROFILE_LAP);
} | php | private function __buildPage()
{
$start = precision_timer();
if (!$page = $this->resolvePage()) {
throw new FrontendPageNotFoundException;
}
/**
* Just after having resolved the page, but prior to any commencement of output creation
* @delegate FrontendPageResolved
* @param string $context
* '/frontend/'
* @param FrontendPage $page
* An instance of this class, passed by reference
* @param array $page_data
* An associative array of page data, which is a combination from `tbl_pages` and
* the path of the page on the filesystem. Passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('FrontendPageResolved', '/frontend/', array('page' => &$this, 'page_data' => &$page));
$this->_pageData = $page;
$path = explode('/', $page['path']);
$root_page = is_array($path) ? array_shift($path) : $path;
$current_path = explode(dirname(server_safe('SCRIPT_NAME')), server_safe('REQUEST_URI'), 2);
$current_path = '/' . ltrim(end($current_path), '/');
$split_path = explode('?', $current_path, 3);
$current_path = rtrim(current($split_path), '/');
$querystring = next($split_path);
// Get max upload size from php and symphony config then choose the smallest
$upload_size_php = ini_size_to_bytes(ini_get('upload_max_filesize'));
$upload_size_sym = Symphony::Configuration()->get('max_upload_size', 'admin');
$date = new DateTime();
$this->_param = array(
'today' => $date->format('Y-m-d'),
'current-time' => $date->format('H:i'),
'this-year' => $date->format('Y'),
'this-month' => $date->format('m'),
'this-day' => $date->format('d'),
'timezone' => $date->format('P'),
'website-name' => Symphony::Configuration()->get('sitename', 'general'),
'page-title' => $page['title'],
'root' => URL,
'workspace' => URL . '/workspace',
'workspace-path' => DIRROOT . '/workspace',
'http-host' => HTTP_HOST,
'root-page' => ($root_page ? $root_page : $page['handle']),
'current-page' => $page['handle'],
'current-page-id' => $page['id'],
'current-path' => ($current_path == '') ? '/' : $current_path,
'parent-path' => '/' . $page['path'],
'current-query-string' => self::sanitizeParameter($querystring),
'current-url' => URL . $current_path,
'upload-limit' => min($upload_size_php, $upload_size_sym),
'symphony-version' => Symphony::Configuration()->get('version', 'symphony'),
);
if (isset($this->_env['url']) && is_array($this->_env['url'])) {
foreach ($this->_env['url'] as $key => $val) {
$this->_param[$key] = $val;
}
}
if (is_array($_GET) && !empty($_GET)) {
foreach ($_GET as $key => $val) {
if (in_array($key, array('symphony-page', 'debug', 'profile'))) {
continue;
}
// If the browser sends encoded entities for &, ie. a=1&b=2
// this causes the $_GET to output they key as amp;b, which results in
// $url-amp;b. This pattern will remove amp; allow the correct param
// to be used, $url-b
$key = preg_replace('/(^amp;|\/)/', null, $key);
// If the key gets replaced out then it will break the XML so prevent
// the parameter being set.
$key = General::createHandle($key);
if (!$key) {
continue;
}
// Handle ?foo[bar]=hi as well as straight ?foo=hi RE: #1348
if (is_array($val)) {
$val = General::array_map_recursive(array('FrontendPage', 'sanitizeParameter'), $val);
} else {
$val = self::sanitizeParameter($val);
}
$this->_param['url-' . $key] = $val;
}
}
if (is_array($_COOKIE[__SYM_COOKIE_PREFIX__]) && !empty($_COOKIE[__SYM_COOKIE_PREFIX__])) {
foreach ($_COOKIE[__SYM_COOKIE_PREFIX__] as $key => $val) {
if ($key === 'xsrf-token' && is_array($val)) {
$val = key($val);
}
$this->_param['cookie-' . $key] = $val;
}
}
// Flatten parameters:
General::flattenArray($this->_param);
// Add Page Types to parameters so they are not flattened too early
$this->_param['page-types'] = $page['type'];
// Add Page events the same way
$this->_param['page-events'] = explode(',', trim(str_replace('_', '-', $page['events']), ','));
/**
* Just after having resolved the page params, but prior to any commencement of output creation
* @delegate FrontendParamsResolve
* @param string $context
* '/frontend/'
* @param array $params
* An associative array of this page's parameters
*/
Symphony::ExtensionManager()->notifyMembers('FrontendParamsResolve', '/frontend/', array('params' => &$this->_param));
$xml_build_start = precision_timer();
$xml = new XMLElement('data');
$xml->setIncludeHeader(true);
$events = new XMLElement('events');
$this->processEvents($page['events'], $events);
$xml->appendChild($events);
$this->_events_xml = clone $events;
$this->processDatasources($page['data_sources'], $xml);
Symphony::Profiler()->seed($xml_build_start);
Symphony::Profiler()->sample('XML Built', PROFILE_LAP);
if (isset($this->_env['pool']) && is_array($this->_env['pool']) && !empty($this->_env['pool'])) {
foreach ($this->_env['pool'] as $handle => $p) {
if (!is_array($p)) {
$p = array($p);
}
foreach ($p as $key => $value) {
if (is_array($value) && !empty($value)) {
foreach ($value as $kk => $vv) {
$this->_param[$handle] .= @implode(', ', $vv) . ',';
}
} else {
$this->_param[$handle] = @implode(', ', $p);
}
}
$this->_param[$handle] = trim($this->_param[$handle], ',');
}
}
/**
* Access to the resolved param pool, including additional parameters provided by Data Source outputs
* @delegate FrontendParamsPostResolve
* @param string $context
* '/frontend/'
* @param array $params
* An associative array of this page's parameters
*/
Symphony::ExtensionManager()->notifyMembers('FrontendParamsPostResolve', '/frontend/', array('params' => &$this->_param));
$params = new XMLElement('params');
foreach ($this->_param as $key => $value) {
// To support multiple parameters using the 'datasource.field'
// we will pop off the field handle prior to sanitizing the
// key. This is because of a limitation where General::createHandle
// will strip '.' as it's technically punctuation.
if (strpos($key, '.') !== false) {
$parts = explode('.', $key);
$field_handle = '.' . Lang::createHandle(array_pop($parts));
$key = implode('', $parts);
} else {
$field_handle = '';
}
$key = Lang::createHandle($key) . $field_handle;
$param = new XMLElement($key);
// DS output params get flattened to a string, so get the original pre-flattened array
if (isset($this->_env['pool'][$key])) {
$value = $this->_env['pool'][$key];
}
if (is_array($value) && !(count($value) == 1 && empty($value[0]))) {
foreach ($value as $key => $value) {
$item = new XMLElement('item', General::sanitize($value));
$item->setAttribute('handle', Lang::createHandle($value));
$param->appendChild($item);
}
} elseif (is_array($value)) {
$param->setValue(General::sanitize($value[0]));
} elseif (in_array($key, array('xsrf-token', 'current-query-string'))) {
$param->setValue(General::wrapInCDATA($value));
} else {
$param->setValue(General::sanitize($value));
}
$params->appendChild($param);
}
$xml->prependChild($params);
$this->setXML($xml);
$xsl = '<?xml version="1.0" encoding="UTF-8"?>' .
'<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">' .
' <xsl:import href="/' . rawurlencode(ltrim($page['filelocation'], '/')) . '"/>' .
'</xsl:stylesheet>';
$this->setXSL($xsl, false);
$this->setRuntimeParam($this->_param);
Symphony::Profiler()->seed($start);
Symphony::Profiler()->sample('Page Built', PROFILE_LAP);
} | [
"private",
"function",
"__buildPage",
"(",
")",
"{",
"$",
"start",
"=",
"precision_timer",
"(",
")",
";",
"if",
"(",
"!",
"$",
"page",
"=",
"$",
"this",
"->",
"resolvePage",
"(",
")",
")",
"{",
"throw",
"new",
"FrontendPageNotFoundException",
";",
"}",
"/**\n * Just after having resolved the page, but prior to any commencement of output creation\n * @delegate FrontendPageResolved\n * @param string $context\n * '/frontend/'\n * @param FrontendPage $page\n * An instance of this class, passed by reference\n * @param array $page_data\n * An associative array of page data, which is a combination from `tbl_pages` and\n * the path of the page on the filesystem. Passed by reference\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'FrontendPageResolved'",
",",
"'/frontend/'",
",",
"array",
"(",
"'page'",
"=>",
"&",
"$",
"this",
",",
"'page_data'",
"=>",
"&",
"$",
"page",
")",
")",
";",
"$",
"this",
"->",
"_pageData",
"=",
"$",
"page",
";",
"$",
"path",
"=",
"explode",
"(",
"'/'",
",",
"$",
"page",
"[",
"'path'",
"]",
")",
";",
"$",
"root_page",
"=",
"is_array",
"(",
"$",
"path",
")",
"?",
"array_shift",
"(",
"$",
"path",
")",
":",
"$",
"path",
";",
"$",
"current_path",
"=",
"explode",
"(",
"dirname",
"(",
"server_safe",
"(",
"'SCRIPT_NAME'",
")",
")",
",",
"server_safe",
"(",
"'REQUEST_URI'",
")",
",",
"2",
")",
";",
"$",
"current_path",
"=",
"'/'",
".",
"ltrim",
"(",
"end",
"(",
"$",
"current_path",
")",
",",
"'/'",
")",
";",
"$",
"split_path",
"=",
"explode",
"(",
"'?'",
",",
"$",
"current_path",
",",
"3",
")",
";",
"$",
"current_path",
"=",
"rtrim",
"(",
"current",
"(",
"$",
"split_path",
")",
",",
"'/'",
")",
";",
"$",
"querystring",
"=",
"next",
"(",
"$",
"split_path",
")",
";",
"// Get max upload size from php and symphony config then choose the smallest",
"$",
"upload_size_php",
"=",
"ini_size_to_bytes",
"(",
"ini_get",
"(",
"'upload_max_filesize'",
")",
")",
";",
"$",
"upload_size_sym",
"=",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'max_upload_size'",
",",
"'admin'",
")",
";",
"$",
"date",
"=",
"new",
"DateTime",
"(",
")",
";",
"$",
"this",
"->",
"_param",
"=",
"array",
"(",
"'today'",
"=>",
"$",
"date",
"->",
"format",
"(",
"'Y-m-d'",
")",
",",
"'current-time'",
"=>",
"$",
"date",
"->",
"format",
"(",
"'H:i'",
")",
",",
"'this-year'",
"=>",
"$",
"date",
"->",
"format",
"(",
"'Y'",
")",
",",
"'this-month'",
"=>",
"$",
"date",
"->",
"format",
"(",
"'m'",
")",
",",
"'this-day'",
"=>",
"$",
"date",
"->",
"format",
"(",
"'d'",
")",
",",
"'timezone'",
"=>",
"$",
"date",
"->",
"format",
"(",
"'P'",
")",
",",
"'website-name'",
"=>",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'sitename'",
",",
"'general'",
")",
",",
"'page-title'",
"=>",
"$",
"page",
"[",
"'title'",
"]",
",",
"'root'",
"=>",
"URL",
",",
"'workspace'",
"=>",
"URL",
".",
"'/workspace'",
",",
"'workspace-path'",
"=>",
"DIRROOT",
".",
"'/workspace'",
",",
"'http-host'",
"=>",
"HTTP_HOST",
",",
"'root-page'",
"=>",
"(",
"$",
"root_page",
"?",
"$",
"root_page",
":",
"$",
"page",
"[",
"'handle'",
"]",
")",
",",
"'current-page'",
"=>",
"$",
"page",
"[",
"'handle'",
"]",
",",
"'current-page-id'",
"=>",
"$",
"page",
"[",
"'id'",
"]",
",",
"'current-path'",
"=>",
"(",
"$",
"current_path",
"==",
"''",
")",
"?",
"'/'",
":",
"$",
"current_path",
",",
"'parent-path'",
"=>",
"'/'",
".",
"$",
"page",
"[",
"'path'",
"]",
",",
"'current-query-string'",
"=>",
"self",
"::",
"sanitizeParameter",
"(",
"$",
"querystring",
")",
",",
"'current-url'",
"=>",
"URL",
".",
"$",
"current_path",
",",
"'upload-limit'",
"=>",
"min",
"(",
"$",
"upload_size_php",
",",
"$",
"upload_size_sym",
")",
",",
"'symphony-version'",
"=>",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'version'",
",",
"'symphony'",
")",
",",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_env",
"[",
"'url'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"this",
"->",
"_env",
"[",
"'url'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_env",
"[",
"'url'",
"]",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"_param",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"if",
"(",
"is_array",
"(",
"$",
"_GET",
")",
"&&",
"!",
"empty",
"(",
"$",
"_GET",
")",
")",
"{",
"foreach",
"(",
"$",
"_GET",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"array",
"(",
"'symphony-page'",
",",
"'debug'",
",",
"'profile'",
")",
")",
")",
"{",
"continue",
";",
"}",
"// If the browser sends encoded entities for &, ie. a=1&b=2",
"// this causes the $_GET to output they key as amp;b, which results in",
"// $url-amp;b. This pattern will remove amp; allow the correct param",
"// to be used, $url-b",
"$",
"key",
"=",
"preg_replace",
"(",
"'/(^amp;|\\/)/'",
",",
"null",
",",
"$",
"key",
")",
";",
"// If the key gets replaced out then it will break the XML so prevent",
"// the parameter being set.",
"$",
"key",
"=",
"General",
"::",
"createHandle",
"(",
"$",
"key",
")",
";",
"if",
"(",
"!",
"$",
"key",
")",
"{",
"continue",
";",
"}",
"// Handle ?foo[bar]=hi as well as straight ?foo=hi RE: #1348",
"if",
"(",
"is_array",
"(",
"$",
"val",
")",
")",
"{",
"$",
"val",
"=",
"General",
"::",
"array_map_recursive",
"(",
"array",
"(",
"'FrontendPage'",
",",
"'sanitizeParameter'",
")",
",",
"$",
"val",
")",
";",
"}",
"else",
"{",
"$",
"val",
"=",
"self",
"::",
"sanitizeParameter",
"(",
"$",
"val",
")",
";",
"}",
"$",
"this",
"->",
"_param",
"[",
"'url-'",
".",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"if",
"(",
"is_array",
"(",
"$",
"_COOKIE",
"[",
"__SYM_COOKIE_PREFIX__",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"_COOKIE",
"[",
"__SYM_COOKIE_PREFIX__",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"_COOKIE",
"[",
"__SYM_COOKIE_PREFIX__",
"]",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"'xsrf-token'",
"&&",
"is_array",
"(",
"$",
"val",
")",
")",
"{",
"$",
"val",
"=",
"key",
"(",
"$",
"val",
")",
";",
"}",
"$",
"this",
"->",
"_param",
"[",
"'cookie-'",
".",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"// Flatten parameters:",
"General",
"::",
"flattenArray",
"(",
"$",
"this",
"->",
"_param",
")",
";",
"// Add Page Types to parameters so they are not flattened too early",
"$",
"this",
"->",
"_param",
"[",
"'page-types'",
"]",
"=",
"$",
"page",
"[",
"'type'",
"]",
";",
"// Add Page events the same way",
"$",
"this",
"->",
"_param",
"[",
"'page-events'",
"]",
"=",
"explode",
"(",
"','",
",",
"trim",
"(",
"str_replace",
"(",
"'_'",
",",
"'-'",
",",
"$",
"page",
"[",
"'events'",
"]",
")",
",",
"','",
")",
")",
";",
"/**\n * Just after having resolved the page params, but prior to any commencement of output creation\n * @delegate FrontendParamsResolve\n * @param string $context\n * '/frontend/'\n * @param array $params\n * An associative array of this page's parameters\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'FrontendParamsResolve'",
",",
"'/frontend/'",
",",
"array",
"(",
"'params'",
"=>",
"&",
"$",
"this",
"->",
"_param",
")",
")",
";",
"$",
"xml_build_start",
"=",
"precision_timer",
"(",
")",
";",
"$",
"xml",
"=",
"new",
"XMLElement",
"(",
"'data'",
")",
";",
"$",
"xml",
"->",
"setIncludeHeader",
"(",
"true",
")",
";",
"$",
"events",
"=",
"new",
"XMLElement",
"(",
"'events'",
")",
";",
"$",
"this",
"->",
"processEvents",
"(",
"$",
"page",
"[",
"'events'",
"]",
",",
"$",
"events",
")",
";",
"$",
"xml",
"->",
"appendChild",
"(",
"$",
"events",
")",
";",
"$",
"this",
"->",
"_events_xml",
"=",
"clone",
"$",
"events",
";",
"$",
"this",
"->",
"processDatasources",
"(",
"$",
"page",
"[",
"'data_sources'",
"]",
",",
"$",
"xml",
")",
";",
"Symphony",
"::",
"Profiler",
"(",
")",
"->",
"seed",
"(",
"$",
"xml_build_start",
")",
";",
"Symphony",
"::",
"Profiler",
"(",
")",
"->",
"sample",
"(",
"'XML Built'",
",",
"PROFILE_LAP",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_env",
"[",
"'pool'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"this",
"->",
"_env",
"[",
"'pool'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"_env",
"[",
"'pool'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_env",
"[",
"'pool'",
"]",
"as",
"$",
"handle",
"=>",
"$",
"p",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"p",
")",
")",
"{",
"$",
"p",
"=",
"array",
"(",
"$",
"p",
")",
";",
"}",
"foreach",
"(",
"$",
"p",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"!",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"kk",
"=>",
"$",
"vv",
")",
"{",
"$",
"this",
"->",
"_param",
"[",
"$",
"handle",
"]",
".=",
"@",
"implode",
"(",
"', '",
",",
"$",
"vv",
")",
".",
"','",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"_param",
"[",
"$",
"handle",
"]",
"=",
"@",
"implode",
"(",
"', '",
",",
"$",
"p",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_param",
"[",
"$",
"handle",
"]",
"=",
"trim",
"(",
"$",
"this",
"->",
"_param",
"[",
"$",
"handle",
"]",
",",
"','",
")",
";",
"}",
"}",
"/**\n * Access to the resolved param pool, including additional parameters provided by Data Source outputs\n * @delegate FrontendParamsPostResolve\n * @param string $context\n * '/frontend/'\n * @param array $params\n * An associative array of this page's parameters\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'FrontendParamsPostResolve'",
",",
"'/frontend/'",
",",
"array",
"(",
"'params'",
"=>",
"&",
"$",
"this",
"->",
"_param",
")",
")",
";",
"$",
"params",
"=",
"new",
"XMLElement",
"(",
"'params'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_param",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// To support multiple parameters using the 'datasource.field'",
"// we will pop off the field handle prior to sanitizing the",
"// key. This is because of a limitation where General::createHandle",
"// will strip '.' as it's technically punctuation.",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"$",
"field_handle",
"=",
"'.'",
".",
"Lang",
"::",
"createHandle",
"(",
"array_pop",
"(",
"$",
"parts",
")",
")",
";",
"$",
"key",
"=",
"implode",
"(",
"''",
",",
"$",
"parts",
")",
";",
"}",
"else",
"{",
"$",
"field_handle",
"=",
"''",
";",
"}",
"$",
"key",
"=",
"Lang",
"::",
"createHandle",
"(",
"$",
"key",
")",
".",
"$",
"field_handle",
";",
"$",
"param",
"=",
"new",
"XMLElement",
"(",
"$",
"key",
")",
";",
"// DS output params get flattened to a string, so get the original pre-flattened array",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_env",
"[",
"'pool'",
"]",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"_env",
"[",
"'pool'",
"]",
"[",
"$",
"key",
"]",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"!",
"(",
"count",
"(",
"$",
"value",
")",
"==",
"1",
"&&",
"empty",
"(",
"$",
"value",
"[",
"0",
"]",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"item",
"=",
"new",
"XMLElement",
"(",
"'item'",
",",
"General",
"::",
"sanitize",
"(",
"$",
"value",
")",
")",
";",
"$",
"item",
"->",
"setAttribute",
"(",
"'handle'",
",",
"Lang",
"::",
"createHandle",
"(",
"$",
"value",
")",
")",
";",
"$",
"param",
"->",
"appendChild",
"(",
"$",
"item",
")",
";",
"}",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"param",
"->",
"setValue",
"(",
"General",
"::",
"sanitize",
"(",
"$",
"value",
"[",
"0",
"]",
")",
")",
";",
"}",
"elseif",
"(",
"in_array",
"(",
"$",
"key",
",",
"array",
"(",
"'xsrf-token'",
",",
"'current-query-string'",
")",
")",
")",
"{",
"$",
"param",
"->",
"setValue",
"(",
"General",
"::",
"wrapInCDATA",
"(",
"$",
"value",
")",
")",
";",
"}",
"else",
"{",
"$",
"param",
"->",
"setValue",
"(",
"General",
"::",
"sanitize",
"(",
"$",
"value",
")",
")",
";",
"}",
"$",
"params",
"->",
"appendChild",
"(",
"$",
"param",
")",
";",
"}",
"$",
"xml",
"->",
"prependChild",
"(",
"$",
"params",
")",
";",
"$",
"this",
"->",
"setXML",
"(",
"$",
"xml",
")",
";",
"$",
"xsl",
"=",
"'<?xml version=\"1.0\" encoding=\"UTF-8\"?>'",
".",
"'<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">'",
".",
"' <xsl:import href=\"/'",
".",
"rawurlencode",
"(",
"ltrim",
"(",
"$",
"page",
"[",
"'filelocation'",
"]",
",",
"'/'",
")",
")",
".",
"'\"/>'",
".",
"'</xsl:stylesheet>'",
";",
"$",
"this",
"->",
"setXSL",
"(",
"$",
"xsl",
",",
"false",
")",
";",
"$",
"this",
"->",
"setRuntimeParam",
"(",
"$",
"this",
"->",
"_param",
")",
";",
"Symphony",
"::",
"Profiler",
"(",
")",
"->",
"seed",
"(",
"$",
"start",
")",
";",
"Symphony",
"::",
"Profiler",
"(",
")",
"->",
"sample",
"(",
"'Page Built'",
",",
"PROFILE_LAP",
")",
";",
"}"
] | This function sets the page's parameters, processes the Datasources and
Events and sets the `$xml` and `$xsl` variables. This functions resolves the `$page`
by calling the `resolvePage()` function. If a page is not found, it attempts
to locate the Symphony 404 page set in the backend otherwise it throws
the default Symphony 404 page. If the page is found, the page's XSL utility
is found, and the system parameters are set, including any URL parameters,
params from the Symphony cookies. Events and Datasources are executed and
any parameters generated by them are appended to the existing parameters
before setting the Page's XML and XSL variables are set to the be the
generated XML (from the Datasources and Events) and the XSLT (from the
file attached to this Page)
@uses FrontendPageResolved
@uses FrontendParamsResolve
@uses FrontendParamsPostResolve
@see resolvePage() | [
"This",
"function",
"sets",
"the",
"page",
"s",
"parameters",
"processes",
"the",
"Datasources",
"and",
"Events",
"and",
"sets",
"the",
"$xml",
"and",
"$xsl",
"variables",
".",
"This",
"functions",
"resolves",
"the",
"$page",
"by",
"calling",
"the",
"resolvePage",
"()",
"function",
".",
"If",
"a",
"page",
"is",
"not",
"found",
"it",
"attempts",
"to",
"locate",
"the",
"Symphony",
"404",
"page",
"set",
"in",
"the",
"backend",
"otherwise",
"it",
"throws",
"the",
"default",
"Symphony",
"404",
"page",
".",
"If",
"the",
"page",
"is",
"found",
"the",
"page",
"s",
"XSL",
"utility",
"is",
"found",
"and",
"the",
"system",
"parameters",
"are",
"set",
"including",
"any",
"URL",
"parameters",
"params",
"from",
"the",
"Symphony",
"cookies",
".",
"Events",
"and",
"Datasources",
"are",
"executed",
"and",
"any",
"parameters",
"generated",
"by",
"them",
"are",
"appended",
"to",
"the",
"existing",
"parameters",
"before",
"setting",
"the",
"Page",
"s",
"XML",
"and",
"XSL",
"variables",
"are",
"set",
"to",
"the",
"be",
"the",
"generated",
"XML",
"(",
"from",
"the",
"Datasources",
"and",
"Events",
")",
"and",
"the",
"XSLT",
"(",
"from",
"the",
"file",
"attached",
"to",
"this",
"Page",
")"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.frontendpage.php#L325-L546 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.frontendpage.php | FrontendPage.resolvePage | public function resolvePage($page = null)
{
if ($page) {
$this->_page = $page;
}
$row = null;
/**
* Before page resolve. Allows manipulation of page without redirection
* @delegate FrontendPrePageResolve
* @param string $context
* '/frontend/'
* @param mixed $row
* @param FrontendPage $page
* An instance of this FrontendPage
*/
Symphony::ExtensionManager()->notifyMembers('FrontendPrePageResolve', '/frontend/', array('row' => &$row, 'page' => &$this->_page));
// Default to the index page if no page has been specified
if ((!$this->_page || $this->_page == '//') && is_null($row)) {
$row = PageManager::fetchPageByType('index');
// Not the index page (or at least not on first impression)
} elseif (is_null($row)) {
$page_extra_bits = array();
$pathArr = preg_split('/\//', trim($this->_page, '/'), -1, PREG_SPLIT_NO_EMPTY);
$handle = array_pop($pathArr);
do {
$path = implode('/', $pathArr);
if ($row = PageManager::resolvePageByPath($handle, $path)) {
$pathArr[] = $handle;
break 1;
} else {
$page_extra_bits[] = $handle;
}
} while (($handle = array_pop($pathArr)) !== null);
// If the `$pathArr` is empty, that means a page hasn't resolved for
// the given `$page`, however in some cases the index page may allow
// parameters, so we'll check.
if (empty($pathArr)) {
// If the index page does not handle parameters, then return false
// (which will give up the 404), otherwise treat the `$page` as
// parameters of the index. RE: #1351
$index = PageManager::fetchPageByType('index');
if (!$this->__isSchemaValid($index['params'], $page_extra_bits)) {
return false;
} else {
$row = $index;
}
// Page resolved, check the schema (are the parameters valid?)
} elseif (!$this->__isSchemaValid($row['params'], $page_extra_bits)) {
return false;
}
}
// Nothing resolved, bail now
if (!is_array($row) || empty($row)) {
return false;
}
// Process the extra URL params
$url_params = preg_split('/\//', $row['params'], -1, PREG_SPLIT_NO_EMPTY);
foreach ($url_params as $var) {
$this->_env['url'][$var] = null;
}
if (isset($page_extra_bits)) {
if (!empty($page_extra_bits)) {
$page_extra_bits = array_reverse($page_extra_bits);
}
for ($i = 0, $ii = count($page_extra_bits); $i < $ii; $i++) {
$this->_env['url'][$url_params[$i]] = str_replace(' ', '+', $page_extra_bits[$i]);
}
}
$row['type'] = PageManager::fetchPageTypes($row['id']);
// Make sure the user has permission to access this page
if (!$this->is_logged_in && in_array('admin', $row['type'])) {
$row = PageManager::fetchPageByType('403');
if (empty($row)) {
Frontend::instance()->throwCustomError(
__('Please login to view this page.') . ' <a href="' . SYMPHONY_URL . '/login/">' . __('Take me to the login page') . '</a>.',
__('Forbidden'),
Page::HTTP_STATUS_FORBIDDEN
);
}
$row['type'] = PageManager::fetchPageTypes($row['id']);
}
$row['filelocation'] = PageManager::resolvePageFileLocation($row['path'], $row['handle']);
return $row;
} | php | public function resolvePage($page = null)
{
if ($page) {
$this->_page = $page;
}
$row = null;
/**
* Before page resolve. Allows manipulation of page without redirection
* @delegate FrontendPrePageResolve
* @param string $context
* '/frontend/'
* @param mixed $row
* @param FrontendPage $page
* An instance of this FrontendPage
*/
Symphony::ExtensionManager()->notifyMembers('FrontendPrePageResolve', '/frontend/', array('row' => &$row, 'page' => &$this->_page));
// Default to the index page if no page has been specified
if ((!$this->_page || $this->_page == '//') && is_null($row)) {
$row = PageManager::fetchPageByType('index');
// Not the index page (or at least not on first impression)
} elseif (is_null($row)) {
$page_extra_bits = array();
$pathArr = preg_split('/\//', trim($this->_page, '/'), -1, PREG_SPLIT_NO_EMPTY);
$handle = array_pop($pathArr);
do {
$path = implode('/', $pathArr);
if ($row = PageManager::resolvePageByPath($handle, $path)) {
$pathArr[] = $handle;
break 1;
} else {
$page_extra_bits[] = $handle;
}
} while (($handle = array_pop($pathArr)) !== null);
// If the `$pathArr` is empty, that means a page hasn't resolved for
// the given `$page`, however in some cases the index page may allow
// parameters, so we'll check.
if (empty($pathArr)) {
// If the index page does not handle parameters, then return false
// (which will give up the 404), otherwise treat the `$page` as
// parameters of the index. RE: #1351
$index = PageManager::fetchPageByType('index');
if (!$this->__isSchemaValid($index['params'], $page_extra_bits)) {
return false;
} else {
$row = $index;
}
// Page resolved, check the schema (are the parameters valid?)
} elseif (!$this->__isSchemaValid($row['params'], $page_extra_bits)) {
return false;
}
}
// Nothing resolved, bail now
if (!is_array($row) || empty($row)) {
return false;
}
// Process the extra URL params
$url_params = preg_split('/\//', $row['params'], -1, PREG_SPLIT_NO_EMPTY);
foreach ($url_params as $var) {
$this->_env['url'][$var] = null;
}
if (isset($page_extra_bits)) {
if (!empty($page_extra_bits)) {
$page_extra_bits = array_reverse($page_extra_bits);
}
for ($i = 0, $ii = count($page_extra_bits); $i < $ii; $i++) {
$this->_env['url'][$url_params[$i]] = str_replace(' ', '+', $page_extra_bits[$i]);
}
}
$row['type'] = PageManager::fetchPageTypes($row['id']);
// Make sure the user has permission to access this page
if (!$this->is_logged_in && in_array('admin', $row['type'])) {
$row = PageManager::fetchPageByType('403');
if (empty($row)) {
Frontend::instance()->throwCustomError(
__('Please login to view this page.') . ' <a href="' . SYMPHONY_URL . '/login/">' . __('Take me to the login page') . '</a>.',
__('Forbidden'),
Page::HTTP_STATUS_FORBIDDEN
);
}
$row['type'] = PageManager::fetchPageTypes($row['id']);
}
$row['filelocation'] = PageManager::resolvePageFileLocation($row['path'], $row['handle']);
return $row;
} | [
"public",
"function",
"resolvePage",
"(",
"$",
"page",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"page",
")",
"{",
"$",
"this",
"->",
"_page",
"=",
"$",
"page",
";",
"}",
"$",
"row",
"=",
"null",
";",
"/**\n * Before page resolve. Allows manipulation of page without redirection\n * @delegate FrontendPrePageResolve\n * @param string $context\n * '/frontend/'\n * @param mixed $row\n * @param FrontendPage $page\n * An instance of this FrontendPage\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'FrontendPrePageResolve'",
",",
"'/frontend/'",
",",
"array",
"(",
"'row'",
"=>",
"&",
"$",
"row",
",",
"'page'",
"=>",
"&",
"$",
"this",
"->",
"_page",
")",
")",
";",
"// Default to the index page if no page has been specified",
"if",
"(",
"(",
"!",
"$",
"this",
"->",
"_page",
"||",
"$",
"this",
"->",
"_page",
"==",
"'//'",
")",
"&&",
"is_null",
"(",
"$",
"row",
")",
")",
"{",
"$",
"row",
"=",
"PageManager",
"::",
"fetchPageByType",
"(",
"'index'",
")",
";",
"// Not the index page (or at least not on first impression)",
"}",
"elseif",
"(",
"is_null",
"(",
"$",
"row",
")",
")",
"{",
"$",
"page_extra_bits",
"=",
"array",
"(",
")",
";",
"$",
"pathArr",
"=",
"preg_split",
"(",
"'/\\//'",
",",
"trim",
"(",
"$",
"this",
"->",
"_page",
",",
"'/'",
")",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"$",
"handle",
"=",
"array_pop",
"(",
"$",
"pathArr",
")",
";",
"do",
"{",
"$",
"path",
"=",
"implode",
"(",
"'/'",
",",
"$",
"pathArr",
")",
";",
"if",
"(",
"$",
"row",
"=",
"PageManager",
"::",
"resolvePageByPath",
"(",
"$",
"handle",
",",
"$",
"path",
")",
")",
"{",
"$",
"pathArr",
"[",
"]",
"=",
"$",
"handle",
";",
"break",
"1",
";",
"}",
"else",
"{",
"$",
"page_extra_bits",
"[",
"]",
"=",
"$",
"handle",
";",
"}",
"}",
"while",
"(",
"(",
"$",
"handle",
"=",
"array_pop",
"(",
"$",
"pathArr",
")",
")",
"!==",
"null",
")",
";",
"// If the `$pathArr` is empty, that means a page hasn't resolved for",
"// the given `$page`, however in some cases the index page may allow",
"// parameters, so we'll check.",
"if",
"(",
"empty",
"(",
"$",
"pathArr",
")",
")",
"{",
"// If the index page does not handle parameters, then return false",
"// (which will give up the 404), otherwise treat the `$page` as",
"// parameters of the index. RE: #1351",
"$",
"index",
"=",
"PageManager",
"::",
"fetchPageByType",
"(",
"'index'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"__isSchemaValid",
"(",
"$",
"index",
"[",
"'params'",
"]",
",",
"$",
"page_extra_bits",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"row",
"=",
"$",
"index",
";",
"}",
"// Page resolved, check the schema (are the parameters valid?)",
"}",
"elseif",
"(",
"!",
"$",
"this",
"->",
"__isSchemaValid",
"(",
"$",
"row",
"[",
"'params'",
"]",
",",
"$",
"page_extra_bits",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"// Nothing resolved, bail now",
"if",
"(",
"!",
"is_array",
"(",
"$",
"row",
")",
"||",
"empty",
"(",
"$",
"row",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Process the extra URL params",
"$",
"url_params",
"=",
"preg_split",
"(",
"'/\\//'",
",",
"$",
"row",
"[",
"'params'",
"]",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"foreach",
"(",
"$",
"url_params",
"as",
"$",
"var",
")",
"{",
"$",
"this",
"->",
"_env",
"[",
"'url'",
"]",
"[",
"$",
"var",
"]",
"=",
"null",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"page_extra_bits",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"page_extra_bits",
")",
")",
"{",
"$",
"page_extra_bits",
"=",
"array_reverse",
"(",
"$",
"page_extra_bits",
")",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"ii",
"=",
"count",
"(",
"$",
"page_extra_bits",
")",
";",
"$",
"i",
"<",
"$",
"ii",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"_env",
"[",
"'url'",
"]",
"[",
"$",
"url_params",
"[",
"$",
"i",
"]",
"]",
"=",
"str_replace",
"(",
"' '",
",",
"'+'",
",",
"$",
"page_extra_bits",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}",
"$",
"row",
"[",
"'type'",
"]",
"=",
"PageManager",
"::",
"fetchPageTypes",
"(",
"$",
"row",
"[",
"'id'",
"]",
")",
";",
"// Make sure the user has permission to access this page",
"if",
"(",
"!",
"$",
"this",
"->",
"is_logged_in",
"&&",
"in_array",
"(",
"'admin'",
",",
"$",
"row",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"row",
"=",
"PageManager",
"::",
"fetchPageByType",
"(",
"'403'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"row",
")",
")",
"{",
"Frontend",
"::",
"instance",
"(",
")",
"->",
"throwCustomError",
"(",
"__",
"(",
"'Please login to view this page.'",
")",
".",
"' <a href=\"'",
".",
"SYMPHONY_URL",
".",
"'/login/\">'",
".",
"__",
"(",
"'Take me to the login page'",
")",
".",
"'</a>.'",
",",
"__",
"(",
"'Forbidden'",
")",
",",
"Page",
"::",
"HTTP_STATUS_FORBIDDEN",
")",
";",
"}",
"$",
"row",
"[",
"'type'",
"]",
"=",
"PageManager",
"::",
"fetchPageTypes",
"(",
"$",
"row",
"[",
"'id'",
"]",
")",
";",
"}",
"$",
"row",
"[",
"'filelocation'",
"]",
"=",
"PageManager",
"::",
"resolvePageFileLocation",
"(",
"$",
"row",
"[",
"'path'",
"]",
",",
"$",
"row",
"[",
"'handle'",
"]",
")",
";",
"return",
"$",
"row",
";",
"}"
] | This function attempts to resolve the given page in to it's Symphony page. If no
page is given, it is assumed the 'index' is being requested. Before a page row is
returned, it is checked to see that if it has the 'admin' type, that the requesting
user is authenticated as a Symphony author. If they are not, the Symphony 403
page is returned (whether that be set as a user defined page using the page type
of 403, or just returning the Default Symphony 403 error page). Any URL parameters
set on the page are added to the `$env` variable before the function returns an
associative array of page details such as Title, Content Type etc.
@uses FrontendPrePageResolve
@see __isSchemaValid()
@param string $page
The URL of the current page that is being Rendered as returned by `getCurrentPage()`.
If no URL is provided, Symphony assumes the Page with the type 'index' is being
requested.
@throws SymphonyErrorPage
@return array
An associative array of page details | [
"This",
"function",
"attempts",
"to",
"resolve",
"the",
"given",
"page",
"in",
"to",
"it",
"s",
"Symphony",
"page",
".",
"If",
"no",
"page",
"is",
"given",
"it",
"is",
"assumed",
"the",
"index",
"is",
"being",
"requested",
".",
"Before",
"a",
"page",
"row",
"is",
"returned",
"it",
"is",
"checked",
"to",
"see",
"that",
"if",
"it",
"has",
"the",
"admin",
"type",
"that",
"the",
"requesting",
"user",
"is",
"authenticated",
"as",
"a",
"Symphony",
"author",
".",
"If",
"they",
"are",
"not",
"the",
"Symphony",
"403",
"page",
"is",
"returned",
"(",
"whether",
"that",
"be",
"set",
"as",
"a",
"user",
"defined",
"page",
"using",
"the",
"page",
"type",
"of",
"403",
"or",
"just",
"returning",
"the",
"Default",
"Symphony",
"403",
"error",
"page",
")",
".",
"Any",
"URL",
"parameters",
"set",
"on",
"the",
"page",
"are",
"added",
"to",
"the",
"$env",
"variable",
"before",
"the",
"function",
"returns",
"an",
"associative",
"array",
"of",
"page",
"details",
"such",
"as",
"Title",
"Content",
"Type",
"etc",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.frontendpage.php#L568-L671 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.frontendpage.php | FrontendPage.__isSchemaValid | private function __isSchemaValid($schema, array $bits)
{
$schema_arr = preg_split('/\//', $schema, -1, PREG_SPLIT_NO_EMPTY);
return (count($schema_arr) >= count($bits));
} | php | private function __isSchemaValid($schema, array $bits)
{
$schema_arr = preg_split('/\//', $schema, -1, PREG_SPLIT_NO_EMPTY);
return (count($schema_arr) >= count($bits));
} | [
"private",
"function",
"__isSchemaValid",
"(",
"$",
"schema",
",",
"array",
"$",
"bits",
")",
"{",
"$",
"schema_arr",
"=",
"preg_split",
"(",
"'/\\//'",
",",
"$",
"schema",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"return",
"(",
"count",
"(",
"$",
"schema_arr",
")",
">=",
"count",
"(",
"$",
"bits",
")",
")",
";",
"}"
] | Given the allowed params for the resolved page, compare it to
params provided in the URL. If the number of params provided
is less than or equal to the number of URL parameters set for a page,
the Schema is considered valid, otherwise, it's considered to be false
a 404 page will result.
@param string $schema
The URL schema for a page, ie. article/read
@param array $bits
The URL parameters provided from parsing the current URL. This
does not include any `$_GET` or `$_POST` variables.
@return boolean
true if the number of $schema (split by /) is less than the size
of the $bits array. | [
"Given",
"the",
"allowed",
"params",
"for",
"the",
"resolved",
"page",
"compare",
"it",
"to",
"params",
"provided",
"in",
"the",
"URL",
".",
"If",
"the",
"number",
"of",
"params",
"provided",
"is",
"less",
"than",
"or",
"equal",
"to",
"the",
"number",
"of",
"URL",
"parameters",
"set",
"for",
"a",
"page",
"the",
"Schema",
"is",
"considered",
"valid",
"otherwise",
"it",
"s",
"considered",
"to",
"be",
"false",
"a",
"404",
"page",
"will",
"result",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.frontendpage.php#L689-L694 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.frontendpage.php | FrontendPage.processEvents | private function processEvents($events, XMLElement &$wrapper)
{
/**
* Manipulate the events array and event element wrapper
* @delegate FrontendProcessEvents
* @param string $context
* '/frontend/'
* @param array $env
* @param string $events
* A string of all the Events attached to this page, comma separated.
* @param XMLElement $wrapper
* The XMLElement to append the Events results to. Event results are
* contained in a root XMLElement that is the handlised version of
* their name.
* @param array $page_data
* An associative array of page meta data
*/
Symphony::ExtensionManager()->notifyMembers('FrontendProcessEvents', '/frontend/', array(
'env' => $this->_env,
'events' => &$events,
'wrapper' => &$wrapper,
'page_data' => $this->_pageData
));
if (strlen(trim($events)) > 0) {
$events = preg_split('/,\s*/i', $events, -1, PREG_SPLIT_NO_EMPTY);
$events = array_map('trim', $events);
if (!is_array($events) || empty($events)) {
return;
}
$pool = array();
foreach ($events as $handle) {
$pool[$handle] = EventManager::create($handle, array('env' => $this->_env, 'param' => $this->_param));
}
uasort($pool, array($this, '__findEventOrder'));
foreach ($pool as $handle => $event) {
$startTime = precision_timer();
$queries = Symphony::Database()->queryCount();
if ($xml = $event->load()) {
if (is_object($xml)) {
$wrapper->appendChild($xml);
} else {
$wrapper->setValue(
$wrapper->getValue() . PHP_EOL . ' ' . trim($xml)
);
}
}
$queries = Symphony::Database()->queryCount() - $queries;
Symphony::Profiler()->seed($startTime);
Symphony::Profiler()->sample($handle, PROFILE_LAP, 'Event', $queries);
}
}
/**
* Just after the page events have triggered. Provided with the XML object
* @delegate FrontendEventPostProcess
* @param string $context
* '/frontend/'
* @param XMLElement $xml
* The XMLElement to append the Events results to. Event results are
* contained in a root XMLElement that is the handlised version of
* their name.
*/
Symphony::ExtensionManager()->notifyMembers('FrontendEventPostProcess', '/frontend/', array('xml' => &$wrapper));
} | php | private function processEvents($events, XMLElement &$wrapper)
{
/**
* Manipulate the events array and event element wrapper
* @delegate FrontendProcessEvents
* @param string $context
* '/frontend/'
* @param array $env
* @param string $events
* A string of all the Events attached to this page, comma separated.
* @param XMLElement $wrapper
* The XMLElement to append the Events results to. Event results are
* contained in a root XMLElement that is the handlised version of
* their name.
* @param array $page_data
* An associative array of page meta data
*/
Symphony::ExtensionManager()->notifyMembers('FrontendProcessEvents', '/frontend/', array(
'env' => $this->_env,
'events' => &$events,
'wrapper' => &$wrapper,
'page_data' => $this->_pageData
));
if (strlen(trim($events)) > 0) {
$events = preg_split('/,\s*/i', $events, -1, PREG_SPLIT_NO_EMPTY);
$events = array_map('trim', $events);
if (!is_array($events) || empty($events)) {
return;
}
$pool = array();
foreach ($events as $handle) {
$pool[$handle] = EventManager::create($handle, array('env' => $this->_env, 'param' => $this->_param));
}
uasort($pool, array($this, '__findEventOrder'));
foreach ($pool as $handle => $event) {
$startTime = precision_timer();
$queries = Symphony::Database()->queryCount();
if ($xml = $event->load()) {
if (is_object($xml)) {
$wrapper->appendChild($xml);
} else {
$wrapper->setValue(
$wrapper->getValue() . PHP_EOL . ' ' . trim($xml)
);
}
}
$queries = Symphony::Database()->queryCount() - $queries;
Symphony::Profiler()->seed($startTime);
Symphony::Profiler()->sample($handle, PROFILE_LAP, 'Event', $queries);
}
}
/**
* Just after the page events have triggered. Provided with the XML object
* @delegate FrontendEventPostProcess
* @param string $context
* '/frontend/'
* @param XMLElement $xml
* The XMLElement to append the Events results to. Event results are
* contained in a root XMLElement that is the handlised version of
* their name.
*/
Symphony::ExtensionManager()->notifyMembers('FrontendEventPostProcess', '/frontend/', array('xml' => &$wrapper));
} | [
"private",
"function",
"processEvents",
"(",
"$",
"events",
",",
"XMLElement",
"&",
"$",
"wrapper",
")",
"{",
"/**\n * Manipulate the events array and event element wrapper\n * @delegate FrontendProcessEvents\n * @param string $context\n * '/frontend/'\n * @param array $env\n * @param string $events\n * A string of all the Events attached to this page, comma separated.\n * @param XMLElement $wrapper\n * The XMLElement to append the Events results to. Event results are\n * contained in a root XMLElement that is the handlised version of\n * their name.\n * @param array $page_data\n * An associative array of page meta data\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'FrontendProcessEvents'",
",",
"'/frontend/'",
",",
"array",
"(",
"'env'",
"=>",
"$",
"this",
"->",
"_env",
",",
"'events'",
"=>",
"&",
"$",
"events",
",",
"'wrapper'",
"=>",
"&",
"$",
"wrapper",
",",
"'page_data'",
"=>",
"$",
"this",
"->",
"_pageData",
")",
")",
";",
"if",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"events",
")",
")",
">",
"0",
")",
"{",
"$",
"events",
"=",
"preg_split",
"(",
"'/,\\s*/i'",
",",
"$",
"events",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"$",
"events",
"=",
"array_map",
"(",
"'trim'",
",",
"$",
"events",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"events",
")",
"||",
"empty",
"(",
"$",
"events",
")",
")",
"{",
"return",
";",
"}",
"$",
"pool",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"events",
"as",
"$",
"handle",
")",
"{",
"$",
"pool",
"[",
"$",
"handle",
"]",
"=",
"EventManager",
"::",
"create",
"(",
"$",
"handle",
",",
"array",
"(",
"'env'",
"=>",
"$",
"this",
"->",
"_env",
",",
"'param'",
"=>",
"$",
"this",
"->",
"_param",
")",
")",
";",
"}",
"uasort",
"(",
"$",
"pool",
",",
"array",
"(",
"$",
"this",
",",
"'__findEventOrder'",
")",
")",
";",
"foreach",
"(",
"$",
"pool",
"as",
"$",
"handle",
"=>",
"$",
"event",
")",
"{",
"$",
"startTime",
"=",
"precision_timer",
"(",
")",
";",
"$",
"queries",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"queryCount",
"(",
")",
";",
"if",
"(",
"$",
"xml",
"=",
"$",
"event",
"->",
"load",
"(",
")",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"xml",
")",
")",
"{",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"xml",
")",
";",
"}",
"else",
"{",
"$",
"wrapper",
"->",
"setValue",
"(",
"$",
"wrapper",
"->",
"getValue",
"(",
")",
".",
"PHP_EOL",
".",
"' '",
".",
"trim",
"(",
"$",
"xml",
")",
")",
";",
"}",
"}",
"$",
"queries",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"queryCount",
"(",
")",
"-",
"$",
"queries",
";",
"Symphony",
"::",
"Profiler",
"(",
")",
"->",
"seed",
"(",
"$",
"startTime",
")",
";",
"Symphony",
"::",
"Profiler",
"(",
")",
"->",
"sample",
"(",
"$",
"handle",
",",
"PROFILE_LAP",
",",
"'Event'",
",",
"$",
"queries",
")",
";",
"}",
"}",
"/**\n * Just after the page events have triggered. Provided with the XML object\n * @delegate FrontendEventPostProcess\n * @param string $context\n * '/frontend/'\n * @param XMLElement $xml\n * The XMLElement to append the Events results to. Event results are\n * contained in a root XMLElement that is the handlised version of\n * their name.\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'FrontendEventPostProcess'",
",",
"'/frontend/'",
",",
"array",
"(",
"'xml'",
"=>",
"&",
"$",
"wrapper",
")",
")",
";",
"}"
] | The processEvents function executes all Events attached to the resolved
page in the correct order determined by `__findEventOrder()`. The results
from the Events are appended to the page's XML. Events execute first,
before Datasources.
@uses FrontendProcessEvents
@uses FrontendEventPostProcess
@param string $events
A string of all the Events attached to this page, comma separated.
@param XMLElement $wrapper
The XMLElement to append the Events results to. Event results are
contained in a root XMLElement that is the handlised version of
their name.
@throws Exception | [
"The",
"processEvents",
"function",
"executes",
"all",
"Events",
"attached",
"to",
"the",
"resolved",
"page",
"in",
"the",
"correct",
"order",
"determined",
"by",
"__findEventOrder",
"()",
".",
"The",
"results",
"from",
"the",
"Events",
"are",
"appended",
"to",
"the",
"page",
"s",
"XML",
".",
"Events",
"execute",
"first",
"before",
"Datasources",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.frontendpage.php#L712-L783 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.frontendpage.php | FrontendPage.__findEventOrder | private function __findEventOrder($a, $b)
{
if ($a->priority() == $b->priority()) {
$a = $a->about();
$b = $b->about();
$handles = array($a['name'], $b['name']);
asort($handles);
return (key($handles) == 0) ? -1 : 1;
}
return $a->priority() > $b->priority() ? -1 : 1;
} | php | private function __findEventOrder($a, $b)
{
if ($a->priority() == $b->priority()) {
$a = $a->about();
$b = $b->about();
$handles = array($a['name'], $b['name']);
asort($handles);
return (key($handles) == 0) ? -1 : 1;
}
return $a->priority() > $b->priority() ? -1 : 1;
} | [
"private",
"function",
"__findEventOrder",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"a",
"->",
"priority",
"(",
")",
"==",
"$",
"b",
"->",
"priority",
"(",
")",
")",
"{",
"$",
"a",
"=",
"$",
"a",
"->",
"about",
"(",
")",
";",
"$",
"b",
"=",
"$",
"b",
"->",
"about",
"(",
")",
";",
"$",
"handles",
"=",
"array",
"(",
"$",
"a",
"[",
"'name'",
"]",
",",
"$",
"b",
"[",
"'name'",
"]",
")",
";",
"asort",
"(",
"$",
"handles",
")",
";",
"return",
"(",
"key",
"(",
"$",
"handles",
")",
"==",
"0",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
"return",
"$",
"a",
"->",
"priority",
"(",
")",
">",
"$",
"b",
"->",
"priority",
"(",
")",
"?",
"-",
"1",
":",
"1",
";",
"}"
] | This function determines the correct order that events should be executed in.
Events are executed based off priority, with `Event::kHIGH` priority executing
first. If there is more than one Event of the same priority, they are then
executed in alphabetical order. This function is designed to be used with
PHP's uasort function.
@link http://php.net/manual/en/function.uasort.php
@param Event $a
@param Event $b
@return integer | [
"This",
"function",
"determines",
"the",
"correct",
"order",
"that",
"events",
"should",
"be",
"executed",
"in",
".",
"Events",
"are",
"executed",
"based",
"off",
"priority",
"with",
"Event",
"::",
"kHIGH",
"priority",
"executing",
"first",
".",
"If",
"there",
"is",
"more",
"than",
"one",
"Event",
"of",
"the",
"same",
"priority",
"they",
"are",
"then",
"executed",
"in",
"alphabetical",
"order",
".",
"This",
"function",
"is",
"designed",
"to",
"be",
"used",
"with",
"PHP",
"s",
"uasort",
"function",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.frontendpage.php#L797-L809 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.frontendpage.php | FrontendPage.processDatasources | public function processDatasources($datasources, XMLElement &$wrapper, array $params = array())
{
if (trim($datasources) == '') {
return;
}
$datasources = preg_split('/,\s*/i', $datasources, -1, PREG_SPLIT_NO_EMPTY);
$datasources = array_map('trim', $datasources);
if (!is_array($datasources) || empty($datasources)) {
return;
}
$this->_env['pool'] = $params;
$pool = $params;
$dependencies = array();
foreach ($datasources as $handle) {
$pool[$handle] = DatasourceManager::create($handle, array(), false);
$dependencies[$handle] = $pool[$handle]->getDependencies();
}
$dsOrder = $this->__findDatasourceOrder($dependencies);
foreach ($dsOrder as $handle) {
$startTime = precision_timer();
$queries = Symphony::Database()->queryCount();
// default to no XML
$xml = null;
$ds = $pool[$handle];
// Handle redirect on empty setting correctly RE: #1539
try {
$ds->processParameters(array('env' => $this->_env, 'param' => $this->_param));
} catch (FrontendPageNotFoundException $e) {
// Work around. This ensures the 404 page is displayed and
// is not picked up by the default catch() statement below
FrontendPageNotFoundExceptionHandler::render($e);
}
/**
* Allows extensions to execute the data source themselves (e.g. for caching)
* and providing their own output XML instead
*
* @since Symphony 2.3
* @delegate DataSourcePreExecute
* @param string $context
* '/frontend/'
* @param DataSource $datasource
* The Datasource object
* @param mixed $xml
* The XML output of the data source. Can be an `XMLElement` or string.
* @param array $param_pool
* The existing param pool including output parameters of any previous data sources
*/
Symphony::ExtensionManager()->notifyMembers('DataSourcePreExecute', '/frontend/', array(
'datasource' => &$ds,
'xml' => &$xml,
'param_pool' => &$this->_env['pool']
));
// if the XML is still null, an extension has not run the data source, so run normally
// This is deprecated and will be replaced by execute in Symphony 3.0.0
if (is_null($xml)) {
$xml = $ds->grab($this->_env['pool']);
}
if ($xml) {
/**
* After the datasource has executed, either by itself or via the
* `DataSourcePreExecute` delegate, and if the `$xml` variable is truthy,
* this delegate allows extensions to modify the output XML and parameter pool
*
* @since Symphony 2.3
* @delegate DataSourcePostExecute
* @param string $context
* '/frontend/'
* @param DataSource $datasource
* The Datasource object
* @param mixed $xml
* The XML output of the data source. Can be an `XMLElement` or string.
* @param array $param_pool
* The existing param pool including output parameters of any previous data sources
*/
Symphony::ExtensionManager()->notifyMembers('DataSourcePostExecute', '/frontend/', array(
'datasource' => $ds,
'xml' => &$xml,
'param_pool' => &$this->_env['pool']
));
if ($xml instanceof XMLElement) {
$wrapper->appendChild($xml);
} else {
$wrapper->appendChild(
' ' . trim($xml) . PHP_EOL
);
}
}
$queries = Symphony::Database()->queryCount() - $queries;
Symphony::Profiler()->seed($startTime);
Symphony::Profiler()->sample($handle, PROFILE_LAP, 'Datasource', $queries);
unset($ds);
}
} | php | public function processDatasources($datasources, XMLElement &$wrapper, array $params = array())
{
if (trim($datasources) == '') {
return;
}
$datasources = preg_split('/,\s*/i', $datasources, -1, PREG_SPLIT_NO_EMPTY);
$datasources = array_map('trim', $datasources);
if (!is_array($datasources) || empty($datasources)) {
return;
}
$this->_env['pool'] = $params;
$pool = $params;
$dependencies = array();
foreach ($datasources as $handle) {
$pool[$handle] = DatasourceManager::create($handle, array(), false);
$dependencies[$handle] = $pool[$handle]->getDependencies();
}
$dsOrder = $this->__findDatasourceOrder($dependencies);
foreach ($dsOrder as $handle) {
$startTime = precision_timer();
$queries = Symphony::Database()->queryCount();
// default to no XML
$xml = null;
$ds = $pool[$handle];
// Handle redirect on empty setting correctly RE: #1539
try {
$ds->processParameters(array('env' => $this->_env, 'param' => $this->_param));
} catch (FrontendPageNotFoundException $e) {
// Work around. This ensures the 404 page is displayed and
// is not picked up by the default catch() statement below
FrontendPageNotFoundExceptionHandler::render($e);
}
/**
* Allows extensions to execute the data source themselves (e.g. for caching)
* and providing their own output XML instead
*
* @since Symphony 2.3
* @delegate DataSourcePreExecute
* @param string $context
* '/frontend/'
* @param DataSource $datasource
* The Datasource object
* @param mixed $xml
* The XML output of the data source. Can be an `XMLElement` or string.
* @param array $param_pool
* The existing param pool including output parameters of any previous data sources
*/
Symphony::ExtensionManager()->notifyMembers('DataSourcePreExecute', '/frontend/', array(
'datasource' => &$ds,
'xml' => &$xml,
'param_pool' => &$this->_env['pool']
));
// if the XML is still null, an extension has not run the data source, so run normally
// This is deprecated and will be replaced by execute in Symphony 3.0.0
if (is_null($xml)) {
$xml = $ds->grab($this->_env['pool']);
}
if ($xml) {
/**
* After the datasource has executed, either by itself or via the
* `DataSourcePreExecute` delegate, and if the `$xml` variable is truthy,
* this delegate allows extensions to modify the output XML and parameter pool
*
* @since Symphony 2.3
* @delegate DataSourcePostExecute
* @param string $context
* '/frontend/'
* @param DataSource $datasource
* The Datasource object
* @param mixed $xml
* The XML output of the data source. Can be an `XMLElement` or string.
* @param array $param_pool
* The existing param pool including output parameters of any previous data sources
*/
Symphony::ExtensionManager()->notifyMembers('DataSourcePostExecute', '/frontend/', array(
'datasource' => $ds,
'xml' => &$xml,
'param_pool' => &$this->_env['pool']
));
if ($xml instanceof XMLElement) {
$wrapper->appendChild($xml);
} else {
$wrapper->appendChild(
' ' . trim($xml) . PHP_EOL
);
}
}
$queries = Symphony::Database()->queryCount() - $queries;
Symphony::Profiler()->seed($startTime);
Symphony::Profiler()->sample($handle, PROFILE_LAP, 'Datasource', $queries);
unset($ds);
}
} | [
"public",
"function",
"processDatasources",
"(",
"$",
"datasources",
",",
"XMLElement",
"&",
"$",
"wrapper",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"trim",
"(",
"$",
"datasources",
")",
"==",
"''",
")",
"{",
"return",
";",
"}",
"$",
"datasources",
"=",
"preg_split",
"(",
"'/,\\s*/i'",
",",
"$",
"datasources",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"$",
"datasources",
"=",
"array_map",
"(",
"'trim'",
",",
"$",
"datasources",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"datasources",
")",
"||",
"empty",
"(",
"$",
"datasources",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"_env",
"[",
"'pool'",
"]",
"=",
"$",
"params",
";",
"$",
"pool",
"=",
"$",
"params",
";",
"$",
"dependencies",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"datasources",
"as",
"$",
"handle",
")",
"{",
"$",
"pool",
"[",
"$",
"handle",
"]",
"=",
"DatasourceManager",
"::",
"create",
"(",
"$",
"handle",
",",
"array",
"(",
")",
",",
"false",
")",
";",
"$",
"dependencies",
"[",
"$",
"handle",
"]",
"=",
"$",
"pool",
"[",
"$",
"handle",
"]",
"->",
"getDependencies",
"(",
")",
";",
"}",
"$",
"dsOrder",
"=",
"$",
"this",
"->",
"__findDatasourceOrder",
"(",
"$",
"dependencies",
")",
";",
"foreach",
"(",
"$",
"dsOrder",
"as",
"$",
"handle",
")",
"{",
"$",
"startTime",
"=",
"precision_timer",
"(",
")",
";",
"$",
"queries",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"queryCount",
"(",
")",
";",
"// default to no XML",
"$",
"xml",
"=",
"null",
";",
"$",
"ds",
"=",
"$",
"pool",
"[",
"$",
"handle",
"]",
";",
"// Handle redirect on empty setting correctly RE: #1539",
"try",
"{",
"$",
"ds",
"->",
"processParameters",
"(",
"array",
"(",
"'env'",
"=>",
"$",
"this",
"->",
"_env",
",",
"'param'",
"=>",
"$",
"this",
"->",
"_param",
")",
")",
";",
"}",
"catch",
"(",
"FrontendPageNotFoundException",
"$",
"e",
")",
"{",
"// Work around. This ensures the 404 page is displayed and",
"// is not picked up by the default catch() statement below",
"FrontendPageNotFoundExceptionHandler",
"::",
"render",
"(",
"$",
"e",
")",
";",
"}",
"/**\n * Allows extensions to execute the data source themselves (e.g. for caching)\n * and providing their own output XML instead\n *\n * @since Symphony 2.3\n * @delegate DataSourcePreExecute\n * @param string $context\n * '/frontend/'\n * @param DataSource $datasource\n * The Datasource object\n * @param mixed $xml\n * The XML output of the data source. Can be an `XMLElement` or string.\n * @param array $param_pool\n * The existing param pool including output parameters of any previous data sources\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'DataSourcePreExecute'",
",",
"'/frontend/'",
",",
"array",
"(",
"'datasource'",
"=>",
"&",
"$",
"ds",
",",
"'xml'",
"=>",
"&",
"$",
"xml",
",",
"'param_pool'",
"=>",
"&",
"$",
"this",
"->",
"_env",
"[",
"'pool'",
"]",
")",
")",
";",
"// if the XML is still null, an extension has not run the data source, so run normally",
"// This is deprecated and will be replaced by execute in Symphony 3.0.0",
"if",
"(",
"is_null",
"(",
"$",
"xml",
")",
")",
"{",
"$",
"xml",
"=",
"$",
"ds",
"->",
"grab",
"(",
"$",
"this",
"->",
"_env",
"[",
"'pool'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"xml",
")",
"{",
"/**\n * After the datasource has executed, either by itself or via the\n * `DataSourcePreExecute` delegate, and if the `$xml` variable is truthy,\n * this delegate allows extensions to modify the output XML and parameter pool\n *\n * @since Symphony 2.3\n * @delegate DataSourcePostExecute\n * @param string $context\n * '/frontend/'\n * @param DataSource $datasource\n * The Datasource object\n * @param mixed $xml\n * The XML output of the data source. Can be an `XMLElement` or string.\n * @param array $param_pool\n * The existing param pool including output parameters of any previous data sources\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'DataSourcePostExecute'",
",",
"'/frontend/'",
",",
"array",
"(",
"'datasource'",
"=>",
"$",
"ds",
",",
"'xml'",
"=>",
"&",
"$",
"xml",
",",
"'param_pool'",
"=>",
"&",
"$",
"this",
"->",
"_env",
"[",
"'pool'",
"]",
")",
")",
";",
"if",
"(",
"$",
"xml",
"instanceof",
"XMLElement",
")",
"{",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"xml",
")",
";",
"}",
"else",
"{",
"$",
"wrapper",
"->",
"appendChild",
"(",
"' '",
".",
"trim",
"(",
"$",
"xml",
")",
".",
"PHP_EOL",
")",
";",
"}",
"}",
"$",
"queries",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"queryCount",
"(",
")",
"-",
"$",
"queries",
";",
"Symphony",
"::",
"Profiler",
"(",
")",
"->",
"seed",
"(",
"$",
"startTime",
")",
";",
"Symphony",
"::",
"Profiler",
"(",
")",
"->",
"sample",
"(",
"$",
"handle",
",",
"PROFILE_LAP",
",",
"'Datasource'",
",",
"$",
"queries",
")",
";",
"unset",
"(",
"$",
"ds",
")",
";",
"}",
"}"
] | Given an array of all the Datasources for this page, sort them into the
correct execution order and append the Datasource results to the
page XML. If the Datasource provides any parameters, they will be
added to the `$env` pool for use by other Datasources and eventual
inclusion into the page parameters.
@param string $datasources
A string of Datasource's attached to this page, comma separated.
@param XMLElement $wrapper
The XMLElement to append the Datasource results to. Datasource
results are contained in a root XMLElement that is the handlised
version of their name.
@param array $params
Any params to automatically add to the `$env` pool, by default this
is an empty array. It looks like Symphony does not utilise this parameter
at all
@throws Exception | [
"Given",
"an",
"array",
"of",
"all",
"the",
"Datasources",
"for",
"this",
"page",
"sort",
"them",
"into",
"the",
"correct",
"execution",
"order",
"and",
"append",
"the",
"Datasource",
"results",
"to",
"the",
"page",
"XML",
".",
"If",
"the",
"Datasource",
"provides",
"any",
"parameters",
"they",
"will",
"be",
"added",
"to",
"the",
"$env",
"pool",
"for",
"use",
"by",
"other",
"Datasources",
"and",
"eventual",
"inclusion",
"into",
"the",
"page",
"parameters",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.frontendpage.php#L830-L935 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.frontendpage.php | FrontendPage.__findDatasourceOrder | private function __findDatasourceOrder($dependenciesList)
{
if (!is_array($dependenciesList) || empty($dependenciesList)) {
return;
}
foreach ($dependenciesList as $handle => $dependencies) {
foreach ($dependencies as $i => $dependency) {
$dependency = explode('.', $dependency);
$dependenciesList[$handle][$i] = reset($dependency);
}
}
$orderedList = array();
$dsKeyArray = $this->__buildDatasourcePooledParamList(array_keys($dependenciesList));
// 1. First do a cleanup of each dependency list, removing non-existant DS's and find
// the ones that have no dependencies, removing them from the list
foreach ($dependenciesList as $handle => $dependencies) {
$dependenciesList[$handle] = @array_intersect($dsKeyArray, $dependencies);
if (empty($dependenciesList[$handle])) {
unset($dependenciesList[$handle]);
$orderedList[] = str_replace('_', '-', $handle);
}
}
// 2. Iterate over the remaining DS's. Find if all their dependencies are
// in the $orderedList array. Keep iterating until all DS's are in that list
// or there are circular dependencies (list doesn't change between iterations
// of the while loop)
do {
$last_count = count($dependenciesList);
foreach ($dependenciesList as $handle => $dependencies) {
if (General::in_array_all(array_map(function($a) {return str_replace('$ds-', '', $a);}, $dependencies), $orderedList)) {
$orderedList[] = str_replace('_', '-', $handle);
unset($dependenciesList[$handle]);
}
}
} while (!empty($dependenciesList) && $last_count > count($dependenciesList));
if (!empty($dependenciesList)) {
$orderedList = array_merge($orderedList, array_keys($dependenciesList));
}
return array_map(function($a) {return str_replace('-', '_', $a);}, $orderedList);
} | php | private function __findDatasourceOrder($dependenciesList)
{
if (!is_array($dependenciesList) || empty($dependenciesList)) {
return;
}
foreach ($dependenciesList as $handle => $dependencies) {
foreach ($dependencies as $i => $dependency) {
$dependency = explode('.', $dependency);
$dependenciesList[$handle][$i] = reset($dependency);
}
}
$orderedList = array();
$dsKeyArray = $this->__buildDatasourcePooledParamList(array_keys($dependenciesList));
// 1. First do a cleanup of each dependency list, removing non-existant DS's and find
// the ones that have no dependencies, removing them from the list
foreach ($dependenciesList as $handle => $dependencies) {
$dependenciesList[$handle] = @array_intersect($dsKeyArray, $dependencies);
if (empty($dependenciesList[$handle])) {
unset($dependenciesList[$handle]);
$orderedList[] = str_replace('_', '-', $handle);
}
}
// 2. Iterate over the remaining DS's. Find if all their dependencies are
// in the $orderedList array. Keep iterating until all DS's are in that list
// or there are circular dependencies (list doesn't change between iterations
// of the while loop)
do {
$last_count = count($dependenciesList);
foreach ($dependenciesList as $handle => $dependencies) {
if (General::in_array_all(array_map(function($a) {return str_replace('$ds-', '', $a);}, $dependencies), $orderedList)) {
$orderedList[] = str_replace('_', '-', $handle);
unset($dependenciesList[$handle]);
}
}
} while (!empty($dependenciesList) && $last_count > count($dependenciesList));
if (!empty($dependenciesList)) {
$orderedList = array_merge($orderedList, array_keys($dependenciesList));
}
return array_map(function($a) {return str_replace('-', '_', $a);}, $orderedList);
} | [
"private",
"function",
"__findDatasourceOrder",
"(",
"$",
"dependenciesList",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"dependenciesList",
")",
"||",
"empty",
"(",
"$",
"dependenciesList",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"dependenciesList",
"as",
"$",
"handle",
"=>",
"$",
"dependencies",
")",
"{",
"foreach",
"(",
"$",
"dependencies",
"as",
"$",
"i",
"=>",
"$",
"dependency",
")",
"{",
"$",
"dependency",
"=",
"explode",
"(",
"'.'",
",",
"$",
"dependency",
")",
";",
"$",
"dependenciesList",
"[",
"$",
"handle",
"]",
"[",
"$",
"i",
"]",
"=",
"reset",
"(",
"$",
"dependency",
")",
";",
"}",
"}",
"$",
"orderedList",
"=",
"array",
"(",
")",
";",
"$",
"dsKeyArray",
"=",
"$",
"this",
"->",
"__buildDatasourcePooledParamList",
"(",
"array_keys",
"(",
"$",
"dependenciesList",
")",
")",
";",
"// 1. First do a cleanup of each dependency list, removing non-existant DS's and find",
"// the ones that have no dependencies, removing them from the list",
"foreach",
"(",
"$",
"dependenciesList",
"as",
"$",
"handle",
"=>",
"$",
"dependencies",
")",
"{",
"$",
"dependenciesList",
"[",
"$",
"handle",
"]",
"=",
"@",
"array_intersect",
"(",
"$",
"dsKeyArray",
",",
"$",
"dependencies",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"dependenciesList",
"[",
"$",
"handle",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"dependenciesList",
"[",
"$",
"handle",
"]",
")",
";",
"$",
"orderedList",
"[",
"]",
"=",
"str_replace",
"(",
"'_'",
",",
"'-'",
",",
"$",
"handle",
")",
";",
"}",
"}",
"// 2. Iterate over the remaining DS's. Find if all their dependencies are",
"// in the $orderedList array. Keep iterating until all DS's are in that list",
"// or there are circular dependencies (list doesn't change between iterations",
"// of the while loop)",
"do",
"{",
"$",
"last_count",
"=",
"count",
"(",
"$",
"dependenciesList",
")",
";",
"foreach",
"(",
"$",
"dependenciesList",
"as",
"$",
"handle",
"=>",
"$",
"dependencies",
")",
"{",
"if",
"(",
"General",
"::",
"in_array_all",
"(",
"array_map",
"(",
"function",
"(",
"$",
"a",
")",
"{",
"return",
"str_replace",
"(",
"'$ds-'",
",",
"''",
",",
"$",
"a",
")",
";",
"}",
",",
"$",
"dependencies",
")",
",",
"$",
"orderedList",
")",
")",
"{",
"$",
"orderedList",
"[",
"]",
"=",
"str_replace",
"(",
"'_'",
",",
"'-'",
",",
"$",
"handle",
")",
";",
"unset",
"(",
"$",
"dependenciesList",
"[",
"$",
"handle",
"]",
")",
";",
"}",
"}",
"}",
"while",
"(",
"!",
"empty",
"(",
"$",
"dependenciesList",
")",
"&&",
"$",
"last_count",
">",
"count",
"(",
"$",
"dependenciesList",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"dependenciesList",
")",
")",
"{",
"$",
"orderedList",
"=",
"array_merge",
"(",
"$",
"orderedList",
",",
"array_keys",
"(",
"$",
"dependenciesList",
")",
")",
";",
"}",
"return",
"array_map",
"(",
"function",
"(",
"$",
"a",
")",
"{",
"return",
"str_replace",
"(",
"'-'",
",",
"'_'",
",",
"$",
"a",
")",
";",
"}",
",",
"$",
"orderedList",
")",
";",
"}"
] | The function finds the correct order Datasources need to be processed in to
satisfy all dependencies that parameters can resolve correctly and in time for
other Datasources to filter on.
@param array $dependenciesList
An associative array with the key being the Datasource handle and the values
being it's dependencies.
@return array
The sorted array of Datasources in order of how they should be executed | [
"The",
"function",
"finds",
"the",
"correct",
"order",
"Datasources",
"need",
"to",
"be",
"processed",
"in",
"to",
"satisfy",
"all",
"dependencies",
"that",
"parameters",
"can",
"resolve",
"correctly",
"and",
"in",
"time",
"for",
"other",
"Datasources",
"to",
"filter",
"on",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.frontendpage.php#L948-L995 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.frontendpage.php | FrontendPage.__buildDatasourcePooledParamList | private function __buildDatasourcePooledParamList($datasources)
{
if (!is_array($datasources) || empty($datasources)) {
return array();
}
$list = array();
foreach ($datasources as $handle) {
$rootelement = str_replace('_', '-', $handle);
$list[] = '$ds-' . $rootelement;
}
return $list;
} | php | private function __buildDatasourcePooledParamList($datasources)
{
if (!is_array($datasources) || empty($datasources)) {
return array();
}
$list = array();
foreach ($datasources as $handle) {
$rootelement = str_replace('_', '-', $handle);
$list[] = '$ds-' . $rootelement;
}
return $list;
} | [
"private",
"function",
"__buildDatasourcePooledParamList",
"(",
"$",
"datasources",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"datasources",
")",
"||",
"empty",
"(",
"$",
"datasources",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"list",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"datasources",
"as",
"$",
"handle",
")",
"{",
"$",
"rootelement",
"=",
"str_replace",
"(",
"'_'",
",",
"'-'",
",",
"$",
"handle",
")",
";",
"$",
"list",
"[",
"]",
"=",
"'$ds-'",
".",
"$",
"rootelement",
";",
"}",
"return",
"$",
"list",
";",
"}"
] | Given an array of datasource dependancies, this function will translate
each of them to be a valid datasource handle.
@param array $datasources
The datasource dependencies
@return array
An array of the handlised datasources | [
"Given",
"an",
"array",
"of",
"datasource",
"dependancies",
"this",
"function",
"will",
"translate",
"each",
"of",
"them",
"to",
"be",
"a",
"valid",
"datasource",
"handle",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.frontendpage.php#L1006-L1020 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.datasource.php | Datasource.execute | public function execute(array &$param_pool = null)
{
$result = new XMLElement($this->dsParamROOTELEMENT);
try {
$result = $this->execute($param_pool);
} catch (FrontendPageNotFoundException $e) {
// Work around. This ensures the 404 page is displayed and
// is not picked up by the default catch() statement below
FrontendPageNotFoundExceptionHandler::render($e);
} catch (Exception $e) {
$result->appendChild(new XMLElement('error', General::wrapInCDATA($e->getMessage())));
return $result;
}
if ($this->_force_empty_result) {
$result = $this->emptyXMLSet();
}
if ($this->_negate_result) {
$result = $this->negateXMLSet();
}
return $result;
} | php | public function execute(array &$param_pool = null)
{
$result = new XMLElement($this->dsParamROOTELEMENT);
try {
$result = $this->execute($param_pool);
} catch (FrontendPageNotFoundException $e) {
// Work around. This ensures the 404 page is displayed and
// is not picked up by the default catch() statement below
FrontendPageNotFoundExceptionHandler::render($e);
} catch (Exception $e) {
$result->appendChild(new XMLElement('error', General::wrapInCDATA($e->getMessage())));
return $result;
}
if ($this->_force_empty_result) {
$result = $this->emptyXMLSet();
}
if ($this->_negate_result) {
$result = $this->negateXMLSet();
}
return $result;
} | [
"public",
"function",
"execute",
"(",
"array",
"&",
"$",
"param_pool",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"new",
"XMLElement",
"(",
"$",
"this",
"->",
"dsParamROOTELEMENT",
")",
";",
"try",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"execute",
"(",
"$",
"param_pool",
")",
";",
"}",
"catch",
"(",
"FrontendPageNotFoundException",
"$",
"e",
")",
"{",
"// Work around. This ensures the 404 page is displayed and",
"// is not picked up by the default catch() statement below",
"FrontendPageNotFoundExceptionHandler",
"::",
"render",
"(",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"result",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'error'",
",",
"General",
"::",
"wrapInCDATA",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
")",
";",
"return",
"$",
"result",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_force_empty_result",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"emptyXMLSet",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_negate_result",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"negateXMLSet",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | The meat of the Datasource, this function includes the datasource
type's file that will preform the logic to return the data for this datasource
It is passed the current parameters.
@param array $param_pool
The current parameter pool that this Datasource can use when filtering
and finding Entries or data.
@return XMLElement
The XMLElement to add into the XML for a page. | [
"The",
"meat",
"of",
"the",
"Datasource",
"this",
"function",
"includes",
"the",
"datasource",
"type",
"s",
"file",
"that",
"will",
"preform",
"the",
"logic",
"to",
"return",
"the",
"data",
"for",
"this",
"datasource",
"It",
"is",
"passed",
"the",
"current",
"parameters",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.datasource.php#L181-L205 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.datasource.php | Datasource.determineFilterType | public static function determineFilterType($value)
{
// Check for two possible combos
// 1. The old pattern, which is ' + '
// 2. A new pattern, which accounts for '+' === ' ' in urls
$pattern = '/(\s+\+\s+)|(\+\+\+)/';
return preg_match($pattern, $value) === 1 ? Datasource::FILTER_AND : Datasource::FILTER_OR;
} | php | public static function determineFilterType($value)
{
// Check for two possible combos
// 1. The old pattern, which is ' + '
// 2. A new pattern, which accounts for '+' === ' ' in urls
$pattern = '/(\s+\+\s+)|(\+\+\+)/';
return preg_match($pattern, $value) === 1 ? Datasource::FILTER_AND : Datasource::FILTER_OR;
} | [
"public",
"static",
"function",
"determineFilterType",
"(",
"$",
"value",
")",
"{",
"// Check for two possible combos",
"// 1. The old pattern, which is ' + '",
"// 2. A new pattern, which accounts for '+' === ' ' in urls",
"$",
"pattern",
"=",
"'/(\\s+\\+\\s+)|(\\+\\+\\+)/'",
";",
"return",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"value",
")",
"===",
"1",
"?",
"Datasource",
"::",
"FILTER_AND",
":",
"Datasource",
"::",
"FILTER_OR",
";",
"}"
] | By default, all Symphony filters are considering to be OR and " + " filters
are used for AND. They are all used and Entries must match each filter to be included.
It is possible to use OR filtering in a field by using an ", " to separate the values.
If the filter is "test1, test2", this will match any entries where this field
is test1 OR test2. If the filter is "test1 + test2", this will match entries
where this field is test1 AND test2. The spaces around the + are required.
Not all fields supports this feature.
This function is run on each filter (ie. each field) in a datasource.
@param string $value
The filter string for a field.
@return integer
Datasource::FILTER_OR or Datasource::FILTER_AND | [
"By",
"default",
"all",
"Symphony",
"filters",
"are",
"considering",
"to",
"be",
"OR",
"and",
"+",
"filters",
"are",
"used",
"for",
"AND",
".",
"They",
"are",
"all",
"used",
"and",
"Entries",
"must",
"match",
"each",
"filter",
"to",
"be",
"included",
".",
"It",
"is",
"possible",
"to",
"use",
"OR",
"filtering",
"in",
"a",
"field",
"by",
"using",
"an",
"to",
"separate",
"the",
"values",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.datasource.php#L225-L232 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.datasource.php | Datasource.splitFilter | public static function splitFilter($filter_type, $value)
{
$pattern = $filter_type === Datasource::FILTER_AND ? '\+' : '(?<!\\\\),';
$value = preg_split('/\s*' . $pattern . '\s*/', $value, -1, PREG_SPLIT_NO_EMPTY);
$value = array_map('trim', $value);
$value = array_map(array('Datasource', 'removeEscapedCommas'), $value);
return $value;
} | php | public static function splitFilter($filter_type, $value)
{
$pattern = $filter_type === Datasource::FILTER_AND ? '\+' : '(?<!\\\\),';
$value = preg_split('/\s*' . $pattern . '\s*/', $value, -1, PREG_SPLIT_NO_EMPTY);
$value = array_map('trim', $value);
$value = array_map(array('Datasource', 'removeEscapedCommas'), $value);
return $value;
} | [
"public",
"static",
"function",
"splitFilter",
"(",
"$",
"filter_type",
",",
"$",
"value",
")",
"{",
"$",
"pattern",
"=",
"$",
"filter_type",
"===",
"Datasource",
"::",
"FILTER_AND",
"?",
"'\\+'",
":",
"'(?<!\\\\\\\\),'",
";",
"$",
"value",
"=",
"preg_split",
"(",
"'/\\s*'",
".",
"$",
"pattern",
".",
"'\\s*/'",
",",
"$",
"value",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"$",
"value",
"=",
"array_map",
"(",
"'trim'",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"array_map",
"(",
"array",
"(",
"'Datasource'",
",",
"'removeEscapedCommas'",
")",
",",
"$",
"value",
")",
";",
"return",
"$",
"value",
";",
"}"
] | Splits the filter string value into an array.
@since Symphony 2.7.0
@param int $filter_type
The filter's type, as determined by `determineFilterType()`.
Valid values are Datasource::FILTER_OR or Datasource::FILTER_AND
@param string $value
The filter's value
@return array
The splitted filter value, according to its type | [
"Splits",
"the",
"filter",
"string",
"value",
"into",
"an",
"array",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.datasource.php#L246-L253 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.datasource.php | Datasource.emptyXMLSet | public function emptyXMLSet(XMLElement $xml = null)
{
if (is_null($xml)) {
$xml = new XMLElement($this->dsParamROOTELEMENT);
}
$xml->appendChild($this->__noRecordsFound());
return $xml;
} | php | public function emptyXMLSet(XMLElement $xml = null)
{
if (is_null($xml)) {
$xml = new XMLElement($this->dsParamROOTELEMENT);
}
$xml->appendChild($this->__noRecordsFound());
return $xml;
} | [
"public",
"function",
"emptyXMLSet",
"(",
"XMLElement",
"$",
"xml",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"xml",
")",
")",
"{",
"$",
"xml",
"=",
"new",
"XMLElement",
"(",
"$",
"this",
"->",
"dsParamROOTELEMENT",
")",
";",
"}",
"$",
"xml",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"__noRecordsFound",
"(",
")",
")",
";",
"return",
"$",
"xml",
";",
"}"
] | If there is no results to return this function calls `Datasource::__noRecordsFound`
which appends an XMLElement to the current root element.
@param XMLElement $xml
The root element XMLElement for this datasource. By default, this will
the handle of the datasource, as defined by `$this->dsParamROOTELEMENT`
@return XMLElement | [
"If",
"there",
"is",
"no",
"results",
"to",
"return",
"this",
"function",
"calls",
"Datasource",
"::",
"__noRecordsFound",
"which",
"appends",
"an",
"XMLElement",
"to",
"the",
"current",
"root",
"element",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.datasource.php#L264-L273 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.datasource.php | Datasource.negateXMLSet | public function negateXMLSet(XMLElement $xml = null)
{
if (is_null($xml)) {
$xml = new XMLElement($this->dsParamROOTELEMENT);
}
$xml->appendChild($this->__negateResult());
return $xml;
} | php | public function negateXMLSet(XMLElement $xml = null)
{
if (is_null($xml)) {
$xml = new XMLElement($this->dsParamROOTELEMENT);
}
$xml->appendChild($this->__negateResult());
return $xml;
} | [
"public",
"function",
"negateXMLSet",
"(",
"XMLElement",
"$",
"xml",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"xml",
")",
")",
"{",
"$",
"xml",
"=",
"new",
"XMLElement",
"(",
"$",
"this",
"->",
"dsParamROOTELEMENT",
")",
";",
"}",
"$",
"xml",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"__negateResult",
"(",
")",
")",
";",
"return",
"$",
"xml",
";",
"}"
] | If the datasource has been negated this function calls `Datasource::__negateResult`
which appends an XMLElement to the current root element.
@param XMLElement $xml
The root element XMLElement for this datasource. By default, this will
the handle of the datasource, as defined by `$this->dsParamROOTELEMENT`
@return XMLElement | [
"If",
"the",
"datasource",
"has",
"been",
"negated",
"this",
"function",
"calls",
"Datasource",
"::",
"__negateResult",
"which",
"appends",
"an",
"XMLElement",
"to",
"the",
"current",
"root",
"element",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.datasource.php#L284-L293 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.datasource.php | Datasource.processParameters | public function processParameters(array $env = null)
{
if ($env) {
$this->_env = $env;
}
if ((isset($this->_env) && is_array($this->_env)) && isset($this->dsParamFILTERS) && is_array($this->dsParamFILTERS) && !empty($this->dsParamFILTERS)) {
foreach ($this->dsParamFILTERS as $key => $value) {
$value = stripslashes($value);
$new_value = $this->__processParametersInString($value, $this->_env);
// If a filter gets evaluated to nothing, eg. ` + ` or ``, then remove
// the filter. Respects / as this may be real from current-path. RE: #1759
if (strlen(trim($new_value)) === 0 || !preg_match('/[^\s|+|,]+/u', $new_value)) {
unset($this->dsParamFILTERS[$key]);
} else {
$this->dsParamFILTERS[$key] = $new_value;
}
}
}
if (isset($this->dsParamORDER)) {
$this->dsParamORDER = $this->__processParametersInString($this->dsParamORDER, $this->_env);
}
if (isset($this->dsParamSORT)) {
$this->dsParamSORT = $this->__processParametersInString($this->dsParamSORT, $this->_env);
}
if (isset($this->dsParamSTARTPAGE)) {
$this->dsParamSTARTPAGE = $this->__processParametersInString($this->dsParamSTARTPAGE, $this->_env);
if ($this->dsParamSTARTPAGE === '') {
$this->dsParamSTARTPAGE = '1';
}
}
if (isset($this->dsParamLIMIT)) {
$this->dsParamLIMIT = $this->__processParametersInString($this->dsParamLIMIT, $this->_env);
}
if (
isset($this->dsParamREQUIREDPARAM)
&& strlen(trim($this->dsParamREQUIREDPARAM)) > 0
&& $this->__processParametersInString(trim($this->dsParamREQUIREDPARAM), $this->_env, false) === ''
) {
$this->_force_empty_result = true; // don't output any XML
$this->dsParamPARAMOUTPUT = null; // don't output any parameters
$this->dsParamINCLUDEDELEMENTS = null; // don't query any fields in this section
return;
}
if (
isset($this->dsParamNEGATEPARAM)
&& strlen(trim($this->dsParamNEGATEPARAM)) > 0
&& $this->__processParametersInString(trim($this->dsParamNEGATEPARAM), $this->_env, false) !== ''
) {
$this->_negate_result = true; // don't output any XML
$this->dsParamPARAMOUTPUT = null; // don't output any parameters
$this->dsParamINCLUDEDELEMENTS = null; // don't query any fields in this section
return;
}
$this->_param_output_only = ((!isset($this->dsParamINCLUDEDELEMENTS) || !is_array($this->dsParamINCLUDEDELEMENTS) || empty($this->dsParamINCLUDEDELEMENTS)) && !isset($this->dsParamGROUP));
if (isset($this->dsParamREDIRECTONEMPTY) && $this->dsParamREDIRECTONEMPTY === 'yes' && $this->_force_empty_result) {
throw new FrontendPageNotFoundException;
}
} | php | public function processParameters(array $env = null)
{
if ($env) {
$this->_env = $env;
}
if ((isset($this->_env) && is_array($this->_env)) && isset($this->dsParamFILTERS) && is_array($this->dsParamFILTERS) && !empty($this->dsParamFILTERS)) {
foreach ($this->dsParamFILTERS as $key => $value) {
$value = stripslashes($value);
$new_value = $this->__processParametersInString($value, $this->_env);
// If a filter gets evaluated to nothing, eg. ` + ` or ``, then remove
// the filter. Respects / as this may be real from current-path. RE: #1759
if (strlen(trim($new_value)) === 0 || !preg_match('/[^\s|+|,]+/u', $new_value)) {
unset($this->dsParamFILTERS[$key]);
} else {
$this->dsParamFILTERS[$key] = $new_value;
}
}
}
if (isset($this->dsParamORDER)) {
$this->dsParamORDER = $this->__processParametersInString($this->dsParamORDER, $this->_env);
}
if (isset($this->dsParamSORT)) {
$this->dsParamSORT = $this->__processParametersInString($this->dsParamSORT, $this->_env);
}
if (isset($this->dsParamSTARTPAGE)) {
$this->dsParamSTARTPAGE = $this->__processParametersInString($this->dsParamSTARTPAGE, $this->_env);
if ($this->dsParamSTARTPAGE === '') {
$this->dsParamSTARTPAGE = '1';
}
}
if (isset($this->dsParamLIMIT)) {
$this->dsParamLIMIT = $this->__processParametersInString($this->dsParamLIMIT, $this->_env);
}
if (
isset($this->dsParamREQUIREDPARAM)
&& strlen(trim($this->dsParamREQUIREDPARAM)) > 0
&& $this->__processParametersInString(trim($this->dsParamREQUIREDPARAM), $this->_env, false) === ''
) {
$this->_force_empty_result = true; // don't output any XML
$this->dsParamPARAMOUTPUT = null; // don't output any parameters
$this->dsParamINCLUDEDELEMENTS = null; // don't query any fields in this section
return;
}
if (
isset($this->dsParamNEGATEPARAM)
&& strlen(trim($this->dsParamNEGATEPARAM)) > 0
&& $this->__processParametersInString(trim($this->dsParamNEGATEPARAM), $this->_env, false) !== ''
) {
$this->_negate_result = true; // don't output any XML
$this->dsParamPARAMOUTPUT = null; // don't output any parameters
$this->dsParamINCLUDEDELEMENTS = null; // don't query any fields in this section
return;
}
$this->_param_output_only = ((!isset($this->dsParamINCLUDEDELEMENTS) || !is_array($this->dsParamINCLUDEDELEMENTS) || empty($this->dsParamINCLUDEDELEMENTS)) && !isset($this->dsParamGROUP));
if (isset($this->dsParamREDIRECTONEMPTY) && $this->dsParamREDIRECTONEMPTY === 'yes' && $this->_force_empty_result) {
throw new FrontendPageNotFoundException;
}
} | [
"public",
"function",
"processParameters",
"(",
"array",
"$",
"env",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"env",
")",
"{",
"$",
"this",
"->",
"_env",
"=",
"$",
"env",
";",
"}",
"if",
"(",
"(",
"isset",
"(",
"$",
"this",
"->",
"_env",
")",
"&&",
"is_array",
"(",
"$",
"this",
"->",
"_env",
")",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"dsParamFILTERS",
")",
"&&",
"is_array",
"(",
"$",
"this",
"->",
"dsParamFILTERS",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"dsParamFILTERS",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"dsParamFILTERS",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"stripslashes",
"(",
"$",
"value",
")",
";",
"$",
"new_value",
"=",
"$",
"this",
"->",
"__processParametersInString",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"_env",
")",
";",
"// If a filter gets evaluated to nothing, eg. ` + ` or ``, then remove",
"// the filter. Respects / as this may be real from current-path. RE: #1759",
"if",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"new_value",
")",
")",
"===",
"0",
"||",
"!",
"preg_match",
"(",
"'/[^\\s|+|,]+/u'",
",",
"$",
"new_value",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"dsParamFILTERS",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"dsParamFILTERS",
"[",
"$",
"key",
"]",
"=",
"$",
"new_value",
";",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"dsParamORDER",
")",
")",
"{",
"$",
"this",
"->",
"dsParamORDER",
"=",
"$",
"this",
"->",
"__processParametersInString",
"(",
"$",
"this",
"->",
"dsParamORDER",
",",
"$",
"this",
"->",
"_env",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"dsParamSORT",
")",
")",
"{",
"$",
"this",
"->",
"dsParamSORT",
"=",
"$",
"this",
"->",
"__processParametersInString",
"(",
"$",
"this",
"->",
"dsParamSORT",
",",
"$",
"this",
"->",
"_env",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"dsParamSTARTPAGE",
")",
")",
"{",
"$",
"this",
"->",
"dsParamSTARTPAGE",
"=",
"$",
"this",
"->",
"__processParametersInString",
"(",
"$",
"this",
"->",
"dsParamSTARTPAGE",
",",
"$",
"this",
"->",
"_env",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dsParamSTARTPAGE",
"===",
"''",
")",
"{",
"$",
"this",
"->",
"dsParamSTARTPAGE",
"=",
"'1'",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"dsParamLIMIT",
")",
")",
"{",
"$",
"this",
"->",
"dsParamLIMIT",
"=",
"$",
"this",
"->",
"__processParametersInString",
"(",
"$",
"this",
"->",
"dsParamLIMIT",
",",
"$",
"this",
"->",
"_env",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"dsParamREQUIREDPARAM",
")",
"&&",
"strlen",
"(",
"trim",
"(",
"$",
"this",
"->",
"dsParamREQUIREDPARAM",
")",
")",
">",
"0",
"&&",
"$",
"this",
"->",
"__processParametersInString",
"(",
"trim",
"(",
"$",
"this",
"->",
"dsParamREQUIREDPARAM",
")",
",",
"$",
"this",
"->",
"_env",
",",
"false",
")",
"===",
"''",
")",
"{",
"$",
"this",
"->",
"_force_empty_result",
"=",
"true",
";",
"// don't output any XML",
"$",
"this",
"->",
"dsParamPARAMOUTPUT",
"=",
"null",
";",
"// don't output any parameters",
"$",
"this",
"->",
"dsParamINCLUDEDELEMENTS",
"=",
"null",
";",
"// don't query any fields in this section",
"return",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"dsParamNEGATEPARAM",
")",
"&&",
"strlen",
"(",
"trim",
"(",
"$",
"this",
"->",
"dsParamNEGATEPARAM",
")",
")",
">",
"0",
"&&",
"$",
"this",
"->",
"__processParametersInString",
"(",
"trim",
"(",
"$",
"this",
"->",
"dsParamNEGATEPARAM",
")",
",",
"$",
"this",
"->",
"_env",
",",
"false",
")",
"!==",
"''",
")",
"{",
"$",
"this",
"->",
"_negate_result",
"=",
"true",
";",
"// don't output any XML",
"$",
"this",
"->",
"dsParamPARAMOUTPUT",
"=",
"null",
";",
"// don't output any parameters",
"$",
"this",
"->",
"dsParamINCLUDEDELEMENTS",
"=",
"null",
";",
"// don't query any fields in this section",
"return",
";",
"}",
"$",
"this",
"->",
"_param_output_only",
"=",
"(",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"dsParamINCLUDEDELEMENTS",
")",
"||",
"!",
"is_array",
"(",
"$",
"this",
"->",
"dsParamINCLUDEDELEMENTS",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"dsParamINCLUDEDELEMENTS",
")",
")",
"&&",
"!",
"isset",
"(",
"$",
"this",
"->",
"dsParamGROUP",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"dsParamREDIRECTONEMPTY",
")",
"&&",
"$",
"this",
"->",
"dsParamREDIRECTONEMPTY",
"===",
"'yes'",
"&&",
"$",
"this",
"->",
"_force_empty_result",
")",
"{",
"throw",
"new",
"FrontendPageNotFoundException",
";",
"}",
"}"
] | This function will iterates over the filters and replace any parameters with their
actual values. All other Datasource variables such as sorting, ordering and
pagination variables are also set by this function
@param array $env
The environment variables from the Frontend class which includes
any params set by Symphony or Events or by other Datasources
@throws FrontendPageNotFoundException | [
"This",
"function",
"will",
"iterates",
"over",
"the",
"filters",
"and",
"replace",
"any",
"parameters",
"with",
"their",
"actual",
"values",
".",
"All",
"other",
"Datasource",
"variables",
"such",
"as",
"sorting",
"ordering",
"and",
"pagination",
"variables",
"are",
"also",
"set",
"by",
"this",
"function"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.datasource.php#L329-L396 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.datasource.php | Datasource.parseParamURL | public function parseParamURL($url = null)
{
if (!isset($url)) {
return null;
}
// urlencode parameters
$params = array();
if (preg_match_all('@{([^}]+)}@i', $url, $matches, PREG_SET_ORDER)) {
foreach ($matches as $m) {
$params[$m[1]] = array(
'param' => preg_replace('/:encoded$/', null, $m[1]),
'encode' => preg_match('/:encoded$/', $m[1])
);
}
}
foreach ($params as $key => $info) {
$replacement = $this->__processParametersInString($info['param'], $this->_env, false);
if ($info['encode'] == true) {
$replacement = urlencode($replacement);
}
$url = str_replace("{{$key}}", $replacement, $url);
}
return $url;
} | php | public function parseParamURL($url = null)
{
if (!isset($url)) {
return null;
}
// urlencode parameters
$params = array();
if (preg_match_all('@{([^}]+)}@i', $url, $matches, PREG_SET_ORDER)) {
foreach ($matches as $m) {
$params[$m[1]] = array(
'param' => preg_replace('/:encoded$/', null, $m[1]),
'encode' => preg_match('/:encoded$/', $m[1])
);
}
}
foreach ($params as $key => $info) {
$replacement = $this->__processParametersInString($info['param'], $this->_env, false);
if ($info['encode'] == true) {
$replacement = urlencode($replacement);
}
$url = str_replace("{{$key}}", $replacement, $url);
}
return $url;
} | [
"public",
"function",
"parseParamURL",
"(",
"$",
"url",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"url",
")",
")",
"{",
"return",
"null",
";",
"}",
"// urlencode parameters",
"$",
"params",
"=",
"array",
"(",
")",
";",
"if",
"(",
"preg_match_all",
"(",
"'@{([^}]+)}@i'",
",",
"$",
"url",
",",
"$",
"matches",
",",
"PREG_SET_ORDER",
")",
")",
"{",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"m",
")",
"{",
"$",
"params",
"[",
"$",
"m",
"[",
"1",
"]",
"]",
"=",
"array",
"(",
"'param'",
"=>",
"preg_replace",
"(",
"'/:encoded$/'",
",",
"null",
",",
"$",
"m",
"[",
"1",
"]",
")",
",",
"'encode'",
"=>",
"preg_match",
"(",
"'/:encoded$/'",
",",
"$",
"m",
"[",
"1",
"]",
")",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"info",
")",
"{",
"$",
"replacement",
"=",
"$",
"this",
"->",
"__processParametersInString",
"(",
"$",
"info",
"[",
"'param'",
"]",
",",
"$",
"this",
"->",
"_env",
",",
"false",
")",
";",
"if",
"(",
"$",
"info",
"[",
"'encode'",
"]",
"==",
"true",
")",
"{",
"$",
"replacement",
"=",
"urlencode",
"(",
"$",
"replacement",
")",
";",
"}",
"$",
"url",
"=",
"str_replace",
"(",
"\"{{$key}}\"",
",",
"$",
"replacement",
",",
"$",
"url",
")",
";",
"}",
"return",
"$",
"url",
";",
"}"
] | This function will parse a string (usually a URL) and fully evaluate any
parameters (defined by {$param}) to return the absolute string value.
@since Symphony 2.3
@param string $url
The string (usually a URL) that contains the parameters (or doesn't)
@return string
The parsed URL | [
"This",
"function",
"will",
"parse",
"a",
"string",
"(",
"usually",
"a",
"URL",
")",
"and",
"fully",
"evaluate",
"any",
"parameters",
"(",
"defined",
"by",
"{",
"$param",
"}",
")",
"to",
"return",
"the",
"absolute",
"string",
"value",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.datasource.php#L408-L435 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.datasource.php | Datasource.__processParametersInString | public function __processParametersInString($value, array $env, $includeParenthesis = true, $escape = false)
{
if (trim($value) == '') {
return null;
}
if (!$includeParenthesis) {
$value = '{'.$value.'}';
}
if (preg_match_all('@{([^}]+)}@i', $value, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
list($source, $cleaned) = $match;
$replacement = null;
$bits = preg_split('/:/', $cleaned, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bits as $param) {
if ($param{0} !== '$') {
$replacement = $param;
break;
}
$param = trim($param, '$');
$replacement = Datasource::findParameterInEnv($param, $env);
if (is_array($replacement)) {
$replacement = array_map(array('Datasource', 'escapeCommas'), $replacement);
if (count($replacement) > 1) {
$replacement = implode(',', $replacement);
} else {
$replacement = end($replacement);
}
}
if (!empty($replacement)) {
break;
}
}
if ($escape) {
$replacement = urlencode($replacement);
}
$value = str_replace($source, $replacement, $value);
}
}
return $value;
} | php | public function __processParametersInString($value, array $env, $includeParenthesis = true, $escape = false)
{
if (trim($value) == '') {
return null;
}
if (!$includeParenthesis) {
$value = '{'.$value.'}';
}
if (preg_match_all('@{([^}]+)}@i', $value, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
list($source, $cleaned) = $match;
$replacement = null;
$bits = preg_split('/:/', $cleaned, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bits as $param) {
if ($param{0} !== '$') {
$replacement = $param;
break;
}
$param = trim($param, '$');
$replacement = Datasource::findParameterInEnv($param, $env);
if (is_array($replacement)) {
$replacement = array_map(array('Datasource', 'escapeCommas'), $replacement);
if (count($replacement) > 1) {
$replacement = implode(',', $replacement);
} else {
$replacement = end($replacement);
}
}
if (!empty($replacement)) {
break;
}
}
if ($escape) {
$replacement = urlencode($replacement);
}
$value = str_replace($source, $replacement, $value);
}
}
return $value;
} | [
"public",
"function",
"__processParametersInString",
"(",
"$",
"value",
",",
"array",
"$",
"env",
",",
"$",
"includeParenthesis",
"=",
"true",
",",
"$",
"escape",
"=",
"false",
")",
"{",
"if",
"(",
"trim",
"(",
"$",
"value",
")",
"==",
"''",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"$",
"includeParenthesis",
")",
"{",
"$",
"value",
"=",
"'{'",
".",
"$",
"value",
".",
"'}'",
";",
"}",
"if",
"(",
"preg_match_all",
"(",
"'@{([^}]+)}@i'",
",",
"$",
"value",
",",
"$",
"matches",
",",
"PREG_SET_ORDER",
")",
")",
"{",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"match",
")",
"{",
"list",
"(",
"$",
"source",
",",
"$",
"cleaned",
")",
"=",
"$",
"match",
";",
"$",
"replacement",
"=",
"null",
";",
"$",
"bits",
"=",
"preg_split",
"(",
"'/:/'",
",",
"$",
"cleaned",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"foreach",
"(",
"$",
"bits",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"$",
"param",
"{",
"0",
"}",
"!==",
"'$'",
")",
"{",
"$",
"replacement",
"=",
"$",
"param",
";",
"break",
";",
"}",
"$",
"param",
"=",
"trim",
"(",
"$",
"param",
",",
"'$'",
")",
";",
"$",
"replacement",
"=",
"Datasource",
"::",
"findParameterInEnv",
"(",
"$",
"param",
",",
"$",
"env",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"replacement",
")",
")",
"{",
"$",
"replacement",
"=",
"array_map",
"(",
"array",
"(",
"'Datasource'",
",",
"'escapeCommas'",
")",
",",
"$",
"replacement",
")",
";",
"if",
"(",
"count",
"(",
"$",
"replacement",
")",
">",
"1",
")",
"{",
"$",
"replacement",
"=",
"implode",
"(",
"','",
",",
"$",
"replacement",
")",
";",
"}",
"else",
"{",
"$",
"replacement",
"=",
"end",
"(",
"$",
"replacement",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"replacement",
")",
")",
"{",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"escape",
")",
"{",
"$",
"replacement",
"=",
"urlencode",
"(",
"$",
"replacement",
")",
";",
"}",
"$",
"value",
"=",
"str_replace",
"(",
"$",
"source",
",",
"$",
"replacement",
",",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"value",
";",
"}"
] | This function will replace any parameters in a string with their value.
Parameters are defined by being prefixed by a `$` character. In certain
situations, the parameter will be surrounded by `{}`, which Symphony
takes to mean, evaluate this parameter to a value, other times it will be
omitted which is usually used to indicate that this parameter exists
@param string $value
The string with the parameters that need to be evaluated
@param array $env
The environment variables from the Frontend class which includes
any params set by Symphony or Events or by other Datasources
@param boolean $includeParenthesis
Parameters will sometimes not be surrounded by `{}`. If this is the case
setting this parameter to false will make this function automatically add
them to the parameter. By default this is true, which means all parameters
in the string already are surrounded by `{}`
@param boolean $escape
If set to true, the resulting value will passed through `urlencode` before
being returned. By default this is `false`
@return string
The string with all parameters evaluated. If a parameter is not found, it will
not be replaced and remain in the `$value`. | [
"This",
"function",
"will",
"replace",
"any",
"parameters",
"in",
"a",
"string",
"with",
"their",
"value",
".",
"Parameters",
"are",
"defined",
"by",
"being",
"prefixed",
"by",
"a",
"$",
"character",
".",
"In",
"certain",
"situations",
"the",
"parameter",
"will",
"be",
"surrounded",
"by",
"{}",
"which",
"Symphony",
"takes",
"to",
"mean",
"evaluate",
"this",
"parameter",
"to",
"a",
"value",
"other",
"times",
"it",
"will",
"be",
"omitted",
"which",
"is",
"usually",
"used",
"to",
"indicate",
"that",
"this",
"parameter",
"exists"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.datasource.php#L461-L512 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.datasource.php | Datasource.findParameterInEnv | public static function findParameterInEnv($needle, $env)
{
if (isset($env['env']['url'][$needle])) {
return $env['env']['url'][$needle];
}
if (isset($env['env']['pool'][$needle])) {
return $env['env']['pool'][$needle];
}
if (isset($env['param'][$needle])) {
return $env['param'][$needle];
}
return null;
} | php | public static function findParameterInEnv($needle, $env)
{
if (isset($env['env']['url'][$needle])) {
return $env['env']['url'][$needle];
}
if (isset($env['env']['pool'][$needle])) {
return $env['env']['pool'][$needle];
}
if (isset($env['param'][$needle])) {
return $env['param'][$needle];
}
return null;
} | [
"public",
"static",
"function",
"findParameterInEnv",
"(",
"$",
"needle",
",",
"$",
"env",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"env",
"[",
"'env'",
"]",
"[",
"'url'",
"]",
"[",
"$",
"needle",
"]",
")",
")",
"{",
"return",
"$",
"env",
"[",
"'env'",
"]",
"[",
"'url'",
"]",
"[",
"$",
"needle",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"env",
"[",
"'env'",
"]",
"[",
"'pool'",
"]",
"[",
"$",
"needle",
"]",
")",
")",
"{",
"return",
"$",
"env",
"[",
"'env'",
"]",
"[",
"'pool'",
"]",
"[",
"$",
"needle",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"env",
"[",
"'param'",
"]",
"[",
"$",
"needle",
"]",
")",
")",
"{",
"return",
"$",
"env",
"[",
"'param'",
"]",
"[",
"$",
"needle",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Parameters can exist in three different facets of Symphony; in the URL,
in the parameter pool or as an Symphony param. This function will attempt
to find a parameter in those three areas and return the value. If it is not found
null is returned
@param string $needle
The parameter name
@param array $env
The environment variables from the Frontend class which includes
any params set by Symphony or Events or by other Datasources
@return mixed
If the value is not found, null, otherwise a string or an array is returned | [
"Parameters",
"can",
"exist",
"in",
"three",
"different",
"facets",
"of",
"Symphony",
";",
"in",
"the",
"URL",
"in",
"the",
"parameter",
"pool",
"or",
"as",
"an",
"Symphony",
"param",
".",
"This",
"function",
"will",
"attempt",
"to",
"find",
"a",
"parameter",
"in",
"those",
"three",
"areas",
"and",
"return",
"the",
"value",
".",
"If",
"it",
"is",
"not",
"found",
"null",
"is",
"returned"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.datasource.php#L553-L568 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.datasource.php | Datasource.__determineFilterType | public function __determineFilterType($value)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('Datasource::__determineFilterType()', 'Datasource::determineFilterType()');
}
return self::determineFilterType($value);
} | php | public function __determineFilterType($value)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('Datasource::__determineFilterType()', 'Datasource::determineFilterType()');
}
return self::determineFilterType($value);
} | [
"public",
"function",
"__determineFilterType",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"Symphony",
"::",
"Log",
"(",
")",
")",
"{",
"Symphony",
"::",
"Log",
"(",
")",
"->",
"pushDeprecateWarningToLog",
"(",
"'Datasource::__determineFilterType()'",
",",
"'Datasource::determineFilterType()'",
")",
";",
"}",
"return",
"self",
"::",
"determineFilterType",
"(",
"$",
"value",
")",
";",
"}"
] | By default, all Symphony filters are considering to be OR and "+" filters
are used for AND. They are all used and Entries must match each filter to be included.
It is possible to use OR filtering in a field by using an "," to separate the values.
eg. If the filter is "test1, test2", this will match any entries where this field
is test1 OR test2. If the filter is "test1 + test2", this will match entries
where this field is test1 AND test2. Not all fields supports this feature.
This function is run on each filter (ie. each field) in a datasource.
@deprecated Since Symphony 2.6.0 it is recommended to use the static version,
`Datasource::determineFilterType`
@param string $value
The filter string for a field.
@return integer
Datasource::FILTER_OR or Datasource::FILTER_AND | [
"By",
"default",
"all",
"Symphony",
"filters",
"are",
"considering",
"to",
"be",
"OR",
"and",
"+",
"filters",
"are",
"used",
"for",
"AND",
".",
"They",
"are",
"all",
"used",
"and",
"Entries",
"must",
"match",
"each",
"filter",
"to",
"be",
"included",
".",
"It",
"is",
"possible",
"to",
"use",
"OR",
"filtering",
"in",
"a",
"field",
"by",
"using",
"an",
"to",
"separate",
"the",
"values",
".",
"eg",
".",
"If",
"the",
"filter",
"is",
"test1",
"test2",
"this",
"will",
"match",
"any",
"entries",
"where",
"this",
"field",
"is",
"test1",
"OR",
"test2",
".",
"If",
"the",
"filter",
"is",
"test1",
"+",
"test2",
"this",
"will",
"match",
"entries",
"where",
"this",
"field",
"is",
"test1",
"AND",
"test2",
".",
"Not",
"all",
"fields",
"supports",
"this",
"feature",
".",
"This",
"function",
"is",
"run",
"on",
"each",
"filter",
"(",
"ie",
".",
"each",
"field",
")",
"in",
"a",
"datasource",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.datasource.php#L586-L592 |
symphonycms/symphony-2 | symphony/lib/toolkit/cryptography/class.pbkdf2.php | PBKDF2.hash | public static function hash($input, $salt = null, $iterations = null, $keylength = null)
{
if ($salt === null) {
$salt = self::generateSalt(self::SALT_LENGTH);
}
if ($iterations === null) {
$iterations = self::ITERATIONS;
}
if ($keylength === null) {
$keylength = self::KEY_LENGTH;
}
$hashlength = strlen(hash(self::ALGORITHM, null, true));
$blocks = ceil(self::KEY_LENGTH / $hashlength);
$key = '';
for ($block = 1; $block <= $blocks; $block++) {
$ib = $b = hash_hmac(self::ALGORITHM, $salt . pack('N', $block), $input, true);
for ($i = 1; $i < $iterations; $i++) {
$ib ^= ($b = hash_hmac(self::ALGORITHM, $b, $input, true));
}
$key .= $ib;
}
return self::PREFIX . "|" . $iterations . "|" . $salt . "|" . base64_encode(substr($key, 0, $keylength));
} | php | public static function hash($input, $salt = null, $iterations = null, $keylength = null)
{
if ($salt === null) {
$salt = self::generateSalt(self::SALT_LENGTH);
}
if ($iterations === null) {
$iterations = self::ITERATIONS;
}
if ($keylength === null) {
$keylength = self::KEY_LENGTH;
}
$hashlength = strlen(hash(self::ALGORITHM, null, true));
$blocks = ceil(self::KEY_LENGTH / $hashlength);
$key = '';
for ($block = 1; $block <= $blocks; $block++) {
$ib = $b = hash_hmac(self::ALGORITHM, $salt . pack('N', $block), $input, true);
for ($i = 1; $i < $iterations; $i++) {
$ib ^= ($b = hash_hmac(self::ALGORITHM, $b, $input, true));
}
$key .= $ib;
}
return self::PREFIX . "|" . $iterations . "|" . $salt . "|" . base64_encode(substr($key, 0, $keylength));
} | [
"public",
"static",
"function",
"hash",
"(",
"$",
"input",
",",
"$",
"salt",
"=",
"null",
",",
"$",
"iterations",
"=",
"null",
",",
"$",
"keylength",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"salt",
"===",
"null",
")",
"{",
"$",
"salt",
"=",
"self",
"::",
"generateSalt",
"(",
"self",
"::",
"SALT_LENGTH",
")",
";",
"}",
"if",
"(",
"$",
"iterations",
"===",
"null",
")",
"{",
"$",
"iterations",
"=",
"self",
"::",
"ITERATIONS",
";",
"}",
"if",
"(",
"$",
"keylength",
"===",
"null",
")",
"{",
"$",
"keylength",
"=",
"self",
"::",
"KEY_LENGTH",
";",
"}",
"$",
"hashlength",
"=",
"strlen",
"(",
"hash",
"(",
"self",
"::",
"ALGORITHM",
",",
"null",
",",
"true",
")",
")",
";",
"$",
"blocks",
"=",
"ceil",
"(",
"self",
"::",
"KEY_LENGTH",
"/",
"$",
"hashlength",
")",
";",
"$",
"key",
"=",
"''",
";",
"for",
"(",
"$",
"block",
"=",
"1",
";",
"$",
"block",
"<=",
"$",
"blocks",
";",
"$",
"block",
"++",
")",
"{",
"$",
"ib",
"=",
"$",
"b",
"=",
"hash_hmac",
"(",
"self",
"::",
"ALGORITHM",
",",
"$",
"salt",
".",
"pack",
"(",
"'N'",
",",
"$",
"block",
")",
",",
"$",
"input",
",",
"true",
")",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"$",
"iterations",
";",
"$",
"i",
"++",
")",
"{",
"$",
"ib",
"^=",
"(",
"$",
"b",
"=",
"hash_hmac",
"(",
"self",
"::",
"ALGORITHM",
",",
"$",
"b",
",",
"$",
"input",
",",
"true",
")",
")",
";",
"}",
"$",
"key",
".=",
"$",
"ib",
";",
"}",
"return",
"self",
"::",
"PREFIX",
".",
"\"|\"",
".",
"$",
"iterations",
".",
"\"|\"",
".",
"$",
"salt",
".",
"\"|\"",
".",
"base64_encode",
"(",
"substr",
"(",
"$",
"key",
",",
"0",
",",
"$",
"keylength",
")",
")",
";",
"}"
] | Uses `PBKDF2` and random salt generation to create a hash based on some input.
Original implementation was under public domain, taken from
http://www.itnewb.com/tutorial/Encrypting-Passwords-with-PHP-for-Storage-Using-the-RSA-PBKDF2-Standard
@param string $input
the string to be hashed
@param string $salt
an optional salt
@param integer $iterations
an optional number of iterations to be used
@param string $keylength
an optional length the key will be cropped to fit
@return string
the hashed string | [
"Uses",
"PBKDF2",
"and",
"random",
"salt",
"generation",
"to",
"create",
"a",
"hash",
"based",
"on",
"some",
"input",
".",
"Original",
"implementation",
"was",
"under",
"public",
"domain",
"taken",
"from",
"http",
":",
"//",
"www",
".",
"itnewb",
".",
"com",
"/",
"tutorial",
"/",
"Encrypting",
"-",
"Passwords",
"-",
"with",
"-",
"PHP",
"-",
"for",
"-",
"Storage",
"-",
"Using",
"-",
"the",
"-",
"RSA",
"-",
"PBKDF2",
"-",
"Standard"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/cryptography/class.pbkdf2.php#L56-L85 |
symphonycms/symphony-2 | symphony/lib/toolkit/cryptography/class.pbkdf2.php | PBKDF2.compare | public static function compare($input, $hash, $isHash = false)
{
$salt = self::extractSalt($hash);
$iterations = self::extractIterations($hash);
$keylength = strlen(base64_decode(self::extractHash($hash)));
return $hash === self::hash($input, $salt, $iterations, $keylength);
} | php | public static function compare($input, $hash, $isHash = false)
{
$salt = self::extractSalt($hash);
$iterations = self::extractIterations($hash);
$keylength = strlen(base64_decode(self::extractHash($hash)));
return $hash === self::hash($input, $salt, $iterations, $keylength);
} | [
"public",
"static",
"function",
"compare",
"(",
"$",
"input",
",",
"$",
"hash",
",",
"$",
"isHash",
"=",
"false",
")",
"{",
"$",
"salt",
"=",
"self",
"::",
"extractSalt",
"(",
"$",
"hash",
")",
";",
"$",
"iterations",
"=",
"self",
"::",
"extractIterations",
"(",
"$",
"hash",
")",
";",
"$",
"keylength",
"=",
"strlen",
"(",
"base64_decode",
"(",
"self",
"::",
"extractHash",
"(",
"$",
"hash",
")",
")",
")",
";",
"return",
"$",
"hash",
"===",
"self",
"::",
"hash",
"(",
"$",
"input",
",",
"$",
"salt",
",",
"$",
"iterations",
",",
"$",
"keylength",
")",
";",
"}"
] | Compares a given hash with a cleantext password. Also extracts the salt
from the hash.
@param string $input
the cleartext password
@param string $hash
the hash the password should be checked against
@param boolean $isHash
@return boolean
the result of the comparison | [
"Compares",
"a",
"given",
"hash",
"with",
"a",
"cleantext",
"password",
".",
"Also",
"extracts",
"the",
"salt",
"from",
"the",
"hash",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/cryptography/class.pbkdf2.php#L99-L106 |
symphonycms/symphony-2 | symphony/lib/toolkit/cryptography/class.pbkdf2.php | PBKDF2.requiresMigration | public static function requiresMigration($hash)
{
$length = self::extractSaltlength($hash);
$iterations = self::extractIterations($hash);
$keylength = strlen(base64_decode(self::extractHash($hash)));
if ($length !== self::SALT_LENGTH || $iterations !== self::ITERATIONS || $keylength !== self::KEY_LENGTH) {
return true;
} else {
return false;
}
} | php | public static function requiresMigration($hash)
{
$length = self::extractSaltlength($hash);
$iterations = self::extractIterations($hash);
$keylength = strlen(base64_decode(self::extractHash($hash)));
if ($length !== self::SALT_LENGTH || $iterations !== self::ITERATIONS || $keylength !== self::KEY_LENGTH) {
return true;
} else {
return false;
}
} | [
"public",
"static",
"function",
"requiresMigration",
"(",
"$",
"hash",
")",
"{",
"$",
"length",
"=",
"self",
"::",
"extractSaltlength",
"(",
"$",
"hash",
")",
";",
"$",
"iterations",
"=",
"self",
"::",
"extractIterations",
"(",
"$",
"hash",
")",
";",
"$",
"keylength",
"=",
"strlen",
"(",
"base64_decode",
"(",
"self",
"::",
"extractHash",
"(",
"$",
"hash",
")",
")",
")",
";",
"if",
"(",
"$",
"length",
"!==",
"self",
"::",
"SALT_LENGTH",
"||",
"$",
"iterations",
"!==",
"self",
"::",
"ITERATIONS",
"||",
"$",
"keylength",
"!==",
"self",
"::",
"KEY_LENGTH",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Checks if provided hash has been computed by most recent algorithm
returns true if otherwise
@param string $hash
the hash to be checked
@return boolean
whether the hash should be re-computed | [
"Checks",
"if",
"provided",
"hash",
"has",
"been",
"computed",
"by",
"most",
"recent",
"algorithm",
"returns",
"true",
"if",
"otherwise"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/cryptography/class.pbkdf2.php#L175-L186 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.getValue | public function getValue()
{
$value = '';
if (is_array($this->_value)) {
foreach ($this->_value as $v) {
if ($v instanceof XMLElement) {
$value .= $v->generate();
} else {
$value .= $v;
}
}
} elseif (!is_null($this->_value)) {
$value = $this->_value;
}
return $value;
} | php | public function getValue()
{
$value = '';
if (is_array($this->_value)) {
foreach ($this->_value as $v) {
if ($v instanceof XMLElement) {
$value .= $v->generate();
} else {
$value .= $v;
}
}
} elseif (!is_null($this->_value)) {
$value = $this->_value;
}
return $value;
} | [
"public",
"function",
"getValue",
"(",
")",
"{",
"$",
"value",
"=",
"''",
";",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"_value",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_value",
"as",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"v",
"instanceof",
"XMLElement",
")",
"{",
"$",
"value",
".=",
"$",
"v",
"->",
"generate",
"(",
")",
";",
"}",
"else",
"{",
"$",
"value",
".=",
"$",
"v",
";",
"}",
"}",
"}",
"elseif",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"_value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"_value",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Accessor for `$_value`
@return string|XMLElement | [
"Accessor",
"for",
"$_value"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L145-L162 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.getChild | public function getChild($position)
{
if (!isset($this->_children[$this->getRealIndex($position)])) {
return null;
}
return $this->_children[$this->getRealIndex($position)];
} | php | public function getChild($position)
{
if (!isset($this->_children[$this->getRealIndex($position)])) {
return null;
}
return $this->_children[$this->getRealIndex($position)];
} | [
"public",
"function",
"getChild",
"(",
"$",
"position",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_children",
"[",
"$",
"this",
"->",
"getRealIndex",
"(",
"$",
"position",
")",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"_children",
"[",
"$",
"this",
"->",
"getRealIndex",
"(",
"$",
"position",
")",
"]",
";",
"}"
] | Retrieves a child-element by position
@since Symphony 2.3
@param integer $position
@return XMLElement | [
"Retrieves",
"a",
"child",
"-",
"element",
"by",
"position"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L196-L203 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.getChildByName | public function getChildByName($name, $position)
{
$result = array_values($this->getChildrenByName($name));
if (!isset($result[$position])) {
return null;
}
return $result[$position];
} | php | public function getChildByName($name, $position)
{
$result = array_values($this->getChildrenByName($name));
if (!isset($result[$position])) {
return null;
}
return $result[$position];
} | [
"public",
"function",
"getChildByName",
"(",
"$",
"name",
",",
"$",
"position",
")",
"{",
"$",
"result",
"=",
"array_values",
"(",
"$",
"this",
"->",
"getChildrenByName",
"(",
"$",
"name",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
"[",
"$",
"position",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"result",
"[",
"$",
"position",
"]",
";",
"}"
] | Retrieves child-element by name and position. If no child is found,
`NULL` will be returned.
@since Symphony 2.3
@param string $name
@param integer $position
@return XMLElement | [
"Retrieves",
"child",
"-",
"element",
"by",
"name",
"and",
"position",
".",
"If",
"no",
"child",
"is",
"found",
"NULL",
"will",
"be",
"returned",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L235-L244 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.getChildrenByName | public function getChildrenByName($name)
{
$result = array();
foreach ($this as $i => $child) {
if ($child->getName() != $name) {
continue;
}
$result[$i] = $child;
}
return $result;
} | php | public function getChildrenByName($name)
{
$result = array();
foreach ($this as $i => $child) {
if ($child->getName() != $name) {
continue;
}
$result[$i] = $child;
}
return $result;
} | [
"public",
"function",
"getChildrenByName",
"(",
"$",
"name",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"as",
"$",
"i",
"=>",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"child",
"->",
"getName",
"(",
")",
"!=",
"$",
"name",
")",
"{",
"continue",
";",
"}",
"$",
"result",
"[",
"$",
"i",
"]",
"=",
"$",
"child",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Accessor to return an associative array of all `$this->_children`
whose's name matches the given `$name`. If no children are found,
an empty array will be returned.
@since Symphony 2.2.2
@param string $name
@return array
An associative array where the key is the `$index` of the child
in `$this->_children` | [
"Accessor",
"to",
"return",
"an",
"associative",
"array",
"of",
"all",
"$this",
"-",
">",
"_children",
"whose",
"s",
"name",
"matches",
"the",
"given",
"$name",
".",
"If",
"no",
"children",
"are",
"found",
"an",
"empty",
"array",
"will",
"be",
"returned",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L257-L270 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.setName | public function setName($name, $createHandle = false)
{
$this->_name = ($createHandle) ? Lang::createHandle($name) : $name;
} | php | public function setName($name, $createHandle = false)
{
$this->_name = ($createHandle) ? Lang::createHandle($name) : $name;
} | [
"public",
"function",
"setName",
"(",
"$",
"name",
",",
"$",
"createHandle",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"_name",
"=",
"(",
"$",
"createHandle",
")",
"?",
"Lang",
"::",
"createHandle",
"(",
"$",
"name",
")",
":",
"$",
"name",
";",
"}"
] | Sets the name of this `XMLElement`, ie. 'p' => <p />
@since Symphony 2.3.2
@param string $name
The name of the `XMLElement`, 'p'.
@param boolean $createHandle
Whether this function should convert the `$name` to a handle. Defaults to
`false`. | [
"Sets",
"the",
"name",
"of",
"this",
"XMLElement",
"ie",
".",
"p",
"=",
">",
"<p",
"/",
">"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L375-L378 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.setValue | public function setValue($value)
{
if (is_array($value)) {
$value = implode(', ', $value);
}
if (!is_null($value)) {
$this->_value = $value;
$this->appendChild($value);
}
} | php | public function setValue($value)
{
if (is_array($value)) {
$value = implode(', ', $value);
}
if (!is_null($value)) {
$this->_value = $value;
$this->appendChild($value);
}
} | [
"public",
"function",
"setValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"implode",
"(",
"', '",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"_value",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"appendChild",
"(",
"$",
"value",
")",
";",
"}",
"}"
] | Sets the value of the `XMLElement`. Checks to see
whether the value should be prepended or appended
to the children.
@param string|XMLElement|array $value
Defaults to true. | [
"Sets",
"the",
"value",
"of",
"the",
"XMLElement",
".",
"Checks",
"to",
"see",
"whether",
"the",
"value",
"should",
"be",
"prepended",
"or",
"appended",
"to",
"the",
"children",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L388-L398 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.replaceValue | public function replaceValue($value)
{
foreach ($this->_children as $i => $child) {
if ($child instanceof XMLElement) {
continue;
}
unset($this->_children[$i]);
}
$this->setValue($value);
} | php | public function replaceValue($value)
{
foreach ($this->_children as $i => $child) {
if ($child instanceof XMLElement) {
continue;
}
unset($this->_children[$i]);
}
$this->setValue($value);
} | [
"public",
"function",
"replaceValue",
"(",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_children",
"as",
"$",
"i",
"=>",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"child",
"instanceof",
"XMLElement",
")",
"{",
"continue",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"_children",
"[",
"$",
"i",
"]",
")",
";",
"}",
"$",
"this",
"->",
"setValue",
"(",
"$",
"value",
")",
";",
"}"
] | This function will remove all text attributes from the `XMLElement` node
and replace them with the given value.
@since Symphony 2.4
@param string|XMLElement|array $value | [
"This",
"function",
"will",
"remove",
"all",
"text",
"attributes",
"from",
"the",
"XMLElement",
"node",
"and",
"replace",
"them",
"with",
"the",
"given",
"value",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L407-L418 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.setAttributeArray | public function setAttributeArray(array $attributes = null)
{
if (!is_array($attributes) || empty($attributes)) {
return;
}
foreach ($attributes as $name => $value) {
$this->setAttribute($name, $value);
}
} | php | public function setAttributeArray(array $attributes = null)
{
if (!is_array($attributes) || empty($attributes)) {
return;
}
foreach ($attributes as $name => $value) {
$this->setAttribute($name, $value);
}
} | [
"public",
"function",
"setAttributeArray",
"(",
"array",
"$",
"attributes",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"attributes",
")",
"||",
"empty",
"(",
"$",
"attributes",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setAttribute",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}"
] | A convenience method to quickly add multiple attributes to
an `XMLElement`
@param array $attributes
Associative array with the key being the name and
the value being the value of the attribute. | [
"A",
"convenience",
"method",
"to",
"quickly",
"add",
"multiple",
"attributes",
"to",
"an",
"XMLElement"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L441-L450 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.setChildren | public function setChildren(array $children = null)
{
foreach ($children as $child) {
$this->validateChild($child);
}
$this->_children = $children;
return true;
} | php | public function setChildren(array $children = null)
{
foreach ($children as $child) {
$this->validateChild($child);
}
$this->_children = $children;
return true;
} | [
"public",
"function",
"setChildren",
"(",
"array",
"$",
"children",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"this",
"->",
"validateChild",
"(",
"$",
"child",
")",
";",
"}",
"$",
"this",
"->",
"_children",
"=",
"$",
"children",
";",
"return",
"true",
";",
"}"
] | This function expects an array of `XMLElement` that will completely
replace the contents of `$this->_children`. Take care when using
this function.
@since Symphony 2.2.2
@param array $children
An array of XMLElement's to act as the children for the current
XMLElement instance
@return boolean | [
"This",
"function",
"expects",
"an",
"array",
"of",
"XMLElement",
"that",
"will",
"completely",
"replace",
"the",
"contents",
"of",
"$this",
"-",
">",
"_children",
".",
"Take",
"care",
"when",
"using",
"this",
"function",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L479-L487 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.appendChildArray | public function appendChildArray(array $children = null)
{
if (is_array($children) && !empty($children)) {
foreach ($children as $child) {
$this->appendChild($child);
}
}
} | php | public function appendChildArray(array $children = null)
{
if (is_array($children) && !empty($children)) {
foreach ($children as $child) {
$this->appendChild($child);
}
}
} | [
"public",
"function",
"appendChildArray",
"(",
"array",
"$",
"children",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"children",
")",
"&&",
"!",
"empty",
"(",
"$",
"children",
")",
")",
"{",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"this",
"->",
"appendChild",
"(",
"$",
"child",
")",
";",
"}",
"}",
"}"
] | A convenience method to add children to an `XMLElement`
quickly.
@param array $children | [
"A",
"convenience",
"method",
"to",
"add",
"children",
"to",
"an",
"XMLElement",
"quickly",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L509-L516 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.addClass | public function addClass($class)
{
$current = preg_split('%\s+%', $this->getAttribute('class'), 0, PREG_SPLIT_NO_EMPTY);
$added = preg_split('%\s+%', $class, 0, PREG_SPLIT_NO_EMPTY);
$current = array_merge($current, $added);
$classes = implode(' ', $current);
$this->setAttribute('class', $classes);
} | php | public function addClass($class)
{
$current = preg_split('%\s+%', $this->getAttribute('class'), 0, PREG_SPLIT_NO_EMPTY);
$added = preg_split('%\s+%', $class, 0, PREG_SPLIT_NO_EMPTY);
$current = array_merge($current, $added);
$classes = implode(' ', $current);
$this->setAttribute('class', $classes);
} | [
"public",
"function",
"addClass",
"(",
"$",
"class",
")",
"{",
"$",
"current",
"=",
"preg_split",
"(",
"'%\\s+%'",
",",
"$",
"this",
"->",
"getAttribute",
"(",
"'class'",
")",
",",
"0",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"$",
"added",
"=",
"preg_split",
"(",
"'%\\s+%'",
",",
"$",
"class",
",",
"0",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"$",
"current",
"=",
"array_merge",
"(",
"$",
"current",
",",
"$",
"added",
")",
";",
"$",
"classes",
"=",
"implode",
"(",
"' '",
",",
"$",
"current",
")",
";",
"$",
"this",
"->",
"setAttribute",
"(",
"'class'",
",",
"$",
"classes",
")",
";",
"}"
] | A convenience method to quickly add a CSS class to this `XMLElement`'s
existing class attribute. If the attribute does not exist, it will
be created.
@since Symphony 2.2.2
@param string $class
The CSS classname to add to this `XMLElement` | [
"A",
"convenience",
"method",
"to",
"quickly",
"add",
"a",
"CSS",
"class",
"to",
"this",
"XMLElement",
"s",
"existing",
"class",
"attribute",
".",
"If",
"the",
"attribute",
"does",
"not",
"exist",
"it",
"will",
"be",
"created",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L539-L547 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.removeClass | public function removeClass($class)
{
$classes = preg_split('%\s+%', $this->getAttribute('class'), 0, PREG_SPLIT_NO_EMPTY);
$removed = preg_split('%\s+%', $class, 0, PREG_SPLIT_NO_EMPTY);
$classes = array_diff($classes, $removed);
$classes = implode(' ', $classes);
$this->setAttribute('class', $classes);
} | php | public function removeClass($class)
{
$classes = preg_split('%\s+%', $this->getAttribute('class'), 0, PREG_SPLIT_NO_EMPTY);
$removed = preg_split('%\s+%', $class, 0, PREG_SPLIT_NO_EMPTY);
$classes = array_diff($classes, $removed);
$classes = implode(' ', $classes);
$this->setAttribute('class', $classes);
} | [
"public",
"function",
"removeClass",
"(",
"$",
"class",
")",
"{",
"$",
"classes",
"=",
"preg_split",
"(",
"'%\\s+%'",
",",
"$",
"this",
"->",
"getAttribute",
"(",
"'class'",
")",
",",
"0",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"$",
"removed",
"=",
"preg_split",
"(",
"'%\\s+%'",
",",
"$",
"class",
",",
"0",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"$",
"classes",
"=",
"array_diff",
"(",
"$",
"classes",
",",
"$",
"removed",
")",
";",
"$",
"classes",
"=",
"implode",
"(",
"' '",
",",
"$",
"classes",
")",
";",
"$",
"this",
"->",
"setAttribute",
"(",
"'class'",
",",
"$",
"classes",
")",
";",
"}"
] | A convenience method to quickly remove a CSS class from an
`XMLElement`'s existing class attribute. If the attribute does not
exist, this method will do nothing.
@since Symphony 2.2.2
@param string $class
The CSS classname to remove from this `XMLElement` | [
"A",
"convenience",
"method",
"to",
"quickly",
"remove",
"a",
"CSS",
"class",
"from",
"an",
"XMLElement",
"s",
"existing",
"class",
"attribute",
".",
"If",
"the",
"attribute",
"does",
"not",
"exist",
"this",
"method",
"will",
"do",
"nothing",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L558-L566 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.removeChildAt | public function removeChildAt($index)
{
if (!is_numeric($index)) {
return false;
}
$index = $this->getRealIndex($index);
if (!isset($this->_children[$index])) {
return false;
}
unset($this->_children[$index]);
return true;
} | php | public function removeChildAt($index)
{
if (!is_numeric($index)) {
return false;
}
$index = $this->getRealIndex($index);
if (!isset($this->_children[$index])) {
return false;
}
unset($this->_children[$index]);
return true;
} | [
"public",
"function",
"removeChildAt",
"(",
"$",
"index",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"index",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"index",
"=",
"$",
"this",
"->",
"getRealIndex",
"(",
"$",
"index",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_children",
"[",
"$",
"index",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"_children",
"[",
"$",
"index",
"]",
")",
";",
"return",
"true",
";",
"}"
] | Given the position of the child in the `$this->_children`,
this function will unset the child at that position. This function
is not reversible. This function does not alter the key's of
`$this->_children` after removing a child
@since Symphony 2.2.2
@param integer $index
The index of the child to be removed. If the index given is negative
it will be calculated from the end of `$this->_children`.
@return boolean
true if child was successfully removed, false otherwise. | [
"Given",
"the",
"position",
"of",
"the",
"child",
"in",
"the",
"$this",
"-",
">",
"_children",
"this",
"function",
"will",
"unset",
"the",
"child",
"at",
"that",
"position",
".",
"This",
"function",
"is",
"not",
"reversible",
".",
"This",
"function",
"does",
"not",
"alter",
"the",
"key",
"s",
"of",
"$this",
"-",
">",
"_children",
"after",
"removing",
"a",
"child"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L590-L605 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.insertChildAt | public function insertChildAt($index, XMLElement $child = null)
{
if (!is_numeric($index)) {
return false;
}
$this->validateChild($child);
if ($index >= $this->getNumberOfChildren()) {
return $this->appendChild($child);
}
$start = array_slice($this->_children, 0, $index);
$end = array_slice($this->_children, $index);
$merge = array_merge($start, array(
$index => $child
), $end);
return $this->setChildren($merge);
} | php | public function insertChildAt($index, XMLElement $child = null)
{
if (!is_numeric($index)) {
return false;
}
$this->validateChild($child);
if ($index >= $this->getNumberOfChildren()) {
return $this->appendChild($child);
}
$start = array_slice($this->_children, 0, $index);
$end = array_slice($this->_children, $index);
$merge = array_merge($start, array(
$index => $child
), $end);
return $this->setChildren($merge);
} | [
"public",
"function",
"insertChildAt",
"(",
"$",
"index",
",",
"XMLElement",
"$",
"child",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"index",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"validateChild",
"(",
"$",
"child",
")",
";",
"if",
"(",
"$",
"index",
">=",
"$",
"this",
"->",
"getNumberOfChildren",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"appendChild",
"(",
"$",
"child",
")",
";",
"}",
"$",
"start",
"=",
"array_slice",
"(",
"$",
"this",
"->",
"_children",
",",
"0",
",",
"$",
"index",
")",
";",
"$",
"end",
"=",
"array_slice",
"(",
"$",
"this",
"->",
"_children",
",",
"$",
"index",
")",
";",
"$",
"merge",
"=",
"array_merge",
"(",
"$",
"start",
",",
"array",
"(",
"$",
"index",
"=>",
"$",
"child",
")",
",",
"$",
"end",
")",
";",
"return",
"$",
"this",
"->",
"setChildren",
"(",
"$",
"merge",
")",
";",
"}"
] | Given a desired index, and an `XMLElement`, this function will insert
the child at that index in `$this->_children` shuffling all children
greater than `$index` down one. If the `$index` given is greater then
the number of children for this `XMLElement`, the `$child` will be
appended to the current `$this->_children` array.
@since Symphony 2.2.2
@param integer $index
The index where the `$child` should be inserted. If this is negative
the index will be calculated from the end of `$this->_children`.
@param XMLElement $child
The XMLElement to insert at the desired `$index`
@return boolean | [
"Given",
"a",
"desired",
"index",
"and",
"an",
"XMLElement",
"this",
"function",
"will",
"insert",
"the",
"child",
"at",
"that",
"index",
"in",
"$this",
"-",
">",
"_children",
"shuffling",
"all",
"children",
"greater",
"than",
"$index",
"down",
"one",
".",
"If",
"the",
"$index",
"given",
"is",
"greater",
"then",
"the",
"number",
"of",
"children",
"for",
"this",
"XMLElement",
"the",
"$child",
"will",
"be",
"appended",
"to",
"the",
"current",
"$this",
"-",
">",
"_children",
"array",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L622-L642 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.replaceChildAt | public function replaceChildAt($index, XMLElement $child = null)
{
if (!is_numeric($index)) {
return false;
}
$this->validateChild($child);
$index = $this->getRealIndex($index);
if (!isset($this->_children[$index])) {
return false;
}
$this->_children[$index] = $child;
return true;
} | php | public function replaceChildAt($index, XMLElement $child = null)
{
if (!is_numeric($index)) {
return false;
}
$this->validateChild($child);
$index = $this->getRealIndex($index);
if (!isset($this->_children[$index])) {
return false;
}
$this->_children[$index] = $child;
return true;
} | [
"public",
"function",
"replaceChildAt",
"(",
"$",
"index",
",",
"XMLElement",
"$",
"child",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"index",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"validateChild",
"(",
"$",
"child",
")",
";",
"$",
"index",
"=",
"$",
"this",
"->",
"getRealIndex",
"(",
"$",
"index",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_children",
"[",
"$",
"index",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"_children",
"[",
"$",
"index",
"]",
"=",
"$",
"child",
";",
"return",
"true",
";",
"}"
] | Given the position of the child to replace, and an `XMLElement`
of the replacement child, this function will replace one child
with another
@since Symphony 2.2.2
@param integer $index
The index of the child to be replaced. If the index given is negative
it will be calculated from the end of `$this->_children`.
@param XMLElement $child
An XMLElement of the new child
@return boolean | [
"Given",
"the",
"position",
"of",
"the",
"child",
"to",
"replace",
"and",
"an",
"XMLElement",
"of",
"the",
"replacement",
"child",
"this",
"function",
"will",
"replace",
"one",
"child",
"with",
"another"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L657-L674 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.stripInvalidXMLCharacters | public static function stripInvalidXMLCharacters($value)
{
if (Lang::isUnicodeCompiled()) {
return preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $value);
} else {
$ret = '';
if (empty($value)) {
return $ret;
}
$length = strlen($value);
for ($i=0; $i < $length; $i++) {
$current = ord($value{$i});
if (($current == 0x9) ||
($current == 0xA) ||
($current == 0xD) ||
(($current >= 0x20) && ($current <= 0xD7FF)) ||
(($current >= 0xE000) && ($current <= 0xFFFD)) ||
(($current >= 0x10000) && ($current <= 0x10FFFF))) {
$ret .= chr($current);
}
}
return $ret;
}
} | php | public static function stripInvalidXMLCharacters($value)
{
if (Lang::isUnicodeCompiled()) {
return preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $value);
} else {
$ret = '';
if (empty($value)) {
return $ret;
}
$length = strlen($value);
for ($i=0; $i < $length; $i++) {
$current = ord($value{$i});
if (($current == 0x9) ||
($current == 0xA) ||
($current == 0xD) ||
(($current >= 0x20) && ($current <= 0xD7FF)) ||
(($current >= 0xE000) && ($current <= 0xFFFD)) ||
(($current >= 0x10000) && ($current <= 0x10FFFF))) {
$ret .= chr($current);
}
}
return $ret;
}
} | [
"public",
"static",
"function",
"stripInvalidXMLCharacters",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"Lang",
"::",
"isUnicodeCompiled",
"(",
")",
")",
"{",
"return",
"preg_replace",
"(",
"'/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u'",
",",
"' '",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"ret",
"=",
"''",
";",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"ret",
";",
"}",
"$",
"length",
"=",
"strlen",
"(",
"$",
"value",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"current",
"=",
"ord",
"(",
"$",
"value",
"{",
"$",
"i",
"}",
")",
";",
"if",
"(",
"(",
"$",
"current",
"==",
"0x9",
")",
"||",
"(",
"$",
"current",
"==",
"0xA",
")",
"||",
"(",
"$",
"current",
"==",
"0xD",
")",
"||",
"(",
"(",
"$",
"current",
">=",
"0x20",
")",
"&&",
"(",
"$",
"current",
"<=",
"0xD7FF",
")",
")",
"||",
"(",
"(",
"$",
"current",
">=",
"0xE000",
")",
"&&",
"(",
"$",
"current",
"<=",
"0xFFFD",
")",
")",
"||",
"(",
"(",
"$",
"current",
">=",
"0x10000",
")",
"&&",
"(",
"$",
"current",
"<=",
"0x10FFFF",
")",
")",
")",
"{",
"$",
"ret",
".=",
"chr",
"(",
"$",
"current",
")",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}",
"}"
] | This function strips characters that are not allowed in XML
@since Symphony 2.3
@link http://www.w3.org/TR/xml/#charsets
@link http://www.phpedit.net/snippet/Remove-Invalid-XML-Characters
@param string $value
@return string | [
"This",
"function",
"strips",
"characters",
"that",
"are",
"not",
"allowed",
"in",
"XML"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L705-L732 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.generate | public function generate($indent = false, $tab_depth = 0, $has_parent = false)
{
$result = null;
$newline = ($indent ? PHP_EOL : null);
if (!$has_parent) {
if ($this->_includeHeader) {
$result .= sprintf(
'<?xml version="%s" encoding="%s" ?>%s',
$this->_version,
$this->_encoding,
$newline
);
}
if ($this->_dtd) {
$result .= $this->_dtd . $newline;
}
if (is_array($this->_processingInstructions) && !empty($this->_processingInstructions)) {
$result .= implode(PHP_EOL, $this->_processingInstructions);
}
}
$result .= ($indent ? str_repeat("\t", $tab_depth) : null) . '<' . $this->getName();
$attributes = $this->getAttributes();
if (!empty($attributes)) {
foreach ($attributes as $attribute => $value) {
$length = strlen($value);
if ($length !== 0 || $length === 0 && $this->_allowEmptyAttributes) {
$result .= sprintf(' %s="%s"', $attribute, $value);
}
}
}
$value = $this->getValue();
$added_newline = false;
if ($this->getNumberOfChildren() > 0 || strlen($value) !== 0 || !$this->_selfclosing) {
$result .= '>';
foreach ($this->_children as $i => $child) {
if (!($child instanceof XMLElement)) {
$result .= $child;
} else {
if ($added_newline === false) {
$added_newline = true;
$result .= $newline;
}
$child->setElementStyle($this->_elementStyle);
$result .= $child->generate($indent, $tab_depth + 1, true);
}
}
$result .= sprintf(
"%s</%s>%s",
($indent && $added_newline ? str_repeat("\t", $tab_depth) : null),
$this->getName(),
$newline
);
// Empty elements:
} else {
if ($this->_elementStyle === 'xml') {
$result .= ' />';
} elseif (in_array($this->_name, XMLElement::$no_end_tags) || (substr($this->getName(), 0, 3) === '!--')) {
$result .= '>';
} else {
$result .= sprintf("></%s>", $this->getName());
}
$result .= $newline;
}
return $result;
} | php | public function generate($indent = false, $tab_depth = 0, $has_parent = false)
{
$result = null;
$newline = ($indent ? PHP_EOL : null);
if (!$has_parent) {
if ($this->_includeHeader) {
$result .= sprintf(
'<?xml version="%s" encoding="%s" ?>%s',
$this->_version,
$this->_encoding,
$newline
);
}
if ($this->_dtd) {
$result .= $this->_dtd . $newline;
}
if (is_array($this->_processingInstructions) && !empty($this->_processingInstructions)) {
$result .= implode(PHP_EOL, $this->_processingInstructions);
}
}
$result .= ($indent ? str_repeat("\t", $tab_depth) : null) . '<' . $this->getName();
$attributes = $this->getAttributes();
if (!empty($attributes)) {
foreach ($attributes as $attribute => $value) {
$length = strlen($value);
if ($length !== 0 || $length === 0 && $this->_allowEmptyAttributes) {
$result .= sprintf(' %s="%s"', $attribute, $value);
}
}
}
$value = $this->getValue();
$added_newline = false;
if ($this->getNumberOfChildren() > 0 || strlen($value) !== 0 || !$this->_selfclosing) {
$result .= '>';
foreach ($this->_children as $i => $child) {
if (!($child instanceof XMLElement)) {
$result .= $child;
} else {
if ($added_newline === false) {
$added_newline = true;
$result .= $newline;
}
$child->setElementStyle($this->_elementStyle);
$result .= $child->generate($indent, $tab_depth + 1, true);
}
}
$result .= sprintf(
"%s</%s>%s",
($indent && $added_newline ? str_repeat("\t", $tab_depth) : null),
$this->getName(),
$newline
);
// Empty elements:
} else {
if ($this->_elementStyle === 'xml') {
$result .= ' />';
} elseif (in_array($this->_name, XMLElement::$no_end_tags) || (substr($this->getName(), 0, 3) === '!--')) {
$result .= '>';
} else {
$result .= sprintf("></%s>", $this->getName());
}
$result .= $newline;
}
return $result;
} | [
"public",
"function",
"generate",
"(",
"$",
"indent",
"=",
"false",
",",
"$",
"tab_depth",
"=",
"0",
",",
"$",
"has_parent",
"=",
"false",
")",
"{",
"$",
"result",
"=",
"null",
";",
"$",
"newline",
"=",
"(",
"$",
"indent",
"?",
"PHP_EOL",
":",
"null",
")",
";",
"if",
"(",
"!",
"$",
"has_parent",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_includeHeader",
")",
"{",
"$",
"result",
".=",
"sprintf",
"(",
"'<?xml version=\"%s\" encoding=\"%s\" ?>%s'",
",",
"$",
"this",
"->",
"_version",
",",
"$",
"this",
"->",
"_encoding",
",",
"$",
"newline",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_dtd",
")",
"{",
"$",
"result",
".=",
"$",
"this",
"->",
"_dtd",
".",
"$",
"newline",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"_processingInstructions",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"_processingInstructions",
")",
")",
"{",
"$",
"result",
".=",
"implode",
"(",
"PHP_EOL",
",",
"$",
"this",
"->",
"_processingInstructions",
")",
";",
"}",
"}",
"$",
"result",
".=",
"(",
"$",
"indent",
"?",
"str_repeat",
"(",
"\"\\t\"",
",",
"$",
"tab_depth",
")",
":",
"null",
")",
".",
"'<'",
".",
"$",
"this",
"->",
"getName",
"(",
")",
";",
"$",
"attributes",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"attributes",
")",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
"=>",
"$",
"value",
")",
"{",
"$",
"length",
"=",
"strlen",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"length",
"!==",
"0",
"||",
"$",
"length",
"===",
"0",
"&&",
"$",
"this",
"->",
"_allowEmptyAttributes",
")",
"{",
"$",
"result",
".=",
"sprintf",
"(",
"' %s=\"%s\"'",
",",
"$",
"attribute",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"getValue",
"(",
")",
";",
"$",
"added_newline",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"getNumberOfChildren",
"(",
")",
">",
"0",
"||",
"strlen",
"(",
"$",
"value",
")",
"!==",
"0",
"||",
"!",
"$",
"this",
"->",
"_selfclosing",
")",
"{",
"$",
"result",
".=",
"'>'",
";",
"foreach",
"(",
"$",
"this",
"->",
"_children",
"as",
"$",
"i",
"=>",
"$",
"child",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"child",
"instanceof",
"XMLElement",
")",
")",
"{",
"$",
"result",
".=",
"$",
"child",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"added_newline",
"===",
"false",
")",
"{",
"$",
"added_newline",
"=",
"true",
";",
"$",
"result",
".=",
"$",
"newline",
";",
"}",
"$",
"child",
"->",
"setElementStyle",
"(",
"$",
"this",
"->",
"_elementStyle",
")",
";",
"$",
"result",
".=",
"$",
"child",
"->",
"generate",
"(",
"$",
"indent",
",",
"$",
"tab_depth",
"+",
"1",
",",
"true",
")",
";",
"}",
"}",
"$",
"result",
".=",
"sprintf",
"(",
"\"%s</%s>%s\"",
",",
"(",
"$",
"indent",
"&&",
"$",
"added_newline",
"?",
"str_repeat",
"(",
"\"\\t\"",
",",
"$",
"tab_depth",
")",
":",
"null",
")",
",",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"$",
"newline",
")",
";",
"// Empty elements:",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"_elementStyle",
"===",
"'xml'",
")",
"{",
"$",
"result",
".=",
"' />'",
";",
"}",
"elseif",
"(",
"in_array",
"(",
"$",
"this",
"->",
"_name",
",",
"XMLElement",
"::",
"$",
"no_end_tags",
")",
"||",
"(",
"substr",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"0",
",",
"3",
")",
"===",
"'!--'",
")",
")",
"{",
"$",
"result",
".=",
"'>'",
";",
"}",
"else",
"{",
"$",
"result",
".=",
"sprintf",
"(",
"\"></%s>\"",
",",
"$",
"this",
"->",
"getName",
"(",
")",
")",
";",
"}",
"$",
"result",
".=",
"$",
"newline",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | This function will turn the `XMLElement` into a string
representing the element as it would appear in the markup.
The result is valid XML.
@param boolean $indent
Defaults to false
@param integer $tab_depth
Defaults to 0, indicates the number of tabs (\t) that this
element should be indented by in the output string
@param boolean $has_parent
Defaults to false, set to true when the children are being
generated. Only the parent will output an XML declaration
if `$this->_includeHeader` is set to true.
@return string | [
"This",
"function",
"will",
"turn",
"the",
"XMLElement",
"into",
"a",
"string",
"representing",
"the",
"element",
"as",
"it",
"would",
"appear",
"in",
"the",
"markup",
".",
"The",
"result",
"is",
"valid",
"XML",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L750-L828 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.convertFromXMLString | public static function convertFromXMLString($root_element, $xml)
{
$doc = new DOMDocument('1.0', 'utf-8');
$doc->loadXML($xml);
return self::convertFromDOMDocument($root_element, $doc);
} | php | public static function convertFromXMLString($root_element, $xml)
{
$doc = new DOMDocument('1.0', 'utf-8');
$doc->loadXML($xml);
return self::convertFromDOMDocument($root_element, $doc);
} | [
"public",
"static",
"function",
"convertFromXMLString",
"(",
"$",
"root_element",
",",
"$",
"xml",
")",
"{",
"$",
"doc",
"=",
"new",
"DOMDocument",
"(",
"'1.0'",
",",
"'utf-8'",
")",
";",
"$",
"doc",
"->",
"loadXML",
"(",
"$",
"xml",
")",
";",
"return",
"self",
"::",
"convertFromDOMDocument",
"(",
"$",
"root_element",
",",
"$",
"doc",
")",
";",
"}"
] | Given a string of XML, this function will convert it to an `XMLElement`
object and return the result.
@since Symphony 2.4
@param string $root_element
@param string $xml
A string of XML
@return XMLElement | [
"Given",
"a",
"string",
"of",
"XML",
"this",
"function",
"will",
"convert",
"it",
"to",
"an",
"XMLElement",
"object",
"and",
"return",
"the",
"result",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L840-L846 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.convertFromDOMDocument | public static function convertFromDOMDocument($root_element, DOMDocument $doc)
{
$xpath = new DOMXPath($doc);
$root = new XMLElement($root_element);
foreach ($xpath->query('.') as $node) {
self::convertNode($root, $node);
}
return $root;
} | php | public static function convertFromDOMDocument($root_element, DOMDocument $doc)
{
$xpath = new DOMXPath($doc);
$root = new XMLElement($root_element);
foreach ($xpath->query('.') as $node) {
self::convertNode($root, $node);
}
return $root;
} | [
"public",
"static",
"function",
"convertFromDOMDocument",
"(",
"$",
"root_element",
",",
"DOMDocument",
"$",
"doc",
")",
"{",
"$",
"xpath",
"=",
"new",
"DOMXPath",
"(",
"$",
"doc",
")",
";",
"$",
"root",
"=",
"new",
"XMLElement",
"(",
"$",
"root_element",
")",
";",
"foreach",
"(",
"$",
"xpath",
"->",
"query",
"(",
"'.'",
")",
"as",
"$",
"node",
")",
"{",
"self",
"::",
"convertNode",
"(",
"$",
"root",
",",
"$",
"node",
")",
";",
"}",
"return",
"$",
"root",
";",
"}"
] | Given a `DOMDocument`, this function will convert it to an `XMLElement`
object and return the result.
@since Symphony 2.4
@param string $root_element
@param DOMDOcument $doc
@return XMLElement | [
"Given",
"a",
"DOMDocument",
"this",
"function",
"will",
"convert",
"it",
"to",
"an",
"XMLElement",
"object",
"and",
"return",
"the",
"result",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L857-L867 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xmlelement.php | XMLElement.convert | private static function convert(XMLElement $root = null, DOMNode $node)
{
$el = new XMLElement($node->tagName);
self::convertNode($el, $node);
if (is_null($root)) {
return $el;
} else {
$root->appendChild($el);
}
} | php | private static function convert(XMLElement $root = null, DOMNode $node)
{
$el = new XMLElement($node->tagName);
self::convertNode($el, $node);
if (is_null($root)) {
return $el;
} else {
$root->appendChild($el);
}
} | [
"private",
"static",
"function",
"convert",
"(",
"XMLElement",
"$",
"root",
"=",
"null",
",",
"DOMNode",
"$",
"node",
")",
"{",
"$",
"el",
"=",
"new",
"XMLElement",
"(",
"$",
"node",
"->",
"tagName",
")",
";",
"self",
"::",
"convertNode",
"(",
"$",
"el",
",",
"$",
"node",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"root",
")",
")",
"{",
"return",
"$",
"el",
";",
"}",
"else",
"{",
"$",
"root",
"->",
"appendChild",
"(",
"$",
"el",
")",
";",
"}",
"}"
] | This helper function is used by `XMLElement::convertFromDOMDocument`
to recursively convert `DOMNode` into an `XMLElement` structure
@since Symphony 2.4
@param XMLElement $root
@param DOMNOde $node
@return XMLElement | [
"This",
"helper",
"function",
"is",
"used",
"by",
"XMLElement",
"::",
"convertFromDOMDocument",
"to",
"recursively",
"convert",
"DOMNode",
"into",
"an",
"XMLElement",
"structure"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xmlelement.php#L878-L889 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.