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/lib/Roundcube/rcube_enriched.php
rcube_enriched.to_html
public static function to_html($body) { $body = str_replace('<<','&lt;',$body); $body = self::convert_newlines($body); $body = str_replace("\n", '<br>', $body); $body = self::convert_formatting($body); $body = self::convert_color($body); $body = self::convert_font($body); $body = self::convert_excerpt($body); //$body = nl2br($body); return $body; }
php
public static function to_html($body) { $body = str_replace('<<','&lt;',$body); $body = self::convert_newlines($body); $body = str_replace("\n", '<br>', $body); $body = self::convert_formatting($body); $body = self::convert_color($body); $body = self::convert_font($body); $body = self::convert_excerpt($body); //$body = nl2br($body); return $body; }
[ "public", "static", "function", "to_html", "(", "$", "body", ")", "{", "$", "body", "=", "str_replace", "(", "'<<'", ",", "'&lt;'", ",", "$", "body", ")", ";", "$", "body", "=", "self", "::", "convert_newlines", "(", "$", "body", ")", ";", "$", "body", "=", "str_replace", "(", "\"\\n\"", ",", "'<br>'", ",", "$", "body", ")", ";", "$", "body", "=", "self", "::", "convert_formatting", "(", "$", "body", ")", ";", "$", "body", "=", "self", "::", "convert_color", "(", "$", "body", ")", ";", "$", "body", "=", "self", "::", "convert_font", "(", "$", "body", ")", ";", "$", "body", "=", "self", "::", "convert_excerpt", "(", "$", "body", ")", ";", "//$body = nl2br($body);", "return", "$", "body", ";", "}" ]
Converts Enriched text into HTML format @param string $body Enriched text @return string HTML text
[ "Converts", "Enriched", "text", "into", "HTML", "format" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_enriched.php#L137-L149
train
i-MSCP/roundcube
roundcubemail/plugins/password/drivers/cpanel_webmail.php
rcube_cpanel_webmail_password.save
public function save($curpas, $newpass) { $user = $_SESSION['username']; $userpwd = "$user:$curpas"; list($login) = explode('@', $user); $data = array( 'email' => $login, 'password' => $newpass ); $url = self::url(); $response = $this->curl_auth_post($userpwd, $url, $data); return self::decode_response($response); }
php
public function save($curpas, $newpass) { $user = $_SESSION['username']; $userpwd = "$user:$curpas"; list($login) = explode('@', $user); $data = array( 'email' => $login, 'password' => $newpass ); $url = self::url(); $response = $this->curl_auth_post($userpwd, $url, $data); return self::decode_response($response); }
[ "public", "function", "save", "(", "$", "curpas", ",", "$", "newpass", ")", "{", "$", "user", "=", "$", "_SESSION", "[", "'username'", "]", ";", "$", "userpwd", "=", "\"$user:$curpas\"", ";", "list", "(", "$", "login", ")", "=", "explode", "(", "'@'", ",", "$", "user", ")", ";", "$", "data", "=", "array", "(", "'email'", "=>", "$", "login", ",", "'password'", "=>", "$", "newpass", ")", ";", "$", "url", "=", "self", "::", "url", "(", ")", ";", "$", "response", "=", "$", "this", "->", "curl_auth_post", "(", "$", "userpwd", ",", "$", "url", ",", "$", "data", ")", ";", "return", "self", "::", "decode_response", "(", "$", "response", ")", ";", "}" ]
Changes the user's password. It is called by password.php. See "Driver API" README and password.php for the interface details. @param string $curpas current (old) password @param string $newpass new requested password @return mixed int code or assoc array with 'code' and 'message', see "Driver API" README and password.php
[ "Changes", "the", "user", "s", "password", ".", "It", "is", "called", "by", "password", ".", "php", ".", "See", "Driver", "API", "README", "and", "password", ".", "php", "for", "the", "interface", "details", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/password/drivers/cpanel_webmail.php#L40-L55
train
i-MSCP/roundcube
roundcubemail/plugins/password/drivers/cpanel_webmail.php
rcube_cpanel_webmail_password.decode_response
public static function decode_response($response) { if (!$response) { return PASSWORD_CONNECT_ERROR; } // $result should be `null` or `stdClass` object $result = json_decode($response); // The UAPI may return HTML instead of JSON on missing authentication if ($result && $result->status === 1) { return PASSWORD_SUCCESS; } if ($result && is_array($result->errors) && count($result->errors) > 0) { return array( 'code' => PASSWORD_ERROR, 'message' => $result->errors[0], ); } return PASSWORD_ERROR; }
php
public static function decode_response($response) { if (!$response) { return PASSWORD_CONNECT_ERROR; } // $result should be `null` or `stdClass` object $result = json_decode($response); // The UAPI may return HTML instead of JSON on missing authentication if ($result && $result->status === 1) { return PASSWORD_SUCCESS; } if ($result && is_array($result->errors) && count($result->errors) > 0) { return array( 'code' => PASSWORD_ERROR, 'message' => $result->errors[0], ); } return PASSWORD_ERROR; }
[ "public", "static", "function", "decode_response", "(", "$", "response", ")", "{", "if", "(", "!", "$", "response", ")", "{", "return", "PASSWORD_CONNECT_ERROR", ";", "}", "// $result should be `null` or `stdClass` object", "$", "result", "=", "json_decode", "(", "$", "response", ")", ";", "// The UAPI may return HTML instead of JSON on missing authentication", "if", "(", "$", "result", "&&", "$", "result", "->", "status", "===", "1", ")", "{", "return", "PASSWORD_SUCCESS", ";", "}", "if", "(", "$", "result", "&&", "is_array", "(", "$", "result", "->", "errors", ")", "&&", "count", "(", "$", "result", "->", "errors", ")", ">", "0", ")", "{", "return", "array", "(", "'code'", "=>", "PASSWORD_ERROR", ",", "'message'", "=>", "$", "result", "->", "errors", "[", "0", "]", ",", ")", ";", "}", "return", "PASSWORD_ERROR", ";", "}" ]
Converts a UAPI response to a password driver response. @param string $response JSON response by the Cpanel UAPI @return mixed response code or array, see <code>save</code>
[ "Converts", "a", "UAPI", "response", "to", "a", "password", "driver", "response", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/password/drivers/cpanel_webmail.php#L80-L102
train
i-MSCP/roundcube
roundcubemail/plugins/password/drivers/cpanel_webmail.php
rcube_cpanel_webmail_password.curl_auth_post
private function curl_auth_post($userpwd, $url, $postdata) { $ch = curl_init(); $postfields = http_build_query($postdata, '', '&'); // see http://php.net/manual/en/function.curl-setopt.php curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BUFFERSIZE, 131072); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, CURLOPT_USERPWD, $userpwd); $result = curl_exec($ch); $error = curl_error($ch); curl_close($ch); if ($result === false) { rcube::raise_error("curl error: $error", true, false); } return $result; }
php
private function curl_auth_post($userpwd, $url, $postdata) { $ch = curl_init(); $postfields = http_build_query($postdata, '', '&'); // see http://php.net/manual/en/function.curl-setopt.php curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BUFFERSIZE, 131072); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, CURLOPT_USERPWD, $userpwd); $result = curl_exec($ch); $error = curl_error($ch); curl_close($ch); if ($result === false) { rcube::raise_error("curl error: $error", true, false); } return $result; }
[ "private", "function", "curl_auth_post", "(", "$", "userpwd", ",", "$", "url", ",", "$", "postdata", ")", "{", "$", "ch", "=", "curl_init", "(", ")", ";", "$", "postfields", "=", "http_build_query", "(", "$", "postdata", ",", "''", ",", "'&'", ")", ";", "// see http://php.net/manual/en/function.curl-setopt.php", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYPEER", ",", "0", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYHOST", ",", "0", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_RETURNTRANSFER", ",", "1", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_BUFFERSIZE", ",", "131072", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_URL", ",", "$", "url", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_POST", ",", "1", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_POSTFIELDS", ",", "$", "postfields", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_USERPWD", ",", "$", "userpwd", ")", ";", "$", "result", "=", "curl_exec", "(", "$", "ch", ")", ";", "$", "error", "=", "curl_error", "(", "$", "ch", ")", ";", "curl_close", "(", "$", "ch", ")", ";", "if", "(", "$", "result", "===", "false", ")", "{", "rcube", "::", "raise_error", "(", "\"curl error: $error\"", ",", "true", ",", "false", ")", ";", "}", "return", "$", "result", ";", "}" ]
Post data to the given URL using basic authentication. Example: <code> curl_auth_post('john:Secr3t', 'https://example.org', array( 'param' => 'value', 'param' => 'value' )); </code> @param string $userpwd user name and password separated by a colon <code>:</code> @param string $url the URL to post data to @param array $postdata the data to post @return string|false The body of the reply, False on error
[ "Post", "data", "to", "the", "given", "URL", "using", "basic", "authentication", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/password/drivers/cpanel_webmail.php#L123-L147
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_db_oracle.php
rcube_db_oracle.conn_create
protected function conn_create($dsn) { // Get database specific connection options $dsn_options = $this->dsn_options($dsn); $function = $this->db_pconn ? 'oci_pconnect' : 'oci_connect'; if (!function_exists($function)) { $this->db_error = true; $this->db_error_msg = 'OCI8 extension not loaded. See http://php.net/manual/en/book.oci8.php'; rcube::raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, 'message' => $this->db_error_msg), true, false); return; } // connect $dbh = @$function($dsn['username'], $dsn['password'], $dsn_options['database'], $dsn_options['charset']); if (!$dbh) { $error = oci_error(); $this->db_error = true; $this->db_error_msg = $error['message']; rcube::raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, 'message' => $this->db_error_msg), true, false); return; } // configure session $this->conn_configure($dsn, $dbh); return $dbh; }
php
protected function conn_create($dsn) { // Get database specific connection options $dsn_options = $this->dsn_options($dsn); $function = $this->db_pconn ? 'oci_pconnect' : 'oci_connect'; if (!function_exists($function)) { $this->db_error = true; $this->db_error_msg = 'OCI8 extension not loaded. See http://php.net/manual/en/book.oci8.php'; rcube::raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, 'message' => $this->db_error_msg), true, false); return; } // connect $dbh = @$function($dsn['username'], $dsn['password'], $dsn_options['database'], $dsn_options['charset']); if (!$dbh) { $error = oci_error(); $this->db_error = true; $this->db_error_msg = $error['message']; rcube::raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, 'message' => $this->db_error_msg), true, false); return; } // configure session $this->conn_configure($dsn, $dbh); return $dbh; }
[ "protected", "function", "conn_create", "(", "$", "dsn", ")", "{", "// Get database specific connection options", "$", "dsn_options", "=", "$", "this", "->", "dsn_options", "(", "$", "dsn", ")", ";", "$", "function", "=", "$", "this", "->", "db_pconn", "?", "'oci_pconnect'", ":", "'oci_connect'", ";", "if", "(", "!", "function_exists", "(", "$", "function", ")", ")", "{", "$", "this", "->", "db_error", "=", "true", ";", "$", "this", "->", "db_error_msg", "=", "'OCI8 extension not loaded. See http://php.net/manual/en/book.oci8.php'", ";", "rcube", "::", "raise_error", "(", "array", "(", "'code'", "=>", "500", ",", "'type'", "=>", "'db'", ",", "'line'", "=>", "__LINE__", ",", "'file'", "=>", "__FILE__", ",", "'message'", "=>", "$", "this", "->", "db_error_msg", ")", ",", "true", ",", "false", ")", ";", "return", ";", "}", "// connect", "$", "dbh", "=", "@", "$", "function", "(", "$", "dsn", "[", "'username'", "]", ",", "$", "dsn", "[", "'password'", "]", ",", "$", "dsn_options", "[", "'database'", "]", ",", "$", "dsn_options", "[", "'charset'", "]", ")", ";", "if", "(", "!", "$", "dbh", ")", "{", "$", "error", "=", "oci_error", "(", ")", ";", "$", "this", "->", "db_error", "=", "true", ";", "$", "this", "->", "db_error_msg", "=", "$", "error", "[", "'message'", "]", ";", "rcube", "::", "raise_error", "(", "array", "(", "'code'", "=>", "500", ",", "'type'", "=>", "'db'", ",", "'line'", "=>", "__LINE__", ",", "'file'", "=>", "__FILE__", ",", "'message'", "=>", "$", "this", "->", "db_error_msg", ")", ",", "true", ",", "false", ")", ";", "return", ";", "}", "// configure session", "$", "this", "->", "conn_configure", "(", "$", "dsn", ",", "$", "dbh", ")", ";", "return", "$", "dbh", ";", "}" ]
Create connection instance
[ "Create", "connection", "instance" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_db_oracle.php#L34-L71
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_db_oracle.php
rcube_db_oracle.conn_configure
protected function conn_configure($dsn, $dbh) { $init_queries = array( "ALTER SESSION SET nls_date_format = 'YYYY-MM-DD'", "ALTER SESSION SET nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SS'", ); foreach ($init_queries as $query) { $stmt = oci_parse($dbh, $query); oci_execute($stmt); } }
php
protected function conn_configure($dsn, $dbh) { $init_queries = array( "ALTER SESSION SET nls_date_format = 'YYYY-MM-DD'", "ALTER SESSION SET nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SS'", ); foreach ($init_queries as $query) { $stmt = oci_parse($dbh, $query); oci_execute($stmt); } }
[ "protected", "function", "conn_configure", "(", "$", "dsn", ",", "$", "dbh", ")", "{", "$", "init_queries", "=", "array", "(", "\"ALTER SESSION SET nls_date_format = 'YYYY-MM-DD'\"", ",", "\"ALTER SESSION SET nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SS'\"", ",", ")", ";", "foreach", "(", "$", "init_queries", "as", "$", "query", ")", "{", "$", "stmt", "=", "oci_parse", "(", "$", "dbh", ",", "$", "query", ")", ";", "oci_execute", "(", "$", "stmt", ")", ";", "}", "}" ]
Driver-specific configuration of database connection @param array $dsn DSN for DB connections @param PDO $dbh Connection handler
[ "Driver", "-", "specific", "configuration", "of", "database", "connection" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_db_oracle.php#L79-L90
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_db_oracle.php
rcube_db_oracle.fix_table_names
protected function fix_table_names($sql) { if (!$this->options['table_prefix']) { return $sql; } $sql = parent::fix_table_names($sql); // replace sequence names, and other Oracle-specific commands $sql = preg_replace_callback('/((SEQUENCE ["]?)([^" \r\n]+)/', array($this, 'fix_table_names_callback'), $sql ); $sql = preg_replace_callback( '/([ \r\n]+["]?)([^"\' \r\n\.]+)(["]?\.nextval)/', array($this, 'fix_table_names_seq_callback'), $sql ); return $sql; }
php
protected function fix_table_names($sql) { if (!$this->options['table_prefix']) { return $sql; } $sql = parent::fix_table_names($sql); // replace sequence names, and other Oracle-specific commands $sql = preg_replace_callback('/((SEQUENCE ["]?)([^" \r\n]+)/', array($this, 'fix_table_names_callback'), $sql ); $sql = preg_replace_callback( '/([ \r\n]+["]?)([^"\' \r\n\.]+)(["]?\.nextval)/', array($this, 'fix_table_names_seq_callback'), $sql ); return $sql; }
[ "protected", "function", "fix_table_names", "(", "$", "sql", ")", "{", "if", "(", "!", "$", "this", "->", "options", "[", "'table_prefix'", "]", ")", "{", "return", "$", "sql", ";", "}", "$", "sql", "=", "parent", "::", "fix_table_names", "(", "$", "sql", ")", ";", "// replace sequence names, and other Oracle-specific commands", "$", "sql", "=", "preg_replace_callback", "(", "'/((SEQUENCE [\"]?)([^\" \\r\\n]+)/'", ",", "array", "(", "$", "this", ",", "'fix_table_names_callback'", ")", ",", "$", "sql", ")", ";", "$", "sql", "=", "preg_replace_callback", "(", "'/([ \\r\\n]+[\"]?)([^\"\\' \\r\\n\\.]+)([\"]?\\.nextval)/'", ",", "array", "(", "$", "this", ",", "'fix_table_names_seq_callback'", ")", ",", "$", "sql", ")", ";", "return", "$", "sql", ";", "}" ]
Parse SQL file and fix table names according to table prefix
[ "Parse", "SQL", "file", "and", "fix", "table", "names", "according", "to", "table", "prefix" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_db_oracle.php#L445-L466
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_db_oracle.php
rcube_db_oracle.dsn_options
protected function dsn_options($dsn) { $params = array(); if ($dsn['hostspec']) { $host = $dsn['hostspec']; if ($dsn['port']) { $host .= ':' . $dsn['port']; } $params['database'] = $host . '/' . $dsn['database']; } $params['charset'] = 'UTF8'; return $params; }
php
protected function dsn_options($dsn) { $params = array(); if ($dsn['hostspec']) { $host = $dsn['hostspec']; if ($dsn['port']) { $host .= ':' . $dsn['port']; } $params['database'] = $host . '/' . $dsn['database']; } $params['charset'] = 'UTF8'; return $params; }
[ "protected", "function", "dsn_options", "(", "$", "dsn", ")", "{", "$", "params", "=", "array", "(", ")", ";", "if", "(", "$", "dsn", "[", "'hostspec'", "]", ")", "{", "$", "host", "=", "$", "dsn", "[", "'hostspec'", "]", ";", "if", "(", "$", "dsn", "[", "'port'", "]", ")", "{", "$", "host", ".=", "':'", ".", "$", "dsn", "[", "'port'", "]", ";", "}", "$", "params", "[", "'database'", "]", "=", "$", "host", ".", "'/'", ".", "$", "dsn", "[", "'database'", "]", ";", "}", "$", "params", "[", "'charset'", "]", "=", "'UTF8'", ";", "return", "$", "params", ";", "}" ]
Returns connection options from DSN array
[ "Returns", "connection", "options", "from", "DSN", "array" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_db_oracle.php#L479-L495
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_db.php
rcube_db.dsn_connect
protected function dsn_connect($dsn, $mode) { $this->db_error = false; $this->db_error_msg = null; // return existing handle if ($this->dbhs[$mode]) { $this->dbh = $this->dbhs[$mode]; $this->db_mode = $mode; return $this->dbh; } // connect to database if ($dbh = $this->conn_create($dsn)) { $this->dbh = $dbh; $this->dbhs[$mode] = $dbh; $this->db_mode = $mode; $this->db_connected = true; } }
php
protected function dsn_connect($dsn, $mode) { $this->db_error = false; $this->db_error_msg = null; // return existing handle if ($this->dbhs[$mode]) { $this->dbh = $this->dbhs[$mode]; $this->db_mode = $mode; return $this->dbh; } // connect to database if ($dbh = $this->conn_create($dsn)) { $this->dbh = $dbh; $this->dbhs[$mode] = $dbh; $this->db_mode = $mode; $this->db_connected = true; } }
[ "protected", "function", "dsn_connect", "(", "$", "dsn", ",", "$", "mode", ")", "{", "$", "this", "->", "db_error", "=", "false", ";", "$", "this", "->", "db_error_msg", "=", "null", ";", "// return existing handle", "if", "(", "$", "this", "->", "dbhs", "[", "$", "mode", "]", ")", "{", "$", "this", "->", "dbh", "=", "$", "this", "->", "dbhs", "[", "$", "mode", "]", ";", "$", "this", "->", "db_mode", "=", "$", "mode", ";", "return", "$", "this", "->", "dbh", ";", "}", "// connect to database", "if", "(", "$", "dbh", "=", "$", "this", "->", "conn_create", "(", "$", "dsn", ")", ")", "{", "$", "this", "->", "dbh", "=", "$", "dbh", ";", "$", "this", "->", "dbhs", "[", "$", "mode", "]", "=", "$", "dbh", ";", "$", "this", "->", "db_mode", "=", "$", "mode", ";", "$", "this", "->", "db_connected", "=", "true", ";", "}", "}" ]
Connect to specific database @param array $dsn DSN for DB connections @param string $mode Connection mode (r|w)
[ "Connect", "to", "specific", "database" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_db.php#L124-L143
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_db.php
rcube_db.db_connect
public function db_connect($mode, $force = false) { // previous connection failed, don't attempt to connect again if ($this->conn_failure) { return; } // no replication if ($this->db_dsnw == $this->db_dsnr) { $mode = 'w'; } // Already connected if ($this->db_connected) { // connected to db with the same or "higher" mode (if allowed) if ($this->db_mode == $mode || $this->db_mode == 'w' && !$force && !$this->options['dsnw_noread']) { return; } } $dsn = ($mode == 'r') ? $this->db_dsnr_array : $this->db_dsnw_array; $this->dsn_connect($dsn, $mode); // use write-master when read-only fails if (!$this->db_connected && $mode == 'r' && $this->is_replicated()) { $this->dsn_connect($this->db_dsnw_array, 'w'); } $this->conn_failure = !$this->db_connected; }
php
public function db_connect($mode, $force = false) { // previous connection failed, don't attempt to connect again if ($this->conn_failure) { return; } // no replication if ($this->db_dsnw == $this->db_dsnr) { $mode = 'w'; } // Already connected if ($this->db_connected) { // connected to db with the same or "higher" mode (if allowed) if ($this->db_mode == $mode || $this->db_mode == 'w' && !$force && !$this->options['dsnw_noread']) { return; } } $dsn = ($mode == 'r') ? $this->db_dsnr_array : $this->db_dsnw_array; $this->dsn_connect($dsn, $mode); // use write-master when read-only fails if (!$this->db_connected && $mode == 'r' && $this->is_replicated()) { $this->dsn_connect($this->db_dsnw_array, 'w'); } $this->conn_failure = !$this->db_connected; }
[ "public", "function", "db_connect", "(", "$", "mode", ",", "$", "force", "=", "false", ")", "{", "// previous connection failed, don't attempt to connect again", "if", "(", "$", "this", "->", "conn_failure", ")", "{", "return", ";", "}", "// no replication", "if", "(", "$", "this", "->", "db_dsnw", "==", "$", "this", "->", "db_dsnr", ")", "{", "$", "mode", "=", "'w'", ";", "}", "// Already connected", "if", "(", "$", "this", "->", "db_connected", ")", "{", "// connected to db with the same or \"higher\" mode (if allowed)", "if", "(", "$", "this", "->", "db_mode", "==", "$", "mode", "||", "$", "this", "->", "db_mode", "==", "'w'", "&&", "!", "$", "force", "&&", "!", "$", "this", "->", "options", "[", "'dsnw_noread'", "]", ")", "{", "return", ";", "}", "}", "$", "dsn", "=", "(", "$", "mode", "==", "'r'", ")", "?", "$", "this", "->", "db_dsnr_array", ":", "$", "this", "->", "db_dsnw_array", ";", "$", "this", "->", "dsn_connect", "(", "$", "dsn", ",", "$", "mode", ")", ";", "// use write-master when read-only fails", "if", "(", "!", "$", "this", "->", "db_connected", "&&", "$", "mode", "==", "'r'", "&&", "$", "this", "->", "is_replicated", "(", ")", ")", "{", "$", "this", "->", "dsn_connect", "(", "$", "this", "->", "db_dsnw_array", ",", "'w'", ")", ";", "}", "$", "this", "->", "conn_failure", "=", "!", "$", "this", "->", "db_connected", ";", "}" ]
Connect to appropriate database depending on the operation @param string $mode Connection mode (r|w) @param boolean $force Enforce using the given mode
[ "Connect", "to", "appropriate", "database", "depending", "on", "the", "operation" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_db.php#L209-L238
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_db.php
rcube_db.dsn_select
protected function dsn_select($query) { // no replication if ($this->db_dsnw == $this->db_dsnr) { return 'w'; } // Read or write ? $mode = preg_match('/^(select|show|set)/i', $query) ? 'r' : 'w'; $start = '[' . $this->options['identifier_start'] . self::DEFAULT_QUOTE . ']'; $end = '[' . $this->options['identifier_end'] . self::DEFAULT_QUOTE . ']'; $regex = '/(?:^|\s)(from|update|into|join)\s+'.$start.'?([a-z0-9._]+)'.$end.'?\s+/i'; // find tables involved in this query if (preg_match_all($regex, $query, $matches, PREG_SET_ORDER)) { foreach ($matches as $m) { $table = $m[2]; // always use direct mapping if ($this->options['table_dsn_map'][$table]) { $mode = $this->options['table_dsn_map'][$table]; break; // primary table rules } else if ($mode == 'r') { // connected to db with the same or "higher" mode for this table $db_mode = $this->table_connections[$table]; if ($db_mode == 'w' && !$this->options['dsnw_noread']) { $mode = $db_mode; } } } // remember mode chosen (for primary table) $table = $matches[0][2]; $this->table_connections[$table] = $mode; } return $mode; }
php
protected function dsn_select($query) { // no replication if ($this->db_dsnw == $this->db_dsnr) { return 'w'; } // Read or write ? $mode = preg_match('/^(select|show|set)/i', $query) ? 'r' : 'w'; $start = '[' . $this->options['identifier_start'] . self::DEFAULT_QUOTE . ']'; $end = '[' . $this->options['identifier_end'] . self::DEFAULT_QUOTE . ']'; $regex = '/(?:^|\s)(from|update|into|join)\s+'.$start.'?([a-z0-9._]+)'.$end.'?\s+/i'; // find tables involved in this query if (preg_match_all($regex, $query, $matches, PREG_SET_ORDER)) { foreach ($matches as $m) { $table = $m[2]; // always use direct mapping if ($this->options['table_dsn_map'][$table]) { $mode = $this->options['table_dsn_map'][$table]; break; // primary table rules } else if ($mode == 'r') { // connected to db with the same or "higher" mode for this table $db_mode = $this->table_connections[$table]; if ($db_mode == 'w' && !$this->options['dsnw_noread']) { $mode = $db_mode; } } } // remember mode chosen (for primary table) $table = $matches[0][2]; $this->table_connections[$table] = $mode; } return $mode; }
[ "protected", "function", "dsn_select", "(", "$", "query", ")", "{", "// no replication", "if", "(", "$", "this", "->", "db_dsnw", "==", "$", "this", "->", "db_dsnr", ")", "{", "return", "'w'", ";", "}", "// Read or write ?", "$", "mode", "=", "preg_match", "(", "'/^(select|show|set)/i'", ",", "$", "query", ")", "?", "'r'", ":", "'w'", ";", "$", "start", "=", "'['", ".", "$", "this", "->", "options", "[", "'identifier_start'", "]", ".", "self", "::", "DEFAULT_QUOTE", ".", "']'", ";", "$", "end", "=", "'['", ".", "$", "this", "->", "options", "[", "'identifier_end'", "]", ".", "self", "::", "DEFAULT_QUOTE", ".", "']'", ";", "$", "regex", "=", "'/(?:^|\\s)(from|update|into|join)\\s+'", ".", "$", "start", ".", "'?([a-z0-9._]+)'", ".", "$", "end", ".", "'?\\s+/i'", ";", "// find tables involved in this query", "if", "(", "preg_match_all", "(", "$", "regex", ",", "$", "query", ",", "$", "matches", ",", "PREG_SET_ORDER", ")", ")", "{", "foreach", "(", "$", "matches", "as", "$", "m", ")", "{", "$", "table", "=", "$", "m", "[", "2", "]", ";", "// always use direct mapping", "if", "(", "$", "this", "->", "options", "[", "'table_dsn_map'", "]", "[", "$", "table", "]", ")", "{", "$", "mode", "=", "$", "this", "->", "options", "[", "'table_dsn_map'", "]", "[", "$", "table", "]", ";", "break", ";", "// primary table rules", "}", "else", "if", "(", "$", "mode", "==", "'r'", ")", "{", "// connected to db with the same or \"higher\" mode for this table", "$", "db_mode", "=", "$", "this", "->", "table_connections", "[", "$", "table", "]", ";", "if", "(", "$", "db_mode", "==", "'w'", "&&", "!", "$", "this", "->", "options", "[", "'dsnw_noread'", "]", ")", "{", "$", "mode", "=", "$", "db_mode", ";", "}", "}", "}", "// remember mode chosen (for primary table)", "$", "table", "=", "$", "matches", "[", "0", "]", "[", "2", "]", ";", "$", "this", "->", "table_connections", "[", "$", "table", "]", "=", "$", "mode", ";", "}", "return", "$", "mode", ";", "}" ]
Analyze the given SQL statement and select the appropriate connection to use
[ "Analyze", "the", "given", "SQL", "statement", "and", "select", "the", "appropriate", "connection", "to", "use" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_db.php#L243-L282
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_db.php
rcube_db.is_error
public function is_error($result = null) { if ($result !== null) { return $result === false ? $this->db_error_msg : null; } return $this->db_error ? $this->db_error_msg : null; }
php
public function is_error($result = null) { if ($result !== null) { return $result === false ? $this->db_error_msg : null; } return $this->db_error ? $this->db_error_msg : null; }
[ "public", "function", "is_error", "(", "$", "result", "=", "null", ")", "{", "if", "(", "$", "result", "!==", "null", ")", "{", "return", "$", "result", "===", "false", "?", "$", "this", "->", "db_error_msg", ":", "null", ";", "}", "return", "$", "this", "->", "db_error", "?", "$", "this", "->", "db_error_msg", ":", "null", ";", "}" ]
Getter for error state @param mixed $result Optional query result @return string Error message
[ "Getter", "for", "error", "state" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_db.php#L318-L325
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_db.php
rcube_db.query
public function query() { $params = func_get_args(); $query = array_shift($params); // Support one argument of type array, instead of n arguments if (count($params) == 1 && is_array($params[0])) { $params = $params[0]; } return $this->_query($query, 0, 0, $params); }
php
public function query() { $params = func_get_args(); $query = array_shift($params); // Support one argument of type array, instead of n arguments if (count($params) == 1 && is_array($params[0])) { $params = $params[0]; } return $this->_query($query, 0, 0, $params); }
[ "public", "function", "query", "(", ")", "{", "$", "params", "=", "func_get_args", "(", ")", ";", "$", "query", "=", "array_shift", "(", "$", "params", ")", ";", "// Support one argument of type array, instead of n arguments", "if", "(", "count", "(", "$", "params", ")", "==", "1", "&&", "is_array", "(", "$", "params", "[", "0", "]", ")", ")", "{", "$", "params", "=", "$", "params", "[", "0", "]", ";", "}", "return", "$", "this", "->", "_query", "(", "$", "query", ",", "0", ",", "0", ",", "$", "params", ")", ";", "}" ]
Execute a SQL query @param string SQL query to execute @param mixed Values to be inserted in query @return number Query handle identifier
[ "Execute", "a", "SQL", "query" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_db.php#L369-L380
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_db.php
rcube_db.query_parse
protected function query_parse($query) { $start = $this->options['identifier_start']; $end = $this->options['identifier_end']; $quote = self::DEFAULT_QUOTE; if ($start == $quote) { return $query; } $pos = 0; $in = false; while ($pos = strpos($query, $quote, $pos)) { if ($query[$pos+1] == $quote) { // skip escaped quote $pos += 2; } else { if ($in) { $q = $end; $in = false; } else { $q = $start; $in = true; } $query = substr_replace($query, $q, $pos, 1); $pos++; } } return $query; }
php
protected function query_parse($query) { $start = $this->options['identifier_start']; $end = $this->options['identifier_end']; $quote = self::DEFAULT_QUOTE; if ($start == $quote) { return $query; } $pos = 0; $in = false; while ($pos = strpos($query, $quote, $pos)) { if ($query[$pos+1] == $quote) { // skip escaped quote $pos += 2; } else { if ($in) { $q = $end; $in = false; } else { $q = $start; $in = true; } $query = substr_replace($query, $q, $pos, 1); $pos++; } } return $query; }
[ "protected", "function", "query_parse", "(", "$", "query", ")", "{", "$", "start", "=", "$", "this", "->", "options", "[", "'identifier_start'", "]", ";", "$", "end", "=", "$", "this", "->", "options", "[", "'identifier_end'", "]", ";", "$", "quote", "=", "self", "::", "DEFAULT_QUOTE", ";", "if", "(", "$", "start", "==", "$", "quote", ")", "{", "return", "$", "query", ";", "}", "$", "pos", "=", "0", ";", "$", "in", "=", "false", ";", "while", "(", "$", "pos", "=", "strpos", "(", "$", "query", ",", "$", "quote", ",", "$", "pos", ")", ")", "{", "if", "(", "$", "query", "[", "$", "pos", "+", "1", "]", "==", "$", "quote", ")", "{", "// skip escaped quote", "$", "pos", "+=", "2", ";", "}", "else", "{", "if", "(", "$", "in", ")", "{", "$", "q", "=", "$", "end", ";", "$", "in", "=", "false", ";", "}", "else", "{", "$", "q", "=", "$", "start", ";", "$", "in", "=", "true", ";", "}", "$", "query", "=", "substr_replace", "(", "$", "query", ",", "$", "q", ",", "$", "pos", ",", "1", ")", ";", "$", "pos", "++", ";", "}", "}", "return", "$", "query", ";", "}" ]
Parse SQL query and replace identifier quoting @param string $query SQL query @return string SQL query
[ "Parse", "SQL", "query", "and", "replace", "identifier", "quoting" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_db.php#L490-L523
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_db.php
rcube_db.num_rows
public function num_rows($result = null) { if (($result || ($result === null && ($result = $this->last_result))) && $result !== true) { // repeat query with SELECT COUNT(*) ... if (preg_match('/^SELECT\s+(?:ALL\s+|DISTINCT\s+)?(?:.*?)\s+FROM\s+(.*)$/ims', $result->queryString, $m)) { $query = $this->dbh->query('SELECT COUNT(*) FROM ' . $m[1], PDO::FETCH_NUM); return $query ? intval($query->fetchColumn(0)) : false; } else { $num = count($result->fetchAll()); $result->execute(); // re-execute query because there's no seek(0) return $num; } } return false; }
php
public function num_rows($result = null) { if (($result || ($result === null && ($result = $this->last_result))) && $result !== true) { // repeat query with SELECT COUNT(*) ... if (preg_match('/^SELECT\s+(?:ALL\s+|DISTINCT\s+)?(?:.*?)\s+FROM\s+(.*)$/ims', $result->queryString, $m)) { $query = $this->dbh->query('SELECT COUNT(*) FROM ' . $m[1], PDO::FETCH_NUM); return $query ? intval($query->fetchColumn(0)) : false; } else { $num = count($result->fetchAll()); $result->execute(); // re-execute query because there's no seek(0) return $num; } } return false; }
[ "public", "function", "num_rows", "(", "$", "result", "=", "null", ")", "{", "if", "(", "(", "$", "result", "||", "(", "$", "result", "===", "null", "&&", "(", "$", "result", "=", "$", "this", "->", "last_result", ")", ")", ")", "&&", "$", "result", "!==", "true", ")", "{", "// repeat query with SELECT COUNT(*) ...", "if", "(", "preg_match", "(", "'/^SELECT\\s+(?:ALL\\s+|DISTINCT\\s+)?(?:.*?)\\s+FROM\\s+(.*)$/ims'", ",", "$", "result", "->", "queryString", ",", "$", "m", ")", ")", "{", "$", "query", "=", "$", "this", "->", "dbh", "->", "query", "(", "'SELECT COUNT(*) FROM '", ".", "$", "m", "[", "1", "]", ",", "PDO", "::", "FETCH_NUM", ")", ";", "return", "$", "query", "?", "intval", "(", "$", "query", "->", "fetchColumn", "(", "0", ")", ")", ":", "false", ";", "}", "else", "{", "$", "num", "=", "count", "(", "$", "result", "->", "fetchAll", "(", ")", ")", ";", "$", "result", "->", "execute", "(", ")", ";", "// re-execute query because there's no seek(0)", "return", "$", "num", ";", "}", "}", "return", "false", ";", "}" ]
Get number of rows for a SQL query If no query handle is specified, the last query will be taken as reference @param mixed $result Optional query handle @return mixed Number of rows or false on failure @deprecated This method shows very poor performance and should be avoided.
[ "Get", "number", "of", "rows", "for", "a", "SQL", "query", "If", "no", "query", "handle", "is", "specified", "the", "last", "query", "will", "be", "taken", "as", "reference" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_db.php#L579-L595
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_db.php
rcube_db.quote
public function quote($input, $type = null) { // handle int directly for better performance if ($type == 'integer' || $type == 'int') { return intval($input); } if (is_null($input)) { return 'NULL'; } if ($input instanceof DateTime) { return $this->quote($input->format($this->options['datetime_format'])); } if ($type == 'ident') { return $this->quote_identifier($input); } // create DB handle if not available if (!$this->dbh) { $this->db_connect('r'); } if ($this->dbh) { $map = array( 'bool' => PDO::PARAM_BOOL, 'integer' => PDO::PARAM_INT, ); $type = isset($map[$type]) ? $map[$type] : PDO::PARAM_STR; return strtr($this->dbh->quote($input, $type), // escape ? and ` array('?' => '??', self::DEFAULT_QUOTE => self::DEFAULT_QUOTE.self::DEFAULT_QUOTE) ); } return 'NULL'; }
php
public function quote($input, $type = null) { // handle int directly for better performance if ($type == 'integer' || $type == 'int') { return intval($input); } if (is_null($input)) { return 'NULL'; } if ($input instanceof DateTime) { return $this->quote($input->format($this->options['datetime_format'])); } if ($type == 'ident') { return $this->quote_identifier($input); } // create DB handle if not available if (!$this->dbh) { $this->db_connect('r'); } if ($this->dbh) { $map = array( 'bool' => PDO::PARAM_BOOL, 'integer' => PDO::PARAM_INT, ); $type = isset($map[$type]) ? $map[$type] : PDO::PARAM_STR; return strtr($this->dbh->quote($input, $type), // escape ? and ` array('?' => '??', self::DEFAULT_QUOTE => self::DEFAULT_QUOTE.self::DEFAULT_QUOTE) ); } return 'NULL'; }
[ "public", "function", "quote", "(", "$", "input", ",", "$", "type", "=", "null", ")", "{", "// handle int directly for better performance", "if", "(", "$", "type", "==", "'integer'", "||", "$", "type", "==", "'int'", ")", "{", "return", "intval", "(", "$", "input", ")", ";", "}", "if", "(", "is_null", "(", "$", "input", ")", ")", "{", "return", "'NULL'", ";", "}", "if", "(", "$", "input", "instanceof", "DateTime", ")", "{", "return", "$", "this", "->", "quote", "(", "$", "input", "->", "format", "(", "$", "this", "->", "options", "[", "'datetime_format'", "]", ")", ")", ";", "}", "if", "(", "$", "type", "==", "'ident'", ")", "{", "return", "$", "this", "->", "quote_identifier", "(", "$", "input", ")", ";", "}", "// create DB handle if not available", "if", "(", "!", "$", "this", "->", "dbh", ")", "{", "$", "this", "->", "db_connect", "(", "'r'", ")", ";", "}", "if", "(", "$", "this", "->", "dbh", ")", "{", "$", "map", "=", "array", "(", "'bool'", "=>", "PDO", "::", "PARAM_BOOL", ",", "'integer'", "=>", "PDO", "::", "PARAM_INT", ",", ")", ";", "$", "type", "=", "isset", "(", "$", "map", "[", "$", "type", "]", ")", "?", "$", "map", "[", "$", "type", "]", ":", "PDO", "::", "PARAM_STR", ";", "return", "strtr", "(", "$", "this", "->", "dbh", "->", "quote", "(", "$", "input", ",", "$", "type", ")", ",", "// escape ? and `", "array", "(", "'?'", "=>", "'??'", ",", "self", "::", "DEFAULT_QUOTE", "=>", "self", "::", "DEFAULT_QUOTE", ".", "self", "::", "DEFAULT_QUOTE", ")", ")", ";", "}", "return", "'NULL'", ";", "}" ]
Formats input so it can be safely used in a query @param mixed $input Value to quote @param string $type Type of data (integer, bool, ident) @return string Quoted/converted string for use in query
[ "Formats", "input", "so", "it", "can", "be", "safely", "used", "in", "a", "query" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_db.php#L814-L853
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_db.php
rcube_db.quote_identifier
public function quote_identifier($str) { $start = $this->options['identifier_start']; $end = $this->options['identifier_end']; $name = array(); foreach (explode('.', $str) as $elem) { $elem = str_replace(array($start, $end), '', $elem); $name[] = $start . $elem . $end; } return implode($name, '.'); }
php
public function quote_identifier($str) { $start = $this->options['identifier_start']; $end = $this->options['identifier_end']; $name = array(); foreach (explode('.', $str) as $elem) { $elem = str_replace(array($start, $end), '', $elem); $name[] = $start . $elem . $end; } return implode($name, '.'); }
[ "public", "function", "quote_identifier", "(", "$", "str", ")", "{", "$", "start", "=", "$", "this", "->", "options", "[", "'identifier_start'", "]", ";", "$", "end", "=", "$", "this", "->", "options", "[", "'identifier_end'", "]", ";", "$", "name", "=", "array", "(", ")", ";", "foreach", "(", "explode", "(", "'.'", ",", "$", "str", ")", "as", "$", "elem", ")", "{", "$", "elem", "=", "str_replace", "(", "array", "(", "$", "start", ",", "$", "end", ")", ",", "''", ",", "$", "elem", ")", ";", "$", "name", "[", "]", "=", "$", "start", ".", "$", "elem", ".", "$", "end", ";", "}", "return", "implode", "(", "$", "name", ",", "'.'", ")", ";", "}" ]
Quotes a string so it can be safely used as a table or column name @param string $str Value to quote @return string Quoted string for use in query
[ "Quotes", "a", "string", "so", "it", "can", "be", "safely", "used", "as", "a", "table", "or", "column", "name" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_db.php#L906-L918
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_db.php
rcube_db.now
public function now($interval = 0) { if ($interval) { $add = ' ' . ($interval > 0 ? '+' : '-') . ' INTERVAL '; $add .= $interval > 0 ? intval($interval) : intval($interval) * -1; $add .= ' SECOND'; } return "now()" . $add; }
php
public function now($interval = 0) { if ($interval) { $add = ' ' . ($interval > 0 ? '+' : '-') . ' INTERVAL '; $add .= $interval > 0 ? intval($interval) : intval($interval) * -1; $add .= ' SECOND'; } return "now()" . $add; }
[ "public", "function", "now", "(", "$", "interval", "=", "0", ")", "{", "if", "(", "$", "interval", ")", "{", "$", "add", "=", "' '", ".", "(", "$", "interval", ">", "0", "?", "'+'", ":", "'-'", ")", ".", "' INTERVAL '", ";", "$", "add", ".=", "$", "interval", ">", "0", "?", "intval", "(", "$", "interval", ")", ":", "intval", "(", "$", "interval", ")", "*", "-", "1", ";", "$", "add", ".=", "' SECOND'", ";", "}", "return", "\"now()\"", ".", "$", "add", ";", "}" ]
Return SQL function for current time and date @param int $interval Optional interval (in seconds) to add/subtract @return string SQL function to use in query
[ "Return", "SQL", "function", "for", "current", "time", "and", "date" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_db.php#L927-L936
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_db.php
rcube_db.array2list
public function array2list($arr, $type = null) { if (!is_array($arr)) { return $this->quote($arr, $type); } foreach ($arr as $idx => $item) { $arr[$idx] = $this->quote($item, $type); } return implode(',', $arr); }
php
public function array2list($arr, $type = null) { if (!is_array($arr)) { return $this->quote($arr, $type); } foreach ($arr as $idx => $item) { $arr[$idx] = $this->quote($item, $type); } return implode(',', $arr); }
[ "public", "function", "array2list", "(", "$", "arr", ",", "$", "type", "=", "null", ")", "{", "if", "(", "!", "is_array", "(", "$", "arr", ")", ")", "{", "return", "$", "this", "->", "quote", "(", "$", "arr", ",", "$", "type", ")", ";", "}", "foreach", "(", "$", "arr", "as", "$", "idx", "=>", "$", "item", ")", "{", "$", "arr", "[", "$", "idx", "]", "=", "$", "this", "->", "quote", "(", "$", "item", ",", "$", "type", ")", ";", "}", "return", "implode", "(", "','", ",", "$", "arr", ")", ";", "}" ]
Return list of elements for use with SQL's IN clause @param array $arr Input array @param string $type Type of data (integer, bool, ident) @return string Comma-separated list of quoted values for use in query
[ "Return", "list", "of", "elements", "for", "use", "with", "SQL", "s", "IN", "clause" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_db.php#L946-L957
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_db.php
rcube_db.table_name
public function table_name($table, $quoted = false) { // let plugins alter the table name (#1489837) $plugin = rcube::get_instance()->plugins->exec_hook('db_table_name', array('table' => $table)); $table = $plugin['table']; // add prefix to the table name if configured if (($prefix = $this->options['table_prefix']) && strpos($table, $prefix) !== 0) { $table = $prefix . $table; } if ($quoted) { $table = $this->quote_identifier($table); } return $table; }
php
public function table_name($table, $quoted = false) { // let plugins alter the table name (#1489837) $plugin = rcube::get_instance()->plugins->exec_hook('db_table_name', array('table' => $table)); $table = $plugin['table']; // add prefix to the table name if configured if (($prefix = $this->options['table_prefix']) && strpos($table, $prefix) !== 0) { $table = $prefix . $table; } if ($quoted) { $table = $this->quote_identifier($table); } return $table; }
[ "public", "function", "table_name", "(", "$", "table", ",", "$", "quoted", "=", "false", ")", "{", "// let plugins alter the table name (#1489837)", "$", "plugin", "=", "rcube", "::", "get_instance", "(", ")", "->", "plugins", "->", "exec_hook", "(", "'db_table_name'", ",", "array", "(", "'table'", "=>", "$", "table", ")", ")", ";", "$", "table", "=", "$", "plugin", "[", "'table'", "]", ";", "// add prefix to the table name if configured", "if", "(", "(", "$", "prefix", "=", "$", "this", "->", "options", "[", "'table_prefix'", "]", ")", "&&", "strpos", "(", "$", "table", ",", "$", "prefix", ")", "!==", "0", ")", "{", "$", "table", "=", "$", "prefix", ".", "$", "table", ";", "}", "if", "(", "$", "quoted", ")", "{", "$", "table", "=", "$", "this", "->", "quote_identifier", "(", "$", "table", ")", ";", "}", "return", "$", "table", ";", "}" ]
Return correct name for a specific database table @param string $table Table name @param bool $quoted Quote table identifier @return string Translated table name
[ "Return", "correct", "name", "for", "a", "specific", "database", "table" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_db.php#L1094-L1110
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_session_memcache.php
rcube_session_memcache.read
public function read($key) { if ($value = $this->memcache->get($key)) { $arr = unserialize($value); $this->changed = $arr['changed']; $this->ip = $arr['ip']; $this->vars = $arr['vars']; $this->key = $key; } if ($this->debug) { $this->debug('get', $key, $value); } return $this->vars ?: ''; }
php
public function read($key) { if ($value = $this->memcache->get($key)) { $arr = unserialize($value); $this->changed = $arr['changed']; $this->ip = $arr['ip']; $this->vars = $arr['vars']; $this->key = $key; } if ($this->debug) { $this->debug('get', $key, $value); } return $this->vars ?: ''; }
[ "public", "function", "read", "(", "$", "key", ")", "{", "if", "(", "$", "value", "=", "$", "this", "->", "memcache", "->", "get", "(", "$", "key", ")", ")", "{", "$", "arr", "=", "unserialize", "(", "$", "value", ")", ";", "$", "this", "->", "changed", "=", "$", "arr", "[", "'changed'", "]", ";", "$", "this", "->", "ip", "=", "$", "arr", "[", "'ip'", "]", ";", "$", "this", "->", "vars", "=", "$", "arr", "[", "'vars'", "]", ";", "$", "this", "->", "key", "=", "$", "key", ";", "}", "if", "(", "$", "this", "->", "debug", ")", "{", "$", "this", "->", "debug", "(", "'get'", ",", "$", "key", ",", "$", "value", ")", ";", "}", "return", "$", "this", "->", "vars", "?", ":", "''", ";", "}" ]
Read session data from memcache @param $key @return null|string
[ "Read", "session", "data", "from", "memcache" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_session_memcache.php#L102-L117
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_session_memcache.php
rcube_session_memcache.write
public function write($key, $vars) { $data = serialize(array('changed' => time(), 'ip' => $this->ip, 'vars' => $vars)); $result = $this->memcache->set($key, $data, MEMCACHE_COMPRESSED, $this->lifetime + 60); if ($this->debug) { $this->debug('set', $key, $data, $result); } return $result; }
php
public function write($key, $vars) { $data = serialize(array('changed' => time(), 'ip' => $this->ip, 'vars' => $vars)); $result = $this->memcache->set($key, $data, MEMCACHE_COMPRESSED, $this->lifetime + 60); if ($this->debug) { $this->debug('set', $key, $data, $result); } return $result; }
[ "public", "function", "write", "(", "$", "key", ",", "$", "vars", ")", "{", "$", "data", "=", "serialize", "(", "array", "(", "'changed'", "=>", "time", "(", ")", ",", "'ip'", "=>", "$", "this", "->", "ip", ",", "'vars'", "=>", "$", "vars", ")", ")", ";", "$", "result", "=", "$", "this", "->", "memcache", "->", "set", "(", "$", "key", ",", "$", "data", ",", "MEMCACHE_COMPRESSED", ",", "$", "this", "->", "lifetime", "+", "60", ")", ";", "if", "(", "$", "this", "->", "debug", ")", "{", "$", "this", "->", "debug", "(", "'set'", ",", "$", "key", ",", "$", "data", ",", "$", "result", ")", ";", "}", "return", "$", "result", ";", "}" ]
Write data to memcache storage @param $key @param $vars @return bool
[ "Write", "data", "to", "memcache", "storage" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_session_memcache.php#L127-L137
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_session_memcache.php
rcube_session_memcache.update
public function update($key, $newvars, $oldvars) { $ts = microtime(true); if ($newvars !== $oldvars || $ts - $this->changed > $this->lifetime / 3) { $data = serialize(array('changed' => time(), 'ip' => $this->ip, 'vars' => $newvars)); $result = $this->memcache->set($key, $data, MEMCACHE_COMPRESSED, $this->lifetime + 60); if ($this->debug) { $this->debug('set', $key, $data, $result); } return $result; } return true; }
php
public function update($key, $newvars, $oldvars) { $ts = microtime(true); if ($newvars !== $oldvars || $ts - $this->changed > $this->lifetime / 3) { $data = serialize(array('changed' => time(), 'ip' => $this->ip, 'vars' => $newvars)); $result = $this->memcache->set($key, $data, MEMCACHE_COMPRESSED, $this->lifetime + 60); if ($this->debug) { $this->debug('set', $key, $data, $result); } return $result; } return true; }
[ "public", "function", "update", "(", "$", "key", ",", "$", "newvars", ",", "$", "oldvars", ")", "{", "$", "ts", "=", "microtime", "(", "true", ")", ";", "if", "(", "$", "newvars", "!==", "$", "oldvars", "||", "$", "ts", "-", "$", "this", "->", "changed", ">", "$", "this", "->", "lifetime", "/", "3", ")", "{", "$", "data", "=", "serialize", "(", "array", "(", "'changed'", "=>", "time", "(", ")", ",", "'ip'", "=>", "$", "this", "->", "ip", ",", "'vars'", "=>", "$", "newvars", ")", ")", ";", "$", "result", "=", "$", "this", "->", "memcache", "->", "set", "(", "$", "key", ",", "$", "data", ",", "MEMCACHE_COMPRESSED", ",", "$", "this", "->", "lifetime", "+", "60", ")", ";", "if", "(", "$", "this", "->", "debug", ")", "{", "$", "this", "->", "debug", "(", "'set'", ",", "$", "key", ",", "$", "data", ",", "$", "result", ")", ";", "}", "return", "$", "result", ";", "}", "return", "true", ";", "}" ]
Update memcache session data @param $key @param $newvars @param $oldvars @return bool
[ "Update", "memcache", "session", "data" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_session_memcache.php#L148-L164
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_session_memcache.php
rcube_session_memcache.debug
protected function debug($type, $key, $data = null, $result = null) { $line = strtoupper($type) . ' ' . $key; if ($data !== null) { $line .= ' ' . $data; } rcube::debug('memcache', $line, $result); }
php
protected function debug($type, $key, $data = null, $result = null) { $line = strtoupper($type) . ' ' . $key; if ($data !== null) { $line .= ' ' . $data; } rcube::debug('memcache', $line, $result); }
[ "protected", "function", "debug", "(", "$", "type", ",", "$", "key", ",", "$", "data", "=", "null", ",", "$", "result", "=", "null", ")", "{", "$", "line", "=", "strtoupper", "(", "$", "type", ")", ".", "' '", ".", "$", "key", ";", "if", "(", "$", "data", "!==", "null", ")", "{", "$", "line", ".=", "' '", ".", "$", "data", ";", "}", "rcube", "::", "debug", "(", "'memcache'", ",", "$", "line", ",", "$", "result", ")", ";", "}" ]
Write memcache debug info to the log
[ "Write", "memcache", "debug", "info", "to", "the", "log" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_session_memcache.php#L169-L178
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_utils.php
rcmail_utils.db
public static function db() { if (self::$db === null) { $rc = rcube::get_instance(); $db = rcube_db::factory($rc->config->get('db_dsnw')); $db->set_debug((bool)$rc->config->get('sql_debug')); // Connect to database $db->db_connect('w'); if (!$db->is_connected()) { rcube::raise_error("Error connecting to database: " . $db->is_error(), false, true); } self::$db = $db; } return self::$db; }
php
public static function db() { if (self::$db === null) { $rc = rcube::get_instance(); $db = rcube_db::factory($rc->config->get('db_dsnw')); $db->set_debug((bool)$rc->config->get('sql_debug')); // Connect to database $db->db_connect('w'); if (!$db->is_connected()) { rcube::raise_error("Error connecting to database: " . $db->is_error(), false, true); } self::$db = $db; } return self::$db; }
[ "public", "static", "function", "db", "(", ")", "{", "if", "(", "self", "::", "$", "db", "===", "null", ")", "{", "$", "rc", "=", "rcube", "::", "get_instance", "(", ")", ";", "$", "db", "=", "rcube_db", "::", "factory", "(", "$", "rc", "->", "config", "->", "get", "(", "'db_dsnw'", ")", ")", ";", "$", "db", "->", "set_debug", "(", "(", "bool", ")", "$", "rc", "->", "config", "->", "get", "(", "'sql_debug'", ")", ")", ";", "// Connect to database", "$", "db", "->", "db_connect", "(", "'w'", ")", ";", "if", "(", "!", "$", "db", "->", "is_connected", "(", ")", ")", "{", "rcube", "::", "raise_error", "(", "\"Error connecting to database: \"", ".", "$", "db", "->", "is_error", "(", ")", ",", "false", ",", "true", ")", ";", "}", "self", "::", "$", "db", "=", "$", "db", ";", "}", "return", "self", "::", "$", "db", ";", "}" ]
Initialize database object and connect @return rcube_db Database instance
[ "Initialize", "database", "object", "and", "connect" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_utils.php#L38-L57
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_utils.php
rcmail_utils.db_init
public static function db_init($dir) { $db = self::db(); $file = $dir . '/' . $db->db_provider . '.initial.sql'; if (!file_exists($file)) { rcube::raise_error("DDL file $file not found", false, true); } echo "Creating database schema... "; if ($sql = file_get_contents($file)) { if (!$db->exec_script($sql)) { $error = $db->is_error(); } } else { $error = "Unable to read file $file or it is empty"; } if ($error) { echo "[FAILED]\n"; rcube::raise_error($error, false, true); } else { echo "[OK]\n"; } }
php
public static function db_init($dir) { $db = self::db(); $file = $dir . '/' . $db->db_provider . '.initial.sql'; if (!file_exists($file)) { rcube::raise_error("DDL file $file not found", false, true); } echo "Creating database schema... "; if ($sql = file_get_contents($file)) { if (!$db->exec_script($sql)) { $error = $db->is_error(); } } else { $error = "Unable to read file $file or it is empty"; } if ($error) { echo "[FAILED]\n"; rcube::raise_error($error, false, true); } else { echo "[OK]\n"; } }
[ "public", "static", "function", "db_init", "(", "$", "dir", ")", "{", "$", "db", "=", "self", "::", "db", "(", ")", ";", "$", "file", "=", "$", "dir", ".", "'/'", ".", "$", "db", "->", "db_provider", ".", "'.initial.sql'", ";", "if", "(", "!", "file_exists", "(", "$", "file", ")", ")", "{", "rcube", "::", "raise_error", "(", "\"DDL file $file not found\"", ",", "false", ",", "true", ")", ";", "}", "echo", "\"Creating database schema... \"", ";", "if", "(", "$", "sql", "=", "file_get_contents", "(", "$", "file", ")", ")", "{", "if", "(", "!", "$", "db", "->", "exec_script", "(", "$", "sql", ")", ")", "{", "$", "error", "=", "$", "db", "->", "is_error", "(", ")", ";", "}", "}", "else", "{", "$", "error", "=", "\"Unable to read file $file or it is empty\"", ";", "}", "if", "(", "$", "error", ")", "{", "echo", "\"[FAILED]\\n\"", ";", "rcube", "::", "raise_error", "(", "$", "error", ",", "false", ",", "true", ")", ";", "}", "else", "{", "echo", "\"[OK]\\n\"", ";", "}", "}" ]
Initialize database schema @param string $dir Directory with sql files
[ "Initialize", "database", "schema" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_utils.php#L64-L91
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_utils.php
rcmail_utils.db_update_schema
protected static function db_update_schema($package, $version, $file) { $db = self::db(); // read DDL file if ($sql = file_get_contents($file)) { if (!$db->exec_script($sql)) { return $db->is_error(); } } // escape if 'system' table does not exist if ($version < 2013011000) { return; } $system_table = $db->table_name('system', true); $db->query("UPDATE " . $system_table . " SET `value` = ?" . " WHERE `name` = ?", $version, $package . '-version'); if (!$db->is_error() && !$db->affected_rows()) { $db->query("INSERT INTO " . $system_table ." (`name`, `value`) VALUES (?, ?)", $package . '-version', $version); } return $db->is_error(); }
php
protected static function db_update_schema($package, $version, $file) { $db = self::db(); // read DDL file if ($sql = file_get_contents($file)) { if (!$db->exec_script($sql)) { return $db->is_error(); } } // escape if 'system' table does not exist if ($version < 2013011000) { return; } $system_table = $db->table_name('system', true); $db->query("UPDATE " . $system_table . " SET `value` = ?" . " WHERE `name` = ?", $version, $package . '-version'); if (!$db->is_error() && !$db->affected_rows()) { $db->query("INSERT INTO " . $system_table ." (`name`, `value`) VALUES (?, ?)", $package . '-version', $version); } return $db->is_error(); }
[ "protected", "static", "function", "db_update_schema", "(", "$", "package", ",", "$", "version", ",", "$", "file", ")", "{", "$", "db", "=", "self", "::", "db", "(", ")", ";", "// read DDL file", "if", "(", "$", "sql", "=", "file_get_contents", "(", "$", "file", ")", ")", "{", "if", "(", "!", "$", "db", "->", "exec_script", "(", "$", "sql", ")", ")", "{", "return", "$", "db", "->", "is_error", "(", ")", ";", "}", "}", "// escape if 'system' table does not exist", "if", "(", "$", "version", "<", "2013011000", ")", "{", "return", ";", "}", "$", "system_table", "=", "$", "db", "->", "table_name", "(", "'system'", ",", "true", ")", ";", "$", "db", "->", "query", "(", "\"UPDATE \"", ".", "$", "system_table", ".", "\" SET `value` = ?\"", ".", "\" WHERE `name` = ?\"", ",", "$", "version", ",", "$", "package", ".", "'-version'", ")", ";", "if", "(", "!", "$", "db", "->", "is_error", "(", ")", "&&", "!", "$", "db", "->", "affected_rows", "(", ")", ")", "{", "$", "db", "->", "query", "(", "\"INSERT INTO \"", ".", "$", "system_table", ".", "\" (`name`, `value`) VALUES (?, ?)\"", ",", "$", "package", ".", "'-version'", ",", "$", "version", ")", ";", "}", "return", "$", "db", "->", "is_error", "(", ")", ";", "}" ]
Run database update from a single sql file
[ "Run", "database", "update", "from", "a", "single", "sql", "file" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_utils.php#L226-L256
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_utils.php
rcmail_utils.db_clean
public static function db_clean($days) { // mapping for table name => primary key $primary_keys = array( 'contacts' => 'contact_id', 'contactgroups' => 'contactgroup_id', ); $db = self::db(); $threshold = date('Y-m-d 00:00:00', time() - $days * 86400); foreach (array('contacts','contactgroups','identities') as $table) { $sqltable = $db->table_name($table, true); // also delete linked records // could be skipped for databases which respect foreign key constraints if ($db->db_provider == 'sqlite' && ($table == 'contacts' || $table == 'contactgroups')) { $pk = $primary_keys[$table]; $memberstable = $db->table_name('contactgroupmembers'); $db->query( "DELETE FROM " . $db->quote_identifier($memberstable) . " WHERE `$pk` IN (" . "SELECT `$pk` FROM $sqltable" . " WHERE `del` = 1 AND `changed` < ?" . ")", $threshold); echo $db->affected_rows() . " records deleted from '$memberstable'\n"; } // delete outdated records $db->query("DELETE FROM $sqltable WHERE `del` = 1 AND `changed` < ?", $threshold); echo $db->affected_rows() . " records deleted from '$table'\n"; } }
php
public static function db_clean($days) { // mapping for table name => primary key $primary_keys = array( 'contacts' => 'contact_id', 'contactgroups' => 'contactgroup_id', ); $db = self::db(); $threshold = date('Y-m-d 00:00:00', time() - $days * 86400); foreach (array('contacts','contactgroups','identities') as $table) { $sqltable = $db->table_name($table, true); // also delete linked records // could be skipped for databases which respect foreign key constraints if ($db->db_provider == 'sqlite' && ($table == 'contacts' || $table == 'contactgroups')) { $pk = $primary_keys[$table]; $memberstable = $db->table_name('contactgroupmembers'); $db->query( "DELETE FROM " . $db->quote_identifier($memberstable) . " WHERE `$pk` IN (" . "SELECT `$pk` FROM $sqltable" . " WHERE `del` = 1 AND `changed` < ?" . ")", $threshold); echo $db->affected_rows() . " records deleted from '$memberstable'\n"; } // delete outdated records $db->query("DELETE FROM $sqltable WHERE `del` = 1 AND `changed` < ?", $threshold); echo $db->affected_rows() . " records deleted from '$table'\n"; } }
[ "public", "static", "function", "db_clean", "(", "$", "days", ")", "{", "// mapping for table name => primary key", "$", "primary_keys", "=", "array", "(", "'contacts'", "=>", "'contact_id'", ",", "'contactgroups'", "=>", "'contactgroup_id'", ",", ")", ";", "$", "db", "=", "self", "::", "db", "(", ")", ";", "$", "threshold", "=", "date", "(", "'Y-m-d 00:00:00'", ",", "time", "(", ")", "-", "$", "days", "*", "86400", ")", ";", "foreach", "(", "array", "(", "'contacts'", ",", "'contactgroups'", ",", "'identities'", ")", "as", "$", "table", ")", "{", "$", "sqltable", "=", "$", "db", "->", "table_name", "(", "$", "table", ",", "true", ")", ";", "// also delete linked records", "// could be skipped for databases which respect foreign key constraints", "if", "(", "$", "db", "->", "db_provider", "==", "'sqlite'", "&&", "(", "$", "table", "==", "'contacts'", "||", "$", "table", "==", "'contactgroups'", ")", ")", "{", "$", "pk", "=", "$", "primary_keys", "[", "$", "table", "]", ";", "$", "memberstable", "=", "$", "db", "->", "table_name", "(", "'contactgroupmembers'", ")", ";", "$", "db", "->", "query", "(", "\"DELETE FROM \"", ".", "$", "db", "->", "quote_identifier", "(", "$", "memberstable", ")", ".", "\" WHERE `$pk` IN (\"", ".", "\"SELECT `$pk` FROM $sqltable\"", ".", "\" WHERE `del` = 1 AND `changed` < ?\"", ".", "\")\"", ",", "$", "threshold", ")", ";", "echo", "$", "db", "->", "affected_rows", "(", ")", ".", "\" records deleted from '$memberstable'\\n\"", ";", "}", "// delete outdated records", "$", "db", "->", "query", "(", "\"DELETE FROM $sqltable WHERE `del` = 1 AND `changed` < ?\"", ",", "$", "threshold", ")", ";", "echo", "$", "db", "->", "affected_rows", "(", ")", ".", "\" records deleted from '$table'\\n\"", ";", "}", "}" ]
Removes all deleted records older than X days @param int $days Number of days
[ "Removes", "all", "deleted", "records", "older", "than", "X", "days" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_utils.php#L263-L300
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_utils.php
rcmail_utils.mod_pref
public static function mod_pref($name, $value, $userid = null, $type = 'string') { $db = self::db(); if ($userid) { $query = '`user_id` = ' . intval($userid); } else { $query = '1=1'; } $type = strtolower($type); if ($type == 'bool' || $type == 'boolean') { $value = rcube_utils::get_boolean($value); } else if ($type == 'int' || $type == 'integer') { $value = (int) $value; } // iterate over all users $sql_result = $db->query("SELECT * FROM " . $db->table_name('users', true) . " WHERE $query"); while ($sql_result && ($sql_arr = $db->fetch_assoc($sql_result))) { echo "Updating prefs for user " . $sql_arr['user_id'] . "..."; $user = new rcube_user($sql_arr['user_id'], $sql_arr); $prefs = $old_prefs = $user->get_prefs(); $prefs[$name] = $value; if ($prefs != $old_prefs) { $user->save_prefs($prefs, true); echo "saved.\n"; } else { echo "nothing changed.\n"; } } }
php
public static function mod_pref($name, $value, $userid = null, $type = 'string') { $db = self::db(); if ($userid) { $query = '`user_id` = ' . intval($userid); } else { $query = '1=1'; } $type = strtolower($type); if ($type == 'bool' || $type == 'boolean') { $value = rcube_utils::get_boolean($value); } else if ($type == 'int' || $type == 'integer') { $value = (int) $value; } // iterate over all users $sql_result = $db->query("SELECT * FROM " . $db->table_name('users', true) . " WHERE $query"); while ($sql_result && ($sql_arr = $db->fetch_assoc($sql_result))) { echo "Updating prefs for user " . $sql_arr['user_id'] . "..."; $user = new rcube_user($sql_arr['user_id'], $sql_arr); $prefs = $old_prefs = $user->get_prefs(); $prefs[$name] = $value; if ($prefs != $old_prefs) { $user->save_prefs($prefs, true); echo "saved.\n"; } else { echo "nothing changed.\n"; } } }
[ "public", "static", "function", "mod_pref", "(", "$", "name", ",", "$", "value", ",", "$", "userid", "=", "null", ",", "$", "type", "=", "'string'", ")", "{", "$", "db", "=", "self", "::", "db", "(", ")", ";", "if", "(", "$", "userid", ")", "{", "$", "query", "=", "'`user_id` = '", ".", "intval", "(", "$", "userid", ")", ";", "}", "else", "{", "$", "query", "=", "'1=1'", ";", "}", "$", "type", "=", "strtolower", "(", "$", "type", ")", ";", "if", "(", "$", "type", "==", "'bool'", "||", "$", "type", "==", "'boolean'", ")", "{", "$", "value", "=", "rcube_utils", "::", "get_boolean", "(", "$", "value", ")", ";", "}", "else", "if", "(", "$", "type", "==", "'int'", "||", "$", "type", "==", "'integer'", ")", "{", "$", "value", "=", "(", "int", ")", "$", "value", ";", "}", "// iterate over all users", "$", "sql_result", "=", "$", "db", "->", "query", "(", "\"SELECT * FROM \"", ".", "$", "db", "->", "table_name", "(", "'users'", ",", "true", ")", ".", "\" WHERE $query\"", ")", ";", "while", "(", "$", "sql_result", "&&", "(", "$", "sql_arr", "=", "$", "db", "->", "fetch_assoc", "(", "$", "sql_result", ")", ")", ")", "{", "echo", "\"Updating prefs for user \"", ".", "$", "sql_arr", "[", "'user_id'", "]", ".", "\"...\"", ";", "$", "user", "=", "new", "rcube_user", "(", "$", "sql_arr", "[", "'user_id'", "]", ",", "$", "sql_arr", ")", ";", "$", "prefs", "=", "$", "old_prefs", "=", "$", "user", "->", "get_prefs", "(", ")", ";", "$", "prefs", "[", "$", "name", "]", "=", "$", "value", ";", "if", "(", "$", "prefs", "!=", "$", "old_prefs", ")", "{", "$", "user", "->", "save_prefs", "(", "$", "prefs", ",", "true", ")", ";", "echo", "\"saved.\\n\"", ";", "}", "else", "{", "echo", "\"nothing changed.\\n\"", ";", "}", "}", "}" ]
Modify user preferences @param string $name Option name @param string $value Option value @param int $userid Optional user identifier @param string $type Optional value type (bool, int, string)
[ "Modify", "user", "preferences" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_utils.php#L335-L374
train
i-MSCP/roundcube
roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_vacation.php
rcube_sieve_vacation.vacation_interval
public static function vacation_interval(&$vacation) { $rcube = rcube::get_instance(); if (isset($vacation['seconds'])) { $interval = $vacation['seconds']; } else if (isset($vacation['days'])) { $interval = $vacation['days']; } else if ($interval_cfg = $rcube->config->get('managesieve_vacation_interval')) { if (preg_match('/^([0-9]+)s$/', $interval_cfg, $m)) { if ($seconds_extension) { $vacation['seconds'] = ($interval = intval($m[1])) ? $interval : null; } else { $vacation['days'] = $interval = ceil(intval($m[1])/86400); } } else { $vacation['days'] = $interval = intval($interval_cfg); } } return $interval ?: ''; }
php
public static function vacation_interval(&$vacation) { $rcube = rcube::get_instance(); if (isset($vacation['seconds'])) { $interval = $vacation['seconds']; } else if (isset($vacation['days'])) { $interval = $vacation['days']; } else if ($interval_cfg = $rcube->config->get('managesieve_vacation_interval')) { if (preg_match('/^([0-9]+)s$/', $interval_cfg, $m)) { if ($seconds_extension) { $vacation['seconds'] = ($interval = intval($m[1])) ? $interval : null; } else { $vacation['days'] = $interval = ceil(intval($m[1])/86400); } } else { $vacation['days'] = $interval = intval($interval_cfg); } } return $interval ?: ''; }
[ "public", "static", "function", "vacation_interval", "(", "&", "$", "vacation", ")", "{", "$", "rcube", "=", "rcube", "::", "get_instance", "(", ")", ";", "if", "(", "isset", "(", "$", "vacation", "[", "'seconds'", "]", ")", ")", "{", "$", "interval", "=", "$", "vacation", "[", "'seconds'", "]", ";", "}", "else", "if", "(", "isset", "(", "$", "vacation", "[", "'days'", "]", ")", ")", "{", "$", "interval", "=", "$", "vacation", "[", "'days'", "]", ";", "}", "else", "if", "(", "$", "interval_cfg", "=", "$", "rcube", "->", "config", "->", "get", "(", "'managesieve_vacation_interval'", ")", ")", "{", "if", "(", "preg_match", "(", "'/^([0-9]+)s$/'", ",", "$", "interval_cfg", ",", "$", "m", ")", ")", "{", "if", "(", "$", "seconds_extension", ")", "{", "$", "vacation", "[", "'seconds'", "]", "=", "(", "$", "interval", "=", "intval", "(", "$", "m", "[", "1", "]", ")", ")", "?", "$", "interval", ":", "null", ";", "}", "else", "{", "$", "vacation", "[", "'days'", "]", "=", "$", "interval", "=", "ceil", "(", "intval", "(", "$", "m", "[", "1", "]", ")", "/", "86400", ")", ";", "}", "}", "else", "{", "$", "vacation", "[", "'days'", "]", "=", "$", "interval", "=", "intval", "(", "$", "interval_cfg", ")", ";", "}", "}", "return", "$", "interval", "?", ":", "''", ";", "}" ]
Get current vacation interval
[ "Get", "current", "vacation", "interval" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_vacation.php#L588-L613
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/html.php
html.show
public function show() { return self::tag($this->tagname, $this->attrib, $this->content, array_merge(self::$common_attrib, $this->allowed)); }
php
public function show() { return self::tag($this->tagname, $this->attrib, $this->content, array_merge(self::$common_attrib, $this->allowed)); }
[ "public", "function", "show", "(", ")", "{", "return", "self", "::", "tag", "(", "$", "this", "->", "tagname", ",", "$", "this", "->", "attrib", ",", "$", "this", "->", "content", ",", "array_merge", "(", "self", "::", "$", "common_attrib", ",", "$", "this", "->", "allowed", ")", ")", ";", "}" ]
Return the tag code @return string The finally composed HTML tag
[ "Return", "the", "tag", "code" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/html.php#L56-L59
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/html.php
html.tag
public static function tag($tagname, $attrib = array(), $content = null, $allowed = null) { if (is_string($attrib)) { $attrib = array('class' => $attrib); } $inline_tags = array('a','span','img'); $suffix = $attrib['nl'] || ($content && $attrib['nl'] !== false && !in_array($tagname, $inline_tags)) ? "\n" : ''; $tagname = self::$lc_tags ? strtolower($tagname) : $tagname; if (isset($content) || in_array($tagname, self::$containers)) { $suffix = $attrib['noclose'] ? $suffix : '</' . $tagname . '>' . $suffix; unset($attrib['noclose'], $attrib['nl']); return '<' . $tagname . self::attrib_string($attrib, $allowed) . '>' . $content . $suffix; } else { return '<' . $tagname . self::attrib_string($attrib, $allowed) . '>' . $suffix; } }
php
public static function tag($tagname, $attrib = array(), $content = null, $allowed = null) { if (is_string($attrib)) { $attrib = array('class' => $attrib); } $inline_tags = array('a','span','img'); $suffix = $attrib['nl'] || ($content && $attrib['nl'] !== false && !in_array($tagname, $inline_tags)) ? "\n" : ''; $tagname = self::$lc_tags ? strtolower($tagname) : $tagname; if (isset($content) || in_array($tagname, self::$containers)) { $suffix = $attrib['noclose'] ? $suffix : '</' . $tagname . '>' . $suffix; unset($attrib['noclose'], $attrib['nl']); return '<' . $tagname . self::attrib_string($attrib, $allowed) . '>' . $content . $suffix; } else { return '<' . $tagname . self::attrib_string($attrib, $allowed) . '>' . $suffix; } }
[ "public", "static", "function", "tag", "(", "$", "tagname", ",", "$", "attrib", "=", "array", "(", ")", ",", "$", "content", "=", "null", ",", "$", "allowed", "=", "null", ")", "{", "if", "(", "is_string", "(", "$", "attrib", ")", ")", "{", "$", "attrib", "=", "array", "(", "'class'", "=>", "$", "attrib", ")", ";", "}", "$", "inline_tags", "=", "array", "(", "'a'", ",", "'span'", ",", "'img'", ")", ";", "$", "suffix", "=", "$", "attrib", "[", "'nl'", "]", "||", "(", "$", "content", "&&", "$", "attrib", "[", "'nl'", "]", "!==", "false", "&&", "!", "in_array", "(", "$", "tagname", ",", "$", "inline_tags", ")", ")", "?", "\"\\n\"", ":", "''", ";", "$", "tagname", "=", "self", "::", "$", "lc_tags", "?", "strtolower", "(", "$", "tagname", ")", ":", "$", "tagname", ";", "if", "(", "isset", "(", "$", "content", ")", "||", "in_array", "(", "$", "tagname", ",", "self", "::", "$", "containers", ")", ")", "{", "$", "suffix", "=", "$", "attrib", "[", "'noclose'", "]", "?", "$", "suffix", ":", "'</'", ".", "$", "tagname", ".", "'>'", ".", "$", "suffix", ";", "unset", "(", "$", "attrib", "[", "'noclose'", "]", ",", "$", "attrib", "[", "'nl'", "]", ")", ";", "return", "'<'", ".", "$", "tagname", ".", "self", "::", "attrib_string", "(", "$", "attrib", ",", "$", "allowed", ")", ".", "'>'", ".", "$", "content", ".", "$", "suffix", ";", "}", "else", "{", "return", "'<'", ".", "$", "tagname", ".", "self", "::", "attrib_string", "(", "$", "attrib", ",", "$", "allowed", ")", ".", "'>'", ".", "$", "suffix", ";", "}", "}" ]
Generic method to create a HTML tag @param string $tagname Tag name @param array $attrib Tag attributes as key/value pairs @param string $content Optional Tag content (creates a container tag) @param array $allowed List with allowed attributes, omit to allow all @return string The XHTML tag
[ "Generic", "method", "to", "create", "a", "HTML", "tag" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/html.php#L73-L91
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/html.php
html.doctype
public static function doctype($type) { $doctypes = array( 'html5' => '<!DOCTYPE html>', 'xhtml' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', 'xhtml-trans' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', 'xhtml-strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', ); if ($doctypes[$type]) { self::$doctype = preg_replace('/-\w+$/', '', $type); return $doctypes[$type]; } return ''; }
php
public static function doctype($type) { $doctypes = array( 'html5' => '<!DOCTYPE html>', 'xhtml' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', 'xhtml-trans' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', 'xhtml-strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', ); if ($doctypes[$type]) { self::$doctype = preg_replace('/-\w+$/', '', $type); return $doctypes[$type]; } return ''; }
[ "public", "static", "function", "doctype", "(", "$", "type", ")", "{", "$", "doctypes", "=", "array", "(", "'html5'", "=>", "'<!DOCTYPE html>'", ",", "'xhtml'", "=>", "'<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">'", ",", "'xhtml-trans'", "=>", "'<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">'", ",", "'xhtml-strict'", "=>", "'<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">'", ",", ")", ";", "if", "(", "$", "doctypes", "[", "$", "type", "]", ")", "{", "self", "::", "$", "doctype", "=", "preg_replace", "(", "'/-\\w+$/'", ",", "''", ",", "$", "type", ")", ";", "return", "$", "doctypes", "[", "$", "type", "]", ";", "}", "return", "''", ";", "}" ]
Return DOCTYPE tag of specified type @param string $type Document type (html5, xhtml, 'xhtml-trans, xhtml-strict)
[ "Return", "DOCTYPE", "tag", "of", "specified", "type" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/html.php#L98-L113
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/html.php
html.a
public static function a($attr, $cont) { if (is_string($attr)) { $attr = array('href' => $attr); } return self::tag('a', $attr, $cont, array_merge(self::$common_attrib, array('href','target','name','rel','onclick','onmouseover','onmouseout','onmousedown','onmouseup'))); }
php
public static function a($attr, $cont) { if (is_string($attr)) { $attr = array('href' => $attr); } return self::tag('a', $attr, $cont, array_merge(self::$common_attrib, array('href','target','name','rel','onclick','onmouseover','onmouseout','onmousedown','onmouseup'))); }
[ "public", "static", "function", "a", "(", "$", "attr", ",", "$", "cont", ")", "{", "if", "(", "is_string", "(", "$", "attr", ")", ")", "{", "$", "attr", "=", "array", "(", "'href'", "=>", "$", "attr", ")", ";", "}", "return", "self", "::", "tag", "(", "'a'", ",", "$", "attr", ",", "$", "cont", ",", "array_merge", "(", "self", "::", "$", "common_attrib", ",", "array", "(", "'href'", ",", "'target'", ",", "'name'", ",", "'rel'", ",", "'onclick'", ",", "'onmouseover'", ",", "'onmouseout'", ",", "'onmousedown'", ",", "'onmouseup'", ")", ")", ")", ";", "}" ]
Derrived method for link tags @param mixed $attr Hash array with tag attributes or string with link location (href) @param string $cont Link content @return string HTML code @see html::tag()
[ "Derrived", "method", "for", "link", "tags" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/html.php#L178-L186
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/html.php
html.span
public static function span($attr, $cont) { if (is_string($attr)) { $attr = array('class' => $attr); } return self::tag('span', $attr, $cont, self::$common_attrib); }
php
public static function span($attr, $cont) { if (is_string($attr)) { $attr = array('class' => $attr); } return self::tag('span', $attr, $cont, self::$common_attrib); }
[ "public", "static", "function", "span", "(", "$", "attr", ",", "$", "cont", ")", "{", "if", "(", "is_string", "(", "$", "attr", ")", ")", "{", "$", "attr", "=", "array", "(", "'class'", "=>", "$", "attr", ")", ";", "}", "return", "self", "::", "tag", "(", "'span'", ",", "$", "attr", ",", "$", "cont", ",", "self", "::", "$", "common_attrib", ")", ";", "}" ]
Derrived method for inline span tags @param mixed $attr Hash array with tag attributes or string with class name @param string $cont Tag content @return string HTML code @see html::tag()
[ "Derrived", "method", "for", "inline", "span", "tags" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/html.php#L197-L204
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/html.php
html.label
public static function label($attr, $cont) { if (is_string($attr)) { $attr = array('for' => $attr); } return self::tag('label', $attr, $cont, array_merge(self::$common_attrib, array('for','onkeypress'))); }
php
public static function label($attr, $cont) { if (is_string($attr)) { $attr = array('for' => $attr); } return self::tag('label', $attr, $cont, array_merge(self::$common_attrib, array('for','onkeypress'))); }
[ "public", "static", "function", "label", "(", "$", "attr", ",", "$", "cont", ")", "{", "if", "(", "is_string", "(", "$", "attr", ")", ")", "{", "$", "attr", "=", "array", "(", "'for'", "=>", "$", "attr", ")", ";", "}", "return", "self", "::", "tag", "(", "'label'", ",", "$", "attr", ",", "$", "cont", ",", "array_merge", "(", "self", "::", "$", "common_attrib", ",", "array", "(", "'for'", ",", "'onkeypress'", ")", ")", ")", ";", "}" ]
Derrived method for form element labels @param mixed $attr Hash array with tag attributes or string with 'for' attrib @param string $cont Tag content @return string HTML code @see html::tag()
[ "Derrived", "method", "for", "form", "element", "labels" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/html.php#L215-L223
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/html.php
html.attrib_string
public static function attrib_string($attrib = array(), $allowed = null) { if (empty($attrib)) { return ''; } $allowed_f = array_flip((array)$allowed); $attrib_arr = array(); foreach ($attrib as $key => $value) { // skip size if not numeric if ($key == 'size' && !is_numeric($value)) { continue; } // ignore "internal" or empty attributes if ($key == 'nl' || $value === null) { continue; } // ignore not allowed attributes, except aria-* and data-* if (!empty($allowed)) { $is_data_attr = @substr_compare($key, 'data-', 0, 5) === 0; $is_aria_attr = @substr_compare($key, 'aria-', 0, 5) === 0; if (!$is_aria_attr && !$is_data_attr && !isset($allowed_f[$key])) { continue; } } // skip empty eventhandlers if (preg_match('/^on[a-z]+/', $key) && !$value) { continue; } // attributes with no value if (in_array($key, self::$bool_attrib)) { if ($value) { $value = $key; if (self::$doctype == 'xhtml') { $value .= '="' . $value . '"'; } $attrib_arr[] = $value; } } else { $attrib_arr[] = $key . '="' . self::quote($value) . '"'; } } return count($attrib_arr) ? ' '.implode(' ', $attrib_arr) : ''; }
php
public static function attrib_string($attrib = array(), $allowed = null) { if (empty($attrib)) { return ''; } $allowed_f = array_flip((array)$allowed); $attrib_arr = array(); foreach ($attrib as $key => $value) { // skip size if not numeric if ($key == 'size' && !is_numeric($value)) { continue; } // ignore "internal" or empty attributes if ($key == 'nl' || $value === null) { continue; } // ignore not allowed attributes, except aria-* and data-* if (!empty($allowed)) { $is_data_attr = @substr_compare($key, 'data-', 0, 5) === 0; $is_aria_attr = @substr_compare($key, 'aria-', 0, 5) === 0; if (!$is_aria_attr && !$is_data_attr && !isset($allowed_f[$key])) { continue; } } // skip empty eventhandlers if (preg_match('/^on[a-z]+/', $key) && !$value) { continue; } // attributes with no value if (in_array($key, self::$bool_attrib)) { if ($value) { $value = $key; if (self::$doctype == 'xhtml') { $value .= '="' . $value . '"'; } $attrib_arr[] = $value; } } else { $attrib_arr[] = $key . '="' . self::quote($value) . '"'; } } return count($attrib_arr) ? ' '.implode(' ', $attrib_arr) : ''; }
[ "public", "static", "function", "attrib_string", "(", "$", "attrib", "=", "array", "(", ")", ",", "$", "allowed", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "attrib", ")", ")", "{", "return", "''", ";", "}", "$", "allowed_f", "=", "array_flip", "(", "(", "array", ")", "$", "allowed", ")", ";", "$", "attrib_arr", "=", "array", "(", ")", ";", "foreach", "(", "$", "attrib", "as", "$", "key", "=>", "$", "value", ")", "{", "// skip size if not numeric", "if", "(", "$", "key", "==", "'size'", "&&", "!", "is_numeric", "(", "$", "value", ")", ")", "{", "continue", ";", "}", "// ignore \"internal\" or empty attributes", "if", "(", "$", "key", "==", "'nl'", "||", "$", "value", "===", "null", ")", "{", "continue", ";", "}", "// ignore not allowed attributes, except aria-* and data-*", "if", "(", "!", "empty", "(", "$", "allowed", ")", ")", "{", "$", "is_data_attr", "=", "@", "substr_compare", "(", "$", "key", ",", "'data-'", ",", "0", ",", "5", ")", "===", "0", ";", "$", "is_aria_attr", "=", "@", "substr_compare", "(", "$", "key", ",", "'aria-'", ",", "0", ",", "5", ")", "===", "0", ";", "if", "(", "!", "$", "is_aria_attr", "&&", "!", "$", "is_data_attr", "&&", "!", "isset", "(", "$", "allowed_f", "[", "$", "key", "]", ")", ")", "{", "continue", ";", "}", "}", "// skip empty eventhandlers", "if", "(", "preg_match", "(", "'/^on[a-z]+/'", ",", "$", "key", ")", "&&", "!", "$", "value", ")", "{", "continue", ";", "}", "// attributes with no value", "if", "(", "in_array", "(", "$", "key", ",", "self", "::", "$", "bool_attrib", ")", ")", "{", "if", "(", "$", "value", ")", "{", "$", "value", "=", "$", "key", ";", "if", "(", "self", "::", "$", "doctype", "==", "'xhtml'", ")", "{", "$", "value", ".=", "'=\"'", ".", "$", "value", ".", "'\"'", ";", "}", "$", "attrib_arr", "[", "]", "=", "$", "value", ";", "}", "}", "else", "{", "$", "attrib_arr", "[", "]", "=", "$", "key", ".", "'=\"'", ".", "self", "::", "quote", "(", "$", "value", ")", ".", "'\"'", ";", "}", "}", "return", "count", "(", "$", "attrib_arr", ")", "?", "' '", ".", "implode", "(", "' '", ",", "$", "attrib_arr", ")", ":", "''", ";", "}" ]
Create string with attributes @param array $attrib Associative array with tag attributes @param array $allowed List of allowed attributes @return string Valid attribute string
[ "Create", "string", "with", "attributes" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/html.php#L289-L340
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/html.php
html.quote
public static function quote($str) { static $flags; if (!$flags) { $flags = ENT_COMPAT; if (defined('ENT_SUBSTITUTE')) { $flags |= ENT_SUBSTITUTE; } } return @htmlspecialchars($str, $flags, RCUBE_CHARSET); }
php
public static function quote($str) { static $flags; if (!$flags) { $flags = ENT_COMPAT; if (defined('ENT_SUBSTITUTE')) { $flags |= ENT_SUBSTITUTE; } } return @htmlspecialchars($str, $flags, RCUBE_CHARSET); }
[ "public", "static", "function", "quote", "(", "$", "str", ")", "{", "static", "$", "flags", ";", "if", "(", "!", "$", "flags", ")", "{", "$", "flags", "=", "ENT_COMPAT", ";", "if", "(", "defined", "(", "'ENT_SUBSTITUTE'", ")", ")", "{", "$", "flags", "|=", "ENT_SUBSTITUTE", ";", "}", "}", "return", "@", "htmlspecialchars", "(", "$", "str", ",", "$", "flags", ",", "RCUBE_CHARSET", ")", ";", "}" ]
Replacing specials characters in html attribute value @param string $str Input string @return string The quoted string
[ "Replacing", "specials", "characters", "in", "html", "attribute", "value" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/html.php#L376-L388
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/html.php
html_hiddenfield.show
public function show() { $out = ''; foreach ($this->fields as $attrib) { $out .= self::tag($this->tagname, array('type' => $this->type) + $attrib); } return $out; }
php
public function show() { $out = ''; foreach ($this->fields as $attrib) { $out .= self::tag($this->tagname, array('type' => $this->type) + $attrib); } return $out; }
[ "public", "function", "show", "(", ")", "{", "$", "out", "=", "''", ";", "foreach", "(", "$", "this", "->", "fields", "as", "$", "attrib", ")", "{", "$", "out", ".=", "self", "::", "tag", "(", "$", "this", "->", "tagname", ",", "array", "(", "'type'", "=>", "$", "this", "->", "type", ")", "+", "$", "attrib", ")", ";", "}", "return", "$", "out", ";", "}" ]
Create HTML code for the hidden fields @return string Final HTML code
[ "Create", "HTML", "code", "for", "the", "hidden", "fields" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/html.php#L502-L510
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/html.php
html_select.add
public function add($names, $values = null, $attrib = array()) { if (is_array($names)) { foreach ($names as $i => $text) { $this->options[] = array('text' => $text, 'value' => $values[$i]) + $attrib; } } else { $this->options[] = array('text' => $names, 'value' => $values) + $attrib; } }
php
public function add($names, $values = null, $attrib = array()) { if (is_array($names)) { foreach ($names as $i => $text) { $this->options[] = array('text' => $text, 'value' => $values[$i]) + $attrib; } } else { $this->options[] = array('text' => $names, 'value' => $values) + $attrib; } }
[ "public", "function", "add", "(", "$", "names", ",", "$", "values", "=", "null", ",", "$", "attrib", "=", "array", "(", ")", ")", "{", "if", "(", "is_array", "(", "$", "names", ")", ")", "{", "foreach", "(", "$", "names", "as", "$", "i", "=>", "$", "text", ")", "{", "$", "this", "->", "options", "[", "]", "=", "array", "(", "'text'", "=>", "$", "text", ",", "'value'", "=>", "$", "values", "[", "$", "i", "]", ")", "+", "$", "attrib", ";", "}", "}", "else", "{", "$", "this", "->", "options", "[", "]", "=", "array", "(", "'text'", "=>", "$", "names", ",", "'value'", "=>", "$", "values", ")", "+", "$", "attrib", ";", "}", "}" ]
Add a new option to this drop-down @param mixed $names Option name or array with option names @param mixed $values Option value or array with option values @param array $attrib Additional attributes for the option entry
[ "Add", "a", "new", "option", "to", "this", "drop", "-", "down" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/html.php#L657-L667
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/html.php
html_table.add
public function add($attr, $cont) { if (is_string($attr)) { $attr = array('class' => $attr); } $cell = new stdClass; $cell->attrib = $attr; $cell->content = $cont; $this->rows[$this->rowindex]->cells[$this->colindex] = $cell; $this->colindex += max(1, intval($attr['colspan'])); if ($this->attrib['cols'] && $this->colindex >= $this->attrib['cols']) { $this->add_row(); } }
php
public function add($attr, $cont) { if (is_string($attr)) { $attr = array('class' => $attr); } $cell = new stdClass; $cell->attrib = $attr; $cell->content = $cont; $this->rows[$this->rowindex]->cells[$this->colindex] = $cell; $this->colindex += max(1, intval($attr['colspan'])); if ($this->attrib['cols'] && $this->colindex >= $this->attrib['cols']) { $this->add_row(); } }
[ "public", "function", "add", "(", "$", "attr", ",", "$", "cont", ")", "{", "if", "(", "is_string", "(", "$", "attr", ")", ")", "{", "$", "attr", "=", "array", "(", "'class'", "=>", "$", "attr", ")", ";", "}", "$", "cell", "=", "new", "stdClass", ";", "$", "cell", "->", "attrib", "=", "$", "attr", ";", "$", "cell", "->", "content", "=", "$", "cont", ";", "$", "this", "->", "rows", "[", "$", "this", "->", "rowindex", "]", "->", "cells", "[", "$", "this", "->", "colindex", "]", "=", "$", "cell", ";", "$", "this", "->", "colindex", "+=", "max", "(", "1", ",", "intval", "(", "$", "attr", "[", "'colspan'", "]", ")", ")", ";", "if", "(", "$", "this", "->", "attrib", "[", "'cols'", "]", "&&", "$", "this", "->", "colindex", ">=", "$", "this", "->", "attrib", "[", "'cols'", "]", ")", "{", "$", "this", "->", "add_row", "(", ")", ";", "}", "}" ]
Add a table cell @param array $attr Cell attributes @param string $cont Cell content
[ "Add", "a", "table", "cell" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/html.php#L744-L760
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/html.php
html_table.add_header
public function add_header($attr, $cont) { if (is_string($attr)) { $attr = array('class' => $attr); } $cell = new stdClass; $cell->attrib = $attr; $cell->content = $cont; $this->header[] = $cell; }
php
public function add_header($attr, $cont) { if (is_string($attr)) { $attr = array('class' => $attr); } $cell = new stdClass; $cell->attrib = $attr; $cell->content = $cont; $this->header[] = $cell; }
[ "public", "function", "add_header", "(", "$", "attr", ",", "$", "cont", ")", "{", "if", "(", "is_string", "(", "$", "attr", ")", ")", "{", "$", "attr", "=", "array", "(", "'class'", "=>", "$", "attr", ")", ";", "}", "$", "cell", "=", "new", "stdClass", ";", "$", "cell", "->", "attrib", "=", "$", "attr", ";", "$", "cell", "->", "content", "=", "$", "cont", ";", "$", "this", "->", "header", "[", "]", "=", "$", "cell", ";", "}" ]
Add a table header cell @param array $attr Cell attributes @param string $cont Cell content
[ "Add", "a", "table", "header", "cell" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/html.php#L768-L778
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/html.php
html_table.remove_column
public function remove_column($class) { // Remove the header foreach ($this->header as $index => $header){ if ($header->attrib['class'] == $class){ unset($this->header[$index]); break; } } // Remove cells from rows foreach ($this->rows as $i => $row){ foreach ($row->cells as $j => $cell){ if ($cell->attrib['class'] == $class){ unset($this->rows[$i]->cells[$j]); break; } } } }
php
public function remove_column($class) { // Remove the header foreach ($this->header as $index => $header){ if ($header->attrib['class'] == $class){ unset($this->header[$index]); break; } } // Remove cells from rows foreach ($this->rows as $i => $row){ foreach ($row->cells as $j => $cell){ if ($cell->attrib['class'] == $class){ unset($this->rows[$i]->cells[$j]); break; } } } }
[ "public", "function", "remove_column", "(", "$", "class", ")", "{", "// Remove the header", "foreach", "(", "$", "this", "->", "header", "as", "$", "index", "=>", "$", "header", ")", "{", "if", "(", "$", "header", "->", "attrib", "[", "'class'", "]", "==", "$", "class", ")", "{", "unset", "(", "$", "this", "->", "header", "[", "$", "index", "]", ")", ";", "break", ";", "}", "}", "// Remove cells from rows", "foreach", "(", "$", "this", "->", "rows", "as", "$", "i", "=>", "$", "row", ")", "{", "foreach", "(", "$", "row", "->", "cells", "as", "$", "j", "=>", "$", "cell", ")", "{", "if", "(", "$", "cell", "->", "attrib", "[", "'class'", "]", "==", "$", "class", ")", "{", "unset", "(", "$", "this", "->", "rows", "[", "$", "i", "]", "->", "cells", "[", "$", "j", "]", ")", ";", "break", ";", "}", "}", "}", "}" ]
Remove a column from a table Useful for plugins making alterations @param string $class Class name
[ "Remove", "a", "column", "from", "a", "table", "Useful", "for", "plugins", "making", "alterations" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/html.php#L786-L805
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/html.php
html_table.add_row
public function add_row($attr = array()) { $this->rowindex++; $this->colindex = 0; $this->rows[$this->rowindex] = new stdClass; $this->rows[$this->rowindex]->attrib = $attr; $this->rows[$this->rowindex]->cells = array(); }
php
public function add_row($attr = array()) { $this->rowindex++; $this->colindex = 0; $this->rows[$this->rowindex] = new stdClass; $this->rows[$this->rowindex]->attrib = $attr; $this->rows[$this->rowindex]->cells = array(); }
[ "public", "function", "add_row", "(", "$", "attr", "=", "array", "(", ")", ")", "{", "$", "this", "->", "rowindex", "++", ";", "$", "this", "->", "colindex", "=", "0", ";", "$", "this", "->", "rows", "[", "$", "this", "->", "rowindex", "]", "=", "new", "stdClass", ";", "$", "this", "->", "rows", "[", "$", "this", "->", "rowindex", "]", "->", "attrib", "=", "$", "attr", ";", "$", "this", "->", "rows", "[", "$", "this", "->", "rowindex", "]", "->", "cells", "=", "array", "(", ")", ";", "}" ]
Jump to next row @param array $attr Row attributes
[ "Jump", "to", "next", "row" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/html.php#L812-L819
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/html.php
html_table.set_row_attribs
public function set_row_attribs($attr = array(), $index = null) { if (is_string($attr)) { $attr = array('class' => $attr); } if ($index === null) { $index = $this->rowindex; } // make sure row object exists (#1489094) if (!$this->rows[$index]) { $this->rows[$index] = new stdClass; } $this->rows[$index]->attrib = $attr; }
php
public function set_row_attribs($attr = array(), $index = null) { if (is_string($attr)) { $attr = array('class' => $attr); } if ($index === null) { $index = $this->rowindex; } // make sure row object exists (#1489094) if (!$this->rows[$index]) { $this->rows[$index] = new stdClass; } $this->rows[$index]->attrib = $attr; }
[ "public", "function", "set_row_attribs", "(", "$", "attr", "=", "array", "(", ")", ",", "$", "index", "=", "null", ")", "{", "if", "(", "is_string", "(", "$", "attr", ")", ")", "{", "$", "attr", "=", "array", "(", "'class'", "=>", "$", "attr", ")", ";", "}", "if", "(", "$", "index", "===", "null", ")", "{", "$", "index", "=", "$", "this", "->", "rowindex", ";", "}", "// make sure row object exists (#1489094)", "if", "(", "!", "$", "this", "->", "rows", "[", "$", "index", "]", ")", "{", "$", "this", "->", "rows", "[", "$", "index", "]", "=", "new", "stdClass", ";", "}", "$", "this", "->", "rows", "[", "$", "index", "]", "->", "attrib", "=", "$", "attr", ";", "}" ]
Set row attributes @param array $attr Row attributes @param int $index Optional row index (default current row index)
[ "Set", "row", "attributes" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/html.php#L827-L843
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/html.php
html_table.get_row_attribs
public function get_row_attribs($index = null) { if ($index === null) { $index = $this->rowindex; } return $this->rows[$index] ? $this->rows[$index]->attrib : null; }
php
public function get_row_attribs($index = null) { if ($index === null) { $index = $this->rowindex; } return $this->rows[$index] ? $this->rows[$index]->attrib : null; }
[ "public", "function", "get_row_attribs", "(", "$", "index", "=", "null", ")", "{", "if", "(", "$", "index", "===", "null", ")", "{", "$", "index", "=", "$", "this", "->", "rowindex", ";", "}", "return", "$", "this", "->", "rows", "[", "$", "index", "]", "?", "$", "this", "->", "rows", "[", "$", "index", "]", "->", "attrib", ":", "null", ";", "}" ]
Get row attributes @param int $index Row index @return array Row attributes
[ "Get", "row", "attributes" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/html.php#L852-L859
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/html.php
html_table.show
public function show($attrib = null) { if (is_array($attrib)) { $this->attrib = array_merge($this->attrib, $attrib); } $thead = $tbody = ""; // include <thead> if (!empty($this->header)) { $rowcontent = ''; foreach ($this->header as $c => $col) { $rowcontent .= self::tag($this->_head_tagname(), $col->attrib, $col->content); } $thead = $this->tagname == 'table' ? self::tag('thead', null, self::tag('tr', null, $rowcontent, parent::$common_attrib)) : self::tag($this->_row_tagname(), array('class' => 'thead'), $rowcontent, parent::$common_attrib); } foreach ($this->rows as $r => $row) { $rowcontent = ''; foreach ($row->cells as $c => $col) { $rowcontent .= self::tag($this->_col_tagname(), $col->attrib, $col->content); } if ($r < $this->rowindex || count($row->cells)) { $tbody .= self::tag($this->_row_tagname(), $row->attrib, $rowcontent, parent::$common_attrib); } } if ($this->attrib['rowsonly']) { return $tbody; } // add <tbody> $this->content = $thead . ($this->tagname == 'table' ? self::tag('tbody', null, $tbody) : $tbody); unset($this->attrib['cols'], $this->attrib['rowsonly']); return parent::show(); }
php
public function show($attrib = null) { if (is_array($attrib)) { $this->attrib = array_merge($this->attrib, $attrib); } $thead = $tbody = ""; // include <thead> if (!empty($this->header)) { $rowcontent = ''; foreach ($this->header as $c => $col) { $rowcontent .= self::tag($this->_head_tagname(), $col->attrib, $col->content); } $thead = $this->tagname == 'table' ? self::tag('thead', null, self::tag('tr', null, $rowcontent, parent::$common_attrib)) : self::tag($this->_row_tagname(), array('class' => 'thead'), $rowcontent, parent::$common_attrib); } foreach ($this->rows as $r => $row) { $rowcontent = ''; foreach ($row->cells as $c => $col) { $rowcontent .= self::tag($this->_col_tagname(), $col->attrib, $col->content); } if ($r < $this->rowindex || count($row->cells)) { $tbody .= self::tag($this->_row_tagname(), $row->attrib, $rowcontent, parent::$common_attrib); } } if ($this->attrib['rowsonly']) { return $tbody; } // add <tbody> $this->content = $thead . ($this->tagname == 'table' ? self::tag('tbody', null, $tbody) : $tbody); unset($this->attrib['cols'], $this->attrib['rowsonly']); return parent::show(); }
[ "public", "function", "show", "(", "$", "attrib", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "attrib", ")", ")", "{", "$", "this", "->", "attrib", "=", "array_merge", "(", "$", "this", "->", "attrib", ",", "$", "attrib", ")", ";", "}", "$", "thead", "=", "$", "tbody", "=", "\"\"", ";", "// include <thead>", "if", "(", "!", "empty", "(", "$", "this", "->", "header", ")", ")", "{", "$", "rowcontent", "=", "''", ";", "foreach", "(", "$", "this", "->", "header", "as", "$", "c", "=>", "$", "col", ")", "{", "$", "rowcontent", ".=", "self", "::", "tag", "(", "$", "this", "->", "_head_tagname", "(", ")", ",", "$", "col", "->", "attrib", ",", "$", "col", "->", "content", ")", ";", "}", "$", "thead", "=", "$", "this", "->", "tagname", "==", "'table'", "?", "self", "::", "tag", "(", "'thead'", ",", "null", ",", "self", "::", "tag", "(", "'tr'", ",", "null", ",", "$", "rowcontent", ",", "parent", "::", "$", "common_attrib", ")", ")", ":", "self", "::", "tag", "(", "$", "this", "->", "_row_tagname", "(", ")", ",", "array", "(", "'class'", "=>", "'thead'", ")", ",", "$", "rowcontent", ",", "parent", "::", "$", "common_attrib", ")", ";", "}", "foreach", "(", "$", "this", "->", "rows", "as", "$", "r", "=>", "$", "row", ")", "{", "$", "rowcontent", "=", "''", ";", "foreach", "(", "$", "row", "->", "cells", "as", "$", "c", "=>", "$", "col", ")", "{", "$", "rowcontent", ".=", "self", "::", "tag", "(", "$", "this", "->", "_col_tagname", "(", ")", ",", "$", "col", "->", "attrib", ",", "$", "col", "->", "content", ")", ";", "}", "if", "(", "$", "r", "<", "$", "this", "->", "rowindex", "||", "count", "(", "$", "row", "->", "cells", ")", ")", "{", "$", "tbody", ".=", "self", "::", "tag", "(", "$", "this", "->", "_row_tagname", "(", ")", ",", "$", "row", "->", "attrib", ",", "$", "rowcontent", ",", "parent", "::", "$", "common_attrib", ")", ";", "}", "}", "if", "(", "$", "this", "->", "attrib", "[", "'rowsonly'", "]", ")", "{", "return", "$", "tbody", ";", "}", "// add <tbody>", "$", "this", "->", "content", "=", "$", "thead", ".", "(", "$", "this", "->", "tagname", "==", "'table'", "?", "self", "::", "tag", "(", "'tbody'", ",", "null", ",", "$", "tbody", ")", ":", "$", "tbody", ")", ";", "unset", "(", "$", "this", "->", "attrib", "[", "'cols'", "]", ",", "$", "this", "->", "attrib", "[", "'rowsonly'", "]", ")", ";", "return", "parent", "::", "show", "(", ")", ";", "}" ]
Build HTML output of the table data @param array $attrib Table attributes @return string The final table HTML code
[ "Build", "HTML", "output", "of", "the", "table", "data" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/html.php#L868-L906
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_contacts.php
rcube_contacts.reset
function reset() { $this->result = null; $this->filter = null; $this->cache = null; }
php
function reset() { $this->result = null; $this->filter = null; $this->cache = null; }
[ "function", "reset", "(", ")", "{", "$", "this", "->", "result", "=", "null", ";", "$", "this", "->", "filter", "=", "null", ";", "$", "this", "->", "cache", "=", "null", ";", "}" ]
Reset all saved results and search parameters
[ "Reset", "all", "saved", "results", "and", "search", "parameters" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_contacts.php#L122-L127
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_contacts.php
rcube_contacts.fulltext_sql_where
private function fulltext_sql_where($value, $mode, $col = 'words', $bool = 'AND') { $WS = ' '; $AS = $col == 'words' ? $WS : self::SEPARATOR; $words = $col == 'words' ? rcube_utils::normalize_string($value, true) : array($value); $where = array(); foreach ($words as $word) { if ($mode & rcube_addressbook::SEARCH_STRICT) { $where[] = '(' . $this->db->ilike($col, $word) . ' OR ' . $this->db->ilike($col, $word . $AS . '%') . ' OR ' . $this->db->ilike($col, '%' . $AS . $word . $AS . '%') . ' OR ' . $this->db->ilike($col, '%' . $AS . $word) . ')'; } else if ($mode & rcube_addressbook::SEARCH_PREFIX) { $where[] = '(' . $this->db->ilike($col, $word . '%') . ' OR ' . $this->db->ilike($col, '%' . $AS . $word . '%') . ')'; } else { $where[] = $this->db->ilike($col, '%' . $word . '%'); } } return count($where) ? '(' . join(" $bool ", $where) . ')' : ''; }
php
private function fulltext_sql_where($value, $mode, $col = 'words', $bool = 'AND') { $WS = ' '; $AS = $col == 'words' ? $WS : self::SEPARATOR; $words = $col == 'words' ? rcube_utils::normalize_string($value, true) : array($value); $where = array(); foreach ($words as $word) { if ($mode & rcube_addressbook::SEARCH_STRICT) { $where[] = '(' . $this->db->ilike($col, $word) . ' OR ' . $this->db->ilike($col, $word . $AS . '%') . ' OR ' . $this->db->ilike($col, '%' . $AS . $word . $AS . '%') . ' OR ' . $this->db->ilike($col, '%' . $AS . $word) . ')'; } else if ($mode & rcube_addressbook::SEARCH_PREFIX) { $where[] = '(' . $this->db->ilike($col, $word . '%') . ' OR ' . $this->db->ilike($col, '%' . $AS . $word . '%') . ')'; } else { $where[] = $this->db->ilike($col, '%' . $word . '%'); } } return count($where) ? '(' . join(" $bool ", $where) . ')' : ''; }
[ "private", "function", "fulltext_sql_where", "(", "$", "value", ",", "$", "mode", ",", "$", "col", "=", "'words'", ",", "$", "bool", "=", "'AND'", ")", "{", "$", "WS", "=", "' '", ";", "$", "AS", "=", "$", "col", "==", "'words'", "?", "$", "WS", ":", "self", "::", "SEPARATOR", ";", "$", "words", "=", "$", "col", "==", "'words'", "?", "rcube_utils", "::", "normalize_string", "(", "$", "value", ",", "true", ")", ":", "array", "(", "$", "value", ")", ";", "$", "where", "=", "array", "(", ")", ";", "foreach", "(", "$", "words", "as", "$", "word", ")", "{", "if", "(", "$", "mode", "&", "rcube_addressbook", "::", "SEARCH_STRICT", ")", "{", "$", "where", "[", "]", "=", "'('", ".", "$", "this", "->", "db", "->", "ilike", "(", "$", "col", ",", "$", "word", ")", ".", "' OR '", ".", "$", "this", "->", "db", "->", "ilike", "(", "$", "col", ",", "$", "word", ".", "$", "AS", ".", "'%'", ")", ".", "' OR '", ".", "$", "this", "->", "db", "->", "ilike", "(", "$", "col", ",", "'%'", ".", "$", "AS", ".", "$", "word", ".", "$", "AS", ".", "'%'", ")", ".", "' OR '", ".", "$", "this", "->", "db", "->", "ilike", "(", "$", "col", ",", "'%'", ".", "$", "AS", ".", "$", "word", ")", ".", "')'", ";", "}", "else", "if", "(", "$", "mode", "&", "rcube_addressbook", "::", "SEARCH_PREFIX", ")", "{", "$", "where", "[", "]", "=", "'('", ".", "$", "this", "->", "db", "->", "ilike", "(", "$", "col", ",", "$", "word", ".", "'%'", ")", ".", "' OR '", ".", "$", "this", "->", "db", "->", "ilike", "(", "$", "col", ",", "'%'", ".", "$", "AS", ".", "$", "word", ".", "'%'", ")", ".", "')'", ";", "}", "else", "{", "$", "where", "[", "]", "=", "$", "this", "->", "db", "->", "ilike", "(", "$", "col", ",", "'%'", ".", "$", "word", ".", "'%'", ")", ";", "}", "}", "return", "count", "(", "$", "where", ")", "?", "'('", ".", "join", "(", "\" $bool \"", ",", "$", "where", ")", ".", "')'", ":", "''", ";", "}" ]
Helper method to compose SQL where statements for fulltext searching
[ "Helper", "method", "to", "compose", "SQL", "where", "statements", "for", "fulltext", "searching" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_contacts.php#L439-L463
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_contacts.php
rcube_contacts.convert_db_data
private function convert_db_data($sql_arr) { $record = array(); $record['ID'] = $sql_arr[$this->primary_key]; if ($sql_arr['vcard']) { unset($sql_arr['email']); $vcard = new rcube_vcard($sql_arr['vcard'], RCUBE_CHARSET, false, $this->vcard_fieldmap); $record += $vcard->get_assoc() + $sql_arr; } else { $record += $sql_arr; $record['email'] = explode(self::SEPARATOR, $record['email']); $record['email'] = array_map('trim', $record['email']); } return $record; }
php
private function convert_db_data($sql_arr) { $record = array(); $record['ID'] = $sql_arr[$this->primary_key]; if ($sql_arr['vcard']) { unset($sql_arr['email']); $vcard = new rcube_vcard($sql_arr['vcard'], RCUBE_CHARSET, false, $this->vcard_fieldmap); $record += $vcard->get_assoc() + $sql_arr; } else { $record += $sql_arr; $record['email'] = explode(self::SEPARATOR, $record['email']); $record['email'] = array_map('trim', $record['email']); } return $record; }
[ "private", "function", "convert_db_data", "(", "$", "sql_arr", ")", "{", "$", "record", "=", "array", "(", ")", ";", "$", "record", "[", "'ID'", "]", "=", "$", "sql_arr", "[", "$", "this", "->", "primary_key", "]", ";", "if", "(", "$", "sql_arr", "[", "'vcard'", "]", ")", "{", "unset", "(", "$", "sql_arr", "[", "'email'", "]", ")", ";", "$", "vcard", "=", "new", "rcube_vcard", "(", "$", "sql_arr", "[", "'vcard'", "]", ",", "RCUBE_CHARSET", ",", "false", ",", "$", "this", "->", "vcard_fieldmap", ")", ";", "$", "record", "+=", "$", "vcard", "->", "get_assoc", "(", ")", "+", "$", "sql_arr", ";", "}", "else", "{", "$", "record", "+=", "$", "sql_arr", ";", "$", "record", "[", "'email'", "]", "=", "explode", "(", "self", "::", "SEPARATOR", ",", "$", "record", "[", "'email'", "]", ")", ";", "$", "record", "[", "'email'", "]", "=", "array_map", "(", "'trim'", ",", "$", "record", "[", "'email'", "]", ")", ";", "}", "return", "$", "record", ";", "}" ]
Convert data stored in the database into output format
[ "Convert", "data", "stored", "in", "the", "database", "into", "output", "format" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_contacts.php#L697-L714
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_contacts.php
rcube_contacts.convert_save_data
private function convert_save_data($save_data, $record = array()) { $out = array(); $words = ''; // copy values into vcard object $vcard = new rcube_vcard($record['vcard'] ?: $save_data['vcard'], RCUBE_CHARSET, false, $this->vcard_fieldmap); $vcard->reset(); // don't store groups in vCard (#1490277) $vcard->set('groups', null); unset($save_data['groups']); foreach ($save_data as $key => $values) { list($field, $section) = explode(':', $key); $fulltext = in_array($field, $this->fulltext_cols); // avoid casting DateTime objects to array if (is_object($values) && is_a($values, 'DateTime')) { $values = array(0 => $values); } foreach ((array)$values as $value) { if (isset($value)) $vcard->set($field, $value, $section); if ($fulltext && is_array($value)) $words .= ' ' . rcube_utils::normalize_string(join(" ", $value)); else if ($fulltext && strlen($value) >= 3) $words .= ' ' . rcube_utils::normalize_string($value); } } $out['vcard'] = $vcard->export(false); foreach ($this->table_cols as $col) { $key = $col; if (!isset($save_data[$key])) $key .= ':home'; if (isset($save_data[$key])) { if (is_array($save_data[$key])) $out[$col] = join(self::SEPARATOR, $save_data[$key]); else $out[$col] = $save_data[$key]; } } // save all e-mails in database column $out['email'] = join(self::SEPARATOR, $vcard->email); // join words for fulltext search $out['words'] = join(" ", array_unique(explode(" ", $words))); return $out; }
php
private function convert_save_data($save_data, $record = array()) { $out = array(); $words = ''; // copy values into vcard object $vcard = new rcube_vcard($record['vcard'] ?: $save_data['vcard'], RCUBE_CHARSET, false, $this->vcard_fieldmap); $vcard->reset(); // don't store groups in vCard (#1490277) $vcard->set('groups', null); unset($save_data['groups']); foreach ($save_data as $key => $values) { list($field, $section) = explode(':', $key); $fulltext = in_array($field, $this->fulltext_cols); // avoid casting DateTime objects to array if (is_object($values) && is_a($values, 'DateTime')) { $values = array(0 => $values); } foreach ((array)$values as $value) { if (isset($value)) $vcard->set($field, $value, $section); if ($fulltext && is_array($value)) $words .= ' ' . rcube_utils::normalize_string(join(" ", $value)); else if ($fulltext && strlen($value) >= 3) $words .= ' ' . rcube_utils::normalize_string($value); } } $out['vcard'] = $vcard->export(false); foreach ($this->table_cols as $col) { $key = $col; if (!isset($save_data[$key])) $key .= ':home'; if (isset($save_data[$key])) { if (is_array($save_data[$key])) $out[$col] = join(self::SEPARATOR, $save_data[$key]); else $out[$col] = $save_data[$key]; } } // save all e-mails in database column $out['email'] = join(self::SEPARATOR, $vcard->email); // join words for fulltext search $out['words'] = join(" ", array_unique(explode(" ", $words))); return $out; }
[ "private", "function", "convert_save_data", "(", "$", "save_data", ",", "$", "record", "=", "array", "(", ")", ")", "{", "$", "out", "=", "array", "(", ")", ";", "$", "words", "=", "''", ";", "// copy values into vcard object", "$", "vcard", "=", "new", "rcube_vcard", "(", "$", "record", "[", "'vcard'", "]", "?", ":", "$", "save_data", "[", "'vcard'", "]", ",", "RCUBE_CHARSET", ",", "false", ",", "$", "this", "->", "vcard_fieldmap", ")", ";", "$", "vcard", "->", "reset", "(", ")", ";", "// don't store groups in vCard (#1490277)", "$", "vcard", "->", "set", "(", "'groups'", ",", "null", ")", ";", "unset", "(", "$", "save_data", "[", "'groups'", "]", ")", ";", "foreach", "(", "$", "save_data", "as", "$", "key", "=>", "$", "values", ")", "{", "list", "(", "$", "field", ",", "$", "section", ")", "=", "explode", "(", "':'", ",", "$", "key", ")", ";", "$", "fulltext", "=", "in_array", "(", "$", "field", ",", "$", "this", "->", "fulltext_cols", ")", ";", "// avoid casting DateTime objects to array", "if", "(", "is_object", "(", "$", "values", ")", "&&", "is_a", "(", "$", "values", ",", "'DateTime'", ")", ")", "{", "$", "values", "=", "array", "(", "0", "=>", "$", "values", ")", ";", "}", "foreach", "(", "(", "array", ")", "$", "values", "as", "$", "value", ")", "{", "if", "(", "isset", "(", "$", "value", ")", ")", "$", "vcard", "->", "set", "(", "$", "field", ",", "$", "value", ",", "$", "section", ")", ";", "if", "(", "$", "fulltext", "&&", "is_array", "(", "$", "value", ")", ")", "$", "words", ".=", "' '", ".", "rcube_utils", "::", "normalize_string", "(", "join", "(", "\" \"", ",", "$", "value", ")", ")", ";", "else", "if", "(", "$", "fulltext", "&&", "strlen", "(", "$", "value", ")", ">=", "3", ")", "$", "words", ".=", "' '", ".", "rcube_utils", "::", "normalize_string", "(", "$", "value", ")", ";", "}", "}", "$", "out", "[", "'vcard'", "]", "=", "$", "vcard", "->", "export", "(", "false", ")", ";", "foreach", "(", "$", "this", "->", "table_cols", "as", "$", "col", ")", "{", "$", "key", "=", "$", "col", ";", "if", "(", "!", "isset", "(", "$", "save_data", "[", "$", "key", "]", ")", ")", "$", "key", ".=", "':home'", ";", "if", "(", "isset", "(", "$", "save_data", "[", "$", "key", "]", ")", ")", "{", "if", "(", "is_array", "(", "$", "save_data", "[", "$", "key", "]", ")", ")", "$", "out", "[", "$", "col", "]", "=", "join", "(", "self", "::", "SEPARATOR", ",", "$", "save_data", "[", "$", "key", "]", ")", ";", "else", "$", "out", "[", "$", "col", "]", "=", "$", "save_data", "[", "$", "key", "]", ";", "}", "}", "// save all e-mails in database column", "$", "out", "[", "'email'", "]", "=", "join", "(", "self", "::", "SEPARATOR", ",", "$", "vcard", "->", "email", ")", ";", "// join words for fulltext search", "$", "out", "[", "'words'", "]", "=", "join", "(", "\" \"", ",", "array_unique", "(", "explode", "(", "\" \"", ",", "$", "words", ")", ")", ")", ";", "return", "$", "out", ";", "}" ]
Convert input data for storing in the database
[ "Convert", "input", "data", "for", "storing", "in", "the", "database" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_contacts.php#L719-L769
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_contacts.php
rcube_contacts.delete_all
function delete_all($with_groups = false) { $this->cache = null; $now = $this->db->now(); $this->db->query("UPDATE " . $this->db->table_name($this->db_name, true) . " SET `del` = 1, `changed` = $now" . " WHERE `user_id` = ?", $this->user_id); $count = $this->db->affected_rows(); if ($with_groups) { $this->db->query("UPDATE " . $this->db->table_name($this->db_groups, true) . " SET `del` = 1, `changed` = $now" . " WHERE `user_id` = ?", $this->user_id); $count += $this->db->affected_rows(); } return $count; }
php
function delete_all($with_groups = false) { $this->cache = null; $now = $this->db->now(); $this->db->query("UPDATE " . $this->db->table_name($this->db_name, true) . " SET `del` = 1, `changed` = $now" . " WHERE `user_id` = ?", $this->user_id); $count = $this->db->affected_rows(); if ($with_groups) { $this->db->query("UPDATE " . $this->db->table_name($this->db_groups, true) . " SET `del` = 1, `changed` = $now" . " WHERE `user_id` = ?", $this->user_id); $count += $this->db->affected_rows(); } return $count; }
[ "function", "delete_all", "(", "$", "with_groups", "=", "false", ")", "{", "$", "this", "->", "cache", "=", "null", ";", "$", "now", "=", "$", "this", "->", "db", "->", "now", "(", ")", ";", "$", "this", "->", "db", "->", "query", "(", "\"UPDATE \"", ".", "$", "this", "->", "db", "->", "table_name", "(", "$", "this", "->", "db_name", ",", "true", ")", ".", "\" SET `del` = 1, `changed` = $now\"", ".", "\" WHERE `user_id` = ?\"", ",", "$", "this", "->", "user_id", ")", ";", "$", "count", "=", "$", "this", "->", "db", "->", "affected_rows", "(", ")", ";", "if", "(", "$", "with_groups", ")", "{", "$", "this", "->", "db", "->", "query", "(", "\"UPDATE \"", ".", "$", "this", "->", "db", "->", "table_name", "(", "$", "this", "->", "db_groups", ",", "true", ")", ".", "\" SET `del` = 1, `changed` = $now\"", ".", "\" WHERE `user_id` = ?\"", ",", "$", "this", "->", "user_id", ")", ";", "$", "count", "+=", "$", "this", "->", "db", "->", "affected_rows", "(", ")", ";", "}", "return", "$", "count", ";", "}" ]
Remove all records from the database @param bool $with_groups Remove also groups @return int Number of removed records
[ "Remove", "all", "records", "from", "the", "database" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_contacts.php#L833-L854
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_contacts.php
rcube_contacts.unique_groupname
private function unique_groupname($name) { $checkname = $name; $num = 2; $hit = false; do { $sql_result = $this->db->query( "SELECT 1 FROM " . $this->db->table_name($this->db_groups, true). " WHERE `del` <> 1". " AND `user_id` = ?". " AND `name` = ?", $this->user_id, $checkname); // append number to make name unique if ($hit = $this->db->fetch_array($sql_result)) { $checkname = $name . ' ' . $num++; } } while ($hit); return $checkname; }
php
private function unique_groupname($name) { $checkname = $name; $num = 2; $hit = false; do { $sql_result = $this->db->query( "SELECT 1 FROM " . $this->db->table_name($this->db_groups, true). " WHERE `del` <> 1". " AND `user_id` = ?". " AND `name` = ?", $this->user_id, $checkname); // append number to make name unique if ($hit = $this->db->fetch_array($sql_result)) { $checkname = $name . ' ' . $num++; } } while ($hit); return $checkname; }
[ "private", "function", "unique_groupname", "(", "$", "name", ")", "{", "$", "checkname", "=", "$", "name", ";", "$", "num", "=", "2", ";", "$", "hit", "=", "false", ";", "do", "{", "$", "sql_result", "=", "$", "this", "->", "db", "->", "query", "(", "\"SELECT 1 FROM \"", ".", "$", "this", "->", "db", "->", "table_name", "(", "$", "this", "->", "db_groups", ",", "true", ")", ".", "\" WHERE `del` <> 1\"", ".", "\" AND `user_id` = ?\"", ".", "\" AND `name` = ?\"", ",", "$", "this", "->", "user_id", ",", "$", "checkname", ")", ";", "// append number to make name unique", "if", "(", "$", "hit", "=", "$", "this", "->", "db", "->", "fetch_array", "(", "$", "sql_result", ")", ")", "{", "$", "checkname", "=", "$", "name", ".", "' '", ".", "$", "num", "++", ";", "}", "}", "while", "(", "$", "hit", ")", ";", "return", "$", "checkname", ";", "}" ]
Check for existing groups with the same name @param string $name Name to check @return string A group name which is unique for the current use
[ "Check", "for", "existing", "groups", "with", "the", "same", "name" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_contacts.php#L1015-L1038
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_spellchecker.php
rcube_spellchecker.languages
function languages() { // trust configuration $configured = $this->rc->config->get('spellcheck_languages'); if (!empty($configured) && is_array($configured) && !$configured[0]) { return $configured; } else if (!empty($configured)) { $langs = (array)$configured; } else if ($this->backend) { $langs = $this->backend->languages(); } // load index @include(RCUBE_LOCALIZATION_DIR . 'index.inc'); // add correct labels $languages = array(); foreach ($langs as $lang) { $langc = strtolower(substr($lang, 0, 2)); $alias = $rcube_language_aliases[$langc]; if (!$alias) { $alias = $langc.'_'.strtoupper($langc); } if ($rcube_languages[$lang]) { $languages[$lang] = $rcube_languages[$lang]; } else if ($rcube_languages[$alias]) { $languages[$lang] = $rcube_languages[$alias]; } else { $languages[$lang] = ucfirst($lang); } } // remove possible duplicates (#1489395) $languages = array_unique($languages); asort($languages); return $languages; }
php
function languages() { // trust configuration $configured = $this->rc->config->get('spellcheck_languages'); if (!empty($configured) && is_array($configured) && !$configured[0]) { return $configured; } else if (!empty($configured)) { $langs = (array)$configured; } else if ($this->backend) { $langs = $this->backend->languages(); } // load index @include(RCUBE_LOCALIZATION_DIR . 'index.inc'); // add correct labels $languages = array(); foreach ($langs as $lang) { $langc = strtolower(substr($lang, 0, 2)); $alias = $rcube_language_aliases[$langc]; if (!$alias) { $alias = $langc.'_'.strtoupper($langc); } if ($rcube_languages[$lang]) { $languages[$lang] = $rcube_languages[$lang]; } else if ($rcube_languages[$alias]) { $languages[$lang] = $rcube_languages[$alias]; } else { $languages[$lang] = ucfirst($lang); } } // remove possible duplicates (#1489395) $languages = array_unique($languages); asort($languages); return $languages; }
[ "function", "languages", "(", ")", "{", "// trust configuration", "$", "configured", "=", "$", "this", "->", "rc", "->", "config", "->", "get", "(", "'spellcheck_languages'", ")", ";", "if", "(", "!", "empty", "(", "$", "configured", ")", "&&", "is_array", "(", "$", "configured", ")", "&&", "!", "$", "configured", "[", "0", "]", ")", "{", "return", "$", "configured", ";", "}", "else", "if", "(", "!", "empty", "(", "$", "configured", ")", ")", "{", "$", "langs", "=", "(", "array", ")", "$", "configured", ";", "}", "else", "if", "(", "$", "this", "->", "backend", ")", "{", "$", "langs", "=", "$", "this", "->", "backend", "->", "languages", "(", ")", ";", "}", "// load index", "@", "include", "(", "RCUBE_LOCALIZATION_DIR", ".", "'index.inc'", ")", ";", "// add correct labels", "$", "languages", "=", "array", "(", ")", ";", "foreach", "(", "$", "langs", "as", "$", "lang", ")", "{", "$", "langc", "=", "strtolower", "(", "substr", "(", "$", "lang", ",", "0", ",", "2", ")", ")", ";", "$", "alias", "=", "$", "rcube_language_aliases", "[", "$", "langc", "]", ";", "if", "(", "!", "$", "alias", ")", "{", "$", "alias", "=", "$", "langc", ".", "'_'", ".", "strtoupper", "(", "$", "langc", ")", ";", "}", "if", "(", "$", "rcube_languages", "[", "$", "lang", "]", ")", "{", "$", "languages", "[", "$", "lang", "]", "=", "$", "rcube_languages", "[", "$", "lang", "]", ";", "}", "else", "if", "(", "$", "rcube_languages", "[", "$", "alias", "]", ")", "{", "$", "languages", "[", "$", "lang", "]", "=", "$", "rcube_languages", "[", "$", "alias", "]", ";", "}", "else", "{", "$", "languages", "[", "$", "lang", "]", "=", "ucfirst", "(", "$", "lang", ")", ";", "}", "}", "// remove possible duplicates (#1489395)", "$", "languages", "=", "array_unique", "(", "$", "languages", ")", ";", "asort", "(", "$", "languages", ")", ";", "return", "$", "languages", ";", "}" ]
Return a list of supported languages
[ "Return", "a", "list", "of", "supported", "languages" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_spellchecker.php#L71-L113
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_spellchecker.php
rcube_spellchecker.is_exception
public function is_exception($word) { // Contain only symbols (e.g. "+9,0", "2:2") if (!$word || preg_match('/^[0-9@#$%^&_+~*<>=:;?!,.-]+$/', $word)) return true; // Contain symbols (e.g. "g@@gle"), all symbols excluding separators if (!empty($this->options['ignore_syms']) && preg_match('/[@#$%^&_+~*=-]/', $word)) return true; // Contain numbers (e.g. "g00g13") if (!empty($this->options['ignore_nums']) && preg_match('/[0-9]/', $word)) return true; // Blocked caps (e.g. "GOOGLE") if (!empty($this->options['ignore_caps']) && $word == mb_strtoupper($word)) return true; // Use exceptions from dictionary if (!empty($this->options['dictionary'])) { $this->load_dict(); // @TODO: should dictionary be case-insensitive? if (!empty($this->dict) && in_array($word, $this->dict)) return true; } return false; }
php
public function is_exception($word) { // Contain only symbols (e.g. "+9,0", "2:2") if (!$word || preg_match('/^[0-9@#$%^&_+~*<>=:;?!,.-]+$/', $word)) return true; // Contain symbols (e.g. "g@@gle"), all symbols excluding separators if (!empty($this->options['ignore_syms']) && preg_match('/[@#$%^&_+~*=-]/', $word)) return true; // Contain numbers (e.g. "g00g13") if (!empty($this->options['ignore_nums']) && preg_match('/[0-9]/', $word)) return true; // Blocked caps (e.g. "GOOGLE") if (!empty($this->options['ignore_caps']) && $word == mb_strtoupper($word)) return true; // Use exceptions from dictionary if (!empty($this->options['dictionary'])) { $this->load_dict(); // @TODO: should dictionary be case-insensitive? if (!empty($this->dict) && in_array($word, $this->dict)) return true; } return false; }
[ "public", "function", "is_exception", "(", "$", "word", ")", "{", "// Contain only symbols (e.g. \"+9,0\", \"2:2\")", "if", "(", "!", "$", "word", "||", "preg_match", "(", "'/^[0-9@#$%^&_+~*<>=:;?!,.-]+$/'", ",", "$", "word", ")", ")", "return", "true", ";", "// Contain symbols (e.g. \"g@@gle\"), all symbols excluding separators", "if", "(", "!", "empty", "(", "$", "this", "->", "options", "[", "'ignore_syms'", "]", ")", "&&", "preg_match", "(", "'/[@#$%^&_+~*=-]/'", ",", "$", "word", ")", ")", "return", "true", ";", "// Contain numbers (e.g. \"g00g13\")", "if", "(", "!", "empty", "(", "$", "this", "->", "options", "[", "'ignore_nums'", "]", ")", "&&", "preg_match", "(", "'/[0-9]/'", ",", "$", "word", ")", ")", "return", "true", ";", "// Blocked caps (e.g. \"GOOGLE\")", "if", "(", "!", "empty", "(", "$", "this", "->", "options", "[", "'ignore_caps'", "]", ")", "&&", "$", "word", "==", "mb_strtoupper", "(", "$", "word", ")", ")", "return", "true", ";", "// Use exceptions from dictionary", "if", "(", "!", "empty", "(", "$", "this", "->", "options", "[", "'dictionary'", "]", ")", ")", "{", "$", "this", "->", "load_dict", "(", ")", ";", "// @TODO: should dictionary be case-insensitive?", "if", "(", "!", "empty", "(", "$", "this", "->", "dict", ")", "&&", "in_array", "(", "$", "word", ",", "$", "this", "->", "dict", ")", ")", "return", "true", ";", "}", "return", "false", ";", "}" ]
Check if the specified word is an exception according to spellcheck options. @param string $word The word @return bool True if the word is an exception, False otherwise
[ "Check", "if", "the", "specified", "word", "is", "an", "exception", "according", "to", "spellcheck", "options", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_spellchecker.php#L265-L293
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_spellchecker.php
rcube_spellchecker.add_word
public function add_word($word) { $this->load_dict(); foreach (explode(' ', $word) as $word) { // sanity check if (strlen($word) < 512) { $this->dict[] = $word; $valid = true; } } if ($valid) { $this->dict = array_unique($this->dict); $this->update_dict(); } }
php
public function add_word($word) { $this->load_dict(); foreach (explode(' ', $word) as $word) { // sanity check if (strlen($word) < 512) { $this->dict[] = $word; $valid = true; } } if ($valid) { $this->dict = array_unique($this->dict); $this->update_dict(); } }
[ "public", "function", "add_word", "(", "$", "word", ")", "{", "$", "this", "->", "load_dict", "(", ")", ";", "foreach", "(", "explode", "(", "' '", ",", "$", "word", ")", "as", "$", "word", ")", "{", "// sanity check", "if", "(", "strlen", "(", "$", "word", ")", "<", "512", ")", "{", "$", "this", "->", "dict", "[", "]", "=", "$", "word", ";", "$", "valid", "=", "true", ";", "}", "}", "if", "(", "$", "valid", ")", "{", "$", "this", "->", "dict", "=", "array_unique", "(", "$", "this", "->", "dict", ")", ";", "$", "this", "->", "update_dict", "(", ")", ";", "}", "}" ]
Add a word to dictionary @param string $word The word to add
[ "Add", "a", "word", "to", "dictionary" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_spellchecker.php#L300-L316
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_spellchecker.php
rcube_spellchecker.remove_word
public function remove_word($word) { $this->load_dict(); if (($key = array_search($word, $this->dict)) !== false) { unset($this->dict[$key]); $this->update_dict(); } }
php
public function remove_word($word) { $this->load_dict(); if (($key = array_search($word, $this->dict)) !== false) { unset($this->dict[$key]); $this->update_dict(); } }
[ "public", "function", "remove_word", "(", "$", "word", ")", "{", "$", "this", "->", "load_dict", "(", ")", ";", "if", "(", "(", "$", "key", "=", "array_search", "(", "$", "word", ",", "$", "this", "->", "dict", ")", ")", "!==", "false", ")", "{", "unset", "(", "$", "this", "->", "dict", "[", "$", "key", "]", ")", ";", "$", "this", "->", "update_dict", "(", ")", ";", "}", "}" ]
Remove a word from dictionary @param string $word The word to remove
[ "Remove", "a", "word", "from", "dictionary" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_spellchecker.php#L323-L331
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_spellchecker.php
rcube_spellchecker.update_dict
private function update_dict() { if (strcasecmp($this->options['dictionary'], 'shared') != 0) { $userid = $this->rc->get_user_id(); } $plugin = $this->rc->plugins->exec_hook('spell_dictionary_save', array( 'userid' => $userid, 'language' => $this->lang, 'dictionary' => $this->dict)); if (!empty($plugin['abort'])) { return; } if ($this->have_dict) { if (!empty($this->dict)) { $this->rc->db->query( "UPDATE " . $this->rc->db->table_name('dictionary', true) ." SET `data` = ?" ." WHERE `user_id` " . ($plugin['userid'] ? "= ".$this->rc->db->quote($plugin['userid']) : "IS NULL") ." AND `language` = ?", implode(' ', $plugin['dictionary']), $plugin['language']); } // don't store empty dict else { $this->rc->db->query( "DELETE FROM " . $this->rc->db->table_name('dictionary', true) ." WHERE `user_id` " . ($plugin['userid'] ? "= ".$this->rc->db->quote($plugin['userid']) : "IS NULL") ." AND `language` = ?", $plugin['language']); } } else if (!empty($this->dict)) { $this->rc->db->query( "INSERT INTO " . $this->rc->db->table_name('dictionary', true) ." (`user_id`, `language`, `data`) VALUES (?, ?, ?)", $plugin['userid'], $plugin['language'], implode(' ', $plugin['dictionary'])); } }
php
private function update_dict() { if (strcasecmp($this->options['dictionary'], 'shared') != 0) { $userid = $this->rc->get_user_id(); } $plugin = $this->rc->plugins->exec_hook('spell_dictionary_save', array( 'userid' => $userid, 'language' => $this->lang, 'dictionary' => $this->dict)); if (!empty($plugin['abort'])) { return; } if ($this->have_dict) { if (!empty($this->dict)) { $this->rc->db->query( "UPDATE " . $this->rc->db->table_name('dictionary', true) ." SET `data` = ?" ." WHERE `user_id` " . ($plugin['userid'] ? "= ".$this->rc->db->quote($plugin['userid']) : "IS NULL") ." AND `language` = ?", implode(' ', $plugin['dictionary']), $plugin['language']); } // don't store empty dict else { $this->rc->db->query( "DELETE FROM " . $this->rc->db->table_name('dictionary', true) ." WHERE `user_id` " . ($plugin['userid'] ? "= ".$this->rc->db->quote($plugin['userid']) : "IS NULL") ." AND `language` = ?", $plugin['language']); } } else if (!empty($this->dict)) { $this->rc->db->query( "INSERT INTO " . $this->rc->db->table_name('dictionary', true) ." (`user_id`, `language`, `data`) VALUES (?, ?, ?)", $plugin['userid'], $plugin['language'], implode(' ', $plugin['dictionary'])); } }
[ "private", "function", "update_dict", "(", ")", "{", "if", "(", "strcasecmp", "(", "$", "this", "->", "options", "[", "'dictionary'", "]", ",", "'shared'", ")", "!=", "0", ")", "{", "$", "userid", "=", "$", "this", "->", "rc", "->", "get_user_id", "(", ")", ";", "}", "$", "plugin", "=", "$", "this", "->", "rc", "->", "plugins", "->", "exec_hook", "(", "'spell_dictionary_save'", ",", "array", "(", "'userid'", "=>", "$", "userid", ",", "'language'", "=>", "$", "this", "->", "lang", ",", "'dictionary'", "=>", "$", "this", "->", "dict", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "plugin", "[", "'abort'", "]", ")", ")", "{", "return", ";", "}", "if", "(", "$", "this", "->", "have_dict", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "dict", ")", ")", "{", "$", "this", "->", "rc", "->", "db", "->", "query", "(", "\"UPDATE \"", ".", "$", "this", "->", "rc", "->", "db", "->", "table_name", "(", "'dictionary'", ",", "true", ")", ".", "\" SET `data` = ?\"", ".", "\" WHERE `user_id` \"", ".", "(", "$", "plugin", "[", "'userid'", "]", "?", "\"= \"", ".", "$", "this", "->", "rc", "->", "db", "->", "quote", "(", "$", "plugin", "[", "'userid'", "]", ")", ":", "\"IS NULL\"", ")", ".", "\" AND `language` = ?\"", ",", "implode", "(", "' '", ",", "$", "plugin", "[", "'dictionary'", "]", ")", ",", "$", "plugin", "[", "'language'", "]", ")", ";", "}", "// don't store empty dict", "else", "{", "$", "this", "->", "rc", "->", "db", "->", "query", "(", "\"DELETE FROM \"", ".", "$", "this", "->", "rc", "->", "db", "->", "table_name", "(", "'dictionary'", ",", "true", ")", ".", "\" WHERE `user_id` \"", ".", "(", "$", "plugin", "[", "'userid'", "]", "?", "\"= \"", ".", "$", "this", "->", "rc", "->", "db", "->", "quote", "(", "$", "plugin", "[", "'userid'", "]", ")", ":", "\"IS NULL\"", ")", ".", "\" AND `language` = ?\"", ",", "$", "plugin", "[", "'language'", "]", ")", ";", "}", "}", "else", "if", "(", "!", "empty", "(", "$", "this", "->", "dict", ")", ")", "{", "$", "this", "->", "rc", "->", "db", "->", "query", "(", "\"INSERT INTO \"", ".", "$", "this", "->", "rc", "->", "db", "->", "table_name", "(", "'dictionary'", ",", "true", ")", ".", "\" (`user_id`, `language`, `data`) VALUES (?, ?, ?)\"", ",", "$", "plugin", "[", "'userid'", "]", ",", "$", "plugin", "[", "'language'", "]", ",", "implode", "(", "' '", ",", "$", "plugin", "[", "'dictionary'", "]", ")", ")", ";", "}", "}" ]
Update dictionary row in DB
[ "Update", "dictionary", "row", "in", "DB" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_spellchecker.php#L336-L373
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_spellchecker.php
rcube_spellchecker.load_dict
private function load_dict() { if (is_array($this->dict)) { return $this->dict; } if (strcasecmp($this->options['dictionary'], 'shared') != 0) { $userid = $this->rc->get_user_id(); } $plugin = $this->rc->plugins->exec_hook('spell_dictionary_get', array( 'userid' => $userid, 'language' => $this->lang, 'dictionary' => array())); if (empty($plugin['abort'])) { $dict = array(); $sql_result = $this->rc->db->query( "SELECT `data` FROM " . $this->rc->db->table_name('dictionary', true) ." WHERE `user_id` ". ($plugin['userid'] ? "= ".$this->rc->db->quote($plugin['userid']) : "IS NULL") ." AND `language` = ?", $plugin['language']); if ($sql_arr = $this->rc->db->fetch_assoc($sql_result)) { $this->have_dict = true; if (!empty($sql_arr['data'])) { $dict = explode(' ', $sql_arr['data']); } } $plugin['dictionary'] = array_merge((array)$plugin['dictionary'], $dict); } if (!empty($plugin['dictionary']) && is_array($plugin['dictionary'])) { $this->dict = $plugin['dictionary']; } else { $this->dict = array(); } return $this->dict; }
php
private function load_dict() { if (is_array($this->dict)) { return $this->dict; } if (strcasecmp($this->options['dictionary'], 'shared') != 0) { $userid = $this->rc->get_user_id(); } $plugin = $this->rc->plugins->exec_hook('spell_dictionary_get', array( 'userid' => $userid, 'language' => $this->lang, 'dictionary' => array())); if (empty($plugin['abort'])) { $dict = array(); $sql_result = $this->rc->db->query( "SELECT `data` FROM " . $this->rc->db->table_name('dictionary', true) ." WHERE `user_id` ". ($plugin['userid'] ? "= ".$this->rc->db->quote($plugin['userid']) : "IS NULL") ." AND `language` = ?", $plugin['language']); if ($sql_arr = $this->rc->db->fetch_assoc($sql_result)) { $this->have_dict = true; if (!empty($sql_arr['data'])) { $dict = explode(' ', $sql_arr['data']); } } $plugin['dictionary'] = array_merge((array)$plugin['dictionary'], $dict); } if (!empty($plugin['dictionary']) && is_array($plugin['dictionary'])) { $this->dict = $plugin['dictionary']; } else { $this->dict = array(); } return $this->dict; }
[ "private", "function", "load_dict", "(", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "dict", ")", ")", "{", "return", "$", "this", "->", "dict", ";", "}", "if", "(", "strcasecmp", "(", "$", "this", "->", "options", "[", "'dictionary'", "]", ",", "'shared'", ")", "!=", "0", ")", "{", "$", "userid", "=", "$", "this", "->", "rc", "->", "get_user_id", "(", ")", ";", "}", "$", "plugin", "=", "$", "this", "->", "rc", "->", "plugins", "->", "exec_hook", "(", "'spell_dictionary_get'", ",", "array", "(", "'userid'", "=>", "$", "userid", ",", "'language'", "=>", "$", "this", "->", "lang", ",", "'dictionary'", "=>", "array", "(", ")", ")", ")", ";", "if", "(", "empty", "(", "$", "plugin", "[", "'abort'", "]", ")", ")", "{", "$", "dict", "=", "array", "(", ")", ";", "$", "sql_result", "=", "$", "this", "->", "rc", "->", "db", "->", "query", "(", "\"SELECT `data` FROM \"", ".", "$", "this", "->", "rc", "->", "db", "->", "table_name", "(", "'dictionary'", ",", "true", ")", ".", "\" WHERE `user_id` \"", ".", "(", "$", "plugin", "[", "'userid'", "]", "?", "\"= \"", ".", "$", "this", "->", "rc", "->", "db", "->", "quote", "(", "$", "plugin", "[", "'userid'", "]", ")", ":", "\"IS NULL\"", ")", ".", "\" AND `language` = ?\"", ",", "$", "plugin", "[", "'language'", "]", ")", ";", "if", "(", "$", "sql_arr", "=", "$", "this", "->", "rc", "->", "db", "->", "fetch_assoc", "(", "$", "sql_result", ")", ")", "{", "$", "this", "->", "have_dict", "=", "true", ";", "if", "(", "!", "empty", "(", "$", "sql_arr", "[", "'data'", "]", ")", ")", "{", "$", "dict", "=", "explode", "(", "' '", ",", "$", "sql_arr", "[", "'data'", "]", ")", ";", "}", "}", "$", "plugin", "[", "'dictionary'", "]", "=", "array_merge", "(", "(", "array", ")", "$", "plugin", "[", "'dictionary'", "]", ",", "$", "dict", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "plugin", "[", "'dictionary'", "]", ")", "&&", "is_array", "(", "$", "plugin", "[", "'dictionary'", "]", ")", ")", "{", "$", "this", "->", "dict", "=", "$", "plugin", "[", "'dictionary'", "]", ";", "}", "else", "{", "$", "this", "->", "dict", "=", "array", "(", ")", ";", "}", "return", "$", "this", "->", "dict", ";", "}" ]
Get dictionary from DB
[ "Get", "dictionary", "from", "DB" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_spellchecker.php#L378-L417
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_spellcheck_enchant.php
rcube_spellcheck_enchant.init
private function init() { if (!$this->enchant_broker) { if (!extension_loaded('enchant')) { $this->error = "Enchant extension not available"; return; } $this->enchant_broker = enchant_broker_init(); } if (!enchant_broker_dict_exists($this->enchant_broker, $this->lang)) { $this->error = "Unable to load dictionary for selected language using Enchant"; return; } $this->enchant_dictionary = enchant_broker_request_dict($this->enchant_broker, $this->lang); }
php
private function init() { if (!$this->enchant_broker) { if (!extension_loaded('enchant')) { $this->error = "Enchant extension not available"; return; } $this->enchant_broker = enchant_broker_init(); } if (!enchant_broker_dict_exists($this->enchant_broker, $this->lang)) { $this->error = "Unable to load dictionary for selected language using Enchant"; return; } $this->enchant_dictionary = enchant_broker_request_dict($this->enchant_broker, $this->lang); }
[ "private", "function", "init", "(", ")", "{", "if", "(", "!", "$", "this", "->", "enchant_broker", ")", "{", "if", "(", "!", "extension_loaded", "(", "'enchant'", ")", ")", "{", "$", "this", "->", "error", "=", "\"Enchant extension not available\"", ";", "return", ";", "}", "$", "this", "->", "enchant_broker", "=", "enchant_broker_init", "(", ")", ";", "}", "if", "(", "!", "enchant_broker_dict_exists", "(", "$", "this", "->", "enchant_broker", ",", "$", "this", "->", "lang", ")", ")", "{", "$", "this", "->", "error", "=", "\"Unable to load dictionary for selected language using Enchant\"", ";", "return", ";", "}", "$", "this", "->", "enchant_dictionary", "=", "enchant_broker_request_dict", "(", "$", "this", "->", "enchant_broker", ",", "$", "this", "->", "lang", ")", ";", "}" ]
Initializes Enchant dictionary
[ "Initializes", "Enchant", "dictionary" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_spellcheck_enchant.php#L55-L72
train
i-MSCP/roundcube
roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php
rcube_sieve_script.set_var
public function set_var($name, $value, $mods = array()) { // Check if variable exists for ($i=0, $len=count($this->vars); $i<$len; $i++) { if ($this->vars[$i]['name'] == $name) { break; } } $var = array_merge($mods, array('name' => $name, 'value' => $value)); $this->vars[$i] = $var; }
php
public function set_var($name, $value, $mods = array()) { // Check if variable exists for ($i=0, $len=count($this->vars); $i<$len; $i++) { if ($this->vars[$i]['name'] == $name) { break; } } $var = array_merge($mods, array('name' => $name, 'value' => $value)); $this->vars[$i] = $var; }
[ "public", "function", "set_var", "(", "$", "name", ",", "$", "value", ",", "$", "mods", "=", "array", "(", ")", ")", "{", "// Check if variable exists", "for", "(", "$", "i", "=", "0", ",", "$", "len", "=", "count", "(", "$", "this", "->", "vars", ")", ";", "$", "i", "<", "$", "len", ";", "$", "i", "++", ")", "{", "if", "(", "$", "this", "->", "vars", "[", "$", "i", "]", "[", "'name'", "]", "==", "$", "name", ")", "{", "break", ";", "}", "}", "$", "var", "=", "array_merge", "(", "$", "mods", ",", "array", "(", "'name'", "=>", "$", "name", ",", "'value'", "=>", "$", "value", ")", ")", ";", "$", "this", "->", "vars", "[", "$", "i", "]", "=", "$", "var", ";", "}" ]
Sets "global" variable @param string $name Variable name @param string $value Variable value @param array $mods Variable modifiers
[ "Sets", "global", "variable" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php#L124-L135
train
i-MSCP/roundcube
roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php
rcube_sieve_script.unset_var
public function unset_var($name) { // Check if variable exists foreach ($this->vars as $idx => $var) { if ($var['name'] == $name) { unset($this->vars[$idx]); break; } } }
php
public function unset_var($name) { // Check if variable exists foreach ($this->vars as $idx => $var) { if ($var['name'] == $name) { unset($this->vars[$idx]); break; } } }
[ "public", "function", "unset_var", "(", "$", "name", ")", "{", "// Check if variable exists", "foreach", "(", "$", "this", "->", "vars", "as", "$", "idx", "=>", "$", "var", ")", "{", "if", "(", "$", "var", "[", "'name'", "]", "==", "$", "name", ")", "{", "unset", "(", "$", "this", "->", "vars", "[", "$", "idx", "]", ")", ";", "break", ";", "}", "}", "}" ]
Unsets "global" variable @param string $name Variable name
[ "Unsets", "global", "variable" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php#L142-L151
train
i-MSCP/roundcube
roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php
rcube_sieve_script.get_var
public function get_var($name) { // Check if variable exists for ($i=0, $len=count($this->vars); $i<$len; $i++) { if ($this->vars[$i]['name'] == $name) { return $this->vars[$i]['name']; } } }
php
public function get_var($name) { // Check if variable exists for ($i=0, $len=count($this->vars); $i<$len; $i++) { if ($this->vars[$i]['name'] == $name) { return $this->vars[$i]['name']; } } }
[ "public", "function", "get_var", "(", "$", "name", ")", "{", "// Check if variable exists", "for", "(", "$", "i", "=", "0", ",", "$", "len", "=", "count", "(", "$", "this", "->", "vars", ")", ";", "$", "i", "<", "$", "len", ";", "$", "i", "++", ")", "{", "if", "(", "$", "this", "->", "vars", "[", "$", "i", "]", "[", "'name'", "]", "==", "$", "name", ")", "{", "return", "$", "this", "->", "vars", "[", "$", "i", "]", "[", "'name'", "]", ";", "}", "}", "}" ]
Gets the value of "global" variable @param string $name Variable name @return string Variable value
[ "Gets", "the", "value", "of", "global", "variable" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php#L160-L168
train
i-MSCP/roundcube
roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php
rcube_sieve_script._parse_text
private function _parse_text($script) { $prefix = ''; $options = array(); $position = 0; $length = strlen($script); while ($position < $length) { // skip whitespace chars $position = self::ltrim_position($script, $position); $rulename = ''; // Comments while ($script[$position] === '#') { $endl = strpos($script, "\n", $position) ?: $length; $line = substr($script, $position, $endl - $position); // Roundcube format if (preg_match('/^# rule:\[(.*)\]/', $line, $matches)) { $rulename = $matches[1]; } // KEP:14 variables else if (preg_match('/^# (EDITOR|EDITOR_VERSION) (.+)$/', $line, $matches)) { $this->set_var($matches[1], $matches[2]); } // Horde-Ingo format else if (!empty($options['format']) && $options['format'] == 'INGO' && preg_match('/^# (.*)/', $line, $matches) ) { $rulename = $matches[1]; } else if (empty($options['prefix'])) { $prefix .= $line . "\n"; } // skip empty lines after the comment (#5657) $position = self::ltrim_position($script, $endl + 1); } // handle script header if (empty($options['prefix'])) { $options['prefix'] = true; if ($prefix && strpos($prefix, 'horde.org/ingo')) { $options['format'] = 'INGO'; } } // Control structures/blocks if (preg_match('/^(if|else|elsif)/i', substr($script, $position, 5))) { $rule = $this->_tokenize_rule($script, $position); if (strlen($rulename) && !empty($rule)) { $rule['name'] = $rulename; } } // Simple commands else { $rule = $this->_parse_actions($script, $position, ';'); if (!empty($rule[0]) && is_array($rule)) { // set "global" variables if ($rule[0]['type'] == 'set') { unset($rule[0]['type']); $this->vars[] = $rule[0]; unset($rule); } else { $rule = array('actions' => $rule); } } } if (!empty($rule)) { $this->content[] = $rule; } } if (!empty($prefix)) { $this->prefix = trim($prefix); } }
php
private function _parse_text($script) { $prefix = ''; $options = array(); $position = 0; $length = strlen($script); while ($position < $length) { // skip whitespace chars $position = self::ltrim_position($script, $position); $rulename = ''; // Comments while ($script[$position] === '#') { $endl = strpos($script, "\n", $position) ?: $length; $line = substr($script, $position, $endl - $position); // Roundcube format if (preg_match('/^# rule:\[(.*)\]/', $line, $matches)) { $rulename = $matches[1]; } // KEP:14 variables else if (preg_match('/^# (EDITOR|EDITOR_VERSION) (.+)$/', $line, $matches)) { $this->set_var($matches[1], $matches[2]); } // Horde-Ingo format else if (!empty($options['format']) && $options['format'] == 'INGO' && preg_match('/^# (.*)/', $line, $matches) ) { $rulename = $matches[1]; } else if (empty($options['prefix'])) { $prefix .= $line . "\n"; } // skip empty lines after the comment (#5657) $position = self::ltrim_position($script, $endl + 1); } // handle script header if (empty($options['prefix'])) { $options['prefix'] = true; if ($prefix && strpos($prefix, 'horde.org/ingo')) { $options['format'] = 'INGO'; } } // Control structures/blocks if (preg_match('/^(if|else|elsif)/i', substr($script, $position, 5))) { $rule = $this->_tokenize_rule($script, $position); if (strlen($rulename) && !empty($rule)) { $rule['name'] = $rulename; } } // Simple commands else { $rule = $this->_parse_actions($script, $position, ';'); if (!empty($rule[0]) && is_array($rule)) { // set "global" variables if ($rule[0]['type'] == 'set') { unset($rule[0]['type']); $this->vars[] = $rule[0]; unset($rule); } else { $rule = array('actions' => $rule); } } } if (!empty($rule)) { $this->content[] = $rule; } } if (!empty($prefix)) { $this->prefix = trim($prefix); } }
[ "private", "function", "_parse_text", "(", "$", "script", ")", "{", "$", "prefix", "=", "''", ";", "$", "options", "=", "array", "(", ")", ";", "$", "position", "=", "0", ";", "$", "length", "=", "strlen", "(", "$", "script", ")", ";", "while", "(", "$", "position", "<", "$", "length", ")", "{", "// skip whitespace chars", "$", "position", "=", "self", "::", "ltrim_position", "(", "$", "script", ",", "$", "position", ")", ";", "$", "rulename", "=", "''", ";", "// Comments", "while", "(", "$", "script", "[", "$", "position", "]", "===", "'#'", ")", "{", "$", "endl", "=", "strpos", "(", "$", "script", ",", "\"\\n\"", ",", "$", "position", ")", "?", ":", "$", "length", ";", "$", "line", "=", "substr", "(", "$", "script", ",", "$", "position", ",", "$", "endl", "-", "$", "position", ")", ";", "// Roundcube format", "if", "(", "preg_match", "(", "'/^# rule:\\[(.*)\\]/'", ",", "$", "line", ",", "$", "matches", ")", ")", "{", "$", "rulename", "=", "$", "matches", "[", "1", "]", ";", "}", "// KEP:14 variables", "else", "if", "(", "preg_match", "(", "'/^# (EDITOR|EDITOR_VERSION) (.+)$/'", ",", "$", "line", ",", "$", "matches", ")", ")", "{", "$", "this", "->", "set_var", "(", "$", "matches", "[", "1", "]", ",", "$", "matches", "[", "2", "]", ")", ";", "}", "// Horde-Ingo format", "else", "if", "(", "!", "empty", "(", "$", "options", "[", "'format'", "]", ")", "&&", "$", "options", "[", "'format'", "]", "==", "'INGO'", "&&", "preg_match", "(", "'/^# (.*)/'", ",", "$", "line", ",", "$", "matches", ")", ")", "{", "$", "rulename", "=", "$", "matches", "[", "1", "]", ";", "}", "else", "if", "(", "empty", "(", "$", "options", "[", "'prefix'", "]", ")", ")", "{", "$", "prefix", ".=", "$", "line", ".", "\"\\n\"", ";", "}", "// skip empty lines after the comment (#5657)", "$", "position", "=", "self", "::", "ltrim_position", "(", "$", "script", ",", "$", "endl", "+", "1", ")", ";", "}", "// handle script header", "if", "(", "empty", "(", "$", "options", "[", "'prefix'", "]", ")", ")", "{", "$", "options", "[", "'prefix'", "]", "=", "true", ";", "if", "(", "$", "prefix", "&&", "strpos", "(", "$", "prefix", ",", "'horde.org/ingo'", ")", ")", "{", "$", "options", "[", "'format'", "]", "=", "'INGO'", ";", "}", "}", "// Control structures/blocks", "if", "(", "preg_match", "(", "'/^(if|else|elsif)/i'", ",", "substr", "(", "$", "script", ",", "$", "position", ",", "5", ")", ")", ")", "{", "$", "rule", "=", "$", "this", "->", "_tokenize_rule", "(", "$", "script", ",", "$", "position", ")", ";", "if", "(", "strlen", "(", "$", "rulename", ")", "&&", "!", "empty", "(", "$", "rule", ")", ")", "{", "$", "rule", "[", "'name'", "]", "=", "$", "rulename", ";", "}", "}", "// Simple commands", "else", "{", "$", "rule", "=", "$", "this", "->", "_parse_actions", "(", "$", "script", ",", "$", "position", ",", "';'", ")", ";", "if", "(", "!", "empty", "(", "$", "rule", "[", "0", "]", ")", "&&", "is_array", "(", "$", "rule", ")", ")", "{", "// set \"global\" variables", "if", "(", "$", "rule", "[", "0", "]", "[", "'type'", "]", "==", "'set'", ")", "{", "unset", "(", "$", "rule", "[", "0", "]", "[", "'type'", "]", ")", ";", "$", "this", "->", "vars", "[", "]", "=", "$", "rule", "[", "0", "]", ";", "unset", "(", "$", "rule", ")", ";", "}", "else", "{", "$", "rule", "=", "array", "(", "'actions'", "=>", "$", "rule", ")", ";", "}", "}", "}", "if", "(", "!", "empty", "(", "$", "rule", ")", ")", "{", "$", "this", "->", "content", "[", "]", "=", "$", "rule", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "prefix", ")", ")", "{", "$", "this", "->", "prefix", "=", "trim", "(", "$", "prefix", ")", ";", "}", "}" ]
Converts text script to rules array @param string Text script
[ "Converts", "text", "script", "to", "rules", "array" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php#L560-L638
train
i-MSCP/roundcube
roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php
rcube_sieve_script.add_comparator
private function add_comparator($test, &$out, &$exts) { if (empty($test['comparator'])) { return; } if ($test['comparator'] == 'i;ascii-numeric') { array_push($exts, 'relational'); array_push($exts, 'comparator-i;ascii-numeric'); } else if (!in_array($test['comparator'], array('i;octet', 'i;ascii-casemap'))) { array_push($exts, 'comparator-' . $test['comparator']); } // skip default comparator if ($test['comparator'] != 'i;ascii-casemap') { $out .= ' :comparator ' . self::escape_string($test['comparator']); } }
php
private function add_comparator($test, &$out, &$exts) { if (empty($test['comparator'])) { return; } if ($test['comparator'] == 'i;ascii-numeric') { array_push($exts, 'relational'); array_push($exts, 'comparator-i;ascii-numeric'); } else if (!in_array($test['comparator'], array('i;octet', 'i;ascii-casemap'))) { array_push($exts, 'comparator-' . $test['comparator']); } // skip default comparator if ($test['comparator'] != 'i;ascii-casemap') { $out .= ' :comparator ' . self::escape_string($test['comparator']); } }
[ "private", "function", "add_comparator", "(", "$", "test", ",", "&", "$", "out", ",", "&", "$", "exts", ")", "{", "if", "(", "empty", "(", "$", "test", "[", "'comparator'", "]", ")", ")", "{", "return", ";", "}", "if", "(", "$", "test", "[", "'comparator'", "]", "==", "'i;ascii-numeric'", ")", "{", "array_push", "(", "$", "exts", ",", "'relational'", ")", ";", "array_push", "(", "$", "exts", ",", "'comparator-i;ascii-numeric'", ")", ";", "}", "else", "if", "(", "!", "in_array", "(", "$", "test", "[", "'comparator'", "]", ",", "array", "(", "'i;octet'", ",", "'i;ascii-casemap'", ")", ")", ")", "{", "array_push", "(", "$", "exts", ",", "'comparator-'", ".", "$", "test", "[", "'comparator'", "]", ")", ";", "}", "// skip default comparator", "if", "(", "$", "test", "[", "'comparator'", "]", "!=", "'i;ascii-casemap'", ")", "{", "$", "out", ".=", "' :comparator '", ".", "self", "::", "escape_string", "(", "$", "test", "[", "'comparator'", "]", ")", ";", "}", "}" ]
Add comparator to the test
[ "Add", "comparator", "to", "the", "test" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php#L958-L976
train
i-MSCP/roundcube
roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php
rcube_sieve_script.add_index
private function add_index($test, &$out, &$exts) { if (!empty($test['index'])) { array_push($exts, 'index'); $out .= ' :index ' . intval($test['index']) . ($test['last'] ? ' :last' : ''); } }
php
private function add_index($test, &$out, &$exts) { if (!empty($test['index'])) { array_push($exts, 'index'); $out .= ' :index ' . intval($test['index']) . ($test['last'] ? ' :last' : ''); } }
[ "private", "function", "add_index", "(", "$", "test", ",", "&", "$", "out", ",", "&", "$", "exts", ")", "{", "if", "(", "!", "empty", "(", "$", "test", "[", "'index'", "]", ")", ")", "{", "array_push", "(", "$", "exts", ",", "'index'", ")", ";", "$", "out", ".=", "' :index '", ".", "intval", "(", "$", "test", "[", "'index'", "]", ")", ".", "(", "$", "test", "[", "'last'", "]", "?", "' :last'", ":", "''", ")", ";", "}", "}" ]
Add index argument to the test
[ "Add", "index", "argument", "to", "the", "test" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php#L981-L987
train
i-MSCP/roundcube
roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php
rcube_sieve_script.add_operator
private function add_operator($test, &$out, &$exts) { if (empty($test['type'])) { return; } // relational operator if (preg_match('/^(value|count)-([gteqnl]{2})/', $test['type'], $m)) { array_push($exts, 'relational'); $out .= ' :' . $m[1] . ' "' . $m[2] . '"'; } else { if ($test['type'] == 'regex') { array_push($exts, 'regex'); } $out .= ' :' . $test['type']; } $this->add_comparator($test, $out, $exts); }
php
private function add_operator($test, &$out, &$exts) { if (empty($test['type'])) { return; } // relational operator if (preg_match('/^(value|count)-([gteqnl]{2})/', $test['type'], $m)) { array_push($exts, 'relational'); $out .= ' :' . $m[1] . ' "' . $m[2] . '"'; } else { if ($test['type'] == 'regex') { array_push($exts, 'regex'); } $out .= ' :' . $test['type']; } $this->add_comparator($test, $out, $exts); }
[ "private", "function", "add_operator", "(", "$", "test", ",", "&", "$", "out", ",", "&", "$", "exts", ")", "{", "if", "(", "empty", "(", "$", "test", "[", "'type'", "]", ")", ")", "{", "return", ";", "}", "// relational operator", "if", "(", "preg_match", "(", "'/^(value|count)-([gteqnl]{2})/'", ",", "$", "test", "[", "'type'", "]", ",", "$", "m", ")", ")", "{", "array_push", "(", "$", "exts", ",", "'relational'", ")", ";", "$", "out", ".=", "' :'", ".", "$", "m", "[", "1", "]", ".", "' \"'", ".", "$", "m", "[", "2", "]", ".", "'\"'", ";", "}", "else", "{", "if", "(", "$", "test", "[", "'type'", "]", "==", "'regex'", ")", "{", "array_push", "(", "$", "exts", ",", "'regex'", ")", ";", "}", "$", "out", ".=", "' :'", ".", "$", "test", "[", "'type'", "]", ";", "}", "$", "this", "->", "add_comparator", "(", "$", "test", ",", "$", "out", ",", "$", "exts", ")", ";", "}" ]
Add operators to the test
[ "Add", "operators", "to", "the", "test" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php#L992-L1013
train
i-MSCP/roundcube
roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php
rcube_sieve_script.action_arguments
private function action_arguments(&$tokens, $bool_args, $val_args = array()) { $action = array(); $result = array(); for ($i=0, $len=count($tokens); $i<$len; $i++) { $tok = $tokens[$i]; if (!is_array($tok) && $tok[0] == ':') { $tok = strtolower(substr($tok, 1)); if (in_array($tok, $bool_args)) { $action[$tok] = true; } else if (in_array($tok, $val_args)) { $action[$tok] = $tokens[++$i]; } else { $result[] = $tok; } } else { $result[] = $tok; } } $tokens = $result; return $action; }
php
private function action_arguments(&$tokens, $bool_args, $val_args = array()) { $action = array(); $result = array(); for ($i=0, $len=count($tokens); $i<$len; $i++) { $tok = $tokens[$i]; if (!is_array($tok) && $tok[0] == ':') { $tok = strtolower(substr($tok, 1)); if (in_array($tok, $bool_args)) { $action[$tok] = true; } else if (in_array($tok, $val_args)) { $action[$tok] = $tokens[++$i]; } else { $result[] = $tok; } } else { $result[] = $tok; } } $tokens = $result; return $action; }
[ "private", "function", "action_arguments", "(", "&", "$", "tokens", ",", "$", "bool_args", ",", "$", "val_args", "=", "array", "(", ")", ")", "{", "$", "action", "=", "array", "(", ")", ";", "$", "result", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "0", ",", "$", "len", "=", "count", "(", "$", "tokens", ")", ";", "$", "i", "<", "$", "len", ";", "$", "i", "++", ")", "{", "$", "tok", "=", "$", "tokens", "[", "$", "i", "]", ";", "if", "(", "!", "is_array", "(", "$", "tok", ")", "&&", "$", "tok", "[", "0", "]", "==", "':'", ")", "{", "$", "tok", "=", "strtolower", "(", "substr", "(", "$", "tok", ",", "1", ")", ")", ";", "if", "(", "in_array", "(", "$", "tok", ",", "$", "bool_args", ")", ")", "{", "$", "action", "[", "$", "tok", "]", "=", "true", ";", "}", "else", "if", "(", "in_array", "(", "$", "tok", ",", "$", "val_args", ")", ")", "{", "$", "action", "[", "$", "tok", "]", "=", "$", "tokens", "[", "++", "$", "i", "]", ";", "}", "else", "{", "$", "result", "[", "]", "=", "$", "tok", ";", "}", "}", "else", "{", "$", "result", "[", "]", "=", "$", "tok", ";", "}", "}", "$", "tokens", "=", "$", "result", ";", "return", "$", "action", ";", "}" ]
Extract action arguments
[ "Extract", "action", "arguments" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php#L1053-L1080
train
i-MSCP/roundcube
roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php
rcube_sieve_script.escape_string
static function escape_string($str) { if (is_array($str) && count($str) > 1) { foreach ($str as $idx => $val) $str[$idx] = self::escape_string($val); return '[' . implode(',', $str) . ']'; } else if (is_array($str)) { $str = array_pop($str); } // multi-line string if (preg_match('/[\r\n\0]/', $str)) { return sprintf("text:\n%s\n.\n", self::escape_multiline_string($str)); } // quoted-string else { return '"' . addcslashes($str, '\\"') . '"'; } }
php
static function escape_string($str) { if (is_array($str) && count($str) > 1) { foreach ($str as $idx => $val) $str[$idx] = self::escape_string($val); return '[' . implode(',', $str) . ']'; } else if (is_array($str)) { $str = array_pop($str); } // multi-line string if (preg_match('/[\r\n\0]/', $str)) { return sprintf("text:\n%s\n.\n", self::escape_multiline_string($str)); } // quoted-string else { return '"' . addcslashes($str, '\\"') . '"'; } }
[ "static", "function", "escape_string", "(", "$", "str", ")", "{", "if", "(", "is_array", "(", "$", "str", ")", "&&", "count", "(", "$", "str", ")", ">", "1", ")", "{", "foreach", "(", "$", "str", "as", "$", "idx", "=>", "$", "val", ")", "$", "str", "[", "$", "idx", "]", "=", "self", "::", "escape_string", "(", "$", "val", ")", ";", "return", "'['", ".", "implode", "(", "','", ",", "$", "str", ")", ".", "']'", ";", "}", "else", "if", "(", "is_array", "(", "$", "str", ")", ")", "{", "$", "str", "=", "array_pop", "(", "$", "str", ")", ";", "}", "// multi-line string", "if", "(", "preg_match", "(", "'/[\\r\\n\\0]/'", ",", "$", "str", ")", ")", "{", "return", "sprintf", "(", "\"text:\\n%s\\n.\\n\"", ",", "self", "::", "escape_multiline_string", "(", "$", "str", ")", ")", ";", "}", "// quoted-string", "else", "{", "return", "'\"'", ".", "addcslashes", "(", "$", "str", ",", "'\\\\\"'", ")", ".", "'\"'", ";", "}", "}" ]
Escape special chars into quoted string value or multi-line string or list of strings @param string $str Text or array (list) of strings @return string Result text
[ "Escape", "special", "chars", "into", "quoted", "string", "value", "or", "multi", "-", "line", "string", "or", "list", "of", "strings" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php#L1090-L1110
train
i-MSCP/roundcube
roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php
rcube_sieve_script.escape_multiline_string
static function escape_multiline_string($str) { $str = preg_split('/(\r?\n)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE); foreach ($str as $idx => $line) { // dot-stuffing if (isset($line[0]) && $line[0] == '.') { $str[$idx] = '.' . $line; } } return implode($str); }
php
static function escape_multiline_string($str) { $str = preg_split('/(\r?\n)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE); foreach ($str as $idx => $line) { // dot-stuffing if (isset($line[0]) && $line[0] == '.') { $str[$idx] = '.' . $line; } } return implode($str); }
[ "static", "function", "escape_multiline_string", "(", "$", "str", ")", "{", "$", "str", "=", "preg_split", "(", "'/(\\r?\\n)/'", ",", "$", "str", ",", "-", "1", ",", "PREG_SPLIT_DELIM_CAPTURE", ")", ";", "foreach", "(", "$", "str", "as", "$", "idx", "=>", "$", "line", ")", "{", "// dot-stuffing", "if", "(", "isset", "(", "$", "line", "[", "0", "]", ")", "&&", "$", "line", "[", "0", "]", "==", "'.'", ")", "{", "$", "str", "[", "$", "idx", "]", "=", "'.'", ".", "$", "line", ";", "}", "}", "return", "implode", "(", "$", "str", ")", ";", "}" ]
Escape special chars in multi-line string value @param string $str Text @return string Text
[ "Escape", "special", "chars", "in", "multi", "-", "line", "string", "value" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php#L1119-L1131
train
i-MSCP/roundcube
roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php
rcube_sieve_script.ltrim_position
static function ltrim_position($content, $position, $br = true) { $blanks = array("\t", "\0", "\x0B", " "); if ($br) { $blanks[] = "\r"; $blanks[] = "\n"; } while (isset($content[$position]) && isset($content[$position + 1]) && in_array($content[$position], $blanks, true) ) { $position++; } return $position; }
php
static function ltrim_position($content, $position, $br = true) { $blanks = array("\t", "\0", "\x0B", " "); if ($br) { $blanks[] = "\r"; $blanks[] = "\n"; } while (isset($content[$position]) && isset($content[$position + 1]) && in_array($content[$position], $blanks, true) ) { $position++; } return $position; }
[ "static", "function", "ltrim_position", "(", "$", "content", ",", "$", "position", ",", "$", "br", "=", "true", ")", "{", "$", "blanks", "=", "array", "(", "\"\\t\"", ",", "\"\\0\"", ",", "\"\\x0B\"", ",", "\" \"", ")", ";", "if", "(", "$", "br", ")", "{", "$", "blanks", "[", "]", "=", "\"\\r\"", ";", "$", "blanks", "[", "]", "=", "\"\\n\"", ";", "}", "while", "(", "isset", "(", "$", "content", "[", "$", "position", "]", ")", "&&", "isset", "(", "$", "content", "[", "$", "position", "+", "1", "]", ")", "&&", "in_array", "(", "$", "content", "[", "$", "position", "]", ",", "$", "blanks", ",", "true", ")", ")", "{", "$", "position", "++", ";", "}", "return", "$", "position", ";", "}" ]
Skip whitespace characters in a string from specified position.
[ "Skip", "whitespace", "characters", "in", "a", "string", "from", "specified", "position", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/managesieve/lib/Roundcube/rcube_sieve_script.php#L1314-L1330
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_mime_decode.php
rcube_mime_decode.decode
public function decode($input, $convert = true) { list($header, $body) = $this->splitBodyHeader($input); $struct = $this->do_decode($header, $body); if ($struct && $convert) { $struct = $this->structure_part($struct); } return $struct; }
php
public function decode($input, $convert = true) { list($header, $body) = $this->splitBodyHeader($input); $struct = $this->do_decode($header, $body); if ($struct && $convert) { $struct = $this->structure_part($struct); } return $struct; }
[ "public", "function", "decode", "(", "$", "input", ",", "$", "convert", "=", "true", ")", "{", "list", "(", "$", "header", ",", "$", "body", ")", "=", "$", "this", "->", "splitBodyHeader", "(", "$", "input", ")", ";", "$", "struct", "=", "$", "this", "->", "do_decode", "(", "$", "header", ",", "$", "body", ")", ";", "if", "(", "$", "struct", "&&", "$", "convert", ")", "{", "$", "struct", "=", "$", "this", "->", "structure_part", "(", "$", "struct", ")", ";", "}", "return", "$", "struct", ";", "}" ]
Performs the decoding process. @param string $input The input to decode @param bool $convert Convert result to rcube_message_part structure @return object|bool Decoded results or False on failure
[ "Performs", "the", "decoding", "process", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_mime_decode.php#L75-L86
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_mime_decode.php
rcube_mime_decode.boundarySplit
protected function boundarySplit($input, $boundary) { $tmp = explode('--' . $boundary, $input); for ($i = 1; $i < count($tmp)-1; $i++) { $parts[] = $tmp[$i]; } return $parts; }
php
protected function boundarySplit($input, $boundary) { $tmp = explode('--' . $boundary, $input); for ($i = 1; $i < count($tmp)-1; $i++) { $parts[] = $tmp[$i]; } return $parts; }
[ "protected", "function", "boundarySplit", "(", "$", "input", ",", "$", "boundary", ")", "{", "$", "tmp", "=", "explode", "(", "'--'", ".", "$", "boundary", ",", "$", "input", ")", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<", "count", "(", "$", "tmp", ")", "-", "1", ";", "$", "i", "++", ")", "{", "$", "parts", "[", "]", "=", "$", "tmp", "[", "$", "i", "]", ";", "}", "return", "$", "parts", ";", "}" ]
This function splits the input based on the given boundary @param string $input Input to parse @param string $boundary Boundary @return array Contains array of resulting mime parts
[ "This", "function", "splits", "the", "input", "based", "on", "the", "given", "boundary" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_mime_decode.php#L319-L328
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_mime_decode.php
rcube_mime_decode.structure_part
protected function structure_part($part, $count = 0, $parent = '') { $struct = new rcube_message_part; $struct->mime_id = $part->mime_id ?: (empty($parent) ? (string)$count : "$parent.$count"); $struct->headers = $part->headers; $struct->mimetype = $part->ctype_primary . '/' . $part->ctype_secondary; $struct->ctype_primary = $part->ctype_primary; $struct->ctype_secondary = $part->ctype_secondary; $struct->ctype_parameters = $part->ctype_parameters; if ($part->headers['content-transfer-encoding']) { $struct->encoding = $part->headers['content-transfer-encoding']; } if ($part->ctype_parameters['charset']) { $struct->charset = $part->ctype_parameters['charset']; } $part_charset = $struct->charset ?: $this->params['default_charset']; // determine filename if (($filename = $part->d_parameters['filename']) || ($filename = $part->ctype_parameters['name'])) { if (!$this->params['decode_headers']) { $filename = $this->decodeHeader($filename); } $struct->filename = $filename; } $struct->body = $part->body; $struct->size = strlen($part->body); $struct->disposition = $part->disposition; $count = 0; foreach ((array)$part->parts as $child_part) { $struct->parts[] = $this->structure_part($child_part, ++$count, $struct->mime_id); } return $struct; }
php
protected function structure_part($part, $count = 0, $parent = '') { $struct = new rcube_message_part; $struct->mime_id = $part->mime_id ?: (empty($parent) ? (string)$count : "$parent.$count"); $struct->headers = $part->headers; $struct->mimetype = $part->ctype_primary . '/' . $part->ctype_secondary; $struct->ctype_primary = $part->ctype_primary; $struct->ctype_secondary = $part->ctype_secondary; $struct->ctype_parameters = $part->ctype_parameters; if ($part->headers['content-transfer-encoding']) { $struct->encoding = $part->headers['content-transfer-encoding']; } if ($part->ctype_parameters['charset']) { $struct->charset = $part->ctype_parameters['charset']; } $part_charset = $struct->charset ?: $this->params['default_charset']; // determine filename if (($filename = $part->d_parameters['filename']) || ($filename = $part->ctype_parameters['name'])) { if (!$this->params['decode_headers']) { $filename = $this->decodeHeader($filename); } $struct->filename = $filename; } $struct->body = $part->body; $struct->size = strlen($part->body); $struct->disposition = $part->disposition; $count = 0; foreach ((array)$part->parts as $child_part) { $struct->parts[] = $this->structure_part($child_part, ++$count, $struct->mime_id); } return $struct; }
[ "protected", "function", "structure_part", "(", "$", "part", ",", "$", "count", "=", "0", ",", "$", "parent", "=", "''", ")", "{", "$", "struct", "=", "new", "rcube_message_part", ";", "$", "struct", "->", "mime_id", "=", "$", "part", "->", "mime_id", "?", ":", "(", "empty", "(", "$", "parent", ")", "?", "(", "string", ")", "$", "count", ":", "\"$parent.$count\"", ")", ";", "$", "struct", "->", "headers", "=", "$", "part", "->", "headers", ";", "$", "struct", "->", "mimetype", "=", "$", "part", "->", "ctype_primary", ".", "'/'", ".", "$", "part", "->", "ctype_secondary", ";", "$", "struct", "->", "ctype_primary", "=", "$", "part", "->", "ctype_primary", ";", "$", "struct", "->", "ctype_secondary", "=", "$", "part", "->", "ctype_secondary", ";", "$", "struct", "->", "ctype_parameters", "=", "$", "part", "->", "ctype_parameters", ";", "if", "(", "$", "part", "->", "headers", "[", "'content-transfer-encoding'", "]", ")", "{", "$", "struct", "->", "encoding", "=", "$", "part", "->", "headers", "[", "'content-transfer-encoding'", "]", ";", "}", "if", "(", "$", "part", "->", "ctype_parameters", "[", "'charset'", "]", ")", "{", "$", "struct", "->", "charset", "=", "$", "part", "->", "ctype_parameters", "[", "'charset'", "]", ";", "}", "$", "part_charset", "=", "$", "struct", "->", "charset", "?", ":", "$", "this", "->", "params", "[", "'default_charset'", "]", ";", "// determine filename", "if", "(", "(", "$", "filename", "=", "$", "part", "->", "d_parameters", "[", "'filename'", "]", ")", "||", "(", "$", "filename", "=", "$", "part", "->", "ctype_parameters", "[", "'name'", "]", ")", ")", "{", "if", "(", "!", "$", "this", "->", "params", "[", "'decode_headers'", "]", ")", "{", "$", "filename", "=", "$", "this", "->", "decodeHeader", "(", "$", "filename", ")", ";", "}", "$", "struct", "->", "filename", "=", "$", "filename", ";", "}", "$", "struct", "->", "body", "=", "$", "part", "->", "body", ";", "$", "struct", "->", "size", "=", "strlen", "(", "$", "part", "->", "body", ")", ";", "$", "struct", "->", "disposition", "=", "$", "part", "->", "disposition", ";", "$", "count", "=", "0", ";", "foreach", "(", "(", "array", ")", "$", "part", "->", "parts", "as", "$", "child_part", ")", "{", "$", "struct", "->", "parts", "[", "]", "=", "$", "this", "->", "structure_part", "(", "$", "child_part", ",", "++", "$", "count", ",", "$", "struct", "->", "mime_id", ")", ";", "}", "return", "$", "struct", ";", "}" ]
Recursive method to convert a rcube_mime_decode structure into a rcube_message_part object. @param object $part A message part struct @param int $count Part count @param string $parent Parent MIME ID @return object rcube_message_part @see self::decode()
[ "Recursive", "method", "to", "convert", "a", "rcube_mime_decode", "structure", "into", "a", "rcube_message_part", "object", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_mime_decode.php#L355-L394
train
i-MSCP/roundcube
roundcubemail/plugins/emoticons/emoticons_engine.php
emoticons_engine.icons2text
public static function icons2text($html) { $emoticons = array( '8-)' => 'smiley-cool', ':-#' => 'smiley-foot-in-mouth', ':-*' => 'smiley-kiss', ':-X' => 'smiley-sealed', ':-P' => 'smiley-tongue-out', ':-@' => 'smiley-yell', ":'(" => 'smiley-cry', ':-(' => 'smiley-frown', ':-D' => 'smiley-laughing', ':-)' => 'smiley-smile', ':-S' => 'smiley-undecided', ':-$' => 'smiley-embarassed', 'O:-)' => 'smiley-innocent', ':-|' => 'smiley-money-mouth', ':-O' => 'smiley-surprised', ';-)' => 'smiley-wink', ); foreach ($emoticons as $idx => $file) { // <img title="Cry" src="http://.../program/js/tinymce/plugins/emoticons/img/smiley-cry.gif" border="0" alt="Cry" /> $file = preg_quote(self::IMG_PATH . $file . '.gif', '/'); $search[] = '/<img (title="[a-z ]+" )?src="[^"]+' . $file . '"[^>]+\/>/i'; $replace[] = $idx; } return preg_replace($search, $replace, $html); }
php
public static function icons2text($html) { $emoticons = array( '8-)' => 'smiley-cool', ':-#' => 'smiley-foot-in-mouth', ':-*' => 'smiley-kiss', ':-X' => 'smiley-sealed', ':-P' => 'smiley-tongue-out', ':-@' => 'smiley-yell', ":'(" => 'smiley-cry', ':-(' => 'smiley-frown', ':-D' => 'smiley-laughing', ':-)' => 'smiley-smile', ':-S' => 'smiley-undecided', ':-$' => 'smiley-embarassed', 'O:-)' => 'smiley-innocent', ':-|' => 'smiley-money-mouth', ':-O' => 'smiley-surprised', ';-)' => 'smiley-wink', ); foreach ($emoticons as $idx => $file) { // <img title="Cry" src="http://.../program/js/tinymce/plugins/emoticons/img/smiley-cry.gif" border="0" alt="Cry" /> $file = preg_quote(self::IMG_PATH . $file . '.gif', '/'); $search[] = '/<img (title="[a-z ]+" )?src="[^"]+' . $file . '"[^>]+\/>/i'; $replace[] = $idx; } return preg_replace($search, $replace, $html); }
[ "public", "static", "function", "icons2text", "(", "$", "html", ")", "{", "$", "emoticons", "=", "array", "(", "'8-)'", "=>", "'smiley-cool'", ",", "':-#'", "=>", "'smiley-foot-in-mouth'", ",", "':-*'", "=>", "'smiley-kiss'", ",", "':-X'", "=>", "'smiley-sealed'", ",", "':-P'", "=>", "'smiley-tongue-out'", ",", "':-@'", "=>", "'smiley-yell'", ",", "\":'(\"", "=>", "'smiley-cry'", ",", "':-('", "=>", "'smiley-frown'", ",", "':-D'", "=>", "'smiley-laughing'", ",", "':-)'", "=>", "'smiley-smile'", ",", "':-S'", "=>", "'smiley-undecided'", ",", "':-$'", "=>", "'smiley-embarassed'", ",", "'O:-)'", "=>", "'smiley-innocent'", ",", "':-|'", "=>", "'smiley-money-mouth'", ",", "':-O'", "=>", "'smiley-surprised'", ",", "';-)'", "=>", "'smiley-wink'", ",", ")", ";", "foreach", "(", "$", "emoticons", "as", "$", "idx", "=>", "$", "file", ")", "{", "// <img title=\"Cry\" src=\"http://.../program/js/tinymce/plugins/emoticons/img/smiley-cry.gif\" border=\"0\" alt=\"Cry\" />", "$", "file", "=", "preg_quote", "(", "self", "::", "IMG_PATH", ".", "$", "file", ".", "'.gif'", ",", "'/'", ")", ";", "$", "search", "[", "]", "=", "'/<img (title=\"[a-z ]+\" )?src=\"[^\"]+'", ".", "$", "file", ".", "'\"[^>]+\\/>/i'", ";", "$", "replace", "[", "]", "=", "$", "idx", ";", "}", "return", "preg_replace", "(", "$", "search", ",", "$", "replace", ",", "$", "html", ")", ";", "}" ]
Replaces TinyMCE's emoticon images with plain-text representation @param string $html HTML content @return string HTML content
[ "Replaces", "TinyMCE", "s", "emoticon", "images", "with", "plain", "-", "text", "representation" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/emoticons/emoticons_engine.php#L19-L48
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_addressbook.php
rcube_addressbook.insertMultiple
function insertMultiple($recset, $check=false) { $ids = array(); if (is_object($recset) && is_a($recset, rcube_result_set)) { while ($row = $recset->next()) { if ($insert = $this->insert($row, $check)) $ids[] = $insert; } } return $ids; }
php
function insertMultiple($recset, $check=false) { $ids = array(); if (is_object($recset) && is_a($recset, rcube_result_set)) { while ($row = $recset->next()) { if ($insert = $this->insert($row, $check)) $ids[] = $insert; } } return $ids; }
[ "function", "insertMultiple", "(", "$", "recset", ",", "$", "check", "=", "false", ")", "{", "$", "ids", "=", "array", "(", ")", ";", "if", "(", "is_object", "(", "$", "recset", ")", "&&", "is_a", "(", "$", "recset", ",", "rcube_result_set", ")", ")", "{", "while", "(", "$", "row", "=", "$", "recset", "->", "next", "(", ")", ")", "{", "if", "(", "$", "insert", "=", "$", "this", "->", "insert", "(", "$", "row", ",", "$", "check", ")", ")", "$", "ids", "[", "]", "=", "$", "insert", ";", "}", "}", "return", "$", "ids", ";", "}" ]
Create new contact records for every item in the record set @param rcube_result_set $recset Recordset to insert @param boolean $check True to check for duplicates first @return array List of created record IDs
[ "Create", "new", "contact", "records", "for", "every", "item", "in", "the", "record", "set" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_addressbook.php#L275-L285
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_addressbook.php
rcube_addressbook.get_col_values
public static function get_col_values($col, $data, $flat = false) { $out = array(); foreach ((array)$data as $c => $values) { if ($c === $col || strpos($c, $col.':') === 0) { if ($flat) { $out = array_merge($out, (array)$values); } else { list(, $type) = explode(':', $c); $out[$type] = array_merge((array)$out[$type], (array)$values); } } } // remove duplicates if ($flat && !empty($out)) { $out = array_unique($out); } return $out; }
php
public static function get_col_values($col, $data, $flat = false) { $out = array(); foreach ((array)$data as $c => $values) { if ($c === $col || strpos($c, $col.':') === 0) { if ($flat) { $out = array_merge($out, (array)$values); } else { list(, $type) = explode(':', $c); $out[$type] = array_merge((array)$out[$type], (array)$values); } } } // remove duplicates if ($flat && !empty($out)) { $out = array_unique($out); } return $out; }
[ "public", "static", "function", "get_col_values", "(", "$", "col", ",", "$", "data", ",", "$", "flat", "=", "false", ")", "{", "$", "out", "=", "array", "(", ")", ";", "foreach", "(", "(", "array", ")", "$", "data", "as", "$", "c", "=>", "$", "values", ")", "{", "if", "(", "$", "c", "===", "$", "col", "||", "strpos", "(", "$", "c", ",", "$", "col", ".", "':'", ")", "===", "0", ")", "{", "if", "(", "$", "flat", ")", "{", "$", "out", "=", "array_merge", "(", "$", "out", ",", "(", "array", ")", "$", "values", ")", ";", "}", "else", "{", "list", "(", ",", "$", "type", ")", "=", "explode", "(", "':'", ",", "$", "c", ")", ";", "$", "out", "[", "$", "type", "]", "=", "array_merge", "(", "(", "array", ")", "$", "out", "[", "$", "type", "]", ",", "(", "array", ")", "$", "values", ")", ";", "}", "}", "}", "// remove duplicates", "if", "(", "$", "flat", "&&", "!", "empty", "(", "$", "out", ")", ")", "{", "$", "out", "=", "array_unique", "(", "$", "out", ")", ";", "}", "return", "$", "out", ";", "}" ]
Utility function to return all values of a certain data column either as flat list or grouped by subtype @param string $col Col name @param array $data Record data array as used for saving @param bool $flat True to return one array with all values, False for hash array with values grouped by type @return array List of column values
[ "Utility", "function", "to", "return", "all", "values", "of", "a", "certain", "data", "column", "either", "as", "flat", "list", "or", "grouped", "by", "subtype" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_addressbook.php#L460-L481
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_addressbook.php
rcube_addressbook.compose_display_name
public static function compose_display_name($contact, $full_email = false) { $contact = rcube::get_instance()->plugins->exec_hook('contact_displayname', $contact); $fn = $contact['name']; // default display name composition according to vcard standard if (!$fn) { $fn = join(' ', array_filter(array($contact['prefix'], $contact['firstname'], $contact['middlename'], $contact['surname'], $contact['suffix']))); $fn = trim(preg_replace('/\s+/u', ' ', $fn)); } // use email address part for name $email = self::get_col_values('email', $contact, true); $email = $email[0]; if ($email && (empty($fn) || $fn == $email)) { // return full email if ($full_email) return $email; list($emailname) = explode('@', $email); if (preg_match('/(.*)[\.\-\_](.*)/', $emailname, $match)) $fn = trim(ucfirst($match[1]).' '.ucfirst($match[2])); else $fn = ucfirst($emailname); } return $fn; }
php
public static function compose_display_name($contact, $full_email = false) { $contact = rcube::get_instance()->plugins->exec_hook('contact_displayname', $contact); $fn = $contact['name']; // default display name composition according to vcard standard if (!$fn) { $fn = join(' ', array_filter(array($contact['prefix'], $contact['firstname'], $contact['middlename'], $contact['surname'], $contact['suffix']))); $fn = trim(preg_replace('/\s+/u', ' ', $fn)); } // use email address part for name $email = self::get_col_values('email', $contact, true); $email = $email[0]; if ($email && (empty($fn) || $fn == $email)) { // return full email if ($full_email) return $email; list($emailname) = explode('@', $email); if (preg_match('/(.*)[\.\-\_](.*)/', $emailname, $match)) $fn = trim(ucfirst($match[1]).' '.ucfirst($match[2])); else $fn = ucfirst($emailname); } return $fn; }
[ "public", "static", "function", "compose_display_name", "(", "$", "contact", ",", "$", "full_email", "=", "false", ")", "{", "$", "contact", "=", "rcube", "::", "get_instance", "(", ")", "->", "plugins", "->", "exec_hook", "(", "'contact_displayname'", ",", "$", "contact", ")", ";", "$", "fn", "=", "$", "contact", "[", "'name'", "]", ";", "// default display name composition according to vcard standard", "if", "(", "!", "$", "fn", ")", "{", "$", "fn", "=", "join", "(", "' '", ",", "array_filter", "(", "array", "(", "$", "contact", "[", "'prefix'", "]", ",", "$", "contact", "[", "'firstname'", "]", ",", "$", "contact", "[", "'middlename'", "]", ",", "$", "contact", "[", "'surname'", "]", ",", "$", "contact", "[", "'suffix'", "]", ")", ")", ")", ";", "$", "fn", "=", "trim", "(", "preg_replace", "(", "'/\\s+/u'", ",", "' '", ",", "$", "fn", ")", ")", ";", "}", "// use email address part for name", "$", "email", "=", "self", "::", "get_col_values", "(", "'email'", ",", "$", "contact", ",", "true", ")", ";", "$", "email", "=", "$", "email", "[", "0", "]", ";", "if", "(", "$", "email", "&&", "(", "empty", "(", "$", "fn", ")", "||", "$", "fn", "==", "$", "email", ")", ")", "{", "// return full email", "if", "(", "$", "full_email", ")", "return", "$", "email", ";", "list", "(", "$", "emailname", ")", "=", "explode", "(", "'@'", ",", "$", "email", ")", ";", "if", "(", "preg_match", "(", "'/(.*)[\\.\\-\\_](.*)/'", ",", "$", "emailname", ",", "$", "match", ")", ")", "$", "fn", "=", "trim", "(", "ucfirst", "(", "$", "match", "[", "1", "]", ")", ".", "' '", ".", "ucfirst", "(", "$", "match", "[", "2", "]", ")", ")", ";", "else", "$", "fn", "=", "ucfirst", "(", "$", "emailname", ")", ";", "}", "return", "$", "fn", ";", "}" ]
Compose a valid display name from the given structured contact data @param array $contact Hash array with contact data as key-value pairs @param bool $full_email Don't attempt to extract components from the email address @return string Display name
[ "Compose", "a", "valid", "display", "name", "from", "the", "given", "structured", "contact", "data" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_addressbook.php#L504-L532
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_addressbook.php
rcube_addressbook.compose_list_name
public static function compose_list_name($contact) { static $compose_mode; if (!isset($compose_mode)) // cache this $compose_mode = rcube::get_instance()->config->get('addressbook_name_listing', 0); if ($compose_mode == 3) $fn = join(' ', array($contact['surname'] . ',', $contact['firstname'], $contact['middlename'])); else if ($compose_mode == 2) $fn = join(' ', array($contact['surname'], $contact['firstname'], $contact['middlename'])); else if ($compose_mode == 1) $fn = join(' ', array($contact['firstname'], $contact['middlename'], $contact['surname'])); else if ($compose_mode == 0) $fn = $contact['name'] ?: join(' ', array($contact['prefix'], $contact['firstname'], $contact['middlename'], $contact['surname'], $contact['suffix'])); else { $plugin = rcube::get_instance()->plugins->exec_hook('contact_listname', array('contact' => $contact)); $fn = $plugin['fn']; } $fn = trim($fn, ', '); $fn = preg_replace('/\s+/u', ' ', $fn); // fallbacks... if ($fn === '') { // ... display name if ($name = trim($contact['name'])) { $fn = $name; } // ... organization else if ($org = trim($contact['organization'])) { $fn = $org; } // ... email address else if (($email = self::get_col_values('email', $contact, true)) && !empty($email)) { $fn = $email[0]; } } return $fn; }
php
public static function compose_list_name($contact) { static $compose_mode; if (!isset($compose_mode)) // cache this $compose_mode = rcube::get_instance()->config->get('addressbook_name_listing', 0); if ($compose_mode == 3) $fn = join(' ', array($contact['surname'] . ',', $contact['firstname'], $contact['middlename'])); else if ($compose_mode == 2) $fn = join(' ', array($contact['surname'], $contact['firstname'], $contact['middlename'])); else if ($compose_mode == 1) $fn = join(' ', array($contact['firstname'], $contact['middlename'], $contact['surname'])); else if ($compose_mode == 0) $fn = $contact['name'] ?: join(' ', array($contact['prefix'], $contact['firstname'], $contact['middlename'], $contact['surname'], $contact['suffix'])); else { $plugin = rcube::get_instance()->plugins->exec_hook('contact_listname', array('contact' => $contact)); $fn = $plugin['fn']; } $fn = trim($fn, ', '); $fn = preg_replace('/\s+/u', ' ', $fn); // fallbacks... if ($fn === '') { // ... display name if ($name = trim($contact['name'])) { $fn = $name; } // ... organization else if ($org = trim($contact['organization'])) { $fn = $org; } // ... email address else if (($email = self::get_col_values('email', $contact, true)) && !empty($email)) { $fn = $email[0]; } } return $fn; }
[ "public", "static", "function", "compose_list_name", "(", "$", "contact", ")", "{", "static", "$", "compose_mode", ";", "if", "(", "!", "isset", "(", "$", "compose_mode", ")", ")", "// cache this", "$", "compose_mode", "=", "rcube", "::", "get_instance", "(", ")", "->", "config", "->", "get", "(", "'addressbook_name_listing'", ",", "0", ")", ";", "if", "(", "$", "compose_mode", "==", "3", ")", "$", "fn", "=", "join", "(", "' '", ",", "array", "(", "$", "contact", "[", "'surname'", "]", ".", "','", ",", "$", "contact", "[", "'firstname'", "]", ",", "$", "contact", "[", "'middlename'", "]", ")", ")", ";", "else", "if", "(", "$", "compose_mode", "==", "2", ")", "$", "fn", "=", "join", "(", "' '", ",", "array", "(", "$", "contact", "[", "'surname'", "]", ",", "$", "contact", "[", "'firstname'", "]", ",", "$", "contact", "[", "'middlename'", "]", ")", ")", ";", "else", "if", "(", "$", "compose_mode", "==", "1", ")", "$", "fn", "=", "join", "(", "' '", ",", "array", "(", "$", "contact", "[", "'firstname'", "]", ",", "$", "contact", "[", "'middlename'", "]", ",", "$", "contact", "[", "'surname'", "]", ")", ")", ";", "else", "if", "(", "$", "compose_mode", "==", "0", ")", "$", "fn", "=", "$", "contact", "[", "'name'", "]", "?", ":", "join", "(", "' '", ",", "array", "(", "$", "contact", "[", "'prefix'", "]", ",", "$", "contact", "[", "'firstname'", "]", ",", "$", "contact", "[", "'middlename'", "]", ",", "$", "contact", "[", "'surname'", "]", ",", "$", "contact", "[", "'suffix'", "]", ")", ")", ";", "else", "{", "$", "plugin", "=", "rcube", "::", "get_instance", "(", ")", "->", "plugins", "->", "exec_hook", "(", "'contact_listname'", ",", "array", "(", "'contact'", "=>", "$", "contact", ")", ")", ";", "$", "fn", "=", "$", "plugin", "[", "'fn'", "]", ";", "}", "$", "fn", "=", "trim", "(", "$", "fn", ",", "', '", ")", ";", "$", "fn", "=", "preg_replace", "(", "'/\\s+/u'", ",", "' '", ",", "$", "fn", ")", ";", "// fallbacks...", "if", "(", "$", "fn", "===", "''", ")", "{", "// ... display name", "if", "(", "$", "name", "=", "trim", "(", "$", "contact", "[", "'name'", "]", ")", ")", "{", "$", "fn", "=", "$", "name", ";", "}", "// ... organization", "else", "if", "(", "$", "org", "=", "trim", "(", "$", "contact", "[", "'organization'", "]", ")", ")", "{", "$", "fn", "=", "$", "org", ";", "}", "// ... email address", "else", "if", "(", "(", "$", "email", "=", "self", "::", "get_col_values", "(", "'email'", ",", "$", "contact", ",", "true", ")", ")", "&&", "!", "empty", "(", "$", "email", ")", ")", "{", "$", "fn", "=", "$", "email", "[", "0", "]", ";", "}", "}", "return", "$", "fn", ";", "}" ]
Compose the name to display in the contacts list for the given contact record. This respects the settings parameter how to list conacts. @param array $contact Hash array with contact data as key-value pairs @return string List name
[ "Compose", "the", "name", "to", "display", "in", "the", "contacts", "list", "for", "the", "given", "contact", "record", ".", "This", "respects", "the", "settings", "parameter", "how", "to", "list", "conacts", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_addressbook.php#L542-L582
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_addressbook.php
rcube_addressbook.compose_search_name
public static function compose_search_name($contact, $email = null, $name = null, $templ = null) { static $template; if (empty($templ) && !isset($template)) { // cache this $template = rcube::get_instance()->config->get('contact_search_name'); if (empty($template)) { $template = '{name} <{email}>'; } } $result = $templ ?: $template; if (preg_match_all('/\{[a-z]+\}/', $result, $matches)) { foreach ($matches[0] as $key) { $key = trim($key, '{}'); $value = ''; switch ($key) { case 'name': $value = $name ?: self::compose_list_name($contact); // If name(s) are undefined compose_list_name() may return an email address // here we prevent from returning the same name and email if ($name === $email && strpos($result, '{email}') !== false) { $value = ''; } break; case 'email': $value = $email; break; } if (empty($value)) { $value = strpos($key, ':') ? $contact[$key] : self::get_col_values($key, $contact, true); if (is_array($value)) { $value = $value[0]; } } $result = str_replace('{' . $key . '}', $value, $result); } } $result = preg_replace('/\s+/u', ' ', $result); $result = preg_replace('/\s*(<>|\(\)|\[\])/u', '', $result); $result = trim($result, '/ '); return $result; }
php
public static function compose_search_name($contact, $email = null, $name = null, $templ = null) { static $template; if (empty($templ) && !isset($template)) { // cache this $template = rcube::get_instance()->config->get('contact_search_name'); if (empty($template)) { $template = '{name} <{email}>'; } } $result = $templ ?: $template; if (preg_match_all('/\{[a-z]+\}/', $result, $matches)) { foreach ($matches[0] as $key) { $key = trim($key, '{}'); $value = ''; switch ($key) { case 'name': $value = $name ?: self::compose_list_name($contact); // If name(s) are undefined compose_list_name() may return an email address // here we prevent from returning the same name and email if ($name === $email && strpos($result, '{email}') !== false) { $value = ''; } break; case 'email': $value = $email; break; } if (empty($value)) { $value = strpos($key, ':') ? $contact[$key] : self::get_col_values($key, $contact, true); if (is_array($value)) { $value = $value[0]; } } $result = str_replace('{' . $key . '}', $value, $result); } } $result = preg_replace('/\s+/u', ' ', $result); $result = preg_replace('/\s*(<>|\(\)|\[\])/u', '', $result); $result = trim($result, '/ '); return $result; }
[ "public", "static", "function", "compose_search_name", "(", "$", "contact", ",", "$", "email", "=", "null", ",", "$", "name", "=", "null", ",", "$", "templ", "=", "null", ")", "{", "static", "$", "template", ";", "if", "(", "empty", "(", "$", "templ", ")", "&&", "!", "isset", "(", "$", "template", ")", ")", "{", "// cache this", "$", "template", "=", "rcube", "::", "get_instance", "(", ")", "->", "config", "->", "get", "(", "'contact_search_name'", ")", ";", "if", "(", "empty", "(", "$", "template", ")", ")", "{", "$", "template", "=", "'{name} <{email}>'", ";", "}", "}", "$", "result", "=", "$", "templ", "?", ":", "$", "template", ";", "if", "(", "preg_match_all", "(", "'/\\{[a-z]+\\}/'", ",", "$", "result", ",", "$", "matches", ")", ")", "{", "foreach", "(", "$", "matches", "[", "0", "]", "as", "$", "key", ")", "{", "$", "key", "=", "trim", "(", "$", "key", ",", "'{}'", ")", ";", "$", "value", "=", "''", ";", "switch", "(", "$", "key", ")", "{", "case", "'name'", ":", "$", "value", "=", "$", "name", "?", ":", "self", "::", "compose_list_name", "(", "$", "contact", ")", ";", "// If name(s) are undefined compose_list_name() may return an email address", "// here we prevent from returning the same name and email", "if", "(", "$", "name", "===", "$", "email", "&&", "strpos", "(", "$", "result", ",", "'{email}'", ")", "!==", "false", ")", "{", "$", "value", "=", "''", ";", "}", "break", ";", "case", "'email'", ":", "$", "value", "=", "$", "email", ";", "break", ";", "}", "if", "(", "empty", "(", "$", "value", ")", ")", "{", "$", "value", "=", "strpos", "(", "$", "key", ",", "':'", ")", "?", "$", "contact", "[", "$", "key", "]", ":", "self", "::", "get_col_values", "(", "$", "key", ",", "$", "contact", ",", "true", ")", ";", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "value", "=", "$", "value", "[", "0", "]", ";", "}", "}", "$", "result", "=", "str_replace", "(", "'{'", ".", "$", "key", ".", "'}'", ",", "$", "value", ",", "$", "result", ")", ";", "}", "}", "$", "result", "=", "preg_replace", "(", "'/\\s+/u'", ",", "' '", ",", "$", "result", ")", ";", "$", "result", "=", "preg_replace", "(", "'/\\s*(<>|\\(\\)|\\[\\])/u'", ",", "''", ",", "$", "result", ")", ";", "$", "result", "=", "trim", "(", "$", "result", ",", "'/ '", ")", ";", "return", "$", "result", ";", "}" ]
Build contact display name for autocomplete listing @param array $contact Hash array with contact data as key-value pairs @param string $email Optional email address @param string $name Optional name (self::compose_list_name() result) @param string $templ Optional template to use (defaults to the 'contact_search_name' config option) @return string Display name
[ "Build", "contact", "display", "name", "for", "autocomplete", "listing" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_addressbook.php#L594-L645
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_addressbook.php
rcube_addressbook.compose_contact_key
public static function compose_contact_key($contact, $sort_col) { $key = $contact[$sort_col]; // add email to a key to not skip contacts with the same name (#1488375) if (($email = self::get_col_values('email', $contact, true)) && !empty($email)) { $key .= ':' . implode(':', (array)$email); } // Make the key really unique (as we e.g. support contacts with no email) $key .= ':' . $contact['sourceid'] . ':' . $contact['ID']; return $key; }
php
public static function compose_contact_key($contact, $sort_col) { $key = $contact[$sort_col]; // add email to a key to not skip contacts with the same name (#1488375) if (($email = self::get_col_values('email', $contact, true)) && !empty($email)) { $key .= ':' . implode(':', (array)$email); } // Make the key really unique (as we e.g. support contacts with no email) $key .= ':' . $contact['sourceid'] . ':' . $contact['ID']; return $key; }
[ "public", "static", "function", "compose_contact_key", "(", "$", "contact", ",", "$", "sort_col", ")", "{", "$", "key", "=", "$", "contact", "[", "$", "sort_col", "]", ";", "// add email to a key to not skip contacts with the same name (#1488375)", "if", "(", "(", "$", "email", "=", "self", "::", "get_col_values", "(", "'email'", ",", "$", "contact", ",", "true", ")", ")", "&&", "!", "empty", "(", "$", "email", ")", ")", "{", "$", "key", ".=", "':'", ".", "implode", "(", "':'", ",", "(", "array", ")", "$", "email", ")", ";", "}", "// Make the key really unique (as we e.g. support contacts with no email)", "$", "key", ".=", "':'", ".", "$", "contact", "[", "'sourceid'", "]", ".", "':'", ".", "$", "contact", "[", "'ID'", "]", ";", "return", "$", "key", ";", "}" ]
Create a unique key for sorting contacts @param array $contact Contact record @param string $sort_col Sorting column name @return string Unique key
[ "Create", "a", "unique", "key", "for", "sorting", "contacts" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_addressbook.php#L655-L668
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_addressbook.php
rcube_addressbook.compare_search_value
protected function compare_search_value($colname, $value, $search, $mode) { // The value is a date string, for date we'll // use only strict comparison (mode = 1) // @TODO: partial search, e.g. match only day and month if (in_array($colname, $this->date_cols)) { return (($value = rcube_utils::anytodatetime($value)) && ($search = rcube_utils::anytodatetime($search)) && $value->format('Ymd') == $search->format('Ymd')); } // Gender is a special value, must use strict comparison (#5757) if ($colname == 'gender') { $mode = self::SEARCH_STRICT; } // composite field, e.g. address foreach ((array)$value as $val) { $val = mb_strtolower($val); if ($mode & self::SEARCH_STRICT) { $got = ($val == $search); } else if ($mode & self::SEARCH_PREFIX) { $got = ($search == substr($val, 0, strlen($search))); } else { $got = (strpos($val, $search) !== false); } if ($got) { return true; } } return false; }
php
protected function compare_search_value($colname, $value, $search, $mode) { // The value is a date string, for date we'll // use only strict comparison (mode = 1) // @TODO: partial search, e.g. match only day and month if (in_array($colname, $this->date_cols)) { return (($value = rcube_utils::anytodatetime($value)) && ($search = rcube_utils::anytodatetime($search)) && $value->format('Ymd') == $search->format('Ymd')); } // Gender is a special value, must use strict comparison (#5757) if ($colname == 'gender') { $mode = self::SEARCH_STRICT; } // composite field, e.g. address foreach ((array)$value as $val) { $val = mb_strtolower($val); if ($mode & self::SEARCH_STRICT) { $got = ($val == $search); } else if ($mode & self::SEARCH_PREFIX) { $got = ($search == substr($val, 0, strlen($search))); } else { $got = (strpos($val, $search) !== false); } if ($got) { return true; } } return false; }
[ "protected", "function", "compare_search_value", "(", "$", "colname", ",", "$", "value", ",", "$", "search", ",", "$", "mode", ")", "{", "// The value is a date string, for date we'll", "// use only strict comparison (mode = 1)", "// @TODO: partial search, e.g. match only day and month", "if", "(", "in_array", "(", "$", "colname", ",", "$", "this", "->", "date_cols", ")", ")", "{", "return", "(", "(", "$", "value", "=", "rcube_utils", "::", "anytodatetime", "(", "$", "value", ")", ")", "&&", "(", "$", "search", "=", "rcube_utils", "::", "anytodatetime", "(", "$", "search", ")", ")", "&&", "$", "value", "->", "format", "(", "'Ymd'", ")", "==", "$", "search", "->", "format", "(", "'Ymd'", ")", ")", ";", "}", "// Gender is a special value, must use strict comparison (#5757)", "if", "(", "$", "colname", "==", "'gender'", ")", "{", "$", "mode", "=", "self", "::", "SEARCH_STRICT", ";", "}", "// composite field, e.g. address", "foreach", "(", "(", "array", ")", "$", "value", "as", "$", "val", ")", "{", "$", "val", "=", "mb_strtolower", "(", "$", "val", ")", ";", "if", "(", "$", "mode", "&", "self", "::", "SEARCH_STRICT", ")", "{", "$", "got", "=", "(", "$", "val", "==", "$", "search", ")", ";", "}", "else", "if", "(", "$", "mode", "&", "self", "::", "SEARCH_PREFIX", ")", "{", "$", "got", "=", "(", "$", "search", "==", "substr", "(", "$", "val", ",", "0", ",", "strlen", "(", "$", "search", ")", ")", ")", ";", "}", "else", "{", "$", "got", "=", "(", "strpos", "(", "$", "val", ",", "$", "search", ")", "!==", "false", ")", ";", "}", "if", "(", "$", "got", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Compare search value with contact data @param string $colname Data name @param string|array $value Data value @param string $search Search value @param int $mode Search mode @return bool Comparison result
[ "Compare", "search", "value", "with", "contact", "data" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_addressbook.php#L680-L716
train
i-MSCP/roundcube
roundcubemail/plugins/vcard_attachments/vcard_attachments.php
vcard_attachments.message_load
function message_load($p) { $this->message = $p['object']; // handle attachments vcard attachments foreach ((array)$this->message->attachments as $attachment) { if ($this->is_vcard($attachment)) { $this->vcard_parts[] = $attachment->mime_id; } } // the same with message bodies foreach ((array)$this->message->parts as $part) { if ($this->is_vcard($part)) { $this->vcard_parts[] = $part->mime_id; $this->vcard_bodies[] = $part->mime_id; } } if ($this->vcard_parts) { $this->add_texts('localization'); } }
php
function message_load($p) { $this->message = $p['object']; // handle attachments vcard attachments foreach ((array)$this->message->attachments as $attachment) { if ($this->is_vcard($attachment)) { $this->vcard_parts[] = $attachment->mime_id; } } // the same with message bodies foreach ((array)$this->message->parts as $part) { if ($this->is_vcard($part)) { $this->vcard_parts[] = $part->mime_id; $this->vcard_bodies[] = $part->mime_id; } } if ($this->vcard_parts) { $this->add_texts('localization'); } }
[ "function", "message_load", "(", "$", "p", ")", "{", "$", "this", "->", "message", "=", "$", "p", "[", "'object'", "]", ";", "// handle attachments vcard attachments", "foreach", "(", "(", "array", ")", "$", "this", "->", "message", "->", "attachments", "as", "$", "attachment", ")", "{", "if", "(", "$", "this", "->", "is_vcard", "(", "$", "attachment", ")", ")", "{", "$", "this", "->", "vcard_parts", "[", "]", "=", "$", "attachment", "->", "mime_id", ";", "}", "}", "// the same with message bodies", "foreach", "(", "(", "array", ")", "$", "this", "->", "message", "->", "parts", "as", "$", "part", ")", "{", "if", "(", "$", "this", "->", "is_vcard", "(", "$", "part", ")", ")", "{", "$", "this", "->", "vcard_parts", "[", "]", "=", "$", "part", "->", "mime_id", ";", "$", "this", "->", "vcard_bodies", "[", "]", "=", "$", "part", "->", "mime_id", ";", "}", "}", "if", "(", "$", "this", "->", "vcard_parts", ")", "{", "$", "this", "->", "add_texts", "(", "'localization'", ")", ";", "}", "}" ]
Check message bodies and attachments for vcards
[ "Check", "message", "bodies", "and", "attachments", "for", "vcards" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/vcard_attachments/vcard_attachments.php#L60-L81
train
i-MSCP/roundcube
roundcubemail/plugins/vcard_attachments/vcard_attachments.php
vcard_attachments.html_output
function html_output($p) { $attach_script = false; foreach ($this->vcard_parts as $part) { $vcards = rcube_vcard::import($this->message->get_part_content($part, null, true)); // successfully parsed vcards? if (empty($vcards)) { continue; } // remove part's body if (in_array($part, $this->vcard_bodies)) { $p['content'] = ''; } foreach ($vcards as $idx => $vcard) { // skip invalid vCards if (empty($vcard->email) || empty($vcard->email[0])) { continue; } $display = $vcard->displayname . ' <'.$vcard->email[0].'>'; // add box below message body $p['content'] .= html::p(array('class' => 'vcardattachment'), html::a(array( 'href' => "#", 'onclick' => "return plugin_vcard_save_contact('" . rcube::JQ($part.':'.$idx) . "')", 'title' => $this->gettext('addvcardmsg'), ), html::span(null, rcube::Q($display))) ); } $attach_script = true; } if ($attach_script) { $this->include_script('vcardattach.js'); $this->include_stylesheet($this->local_skin_path() . '/style.css'); } return $p; }
php
function html_output($p) { $attach_script = false; foreach ($this->vcard_parts as $part) { $vcards = rcube_vcard::import($this->message->get_part_content($part, null, true)); // successfully parsed vcards? if (empty($vcards)) { continue; } // remove part's body if (in_array($part, $this->vcard_bodies)) { $p['content'] = ''; } foreach ($vcards as $idx => $vcard) { // skip invalid vCards if (empty($vcard->email) || empty($vcard->email[0])) { continue; } $display = $vcard->displayname . ' <'.$vcard->email[0].'>'; // add box below message body $p['content'] .= html::p(array('class' => 'vcardattachment'), html::a(array( 'href' => "#", 'onclick' => "return plugin_vcard_save_contact('" . rcube::JQ($part.':'.$idx) . "')", 'title' => $this->gettext('addvcardmsg'), ), html::span(null, rcube::Q($display))) ); } $attach_script = true; } if ($attach_script) { $this->include_script('vcardattach.js'); $this->include_stylesheet($this->local_skin_path() . '/style.css'); } return $p; }
[ "function", "html_output", "(", "$", "p", ")", "{", "$", "attach_script", "=", "false", ";", "foreach", "(", "$", "this", "->", "vcard_parts", "as", "$", "part", ")", "{", "$", "vcards", "=", "rcube_vcard", "::", "import", "(", "$", "this", "->", "message", "->", "get_part_content", "(", "$", "part", ",", "null", ",", "true", ")", ")", ";", "// successfully parsed vcards?", "if", "(", "empty", "(", "$", "vcards", ")", ")", "{", "continue", ";", "}", "// remove part's body", "if", "(", "in_array", "(", "$", "part", ",", "$", "this", "->", "vcard_bodies", ")", ")", "{", "$", "p", "[", "'content'", "]", "=", "''", ";", "}", "foreach", "(", "$", "vcards", "as", "$", "idx", "=>", "$", "vcard", ")", "{", "// skip invalid vCards", "if", "(", "empty", "(", "$", "vcard", "->", "email", ")", "||", "empty", "(", "$", "vcard", "->", "email", "[", "0", "]", ")", ")", "{", "continue", ";", "}", "$", "display", "=", "$", "vcard", "->", "displayname", ".", "' <'", ".", "$", "vcard", "->", "email", "[", "0", "]", ".", "'>'", ";", "// add box below message body", "$", "p", "[", "'content'", "]", ".=", "html", "::", "p", "(", "array", "(", "'class'", "=>", "'vcardattachment'", ")", ",", "html", "::", "a", "(", "array", "(", "'href'", "=>", "\"#\"", ",", "'onclick'", "=>", "\"return plugin_vcard_save_contact('\"", ".", "rcube", "::", "JQ", "(", "$", "part", ".", "':'", ".", "$", "idx", ")", ".", "\"')\"", ",", "'title'", "=>", "$", "this", "->", "gettext", "(", "'addvcardmsg'", ")", ",", ")", ",", "html", "::", "span", "(", "null", ",", "rcube", "::", "Q", "(", "$", "display", ")", ")", ")", ")", ";", "}", "$", "attach_script", "=", "true", ";", "}", "if", "(", "$", "attach_script", ")", "{", "$", "this", "->", "include_script", "(", "'vcardattach.js'", ")", ";", "$", "this", "->", "include_stylesheet", "(", "$", "this", "->", "local_skin_path", "(", ")", ".", "'/style.css'", ")", ";", "}", "return", "$", "p", ";", "}" ]
This callback function adds a box below the message content if there is a vcard attachment available
[ "This", "callback", "function", "adds", "a", "box", "below", "the", "message", "content", "if", "there", "is", "a", "vcard", "attachment", "available" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/vcard_attachments/vcard_attachments.php#L87-L132
train
i-MSCP/roundcube
roundcubemail/plugins/vcard_attachments/vcard_attachments.php
vcard_attachments.save_vcard
function save_vcard() { $this->add_texts('localization', true); $uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST); $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST); $mime_id = rcube_utils::get_input_value('_part', rcube_utils::INPUT_POST); $rcmail = rcmail::get_instance(); $message = new rcube_message($uid, $mbox); if ($uid && $mime_id) { list($mime_id, $index) = explode(':', $mime_id); $part = $message->get_part_content($mime_id, null, true); } $error_msg = $this->gettext('vcardsavefailed'); if ($part && ($vcards = rcube_vcard::import($part)) && ($vcard = $vcards[$index]) && $vcard->displayname && $vcard->email ) { $CONTACTS = $this->get_address_book(); $email = $vcard->email[0]; $contact = $vcard->get_assoc(); $valid = true; // skip entries without an e-mail address or invalid if (empty($email) || !$CONTACTS->validate($contact, true)) { $valid = false; } else { // We're using UTF8 internally $email = rcube_utils::idn_to_utf8($email); // compare e-mail address $existing = $CONTACTS->search('email', $email, 1, false); // compare display name if (!$existing->count && $vcard->displayname) { $existing = $CONTACTS->search('name', $vcard->displayname, 1, false); } if ($existing->count) { $rcmail->output->command('display_message', $this->gettext('contactexists'), 'warning'); $valid = false; } } if ($valid) { $plugin = $rcmail->plugins->exec_hook('contact_create', array('record' => $contact, 'source' => null)); $contact = $plugin['record']; if (!$plugin['abort'] && $CONTACTS->insert($contact)) $rcmail->output->command('display_message', $this->gettext('addedsuccessfully'), 'confirmation'); else $rcmail->output->command('display_message', $error_msg, 'error'); } } else { $rcmail->output->command('display_message', $error_msg, 'error'); } $rcmail->output->send(); }
php
function save_vcard() { $this->add_texts('localization', true); $uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST); $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST); $mime_id = rcube_utils::get_input_value('_part', rcube_utils::INPUT_POST); $rcmail = rcmail::get_instance(); $message = new rcube_message($uid, $mbox); if ($uid && $mime_id) { list($mime_id, $index) = explode(':', $mime_id); $part = $message->get_part_content($mime_id, null, true); } $error_msg = $this->gettext('vcardsavefailed'); if ($part && ($vcards = rcube_vcard::import($part)) && ($vcard = $vcards[$index]) && $vcard->displayname && $vcard->email ) { $CONTACTS = $this->get_address_book(); $email = $vcard->email[0]; $contact = $vcard->get_assoc(); $valid = true; // skip entries without an e-mail address or invalid if (empty($email) || !$CONTACTS->validate($contact, true)) { $valid = false; } else { // We're using UTF8 internally $email = rcube_utils::idn_to_utf8($email); // compare e-mail address $existing = $CONTACTS->search('email', $email, 1, false); // compare display name if (!$existing->count && $vcard->displayname) { $existing = $CONTACTS->search('name', $vcard->displayname, 1, false); } if ($existing->count) { $rcmail->output->command('display_message', $this->gettext('contactexists'), 'warning'); $valid = false; } } if ($valid) { $plugin = $rcmail->plugins->exec_hook('contact_create', array('record' => $contact, 'source' => null)); $contact = $plugin['record']; if (!$plugin['abort'] && $CONTACTS->insert($contact)) $rcmail->output->command('display_message', $this->gettext('addedsuccessfully'), 'confirmation'); else $rcmail->output->command('display_message', $error_msg, 'error'); } } else { $rcmail->output->command('display_message', $error_msg, 'error'); } $rcmail->output->send(); }
[ "function", "save_vcard", "(", ")", "{", "$", "this", "->", "add_texts", "(", "'localization'", ",", "true", ")", ";", "$", "uid", "=", "rcube_utils", "::", "get_input_value", "(", "'_uid'", ",", "rcube_utils", "::", "INPUT_POST", ")", ";", "$", "mbox", "=", "rcube_utils", "::", "get_input_value", "(", "'_mbox'", ",", "rcube_utils", "::", "INPUT_POST", ")", ";", "$", "mime_id", "=", "rcube_utils", "::", "get_input_value", "(", "'_part'", ",", "rcube_utils", "::", "INPUT_POST", ")", ";", "$", "rcmail", "=", "rcmail", "::", "get_instance", "(", ")", ";", "$", "message", "=", "new", "rcube_message", "(", "$", "uid", ",", "$", "mbox", ")", ";", "if", "(", "$", "uid", "&&", "$", "mime_id", ")", "{", "list", "(", "$", "mime_id", ",", "$", "index", ")", "=", "explode", "(", "':'", ",", "$", "mime_id", ")", ";", "$", "part", "=", "$", "message", "->", "get_part_content", "(", "$", "mime_id", ",", "null", ",", "true", ")", ";", "}", "$", "error_msg", "=", "$", "this", "->", "gettext", "(", "'vcardsavefailed'", ")", ";", "if", "(", "$", "part", "&&", "(", "$", "vcards", "=", "rcube_vcard", "::", "import", "(", "$", "part", ")", ")", "&&", "(", "$", "vcard", "=", "$", "vcards", "[", "$", "index", "]", ")", "&&", "$", "vcard", "->", "displayname", "&&", "$", "vcard", "->", "email", ")", "{", "$", "CONTACTS", "=", "$", "this", "->", "get_address_book", "(", ")", ";", "$", "email", "=", "$", "vcard", "->", "email", "[", "0", "]", ";", "$", "contact", "=", "$", "vcard", "->", "get_assoc", "(", ")", ";", "$", "valid", "=", "true", ";", "// skip entries without an e-mail address or invalid", "if", "(", "empty", "(", "$", "email", ")", "||", "!", "$", "CONTACTS", "->", "validate", "(", "$", "contact", ",", "true", ")", ")", "{", "$", "valid", "=", "false", ";", "}", "else", "{", "// We're using UTF8 internally", "$", "email", "=", "rcube_utils", "::", "idn_to_utf8", "(", "$", "email", ")", ";", "// compare e-mail address", "$", "existing", "=", "$", "CONTACTS", "->", "search", "(", "'email'", ",", "$", "email", ",", "1", ",", "false", ")", ";", "// compare display name", "if", "(", "!", "$", "existing", "->", "count", "&&", "$", "vcard", "->", "displayname", ")", "{", "$", "existing", "=", "$", "CONTACTS", "->", "search", "(", "'name'", ",", "$", "vcard", "->", "displayname", ",", "1", ",", "false", ")", ";", "}", "if", "(", "$", "existing", "->", "count", ")", "{", "$", "rcmail", "->", "output", "->", "command", "(", "'display_message'", ",", "$", "this", "->", "gettext", "(", "'contactexists'", ")", ",", "'warning'", ")", ";", "$", "valid", "=", "false", ";", "}", "}", "if", "(", "$", "valid", ")", "{", "$", "plugin", "=", "$", "rcmail", "->", "plugins", "->", "exec_hook", "(", "'contact_create'", ",", "array", "(", "'record'", "=>", "$", "contact", ",", "'source'", "=>", "null", ")", ")", ";", "$", "contact", "=", "$", "plugin", "[", "'record'", "]", ";", "if", "(", "!", "$", "plugin", "[", "'abort'", "]", "&&", "$", "CONTACTS", "->", "insert", "(", "$", "contact", ")", ")", "$", "rcmail", "->", "output", "->", "command", "(", "'display_message'", ",", "$", "this", "->", "gettext", "(", "'addedsuccessfully'", ")", ",", "'confirmation'", ")", ";", "else", "$", "rcmail", "->", "output", "->", "command", "(", "'display_message'", ",", "$", "error_msg", ",", "'error'", ")", ";", "}", "}", "else", "{", "$", "rcmail", "->", "output", "->", "command", "(", "'display_message'", ",", "$", "error_msg", ",", "'error'", ")", ";", "}", "$", "rcmail", "->", "output", "->", "send", "(", ")", ";", "}" ]
Handler for request action
[ "Handler", "for", "request", "action" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/vcard_attachments/vcard_attachments.php#L137-L199
train
i-MSCP/roundcube
roundcubemail/plugins/vcard_attachments/vcard_attachments.php
vcard_attachments.is_vcard
function is_vcard($part) { return ( // Content-Type: text/vcard; $part->mimetype == 'text/vcard' || // Content-Type: text/x-vcard; $part->mimetype == 'text/x-vcard' || // Content-Type: text/directory; profile=vCard; ($part->mimetype == 'text/directory' && ( ($part->ctype_parameters['profile'] && strtolower($part->ctype_parameters['profile']) == 'vcard') // Content-Type: text/directory; (with filename=*.vcf) || ($part->filename && preg_match('/\.vcf$/i', $part->filename)) ) ) ); }
php
function is_vcard($part) { return ( // Content-Type: text/vcard; $part->mimetype == 'text/vcard' || // Content-Type: text/x-vcard; $part->mimetype == 'text/x-vcard' || // Content-Type: text/directory; profile=vCard; ($part->mimetype == 'text/directory' && ( ($part->ctype_parameters['profile'] && strtolower($part->ctype_parameters['profile']) == 'vcard') // Content-Type: text/directory; (with filename=*.vcf) || ($part->filename && preg_match('/\.vcf$/i', $part->filename)) ) ) ); }
[ "function", "is_vcard", "(", "$", "part", ")", "{", "return", "(", "// Content-Type: text/vcard;", "$", "part", "->", "mimetype", "==", "'text/vcard'", "||", "// Content-Type: text/x-vcard;", "$", "part", "->", "mimetype", "==", "'text/x-vcard'", "||", "// Content-Type: text/directory; profile=vCard;", "(", "$", "part", "->", "mimetype", "==", "'text/directory'", "&&", "(", "(", "$", "part", "->", "ctype_parameters", "[", "'profile'", "]", "&&", "strtolower", "(", "$", "part", "->", "ctype_parameters", "[", "'profile'", "]", ")", "==", "'vcard'", ")", "// Content-Type: text/directory; (with filename=*.vcf)", "||", "(", "$", "part", "->", "filename", "&&", "preg_match", "(", "'/\\.vcf$/i'", ",", "$", "part", "->", "filename", ")", ")", ")", ")", ")", ";", "}" ]
Checks if specified message part is a vcard data @param rcube_message_part Part object @return boolean True if part is of type vcard
[ "Checks", "if", "specified", "message", "part", "is", "a", "vcard", "data" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/vcard_attachments/vcard_attachments.php#L208-L224
train
i-MSCP/roundcube
roundcubemail/plugins/vcard_attachments/vcard_attachments.php
vcard_attachments.attach_vcard
public function attach_vcard($args) { if (preg_match('|^vcard://(.+)$|', $args['uri'], $m)) { list($cid, $source) = explode('-', $m[1]); $vcard = $this->get_contact_vcard($source, $cid, $filename); $params = array( 'filename' => $filename, 'mimetype' => 'text/vcard', ); if ($vcard) { $args['attachment'] = rcmail_save_attachment($vcard, null, $args['compose_id'], $params); } } return $args; }
php
public function attach_vcard($args) { if (preg_match('|^vcard://(.+)$|', $args['uri'], $m)) { list($cid, $source) = explode('-', $m[1]); $vcard = $this->get_contact_vcard($source, $cid, $filename); $params = array( 'filename' => $filename, 'mimetype' => 'text/vcard', ); if ($vcard) { $args['attachment'] = rcmail_save_attachment($vcard, null, $args['compose_id'], $params); } } return $args; }
[ "public", "function", "attach_vcard", "(", "$", "args", ")", "{", "if", "(", "preg_match", "(", "'|^vcard://(.+)$|'", ",", "$", "args", "[", "'uri'", "]", ",", "$", "m", ")", ")", "{", "list", "(", "$", "cid", ",", "$", "source", ")", "=", "explode", "(", "'-'", ",", "$", "m", "[", "1", "]", ")", ";", "$", "vcard", "=", "$", "this", "->", "get_contact_vcard", "(", "$", "source", ",", "$", "cid", ",", "$", "filename", ")", ";", "$", "params", "=", "array", "(", "'filename'", "=>", "$", "filename", ",", "'mimetype'", "=>", "'text/vcard'", ",", ")", ";", "if", "(", "$", "vcard", ")", "{", "$", "args", "[", "'attachment'", "]", "=", "rcmail_save_attachment", "(", "$", "vcard", ",", "null", ",", "$", "args", "[", "'compose_id'", "]", ",", "$", "params", ")", ";", "}", "}", "return", "$", "args", ";", "}" ]
Attaches a contact vcard to composed mail
[ "Attaches", "a", "contact", "vcard", "to", "composed", "mail" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/vcard_attachments/vcard_attachments.php#L254-L271
train
i-MSCP/roundcube
roundcubemail/plugins/vcard_attachments/vcard_attachments.php
vcard_attachments.get_contact_vcard
private function get_contact_vcard($source, $cid, &$filename = null) { $rcmail = rcmail::get_instance(); $source = $rcmail->get_address_book($source); $contact = $source->get_record($cid, true); if ($contact) { $fieldmap = $source ? $source->vcard_map : null; if (empty($contact['vcard'])) { $vcard = new rcube_vcard('', RCUBE_CHARSET, false, $fieldmap); $vcard->reset(); foreach ($contact as $key => $values) { list($field, $section) = explode(':', $key); // avoid unwanted casting of DateTime objects to an array // (same as in rcube_contacts::convert_save_data()) if (is_object($values) && is_a($values, 'DateTime')) { $values = array($values); } foreach ((array) $values as $value) { if (is_array($value) || is_a($value, 'DateTime') || @strlen($value)) { $vcard->set($field, $value, strtoupper($section)); } } } $contact['vcard'] = $vcard->export(); } $name = rcube_addressbook::compose_list_name($contact); $filename = (self::parse_filename($name) ?: 'contact') . '.vcf'; // fix folding and end-of-line chars $vcard = preg_replace('/\r|\n\s+/', '', $contact['vcard']); $vcard = preg_replace('/\n/', rcube_vcard::$eol, $vcard); return rcube_vcard::rfc2425_fold($vcard) . rcube_vcard::$eol; } }
php
private function get_contact_vcard($source, $cid, &$filename = null) { $rcmail = rcmail::get_instance(); $source = $rcmail->get_address_book($source); $contact = $source->get_record($cid, true); if ($contact) { $fieldmap = $source ? $source->vcard_map : null; if (empty($contact['vcard'])) { $vcard = new rcube_vcard('', RCUBE_CHARSET, false, $fieldmap); $vcard->reset(); foreach ($contact as $key => $values) { list($field, $section) = explode(':', $key); // avoid unwanted casting of DateTime objects to an array // (same as in rcube_contacts::convert_save_data()) if (is_object($values) && is_a($values, 'DateTime')) { $values = array($values); } foreach ((array) $values as $value) { if (is_array($value) || is_a($value, 'DateTime') || @strlen($value)) { $vcard->set($field, $value, strtoupper($section)); } } } $contact['vcard'] = $vcard->export(); } $name = rcube_addressbook::compose_list_name($contact); $filename = (self::parse_filename($name) ?: 'contact') . '.vcf'; // fix folding and end-of-line chars $vcard = preg_replace('/\r|\n\s+/', '', $contact['vcard']); $vcard = preg_replace('/\n/', rcube_vcard::$eol, $vcard); return rcube_vcard::rfc2425_fold($vcard) . rcube_vcard::$eol; } }
[ "private", "function", "get_contact_vcard", "(", "$", "source", ",", "$", "cid", ",", "&", "$", "filename", "=", "null", ")", "{", "$", "rcmail", "=", "rcmail", "::", "get_instance", "(", ")", ";", "$", "source", "=", "$", "rcmail", "->", "get_address_book", "(", "$", "source", ")", ";", "$", "contact", "=", "$", "source", "->", "get_record", "(", "$", "cid", ",", "true", ")", ";", "if", "(", "$", "contact", ")", "{", "$", "fieldmap", "=", "$", "source", "?", "$", "source", "->", "vcard_map", ":", "null", ";", "if", "(", "empty", "(", "$", "contact", "[", "'vcard'", "]", ")", ")", "{", "$", "vcard", "=", "new", "rcube_vcard", "(", "''", ",", "RCUBE_CHARSET", ",", "false", ",", "$", "fieldmap", ")", ";", "$", "vcard", "->", "reset", "(", ")", ";", "foreach", "(", "$", "contact", "as", "$", "key", "=>", "$", "values", ")", "{", "list", "(", "$", "field", ",", "$", "section", ")", "=", "explode", "(", "':'", ",", "$", "key", ")", ";", "// avoid unwanted casting of DateTime objects to an array", "// (same as in rcube_contacts::convert_save_data())", "if", "(", "is_object", "(", "$", "values", ")", "&&", "is_a", "(", "$", "values", ",", "'DateTime'", ")", ")", "{", "$", "values", "=", "array", "(", "$", "values", ")", ";", "}", "foreach", "(", "(", "array", ")", "$", "values", "as", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", "||", "is_a", "(", "$", "value", ",", "'DateTime'", ")", "||", "@", "strlen", "(", "$", "value", ")", ")", "{", "$", "vcard", "->", "set", "(", "$", "field", ",", "$", "value", ",", "strtoupper", "(", "$", "section", ")", ")", ";", "}", "}", "}", "$", "contact", "[", "'vcard'", "]", "=", "$", "vcard", "->", "export", "(", ")", ";", "}", "$", "name", "=", "rcube_addressbook", "::", "compose_list_name", "(", "$", "contact", ")", ";", "$", "filename", "=", "(", "self", "::", "parse_filename", "(", "$", "name", ")", "?", ":", "'contact'", ")", ".", "'.vcf'", ";", "// fix folding and end-of-line chars", "$", "vcard", "=", "preg_replace", "(", "'/\\r|\\n\\s+/'", ",", "''", ",", "$", "contact", "[", "'vcard'", "]", ")", ";", "$", "vcard", "=", "preg_replace", "(", "'/\\n/'", ",", "rcube_vcard", "::", "$", "eol", ",", "$", "vcard", ")", ";", "return", "rcube_vcard", "::", "rfc2425_fold", "(", "$", "vcard", ")", ".", "rcube_vcard", "::", "$", "eol", ";", "}", "}" ]
Get vcard data for specified contact
[ "Get", "vcard", "data", "for", "specified", "contact" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/vcard_attachments/vcard_attachments.php#L276-L316
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_tnef_decoder.php
rcube_tnef_decoder.decompress
public function decompress($data, $params = array()) { $out = array(); if ($this->_geti($data, 32) == self::SIGNATURE) { $this->_geti($data, 16); while (strlen($data) > 0) { switch ($this->_geti($data, 8)) { case self::LVL_MESSAGE: $this->_decodeMessage($data); break; case self::LVL_ATTACHMENT: $this->_decodeAttachment($data, $out); break; } } } return array_reverse($out); }
php
public function decompress($data, $params = array()) { $out = array(); if ($this->_geti($data, 32) == self::SIGNATURE) { $this->_geti($data, 16); while (strlen($data) > 0) { switch ($this->_geti($data, 8)) { case self::LVL_MESSAGE: $this->_decodeMessage($data); break; case self::LVL_ATTACHMENT: $this->_decodeAttachment($data, $out); break; } } } return array_reverse($out); }
[ "public", "function", "decompress", "(", "$", "data", ",", "$", "params", "=", "array", "(", ")", ")", "{", "$", "out", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "_geti", "(", "$", "data", ",", "32", ")", "==", "self", "::", "SIGNATURE", ")", "{", "$", "this", "->", "_geti", "(", "$", "data", ",", "16", ")", ";", "while", "(", "strlen", "(", "$", "data", ")", ">", "0", ")", "{", "switch", "(", "$", "this", "->", "_geti", "(", "$", "data", ",", "8", ")", ")", "{", "case", "self", "::", "LVL_MESSAGE", ":", "$", "this", "->", "_decodeMessage", "(", "$", "data", ")", ";", "break", ";", "case", "self", "::", "LVL_ATTACHMENT", ":", "$", "this", "->", "_decodeAttachment", "(", "$", "data", ",", "$", "out", ")", ";", "break", ";", "}", "}", "}", "return", "array_reverse", "(", "$", "out", ")", ";", "}" ]
Decompress the data. @param string $data The data to decompress. @param array $params An array of arguments needed to decompress the data. @return mixed The decompressed data.
[ "Decompress", "the", "data", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_tnef_decoder.php#L107-L128
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_tnef_decoder.php
rcube_tnef_decoder.convertString
protected function convertString($str, $use_codepage = false) { if ($convert && $this->codepage && ($charset = rcube_charset::$windows_codepages[$this->codepage]) ) { $str = rcube_charset::convert($str, $charset); } else if (strpos($str, "\0") !== false) { $str = rcube_charset::convert($str, 'UTF-16LE'); } $str = rtrim($str, "\0"); return $str; }
php
protected function convertString($str, $use_codepage = false) { if ($convert && $this->codepage && ($charset = rcube_charset::$windows_codepages[$this->codepage]) ) { $str = rcube_charset::convert($str, $charset); } else if (strpos($str, "\0") !== false) { $str = rcube_charset::convert($str, 'UTF-16LE'); } $str = rtrim($str, "\0"); return $str; }
[ "protected", "function", "convertString", "(", "$", "str", ",", "$", "use_codepage", "=", "false", ")", "{", "if", "(", "$", "convert", "&&", "$", "this", "->", "codepage", "&&", "(", "$", "charset", "=", "rcube_charset", "::", "$", "windows_codepages", "[", "$", "this", "->", "codepage", "]", ")", ")", "{", "$", "str", "=", "rcube_charset", "::", "convert", "(", "$", "str", ",", "$", "charset", ")", ";", "}", "else", "if", "(", "strpos", "(", "$", "str", ",", "\"\\0\"", ")", "!==", "false", ")", "{", "$", "str", "=", "rcube_charset", "::", "convert", "(", "$", "str", ",", "'UTF-16LE'", ")", ";", "}", "$", "str", "=", "rtrim", "(", "$", "str", ",", "\"\\0\"", ")", ";", "return", "$", "str", ";", "}" ]
Convert string value to system charset according to defined codepage
[ "Convert", "string", "value", "to", "system", "charset", "according", "to", "defined", "codepage" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_tnef_decoder.php#L388-L402
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.readLine
protected function readLine($size = 1024) { $line = ''; if (!$size) { $size = 1024; } do { if ($this->eof()) { return $line ?: null; } $buffer = fgets($this->fp, $size); if ($buffer === false) { $this->closeSocket(); break; } if ($this->debug) { $this->debug('S: '. rtrim($buffer)); } $line .= $buffer; } while (substr($buffer, -1) != "\n"); return $line; }
php
protected function readLine($size = 1024) { $line = ''; if (!$size) { $size = 1024; } do { if ($this->eof()) { return $line ?: null; } $buffer = fgets($this->fp, $size); if ($buffer === false) { $this->closeSocket(); break; } if ($this->debug) { $this->debug('S: '. rtrim($buffer)); } $line .= $buffer; } while (substr($buffer, -1) != "\n"); return $line; }
[ "protected", "function", "readLine", "(", "$", "size", "=", "1024", ")", "{", "$", "line", "=", "''", ";", "if", "(", "!", "$", "size", ")", "{", "$", "size", "=", "1024", ";", "}", "do", "{", "if", "(", "$", "this", "->", "eof", "(", ")", ")", "{", "return", "$", "line", "?", ":", "null", ";", "}", "$", "buffer", "=", "fgets", "(", "$", "this", "->", "fp", ",", "$", "size", ")", ";", "if", "(", "$", "buffer", "===", "false", ")", "{", "$", "this", "->", "closeSocket", "(", ")", ";", "break", ";", "}", "if", "(", "$", "this", "->", "debug", ")", "{", "$", "this", "->", "debug", "(", "'S: '", ".", "rtrim", "(", "$", "buffer", ")", ")", ";", "}", "$", "line", ".=", "$", "buffer", ";", "}", "while", "(", "substr", "(", "$", "buffer", ",", "-", "1", ")", "!=", "\"\\n\"", ")", ";", "return", "$", "line", ";", "}" ]
Reads line from the connection stream @param int $size Buffer size @return string Line of text response
[ "Reads", "line", "from", "the", "connection", "stream" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L191-L220
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.multLine
protected function multLine($line, $escape = false) { $line = rtrim($line); if (preg_match('/\{([0-9]+)\}$/', $line, $m)) { $out = ''; $str = substr($line, 0, -strlen($m[0])); $bytes = $m[1]; while (strlen($out) < $bytes) { $line = $this->readBytes($bytes); if ($line === null) { break; } $out .= $line; } $line = $str . ($escape ? $this->escape($out) : $out); } return $line; }
php
protected function multLine($line, $escape = false) { $line = rtrim($line); if (preg_match('/\{([0-9]+)\}$/', $line, $m)) { $out = ''; $str = substr($line, 0, -strlen($m[0])); $bytes = $m[1]; while (strlen($out) < $bytes) { $line = $this->readBytes($bytes); if ($line === null) { break; } $out .= $line; } $line = $str . ($escape ? $this->escape($out) : $out); } return $line; }
[ "protected", "function", "multLine", "(", "$", "line", ",", "$", "escape", "=", "false", ")", "{", "$", "line", "=", "rtrim", "(", "$", "line", ")", ";", "if", "(", "preg_match", "(", "'/\\{([0-9]+)\\}$/'", ",", "$", "line", ",", "$", "m", ")", ")", "{", "$", "out", "=", "''", ";", "$", "str", "=", "substr", "(", "$", "line", ",", "0", ",", "-", "strlen", "(", "$", "m", "[", "0", "]", ")", ")", ";", "$", "bytes", "=", "$", "m", "[", "1", "]", ";", "while", "(", "strlen", "(", "$", "out", ")", "<", "$", "bytes", ")", "{", "$", "line", "=", "$", "this", "->", "readBytes", "(", "$", "bytes", ")", ";", "if", "(", "$", "line", "===", "null", ")", "{", "break", ";", "}", "$", "out", ".=", "$", "line", ";", "}", "$", "line", "=", "$", "str", ".", "(", "$", "escape", "?", "$", "this", "->", "escape", "(", "$", "out", ")", ":", "$", "out", ")", ";", "}", "return", "$", "line", ";", "}" ]
Reads more data from the connection stream when provided data contain string literal @param string $line Response text @param bool $escape Enables escaping @return string Line of text response
[ "Reads", "more", "data", "from", "the", "connection", "stream", "when", "provided", "data", "contain", "string", "literal" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L231-L252
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.readBytes
protected function readBytes($bytes) { $data = ''; $len = 0; while ($len < $bytes && !$this->eof()) { $d = fread($this->fp, $bytes-$len); if ($this->debug) { $this->debug('S: '. $d); } $data .= $d; $data_len = strlen($data); if ($len == $data_len) { break; // nothing was read -> exit to avoid apache lockups } $len = $data_len; } return $data; }
php
protected function readBytes($bytes) { $data = ''; $len = 0; while ($len < $bytes && !$this->eof()) { $d = fread($this->fp, $bytes-$len); if ($this->debug) { $this->debug('S: '. $d); } $data .= $d; $data_len = strlen($data); if ($len == $data_len) { break; // nothing was read -> exit to avoid apache lockups } $len = $data_len; } return $data; }
[ "protected", "function", "readBytes", "(", "$", "bytes", ")", "{", "$", "data", "=", "''", ";", "$", "len", "=", "0", ";", "while", "(", "$", "len", "<", "$", "bytes", "&&", "!", "$", "this", "->", "eof", "(", ")", ")", "{", "$", "d", "=", "fread", "(", "$", "this", "->", "fp", ",", "$", "bytes", "-", "$", "len", ")", ";", "if", "(", "$", "this", "->", "debug", ")", "{", "$", "this", "->", "debug", "(", "'S: '", ".", "$", "d", ")", ";", "}", "$", "data", ".=", "$", "d", ";", "$", "data_len", "=", "strlen", "(", "$", "data", ")", ";", "if", "(", "$", "len", "==", "$", "data_len", ")", "{", "break", ";", "// nothing was read -> exit to avoid apache lockups", "}", "$", "len", "=", "$", "data_len", ";", "}", "return", "$", "data", ";", "}" ]
Reads specified number of bytes from the connection stream @param int $bytes Number of bytes to get @return string Response text
[ "Reads", "specified", "number", "of", "bytes", "from", "the", "connection", "stream" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L261-L280
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.readReply
protected function readReply(&$untagged = null) { do { $line = trim($this->readLine(1024)); // store untagged response lines if ($line[0] == '*') { $untagged[] = $line; } } while ($line[0] == '*'); if ($untagged) { $untagged = join("\n", $untagged); } return $line; }
php
protected function readReply(&$untagged = null) { do { $line = trim($this->readLine(1024)); // store untagged response lines if ($line[0] == '*') { $untagged[] = $line; } } while ($line[0] == '*'); if ($untagged) { $untagged = join("\n", $untagged); } return $line; }
[ "protected", "function", "readReply", "(", "&", "$", "untagged", "=", "null", ")", "{", "do", "{", "$", "line", "=", "trim", "(", "$", "this", "->", "readLine", "(", "1024", ")", ")", ";", "// store untagged response lines", "if", "(", "$", "line", "[", "0", "]", "==", "'*'", ")", "{", "$", "untagged", "[", "]", "=", "$", "line", ";", "}", "}", "while", "(", "$", "line", "[", "0", "]", "==", "'*'", ")", ";", "if", "(", "$", "untagged", ")", "{", "$", "untagged", "=", "join", "(", "\"\\n\"", ",", "$", "untagged", ")", ";", "}", "return", "$", "line", ";", "}" ]
Reads complete response to the IMAP command @param array $untagged Will be filled with untagged response lines @return string Response text
[ "Reads", "complete", "response", "to", "the", "IMAP", "command" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L289-L305
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.parseResult
protected function parseResult($string, $err_prefix = '') { if (preg_match('/^[a-z0-9*]+ (OK|NO|BAD|BYE)(.*)$/i', trim($string), $matches)) { $res = strtoupper($matches[1]); $str = trim($matches[2]); if ($res == 'OK') { $this->errornum = self::ERROR_OK; } else if ($res == 'NO') { $this->errornum = self::ERROR_NO; } else if ($res == 'BAD') { $this->errornum = self::ERROR_BAD; } else if ($res == 'BYE') { $this->closeSocket(); $this->errornum = self::ERROR_BYE; } if ($str) { $str = trim($str); // get response string and code (RFC5530) if (preg_match("/^\[([a-z-]+)\]/i", $str, $m)) { $this->resultcode = strtoupper($m[1]); $str = trim(substr($str, strlen($m[1]) + 2)); } else { $this->resultcode = null; // parse response for [APPENDUID 1204196876 3456] if (preg_match("/^\[APPENDUID [0-9]+ ([0-9]+)\]/i", $str, $m)) { $this->data['APPENDUID'] = $m[1]; } // parse response for [COPYUID 1204196876 3456:3457 123:124] else if (preg_match("/^\[COPYUID [0-9]+ ([0-9,:]+) ([0-9,:]+)\]/i", $str, $m)) { $this->data['COPYUID'] = array($m[1], $m[2]); } } $this->result = $str; if ($this->errornum != self::ERROR_OK) { $this->error = $err_prefix ? $err_prefix.$str : $str; } } return $this->errornum; } return self::ERROR_UNKNOWN; }
php
protected function parseResult($string, $err_prefix = '') { if (preg_match('/^[a-z0-9*]+ (OK|NO|BAD|BYE)(.*)$/i', trim($string), $matches)) { $res = strtoupper($matches[1]); $str = trim($matches[2]); if ($res == 'OK') { $this->errornum = self::ERROR_OK; } else if ($res == 'NO') { $this->errornum = self::ERROR_NO; } else if ($res == 'BAD') { $this->errornum = self::ERROR_BAD; } else if ($res == 'BYE') { $this->closeSocket(); $this->errornum = self::ERROR_BYE; } if ($str) { $str = trim($str); // get response string and code (RFC5530) if (preg_match("/^\[([a-z-]+)\]/i", $str, $m)) { $this->resultcode = strtoupper($m[1]); $str = trim(substr($str, strlen($m[1]) + 2)); } else { $this->resultcode = null; // parse response for [APPENDUID 1204196876 3456] if (preg_match("/^\[APPENDUID [0-9]+ ([0-9]+)\]/i", $str, $m)) { $this->data['APPENDUID'] = $m[1]; } // parse response for [COPYUID 1204196876 3456:3457 123:124] else if (preg_match("/^\[COPYUID [0-9]+ ([0-9,:]+) ([0-9,:]+)\]/i", $str, $m)) { $this->data['COPYUID'] = array($m[1], $m[2]); } } $this->result = $str; if ($this->errornum != self::ERROR_OK) { $this->error = $err_prefix ? $err_prefix.$str : $str; } } return $this->errornum; } return self::ERROR_UNKNOWN; }
[ "protected", "function", "parseResult", "(", "$", "string", ",", "$", "err_prefix", "=", "''", ")", "{", "if", "(", "preg_match", "(", "'/^[a-z0-9*]+ (OK|NO|BAD|BYE)(.*)$/i'", ",", "trim", "(", "$", "string", ")", ",", "$", "matches", ")", ")", "{", "$", "res", "=", "strtoupper", "(", "$", "matches", "[", "1", "]", ")", ";", "$", "str", "=", "trim", "(", "$", "matches", "[", "2", "]", ")", ";", "if", "(", "$", "res", "==", "'OK'", ")", "{", "$", "this", "->", "errornum", "=", "self", "::", "ERROR_OK", ";", "}", "else", "if", "(", "$", "res", "==", "'NO'", ")", "{", "$", "this", "->", "errornum", "=", "self", "::", "ERROR_NO", ";", "}", "else", "if", "(", "$", "res", "==", "'BAD'", ")", "{", "$", "this", "->", "errornum", "=", "self", "::", "ERROR_BAD", ";", "}", "else", "if", "(", "$", "res", "==", "'BYE'", ")", "{", "$", "this", "->", "closeSocket", "(", ")", ";", "$", "this", "->", "errornum", "=", "self", "::", "ERROR_BYE", ";", "}", "if", "(", "$", "str", ")", "{", "$", "str", "=", "trim", "(", "$", "str", ")", ";", "// get response string and code (RFC5530)", "if", "(", "preg_match", "(", "\"/^\\[([a-z-]+)\\]/i\"", ",", "$", "str", ",", "$", "m", ")", ")", "{", "$", "this", "->", "resultcode", "=", "strtoupper", "(", "$", "m", "[", "1", "]", ")", ";", "$", "str", "=", "trim", "(", "substr", "(", "$", "str", ",", "strlen", "(", "$", "m", "[", "1", "]", ")", "+", "2", ")", ")", ";", "}", "else", "{", "$", "this", "->", "resultcode", "=", "null", ";", "// parse response for [APPENDUID 1204196876 3456]", "if", "(", "preg_match", "(", "\"/^\\[APPENDUID [0-9]+ ([0-9]+)\\]/i\"", ",", "$", "str", ",", "$", "m", ")", ")", "{", "$", "this", "->", "data", "[", "'APPENDUID'", "]", "=", "$", "m", "[", "1", "]", ";", "}", "// parse response for [COPYUID 1204196876 3456:3457 123:124]", "else", "if", "(", "preg_match", "(", "\"/^\\[COPYUID [0-9]+ ([0-9,:]+) ([0-9,:]+)\\]/i\"", ",", "$", "str", ",", "$", "m", ")", ")", "{", "$", "this", "->", "data", "[", "'COPYUID'", "]", "=", "array", "(", "$", "m", "[", "1", "]", ",", "$", "m", "[", "2", "]", ")", ";", "}", "}", "$", "this", "->", "result", "=", "$", "str", ";", "if", "(", "$", "this", "->", "errornum", "!=", "self", "::", "ERROR_OK", ")", "{", "$", "this", "->", "error", "=", "$", "err_prefix", "?", "$", "err_prefix", ".", "$", "str", ":", "$", "str", ";", "}", "}", "return", "$", "this", "->", "errornum", ";", "}", "return", "self", "::", "ERROR_UNKNOWN", ";", "}" ]
Response parser. @param string $string Response text @param string $err_prefix Error message prefix @return int Response status
[ "Response", "parser", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L315-L365
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.eof
protected function eof() { if (!is_resource($this->fp)) { return true; } // If a connection opened by fsockopen() wasn't closed // by the server, feof() will hang. $start = microtime(true); if (feof($this->fp) || ($this->prefs['timeout'] && (microtime(true) - $start > $this->prefs['timeout'])) ) { $this->closeSocket(); return true; } return false; }
php
protected function eof() { if (!is_resource($this->fp)) { return true; } // If a connection opened by fsockopen() wasn't closed // by the server, feof() will hang. $start = microtime(true); if (feof($this->fp) || ($this->prefs['timeout'] && (microtime(true) - $start > $this->prefs['timeout'])) ) { $this->closeSocket(); return true; } return false; }
[ "protected", "function", "eof", "(", ")", "{", "if", "(", "!", "is_resource", "(", "$", "this", "->", "fp", ")", ")", "{", "return", "true", ";", "}", "// If a connection opened by fsockopen() wasn't closed", "// by the server, feof() will hang.", "$", "start", "=", "microtime", "(", "true", ")", ";", "if", "(", "feof", "(", "$", "this", "->", "fp", ")", "||", "(", "$", "this", "->", "prefs", "[", "'timeout'", "]", "&&", "(", "microtime", "(", "true", ")", "-", "$", "start", ">", "$", "this", "->", "prefs", "[", "'timeout'", "]", ")", ")", ")", "{", "$", "this", "->", "closeSocket", "(", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Checks connection stream state. @return bool True if connection is closed
[ "Checks", "connection", "stream", "state", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L372-L390
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.getHierarchyDelimiter
public function getHierarchyDelimiter() { if ($this->prefs['delimiter']) { return $this->prefs['delimiter']; } // try (LIST "" ""), should return delimiter (RFC2060 Sec 6.3.8) list($code, $response) = $this->execute('LIST', array($this->escape(''), $this->escape(''))); if ($code == self::ERROR_OK) { $args = $this->tokenizeResponse($response, 4); $delimiter = $args[3]; if (strlen($delimiter) > 0) { return ($this->prefs['delimiter'] = $delimiter); } } }
php
public function getHierarchyDelimiter() { if ($this->prefs['delimiter']) { return $this->prefs['delimiter']; } // try (LIST "" ""), should return delimiter (RFC2060 Sec 6.3.8) list($code, $response) = $this->execute('LIST', array($this->escape(''), $this->escape(''))); if ($code == self::ERROR_OK) { $args = $this->tokenizeResponse($response, 4); $delimiter = $args[3]; if (strlen($delimiter) > 0) { return ($this->prefs['delimiter'] = $delimiter); } } }
[ "public", "function", "getHierarchyDelimiter", "(", ")", "{", "if", "(", "$", "this", "->", "prefs", "[", "'delimiter'", "]", ")", "{", "return", "$", "this", "->", "prefs", "[", "'delimiter'", "]", ";", "}", "// try (LIST \"\" \"\"), should return delimiter (RFC2060 Sec 6.3.8)", "list", "(", "$", "code", ",", "$", "response", ")", "=", "$", "this", "->", "execute", "(", "'LIST'", ",", "array", "(", "$", "this", "->", "escape", "(", "''", ")", ",", "$", "this", "->", "escape", "(", "''", ")", ")", ")", ";", "if", "(", "$", "code", "==", "self", "::", "ERROR_OK", ")", "{", "$", "args", "=", "$", "this", "->", "tokenizeResponse", "(", "$", "response", ",", "4", ")", ";", "$", "delimiter", "=", "$", "args", "[", "3", "]", ";", "if", "(", "strlen", "(", "$", "delimiter", ")", ">", "0", ")", "{", "return", "(", "$", "this", "->", "prefs", "[", "'delimiter'", "]", "=", "$", "delimiter", ")", ";", "}", "}", "}" ]
Detects hierarchy delimiter @return string The delimiter
[ "Detects", "hierarchy", "delimiter" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L747-L765
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.closeConnection
public function closeConnection() { if ($this->logged && $this->putLine($this->nextTag() . ' LOGOUT')) { $this->readReply(); } $this->closeSocket(); }
php
public function closeConnection() { if ($this->logged && $this->putLine($this->nextTag() . ' LOGOUT')) { $this->readReply(); } $this->closeSocket(); }
[ "public", "function", "closeConnection", "(", ")", "{", "if", "(", "$", "this", "->", "logged", "&&", "$", "this", "->", "putLine", "(", "$", "this", "->", "nextTag", "(", ")", ".", "' LOGOUT'", ")", ")", "{", "$", "this", "->", "readReply", "(", ")", ";", "}", "$", "this", "->", "closeSocket", "(", ")", ";", "}" ]
Closes connection with logout.
[ "Closes", "connection", "with", "logout", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L1083-L1090
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.status
public function status($mailbox, $items = array()) { if (!strlen($mailbox)) { return false; } if (!in_array('MESSAGES', $items)) { $items[] = 'MESSAGES'; } if (!in_array('UNSEEN', $items)) { $items[] = 'UNSEEN'; } list($code, $response) = $this->execute('STATUS', array($this->escape($mailbox), '(' . implode(' ', $items) . ')'), 0, '/^\* STATUS /i'); if ($code == self::ERROR_OK && $response) { $result = array(); $response = substr($response, 9); // remove prefix "* STATUS " list($mbox, $items) = $this->tokenizeResponse($response, 2); // Fix for #1487859. Some buggy server returns not quoted // folder name with spaces. Let's try to handle this situation if (!is_array($items) && ($pos = strpos($response, '(')) !== false) { $response = substr($response, $pos); $items = $this->tokenizeResponse($response, 1); } if (!is_array($items)) { return $result; } for ($i=0, $len=count($items); $i<$len; $i += 2) { $result[$items[$i]] = $items[$i+1]; } $this->data['STATUS:'.$mailbox] = $result; return $result; } return false; }
php
public function status($mailbox, $items = array()) { if (!strlen($mailbox)) { return false; } if (!in_array('MESSAGES', $items)) { $items[] = 'MESSAGES'; } if (!in_array('UNSEEN', $items)) { $items[] = 'UNSEEN'; } list($code, $response) = $this->execute('STATUS', array($this->escape($mailbox), '(' . implode(' ', $items) . ')'), 0, '/^\* STATUS /i'); if ($code == self::ERROR_OK && $response) { $result = array(); $response = substr($response, 9); // remove prefix "* STATUS " list($mbox, $items) = $this->tokenizeResponse($response, 2); // Fix for #1487859. Some buggy server returns not quoted // folder name with spaces. Let's try to handle this situation if (!is_array($items) && ($pos = strpos($response, '(')) !== false) { $response = substr($response, $pos); $items = $this->tokenizeResponse($response, 1); } if (!is_array($items)) { return $result; } for ($i=0, $len=count($items); $i<$len; $i += 2) { $result[$items[$i]] = $items[$i+1]; } $this->data['STATUS:'.$mailbox] = $result; return $result; } return false; }
[ "public", "function", "status", "(", "$", "mailbox", ",", "$", "items", "=", "array", "(", ")", ")", "{", "if", "(", "!", "strlen", "(", "$", "mailbox", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "in_array", "(", "'MESSAGES'", ",", "$", "items", ")", ")", "{", "$", "items", "[", "]", "=", "'MESSAGES'", ";", "}", "if", "(", "!", "in_array", "(", "'UNSEEN'", ",", "$", "items", ")", ")", "{", "$", "items", "[", "]", "=", "'UNSEEN'", ";", "}", "list", "(", "$", "code", ",", "$", "response", ")", "=", "$", "this", "->", "execute", "(", "'STATUS'", ",", "array", "(", "$", "this", "->", "escape", "(", "$", "mailbox", ")", ",", "'('", ".", "implode", "(", "' '", ",", "$", "items", ")", ".", "')'", ")", ",", "0", ",", "'/^\\* STATUS /i'", ")", ";", "if", "(", "$", "code", "==", "self", "::", "ERROR_OK", "&&", "$", "response", ")", "{", "$", "result", "=", "array", "(", ")", ";", "$", "response", "=", "substr", "(", "$", "response", ",", "9", ")", ";", "// remove prefix \"* STATUS \"", "list", "(", "$", "mbox", ",", "$", "items", ")", "=", "$", "this", "->", "tokenizeResponse", "(", "$", "response", ",", "2", ")", ";", "// Fix for #1487859. Some buggy server returns not quoted", "// folder name with spaces. Let's try to handle this situation", "if", "(", "!", "is_array", "(", "$", "items", ")", "&&", "(", "$", "pos", "=", "strpos", "(", "$", "response", ",", "'('", ")", ")", "!==", "false", ")", "{", "$", "response", "=", "substr", "(", "$", "response", ",", "$", "pos", ")", ";", "$", "items", "=", "$", "this", "->", "tokenizeResponse", "(", "$", "response", ",", "1", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "items", ")", ")", "{", "return", "$", "result", ";", "}", "for", "(", "$", "i", "=", "0", ",", "$", "len", "=", "count", "(", "$", "items", ")", ";", "$", "i", "<", "$", "len", ";", "$", "i", "+=", "2", ")", "{", "$", "result", "[", "$", "items", "[", "$", "i", "]", "]", "=", "$", "items", "[", "$", "i", "+", "1", "]", ";", "}", "$", "this", "->", "data", "[", "'STATUS:'", ".", "$", "mailbox", "]", "=", "$", "result", ";", "return", "$", "result", ";", "}", "return", "false", ";", "}" ]
Executes STATUS command @param string $mailbox Mailbox name @param array $items Additional requested item names. By default MESSAGES and UNSEEN are requested. Other defined in RFC3501: UIDNEXT, UIDVALIDITY, RECENT @return array Status item-value hash @since 0.5-beta
[ "Executes", "STATUS", "command" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L1227-L1270
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.expunge
public function expunge($mailbox, $messages = null) { if (!$this->select($mailbox)) { return false; } if (!$this->data['READ-WRITE']) { $this->setError(self::ERROR_READONLY, "Mailbox is read-only"); return false; } // Clear internal status cache $this->clear_status_cache($mailbox); if (!empty($messages) && $messages != '*' && $this->hasCapability('UIDPLUS')) { $messages = self::compressMessageSet($messages); $result = $this->execute('UID EXPUNGE', array($messages), self::COMMAND_NORESPONSE); } else { $result = $this->execute('EXPUNGE', null, self::COMMAND_NORESPONSE); } if ($result == self::ERROR_OK) { $this->selected = null; // state has changed, need to reselect return true; } return false; }
php
public function expunge($mailbox, $messages = null) { if (!$this->select($mailbox)) { return false; } if (!$this->data['READ-WRITE']) { $this->setError(self::ERROR_READONLY, "Mailbox is read-only"); return false; } // Clear internal status cache $this->clear_status_cache($mailbox); if (!empty($messages) && $messages != '*' && $this->hasCapability('UIDPLUS')) { $messages = self::compressMessageSet($messages); $result = $this->execute('UID EXPUNGE', array($messages), self::COMMAND_NORESPONSE); } else { $result = $this->execute('EXPUNGE', null, self::COMMAND_NORESPONSE); } if ($result == self::ERROR_OK) { $this->selected = null; // state has changed, need to reselect return true; } return false; }
[ "public", "function", "expunge", "(", "$", "mailbox", ",", "$", "messages", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "select", "(", "$", "mailbox", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "this", "->", "data", "[", "'READ-WRITE'", "]", ")", "{", "$", "this", "->", "setError", "(", "self", "::", "ERROR_READONLY", ",", "\"Mailbox is read-only\"", ")", ";", "return", "false", ";", "}", "// Clear internal status cache", "$", "this", "->", "clear_status_cache", "(", "$", "mailbox", ")", ";", "if", "(", "!", "empty", "(", "$", "messages", ")", "&&", "$", "messages", "!=", "'*'", "&&", "$", "this", "->", "hasCapability", "(", "'UIDPLUS'", ")", ")", "{", "$", "messages", "=", "self", "::", "compressMessageSet", "(", "$", "messages", ")", ";", "$", "result", "=", "$", "this", "->", "execute", "(", "'UID EXPUNGE'", ",", "array", "(", "$", "messages", ")", ",", "self", "::", "COMMAND_NORESPONSE", ")", ";", "}", "else", "{", "$", "result", "=", "$", "this", "->", "execute", "(", "'EXPUNGE'", ",", "null", ",", "self", "::", "COMMAND_NORESPONSE", ")", ";", "}", "if", "(", "$", "result", "==", "self", "::", "ERROR_OK", ")", "{", "$", "this", "->", "selected", "=", "null", ";", "// state has changed, need to reselect", "return", "true", ";", "}", "return", "false", ";", "}" ]
Executes EXPUNGE command @param string $mailbox Mailbox name @param string|array $messages Message UIDs to expunge @return boolean True on success, False on error
[ "Executes", "EXPUNGE", "command" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L1280-L1308
train