repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
i-MSCP/roundcube | roundcubemail/program/include/rcmail_install.php | rcmail_install.fail | public function fail($name, $message = '', $url = '', $optional=false)
{
if (!$optional) {
$this->failures++;
}
echo rcube::Q($name) . ': <span class="fail">NOT OK</span>';
$this->_showhint($message, $url);
} | php | public function fail($name, $message = '', $url = '', $optional=false)
{
if (!$optional) {
$this->failures++;
}
echo rcube::Q($name) . ': <span class="fail">NOT OK</span>';
$this->_showhint($message, $url);
} | [
"public",
"function",
"fail",
"(",
"$",
"name",
",",
"$",
"message",
"=",
"''",
",",
"$",
"url",
"=",
"''",
",",
"$",
"optional",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"optional",
")",
"{",
"$",
"this",
"->",
"failures",
"++",
";",
"}",
"echo",
"rcube",
"::",
"Q",
"(",
"$",
"name",
")",
".",
"': <span class=\"fail\">NOT OK</span>'",
";",
"$",
"this",
"->",
"_showhint",
"(",
"$",
"message",
",",
"$",
"url",
")",
";",
"}"
]
| Display an error status and increase failure count
@param string $name Test name
@param string $message Error message
@param string $url URL for details
@param bool $optional Do not count this failure | [
"Display",
"an",
"error",
"status",
"and",
"increase",
"failure",
"count"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_install.php#L682-L690 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail_install.php | rcmail_install.na | public function na($name, $message = '', $url = '')
{
echo rcube::Q($name) . ': <span class="na">NOT AVAILABLE</span>';
$this->_showhint($message, $url);
} | php | public function na($name, $message = '', $url = '')
{
echo rcube::Q($name) . ': <span class="na">NOT AVAILABLE</span>';
$this->_showhint($message, $url);
} | [
"public",
"function",
"na",
"(",
"$",
"name",
",",
"$",
"message",
"=",
"''",
",",
"$",
"url",
"=",
"''",
")",
"{",
"echo",
"rcube",
"::",
"Q",
"(",
"$",
"name",
")",
".",
"': <span class=\"na\">NOT AVAILABLE</span>'",
";",
"$",
"this",
"->",
"_showhint",
"(",
"$",
"message",
",",
"$",
"url",
")",
";",
"}"
]
| Display warning status
@param string $name Test name
@param string $message Warning message
@param string $url URL for details | [
"Display",
"warning",
"status"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_install.php#L712-L716 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail_install.php | rcmail_install.init_db | public function init_db($db)
{
$engine = $db->db_provider;
// read schema file from /SQL/*
$fname = INSTALL_PATH . "SQL/$engine.initial.sql";
if ($sql = @file_get_contents($fname)) {
$db->set_option('table_prefix', $this->config['db_prefix']);
$db->exec_script($sql);
}
else {
$this->fail('DB Schema', "Cannot read the schema file: $fname");
return false;
}
if ($err = $this->get_error()) {
$this->fail('DB Schema', "Error creating database schema: $err");
return false;
}
return true;
} | php | public function init_db($db)
{
$engine = $db->db_provider;
// read schema file from /SQL/*
$fname = INSTALL_PATH . "SQL/$engine.initial.sql";
if ($sql = @file_get_contents($fname)) {
$db->set_option('table_prefix', $this->config['db_prefix']);
$db->exec_script($sql);
}
else {
$this->fail('DB Schema', "Cannot read the schema file: $fname");
return false;
}
if ($err = $this->get_error()) {
$this->fail('DB Schema', "Error creating database schema: $err");
return false;
}
return true;
} | [
"public",
"function",
"init_db",
"(",
"$",
"db",
")",
"{",
"$",
"engine",
"=",
"$",
"db",
"->",
"db_provider",
";",
"// read schema file from /SQL/*",
"$",
"fname",
"=",
"INSTALL_PATH",
".",
"\"SQL/$engine.initial.sql\"",
";",
"if",
"(",
"$",
"sql",
"=",
"@",
"file_get_contents",
"(",
"$",
"fname",
")",
")",
"{",
"$",
"db",
"->",
"set_option",
"(",
"'table_prefix'",
",",
"$",
"this",
"->",
"config",
"[",
"'db_prefix'",
"]",
")",
";",
"$",
"db",
"->",
"exec_script",
"(",
"$",
"sql",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"fail",
"(",
"'DB Schema'",
",",
"\"Cannot read the schema file: $fname\"",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"err",
"=",
"$",
"this",
"->",
"get_error",
"(",
")",
")",
"{",
"$",
"this",
"->",
"fail",
"(",
"'DB Schema'",
",",
"\"Error creating database schema: $err\"",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Initialize the database with the according schema
@param rcube_db $db Database connection
@return boolen True on success, False on error | [
"Initialize",
"the",
"database",
"with",
"the",
"according",
"schema"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_install.php#L805-L826 | train |
i-MSCP/roundcube | roundcubemail/plugins/password/drivers/plesk.php | rcube_plesk_password.save | function save($currpass, $newpass)
{
// get config
$rcmail = rcmail::get_instance();
$host = $rcmail->config->get('password_plesk_host');
$user = $rcmail->config->get('password_plesk_user');
$pass = $rcmail->config->get('password_plesk_pass');
$port = $rcmail->config->get('password_plesk_rpc_port');
$path = $rcmail->config->get('password_plesk_rpc_path');
// create plesk-object
$plesk = new plesk_rpc;
$plesk->init($host, $port, $path, $user, $pass);
// try to change password and return the status
$result = $plesk->change_mailbox_password($_SESSION['username'], $newpass);
//$plesk->destroy();
if ($result) {
return PASSWORD_SUCCESS;
}
return PASSWORD_ERROR;
} | php | function save($currpass, $newpass)
{
// get config
$rcmail = rcmail::get_instance();
$host = $rcmail->config->get('password_plesk_host');
$user = $rcmail->config->get('password_plesk_user');
$pass = $rcmail->config->get('password_plesk_pass');
$port = $rcmail->config->get('password_plesk_rpc_port');
$path = $rcmail->config->get('password_plesk_rpc_path');
// create plesk-object
$plesk = new plesk_rpc;
$plesk->init($host, $port, $path, $user, $pass);
// try to change password and return the status
$result = $plesk->change_mailbox_password($_SESSION['username'], $newpass);
//$plesk->destroy();
if ($result) {
return PASSWORD_SUCCESS;
}
return PASSWORD_ERROR;
} | [
"function",
"save",
"(",
"$",
"currpass",
",",
"$",
"newpass",
")",
"{",
"// get config",
"$",
"rcmail",
"=",
"rcmail",
"::",
"get_instance",
"(",
")",
";",
"$",
"host",
"=",
"$",
"rcmail",
"->",
"config",
"->",
"get",
"(",
"'password_plesk_host'",
")",
";",
"$",
"user",
"=",
"$",
"rcmail",
"->",
"config",
"->",
"get",
"(",
"'password_plesk_user'",
")",
";",
"$",
"pass",
"=",
"$",
"rcmail",
"->",
"config",
"->",
"get",
"(",
"'password_plesk_pass'",
")",
";",
"$",
"port",
"=",
"$",
"rcmail",
"->",
"config",
"->",
"get",
"(",
"'password_plesk_rpc_port'",
")",
";",
"$",
"path",
"=",
"$",
"rcmail",
"->",
"config",
"->",
"get",
"(",
"'password_plesk_rpc_path'",
")",
";",
"// create plesk-object",
"$",
"plesk",
"=",
"new",
"plesk_rpc",
";",
"$",
"plesk",
"->",
"init",
"(",
"$",
"host",
",",
"$",
"port",
",",
"$",
"path",
",",
"$",
"user",
",",
"$",
"pass",
")",
";",
"// try to change password and return the status",
"$",
"result",
"=",
"$",
"plesk",
"->",
"change_mailbox_password",
"(",
"$",
"_SESSION",
"[",
"'username'",
"]",
",",
"$",
"newpass",
")",
";",
"//$plesk->destroy();",
"if",
"(",
"$",
"result",
")",
"{",
"return",
"PASSWORD_SUCCESS",
";",
"}",
"return",
"PASSWORD_ERROR",
";",
"}"
]
| this method is called from roundcube to change the password
roundcube allready validated the old password so we just need to change it at this point
@author Cyrill von Wattenwyl <[email protected]>
@param string $curpass Current password
@param string $newpass New password
@returns int PASSWORD_SUCCESS|PASSWORD_ERROR | [
"this",
"method",
"is",
"called",
"from",
"roundcube",
"to",
"change",
"the",
"password"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/password/drivers/plesk.php#L52-L75 | train |
i-MSCP/roundcube | roundcubemail/plugins/password/drivers/plesk.php | plesk_rpc.init | function init($host, $port, $path, $user, $pass)
{
$headers = array(
sprintf("HTTP_AUTH_LOGIN: %s", $user),
sprintf("HTTP_AUTH_PASSWD: %s", $pass),
"Content-Type: text/xml"
);
$url = sprintf("https://%s:%s/%s", $host, $port, $path);
$this->curl = curl_init();
curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT , 5);
curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST , 0);
curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER , false);
curl_setopt($this->curl, CURLOPT_HTTPHEADER , $headers);
curl_setopt($this->curl, CURLOPT_URL , $url);
} | php | function init($host, $port, $path, $user, $pass)
{
$headers = array(
sprintf("HTTP_AUTH_LOGIN: %s", $user),
sprintf("HTTP_AUTH_PASSWD: %s", $pass),
"Content-Type: text/xml"
);
$url = sprintf("https://%s:%s/%s", $host, $port, $path);
$this->curl = curl_init();
curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT , 5);
curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST , 0);
curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER , false);
curl_setopt($this->curl, CURLOPT_HTTPHEADER , $headers);
curl_setopt($this->curl, CURLOPT_URL , $url);
} | [
"function",
"init",
"(",
"$",
"host",
",",
"$",
"port",
",",
"$",
"path",
",",
"$",
"user",
",",
"$",
"pass",
")",
"{",
"$",
"headers",
"=",
"array",
"(",
"sprintf",
"(",
"\"HTTP_AUTH_LOGIN: %s\"",
",",
"$",
"user",
")",
",",
"sprintf",
"(",
"\"HTTP_AUTH_PASSWD: %s\"",
",",
"$",
"pass",
")",
",",
"\"Content-Type: text/xml\"",
")",
";",
"$",
"url",
"=",
"sprintf",
"(",
"\"https://%s:%s/%s\"",
",",
"$",
"host",
",",
"$",
"port",
",",
"$",
"path",
")",
";",
"$",
"this",
"->",
"curl",
"=",
"curl_init",
"(",
")",
";",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_CONNECTTIMEOUT",
",",
"5",
")",
";",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_SSL_VERIFYHOST",
",",
"0",
")",
";",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_SSL_VERIFYPEER",
",",
"false",
")",
";",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"headers",
")",
";",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_URL",
",",
"$",
"url",
")",
";",
"}"
]
| init plesk-rpc via curl
@param string $host plesk host
@param string $port plesk rpc port
@param string $path plesk rpc path
@param string $user plesk user
@param string $user plesk password
@returns void | [
"init",
"plesk",
"-",
"rpc",
"via",
"curl"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/password/drivers/plesk.php#L101-L117 | train |
i-MSCP/roundcube | roundcubemail/plugins/password/drivers/plesk.php | plesk_rpc.send_request | function send_request($packet)
{
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $packet);
$retval = curl_exec($this->curl);
return $retval;
} | php | function send_request($packet)
{
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $packet);
$retval = curl_exec($this->curl);
return $retval;
} | [
"function",
"send_request",
"(",
"$",
"packet",
")",
"{",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"packet",
")",
";",
"$",
"retval",
"=",
"curl_exec",
"(",
"$",
"this",
"->",
"curl",
")",
";",
"return",
"$",
"retval",
";",
"}"
]
| send a request to the plesk
@param string $packet XML-Packet to send to Plesk
@returns bool request was successful or not | [
"send",
"a",
"request",
"to",
"the",
"plesk"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/password/drivers/plesk.php#L125-L132 | train |
i-MSCP/roundcube | roundcubemail/plugins/password/drivers/plesk.php | plesk_rpc.domain_info | function domain_info($domain)
{
// build xml
$request = $this->get_request_obj();
$site = $request->addChild("site");
$get = $site->addChild("get");
$filter = $get->addChild("filter");
$filter->addChild("name", utf8_encode($domain));
$dataset = $get->addChild("dataset");
$dataset->addChild("hosting");
$packet = $request->asXML();
// send the request
$res = $this->send_request($packet);
// make it to simple-xml-object
$xml = new SimpleXMLElement($res);
return $xml;
} | php | function domain_info($domain)
{
// build xml
$request = $this->get_request_obj();
$site = $request->addChild("site");
$get = $site->addChild("get");
$filter = $get->addChild("filter");
$filter->addChild("name", utf8_encode($domain));
$dataset = $get->addChild("dataset");
$dataset->addChild("hosting");
$packet = $request->asXML();
// send the request
$res = $this->send_request($packet);
// make it to simple-xml-object
$xml = new SimpleXMLElement($res);
return $xml;
} | [
"function",
"domain_info",
"(",
"$",
"domain",
")",
"{",
"// build xml",
"$",
"request",
"=",
"$",
"this",
"->",
"get_request_obj",
"(",
")",
";",
"$",
"site",
"=",
"$",
"request",
"->",
"addChild",
"(",
"\"site\"",
")",
";",
"$",
"get",
"=",
"$",
"site",
"->",
"addChild",
"(",
"\"get\"",
")",
";",
"$",
"filter",
"=",
"$",
"get",
"->",
"addChild",
"(",
"\"filter\"",
")",
";",
"$",
"filter",
"->",
"addChild",
"(",
"\"name\"",
",",
"utf8_encode",
"(",
"$",
"domain",
")",
")",
";",
"$",
"dataset",
"=",
"$",
"get",
"->",
"addChild",
"(",
"\"dataset\"",
")",
";",
"$",
"dataset",
"->",
"addChild",
"(",
"\"hosting\"",
")",
";",
"$",
"packet",
"=",
"$",
"request",
"->",
"asXML",
"(",
")",
";",
"// send the request",
"$",
"res",
"=",
"$",
"this",
"->",
"send_request",
"(",
"$",
"packet",
")",
";",
"// make it to simple-xml-object",
"$",
"xml",
"=",
"new",
"SimpleXMLElement",
"(",
"$",
"res",
")",
";",
"return",
"$",
"xml",
";",
"}"
]
| Get all hosting-information of a domain
@param string $domain domain-name
@returns object SimpleXML object | [
"Get",
"all",
"hosting",
"-",
"information",
"of",
"a",
"domain"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/password/drivers/plesk.php#L160-L181 | train |
i-MSCP/roundcube | roundcubemail/plugins/password/drivers/plesk.php | plesk_rpc.get_domain_id | function get_domain_id($domain)
{
$xml = $this->domain_info($domain);
$id = intval($xml->site->get->result->id);
$id = (is_int($id)) ? $id : false;
return $id;
} | php | function get_domain_id($domain)
{
$xml = $this->domain_info($domain);
$id = intval($xml->site->get->result->id);
$id = (is_int($id)) ? $id : false;
return $id;
} | [
"function",
"get_domain_id",
"(",
"$",
"domain",
")",
"{",
"$",
"xml",
"=",
"$",
"this",
"->",
"domain_info",
"(",
"$",
"domain",
")",
";",
"$",
"id",
"=",
"intval",
"(",
"$",
"xml",
"->",
"site",
"->",
"get",
"->",
"result",
"->",
"id",
")",
";",
"$",
"id",
"=",
"(",
"is_int",
"(",
"$",
"id",
")",
")",
"?",
"$",
"id",
":",
"false",
";",
"return",
"$",
"id",
";",
"}"
]
| Get psa-id of a domain
@param string $domain domain-name
@returns bool|int false if failed and integer if successed | [
"Get",
"psa",
"-",
"id",
"of",
"a",
"domain"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/password/drivers/plesk.php#L190-L197 | train |
i-MSCP/roundcube | roundcubemail/plugins/password/drivers/plesk.php | plesk_rpc.change_mailbox_password | function change_mailbox_password($mailbox, $newpass)
{
list($user, $domain) = explode("@", $mailbox);
$domain_id = $this->get_domain_id($domain);
// if domain cannot be resolved to an id, do not continue
if (!$domain_id) {
return false;
}
// build xml-packet
$request = $this -> get_request_obj();
$mail = $request -> addChild("mail");
$update = $mail -> addChild("update");
$add = $update -> addChild("set");
$filter = $add -> addChild("filter");
$filter->addChild("site-id", $domain_id);
$mailname = $filter->addChild("mailname");
$mailname->addChild("name", $user);
$password = $mailname->addChild("password");
$password->addChild("value", $newpass);
$password->addChild("type", "plain");
$packet = $request->asXML();
// send the request to plesk
$res = $this->send_request($packet);
$xml = new SimpleXMLElement($res);
$res = strval($xml->mail->update->set->result->status);
return $res == "ok";
} | php | function change_mailbox_password($mailbox, $newpass)
{
list($user, $domain) = explode("@", $mailbox);
$domain_id = $this->get_domain_id($domain);
// if domain cannot be resolved to an id, do not continue
if (!$domain_id) {
return false;
}
// build xml-packet
$request = $this -> get_request_obj();
$mail = $request -> addChild("mail");
$update = $mail -> addChild("update");
$add = $update -> addChild("set");
$filter = $add -> addChild("filter");
$filter->addChild("site-id", $domain_id);
$mailname = $filter->addChild("mailname");
$mailname->addChild("name", $user);
$password = $mailname->addChild("password");
$password->addChild("value", $newpass);
$password->addChild("type", "plain");
$packet = $request->asXML();
// send the request to plesk
$res = $this->send_request($packet);
$xml = new SimpleXMLElement($res);
$res = strval($xml->mail->update->set->result->status);
return $res == "ok";
} | [
"function",
"change_mailbox_password",
"(",
"$",
"mailbox",
",",
"$",
"newpass",
")",
"{",
"list",
"(",
"$",
"user",
",",
"$",
"domain",
")",
"=",
"explode",
"(",
"\"@\"",
",",
"$",
"mailbox",
")",
";",
"$",
"domain_id",
"=",
"$",
"this",
"->",
"get_domain_id",
"(",
"$",
"domain",
")",
";",
"// if domain cannot be resolved to an id, do not continue",
"if",
"(",
"!",
"$",
"domain_id",
")",
"{",
"return",
"false",
";",
"}",
"// build xml-packet",
"$",
"request",
"=",
"$",
"this",
"->",
"get_request_obj",
"(",
")",
";",
"$",
"mail",
"=",
"$",
"request",
"->",
"addChild",
"(",
"\"mail\"",
")",
";",
"$",
"update",
"=",
"$",
"mail",
"->",
"addChild",
"(",
"\"update\"",
")",
";",
"$",
"add",
"=",
"$",
"update",
"->",
"addChild",
"(",
"\"set\"",
")",
";",
"$",
"filter",
"=",
"$",
"add",
"->",
"addChild",
"(",
"\"filter\"",
")",
";",
"$",
"filter",
"->",
"addChild",
"(",
"\"site-id\"",
",",
"$",
"domain_id",
")",
";",
"$",
"mailname",
"=",
"$",
"filter",
"->",
"addChild",
"(",
"\"mailname\"",
")",
";",
"$",
"mailname",
"->",
"addChild",
"(",
"\"name\"",
",",
"$",
"user",
")",
";",
"$",
"password",
"=",
"$",
"mailname",
"->",
"addChild",
"(",
"\"password\"",
")",
";",
"$",
"password",
"->",
"addChild",
"(",
"\"value\"",
",",
"$",
"newpass",
")",
";",
"$",
"password",
"->",
"addChild",
"(",
"\"type\"",
",",
"\"plain\"",
")",
";",
"$",
"packet",
"=",
"$",
"request",
"->",
"asXML",
"(",
")",
";",
"// send the request to plesk",
"$",
"res",
"=",
"$",
"this",
"->",
"send_request",
"(",
"$",
"packet",
")",
";",
"$",
"xml",
"=",
"new",
"SimpleXMLElement",
"(",
"$",
"res",
")",
";",
"$",
"res",
"=",
"strval",
"(",
"$",
"xml",
"->",
"mail",
"->",
"update",
"->",
"set",
"->",
"result",
"->",
"status",
")",
";",
"return",
"$",
"res",
"==",
"\"ok\"",
";",
"}"
]
| Change Password of a mailbox
@param string $mailbox full email-address ([email protected])
@param string $newpass new password of mailbox
@returns bool | [
"Change",
"Password",
"of",
"a",
"mailbox"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/password/drivers/plesk.php#L207-L240 | train |
i-MSCP/roundcube | roundcubemail/program/lib/Roundcube/rcube_cache_shared.php | rcube_cache_shared.expunge | function expunge()
{
if ($this->type == 'db' && $this->db && $this->ttl) {
$this->db->query(
"DELETE FROM {$this->table}"
. " WHERE `cache_key` LIKE ?"
. " AND `expires` < " . $this->db->now(),
$this->prefix . '.%');
}
} | php | function expunge()
{
if ($this->type == 'db' && $this->db && $this->ttl) {
$this->db->query(
"DELETE FROM {$this->table}"
. " WHERE `cache_key` LIKE ?"
. " AND `expires` < " . $this->db->now(),
$this->prefix . '.%');
}
} | [
"function",
"expunge",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"type",
"==",
"'db'",
"&&",
"$",
"this",
"->",
"db",
"&&",
"$",
"this",
"->",
"ttl",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"\"DELETE FROM {$this->table}\"",
".",
"\" WHERE `cache_key` LIKE ?\"",
".",
"\" AND `expires` < \"",
".",
"$",
"this",
"->",
"db",
"->",
"now",
"(",
")",
",",
"$",
"this",
"->",
"prefix",
".",
"'.%'",
")",
";",
"}",
"}"
]
| Remove cache records older than ttl | [
"Remove",
"cache",
"records",
"older",
"than",
"ttl"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_cache_shared.php#L188-L197 | train |
i-MSCP/roundcube | roundcubemail/plugins/managesieve/managesieve.php | managesieve.settings_actions | function settings_actions($args)
{
$this->load_config();
$vacation_mode = (int) $this->rc->config->get('managesieve_vacation');
// register Filters action
if ($vacation_mode != 2) {
$args['actions'][] = array(
'action' => 'plugin.managesieve',
'class' => 'filter',
'label' => 'filters',
'domain' => 'managesieve',
'title' => 'filterstitle',
);
}
// register Vacation action
if ($vacation_mode > 0) {
$args['actions'][] = array(
'action' => 'plugin.managesieve-vacation',
'class' => 'vacation',
'label' => 'vacation',
'domain' => 'managesieve',
'title' => 'vacationtitle',
);
}
return $args;
} | php | function settings_actions($args)
{
$this->load_config();
$vacation_mode = (int) $this->rc->config->get('managesieve_vacation');
// register Filters action
if ($vacation_mode != 2) {
$args['actions'][] = array(
'action' => 'plugin.managesieve',
'class' => 'filter',
'label' => 'filters',
'domain' => 'managesieve',
'title' => 'filterstitle',
);
}
// register Vacation action
if ($vacation_mode > 0) {
$args['actions'][] = array(
'action' => 'plugin.managesieve-vacation',
'class' => 'vacation',
'label' => 'vacation',
'domain' => 'managesieve',
'title' => 'vacationtitle',
);
}
return $args;
} | [
"function",
"settings_actions",
"(",
"$",
"args",
")",
"{",
"$",
"this",
"->",
"load_config",
"(",
")",
";",
"$",
"vacation_mode",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"rc",
"->",
"config",
"->",
"get",
"(",
"'managesieve_vacation'",
")",
";",
"// register Filters action",
"if",
"(",
"$",
"vacation_mode",
"!=",
"2",
")",
"{",
"$",
"args",
"[",
"'actions'",
"]",
"[",
"]",
"=",
"array",
"(",
"'action'",
"=>",
"'plugin.managesieve'",
",",
"'class'",
"=>",
"'filter'",
",",
"'label'",
"=>",
"'filters'",
",",
"'domain'",
"=>",
"'managesieve'",
",",
"'title'",
"=>",
"'filterstitle'",
",",
")",
";",
"}",
"// register Vacation action",
"if",
"(",
"$",
"vacation_mode",
">",
"0",
")",
"{",
"$",
"args",
"[",
"'actions'",
"]",
"[",
"]",
"=",
"array",
"(",
"'action'",
"=>",
"'plugin.managesieve-vacation'",
",",
"'class'",
"=>",
"'vacation'",
",",
"'label'",
"=>",
"'vacation'",
",",
"'domain'",
"=>",
"'managesieve'",
",",
"'title'",
"=>",
"'vacationtitle'",
",",
")",
";",
"}",
"return",
"$",
"args",
";",
"}"
]
| Adds Filters section in Settings | [
"Adds",
"Filters",
"section",
"in",
"Settings"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/managesieve.php#L100-L129 | train |
i-MSCP/roundcube | roundcubemail/plugins/managesieve/managesieve.php | managesieve.mail_task_handler | function mail_task_handler()
{
// make sure we're not in ajax request
if ($this->rc->output->type != 'html') {
return;
}
// use jQuery for popup window
$this->require_plugin('jqueryui');
// include js script and localization
$this->init_ui();
// add 'Create filter' item to message menu
$this->api->add_content(html::tag('li', null,
$this->api->output->button(array(
'command' => 'managesieve-create',
'label' => 'managesieve.filtercreate',
'type' => 'link',
'classact' => 'icon filterlink active',
'class' => 'icon filterlink',
'innerclass' => 'icon filterlink',
))), 'messagemenu');
// register some labels/messages
$this->rc->output->add_label('managesieve.newfilter', 'managesieve.usedata',
'managesieve.nodata', 'managesieve.nextstep', 'save');
$this->rc->session->remove('managesieve_current');
} | php | function mail_task_handler()
{
// make sure we're not in ajax request
if ($this->rc->output->type != 'html') {
return;
}
// use jQuery for popup window
$this->require_plugin('jqueryui');
// include js script and localization
$this->init_ui();
// add 'Create filter' item to message menu
$this->api->add_content(html::tag('li', null,
$this->api->output->button(array(
'command' => 'managesieve-create',
'label' => 'managesieve.filtercreate',
'type' => 'link',
'classact' => 'icon filterlink active',
'class' => 'icon filterlink',
'innerclass' => 'icon filterlink',
))), 'messagemenu');
// register some labels/messages
$this->rc->output->add_label('managesieve.newfilter', 'managesieve.usedata',
'managesieve.nodata', 'managesieve.nextstep', 'save');
$this->rc->session->remove('managesieve_current');
} | [
"function",
"mail_task_handler",
"(",
")",
"{",
"// make sure we're not in ajax request",
"if",
"(",
"$",
"this",
"->",
"rc",
"->",
"output",
"->",
"type",
"!=",
"'html'",
")",
"{",
"return",
";",
"}",
"// use jQuery for popup window",
"$",
"this",
"->",
"require_plugin",
"(",
"'jqueryui'",
")",
";",
"// include js script and localization",
"$",
"this",
"->",
"init_ui",
"(",
")",
";",
"// add 'Create filter' item to message menu",
"$",
"this",
"->",
"api",
"->",
"add_content",
"(",
"html",
"::",
"tag",
"(",
"'li'",
",",
"null",
",",
"$",
"this",
"->",
"api",
"->",
"output",
"->",
"button",
"(",
"array",
"(",
"'command'",
"=>",
"'managesieve-create'",
",",
"'label'",
"=>",
"'managesieve.filtercreate'",
",",
"'type'",
"=>",
"'link'",
",",
"'classact'",
"=>",
"'icon filterlink active'",
",",
"'class'",
"=>",
"'icon filterlink'",
",",
"'innerclass'",
"=>",
"'icon filterlink'",
",",
")",
")",
")",
",",
"'messagemenu'",
")",
";",
"// register some labels/messages",
"$",
"this",
"->",
"rc",
"->",
"output",
"->",
"add_label",
"(",
"'managesieve.newfilter'",
",",
"'managesieve.usedata'",
",",
"'managesieve.nodata'",
",",
"'managesieve.nextstep'",
",",
"'save'",
")",
";",
"$",
"this",
"->",
"rc",
"->",
"session",
"->",
"remove",
"(",
"'managesieve_current'",
")",
";",
"}"
]
| Add UI elements to the 'mailbox view' and 'show message' UI. | [
"Add",
"UI",
"elements",
"to",
"the",
"mailbox",
"view",
"and",
"show",
"message",
"UI",
"."
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/managesieve.php#L134-L163 | train |
i-MSCP/roundcube | roundcubemail/plugins/managesieve/managesieve.php | managesieve.mail_headers | function mail_headers($args)
{
// this hook can be executed many times
if ($this->mail_headers_done) {
return $args;
}
$this->mail_headers_done = true;
$headers = $this->parse_headers($args['headers']);
if ($this->rc->action == 'preview')
$this->rc->output->command('parent.set_env', array('sieve_headers' => $headers));
else
$this->rc->output->set_env('sieve_headers', $headers);
return $args;
} | php | function mail_headers($args)
{
// this hook can be executed many times
if ($this->mail_headers_done) {
return $args;
}
$this->mail_headers_done = true;
$headers = $this->parse_headers($args['headers']);
if ($this->rc->action == 'preview')
$this->rc->output->command('parent.set_env', array('sieve_headers' => $headers));
else
$this->rc->output->set_env('sieve_headers', $headers);
return $args;
} | [
"function",
"mail_headers",
"(",
"$",
"args",
")",
"{",
"// this hook can be executed many times",
"if",
"(",
"$",
"this",
"->",
"mail_headers_done",
")",
"{",
"return",
"$",
"args",
";",
"}",
"$",
"this",
"->",
"mail_headers_done",
"=",
"true",
";",
"$",
"headers",
"=",
"$",
"this",
"->",
"parse_headers",
"(",
"$",
"args",
"[",
"'headers'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"rc",
"->",
"action",
"==",
"'preview'",
")",
"$",
"this",
"->",
"rc",
"->",
"output",
"->",
"command",
"(",
"'parent.set_env'",
",",
"array",
"(",
"'sieve_headers'",
"=>",
"$",
"headers",
")",
")",
";",
"else",
"$",
"this",
"->",
"rc",
"->",
"output",
"->",
"set_env",
"(",
"'sieve_headers'",
",",
"$",
"headers",
")",
";",
"return",
"$",
"args",
";",
"}"
]
| Get message headers for popup window | [
"Get",
"message",
"headers",
"for",
"popup",
"window"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/managesieve.php#L168-L185 | train |
i-MSCP/roundcube | roundcubemail/plugins/managesieve/managesieve.php | managesieve.managesieve_actions | function managesieve_actions()
{
$uids = rcmail::get_uids(null, null, $multifolder, rcube_utils::INPUT_POST);
// handle fetching email headers for the new filter form
if (!empty($uids)) {
$mailbox = key($uids);
$message = new rcube_message($uids[$mailbox][0], $mailbox);
$headers = $this->parse_headers($message->headers);
$this->rc->output->set_env('sieve_headers', $headers);
$this->rc->output->command('managesieve_create', true);
$this->rc->output->send();
}
// handle other actions
$engine_type = $this->rc->action == 'plugin.managesieve-vacation' ? 'vacation' : '';
$engine = $this->get_engine($engine_type);
$this->init_ui();
$engine->actions();
} | php | function managesieve_actions()
{
$uids = rcmail::get_uids(null, null, $multifolder, rcube_utils::INPUT_POST);
// handle fetching email headers for the new filter form
if (!empty($uids)) {
$mailbox = key($uids);
$message = new rcube_message($uids[$mailbox][0], $mailbox);
$headers = $this->parse_headers($message->headers);
$this->rc->output->set_env('sieve_headers', $headers);
$this->rc->output->command('managesieve_create', true);
$this->rc->output->send();
}
// handle other actions
$engine_type = $this->rc->action == 'plugin.managesieve-vacation' ? 'vacation' : '';
$engine = $this->get_engine($engine_type);
$this->init_ui();
$engine->actions();
} | [
"function",
"managesieve_actions",
"(",
")",
"{",
"$",
"uids",
"=",
"rcmail",
"::",
"get_uids",
"(",
"null",
",",
"null",
",",
"$",
"multifolder",
",",
"rcube_utils",
"::",
"INPUT_POST",
")",
";",
"// handle fetching email headers for the new filter form",
"if",
"(",
"!",
"empty",
"(",
"$",
"uids",
")",
")",
"{",
"$",
"mailbox",
"=",
"key",
"(",
"$",
"uids",
")",
";",
"$",
"message",
"=",
"new",
"rcube_message",
"(",
"$",
"uids",
"[",
"$",
"mailbox",
"]",
"[",
"0",
"]",
",",
"$",
"mailbox",
")",
";",
"$",
"headers",
"=",
"$",
"this",
"->",
"parse_headers",
"(",
"$",
"message",
"->",
"headers",
")",
";",
"$",
"this",
"->",
"rc",
"->",
"output",
"->",
"set_env",
"(",
"'sieve_headers'",
",",
"$",
"headers",
")",
";",
"$",
"this",
"->",
"rc",
"->",
"output",
"->",
"command",
"(",
"'managesieve_create'",
",",
"true",
")",
";",
"$",
"this",
"->",
"rc",
"->",
"output",
"->",
"send",
"(",
")",
";",
"}",
"// handle other actions",
"$",
"engine_type",
"=",
"$",
"this",
"->",
"rc",
"->",
"action",
"==",
"'plugin.managesieve-vacation'",
"?",
"'vacation'",
":",
"''",
";",
"$",
"engine",
"=",
"$",
"this",
"->",
"get_engine",
"(",
"$",
"engine_type",
")",
";",
"$",
"this",
"->",
"init_ui",
"(",
")",
";",
"$",
"engine",
"->",
"actions",
"(",
")",
";",
"}"
]
| Plugin action handler | [
"Plugin",
"action",
"handler"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/managesieve.php#L190-L211 | train |
i-MSCP/roundcube | roundcubemail/plugins/managesieve/managesieve.php | managesieve.managesieve_save | function managesieve_save()
{
// load localization
$this->add_texts('localization/', array('filters','managefilters'));
// include main js script
if ($this->api->output->type == 'html') {
$this->include_script('managesieve.js');
}
$engine = $this->get_engine();
$engine->save();
} | php | function managesieve_save()
{
// load localization
$this->add_texts('localization/', array('filters','managefilters'));
// include main js script
if ($this->api->output->type == 'html') {
$this->include_script('managesieve.js');
}
$engine = $this->get_engine();
$engine->save();
} | [
"function",
"managesieve_save",
"(",
")",
"{",
"// load localization",
"$",
"this",
"->",
"add_texts",
"(",
"'localization/'",
",",
"array",
"(",
"'filters'",
",",
"'managefilters'",
")",
")",
";",
"// include main js script",
"if",
"(",
"$",
"this",
"->",
"api",
"->",
"output",
"->",
"type",
"==",
"'html'",
")",
"{",
"$",
"this",
"->",
"include_script",
"(",
"'managesieve.js'",
")",
";",
"}",
"$",
"engine",
"=",
"$",
"this",
"->",
"get_engine",
"(",
")",
";",
"$",
"engine",
"->",
"save",
"(",
")",
";",
"}"
]
| Forms save action handler | [
"Forms",
"save",
"action",
"handler"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/managesieve.php#L216-L228 | train |
i-MSCP/roundcube | roundcubemail/plugins/managesieve/managesieve.php | managesieve.managesieve_saveraw | function managesieve_saveraw()
{
$engine = $this->get_engine();
if (!$this->rc->config->get('managesieve_raw_editor', true)) {
return;
}
// load localization
$this->add_texts('localization/', array('filters','managefilters'));
$engine->saveraw();
} | php | function managesieve_saveraw()
{
$engine = $this->get_engine();
if (!$this->rc->config->get('managesieve_raw_editor', true)) {
return;
}
// load localization
$this->add_texts('localization/', array('filters','managefilters'));
$engine->saveraw();
} | [
"function",
"managesieve_saveraw",
"(",
")",
"{",
"$",
"engine",
"=",
"$",
"this",
"->",
"get_engine",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"rc",
"->",
"config",
"->",
"get",
"(",
"'managesieve_raw_editor'",
",",
"true",
")",
")",
"{",
"return",
";",
"}",
"// load localization",
"$",
"this",
"->",
"add_texts",
"(",
"'localization/'",
",",
"array",
"(",
"'filters'",
",",
"'managefilters'",
")",
")",
";",
"$",
"engine",
"->",
"saveraw",
"(",
")",
";",
"}"
]
| Raw form save action handler | [
"Raw",
"form",
"save",
"action",
"handler"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/managesieve.php#L233-L245 | train |
i-MSCP/roundcube | roundcubemail/plugins/managesieve/managesieve.php | managesieve.get_engine | public function get_engine($type = null)
{
if (!$this->engine) {
$this->load_config();
// Add include path for internal classes
$include_path = $this->home . '/lib' . PATH_SEPARATOR;
$include_path .= ini_get('include_path');
set_include_path($include_path);
$class_name = 'rcube_sieve_' . ($type ?: 'engine');
$this->engine = new $class_name($this);
}
return $this->engine;
} | php | public function get_engine($type = null)
{
if (!$this->engine) {
$this->load_config();
// Add include path for internal classes
$include_path = $this->home . '/lib' . PATH_SEPARATOR;
$include_path .= ini_get('include_path');
set_include_path($include_path);
$class_name = 'rcube_sieve_' . ($type ?: 'engine');
$this->engine = new $class_name($this);
}
return $this->engine;
} | [
"public",
"function",
"get_engine",
"(",
"$",
"type",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"engine",
")",
"{",
"$",
"this",
"->",
"load_config",
"(",
")",
";",
"// Add include path for internal classes",
"$",
"include_path",
"=",
"$",
"this",
"->",
"home",
".",
"'/lib'",
".",
"PATH_SEPARATOR",
";",
"$",
"include_path",
".=",
"ini_get",
"(",
"'include_path'",
")",
";",
"set_include_path",
"(",
"$",
"include_path",
")",
";",
"$",
"class_name",
"=",
"'rcube_sieve_'",
".",
"(",
"$",
"type",
"?",
":",
"'engine'",
")",
";",
"$",
"this",
"->",
"engine",
"=",
"new",
"$",
"class_name",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
"->",
"engine",
";",
"}"
]
| Initializes engine object | [
"Initializes",
"engine",
"object"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/managesieve.php#L250-L265 | train |
i-MSCP/roundcube | roundcubemail/plugins/managesieve/managesieve.php | managesieve.parse_headers | private function parse_headers($headers)
{
$result = array();
if ($headers->subject)
$result[] = array('Subject', rcube_mime::decode_header($headers->subject));
// @TODO: List-Id, others?
foreach (array('From', 'To') as $h) {
$hl = strtolower($h);
if ($headers->$hl) {
$list = rcube_mime::decode_address_list($headers->$hl);
foreach ($list as $item) {
if ($item['mailto']) {
$result[] = array($h, $item['mailto']);
}
}
}
}
return $result;
} | php | private function parse_headers($headers)
{
$result = array();
if ($headers->subject)
$result[] = array('Subject', rcube_mime::decode_header($headers->subject));
// @TODO: List-Id, others?
foreach (array('From', 'To') as $h) {
$hl = strtolower($h);
if ($headers->$hl) {
$list = rcube_mime::decode_address_list($headers->$hl);
foreach ($list as $item) {
if ($item['mailto']) {
$result[] = array($h, $item['mailto']);
}
}
}
}
return $result;
} | [
"private",
"function",
"parse_headers",
"(",
"$",
"headers",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"headers",
"->",
"subject",
")",
"$",
"result",
"[",
"]",
"=",
"array",
"(",
"'Subject'",
",",
"rcube_mime",
"::",
"decode_header",
"(",
"$",
"headers",
"->",
"subject",
")",
")",
";",
"// @TODO: List-Id, others?",
"foreach",
"(",
"array",
"(",
"'From'",
",",
"'To'",
")",
"as",
"$",
"h",
")",
"{",
"$",
"hl",
"=",
"strtolower",
"(",
"$",
"h",
")",
";",
"if",
"(",
"$",
"headers",
"->",
"$",
"hl",
")",
"{",
"$",
"list",
"=",
"rcube_mime",
"::",
"decode_address_list",
"(",
"$",
"headers",
"->",
"$",
"hl",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"[",
"'mailto'",
"]",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"array",
"(",
"$",
"h",
",",
"$",
"item",
"[",
"'mailto'",
"]",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
]
| Extract mail headers for new filter form | [
"Extract",
"mail",
"headers",
"for",
"new",
"filter",
"form"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/managesieve.php#L270-L291 | train |
i-MSCP/roundcube | roundcubemail/program/lib/Roundcube/rcube_db_sqlite.php | rcube_db_sqlite.conn_configure | protected function conn_configure($dsn, $dbh)
{
// Initialize database structure in file is empty
if (!empty($dsn['database']) && !filesize($dsn['database'])) {
$data = file_get_contents(RCUBE_INSTALL_PATH . 'SQL/sqlite.initial.sql');
if (strlen($data)) {
$this->debug('INITIALIZE DATABASE');
$q = $dbh->exec($data);
if ($q === false) {
$error = $dbh->errorInfo();
$this->db_error = true;
$this->db_error_msg = sprintf('[%s] %s', $error[1], $error[2]);
rcube::raise_error(array('code' => 500, 'type' => 'db',
'line' => __LINE__, 'file' => __FILE__,
'message' => $this->db_error_msg), true, false);
}
}
}
} | php | protected function conn_configure($dsn, $dbh)
{
// Initialize database structure in file is empty
if (!empty($dsn['database']) && !filesize($dsn['database'])) {
$data = file_get_contents(RCUBE_INSTALL_PATH . 'SQL/sqlite.initial.sql');
if (strlen($data)) {
$this->debug('INITIALIZE DATABASE');
$q = $dbh->exec($data);
if ($q === false) {
$error = $dbh->errorInfo();
$this->db_error = true;
$this->db_error_msg = sprintf('[%s] %s', $error[1], $error[2]);
rcube::raise_error(array('code' => 500, 'type' => 'db',
'line' => __LINE__, 'file' => __FILE__,
'message' => $this->db_error_msg), true, false);
}
}
}
} | [
"protected",
"function",
"conn_configure",
"(",
"$",
"dsn",
",",
"$",
"dbh",
")",
"{",
"// Initialize database structure in file is empty",
"if",
"(",
"!",
"empty",
"(",
"$",
"dsn",
"[",
"'database'",
"]",
")",
"&&",
"!",
"filesize",
"(",
"$",
"dsn",
"[",
"'database'",
"]",
")",
")",
"{",
"$",
"data",
"=",
"file_get_contents",
"(",
"RCUBE_INSTALL_PATH",
".",
"'SQL/sqlite.initial.sql'",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"debug",
"(",
"'INITIALIZE DATABASE'",
")",
";",
"$",
"q",
"=",
"$",
"dbh",
"->",
"exec",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"q",
"===",
"false",
")",
"{",
"$",
"error",
"=",
"$",
"dbh",
"->",
"errorInfo",
"(",
")",
";",
"$",
"this",
"->",
"db_error",
"=",
"true",
";",
"$",
"this",
"->",
"db_error_msg",
"=",
"sprintf",
"(",
"'[%s] %s'",
",",
"$",
"error",
"[",
"1",
"]",
",",
"$",
"error",
"[",
"2",
"]",
")",
";",
"rcube",
"::",
"raise_error",
"(",
"array",
"(",
"'code'",
"=>",
"500",
",",
"'type'",
"=>",
"'db'",
",",
"'line'",
"=>",
"__LINE__",
",",
"'file'",
"=>",
"__FILE__",
",",
"'message'",
"=>",
"$",
"this",
"->",
"db_error_msg",
")",
",",
"true",
",",
"false",
")",
";",
"}",
"}",
"}",
"}"
]
| Configure connection, create database if not exists | [
"Configure",
"connection",
"create",
"database",
"if",
"not",
"exists"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_db_sqlite.php#L50-L72 | train |
i-MSCP/roundcube | roundcubemail/plugins/password/drivers/ldap.php | rcube_ldap_password.search_userdn | function search_userdn($rcmail)
{
$binddn = $rcmail->config->get('password_ldap_searchDN');
$bindpw = $rcmail->config->get('password_ldap_searchPW');
$ldapConfig = array (
'basedn' => $rcmail->config->get('password_ldap_basedn'),
'host' => $rcmail->config->get('password_ldap_host', 'localhost'),
'port' => $rcmail->config->get('password_ldap_port', '389'),
'starttls' => $rcmail->config->get('password_ldap_starttls'),
'version' => $rcmail->config->get('password_ldap_version', '3'),
);
// allow anonymous searches
if (!empty($binddn)) {
$ldapConfig['binddn'] = $binddn;
$ldapConfig['bindpw'] = $bindpw;
}
$ldap = Net_LDAP2::connect($ldapConfig);
if (is_a($ldap, 'PEAR_Error')) {
return '';
}
$base = self::substitute_vars($rcmail->config->get('password_ldap_search_base'));
$filter = self::substitute_vars($rcmail->config->get('password_ldap_search_filter'));
$options = array (
'scope' => 'sub',
'attributes' => array(),
);
$result = $ldap->search($base, $filter, $options);
if (is_a($result, 'PEAR_Error') || ($result->count() != 1)) {
$ldap->done();
return '';
}
$userDN = $result->current()->dn();
$ldap->done();
return $userDN;
} | php | function search_userdn($rcmail)
{
$binddn = $rcmail->config->get('password_ldap_searchDN');
$bindpw = $rcmail->config->get('password_ldap_searchPW');
$ldapConfig = array (
'basedn' => $rcmail->config->get('password_ldap_basedn'),
'host' => $rcmail->config->get('password_ldap_host', 'localhost'),
'port' => $rcmail->config->get('password_ldap_port', '389'),
'starttls' => $rcmail->config->get('password_ldap_starttls'),
'version' => $rcmail->config->get('password_ldap_version', '3'),
);
// allow anonymous searches
if (!empty($binddn)) {
$ldapConfig['binddn'] = $binddn;
$ldapConfig['bindpw'] = $bindpw;
}
$ldap = Net_LDAP2::connect($ldapConfig);
if (is_a($ldap, 'PEAR_Error')) {
return '';
}
$base = self::substitute_vars($rcmail->config->get('password_ldap_search_base'));
$filter = self::substitute_vars($rcmail->config->get('password_ldap_search_filter'));
$options = array (
'scope' => 'sub',
'attributes' => array(),
);
$result = $ldap->search($base, $filter, $options);
if (is_a($result, 'PEAR_Error') || ($result->count() != 1)) {
$ldap->done();
return '';
}
$userDN = $result->current()->dn();
$ldap->done();
return $userDN;
} | [
"function",
"search_userdn",
"(",
"$",
"rcmail",
")",
"{",
"$",
"binddn",
"=",
"$",
"rcmail",
"->",
"config",
"->",
"get",
"(",
"'password_ldap_searchDN'",
")",
";",
"$",
"bindpw",
"=",
"$",
"rcmail",
"->",
"config",
"->",
"get",
"(",
"'password_ldap_searchPW'",
")",
";",
"$",
"ldapConfig",
"=",
"array",
"(",
"'basedn'",
"=>",
"$",
"rcmail",
"->",
"config",
"->",
"get",
"(",
"'password_ldap_basedn'",
")",
",",
"'host'",
"=>",
"$",
"rcmail",
"->",
"config",
"->",
"get",
"(",
"'password_ldap_host'",
",",
"'localhost'",
")",
",",
"'port'",
"=>",
"$",
"rcmail",
"->",
"config",
"->",
"get",
"(",
"'password_ldap_port'",
",",
"'389'",
")",
",",
"'starttls'",
"=>",
"$",
"rcmail",
"->",
"config",
"->",
"get",
"(",
"'password_ldap_starttls'",
")",
",",
"'version'",
"=>",
"$",
"rcmail",
"->",
"config",
"->",
"get",
"(",
"'password_ldap_version'",
",",
"'3'",
")",
",",
")",
";",
"// allow anonymous searches",
"if",
"(",
"!",
"empty",
"(",
"$",
"binddn",
")",
")",
"{",
"$",
"ldapConfig",
"[",
"'binddn'",
"]",
"=",
"$",
"binddn",
";",
"$",
"ldapConfig",
"[",
"'bindpw'",
"]",
"=",
"$",
"bindpw",
";",
"}",
"$",
"ldap",
"=",
"Net_LDAP2",
"::",
"connect",
"(",
"$",
"ldapConfig",
")",
";",
"if",
"(",
"is_a",
"(",
"$",
"ldap",
",",
"'PEAR_Error'",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"base",
"=",
"self",
"::",
"substitute_vars",
"(",
"$",
"rcmail",
"->",
"config",
"->",
"get",
"(",
"'password_ldap_search_base'",
")",
")",
";",
"$",
"filter",
"=",
"self",
"::",
"substitute_vars",
"(",
"$",
"rcmail",
"->",
"config",
"->",
"get",
"(",
"'password_ldap_search_filter'",
")",
")",
";",
"$",
"options",
"=",
"array",
"(",
"'scope'",
"=>",
"'sub'",
",",
"'attributes'",
"=>",
"array",
"(",
")",
",",
")",
";",
"$",
"result",
"=",
"$",
"ldap",
"->",
"search",
"(",
"$",
"base",
",",
"$",
"filter",
",",
"$",
"options",
")",
";",
"if",
"(",
"is_a",
"(",
"$",
"result",
",",
"'PEAR_Error'",
")",
"||",
"(",
"$",
"result",
"->",
"count",
"(",
")",
"!=",
"1",
")",
")",
"{",
"$",
"ldap",
"->",
"done",
"(",
")",
";",
"return",
"''",
";",
"}",
"$",
"userDN",
"=",
"$",
"result",
"->",
"current",
"(",
")",
"->",
"dn",
"(",
")",
";",
"$",
"ldap",
"->",
"done",
"(",
")",
";",
"return",
"$",
"userDN",
";",
"}"
]
| Bind with searchDN and searchPW and search for the user's DN.
Use search_base and search_filter defined in config file.
Return the found DN. | [
"Bind",
"with",
"searchDN",
"and",
"searchPW",
"and",
"search",
"for",
"the",
"user",
"s",
"DN",
".",
"Use",
"search_base",
"and",
"search_filter",
"defined",
"in",
"config",
"file",
".",
"Return",
"the",
"found",
"DN",
"."
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/password/drivers/ldap.php#L157-L198 | train |
i-MSCP/roundcube | roundcubemail/program/lib/Roundcube/rcube_result_thread.php | rcube_result_thread.init | public function init($data = null)
{
$this->meta = array();
$data = explode('*', (string)$data);
// ...skip unilateral untagged server responses
for ($i=0, $len=count($data); $i<$len; $i++) {
if (preg_match('/^ THREAD/i', $data[$i])) {
// valid response, initialize raw_data for is_error()
$this->raw_data = '';
$data[$i] = substr($data[$i], 7);
break;
}
unset($data[$i]);
}
if (empty($data)) {
return;
}
$data = array_shift($data);
$data = trim($data);
$data = preg_replace('/[\r\n]/', '', $data);
$data = preg_replace('/\s+/', ' ', $data);
$this->raw_data = $this->parse_thread($data);
} | php | public function init($data = null)
{
$this->meta = array();
$data = explode('*', (string)$data);
// ...skip unilateral untagged server responses
for ($i=0, $len=count($data); $i<$len; $i++) {
if (preg_match('/^ THREAD/i', $data[$i])) {
// valid response, initialize raw_data for is_error()
$this->raw_data = '';
$data[$i] = substr($data[$i], 7);
break;
}
unset($data[$i]);
}
if (empty($data)) {
return;
}
$data = array_shift($data);
$data = trim($data);
$data = preg_replace('/[\r\n]/', '', $data);
$data = preg_replace('/\s+/', ' ', $data);
$this->raw_data = $this->parse_thread($data);
} | [
"public",
"function",
"init",
"(",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"meta",
"=",
"array",
"(",
")",
";",
"$",
"data",
"=",
"explode",
"(",
"'*'",
",",
"(",
"string",
")",
"$",
"data",
")",
";",
"// ...skip unilateral untagged server responses",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"len",
"=",
"count",
"(",
"$",
"data",
")",
";",
"$",
"i",
"<",
"$",
"len",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^ THREAD/i'",
",",
"$",
"data",
"[",
"$",
"i",
"]",
")",
")",
"{",
"// valid response, initialize raw_data for is_error()",
"$",
"this",
"->",
"raw_data",
"=",
"''",
";",
"$",
"data",
"[",
"$",
"i",
"]",
"=",
"substr",
"(",
"$",
"data",
"[",
"$",
"i",
"]",
",",
"7",
")",
";",
"break",
";",
"}",
"unset",
"(",
"$",
"data",
"[",
"$",
"i",
"]",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"return",
";",
"}",
"$",
"data",
"=",
"array_shift",
"(",
"$",
"data",
")",
";",
"$",
"data",
"=",
"trim",
"(",
"$",
"data",
")",
";",
"$",
"data",
"=",
"preg_replace",
"(",
"'/[\\r\\n]/'",
",",
"''",
",",
"$",
"data",
")",
";",
"$",
"data",
"=",
"preg_replace",
"(",
"'/\\s+/'",
",",
"' '",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"raw_data",
"=",
"$",
"this",
"->",
"parse_thread",
"(",
"$",
"data",
")",
";",
"}"
]
| Initializes object with IMAP command response
@param string $data IMAP response string | [
"Initializes",
"object",
"with",
"IMAP",
"command",
"response"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_result_thread.php#L55-L83 | train |
i-MSCP/roundcube | roundcubemail/program/lib/Roundcube/rcube_result_thread.php | rcube_result_thread.count_messages | public function count_messages()
{
if ($this->meta['messages'] !== null)
return $this->meta['messages'];
if (empty($this->raw_data)) {
$this->meta['messages'] = 0;
}
else {
$this->meta['messages'] = 1
+ substr_count($this->raw_data, self::SEPARATOR_ELEMENT)
+ substr_count($this->raw_data, self::SEPARATOR_ITEM);
}
if ($this->meta['messages'] == 0 || $this->meta['messages'] == 1)
$this->meta['count'] = $this->meta['messages'];
return $this->meta['messages'];
} | php | public function count_messages()
{
if ($this->meta['messages'] !== null)
return $this->meta['messages'];
if (empty($this->raw_data)) {
$this->meta['messages'] = 0;
}
else {
$this->meta['messages'] = 1
+ substr_count($this->raw_data, self::SEPARATOR_ELEMENT)
+ substr_count($this->raw_data, self::SEPARATOR_ITEM);
}
if ($this->meta['messages'] == 0 || $this->meta['messages'] == 1)
$this->meta['count'] = $this->meta['messages'];
return $this->meta['messages'];
} | [
"public",
"function",
"count_messages",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"meta",
"[",
"'messages'",
"]",
"!==",
"null",
")",
"return",
"$",
"this",
"->",
"meta",
"[",
"'messages'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"raw_data",
")",
")",
"{",
"$",
"this",
"->",
"meta",
"[",
"'messages'",
"]",
"=",
"0",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"meta",
"[",
"'messages'",
"]",
"=",
"1",
"+",
"substr_count",
"(",
"$",
"this",
"->",
"raw_data",
",",
"self",
"::",
"SEPARATOR_ELEMENT",
")",
"+",
"substr_count",
"(",
"$",
"this",
"->",
"raw_data",
",",
"self",
"::",
"SEPARATOR_ITEM",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"meta",
"[",
"'messages'",
"]",
"==",
"0",
"||",
"$",
"this",
"->",
"meta",
"[",
"'messages'",
"]",
"==",
"1",
")",
"$",
"this",
"->",
"meta",
"[",
"'count'",
"]",
"=",
"$",
"this",
"->",
"meta",
"[",
"'messages'",
"]",
";",
"return",
"$",
"this",
"->",
"meta",
"[",
"'messages'",
"]",
";",
"}"
]
| Returns number of all messages in the result
@return int Number of elements | [
"Returns",
"number",
"of",
"all",
"messages",
"in",
"the",
"result"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_result_thread.php#L133-L151 | train |
i-MSCP/roundcube | roundcubemail/program/lib/Roundcube/rcube_result_thread.php | rcube_result_thread.get | public function get()
{
if (empty($this->raw_data)) {
return array();
}
$regexp = '/(' . preg_quote(self::SEPARATOR_ELEMENT, '/')
. '|' . preg_quote(self::SEPARATOR_ITEM, '/') . '[0-9]+' . preg_quote(self::SEPARATOR_LEVEL, '/')
.')/';
return preg_split($regexp, $this->raw_data);
} | php | public function get()
{
if (empty($this->raw_data)) {
return array();
}
$regexp = '/(' . preg_quote(self::SEPARATOR_ELEMENT, '/')
. '|' . preg_quote(self::SEPARATOR_ITEM, '/') . '[0-9]+' . preg_quote(self::SEPARATOR_LEVEL, '/')
.')/';
return preg_split($regexp, $this->raw_data);
} | [
"public",
"function",
"get",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"raw_data",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"regexp",
"=",
"'/('",
".",
"preg_quote",
"(",
"self",
"::",
"SEPARATOR_ELEMENT",
",",
"'/'",
")",
".",
"'|'",
".",
"preg_quote",
"(",
"self",
"::",
"SEPARATOR_ITEM",
",",
"'/'",
")",
".",
"'[0-9]+'",
".",
"preg_quote",
"(",
"self",
"::",
"SEPARATOR_LEVEL",
",",
"'/'",
")",
".",
"')/'",
";",
"return",
"preg_split",
"(",
"$",
"regexp",
",",
"$",
"this",
"->",
"raw_data",
")",
";",
"}"
]
| Return IDs of all messages in the result. Threaded data will be flattened.
@return array List of message identifiers | [
"Return",
"IDs",
"of",
"all",
"messages",
"in",
"the",
"result",
".",
"Threaded",
"data",
"will",
"be",
"flattened",
"."
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_result_thread.php#L300-L311 | train |
i-MSCP/roundcube | roundcubemail/program/lib/Roundcube/rcube_result_thread.php | rcube_result_thread.get_tree | public function get_tree()
{
$datalen = strlen($this->raw_data);
$result = array();
$start = 0;
while (($pos = @strpos($this->raw_data, self::SEPARATOR_ELEMENT, $start))
|| ($start < $datalen && ($pos = $datalen))
) {
$len = $pos - $start;
$elem = substr($this->raw_data, $start, $len);
$items = explode(self::SEPARATOR_ITEM, $elem);
$result[array_shift($items)] = $this->build_thread($items);
$start = $pos + 1;
}
return $result;
} | php | public function get_tree()
{
$datalen = strlen($this->raw_data);
$result = array();
$start = 0;
while (($pos = @strpos($this->raw_data, self::SEPARATOR_ELEMENT, $start))
|| ($start < $datalen && ($pos = $datalen))
) {
$len = $pos - $start;
$elem = substr($this->raw_data, $start, $len);
$items = explode(self::SEPARATOR_ITEM, $elem);
$result[array_shift($items)] = $this->build_thread($items);
$start = $pos + 1;
}
return $result;
} | [
"public",
"function",
"get_tree",
"(",
")",
"{",
"$",
"datalen",
"=",
"strlen",
"(",
"$",
"this",
"->",
"raw_data",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"start",
"=",
"0",
";",
"while",
"(",
"(",
"$",
"pos",
"=",
"@",
"strpos",
"(",
"$",
"this",
"->",
"raw_data",
",",
"self",
"::",
"SEPARATOR_ELEMENT",
",",
"$",
"start",
")",
")",
"||",
"(",
"$",
"start",
"<",
"$",
"datalen",
"&&",
"(",
"$",
"pos",
"=",
"$",
"datalen",
")",
")",
")",
"{",
"$",
"len",
"=",
"$",
"pos",
"-",
"$",
"start",
";",
"$",
"elem",
"=",
"substr",
"(",
"$",
"this",
"->",
"raw_data",
",",
"$",
"start",
",",
"$",
"len",
")",
";",
"$",
"items",
"=",
"explode",
"(",
"self",
"::",
"SEPARATOR_ITEM",
",",
"$",
"elem",
")",
";",
"$",
"result",
"[",
"array_shift",
"(",
"$",
"items",
")",
"]",
"=",
"$",
"this",
"->",
"build_thread",
"(",
"$",
"items",
")",
";",
"$",
"start",
"=",
"$",
"pos",
"+",
"1",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Returns data as tree
@return array Data tree | [
"Returns",
"data",
"as",
"tree"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_result_thread.php#L490-L507 | train |
i-MSCP/roundcube | roundcubemail/program/lib/Roundcube/rcube_result_thread.php | rcube_result_thread.get_thread_data | public function get_thread_data()
{
$data = $this->get_tree();
$depth = array();
$children = array();
$this->build_thread_data($data, $depth, $children);
return array($depth, $children);
} | php | public function get_thread_data()
{
$data = $this->get_tree();
$depth = array();
$children = array();
$this->build_thread_data($data, $depth, $children);
return array($depth, $children);
} | [
"public",
"function",
"get_thread_data",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"get_tree",
"(",
")",
";",
"$",
"depth",
"=",
"array",
"(",
")",
";",
"$",
"children",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"build_thread_data",
"(",
"$",
"data",
",",
"$",
"depth",
",",
"$",
"children",
")",
";",
"return",
"array",
"(",
"$",
"depth",
",",
"$",
"children",
")",
";",
"}"
]
| Returns thread depth and children data
@return array Thread data | [
"Returns",
"thread",
"depth",
"and",
"children",
"data"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_result_thread.php#L514-L523 | train |
i-MSCP/roundcube | roundcubemail/program/lib/Roundcube/rcube_result_thread.php | rcube_result_thread.build_thread_data | protected function build_thread_data($data, &$depth, &$children, $level = 0)
{
foreach ((array)$data as $key => $val) {
$empty = empty($val) || !is_array($val);
$children[$key] = !$empty;
$depth[$key] = $level;
if (!$empty) {
$this->build_thread_data($val, $depth, $children, $level + 1);
}
}
} | php | protected function build_thread_data($data, &$depth, &$children, $level = 0)
{
foreach ((array)$data as $key => $val) {
$empty = empty($val) || !is_array($val);
$children[$key] = !$empty;
$depth[$key] = $level;
if (!$empty) {
$this->build_thread_data($val, $depth, $children, $level + 1);
}
}
} | [
"protected",
"function",
"build_thread_data",
"(",
"$",
"data",
",",
"&",
"$",
"depth",
",",
"&",
"$",
"children",
",",
"$",
"level",
"=",
"0",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"empty",
"=",
"empty",
"(",
"$",
"val",
")",
"||",
"!",
"is_array",
"(",
"$",
"val",
")",
";",
"$",
"children",
"[",
"$",
"key",
"]",
"=",
"!",
"$",
"empty",
";",
"$",
"depth",
"[",
"$",
"key",
"]",
"=",
"$",
"level",
";",
"if",
"(",
"!",
"$",
"empty",
")",
"{",
"$",
"this",
"->",
"build_thread_data",
"(",
"$",
"val",
",",
"$",
"depth",
",",
"$",
"children",
",",
"$",
"level",
"+",
"1",
")",
";",
"}",
"}",
"}"
]
| Creates 'depth' and 'children' arrays from stored thread 'tree' data. | [
"Creates",
"depth",
"and",
"children",
"arrays",
"from",
"stored",
"thread",
"tree",
"data",
"."
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_result_thread.php#L528-L538 | train |
i-MSCP/roundcube | roundcubemail/program/lib/Roundcube/rcube_result_thread.php | rcube_result_thread.build_thread | protected function build_thread($items, $level = 1, &$pos = 0)
{
$result = array();
for ($len=count($items); $pos < $len; $pos++) {
list($lv, $id) = explode(self::SEPARATOR_LEVEL, $items[$pos]);
if ($level == $lv) {
$pos++;
$result[$id] = $this->build_thread($items, $level+1, $pos);
}
else {
$pos--;
break;
}
}
return $result;
} | php | protected function build_thread($items, $level = 1, &$pos = 0)
{
$result = array();
for ($len=count($items); $pos < $len; $pos++) {
list($lv, $id) = explode(self::SEPARATOR_LEVEL, $items[$pos]);
if ($level == $lv) {
$pos++;
$result[$id] = $this->build_thread($items, $level+1, $pos);
}
else {
$pos--;
break;
}
}
return $result;
} | [
"protected",
"function",
"build_thread",
"(",
"$",
"items",
",",
"$",
"level",
"=",
"1",
",",
"&",
"$",
"pos",
"=",
"0",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"len",
"=",
"count",
"(",
"$",
"items",
")",
";",
"$",
"pos",
"<",
"$",
"len",
";",
"$",
"pos",
"++",
")",
"{",
"list",
"(",
"$",
"lv",
",",
"$",
"id",
")",
"=",
"explode",
"(",
"self",
"::",
"SEPARATOR_LEVEL",
",",
"$",
"items",
"[",
"$",
"pos",
"]",
")",
";",
"if",
"(",
"$",
"level",
"==",
"$",
"lv",
")",
"{",
"$",
"pos",
"++",
";",
"$",
"result",
"[",
"$",
"id",
"]",
"=",
"$",
"this",
"->",
"build_thread",
"(",
"$",
"items",
",",
"$",
"level",
"+",
"1",
",",
"$",
"pos",
")",
";",
"}",
"else",
"{",
"$",
"pos",
"--",
";",
"break",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
]
| Converts part of the raw thread into an array | [
"Converts",
"part",
"of",
"the",
"raw",
"thread",
"into",
"an",
"array"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_result_thread.php#L543-L560 | train |
i-MSCP/roundcube | roundcubemail/program/lib/Roundcube/rcube_result_thread.php | rcube_result_thread.parse_thread | protected function parse_thread($str, $begin = 0, $end = 0, $depth = 0)
{
// Don't be tempted to change $str to pass by reference to speed this up - it will slow it down by about
// 7 times instead :-) See comments on http://uk2.php.net/references and this article:
// http://derickrethans.nl/files/phparch-php-variables-article.pdf
$node = '';
if (!$end) {
$end = strlen($str);
}
// Let's try to store data in max. compacted stracture as a string,
// arrays handling is much more expensive
// For the following structure: THREAD (2)(3 6 (4 23)(44 7 96))
// -- 2
// -- 3
// \-- 6
// |-- 4
// | \-- 23
// |
// \-- 44
// \-- 7
// \-- 96
//
// The output will be: 2,3^1:6^2:4^3:23^2:44^3:7^4:96
if ($str[$begin] != '(') {
// find next bracket
$stop = $begin + strcspn($str, '()', $begin, $end - $begin);
$messages = explode(' ', trim(substr($str, $begin, $stop - $begin)));
if (empty($messages)) {
return $node;
}
foreach ($messages as $msg) {
if ($msg) {
$node .= ($depth ? self::SEPARATOR_ITEM.$depth.self::SEPARATOR_LEVEL : '').$msg;
$this->meta['messages']++;
$depth++;
}
}
if ($stop < $end) {
$node .= $this->parse_thread($str, $stop, $end, $depth);
}
}
else {
$off = $begin;
while ($off < $end) {
$start = $off;
$off++;
$n = 1;
while ($n > 0) {
$p = strpos($str, ')', $off);
if ($p === false) {
// error, wrong structure, mismatched brackets in IMAP THREAD response
// @TODO: write error to the log or maybe set $this->raw_data = null;
return $node;
}
$p1 = strpos($str, '(', $off);
if ($p1 !== false && $p1 < $p) {
$off = $p1 + 1;
$n++;
}
else {
$off = $p + 1;
$n--;
}
}
$thread = $this->parse_thread($str, $start + 1, $off - 1, $depth);
if ($thread) {
if (!$depth) {
if ($node) {
$node .= self::SEPARATOR_ELEMENT;
}
}
$node .= $thread;
}
}
}
return $node;
} | php | protected function parse_thread($str, $begin = 0, $end = 0, $depth = 0)
{
// Don't be tempted to change $str to pass by reference to speed this up - it will slow it down by about
// 7 times instead :-) See comments on http://uk2.php.net/references and this article:
// http://derickrethans.nl/files/phparch-php-variables-article.pdf
$node = '';
if (!$end) {
$end = strlen($str);
}
// Let's try to store data in max. compacted stracture as a string,
// arrays handling is much more expensive
// For the following structure: THREAD (2)(3 6 (4 23)(44 7 96))
// -- 2
// -- 3
// \-- 6
// |-- 4
// | \-- 23
// |
// \-- 44
// \-- 7
// \-- 96
//
// The output will be: 2,3^1:6^2:4^3:23^2:44^3:7^4:96
if ($str[$begin] != '(') {
// find next bracket
$stop = $begin + strcspn($str, '()', $begin, $end - $begin);
$messages = explode(' ', trim(substr($str, $begin, $stop - $begin)));
if (empty($messages)) {
return $node;
}
foreach ($messages as $msg) {
if ($msg) {
$node .= ($depth ? self::SEPARATOR_ITEM.$depth.self::SEPARATOR_LEVEL : '').$msg;
$this->meta['messages']++;
$depth++;
}
}
if ($stop < $end) {
$node .= $this->parse_thread($str, $stop, $end, $depth);
}
}
else {
$off = $begin;
while ($off < $end) {
$start = $off;
$off++;
$n = 1;
while ($n > 0) {
$p = strpos($str, ')', $off);
if ($p === false) {
// error, wrong structure, mismatched brackets in IMAP THREAD response
// @TODO: write error to the log or maybe set $this->raw_data = null;
return $node;
}
$p1 = strpos($str, '(', $off);
if ($p1 !== false && $p1 < $p) {
$off = $p1 + 1;
$n++;
}
else {
$off = $p + 1;
$n--;
}
}
$thread = $this->parse_thread($str, $start + 1, $off - 1, $depth);
if ($thread) {
if (!$depth) {
if ($node) {
$node .= self::SEPARATOR_ELEMENT;
}
}
$node .= $thread;
}
}
}
return $node;
} | [
"protected",
"function",
"parse_thread",
"(",
"$",
"str",
",",
"$",
"begin",
"=",
"0",
",",
"$",
"end",
"=",
"0",
",",
"$",
"depth",
"=",
"0",
")",
"{",
"// Don't be tempted to change $str to pass by reference to speed this up - it will slow it down by about",
"// 7 times instead :-) See comments on http://uk2.php.net/references and this article:",
"// http://derickrethans.nl/files/phparch-php-variables-article.pdf",
"$",
"node",
"=",
"''",
";",
"if",
"(",
"!",
"$",
"end",
")",
"{",
"$",
"end",
"=",
"strlen",
"(",
"$",
"str",
")",
";",
"}",
"// Let's try to store data in max. compacted stracture as a string,",
"// arrays handling is much more expensive",
"// For the following structure: THREAD (2)(3 6 (4 23)(44 7 96))",
"// -- 2",
"// -- 3",
"// \\-- 6",
"// |-- 4",
"// | \\-- 23",
"// |",
"// \\-- 44",
"// \\-- 7",
"// \\-- 96",
"//",
"// The output will be: 2,3^1:6^2:4^3:23^2:44^3:7^4:96",
"if",
"(",
"$",
"str",
"[",
"$",
"begin",
"]",
"!=",
"'('",
")",
"{",
"// find next bracket",
"$",
"stop",
"=",
"$",
"begin",
"+",
"strcspn",
"(",
"$",
"str",
",",
"'()'",
",",
"$",
"begin",
",",
"$",
"end",
"-",
"$",
"begin",
")",
";",
"$",
"messages",
"=",
"explode",
"(",
"' '",
",",
"trim",
"(",
"substr",
"(",
"$",
"str",
",",
"$",
"begin",
",",
"$",
"stop",
"-",
"$",
"begin",
")",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"messages",
")",
")",
"{",
"return",
"$",
"node",
";",
"}",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"msg",
")",
"{",
"if",
"(",
"$",
"msg",
")",
"{",
"$",
"node",
".=",
"(",
"$",
"depth",
"?",
"self",
"::",
"SEPARATOR_ITEM",
".",
"$",
"depth",
".",
"self",
"::",
"SEPARATOR_LEVEL",
":",
"''",
")",
".",
"$",
"msg",
";",
"$",
"this",
"->",
"meta",
"[",
"'messages'",
"]",
"++",
";",
"$",
"depth",
"++",
";",
"}",
"}",
"if",
"(",
"$",
"stop",
"<",
"$",
"end",
")",
"{",
"$",
"node",
".=",
"$",
"this",
"->",
"parse_thread",
"(",
"$",
"str",
",",
"$",
"stop",
",",
"$",
"end",
",",
"$",
"depth",
")",
";",
"}",
"}",
"else",
"{",
"$",
"off",
"=",
"$",
"begin",
";",
"while",
"(",
"$",
"off",
"<",
"$",
"end",
")",
"{",
"$",
"start",
"=",
"$",
"off",
";",
"$",
"off",
"++",
";",
"$",
"n",
"=",
"1",
";",
"while",
"(",
"$",
"n",
">",
"0",
")",
"{",
"$",
"p",
"=",
"strpos",
"(",
"$",
"str",
",",
"')'",
",",
"$",
"off",
")",
";",
"if",
"(",
"$",
"p",
"===",
"false",
")",
"{",
"// error, wrong structure, mismatched brackets in IMAP THREAD response",
"// @TODO: write error to the log or maybe set $this->raw_data = null;",
"return",
"$",
"node",
";",
"}",
"$",
"p1",
"=",
"strpos",
"(",
"$",
"str",
",",
"'('",
",",
"$",
"off",
")",
";",
"if",
"(",
"$",
"p1",
"!==",
"false",
"&&",
"$",
"p1",
"<",
"$",
"p",
")",
"{",
"$",
"off",
"=",
"$",
"p1",
"+",
"1",
";",
"$",
"n",
"++",
";",
"}",
"else",
"{",
"$",
"off",
"=",
"$",
"p",
"+",
"1",
";",
"$",
"n",
"--",
";",
"}",
"}",
"$",
"thread",
"=",
"$",
"this",
"->",
"parse_thread",
"(",
"$",
"str",
",",
"$",
"start",
"+",
"1",
",",
"$",
"off",
"-",
"1",
",",
"$",
"depth",
")",
";",
"if",
"(",
"$",
"thread",
")",
"{",
"if",
"(",
"!",
"$",
"depth",
")",
"{",
"if",
"(",
"$",
"node",
")",
"{",
"$",
"node",
".=",
"self",
"::",
"SEPARATOR_ELEMENT",
";",
"}",
"}",
"$",
"node",
".=",
"$",
"thread",
";",
"}",
"}",
"}",
"return",
"$",
"node",
";",
"}"
]
| IMAP THREAD response parser | [
"IMAP",
"THREAD",
"response",
"parser"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_result_thread.php#L565-L648 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.startup | protected function startup()
{
$this->init(self::INIT_WITH_DB | self::INIT_WITH_PLUGINS);
// set filename if not index.php
if (($basename = basename($_SERVER['SCRIPT_FILENAME'])) && $basename != 'index.php') {
$this->filename = $basename;
}
// load all configured plugins
$plugins = (array) $this->config->get('plugins', array());
$required_plugins = array('filesystem_attachments', 'jqueryui');
$this->plugins->load_plugins($plugins, $required_plugins);
// start session
$this->session_init();
// create user object
$this->set_user(new rcube_user($_SESSION['user_id']));
// set task and action properties
$this->set_task(rcube_utils::get_input_value('_task', rcube_utils::INPUT_GPC));
$this->action = asciiwords(rcube_utils::get_input_value('_action', rcube_utils::INPUT_GPC));
// reset some session parameters when changing task
if ($this->task != 'utils') {
// we reset list page when switching to another task
// but only to the main task interface - empty action (#1489076, #1490116)
// this will prevent from unintentional page reset on cross-task requests
if ($this->session && $_SESSION['task'] != $this->task && empty($this->action)) {
$this->session->remove('page');
// set current task to session
$_SESSION['task'] = $this->task;
}
}
// init output class (not in CLI mode)
if (!empty($_REQUEST['_remote'])) {
$GLOBALS['OUTPUT'] = $this->json_init();
}
else if ($_SERVER['REMOTE_ADDR']) {
$GLOBALS['OUTPUT'] = $this->load_gui(!empty($_REQUEST['_framed']));
}
// run init method on all the plugins
$this->plugins->init($this, $this->task);
} | php | protected function startup()
{
$this->init(self::INIT_WITH_DB | self::INIT_WITH_PLUGINS);
// set filename if not index.php
if (($basename = basename($_SERVER['SCRIPT_FILENAME'])) && $basename != 'index.php') {
$this->filename = $basename;
}
// load all configured plugins
$plugins = (array) $this->config->get('plugins', array());
$required_plugins = array('filesystem_attachments', 'jqueryui');
$this->plugins->load_plugins($plugins, $required_plugins);
// start session
$this->session_init();
// create user object
$this->set_user(new rcube_user($_SESSION['user_id']));
// set task and action properties
$this->set_task(rcube_utils::get_input_value('_task', rcube_utils::INPUT_GPC));
$this->action = asciiwords(rcube_utils::get_input_value('_action', rcube_utils::INPUT_GPC));
// reset some session parameters when changing task
if ($this->task != 'utils') {
// we reset list page when switching to another task
// but only to the main task interface - empty action (#1489076, #1490116)
// this will prevent from unintentional page reset on cross-task requests
if ($this->session && $_SESSION['task'] != $this->task && empty($this->action)) {
$this->session->remove('page');
// set current task to session
$_SESSION['task'] = $this->task;
}
}
// init output class (not in CLI mode)
if (!empty($_REQUEST['_remote'])) {
$GLOBALS['OUTPUT'] = $this->json_init();
}
else if ($_SERVER['REMOTE_ADDR']) {
$GLOBALS['OUTPUT'] = $this->load_gui(!empty($_REQUEST['_framed']));
}
// run init method on all the plugins
$this->plugins->init($this, $this->task);
} | [
"protected",
"function",
"startup",
"(",
")",
"{",
"$",
"this",
"->",
"init",
"(",
"self",
"::",
"INIT_WITH_DB",
"|",
"self",
"::",
"INIT_WITH_PLUGINS",
")",
";",
"// set filename if not index.php",
"if",
"(",
"(",
"$",
"basename",
"=",
"basename",
"(",
"$",
"_SERVER",
"[",
"'SCRIPT_FILENAME'",
"]",
")",
")",
"&&",
"$",
"basename",
"!=",
"'index.php'",
")",
"{",
"$",
"this",
"->",
"filename",
"=",
"$",
"basename",
";",
"}",
"// load all configured plugins",
"$",
"plugins",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'plugins'",
",",
"array",
"(",
")",
")",
";",
"$",
"required_plugins",
"=",
"array",
"(",
"'filesystem_attachments'",
",",
"'jqueryui'",
")",
";",
"$",
"this",
"->",
"plugins",
"->",
"load_plugins",
"(",
"$",
"plugins",
",",
"$",
"required_plugins",
")",
";",
"// start session",
"$",
"this",
"->",
"session_init",
"(",
")",
";",
"// create user object",
"$",
"this",
"->",
"set_user",
"(",
"new",
"rcube_user",
"(",
"$",
"_SESSION",
"[",
"'user_id'",
"]",
")",
")",
";",
"// set task and action properties",
"$",
"this",
"->",
"set_task",
"(",
"rcube_utils",
"::",
"get_input_value",
"(",
"'_task'",
",",
"rcube_utils",
"::",
"INPUT_GPC",
")",
")",
";",
"$",
"this",
"->",
"action",
"=",
"asciiwords",
"(",
"rcube_utils",
"::",
"get_input_value",
"(",
"'_action'",
",",
"rcube_utils",
"::",
"INPUT_GPC",
")",
")",
";",
"// reset some session parameters when changing task",
"if",
"(",
"$",
"this",
"->",
"task",
"!=",
"'utils'",
")",
"{",
"// we reset list page when switching to another task",
"// but only to the main task interface - empty action (#1489076, #1490116)",
"// this will prevent from unintentional page reset on cross-task requests",
"if",
"(",
"$",
"this",
"->",
"session",
"&&",
"$",
"_SESSION",
"[",
"'task'",
"]",
"!=",
"$",
"this",
"->",
"task",
"&&",
"empty",
"(",
"$",
"this",
"->",
"action",
")",
")",
"{",
"$",
"this",
"->",
"session",
"->",
"remove",
"(",
"'page'",
")",
";",
"// set current task to session",
"$",
"_SESSION",
"[",
"'task'",
"]",
"=",
"$",
"this",
"->",
"task",
";",
"}",
"}",
"// init output class (not in CLI mode)",
"if",
"(",
"!",
"empty",
"(",
"$",
"_REQUEST",
"[",
"'_remote'",
"]",
")",
")",
"{",
"$",
"GLOBALS",
"[",
"'OUTPUT'",
"]",
"=",
"$",
"this",
"->",
"json_init",
"(",
")",
";",
"}",
"else",
"if",
"(",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
")",
"{",
"$",
"GLOBALS",
"[",
"'OUTPUT'",
"]",
"=",
"$",
"this",
"->",
"load_gui",
"(",
"!",
"empty",
"(",
"$",
"_REQUEST",
"[",
"'_framed'",
"]",
")",
")",
";",
"}",
"// run init method on all the plugins",
"$",
"this",
"->",
"plugins",
"->",
"init",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"task",
")",
";",
"}"
]
| Initial startup function
to register session, create database and imap connections | [
"Initial",
"startup",
"function",
"to",
"register",
"session",
"create",
"database",
"and",
"imap",
"connections"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L89-L136 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.set_task | public function set_task($task)
{
if (php_sapi_name() == 'cli') {
$task = 'cli';
}
else if (!$this->user || !$this->user->ID) {
$task = 'login';
}
else {
$task = asciiwords($task, true) ?: 'mail';
}
$this->task = $task;
$this->comm_path = $this->url(array('task' => $this->task));
if (!empty($_REQUEST['_framed'])) {
$this->comm_path .= '&_framed=1';
}
if ($this->output) {
$this->output->set_env('task', $this->task);
$this->output->set_env('comm_path', $this->comm_path);
}
} | php | public function set_task($task)
{
if (php_sapi_name() == 'cli') {
$task = 'cli';
}
else if (!$this->user || !$this->user->ID) {
$task = 'login';
}
else {
$task = asciiwords($task, true) ?: 'mail';
}
$this->task = $task;
$this->comm_path = $this->url(array('task' => $this->task));
if (!empty($_REQUEST['_framed'])) {
$this->comm_path .= '&_framed=1';
}
if ($this->output) {
$this->output->set_env('task', $this->task);
$this->output->set_env('comm_path', $this->comm_path);
}
} | [
"public",
"function",
"set_task",
"(",
"$",
"task",
")",
"{",
"if",
"(",
"php_sapi_name",
"(",
")",
"==",
"'cli'",
")",
"{",
"$",
"task",
"=",
"'cli'",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"this",
"->",
"user",
"||",
"!",
"$",
"this",
"->",
"user",
"->",
"ID",
")",
"{",
"$",
"task",
"=",
"'login'",
";",
"}",
"else",
"{",
"$",
"task",
"=",
"asciiwords",
"(",
"$",
"task",
",",
"true",
")",
"?",
":",
"'mail'",
";",
"}",
"$",
"this",
"->",
"task",
"=",
"$",
"task",
";",
"$",
"this",
"->",
"comm_path",
"=",
"$",
"this",
"->",
"url",
"(",
"array",
"(",
"'task'",
"=>",
"$",
"this",
"->",
"task",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"_REQUEST",
"[",
"'_framed'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"comm_path",
".=",
"'&_framed=1'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"output",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'task'",
",",
"$",
"this",
"->",
"task",
")",
";",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'comm_path'",
",",
"$",
"this",
"->",
"comm_path",
")",
";",
"}",
"}"
]
| Setter for application task
@param string $task Task to set | [
"Setter",
"for",
"application",
"task"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L143-L166 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.get_address_book | public function get_address_book($id, $writeable = false)
{
$contacts = null;
$ldap_config = (array)$this->config->get('ldap_public');
// 'sql' is the alias for '0' used by autocomplete
if ($id == 'sql')
$id = '0';
else if ($id == -1) {
$id = $this->config->get('default_addressbook');
$default = true;
}
// use existing instance
if (isset($this->address_books[$id]) && ($this->address_books[$id] instanceof rcube_addressbook)) {
$contacts = $this->address_books[$id];
}
else if ($id && $ldap_config[$id]) {
$domain = $this->config->mail_domain($_SESSION['storage_host']);
$contacts = new rcube_ldap($ldap_config[$id], $this->config->get('ldap_debug'), $domain);
}
else if ($id === '0') {
$contacts = new rcube_contacts($this->db, $this->get_user_id());
}
else {
$plugin = $this->plugins->exec_hook('addressbook_get', array('id' => $id, 'writeable' => $writeable));
// plugin returned instance of a rcube_addressbook
if ($plugin['instance'] instanceof rcube_addressbook) {
$contacts = $plugin['instance'];
}
}
// when user requested default writeable addressbook
// we need to check if default is writeable, if not we
// will return first writeable book (if any exist)
if ($contacts && $default && $contacts->readonly && $writeable) {
$contacts = null;
}
// Get first addressbook from the list if configured default doesn't exist
// This can happen when user deleted the addressbook (e.g. Kolab folder)
if (!$contacts && (!$id || $default)) {
$source = reset($this->get_address_sources($writeable, !$default));
if (!empty($source)) {
$contacts = $this->get_address_book($source['id']);
if ($contacts) {
$id = $source['id'];
}
}
}
if (!$contacts) {
// there's no default, just return
if ($default) {
return null;
}
self::raise_error(array(
'code' => 700,
'file' => __FILE__,
'line' => __LINE__,
'message' => "Addressbook source ($id) not found!"
),
true, true);
}
// add to the 'books' array for shutdown function
$this->address_books[$id] = $contacts;
if ($writeable && $contacts->readonly) {
return null;
}
// set configured sort order
if ($sort_col = $this->config->get('addressbook_sort_col')) {
$contacts->set_sort_order($sort_col);
}
return $contacts;
} | php | public function get_address_book($id, $writeable = false)
{
$contacts = null;
$ldap_config = (array)$this->config->get('ldap_public');
// 'sql' is the alias for '0' used by autocomplete
if ($id == 'sql')
$id = '0';
else if ($id == -1) {
$id = $this->config->get('default_addressbook');
$default = true;
}
// use existing instance
if (isset($this->address_books[$id]) && ($this->address_books[$id] instanceof rcube_addressbook)) {
$contacts = $this->address_books[$id];
}
else if ($id && $ldap_config[$id]) {
$domain = $this->config->mail_domain($_SESSION['storage_host']);
$contacts = new rcube_ldap($ldap_config[$id], $this->config->get('ldap_debug'), $domain);
}
else if ($id === '0') {
$contacts = new rcube_contacts($this->db, $this->get_user_id());
}
else {
$plugin = $this->plugins->exec_hook('addressbook_get', array('id' => $id, 'writeable' => $writeable));
// plugin returned instance of a rcube_addressbook
if ($plugin['instance'] instanceof rcube_addressbook) {
$contacts = $plugin['instance'];
}
}
// when user requested default writeable addressbook
// we need to check if default is writeable, if not we
// will return first writeable book (if any exist)
if ($contacts && $default && $contacts->readonly && $writeable) {
$contacts = null;
}
// Get first addressbook from the list if configured default doesn't exist
// This can happen when user deleted the addressbook (e.g. Kolab folder)
if (!$contacts && (!$id || $default)) {
$source = reset($this->get_address_sources($writeable, !$default));
if (!empty($source)) {
$contacts = $this->get_address_book($source['id']);
if ($contacts) {
$id = $source['id'];
}
}
}
if (!$contacts) {
// there's no default, just return
if ($default) {
return null;
}
self::raise_error(array(
'code' => 700,
'file' => __FILE__,
'line' => __LINE__,
'message' => "Addressbook source ($id) not found!"
),
true, true);
}
// add to the 'books' array for shutdown function
$this->address_books[$id] = $contacts;
if ($writeable && $contacts->readonly) {
return null;
}
// set configured sort order
if ($sort_col = $this->config->get('addressbook_sort_col')) {
$contacts->set_sort_order($sort_col);
}
return $contacts;
} | [
"public",
"function",
"get_address_book",
"(",
"$",
"id",
",",
"$",
"writeable",
"=",
"false",
")",
"{",
"$",
"contacts",
"=",
"null",
";",
"$",
"ldap_config",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'ldap_public'",
")",
";",
"// 'sql' is the alias for '0' used by autocomplete",
"if",
"(",
"$",
"id",
"==",
"'sql'",
")",
"$",
"id",
"=",
"'0'",
";",
"else",
"if",
"(",
"$",
"id",
"==",
"-",
"1",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'default_addressbook'",
")",
";",
"$",
"default",
"=",
"true",
";",
"}",
"// use existing instance",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"address_books",
"[",
"$",
"id",
"]",
")",
"&&",
"(",
"$",
"this",
"->",
"address_books",
"[",
"$",
"id",
"]",
"instanceof",
"rcube_addressbook",
")",
")",
"{",
"$",
"contacts",
"=",
"$",
"this",
"->",
"address_books",
"[",
"$",
"id",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"id",
"&&",
"$",
"ldap_config",
"[",
"$",
"id",
"]",
")",
"{",
"$",
"domain",
"=",
"$",
"this",
"->",
"config",
"->",
"mail_domain",
"(",
"$",
"_SESSION",
"[",
"'storage_host'",
"]",
")",
";",
"$",
"contacts",
"=",
"new",
"rcube_ldap",
"(",
"$",
"ldap_config",
"[",
"$",
"id",
"]",
",",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'ldap_debug'",
")",
",",
"$",
"domain",
")",
";",
"}",
"else",
"if",
"(",
"$",
"id",
"===",
"'0'",
")",
"{",
"$",
"contacts",
"=",
"new",
"rcube_contacts",
"(",
"$",
"this",
"->",
"db",
",",
"$",
"this",
"->",
"get_user_id",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"plugin",
"=",
"$",
"this",
"->",
"plugins",
"->",
"exec_hook",
"(",
"'addressbook_get'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
",",
"'writeable'",
"=>",
"$",
"writeable",
")",
")",
";",
"// plugin returned instance of a rcube_addressbook",
"if",
"(",
"$",
"plugin",
"[",
"'instance'",
"]",
"instanceof",
"rcube_addressbook",
")",
"{",
"$",
"contacts",
"=",
"$",
"plugin",
"[",
"'instance'",
"]",
";",
"}",
"}",
"// when user requested default writeable addressbook",
"// we need to check if default is writeable, if not we",
"// will return first writeable book (if any exist)",
"if",
"(",
"$",
"contacts",
"&&",
"$",
"default",
"&&",
"$",
"contacts",
"->",
"readonly",
"&&",
"$",
"writeable",
")",
"{",
"$",
"contacts",
"=",
"null",
";",
"}",
"// Get first addressbook from the list if configured default doesn't exist",
"// This can happen when user deleted the addressbook (e.g. Kolab folder)",
"if",
"(",
"!",
"$",
"contacts",
"&&",
"(",
"!",
"$",
"id",
"||",
"$",
"default",
")",
")",
"{",
"$",
"source",
"=",
"reset",
"(",
"$",
"this",
"->",
"get_address_sources",
"(",
"$",
"writeable",
",",
"!",
"$",
"default",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"source",
")",
")",
"{",
"$",
"contacts",
"=",
"$",
"this",
"->",
"get_address_book",
"(",
"$",
"source",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"$",
"contacts",
")",
"{",
"$",
"id",
"=",
"$",
"source",
"[",
"'id'",
"]",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"contacts",
")",
"{",
"// there's no default, just return",
"if",
"(",
"$",
"default",
")",
"{",
"return",
"null",
";",
"}",
"self",
"::",
"raise_error",
"(",
"array",
"(",
"'code'",
"=>",
"700",
",",
"'file'",
"=>",
"__FILE__",
",",
"'line'",
"=>",
"__LINE__",
",",
"'message'",
"=>",
"\"Addressbook source ($id) not found!\"",
")",
",",
"true",
",",
"true",
")",
";",
"}",
"// add to the 'books' array for shutdown function",
"$",
"this",
"->",
"address_books",
"[",
"$",
"id",
"]",
"=",
"$",
"contacts",
";",
"if",
"(",
"$",
"writeable",
"&&",
"$",
"contacts",
"->",
"readonly",
")",
"{",
"return",
"null",
";",
"}",
"// set configured sort order",
"if",
"(",
"$",
"sort_col",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'addressbook_sort_col'",
")",
")",
"{",
"$",
"contacts",
"->",
"set_sort_order",
"(",
"$",
"sort_col",
")",
";",
"}",
"return",
"$",
"contacts",
";",
"}"
]
| Return instance of the internal address book class
@param string $id Address book identifier (-1 for default addressbook)
@param boolean $writeable True if the address book needs to be writeable
@return rcube_contacts Address book object | [
"Return",
"instance",
"of",
"the",
"internal",
"address",
"book",
"class"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L199-L279 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.get_address_book_id | public function get_address_book_id($object)
{
foreach ($this->address_books as $index => $book) {
if ($book === $object) {
return $index;
}
}
} | php | public function get_address_book_id($object)
{
foreach ($this->address_books as $index => $book) {
if ($book === $object) {
return $index;
}
}
} | [
"public",
"function",
"get_address_book_id",
"(",
"$",
"object",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"address_books",
"as",
"$",
"index",
"=>",
"$",
"book",
")",
"{",
"if",
"(",
"$",
"book",
"===",
"$",
"object",
")",
"{",
"return",
"$",
"index",
";",
"}",
"}",
"}"
]
| Return identifier of the address book object
@param rcube_addressbook $object Addressbook source object
@return string Source identifier | [
"Return",
"identifier",
"of",
"the",
"address",
"book",
"object"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L288-L295 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.get_address_sources | public function get_address_sources($writeable = false, $skip_hidden = false)
{
$abook_type = (string) $this->config->get('address_book_type');
$ldap_config = (array) $this->config->get('ldap_public');
$autocomplete = (array) $this->config->get('autocomplete_addressbooks');
$list = array();
// We are using the DB address book or a plugin address book
if (!empty($abook_type) && strtolower($abook_type) != 'ldap') {
if (!isset($this->address_books['0'])) {
$this->address_books['0'] = new rcube_contacts($this->db, $this->get_user_id());
}
$list['0'] = array(
'id' => '0',
'name' => $this->gettext('personaladrbook'),
'groups' => $this->address_books['0']->groups,
'readonly' => $this->address_books['0']->readonly,
'undelete' => $this->address_books['0']->undelete && $this->config->get('undo_timeout'),
'autocomplete' => in_array('sql', $autocomplete),
);
}
if (!empty($ldap_config)) {
foreach ($ldap_config as $id => $prop) {
// handle misconfiguration
if (empty($prop) || !is_array($prop)) {
continue;
}
$list[$id] = array(
'id' => $id,
'name' => html::quote($prop['name']),
'groups' => !empty($prop['groups']) || !empty($prop['group_filters']),
'readonly' => !$prop['writable'],
'hidden' => $prop['hidden'],
'autocomplete' => in_array($id, $autocomplete)
);
}
}
$plugin = $this->plugins->exec_hook('addressbooks_list', array('sources' => $list));
$list = $plugin['sources'];
foreach ($list as $idx => $item) {
// register source for shutdown function
if (!is_object($this->address_books[$item['id']])) {
$this->address_books[$item['id']] = $item;
}
// remove from list if not writeable as requested
if ($writeable && $item['readonly']) {
unset($list[$idx]);
}
// remove from list if hidden as requested
else if ($skip_hidden && $item['hidden']) {
unset($list[$idx]);
}
}
return $list;
} | php | public function get_address_sources($writeable = false, $skip_hidden = false)
{
$abook_type = (string) $this->config->get('address_book_type');
$ldap_config = (array) $this->config->get('ldap_public');
$autocomplete = (array) $this->config->get('autocomplete_addressbooks');
$list = array();
// We are using the DB address book or a plugin address book
if (!empty($abook_type) && strtolower($abook_type) != 'ldap') {
if (!isset($this->address_books['0'])) {
$this->address_books['0'] = new rcube_contacts($this->db, $this->get_user_id());
}
$list['0'] = array(
'id' => '0',
'name' => $this->gettext('personaladrbook'),
'groups' => $this->address_books['0']->groups,
'readonly' => $this->address_books['0']->readonly,
'undelete' => $this->address_books['0']->undelete && $this->config->get('undo_timeout'),
'autocomplete' => in_array('sql', $autocomplete),
);
}
if (!empty($ldap_config)) {
foreach ($ldap_config as $id => $prop) {
// handle misconfiguration
if (empty($prop) || !is_array($prop)) {
continue;
}
$list[$id] = array(
'id' => $id,
'name' => html::quote($prop['name']),
'groups' => !empty($prop['groups']) || !empty($prop['group_filters']),
'readonly' => !$prop['writable'],
'hidden' => $prop['hidden'],
'autocomplete' => in_array($id, $autocomplete)
);
}
}
$plugin = $this->plugins->exec_hook('addressbooks_list', array('sources' => $list));
$list = $plugin['sources'];
foreach ($list as $idx => $item) {
// register source for shutdown function
if (!is_object($this->address_books[$item['id']])) {
$this->address_books[$item['id']] = $item;
}
// remove from list if not writeable as requested
if ($writeable && $item['readonly']) {
unset($list[$idx]);
}
// remove from list if hidden as requested
else if ($skip_hidden && $item['hidden']) {
unset($list[$idx]);
}
}
return $list;
} | [
"public",
"function",
"get_address_sources",
"(",
"$",
"writeable",
"=",
"false",
",",
"$",
"skip_hidden",
"=",
"false",
")",
"{",
"$",
"abook_type",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'address_book_type'",
")",
";",
"$",
"ldap_config",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'ldap_public'",
")",
";",
"$",
"autocomplete",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'autocomplete_addressbooks'",
")",
";",
"$",
"list",
"=",
"array",
"(",
")",
";",
"// We are using the DB address book or a plugin address book",
"if",
"(",
"!",
"empty",
"(",
"$",
"abook_type",
")",
"&&",
"strtolower",
"(",
"$",
"abook_type",
")",
"!=",
"'ldap'",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"address_books",
"[",
"'0'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"address_books",
"[",
"'0'",
"]",
"=",
"new",
"rcube_contacts",
"(",
"$",
"this",
"->",
"db",
",",
"$",
"this",
"->",
"get_user_id",
"(",
")",
")",
";",
"}",
"$",
"list",
"[",
"'0'",
"]",
"=",
"array",
"(",
"'id'",
"=>",
"'0'",
",",
"'name'",
"=>",
"$",
"this",
"->",
"gettext",
"(",
"'personaladrbook'",
")",
",",
"'groups'",
"=>",
"$",
"this",
"->",
"address_books",
"[",
"'0'",
"]",
"->",
"groups",
",",
"'readonly'",
"=>",
"$",
"this",
"->",
"address_books",
"[",
"'0'",
"]",
"->",
"readonly",
",",
"'undelete'",
"=>",
"$",
"this",
"->",
"address_books",
"[",
"'0'",
"]",
"->",
"undelete",
"&&",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'undo_timeout'",
")",
",",
"'autocomplete'",
"=>",
"in_array",
"(",
"'sql'",
",",
"$",
"autocomplete",
")",
",",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"ldap_config",
")",
")",
"{",
"foreach",
"(",
"$",
"ldap_config",
"as",
"$",
"id",
"=>",
"$",
"prop",
")",
"{",
"// handle misconfiguration",
"if",
"(",
"empty",
"(",
"$",
"prop",
")",
"||",
"!",
"is_array",
"(",
"$",
"prop",
")",
")",
"{",
"continue",
";",
"}",
"$",
"list",
"[",
"$",
"id",
"]",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"id",
",",
"'name'",
"=>",
"html",
"::",
"quote",
"(",
"$",
"prop",
"[",
"'name'",
"]",
")",
",",
"'groups'",
"=>",
"!",
"empty",
"(",
"$",
"prop",
"[",
"'groups'",
"]",
")",
"||",
"!",
"empty",
"(",
"$",
"prop",
"[",
"'group_filters'",
"]",
")",
",",
"'readonly'",
"=>",
"!",
"$",
"prop",
"[",
"'writable'",
"]",
",",
"'hidden'",
"=>",
"$",
"prop",
"[",
"'hidden'",
"]",
",",
"'autocomplete'",
"=>",
"in_array",
"(",
"$",
"id",
",",
"$",
"autocomplete",
")",
")",
";",
"}",
"}",
"$",
"plugin",
"=",
"$",
"this",
"->",
"plugins",
"->",
"exec_hook",
"(",
"'addressbooks_list'",
",",
"array",
"(",
"'sources'",
"=>",
"$",
"list",
")",
")",
";",
"$",
"list",
"=",
"$",
"plugin",
"[",
"'sources'",
"]",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"idx",
"=>",
"$",
"item",
")",
"{",
"// register source for shutdown function",
"if",
"(",
"!",
"is_object",
"(",
"$",
"this",
"->",
"address_books",
"[",
"$",
"item",
"[",
"'id'",
"]",
"]",
")",
")",
"{",
"$",
"this",
"->",
"address_books",
"[",
"$",
"item",
"[",
"'id'",
"]",
"]",
"=",
"$",
"item",
";",
"}",
"// remove from list if not writeable as requested",
"if",
"(",
"$",
"writeable",
"&&",
"$",
"item",
"[",
"'readonly'",
"]",
")",
"{",
"unset",
"(",
"$",
"list",
"[",
"$",
"idx",
"]",
")",
";",
"}",
"// remove from list if hidden as requested",
"else",
"if",
"(",
"$",
"skip_hidden",
"&&",
"$",
"item",
"[",
"'hidden'",
"]",
")",
"{",
"unset",
"(",
"$",
"list",
"[",
"$",
"idx",
"]",
")",
";",
"}",
"}",
"return",
"$",
"list",
";",
"}"
]
| Return address books list
@param boolean $writeable True if the address book needs to be writeable
@param boolean $skip_hidden True if the address book needs to be not hidden
@return array Address books array | [
"Return",
"address",
"books",
"list"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L305-L365 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.get_compose_responses | public function get_compose_responses($sorted = false, $user_only = false)
{
$responses = array();
if (!$user_only) {
foreach ($this->config->get('compose_responses_static', array()) as $response) {
if (empty($response['key'])) {
$response['key'] = substr(md5($response['name']), 0, 16);
}
$response['static'] = true;
$response['class'] = 'readonly';
$k = $sorted ? '0000-' . mb_strtolower($response['name']) : $response['key'];
$responses[$k] = $response;
}
}
foreach ($this->config->get('compose_responses', array()) as $response) {
if (empty($response['key'])) {
$response['key'] = substr(md5($response['name']), 0, 16);
}
$k = $sorted ? mb_strtolower($response['name']) : $response['key'];
$responses[$k] = $response;
}
// sort list by name
if ($sorted) {
ksort($responses, SORT_LOCALE_STRING);
}
$responses = array_values($responses);
$hook = $this->plugins->exec_hook('get_compose_responses', array(
'list' => $responses,
'sorted' => $sorted,
'user_only' => $user_only,
));
return $hook['list'];
} | php | public function get_compose_responses($sorted = false, $user_only = false)
{
$responses = array();
if (!$user_only) {
foreach ($this->config->get('compose_responses_static', array()) as $response) {
if (empty($response['key'])) {
$response['key'] = substr(md5($response['name']), 0, 16);
}
$response['static'] = true;
$response['class'] = 'readonly';
$k = $sorted ? '0000-' . mb_strtolower($response['name']) : $response['key'];
$responses[$k] = $response;
}
}
foreach ($this->config->get('compose_responses', array()) as $response) {
if (empty($response['key'])) {
$response['key'] = substr(md5($response['name']), 0, 16);
}
$k = $sorted ? mb_strtolower($response['name']) : $response['key'];
$responses[$k] = $response;
}
// sort list by name
if ($sorted) {
ksort($responses, SORT_LOCALE_STRING);
}
$responses = array_values($responses);
$hook = $this->plugins->exec_hook('get_compose_responses', array(
'list' => $responses,
'sorted' => $sorted,
'user_only' => $user_only,
));
return $hook['list'];
} | [
"public",
"function",
"get_compose_responses",
"(",
"$",
"sorted",
"=",
"false",
",",
"$",
"user_only",
"=",
"false",
")",
"{",
"$",
"responses",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"user_only",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'compose_responses_static'",
",",
"array",
"(",
")",
")",
"as",
"$",
"response",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"response",
"[",
"'key'",
"]",
")",
")",
"{",
"$",
"response",
"[",
"'key'",
"]",
"=",
"substr",
"(",
"md5",
"(",
"$",
"response",
"[",
"'name'",
"]",
")",
",",
"0",
",",
"16",
")",
";",
"}",
"$",
"response",
"[",
"'static'",
"]",
"=",
"true",
";",
"$",
"response",
"[",
"'class'",
"]",
"=",
"'readonly'",
";",
"$",
"k",
"=",
"$",
"sorted",
"?",
"'0000-'",
".",
"mb_strtolower",
"(",
"$",
"response",
"[",
"'name'",
"]",
")",
":",
"$",
"response",
"[",
"'key'",
"]",
";",
"$",
"responses",
"[",
"$",
"k",
"]",
"=",
"$",
"response",
";",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'compose_responses'",
",",
"array",
"(",
")",
")",
"as",
"$",
"response",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"response",
"[",
"'key'",
"]",
")",
")",
"{",
"$",
"response",
"[",
"'key'",
"]",
"=",
"substr",
"(",
"md5",
"(",
"$",
"response",
"[",
"'name'",
"]",
")",
",",
"0",
",",
"16",
")",
";",
"}",
"$",
"k",
"=",
"$",
"sorted",
"?",
"mb_strtolower",
"(",
"$",
"response",
"[",
"'name'",
"]",
")",
":",
"$",
"response",
"[",
"'key'",
"]",
";",
"$",
"responses",
"[",
"$",
"k",
"]",
"=",
"$",
"response",
";",
"}",
"// sort list by name",
"if",
"(",
"$",
"sorted",
")",
"{",
"ksort",
"(",
"$",
"responses",
",",
"SORT_LOCALE_STRING",
")",
";",
"}",
"$",
"responses",
"=",
"array_values",
"(",
"$",
"responses",
")",
";",
"$",
"hook",
"=",
"$",
"this",
"->",
"plugins",
"->",
"exec_hook",
"(",
"'get_compose_responses'",
",",
"array",
"(",
"'list'",
"=>",
"$",
"responses",
",",
"'sorted'",
"=>",
"$",
"sorted",
",",
"'user_only'",
"=>",
"$",
"user_only",
",",
")",
")",
";",
"return",
"$",
"hook",
"[",
"'list'",
"]",
";",
"}"
]
| Getter for compose responses.
These are stored in local config and user preferences.
@param boolean $sorted True to sort the list alphabetically
@param boolean $user_only True if only this user's responses shall be listed
@return array List of the current user's stored responses | [
"Getter",
"for",
"compose",
"responses",
".",
"These",
"are",
"stored",
"in",
"local",
"config",
"and",
"user",
"preferences",
"."
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L376-L417 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.load_gui | public function load_gui($framed = false)
{
// init output page
if (!($this->output instanceof rcmail_output_html)) {
$this->output = new rcmail_output_html($this->task, $framed);
}
// set refresh interval
$this->output->set_env('refresh_interval', $this->config->get('refresh_interval', 0));
$this->output->set_env('session_lifetime', $this->config->get('session_lifetime', 0) * 60);
if ($framed) {
$this->comm_path .= '&_framed=1';
$this->output->set_env('framed', true);
}
$this->output->set_env('task', $this->task);
$this->output->set_env('action', $this->action);
$this->output->set_env('comm_path', $this->comm_path);
$this->output->set_charset(RCUBE_CHARSET);
if ($this->user && $this->user->ID) {
$this->output->set_env('user_id', $this->user->get_hash());
}
// set compose mode for all tasks (message compose step can be triggered from everywhere)
$this->output->set_env('compose_extwin', $this->config->get('compose_extwin',false));
// add some basic labels to client
$this->output->add_label('loading', 'servererror', 'connerror', 'requesttimedout',
'refreshing', 'windowopenerror', 'uploadingmany', 'close');
return $this->output;
} | php | public function load_gui($framed = false)
{
// init output page
if (!($this->output instanceof rcmail_output_html)) {
$this->output = new rcmail_output_html($this->task, $framed);
}
// set refresh interval
$this->output->set_env('refresh_interval', $this->config->get('refresh_interval', 0));
$this->output->set_env('session_lifetime', $this->config->get('session_lifetime', 0) * 60);
if ($framed) {
$this->comm_path .= '&_framed=1';
$this->output->set_env('framed', true);
}
$this->output->set_env('task', $this->task);
$this->output->set_env('action', $this->action);
$this->output->set_env('comm_path', $this->comm_path);
$this->output->set_charset(RCUBE_CHARSET);
if ($this->user && $this->user->ID) {
$this->output->set_env('user_id', $this->user->get_hash());
}
// set compose mode for all tasks (message compose step can be triggered from everywhere)
$this->output->set_env('compose_extwin', $this->config->get('compose_extwin',false));
// add some basic labels to client
$this->output->add_label('loading', 'servererror', 'connerror', 'requesttimedout',
'refreshing', 'windowopenerror', 'uploadingmany', 'close');
return $this->output;
} | [
"public",
"function",
"load_gui",
"(",
"$",
"framed",
"=",
"false",
")",
"{",
"// init output page",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"output",
"instanceof",
"rcmail_output_html",
")",
")",
"{",
"$",
"this",
"->",
"output",
"=",
"new",
"rcmail_output_html",
"(",
"$",
"this",
"->",
"task",
",",
"$",
"framed",
")",
";",
"}",
"// set refresh interval",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'refresh_interval'",
",",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'refresh_interval'",
",",
"0",
")",
")",
";",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'session_lifetime'",
",",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'session_lifetime'",
",",
"0",
")",
"*",
"60",
")",
";",
"if",
"(",
"$",
"framed",
")",
"{",
"$",
"this",
"->",
"comm_path",
".=",
"'&_framed=1'",
";",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'framed'",
",",
"true",
")",
";",
"}",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'task'",
",",
"$",
"this",
"->",
"task",
")",
";",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'action'",
",",
"$",
"this",
"->",
"action",
")",
";",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'comm_path'",
",",
"$",
"this",
"->",
"comm_path",
")",
";",
"$",
"this",
"->",
"output",
"->",
"set_charset",
"(",
"RCUBE_CHARSET",
")",
";",
"if",
"(",
"$",
"this",
"->",
"user",
"&&",
"$",
"this",
"->",
"user",
"->",
"ID",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'user_id'",
",",
"$",
"this",
"->",
"user",
"->",
"get_hash",
"(",
")",
")",
";",
"}",
"// set compose mode for all tasks (message compose step can be triggered from everywhere)",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'compose_extwin'",
",",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'compose_extwin'",
",",
"false",
")",
")",
";",
"// add some basic labels to client",
"$",
"this",
"->",
"output",
"->",
"add_label",
"(",
"'loading'",
",",
"'servererror'",
",",
"'connerror'",
",",
"'requesttimedout'",
",",
"'refreshing'",
",",
"'windowopenerror'",
",",
"'uploadingmany'",
",",
"'close'",
")",
";",
"return",
"$",
"this",
"->",
"output",
";",
"}"
]
| Init output object for GUI and add common scripts.
This will instantiate a rcmail_output_html object and set
environment vars according to the current session and configuration
@param boolean $framed True if this request is loaded in a (i)frame
@return rcube_output Reference to HTML output object | [
"Init",
"output",
"object",
"for",
"GUI",
"and",
"add",
"common",
"scripts",
".",
"This",
"will",
"instantiate",
"a",
"rcmail_output_html",
"object",
"and",
"set",
"environment",
"vars",
"according",
"to",
"the",
"current",
"session",
"and",
"configuration"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L428-L461 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.json_init | public function json_init()
{
if (!($this->output instanceof rcmail_output_json)) {
$this->output = new rcmail_output_json($this->task);
}
return $this->output;
} | php | public function json_init()
{
if (!($this->output instanceof rcmail_output_json)) {
$this->output = new rcmail_output_json($this->task);
}
return $this->output;
} | [
"public",
"function",
"json_init",
"(",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"output",
"instanceof",
"rcmail_output_json",
")",
")",
"{",
"$",
"this",
"->",
"output",
"=",
"new",
"rcmail_output_json",
"(",
"$",
"this",
"->",
"task",
")",
";",
"}",
"return",
"$",
"this",
"->",
"output",
";",
"}"
]
| Create an output object for JSON responses
@return rcube_output Reference to JSON output object | [
"Create",
"an",
"output",
"object",
"for",
"JSON",
"responses"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L468-L475 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.login_error | public function login_error()
{
if ($this->login_error) {
return $this->login_error;
}
if ($this->storage && $this->storage->get_error_code() < -1) {
return self::ERROR_STORAGE;
}
} | php | public function login_error()
{
if ($this->login_error) {
return $this->login_error;
}
if ($this->storage && $this->storage->get_error_code() < -1) {
return self::ERROR_STORAGE;
}
} | [
"public",
"function",
"login_error",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"login_error",
")",
"{",
"return",
"$",
"this",
"->",
"login_error",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"storage",
"&&",
"$",
"this",
"->",
"storage",
"->",
"get_error_code",
"(",
")",
"<",
"-",
"1",
")",
"{",
"return",
"self",
"::",
"ERROR_STORAGE",
";",
"}",
"}"
]
| Returns error code of last login operation
@return int Error code | [
"Returns",
"error",
"code",
"of",
"last",
"login",
"operation"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L708-L717 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.autoselect_host | public function autoselect_host()
{
$default_host = $this->config->get('default_host');
$host = null;
if (is_array($default_host)) {
$post_host = rcube_utils::get_input_value('_host', rcube_utils::INPUT_POST);
$post_user = rcube_utils::get_input_value('_user', rcube_utils::INPUT_POST);
list(, $domain) = explode('@', $post_user);
// direct match in default_host array
if ($default_host[$post_host] || in_array($post_host, array_values($default_host))) {
$host = $post_host;
}
// try to select host by mail domain
else if (!empty($domain)) {
foreach ($default_host as $storage_host => $mail_domains) {
if (is_array($mail_domains) && in_array_nocase($domain, $mail_domains)) {
$host = $storage_host;
break;
}
else if (stripos($storage_host, $domain) !== false || stripos(strval($mail_domains), $domain) !== false) {
$host = is_numeric($storage_host) ? $mail_domains : $storage_host;
break;
}
}
}
// take the first entry if $host is still not set
if (empty($host)) {
$key = key($default_host);
$host = is_numeric($key) ? $default_host[$key] : $key;
}
}
else if (empty($default_host)) {
$host = rcube_utils::get_input_value('_host', rcube_utils::INPUT_POST);
}
else {
$host = rcube_utils::parse_host($default_host);
}
return $host;
} | php | public function autoselect_host()
{
$default_host = $this->config->get('default_host');
$host = null;
if (is_array($default_host)) {
$post_host = rcube_utils::get_input_value('_host', rcube_utils::INPUT_POST);
$post_user = rcube_utils::get_input_value('_user', rcube_utils::INPUT_POST);
list(, $domain) = explode('@', $post_user);
// direct match in default_host array
if ($default_host[$post_host] || in_array($post_host, array_values($default_host))) {
$host = $post_host;
}
// try to select host by mail domain
else if (!empty($domain)) {
foreach ($default_host as $storage_host => $mail_domains) {
if (is_array($mail_domains) && in_array_nocase($domain, $mail_domains)) {
$host = $storage_host;
break;
}
else if (stripos($storage_host, $domain) !== false || stripos(strval($mail_domains), $domain) !== false) {
$host = is_numeric($storage_host) ? $mail_domains : $storage_host;
break;
}
}
}
// take the first entry if $host is still not set
if (empty($host)) {
$key = key($default_host);
$host = is_numeric($key) ? $default_host[$key] : $key;
}
}
else if (empty($default_host)) {
$host = rcube_utils::get_input_value('_host', rcube_utils::INPUT_POST);
}
else {
$host = rcube_utils::parse_host($default_host);
}
return $host;
} | [
"public",
"function",
"autoselect_host",
"(",
")",
"{",
"$",
"default_host",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'default_host'",
")",
";",
"$",
"host",
"=",
"null",
";",
"if",
"(",
"is_array",
"(",
"$",
"default_host",
")",
")",
"{",
"$",
"post_host",
"=",
"rcube_utils",
"::",
"get_input_value",
"(",
"'_host'",
",",
"rcube_utils",
"::",
"INPUT_POST",
")",
";",
"$",
"post_user",
"=",
"rcube_utils",
"::",
"get_input_value",
"(",
"'_user'",
",",
"rcube_utils",
"::",
"INPUT_POST",
")",
";",
"list",
"(",
",",
"$",
"domain",
")",
"=",
"explode",
"(",
"'@'",
",",
"$",
"post_user",
")",
";",
"// direct match in default_host array",
"if",
"(",
"$",
"default_host",
"[",
"$",
"post_host",
"]",
"||",
"in_array",
"(",
"$",
"post_host",
",",
"array_values",
"(",
"$",
"default_host",
")",
")",
")",
"{",
"$",
"host",
"=",
"$",
"post_host",
";",
"}",
"// try to select host by mail domain",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"domain",
")",
")",
"{",
"foreach",
"(",
"$",
"default_host",
"as",
"$",
"storage_host",
"=>",
"$",
"mail_domains",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"mail_domains",
")",
"&&",
"in_array_nocase",
"(",
"$",
"domain",
",",
"$",
"mail_domains",
")",
")",
"{",
"$",
"host",
"=",
"$",
"storage_host",
";",
"break",
";",
"}",
"else",
"if",
"(",
"stripos",
"(",
"$",
"storage_host",
",",
"$",
"domain",
")",
"!==",
"false",
"||",
"stripos",
"(",
"strval",
"(",
"$",
"mail_domains",
")",
",",
"$",
"domain",
")",
"!==",
"false",
")",
"{",
"$",
"host",
"=",
"is_numeric",
"(",
"$",
"storage_host",
")",
"?",
"$",
"mail_domains",
":",
"$",
"storage_host",
";",
"break",
";",
"}",
"}",
"}",
"// take the first entry if $host is still not set",
"if",
"(",
"empty",
"(",
"$",
"host",
")",
")",
"{",
"$",
"key",
"=",
"key",
"(",
"$",
"default_host",
")",
";",
"$",
"host",
"=",
"is_numeric",
"(",
"$",
"key",
")",
"?",
"$",
"default_host",
"[",
"$",
"key",
"]",
":",
"$",
"key",
";",
"}",
"}",
"else",
"if",
"(",
"empty",
"(",
"$",
"default_host",
")",
")",
"{",
"$",
"host",
"=",
"rcube_utils",
"::",
"get_input_value",
"(",
"'_host'",
",",
"rcube_utils",
"::",
"INPUT_POST",
")",
";",
"}",
"else",
"{",
"$",
"host",
"=",
"rcube_utils",
"::",
"parse_host",
"(",
"$",
"default_host",
")",
";",
"}",
"return",
"$",
"host",
";",
"}"
]
| Auto-select IMAP host based on the posted login information
@return string Selected IMAP host | [
"Auto",
"-",
"select",
"IMAP",
"host",
"based",
"on",
"the",
"posted",
"login",
"information"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L724-L767 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.kill_session | public function kill_session()
{
$this->plugins->exec_hook('session_destroy');
$this->session->kill();
$_SESSION = array('language' => $this->user->language, 'temp' => true, 'skin' => $this->config->get('skin'));
$this->user->reset();
} | php | public function kill_session()
{
$this->plugins->exec_hook('session_destroy');
$this->session->kill();
$_SESSION = array('language' => $this->user->language, 'temp' => true, 'skin' => $this->config->get('skin'));
$this->user->reset();
} | [
"public",
"function",
"kill_session",
"(",
")",
"{",
"$",
"this",
"->",
"plugins",
"->",
"exec_hook",
"(",
"'session_destroy'",
")",
";",
"$",
"this",
"->",
"session",
"->",
"kill",
"(",
")",
";",
"$",
"_SESSION",
"=",
"array",
"(",
"'language'",
"=>",
"$",
"this",
"->",
"user",
"->",
"language",
",",
"'temp'",
"=>",
"true",
",",
"'skin'",
"=>",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'skin'",
")",
")",
";",
"$",
"this",
"->",
"user",
"->",
"reset",
"(",
")",
";",
"}"
]
| Destroy session data and remove cookie | [
"Destroy",
"session",
"data",
"and",
"remove",
"cookie"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L772-L779 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.logout_actions | public function logout_actions()
{
$storage = $this->get_storage();
$logout_expunge = $this->config->get('logout_expunge');
$logout_purge = $this->config->get('logout_purge');
$trash_mbox = $this->config->get('trash_mbox');
if ($logout_purge && !empty($trash_mbox)) {
$storage->clear_folder($trash_mbox);
}
if ($logout_expunge) {
$storage->expunge_folder('INBOX');
}
// Try to save unsaved user preferences
if (!empty($_SESSION['preferences'])) {
$this->user->save_prefs(unserialize($_SESSION['preferences']));
}
} | php | public function logout_actions()
{
$storage = $this->get_storage();
$logout_expunge = $this->config->get('logout_expunge');
$logout_purge = $this->config->get('logout_purge');
$trash_mbox = $this->config->get('trash_mbox');
if ($logout_purge && !empty($trash_mbox)) {
$storage->clear_folder($trash_mbox);
}
if ($logout_expunge) {
$storage->expunge_folder('INBOX');
}
// Try to save unsaved user preferences
if (!empty($_SESSION['preferences'])) {
$this->user->save_prefs(unserialize($_SESSION['preferences']));
}
} | [
"public",
"function",
"logout_actions",
"(",
")",
"{",
"$",
"storage",
"=",
"$",
"this",
"->",
"get_storage",
"(",
")",
";",
"$",
"logout_expunge",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'logout_expunge'",
")",
";",
"$",
"logout_purge",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'logout_purge'",
")",
";",
"$",
"trash_mbox",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'trash_mbox'",
")",
";",
"if",
"(",
"$",
"logout_purge",
"&&",
"!",
"empty",
"(",
"$",
"trash_mbox",
")",
")",
"{",
"$",
"storage",
"->",
"clear_folder",
"(",
"$",
"trash_mbox",
")",
";",
"}",
"if",
"(",
"$",
"logout_expunge",
")",
"{",
"$",
"storage",
"->",
"expunge_folder",
"(",
"'INBOX'",
")",
";",
"}",
"// Try to save unsaved user preferences",
"if",
"(",
"!",
"empty",
"(",
"$",
"_SESSION",
"[",
"'preferences'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"user",
"->",
"save_prefs",
"(",
"unserialize",
"(",
"$",
"_SESSION",
"[",
"'preferences'",
"]",
")",
")",
";",
"}",
"}"
]
| Do server side actions on logout | [
"Do",
"server",
"side",
"actions",
"on",
"logout"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L784-L803 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.url | public function url($p, $absolute = false, $full = false, $secure = false)
{
if (!is_array($p)) {
if (strpos($p, 'http') === 0) {
return $p;
}
$p = array('_action' => @func_get_arg(0));
}
$pre = array();
$task = $p['_task'] ?: ($p['task'] ?: $this->task);
$pre['_task'] = $task;
unset($p['task'], $p['_task']);
$url = $this->filename;
$delm = '?';
foreach (array_merge($pre, $p) as $key => $val) {
if ($val !== '' && $val !== null) {
$par = $key[0] == '_' ? $key : '_'.$key;
$url .= $delm.urlencode($par).'='.urlencode($val);
$delm = '&';
}
}
$base_path = strval($_SERVER['REDIRECT_SCRIPT_URL'] ?: $_SERVER['SCRIPT_NAME']);
$base_path = preg_replace('![^/]+$!', '', $base_path);
if ($secure && ($token = $this->get_secure_url_token(true))) {
// add token to the url
$url = $token . '/' . $url;
// remove old token from the path
$base_path = rtrim($base_path, '/');
$base_path = preg_replace('/\/[a-zA-Z0-9]{' . strlen($token) . '}$/', '', $base_path);
// this need to be full url to make redirects work
$absolute = true;
}
else if ($secure && ($token = $this->get_request_token()))
$url .= $delm . '_token=' . urlencode($token);
if ($absolute || $full) {
// add base path to this Roundcube installation
if ($base_path == '') $base_path = '/';
$prefix = $base_path;
// prepend protocol://hostname:port
if ($full) {
$prefix = rcube_utils::resolve_url($prefix);
}
$prefix = rtrim($prefix, '/') . '/';
}
else {
$prefix = './';
}
return $prefix . $url;
} | php | public function url($p, $absolute = false, $full = false, $secure = false)
{
if (!is_array($p)) {
if (strpos($p, 'http') === 0) {
return $p;
}
$p = array('_action' => @func_get_arg(0));
}
$pre = array();
$task = $p['_task'] ?: ($p['task'] ?: $this->task);
$pre['_task'] = $task;
unset($p['task'], $p['_task']);
$url = $this->filename;
$delm = '?';
foreach (array_merge($pre, $p) as $key => $val) {
if ($val !== '' && $val !== null) {
$par = $key[0] == '_' ? $key : '_'.$key;
$url .= $delm.urlencode($par).'='.urlencode($val);
$delm = '&';
}
}
$base_path = strval($_SERVER['REDIRECT_SCRIPT_URL'] ?: $_SERVER['SCRIPT_NAME']);
$base_path = preg_replace('![^/]+$!', '', $base_path);
if ($secure && ($token = $this->get_secure_url_token(true))) {
// add token to the url
$url = $token . '/' . $url;
// remove old token from the path
$base_path = rtrim($base_path, '/');
$base_path = preg_replace('/\/[a-zA-Z0-9]{' . strlen($token) . '}$/', '', $base_path);
// this need to be full url to make redirects work
$absolute = true;
}
else if ($secure && ($token = $this->get_request_token()))
$url .= $delm . '_token=' . urlencode($token);
if ($absolute || $full) {
// add base path to this Roundcube installation
if ($base_path == '') $base_path = '/';
$prefix = $base_path;
// prepend protocol://hostname:port
if ($full) {
$prefix = rcube_utils::resolve_url($prefix);
}
$prefix = rtrim($prefix, '/') . '/';
}
else {
$prefix = './';
}
return $prefix . $url;
} | [
"public",
"function",
"url",
"(",
"$",
"p",
",",
"$",
"absolute",
"=",
"false",
",",
"$",
"full",
"=",
"false",
",",
"$",
"secure",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"p",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"p",
",",
"'http'",
")",
"===",
"0",
")",
"{",
"return",
"$",
"p",
";",
"}",
"$",
"p",
"=",
"array",
"(",
"'_action'",
"=>",
"@",
"func_get_arg",
"(",
"0",
")",
")",
";",
"}",
"$",
"pre",
"=",
"array",
"(",
")",
";",
"$",
"task",
"=",
"$",
"p",
"[",
"'_task'",
"]",
"?",
":",
"(",
"$",
"p",
"[",
"'task'",
"]",
"?",
":",
"$",
"this",
"->",
"task",
")",
";",
"$",
"pre",
"[",
"'_task'",
"]",
"=",
"$",
"task",
";",
"unset",
"(",
"$",
"p",
"[",
"'task'",
"]",
",",
"$",
"p",
"[",
"'_task'",
"]",
")",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"filename",
";",
"$",
"delm",
"=",
"'?'",
";",
"foreach",
"(",
"array_merge",
"(",
"$",
"pre",
",",
"$",
"p",
")",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"val",
"!==",
"''",
"&&",
"$",
"val",
"!==",
"null",
")",
"{",
"$",
"par",
"=",
"$",
"key",
"[",
"0",
"]",
"==",
"'_'",
"?",
"$",
"key",
":",
"'_'",
".",
"$",
"key",
";",
"$",
"url",
".=",
"$",
"delm",
".",
"urlencode",
"(",
"$",
"par",
")",
".",
"'='",
".",
"urlencode",
"(",
"$",
"val",
")",
";",
"$",
"delm",
"=",
"'&'",
";",
"}",
"}",
"$",
"base_path",
"=",
"strval",
"(",
"$",
"_SERVER",
"[",
"'REDIRECT_SCRIPT_URL'",
"]",
"?",
":",
"$",
"_SERVER",
"[",
"'SCRIPT_NAME'",
"]",
")",
";",
"$",
"base_path",
"=",
"preg_replace",
"(",
"'![^/]+$!'",
",",
"''",
",",
"$",
"base_path",
")",
";",
"if",
"(",
"$",
"secure",
"&&",
"(",
"$",
"token",
"=",
"$",
"this",
"->",
"get_secure_url_token",
"(",
"true",
")",
")",
")",
"{",
"// add token to the url",
"$",
"url",
"=",
"$",
"token",
".",
"'/'",
".",
"$",
"url",
";",
"// remove old token from the path",
"$",
"base_path",
"=",
"rtrim",
"(",
"$",
"base_path",
",",
"'/'",
")",
";",
"$",
"base_path",
"=",
"preg_replace",
"(",
"'/\\/[a-zA-Z0-9]{'",
".",
"strlen",
"(",
"$",
"token",
")",
".",
"'}$/'",
",",
"''",
",",
"$",
"base_path",
")",
";",
"// this need to be full url to make redirects work",
"$",
"absolute",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"$",
"secure",
"&&",
"(",
"$",
"token",
"=",
"$",
"this",
"->",
"get_request_token",
"(",
")",
")",
")",
"$",
"url",
".=",
"$",
"delm",
".",
"'_token='",
".",
"urlencode",
"(",
"$",
"token",
")",
";",
"if",
"(",
"$",
"absolute",
"||",
"$",
"full",
")",
"{",
"// add base path to this Roundcube installation",
"if",
"(",
"$",
"base_path",
"==",
"''",
")",
"$",
"base_path",
"=",
"'/'",
";",
"$",
"prefix",
"=",
"$",
"base_path",
";",
"// prepend protocol://hostname:port",
"if",
"(",
"$",
"full",
")",
"{",
"$",
"prefix",
"=",
"rcube_utils",
"::",
"resolve_url",
"(",
"$",
"prefix",
")",
";",
"}",
"$",
"prefix",
"=",
"rtrim",
"(",
"$",
"prefix",
",",
"'/'",
")",
".",
"'/'",
";",
"}",
"else",
"{",
"$",
"prefix",
"=",
"'./'",
";",
"}",
"return",
"$",
"prefix",
".",
"$",
"url",
";",
"}"
]
| Build a valid URL to this instance of Roundcube
@param mixed $p Either a string with the action or
url parameters as key-value pairs
@param boolean $absolute Build an URL absolute to document root
@param boolean $full Create fully qualified URL including http(s):// and hostname
@param bool $secure Return absolute URL in secure location
@return string Valid application URL | [
"Build",
"a",
"valid",
"URL",
"to",
"this",
"instance",
"of",
"Roundcube"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L816-L876 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.shutdown | public function shutdown()
{
parent::shutdown();
foreach ($this->address_books as $book) {
if (is_object($book) && is_a($book, 'rcube_addressbook')) {
$book->close();
}
}
// write performance stats to logs/console
if ($this->config->get('devel_mode') || $this->config->get('performance_stats')) {
// make sure logged numbers use unified format
setlocale(LC_NUMERIC, 'en_US.utf8', 'en_US.UTF-8', 'en_US', 'C');
if (function_exists('memory_get_usage')) {
$mem = $this->show_bytes(memory_get_usage());
}
if (function_exists('memory_get_peak_usage')) {
$mem .= '/'.$this->show_bytes(memory_get_peak_usage());
}
$log = $this->task . ($this->action ? '/'.$this->action : '') . ($mem ? " [$mem]" : '');
if (defined('RCMAIL_START')) {
self::print_timer(RCMAIL_START, $log);
}
else {
self::console($log);
}
}
} | php | public function shutdown()
{
parent::shutdown();
foreach ($this->address_books as $book) {
if (is_object($book) && is_a($book, 'rcube_addressbook')) {
$book->close();
}
}
// write performance stats to logs/console
if ($this->config->get('devel_mode') || $this->config->get('performance_stats')) {
// make sure logged numbers use unified format
setlocale(LC_NUMERIC, 'en_US.utf8', 'en_US.UTF-8', 'en_US', 'C');
if (function_exists('memory_get_usage')) {
$mem = $this->show_bytes(memory_get_usage());
}
if (function_exists('memory_get_peak_usage')) {
$mem .= '/'.$this->show_bytes(memory_get_peak_usage());
}
$log = $this->task . ($this->action ? '/'.$this->action : '') . ($mem ? " [$mem]" : '');
if (defined('RCMAIL_START')) {
self::print_timer(RCMAIL_START, $log);
}
else {
self::console($log);
}
}
} | [
"public",
"function",
"shutdown",
"(",
")",
"{",
"parent",
"::",
"shutdown",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"address_books",
"as",
"$",
"book",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"book",
")",
"&&",
"is_a",
"(",
"$",
"book",
",",
"'rcube_addressbook'",
")",
")",
"{",
"$",
"book",
"->",
"close",
"(",
")",
";",
"}",
"}",
"// write performance stats to logs/console",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'devel_mode'",
")",
"||",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'performance_stats'",
")",
")",
"{",
"// make sure logged numbers use unified format",
"setlocale",
"(",
"LC_NUMERIC",
",",
"'en_US.utf8'",
",",
"'en_US.UTF-8'",
",",
"'en_US'",
",",
"'C'",
")",
";",
"if",
"(",
"function_exists",
"(",
"'memory_get_usage'",
")",
")",
"{",
"$",
"mem",
"=",
"$",
"this",
"->",
"show_bytes",
"(",
"memory_get_usage",
"(",
")",
")",
";",
"}",
"if",
"(",
"function_exists",
"(",
"'memory_get_peak_usage'",
")",
")",
"{",
"$",
"mem",
".=",
"'/'",
".",
"$",
"this",
"->",
"show_bytes",
"(",
"memory_get_peak_usage",
"(",
")",
")",
";",
"}",
"$",
"log",
"=",
"$",
"this",
"->",
"task",
".",
"(",
"$",
"this",
"->",
"action",
"?",
"'/'",
".",
"$",
"this",
"->",
"action",
":",
"''",
")",
".",
"(",
"$",
"mem",
"?",
"\" [$mem]\"",
":",
"''",
")",
";",
"if",
"(",
"defined",
"(",
"'RCMAIL_START'",
")",
")",
"{",
"self",
"::",
"print_timer",
"(",
"RCMAIL_START",
",",
"$",
"log",
")",
";",
"}",
"else",
"{",
"self",
"::",
"console",
"(",
"$",
"log",
")",
";",
"}",
"}",
"}"
]
| Function to be executed in script shutdown | [
"Function",
"to",
"be",
"executed",
"in",
"script",
"shutdown"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L881-L912 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.request_security_check | public function request_security_check($mode = rcube_utils::INPUT_POST)
{
// check request token
if (!$this->check_request($mode)) {
$error = array('code' => 403, 'message' => "Request security check failed");
self::raise_error($error, false, true);
}
// check referer if configured
if ($this->config->get('referer_check') && !rcube_utils::check_referer()) {
$error = array('code' => 403, 'message' => "Referer check failed");
self::raise_error($error, true, true);
}
} | php | public function request_security_check($mode = rcube_utils::INPUT_POST)
{
// check request token
if (!$this->check_request($mode)) {
$error = array('code' => 403, 'message' => "Request security check failed");
self::raise_error($error, false, true);
}
// check referer if configured
if ($this->config->get('referer_check') && !rcube_utils::check_referer()) {
$error = array('code' => 403, 'message' => "Referer check failed");
self::raise_error($error, true, true);
}
} | [
"public",
"function",
"request_security_check",
"(",
"$",
"mode",
"=",
"rcube_utils",
"::",
"INPUT_POST",
")",
"{",
"// check request token",
"if",
"(",
"!",
"$",
"this",
"->",
"check_request",
"(",
"$",
"mode",
")",
")",
"{",
"$",
"error",
"=",
"array",
"(",
"'code'",
"=>",
"403",
",",
"'message'",
"=>",
"\"Request security check failed\"",
")",
";",
"self",
"::",
"raise_error",
"(",
"$",
"error",
",",
"false",
",",
"true",
")",
";",
"}",
"// check referer if configured",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'referer_check'",
")",
"&&",
"!",
"rcube_utils",
"::",
"check_referer",
"(",
")",
")",
"{",
"$",
"error",
"=",
"array",
"(",
"'code'",
"=>",
"403",
",",
"'message'",
"=>",
"\"Referer check failed\"",
")",
";",
"self",
"::",
"raise_error",
"(",
"$",
"error",
",",
"true",
",",
"true",
")",
";",
"}",
"}"
]
| CSRF attack prevention code. Raises error when check fails.
@param int $mode Request mode | [
"CSRF",
"attack",
"prevention",
"code",
".",
"Raises",
"error",
"when",
"check",
"fails",
"."
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L919-L932 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.register_action_map | public function register_action_map($map)
{
if (is_array($map)) {
foreach ($map as $idx => $val) {
$this->action_map[$idx] = $val;
}
}
} | php | public function register_action_map($map)
{
if (is_array($map)) {
foreach ($map as $idx => $val) {
$this->action_map[$idx] = $val;
}
}
} | [
"public",
"function",
"register_action_map",
"(",
"$",
"map",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"map",
")",
")",
"{",
"foreach",
"(",
"$",
"map",
"as",
"$",
"idx",
"=>",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"action_map",
"[",
"$",
"idx",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"}"
]
| Registers action aliases for current task
@param array $map Alias-to-filename hash array | [
"Registers",
"action",
"aliases",
"for",
"current",
"task"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L939-L946 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.get_action_file | public function get_action_file()
{
if (!empty($this->action_map[$this->action])) {
return $this->action_map[$this->action];
}
return strtr($this->action, '-', '_') . '.inc';
} | php | public function get_action_file()
{
if (!empty($this->action_map[$this->action])) {
return $this->action_map[$this->action];
}
return strtr($this->action, '-', '_') . '.inc';
} | [
"public",
"function",
"get_action_file",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"action_map",
"[",
"$",
"this",
"->",
"action",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"action_map",
"[",
"$",
"this",
"->",
"action",
"]",
";",
"}",
"return",
"strtr",
"(",
"$",
"this",
"->",
"action",
",",
"'-'",
",",
"'_'",
")",
".",
"'.inc'",
";",
"}"
]
| Returns current action filename
@param array $map Alias-to-filename hash array | [
"Returns",
"current",
"action",
"filename"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L953-L960 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.set_env_config | public function set_env_config($options)
{
foreach ((array) $options as $option) {
if ($this->config->get($option)) {
$this->output->set_env($option, true);
}
}
} | php | public function set_env_config($options)
{
foreach ((array) $options as $option) {
if ($this->config->get($option)) {
$this->output->set_env($option, true);
}
}
} | [
"public",
"function",
"set_env_config",
"(",
"$",
"options",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"options",
"as",
"$",
"option",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"$",
"option",
")",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"$",
"option",
",",
"true",
")",
";",
"}",
"}",
"}"
]
| Set environment variables for specified config options
@param array $options List of configuration option names | [
"Set",
"environment",
"variables",
"for",
"specified",
"config",
"options"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L1076-L1083 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.user_date | public function user_date()
{
// get user's timezone
try {
$tz = new DateTimeZone($this->config->get('timezone'));
$date = new DateTime('now', $tz);
}
catch (Exception $e) {
$date = new DateTime();
}
return $date->format('r');
} | php | public function user_date()
{
// get user's timezone
try {
$tz = new DateTimeZone($this->config->get('timezone'));
$date = new DateTime('now', $tz);
}
catch (Exception $e) {
$date = new DateTime();
}
return $date->format('r');
} | [
"public",
"function",
"user_date",
"(",
")",
"{",
"// get user's timezone",
"try",
"{",
"$",
"tz",
"=",
"new",
"DateTimeZone",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'timezone'",
")",
")",
";",
"$",
"date",
"=",
"new",
"DateTime",
"(",
"'now'",
",",
"$",
"tz",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"date",
"=",
"new",
"DateTime",
"(",
")",
";",
"}",
"return",
"$",
"date",
"->",
"format",
"(",
"'r'",
")",
";",
"}"
]
| Returns RFC2822 formatted current date in user's timezone
@return string Date | [
"Returns",
"RFC2822",
"formatted",
"current",
"date",
"in",
"user",
"s",
"timezone"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L1090-L1102 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.table_output | public function table_output($attrib, $table_data, $show_cols, $id_col)
{
$table = new html_table($attrib);
// add table header
if (!$attrib['noheader']) {
foreach ($show_cols as $col) {
$table->add_header($col, $this->Q($this->gettext($col)));
}
}
if (!is_array($table_data)) {
$db = $this->get_dbh();
while ($table_data && ($sql_arr = $db->fetch_assoc($table_data))) {
$table->add_row(array('id' => 'rcmrow' . rcube_utils::html_identifier($sql_arr[$id_col])));
// format each col
foreach ($show_cols as $col) {
$table->add($col, $this->Q($sql_arr[$col]));
}
}
}
else {
foreach ($table_data as $row_data) {
$class = !empty($row_data['class']) ? $row_data['class'] : null;
if (!empty($attrib['rowclass']))
$class = trim($class . ' ' . $attrib['rowclass']);
$rowid = 'rcmrow' . rcube_utils::html_identifier($row_data[$id_col]);
$table->add_row(array('id' => $rowid, 'class' => $class));
// format each col
foreach ($show_cols as $col) {
$val = is_array($row_data[$col]) ? $row_data[$col][0] : $row_data[$col];
$table->add($col, empty($attrib['ishtml']) ? $this->Q($val) : $val);
}
}
}
return $table->show($attrib);
} | php | public function table_output($attrib, $table_data, $show_cols, $id_col)
{
$table = new html_table($attrib);
// add table header
if (!$attrib['noheader']) {
foreach ($show_cols as $col) {
$table->add_header($col, $this->Q($this->gettext($col)));
}
}
if (!is_array($table_data)) {
$db = $this->get_dbh();
while ($table_data && ($sql_arr = $db->fetch_assoc($table_data))) {
$table->add_row(array('id' => 'rcmrow' . rcube_utils::html_identifier($sql_arr[$id_col])));
// format each col
foreach ($show_cols as $col) {
$table->add($col, $this->Q($sql_arr[$col]));
}
}
}
else {
foreach ($table_data as $row_data) {
$class = !empty($row_data['class']) ? $row_data['class'] : null;
if (!empty($attrib['rowclass']))
$class = trim($class . ' ' . $attrib['rowclass']);
$rowid = 'rcmrow' . rcube_utils::html_identifier($row_data[$id_col]);
$table->add_row(array('id' => $rowid, 'class' => $class));
// format each col
foreach ($show_cols as $col) {
$val = is_array($row_data[$col]) ? $row_data[$col][0] : $row_data[$col];
$table->add($col, empty($attrib['ishtml']) ? $this->Q($val) : $val);
}
}
}
return $table->show($attrib);
} | [
"public",
"function",
"table_output",
"(",
"$",
"attrib",
",",
"$",
"table_data",
",",
"$",
"show_cols",
",",
"$",
"id_col",
")",
"{",
"$",
"table",
"=",
"new",
"html_table",
"(",
"$",
"attrib",
")",
";",
"// add table header",
"if",
"(",
"!",
"$",
"attrib",
"[",
"'noheader'",
"]",
")",
"{",
"foreach",
"(",
"$",
"show_cols",
"as",
"$",
"col",
")",
"{",
"$",
"table",
"->",
"add_header",
"(",
"$",
"col",
",",
"$",
"this",
"->",
"Q",
"(",
"$",
"this",
"->",
"gettext",
"(",
"$",
"col",
")",
")",
")",
";",
"}",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"table_data",
")",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"get_dbh",
"(",
")",
";",
"while",
"(",
"$",
"table_data",
"&&",
"(",
"$",
"sql_arr",
"=",
"$",
"db",
"->",
"fetch_assoc",
"(",
"$",
"table_data",
")",
")",
")",
"{",
"$",
"table",
"->",
"add_row",
"(",
"array",
"(",
"'id'",
"=>",
"'rcmrow'",
".",
"rcube_utils",
"::",
"html_identifier",
"(",
"$",
"sql_arr",
"[",
"$",
"id_col",
"]",
")",
")",
")",
";",
"// format each col",
"foreach",
"(",
"$",
"show_cols",
"as",
"$",
"col",
")",
"{",
"$",
"table",
"->",
"add",
"(",
"$",
"col",
",",
"$",
"this",
"->",
"Q",
"(",
"$",
"sql_arr",
"[",
"$",
"col",
"]",
")",
")",
";",
"}",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"table_data",
"as",
"$",
"row_data",
")",
"{",
"$",
"class",
"=",
"!",
"empty",
"(",
"$",
"row_data",
"[",
"'class'",
"]",
")",
"?",
"$",
"row_data",
"[",
"'class'",
"]",
":",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"attrib",
"[",
"'rowclass'",
"]",
")",
")",
"$",
"class",
"=",
"trim",
"(",
"$",
"class",
".",
"' '",
".",
"$",
"attrib",
"[",
"'rowclass'",
"]",
")",
";",
"$",
"rowid",
"=",
"'rcmrow'",
".",
"rcube_utils",
"::",
"html_identifier",
"(",
"$",
"row_data",
"[",
"$",
"id_col",
"]",
")",
";",
"$",
"table",
"->",
"add_row",
"(",
"array",
"(",
"'id'",
"=>",
"$",
"rowid",
",",
"'class'",
"=>",
"$",
"class",
")",
")",
";",
"// format each col",
"foreach",
"(",
"$",
"show_cols",
"as",
"$",
"col",
")",
"{",
"$",
"val",
"=",
"is_array",
"(",
"$",
"row_data",
"[",
"$",
"col",
"]",
")",
"?",
"$",
"row_data",
"[",
"$",
"col",
"]",
"[",
"0",
"]",
":",
"$",
"row_data",
"[",
"$",
"col",
"]",
";",
"$",
"table",
"->",
"add",
"(",
"$",
"col",
",",
"empty",
"(",
"$",
"attrib",
"[",
"'ishtml'",
"]",
")",
"?",
"$",
"this",
"->",
"Q",
"(",
"$",
"val",
")",
":",
"$",
"val",
")",
";",
"}",
"}",
"}",
"return",
"$",
"table",
"->",
"show",
"(",
"$",
"attrib",
")",
";",
"}"
]
| Create a HTML table based on the given data
@param array $attrib Named table attributes
@param mixed $table_data Table row data. Either a two-dimensional array
or a valid SQL result set
@param array $show_cols List of cols to show
@param string $id_col Name of the identifier col
@return string HTML table code | [
"Create",
"a",
"HTML",
"table",
"based",
"on",
"the",
"given",
"data"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L1152-L1192 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.folder_selector | public function folder_selector($p = array())
{
$realnames = $this->config->get('show_real_foldernames');
$p += array('maxlength' => 100, 'realnames' => $realnames, 'is_escaped' => true);
$a_mailboxes = array();
$storage = $this->get_storage();
if (empty($p['folder_name'])) {
$p['folder_name'] = '*';
}
if ($p['unsubscribed']) {
$list = $storage->list_folders('', $p['folder_name'], $p['folder_filter'], $p['folder_rights']);
}
else {
$list = $storage->list_folders_subscribed('', $p['folder_name'], $p['folder_filter'], $p['folder_rights']);
}
$delimiter = $storage->get_hierarchy_delimiter();
if (!empty($p['exceptions'])) {
$list = array_diff($list, (array) $p['exceptions']);
}
if (!empty($p['additional'])) {
foreach ($p['additional'] as $add_folder) {
$add_items = explode($delimiter, $add_folder);
$folder = '';
while (count($add_items)) {
$folder .= array_shift($add_items);
// @TODO: sorting
if (!in_array($folder, $list)) {
$list[] = $folder;
}
$folder .= $delimiter;
}
}
}
foreach ($list as $folder) {
$this->build_folder_tree($a_mailboxes, $folder, $delimiter);
}
$select = new html_select($p);
if ($p['noselection']) {
$select->add(html::quote($p['noselection']), '');
}
$this->render_folder_tree_select($a_mailboxes, $mbox, $p['maxlength'], $select, $p['realnames'], 0, $p);
return $select;
} | php | public function folder_selector($p = array())
{
$realnames = $this->config->get('show_real_foldernames');
$p += array('maxlength' => 100, 'realnames' => $realnames, 'is_escaped' => true);
$a_mailboxes = array();
$storage = $this->get_storage();
if (empty($p['folder_name'])) {
$p['folder_name'] = '*';
}
if ($p['unsubscribed']) {
$list = $storage->list_folders('', $p['folder_name'], $p['folder_filter'], $p['folder_rights']);
}
else {
$list = $storage->list_folders_subscribed('', $p['folder_name'], $p['folder_filter'], $p['folder_rights']);
}
$delimiter = $storage->get_hierarchy_delimiter();
if (!empty($p['exceptions'])) {
$list = array_diff($list, (array) $p['exceptions']);
}
if (!empty($p['additional'])) {
foreach ($p['additional'] as $add_folder) {
$add_items = explode($delimiter, $add_folder);
$folder = '';
while (count($add_items)) {
$folder .= array_shift($add_items);
// @TODO: sorting
if (!in_array($folder, $list)) {
$list[] = $folder;
}
$folder .= $delimiter;
}
}
}
foreach ($list as $folder) {
$this->build_folder_tree($a_mailboxes, $folder, $delimiter);
}
$select = new html_select($p);
if ($p['noselection']) {
$select->add(html::quote($p['noselection']), '');
}
$this->render_folder_tree_select($a_mailboxes, $mbox, $p['maxlength'], $select, $p['realnames'], 0, $p);
return $select;
} | [
"public",
"function",
"folder_selector",
"(",
"$",
"p",
"=",
"array",
"(",
")",
")",
"{",
"$",
"realnames",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'show_real_foldernames'",
")",
";",
"$",
"p",
"+=",
"array",
"(",
"'maxlength'",
"=>",
"100",
",",
"'realnames'",
"=>",
"$",
"realnames",
",",
"'is_escaped'",
"=>",
"true",
")",
";",
"$",
"a_mailboxes",
"=",
"array",
"(",
")",
";",
"$",
"storage",
"=",
"$",
"this",
"->",
"get_storage",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"p",
"[",
"'folder_name'",
"]",
")",
")",
"{",
"$",
"p",
"[",
"'folder_name'",
"]",
"=",
"'*'",
";",
"}",
"if",
"(",
"$",
"p",
"[",
"'unsubscribed'",
"]",
")",
"{",
"$",
"list",
"=",
"$",
"storage",
"->",
"list_folders",
"(",
"''",
",",
"$",
"p",
"[",
"'folder_name'",
"]",
",",
"$",
"p",
"[",
"'folder_filter'",
"]",
",",
"$",
"p",
"[",
"'folder_rights'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"list",
"=",
"$",
"storage",
"->",
"list_folders_subscribed",
"(",
"''",
",",
"$",
"p",
"[",
"'folder_name'",
"]",
",",
"$",
"p",
"[",
"'folder_filter'",
"]",
",",
"$",
"p",
"[",
"'folder_rights'",
"]",
")",
";",
"}",
"$",
"delimiter",
"=",
"$",
"storage",
"->",
"get_hierarchy_delimiter",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"p",
"[",
"'exceptions'",
"]",
")",
")",
"{",
"$",
"list",
"=",
"array_diff",
"(",
"$",
"list",
",",
"(",
"array",
")",
"$",
"p",
"[",
"'exceptions'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"p",
"[",
"'additional'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"p",
"[",
"'additional'",
"]",
"as",
"$",
"add_folder",
")",
"{",
"$",
"add_items",
"=",
"explode",
"(",
"$",
"delimiter",
",",
"$",
"add_folder",
")",
";",
"$",
"folder",
"=",
"''",
";",
"while",
"(",
"count",
"(",
"$",
"add_items",
")",
")",
"{",
"$",
"folder",
".=",
"array_shift",
"(",
"$",
"add_items",
")",
";",
"// @TODO: sorting",
"if",
"(",
"!",
"in_array",
"(",
"$",
"folder",
",",
"$",
"list",
")",
")",
"{",
"$",
"list",
"[",
"]",
"=",
"$",
"folder",
";",
"}",
"$",
"folder",
".=",
"$",
"delimiter",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"list",
"as",
"$",
"folder",
")",
"{",
"$",
"this",
"->",
"build_folder_tree",
"(",
"$",
"a_mailboxes",
",",
"$",
"folder",
",",
"$",
"delimiter",
")",
";",
"}",
"$",
"select",
"=",
"new",
"html_select",
"(",
"$",
"p",
")",
";",
"if",
"(",
"$",
"p",
"[",
"'noselection'",
"]",
")",
"{",
"$",
"select",
"->",
"add",
"(",
"html",
"::",
"quote",
"(",
"$",
"p",
"[",
"'noselection'",
"]",
")",
",",
"''",
")",
";",
"}",
"$",
"this",
"->",
"render_folder_tree_select",
"(",
"$",
"a_mailboxes",
",",
"$",
"mbox",
",",
"$",
"p",
"[",
"'maxlength'",
"]",
",",
"$",
"select",
",",
"$",
"p",
"[",
"'realnames'",
"]",
",",
"0",
",",
"$",
"p",
")",
";",
"return",
"$",
"select",
";",
"}"
]
| Return folders list as html_select object
@param array $p Named parameters
@return html_select HTML drop-down object | [
"Return",
"folders",
"list",
"as",
"html_select",
"object"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L1420-L1474 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.build_folder_tree | public function build_folder_tree(&$arrFolders, $folder, $delm = '/', $path = '')
{
// Handle namespace prefix
$prefix = '';
if (!$path) {
$n_folder = $folder;
$folder = $this->storage->mod_folder($folder);
if ($n_folder != $folder) {
$prefix = substr($n_folder, 0, -strlen($folder));
}
}
$pos = strpos($folder, $delm);
if ($pos !== false) {
$subFolders = substr($folder, $pos+1);
$currentFolder = substr($folder, 0, $pos);
// sometimes folder has a delimiter as the last character
if (!strlen($subFolders)) {
$virtual = false;
}
else if (!isset($arrFolders[$currentFolder])) {
$virtual = true;
}
else {
$virtual = $arrFolders[$currentFolder]['virtual'];
}
}
else {
$subFolders = false;
$currentFolder = $folder;
$virtual = false;
}
$path .= $prefix . $currentFolder;
if (!isset($arrFolders[$currentFolder])) {
$arrFolders[$currentFolder] = array(
'id' => $path,
'name' => rcube_charset::convert($currentFolder, 'UTF7-IMAP'),
'virtual' => $virtual,
'folders' => array()
);
}
else {
$arrFolders[$currentFolder]['virtual'] = $virtual;
}
if (strlen($subFolders)) {
$this->build_folder_tree($arrFolders[$currentFolder]['folders'], $subFolders, $delm, $path.$delm);
}
} | php | public function build_folder_tree(&$arrFolders, $folder, $delm = '/', $path = '')
{
// Handle namespace prefix
$prefix = '';
if (!$path) {
$n_folder = $folder;
$folder = $this->storage->mod_folder($folder);
if ($n_folder != $folder) {
$prefix = substr($n_folder, 0, -strlen($folder));
}
}
$pos = strpos($folder, $delm);
if ($pos !== false) {
$subFolders = substr($folder, $pos+1);
$currentFolder = substr($folder, 0, $pos);
// sometimes folder has a delimiter as the last character
if (!strlen($subFolders)) {
$virtual = false;
}
else if (!isset($arrFolders[$currentFolder])) {
$virtual = true;
}
else {
$virtual = $arrFolders[$currentFolder]['virtual'];
}
}
else {
$subFolders = false;
$currentFolder = $folder;
$virtual = false;
}
$path .= $prefix . $currentFolder;
if (!isset($arrFolders[$currentFolder])) {
$arrFolders[$currentFolder] = array(
'id' => $path,
'name' => rcube_charset::convert($currentFolder, 'UTF7-IMAP'),
'virtual' => $virtual,
'folders' => array()
);
}
else {
$arrFolders[$currentFolder]['virtual'] = $virtual;
}
if (strlen($subFolders)) {
$this->build_folder_tree($arrFolders[$currentFolder]['folders'], $subFolders, $delm, $path.$delm);
}
} | [
"public",
"function",
"build_folder_tree",
"(",
"&",
"$",
"arrFolders",
",",
"$",
"folder",
",",
"$",
"delm",
"=",
"'/'",
",",
"$",
"path",
"=",
"''",
")",
"{",
"// Handle namespace prefix",
"$",
"prefix",
"=",
"''",
";",
"if",
"(",
"!",
"$",
"path",
")",
"{",
"$",
"n_folder",
"=",
"$",
"folder",
";",
"$",
"folder",
"=",
"$",
"this",
"->",
"storage",
"->",
"mod_folder",
"(",
"$",
"folder",
")",
";",
"if",
"(",
"$",
"n_folder",
"!=",
"$",
"folder",
")",
"{",
"$",
"prefix",
"=",
"substr",
"(",
"$",
"n_folder",
",",
"0",
",",
"-",
"strlen",
"(",
"$",
"folder",
")",
")",
";",
"}",
"}",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"folder",
",",
"$",
"delm",
")",
";",
"if",
"(",
"$",
"pos",
"!==",
"false",
")",
"{",
"$",
"subFolders",
"=",
"substr",
"(",
"$",
"folder",
",",
"$",
"pos",
"+",
"1",
")",
";",
"$",
"currentFolder",
"=",
"substr",
"(",
"$",
"folder",
",",
"0",
",",
"$",
"pos",
")",
";",
"// sometimes folder has a delimiter as the last character",
"if",
"(",
"!",
"strlen",
"(",
"$",
"subFolders",
")",
")",
"{",
"$",
"virtual",
"=",
"false",
";",
"}",
"else",
"if",
"(",
"!",
"isset",
"(",
"$",
"arrFolders",
"[",
"$",
"currentFolder",
"]",
")",
")",
"{",
"$",
"virtual",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"virtual",
"=",
"$",
"arrFolders",
"[",
"$",
"currentFolder",
"]",
"[",
"'virtual'",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"subFolders",
"=",
"false",
";",
"$",
"currentFolder",
"=",
"$",
"folder",
";",
"$",
"virtual",
"=",
"false",
";",
"}",
"$",
"path",
".=",
"$",
"prefix",
".",
"$",
"currentFolder",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"arrFolders",
"[",
"$",
"currentFolder",
"]",
")",
")",
"{",
"$",
"arrFolders",
"[",
"$",
"currentFolder",
"]",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"path",
",",
"'name'",
"=>",
"rcube_charset",
"::",
"convert",
"(",
"$",
"currentFolder",
",",
"'UTF7-IMAP'",
")",
",",
"'virtual'",
"=>",
"$",
"virtual",
",",
"'folders'",
"=>",
"array",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"arrFolders",
"[",
"$",
"currentFolder",
"]",
"[",
"'virtual'",
"]",
"=",
"$",
"virtual",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"subFolders",
")",
")",
"{",
"$",
"this",
"->",
"build_folder_tree",
"(",
"$",
"arrFolders",
"[",
"$",
"currentFolder",
"]",
"[",
"'folders'",
"]",
",",
"$",
"subFolders",
",",
"$",
"delm",
",",
"$",
"path",
".",
"$",
"delm",
")",
";",
"}",
"}"
]
| Create a hierarchical array of the mailbox list | [
"Create",
"a",
"hierarchical",
"array",
"of",
"the",
"mailbox",
"list"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L1479-L1532 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.folder_classname | public function folder_classname($folder_id)
{
if ($folder_id == 'INBOX') {
return 'inbox';
}
// for these mailboxes we have localized labels and css classes
foreach (array('sent', 'drafts', 'trash', 'junk') as $smbx)
{
if ($folder_id === $this->config->get($smbx.'_mbox')) {
return $smbx;
}
}
} | php | public function folder_classname($folder_id)
{
if ($folder_id == 'INBOX') {
return 'inbox';
}
// for these mailboxes we have localized labels and css classes
foreach (array('sent', 'drafts', 'trash', 'junk') as $smbx)
{
if ($folder_id === $this->config->get($smbx.'_mbox')) {
return $smbx;
}
}
} | [
"public",
"function",
"folder_classname",
"(",
"$",
"folder_id",
")",
"{",
"if",
"(",
"$",
"folder_id",
"==",
"'INBOX'",
")",
"{",
"return",
"'inbox'",
";",
"}",
"// for these mailboxes we have localized labels and css classes",
"foreach",
"(",
"array",
"(",
"'sent'",
",",
"'drafts'",
",",
"'trash'",
",",
"'junk'",
")",
"as",
"$",
"smbx",
")",
"{",
"if",
"(",
"$",
"folder_id",
"===",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"$",
"smbx",
".",
"'_mbox'",
")",
")",
"{",
"return",
"$",
"smbx",
";",
"}",
"}",
"}"
]
| Return internal name for the given folder if it matches the configured special folders | [
"Return",
"internal",
"name",
"for",
"the",
"given",
"folder",
"if",
"it",
"matches",
"the",
"configured",
"special",
"folders"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L1676-L1689 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.localize_foldername | public function localize_foldername($name, $with_path = false, $path_remove = false)
{
$realnames = $this->config->get('show_real_foldernames');
if (!$realnames && ($folder_class = $this->folder_classname($name))) {
return $this->gettext($folder_class);
}
$storage = $this->get_storage();
$delimiter = $storage->get_hierarchy_delimiter();
// Remove the path
if ($path_remove) {
if (strpos($name, $delimiter)) {
$path = explode($delimiter, $name);
$name = array_pop($path);
}
}
// try to localize path of the folder
else if ($with_path && !$realnames) {
$path = explode($delimiter, $name);
$count = count($path);
if ($count > 1) {
for ($i = 1; $i < $count; $i++) {
$folder = implode($delimiter, array_slice($path, 0, -$i));
if ($folder_class = $this->folder_classname($folder)) {
$name = implode($delimiter, array_slice($path, $count - $i));
$name = rcube_charset::convert($name, 'UTF7-IMAP');
return $this->gettext($folder_class) . $delimiter . $name;
}
}
}
}
return rcube_charset::convert($name, 'UTF7-IMAP');
} | php | public function localize_foldername($name, $with_path = false, $path_remove = false)
{
$realnames = $this->config->get('show_real_foldernames');
if (!$realnames && ($folder_class = $this->folder_classname($name))) {
return $this->gettext($folder_class);
}
$storage = $this->get_storage();
$delimiter = $storage->get_hierarchy_delimiter();
// Remove the path
if ($path_remove) {
if (strpos($name, $delimiter)) {
$path = explode($delimiter, $name);
$name = array_pop($path);
}
}
// try to localize path of the folder
else if ($with_path && !$realnames) {
$path = explode($delimiter, $name);
$count = count($path);
if ($count > 1) {
for ($i = 1; $i < $count; $i++) {
$folder = implode($delimiter, array_slice($path, 0, -$i));
if ($folder_class = $this->folder_classname($folder)) {
$name = implode($delimiter, array_slice($path, $count - $i));
$name = rcube_charset::convert($name, 'UTF7-IMAP');
return $this->gettext($folder_class) . $delimiter . $name;
}
}
}
}
return rcube_charset::convert($name, 'UTF7-IMAP');
} | [
"public",
"function",
"localize_foldername",
"(",
"$",
"name",
",",
"$",
"with_path",
"=",
"false",
",",
"$",
"path_remove",
"=",
"false",
")",
"{",
"$",
"realnames",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'show_real_foldernames'",
")",
";",
"if",
"(",
"!",
"$",
"realnames",
"&&",
"(",
"$",
"folder_class",
"=",
"$",
"this",
"->",
"folder_classname",
"(",
"$",
"name",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"gettext",
"(",
"$",
"folder_class",
")",
";",
"}",
"$",
"storage",
"=",
"$",
"this",
"->",
"get_storage",
"(",
")",
";",
"$",
"delimiter",
"=",
"$",
"storage",
"->",
"get_hierarchy_delimiter",
"(",
")",
";",
"// Remove the path",
"if",
"(",
"$",
"path_remove",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"$",
"delimiter",
")",
")",
"{",
"$",
"path",
"=",
"explode",
"(",
"$",
"delimiter",
",",
"$",
"name",
")",
";",
"$",
"name",
"=",
"array_pop",
"(",
"$",
"path",
")",
";",
"}",
"}",
"// try to localize path of the folder",
"else",
"if",
"(",
"$",
"with_path",
"&&",
"!",
"$",
"realnames",
")",
"{",
"$",
"path",
"=",
"explode",
"(",
"$",
"delimiter",
",",
"$",
"name",
")",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"count",
">",
"1",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"++",
")",
"{",
"$",
"folder",
"=",
"implode",
"(",
"$",
"delimiter",
",",
"array_slice",
"(",
"$",
"path",
",",
"0",
",",
"-",
"$",
"i",
")",
")",
";",
"if",
"(",
"$",
"folder_class",
"=",
"$",
"this",
"->",
"folder_classname",
"(",
"$",
"folder",
")",
")",
"{",
"$",
"name",
"=",
"implode",
"(",
"$",
"delimiter",
",",
"array_slice",
"(",
"$",
"path",
",",
"$",
"count",
"-",
"$",
"i",
")",
")",
";",
"$",
"name",
"=",
"rcube_charset",
"::",
"convert",
"(",
"$",
"name",
",",
"'UTF7-IMAP'",
")",
";",
"return",
"$",
"this",
"->",
"gettext",
"(",
"$",
"folder_class",
")",
".",
"$",
"delimiter",
".",
"$",
"name",
";",
"}",
"}",
"}",
"}",
"return",
"rcube_charset",
"::",
"convert",
"(",
"$",
"name",
",",
"'UTF7-IMAP'",
")",
";",
"}"
]
| Try to localize the given IMAP folder name.
UTF-7 decode it in case no localized text was found
@param string $name Folder name
@param bool $with_path Enable path localization
@param bool $path_remove Remove the path
@return string Localized folder name in UTF-8 encoding | [
"Try",
"to",
"localize",
"the",
"given",
"IMAP",
"folder",
"name",
".",
"UTF",
"-",
"7",
"decode",
"it",
"in",
"case",
"no",
"localized",
"text",
"was",
"found"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L1701-L1738 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.localize_folderpath | public function localize_folderpath($path)
{
$protect_folders = $this->config->get('protect_default_folders');
$delimiter = $this->storage->get_hierarchy_delimiter();
$path = explode($delimiter, $path);
$result = array();
foreach ($path as $idx => $dir) {
$directory = implode($delimiter, array_slice($path, 0, $idx+1));
if ($protect_folders && $this->storage->is_special_folder($directory)) {
unset($result);
$result[] = $this->localize_foldername($directory);
}
else {
$result[] = rcube_charset::convert($dir, 'UTF7-IMAP');
}
}
return implode($delimiter, $result);
} | php | public function localize_folderpath($path)
{
$protect_folders = $this->config->get('protect_default_folders');
$delimiter = $this->storage->get_hierarchy_delimiter();
$path = explode($delimiter, $path);
$result = array();
foreach ($path as $idx => $dir) {
$directory = implode($delimiter, array_slice($path, 0, $idx+1));
if ($protect_folders && $this->storage->is_special_folder($directory)) {
unset($result);
$result[] = $this->localize_foldername($directory);
}
else {
$result[] = rcube_charset::convert($dir, 'UTF7-IMAP');
}
}
return implode($delimiter, $result);
} | [
"public",
"function",
"localize_folderpath",
"(",
"$",
"path",
")",
"{",
"$",
"protect_folders",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'protect_default_folders'",
")",
";",
"$",
"delimiter",
"=",
"$",
"this",
"->",
"storage",
"->",
"get_hierarchy_delimiter",
"(",
")",
";",
"$",
"path",
"=",
"explode",
"(",
"$",
"delimiter",
",",
"$",
"path",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"path",
"as",
"$",
"idx",
"=>",
"$",
"dir",
")",
"{",
"$",
"directory",
"=",
"implode",
"(",
"$",
"delimiter",
",",
"array_slice",
"(",
"$",
"path",
",",
"0",
",",
"$",
"idx",
"+",
"1",
")",
")",
";",
"if",
"(",
"$",
"protect_folders",
"&&",
"$",
"this",
"->",
"storage",
"->",
"is_special_folder",
"(",
"$",
"directory",
")",
")",
"{",
"unset",
"(",
"$",
"result",
")",
";",
"$",
"result",
"[",
"]",
"=",
"$",
"this",
"->",
"localize_foldername",
"(",
"$",
"directory",
")",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"]",
"=",
"rcube_charset",
"::",
"convert",
"(",
"$",
"dir",
",",
"'UTF7-IMAP'",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"$",
"delimiter",
",",
"$",
"result",
")",
";",
"}"
]
| Localize folder path | [
"Localize",
"folder",
"path"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L1743-L1762 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.quota_display | public static function quota_display($attrib)
{
$rcmail = rcmail::get_instance();
if (!$attrib['id']) {
$attrib['id'] = 'rcmquotadisplay';
}
$_SESSION['quota_display'] = !empty($attrib['display']) ? $attrib['display'] : 'text';
$rcmail->output->add_gui_object('quotadisplay', $attrib['id']);
$quota = $rcmail->quota_content($attrib);
$rcmail->output->add_script('rcmail.set_quota('.rcube_output::json_serialize($quota).');', 'docready');
return html::span($attrib, ' ');
} | php | public static function quota_display($attrib)
{
$rcmail = rcmail::get_instance();
if (!$attrib['id']) {
$attrib['id'] = 'rcmquotadisplay';
}
$_SESSION['quota_display'] = !empty($attrib['display']) ? $attrib['display'] : 'text';
$rcmail->output->add_gui_object('quotadisplay', $attrib['id']);
$quota = $rcmail->quota_content($attrib);
$rcmail->output->add_script('rcmail.set_quota('.rcube_output::json_serialize($quota).');', 'docready');
return html::span($attrib, ' ');
} | [
"public",
"static",
"function",
"quota_display",
"(",
"$",
"attrib",
")",
"{",
"$",
"rcmail",
"=",
"rcmail",
"::",
"get_instance",
"(",
")",
";",
"if",
"(",
"!",
"$",
"attrib",
"[",
"'id'",
"]",
")",
"{",
"$",
"attrib",
"[",
"'id'",
"]",
"=",
"'rcmquotadisplay'",
";",
"}",
"$",
"_SESSION",
"[",
"'quota_display'",
"]",
"=",
"!",
"empty",
"(",
"$",
"attrib",
"[",
"'display'",
"]",
")",
"?",
"$",
"attrib",
"[",
"'display'",
"]",
":",
"'text'",
";",
"$",
"rcmail",
"->",
"output",
"->",
"add_gui_object",
"(",
"'quotadisplay'",
",",
"$",
"attrib",
"[",
"'id'",
"]",
")",
";",
"$",
"quota",
"=",
"$",
"rcmail",
"->",
"quota_content",
"(",
"$",
"attrib",
")",
";",
"$",
"rcmail",
"->",
"output",
"->",
"add_script",
"(",
"'rcmail.set_quota('",
".",
"rcube_output",
"::",
"json_serialize",
"(",
"$",
"quota",
")",
".",
"');'",
",",
"'docready'",
")",
";",
"return",
"html",
"::",
"span",
"(",
"$",
"attrib",
",",
"' '",
")",
";",
"}"
]
| Return HTML for quota indicator object
@param array $attrib Named parameters
@return string HTML code for the quota indicator object | [
"Return",
"HTML",
"for",
"quota",
"indicator",
"object"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L1771-L1788 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.html_editor | public function html_editor($mode = '')
{
$spellcheck = intval($this->config->get('enable_spellcheck'));
$spelldict = intval($this->config->get('spellcheck_dictionary'));
$disabled_plugins = array();
$disabled_buttons = array();
$extra_plugins = array();
$extra_buttons = array();
if (!$spellcheck) {
$disabled_plugins[] = 'spellchecker';
}
$hook = $this->plugins->exec_hook('html_editor', array(
'mode' => $mode,
'disabled_plugins' => $disabled_plugins,
'disabled_buttons' => $disabled_buttons,
'extra_plugins' => $extra_plugins,
'extra_buttons' => $extra_buttons,
));
if ($hook['abort']) {
return;
}
$lang_codes = array($_SESSION['language']);
$assets_dir = $this->config->get('assets_dir') ?: INSTALL_PATH;
if ($pos = strpos($_SESSION['language'], '_')) {
$lang_codes[] = substr($_SESSION['language'], 0, $pos);
}
foreach ($lang_codes as $code) {
if (file_exists("$assets_dir/program/js/tinymce/langs/$code.js")) {
$lang = $code;
break;
}
}
if (empty($lang)) {
$lang = 'en';
}
$config = array(
'mode' => $mode,
'lang' => $lang,
'skin_path' => $this->output->get_skin_path(),
'spellcheck' => $spellcheck, // deprecated
'spelldict' => $spelldict,
'disabled_plugins' => $hook['disabled_plugins'],
'disabled_buttons' => $hook['disabled_buttons'],
'extra_plugins' => $hook['extra_plugins'],
'extra_buttons' => $hook['extra_buttons'],
);
$this->output->add_label('selectimage', 'addimage', 'selectmedia', 'addmedia');
$this->output->set_env('editor_config', $config);
$this->output->include_css('program/resources/tinymce/browser.css');
$this->output->include_script('tinymce/tinymce.min.js');
$this->output->include_script('editor.js');
} | php | public function html_editor($mode = '')
{
$spellcheck = intval($this->config->get('enable_spellcheck'));
$spelldict = intval($this->config->get('spellcheck_dictionary'));
$disabled_plugins = array();
$disabled_buttons = array();
$extra_plugins = array();
$extra_buttons = array();
if (!$spellcheck) {
$disabled_plugins[] = 'spellchecker';
}
$hook = $this->plugins->exec_hook('html_editor', array(
'mode' => $mode,
'disabled_plugins' => $disabled_plugins,
'disabled_buttons' => $disabled_buttons,
'extra_plugins' => $extra_plugins,
'extra_buttons' => $extra_buttons,
));
if ($hook['abort']) {
return;
}
$lang_codes = array($_SESSION['language']);
$assets_dir = $this->config->get('assets_dir') ?: INSTALL_PATH;
if ($pos = strpos($_SESSION['language'], '_')) {
$lang_codes[] = substr($_SESSION['language'], 0, $pos);
}
foreach ($lang_codes as $code) {
if (file_exists("$assets_dir/program/js/tinymce/langs/$code.js")) {
$lang = $code;
break;
}
}
if (empty($lang)) {
$lang = 'en';
}
$config = array(
'mode' => $mode,
'lang' => $lang,
'skin_path' => $this->output->get_skin_path(),
'spellcheck' => $spellcheck, // deprecated
'spelldict' => $spelldict,
'disabled_plugins' => $hook['disabled_plugins'],
'disabled_buttons' => $hook['disabled_buttons'],
'extra_plugins' => $hook['extra_plugins'],
'extra_buttons' => $hook['extra_buttons'],
);
$this->output->add_label('selectimage', 'addimage', 'selectmedia', 'addmedia');
$this->output->set_env('editor_config', $config);
$this->output->include_css('program/resources/tinymce/browser.css');
$this->output->include_script('tinymce/tinymce.min.js');
$this->output->include_script('editor.js');
} | [
"public",
"function",
"html_editor",
"(",
"$",
"mode",
"=",
"''",
")",
"{",
"$",
"spellcheck",
"=",
"intval",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'enable_spellcheck'",
")",
")",
";",
"$",
"spelldict",
"=",
"intval",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'spellcheck_dictionary'",
")",
")",
";",
"$",
"disabled_plugins",
"=",
"array",
"(",
")",
";",
"$",
"disabled_buttons",
"=",
"array",
"(",
")",
";",
"$",
"extra_plugins",
"=",
"array",
"(",
")",
";",
"$",
"extra_buttons",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"spellcheck",
")",
"{",
"$",
"disabled_plugins",
"[",
"]",
"=",
"'spellchecker'",
";",
"}",
"$",
"hook",
"=",
"$",
"this",
"->",
"plugins",
"->",
"exec_hook",
"(",
"'html_editor'",
",",
"array",
"(",
"'mode'",
"=>",
"$",
"mode",
",",
"'disabled_plugins'",
"=>",
"$",
"disabled_plugins",
",",
"'disabled_buttons'",
"=>",
"$",
"disabled_buttons",
",",
"'extra_plugins'",
"=>",
"$",
"extra_plugins",
",",
"'extra_buttons'",
"=>",
"$",
"extra_buttons",
",",
")",
")",
";",
"if",
"(",
"$",
"hook",
"[",
"'abort'",
"]",
")",
"{",
"return",
";",
"}",
"$",
"lang_codes",
"=",
"array",
"(",
"$",
"_SESSION",
"[",
"'language'",
"]",
")",
";",
"$",
"assets_dir",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'assets_dir'",
")",
"?",
":",
"INSTALL_PATH",
";",
"if",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"_SESSION",
"[",
"'language'",
"]",
",",
"'_'",
")",
")",
"{",
"$",
"lang_codes",
"[",
"]",
"=",
"substr",
"(",
"$",
"_SESSION",
"[",
"'language'",
"]",
",",
"0",
",",
"$",
"pos",
")",
";",
"}",
"foreach",
"(",
"$",
"lang_codes",
"as",
"$",
"code",
")",
"{",
"if",
"(",
"file_exists",
"(",
"\"$assets_dir/program/js/tinymce/langs/$code.js\"",
")",
")",
"{",
"$",
"lang",
"=",
"$",
"code",
";",
"break",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"lang",
")",
")",
"{",
"$",
"lang",
"=",
"'en'",
";",
"}",
"$",
"config",
"=",
"array",
"(",
"'mode'",
"=>",
"$",
"mode",
",",
"'lang'",
"=>",
"$",
"lang",
",",
"'skin_path'",
"=>",
"$",
"this",
"->",
"output",
"->",
"get_skin_path",
"(",
")",
",",
"'spellcheck'",
"=>",
"$",
"spellcheck",
",",
"// deprecated",
"'spelldict'",
"=>",
"$",
"spelldict",
",",
"'disabled_plugins'",
"=>",
"$",
"hook",
"[",
"'disabled_plugins'",
"]",
",",
"'disabled_buttons'",
"=>",
"$",
"hook",
"[",
"'disabled_buttons'",
"]",
",",
"'extra_plugins'",
"=>",
"$",
"hook",
"[",
"'extra_plugins'",
"]",
",",
"'extra_buttons'",
"=>",
"$",
"hook",
"[",
"'extra_buttons'",
"]",
",",
")",
";",
"$",
"this",
"->",
"output",
"->",
"add_label",
"(",
"'selectimage'",
",",
"'addimage'",
",",
"'selectmedia'",
",",
"'addmedia'",
")",
";",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'editor_config'",
",",
"$",
"config",
")",
";",
"$",
"this",
"->",
"output",
"->",
"include_css",
"(",
"'program/resources/tinymce/browser.css'",
")",
";",
"$",
"this",
"->",
"output",
"->",
"include_script",
"(",
"'tinymce/tinymce.min.js'",
")",
";",
"$",
"this",
"->",
"output",
"->",
"include_script",
"(",
"'editor.js'",
")",
";",
"}"
]
| Output HTML editor scripts
@param string $mode Editor mode | [
"Output",
"HTML",
"editor",
"scripts"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L1941-L2001 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.upload_progress | public function upload_progress()
{
$params = array(
'action' => $this->action,
'name' => rcube_utils::get_input_value('_progress', rcube_utils::INPUT_GET),
);
if (function_exists('uploadprogress_get_info')) {
$status = uploadprogress_get_info($params['name']);
if (!empty($status)) {
$params['current'] = $status['bytes_uploaded'];
$params['total'] = $status['bytes_total'];
}
}
if (!isset($status) && filter_var(ini_get('apc.rfc1867'), FILTER_VALIDATE_BOOLEAN)
&& ini_get('apc.rfc1867_name')
) {
$prefix = ini_get('apc.rfc1867_prefix');
$status = apc_fetch($prefix . $params['name']);
if (!empty($status)) {
$params['current'] = $status['current'];
$params['total'] = $status['total'];
}
}
if (!isset($status) && filter_var(ini_get('session.upload_progress.enabled'), FILTER_VALIDATE_BOOLEAN)
&& ini_get('session.upload_progress.name')
) {
$key = ini_get('session.upload_progress.prefix') . $params['name'];
$params['total'] = $_SESSION[$key]['content_length'];
$params['current'] = $_SESSION[$key]['bytes_processed'];
}
if (!empty($params['total'])) {
$total = $this->show_bytes($params['total'], $unit);
switch ($unit) {
case 'GB':
$gb = $params['current']/1073741824;
$current = sprintf($gb >= 10 ? "%d" : "%.1f", $gb);
break;
case 'MB':
$mb = $params['current']/1048576;
$current = sprintf($mb >= 10 ? "%d" : "%.1f", $mb);
break;
case 'KB':
$current = round($params['current']/1024);
break;
case 'B':
default:
$current = $params['current'];
break;
}
$params['percent'] = round($params['current']/$params['total']*100);
$params['text'] = $this->gettext(array(
'name' => 'uploadprogress',
'vars' => array(
'percent' => $params['percent'] . '%',
'current' => $current,
'total' => $total
)
));
}
$this->output->command('upload_progress_update', $params);
$this->output->send();
} | php | public function upload_progress()
{
$params = array(
'action' => $this->action,
'name' => rcube_utils::get_input_value('_progress', rcube_utils::INPUT_GET),
);
if (function_exists('uploadprogress_get_info')) {
$status = uploadprogress_get_info($params['name']);
if (!empty($status)) {
$params['current'] = $status['bytes_uploaded'];
$params['total'] = $status['bytes_total'];
}
}
if (!isset($status) && filter_var(ini_get('apc.rfc1867'), FILTER_VALIDATE_BOOLEAN)
&& ini_get('apc.rfc1867_name')
) {
$prefix = ini_get('apc.rfc1867_prefix');
$status = apc_fetch($prefix . $params['name']);
if (!empty($status)) {
$params['current'] = $status['current'];
$params['total'] = $status['total'];
}
}
if (!isset($status) && filter_var(ini_get('session.upload_progress.enabled'), FILTER_VALIDATE_BOOLEAN)
&& ini_get('session.upload_progress.name')
) {
$key = ini_get('session.upload_progress.prefix') . $params['name'];
$params['total'] = $_SESSION[$key]['content_length'];
$params['current'] = $_SESSION[$key]['bytes_processed'];
}
if (!empty($params['total'])) {
$total = $this->show_bytes($params['total'], $unit);
switch ($unit) {
case 'GB':
$gb = $params['current']/1073741824;
$current = sprintf($gb >= 10 ? "%d" : "%.1f", $gb);
break;
case 'MB':
$mb = $params['current']/1048576;
$current = sprintf($mb >= 10 ? "%d" : "%.1f", $mb);
break;
case 'KB':
$current = round($params['current']/1024);
break;
case 'B':
default:
$current = $params['current'];
break;
}
$params['percent'] = round($params['current']/$params['total']*100);
$params['text'] = $this->gettext(array(
'name' => 'uploadprogress',
'vars' => array(
'percent' => $params['percent'] . '%',
'current' => $current,
'total' => $total
)
));
}
$this->output->command('upload_progress_update', $params);
$this->output->send();
} | [
"public",
"function",
"upload_progress",
"(",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"action",
",",
"'name'",
"=>",
"rcube_utils",
"::",
"get_input_value",
"(",
"'_progress'",
",",
"rcube_utils",
"::",
"INPUT_GET",
")",
",",
")",
";",
"if",
"(",
"function_exists",
"(",
"'uploadprogress_get_info'",
")",
")",
"{",
"$",
"status",
"=",
"uploadprogress_get_info",
"(",
"$",
"params",
"[",
"'name'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"status",
")",
")",
"{",
"$",
"params",
"[",
"'current'",
"]",
"=",
"$",
"status",
"[",
"'bytes_uploaded'",
"]",
";",
"$",
"params",
"[",
"'total'",
"]",
"=",
"$",
"status",
"[",
"'bytes_total'",
"]",
";",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"status",
")",
"&&",
"filter_var",
"(",
"ini_get",
"(",
"'apc.rfc1867'",
")",
",",
"FILTER_VALIDATE_BOOLEAN",
")",
"&&",
"ini_get",
"(",
"'apc.rfc1867_name'",
")",
")",
"{",
"$",
"prefix",
"=",
"ini_get",
"(",
"'apc.rfc1867_prefix'",
")",
";",
"$",
"status",
"=",
"apc_fetch",
"(",
"$",
"prefix",
".",
"$",
"params",
"[",
"'name'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"status",
")",
")",
"{",
"$",
"params",
"[",
"'current'",
"]",
"=",
"$",
"status",
"[",
"'current'",
"]",
";",
"$",
"params",
"[",
"'total'",
"]",
"=",
"$",
"status",
"[",
"'total'",
"]",
";",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"status",
")",
"&&",
"filter_var",
"(",
"ini_get",
"(",
"'session.upload_progress.enabled'",
")",
",",
"FILTER_VALIDATE_BOOLEAN",
")",
"&&",
"ini_get",
"(",
"'session.upload_progress.name'",
")",
")",
"{",
"$",
"key",
"=",
"ini_get",
"(",
"'session.upload_progress.prefix'",
")",
".",
"$",
"params",
"[",
"'name'",
"]",
";",
"$",
"params",
"[",
"'total'",
"]",
"=",
"$",
"_SESSION",
"[",
"$",
"key",
"]",
"[",
"'content_length'",
"]",
";",
"$",
"params",
"[",
"'current'",
"]",
"=",
"$",
"_SESSION",
"[",
"$",
"key",
"]",
"[",
"'bytes_processed'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"params",
"[",
"'total'",
"]",
")",
")",
"{",
"$",
"total",
"=",
"$",
"this",
"->",
"show_bytes",
"(",
"$",
"params",
"[",
"'total'",
"]",
",",
"$",
"unit",
")",
";",
"switch",
"(",
"$",
"unit",
")",
"{",
"case",
"'GB'",
":",
"$",
"gb",
"=",
"$",
"params",
"[",
"'current'",
"]",
"/",
"1073741824",
";",
"$",
"current",
"=",
"sprintf",
"(",
"$",
"gb",
">=",
"10",
"?",
"\"%d\"",
":",
"\"%.1f\"",
",",
"$",
"gb",
")",
";",
"break",
";",
"case",
"'MB'",
":",
"$",
"mb",
"=",
"$",
"params",
"[",
"'current'",
"]",
"/",
"1048576",
";",
"$",
"current",
"=",
"sprintf",
"(",
"$",
"mb",
">=",
"10",
"?",
"\"%d\"",
":",
"\"%.1f\"",
",",
"$",
"mb",
")",
";",
"break",
";",
"case",
"'KB'",
":",
"$",
"current",
"=",
"round",
"(",
"$",
"params",
"[",
"'current'",
"]",
"/",
"1024",
")",
";",
"break",
";",
"case",
"'B'",
":",
"default",
":",
"$",
"current",
"=",
"$",
"params",
"[",
"'current'",
"]",
";",
"break",
";",
"}",
"$",
"params",
"[",
"'percent'",
"]",
"=",
"round",
"(",
"$",
"params",
"[",
"'current'",
"]",
"/",
"$",
"params",
"[",
"'total'",
"]",
"*",
"100",
")",
";",
"$",
"params",
"[",
"'text'",
"]",
"=",
"$",
"this",
"->",
"gettext",
"(",
"array",
"(",
"'name'",
"=>",
"'uploadprogress'",
",",
"'vars'",
"=>",
"array",
"(",
"'percent'",
"=>",
"$",
"params",
"[",
"'percent'",
"]",
".",
"'%'",
",",
"'current'",
"=>",
"$",
"current",
",",
"'total'",
"=>",
"$",
"total",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"output",
"->",
"command",
"(",
"'upload_progress_update'",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"output",
"->",
"send",
"(",
")",
";",
"}"
]
| File upload progress handler. | [
"File",
"upload",
"progress",
"handler",
"."
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L2006-L2076 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.upload_init | public function upload_init($max_size = null)
{
// Enable upload progress bar
if ($seconds = $this->config->get('upload_progress')) {
if (function_exists('uploadprogress_get_info')) {
$field_name = 'UPLOAD_IDENTIFIER';
}
if (!$field_name && filter_var(ini_get('apc.rfc1867'), FILTER_VALIDATE_BOOLEAN)) {
$field_name = ini_get('apc.rfc1867_name');
}
if (!$field_name && filter_var(ini_get('session.upload_progress.enabled'), FILTER_VALIDATE_BOOLEAN)) {
$field_name = ini_get('session.upload_progress.name');
}
if ($field_name) {
$this->output->set_env('upload_progress_name', $field_name);
$this->output->set_env('upload_progress_time', (int) $seconds);
}
}
// find max filesize value
$max_filesize = rcube_utils::max_upload_size();
if ($max_size && $max_size < $max_filesize) {
$max_filesize = $max_size;
}
$max_filesize_txt = $this->show_bytes($max_filesize);
$this->output->set_env('max_filesize', $max_filesize);
$this->output->set_env('filesizeerror', $this->gettext(array(
'name' => 'filesizeerror', 'vars' => array('size' => $max_filesize_txt))));
if ($max_filecount = ini_get('max_file_uploads')) {
$this->output->set_env('max_filecount', $max_filecount);
$this->output->set_env('filecounterror', $this->gettext(array(
'name' => 'filecounterror', 'vars' => array('count' => $max_filecount))));
}
return $max_filesize_txt;
} | php | public function upload_init($max_size = null)
{
// Enable upload progress bar
if ($seconds = $this->config->get('upload_progress')) {
if (function_exists('uploadprogress_get_info')) {
$field_name = 'UPLOAD_IDENTIFIER';
}
if (!$field_name && filter_var(ini_get('apc.rfc1867'), FILTER_VALIDATE_BOOLEAN)) {
$field_name = ini_get('apc.rfc1867_name');
}
if (!$field_name && filter_var(ini_get('session.upload_progress.enabled'), FILTER_VALIDATE_BOOLEAN)) {
$field_name = ini_get('session.upload_progress.name');
}
if ($field_name) {
$this->output->set_env('upload_progress_name', $field_name);
$this->output->set_env('upload_progress_time', (int) $seconds);
}
}
// find max filesize value
$max_filesize = rcube_utils::max_upload_size();
if ($max_size && $max_size < $max_filesize) {
$max_filesize = $max_size;
}
$max_filesize_txt = $this->show_bytes($max_filesize);
$this->output->set_env('max_filesize', $max_filesize);
$this->output->set_env('filesizeerror', $this->gettext(array(
'name' => 'filesizeerror', 'vars' => array('size' => $max_filesize_txt))));
if ($max_filecount = ini_get('max_file_uploads')) {
$this->output->set_env('max_filecount', $max_filecount);
$this->output->set_env('filecounterror', $this->gettext(array(
'name' => 'filecounterror', 'vars' => array('count' => $max_filecount))));
}
return $max_filesize_txt;
} | [
"public",
"function",
"upload_init",
"(",
"$",
"max_size",
"=",
"null",
")",
"{",
"// Enable upload progress bar",
"if",
"(",
"$",
"seconds",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'upload_progress'",
")",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'uploadprogress_get_info'",
")",
")",
"{",
"$",
"field_name",
"=",
"'UPLOAD_IDENTIFIER'",
";",
"}",
"if",
"(",
"!",
"$",
"field_name",
"&&",
"filter_var",
"(",
"ini_get",
"(",
"'apc.rfc1867'",
")",
",",
"FILTER_VALIDATE_BOOLEAN",
")",
")",
"{",
"$",
"field_name",
"=",
"ini_get",
"(",
"'apc.rfc1867_name'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"field_name",
"&&",
"filter_var",
"(",
"ini_get",
"(",
"'session.upload_progress.enabled'",
")",
",",
"FILTER_VALIDATE_BOOLEAN",
")",
")",
"{",
"$",
"field_name",
"=",
"ini_get",
"(",
"'session.upload_progress.name'",
")",
";",
"}",
"if",
"(",
"$",
"field_name",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'upload_progress_name'",
",",
"$",
"field_name",
")",
";",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'upload_progress_time'",
",",
"(",
"int",
")",
"$",
"seconds",
")",
";",
"}",
"}",
"// find max filesize value",
"$",
"max_filesize",
"=",
"rcube_utils",
"::",
"max_upload_size",
"(",
")",
";",
"if",
"(",
"$",
"max_size",
"&&",
"$",
"max_size",
"<",
"$",
"max_filesize",
")",
"{",
"$",
"max_filesize",
"=",
"$",
"max_size",
";",
"}",
"$",
"max_filesize_txt",
"=",
"$",
"this",
"->",
"show_bytes",
"(",
"$",
"max_filesize",
")",
";",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'max_filesize'",
",",
"$",
"max_filesize",
")",
";",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'filesizeerror'",
",",
"$",
"this",
"->",
"gettext",
"(",
"array",
"(",
"'name'",
"=>",
"'filesizeerror'",
",",
"'vars'",
"=>",
"array",
"(",
"'size'",
"=>",
"$",
"max_filesize_txt",
")",
")",
")",
")",
";",
"if",
"(",
"$",
"max_filecount",
"=",
"ini_get",
"(",
"'max_file_uploads'",
")",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'max_filecount'",
",",
"$",
"max_filecount",
")",
";",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'filecounterror'",
",",
"$",
"this",
"->",
"gettext",
"(",
"array",
"(",
"'name'",
"=>",
"'filecounterror'",
",",
"'vars'",
"=>",
"array",
"(",
"'count'",
"=>",
"$",
"max_filecount",
")",
")",
")",
")",
";",
"}",
"return",
"$",
"max_filesize_txt",
";",
"}"
]
| Initializes file uploading interface.
@param int $max_size Optional maximum file size in bytes
@return string Human-readable file size limit | [
"Initializes",
"file",
"uploading",
"interface",
"."
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L2085-L2123 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.upload_form | public function upload_form($attrib, $name, $action, $input_attr = array())
{
// Get filesize, enable upload progress bar
$max_filesize = $this->upload_init();
$hint = html::div('hint', $this->gettext(array('name' => 'maxuploadsize', 'vars' => array('size' => $max_filesize))));
if ($attrib['mode'] == 'hint') {
return $hint;
}
// set defaults
$attrib += array('id' => 'rcmUploadbox', 'buttons' => 'yes');
$event = rcmail_output::JS_OBJECT_NAME . ".command('$action', this.form)";
$form_id = $attrib['id'] . 'Frm';
// Default attributes of file input and form
$input_attr += array(
'id' => $attrib['id'] . 'Input',
'type' => 'file',
'name' => '_attachments[]',
);
$form_attr = array(
'id' => $form_id,
'name' => $name,
'method' => 'post',
'enctype' => 'multipart/form-data'
);
if ($attrib['mode'] == 'smart') {
unset($attrib['buttons']);
$form_attr['class'] = 'smart-upload';
$input_attr = array_merge($input_attr, array(
// #5854: Chrome does not execute onchange when selecting the same file.
// To fix this we reset the input using null value.
'onchange' => "$event; this.value=null",
'class' => 'smart-upload',
'tabindex' => '-1',
));
}
$input = new html_inputfield($input_attr);
$content = $attrib['prefix'] . $input->show();
if ($attrib['mode'] != 'smart') {
$content = html::div(null, $content);
$content .= $hint;
}
if (rcube_utils::get_boolean($attrib['buttons'])) {
$button = new html_inputfield(array('type' => 'button'));
$content .= html::div('buttons',
$button->show($this->gettext('close'), array('class' => 'button', 'onclick' => "$('#{$attrib['id']}').hide()")) . ' ' .
$button->show($this->gettext('upload'), array('class' => 'button mainaction', 'onclick' => $event))
);
}
$this->output->add_gui_object($name, $form_id);
return html::div($attrib, $this->output->form_tag($form_attr, $content));
} | php | public function upload_form($attrib, $name, $action, $input_attr = array())
{
// Get filesize, enable upload progress bar
$max_filesize = $this->upload_init();
$hint = html::div('hint', $this->gettext(array('name' => 'maxuploadsize', 'vars' => array('size' => $max_filesize))));
if ($attrib['mode'] == 'hint') {
return $hint;
}
// set defaults
$attrib += array('id' => 'rcmUploadbox', 'buttons' => 'yes');
$event = rcmail_output::JS_OBJECT_NAME . ".command('$action', this.form)";
$form_id = $attrib['id'] . 'Frm';
// Default attributes of file input and form
$input_attr += array(
'id' => $attrib['id'] . 'Input',
'type' => 'file',
'name' => '_attachments[]',
);
$form_attr = array(
'id' => $form_id,
'name' => $name,
'method' => 'post',
'enctype' => 'multipart/form-data'
);
if ($attrib['mode'] == 'smart') {
unset($attrib['buttons']);
$form_attr['class'] = 'smart-upload';
$input_attr = array_merge($input_attr, array(
// #5854: Chrome does not execute onchange when selecting the same file.
// To fix this we reset the input using null value.
'onchange' => "$event; this.value=null",
'class' => 'smart-upload',
'tabindex' => '-1',
));
}
$input = new html_inputfield($input_attr);
$content = $attrib['prefix'] . $input->show();
if ($attrib['mode'] != 'smart') {
$content = html::div(null, $content);
$content .= $hint;
}
if (rcube_utils::get_boolean($attrib['buttons'])) {
$button = new html_inputfield(array('type' => 'button'));
$content .= html::div('buttons',
$button->show($this->gettext('close'), array('class' => 'button', 'onclick' => "$('#{$attrib['id']}').hide()")) . ' ' .
$button->show($this->gettext('upload'), array('class' => 'button mainaction', 'onclick' => $event))
);
}
$this->output->add_gui_object($name, $form_id);
return html::div($attrib, $this->output->form_tag($form_attr, $content));
} | [
"public",
"function",
"upload_form",
"(",
"$",
"attrib",
",",
"$",
"name",
",",
"$",
"action",
",",
"$",
"input_attr",
"=",
"array",
"(",
")",
")",
"{",
"// Get filesize, enable upload progress bar",
"$",
"max_filesize",
"=",
"$",
"this",
"->",
"upload_init",
"(",
")",
";",
"$",
"hint",
"=",
"html",
"::",
"div",
"(",
"'hint'",
",",
"$",
"this",
"->",
"gettext",
"(",
"array",
"(",
"'name'",
"=>",
"'maxuploadsize'",
",",
"'vars'",
"=>",
"array",
"(",
"'size'",
"=>",
"$",
"max_filesize",
")",
")",
")",
")",
";",
"if",
"(",
"$",
"attrib",
"[",
"'mode'",
"]",
"==",
"'hint'",
")",
"{",
"return",
"$",
"hint",
";",
"}",
"// set defaults",
"$",
"attrib",
"+=",
"array",
"(",
"'id'",
"=>",
"'rcmUploadbox'",
",",
"'buttons'",
"=>",
"'yes'",
")",
";",
"$",
"event",
"=",
"rcmail_output",
"::",
"JS_OBJECT_NAME",
".",
"\".command('$action', this.form)\"",
";",
"$",
"form_id",
"=",
"$",
"attrib",
"[",
"'id'",
"]",
".",
"'Frm'",
";",
"// Default attributes of file input and form",
"$",
"input_attr",
"+=",
"array",
"(",
"'id'",
"=>",
"$",
"attrib",
"[",
"'id'",
"]",
".",
"'Input'",
",",
"'type'",
"=>",
"'file'",
",",
"'name'",
"=>",
"'_attachments[]'",
",",
")",
";",
"$",
"form_attr",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"form_id",
",",
"'name'",
"=>",
"$",
"name",
",",
"'method'",
"=>",
"'post'",
",",
"'enctype'",
"=>",
"'multipart/form-data'",
")",
";",
"if",
"(",
"$",
"attrib",
"[",
"'mode'",
"]",
"==",
"'smart'",
")",
"{",
"unset",
"(",
"$",
"attrib",
"[",
"'buttons'",
"]",
")",
";",
"$",
"form_attr",
"[",
"'class'",
"]",
"=",
"'smart-upload'",
";",
"$",
"input_attr",
"=",
"array_merge",
"(",
"$",
"input_attr",
",",
"array",
"(",
"// #5854: Chrome does not execute onchange when selecting the same file.",
"// To fix this we reset the input using null value.",
"'onchange'",
"=>",
"\"$event; this.value=null\"",
",",
"'class'",
"=>",
"'smart-upload'",
",",
"'tabindex'",
"=>",
"'-1'",
",",
")",
")",
";",
"}",
"$",
"input",
"=",
"new",
"html_inputfield",
"(",
"$",
"input_attr",
")",
";",
"$",
"content",
"=",
"$",
"attrib",
"[",
"'prefix'",
"]",
".",
"$",
"input",
"->",
"show",
"(",
")",
";",
"if",
"(",
"$",
"attrib",
"[",
"'mode'",
"]",
"!=",
"'smart'",
")",
"{",
"$",
"content",
"=",
"html",
"::",
"div",
"(",
"null",
",",
"$",
"content",
")",
";",
"$",
"content",
".=",
"$",
"hint",
";",
"}",
"if",
"(",
"rcube_utils",
"::",
"get_boolean",
"(",
"$",
"attrib",
"[",
"'buttons'",
"]",
")",
")",
"{",
"$",
"button",
"=",
"new",
"html_inputfield",
"(",
"array",
"(",
"'type'",
"=>",
"'button'",
")",
")",
";",
"$",
"content",
".=",
"html",
"::",
"div",
"(",
"'buttons'",
",",
"$",
"button",
"->",
"show",
"(",
"$",
"this",
"->",
"gettext",
"(",
"'close'",
")",
",",
"array",
"(",
"'class'",
"=>",
"'button'",
",",
"'onclick'",
"=>",
"\"$('#{$attrib['id']}').hide()\"",
")",
")",
".",
"' '",
".",
"$",
"button",
"->",
"show",
"(",
"$",
"this",
"->",
"gettext",
"(",
"'upload'",
")",
",",
"array",
"(",
"'class'",
"=>",
"'button mainaction'",
",",
"'onclick'",
"=>",
"$",
"event",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"output",
"->",
"add_gui_object",
"(",
"$",
"name",
",",
"$",
"form_id",
")",
";",
"return",
"html",
"::",
"div",
"(",
"$",
"attrib",
",",
"$",
"this",
"->",
"output",
"->",
"form_tag",
"(",
"$",
"form_attr",
",",
"$",
"content",
")",
")",
";",
"}"
]
| Upload form object
@param array $attrib Object attributes
@param string $name Form object name
@param string $action Form action name
@param array $input_attr File input attributes
@return string HTML output | [
"Upload",
"form",
"object"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L2135-L2197 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.display_uploaded_file | public function display_uploaded_file($file)
{
if (empty($file)) {
return;
}
$file = $this->plugins->exec_hook('attachment_display', $file);
if ($file['status']) {
if (empty($file['size'])) {
$file['size'] = $file['data'] ? strlen($file['data']) : @filesize($file['path']);
}
// generate image thumbnail for file browser in HTML editor
if (!empty($_GET['_thumbnail'])) {
$temp_dir = $this->config->get('temp_dir');
$thumbnail_size = 80;
$mimetype = $file['mimetype'];
$file_ident = $file['id'] . ':' . $file['mimetype'] . ':' . $file['size'];
$cache_basename = $temp_dir . '/' . md5($file_ident . ':' . $this->user->ID . ':' . $thumbnail_size);
$cache_file = $cache_basename . '.thumb';
// render thumbnail image if not done yet
if (!is_file($cache_file)) {
if (!$file['path']) {
$orig_name = $filename = $cache_basename . '.tmp';
file_put_contents($orig_name, $file['data']);
}
else {
$filename = $file['path'];
}
$image = new rcube_image($filename);
if ($imgtype = $image->resize($thumbnail_size, $cache_file, true)) {
$mimetype = 'image/' . $imgtype;
if ($orig_name) {
unlink($orig_name);
}
}
}
if (is_file($cache_file)) {
// cache for 1h
$this->output->future_expire_header(3600);
header('Content-Type: ' . $mimetype);
header('Content-Length: ' . filesize($cache_file));
readfile($cache_file);
exit;
}
}
header('Content-Type: ' . $file['mimetype']);
header('Content-Length: ' . $file['size']);
if ($file['data']) {
echo $file['data'];
}
else if ($file['path']) {
readfile($file['path']);
}
}
} | php | public function display_uploaded_file($file)
{
if (empty($file)) {
return;
}
$file = $this->plugins->exec_hook('attachment_display', $file);
if ($file['status']) {
if (empty($file['size'])) {
$file['size'] = $file['data'] ? strlen($file['data']) : @filesize($file['path']);
}
// generate image thumbnail for file browser in HTML editor
if (!empty($_GET['_thumbnail'])) {
$temp_dir = $this->config->get('temp_dir');
$thumbnail_size = 80;
$mimetype = $file['mimetype'];
$file_ident = $file['id'] . ':' . $file['mimetype'] . ':' . $file['size'];
$cache_basename = $temp_dir . '/' . md5($file_ident . ':' . $this->user->ID . ':' . $thumbnail_size);
$cache_file = $cache_basename . '.thumb';
// render thumbnail image if not done yet
if (!is_file($cache_file)) {
if (!$file['path']) {
$orig_name = $filename = $cache_basename . '.tmp';
file_put_contents($orig_name, $file['data']);
}
else {
$filename = $file['path'];
}
$image = new rcube_image($filename);
if ($imgtype = $image->resize($thumbnail_size, $cache_file, true)) {
$mimetype = 'image/' . $imgtype;
if ($orig_name) {
unlink($orig_name);
}
}
}
if (is_file($cache_file)) {
// cache for 1h
$this->output->future_expire_header(3600);
header('Content-Type: ' . $mimetype);
header('Content-Length: ' . filesize($cache_file));
readfile($cache_file);
exit;
}
}
header('Content-Type: ' . $file['mimetype']);
header('Content-Length: ' . $file['size']);
if ($file['data']) {
echo $file['data'];
}
else if ($file['path']) {
readfile($file['path']);
}
}
} | [
"public",
"function",
"display_uploaded_file",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"file",
")",
")",
"{",
"return",
";",
"}",
"$",
"file",
"=",
"$",
"this",
"->",
"plugins",
"->",
"exec_hook",
"(",
"'attachment_display'",
",",
"$",
"file",
")",
";",
"if",
"(",
"$",
"file",
"[",
"'status'",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"file",
"[",
"'size'",
"]",
")",
")",
"{",
"$",
"file",
"[",
"'size'",
"]",
"=",
"$",
"file",
"[",
"'data'",
"]",
"?",
"strlen",
"(",
"$",
"file",
"[",
"'data'",
"]",
")",
":",
"@",
"filesize",
"(",
"$",
"file",
"[",
"'path'",
"]",
")",
";",
"}",
"// generate image thumbnail for file browser in HTML editor",
"if",
"(",
"!",
"empty",
"(",
"$",
"_GET",
"[",
"'_thumbnail'",
"]",
")",
")",
"{",
"$",
"temp_dir",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'temp_dir'",
")",
";",
"$",
"thumbnail_size",
"=",
"80",
";",
"$",
"mimetype",
"=",
"$",
"file",
"[",
"'mimetype'",
"]",
";",
"$",
"file_ident",
"=",
"$",
"file",
"[",
"'id'",
"]",
".",
"':'",
".",
"$",
"file",
"[",
"'mimetype'",
"]",
".",
"':'",
".",
"$",
"file",
"[",
"'size'",
"]",
";",
"$",
"cache_basename",
"=",
"$",
"temp_dir",
".",
"'/'",
".",
"md5",
"(",
"$",
"file_ident",
".",
"':'",
".",
"$",
"this",
"->",
"user",
"->",
"ID",
".",
"':'",
".",
"$",
"thumbnail_size",
")",
";",
"$",
"cache_file",
"=",
"$",
"cache_basename",
".",
"'.thumb'",
";",
"// render thumbnail image if not done yet",
"if",
"(",
"!",
"is_file",
"(",
"$",
"cache_file",
")",
")",
"{",
"if",
"(",
"!",
"$",
"file",
"[",
"'path'",
"]",
")",
"{",
"$",
"orig_name",
"=",
"$",
"filename",
"=",
"$",
"cache_basename",
".",
"'.tmp'",
";",
"file_put_contents",
"(",
"$",
"orig_name",
",",
"$",
"file",
"[",
"'data'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"filename",
"=",
"$",
"file",
"[",
"'path'",
"]",
";",
"}",
"$",
"image",
"=",
"new",
"rcube_image",
"(",
"$",
"filename",
")",
";",
"if",
"(",
"$",
"imgtype",
"=",
"$",
"image",
"->",
"resize",
"(",
"$",
"thumbnail_size",
",",
"$",
"cache_file",
",",
"true",
")",
")",
"{",
"$",
"mimetype",
"=",
"'image/'",
".",
"$",
"imgtype",
";",
"if",
"(",
"$",
"orig_name",
")",
"{",
"unlink",
"(",
"$",
"orig_name",
")",
";",
"}",
"}",
"}",
"if",
"(",
"is_file",
"(",
"$",
"cache_file",
")",
")",
"{",
"// cache for 1h",
"$",
"this",
"->",
"output",
"->",
"future_expire_header",
"(",
"3600",
")",
";",
"header",
"(",
"'Content-Type: '",
".",
"$",
"mimetype",
")",
";",
"header",
"(",
"'Content-Length: '",
".",
"filesize",
"(",
"$",
"cache_file",
")",
")",
";",
"readfile",
"(",
"$",
"cache_file",
")",
";",
"exit",
";",
"}",
"}",
"header",
"(",
"'Content-Type: '",
".",
"$",
"file",
"[",
"'mimetype'",
"]",
")",
";",
"header",
"(",
"'Content-Length: '",
".",
"$",
"file",
"[",
"'size'",
"]",
")",
";",
"if",
"(",
"$",
"file",
"[",
"'data'",
"]",
")",
"{",
"echo",
"$",
"file",
"[",
"'data'",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"file",
"[",
"'path'",
"]",
")",
"{",
"readfile",
"(",
"$",
"file",
"[",
"'path'",
"]",
")",
";",
"}",
"}",
"}"
]
| Outputs uploaded file content (with image thumbnails support
@param array $file Upload file data | [
"Outputs",
"uploaded",
"file",
"content",
"(",
"with",
"image",
"thumbnails",
"support"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L2204-L2267 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.autocomplete_init | public function autocomplete_init()
{
static $init;
if ($init) {
return;
}
$init = 1;
if (($threads = (int)$this->config->get('autocomplete_threads')) > 0) {
$book_types = (array) $this->config->get('autocomplete_addressbooks', 'sql');
if (count($book_types) > 1) {
$this->output->set_env('autocomplete_threads', $threads);
$this->output->set_env('autocomplete_sources', $book_types);
}
}
$this->output->set_env('autocomplete_max', (int)$this->config->get('autocomplete_max', 15));
$this->output->set_env('autocomplete_min_length', $this->config->get('autocomplete_min_length'));
$this->output->add_label('autocompletechars', 'autocompletemore');
} | php | public function autocomplete_init()
{
static $init;
if ($init) {
return;
}
$init = 1;
if (($threads = (int)$this->config->get('autocomplete_threads')) > 0) {
$book_types = (array) $this->config->get('autocomplete_addressbooks', 'sql');
if (count($book_types) > 1) {
$this->output->set_env('autocomplete_threads', $threads);
$this->output->set_env('autocomplete_sources', $book_types);
}
}
$this->output->set_env('autocomplete_max', (int)$this->config->get('autocomplete_max', 15));
$this->output->set_env('autocomplete_min_length', $this->config->get('autocomplete_min_length'));
$this->output->add_label('autocompletechars', 'autocompletemore');
} | [
"public",
"function",
"autocomplete_init",
"(",
")",
"{",
"static",
"$",
"init",
";",
"if",
"(",
"$",
"init",
")",
"{",
"return",
";",
"}",
"$",
"init",
"=",
"1",
";",
"if",
"(",
"(",
"$",
"threads",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'autocomplete_threads'",
")",
")",
">",
"0",
")",
"{",
"$",
"book_types",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'autocomplete_addressbooks'",
",",
"'sql'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"book_types",
")",
">",
"1",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'autocomplete_threads'",
",",
"$",
"threads",
")",
";",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'autocomplete_sources'",
",",
"$",
"book_types",
")",
";",
"}",
"}",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'autocomplete_max'",
",",
"(",
"int",
")",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'autocomplete_max'",
",",
"15",
")",
")",
";",
"$",
"this",
"->",
"output",
"->",
"set_env",
"(",
"'autocomplete_min_length'",
",",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'autocomplete_min_length'",
")",
")",
";",
"$",
"this",
"->",
"output",
"->",
"add_label",
"(",
"'autocompletechars'",
",",
"'autocompletemore'",
")",
";",
"}"
]
| Initializes client-side autocompletion. | [
"Initializes",
"client",
"-",
"side",
"autocompletion",
"."
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L2272-L2293 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.show_bytes | public function show_bytes($bytes, &$unit = null)
{
if ($bytes >= 1073741824) {
$unit = 'GB';
$gb = $bytes/1073741824;
$str = sprintf($gb >= 10 ? "%d " : "%.1f ", $gb) . $this->gettext($unit);
}
else if ($bytes >= 1048576) {
$unit = 'MB';
$mb = $bytes/1048576;
$str = sprintf($mb >= 10 ? "%d " : "%.1f ", $mb) . $this->gettext($unit);
}
else if ($bytes >= 1024) {
$unit = 'KB';
$str = sprintf("%d ", round($bytes/1024)) . $this->gettext($unit);
}
else {
$unit = 'B';
$str = sprintf('%d ', $bytes) . $this->gettext($unit);
}
return $str;
} | php | public function show_bytes($bytes, &$unit = null)
{
if ($bytes >= 1073741824) {
$unit = 'GB';
$gb = $bytes/1073741824;
$str = sprintf($gb >= 10 ? "%d " : "%.1f ", $gb) . $this->gettext($unit);
}
else if ($bytes >= 1048576) {
$unit = 'MB';
$mb = $bytes/1048576;
$str = sprintf($mb >= 10 ? "%d " : "%.1f ", $mb) . $this->gettext($unit);
}
else if ($bytes >= 1024) {
$unit = 'KB';
$str = sprintf("%d ", round($bytes/1024)) . $this->gettext($unit);
}
else {
$unit = 'B';
$str = sprintf('%d ', $bytes) . $this->gettext($unit);
}
return $str;
} | [
"public",
"function",
"show_bytes",
"(",
"$",
"bytes",
",",
"&",
"$",
"unit",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"bytes",
">=",
"1073741824",
")",
"{",
"$",
"unit",
"=",
"'GB'",
";",
"$",
"gb",
"=",
"$",
"bytes",
"/",
"1073741824",
";",
"$",
"str",
"=",
"sprintf",
"(",
"$",
"gb",
">=",
"10",
"?",
"\"%d \"",
":",
"\"%.1f \"",
",",
"$",
"gb",
")",
".",
"$",
"this",
"->",
"gettext",
"(",
"$",
"unit",
")",
";",
"}",
"else",
"if",
"(",
"$",
"bytes",
">=",
"1048576",
")",
"{",
"$",
"unit",
"=",
"'MB'",
";",
"$",
"mb",
"=",
"$",
"bytes",
"/",
"1048576",
";",
"$",
"str",
"=",
"sprintf",
"(",
"$",
"mb",
">=",
"10",
"?",
"\"%d \"",
":",
"\"%.1f \"",
",",
"$",
"mb",
")",
".",
"$",
"this",
"->",
"gettext",
"(",
"$",
"unit",
")",
";",
"}",
"else",
"if",
"(",
"$",
"bytes",
">=",
"1024",
")",
"{",
"$",
"unit",
"=",
"'KB'",
";",
"$",
"str",
"=",
"sprintf",
"(",
"\"%d \"",
",",
"round",
"(",
"$",
"bytes",
"/",
"1024",
")",
")",
".",
"$",
"this",
"->",
"gettext",
"(",
"$",
"unit",
")",
";",
"}",
"else",
"{",
"$",
"unit",
"=",
"'B'",
";",
"$",
"str",
"=",
"sprintf",
"(",
"'%d '",
",",
"$",
"bytes",
")",
".",
"$",
"this",
"->",
"gettext",
"(",
"$",
"unit",
")",
";",
"}",
"return",
"$",
"str",
";",
"}"
]
| Create a human readable string for a number of bytes
@param int $bytes Number of bytes
@param string &$unit Size unit
@return string Byte string | [
"Create",
"a",
"human",
"readable",
"string",
"for",
"a",
"number",
"of",
"bytes"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L2335-L2357 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.html2text | public function html2text($html, $options = array())
{
$default_options = array(
'links' => true,
'width' => 75,
'body' => $html,
'charset' => RCUBE_CHARSET,
);
$options = array_merge($default_options, (array) $options);
// Plugins may want to modify HTML in another/additional way
$options = $this->plugins->exec_hook('html2text', $options);
// Convert to text
if (!$options['abort']) {
$converter = new rcube_html2text($options['body'],
false, $options['links'], $options['width'], $options['charset']);
$options['body'] = rtrim($converter->get_text());
}
return $options['body'];
} | php | public function html2text($html, $options = array())
{
$default_options = array(
'links' => true,
'width' => 75,
'body' => $html,
'charset' => RCUBE_CHARSET,
);
$options = array_merge($default_options, (array) $options);
// Plugins may want to modify HTML in another/additional way
$options = $this->plugins->exec_hook('html2text', $options);
// Convert to text
if (!$options['abort']) {
$converter = new rcube_html2text($options['body'],
false, $options['links'], $options['width'], $options['charset']);
$options['body'] = rtrim($converter->get_text());
}
return $options['body'];
} | [
"public",
"function",
"html2text",
"(",
"$",
"html",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"default_options",
"=",
"array",
"(",
"'links'",
"=>",
"true",
",",
"'width'",
"=>",
"75",
",",
"'body'",
"=>",
"$",
"html",
",",
"'charset'",
"=>",
"RCUBE_CHARSET",
",",
")",
";",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"default_options",
",",
"(",
"array",
")",
"$",
"options",
")",
";",
"// Plugins may want to modify HTML in another/additional way",
"$",
"options",
"=",
"$",
"this",
"->",
"plugins",
"->",
"exec_hook",
"(",
"'html2text'",
",",
"$",
"options",
")",
";",
"// Convert to text",
"if",
"(",
"!",
"$",
"options",
"[",
"'abort'",
"]",
")",
"{",
"$",
"converter",
"=",
"new",
"rcube_html2text",
"(",
"$",
"options",
"[",
"'body'",
"]",
",",
"false",
",",
"$",
"options",
"[",
"'links'",
"]",
",",
"$",
"options",
"[",
"'width'",
"]",
",",
"$",
"options",
"[",
"'charset'",
"]",
")",
";",
"$",
"options",
"[",
"'body'",
"]",
"=",
"rtrim",
"(",
"$",
"converter",
"->",
"get_text",
"(",
")",
")",
";",
"}",
"return",
"$",
"options",
"[",
"'body'",
"]",
";",
"}"
]
| Converts HTML content into plain text
@param string $html HTML content
@param array $options Conversion parameters (width, links, charset)
@return string Plain text | [
"Converts",
"HTML",
"content",
"into",
"plain",
"text"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L2486-L2509 | train |
i-MSCP/roundcube | roundcubemail/program/include/rcmail.php | rcmail.storage_connect | public function storage_connect()
{
$storage = $this->get_storage();
if ($_SESSION['storage_host'] && !$storage->is_connected()) {
$host = $_SESSION['storage_host'];
$user = $_SESSION['username'];
$port = $_SESSION['storage_port'];
$ssl = $_SESSION['storage_ssl'];
$pass = $this->decrypt($_SESSION['password']);
if (!$storage->connect($host, $user, $pass, $port, $ssl)) {
if (is_object($this->output)) {
$this->output->show_message('storageerror', 'error');
}
}
else {
$this->set_storage_prop();
}
}
return $storage->is_connected();
} | php | public function storage_connect()
{
$storage = $this->get_storage();
if ($_SESSION['storage_host'] && !$storage->is_connected()) {
$host = $_SESSION['storage_host'];
$user = $_SESSION['username'];
$port = $_SESSION['storage_port'];
$ssl = $_SESSION['storage_ssl'];
$pass = $this->decrypt($_SESSION['password']);
if (!$storage->connect($host, $user, $pass, $port, $ssl)) {
if (is_object($this->output)) {
$this->output->show_message('storageerror', 'error');
}
}
else {
$this->set_storage_prop();
}
}
return $storage->is_connected();
} | [
"public",
"function",
"storage_connect",
"(",
")",
"{",
"$",
"storage",
"=",
"$",
"this",
"->",
"get_storage",
"(",
")",
";",
"if",
"(",
"$",
"_SESSION",
"[",
"'storage_host'",
"]",
"&&",
"!",
"$",
"storage",
"->",
"is_connected",
"(",
")",
")",
"{",
"$",
"host",
"=",
"$",
"_SESSION",
"[",
"'storage_host'",
"]",
";",
"$",
"user",
"=",
"$",
"_SESSION",
"[",
"'username'",
"]",
";",
"$",
"port",
"=",
"$",
"_SESSION",
"[",
"'storage_port'",
"]",
";",
"$",
"ssl",
"=",
"$",
"_SESSION",
"[",
"'storage_ssl'",
"]",
";",
"$",
"pass",
"=",
"$",
"this",
"->",
"decrypt",
"(",
"$",
"_SESSION",
"[",
"'password'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"storage",
"->",
"connect",
"(",
"$",
"host",
",",
"$",
"user",
",",
"$",
"pass",
",",
"$",
"port",
",",
"$",
"ssl",
")",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"this",
"->",
"output",
")",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"show_message",
"(",
"'storageerror'",
",",
"'error'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"set_storage_prop",
"(",
")",
";",
"}",
"}",
"return",
"$",
"storage",
"->",
"is_connected",
"(",
")",
";",
"}"
]
| Connect to the mail storage server with stored session data
@return bool True on success, False on error | [
"Connect",
"to",
"the",
"mail",
"storage",
"server",
"with",
"stored",
"session",
"data"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail.php#L2516-L2538 | train |
netgen/NetgenInformationCollectionBundle | bundle/Action/ActionRegistry.php | ActionRegistry.addAction | public function addAction($name, ActionInterface $action, $priority = Priority::DEFAULT_PRIORITY)
{
$this->actions[] = array(
'name' => $name,
'action' => $action,
'priority' => $priority,
);
} | php | public function addAction($name, ActionInterface $action, $priority = Priority::DEFAULT_PRIORITY)
{
$this->actions[] = array(
'name' => $name,
'action' => $action,
'priority' => $priority,
);
} | [
"public",
"function",
"addAction",
"(",
"$",
"name",
",",
"ActionInterface",
"$",
"action",
",",
"$",
"priority",
"=",
"Priority",
"::",
"DEFAULT_PRIORITY",
")",
"{",
"$",
"this",
"->",
"actions",
"[",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"name",
",",
"'action'",
"=>",
"$",
"action",
",",
"'priority'",
"=>",
"$",
"priority",
",",
")",
";",
"}"
]
| Adds action to stack.
@param string $name
@param ActionInterface $action
@param int $priority | [
"Adds",
"action",
"to",
"stack",
"."
]
| 3ed7a2b33b1e80d3a0d9ee607eab495396044b29 | https://github.com/netgen/NetgenInformationCollectionBundle/blob/3ed7a2b33b1e80d3a0d9ee607eab495396044b29/bundle/Action/ActionRegistry.php#L55-L62 | train |
netgen/NetgenInformationCollectionBundle | bundle/Action/ActionRegistry.php | ActionRegistry.prepareConfig | protected function prepareConfig($contentTypeIdentifier)
{
if (!empty($this->config[ConfigurationConstants::CONTENT_TYPES][$contentTypeIdentifier])) {
return $this->config[ConfigurationConstants::CONTENT_TYPES][$contentTypeIdentifier];
}
if (!empty($this->config['default'])) {
return $this->config['default'];
}
return array();
} | php | protected function prepareConfig($contentTypeIdentifier)
{
if (!empty($this->config[ConfigurationConstants::CONTENT_TYPES][$contentTypeIdentifier])) {
return $this->config[ConfigurationConstants::CONTENT_TYPES][$contentTypeIdentifier];
}
if (!empty($this->config['default'])) {
return $this->config['default'];
}
return array();
} | [
"protected",
"function",
"prepareConfig",
"(",
"$",
"contentTypeIdentifier",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
"[",
"ConfigurationConstants",
"::",
"CONTENT_TYPES",
"]",
"[",
"$",
"contentTypeIdentifier",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"config",
"[",
"ConfigurationConstants",
"::",
"CONTENT_TYPES",
"]",
"[",
"$",
"contentTypeIdentifier",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
"[",
"'default'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"config",
"[",
"'default'",
"]",
";",
"}",
"return",
"array",
"(",
")",
";",
"}"
]
| Returns configuration for given content type identifier if exists
or default one.
@param string $contentTypeIdentifier
@return array | [
"Returns",
"configuration",
"for",
"given",
"content",
"type",
"identifier",
"if",
"exists",
"or",
"default",
"one",
"."
]
| 3ed7a2b33b1e80d3a0d9ee607eab495396044b29 | https://github.com/netgen/NetgenInformationCollectionBundle/blob/3ed7a2b33b1e80d3a0d9ee607eab495396044b29/bundle/Action/ActionRegistry.php#L120-L131 | train |
netgen/NetgenInformationCollectionBundle | bundle/Action/ActionRegistry.php | ActionRegistry.prepareActions | protected function prepareActions()
{
usort($this->actions, function ($one, $two) {
if ($one['priority'] === $two['priority']) {
return 0;
}
return ($one['priority'] > $two['priority']) ? -1 : 1;
});
} | php | protected function prepareActions()
{
usort($this->actions, function ($one, $two) {
if ($one['priority'] === $two['priority']) {
return 0;
}
return ($one['priority'] > $two['priority']) ? -1 : 1;
});
} | [
"protected",
"function",
"prepareActions",
"(",
")",
"{",
"usort",
"(",
"$",
"this",
"->",
"actions",
",",
"function",
"(",
"$",
"one",
",",
"$",
"two",
")",
"{",
"if",
"(",
"$",
"one",
"[",
"'priority'",
"]",
"===",
"$",
"two",
"[",
"'priority'",
"]",
")",
"{",
"return",
"0",
";",
"}",
"return",
"(",
"$",
"one",
"[",
"'priority'",
"]",
">",
"$",
"two",
"[",
"'priority'",
"]",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
")",
";",
"}"
]
| Sorts actions by priority. | [
"Sorts",
"actions",
"by",
"priority",
"."
]
| 3ed7a2b33b1e80d3a0d9ee607eab495396044b29 | https://github.com/netgen/NetgenInformationCollectionBundle/blob/3ed7a2b33b1e80d3a0d9ee607eab495396044b29/bundle/Action/ActionRegistry.php#L136-L145 | train |
i-MSCP/roundcube | roundcubemail/plugins/enigma/lib/enigma_key.php | enigma_key.get_type | function get_type()
{
if ($this->subkeys[0]->has_private)
return enigma_key::TYPE_KEYPAIR;
else if (!empty($this->subkeys[0]))
return enigma_key::TYPE_PUBLIC;
return enigma_key::TYPE_UNKNOWN;
} | php | function get_type()
{
if ($this->subkeys[0]->has_private)
return enigma_key::TYPE_KEYPAIR;
else if (!empty($this->subkeys[0]))
return enigma_key::TYPE_PUBLIC;
return enigma_key::TYPE_UNKNOWN;
} | [
"function",
"get_type",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"subkeys",
"[",
"0",
"]",
"->",
"has_private",
")",
"return",
"enigma_key",
"::",
"TYPE_KEYPAIR",
";",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"subkeys",
"[",
"0",
"]",
")",
")",
"return",
"enigma_key",
"::",
"TYPE_PUBLIC",
";",
"return",
"enigma_key",
"::",
"TYPE_UNKNOWN",
";",
"}"
]
| Returns key type | [
"Returns",
"key",
"type"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_key.php#L48-L56 | train |
i-MSCP/roundcube | roundcubemail/plugins/enigma/lib/enigma_key.php | enigma_key.is_expired | function is_expired()
{
$now = time();
foreach ($this->subkeys as $subkey)
if (!$subkey->expires || $subkey->expires > $now)
return true;
return false;
} | php | function is_expired()
{
$now = time();
foreach ($this->subkeys as $subkey)
if (!$subkey->expires || $subkey->expires > $now)
return true;
return false;
} | [
"function",
"is_expired",
"(",
")",
"{",
"$",
"now",
"=",
"time",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"subkeys",
"as",
"$",
"subkey",
")",
"if",
"(",
"!",
"$",
"subkey",
"->",
"expires",
"||",
"$",
"subkey",
"->",
"expires",
">",
"$",
"now",
")",
"return",
"true",
";",
"return",
"false",
";",
"}"
]
| Returns true if any of subkeys is not expired | [
"Returns",
"true",
"if",
"any",
"of",
"subkeys",
"is",
"not",
"expired"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_key.php#L85-L94 | train |
i-MSCP/roundcube | roundcubemail/plugins/enigma/lib/enigma_key.php | enigma_key.is_private | function is_private()
{
$now = time();
foreach ($this->subkeys as $subkey)
if ($subkey->has_private)
return true;
return false;
} | php | function is_private()
{
$now = time();
foreach ($this->subkeys as $subkey)
if ($subkey->has_private)
return true;
return false;
} | [
"function",
"is_private",
"(",
")",
"{",
"$",
"now",
"=",
"time",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"subkeys",
"as",
"$",
"subkey",
")",
"if",
"(",
"$",
"subkey",
"->",
"has_private",
")",
"return",
"true",
";",
"return",
"false",
";",
"}"
]
| Returns true if any of subkeys is a private key | [
"Returns",
"true",
"if",
"any",
"of",
"subkeys",
"is",
"a",
"private",
"key"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_key.php#L99-L108 | train |
i-MSCP/roundcube | roundcubemail/plugins/enigma/lib/enigma_key.php | enigma_key.find_subkey | function find_subkey($email, $mode)
{
$now = time();
foreach ($this->users as $user) {
if (strcasecmp($user->email, $email) === 0 && $user->valid && !$user->revoked) {
foreach ($this->subkeys as $subkey) {
if (!$subkey->revoked && (!$subkey->expires || $subkey->expires > $now)) {
if ($subkey->usage & $mode) {
return $subkey;
}
}
}
}
}
} | php | function find_subkey($email, $mode)
{
$now = time();
foreach ($this->users as $user) {
if (strcasecmp($user->email, $email) === 0 && $user->valid && !$user->revoked) {
foreach ($this->subkeys as $subkey) {
if (!$subkey->revoked && (!$subkey->expires || $subkey->expires > $now)) {
if ($subkey->usage & $mode) {
return $subkey;
}
}
}
}
}
} | [
"function",
"find_subkey",
"(",
"$",
"email",
",",
"$",
"mode",
")",
"{",
"$",
"now",
"=",
"time",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"users",
"as",
"$",
"user",
")",
"{",
"if",
"(",
"strcasecmp",
"(",
"$",
"user",
"->",
"email",
",",
"$",
"email",
")",
"===",
"0",
"&&",
"$",
"user",
"->",
"valid",
"&&",
"!",
"$",
"user",
"->",
"revoked",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"subkeys",
"as",
"$",
"subkey",
")",
"{",
"if",
"(",
"!",
"$",
"subkey",
"->",
"revoked",
"&&",
"(",
"!",
"$",
"subkey",
"->",
"expires",
"||",
"$",
"subkey",
"->",
"expires",
">",
"$",
"now",
")",
")",
"{",
"if",
"(",
"$",
"subkey",
"->",
"usage",
"&",
"$",
"mode",
")",
"{",
"return",
"$",
"subkey",
";",
"}",
"}",
"}",
"}",
"}",
"}"
]
| Get key ID by user email | [
"Get",
"key",
"ID",
"by",
"user",
"email"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_key.php#L113-L128 | train |
i-MSCP/roundcube | roundcubemail/plugins/enigma/lib/enigma_key.php | enigma_key.format_fingerprint | static function format_fingerprint($fingerprint)
{
if (!$fingerprint) {
return '';
}
$result = '';
for ($i=0; $i<40; $i++) {
if ($i % 4 == 0) {
$result .= ' ';
}
$result .= $fingerprint[$i];
}
return $result;
} | php | static function format_fingerprint($fingerprint)
{
if (!$fingerprint) {
return '';
}
$result = '';
for ($i=0; $i<40; $i++) {
if ($i % 4 == 0) {
$result .= ' ';
}
$result .= $fingerprint[$i];
}
return $result;
} | [
"static",
"function",
"format_fingerprint",
"(",
"$",
"fingerprint",
")",
"{",
"if",
"(",
"!",
"$",
"fingerprint",
")",
"{",
"return",
"''",
";",
"}",
"$",
"result",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"40",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"i",
"%",
"4",
"==",
"0",
")",
"{",
"$",
"result",
".=",
"' '",
";",
"}",
"$",
"result",
".=",
"$",
"fingerprint",
"[",
"$",
"i",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Formats fingerprint string
@param string Key fingerprint
@return string Formatted fingerprint (with spaces) | [
"Formats",
"fingerprint",
"string"
]
| 141965e74cf301575198abc6bf12f207aacaa6c3 | https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/enigma/lib/enigma_key.php#L151-L166 | train |
VIPnytt/SitemapParser | src/SitemapParser.php | SitemapParser.getQueue | public function getQueue()
{
$this->queue = array_values(array_diff(array_unique(array_merge($this->queue, array_keys($this->sitemaps))), $this->history));
return $this->queue;
} | php | public function getQueue()
{
$this->queue = array_values(array_diff(array_unique(array_merge($this->queue, array_keys($this->sitemaps))), $this->history));
return $this->queue;
} | [
"public",
"function",
"getQueue",
"(",
")",
"{",
"$",
"this",
"->",
"queue",
"=",
"array_values",
"(",
"array_diff",
"(",
"array_unique",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"queue",
",",
"array_keys",
"(",
"$",
"this",
"->",
"sitemaps",
")",
")",
")",
",",
"$",
"this",
"->",
"history",
")",
")",
";",
"return",
"$",
"this",
"->",
"queue",
";",
"}"
]
| Sitemap URLs discovered but not yet parsed
@return array | [
"Sitemap",
"URLs",
"discovered",
"but",
"not",
"yet",
"parsed"
]
| 57cb0dcac0e9a51b6a5287a0672d30f6827fdc3d | https://github.com/VIPnytt/SitemapParser/blob/57cb0dcac0e9a51b6a5287a0672d30f6827fdc3d/src/SitemapParser.php#L152-L156 | train |
VIPnytt/SitemapParser | src/SitemapParser.php | SitemapParser.getContent | protected function getContent()
{
$this->currentURL = $this->urlEncode($this->currentURL);
if (!$this->urlValidate($this->currentURL)) {
throw new SitemapParserException('Invalid URL');
}
try {
if (!isset($this->config['guzzle']['headers']['User-Agent'])) {
$this->config['guzzle']['headers']['User-Agent'] = $this->userAgent;
}
$client = new GuzzleHttp\Client();
$res = $client->request('GET', $this->currentURL, $this->config['guzzle']);
return $res->getBody();
} catch (GuzzleHttp\Exception\TransferException $e) {
throw new SitemapParserException($e->getMessage());
}
} | php | protected function getContent()
{
$this->currentURL = $this->urlEncode($this->currentURL);
if (!$this->urlValidate($this->currentURL)) {
throw new SitemapParserException('Invalid URL');
}
try {
if (!isset($this->config['guzzle']['headers']['User-Agent'])) {
$this->config['guzzle']['headers']['User-Agent'] = $this->userAgent;
}
$client = new GuzzleHttp\Client();
$res = $client->request('GET', $this->currentURL, $this->config['guzzle']);
return $res->getBody();
} catch (GuzzleHttp\Exception\TransferException $e) {
throw new SitemapParserException($e->getMessage());
}
} | [
"protected",
"function",
"getContent",
"(",
")",
"{",
"$",
"this",
"->",
"currentURL",
"=",
"$",
"this",
"->",
"urlEncode",
"(",
"$",
"this",
"->",
"currentURL",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"urlValidate",
"(",
"$",
"this",
"->",
"currentURL",
")",
")",
"{",
"throw",
"new",
"SitemapParserException",
"(",
"'Invalid URL'",
")",
";",
"}",
"try",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'guzzle'",
"]",
"[",
"'headers'",
"]",
"[",
"'User-Agent'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"config",
"[",
"'guzzle'",
"]",
"[",
"'headers'",
"]",
"[",
"'User-Agent'",
"]",
"=",
"$",
"this",
"->",
"userAgent",
";",
"}",
"$",
"client",
"=",
"new",
"GuzzleHttp",
"\\",
"Client",
"(",
")",
";",
"$",
"res",
"=",
"$",
"client",
"->",
"request",
"(",
"'GET'",
",",
"$",
"this",
"->",
"currentURL",
",",
"$",
"this",
"->",
"config",
"[",
"'guzzle'",
"]",
")",
";",
"return",
"$",
"res",
"->",
"getBody",
"(",
")",
";",
"}",
"catch",
"(",
"GuzzleHttp",
"\\",
"Exception",
"\\",
"TransferException",
"$",
"e",
")",
"{",
"throw",
"new",
"SitemapParserException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
]
| Request the body content of an URL
@return string Raw body content
@throws SitemapParserException | [
"Request",
"the",
"body",
"content",
"of",
"an",
"URL"
]
| 57cb0dcac0e9a51b6a5287a0672d30f6827fdc3d | https://github.com/VIPnytt/SitemapParser/blob/57cb0dcac0e9a51b6a5287a0672d30f6827fdc3d/src/SitemapParser.php#L206-L222 | train |
VIPnytt/SitemapParser | src/SitemapParser.php | SitemapParser.parseRobotstxt | protected function parseRobotstxt($robotstxt)
{
// Split lines into array
$lines = array_filter(array_map('trim', mb_split('\r\n|\n|\r', $robotstxt)));
// Parse each line individually
foreach ($lines as $line) {
// Remove comments
$line = mb_split('#', $line, 2)[0];
// Split by directive and rule
$pair = array_map('trim', mb_split(':', $line, 2));
// Check if the line contains a sitemap
if (
mb_strtolower($pair[0]) !== self::XML_TAG_SITEMAP ||
empty($pair[1])
) {
// Line does not contain any supported directive
continue;
}
$url = $this->urlEncode($pair[1]);
if ($this->urlValidate($url)) {
$this->addArray(self::XML_TAG_SITEMAP, ['loc' => $url]);
}
}
return true;
} | php | protected function parseRobotstxt($robotstxt)
{
// Split lines into array
$lines = array_filter(array_map('trim', mb_split('\r\n|\n|\r', $robotstxt)));
// Parse each line individually
foreach ($lines as $line) {
// Remove comments
$line = mb_split('#', $line, 2)[0];
// Split by directive and rule
$pair = array_map('trim', mb_split(':', $line, 2));
// Check if the line contains a sitemap
if (
mb_strtolower($pair[0]) !== self::XML_TAG_SITEMAP ||
empty($pair[1])
) {
// Line does not contain any supported directive
continue;
}
$url = $this->urlEncode($pair[1]);
if ($this->urlValidate($url)) {
$this->addArray(self::XML_TAG_SITEMAP, ['loc' => $url]);
}
}
return true;
} | [
"protected",
"function",
"parseRobotstxt",
"(",
"$",
"robotstxt",
")",
"{",
"// Split lines into array",
"$",
"lines",
"=",
"array_filter",
"(",
"array_map",
"(",
"'trim'",
",",
"mb_split",
"(",
"'\\r\\n|\\n|\\r'",
",",
"$",
"robotstxt",
")",
")",
")",
";",
"// Parse each line individually",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"// Remove comments",
"$",
"line",
"=",
"mb_split",
"(",
"'#'",
",",
"$",
"line",
",",
"2",
")",
"[",
"0",
"]",
";",
"// Split by directive and rule",
"$",
"pair",
"=",
"array_map",
"(",
"'trim'",
",",
"mb_split",
"(",
"':'",
",",
"$",
"line",
",",
"2",
")",
")",
";",
"// Check if the line contains a sitemap",
"if",
"(",
"mb_strtolower",
"(",
"$",
"pair",
"[",
"0",
"]",
")",
"!==",
"self",
"::",
"XML_TAG_SITEMAP",
"||",
"empty",
"(",
"$",
"pair",
"[",
"1",
"]",
")",
")",
"{",
"// Line does not contain any supported directive",
"continue",
";",
"}",
"$",
"url",
"=",
"$",
"this",
"->",
"urlEncode",
"(",
"$",
"pair",
"[",
"1",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"urlValidate",
"(",
"$",
"url",
")",
")",
"{",
"$",
"this",
"->",
"addArray",
"(",
"self",
"::",
"XML_TAG_SITEMAP",
",",
"[",
"'loc'",
"=>",
"$",
"url",
"]",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Search for sitemaps in the robots.txt content
@param string $robotstxt
@return bool | [
"Search",
"for",
"sitemaps",
"in",
"the",
"robots",
".",
"txt",
"content"
]
| 57cb0dcac0e9a51b6a5287a0672d30f6827fdc3d | https://github.com/VIPnytt/SitemapParser/blob/57cb0dcac0e9a51b6a5287a0672d30f6827fdc3d/src/SitemapParser.php#L230-L254 | train |
VIPnytt/SitemapParser | src/SitemapParser.php | SitemapParser.addArray | protected function addArray($type, array $array)
{
if (!isset($array['loc'])) {
return false;
}
$array['loc'] = $this->urlEncode(trim($array['loc']));
if ($this->urlValidate($array['loc'])) {
switch ($type) {
case self::XML_TAG_SITEMAP:
$this->sitemaps[$array['loc']] = $this->fixMissingTags(['lastmod'], $array);
return true;
case self::XML_TAG_URL:
$this->urls[$array['loc']] = $this->fixMissingTags(['lastmod', 'changefreq', 'priority'], $array);
return true;
}
}
return false;
} | php | protected function addArray($type, array $array)
{
if (!isset($array['loc'])) {
return false;
}
$array['loc'] = $this->urlEncode(trim($array['loc']));
if ($this->urlValidate($array['loc'])) {
switch ($type) {
case self::XML_TAG_SITEMAP:
$this->sitemaps[$array['loc']] = $this->fixMissingTags(['lastmod'], $array);
return true;
case self::XML_TAG_URL:
$this->urls[$array['loc']] = $this->fixMissingTags(['lastmod', 'changefreq', 'priority'], $array);
return true;
}
}
return false;
} | [
"protected",
"function",
"addArray",
"(",
"$",
"type",
",",
"array",
"$",
"array",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"array",
"[",
"'loc'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"array",
"[",
"'loc'",
"]",
"=",
"$",
"this",
"->",
"urlEncode",
"(",
"trim",
"(",
"$",
"array",
"[",
"'loc'",
"]",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"urlValidate",
"(",
"$",
"array",
"[",
"'loc'",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"self",
"::",
"XML_TAG_SITEMAP",
":",
"$",
"this",
"->",
"sitemaps",
"[",
"$",
"array",
"[",
"'loc'",
"]",
"]",
"=",
"$",
"this",
"->",
"fixMissingTags",
"(",
"[",
"'lastmod'",
"]",
",",
"$",
"array",
")",
";",
"return",
"true",
";",
"case",
"self",
"::",
"XML_TAG_URL",
":",
"$",
"this",
"->",
"urls",
"[",
"$",
"array",
"[",
"'loc'",
"]",
"]",
"=",
"$",
"this",
"->",
"fixMissingTags",
"(",
"[",
"'lastmod'",
",",
"'changefreq'",
",",
"'priority'",
"]",
",",
"$",
"array",
")",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Validate URL arrays and add them to their corresponding arrays
@param string $type sitemap|url
@param array $array Tag array
@return bool | [
"Validate",
"URL",
"arrays",
"and",
"add",
"them",
"to",
"their",
"corresponding",
"arrays"
]
| 57cb0dcac0e9a51b6a5287a0672d30f6827fdc3d | https://github.com/VIPnytt/SitemapParser/blob/57cb0dcac0e9a51b6a5287a0672d30f6827fdc3d/src/SitemapParser.php#L263-L280 | train |
VIPnytt/SitemapParser | src/SitemapParser.php | SitemapParser.generateXMLObject | protected function generateXMLObject($xml)
{
try {
libxml_use_internal_errors(true);
return new SimpleXMLElement($xml, LIBXML_NOCDATA);
} catch (\Exception $e) {
return false;
}
} | php | protected function generateXMLObject($xml)
{
try {
libxml_use_internal_errors(true);
return new SimpleXMLElement($xml, LIBXML_NOCDATA);
} catch (\Exception $e) {
return false;
}
} | [
"protected",
"function",
"generateXMLObject",
"(",
"$",
"xml",
")",
"{",
"try",
"{",
"libxml_use_internal_errors",
"(",
"true",
")",
";",
"return",
"new",
"SimpleXMLElement",
"(",
"$",
"xml",
",",
"LIBXML_NOCDATA",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
]
| Generate the \SimpleXMLElement object if the XML is valid
@param string $xml
@return \SimpleXMLElement|false | [
"Generate",
"the",
"\\",
"SimpleXMLElement",
"object",
"if",
"the",
"XML",
"is",
"valid"
]
| 57cb0dcac0e9a51b6a5287a0672d30f6827fdc3d | https://github.com/VIPnytt/SitemapParser/blob/57cb0dcac0e9a51b6a5287a0672d30f6827fdc3d/src/SitemapParser.php#L305-L313 | train |
VIPnytt/SitemapParser | src/SitemapParser.php | SitemapParser.parseString | protected function parseString($string)
{
if (!isset($this->config['strict']) || $this->config['strict'] !== false) {
// Strings are not part of any documented sitemap standard
return false;
}
$array = array_filter(array_map('trim', mb_split('\r\n|\n|\r', $string)));
foreach ($array as $line) {
if ($this->isSitemapURL($line)) {
$this->addArray(self::XML_TAG_SITEMAP, ['loc' => $line]);
continue;
}
$this->addArray(self::XML_TAG_URL, ['loc' => $line]);
}
return true;
} | php | protected function parseString($string)
{
if (!isset($this->config['strict']) || $this->config['strict'] !== false) {
// Strings are not part of any documented sitemap standard
return false;
}
$array = array_filter(array_map('trim', mb_split('\r\n|\n|\r', $string)));
foreach ($array as $line) {
if ($this->isSitemapURL($line)) {
$this->addArray(self::XML_TAG_SITEMAP, ['loc' => $line]);
continue;
}
$this->addArray(self::XML_TAG_URL, ['loc' => $line]);
}
return true;
} | [
"protected",
"function",
"parseString",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'strict'",
"]",
")",
"||",
"$",
"this",
"->",
"config",
"[",
"'strict'",
"]",
"!==",
"false",
")",
"{",
"// Strings are not part of any documented sitemap standard",
"return",
"false",
";",
"}",
"$",
"array",
"=",
"array_filter",
"(",
"array_map",
"(",
"'trim'",
",",
"mb_split",
"(",
"'\\r\\n|\\n|\\r'",
",",
"$",
"string",
")",
")",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"line",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSitemapURL",
"(",
"$",
"line",
")",
")",
"{",
"$",
"this",
"->",
"addArray",
"(",
"self",
"::",
"XML_TAG_SITEMAP",
",",
"[",
"'loc'",
"=>",
"$",
"line",
"]",
")",
";",
"continue",
";",
"}",
"$",
"this",
"->",
"addArray",
"(",
"self",
"::",
"XML_TAG_URL",
",",
"[",
"'loc'",
"=>",
"$",
"line",
"]",
")",
";",
"}",
"return",
"true",
";",
"}"
]
| Parse line separated text string
@param string $string
@return bool | [
"Parse",
"line",
"separated",
"text",
"string"
]
| 57cb0dcac0e9a51b6a5287a0672d30f6827fdc3d | https://github.com/VIPnytt/SitemapParser/blob/57cb0dcac0e9a51b6a5287a0672d30f6827fdc3d/src/SitemapParser.php#L321-L336 | train |
VIPnytt/SitemapParser | src/SitemapParser.php | SitemapParser.isSitemapURL | protected function isSitemapURL($url)
{
$path = parse_url($this->urlEncode($url), PHP_URL_PATH);
return $this->urlValidate($url) && (
mb_substr($path, -mb_strlen(self::XML_EXTENSION) - 1) == '.' . self::XML_EXTENSION ||
mb_substr($path, -mb_strlen(self::XML_EXTENSION_COMPRESSED) - 1) == '.' . self::XML_EXTENSION_COMPRESSED
);
} | php | protected function isSitemapURL($url)
{
$path = parse_url($this->urlEncode($url), PHP_URL_PATH);
return $this->urlValidate($url) && (
mb_substr($path, -mb_strlen(self::XML_EXTENSION) - 1) == '.' . self::XML_EXTENSION ||
mb_substr($path, -mb_strlen(self::XML_EXTENSION_COMPRESSED) - 1) == '.' . self::XML_EXTENSION_COMPRESSED
);
} | [
"protected",
"function",
"isSitemapURL",
"(",
"$",
"url",
")",
"{",
"$",
"path",
"=",
"parse_url",
"(",
"$",
"this",
"->",
"urlEncode",
"(",
"$",
"url",
")",
",",
"PHP_URL_PATH",
")",
";",
"return",
"$",
"this",
"->",
"urlValidate",
"(",
"$",
"url",
")",
"&&",
"(",
"mb_substr",
"(",
"$",
"path",
",",
"-",
"mb_strlen",
"(",
"self",
"::",
"XML_EXTENSION",
")",
"-",
"1",
")",
"==",
"'.'",
".",
"self",
"::",
"XML_EXTENSION",
"||",
"mb_substr",
"(",
"$",
"path",
",",
"-",
"mb_strlen",
"(",
"self",
"::",
"XML_EXTENSION_COMPRESSED",
")",
"-",
"1",
")",
"==",
"'.'",
".",
"self",
"::",
"XML_EXTENSION_COMPRESSED",
")",
";",
"}"
]
| Check if the URL may contain an Sitemap
@param string $url
@return bool | [
"Check",
"if",
"the",
"URL",
"may",
"contain",
"an",
"Sitemap"
]
| 57cb0dcac0e9a51b6a5287a0672d30f6827fdc3d | https://github.com/VIPnytt/SitemapParser/blob/57cb0dcac0e9a51b6a5287a0672d30f6827fdc3d/src/SitemapParser.php#L344-L351 | train |
VIPnytt/SitemapParser | src/SitemapParser.php | SitemapParser.parseJson | protected function parseJson($type, \SimpleXMLElement $json)
{
if (!isset($json->$type)) {
return false;
}
foreach ($json->$type as $url) {
$this->addArray($type, (array)$url);
}
return true;
} | php | protected function parseJson($type, \SimpleXMLElement $json)
{
if (!isset($json->$type)) {
return false;
}
foreach ($json->$type as $url) {
$this->addArray($type, (array)$url);
}
return true;
} | [
"protected",
"function",
"parseJson",
"(",
"$",
"type",
",",
"\\",
"SimpleXMLElement",
"$",
"json",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"json",
"->",
"$",
"type",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"json",
"->",
"$",
"type",
"as",
"$",
"url",
")",
"{",
"$",
"this",
"->",
"addArray",
"(",
"$",
"type",
",",
"(",
"array",
")",
"$",
"url",
")",
";",
"}",
"return",
"true",
";",
"}"
]
| Parse Json object
@param string $type Sitemap or URL
@param \SimpleXMLElement $json object
@return bool | [
"Parse",
"Json",
"object"
]
| 57cb0dcac0e9a51b6a5287a0672d30f6827fdc3d | https://github.com/VIPnytt/SitemapParser/blob/57cb0dcac0e9a51b6a5287a0672d30f6827fdc3d/src/SitemapParser.php#L360-L369 | train |
symbiote/silverstripe-memberprofiles | src/Pages/MemberProfilePage.php | MemberProfilePage.Link | public function Link($action = null)
{
if (!$action
&& Member::currentUserID()
&& !$this->AllowProfileEditing
&& $this->CanAddMembers()
) {
$action = 'add';
}
return parent::Link($action);
} | php | public function Link($action = null)
{
if (!$action
&& Member::currentUserID()
&& !$this->AllowProfileEditing
&& $this->CanAddMembers()
) {
$action = 'add';
}
return parent::Link($action);
} | [
"public",
"function",
"Link",
"(",
"$",
"action",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"action",
"&&",
"Member",
"::",
"currentUserID",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"AllowProfileEditing",
"&&",
"$",
"this",
"->",
"CanAddMembers",
"(",
")",
")",
"{",
"$",
"action",
"=",
"'add'",
";",
"}",
"return",
"parent",
"::",
"Link",
"(",
"$",
"action",
")",
";",
"}"
]
| If profile editing is disabled, but the current user can add members,
just link directly to the add action.
@param string $action | [
"If",
"profile",
"editing",
"is",
"disabled",
"but",
"the",
"current",
"user",
"can",
"add",
"members",
"just",
"link",
"directly",
"to",
"the",
"add",
"action",
"."
]
| 78afc584a1a3f5850f845943f23b233bf1898b81 | https://github.com/symbiote/silverstripe-memberprofiles/blob/78afc584a1a3f5850f845943f23b233bf1898b81/src/Pages/MemberProfilePage.php#L178-L189 | train |
symbiote/silverstripe-memberprofiles | src/Pages/MemberProfilePage.php | MemberProfilePage.Fields | public function Fields()
{
$list = $this->getComponents('Fields');
$fields = singleton(Member::class)->getMemberFormFields()->dataFields();
$included = array();
foreach ($list as $profileField) {
if (!array_key_exists($profileField->MemberField, $fields)) {
$profileField->delete();
} else {
$included[] = $profileField->MemberField;
}
}
foreach ($fields as $name => $field) {
if (!in_array($name, $included)) {
$profileField = new MemberProfileField();
$profileField->MemberField = $name;
if (isset(self::$profile_field_defaults[$name])) {
$profileField->update(self::$profile_field_defaults[$name]);
}
$list->add($profileField);
}
}
return $list;
} | php | public function Fields()
{
$list = $this->getComponents('Fields');
$fields = singleton(Member::class)->getMemberFormFields()->dataFields();
$included = array();
foreach ($list as $profileField) {
if (!array_key_exists($profileField->MemberField, $fields)) {
$profileField->delete();
} else {
$included[] = $profileField->MemberField;
}
}
foreach ($fields as $name => $field) {
if (!in_array($name, $included)) {
$profileField = new MemberProfileField();
$profileField->MemberField = $name;
if (isset(self::$profile_field_defaults[$name])) {
$profileField->update(self::$profile_field_defaults[$name]);
}
$list->add($profileField);
}
}
return $list;
} | [
"public",
"function",
"Fields",
"(",
")",
"{",
"$",
"list",
"=",
"$",
"this",
"->",
"getComponents",
"(",
"'Fields'",
")",
";",
"$",
"fields",
"=",
"singleton",
"(",
"Member",
"::",
"class",
")",
"->",
"getMemberFormFields",
"(",
")",
"->",
"dataFields",
"(",
")",
";",
"$",
"included",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"profileField",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"profileField",
"->",
"MemberField",
",",
"$",
"fields",
")",
")",
"{",
"$",
"profileField",
"->",
"delete",
"(",
")",
";",
"}",
"else",
"{",
"$",
"included",
"[",
"]",
"=",
"$",
"profileField",
"->",
"MemberField",
";",
"}",
"}",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"name",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"name",
",",
"$",
"included",
")",
")",
"{",
"$",
"profileField",
"=",
"new",
"MemberProfileField",
"(",
")",
";",
"$",
"profileField",
"->",
"MemberField",
"=",
"$",
"name",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"profile_field_defaults",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"profileField",
"->",
"update",
"(",
"self",
"::",
"$",
"profile_field_defaults",
"[",
"$",
"name",
"]",
")",
";",
"}",
"$",
"list",
"->",
"add",
"(",
"$",
"profileField",
")",
";",
"}",
"}",
"return",
"$",
"list",
";",
"}"
]
| Returns a list of profile field objects after synchronising them with the
Member form fields.
@return HasManyList|UnsavedRelationList Fields() | [
"Returns",
"a",
"list",
"of",
"profile",
"field",
"objects",
"after",
"synchronising",
"them",
"with",
"the",
"Member",
"form",
"fields",
"."
]
| 78afc584a1a3f5850f845943f23b233bf1898b81 | https://github.com/symbiote/silverstripe-memberprofiles/blob/78afc584a1a3f5850f845943f23b233bf1898b81/src/Pages/MemberProfilePage.php#L412-L440 | train |
symbiote/silverstripe-memberprofiles | src/Pages/MemberProfilePageController.php | MemberProfilePageController.indexRegister | protected function indexRegister()
{
if (!$this->AllowRegistration) {
return Security::permissionFailure($this, _t(
'MemberProfiles.CANNOTREGPLEASELOGIN',
'You cannot register on this profile page. Please login to edit your profile.'
));
}
$data = array(
'Type' => 'Register',
'Title' => $this->obj('RegistrationTitle'),
'Content' => $this->obj('RegistrationContent'),
'Form' => $this->RegisterForm()
);
return $this->customise($data);
} | php | protected function indexRegister()
{
if (!$this->AllowRegistration) {
return Security::permissionFailure($this, _t(
'MemberProfiles.CANNOTREGPLEASELOGIN',
'You cannot register on this profile page. Please login to edit your profile.'
));
}
$data = array(
'Type' => 'Register',
'Title' => $this->obj('RegistrationTitle'),
'Content' => $this->obj('RegistrationContent'),
'Form' => $this->RegisterForm()
);
return $this->customise($data);
} | [
"protected",
"function",
"indexRegister",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"AllowRegistration",
")",
"{",
"return",
"Security",
"::",
"permissionFailure",
"(",
"$",
"this",
",",
"_t",
"(",
"'MemberProfiles.CANNOTREGPLEASELOGIN'",
",",
"'You cannot register on this profile page. Please login to edit your profile.'",
")",
")",
";",
"}",
"$",
"data",
"=",
"array",
"(",
"'Type'",
"=>",
"'Register'",
",",
"'Title'",
"=>",
"$",
"this",
"->",
"obj",
"(",
"'RegistrationTitle'",
")",
",",
"'Content'",
"=>",
"$",
"this",
"->",
"obj",
"(",
"'RegistrationContent'",
")",
",",
"'Form'",
"=>",
"$",
"this",
"->",
"RegisterForm",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"customise",
"(",
"$",
"data",
")",
";",
"}"
]
| Allow users to register if registration is enabled.
@return array|ViewableData_Customised | [
"Allow",
"users",
"to",
"register",
"if",
"registration",
"is",
"enabled",
"."
]
| 78afc584a1a3f5850f845943f23b233bf1898b81 | https://github.com/symbiote/silverstripe-memberprofiles/blob/78afc584a1a3f5850f845943f23b233bf1898b81/src/Pages/MemberProfilePageController.php#L94-L111 | train |
symbiote/silverstripe-memberprofiles | src/Pages/MemberProfilePageController.php | MemberProfilePageController.indexProfile | protected function indexProfile()
{
if (!$this->AllowProfileEditing) {
if ($this->AllowAdding && Injector::inst()->get(Member::class)->canCreate()) {
return $this->redirect($this->Link('add'));
}
return Security::permissionFailure($this, _t(
'MemberProfiles.CANNOTEDIT',
'You cannot edit your profile via this page.'
));
}
$member = Member::currentUser();
foreach ($this->Groups() as $group) {
if (!$member->inGroup($group)) {
return Security::permissionFailure($this);
}
}
$form = $this->ProfileForm();
$form->loadDataFrom($member);
if ($password = $form->Fields()->fieldByName('Password')) {
if ($password->hasMethod('setCanBeEmpty')) {
$password->setCanBeEmpty(false);
$password->setValue(null);
$password->setCanBeEmpty(true);
} else {
// If Password field is ReadonlyField or similar
$password->setValue(null);
}
}
$data = array(
'Type' => 'Profile',
'Title' => $this->obj('ProfileTitle'),
'Content' => $this->obj('ProfileContent'),
'Form' => $form
);
return $this->customise($data);
} | php | protected function indexProfile()
{
if (!$this->AllowProfileEditing) {
if ($this->AllowAdding && Injector::inst()->get(Member::class)->canCreate()) {
return $this->redirect($this->Link('add'));
}
return Security::permissionFailure($this, _t(
'MemberProfiles.CANNOTEDIT',
'You cannot edit your profile via this page.'
));
}
$member = Member::currentUser();
foreach ($this->Groups() as $group) {
if (!$member->inGroup($group)) {
return Security::permissionFailure($this);
}
}
$form = $this->ProfileForm();
$form->loadDataFrom($member);
if ($password = $form->Fields()->fieldByName('Password')) {
if ($password->hasMethod('setCanBeEmpty')) {
$password->setCanBeEmpty(false);
$password->setValue(null);
$password->setCanBeEmpty(true);
} else {
// If Password field is ReadonlyField or similar
$password->setValue(null);
}
}
$data = array(
'Type' => 'Profile',
'Title' => $this->obj('ProfileTitle'),
'Content' => $this->obj('ProfileContent'),
'Form' => $form
);
return $this->customise($data);
} | [
"protected",
"function",
"indexProfile",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"AllowProfileEditing",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"AllowAdding",
"&&",
"Injector",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"Member",
"::",
"class",
")",
"->",
"canCreate",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"Link",
"(",
"'add'",
")",
")",
";",
"}",
"return",
"Security",
"::",
"permissionFailure",
"(",
"$",
"this",
",",
"_t",
"(",
"'MemberProfiles.CANNOTEDIT'",
",",
"'You cannot edit your profile via this page.'",
")",
")",
";",
"}",
"$",
"member",
"=",
"Member",
"::",
"currentUser",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"Groups",
"(",
")",
"as",
"$",
"group",
")",
"{",
"if",
"(",
"!",
"$",
"member",
"->",
"inGroup",
"(",
"$",
"group",
")",
")",
"{",
"return",
"Security",
"::",
"permissionFailure",
"(",
"$",
"this",
")",
";",
"}",
"}",
"$",
"form",
"=",
"$",
"this",
"->",
"ProfileForm",
"(",
")",
";",
"$",
"form",
"->",
"loadDataFrom",
"(",
"$",
"member",
")",
";",
"if",
"(",
"$",
"password",
"=",
"$",
"form",
"->",
"Fields",
"(",
")",
"->",
"fieldByName",
"(",
"'Password'",
")",
")",
"{",
"if",
"(",
"$",
"password",
"->",
"hasMethod",
"(",
"'setCanBeEmpty'",
")",
")",
"{",
"$",
"password",
"->",
"setCanBeEmpty",
"(",
"false",
")",
";",
"$",
"password",
"->",
"setValue",
"(",
"null",
")",
";",
"$",
"password",
"->",
"setCanBeEmpty",
"(",
"true",
")",
";",
"}",
"else",
"{",
"// If Password field is ReadonlyField or similar",
"$",
"password",
"->",
"setValue",
"(",
"null",
")",
";",
"}",
"}",
"$",
"data",
"=",
"array",
"(",
"'Type'",
"=>",
"'Profile'",
",",
"'Title'",
"=>",
"$",
"this",
"->",
"obj",
"(",
"'ProfileTitle'",
")",
",",
"'Content'",
"=>",
"$",
"this",
"->",
"obj",
"(",
"'ProfileContent'",
")",
",",
"'Form'",
"=>",
"$",
"form",
")",
";",
"return",
"$",
"this",
"->",
"customise",
"(",
"$",
"data",
")",
";",
"}"
]
| Allows users to edit their profile if they are in at least one of the
groups this page is restricted to, and editing isn't disabled.
If editing is disabled, but the current user can add users, then they
are redirected to the add user page.
@return array|ViewableData_Customised | [
"Allows",
"users",
"to",
"edit",
"their",
"profile",
"if",
"they",
"are",
"in",
"at",
"least",
"one",
"of",
"the",
"groups",
"this",
"page",
"is",
"restricted",
"to",
"and",
"editing",
"isn",
"t",
"disabled",
"."
]
| 78afc584a1a3f5850f845943f23b233bf1898b81 | https://github.com/symbiote/silverstripe-memberprofiles/blob/78afc584a1a3f5850f845943f23b233bf1898b81/src/Pages/MemberProfilePageController.php#L122-L165 | train |
symbiote/silverstripe-memberprofiles | src/Pages/MemberProfilePageController.php | MemberProfilePageController.register | public function register($data, Form $form)
{
$member = $this->addMember($form);
if (!$member) {
return $this->redirectBack();
}
// If they can login, immediately log them in
if ($member->canLogin()) {
Injector::inst()->get(IdentityStore::class)->logIn($member);
}
if ($this->RegistrationRedirect) {
if ($this->PostRegistrationTargetID) {
$this->redirect($this->PostRegistrationTarget()->Link());
return;
}
$session = $this->getRequest()->getSession();
$sessionTarget = $session->get('MemberProfile.REDIRECT');
if ($sessionTarget) {
$session->clear('MemberProfile.REDIRECT');
if (Director::is_site_url($sessionTarget)) {
return $this->redirect($sessionTarget);
}
}
}
return $this->redirect($this->Link('afterregistration'));
} | php | public function register($data, Form $form)
{
$member = $this->addMember($form);
if (!$member) {
return $this->redirectBack();
}
// If they can login, immediately log them in
if ($member->canLogin()) {
Injector::inst()->get(IdentityStore::class)->logIn($member);
}
if ($this->RegistrationRedirect) {
if ($this->PostRegistrationTargetID) {
$this->redirect($this->PostRegistrationTarget()->Link());
return;
}
$session = $this->getRequest()->getSession();
$sessionTarget = $session->get('MemberProfile.REDIRECT');
if ($sessionTarget) {
$session->clear('MemberProfile.REDIRECT');
if (Director::is_site_url($sessionTarget)) {
return $this->redirect($sessionTarget);
}
}
}
return $this->redirect($this->Link('afterregistration'));
} | [
"public",
"function",
"register",
"(",
"$",
"data",
",",
"Form",
"$",
"form",
")",
"{",
"$",
"member",
"=",
"$",
"this",
"->",
"addMember",
"(",
"$",
"form",
")",
";",
"if",
"(",
"!",
"$",
"member",
")",
"{",
"return",
"$",
"this",
"->",
"redirectBack",
"(",
")",
";",
"}",
"// If they can login, immediately log them in",
"if",
"(",
"$",
"member",
"->",
"canLogin",
"(",
")",
")",
"{",
"Injector",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"IdentityStore",
"::",
"class",
")",
"->",
"logIn",
"(",
"$",
"member",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"RegistrationRedirect",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"PostRegistrationTargetID",
")",
"{",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"PostRegistrationTarget",
"(",
")",
"->",
"Link",
"(",
")",
")",
";",
"return",
";",
"}",
"$",
"session",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"getSession",
"(",
")",
";",
"$",
"sessionTarget",
"=",
"$",
"session",
"->",
"get",
"(",
"'MemberProfile.REDIRECT'",
")",
";",
"if",
"(",
"$",
"sessionTarget",
")",
"{",
"$",
"session",
"->",
"clear",
"(",
"'MemberProfile.REDIRECT'",
")",
";",
"if",
"(",
"Director",
"::",
"is_site_url",
"(",
"$",
"sessionTarget",
")",
")",
"{",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"sessionTarget",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"Link",
"(",
"'afterregistration'",
")",
")",
";",
"}"
]
| Handles validation and saving new Member objects, as well as sending out validation emails. | [
"Handles",
"validation",
"and",
"saving",
"new",
"Member",
"objects",
"as",
"well",
"as",
"sending",
"out",
"validation",
"emails",
"."
]
| 78afc584a1a3f5850f845943f23b233bf1898b81 | https://github.com/symbiote/silverstripe-memberprofiles/blob/78afc584a1a3f5850f845943f23b233bf1898b81/src/Pages/MemberProfilePageController.php#L206-L235 | train |
symbiote/silverstripe-memberprofiles | src/Pages/MemberProfilePageController.php | MemberProfilePageController.save | public function save(array $data, Form $form)
{
$member = Member::currentUser();
$groupIds = $this->getSettableGroupIdsFrom($form, $member);
$member->Groups()->setByIDList($groupIds);
$form->saveInto($member);
try {
$member->write();
} catch (ValidationException $e) {
$validationMessages = implode("; ", $e->getResult()->getMessages());
$form->sessionMessage($validationMessages, 'bad');
return $this->redirectBack();
}
$form->sessionMessage(
_t('MemberProfiles.PROFILEUPDATED', 'Your profile has been updated.'),
'good'
);
return $this->redirectBack();
} | php | public function save(array $data, Form $form)
{
$member = Member::currentUser();
$groupIds = $this->getSettableGroupIdsFrom($form, $member);
$member->Groups()->setByIDList($groupIds);
$form->saveInto($member);
try {
$member->write();
} catch (ValidationException $e) {
$validationMessages = implode("; ", $e->getResult()->getMessages());
$form->sessionMessage($validationMessages, 'bad');
return $this->redirectBack();
}
$form->sessionMessage(
_t('MemberProfiles.PROFILEUPDATED', 'Your profile has been updated.'),
'good'
);
return $this->redirectBack();
} | [
"public",
"function",
"save",
"(",
"array",
"$",
"data",
",",
"Form",
"$",
"form",
")",
"{",
"$",
"member",
"=",
"Member",
"::",
"currentUser",
"(",
")",
";",
"$",
"groupIds",
"=",
"$",
"this",
"->",
"getSettableGroupIdsFrom",
"(",
"$",
"form",
",",
"$",
"member",
")",
";",
"$",
"member",
"->",
"Groups",
"(",
")",
"->",
"setByIDList",
"(",
"$",
"groupIds",
")",
";",
"$",
"form",
"->",
"saveInto",
"(",
"$",
"member",
")",
";",
"try",
"{",
"$",
"member",
"->",
"write",
"(",
")",
";",
"}",
"catch",
"(",
"ValidationException",
"$",
"e",
")",
"{",
"$",
"validationMessages",
"=",
"implode",
"(",
"\"; \"",
",",
"$",
"e",
"->",
"getResult",
"(",
")",
"->",
"getMessages",
"(",
")",
")",
";",
"$",
"form",
"->",
"sessionMessage",
"(",
"$",
"validationMessages",
",",
"'bad'",
")",
";",
"return",
"$",
"this",
"->",
"redirectBack",
"(",
")",
";",
"}",
"$",
"form",
"->",
"sessionMessage",
"(",
"_t",
"(",
"'MemberProfiles.PROFILEUPDATED'",
",",
"'Your profile has been updated.'",
")",
",",
"'good'",
")",
";",
"return",
"$",
"this",
"->",
"redirectBack",
"(",
")",
";",
"}"
]
| Updates an existing Member's profile. | [
"Updates",
"an",
"existing",
"Member",
"s",
"profile",
"."
]
| 78afc584a1a3f5850f845943f23b233bf1898b81 | https://github.com/symbiote/silverstripe-memberprofiles/blob/78afc584a1a3f5850f845943f23b233bf1898b81/src/Pages/MemberProfilePageController.php#L272-L294 | train |
symbiote/silverstripe-memberprofiles | src/Pages/MemberProfilePageController.php | MemberProfilePageController.doAdd | public function doAdd($data, $form)
{
if ($this->addMember($form)) {
$form->sessionMessage(
_t('MemberProfiles.MEMBERADDED', 'The new member has been added.'),
'good'
);
}
return $this->redirectBack();
} | php | public function doAdd($data, $form)
{
if ($this->addMember($form)) {
$form->sessionMessage(
_t('MemberProfiles.MEMBERADDED', 'The new member has been added.'),
'good'
);
}
return $this->redirectBack();
} | [
"public",
"function",
"doAdd",
"(",
"$",
"data",
",",
"$",
"form",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"addMember",
"(",
"$",
"form",
")",
")",
"{",
"$",
"form",
"->",
"sessionMessage",
"(",
"_t",
"(",
"'MemberProfiles.MEMBERADDED'",
",",
"'The new member has been added.'",
")",
",",
"'good'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirectBack",
"(",
")",
";",
"}"
]
| Saves an add member form submission into a new member object. | [
"Saves",
"an",
"add",
"member",
"form",
"submission",
"into",
"a",
"new",
"member",
"object",
"."
]
| 78afc584a1a3f5850f845943f23b233bf1898b81 | https://github.com/symbiote/silverstripe-memberprofiles/blob/78afc584a1a3f5850f845943f23b233bf1898b81/src/Pages/MemberProfilePageController.php#L341-L351 | train |
symbiote/silverstripe-memberprofiles | src/Pages/MemberProfilePageController.php | MemberProfilePageController.getSettableGroupIdsFrom | protected function getSettableGroupIdsFrom(Form $form, Member $member = null)
{
// first off check to see if groups were selected by the user. If so, we want
// to remove that control from the form list (just in case someone's sent through an
// ID for a group like, say, the admin's group...). It means we have to handle the setting
// ourselves, but that's okay
$groupField = $form->Fields()->dataFieldByName('Groups');
// The list of selectable groups
$groupIds = $allowedIds = $this->SelectableGroups()->map('ID', 'ID')->toArray();
// we need to track the selected groups against the existing user's groups - this is
// so that we don't accidentally remove them from the list of groups
// a user might have been placed in via other means
$existingIds = array();
if ($member) {
$existing = $member->Groups();
if ($existing && $existing->count() > 0) {
$existingIds = $existing->map('ID', 'ID')->toArray();
// remove any that are in the selectable groups map - we only want to
// worry about those that aren't managed by this form
foreach ($groupIds as $gid) {
unset($existingIds[$gid]);
}
}
}
if ($groupField) {
$givenIds = $groupField->Value();
$groupIds = array();
if ($givenIds) {
foreach ($givenIds as $givenId) {
if (isset($allowedIds[$givenId])) {
$groupIds[] = $givenId;
}
}
}
$form->Fields()->removeByName('Groups');
}
foreach ($this->Groups()->column('ID') as $mustId) {
$groupIds[] = $mustId;
}
foreach ($existingIds as $existingId) {
if (!in_array($existingId, $groupIds)) {
$groupIds[] = $existingId;
}
}
return $groupIds;
} | php | protected function getSettableGroupIdsFrom(Form $form, Member $member = null)
{
// first off check to see if groups were selected by the user. If so, we want
// to remove that control from the form list (just in case someone's sent through an
// ID for a group like, say, the admin's group...). It means we have to handle the setting
// ourselves, but that's okay
$groupField = $form->Fields()->dataFieldByName('Groups');
// The list of selectable groups
$groupIds = $allowedIds = $this->SelectableGroups()->map('ID', 'ID')->toArray();
// we need to track the selected groups against the existing user's groups - this is
// so that we don't accidentally remove them from the list of groups
// a user might have been placed in via other means
$existingIds = array();
if ($member) {
$existing = $member->Groups();
if ($existing && $existing->count() > 0) {
$existingIds = $existing->map('ID', 'ID')->toArray();
// remove any that are in the selectable groups map - we only want to
// worry about those that aren't managed by this form
foreach ($groupIds as $gid) {
unset($existingIds[$gid]);
}
}
}
if ($groupField) {
$givenIds = $groupField->Value();
$groupIds = array();
if ($givenIds) {
foreach ($givenIds as $givenId) {
if (isset($allowedIds[$givenId])) {
$groupIds[] = $givenId;
}
}
}
$form->Fields()->removeByName('Groups');
}
foreach ($this->Groups()->column('ID') as $mustId) {
$groupIds[] = $mustId;
}
foreach ($existingIds as $existingId) {
if (!in_array($existingId, $groupIds)) {
$groupIds[] = $existingId;
}
}
return $groupIds;
} | [
"protected",
"function",
"getSettableGroupIdsFrom",
"(",
"Form",
"$",
"form",
",",
"Member",
"$",
"member",
"=",
"null",
")",
"{",
"// first off check to see if groups were selected by the user. If so, we want",
"// to remove that control from the form list (just in case someone's sent through an",
"// ID for a group like, say, the admin's group...). It means we have to handle the setting",
"// ourselves, but that's okay",
"$",
"groupField",
"=",
"$",
"form",
"->",
"Fields",
"(",
")",
"->",
"dataFieldByName",
"(",
"'Groups'",
")",
";",
"// The list of selectable groups",
"$",
"groupIds",
"=",
"$",
"allowedIds",
"=",
"$",
"this",
"->",
"SelectableGroups",
"(",
")",
"->",
"map",
"(",
"'ID'",
",",
"'ID'",
")",
"->",
"toArray",
"(",
")",
";",
"// we need to track the selected groups against the existing user's groups - this is",
"// so that we don't accidentally remove them from the list of groups",
"// a user might have been placed in via other means",
"$",
"existingIds",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"member",
")",
"{",
"$",
"existing",
"=",
"$",
"member",
"->",
"Groups",
"(",
")",
";",
"if",
"(",
"$",
"existing",
"&&",
"$",
"existing",
"->",
"count",
"(",
")",
">",
"0",
")",
"{",
"$",
"existingIds",
"=",
"$",
"existing",
"->",
"map",
"(",
"'ID'",
",",
"'ID'",
")",
"->",
"toArray",
"(",
")",
";",
"// remove any that are in the selectable groups map - we only want to",
"// worry about those that aren't managed by this form",
"foreach",
"(",
"$",
"groupIds",
"as",
"$",
"gid",
")",
"{",
"unset",
"(",
"$",
"existingIds",
"[",
"$",
"gid",
"]",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"groupField",
")",
"{",
"$",
"givenIds",
"=",
"$",
"groupField",
"->",
"Value",
"(",
")",
";",
"$",
"groupIds",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"givenIds",
")",
"{",
"foreach",
"(",
"$",
"givenIds",
"as",
"$",
"givenId",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"allowedIds",
"[",
"$",
"givenId",
"]",
")",
")",
"{",
"$",
"groupIds",
"[",
"]",
"=",
"$",
"givenId",
";",
"}",
"}",
"}",
"$",
"form",
"->",
"Fields",
"(",
")",
"->",
"removeByName",
"(",
"'Groups'",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"Groups",
"(",
")",
"->",
"column",
"(",
"'ID'",
")",
"as",
"$",
"mustId",
")",
"{",
"$",
"groupIds",
"[",
"]",
"=",
"$",
"mustId",
";",
"}",
"foreach",
"(",
"$",
"existingIds",
"as",
"$",
"existingId",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"existingId",
",",
"$",
"groupIds",
")",
")",
"{",
"$",
"groupIds",
"[",
"]",
"=",
"$",
"existingId",
";",
"}",
"}",
"return",
"$",
"groupIds",
";",
"}"
]
| Gets the list of groups that can be set after the submission of a particular form
This works around the problem with the checkboxsetfield which doesn't validate that the
groups that the user has selected are not validated against the list of groups the user is
allowed to choose from.
@param Form $form
@param Member $member | [
"Gets",
"the",
"list",
"of",
"groups",
"that",
"can",
"be",
"set",
"after",
"the",
"submission",
"of",
"a",
"particular",
"form"
]
| 78afc584a1a3f5850f845943f23b233bf1898b81 | https://github.com/symbiote/silverstripe-memberprofiles/blob/78afc584a1a3f5850f845943f23b233bf1898b81/src/Pages/MemberProfilePageController.php#L373-L423 | train |
symbiote/silverstripe-memberprofiles | src/Pages/MemberProfilePageController.php | MemberProfilePageController.confirm | public function confirm(HTTPRequest $request)
{
if ($this->EmailType !== 'Confirmation' &&
$this->EmailType !== 'Validation') {
return $this->httpError(400, 'No confirmation required.');
}
$currentMember = Member::currentUser();
$id = (int)$request->param('ID');
$key = $request->getVar('key');
if ($currentMember) {
if ($currentMember->ID == $id) {
return Security::permissionFailure($this, _t(
'MemberProfiles.ALREADYCONFIRMED',
'Your account is already confirmed.'
));
}
return Security::permissionFailure($this, _t(
'MemberProfiles.CANNOTCONFIRMLOGGEDIN',
'You cannot confirm account while you are logged in.'
));
}
if (!$id ||
!$key) {
return $this->httpError(404);
}
$confirmationTitle = $this->data()->dbObject('ConfirmationTitle');
/**
* @var Member|null $member
*/
$member = DataObject::get_by_id(Member::class, $id);
if (!$member) {
return $this->invalidRequest('Member #'.$id.' does not exist.');
}
if (!$member->NeedsValidation) {
// NOTE(Jake): 2018-05-03
//
// You might be hitting this if you set your MemberProfilePage to use
// Email Setting 'Confirmation' rather than 'Validation' and you didn't
// edit the original Email template to not include the copy about confirmation.
//
return $this->invalidRequest('Member #'.$id.' does not need validation.');
}
if (!$member->ValidationKey) {
return $this->invalidRequest('Member #'.$id.' does not have a validation key.');
}
if ($member->ValidationKey !== $key) {
return $this->invalidRequest('Validation key does not match.');
}
// Allow member to login
$member->NeedsValidation = false;
$member->ValidationKey = null;
$validationResult = $member->validateCanLogin();
if (!$validationResult->isValid()) {
$this->getResponse()->setStatusCode(500);
$validationMessages = $validationResult->getMessages();
return [
'Title' => $confirmationTitle,
'Content' => $validationMessages ? $validationMessages[0]['message'] : _t('MemberProfiles.ERRORCONFIRMATION', 'An unexpected error occurred.'),
];
}
$member->write();
$this->extend('onConfirm', $member);
if ($member->canLogin()) {
Injector::inst()->get(IdentityStore::class)->logIn($member);
} else {
throw new Exception('Permission issue occurred. Was the "$member->validateCanLogin" check above this code block removed?');
}
return [
'Title' => $this->data()->dbObject('ConfirmationTitle'),
'Content' => $this->data()->dbObject('ConfirmationContent')
];
} | php | public function confirm(HTTPRequest $request)
{
if ($this->EmailType !== 'Confirmation' &&
$this->EmailType !== 'Validation') {
return $this->httpError(400, 'No confirmation required.');
}
$currentMember = Member::currentUser();
$id = (int)$request->param('ID');
$key = $request->getVar('key');
if ($currentMember) {
if ($currentMember->ID == $id) {
return Security::permissionFailure($this, _t(
'MemberProfiles.ALREADYCONFIRMED',
'Your account is already confirmed.'
));
}
return Security::permissionFailure($this, _t(
'MemberProfiles.CANNOTCONFIRMLOGGEDIN',
'You cannot confirm account while you are logged in.'
));
}
if (!$id ||
!$key) {
return $this->httpError(404);
}
$confirmationTitle = $this->data()->dbObject('ConfirmationTitle');
/**
* @var Member|null $member
*/
$member = DataObject::get_by_id(Member::class, $id);
if (!$member) {
return $this->invalidRequest('Member #'.$id.' does not exist.');
}
if (!$member->NeedsValidation) {
// NOTE(Jake): 2018-05-03
//
// You might be hitting this if you set your MemberProfilePage to use
// Email Setting 'Confirmation' rather than 'Validation' and you didn't
// edit the original Email template to not include the copy about confirmation.
//
return $this->invalidRequest('Member #'.$id.' does not need validation.');
}
if (!$member->ValidationKey) {
return $this->invalidRequest('Member #'.$id.' does not have a validation key.');
}
if ($member->ValidationKey !== $key) {
return $this->invalidRequest('Validation key does not match.');
}
// Allow member to login
$member->NeedsValidation = false;
$member->ValidationKey = null;
$validationResult = $member->validateCanLogin();
if (!$validationResult->isValid()) {
$this->getResponse()->setStatusCode(500);
$validationMessages = $validationResult->getMessages();
return [
'Title' => $confirmationTitle,
'Content' => $validationMessages ? $validationMessages[0]['message'] : _t('MemberProfiles.ERRORCONFIRMATION', 'An unexpected error occurred.'),
];
}
$member->write();
$this->extend('onConfirm', $member);
if ($member->canLogin()) {
Injector::inst()->get(IdentityStore::class)->logIn($member);
} else {
throw new Exception('Permission issue occurred. Was the "$member->validateCanLogin" check above this code block removed?');
}
return [
'Title' => $this->data()->dbObject('ConfirmationTitle'),
'Content' => $this->data()->dbObject('ConfirmationContent')
];
} | [
"public",
"function",
"confirm",
"(",
"HTTPRequest",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"EmailType",
"!==",
"'Confirmation'",
"&&",
"$",
"this",
"->",
"EmailType",
"!==",
"'Validation'",
")",
"{",
"return",
"$",
"this",
"->",
"httpError",
"(",
"400",
",",
"'No confirmation required.'",
")",
";",
"}",
"$",
"currentMember",
"=",
"Member",
"::",
"currentUser",
"(",
")",
";",
"$",
"id",
"=",
"(",
"int",
")",
"$",
"request",
"->",
"param",
"(",
"'ID'",
")",
";",
"$",
"key",
"=",
"$",
"request",
"->",
"getVar",
"(",
"'key'",
")",
";",
"if",
"(",
"$",
"currentMember",
")",
"{",
"if",
"(",
"$",
"currentMember",
"->",
"ID",
"==",
"$",
"id",
")",
"{",
"return",
"Security",
"::",
"permissionFailure",
"(",
"$",
"this",
",",
"_t",
"(",
"'MemberProfiles.ALREADYCONFIRMED'",
",",
"'Your account is already confirmed.'",
")",
")",
";",
"}",
"return",
"Security",
"::",
"permissionFailure",
"(",
"$",
"this",
",",
"_t",
"(",
"'MemberProfiles.CANNOTCONFIRMLOGGEDIN'",
",",
"'You cannot confirm account while you are logged in.'",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"id",
"||",
"!",
"$",
"key",
")",
"{",
"return",
"$",
"this",
"->",
"httpError",
"(",
"404",
")",
";",
"}",
"$",
"confirmationTitle",
"=",
"$",
"this",
"->",
"data",
"(",
")",
"->",
"dbObject",
"(",
"'ConfirmationTitle'",
")",
";",
"/**\n * @var Member|null $member\n */",
"$",
"member",
"=",
"DataObject",
"::",
"get_by_id",
"(",
"Member",
"::",
"class",
",",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"member",
")",
"{",
"return",
"$",
"this",
"->",
"invalidRequest",
"(",
"'Member #'",
".",
"$",
"id",
".",
"' does not exist.'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"member",
"->",
"NeedsValidation",
")",
"{",
"// NOTE(Jake): 2018-05-03",
"//",
"// You might be hitting this if you set your MemberProfilePage to use",
"// Email Setting 'Confirmation' rather than 'Validation' and you didn't",
"// edit the original Email template to not include the copy about confirmation.",
"//",
"return",
"$",
"this",
"->",
"invalidRequest",
"(",
"'Member #'",
".",
"$",
"id",
".",
"' does not need validation.'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"member",
"->",
"ValidationKey",
")",
"{",
"return",
"$",
"this",
"->",
"invalidRequest",
"(",
"'Member #'",
".",
"$",
"id",
".",
"' does not have a validation key.'",
")",
";",
"}",
"if",
"(",
"$",
"member",
"->",
"ValidationKey",
"!==",
"$",
"key",
")",
"{",
"return",
"$",
"this",
"->",
"invalidRequest",
"(",
"'Validation key does not match.'",
")",
";",
"}",
"// Allow member to login",
"$",
"member",
"->",
"NeedsValidation",
"=",
"false",
";",
"$",
"member",
"->",
"ValidationKey",
"=",
"null",
";",
"$",
"validationResult",
"=",
"$",
"member",
"->",
"validateCanLogin",
"(",
")",
";",
"if",
"(",
"!",
"$",
"validationResult",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getResponse",
"(",
")",
"->",
"setStatusCode",
"(",
"500",
")",
";",
"$",
"validationMessages",
"=",
"$",
"validationResult",
"->",
"getMessages",
"(",
")",
";",
"return",
"[",
"'Title'",
"=>",
"$",
"confirmationTitle",
",",
"'Content'",
"=>",
"$",
"validationMessages",
"?",
"$",
"validationMessages",
"[",
"0",
"]",
"[",
"'message'",
"]",
":",
"_t",
"(",
"'MemberProfiles.ERRORCONFIRMATION'",
",",
"'An unexpected error occurred.'",
")",
",",
"]",
";",
"}",
"$",
"member",
"->",
"write",
"(",
")",
";",
"$",
"this",
"->",
"extend",
"(",
"'onConfirm'",
",",
"$",
"member",
")",
";",
"if",
"(",
"$",
"member",
"->",
"canLogin",
"(",
")",
")",
"{",
"Injector",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"IdentityStore",
"::",
"class",
")",
"->",
"logIn",
"(",
"$",
"member",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'Permission issue occurred. Was the \"$member->validateCanLogin\" check above this code block removed?'",
")",
";",
"}",
"return",
"[",
"'Title'",
"=>",
"$",
"this",
"->",
"data",
"(",
")",
"->",
"dbObject",
"(",
"'ConfirmationTitle'",
")",
",",
"'Content'",
"=>",
"$",
"this",
"->",
"data",
"(",
")",
"->",
"dbObject",
"(",
"'ConfirmationContent'",
")",
"]",
";",
"}"
]
| Allows the user to confirm their account by clicking on the validation link in
the confirmation email.
@param HTTPRequest $request
@return array|HTTPResponse | [
"Allows",
"the",
"user",
"to",
"confirm",
"their",
"account",
"by",
"clicking",
"on",
"the",
"validation",
"link",
"in",
"the",
"confirmation",
"email",
"."
]
| 78afc584a1a3f5850f845943f23b233bf1898b81 | https://github.com/symbiote/silverstripe-memberprofiles/blob/78afc584a1a3f5850f845943f23b233bf1898b81/src/Pages/MemberProfilePageController.php#L432-L513 | train |
symbiote/silverstripe-memberprofiles | src/Pages/MemberProfilePageController.php | MemberProfilePageController.addMember | protected function addMember($form)
{
$member = new Member();
$groupIds = $this->getSettableGroupIdsFrom($form);
$form->saveInto($member);
$member->ProfilePageID = $this->ID;
$member->NeedsValidation = ($this->EmailType === 'Validation');
$member->NeedsApproval = $this->RequireApproval;
try {
$member->write();
} catch (ValidationException $e) {
$validationMessages = implode("; ", $e->getResult()->getMessages());
$form->sessionMessage($validationMessages, 'bad');
return null;
}
// set after member is created otherwise the member object does not exist
$member->Groups()->setByIDList($groupIds);
// If we require admin approval, send an email to the admin and delay
// sending an email to the member.
if ($this->RequireApproval) {
$groups = $this->ApprovalGroups();
if (!$groups ||
$groups->count() == 0) {
// If nothing is configured, fallback to ADMIN
$groups = Permission::get_groups_by_permission('ADMIN');
}
$emails = [];
if ($groups) {
foreach ($groups as $group) {
foreach ($group->Members() as $_member) {
if ($_member->Email) {
$emails[] = $_member->Email;
}
}
}
}
if ($emails) {
$emails = array_unique($emails);
$mail = Email::create();
$config = SiteConfig::current_site_config();
$approve = Controller::join_links(
Director::baseURL(),
'member-approval',
$member->ID,
'?token=' . $member->ValidationKey
);
$mail->setSubject("Registration Approval Requested for $config->Title");
foreach ($emails as $email) {
if (!Email::is_valid_address($email)) {
// Ignore invalid email addresses or else we'll get validation errors.
// ie. default 'admin' account
continue;
}
$mail->addBCC($email);
}
$mail->setHTMLTemplate('Symbiote\\MemberProfiles\\Email\\MemberRequiresApprovalEmail');
$mail->setData(array(
'SiteConfig' => $config,
'Member' => $member,
'ApproveLink' => Director::absoluteURL($approve)
));
$mail->send();
}
} else {
// NOTE(Jake): 2018-05-03
//
// Only send the confirmation email immediately after registering if they
// don't require admin approval.
//
switch ($this->EmailType) {
case 'None':
// Does not require anything
break;
case 'Confirmation':
case 'Validation':
// Must activate themselves via the confirmation email
$email = MemberConfirmationEmail::create($this->data(), $member);
$email->send();
break;
}
}
$this->extend('onAddMember', $member);
return $member;
} | php | protected function addMember($form)
{
$member = new Member();
$groupIds = $this->getSettableGroupIdsFrom($form);
$form->saveInto($member);
$member->ProfilePageID = $this->ID;
$member->NeedsValidation = ($this->EmailType === 'Validation');
$member->NeedsApproval = $this->RequireApproval;
try {
$member->write();
} catch (ValidationException $e) {
$validationMessages = implode("; ", $e->getResult()->getMessages());
$form->sessionMessage($validationMessages, 'bad');
return null;
}
// set after member is created otherwise the member object does not exist
$member->Groups()->setByIDList($groupIds);
// If we require admin approval, send an email to the admin and delay
// sending an email to the member.
if ($this->RequireApproval) {
$groups = $this->ApprovalGroups();
if (!$groups ||
$groups->count() == 0) {
// If nothing is configured, fallback to ADMIN
$groups = Permission::get_groups_by_permission('ADMIN');
}
$emails = [];
if ($groups) {
foreach ($groups as $group) {
foreach ($group->Members() as $_member) {
if ($_member->Email) {
$emails[] = $_member->Email;
}
}
}
}
if ($emails) {
$emails = array_unique($emails);
$mail = Email::create();
$config = SiteConfig::current_site_config();
$approve = Controller::join_links(
Director::baseURL(),
'member-approval',
$member->ID,
'?token=' . $member->ValidationKey
);
$mail->setSubject("Registration Approval Requested for $config->Title");
foreach ($emails as $email) {
if (!Email::is_valid_address($email)) {
// Ignore invalid email addresses or else we'll get validation errors.
// ie. default 'admin' account
continue;
}
$mail->addBCC($email);
}
$mail->setHTMLTemplate('Symbiote\\MemberProfiles\\Email\\MemberRequiresApprovalEmail');
$mail->setData(array(
'SiteConfig' => $config,
'Member' => $member,
'ApproveLink' => Director::absoluteURL($approve)
));
$mail->send();
}
} else {
// NOTE(Jake): 2018-05-03
//
// Only send the confirmation email immediately after registering if they
// don't require admin approval.
//
switch ($this->EmailType) {
case 'None':
// Does not require anything
break;
case 'Confirmation':
case 'Validation':
// Must activate themselves via the confirmation email
$email = MemberConfirmationEmail::create($this->data(), $member);
$email->send();
break;
}
}
$this->extend('onAddMember', $member);
return $member;
} | [
"protected",
"function",
"addMember",
"(",
"$",
"form",
")",
"{",
"$",
"member",
"=",
"new",
"Member",
"(",
")",
";",
"$",
"groupIds",
"=",
"$",
"this",
"->",
"getSettableGroupIdsFrom",
"(",
"$",
"form",
")",
";",
"$",
"form",
"->",
"saveInto",
"(",
"$",
"member",
")",
";",
"$",
"member",
"->",
"ProfilePageID",
"=",
"$",
"this",
"->",
"ID",
";",
"$",
"member",
"->",
"NeedsValidation",
"=",
"(",
"$",
"this",
"->",
"EmailType",
"===",
"'Validation'",
")",
";",
"$",
"member",
"->",
"NeedsApproval",
"=",
"$",
"this",
"->",
"RequireApproval",
";",
"try",
"{",
"$",
"member",
"->",
"write",
"(",
")",
";",
"}",
"catch",
"(",
"ValidationException",
"$",
"e",
")",
"{",
"$",
"validationMessages",
"=",
"implode",
"(",
"\"; \"",
",",
"$",
"e",
"->",
"getResult",
"(",
")",
"->",
"getMessages",
"(",
")",
")",
";",
"$",
"form",
"->",
"sessionMessage",
"(",
"$",
"validationMessages",
",",
"'bad'",
")",
";",
"return",
"null",
";",
"}",
"// set after member is created otherwise the member object does not exist",
"$",
"member",
"->",
"Groups",
"(",
")",
"->",
"setByIDList",
"(",
"$",
"groupIds",
")",
";",
"// If we require admin approval, send an email to the admin and delay",
"// sending an email to the member.",
"if",
"(",
"$",
"this",
"->",
"RequireApproval",
")",
"{",
"$",
"groups",
"=",
"$",
"this",
"->",
"ApprovalGroups",
"(",
")",
";",
"if",
"(",
"!",
"$",
"groups",
"||",
"$",
"groups",
"->",
"count",
"(",
")",
"==",
"0",
")",
"{",
"// If nothing is configured, fallback to ADMIN",
"$",
"groups",
"=",
"Permission",
"::",
"get_groups_by_permission",
"(",
"'ADMIN'",
")",
";",
"}",
"$",
"emails",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"groups",
")",
"{",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"group",
")",
"{",
"foreach",
"(",
"$",
"group",
"->",
"Members",
"(",
")",
"as",
"$",
"_member",
")",
"{",
"if",
"(",
"$",
"_member",
"->",
"Email",
")",
"{",
"$",
"emails",
"[",
"]",
"=",
"$",
"_member",
"->",
"Email",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"$",
"emails",
")",
"{",
"$",
"emails",
"=",
"array_unique",
"(",
"$",
"emails",
")",
";",
"$",
"mail",
"=",
"Email",
"::",
"create",
"(",
")",
";",
"$",
"config",
"=",
"SiteConfig",
"::",
"current_site_config",
"(",
")",
";",
"$",
"approve",
"=",
"Controller",
"::",
"join_links",
"(",
"Director",
"::",
"baseURL",
"(",
")",
",",
"'member-approval'",
",",
"$",
"member",
"->",
"ID",
",",
"'?token='",
".",
"$",
"member",
"->",
"ValidationKey",
")",
";",
"$",
"mail",
"->",
"setSubject",
"(",
"\"Registration Approval Requested for $config->Title\"",
")",
";",
"foreach",
"(",
"$",
"emails",
"as",
"$",
"email",
")",
"{",
"if",
"(",
"!",
"Email",
"::",
"is_valid_address",
"(",
"$",
"email",
")",
")",
"{",
"// Ignore invalid email addresses or else we'll get validation errors.",
"// ie. default 'admin' account",
"continue",
";",
"}",
"$",
"mail",
"->",
"addBCC",
"(",
"$",
"email",
")",
";",
"}",
"$",
"mail",
"->",
"setHTMLTemplate",
"(",
"'Symbiote\\\\MemberProfiles\\\\Email\\\\MemberRequiresApprovalEmail'",
")",
";",
"$",
"mail",
"->",
"setData",
"(",
"array",
"(",
"'SiteConfig'",
"=>",
"$",
"config",
",",
"'Member'",
"=>",
"$",
"member",
",",
"'ApproveLink'",
"=>",
"Director",
"::",
"absoluteURL",
"(",
"$",
"approve",
")",
")",
")",
";",
"$",
"mail",
"->",
"send",
"(",
")",
";",
"}",
"}",
"else",
"{",
"// NOTE(Jake): 2018-05-03",
"//",
"// Only send the confirmation email immediately after registering if they",
"// don't require admin approval.",
"//",
"switch",
"(",
"$",
"this",
"->",
"EmailType",
")",
"{",
"case",
"'None'",
":",
"// Does not require anything",
"break",
";",
"case",
"'Confirmation'",
":",
"case",
"'Validation'",
":",
"// Must activate themselves via the confirmation email",
"$",
"email",
"=",
"MemberConfirmationEmail",
"::",
"create",
"(",
"$",
"this",
"->",
"data",
"(",
")",
",",
"$",
"member",
")",
";",
"$",
"email",
"->",
"send",
"(",
")",
";",
"break",
";",
"}",
"}",
"$",
"this",
"->",
"extend",
"(",
"'onAddMember'",
",",
"$",
"member",
")",
";",
"return",
"$",
"member",
";",
"}"
]
| Attempts to save either a registration or add member form submission
into a new member object, returning NULL on validation failure.
@return Member|null | [
"Attempts",
"to",
"save",
"either",
"a",
"registration",
"or",
"add",
"member",
"form",
"submission",
"into",
"a",
"new",
"member",
"object",
"returning",
"NULL",
"on",
"validation",
"failure",
"."
]
| 78afc584a1a3f5850f845943f23b233bf1898b81 | https://github.com/symbiote/silverstripe-memberprofiles/blob/78afc584a1a3f5850f845943f23b233bf1898b81/src/Pages/MemberProfilePageController.php#L546-L641 | train |
symbiote/silverstripe-memberprofiles | src/Extensions/MemberProfileExtension.php | MemberProfileExtension.saveManualEmailValidation | public function saveManualEmailValidation($value)
{
if ($value === 'confirm') {
$this->owner->NeedsValidation = false;
} elseif ($value === 'resend') {
$email = MemberConfirmationEmail::create($this->owner->ProfilePage(), $this->owner);
$email->send();
}
} | php | public function saveManualEmailValidation($value)
{
if ($value === 'confirm') {
$this->owner->NeedsValidation = false;
} elseif ($value === 'resend') {
$email = MemberConfirmationEmail::create($this->owner->ProfilePage(), $this->owner);
$email->send();
}
} | [
"public",
"function",
"saveManualEmailValidation",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"'confirm'",
")",
"{",
"$",
"this",
"->",
"owner",
"->",
"NeedsValidation",
"=",
"false",
";",
"}",
"elseif",
"(",
"$",
"value",
"===",
"'resend'",
")",
"{",
"$",
"email",
"=",
"MemberConfirmationEmail",
"::",
"create",
"(",
"$",
"this",
"->",
"owner",
"->",
"ProfilePage",
"(",
")",
",",
"$",
"this",
"->",
"owner",
")",
";",
"$",
"email",
"->",
"send",
"(",
")",
";",
"}",
"}"
]
| Allows admin users to manually confirm a user. | [
"Allows",
"admin",
"users",
"to",
"manually",
"confirm",
"a",
"user",
"."
]
| 78afc584a1a3f5850f845943f23b233bf1898b81 | https://github.com/symbiote/silverstripe-memberprofiles/blob/78afc584a1a3f5850f845943f23b233bf1898b81/src/Extensions/MemberProfileExtension.php#L64-L72 | train |
symbiote/silverstripe-memberprofiles | src/Pages/MemberProfileViewer.php | MemberProfileViewer.handleList | public function handleList($request)
{
$parent = $this->getParent();
$fields = $parent->Fields()->filter('MemberListVisible', true);
$groups = $parent->Groups();
if ($groups->count() > 0) {
$members = $groups->relation('Members');
} else {
$members = Member::get();
// NOTE(Jake): 2018-05-02
//
// We may want to enable a flag so that ADMIN users are automatically omitted from this list
// by default.
//
//$members = $members->filter('ID:not', Permission::get_members_by_permission('ADMIN')->map('ID', 'ID')->toArray());
}
$members = PaginatedList::create($members, $request);
$list = new ArrayList();
foreach ($members as $member) {
$cols = new ArrayList();
$public = $member->getPublicFields();
$link = $this->Link($member->ID);
foreach ($fields as $field) {
if ($field->PublicVisibility == 'MemberChoice'
&& !in_array($field->MemberField, $public)
) {
$value = null;
} else {
$value = $member->{$field->MemberField};
}
$cols->push(new ArrayData(array(
'Name' => $field->MemberField,
'Title' => $field->Title,
'Value' => $value,
'Sortable' => $member->hasDatabaseField($field->MemberField),
'Link' => $link
)));
}
$list->push($member->customise(array(
'Fields' => $cols
)));
}
$list = PaginatedList::create($list, $request);
$list->setLimitItems(false);
$list->setTotalItems($members->getTotalItems());
$this->data()->Title = _t('MemberProfiles.MEMBERLIST', 'Member List');
$this->data()->Parent = $this->getParent();
$controller = $this->customise(array(
'Type' => 'List',
'Members' => $list
));
return $controller;
} | php | public function handleList($request)
{
$parent = $this->getParent();
$fields = $parent->Fields()->filter('MemberListVisible', true);
$groups = $parent->Groups();
if ($groups->count() > 0) {
$members = $groups->relation('Members');
} else {
$members = Member::get();
// NOTE(Jake): 2018-05-02
//
// We may want to enable a flag so that ADMIN users are automatically omitted from this list
// by default.
//
//$members = $members->filter('ID:not', Permission::get_members_by_permission('ADMIN')->map('ID', 'ID')->toArray());
}
$members = PaginatedList::create($members, $request);
$list = new ArrayList();
foreach ($members as $member) {
$cols = new ArrayList();
$public = $member->getPublicFields();
$link = $this->Link($member->ID);
foreach ($fields as $field) {
if ($field->PublicVisibility == 'MemberChoice'
&& !in_array($field->MemberField, $public)
) {
$value = null;
} else {
$value = $member->{$field->MemberField};
}
$cols->push(new ArrayData(array(
'Name' => $field->MemberField,
'Title' => $field->Title,
'Value' => $value,
'Sortable' => $member->hasDatabaseField($field->MemberField),
'Link' => $link
)));
}
$list->push($member->customise(array(
'Fields' => $cols
)));
}
$list = PaginatedList::create($list, $request);
$list->setLimitItems(false);
$list->setTotalItems($members->getTotalItems());
$this->data()->Title = _t('MemberProfiles.MEMBERLIST', 'Member List');
$this->data()->Parent = $this->getParent();
$controller = $this->customise(array(
'Type' => 'List',
'Members' => $list
));
return $controller;
} | [
"public",
"function",
"handleList",
"(",
"$",
"request",
")",
"{",
"$",
"parent",
"=",
"$",
"this",
"->",
"getParent",
"(",
")",
";",
"$",
"fields",
"=",
"$",
"parent",
"->",
"Fields",
"(",
")",
"->",
"filter",
"(",
"'MemberListVisible'",
",",
"true",
")",
";",
"$",
"groups",
"=",
"$",
"parent",
"->",
"Groups",
"(",
")",
";",
"if",
"(",
"$",
"groups",
"->",
"count",
"(",
")",
">",
"0",
")",
"{",
"$",
"members",
"=",
"$",
"groups",
"->",
"relation",
"(",
"'Members'",
")",
";",
"}",
"else",
"{",
"$",
"members",
"=",
"Member",
"::",
"get",
"(",
")",
";",
"// NOTE(Jake): 2018-05-02",
"//",
"// We may want to enable a flag so that ADMIN users are automatically omitted from this list",
"// by default.",
"//",
"//$members = $members->filter('ID:not', Permission::get_members_by_permission('ADMIN')->map('ID', 'ID')->toArray());",
"}",
"$",
"members",
"=",
"PaginatedList",
"::",
"create",
"(",
"$",
"members",
",",
"$",
"request",
")",
";",
"$",
"list",
"=",
"new",
"ArrayList",
"(",
")",
";",
"foreach",
"(",
"$",
"members",
"as",
"$",
"member",
")",
"{",
"$",
"cols",
"=",
"new",
"ArrayList",
"(",
")",
";",
"$",
"public",
"=",
"$",
"member",
"->",
"getPublicFields",
"(",
")",
";",
"$",
"link",
"=",
"$",
"this",
"->",
"Link",
"(",
"$",
"member",
"->",
"ID",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"->",
"PublicVisibility",
"==",
"'MemberChoice'",
"&&",
"!",
"in_array",
"(",
"$",
"field",
"->",
"MemberField",
",",
"$",
"public",
")",
")",
"{",
"$",
"value",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"member",
"->",
"{",
"$",
"field",
"->",
"MemberField",
"}",
";",
"}",
"$",
"cols",
"->",
"push",
"(",
"new",
"ArrayData",
"(",
"array",
"(",
"'Name'",
"=>",
"$",
"field",
"->",
"MemberField",
",",
"'Title'",
"=>",
"$",
"field",
"->",
"Title",
",",
"'Value'",
"=>",
"$",
"value",
",",
"'Sortable'",
"=>",
"$",
"member",
"->",
"hasDatabaseField",
"(",
"$",
"field",
"->",
"MemberField",
")",
",",
"'Link'",
"=>",
"$",
"link",
")",
")",
")",
";",
"}",
"$",
"list",
"->",
"push",
"(",
"$",
"member",
"->",
"customise",
"(",
"array",
"(",
"'Fields'",
"=>",
"$",
"cols",
")",
")",
")",
";",
"}",
"$",
"list",
"=",
"PaginatedList",
"::",
"create",
"(",
"$",
"list",
",",
"$",
"request",
")",
";",
"$",
"list",
"->",
"setLimitItems",
"(",
"false",
")",
";",
"$",
"list",
"->",
"setTotalItems",
"(",
"$",
"members",
"->",
"getTotalItems",
"(",
")",
")",
";",
"$",
"this",
"->",
"data",
"(",
")",
"->",
"Title",
"=",
"_t",
"(",
"'MemberProfiles.MEMBERLIST'",
",",
"'Member List'",
")",
";",
"$",
"this",
"->",
"data",
"(",
")",
"->",
"Parent",
"=",
"$",
"this",
"->",
"getParent",
"(",
")",
";",
"$",
"controller",
"=",
"$",
"this",
"->",
"customise",
"(",
"array",
"(",
"'Type'",
"=>",
"'List'",
",",
"'Members'",
"=>",
"$",
"list",
")",
")",
";",
"return",
"$",
"controller",
";",
"}"
]
| Displays a list of all members on the site that belong to the selected
groups.
@return ViewableData | [
"Displays",
"a",
"list",
"of",
"all",
"members",
"on",
"the",
"site",
"that",
"belong",
"to",
"the",
"selected",
"groups",
"."
]
| 78afc584a1a3f5850f845943f23b233bf1898b81 | https://github.com/symbiote/silverstripe-memberprofiles/blob/78afc584a1a3f5850f845943f23b233bf1898b81/src/Pages/MemberProfileViewer.php#L63-L123 | train |
symbiote/silverstripe-memberprofiles | src/Pages/MemberProfileViewer.php | MemberProfileViewer.handleView | public function handleView($request)
{
$id = $request->param('MemberID');
if (!ctype_digit($id)) {
$this->httpError(404);
}
/**
* @var Member $member
*/
$member = Member::get()->byID($id);
$groups = $this->getParent()->Groups();
if ($groups->count() > 0 && !$member->inGroups($groups)) {
$this->httpError(403);
}
$sections = $this->getParent()->Sections();
$sectionsList = new ArrayList();
foreach ($sections as $section) {
$sectionsList->push($section);
$section->setMember($member);
}
$this->data()->Title = sprintf(
_t('MemberProfiles.MEMBERPROFILETITLE', "%s's Profile"),
$member->getName()
);
$this->data()->Parent = $this->getParent();
$controller = $this->customise(array(
'Type' => 'View',
'Member' => $member,
'Sections' => $sectionsList,
'IsSelf' => $member->ID == Member::currentUserID()
));
return $controller;
} | php | public function handleView($request)
{
$id = $request->param('MemberID');
if (!ctype_digit($id)) {
$this->httpError(404);
}
/**
* @var Member $member
*/
$member = Member::get()->byID($id);
$groups = $this->getParent()->Groups();
if ($groups->count() > 0 && !$member->inGroups($groups)) {
$this->httpError(403);
}
$sections = $this->getParent()->Sections();
$sectionsList = new ArrayList();
foreach ($sections as $section) {
$sectionsList->push($section);
$section->setMember($member);
}
$this->data()->Title = sprintf(
_t('MemberProfiles.MEMBERPROFILETITLE', "%s's Profile"),
$member->getName()
);
$this->data()->Parent = $this->getParent();
$controller = $this->customise(array(
'Type' => 'View',
'Member' => $member,
'Sections' => $sectionsList,
'IsSelf' => $member->ID == Member::currentUserID()
));
return $controller;
} | [
"public",
"function",
"handleView",
"(",
"$",
"request",
")",
"{",
"$",
"id",
"=",
"$",
"request",
"->",
"param",
"(",
"'MemberID'",
")",
";",
"if",
"(",
"!",
"ctype_digit",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"httpError",
"(",
"404",
")",
";",
"}",
"/**\n * @var Member $member\n */",
"$",
"member",
"=",
"Member",
"::",
"get",
"(",
")",
"->",
"byID",
"(",
"$",
"id",
")",
";",
"$",
"groups",
"=",
"$",
"this",
"->",
"getParent",
"(",
")",
"->",
"Groups",
"(",
")",
";",
"if",
"(",
"$",
"groups",
"->",
"count",
"(",
")",
">",
"0",
"&&",
"!",
"$",
"member",
"->",
"inGroups",
"(",
"$",
"groups",
")",
")",
"{",
"$",
"this",
"->",
"httpError",
"(",
"403",
")",
";",
"}",
"$",
"sections",
"=",
"$",
"this",
"->",
"getParent",
"(",
")",
"->",
"Sections",
"(",
")",
";",
"$",
"sectionsList",
"=",
"new",
"ArrayList",
"(",
")",
";",
"foreach",
"(",
"$",
"sections",
"as",
"$",
"section",
")",
"{",
"$",
"sectionsList",
"->",
"push",
"(",
"$",
"section",
")",
";",
"$",
"section",
"->",
"setMember",
"(",
"$",
"member",
")",
";",
"}",
"$",
"this",
"->",
"data",
"(",
")",
"->",
"Title",
"=",
"sprintf",
"(",
"_t",
"(",
"'MemberProfiles.MEMBERPROFILETITLE'",
",",
"\"%s's Profile\"",
")",
",",
"$",
"member",
"->",
"getName",
"(",
")",
")",
";",
"$",
"this",
"->",
"data",
"(",
")",
"->",
"Parent",
"=",
"$",
"this",
"->",
"getParent",
"(",
")",
";",
"$",
"controller",
"=",
"$",
"this",
"->",
"customise",
"(",
"array",
"(",
"'Type'",
"=>",
"'View'",
",",
"'Member'",
"=>",
"$",
"member",
",",
"'Sections'",
"=>",
"$",
"sectionsList",
",",
"'IsSelf'",
"=>",
"$",
"member",
"->",
"ID",
"==",
"Member",
"::",
"currentUserID",
"(",
")",
")",
")",
";",
"return",
"$",
"controller",
";",
"}"
]
| Handles viewing an individual user's profile.
@return \SilverStripe\View\ViewableData_Customised | [
"Handles",
"viewing",
"an",
"individual",
"user",
"s",
"profile",
"."
]
| 78afc584a1a3f5850f845943f23b233bf1898b81 | https://github.com/symbiote/silverstripe-memberprofiles/blob/78afc584a1a3f5850f845943f23b233bf1898b81/src/Pages/MemberProfileViewer.php#L130-L170 | train |
symbiote/silverstripe-memberprofiles | src/Model/MemberProfileField.php | MemberProfileField.getDefaultTitle | public function getDefaultTitle($force = true)
{
$fields = $this->getMemberFields();
$field = $fields->dataFieldByName($this->MemberField);
$title = $field->Title();
if (!$title && $force) {
$title = $field->getName();
}
return $title;
} | php | public function getDefaultTitle($force = true)
{
$fields = $this->getMemberFields();
$field = $fields->dataFieldByName($this->MemberField);
$title = $field->Title();
if (!$title && $force) {
$title = $field->getName();
}
return $title;
} | [
"public",
"function",
"getDefaultTitle",
"(",
"$",
"force",
"=",
"true",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"getMemberFields",
"(",
")",
";",
"$",
"field",
"=",
"$",
"fields",
"->",
"dataFieldByName",
"(",
"$",
"this",
"->",
"MemberField",
")",
";",
"$",
"title",
"=",
"$",
"field",
"->",
"Title",
"(",
")",
";",
"if",
"(",
"!",
"$",
"title",
"&&",
"$",
"force",
")",
"{",
"$",
"title",
"=",
"$",
"field",
"->",
"getName",
"(",
")",
";",
"}",
"return",
"$",
"title",
";",
"}"
]
| Get the default title for this field from the form field.
@param bool $force Force a non-empty title to be returned.
@return string | [
"Get",
"the",
"default",
"title",
"for",
"this",
"field",
"from",
"the",
"form",
"field",
"."
]
| 78afc584a1a3f5850f845943f23b233bf1898b81 | https://github.com/symbiote/silverstripe-memberprofiles/blob/78afc584a1a3f5850f845943f23b233bf1898b81/src/Model/MemberProfileField.php#L222-L233 | train |
czim/laravel-repository | src/PostProcessors/ApplyExtraHiddenAndVisibleAttributes.php | ApplyExtraHiddenAndVisibleAttributes.process | public function process(Model $model)
{
$hiddenOnModel = $model->getHidden();
foreach ($this->unhidden as $unhidden) {
if (($key = array_search($unhidden, $hiddenOnModel)) !== false) {
unset($hiddenOnModel[ $key ]);
}
}
$hiddenOnModel = array_merge($hiddenOnModel, $this->hidden);
$model->setHidden($hiddenOnModel);
return $model;
} | php | public function process(Model $model)
{
$hiddenOnModel = $model->getHidden();
foreach ($this->unhidden as $unhidden) {
if (($key = array_search($unhidden, $hiddenOnModel)) !== false) {
unset($hiddenOnModel[ $key ]);
}
}
$hiddenOnModel = array_merge($hiddenOnModel, $this->hidden);
$model->setHidden($hiddenOnModel);
return $model;
} | [
"public",
"function",
"process",
"(",
"Model",
"$",
"model",
")",
"{",
"$",
"hiddenOnModel",
"=",
"$",
"model",
"->",
"getHidden",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"unhidden",
"as",
"$",
"unhidden",
")",
"{",
"if",
"(",
"(",
"$",
"key",
"=",
"array_search",
"(",
"$",
"unhidden",
",",
"$",
"hiddenOnModel",
")",
")",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"hiddenOnModel",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"$",
"hiddenOnModel",
"=",
"array_merge",
"(",
"$",
"hiddenOnModel",
",",
"$",
"this",
"->",
"hidden",
")",
";",
"$",
"model",
"->",
"setHidden",
"(",
"$",
"hiddenOnModel",
")",
";",
"return",
"$",
"model",
";",
"}"
]
| Applies processing to a single model
@param Model $model
@return Model | [
"Applies",
"processing",
"to",
"a",
"single",
"model"
]
| 5f75a39a1b881f7511d355fe6a5ce07f2101b282 | https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/PostProcessors/ApplyExtraHiddenAndVisibleAttributes.php#L41-L58 | train |
czim/laravel-repository | src/Console/Commands/MakeRepositoryCommand.php | MakeRepositoryCommand.loadConfig | protected function loadConfig()
{
$this->namespace = config('repository.generate.namespace', $this->namespace);
$this->base = config('repository.generate.base', $this->base);
$this->suffix = config('repository.generate.suffix', $this->suffix);
$this->models = config('repository.generate.models', $this->models);
} | php | protected function loadConfig()
{
$this->namespace = config('repository.generate.namespace', $this->namespace);
$this->base = config('repository.generate.base', $this->base);
$this->suffix = config('repository.generate.suffix', $this->suffix);
$this->models = config('repository.generate.models', $this->models);
} | [
"protected",
"function",
"loadConfig",
"(",
")",
"{",
"$",
"this",
"->",
"namespace",
"=",
"config",
"(",
"'repository.generate.namespace'",
",",
"$",
"this",
"->",
"namespace",
")",
";",
"$",
"this",
"->",
"base",
"=",
"config",
"(",
"'repository.generate.base'",
",",
"$",
"this",
"->",
"base",
")",
";",
"$",
"this",
"->",
"suffix",
"=",
"config",
"(",
"'repository.generate.suffix'",
",",
"$",
"this",
"->",
"suffix",
")",
";",
"$",
"this",
"->",
"models",
"=",
"config",
"(",
"'repository.generate.models'",
",",
"$",
"this",
"->",
"models",
")",
";",
"}"
]
| Load the configuration for the command. | [
"Load",
"the",
"configuration",
"for",
"the",
"command",
"."
]
| 5f75a39a1b881f7511d355fe6a5ce07f2101b282 | https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/Console/Commands/MakeRepositoryCommand.php#L63-L69 | train |
czim/laravel-repository | src/Console/Commands/MakeRepositoryCommand.php | MakeRepositoryCommand.replaceModelClass | protected function replaceModelClass(&$stub, $name)
{
$names = explode('\\', $name);
$class = array_pop($names);
$stub = str_replace('DummyModelClass', $class, $stub);
return $this;
} | php | protected function replaceModelClass(&$stub, $name)
{
$names = explode('\\', $name);
$class = array_pop($names);
$stub = str_replace('DummyModelClass', $class, $stub);
return $this;
} | [
"protected",
"function",
"replaceModelClass",
"(",
"&",
"$",
"stub",
",",
"$",
"name",
")",
"{",
"$",
"names",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"name",
")",
";",
"$",
"class",
"=",
"array_pop",
"(",
"$",
"names",
")",
";",
"$",
"stub",
"=",
"str_replace",
"(",
"'DummyModelClass'",
",",
"$",
"class",
",",
"$",
"stub",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Replace the probable model class name for the given stub.
@param string $stub
@param string $name
@return $this | [
"Replace",
"the",
"probable",
"model",
"class",
"name",
"for",
"the",
"given",
"stub",
"."
]
| 5f75a39a1b881f7511d355fe6a5ce07f2101b282 | https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/Console/Commands/MakeRepositoryCommand.php#L133-L141 | train |
czim/laravel-repository | src/Console/Commands/MakeRepositoryCommand.php | MakeRepositoryCommand.getModelClass | protected function getModelClass($name)
{
$modelClass = $this->getModelNameInput();
// Generate the model class from the repository class name if not explicitly set
if ( ! $modelClass) {
$repositoryClass = str_replace($this->getNamespace($name) . '\\', '', $name);
$class = str_replace($this->suffix, '', $repositoryClass);
$modelClass = str_singular($class);
}
// Append the expected models namespace if not namespaced yet
if (false === strpos($modelClass, '\\')) {
$modelClass = "{$this->models}\\{$modelClass}";
}
return $modelClass;
} | php | protected function getModelClass($name)
{
$modelClass = $this->getModelNameInput();
// Generate the model class from the repository class name if not explicitly set
if ( ! $modelClass) {
$repositoryClass = str_replace($this->getNamespace($name) . '\\', '', $name);
$class = str_replace($this->suffix, '', $repositoryClass);
$modelClass = str_singular($class);
}
// Append the expected models namespace if not namespaced yet
if (false === strpos($modelClass, '\\')) {
$modelClass = "{$this->models}\\{$modelClass}";
}
return $modelClass;
} | [
"protected",
"function",
"getModelClass",
"(",
"$",
"name",
")",
"{",
"$",
"modelClass",
"=",
"$",
"this",
"->",
"getModelNameInput",
"(",
")",
";",
"// Generate the model class from the repository class name if not explicitly set",
"if",
"(",
"!",
"$",
"modelClass",
")",
"{",
"$",
"repositoryClass",
"=",
"str_replace",
"(",
"$",
"this",
"->",
"getNamespace",
"(",
"$",
"name",
")",
".",
"'\\\\'",
",",
"''",
",",
"$",
"name",
")",
";",
"$",
"class",
"=",
"str_replace",
"(",
"$",
"this",
"->",
"suffix",
",",
"''",
",",
"$",
"repositoryClass",
")",
";",
"$",
"modelClass",
"=",
"str_singular",
"(",
"$",
"class",
")",
";",
"}",
"// Append the expected models namespace if not namespaced yet",
"if",
"(",
"false",
"===",
"strpos",
"(",
"$",
"modelClass",
",",
"'\\\\'",
")",
")",
"{",
"$",
"modelClass",
"=",
"\"{$this->models}\\\\{$modelClass}\"",
";",
"}",
"return",
"$",
"modelClass",
";",
"}"
]
| Get the class name of the probable associated model.
@param $name
@return string | [
"Get",
"the",
"class",
"name",
"of",
"the",
"probable",
"associated",
"model",
"."
]
| 5f75a39a1b881f7511d355fe6a5ce07f2101b282 | https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/Console/Commands/MakeRepositoryCommand.php#L149-L168 | train |
czim/laravel-repository | src/Console/Commands/MakeRepositoryCommand.php | MakeRepositoryCommand.replaceBaseRepositoryClass | protected function replaceBaseRepositoryClass(&$stub, $name)
{
$baseClass = str_replace($this->getNamespace($name) . '\\', '', $name);
$stub = str_replace('BaseRepositoryClass', $baseClass, $stub);
return $this;
} | php | protected function replaceBaseRepositoryClass(&$stub, $name)
{
$baseClass = str_replace($this->getNamespace($name) . '\\', '', $name);
$stub = str_replace('BaseRepositoryClass', $baseClass, $stub);
return $this;
} | [
"protected",
"function",
"replaceBaseRepositoryClass",
"(",
"&",
"$",
"stub",
",",
"$",
"name",
")",
"{",
"$",
"baseClass",
"=",
"str_replace",
"(",
"$",
"this",
"->",
"getNamespace",
"(",
"$",
"name",
")",
".",
"'\\\\'",
",",
"''",
",",
"$",
"name",
")",
";",
"$",
"stub",
"=",
"str_replace",
"(",
"'BaseRepositoryClass'",
",",
"$",
"baseClass",
",",
"$",
"stub",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Replace the default base repository class name for the given stub.
@param string $stub
@param string $name
@return $this | [
"Replace",
"the",
"default",
"base",
"repository",
"class",
"name",
"for",
"the",
"given",
"stub",
"."
]
| 5f75a39a1b881f7511d355fe6a5ce07f2101b282 | https://github.com/czim/laravel-repository/blob/5f75a39a1b881f7511d355fe6a5ce07f2101b282/src/Console/Commands/MakeRepositoryCommand.php#L191-L197 | train |
ProLoser/CakePHP-CSV | src/Model/Behavior/CsvBehavior.php | CsvBehavior.importCsv | public function importCsv($content, $fields = array(), $options = array())
{
$config = $this->getConfig();
$options = array_merge($config, $options);
if (!$this->_trigger('beforeImportCsv', array($content, $fields, $options))) {
return false;
}
if ($options['text']) {
// store the content to a file and reset
$file = fopen("php://memory", "rw");
fwrite($file, $content);
fseek($file, 0);
} else {
$file = fopen($content, 'r');
}
// open the file
if ($file) {
$data = [];
if (empty($fields)) {
// read the 1st row as headings
$fields = fgetcsv($file, $options['length'], $options['delimiter'], $options['enclosure']);
foreach ( $fields as $key => $field ) {
$field = trim($field);
if ( empty($field) ) {
continue;
}
$fields[$key] = strtolower($field);
}
} elseif ( $options['headers'] ) {
fgetcsv($file, $options['length'], $options['delimiter'], $options['enclosure']);
}
// Row counter
$r = 0;
// read each data row in the file
$alias = $this->_table->getAlias();
while ($row = fgetcsv($file, $options['length'], $options['delimiter'], $options['enclosure'])) {
// for each header field
foreach ($fields as $f => $field) {
if (!isset($row[$f])) {
$row[$f] = null;
}
$row[$f] = trim($row[$f]);
// get the data field from Model.field
if (strpos($field,'.')) {
$keys = explode('.',$field);
if ( $keys[0] == $alias ) {
$field = $keys[1];
}
if ( !isset($data[$r]) ) {
$data[$r] = [];
}
$data[$r] = Hash::insert($data[$r], $field, $row[$f]);
} else {
$data[$r][$field] = $row[$f];
}
}
$r++;
}
// close the file
fclose($file);
$this->_trigger('afterImportCsv', array($data));
// return the messages
return $data;
} else {
return false;
}
} | php | public function importCsv($content, $fields = array(), $options = array())
{
$config = $this->getConfig();
$options = array_merge($config, $options);
if (!$this->_trigger('beforeImportCsv', array($content, $fields, $options))) {
return false;
}
if ($options['text']) {
// store the content to a file and reset
$file = fopen("php://memory", "rw");
fwrite($file, $content);
fseek($file, 0);
} else {
$file = fopen($content, 'r');
}
// open the file
if ($file) {
$data = [];
if (empty($fields)) {
// read the 1st row as headings
$fields = fgetcsv($file, $options['length'], $options['delimiter'], $options['enclosure']);
foreach ( $fields as $key => $field ) {
$field = trim($field);
if ( empty($field) ) {
continue;
}
$fields[$key] = strtolower($field);
}
} elseif ( $options['headers'] ) {
fgetcsv($file, $options['length'], $options['delimiter'], $options['enclosure']);
}
// Row counter
$r = 0;
// read each data row in the file
$alias = $this->_table->getAlias();
while ($row = fgetcsv($file, $options['length'], $options['delimiter'], $options['enclosure'])) {
// for each header field
foreach ($fields as $f => $field) {
if (!isset($row[$f])) {
$row[$f] = null;
}
$row[$f] = trim($row[$f]);
// get the data field from Model.field
if (strpos($field,'.')) {
$keys = explode('.',$field);
if ( $keys[0] == $alias ) {
$field = $keys[1];
}
if ( !isset($data[$r]) ) {
$data[$r] = [];
}
$data[$r] = Hash::insert($data[$r], $field, $row[$f]);
} else {
$data[$r][$field] = $row[$f];
}
}
$r++;
}
// close the file
fclose($file);
$this->_trigger('afterImportCsv', array($data));
// return the messages
return $data;
} else {
return false;
}
} | [
"public",
"function",
"importCsv",
"(",
"$",
"content",
",",
"$",
"fields",
"=",
"array",
"(",
")",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"config",
",",
"$",
"options",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"_trigger",
"(",
"'beforeImportCsv'",
",",
"array",
"(",
"$",
"content",
",",
"$",
"fields",
",",
"$",
"options",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'text'",
"]",
")",
"{",
"// store the content to a file and reset",
"$",
"file",
"=",
"fopen",
"(",
"\"php://memory\"",
",",
"\"rw\"",
")",
";",
"fwrite",
"(",
"$",
"file",
",",
"$",
"content",
")",
";",
"fseek",
"(",
"$",
"file",
",",
"0",
")",
";",
"}",
"else",
"{",
"$",
"file",
"=",
"fopen",
"(",
"$",
"content",
",",
"'r'",
")",
";",
"}",
"// open the file",
"if",
"(",
"$",
"file",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"// read the 1st row as headings",
"$",
"fields",
"=",
"fgetcsv",
"(",
"$",
"file",
",",
"$",
"options",
"[",
"'length'",
"]",
",",
"$",
"options",
"[",
"'delimiter'",
"]",
",",
"$",
"options",
"[",
"'enclosure'",
"]",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"key",
"=>",
"$",
"field",
")",
"{",
"$",
"field",
"=",
"trim",
"(",
"$",
"field",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"field",
")",
")",
"{",
"continue",
";",
"}",
"$",
"fields",
"[",
"$",
"key",
"]",
"=",
"strtolower",
"(",
"$",
"field",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"options",
"[",
"'headers'",
"]",
")",
"{",
"fgetcsv",
"(",
"$",
"file",
",",
"$",
"options",
"[",
"'length'",
"]",
",",
"$",
"options",
"[",
"'delimiter'",
"]",
",",
"$",
"options",
"[",
"'enclosure'",
"]",
")",
";",
"}",
"// Row counter",
"$",
"r",
"=",
"0",
";",
"// read each data row in the file",
"$",
"alias",
"=",
"$",
"this",
"->",
"_table",
"->",
"getAlias",
"(",
")",
";",
"while",
"(",
"$",
"row",
"=",
"fgetcsv",
"(",
"$",
"file",
",",
"$",
"options",
"[",
"'length'",
"]",
",",
"$",
"options",
"[",
"'delimiter'",
"]",
",",
"$",
"options",
"[",
"'enclosure'",
"]",
")",
")",
"{",
"// for each header field",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"f",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"row",
"[",
"$",
"f",
"]",
")",
")",
"{",
"$",
"row",
"[",
"$",
"f",
"]",
"=",
"null",
";",
"}",
"$",
"row",
"[",
"$",
"f",
"]",
"=",
"trim",
"(",
"$",
"row",
"[",
"$",
"f",
"]",
")",
";",
"// get the data field from Model.field",
"if",
"(",
"strpos",
"(",
"$",
"field",
",",
"'.'",
")",
")",
"{",
"$",
"keys",
"=",
"explode",
"(",
"'.'",
",",
"$",
"field",
")",
";",
"if",
"(",
"$",
"keys",
"[",
"0",
"]",
"==",
"$",
"alias",
")",
"{",
"$",
"field",
"=",
"$",
"keys",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"r",
"]",
")",
")",
"{",
"$",
"data",
"[",
"$",
"r",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"data",
"[",
"$",
"r",
"]",
"=",
"Hash",
"::",
"insert",
"(",
"$",
"data",
"[",
"$",
"r",
"]",
",",
"$",
"field",
",",
"$",
"row",
"[",
"$",
"f",
"]",
")",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"$",
"r",
"]",
"[",
"$",
"field",
"]",
"=",
"$",
"row",
"[",
"$",
"f",
"]",
";",
"}",
"}",
"$",
"r",
"++",
";",
"}",
"// close the file",
"fclose",
"(",
"$",
"file",
")",
";",
"$",
"this",
"->",
"_trigger",
"(",
"'afterImportCsv'",
",",
"array",
"(",
"$",
"data",
")",
")",
";",
"// return the messages",
"return",
"$",
"data",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
]
| Import public function
@param string $conent filename or path to the file under webroot
@param array $fields to import
@param array $options to set
@return array of all data from the csv file in [Model][field] format
@author Dean Sofer | [
"Import",
"public",
"function"
]
| d9734b1d585e2ff5d4a762a06ea65eee83aebba3 | https://github.com/ProLoser/CakePHP-CSV/blob/d9734b1d585e2ff5d4a762a06ea65eee83aebba3/src/Model/Behavior/CsvBehavior.php#L38-L113 | train |
ProLoser/CakePHP-CSV | src/Model/Behavior/CsvBehavior.php | CsvBehavior.exportCsv | public function exportCsv($filename, $data, $options = array())
{
$config = $this->getConfig();
$options = array_merge($config, $options);
if (!$this->_trigger('beforeExportCsv', array($filename, $data, $options))) {
return false;
}
// open the file
if ($file = fopen($filename, 'w')) {
// Add BOM for proper display UTF-8 in EXCEL
if($options['excel_bom']) {
fputs($file, chr(239) . chr(187) . chr(191));
}
// Iterate through and format data
$firstRecord = true;
foreach ($data as $record) {
$record = $record->toArray();
$row = array();
foreach ($record as $field => $value) {
if ( !is_array($value) ) {
$row[] = $value;
if ($firstRecord) {
$headers[] = $field;
}
continue;
}
$table = $field;
$fields = $value;
// TODO add parsing for HABTM
foreach ($fields as $field => $value) {
if (!is_array($value)) {
if ($firstRecord) {
$headers[] = $table . '.' . $field;
}
$row[] = $value;
} // TODO due to HABTM potentially being huge, creating an else might not be plausible
}
}
$rows[] = $row;
$firstRecord = false;
}
if ($options['headers']) {
// write the 1st row as headings
fputcsv($file, $headers, $options['delimiter'], $options['enclosure']);
}
// Row counter
$r = 0;
foreach ($rows as $row) {
fputcsv($file, $row, $options['delimiter'], $options['enclosure']);
$r++;
}
// close the file
fclose($file);
$this->_trigger('afterExportCsv', array());
return $r;
} else {
return false;
}
} | php | public function exportCsv($filename, $data, $options = array())
{
$config = $this->getConfig();
$options = array_merge($config, $options);
if (!$this->_trigger('beforeExportCsv', array($filename, $data, $options))) {
return false;
}
// open the file
if ($file = fopen($filename, 'w')) {
// Add BOM for proper display UTF-8 in EXCEL
if($options['excel_bom']) {
fputs($file, chr(239) . chr(187) . chr(191));
}
// Iterate through and format data
$firstRecord = true;
foreach ($data as $record) {
$record = $record->toArray();
$row = array();
foreach ($record as $field => $value) {
if ( !is_array($value) ) {
$row[] = $value;
if ($firstRecord) {
$headers[] = $field;
}
continue;
}
$table = $field;
$fields = $value;
// TODO add parsing for HABTM
foreach ($fields as $field => $value) {
if (!is_array($value)) {
if ($firstRecord) {
$headers[] = $table . '.' . $field;
}
$row[] = $value;
} // TODO due to HABTM potentially being huge, creating an else might not be plausible
}
}
$rows[] = $row;
$firstRecord = false;
}
if ($options['headers']) {
// write the 1st row as headings
fputcsv($file, $headers, $options['delimiter'], $options['enclosure']);
}
// Row counter
$r = 0;
foreach ($rows as $row) {
fputcsv($file, $row, $options['delimiter'], $options['enclosure']);
$r++;
}
// close the file
fclose($file);
$this->_trigger('afterExportCsv', array());
return $r;
} else {
return false;
}
} | [
"public",
"function",
"exportCsv",
"(",
"$",
"filename",
",",
"$",
"data",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"config",
",",
"$",
"options",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"_trigger",
"(",
"'beforeExportCsv'",
",",
"array",
"(",
"$",
"filename",
",",
"$",
"data",
",",
"$",
"options",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"// open the file",
"if",
"(",
"$",
"file",
"=",
"fopen",
"(",
"$",
"filename",
",",
"'w'",
")",
")",
"{",
"// Add BOM for proper display UTF-8 in EXCEL",
"if",
"(",
"$",
"options",
"[",
"'excel_bom'",
"]",
")",
"{",
"fputs",
"(",
"$",
"file",
",",
"chr",
"(",
"239",
")",
".",
"chr",
"(",
"187",
")",
".",
"chr",
"(",
"191",
")",
")",
";",
"}",
"// Iterate through and format data",
"$",
"firstRecord",
"=",
"true",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"record",
")",
"{",
"$",
"record",
"=",
"$",
"record",
"->",
"toArray",
"(",
")",
";",
"$",
"row",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"record",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"row",
"[",
"]",
"=",
"$",
"value",
";",
"if",
"(",
"$",
"firstRecord",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"$",
"field",
";",
"}",
"continue",
";",
"}",
"$",
"table",
"=",
"$",
"field",
";",
"$",
"fields",
"=",
"$",
"value",
";",
"// TODO add parsing for HABTM",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"$",
"firstRecord",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"$",
"table",
".",
"'.'",
".",
"$",
"field",
";",
"}",
"$",
"row",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"// TODO due to HABTM potentially being huge, creating an else might not be plausible",
"}",
"}",
"$",
"rows",
"[",
"]",
"=",
"$",
"row",
";",
"$",
"firstRecord",
"=",
"false",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'headers'",
"]",
")",
"{",
"// write the 1st row as headings",
"fputcsv",
"(",
"$",
"file",
",",
"$",
"headers",
",",
"$",
"options",
"[",
"'delimiter'",
"]",
",",
"$",
"options",
"[",
"'enclosure'",
"]",
")",
";",
"}",
"// Row counter",
"$",
"r",
"=",
"0",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"fputcsv",
"(",
"$",
"file",
",",
"$",
"row",
",",
"$",
"options",
"[",
"'delimiter'",
"]",
",",
"$",
"options",
"[",
"'enclosure'",
"]",
")",
";",
"$",
"r",
"++",
";",
"}",
"// close the file",
"fclose",
"(",
"$",
"file",
")",
";",
"$",
"this",
"->",
"_trigger",
"(",
"'afterExportCsv'",
",",
"array",
"(",
")",
")",
";",
"return",
"$",
"r",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
]
| Converts a data array into
@param string $filename to export to
@param string $data to export
@return void
@author Dean | [
"Converts",
"a",
"data",
"array",
"into"
]
| d9734b1d585e2ff5d4a762a06ea65eee83aebba3 | https://github.com/ProLoser/CakePHP-CSV/blob/d9734b1d585e2ff5d4a762a06ea65eee83aebba3/src/Model/Behavior/CsvBehavior.php#L123-L187 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.