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/core/class.session.php | Session.write | public static function write($id, $data)
{
// Only prevent this record from saving if there isn't already a record
// in the database. This prevents empty Sessions from being created, but
// allows them to be nulled.
$session_data = Session::read($id);
if (!$session_data) {
$empty = true;
if (function_exists('session_status') && session_status() === PHP_SESSION_ACTIVE) {
$unserialized_data = Session::unserialize($data);
foreach ($unserialized_data as $d) {
if (!empty($d)) {
$empty = false;
}
}
if ($empty) {
return true;
}
// PHP 7.0 makes the session inactive in write callback,
// so we try to detect empty sessions without decoding them
} elseif ($data === Symphony::Configuration()->get('cookie_prefix', 'symphony') . '|a:0:{}') {
return true;
}
}
$fields = array(
'session' => $id,
'session_expires' => time(),
'session_data' => $data
);
return Symphony::Database()->insert($fields, 'tbl_sessions', true);
} | php | public static function write($id, $data)
{
// Only prevent this record from saving if there isn't already a record
// in the database. This prevents empty Sessions from being created, but
// allows them to be nulled.
$session_data = Session::read($id);
if (!$session_data) {
$empty = true;
if (function_exists('session_status') && session_status() === PHP_SESSION_ACTIVE) {
$unserialized_data = Session::unserialize($data);
foreach ($unserialized_data as $d) {
if (!empty($d)) {
$empty = false;
}
}
if ($empty) {
return true;
}
// PHP 7.0 makes the session inactive in write callback,
// so we try to detect empty sessions without decoding them
} elseif ($data === Symphony::Configuration()->get('cookie_prefix', 'symphony') . '|a:0:{}') {
return true;
}
}
$fields = array(
'session' => $id,
'session_expires' => time(),
'session_data' => $data
);
return Symphony::Database()->insert($fields, 'tbl_sessions', true);
} | [
"public",
"static",
"function",
"write",
"(",
"$",
"id",
",",
"$",
"data",
")",
"{",
"// Only prevent this record from saving if there isn't already a record",
"// in the database. This prevents empty Sessions from being created, but",
"// allows them to be nulled.",
"$",
"session_data",
"=",
"Session",
"::",
"read",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"session_data",
")",
"{",
"$",
"empty",
"=",
"true",
";",
"if",
"(",
"function_exists",
"(",
"'session_status'",
")",
"&&",
"session_status",
"(",
")",
"===",
"PHP_SESSION_ACTIVE",
")",
"{",
"$",
"unserialized_data",
"=",
"Session",
"::",
"unserialize",
"(",
"$",
"data",
")",
";",
"foreach",
"(",
"$",
"unserialized_data",
"as",
"$",
"d",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"d",
")",
")",
"{",
"$",
"empty",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"$",
"empty",
")",
"{",
"return",
"true",
";",
"}",
"// PHP 7.0 makes the session inactive in write callback,",
"// so we try to detect empty sessions without decoding them",
"}",
"elseif",
"(",
"$",
"data",
"===",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'cookie_prefix'",
",",
"'symphony'",
")",
".",
"'|a:0:{}'",
")",
"{",
"return",
"true",
";",
"}",
"}",
"$",
"fields",
"=",
"array",
"(",
"'session'",
"=>",
"$",
"id",
",",
"'session_expires'",
"=>",
"time",
"(",
")",
",",
"'session_data'",
"=>",
"$",
"data",
")",
";",
"return",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"insert",
"(",
"$",
"fields",
",",
"'tbl_sessions'",
",",
"true",
")",
";",
"}"
] | Given an ID, and some data, save it into `tbl_sessions`. This uses
the ID as a unique key, and will override any existing data. If the
`$data` is deemed to be empty, no row will be saved in the database
unless there is an existing row.
@param string $id
The ID of the Session, usually a hash
@param string $data
The Session information, usually a serialized object of
`$_SESSION[Cookie->_index]`
@throws DatabaseException
@return boolean
true if the Session information was saved successfully, false otherwise | [
"Given",
"an",
"ID",
"and",
"some",
"data",
"save",
"it",
"into",
"tbl_sessions",
".",
"This",
"uses",
"the",
"ID",
"as",
"a",
"unique",
"key",
"and",
"will",
"override",
"any",
"existing",
"data",
".",
"If",
"the",
"$data",
"is",
"deemed",
"to",
"be",
"empty",
"no",
"row",
"will",
"be",
"saved",
"in",
"the",
"database",
"unless",
"there",
"is",
"an",
"existing",
"row",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.session.php#L180-L214 |
symphonycms/symphony-2 | symphony/lib/core/class.session.php | Session.unserialize | private static function unserialize($data)
{
$hasBuffer = isset($_SESSION);
$buffer = $_SESSION;
session_decode($data);
$session = $_SESSION;
if ($hasBuffer) {
$_SESSION = $buffer;
} else {
unset($_SESSION);
}
return $session;
} | php | private static function unserialize($data)
{
$hasBuffer = isset($_SESSION);
$buffer = $_SESSION;
session_decode($data);
$session = $_SESSION;
if ($hasBuffer) {
$_SESSION = $buffer;
} else {
unset($_SESSION);
}
return $session;
} | [
"private",
"static",
"function",
"unserialize",
"(",
"$",
"data",
")",
"{",
"$",
"hasBuffer",
"=",
"isset",
"(",
"$",
"_SESSION",
")",
";",
"$",
"buffer",
"=",
"$",
"_SESSION",
";",
"session_decode",
"(",
"$",
"data",
")",
";",
"$",
"session",
"=",
"$",
"_SESSION",
";",
"if",
"(",
"$",
"hasBuffer",
")",
"{",
"$",
"_SESSION",
"=",
"$",
"buffer",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"_SESSION",
")",
";",
"}",
"return",
"$",
"session",
";",
"}"
] | Given raw session data return the unserialized array.
Used to check if the session is really empty before writing.
@since Symphony 2.3.3
@param string $data
The serialized session data
@return array
The unserialised session data | [
"Given",
"raw",
"session",
"data",
"return",
"the",
"unserialized",
"array",
".",
"Used",
"to",
"check",
"if",
"the",
"session",
"is",
"really",
"empty",
"before",
"writing",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.session.php#L226-L240 |
symphonycms/symphony-2 | symphony/lib/core/class.session.php | Session.read | public static function read($id)
{
return (string)Symphony::Database()->fetchVar(
'session_data',
0,
sprintf(
"SELECT `session_data`
FROM `tbl_sessions`
WHERE `session` = '%s'
LIMIT 1",
Symphony::Database()->cleanValue($id)
)
);
} | php | public static function read($id)
{
return (string)Symphony::Database()->fetchVar(
'session_data',
0,
sprintf(
"SELECT `session_data`
FROM `tbl_sessions`
WHERE `session` = '%s'
LIMIT 1",
Symphony::Database()->cleanValue($id)
)
);
} | [
"public",
"static",
"function",
"read",
"(",
"$",
"id",
")",
"{",
"return",
"(",
"string",
")",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchVar",
"(",
"'session_data'",
",",
"0",
",",
"sprintf",
"(",
"\"SELECT `session_data`\n FROM `tbl_sessions`\n WHERE `session` = '%s'\n LIMIT 1\"",
",",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"cleanValue",
"(",
"$",
"id",
")",
")",
")",
";",
"}"
] | Given a session's ID, return it's row from `tbl_sessions`
@param string $id
The identifier for the Session to fetch
@return string
The serialised session data | [
"Given",
"a",
"session",
"s",
"ID",
"return",
"it",
"s",
"row",
"from",
"tbl_sessions"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.session.php#L250-L263 |
symphonycms/symphony-2 | symphony/lib/core/class.session.php | Session.destroy | public static function destroy($id)
{
return Symphony::Database()->query(
sprintf(
"DELETE
FROM `tbl_sessions`
WHERE `session` = '%s'",
Symphony::Database()->cleanValue($id)
)
);
} | php | public static function destroy($id)
{
return Symphony::Database()->query(
sprintf(
"DELETE
FROM `tbl_sessions`
WHERE `session` = '%s'",
Symphony::Database()->cleanValue($id)
)
);
} | [
"public",
"static",
"function",
"destroy",
"(",
"$",
"id",
")",
"{",
"return",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"query",
"(",
"sprintf",
"(",
"\"DELETE\n FROM `tbl_sessions`\n WHERE `session` = '%s'\"",
",",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"cleanValue",
"(",
"$",
"id",
")",
")",
")",
";",
"}"
] | Given a session's ID, remove it's row from `tbl_sessions`
@param string $id
The identifier for the Session to destroy
@throws DatabaseException
@return boolean
true if the Session was deleted successfully, false otherwise | [
"Given",
"a",
"session",
"s",
"ID",
"remove",
"it",
"s",
"row",
"from",
"tbl_sessions"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.session.php#L274-L284 |
symphonycms/symphony-2 | symphony/lib/core/class.session.php | Session.gc | public static function gc($max)
{
return Symphony::Database()->query(
sprintf(
"DELETE
FROM `tbl_sessions`
WHERE `session_expires` <= %d",
Symphony::Database()->cleanValue(time() - $max)
)
);
} | php | public static function gc($max)
{
return Symphony::Database()->query(
sprintf(
"DELETE
FROM `tbl_sessions`
WHERE `session_expires` <= %d",
Symphony::Database()->cleanValue(time() - $max)
)
);
} | [
"public",
"static",
"function",
"gc",
"(",
"$",
"max",
")",
"{",
"return",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"query",
"(",
"sprintf",
"(",
"\"DELETE\n FROM `tbl_sessions`\n WHERE `session_expires` <= %d\"",
",",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"cleanValue",
"(",
"time",
"(",
")",
"-",
"$",
"max",
")",
")",
")",
";",
"}"
] | The garbage collector, which removes all empty Sessions, or any
Sessions that have expired. This has a 10% chance of firing based
off the `gc_probability`/`gc_divisor`.
@param integer $max
The max session lifetime.
@throws DatabaseException
@return boolean
true on Session deletion, false if an error occurs | [
"The",
"garbage",
"collector",
"which",
"removes",
"all",
"empty",
"Sessions",
"or",
"any",
"Sessions",
"that",
"have",
"expired",
".",
"This",
"has",
"a",
"10%",
"chance",
"of",
"firing",
"based",
"off",
"the",
"gc_probability",
"/",
"gc_divisor",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.session.php#L297-L307 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.jsonpage.php | JSONPage.generate | public function generate($page = null)
{
// Set the actual status code in the xml response
$this->_Result['status'] = $this->getHttpStatusCode();
parent::generate($page);
return json_encode($this->_Result);
} | php | public function generate($page = null)
{
// Set the actual status code in the xml response
$this->_Result['status'] = $this->getHttpStatusCode();
parent::generate($page);
return json_encode($this->_Result);
} | [
"public",
"function",
"generate",
"(",
"$",
"page",
"=",
"null",
")",
"{",
"// Set the actual status code in the xml response",
"$",
"this",
"->",
"_Result",
"[",
"'status'",
"]",
"=",
"$",
"this",
"->",
"getHttpStatusCode",
"(",
")",
";",
"parent",
"::",
"generate",
"(",
"$",
"page",
")",
";",
"return",
"json_encode",
"(",
"$",
"this",
"->",
"_Result",
")",
";",
"}"
] | The generate functions outputs the correct headers for
this `JSONPage`, adds `$this->getHttpStatusCode()` code to the root attribute
before calling the parent generate function and generating
the `$this->_Result` json string
@param null $page
@return string | [
"The",
"generate",
"functions",
"outputs",
"the",
"correct",
"headers",
"for",
"this",
"JSONPage",
"adds",
"$this",
"-",
">",
"getHttpStatusCode",
"()",
"code",
"to",
"the",
"root",
"attribute",
"before",
"calling",
"the",
"parent",
"generate",
"function",
"and",
"generating",
"the",
"$this",
"-",
">",
"_Result",
"json",
"string"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.jsonpage.php#L56-L64 |
symphonycms/symphony-2 | symphony/content/content.systempreferences.php | contentSystemPreferences.view | public function view()
{
$this->setPageType('form');
$this->setTitle(__('%1$s – %2$s', array(__('Preferences'), __('Symphony'))));
$this->addElementToHead(new XMLElement('link', null, array(
'rel' => 'canonical',
'href' => SYMPHONY_URL . '/system/preferences/',
)));
$this->appendSubheading(__('Preferences'));
$bIsWritable = true;
$formHasErrors = (is_array($this->_errors) && !empty($this->_errors));
if (General::checkFileWritable(CONFIG) === false) {
$this->pageAlert(__('The Symphony configuration file, %s, or folder is not writable. You will not be able to save changes to preferences.', array('<code>/manifest/config.php</code>')), Alert::ERROR);
$bIsWritable = false;
} elseif ($formHasErrors) {
$this->pageAlert(
__('An error occurred while processing this form. See below for details.'), Alert::ERROR
);
} elseif (isset($this->_context[0]) && $this->_context[0] == 'success') {
$this->pageAlert(__('Preferences saved.'), Alert::SUCCESS);
}
// Get available languages
$languages = Lang::getAvailableLanguages();
if (count($languages) > 1) {
// Create language selection
$group = new XMLElement('fieldset');
$group->setAttribute('class', 'settings');
$group->appendChild(new XMLElement('legend', __('System Language')));
$label = Widget::Label();
// Get language names
asort($languages);
$options = array();
foreach ($languages as $code => $name) {
$options[] = array($code, $code == Symphony::Configuration()->get('lang', 'symphony'), $name);
}
$select = Widget::Select('settings[symphony][lang]', $options);
$label->appendChild($select);
$group->appendChild($label);
$group->appendChild(new XMLElement('p', __('Authors can set up a differing language in their profiles.'), array('class' => 'help')));
// Append language selection
$this->Form->appendChild($group);
}
// Get available EmailGateways
$email_gateways = EmailGatewayManager::listAll();
if (count($email_gateways) >= 1) {
$group = new XMLElement('fieldset', null, array('class' => 'settings condensed'));
$group->appendChild(new XMLElement('legend', __('Default Email Settings')));
$label = Widget::Label(__('Gateway'));
// Get gateway names
ksort($email_gateways);
$default_gateway = EmailGatewayManager::getDefaultGateway();
$selected_is_installed = EmailGatewayManager::__getClassPath($default_gateway);
$options = array();
foreach ($email_gateways as $handle => $details) {
$options[] = array($handle, (($handle == $default_gateway) || (($selected_is_installed == false) && $handle == 'sendmail')), $details['name']);
}
$select = Widget::Select('settings[Email][default_gateway]', $options, array('class' => 'picker', 'data-interactive' => 'data-interactive'));
$label->appendChild($select);
$group->appendChild($label);
// Append email gateway selection
$this->Form->appendChild($group);
}
foreach ($email_gateways as $gateway) {
$gateway_settings = EmailGatewayManager::create($gateway['handle'])->getPreferencesPane();
if (is_a($gateway_settings, 'XMLElement')) {
$this->Form->appendChild($gateway_settings);
}
}
// Get available cache drivers
$caches = Symphony::ExtensionManager()->getProvidersOf('cache');
// Add default Symphony cache driver..
$caches['database'] = 'Database';
if (count($caches) > 1) {
$group = new XMLElement('fieldset', null, array('class' => 'settings condensed'));
$group->appendChild(new XMLElement('legend', __('Default Cache Settings')));
/**
* Add custom Caching groups. For example a Datasource extension might want to add in the ability
* for set a cache driver for it's functionality. This should usually be a dropdown, which allows
* a developer to select what driver they want to use for caching. This choice is stored in the
* Configuration in a Caching node.
* eg.
* 'caching' => array (
* 'remote_datasource' => 'database',
* 'dynamic_ds' => 'YourCachingExtensionClassName'
* )
*
* @since Symphony 2.4
* @delegate AddCachingOpportunity
* @param string $context
* '/system/preferences/'
* @param XMLElement $wrapper
* An XMLElement of the current Caching fieldset
* @param string $config_path
* The node in the Configuration where this information will be stored. Read only.
* @param array $available_caches
* An array of the available cache providers
* @param array $errors
* An array of errors
*/
Symphony::ExtensionManager()->notifyMembers('AddCachingOpportunity', '/system/preferences/', array(
'wrapper' => &$group,
'config_path' => 'caching',
'available_caches' => $caches,
'errors' => $this->_errors
));
$this->Form->appendChild($group);
}
/**
* Add Extension custom preferences. Use the $wrapper reference to append objects.
*
* @delegate AddCustomPreferenceFieldsets
* @param string $context
* '/system/preferences/'
* @param XMLElement $wrapper
* An XMLElement of the current page
* @param array $errors
* An array of errors
*/
Symphony::ExtensionManager()->notifyMembers('AddCustomPreferenceFieldsets', '/system/preferences/', array(
'wrapper' => &$this->Form,
'errors' => $this->_errors
));
$div = new XMLElement('div');
$div->setAttribute('class', 'actions');
$version = new XMLElement('p', 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), array(
'id' => 'version'
));
$div->appendChild($version);
$attr = array('accesskey' => 's');
if (!$bIsWritable) {
$attr['disabled'] = 'disabled';
}
$div->appendChild(Widget::Input('action[save]', __('Save Changes'), 'submit', $attr));
$this->Form->appendChild($div);
} | php | public function view()
{
$this->setPageType('form');
$this->setTitle(__('%1$s – %2$s', array(__('Preferences'), __('Symphony'))));
$this->addElementToHead(new XMLElement('link', null, array(
'rel' => 'canonical',
'href' => SYMPHONY_URL . '/system/preferences/',
)));
$this->appendSubheading(__('Preferences'));
$bIsWritable = true;
$formHasErrors = (is_array($this->_errors) && !empty($this->_errors));
if (General::checkFileWritable(CONFIG) === false) {
$this->pageAlert(__('The Symphony configuration file, %s, or folder is not writable. You will not be able to save changes to preferences.', array('<code>/manifest/config.php</code>')), Alert::ERROR);
$bIsWritable = false;
} elseif ($formHasErrors) {
$this->pageAlert(
__('An error occurred while processing this form. See below for details.'), Alert::ERROR
);
} elseif (isset($this->_context[0]) && $this->_context[0] == 'success') {
$this->pageAlert(__('Preferences saved.'), Alert::SUCCESS);
}
// Get available languages
$languages = Lang::getAvailableLanguages();
if (count($languages) > 1) {
// Create language selection
$group = new XMLElement('fieldset');
$group->setAttribute('class', 'settings');
$group->appendChild(new XMLElement('legend', __('System Language')));
$label = Widget::Label();
// Get language names
asort($languages);
$options = array();
foreach ($languages as $code => $name) {
$options[] = array($code, $code == Symphony::Configuration()->get('lang', 'symphony'), $name);
}
$select = Widget::Select('settings[symphony][lang]', $options);
$label->appendChild($select);
$group->appendChild($label);
$group->appendChild(new XMLElement('p', __('Authors can set up a differing language in their profiles.'), array('class' => 'help')));
// Append language selection
$this->Form->appendChild($group);
}
// Get available EmailGateways
$email_gateways = EmailGatewayManager::listAll();
if (count($email_gateways) >= 1) {
$group = new XMLElement('fieldset', null, array('class' => 'settings condensed'));
$group->appendChild(new XMLElement('legend', __('Default Email Settings')));
$label = Widget::Label(__('Gateway'));
// Get gateway names
ksort($email_gateways);
$default_gateway = EmailGatewayManager::getDefaultGateway();
$selected_is_installed = EmailGatewayManager::__getClassPath($default_gateway);
$options = array();
foreach ($email_gateways as $handle => $details) {
$options[] = array($handle, (($handle == $default_gateway) || (($selected_is_installed == false) && $handle == 'sendmail')), $details['name']);
}
$select = Widget::Select('settings[Email][default_gateway]', $options, array('class' => 'picker', 'data-interactive' => 'data-interactive'));
$label->appendChild($select);
$group->appendChild($label);
// Append email gateway selection
$this->Form->appendChild($group);
}
foreach ($email_gateways as $gateway) {
$gateway_settings = EmailGatewayManager::create($gateway['handle'])->getPreferencesPane();
if (is_a($gateway_settings, 'XMLElement')) {
$this->Form->appendChild($gateway_settings);
}
}
// Get available cache drivers
$caches = Symphony::ExtensionManager()->getProvidersOf('cache');
// Add default Symphony cache driver..
$caches['database'] = 'Database';
if (count($caches) > 1) {
$group = new XMLElement('fieldset', null, array('class' => 'settings condensed'));
$group->appendChild(new XMLElement('legend', __('Default Cache Settings')));
/**
* Add custom Caching groups. For example a Datasource extension might want to add in the ability
* for set a cache driver for it's functionality. This should usually be a dropdown, which allows
* a developer to select what driver they want to use for caching. This choice is stored in the
* Configuration in a Caching node.
* eg.
* 'caching' => array (
* 'remote_datasource' => 'database',
* 'dynamic_ds' => 'YourCachingExtensionClassName'
* )
*
* @since Symphony 2.4
* @delegate AddCachingOpportunity
* @param string $context
* '/system/preferences/'
* @param XMLElement $wrapper
* An XMLElement of the current Caching fieldset
* @param string $config_path
* The node in the Configuration where this information will be stored. Read only.
* @param array $available_caches
* An array of the available cache providers
* @param array $errors
* An array of errors
*/
Symphony::ExtensionManager()->notifyMembers('AddCachingOpportunity', '/system/preferences/', array(
'wrapper' => &$group,
'config_path' => 'caching',
'available_caches' => $caches,
'errors' => $this->_errors
));
$this->Form->appendChild($group);
}
/**
* Add Extension custom preferences. Use the $wrapper reference to append objects.
*
* @delegate AddCustomPreferenceFieldsets
* @param string $context
* '/system/preferences/'
* @param XMLElement $wrapper
* An XMLElement of the current page
* @param array $errors
* An array of errors
*/
Symphony::ExtensionManager()->notifyMembers('AddCustomPreferenceFieldsets', '/system/preferences/', array(
'wrapper' => &$this->Form,
'errors' => $this->_errors
));
$div = new XMLElement('div');
$div->setAttribute('class', 'actions');
$version = new XMLElement('p', 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), array(
'id' => 'version'
));
$div->appendChild($version);
$attr = array('accesskey' => 's');
if (!$bIsWritable) {
$attr['disabled'] = 'disabled';
}
$div->appendChild(Widget::Input('action[save]', __('Save Changes'), 'submit', $attr));
$this->Form->appendChild($div);
} | [
"public",
"function",
"view",
"(",
")",
"{",
"$",
"this",
"->",
"setPageType",
"(",
"'form'",
")",
";",
"$",
"this",
"->",
"setTitle",
"(",
"__",
"(",
"'%1$s – %2$s'",
",",
"array",
"(",
"__",
"(",
"'Preferences'",
")",
",",
"__",
"(",
"'Symphony'",
")",
")",
")",
")",
";",
"$",
"this",
"->",
"addElementToHead",
"(",
"new",
"XMLElement",
"(",
"'link'",
",",
"null",
",",
"array",
"(",
"'rel'",
"=>",
"'canonical'",
",",
"'href'",
"=>",
"SYMPHONY_URL",
".",
"'/system/preferences/'",
",",
")",
")",
")",
";",
"$",
"this",
"->",
"appendSubheading",
"(",
"__",
"(",
"'Preferences'",
")",
")",
";",
"$",
"bIsWritable",
"=",
"true",
";",
"$",
"formHasErrors",
"=",
"(",
"is_array",
"(",
"$",
"this",
"->",
"_errors",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"_errors",
")",
")",
";",
"if",
"(",
"General",
"::",
"checkFileWritable",
"(",
"CONFIG",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"pageAlert",
"(",
"__",
"(",
"'The Symphony configuration file, %s, or folder is not writable. You will not be able to save changes to preferences.'",
",",
"array",
"(",
"'<code>/manifest/config.php</code>'",
")",
")",
",",
"Alert",
"::",
"ERROR",
")",
";",
"$",
"bIsWritable",
"=",
"false",
";",
"}",
"elseif",
"(",
"$",
"formHasErrors",
")",
"{",
"$",
"this",
"->",
"pageAlert",
"(",
"__",
"(",
"'An error occurred while processing this form. See below for details.'",
")",
",",
"Alert",
"::",
"ERROR",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"_context",
"[",
"0",
"]",
")",
"&&",
"$",
"this",
"->",
"_context",
"[",
"0",
"]",
"==",
"'success'",
")",
"{",
"$",
"this",
"->",
"pageAlert",
"(",
"__",
"(",
"'Preferences saved.'",
")",
",",
"Alert",
"::",
"SUCCESS",
")",
";",
"}",
"// Get available languages",
"$",
"languages",
"=",
"Lang",
"::",
"getAvailableLanguages",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"languages",
")",
">",
"1",
")",
"{",
"// Create language selection",
"$",
"group",
"=",
"new",
"XMLElement",
"(",
"'fieldset'",
")",
";",
"$",
"group",
"->",
"setAttribute",
"(",
"'class'",
",",
"'settings'",
")",
";",
"$",
"group",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'legend'",
",",
"__",
"(",
"'System Language'",
")",
")",
")",
";",
"$",
"label",
"=",
"Widget",
"::",
"Label",
"(",
")",
";",
"// Get language names",
"asort",
"(",
"$",
"languages",
")",
";",
"$",
"options",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"languages",
"as",
"$",
"code",
"=>",
"$",
"name",
")",
"{",
"$",
"options",
"[",
"]",
"=",
"array",
"(",
"$",
"code",
",",
"$",
"code",
"==",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'lang'",
",",
"'symphony'",
")",
",",
"$",
"name",
")",
";",
"}",
"$",
"select",
"=",
"Widget",
"::",
"Select",
"(",
"'settings[symphony][lang]'",
",",
"$",
"options",
")",
";",
"$",
"label",
"->",
"appendChild",
"(",
"$",
"select",
")",
";",
"$",
"group",
"->",
"appendChild",
"(",
"$",
"label",
")",
";",
"$",
"group",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'p'",
",",
"__",
"(",
"'Authors can set up a differing language in their profiles.'",
")",
",",
"array",
"(",
"'class'",
"=>",
"'help'",
")",
")",
")",
";",
"// Append language selection",
"$",
"this",
"->",
"Form",
"->",
"appendChild",
"(",
"$",
"group",
")",
";",
"}",
"// Get available EmailGateways",
"$",
"email_gateways",
"=",
"EmailGatewayManager",
"::",
"listAll",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"email_gateways",
")",
">=",
"1",
")",
"{",
"$",
"group",
"=",
"new",
"XMLElement",
"(",
"'fieldset'",
",",
"null",
",",
"array",
"(",
"'class'",
"=>",
"'settings condensed'",
")",
")",
";",
"$",
"group",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'legend'",
",",
"__",
"(",
"'Default Email Settings'",
")",
")",
")",
";",
"$",
"label",
"=",
"Widget",
"::",
"Label",
"(",
"__",
"(",
"'Gateway'",
")",
")",
";",
"// Get gateway names",
"ksort",
"(",
"$",
"email_gateways",
")",
";",
"$",
"default_gateway",
"=",
"EmailGatewayManager",
"::",
"getDefaultGateway",
"(",
")",
";",
"$",
"selected_is_installed",
"=",
"EmailGatewayManager",
"::",
"__getClassPath",
"(",
"$",
"default_gateway",
")",
";",
"$",
"options",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"email_gateways",
"as",
"$",
"handle",
"=>",
"$",
"details",
")",
"{",
"$",
"options",
"[",
"]",
"=",
"array",
"(",
"$",
"handle",
",",
"(",
"(",
"$",
"handle",
"==",
"$",
"default_gateway",
")",
"||",
"(",
"(",
"$",
"selected_is_installed",
"==",
"false",
")",
"&&",
"$",
"handle",
"==",
"'sendmail'",
")",
")",
",",
"$",
"details",
"[",
"'name'",
"]",
")",
";",
"}",
"$",
"select",
"=",
"Widget",
"::",
"Select",
"(",
"'settings[Email][default_gateway]'",
",",
"$",
"options",
",",
"array",
"(",
"'class'",
"=>",
"'picker'",
",",
"'data-interactive'",
"=>",
"'data-interactive'",
")",
")",
";",
"$",
"label",
"->",
"appendChild",
"(",
"$",
"select",
")",
";",
"$",
"group",
"->",
"appendChild",
"(",
"$",
"label",
")",
";",
"// Append email gateway selection",
"$",
"this",
"->",
"Form",
"->",
"appendChild",
"(",
"$",
"group",
")",
";",
"}",
"foreach",
"(",
"$",
"email_gateways",
"as",
"$",
"gateway",
")",
"{",
"$",
"gateway_settings",
"=",
"EmailGatewayManager",
"::",
"create",
"(",
"$",
"gateway",
"[",
"'handle'",
"]",
")",
"->",
"getPreferencesPane",
"(",
")",
";",
"if",
"(",
"is_a",
"(",
"$",
"gateway_settings",
",",
"'XMLElement'",
")",
")",
"{",
"$",
"this",
"->",
"Form",
"->",
"appendChild",
"(",
"$",
"gateway_settings",
")",
";",
"}",
"}",
"// Get available cache drivers",
"$",
"caches",
"=",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"getProvidersOf",
"(",
"'cache'",
")",
";",
"// Add default Symphony cache driver..",
"$",
"caches",
"[",
"'database'",
"]",
"=",
"'Database'",
";",
"if",
"(",
"count",
"(",
"$",
"caches",
")",
">",
"1",
")",
"{",
"$",
"group",
"=",
"new",
"XMLElement",
"(",
"'fieldset'",
",",
"null",
",",
"array",
"(",
"'class'",
"=>",
"'settings condensed'",
")",
")",
";",
"$",
"group",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'legend'",
",",
"__",
"(",
"'Default Cache Settings'",
")",
")",
")",
";",
"/**\n * Add custom Caching groups. For example a Datasource extension might want to add in the ability\n * for set a cache driver for it's functionality. This should usually be a dropdown, which allows\n * a developer to select what driver they want to use for caching. This choice is stored in the\n * Configuration in a Caching node.\n * eg.\n * 'caching' => array (\n * 'remote_datasource' => 'database',\n * 'dynamic_ds' => 'YourCachingExtensionClassName'\n * )\n *\n * @since Symphony 2.4\n * @delegate AddCachingOpportunity\n * @param string $context\n * '/system/preferences/'\n * @param XMLElement $wrapper\n * An XMLElement of the current Caching fieldset\n * @param string $config_path\n * The node in the Configuration where this information will be stored. Read only.\n * @param array $available_caches\n * An array of the available cache providers\n * @param array $errors\n * An array of errors\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'AddCachingOpportunity'",
",",
"'/system/preferences/'",
",",
"array",
"(",
"'wrapper'",
"=>",
"&",
"$",
"group",
",",
"'config_path'",
"=>",
"'caching'",
",",
"'available_caches'",
"=>",
"$",
"caches",
",",
"'errors'",
"=>",
"$",
"this",
"->",
"_errors",
")",
")",
";",
"$",
"this",
"->",
"Form",
"->",
"appendChild",
"(",
"$",
"group",
")",
";",
"}",
"/**\n * Add Extension custom preferences. Use the $wrapper reference to append objects.\n *\n * @delegate AddCustomPreferenceFieldsets\n * @param string $context\n * '/system/preferences/'\n * @param XMLElement $wrapper\n * An XMLElement of the current page\n * @param array $errors\n * An array of errors\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'AddCustomPreferenceFieldsets'",
",",
"'/system/preferences/'",
",",
"array",
"(",
"'wrapper'",
"=>",
"&",
"$",
"this",
"->",
"Form",
",",
"'errors'",
"=>",
"$",
"this",
"->",
"_errors",
")",
")",
";",
"$",
"div",
"=",
"new",
"XMLElement",
"(",
"'div'",
")",
";",
"$",
"div",
"->",
"setAttribute",
"(",
"'class'",
",",
"'actions'",
")",
";",
"$",
"version",
"=",
"new",
"XMLElement",
"(",
"'p'",
",",
"'Symphony '",
".",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'version'",
",",
"'symphony'",
")",
",",
"array",
"(",
"'id'",
"=>",
"'version'",
")",
")",
";",
"$",
"div",
"->",
"appendChild",
"(",
"$",
"version",
")",
";",
"$",
"attr",
"=",
"array",
"(",
"'accesskey'",
"=>",
"'s'",
")",
";",
"if",
"(",
"!",
"$",
"bIsWritable",
")",
"{",
"$",
"attr",
"[",
"'disabled'",
"]",
"=",
"'disabled'",
";",
"}",
"$",
"div",
"->",
"appendChild",
"(",
"Widget",
"::",
"Input",
"(",
"'action[save]'",
",",
"__",
"(",
"'Save Changes'",
")",
",",
"'submit'",
",",
"$",
"attr",
")",
")",
";",
"$",
"this",
"->",
"Form",
"->",
"appendChild",
"(",
"$",
"div",
")",
";",
"}"
] | Overload the parent 'view' function since we dont need the switchboard logic | [
"Overload",
"the",
"parent",
"view",
"function",
"since",
"we",
"dont",
"need",
"the",
"switchboard",
"logic"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/content/content.systempreferences.php#L19-L180 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.textarea.php | fieldTextarea.__applyFormatting | protected function __applyFormatting($data, $validate = false, &$errors = null)
{
$result = '';
if ($this->get('formatter')) {
$formatter = TextformatterManager::create($this->get('formatter'));
$result = $formatter->run($data);
}
if ($validate === true) {
if (!General::validateXML($result, $errors, false, new XsltProcess)) {
$result = html_entity_decode($result, ENT_QUOTES, 'UTF-8');
$result = $this->__replaceAmpersands($result);
if (!General::validateXML($result, $errors, false, new XsltProcess)) {
return false;
}
}
}
return $result;
} | php | protected function __applyFormatting($data, $validate = false, &$errors = null)
{
$result = '';
if ($this->get('formatter')) {
$formatter = TextformatterManager::create($this->get('formatter'));
$result = $formatter->run($data);
}
if ($validate === true) {
if (!General::validateXML($result, $errors, false, new XsltProcess)) {
$result = html_entity_decode($result, ENT_QUOTES, 'UTF-8');
$result = $this->__replaceAmpersands($result);
if (!General::validateXML($result, $errors, false, new XsltProcess)) {
return false;
}
}
}
return $result;
} | [
"protected",
"function",
"__applyFormatting",
"(",
"$",
"data",
",",
"$",
"validate",
"=",
"false",
",",
"&",
"$",
"errors",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'formatter'",
")",
")",
"{",
"$",
"formatter",
"=",
"TextformatterManager",
"::",
"create",
"(",
"$",
"this",
"->",
"get",
"(",
"'formatter'",
")",
")",
";",
"$",
"result",
"=",
"$",
"formatter",
"->",
"run",
"(",
"$",
"data",
")",
";",
"}",
"if",
"(",
"$",
"validate",
"===",
"true",
")",
"{",
"if",
"(",
"!",
"General",
"::",
"validateXML",
"(",
"$",
"result",
",",
"$",
"errors",
",",
"false",
",",
"new",
"XsltProcess",
")",
")",
"{",
"$",
"result",
"=",
"html_entity_decode",
"(",
"$",
"result",
",",
"ENT_QUOTES",
",",
"'UTF-8'",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"__replaceAmpersands",
"(",
"$",
"result",
")",
";",
"if",
"(",
"!",
"General",
"::",
"validateXML",
"(",
"$",
"result",
",",
"$",
"errors",
",",
"false",
",",
"new",
"XsltProcess",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | /*-------------------------------------------------------------------------
Utilities:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Utilities",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.textarea.php#L60-L81 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.textarea.php | fieldTextarea.displayPublishPanel | public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null)
{
$label = Widget::Label($this->get('label'));
if ($this->get('required') !== 'yes') {
$label->appendChild(new XMLElement('i', __('Optional')));
}
$value = isset($data['value']) ? $data['value'] : null;
$textarea = Widget::Textarea('fields'.$fieldnamePrefix.'['.$this->get('element_name').']'.$fieldnamePostfix, (int)$this->get('size'), 50, (strlen($value) != 0 ? General::sanitizeDouble($value) : null));
if ($this->get('formatter') != 'none') {
$textarea->setAttribute('class', $this->get('formatter'));
}
/**
* Allows developers modify the textarea before it is rendered in the publish forms
*
* @delegate ModifyTextareaFieldPublishWidget
* @param string $context
* '/backend/'
* @param Field $field
* @param Widget $label
* @param Widget $textarea
*/
Symphony::ExtensionManager()->notifyMembers('ModifyTextareaFieldPublishWidget', '/backend/', array(
'field' => &$this,
'label' => &$label,
'textarea' => &$textarea
));
$label->appendChild($textarea);
if ($flagWithError != null) {
$wrapper->appendChild(Widget::Error($label, $flagWithError));
} else {
$wrapper->appendChild($label);
}
} | php | public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null)
{
$label = Widget::Label($this->get('label'));
if ($this->get('required') !== 'yes') {
$label->appendChild(new XMLElement('i', __('Optional')));
}
$value = isset($data['value']) ? $data['value'] : null;
$textarea = Widget::Textarea('fields'.$fieldnamePrefix.'['.$this->get('element_name').']'.$fieldnamePostfix, (int)$this->get('size'), 50, (strlen($value) != 0 ? General::sanitizeDouble($value) : null));
if ($this->get('formatter') != 'none') {
$textarea->setAttribute('class', $this->get('formatter'));
}
/**
* Allows developers modify the textarea before it is rendered in the publish forms
*
* @delegate ModifyTextareaFieldPublishWidget
* @param string $context
* '/backend/'
* @param Field $field
* @param Widget $label
* @param Widget $textarea
*/
Symphony::ExtensionManager()->notifyMembers('ModifyTextareaFieldPublishWidget', '/backend/', array(
'field' => &$this,
'label' => &$label,
'textarea' => &$textarea
));
$label->appendChild($textarea);
if ($flagWithError != null) {
$wrapper->appendChild(Widget::Error($label, $flagWithError));
} else {
$wrapper->appendChild($label);
}
} | [
"public",
"function",
"displayPublishPanel",
"(",
"XMLElement",
"&",
"$",
"wrapper",
",",
"$",
"data",
"=",
"null",
",",
"$",
"flagWithError",
"=",
"null",
",",
"$",
"fieldnamePrefix",
"=",
"null",
",",
"$",
"fieldnamePostfix",
"=",
"null",
",",
"$",
"entry_id",
"=",
"null",
")",
"{",
"$",
"label",
"=",
"Widget",
"::",
"Label",
"(",
"$",
"this",
"->",
"get",
"(",
"'label'",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'required'",
")",
"!==",
"'yes'",
")",
"{",
"$",
"label",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'i'",
",",
"__",
"(",
"'Optional'",
")",
")",
")",
";",
"}",
"$",
"value",
"=",
"isset",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
"?",
"$",
"data",
"[",
"'value'",
"]",
":",
"null",
";",
"$",
"textarea",
"=",
"Widget",
"::",
"Textarea",
"(",
"'fields'",
".",
"$",
"fieldnamePrefix",
".",
"'['",
".",
"$",
"this",
"->",
"get",
"(",
"'element_name'",
")",
".",
"']'",
".",
"$",
"fieldnamePostfix",
",",
"(",
"int",
")",
"$",
"this",
"->",
"get",
"(",
"'size'",
")",
",",
"50",
",",
"(",
"strlen",
"(",
"$",
"value",
")",
"!=",
"0",
"?",
"General",
"::",
"sanitizeDouble",
"(",
"$",
"value",
")",
":",
"null",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'formatter'",
")",
"!=",
"'none'",
")",
"{",
"$",
"textarea",
"->",
"setAttribute",
"(",
"'class'",
",",
"$",
"this",
"->",
"get",
"(",
"'formatter'",
")",
")",
";",
"}",
"/**\n * Allows developers modify the textarea before it is rendered in the publish forms\n *\n * @delegate ModifyTextareaFieldPublishWidget\n * @param string $context\n * '/backend/'\n * @param Field $field\n * @param Widget $label\n * @param Widget $textarea\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'ModifyTextareaFieldPublishWidget'",
",",
"'/backend/'",
",",
"array",
"(",
"'field'",
"=>",
"&",
"$",
"this",
",",
"'label'",
"=>",
"&",
"$",
"label",
",",
"'textarea'",
"=>",
"&",
"$",
"textarea",
")",
")",
";",
"$",
"label",
"->",
"appendChild",
"(",
"$",
"textarea",
")",
";",
"if",
"(",
"$",
"flagWithError",
"!=",
"null",
")",
"{",
"$",
"wrapper",
"->",
"appendChild",
"(",
"Widget",
"::",
"Error",
"(",
"$",
"label",
",",
"$",
"flagWithError",
")",
")",
";",
"}",
"else",
"{",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"label",
")",
";",
"}",
"}"
] | /*-------------------------------------------------------------------------
Publish:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Publish",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.textarea.php#L145-L183 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.textarea.php | fieldTextarea.prepareExportValue | public function prepareExportValue($data, $mode, $entry_id = null)
{
$modes = (object)$this->getExportModes();
// Export handles:
if ($mode === $modes->getHandle) {
if (isset($data['handle'])) {
return $data['handle'];
} elseif (isset($data['value'])) {
return Lang::createHandle($data['value']);
}
// Export unformatted:
} elseif ($mode === $modes->getUnformatted || $mode === $modes->getPostdata) {
return isset($data['value'])
? $data['value']
: null;
// Export formatted:
} elseif ($mode === $modes->getFormatted) {
if (isset($data['value_formatted'])) {
return $data['value_formatted'];
} elseif (isset($data['value'])) {
return General::sanitize($data['value']);
}
}
return null;
} | php | public function prepareExportValue($data, $mode, $entry_id = null)
{
$modes = (object)$this->getExportModes();
// Export handles:
if ($mode === $modes->getHandle) {
if (isset($data['handle'])) {
return $data['handle'];
} elseif (isset($data['value'])) {
return Lang::createHandle($data['value']);
}
// Export unformatted:
} elseif ($mode === $modes->getUnformatted || $mode === $modes->getPostdata) {
return isset($data['value'])
? $data['value']
: null;
// Export formatted:
} elseif ($mode === $modes->getFormatted) {
if (isset($data['value_formatted'])) {
return $data['value_formatted'];
} elseif (isset($data['value'])) {
return General::sanitize($data['value']);
}
}
return null;
} | [
"public",
"function",
"prepareExportValue",
"(",
"$",
"data",
",",
"$",
"mode",
",",
"$",
"entry_id",
"=",
"null",
")",
"{",
"$",
"modes",
"=",
"(",
"object",
")",
"$",
"this",
"->",
"getExportModes",
"(",
")",
";",
"// Export handles:",
"if",
"(",
"$",
"mode",
"===",
"$",
"modes",
"->",
"getHandle",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'handle'",
"]",
")",
")",
"{",
"return",
"$",
"data",
"[",
"'handle'",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
")",
"{",
"return",
"Lang",
"::",
"createHandle",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
";",
"}",
"// Export unformatted:",
"}",
"elseif",
"(",
"$",
"mode",
"===",
"$",
"modes",
"->",
"getUnformatted",
"||",
"$",
"mode",
"===",
"$",
"modes",
"->",
"getPostdata",
")",
"{",
"return",
"isset",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
"?",
"$",
"data",
"[",
"'value'",
"]",
":",
"null",
";",
"// Export formatted:",
"}",
"elseif",
"(",
"$",
"mode",
"===",
"$",
"modes",
"->",
"getFormatted",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'value_formatted'",
"]",
")",
")",
"{",
"return",
"$",
"data",
"[",
"'value_formatted'",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
")",
"{",
"return",
"General",
"::",
"sanitize",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Give the field some data and ask it to return a value using one of many
possible modes.
@param mixed $data
@param integer $mode
@param integer $entry_id
@return string|null | [
"Give",
"the",
"field",
"some",
"data",
"and",
"ask",
"it",
"to",
"return",
"a",
"value",
"using",
"one",
"of",
"many",
"possible",
"modes",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.textarea.php#L329-L357 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.textarea.php | fieldTextarea.buildDSRetrievalSQL | public function buildDSRetrievalSQL($data, &$joins, &$where, $andOperation = false)
{
$field_id = $this->get('id');
if (self::isFilterRegex($data[0])) {
$this->buildRegexSQL($data[0], array('value'), $joins, $where);
} elseif (self::isFilterSQL($data[0])) {
$this->buildFilterSQL($data[0], array('value'), $joins, $where);
} else {
if (is_array($data)) {
$data = $data[0];
}
$this->_key++;
$data = $this->cleanValue($data);
$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 MATCH (t{$field_id}_{$this->_key}.value) AGAINST ('{$data}' IN BOOLEAN MODE)
";
}
return true;
} | php | public function buildDSRetrievalSQL($data, &$joins, &$where, $andOperation = false)
{
$field_id = $this->get('id');
if (self::isFilterRegex($data[0])) {
$this->buildRegexSQL($data[0], array('value'), $joins, $where);
} elseif (self::isFilterSQL($data[0])) {
$this->buildFilterSQL($data[0], array('value'), $joins, $where);
} else {
if (is_array($data)) {
$data = $data[0];
}
$this->_key++;
$data = $this->cleanValue($data);
$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 MATCH (t{$field_id}_{$this->_key}.value) AGAINST ('{$data}' IN BOOLEAN MODE)
";
}
return true;
} | [
"public",
"function",
"buildDSRetrievalSQL",
"(",
"$",
"data",
",",
"&",
"$",
"joins",
",",
"&",
"$",
"where",
",",
"$",
"andOperation",
"=",
"false",
")",
"{",
"$",
"field_id",
"=",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
";",
"if",
"(",
"self",
"::",
"isFilterRegex",
"(",
"$",
"data",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"buildRegexSQL",
"(",
"$",
"data",
"[",
"0",
"]",
",",
"array",
"(",
"'value'",
")",
",",
"$",
"joins",
",",
"$",
"where",
")",
";",
"}",
"elseif",
"(",
"self",
"::",
"isFilterSQL",
"(",
"$",
"data",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"buildFilterSQL",
"(",
"$",
"data",
"[",
"0",
"]",
",",
"array",
"(",
"'value'",
")",
",",
"$",
"joins",
",",
"$",
"where",
")",
";",
"}",
"else",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"$",
"data",
"[",
"0",
"]",
";",
"}",
"$",
"this",
"->",
"_key",
"++",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"cleanValue",
"(",
"$",
"data",
")",
";",
"$",
"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",
".=",
"\"\n AND MATCH (t{$field_id}_{$this->_key}.value) AGAINST ('{$data}' IN BOOLEAN MODE)\n \"",
";",
"}",
"return",
"true",
";",
"}"
] | /*-------------------------------------------------------------------------
Filtering:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Filtering",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.textarea.php#L363-L389 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.textarea.php | fieldTextarea.getExampleFormMarkup | public function getExampleFormMarkup()
{
$label = Widget::Label($this->get('label'));
$label->appendChild(Widget::Textarea('fields['.$this->get('element_name').']', (int)$this->get('size'), 50));
return $label;
} | php | public function getExampleFormMarkup()
{
$label = Widget::Label($this->get('label'));
$label->appendChild(Widget::Textarea('fields['.$this->get('element_name').']', (int)$this->get('size'), 50));
return $label;
} | [
"public",
"function",
"getExampleFormMarkup",
"(",
")",
"{",
"$",
"label",
"=",
"Widget",
"::",
"Label",
"(",
"$",
"this",
"->",
"get",
"(",
"'label'",
")",
")",
";",
"$",
"label",
"->",
"appendChild",
"(",
"Widget",
"::",
"Textarea",
"(",
"'fields['",
".",
"$",
"this",
"->",
"get",
"(",
"'element_name'",
")",
".",
"']'",
",",
"(",
"int",
")",
"$",
"this",
"->",
"get",
"(",
"'size'",
")",
",",
"50",
")",
")",
";",
"return",
"$",
"label",
";",
"}"
] | /*-------------------------------------------------------------------------
Events:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Events",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.textarea.php#L395-L401 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.validateString | public static function validateString($string, $rule)
{
if (!is_array($rule) && ($rule == '' || $rule == null)) {
return true;
}
if (!is_array($string) && ($string == '' || $rule == null)) {
return true;
}
if (!is_array($rule)) {
$rule = array($rule);
}
if (!is_array($string)) {
$string = array($string);
}
foreach ($rule as $r) {
foreach ($string as $s) {
if (!preg_match($r, $s)) {
return false;
}
}
}
return true;
} | php | public static function validateString($string, $rule)
{
if (!is_array($rule) && ($rule == '' || $rule == null)) {
return true;
}
if (!is_array($string) && ($string == '' || $rule == null)) {
return true;
}
if (!is_array($rule)) {
$rule = array($rule);
}
if (!is_array($string)) {
$string = array($string);
}
foreach ($rule as $r) {
foreach ($string as $s) {
if (!preg_match($r, $s)) {
return false;
}
}
}
return true;
} | [
"public",
"static",
"function",
"validateString",
"(",
"$",
"string",
",",
"$",
"rule",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"rule",
")",
"&&",
"(",
"$",
"rule",
"==",
"''",
"||",
"$",
"rule",
"==",
"null",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"string",
")",
"&&",
"(",
"$",
"string",
"==",
"''",
"||",
"$",
"rule",
"==",
"null",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"rule",
")",
")",
"{",
"$",
"rule",
"=",
"array",
"(",
"$",
"rule",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"string",
")",
")",
"{",
"$",
"string",
"=",
"array",
"(",
"$",
"string",
")",
";",
"}",
"foreach",
"(",
"$",
"rule",
"as",
"$",
"r",
")",
"{",
"foreach",
"(",
"$",
"string",
"as",
"$",
"s",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"r",
",",
"$",
"s",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | Validate a string against a set of regular expressions.
@param array|string $string
string to operate on
@param array|string $rule
a single rule or array of rules
@return boolean
false if any of the rules in $rule do not match any of the strings in
`$string`, return true otherwise. | [
"Validate",
"a",
"string",
"against",
"a",
"set",
"of",
"regular",
"expressions",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L72-L98 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.validateXML | public static function validateXML($data, &$errors, $isFile = true, $xsltProcessor = null, $encoding = 'UTF-8')
{
$_data = ($isFile) ? file_get_contents($data) : $data;
$_data = preg_replace('/<!DOCTYPE[-.:"\'\/\\w\\s]+>/', null, $_data);
if (strpos($_data, '<?xml') === false) {
$_data = '<?xml version="1.0" encoding="'.$encoding.'"?><rootelement>'.$_data.'</rootelement>';
}
if (is_object($xsltProcessor)) {
$xsl = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/"></xsl:template>
</xsl:stylesheet>';
$xsltProcessor->process($_data, $xsl, array());
if ($xsltProcessor->isErrors()) {
$errors = $xsltProcessor->getError(true);
return false;
}
} else {
$_parser = xml_parser_create();
xml_parser_set_option($_parser, XML_OPTION_SKIP_WHITE, 0);
xml_parser_set_option($_parser, XML_OPTION_CASE_FOLDING, 0);
if (!xml_parse($_parser, $_data)) {
$errors = array('error' => xml_get_error_code($_parser) . ': ' . xml_error_string(xml_get_error_code($_parser)),
'col' => xml_get_current_column_number($_parser),
'line' => (xml_get_current_line_number($_parser) - 2));
return false;
}
xml_parser_free($_parser);
}
return true;
} | php | public static function validateXML($data, &$errors, $isFile = true, $xsltProcessor = null, $encoding = 'UTF-8')
{
$_data = ($isFile) ? file_get_contents($data) : $data;
$_data = preg_replace('/<!DOCTYPE[-.:"\'\/\\w\\s]+>/', null, $_data);
if (strpos($_data, '<?xml') === false) {
$_data = '<?xml version="1.0" encoding="'.$encoding.'"?><rootelement>'.$_data.'</rootelement>';
}
if (is_object($xsltProcessor)) {
$xsl = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/"></xsl:template>
</xsl:stylesheet>';
$xsltProcessor->process($_data, $xsl, array());
if ($xsltProcessor->isErrors()) {
$errors = $xsltProcessor->getError(true);
return false;
}
} else {
$_parser = xml_parser_create();
xml_parser_set_option($_parser, XML_OPTION_SKIP_WHITE, 0);
xml_parser_set_option($_parser, XML_OPTION_CASE_FOLDING, 0);
if (!xml_parse($_parser, $_data)) {
$errors = array('error' => xml_get_error_code($_parser) . ': ' . xml_error_string(xml_get_error_code($_parser)),
'col' => xml_get_current_column_number($_parser),
'line' => (xml_get_current_line_number($_parser) - 2));
return false;
}
xml_parser_free($_parser);
}
return true;
} | [
"public",
"static",
"function",
"validateXML",
"(",
"$",
"data",
",",
"&",
"$",
"errors",
",",
"$",
"isFile",
"=",
"true",
",",
"$",
"xsltProcessor",
"=",
"null",
",",
"$",
"encoding",
"=",
"'UTF-8'",
")",
"{",
"$",
"_data",
"=",
"(",
"$",
"isFile",
")",
"?",
"file_get_contents",
"(",
"$",
"data",
")",
":",
"$",
"data",
";",
"$",
"_data",
"=",
"preg_replace",
"(",
"'/<!DOCTYPE[-.:\"\\'\\/\\\\w\\\\s]+>/'",
",",
"null",
",",
"$",
"_data",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"_data",
",",
"'<?xml'",
")",
"===",
"false",
")",
"{",
"$",
"_data",
"=",
"'<?xml version=\"1.0\" encoding=\"'",
".",
"$",
"encoding",
".",
"'\"?><rootelement>'",
".",
"$",
"_data",
".",
"'</rootelement>'",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"xsltProcessor",
")",
")",
"{",
"$",
"xsl",
"=",
"'<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n\n <xsl:template match=\"/\"></xsl:template>\n\n </xsl:stylesheet>'",
";",
"$",
"xsltProcessor",
"->",
"process",
"(",
"$",
"_data",
",",
"$",
"xsl",
",",
"array",
"(",
")",
")",
";",
"if",
"(",
"$",
"xsltProcessor",
"->",
"isErrors",
"(",
")",
")",
"{",
"$",
"errors",
"=",
"$",
"xsltProcessor",
"->",
"getError",
"(",
"true",
")",
";",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"$",
"_parser",
"=",
"xml_parser_create",
"(",
")",
";",
"xml_parser_set_option",
"(",
"$",
"_parser",
",",
"XML_OPTION_SKIP_WHITE",
",",
"0",
")",
";",
"xml_parser_set_option",
"(",
"$",
"_parser",
",",
"XML_OPTION_CASE_FOLDING",
",",
"0",
")",
";",
"if",
"(",
"!",
"xml_parse",
"(",
"$",
"_parser",
",",
"$",
"_data",
")",
")",
"{",
"$",
"errors",
"=",
"array",
"(",
"'error'",
"=>",
"xml_get_error_code",
"(",
"$",
"_parser",
")",
".",
"': '",
".",
"xml_error_string",
"(",
"xml_get_error_code",
"(",
"$",
"_parser",
")",
")",
",",
"'col'",
"=>",
"xml_get_current_column_number",
"(",
"$",
"_parser",
")",
",",
"'line'",
"=>",
"(",
"xml_get_current_line_number",
"(",
"$",
"_parser",
")",
"-",
"2",
")",
")",
";",
"return",
"false",
";",
"}",
"xml_parser_free",
"(",
"$",
"_parser",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Checks an xml document for well-formedness.
@param string $data
filename, xml document as a string, or arbitrary string
@param pointer &$errors
pointer to an array which will contain any validation errors
@param boolean $isFile (optional)
if this is true, the method will attempt to read from a file, `$data`
instead.
@param XsltProcess $xsltProcessor (optional)
if set, the validation will be done using this XSLT processor rather
than the built in XML parser. the default is null.
@param string $encoding (optional)
if no XML header is expected, than this should be set to match the
encoding of the XML
@return boolean
true if there are no errors in validating the XML, false otherwise. | [
"Checks",
"an",
"xml",
"document",
"for",
"well",
"-",
"formedness",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L135-L173 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.validateURL | public static function validateURL($url = null)
{
$url = trim($url);
if (is_null($url) || $url == '') {
return $url;
}
if (!preg_match('#^http[s]?:\/\/#i', $url)) {
$url = 'http://' . $url;
}
include TOOLKIT . '/util.validators.php';
if (!preg_match($validators['URI'], $url)) {
$url = '';
}
return $url;
} | php | public static function validateURL($url = null)
{
$url = trim($url);
if (is_null($url) || $url == '') {
return $url;
}
if (!preg_match('#^http[s]?:\/\/#i', $url)) {
$url = 'http://' . $url;
}
include TOOLKIT . '/util.validators.php';
if (!preg_match($validators['URI'], $url)) {
$url = '';
}
return $url;
} | [
"public",
"static",
"function",
"validateURL",
"(",
"$",
"url",
"=",
"null",
")",
"{",
"$",
"url",
"=",
"trim",
"(",
"$",
"url",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"url",
")",
"||",
"$",
"url",
"==",
"''",
")",
"{",
"return",
"$",
"url",
";",
"}",
"if",
"(",
"!",
"preg_match",
"(",
"'#^http[s]?:\\/\\/#i'",
",",
"$",
"url",
")",
")",
"{",
"$",
"url",
"=",
"'http://'",
".",
"$",
"url",
";",
"}",
"include",
"TOOLKIT",
".",
"'/util.validators.php'",
";",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"validators",
"[",
"'URI'",
"]",
",",
"$",
"url",
")",
")",
"{",
"$",
"url",
"=",
"''",
";",
"}",
"return",
"$",
"url",
";",
"}"
] | Check that a string is a valid URL.
@param string $url
string to operate on
@return string
a blank string or a valid URL | [
"Check",
"that",
"a",
"string",
"is",
"a",
"valid",
"URL",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L183-L202 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.cleanArray | public static function cleanArray(array &$arr)
{
foreach ($arr as $k => $v) {
if (is_array($v)) {
self::cleanArray($arr[$k]);
} else {
$arr[$k] = stripslashes($v);
}
}
} | php | public static function cleanArray(array &$arr)
{
foreach ($arr as $k => $v) {
if (is_array($v)) {
self::cleanArray($arr[$k]);
} else {
$arr[$k] = stripslashes($v);
}
}
} | [
"public",
"static",
"function",
"cleanArray",
"(",
"array",
"&",
"$",
"arr",
")",
"{",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"v",
")",
")",
"{",
"self",
"::",
"cleanArray",
"(",
"$",
"arr",
"[",
"$",
"k",
"]",
")",
";",
"}",
"else",
"{",
"$",
"arr",
"[",
"$",
"k",
"]",
"=",
"stripslashes",
"(",
"$",
"v",
")",
";",
"}",
"}",
"}"
] | Strip any slashes from all array values.
@param array &$arr
Pointer to an array to operate on. Can be multi-dimensional. | [
"Strip",
"any",
"slashes",
"from",
"all",
"array",
"values",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L210-L219 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.flattenArray | public static function flattenArray(array &$source, &$output = null, $path = null)
{
if (is_null($output)) {
$output = array();
}
foreach ($source as $key => $value) {
if (is_int($key)) {
$key = (string)($key + 1);
}
if (!is_null($path)) {
$key = $path . '.' . (string)$key;
}
if (is_array($value)) {
self::flattenArray($value, $output, $key);
} else {
$output[$key] = $value;
}
}
$source = $output;
} | php | public static function flattenArray(array &$source, &$output = null, $path = null)
{
if (is_null($output)) {
$output = array();
}
foreach ($source as $key => $value) {
if (is_int($key)) {
$key = (string)($key + 1);
}
if (!is_null($path)) {
$key = $path . '.' . (string)$key;
}
if (is_array($value)) {
self::flattenArray($value, $output, $key);
} else {
$output[$key] = $value;
}
}
$source = $output;
} | [
"public",
"static",
"function",
"flattenArray",
"(",
"array",
"&",
"$",
"source",
",",
"&",
"$",
"output",
"=",
"null",
",",
"$",
"path",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"output",
")",
")",
"{",
"$",
"output",
"=",
"array",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"source",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"$",
"key",
"=",
"(",
"string",
")",
"(",
"$",
"key",
"+",
"1",
")",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"path",
")",
")",
"{",
"$",
"key",
"=",
"$",
"path",
".",
"'.'",
".",
"(",
"string",
")",
"$",
"key",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"self",
"::",
"flattenArray",
"(",
"$",
"value",
",",
"$",
"output",
",",
"$",
"key",
")",
";",
"}",
"else",
"{",
"$",
"output",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"$",
"source",
"=",
"$",
"output",
";",
"}"
] | Flatten the input array. Any elements of the input array that are
themselves arrays will be removed and the contents of the removed array
inserted in its place. The keys for the inserted values will be the
concatenation of the keys in the original arrays in which it was embedded.
The elements of the path are separated by periods (.). For example,
given the following nested array structure:
`
array(1 =>
array('key' => 'value'),
2 =>
array('key2' => 'value2', 'key3' => 'value3')
)
`
will flatten to:
`array('1.key' => 'value', '2.key2' => 'value2', '2.key3' => 'value3')`
@param array &$source
The array to flatten, passed by reference
@param array &$output (optional)
The array in which to store the flattened input, passed by reference.
if this is not provided then a new array will be created.
@param string $path (optional)
the current prefix of the keys to insert into the output array. this
defaults to null. | [
"Flatten",
"the",
"input",
"array",
".",
"Any",
"elements",
"of",
"the",
"input",
"array",
"that",
"are",
"themselves",
"arrays",
"will",
"be",
"removed",
"and",
"the",
"contents",
"of",
"the",
"removed",
"array",
"inserted",
"in",
"its",
"place",
".",
"The",
"keys",
"for",
"the",
"inserted",
"values",
"will",
"be",
"the",
"concatenation",
"of",
"the",
"keys",
"in",
"the",
"original",
"arrays",
"in",
"which",
"it",
"was",
"embedded",
".",
"The",
"elements",
"of",
"the",
"path",
"are",
"separated",
"by",
"periods",
"(",
".",
")",
".",
"For",
"example",
"given",
"the",
"following",
"nested",
"array",
"structure",
":",
"array",
"(",
"1",
"=",
">",
"array",
"(",
"key",
"=",
">",
"value",
")",
"2",
"=",
">",
"array",
"(",
"key2",
"=",
">",
"value2",
"key3",
"=",
">",
"value3",
")",
")",
"will",
"flatten",
"to",
":",
"array",
"(",
"1",
".",
"key",
"=",
">",
"value",
"2",
".",
"key2",
"=",
">",
"value2",
"2",
".",
"key3",
"=",
">",
"value3",
")"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L247-L270 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.flattenArraySub | protected static function flattenArraySub(array &$output, array &$source, $path)
{
foreach ($source as $key => $value) {
$key = $path . ':' . $key;
if (is_array($value)) {
self::flattenArraySub($output, $value, $key);
} else {
$output[$key] = $value;
}
}
} | php | protected static function flattenArraySub(array &$output, array &$source, $path)
{
foreach ($source as $key => $value) {
$key = $path . ':' . $key;
if (is_array($value)) {
self::flattenArraySub($output, $value, $key);
} else {
$output[$key] = $value;
}
}
} | [
"protected",
"static",
"function",
"flattenArraySub",
"(",
"array",
"&",
"$",
"output",
",",
"array",
"&",
"$",
"source",
",",
"$",
"path",
")",
"{",
"foreach",
"(",
"$",
"source",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"key",
"=",
"$",
"path",
".",
"':'",
".",
"$",
"key",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"self",
"::",
"flattenArraySub",
"(",
"$",
"output",
",",
"$",
"value",
",",
"$",
"key",
")",
";",
"}",
"else",
"{",
"$",
"output",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}"
] | Flatten the input array. Any elements of the input array that are
themselves arrays will be removed and the contents of the removed array
inserted in its place. The keys for the inserted values will be the
concatenation of the keys in the original arrays in which it was embedded.
The elements of the path are separated by colons (:). For example, given
the following nested array structure:
`
array(1 =>
array('key' => 'value'),
2 =>
array('key2' => 'value2', 'key3' => 'value3')
)
`
will flatten to:
`array('1:key' => 'value', '2:key2' => 'value2', '2:key3' => 'value3')`
@param array &$output
The array in which to store the flattened input, passed by reference.
@param array &$source
The array to flatten, passed by reference
@param string $path
the current prefix of the keys to insert into the output array. | [
"Flatten",
"the",
"input",
"array",
".",
"Any",
"elements",
"of",
"the",
"input",
"array",
"that",
"are",
"themselves",
"arrays",
"will",
"be",
"removed",
"and",
"the",
"contents",
"of",
"the",
"removed",
"array",
"inserted",
"in",
"its",
"place",
".",
"The",
"keys",
"for",
"the",
"inserted",
"values",
"will",
"be",
"the",
"concatenation",
"of",
"the",
"keys",
"in",
"the",
"original",
"arrays",
"in",
"which",
"it",
"was",
"embedded",
".",
"The",
"elements",
"of",
"the",
"path",
"are",
"separated",
"by",
"colons",
"(",
":",
")",
".",
"For",
"example",
"given",
"the",
"following",
"nested",
"array",
"structure",
":",
"array",
"(",
"1",
"=",
">",
"array",
"(",
"key",
"=",
">",
"value",
")",
"2",
"=",
">",
"array",
"(",
"key2",
"=",
">",
"value2",
"key3",
"=",
">",
"value3",
")",
")",
"will",
"flatten",
"to",
":",
"array",
"(",
"1",
":",
"key",
"=",
">",
"value",
"2",
":",
"key2",
"=",
">",
"value2",
"2",
":",
"key3",
"=",
">",
"value3",
")"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L297-L308 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.createHandle | public static function createHandle($string, $max_length = 255, $delim = '-', $uriencode = false, $additional_rule_set = null)
{
$max_length = intval($max_length);
// Strip out any tag
$string = strip_tags($string);
// Remove punctuation
$string = preg_replace('/[\\.\'"]+/', null, $string);
// Trim it
if ($max_length > 0) {
$string = General::limitWords($string, $max_length);
}
// Replace spaces (tab, newline etc) with the delimiter
$string = preg_replace('/[\s]+/', $delim, $string);
// Find all legal characters
preg_match_all('/[^<>?@:!\-\/\[-`;‘’…]+/u', $string, $matches);
// Join only legal character with the $delim
$string = implode($delim, $matches[0]);
// Allow for custom rules
if (is_array($additional_rule_set) && !empty($additional_rule_set)) {
foreach ($additional_rule_set as $rule => $replacement) {
$string = preg_replace($rule, $replacement, $string);
}
}
// Remove leading or trailing delim characters
$string = trim($string, $delim);
// Encode it for URI use
if ($uriencode) {
$string = urlencode($string);
}
// Make it lowercase
$string = strtolower($string);
return $string;
} | php | public static function createHandle($string, $max_length = 255, $delim = '-', $uriencode = false, $additional_rule_set = null)
{
$max_length = intval($max_length);
// Strip out any tag
$string = strip_tags($string);
// Remove punctuation
$string = preg_replace('/[\\.\'"]+/', null, $string);
// Trim it
if ($max_length > 0) {
$string = General::limitWords($string, $max_length);
}
// Replace spaces (tab, newline etc) with the delimiter
$string = preg_replace('/[\s]+/', $delim, $string);
// Find all legal characters
preg_match_all('/[^<>?@:!\-\/\[-`;‘’…]+/u', $string, $matches);
// Join only legal character with the $delim
$string = implode($delim, $matches[0]);
// Allow for custom rules
if (is_array($additional_rule_set) && !empty($additional_rule_set)) {
foreach ($additional_rule_set as $rule => $replacement) {
$string = preg_replace($rule, $replacement, $string);
}
}
// Remove leading or trailing delim characters
$string = trim($string, $delim);
// Encode it for URI use
if ($uriencode) {
$string = urlencode($string);
}
// Make it lowercase
$string = strtolower($string);
return $string;
} | [
"public",
"static",
"function",
"createHandle",
"(",
"$",
"string",
",",
"$",
"max_length",
"=",
"255",
",",
"$",
"delim",
"=",
"'-'",
",",
"$",
"uriencode",
"=",
"false",
",",
"$",
"additional_rule_set",
"=",
"null",
")",
"{",
"$",
"max_length",
"=",
"intval",
"(",
"$",
"max_length",
")",
";",
"// Strip out any tag",
"$",
"string",
"=",
"strip_tags",
"(",
"$",
"string",
")",
";",
"// Remove punctuation",
"$",
"string",
"=",
"preg_replace",
"(",
"'/[\\\\.\\'\"]+/'",
",",
"null",
",",
"$",
"string",
")",
";",
"// Trim it",
"if",
"(",
"$",
"max_length",
">",
"0",
")",
"{",
"$",
"string",
"=",
"General",
"::",
"limitWords",
"(",
"$",
"string",
",",
"$",
"max_length",
")",
";",
"}",
"// Replace spaces (tab, newline etc) with the delimiter",
"$",
"string",
"=",
"preg_replace",
"(",
"'/[\\s]+/'",
",",
"$",
"delim",
",",
"$",
"string",
")",
";",
"// Find all legal characters",
"preg_match_all",
"(",
"'/[^<>?@:!\\-\\/\\[-`;‘’…]+/u', $str",
"i",
"g",
", $mat",
"c",
"e",
"s);",
"",
"",
"// Join only legal character with the $delim",
"$",
"string",
"=",
"implode",
"(",
"$",
"delim",
",",
"$",
"matches",
"[",
"0",
"]",
")",
";",
"// Allow for custom rules",
"if",
"(",
"is_array",
"(",
"$",
"additional_rule_set",
")",
"&&",
"!",
"empty",
"(",
"$",
"additional_rule_set",
")",
")",
"{",
"foreach",
"(",
"$",
"additional_rule_set",
"as",
"$",
"rule",
"=>",
"$",
"replacement",
")",
"{",
"$",
"string",
"=",
"preg_replace",
"(",
"$",
"rule",
",",
"$",
"replacement",
",",
"$",
"string",
")",
";",
"}",
"}",
"// Remove leading or trailing delim characters",
"$",
"string",
"=",
"trim",
"(",
"$",
"string",
",",
"$",
"delim",
")",
";",
"// Encode it for URI use",
"if",
"(",
"$",
"uriencode",
")",
"{",
"$",
"string",
"=",
"urlencode",
"(",
"$",
"string",
")",
";",
"}",
"// Make it lowercase",
"$",
"string",
"=",
"strtolower",
"(",
"$",
"string",
")",
";",
"return",
"$",
"string",
";",
"}"
] | Given a string, this will clean it for use as a Symphony handle. Preserves multi-byte characters.
@since Symphony 2.2.1
@param string $string
String to be cleaned up
@param integer $max_length
The maximum number of characters in the handle
@param string $delim
All non-valid characters will be replaced with this
@param boolean $uriencode
Force the resultant string to be uri encoded making it safe for URLs
@param array $additional_rule_set
An array of REGEX patterns that should be applied to the `$string`. This
occurs after the string has been trimmed and joined with the `$delim`
@return string
Returns resultant handle | [
"Given",
"a",
"string",
"this",
"will",
"clean",
"it",
"for",
"use",
"as",
"a",
"Symphony",
"handle",
".",
"Preserves",
"multi",
"-",
"byte",
"characters",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L328-L371 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.createFilename | public static function createFilename($string, $delim = '-')
{
// Strip out any tag
$string = strip_tags($string);
// Find all legal characters
$count = preg_match_all('/[\p{L}\w:;.,+=~]+/u', $string, $matches);
if ($count <= 0 || $count == false) {
preg_match_all('/[\w:;.,+=~]+/', $string, $matches);
}
// Join only legal character with the $delim
$string = implode($delim, $matches[0]);
// Remove leading or trailing delim characters
$string = trim($string, $delim);
// Make it lowercase
$string = strtolower($string);
return $string;
} | php | public static function createFilename($string, $delim = '-')
{
// Strip out any tag
$string = strip_tags($string);
// Find all legal characters
$count = preg_match_all('/[\p{L}\w:;.,+=~]+/u', $string, $matches);
if ($count <= 0 || $count == false) {
preg_match_all('/[\w:;.,+=~]+/', $string, $matches);
}
// Join only legal character with the $delim
$string = implode($delim, $matches[0]);
// Remove leading or trailing delim characters
$string = trim($string, $delim);
// Make it lowercase
$string = strtolower($string);
return $string;
} | [
"public",
"static",
"function",
"createFilename",
"(",
"$",
"string",
",",
"$",
"delim",
"=",
"'-'",
")",
"{",
"// Strip out any tag",
"$",
"string",
"=",
"strip_tags",
"(",
"$",
"string",
")",
";",
"// Find all legal characters",
"$",
"count",
"=",
"preg_match_all",
"(",
"'/[\\p{L}\\w:;.,+=~]+/u'",
",",
"$",
"string",
",",
"$",
"matches",
")",
";",
"if",
"(",
"$",
"count",
"<=",
"0",
"||",
"$",
"count",
"==",
"false",
")",
"{",
"preg_match_all",
"(",
"'/[\\w:;.,+=~]+/'",
",",
"$",
"string",
",",
"$",
"matches",
")",
";",
"}",
"// Join only legal character with the $delim",
"$",
"string",
"=",
"implode",
"(",
"$",
"delim",
",",
"$",
"matches",
"[",
"0",
"]",
")",
";",
"// Remove leading or trailing delim characters",
"$",
"string",
"=",
"trim",
"(",
"$",
"string",
",",
"$",
"delim",
")",
";",
"// Make it lowercase",
"$",
"string",
"=",
"strtolower",
"(",
"$",
"string",
")",
";",
"return",
"$",
"string",
";",
"}"
] | Given a string, this will clean it for use as a filename. Preserves multi-byte characters.
@since Symphony 2.2.1
@param string $string
String to be cleaned up
@param string $delim
All non-valid characters will be replaced with this
@return string
Returns created filename | [
"Given",
"a",
"string",
"this",
"will",
"clean",
"it",
"for",
"use",
"as",
"a",
"filename",
".",
"Preserves",
"multi",
"-",
"byte",
"characters",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L384-L405 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.strpos | public static function strpos($haystack, $needle, $offset = 0)
{
if (function_exists('mb_strpos')) {
return mb_strpos($haystack, $needle, $offset, 'utf-8');
}
return strpos($haystack, $needle, $offset);
} | php | public static function strpos($haystack, $needle, $offset = 0)
{
if (function_exists('mb_strpos')) {
return mb_strpos($haystack, $needle, $offset, 'utf-8');
}
return strpos($haystack, $needle, $offset);
} | [
"public",
"static",
"function",
"strpos",
"(",
"$",
"haystack",
",",
"$",
"needle",
",",
"$",
"offset",
"=",
"0",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'mb_strpos'",
")",
")",
"{",
"return",
"mb_strpos",
"(",
"$",
"haystack",
",",
"$",
"needle",
",",
"$",
"offset",
",",
"'utf-8'",
")",
";",
"}",
"return",
"strpos",
"(",
"$",
"haystack",
",",
"$",
"needle",
",",
"$",
"offset",
")",
";",
"}"
] | Finds position of the first occurrence of a string in a string.
This function will attempt to use PHP's `mbstring` functions if they are available.
This function also forces utf-8 encoding for mbstring.
@since Symphony 2.7.0
@param string $haystack
the string to look into
@param string $needle
the string to look for
@param int $offset
the search offset. If it is not specified, 0 is used.
A negative offset counts from the end of the string.
@return int
the numeric position of the first occurrence of needle in the haystack | [
"Finds",
"position",
"of",
"the",
"first",
"occurrence",
"of",
"a",
"string",
"in",
"a",
"string",
".",
"This",
"function",
"will",
"attempt",
"to",
"use",
"PHP",
"s",
"mbstring",
"functions",
"if",
"they",
"are",
"available",
".",
"This",
"function",
"also",
"forces",
"utf",
"-",
"8",
"encoding",
"for",
"mbstring",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L442-L448 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.substr | public static function substr($str, $start, $length = null)
{
if (function_exists('mb_substr')) {
return mb_substr($str, $start, $length, 'utf-8');
}
if ($length === null) {
return substr($str, $start);
}
return substr($str, $start, $length);
} | php | public static function substr($str, $start, $length = null)
{
if (function_exists('mb_substr')) {
return mb_substr($str, $start, $length, 'utf-8');
}
if ($length === null) {
return substr($str, $start);
}
return substr($str, $start, $length);
} | [
"public",
"static",
"function",
"substr",
"(",
"$",
"str",
",",
"$",
"start",
",",
"$",
"length",
"=",
"null",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'mb_substr'",
")",
")",
"{",
"return",
"mb_substr",
"(",
"$",
"str",
",",
"$",
"start",
",",
"$",
"length",
",",
"'utf-8'",
")",
";",
"}",
"if",
"(",
"$",
"length",
"===",
"null",
")",
"{",
"return",
"substr",
"(",
"$",
"str",
",",
"$",
"start",
")",
";",
"}",
"return",
"substr",
"(",
"$",
"str",
",",
"$",
"start",
",",
"$",
"length",
")",
";",
"}"
] | Creates a sub string.
This function will attempt to use PHP's `mbstring` functions if they are available.
This function also forces utf-8 encoding.
@since Symphony 2.5.0
@param string $str
the string to operate on
@param int $start
the starting offset
@param int $length
the length of the substring
@return string
the resulting substring | [
"Creates",
"a",
"sub",
"string",
".",
"This",
"function",
"will",
"attempt",
"to",
"use",
"PHP",
"s",
"mbstring",
"functions",
"if",
"they",
"are",
"available",
".",
"This",
"function",
"also",
"forces",
"utf",
"-",
"8",
"encoding",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L465-L474 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.substrmin | public static function substrmin($str, $val)
{
return self::substr($str, 0, min(self::strlen($str), $val));
} | php | public static function substrmin($str, $val)
{
return self::substr($str, 0, min(self::strlen($str), $val));
} | [
"public",
"static",
"function",
"substrmin",
"(",
"$",
"str",
",",
"$",
"val",
")",
"{",
"return",
"self",
"::",
"substr",
"(",
"$",
"str",
",",
"0",
",",
"min",
"(",
"self",
"::",
"strlen",
"(",
"$",
"str",
")",
",",
"$",
"val",
")",
")",
";",
"}"
] | Extract the first `$val` characters of the input string. If `$val`
is larger than the length of the input string then the original
input string is returned.
@param string $str
the string to operate on
@param integer $val
the number to compare lengths with
@return string|boolean
the resulting string or false on failure. | [
"Extract",
"the",
"first",
"$val",
"characters",
"of",
"the",
"input",
"string",
".",
"If",
"$val",
"is",
"larger",
"than",
"the",
"length",
"of",
"the",
"input",
"string",
"then",
"the",
"original",
"input",
"string",
"is",
"returned",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L488-L491 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.substrmax | public static function substrmax($str, $val)
{
return self::substr($str, 0, max(self::strlen($str), $val));
} | php | public static function substrmax($str, $val)
{
return self::substr($str, 0, max(self::strlen($str), $val));
} | [
"public",
"static",
"function",
"substrmax",
"(",
"$",
"str",
",",
"$",
"val",
")",
"{",
"return",
"self",
"::",
"substr",
"(",
"$",
"str",
",",
"0",
",",
"max",
"(",
"self",
"::",
"strlen",
"(",
"$",
"str",
")",
",",
"$",
"val",
")",
")",
";",
"}"
] | Extract the first `$val` characters of the input string. If
`$val` is larger than the length of the input string then
the original input string is returned
@param string $str
the string to operate on
@param integer $val
the number to compare lengths with
@return string|boolean
the resulting string or false on failure. | [
"Extract",
"the",
"first",
"$val",
"characters",
"of",
"the",
"input",
"string",
".",
"If",
"$val",
"is",
"larger",
"than",
"the",
"length",
"of",
"the",
"input",
"string",
"then",
"the",
"original",
"input",
"string",
"is",
"returned"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L505-L508 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.right | public static function right($str, $num)
{
$str = self::substr($str, self::strlen($str)-$num, $num);
return $str;
} | php | public static function right($str, $num)
{
$str = self::substr($str, self::strlen($str)-$num, $num);
return $str;
} | [
"public",
"static",
"function",
"right",
"(",
"$",
"str",
",",
"$",
"num",
")",
"{",
"$",
"str",
"=",
"self",
"::",
"substr",
"(",
"$",
"str",
",",
"self",
"::",
"strlen",
"(",
"$",
"str",
")",
"-",
"$",
"num",
",",
"$",
"num",
")",
";",
"return",
"$",
"str",
";",
"}"
] | Extract the last `$num` characters from a string.
@param string $str
the string to extract the characters from.
@param integer $num
the number of characters to extract.
@return string|boolean
a string containing the last `$num` characters of the
input string, or false on failure. | [
"Extract",
"the",
"last",
"$num",
"characters",
"from",
"a",
"string",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L521-L525 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.realiseDirectory | public static function realiseDirectory($path, $mode = 0755, $silent = true)
{
if (is_dir($path)) {
return true;
}
try {
$current_umask = umask(0);
$success = @mkdir($path, intval($mode, 8), true);
umask($current_umask);
return $success;
} catch (Exception $ex) {
if ($silent === false) {
throw new Exception(__('Unable to create path - %s', array($path)));
}
return false;
}
} | php | public static function realiseDirectory($path, $mode = 0755, $silent = true)
{
if (is_dir($path)) {
return true;
}
try {
$current_umask = umask(0);
$success = @mkdir($path, intval($mode, 8), true);
umask($current_umask);
return $success;
} catch (Exception $ex) {
if ($silent === false) {
throw new Exception(__('Unable to create path - %s', array($path)));
}
return false;
}
} | [
"public",
"static",
"function",
"realiseDirectory",
"(",
"$",
"path",
",",
"$",
"mode",
"=",
"0755",
",",
"$",
"silent",
"=",
"true",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"return",
"true",
";",
"}",
"try",
"{",
"$",
"current_umask",
"=",
"umask",
"(",
"0",
")",
";",
"$",
"success",
"=",
"@",
"mkdir",
"(",
"$",
"path",
",",
"intval",
"(",
"$",
"mode",
",",
"8",
")",
",",
"true",
")",
";",
"umask",
"(",
"$",
"current_umask",
")",
";",
"return",
"$",
"success",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"if",
"(",
"$",
"silent",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"__",
"(",
"'Unable to create path - %s'",
",",
"array",
"(",
"$",
"path",
")",
")",
")",
";",
"}",
"return",
"false",
";",
"}",
"}"
] | Create all the directories as specified by the input path. If the current
directory already exists, this function will return true.
@param string $path
the path containing the directories to create.
@param string|integer $mode (optional)
the permissions (in octal) of the directories to create. Defaults to 0755
@param boolean $silent (optional)
true if an exception should be raised if an error occurs, false
otherwise. this defaults to true.
@throws Exception
@return boolean | [
"Create",
"all",
"the",
"directories",
"as",
"specified",
"by",
"the",
"input",
"path",
".",
"If",
"the",
"current",
"directory",
"already",
"exists",
"this",
"function",
"will",
"return",
"true",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L558-L577 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.deleteDirectory | public static function deleteDirectory($dir, $silent = true)
{
try {
if (!@file_exists($dir)) {
return true;
}
if (!@is_dir($dir)) {
return @unlink($dir);
}
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..') {
continue;
}
if (!self::deleteDirectory($dir.DIRECTORY_SEPARATOR.$item)) {
return false;
}
}
return rmdir($dir);
} catch (Exception $ex) {
if ($silent === false) {
throw new Exception(__('Unable to remove - %s', array($dir)));
}
return false;
}
} | php | public static function deleteDirectory($dir, $silent = true)
{
try {
if (!@file_exists($dir)) {
return true;
}
if (!@is_dir($dir)) {
return @unlink($dir);
}
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..') {
continue;
}
if (!self::deleteDirectory($dir.DIRECTORY_SEPARATOR.$item)) {
return false;
}
}
return rmdir($dir);
} catch (Exception $ex) {
if ($silent === false) {
throw new Exception(__('Unable to remove - %s', array($dir)));
}
return false;
}
} | [
"public",
"static",
"function",
"deleteDirectory",
"(",
"$",
"dir",
",",
"$",
"silent",
"=",
"true",
")",
"{",
"try",
"{",
"if",
"(",
"!",
"@",
"file_exists",
"(",
"$",
"dir",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"@",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"return",
"@",
"unlink",
"(",
"$",
"dir",
")",
";",
"}",
"foreach",
"(",
"scandir",
"(",
"$",
"dir",
")",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"==",
"'.'",
"||",
"$",
"item",
"==",
"'..'",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"self",
"::",
"deleteDirectory",
"(",
"$",
"dir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"item",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"rmdir",
"(",
"$",
"dir",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"if",
"(",
"$",
"silent",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"__",
"(",
"'Unable to remove - %s'",
",",
"array",
"(",
"$",
"dir",
")",
")",
")",
";",
"}",
"return",
"false",
";",
"}",
"}"
] | Recursively deletes all files and directories given a directory. This
function has two path. This function optionally takes a `$silent` parameter,
which when `false` will throw an `Exception` if there is an error deleting a file
or folder.
@since Symphony 2.3
@param string $dir
the path of the directory to delete
@param boolean $silent (optional)
true if an exception should be raised if an error occurs, false
otherwise. this defaults to true.
@throws Exception
@return boolean | [
"Recursively",
"deletes",
"all",
"files",
"and",
"directories",
"given",
"a",
"directory",
".",
"This",
"function",
"has",
"two",
"path",
".",
"This",
"function",
"optionally",
"takes",
"a",
"$silent",
"parameter",
"which",
"when",
"false",
"will",
"throw",
"an",
"Exception",
"if",
"there",
"is",
"an",
"error",
"deleting",
"a",
"file",
"or",
"folder",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L594-L623 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.in_array_multi | public static function in_array_multi($needle, $haystack)
{
if ($needle == $haystack) {
return true;
}
if (is_array($haystack)) {
foreach ($haystack as $key => $val) {
if (is_array($val)) {
if (self::in_array_multi($needle, $val)) {
return true;
}
} elseif (!strcmp($needle, $key) || !strcmp($needle, $val)) {
return true;
}
}
}
return false;
} | php | public static function in_array_multi($needle, $haystack)
{
if ($needle == $haystack) {
return true;
}
if (is_array($haystack)) {
foreach ($haystack as $key => $val) {
if (is_array($val)) {
if (self::in_array_multi($needle, $val)) {
return true;
}
} elseif (!strcmp($needle, $key) || !strcmp($needle, $val)) {
return true;
}
}
}
return false;
} | [
"public",
"static",
"function",
"in_array_multi",
"(",
"$",
"needle",
",",
"$",
"haystack",
")",
"{",
"if",
"(",
"$",
"needle",
"==",
"$",
"haystack",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"haystack",
")",
")",
"{",
"foreach",
"(",
"$",
"haystack",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"val",
")",
")",
"{",
"if",
"(",
"self",
"::",
"in_array_multi",
"(",
"$",
"needle",
",",
"$",
"val",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"elseif",
"(",
"!",
"strcmp",
"(",
"$",
"needle",
",",
"$",
"key",
")",
"||",
"!",
"strcmp",
"(",
"$",
"needle",
",",
"$",
"val",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Search a multi-dimensional array for a value.
@param mixed $needle
the value to search for.
@param array $haystack
the multi-dimensional array to search.
@return boolean
true if `$needle` is found in `$haystack`.
true if `$needle` == `$haystack`.
true if `$needle` is found in any of the arrays contained within `$haystack`.
false otherwise. | [
"Search",
"a",
"multi",
"-",
"dimensional",
"array",
"for",
"a",
"value",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L638-L657 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.in_array_all | public static function in_array_all($needles, $haystack)
{
foreach ($needles as $n) {
if (!in_array($n, $haystack)) {
return false;
}
}
return true;
} | php | public static function in_array_all($needles, $haystack)
{
foreach ($needles as $n) {
if (!in_array($n, $haystack)) {
return false;
}
}
return true;
} | [
"public",
"static",
"function",
"in_array_all",
"(",
"$",
"needles",
",",
"$",
"haystack",
")",
"{",
"foreach",
"(",
"$",
"needles",
"as",
"$",
"n",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"n",
",",
"$",
"haystack",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Search an array for multiple values.
@param array $needles
the values to search the `$haystack` for.
@param array $haystack
the in which to search for the `$needles`
@return boolean
true if any of the `$needles` are in `$haystack`,
false otherwise. | [
"Search",
"an",
"array",
"for",
"multiple",
"values",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L670-L679 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.processFilePostData | public static function processFilePostData($filedata)
{
$result = array();
foreach ($filedata as $key => $data) {
foreach ($data as $handle => $value) {
if (is_array($value)) {
foreach ($value as $index => $pair) {
if (!is_array($result[$handle][$index])) {
$result[$handle][$index] = array();
}
if (!is_array($pair)) {
$result[$handle][$index][$key] = $pair;
} else {
$result[$handle][$index][array_pop(array_keys($pair))][$key] = array_pop(array_values($pair));
}
}
} else {
$result[$handle][$key] = $value;
}
}
}
return $result;
} | php | public static function processFilePostData($filedata)
{
$result = array();
foreach ($filedata as $key => $data) {
foreach ($data as $handle => $value) {
if (is_array($value)) {
foreach ($value as $index => $pair) {
if (!is_array($result[$handle][$index])) {
$result[$handle][$index] = array();
}
if (!is_array($pair)) {
$result[$handle][$index][$key] = $pair;
} else {
$result[$handle][$index][array_pop(array_keys($pair))][$key] = array_pop(array_values($pair));
}
}
} else {
$result[$handle][$key] = $value;
}
}
}
return $result;
} | [
"public",
"static",
"function",
"processFilePostData",
"(",
"$",
"filedata",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"filedata",
"as",
"$",
"key",
"=>",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"handle",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"index",
"=>",
"$",
"pair",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"result",
"[",
"$",
"handle",
"]",
"[",
"$",
"index",
"]",
")",
")",
"{",
"$",
"result",
"[",
"$",
"handle",
"]",
"[",
"$",
"index",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"pair",
")",
")",
"{",
"$",
"result",
"[",
"$",
"handle",
"]",
"[",
"$",
"index",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"pair",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"$",
"handle",
"]",
"[",
"$",
"index",
"]",
"[",
"array_pop",
"(",
"array_keys",
"(",
"$",
"pair",
")",
")",
"]",
"[",
"$",
"key",
"]",
"=",
"array_pop",
"(",
"array_values",
"(",
"$",
"pair",
")",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"result",
"[",
"$",
"handle",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Transform a multi-dimensional array to a flat array. The input array
is expected to conform to the structure of the `$_FILES` variable.
@param array $filedata
the raw `$_FILES` data structured array
@return array
the flattened array. | [
"Transform",
"a",
"multi",
"-",
"dimensional",
"array",
"to",
"a",
"flat",
"array",
".",
"The",
"input",
"array",
"is",
"expected",
"to",
"conform",
"to",
"the",
"structure",
"of",
"the",
"$_FILES",
"variable",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L690-L715 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.getPostData | public static function getPostData()
{
if (!function_exists('merge_file_post_data')) {
function merge_file_post_data($type, array $file, &$post)
{
foreach ($file as $key => $value) {
if (!isset($post[$key])) {
$post[$key] = array();
}
if (is_array($value)) {
merge_file_post_data($type, $value, $post[$key]);
} else {
$post[$key][$type] = $value;
}
}
}
}
$files = array(
'name' => array(),
'type' => array(),
'tmp_name' => array(),
'error' => array(),
'size' => array()
);
$post = $_POST;
if (is_array($_FILES) && !empty($_FILES)) {
foreach ($_FILES as $key_a => $data_a) {
if (!is_array($data_a)) {
continue;
}
foreach ($data_a as $key_b => $data_b) {
$files[$key_b][$key_a] = $data_b;
}
}
}
foreach ($files as $type => $data) {
merge_file_post_data($type, $data, $post);
}
return $post;
} | php | public static function getPostData()
{
if (!function_exists('merge_file_post_data')) {
function merge_file_post_data($type, array $file, &$post)
{
foreach ($file as $key => $value) {
if (!isset($post[$key])) {
$post[$key] = array();
}
if (is_array($value)) {
merge_file_post_data($type, $value, $post[$key]);
} else {
$post[$key][$type] = $value;
}
}
}
}
$files = array(
'name' => array(),
'type' => array(),
'tmp_name' => array(),
'error' => array(),
'size' => array()
);
$post = $_POST;
if (is_array($_FILES) && !empty($_FILES)) {
foreach ($_FILES as $key_a => $data_a) {
if (!is_array($data_a)) {
continue;
}
foreach ($data_a as $key_b => $data_b) {
$files[$key_b][$key_a] = $data_b;
}
}
}
foreach ($files as $type => $data) {
merge_file_post_data($type, $data, $post);
}
return $post;
} | [
"public",
"static",
"function",
"getPostData",
"(",
")",
"{",
"if",
"(",
"!",
"function_exists",
"(",
"'merge_file_post_data'",
")",
")",
"{",
"function",
"merge_file_post_data",
"(",
"$",
"type",
",",
"array",
"$",
"file",
",",
"&",
"$",
"post",
")",
"{",
"foreach",
"(",
"$",
"file",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"post",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"post",
"[",
"$",
"key",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"merge_file_post_data",
"(",
"$",
"type",
",",
"$",
"value",
",",
"$",
"post",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"{",
"$",
"post",
"[",
"$",
"key",
"]",
"[",
"$",
"type",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"}",
"$",
"files",
"=",
"array",
"(",
"'name'",
"=>",
"array",
"(",
")",
",",
"'type'",
"=>",
"array",
"(",
")",
",",
"'tmp_name'",
"=>",
"array",
"(",
")",
",",
"'error'",
"=>",
"array",
"(",
")",
",",
"'size'",
"=>",
"array",
"(",
")",
")",
";",
"$",
"post",
"=",
"$",
"_POST",
";",
"if",
"(",
"is_array",
"(",
"$",
"_FILES",
")",
"&&",
"!",
"empty",
"(",
"$",
"_FILES",
")",
")",
"{",
"foreach",
"(",
"$",
"_FILES",
"as",
"$",
"key_a",
"=>",
"$",
"data_a",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data_a",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"data_a",
"as",
"$",
"key_b",
"=>",
"$",
"data_b",
")",
"{",
"$",
"files",
"[",
"$",
"key_b",
"]",
"[",
"$",
"key_a",
"]",
"=",
"$",
"data_b",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"files",
"as",
"$",
"type",
"=>",
"$",
"data",
")",
"{",
"merge_file_post_data",
"(",
"$",
"type",
",",
"$",
"data",
",",
"$",
"post",
")",
";",
"}",
"return",
"$",
"post",
";",
"}"
] | Merge `$_POST` with `$_FILES` to produce a flat array of the contents
of both. If there is no merge_file_post_data function defined then
such a function is created. This is necessary to overcome PHP's ability
to handle forms. This overcomes PHP's convoluted `$_FILES` structure
to make it simpler to access `multi-part/formdata`.
@return array
a flat array containing the flattened contents of both `$_POST` and
`$_FILES`. | [
"Merge",
"$_POST",
"with",
"$_FILES",
"to",
"produce",
"a",
"flat",
"array",
"of",
"the",
"contents",
"of",
"both",
".",
"If",
"there",
"is",
"no",
"merge_file_post_data",
"function",
"defined",
"then",
"such",
"a",
"function",
"is",
"created",
".",
"This",
"is",
"necessary",
"to",
"overcome",
"PHP",
"s",
"ability",
"to",
"handle",
"forms",
".",
"This",
"overcomes",
"PHP",
"s",
"convoluted",
"$_FILES",
"structure",
"to",
"make",
"it",
"simpler",
"to",
"access",
"multi",
"-",
"part",
"/",
"formdata",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L728-L773 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.array_find_available_index | public static function array_find_available_index($array, $seed = null)
{
if (!is_null($seed)) {
$index = $seed;
} else {
$keys = array_keys($array);
sort($keys);
$index = array_pop($keys);
}
if (isset($array[$index])) {
do {
$index++;
} while (isset($array[$index]));
}
return $index;
} | php | public static function array_find_available_index($array, $seed = null)
{
if (!is_null($seed)) {
$index = $seed;
} else {
$keys = array_keys($array);
sort($keys);
$index = array_pop($keys);
}
if (isset($array[$index])) {
do {
$index++;
} while (isset($array[$index]));
}
return $index;
} | [
"public",
"static",
"function",
"array_find_available_index",
"(",
"$",
"array",
",",
"$",
"seed",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"seed",
")",
")",
"{",
"$",
"index",
"=",
"$",
"seed",
";",
"}",
"else",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"array",
")",
";",
"sort",
"(",
"$",
"keys",
")",
";",
"$",
"index",
"=",
"array_pop",
"(",
"$",
"keys",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"array",
"[",
"$",
"index",
"]",
")",
")",
"{",
"do",
"{",
"$",
"index",
"++",
";",
"}",
"while",
"(",
"isset",
"(",
"$",
"array",
"[",
"$",
"index",
"]",
")",
")",
";",
"}",
"return",
"$",
"index",
";",
"}"
] | Find the next available index in an array. Works best with numeric keys.
The next available index is the minimum integer such that the array does
not have a mapping for that index. Uses the increment operator on the
index type of the input array, whatever that may do.
@param array $array
the array to find the next index for.
@param mixed $seed (optional)
the object with which the search for an empty index is initialized. this
defaults to null.
@return integer
the minimum empty index into the input array. | [
"Find",
"the",
"next",
"available",
"index",
"in",
"an",
"array",
".",
"Works",
"best",
"with",
"numeric",
"keys",
".",
"The",
"next",
"available",
"index",
"is",
"the",
"minimum",
"integer",
"such",
"that",
"the",
"array",
"does",
"not",
"have",
"a",
"mapping",
"for",
"that",
"index",
".",
"Uses",
"the",
"increment",
"operator",
"on",
"the",
"index",
"type",
"of",
"the",
"input",
"array",
"whatever",
"that",
"may",
"do",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L789-L806 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.in_iarray | public static function in_iarray($needle, array $haystack)
{
foreach ($haystack as $key => $value) {
if (strcasecmp($value, $needle) == 0) {
return true;
}
}
return false;
} | php | public static function in_iarray($needle, array $haystack)
{
foreach ($haystack as $key => $value) {
if (strcasecmp($value, $needle) == 0) {
return true;
}
}
return false;
} | [
"public",
"static",
"function",
"in_iarray",
"(",
"$",
"needle",
",",
"array",
"$",
"haystack",
")",
"{",
"foreach",
"(",
"$",
"haystack",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"strcasecmp",
"(",
"$",
"value",
",",
"$",
"needle",
")",
"==",
"0",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Test whether a value is in an array based on string comparison, ignoring
the case of the values.
@param mixed $needle
the object to search the array for.
@param array $haystack
the array to search for the `$needle`.
@return boolean
true if the `$needle` is in the `$haystack`, false otherwise. | [
"Test",
"whether",
"a",
"value",
"is",
"in",
"an",
"array",
"based",
"on",
"string",
"comparison",
"ignoring",
"the",
"case",
"of",
"the",
"values",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L836-L844 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.array_iunique | public static function array_iunique(array $array)
{
$tmp = array();
foreach ($array as $key => $value) {
if (!self::in_iarray($value, $tmp)) {
$tmp[$key] = $value;
}
}
return $tmp;
} | php | public static function array_iunique(array $array)
{
$tmp = array();
foreach ($array as $key => $value) {
if (!self::in_iarray($value, $tmp)) {
$tmp[$key] = $value;
}
}
return $tmp;
} | [
"public",
"static",
"function",
"array_iunique",
"(",
"array",
"$",
"array",
")",
"{",
"$",
"tmp",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"in_iarray",
"(",
"$",
"value",
",",
"$",
"tmp",
")",
")",
"{",
"$",
"tmp",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"tmp",
";",
"}"
] | Filter the input array for duplicates, treating each element in the array
as a string and comparing them using a case insensitive comparison function.
@param array $array
the array to filter.
@return array
a new array containing only the unique elements of the input array. | [
"Filter",
"the",
"input",
"array",
"for",
"duplicates",
"treating",
"each",
"element",
"in",
"the",
"array",
"as",
"a",
"string",
"and",
"comparing",
"them",
"using",
"a",
"case",
"insensitive",
"comparison",
"function",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L855-L866 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.array_map_recursive | public static function array_map_recursive($function, array $array)
{
$tmp = array();
foreach ($array as $key => $value) {
if (is_array($value)) {
$tmp[$key] = self::array_map_recursive($function, $value);
} else {
$tmp[$key] = call_user_func($function, $value);
}
}
return $tmp;
} | php | public static function array_map_recursive($function, array $array)
{
$tmp = array();
foreach ($array as $key => $value) {
if (is_array($value)) {
$tmp[$key] = self::array_map_recursive($function, $value);
} else {
$tmp[$key] = call_user_func($function, $value);
}
}
return $tmp;
} | [
"public",
"static",
"function",
"array_map_recursive",
"(",
"$",
"function",
",",
"array",
"$",
"array",
")",
"{",
"$",
"tmp",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"tmp",
"[",
"$",
"key",
"]",
"=",
"self",
"::",
"array_map_recursive",
"(",
"$",
"function",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"tmp",
"[",
"$",
"key",
"]",
"=",
"call_user_func",
"(",
"$",
"function",
",",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"tmp",
";",
"}"
] | Function recursively apply a function to an array's values.
This will not touch the keys, just the values.
@since Symphony 2.2
@param string $function
@param array $array
@return array
a new array with all the values passed through the given `$function` | [
"Function",
"recursively",
"apply",
"a",
"function",
"to",
"an",
"array",
"s",
"values",
".",
"This",
"will",
"not",
"touch",
"the",
"keys",
"just",
"the",
"values",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L878-L891 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.array_to_xml | public static function array_to_xml(XMLElement $parent, array $data, $validate = false)
{
foreach ($data as $element_name => $value) {
if (!is_numeric($value) && empty($value)) {
continue;
}
if (is_int($element_name)) {
$child = new XMLElement('item');
$child->setAttribute('index', $element_name + 1);
} else {
$child = new XMLElement($element_name, null, array(), true);
}
if (is_array($value) || is_object($value)) {
self::array_to_xml($child, (array)$value);
if ($child->getNumberOfChildren() == 0) {
continue;
}
} elseif ($validate === true && !self::validateXML(self::sanitize($value), $errors, false, new XSLTProcess)) {
continue;
} else {
$child->setValue(self::sanitize($value));
}
$parent->appendChild($child);
}
} | php | public static function array_to_xml(XMLElement $parent, array $data, $validate = false)
{
foreach ($data as $element_name => $value) {
if (!is_numeric($value) && empty($value)) {
continue;
}
if (is_int($element_name)) {
$child = new XMLElement('item');
$child->setAttribute('index', $element_name + 1);
} else {
$child = new XMLElement($element_name, null, array(), true);
}
if (is_array($value) || is_object($value)) {
self::array_to_xml($child, (array)$value);
if ($child->getNumberOfChildren() == 0) {
continue;
}
} elseif ($validate === true && !self::validateXML(self::sanitize($value), $errors, false, new XSLTProcess)) {
continue;
} else {
$child->setValue(self::sanitize($value));
}
$parent->appendChild($child);
}
} | [
"public",
"static",
"function",
"array_to_xml",
"(",
"XMLElement",
"$",
"parent",
",",
"array",
"$",
"data",
",",
"$",
"validate",
"=",
"false",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"element_name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"value",
")",
"&&",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"is_int",
"(",
"$",
"element_name",
")",
")",
"{",
"$",
"child",
"=",
"new",
"XMLElement",
"(",
"'item'",
")",
";",
"$",
"child",
"->",
"setAttribute",
"(",
"'index'",
",",
"$",
"element_name",
"+",
"1",
")",
";",
"}",
"else",
"{",
"$",
"child",
"=",
"new",
"XMLElement",
"(",
"$",
"element_name",
",",
"null",
",",
"array",
"(",
")",
",",
"true",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"||",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"self",
"::",
"array_to_xml",
"(",
"$",
"child",
",",
"(",
"array",
")",
"$",
"value",
")",
";",
"if",
"(",
"$",
"child",
"->",
"getNumberOfChildren",
"(",
")",
"==",
"0",
")",
"{",
"continue",
";",
"}",
"}",
"elseif",
"(",
"$",
"validate",
"===",
"true",
"&&",
"!",
"self",
"::",
"validateXML",
"(",
"self",
"::",
"sanitize",
"(",
"$",
"value",
")",
",",
"$",
"errors",
",",
"false",
",",
"new",
"XSLTProcess",
")",
")",
"{",
"continue",
";",
"}",
"else",
"{",
"$",
"child",
"->",
"setValue",
"(",
"self",
"::",
"sanitize",
"(",
"$",
"value",
")",
")",
";",
"}",
"$",
"parent",
"->",
"appendChild",
"(",
"$",
"child",
")",
";",
"}",
"}"
] | Convert an array into an XML fragment and append it to an existing
XML element. Any arrays contained as elements in the input array will
also be recursively formatted and appended to the input XML fragment.
The input XML element will be modified as a result of calling this.
@param XMLElement $parent
the XML element to append the formatted array data to.
@param array $data
the array to format and append to the XML fragment.
@param boolean $validate
true if the formatted array data should be validated as it is
constructed, false otherwise. | [
"Convert",
"an",
"array",
"into",
"an",
"XML",
"fragment",
"and",
"append",
"it",
"to",
"an",
"existing",
"XML",
"element",
".",
"Any",
"arrays",
"contained",
"as",
"elements",
"in",
"the",
"input",
"array",
"will",
"also",
"be",
"recursively",
"formatted",
"and",
"appended",
"to",
"the",
"input",
"XML",
"fragment",
".",
"The",
"input",
"XML",
"element",
"will",
"be",
"modified",
"as",
"a",
"result",
"of",
"calling",
"this",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L907-L935 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.writeFile | public static function writeFile($file, $data, $perm = 0644, $mode = 'w', $trim = false)
{
if (static::checkFileWritable($file) === false) {
return false;
}
if (!$handle = fopen($file, $mode)) {
return false;
}
if ($trim === true) {
$data = preg_replace("/(" . PHP_EOL . "([ |\t]+)?){2,}" . PHP_EOL . "/", PHP_EOL . PHP_EOL, trim($data));
}
if (fwrite($handle, $data, strlen($data)) === false) {
return false;
}
fclose($handle);
try {
if (is_null($perm)) {
$perm = 0644;
}
@chmod($file, intval($perm, 8));
} catch (Exception $ex) {
// If we can't chmod the file, this is probably because our host is
// running PHP with a different user to that of the file. Although we
// can delete the file, create a new one and then chmod it, we run the
// risk of losing the file as we aren't saving it anywhere. For the immediate
// future, atomic saving isn't needed by Symphony and it's recommended that
// if your extension require this logic, it uses it's own function rather
// than this 'General' one.
return true;
}
return true;
} | php | public static function writeFile($file, $data, $perm = 0644, $mode = 'w', $trim = false)
{
if (static::checkFileWritable($file) === false) {
return false;
}
if (!$handle = fopen($file, $mode)) {
return false;
}
if ($trim === true) {
$data = preg_replace("/(" . PHP_EOL . "([ |\t]+)?){2,}" . PHP_EOL . "/", PHP_EOL . PHP_EOL, trim($data));
}
if (fwrite($handle, $data, strlen($data)) === false) {
return false;
}
fclose($handle);
try {
if (is_null($perm)) {
$perm = 0644;
}
@chmod($file, intval($perm, 8));
} catch (Exception $ex) {
// If we can't chmod the file, this is probably because our host is
// running PHP with a different user to that of the file. Although we
// can delete the file, create a new one and then chmod it, we run the
// risk of losing the file as we aren't saving it anywhere. For the immediate
// future, atomic saving isn't needed by Symphony and it's recommended that
// if your extension require this logic, it uses it's own function rather
// than this 'General' one.
return true;
}
return true;
} | [
"public",
"static",
"function",
"writeFile",
"(",
"$",
"file",
",",
"$",
"data",
",",
"$",
"perm",
"=",
"0644",
",",
"$",
"mode",
"=",
"'w'",
",",
"$",
"trim",
"=",
"false",
")",
"{",
"if",
"(",
"static",
"::",
"checkFileWritable",
"(",
"$",
"file",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"handle",
"=",
"fopen",
"(",
"$",
"file",
",",
"$",
"mode",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"trim",
"===",
"true",
")",
"{",
"$",
"data",
"=",
"preg_replace",
"(",
"\"/(\"",
".",
"PHP_EOL",
".",
"\"([ |\\t]+)?){2,}\"",
".",
"PHP_EOL",
".",
"\"/\"",
",",
"PHP_EOL",
".",
"PHP_EOL",
",",
"trim",
"(",
"$",
"data",
")",
")",
";",
"}",
"if",
"(",
"fwrite",
"(",
"$",
"handle",
",",
"$",
"data",
",",
"strlen",
"(",
"$",
"data",
")",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"fclose",
"(",
"$",
"handle",
")",
";",
"try",
"{",
"if",
"(",
"is_null",
"(",
"$",
"perm",
")",
")",
"{",
"$",
"perm",
"=",
"0644",
";",
"}",
"@",
"chmod",
"(",
"$",
"file",
",",
"intval",
"(",
"$",
"perm",
",",
"8",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"// If we can't chmod the file, this is probably because our host is",
"// running PHP with a different user to that of the file. Although we",
"// can delete the file, create a new one and then chmod it, we run the",
"// risk of losing the file as we aren't saving it anywhere. For the immediate",
"// future, atomic saving isn't needed by Symphony and it's recommended that",
"// if your extension require this logic, it uses it's own function rather",
"// than this 'General' one.",
"return",
"true",
";",
"}",
"return",
"true",
";",
"}"
] | Create a file at the input path with the (optional) input permissions
with the input content. This function will ignore errors in opening,
writing, closing and changing the permissions of the resulting file.
If opening or writing the file fail then this will return false.
This method calls `General::checkFileWritable()` which properly checks
for permissions.
@uses General::checkFileWritable()
@param string $file
the path of the file to write.
@param mixed $data
the data to write to the file.
@param integer|string $perm (optional)
the permissions as an octal number to set set on the resulting file.
this defaults to 0644 (if omitted or set to null)
@param string $mode (optional)
the mode that the file should be opened with, defaults to 'w'. See modes
at http://php.net/manual/en/function.fopen.php
@param boolean $trim (optional)
removes tripple linebreaks
@return boolean
true if the file is successfully opened, written to, closed and has the
required permissions set. false, otherwise. | [
"Create",
"a",
"file",
"at",
"the",
"input",
"path",
"with",
"the",
"(",
"optional",
")",
"input",
"permissions",
"with",
"the",
"input",
"content",
".",
"This",
"function",
"will",
"ignore",
"errors",
"in",
"opening",
"writing",
"closing",
"and",
"changing",
"the",
"permissions",
"of",
"the",
"resulting",
"file",
".",
"If",
"opening",
"or",
"writing",
"the",
"file",
"fail",
"then",
"this",
"will",
"return",
"false",
".",
"This",
"method",
"calls",
"General",
"::",
"checkFileWritable",
"()",
"which",
"properly",
"checks",
"for",
"permissions",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L962-L1000 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.checkFile | public static function checkFile($file)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('General::checkFile()', '`General::checkFileWritable()');
}
clearstatcache();
$dir = dirname($file);
if (
(!is_writable($dir) || !is_readable($dir)) // Folder
|| (file_exists($file) && (!is_readable($file) || !is_writable($file))) // File
) {
return false;
}
return true;
} | php | public static function checkFile($file)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('General::checkFile()', '`General::checkFileWritable()');
}
clearstatcache();
$dir = dirname($file);
if (
(!is_writable($dir) || !is_readable($dir)) // Folder
|| (file_exists($file) && (!is_readable($file) || !is_writable($file))) // File
) {
return false;
}
return true;
} | [
"public",
"static",
"function",
"checkFile",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"Symphony",
"::",
"Log",
"(",
")",
")",
"{",
"Symphony",
"::",
"Log",
"(",
")",
"->",
"pushDeprecateWarningToLog",
"(",
"'General::checkFile()'",
",",
"'`General::checkFileWritable()'",
")",
";",
"}",
"clearstatcache",
"(",
")",
";",
"$",
"dir",
"=",
"dirname",
"(",
"$",
"file",
")",
";",
"if",
"(",
"(",
"!",
"is_writable",
"(",
"$",
"dir",
")",
"||",
"!",
"is_readable",
"(",
"$",
"dir",
")",
")",
"// Folder",
"||",
"(",
"file_exists",
"(",
"$",
"file",
")",
"&&",
"(",
"!",
"is_readable",
"(",
"$",
"file",
")",
"||",
"!",
"is_writable",
"(",
"$",
"file",
")",
")",
")",
"// File",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Checks that the file and its folder are readable and writable.
@deprecated @since Symphony 2.7.0
@since Symphony 2.6.3
@return boolean | [
"Checks",
"that",
"the",
"file",
"and",
"its",
"folder",
"are",
"readable",
"and",
"writable",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L1009-L1025 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.checkFileWritable | public static function checkFileWritable($file)
{
clearstatcache();
if (@file_exists($file)) {
// Writing to an existing file does not require write
// permissions on the directory.
return @is_writable($file);
}
$dir = dirname($file);
// Creating a file requires write permissions on the directory.
return @file_exists($dir) && @is_writable($dir);
} | php | public static function checkFileWritable($file)
{
clearstatcache();
if (@file_exists($file)) {
// Writing to an existing file does not require write
// permissions on the directory.
return @is_writable($file);
}
$dir = dirname($file);
// Creating a file requires write permissions on the directory.
return @file_exists($dir) && @is_writable($dir);
} | [
"public",
"static",
"function",
"checkFileWritable",
"(",
"$",
"file",
")",
"{",
"clearstatcache",
"(",
")",
";",
"if",
"(",
"@",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"// Writing to an existing file does not require write",
"// permissions on the directory.",
"return",
"@",
"is_writable",
"(",
"$",
"file",
")",
";",
"}",
"$",
"dir",
"=",
"dirname",
"(",
"$",
"file",
")",
";",
"// Creating a file requires write permissions on the directory.",
"return",
"@",
"file_exists",
"(",
"$",
"dir",
")",
"&&",
"@",
"is_writable",
"(",
"$",
"dir",
")",
";",
"}"
] | Checks that the file is writable.
It first checks to see if the $file path exists
and if it does, checks that is it writable. If the file
does not exits, it checks that the directory exists and if it does,
checks that it is writable.
@uses clearstatcache()
@since Symphony 2.7.0
@param string $file
The path of the file
@return boolean | [
"Checks",
"that",
"the",
"file",
"is",
"writable",
".",
"It",
"first",
"checks",
"to",
"see",
"if",
"the",
"$file",
"path",
"exists",
"and",
"if",
"it",
"does",
"checks",
"that",
"is",
"it",
"writable",
".",
"If",
"the",
"file",
"does",
"not",
"exits",
"it",
"checks",
"that",
"the",
"directory",
"exists",
"and",
"if",
"it",
"does",
"checks",
"that",
"it",
"is",
"writable",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L1058-L1069 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.checkFileDeletable | public static function checkFileDeletable($file)
{
clearstatcache();
$dir = dirname($file);
// Deleting a file requires write permissions on the directory.
// It does not require write permissions on the file
return @file_exists($dir) && @is_writable($dir);
} | php | public static function checkFileDeletable($file)
{
clearstatcache();
$dir = dirname($file);
// Deleting a file requires write permissions on the directory.
// It does not require write permissions on the file
return @file_exists($dir) && @is_writable($dir);
} | [
"public",
"static",
"function",
"checkFileDeletable",
"(",
"$",
"file",
")",
"{",
"clearstatcache",
"(",
")",
";",
"$",
"dir",
"=",
"dirname",
"(",
"$",
"file",
")",
";",
"// Deleting a file requires write permissions on the directory.",
"// It does not require write permissions on the file",
"return",
"@",
"file_exists",
"(",
"$",
"dir",
")",
"&&",
"@",
"is_writable",
"(",
"$",
"dir",
")",
";",
"}"
] | Checks that the file is deletable.
It first checks to see if the $file path exists
and if it does, checks that is it writable.
@uses clearstatcache()
@since Symphony 2.7.0
@param string $file
The path of the file
@return boolean | [
"Checks",
"that",
"the",
"file",
"is",
"deletable",
".",
"It",
"first",
"checks",
"to",
"see",
"if",
"the",
"$file",
"path",
"exists",
"and",
"if",
"it",
"does",
"checks",
"that",
"is",
"it",
"writable",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L1082-L1089 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.deleteFile | public static function deleteFile($file, $silent = true)
{
try {
if (static::checkFileDeletable($file) === false) {
throw new Exception(__('Denied by permission'));
}
if (!@file_exists($file)) {
return true;
}
return @unlink($file);
} catch (Exception $ex) {
if ($silent === false) {
throw new Exception(__('Unable to remove file - %s', array($file)), 0, $ex);
}
return false;
}
} | php | public static function deleteFile($file, $silent = true)
{
try {
if (static::checkFileDeletable($file) === false) {
throw new Exception(__('Denied by permission'));
}
if (!@file_exists($file)) {
return true;
}
return @unlink($file);
} catch (Exception $ex) {
if ($silent === false) {
throw new Exception(__('Unable to remove file - %s', array($file)), 0, $ex);
}
return false;
}
} | [
"public",
"static",
"function",
"deleteFile",
"(",
"$",
"file",
",",
"$",
"silent",
"=",
"true",
")",
"{",
"try",
"{",
"if",
"(",
"static",
"::",
"checkFileDeletable",
"(",
"$",
"file",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"__",
"(",
"'Denied by permission'",
")",
")",
";",
"}",
"if",
"(",
"!",
"@",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"@",
"unlink",
"(",
"$",
"file",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"if",
"(",
"$",
"silent",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"__",
"(",
"'Unable to remove file - %s'",
",",
"array",
"(",
"$",
"file",
")",
")",
",",
"0",
",",
"$",
"ex",
")",
";",
"}",
"return",
"false",
";",
"}",
"}"
] | Delete a file at a given path, silently ignoring errors depending
on the value of the input variable $silent.
@uses General::checkFileDeletable()
@param string $file
the path of the file to delete
@param boolean $silent (optional)
true if an exception should be raised if an error occurs, false
otherwise. this defaults to true.
@throws Exception
@return boolean
true if the file is successfully unlinked, if the unlink fails and
silent is set to true then an exception is thrown. if the unlink
fails and silent is set to false then this returns false. | [
"Delete",
"a",
"file",
"at",
"a",
"given",
"path",
"silently",
"ignoring",
"errors",
"depending",
"on",
"the",
"value",
"of",
"the",
"input",
"variable",
"$silent",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L1107-L1124 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.getMimeType | public function getMimeType($file)
{
if (!empty($file)) {
// in PHP 5.3 we can use 'finfo'
if (PHP_VERSION_ID >= 50300 && function_exists('finfo_open')) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_file($finfo, $file);
finfo_close($finfo);
} else {
// A few mimetypes to "guess" using the file extension.
$mimetypes = array(
'txt' => 'text/plain',
'csv' => 'text/csv',
'pdf' => 'application/pdf',
'doc' => 'application/msword',
'docx' => 'application/msword',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
'eps' => 'application/postscript',
'zip' => 'application/zip',
'gif' => 'image/gif',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'png' => 'image/png',
'mp3' => 'audio/mpeg',
'mp4a' => 'audio/mp4',
'aac' => 'audio/x-aac',
'aif' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'wav' => 'audio/x-wav',
'wma' => 'audio/x-ms-wma',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mp4' => 'video/mp4',
'mov' => 'video/quicktime',
'avi' => 'video/x-msvideo',
'wmv' => 'video/x-ms-wmv',
);
$extension = substr(strrchr($file, '.'), 1);
if ($mimetypes[strtolower($extension)] !== null) {
$mime_type = $mimetypes[$extension];
} else {
$mime_type = 'application/octet-stream';
}
}
return $mime_type;
}
return false;
} | php | public function getMimeType($file)
{
if (!empty($file)) {
// in PHP 5.3 we can use 'finfo'
if (PHP_VERSION_ID >= 50300 && function_exists('finfo_open')) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_file($finfo, $file);
finfo_close($finfo);
} else {
// A few mimetypes to "guess" using the file extension.
$mimetypes = array(
'txt' => 'text/plain',
'csv' => 'text/csv',
'pdf' => 'application/pdf',
'doc' => 'application/msword',
'docx' => 'application/msword',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
'eps' => 'application/postscript',
'zip' => 'application/zip',
'gif' => 'image/gif',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'png' => 'image/png',
'mp3' => 'audio/mpeg',
'mp4a' => 'audio/mp4',
'aac' => 'audio/x-aac',
'aif' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'wav' => 'audio/x-wav',
'wma' => 'audio/x-ms-wma',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mp4' => 'video/mp4',
'mov' => 'video/quicktime',
'avi' => 'video/x-msvideo',
'wmv' => 'video/x-ms-wmv',
);
$extension = substr(strrchr($file, '.'), 1);
if ($mimetypes[strtolower($extension)] !== null) {
$mime_type = $mimetypes[$extension];
} else {
$mime_type = 'application/octet-stream';
}
}
return $mime_type;
}
return false;
} | [
"public",
"function",
"getMimeType",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"file",
")",
")",
"{",
"// in PHP 5.3 we can use 'finfo'",
"if",
"(",
"PHP_VERSION_ID",
">=",
"50300",
"&&",
"function_exists",
"(",
"'finfo_open'",
")",
")",
"{",
"$",
"finfo",
"=",
"finfo_open",
"(",
"FILEINFO_MIME_TYPE",
")",
";",
"$",
"mime_type",
"=",
"finfo_file",
"(",
"$",
"finfo",
",",
"$",
"file",
")",
";",
"finfo_close",
"(",
"$",
"finfo",
")",
";",
"}",
"else",
"{",
"// A few mimetypes to \"guess\" using the file extension.",
"$",
"mimetypes",
"=",
"array",
"(",
"'txt'",
"=>",
"'text/plain'",
",",
"'csv'",
"=>",
"'text/csv'",
",",
"'pdf'",
"=>",
"'application/pdf'",
",",
"'doc'",
"=>",
"'application/msword'",
",",
"'docx'",
"=>",
"'application/msword'",
",",
"'xls'",
"=>",
"'application/vnd.ms-excel'",
",",
"'ppt'",
"=>",
"'application/vnd.ms-powerpoint'",
",",
"'eps'",
"=>",
"'application/postscript'",
",",
"'zip'",
"=>",
"'application/zip'",
",",
"'gif'",
"=>",
"'image/gif'",
",",
"'jpg'",
"=>",
"'image/jpeg'",
",",
"'jpeg'",
"=>",
"'image/jpeg'",
",",
"'png'",
"=>",
"'image/png'",
",",
"'mp3'",
"=>",
"'audio/mpeg'",
",",
"'mp4a'",
"=>",
"'audio/mp4'",
",",
"'aac'",
"=>",
"'audio/x-aac'",
",",
"'aif'",
"=>",
"'audio/x-aiff'",
",",
"'aiff'",
"=>",
"'audio/x-aiff'",
",",
"'wav'",
"=>",
"'audio/x-wav'",
",",
"'wma'",
"=>",
"'audio/x-ms-wma'",
",",
"'mpeg'",
"=>",
"'video/mpeg'",
",",
"'mpg'",
"=>",
"'video/mpeg'",
",",
"'mp4'",
"=>",
"'video/mp4'",
",",
"'mov'",
"=>",
"'video/quicktime'",
",",
"'avi'",
"=>",
"'video/x-msvideo'",
",",
"'wmv'",
"=>",
"'video/x-ms-wmv'",
",",
")",
";",
"$",
"extension",
"=",
"substr",
"(",
"strrchr",
"(",
"$",
"file",
",",
"'.'",
")",
",",
"1",
")",
";",
"if",
"(",
"$",
"mimetypes",
"[",
"strtolower",
"(",
"$",
"extension",
")",
"]",
"!==",
"null",
")",
"{",
"$",
"mime_type",
"=",
"$",
"mimetypes",
"[",
"$",
"extension",
"]",
";",
"}",
"else",
"{",
"$",
"mime_type",
"=",
"'application/octet-stream'",
";",
"}",
"}",
"return",
"$",
"mime_type",
";",
"}",
"return",
"false",
";",
"}"
] | Gets mime type of a file.
For email attachments, the mime type is very important.
Uses the PHP 5.3 function `finfo_open` when available, otherwise falls
back to using a mapping of known of common mimetypes. If no matches
are found `application/octet-stream` will be returned.
@author Michael Eichelsdoerfer
@author Huib Keemink
@param string $file
@return string|boolean
the mime type of the file, or false is none found | [
"Gets",
"mime",
"type",
"of",
"a",
"file",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L1154-L1205 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.listDirStructure | public static function listDirStructure($dir = '.', $filter = null, $recurse = true, $strip_root = null, $exclude = array(), $ignore_hidden = true)
{
if (!is_dir($dir)) {
return null;
}
$files = array();
foreach (scandir($dir) as $file) {
if (
($file == '.' || $file == '..')
|| ($ignore_hidden && $file{0} == '.')
|| !is_dir("$dir/$file")
|| in_array($file, $exclude)
|| in_array("$dir/$file", $exclude)
) {
continue;
}
if (!is_null($filter)) {
if (!preg_match($filter, $file)) {
continue;
}
}
$files[] = rtrim(str_replace($strip_root, '', $dir), '/') ."/$file/";
if ($recurse) {
$files = @array_merge($files, self::listDirStructure("$dir/$file", $filter, $recurse, $strip_root, $exclude, $ignore_hidden));
}
}
return $files;
} | php | public static function listDirStructure($dir = '.', $filter = null, $recurse = true, $strip_root = null, $exclude = array(), $ignore_hidden = true)
{
if (!is_dir($dir)) {
return null;
}
$files = array();
foreach (scandir($dir) as $file) {
if (
($file == '.' || $file == '..')
|| ($ignore_hidden && $file{0} == '.')
|| !is_dir("$dir/$file")
|| in_array($file, $exclude)
|| in_array("$dir/$file", $exclude)
) {
continue;
}
if (!is_null($filter)) {
if (!preg_match($filter, $file)) {
continue;
}
}
$files[] = rtrim(str_replace($strip_root, '', $dir), '/') ."/$file/";
if ($recurse) {
$files = @array_merge($files, self::listDirStructure("$dir/$file", $filter, $recurse, $strip_root, $exclude, $ignore_hidden));
}
}
return $files;
} | [
"public",
"static",
"function",
"listDirStructure",
"(",
"$",
"dir",
"=",
"'.'",
",",
"$",
"filter",
"=",
"null",
",",
"$",
"recurse",
"=",
"true",
",",
"$",
"strip_root",
"=",
"null",
",",
"$",
"exclude",
"=",
"array",
"(",
")",
",",
"$",
"ignore_hidden",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"files",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"scandir",
"(",
"$",
"dir",
")",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"(",
"$",
"file",
"==",
"'.'",
"||",
"$",
"file",
"==",
"'..'",
")",
"||",
"(",
"$",
"ignore_hidden",
"&&",
"$",
"file",
"{",
"0",
"}",
"==",
"'.'",
")",
"||",
"!",
"is_dir",
"(",
"\"$dir/$file\"",
")",
"||",
"in_array",
"(",
"$",
"file",
",",
"$",
"exclude",
")",
"||",
"in_array",
"(",
"\"$dir/$file\"",
",",
"$",
"exclude",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"filter",
")",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"filter",
",",
"$",
"file",
")",
")",
"{",
"continue",
";",
"}",
"}",
"$",
"files",
"[",
"]",
"=",
"rtrim",
"(",
"str_replace",
"(",
"$",
"strip_root",
",",
"''",
",",
"$",
"dir",
")",
",",
"'/'",
")",
".",
"\"/$file/\"",
";",
"if",
"(",
"$",
"recurse",
")",
"{",
"$",
"files",
"=",
"@",
"array_merge",
"(",
"$",
"files",
",",
"self",
"::",
"listDirStructure",
"(",
"\"$dir/$file\"",
",",
"$",
"filter",
",",
"$",
"recurse",
",",
"$",
"strip_root",
",",
"$",
"exclude",
",",
"$",
"ignore_hidden",
")",
")",
";",
"}",
"}",
"return",
"$",
"files",
";",
"}"
] | Construct a multi-dimensional array that reflects the directory
structure of a given path.
@param string $dir (optional)
the path of the directory to construct the multi-dimensional array
for. this defaults to '.'.
@param string $filter (optional)
A regular expression to filter the directories. This is positive filter, ie.
if the filter matches, the directory is included. Defaults to null.
@param boolean $recurse (optional)
true if sub-directories should be traversed and reflected in the
resulting array, false otherwise.
@param mixed $strip_root (optional)
If null, the full path to the file will be returned, otherwise the value
of `strip_root` will be removed from the file path.
@param array $exclude (optional)
ignore directories listed in this array. this defaults to an empty array.
@param boolean $ignore_hidden (optional)
ignore hidden directory (i.e.directories that begin with a period). this defaults
to true.
@return null|array
return the array structure reflecting the input directory or null if
the input directory is not actually a directory. | [
"Construct",
"a",
"multi",
"-",
"dimensional",
"array",
"that",
"reflects",
"the",
"directory",
"structure",
"of",
"a",
"given",
"path",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L1232-L1265 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.listStructure | public static function listStructure($dir = ".", $filters = array(), $recurse = true, $sort = "asc", $strip_root = null, $exclude = array(), $ignore_hidden = true)
{
if (!is_dir($dir)) {
return null;
}
// Check to see if $filters is a string containing a regex, or an array of file types
if (is_array($filters) && !empty($filters)) {
$filter_type = 'file';
} elseif (is_string($filters)) {
$filter_type = 'regex';
} else {
$filter_type = null;
}
$files = array();
$prefix = str_replace($strip_root, '', $dir);
if ($prefix !== "" && substr($prefix, -1) !== "/") {
$prefix .= "/";
}
$files['dirlist'] = array();
$files['filelist'] = array();
foreach (scandir($dir) as $file) {
if (
($file == '.' || $file === '..')
|| ($ignore_hidden && $file{0} === '.')
|| in_array($file, $exclude)
|| in_array("$dir/$file", $exclude)
) {
continue;
}
$dir = rtrim($dir, '/');
if (is_dir("$dir/$file")) {
if ($recurse) {
$files["$prefix$file/"] = self::listStructure("$dir/$file", $filters, $recurse, $sort, $strip_root, $exclude, $ignore_hidden);
}
$files['dirlist'][] = "$prefix$file/";
} elseif ($filter_type === 'regex') {
if (preg_match($filters, $file)) {
$files['filelist'][] = "$prefix$file";
}
} elseif ($filter_type === 'file') {
if (in_array(self::getExtension($file), $filters)) {
$files['filelist'][] = "$prefix$file";
}
} elseif (is_null($filter_type)) {
$files['filelist'][] = "$prefix$file";
}
}
if (is_array($files['filelist'])) {
($sort == 'desc') ? rsort($files['filelist']) : sort($files['filelist']);
}
return $files;
} | php | public static function listStructure($dir = ".", $filters = array(), $recurse = true, $sort = "asc", $strip_root = null, $exclude = array(), $ignore_hidden = true)
{
if (!is_dir($dir)) {
return null;
}
// Check to see if $filters is a string containing a regex, or an array of file types
if (is_array($filters) && !empty($filters)) {
$filter_type = 'file';
} elseif (is_string($filters)) {
$filter_type = 'regex';
} else {
$filter_type = null;
}
$files = array();
$prefix = str_replace($strip_root, '', $dir);
if ($prefix !== "" && substr($prefix, -1) !== "/") {
$prefix .= "/";
}
$files['dirlist'] = array();
$files['filelist'] = array();
foreach (scandir($dir) as $file) {
if (
($file == '.' || $file === '..')
|| ($ignore_hidden && $file{0} === '.')
|| in_array($file, $exclude)
|| in_array("$dir/$file", $exclude)
) {
continue;
}
$dir = rtrim($dir, '/');
if (is_dir("$dir/$file")) {
if ($recurse) {
$files["$prefix$file/"] = self::listStructure("$dir/$file", $filters, $recurse, $sort, $strip_root, $exclude, $ignore_hidden);
}
$files['dirlist'][] = "$prefix$file/";
} elseif ($filter_type === 'regex') {
if (preg_match($filters, $file)) {
$files['filelist'][] = "$prefix$file";
}
} elseif ($filter_type === 'file') {
if (in_array(self::getExtension($file), $filters)) {
$files['filelist'][] = "$prefix$file";
}
} elseif (is_null($filter_type)) {
$files['filelist'][] = "$prefix$file";
}
}
if (is_array($files['filelist'])) {
($sort == 'desc') ? rsort($files['filelist']) : sort($files['filelist']);
}
return $files;
} | [
"public",
"static",
"function",
"listStructure",
"(",
"$",
"dir",
"=",
"\".\"",
",",
"$",
"filters",
"=",
"array",
"(",
")",
",",
"$",
"recurse",
"=",
"true",
",",
"$",
"sort",
"=",
"\"asc\"",
",",
"$",
"strip_root",
"=",
"null",
",",
"$",
"exclude",
"=",
"array",
"(",
")",
",",
"$",
"ignore_hidden",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"return",
"null",
";",
"}",
"// Check to see if $filters is a string containing a regex, or an array of file types",
"if",
"(",
"is_array",
"(",
"$",
"filters",
")",
"&&",
"!",
"empty",
"(",
"$",
"filters",
")",
")",
"{",
"$",
"filter_type",
"=",
"'file'",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"filters",
")",
")",
"{",
"$",
"filter_type",
"=",
"'regex'",
";",
"}",
"else",
"{",
"$",
"filter_type",
"=",
"null",
";",
"}",
"$",
"files",
"=",
"array",
"(",
")",
";",
"$",
"prefix",
"=",
"str_replace",
"(",
"$",
"strip_root",
",",
"''",
",",
"$",
"dir",
")",
";",
"if",
"(",
"$",
"prefix",
"!==",
"\"\"",
"&&",
"substr",
"(",
"$",
"prefix",
",",
"-",
"1",
")",
"!==",
"\"/\"",
")",
"{",
"$",
"prefix",
".=",
"\"/\"",
";",
"}",
"$",
"files",
"[",
"'dirlist'",
"]",
"=",
"array",
"(",
")",
";",
"$",
"files",
"[",
"'filelist'",
"]",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"scandir",
"(",
"$",
"dir",
")",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"(",
"$",
"file",
"==",
"'.'",
"||",
"$",
"file",
"===",
"'..'",
")",
"||",
"(",
"$",
"ignore_hidden",
"&&",
"$",
"file",
"{",
"0",
"}",
"===",
"'.'",
")",
"||",
"in_array",
"(",
"$",
"file",
",",
"$",
"exclude",
")",
"||",
"in_array",
"(",
"\"$dir/$file\"",
",",
"$",
"exclude",
")",
")",
"{",
"continue",
";",
"}",
"$",
"dir",
"=",
"rtrim",
"(",
"$",
"dir",
",",
"'/'",
")",
";",
"if",
"(",
"is_dir",
"(",
"\"$dir/$file\"",
")",
")",
"{",
"if",
"(",
"$",
"recurse",
")",
"{",
"$",
"files",
"[",
"\"$prefix$file/\"",
"]",
"=",
"self",
"::",
"listStructure",
"(",
"\"$dir/$file\"",
",",
"$",
"filters",
",",
"$",
"recurse",
",",
"$",
"sort",
",",
"$",
"strip_root",
",",
"$",
"exclude",
",",
"$",
"ignore_hidden",
")",
";",
"}",
"$",
"files",
"[",
"'dirlist'",
"]",
"[",
"]",
"=",
"\"$prefix$file/\"",
";",
"}",
"elseif",
"(",
"$",
"filter_type",
"===",
"'regex'",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"filters",
",",
"$",
"file",
")",
")",
"{",
"$",
"files",
"[",
"'filelist'",
"]",
"[",
"]",
"=",
"\"$prefix$file\"",
";",
"}",
"}",
"elseif",
"(",
"$",
"filter_type",
"===",
"'file'",
")",
"{",
"if",
"(",
"in_array",
"(",
"self",
"::",
"getExtension",
"(",
"$",
"file",
")",
",",
"$",
"filters",
")",
")",
"{",
"$",
"files",
"[",
"'filelist'",
"]",
"[",
"]",
"=",
"\"$prefix$file\"",
";",
"}",
"}",
"elseif",
"(",
"is_null",
"(",
"$",
"filter_type",
")",
")",
"{",
"$",
"files",
"[",
"'filelist'",
"]",
"[",
"]",
"=",
"\"$prefix$file\"",
";",
"}",
"}",
"if",
"(",
"is_array",
"(",
"$",
"files",
"[",
"'filelist'",
"]",
")",
")",
"{",
"(",
"$",
"sort",
"==",
"'desc'",
")",
"?",
"rsort",
"(",
"$",
"files",
"[",
"'filelist'",
"]",
")",
":",
"sort",
"(",
"$",
"files",
"[",
"'filelist'",
"]",
")",
";",
"}",
"return",
"$",
"files",
";",
"}"
] | Construct a multi-dimensional array that reflects the directory
structure of a given path grouped into directory and file keys
matching any input constraints.
@param string $dir (optional)
the path of the directory to construct the multi-dimensional array
for. this defaults to '.'.
@param array|string $filters (optional)
either a regular expression to filter the files by or an array of
files to include.
@param boolean $recurse (optional)
true if sub-directories should be traversed and reflected in the
resulting array, false otherwise.
@param string $sort (optional)
'asc' if the resulting filelist array should be sorted, anything else otherwise.
this defaults to 'asc'.
@param mixed $strip_root (optional)
If null, the full path to the file will be returned, otherwise the value
of `strip_root` will be removed from the file path.
@param array $exclude (optional)
ignore files listed in this array. this defaults to an empty array.
@param boolean $ignore_hidden (optional)
ignore hidden files (i.e. files that begin with a period). this defaults
to true.
@return null|array
return the array structure reflecting the input directory or null if
the input directory is not actually a directory. | [
"Construct",
"a",
"multi",
"-",
"dimensional",
"array",
"that",
"reflects",
"the",
"directory",
"structure",
"of",
"a",
"given",
"path",
"grouped",
"into",
"directory",
"and",
"file",
"keys",
"matching",
"any",
"input",
"constraints",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L1296-L1357 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.countWords | public static function countWords($string)
{
$string = strip_tags($string);
// Strip spaces:
$string = html_entity_decode($string, ENT_NOQUOTES, 'UTF-8');
$spaces = array(
' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ',
'​', '𠀯', ' '
);
foreach ($spaces as &$space) {
$space = html_entity_decode($space, ENT_NOQUOTES, 'UTF-8');
}
$string = str_replace($spaces, ' ', $string);
$string = preg_replace('/[^\w\s]/i', '', $string);
return str_word_count($string);
} | php | public static function countWords($string)
{
$string = strip_tags($string);
// Strip spaces:
$string = html_entity_decode($string, ENT_NOQUOTES, 'UTF-8');
$spaces = array(
' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ',
'​', '𠀯', ' '
);
foreach ($spaces as &$space) {
$space = html_entity_decode($space, ENT_NOQUOTES, 'UTF-8');
}
$string = str_replace($spaces, ' ', $string);
$string = preg_replace('/[^\w\s]/i', '', $string);
return str_word_count($string);
} | [
"public",
"static",
"function",
"countWords",
"(",
"$",
"string",
")",
"{",
"$",
"string",
"=",
"strip_tags",
"(",
"$",
"string",
")",
";",
"// Strip spaces:",
"$",
"string",
"=",
"html_entity_decode",
"(",
"$",
"string",
",",
"ENT_NOQUOTES",
",",
"'UTF-8'",
")",
";",
"$",
"spaces",
"=",
"array",
"(",
"' '",
",",
"' '",
",",
"' '",
",",
"' '",
",",
"' '",
",",
"' '",
",",
"' '",
",",
"' '",
",",
"'​'",
",",
"'𠀯'",
",",
"' '",
")",
";",
"foreach",
"(",
"$",
"spaces",
"as",
"&",
"$",
"space",
")",
"{",
"$",
"space",
"=",
"html_entity_decode",
"(",
"$",
"space",
",",
"ENT_NOQUOTES",
",",
"'UTF-8'",
")",
";",
"}",
"$",
"string",
"=",
"str_replace",
"(",
"$",
"spaces",
",",
"' '",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"preg_replace",
"(",
"'/[^\\w\\s]/i'",
",",
"''",
",",
"$",
"string",
")",
";",
"return",
"str_word_count",
"(",
"$",
"string",
")",
";",
"}"
] | Count the number of words in a string. Words are delimited by "spaces".
The characters included in the set of "spaces" are:
' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ',
'​', '𠀯', ' '
Any html/xml tags are first removed by strip_tags() and any included html
entities are decoded. The resulting string is then split by the above set
of spaces and the resulting size of the resulting array returned.
@param string $string
the string from which to count the contained words.
@return integer
the number of words contained in the input string. | [
"Count",
"the",
"number",
"of",
"words",
"in",
"a",
"string",
".",
"Words",
"are",
"delimited",
"by",
"spaces",
".",
"The",
"characters",
"included",
"in",
"the",
"set",
"of",
"spaces",
"are",
":",
" ",
";",
" ",
";",
" ",
";",
" ",
";",
" ",
";",
" ",
";",
" ",
";",
" ",
";",
"​",
";",
"𠀯",
";",
" ",
";",
"Any",
"html",
"/",
"xml",
"tags",
"are",
"first",
"removed",
"by",
"strip_tags",
"()",
"and",
"any",
"included",
"html",
"entities",
"are",
"decoded",
".",
"The",
"resulting",
"string",
"is",
"then",
"split",
"by",
"the",
"above",
"set",
"of",
"spaces",
"and",
"the",
"resulting",
"size",
"of",
"the",
"resulting",
"array",
"returned",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L1374-L1394 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.limitWords | public static function limitWords($string, $maxChars = 200, $appendHellip = false)
{
if ($appendHellip) {
$maxChars -= 1;
}
$string = trim(strip_tags(nl2br($string)));
$original_length = strlen($string);
if ($original_length == 0) {
return null;
} elseif ($original_length <= $maxChars) {
return $string;
}
// Compute the negative offset
$offset = $maxChars - $original_length;
// Find the first word break char before the maxChars limit is hit.
$last_word_break = max(array_filter(array_map(function ($wb) use ($string, $offset) {
return strrpos($string, $wb, $offset);
}, array(' ', '-', ',', '.', '!', '?', PHP_EOL))));
$result = substr($string, 0, $last_word_break);
if ($appendHellip) {
$result .= "…";
}
return $result;
} | php | public static function limitWords($string, $maxChars = 200, $appendHellip = false)
{
if ($appendHellip) {
$maxChars -= 1;
}
$string = trim(strip_tags(nl2br($string)));
$original_length = strlen($string);
if ($original_length == 0) {
return null;
} elseif ($original_length <= $maxChars) {
return $string;
}
// Compute the negative offset
$offset = $maxChars - $original_length;
// Find the first word break char before the maxChars limit is hit.
$last_word_break = max(array_filter(array_map(function ($wb) use ($string, $offset) {
return strrpos($string, $wb, $offset);
}, array(' ', '-', ',', '.', '!', '?', PHP_EOL))));
$result = substr($string, 0, $last_word_break);
if ($appendHellip) {
$result .= "…";
}
return $result;
} | [
"public",
"static",
"function",
"limitWords",
"(",
"$",
"string",
",",
"$",
"maxChars",
"=",
"200",
",",
"$",
"appendHellip",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"appendHellip",
")",
"{",
"$",
"maxChars",
"-=",
"1",
";",
"}",
"$",
"string",
"=",
"trim",
"(",
"strip_tags",
"(",
"nl2br",
"(",
"$",
"string",
")",
")",
")",
";",
"$",
"original_length",
"=",
"strlen",
"(",
"$",
"string",
")",
";",
"if",
"(",
"$",
"original_length",
"==",
"0",
")",
"{",
"return",
"null",
";",
"}",
"elseif",
"(",
"$",
"original_length",
"<=",
"$",
"maxChars",
")",
"{",
"return",
"$",
"string",
";",
"}",
"// Compute the negative offset",
"$",
"offset",
"=",
"$",
"maxChars",
"-",
"$",
"original_length",
";",
"// Find the first word break char before the maxChars limit is hit.",
"$",
"last_word_break",
"=",
"max",
"(",
"array_filter",
"(",
"array_map",
"(",
"function",
"(",
"$",
"wb",
")",
"use",
"(",
"$",
"string",
",",
"$",
"offset",
")",
"{",
"return",
"strrpos",
"(",
"$",
"string",
",",
"$",
"wb",
",",
"$",
"offset",
")",
";",
"}",
",",
"array",
"(",
"' '",
",",
"'-'",
",",
"','",
",",
"'.'",
",",
"'!'",
",",
"'?'",
",",
"PHP_EOL",
")",
")",
")",
")",
";",
"$",
"result",
"=",
"substr",
"(",
"$",
"string",
",",
"0",
",",
"$",
"last_word_break",
")",
";",
"if",
"(",
"$",
"appendHellip",
")",
"{",
"$",
"result",
".=",
"\"…\"",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Truncate a string to a given length, respecting word boundaries. The returned
string will always be less than `$maxChars`. Newlines, HTML elements and
leading or trailing spaces are removed from the string.
@param string $string
the string to truncate.
@param integer $maxChars (optional)
the maximum length of the string to truncate the input string to. this
defaults to 200 characters.
@param boolean $appendHellip (optional)
true if the ellipses should be appended to the result in circumstances
where the result is shorter than the input string. false otherwise. this
defaults to false.
@return null|string
if the resulting string contains only spaces then null is returned. otherwise
a string that satisfies the input constraints. | [
"Truncate",
"a",
"string",
"to",
"a",
"given",
"length",
"respecting",
"word",
"boundaries",
".",
"The",
"returned",
"string",
"will",
"always",
"be",
"less",
"than",
"$maxChars",
".",
"Newlines",
"HTML",
"elements",
"and",
"leading",
"or",
"trailing",
"spaces",
"are",
"removed",
"from",
"the",
"string",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L1414-L1442 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.uploadFile | public static function uploadFile($dest_path, $dest_name, $tmp_name, $perm = 0644)
{
// Upload the file
if (@is_uploaded_file($tmp_name)) {
$dest_path = rtrim($dest_path, '/') . '/';
$dest = $dest_path . $dest_name;
// Check that destination is writable
if (!static::checkFileWritable($dest)) {
return false;
}
// Try place the file in the correction location
if (@move_uploaded_file($tmp_name, $dest)) {
if (is_null($perm)) {
$perm = 0644;
}
@chmod($dest, intval($perm, 8));
return true;
}
}
// Could not move the file
return false;
} | php | public static function uploadFile($dest_path, $dest_name, $tmp_name, $perm = 0644)
{
// Upload the file
if (@is_uploaded_file($tmp_name)) {
$dest_path = rtrim($dest_path, '/') . '/';
$dest = $dest_path . $dest_name;
// Check that destination is writable
if (!static::checkFileWritable($dest)) {
return false;
}
// Try place the file in the correction location
if (@move_uploaded_file($tmp_name, $dest)) {
if (is_null($perm)) {
$perm = 0644;
}
@chmod($dest, intval($perm, 8));
return true;
}
}
// Could not move the file
return false;
} | [
"public",
"static",
"function",
"uploadFile",
"(",
"$",
"dest_path",
",",
"$",
"dest_name",
",",
"$",
"tmp_name",
",",
"$",
"perm",
"=",
"0644",
")",
"{",
"// Upload the file",
"if",
"(",
"@",
"is_uploaded_file",
"(",
"$",
"tmp_name",
")",
")",
"{",
"$",
"dest_path",
"=",
"rtrim",
"(",
"$",
"dest_path",
",",
"'/'",
")",
".",
"'/'",
";",
"$",
"dest",
"=",
"$",
"dest_path",
".",
"$",
"dest_name",
";",
"// Check that destination is writable",
"if",
"(",
"!",
"static",
"::",
"checkFileWritable",
"(",
"$",
"dest",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Try place the file in the correction location",
"if",
"(",
"@",
"move_uploaded_file",
"(",
"$",
"tmp_name",
",",
"$",
"dest",
")",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"perm",
")",
")",
"{",
"$",
"perm",
"=",
"0644",
";",
"}",
"@",
"chmod",
"(",
"$",
"dest",
",",
"intval",
"(",
"$",
"perm",
",",
"8",
")",
")",
";",
"return",
"true",
";",
"}",
"}",
"// Could not move the file",
"return",
"false",
";",
"}"
] | Move a file from the source path to the destination path and name and
set its permissions to the input permissions. This will ignore errors
in the `is_uploaded_file()`, `move_uploaded_file()` and `chmod()` functions.
@uses General::checkFileWritable()
@param string $dest_path
the file path to which the source file is to be moved.
@param string $dest_name
the file name within the file path to which the source file is to be moved.
@param string $tmp_name
the full path name of the source file to move.
@param integer|string $perm (optional)
the permissions to apply to the moved file. this defaults to 0644 @since
Symphony 2.7.0. It was 0777 in 2.6.x and less.
@return boolean
true if the file was moved and its permissions set as required. false otherwise. | [
"Move",
"a",
"file",
"from",
"the",
"source",
"path",
"to",
"the",
"destination",
"path",
"and",
"name",
"and",
"set",
"its",
"permissions",
"to",
"the",
"input",
"permissions",
".",
"This",
"will",
"ignore",
"errors",
"in",
"the",
"is_uploaded_file",
"()",
"move_uploaded_file",
"()",
"and",
"chmod",
"()",
"functions",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L1462-L1485 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.formatFilesize | public static function formatFilesize($file_size)
{
$file_size = intval($file_size);
if ($file_size >= (1024 * 1024)) {
$file_size = number_format($file_size * (1 / (1024 * 1024)), 2) . ' MB';
} elseif ($file_size >= 1024) {
$file_size = intval($file_size * (1/1024)) . ' KB';
} else {
$file_size = intval($file_size) . ' bytes';
}
return $file_size;
} | php | public static function formatFilesize($file_size)
{
$file_size = intval($file_size);
if ($file_size >= (1024 * 1024)) {
$file_size = number_format($file_size * (1 / (1024 * 1024)), 2) . ' MB';
} elseif ($file_size >= 1024) {
$file_size = intval($file_size * (1/1024)) . ' KB';
} else {
$file_size = intval($file_size) . ' bytes';
}
return $file_size;
} | [
"public",
"static",
"function",
"formatFilesize",
"(",
"$",
"file_size",
")",
"{",
"$",
"file_size",
"=",
"intval",
"(",
"$",
"file_size",
")",
";",
"if",
"(",
"$",
"file_size",
">=",
"(",
"1024",
"*",
"1024",
")",
")",
"{",
"$",
"file_size",
"=",
"number_format",
"(",
"$",
"file_size",
"*",
"(",
"1",
"/",
"(",
"1024",
"*",
"1024",
")",
")",
",",
"2",
")",
".",
"' MB'",
";",
"}",
"elseif",
"(",
"$",
"file_size",
">=",
"1024",
")",
"{",
"$",
"file_size",
"=",
"intval",
"(",
"$",
"file_size",
"*",
"(",
"1",
"/",
"1024",
")",
")",
".",
"' KB'",
";",
"}",
"else",
"{",
"$",
"file_size",
"=",
"intval",
"(",
"$",
"file_size",
")",
".",
"' bytes'",
";",
"}",
"return",
"$",
"file_size",
";",
"}"
] | Format a number of bytes in human readable format. This will append MB as
appropriate for values greater than 1,024*1,024, KB for values between
1,024 and 1,024*1,024-1 and bytes for values between 0 and 1,024.
@param integer $file_size
the number to format.
@return string
the formatted number. | [
"Format",
"a",
"number",
"of",
"bytes",
"in",
"human",
"readable",
"format",
".",
"This",
"will",
"append",
"MB",
"as",
"appropriate",
"for",
"values",
"greater",
"than",
"1",
"024",
"*",
"1",
"024",
"KB",
"for",
"values",
"between",
"1",
"024",
"and",
"1",
"024",
"*",
"1",
"024",
"-",
"1",
"and",
"bytes",
"for",
"values",
"between",
"0",
"and",
"1",
"024",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L1497-L1510 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.convertHumanFileSizeToBytes | public static function convertHumanFileSizeToBytes($file_size)
{
$file_size = str_replace(
array(' MB', ' KB', ' bytes'),
array('M', 'K', 'B'),
trim($file_size)
);
$last = strtolower($file_size[strlen($file_size)-1]);
$file_size = (int) $file_size;
switch ($last) {
case 'g':
$file_size *= 1024;
case 'm':
$file_size *= 1024;
case 'k':
$file_size *= 1024;
}
return $file_size;
} | php | public static function convertHumanFileSizeToBytes($file_size)
{
$file_size = str_replace(
array(' MB', ' KB', ' bytes'),
array('M', 'K', 'B'),
trim($file_size)
);
$last = strtolower($file_size[strlen($file_size)-1]);
$file_size = (int) $file_size;
switch ($last) {
case 'g':
$file_size *= 1024;
case 'm':
$file_size *= 1024;
case 'k':
$file_size *= 1024;
}
return $file_size;
} | [
"public",
"static",
"function",
"convertHumanFileSizeToBytes",
"(",
"$",
"file_size",
")",
"{",
"$",
"file_size",
"=",
"str_replace",
"(",
"array",
"(",
"' MB'",
",",
"' KB'",
",",
"' bytes'",
")",
",",
"array",
"(",
"'M'",
",",
"'K'",
",",
"'B'",
")",
",",
"trim",
"(",
"$",
"file_size",
")",
")",
";",
"$",
"last",
"=",
"strtolower",
"(",
"$",
"file_size",
"[",
"strlen",
"(",
"$",
"file_size",
")",
"-",
"1",
"]",
")",
";",
"$",
"file_size",
"=",
"(",
"int",
")",
"$",
"file_size",
";",
"switch",
"(",
"$",
"last",
")",
"{",
"case",
"'g'",
":",
"$",
"file_size",
"*=",
"1024",
";",
"case",
"'m'",
":",
"$",
"file_size",
"*=",
"1024",
";",
"case",
"'k'",
":",
"$",
"file_size",
"*=",
"1024",
";",
"}",
"return",
"$",
"file_size",
";",
"}"
] | Gets the number of bytes from 'human readable' size value. Supports
the output of `General::formatFilesize` as well as reading values
from the PHP configuration. eg. 1 MB or 1M
@since Symphony 2.5.2
@param string $file_size
@return integer | [
"Gets",
"the",
"number",
"of",
"bytes",
"from",
"human",
"readable",
"size",
"value",
".",
"Supports",
"the",
"output",
"of",
"General",
"::",
"formatFilesize",
"as",
"well",
"as",
"reading",
"values",
"from",
"the",
"PHP",
"configuration",
".",
"eg",
".",
"1",
"MB",
"or",
"1M"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L1521-L1543 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.createXMLDateObject | public static function createXMLDateObject($timestamp, $element = 'date', $date_format = 'Y-m-d', $time_format = 'H:i', $namespace = null)
{
if (!class_exists('XMLElement')) {
return false;
}
if (empty($date_format)) {
$date_format = DateTimeObj::getSetting('date_format');
}
if (empty($time_format)) {
$time_format = DateTimeObj::getSetting('time_format');
}
$xDate = new XMLElement(
(!is_null($namespace) ? $namespace . ':' : '') . $element,
DateTimeObj::get($date_format, $timestamp),
array(
'iso' => DateTimeObj::get('c', $timestamp),
'timestamp' => DateTimeObj::get('U', $timestamp),
'time' => DateTimeObj::get($time_format, $timestamp),
'weekday' => DateTimeObj::get('N', $timestamp),
'offset' => DateTimeObj::get('O', $timestamp)
)
);
return $xDate;
} | php | public static function createXMLDateObject($timestamp, $element = 'date', $date_format = 'Y-m-d', $time_format = 'H:i', $namespace = null)
{
if (!class_exists('XMLElement')) {
return false;
}
if (empty($date_format)) {
$date_format = DateTimeObj::getSetting('date_format');
}
if (empty($time_format)) {
$time_format = DateTimeObj::getSetting('time_format');
}
$xDate = new XMLElement(
(!is_null($namespace) ? $namespace . ':' : '') . $element,
DateTimeObj::get($date_format, $timestamp),
array(
'iso' => DateTimeObj::get('c', $timestamp),
'timestamp' => DateTimeObj::get('U', $timestamp),
'time' => DateTimeObj::get($time_format, $timestamp),
'weekday' => DateTimeObj::get('N', $timestamp),
'offset' => DateTimeObj::get('O', $timestamp)
)
);
return $xDate;
} | [
"public",
"static",
"function",
"createXMLDateObject",
"(",
"$",
"timestamp",
",",
"$",
"element",
"=",
"'date'",
",",
"$",
"date_format",
"=",
"'Y-m-d'",
",",
"$",
"time_format",
"=",
"'H:i'",
",",
"$",
"namespace",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"'XMLElement'",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"date_format",
")",
")",
"{",
"$",
"date_format",
"=",
"DateTimeObj",
"::",
"getSetting",
"(",
"'date_format'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"time_format",
")",
")",
"{",
"$",
"time_format",
"=",
"DateTimeObj",
"::",
"getSetting",
"(",
"'time_format'",
")",
";",
"}",
"$",
"xDate",
"=",
"new",
"XMLElement",
"(",
"(",
"!",
"is_null",
"(",
"$",
"namespace",
")",
"?",
"$",
"namespace",
".",
"':'",
":",
"''",
")",
".",
"$",
"element",
",",
"DateTimeObj",
"::",
"get",
"(",
"$",
"date_format",
",",
"$",
"timestamp",
")",
",",
"array",
"(",
"'iso'",
"=>",
"DateTimeObj",
"::",
"get",
"(",
"'c'",
",",
"$",
"timestamp",
")",
",",
"'timestamp'",
"=>",
"DateTimeObj",
"::",
"get",
"(",
"'U'",
",",
"$",
"timestamp",
")",
",",
"'time'",
"=>",
"DateTimeObj",
"::",
"get",
"(",
"$",
"time_format",
",",
"$",
"timestamp",
")",
",",
"'weekday'",
"=>",
"DateTimeObj",
"::",
"get",
"(",
"'N'",
",",
"$",
"timestamp",
")",
",",
"'offset'",
"=>",
"DateTimeObj",
"::",
"get",
"(",
"'O'",
",",
"$",
"timestamp",
")",
")",
")",
";",
"return",
"$",
"xDate",
";",
"}"
] | Construct an XML fragment that reflects the structure of the input timestamp.
@param integer $timestamp
the timestamp to construct the XML element from.
@param string $element (optional)
the name of the element to append to the namespace of the constructed XML.
this defaults to "date".
@param string $date_format (optional)
the format to apply to the date, defaults to `Y-m-d`.
if empty, uses DateTimeObj settings.
@param string $time_format (optional)
the format to apply to the date, defaults to `H:i`.
if empty, uses DateTimeObj settings.
@param string $namespace (optional)
the namespace in which the resulting XML entity will reside. this defaults
to null.
@return boolean|XMLElement
false if there is no XMLElement class on the system, the constructed XML element
otherwise. | [
"Construct",
"an",
"XML",
"fragment",
"that",
"reflects",
"the",
"structure",
"of",
"the",
"input",
"timestamp",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L1566-L1592 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.buildPaginationElement | public static function buildPaginationElement($total_entries = 0, $total_pages = 0, $entries_per_page = 1, $current_page = 1)
{
$pageinfo = new XMLElement('pagination');
$pageinfo->setAttribute('total-entries', $total_entries);
$pageinfo->setAttribute('total-pages', $total_pages);
$pageinfo->setAttribute('entries-per-page', $entries_per_page);
$pageinfo->setAttribute('current-page', $current_page);
return $pageinfo;
} | php | public static function buildPaginationElement($total_entries = 0, $total_pages = 0, $entries_per_page = 1, $current_page = 1)
{
$pageinfo = new XMLElement('pagination');
$pageinfo->setAttribute('total-entries', $total_entries);
$pageinfo->setAttribute('total-pages', $total_pages);
$pageinfo->setAttribute('entries-per-page', $entries_per_page);
$pageinfo->setAttribute('current-page', $current_page);
return $pageinfo;
} | [
"public",
"static",
"function",
"buildPaginationElement",
"(",
"$",
"total_entries",
"=",
"0",
",",
"$",
"total_pages",
"=",
"0",
",",
"$",
"entries_per_page",
"=",
"1",
",",
"$",
"current_page",
"=",
"1",
")",
"{",
"$",
"pageinfo",
"=",
"new",
"XMLElement",
"(",
"'pagination'",
")",
";",
"$",
"pageinfo",
"->",
"setAttribute",
"(",
"'total-entries'",
",",
"$",
"total_entries",
")",
";",
"$",
"pageinfo",
"->",
"setAttribute",
"(",
"'total-pages'",
",",
"$",
"total_pages",
")",
";",
"$",
"pageinfo",
"->",
"setAttribute",
"(",
"'entries-per-page'",
",",
"$",
"entries_per_page",
")",
";",
"$",
"pageinfo",
"->",
"setAttribute",
"(",
"'current-page'",
",",
"$",
"current_page",
")",
";",
"return",
"$",
"pageinfo",
";",
"}"
] | Construct an XML fragment that describes a pagination structure.
@param integer $total_entries (optional)
the total number of entries that this structure is paginating. this
defaults to 0.
@param integer $total_pages (optional)
the total number of pages within the pagination structure. this defaults
to 0.
@param integer $entries_per_page (optional)
the number of entries per page. this defaults to 1.
@param integer $current_page (optional)
the current page within the total number of pages within this pagination
structure. this defaults to 1.
@return XMLElement
the constructed XML fragment. | [
"Construct",
"an",
"XML",
"fragment",
"that",
"describes",
"a",
"pagination",
"structure",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L1611-L1621 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.hash | public static function hash($input, $algorithm = 'sha1')
{
switch ($algorithm) {
case 'sha1':
return SHA1::hash($input);
case 'md5':
return MD5::hash($input);
case 'pbkdf2':
default:
return Crytography::hash($input, $algorithm);
}
} | php | public static function hash($input, $algorithm = 'sha1')
{
switch ($algorithm) {
case 'sha1':
return SHA1::hash($input);
case 'md5':
return MD5::hash($input);
case 'pbkdf2':
default:
return Crytography::hash($input, $algorithm);
}
} | [
"public",
"static",
"function",
"hash",
"(",
"$",
"input",
",",
"$",
"algorithm",
"=",
"'sha1'",
")",
"{",
"switch",
"(",
"$",
"algorithm",
")",
"{",
"case",
"'sha1'",
":",
"return",
"SHA1",
"::",
"hash",
"(",
"$",
"input",
")",
";",
"case",
"'md5'",
":",
"return",
"MD5",
"::",
"hash",
"(",
"$",
"input",
")",
";",
"case",
"'pbkdf2'",
":",
"default",
":",
"return",
"Crytography",
"::",
"hash",
"(",
"$",
"input",
",",
"$",
"algorithm",
")",
";",
"}",
"}"
] | Uses `SHA1` or `MD5` to create a hash based on some input
This function is currently very basic, but would allow
future expansion. Salting the hash comes to mind.
@param string $input
the string to be hashed
@param string $algorithm
This function supports 'md5', 'sha1' and 'pbkdf2'. Any
other algorithm will default to 'pbkdf2'.
@return string
the hashed string | [
"Uses",
"SHA1",
"or",
"MD5",
"to",
"create",
"a",
"hash",
"based",
"on",
"some",
"input",
"This",
"function",
"is",
"currently",
"very",
"basic",
"but",
"would",
"allow",
"future",
"expansion",
".",
"Salting",
"the",
"hash",
"comes",
"to",
"mind",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L1636-L1649 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.ensureType | public static function ensureType(array $params)
{
foreach ($params as $name => $param) {
if (isset($param['optional']) && ($param['optional'] === true)) {
if (is_null($param['var'])) {
continue;
}
// if not null, check it's type
}
// validate the validator
$validator = 'is_'.$param['type'];
if (!function_exists($validator)) {
throw new InvalidArgumentException(__('Enforced type `%1$s` for argument `$%2$s` does not match any known variable types.', array($param['type'], $name)));
}
// validate variable type
if (!call_user_func($validator, $param['var'])) {
throw new InvalidArgumentException(__('Argument `$%1$s` is not of type `%2$s`, given `%3$s`.', array($name, $param['type'], gettype($param['var']))));
}
}
} | php | public static function ensureType(array $params)
{
foreach ($params as $name => $param) {
if (isset($param['optional']) && ($param['optional'] === true)) {
if (is_null($param['var'])) {
continue;
}
// if not null, check it's type
}
// validate the validator
$validator = 'is_'.$param['type'];
if (!function_exists($validator)) {
throw new InvalidArgumentException(__('Enforced type `%1$s` for argument `$%2$s` does not match any known variable types.', array($param['type'], $name)));
}
// validate variable type
if (!call_user_func($validator, $param['var'])) {
throw new InvalidArgumentException(__('Argument `$%1$s` is not of type `%2$s`, given `%3$s`.', array($name, $param['type'], gettype($param['var']))));
}
}
} | [
"public",
"static",
"function",
"ensureType",
"(",
"array",
"$",
"params",
")",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"name",
"=>",
"$",
"param",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"param",
"[",
"'optional'",
"]",
")",
"&&",
"(",
"$",
"param",
"[",
"'optional'",
"]",
"===",
"true",
")",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"param",
"[",
"'var'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"// if not null, check it's type",
"}",
"// validate the validator",
"$",
"validator",
"=",
"'is_'",
".",
"$",
"param",
"[",
"'type'",
"]",
";",
"if",
"(",
"!",
"function_exists",
"(",
"$",
"validator",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"__",
"(",
"'Enforced type `%1$s` for argument `$%2$s` does not match any known variable types.'",
",",
"array",
"(",
"$",
"param",
"[",
"'type'",
"]",
",",
"$",
"name",
")",
")",
")",
";",
"}",
"// validate variable type",
"if",
"(",
"!",
"call_user_func",
"(",
"$",
"validator",
",",
"$",
"param",
"[",
"'var'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"__",
"(",
"'Argument `$%1$s` is not of type `%2$s`, given `%3$s`.'",
",",
"array",
"(",
"$",
"name",
",",
"$",
"param",
"[",
"'type'",
"]",
",",
"gettype",
"(",
"$",
"param",
"[",
"'var'",
"]",
")",
")",
")",
")",
";",
"}",
"}",
"}"
] | Helper to cut down on variables' type check.
Currently known types are the PHP defaults.
Uses `is_XXX()` functions internally.
@since Symphony 2.3
@param array $params - an array of arrays containing variables info
Array[
$key1 => $value1
$key2 => $value2
...
]
$key = the name of the variable
$value = Array[
'var' => the variable to check
'type' => enforced type. Must match the XXX part from an `is_XXX()` function
'optional' => boolean. If this is set, the default value of the variable must be null
]
@throws InvalidArgumentException if validator doesn't exist.
@throws InvalidArgumentException if variable type validation fails.
@example
$color = 'red';
$foo = null;
$bar = 21;
General::ensureType(array(
'color' => array('var' => $color, 'type'=> 'string'), // success
'foo' => array('var' => $foo, 'type'=> 'int', 'optional' => true), // success
'bar' => array('var' => $bar, 'type'=> 'string') // fail
)); | [
"Helper",
"to",
"cut",
"down",
"on",
"variables",
"type",
"check",
".",
"Currently",
"known",
"types",
"are",
"the",
"PHP",
"defaults",
".",
"Uses",
"is_XXX",
"()",
"functions",
"internally",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L1687-L1709 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.general.php | General.wrapInCDATA | public static function wrapInCDATA($value)
{
if (empty($value)) {
return $value;
}
$startRegExp = '/^' . preg_quote(CDATA_BEGIN) . '/';
$endRegExp = '/' . preg_quote(CDATA_END) . '$/';
if (!preg_match($startRegExp, $value)) {
$value = CDATA_BEGIN . $value;
}
if (!preg_match($endRegExp, $value)) {
$value .= CDATA_END;
}
return $value;
} | php | public static function wrapInCDATA($value)
{
if (empty($value)) {
return $value;
}
$startRegExp = '/^' . preg_quote(CDATA_BEGIN) . '/';
$endRegExp = '/' . preg_quote(CDATA_END) . '$/';
if (!preg_match($startRegExp, $value)) {
$value = CDATA_BEGIN . $value;
}
if (!preg_match($endRegExp, $value)) {
$value .= CDATA_END;
}
return $value;
} | [
"public",
"static",
"function",
"wrapInCDATA",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"$",
"startRegExp",
"=",
"'/^'",
".",
"preg_quote",
"(",
"CDATA_BEGIN",
")",
".",
"'/'",
";",
"$",
"endRegExp",
"=",
"'/'",
".",
"preg_quote",
"(",
"CDATA_END",
")",
".",
"'$/'",
";",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"startRegExp",
",",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"CDATA_BEGIN",
".",
"$",
"value",
";",
"}",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"endRegExp",
",",
"$",
"value",
")",
")",
"{",
"$",
"value",
".=",
"CDATA_END",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Wrap a value in CDATA tags for XSL output of non encoded data, only
if not already wrapped.
@since Symphony 2.3.2
@param string $value
The string to wrap in CDATA
@return string
The wrapped string | [
"Wrap",
"a",
"value",
"in",
"CDATA",
"tags",
"for",
"XSL",
"output",
"of",
"non",
"encoded",
"data",
"only",
"if",
"not",
"already",
"wrapped",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.general.php#L1723-L1741 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.authormanager.php | AuthorManager.add | public static function add(array $fields)
{
if (!Symphony::Database()->insert($fields, 'tbl_authors')) {
return false;
}
$author_id = Symphony::Database()->getInsertID();
return $author_id;
} | php | public static function add(array $fields)
{
if (!Symphony::Database()->insert($fields, 'tbl_authors')) {
return false;
}
$author_id = Symphony::Database()->getInsertID();
return $author_id;
} | [
"public",
"static",
"function",
"add",
"(",
"array",
"$",
"fields",
")",
"{",
"if",
"(",
"!",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"insert",
"(",
"$",
"fields",
",",
"'tbl_authors'",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"author_id",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"getInsertID",
"(",
")",
";",
"return",
"$",
"author_id",
";",
"}"
] | Given an associative array of fields, insert them into the database
returning the resulting Author ID if successful, or false if there
was an error
@param array $fields
Associative array of field names => values for the Author object
@throws DatabaseException
@return integer|boolean
Returns an Author ID of the created Author on success, false otherwise. | [
"Given",
"an",
"associative",
"array",
"of",
"fields",
"insert",
"them",
"into",
"the",
"database",
"returning",
"the",
"resulting",
"Author",
"ID",
"if",
"successful",
"or",
"false",
"if",
"there",
"was",
"an",
"error"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.authormanager.php#L33-L42 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.authormanager.php | AuthorManager.fetch | public static function fetch($sortby = 'id', $sortdirection = 'ASC', $limit = null, $start = null, $where = null, $joins = null)
{
$sortby = is_null($sortby) ? 'id' : Symphony::Database()->cleanValue($sortby);
$sortdirection = $sortdirection === 'ASC' ? 'ASC' : 'DESC';
$records = Symphony::Database()->fetch(sprintf(
"SELECT a.*
FROM `tbl_authors` AS `a`
%s
WHERE %s
ORDER BY %s %s
%s %s",
$joins,
($where) ? $where : 1,
'a.'. $sortby,
$sortdirection,
($limit) ? sprintf("LIMIT %d", $limit) : '',
($start && $limit) ? ', ' . $start : ''
));
if (!is_array($records) || empty($records)) {
return array();
}
$authors = array();
foreach ($records as $row) {
$author = new Author;
foreach ($row as $field => $val) {
$author->set($field, $val);
}
self::$_pool[$author->get('id')] = $author;
$authors[] = $author;
}
return $authors;
} | php | public static function fetch($sortby = 'id', $sortdirection = 'ASC', $limit = null, $start = null, $where = null, $joins = null)
{
$sortby = is_null($sortby) ? 'id' : Symphony::Database()->cleanValue($sortby);
$sortdirection = $sortdirection === 'ASC' ? 'ASC' : 'DESC';
$records = Symphony::Database()->fetch(sprintf(
"SELECT a.*
FROM `tbl_authors` AS `a`
%s
WHERE %s
ORDER BY %s %s
%s %s",
$joins,
($where) ? $where : 1,
'a.'. $sortby,
$sortdirection,
($limit) ? sprintf("LIMIT %d", $limit) : '',
($start && $limit) ? ', ' . $start : ''
));
if (!is_array($records) || empty($records)) {
return array();
}
$authors = array();
foreach ($records as $row) {
$author = new Author;
foreach ($row as $field => $val) {
$author->set($field, $val);
}
self::$_pool[$author->get('id')] = $author;
$authors[] = $author;
}
return $authors;
} | [
"public",
"static",
"function",
"fetch",
"(",
"$",
"sortby",
"=",
"'id'",
",",
"$",
"sortdirection",
"=",
"'ASC'",
",",
"$",
"limit",
"=",
"null",
",",
"$",
"start",
"=",
"null",
",",
"$",
"where",
"=",
"null",
",",
"$",
"joins",
"=",
"null",
")",
"{",
"$",
"sortby",
"=",
"is_null",
"(",
"$",
"sortby",
")",
"?",
"'id'",
":",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"cleanValue",
"(",
"$",
"sortby",
")",
";",
"$",
"sortdirection",
"=",
"$",
"sortdirection",
"===",
"'ASC'",
"?",
"'ASC'",
":",
"'DESC'",
";",
"$",
"records",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetch",
"(",
"sprintf",
"(",
"\"SELECT a.*\n FROM `tbl_authors` AS `a`\n %s\n WHERE %s\n ORDER BY %s %s\n %s %s\"",
",",
"$",
"joins",
",",
"(",
"$",
"where",
")",
"?",
"$",
"where",
":",
"1",
",",
"'a.'",
".",
"$",
"sortby",
",",
"$",
"sortdirection",
",",
"(",
"$",
"limit",
")",
"?",
"sprintf",
"(",
"\"LIMIT %d\"",
",",
"$",
"limit",
")",
":",
"''",
",",
"(",
"$",
"start",
"&&",
"$",
"limit",
")",
"?",
"', '",
".",
"$",
"start",
":",
"''",
")",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"records",
")",
"||",
"empty",
"(",
"$",
"records",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"authors",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"row",
")",
"{",
"$",
"author",
"=",
"new",
"Author",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"field",
"=>",
"$",
"val",
")",
"{",
"$",
"author",
"->",
"set",
"(",
"$",
"field",
",",
"$",
"val",
")",
";",
"}",
"self",
"::",
"$",
"_pool",
"[",
"$",
"author",
"->",
"get",
"(",
"'id'",
")",
"]",
"=",
"$",
"author",
";",
"$",
"authors",
"[",
"]",
"=",
"$",
"author",
";",
"}",
"return",
"$",
"authors",
";",
"}"
] | The fetch method returns all Authors from Symphony with the option to sort
or limit the output. This method returns an array of Author objects.
@param string $sortby
The field to sort the authors by, defaults to 'id'
@param string $sortdirection
Available values of ASC (Ascending) or DESC (Descending), which refer to the
sort order for the query. Defaults to ASC (Ascending)
@param integer $limit
The number of rows to return
@param integer $start
The offset start point for limiting, maps to the LIMIT {x}, {y} MySQL functionality
@param string $where
Any custom WHERE clauses. The `tbl_authors` alias is `a`
@param string $joins
Any custom JOIN's
@throws DatabaseException
@return array
An array of Author objects. If no Authors are found, an empty array is returned. | [
"The",
"fetch",
"method",
"returns",
"all",
"Authors",
"from",
"Symphony",
"with",
"the",
"option",
"to",
"sort",
"or",
"limit",
"the",
"output",
".",
"This",
"method",
"returns",
"an",
"array",
"of",
"Author",
"objects",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.authormanager.php#L102-L140 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.authormanager.php | AuthorManager.fetchByID | public static function fetchByID($id)
{
$return_single = false;
if (is_null($id)) {
return null;
}
if (!is_array($id)) {
$return_single = true;
$id = array((int)$id);
}
if (empty($id)) {
return null;
}
// Get all the Author ID's that are already in `self::$_pool`
$authors = array();
$pooled_authors = array_intersect($id, array_keys(self::$_pool));
foreach ($pooled_authors as $pool_author) {
$authors[] = self::$_pool[$pool_author];
}
// Get all the Author ID's that are not already stored in `self::$_pool`
$id = array_diff($id, array_keys(self::$_pool));
$id = array_filter($id);
if (empty($id)) {
return ($return_single ? $authors[0] : $authors);
}
$records = Symphony::Database()->fetch(sprintf(
"SELECT *
FROM `tbl_authors`
WHERE `id` IN (%s)",
implode(",", $id)
));
if (!is_array($records) || empty($records)) {
return ($return_single ? $authors[0] : $authors);
}
foreach ($records as $row) {
$author = new Author;
foreach ($row as $field => $val) {
$author->set($field, $val);
}
self::$_pool[$author->get('id')] = $author;
$authors[] = $author;
}
return ($return_single ? $authors[0] : $authors);
} | php | public static function fetchByID($id)
{
$return_single = false;
if (is_null($id)) {
return null;
}
if (!is_array($id)) {
$return_single = true;
$id = array((int)$id);
}
if (empty($id)) {
return null;
}
// Get all the Author ID's that are already in `self::$_pool`
$authors = array();
$pooled_authors = array_intersect($id, array_keys(self::$_pool));
foreach ($pooled_authors as $pool_author) {
$authors[] = self::$_pool[$pool_author];
}
// Get all the Author ID's that are not already stored in `self::$_pool`
$id = array_diff($id, array_keys(self::$_pool));
$id = array_filter($id);
if (empty($id)) {
return ($return_single ? $authors[0] : $authors);
}
$records = Symphony::Database()->fetch(sprintf(
"SELECT *
FROM `tbl_authors`
WHERE `id` IN (%s)",
implode(",", $id)
));
if (!is_array($records) || empty($records)) {
return ($return_single ? $authors[0] : $authors);
}
foreach ($records as $row) {
$author = new Author;
foreach ($row as $field => $val) {
$author->set($field, $val);
}
self::$_pool[$author->get('id')] = $author;
$authors[] = $author;
}
return ($return_single ? $authors[0] : $authors);
} | [
"public",
"static",
"function",
"fetchByID",
"(",
"$",
"id",
")",
"{",
"$",
"return_single",
"=",
"false",
";",
"if",
"(",
"is_null",
"(",
"$",
"id",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"id",
")",
")",
"{",
"$",
"return_single",
"=",
"true",
";",
"$",
"id",
"=",
"array",
"(",
"(",
"int",
")",
"$",
"id",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"return",
"null",
";",
"}",
"// Get all the Author ID's that are already in `self::$_pool`",
"$",
"authors",
"=",
"array",
"(",
")",
";",
"$",
"pooled_authors",
"=",
"array_intersect",
"(",
"$",
"id",
",",
"array_keys",
"(",
"self",
"::",
"$",
"_pool",
")",
")",
";",
"foreach",
"(",
"$",
"pooled_authors",
"as",
"$",
"pool_author",
")",
"{",
"$",
"authors",
"[",
"]",
"=",
"self",
"::",
"$",
"_pool",
"[",
"$",
"pool_author",
"]",
";",
"}",
"// Get all the Author ID's that are not already stored in `self::$_pool`",
"$",
"id",
"=",
"array_diff",
"(",
"$",
"id",
",",
"array_keys",
"(",
"self",
"::",
"$",
"_pool",
")",
")",
";",
"$",
"id",
"=",
"array_filter",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"return",
"(",
"$",
"return_single",
"?",
"$",
"authors",
"[",
"0",
"]",
":",
"$",
"authors",
")",
";",
"}",
"$",
"records",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetch",
"(",
"sprintf",
"(",
"\"SELECT *\n FROM `tbl_authors`\n WHERE `id` IN (%s)\"",
",",
"implode",
"(",
"\",\"",
",",
"$",
"id",
")",
")",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"records",
")",
"||",
"empty",
"(",
"$",
"records",
")",
")",
"{",
"return",
"(",
"$",
"return_single",
"?",
"$",
"authors",
"[",
"0",
"]",
":",
"$",
"authors",
")",
";",
"}",
"foreach",
"(",
"$",
"records",
"as",
"$",
"row",
")",
"{",
"$",
"author",
"=",
"new",
"Author",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"field",
"=>",
"$",
"val",
")",
"{",
"$",
"author",
"->",
"set",
"(",
"$",
"field",
",",
"$",
"val",
")",
";",
"}",
"self",
"::",
"$",
"_pool",
"[",
"$",
"author",
"->",
"get",
"(",
"'id'",
")",
"]",
"=",
"$",
"author",
";",
"$",
"authors",
"[",
"]",
"=",
"$",
"author",
";",
"}",
"return",
"(",
"$",
"return_single",
"?",
"$",
"authors",
"[",
"0",
"]",
":",
"$",
"authors",
")",
";",
"}"
] | Returns Author's that match the provided ID's with the option to
sort or limit the output. This function will search the
`AuthorManager::$_pool` for Authors first before querying `tbl_authors`
@param integer|array $id
A single ID or an array of ID's
@throws DatabaseException
@return mixed
If `$id` is an integer, the result will be an Author object,
otherwise an array of Author objects will be returned. If no
Authors are found, or no `$id` is given, `null` is returned. | [
"Returns",
"Author",
"s",
"that",
"match",
"the",
"provided",
"ID",
"s",
"with",
"the",
"option",
"to",
"sort",
"or",
"limit",
"the",
"output",
".",
"This",
"function",
"will",
"search",
"the",
"AuthorManager",
"::",
"$_pool",
"for",
"Authors",
"first",
"before",
"querying",
"tbl_authors"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.authormanager.php#L155-L211 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.authormanager.php | AuthorManager.fetchByUsername | public static function fetchByUsername($username)
{
if (!isset(self::$_pool[$username])) {
$records = Symphony::Database()->fetchRow(0, sprintf(
"SELECT *
FROM `tbl_authors`
WHERE `username` = '%s'
LIMIT 1",
Symphony::Database()->cleanValue($username)
));
if (!is_array($records) || empty($records)) {
return null;
}
$author = new Author;
foreach ($records as $field => $val) {
$author->set($field, $val);
}
self::$_pool[$username] = $author;
}
return self::$_pool[$username];
} | php | public static function fetchByUsername($username)
{
if (!isset(self::$_pool[$username])) {
$records = Symphony::Database()->fetchRow(0, sprintf(
"SELECT *
FROM `tbl_authors`
WHERE `username` = '%s'
LIMIT 1",
Symphony::Database()->cleanValue($username)
));
if (!is_array($records) || empty($records)) {
return null;
}
$author = new Author;
foreach ($records as $field => $val) {
$author->set($field, $val);
}
self::$_pool[$username] = $author;
}
return self::$_pool[$username];
} | [
"public",
"static",
"function",
"fetchByUsername",
"(",
"$",
"username",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"_pool",
"[",
"$",
"username",
"]",
")",
")",
"{",
"$",
"records",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchRow",
"(",
"0",
",",
"sprintf",
"(",
"\"SELECT *\n FROM `tbl_authors`\n WHERE `username` = '%s'\n LIMIT 1\"",
",",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"cleanValue",
"(",
"$",
"username",
")",
")",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"records",
")",
"||",
"empty",
"(",
"$",
"records",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"author",
"=",
"new",
"Author",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"field",
"=>",
"$",
"val",
")",
"{",
"$",
"author",
"->",
"set",
"(",
"$",
"field",
",",
"$",
"val",
")",
";",
"}",
"self",
"::",
"$",
"_pool",
"[",
"$",
"username",
"]",
"=",
"$",
"author",
";",
"}",
"return",
"self",
"::",
"$",
"_pool",
"[",
"$",
"username",
"]",
";",
"}"
] | Returns an Author by Username. This function will search the
`AuthorManager::$_pool` for Authors first before querying `tbl_authors`
@param string $username
The Author's username
@return Author|null
If an Author is found, an Author object is returned, otherwise null. | [
"Returns",
"an",
"Author",
"by",
"Username",
".",
"This",
"function",
"will",
"search",
"the",
"AuthorManager",
"::",
"$_pool",
"for",
"Authors",
"first",
"before",
"querying",
"tbl_authors"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.authormanager.php#L222-L247 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.authormanager.php | AuthorManager.activateAuthToken | public static function activateAuthToken($author_id)
{
if (!is_int($author_id)) {
return false;
}
return Symphony::Database()->query(sprintf(
"UPDATE `tbl_authors`
SET `auth_token_active` = 'yes'
WHERE `id` = %d",
$author_id
));
} | php | public static function activateAuthToken($author_id)
{
if (!is_int($author_id)) {
return false;
}
return Symphony::Database()->query(sprintf(
"UPDATE `tbl_authors`
SET `auth_token_active` = 'yes'
WHERE `id` = %d",
$author_id
));
} | [
"public",
"static",
"function",
"activateAuthToken",
"(",
"$",
"author_id",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"author_id",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"query",
"(",
"sprintf",
"(",
"\"UPDATE `tbl_authors`\n SET `auth_token_active` = 'yes'\n WHERE `id` = %d\"",
",",
"$",
"author_id",
")",
")",
";",
"}"
] | This function will allow an Author to sign into Symphony by using their
authentication token as well as username/password.
@param integer $author_id
The Author ID to allow to use their authentication token.
@throws DatabaseException
@return boolean | [
"This",
"function",
"will",
"allow",
"an",
"Author",
"to",
"sign",
"into",
"Symphony",
"by",
"using",
"their",
"authentication",
"token",
"as",
"well",
"as",
"username",
"/",
"password",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.authormanager.php#L258-L270 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.authormanager.php | AuthorManager.deactivateAuthToken | public static function deactivateAuthToken($author_id)
{
if (!is_int($author_id)) {
return false;
}
return Symphony::Database()->query(sprintf(
"UPDATE `tbl_authors`
SET `auth_token_active` = 'no'
WHERE `id` = %d",
$author_id
));
} | php | public static function deactivateAuthToken($author_id)
{
if (!is_int($author_id)) {
return false;
}
return Symphony::Database()->query(sprintf(
"UPDATE `tbl_authors`
SET `auth_token_active` = 'no'
WHERE `id` = %d",
$author_id
));
} | [
"public",
"static",
"function",
"deactivateAuthToken",
"(",
"$",
"author_id",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"author_id",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"query",
"(",
"sprintf",
"(",
"\"UPDATE `tbl_authors`\n SET `auth_token_active` = 'no'\n WHERE `id` = %d\"",
",",
"$",
"author_id",
")",
")",
";",
"}"
] | This function will remove the ability for an Author to sign into Symphony
by using their authentication token
@param integer $author_id
The Author ID to allow to use their authentication token.
@throws DatabaseException
@return boolean | [
"This",
"function",
"will",
"remove",
"the",
"ability",
"for",
"an",
"Author",
"to",
"sign",
"into",
"Symphony",
"by",
"using",
"their",
"authentication",
"token"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.authormanager.php#L281-L293 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.smtp.php | SMTP.sendMail | public function sendMail($from, $to, $message)
{
$this->_connect($this->_host, $this->_port);
$this->mail($from);
if (!is_array($to)) {
$to = array($to);
}
foreach ($to as $recipient) {
$this->rcpt($recipient);
}
$this->data($message);
$this->rset();
} | php | public function sendMail($from, $to, $message)
{
$this->_connect($this->_host, $this->_port);
$this->mail($from);
if (!is_array($to)) {
$to = array($to);
}
foreach ($to as $recipient) {
$this->rcpt($recipient);
}
$this->data($message);
$this->rset();
} | [
"public",
"function",
"sendMail",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"_connect",
"(",
"$",
"this",
"->",
"_host",
",",
"$",
"this",
"->",
"_port",
")",
";",
"$",
"this",
"->",
"mail",
"(",
"$",
"from",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"to",
")",
")",
"{",
"$",
"to",
"=",
"array",
"(",
"$",
"to",
")",
";",
"}",
"foreach",
"(",
"$",
"to",
"as",
"$",
"recipient",
")",
"{",
"$",
"this",
"->",
"rcpt",
"(",
"$",
"recipient",
")",
";",
"}",
"$",
"this",
"->",
"data",
"(",
"$",
"message",
")",
";",
"$",
"this",
"->",
"rset",
"(",
")",
";",
"}"
] | The actual email sending.
The connection to the server (connecting, EHLO, AUTH, etc) is done here,
right before the actual email is sent. This is to make sure the connection does not time out.
@param string $from
The from string. Should have the following format: email@domain.tld
@param string $to
The email address to send the email to.
@param string $subject
The subject to send the email to.
@param string $message
@throws SMTPException
@throws Exception
@return boolean | [
"The",
"actual",
"email",
"sending",
".",
"The",
"connection",
"to",
"the",
"server",
"(",
"connecting",
"EHLO",
"AUTH",
"etc",
")",
"is",
"done",
"here",
"right",
"before",
"the",
"actual",
"email",
"is",
"sent",
".",
"This",
"is",
"to",
"make",
"sure",
"the",
"connection",
"does",
"not",
"time",
"out",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.smtp.php#L136-L150 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.smtp.php | SMTP.setHeader | public function setHeader($header, $value)
{
if (is_array($value)) {
throw new SMTPException(__('Header fields can only contain strings'));
}
$this->_header_fields[$header] = $value;
} | php | public function setHeader($header, $value)
{
if (is_array($value)) {
throw new SMTPException(__('Header fields can only contain strings'));
}
$this->_header_fields[$header] = $value;
} | [
"public",
"function",
"setHeader",
"(",
"$",
"header",
",",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"SMTPException",
"(",
"__",
"(",
"'Header fields can only contain strings'",
")",
")",
";",
"}",
"$",
"this",
"->",
"_header_fields",
"[",
"$",
"header",
"]",
"=",
"$",
"value",
";",
"}"
] | Sets a header to be sent in the email.
@throws SMTPException
@param string $header
@param string $value
@return void | [
"Sets",
"a",
"header",
"to",
"be",
"sent",
"in",
"the",
"email",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.smtp.php#L160-L167 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.smtp.php | SMTP.helo | public function helo()
{
if ($this->_mail !== false) {
throw new SMTPException(__('Can not call HELO on existing session'));
}
//wait for the server to be ready
$this->_expect(220, 300);
//send ehlo or ehlo request.
try {
$this->_ehlo();
} catch (SMTPException $e) {
$this->_helo();
} catch (Exception $e) {
throw $e;
}
$this->_helo = true;
} | php | public function helo()
{
if ($this->_mail !== false) {
throw new SMTPException(__('Can not call HELO on existing session'));
}
//wait for the server to be ready
$this->_expect(220, 300);
//send ehlo or ehlo request.
try {
$this->_ehlo();
} catch (SMTPException $e) {
$this->_helo();
} catch (Exception $e) {
throw $e;
}
$this->_helo = true;
} | [
"public",
"function",
"helo",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_mail",
"!==",
"false",
")",
"{",
"throw",
"new",
"SMTPException",
"(",
"__",
"(",
"'Can not call HELO on existing session'",
")",
")",
";",
"}",
"//wait for the server to be ready",
"$",
"this",
"->",
"_expect",
"(",
"220",
",",
"300",
")",
";",
"//send ehlo or ehlo request.",
"try",
"{",
"$",
"this",
"->",
"_ehlo",
"(",
")",
";",
"}",
"catch",
"(",
"SMTPException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"_helo",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"$",
"this",
"->",
"_helo",
"=",
"true",
";",
"}"
] | Initiates the ehlo/helo requests.
@throws SMTPException
@throws Exception
@return void | [
"Initiates",
"the",
"ehlo",
"/",
"helo",
"requests",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.smtp.php#L177-L196 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.smtp.php | SMTP.mail | public function mail($from)
{
if ($this->_helo == false) {
throw new SMTPException(__('Must call EHLO (or HELO) before calling MAIL'));
} elseif ($this->_mail !== false) {
throw new SMTPException(__('Only one call to MAIL may be made at a time.'));
}
$this->_send('MAIL FROM:<' . $from . '>');
$this->_expect(250, 300);
$this->_from = $from;
$this->_mail = true;
$this->_rcpt = false;
$this->_data = false;
} | php | public function mail($from)
{
if ($this->_helo == false) {
throw new SMTPException(__('Must call EHLO (or HELO) before calling MAIL'));
} elseif ($this->_mail !== false) {
throw new SMTPException(__('Only one call to MAIL may be made at a time.'));
}
$this->_send('MAIL FROM:<' . $from . '>');
$this->_expect(250, 300);
$this->_from = $from;
$this->_mail = true;
$this->_rcpt = false;
$this->_data = false;
} | [
"public",
"function",
"mail",
"(",
"$",
"from",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_helo",
"==",
"false",
")",
"{",
"throw",
"new",
"SMTPException",
"(",
"__",
"(",
"'Must call EHLO (or HELO) before calling MAIL'",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"_mail",
"!==",
"false",
")",
"{",
"throw",
"new",
"SMTPException",
"(",
"__",
"(",
"'Only one call to MAIL may be made at a time.'",
")",
")",
";",
"}",
"$",
"this",
"->",
"_send",
"(",
"'MAIL FROM:<'",
".",
"$",
"from",
".",
"'>'",
")",
";",
"$",
"this",
"->",
"_expect",
"(",
"250",
",",
"300",
")",
";",
"$",
"this",
"->",
"_from",
"=",
"$",
"from",
";",
"$",
"this",
"->",
"_mail",
"=",
"true",
";",
"$",
"this",
"->",
"_rcpt",
"=",
"false",
";",
"$",
"this",
"->",
"_data",
"=",
"false",
";",
"}"
] | Calls the MAIL command on the server.
@throws SMTPException
@param string $from
The email address to send the email from.
@return void | [
"Calls",
"the",
"MAIL",
"command",
"on",
"the",
"server",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.smtp.php#L206-L221 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.smtp.php | SMTP.rcpt | public function rcpt($to)
{
if ($this->_mail == false) {
throw new SMTPException(__('Must call MAIL before calling RCPT'));
}
$this->_send('RCPT TO:<' . $to . '>');
$this->_expect(array(250, 251), 300);
$this->_rcpt = true;
} | php | public function rcpt($to)
{
if ($this->_mail == false) {
throw new SMTPException(__('Must call MAIL before calling RCPT'));
}
$this->_send('RCPT TO:<' . $to . '>');
$this->_expect(array(250, 251), 300);
$this->_rcpt = true;
} | [
"public",
"function",
"rcpt",
"(",
"$",
"to",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_mail",
"==",
"false",
")",
"{",
"throw",
"new",
"SMTPException",
"(",
"__",
"(",
"'Must call MAIL before calling RCPT'",
")",
")",
";",
"}",
"$",
"this",
"->",
"_send",
"(",
"'RCPT TO:<'",
".",
"$",
"to",
".",
"'>'",
")",
";",
"$",
"this",
"->",
"_expect",
"(",
"array",
"(",
"250",
",",
"251",
")",
",",
"300",
")",
";",
"$",
"this",
"->",
"_rcpt",
"=",
"true",
";",
"}"
] | Calls the RCPT command on the server. May be called multiple times for more than one recipient.
@throws SMTPException
@param string $to
The address to send the email to.
@return void | [
"Calls",
"the",
"RCPT",
"command",
"on",
"the",
"server",
".",
"May",
"be",
"called",
"multiple",
"times",
"for",
"more",
"than",
"one",
"recipient",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.smtp.php#L231-L241 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.smtp.php | SMTP.data | public function data($data)
{
if ($this->_rcpt == false) {
throw new SMTPException(__('Must call RCPT before calling DATA'));
}
$this->_send('DATA');
$this->_expect(354, 120);
foreach ($this->_header_fields as $name => $body) {
// Every header can contain an array. Will insert multiple header fields of that type with the contents of array.
// Useful for multiple recipients, for instance.
if (!is_array($body)) {
$body = array($body);
}
foreach ($body as $val) {
$this->_send($name . ': ' . $val);
}
}
// Send an empty newline. Solves bugs with Apple Mail
$this->_send('');
// Because the message can contain \n as a newline, replace all \r\n with \n and explode on \n.
// The send() function will use the proper line ending (\r\n).
$data = str_replace("\r\n", "\n", $data);
$data_arr = explode("\n", $data);
foreach ($data_arr as $line) {
// Escape line if first character is a period (dot). http://tools.ietf.org/html/rfc2821#section-4.5.2
if (strpos($line, '.') === 0) {
$line = '.' . $line;
}
$this->_send($line);
}
$this->_send('.');
$this->_expect(250, 600);
$this->_data = true;
} | php | public function data($data)
{
if ($this->_rcpt == false) {
throw new SMTPException(__('Must call RCPT before calling DATA'));
}
$this->_send('DATA');
$this->_expect(354, 120);
foreach ($this->_header_fields as $name => $body) {
// Every header can contain an array. Will insert multiple header fields of that type with the contents of array.
// Useful for multiple recipients, for instance.
if (!is_array($body)) {
$body = array($body);
}
foreach ($body as $val) {
$this->_send($name . ': ' . $val);
}
}
// Send an empty newline. Solves bugs with Apple Mail
$this->_send('');
// Because the message can contain \n as a newline, replace all \r\n with \n and explode on \n.
// The send() function will use the proper line ending (\r\n).
$data = str_replace("\r\n", "\n", $data);
$data_arr = explode("\n", $data);
foreach ($data_arr as $line) {
// Escape line if first character is a period (dot). http://tools.ietf.org/html/rfc2821#section-4.5.2
if (strpos($line, '.') === 0) {
$line = '.' . $line;
}
$this->_send($line);
}
$this->_send('.');
$this->_expect(250, 600);
$this->_data = true;
} | [
"public",
"function",
"data",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_rcpt",
"==",
"false",
")",
"{",
"throw",
"new",
"SMTPException",
"(",
"__",
"(",
"'Must call RCPT before calling DATA'",
")",
")",
";",
"}",
"$",
"this",
"->",
"_send",
"(",
"'DATA'",
")",
";",
"$",
"this",
"->",
"_expect",
"(",
"354",
",",
"120",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_header_fields",
"as",
"$",
"name",
"=>",
"$",
"body",
")",
"{",
"// Every header can contain an array. Will insert multiple header fields of that type with the contents of array.",
"// Useful for multiple recipients, for instance.",
"if",
"(",
"!",
"is_array",
"(",
"$",
"body",
")",
")",
"{",
"$",
"body",
"=",
"array",
"(",
"$",
"body",
")",
";",
"}",
"foreach",
"(",
"$",
"body",
"as",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"_send",
"(",
"$",
"name",
".",
"': '",
".",
"$",
"val",
")",
";",
"}",
"}",
"// Send an empty newline. Solves bugs with Apple Mail",
"$",
"this",
"->",
"_send",
"(",
"''",
")",
";",
"// Because the message can contain \\n as a newline, replace all \\r\\n with \\n and explode on \\n.",
"// The send() function will use the proper line ending (\\r\\n).",
"$",
"data",
"=",
"str_replace",
"(",
"\"\\r\\n\"",
",",
"\"\\n\"",
",",
"$",
"data",
")",
";",
"$",
"data_arr",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"data",
")",
";",
"foreach",
"(",
"$",
"data_arr",
"as",
"$",
"line",
")",
"{",
"// Escape line if first character is a period (dot). http://tools.ietf.org/html/rfc2821#section-4.5.2",
"if",
"(",
"strpos",
"(",
"$",
"line",
",",
"'.'",
")",
"===",
"0",
")",
"{",
"$",
"line",
"=",
"'.'",
".",
"$",
"line",
";",
"}",
"$",
"this",
"->",
"_send",
"(",
"$",
"line",
")",
";",
"}",
"$",
"this",
"->",
"_send",
"(",
"'.'",
")",
";",
"$",
"this",
"->",
"_expect",
"(",
"250",
",",
"600",
")",
";",
"$",
"this",
"->",
"_data",
"=",
"true",
";",
"}"
] | Calls the data command on the server.
Also includes header fields in the command.
@throws SMTPException
@param string $data
@return void | [
"Calls",
"the",
"data",
"command",
"on",
"the",
"server",
".",
"Also",
"includes",
"header",
"fields",
"in",
"the",
"command",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.smtp.php#L251-L290 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.smtp.php | SMTP._auth | protected function _auth()
{
if ($this->_helo == false) {
throw new SMTPException(__('Must call EHLO (or HELO) before calling AUTH'));
} elseif ($this->_auth !== false) {
throw new SMTPException(__('Can not call AUTH again.'));
}
$this->_send('AUTH LOGIN');
$this->_expect(334);
$this->_send(base64_encode($this->_user));
$this->_expect(334);
$this->_send(base64_encode($this->_pass));
$this->_expect(235);
$this->_auth = true;
} | php | protected function _auth()
{
if ($this->_helo == false) {
throw new SMTPException(__('Must call EHLO (or HELO) before calling AUTH'));
} elseif ($this->_auth !== false) {
throw new SMTPException(__('Can not call AUTH again.'));
}
$this->_send('AUTH LOGIN');
$this->_expect(334);
$this->_send(base64_encode($this->_user));
$this->_expect(334);
$this->_send(base64_encode($this->_pass));
$this->_expect(235);
$this->_auth = true;
} | [
"protected",
"function",
"_auth",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_helo",
"==",
"false",
")",
"{",
"throw",
"new",
"SMTPException",
"(",
"__",
"(",
"'Must call EHLO (or HELO) before calling AUTH'",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"_auth",
"!==",
"false",
")",
"{",
"throw",
"new",
"SMTPException",
"(",
"__",
"(",
"'Can not call AUTH again.'",
")",
")",
";",
"}",
"$",
"this",
"->",
"_send",
"(",
"'AUTH LOGIN'",
")",
";",
"$",
"this",
"->",
"_expect",
"(",
"334",
")",
";",
"$",
"this",
"->",
"_send",
"(",
"base64_encode",
"(",
"$",
"this",
"->",
"_user",
")",
")",
";",
"$",
"this",
"->",
"_expect",
"(",
"334",
")",
";",
"$",
"this",
"->",
"_send",
"(",
"base64_encode",
"(",
"$",
"this",
"->",
"_pass",
")",
")",
";",
"$",
"this",
"->",
"_expect",
"(",
"235",
")",
";",
"$",
"this",
"->",
"_auth",
"=",
"true",
";",
"}"
] | Authenticates to the server.
Currently supports the AUTH LOGIN command.
May be extended if more methods are needed.
@throws SMTPException
@return void | [
"Authenticates",
"to",
"the",
"server",
".",
"Currently",
"supports",
"the",
"AUTH",
"LOGIN",
"command",
".",
"May",
"be",
"extended",
"if",
"more",
"methods",
"are",
"needed",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.smtp.php#L330-L345 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.smtp.php | SMTP._tls | protected function _tls()
{
if ($this->_secure == 'tls') {
$this->_send('STARTTLS');
$this->_expect(220, 180);
if (!stream_socket_enable_crypto($this->_connection, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
throw new SMTPException(__('Unable to connect via TLS'));
}
$this->_ehlo();
}
} | php | protected function _tls()
{
if ($this->_secure == 'tls') {
$this->_send('STARTTLS');
$this->_expect(220, 180);
if (!stream_socket_enable_crypto($this->_connection, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
throw new SMTPException(__('Unable to connect via TLS'));
}
$this->_ehlo();
}
} | [
"protected",
"function",
"_tls",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_secure",
"==",
"'tls'",
")",
"{",
"$",
"this",
"->",
"_send",
"(",
"'STARTTLS'",
")",
";",
"$",
"this",
"->",
"_expect",
"(",
"220",
",",
"180",
")",
";",
"if",
"(",
"!",
"stream_socket_enable_crypto",
"(",
"$",
"this",
"->",
"_connection",
",",
"true",
",",
"STREAM_CRYPTO_METHOD_TLS_CLIENT",
")",
")",
"{",
"throw",
"new",
"SMTPException",
"(",
"__",
"(",
"'Unable to connect via TLS'",
")",
")",
";",
"}",
"$",
"this",
"->",
"_ehlo",
"(",
")",
";",
"}",
"}"
] | Encrypts the current session with TLS.
@throws SMTPException
@return void | [
"Encrypts",
"the",
"current",
"session",
"with",
"TLS",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.smtp.php#L379-L389 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.smtp.php | SMTP._send | protected function _send($request)
{
$this->checkConnection();
$result = fwrite($this->_connection, $request . "\r\n");
if ($result === false) {
throw new SMTPException(__('Could not send request: %s', array($request)));
}
return $result;
} | php | protected function _send($request)
{
$this->checkConnection();
$result = fwrite($this->_connection, $request . "\r\n");
if ($result === false) {
throw new SMTPException(__('Could not send request: %s', array($request)));
}
return $result;
} | [
"protected",
"function",
"_send",
"(",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"checkConnection",
"(",
")",
";",
"$",
"result",
"=",
"fwrite",
"(",
"$",
"this",
"->",
"_connection",
",",
"$",
"request",
".",
"\"\\r\\n\"",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"throw",
"new",
"SMTPException",
"(",
"__",
"(",
"'Could not send request: %s'",
",",
"array",
"(",
"$",
"request",
")",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Send a request to the host, appends the request with a line break.
@param string $request
@throws SMTPException
@return boolean|integer number of characters written. | [
"Send",
"a",
"request",
"to",
"the",
"host",
"appends",
"the",
"request",
"with",
"a",
"line",
"break",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.smtp.php#L398-L408 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.smtp.php | SMTP._receive | protected function _receive($timeout = null)
{
$this->checkConnection();
if ($timeout !== null) {
stream_set_timeout($this->_connection, $timeout);
}
$response = fgets($this->_connection, 1024);
$info = stream_get_meta_data($this->_connection);
if (!empty($info['timed_out'])) {
throw new SMTPException(__('%s has timed out', array($this->_host)));
} elseif ($response === false) {
throw new SMTPException(__('Could not read from %s', array($this->_host)));
}
return $response;
} | php | protected function _receive($timeout = null)
{
$this->checkConnection();
if ($timeout !== null) {
stream_set_timeout($this->_connection, $timeout);
}
$response = fgets($this->_connection, 1024);
$info = stream_get_meta_data($this->_connection);
if (!empty($info['timed_out'])) {
throw new SMTPException(__('%s has timed out', array($this->_host)));
} elseif ($response === false) {
throw new SMTPException(__('Could not read from %s', array($this->_host)));
}
return $response;
} | [
"protected",
"function",
"_receive",
"(",
"$",
"timeout",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"checkConnection",
"(",
")",
";",
"if",
"(",
"$",
"timeout",
"!==",
"null",
")",
"{",
"stream_set_timeout",
"(",
"$",
"this",
"->",
"_connection",
",",
"$",
"timeout",
")",
";",
"}",
"$",
"response",
"=",
"fgets",
"(",
"$",
"this",
"->",
"_connection",
",",
"1024",
")",
";",
"$",
"info",
"=",
"stream_get_meta_data",
"(",
"$",
"this",
"->",
"_connection",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"info",
"[",
"'timed_out'",
"]",
")",
")",
"{",
"throw",
"new",
"SMTPException",
"(",
"__",
"(",
"'%s has timed out'",
",",
"array",
"(",
"$",
"this",
"->",
"_host",
")",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"response",
"===",
"false",
")",
"{",
"throw",
"new",
"SMTPException",
"(",
"__",
"(",
"'Could not read from %s'",
",",
"array",
"(",
"$",
"this",
"->",
"_host",
")",
")",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Get a line from the stream.
@param integer $timeout
Per-request timeout value if applicable. Defaults to null which
will not set a timeout.
@throws SMTPException
@return string | [
"Get",
"a",
"line",
"from",
"the",
"stream",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.smtp.php#L419-L437 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.smtp.php | SMTP._expect | protected function _expect($code, $timeout = null)
{
$this->_response = array();
$cmd = '';
$more = '';
$msg = '';
$errMsg = '';
if (!is_array($code)) {
$code = array($code);
}
// Borrowed from the Zend Email Library
do {
$result = $this->_receive($timeout);
list($cmd, $more, $msg) = preg_split('/([\s-]+)/', $result, 2, PREG_SPLIT_DELIM_CAPTURE);
if ($errMsg !== '') {
$errMsg .= ' ' . $msg;
} elseif ($cmd === null || !in_array($cmd, $code)) {
$errMsg = $msg;
}
} while (strpos($more, '-') === 0); // The '-' message prefix indicates an information string instead of a response string.
if ($errMsg !== '') {
$this->rset();
throw new SMTPException($errMsg);
}
return $msg;
} | php | protected function _expect($code, $timeout = null)
{
$this->_response = array();
$cmd = '';
$more = '';
$msg = '';
$errMsg = '';
if (!is_array($code)) {
$code = array($code);
}
// Borrowed from the Zend Email Library
do {
$result = $this->_receive($timeout);
list($cmd, $more, $msg) = preg_split('/([\s-]+)/', $result, 2, PREG_SPLIT_DELIM_CAPTURE);
if ($errMsg !== '') {
$errMsg .= ' ' . $msg;
} elseif ($cmd === null || !in_array($cmd, $code)) {
$errMsg = $msg;
}
} while (strpos($more, '-') === 0); // The '-' message prefix indicates an information string instead of a response string.
if ($errMsg !== '') {
$this->rset();
throw new SMTPException($errMsg);
}
return $msg;
} | [
"protected",
"function",
"_expect",
"(",
"$",
"code",
",",
"$",
"timeout",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"_response",
"=",
"array",
"(",
")",
";",
"$",
"cmd",
"=",
"''",
";",
"$",
"more",
"=",
"''",
";",
"$",
"msg",
"=",
"''",
";",
"$",
"errMsg",
"=",
"''",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"code",
")",
")",
"{",
"$",
"code",
"=",
"array",
"(",
"$",
"code",
")",
";",
"}",
"// Borrowed from the Zend Email Library",
"do",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"_receive",
"(",
"$",
"timeout",
")",
";",
"list",
"(",
"$",
"cmd",
",",
"$",
"more",
",",
"$",
"msg",
")",
"=",
"preg_split",
"(",
"'/([\\s-]+)/'",
",",
"$",
"result",
",",
"2",
",",
"PREG_SPLIT_DELIM_CAPTURE",
")",
";",
"if",
"(",
"$",
"errMsg",
"!==",
"''",
")",
"{",
"$",
"errMsg",
".=",
"' '",
".",
"$",
"msg",
";",
"}",
"elseif",
"(",
"$",
"cmd",
"===",
"null",
"||",
"!",
"in_array",
"(",
"$",
"cmd",
",",
"$",
"code",
")",
")",
"{",
"$",
"errMsg",
"=",
"$",
"msg",
";",
"}",
"}",
"while",
"(",
"strpos",
"(",
"$",
"more",
",",
"'-'",
")",
"===",
"0",
")",
";",
"// The '-' message prefix indicates an information string instead of a response string.",
"if",
"(",
"$",
"errMsg",
"!==",
"''",
")",
"{",
"$",
"this",
"->",
"rset",
"(",
")",
";",
"throw",
"new",
"SMTPException",
"(",
"$",
"errMsg",
")",
";",
"}",
"return",
"$",
"msg",
";",
"}"
] | Parse server response for successful codes
Read the response from the stream and check for expected return code.
@throws SMTPException
@param string|array $code
One or more codes that indicate a successful response
@param integer $timeout
Per-request timeout value if applicable. Defaults to null which
will not set a timeout.
@return string
Last line of response string | [
"Parse",
"server",
"response",
"for",
"successful",
"codes"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.smtp.php#L453-L483 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.smtp.php | SMTP._connect | protected function _connect($host, $port)
{
$errorNum = 0;
$errorStr = '';
$remoteAddr = $this->_transport . '://' . $host . ':' . $port;
if (!is_resource($this->_connection)) {
$this->_connection = @stream_socket_client($remoteAddr, $errorNum, $errorStr, self::TIMEOUT);
if ($this->_connection === false) {
if ($errorNum == 0) {
throw new SMTPException(__('Unable to open socket. Unknown error'));
} else {
throw new SMTPException(__('Unable to open socket. %s', array($errorStr)));
}
}
if (@stream_set_timeout($this->_connection, self::TIMEOUT) === false) {
throw new SMTPException(__('Unable to set timeout.'));
}
$this->helo();
if ($this->_secure == 'tls') {
$this->_tls();
}
if (($this->_user !== null) && ($this->_pass !== null)) {
$this->_auth();
}
}
} | php | protected function _connect($host, $port)
{
$errorNum = 0;
$errorStr = '';
$remoteAddr = $this->_transport . '://' . $host . ':' . $port;
if (!is_resource($this->_connection)) {
$this->_connection = @stream_socket_client($remoteAddr, $errorNum, $errorStr, self::TIMEOUT);
if ($this->_connection === false) {
if ($errorNum == 0) {
throw new SMTPException(__('Unable to open socket. Unknown error'));
} else {
throw new SMTPException(__('Unable to open socket. %s', array($errorStr)));
}
}
if (@stream_set_timeout($this->_connection, self::TIMEOUT) === false) {
throw new SMTPException(__('Unable to set timeout.'));
}
$this->helo();
if ($this->_secure == 'tls') {
$this->_tls();
}
if (($this->_user !== null) && ($this->_pass !== null)) {
$this->_auth();
}
}
} | [
"protected",
"function",
"_connect",
"(",
"$",
"host",
",",
"$",
"port",
")",
"{",
"$",
"errorNum",
"=",
"0",
";",
"$",
"errorStr",
"=",
"''",
";",
"$",
"remoteAddr",
"=",
"$",
"this",
"->",
"_transport",
".",
"'://'",
".",
"$",
"host",
".",
"':'",
".",
"$",
"port",
";",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"this",
"->",
"_connection",
")",
")",
"{",
"$",
"this",
"->",
"_connection",
"=",
"@",
"stream_socket_client",
"(",
"$",
"remoteAddr",
",",
"$",
"errorNum",
",",
"$",
"errorStr",
",",
"self",
"::",
"TIMEOUT",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_connection",
"===",
"false",
")",
"{",
"if",
"(",
"$",
"errorNum",
"==",
"0",
")",
"{",
"throw",
"new",
"SMTPException",
"(",
"__",
"(",
"'Unable to open socket. Unknown error'",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"SMTPException",
"(",
"__",
"(",
"'Unable to open socket. %s'",
",",
"array",
"(",
"$",
"errorStr",
")",
")",
")",
";",
"}",
"}",
"if",
"(",
"@",
"stream_set_timeout",
"(",
"$",
"this",
"->",
"_connection",
",",
"self",
"::",
"TIMEOUT",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"SMTPException",
"(",
"__",
"(",
"'Unable to set timeout.'",
")",
")",
";",
"}",
"$",
"this",
"->",
"helo",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_secure",
"==",
"'tls'",
")",
"{",
"$",
"this",
"->",
"_tls",
"(",
")",
";",
"}",
"if",
"(",
"(",
"$",
"this",
"->",
"_user",
"!==",
"null",
")",
"&&",
"(",
"$",
"this",
"->",
"_pass",
"!==",
"null",
")",
")",
"{",
"$",
"this",
"->",
"_auth",
"(",
")",
";",
"}",
"}",
"}"
] | Connect to the host, and perform basic functions like helo and auth.
@param string $host
@param integer $port
@throws SMTPException
@throws Exception
@return void | [
"Connect",
"to",
"the",
"host",
"and",
"perform",
"basic",
"functions",
"like",
"helo",
"and",
"auth",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.smtp.php#L495-L527 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.getInstance | public static function getInstance($name)
{
return (isset(self::$_pool[$name]) ? self::$_pool[$name] : self::create($name));
} | php | public static function getInstance($name)
{
return (isset(self::$_pool[$name]) ? self::$_pool[$name] : self::create($name));
} | [
"public",
"static",
"function",
"getInstance",
"(",
"$",
"name",
")",
"{",
"return",
"(",
"isset",
"(",
"self",
"::",
"$",
"_pool",
"[",
"$",
"name",
"]",
")",
"?",
"self",
"::",
"$",
"_pool",
"[",
"$",
"name",
"]",
":",
"self",
"::",
"create",
"(",
"$",
"name",
")",
")",
";",
"}"
] | This function returns an instance of an extension from it's name
@param string $name
The name of the Extension Class minus the extension prefix.
@throws SymphonyErrorPage
@throws Exception
@return Extension | [
"This",
"function",
"returns",
"an",
"instance",
"of",
"an",
"extension",
"from",
"it",
"s",
"name"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L125-L128 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.__buildExtensionList | private static function __buildExtensionList($update = false)
{
if (empty(self::$_extensions) || $update) {
self::$_extensions = Symphony::Database()->fetch("SELECT * FROM `tbl_extensions`", 'name');
}
} | php | private static function __buildExtensionList($update = false)
{
if (empty(self::$_extensions) || $update) {
self::$_extensions = Symphony::Database()->fetch("SELECT * FROM `tbl_extensions`", 'name');
}
} | [
"private",
"static",
"function",
"__buildExtensionList",
"(",
"$",
"update",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"self",
"::",
"$",
"_extensions",
")",
"||",
"$",
"update",
")",
"{",
"self",
"::",
"$",
"_extensions",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetch",
"(",
"\"SELECT * FROM `tbl_extensions`\"",
",",
"'name'",
")",
";",
"}",
"}"
] | Populates the `ExtensionManager::$_extensions` array with all the
extensions stored in `tbl_extensions`. If `ExtensionManager::$_extensions`
isn't empty, passing true as a parameter will force the array to update
@param boolean $update
Updates the `ExtensionManager::$_extensions` array even if it was
populated, defaults to false.
@throws DatabaseException | [
"Populates",
"the",
"ExtensionManager",
"::",
"$_extensions",
"array",
"with",
"all",
"the",
"extensions",
"stored",
"in",
"tbl_extensions",
".",
"If",
"ExtensionManager",
"::",
"$_extensions",
"isn",
"t",
"empty",
"passing",
"true",
"as",
"a",
"parameter",
"will",
"force",
"the",
"array",
"to",
"update"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L140-L145 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.fetchStatus | public static function fetchStatus($about)
{
$return = array();
self::__buildExtensionList();
if (isset($about['handle']) && array_key_exists($about['handle'], self::$_extensions)) {
if (self::$_extensions[$about['handle']]['status'] == 'enabled') {
$return[] = Extension::EXTENSION_ENABLED;
} else {
$return[] = Extension::EXTENSION_DISABLED;
}
} else {
$return[] = Extension::EXTENSION_NOT_INSTALLED;
}
if (isset($about['handle'], $about['version']) && self::__requiresUpdate($about['handle'], $about['version'])) {
$return[] = Extension::EXTENSION_REQUIRES_UPDATE;
}
return $return;
} | php | public static function fetchStatus($about)
{
$return = array();
self::__buildExtensionList();
if (isset($about['handle']) && array_key_exists($about['handle'], self::$_extensions)) {
if (self::$_extensions[$about['handle']]['status'] == 'enabled') {
$return[] = Extension::EXTENSION_ENABLED;
} else {
$return[] = Extension::EXTENSION_DISABLED;
}
} else {
$return[] = Extension::EXTENSION_NOT_INSTALLED;
}
if (isset($about['handle'], $about['version']) && self::__requiresUpdate($about['handle'], $about['version'])) {
$return[] = Extension::EXTENSION_REQUIRES_UPDATE;
}
return $return;
} | [
"public",
"static",
"function",
"fetchStatus",
"(",
"$",
"about",
")",
"{",
"$",
"return",
"=",
"array",
"(",
")",
";",
"self",
"::",
"__buildExtensionList",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"about",
"[",
"'handle'",
"]",
")",
"&&",
"array_key_exists",
"(",
"$",
"about",
"[",
"'handle'",
"]",
",",
"self",
"::",
"$",
"_extensions",
")",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"_extensions",
"[",
"$",
"about",
"[",
"'handle'",
"]",
"]",
"[",
"'status'",
"]",
"==",
"'enabled'",
")",
"{",
"$",
"return",
"[",
"]",
"=",
"Extension",
"::",
"EXTENSION_ENABLED",
";",
"}",
"else",
"{",
"$",
"return",
"[",
"]",
"=",
"Extension",
"::",
"EXTENSION_DISABLED",
";",
"}",
"}",
"else",
"{",
"$",
"return",
"[",
"]",
"=",
"Extension",
"::",
"EXTENSION_NOT_INSTALLED",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"about",
"[",
"'handle'",
"]",
",",
"$",
"about",
"[",
"'version'",
"]",
")",
"&&",
"self",
"::",
"__requiresUpdate",
"(",
"$",
"about",
"[",
"'handle'",
"]",
",",
"$",
"about",
"[",
"'version'",
"]",
")",
")",
"{",
"$",
"return",
"[",
"]",
"=",
"Extension",
"::",
"EXTENSION_REQUIRES_UPDATE",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Returns the status of an Extension given an associative array containing
the Extension `handle` and `version` where the `version` is the file
version, not the installed version. This function returns an array
which may include a maximum of two statuses.
@param array $about
An associative array of the extension meta data, typically returned
by `ExtensionManager::about()`. At the very least this array needs
`handle` and `version` keys.
@return array
An array of extension statuses, with the possible values being
`EXTENSION_ENABLED`, `EXTENSION_DISABLED`, `EXTENSION_REQUIRES_UPDATE`
or `EXTENSION_NOT_INSTALLED`. If an extension doesn't exist,
`EXTENSION_NOT_INSTALLED` will be returned. | [
"Returns",
"the",
"status",
"of",
"an",
"Extension",
"given",
"an",
"associative",
"array",
"containing",
"the",
"Extension",
"handle",
"and",
"version",
"where",
"the",
"version",
"is",
"the",
"file",
"version",
"not",
"the",
"installed",
"version",
".",
"This",
"function",
"returns",
"an",
"array",
"which",
"may",
"include",
"a",
"maximum",
"of",
"two",
"statuses",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L163-L183 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.fetchInstalledVersion | public static function fetchInstalledVersion($name)
{
self::__buildExtensionList();
return (isset(self::$_extensions[$name]) ? self::$_extensions[$name]['version'] : null);
} | php | public static function fetchInstalledVersion($name)
{
self::__buildExtensionList();
return (isset(self::$_extensions[$name]) ? self::$_extensions[$name]['version'] : null);
} | [
"public",
"static",
"function",
"fetchInstalledVersion",
"(",
"$",
"name",
")",
"{",
"self",
"::",
"__buildExtensionList",
"(",
")",
";",
"return",
"(",
"isset",
"(",
"self",
"::",
"$",
"_extensions",
"[",
"$",
"name",
"]",
")",
"?",
"self",
"::",
"$",
"_extensions",
"[",
"$",
"name",
"]",
"[",
"'version'",
"]",
":",
"null",
")",
";",
"}"
] | A convenience method that returns an extension version from it's name.
@param string $name
The name of the Extension Class minus the extension prefix.
@return string | [
"A",
"convenience",
"method",
"that",
"returns",
"an",
"extension",
"version",
"from",
"it",
"s",
"name",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L192-L197 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.getProvidersOf | public static function getProvidersOf($type = null)
{
// Loop over all extensions and build an array of providable objects
if (empty(self::$_providers)) {
self::$_providers = array();
foreach (self::listInstalledHandles() as $handle) {
$obj = self::getInstance($handle);
if (!method_exists($obj, 'providerOf')) {
continue;
}
$providers = $obj->providerOf();
if (empty($providers)) {
continue;
}
// For each of the matching objects (by $type), resolve the object path
self::$_providers = array_merge_recursive(self::$_providers, $obj->providerOf());
}
}
// Return an array of objects
if (is_null($type)) {
return self::$_providers;
}
if (!isset(self::$_providers[$type])) {
return array();
}
return self::$_providers[$type];
} | php | public static function getProvidersOf($type = null)
{
// Loop over all extensions and build an array of providable objects
if (empty(self::$_providers)) {
self::$_providers = array();
foreach (self::listInstalledHandles() as $handle) {
$obj = self::getInstance($handle);
if (!method_exists($obj, 'providerOf')) {
continue;
}
$providers = $obj->providerOf();
if (empty($providers)) {
continue;
}
// For each of the matching objects (by $type), resolve the object path
self::$_providers = array_merge_recursive(self::$_providers, $obj->providerOf());
}
}
// Return an array of objects
if (is_null($type)) {
return self::$_providers;
}
if (!isset(self::$_providers[$type])) {
return array();
}
return self::$_providers[$type];
} | [
"public",
"static",
"function",
"getProvidersOf",
"(",
"$",
"type",
"=",
"null",
")",
"{",
"// Loop over all extensions and build an array of providable objects",
"if",
"(",
"empty",
"(",
"self",
"::",
"$",
"_providers",
")",
")",
"{",
"self",
"::",
"$",
"_providers",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"self",
"::",
"listInstalledHandles",
"(",
")",
"as",
"$",
"handle",
")",
"{",
"$",
"obj",
"=",
"self",
"::",
"getInstance",
"(",
"$",
"handle",
")",
";",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"obj",
",",
"'providerOf'",
")",
")",
"{",
"continue",
";",
"}",
"$",
"providers",
"=",
"$",
"obj",
"->",
"providerOf",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"providers",
")",
")",
"{",
"continue",
";",
"}",
"// For each of the matching objects (by $type), resolve the object path",
"self",
"::",
"$",
"_providers",
"=",
"array_merge_recursive",
"(",
"self",
"::",
"$",
"_providers",
",",
"$",
"obj",
"->",
"providerOf",
"(",
")",
")",
";",
"}",
"}",
"// Return an array of objects",
"if",
"(",
"is_null",
"(",
"$",
"type",
")",
")",
"{",
"return",
"self",
"::",
"$",
"_providers",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"_providers",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"return",
"self",
"::",
"$",
"_providers",
"[",
"$",
"type",
"]",
";",
"}"
] | Return an array all the Provider objects supplied by extensions,
optionally filtered by a given `$type`.
@since Symphony 2.3
@todo Add information about the possible types
@param string $type
This will only return Providers of this type. If null, which is
default, all providers will be returned.
@throws Exception
@throws SymphonyErrorPage
@return array
An array of objects | [
"Return",
"an",
"array",
"all",
"the",
"Provider",
"objects",
"supplied",
"by",
"extensions",
"optionally",
"filtered",
"by",
"a",
"given",
"$type",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L227-L261 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.getCacheProvider | public static function getCacheProvider($key = null, $reuse = true)
{
$cacheDriver = Symphony::Configuration()->get($key, 'caching');
if (in_array($cacheDriver, array_keys(Symphony::ExtensionManager()->getProvidersOf('cache')))) {
$cacheable = new $cacheDriver;
} else {
$cacheable = Symphony::Database();
$cacheDriver = 'CacheDatabase';
}
if ($reuse === false) {
return new Cacheable($cacheable);
} elseif (!isset(self::$_pool[$cacheDriver])) {
self::$_pool[$cacheDriver] = new Cacheable($cacheable);
}
return self::$_pool[$cacheDriver];
} | php | public static function getCacheProvider($key = null, $reuse = true)
{
$cacheDriver = Symphony::Configuration()->get($key, 'caching');
if (in_array($cacheDriver, array_keys(Symphony::ExtensionManager()->getProvidersOf('cache')))) {
$cacheable = new $cacheDriver;
} else {
$cacheable = Symphony::Database();
$cacheDriver = 'CacheDatabase';
}
if ($reuse === false) {
return new Cacheable($cacheable);
} elseif (!isset(self::$_pool[$cacheDriver])) {
self::$_pool[$cacheDriver] = new Cacheable($cacheable);
}
return self::$_pool[$cacheDriver];
} | [
"public",
"static",
"function",
"getCacheProvider",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"reuse",
"=",
"true",
")",
"{",
"$",
"cacheDriver",
"=",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"$",
"key",
",",
"'caching'",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"cacheDriver",
",",
"array_keys",
"(",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"getProvidersOf",
"(",
"'cache'",
")",
")",
")",
")",
"{",
"$",
"cacheable",
"=",
"new",
"$",
"cacheDriver",
";",
"}",
"else",
"{",
"$",
"cacheable",
"=",
"Symphony",
"::",
"Database",
"(",
")",
";",
"$",
"cacheDriver",
"=",
"'CacheDatabase'",
";",
"}",
"if",
"(",
"$",
"reuse",
"===",
"false",
")",
"{",
"return",
"new",
"Cacheable",
"(",
"$",
"cacheable",
")",
";",
"}",
"elseif",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"_pool",
"[",
"$",
"cacheDriver",
"]",
")",
")",
"{",
"self",
"::",
"$",
"_pool",
"[",
"$",
"cacheDriver",
"]",
"=",
"new",
"Cacheable",
"(",
"$",
"cacheable",
")",
";",
"}",
"return",
"self",
"::",
"$",
"_pool",
"[",
"$",
"cacheDriver",
"]",
";",
"}"
] | This function will return the `Cacheable` object with the appropriate
caching layer for the given `$key`. This `$key` should be stored in
the Symphony configuration in the caching group with a reference
to the class of the caching object. If the key is not found, this
will return a default `Cacheable` object created with the MySQL driver.
@since Symphony 2.4
@param string $key
Should be a reference in the Configuration file to the Caching class
@param boolean $reuse
By default true, which will reuse an existing Cacheable object of `$key`
if it exists. If false, a new instance will be generated.
@return Cacheable | [
"This",
"function",
"will",
"return",
"the",
"Cacheable",
"object",
"with",
"the",
"appropriate",
"caching",
"layer",
"for",
"the",
"given",
"$key",
".",
"This",
"$key",
"should",
"be",
"stored",
"in",
"the",
"Symphony",
"configuration",
"in",
"the",
"caching",
"group",
"with",
"a",
"reference",
"to",
"the",
"class",
"of",
"the",
"caching",
"object",
".",
"If",
"the",
"key",
"is",
"not",
"found",
"this",
"will",
"return",
"a",
"default",
"Cacheable",
"object",
"created",
"with",
"the",
"MySQL",
"driver",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L278-L296 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.__requiresInstallation | private static function __requiresInstallation($name)
{
self::__buildExtensionList();
$id = self::$_extensions[$name]['id'];
return (is_numeric($id) ? false : true);
} | php | private static function __requiresInstallation($name)
{
self::__buildExtensionList();
$id = self::$_extensions[$name]['id'];
return (is_numeric($id) ? false : true);
} | [
"private",
"static",
"function",
"__requiresInstallation",
"(",
"$",
"name",
")",
"{",
"self",
"::",
"__buildExtensionList",
"(",
")",
";",
"$",
"id",
"=",
"self",
"::",
"$",
"_extensions",
"[",
"$",
"name",
"]",
"[",
"'id'",
"]",
";",
"return",
"(",
"is_numeric",
"(",
"$",
"id",
")",
"?",
"false",
":",
"true",
")",
";",
"}"
] | Determines whether the current extension is installed or not by checking
for an id in `tbl_extensions`
@param string $name
The name of the Extension Class minus the extension prefix.
@return boolean | [
"Determines",
"whether",
"the",
"current",
"extension",
"is",
"installed",
"or",
"not",
"by",
"checking",
"for",
"an",
"id",
"in",
"tbl_extensions"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L306-L312 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.__requiresUpdate | private static function __requiresUpdate($name, $file_version)
{
$installed_version = self::fetchInstalledVersion($name);
if (is_null($installed_version)) {
return false;
}
return (version_compare($installed_version, $file_version, '<') ? $installed_version : false);
} | php | private static function __requiresUpdate($name, $file_version)
{
$installed_version = self::fetchInstalledVersion($name);
if (is_null($installed_version)) {
return false;
}
return (version_compare($installed_version, $file_version, '<') ? $installed_version : false);
} | [
"private",
"static",
"function",
"__requiresUpdate",
"(",
"$",
"name",
",",
"$",
"file_version",
")",
"{",
"$",
"installed_version",
"=",
"self",
"::",
"fetchInstalledVersion",
"(",
"$",
"name",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"installed_version",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"version_compare",
"(",
"$",
"installed_version",
",",
"$",
"file_version",
",",
"'<'",
")",
"?",
"$",
"installed_version",
":",
"false",
")",
";",
"}"
] | Determines whether an extension needs to be updated or not using
PHP's `version_compare` function. This function will return the
installed version if the extension requires an update, or
false otherwise.
@param string $name
The name of the Extension Class minus the extension prefix.
@param string $file_version
The version of the extension from the **file**, not the Database.
@return string|boolean
If the given extension (by $name) requires updating, the installed
version is returned, otherwise, if the extension doesn't require
updating, false. | [
"Determines",
"whether",
"an",
"extension",
"needs",
"to",
"be",
"updated",
"or",
"not",
"using",
"PHP",
"s",
"version_compare",
"function",
".",
"This",
"function",
"will",
"return",
"the",
"installed",
"version",
"if",
"the",
"extension",
"requires",
"an",
"update",
"or",
"false",
"otherwise",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L329-L338 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.enable | public static function enable($name)
{
$obj = self::getInstance($name);
// If not installed, install it
if (self::__requiresInstallation($name) && $obj->install() === false) {
// If the installation failed, run the uninstall method which
// should rollback the install method. #1326
$obj->uninstall();
return false;
// If the extension requires updating before enabling, then update it
} elseif (($about = self::about($name)) && ($previousVersion = self::__requiresUpdate($name, $about['version'])) !== false) {
$obj->update($previousVersion);
}
if (!isset($about)) {
$about = self::about($name);
}
$id = self::fetchExtensionID($name);
$fields = array(
'name' => $name,
'status' => 'enabled',
'version' => $about['version']
);
// If there's no $id, the extension needs to be installed
if (is_null($id)) {
Symphony::Database()->insert($fields, 'tbl_extensions');
self::__buildExtensionList(true);
// Extension is installed, so update!
} else {
Symphony::Database()->update($fields, 'tbl_extensions', sprintf(" `id` = %d ", $id));
}
self::registerDelegates($name);
// Now enable the extension
$obj->enable();
return true;
} | php | public static function enable($name)
{
$obj = self::getInstance($name);
// If not installed, install it
if (self::__requiresInstallation($name) && $obj->install() === false) {
// If the installation failed, run the uninstall method which
// should rollback the install method. #1326
$obj->uninstall();
return false;
// If the extension requires updating before enabling, then update it
} elseif (($about = self::about($name)) && ($previousVersion = self::__requiresUpdate($name, $about['version'])) !== false) {
$obj->update($previousVersion);
}
if (!isset($about)) {
$about = self::about($name);
}
$id = self::fetchExtensionID($name);
$fields = array(
'name' => $name,
'status' => 'enabled',
'version' => $about['version']
);
// If there's no $id, the extension needs to be installed
if (is_null($id)) {
Symphony::Database()->insert($fields, 'tbl_extensions');
self::__buildExtensionList(true);
// Extension is installed, so update!
} else {
Symphony::Database()->update($fields, 'tbl_extensions', sprintf(" `id` = %d ", $id));
}
self::registerDelegates($name);
// Now enable the extension
$obj->enable();
return true;
} | [
"public",
"static",
"function",
"enable",
"(",
"$",
"name",
")",
"{",
"$",
"obj",
"=",
"self",
"::",
"getInstance",
"(",
"$",
"name",
")",
";",
"// If not installed, install it",
"if",
"(",
"self",
"::",
"__requiresInstallation",
"(",
"$",
"name",
")",
"&&",
"$",
"obj",
"->",
"install",
"(",
")",
"===",
"false",
")",
"{",
"// If the installation failed, run the uninstall method which",
"// should rollback the install method. #1326",
"$",
"obj",
"->",
"uninstall",
"(",
")",
";",
"return",
"false",
";",
"// If the extension requires updating before enabling, then update it",
"}",
"elseif",
"(",
"(",
"$",
"about",
"=",
"self",
"::",
"about",
"(",
"$",
"name",
")",
")",
"&&",
"(",
"$",
"previousVersion",
"=",
"self",
"::",
"__requiresUpdate",
"(",
"$",
"name",
",",
"$",
"about",
"[",
"'version'",
"]",
")",
")",
"!==",
"false",
")",
"{",
"$",
"obj",
"->",
"update",
"(",
"$",
"previousVersion",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"about",
")",
")",
"{",
"$",
"about",
"=",
"self",
"::",
"about",
"(",
"$",
"name",
")",
";",
"}",
"$",
"id",
"=",
"self",
"::",
"fetchExtensionID",
"(",
"$",
"name",
")",
";",
"$",
"fields",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"name",
",",
"'status'",
"=>",
"'enabled'",
",",
"'version'",
"=>",
"$",
"about",
"[",
"'version'",
"]",
")",
";",
"// If there's no $id, the extension needs to be installed",
"if",
"(",
"is_null",
"(",
"$",
"id",
")",
")",
"{",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"insert",
"(",
"$",
"fields",
",",
"'tbl_extensions'",
")",
";",
"self",
"::",
"__buildExtensionList",
"(",
"true",
")",
";",
"// Extension is installed, so update!",
"}",
"else",
"{",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"update",
"(",
"$",
"fields",
",",
"'tbl_extensions'",
",",
"sprintf",
"(",
"\" `id` = %d \"",
",",
"$",
"id",
")",
")",
";",
"}",
"self",
"::",
"registerDelegates",
"(",
"$",
"name",
")",
";",
"// Now enable the extension",
"$",
"obj",
"->",
"enable",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Enabling an extension will re-register all it's delegates with Symphony.
It will also install or update the extension if needs be by calling the
extensions respective install and update methods. The enable method is
of the extension object is finally called.
@see toolkit.ExtensionManager#registerDelegates()
@see toolkit.ExtensionManager#__canUninstallOrDisable()
@param string $name
The name of the Extension Class minus the extension prefix.
@throws SymphonyErrorPage
@throws Exception
@return boolean | [
"Enabling",
"an",
"extension",
"will",
"re",
"-",
"register",
"all",
"it",
"s",
"delegates",
"with",
"Symphony",
".",
"It",
"will",
"also",
"install",
"or",
"update",
"the",
"extension",
"if",
"needs",
"be",
"by",
"calling",
"the",
"extensions",
"respective",
"install",
"and",
"update",
"methods",
".",
"The",
"enable",
"method",
"is",
"of",
"the",
"extension",
"object",
"is",
"finally",
"called",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L354-L398 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.disable | public static function disable($name)
{
$obj = self::getInstance($name);
self::__canUninstallOrDisable($obj);
$info = self::about($name);
$id = self::fetchExtensionID($name);
Symphony::Database()->update(
array(
'name' => $name,
'status' => 'disabled',
'version' => $info['version']
),
'tbl_extensions',
sprintf(" `id` = %d ", $id)
);
$obj->disable();
self::removeDelegates($name);
return true;
} | php | public static function disable($name)
{
$obj = self::getInstance($name);
self::__canUninstallOrDisable($obj);
$info = self::about($name);
$id = self::fetchExtensionID($name);
Symphony::Database()->update(
array(
'name' => $name,
'status' => 'disabled',
'version' => $info['version']
),
'tbl_extensions',
sprintf(" `id` = %d ", $id)
);
$obj->disable();
self::removeDelegates($name);
return true;
} | [
"public",
"static",
"function",
"disable",
"(",
"$",
"name",
")",
"{",
"$",
"obj",
"=",
"self",
"::",
"getInstance",
"(",
"$",
"name",
")",
";",
"self",
"::",
"__canUninstallOrDisable",
"(",
"$",
"obj",
")",
";",
"$",
"info",
"=",
"self",
"::",
"about",
"(",
"$",
"name",
")",
";",
"$",
"id",
"=",
"self",
"::",
"fetchExtensionID",
"(",
"$",
"name",
")",
";",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"update",
"(",
"array",
"(",
"'name'",
"=>",
"$",
"name",
",",
"'status'",
"=>",
"'disabled'",
",",
"'version'",
"=>",
"$",
"info",
"[",
"'version'",
"]",
")",
",",
"'tbl_extensions'",
",",
"sprintf",
"(",
"\" `id` = %d \"",
",",
"$",
"id",
")",
")",
";",
"$",
"obj",
"->",
"disable",
"(",
")",
";",
"self",
"::",
"removeDelegates",
"(",
"$",
"name",
")",
";",
"return",
"true",
";",
"}"
] | Disabling an extension will prevent it from executing but retain all it's
settings in the relevant tables. Symphony checks that an extension can
be disabled using the `canUninstallorDisable()` before removing
all delegate subscriptions from the database and calling the extension's
`disable()` function.
@see toolkit.ExtensionManager#removeDelegates()
@see toolkit.ExtensionManager#__canUninstallOrDisable()
@param string $name
The name of the Extension Class minus the extension prefix.
@throws DatabaseException
@throws SymphonyErrorPage
@throws Exception
@return boolean | [
"Disabling",
"an",
"extension",
"will",
"prevent",
"it",
"from",
"executing",
"but",
"retain",
"all",
"it",
"s",
"settings",
"in",
"the",
"relevant",
"tables",
".",
"Symphony",
"checks",
"that",
"an",
"extension",
"can",
"be",
"disabled",
"using",
"the",
"canUninstallorDisable",
"()",
"before",
"removing",
"all",
"delegate",
"subscriptions",
"from",
"the",
"database",
"and",
"calling",
"the",
"extension",
"s",
"disable",
"()",
"function",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L416-L440 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.uninstall | public static function uninstall($name)
{
// If this function is called because the extension doesn't exist,
// then catch the error and just remove from the database. This
// means that the uninstall() function will not run on the extension,
// which may be a blessing in disguise as no entry data will be removed
try {
$obj = self::getInstance($name);
self::__canUninstallOrDisable($obj);
$obj->uninstall();
} catch (SymphonyErrorPage $ex) {
// Create a consistant key
$key = str_replace('-', '_', $ex->getTemplateName());
if ($key !== 'missing_extension') {
throw $ex;
}
}
self::removeDelegates($name);
Symphony::Database()->delete('tbl_extensions', sprintf(" `name` = '%s' ", $name));
return true;
} | php | public static function uninstall($name)
{
// If this function is called because the extension doesn't exist,
// then catch the error and just remove from the database. This
// means that the uninstall() function will not run on the extension,
// which may be a blessing in disguise as no entry data will be removed
try {
$obj = self::getInstance($name);
self::__canUninstallOrDisable($obj);
$obj->uninstall();
} catch (SymphonyErrorPage $ex) {
// Create a consistant key
$key = str_replace('-', '_', $ex->getTemplateName());
if ($key !== 'missing_extension') {
throw $ex;
}
}
self::removeDelegates($name);
Symphony::Database()->delete('tbl_extensions', sprintf(" `name` = '%s' ", $name));
return true;
} | [
"public",
"static",
"function",
"uninstall",
"(",
"$",
"name",
")",
"{",
"// If this function is called because the extension doesn't exist,",
"// then catch the error and just remove from the database. This",
"// means that the uninstall() function will not run on the extension,",
"// which may be a blessing in disguise as no entry data will be removed",
"try",
"{",
"$",
"obj",
"=",
"self",
"::",
"getInstance",
"(",
"$",
"name",
")",
";",
"self",
"::",
"__canUninstallOrDisable",
"(",
"$",
"obj",
")",
";",
"$",
"obj",
"->",
"uninstall",
"(",
")",
";",
"}",
"catch",
"(",
"SymphonyErrorPage",
"$",
"ex",
")",
"{",
"// Create a consistant key",
"$",
"key",
"=",
"str_replace",
"(",
"'-'",
",",
"'_'",
",",
"$",
"ex",
"->",
"getTemplateName",
"(",
")",
")",
";",
"if",
"(",
"$",
"key",
"!==",
"'missing_extension'",
")",
"{",
"throw",
"$",
"ex",
";",
"}",
"}",
"self",
"::",
"removeDelegates",
"(",
"$",
"name",
")",
";",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"delete",
"(",
"'tbl_extensions'",
",",
"sprintf",
"(",
"\" `name` = '%s' \"",
",",
"$",
"name",
")",
")",
";",
"return",
"true",
";",
"}"
] | Uninstalling an extension will unregister all delegate subscriptions and
remove all extension settings. Symphony checks that an extension can
be uninstalled using the `canUninstallorDisable()` before calling
the extension's `uninstall()` function. Alternatively, if this function
is called because the extension described by `$name` cannot be found
it's delegates and extension meta information will just be removed from the
database.
@see toolkit.ExtensionManager#removeDelegates()
@see toolkit.ExtensionManager#__canUninstallOrDisable()
@param string $name
The name of the Extension Class minus the extension prefix.
@throws Exception
@throws SymphonyErrorPage
@throws DatabaseException
@throws Exception
@return boolean | [
"Uninstalling",
"an",
"extension",
"will",
"unregister",
"all",
"delegate",
"subscriptions",
"and",
"remove",
"all",
"extension",
"settings",
".",
"Symphony",
"checks",
"that",
"an",
"extension",
"can",
"be",
"uninstalled",
"using",
"the",
"canUninstallorDisable",
"()",
"before",
"calling",
"the",
"extension",
"s",
"uninstall",
"()",
"function",
".",
"Alternatively",
"if",
"this",
"function",
"is",
"called",
"because",
"the",
"extension",
"described",
"by",
"$name",
"cannot",
"be",
"found",
"it",
"s",
"delegates",
"and",
"extension",
"meta",
"information",
"will",
"just",
"be",
"removed",
"from",
"the",
"database",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L461-L484 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.registerDelegates | public static function registerDelegates($name)
{
$obj = self::getInstance($name);
$id = self::fetchExtensionID($name);
if (!$id) {
return false;
}
Symphony::Database()->delete('tbl_extensions_delegates', sprintf("
`extension_id` = %d ", $id
));
$delegates = $obj->getSubscribedDelegates();
if (is_array($delegates) && !empty($delegates)) {
foreach ($delegates as $delegate) {
Symphony::Database()->insert(
array(
'extension_id' => $id,
'page' => $delegate['page'],
'delegate' => $delegate['delegate'],
'callback' => $delegate['callback']
),
'tbl_extensions_delegates'
);
}
}
// Remove the unused DB records
self::cleanupDatabase();
return $id;
} | php | public static function registerDelegates($name)
{
$obj = self::getInstance($name);
$id = self::fetchExtensionID($name);
if (!$id) {
return false;
}
Symphony::Database()->delete('tbl_extensions_delegates', sprintf("
`extension_id` = %d ", $id
));
$delegates = $obj->getSubscribedDelegates();
if (is_array($delegates) && !empty($delegates)) {
foreach ($delegates as $delegate) {
Symphony::Database()->insert(
array(
'extension_id' => $id,
'page' => $delegate['page'],
'delegate' => $delegate['delegate'],
'callback' => $delegate['callback']
),
'tbl_extensions_delegates'
);
}
}
// Remove the unused DB records
self::cleanupDatabase();
return $id;
} | [
"public",
"static",
"function",
"registerDelegates",
"(",
"$",
"name",
")",
"{",
"$",
"obj",
"=",
"self",
"::",
"getInstance",
"(",
"$",
"name",
")",
";",
"$",
"id",
"=",
"self",
"::",
"fetchExtensionID",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"$",
"id",
")",
"{",
"return",
"false",
";",
"}",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"delete",
"(",
"'tbl_extensions_delegates'",
",",
"sprintf",
"(",
"\"\n `extension_id` = %d \"",
",",
"$",
"id",
")",
")",
";",
"$",
"delegates",
"=",
"$",
"obj",
"->",
"getSubscribedDelegates",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"delegates",
")",
"&&",
"!",
"empty",
"(",
"$",
"delegates",
")",
")",
"{",
"foreach",
"(",
"$",
"delegates",
"as",
"$",
"delegate",
")",
"{",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"insert",
"(",
"array",
"(",
"'extension_id'",
"=>",
"$",
"id",
",",
"'page'",
"=>",
"$",
"delegate",
"[",
"'page'",
"]",
",",
"'delegate'",
"=>",
"$",
"delegate",
"[",
"'delegate'",
"]",
",",
"'callback'",
"=>",
"$",
"delegate",
"[",
"'callback'",
"]",
")",
",",
"'tbl_extensions_delegates'",
")",
";",
"}",
"}",
"// Remove the unused DB records",
"self",
"::",
"cleanupDatabase",
"(",
")",
";",
"return",
"$",
"id",
";",
"}"
] | This functions registers an extensions delegates in `tbl_extensions_delegates`.
@param string $name
The name of the Extension Class minus the extension prefix.
@throws Exception
@throws SymphonyErrorPage
@return integer
The Extension ID | [
"This",
"functions",
"registers",
"an",
"extensions",
"delegates",
"in",
"tbl_extensions_delegates",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L496-L529 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.removeDelegates | public static function removeDelegates($name)
{
$delegates = Symphony::Database()->fetchCol('id', sprintf("
SELECT tbl_extensions_delegates.`id`
FROM `tbl_extensions_delegates`
LEFT JOIN `tbl_extensions`
ON (`tbl_extensions`.id = `tbl_extensions_delegates`.extension_id)
WHERE `tbl_extensions`.name = '%s'",
$name
));
if (!empty($delegates)) {
Symphony::Database()->delete('tbl_extensions_delegates', " `id` IN ('". implode("', '", $delegates). "') ");
}
// Remove the unused DB records
self::cleanupDatabase();
return true;
} | php | public static function removeDelegates($name)
{
$delegates = Symphony::Database()->fetchCol('id', sprintf("
SELECT tbl_extensions_delegates.`id`
FROM `tbl_extensions_delegates`
LEFT JOIN `tbl_extensions`
ON (`tbl_extensions`.id = `tbl_extensions_delegates`.extension_id)
WHERE `tbl_extensions`.name = '%s'",
$name
));
if (!empty($delegates)) {
Symphony::Database()->delete('tbl_extensions_delegates', " `id` IN ('". implode("', '", $delegates). "') ");
}
// Remove the unused DB records
self::cleanupDatabase();
return true;
} | [
"public",
"static",
"function",
"removeDelegates",
"(",
"$",
"name",
")",
"{",
"$",
"delegates",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchCol",
"(",
"'id'",
",",
"sprintf",
"(",
"\"\n SELECT tbl_extensions_delegates.`id`\n FROM `tbl_extensions_delegates`\n LEFT JOIN `tbl_extensions`\n ON (`tbl_extensions`.id = `tbl_extensions_delegates`.extension_id)\n WHERE `tbl_extensions`.name = '%s'\"",
",",
"$",
"name",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"delegates",
")",
")",
"{",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"delete",
"(",
"'tbl_extensions_delegates'",
",",
"\" `id` IN ('\"",
".",
"implode",
"(",
"\"', '\"",
",",
"$",
"delegates",
")",
".",
"\"') \"",
")",
";",
"}",
"// Remove the unused DB records",
"self",
"::",
"cleanupDatabase",
"(",
")",
";",
"return",
"true",
";",
"}"
] | This function will remove all delegate subscriptions for an extension
given an extension's name. This triggers `cleanupDatabase()`
@see toolkit.ExtensionManager#cleanupDatabase()
@param string $name
The name of the Extension Class minus the extension prefix.
@return boolean | [
"This",
"function",
"will",
"remove",
"all",
"delegate",
"subscriptions",
"for",
"an",
"extension",
"given",
"an",
"extension",
"s",
"name",
".",
"This",
"triggers",
"cleanupDatabase",
"()"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L540-L559 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.__canUninstallOrDisable | private static function __canUninstallOrDisable(Extension $obj)
{
$extension_handle = strtolower(preg_replace('/^extension_/i', null, get_class($obj)));
$about = self::about($extension_handle);
// Fields:
if (is_dir(EXTENSIONS . "/{$extension_handle}/fields")) {
foreach (glob(EXTENSIONS . "/{$extension_handle}/fields/field.*.php") as $file) {
$type = preg_replace(array('/^field\./i', '/\.php$/i'), null, basename($file));
if (FieldManager::isFieldUsed($type)) {
throw new Exception(
__('The field ‘%s’, provided by the Extension ‘%s’, is currently in use.', array(basename($file), $about['name']))
. ' ' . __("Please remove it from your sections prior to uninstalling or disabling.")
);
}
}
}
// Data Sources:
if (is_dir(EXTENSIONS . "/{$extension_handle}/data-sources")) {
foreach (glob(EXTENSIONS . "/{$extension_handle}/data-sources/data.*.php") as $file) {
$handle = preg_replace(array('/^data\./i', '/\.php$/i'), null, basename($file));
if (PageManager::isDataSourceUsed($handle)) {
throw new Exception(
__('The Data Source ‘%s’, provided by the Extension ‘%s’, is currently in use.', array(basename($file), $about['name']))
. ' ' . __("Please remove it from your pages prior to uninstalling or disabling.")
);
}
}
}
// Events
if (is_dir(EXTENSIONS . "/{$extension_handle}/events")) {
foreach (glob(EXTENSIONS . "/{$extension_handle}/events/event.*.php") as $file) {
$handle = preg_replace(array('/^event\./i', '/\.php$/i'), null, basename($file));
if (PageManager::isEventUsed($handle)) {
throw new Exception(
__('The Event ‘%s’, provided by the Extension ‘%s’, is currently in use.', array(basename($file), $about['name']))
. ' ' . __("Please remove it from your pages prior to uninstalling or disabling.")
);
}
}
}
// Text Formatters
if (is_dir(EXTENSIONS . "/{$extension_handle}/text-formatters")) {
foreach (glob(EXTENSIONS . "/{$extension_handle}/text-formatters/formatter.*.php") as $file) {
$handle = preg_replace(array('/^formatter\./i', '/\.php$/i'), null, basename($file));
if (FieldManager::isTextFormatterUsed($handle)) {
throw new Exception(
__('The Text Formatter ‘%s’, provided by the Extension ‘%s’, is currently in use.', array(basename($file), $about['name']))
. ' ' . __("Please remove it from your fields prior to uninstalling or disabling.")
);
}
}
}
} | php | private static function __canUninstallOrDisable(Extension $obj)
{
$extension_handle = strtolower(preg_replace('/^extension_/i', null, get_class($obj)));
$about = self::about($extension_handle);
// Fields:
if (is_dir(EXTENSIONS . "/{$extension_handle}/fields")) {
foreach (glob(EXTENSIONS . "/{$extension_handle}/fields/field.*.php") as $file) {
$type = preg_replace(array('/^field\./i', '/\.php$/i'), null, basename($file));
if (FieldManager::isFieldUsed($type)) {
throw new Exception(
__('The field ‘%s’, provided by the Extension ‘%s’, is currently in use.', array(basename($file), $about['name']))
. ' ' . __("Please remove it from your sections prior to uninstalling or disabling.")
);
}
}
}
// Data Sources:
if (is_dir(EXTENSIONS . "/{$extension_handle}/data-sources")) {
foreach (glob(EXTENSIONS . "/{$extension_handle}/data-sources/data.*.php") as $file) {
$handle = preg_replace(array('/^data\./i', '/\.php$/i'), null, basename($file));
if (PageManager::isDataSourceUsed($handle)) {
throw new Exception(
__('The Data Source ‘%s’, provided by the Extension ‘%s’, is currently in use.', array(basename($file), $about['name']))
. ' ' . __("Please remove it from your pages prior to uninstalling or disabling.")
);
}
}
}
// Events
if (is_dir(EXTENSIONS . "/{$extension_handle}/events")) {
foreach (glob(EXTENSIONS . "/{$extension_handle}/events/event.*.php") as $file) {
$handle = preg_replace(array('/^event\./i', '/\.php$/i'), null, basename($file));
if (PageManager::isEventUsed($handle)) {
throw new Exception(
__('The Event ‘%s’, provided by the Extension ‘%s’, is currently in use.', array(basename($file), $about['name']))
. ' ' . __("Please remove it from your pages prior to uninstalling or disabling.")
);
}
}
}
// Text Formatters
if (is_dir(EXTENSIONS . "/{$extension_handle}/text-formatters")) {
foreach (glob(EXTENSIONS . "/{$extension_handle}/text-formatters/formatter.*.php") as $file) {
$handle = preg_replace(array('/^formatter\./i', '/\.php$/i'), null, basename($file));
if (FieldManager::isTextFormatterUsed($handle)) {
throw new Exception(
__('The Text Formatter ‘%s’, provided by the Extension ‘%s’, is currently in use.', array(basename($file), $about['name']))
. ' ' . __("Please remove it from your fields prior to uninstalling or disabling.")
);
}
}
}
} | [
"private",
"static",
"function",
"__canUninstallOrDisable",
"(",
"Extension",
"$",
"obj",
")",
"{",
"$",
"extension_handle",
"=",
"strtolower",
"(",
"preg_replace",
"(",
"'/^extension_/i'",
",",
"null",
",",
"get_class",
"(",
"$",
"obj",
")",
")",
")",
";",
"$",
"about",
"=",
"self",
"::",
"about",
"(",
"$",
"extension_handle",
")",
";",
"// Fields:",
"if",
"(",
"is_dir",
"(",
"EXTENSIONS",
".",
"\"/{$extension_handle}/fields\"",
")",
")",
"{",
"foreach",
"(",
"glob",
"(",
"EXTENSIONS",
".",
"\"/{$extension_handle}/fields/field.*.php\"",
")",
"as",
"$",
"file",
")",
"{",
"$",
"type",
"=",
"preg_replace",
"(",
"array",
"(",
"'/^field\\./i'",
",",
"'/\\.php$/i'",
")",
",",
"null",
",",
"basename",
"(",
"$",
"file",
")",
")",
";",
"if",
"(",
"FieldManager",
"::",
"isFieldUsed",
"(",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"__",
"(",
"'The field ‘%s’, provided by the Extension ‘%s’, is currently in use.', array(",
"b",
"senam",
"e",
"($file),",
" ",
"$",
"abou",
"t",
"[",
"n",
"ame']",
")",
")",
"",
"",
"",
".",
"' '",
".",
"__",
"(",
"\"Please remove it from your sections prior to uninstalling or disabling.\"",
")",
")",
";",
"}",
"}",
"}",
"// Data Sources:",
"if",
"(",
"is_dir",
"(",
"EXTENSIONS",
".",
"\"/{$extension_handle}/data-sources\"",
")",
")",
"{",
"foreach",
"(",
"glob",
"(",
"EXTENSIONS",
".",
"\"/{$extension_handle}/data-sources/data.*.php\"",
")",
"as",
"$",
"file",
")",
"{",
"$",
"handle",
"=",
"preg_replace",
"(",
"array",
"(",
"'/^data\\./i'",
",",
"'/\\.php$/i'",
")",
",",
"null",
",",
"basename",
"(",
"$",
"file",
")",
")",
";",
"if",
"(",
"PageManager",
"::",
"isDataSourceUsed",
"(",
"$",
"handle",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"__",
"(",
"'The Data Source ‘%s’, provided by the Extension ‘%s’, is currently in use.', array(",
"b",
"senam",
"e",
"($file),",
" ",
"$",
"abou",
"t",
"[",
"n",
"ame']",
")",
")",
"",
"",
"",
".",
"' '",
".",
"__",
"(",
"\"Please remove it from your pages prior to uninstalling or disabling.\"",
")",
")",
";",
"}",
"}",
"}",
"// Events",
"if",
"(",
"is_dir",
"(",
"EXTENSIONS",
".",
"\"/{$extension_handle}/events\"",
")",
")",
"{",
"foreach",
"(",
"glob",
"(",
"EXTENSIONS",
".",
"\"/{$extension_handle}/events/event.*.php\"",
")",
"as",
"$",
"file",
")",
"{",
"$",
"handle",
"=",
"preg_replace",
"(",
"array",
"(",
"'/^event\\./i'",
",",
"'/\\.php$/i'",
")",
",",
"null",
",",
"basename",
"(",
"$",
"file",
")",
")",
";",
"if",
"(",
"PageManager",
"::",
"isEventUsed",
"(",
"$",
"handle",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"__",
"(",
"'The Event ‘%s’, provided by the Extension ‘%s’, is currently in use.', array(",
"b",
"senam",
"e",
"($file),",
" ",
"$",
"abou",
"t",
"[",
"n",
"ame']",
")",
")",
"",
"",
"",
".",
"' '",
".",
"__",
"(",
"\"Please remove it from your pages prior to uninstalling or disabling.\"",
")",
")",
";",
"}",
"}",
"}",
"// Text Formatters",
"if",
"(",
"is_dir",
"(",
"EXTENSIONS",
".",
"\"/{$extension_handle}/text-formatters\"",
")",
")",
"{",
"foreach",
"(",
"glob",
"(",
"EXTENSIONS",
".",
"\"/{$extension_handle}/text-formatters/formatter.*.php\"",
")",
"as",
"$",
"file",
")",
"{",
"$",
"handle",
"=",
"preg_replace",
"(",
"array",
"(",
"'/^formatter\\./i'",
",",
"'/\\.php$/i'",
")",
",",
"null",
",",
"basename",
"(",
"$",
"file",
")",
")",
";",
"if",
"(",
"FieldManager",
"::",
"isTextFormatterUsed",
"(",
"$",
"handle",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"__",
"(",
"'The Text Formatter ‘%s’, provided by the Extension ‘%s’, is currently in use.', array(",
"b",
"senam",
"e",
"($file),",
" ",
"$",
"abou",
"t",
"[",
"n",
"ame']",
")",
")",
"",
"",
"",
".",
"' '",
".",
"__",
"(",
"\"Please remove it from your fields prior to uninstalling or disabling.\"",
")",
")",
";",
"}",
"}",
"}",
"}"
] | This function checks that if the given extension has provided Fields,
Data Sources or Events, that they aren't in use before the extension
is uninstalled or disabled. This prevents exceptions from occurring when
accessing an object that was using something provided by this Extension
can't anymore because it has been removed.
@param Extension $obj
An extension object
@throws SymphonyErrorPage
@throws Exception | [
"This",
"function",
"checks",
"that",
"if",
"the",
"given",
"extension",
"has",
"provided",
"Fields",
"Data",
"Sources",
"or",
"Events",
"that",
"they",
"aren",
"t",
"in",
"use",
"before",
"the",
"extension",
"is",
"uninstalled",
"or",
"disabled",
".",
"This",
"prevents",
"exceptions",
"from",
"occurring",
"when",
"accessing",
"an",
"object",
"that",
"was",
"using",
"something",
"provided",
"by",
"this",
"Extension",
"can",
"t",
"anymore",
"because",
"it",
"has",
"been",
"removed",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L573-L633 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.notifyMembers | public static function notifyMembers($delegate, $page, array $context = array())
{
// Make sure $page is an array
if (!is_array($page)) {
$page = array($page);
}
// Support for global delegate subscription
if (!in_array('*', $page)) {
$page[] = '*';
}
$services = array();
if (isset(self::$_subscriptions[$delegate])) {
foreach (self::$_subscriptions[$delegate] as $subscription) {
if (!in_array($subscription['page'], $page)) {
continue;
}
$services[] = $subscription;
}
}
if (empty($services)) {
return null;
}
$context += array('page' => $page, 'delegate' => $delegate);
$profiling = Symphony::Profiler() instanceof Profiler;
foreach ($services as $s) {
if ($profiling) {
// Initial seeding and query count
Symphony::Profiler()->seed();
$queries = Symphony::Database()->queryCount();
}
// Get instance of extension and execute the callback passing
// the `$context` along
$obj = self::getInstance($s['name']);
if (is_object($obj) && method_exists($obj, $s['callback'])) {
$obj->{$s['callback']}($context);
}
// Complete the Profiling sample
if ($profiling) {
$queries = Symphony::Database()->queryCount() - $queries;
Symphony::Profiler()->sample($delegate . '|' . $s['name'], PROFILE_LAP, 'Delegate', $queries);
}
}
} | php | public static function notifyMembers($delegate, $page, array $context = array())
{
// Make sure $page is an array
if (!is_array($page)) {
$page = array($page);
}
// Support for global delegate subscription
if (!in_array('*', $page)) {
$page[] = '*';
}
$services = array();
if (isset(self::$_subscriptions[$delegate])) {
foreach (self::$_subscriptions[$delegate] as $subscription) {
if (!in_array($subscription['page'], $page)) {
continue;
}
$services[] = $subscription;
}
}
if (empty($services)) {
return null;
}
$context += array('page' => $page, 'delegate' => $delegate);
$profiling = Symphony::Profiler() instanceof Profiler;
foreach ($services as $s) {
if ($profiling) {
// Initial seeding and query count
Symphony::Profiler()->seed();
$queries = Symphony::Database()->queryCount();
}
// Get instance of extension and execute the callback passing
// the `$context` along
$obj = self::getInstance($s['name']);
if (is_object($obj) && method_exists($obj, $s['callback'])) {
$obj->{$s['callback']}($context);
}
// Complete the Profiling sample
if ($profiling) {
$queries = Symphony::Database()->queryCount() - $queries;
Symphony::Profiler()->sample($delegate . '|' . $s['name'], PROFILE_LAP, 'Delegate', $queries);
}
}
} | [
"public",
"static",
"function",
"notifyMembers",
"(",
"$",
"delegate",
",",
"$",
"page",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"// Make sure $page is an array",
"if",
"(",
"!",
"is_array",
"(",
"$",
"page",
")",
")",
"{",
"$",
"page",
"=",
"array",
"(",
"$",
"page",
")",
";",
"}",
"// Support for global delegate subscription",
"if",
"(",
"!",
"in_array",
"(",
"'*'",
",",
"$",
"page",
")",
")",
"{",
"$",
"page",
"[",
"]",
"=",
"'*'",
";",
"}",
"$",
"services",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"_subscriptions",
"[",
"$",
"delegate",
"]",
")",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"_subscriptions",
"[",
"$",
"delegate",
"]",
"as",
"$",
"subscription",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"subscription",
"[",
"'page'",
"]",
",",
"$",
"page",
")",
")",
"{",
"continue",
";",
"}",
"$",
"services",
"[",
"]",
"=",
"$",
"subscription",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"services",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"context",
"+=",
"array",
"(",
"'page'",
"=>",
"$",
"page",
",",
"'delegate'",
"=>",
"$",
"delegate",
")",
";",
"$",
"profiling",
"=",
"Symphony",
"::",
"Profiler",
"(",
")",
"instanceof",
"Profiler",
";",
"foreach",
"(",
"$",
"services",
"as",
"$",
"s",
")",
"{",
"if",
"(",
"$",
"profiling",
")",
"{",
"// Initial seeding and query count",
"Symphony",
"::",
"Profiler",
"(",
")",
"->",
"seed",
"(",
")",
";",
"$",
"queries",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"queryCount",
"(",
")",
";",
"}",
"// Get instance of extension and execute the callback passing",
"// the `$context` along",
"$",
"obj",
"=",
"self",
"::",
"getInstance",
"(",
"$",
"s",
"[",
"'name'",
"]",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"obj",
")",
"&&",
"method_exists",
"(",
"$",
"obj",
",",
"$",
"s",
"[",
"'callback'",
"]",
")",
")",
"{",
"$",
"obj",
"->",
"{",
"$",
"s",
"[",
"'callback'",
"]",
"}",
"(",
"$",
"context",
")",
";",
"}",
"// Complete the Profiling sample",
"if",
"(",
"$",
"profiling",
")",
"{",
"$",
"queries",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"queryCount",
"(",
")",
"-",
"$",
"queries",
";",
"Symphony",
"::",
"Profiler",
"(",
")",
"->",
"sample",
"(",
"$",
"delegate",
".",
"'|'",
".",
"$",
"s",
"[",
"'name'",
"]",
",",
"PROFILE_LAP",
",",
"'Delegate'",
",",
"$",
"queries",
")",
";",
"}",
"}",
"}"
] | Given a delegate name, notify all extensions that have registered to that
delegate to executing their callbacks with a `$context` array parameter
that contains information about the current Symphony state.
@param string $delegate
The delegate name
@param string $page
The current page namespace that this delegate operates in
@param array $context
The `$context` param is an associative array that at minimum will contain
the current Administration class, the current page object and the delegate
name. Other context information may be passed to this function when it is
called. eg.
array(
'parent' =>& $this->Parent,
'page' => $page,
'delegate' => $delegate
);
@throws Exception
@throws SymphonyErrorPage
@return null|void | [
"Given",
"a",
"delegate",
"name",
"notify",
"all",
"extensions",
"that",
"have",
"registered",
"to",
"that",
"delegate",
"to",
"executing",
"their",
"callbacks",
"with",
"a",
"$context",
"array",
"parameter",
"that",
"contains",
"information",
"about",
"the",
"current",
"Symphony",
"state",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L659-L711 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.listInstalledHandles | public static function listInstalledHandles()
{
if (empty(self::$_enabled_extensions) && Symphony::Database()->isConnected()) {
self::$_enabled_extensions = Symphony::Database()->fetchCol(
'name',
"SELECT `name` FROM `tbl_extensions` WHERE `status` = 'enabled'"
);
}
return self::$_enabled_extensions;
} | php | public static function listInstalledHandles()
{
if (empty(self::$_enabled_extensions) && Symphony::Database()->isConnected()) {
self::$_enabled_extensions = Symphony::Database()->fetchCol(
'name',
"SELECT `name` FROM `tbl_extensions` WHERE `status` = 'enabled'"
);
}
return self::$_enabled_extensions;
} | [
"public",
"static",
"function",
"listInstalledHandles",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"self",
"::",
"$",
"_enabled_extensions",
")",
"&&",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"isConnected",
"(",
")",
")",
"{",
"self",
"::",
"$",
"_enabled_extensions",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchCol",
"(",
"'name'",
",",
"\"SELECT `name` FROM `tbl_extensions` WHERE `status` = 'enabled'\"",
")",
";",
"}",
"return",
"self",
"::",
"$",
"_enabled_extensions",
";",
"}"
] | Returns an array of all the enabled extensions available
@return array | [
"Returns",
"an",
"array",
"of",
"all",
"the",
"enabled",
"extensions",
"available"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L718-L727 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.listAll | public static function listAll($filter = '/^((?![-^?%:*|"<>]).)*$/')
{
$result = array();
$extensions = General::listDirStructure(EXTENSIONS, $filter, false, EXTENSIONS);
if (is_array($extensions) && !empty($extensions)) {
foreach ($extensions as $extension) {
$e = trim($extension, '/');
if ($about = self::about($e)) {
$result[$e] = $about;
}
}
}
return $result;
} | php | public static function listAll($filter = '/^((?![-^?%:*|"<>]).)*$/')
{
$result = array();
$extensions = General::listDirStructure(EXTENSIONS, $filter, false, EXTENSIONS);
if (is_array($extensions) && !empty($extensions)) {
foreach ($extensions as $extension) {
$e = trim($extension, '/');
if ($about = self::about($e)) {
$result[$e] = $about;
}
}
}
return $result;
} | [
"public",
"static",
"function",
"listAll",
"(",
"$",
"filter",
"=",
"'/^((?![-^?%:*|\"<>]).)*$/'",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"extensions",
"=",
"General",
"::",
"listDirStructure",
"(",
"EXTENSIONS",
",",
"$",
"filter",
",",
"false",
",",
"EXTENSIONS",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"extensions",
")",
"&&",
"!",
"empty",
"(",
"$",
"extensions",
")",
")",
"{",
"foreach",
"(",
"$",
"extensions",
"as",
"$",
"extension",
")",
"{",
"$",
"e",
"=",
"trim",
"(",
"$",
"extension",
",",
"'/'",
")",
";",
"if",
"(",
"$",
"about",
"=",
"self",
"::",
"about",
"(",
"$",
"e",
")",
")",
"{",
"$",
"result",
"[",
"$",
"e",
"]",
"=",
"$",
"about",
";",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Will return an associative array of all extensions and their about information
@param string $filter
Allows a regular expression to be passed to return only extensions whose
folders match the filter.
@throws SymphonyErrorPage
@throws Exception
@return array
An associative array with the key being the extension folder and the value
being the extension's about information | [
"Will",
"return",
"an",
"associative",
"array",
"of",
"all",
"extensions",
"and",
"their",
"about",
"information"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L741-L757 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.sortByAuthor | private static function sortByAuthor($a, $b, $i = 0)
{
$first = $a;
$second = $b;
if (isset($a[$i])) {
$first = $a[$i];
}
if (isset($b[$i])) {
$second = $b[$i];
}
if ($first == $a && $second == $b && $first['name'] == $second['name']) {
return 1;
} elseif ($first['name'] == $second['name']) {
return self::sortByAuthor($a, $b, $i + 1);
} else {
return ($first['name'] < $second['name']) ? -1 : 1;
}
} | php | private static function sortByAuthor($a, $b, $i = 0)
{
$first = $a;
$second = $b;
if (isset($a[$i])) {
$first = $a[$i];
}
if (isset($b[$i])) {
$second = $b[$i];
}
if ($first == $a && $second == $b && $first['name'] == $second['name']) {
return 1;
} elseif ($first['name'] == $second['name']) {
return self::sortByAuthor($a, $b, $i + 1);
} else {
return ($first['name'] < $second['name']) ? -1 : 1;
}
} | [
"private",
"static",
"function",
"sortByAuthor",
"(",
"$",
"a",
",",
"$",
"b",
",",
"$",
"i",
"=",
"0",
")",
"{",
"$",
"first",
"=",
"$",
"a",
";",
"$",
"second",
"=",
"$",
"b",
";",
"if",
"(",
"isset",
"(",
"$",
"a",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"first",
"=",
"$",
"a",
"[",
"$",
"i",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"b",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"second",
"=",
"$",
"b",
"[",
"$",
"i",
"]",
";",
"}",
"if",
"(",
"$",
"first",
"==",
"$",
"a",
"&&",
"$",
"second",
"==",
"$",
"b",
"&&",
"$",
"first",
"[",
"'name'",
"]",
"==",
"$",
"second",
"[",
"'name'",
"]",
")",
"{",
"return",
"1",
";",
"}",
"elseif",
"(",
"$",
"first",
"[",
"'name'",
"]",
"==",
"$",
"second",
"[",
"'name'",
"]",
")",
"{",
"return",
"self",
"::",
"sortByAuthor",
"(",
"$",
"a",
",",
"$",
"b",
",",
"$",
"i",
"+",
"1",
")",
";",
"}",
"else",
"{",
"return",
"(",
"$",
"first",
"[",
"'name'",
"]",
"<",
"$",
"second",
"[",
"'name'",
"]",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
"}"
] | Custom user sorting function used inside `fetch` to recursively sort authors
by their names.
@param array $a
@param array $b
@param integer $i
@return integer | [
"Custom",
"user",
"sorting",
"function",
"used",
"inside",
"fetch",
"to",
"recursively",
"sort",
"authors",
"by",
"their",
"names",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L768-L788 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.fetch | public static function fetch(array $select = array(), array $where = array(), $order_by = null)
{
$extensions = self::listAll();
$data = array();
if (empty($select) && empty($where) && is_null($order_by)) {
return $extensions;
}
if (empty($extensions)) {
return array();
}
if (!is_null($order_by)) {
$author = $name = $label = array();
$order_by = array_map('strtolower', explode(' ', $order_by));
$order = ($order_by[1] == 'desc') ? SORT_DESC : SORT_ASC;
$sort = $order_by[0];
if ($sort == 'author') {
foreach ($extensions as $key => $about) {
$author[$key] = $about['author'];
}
uasort($author, array('self', 'sortByAuthor'));
if ($order == SORT_DESC) {
$author = array_reverse($author);
}
foreach ($author as $key => $value) {
$data[$key] = $extensions[$key];
}
$extensions = $data;
} elseif ($sort == 'name') {
foreach ($extensions as $key => $about) {
$name[$key] = strtolower($about['name']);
$label[$key] = $key;
}
array_multisort($name, $order, $label, $order, $extensions);
}
}
foreach ($extensions as $i => $e) {
$data[$i] = array();
foreach ($e as $key => $value) {
// If $select is empty, we assume every field is requested
if (in_array($key, $select) || empty($select)) {
$data[$i][$key] = $value;
}
}
}
return $data;
} | php | public static function fetch(array $select = array(), array $where = array(), $order_by = null)
{
$extensions = self::listAll();
$data = array();
if (empty($select) && empty($where) && is_null($order_by)) {
return $extensions;
}
if (empty($extensions)) {
return array();
}
if (!is_null($order_by)) {
$author = $name = $label = array();
$order_by = array_map('strtolower', explode(' ', $order_by));
$order = ($order_by[1] == 'desc') ? SORT_DESC : SORT_ASC;
$sort = $order_by[0];
if ($sort == 'author') {
foreach ($extensions as $key => $about) {
$author[$key] = $about['author'];
}
uasort($author, array('self', 'sortByAuthor'));
if ($order == SORT_DESC) {
$author = array_reverse($author);
}
foreach ($author as $key => $value) {
$data[$key] = $extensions[$key];
}
$extensions = $data;
} elseif ($sort == 'name') {
foreach ($extensions as $key => $about) {
$name[$key] = strtolower($about['name']);
$label[$key] = $key;
}
array_multisort($name, $order, $label, $order, $extensions);
}
}
foreach ($extensions as $i => $e) {
$data[$i] = array();
foreach ($e as $key => $value) {
// If $select is empty, we assume every field is requested
if (in_array($key, $select) || empty($select)) {
$data[$i][$key] = $value;
}
}
}
return $data;
} | [
"public",
"static",
"function",
"fetch",
"(",
"array",
"$",
"select",
"=",
"array",
"(",
")",
",",
"array",
"$",
"where",
"=",
"array",
"(",
")",
",",
"$",
"order_by",
"=",
"null",
")",
"{",
"$",
"extensions",
"=",
"self",
"::",
"listAll",
"(",
")",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"select",
")",
"&&",
"empty",
"(",
"$",
"where",
")",
"&&",
"is_null",
"(",
"$",
"order_by",
")",
")",
"{",
"return",
"$",
"extensions",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"extensions",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"order_by",
")",
")",
"{",
"$",
"author",
"=",
"$",
"name",
"=",
"$",
"label",
"=",
"array",
"(",
")",
";",
"$",
"order_by",
"=",
"array_map",
"(",
"'strtolower'",
",",
"explode",
"(",
"' '",
",",
"$",
"order_by",
")",
")",
";",
"$",
"order",
"=",
"(",
"$",
"order_by",
"[",
"1",
"]",
"==",
"'desc'",
")",
"?",
"SORT_DESC",
":",
"SORT_ASC",
";",
"$",
"sort",
"=",
"$",
"order_by",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"sort",
"==",
"'author'",
")",
"{",
"foreach",
"(",
"$",
"extensions",
"as",
"$",
"key",
"=>",
"$",
"about",
")",
"{",
"$",
"author",
"[",
"$",
"key",
"]",
"=",
"$",
"about",
"[",
"'author'",
"]",
";",
"}",
"uasort",
"(",
"$",
"author",
",",
"array",
"(",
"'self'",
",",
"'sortByAuthor'",
")",
")",
";",
"if",
"(",
"$",
"order",
"==",
"SORT_DESC",
")",
"{",
"$",
"author",
"=",
"array_reverse",
"(",
"$",
"author",
")",
";",
"}",
"foreach",
"(",
"$",
"author",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"extensions",
"[",
"$",
"key",
"]",
";",
"}",
"$",
"extensions",
"=",
"$",
"data",
";",
"}",
"elseif",
"(",
"$",
"sort",
"==",
"'name'",
")",
"{",
"foreach",
"(",
"$",
"extensions",
"as",
"$",
"key",
"=>",
"$",
"about",
")",
"{",
"$",
"name",
"[",
"$",
"key",
"]",
"=",
"strtolower",
"(",
"$",
"about",
"[",
"'name'",
"]",
")",
";",
"$",
"label",
"[",
"$",
"key",
"]",
"=",
"$",
"key",
";",
"}",
"array_multisort",
"(",
"$",
"name",
",",
"$",
"order",
",",
"$",
"label",
",",
"$",
"order",
",",
"$",
"extensions",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"extensions",
"as",
"$",
"i",
"=>",
"$",
"e",
")",
"{",
"$",
"data",
"[",
"$",
"i",
"]",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"e",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// If $select is empty, we assume every field is requested",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"select",
")",
"||",
"empty",
"(",
"$",
"select",
")",
")",
"{",
"$",
"data",
"[",
"$",
"i",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | This function will return an associative array of Extension information. The
information returned is defined by the `$select` parameter, which will allow
a developer to restrict what information is returned about the Extension.
Optionally, `$where` (not implemented) and `$order_by` parameters allow a developer to
further refine their query.
@param array $select (optional)
Accepts an array of keys to return from the listAll() method. If omitted, all keys
will be returned.
@param array $where (optional)
Not implemented.
@param string $order_by (optional)
Allows a developer to return the extensions in a particular order. The syntax is the
same as other `fetch` methods. If omitted this will return resources ordered by `name`.
@throws Exception
@throws SymphonyErrorPage
@return array
An associative array of Extension information, formatted in the same way as the
listAll() method. | [
"This",
"function",
"will",
"return",
"an",
"associative",
"array",
"of",
"Extension",
"information",
".",
"The",
"information",
"returned",
"is",
"defined",
"by",
"the",
"$select",
"parameter",
"which",
"will",
"allow",
"a",
"developer",
"to",
"restrict",
"what",
"information",
"is",
"returned",
"about",
"the",
"Extension",
".",
"Optionally",
"$where",
"(",
"not",
"implemented",
")",
"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.extensionmanager.php#L811-L867 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.about | public static function about($name, $rawXML = false)
{
// See if the extension has the new meta format
if (file_exists(self::__getClassPath($name) . '/extension.meta.xml')) {
try {
$meta = new DOMDocument;
$meta->load(self::__getClassPath($name) . '/extension.meta.xml');
$xpath = new DOMXPath($meta);
$rootNamespace = $meta->lookupNamespaceUri($meta->namespaceURI);
if (is_null($rootNamespace)) {
throw new Exception(__('Missing default namespace definition.'));
} else {
$xpath->registerNamespace('ext', $rootNamespace);
}
} catch (Exception $ex) {
Symphony::Engine()->throwCustomError(
__('The %1$s file for the %2$s extension is not valid XML: %3$s', array(
'<code>extension.meta.xml</code>',
'<code>' . $name . '</code>',
'<br /><code>' . $ex->getMessage() . '</code>'
))
);
}
// Load <extension>
$extension = $xpath->query('/ext:extension')->item(0);
// Check to see that the extension is named correctly, if it is
// not, then return nothing
if (self::__getClassName($name) !== self::__getClassName($xpath->evaluate('string(@id)', $extension))) {
return array();
}
// If `$rawXML` is set, just return our DOMDocument instance
if ($rawXML) {
return $meta;
}
$about = array(
'name' => $xpath->evaluate('string(ext:name)', $extension),
'handle' => $name,
'github' => $xpath->evaluate('string(ext:repo)', $extension),
'discuss' => $xpath->evaluate('string(ext:url[@type="discuss"])', $extension),
'homepage' => $xpath->evaluate('string(ext:url[@type="homepage"])', $extension),
'wiki' => $xpath->evaluate('string(ext:url[@type="wiki"])', $extension),
'issues' => $xpath->evaluate('string(ext:url[@type="issues"])', $extension),
'status' => array()
);
// find the latest <release> (largest version number)
$latest_release_version = '0.0.0';
foreach ($xpath->query('//ext:release', $extension) as $release) {
$version = $xpath->evaluate('string(@version)', $release);
if (version_compare($version, $latest_release_version, '>')) {
$latest_release_version = $version;
}
}
// Load the latest <release> information
if ($release = $xpath->query("//ext:release[@version='$latest_release_version']", $extension)->item(0)) {
$about += array(
'version' => $xpath->evaluate('string(@version)', $release),
'release-date' => $xpath->evaluate('string(@date)', $release)
);
// If it exists, load in the 'min/max' version data for this release
$required_min_version = $xpath->evaluate('string(@min)', $release);
$required_max_version = $xpath->evaluate('string(@max)', $release);
$current_symphony_version = Symphony::Configuration()->get('version', 'symphony');
// Remove pre-release notes from the current Symphony version so that
// we don't get false erros in the backend
$current_symphony_version = preg_replace(array('/dev/i', '/-?beta\.?\d/i', '/-?rc\.?\d/i', '/\.0(?:\.0)?$/'), '', $current_symphony_version);
// Munge the version number so that it makes sense in the backend.
// Consider, 2.3.x. As the min version, this means 2.3 onwards,
// for the max it implies any 2.3 release. RE: #1019
// Also remove any .0 when doing the comparison to prevent extensions
// that don't use semver yet. RE: #2146
$required_min_version = preg_replace(array('/\.x/', '/\.0$/'), '', $required_min_version);
$required_max_version = preg_replace(array('/\.x/', '/\.0$/'), 'p', $required_max_version);
// Min version
if (!empty($required_min_version) && version_compare($current_symphony_version, $required_min_version, '<')) {
$about['status'][] = Extension::EXTENSION_NOT_COMPATIBLE;
$about['required_version'] = $required_min_version;
// Max version
} elseif (!empty($required_max_version) && version_compare($current_symphony_version, $required_max_version, '>')) {
$about['status'][] = Extension::EXTENSION_NOT_COMPATIBLE;
$about['required_version'] = str_replace('p', '.x', $required_max_version);
}
}
// Add the <author> information
foreach ($xpath->query('//ext:author', $extension) as $author) {
$a = array(
'name' => $xpath->evaluate('string(ext:name)', $author),
'website' => $xpath->evaluate('string(ext:website)', $author),
'github' => $xpath->evaluate('string(ext:name/@github)', $author),
'email' => $xpath->evaluate('string(ext:email)', $author)
);
$about['author'][] = array_filter($a);
}
$about['status'] = array_merge($about['status'], self::fetchStatus($about));
return $about;
} else {
Symphony::Log()->pushToLog(sprintf('%s does not have an extension.meta.xml file', $name), E_DEPRECATED, true);
return array();
}
} | php | public static function about($name, $rawXML = false)
{
// See if the extension has the new meta format
if (file_exists(self::__getClassPath($name) . '/extension.meta.xml')) {
try {
$meta = new DOMDocument;
$meta->load(self::__getClassPath($name) . '/extension.meta.xml');
$xpath = new DOMXPath($meta);
$rootNamespace = $meta->lookupNamespaceUri($meta->namespaceURI);
if (is_null($rootNamespace)) {
throw new Exception(__('Missing default namespace definition.'));
} else {
$xpath->registerNamespace('ext', $rootNamespace);
}
} catch (Exception $ex) {
Symphony::Engine()->throwCustomError(
__('The %1$s file for the %2$s extension is not valid XML: %3$s', array(
'<code>extension.meta.xml</code>',
'<code>' . $name . '</code>',
'<br /><code>' . $ex->getMessage() . '</code>'
))
);
}
// Load <extension>
$extension = $xpath->query('/ext:extension')->item(0);
// Check to see that the extension is named correctly, if it is
// not, then return nothing
if (self::__getClassName($name) !== self::__getClassName($xpath->evaluate('string(@id)', $extension))) {
return array();
}
// If `$rawXML` is set, just return our DOMDocument instance
if ($rawXML) {
return $meta;
}
$about = array(
'name' => $xpath->evaluate('string(ext:name)', $extension),
'handle' => $name,
'github' => $xpath->evaluate('string(ext:repo)', $extension),
'discuss' => $xpath->evaluate('string(ext:url[@type="discuss"])', $extension),
'homepage' => $xpath->evaluate('string(ext:url[@type="homepage"])', $extension),
'wiki' => $xpath->evaluate('string(ext:url[@type="wiki"])', $extension),
'issues' => $xpath->evaluate('string(ext:url[@type="issues"])', $extension),
'status' => array()
);
// find the latest <release> (largest version number)
$latest_release_version = '0.0.0';
foreach ($xpath->query('//ext:release', $extension) as $release) {
$version = $xpath->evaluate('string(@version)', $release);
if (version_compare($version, $latest_release_version, '>')) {
$latest_release_version = $version;
}
}
// Load the latest <release> information
if ($release = $xpath->query("//ext:release[@version='$latest_release_version']", $extension)->item(0)) {
$about += array(
'version' => $xpath->evaluate('string(@version)', $release),
'release-date' => $xpath->evaluate('string(@date)', $release)
);
// If it exists, load in the 'min/max' version data for this release
$required_min_version = $xpath->evaluate('string(@min)', $release);
$required_max_version = $xpath->evaluate('string(@max)', $release);
$current_symphony_version = Symphony::Configuration()->get('version', 'symphony');
// Remove pre-release notes from the current Symphony version so that
// we don't get false erros in the backend
$current_symphony_version = preg_replace(array('/dev/i', '/-?beta\.?\d/i', '/-?rc\.?\d/i', '/\.0(?:\.0)?$/'), '', $current_symphony_version);
// Munge the version number so that it makes sense in the backend.
// Consider, 2.3.x. As the min version, this means 2.3 onwards,
// for the max it implies any 2.3 release. RE: #1019
// Also remove any .0 when doing the comparison to prevent extensions
// that don't use semver yet. RE: #2146
$required_min_version = preg_replace(array('/\.x/', '/\.0$/'), '', $required_min_version);
$required_max_version = preg_replace(array('/\.x/', '/\.0$/'), 'p', $required_max_version);
// Min version
if (!empty($required_min_version) && version_compare($current_symphony_version, $required_min_version, '<')) {
$about['status'][] = Extension::EXTENSION_NOT_COMPATIBLE;
$about['required_version'] = $required_min_version;
// Max version
} elseif (!empty($required_max_version) && version_compare($current_symphony_version, $required_max_version, '>')) {
$about['status'][] = Extension::EXTENSION_NOT_COMPATIBLE;
$about['required_version'] = str_replace('p', '.x', $required_max_version);
}
}
// Add the <author> information
foreach ($xpath->query('//ext:author', $extension) as $author) {
$a = array(
'name' => $xpath->evaluate('string(ext:name)', $author),
'website' => $xpath->evaluate('string(ext:website)', $author),
'github' => $xpath->evaluate('string(ext:name/@github)', $author),
'email' => $xpath->evaluate('string(ext:email)', $author)
);
$about['author'][] = array_filter($a);
}
$about['status'] = array_merge($about['status'], self::fetchStatus($about));
return $about;
} else {
Symphony::Log()->pushToLog(sprintf('%s does not have an extension.meta.xml file', $name), E_DEPRECATED, true);
return array();
}
} | [
"public",
"static",
"function",
"about",
"(",
"$",
"name",
",",
"$",
"rawXML",
"=",
"false",
")",
"{",
"// See if the extension has the new meta format",
"if",
"(",
"file_exists",
"(",
"self",
"::",
"__getClassPath",
"(",
"$",
"name",
")",
".",
"'/extension.meta.xml'",
")",
")",
"{",
"try",
"{",
"$",
"meta",
"=",
"new",
"DOMDocument",
";",
"$",
"meta",
"->",
"load",
"(",
"self",
"::",
"__getClassPath",
"(",
"$",
"name",
")",
".",
"'/extension.meta.xml'",
")",
";",
"$",
"xpath",
"=",
"new",
"DOMXPath",
"(",
"$",
"meta",
")",
";",
"$",
"rootNamespace",
"=",
"$",
"meta",
"->",
"lookupNamespaceUri",
"(",
"$",
"meta",
"->",
"namespaceURI",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"rootNamespace",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"__",
"(",
"'Missing default namespace definition.'",
")",
")",
";",
"}",
"else",
"{",
"$",
"xpath",
"->",
"registerNamespace",
"(",
"'ext'",
",",
"$",
"rootNamespace",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"Symphony",
"::",
"Engine",
"(",
")",
"->",
"throwCustomError",
"(",
"__",
"(",
"'The %1$s file for the %2$s extension is not valid XML: %3$s'",
",",
"array",
"(",
"'<code>extension.meta.xml</code>'",
",",
"'<code>'",
".",
"$",
"name",
".",
"'</code>'",
",",
"'<br /><code>'",
".",
"$",
"ex",
"->",
"getMessage",
"(",
")",
".",
"'</code>'",
")",
")",
")",
";",
"}",
"// Load <extension>",
"$",
"extension",
"=",
"$",
"xpath",
"->",
"query",
"(",
"'/ext:extension'",
")",
"->",
"item",
"(",
"0",
")",
";",
"// Check to see that the extension is named correctly, if it is",
"// not, then return nothing",
"if",
"(",
"self",
"::",
"__getClassName",
"(",
"$",
"name",
")",
"!==",
"self",
"::",
"__getClassName",
"(",
"$",
"xpath",
"->",
"evaluate",
"(",
"'string(@id)'",
",",
"$",
"extension",
")",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"// If `$rawXML` is set, just return our DOMDocument instance",
"if",
"(",
"$",
"rawXML",
")",
"{",
"return",
"$",
"meta",
";",
"}",
"$",
"about",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"xpath",
"->",
"evaluate",
"(",
"'string(ext:name)'",
",",
"$",
"extension",
")",
",",
"'handle'",
"=>",
"$",
"name",
",",
"'github'",
"=>",
"$",
"xpath",
"->",
"evaluate",
"(",
"'string(ext:repo)'",
",",
"$",
"extension",
")",
",",
"'discuss'",
"=>",
"$",
"xpath",
"->",
"evaluate",
"(",
"'string(ext:url[@type=\"discuss\"])'",
",",
"$",
"extension",
")",
",",
"'homepage'",
"=>",
"$",
"xpath",
"->",
"evaluate",
"(",
"'string(ext:url[@type=\"homepage\"])'",
",",
"$",
"extension",
")",
",",
"'wiki'",
"=>",
"$",
"xpath",
"->",
"evaluate",
"(",
"'string(ext:url[@type=\"wiki\"])'",
",",
"$",
"extension",
")",
",",
"'issues'",
"=>",
"$",
"xpath",
"->",
"evaluate",
"(",
"'string(ext:url[@type=\"issues\"])'",
",",
"$",
"extension",
")",
",",
"'status'",
"=>",
"array",
"(",
")",
")",
";",
"// find the latest <release> (largest version number)",
"$",
"latest_release_version",
"=",
"'0.0.0'",
";",
"foreach",
"(",
"$",
"xpath",
"->",
"query",
"(",
"'//ext:release'",
",",
"$",
"extension",
")",
"as",
"$",
"release",
")",
"{",
"$",
"version",
"=",
"$",
"xpath",
"->",
"evaluate",
"(",
"'string(@version)'",
",",
"$",
"release",
")",
";",
"if",
"(",
"version_compare",
"(",
"$",
"version",
",",
"$",
"latest_release_version",
",",
"'>'",
")",
")",
"{",
"$",
"latest_release_version",
"=",
"$",
"version",
";",
"}",
"}",
"// Load the latest <release> information",
"if",
"(",
"$",
"release",
"=",
"$",
"xpath",
"->",
"query",
"(",
"\"//ext:release[@version='$latest_release_version']\"",
",",
"$",
"extension",
")",
"->",
"item",
"(",
"0",
")",
")",
"{",
"$",
"about",
"+=",
"array",
"(",
"'version'",
"=>",
"$",
"xpath",
"->",
"evaluate",
"(",
"'string(@version)'",
",",
"$",
"release",
")",
",",
"'release-date'",
"=>",
"$",
"xpath",
"->",
"evaluate",
"(",
"'string(@date)'",
",",
"$",
"release",
")",
")",
";",
"// If it exists, load in the 'min/max' version data for this release",
"$",
"required_min_version",
"=",
"$",
"xpath",
"->",
"evaluate",
"(",
"'string(@min)'",
",",
"$",
"release",
")",
";",
"$",
"required_max_version",
"=",
"$",
"xpath",
"->",
"evaluate",
"(",
"'string(@max)'",
",",
"$",
"release",
")",
";",
"$",
"current_symphony_version",
"=",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'version'",
",",
"'symphony'",
")",
";",
"// Remove pre-release notes from the current Symphony version so that",
"// we don't get false erros in the backend",
"$",
"current_symphony_version",
"=",
"preg_replace",
"(",
"array",
"(",
"'/dev/i'",
",",
"'/-?beta\\.?\\d/i'",
",",
"'/-?rc\\.?\\d/i'",
",",
"'/\\.0(?:\\.0)?$/'",
")",
",",
"''",
",",
"$",
"current_symphony_version",
")",
";",
"// Munge the version number so that it makes sense in the backend.",
"// Consider, 2.3.x. As the min version, this means 2.3 onwards,",
"// for the max it implies any 2.3 release. RE: #1019",
"// Also remove any .0 when doing the comparison to prevent extensions",
"// that don't use semver yet. RE: #2146",
"$",
"required_min_version",
"=",
"preg_replace",
"(",
"array",
"(",
"'/\\.x/'",
",",
"'/\\.0$/'",
")",
",",
"''",
",",
"$",
"required_min_version",
")",
";",
"$",
"required_max_version",
"=",
"preg_replace",
"(",
"array",
"(",
"'/\\.x/'",
",",
"'/\\.0$/'",
")",
",",
"'p'",
",",
"$",
"required_max_version",
")",
";",
"// Min version",
"if",
"(",
"!",
"empty",
"(",
"$",
"required_min_version",
")",
"&&",
"version_compare",
"(",
"$",
"current_symphony_version",
",",
"$",
"required_min_version",
",",
"'<'",
")",
")",
"{",
"$",
"about",
"[",
"'status'",
"]",
"[",
"]",
"=",
"Extension",
"::",
"EXTENSION_NOT_COMPATIBLE",
";",
"$",
"about",
"[",
"'required_version'",
"]",
"=",
"$",
"required_min_version",
";",
"// Max version",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"required_max_version",
")",
"&&",
"version_compare",
"(",
"$",
"current_symphony_version",
",",
"$",
"required_max_version",
",",
"'>'",
")",
")",
"{",
"$",
"about",
"[",
"'status'",
"]",
"[",
"]",
"=",
"Extension",
"::",
"EXTENSION_NOT_COMPATIBLE",
";",
"$",
"about",
"[",
"'required_version'",
"]",
"=",
"str_replace",
"(",
"'p'",
",",
"'.x'",
",",
"$",
"required_max_version",
")",
";",
"}",
"}",
"// Add the <author> information",
"foreach",
"(",
"$",
"xpath",
"->",
"query",
"(",
"'//ext:author'",
",",
"$",
"extension",
")",
"as",
"$",
"author",
")",
"{",
"$",
"a",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"xpath",
"->",
"evaluate",
"(",
"'string(ext:name)'",
",",
"$",
"author",
")",
",",
"'website'",
"=>",
"$",
"xpath",
"->",
"evaluate",
"(",
"'string(ext:website)'",
",",
"$",
"author",
")",
",",
"'github'",
"=>",
"$",
"xpath",
"->",
"evaluate",
"(",
"'string(ext:name/@github)'",
",",
"$",
"author",
")",
",",
"'email'",
"=>",
"$",
"xpath",
"->",
"evaluate",
"(",
"'string(ext:email)'",
",",
"$",
"author",
")",
")",
";",
"$",
"about",
"[",
"'author'",
"]",
"[",
"]",
"=",
"array_filter",
"(",
"$",
"a",
")",
";",
"}",
"$",
"about",
"[",
"'status'",
"]",
"=",
"array_merge",
"(",
"$",
"about",
"[",
"'status'",
"]",
",",
"self",
"::",
"fetchStatus",
"(",
"$",
"about",
")",
")",
";",
"return",
"$",
"about",
";",
"}",
"else",
"{",
"Symphony",
"::",
"Log",
"(",
")",
"->",
"pushToLog",
"(",
"sprintf",
"(",
"'%s does not have an extension.meta.xml file'",
",",
"$",
"name",
")",
",",
"E_DEPRECATED",
",",
"true",
")",
";",
"return",
"array",
"(",
")",
";",
"}",
"}"
] | This function will load an extension's meta information given the extension
`$name`. Since Symphony 2.3, this function will look for an `extension.meta.xml`
file inside the extension's folder. If this is not found, it will initialise
the extension and invoke the `about()` function. By default this extension will
return an associative array display the basic meta data about the given extension.
If the `$rawXML` parameter is passed true, and the extension has a `extension.meta.xml`
file, this function will return `DOMDocument` of the file.
@param string $name
The name of the Extension Class minus the extension prefix.
@param boolean $rawXML
If passed as true, and is available, this function will return the
DOMDocument of representation of the given extension's `extension.meta.xml`
file. If the file is not available, the extension will return the normal
`about()` results. By default this is false.
@throws Exception
@throws SymphonyErrorPage
@return array
An associative array describing this extension | [
"This",
"function",
"will",
"load",
"an",
"extension",
"s",
"meta",
"information",
"given",
"the",
"extension",
"$name",
".",
"Since",
"Symphony",
"2",
".",
"3",
"this",
"function",
"will",
"look",
"for",
"an",
"extension",
".",
"meta",
".",
"xml",
"file",
"inside",
"the",
"extension",
"s",
"folder",
".",
"If",
"this",
"is",
"not",
"found",
"it",
"will",
"initialise",
"the",
"extension",
"and",
"invoke",
"the",
"about",
"()",
"function",
".",
"By",
"default",
"this",
"extension",
"will",
"return",
"an",
"associative",
"array",
"display",
"the",
"basic",
"meta",
"data",
"about",
"the",
"given",
"extension",
".",
"If",
"the",
"$rawXML",
"parameter",
"is",
"passed",
"true",
"and",
"the",
"extension",
"has",
"a",
"extension",
".",
"meta",
".",
"xml",
"file",
"this",
"function",
"will",
"return",
"DOMDocument",
"of",
"the",
"file",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L890-L1005 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.create | public static function create($name)
{
if (!isset(self::$_pool[$name])) {
$classname = self::__getClassName($name);
$path = self::__getDriverPath($name);
if (!is_file($path)) {
$errMsg = __('Could not find extension %s at location %s.', array(
'<code>' . $name . '</code>',
'<code>' . str_replace(DOCROOT . '/', '', $path) . '</code>'
));
try {
Symphony::Engine()->throwCustomError(
$errMsg,
__('Symphony Extension Missing Error'),
Page::HTTP_STATUS_ERROR,
'missing_extension',
array(
'name' => $name,
'path' => $path
)
);
} catch (Exception $ex) {
throw new Exception($errMsg, 0, $ex);
}
}
if (!class_exists($classname)) {
require_once($path);
}
// Create the extension object
self::$_pool[$name] = new $classname(array());
}
return self::$_pool[$name];
} | php | public static function create($name)
{
if (!isset(self::$_pool[$name])) {
$classname = self::__getClassName($name);
$path = self::__getDriverPath($name);
if (!is_file($path)) {
$errMsg = __('Could not find extension %s at location %s.', array(
'<code>' . $name . '</code>',
'<code>' . str_replace(DOCROOT . '/', '', $path) . '</code>'
));
try {
Symphony::Engine()->throwCustomError(
$errMsg,
__('Symphony Extension Missing Error'),
Page::HTTP_STATUS_ERROR,
'missing_extension',
array(
'name' => $name,
'path' => $path
)
);
} catch (Exception $ex) {
throw new Exception($errMsg, 0, $ex);
}
}
if (!class_exists($classname)) {
require_once($path);
}
// Create the extension object
self::$_pool[$name] = new $classname(array());
}
return self::$_pool[$name];
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"_pool",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"classname",
"=",
"self",
"::",
"__getClassName",
"(",
"$",
"name",
")",
";",
"$",
"path",
"=",
"self",
"::",
"__getDriverPath",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"is_file",
"(",
"$",
"path",
")",
")",
"{",
"$",
"errMsg",
"=",
"__",
"(",
"'Could not find extension %s at location %s.'",
",",
"array",
"(",
"'<code>'",
".",
"$",
"name",
".",
"'</code>'",
",",
"'<code>'",
".",
"str_replace",
"(",
"DOCROOT",
".",
"'/'",
",",
"''",
",",
"$",
"path",
")",
".",
"'</code>'",
")",
")",
";",
"try",
"{",
"Symphony",
"::",
"Engine",
"(",
")",
"->",
"throwCustomError",
"(",
"$",
"errMsg",
",",
"__",
"(",
"'Symphony Extension Missing Error'",
")",
",",
"Page",
"::",
"HTTP_STATUS_ERROR",
",",
"'missing_extension'",
",",
"array",
"(",
"'name'",
"=>",
"$",
"name",
",",
"'path'",
"=>",
"$",
"path",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"throw",
"new",
"Exception",
"(",
"$",
"errMsg",
",",
"0",
",",
"$",
"ex",
")",
";",
"}",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"classname",
")",
")",
"{",
"require_once",
"(",
"$",
"path",
")",
";",
"}",
"// Create the extension object",
"self",
"::",
"$",
"_pool",
"[",
"$",
"name",
"]",
"=",
"new",
"$",
"classname",
"(",
"array",
"(",
")",
")",
";",
"}",
"return",
"self",
"::",
"$",
"_pool",
"[",
"$",
"name",
"]",
";",
"}"
] | Creates an instance of a given class and returns it
@param string $name
The name of the Extension Class minus the extension prefix.
@throws Exception
@throws SymphonyErrorPage
@return Extension | [
"Creates",
"an",
"instance",
"of",
"a",
"given",
"class",
"and",
"returns",
"it"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L1016-L1052 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.extensionmanager.php | ExtensionManager.cleanupDatabase | public static function cleanupDatabase()
{
// Grab any extensions sitting in the database
$rows = Symphony::Database()->fetch("SELECT `name` FROM `tbl_extensions`");
// Iterate over each row
if (is_array($rows) && !empty($rows)) {
foreach ($rows as $r) {
$name = $r['name'];
$status = isset($r['status']) ? $r['status'] : null;
// Grab the install location
$path = self::__getClassPath($name);
$existing_id = self::fetchExtensionID($name);
// If it doesnt exist, remove the DB rows
if (!@is_dir($path)) {
Symphony::Database()->delete("tbl_extensions_delegates", sprintf(" `extension_id` = %d ", $existing_id));
Symphony::Database()->delete('tbl_extensions', sprintf(" `id` = %d LIMIT 1", $existing_id));
} elseif ($status == 'disabled') {
Symphony::Database()->delete("tbl_extensions_delegates", sprintf(" `extension_id` = %d ", $existing_id));
}
}
}
} | php | public static function cleanupDatabase()
{
// Grab any extensions sitting in the database
$rows = Symphony::Database()->fetch("SELECT `name` FROM `tbl_extensions`");
// Iterate over each row
if (is_array($rows) && !empty($rows)) {
foreach ($rows as $r) {
$name = $r['name'];
$status = isset($r['status']) ? $r['status'] : null;
// Grab the install location
$path = self::__getClassPath($name);
$existing_id = self::fetchExtensionID($name);
// If it doesnt exist, remove the DB rows
if (!@is_dir($path)) {
Symphony::Database()->delete("tbl_extensions_delegates", sprintf(" `extension_id` = %d ", $existing_id));
Symphony::Database()->delete('tbl_extensions', sprintf(" `id` = %d LIMIT 1", $existing_id));
} elseif ($status == 'disabled') {
Symphony::Database()->delete("tbl_extensions_delegates", sprintf(" `extension_id` = %d ", $existing_id));
}
}
}
} | [
"public",
"static",
"function",
"cleanupDatabase",
"(",
")",
"{",
"// Grab any extensions sitting in the database",
"$",
"rows",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetch",
"(",
"\"SELECT `name` FROM `tbl_extensions`\"",
")",
";",
"// Iterate over each row",
"if",
"(",
"is_array",
"(",
"$",
"rows",
")",
"&&",
"!",
"empty",
"(",
"$",
"rows",
")",
")",
"{",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"r",
")",
"{",
"$",
"name",
"=",
"$",
"r",
"[",
"'name'",
"]",
";",
"$",
"status",
"=",
"isset",
"(",
"$",
"r",
"[",
"'status'",
"]",
")",
"?",
"$",
"r",
"[",
"'status'",
"]",
":",
"null",
";",
"// Grab the install location",
"$",
"path",
"=",
"self",
"::",
"__getClassPath",
"(",
"$",
"name",
")",
";",
"$",
"existing_id",
"=",
"self",
"::",
"fetchExtensionID",
"(",
"$",
"name",
")",
";",
"// If it doesnt exist, remove the DB rows",
"if",
"(",
"!",
"@",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"delete",
"(",
"\"tbl_extensions_delegates\"",
",",
"sprintf",
"(",
"\" `extension_id` = %d \"",
",",
"$",
"existing_id",
")",
")",
";",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"delete",
"(",
"'tbl_extensions'",
",",
"sprintf",
"(",
"\" `id` = %d LIMIT 1\"",
",",
"$",
"existing_id",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"status",
"==",
"'disabled'",
")",
"{",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"delete",
"(",
"\"tbl_extensions_delegates\"",
",",
"sprintf",
"(",
"\" `extension_id` = %d \"",
",",
"$",
"existing_id",
")",
")",
";",
"}",
"}",
"}",
"}"
] | A utility function that is used by the ExtensionManager to ensure
stray delegates are not in `tbl_extensions_delegates`. It is called when
a new Delegate is added or removed. | [
"A",
"utility",
"function",
"that",
"is",
"used",
"by",
"the",
"ExtensionManager",
"to",
"ensure",
"stray",
"delegates",
"are",
"not",
"in",
"tbl_extensions_delegates",
".",
"It",
"is",
"called",
"when",
"a",
"new",
"Delegate",
"is",
"added",
"or",
"removed",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.extensionmanager.php#L1059-L1083 |
symphonycms/symphony-2 | symphony/lib/core/class.cookie.php | Cookie.__init | private function __init()
{
$this->_session = Session::start($this->_timeout, $this->_path, $this->_domain, $this->_httpOnly, $this->_secure);
if (!$this->_session) {
return false;
}
if (!isset($_SESSION[$this->_index])) {
$_SESSION[$this->_index] = array();
}
// Class FrontendPage uses $_COOKIE directly (inside it's __buildPage() function), so try to emulate it.
// @deprecated will be removed in Symphony 3.0.0
$_COOKIE[$this->_index] = &$_SESSION[$this->_index];
return $this->_session;
} | php | private function __init()
{
$this->_session = Session::start($this->_timeout, $this->_path, $this->_domain, $this->_httpOnly, $this->_secure);
if (!$this->_session) {
return false;
}
if (!isset($_SESSION[$this->_index])) {
$_SESSION[$this->_index] = array();
}
// Class FrontendPage uses $_COOKIE directly (inside it's __buildPage() function), so try to emulate it.
// @deprecated will be removed in Symphony 3.0.0
$_COOKIE[$this->_index] = &$_SESSION[$this->_index];
return $this->_session;
} | [
"private",
"function",
"__init",
"(",
")",
"{",
"$",
"this",
"->",
"_session",
"=",
"Session",
"::",
"start",
"(",
"$",
"this",
"->",
"_timeout",
",",
"$",
"this",
"->",
"_path",
",",
"$",
"this",
"->",
"_domain",
",",
"$",
"this",
"->",
"_httpOnly",
",",
"$",
"this",
"->",
"_secure",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"_session",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"_index",
"]",
")",
")",
"{",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"_index",
"]",
"=",
"array",
"(",
")",
";",
"}",
"// Class FrontendPage uses $_COOKIE directly (inside it's __buildPage() function), so try to emulate it.",
"// @deprecated will be removed in Symphony 3.0.0",
"$",
"_COOKIE",
"[",
"$",
"this",
"->",
"_index",
"]",
"=",
"&",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"_index",
"]",
";",
"return",
"$",
"this",
"->",
"_session",
";",
"}"
] | Initialises a new Session instance using this cookie's params
@throws Throwable
@return string|boolean | [
"Initialises",
"a",
"new",
"Session",
"instance",
"using",
"this",
"cookie",
"s",
"params"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.cookie.php#L125-L142 |
symphonycms/symphony-2 | symphony/lib/core/class.cookie.php | Cookie.get | public function get($name = null)
{
if (is_null($name) && isset($_SESSION[$this->_index])) {
return $_SESSION[$this->_index];
}
if (isset($_SESSION[$this->_index]) && is_array($_SESSION[$this->_index]) && array_key_exists($name, $_SESSION[$this->_index])) {
return $_SESSION[$this->_index][$name];
}
return null;
} | php | public function get($name = null)
{
if (is_null($name) && isset($_SESSION[$this->_index])) {
return $_SESSION[$this->_index];
}
if (isset($_SESSION[$this->_index]) && is_array($_SESSION[$this->_index]) && array_key_exists($name, $_SESSION[$this->_index])) {
return $_SESSION[$this->_index][$name];
}
return null;
} | [
"public",
"function",
"get",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"name",
")",
"&&",
"isset",
"(",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"_index",
"]",
")",
")",
"{",
"return",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"_index",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"_index",
"]",
")",
"&&",
"is_array",
"(",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"_index",
"]",
")",
"&&",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"_index",
"]",
")",
")",
"{",
"return",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"_index",
"]",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Accessor function for properties in the `$_SESSION` array
@param string $name
The name of the property to retrieve (optional)
@return string|null
The value of the property, or null if it does not exist. If
no `$name` is provided, return the entire Cookie. | [
"Accessor",
"function",
"for",
"properties",
"in",
"the",
"$_SESSION",
"array"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.cookie.php#L167-L178 |
symphonycms/symphony-2 | symphony/lib/core/class.cookie.php | Cookie.expire | public function expire()
{
if (!isset($_SESSION[$this->_index]) || !is_array($_SESSION[$this->_index]) || empty($_SESSION[$this->_index])) {
return;
}
unset($_SESSION[$this->_index]);
// Calling session_destroy triggers the Session::destroy function which removes the entire session
// from the database. To prevent logout issues between functionality that relies on $_SESSION, such
// as Symphony authentication or the Members extension, only delete the $_SESSION if it empty!
if (empty($_SESSION)) {
session_destroy();
}
} | php | public function expire()
{
if (!isset($_SESSION[$this->_index]) || !is_array($_SESSION[$this->_index]) || empty($_SESSION[$this->_index])) {
return;
}
unset($_SESSION[$this->_index]);
// Calling session_destroy triggers the Session::destroy function which removes the entire session
// from the database. To prevent logout issues between functionality that relies on $_SESSION, such
// as Symphony authentication or the Members extension, only delete the $_SESSION if it empty!
if (empty($_SESSION)) {
session_destroy();
}
} | [
"public",
"function",
"expire",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"_index",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"_index",
"]",
")",
"||",
"empty",
"(",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"_index",
"]",
")",
")",
"{",
"return",
";",
"}",
"unset",
"(",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"_index",
"]",
")",
";",
"// Calling session_destroy triggers the Session::destroy function which removes the entire session",
"// from the database. To prevent logout issues between functionality that relies on $_SESSION, such",
"// as Symphony authentication or the Members extension, only delete the $_SESSION if it empty!",
"if",
"(",
"empty",
"(",
"$",
"_SESSION",
")",
")",
"{",
"session_destroy",
"(",
")",
";",
"}",
"}"
] | Expires the current `$_SESSION` by unsetting the Symphony
namespace (`$this->_index`). If the `$_SESSION`
is empty, the function will destroy the entire `$_SESSION`
@link http://au2.php.net/manual/en/function.session-destroy.php | [
"Expires",
"the",
"current",
"$_SESSION",
"by",
"unsetting",
"the",
"Symphony",
"namespace",
"(",
"$this",
"-",
">",
"_index",
")",
".",
"If",
"the",
"$_SESSION",
"is",
"empty",
"the",
"function",
"will",
"destroy",
"the",
"entire",
"$_SESSION"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.cookie.php#L187-L201 |
symphonycms/symphony-2 | symphony/lib/toolkit/cryptography/class.sha1.php | SHA1.hash | public static function hash($input)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('SHA1::hash()', 'PBKDF2::hash()', array(
'message-format' => __('The use of `%s` is strongly discouraged due to severe security flaws.'),
));
}
return sha1($input);
} | php | public static function hash($input)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('SHA1::hash()', 'PBKDF2::hash()', array(
'message-format' => __('The use of `%s` is strongly discouraged due to severe security flaws.'),
));
}
return sha1($input);
} | [
"public",
"static",
"function",
"hash",
"(",
"$",
"input",
")",
"{",
"if",
"(",
"Symphony",
"::",
"Log",
"(",
")",
")",
"{",
"Symphony",
"::",
"Log",
"(",
")",
"->",
"pushDeprecateWarningToLog",
"(",
"'SHA1::hash()'",
",",
"'PBKDF2::hash()'",
",",
"array",
"(",
"'message-format'",
"=>",
"__",
"(",
"'The use of `%s` is strongly discouraged due to severe security flaws.'",
")",
",",
")",
")",
";",
"}",
"return",
"sha1",
"(",
"$",
"input",
")",
";",
"}"
] | Uses `SHA1` to create a hash based on some input
@param string $input
the string to be hashed
@return string
the hashed string | [
"Uses",
"SHA1",
"to",
"create",
"a",
"hash",
"based",
"on",
"some",
"input"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/cryptography/class.sha1.php#L24-L32 |
symphonycms/symphony-2 | symphony/lib/toolkit/cryptography/class.sha1.php | SHA1.file | public static function file($input)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('SHA1::file()', 'PBKDF2::hash()', array(
'message-format' => __('The use of `%s` is strongly discouraged due to severe security flaws.'),
));
}
return sha1_file($input);
} | php | public static function file($input)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('SHA1::file()', 'PBKDF2::hash()', array(
'message-format' => __('The use of `%s` is strongly discouraged due to severe security flaws.'),
));
}
return sha1_file($input);
} | [
"public",
"static",
"function",
"file",
"(",
"$",
"input",
")",
"{",
"if",
"(",
"Symphony",
"::",
"Log",
"(",
")",
")",
"{",
"Symphony",
"::",
"Log",
"(",
")",
"->",
"pushDeprecateWarningToLog",
"(",
"'SHA1::file()'",
",",
"'PBKDF2::hash()'",
",",
"array",
"(",
"'message-format'",
"=>",
"__",
"(",
"'The use of `%s` is strongly discouraged due to severe security flaws.'",
")",
",",
")",
")",
";",
"}",
"return",
"sha1_file",
"(",
"$",
"input",
")",
";",
"}"
] | Uses `SHA1` to create a hash from the contents of a file
@param string $input
the file to be hashed
@return string
the hashed string | [
"Uses",
"SHA1",
"to",
"create",
"a",
"hash",
"from",
"the",
"contents",
"of",
"a",
"file"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/cryptography/class.sha1.php#L42-L50 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.page.php | Page.setHttpStatusValue | final public static function setHttpStatusValue($status_code, $string_value)
{
if (!$string_value) {
unset(self::$HTTP_STATUSES[$status_code]);
} elseif (is_int($status_code) && $status_code >= 100 && $status_code < 600) {
self::$HTTP_STATUSES[$status_code] = $string_value;
} else {
// Throw error ?
}
} | php | final public static function setHttpStatusValue($status_code, $string_value)
{
if (!$string_value) {
unset(self::$HTTP_STATUSES[$status_code]);
} elseif (is_int($status_code) && $status_code >= 100 && $status_code < 600) {
self::$HTTP_STATUSES[$status_code] = $string_value;
} else {
// Throw error ?
}
} | [
"final",
"public",
"static",
"function",
"setHttpStatusValue",
"(",
"$",
"status_code",
",",
"$",
"string_value",
")",
"{",
"if",
"(",
"!",
"$",
"string_value",
")",
"{",
"unset",
"(",
"self",
"::",
"$",
"HTTP_STATUSES",
"[",
"$",
"status_code",
"]",
")",
";",
"}",
"elseif",
"(",
"is_int",
"(",
"$",
"status_code",
")",
"&&",
"$",
"status_code",
">=",
"100",
"&&",
"$",
"status_code",
"<",
"600",
")",
"{",
"self",
"::",
"$",
"HTTP_STATUSES",
"[",
"$",
"status_code",
"]",
"=",
"$",
"string_value",
";",
"}",
"else",
"{",
"// Throw error ?",
"}",
"}"
] | Sets the `$sting_value` for the specified `$status_code`.
If `$sting_value` is null, the `$status_code` is removed from
the array.
This allow developers to register customs HTTP_STATUS into the
static `Page::$HTTP_STATUSES` array and use `$page->setHttpStatus()`.
@since Symphony 2.3.2
@param integer $status_code
The HTTP Status numeric code.
@param string $string_value
The HTTP Status string value. | [
"Sets",
"the",
"$sting_value",
"for",
"the",
"specified",
"$status_code",
".",
"If",
"$sting_value",
"is",
"null",
"the",
"$status_code",
"is",
"removed",
"from",
"the",
"array",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.page.php#L188-L197 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.