repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
symphonycms/symphony-2 | symphony/lib/toolkit/class.emailgateway.php | EmailGateway.setSenderEmailAddress | public function setSenderEmailAddress($email)
{
if (!$this->validateHeaderFieldValue($email)) {
throw new EmailValidationException(__('Sender Email Address can not contain carriage return or newlines.'));
}
$this->_sender_email_address = $email;
} | php | public function setSenderEmailAddress($email)
{
if (!$this->validateHeaderFieldValue($email)) {
throw new EmailValidationException(__('Sender Email Address can not contain carriage return or newlines.'));
}
$this->_sender_email_address = $email;
} | [
"public",
"function",
"setSenderEmailAddress",
"(",
"$",
"email",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"validateHeaderFieldValue",
"(",
"$",
"email",
")",
")",
"{",
"throw",
"new",
"EmailValidationException",
"(",
"__",
"(",
"'Sender Email Address can not contain carriage return or newlines.'",
")",
")",
";",
"}",
"$",
"this",
"->",
"_sender_email_address",
"=",
"$",
"email",
";",
"}"
] | Sets the sender-email.
@throws EmailValidationException
@param string $email
The email-address emails will be sent from.
@return void | [
"Sets",
"the",
"sender",
"-",
"email",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.emailgateway.php#L173-L180 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.emailgateway.php | EmailGateway.setSenderName | public function setSenderName($name)
{
if (!$this->validateHeaderFieldValue($name)) {
throw new EmailValidationException(__('Sender Name can not contain carriage return or newlines.'));
}
$this->_sender_name = $name;
} | php | public function setSenderName($name)
{
if (!$this->validateHeaderFieldValue($name)) {
throw new EmailValidationException(__('Sender Name can not contain carriage return or newlines.'));
}
$this->_sender_name = $name;
} | [
"public",
"function",
"setSenderName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"validateHeaderFieldValue",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"EmailValidationException",
"(",
"__",
"(",
"'Sender Name can not contain carriage return or newlines.'",
")",
")",
";",
"}",
"$",
"this",
"->",
"_sender_name",
"=",
"$",
"name",
";",
"}"
] | Sets the sender-name.
@throws EmailValidationException
@param string $name
The name emails will be sent from.
@return void | [
"Sets",
"the",
"sender",
"-",
"name",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.emailgateway.php#L190-L197 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.emailgateway.php | EmailGateway.setRecipients | public function setRecipients($email)
{
if (!is_array($email)) {
$email = explode(',', $email);
// trim all values
array_walk($email, function(&$val) {
return $val = trim($val);
});
// remove empty elements
$email = array_filter($email);
}
foreach ($email as $e) {
if (!$this->validateHeaderFieldValue($e)) {
throw new EmailValidationException(__('Recipient address can not contain carriage return or newlines.'));
}
}
$this->_recipients = $email;
} | php | public function setRecipients($email)
{
if (!is_array($email)) {
$email = explode(',', $email);
// trim all values
array_walk($email, function(&$val) {
return $val = trim($val);
});
// remove empty elements
$email = array_filter($email);
}
foreach ($email as $e) {
if (!$this->validateHeaderFieldValue($e)) {
throw new EmailValidationException(__('Recipient address can not contain carriage return or newlines.'));
}
}
$this->_recipients = $email;
} | [
"public",
"function",
"setRecipients",
"(",
"$",
"email",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"email",
")",
")",
"{",
"$",
"email",
"=",
"explode",
"(",
"','",
",",
"$",
"email",
")",
";",
"// trim all values",
"array_walk",
"(",
"$",
"email",
",",
"function",
"(",
"&",
"$",
"val",
")",
"{",
"return",
"$",
"val",
"=",
"trim",
"(",
"$",
"val",
")",
";",
"}",
")",
";",
"// remove empty elements",
"$",
"email",
"=",
"array_filter",
"(",
"$",
"email",
")",
";",
"}",
"foreach",
"(",
"$",
"email",
"as",
"$",
"e",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"validateHeaderFieldValue",
"(",
"$",
"e",
")",
")",
"{",
"throw",
"new",
"EmailValidationException",
"(",
"__",
"(",
"'Recipient address can not contain carriage return or newlines.'",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_recipients",
"=",
"$",
"email",
";",
"}"
] | Sets the recipients.
@param string|array $email
The email-address(es) to send the email to.
@throws EmailValidationException
@return void | [
"Sets",
"the",
"recipients",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.emailgateway.php#L207-L226 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.emailgateway.php | EmailGateway.setAttachments | public function setAttachments($files)
{
// Always erase
$this->_attachments = array();
// check if we have an input value
if ($files == null) {
return;
}
// make sure we are dealing with an array
if (!is_array($files)) {
$files = array($files);
}
// Append each attachment one by one in order
// to normalize each input
foreach ($files as $key => $file) {
if (is_numeric($key)) {
// key is numeric, assume keyed array or string
$this->appendAttachment($file);
} else {
// key is not numeric, assume key is filename
// and file is a string, key needs to be preserved
$this->appendAttachment(array($key => $file));
}
}
} | php | public function setAttachments($files)
{
// Always erase
$this->_attachments = array();
// check if we have an input value
if ($files == null) {
return;
}
// make sure we are dealing with an array
if (!is_array($files)) {
$files = array($files);
}
// Append each attachment one by one in order
// to normalize each input
foreach ($files as $key => $file) {
if (is_numeric($key)) {
// key is numeric, assume keyed array or string
$this->appendAttachment($file);
} else {
// key is not numeric, assume key is filename
// and file is a string, key needs to be preserved
$this->appendAttachment(array($key => $file));
}
}
} | [
"public",
"function",
"setAttachments",
"(",
"$",
"files",
")",
"{",
"// Always erase",
"$",
"this",
"->",
"_attachments",
"=",
"array",
"(",
")",
";",
"// check if we have an input value",
"if",
"(",
"$",
"files",
"==",
"null",
")",
"{",
"return",
";",
"}",
"// make sure we are dealing with an array",
"if",
"(",
"!",
"is_array",
"(",
"$",
"files",
")",
")",
"{",
"$",
"files",
"=",
"array",
"(",
"$",
"files",
")",
";",
"}",
"// Append each attachment one by one in order",
"// to normalize each input",
"foreach",
"(",
"$",
"files",
"as",
"$",
"key",
"=>",
"$",
"file",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"// key is numeric, assume keyed array or string",
"$",
"this",
"->",
"appendAttachment",
"(",
"$",
"file",
")",
";",
"}",
"else",
"{",
"// key is not numeric, assume key is filename",
"// and file is a string, key needs to be preserved",
"$",
"this",
"->",
"appendAttachment",
"(",
"array",
"(",
"$",
"key",
"=>",
"$",
"file",
")",
")",
";",
"}",
"}",
"}"
] | This function sets one or multiple attachment files
to the email.
Passing `null` to this function will
erase the current values with an empty array.
@param string|array $files
Accepts the same parameters format as `EmailGateway::addAttachment()`
but you can also all multiple values at once if all files are
wrap in a array.
Example:
````
$email->setAttachments(array(
array(
'file' => 'http://example.com/foo.txt',
'charset' => 'UTF-8'
),
'path/to/your/webspace/foo/bar.csv',
...
));
```` | [
"This",
"function",
"sets",
"one",
"or",
"multiple",
"attachment",
"files",
"to",
"the",
"email",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.emailgateway.php#L276-L303 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.emailgateway.php | EmailGateway.appendAttachment | public function appendAttachment($file)
{
if (!is_array($file)) {
// treat the param as string (old format)
$file = array(
'file' => $file,
'filename' => null,
'charset' => null,
);
// is array, but not the right key
} elseif (!isset($file['file'])) {
// another (un-documented) old format: key is filename
$keys = array_keys($file);
$file = array(
'file' => $file[$keys[0]],
'filename' => is_numeric($keys[0]) ? null : $keys[0],
'charset' => null,
);
}
// push properly formatted file entry
$this->_attachments[] = $file;
} | php | public function appendAttachment($file)
{
if (!is_array($file)) {
// treat the param as string (old format)
$file = array(
'file' => $file,
'filename' => null,
'charset' => null,
);
// is array, but not the right key
} elseif (!isset($file['file'])) {
// another (un-documented) old format: key is filename
$keys = array_keys($file);
$file = array(
'file' => $file[$keys[0]],
'filename' => is_numeric($keys[0]) ? null : $keys[0],
'charset' => null,
);
}
// push properly formatted file entry
$this->_attachments[] = $file;
} | [
"public",
"function",
"appendAttachment",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"file",
")",
")",
"{",
"// treat the param as string (old format)",
"$",
"file",
"=",
"array",
"(",
"'file'",
"=>",
"$",
"file",
",",
"'filename'",
"=>",
"null",
",",
"'charset'",
"=>",
"null",
",",
")",
";",
"// is array, but not the right key",
"}",
"elseif",
"(",
"!",
"isset",
"(",
"$",
"file",
"[",
"'file'",
"]",
")",
")",
"{",
"// another (un-documented) old format: key is filename",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"file",
")",
";",
"$",
"file",
"=",
"array",
"(",
"'file'",
"=>",
"$",
"file",
"[",
"$",
"keys",
"[",
"0",
"]",
"]",
",",
"'filename'",
"=>",
"is_numeric",
"(",
"$",
"keys",
"[",
"0",
"]",
")",
"?",
"null",
":",
"$",
"keys",
"[",
"0",
"]",
",",
"'charset'",
"=>",
"null",
",",
")",
";",
"}",
"// push properly formatted file entry",
"$",
"this",
"->",
"_attachments",
"[",
"]",
"=",
"$",
"file",
";",
"}"
] | Appends one file attachment to the attachments array.
@since Symphony 2.3.5
@param string|array $file
Can be a string representing the file path, absolute or relative, i.e.
`'http://example.com/foo.txt'` or `'path/to/your/webspace/foo/bar.csv'`.
Can also be a keyed array. This will enable more options, like setting the
charset used by mail agent to open the file or a different filename.
Example:
````
$email->appendAttachment(array(
'file' => 'http://example.com/foo.txt',
'filename' => 'bar.txt',
'charset' => 'UTF-8',
'mime-type' => 'text/csv',
));
```` | [
"Appends",
"one",
"file",
"attachment",
"to",
"the",
"attachments",
"array",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.emailgateway.php#L327-L350 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.emailgateway.php | EmailGateway.appendHeaderField | public function appendHeaderField($name, $body)
{
if (is_array($body)) {
throw new EmailGatewayException(__('%s accepts strings only; arrays are not allowed.', array('<code>appendHeaderField</code>')));
}
$this->_header_fields[$name] = $body;
} | php | public function appendHeaderField($name, $body)
{
if (is_array($body)) {
throw new EmailGatewayException(__('%s accepts strings only; arrays are not allowed.', array('<code>appendHeaderField</code>')));
}
$this->_header_fields[$name] = $body;
} | [
"public",
"function",
"appendHeaderField",
"(",
"$",
"name",
",",
"$",
"body",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"body",
")",
")",
"{",
"throw",
"new",
"EmailGatewayException",
"(",
"__",
"(",
"'%s accepts strings only; arrays are not allowed.'",
",",
"array",
"(",
"'<code>appendHeaderField</code>'",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"_header_fields",
"[",
"$",
"name",
"]",
"=",
"$",
"body",
";",
"}"
] | Appends a single header field to the header fields array.
The header field should be presented as a name/body pair.
@throws EmailGatewayException
@param string $name
The header field name. Examples are From, Bcc, X-Sender and Reply-to.
@param string $body
The header field body.
@return void | [
"Appends",
"a",
"single",
"header",
"field",
"to",
"the",
"header",
"fields",
"array",
".",
"The",
"header",
"field",
"should",
"be",
"presented",
"as",
"a",
"name",
"/",
"body",
"pair",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.emailgateway.php#L464-L471 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.emailgateway.php | EmailGateway.appendHeaderFields | public function appendHeaderFields(array $header_array = array())
{
foreach ($header_array as $name => $body) {
$this->appendHeaderField($name, $body);
}
} | php | public function appendHeaderFields(array $header_array = array())
{
foreach ($header_array as $name => $body) {
$this->appendHeaderField($name, $body);
}
} | [
"public",
"function",
"appendHeaderFields",
"(",
"array",
"$",
"header_array",
"=",
"array",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"header_array",
"as",
"$",
"name",
"=>",
"$",
"body",
")",
"{",
"$",
"this",
"->",
"appendHeaderField",
"(",
"$",
"name",
",",
"$",
"body",
")",
";",
"}",
"}"
] | Appends one or more header fields to the header fields array.
Header fields should be presented as an array with name/body pairs.
@param array $header_array
The header fields. Examples are From, X-Sender and Reply-to.
@throws EmailGatewayException
@return void | [
"Appends",
"one",
"or",
"more",
"header",
"fields",
"to",
"the",
"header",
"fields",
"array",
".",
"Header",
"fields",
"should",
"be",
"presented",
"as",
"an",
"array",
"with",
"name",
"/",
"body",
"pairs",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.emailgateway.php#L482-L487 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.emailgateway.php | EmailGateway.validate | public function validate()
{
if (strlen(trim($this->_subject)) <= 0) {
throw new EmailValidationException(__('Email subject cannot be empty.'));
} elseif (strlen(trim($this->_sender_email_address)) <= 0) {
throw new EmailValidationException(__('Sender email address cannot be empty.'));
} elseif (!filter_var($this->_sender_email_address, FILTER_VALIDATE_EMAIL)) {
throw new EmailValidationException(__('Sender email address must be a valid email address.'));
} else {
foreach ($this->_recipients as $address) {
if (strlen(trim($address)) <= 0) {
throw new EmailValidationException(__('Recipient email address cannot be empty.'));
} elseif (!filter_var($address, FILTER_VALIDATE_EMAIL)) {
throw new EmailValidationException(__('The email address ‘%s’ is invalid.', array($address)));
}
}
}
return true;
} | php | public function validate()
{
if (strlen(trim($this->_subject)) <= 0) {
throw new EmailValidationException(__('Email subject cannot be empty.'));
} elseif (strlen(trim($this->_sender_email_address)) <= 0) {
throw new EmailValidationException(__('Sender email address cannot be empty.'));
} elseif (!filter_var($this->_sender_email_address, FILTER_VALIDATE_EMAIL)) {
throw new EmailValidationException(__('Sender email address must be a valid email address.'));
} else {
foreach ($this->_recipients as $address) {
if (strlen(trim($address)) <= 0) {
throw new EmailValidationException(__('Recipient email address cannot be empty.'));
} elseif (!filter_var($address, FILTER_VALIDATE_EMAIL)) {
throw new EmailValidationException(__('The email address ‘%s’ is invalid.', array($address)));
}
}
}
return true;
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"if",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"this",
"->",
"_subject",
")",
")",
"<=",
"0",
")",
"{",
"throw",
"new",
"EmailValidationException",
"(",
"__",
"(",
"'Email subject cannot be empty.'",
")",
")",
";",
"}",
"elseif",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"this",
"->",
"_sender_email_address",
")",
")",
"<=",
"0",
")",
"{",
"throw",
"new",
"EmailValidationException",
"(",
"__",
"(",
"'Sender email address cannot be empty.'",
")",
")",
";",
"}",
"elseif",
"(",
"!",
"filter_var",
"(",
"$",
"this",
"->",
"_sender_email_address",
",",
"FILTER_VALIDATE_EMAIL",
")",
")",
"{",
"throw",
"new",
"EmailValidationException",
"(",
"__",
"(",
"'Sender email address must be a valid email address.'",
")",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_recipients",
"as",
"$",
"address",
")",
"{",
"if",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"address",
")",
")",
"<=",
"0",
")",
"{",
"throw",
"new",
"EmailValidationException",
"(",
"__",
"(",
"'Recipient email address cannot be empty.'",
")",
")",
";",
"}",
"elseif",
"(",
"!",
"filter_var",
"(",
"$",
"address",
",",
"FILTER_VALIDATE_EMAIL",
")",
")",
"{",
"throw",
"new",
"EmailValidationException",
"(",
"__",
"(",
"'The email address ‘%s’ is invalid.', ar",
"r",
"y($ad",
"d",
"r",
"ess)));",
"",
"",
"",
"",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | Makes sure the Subject, Sender Email and Recipients values are
all set and are valid. The message body is checked in
`prepareMessageBody`
@see prepareMessageBody()
@throws EmailValidationException
@return boolean | [
"Makes",
"sure",
"the",
"Subject",
"Sender",
"Email",
"and",
"Recipients",
"values",
"are",
"all",
"set",
"and",
"are",
"valid",
".",
"The",
"message",
"body",
"is",
"checked",
"in",
"prepareMessageBody"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.emailgateway.php#L498-L517 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.emailgateway.php | EmailGateway.prepareMessageBody | protected function prepareMessageBody()
{
$attachments = $this->getSectionAttachments();
if ($attachments) {
$this->appendHeaderFields($this->contentInfoArray('multipart/mixed'));
if (!empty($this->_text_plain) && !empty($this->_text_html)) {
$this->_body = $this->boundaryDelimiterLine('multipart/mixed')
. $this->contentInfoString('multipart/alternative')
. $this->getSectionMultipartAlternative()
. $attachments
;
} elseif (!empty($this->_text_plain)) {
$this->_body = $this->boundaryDelimiterLine('multipart/mixed')
. $this->contentInfoString('text/plain')
. $this->getSectionTextPlain()
. $attachments
;
} elseif (!empty($this->_text_html)) {
$this->_body = $this->boundaryDelimiterLine('multipart/mixed')
. $this->contentInfoString('text/html')
. $this->getSectionTextHtml()
. $attachments
;
} else {
$this->_body = $attachments;
}
$this->_body .= $this->finalBoundaryDelimiterLine('multipart/mixed');
} elseif (!empty($this->_text_plain) && !empty($this->_text_html)) {
$this->appendHeaderFields($this->contentInfoArray('multipart/alternative'));
$this->_body = $this->getSectionMultipartAlternative();
} elseif (!empty($this->_text_plain)) {
$this->appendHeaderFields($this->contentInfoArray('text/plain'));
$this->_body = $this->getSectionTextPlain();
} elseif (!empty($this->_text_html)) {
$this->appendHeaderFields($this->contentInfoArray('text/html'));
$this->_body = $this->getSectionTextHtml();
} else {
throw new EmailGatewayException(__('No attachments or body text was set. Can not send empty email.'));
}
} | php | protected function prepareMessageBody()
{
$attachments = $this->getSectionAttachments();
if ($attachments) {
$this->appendHeaderFields($this->contentInfoArray('multipart/mixed'));
if (!empty($this->_text_plain) && !empty($this->_text_html)) {
$this->_body = $this->boundaryDelimiterLine('multipart/mixed')
. $this->contentInfoString('multipart/alternative')
. $this->getSectionMultipartAlternative()
. $attachments
;
} elseif (!empty($this->_text_plain)) {
$this->_body = $this->boundaryDelimiterLine('multipart/mixed')
. $this->contentInfoString('text/plain')
. $this->getSectionTextPlain()
. $attachments
;
} elseif (!empty($this->_text_html)) {
$this->_body = $this->boundaryDelimiterLine('multipart/mixed')
. $this->contentInfoString('text/html')
. $this->getSectionTextHtml()
. $attachments
;
} else {
$this->_body = $attachments;
}
$this->_body .= $this->finalBoundaryDelimiterLine('multipart/mixed');
} elseif (!empty($this->_text_plain) && !empty($this->_text_html)) {
$this->appendHeaderFields($this->contentInfoArray('multipart/alternative'));
$this->_body = $this->getSectionMultipartAlternative();
} elseif (!empty($this->_text_plain)) {
$this->appendHeaderFields($this->contentInfoArray('text/plain'));
$this->_body = $this->getSectionTextPlain();
} elseif (!empty($this->_text_html)) {
$this->appendHeaderFields($this->contentInfoArray('text/html'));
$this->_body = $this->getSectionTextHtml();
} else {
throw new EmailGatewayException(__('No attachments or body text was set. Can not send empty email.'));
}
} | [
"protected",
"function",
"prepareMessageBody",
"(",
")",
"{",
"$",
"attachments",
"=",
"$",
"this",
"->",
"getSectionAttachments",
"(",
")",
";",
"if",
"(",
"$",
"attachments",
")",
"{",
"$",
"this",
"->",
"appendHeaderFields",
"(",
"$",
"this",
"->",
"contentInfoArray",
"(",
"'multipart/mixed'",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_text_plain",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"_text_html",
")",
")",
"{",
"$",
"this",
"->",
"_body",
"=",
"$",
"this",
"->",
"boundaryDelimiterLine",
"(",
"'multipart/mixed'",
")",
".",
"$",
"this",
"->",
"contentInfoString",
"(",
"'multipart/alternative'",
")",
".",
"$",
"this",
"->",
"getSectionMultipartAlternative",
"(",
")",
".",
"$",
"attachments",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_text_plain",
")",
")",
"{",
"$",
"this",
"->",
"_body",
"=",
"$",
"this",
"->",
"boundaryDelimiterLine",
"(",
"'multipart/mixed'",
")",
".",
"$",
"this",
"->",
"contentInfoString",
"(",
"'text/plain'",
")",
".",
"$",
"this",
"->",
"getSectionTextPlain",
"(",
")",
".",
"$",
"attachments",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_text_html",
")",
")",
"{",
"$",
"this",
"->",
"_body",
"=",
"$",
"this",
"->",
"boundaryDelimiterLine",
"(",
"'multipart/mixed'",
")",
".",
"$",
"this",
"->",
"contentInfoString",
"(",
"'text/html'",
")",
".",
"$",
"this",
"->",
"getSectionTextHtml",
"(",
")",
".",
"$",
"attachments",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_body",
"=",
"$",
"attachments",
";",
"}",
"$",
"this",
"->",
"_body",
".=",
"$",
"this",
"->",
"finalBoundaryDelimiterLine",
"(",
"'multipart/mixed'",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_text_plain",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"_text_html",
")",
")",
"{",
"$",
"this",
"->",
"appendHeaderFields",
"(",
"$",
"this",
"->",
"contentInfoArray",
"(",
"'multipart/alternative'",
")",
")",
";",
"$",
"this",
"->",
"_body",
"=",
"$",
"this",
"->",
"getSectionMultipartAlternative",
"(",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_text_plain",
")",
")",
"{",
"$",
"this",
"->",
"appendHeaderFields",
"(",
"$",
"this",
"->",
"contentInfoArray",
"(",
"'text/plain'",
")",
")",
";",
"$",
"this",
"->",
"_body",
"=",
"$",
"this",
"->",
"getSectionTextPlain",
"(",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_text_html",
")",
")",
"{",
"$",
"this",
"->",
"appendHeaderFields",
"(",
"$",
"this",
"->",
"contentInfoArray",
"(",
"'text/html'",
")",
")",
";",
"$",
"this",
"->",
"_body",
"=",
"$",
"this",
"->",
"getSectionTextHtml",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"EmailGatewayException",
"(",
"__",
"(",
"'No attachments or body text was set. Can not send empty email.'",
")",
")",
";",
"}",
"}"
] | Build the message body and the content-describing header fields
The result of this building is an updated body variable in the
gateway itself.
@throws EmailGatewayException
@throws Exception
@return boolean | [
"Build",
"the",
"message",
"body",
"and",
"the",
"content",
"-",
"describing",
"header",
"fields"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.emailgateway.php#L529-L568 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.emailgateway.php | EmailGateway.getSectionMultipartAlternative | protected function getSectionMultipartAlternative()
{
$output = $this->boundaryDelimiterLine('multipart/alternative')
. $this->contentInfoString('text/plain')
. $this->getSectionTextPlain()
. $this->boundaryDelimiterLine('multipart/alternative')
. $this->contentInfoString('text/html')
. $this->getSectionTextHtml()
. $this->finalBoundaryDelimiterLine('multipart/alternative')
;
return $output;
} | php | protected function getSectionMultipartAlternative()
{
$output = $this->boundaryDelimiterLine('multipart/alternative')
. $this->contentInfoString('text/plain')
. $this->getSectionTextPlain()
. $this->boundaryDelimiterLine('multipart/alternative')
. $this->contentInfoString('text/html')
. $this->getSectionTextHtml()
. $this->finalBoundaryDelimiterLine('multipart/alternative')
;
return $output;
} | [
"protected",
"function",
"getSectionMultipartAlternative",
"(",
")",
"{",
"$",
"output",
"=",
"$",
"this",
"->",
"boundaryDelimiterLine",
"(",
"'multipart/alternative'",
")",
".",
"$",
"this",
"->",
"contentInfoString",
"(",
"'text/plain'",
")",
".",
"$",
"this",
"->",
"getSectionTextPlain",
"(",
")",
".",
"$",
"this",
"->",
"boundaryDelimiterLine",
"(",
"'multipart/alternative'",
")",
".",
"$",
"this",
"->",
"contentInfoString",
"(",
"'text/html'",
")",
".",
"$",
"this",
"->",
"getSectionTextHtml",
"(",
")",
".",
"$",
"this",
"->",
"finalBoundaryDelimiterLine",
"(",
"'multipart/alternative'",
")",
";",
"return",
"$",
"output",
";",
"}"
] | Build multipart email section. Used by sendmail and smtp classes to
send multipart email.
Will return a string containing the section. Can be used to send to
an email server directly.
@return string | [
"Build",
"multipart",
"email",
"section",
".",
"Used",
"by",
"sendmail",
"and",
"smtp",
"classes",
"to",
"send",
"multipart",
"email",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.emailgateway.php#L578-L590 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.emailgateway.php | EmailGateway.getSectionAttachments | protected function getSectionAttachments()
{
$output = '';
foreach ($this->_attachments as $key => $file) {
$tmp_file = false;
// If the attachment is a URL, download the file to a temporary location.
// This prevents downloading the file twice - once for info, once for data.
if (filter_var($file['file'], FILTER_VALIDATE_URL)) {
$gateway = new Gateway();
$gateway->init($file['file']);
$gateway->setopt('TIMEOUT', 30);
$file_content = @$gateway->exec();
$tmp_file = tempnam(TMP, 'attachment');
General::writeFile($tmp_file, $file_content, Symphony::Configuration()->get('write_mode', 'file'));
$original_filename = $file['file'];
$file['file'] = $tmp_file;
// Without this the temporary filename will be used. Ugly!
if (is_null($file['filename'])) {
$file['filename'] = basename($original_filename);
}
} else {
$file_content = @file_get_contents($file['file']);
}
if ($file_content !== false && !empty($file_content)) {
$output .= $this->boundaryDelimiterLine('multipart/mixed')
. $this->contentInfoString($file['mime-type'], $file['file'], $file['filename'], $file['charset'])
. EmailHelper::base64ContentTransferEncode($file_content);
} else {
if ($this->_validate_attachment_errors) {
if (!$tmp_file === false) {
$filename = $original_filename;
} else {
$filename = $file['file'];
}
throw new EmailGatewayException(__('The content of the file `%s` could not be loaded.', array($filename)));
}
}
if (!$tmp_file === false) {
General::deleteFile($tmp_file);
}
}
return $output;
} | php | protected function getSectionAttachments()
{
$output = '';
foreach ($this->_attachments as $key => $file) {
$tmp_file = false;
// If the attachment is a URL, download the file to a temporary location.
// This prevents downloading the file twice - once for info, once for data.
if (filter_var($file['file'], FILTER_VALIDATE_URL)) {
$gateway = new Gateway();
$gateway->init($file['file']);
$gateway->setopt('TIMEOUT', 30);
$file_content = @$gateway->exec();
$tmp_file = tempnam(TMP, 'attachment');
General::writeFile($tmp_file, $file_content, Symphony::Configuration()->get('write_mode', 'file'));
$original_filename = $file['file'];
$file['file'] = $tmp_file;
// Without this the temporary filename will be used. Ugly!
if (is_null($file['filename'])) {
$file['filename'] = basename($original_filename);
}
} else {
$file_content = @file_get_contents($file['file']);
}
if ($file_content !== false && !empty($file_content)) {
$output .= $this->boundaryDelimiterLine('multipart/mixed')
. $this->contentInfoString($file['mime-type'], $file['file'], $file['filename'], $file['charset'])
. EmailHelper::base64ContentTransferEncode($file_content);
} else {
if ($this->_validate_attachment_errors) {
if (!$tmp_file === false) {
$filename = $original_filename;
} else {
$filename = $file['file'];
}
throw new EmailGatewayException(__('The content of the file `%s` could not be loaded.', array($filename)));
}
}
if (!$tmp_file === false) {
General::deleteFile($tmp_file);
}
}
return $output;
} | [
"protected",
"function",
"getSectionAttachments",
"(",
")",
"{",
"$",
"output",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"_attachments",
"as",
"$",
"key",
"=>",
"$",
"file",
")",
"{",
"$",
"tmp_file",
"=",
"false",
";",
"// If the attachment is a URL, download the file to a temporary location.",
"// This prevents downloading the file twice - once for info, once for data.",
"if",
"(",
"filter_var",
"(",
"$",
"file",
"[",
"'file'",
"]",
",",
"FILTER_VALIDATE_URL",
")",
")",
"{",
"$",
"gateway",
"=",
"new",
"Gateway",
"(",
")",
";",
"$",
"gateway",
"->",
"init",
"(",
"$",
"file",
"[",
"'file'",
"]",
")",
";",
"$",
"gateway",
"->",
"setopt",
"(",
"'TIMEOUT'",
",",
"30",
")",
";",
"$",
"file_content",
"=",
"@",
"$",
"gateway",
"->",
"exec",
"(",
")",
";",
"$",
"tmp_file",
"=",
"tempnam",
"(",
"TMP",
",",
"'attachment'",
")",
";",
"General",
"::",
"writeFile",
"(",
"$",
"tmp_file",
",",
"$",
"file_content",
",",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'write_mode'",
",",
"'file'",
")",
")",
";",
"$",
"original_filename",
"=",
"$",
"file",
"[",
"'file'",
"]",
";",
"$",
"file",
"[",
"'file'",
"]",
"=",
"$",
"tmp_file",
";",
"// Without this the temporary filename will be used. Ugly!",
"if",
"(",
"is_null",
"(",
"$",
"file",
"[",
"'filename'",
"]",
")",
")",
"{",
"$",
"file",
"[",
"'filename'",
"]",
"=",
"basename",
"(",
"$",
"original_filename",
")",
";",
"}",
"}",
"else",
"{",
"$",
"file_content",
"=",
"@",
"file_get_contents",
"(",
"$",
"file",
"[",
"'file'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"file_content",
"!==",
"false",
"&&",
"!",
"empty",
"(",
"$",
"file_content",
")",
")",
"{",
"$",
"output",
".=",
"$",
"this",
"->",
"boundaryDelimiterLine",
"(",
"'multipart/mixed'",
")",
".",
"$",
"this",
"->",
"contentInfoString",
"(",
"$",
"file",
"[",
"'mime-type'",
"]",
",",
"$",
"file",
"[",
"'file'",
"]",
",",
"$",
"file",
"[",
"'filename'",
"]",
",",
"$",
"file",
"[",
"'charset'",
"]",
")",
".",
"EmailHelper",
"::",
"base64ContentTransferEncode",
"(",
"$",
"file_content",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"_validate_attachment_errors",
")",
"{",
"if",
"(",
"!",
"$",
"tmp_file",
"===",
"false",
")",
"{",
"$",
"filename",
"=",
"$",
"original_filename",
";",
"}",
"else",
"{",
"$",
"filename",
"=",
"$",
"file",
"[",
"'file'",
"]",
";",
"}",
"throw",
"new",
"EmailGatewayException",
"(",
"__",
"(",
"'The content of the file `%s` could not be loaded.'",
",",
"array",
"(",
"$",
"filename",
")",
")",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"tmp_file",
"===",
"false",
")",
"{",
"General",
"::",
"deleteFile",
"(",
"$",
"tmp_file",
")",
";",
"}",
"}",
"return",
"$",
"output",
";",
"}"
] | Builds the attachment section of a multipart email.
Will return a string containing the section. Can be used to send to
an email server directly.
@throws EmailGatewayException
@throws Exception
@return string | [
"Builds",
"the",
"attachment",
"section",
"of",
"a",
"multipart",
"email",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.emailgateway.php#L602-L652 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.emailgateway.php | EmailGateway.getSectionTextPlain | protected function getSectionTextPlain()
{
if ($this->_text_encoding == 'quoted-printable') {
return EmailHelper::qpContentTransferEncode($this->_text_plain)."\r\n";
} elseif ($this->_text_encoding == 'base64') {
// don't add CRLF if using base64 - spam filters don't
// like this
return EmailHelper::base64ContentTransferEncode($this->_text_plain);
}
return $this->_text_plain."\r\n";
} | php | protected function getSectionTextPlain()
{
if ($this->_text_encoding == 'quoted-printable') {
return EmailHelper::qpContentTransferEncode($this->_text_plain)."\r\n";
} elseif ($this->_text_encoding == 'base64') {
// don't add CRLF if using base64 - spam filters don't
// like this
return EmailHelper::base64ContentTransferEncode($this->_text_plain);
}
return $this->_text_plain."\r\n";
} | [
"protected",
"function",
"getSectionTextPlain",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_text_encoding",
"==",
"'quoted-printable'",
")",
"{",
"return",
"EmailHelper",
"::",
"qpContentTransferEncode",
"(",
"$",
"this",
"->",
"_text_plain",
")",
".",
"\"\\r\\n\"",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"_text_encoding",
"==",
"'base64'",
")",
"{",
"// don't add CRLF if using base64 - spam filters don't",
"// like this",
"return",
"EmailHelper",
"::",
"base64ContentTransferEncode",
"(",
"$",
"this",
"->",
"_text_plain",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_text_plain",
".",
"\"\\r\\n\"",
";",
"}"
] | Builds the text section of a text/plain email.
Will return a string containing the section. Can be used to send to
an email server directly.
@return string | [
"Builds",
"the",
"text",
"section",
"of",
"a",
"text",
"/",
"plain",
"email",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.emailgateway.php#L661-L672 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.emailgateway.php | EmailGateway.getSectionTextHtml | protected function getSectionTextHtml()
{
if ($this->_text_encoding == 'quoted-printable') {
return EmailHelper::qpContentTransferEncode($this->_text_html)."\r\n";
} elseif ($this->_text_encoding == 'base64') {
// don't add CRLF if using base64 - spam filters don't
// like this
return EmailHelper::base64ContentTransferEncode($this->_text_html);
}
return $this->_text_html."\r\n";
} | php | protected function getSectionTextHtml()
{
if ($this->_text_encoding == 'quoted-printable') {
return EmailHelper::qpContentTransferEncode($this->_text_html)."\r\n";
} elseif ($this->_text_encoding == 'base64') {
// don't add CRLF if using base64 - spam filters don't
// like this
return EmailHelper::base64ContentTransferEncode($this->_text_html);
}
return $this->_text_html."\r\n";
} | [
"protected",
"function",
"getSectionTextHtml",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_text_encoding",
"==",
"'quoted-printable'",
")",
"{",
"return",
"EmailHelper",
"::",
"qpContentTransferEncode",
"(",
"$",
"this",
"->",
"_text_html",
")",
".",
"\"\\r\\n\"",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"_text_encoding",
"==",
"'base64'",
")",
"{",
"// don't add CRLF if using base64 - spam filters don't",
"// like this",
"return",
"EmailHelper",
"::",
"base64ContentTransferEncode",
"(",
"$",
"this",
"->",
"_text_html",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_text_html",
".",
"\"\\r\\n\"",
";",
"}"
] | Builds the html section of a text/html email.
Will return a string containing the section. Can be used to send to
an email server directly.
@return string | [
"Builds",
"the",
"html",
"section",
"of",
"a",
"text",
"/",
"html",
"email",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.emailgateway.php#L681-L691 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.emailgateway.php | EmailGateway.contentInfoArray | public function contentInfoArray($type = null, $file = null, $filename = null, $charset = null)
{
// Common descriptions
$description = array(
'multipart/mixed' => array(
'Content-Type' => 'multipart/mixed; boundary="'
.$this->getBoundary('multipart/mixed').'"',
),
'multipart/alternative' => array(
'Content-Type' => 'multipart/alternative; boundary="'
.$this->getBoundary('multipart/alternative').'"',
),
'text/plain' => array(
'Content-Type' => 'text/plain; charset=UTF-8',
'Content-Transfer-Encoding' => $this->_text_encoding ? $this->_text_encoding : '8bit',
),
'text/html' => array(
'Content-Type' => 'text/html; charset=UTF-8',
'Content-Transfer-Encoding' => $this->_text_encoding ? $this->_text_encoding : '8bit',
),
);
// Try common
if (!empty($type) && !empty($description[$type])) {
// return it if found
return $description[$type];
}
// assure we have a file name
$filename = !is_null($filename) ? $filename : basename($file);
// Format charset for insertion in content-type, if needed
if (!empty($charset)) {
$charset = sprintf('charset=%s;', $charset);
} else {
$charset = '';
}
// if the mime type is not set, try to obtain using the getMimeType
if (empty($type)) {
//assume that the attachment mimetime is appended
$type = General::getMimeType($file);
}
// Return binary description
return array(
'Content-Type' => $type.';'.$charset.' name="'.$filename.'"',
'Content-Transfer-Encoding' => 'base64',
'Content-Disposition' => 'attachment; filename="' .$filename .'"',
);
} | php | public function contentInfoArray($type = null, $file = null, $filename = null, $charset = null)
{
// Common descriptions
$description = array(
'multipart/mixed' => array(
'Content-Type' => 'multipart/mixed; boundary="'
.$this->getBoundary('multipart/mixed').'"',
),
'multipart/alternative' => array(
'Content-Type' => 'multipart/alternative; boundary="'
.$this->getBoundary('multipart/alternative').'"',
),
'text/plain' => array(
'Content-Type' => 'text/plain; charset=UTF-8',
'Content-Transfer-Encoding' => $this->_text_encoding ? $this->_text_encoding : '8bit',
),
'text/html' => array(
'Content-Type' => 'text/html; charset=UTF-8',
'Content-Transfer-Encoding' => $this->_text_encoding ? $this->_text_encoding : '8bit',
),
);
// Try common
if (!empty($type) && !empty($description[$type])) {
// return it if found
return $description[$type];
}
// assure we have a file name
$filename = !is_null($filename) ? $filename : basename($file);
// Format charset for insertion in content-type, if needed
if (!empty($charset)) {
$charset = sprintf('charset=%s;', $charset);
} else {
$charset = '';
}
// if the mime type is not set, try to obtain using the getMimeType
if (empty($type)) {
//assume that the attachment mimetime is appended
$type = General::getMimeType($file);
}
// Return binary description
return array(
'Content-Type' => $type.';'.$charset.' name="'.$filename.'"',
'Content-Transfer-Encoding' => 'base64',
'Content-Disposition' => 'attachment; filename="' .$filename .'"',
);
} | [
"public",
"function",
"contentInfoArray",
"(",
"$",
"type",
"=",
"null",
",",
"$",
"file",
"=",
"null",
",",
"$",
"filename",
"=",
"null",
",",
"$",
"charset",
"=",
"null",
")",
"{",
"// Common descriptions",
"$",
"description",
"=",
"array",
"(",
"'multipart/mixed'",
"=>",
"array",
"(",
"'Content-Type'",
"=>",
"'multipart/mixed; boundary=\"'",
".",
"$",
"this",
"->",
"getBoundary",
"(",
"'multipart/mixed'",
")",
".",
"'\"'",
",",
")",
",",
"'multipart/alternative'",
"=>",
"array",
"(",
"'Content-Type'",
"=>",
"'multipart/alternative; boundary=\"'",
".",
"$",
"this",
"->",
"getBoundary",
"(",
"'multipart/alternative'",
")",
".",
"'\"'",
",",
")",
",",
"'text/plain'",
"=>",
"array",
"(",
"'Content-Type'",
"=>",
"'text/plain; charset=UTF-8'",
",",
"'Content-Transfer-Encoding'",
"=>",
"$",
"this",
"->",
"_text_encoding",
"?",
"$",
"this",
"->",
"_text_encoding",
":",
"'8bit'",
",",
")",
",",
"'text/html'",
"=>",
"array",
"(",
"'Content-Type'",
"=>",
"'text/html; charset=UTF-8'",
",",
"'Content-Transfer-Encoding'",
"=>",
"$",
"this",
"->",
"_text_encoding",
"?",
"$",
"this",
"->",
"_text_encoding",
":",
"'8bit'",
",",
")",
",",
")",
";",
"// Try common",
"if",
"(",
"!",
"empty",
"(",
"$",
"type",
")",
"&&",
"!",
"empty",
"(",
"$",
"description",
"[",
"$",
"type",
"]",
")",
")",
"{",
"// return it if found",
"return",
"$",
"description",
"[",
"$",
"type",
"]",
";",
"}",
"// assure we have a file name",
"$",
"filename",
"=",
"!",
"is_null",
"(",
"$",
"filename",
")",
"?",
"$",
"filename",
":",
"basename",
"(",
"$",
"file",
")",
";",
"// Format charset for insertion in content-type, if needed",
"if",
"(",
"!",
"empty",
"(",
"$",
"charset",
")",
")",
"{",
"$",
"charset",
"=",
"sprintf",
"(",
"'charset=%s;'",
",",
"$",
"charset",
")",
";",
"}",
"else",
"{",
"$",
"charset",
"=",
"''",
";",
"}",
"// if the mime type is not set, try to obtain using the getMimeType",
"if",
"(",
"empty",
"(",
"$",
"type",
")",
")",
"{",
"//assume that the attachment mimetime is appended",
"$",
"type",
"=",
"General",
"::",
"getMimeType",
"(",
"$",
"file",
")",
";",
"}",
"// Return binary description",
"return",
"array",
"(",
"'Content-Type'",
"=>",
"$",
"type",
".",
"';'",
".",
"$",
"charset",
".",
"' name=\"'",
".",
"$",
"filename",
".",
"'\"'",
",",
"'Content-Transfer-Encoding'",
"=>",
"'base64'",
",",
"'Content-Disposition'",
"=>",
"'attachment; filename=\"'",
".",
"$",
"filename",
".",
"'\"'",
",",
")",
";",
"}"
] | Builds the right content-type/encoding types based on file and
content-type.
Will try to match a common description, based on the $type param.
If nothing is found, will return a base64 attached file disposition.
Can be used to send to an email server directly.
@param string $type optional mime-type
@param string $file optional the path of the attachment
@param string $filename optional the name of the attached file
@param string $charset optional the charset of the attached file
@return array | [
"Builds",
"the",
"right",
"content",
"-",
"type",
"/",
"encoding",
"types",
"based",
"on",
"file",
"and",
"content",
"-",
"type",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.emailgateway.php#L709-L757 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.emailgateway.php | EmailGateway.contentInfoString | protected function contentInfoString($type = null, $file = null, $filename = null, $charset = null)
{
$data = $this->contentInfoArray($type, $file, $filename, $charset);
$fields = array();
foreach ($data as $key => $value) {
$fields[] = EmailHelper::fold(sprintf('%s: %s', $key, $value));
}
return !empty($fields) ? implode("\r\n", $fields)."\r\n\r\n" : null;
} | php | protected function contentInfoString($type = null, $file = null, $filename = null, $charset = null)
{
$data = $this->contentInfoArray($type, $file, $filename, $charset);
$fields = array();
foreach ($data as $key => $value) {
$fields[] = EmailHelper::fold(sprintf('%s: %s', $key, $value));
}
return !empty($fields) ? implode("\r\n", $fields)."\r\n\r\n" : null;
} | [
"protected",
"function",
"contentInfoString",
"(",
"$",
"type",
"=",
"null",
",",
"$",
"file",
"=",
"null",
",",
"$",
"filename",
"=",
"null",
",",
"$",
"charset",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"contentInfoArray",
"(",
"$",
"type",
",",
"$",
"file",
",",
"$",
"filename",
",",
"$",
"charset",
")",
";",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"fields",
"[",
"]",
"=",
"EmailHelper",
"::",
"fold",
"(",
"sprintf",
"(",
"'%s: %s'",
",",
"$",
"key",
",",
"$",
"value",
")",
")",
";",
"}",
"return",
"!",
"empty",
"(",
"$",
"fields",
")",
"?",
"implode",
"(",
"\"\\r\\n\"",
",",
"$",
"fields",
")",
".",
"\"\\r\\n\\r\\n\"",
":",
"null",
";",
"}"
] | Creates the properly formatted InfoString based on the InfoArray.
@see EmailGateway::contentInfoArray()
@return string|null | [
"Creates",
"the",
"properly",
"formatted",
"InfoString",
"based",
"on",
"the",
"InfoArray",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.emailgateway.php#L766-L776 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.emailgateway.php | EmailGateway.__toCamel | private function __toCamel($string, $caseFirst = false)
{
$string = strtolower($string);
$a = explode('_', $string);
$a = array_map('ucfirst', $a);
if (!$caseFirst) {
$a[0] = lcfirst($a[0]);
}
return implode('', $a);
} | php | private function __toCamel($string, $caseFirst = false)
{
$string = strtolower($string);
$a = explode('_', $string);
$a = array_map('ucfirst', $a);
if (!$caseFirst) {
$a[0] = lcfirst($a[0]);
}
return implode('', $a);
} | [
"private",
"function",
"__toCamel",
"(",
"$",
"string",
",",
"$",
"caseFirst",
"=",
"false",
")",
"{",
"$",
"string",
"=",
"strtolower",
"(",
"$",
"string",
")",
";",
"$",
"a",
"=",
"explode",
"(",
"'_'",
",",
"$",
"string",
")",
";",
"$",
"a",
"=",
"array_map",
"(",
"'ucfirst'",
",",
"$",
"a",
")",
";",
"if",
"(",
"!",
"$",
"caseFirst",
")",
"{",
"$",
"a",
"[",
"0",
"]",
"=",
"lcfirst",
"(",
"$",
"a",
"[",
"0",
"]",
")",
";",
"}",
"return",
"implode",
"(",
"''",
",",
"$",
"a",
")",
";",
"}"
] | Internal function to turn underscored variables into camelcase, for
use in methods.
Because Symphony has a difference in naming between properties and
methods (underscored vs camelcased) and the Email class uses the
magic __set function to find property-setting-methods, this
conversion is needed.
@param string $string
The string to convert
@param boolean $caseFirst
If this is true, the first character will be uppercased. Useful
for method names (setName).
If set to false, the first character will be lowercased. This is
default behaviour.
@return string | [
"Internal",
"function",
"to",
"turn",
"underscored",
"variables",
"into",
"camelcase",
"for",
"use",
"in",
"methods",
".",
"Because",
"Symphony",
"has",
"a",
"difference",
"in",
"naming",
"between",
"properties",
"and",
"methods",
"(",
"underscored",
"vs",
"camelcased",
")",
"and",
"the",
"Email",
"class",
"uses",
"the",
"magic",
"__set",
"function",
"to",
"find",
"property",
"-",
"setting",
"-",
"methods",
"this",
"conversion",
"is",
"needed",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.emailgateway.php#L882-L893 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.emailgateway.php | EmailGateway.__fromCamel | private function __fromCamel($string)
{
$string[0] = strtolower($string[0]);
return preg_replace_callback('/([A-Z])/', function($c) {
return "_" . strtolower($c[1]);
}, $string);
} | php | private function __fromCamel($string)
{
$string[0] = strtolower($string[0]);
return preg_replace_callback('/([A-Z])/', function($c) {
return "_" . strtolower($c[1]);
}, $string);
} | [
"private",
"function",
"__fromCamel",
"(",
"$",
"string",
")",
"{",
"$",
"string",
"[",
"0",
"]",
"=",
"strtolower",
"(",
"$",
"string",
"[",
"0",
"]",
")",
";",
"return",
"preg_replace_callback",
"(",
"'/([A-Z])/'",
",",
"function",
"(",
"$",
"c",
")",
"{",
"return",
"\"_\"",
".",
"strtolower",
"(",
"$",
"c",
"[",
"1",
"]",
")",
";",
"}",
",",
"$",
"string",
")",
";",
"}"
] | The reverse of the __toCamel function.
@param string $string
The string to convert
@return string | [
"The",
"reverse",
"of",
"the",
"__toCamel",
"function",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.emailgateway.php#L902-L909 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.flush | public function flush()
{
$this->_result = null;
$this->_lastResult = array();
$this->_lastQuery = null;
$this->_lastQueryHash = null;
} | php | public function flush()
{
$this->_result = null;
$this->_lastResult = array();
$this->_lastQuery = null;
$this->_lastQueryHash = null;
} | [
"public",
"function",
"flush",
"(",
")",
"{",
"$",
"this",
"->",
"_result",
"=",
"null",
";",
"$",
"this",
"->",
"_lastResult",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"_lastQuery",
"=",
"null",
";",
"$",
"this",
"->",
"_lastQueryHash",
"=",
"null",
";",
"}"
] | Resets the result, `$this->_lastResult` and `$this->_lastQuery` to their empty
values. Called on each query and when the class is destroyed. | [
"Resets",
"the",
"result",
"$this",
"-",
">",
"_lastResult",
"and",
"$this",
"-",
">",
"_lastQuery",
"to",
"their",
"empty",
"values",
".",
"Called",
"on",
"each",
"query",
"and",
"when",
"the",
"class",
"is",
"destroyed",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L175-L181 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.isConnected | public static function isConnected()
{
try {
$connected = (
isset(self::$_connection['id'])
&& !is_null(self::$_connection['id'])
);
} catch (Exception $ex) {
return false;
}
return $connected;
} | php | public static function isConnected()
{
try {
$connected = (
isset(self::$_connection['id'])
&& !is_null(self::$_connection['id'])
);
} catch (Exception $ex) {
return false;
}
return $connected;
} | [
"public",
"static",
"function",
"isConnected",
"(",
")",
"{",
"try",
"{",
"$",
"connected",
"=",
"(",
"isset",
"(",
"self",
"::",
"$",
"_connection",
"[",
"'id'",
"]",
")",
"&&",
"!",
"is_null",
"(",
"self",
"::",
"$",
"_connection",
"[",
"'id'",
"]",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"connected",
";",
"}"
] | Determines if a connection has been made to the MySQL server
@return boolean | [
"Determines",
"if",
"a",
"connection",
"has",
"been",
"made",
"to",
"the",
"MySQL",
"server"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L295-L307 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.connect | public function connect($host = null, $user = null, $password = null, $port = '3306', $database = null)
{
self::$_connection = array(
'host' => $host,
'user' => $user,
'pass' => $password,
'port' => $port,
'database' => $database
);
try {
self::$_connection['id'] = mysqli_connect(
self::$_connection['host'],
self::$_connection['user'],
self::$_connection['pass'],
self::$_connection['database'],
self::$_connection['port']
);
if (!$this->isConnected()) {
$this->__error('connect');
}
} catch (Exception $ex) {
$this->__error('connect');
}
return true;
} | php | public function connect($host = null, $user = null, $password = null, $port = '3306', $database = null)
{
self::$_connection = array(
'host' => $host,
'user' => $user,
'pass' => $password,
'port' => $port,
'database' => $database
);
try {
self::$_connection['id'] = mysqli_connect(
self::$_connection['host'],
self::$_connection['user'],
self::$_connection['pass'],
self::$_connection['database'],
self::$_connection['port']
);
if (!$this->isConnected()) {
$this->__error('connect');
}
} catch (Exception $ex) {
$this->__error('connect');
}
return true;
} | [
"public",
"function",
"connect",
"(",
"$",
"host",
"=",
"null",
",",
"$",
"user",
"=",
"null",
",",
"$",
"password",
"=",
"null",
",",
"$",
"port",
"=",
"'3306'",
",",
"$",
"database",
"=",
"null",
")",
"{",
"self",
"::",
"$",
"_connection",
"=",
"array",
"(",
"'host'",
"=>",
"$",
"host",
",",
"'user'",
"=>",
"$",
"user",
",",
"'pass'",
"=>",
"$",
"password",
",",
"'port'",
"=>",
"$",
"port",
",",
"'database'",
"=>",
"$",
"database",
")",
";",
"try",
"{",
"self",
"::",
"$",
"_connection",
"[",
"'id'",
"]",
"=",
"mysqli_connect",
"(",
"self",
"::",
"$",
"_connection",
"[",
"'host'",
"]",
",",
"self",
"::",
"$",
"_connection",
"[",
"'user'",
"]",
",",
"self",
"::",
"$",
"_connection",
"[",
"'pass'",
"]",
",",
"self",
"::",
"$",
"_connection",
"[",
"'database'",
"]",
",",
"self",
"::",
"$",
"_connection",
"[",
"'port'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isConnected",
"(",
")",
")",
"{",
"$",
"this",
"->",
"__error",
"(",
"'connect'",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"$",
"this",
"->",
"__error",
"(",
"'connect'",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Creates a connect to the database server given the credentials. If an
error occurs, a `DatabaseException` is thrown, otherwise true is returned
@param string $host
Defaults to null, which MySQL assumes as localhost.
@param string $user
Defaults to null
@param string $password
Defaults to null
@param string $port
Defaults to 3306.
@param null $database
@throws DatabaseException
@return boolean | [
"Creates",
"a",
"connect",
"to",
"the",
"database",
"server",
"given",
"the",
"credentials",
".",
"If",
"an",
"error",
"occurs",
"a",
"DatabaseException",
"is",
"thrown",
"otherwise",
"true",
"is",
"returned"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L338-L365 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.setTimeZone | public function setTimeZone($timezone = null)
{
if (is_null($timezone)) {
return;
}
// What is the time now in the install timezone
$symphony_date = new DateTime('now', new DateTimeZone($timezone));
// MySQL wants the offset to be in the format +/-H:I, getOffset returns offset in seconds
$utc = new DateTime('now ' . $symphony_date->getOffset() . ' seconds', new DateTimeZone("UTC"));
// Get the difference between the symphony install timezone and UTC
$offset = $symphony_date->diff($utc)->format('%R%H:%I');
$this->query("SET time_zone = '$offset'");
} | php | public function setTimeZone($timezone = null)
{
if (is_null($timezone)) {
return;
}
// What is the time now in the install timezone
$symphony_date = new DateTime('now', new DateTimeZone($timezone));
// MySQL wants the offset to be in the format +/-H:I, getOffset returns offset in seconds
$utc = new DateTime('now ' . $symphony_date->getOffset() . ' seconds', new DateTimeZone("UTC"));
// Get the difference between the symphony install timezone and UTC
$offset = $symphony_date->diff($utc)->format('%R%H:%I');
$this->query("SET time_zone = '$offset'");
} | [
"public",
"function",
"setTimeZone",
"(",
"$",
"timezone",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"timezone",
")",
")",
"{",
"return",
";",
"}",
"// What is the time now in the install timezone",
"$",
"symphony_date",
"=",
"new",
"DateTime",
"(",
"'now'",
",",
"new",
"DateTimeZone",
"(",
"$",
"timezone",
")",
")",
";",
"// MySQL wants the offset to be in the format +/-H:I, getOffset returns offset in seconds",
"$",
"utc",
"=",
"new",
"DateTime",
"(",
"'now '",
".",
"$",
"symphony_date",
"->",
"getOffset",
"(",
")",
".",
"' seconds'",
",",
"new",
"DateTimeZone",
"(",
"\"UTC\"",
")",
")",
";",
"// Get the difference between the symphony install timezone and UTC",
"$",
"offset",
"=",
"$",
"symphony_date",
"->",
"diff",
"(",
"$",
"utc",
")",
"->",
"format",
"(",
"'%R%H:%I'",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"SET time_zone = '$offset'\"",
")",
";",
"}"
] | Sets the MySQL connection to use this timezone instead of the default
MySQL server timezone.
@throws DatabaseException
@link https://dev.mysql.com/doc/refman/5.6/en/time-zone-support.html
@link https://github.com/symphonycms/symphony-2/issues/1726
@since Symphony 2.3.3
@param string $timezone
Timezone will human readable, such as Australia/Brisbane. | [
"Sets",
"the",
"MySQL",
"connection",
"to",
"use",
"this",
"timezone",
"instead",
"of",
"the",
"default",
"MySQL",
"server",
"timezone",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L421-L437 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.cleanValue | public static function cleanValue($value)
{
if (function_exists('mysqli_real_escape_string') && self::isConnected()) {
return mysqli_real_escape_string(self::$_connection['id'], $value);
} else {
return addslashes($value);
}
} | php | public static function cleanValue($value)
{
if (function_exists('mysqli_real_escape_string') && self::isConnected()) {
return mysqli_real_escape_string(self::$_connection['id'], $value);
} else {
return addslashes($value);
}
} | [
"public",
"static",
"function",
"cleanValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'mysqli_real_escape_string'",
")",
"&&",
"self",
"::",
"isConnected",
"(",
")",
")",
"{",
"return",
"mysqli_real_escape_string",
"(",
"self",
"::",
"$",
"_connection",
"[",
"'id'",
"]",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"return",
"addslashes",
"(",
"$",
"value",
")",
";",
"}",
"}"
] | This function will clean a string using the `mysqli_real_escape_string` function
taking into account the current database character encoding. Note that this
function does not encode _ or %. If `mysqli_real_escape_string` doesn't exist,
`addslashes` will be used as a backup option
@param string $value
The string to be encoded into an escaped SQL string
@return string
The escaped SQL string | [
"This",
"function",
"will",
"clean",
"a",
"string",
"using",
"the",
"mysqli_real_escape_string",
"function",
"taking",
"into",
"account",
"the",
"current",
"database",
"character",
"encoding",
".",
"Note",
"that",
"this",
"function",
"does",
"not",
"encode",
"_",
"or",
"%",
".",
"If",
"mysqli_real_escape_string",
"doesn",
"t",
"exist",
"addslashes",
"will",
"be",
"used",
"as",
"a",
"backup",
"option"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L450-L457 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.cleanFields | public static function cleanFields(array &$array)
{
foreach ($array as $key => $val) {
// Handle arrays with more than 1 level
if (is_array($val)) {
self::cleanFields($val);
continue;
} elseif (strlen($val) == 0) {
$array[$key] = 'null';
} else {
$array[$key] = "'" . self::cleanValue($val) . "'";
}
}
} | php | public static function cleanFields(array &$array)
{
foreach ($array as $key => $val) {
// Handle arrays with more than 1 level
if (is_array($val)) {
self::cleanFields($val);
continue;
} elseif (strlen($val) == 0) {
$array[$key] = 'null';
} else {
$array[$key] = "'" . self::cleanValue($val) . "'";
}
}
} | [
"public",
"static",
"function",
"cleanFields",
"(",
"array",
"&",
"$",
"array",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"// Handle arrays with more than 1 level",
"if",
"(",
"is_array",
"(",
"$",
"val",
")",
")",
"{",
"self",
"::",
"cleanFields",
"(",
"$",
"val",
")",
";",
"continue",
";",
"}",
"elseif",
"(",
"strlen",
"(",
"$",
"val",
")",
"==",
"0",
")",
"{",
"$",
"array",
"[",
"$",
"key",
"]",
"=",
"'null'",
";",
"}",
"else",
"{",
"$",
"array",
"[",
"$",
"key",
"]",
"=",
"\"'\"",
".",
"self",
"::",
"cleanValue",
"(",
"$",
"val",
")",
".",
"\"'\"",
";",
"}",
"}",
"}"
] | This function will apply the `cleanValue` function to an associative
array of data, encoding only the value, not the key. This function
can handle recursive arrays. This function manipulates the given
parameter by reference.
@see cleanValue
@param array $array
The associative array of data to encode, this parameter is manipulated
by reference. | [
"This",
"function",
"will",
"apply",
"the",
"cleanValue",
"function",
"to",
"an",
"associative",
"array",
"of",
"data",
"encoding",
"only",
"the",
"value",
"not",
"the",
"key",
".",
"This",
"function",
"can",
"handle",
"recursive",
"arrays",
".",
"This",
"function",
"manipulates",
"the",
"given",
"parameter",
"by",
"reference",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L470-L484 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.query | public function query($query, $type = "OBJECT")
{
if (empty($query) || self::isConnected() === false) {
return false;
}
$start = precision_timer();
$query = trim($query);
$query_type = $this->determineQueryType($query);
$query_hash = md5($query.$start);
if (self::$_connection['tbl_prefix'] !== 'tbl_') {
$query = preg_replace('/tbl_(\S+?)([\s\.,]|$)/', self::$_connection['tbl_prefix'].'\\1\\2', $query);
}
// TYPE is deprecated since MySQL 4.0.18, ENGINE is preferred
if ($query_type == self::__WRITE_OPERATION__) {
$query = preg_replace('/TYPE=(MyISAM|InnoDB)/i', 'ENGINE=$1', $query);
} elseif ($query_type == self::__READ_OPERATION__ && !preg_match('/^SELECT\s+SQL(_NO)?_CACHE/i', $query)) {
if ($this->isCachingEnabled()) {
$query = preg_replace('/^SELECT\s+/i', 'SELECT SQL_CACHE ', $query);
} else {
$query = preg_replace('/^SELECT\s+/i', 'SELECT SQL_NO_CACHE ', $query);
}
}
$this->flush();
$this->_lastQuery = $query;
$this->_lastQueryHash = $query_hash;
$this->_result = mysqli_query(self::$_connection['id'], $query);
$this->_lastInsertID = mysqli_insert_id(self::$_connection['id']);
self::$_query_count++;
if (mysqli_error(self::$_connection['id'])) {
$this->__error();
} elseif (($this->_result instanceof mysqli_result)) {
if ($type == "ASSOC") {
while ($row = mysqli_fetch_assoc($this->_result)) {
$this->_lastResult[] = $row;
}
} else {
while ($row = mysqli_fetch_object($this->_result)) {
$this->_lastResult[] = $row;
}
}
mysqli_free_result($this->_result);
}
$stop = precision_timer('stop', $start);
/**
* After a query has successfully executed, that is it was considered
* valid SQL, this delegate will provide the query, the query_hash and
* the execution time of the query.
*
* Note that this function only starts logging once the ExtensionManager
* is available, which means it will not fire for the first couple of
* queries that set the character set.
*
* @since Symphony 2.3
* @delegate PostQueryExecution
* @param string $context
* '/frontend/' or '/backend/'
* @param string $query
* The query that has just been executed
* @param string $query_hash
* The hash used by Symphony to uniquely identify this query
* @param float $execution_time
* The time that it took to run `$query`
*/
if (self::$_logging === true) {
if (Symphony::ExtensionManager() instanceof ExtensionManager) {
Symphony::ExtensionManager()->notifyMembers('PostQueryExecution', class_exists('Administration', false) ? '/backend/' : '/frontend/', array(
'query' => $query,
'query_hash' => $query_hash,
'execution_time' => $stop
));
// If the ExceptionHandler is enabled, then the user is authenticated
// or we have a serious issue, so log the query.
if (GenericExceptionHandler::$enabled) {
self::$_log[$query_hash] = array(
'query' => $query,
'query_hash' => $query_hash,
'execution_time' => $stop
);
}
// Symphony isn't ready yet. Log internally
} else {
self::$_log[$query_hash] = array(
'query' => $query,
'query_hash' => $query_hash,
'execution_time' => $stop
);
}
}
return true;
} | php | public function query($query, $type = "OBJECT")
{
if (empty($query) || self::isConnected() === false) {
return false;
}
$start = precision_timer();
$query = trim($query);
$query_type = $this->determineQueryType($query);
$query_hash = md5($query.$start);
if (self::$_connection['tbl_prefix'] !== 'tbl_') {
$query = preg_replace('/tbl_(\S+?)([\s\.,]|$)/', self::$_connection['tbl_prefix'].'\\1\\2', $query);
}
// TYPE is deprecated since MySQL 4.0.18, ENGINE is preferred
if ($query_type == self::__WRITE_OPERATION__) {
$query = preg_replace('/TYPE=(MyISAM|InnoDB)/i', 'ENGINE=$1', $query);
} elseif ($query_type == self::__READ_OPERATION__ && !preg_match('/^SELECT\s+SQL(_NO)?_CACHE/i', $query)) {
if ($this->isCachingEnabled()) {
$query = preg_replace('/^SELECT\s+/i', 'SELECT SQL_CACHE ', $query);
} else {
$query = preg_replace('/^SELECT\s+/i', 'SELECT SQL_NO_CACHE ', $query);
}
}
$this->flush();
$this->_lastQuery = $query;
$this->_lastQueryHash = $query_hash;
$this->_result = mysqli_query(self::$_connection['id'], $query);
$this->_lastInsertID = mysqli_insert_id(self::$_connection['id']);
self::$_query_count++;
if (mysqli_error(self::$_connection['id'])) {
$this->__error();
} elseif (($this->_result instanceof mysqli_result)) {
if ($type == "ASSOC") {
while ($row = mysqli_fetch_assoc($this->_result)) {
$this->_lastResult[] = $row;
}
} else {
while ($row = mysqli_fetch_object($this->_result)) {
$this->_lastResult[] = $row;
}
}
mysqli_free_result($this->_result);
}
$stop = precision_timer('stop', $start);
/**
* After a query has successfully executed, that is it was considered
* valid SQL, this delegate will provide the query, the query_hash and
* the execution time of the query.
*
* Note that this function only starts logging once the ExtensionManager
* is available, which means it will not fire for the first couple of
* queries that set the character set.
*
* @since Symphony 2.3
* @delegate PostQueryExecution
* @param string $context
* '/frontend/' or '/backend/'
* @param string $query
* The query that has just been executed
* @param string $query_hash
* The hash used by Symphony to uniquely identify this query
* @param float $execution_time
* The time that it took to run `$query`
*/
if (self::$_logging === true) {
if (Symphony::ExtensionManager() instanceof ExtensionManager) {
Symphony::ExtensionManager()->notifyMembers('PostQueryExecution', class_exists('Administration', false) ? '/backend/' : '/frontend/', array(
'query' => $query,
'query_hash' => $query_hash,
'execution_time' => $stop
));
// If the ExceptionHandler is enabled, then the user is authenticated
// or we have a serious issue, so log the query.
if (GenericExceptionHandler::$enabled) {
self::$_log[$query_hash] = array(
'query' => $query,
'query_hash' => $query_hash,
'execution_time' => $stop
);
}
// Symphony isn't ready yet. Log internally
} else {
self::$_log[$query_hash] = array(
'query' => $query,
'query_hash' => $query_hash,
'execution_time' => $stop
);
}
}
return true;
} | [
"public",
"function",
"query",
"(",
"$",
"query",
",",
"$",
"type",
"=",
"\"OBJECT\"",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"query",
")",
"||",
"self",
"::",
"isConnected",
"(",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"start",
"=",
"precision_timer",
"(",
")",
";",
"$",
"query",
"=",
"trim",
"(",
"$",
"query",
")",
";",
"$",
"query_type",
"=",
"$",
"this",
"->",
"determineQueryType",
"(",
"$",
"query",
")",
";",
"$",
"query_hash",
"=",
"md5",
"(",
"$",
"query",
".",
"$",
"start",
")",
";",
"if",
"(",
"self",
"::",
"$",
"_connection",
"[",
"'tbl_prefix'",
"]",
"!==",
"'tbl_'",
")",
"{",
"$",
"query",
"=",
"preg_replace",
"(",
"'/tbl_(\\S+?)([\\s\\.,]|$)/'",
",",
"self",
"::",
"$",
"_connection",
"[",
"'tbl_prefix'",
"]",
".",
"'\\\\1\\\\2'",
",",
"$",
"query",
")",
";",
"}",
"// TYPE is deprecated since MySQL 4.0.18, ENGINE is preferred",
"if",
"(",
"$",
"query_type",
"==",
"self",
"::",
"__WRITE_OPERATION__",
")",
"{",
"$",
"query",
"=",
"preg_replace",
"(",
"'/TYPE=(MyISAM|InnoDB)/i'",
",",
"'ENGINE=$1'",
",",
"$",
"query",
")",
";",
"}",
"elseif",
"(",
"$",
"query_type",
"==",
"self",
"::",
"__READ_OPERATION__",
"&&",
"!",
"preg_match",
"(",
"'/^SELECT\\s+SQL(_NO)?_CACHE/i'",
",",
"$",
"query",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isCachingEnabled",
"(",
")",
")",
"{",
"$",
"query",
"=",
"preg_replace",
"(",
"'/^SELECT\\s+/i'",
",",
"'SELECT SQL_CACHE '",
",",
"$",
"query",
")",
";",
"}",
"else",
"{",
"$",
"query",
"=",
"preg_replace",
"(",
"'/^SELECT\\s+/i'",
",",
"'SELECT SQL_NO_CACHE '",
",",
"$",
"query",
")",
";",
"}",
"}",
"$",
"this",
"->",
"flush",
"(",
")",
";",
"$",
"this",
"->",
"_lastQuery",
"=",
"$",
"query",
";",
"$",
"this",
"->",
"_lastQueryHash",
"=",
"$",
"query_hash",
";",
"$",
"this",
"->",
"_result",
"=",
"mysqli_query",
"(",
"self",
"::",
"$",
"_connection",
"[",
"'id'",
"]",
",",
"$",
"query",
")",
";",
"$",
"this",
"->",
"_lastInsertID",
"=",
"mysqli_insert_id",
"(",
"self",
"::",
"$",
"_connection",
"[",
"'id'",
"]",
")",
";",
"self",
"::",
"$",
"_query_count",
"++",
";",
"if",
"(",
"mysqli_error",
"(",
"self",
"::",
"$",
"_connection",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"__error",
"(",
")",
";",
"}",
"elseif",
"(",
"(",
"$",
"this",
"->",
"_result",
"instanceof",
"mysqli_result",
")",
")",
"{",
"if",
"(",
"$",
"type",
"==",
"\"ASSOC\"",
")",
"{",
"while",
"(",
"$",
"row",
"=",
"mysqli_fetch_assoc",
"(",
"$",
"this",
"->",
"_result",
")",
")",
"{",
"$",
"this",
"->",
"_lastResult",
"[",
"]",
"=",
"$",
"row",
";",
"}",
"}",
"else",
"{",
"while",
"(",
"$",
"row",
"=",
"mysqli_fetch_object",
"(",
"$",
"this",
"->",
"_result",
")",
")",
"{",
"$",
"this",
"->",
"_lastResult",
"[",
"]",
"=",
"$",
"row",
";",
"}",
"}",
"mysqli_free_result",
"(",
"$",
"this",
"->",
"_result",
")",
";",
"}",
"$",
"stop",
"=",
"precision_timer",
"(",
"'stop'",
",",
"$",
"start",
")",
";",
"/**\n * After a query has successfully executed, that is it was considered\n * valid SQL, this delegate will provide the query, the query_hash and\n * the execution time of the query.\n *\n * Note that this function only starts logging once the ExtensionManager\n * is available, which means it will not fire for the first couple of\n * queries that set the character set.\n *\n * @since Symphony 2.3\n * @delegate PostQueryExecution\n * @param string $context\n * '/frontend/' or '/backend/'\n * @param string $query\n * The query that has just been executed\n * @param string $query_hash\n * The hash used by Symphony to uniquely identify this query\n * @param float $execution_time\n * The time that it took to run `$query`\n */",
"if",
"(",
"self",
"::",
"$",
"_logging",
"===",
"true",
")",
"{",
"if",
"(",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"instanceof",
"ExtensionManager",
")",
"{",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'PostQueryExecution'",
",",
"class_exists",
"(",
"'Administration'",
",",
"false",
")",
"?",
"'/backend/'",
":",
"'/frontend/'",
",",
"array",
"(",
"'query'",
"=>",
"$",
"query",
",",
"'query_hash'",
"=>",
"$",
"query_hash",
",",
"'execution_time'",
"=>",
"$",
"stop",
")",
")",
";",
"// If the ExceptionHandler is enabled, then the user is authenticated",
"// or we have a serious issue, so log the query.",
"if",
"(",
"GenericExceptionHandler",
"::",
"$",
"enabled",
")",
"{",
"self",
"::",
"$",
"_log",
"[",
"$",
"query_hash",
"]",
"=",
"array",
"(",
"'query'",
"=>",
"$",
"query",
",",
"'query_hash'",
"=>",
"$",
"query_hash",
",",
"'execution_time'",
"=>",
"$",
"stop",
")",
";",
"}",
"// Symphony isn't ready yet. Log internally",
"}",
"else",
"{",
"self",
"::",
"$",
"_log",
"[",
"$",
"query_hash",
"]",
"=",
"array",
"(",
"'query'",
"=>",
"$",
"query",
",",
"'query_hash'",
"=>",
"$",
"query_hash",
",",
"'execution_time'",
"=>",
"$",
"stop",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Takes an SQL string and executes it. This function will apply query
caching if it is a read operation and if query caching is set. Symphony
will convert the `tbl_` prefix of tables to be the one set during installation.
A type parameter is provided to specify whether `$this->_lastResult` will be an array
of objects or an array of associative arrays. The default is objects. This
function will return boolean, but set `$this->_lastResult` to the result.
@uses PostQueryExecution
@param string $query
The full SQL query to execute.
@param string $type
Whether to return the result as objects or associative array. Defaults
to OBJECT which will return objects. The other option is ASSOC. If $type
is not either of these, it will return objects.
@throws DatabaseException
@return boolean
true if the query executed without errors, false otherwise | [
"Takes",
"an",
"SQL",
"string",
"and",
"executes",
"it",
".",
"This",
"function",
"will",
"apply",
"query",
"caching",
"if",
"it",
"is",
"a",
"read",
"operation",
"and",
"if",
"query",
"caching",
"is",
"set",
".",
"Symphony",
"will",
"convert",
"the",
"tbl_",
"prefix",
"of",
"tables",
"to",
"be",
"the",
"one",
"set",
"during",
"installation",
".",
"A",
"type",
"parameter",
"is",
"provided",
"to",
"specify",
"whether",
"$this",
"-",
">",
"_lastResult",
"will",
"be",
"an",
"array",
"of",
"objects",
"or",
"an",
"array",
"of",
"associative",
"arrays",
".",
"The",
"default",
"is",
"objects",
".",
"This",
"function",
"will",
"return",
"boolean",
"but",
"set",
"$this",
"-",
">",
"_lastResult",
"to",
"the",
"result",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L520-L620 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.insert | public function insert(array $fields, $table, $updateOnDuplicate = false)
{
// Multiple Insert
if (is_array(current($fields))) {
$sql = "INSERT INTO `$table` (`".implode('`, `', array_keys(current($fields))).'`) VALUES ';
$rows = array();
foreach ($fields as $key => $array) {
// Sanity check: Make sure we dont end up with ',()' in the SQL.
if (!is_array($array)) {
continue;
}
self::cleanFields($array);
$rows[] = '('.implode(', ', $array).')';
}
$sql .= implode(", ", $rows);
// Single Insert
} else {
self::cleanFields($fields);
$sql = "INSERT INTO `$table` (`".implode('`, `', array_keys($fields)).'`) VALUES ('.implode(', ', $fields).')';
if ($updateOnDuplicate) {
$sql .= ' ON DUPLICATE KEY UPDATE ';
foreach ($fields as $key => $value) {
$sql .= " `$key` = $value,";
}
$sql = trim($sql, ',');
}
}
return $this->query($sql);
} | php | public function insert(array $fields, $table, $updateOnDuplicate = false)
{
// Multiple Insert
if (is_array(current($fields))) {
$sql = "INSERT INTO `$table` (`".implode('`, `', array_keys(current($fields))).'`) VALUES ';
$rows = array();
foreach ($fields as $key => $array) {
// Sanity check: Make sure we dont end up with ',()' in the SQL.
if (!is_array($array)) {
continue;
}
self::cleanFields($array);
$rows[] = '('.implode(', ', $array).')';
}
$sql .= implode(", ", $rows);
// Single Insert
} else {
self::cleanFields($fields);
$sql = "INSERT INTO `$table` (`".implode('`, `', array_keys($fields)).'`) VALUES ('.implode(', ', $fields).')';
if ($updateOnDuplicate) {
$sql .= ' ON DUPLICATE KEY UPDATE ';
foreach ($fields as $key => $value) {
$sql .= " `$key` = $value,";
}
$sql = trim($sql, ',');
}
}
return $this->query($sql);
} | [
"public",
"function",
"insert",
"(",
"array",
"$",
"fields",
",",
"$",
"table",
",",
"$",
"updateOnDuplicate",
"=",
"false",
")",
"{",
"// Multiple Insert",
"if",
"(",
"is_array",
"(",
"current",
"(",
"$",
"fields",
")",
")",
")",
"{",
"$",
"sql",
"=",
"\"INSERT INTO `$table` (`\"",
".",
"implode",
"(",
"'`, `'",
",",
"array_keys",
"(",
"current",
"(",
"$",
"fields",
")",
")",
")",
".",
"'`) VALUES '",
";",
"$",
"rows",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"key",
"=>",
"$",
"array",
")",
"{",
"// Sanity check: Make sure we dont end up with ',()' in the SQL.",
"if",
"(",
"!",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
"continue",
";",
"}",
"self",
"::",
"cleanFields",
"(",
"$",
"array",
")",
";",
"$",
"rows",
"[",
"]",
"=",
"'('",
".",
"implode",
"(",
"', '",
",",
"$",
"array",
")",
".",
"')'",
";",
"}",
"$",
"sql",
".=",
"implode",
"(",
"\", \"",
",",
"$",
"rows",
")",
";",
"// Single Insert",
"}",
"else",
"{",
"self",
"::",
"cleanFields",
"(",
"$",
"fields",
")",
";",
"$",
"sql",
"=",
"\"INSERT INTO `$table` (`\"",
".",
"implode",
"(",
"'`, `'",
",",
"array_keys",
"(",
"$",
"fields",
")",
")",
".",
"'`) VALUES ('",
".",
"implode",
"(",
"', '",
",",
"$",
"fields",
")",
".",
"')'",
";",
"if",
"(",
"$",
"updateOnDuplicate",
")",
"{",
"$",
"sql",
".=",
"' ON DUPLICATE KEY UPDATE '",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"sql",
".=",
"\" `$key` = $value,\"",
";",
"}",
"$",
"sql",
"=",
"trim",
"(",
"$",
"sql",
",",
"','",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"}"
] | A convenience method to insert data into the Database. This function
takes an associative array of data to input, with the keys being the column
names and the table. An optional parameter exposes MySQL's ON DUPLICATE
KEY UPDATE functionality, which will update the values if a duplicate key
is found.
@param array $fields
An associative array of data to input, with the key's mapping to the
column names. Alternatively, an array of associative array's can be
provided, which will perform multiple inserts
@param string $table
The table name, including the tbl prefix which will be changed
to this Symphony's table prefix in the query function
@param boolean $updateOnDuplicate
If set to true, data will updated if any key constraints are found that cause
conflicts. By default this is set to false, which will not update the data and
would return an SQL error
@throws DatabaseException
@return boolean | [
"A",
"convenience",
"method",
"to",
"insert",
"data",
"into",
"the",
"Database",
".",
"This",
"function",
"takes",
"an",
"associative",
"array",
"of",
"data",
"to",
"input",
"with",
"the",
"keys",
"being",
"the",
"column",
"names",
"and",
"the",
"table",
".",
"An",
"optional",
"parameter",
"exposes",
"MySQL",
"s",
"ON",
"DUPLICATE",
"KEY",
"UPDATE",
"functionality",
"which",
"will",
"update",
"the",
"values",
"if",
"a",
"duplicate",
"key",
"is",
"found",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L655-L691 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.update | public function update($fields, $table, $where = null)
{
self::cleanFields($fields);
$sql = "UPDATE $table SET ";
$rows = array();
foreach ($fields as $key => $val) {
$rows[] = " `$key` = $val";
}
$sql .= implode(', ', $rows) . (!is_null($where) ? ' WHERE ' . $where : null);
return $this->query($sql);
} | php | public function update($fields, $table, $where = null)
{
self::cleanFields($fields);
$sql = "UPDATE $table SET ";
$rows = array();
foreach ($fields as $key => $val) {
$rows[] = " `$key` = $val";
}
$sql .= implode(', ', $rows) . (!is_null($where) ? ' WHERE ' . $where : null);
return $this->query($sql);
} | [
"public",
"function",
"update",
"(",
"$",
"fields",
",",
"$",
"table",
",",
"$",
"where",
"=",
"null",
")",
"{",
"self",
"::",
"cleanFields",
"(",
"$",
"fields",
")",
";",
"$",
"sql",
"=",
"\"UPDATE $table SET \"",
";",
"$",
"rows",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"rows",
"[",
"]",
"=",
"\" `$key` = $val\"",
";",
"}",
"$",
"sql",
".=",
"implode",
"(",
"', '",
",",
"$",
"rows",
")",
".",
"(",
"!",
"is_null",
"(",
"$",
"where",
")",
"?",
"' WHERE '",
".",
"$",
"where",
":",
"null",
")",
";",
"return",
"$",
"this",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"}"
] | A convenience method to update data that exists in the Database. This function
takes an associative array of data to input, with the keys being the column
names and the table. A WHERE statement can be provided to select the rows
to update
@param array $fields
An associative array of data to input, with the key's mapping to the
column names.
@param string $table
The table name, including the tbl prefix which will be changed
to this Symphony's table prefix in the query function
@param string $where
A WHERE statement for this UPDATE statement, defaults to null
which will update all rows in the $table
@throws DatabaseException
@return boolean | [
"A",
"convenience",
"method",
"to",
"update",
"data",
"that",
"exists",
"in",
"the",
"Database",
".",
"This",
"function",
"takes",
"an",
"associative",
"array",
"of",
"data",
"to",
"input",
"with",
"the",
"keys",
"being",
"the",
"column",
"names",
"and",
"the",
"table",
".",
"A",
"WHERE",
"statement",
"can",
"be",
"provided",
"to",
"select",
"the",
"rows",
"to",
"update"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L711-L724 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.delete | public function delete($table, $where = null)
{
$sql = "DELETE FROM `$table`";
if (!is_null($where)) {
$sql .= " WHERE $where";
}
return $this->query($sql);
} | php | public function delete($table, $where = null)
{
$sql = "DELETE FROM `$table`";
if (!is_null($where)) {
$sql .= " WHERE $where";
}
return $this->query($sql);
} | [
"public",
"function",
"delete",
"(",
"$",
"table",
",",
"$",
"where",
"=",
"null",
")",
"{",
"$",
"sql",
"=",
"\"DELETE FROM `$table`\"",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"where",
")",
")",
"{",
"$",
"sql",
".=",
"\" WHERE $where\"",
";",
"}",
"return",
"$",
"this",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"}"
] | Given a table name and a WHERE statement, delete rows from the
Database.
@param string $table
The table name, including the tbl prefix which will be changed
to this Symphony's table prefix in the query function
@param string $where
A WHERE statement for this DELETE statement, defaults to null,
which will delete all rows in the $table
@throws DatabaseException
@return boolean | [
"Given",
"a",
"table",
"name",
"and",
"a",
"WHERE",
"statement",
"delete",
"rows",
"from",
"the",
"Database",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L739-L748 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.fetch | public function fetch($query = null, $index_by_column = null)
{
if (!is_null($query)) {
$this->query($query, "ASSOC");
} elseif (is_null($this->_lastResult)) {
return array();
}
$result = $this->_lastResult;
if (!is_null($index_by_column) && isset($result[0][$index_by_column])) {
$n = array();
foreach ($result as $ii) {
$n[$ii[$index_by_column]] = $ii;
}
$result = $n;
}
return $result;
} | php | public function fetch($query = null, $index_by_column = null)
{
if (!is_null($query)) {
$this->query($query, "ASSOC");
} elseif (is_null($this->_lastResult)) {
return array();
}
$result = $this->_lastResult;
if (!is_null($index_by_column) && isset($result[0][$index_by_column])) {
$n = array();
foreach ($result as $ii) {
$n[$ii[$index_by_column]] = $ii;
}
$result = $n;
}
return $result;
} | [
"public",
"function",
"fetch",
"(",
"$",
"query",
"=",
"null",
",",
"$",
"index_by_column",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"query",
")",
")",
"{",
"$",
"this",
"->",
"query",
"(",
"$",
"query",
",",
"\"ASSOC\"",
")",
";",
"}",
"elseif",
"(",
"is_null",
"(",
"$",
"this",
"->",
"_lastResult",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"_lastResult",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"index_by_column",
")",
"&&",
"isset",
"(",
"$",
"result",
"[",
"0",
"]",
"[",
"$",
"index_by_column",
"]",
")",
")",
"{",
"$",
"n",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"ii",
")",
"{",
"$",
"n",
"[",
"$",
"ii",
"[",
"$",
"index_by_column",
"]",
"]",
"=",
"$",
"ii",
";",
"}",
"$",
"result",
"=",
"$",
"n",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns an associative array that contains the results of the
given `$query`. Optionally, the resulting array can be indexed
by a particular column.
@param string $query
The full SQL query to execute. Defaults to null, which will
use the _lastResult
@param string $index_by_column
The name of a column in the table to use it's value to index
the result by. If this is omitted (and it is by default), an
array of associative arrays is returned, with the key being the
column names
@throws DatabaseException
@return array
An associative array with the column names as the keys | [
"Returns",
"an",
"associative",
"array",
"that",
"contains",
"the",
"results",
"of",
"the",
"given",
"$query",
".",
"Optionally",
"the",
"resulting",
"array",
"can",
"be",
"indexed",
"by",
"a",
"particular",
"column",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L767-L788 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.fetchRow | public function fetchRow($offset = 0, $query = null)
{
$result = $this->fetch($query);
return (empty($result) ? array() : $result[$offset]);
} | php | public function fetchRow($offset = 0, $query = null)
{
$result = $this->fetch($query);
return (empty($result) ? array() : $result[$offset]);
} | [
"public",
"function",
"fetchRow",
"(",
"$",
"offset",
"=",
"0",
",",
"$",
"query",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"fetch",
"(",
"$",
"query",
")",
";",
"return",
"(",
"empty",
"(",
"$",
"result",
")",
"?",
"array",
"(",
")",
":",
"$",
"result",
"[",
"$",
"offset",
"]",
")",
";",
"}"
] | Returns the row at the specified index from the given query. If no
query is given, it will use the `$this->_lastResult`. If no offset is provided,
the function will return the first row. This function does not imply any
LIMIT to the given `$query`, so for the more efficient use, it is recommended
that the `$query` have a LIMIT set.
@param integer $offset
The row to return from the SQL query. For instance, if the second
row from the result was required, the offset would be 1, because it
is zero based.
@param string $query
The full SQL query to execute. Defaults to null, which will
use the `$this->_lastResult`
@throws DatabaseException
@return array
If there is no row at the specified `$offset`, an empty array will be returned
otherwise an associative array of that row will be returned. | [
"Returns",
"the",
"row",
"at",
"the",
"specified",
"index",
"from",
"the",
"given",
"query",
".",
"If",
"no",
"query",
"is",
"given",
"it",
"will",
"use",
"the",
"$this",
"-",
">",
"_lastResult",
".",
"If",
"no",
"offset",
"is",
"provided",
"the",
"function",
"will",
"return",
"the",
"first",
"row",
".",
"This",
"function",
"does",
"not",
"imply",
"any",
"LIMIT",
"to",
"the",
"given",
"$query",
"so",
"for",
"the",
"more",
"efficient",
"use",
"it",
"is",
"recommended",
"that",
"the",
"$query",
"have",
"a",
"LIMIT",
"set",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L809-L813 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.fetchCol | public function fetchCol($column, $query = null)
{
$result = $this->fetch($query);
if (empty($result)) {
return array();
}
$rows = array();
foreach ($result as $row) {
$rows[] = $row[$column];
}
return $rows;
} | php | public function fetchCol($column, $query = null)
{
$result = $this->fetch($query);
if (empty($result)) {
return array();
}
$rows = array();
foreach ($result as $row) {
$rows[] = $row[$column];
}
return $rows;
} | [
"public",
"function",
"fetchCol",
"(",
"$",
"column",
",",
"$",
"query",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"fetch",
"(",
"$",
"query",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"rows",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"row",
")",
"{",
"$",
"rows",
"[",
"]",
"=",
"$",
"row",
"[",
"$",
"column",
"]",
";",
"}",
"return",
"$",
"rows",
";",
"}"
] | Returns an array of values for a specified column in a given query.
If no query is given, it will use the `$this->_lastResult`.
@param string $column
The column name in the query to return the values for
@param string $query
The full SQL query to execute. Defaults to null, which will
use the `$this->_lastResult`
@throws DatabaseException
@return array
If there is no results for the `$query`, an empty array will be returned
otherwise an array of values for that given `$column` will be returned | [
"Returns",
"an",
"array",
"of",
"values",
"for",
"a",
"specified",
"column",
"in",
"a",
"given",
"query",
".",
"If",
"no",
"query",
"is",
"given",
"it",
"will",
"use",
"the",
"$this",
"-",
">",
"_lastResult",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L829-L843 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.fetchVar | public function fetchVar($column, $offset = 0, $query = null)
{
$result = $this->fetch($query);
return (empty($result) ? null : $result[$offset][$column]);
} | php | public function fetchVar($column, $offset = 0, $query = null)
{
$result = $this->fetch($query);
return (empty($result) ? null : $result[$offset][$column]);
} | [
"public",
"function",
"fetchVar",
"(",
"$",
"column",
",",
"$",
"offset",
"=",
"0",
",",
"$",
"query",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"fetch",
"(",
"$",
"query",
")",
";",
"return",
"(",
"empty",
"(",
"$",
"result",
")",
"?",
"null",
":",
"$",
"result",
"[",
"$",
"offset",
"]",
"[",
"$",
"column",
"]",
")",
";",
"}"
] | Returns the value for a specified column at a specified offset. If no
offset is provided, it will return the value for column of the first row.
If no query is given, it will use the `$this->_lastResult`.
@param string $column
The column name in the query to return the values for
@param integer $offset
The row to use to return the value for the given `$column` from the SQL
query. For instance, if `$column` form the second row was required, the
offset would be 1, because it is zero based.
@param string $query
The full SQL query to execute. Defaults to null, which will
use the `$this->_lastResult`
@throws DatabaseException
@return string|null
Returns the value of the given column, if it doesn't exist, null will be
returned | [
"Returns",
"the",
"value",
"for",
"a",
"specified",
"column",
"at",
"a",
"specified",
"offset",
".",
"If",
"no",
"offset",
"is",
"provided",
"it",
"will",
"return",
"the",
"value",
"for",
"column",
"of",
"the",
"first",
"row",
".",
"If",
"no",
"query",
"is",
"given",
"it",
"will",
"use",
"the",
"$this",
"-",
">",
"_lastResult",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L864-L868 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.tableContainsField | public function tableContainsField($table, $field)
{
$table = MySQL::cleanValue($table);
$field = MySQL::cleanValue($field);
$results = $this->fetch("DESC `{$table}` `{$field}`");
return (is_array($results) && !empty($results));
} | php | public function tableContainsField($table, $field)
{
$table = MySQL::cleanValue($table);
$field = MySQL::cleanValue($field);
$results = $this->fetch("DESC `{$table}` `{$field}`");
return (is_array($results) && !empty($results));
} | [
"public",
"function",
"tableContainsField",
"(",
"$",
"table",
",",
"$",
"field",
")",
"{",
"$",
"table",
"=",
"MySQL",
"::",
"cleanValue",
"(",
"$",
"table",
")",
";",
"$",
"field",
"=",
"MySQL",
"::",
"cleanValue",
"(",
"$",
"field",
")",
";",
"$",
"results",
"=",
"$",
"this",
"->",
"fetch",
"(",
"\"DESC `{$table}` `{$field}`\"",
")",
";",
"return",
"(",
"is_array",
"(",
"$",
"results",
")",
"&&",
"!",
"empty",
"(",
"$",
"results",
")",
")",
";",
"}"
] | This function takes `$table` and `$field` names and returns boolean
if the `$table` contains the `$field`.
@since Symphony 2.3
@link https://dev.mysql.com/doc/refman/en/describe.html
@param string $table
The table name
@param string $field
The field name
@throws DatabaseException
@return boolean
true if `$table` contains `$field`, false otherwise | [
"This",
"function",
"takes",
"$table",
"and",
"$field",
"names",
"and",
"returns",
"boolean",
"if",
"the",
"$table",
"contains",
"the",
"$field",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L884-L890 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.tableExists | public function tableExists($table)
{
$table = MySQL::cleanValue($table);
$results = $this->fetch(sprintf("SHOW TABLES LIKE '%s'", $table));
return (is_array($results) && !empty($results));
} | php | public function tableExists($table)
{
$table = MySQL::cleanValue($table);
$results = $this->fetch(sprintf("SHOW TABLES LIKE '%s'", $table));
return (is_array($results) && !empty($results));
} | [
"public",
"function",
"tableExists",
"(",
"$",
"table",
")",
"{",
"$",
"table",
"=",
"MySQL",
"::",
"cleanValue",
"(",
"$",
"table",
")",
";",
"$",
"results",
"=",
"$",
"this",
"->",
"fetch",
"(",
"sprintf",
"(",
"\"SHOW TABLES LIKE '%s'\"",
",",
"$",
"table",
")",
")",
";",
"return",
"(",
"is_array",
"(",
"$",
"results",
")",
"&&",
"!",
"empty",
"(",
"$",
"results",
")",
")",
";",
"}"
] | This function takes `$table` and returns boolean
if it exists or not.
@since Symphony 2.3.4
@link https://dev.mysql.com/doc/refman/en/show-tables.html
@param string $table
The table name
@throws DatabaseException
@return boolean
true if `$table` exists, false otherwise | [
"This",
"function",
"takes",
"$table",
"and",
"returns",
"boolean",
"if",
"it",
"exists",
"or",
"not",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L904-L909 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.__error | private function __error($type = null)
{
if ($type == 'connect') {
$msg = mysqli_connect_error();
$errornum = mysqli_connect_errno();
} else {
$msg = mysqli_error(self::$_connection['id']);
$errornum = mysqli_errno(self::$_connection['id']);
}
/**
* After a query execution has failed this delegate will provide the query,
* query hash, error message and the error number.
*
* Note that this function only starts logging once the `ExtensionManager`
* is available, which means it will not fire for the first couple of
* queries that set the character set.
*
* @since Symphony 2.3
* @delegate QueryExecutionError
* @param string $context
* '/frontend/' or '/backend/'
* @param string $query
* The query that has just been executed
* @param string $query_hash
* The hash used by Symphony to uniquely identify this query
* @param string $msg
* The error message provided by MySQL which includes information on why the execution failed
* @param integer $num
* The error number that corresponds with the MySQL error message
*/
if (self::$_logging === true) {
if (Symphony::ExtensionManager() instanceof ExtensionManager) {
Symphony::ExtensionManager()->notifyMembers('QueryExecutionError', class_exists('Administration', false) ? '/backend/' : '/frontend/', array(
'query' => $this->_lastQuery,
'query_hash' => $this->_lastQueryHash,
'msg' => $msg,
'num' => $errornum
));
}
}
throw new DatabaseException(__('MySQL Error (%1$s): %2$s in query: %3$s', array($errornum, $msg, $this->_lastQuery)), array(
'msg' => $msg,
'num' => $errornum,
'query' => $this->_lastQuery
));
} | php | private function __error($type = null)
{
if ($type == 'connect') {
$msg = mysqli_connect_error();
$errornum = mysqli_connect_errno();
} else {
$msg = mysqli_error(self::$_connection['id']);
$errornum = mysqli_errno(self::$_connection['id']);
}
/**
* After a query execution has failed this delegate will provide the query,
* query hash, error message and the error number.
*
* Note that this function only starts logging once the `ExtensionManager`
* is available, which means it will not fire for the first couple of
* queries that set the character set.
*
* @since Symphony 2.3
* @delegate QueryExecutionError
* @param string $context
* '/frontend/' or '/backend/'
* @param string $query
* The query that has just been executed
* @param string $query_hash
* The hash used by Symphony to uniquely identify this query
* @param string $msg
* The error message provided by MySQL which includes information on why the execution failed
* @param integer $num
* The error number that corresponds with the MySQL error message
*/
if (self::$_logging === true) {
if (Symphony::ExtensionManager() instanceof ExtensionManager) {
Symphony::ExtensionManager()->notifyMembers('QueryExecutionError', class_exists('Administration', false) ? '/backend/' : '/frontend/', array(
'query' => $this->_lastQuery,
'query_hash' => $this->_lastQueryHash,
'msg' => $msg,
'num' => $errornum
));
}
}
throw new DatabaseException(__('MySQL Error (%1$s): %2$s in query: %3$s', array($errornum, $msg, $this->_lastQuery)), array(
'msg' => $msg,
'num' => $errornum,
'query' => $this->_lastQuery
));
} | [
"private",
"function",
"__error",
"(",
"$",
"type",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"type",
"==",
"'connect'",
")",
"{",
"$",
"msg",
"=",
"mysqli_connect_error",
"(",
")",
";",
"$",
"errornum",
"=",
"mysqli_connect_errno",
"(",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"mysqli_error",
"(",
"self",
"::",
"$",
"_connection",
"[",
"'id'",
"]",
")",
";",
"$",
"errornum",
"=",
"mysqli_errno",
"(",
"self",
"::",
"$",
"_connection",
"[",
"'id'",
"]",
")",
";",
"}",
"/**\n * After a query execution has failed this delegate will provide the query,\n * query hash, error message and the error number.\n *\n * Note that this function only starts logging once the `ExtensionManager`\n * is available, which means it will not fire for the first couple of\n * queries that set the character set.\n *\n * @since Symphony 2.3\n * @delegate QueryExecutionError\n * @param string $context\n * '/frontend/' or '/backend/'\n * @param string $query\n * The query that has just been executed\n * @param string $query_hash\n * The hash used by Symphony to uniquely identify this query\n * @param string $msg\n * The error message provided by MySQL which includes information on why the execution failed\n * @param integer $num\n * The error number that corresponds with the MySQL error message\n */",
"if",
"(",
"self",
"::",
"$",
"_logging",
"===",
"true",
")",
"{",
"if",
"(",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"instanceof",
"ExtensionManager",
")",
"{",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'QueryExecutionError'",
",",
"class_exists",
"(",
"'Administration'",
",",
"false",
")",
"?",
"'/backend/'",
":",
"'/frontend/'",
",",
"array",
"(",
"'query'",
"=>",
"$",
"this",
"->",
"_lastQuery",
",",
"'query_hash'",
"=>",
"$",
"this",
"->",
"_lastQueryHash",
",",
"'msg'",
"=>",
"$",
"msg",
",",
"'num'",
"=>",
"$",
"errornum",
")",
")",
";",
"}",
"}",
"throw",
"new",
"DatabaseException",
"(",
"__",
"(",
"'MySQL Error (%1$s): %2$s in query: %3$s'",
",",
"array",
"(",
"$",
"errornum",
",",
"$",
"msg",
",",
"$",
"this",
"->",
"_lastQuery",
")",
")",
",",
"array",
"(",
"'msg'",
"=>",
"$",
"msg",
",",
"'num'",
"=>",
"$",
"errornum",
",",
"'query'",
"=>",
"$",
"this",
"->",
"_lastQuery",
")",
")",
";",
"}"
] | If an error occurs in a query, this function is called which logs
the last query and the error number and error message from MySQL
before throwing a `DatabaseException`
@uses QueryExecutionError
@throws DatabaseException
@param string $type
Accepts one parameter, 'connect', which will return the correct
error codes when the connection sequence fails | [
"If",
"an",
"error",
"occurs",
"in",
"a",
"query",
"this",
"function",
"is",
"called",
"which",
"logs",
"the",
"last",
"query",
"and",
"the",
"error",
"number",
"and",
"error",
"message",
"from",
"MySQL",
"before",
"throwing",
"a",
"DatabaseException"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L922-L969 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.debug | public function debug($type = null)
{
if (!$type) {
return self::$_log;
}
return ($type == 'error' ? self::$_log['error'] : self::$_log['query']);
} | php | public function debug($type = null)
{
if (!$type) {
return self::$_log;
}
return ($type == 'error' ? self::$_log['error'] : self::$_log['query']);
} | [
"public",
"function",
"debug",
"(",
"$",
"type",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"type",
")",
"{",
"return",
"self",
"::",
"$",
"_log",
";",
"}",
"return",
"(",
"$",
"type",
"==",
"'error'",
"?",
"self",
"::",
"$",
"_log",
"[",
"'error'",
"]",
":",
"self",
"::",
"$",
"_log",
"[",
"'query'",
"]",
")",
";",
"}"
] | Returns all the log entries by type. There are two valid types,
error and debug. If no type is given, the entire log is returned,
otherwise only log messages for that type are returned
@param null|string $type
@return array
An array of associative array's. Log entries of the error type
return the query the error occurred on and the error number and
message from MySQL. Log entries of the debug type return the
the query and the start/stop time to indicate how long it took
to run | [
"Returns",
"all",
"the",
"log",
"entries",
"by",
"type",
".",
"There",
"are",
"two",
"valid",
"types",
"error",
"and",
"debug",
".",
"If",
"no",
"type",
"is",
"given",
"the",
"entire",
"log",
"is",
"returned",
"otherwise",
"only",
"log",
"messages",
"for",
"that",
"type",
"are",
"returned"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L984-L991 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.getStatistics | public function getStatistics()
{
$query_timer = 0.0;
$slow_queries = array();
foreach (self::$_log as $key => $val) {
$query_timer += $val['execution_time'];
if ($val['execution_time'] > 0.0999) {
$slow_queries[] = $val;
}
}
return array(
'queries' => self::queryCount(),
'slow-queries' => $slow_queries,
'total-query-time' => number_format($query_timer, 4, '.', '')
);
} | php | public function getStatistics()
{
$query_timer = 0.0;
$slow_queries = array();
foreach (self::$_log as $key => $val) {
$query_timer += $val['execution_time'];
if ($val['execution_time'] > 0.0999) {
$slow_queries[] = $val;
}
}
return array(
'queries' => self::queryCount(),
'slow-queries' => $slow_queries,
'total-query-time' => number_format($query_timer, 4, '.', '')
);
} | [
"public",
"function",
"getStatistics",
"(",
")",
"{",
"$",
"query_timer",
"=",
"0.0",
";",
"$",
"slow_queries",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"self",
"::",
"$",
"_log",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"query_timer",
"+=",
"$",
"val",
"[",
"'execution_time'",
"]",
";",
"if",
"(",
"$",
"val",
"[",
"'execution_time'",
"]",
">",
"0.0999",
")",
"{",
"$",
"slow_queries",
"[",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"return",
"array",
"(",
"'queries'",
"=>",
"self",
"::",
"queryCount",
"(",
")",
",",
"'slow-queries'",
"=>",
"$",
"slow_queries",
",",
"'total-query-time'",
"=>",
"number_format",
"(",
"$",
"query_timer",
",",
"4",
",",
"'.'",
",",
"''",
")",
")",
";",
"}"
] | Returns some basic statistics from the MySQL class about the
number of queries, the time it took to query and any slow queries.
A slow query is defined as one that took longer than 0.0999 seconds
This function is used by the Profile devkit
@return array
An associative array with the number of queries, an array of slow
queries and the total query time. | [
"Returns",
"some",
"basic",
"statistics",
"from",
"the",
"MySQL",
"class",
"about",
"the",
"number",
"of",
"queries",
"the",
"time",
"it",
"took",
"to",
"query",
"and",
"any",
"slow",
"queries",
".",
"A",
"slow",
"query",
"is",
"defined",
"as",
"one",
"that",
"took",
"longer",
"than",
"0",
".",
"0999",
"seconds",
"This",
"function",
"is",
"used",
"by",
"the",
"Profile",
"devkit"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L1003-L1020 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.mysql.php | MySQL.import | public function import($sql, $force_engine = false)
{
if ($force_engine) {
// Silently attempt to change the storage engine. This prevents INNOdb errors.
$this->query('SET default_storage_engine = MYISAM');
}
$queries = preg_split('/;[\\r\\n]+/', $sql, -1, PREG_SPLIT_NO_EMPTY);
if (!is_array($queries) || empty($queries) || count($queries) <= 0) {
throw new Exception('The SQL string contains no queries.');
}
foreach ($queries as $sql) {
if (trim($sql) !== '') {
$result = $this->query($sql);
}
if (!$result) {
return false;
}
}
return true;
} | php | public function import($sql, $force_engine = false)
{
if ($force_engine) {
// Silently attempt to change the storage engine. This prevents INNOdb errors.
$this->query('SET default_storage_engine = MYISAM');
}
$queries = preg_split('/;[\\r\\n]+/', $sql, -1, PREG_SPLIT_NO_EMPTY);
if (!is_array($queries) || empty($queries) || count($queries) <= 0) {
throw new Exception('The SQL string contains no queries.');
}
foreach ($queries as $sql) {
if (trim($sql) !== '') {
$result = $this->query($sql);
}
if (!$result) {
return false;
}
}
return true;
} | [
"public",
"function",
"import",
"(",
"$",
"sql",
",",
"$",
"force_engine",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"force_engine",
")",
"{",
"// Silently attempt to change the storage engine. This prevents INNOdb errors.",
"$",
"this",
"->",
"query",
"(",
"'SET default_storage_engine = MYISAM'",
")",
";",
"}",
"$",
"queries",
"=",
"preg_split",
"(",
"'/;[\\\\r\\\\n]+/'",
",",
"$",
"sql",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"queries",
")",
"||",
"empty",
"(",
"$",
"queries",
")",
"||",
"count",
"(",
"$",
"queries",
")",
"<=",
"0",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'The SQL string contains no queries.'",
")",
";",
"}",
"foreach",
"(",
"$",
"queries",
"as",
"$",
"sql",
")",
"{",
"if",
"(",
"trim",
"(",
"$",
"sql",
")",
"!==",
"''",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"}",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Convenience function to allow you to execute multiple SQL queries at once
by providing a string with the queries delimited with a `;`
@throws DatabaseException
@throws Exception
@param string $sql
A string containing SQL queries delimited by `;`
@param boolean $force_engine
If set to true, this will set MySQL's default storage engine to MyISAM.
Defaults to false, which will use MySQL's default storage engine when
tables don't explicitly define which engine they should be created with
@return boolean
If one of the queries fails, false will be returned and no further queries
will be executed, otherwise true will be returned. | [
"Convenience",
"function",
"to",
"allow",
"you",
"to",
"execute",
"multiple",
"SQL",
"queries",
"at",
"once",
"by",
"providing",
"a",
"string",
"with",
"the",
"queries",
"delimited",
"with",
"a",
";"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.mysql.php#L1038-L1062 |
symphonycms/symphony-2 | symphony/content/class.sortable.php | Sortable.initialize | public static function initialize(HTMLPage $object, &$result, &$sort, &$order, array $params = array())
{
if (isset($_REQUEST['sort'])) {
$sort = $_REQUEST['sort'];
} else {
$sort = null;
}
if (isset($_REQUEST['order'])) {
$order = ($_REQUEST['order'] == 'desc' ? 'desc' : 'asc');
} else {
$order = null;
}
$result = $object->sort($sort, $order, $params);
} | php | public static function initialize(HTMLPage $object, &$result, &$sort, &$order, array $params = array())
{
if (isset($_REQUEST['sort'])) {
$sort = $_REQUEST['sort'];
} else {
$sort = null;
}
if (isset($_REQUEST['order'])) {
$order = ($_REQUEST['order'] == 'desc' ? 'desc' : 'asc');
} else {
$order = null;
}
$result = $object->sort($sort, $order, $params);
} | [
"public",
"static",
"function",
"initialize",
"(",
"HTMLPage",
"$",
"object",
",",
"&",
"$",
"result",
",",
"&",
"$",
"sort",
",",
"&",
"$",
"order",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_REQUEST",
"[",
"'sort'",
"]",
")",
")",
"{",
"$",
"sort",
"=",
"$",
"_REQUEST",
"[",
"'sort'",
"]",
";",
"}",
"else",
"{",
"$",
"sort",
"=",
"null",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_REQUEST",
"[",
"'order'",
"]",
")",
")",
"{",
"$",
"order",
"=",
"(",
"$",
"_REQUEST",
"[",
"'order'",
"]",
"==",
"'desc'",
"?",
"'desc'",
":",
"'asc'",
")",
";",
"}",
"else",
"{",
"$",
"order",
"=",
"null",
";",
"}",
"$",
"result",
"=",
"$",
"object",
"->",
"sort",
"(",
"$",
"sort",
",",
"$",
"order",
",",
"$",
"params",
")",
";",
"}"
] | This method initializes the `$result`, `$sort` and `$order` variables by using the
`$_REQUEST` array. The `$result` is passed by reference, and is return of calling the
`$object->sort()` method. It is this method that actually invokes the sorting inside
the `$object`.
@param HTMLPage $object
The object responsible for sorting the items. It must implement a `sort()` method.
@param array $result
This variable stores an array sorted objects. Once set, its value is available
to the client class of Sortable.
@param string $sort
This variable stores the field (or axis) the objects are sorted by. Once set,
its value is available to the client class of `Sortable`.
@param string $order
This variable stores the sort order (i.e. 'asc' or 'desc'). Once set, its value
is available to the client class of Sortable.
@param array $params (optional)
An array of parameters that can be passed to the context-based method. | [
"This",
"method",
"initializes",
"the",
"$result",
"$sort",
"and",
"$order",
"variables",
"by",
"using",
"the",
"$_REQUEST",
"array",
".",
"The",
"$result",
"is",
"passed",
"by",
"reference",
"and",
"is",
"return",
"of",
"calling",
"the",
"$object",
"-",
">",
"sort",
"()",
"method",
".",
"It",
"is",
"this",
"method",
"that",
"actually",
"invokes",
"the",
"sorting",
"inside",
"the",
"$object",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/content/class.sortable.php#L40-L55 |
symphonycms/symphony-2 | symphony/content/class.sortable.php | Sortable.buildTableHeaders | public static function buildTableHeaders($columns, $sort, $order, $extra_url_params = null)
{
$aTableHead = array();
foreach ($columns as $c) {
if ($c['sortable']) {
$label = new XMLElement('span', $c['label']);
$label = $label->generate();
if ($c['handle'] == $sort) {
$link = sprintf(
'?sort=%s&order=%s%s',
$c['handle'],
($order == 'desc' ? 'asc' : 'desc'),
$extra_url_params
);
$th = Widget::Anchor(
$label,
$link,
__('Sort by %1$s %2$s', array(($order == 'desc' ? __('ascending') : __('descending')), strtolower($c['label']))),
'active'
);
} else {
$link = sprintf(
'?sort=%s&order=asc%s',
$c['handle'],
$extra_url_params
);
$th = Widget::Anchor(
$label,
$link,
__('Sort by %1$s %2$s', array(__('ascending'), strtolower($c['label'])))
);
}
} else {
$th = $c['label'];
}
$aTableHead[] = array($th, 'col', isset($c['attrs']) ? $c['attrs'] : null);
}
return $aTableHead;
} | php | public static function buildTableHeaders($columns, $sort, $order, $extra_url_params = null)
{
$aTableHead = array();
foreach ($columns as $c) {
if ($c['sortable']) {
$label = new XMLElement('span', $c['label']);
$label = $label->generate();
if ($c['handle'] == $sort) {
$link = sprintf(
'?sort=%s&order=%s%s',
$c['handle'],
($order == 'desc' ? 'asc' : 'desc'),
$extra_url_params
);
$th = Widget::Anchor(
$label,
$link,
__('Sort by %1$s %2$s', array(($order == 'desc' ? __('ascending') : __('descending')), strtolower($c['label']))),
'active'
);
} else {
$link = sprintf(
'?sort=%s&order=asc%s',
$c['handle'],
$extra_url_params
);
$th = Widget::Anchor(
$label,
$link,
__('Sort by %1$s %2$s', array(__('ascending'), strtolower($c['label'])))
);
}
} else {
$th = $c['label'];
}
$aTableHead[] = array($th, 'col', isset($c['attrs']) ? $c['attrs'] : null);
}
return $aTableHead;
} | [
"public",
"static",
"function",
"buildTableHeaders",
"(",
"$",
"columns",
",",
"$",
"sort",
",",
"$",
"order",
",",
"$",
"extra_url_params",
"=",
"null",
")",
"{",
"$",
"aTableHead",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"c",
")",
"{",
"if",
"(",
"$",
"c",
"[",
"'sortable'",
"]",
")",
"{",
"$",
"label",
"=",
"new",
"XMLElement",
"(",
"'span'",
",",
"$",
"c",
"[",
"'label'",
"]",
")",
";",
"$",
"label",
"=",
"$",
"label",
"->",
"generate",
"(",
")",
";",
"if",
"(",
"$",
"c",
"[",
"'handle'",
"]",
"==",
"$",
"sort",
")",
"{",
"$",
"link",
"=",
"sprintf",
"(",
"'?sort=%s&order=%s%s'",
",",
"$",
"c",
"[",
"'handle'",
"]",
",",
"(",
"$",
"order",
"==",
"'desc'",
"?",
"'asc'",
":",
"'desc'",
")",
",",
"$",
"extra_url_params",
")",
";",
"$",
"th",
"=",
"Widget",
"::",
"Anchor",
"(",
"$",
"label",
",",
"$",
"link",
",",
"__",
"(",
"'Sort by %1$s %2$s'",
",",
"array",
"(",
"(",
"$",
"order",
"==",
"'desc'",
"?",
"__",
"(",
"'ascending'",
")",
":",
"__",
"(",
"'descending'",
")",
")",
",",
"strtolower",
"(",
"$",
"c",
"[",
"'label'",
"]",
")",
")",
")",
",",
"'active'",
")",
";",
"}",
"else",
"{",
"$",
"link",
"=",
"sprintf",
"(",
"'?sort=%s&order=asc%s'",
",",
"$",
"c",
"[",
"'handle'",
"]",
",",
"$",
"extra_url_params",
")",
";",
"$",
"th",
"=",
"Widget",
"::",
"Anchor",
"(",
"$",
"label",
",",
"$",
"link",
",",
"__",
"(",
"'Sort by %1$s %2$s'",
",",
"array",
"(",
"__",
"(",
"'ascending'",
")",
",",
"strtolower",
"(",
"$",
"c",
"[",
"'label'",
"]",
")",
")",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"th",
"=",
"$",
"c",
"[",
"'label'",
"]",
";",
"}",
"$",
"aTableHead",
"[",
"]",
"=",
"array",
"(",
"$",
"th",
",",
"'col'",
",",
"isset",
"(",
"$",
"c",
"[",
"'attrs'",
"]",
")",
"?",
"$",
"c",
"[",
"'attrs'",
"]",
":",
"null",
")",
";",
"}",
"return",
"$",
"aTableHead",
";",
"}"
] | This method builds the markup for sorting-aware table headers. It accepts an
`$columns` array, as well as the current sorting axis `$sort` and the
current sort order, `$order`. If `$extra_url_params` are provided, they are
appended to the redirect string upon clicking on a table header.
'label' => 'Column label',
'sortable' => (true|false),
'handle' => 'handle for the column (i.e. the field ID), used as value for $sort',
'attrs' => array(
'HTML <a> attribute' => 'value',
[...]
)
@param array $columns
An array of columns that will be converted into table headers.
@param string $sort
The current field (or axis) the objects are sorted by.
@param string $order
The current sort order (i.e. 'asc' or 'desc').
@param string $extra_url_params (optional)
A string of URL parameters that will be appended to the redirect string.
@throws InvalidArgumentException
@return array
An array of table headers that can be directly passed to `Widget::TableHead`. | [
"This",
"method",
"builds",
"the",
"markup",
"for",
"sorting",
"-",
"aware",
"table",
"headers",
".",
"It",
"accepts",
"an",
"$columns",
"array",
"as",
"well",
"as",
"the",
"current",
"sorting",
"axis",
"$sort",
"and",
"the",
"current",
"sort",
"order",
"$order",
".",
"If",
"$extra_url_params",
"are",
"provided",
"they",
"are",
"appended",
"to",
"the",
"redirect",
"string",
"upon",
"clicking",
"on",
"a",
"table",
"header",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/content/class.sortable.php#L83-L125 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.select.php | FieldSelect.findAndAddDynamicOptions | public function findAndAddDynamicOptions(&$values)
{
if (!is_array($values)) {
$values = array();
}
$results = false;
// Fixes #1802
if (!Symphony::Database()->tableExists('tbl_entries_data_' . $this->get('dynamic_options'))) {
return;
}
// Ensure that the table has a 'value' column
if ((boolean)Symphony::Database()->fetchVar('Field', 0, sprintf(
"SHOW COLUMNS FROM `tbl_entries_data_%d` LIKE '%s'",
$this->get('dynamic_options'),
'value'
))) {
$results = Symphony::Database()->fetchCol('value', sprintf(
"SELECT DISTINCT `value`
FROM `tbl_entries_data_%d`
ORDER BY `value` ASC",
$this->get('dynamic_options')
));
}
// In the case of a Upload field, use 'file' instead of 'value'
if (($results == false) && (boolean)Symphony::Database()->fetchVar('Field', 0, sprintf(
"SHOW COLUMNS FROM `tbl_entries_data_%d` LIKE '%s'",
$this->get('dynamic_options'),
'file'
))) {
$results = Symphony::Database()->fetchCol('file', sprintf(
"SELECT DISTINCT `file`
FROM `tbl_entries_data_%d`
ORDER BY `file` ASC",
$this->get('dynamic_options')
));
}
if ($results) {
if ($this->get('sort_options') == 'no') {
natsort($results);
}
$values = array_merge($values, $results);
}
} | php | public function findAndAddDynamicOptions(&$values)
{
if (!is_array($values)) {
$values = array();
}
$results = false;
// Fixes #1802
if (!Symphony::Database()->tableExists('tbl_entries_data_' . $this->get('dynamic_options'))) {
return;
}
// Ensure that the table has a 'value' column
if ((boolean)Symphony::Database()->fetchVar('Field', 0, sprintf(
"SHOW COLUMNS FROM `tbl_entries_data_%d` LIKE '%s'",
$this->get('dynamic_options'),
'value'
))) {
$results = Symphony::Database()->fetchCol('value', sprintf(
"SELECT DISTINCT `value`
FROM `tbl_entries_data_%d`
ORDER BY `value` ASC",
$this->get('dynamic_options')
));
}
// In the case of a Upload field, use 'file' instead of 'value'
if (($results == false) && (boolean)Symphony::Database()->fetchVar('Field', 0, sprintf(
"SHOW COLUMNS FROM `tbl_entries_data_%d` LIKE '%s'",
$this->get('dynamic_options'),
'file'
))) {
$results = Symphony::Database()->fetchCol('file', sprintf(
"SELECT DISTINCT `file`
FROM `tbl_entries_data_%d`
ORDER BY `file` ASC",
$this->get('dynamic_options')
));
}
if ($results) {
if ($this->get('sort_options') == 'no') {
natsort($results);
}
$values = array_merge($values, $results);
}
} | [
"public",
"function",
"findAndAddDynamicOptions",
"(",
"&",
"$",
"values",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"values",
")",
")",
"{",
"$",
"values",
"=",
"array",
"(",
")",
";",
"}",
"$",
"results",
"=",
"false",
";",
"// Fixes #1802",
"if",
"(",
"!",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"tableExists",
"(",
"'tbl_entries_data_'",
".",
"$",
"this",
"->",
"get",
"(",
"'dynamic_options'",
")",
")",
")",
"{",
"return",
";",
"}",
"// Ensure that the table has a 'value' column",
"if",
"(",
"(",
"boolean",
")",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchVar",
"(",
"'Field'",
",",
"0",
",",
"sprintf",
"(",
"\"SHOW COLUMNS FROM `tbl_entries_data_%d` LIKE '%s'\"",
",",
"$",
"this",
"->",
"get",
"(",
"'dynamic_options'",
")",
",",
"'value'",
")",
")",
")",
"{",
"$",
"results",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchCol",
"(",
"'value'",
",",
"sprintf",
"(",
"\"SELECT DISTINCT `value`\n FROM `tbl_entries_data_%d`\n ORDER BY `value` ASC\"",
",",
"$",
"this",
"->",
"get",
"(",
"'dynamic_options'",
")",
")",
")",
";",
"}",
"// In the case of a Upload field, use 'file' instead of 'value'",
"if",
"(",
"(",
"$",
"results",
"==",
"false",
")",
"&&",
"(",
"boolean",
")",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchVar",
"(",
"'Field'",
",",
"0",
",",
"sprintf",
"(",
"\"SHOW COLUMNS FROM `tbl_entries_data_%d` LIKE '%s'\"",
",",
"$",
"this",
"->",
"get",
"(",
"'dynamic_options'",
")",
",",
"'file'",
")",
")",
")",
"{",
"$",
"results",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchCol",
"(",
"'file'",
",",
"sprintf",
"(",
"\"SELECT DISTINCT `file`\n FROM `tbl_entries_data_%d`\n ORDER BY `file` ASC\"",
",",
"$",
"this",
"->",
"get",
"(",
"'dynamic_options'",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"results",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'sort_options'",
")",
"==",
"'no'",
")",
"{",
"natsort",
"(",
"$",
"results",
")",
";",
"}",
"$",
"values",
"=",
"array_merge",
"(",
"$",
"values",
",",
"$",
"results",
")",
";",
"}",
"}"
] | /*-------------------------------------------------------------------------
Utilities:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Utilities",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.select.php#L127-L175 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.select.php | FieldSelect.findDefaults | public function findDefaults(array &$settings)
{
if (!isset($settings['allow_multiple_selection'])) {
$settings['allow_multiple_selection'] = 'no';
}
if (!isset($settings['show_association'])) {
$settings['show_association'] = 'no';
}
if (!isset($settings['sort_options'])) {
$settings['sort_options'] = 'no';
}
} | php | public function findDefaults(array &$settings)
{
if (!isset($settings['allow_multiple_selection'])) {
$settings['allow_multiple_selection'] = 'no';
}
if (!isset($settings['show_association'])) {
$settings['show_association'] = 'no';
}
if (!isset($settings['sort_options'])) {
$settings['sort_options'] = 'no';
}
} | [
"public",
"function",
"findDefaults",
"(",
"array",
"&",
"$",
"settings",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"settings",
"[",
"'allow_multiple_selection'",
"]",
")",
")",
"{",
"$",
"settings",
"[",
"'allow_multiple_selection'",
"]",
"=",
"'no'",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"settings",
"[",
"'show_association'",
"]",
")",
")",
"{",
"$",
"settings",
"[",
"'show_association'",
"]",
"=",
"'no'",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"settings",
"[",
"'sort_options'",
"]",
")",
")",
"{",
"$",
"settings",
"[",
"'sort_options'",
"]",
"=",
"'no'",
";",
"}",
"}"
] | /*-------------------------------------------------------------------------
Settings:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Settings",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.select.php#L181-L194 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.select.php | FieldSelect.displayPublishPanel | public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null)
{
$states = $this->getToggleStates();
$value = isset($data['value']) ? $data['value'] : null;
if (!is_array($value)) {
$value = array($value);
}
$options = array();
if ($this->get('required') !== 'yes') {
$options[] = array(null, false, null);
}
foreach ($states as $handle => $v) {
$options[] = array(General::sanitize($v), in_array($v, $value), General::sanitize($v));
}
$fieldname = 'fields'.$fieldnamePrefix.'['.$this->get('element_name').']'.$fieldnamePostfix;
if ($this->get('allow_multiple_selection') === 'yes') {
$fieldname .= '[]';
}
$label = Widget::Label($this->get('label'));
if ($this->get('required') !== 'yes') {
$label->appendChild(new XMLElement('i', __('Optional')));
}
$label->appendChild(Widget::Select($fieldname, $options, ($this->get('allow_multiple_selection') === 'yes' ? array('multiple' => 'multiple', 'size' => count($options)) : null)));
if ($flagWithError != null) {
$wrapper->appendChild(Widget::Error($label, $flagWithError));
} else {
$wrapper->appendChild($label);
}
} | php | public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null)
{
$states = $this->getToggleStates();
$value = isset($data['value']) ? $data['value'] : null;
if (!is_array($value)) {
$value = array($value);
}
$options = array();
if ($this->get('required') !== 'yes') {
$options[] = array(null, false, null);
}
foreach ($states as $handle => $v) {
$options[] = array(General::sanitize($v), in_array($v, $value), General::sanitize($v));
}
$fieldname = 'fields'.$fieldnamePrefix.'['.$this->get('element_name').']'.$fieldnamePostfix;
if ($this->get('allow_multiple_selection') === 'yes') {
$fieldname .= '[]';
}
$label = Widget::Label($this->get('label'));
if ($this->get('required') !== 'yes') {
$label->appendChild(new XMLElement('i', __('Optional')));
}
$label->appendChild(Widget::Select($fieldname, $options, ($this->get('allow_multiple_selection') === 'yes' ? array('multiple' => 'multiple', 'size' => count($options)) : null)));
if ($flagWithError != null) {
$wrapper->appendChild(Widget::Error($label, $flagWithError));
} else {
$wrapper->appendChild($label);
}
} | [
"public",
"function",
"displayPublishPanel",
"(",
"XMLElement",
"&",
"$",
"wrapper",
",",
"$",
"data",
"=",
"null",
",",
"$",
"flagWithError",
"=",
"null",
",",
"$",
"fieldnamePrefix",
"=",
"null",
",",
"$",
"fieldnamePostfix",
"=",
"null",
",",
"$",
"entry_id",
"=",
"null",
")",
"{",
"$",
"states",
"=",
"$",
"this",
"->",
"getToggleStates",
"(",
")",
";",
"$",
"value",
"=",
"isset",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
"?",
"$",
"data",
"[",
"'value'",
"]",
":",
"null",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"array",
"(",
"$",
"value",
")",
";",
"}",
"$",
"options",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'required'",
")",
"!==",
"'yes'",
")",
"{",
"$",
"options",
"[",
"]",
"=",
"array",
"(",
"null",
",",
"false",
",",
"null",
")",
";",
"}",
"foreach",
"(",
"$",
"states",
"as",
"$",
"handle",
"=>",
"$",
"v",
")",
"{",
"$",
"options",
"[",
"]",
"=",
"array",
"(",
"General",
"::",
"sanitize",
"(",
"$",
"v",
")",
",",
"in_array",
"(",
"$",
"v",
",",
"$",
"value",
")",
",",
"General",
"::",
"sanitize",
"(",
"$",
"v",
")",
")",
";",
"}",
"$",
"fieldname",
"=",
"'fields'",
".",
"$",
"fieldnamePrefix",
".",
"'['",
".",
"$",
"this",
"->",
"get",
"(",
"'element_name'",
")",
".",
"']'",
".",
"$",
"fieldnamePostfix",
";",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'allow_multiple_selection'",
")",
"===",
"'yes'",
")",
"{",
"$",
"fieldname",
".=",
"'[]'",
";",
"}",
"$",
"label",
"=",
"Widget",
"::",
"Label",
"(",
"$",
"this",
"->",
"get",
"(",
"'label'",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'required'",
")",
"!==",
"'yes'",
")",
"{",
"$",
"label",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'i'",
",",
"__",
"(",
"'Optional'",
")",
")",
")",
";",
"}",
"$",
"label",
"->",
"appendChild",
"(",
"Widget",
"::",
"Select",
"(",
"$",
"fieldname",
",",
"$",
"options",
",",
"(",
"$",
"this",
"->",
"get",
"(",
"'allow_multiple_selection'",
")",
"===",
"'yes'",
"?",
"array",
"(",
"'multiple'",
"=>",
"'multiple'",
",",
"'size'",
"=>",
"count",
"(",
"$",
"options",
")",
")",
":",
"null",
")",
")",
")",
";",
"if",
"(",
"$",
"flagWithError",
"!=",
"null",
")",
"{",
"$",
"wrapper",
"->",
"appendChild",
"(",
"Widget",
"::",
"Error",
"(",
"$",
"label",
",",
"$",
"flagWithError",
")",
")",
";",
"}",
"else",
"{",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"label",
")",
";",
"}",
"}"
] | /*-------------------------------------------------------------------------
Publish:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Publish",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.select.php#L317-L354 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.select.php | FieldSelect.prepareImportValue | public function prepareImportValue($data, $mode, $entry_id = null)
{
$message = $status = null;
$modes = (object)$this->getImportModes();
if (!is_array($data)) {
$data = array($data);
}
if ($mode === $modes->getValue) {
if ($this->get('allow_multiple_selection') === 'no') {
$data = array(implode('', $data));
}
return $data;
} elseif ($mode === $modes->getPostdata) {
return $this->processRawFieldData($data, $status, $message, true, $entry_id);
}
return null;
} | php | public function prepareImportValue($data, $mode, $entry_id = null)
{
$message = $status = null;
$modes = (object)$this->getImportModes();
if (!is_array($data)) {
$data = array($data);
}
if ($mode === $modes->getValue) {
if ($this->get('allow_multiple_selection') === 'no') {
$data = array(implode('', $data));
}
return $data;
} elseif ($mode === $modes->getPostdata) {
return $this->processRawFieldData($data, $status, $message, true, $entry_id);
}
return null;
} | [
"public",
"function",
"prepareImportValue",
"(",
"$",
"data",
",",
"$",
"mode",
",",
"$",
"entry_id",
"=",
"null",
")",
"{",
"$",
"message",
"=",
"$",
"status",
"=",
"null",
";",
"$",
"modes",
"=",
"(",
"object",
")",
"$",
"this",
"->",
"getImportModes",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"array",
"(",
"$",
"data",
")",
";",
"}",
"if",
"(",
"$",
"mode",
"===",
"$",
"modes",
"->",
"getValue",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'allow_multiple_selection'",
")",
"===",
"'no'",
")",
"{",
"$",
"data",
"=",
"array",
"(",
"implode",
"(",
"''",
",",
"$",
"data",
")",
")",
";",
"}",
"return",
"$",
"data",
";",
"}",
"elseif",
"(",
"$",
"mode",
"===",
"$",
"modes",
"->",
"getPostdata",
")",
"{",
"return",
"$",
"this",
"->",
"processRawFieldData",
"(",
"$",
"data",
",",
"$",
"status",
",",
"$",
"message",
",",
"true",
",",
"$",
"entry_id",
")",
";",
"}",
"return",
"null",
";",
"}"
] | /*-------------------------------------------------------------------------
Import:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Import",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.select.php#L404-L424 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.select.php | FieldSelect.getExportModes | public function getExportModes()
{
return array(
'listHandle' => ExportableField::LIST_OF
+ ExportableField::HANDLE,
'listValue' => ExportableField::LIST_OF
+ ExportableField::VALUE,
'listHandleToValue' => ExportableField::LIST_OF
+ ExportableField::HANDLE
+ ExportableField::VALUE,
'getPostdata' => ExportableField::POSTDATA
);
} | php | public function getExportModes()
{
return array(
'listHandle' => ExportableField::LIST_OF
+ ExportableField::HANDLE,
'listValue' => ExportableField::LIST_OF
+ ExportableField::VALUE,
'listHandleToValue' => ExportableField::LIST_OF
+ ExportableField::HANDLE
+ ExportableField::VALUE,
'getPostdata' => ExportableField::POSTDATA
);
} | [
"public",
"function",
"getExportModes",
"(",
")",
"{",
"return",
"array",
"(",
"'listHandle'",
"=>",
"ExportableField",
"::",
"LIST_OF",
"+",
"ExportableField",
"::",
"HANDLE",
",",
"'listValue'",
"=>",
"ExportableField",
"::",
"LIST_OF",
"+",
"ExportableField",
"::",
"VALUE",
",",
"'listHandleToValue'",
"=>",
"ExportableField",
"::",
"LIST_OF",
"+",
"ExportableField",
"::",
"HANDLE",
"+",
"ExportableField",
"::",
"VALUE",
",",
"'getPostdata'",
"=>",
"ExportableField",
"::",
"POSTDATA",
")",
";",
"}"
] | Return a list of supported export modes for use with `prepareExportValue`.
@return array | [
"Return",
"a",
"list",
"of",
"supported",
"export",
"modes",
"for",
"use",
"with",
"prepareExportValue",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.select.php#L435-L447 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.select.php | FieldSelect.displayFilteringOptions | public function displayFilteringOptions(XMLElement &$wrapper)
{
$existing_options = $this->getToggleStates();
if (is_array($existing_options) && !empty($existing_options)) {
$optionlist = new XMLElement('ul');
$optionlist->setAttribute('class', 'tags');
$optionlist->setAttribute('data-interactive', 'data-interactive');
foreach ($existing_options as $option) {
$optionlist->appendChild(
new XMLElement('li', General::sanitize($option))
);
};
$wrapper->appendChild($optionlist);
}
} | php | public function displayFilteringOptions(XMLElement &$wrapper)
{
$existing_options = $this->getToggleStates();
if (is_array($existing_options) && !empty($existing_options)) {
$optionlist = new XMLElement('ul');
$optionlist->setAttribute('class', 'tags');
$optionlist->setAttribute('data-interactive', 'data-interactive');
foreach ($existing_options as $option) {
$optionlist->appendChild(
new XMLElement('li', General::sanitize($option))
);
};
$wrapper->appendChild($optionlist);
}
} | [
"public",
"function",
"displayFilteringOptions",
"(",
"XMLElement",
"&",
"$",
"wrapper",
")",
"{",
"$",
"existing_options",
"=",
"$",
"this",
"->",
"getToggleStates",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"existing_options",
")",
"&&",
"!",
"empty",
"(",
"$",
"existing_options",
")",
")",
"{",
"$",
"optionlist",
"=",
"new",
"XMLElement",
"(",
"'ul'",
")",
";",
"$",
"optionlist",
"->",
"setAttribute",
"(",
"'class'",
",",
"'tags'",
")",
";",
"$",
"optionlist",
"->",
"setAttribute",
"(",
"'data-interactive'",
",",
"'data-interactive'",
")",
";",
"foreach",
"(",
"$",
"existing_options",
"as",
"$",
"option",
")",
"{",
"$",
"optionlist",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'li'",
",",
"General",
"::",
"sanitize",
"(",
"$",
"option",
")",
")",
")",
";",
"}",
";",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"optionlist",
")",
";",
"}",
"}"
] | /*-------------------------------------------------------------------------
Filtering:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Filtering",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.select.php#L498-L515 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.select.php | FieldSelect.groupRecords | public function groupRecords($records)
{
if (!is_array($records) || empty($records)) {
return;
}
$groups = array($this->get('element_name') => array());
foreach ($records as $r) {
$data = $r->getData($this->get('id'));
$value = General::sanitize($data['value']);
if (!isset($groups[$this->get('element_name')][$data['handle']])) {
$groups[$this->get('element_name')][$data['handle']] = array(
'attr' => array('handle' => $data['handle'], 'value' => $value),
'records' => array(),
'groups' => array()
);
}
$groups[$this->get('element_name')][$data['handle']]['records'][] = $r;
}
return $groups;
} | php | public function groupRecords($records)
{
if (!is_array($records) || empty($records)) {
return;
}
$groups = array($this->get('element_name') => array());
foreach ($records as $r) {
$data = $r->getData($this->get('id'));
$value = General::sanitize($data['value']);
if (!isset($groups[$this->get('element_name')][$data['handle']])) {
$groups[$this->get('element_name')][$data['handle']] = array(
'attr' => array('handle' => $data['handle'], 'value' => $value),
'records' => array(),
'groups' => array()
);
}
$groups[$this->get('element_name')][$data['handle']]['records'][] = $r;
}
return $groups;
} | [
"public",
"function",
"groupRecords",
"(",
"$",
"records",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"records",
")",
"||",
"empty",
"(",
"$",
"records",
")",
")",
"{",
"return",
";",
"}",
"$",
"groups",
"=",
"array",
"(",
"$",
"this",
"->",
"get",
"(",
"'element_name'",
")",
"=>",
"array",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"r",
")",
"{",
"$",
"data",
"=",
"$",
"r",
"->",
"getData",
"(",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"$",
"value",
"=",
"General",
"::",
"sanitize",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"groups",
"[",
"$",
"this",
"->",
"get",
"(",
"'element_name'",
")",
"]",
"[",
"$",
"data",
"[",
"'handle'",
"]",
"]",
")",
")",
"{",
"$",
"groups",
"[",
"$",
"this",
"->",
"get",
"(",
"'element_name'",
")",
"]",
"[",
"$",
"data",
"[",
"'handle'",
"]",
"]",
"=",
"array",
"(",
"'attr'",
"=>",
"array",
"(",
"'handle'",
"=>",
"$",
"data",
"[",
"'handle'",
"]",
",",
"'value'",
"=>",
"$",
"value",
")",
",",
"'records'",
"=>",
"array",
"(",
")",
",",
"'groups'",
"=>",
"array",
"(",
")",
")",
";",
"}",
"$",
"groups",
"[",
"$",
"this",
"->",
"get",
"(",
"'element_name'",
")",
"]",
"[",
"$",
"data",
"[",
"'handle'",
"]",
"]",
"[",
"'records'",
"]",
"[",
"]",
"=",
"$",
"r",
";",
"}",
"return",
"$",
"groups",
";",
"}"
] | /*-------------------------------------------------------------------------
Grouping:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Grouping",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.select.php#L521-L545 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.select.php | FieldSelect.getExampleFormMarkup | public function getExampleFormMarkup()
{
$states = $this->getToggleStates();
$options = array();
foreach ($states as $handle => $v) {
$options[] = array($v, null, $v);
}
$fieldname = 'fields['.$this->get('element_name').']';
if ($this->get('allow_multiple_selection') === 'yes') {
$fieldname .= '[]';
}
$label = Widget::Label($this->get('label'));
$label->appendChild(Widget::Select($fieldname, $options, ($this->get('allow_multiple_selection') === 'yes' ? array('multiple' => 'multiple') : null)));
return $label;
} | php | public function getExampleFormMarkup()
{
$states = $this->getToggleStates();
$options = array();
foreach ($states as $handle => $v) {
$options[] = array($v, null, $v);
}
$fieldname = 'fields['.$this->get('element_name').']';
if ($this->get('allow_multiple_selection') === 'yes') {
$fieldname .= '[]';
}
$label = Widget::Label($this->get('label'));
$label->appendChild(Widget::Select($fieldname, $options, ($this->get('allow_multiple_selection') === 'yes' ? array('multiple' => 'multiple') : null)));
return $label;
} | [
"public",
"function",
"getExampleFormMarkup",
"(",
")",
"{",
"$",
"states",
"=",
"$",
"this",
"->",
"getToggleStates",
"(",
")",
";",
"$",
"options",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"states",
"as",
"$",
"handle",
"=>",
"$",
"v",
")",
"{",
"$",
"options",
"[",
"]",
"=",
"array",
"(",
"$",
"v",
",",
"null",
",",
"$",
"v",
")",
";",
"}",
"$",
"fieldname",
"=",
"'fields['",
".",
"$",
"this",
"->",
"get",
"(",
"'element_name'",
")",
".",
"']'",
";",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'allow_multiple_selection'",
")",
"===",
"'yes'",
")",
"{",
"$",
"fieldname",
".=",
"'[]'",
";",
"}",
"$",
"label",
"=",
"Widget",
"::",
"Label",
"(",
"$",
"this",
"->",
"get",
"(",
"'label'",
")",
")",
";",
"$",
"label",
"->",
"appendChild",
"(",
"Widget",
"::",
"Select",
"(",
"$",
"fieldname",
",",
"$",
"options",
",",
"(",
"$",
"this",
"->",
"get",
"(",
"'allow_multiple_selection'",
")",
"===",
"'yes'",
"?",
"array",
"(",
"'multiple'",
"=>",
"'multiple'",
")",
":",
"null",
")",
")",
")",
";",
"return",
"$",
"label",
";",
"}"
] | /*-------------------------------------------------------------------------
Events:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Events",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.select.php#L551-L571 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.event.php | Event.getNotificationTemplate | public static function getNotificationTemplate($language)
{
$langformat = '%s/email.entrycreated.%s.tpl';
$defaultformat = '%s/email.entrycreated.tpl';
if (file_exists($template = sprintf($langformat, WORKSPACE . '/template', $language))) {
return $template;
} elseif (file_exists($template = sprintf($defaultformat, WORKSPACE . '/template'))) {
return $template;
} elseif (file_exists($template = sprintf($langformat, TEMPLATE, $language))) {
return $template;
} elseif (file_exists($template = sprintf($defaultformat, TEMPLATE))) {
return $template;
} else {
return false;
}
} | php | public static function getNotificationTemplate($language)
{
$langformat = '%s/email.entrycreated.%s.tpl';
$defaultformat = '%s/email.entrycreated.tpl';
if (file_exists($template = sprintf($langformat, WORKSPACE . '/template', $language))) {
return $template;
} elseif (file_exists($template = sprintf($defaultformat, WORKSPACE . '/template'))) {
return $template;
} elseif (file_exists($template = sprintf($langformat, TEMPLATE, $language))) {
return $template;
} elseif (file_exists($template = sprintf($defaultformat, TEMPLATE))) {
return $template;
} else {
return false;
}
} | [
"public",
"static",
"function",
"getNotificationTemplate",
"(",
"$",
"language",
")",
"{",
"$",
"langformat",
"=",
"'%s/email.entrycreated.%s.tpl'",
";",
"$",
"defaultformat",
"=",
"'%s/email.entrycreated.tpl'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"template",
"=",
"sprintf",
"(",
"$",
"langformat",
",",
"WORKSPACE",
".",
"'/template'",
",",
"$",
"language",
")",
")",
")",
"{",
"return",
"$",
"template",
";",
"}",
"elseif",
"(",
"file_exists",
"(",
"$",
"template",
"=",
"sprintf",
"(",
"$",
"defaultformat",
",",
"WORKSPACE",
".",
"'/template'",
")",
")",
")",
"{",
"return",
"$",
"template",
";",
"}",
"elseif",
"(",
"file_exists",
"(",
"$",
"template",
"=",
"sprintf",
"(",
"$",
"langformat",
",",
"TEMPLATE",
",",
"$",
"language",
")",
")",
")",
"{",
"return",
"$",
"template",
";",
"}",
"elseif",
"(",
"file_exists",
"(",
"$",
"template",
"=",
"sprintf",
"(",
"$",
"defaultformat",
",",
"TEMPLATE",
")",
")",
")",
"{",
"return",
"$",
"template",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Returns the path to the email-notification-template by looking at the
`WORKSPACE/template/` directory, then at the `TEMPLATES`
directory for the convention `notification.*.tpl`. If the template
is not found, false is returned
@param string $language
Language used in system
@return mixed
String, which is the path to the template if the template is found,
false otherwise | [
"Returns",
"the",
"path",
"to",
"the",
"email",
"-",
"notification",
"-",
"template",
"by",
"looking",
"at",
"the",
"WORKSPACE",
"/",
"template",
"/",
"directory",
"then",
"at",
"the",
"TEMPLATES",
"directory",
"for",
"the",
"convention",
"notification",
".",
"*",
".",
"tpl",
".",
"If",
"the",
"template",
"is",
"not",
"found",
"false",
"is",
"returned"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.event.php#L109-L125 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.sectionmanager.php | SectionManager.add | public static function add(array $settings)
{
$defaults = array();
$defaults['creation_date'] = $defaults['modification_date'] = DateTimeObj::get('Y-m-d H:i:s');
$defaults['creation_date_gmt'] = $defaults['modification_date_gmt'] = DateTimeObj::getGMT('Y-m-d H:i:s');
$defaults['author_id'] = 1;
$defaults['modification_author_id'] = 1;
$settings = array_replace($defaults, $settings);
if (!Symphony::Database()->insert($settings, 'tbl_sections')) {
return false;
}
return Symphony::Database()->getInsertID();
} | php | public static function add(array $settings)
{
$defaults = array();
$defaults['creation_date'] = $defaults['modification_date'] = DateTimeObj::get('Y-m-d H:i:s');
$defaults['creation_date_gmt'] = $defaults['modification_date_gmt'] = DateTimeObj::getGMT('Y-m-d H:i:s');
$defaults['author_id'] = 1;
$defaults['modification_author_id'] = 1;
$settings = array_replace($defaults, $settings);
if (!Symphony::Database()->insert($settings, 'tbl_sections')) {
return false;
}
return Symphony::Database()->getInsertID();
} | [
"public",
"static",
"function",
"add",
"(",
"array",
"$",
"settings",
")",
"{",
"$",
"defaults",
"=",
"array",
"(",
")",
";",
"$",
"defaults",
"[",
"'creation_date'",
"]",
"=",
"$",
"defaults",
"[",
"'modification_date'",
"]",
"=",
"DateTimeObj",
"::",
"get",
"(",
"'Y-m-d H:i:s'",
")",
";",
"$",
"defaults",
"[",
"'creation_date_gmt'",
"]",
"=",
"$",
"defaults",
"[",
"'modification_date_gmt'",
"]",
"=",
"DateTimeObj",
"::",
"getGMT",
"(",
"'Y-m-d H:i:s'",
")",
";",
"$",
"defaults",
"[",
"'author_id'",
"]",
"=",
"1",
";",
"$",
"defaults",
"[",
"'modification_author_id'",
"]",
"=",
"1",
";",
"$",
"settings",
"=",
"array_replace",
"(",
"$",
"defaults",
",",
"$",
"settings",
")",
";",
"if",
"(",
"!",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"insert",
"(",
"$",
"settings",
",",
"'tbl_sections'",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"getInsertID",
"(",
")",
";",
"}"
] | Takes an associative array of Section settings and creates a new
entry in the `tbl_sections` table, returning the ID of the Section.
The ID of the section is generated using auto_increment and returned
as the Section ID.
@param array $settings
An associative of settings for a section with the key being
a column name from `tbl_sections`
@throws DatabaseException
@return integer
The newly created Section's ID | [
"Takes",
"an",
"associative",
"array",
"of",
"Section",
"settings",
"and",
"creates",
"a",
"new",
"entry",
"in",
"the",
"tbl_sections",
"table",
"returning",
"the",
"ID",
"of",
"the",
"Section",
".",
"The",
"ID",
"of",
"the",
"section",
"is",
"generated",
"using",
"auto_increment",
"and",
"returned",
"as",
"the",
"Section",
"ID",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.sectionmanager.php#L35-L48 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.sectionmanager.php | SectionManager.edit | public static function edit($section_id, array $settings)
{
$defaults = array();
$defaults['modification_date'] = DateTimeObj::get('Y-m-d H:i:s');
$defaults['modification_date_gmt'] = DateTimeObj::getGMT('Y-m-d H:i:s');
$defaults['author_id'] = 1;
$defaults['modification_author_id'] = 1;
$settings = array_replace($defaults, $settings);
if (!Symphony::Database()->update($settings, 'tbl_sections', sprintf(" `id` = %d", $section_id))) {
return false;
}
return true;
} | php | public static function edit($section_id, array $settings)
{
$defaults = array();
$defaults['modification_date'] = DateTimeObj::get('Y-m-d H:i:s');
$defaults['modification_date_gmt'] = DateTimeObj::getGMT('Y-m-d H:i:s');
$defaults['author_id'] = 1;
$defaults['modification_author_id'] = 1;
$settings = array_replace($defaults, $settings);
if (!Symphony::Database()->update($settings, 'tbl_sections', sprintf(" `id` = %d", $section_id))) {
return false;
}
return true;
} | [
"public",
"static",
"function",
"edit",
"(",
"$",
"section_id",
",",
"array",
"$",
"settings",
")",
"{",
"$",
"defaults",
"=",
"array",
"(",
")",
";",
"$",
"defaults",
"[",
"'modification_date'",
"]",
"=",
"DateTimeObj",
"::",
"get",
"(",
"'Y-m-d H:i:s'",
")",
";",
"$",
"defaults",
"[",
"'modification_date_gmt'",
"]",
"=",
"DateTimeObj",
"::",
"getGMT",
"(",
"'Y-m-d H:i:s'",
")",
";",
"$",
"defaults",
"[",
"'author_id'",
"]",
"=",
"1",
";",
"$",
"defaults",
"[",
"'modification_author_id'",
"]",
"=",
"1",
";",
"$",
"settings",
"=",
"array_replace",
"(",
"$",
"defaults",
",",
"$",
"settings",
")",
";",
"if",
"(",
"!",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"update",
"(",
"$",
"settings",
",",
"'tbl_sections'",
",",
"sprintf",
"(",
"\" `id` = %d\"",
",",
"$",
"section_id",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Updates an existing Section given it's ID and an associative
array of settings. The array does not have to contain all the
settings for the Section as there is no deletion of settings
prior to updating the Section
@param integer $section_id
The ID of the Section to edit
@param array $settings
An associative of settings for a section with the key being
a column name from `tbl_sections`
@throws DatabaseException
@return boolean | [
"Updates",
"an",
"existing",
"Section",
"given",
"it",
"s",
"ID",
"and",
"an",
"associative",
"array",
"of",
"settings",
".",
"The",
"array",
"does",
"not",
"have",
"to",
"contain",
"all",
"the",
"settings",
"for",
"the",
"Section",
"as",
"there",
"is",
"no",
"deletion",
"of",
"settings",
"prior",
"to",
"updating",
"the",
"Section"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.sectionmanager.php#L64-L77 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.sectionmanager.php | SectionManager.delete | public static function delete($section_id)
{
$details = Symphony::Database()->fetchRow(0, sprintf("
SELECT `sortorder` FROM tbl_sections WHERE `id` = %d",
$section_id
));
// Delete all the entries
$entries = Symphony::Database()->fetchCol('id', "SELECT `id` FROM `tbl_entries` WHERE `section_id` = '$section_id'");
EntryManager::delete($entries);
// Delete all the fields
$fields = FieldManager::fetch(null, $section_id);
if (is_array($fields) && !empty($fields)) {
foreach ($fields as $field) {
FieldManager::delete($field->get('id'));
}
}
// Delete the section
Symphony::Database()->delete('tbl_sections', sprintf("
`id` = %d", $section_id
));
// Update the sort orders
Symphony::Database()->query(sprintf("
UPDATE tbl_sections
SET `sortorder` = (`sortorder` - 1)
WHERE `sortorder` > %d",
$details['sortorder']
));
// Delete the section associations
Symphony::Database()->delete('tbl_sections_association', sprintf("
`parent_section_id` = %d", $section_id
));
return true;
} | php | public static function delete($section_id)
{
$details = Symphony::Database()->fetchRow(0, sprintf("
SELECT `sortorder` FROM tbl_sections WHERE `id` = %d",
$section_id
));
// Delete all the entries
$entries = Symphony::Database()->fetchCol('id', "SELECT `id` FROM `tbl_entries` WHERE `section_id` = '$section_id'");
EntryManager::delete($entries);
// Delete all the fields
$fields = FieldManager::fetch(null, $section_id);
if (is_array($fields) && !empty($fields)) {
foreach ($fields as $field) {
FieldManager::delete($field->get('id'));
}
}
// Delete the section
Symphony::Database()->delete('tbl_sections', sprintf("
`id` = %d", $section_id
));
// Update the sort orders
Symphony::Database()->query(sprintf("
UPDATE tbl_sections
SET `sortorder` = (`sortorder` - 1)
WHERE `sortorder` > %d",
$details['sortorder']
));
// Delete the section associations
Symphony::Database()->delete('tbl_sections_association', sprintf("
`parent_section_id` = %d", $section_id
));
return true;
} | [
"public",
"static",
"function",
"delete",
"(",
"$",
"section_id",
")",
"{",
"$",
"details",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchRow",
"(",
"0",
",",
"sprintf",
"(",
"\"\n SELECT `sortorder` FROM tbl_sections WHERE `id` = %d\"",
",",
"$",
"section_id",
")",
")",
";",
"// Delete all the entries",
"$",
"entries",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchCol",
"(",
"'id'",
",",
"\"SELECT `id` FROM `tbl_entries` WHERE `section_id` = '$section_id'\"",
")",
";",
"EntryManager",
"::",
"delete",
"(",
"$",
"entries",
")",
";",
"// Delete all the fields",
"$",
"fields",
"=",
"FieldManager",
"::",
"fetch",
"(",
"null",
",",
"$",
"section_id",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"fields",
")",
"&&",
"!",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"FieldManager",
"::",
"delete",
"(",
"$",
"field",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"}",
"}",
"// Delete the section",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"delete",
"(",
"'tbl_sections'",
",",
"sprintf",
"(",
"\"\n `id` = %d\"",
",",
"$",
"section_id",
")",
")",
";",
"// Update the sort orders",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"query",
"(",
"sprintf",
"(",
"\"\n UPDATE tbl_sections\n SET `sortorder` = (`sortorder` - 1)\n WHERE `sortorder` > %d\"",
",",
"$",
"details",
"[",
"'sortorder'",
"]",
")",
")",
";",
"// Delete the section associations",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"delete",
"(",
"'tbl_sections_association'",
",",
"sprintf",
"(",
"\"\n `parent_section_id` = %d\"",
",",
"$",
"section_id",
")",
")",
";",
"return",
"true",
";",
"}"
] | Deletes a Section by Section ID, removing all entries, fields, the
Section and any Section Associations in that order
@param integer $section_id
The ID of the Section to delete
@throws DatabaseException
@throws Exception
@return boolean
Returns true when completed | [
"Deletes",
"a",
"Section",
"by",
"Section",
"ID",
"removing",
"all",
"entries",
"fields",
"the",
"Section",
"and",
"any",
"Section",
"Associations",
"in",
"that",
"order"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.sectionmanager.php#L90-L129 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.sectionmanager.php | SectionManager.fetch | public static function fetch($section_id = null, $order = 'ASC', $sortfield = 'name')
{
$returnSingle = false;
$section_ids = array();
if (!is_null($section_id)) {
if (!is_array($section_id)) {
$returnSingle = true;
$section_ids = array($section_id);
} else {
$section_ids = $section_id;
}
}
if ($returnSingle && isset(self::$_pool[$section_id])) {
return self::$_pool[$section_id];
}
// Ensure they are always an ID
$section_ids = array_map('intval', $section_ids);
$sql = sprintf(
"SELECT `s`.*
FROM `tbl_sections` AS `s`
%s
%s",
!empty($section_id) ? " WHERE `s`.`id` IN (" . implode(',', $section_ids) . ") " : "",
empty($section_id) ? " ORDER BY `s`.`$sortfield` $order" : ""
);
if (!$sections = Symphony::Database()->fetch($sql)) {
return ($returnSingle ? false : array());
}
$ret = array();
foreach ($sections as $s) {
$obj = self::create();
foreach ($s as $name => $value) {
$obj->set($name, $value);
}
$obj->set('creation_date', DateTimeObj::get('c', $obj->get('creation_date')));
$modDate = $obj->get('modification_date');
if (!empty($modDate)) {
$obj->set('modification_date', DateTimeObj::get('c', $obj->get('modification_date')));
} else {
$obj->set('modification_date', $obj->get('creation_date'));
}
self::$_pool[$obj->get('id')] = $obj;
$ret[] = $obj;
}
return (count($ret) == 1 && $returnSingle ? $ret[0] : $ret);
} | php | public static function fetch($section_id = null, $order = 'ASC', $sortfield = 'name')
{
$returnSingle = false;
$section_ids = array();
if (!is_null($section_id)) {
if (!is_array($section_id)) {
$returnSingle = true;
$section_ids = array($section_id);
} else {
$section_ids = $section_id;
}
}
if ($returnSingle && isset(self::$_pool[$section_id])) {
return self::$_pool[$section_id];
}
// Ensure they are always an ID
$section_ids = array_map('intval', $section_ids);
$sql = sprintf(
"SELECT `s`.*
FROM `tbl_sections` AS `s`
%s
%s",
!empty($section_id) ? " WHERE `s`.`id` IN (" . implode(',', $section_ids) . ") " : "",
empty($section_id) ? " ORDER BY `s`.`$sortfield` $order" : ""
);
if (!$sections = Symphony::Database()->fetch($sql)) {
return ($returnSingle ? false : array());
}
$ret = array();
foreach ($sections as $s) {
$obj = self::create();
foreach ($s as $name => $value) {
$obj->set($name, $value);
}
$obj->set('creation_date', DateTimeObj::get('c', $obj->get('creation_date')));
$modDate = $obj->get('modification_date');
if (!empty($modDate)) {
$obj->set('modification_date', DateTimeObj::get('c', $obj->get('modification_date')));
} else {
$obj->set('modification_date', $obj->get('creation_date'));
}
self::$_pool[$obj->get('id')] = $obj;
$ret[] = $obj;
}
return (count($ret) == 1 && $returnSingle ? $ret[0] : $ret);
} | [
"public",
"static",
"function",
"fetch",
"(",
"$",
"section_id",
"=",
"null",
",",
"$",
"order",
"=",
"'ASC'",
",",
"$",
"sortfield",
"=",
"'name'",
")",
"{",
"$",
"returnSingle",
"=",
"false",
";",
"$",
"section_ids",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"section_id",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"section_id",
")",
")",
"{",
"$",
"returnSingle",
"=",
"true",
";",
"$",
"section_ids",
"=",
"array",
"(",
"$",
"section_id",
")",
";",
"}",
"else",
"{",
"$",
"section_ids",
"=",
"$",
"section_id",
";",
"}",
"}",
"if",
"(",
"$",
"returnSingle",
"&&",
"isset",
"(",
"self",
"::",
"$",
"_pool",
"[",
"$",
"section_id",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"_pool",
"[",
"$",
"section_id",
"]",
";",
"}",
"// Ensure they are always an ID",
"$",
"section_ids",
"=",
"array_map",
"(",
"'intval'",
",",
"$",
"section_ids",
")",
";",
"$",
"sql",
"=",
"sprintf",
"(",
"\"SELECT `s`.*\n FROM `tbl_sections` AS `s`\n %s\n %s\"",
",",
"!",
"empty",
"(",
"$",
"section_id",
")",
"?",
"\" WHERE `s`.`id` IN (\"",
".",
"implode",
"(",
"','",
",",
"$",
"section_ids",
")",
".",
"\") \"",
":",
"\"\"",
",",
"empty",
"(",
"$",
"section_id",
")",
"?",
"\" ORDER BY `s`.`$sortfield` $order\"",
":",
"\"\"",
")",
";",
"if",
"(",
"!",
"$",
"sections",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetch",
"(",
"$",
"sql",
")",
")",
"{",
"return",
"(",
"$",
"returnSingle",
"?",
"false",
":",
"array",
"(",
")",
")",
";",
"}",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"sections",
"as",
"$",
"s",
")",
"{",
"$",
"obj",
"=",
"self",
"::",
"create",
"(",
")",
";",
"foreach",
"(",
"$",
"s",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"obj",
"->",
"set",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"$",
"obj",
"->",
"set",
"(",
"'creation_date'",
",",
"DateTimeObj",
"::",
"get",
"(",
"'c'",
",",
"$",
"obj",
"->",
"get",
"(",
"'creation_date'",
")",
")",
")",
";",
"$",
"modDate",
"=",
"$",
"obj",
"->",
"get",
"(",
"'modification_date'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"modDate",
")",
")",
"{",
"$",
"obj",
"->",
"set",
"(",
"'modification_date'",
",",
"DateTimeObj",
"::",
"get",
"(",
"'c'",
",",
"$",
"obj",
"->",
"get",
"(",
"'modification_date'",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"obj",
"->",
"set",
"(",
"'modification_date'",
",",
"$",
"obj",
"->",
"get",
"(",
"'creation_date'",
")",
")",
";",
"}",
"self",
"::",
"$",
"_pool",
"[",
"$",
"obj",
"->",
"get",
"(",
"'id'",
")",
"]",
"=",
"$",
"obj",
";",
"$",
"ret",
"[",
"]",
"=",
"$",
"obj",
";",
"}",
"return",
"(",
"count",
"(",
"$",
"ret",
")",
"==",
"1",
"&&",
"$",
"returnSingle",
"?",
"$",
"ret",
"[",
"0",
"]",
":",
"$",
"ret",
")",
";",
"}"
] | Returns a Section object by ID, or returns an array of Sections
if the Section ID was omitted. If the Section ID is omitted, it is
possible to sort the Sections by providing a sort order and sort
field. By default, Sections will be order in ascending order by
their name
@param integer|array $section_id
The ID of the section to return, or an array of ID's. Defaults to null
@param string $order
If `$section_id` is omitted, this is the sortorder of the returned
objects. Defaults to ASC, other options id DESC
@param string $sortfield
The name of the column in the `tbl_sections` table to sort
on. Defaults to name
@throws DatabaseException
@return Section|array
A Section object or an array of Section objects | [
"Returns",
"a",
"Section",
"object",
"by",
"ID",
"or",
"returns",
"an",
"array",
"of",
"Sections",
"if",
"the",
"Section",
"ID",
"was",
"omitted",
".",
"If",
"the",
"Section",
"ID",
"is",
"omitted",
"it",
"is",
"possible",
"to",
"sort",
"the",
"Sections",
"by",
"providing",
"a",
"sort",
"order",
"and",
"sort",
"field",
".",
"By",
"default",
"Sections",
"will",
"be",
"order",
"in",
"ascending",
"order",
"by",
"their",
"name"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.sectionmanager.php#L150-L207 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.sectionmanager.php | SectionManager.createSectionAssociation | public static function createSectionAssociation($parent_section_id = null, $child_field_id = null, $parent_field_id = null, $show_association = true, $interface = null, $editor = null)
{
if (is_null($parent_section_id) && (is_null($parent_field_id) || !$parent_field_id)) {
return false;
}
if (is_null($parent_section_id)) {
$parent_field = FieldManager::fetch($parent_field_id);
$parent_section_id = $parent_field->get('parent_section');
}
$child_field = FieldManager::fetch($child_field_id);
$child_section_id = $child_field->get('parent_section');
$fields = array(
'parent_section_id' => $parent_section_id,
'parent_section_field_id' => $parent_field_id,
'child_section_id' => $child_section_id,
'child_section_field_id' => $child_field_id,
'hide_association' => ($show_association ? 'no' : 'yes'),
'interface' => $interface,
'editor' => $editor
);
return Symphony::Database()->insert($fields, 'tbl_sections_association');
} | php | public static function createSectionAssociation($parent_section_id = null, $child_field_id = null, $parent_field_id = null, $show_association = true, $interface = null, $editor = null)
{
if (is_null($parent_section_id) && (is_null($parent_field_id) || !$parent_field_id)) {
return false;
}
if (is_null($parent_section_id)) {
$parent_field = FieldManager::fetch($parent_field_id);
$parent_section_id = $parent_field->get('parent_section');
}
$child_field = FieldManager::fetch($child_field_id);
$child_section_id = $child_field->get('parent_section');
$fields = array(
'parent_section_id' => $parent_section_id,
'parent_section_field_id' => $parent_field_id,
'child_section_id' => $child_section_id,
'child_section_field_id' => $child_field_id,
'hide_association' => ($show_association ? 'no' : 'yes'),
'interface' => $interface,
'editor' => $editor
);
return Symphony::Database()->insert($fields, 'tbl_sections_association');
} | [
"public",
"static",
"function",
"createSectionAssociation",
"(",
"$",
"parent_section_id",
"=",
"null",
",",
"$",
"child_field_id",
"=",
"null",
",",
"$",
"parent_field_id",
"=",
"null",
",",
"$",
"show_association",
"=",
"true",
",",
"$",
"interface",
"=",
"null",
",",
"$",
"editor",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"parent_section_id",
")",
"&&",
"(",
"is_null",
"(",
"$",
"parent_field_id",
")",
"||",
"!",
"$",
"parent_field_id",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"parent_section_id",
")",
")",
"{",
"$",
"parent_field",
"=",
"FieldManager",
"::",
"fetch",
"(",
"$",
"parent_field_id",
")",
";",
"$",
"parent_section_id",
"=",
"$",
"parent_field",
"->",
"get",
"(",
"'parent_section'",
")",
";",
"}",
"$",
"child_field",
"=",
"FieldManager",
"::",
"fetch",
"(",
"$",
"child_field_id",
")",
";",
"$",
"child_section_id",
"=",
"$",
"child_field",
"->",
"get",
"(",
"'parent_section'",
")",
";",
"$",
"fields",
"=",
"array",
"(",
"'parent_section_id'",
"=>",
"$",
"parent_section_id",
",",
"'parent_section_field_id'",
"=>",
"$",
"parent_field_id",
",",
"'child_section_id'",
"=>",
"$",
"child_section_id",
",",
"'child_section_field_id'",
"=>",
"$",
"child_field_id",
",",
"'hide_association'",
"=>",
"(",
"$",
"show_association",
"?",
"'no'",
":",
"'yes'",
")",
",",
"'interface'",
"=>",
"$",
"interface",
",",
"'editor'",
"=>",
"$",
"editor",
")",
";",
"return",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"insert",
"(",
"$",
"fields",
",",
"'tbl_sections_association'",
")",
";",
"}"
] | Create an association between a section and a field.
@since Symphony 2.3
@param integer $parent_section_id
The linked section id.
@param integer $child_field_id
The field ID of the field that is creating the association
@param integer $parent_field_id (optional)
The field ID of the linked field in the linked section
@param boolean $show_association (optional)
Whether of not the link should be shown on the entries table of the
linked section. This defaults to true.
@throws DatabaseException
@throws Exception
@return boolean
true if the association was successfully made, false otherwise. | [
"Create",
"an",
"association",
"between",
"a",
"section",
"and",
"a",
"field",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.sectionmanager.php#L274-L299 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.sectionmanager.php | SectionManager.fetchAssociatedSections | public static function fetchAssociatedSections($section_id, $respect_visibility = false)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('SectionManager::fetchAssociatedSections()', 'SectionManager::fetchChildAssociations()');
}
self::fetchChildAssociations($section_id, $respect_visibility);
} | php | public static function fetchAssociatedSections($section_id, $respect_visibility = false)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('SectionManager::fetchAssociatedSections()', 'SectionManager::fetchChildAssociations()');
}
self::fetchChildAssociations($section_id, $respect_visibility);
} | [
"public",
"static",
"function",
"fetchAssociatedSections",
"(",
"$",
"section_id",
",",
"$",
"respect_visibility",
"=",
"false",
")",
"{",
"if",
"(",
"Symphony",
"::",
"Log",
"(",
")",
")",
"{",
"Symphony",
"::",
"Log",
"(",
")",
"->",
"pushDeprecateWarningToLog",
"(",
"'SectionManager::fetchAssociatedSections()'",
",",
"'SectionManager::fetchChildAssociations()'",
")",
";",
"}",
"self",
"::",
"fetchChildAssociations",
"(",
"$",
"section_id",
",",
"$",
"respect_visibility",
")",
";",
"}"
] | Returns any section associations this section has with other sections
linked using fields. Has an optional parameter, `$respect_visibility` that
will only return associations that are deemed visible by a field that
created the association. eg. An articles section may link to the authors
section, but the field that links these sections has hidden this association
so an Articles column will not appear on the Author's Publish Index
@deprecated This function will be removed in Symphony 3.0. Use `fetchChildAssociations` instead.
@since Symphony 2.3
@param integer $section_id
The ID of the section
@param boolean $respect_visibility
Whether to return all the section associations regardless of if they
are deemed visible or not. Defaults to false, which will return all
associations.
@return array | [
"Returns",
"any",
"section",
"associations",
"this",
"section",
"has",
"with",
"other",
"sections",
"linked",
"using",
"fields",
".",
"Has",
"an",
"optional",
"parameter",
"$respect_visibility",
"that",
"will",
"only",
"return",
"associations",
"that",
"are",
"deemed",
"visible",
"by",
"a",
"field",
"that",
"created",
"the",
"association",
".",
"eg",
".",
"An",
"articles",
"section",
"may",
"link",
"to",
"the",
"authors",
"section",
"but",
"the",
"field",
"that",
"links",
"these",
"sections",
"has",
"hidden",
"this",
"association",
"so",
"an",
"Articles",
"column",
"will",
"not",
"appear",
"on",
"the",
"Author",
"s",
"Publish",
"Index"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.sectionmanager.php#L359-L365 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.sectionmanager.php | SectionManager.fetchChildAssociations | public static function fetchChildAssociations($section_id, $respect_visibility = false)
{
return Symphony::Database()->fetch(sprintf("
SELECT *
FROM `tbl_sections_association` AS `sa`, `tbl_sections` AS `s`
WHERE `sa`.`parent_section_id` = %d
AND `s`.`id` = `sa`.`child_section_id`
%s
ORDER BY `s`.`sortorder` ASC",
$section_id,
($respect_visibility) ? "AND `sa`.`hide_association` = 'no'" : ""
));
} | php | public static function fetchChildAssociations($section_id, $respect_visibility = false)
{
return Symphony::Database()->fetch(sprintf("
SELECT *
FROM `tbl_sections_association` AS `sa`, `tbl_sections` AS `s`
WHERE `sa`.`parent_section_id` = %d
AND `s`.`id` = `sa`.`child_section_id`
%s
ORDER BY `s`.`sortorder` ASC",
$section_id,
($respect_visibility) ? "AND `sa`.`hide_association` = 'no'" : ""
));
} | [
"public",
"static",
"function",
"fetchChildAssociations",
"(",
"$",
"section_id",
",",
"$",
"respect_visibility",
"=",
"false",
")",
"{",
"return",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetch",
"(",
"sprintf",
"(",
"\"\n SELECT *\n FROM `tbl_sections_association` AS `sa`, `tbl_sections` AS `s`\n WHERE `sa`.`parent_section_id` = %d\n AND `s`.`id` = `sa`.`child_section_id`\n %s\n ORDER BY `s`.`sortorder` ASC\"",
",",
"$",
"section_id",
",",
"(",
"$",
"respect_visibility",
")",
"?",
"\"AND `sa`.`hide_association` = 'no'\"",
":",
"\"\"",
")",
")",
";",
"}"
] | Returns any section associations this section has with other sections
linked using fields, and where this section is the parent in the association.
Has an optional parameter, `$respect_visibility` that
will only return associations that are deemed visible by a field that
created the association. eg. An articles section may link to the authors
section, but the field that links these sections has hidden this association
so an Articles column will not appear on the Author's Publish Index
@since Symphony 2.3.3
@param integer $section_id
The ID of the section
@param boolean $respect_visibility
Whether to return all the section associations regardless of if they
are deemed visible or not. Defaults to false, which will return all
associations.
@throws DatabaseException
@return array | [
"Returns",
"any",
"section",
"associations",
"this",
"section",
"has",
"with",
"other",
"sections",
"linked",
"using",
"fields",
"and",
"where",
"this",
"section",
"is",
"the",
"parent",
"in",
"the",
"association",
".",
"Has",
"an",
"optional",
"parameter",
"$respect_visibility",
"that",
"will",
"only",
"return",
"associations",
"that",
"are",
"deemed",
"visible",
"by",
"a",
"field",
"that",
"created",
"the",
"association",
".",
"eg",
".",
"An",
"articles",
"section",
"may",
"link",
"to",
"the",
"authors",
"section",
"but",
"the",
"field",
"that",
"links",
"these",
"sections",
"has",
"hidden",
"this",
"association",
"so",
"an",
"Articles",
"column",
"will",
"not",
"appear",
"on",
"the",
"Author",
"s",
"Publish",
"Index"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.sectionmanager.php#L386-L398 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.sectionmanager.php | SectionManager.fetchParentAssociations | public static function fetchParentAssociations($section_id, $respect_visibility = false)
{
return Symphony::Database()->fetch(sprintf(
"SELECT *
FROM `tbl_sections_association` AS `sa`, `tbl_sections` AS `s`
WHERE `sa`.`child_section_id` = %d
AND `s`.`id` = `sa`.`parent_section_id`
%s
ORDER BY `s`.`sortorder` ASC",
$section_id,
($respect_visibility) ? "AND `sa`.`hide_association` = 'no'" : ""
));
} | php | public static function fetchParentAssociations($section_id, $respect_visibility = false)
{
return Symphony::Database()->fetch(sprintf(
"SELECT *
FROM `tbl_sections_association` AS `sa`, `tbl_sections` AS `s`
WHERE `sa`.`child_section_id` = %d
AND `s`.`id` = `sa`.`parent_section_id`
%s
ORDER BY `s`.`sortorder` ASC",
$section_id,
($respect_visibility) ? "AND `sa`.`hide_association` = 'no'" : ""
));
} | [
"public",
"static",
"function",
"fetchParentAssociations",
"(",
"$",
"section_id",
",",
"$",
"respect_visibility",
"=",
"false",
")",
"{",
"return",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetch",
"(",
"sprintf",
"(",
"\"SELECT *\n FROM `tbl_sections_association` AS `sa`, `tbl_sections` AS `s`\n WHERE `sa`.`child_section_id` = %d\n AND `s`.`id` = `sa`.`parent_section_id`\n %s\n ORDER BY `s`.`sortorder` ASC\"",
",",
"$",
"section_id",
",",
"(",
"$",
"respect_visibility",
")",
"?",
"\"AND `sa`.`hide_association` = 'no'\"",
":",
"\"\"",
")",
")",
";",
"}"
] | Returns any section associations this section has with other sections
linked using fields, and where this section is the child in the association.
Has an optional parameter, `$respect_visibility` that
will only return associations that are deemed visible by a field that
created the association. eg. An articles section may link to the authors
section, but the field that links these sections has hidden this association
so an Articles column will not appear on the Author's Publish Index
@since Symphony 2.3.3
@param integer $section_id
The ID of the section
@param boolean $respect_visibility
Whether to return all the section associations regardless of if they
are deemed visible or not. Defaults to false, which will return all
associations.
@throws DatabaseException
@return array | [
"Returns",
"any",
"section",
"associations",
"this",
"section",
"has",
"with",
"other",
"sections",
"linked",
"using",
"fields",
"and",
"where",
"this",
"section",
"is",
"the",
"child",
"in",
"the",
"association",
".",
"Has",
"an",
"optional",
"parameter",
"$respect_visibility",
"that",
"will",
"only",
"return",
"associations",
"that",
"are",
"deemed",
"visible",
"by",
"a",
"field",
"that",
"created",
"the",
"association",
".",
"eg",
".",
"An",
"articles",
"section",
"may",
"link",
"to",
"the",
"authors",
"section",
"but",
"the",
"field",
"that",
"links",
"these",
"sections",
"has",
"hidden",
"this",
"association",
"so",
"an",
"Articles",
"column",
"will",
"not",
"appear",
"on",
"the",
"Author",
"s",
"Publish",
"Index"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.sectionmanager.php#L419-L431 |
symphonycms/symphony-2 | symphony/lib/toolkit/cryptography/class.md5.php | MD5.hash | public static function hash($input)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('MD5::hash()', 'PBKDF2::hash()', array(
'message-format' => __('The use of `%s` is strongly discouraged due to severe security flaws.'),
));
}
return md5($input);
} | php | public static function hash($input)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('MD5::hash()', 'PBKDF2::hash()', array(
'message-format' => __('The use of `%s` is strongly discouraged due to severe security flaws.'),
));
}
return md5($input);
} | [
"public",
"static",
"function",
"hash",
"(",
"$",
"input",
")",
"{",
"if",
"(",
"Symphony",
"::",
"Log",
"(",
")",
")",
"{",
"Symphony",
"::",
"Log",
"(",
")",
"->",
"pushDeprecateWarningToLog",
"(",
"'MD5::hash()'",
",",
"'PBKDF2::hash()'",
",",
"array",
"(",
"'message-format'",
"=>",
"__",
"(",
"'The use of `%s` is strongly discouraged due to severe security flaws.'",
")",
",",
")",
")",
";",
"}",
"return",
"md5",
"(",
"$",
"input",
")",
";",
"}"
] | Uses `MD5` to create a hash based on some input
@param string $input
the string to be hashed
@return string
the hashed string | [
"Uses",
"MD5",
"to",
"create",
"a",
"hash",
"based",
"on",
"some",
"input"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/cryptography/class.md5.php#L24-L32 |
symphonycms/symphony-2 | symphony/lib/toolkit/cryptography/class.md5.php | MD5.file | public static function file($input)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('MD5::file()', 'PBKDF2::hash()', array(
'message-format' => __('The use of `%s` is strongly discouraged due to severe security flaws.'),
));
}
return md5_file($input);
} | php | public static function file($input)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('MD5::file()', 'PBKDF2::hash()', array(
'message-format' => __('The use of `%s` is strongly discouraged due to severe security flaws.'),
));
}
return md5_file($input);
} | [
"public",
"static",
"function",
"file",
"(",
"$",
"input",
")",
"{",
"if",
"(",
"Symphony",
"::",
"Log",
"(",
")",
")",
"{",
"Symphony",
"::",
"Log",
"(",
")",
"->",
"pushDeprecateWarningToLog",
"(",
"'MD5::file()'",
",",
"'PBKDF2::hash()'",
",",
"array",
"(",
"'message-format'",
"=>",
"__",
"(",
"'The use of `%s` is strongly discouraged due to severe security flaws.'",
")",
",",
")",
")",
";",
"}",
"return",
"md5_file",
"(",
"$",
"input",
")",
";",
"}"
] | Uses `MD5` to create a hash from the contents of a file
@param string $input
the file to be hashed
@return string
the hashed string | [
"Uses",
"MD5",
"to",
"create",
"a",
"hash",
"from",
"the",
"contents",
"of",
"a",
"file"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/cryptography/class.md5.php#L42-L50 |
symphonycms/symphony-2 | symphony/lib/toolkit/cryptography/class.md5.php | MD5.compare | public static function compare($input, $hash, $isHash = false)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('MD5::compare()', 'PBKDF2::compare()', array(
'message-format' => __('The use of `%s` is strongly discouraged due to severe security flaws.'),
));
}
return ($hash == self::hash($input));
} | php | public static function compare($input, $hash, $isHash = false)
{
if (Symphony::Log()) {
Symphony::Log()->pushDeprecateWarningToLog('MD5::compare()', 'PBKDF2::compare()', array(
'message-format' => __('The use of `%s` is strongly discouraged due to severe security flaws.'),
));
}
return ($hash == self::hash($input));
} | [
"public",
"static",
"function",
"compare",
"(",
"$",
"input",
",",
"$",
"hash",
",",
"$",
"isHash",
"=",
"false",
")",
"{",
"if",
"(",
"Symphony",
"::",
"Log",
"(",
")",
")",
"{",
"Symphony",
"::",
"Log",
"(",
")",
"->",
"pushDeprecateWarningToLog",
"(",
"'MD5::compare()'",
",",
"'PBKDF2::compare()'",
",",
"array",
"(",
"'message-format'",
"=>",
"__",
"(",
"'The use of `%s` is strongly discouraged due to severe security flaws.'",
")",
",",
")",
")",
";",
"}",
"return",
"(",
"$",
"hash",
"==",
"self",
"::",
"hash",
"(",
"$",
"input",
")",
")",
";",
"}"
] | Compares a given hash with a cleantext password.
@param string $input
the cleartext password
@param string $hash
the hash the password should be checked against
@param boolean $isHash
@return bool
the result of the comparison | [
"Compares",
"a",
"given",
"hash",
"with",
"a",
"cleantext",
"password",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/cryptography/class.md5.php#L63-L71 |
symphonycms/symphony-2 | symphony/lib/core/class.symphony.php | Symphony.initialiseErrorHandler | public static function initialiseErrorHandler()
{
// Initialise logging
self::initialiseLog();
GenericExceptionHandler::initialise(self::Log());
GenericErrorHandler::initialise(self::Log());
} | php | public static function initialiseErrorHandler()
{
// Initialise logging
self::initialiseLog();
GenericExceptionHandler::initialise(self::Log());
GenericErrorHandler::initialise(self::Log());
} | [
"public",
"static",
"function",
"initialiseErrorHandler",
"(",
")",
"{",
"// Initialise logging",
"self",
"::",
"initialiseLog",
"(",
")",
";",
"GenericExceptionHandler",
"::",
"initialise",
"(",
"self",
"::",
"Log",
"(",
")",
")",
";",
"GenericErrorHandler",
"::",
"initialise",
"(",
"self",
"::",
"Log",
"(",
")",
")",
";",
"}"
] | Setter for the Symphony Log and Error Handling system
@since Symphony 2.6.0 | [
"Setter",
"for",
"the",
"Symphony",
"Log",
"and",
"Error",
"Handling",
"system"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.symphony.php#L119-L125 |
symphonycms/symphony-2 | symphony/lib/core/class.symphony.php | Symphony.Engine | public static function Engine()
{
if (class_exists('Administration', false)) {
return Administration::instance();
} elseif (class_exists('Frontend', false)) {
return Frontend::instance();
} else {
throw new Exception(__('No suitable engine object found'));
}
} | php | public static function Engine()
{
if (class_exists('Administration', false)) {
return Administration::instance();
} elseif (class_exists('Frontend', false)) {
return Frontend::instance();
} else {
throw new Exception(__('No suitable engine object found'));
}
} | [
"public",
"static",
"function",
"Engine",
"(",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'Administration'",
",",
"false",
")",
")",
"{",
"return",
"Administration",
"::",
"instance",
"(",
")",
";",
"}",
"elseif",
"(",
"class_exists",
"(",
"'Frontend'",
",",
"false",
")",
")",
"{",
"return",
"Frontend",
"::",
"instance",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"__",
"(",
"'No suitable engine object found'",
")",
")",
";",
"}",
"}"
] | Accessor for the Symphony instance, whether it be Frontend
or Administration
@since Symphony 2.2
@throws Exception
@return Symphony | [
"Accessor",
"for",
"the",
"Symphony",
"instance",
"whether",
"it",
"be",
"Frontend",
"or",
"Administration"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.symphony.php#L135-L144 |
symphonycms/symphony-2 | symphony/lib/core/class.symphony.php | Symphony.initialiseConfiguration | public static function initialiseConfiguration(array $data = array())
{
if (empty($data)) {
// Includes the existing CONFIG file and initialises the Configuration
// by setting the values with the setArray function.
include CONFIG;
$data = $settings;
}
self::$Configuration = new Configuration(true);
self::$Configuration->setArray($data);
// Set date format throughout the system
$region = self::Configuration()->get('region');
define_safe('__SYM_DATE_FORMAT__', $region['date_format']);
define_safe('__SYM_TIME_FORMAT__', $region['time_format']);
define_safe('__SYM_DATETIME_FORMAT__', __SYM_DATE_FORMAT__ . $region['datetime_separator'] . __SYM_TIME_FORMAT__);
DateTimeObj::setSettings($region);
} | php | public static function initialiseConfiguration(array $data = array())
{
if (empty($data)) {
// Includes the existing CONFIG file and initialises the Configuration
// by setting the values with the setArray function.
include CONFIG;
$data = $settings;
}
self::$Configuration = new Configuration(true);
self::$Configuration->setArray($data);
// Set date format throughout the system
$region = self::Configuration()->get('region');
define_safe('__SYM_DATE_FORMAT__', $region['date_format']);
define_safe('__SYM_TIME_FORMAT__', $region['time_format']);
define_safe('__SYM_DATETIME_FORMAT__', __SYM_DATE_FORMAT__ . $region['datetime_separator'] . __SYM_TIME_FORMAT__);
DateTimeObj::setSettings($region);
} | [
"public",
"static",
"function",
"initialiseConfiguration",
"(",
"array",
"$",
"data",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"// Includes the existing CONFIG file and initialises the Configuration",
"// by setting the values with the setArray function.",
"include",
"CONFIG",
";",
"$",
"data",
"=",
"$",
"settings",
";",
"}",
"self",
"::",
"$",
"Configuration",
"=",
"new",
"Configuration",
"(",
"true",
")",
";",
"self",
"::",
"$",
"Configuration",
"->",
"setArray",
"(",
"$",
"data",
")",
";",
"// Set date format throughout the system",
"$",
"region",
"=",
"self",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'region'",
")",
";",
"define_safe",
"(",
"'__SYM_DATE_FORMAT__'",
",",
"$",
"region",
"[",
"'date_format'",
"]",
")",
";",
"define_safe",
"(",
"'__SYM_TIME_FORMAT__'",
",",
"$",
"region",
"[",
"'time_format'",
"]",
")",
";",
"define_safe",
"(",
"'__SYM_DATETIME_FORMAT__'",
",",
"__SYM_DATE_FORMAT__",
".",
"$",
"region",
"[",
"'datetime_separator'",
"]",
".",
"__SYM_TIME_FORMAT__",
")",
";",
"DateTimeObj",
"::",
"setSettings",
"(",
"$",
"region",
")",
";",
"}"
] | Setter for `$Configuration`. This function initialise the configuration
object and populate its properties based on the given `$array`. Since
Symphony 2.6.5, it will also set Symphony's date constants.
@since Symphony 2.3
@param array $data
An array of settings to be stored into the Configuration object | [
"Setter",
"for",
"$Configuration",
".",
"This",
"function",
"initialise",
"the",
"configuration",
"object",
"and",
"populate",
"its",
"properties",
"based",
"on",
"the",
"given",
"$array",
".",
"Since",
"Symphony",
"2",
".",
"6",
".",
"5",
"it",
"will",
"also",
"set",
"Symphony",
"s",
"date",
"constants",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.symphony.php#L155-L174 |
symphonycms/symphony-2 | symphony/lib/core/class.symphony.php | Symphony.initialiseLog | public static function initialiseLog($filename = null)
{
if (self::$Log instanceof Log && self::$Log->getLogPath() == $filename) {
return true;
}
if (is_null($filename)) {
$filename = ACTIVITY_LOG;
}
self::$Log = new Log($filename);
self::$Log->setArchive((self::Configuration()->get('archive', 'log') == '1' ? true : false));
self::$Log->setMaxSize(self::Configuration()->get('maxsize', 'log'));
self::$Log->setFilter(self::Configuration()->get('filter', 'log'));
self::$Log->setDateTimeFormat(__SYM_DATETIME_FORMAT__);
if (self::$Log->open(Log::APPEND, self::Configuration()->get('write_mode', 'file')) == '1') {
self::$Log->initialise('Symphony Log');
}
} | php | public static function initialiseLog($filename = null)
{
if (self::$Log instanceof Log && self::$Log->getLogPath() == $filename) {
return true;
}
if (is_null($filename)) {
$filename = ACTIVITY_LOG;
}
self::$Log = new Log($filename);
self::$Log->setArchive((self::Configuration()->get('archive', 'log') == '1' ? true : false));
self::$Log->setMaxSize(self::Configuration()->get('maxsize', 'log'));
self::$Log->setFilter(self::Configuration()->get('filter', 'log'));
self::$Log->setDateTimeFormat(__SYM_DATETIME_FORMAT__);
if (self::$Log->open(Log::APPEND, self::Configuration()->get('write_mode', 'file')) == '1') {
self::$Log->initialise('Symphony Log');
}
} | [
"public",
"static",
"function",
"initialiseLog",
"(",
"$",
"filename",
"=",
"null",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"Log",
"instanceof",
"Log",
"&&",
"self",
"::",
"$",
"Log",
"->",
"getLogPath",
"(",
")",
"==",
"$",
"filename",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"filename",
")",
")",
"{",
"$",
"filename",
"=",
"ACTIVITY_LOG",
";",
"}",
"self",
"::",
"$",
"Log",
"=",
"new",
"Log",
"(",
"$",
"filename",
")",
";",
"self",
"::",
"$",
"Log",
"->",
"setArchive",
"(",
"(",
"self",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'archive'",
",",
"'log'",
")",
"==",
"'1'",
"?",
"true",
":",
"false",
")",
")",
";",
"self",
"::",
"$",
"Log",
"->",
"setMaxSize",
"(",
"self",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'maxsize'",
",",
"'log'",
")",
")",
";",
"self",
"::",
"$",
"Log",
"->",
"setFilter",
"(",
"self",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'filter'",
",",
"'log'",
")",
")",
";",
"self",
"::",
"$",
"Log",
"->",
"setDateTimeFormat",
"(",
"__SYM_DATETIME_FORMAT__",
")",
";",
"if",
"(",
"self",
"::",
"$",
"Log",
"->",
"open",
"(",
"Log",
"::",
"APPEND",
",",
"self",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'write_mode'",
",",
"'file'",
")",
")",
"==",
"'1'",
")",
"{",
"self",
"::",
"$",
"Log",
"->",
"initialise",
"(",
"'Symphony Log'",
")",
";",
"}",
"}"
] | Setter for `$Log`. This function uses the configuration
settings in the 'log' group in the Configuration to create an instance. Date
formatting options are also retrieved from the configuration.
@param string $filename (optional)
The file to write the log to, if omitted this will default to `ACTIVITY_LOG`
@throws Exception
@return bool|void | [
"Setter",
"for",
"$Log",
".",
"This",
"function",
"uses",
"the",
"configuration",
"settings",
"in",
"the",
"log",
"group",
"in",
"the",
"Configuration",
"to",
"create",
"an",
"instance",
".",
"Date",
"formatting",
"options",
"are",
"also",
"retrieved",
"from",
"the",
"configuration",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.symphony.php#L219-L238 |
symphonycms/symphony-2 | symphony/lib/core/class.symphony.php | Symphony.initialiseCookie | public static function initialiseCookie()
{
define_safe('__SYM_COOKIE_PATH__', DIRROOT === '' ? '/' : DIRROOT);
define_safe('__SYM_COOKIE_PREFIX_', self::Configuration()->get('cookie_prefix', 'symphony'));
define_safe('__SYM_COOKIE_PREFIX__', self::Configuration()->get('cookie_prefix', 'symphony'));
self::$Cookie = new Cookie(__SYM_COOKIE_PREFIX__, TWO_WEEKS, __SYM_COOKIE_PATH__);
} | php | public static function initialiseCookie()
{
define_safe('__SYM_COOKIE_PATH__', DIRROOT === '' ? '/' : DIRROOT);
define_safe('__SYM_COOKIE_PREFIX_', self::Configuration()->get('cookie_prefix', 'symphony'));
define_safe('__SYM_COOKIE_PREFIX__', self::Configuration()->get('cookie_prefix', 'symphony'));
self::$Cookie = new Cookie(__SYM_COOKIE_PREFIX__, TWO_WEEKS, __SYM_COOKIE_PATH__);
} | [
"public",
"static",
"function",
"initialiseCookie",
"(",
")",
"{",
"define_safe",
"(",
"'__SYM_COOKIE_PATH__'",
",",
"DIRROOT",
"===",
"''",
"?",
"'/'",
":",
"DIRROOT",
")",
";",
"define_safe",
"(",
"'__SYM_COOKIE_PREFIX_'",
",",
"self",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'cookie_prefix'",
",",
"'symphony'",
")",
")",
";",
"define_safe",
"(",
"'__SYM_COOKIE_PREFIX__'",
",",
"self",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'cookie_prefix'",
",",
"'symphony'",
")",
")",
";",
"self",
"::",
"$",
"Cookie",
"=",
"new",
"Cookie",
"(",
"__SYM_COOKIE_PREFIX__",
",",
"TWO_WEEKS",
",",
"__SYM_COOKIE_PATH__",
")",
";",
"}"
] | Setter for `$Cookie`. This will use PHP's parse_url
function on the current URL to set a cookie using the cookie_prefix
defined in the Symphony configuration. The cookie will last two
weeks.
This function also defines two constants, `__SYM_COOKIE_PATH__`
and `__SYM_COOKIE_PREFIX__`.
@deprecated Prior to Symphony 2.3.2, the constant `__SYM_COOKIE_PREFIX_`
had a typo where it was missing the second underscore. Symphony will
support both constants, `__SYM_COOKIE_PREFIX_` and `__SYM_COOKIE_PREFIX__`
until Symphony 3.0 | [
"Setter",
"for",
"$Cookie",
".",
"This",
"will",
"use",
"PHP",
"s",
"parse_url",
"function",
"on",
"the",
"current",
"URL",
"to",
"set",
"a",
"cookie",
"using",
"the",
"cookie_prefix",
"defined",
"in",
"the",
"Symphony",
"configuration",
".",
"The",
"cookie",
"will",
"last",
"two",
"weeks",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.symphony.php#L265-L272 |
symphonycms/symphony-2 | symphony/lib/core/class.symphony.php | Symphony.initialiseExtensionManager | public static function initialiseExtensionManager($force=false)
{
if (!$force && self::$ExtensionManager instanceof ExtensionManager) {
return true;
}
self::$ExtensionManager = new ExtensionManager;
if (!(self::$ExtensionManager instanceof ExtensionManager)) {
self::throwCustomError(__('Error creating Symphony extension manager.'));
}
} | php | public static function initialiseExtensionManager($force=false)
{
if (!$force && self::$ExtensionManager instanceof ExtensionManager) {
return true;
}
self::$ExtensionManager = new ExtensionManager;
if (!(self::$ExtensionManager instanceof ExtensionManager)) {
self::throwCustomError(__('Error creating Symphony extension manager.'));
}
} | [
"public",
"static",
"function",
"initialiseExtensionManager",
"(",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"force",
"&&",
"self",
"::",
"$",
"ExtensionManager",
"instanceof",
"ExtensionManager",
")",
"{",
"return",
"true",
";",
"}",
"self",
"::",
"$",
"ExtensionManager",
"=",
"new",
"ExtensionManager",
";",
"if",
"(",
"!",
"(",
"self",
"::",
"$",
"ExtensionManager",
"instanceof",
"ExtensionManager",
")",
")",
"{",
"self",
"::",
"throwCustomError",
"(",
"__",
"(",
"'Error creating Symphony extension manager.'",
")",
")",
";",
"}",
"}"
] | Setter for `$ExtensionManager` using the current
Symphony instance as the parent. If for some reason this fails,
a Symphony Error page will be thrown
@param Boolean $force (optional)
When set to true, this function will always create a new
instance of ExtensionManager, replacing self::$ExtensionManager. | [
"Setter",
"for",
"$ExtensionManager",
"using",
"the",
"current",
"Symphony",
"instance",
"as",
"the",
"parent",
".",
"If",
"for",
"some",
"reason",
"this",
"fails",
"a",
"Symphony",
"Error",
"page",
"will",
"be",
"thrown"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.symphony.php#L293-L304 |
symphonycms/symphony-2 | symphony/lib/core/class.symphony.php | Symphony.setDatabase | public static function setDatabase(StdClass $database = null)
{
if (self::Database()) {
return true;
}
self::$Database = !is_null($database) ? $database : new MySQL;
return true;
} | php | public static function setDatabase(StdClass $database = null)
{
if (self::Database()) {
return true;
}
self::$Database = !is_null($database) ? $database : new MySQL;
return true;
} | [
"public",
"static",
"function",
"setDatabase",
"(",
"StdClass",
"$",
"database",
"=",
"null",
")",
"{",
"if",
"(",
"self",
"::",
"Database",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"self",
"::",
"$",
"Database",
"=",
"!",
"is_null",
"(",
"$",
"database",
")",
"?",
"$",
"database",
":",
"new",
"MySQL",
";",
"return",
"true",
";",
"}"
] | Setter for `$Database`, accepts a Database object. If `$database`
is omitted, this function will set `$Database` to be of the `MySQL`
class.
@since Symphony 2.3
@param StdClass $database (optional)
The class to handle all Database operations, if omitted this function
will set `self::$Database` to be an instance of the `MySQL` class.
@return boolean
This function will always return true | [
"Setter",
"for",
"$Database",
"accepts",
"a",
"Database",
"object",
".",
"If",
"$database",
"is",
"omitted",
"this",
"function",
"will",
"set",
"$Database",
"to",
"be",
"of",
"the",
"MySQL",
"class",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.symphony.php#L329-L338 |
symphonycms/symphony-2 | symphony/lib/core/class.symphony.php | Symphony.initialiseDatabase | public static function initialiseDatabase()
{
self::setDatabase();
$details = self::Configuration()->get('database');
try {
if (!self::Database()->connect($details['host'], $details['user'], $details['password'], $details['port'], $details['db'])) {
return false;
}
if (!self::Database()->isConnected()) {
return false;
}
self::Database()->setPrefix($details['tbl_prefix']);
self::Database()->setCharacterEncoding();
self::Database()->setCharacterSet();
self::Database()->setTimeZone(self::Configuration()->get('timezone', 'region'));
if (isset($details['query_caching'])) {
if ($details['query_caching'] == 'off') {
self::Database()->disableCaching();
} elseif ($details['query_caching'] == 'on') {
self::Database()->enableCaching();
}
}
if (isset($details['query_logging'])) {
if ($details['query_logging'] == 'off') {
self::Database()->disableLogging();
} elseif ($details['query_logging'] == 'on') {
self::Database()->enableLogging();
}
}
} catch (DatabaseException $e) {
self::throwCustomError(
$e->getDatabaseErrorCode() . ': ' . $e->getDatabaseErrorMessage(),
__('Symphony Database Error'),
Page::HTTP_STATUS_ERROR,
'database',
array(
'error' => $e,
'message' => __('There was a problem whilst attempting to establish a database connection. Please check all connection information is correct.') . ' ' . __('The following error was returned:')
)
);
}
return true;
} | php | public static function initialiseDatabase()
{
self::setDatabase();
$details = self::Configuration()->get('database');
try {
if (!self::Database()->connect($details['host'], $details['user'], $details['password'], $details['port'], $details['db'])) {
return false;
}
if (!self::Database()->isConnected()) {
return false;
}
self::Database()->setPrefix($details['tbl_prefix']);
self::Database()->setCharacterEncoding();
self::Database()->setCharacterSet();
self::Database()->setTimeZone(self::Configuration()->get('timezone', 'region'));
if (isset($details['query_caching'])) {
if ($details['query_caching'] == 'off') {
self::Database()->disableCaching();
} elseif ($details['query_caching'] == 'on') {
self::Database()->enableCaching();
}
}
if (isset($details['query_logging'])) {
if ($details['query_logging'] == 'off') {
self::Database()->disableLogging();
} elseif ($details['query_logging'] == 'on') {
self::Database()->enableLogging();
}
}
} catch (DatabaseException $e) {
self::throwCustomError(
$e->getDatabaseErrorCode() . ': ' . $e->getDatabaseErrorMessage(),
__('Symphony Database Error'),
Page::HTTP_STATUS_ERROR,
'database',
array(
'error' => $e,
'message' => __('There was a problem whilst attempting to establish a database connection. Please check all connection information is correct.') . ' ' . __('The following error was returned:')
)
);
}
return true;
} | [
"public",
"static",
"function",
"initialiseDatabase",
"(",
")",
"{",
"self",
"::",
"setDatabase",
"(",
")",
";",
"$",
"details",
"=",
"self",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'database'",
")",
";",
"try",
"{",
"if",
"(",
"!",
"self",
"::",
"Database",
"(",
")",
"->",
"connect",
"(",
"$",
"details",
"[",
"'host'",
"]",
",",
"$",
"details",
"[",
"'user'",
"]",
",",
"$",
"details",
"[",
"'password'",
"]",
",",
"$",
"details",
"[",
"'port'",
"]",
",",
"$",
"details",
"[",
"'db'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"self",
"::",
"Database",
"(",
")",
"->",
"isConnected",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"self",
"::",
"Database",
"(",
")",
"->",
"setPrefix",
"(",
"$",
"details",
"[",
"'tbl_prefix'",
"]",
")",
";",
"self",
"::",
"Database",
"(",
")",
"->",
"setCharacterEncoding",
"(",
")",
";",
"self",
"::",
"Database",
"(",
")",
"->",
"setCharacterSet",
"(",
")",
";",
"self",
"::",
"Database",
"(",
")",
"->",
"setTimeZone",
"(",
"self",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'timezone'",
",",
"'region'",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"details",
"[",
"'query_caching'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"details",
"[",
"'query_caching'",
"]",
"==",
"'off'",
")",
"{",
"self",
"::",
"Database",
"(",
")",
"->",
"disableCaching",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"details",
"[",
"'query_caching'",
"]",
"==",
"'on'",
")",
"{",
"self",
"::",
"Database",
"(",
")",
"->",
"enableCaching",
"(",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"details",
"[",
"'query_logging'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"details",
"[",
"'query_logging'",
"]",
"==",
"'off'",
")",
"{",
"self",
"::",
"Database",
"(",
")",
"->",
"disableLogging",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"details",
"[",
"'query_logging'",
"]",
"==",
"'on'",
")",
"{",
"self",
"::",
"Database",
"(",
")",
"->",
"enableLogging",
"(",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"DatabaseException",
"$",
"e",
")",
"{",
"self",
"::",
"throwCustomError",
"(",
"$",
"e",
"->",
"getDatabaseErrorCode",
"(",
")",
".",
"': '",
".",
"$",
"e",
"->",
"getDatabaseErrorMessage",
"(",
")",
",",
"__",
"(",
"'Symphony Database Error'",
")",
",",
"Page",
"::",
"HTTP_STATUS_ERROR",
",",
"'database'",
",",
"array",
"(",
"'error'",
"=>",
"$",
"e",
",",
"'message'",
"=>",
"__",
"(",
"'There was a problem whilst attempting to establish a database connection. Please check all connection information is correct.'",
")",
".",
"' '",
".",
"__",
"(",
"'The following error was returned:'",
")",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] | This will initialise the Database class and attempt to create a connection
using the connection details provided in the Symphony configuration. If any
errors occur whilst doing so, a Symphony Error Page is displayed.
@throws SymphonyErrorPage
@return boolean
This function will return true if the `$Database` was
initialised successfully. | [
"This",
"will",
"initialise",
"the",
"Database",
"class",
"and",
"attempt",
"to",
"create",
"a",
"connection",
"using",
"the",
"connection",
"details",
"provided",
"in",
"the",
"Symphony",
"configuration",
".",
"If",
"any",
"errors",
"occur",
"whilst",
"doing",
"so",
"a",
"Symphony",
"Error",
"Page",
"is",
"displayed",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.symphony.php#L360-L408 |
symphonycms/symphony-2 | symphony/lib/core/class.symphony.php | Symphony.login | public static function login($username, $password, $isHash = false)
{
$username = trim(self::Database()->cleanValue($username));
$password = trim(self::Database()->cleanValue($password));
if (strlen($username) > 0 && strlen($password) > 0) {
$author = AuthorManager::fetch('id', 'ASC', 1, null, sprintf(
"`username` = '%s'",
$username
));
if (!empty($author) && Cryptography::compare($password, current($author)->get('password'), $isHash)) {
self::$Author = current($author);
// Only migrate hashes if there is no update available as the update might change the tbl_authors table.
if (self::isUpgradeAvailable() === false && Cryptography::requiresMigration(self::$Author->get('password'))) {
self::$Author->set('password', Cryptography::hash($password));
self::Database()->update(array('password' => self::$Author->get('password')), 'tbl_authors', sprintf(
" `id` = %d", self::$Author->get('id')
));
}
self::$Cookie->set('username', $username);
self::$Cookie->set('pass', self::$Author->get('password'));
self::Database()->update(array(
'last_seen' => DateTimeObj::get('Y-m-d H:i:s')),
'tbl_authors',
sprintf(" `id` = %d", self::$Author->get('id'))
);
// Only set custom author language in the backend
if (class_exists('Administration', false)) {
Lang::set(self::$Author->get('language'));
}
return true;
}
}
return false;
} | php | public static function login($username, $password, $isHash = false)
{
$username = trim(self::Database()->cleanValue($username));
$password = trim(self::Database()->cleanValue($password));
if (strlen($username) > 0 && strlen($password) > 0) {
$author = AuthorManager::fetch('id', 'ASC', 1, null, sprintf(
"`username` = '%s'",
$username
));
if (!empty($author) && Cryptography::compare($password, current($author)->get('password'), $isHash)) {
self::$Author = current($author);
// Only migrate hashes if there is no update available as the update might change the tbl_authors table.
if (self::isUpgradeAvailable() === false && Cryptography::requiresMigration(self::$Author->get('password'))) {
self::$Author->set('password', Cryptography::hash($password));
self::Database()->update(array('password' => self::$Author->get('password')), 'tbl_authors', sprintf(
" `id` = %d", self::$Author->get('id')
));
}
self::$Cookie->set('username', $username);
self::$Cookie->set('pass', self::$Author->get('password'));
self::Database()->update(array(
'last_seen' => DateTimeObj::get('Y-m-d H:i:s')),
'tbl_authors',
sprintf(" `id` = %d", self::$Author->get('id'))
);
// Only set custom author language in the backend
if (class_exists('Administration', false)) {
Lang::set(self::$Author->get('language'));
}
return true;
}
}
return false;
} | [
"public",
"static",
"function",
"login",
"(",
"$",
"username",
",",
"$",
"password",
",",
"$",
"isHash",
"=",
"false",
")",
"{",
"$",
"username",
"=",
"trim",
"(",
"self",
"::",
"Database",
"(",
")",
"->",
"cleanValue",
"(",
"$",
"username",
")",
")",
";",
"$",
"password",
"=",
"trim",
"(",
"self",
"::",
"Database",
"(",
")",
"->",
"cleanValue",
"(",
"$",
"password",
")",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"username",
")",
">",
"0",
"&&",
"strlen",
"(",
"$",
"password",
")",
">",
"0",
")",
"{",
"$",
"author",
"=",
"AuthorManager",
"::",
"fetch",
"(",
"'id'",
",",
"'ASC'",
",",
"1",
",",
"null",
",",
"sprintf",
"(",
"\"`username` = '%s'\"",
",",
"$",
"username",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"author",
")",
"&&",
"Cryptography",
"::",
"compare",
"(",
"$",
"password",
",",
"current",
"(",
"$",
"author",
")",
"->",
"get",
"(",
"'password'",
")",
",",
"$",
"isHash",
")",
")",
"{",
"self",
"::",
"$",
"Author",
"=",
"current",
"(",
"$",
"author",
")",
";",
"// Only migrate hashes if there is no update available as the update might change the tbl_authors table.",
"if",
"(",
"self",
"::",
"isUpgradeAvailable",
"(",
")",
"===",
"false",
"&&",
"Cryptography",
"::",
"requiresMigration",
"(",
"self",
"::",
"$",
"Author",
"->",
"get",
"(",
"'password'",
")",
")",
")",
"{",
"self",
"::",
"$",
"Author",
"->",
"set",
"(",
"'password'",
",",
"Cryptography",
"::",
"hash",
"(",
"$",
"password",
")",
")",
";",
"self",
"::",
"Database",
"(",
")",
"->",
"update",
"(",
"array",
"(",
"'password'",
"=>",
"self",
"::",
"$",
"Author",
"->",
"get",
"(",
"'password'",
")",
")",
",",
"'tbl_authors'",
",",
"sprintf",
"(",
"\" `id` = %d\"",
",",
"self",
"::",
"$",
"Author",
"->",
"get",
"(",
"'id'",
")",
")",
")",
";",
"}",
"self",
"::",
"$",
"Cookie",
"->",
"set",
"(",
"'username'",
",",
"$",
"username",
")",
";",
"self",
"::",
"$",
"Cookie",
"->",
"set",
"(",
"'pass'",
",",
"self",
"::",
"$",
"Author",
"->",
"get",
"(",
"'password'",
")",
")",
";",
"self",
"::",
"Database",
"(",
")",
"->",
"update",
"(",
"array",
"(",
"'last_seen'",
"=>",
"DateTimeObj",
"::",
"get",
"(",
"'Y-m-d H:i:s'",
")",
")",
",",
"'tbl_authors'",
",",
"sprintf",
"(",
"\" `id` = %d\"",
",",
"self",
"::",
"$",
"Author",
"->",
"get",
"(",
"'id'",
")",
")",
")",
";",
"// Only set custom author language in the backend",
"if",
"(",
"class_exists",
"(",
"'Administration'",
",",
"false",
")",
")",
"{",
"Lang",
"::",
"set",
"(",
"self",
"::",
"$",
"Author",
"->",
"get",
"(",
"'language'",
")",
")",
";",
"}",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Attempts to log an Author in given a username and password.
If the password is not hashed, it will be hashed using the sha1
algorithm. The username and password will be sanitized before
being used to query the Database. If an Author is found, they
will be logged in and the sanitized username and password (also hashed)
will be saved as values in the `$Cookie`.
@see toolkit.Cryptography#hash()
@throws DatabaseException
@param string $username
The Author's username. This will be sanitized before use.
@param string $password
The Author's password. This will be sanitized and then hashed before use
@param boolean $isHash
If the password provided is already hashed, setting this parameter to
true will stop it becoming rehashed. By default it is false.
@return boolean
true if the Author was logged in, false otherwise | [
"Attempts",
"to",
"log",
"an",
"Author",
"in",
"given",
"a",
"username",
"and",
"password",
".",
"If",
"the",
"password",
"is",
"not",
"hashed",
"it",
"will",
"be",
"hashed",
"using",
"the",
"sha1",
"algorithm",
".",
"The",
"username",
"and",
"password",
"will",
"be",
"sanitized",
"before",
"being",
"used",
"to",
"query",
"the",
"Database",
".",
"If",
"an",
"Author",
"is",
"found",
"they",
"will",
"be",
"logged",
"in",
"and",
"the",
"sanitized",
"username",
"and",
"password",
"(",
"also",
"hashed",
")",
"will",
"be",
"saved",
"as",
"values",
"in",
"the",
"$Cookie",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.symphony.php#L441-L483 |
symphonycms/symphony-2 | symphony/lib/core/class.symphony.php | Symphony.loginFromToken | public static function loginFromToken($token)
{
$token = self::Database()->cleanValue($token);
if (strlen(trim($token)) == 0) {
return false;
}
if (strlen($token) == 6 || strlen($token) == 16) {
$row = self::Database()->fetchRow(0, sprintf(
"SELECT `a`.`id`, `a`.`username`, `a`.`password`
FROM `tbl_authors` AS `a`, `tbl_forgotpass` AS `f`
WHERE `a`.`id` = `f`.`author_id`
AND `f`.`expiry` > '%s'
AND `f`.`token` = '%s'
LIMIT 1",
DateTimeObj::getGMT('c'),
$token
));
self::Database()->delete('tbl_forgotpass', sprintf(" `token` = '%s' ", $token));
} else {
$row = self::Database()->fetchRow(0, sprintf(
"SELECT `id`, `username`, `password`
FROM `tbl_authors`
WHERE SUBSTR(%s(CONCAT(`username`, `password`)), 1, 8) = '%s'
AND `auth_token_active` = 'yes'
LIMIT 1",
'SHA1',
$token
));
}
if ($row) {
self::$Author = AuthorManager::fetchByID($row['id']);
self::$Cookie->set('username', $row['username']);
self::$Cookie->set('pass', $row['password']);
self::Database()->update(array('last_seen' => DateTimeObj::getGMT('Y-m-d H:i:s')), 'tbl_authors', sprintf("
`id` = %d", $row['id']
));
return true;
}
return false;
} | php | public static function loginFromToken($token)
{
$token = self::Database()->cleanValue($token);
if (strlen(trim($token)) == 0) {
return false;
}
if (strlen($token) == 6 || strlen($token) == 16) {
$row = self::Database()->fetchRow(0, sprintf(
"SELECT `a`.`id`, `a`.`username`, `a`.`password`
FROM `tbl_authors` AS `a`, `tbl_forgotpass` AS `f`
WHERE `a`.`id` = `f`.`author_id`
AND `f`.`expiry` > '%s'
AND `f`.`token` = '%s'
LIMIT 1",
DateTimeObj::getGMT('c'),
$token
));
self::Database()->delete('tbl_forgotpass', sprintf(" `token` = '%s' ", $token));
} else {
$row = self::Database()->fetchRow(0, sprintf(
"SELECT `id`, `username`, `password`
FROM `tbl_authors`
WHERE SUBSTR(%s(CONCAT(`username`, `password`)), 1, 8) = '%s'
AND `auth_token_active` = 'yes'
LIMIT 1",
'SHA1',
$token
));
}
if ($row) {
self::$Author = AuthorManager::fetchByID($row['id']);
self::$Cookie->set('username', $row['username']);
self::$Cookie->set('pass', $row['password']);
self::Database()->update(array('last_seen' => DateTimeObj::getGMT('Y-m-d H:i:s')), 'tbl_authors', sprintf("
`id` = %d", $row['id']
));
return true;
}
return false;
} | [
"public",
"static",
"function",
"loginFromToken",
"(",
"$",
"token",
")",
"{",
"$",
"token",
"=",
"self",
"::",
"Database",
"(",
")",
"->",
"cleanValue",
"(",
"$",
"token",
")",
";",
"if",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"token",
")",
")",
"==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"token",
")",
"==",
"6",
"||",
"strlen",
"(",
"$",
"token",
")",
"==",
"16",
")",
"{",
"$",
"row",
"=",
"self",
"::",
"Database",
"(",
")",
"->",
"fetchRow",
"(",
"0",
",",
"sprintf",
"(",
"\"SELECT `a`.`id`, `a`.`username`, `a`.`password`\n FROM `tbl_authors` AS `a`, `tbl_forgotpass` AS `f`\n WHERE `a`.`id` = `f`.`author_id`\n AND `f`.`expiry` > '%s'\n AND `f`.`token` = '%s'\n LIMIT 1\"",
",",
"DateTimeObj",
"::",
"getGMT",
"(",
"'c'",
")",
",",
"$",
"token",
")",
")",
";",
"self",
"::",
"Database",
"(",
")",
"->",
"delete",
"(",
"'tbl_forgotpass'",
",",
"sprintf",
"(",
"\" `token` = '%s' \"",
",",
"$",
"token",
")",
")",
";",
"}",
"else",
"{",
"$",
"row",
"=",
"self",
"::",
"Database",
"(",
")",
"->",
"fetchRow",
"(",
"0",
",",
"sprintf",
"(",
"\"SELECT `id`, `username`, `password`\n FROM `tbl_authors`\n WHERE SUBSTR(%s(CONCAT(`username`, `password`)), 1, 8) = '%s'\n AND `auth_token_active` = 'yes'\n LIMIT 1\"",
",",
"'SHA1'",
",",
"$",
"token",
")",
")",
";",
"}",
"if",
"(",
"$",
"row",
")",
"{",
"self",
"::",
"$",
"Author",
"=",
"AuthorManager",
"::",
"fetchByID",
"(",
"$",
"row",
"[",
"'id'",
"]",
")",
";",
"self",
"::",
"$",
"Cookie",
"->",
"set",
"(",
"'username'",
",",
"$",
"row",
"[",
"'username'",
"]",
")",
";",
"self",
"::",
"$",
"Cookie",
"->",
"set",
"(",
"'pass'",
",",
"$",
"row",
"[",
"'password'",
"]",
")",
";",
"self",
"::",
"Database",
"(",
")",
"->",
"update",
"(",
"array",
"(",
"'last_seen'",
"=>",
"DateTimeObj",
"::",
"getGMT",
"(",
"'Y-m-d H:i:s'",
")",
")",
",",
"'tbl_authors'",
",",
"sprintf",
"(",
"\"\n `id` = %d\"",
",",
"$",
"row",
"[",
"'id'",
"]",
")",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Symphony allows Authors to login via the use of tokens instead of
a username and password. A token is derived from concatenating the
Author's username and password and applying the sha1 hash to
it, from this, a portion of the hash is used as the token. This is a useful
feature often used when setting up other Authors accounts or if an
Author forgets their password.
@param string $token
The Author token, which is a portion of the hashed string concatenation
of the Author's username and password
@throws DatabaseException
@return boolean
true if the Author is logged in, false otherwise | [
"Symphony",
"allows",
"Authors",
"to",
"login",
"via",
"the",
"use",
"of",
"tokens",
"instead",
"of",
"a",
"username",
"and",
"password",
".",
"A",
"token",
"is",
"derived",
"from",
"concatenating",
"the",
"Author",
"s",
"username",
"and",
"password",
"and",
"applying",
"the",
"sha1",
"hash",
"to",
"it",
"from",
"this",
"a",
"portion",
"of",
"the",
"hash",
"is",
"used",
"as",
"the",
"token",
".",
"This",
"is",
"a",
"useful",
"feature",
"often",
"used",
"when",
"setting",
"up",
"other",
"Authors",
"accounts",
"or",
"if",
"an",
"Author",
"forgets",
"their",
"password",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.symphony.php#L500-L545 |
symphonycms/symphony-2 | symphony/lib/core/class.symphony.php | Symphony.isLoggedIn | public static function isLoggedIn()
{
// Check to see if Symphony exists, or if we already have an Author instance.
if (is_null(self::$_instance) || self::$Author) {
return true;
}
// No author instance found, attempt to log in with the cookied credentials
return self::login(self::$Cookie->get('username'), self::$Cookie->get('pass'), true);
} | php | public static function isLoggedIn()
{
// Check to see if Symphony exists, or if we already have an Author instance.
if (is_null(self::$_instance) || self::$Author) {
return true;
}
// No author instance found, attempt to log in with the cookied credentials
return self::login(self::$Cookie->get('username'), self::$Cookie->get('pass'), true);
} | [
"public",
"static",
"function",
"isLoggedIn",
"(",
")",
"{",
"// Check to see if Symphony exists, or if we already have an Author instance.",
"if",
"(",
"is_null",
"(",
"self",
"::",
"$",
"_instance",
")",
"||",
"self",
"::",
"$",
"Author",
")",
"{",
"return",
"true",
";",
"}",
"// No author instance found, attempt to log in with the cookied credentials",
"return",
"self",
"::",
"login",
"(",
"self",
"::",
"$",
"Cookie",
"->",
"get",
"(",
"'username'",
")",
",",
"self",
"::",
"$",
"Cookie",
"->",
"get",
"(",
"'pass'",
")",
",",
"true",
")",
";",
"}"
] | This function determines whether an there is a currently logged in
Author for Symphony by using the `$Cookie`'s username
and password. If the instance is not found, they will be logged
in using the cookied credentials.
@see login()
@return boolean | [
"This",
"function",
"determines",
"whether",
"an",
"there",
"is",
"a",
"currently",
"logged",
"in",
"Author",
"for",
"Symphony",
"by",
"using",
"the",
"$Cookie",
"s",
"username",
"and",
"password",
".",
"If",
"the",
"instance",
"is",
"not",
"found",
"they",
"will",
"be",
"logged",
"in",
"using",
"the",
"cookied",
"credentials",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.symphony.php#L567-L576 |
symphonycms/symphony-2 | symphony/lib/core/class.symphony.php | Symphony.getMigrationVersion | public static function getMigrationVersion()
{
if (self::isInstallerAvailable()) {
$migrations = scandir(DOCROOT . '/install/migrations');
$migration_file = end($migrations);
$migration_class = 'migration_' . str_replace('.', '', substr($migration_file, 0, -4));
return call_user_func(array($migration_class, 'getVersion'));
}
return false;
} | php | public static function getMigrationVersion()
{
if (self::isInstallerAvailable()) {
$migrations = scandir(DOCROOT . '/install/migrations');
$migration_file = end($migrations);
$migration_class = 'migration_' . str_replace('.', '', substr($migration_file, 0, -4));
return call_user_func(array($migration_class, 'getVersion'));
}
return false;
} | [
"public",
"static",
"function",
"getMigrationVersion",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"isInstallerAvailable",
"(",
")",
")",
"{",
"$",
"migrations",
"=",
"scandir",
"(",
"DOCROOT",
".",
"'/install/migrations'",
")",
";",
"$",
"migration_file",
"=",
"end",
"(",
"$",
"migrations",
")",
";",
"$",
"migration_class",
"=",
"'migration_'",
".",
"str_replace",
"(",
"'.'",
",",
"''",
",",
"substr",
"(",
"$",
"migration_file",
",",
"0",
",",
"-",
"4",
")",
")",
";",
"return",
"call_user_func",
"(",
"array",
"(",
"$",
"migration_class",
",",
"'getVersion'",
")",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Returns the most recent version found in the `/install/migrations` folder.
Returns a version string to be used in `version_compare()` if an updater
has been found. Returns `FALSE` otherwise.
@since Symphony 2.3.1
@return string|boolean | [
"Returns",
"the",
"most",
"recent",
"version",
"found",
"in",
"the",
"/",
"install",
"/",
"migrations",
"folder",
".",
"Returns",
"a",
"version",
"string",
"to",
"be",
"used",
"in",
"version_compare",
"()",
"if",
"an",
"updater",
"has",
"been",
"found",
".",
"Returns",
"FALSE",
"otherwise",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.symphony.php#L586-L596 |
symphonycms/symphony-2 | symphony/lib/core/class.symphony.php | Symphony.isUpgradeAvailable | public static function isUpgradeAvailable()
{
if (self::isInstallerAvailable()) {
$migration_version = self::getMigrationVersion();
$current_version = Symphony::Configuration()->get('version', 'symphony');
return version_compare($current_version, $migration_version, '<');
}
return false;
} | php | public static function isUpgradeAvailable()
{
if (self::isInstallerAvailable()) {
$migration_version = self::getMigrationVersion();
$current_version = Symphony::Configuration()->get('version', 'symphony');
return version_compare($current_version, $migration_version, '<');
}
return false;
} | [
"public",
"static",
"function",
"isUpgradeAvailable",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"isInstallerAvailable",
"(",
")",
")",
"{",
"$",
"migration_version",
"=",
"self",
"::",
"getMigrationVersion",
"(",
")",
";",
"$",
"current_version",
"=",
"Symphony",
"::",
"Configuration",
"(",
")",
"->",
"get",
"(",
"'version'",
",",
"'symphony'",
")",
";",
"return",
"version_compare",
"(",
"$",
"current_version",
",",
"$",
"migration_version",
",",
"'<'",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Checks if an update is available and applicable for the current installation.
@since Symphony 2.3.1
@return boolean | [
"Checks",
"if",
"an",
"update",
"is",
"available",
"and",
"applicable",
"for",
"the",
"current",
"installation",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.symphony.php#L604-L614 |
symphonycms/symphony-2 | symphony/lib/core/class.symphony.php | Symphony.throwCustomError | public static function throwCustomError($message, $heading = 'Symphony Fatal Error', $status = Page::HTTP_STATUS_ERROR, $template = 'generic', array $additional = array())
{
GenericExceptionHandler::$enabled = true;
throw new SymphonyErrorPage($message, $heading, $template, $additional, $status);
} | php | public static function throwCustomError($message, $heading = 'Symphony Fatal Error', $status = Page::HTTP_STATUS_ERROR, $template = 'generic', array $additional = array())
{
GenericExceptionHandler::$enabled = true;
throw new SymphonyErrorPage($message, $heading, $template, $additional, $status);
} | [
"public",
"static",
"function",
"throwCustomError",
"(",
"$",
"message",
",",
"$",
"heading",
"=",
"'Symphony Fatal Error'",
",",
"$",
"status",
"=",
"Page",
"::",
"HTTP_STATUS_ERROR",
",",
"$",
"template",
"=",
"'generic'",
",",
"array",
"$",
"additional",
"=",
"array",
"(",
")",
")",
"{",
"GenericExceptionHandler",
"::",
"$",
"enabled",
"=",
"true",
";",
"throw",
"new",
"SymphonyErrorPage",
"(",
"$",
"message",
",",
"$",
"heading",
",",
"$",
"template",
",",
"$",
"additional",
",",
"$",
"status",
")",
";",
"}"
] | A wrapper for throwing a new Symphony Error page.
This methods sets the `GenericExceptionHandler::$enabled` value to `true`.
@see core.SymphonyErrorPage
@param string|XMLElement $message
A description for this error, which can be provided as a string
or as an XMLElement.
@param string $heading
A heading for the error page
@param integer $status
Properly sets the HTTP status code for the response. Defaults to
`Page::HTTP_STATUS_ERROR`. Use `Page::HTTP_STATUS_XXX` to set this value.
@param string $template
A string for the error page template to use, defaults to 'generic'. This
can be the name of any template file in the `TEMPLATES` directory.
A template using the naming convention of `tpl.*.php`.
@param array $additional
Allows custom information to be passed to the Symphony Error Page
that the template may want to expose, such as custom Headers etc.
@throws SymphonyErrorPage | [
"A",
"wrapper",
"for",
"throwing",
"a",
"new",
"Symphony",
"Error",
"page",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.symphony.php#L650-L654 |
symphonycms/symphony-2 | symphony/lib/core/class.symphony.php | Symphony.getPageNamespace | public static function getPageNamespace()
{
if (self::$namespace !== false) {
return self::$namespace;
}
$page = getCurrentPage();
if (!is_null($page)) {
$page = trim($page, '/');
}
if (substr($page, 0, 7) == 'publish') {
self::$namespace = '/publish';
} elseif (empty($page) && isset($_REQUEST['mode'])) {
self::$namespace = '/login';
} elseif (empty($page)) {
self::$namespace = null;
} else {
$bits = explode('/', $page);
if ($bits[0] == 'extension') {
self::$namespace = sprintf('/%s/%s/%s', $bits[0], $bits[1], $bits[2]);
} else {
self::$namespace = sprintf('/%s/%s', $bits[0], isset($bits[1]) ? $bits[1] : '');
}
}
return self::$namespace;
} | php | public static function getPageNamespace()
{
if (self::$namespace !== false) {
return self::$namespace;
}
$page = getCurrentPage();
if (!is_null($page)) {
$page = trim($page, '/');
}
if (substr($page, 0, 7) == 'publish') {
self::$namespace = '/publish';
} elseif (empty($page) && isset($_REQUEST['mode'])) {
self::$namespace = '/login';
} elseif (empty($page)) {
self::$namespace = null;
} else {
$bits = explode('/', $page);
if ($bits[0] == 'extension') {
self::$namespace = sprintf('/%s/%s/%s', $bits[0], $bits[1], $bits[2]);
} else {
self::$namespace = sprintf('/%s/%s', $bits[0], isset($bits[1]) ? $bits[1] : '');
}
}
return self::$namespace;
} | [
"public",
"static",
"function",
"getPageNamespace",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"namespace",
"!==",
"false",
")",
"{",
"return",
"self",
"::",
"$",
"namespace",
";",
"}",
"$",
"page",
"=",
"getCurrentPage",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"page",
")",
")",
"{",
"$",
"page",
"=",
"trim",
"(",
"$",
"page",
",",
"'/'",
")",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"page",
",",
"0",
",",
"7",
")",
"==",
"'publish'",
")",
"{",
"self",
"::",
"$",
"namespace",
"=",
"'/publish'",
";",
"}",
"elseif",
"(",
"empty",
"(",
"$",
"page",
")",
"&&",
"isset",
"(",
"$",
"_REQUEST",
"[",
"'mode'",
"]",
")",
")",
"{",
"self",
"::",
"$",
"namespace",
"=",
"'/login'",
";",
"}",
"elseif",
"(",
"empty",
"(",
"$",
"page",
")",
")",
"{",
"self",
"::",
"$",
"namespace",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"bits",
"=",
"explode",
"(",
"'/'",
",",
"$",
"page",
")",
";",
"if",
"(",
"$",
"bits",
"[",
"0",
"]",
"==",
"'extension'",
")",
"{",
"self",
"::",
"$",
"namespace",
"=",
"sprintf",
"(",
"'/%s/%s/%s'",
",",
"$",
"bits",
"[",
"0",
"]",
",",
"$",
"bits",
"[",
"1",
"]",
",",
"$",
"bits",
"[",
"2",
"]",
")",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"namespace",
"=",
"sprintf",
"(",
"'/%s/%s'",
",",
"$",
"bits",
"[",
"0",
"]",
",",
"isset",
"(",
"$",
"bits",
"[",
"1",
"]",
")",
"?",
"$",
"bits",
"[",
"1",
"]",
":",
"''",
")",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"namespace",
";",
"}"
] | Returns the page namespace based on the current URL.
A few examples:
/login
/publish
/blueprints/datasources
[...]
/extension/$extension_name/$page_name
This method is especially useful in couple with the translation function.
@see toolkit#__()
@return string
The page namespace, without any action string (e.g. "new", "saved") or
any value that depends upon the single setup (e.g. the section handle in
/publish/$handle) | [
"Returns",
"the",
"page",
"namespace",
"based",
"on",
"the",
"current",
"URL",
".",
"A",
"few",
"examples",
":"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.symphony.php#L702-L731 |
symphonycms/symphony-2 | symphony/lib/core/class.symphony.php | SymphonyErrorPageHandler.render | public static function render($e)
{
// Validate the type, resolve to a 404 if not valid
if (!static::isValidThrowable($e)) {
$e = new FrontendPageNotFoundException();
}
if ($e->getTemplate() === false) {
Page::renderStatusCode($e->getHttpStatusCode());
if (isset($e->getAdditional()->header)) {
header($e->getAdditional()->header);
}
echo '<h1>Symphony Fatal Error</h1><p>'.$e->getMessage().'</p>';
exit;
}
include $e->getTemplate();
} | php | public static function render($e)
{
// Validate the type, resolve to a 404 if not valid
if (!static::isValidThrowable($e)) {
$e = new FrontendPageNotFoundException();
}
if ($e->getTemplate() === false) {
Page::renderStatusCode($e->getHttpStatusCode());
if (isset($e->getAdditional()->header)) {
header($e->getAdditional()->header);
}
echo '<h1>Symphony Fatal Error</h1><p>'.$e->getMessage().'</p>';
exit;
}
include $e->getTemplate();
} | [
"public",
"static",
"function",
"render",
"(",
"$",
"e",
")",
"{",
"// Validate the type, resolve to a 404 if not valid",
"if",
"(",
"!",
"static",
"::",
"isValidThrowable",
"(",
"$",
"e",
")",
")",
"{",
"$",
"e",
"=",
"new",
"FrontendPageNotFoundException",
"(",
")",
";",
"}",
"if",
"(",
"$",
"e",
"->",
"getTemplate",
"(",
")",
"===",
"false",
")",
"{",
"Page",
"::",
"renderStatusCode",
"(",
"$",
"e",
"->",
"getHttpStatusCode",
"(",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"e",
"->",
"getAdditional",
"(",
")",
"->",
"header",
")",
")",
"{",
"header",
"(",
"$",
"e",
"->",
"getAdditional",
"(",
")",
"->",
"header",
")",
";",
"}",
"echo",
"'<h1>Symphony Fatal Error</h1><p>'",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"'</p>'",
";",
"exit",
";",
"}",
"include",
"$",
"e",
"->",
"getTemplate",
"(",
")",
";",
"}"
] | The render function will take a `SymphonyErrorPage` exception and
output a HTML page. This function first checks to see if their is a custom
template for this exception otherwise it reverts to using the default
`usererror.generic.php`
@param Throwable $e
The Throwable object
@return string
An HTML string | [
"The",
"render",
"function",
"will",
"take",
"a",
"SymphonyErrorPage",
"exception",
"and",
"output",
"a",
"HTML",
"page",
".",
"This",
"function",
"first",
"checks",
"to",
"see",
"if",
"their",
"is",
"a",
"custom",
"template",
"for",
"this",
"exception",
"otherwise",
"it",
"reverts",
"to",
"using",
"the",
"default",
"usererror",
".",
"generic",
".",
"php"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.symphony.php#L752-L771 |
symphonycms/symphony-2 | symphony/lib/core/class.symphony.php | SymphonyErrorPage.getTemplate | public function getTemplate()
{
$format = '%s/usererror.%s.php';
if (file_exists($template = sprintf($format, WORKSPACE . '/template', $this->_template))) {
return $template;
} elseif (file_exists($template = sprintf($format, TEMPLATE, $this->_template))) {
return $template;
} else {
return false;
}
} | php | public function getTemplate()
{
$format = '%s/usererror.%s.php';
if (file_exists($template = sprintf($format, WORKSPACE . '/template', $this->_template))) {
return $template;
} elseif (file_exists($template = sprintf($format, TEMPLATE, $this->_template))) {
return $template;
} else {
return false;
}
} | [
"public",
"function",
"getTemplate",
"(",
")",
"{",
"$",
"format",
"=",
"'%s/usererror.%s.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"template",
"=",
"sprintf",
"(",
"$",
"format",
",",
"WORKSPACE",
".",
"'/template'",
",",
"$",
"this",
"->",
"_template",
")",
")",
")",
"{",
"return",
"$",
"template",
";",
"}",
"elseif",
"(",
"file_exists",
"(",
"$",
"template",
"=",
"sprintf",
"(",
"$",
"format",
",",
"TEMPLATE",
",",
"$",
"this",
"->",
"_template",
")",
")",
")",
"{",
"return",
"$",
"template",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Returns the path to the current template by looking at the
`WORKSPACE/template/` directory, then at the `TEMPLATES`
directory for the convention `usererror.*.php`. If the template
is not found, `false` is returned
@since Symphony 2.3
@return string|false
String, which is the path to the template if the template is found,
false otherwise | [
"Returns",
"the",
"path",
"to",
"the",
"current",
"template",
"by",
"looking",
"at",
"the",
"WORKSPACE",
"/",
"template",
"/",
"directory",
"then",
"at",
"the",
"TEMPLATES",
"directory",
"for",
"the",
"convention",
"usererror",
".",
"*",
".",
"php",
".",
"If",
"the",
"template",
"is",
"not",
"found",
"false",
"is",
"returned"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.symphony.php#L905-L916 |
symphonycms/symphony-2 | symphony/lib/core/class.symphony.php | DatabaseExceptionHandler.render | public static function render($e)
{
// Validate the type, resolve to a 404 if not valid
if (!static::isValidThrowable($e)) {
$e = new FrontendPageNotFoundException();
}
$trace = $queries = null;
foreach ($e->getTrace() as $t) {
$trace .= sprintf(
'<li><code><em>[%s:%d]</em></code></li><li><code>    %s%s%s();</code></li>',
$t['file'],
$t['line'],
(isset($t['class']) ? $t['class'] : null),
(isset($t['type']) ? $t['type'] : null),
$t['function']
);
}
if (is_object(Symphony::Database())) {
$debug = Symphony::Database()->debug();
if (!empty($debug)) {
foreach ($debug as $query) {
$queries .= sprintf(
'<li><em>[%01.4f]</em><code> %s;</code> </li>',
(isset($query['execution_time']) ? $query['execution_time'] : null),
htmlspecialchars($query['query'])
);
}
}
}
$html = sprintf(
file_get_contents(self::getTemplate('fatalerror.database')),
$e->getDatabaseErrorMessage(),
$e->getQuery(),
$trace,
$queries
);
$html = str_replace('{ASSETS_URL}', ASSETS_URL, $html);
$html = str_replace('{SYMPHONY_URL}', SYMPHONY_URL, $html);
$html = str_replace('{URL}', URL, $html);
return $html;
} | php | public static function render($e)
{
// Validate the type, resolve to a 404 if not valid
if (!static::isValidThrowable($e)) {
$e = new FrontendPageNotFoundException();
}
$trace = $queries = null;
foreach ($e->getTrace() as $t) {
$trace .= sprintf(
'<li><code><em>[%s:%d]</em></code></li><li><code>    %s%s%s();</code></li>',
$t['file'],
$t['line'],
(isset($t['class']) ? $t['class'] : null),
(isset($t['type']) ? $t['type'] : null),
$t['function']
);
}
if (is_object(Symphony::Database())) {
$debug = Symphony::Database()->debug();
if (!empty($debug)) {
foreach ($debug as $query) {
$queries .= sprintf(
'<li><em>[%01.4f]</em><code> %s;</code> </li>',
(isset($query['execution_time']) ? $query['execution_time'] : null),
htmlspecialchars($query['query'])
);
}
}
}
$html = sprintf(
file_get_contents(self::getTemplate('fatalerror.database')),
$e->getDatabaseErrorMessage(),
$e->getQuery(),
$trace,
$queries
);
$html = str_replace('{ASSETS_URL}', ASSETS_URL, $html);
$html = str_replace('{SYMPHONY_URL}', SYMPHONY_URL, $html);
$html = str_replace('{URL}', URL, $html);
return $html;
} | [
"public",
"static",
"function",
"render",
"(",
"$",
"e",
")",
"{",
"// Validate the type, resolve to a 404 if not valid",
"if",
"(",
"!",
"static",
"::",
"isValidThrowable",
"(",
"$",
"e",
")",
")",
"{",
"$",
"e",
"=",
"new",
"FrontendPageNotFoundException",
"(",
")",
";",
"}",
"$",
"trace",
"=",
"$",
"queries",
"=",
"null",
";",
"foreach",
"(",
"$",
"e",
"->",
"getTrace",
"(",
")",
"as",
"$",
"t",
")",
"{",
"$",
"trace",
".=",
"sprintf",
"(",
"'<li><code><em>[%s:%d]</em></code></li><li><code>    %s%s%s();</code></li>'",
",",
"$",
"t",
"[",
"'file'",
"]",
",",
"$",
"t",
"[",
"'line'",
"]",
",",
"(",
"isset",
"(",
"$",
"t",
"[",
"'class'",
"]",
")",
"?",
"$",
"t",
"[",
"'class'",
"]",
":",
"null",
")",
",",
"(",
"isset",
"(",
"$",
"t",
"[",
"'type'",
"]",
")",
"?",
"$",
"t",
"[",
"'type'",
"]",
":",
"null",
")",
",",
"$",
"t",
"[",
"'function'",
"]",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"Symphony",
"::",
"Database",
"(",
")",
")",
")",
"{",
"$",
"debug",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"debug",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"debug",
")",
")",
"{",
"foreach",
"(",
"$",
"debug",
"as",
"$",
"query",
")",
"{",
"$",
"queries",
".=",
"sprintf",
"(",
"'<li><em>[%01.4f]</em><code> %s;</code> </li>'",
",",
"(",
"isset",
"(",
"$",
"query",
"[",
"'execution_time'",
"]",
")",
"?",
"$",
"query",
"[",
"'execution_time'",
"]",
":",
"null",
")",
",",
"htmlspecialchars",
"(",
"$",
"query",
"[",
"'query'",
"]",
")",
")",
";",
"}",
"}",
"}",
"$",
"html",
"=",
"sprintf",
"(",
"file_get_contents",
"(",
"self",
"::",
"getTemplate",
"(",
"'fatalerror.database'",
")",
")",
",",
"$",
"e",
"->",
"getDatabaseErrorMessage",
"(",
")",
",",
"$",
"e",
"->",
"getQuery",
"(",
")",
",",
"$",
"trace",
",",
"$",
"queries",
")",
";",
"$",
"html",
"=",
"str_replace",
"(",
"'{ASSETS_URL}'",
",",
"ASSETS_URL",
",",
"$",
"html",
")",
";",
"$",
"html",
"=",
"str_replace",
"(",
"'{SYMPHONY_URL}'",
",",
"SYMPHONY_URL",
",",
"$",
"html",
")",
";",
"$",
"html",
"=",
"str_replace",
"(",
"'{URL}'",
",",
"URL",
",",
"$",
"html",
")",
";",
"return",
"$",
"html",
";",
"}"
] | The render function will take a `DatabaseException` and output a
HTML page.
@param Throwable $e
The Throwable object
@return string
An HTML string | [
"The",
"render",
"function",
"will",
"take",
"a",
"DatabaseException",
"and",
"output",
"a",
"HTML",
"page",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/core/class.symphony.php#L947-L994 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.devkit.php | DevKit.buildIncludes | protected function buildIncludes()
{
$this->addHeaderToPage('Content-Type', 'text/html; charset=UTF-8');
$this->Html->setElementStyle('html');
$this->Html->setDTD('<!DOCTYPE html>');
$this->Html->setAttribute('lang', Lang::get());
$this->addElementToHead(new XMLElement(
'meta',
null,
array(
'http-equiv' => 'Content-Type',
'content' => 'text/html; charset=UTF-8'
)
));
$this->addStylesheetToHead(ASSETS_URL . '/css/devkit.min.css', 'screen', null, false);
} | php | protected function buildIncludes()
{
$this->addHeaderToPage('Content-Type', 'text/html; charset=UTF-8');
$this->Html->setElementStyle('html');
$this->Html->setDTD('<!DOCTYPE html>');
$this->Html->setAttribute('lang', Lang::get());
$this->addElementToHead(new XMLElement(
'meta',
null,
array(
'http-equiv' => 'Content-Type',
'content' => 'text/html; charset=UTF-8'
)
));
$this->addStylesheetToHead(ASSETS_URL . '/css/devkit.min.css', 'screen', null, false);
} | [
"protected",
"function",
"buildIncludes",
"(",
")",
"{",
"$",
"this",
"->",
"addHeaderToPage",
"(",
"'Content-Type'",
",",
"'text/html; charset=UTF-8'",
")",
";",
"$",
"this",
"->",
"Html",
"->",
"setElementStyle",
"(",
"'html'",
")",
";",
"$",
"this",
"->",
"Html",
"->",
"setDTD",
"(",
"'<!DOCTYPE html>'",
")",
";",
"$",
"this",
"->",
"Html",
"->",
"setAttribute",
"(",
"'lang'",
",",
"Lang",
"::",
"get",
"(",
")",
")",
";",
"$",
"this",
"->",
"addElementToHead",
"(",
"new",
"XMLElement",
"(",
"'meta'",
",",
"null",
",",
"array",
"(",
"'http-equiv'",
"=>",
"'Content-Type'",
",",
"'content'",
"=>",
"'text/html; charset=UTF-8'",
")",
")",
")",
";",
"$",
"this",
"->",
"addStylesheetToHead",
"(",
"ASSETS_URL",
".",
"'/css/devkit.min.css'",
",",
"'screen'",
",",
"null",
",",
"false",
")",
";",
"}"
] | Builds the Includes for a Devkit and sets the Content Type
to be text/html. The default Symphony devkit stylesheet
is the only include. The default doctype is enables HTML5 | [
"Builds",
"the",
"Includes",
"for",
"a",
"Devkit",
"and",
"sets",
"the",
"Content",
"Type",
"to",
"be",
"text",
"/",
"html",
".",
"The",
"default",
"Symphony",
"devkit",
"stylesheet",
"is",
"the",
"only",
"include",
".",
"The",
"default",
"doctype",
"is",
"enables",
"HTML5"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.devkit.php#L61-L77 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.devkit.php | DevKit.buildHeader | protected function buildHeader(XMLElement $wrapper)
{
$this->setTitle(__(
'%1$s – %2$s – %3$s',
array(
$this->_pagedata['title'],
__($this->_title),
__('Symphony')
)
));
$h1 = new XMLElement('h1');
$h1->appendChild(Widget::Anchor($this->_pagedata['title'], ($this->_query_string ? '?' . trim(html_entity_decode($this->_query_string), '&') : '.')));
$wrapper->appendChild($h1);
} | php | protected function buildHeader(XMLElement $wrapper)
{
$this->setTitle(__(
'%1$s – %2$s – %3$s',
array(
$this->_pagedata['title'],
__($this->_title),
__('Symphony')
)
));
$h1 = new XMLElement('h1');
$h1->appendChild(Widget::Anchor($this->_pagedata['title'], ($this->_query_string ? '?' . trim(html_entity_decode($this->_query_string), '&') : '.')));
$wrapper->appendChild($h1);
} | [
"protected",
"function",
"buildHeader",
"(",
"XMLElement",
"$",
"wrapper",
")",
"{",
"$",
"this",
"->",
"setTitle",
"(",
"__",
"(",
"'%1$s – %2$s – %3$s'",
",",
"array",
"(",
"$",
"this",
"->",
"_pagedata",
"[",
"'title'",
"]",
",",
"__",
"(",
"$",
"this",
"->",
"_title",
")",
",",
"__",
"(",
"'Symphony'",
")",
")",
")",
")",
";",
"$",
"h1",
"=",
"new",
"XMLElement",
"(",
"'h1'",
")",
";",
"$",
"h1",
"->",
"appendChild",
"(",
"Widget",
"::",
"Anchor",
"(",
"$",
"this",
"->",
"_pagedata",
"[",
"'title'",
"]",
",",
"(",
"$",
"this",
"->",
"_query_string",
"?",
"'?'",
".",
"trim",
"(",
"html_entity_decode",
"(",
"$",
"this",
"->",
"_query_string",
")",
",",
"'&'",
")",
":",
"'.'",
")",
")",
")",
";",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"h1",
")",
";",
"}"
] | This function will build the `<title>` element and create a default
`<h1>` with an anchor to this query string
@param XMLElement $wrapper
The parent `XMLElement` to add the header to
@throws InvalidArgumentException | [
"This",
"function",
"will",
"build",
"the",
"<title",
">",
"element",
"and",
"create",
"a",
"default",
"<h1",
">",
"with",
"an",
"anchor",
"to",
"this",
"query",
"string"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.devkit.php#L87-L102 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.devkit.php | DevKit.buildNavigation | protected function buildNavigation(XMLElement $wrapper)
{
$xml = new DOMDocument();
$xml->preserveWhiteSpace = false;
$xml->formatOutput = true;
$xml->load(ASSETS . '/xml/devkit_navigation.xml');
$root = $xml->documentElement;
$list = new XMLElement('ul');
$list->setAttribute('id', 'navigation');
// Add edit link:
$item = new XMLElement('li');
$item->appendChild(Widget::Anchor(
__('Edit'),
SYMPHONY_URL . '/blueprints/pages/edit/' . $this->_pagedata['id'] . '/'
));
$list->appendChild($item);
// Translate navigation names:
if ($root->hasChildNodes()) {
foreach ($root->childNodes as $item) {
if ($item->tagName == 'item') {
$item->setAttribute('name', __($item->getAttribute('name')));
}
}
}
/**
* Allow navigation XML to be manipulated before it is rendered.
*
* @delegate ManipulateDevKitNavigation
* @param string $context
* '/frontend/'
* @param DOMDocument $xml
*/
Symphony::ExtensionManager()->notifyMembers(
'ManipulateDevKitNavigation',
'/frontend/',
array(
'xml' => $xml
)
);
if ($root->hasChildNodes()) {
foreach ($root->childNodes as $node) {
if ($node->getAttribute('active') === 'yes') {
$item = new XMLElement('li', $node->getAttribute('name'));
} else {
$item = new XMLElement('li');
$item->appendChild(Widget::Anchor(
$node->getAttribute('name'),
'?' . $node->getAttribute('handle') . $this->_query_string
));
}
$list->appendChild($item);
}
}
$wrapper->appendChild($list);
} | php | protected function buildNavigation(XMLElement $wrapper)
{
$xml = new DOMDocument();
$xml->preserveWhiteSpace = false;
$xml->formatOutput = true;
$xml->load(ASSETS . '/xml/devkit_navigation.xml');
$root = $xml->documentElement;
$list = new XMLElement('ul');
$list->setAttribute('id', 'navigation');
// Add edit link:
$item = new XMLElement('li');
$item->appendChild(Widget::Anchor(
__('Edit'),
SYMPHONY_URL . '/blueprints/pages/edit/' . $this->_pagedata['id'] . '/'
));
$list->appendChild($item);
// Translate navigation names:
if ($root->hasChildNodes()) {
foreach ($root->childNodes as $item) {
if ($item->tagName == 'item') {
$item->setAttribute('name', __($item->getAttribute('name')));
}
}
}
/**
* Allow navigation XML to be manipulated before it is rendered.
*
* @delegate ManipulateDevKitNavigation
* @param string $context
* '/frontend/'
* @param DOMDocument $xml
*/
Symphony::ExtensionManager()->notifyMembers(
'ManipulateDevKitNavigation',
'/frontend/',
array(
'xml' => $xml
)
);
if ($root->hasChildNodes()) {
foreach ($root->childNodes as $node) {
if ($node->getAttribute('active') === 'yes') {
$item = new XMLElement('li', $node->getAttribute('name'));
} else {
$item = new XMLElement('li');
$item->appendChild(Widget::Anchor(
$node->getAttribute('name'),
'?' . $node->getAttribute('handle') . $this->_query_string
));
}
$list->appendChild($item);
}
}
$wrapper->appendChild($list);
} | [
"protected",
"function",
"buildNavigation",
"(",
"XMLElement",
"$",
"wrapper",
")",
"{",
"$",
"xml",
"=",
"new",
"DOMDocument",
"(",
")",
";",
"$",
"xml",
"->",
"preserveWhiteSpace",
"=",
"false",
";",
"$",
"xml",
"->",
"formatOutput",
"=",
"true",
";",
"$",
"xml",
"->",
"load",
"(",
"ASSETS",
".",
"'/xml/devkit_navigation.xml'",
")",
";",
"$",
"root",
"=",
"$",
"xml",
"->",
"documentElement",
";",
"$",
"list",
"=",
"new",
"XMLElement",
"(",
"'ul'",
")",
";",
"$",
"list",
"->",
"setAttribute",
"(",
"'id'",
",",
"'navigation'",
")",
";",
"// Add edit link:",
"$",
"item",
"=",
"new",
"XMLElement",
"(",
"'li'",
")",
";",
"$",
"item",
"->",
"appendChild",
"(",
"Widget",
"::",
"Anchor",
"(",
"__",
"(",
"'Edit'",
")",
",",
"SYMPHONY_URL",
".",
"'/blueprints/pages/edit/'",
".",
"$",
"this",
"->",
"_pagedata",
"[",
"'id'",
"]",
".",
"'/'",
")",
")",
";",
"$",
"list",
"->",
"appendChild",
"(",
"$",
"item",
")",
";",
"// Translate navigation names:",
"if",
"(",
"$",
"root",
"->",
"hasChildNodes",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"root",
"->",
"childNodes",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"tagName",
"==",
"'item'",
")",
"{",
"$",
"item",
"->",
"setAttribute",
"(",
"'name'",
",",
"__",
"(",
"$",
"item",
"->",
"getAttribute",
"(",
"'name'",
")",
")",
")",
";",
"}",
"}",
"}",
"/**\n * Allow navigation XML to be manipulated before it is rendered.\n *\n * @delegate ManipulateDevKitNavigation\n * @param string $context\n * '/frontend/'\n * @param DOMDocument $xml\n */",
"Symphony",
"::",
"ExtensionManager",
"(",
")",
"->",
"notifyMembers",
"(",
"'ManipulateDevKitNavigation'",
",",
"'/frontend/'",
",",
"array",
"(",
"'xml'",
"=>",
"$",
"xml",
")",
")",
";",
"if",
"(",
"$",
"root",
"->",
"hasChildNodes",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"root",
"->",
"childNodes",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"->",
"getAttribute",
"(",
"'active'",
")",
"===",
"'yes'",
")",
"{",
"$",
"item",
"=",
"new",
"XMLElement",
"(",
"'li'",
",",
"$",
"node",
"->",
"getAttribute",
"(",
"'name'",
")",
")",
";",
"}",
"else",
"{",
"$",
"item",
"=",
"new",
"XMLElement",
"(",
"'li'",
")",
";",
"$",
"item",
"->",
"appendChild",
"(",
"Widget",
"::",
"Anchor",
"(",
"$",
"node",
"->",
"getAttribute",
"(",
"'name'",
")",
",",
"'?'",
".",
"$",
"node",
"->",
"getAttribute",
"(",
"'handle'",
")",
".",
"$",
"this",
"->",
"_query_string",
")",
")",
";",
"}",
"$",
"list",
"->",
"appendChild",
"(",
"$",
"item",
")",
";",
"}",
"}",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"list",
")",
";",
"}"
] | Using DOMDocument, construct the Navigation list using the `devkit_navigation.xml`
file in the `ASSETS` folder. The default navigation file is an empty `<navigation>`
element. The `ManipulateDevKitNavigation` delegate allows extensions
to inject items into the navigation. The navigation is build by iterating over `<item>`
elements added. The idea is that all Devkit's can be accessed using the Navigation.
@uses ManipulateDevKitNavigation
@param XMLElement $wrapper
The parent XMLElement to add the navigation to
@throws InvalidArgumentException | [
"Using",
"DOMDocument",
"construct",
"the",
"Navigation",
"list",
"using",
"the",
"devkit_navigation",
".",
"xml",
"file",
"in",
"the",
"ASSETS",
"folder",
".",
"The",
"default",
"navigation",
"file",
"is",
"an",
"empty",
"<navigation",
">",
"element",
".",
"The",
"ManipulateDevKitNavigation",
"delegate",
"allows",
"extensions",
"to",
"inject",
"items",
"into",
"the",
"navigation",
".",
"The",
"navigation",
"is",
"build",
"by",
"iterating",
"over",
"<item",
">",
"elements",
"added",
".",
"The",
"idea",
"is",
"that",
"all",
"Devkit",
"s",
"can",
"be",
"accessed",
"using",
"the",
"Navigation",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.devkit.php#L116-L176 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.devkit.php | DevKit.prepare | public function prepare(XSLTPage $page, array $pagedata, $xml, array $param, $output)
{
$this->_page = $page;
$this->_pagedata = $pagedata;
$this->_xml = $xml;
$this->_param = $param;
$this->_output = $output;
if (is_null($this->_title)) {
$this->_title = __('Utility');
}
} | php | public function prepare(XSLTPage $page, array $pagedata, $xml, array $param, $output)
{
$this->_page = $page;
$this->_pagedata = $pagedata;
$this->_xml = $xml;
$this->_param = $param;
$this->_output = $output;
if (is_null($this->_title)) {
$this->_title = __('Utility');
}
} | [
"public",
"function",
"prepare",
"(",
"XSLTPage",
"$",
"page",
",",
"array",
"$",
"pagedata",
",",
"$",
"xml",
",",
"array",
"$",
"param",
",",
"$",
"output",
")",
"{",
"$",
"this",
"->",
"_page",
"=",
"$",
"page",
";",
"$",
"this",
"->",
"_pagedata",
"=",
"$",
"pagedata",
";",
"$",
"this",
"->",
"_xml",
"=",
"$",
"xml",
";",
"$",
"this",
"->",
"_param",
"=",
"$",
"param",
";",
"$",
"this",
"->",
"_output",
"=",
"$",
"output",
";",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"_title",
")",
")",
"{",
"$",
"this",
"->",
"_title",
"=",
"__",
"(",
"'Utility'",
")",
";",
"}",
"}"
] | The prepare function acts a pseudo constructor for the Devkit,
setting some base variables with the given parameters
@param XSLTPage $page
An instance of the XSLTPage, usually FrontendPage
@param array $pagedata
An associative array of the details of the Page that is
being 'Devkitted'. The majority of this information is from
tbl_pages table.
@param string $xml
The XML of the page that the XSLT will be applied to, this includes
any datasource results.
@param array $param
An array of the page parameters, including those provided by
datasources.
@param string $output
The resulting Page after it has been transformed, as a string. This is
similar to what you would see if you 'view-sourced' a page. | [
"The",
"prepare",
"function",
"acts",
"a",
"pseudo",
"constructor",
"for",
"the",
"Devkit",
"setting",
"some",
"base",
"variables",
"with",
"the",
"given",
"parameters"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.devkit.php#L250-L261 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.devkit.php | DevKit.build | public function build()
{
$this->buildIncludes();
$this->_view = General::sanitize($this->_view);
$header = new XMLElement('div');
$header->setAttribute('id', 'header');
$jump = new XMLElement('div');
$jump->setAttribute('id', 'jump');
$content = new XMLElement('div');
$content->setAttribute('id', 'content');
$this->buildHeader($header);
$this->buildNavigation($header);
$this->buildJump($jump);
$header->appendChild($jump);
$this->Body->appendChild($header);
$this->buildContent($content);
$this->Body->appendChild($content);
return $this->generate();
} | php | public function build()
{
$this->buildIncludes();
$this->_view = General::sanitize($this->_view);
$header = new XMLElement('div');
$header->setAttribute('id', 'header');
$jump = new XMLElement('div');
$jump->setAttribute('id', 'jump');
$content = new XMLElement('div');
$content->setAttribute('id', 'content');
$this->buildHeader($header);
$this->buildNavigation($header);
$this->buildJump($jump);
$header->appendChild($jump);
$this->Body->appendChild($header);
$this->buildContent($content);
$this->Body->appendChild($content);
return $this->generate();
} | [
"public",
"function",
"build",
"(",
")",
"{",
"$",
"this",
"->",
"buildIncludes",
"(",
")",
";",
"$",
"this",
"->",
"_view",
"=",
"General",
"::",
"sanitize",
"(",
"$",
"this",
"->",
"_view",
")",
";",
"$",
"header",
"=",
"new",
"XMLElement",
"(",
"'div'",
")",
";",
"$",
"header",
"->",
"setAttribute",
"(",
"'id'",
",",
"'header'",
")",
";",
"$",
"jump",
"=",
"new",
"XMLElement",
"(",
"'div'",
")",
";",
"$",
"jump",
"->",
"setAttribute",
"(",
"'id'",
",",
"'jump'",
")",
";",
"$",
"content",
"=",
"new",
"XMLElement",
"(",
"'div'",
")",
";",
"$",
"content",
"->",
"setAttribute",
"(",
"'id'",
",",
"'content'",
")",
";",
"$",
"this",
"->",
"buildHeader",
"(",
"$",
"header",
")",
";",
"$",
"this",
"->",
"buildNavigation",
"(",
"$",
"header",
")",
";",
"$",
"this",
"->",
"buildJump",
"(",
"$",
"jump",
")",
";",
"$",
"header",
"->",
"appendChild",
"(",
"$",
"jump",
")",
";",
"$",
"this",
"->",
"Body",
"->",
"appendChild",
"(",
"$",
"header",
")",
";",
"$",
"this",
"->",
"buildContent",
"(",
"$",
"content",
")",
";",
"$",
"this",
"->",
"Body",
"->",
"appendChild",
"(",
"$",
"content",
")",
";",
"return",
"$",
"this",
"->",
"generate",
"(",
")",
";",
"}"
] | Called when page is generated, this function calls each of the other
other functions in this page to build the Header, the Navigation,
the Jump menu and finally the content. This function calls it's parent
generate function
@see toolkit.HTMLPage#generate()
@throws InvalidArgumentException
@return string | [
"Called",
"when",
"page",
"is",
"generated",
"this",
"function",
"calls",
"each",
"of",
"the",
"other",
"other",
"functions",
"in",
"this",
"page",
"to",
"build",
"the",
"Header",
"the",
"Navigation",
"the",
"Jump",
"menu",
"and",
"finally",
"the",
"content",
".",
"This",
"function",
"calls",
"it",
"s",
"parent",
"generate",
"function"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.devkit.php#L273-L297 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xsltpage.php | XSLTPage.setXML | public function setXML($xml, $isFile = false)
{
$this->_xml = ($isFile ? file_get_contents($xml) : $xml);
} | php | public function setXML($xml, $isFile = false)
{
$this->_xml = ($isFile ? file_get_contents($xml) : $xml);
} | [
"public",
"function",
"setXML",
"(",
"$",
"xml",
",",
"$",
"isFile",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"_xml",
"=",
"(",
"$",
"isFile",
"?",
"file_get_contents",
"(",
"$",
"xml",
")",
":",
"$",
"xml",
")",
";",
"}"
] | Setter for `$this->_xml`, can optionally load the XML from a file.
@param string|XMLElement $xml
The XML for this XSLT page
@param boolean $isFile
If set to true, the XML will be loaded from a file. It is false by default | [
"Setter",
"for",
"$this",
"-",
">",
"_xml",
"can",
"optionally",
"load",
"the",
"XML",
"from",
"a",
"file",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xsltpage.php#L68-L71 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xsltpage.php | XSLTPage.setXSL | public function setXSL($xsl, $isFile = false)
{
$this->_xsl = ($isFile ? file_get_contents($xsl) : $xsl);
} | php | public function setXSL($xsl, $isFile = false)
{
$this->_xsl = ($isFile ? file_get_contents($xsl) : $xsl);
} | [
"public",
"function",
"setXSL",
"(",
"$",
"xsl",
",",
"$",
"isFile",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"_xsl",
"=",
"(",
"$",
"isFile",
"?",
"file_get_contents",
"(",
"$",
"xsl",
")",
":",
"$",
"xsl",
")",
";",
"}"
] | Setter for `$this->_xsl`, can optionally load the XSLT from a file.
@param string $xsl
The XSLT for this XSLT page
@param boolean $isFile
If set to true, the XSLT will be loaded from a file. It is false by default | [
"Setter",
"for",
"$this",
"-",
">",
"_xsl",
"can",
"optionally",
"load",
"the",
"XSLT",
"from",
"a",
"file",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xsltpage.php#L91-L94 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xsltpage.php | XSLTPage.registerPHPFunction | public function registerPHPFunction($function)
{
if (is_array($function)) {
$this->_registered_php_functions = array_unique(
array_merge($this->_registered_php_functions, $function)
);
} else {
$this->_registered_php_functions[] = $function;
}
} | php | public function registerPHPFunction($function)
{
if (is_array($function)) {
$this->_registered_php_functions = array_unique(
array_merge($this->_registered_php_functions, $function)
);
} else {
$this->_registered_php_functions[] = $function;
}
} | [
"public",
"function",
"registerPHPFunction",
"(",
"$",
"function",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"function",
")",
")",
"{",
"$",
"this",
"->",
"_registered_php_functions",
"=",
"array_unique",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"_registered_php_functions",
",",
"$",
"function",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_registered_php_functions",
"[",
"]",
"=",
"$",
"function",
";",
"}",
"}"
] | Allows the registration of PHP functions to be used on the Frontend
by passing the function name or an array of function names
@param mixed $function
Either an array of function names, or just the function name as a
string | [
"Allows",
"the",
"registration",
"of",
"PHP",
"functions",
"to",
"be",
"used",
"on",
"the",
"Frontend",
"by",
"passing",
"the",
"function",
"name",
"or",
"an",
"array",
"of",
"function",
"names"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xsltpage.php#L144-L153 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.xsltpage.php | XSLTPage.generate | public function generate($page = null)
{
$result = $this->Proc->process($this->_xml, $this->_xsl, $this->_param, $this->_registered_php_functions);
if ($this->Proc->isErrors()) {
$this->setHttpStatus(Page::HTTP_STATUS_ERROR);
return false;
}
parent::generate($page);
return $result;
} | php | public function generate($page = null)
{
$result = $this->Proc->process($this->_xml, $this->_xsl, $this->_param, $this->_registered_php_functions);
if ($this->Proc->isErrors()) {
$this->setHttpStatus(Page::HTTP_STATUS_ERROR);
return false;
}
parent::generate($page);
return $result;
} | [
"public",
"function",
"generate",
"(",
"$",
"page",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"Proc",
"->",
"process",
"(",
"$",
"this",
"->",
"_xml",
",",
"$",
"this",
"->",
"_xsl",
",",
"$",
"this",
"->",
"_param",
",",
"$",
"this",
"->",
"_registered_php_functions",
")",
";",
"if",
"(",
"$",
"this",
"->",
"Proc",
"->",
"isErrors",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setHttpStatus",
"(",
"Page",
"::",
"HTTP_STATUS_ERROR",
")",
";",
"return",
"false",
";",
"}",
"parent",
"::",
"generate",
"(",
"$",
"page",
")",
";",
"return",
"$",
"result",
";",
"}"
] | The generate function calls on the `XsltProcess` to transform the
XML with the given XSLT passing any parameters or functions
If no errors occur, the parent generate function is called to add
the page headers and a string containing the transformed result
is result.
@param null $page
@return string | [
"The",
"generate",
"function",
"calls",
"on",
"the",
"XsltProcess",
"to",
"transform",
"the",
"XML",
"with",
"the",
"given",
"XSLT",
"passing",
"any",
"parameters",
"or",
"functions",
"If",
"no",
"errors",
"occur",
"the",
"parent",
"generate",
"function",
"is",
"called",
"to",
"add",
"the",
"page",
"headers",
"and",
"a",
"string",
"containing",
"the",
"transformed",
"result",
"is",
"result",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.xsltpage.php#L165-L177 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.taglist.php | FieldTagList.fetchAssociatedEntryCount | public function fetchAssociatedEntryCount($value)
{
$value = array_map(array($this, 'cleanValue'), explode(',', $value));
$value = implode("','", $value);
$count = (int)Symphony::Database()->fetchVar('count', 0, sprintf("
SELECT COUNT(handle) AS `count`
FROM `tbl_entries_data_%d`
WHERE `handle` IN ('%s')",
$this->get('id'),
$value
));
return $count;
} | php | public function fetchAssociatedEntryCount($value)
{
$value = array_map(array($this, 'cleanValue'), explode(',', $value));
$value = implode("','", $value);
$count = (int)Symphony::Database()->fetchVar('count', 0, sprintf("
SELECT COUNT(handle) AS `count`
FROM `tbl_entries_data_%d`
WHERE `handle` IN ('%s')",
$this->get('id'),
$value
));
return $count;
} | [
"public",
"function",
"fetchAssociatedEntryCount",
"(",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"array_map",
"(",
"array",
"(",
"$",
"this",
",",
"'cleanValue'",
")",
",",
"explode",
"(",
"','",
",",
"$",
"value",
")",
")",
";",
"$",
"value",
"=",
"implode",
"(",
"\"','\"",
",",
"$",
"value",
")",
";",
"$",
"count",
"=",
"(",
"int",
")",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchVar",
"(",
"'count'",
",",
"0",
",",
"sprintf",
"(",
"\"\n SELECT COUNT(handle) AS `count`\n FROM `tbl_entries_data_%d`\n WHERE `handle` IN ('%s')\"",
",",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"value",
")",
")",
";",
"return",
"$",
"count",
";",
"}"
] | /*-------------------------------------------------------------------------
Utilities:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Utilities",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.taglist.php#L77-L90 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.taglist.php | FieldTagList.findRelatedEntries | public function findRelatedEntries($entry_id, $parent_field_id)
{
// We have the entry_id of the entry that has the referenced tag values
// Lets find out what those handles are so we can then referenced the
// child section looking for them.
$handles = Symphony::Database()->fetchCol('handle', sprintf("
SELECT `handle`
FROM `tbl_entries_data_%d`
WHERE `entry_id` = %d
", $parent_field_id, $entry_id));
$ids = Symphony::Database()->fetchCol('entry_id', sprintf("
SELECT `entry_id`
FROM `tbl_entries_data_%d`
WHERE `handle` IN ('%s')
", $this->get('id'), implode("','", $handles)));
return $ids;
} | php | public function findRelatedEntries($entry_id, $parent_field_id)
{
// We have the entry_id of the entry that has the referenced tag values
// Lets find out what those handles are so we can then referenced the
// child section looking for them.
$handles = Symphony::Database()->fetchCol('handle', sprintf("
SELECT `handle`
FROM `tbl_entries_data_%d`
WHERE `entry_id` = %d
", $parent_field_id, $entry_id));
$ids = Symphony::Database()->fetchCol('entry_id', sprintf("
SELECT `entry_id`
FROM `tbl_entries_data_%d`
WHERE `handle` IN ('%s')
", $this->get('id'), implode("','", $handles)));
return $ids;
} | [
"public",
"function",
"findRelatedEntries",
"(",
"$",
"entry_id",
",",
"$",
"parent_field_id",
")",
"{",
"// We have the entry_id of the entry that has the referenced tag values",
"// Lets find out what those handles are so we can then referenced the",
"// child section looking for them.",
"$",
"handles",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchCol",
"(",
"'handle'",
",",
"sprintf",
"(",
"\"\n SELECT `handle`\n FROM `tbl_entries_data_%d`\n WHERE `entry_id` = %d\n \"",
",",
"$",
"parent_field_id",
",",
"$",
"entry_id",
")",
")",
";",
"$",
"ids",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchCol",
"(",
"'entry_id'",
",",
"sprintf",
"(",
"\"\n SELECT `entry_id`\n FROM `tbl_entries_data_%d`\n WHERE `handle` IN ('%s')\n \"",
",",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
",",
"implode",
"(",
"\"','\"",
",",
"$",
"handles",
")",
")",
")",
";",
"return",
"$",
"ids",
";",
"}"
] | Find all the entries that reference this entry's tags.
@param integer $entry_id
@param integer $parent_field_id
@return array | [
"Find",
"all",
"the",
"entries",
"that",
"reference",
"this",
"entry",
"s",
"tags",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.taglist.php#L124-L142 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.taglist.php | FieldTagList.findParentRelatedEntries | public function findParentRelatedEntries($field_id, $entry_id)
{
// Get all the `handles` that have been referenced from the
// child association.
$handles = Symphony::Database()->fetchCol('handle', sprintf("
SELECT `handle`
FROM `tbl_entries_data_%d`
WHERE `entry_id` = %d
", $this->get('id'), $entry_id));
// Now find the associated entry ids for those `handles` in
// the parent section.
$ids = Symphony::Database()->fetchCol('entry_id', sprintf("
SELECT `entry_id`
FROM `tbl_entries_data_%d`
WHERE `handle` IN ('%s')
", $field_id, implode("','", $handles)));
return $ids;
} | php | public function findParentRelatedEntries($field_id, $entry_id)
{
// Get all the `handles` that have been referenced from the
// child association.
$handles = Symphony::Database()->fetchCol('handle', sprintf("
SELECT `handle`
FROM `tbl_entries_data_%d`
WHERE `entry_id` = %d
", $this->get('id'), $entry_id));
// Now find the associated entry ids for those `handles` in
// the parent section.
$ids = Symphony::Database()->fetchCol('entry_id', sprintf("
SELECT `entry_id`
FROM `tbl_entries_data_%d`
WHERE `handle` IN ('%s')
", $field_id, implode("','", $handles)));
return $ids;
} | [
"public",
"function",
"findParentRelatedEntries",
"(",
"$",
"field_id",
",",
"$",
"entry_id",
")",
"{",
"// Get all the `handles` that have been referenced from the",
"// child association.",
"$",
"handles",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchCol",
"(",
"'handle'",
",",
"sprintf",
"(",
"\"\n SELECT `handle`\n FROM `tbl_entries_data_%d`\n WHERE `entry_id` = %d\n \"",
",",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"entry_id",
")",
")",
";",
"// Now find the associated entry ids for those `handles` in",
"// the parent section.",
"$",
"ids",
"=",
"Symphony",
"::",
"Database",
"(",
")",
"->",
"fetchCol",
"(",
"'entry_id'",
",",
"sprintf",
"(",
"\"\n SELECT `entry_id`\n FROM `tbl_entries_data_%d`\n WHERE `handle` IN ('%s')\n \"",
",",
"$",
"field_id",
",",
"implode",
"(",
"\"','\"",
",",
"$",
"handles",
")",
")",
")",
";",
"return",
"$",
"ids",
";",
"}"
] | Find all the entries that contain the tags that have been referenced
from this field own entry.
@param integer $field_id
@param integer $entry_id
@return array | [
"Find",
"all",
"the",
"entries",
"that",
"contain",
"the",
"tags",
"that",
"have",
"been",
"referenced",
"from",
"this",
"field",
"own",
"entry",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.taglist.php#L152-L171 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.taglist.php | FieldTagList.displayPublishPanel | public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null)
{
$value = null;
if (isset($data['value'])) {
$value = (is_array($data['value']) ? self::__tagArrayToString($data['value']) : $data['value']);
}
$label = Widget::Label($this->get('label'));
if ($this->get('required') !== 'yes') {
$label->appendChild(new XMLElement('i', __('Optional')));
}
$label->appendChild(
Widget::Input('fields'.$fieldnamePrefix.'['.$this->get('element_name').']'.$fieldnamePostfix, (strlen($value) != 0 ? General::sanitize($value) : null))
);
if ($flagWithError != null) {
$wrapper->appendChild(Widget::Error($label, $flagWithError));
} else {
$wrapper->appendChild($label);
}
if ($this->get('pre_populate_source') != null) {
$existing_tags = $this->getToggleStates();
if (is_array($existing_tags) && !empty($existing_tags)) {
$taglist = new XMLElement('ul');
$taglist->setAttribute('class', 'tags');
$taglist->setAttribute('data-interactive', 'data-interactive');
foreach ($existing_tags as $tag) {
$taglist->appendChild(
new XMLElement('li', General::sanitize($tag))
);
}
$wrapper->appendChild($taglist);
}
}
} | php | public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null)
{
$value = null;
if (isset($data['value'])) {
$value = (is_array($data['value']) ? self::__tagArrayToString($data['value']) : $data['value']);
}
$label = Widget::Label($this->get('label'));
if ($this->get('required') !== 'yes') {
$label->appendChild(new XMLElement('i', __('Optional')));
}
$label->appendChild(
Widget::Input('fields'.$fieldnamePrefix.'['.$this->get('element_name').']'.$fieldnamePostfix, (strlen($value) != 0 ? General::sanitize($value) : null))
);
if ($flagWithError != null) {
$wrapper->appendChild(Widget::Error($label, $flagWithError));
} else {
$wrapper->appendChild($label);
}
if ($this->get('pre_populate_source') != null) {
$existing_tags = $this->getToggleStates();
if (is_array($existing_tags) && !empty($existing_tags)) {
$taglist = new XMLElement('ul');
$taglist->setAttribute('class', 'tags');
$taglist->setAttribute('data-interactive', 'data-interactive');
foreach ($existing_tags as $tag) {
$taglist->appendChild(
new XMLElement('li', General::sanitize($tag))
);
}
$wrapper->appendChild($taglist);
}
}
} | [
"public",
"function",
"displayPublishPanel",
"(",
"XMLElement",
"&",
"$",
"wrapper",
",",
"$",
"data",
"=",
"null",
",",
"$",
"flagWithError",
"=",
"null",
",",
"$",
"fieldnamePrefix",
"=",
"null",
",",
"$",
"fieldnamePostfix",
"=",
"null",
",",
"$",
"entry_id",
"=",
"null",
")",
"{",
"$",
"value",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"(",
"is_array",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
"?",
"self",
"::",
"__tagArrayToString",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
":",
"$",
"data",
"[",
"'value'",
"]",
")",
";",
"}",
"$",
"label",
"=",
"Widget",
"::",
"Label",
"(",
"$",
"this",
"->",
"get",
"(",
"'label'",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'required'",
")",
"!==",
"'yes'",
")",
"{",
"$",
"label",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'i'",
",",
"__",
"(",
"'Optional'",
")",
")",
")",
";",
"}",
"$",
"label",
"->",
"appendChild",
"(",
"Widget",
"::",
"Input",
"(",
"'fields'",
".",
"$",
"fieldnamePrefix",
".",
"'['",
".",
"$",
"this",
"->",
"get",
"(",
"'element_name'",
")",
".",
"']'",
".",
"$",
"fieldnamePostfix",
",",
"(",
"strlen",
"(",
"$",
"value",
")",
"!=",
"0",
"?",
"General",
"::",
"sanitize",
"(",
"$",
"value",
")",
":",
"null",
")",
")",
")",
";",
"if",
"(",
"$",
"flagWithError",
"!=",
"null",
")",
"{",
"$",
"wrapper",
"->",
"appendChild",
"(",
"Widget",
"::",
"Error",
"(",
"$",
"label",
",",
"$",
"flagWithError",
")",
")",
";",
"}",
"else",
"{",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"label",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'pre_populate_source'",
")",
"!=",
"null",
")",
"{",
"$",
"existing_tags",
"=",
"$",
"this",
"->",
"getToggleStates",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"existing_tags",
")",
"&&",
"!",
"empty",
"(",
"$",
"existing_tags",
")",
")",
"{",
"$",
"taglist",
"=",
"new",
"XMLElement",
"(",
"'ul'",
")",
";",
"$",
"taglist",
"->",
"setAttribute",
"(",
"'class'",
",",
"'tags'",
")",
";",
"$",
"taglist",
"->",
"setAttribute",
"(",
"'data-interactive'",
",",
"'data-interactive'",
")",
";",
"foreach",
"(",
"$",
"existing_tags",
"as",
"$",
"tag",
")",
"{",
"$",
"taglist",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'li'",
",",
"General",
"::",
"sanitize",
"(",
"$",
"tag",
")",
")",
")",
";",
"}",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"taglist",
")",
";",
"}",
"}",
"}"
] | /*-------------------------------------------------------------------------
Publish:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Publish",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.taglist.php#L344-L385 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.taglist.php | FieldTagList.appendFormattedElement | public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null)
{
if (!is_array($data) || empty($data) || is_null($data['value'])) {
return;
}
$list = new XMLElement($this->get('element_name'));
if (!is_array($data['handle']) && !is_array($data['value'])) {
$data = array(
'handle' => array($data['handle']),
'value' => array($data['value'])
);
}
foreach ($data['value'] as $index => $value) {
$list->appendChild(new XMLElement('item', General::sanitize($value), array(
'handle' => $data['handle'][$index]
)));
}
$wrapper->appendChild($list);
} | php | public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null)
{
if (!is_array($data) || empty($data) || is_null($data['value'])) {
return;
}
$list = new XMLElement($this->get('element_name'));
if (!is_array($data['handle']) && !is_array($data['value'])) {
$data = array(
'handle' => array($data['handle']),
'value' => array($data['value'])
);
}
foreach ($data['value'] as $index => $value) {
$list->appendChild(new XMLElement('item', General::sanitize($value), array(
'handle' => $data['handle'][$index]
)));
}
$wrapper->appendChild($list);
} | [
"public",
"function",
"appendFormattedElement",
"(",
"XMLElement",
"&",
"$",
"wrapper",
",",
"$",
"data",
",",
"$",
"encode",
"=",
"false",
",",
"$",
"mode",
"=",
"null",
",",
"$",
"entry_id",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
"||",
"empty",
"(",
"$",
"data",
")",
"||",
"is_null",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"list",
"=",
"new",
"XMLElement",
"(",
"$",
"this",
"->",
"get",
"(",
"'element_name'",
")",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
"[",
"'handle'",
"]",
")",
"&&",
"!",
"is_array",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"data",
"=",
"array",
"(",
"'handle'",
"=>",
"array",
"(",
"$",
"data",
"[",
"'handle'",
"]",
")",
",",
"'value'",
"=>",
"array",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"data",
"[",
"'value'",
"]",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"$",
"list",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'item'",
",",
"General",
"::",
"sanitize",
"(",
"$",
"value",
")",
",",
"array",
"(",
"'handle'",
"=>",
"$",
"data",
"[",
"'handle'",
"]",
"[",
"$",
"index",
"]",
")",
")",
")",
";",
"}",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"list",
")",
";",
"}"
] | /*-------------------------------------------------------------------------
Output:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Output",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.taglist.php#L448-L470 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.taglist.php | FieldTagList.prepareExportValue | public function prepareExportValue($data, $mode, $entry_id = null)
{
$modes = (object)$this->getExportModes();
if (isset($data['handle']) && is_array($data['handle']) === false) {
$data['handle'] = array(
$data['handle']
);
}
if (isset($data['value']) && is_array($data['value']) === false) {
$data['value'] = array(
$data['value']
);
}
// Handle => value pairs:
if ($mode === $modes->listHandleToValue) {
return isset($data['handle'], $data['value'])
? array_combine($data['handle'], $data['value'])
: array();
// Array of handles:
} elseif ($mode === $modes->listHandle) {
return isset($data['handle'])
? $data['handle']
: array();
// Array of values:
} elseif ($mode === $modes->listValue) {
return isset($data['value'])
? $data['value']
: array();
// Comma seperated values:
} elseif ($mode === $modes->getPostdata) {
return isset($data['value'])
? implode(', ', $data['value'])
: null;
}
} | php | public function prepareExportValue($data, $mode, $entry_id = null)
{
$modes = (object)$this->getExportModes();
if (isset($data['handle']) && is_array($data['handle']) === false) {
$data['handle'] = array(
$data['handle']
);
}
if (isset($data['value']) && is_array($data['value']) === false) {
$data['value'] = array(
$data['value']
);
}
// Handle => value pairs:
if ($mode === $modes->listHandleToValue) {
return isset($data['handle'], $data['value'])
? array_combine($data['handle'], $data['value'])
: array();
// Array of handles:
} elseif ($mode === $modes->listHandle) {
return isset($data['handle'])
? $data['handle']
: array();
// Array of values:
} elseif ($mode === $modes->listValue) {
return isset($data['value'])
? $data['value']
: array();
// Comma seperated values:
} elseif ($mode === $modes->getPostdata) {
return isset($data['value'])
? implode(', ', $data['value'])
: null;
}
} | [
"public",
"function",
"prepareExportValue",
"(",
"$",
"data",
",",
"$",
"mode",
",",
"$",
"entry_id",
"=",
"null",
")",
"{",
"$",
"modes",
"=",
"(",
"object",
")",
"$",
"this",
"->",
"getExportModes",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'handle'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"data",
"[",
"'handle'",
"]",
")",
"===",
"false",
")",
"{",
"$",
"data",
"[",
"'handle'",
"]",
"=",
"array",
"(",
"$",
"data",
"[",
"'handle'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
"===",
"false",
")",
"{",
"$",
"data",
"[",
"'value'",
"]",
"=",
"array",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
";",
"}",
"// Handle => value pairs:",
"if",
"(",
"$",
"mode",
"===",
"$",
"modes",
"->",
"listHandleToValue",
")",
"{",
"return",
"isset",
"(",
"$",
"data",
"[",
"'handle'",
"]",
",",
"$",
"data",
"[",
"'value'",
"]",
")",
"?",
"array_combine",
"(",
"$",
"data",
"[",
"'handle'",
"]",
",",
"$",
"data",
"[",
"'value'",
"]",
")",
":",
"array",
"(",
")",
";",
"// Array of handles:",
"}",
"elseif",
"(",
"$",
"mode",
"===",
"$",
"modes",
"->",
"listHandle",
")",
"{",
"return",
"isset",
"(",
"$",
"data",
"[",
"'handle'",
"]",
")",
"?",
"$",
"data",
"[",
"'handle'",
"]",
":",
"array",
"(",
")",
";",
"// Array of values:",
"}",
"elseif",
"(",
"$",
"mode",
"===",
"$",
"modes",
"->",
"listValue",
")",
"{",
"return",
"isset",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
"?",
"$",
"data",
"[",
"'value'",
"]",
":",
"array",
"(",
")",
";",
"// Comma seperated values:",
"}",
"elseif",
"(",
"$",
"mode",
"===",
"$",
"modes",
"->",
"getPostdata",
")",
"{",
"return",
"isset",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
"?",
"implode",
"(",
"', '",
",",
"$",
"data",
"[",
"'value'",
"]",
")",
":",
"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 array|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.taglist.php#L554-L594 |
symphonycms/symphony-2 | symphony/lib/toolkit/fields/field.taglist.php | FieldTagList.displayFilteringOptions | public function displayFilteringOptions(XMLElement &$wrapper)
{
if ($this->get('pre_populate_source') != null) {
$existing_tags = $this->getToggleStates();
if (is_array($existing_tags) && !empty($existing_tags)) {
$taglist = new XMLElement('ul');
$taglist->setAttribute('class', 'tags');
$taglist->setAttribute('data-interactive', 'data-interactive');
foreach ($existing_tags as $tag) {
$taglist->appendChild(
new XMLElement('li', General::sanitize($tag))
);
}
$wrapper->appendChild($taglist);
}
}
} | php | public function displayFilteringOptions(XMLElement &$wrapper)
{
if ($this->get('pre_populate_source') != null) {
$existing_tags = $this->getToggleStates();
if (is_array($existing_tags) && !empty($existing_tags)) {
$taglist = new XMLElement('ul');
$taglist->setAttribute('class', 'tags');
$taglist->setAttribute('data-interactive', 'data-interactive');
foreach ($existing_tags as $tag) {
$taglist->appendChild(
new XMLElement('li', General::sanitize($tag))
);
}
$wrapper->appendChild($taglist);
}
}
} | [
"public",
"function",
"displayFilteringOptions",
"(",
"XMLElement",
"&",
"$",
"wrapper",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'pre_populate_source'",
")",
"!=",
"null",
")",
"{",
"$",
"existing_tags",
"=",
"$",
"this",
"->",
"getToggleStates",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"existing_tags",
")",
"&&",
"!",
"empty",
"(",
"$",
"existing_tags",
")",
")",
"{",
"$",
"taglist",
"=",
"new",
"XMLElement",
"(",
"'ul'",
")",
";",
"$",
"taglist",
"->",
"setAttribute",
"(",
"'class'",
",",
"'tags'",
")",
";",
"$",
"taglist",
"->",
"setAttribute",
"(",
"'data-interactive'",
",",
"'data-interactive'",
")",
";",
"foreach",
"(",
"$",
"existing_tags",
"as",
"$",
"tag",
")",
"{",
"$",
"taglist",
"->",
"appendChild",
"(",
"new",
"XMLElement",
"(",
"'li'",
",",
"General",
"::",
"sanitize",
"(",
"$",
"tag",
")",
")",
")",
";",
"}",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"taglist",
")",
";",
"}",
"}",
"}"
] | /*-------------------------------------------------------------------------
Filtering:
------------------------------------------------------------------------- | [
"/",
"*",
"-------------------------------------------------------------------------",
"Filtering",
":",
"-------------------------------------------------------------------------"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/fields/field.taglist.php#L600-L619 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.widget.php | Widget.Label | public static function Label($name = null, XMLElement $child = null, $class = null, $id = null, array $attributes = null)
{
General::ensureType(array(
'name' => array('var' => $name, 'type' => 'string', 'optional' => true),
'class' => array('var' => $class, 'type' => 'string', 'optional' => true),
'id' => array('var' => $id, 'type' => 'string', 'optional' => true)
));
$obj = new XMLElement('label', ($name ? $name : null));
if (is_object($child)) {
$obj->appendChild($child);
}
if ($class) {
$obj->setAttribute('class', $class);
}
if ($id) {
$obj->setAttribute('id', $id);
}
if (is_array($attributes) && !empty($attributes)) {
$obj->setAttributeArray($attributes);
}
return $obj;
} | php | public static function Label($name = null, XMLElement $child = null, $class = null, $id = null, array $attributes = null)
{
General::ensureType(array(
'name' => array('var' => $name, 'type' => 'string', 'optional' => true),
'class' => array('var' => $class, 'type' => 'string', 'optional' => true),
'id' => array('var' => $id, 'type' => 'string', 'optional' => true)
));
$obj = new XMLElement('label', ($name ? $name : null));
if (is_object($child)) {
$obj->appendChild($child);
}
if ($class) {
$obj->setAttribute('class', $class);
}
if ($id) {
$obj->setAttribute('id', $id);
}
if (is_array($attributes) && !empty($attributes)) {
$obj->setAttributeArray($attributes);
}
return $obj;
} | [
"public",
"static",
"function",
"Label",
"(",
"$",
"name",
"=",
"null",
",",
"XMLElement",
"$",
"child",
"=",
"null",
",",
"$",
"class",
"=",
"null",
",",
"$",
"id",
"=",
"null",
",",
"array",
"$",
"attributes",
"=",
"null",
")",
"{",
"General",
"::",
"ensureType",
"(",
"array",
"(",
"'name'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"name",
",",
"'type'",
"=>",
"'string'",
",",
"'optional'",
"=>",
"true",
")",
",",
"'class'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"class",
",",
"'type'",
"=>",
"'string'",
",",
"'optional'",
"=>",
"true",
")",
",",
"'id'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"id",
",",
"'type'",
"=>",
"'string'",
",",
"'optional'",
"=>",
"true",
")",
")",
")",
";",
"$",
"obj",
"=",
"new",
"XMLElement",
"(",
"'label'",
",",
"(",
"$",
"name",
"?",
"$",
"name",
":",
"null",
")",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"child",
")",
")",
"{",
"$",
"obj",
"->",
"appendChild",
"(",
"$",
"child",
")",
";",
"}",
"if",
"(",
"$",
"class",
")",
"{",
"$",
"obj",
"->",
"setAttribute",
"(",
"'class'",
",",
"$",
"class",
")",
";",
"}",
"if",
"(",
"$",
"id",
")",
"{",
"$",
"obj",
"->",
"setAttribute",
"(",
"'id'",
",",
"$",
"id",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"attributes",
")",
"&&",
"!",
"empty",
"(",
"$",
"attributes",
")",
")",
"{",
"$",
"obj",
"->",
"setAttributeArray",
"(",
"$",
"attributes",
")",
";",
"}",
"return",
"$",
"obj",
";",
"}"
] | Generates a XMLElement representation of `<label>`
@param string $name (optional)
The text for the resulting `<label>`
@param XMLElement $child (optional)
An XMLElement that this <label> will become the parent of.
Commonly used with `<input>`.
@param string $class (optional)
The class attribute of the resulting `<label>`
@param string $id (optional)
The id attribute of the resulting `<label>`
@param array $attributes (optional)
Any additional attributes can be included in an associative array with
the key being the name and the value being the value of the attribute.
Attributes set from this array will override existing attributes
set by previous params.
@throws InvalidArgumentException
@return XMLElement | [
"Generates",
"a",
"XMLElement",
"representation",
"of",
"<label",
">"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.widget.php#L32-L59 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.widget.php | Widget.Input | public static function Input($name, $value = null, $type = 'text', array $attributes = null)
{
General::ensureType(array(
'name' => array('var' => $name, 'type' => 'string'),
'value' => array('var' => $value, 'type' => 'string', 'optional' => true),
'type' => array('var' => $type, 'type' => 'string', 'optional' => true),
));
$obj = new XMLElement('input');
$obj->setAttribute('name', $name);
if ($type) {
$obj->setAttribute('type', $type);
}
if (strlen($value) !== 0) {
$obj->setAttribute('value', $value);
}
if (is_array($attributes) && !empty($attributes)) {
$obj->setAttributeArray($attributes);
}
return $obj;
} | php | public static function Input($name, $value = null, $type = 'text', array $attributes = null)
{
General::ensureType(array(
'name' => array('var' => $name, 'type' => 'string'),
'value' => array('var' => $value, 'type' => 'string', 'optional' => true),
'type' => array('var' => $type, 'type' => 'string', 'optional' => true),
));
$obj = new XMLElement('input');
$obj->setAttribute('name', $name);
if ($type) {
$obj->setAttribute('type', $type);
}
if (strlen($value) !== 0) {
$obj->setAttribute('value', $value);
}
if (is_array($attributes) && !empty($attributes)) {
$obj->setAttributeArray($attributes);
}
return $obj;
} | [
"public",
"static",
"function",
"Input",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
",",
"$",
"type",
"=",
"'text'",
",",
"array",
"$",
"attributes",
"=",
"null",
")",
"{",
"General",
"::",
"ensureType",
"(",
"array",
"(",
"'name'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"name",
",",
"'type'",
"=>",
"'string'",
")",
",",
"'value'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"value",
",",
"'type'",
"=>",
"'string'",
",",
"'optional'",
"=>",
"true",
")",
",",
"'type'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"type",
",",
"'type'",
"=>",
"'string'",
",",
"'optional'",
"=>",
"true",
")",
",",
")",
")",
";",
"$",
"obj",
"=",
"new",
"XMLElement",
"(",
"'input'",
")",
";",
"$",
"obj",
"->",
"setAttribute",
"(",
"'name'",
",",
"$",
"name",
")",
";",
"if",
"(",
"$",
"type",
")",
"{",
"$",
"obj",
"->",
"setAttribute",
"(",
"'type'",
",",
"$",
"type",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"value",
")",
"!==",
"0",
")",
"{",
"$",
"obj",
"->",
"setAttribute",
"(",
"'value'",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"attributes",
")",
"&&",
"!",
"empty",
"(",
"$",
"attributes",
")",
")",
"{",
"$",
"obj",
"->",
"setAttributeArray",
"(",
"$",
"attributes",
")",
";",
"}",
"return",
"$",
"obj",
";",
"}"
] | Generates a XMLElement representation of `<input>`
@param string $name
The name attribute of the resulting `<input>`
@param string $value (optional)
The value attribute of the resulting `<input>`
@param string $type
The type attribute for this `<input>`, defaults to "text".
@param array $attributes (optional)
Any additional attributes can be included in an associative array with
the key being the name and the value being the value of the attribute.
Attributes set from this array will override existing attributes
set by previous params.
@throws InvalidArgumentException
@return XMLElement | [
"Generates",
"a",
"XMLElement",
"representation",
"of",
"<input",
">"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.widget.php#L78-L102 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.widget.php | Widget.Checkbox | public static function Checkbox($name, $value, $description = null, XMLElement &$wrapper = null, $help = null)
{
General::ensureType(array(
'name' => array('var' => $name, 'type' => 'string'),
'value' => array('var' => $value, 'type' => 'string', 'optional' => true),
'description' => array('var' => $description, 'type' => 'string'),
'help' => array('var' => $help, 'type' => 'string', 'optional' => true),
));
// Build the label
$label = Widget::Label();
if ($help) {
$label->addClass('inline-help');
}
// Add the 'no' default option to the label, or to the wrapper if it's provided
$default_hidden = Widget::Input($name, 'no', 'hidden');
if (is_null($wrapper)) {
$label->appendChild($default_hidden);
} else {
$wrapper->appendChild($default_hidden);
}
// Include the actual checkbox.
$input = Widget::Input($name, 'yes', 'checkbox');
if ($value === 'yes') {
$input->setAttribute('checked', 'checked');
}
// Build the checkbox, then label, then help
$label->setValue(__('%s ' . $description . ' %s', array(
$input->generate(),
($help) ? ' <i>(' . $help . ')</i>' : ''
)));
// If a wrapper was given, add the label to it
if (!is_null($wrapper)) {
$wrapper->appendChild($label);
}
return $label;
} | php | public static function Checkbox($name, $value, $description = null, XMLElement &$wrapper = null, $help = null)
{
General::ensureType(array(
'name' => array('var' => $name, 'type' => 'string'),
'value' => array('var' => $value, 'type' => 'string', 'optional' => true),
'description' => array('var' => $description, 'type' => 'string'),
'help' => array('var' => $help, 'type' => 'string', 'optional' => true),
));
// Build the label
$label = Widget::Label();
if ($help) {
$label->addClass('inline-help');
}
// Add the 'no' default option to the label, or to the wrapper if it's provided
$default_hidden = Widget::Input($name, 'no', 'hidden');
if (is_null($wrapper)) {
$label->appendChild($default_hidden);
} else {
$wrapper->appendChild($default_hidden);
}
// Include the actual checkbox.
$input = Widget::Input($name, 'yes', 'checkbox');
if ($value === 'yes') {
$input->setAttribute('checked', 'checked');
}
// Build the checkbox, then label, then help
$label->setValue(__('%s ' . $description . ' %s', array(
$input->generate(),
($help) ? ' <i>(' . $help . ')</i>' : ''
)));
// If a wrapper was given, add the label to it
if (!is_null($wrapper)) {
$wrapper->appendChild($label);
}
return $label;
} | [
"public",
"static",
"function",
"Checkbox",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"description",
"=",
"null",
",",
"XMLElement",
"&",
"$",
"wrapper",
"=",
"null",
",",
"$",
"help",
"=",
"null",
")",
"{",
"General",
"::",
"ensureType",
"(",
"array",
"(",
"'name'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"name",
",",
"'type'",
"=>",
"'string'",
")",
",",
"'value'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"value",
",",
"'type'",
"=>",
"'string'",
",",
"'optional'",
"=>",
"true",
")",
",",
"'description'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"description",
",",
"'type'",
"=>",
"'string'",
")",
",",
"'help'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"help",
",",
"'type'",
"=>",
"'string'",
",",
"'optional'",
"=>",
"true",
")",
",",
")",
")",
";",
"// Build the label",
"$",
"label",
"=",
"Widget",
"::",
"Label",
"(",
")",
";",
"if",
"(",
"$",
"help",
")",
"{",
"$",
"label",
"->",
"addClass",
"(",
"'inline-help'",
")",
";",
"}",
"// Add the 'no' default option to the label, or to the wrapper if it's provided",
"$",
"default_hidden",
"=",
"Widget",
"::",
"Input",
"(",
"$",
"name",
",",
"'no'",
",",
"'hidden'",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"wrapper",
")",
")",
"{",
"$",
"label",
"->",
"appendChild",
"(",
"$",
"default_hidden",
")",
";",
"}",
"else",
"{",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"default_hidden",
")",
";",
"}",
"// Include the actual checkbox.",
"$",
"input",
"=",
"Widget",
"::",
"Input",
"(",
"$",
"name",
",",
"'yes'",
",",
"'checkbox'",
")",
";",
"if",
"(",
"$",
"value",
"===",
"'yes'",
")",
"{",
"$",
"input",
"->",
"setAttribute",
"(",
"'checked'",
",",
"'checked'",
")",
";",
"}",
"// Build the checkbox, then label, then help",
"$",
"label",
"->",
"setValue",
"(",
"__",
"(",
"'%s '",
".",
"$",
"description",
".",
"' %s'",
",",
"array",
"(",
"$",
"input",
"->",
"generate",
"(",
")",
",",
"(",
"$",
"help",
")",
"?",
"' <i>('",
".",
"$",
"help",
".",
"')</i>'",
":",
"''",
")",
")",
")",
";",
"// If a wrapper was given, add the label to it",
"if",
"(",
"!",
"is_null",
"(",
"$",
"wrapper",
")",
")",
"{",
"$",
"wrapper",
"->",
"appendChild",
"(",
"$",
"label",
")",
";",
"}",
"return",
"$",
"label",
";",
"}"
] | Generates a XMLElement representation of a `<input type='checkbox'>`. This also
includes the actual label of the Checkbox and any help text if required. Note that
this includes two input fields, one is the hidden 'no' value and the other
is the actual checkbox ('yes' value). This is provided so if the checkbox is
not checked, 'no' is still sent in the form request for this `$name`.
@since Symphony 2.5.2
@param string $name
The name attribute of the resulting checkbox
@param string $value
The value attribute of the resulting checkbox
@param string $description
This will be localisable and displayed after the checkbox when
generated.
@param XMLElement $wrapper
Passed by reference, if this is provided the elements will be automatically
added to the wrapper, otherwise they will just be returned.
@param string $help (optional)
A help message to show below the checkbox.
@throws InvalidArgumentException
@return XMLElement
The markup for the label and the checkbox. | [
"Generates",
"a",
"XMLElement",
"representation",
"of",
"a",
"<input",
"type",
"=",
"checkbox",
">",
".",
"This",
"also",
"includes",
"the",
"actual",
"label",
"of",
"the",
"Checkbox",
"and",
"any",
"help",
"text",
"if",
"required",
".",
"Note",
"that",
"this",
"includes",
"two",
"input",
"fields",
"one",
"is",
"the",
"hidden",
"no",
"value",
"and",
"the",
"other",
"is",
"the",
"actual",
"checkbox",
"(",
"yes",
"value",
")",
".",
"This",
"is",
"provided",
"so",
"if",
"the",
"checkbox",
"is",
"not",
"checked",
"no",
"is",
"still",
"sent",
"in",
"the",
"form",
"request",
"for",
"this",
"$name",
"."
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.widget.php#L128-L169 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.widget.php | Widget.Textarea | public static function Textarea($name, $rows = 15, $cols = 50, $value = null, array $attributes = null)
{
General::ensureType(array(
'name' => array('var' => $name, 'type' => 'string'),
'rows' => array('var' => $rows, 'type' => 'int'),
'cols' => array('var' => $cols, 'type' => 'int'),
'value' => array('var' => $value, 'type' => 'string', 'optional' => true)
));
$obj = new XMLElement('textarea', $value);
$obj->setSelfClosingTag(false);
$obj->setAttribute('name', $name);
$obj->setAttribute('rows', $rows);
$obj->setAttribute('cols', $cols);
if (is_array($attributes) && !empty($attributes)) {
$obj->setAttributeArray($attributes);
}
return $obj;
} | php | public static function Textarea($name, $rows = 15, $cols = 50, $value = null, array $attributes = null)
{
General::ensureType(array(
'name' => array('var' => $name, 'type' => 'string'),
'rows' => array('var' => $rows, 'type' => 'int'),
'cols' => array('var' => $cols, 'type' => 'int'),
'value' => array('var' => $value, 'type' => 'string', 'optional' => true)
));
$obj = new XMLElement('textarea', $value);
$obj->setSelfClosingTag(false);
$obj->setAttribute('name', $name);
$obj->setAttribute('rows', $rows);
$obj->setAttribute('cols', $cols);
if (is_array($attributes) && !empty($attributes)) {
$obj->setAttributeArray($attributes);
}
return $obj;
} | [
"public",
"static",
"function",
"Textarea",
"(",
"$",
"name",
",",
"$",
"rows",
"=",
"15",
",",
"$",
"cols",
"=",
"50",
",",
"$",
"value",
"=",
"null",
",",
"array",
"$",
"attributes",
"=",
"null",
")",
"{",
"General",
"::",
"ensureType",
"(",
"array",
"(",
"'name'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"name",
",",
"'type'",
"=>",
"'string'",
")",
",",
"'rows'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"rows",
",",
"'type'",
"=>",
"'int'",
")",
",",
"'cols'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"cols",
",",
"'type'",
"=>",
"'int'",
")",
",",
"'value'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"value",
",",
"'type'",
"=>",
"'string'",
",",
"'optional'",
"=>",
"true",
")",
")",
")",
";",
"$",
"obj",
"=",
"new",
"XMLElement",
"(",
"'textarea'",
",",
"$",
"value",
")",
";",
"$",
"obj",
"->",
"setSelfClosingTag",
"(",
"false",
")",
";",
"$",
"obj",
"->",
"setAttribute",
"(",
"'name'",
",",
"$",
"name",
")",
";",
"$",
"obj",
"->",
"setAttribute",
"(",
"'rows'",
",",
"$",
"rows",
")",
";",
"$",
"obj",
"->",
"setAttribute",
"(",
"'cols'",
",",
"$",
"cols",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"attributes",
")",
"&&",
"!",
"empty",
"(",
"$",
"attributes",
")",
")",
"{",
"$",
"obj",
"->",
"setAttributeArray",
"(",
"$",
"attributes",
")",
";",
"}",
"return",
"$",
"obj",
";",
"}"
] | Generates a XMLElement representation of `<textarea>`
@param string $name
The name of the resulting `<textarea>`
@param integer $rows (optional)
The height of the `<textarea>`, using the rows attribute. Defaults to 15
@param integer $cols (optional)
The width of the `<textarea>`, using the cols attribute. Defaults to 50.
@param string $value (optional)
The content to be displayed inside the `<textarea>`
@param array $attributes (optional)
Any additional attributes can be included in an associative array with
the key being the name and the value being the value of the attribute.
Attributes set from this array will override existing attributes
set by previous params.
@throws InvalidArgumentException
@return XMLElement | [
"Generates",
"a",
"XMLElement",
"representation",
"of",
"<textarea",
">"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.widget.php#L190-L212 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.widget.php | Widget.Anchor | public static function Anchor($value, $href, $title = null, $class = null, $id = null, array $attributes = null)
{
General::ensureType(array(
'value' => array('var' => $value, 'type' => 'string'),
'href' => array('var' => $href, 'type' => 'string'),
'title' => array('var' => $title, 'type' => 'string', 'optional' => true),
'class' => array('var' => $class, 'type' => 'string', 'optional' => true),
'id' => array('var' => $id, 'type' => 'string', 'optional' => true)
));
$obj = new XMLElement('a', $value);
$obj->setAttribute('href', $href);
if ($title) {
$obj->setAttribute('title', $title);
}
if ($class) {
$obj->setAttribute('class', $class);
}
if ($id) {
$obj->setAttribute('id', $id);
}
if (is_array($attributes) && !empty($attributes)) {
$obj->setAttributeArray($attributes);
}
return $obj;
} | php | public static function Anchor($value, $href, $title = null, $class = null, $id = null, array $attributes = null)
{
General::ensureType(array(
'value' => array('var' => $value, 'type' => 'string'),
'href' => array('var' => $href, 'type' => 'string'),
'title' => array('var' => $title, 'type' => 'string', 'optional' => true),
'class' => array('var' => $class, 'type' => 'string', 'optional' => true),
'id' => array('var' => $id, 'type' => 'string', 'optional' => true)
));
$obj = new XMLElement('a', $value);
$obj->setAttribute('href', $href);
if ($title) {
$obj->setAttribute('title', $title);
}
if ($class) {
$obj->setAttribute('class', $class);
}
if ($id) {
$obj->setAttribute('id', $id);
}
if (is_array($attributes) && !empty($attributes)) {
$obj->setAttributeArray($attributes);
}
return $obj;
} | [
"public",
"static",
"function",
"Anchor",
"(",
"$",
"value",
",",
"$",
"href",
",",
"$",
"title",
"=",
"null",
",",
"$",
"class",
"=",
"null",
",",
"$",
"id",
"=",
"null",
",",
"array",
"$",
"attributes",
"=",
"null",
")",
"{",
"General",
"::",
"ensureType",
"(",
"array",
"(",
"'value'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"value",
",",
"'type'",
"=>",
"'string'",
")",
",",
"'href'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"href",
",",
"'type'",
"=>",
"'string'",
")",
",",
"'title'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"title",
",",
"'type'",
"=>",
"'string'",
",",
"'optional'",
"=>",
"true",
")",
",",
"'class'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"class",
",",
"'type'",
"=>",
"'string'",
",",
"'optional'",
"=>",
"true",
")",
",",
"'id'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"id",
",",
"'type'",
"=>",
"'string'",
",",
"'optional'",
"=>",
"true",
")",
")",
")",
";",
"$",
"obj",
"=",
"new",
"XMLElement",
"(",
"'a'",
",",
"$",
"value",
")",
";",
"$",
"obj",
"->",
"setAttribute",
"(",
"'href'",
",",
"$",
"href",
")",
";",
"if",
"(",
"$",
"title",
")",
"{",
"$",
"obj",
"->",
"setAttribute",
"(",
"'title'",
",",
"$",
"title",
")",
";",
"}",
"if",
"(",
"$",
"class",
")",
"{",
"$",
"obj",
"->",
"setAttribute",
"(",
"'class'",
",",
"$",
"class",
")",
";",
"}",
"if",
"(",
"$",
"id",
")",
"{",
"$",
"obj",
"->",
"setAttribute",
"(",
"'id'",
",",
"$",
"id",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"attributes",
")",
"&&",
"!",
"empty",
"(",
"$",
"attributes",
")",
")",
"{",
"$",
"obj",
"->",
"setAttributeArray",
"(",
"$",
"attributes",
")",
";",
"}",
"return",
"$",
"obj",
";",
"}"
] | Generates a XMLElement representation of `<a>`
@param string $value
The text of the resulting `<a>`
@param string $href
The href attribute of the resulting `<a>`
@param string $title (optional)
The title attribute of the resulting `<a>`
@param string $class (optional)
The class attribute of the resulting `<a>`
@param string $id (optional)
The id attribute of the resulting `<a>`
@param array $attributes (optional)
Any additional attributes can be included in an associative array with
the key being the name and the value being the value of the attribute.
Attributes set from this array will override existing attributes
set by previous params.
@throws InvalidArgumentException
@return XMLElement | [
"Generates",
"a",
"XMLElement",
"representation",
"of",
"<a",
">"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.widget.php#L235-L265 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.widget.php | Widget.Form | public static function Form($action = null, $method = 'post', $class = null, $id = null, array $attributes = null)
{
General::ensureType(array(
'action' => array('var' => $action, 'type' => 'string', 'optional' => true),
'method' => array('var' => $method, 'type' => 'string'),
'class' => array('var' => $class, 'type' => 'string', 'optional' => true),
'id' => array('var' => $id, 'type' => 'string', 'optional' => true)
));
$obj = new XMLElement('form');
$obj->setAttribute('action', $action);
$obj->setAttribute('method', $method);
if ($class) {
$obj->setAttribute('class', $class);
}
if ($id) {
$obj->setAttribute('id', $id);
}
if (is_array($attributes) && !empty($attributes)) {
$obj->setAttributeArray($attributes);
}
return $obj;
} | php | public static function Form($action = null, $method = 'post', $class = null, $id = null, array $attributes = null)
{
General::ensureType(array(
'action' => array('var' => $action, 'type' => 'string', 'optional' => true),
'method' => array('var' => $method, 'type' => 'string'),
'class' => array('var' => $class, 'type' => 'string', 'optional' => true),
'id' => array('var' => $id, 'type' => 'string', 'optional' => true)
));
$obj = new XMLElement('form');
$obj->setAttribute('action', $action);
$obj->setAttribute('method', $method);
if ($class) {
$obj->setAttribute('class', $class);
}
if ($id) {
$obj->setAttribute('id', $id);
}
if (is_array($attributes) && !empty($attributes)) {
$obj->setAttributeArray($attributes);
}
return $obj;
} | [
"public",
"static",
"function",
"Form",
"(",
"$",
"action",
"=",
"null",
",",
"$",
"method",
"=",
"'post'",
",",
"$",
"class",
"=",
"null",
",",
"$",
"id",
"=",
"null",
",",
"array",
"$",
"attributes",
"=",
"null",
")",
"{",
"General",
"::",
"ensureType",
"(",
"array",
"(",
"'action'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"action",
",",
"'type'",
"=>",
"'string'",
",",
"'optional'",
"=>",
"true",
")",
",",
"'method'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"method",
",",
"'type'",
"=>",
"'string'",
")",
",",
"'class'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"class",
",",
"'type'",
"=>",
"'string'",
",",
"'optional'",
"=>",
"true",
")",
",",
"'id'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"id",
",",
"'type'",
"=>",
"'string'",
",",
"'optional'",
"=>",
"true",
")",
")",
")",
";",
"$",
"obj",
"=",
"new",
"XMLElement",
"(",
"'form'",
")",
";",
"$",
"obj",
"->",
"setAttribute",
"(",
"'action'",
",",
"$",
"action",
")",
";",
"$",
"obj",
"->",
"setAttribute",
"(",
"'method'",
",",
"$",
"method",
")",
";",
"if",
"(",
"$",
"class",
")",
"{",
"$",
"obj",
"->",
"setAttribute",
"(",
"'class'",
",",
"$",
"class",
")",
";",
"}",
"if",
"(",
"$",
"id",
")",
"{",
"$",
"obj",
"->",
"setAttribute",
"(",
"'id'",
",",
"$",
"id",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"attributes",
")",
"&&",
"!",
"empty",
"(",
"$",
"attributes",
")",
")",
"{",
"$",
"obj",
"->",
"setAttributeArray",
"(",
"$",
"attributes",
")",
";",
"}",
"return",
"$",
"obj",
";",
"}"
] | Generates a XMLElement representation of `<form>`
@param string $action
The text of the resulting `<form>`
@param string $method
The method attribute of the resulting `<form>`. Defaults to "post".
@param string $class (optional)
The class attribute of the resulting `<form>`
@param string $id (optional)
The id attribute of the resulting `<form>`
@param array $attributes (optional)
Any additional attributes can be included in an associative array with
the key being the name and the value being the value of the attribute.
Attributes set from this array will override existing attributes
set by previous params.
@throws InvalidArgumentException
@return XMLElement | [
"Generates",
"a",
"XMLElement",
"representation",
"of",
"<form",
">"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.widget.php#L286-L312 |
symphonycms/symphony-2 | symphony/lib/toolkit/class.widget.php | Widget.Table | public static function Table(XMLElement $header = null, XMLElement $footer = null, XMLElement $body = null, $class = null, $id = null, Array $attributes = null)
{
General::ensureType(array(
'class' => array('var' => $class, 'type' => 'string', 'optional' => true),
'id' => array('var' => $id, 'type' => 'string', 'optional' => true)
));
$obj = new XMLElement('table');
if ($class) {
$obj->setAttribute('class', $class);
}
if ($id) {
$obj->setAttribute('id', $id);
}
if ($header) {
$obj->appendChild($header);
}
if ($footer) {
$obj->appendChild($footer);
}
if ($body) {
$obj->appendChild($body);
}
if (is_array($attributes) && !empty($attributes)) {
$obj->setAttributeArray($attributes);
}
return $obj;
} | php | public static function Table(XMLElement $header = null, XMLElement $footer = null, XMLElement $body = null, $class = null, $id = null, Array $attributes = null)
{
General::ensureType(array(
'class' => array('var' => $class, 'type' => 'string', 'optional' => true),
'id' => array('var' => $id, 'type' => 'string', 'optional' => true)
));
$obj = new XMLElement('table');
if ($class) {
$obj->setAttribute('class', $class);
}
if ($id) {
$obj->setAttribute('id', $id);
}
if ($header) {
$obj->appendChild($header);
}
if ($footer) {
$obj->appendChild($footer);
}
if ($body) {
$obj->appendChild($body);
}
if (is_array($attributes) && !empty($attributes)) {
$obj->setAttributeArray($attributes);
}
return $obj;
} | [
"public",
"static",
"function",
"Table",
"(",
"XMLElement",
"$",
"header",
"=",
"null",
",",
"XMLElement",
"$",
"footer",
"=",
"null",
",",
"XMLElement",
"$",
"body",
"=",
"null",
",",
"$",
"class",
"=",
"null",
",",
"$",
"id",
"=",
"null",
",",
"Array",
"$",
"attributes",
"=",
"null",
")",
"{",
"General",
"::",
"ensureType",
"(",
"array",
"(",
"'class'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"class",
",",
"'type'",
"=>",
"'string'",
",",
"'optional'",
"=>",
"true",
")",
",",
"'id'",
"=>",
"array",
"(",
"'var'",
"=>",
"$",
"id",
",",
"'type'",
"=>",
"'string'",
",",
"'optional'",
"=>",
"true",
")",
")",
")",
";",
"$",
"obj",
"=",
"new",
"XMLElement",
"(",
"'table'",
")",
";",
"if",
"(",
"$",
"class",
")",
"{",
"$",
"obj",
"->",
"setAttribute",
"(",
"'class'",
",",
"$",
"class",
")",
";",
"}",
"if",
"(",
"$",
"id",
")",
"{",
"$",
"obj",
"->",
"setAttribute",
"(",
"'id'",
",",
"$",
"id",
")",
";",
"}",
"if",
"(",
"$",
"header",
")",
"{",
"$",
"obj",
"->",
"appendChild",
"(",
"$",
"header",
")",
";",
"}",
"if",
"(",
"$",
"footer",
")",
"{",
"$",
"obj",
"->",
"appendChild",
"(",
"$",
"footer",
")",
";",
"}",
"if",
"(",
"$",
"body",
")",
"{",
"$",
"obj",
"->",
"appendChild",
"(",
"$",
"body",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"attributes",
")",
"&&",
"!",
"empty",
"(",
"$",
"attributes",
")",
")",
"{",
"$",
"obj",
"->",
"setAttributeArray",
"(",
"$",
"attributes",
")",
";",
"}",
"return",
"$",
"obj",
";",
"}"
] | Generates a XMLElement representation of `<table>`
This is a simple way to create generic Symphony table wrapper
@param XMLElement $header
An XMLElement containing the `<thead>`. See Widget::TableHead
@param XMLElement $footer
An XMLElement containing the `<tfoot>`
@param XMLElement $body
An XMLElement containing the `<tbody>`. See Widget::TableBody
@param string $class (optional)
The class attribute of the resulting `<table>`
@param string $id (optional)
The id attribute of the resulting `<table>`
@param array $attributes (optional)
Any additional attributes can be included in an associative array with
the key being the name and the value being the value of the attribute.
Attributes set from this array will override existing attributes
set by previous params.
@throws InvalidArgumentException
@return XMLElement | [
"Generates",
"a",
"XMLElement",
"representation",
"of",
"<table",
">",
"This",
"is",
"a",
"simple",
"way",
"to",
"create",
"generic",
"Symphony",
"table",
"wrapper"
] | train | https://github.com/symphonycms/symphony-2/blob/68f44f0c36ad3345068676bfb8a61c2e6a2e51f4/symphony/lib/toolkit/class.widget.php#L336-L370 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.