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_imap_generic.php
rcube_imap_generic.close
public function close() { $result = $this->execute('CLOSE', null, self::COMMAND_NORESPONSE); if ($result == self::ERROR_OK) { $this->selected = null; return true; } return false; }
php
public function close() { $result = $this->execute('CLOSE', null, self::COMMAND_NORESPONSE); if ($result == self::ERROR_OK) { $this->selected = null; return true; } return false; }
[ "public", "function", "close", "(", ")", "{", "$", "result", "=", "$", "this", "->", "execute", "(", "'CLOSE'", ",", "null", ",", "self", "::", "COMMAND_NORESPONSE", ")", ";", "if", "(", "$", "result", "==", "self", "::", "ERROR_OK", ")", "{", "$", "this", "->", "selected", "=", "null", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Executes CLOSE command @return boolean True on success, False on error @since 0.5
[ "Executes", "CLOSE", "command" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L1316-L1326
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.deleteFolder
public function deleteFolder($mailbox) { $result = $this->execute('DELETE', array($this->escape($mailbox)), self::COMMAND_NORESPONSE); return $result == self::ERROR_OK; }
php
public function deleteFolder($mailbox) { $result = $this->execute('DELETE', array($this->escape($mailbox)), self::COMMAND_NORESPONSE); return $result == self::ERROR_OK; }
[ "public", "function", "deleteFolder", "(", "$", "mailbox", ")", "{", "$", "result", "=", "$", "this", "->", "execute", "(", "'DELETE'", ",", "array", "(", "$", "this", "->", "escape", "(", "$", "mailbox", ")", ")", ",", "self", "::", "COMMAND_NORESPONSE", ")", ";", "return", "$", "result", "==", "self", "::", "ERROR_OK", ";", "}" ]
Executes DELETE command @param string $mailbox Mailbox name @return boolean True on success, False on error
[ "Executes", "DELETE", "command" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L1402-L1408
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.clearFolder
public function clearFolder($mailbox) { if ($this->countMessages($mailbox) > 0) { $res = $this->flag($mailbox, '1:*', 'DELETED'); } if ($res) { if ($this->selected === $mailbox) { $res = $this->close(); } else { $res = $this->expunge($mailbox); } } return $res; }
php
public function clearFolder($mailbox) { if ($this->countMessages($mailbox) > 0) { $res = $this->flag($mailbox, '1:*', 'DELETED'); } if ($res) { if ($this->selected === $mailbox) { $res = $this->close(); } else { $res = $this->expunge($mailbox); } } return $res; }
[ "public", "function", "clearFolder", "(", "$", "mailbox", ")", "{", "if", "(", "$", "this", "->", "countMessages", "(", "$", "mailbox", ")", ">", "0", ")", "{", "$", "res", "=", "$", "this", "->", "flag", "(", "$", "mailbox", ",", "'1:*'", ",", "'DELETED'", ")", ";", "}", "if", "(", "$", "res", ")", "{", "if", "(", "$", "this", "->", "selected", "===", "$", "mailbox", ")", "{", "$", "res", "=", "$", "this", "->", "close", "(", ")", ";", "}", "else", "{", "$", "res", "=", "$", "this", "->", "expunge", "(", "$", "mailbox", ")", ";", "}", "}", "return", "$", "res", ";", "}" ]
Removes all messages in a folder @param string $mailbox Mailbox name @return boolean True on success, False on error
[ "Removes", "all", "messages", "in", "a", "folder" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L1417-L1433
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.listMailboxes
public function listMailboxes($ref, $mailbox, $return_opts = array(), $select_opts = array()) { return $this->_listMailboxes($ref, $mailbox, false, $return_opts, $select_opts); }
php
public function listMailboxes($ref, $mailbox, $return_opts = array(), $select_opts = array()) { return $this->_listMailboxes($ref, $mailbox, false, $return_opts, $select_opts); }
[ "public", "function", "listMailboxes", "(", "$", "ref", ",", "$", "mailbox", ",", "$", "return_opts", "=", "array", "(", ")", ",", "$", "select_opts", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "_listMailboxes", "(", "$", "ref", ",", "$", "mailbox", ",", "false", ",", "$", "return_opts", ",", "$", "select_opts", ")", ";", "}" ]
Returns list of mailboxes @param string $ref Reference name @param string $mailbox Mailbox name @param array $return_opts (see self::_listMailboxes) @param array $select_opts (see self::_listMailboxes) @return array|bool List of mailboxes or hash of options if STATUS/MYROGHTS response is requested, False on error.
[ "Returns", "list", "of", "mailboxes" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L1446-L1449
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.listSubscribed
public function listSubscribed($ref, $mailbox, $return_opts = array()) { return $this->_listMailboxes($ref, $mailbox, true, $return_opts, null); }
php
public function listSubscribed($ref, $mailbox, $return_opts = array()) { return $this->_listMailboxes($ref, $mailbox, true, $return_opts, null); }
[ "public", "function", "listSubscribed", "(", "$", "ref", ",", "$", "mailbox", ",", "$", "return_opts", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "_listMailboxes", "(", "$", "ref", ",", "$", "mailbox", ",", "true", ",", "$", "return_opts", ",", "null", ")", ";", "}" ]
Returns list of subscribed mailboxes @param string $ref Reference name @param string $mailbox Mailbox name @param array $return_opts (see self::_listMailboxes) @return array|bool List of mailboxes or hash of options if STATUS/MYROGHTS response is requested, False on error.
[ "Returns", "list", "of", "subscribed", "mailboxes" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L1461-L1464
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.countMessages
public function countMessages($mailbox) { if ($this->selected === $mailbox && isset($this->data['EXISTS'])) { return $this->data['EXISTS']; } // Check internal cache $cache = $this->data['STATUS:'.$mailbox]; if (!empty($cache) && isset($cache['MESSAGES'])) { return (int) $cache['MESSAGES']; } // Try STATUS (should be faster than SELECT) $counts = $this->status($mailbox); if (is_array($counts)) { return (int) $counts['MESSAGES']; } return false; }
php
public function countMessages($mailbox) { if ($this->selected === $mailbox && isset($this->data['EXISTS'])) { return $this->data['EXISTS']; } // Check internal cache $cache = $this->data['STATUS:'.$mailbox]; if (!empty($cache) && isset($cache['MESSAGES'])) { return (int) $cache['MESSAGES']; } // Try STATUS (should be faster than SELECT) $counts = $this->status($mailbox); if (is_array($counts)) { return (int) $counts['MESSAGES']; } return false; }
[ "public", "function", "countMessages", "(", "$", "mailbox", ")", "{", "if", "(", "$", "this", "->", "selected", "===", "$", "mailbox", "&&", "isset", "(", "$", "this", "->", "data", "[", "'EXISTS'", "]", ")", ")", "{", "return", "$", "this", "->", "data", "[", "'EXISTS'", "]", ";", "}", "// Check internal cache", "$", "cache", "=", "$", "this", "->", "data", "[", "'STATUS:'", ".", "$", "mailbox", "]", ";", "if", "(", "!", "empty", "(", "$", "cache", ")", "&&", "isset", "(", "$", "cache", "[", "'MESSAGES'", "]", ")", ")", "{", "return", "(", "int", ")", "$", "cache", "[", "'MESSAGES'", "]", ";", "}", "// Try STATUS (should be faster than SELECT)", "$", "counts", "=", "$", "this", "->", "status", "(", "$", "mailbox", ")", ";", "if", "(", "is_array", "(", "$", "counts", ")", ")", "{", "return", "(", "int", ")", "$", "counts", "[", "'MESSAGES'", "]", ";", "}", "return", "false", ";", "}" ]
Returns count of all messages in a folder @param string $mailbox Mailbox name @return int Number of messages, False on error
[ "Returns", "count", "of", "all", "messages", "in", "a", "folder" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L1610-L1629
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.countUnseen
public function countUnseen($mailbox) { // Check internal cache $cache = $this->data['STATUS:'.$mailbox]; if (!empty($cache) && isset($cache['UNSEEN'])) { return (int) $cache['UNSEEN']; } // Try STATUS (should be faster than SELECT+SEARCH) $counts = $this->status($mailbox); if (is_array($counts)) { return (int) $counts['UNSEEN']; } // Invoke SEARCH as a fallback $index = $this->search($mailbox, 'ALL UNSEEN', false, array('COUNT')); if (!$index->is_error()) { return $index->count(); } return false; }
php
public function countUnseen($mailbox) { // Check internal cache $cache = $this->data['STATUS:'.$mailbox]; if (!empty($cache) && isset($cache['UNSEEN'])) { return (int) $cache['UNSEEN']; } // Try STATUS (should be faster than SELECT+SEARCH) $counts = $this->status($mailbox); if (is_array($counts)) { return (int) $counts['UNSEEN']; } // Invoke SEARCH as a fallback $index = $this->search($mailbox, 'ALL UNSEEN', false, array('COUNT')); if (!$index->is_error()) { return $index->count(); } return false; }
[ "public", "function", "countUnseen", "(", "$", "mailbox", ")", "{", "// Check internal cache", "$", "cache", "=", "$", "this", "->", "data", "[", "'STATUS:'", ".", "$", "mailbox", "]", ";", "if", "(", "!", "empty", "(", "$", "cache", ")", "&&", "isset", "(", "$", "cache", "[", "'UNSEEN'", "]", ")", ")", "{", "return", "(", "int", ")", "$", "cache", "[", "'UNSEEN'", "]", ";", "}", "// Try STATUS (should be faster than SELECT+SEARCH)", "$", "counts", "=", "$", "this", "->", "status", "(", "$", "mailbox", ")", ";", "if", "(", "is_array", "(", "$", "counts", ")", ")", "{", "return", "(", "int", ")", "$", "counts", "[", "'UNSEEN'", "]", ";", "}", "// Invoke SEARCH as a fallback", "$", "index", "=", "$", "this", "->", "search", "(", "$", "mailbox", ",", "'ALL UNSEEN'", ",", "false", ",", "array", "(", "'COUNT'", ")", ")", ";", "if", "(", "!", "$", "index", "->", "is_error", "(", ")", ")", "{", "return", "$", "index", "->", "count", "(", ")", ";", "}", "return", "false", ";", "}" ]
Returns count of messages without \Seen flag in a specified folder @param string $mailbox Mailbox name @return int Number of messages, False on error
[ "Returns", "count", "of", "messages", "without", "\\", "Seen", "flag", "in", "a", "specified", "folder" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L1666-L1687
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.sort
public function sort($mailbox, $field = 'ARRIVAL', $criteria = '', $return_uid = false, $encoding = 'US-ASCII') { $old_sel = $this->selected; $supported = array('ARRIVAL', 'CC', 'DATE', 'FROM', 'SIZE', 'SUBJECT', 'TO'); $field = strtoupper($field); if ($field == 'INTERNALDATE') { $field = 'ARRIVAL'; } if (!in_array($field, $supported)) { return new rcube_result_index($mailbox); } if (!$this->select($mailbox)) { return new rcube_result_index($mailbox); } // return empty result when folder is empty and we're just after SELECT if ($old_sel != $mailbox && !$this->data['EXISTS']) { return new rcube_result_index($mailbox, '* SORT'); } // RFC 5957: SORT=DISPLAY if (($field == 'FROM' || $field == 'TO') && $this->getCapability('SORT=DISPLAY')) { $field = 'DISPLAY' . $field; } $encoding = $encoding ? trim($encoding) : 'US-ASCII'; $criteria = $criteria ? 'ALL ' . trim($criteria) : 'ALL'; list($code, $response) = $this->execute($return_uid ? 'UID SORT' : 'SORT', array("($field)", $encoding, $criteria)); if ($code != self::ERROR_OK) { $response = null; } return new rcube_result_index($mailbox, $response); }
php
public function sort($mailbox, $field = 'ARRIVAL', $criteria = '', $return_uid = false, $encoding = 'US-ASCII') { $old_sel = $this->selected; $supported = array('ARRIVAL', 'CC', 'DATE', 'FROM', 'SIZE', 'SUBJECT', 'TO'); $field = strtoupper($field); if ($field == 'INTERNALDATE') { $field = 'ARRIVAL'; } if (!in_array($field, $supported)) { return new rcube_result_index($mailbox); } if (!$this->select($mailbox)) { return new rcube_result_index($mailbox); } // return empty result when folder is empty and we're just after SELECT if ($old_sel != $mailbox && !$this->data['EXISTS']) { return new rcube_result_index($mailbox, '* SORT'); } // RFC 5957: SORT=DISPLAY if (($field == 'FROM' || $field == 'TO') && $this->getCapability('SORT=DISPLAY')) { $field = 'DISPLAY' . $field; } $encoding = $encoding ? trim($encoding) : 'US-ASCII'; $criteria = $criteria ? 'ALL ' . trim($criteria) : 'ALL'; list($code, $response) = $this->execute($return_uid ? 'UID SORT' : 'SORT', array("($field)", $encoding, $criteria)); if ($code != self::ERROR_OK) { $response = null; } return new rcube_result_index($mailbox, $response); }
[ "public", "function", "sort", "(", "$", "mailbox", ",", "$", "field", "=", "'ARRIVAL'", ",", "$", "criteria", "=", "''", ",", "$", "return_uid", "=", "false", ",", "$", "encoding", "=", "'US-ASCII'", ")", "{", "$", "old_sel", "=", "$", "this", "->", "selected", ";", "$", "supported", "=", "array", "(", "'ARRIVAL'", ",", "'CC'", ",", "'DATE'", ",", "'FROM'", ",", "'SIZE'", ",", "'SUBJECT'", ",", "'TO'", ")", ";", "$", "field", "=", "strtoupper", "(", "$", "field", ")", ";", "if", "(", "$", "field", "==", "'INTERNALDATE'", ")", "{", "$", "field", "=", "'ARRIVAL'", ";", "}", "if", "(", "!", "in_array", "(", "$", "field", ",", "$", "supported", ")", ")", "{", "return", "new", "rcube_result_index", "(", "$", "mailbox", ")", ";", "}", "if", "(", "!", "$", "this", "->", "select", "(", "$", "mailbox", ")", ")", "{", "return", "new", "rcube_result_index", "(", "$", "mailbox", ")", ";", "}", "// return empty result when folder is empty and we're just after SELECT", "if", "(", "$", "old_sel", "!=", "$", "mailbox", "&&", "!", "$", "this", "->", "data", "[", "'EXISTS'", "]", ")", "{", "return", "new", "rcube_result_index", "(", "$", "mailbox", ",", "'* SORT'", ")", ";", "}", "// RFC 5957: SORT=DISPLAY", "if", "(", "(", "$", "field", "==", "'FROM'", "||", "$", "field", "==", "'TO'", ")", "&&", "$", "this", "->", "getCapability", "(", "'SORT=DISPLAY'", ")", ")", "{", "$", "field", "=", "'DISPLAY'", ".", "$", "field", ";", "}", "$", "encoding", "=", "$", "encoding", "?", "trim", "(", "$", "encoding", ")", ":", "'US-ASCII'", ";", "$", "criteria", "=", "$", "criteria", "?", "'ALL '", ".", "trim", "(", "$", "criteria", ")", ":", "'ALL'", ";", "list", "(", "$", "code", ",", "$", "response", ")", "=", "$", "this", "->", "execute", "(", "$", "return_uid", "?", "'UID SORT'", ":", "'SORT'", ",", "array", "(", "\"($field)\"", ",", "$", "encoding", ",", "$", "criteria", ")", ")", ";", "if", "(", "$", "code", "!=", "self", "::", "ERROR_OK", ")", "{", "$", "response", "=", "null", ";", "}", "return", "new", "rcube_result_index", "(", "$", "mailbox", ",", "$", "response", ")", ";", "}" ]
Executes SORT command @param string $mailbox Mailbox name @param string $field Field to sort by (ARRIVAL, CC, DATE, FROM, SIZE, SUBJECT, TO) @param string $criteria Searching criteria @param bool $return_uid Enables UID SORT usage @param string $encoding Character set @return rcube_result_index Response data
[ "Executes", "SORT", "command" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L1786-L1825
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.thread
public function thread($mailbox, $algorithm = 'REFERENCES', $criteria = '', $return_uid = false, $encoding = 'US-ASCII') { $old_sel = $this->selected; if (!$this->select($mailbox)) { return new rcube_result_thread($mailbox); } // return empty result when folder is empty and we're just after SELECT if ($old_sel != $mailbox && !$this->data['EXISTS']) { return new rcube_result_thread($mailbox, '* THREAD'); } $encoding = $encoding ? trim($encoding) : 'US-ASCII'; $algorithm = $algorithm ? trim($algorithm) : 'REFERENCES'; $criteria = $criteria ? 'ALL '.trim($criteria) : 'ALL'; list($code, $response) = $this->execute($return_uid ? 'UID THREAD' : 'THREAD', array($algorithm, $encoding, $criteria)); if ($code != self::ERROR_OK) { $response = null; } return new rcube_result_thread($mailbox, $response); }
php
public function thread($mailbox, $algorithm = 'REFERENCES', $criteria = '', $return_uid = false, $encoding = 'US-ASCII') { $old_sel = $this->selected; if (!$this->select($mailbox)) { return new rcube_result_thread($mailbox); } // return empty result when folder is empty and we're just after SELECT if ($old_sel != $mailbox && !$this->data['EXISTS']) { return new rcube_result_thread($mailbox, '* THREAD'); } $encoding = $encoding ? trim($encoding) : 'US-ASCII'; $algorithm = $algorithm ? trim($algorithm) : 'REFERENCES'; $criteria = $criteria ? 'ALL '.trim($criteria) : 'ALL'; list($code, $response) = $this->execute($return_uid ? 'UID THREAD' : 'THREAD', array($algorithm, $encoding, $criteria)); if ($code != self::ERROR_OK) { $response = null; } return new rcube_result_thread($mailbox, $response); }
[ "public", "function", "thread", "(", "$", "mailbox", ",", "$", "algorithm", "=", "'REFERENCES'", ",", "$", "criteria", "=", "''", ",", "$", "return_uid", "=", "false", ",", "$", "encoding", "=", "'US-ASCII'", ")", "{", "$", "old_sel", "=", "$", "this", "->", "selected", ";", "if", "(", "!", "$", "this", "->", "select", "(", "$", "mailbox", ")", ")", "{", "return", "new", "rcube_result_thread", "(", "$", "mailbox", ")", ";", "}", "// return empty result when folder is empty and we're just after SELECT", "if", "(", "$", "old_sel", "!=", "$", "mailbox", "&&", "!", "$", "this", "->", "data", "[", "'EXISTS'", "]", ")", "{", "return", "new", "rcube_result_thread", "(", "$", "mailbox", ",", "'* THREAD'", ")", ";", "}", "$", "encoding", "=", "$", "encoding", "?", "trim", "(", "$", "encoding", ")", ":", "'US-ASCII'", ";", "$", "algorithm", "=", "$", "algorithm", "?", "trim", "(", "$", "algorithm", ")", ":", "'REFERENCES'", ";", "$", "criteria", "=", "$", "criteria", "?", "'ALL '", ".", "trim", "(", "$", "criteria", ")", ":", "'ALL'", ";", "list", "(", "$", "code", ",", "$", "response", ")", "=", "$", "this", "->", "execute", "(", "$", "return_uid", "?", "'UID THREAD'", ":", "'THREAD'", ",", "array", "(", "$", "algorithm", ",", "$", "encoding", ",", "$", "criteria", ")", ")", ";", "if", "(", "$", "code", "!=", "self", "::", "ERROR_OK", ")", "{", "$", "response", "=", "null", ";", "}", "return", "new", "rcube_result_thread", "(", "$", "mailbox", ",", "$", "response", ")", ";", "}" ]
Executes THREAD command @param string $mailbox Mailbox name @param string $algorithm Threading algorithm (ORDEREDSUBJECT, REFERENCES, REFS) @param string $criteria Searching criteria @param bool $return_uid Enables UIDs in result instead of sequence numbers @param string $encoding Character set @return rcube_result_thread Thread data
[ "Executes", "THREAD", "command" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L1838-L1863
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.search
public function search($mailbox, $criteria, $return_uid = false, $items = array()) { $old_sel = $this->selected; if (!$this->select($mailbox)) { return new rcube_result_index($mailbox); } // return empty result when folder is empty and we're just after SELECT if ($old_sel != $mailbox && !$this->data['EXISTS']) { return new rcube_result_index($mailbox, '* SEARCH'); } // If ESEARCH is supported always use ALL // but not when items are specified or using simple id2uid search if (empty($items) && preg_match('/[^0-9]/', $criteria)) { $items = array('ALL'); } $esearch = empty($items) ? false : $this->getCapability('ESEARCH'); $criteria = trim($criteria); $params = ''; // RFC4731: ESEARCH if (!empty($items) && $esearch) { $params .= 'RETURN (' . implode(' ', $items) . ')'; } if (!empty($criteria)) { $params .= ($params ? ' ' : '') . $criteria; } else { $params .= 'ALL'; } list($code, $response) = $this->execute($return_uid ? 'UID SEARCH' : 'SEARCH', array($params)); if ($code != self::ERROR_OK) { $response = null; } return new rcube_result_index($mailbox, $response); }
php
public function search($mailbox, $criteria, $return_uid = false, $items = array()) { $old_sel = $this->selected; if (!$this->select($mailbox)) { return new rcube_result_index($mailbox); } // return empty result when folder is empty and we're just after SELECT if ($old_sel != $mailbox && !$this->data['EXISTS']) { return new rcube_result_index($mailbox, '* SEARCH'); } // If ESEARCH is supported always use ALL // but not when items are specified or using simple id2uid search if (empty($items) && preg_match('/[^0-9]/', $criteria)) { $items = array('ALL'); } $esearch = empty($items) ? false : $this->getCapability('ESEARCH'); $criteria = trim($criteria); $params = ''; // RFC4731: ESEARCH if (!empty($items) && $esearch) { $params .= 'RETURN (' . implode(' ', $items) . ')'; } if (!empty($criteria)) { $params .= ($params ? ' ' : '') . $criteria; } else { $params .= 'ALL'; } list($code, $response) = $this->execute($return_uid ? 'UID SEARCH' : 'SEARCH', array($params)); if ($code != self::ERROR_OK) { $response = null; } return new rcube_result_index($mailbox, $response); }
[ "public", "function", "search", "(", "$", "mailbox", ",", "$", "criteria", ",", "$", "return_uid", "=", "false", ",", "$", "items", "=", "array", "(", ")", ")", "{", "$", "old_sel", "=", "$", "this", "->", "selected", ";", "if", "(", "!", "$", "this", "->", "select", "(", "$", "mailbox", ")", ")", "{", "return", "new", "rcube_result_index", "(", "$", "mailbox", ")", ";", "}", "// return empty result when folder is empty and we're just after SELECT", "if", "(", "$", "old_sel", "!=", "$", "mailbox", "&&", "!", "$", "this", "->", "data", "[", "'EXISTS'", "]", ")", "{", "return", "new", "rcube_result_index", "(", "$", "mailbox", ",", "'* SEARCH'", ")", ";", "}", "// If ESEARCH is supported always use ALL", "// but not when items are specified or using simple id2uid search", "if", "(", "empty", "(", "$", "items", ")", "&&", "preg_match", "(", "'/[^0-9]/'", ",", "$", "criteria", ")", ")", "{", "$", "items", "=", "array", "(", "'ALL'", ")", ";", "}", "$", "esearch", "=", "empty", "(", "$", "items", ")", "?", "false", ":", "$", "this", "->", "getCapability", "(", "'ESEARCH'", ")", ";", "$", "criteria", "=", "trim", "(", "$", "criteria", ")", ";", "$", "params", "=", "''", ";", "// RFC4731: ESEARCH", "if", "(", "!", "empty", "(", "$", "items", ")", "&&", "$", "esearch", ")", "{", "$", "params", ".=", "'RETURN ('", ".", "implode", "(", "' '", ",", "$", "items", ")", ".", "')'", ";", "}", "if", "(", "!", "empty", "(", "$", "criteria", ")", ")", "{", "$", "params", ".=", "(", "$", "params", "?", "' '", ":", "''", ")", ".", "$", "criteria", ";", "}", "else", "{", "$", "params", ".=", "'ALL'", ";", "}", "list", "(", "$", "code", ",", "$", "response", ")", "=", "$", "this", "->", "execute", "(", "$", "return_uid", "?", "'UID SEARCH'", ":", "'SEARCH'", ",", "array", "(", "$", "params", ")", ")", ";", "if", "(", "$", "code", "!=", "self", "::", "ERROR_OK", ")", "{", "$", "response", "=", "null", ";", "}", "return", "new", "rcube_result_index", "(", "$", "mailbox", ",", "$", "response", ")", ";", "}" ]
Executes SEARCH command @param string $mailbox Mailbox name @param string $criteria Searching criteria @param bool $return_uid Enable UID in result instead of sequence ID @param array $items Return items (MIN, MAX, COUNT, ALL) @return rcube_result_index Result data
[ "Executes", "SEARCH", "command" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L1875-L1918
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.index
public function index($mailbox, $message_set, $index_field='', $skip_deleted=true, $uidfetch=false, $return_uid=false) { $msg_index = $this->fetchHeaderIndex($mailbox, $message_set, $index_field, $skip_deleted, $uidfetch, $return_uid); if (!empty($msg_index)) { asort($msg_index); // ASC $msg_index = array_keys($msg_index); $msg_index = '* SEARCH ' . implode(' ', $msg_index); } else { $msg_index = is_array($msg_index) ? '* SEARCH' : null; } return new rcube_result_index($mailbox, $msg_index); }
php
public function index($mailbox, $message_set, $index_field='', $skip_deleted=true, $uidfetch=false, $return_uid=false) { $msg_index = $this->fetchHeaderIndex($mailbox, $message_set, $index_field, $skip_deleted, $uidfetch, $return_uid); if (!empty($msg_index)) { asort($msg_index); // ASC $msg_index = array_keys($msg_index); $msg_index = '* SEARCH ' . implode(' ', $msg_index); } else { $msg_index = is_array($msg_index) ? '* SEARCH' : null; } return new rcube_result_index($mailbox, $msg_index); }
[ "public", "function", "index", "(", "$", "mailbox", ",", "$", "message_set", ",", "$", "index_field", "=", "''", ",", "$", "skip_deleted", "=", "true", ",", "$", "uidfetch", "=", "false", ",", "$", "return_uid", "=", "false", ")", "{", "$", "msg_index", "=", "$", "this", "->", "fetchHeaderIndex", "(", "$", "mailbox", ",", "$", "message_set", ",", "$", "index_field", ",", "$", "skip_deleted", ",", "$", "uidfetch", ",", "$", "return_uid", ")", ";", "if", "(", "!", "empty", "(", "$", "msg_index", ")", ")", "{", "asort", "(", "$", "msg_index", ")", ";", "// ASC", "$", "msg_index", "=", "array_keys", "(", "$", "msg_index", ")", ";", "$", "msg_index", "=", "'* SEARCH '", ".", "implode", "(", "' '", ",", "$", "msg_index", ")", ";", "}", "else", "{", "$", "msg_index", "=", "is_array", "(", "$", "msg_index", ")", "?", "'* SEARCH'", ":", "null", ";", "}", "return", "new", "rcube_result_index", "(", "$", "mailbox", ",", "$", "msg_index", ")", ";", "}" ]
Simulates SORT command by using FETCH and sorting. @param string $mailbox Mailbox name @param string|array $message_set Searching criteria (list of messages to return) @param string $index_field Field to sort by (ARRIVAL, CC, DATE, FROM, SIZE, SUBJECT, TO) @param bool $skip_deleted Makes that DELETED messages will be skipped @param bool $uidfetch Enables UID FETCH usage @param bool $return_uid Enables returning UIDs instead of IDs @return rcube_result_index Response data
[ "Simulates", "SORT", "command", "by", "using", "FETCH", "and", "sorting", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L1932-L1948
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.UID2ID
public function UID2ID($mailbox, $uid) { if ($uid > 0) { $index = $this->search($mailbox, "UID $uid"); if ($index->count() == 1) { $arr = $index->get(); return (int) $arr[0]; } } }
php
public function UID2ID($mailbox, $uid) { if ($uid > 0) { $index = $this->search($mailbox, "UID $uid"); if ($index->count() == 1) { $arr = $index->get(); return (int) $arr[0]; } } }
[ "public", "function", "UID2ID", "(", "$", "mailbox", ",", "$", "uid", ")", "{", "if", "(", "$", "uid", ">", "0", ")", "{", "$", "index", "=", "$", "this", "->", "search", "(", "$", "mailbox", ",", "\"UID $uid\"", ")", ";", "if", "(", "$", "index", "->", "count", "(", ")", "==", "1", ")", "{", "$", "arr", "=", "$", "index", "->", "get", "(", ")", ";", "return", "(", "int", ")", "$", "arr", "[", "0", "]", ";", "}", "}", "}" ]
Returns message sequence identifier @param string $mailbox Mailbox name @param int $uid Message unique identifier (UID) @return int Message sequence identifier
[ "Returns", "message", "sequence", "identifier" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L2132-L2142
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.sortHeaders
public static function sortHeaders($messages, $field, $flag) { // Strategy: First, we'll create an "index" array. // Then, we'll use sort() on that array, and use that to sort the main array. $field = empty($field) ? 'uid' : strtolower($field); $flag = empty($flag) ? 'ASC' : strtoupper($flag); $index = array(); $result = array(); reset($messages); foreach ($messages as $key => $headers) { $value = null; switch ($field) { case 'arrival': $field = 'internaldate'; case 'date': case 'internaldate': case 'timestamp': $value = rcube_utils::strtotime($headers->$field); if (!$value && $field != 'timestamp') { $value = $headers->timestamp; } break; default: // @TODO: decode header value, convert to UTF-8 $value = $headers->$field; if (is_string($value)) { $value = str_replace('"', '', $value); if ($field == 'subject') { $value = preg_replace('/^(Re:\s*|Fwd:\s*|Fw:\s*)+/i', '', $value); } $data = strtoupper($value); } } $index[$key] = $value; } if (!empty($index)) { // sort index if ($flag == 'ASC') { asort($index); } else { arsort($index); } // form new array based on index foreach ($index as $key => $val) { $result[$key] = $messages[$key]; } } return $result; }
php
public static function sortHeaders($messages, $field, $flag) { // Strategy: First, we'll create an "index" array. // Then, we'll use sort() on that array, and use that to sort the main array. $field = empty($field) ? 'uid' : strtolower($field); $flag = empty($flag) ? 'ASC' : strtoupper($flag); $index = array(); $result = array(); reset($messages); foreach ($messages as $key => $headers) { $value = null; switch ($field) { case 'arrival': $field = 'internaldate'; case 'date': case 'internaldate': case 'timestamp': $value = rcube_utils::strtotime($headers->$field); if (!$value && $field != 'timestamp') { $value = $headers->timestamp; } break; default: // @TODO: decode header value, convert to UTF-8 $value = $headers->$field; if (is_string($value)) { $value = str_replace('"', '', $value); if ($field == 'subject') { $value = preg_replace('/^(Re:\s*|Fwd:\s*|Fw:\s*)+/i', '', $value); } $data = strtoupper($value); } } $index[$key] = $value; } if (!empty($index)) { // sort index if ($flag == 'ASC') { asort($index); } else { arsort($index); } // form new array based on index foreach ($index as $key => $val) { $result[$key] = $messages[$key]; } } return $result; }
[ "public", "static", "function", "sortHeaders", "(", "$", "messages", ",", "$", "field", ",", "$", "flag", ")", "{", "// Strategy: First, we'll create an \"index\" array.", "// Then, we'll use sort() on that array, and use that to sort the main array.", "$", "field", "=", "empty", "(", "$", "field", ")", "?", "'uid'", ":", "strtolower", "(", "$", "field", ")", ";", "$", "flag", "=", "empty", "(", "$", "flag", ")", "?", "'ASC'", ":", "strtoupper", "(", "$", "flag", ")", ";", "$", "index", "=", "array", "(", ")", ";", "$", "result", "=", "array", "(", ")", ";", "reset", "(", "$", "messages", ")", ";", "foreach", "(", "$", "messages", "as", "$", "key", "=>", "$", "headers", ")", "{", "$", "value", "=", "null", ";", "switch", "(", "$", "field", ")", "{", "case", "'arrival'", ":", "$", "field", "=", "'internaldate'", ";", "case", "'date'", ":", "case", "'internaldate'", ":", "case", "'timestamp'", ":", "$", "value", "=", "rcube_utils", "::", "strtotime", "(", "$", "headers", "->", "$", "field", ")", ";", "if", "(", "!", "$", "value", "&&", "$", "field", "!=", "'timestamp'", ")", "{", "$", "value", "=", "$", "headers", "->", "timestamp", ";", "}", "break", ";", "default", ":", "// @TODO: decode header value, convert to UTF-8", "$", "value", "=", "$", "headers", "->", "$", "field", ";", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "value", "=", "str_replace", "(", "'\"'", ",", "''", ",", "$", "value", ")", ";", "if", "(", "$", "field", "==", "'subject'", ")", "{", "$", "value", "=", "preg_replace", "(", "'/^(Re:\\s*|Fwd:\\s*|Fw:\\s*)+/i'", ",", "''", ",", "$", "value", ")", ";", "}", "$", "data", "=", "strtoupper", "(", "$", "value", ")", ";", "}", "}", "$", "index", "[", "$", "key", "]", "=", "$", "value", ";", "}", "if", "(", "!", "empty", "(", "$", "index", ")", ")", "{", "// sort index", "if", "(", "$", "flag", "==", "'ASC'", ")", "{", "asort", "(", "$", "index", ")", ";", "}", "else", "{", "arsort", "(", "$", "index", ")", ";", "}", "// form new array based on index", "foreach", "(", "$", "index", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "result", "[", "$", "key", "]", "=", "$", "messages", "[", "$", "key", "]", ";", "}", "}", "return", "$", "result", ";", "}" ]
Sort messages by specified header field @param array $messages Array of rcube_message_header objects @param string $field Name of the property to sort by @param string $flag Sorting order (ASC|DESC) @return array Sorted input array
[ "Sort", "messages", "by", "specified", "header", "field" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L2633-L2693
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.fetchMIMEHeaders
public function fetchMIMEHeaders($mailbox, $uid, $parts, $mime = true) { if (!$this->select($mailbox)) { return false; } $result = false; $parts = (array) $parts; $key = $this->nextTag(); $peeks = array(); $type = $mime ? 'MIME' : 'HEADER'; // format request foreach ($parts as $part) { $peeks[] = "BODY.PEEK[$part.$type]"; } $request = "$key UID FETCH $uid (" . implode(' ', $peeks) . ')'; // send request if (!$this->putLine($request)) { $this->setError(self::ERROR_COMMAND, "Failed to send UID FETCH command"); return false; } do { $line = $this->readLine(1024); if (preg_match('/^\* [0-9]+ FETCH [0-9UID( ]+/', $line, $m)) { $line = ltrim(substr($line, strlen($m[0]))); while (preg_match('/^BODY\[([0-9\.]+)\.'.$type.'\]/', $line, $matches)) { $line = substr($line, strlen($matches[0])); $result[$matches[1]] = trim($this->multLine($line)); $line = $this->readLine(1024); } } } while (!$this->startsWith($line, $key, true)); return $result; }
php
public function fetchMIMEHeaders($mailbox, $uid, $parts, $mime = true) { if (!$this->select($mailbox)) { return false; } $result = false; $parts = (array) $parts; $key = $this->nextTag(); $peeks = array(); $type = $mime ? 'MIME' : 'HEADER'; // format request foreach ($parts as $part) { $peeks[] = "BODY.PEEK[$part.$type]"; } $request = "$key UID FETCH $uid (" . implode(' ', $peeks) . ')'; // send request if (!$this->putLine($request)) { $this->setError(self::ERROR_COMMAND, "Failed to send UID FETCH command"); return false; } do { $line = $this->readLine(1024); if (preg_match('/^\* [0-9]+ FETCH [0-9UID( ]+/', $line, $m)) { $line = ltrim(substr($line, strlen($m[0]))); while (preg_match('/^BODY\[([0-9\.]+)\.'.$type.'\]/', $line, $matches)) { $line = substr($line, strlen($matches[0])); $result[$matches[1]] = trim($this->multLine($line)); $line = $this->readLine(1024); } } } while (!$this->startsWith($line, $key, true)); return $result; }
[ "public", "function", "fetchMIMEHeaders", "(", "$", "mailbox", ",", "$", "uid", ",", "$", "parts", ",", "$", "mime", "=", "true", ")", "{", "if", "(", "!", "$", "this", "->", "select", "(", "$", "mailbox", ")", ")", "{", "return", "false", ";", "}", "$", "result", "=", "false", ";", "$", "parts", "=", "(", "array", ")", "$", "parts", ";", "$", "key", "=", "$", "this", "->", "nextTag", "(", ")", ";", "$", "peeks", "=", "array", "(", ")", ";", "$", "type", "=", "$", "mime", "?", "'MIME'", ":", "'HEADER'", ";", "// format request", "foreach", "(", "$", "parts", "as", "$", "part", ")", "{", "$", "peeks", "[", "]", "=", "\"BODY.PEEK[$part.$type]\"", ";", "}", "$", "request", "=", "\"$key UID FETCH $uid (\"", ".", "implode", "(", "' '", ",", "$", "peeks", ")", ".", "')'", ";", "// send request", "if", "(", "!", "$", "this", "->", "putLine", "(", "$", "request", ")", ")", "{", "$", "this", "->", "setError", "(", "self", "::", "ERROR_COMMAND", ",", "\"Failed to send UID FETCH command\"", ")", ";", "return", "false", ";", "}", "do", "{", "$", "line", "=", "$", "this", "->", "readLine", "(", "1024", ")", ";", "if", "(", "preg_match", "(", "'/^\\* [0-9]+ FETCH [0-9UID( ]+/'", ",", "$", "line", ",", "$", "m", ")", ")", "{", "$", "line", "=", "ltrim", "(", "substr", "(", "$", "line", ",", "strlen", "(", "$", "m", "[", "0", "]", ")", ")", ")", ";", "while", "(", "preg_match", "(", "'/^BODY\\[([0-9\\.]+)\\.'", ".", "$", "type", ".", "'\\]/'", ",", "$", "line", ",", "$", "matches", ")", ")", "{", "$", "line", "=", "substr", "(", "$", "line", ",", "strlen", "(", "$", "matches", "[", "0", "]", ")", ")", ";", "$", "result", "[", "$", "matches", "[", "1", "]", "]", "=", "trim", "(", "$", "this", "->", "multLine", "(", "$", "line", ")", ")", ";", "$", "line", "=", "$", "this", "->", "readLine", "(", "1024", ")", ";", "}", "}", "}", "while", "(", "!", "$", "this", "->", "startsWith", "(", "$", "line", ",", "$", "key", ",", "true", ")", ")", ";", "return", "$", "result", ";", "}" ]
Fetch MIME headers of specified message parts @param string $mailbox Mailbox name @param int $uid Message UID @param array $parts Message part identifiers @param bool $mime Use MIME instad of HEADER @return array|bool Array containing headers string for each specified body False on failure.
[ "Fetch", "MIME", "headers", "of", "specified", "message", "parts" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L2706-L2746
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.fetchPartHeader
public function fetchPartHeader($mailbox, $id, $is_uid = false, $part = null) { $part = empty($part) ? 'HEADER' : $part.'.MIME'; return $this->handlePartBody($mailbox, $id, $is_uid, $part); }
php
public function fetchPartHeader($mailbox, $id, $is_uid = false, $part = null) { $part = empty($part) ? 'HEADER' : $part.'.MIME'; return $this->handlePartBody($mailbox, $id, $is_uid, $part); }
[ "public", "function", "fetchPartHeader", "(", "$", "mailbox", ",", "$", "id", ",", "$", "is_uid", "=", "false", ",", "$", "part", "=", "null", ")", "{", "$", "part", "=", "empty", "(", "$", "part", ")", "?", "'HEADER'", ":", "$", "part", ".", "'.MIME'", ";", "return", "$", "this", "->", "handlePartBody", "(", "$", "mailbox", ",", "$", "id", ",", "$", "is_uid", ",", "$", "part", ")", ";", "}" ]
Fetches message part header
[ "Fetches", "message", "part", "header" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L2751-L2756
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.appendFromFile
public function appendFromFile($mailbox, $path, $headers=null, $flags = array(), $date = null, $binary = false) { // open message file if (file_exists(realpath($path))) { $fp = fopen($path, 'r'); } if (!$fp) { $this->setError(self::ERROR_UNKNOWN, "Couldn't open $path for reading"); return false; } $message = array(); if ($headers) { $message[] = trim($headers, "\r\n") . "\r\n\r\n"; } $message[] = $fp; return $this->append($mailbox, $message, $flags, $date, $binary); }
php
public function appendFromFile($mailbox, $path, $headers=null, $flags = array(), $date = null, $binary = false) { // open message file if (file_exists(realpath($path))) { $fp = fopen($path, 'r'); } if (!$fp) { $this->setError(self::ERROR_UNKNOWN, "Couldn't open $path for reading"); return false; } $message = array(); if ($headers) { $message[] = trim($headers, "\r\n") . "\r\n\r\n"; } $message[] = $fp; return $this->append($mailbox, $message, $flags, $date, $binary); }
[ "public", "function", "appendFromFile", "(", "$", "mailbox", ",", "$", "path", ",", "$", "headers", "=", "null", ",", "$", "flags", "=", "array", "(", ")", ",", "$", "date", "=", "null", ",", "$", "binary", "=", "false", ")", "{", "// open message file", "if", "(", "file_exists", "(", "realpath", "(", "$", "path", ")", ")", ")", "{", "$", "fp", "=", "fopen", "(", "$", "path", ",", "'r'", ")", ";", "}", "if", "(", "!", "$", "fp", ")", "{", "$", "this", "->", "setError", "(", "self", "::", "ERROR_UNKNOWN", ",", "\"Couldn't open $path for reading\"", ")", ";", "return", "false", ";", "}", "$", "message", "=", "array", "(", ")", ";", "if", "(", "$", "headers", ")", "{", "$", "message", "[", "]", "=", "trim", "(", "$", "headers", ",", "\"\\r\\n\"", ")", ".", "\"\\r\\n\\r\\n\"", ";", "}", "$", "message", "[", "]", "=", "$", "fp", ";", "return", "$", "this", "->", "append", "(", "$", "mailbox", ",", "$", "message", ",", "$", "flags", ",", "$", "date", ",", "$", "binary", ")", ";", "}" ]
Handler for IMAP APPEND command. @param string $mailbox Mailbox name @param string $path Path to the file with message body @param string $headers Message headers @param array $flags Message flags @param string $date Message internal date @param bool $binary Enable BINARY append (RFC3516) @return string|bool On success APPENDUID response (if available) or True, False on failure
[ "Handler", "for", "IMAP", "APPEND", "command", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L3078-L3097
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.getQuota
public function getQuota($mailbox = null) { if ($mailbox === null || $mailbox === '') { $mailbox = 'INBOX'; } // a0001 GETQUOTAROOT INBOX // * QUOTAROOT INBOX user/sample // * QUOTA user/sample (STORAGE 654 9765) // a0001 OK Completed list($code, $response) = $this->execute('GETQUOTAROOT', array($this->escape($mailbox)), 0, '/^\* QUOTA /i'); $result = false; $min_free = PHP_INT_MAX; $all = array(); if ($code == self::ERROR_OK) { foreach (explode("\n", $response) as $line) { list(, , $quota_root) = $this->tokenizeResponse($line, 3); $quotas = $this->tokenizeResponse($line, 1); if (empty($quotas)) { continue; } foreach (array_chunk($quotas, 3) as $quota) { list($type, $used, $total) = $quota; $type = strtolower($type); if ($type && $total) { $all[$quota_root][$type]['used'] = intval($used); $all[$quota_root][$type]['total'] = intval($total); } } if (empty($all[$quota_root]['storage'])) { continue; } $used = $all[$quota_root]['storage']['used']; $total = $all[$quota_root]['storage']['total']; $free = $total - $used; // calculate lowest available space from all storage quotas if ($free < $min_free) { $min_free = $free; $result['used'] = $used; $result['total'] = $total; $result['percent'] = min(100, round(($used/max(1,$total))*100)); $result['free'] = 100 - $result['percent']; } } } if (!empty($result)) { $result['all'] = $all; } return $result; }
php
public function getQuota($mailbox = null) { if ($mailbox === null || $mailbox === '') { $mailbox = 'INBOX'; } // a0001 GETQUOTAROOT INBOX // * QUOTAROOT INBOX user/sample // * QUOTA user/sample (STORAGE 654 9765) // a0001 OK Completed list($code, $response) = $this->execute('GETQUOTAROOT', array($this->escape($mailbox)), 0, '/^\* QUOTA /i'); $result = false; $min_free = PHP_INT_MAX; $all = array(); if ($code == self::ERROR_OK) { foreach (explode("\n", $response) as $line) { list(, , $quota_root) = $this->tokenizeResponse($line, 3); $quotas = $this->tokenizeResponse($line, 1); if (empty($quotas)) { continue; } foreach (array_chunk($quotas, 3) as $quota) { list($type, $used, $total) = $quota; $type = strtolower($type); if ($type && $total) { $all[$quota_root][$type]['used'] = intval($used); $all[$quota_root][$type]['total'] = intval($total); } } if (empty($all[$quota_root]['storage'])) { continue; } $used = $all[$quota_root]['storage']['used']; $total = $all[$quota_root]['storage']['total']; $free = $total - $used; // calculate lowest available space from all storage quotas if ($free < $min_free) { $min_free = $free; $result['used'] = $used; $result['total'] = $total; $result['percent'] = min(100, round(($used/max(1,$total))*100)); $result['free'] = 100 - $result['percent']; } } } if (!empty($result)) { $result['all'] = $all; } return $result; }
[ "public", "function", "getQuota", "(", "$", "mailbox", "=", "null", ")", "{", "if", "(", "$", "mailbox", "===", "null", "||", "$", "mailbox", "===", "''", ")", "{", "$", "mailbox", "=", "'INBOX'", ";", "}", "// a0001 GETQUOTAROOT INBOX", "// * QUOTAROOT INBOX user/sample", "// * QUOTA user/sample (STORAGE 654 9765)", "// a0001 OK Completed", "list", "(", "$", "code", ",", "$", "response", ")", "=", "$", "this", "->", "execute", "(", "'GETQUOTAROOT'", ",", "array", "(", "$", "this", "->", "escape", "(", "$", "mailbox", ")", ")", ",", "0", ",", "'/^\\* QUOTA /i'", ")", ";", "$", "result", "=", "false", ";", "$", "min_free", "=", "PHP_INT_MAX", ";", "$", "all", "=", "array", "(", ")", ";", "if", "(", "$", "code", "==", "self", "::", "ERROR_OK", ")", "{", "foreach", "(", "explode", "(", "\"\\n\"", ",", "$", "response", ")", "as", "$", "line", ")", "{", "list", "(", ",", ",", "$", "quota_root", ")", "=", "$", "this", "->", "tokenizeResponse", "(", "$", "line", ",", "3", ")", ";", "$", "quotas", "=", "$", "this", "->", "tokenizeResponse", "(", "$", "line", ",", "1", ")", ";", "if", "(", "empty", "(", "$", "quotas", ")", ")", "{", "continue", ";", "}", "foreach", "(", "array_chunk", "(", "$", "quotas", ",", "3", ")", "as", "$", "quota", ")", "{", "list", "(", "$", "type", ",", "$", "used", ",", "$", "total", ")", "=", "$", "quota", ";", "$", "type", "=", "strtolower", "(", "$", "type", ")", ";", "if", "(", "$", "type", "&&", "$", "total", ")", "{", "$", "all", "[", "$", "quota_root", "]", "[", "$", "type", "]", "[", "'used'", "]", "=", "intval", "(", "$", "used", ")", ";", "$", "all", "[", "$", "quota_root", "]", "[", "$", "type", "]", "[", "'total'", "]", "=", "intval", "(", "$", "total", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "all", "[", "$", "quota_root", "]", "[", "'storage'", "]", ")", ")", "{", "continue", ";", "}", "$", "used", "=", "$", "all", "[", "$", "quota_root", "]", "[", "'storage'", "]", "[", "'used'", "]", ";", "$", "total", "=", "$", "all", "[", "$", "quota_root", "]", "[", "'storage'", "]", "[", "'total'", "]", ";", "$", "free", "=", "$", "total", "-", "$", "used", ";", "// calculate lowest available space from all storage quotas", "if", "(", "$", "free", "<", "$", "min_free", ")", "{", "$", "min_free", "=", "$", "free", ";", "$", "result", "[", "'used'", "]", "=", "$", "used", ";", "$", "result", "[", "'total'", "]", "=", "$", "total", ";", "$", "result", "[", "'percent'", "]", "=", "min", "(", "100", ",", "round", "(", "(", "$", "used", "/", "max", "(", "1", ",", "$", "total", ")", ")", "*", "100", ")", ")", ";", "$", "result", "[", "'free'", "]", "=", "100", "-", "$", "result", "[", "'percent'", "]", ";", "}", "}", "}", "if", "(", "!", "empty", "(", "$", "result", ")", ")", "{", "$", "result", "[", "'all'", "]", "=", "$", "all", ";", "}", "return", "$", "result", ";", "}" ]
Returns QUOTA information @param string $mailbox Mailbox name @return array Quota information
[ "Returns", "QUOTA", "information" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L3106-L3167
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.getStructure
public function getStructure($mailbox, $id, $is_uid = false) { $result = $this->fetch($mailbox, $id, $is_uid, array('BODYSTRUCTURE')); if (is_array($result)) { $result = array_shift($result); return $result->bodystructure; } return false; }
php
public function getStructure($mailbox, $id, $is_uid = false) { $result = $this->fetch($mailbox, $id, $is_uid, array('BODYSTRUCTURE')); if (is_array($result)) { $result = array_shift($result); return $result->bodystructure; } return false; }
[ "public", "function", "getStructure", "(", "$", "mailbox", ",", "$", "id", ",", "$", "is_uid", "=", "false", ")", "{", "$", "result", "=", "$", "this", "->", "fetch", "(", "$", "mailbox", ",", "$", "id", ",", "$", "is_uid", ",", "array", "(", "'BODYSTRUCTURE'", ")", ")", ";", "if", "(", "is_array", "(", "$", "result", ")", ")", "{", "$", "result", "=", "array_shift", "(", "$", "result", ")", ";", "return", "$", "result", "->", "bodystructure", ";", "}", "return", "false", ";", "}" ]
Returns BODYSTRUCTURE for the specified message. @param string $mailbox Folder name @param int $id Message sequence number or UID @param bool $is_uid True if $id is an UID @return array/bool Body structure array or False on error. @since 0.6
[ "Returns", "BODYSTRUCTURE", "for", "the", "specified", "message", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L3602-L3612
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.getStructurePartData
public static function getStructurePartData($structure, $part) { $part_a = self::getStructurePartArray($structure, $part); $data = array(); if (empty($part_a)) { return $data; } // content-type if (is_array($part_a[0])) { $data['type'] = 'multipart'; } else { $data['type'] = strtolower($part_a[0]); $data['encoding'] = strtolower($part_a[5]); // charset if (is_array($part_a[2])) { foreach ($part_a[2] as $key => $val) { if (strcasecmp($val, 'charset') == 0) { $data['charset'] = $part_a[2][$key+1]; break; } } } } // size $data['size'] = intval($part_a[6]); return $data; }
php
public static function getStructurePartData($structure, $part) { $part_a = self::getStructurePartArray($structure, $part); $data = array(); if (empty($part_a)) { return $data; } // content-type if (is_array($part_a[0])) { $data['type'] = 'multipart'; } else { $data['type'] = strtolower($part_a[0]); $data['encoding'] = strtolower($part_a[5]); // charset if (is_array($part_a[2])) { foreach ($part_a[2] as $key => $val) { if (strcasecmp($val, 'charset') == 0) { $data['charset'] = $part_a[2][$key+1]; break; } } } } // size $data['size'] = intval($part_a[6]); return $data; }
[ "public", "static", "function", "getStructurePartData", "(", "$", "structure", ",", "$", "part", ")", "{", "$", "part_a", "=", "self", "::", "getStructurePartArray", "(", "$", "structure", ",", "$", "part", ")", ";", "$", "data", "=", "array", "(", ")", ";", "if", "(", "empty", "(", "$", "part_a", ")", ")", "{", "return", "$", "data", ";", "}", "// content-type", "if", "(", "is_array", "(", "$", "part_a", "[", "0", "]", ")", ")", "{", "$", "data", "[", "'type'", "]", "=", "'multipart'", ";", "}", "else", "{", "$", "data", "[", "'type'", "]", "=", "strtolower", "(", "$", "part_a", "[", "0", "]", ")", ";", "$", "data", "[", "'encoding'", "]", "=", "strtolower", "(", "$", "part_a", "[", "5", "]", ")", ";", "// charset", "if", "(", "is_array", "(", "$", "part_a", "[", "2", "]", ")", ")", "{", "foreach", "(", "$", "part_a", "[", "2", "]", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "strcasecmp", "(", "$", "val", ",", "'charset'", ")", "==", "0", ")", "{", "$", "data", "[", "'charset'", "]", "=", "$", "part_a", "[", "2", "]", "[", "$", "key", "+", "1", "]", ";", "break", ";", "}", "}", "}", "}", "// size", "$", "data", "[", "'size'", "]", "=", "intval", "(", "$", "part_a", "[", "6", "]", ")", ";", "return", "$", "data", ";", "}" ]
Returns data of a message part according to specified structure. @param array $structure Message structure (getStructure() result) @param string $part Message part identifier @return array Part data as hash array (type, encoding, charset, size)
[ "Returns", "data", "of", "a", "message", "part", "according", "to", "specified", "structure", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L3622-L3654
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.execute
public function execute($command, $arguments = array(), $options = 0, $filter = null) { $tag = $this->nextTag(); $query = $tag . ' ' . $command; $noresp = ($options & self::COMMAND_NORESPONSE); $response = $noresp ? null : ''; if (!empty($arguments)) { foreach ($arguments as $arg) { $query .= ' ' . self::r_implode($arg); } } // Send command if (!$this->putLineC($query, true, ($options & self::COMMAND_ANONYMIZED))) { preg_match('/^[A-Z0-9]+ ((UID )?[A-Z]+)/', $query, $matches); $cmd = $matches[1] ?: 'UNKNOWN'; $this->setError(self::ERROR_COMMAND, "Failed to send $cmd command"); return $noresp ? self::ERROR_COMMAND : array(self::ERROR_COMMAND, ''); } // Parse response do { $line = $this->readLine(4096); if ($response !== null) { // TODO: Better string literals handling with filter if (!$filter || preg_match($filter, $line)) { $response .= $line; } } // parse untagged response for [COPYUID 1204196876 3456:3457 123:124] (RFC6851) if ($line && $command == 'UID MOVE') { if (preg_match("/^\* OK \[COPYUID [0-9]+ ([0-9,:]+) ([0-9,:]+)\]/i", $line, $m)) { $this->data['COPYUID'] = array($m[1], $m[2]); } } } while (!$this->startsWith($line, $tag . ' ', true, true)); $code = $this->parseResult($line, $command . ': '); // Remove last line from response if ($response) { if (!$filter) { $line_len = min(strlen($response), strlen($line)); $response = substr($response, 0, -$line_len); } $response = rtrim($response, "\r\n"); } // optional CAPABILITY response if (($options & self::COMMAND_CAPABILITY) && $code == self::ERROR_OK && preg_match('/\[CAPABILITY ([^]]+)\]/i', $line, $matches) ) { $this->parseCapability($matches[1], true); } // return last line only (without command tag, result and response code) if ($line && ($options & self::COMMAND_LASTLINE)) { $response = preg_replace("/^$tag (OK|NO|BAD|BYE|PREAUTH)?\s*(\[[a-z-]+\])?\s*/i", '', trim($line)); } return $noresp ? $code : array($code, $response); }
php
public function execute($command, $arguments = array(), $options = 0, $filter = null) { $tag = $this->nextTag(); $query = $tag . ' ' . $command; $noresp = ($options & self::COMMAND_NORESPONSE); $response = $noresp ? null : ''; if (!empty($arguments)) { foreach ($arguments as $arg) { $query .= ' ' . self::r_implode($arg); } } // Send command if (!$this->putLineC($query, true, ($options & self::COMMAND_ANONYMIZED))) { preg_match('/^[A-Z0-9]+ ((UID )?[A-Z]+)/', $query, $matches); $cmd = $matches[1] ?: 'UNKNOWN'; $this->setError(self::ERROR_COMMAND, "Failed to send $cmd command"); return $noresp ? self::ERROR_COMMAND : array(self::ERROR_COMMAND, ''); } // Parse response do { $line = $this->readLine(4096); if ($response !== null) { // TODO: Better string literals handling with filter if (!$filter || preg_match($filter, $line)) { $response .= $line; } } // parse untagged response for [COPYUID 1204196876 3456:3457 123:124] (RFC6851) if ($line && $command == 'UID MOVE') { if (preg_match("/^\* OK \[COPYUID [0-9]+ ([0-9,:]+) ([0-9,:]+)\]/i", $line, $m)) { $this->data['COPYUID'] = array($m[1], $m[2]); } } } while (!$this->startsWith($line, $tag . ' ', true, true)); $code = $this->parseResult($line, $command . ': '); // Remove last line from response if ($response) { if (!$filter) { $line_len = min(strlen($response), strlen($line)); $response = substr($response, 0, -$line_len); } $response = rtrim($response, "\r\n"); } // optional CAPABILITY response if (($options & self::COMMAND_CAPABILITY) && $code == self::ERROR_OK && preg_match('/\[CAPABILITY ([^]]+)\]/i', $line, $matches) ) { $this->parseCapability($matches[1], true); } // return last line only (without command tag, result and response code) if ($line && ($options & self::COMMAND_LASTLINE)) { $response = preg_replace("/^$tag (OK|NO|BAD|BYE|PREAUTH)?\s*(\[[a-z-]+\])?\s*/i", '', trim($line)); } return $noresp ? $code : array($code, $response); }
[ "public", "function", "execute", "(", "$", "command", ",", "$", "arguments", "=", "array", "(", ")", ",", "$", "options", "=", "0", ",", "$", "filter", "=", "null", ")", "{", "$", "tag", "=", "$", "this", "->", "nextTag", "(", ")", ";", "$", "query", "=", "$", "tag", ".", "' '", ".", "$", "command", ";", "$", "noresp", "=", "(", "$", "options", "&", "self", "::", "COMMAND_NORESPONSE", ")", ";", "$", "response", "=", "$", "noresp", "?", "null", ":", "''", ";", "if", "(", "!", "empty", "(", "$", "arguments", ")", ")", "{", "foreach", "(", "$", "arguments", "as", "$", "arg", ")", "{", "$", "query", ".=", "' '", ".", "self", "::", "r_implode", "(", "$", "arg", ")", ";", "}", "}", "// Send command", "if", "(", "!", "$", "this", "->", "putLineC", "(", "$", "query", ",", "true", ",", "(", "$", "options", "&", "self", "::", "COMMAND_ANONYMIZED", ")", ")", ")", "{", "preg_match", "(", "'/^[A-Z0-9]+ ((UID )?[A-Z]+)/'", ",", "$", "query", ",", "$", "matches", ")", ";", "$", "cmd", "=", "$", "matches", "[", "1", "]", "?", ":", "'UNKNOWN'", ";", "$", "this", "->", "setError", "(", "self", "::", "ERROR_COMMAND", ",", "\"Failed to send $cmd command\"", ")", ";", "return", "$", "noresp", "?", "self", "::", "ERROR_COMMAND", ":", "array", "(", "self", "::", "ERROR_COMMAND", ",", "''", ")", ";", "}", "// Parse response", "do", "{", "$", "line", "=", "$", "this", "->", "readLine", "(", "4096", ")", ";", "if", "(", "$", "response", "!==", "null", ")", "{", "// TODO: Better string literals handling with filter", "if", "(", "!", "$", "filter", "||", "preg_match", "(", "$", "filter", ",", "$", "line", ")", ")", "{", "$", "response", ".=", "$", "line", ";", "}", "}", "// parse untagged response for [COPYUID 1204196876 3456:3457 123:124] (RFC6851)", "if", "(", "$", "line", "&&", "$", "command", "==", "'UID MOVE'", ")", "{", "if", "(", "preg_match", "(", "\"/^\\* OK \\[COPYUID [0-9]+ ([0-9,:]+) ([0-9,:]+)\\]/i\"", ",", "$", "line", ",", "$", "m", ")", ")", "{", "$", "this", "->", "data", "[", "'COPYUID'", "]", "=", "array", "(", "$", "m", "[", "1", "]", ",", "$", "m", "[", "2", "]", ")", ";", "}", "}", "}", "while", "(", "!", "$", "this", "->", "startsWith", "(", "$", "line", ",", "$", "tag", ".", "' '", ",", "true", ",", "true", ")", ")", ";", "$", "code", "=", "$", "this", "->", "parseResult", "(", "$", "line", ",", "$", "command", ".", "': '", ")", ";", "// Remove last line from response", "if", "(", "$", "response", ")", "{", "if", "(", "!", "$", "filter", ")", "{", "$", "line_len", "=", "min", "(", "strlen", "(", "$", "response", ")", ",", "strlen", "(", "$", "line", ")", ")", ";", "$", "response", "=", "substr", "(", "$", "response", ",", "0", ",", "-", "$", "line_len", ")", ";", "}", "$", "response", "=", "rtrim", "(", "$", "response", ",", "\"\\r\\n\"", ")", ";", "}", "// optional CAPABILITY response", "if", "(", "(", "$", "options", "&", "self", "::", "COMMAND_CAPABILITY", ")", "&&", "$", "code", "==", "self", "::", "ERROR_OK", "&&", "preg_match", "(", "'/\\[CAPABILITY ([^]]+)\\]/i'", ",", "$", "line", ",", "$", "matches", ")", ")", "{", "$", "this", "->", "parseCapability", "(", "$", "matches", "[", "1", "]", ",", "true", ")", ";", "}", "// return last line only (without command tag, result and response code)", "if", "(", "$", "line", "&&", "(", "$", "options", "&", "self", "::", "COMMAND_LASTLINE", ")", ")", "{", "$", "response", "=", "preg_replace", "(", "\"/^$tag (OK|NO|BAD|BYE|PREAUTH)?\\s*(\\[[a-z-]+\\])?\\s*/i\"", ",", "''", ",", "trim", "(", "$", "line", ")", ")", ";", "}", "return", "$", "noresp", "?", "$", "code", ":", "array", "(", "$", "code", ",", "$", "response", ")", ";", "}" ]
Sends IMAP command and parses result @param string $command IMAP command @param array $arguments Command arguments @param int $options Execution options @param string $filter Line filter (regexp) @return mixed Response code or list of response code and data @since 0.5-beta
[ "Sends", "IMAP", "command", "and", "parses", "result" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L3710-L3777
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.tokenizeResponse
public static function tokenizeResponse(&$str, $num=0) { $result = array(); while (!$num || count($result) < $num) { // remove spaces from the beginning of the string $str = ltrim($str); switch ($str[0]) { // String literal case '{': if (($epos = strpos($str, "}\r\n", 1)) == false) { // error } if (!is_numeric(($bytes = substr($str, 1, $epos - 1)))) { // error } $result[] = $bytes ? substr($str, $epos + 3, $bytes) : ''; $str = substr($str, $epos + 3 + $bytes); break; // Quoted string case '"': $len = strlen($str); for ($pos=1; $pos<$len; $pos++) { if ($str[$pos] == '"') { break; } if ($str[$pos] == "\\") { if ($str[$pos + 1] == '"' || $str[$pos + 1] == "\\") { $pos++; } } } // we need to strip slashes for a quoted string $result[] = stripslashes(substr($str, 1, $pos - 1)); $str = substr($str, $pos + 1); break; // Parenthesized list case '(': $str = substr($str, 1); $result[] = self::tokenizeResponse($str); break; case ')': $str = substr($str, 1); return $result; // String atom, number, astring, NIL, *, % default: // empty string if ($str === '' || $str === null) { break 2; } // excluded chars: SP, CTL, ), DEL // we do not exclude [ and ] (#1489223) if (preg_match('/^([^\x00-\x20\x29\x7F]+)/', $str, $m)) { $result[] = $m[1] == 'NIL' ? null : $m[1]; $str = substr($str, strlen($m[1])); } break; } } return $num == 1 ? $result[0] : $result; }
php
public static function tokenizeResponse(&$str, $num=0) { $result = array(); while (!$num || count($result) < $num) { // remove spaces from the beginning of the string $str = ltrim($str); switch ($str[0]) { // String literal case '{': if (($epos = strpos($str, "}\r\n", 1)) == false) { // error } if (!is_numeric(($bytes = substr($str, 1, $epos - 1)))) { // error } $result[] = $bytes ? substr($str, $epos + 3, $bytes) : ''; $str = substr($str, $epos + 3 + $bytes); break; // Quoted string case '"': $len = strlen($str); for ($pos=1; $pos<$len; $pos++) { if ($str[$pos] == '"') { break; } if ($str[$pos] == "\\") { if ($str[$pos + 1] == '"' || $str[$pos + 1] == "\\") { $pos++; } } } // we need to strip slashes for a quoted string $result[] = stripslashes(substr($str, 1, $pos - 1)); $str = substr($str, $pos + 1); break; // Parenthesized list case '(': $str = substr($str, 1); $result[] = self::tokenizeResponse($str); break; case ')': $str = substr($str, 1); return $result; // String atom, number, astring, NIL, *, % default: // empty string if ($str === '' || $str === null) { break 2; } // excluded chars: SP, CTL, ), DEL // we do not exclude [ and ] (#1489223) if (preg_match('/^([^\x00-\x20\x29\x7F]+)/', $str, $m)) { $result[] = $m[1] == 'NIL' ? null : $m[1]; $str = substr($str, strlen($m[1])); } break; } } return $num == 1 ? $result[0] : $result; }
[ "public", "static", "function", "tokenizeResponse", "(", "&", "$", "str", ",", "$", "num", "=", "0", ")", "{", "$", "result", "=", "array", "(", ")", ";", "while", "(", "!", "$", "num", "||", "count", "(", "$", "result", ")", "<", "$", "num", ")", "{", "// remove spaces from the beginning of the string", "$", "str", "=", "ltrim", "(", "$", "str", ")", ";", "switch", "(", "$", "str", "[", "0", "]", ")", "{", "// String literal", "case", "'{'", ":", "if", "(", "(", "$", "epos", "=", "strpos", "(", "$", "str", ",", "\"}\\r\\n\"", ",", "1", ")", ")", "==", "false", ")", "{", "// error", "}", "if", "(", "!", "is_numeric", "(", "(", "$", "bytes", "=", "substr", "(", "$", "str", ",", "1", ",", "$", "epos", "-", "1", ")", ")", ")", ")", "{", "// error", "}", "$", "result", "[", "]", "=", "$", "bytes", "?", "substr", "(", "$", "str", ",", "$", "epos", "+", "3", ",", "$", "bytes", ")", ":", "''", ";", "$", "str", "=", "substr", "(", "$", "str", ",", "$", "epos", "+", "3", "+", "$", "bytes", ")", ";", "break", ";", "// Quoted string", "case", "'\"'", ":", "$", "len", "=", "strlen", "(", "$", "str", ")", ";", "for", "(", "$", "pos", "=", "1", ";", "$", "pos", "<", "$", "len", ";", "$", "pos", "++", ")", "{", "if", "(", "$", "str", "[", "$", "pos", "]", "==", "'\"'", ")", "{", "break", ";", "}", "if", "(", "$", "str", "[", "$", "pos", "]", "==", "\"\\\\\"", ")", "{", "if", "(", "$", "str", "[", "$", "pos", "+", "1", "]", "==", "'\"'", "||", "$", "str", "[", "$", "pos", "+", "1", "]", "==", "\"\\\\\"", ")", "{", "$", "pos", "++", ";", "}", "}", "}", "// we need to strip slashes for a quoted string", "$", "result", "[", "]", "=", "stripslashes", "(", "substr", "(", "$", "str", ",", "1", ",", "$", "pos", "-", "1", ")", ")", ";", "$", "str", "=", "substr", "(", "$", "str", ",", "$", "pos", "+", "1", ")", ";", "break", ";", "// Parenthesized list", "case", "'('", ":", "$", "str", "=", "substr", "(", "$", "str", ",", "1", ")", ";", "$", "result", "[", "]", "=", "self", "::", "tokenizeResponse", "(", "$", "str", ")", ";", "break", ";", "case", "')'", ":", "$", "str", "=", "substr", "(", "$", "str", ",", "1", ")", ";", "return", "$", "result", ";", "// String atom, number, astring, NIL, *, %", "default", ":", "// empty string", "if", "(", "$", "str", "===", "''", "||", "$", "str", "===", "null", ")", "{", "break", "2", ";", "}", "// excluded chars: SP, CTL, ), DEL", "// we do not exclude [ and ] (#1489223)", "if", "(", "preg_match", "(", "'/^([^\\x00-\\x20\\x29\\x7F]+)/'", ",", "$", "str", ",", "$", "m", ")", ")", "{", "$", "result", "[", "]", "=", "$", "m", "[", "1", "]", "==", "'NIL'", "?", "null", ":", "$", "m", "[", "1", "]", ";", "$", "str", "=", "substr", "(", "$", "str", ",", "strlen", "(", "$", "m", "[", "1", "]", ")", ")", ";", "}", "break", ";", "}", "}", "return", "$", "num", "==", "1", "?", "$", "result", "[", "0", "]", ":", "$", "result", ";", "}" ]
Splits IMAP response into string tokens @param string &$str The IMAP's server response @param int $num Number of tokens to return @return mixed Tokens array or string if $num=1 @since 0.5-beta
[ "Splits", "IMAP", "response", "into", "string", "tokens" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L3788-L3859
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.compressMessageSet
public static function compressMessageSet($messages, $force=false) { // given a comma delimited list of independent mid's, // compresses by grouping sequences together if (!is_array($messages)) { // if less than 255 bytes long, let's not bother if (!$force && strlen($messages) < 255) { return preg_match('/[^0-9:,*]/', $messages) ? 'INVALID' : $messages; } // see if it's already been compressed if (strpos($messages, ':') !== false) { return preg_match('/[^0-9:,*]/', $messages) ? 'INVALID' : $messages; } // separate, then sort $messages = explode(',', $messages); } sort($messages); $result = array(); $start = $prev = $messages[0]; foreach ($messages as $id) { $incr = $id - $prev; if ($incr > 1) { // found a gap if ($start == $prev) { $result[] = $prev; // push single id } else { $result[] = $start . ':' . $prev; // push sequence as start_id:end_id } $start = $id; // start of new sequence } $prev = $id; } // handle the last sequence/id if ($start == $prev) { $result[] = $prev; } else { $result[] = $start.':'.$prev; } // return as comma separated string $result = implode(',', $result); return preg_match('/[^0-9:,*]/', $result) ? 'INVALID' : $result; }
php
public static function compressMessageSet($messages, $force=false) { // given a comma delimited list of independent mid's, // compresses by grouping sequences together if (!is_array($messages)) { // if less than 255 bytes long, let's not bother if (!$force && strlen($messages) < 255) { return preg_match('/[^0-9:,*]/', $messages) ? 'INVALID' : $messages; } // see if it's already been compressed if (strpos($messages, ':') !== false) { return preg_match('/[^0-9:,*]/', $messages) ? 'INVALID' : $messages; } // separate, then sort $messages = explode(',', $messages); } sort($messages); $result = array(); $start = $prev = $messages[0]; foreach ($messages as $id) { $incr = $id - $prev; if ($incr > 1) { // found a gap if ($start == $prev) { $result[] = $prev; // push single id } else { $result[] = $start . ':' . $prev; // push sequence as start_id:end_id } $start = $id; // start of new sequence } $prev = $id; } // handle the last sequence/id if ($start == $prev) { $result[] = $prev; } else { $result[] = $start.':'.$prev; } // return as comma separated string $result = implode(',', $result); return preg_match('/[^0-9:,*]/', $result) ? 'INVALID' : $result; }
[ "public", "static", "function", "compressMessageSet", "(", "$", "messages", ",", "$", "force", "=", "false", ")", "{", "// given a comma delimited list of independent mid's,", "// compresses by grouping sequences together", "if", "(", "!", "is_array", "(", "$", "messages", ")", ")", "{", "// if less than 255 bytes long, let's not bother", "if", "(", "!", "$", "force", "&&", "strlen", "(", "$", "messages", ")", "<", "255", ")", "{", "return", "preg_match", "(", "'/[^0-9:,*]/'", ",", "$", "messages", ")", "?", "'INVALID'", ":", "$", "messages", ";", "}", "// see if it's already been compressed", "if", "(", "strpos", "(", "$", "messages", ",", "':'", ")", "!==", "false", ")", "{", "return", "preg_match", "(", "'/[^0-9:,*]/'", ",", "$", "messages", ")", "?", "'INVALID'", ":", "$", "messages", ";", "}", "// separate, then sort", "$", "messages", "=", "explode", "(", "','", ",", "$", "messages", ")", ";", "}", "sort", "(", "$", "messages", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "start", "=", "$", "prev", "=", "$", "messages", "[", "0", "]", ";", "foreach", "(", "$", "messages", "as", "$", "id", ")", "{", "$", "incr", "=", "$", "id", "-", "$", "prev", ";", "if", "(", "$", "incr", ">", "1", ")", "{", "// found a gap", "if", "(", "$", "start", "==", "$", "prev", ")", "{", "$", "result", "[", "]", "=", "$", "prev", ";", "// push single id", "}", "else", "{", "$", "result", "[", "]", "=", "$", "start", ".", "':'", ".", "$", "prev", ";", "// push sequence as start_id:end_id", "}", "$", "start", "=", "$", "id", ";", "// start of new sequence", "}", "$", "prev", "=", "$", "id", ";", "}", "// handle the last sequence/id", "if", "(", "$", "start", "==", "$", "prev", ")", "{", "$", "result", "[", "]", "=", "$", "prev", ";", "}", "else", "{", "$", "result", "[", "]", "=", "$", "start", ".", "':'", ".", "$", "prev", ";", "}", "// return as comma separated string", "$", "result", "=", "implode", "(", "','", ",", "$", "result", ")", ";", "return", "preg_match", "(", "'/[^0-9:,*]/'", ",", "$", "result", ")", "?", "'INVALID'", ":", "$", "result", ";", "}" ]
Converts message identifiers array into sequence-set syntax @param array $messages Message identifiers @param bool $force Forces compression of any size @return string Compressed sequence-set
[ "Converts", "message", "identifiers", "array", "into", "sequence", "-", "set", "syntax" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L3889-L3939
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.uncompressMessageSet
public static function uncompressMessageSet($messages) { if (empty($messages)) { return array(); } $result = array(); $messages = explode(',', $messages); foreach ($messages as $idx => $part) { $items = explode(':', $part); $max = max($items[0], $items[1]); for ($x=$items[0]; $x<=$max; $x++) { $result[] = (int)$x; } unset($messages[$idx]); } return $result; }
php
public static function uncompressMessageSet($messages) { if (empty($messages)) { return array(); } $result = array(); $messages = explode(',', $messages); foreach ($messages as $idx => $part) { $items = explode(':', $part); $max = max($items[0], $items[1]); for ($x=$items[0]; $x<=$max; $x++) { $result[] = (int)$x; } unset($messages[$idx]); } return $result; }
[ "public", "static", "function", "uncompressMessageSet", "(", "$", "messages", ")", "{", "if", "(", "empty", "(", "$", "messages", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "messages", "=", "explode", "(", "','", ",", "$", "messages", ")", ";", "foreach", "(", "$", "messages", "as", "$", "idx", "=>", "$", "part", ")", "{", "$", "items", "=", "explode", "(", "':'", ",", "$", "part", ")", ";", "$", "max", "=", "max", "(", "$", "items", "[", "0", "]", ",", "$", "items", "[", "1", "]", ")", ";", "for", "(", "$", "x", "=", "$", "items", "[", "0", "]", ";", "$", "x", "<=", "$", "max", ";", "$", "x", "++", ")", "{", "$", "result", "[", "]", "=", "(", "int", ")", "$", "x", ";", "}", "unset", "(", "$", "messages", "[", "$", "idx", "]", ")", ";", "}", "return", "$", "result", ";", "}" ]
Converts message sequence-set into array @param string $messages Message identifiers @return array List of message identifiers
[ "Converts", "message", "sequence", "-", "set", "into", "array" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L3948-L3968
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.clear_status_cache
protected function clear_status_cache($mailbox) { unset($this->data['STATUS:' . $mailbox]); $keys = array('EXISTS', 'RECENT', 'UNSEEN', 'UID-MAP'); foreach ($keys as $key) { unset($this->data[$key]); } }
php
protected function clear_status_cache($mailbox) { unset($this->data['STATUS:' . $mailbox]); $keys = array('EXISTS', 'RECENT', 'UNSEEN', 'UID-MAP'); foreach ($keys as $key) { unset($this->data[$key]); } }
[ "protected", "function", "clear_status_cache", "(", "$", "mailbox", ")", "{", "unset", "(", "$", "this", "->", "data", "[", "'STATUS:'", ".", "$", "mailbox", "]", ")", ";", "$", "keys", "=", "array", "(", "'EXISTS'", ",", "'RECENT'", ",", "'UNSEEN'", ",", "'UID-MAP'", ")", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "unset", "(", "$", "this", "->", "data", "[", "$", "key", "]", ")", ";", "}", "}" ]
Clear internal status cache
[ "Clear", "internal", "status", "cache" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L3973-L3982
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.clear_mailbox_cache
protected function clear_mailbox_cache() { $this->clear_status_cache($this->selected); $keys = array('UIDNEXT', 'UIDVALIDITY', 'HIGHESTMODSEQ', 'NOMODSEQ', 'PERMANENTFLAGS', 'QRESYNC', 'VANISHED', 'READ-WRITE'); foreach ($keys as $key) { unset($this->data[$key]); } }
php
protected function clear_mailbox_cache() { $this->clear_status_cache($this->selected); $keys = array('UIDNEXT', 'UIDVALIDITY', 'HIGHESTMODSEQ', 'NOMODSEQ', 'PERMANENTFLAGS', 'QRESYNC', 'VANISHED', 'READ-WRITE'); foreach ($keys as $key) { unset($this->data[$key]); } }
[ "protected", "function", "clear_mailbox_cache", "(", ")", "{", "$", "this", "->", "clear_status_cache", "(", "$", "this", "->", "selected", ")", ";", "$", "keys", "=", "array", "(", "'UIDNEXT'", ",", "'UIDVALIDITY'", ",", "'HIGHESTMODSEQ'", ",", "'NOMODSEQ'", ",", "'PERMANENTFLAGS'", ",", "'QRESYNC'", ",", "'VANISHED'", ",", "'READ-WRITE'", ")", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "unset", "(", "$", "this", "->", "data", "[", "$", "key", "]", ")", ";", "}", "}" ]
Clear internal cache of the current mailbox
[ "Clear", "internal", "cache", "of", "the", "current", "mailbox" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L3987-L3997
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.flagsToStr
protected function flagsToStr($flags) { foreach ((array)$flags as $idx => $flag) { if ($flag = $this->flags[strtoupper($flag)]) { $flags[$idx] = $flag; } } return implode(' ', (array)$flags); }
php
protected function flagsToStr($flags) { foreach ((array)$flags as $idx => $flag) { if ($flag = $this->flags[strtoupper($flag)]) { $flags[$idx] = $flag; } } return implode(' ', (array)$flags); }
[ "protected", "function", "flagsToStr", "(", "$", "flags", ")", "{", "foreach", "(", "(", "array", ")", "$", "flags", "as", "$", "idx", "=>", "$", "flag", ")", "{", "if", "(", "$", "flag", "=", "$", "this", "->", "flags", "[", "strtoupper", "(", "$", "flag", ")", "]", ")", "{", "$", "flags", "[", "$", "idx", "]", "=", "$", "flag", ";", "}", "}", "return", "implode", "(", "' '", ",", "(", "array", ")", "$", "flags", ")", ";", "}" ]
Converts flags array into string for inclusion in IMAP command @param array $flags Flags (see self::flags) @return string Space-separated list of flags
[ "Converts", "flags", "array", "into", "string", "for", "inclusion", "in", "IMAP", "command" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L4006-L4015
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
rcube_imap_generic.parseCapability
protected function parseCapability($str, $trusted=false) { $str = preg_replace('/^\* CAPABILITY /i', '', $str); $this->capability = explode(' ', strtoupper($str)); if (!empty($this->prefs['disabled_caps'])) { $this->capability = array_diff($this->capability, $this->prefs['disabled_caps']); } if (!isset($this->prefs['literal+']) && in_array('LITERAL+', $this->capability)) { $this->prefs['literal+'] = true; } if ($trusted) { $this->capability_readed = true; } }
php
protected function parseCapability($str, $trusted=false) { $str = preg_replace('/^\* CAPABILITY /i', '', $str); $this->capability = explode(' ', strtoupper($str)); if (!empty($this->prefs['disabled_caps'])) { $this->capability = array_diff($this->capability, $this->prefs['disabled_caps']); } if (!isset($this->prefs['literal+']) && in_array('LITERAL+', $this->capability)) { $this->prefs['literal+'] = true; } if ($trusted) { $this->capability_readed = true; } }
[ "protected", "function", "parseCapability", "(", "$", "str", ",", "$", "trusted", "=", "false", ")", "{", "$", "str", "=", "preg_replace", "(", "'/^\\* CAPABILITY /i'", ",", "''", ",", "$", "str", ")", ";", "$", "this", "->", "capability", "=", "explode", "(", "' '", ",", "strtoupper", "(", "$", "str", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "prefs", "[", "'disabled_caps'", "]", ")", ")", "{", "$", "this", "->", "capability", "=", "array_diff", "(", "$", "this", "->", "capability", ",", "$", "this", "->", "prefs", "[", "'disabled_caps'", "]", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "prefs", "[", "'literal+'", "]", ")", "&&", "in_array", "(", "'LITERAL+'", ",", "$", "this", "->", "capability", ")", ")", "{", "$", "this", "->", "prefs", "[", "'literal+'", "]", "=", "true", ";", "}", "if", "(", "$", "trusted", ")", "{", "$", "this", "->", "capability_readed", "=", "true", ";", "}", "}" ]
CAPABILITY response parser
[ "CAPABILITY", "response", "parser" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php#L4020-L4037
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_plugin_api.php
rcube_plugin_api.init
public function init($app, $task = '') { $this->task = $task; $this->output = $app->output; // register an internal hook $this->register_hook('template_container', array($this, 'template_container_hook')); // maybe also register a shudown function which triggers // shutdown functions of all plugin objects foreach ($this->plugins as $plugin) { // ... task, request type and framed mode if (!$this->plugins_initialized[$plugin->ID] && !$this->filter($plugin)) { $plugin->init(); $this->plugins_initialized[$plugin->ID] = $plugin; } } // we have finished initializing all plugins $this->initialized = true; }
php
public function init($app, $task = '') { $this->task = $task; $this->output = $app->output; // register an internal hook $this->register_hook('template_container', array($this, 'template_container_hook')); // maybe also register a shudown function which triggers // shutdown functions of all plugin objects foreach ($this->plugins as $plugin) { // ... task, request type and framed mode if (!$this->plugins_initialized[$plugin->ID] && !$this->filter($plugin)) { $plugin->init(); $this->plugins_initialized[$plugin->ID] = $plugin; } } // we have finished initializing all plugins $this->initialized = true; }
[ "public", "function", "init", "(", "$", "app", ",", "$", "task", "=", "''", ")", "{", "$", "this", "->", "task", "=", "$", "task", ";", "$", "this", "->", "output", "=", "$", "app", "->", "output", ";", "// register an internal hook", "$", "this", "->", "register_hook", "(", "'template_container'", ",", "array", "(", "$", "this", ",", "'template_container_hook'", ")", ")", ";", "// maybe also register a shudown function which triggers", "// shutdown functions of all plugin objects", "foreach", "(", "$", "this", "->", "plugins", "as", "$", "plugin", ")", "{", "// ... task, request type and framed mode", "if", "(", "!", "$", "this", "->", "plugins_initialized", "[", "$", "plugin", "->", "ID", "]", "&&", "!", "$", "this", "->", "filter", "(", "$", "plugin", ")", ")", "{", "$", "plugin", "->", "init", "(", ")", ";", "$", "this", "->", "plugins_initialized", "[", "$", "plugin", "->", "ID", "]", "=", "$", "plugin", ";", "}", "}", "// we have finished initializing all plugins", "$", "this", "->", "initialized", "=", "true", ";", "}" ]
Initialize plugin engine This has to be done after rcmail::load_gui() or rcmail::json_init() was called because plugins need to have access to rcmail->output @param object rcube Instance of the rcube base class @param string Current application task (used for conditional plugin loading)
[ "Initialize", "plugin", "engine" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_plugin_api.php#L87-L106
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_plugin_api.php
rcube_plugin_api.load_plugins
public function load_plugins($plugins_enabled, $required_plugins = array()) { foreach ($plugins_enabled as $plugin_name) { $this->load_plugin($plugin_name); } // check existance of all required core plugins foreach ($required_plugins as $plugin_name) { $loaded = false; foreach ($this->plugins as $plugin) { if ($plugin instanceof $plugin_name) { $loaded = true; break; } } // load required core plugin if no derivate was found if (!$loaded) { $loaded = $this->load_plugin($plugin_name); } // trigger fatal error if still not loaded if (!$loaded) { rcube::raise_error(array( 'code' => 520, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Requried plugin $plugin_name was not loaded"), true, true); } } }
php
public function load_plugins($plugins_enabled, $required_plugins = array()) { foreach ($plugins_enabled as $plugin_name) { $this->load_plugin($plugin_name); } // check existance of all required core plugins foreach ($required_plugins as $plugin_name) { $loaded = false; foreach ($this->plugins as $plugin) { if ($plugin instanceof $plugin_name) { $loaded = true; break; } } // load required core plugin if no derivate was found if (!$loaded) { $loaded = $this->load_plugin($plugin_name); } // trigger fatal error if still not loaded if (!$loaded) { rcube::raise_error(array( 'code' => 520, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Requried plugin $plugin_name was not loaded"), true, true); } } }
[ "public", "function", "load_plugins", "(", "$", "plugins_enabled", ",", "$", "required_plugins", "=", "array", "(", ")", ")", "{", "foreach", "(", "$", "plugins_enabled", "as", "$", "plugin_name", ")", "{", "$", "this", "->", "load_plugin", "(", "$", "plugin_name", ")", ";", "}", "// check existance of all required core plugins", "foreach", "(", "$", "required_plugins", "as", "$", "plugin_name", ")", "{", "$", "loaded", "=", "false", ";", "foreach", "(", "$", "this", "->", "plugins", "as", "$", "plugin", ")", "{", "if", "(", "$", "plugin", "instanceof", "$", "plugin_name", ")", "{", "$", "loaded", "=", "true", ";", "break", ";", "}", "}", "// load required core plugin if no derivate was found", "if", "(", "!", "$", "loaded", ")", "{", "$", "loaded", "=", "$", "this", "->", "load_plugin", "(", "$", "plugin_name", ")", ";", "}", "// trigger fatal error if still not loaded", "if", "(", "!", "$", "loaded", ")", "{", "rcube", "::", "raise_error", "(", "array", "(", "'code'", "=>", "520", ",", "'type'", "=>", "'php'", ",", "'file'", "=>", "__FILE__", ",", "'line'", "=>", "__LINE__", ",", "'message'", "=>", "\"Requried plugin $plugin_name was not loaded\"", ")", ",", "true", ",", "true", ")", ";", "}", "}", "}" ]
Load and init all enabled plugins This has to be done after rcmail::load_gui() or rcmail::json_init() was called because plugins need to have access to rcmail->output @param array List of configured plugins to load @param array List of plugins required by the application
[ "Load", "and", "init", "all", "enabled", "plugins" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_plugin_api.php#L117-L146
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_plugin_api.php
rcube_plugin_api.load_plugin
public function load_plugin($plugin_name, $force = false, $require = true) { static $plugins_dir; if (!$plugins_dir) { $dir = dir($this->dir); $plugins_dir = unslashify($dir->path); } // plugin already loaded? if (!$this->plugins[$plugin_name]) { $fn = "$plugins_dir/$plugin_name/$plugin_name.php"; if (!is_readable($fn)) { if ($require) { rcube::raise_error(array('code' => 520, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Failed to load plugin file $fn"), true, false); } return false; } if (!class_exists($plugin_name, false)) { include $fn; } // instantiate class if exists if (!class_exists($plugin_name, false)) { rcube::raise_error(array('code' => 520, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "No plugin class $plugin_name found in $fn"), true, false); return false; } $plugin = new $plugin_name($this); $this->active_plugins[] = $plugin_name; // check inheritance... if (is_subclass_of($plugin, 'rcube_plugin')) { // call onload method on plugin if it exists. // this is useful if you want to be called early in the boot process if (method_exists($plugin, 'onload')) { $plugin->onload(); } if (!empty($plugin->allowed_prefs)) { $this->allowed_prefs = array_merge($this->allowed_prefs, $plugin->allowed_prefs); } $this->plugins[$plugin_name] = $plugin; } } if ($plugin = $this->plugins[$plugin_name]) { // init a plugin only if $force is set or if we're called after initialization if (($force || $this->initialized) && !$this->plugins_initialized[$plugin_name] && ($force || !$this->filter($plugin))) { $plugin->init(); $this->plugins_initialized[$plugin_name] = $plugin; } } return true; }
php
public function load_plugin($plugin_name, $force = false, $require = true) { static $plugins_dir; if (!$plugins_dir) { $dir = dir($this->dir); $plugins_dir = unslashify($dir->path); } // plugin already loaded? if (!$this->plugins[$plugin_name]) { $fn = "$plugins_dir/$plugin_name/$plugin_name.php"; if (!is_readable($fn)) { if ($require) { rcube::raise_error(array('code' => 520, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Failed to load plugin file $fn"), true, false); } return false; } if (!class_exists($plugin_name, false)) { include $fn; } // instantiate class if exists if (!class_exists($plugin_name, false)) { rcube::raise_error(array('code' => 520, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "No plugin class $plugin_name found in $fn"), true, false); return false; } $plugin = new $plugin_name($this); $this->active_plugins[] = $plugin_name; // check inheritance... if (is_subclass_of($plugin, 'rcube_plugin')) { // call onload method on plugin if it exists. // this is useful if you want to be called early in the boot process if (method_exists($plugin, 'onload')) { $plugin->onload(); } if (!empty($plugin->allowed_prefs)) { $this->allowed_prefs = array_merge($this->allowed_prefs, $plugin->allowed_prefs); } $this->plugins[$plugin_name] = $plugin; } } if ($plugin = $this->plugins[$plugin_name]) { // init a plugin only if $force is set or if we're called after initialization if (($force || $this->initialized) && !$this->plugins_initialized[$plugin_name] && ($force || !$this->filter($plugin))) { $plugin->init(); $this->plugins_initialized[$plugin_name] = $plugin; } } return true; }
[ "public", "function", "load_plugin", "(", "$", "plugin_name", ",", "$", "force", "=", "false", ",", "$", "require", "=", "true", ")", "{", "static", "$", "plugins_dir", ";", "if", "(", "!", "$", "plugins_dir", ")", "{", "$", "dir", "=", "dir", "(", "$", "this", "->", "dir", ")", ";", "$", "plugins_dir", "=", "unslashify", "(", "$", "dir", "->", "path", ")", ";", "}", "// plugin already loaded?", "if", "(", "!", "$", "this", "->", "plugins", "[", "$", "plugin_name", "]", ")", "{", "$", "fn", "=", "\"$plugins_dir/$plugin_name/$plugin_name.php\"", ";", "if", "(", "!", "is_readable", "(", "$", "fn", ")", ")", "{", "if", "(", "$", "require", ")", "{", "rcube", "::", "raise_error", "(", "array", "(", "'code'", "=>", "520", ",", "'type'", "=>", "'php'", ",", "'file'", "=>", "__FILE__", ",", "'line'", "=>", "__LINE__", ",", "'message'", "=>", "\"Failed to load plugin file $fn\"", ")", ",", "true", ",", "false", ")", ";", "}", "return", "false", ";", "}", "if", "(", "!", "class_exists", "(", "$", "plugin_name", ",", "false", ")", ")", "{", "include", "$", "fn", ";", "}", "// instantiate class if exists", "if", "(", "!", "class_exists", "(", "$", "plugin_name", ",", "false", ")", ")", "{", "rcube", "::", "raise_error", "(", "array", "(", "'code'", "=>", "520", ",", "'type'", "=>", "'php'", ",", "'file'", "=>", "__FILE__", ",", "'line'", "=>", "__LINE__", ",", "'message'", "=>", "\"No plugin class $plugin_name found in $fn\"", ")", ",", "true", ",", "false", ")", ";", "return", "false", ";", "}", "$", "plugin", "=", "new", "$", "plugin_name", "(", "$", "this", ")", ";", "$", "this", "->", "active_plugins", "[", "]", "=", "$", "plugin_name", ";", "// check inheritance...", "if", "(", "is_subclass_of", "(", "$", "plugin", ",", "'rcube_plugin'", ")", ")", "{", "// call onload method on plugin if it exists.", "// this is useful if you want to be called early in the boot process", "if", "(", "method_exists", "(", "$", "plugin", ",", "'onload'", ")", ")", "{", "$", "plugin", "->", "onload", "(", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "plugin", "->", "allowed_prefs", ")", ")", "{", "$", "this", "->", "allowed_prefs", "=", "array_merge", "(", "$", "this", "->", "allowed_prefs", ",", "$", "plugin", "->", "allowed_prefs", ")", ";", "}", "$", "this", "->", "plugins", "[", "$", "plugin_name", "]", "=", "$", "plugin", ";", "}", "}", "if", "(", "$", "plugin", "=", "$", "this", "->", "plugins", "[", "$", "plugin_name", "]", ")", "{", "// init a plugin only if $force is set or if we're called after initialization", "if", "(", "(", "$", "force", "||", "$", "this", "->", "initialized", ")", "&&", "!", "$", "this", "->", "plugins_initialized", "[", "$", "plugin_name", "]", "&&", "(", "$", "force", "||", "!", "$", "this", "->", "filter", "(", "$", "plugin", ")", ")", ")", "{", "$", "plugin", "->", "init", "(", ")", ";", "$", "this", "->", "plugins_initialized", "[", "$", "plugin_name", "]", "=", "$", "plugin", ";", "}", "}", "return", "true", ";", "}" ]
Load the specified plugin @param string Plugin name @param boolean Force loading of the plugin even if it doesn't match the filter @param boolean Require loading of the plugin, error if it doesn't exist @return boolean True on success, false if not loaded or failure
[ "Load", "the", "specified", "plugin" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_plugin_api.php#L157-L222
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_plugin_api.php
rcube_plugin_api.filter
private function filter($plugin) { return ($plugin->noajax && !(is_object($this->output) && $this->output->type == 'html')) || ($plugin->task && !preg_match('/^('.$plugin->task.')$/i', $this->task)) || ($plugin->noframe && !empty($_REQUEST['_framed'])); }
php
private function filter($plugin) { return ($plugin->noajax && !(is_object($this->output) && $this->output->type == 'html')) || ($plugin->task && !preg_match('/^('.$plugin->task.')$/i', $this->task)) || ($plugin->noframe && !empty($_REQUEST['_framed'])); }
[ "private", "function", "filter", "(", "$", "plugin", ")", "{", "return", "(", "$", "plugin", "->", "noajax", "&&", "!", "(", "is_object", "(", "$", "this", "->", "output", ")", "&&", "$", "this", "->", "output", "->", "type", "==", "'html'", ")", ")", "||", "(", "$", "plugin", "->", "task", "&&", "!", "preg_match", "(", "'/^('", ".", "$", "plugin", "->", "task", ".", "')$/i'", ",", "$", "this", "->", "task", ")", ")", "||", "(", "$", "plugin", "->", "noframe", "&&", "!", "empty", "(", "$", "_REQUEST", "[", "'_framed'", "]", ")", ")", ";", "}" ]
check if we should prevent this plugin from initialising @param $plugin @return bool
[ "check", "if", "we", "should", "prevent", "this", "plugin", "from", "initialising" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_plugin_api.php#L230-L235
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_plugin_api.php
rcube_plugin_api.register_hook
public function register_hook($hook, $callback) { if (is_callable($callback)) { if (isset($this->deprecated_hooks[$hook])) { rcube::raise_error(array('code' => 522, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Deprecated hook name. " . $hook . ' -> ' . $this->deprecated_hooks[$hook]), true, false); $hook = $this->deprecated_hooks[$hook]; } $this->handlers[$hook][] = $callback; } else { rcube::raise_error(array('code' => 521, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Invalid callback function for $hook"), true, false); } }
php
public function register_hook($hook, $callback) { if (is_callable($callback)) { if (isset($this->deprecated_hooks[$hook])) { rcube::raise_error(array('code' => 522, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Deprecated hook name. " . $hook . ' -> ' . $this->deprecated_hooks[$hook]), true, false); $hook = $this->deprecated_hooks[$hook]; } $this->handlers[$hook][] = $callback; } else { rcube::raise_error(array('code' => 521, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Invalid callback function for $hook"), true, false); } }
[ "public", "function", "register_hook", "(", "$", "hook", ",", "$", "callback", ")", "{", "if", "(", "is_callable", "(", "$", "callback", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "deprecated_hooks", "[", "$", "hook", "]", ")", ")", "{", "rcube", "::", "raise_error", "(", "array", "(", "'code'", "=>", "522", ",", "'type'", "=>", "'php'", ",", "'file'", "=>", "__FILE__", ",", "'line'", "=>", "__LINE__", ",", "'message'", "=>", "\"Deprecated hook name. \"", ".", "$", "hook", ".", "' -> '", ".", "$", "this", "->", "deprecated_hooks", "[", "$", "hook", "]", ")", ",", "true", ",", "false", ")", ";", "$", "hook", "=", "$", "this", "->", "deprecated_hooks", "[", "$", "hook", "]", ";", "}", "$", "this", "->", "handlers", "[", "$", "hook", "]", "[", "]", "=", "$", "callback", ";", "}", "else", "{", "rcube", "::", "raise_error", "(", "array", "(", "'code'", "=>", "521", ",", "'type'", "=>", "'php'", ",", "'file'", "=>", "__FILE__", ",", "'line'", "=>", "__LINE__", ",", "'message'", "=>", "\"Invalid callback function for $hook\"", ")", ",", "true", ",", "false", ")", ";", "}", "}" ]
Allows a plugin object to register a callback for a certain hook @param string $hook Hook name @param mixed $callback String with global function name or array($obj, 'methodname')
[ "Allows", "a", "plugin", "object", "to", "register", "a", "callback", "for", "a", "certain", "hook" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_plugin_api.php#L382-L399
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_plugin_api.php
rcube_plugin_api.unregister_hook
public function unregister_hook($hook, $callback) { $callback_id = array_search($callback, (array) $this->handlers[$hook]); if ($callback_id !== false) { // array_splice() removes the element and re-indexes keys // that is required by the 'for' loop in exec_hook() below array_splice($this->handlers[$hook], $callback_id, 1); } }
php
public function unregister_hook($hook, $callback) { $callback_id = array_search($callback, (array) $this->handlers[$hook]); if ($callback_id !== false) { // array_splice() removes the element and re-indexes keys // that is required by the 'for' loop in exec_hook() below array_splice($this->handlers[$hook], $callback_id, 1); } }
[ "public", "function", "unregister_hook", "(", "$", "hook", ",", "$", "callback", ")", "{", "$", "callback_id", "=", "array_search", "(", "$", "callback", ",", "(", "array", ")", "$", "this", "->", "handlers", "[", "$", "hook", "]", ")", ";", "if", "(", "$", "callback_id", "!==", "false", ")", "{", "// array_splice() removes the element and re-indexes keys", "// that is required by the 'for' loop in exec_hook() below", "array_splice", "(", "$", "this", "->", "handlers", "[", "$", "hook", "]", ",", "$", "callback_id", ",", "1", ")", ";", "}", "}" ]
Allow a plugin object to unregister a callback. @param string $hook Hook name @param mixed $callback String with global function name or array($obj, 'methodname')
[ "Allow", "a", "plugin", "object", "to", "unregister", "a", "callback", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_plugin_api.php#L407-L415
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_plugin_api.php
rcube_plugin_api.exec_hook
public function exec_hook($hook, $args = array()) { if (!is_array($args)) { $args = array('arg' => $args); } // TODO: avoid recursion by checking in_array($hook, $this->exec_stack) ? $args += array('abort' => false); array_push($this->exec_stack, $hook); // Use for loop here, so handlers added in the hook will be executed too if (!empty($this->handlers[$hook])) { for ($i = 0; $i < count($this->handlers[$hook]); $i++) { $ret = call_user_func($this->handlers[$hook][$i], $args); if ($ret && is_array($ret)) { $args = $ret + $args; } if ($args['break']) { break; } } } array_pop($this->exec_stack); return $args; }
php
public function exec_hook($hook, $args = array()) { if (!is_array($args)) { $args = array('arg' => $args); } // TODO: avoid recursion by checking in_array($hook, $this->exec_stack) ? $args += array('abort' => false); array_push($this->exec_stack, $hook); // Use for loop here, so handlers added in the hook will be executed too if (!empty($this->handlers[$hook])) { for ($i = 0; $i < count($this->handlers[$hook]); $i++) { $ret = call_user_func($this->handlers[$hook][$i], $args); if ($ret && is_array($ret)) { $args = $ret + $args; } if ($args['break']) { break; } } } array_pop($this->exec_stack); return $args; }
[ "public", "function", "exec_hook", "(", "$", "hook", ",", "$", "args", "=", "array", "(", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "args", ")", ")", "{", "$", "args", "=", "array", "(", "'arg'", "=>", "$", "args", ")", ";", "}", "// TODO: avoid recursion by checking in_array($hook, $this->exec_stack) ?", "$", "args", "+=", "array", "(", "'abort'", "=>", "false", ")", ";", "array_push", "(", "$", "this", "->", "exec_stack", ",", "$", "hook", ")", ";", "// Use for loop here, so handlers added in the hook will be executed too", "if", "(", "!", "empty", "(", "$", "this", "->", "handlers", "[", "$", "hook", "]", ")", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "this", "->", "handlers", "[", "$", "hook", "]", ")", ";", "$", "i", "++", ")", "{", "$", "ret", "=", "call_user_func", "(", "$", "this", "->", "handlers", "[", "$", "hook", "]", "[", "$", "i", "]", ",", "$", "args", ")", ";", "if", "(", "$", "ret", "&&", "is_array", "(", "$", "ret", ")", ")", "{", "$", "args", "=", "$", "ret", "+", "$", "args", ";", "}", "if", "(", "$", "args", "[", "'break'", "]", ")", "{", "break", ";", "}", "}", "}", "array_pop", "(", "$", "this", "->", "exec_stack", ")", ";", "return", "$", "args", ";", "}" ]
Triggers a plugin hook. This is called from the application and executes all registered handlers @param string $hook Hook name @param array $args Named arguments (key->value pairs) @return array The (probably) altered hook arguments
[ "Triggers", "a", "plugin", "hook", ".", "This", "is", "called", "from", "the", "application", "and", "executes", "all", "registered", "handlers" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_plugin_api.php#L426-L453
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_plugin_api.php
rcube_plugin_api.register_action
public function register_action($action, $owner, $callback, $task = null) { // check action name if ($task) $action = $task.'.'.$action; else if (strpos($action, 'plugin.') !== 0) $action = 'plugin.'.$action; // can register action only if it's not taken or registered by myself if (!isset($this->actionmap[$action]) || $this->actionmap[$action] == $owner) { $this->actions[$action] = $callback; $this->actionmap[$action] = $owner; } else { rcube::raise_error(array('code' => 523, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Cannot register action $action;" ." already taken by another plugin"), true, false); } }
php
public function register_action($action, $owner, $callback, $task = null) { // check action name if ($task) $action = $task.'.'.$action; else if (strpos($action, 'plugin.') !== 0) $action = 'plugin.'.$action; // can register action only if it's not taken or registered by myself if (!isset($this->actionmap[$action]) || $this->actionmap[$action] == $owner) { $this->actions[$action] = $callback; $this->actionmap[$action] = $owner; } else { rcube::raise_error(array('code' => 523, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Cannot register action $action;" ." already taken by another plugin"), true, false); } }
[ "public", "function", "register_action", "(", "$", "action", ",", "$", "owner", ",", "$", "callback", ",", "$", "task", "=", "null", ")", "{", "// check action name", "if", "(", "$", "task", ")", "$", "action", "=", "$", "task", ".", "'.'", ".", "$", "action", ";", "else", "if", "(", "strpos", "(", "$", "action", ",", "'plugin.'", ")", "!==", "0", ")", "$", "action", "=", "'plugin.'", ".", "$", "action", ";", "// can register action only if it's not taken or registered by myself", "if", "(", "!", "isset", "(", "$", "this", "->", "actionmap", "[", "$", "action", "]", ")", "||", "$", "this", "->", "actionmap", "[", "$", "action", "]", "==", "$", "owner", ")", "{", "$", "this", "->", "actions", "[", "$", "action", "]", "=", "$", "callback", ";", "$", "this", "->", "actionmap", "[", "$", "action", "]", "=", "$", "owner", ";", "}", "else", "{", "rcube", "::", "raise_error", "(", "array", "(", "'code'", "=>", "523", ",", "'type'", "=>", "'php'", ",", "'file'", "=>", "__FILE__", ",", "'line'", "=>", "__LINE__", ",", "'message'", "=>", "\"Cannot register action $action;\"", ".", "\" already taken by another plugin\"", ")", ",", "true", ",", "false", ")", ";", "}", "}" ]
Let a plugin register a handler for a specific request @param string $action Action name (_task=mail&_action=plugin.foo) @param string $owner Plugin name that registers this action @param mixed $callback Callback: string with global function name or array($obj, 'methodname') @param string $task Task name registered by this plugin
[ "Let", "a", "plugin", "register", "a", "handler", "for", "a", "specific", "request" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_plugin_api.php#L463-L482
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_plugin_api.php
rcube_plugin_api.exec_action
public function exec_action($action) { if (isset($this->actions[$action])) { call_user_func($this->actions[$action]); } else if (rcube::get_instance()->action != 'refresh') { rcube::raise_error(array('code' => 524, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "No handler found for action $action"), true, true); } }
php
public function exec_action($action) { if (isset($this->actions[$action])) { call_user_func($this->actions[$action]); } else if (rcube::get_instance()->action != 'refresh') { rcube::raise_error(array('code' => 524, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "No handler found for action $action"), true, true); } }
[ "public", "function", "exec_action", "(", "$", "action", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "actions", "[", "$", "action", "]", ")", ")", "{", "call_user_func", "(", "$", "this", "->", "actions", "[", "$", "action", "]", ")", ";", "}", "else", "if", "(", "rcube", "::", "get_instance", "(", ")", "->", "action", "!=", "'refresh'", ")", "{", "rcube", "::", "raise_error", "(", "array", "(", "'code'", "=>", "524", ",", "'type'", "=>", "'php'", ",", "'file'", "=>", "__FILE__", ",", "'line'", "=>", "__LINE__", ",", "'message'", "=>", "\"No handler found for action $action\"", ")", ",", "true", ",", "true", ")", ";", "}", "}" ]
This method handles requests like _task=mail&_action=plugin.foo It executes the callback function that was registered with the given action. @param string $action Action name
[ "This", "method", "handles", "requests", "like", "_task", "=", "mail&_action", "=", "plugin", ".", "foo", "It", "executes", "the", "callback", "function", "that", "was", "registered", "with", "the", "given", "action", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_plugin_api.php#L490-L500
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_plugin_api.php
rcube_plugin_api.register_handler
public function register_handler($name, $owner, $callback) { // check name if (strpos($name, 'plugin.') !== 0) { $name = 'plugin.' . $name; } // can register handler only if it's not taken or registered by myself if (is_object($this->output) && (!isset($this->objectsmap[$name]) || $this->objectsmap[$name] == $owner) ) { $this->output->add_handler($name, $callback); $this->objectsmap[$name] = $owner; } else { rcube::raise_error(array('code' => 525, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Cannot register template handler $name;" ." already taken by another plugin or no output object available"), true, false); } }
php
public function register_handler($name, $owner, $callback) { // check name if (strpos($name, 'plugin.') !== 0) { $name = 'plugin.' . $name; } // can register handler only if it's not taken or registered by myself if (is_object($this->output) && (!isset($this->objectsmap[$name]) || $this->objectsmap[$name] == $owner) ) { $this->output->add_handler($name, $callback); $this->objectsmap[$name] = $owner; } else { rcube::raise_error(array('code' => 525, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Cannot register template handler $name;" ." already taken by another plugin or no output object available"), true, false); } }
[ "public", "function", "register_handler", "(", "$", "name", ",", "$", "owner", ",", "$", "callback", ")", "{", "// check name", "if", "(", "strpos", "(", "$", "name", ",", "'plugin.'", ")", "!==", "0", ")", "{", "$", "name", "=", "'plugin.'", ".", "$", "name", ";", "}", "// can register handler only if it's not taken or registered by myself", "if", "(", "is_object", "(", "$", "this", "->", "output", ")", "&&", "(", "!", "isset", "(", "$", "this", "->", "objectsmap", "[", "$", "name", "]", ")", "||", "$", "this", "->", "objectsmap", "[", "$", "name", "]", "==", "$", "owner", ")", ")", "{", "$", "this", "->", "output", "->", "add_handler", "(", "$", "name", ",", "$", "callback", ")", ";", "$", "this", "->", "objectsmap", "[", "$", "name", "]", "=", "$", "owner", ";", "}", "else", "{", "rcube", "::", "raise_error", "(", "array", "(", "'code'", "=>", "525", ",", "'type'", "=>", "'php'", ",", "'file'", "=>", "__FILE__", ",", "'line'", "=>", "__LINE__", ",", "'message'", "=>", "\"Cannot register template handler $name;\"", ".", "\" already taken by another plugin or no output object available\"", ")", ",", "true", ",", "false", ")", ";", "}", "}" ]
Register a handler function for template objects @param string $name Object name @param string $owner Plugin name that registers this action @param mixed $callback Callback: string with global function name or array($obj, 'methodname')
[ "Register", "a", "handler", "function", "for", "template", "objects" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_plugin_api.php#L509-L529
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_plugin_api.php
rcube_plugin_api.is_processing
public function is_processing($hook = null) { return count($this->exec_stack) > 0 && (!$hook || in_array($hook, $this->exec_stack)); }
php
public function is_processing($hook = null) { return count($this->exec_stack) > 0 && (!$hook || in_array($hook, $this->exec_stack)); }
[ "public", "function", "is_processing", "(", "$", "hook", "=", "null", ")", "{", "return", "count", "(", "$", "this", "->", "exec_stack", ")", ">", "0", "&&", "(", "!", "$", "hook", "||", "in_array", "(", "$", "hook", ",", "$", "this", "->", "exec_stack", ")", ")", ";", "}" ]
Check if a plugin hook is currently processing. Mainly used to prevent loops and recursion. @param string $hook Hook to check (optional) @return boolean True if any/the given hook is currently processed, otherwise false
[ "Check", "if", "a", "plugin", "hook", "is", "currently", "processing", ".", "Mainly", "used", "to", "prevent", "loops", "and", "recursion", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_plugin_api.php#L585-L588
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_plugin_api.php
rcube_plugin_api.include_script
public function include_script($fn) { if (is_object($this->output) && $this->output->type == 'html') { $src = $this->resource_url($fn); $this->output->add_header(html::tag('script', array('type' => "text/javascript", 'src' => $src))); } }
php
public function include_script($fn) { if (is_object($this->output) && $this->output->type == 'html') { $src = $this->resource_url($fn); $this->output->add_header(html::tag('script', array('type' => "text/javascript", 'src' => $src))); } }
[ "public", "function", "include_script", "(", "$", "fn", ")", "{", "if", "(", "is_object", "(", "$", "this", "->", "output", ")", "&&", "$", "this", "->", "output", "->", "type", "==", "'html'", ")", "{", "$", "src", "=", "$", "this", "->", "resource_url", "(", "$", "fn", ")", ";", "$", "this", "->", "output", "->", "add_header", "(", "html", "::", "tag", "(", "'script'", ",", "array", "(", "'type'", "=>", "\"text/javascript\"", ",", "'src'", "=>", "$", "src", ")", ")", ")", ";", "}", "}" ]
Include a plugin script file in the current HTML page @param string $fn Path to script
[ "Include", "a", "plugin", "script", "file", "in", "the", "current", "HTML", "page" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_plugin_api.php#L595-L602
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_plugin_api.php
rcube_plugin_api.include_stylesheet
public function include_stylesheet($fn) { if (is_object($this->output) && $this->output->type == 'html') { $src = $this->resource_url($fn); $this->output->include_css($src); } }
php
public function include_stylesheet($fn) { if (is_object($this->output) && $this->output->type == 'html') { $src = $this->resource_url($fn); $this->output->include_css($src); } }
[ "public", "function", "include_stylesheet", "(", "$", "fn", ")", "{", "if", "(", "is_object", "(", "$", "this", "->", "output", ")", "&&", "$", "this", "->", "output", "->", "type", "==", "'html'", ")", "{", "$", "src", "=", "$", "this", "->", "resource_url", "(", "$", "fn", ")", ";", "$", "this", "->", "output", "->", "include_css", "(", "$", "src", ")", ";", "}", "}" ]
Include a plugin stylesheet in the current HTML page @param string $fn Path to stylesheet
[ "Include", "a", "plugin", "stylesheet", "in", "the", "current", "HTML", "page" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_plugin_api.php#L609-L615
train
i-MSCP/roundcube
roundcubemail/plugins/database_attachments/database_attachments.php
database_attachments.get_cache
protected function get_cache() { if (!$this->cache) { $this->load_config(); $rcmail = rcube::get_instance(); $ttl = 12 * 60 * 60; // default: 12 hours $ttl = $rcmail->config->get('database_attachments_cache_ttl', $ttl); $type = $rcmail->config->get('database_attachments_cache', 'db'); $prefix = self::PREFIX; // Add session identifier to the prefix to prevent from removing attachments // in other sessions of the same user (#1490542) if ($id = session_id()) { $prefix .= $id; } // Init SQL cache (disable cache data serialization) $this->cache = $rcmail->get_cache($prefix, $type, $ttl, false); } return $this->cache; }
php
protected function get_cache() { if (!$this->cache) { $this->load_config(); $rcmail = rcube::get_instance(); $ttl = 12 * 60 * 60; // default: 12 hours $ttl = $rcmail->config->get('database_attachments_cache_ttl', $ttl); $type = $rcmail->config->get('database_attachments_cache', 'db'); $prefix = self::PREFIX; // Add session identifier to the prefix to prevent from removing attachments // in other sessions of the same user (#1490542) if ($id = session_id()) { $prefix .= $id; } // Init SQL cache (disable cache data serialization) $this->cache = $rcmail->get_cache($prefix, $type, $ttl, false); } return $this->cache; }
[ "protected", "function", "get_cache", "(", ")", "{", "if", "(", "!", "$", "this", "->", "cache", ")", "{", "$", "this", "->", "load_config", "(", ")", ";", "$", "rcmail", "=", "rcube", "::", "get_instance", "(", ")", ";", "$", "ttl", "=", "12", "*", "60", "*", "60", ";", "// default: 12 hours", "$", "ttl", "=", "$", "rcmail", "->", "config", "->", "get", "(", "'database_attachments_cache_ttl'", ",", "$", "ttl", ")", ";", "$", "type", "=", "$", "rcmail", "->", "config", "->", "get", "(", "'database_attachments_cache'", ",", "'db'", ")", ";", "$", "prefix", "=", "self", "::", "PREFIX", ";", "// Add session identifier to the prefix to prevent from removing attachments", "// in other sessions of the same user (#1490542)", "if", "(", "$", "id", "=", "session_id", "(", ")", ")", "{", "$", "prefix", ".=", "$", "id", ";", "}", "// Init SQL cache (disable cache data serialization)", "$", "this", "->", "cache", "=", "$", "rcmail", "->", "get_cache", "(", "$", "prefix", ",", "$", "type", ",", "$", "ttl", ",", "false", ")", ";", "}", "return", "$", "this", "->", "cache", ";", "}" ]
Initialize and return cache object
[ "Initialize", "and", "return", "cache", "object" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/database_attachments/database_attachments.php#L169-L191
train
i-MSCP/roundcube
roundcubemail/plugins/identicon/identicon_engine.php
identicon_engine.sendOutput
public function sendOutput() { if ($this->binary) { $rcmail = rcmail::get_instance(); $rcmail->output->future_expire_header(10 * 60); header('Content-Type: ' . $this->mimetype); header('Content-Size: ' . strlen($this->binary)); echo $this->binary; return true; } return false; }
php
public function sendOutput() { if ($this->binary) { $rcmail = rcmail::get_instance(); $rcmail->output->future_expire_header(10 * 60); header('Content-Type: ' . $this->mimetype); header('Content-Size: ' . strlen($this->binary)); echo $this->binary; return true; } return false; }
[ "public", "function", "sendOutput", "(", ")", "{", "if", "(", "$", "this", "->", "binary", ")", "{", "$", "rcmail", "=", "rcmail", "::", "get_instance", "(", ")", ";", "$", "rcmail", "->", "output", "->", "future_expire_header", "(", "10", "*", "60", ")", ";", "header", "(", "'Content-Type: '", ".", "$", "this", "->", "mimetype", ")", ";", "header", "(", "'Content-Size: '", ".", "strlen", "(", "$", "this", "->", "binary", ")", ")", ";", "echo", "$", "this", "->", "binary", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Sends the image to the browser
[ "Sends", "the", "image", "to", "the", "browser" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/identicon/identicon_engine.php#L73-L87
train
i-MSCP/roundcube
roundcubemail/plugins/identicon/identicon_engine.php
identicon_engine.generateGD
private function generateGD() { $color = $this->toRGB($this->color); $bgcolor = $this->toRGB($this->bgcolor); // create an image, setup colors $image = imagecreate($this->width, $this->height); $color = imagecolorallocate($image, $color[0], $color[1], $color[2]); $bgcolor = imagecolorallocate($image, $bgcolor[0], $bgcolor[1], $bgcolor[2]); imagefilledrectangle($image, 0, 0, $this->width, $this->height, $bgcolor); // draw the grid created in self::generate() foreach ($this->grid as $item) { if ($item['active']) { imagefilledrectangle($image, $item['x1'], $item['y1'], $item['x2'], $item['y2'], $color); } } // generate an image and save it to a variable ob_start(); imagepng($image, null, 6, PNG_ALL_FILTERS); $this->binary = ob_get_contents(); ob_end_clean(); // cleanup imagedestroy($image); }
php
private function generateGD() { $color = $this->toRGB($this->color); $bgcolor = $this->toRGB($this->bgcolor); // create an image, setup colors $image = imagecreate($this->width, $this->height); $color = imagecolorallocate($image, $color[0], $color[1], $color[2]); $bgcolor = imagecolorallocate($image, $bgcolor[0], $bgcolor[1], $bgcolor[2]); imagefilledrectangle($image, 0, 0, $this->width, $this->height, $bgcolor); // draw the grid created in self::generate() foreach ($this->grid as $item) { if ($item['active']) { imagefilledrectangle($image, $item['x1'], $item['y1'], $item['x2'], $item['y2'], $color); } } // generate an image and save it to a variable ob_start(); imagepng($image, null, 6, PNG_ALL_FILTERS); $this->binary = ob_get_contents(); ob_end_clean(); // cleanup imagedestroy($image); }
[ "private", "function", "generateGD", "(", ")", "{", "$", "color", "=", "$", "this", "->", "toRGB", "(", "$", "this", "->", "color", ")", ";", "$", "bgcolor", "=", "$", "this", "->", "toRGB", "(", "$", "this", "->", "bgcolor", ")", ";", "// create an image, setup colors", "$", "image", "=", "imagecreate", "(", "$", "this", "->", "width", ",", "$", "this", "->", "height", ")", ";", "$", "color", "=", "imagecolorallocate", "(", "$", "image", ",", "$", "color", "[", "0", "]", ",", "$", "color", "[", "1", "]", ",", "$", "color", "[", "2", "]", ")", ";", "$", "bgcolor", "=", "imagecolorallocate", "(", "$", "image", ",", "$", "bgcolor", "[", "0", "]", ",", "$", "bgcolor", "[", "1", "]", ",", "$", "bgcolor", "[", "2", "]", ")", ";", "imagefilledrectangle", "(", "$", "image", ",", "0", ",", "0", ",", "$", "this", "->", "width", ",", "$", "this", "->", "height", ",", "$", "bgcolor", ")", ";", "// draw the grid created in self::generate()", "foreach", "(", "$", "this", "->", "grid", "as", "$", "item", ")", "{", "if", "(", "$", "item", "[", "'active'", "]", ")", "{", "imagefilledrectangle", "(", "$", "image", ",", "$", "item", "[", "'x1'", "]", ",", "$", "item", "[", "'y1'", "]", ",", "$", "item", "[", "'x2'", "]", ",", "$", "item", "[", "'y2'", "]", ",", "$", "color", ")", ";", "}", "}", "// generate an image and save it to a variable", "ob_start", "(", ")", ";", "imagepng", "(", "$", "image", ",", "null", ",", "6", ",", "PNG_ALL_FILTERS", ")", ";", "$", "this", "->", "binary", "=", "ob_get_contents", "(", ")", ";", "ob_end_clean", "(", ")", ";", "// cleanup", "imagedestroy", "(", "$", "image", ")", ";", "}" ]
GD-based icon generation worker
[ "GD", "-", "based", "icon", "generation", "worker" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/identicon/identicon_engine.php#L137-L164
train
i-MSCP/roundcube
roundcubemail/plugins/virtuser_file/virtuser_file.php
virtuser_file.email2user
function email2user($p) { $r = $this->findinvirtual('/^' . preg_quote($p['email'], '/') . '\s/'); for ($i=0; $i<count($r); $i++) { $arr = preg_split('/\s+/', trim($r[$i])); if (count($arr) > 0) { $p['user'] = trim($arr[count($arr)-1]); break; } } return $p; }
php
function email2user($p) { $r = $this->findinvirtual('/^' . preg_quote($p['email'], '/') . '\s/'); for ($i=0; $i<count($r); $i++) { $arr = preg_split('/\s+/', trim($r[$i])); if (count($arr) > 0) { $p['user'] = trim($arr[count($arr)-1]); break; } } return $p; }
[ "function", "email2user", "(", "$", "p", ")", "{", "$", "r", "=", "$", "this", "->", "findinvirtual", "(", "'/^'", ".", "preg_quote", "(", "$", "p", "[", "'email'", "]", ",", "'/'", ")", ".", "'\\s/'", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "r", ")", ";", "$", "i", "++", ")", "{", "$", "arr", "=", "preg_split", "(", "'/\\s+/'", ",", "trim", "(", "$", "r", "[", "$", "i", "]", ")", ")", ";", "if", "(", "count", "(", "$", "arr", ")", ">", "0", ")", "{", "$", "p", "[", "'user'", "]", "=", "trim", "(", "$", "arr", "[", "count", "(", "$", "arr", ")", "-", "1", "]", ")", ";", "break", ";", "}", "}", "return", "$", "p", ";", "}" ]
Email > User
[ "Email", ">", "User" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/virtuser_file/virtuser_file.php#L59-L73
train
i-MSCP/roundcube
roundcubemail/plugins/virtuser_file/virtuser_file.php
virtuser_file.findinvirtual
private function findinvirtual($pattern) { $result = array(); $virtual = null; if ($this->file) $virtual = file($this->file); if (empty($virtual)) return $result; // check each line for matches foreach ($virtual as $line) { $line = trim($line); if (empty($line) || $line[0]=='#') continue; if (preg_match($pattern, $line)) $result[] = $line; } return $result; }
php
private function findinvirtual($pattern) { $result = array(); $virtual = null; if ($this->file) $virtual = file($this->file); if (empty($virtual)) return $result; // check each line for matches foreach ($virtual as $line) { $line = trim($line); if (empty($line) || $line[0]=='#') continue; if (preg_match($pattern, $line)) $result[] = $line; } return $result; }
[ "private", "function", "findinvirtual", "(", "$", "pattern", ")", "{", "$", "result", "=", "array", "(", ")", ";", "$", "virtual", "=", "null", ";", "if", "(", "$", "this", "->", "file", ")", "$", "virtual", "=", "file", "(", "$", "this", "->", "file", ")", ";", "if", "(", "empty", "(", "$", "virtual", ")", ")", "return", "$", "result", ";", "// check each line for matches", "foreach", "(", "$", "virtual", "as", "$", "line", ")", "{", "$", "line", "=", "trim", "(", "$", "line", ")", ";", "if", "(", "empty", "(", "$", "line", ")", "||", "$", "line", "[", "0", "]", "==", "'#'", ")", "continue", ";", "if", "(", "preg_match", "(", "$", "pattern", ",", "$", "line", ")", ")", "$", "result", "[", "]", "=", "$", "line", ";", "}", "return", "$", "result", ";", "}" ]
Find matches of the given pattern in virtuser file @param string Regular expression to search for @return array Matching entries
[ "Find", "matches", "of", "the", "given", "pattern", "in", "virtuser", "file" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/virtuser_file/virtuser_file.php#L81-L103
train
i-MSCP/roundcube
roundcubemail/plugins/emoticons/emoticons.php
emoticons.init
function init() { $rcube = rcube::get_instance(); $this->add_hook('message_part_after', array($this, 'message_part_after')); $this->add_hook('message_outgoing_body', array($this, 'message_outgoing_body')); $this->add_hook('html2text', array($this, 'html2text')); $this->add_hook('html_editor', array($this, 'html_editor')); if ($rcube->task == 'settings') { $this->add_hook('preferences_list', array($this, 'preferences_list')); $this->add_hook('preferences_save', array($this, 'preferences_save')); } }
php
function init() { $rcube = rcube::get_instance(); $this->add_hook('message_part_after', array($this, 'message_part_after')); $this->add_hook('message_outgoing_body', array($this, 'message_outgoing_body')); $this->add_hook('html2text', array($this, 'html2text')); $this->add_hook('html_editor', array($this, 'html_editor')); if ($rcube->task == 'settings') { $this->add_hook('preferences_list', array($this, 'preferences_list')); $this->add_hook('preferences_save', array($this, 'preferences_save')); } }
[ "function", "init", "(", ")", "{", "$", "rcube", "=", "rcube", "::", "get_instance", "(", ")", ";", "$", "this", "->", "add_hook", "(", "'message_part_after'", ",", "array", "(", "$", "this", ",", "'message_part_after'", ")", ")", ";", "$", "this", "->", "add_hook", "(", "'message_outgoing_body'", ",", "array", "(", "$", "this", ",", "'message_outgoing_body'", ")", ")", ";", "$", "this", "->", "add_hook", "(", "'html2text'", ",", "array", "(", "$", "this", ",", "'html2text'", ")", ")", ";", "$", "this", "->", "add_hook", "(", "'html_editor'", ",", "array", "(", "$", "this", ",", "'html_editor'", ")", ")", ";", "if", "(", "$", "rcube", "->", "task", "==", "'settings'", ")", "{", "$", "this", "->", "add_hook", "(", "'preferences_list'", ",", "array", "(", "$", "this", ",", "'preferences_list'", ")", ")", ";", "$", "this", "->", "add_hook", "(", "'preferences_save'", ",", "array", "(", "$", "this", ",", "'preferences_save'", ")", ")", ";", "}", "}" ]
Plugin initilization.
[ "Plugin", "initilization", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/emoticons/emoticons.php#L22-L35
train
i-MSCP/roundcube
roundcubemail/plugins/emoticons/emoticons.php
emoticons.message_outgoing_body
function message_outgoing_body($args) { if ($args['type'] == 'html') { $this->load_config(); $rcube = rcube::get_instance(); if (!$rcube->config->get('emoticons_compose', true)) { return $args; } require_once __DIR__ . '/emoticons_engine.php'; // look for "emoticon" images from TinyMCE and change their src paths to // be file paths on the server instead of URL paths. $images = emoticons_engine::replace($args['body']); // add these images as attachments to the MIME message foreach ($images as $img_name => $img_file) { $args['message']->addHTMLImage($img_file, 'image/gif', '', true, $img_name); } } return $args; }
php
function message_outgoing_body($args) { if ($args['type'] == 'html') { $this->load_config(); $rcube = rcube::get_instance(); if (!$rcube->config->get('emoticons_compose', true)) { return $args; } require_once __DIR__ . '/emoticons_engine.php'; // look for "emoticon" images from TinyMCE and change their src paths to // be file paths on the server instead of URL paths. $images = emoticons_engine::replace($args['body']); // add these images as attachments to the MIME message foreach ($images as $img_name => $img_file) { $args['message']->addHTMLImage($img_file, 'image/gif', '', true, $img_name); } } return $args; }
[ "function", "message_outgoing_body", "(", "$", "args", ")", "{", "if", "(", "$", "args", "[", "'type'", "]", "==", "'html'", ")", "{", "$", "this", "->", "load_config", "(", ")", ";", "$", "rcube", "=", "rcube", "::", "get_instance", "(", ")", ";", "if", "(", "!", "$", "rcube", "->", "config", "->", "get", "(", "'emoticons_compose'", ",", "true", ")", ")", "{", "return", "$", "args", ";", "}", "require_once", "__DIR__", ".", "'/emoticons_engine.php'", ";", "// look for \"emoticon\" images from TinyMCE and change their src paths to", "// be file paths on the server instead of URL paths.", "$", "images", "=", "emoticons_engine", "::", "replace", "(", "$", "args", "[", "'body'", "]", ")", ";", "// add these images as attachments to the MIME message", "foreach", "(", "$", "images", "as", "$", "img_name", "=>", "$", "img_file", ")", "{", "$", "args", "[", "'message'", "]", "->", "addHTMLImage", "(", "$", "img_file", ",", "'image/gif'", ",", "''", ",", "true", ",", "$", "img_name", ")", ";", "}", "}", "return", "$", "args", ";", "}" ]
'message_outgoing_body' hook handler to replace image emoticons from TinyMCE editor with image attachments.
[ "message_outgoing_body", "hook", "handler", "to", "replace", "image", "emoticons", "from", "TinyMCE", "editor", "with", "image", "attachments", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/emoticons/emoticons.php#L63-L86
train
i-MSCP/roundcube
roundcubemail/plugins/emoticons/emoticons.php
emoticons.html2text
function html2text($args) { $rcube = rcube::get_instance(); if ($rcube->action == 'html2text' || $rcube->action == 'send') { $this->load_config(); if (!$rcube->config->get('emoticons_compose', true)) { return $args; } require_once __DIR__ . '/emoticons_engine.php'; $args['body'] = emoticons_engine::icons2text($args['body']); } return $args; }
php
function html2text($args) { $rcube = rcube::get_instance(); if ($rcube->action == 'html2text' || $rcube->action == 'send') { $this->load_config(); if (!$rcube->config->get('emoticons_compose', true)) { return $args; } require_once __DIR__ . '/emoticons_engine.php'; $args['body'] = emoticons_engine::icons2text($args['body']); } return $args; }
[ "function", "html2text", "(", "$", "args", ")", "{", "$", "rcube", "=", "rcube", "::", "get_instance", "(", ")", ";", "if", "(", "$", "rcube", "->", "action", "==", "'html2text'", "||", "$", "rcube", "->", "action", "==", "'send'", ")", "{", "$", "this", "->", "load_config", "(", ")", ";", "if", "(", "!", "$", "rcube", "->", "config", "->", "get", "(", "'emoticons_compose'", ",", "true", ")", ")", "{", "return", "$", "args", ";", "}", "require_once", "__DIR__", ".", "'/emoticons_engine.php'", ";", "$", "args", "[", "'body'", "]", "=", "emoticons_engine", "::", "icons2text", "(", "$", "args", "[", "'body'", "]", ")", ";", "}", "return", "$", "args", ";", "}" ]
'html2text' hook handler to replace image emoticons from TinyMCE editor with plain text emoticons. This is executed on html2text action, i.e. when switching from HTML to text in compose window (or similar place). Also when generating alternative text/plain part.
[ "html2text", "hook", "handler", "to", "replace", "image", "emoticons", "from", "TinyMCE", "editor", "with", "plain", "text", "emoticons", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/emoticons/emoticons.php#L96-L113
train
i-MSCP/roundcube
roundcubemail/plugins/emoticons/emoticons.php
emoticons.html_editor
function html_editor($args) { $rcube = rcube::get_instance(); $this->load_config(); if ($rcube->config->get('emoticons_compose', true)) { $args['extra_plugins'][] = 'emoticons'; $args['extra_buttons'][] = 'emoticons'; } return $args; }
php
function html_editor($args) { $rcube = rcube::get_instance(); $this->load_config(); if ($rcube->config->get('emoticons_compose', true)) { $args['extra_plugins'][] = 'emoticons'; $args['extra_buttons'][] = 'emoticons'; } return $args; }
[ "function", "html_editor", "(", "$", "args", ")", "{", "$", "rcube", "=", "rcube", "::", "get_instance", "(", ")", ";", "$", "this", "->", "load_config", "(", ")", ";", "if", "(", "$", "rcube", "->", "config", "->", "get", "(", "'emoticons_compose'", ",", "true", ")", ")", "{", "$", "args", "[", "'extra_plugins'", "]", "[", "]", "=", "'emoticons'", ";", "$", "args", "[", "'extra_buttons'", "]", "[", "]", "=", "'emoticons'", ";", "}", "return", "$", "args", ";", "}" ]
'html_editor' hook handler, where we enable emoticons in TinyMCE
[ "html_editor", "hook", "handler", "where", "we", "enable", "emoticons", "in", "TinyMCE" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/emoticons/emoticons.php#L118-L130
train
i-MSCP/roundcube
roundcubemail/plugins/emoticons/emoticons.php
emoticons.preferences_list
function preferences_list($args) { $rcube = rcube::get_instance(); $dont_override = $rcube->config->get('dont_override', array()); if ($args['section'] == 'mailview' && !in_array('emoticons_display', $dont_override)) { $this->load_config(); $this->add_texts('localization'); $field_id = 'emoticons_display'; $checkbox = new html_checkbox(array('name' => '_' . $field_id, 'id' => $field_id, 'value' => 1)); $args['blocks']['main']['options']['emoticons_display'] = array( 'title' => $this->gettext('emoticonsdisplay'), 'content' => $checkbox->show(intval($rcube->config->get('emoticons_display', false))) ); } else if ($args['section'] == 'compose' && !in_array('emoticons_compose', $dont_override)) { $this->load_config(); $this->add_texts('localization'); $field_id = 'emoticons_compose'; $checkbox = new html_checkbox(array('name' => '_' . $field_id, 'id' => $field_id, 'value' => 1)); $args['blocks']['main']['options']['emoticons_compose'] = array( 'title' => $this->gettext('emoticonscompose'), 'content' => $checkbox->show(intval($rcube->config->get('emoticons_compose', true))) ); } return $args; }
php
function preferences_list($args) { $rcube = rcube::get_instance(); $dont_override = $rcube->config->get('dont_override', array()); if ($args['section'] == 'mailview' && !in_array('emoticons_display', $dont_override)) { $this->load_config(); $this->add_texts('localization'); $field_id = 'emoticons_display'; $checkbox = new html_checkbox(array('name' => '_' . $field_id, 'id' => $field_id, 'value' => 1)); $args['blocks']['main']['options']['emoticons_display'] = array( 'title' => $this->gettext('emoticonsdisplay'), 'content' => $checkbox->show(intval($rcube->config->get('emoticons_display', false))) ); } else if ($args['section'] == 'compose' && !in_array('emoticons_compose', $dont_override)) { $this->load_config(); $this->add_texts('localization'); $field_id = 'emoticons_compose'; $checkbox = new html_checkbox(array('name' => '_' . $field_id, 'id' => $field_id, 'value' => 1)); $args['blocks']['main']['options']['emoticons_compose'] = array( 'title' => $this->gettext('emoticonscompose'), 'content' => $checkbox->show(intval($rcube->config->get('emoticons_compose', true))) ); } return $args; }
[ "function", "preferences_list", "(", "$", "args", ")", "{", "$", "rcube", "=", "rcube", "::", "get_instance", "(", ")", ";", "$", "dont_override", "=", "$", "rcube", "->", "config", "->", "get", "(", "'dont_override'", ",", "array", "(", ")", ")", ";", "if", "(", "$", "args", "[", "'section'", "]", "==", "'mailview'", "&&", "!", "in_array", "(", "'emoticons_display'", ",", "$", "dont_override", ")", ")", "{", "$", "this", "->", "load_config", "(", ")", ";", "$", "this", "->", "add_texts", "(", "'localization'", ")", ";", "$", "field_id", "=", "'emoticons_display'", ";", "$", "checkbox", "=", "new", "html_checkbox", "(", "array", "(", "'name'", "=>", "'_'", ".", "$", "field_id", ",", "'id'", "=>", "$", "field_id", ",", "'value'", "=>", "1", ")", ")", ";", "$", "args", "[", "'blocks'", "]", "[", "'main'", "]", "[", "'options'", "]", "[", "'emoticons_display'", "]", "=", "array", "(", "'title'", "=>", "$", "this", "->", "gettext", "(", "'emoticonsdisplay'", ")", ",", "'content'", "=>", "$", "checkbox", "->", "show", "(", "intval", "(", "$", "rcube", "->", "config", "->", "get", "(", "'emoticons_display'", ",", "false", ")", ")", ")", ")", ";", "}", "else", "if", "(", "$", "args", "[", "'section'", "]", "==", "'compose'", "&&", "!", "in_array", "(", "'emoticons_compose'", ",", "$", "dont_override", ")", ")", "{", "$", "this", "->", "load_config", "(", ")", ";", "$", "this", "->", "add_texts", "(", "'localization'", ")", ";", "$", "field_id", "=", "'emoticons_compose'", ";", "$", "checkbox", "=", "new", "html_checkbox", "(", "array", "(", "'name'", "=>", "'_'", ".", "$", "field_id", ",", "'id'", "=>", "$", "field_id", ",", "'value'", "=>", "1", ")", ")", ";", "$", "args", "[", "'blocks'", "]", "[", "'main'", "]", "[", "'options'", "]", "[", "'emoticons_compose'", "]", "=", "array", "(", "'title'", "=>", "$", "this", "->", "gettext", "(", "'emoticonscompose'", ")", ",", "'content'", "=>", "$", "checkbox", "->", "show", "(", "intval", "(", "$", "rcube", "->", "config", "->", "get", "(", "'emoticons_compose'", ",", "true", ")", ")", ")", ")", ";", "}", "return", "$", "args", ";", "}" ]
'preferences_list' hook handler
[ "preferences_list", "hook", "handler" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/emoticons/emoticons.php#L135-L166
train
i-MSCP/roundcube
roundcubemail/plugins/emoticons/emoticons.php
emoticons.preferences_save
function preferences_save($args) { $rcube = rcube::get_instance(); $dont_override = $rcube->config->get('dont_override', array()); if ($args['section'] == 'mailview' && !in_array('emoticons_display', $dont_override)) { $args['prefs']['emoticons_display'] = rcube_utils::get_input_value('_emoticons_display', rcube_utils::INPUT_POST) ? true : false; } else if ($args['section'] == 'compose' && !in_array('emoticons_compose', $dont_override)) { $args['prefs']['emoticons_compose'] = rcube_utils::get_input_value('_emoticons_compose', rcube_utils::INPUT_POST) ? true : false; } return $args; }
php
function preferences_save($args) { $rcube = rcube::get_instance(); $dont_override = $rcube->config->get('dont_override', array()); if ($args['section'] == 'mailview' && !in_array('emoticons_display', $dont_override)) { $args['prefs']['emoticons_display'] = rcube_utils::get_input_value('_emoticons_display', rcube_utils::INPUT_POST) ? true : false; } else if ($args['section'] == 'compose' && !in_array('emoticons_compose', $dont_override)) { $args['prefs']['emoticons_compose'] = rcube_utils::get_input_value('_emoticons_compose', rcube_utils::INPUT_POST) ? true : false; } return $args; }
[ "function", "preferences_save", "(", "$", "args", ")", "{", "$", "rcube", "=", "rcube", "::", "get_instance", "(", ")", ";", "$", "dont_override", "=", "$", "rcube", "->", "config", "->", "get", "(", "'dont_override'", ",", "array", "(", ")", ")", ";", "if", "(", "$", "args", "[", "'section'", "]", "==", "'mailview'", "&&", "!", "in_array", "(", "'emoticons_display'", ",", "$", "dont_override", ")", ")", "{", "$", "args", "[", "'prefs'", "]", "[", "'emoticons_display'", "]", "=", "rcube_utils", "::", "get_input_value", "(", "'_emoticons_display'", ",", "rcube_utils", "::", "INPUT_POST", ")", "?", "true", ":", "false", ";", "}", "else", "if", "(", "$", "args", "[", "'section'", "]", "==", "'compose'", "&&", "!", "in_array", "(", "'emoticons_compose'", ",", "$", "dont_override", ")", ")", "{", "$", "args", "[", "'prefs'", "]", "[", "'emoticons_compose'", "]", "=", "rcube_utils", "::", "get_input_value", "(", "'_emoticons_compose'", ",", "rcube_utils", "::", "INPUT_POST", ")", "?", "true", ":", "false", ";", "}", "return", "$", "args", ";", "}" ]
'preferences_save' hook handler
[ "preferences_save", "hook", "handler" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/plugins/emoticons/emoticons.php#L171-L184
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_message_header.php
rcube_message_header.get
public function get($name, $decode = true) { $name = strtolower($name); if (isset($this->obj_headers[$name])) { $value = $this->{$this->obj_headers[$name]}; } else { $value = $this->others[$name]; } if ($decode) { if (is_array($value)) { foreach ($value as $key => $val) { $val = rcube_mime::decode_header($val, $this->charset); $value[$key] = rcube_charset::clean($val); } } else { $value = rcube_mime::decode_header($value, $this->charset); $value = rcube_charset::clean($value); } } return $value; }
php
public function get($name, $decode = true) { $name = strtolower($name); if (isset($this->obj_headers[$name])) { $value = $this->{$this->obj_headers[$name]}; } else { $value = $this->others[$name]; } if ($decode) { if (is_array($value)) { foreach ($value as $key => $val) { $val = rcube_mime::decode_header($val, $this->charset); $value[$key] = rcube_charset::clean($val); } } else { $value = rcube_mime::decode_header($value, $this->charset); $value = rcube_charset::clean($value); } } return $value; }
[ "public", "function", "get", "(", "$", "name", ",", "$", "decode", "=", "true", ")", "{", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "obj_headers", "[", "$", "name", "]", ")", ")", "{", "$", "value", "=", "$", "this", "->", "{", "$", "this", "->", "obj_headers", "[", "$", "name", "]", "}", ";", "}", "else", "{", "$", "value", "=", "$", "this", "->", "others", "[", "$", "name", "]", ";", "}", "if", "(", "$", "decode", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "foreach", "(", "$", "value", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "val", "=", "rcube_mime", "::", "decode_header", "(", "$", "val", ",", "$", "this", "->", "charset", ")", ";", "$", "value", "[", "$", "key", "]", "=", "rcube_charset", "::", "clean", "(", "$", "val", ")", ";", "}", "}", "else", "{", "$", "value", "=", "rcube_mime", "::", "decode_header", "(", "$", "value", ",", "$", "this", "->", "charset", ")", ";", "$", "value", "=", "rcube_charset", "::", "clean", "(", "$", "value", ")", ";", "}", "}", "return", "$", "value", ";", "}" ]
Returns header value
[ "Returns", "header", "value" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_message_header.php#L216-L241
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_message_header.php
rcube_message_header.set
public function set($name, $value) { $name = strtolower($name); if (isset($this->obj_headers[$name])) { $this->{$this->obj_headers[$name]} = $value; } else { $this->others[$name] = $value; } }
php
public function set($name, $value) { $name = strtolower($name); if (isset($this->obj_headers[$name])) { $this->{$this->obj_headers[$name]} = $value; } else { $this->others[$name] = $value; } }
[ "public", "function", "set", "(", "$", "name", ",", "$", "value", ")", "{", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "obj_headers", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "{", "$", "this", "->", "obj_headers", "[", "$", "name", "]", "}", "=", "$", "value", ";", "}", "else", "{", "$", "this", "->", "others", "[", "$", "name", "]", "=", "$", "value", ";", "}", "}" ]
Sets header value
[ "Sets", "header", "value" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_message_header.php#L246-L256
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_message_header.php
rcube_message_header.from_array
public static function from_array($arr) { $obj = new rcube_message_header; foreach ($arr as $k => $v) $obj->set($k, $v); return $obj; }
php
public static function from_array($arr) { $obj = new rcube_message_header; foreach ($arr as $k => $v) $obj->set($k, $v); return $obj; }
[ "public", "static", "function", "from_array", "(", "$", "arr", ")", "{", "$", "obj", "=", "new", "rcube_message_header", ";", "foreach", "(", "$", "arr", "as", "$", "k", "=>", "$", "v", ")", "$", "obj", "->", "set", "(", "$", "k", ",", "$", "v", ")", ";", "return", "$", "obj", ";", "}" ]
Factory method to instantiate headers from a data array @param array Hash array with header values @return object rcube_message_header instance filled with headers values
[ "Factory", "method", "to", "instantiate", "headers", "from", "a", "data", "array" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_message_header.php#L265-L272
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_html2text.php
rcube_html2text.set_base_url
function set_base_url($url = '') { if (empty($url)) { if (!empty($_SERVER['HTTP_HOST'])) { $this->url = 'http://' . $_SERVER['HTTP_HOST']; } else { $this->url = ''; } } else { // Strip any trailing slashes for consistency (relative // URLs may already start with a slash like "/file.html") if (substr($url, -1) == '/') { $url = substr($url, 0, -1); } $this->url = $url; } }
php
function set_base_url($url = '') { if (empty($url)) { if (!empty($_SERVER['HTTP_HOST'])) { $this->url = 'http://' . $_SERVER['HTTP_HOST']; } else { $this->url = ''; } } else { // Strip any trailing slashes for consistency (relative // URLs may already start with a slash like "/file.html") if (substr($url, -1) == '/') { $url = substr($url, 0, -1); } $this->url = $url; } }
[ "function", "set_base_url", "(", "$", "url", "=", "''", ")", "{", "if", "(", "empty", "(", "$", "url", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "_SERVER", "[", "'HTTP_HOST'", "]", ")", ")", "{", "$", "this", "->", "url", "=", "'http://'", ".", "$", "_SERVER", "[", "'HTTP_HOST'", "]", ";", "}", "else", "{", "$", "this", "->", "url", "=", "''", ";", "}", "}", "else", "{", "// Strip any trailing slashes for consistency (relative", "// URLs may already start with a slash like \"/file.html\")", "if", "(", "substr", "(", "$", "url", ",", "-", "1", ")", "==", "'/'", ")", "{", "$", "url", "=", "substr", "(", "$", "url", ",", "0", ",", "-", "1", ")", ";", "}", "$", "this", "->", "url", "=", "$", "url", ";", "}", "}" ]
Sets a base URL to handle relative links.
[ "Sets", "a", "base", "URL", "to", "handle", "relative", "links", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_html2text.php#L404-L422
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_html2text.php
rcube_html2text.blockquote_citation_callback
public function blockquote_citation_callback($m) { $line = ltrim($m[2]); $space = $line[0] == '>' ? '' : ' '; return $m[1] . '>' . $space . $line; }
php
public function blockquote_citation_callback($m) { $line = ltrim($m[2]); $space = $line[0] == '>' ? '' : ' '; return $m[1] . '>' . $space . $line; }
[ "public", "function", "blockquote_citation_callback", "(", "$", "m", ")", "{", "$", "line", "=", "ltrim", "(", "$", "m", "[", "2", "]", ")", ";", "$", "space", "=", "$", "line", "[", "0", "]", "==", "'>'", "?", "''", ":", "' '", ";", "return", "$", "m", "[", "1", "]", ".", "'>'", ".", "$", "space", ".", "$", "line", ";", "}" ]
Callback function to correctly add citation markers for blockquote contents
[ "Callback", "function", "to", "correctly", "add", "citation", "markers", "for", "blockquote", "contents" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_html2text.php#L645-L651
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_image.php
rcube_image.props
public function props() { // use GD extension if (function_exists('getimagesize') && ($imsize = @getimagesize($this->image_file))) { $width = $imsize[0]; $height = $imsize[1]; $gd_type = $imsize[2]; $type = image_type_to_extension($gd_type, false); $channels = $imsize['channels']; } // use ImageMagick if (!$type && ($data = $this->identify())) { list($type, $width, $height) = $data; $channels = null; } if ($type) { return array( 'type' => $type, 'gd_type' => $gd_type, 'width' => $width, 'height' => $height, 'channels' => $channels, ); } return null; }
php
public function props() { // use GD extension if (function_exists('getimagesize') && ($imsize = @getimagesize($this->image_file))) { $width = $imsize[0]; $height = $imsize[1]; $gd_type = $imsize[2]; $type = image_type_to_extension($gd_type, false); $channels = $imsize['channels']; } // use ImageMagick if (!$type && ($data = $this->identify())) { list($type, $width, $height) = $data; $channels = null; } if ($type) { return array( 'type' => $type, 'gd_type' => $gd_type, 'width' => $width, 'height' => $height, 'channels' => $channels, ); } return null; }
[ "public", "function", "props", "(", ")", "{", "// use GD extension", "if", "(", "function_exists", "(", "'getimagesize'", ")", "&&", "(", "$", "imsize", "=", "@", "getimagesize", "(", "$", "this", "->", "image_file", ")", ")", ")", "{", "$", "width", "=", "$", "imsize", "[", "0", "]", ";", "$", "height", "=", "$", "imsize", "[", "1", "]", ";", "$", "gd_type", "=", "$", "imsize", "[", "2", "]", ";", "$", "type", "=", "image_type_to_extension", "(", "$", "gd_type", ",", "false", ")", ";", "$", "channels", "=", "$", "imsize", "[", "'channels'", "]", ";", "}", "// use ImageMagick", "if", "(", "!", "$", "type", "&&", "(", "$", "data", "=", "$", "this", "->", "identify", "(", ")", ")", ")", "{", "list", "(", "$", "type", ",", "$", "width", ",", "$", "height", ")", "=", "$", "data", ";", "$", "channels", "=", "null", ";", "}", "if", "(", "$", "type", ")", "{", "return", "array", "(", "'type'", "=>", "$", "type", ",", "'gd_type'", "=>", "$", "gd_type", ",", "'width'", "=>", "$", "width", ",", "'height'", "=>", "$", "height", ",", "'channels'", "=>", "$", "channels", ",", ")", ";", "}", "return", "null", ";", "}" ]
Get image properties. @return mixed Hash array with image props like type, width, height
[ "Get", "image", "properties", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_image.php#L59-L87
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_image.php
rcube_image.is_convertable
public static function is_convertable($mimetype = null) { $rcube = rcube::get_instance(); // @TODO: check if specified mimetype is really supported return class_exists('Imagick', false) || $rcube->config->get('im_convert_path'); }
php
public static function is_convertable($mimetype = null) { $rcube = rcube::get_instance(); // @TODO: check if specified mimetype is really supported return class_exists('Imagick', false) || $rcube->config->get('im_convert_path'); }
[ "public", "static", "function", "is_convertable", "(", "$", "mimetype", "=", "null", ")", "{", "$", "rcube", "=", "rcube", "::", "get_instance", "(", ")", ";", "// @TODO: check if specified mimetype is really supported", "return", "class_exists", "(", "'Imagick'", ",", "false", ")", "||", "$", "rcube", "->", "config", "->", "get", "(", "'im_convert_path'", ")", ";", "}" ]
Checks if image format conversion is supported @return boolean True if specified format can be converted to another format
[ "Checks", "if", "image", "format", "conversion", "is", "supported" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_image.php#L403-L409
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_image.php
rcube_image.identify
private function identify() { $rcube = rcube::get_instance(); // use ImageMagick in command line if ($cmd = $rcube->config->get('im_identify_path')) { $args = array('in' => $this->image_file, 'format' => "%m %[fx:w] %[fx:h]"); $id = rcube::exec($cmd. ' 2>/dev/null -format {format} {in}', $args); if ($id) { return explode(' ', strtolower($id)); } } // use PHP's Imagick class if (class_exists('Imagick', false)) { try { $image = new Imagick($this->image_file); return array( strtolower($image->getImageFormat()), $image->getImageWidth(), $image->getImageHeight(), ); } catch (Exception $e) {} } }
php
private function identify() { $rcube = rcube::get_instance(); // use ImageMagick in command line if ($cmd = $rcube->config->get('im_identify_path')) { $args = array('in' => $this->image_file, 'format' => "%m %[fx:w] %[fx:h]"); $id = rcube::exec($cmd. ' 2>/dev/null -format {format} {in}', $args); if ($id) { return explode(' ', strtolower($id)); } } // use PHP's Imagick class if (class_exists('Imagick', false)) { try { $image = new Imagick($this->image_file); return array( strtolower($image->getImageFormat()), $image->getImageWidth(), $image->getImageHeight(), ); } catch (Exception $e) {} } }
[ "private", "function", "identify", "(", ")", "{", "$", "rcube", "=", "rcube", "::", "get_instance", "(", ")", ";", "// use ImageMagick in command line", "if", "(", "$", "cmd", "=", "$", "rcube", "->", "config", "->", "get", "(", "'im_identify_path'", ")", ")", "{", "$", "args", "=", "array", "(", "'in'", "=>", "$", "this", "->", "image_file", ",", "'format'", "=>", "\"%m %[fx:w] %[fx:h]\"", ")", ";", "$", "id", "=", "rcube", "::", "exec", "(", "$", "cmd", ".", "' 2>/dev/null -format {format} {in}'", ",", "$", "args", ")", ";", "if", "(", "$", "id", ")", "{", "return", "explode", "(", "' '", ",", "strtolower", "(", "$", "id", ")", ")", ";", "}", "}", "// use PHP's Imagick class", "if", "(", "class_exists", "(", "'Imagick'", ",", "false", ")", ")", "{", "try", "{", "$", "image", "=", "new", "Imagick", "(", "$", "this", "->", "image_file", ")", ";", "return", "array", "(", "strtolower", "(", "$", "image", "->", "getImageFormat", "(", ")", ")", ",", "$", "image", "->", "getImageWidth", "(", ")", ",", "$", "image", "->", "getImageHeight", "(", ")", ",", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "}", "}", "}" ]
ImageMagick based image properties read.
[ "ImageMagick", "based", "image", "properties", "read", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_image.php#L414-L441
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_image.php
rcube_image.mem_check
private function mem_check($props) { // image size is unknown, we can't calculate required memory if (!$props['width']) { return true; } // channels: CMYK - 4, RGB - 3 $multip = ($props['channels'] ?: 3) + 1; // calculate image size in memory (in bytes) $size = $props['width'] * $props['height'] * $multip; return rcube_utils::mem_check($size); }
php
private function mem_check($props) { // image size is unknown, we can't calculate required memory if (!$props['width']) { return true; } // channels: CMYK - 4, RGB - 3 $multip = ($props['channels'] ?: 3) + 1; // calculate image size in memory (in bytes) $size = $props['width'] * $props['height'] * $multip; return rcube_utils::mem_check($size); }
[ "private", "function", "mem_check", "(", "$", "props", ")", "{", "// image size is unknown, we can't calculate required memory", "if", "(", "!", "$", "props", "[", "'width'", "]", ")", "{", "return", "true", ";", "}", "// channels: CMYK - 4, RGB - 3", "$", "multip", "=", "(", "$", "props", "[", "'channels'", "]", "?", ":", "3", ")", "+", "1", ";", "// calculate image size in memory (in bytes)", "$", "size", "=", "$", "props", "[", "'width'", "]", "*", "$", "props", "[", "'height'", "]", "*", "$", "multip", ";", "return", "rcube_utils", "::", "mem_check", "(", "$", "size", ")", ";", "}" ]
Check if we have enough memory to load specified image
[ "Check", "if", "we", "have", "enough", "memory", "to", "load", "specified", "image" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_image.php#L446-L459
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_washtml.php
rcube_washtml.wash_style
private function wash_style($style) { $result = array(); // Remove unwanted white-space characters so regular expressions below work better $style = preg_replace('/[\n\r\s\t]+/', ' ', $style); // Decode insecure character sequences $style = rcube_utils::xss_entity_decode($style); foreach (explode(';', $style) as $declaration) { if (preg_match('/^\s*([a-z\\\-]+)\s*:\s*(.*)\s*$/i', $declaration, $match)) { $cssid = $match[1]; $str = $match[2]; $value = ''; foreach ($this->explode_style($str) as $val) { if (preg_match('/^url\(/i', $val)) { if (preg_match('/^url\(\s*[\'"]?([^\'"\)]*)[\'"]?\s*\)/iu', $val, $match)) { if ($url = $this->wash_uri($match[1])) { $value .= ' url(' . htmlspecialchars($url, ENT_QUOTES) . ')'; } } } else if (!preg_match('/^(behavior|expression)/i', $val)) { // Set position:fixed to position:absolute for security (#5264) if (!strcasecmp($cssid, 'position') && !strcasecmp($val, 'fixed')) { $val = 'absolute'; } // whitelist ? $value .= ' ' . $val; // #1488535: Fix size units, so width:800 would be changed to width:800px if (preg_match('/^(left|right|top|bottom|width|height)/i', $cssid) && preg_match('/^[0-9]+$/', $val) ) { $value .= 'px'; } } } if (isset($value[0])) { $result[] = $cssid . ':' . $value; } } } return implode('; ', $result); }
php
private function wash_style($style) { $result = array(); // Remove unwanted white-space characters so regular expressions below work better $style = preg_replace('/[\n\r\s\t]+/', ' ', $style); // Decode insecure character sequences $style = rcube_utils::xss_entity_decode($style); foreach (explode(';', $style) as $declaration) { if (preg_match('/^\s*([a-z\\\-]+)\s*:\s*(.*)\s*$/i', $declaration, $match)) { $cssid = $match[1]; $str = $match[2]; $value = ''; foreach ($this->explode_style($str) as $val) { if (preg_match('/^url\(/i', $val)) { if (preg_match('/^url\(\s*[\'"]?([^\'"\)]*)[\'"]?\s*\)/iu', $val, $match)) { if ($url = $this->wash_uri($match[1])) { $value .= ' url(' . htmlspecialchars($url, ENT_QUOTES) . ')'; } } } else if (!preg_match('/^(behavior|expression)/i', $val)) { // Set position:fixed to position:absolute for security (#5264) if (!strcasecmp($cssid, 'position') && !strcasecmp($val, 'fixed')) { $val = 'absolute'; } // whitelist ? $value .= ' ' . $val; // #1488535: Fix size units, so width:800 would be changed to width:800px if (preg_match('/^(left|right|top|bottom|width|height)/i', $cssid) && preg_match('/^[0-9]+$/', $val) ) { $value .= 'px'; } } } if (isset($value[0])) { $result[] = $cssid . ':' . $value; } } } return implode('; ', $result); }
[ "private", "function", "wash_style", "(", "$", "style", ")", "{", "$", "result", "=", "array", "(", ")", ";", "// Remove unwanted white-space characters so regular expressions below work better", "$", "style", "=", "preg_replace", "(", "'/[\\n\\r\\s\\t]+/'", ",", "' '", ",", "$", "style", ")", ";", "// Decode insecure character sequences", "$", "style", "=", "rcube_utils", "::", "xss_entity_decode", "(", "$", "style", ")", ";", "foreach", "(", "explode", "(", "';'", ",", "$", "style", ")", "as", "$", "declaration", ")", "{", "if", "(", "preg_match", "(", "'/^\\s*([a-z\\\\\\-]+)\\s*:\\s*(.*)\\s*$/i'", ",", "$", "declaration", ",", "$", "match", ")", ")", "{", "$", "cssid", "=", "$", "match", "[", "1", "]", ";", "$", "str", "=", "$", "match", "[", "2", "]", ";", "$", "value", "=", "''", ";", "foreach", "(", "$", "this", "->", "explode_style", "(", "$", "str", ")", "as", "$", "val", ")", "{", "if", "(", "preg_match", "(", "'/^url\\(/i'", ",", "$", "val", ")", ")", "{", "if", "(", "preg_match", "(", "'/^url\\(\\s*[\\'\"]?([^\\'\"\\)]*)[\\'\"]?\\s*\\)/iu'", ",", "$", "val", ",", "$", "match", ")", ")", "{", "if", "(", "$", "url", "=", "$", "this", "->", "wash_uri", "(", "$", "match", "[", "1", "]", ")", ")", "{", "$", "value", ".=", "' url('", ".", "htmlspecialchars", "(", "$", "url", ",", "ENT_QUOTES", ")", ".", "')'", ";", "}", "}", "}", "else", "if", "(", "!", "preg_match", "(", "'/^(behavior|expression)/i'", ",", "$", "val", ")", ")", "{", "// Set position:fixed to position:absolute for security (#5264)", "if", "(", "!", "strcasecmp", "(", "$", "cssid", ",", "'position'", ")", "&&", "!", "strcasecmp", "(", "$", "val", ",", "'fixed'", ")", ")", "{", "$", "val", "=", "'absolute'", ";", "}", "// whitelist ?", "$", "value", ".=", "' '", ".", "$", "val", ";", "// #1488535: Fix size units, so width:800 would be changed to width:800px", "if", "(", "preg_match", "(", "'/^(left|right|top|bottom|width|height)/i'", ",", "$", "cssid", ")", "&&", "preg_match", "(", "'/^[0-9]+$/'", ",", "$", "val", ")", ")", "{", "$", "value", ".=", "'px'", ";", "}", "}", "}", "if", "(", "isset", "(", "$", "value", "[", "0", "]", ")", ")", "{", "$", "result", "[", "]", "=", "$", "cssid", ".", "':'", ".", "$", "value", ";", "}", "}", "}", "return", "implode", "(", "'; '", ",", "$", "result", ")", ";", "}" ]
Check CSS style
[ "Check", "CSS", "style" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_washtml.php#L238-L287
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_washtml.php
rcube_washtml.wash_uri
private function wash_uri($uri, $blocked_source = false) { if (($src = $this->config['cid_map'][$uri]) || ($src = $this->config['cid_map'][$this->config['base_url'].$uri]) ) { return $src; } // allow url(#id) used in SVG if ($uri[0] == '#') { return $uri; } if (preg_match('/^(http|https|ftp):.+/i', $uri)) { if ($this->config['allow_remote']) { return $uri; } $this->extlinks = true; if ($blocked_source && $this->config['blocked_src']) { return $this->config['blocked_src']; } } else if (preg_match('/^data:image.+/i', $uri)) { // RFC2397 return $uri; } }
php
private function wash_uri($uri, $blocked_source = false) { if (($src = $this->config['cid_map'][$uri]) || ($src = $this->config['cid_map'][$this->config['base_url'].$uri]) ) { return $src; } // allow url(#id) used in SVG if ($uri[0] == '#') { return $uri; } if (preg_match('/^(http|https|ftp):.+/i', $uri)) { if ($this->config['allow_remote']) { return $uri; } $this->extlinks = true; if ($blocked_source && $this->config['blocked_src']) { return $this->config['blocked_src']; } } else if (preg_match('/^data:image.+/i', $uri)) { // RFC2397 return $uri; } }
[ "private", "function", "wash_uri", "(", "$", "uri", ",", "$", "blocked_source", "=", "false", ")", "{", "if", "(", "(", "$", "src", "=", "$", "this", "->", "config", "[", "'cid_map'", "]", "[", "$", "uri", "]", ")", "||", "(", "$", "src", "=", "$", "this", "->", "config", "[", "'cid_map'", "]", "[", "$", "this", "->", "config", "[", "'base_url'", "]", ".", "$", "uri", "]", ")", ")", "{", "return", "$", "src", ";", "}", "// allow url(#id) used in SVG", "if", "(", "$", "uri", "[", "0", "]", "==", "'#'", ")", "{", "return", "$", "uri", ";", "}", "if", "(", "preg_match", "(", "'/^(http|https|ftp):.+/i'", ",", "$", "uri", ")", ")", "{", "if", "(", "$", "this", "->", "config", "[", "'allow_remote'", "]", ")", "{", "return", "$", "uri", ";", "}", "$", "this", "->", "extlinks", "=", "true", ";", "if", "(", "$", "blocked_source", "&&", "$", "this", "->", "config", "[", "'blocked_src'", "]", ")", "{", "return", "$", "this", "->", "config", "[", "'blocked_src'", "]", ";", "}", "}", "else", "if", "(", "preg_match", "(", "'/^data:image.+/i'", ",", "$", "uri", ")", ")", "{", "// RFC2397", "return", "$", "uri", ";", "}", "}" ]
Wash URI value
[ "Wash", "URI", "value" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_washtml.php#L370-L396
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_washtml.php
rcube_washtml.cleanup
private function cleanup($html) { $html = trim($html); // special replacements (not properly handled by washtml class) $html_search = array( // space(s) between <NOBR> '/(<\/nobr>)(\s+)(<nobr>)/i', // PHP bug #32547 workaround: remove title tag '/<title[^>]*>[^<]*<\/title>/i', // remove <!doctype> before BOM (#1490291) '/<\!doctype[^>]+>[^<]*/im', // byte-order mark (only outlook?) '/^(\0\0\xFE\xFF|\xFF\xFE\0\0|\xFE\xFF|\xFF\xFE|\xEF\xBB\xBF)/', // washtml/DOMDocument cannot handle xml namespaces '/<html\s[^>]+>/i', ); $html_replace = array( '\\1'.' &nbsp; '.'\\3', '', '', '', '<html>', ); $html = preg_replace($html_search, $html_replace, trim($html)); // Replace all of those weird MS Word quotes and other high characters $badwordchars = array( "\xe2\x80\x98", // left single quote "\xe2\x80\x99", // right single quote "\xe2\x80\x9c", // left double quote "\xe2\x80\x9d", // right double quote "\xe2\x80\x94", // em dash "\xe2\x80\xa6" // elipses ); $fixedwordchars = array( "'", "'", '"', '"', '&mdash;', '...' ); $html = str_replace($badwordchars, $fixedwordchars, $html); // PCRE errors handling (#1486856), should we use something like for every preg_* use? if ($html === null && ($preg_error = preg_last_error()) != PREG_NO_ERROR) { $errstr = "Could not clean up HTML message! PCRE Error: $preg_error."; if ($preg_error == PREG_BACKTRACK_LIMIT_ERROR) { $errstr .= " Consider raising pcre.backtrack_limit!"; } if ($preg_error == PREG_RECURSION_LIMIT_ERROR) { $errstr .= " Consider raising pcre.recursion_limit!"; } rcube::raise_error(array('code' => 620, 'type' => 'php', 'line' => __LINE__, 'file' => __FILE__, 'message' => $errstr), true, false); return ''; } // FIXME: HTML comments handling could be better. The code below can break comments (#6464), // we should probably do not modify content inside comments at all. // fix (unknown/malformed) HTML tags before "wash" $html = preg_replace_callback('/(<(?!\!)[\/]*)([^\s>]+)([^>]*)/', array($this, 'html_tag_callback'), $html); // Remove invalid HTML comments (#1487759) // Note: We don't want to remove valid comments, conditional comments // and MSOutlook comments (<!-->) $html = preg_replace('/<!--[a-zA-Z0-9]+>/', '', $html); // fix broken nested lists self::fix_broken_lists($html); // turn relative into absolute urls $html = self::resolve_base($html); return $html; }
php
private function cleanup($html) { $html = trim($html); // special replacements (not properly handled by washtml class) $html_search = array( // space(s) between <NOBR> '/(<\/nobr>)(\s+)(<nobr>)/i', // PHP bug #32547 workaround: remove title tag '/<title[^>]*>[^<]*<\/title>/i', // remove <!doctype> before BOM (#1490291) '/<\!doctype[^>]+>[^<]*/im', // byte-order mark (only outlook?) '/^(\0\0\xFE\xFF|\xFF\xFE\0\0|\xFE\xFF|\xFF\xFE|\xEF\xBB\xBF)/', // washtml/DOMDocument cannot handle xml namespaces '/<html\s[^>]+>/i', ); $html_replace = array( '\\1'.' &nbsp; '.'\\3', '', '', '', '<html>', ); $html = preg_replace($html_search, $html_replace, trim($html)); // Replace all of those weird MS Word quotes and other high characters $badwordchars = array( "\xe2\x80\x98", // left single quote "\xe2\x80\x99", // right single quote "\xe2\x80\x9c", // left double quote "\xe2\x80\x9d", // right double quote "\xe2\x80\x94", // em dash "\xe2\x80\xa6" // elipses ); $fixedwordchars = array( "'", "'", '"', '"', '&mdash;', '...' ); $html = str_replace($badwordchars, $fixedwordchars, $html); // PCRE errors handling (#1486856), should we use something like for every preg_* use? if ($html === null && ($preg_error = preg_last_error()) != PREG_NO_ERROR) { $errstr = "Could not clean up HTML message! PCRE Error: $preg_error."; if ($preg_error == PREG_BACKTRACK_LIMIT_ERROR) { $errstr .= " Consider raising pcre.backtrack_limit!"; } if ($preg_error == PREG_RECURSION_LIMIT_ERROR) { $errstr .= " Consider raising pcre.recursion_limit!"; } rcube::raise_error(array('code' => 620, 'type' => 'php', 'line' => __LINE__, 'file' => __FILE__, 'message' => $errstr), true, false); return ''; } // FIXME: HTML comments handling could be better. The code below can break comments (#6464), // we should probably do not modify content inside comments at all. // fix (unknown/malformed) HTML tags before "wash" $html = preg_replace_callback('/(<(?!\!)[\/]*)([^\s>]+)([^>]*)/', array($this, 'html_tag_callback'), $html); // Remove invalid HTML comments (#1487759) // Note: We don't want to remove valid comments, conditional comments // and MSOutlook comments (<!-->) $html = preg_replace('/<!--[a-zA-Z0-9]+>/', '', $html); // fix broken nested lists self::fix_broken_lists($html); // turn relative into absolute urls $html = self::resolve_base($html); return $html; }
[ "private", "function", "cleanup", "(", "$", "html", ")", "{", "$", "html", "=", "trim", "(", "$", "html", ")", ";", "// special replacements (not properly handled by washtml class)", "$", "html_search", "=", "array", "(", "// space(s) between <NOBR>", "'/(<\\/nobr>)(\\s+)(<nobr>)/i'", ",", "// PHP bug #32547 workaround: remove title tag", "'/<title[^>]*>[^<]*<\\/title>/i'", ",", "// remove <!doctype> before BOM (#1490291)", "'/<\\!doctype[^>]+>[^<]*/im'", ",", "// byte-order mark (only outlook?)", "'/^(\\0\\0\\xFE\\xFF|\\xFF\\xFE\\0\\0|\\xFE\\xFF|\\xFF\\xFE|\\xEF\\xBB\\xBF)/'", ",", "// washtml/DOMDocument cannot handle xml namespaces", "'/<html\\s[^>]+>/i'", ",", ")", ";", "$", "html_replace", "=", "array", "(", "'\\\\1'", ".", "' &nbsp; '", ".", "'\\\\3'", ",", "''", ",", "''", ",", "''", ",", "'<html>'", ",", ")", ";", "$", "html", "=", "preg_replace", "(", "$", "html_search", ",", "$", "html_replace", ",", "trim", "(", "$", "html", ")", ")", ";", "// Replace all of those weird MS Word quotes and other high characters", "$", "badwordchars", "=", "array", "(", "\"\\xe2\\x80\\x98\"", ",", "// left single quote", "\"\\xe2\\x80\\x99\"", ",", "// right single quote", "\"\\xe2\\x80\\x9c\"", ",", "// left double quote", "\"\\xe2\\x80\\x9d\"", ",", "// right double quote", "\"\\xe2\\x80\\x94\"", ",", "// em dash", "\"\\xe2\\x80\\xa6\"", "// elipses", ")", ";", "$", "fixedwordchars", "=", "array", "(", "\"'\"", ",", "\"'\"", ",", "'\"'", ",", "'\"'", ",", "'&mdash;'", ",", "'...'", ")", ";", "$", "html", "=", "str_replace", "(", "$", "badwordchars", ",", "$", "fixedwordchars", ",", "$", "html", ")", ";", "// PCRE errors handling (#1486856), should we use something like for every preg_* use?", "if", "(", "$", "html", "===", "null", "&&", "(", "$", "preg_error", "=", "preg_last_error", "(", ")", ")", "!=", "PREG_NO_ERROR", ")", "{", "$", "errstr", "=", "\"Could not clean up HTML message! PCRE Error: $preg_error.\"", ";", "if", "(", "$", "preg_error", "==", "PREG_BACKTRACK_LIMIT_ERROR", ")", "{", "$", "errstr", ".=", "\" Consider raising pcre.backtrack_limit!\"", ";", "}", "if", "(", "$", "preg_error", "==", "PREG_RECURSION_LIMIT_ERROR", ")", "{", "$", "errstr", ".=", "\" Consider raising pcre.recursion_limit!\"", ";", "}", "rcube", "::", "raise_error", "(", "array", "(", "'code'", "=>", "620", ",", "'type'", "=>", "'php'", ",", "'line'", "=>", "__LINE__", ",", "'file'", "=>", "__FILE__", ",", "'message'", "=>", "$", "errstr", ")", ",", "true", ",", "false", ")", ";", "return", "''", ";", "}", "// FIXME: HTML comments handling could be better. The code below can break comments (#6464),", "// we should probably do not modify content inside comments at all.", "// fix (unknown/malformed) HTML tags before \"wash\"", "$", "html", "=", "preg_replace_callback", "(", "'/(<(?!\\!)[\\/]*)([^\\s>]+)([^>]*)/'", ",", "array", "(", "$", "this", ",", "'html_tag_callback'", ")", ",", "$", "html", ")", ";", "// Remove invalid HTML comments (#1487759)", "// Note: We don't want to remove valid comments, conditional comments", "// and MSOutlook comments (<!-->)", "$", "html", "=", "preg_replace", "(", "'/<!--[a-zA-Z0-9]+>/'", ",", "''", ",", "$", "html", ")", ";", "// fix broken nested lists", "self", "::", "fix_broken_lists", "(", "$", "html", ")", ";", "// turn relative into absolute urls", "$", "html", "=", "self", "::", "resolve_base", "(", "$", "html", ")", ";", "return", "$", "html", ";", "}" ]
Clean HTML input
[ "Clean", "HTML", "input" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_washtml.php#L568-L653
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_washtml.php
rcube_washtml.html_tag_callback
public static function html_tag_callback($matches) { // It might be an ending of a comment, ignore (#6464) if (substr($matches[3], -2) == '--') { $matches[0] = ''; return implode('', $matches); } $tagname = $matches[2]; $tagname = preg_replace(array( '/:.*$/', // Microsoft's Smart Tags <st1:xxxx> '/[^a-z0-9_\[\]\!?-]/i', // forbidden characters ), '', $tagname); // fix invalid closing tags - remove any attributes (#1489446) if ($matches[1] == '</') { $matches[3] = ''; } return $matches[1] . $tagname . $matches[3]; }
php
public static function html_tag_callback($matches) { // It might be an ending of a comment, ignore (#6464) if (substr($matches[3], -2) == '--') { $matches[0] = ''; return implode('', $matches); } $tagname = $matches[2]; $tagname = preg_replace(array( '/:.*$/', // Microsoft's Smart Tags <st1:xxxx> '/[^a-z0-9_\[\]\!?-]/i', // forbidden characters ), '', $tagname); // fix invalid closing tags - remove any attributes (#1489446) if ($matches[1] == '</') { $matches[3] = ''; } return $matches[1] . $tagname . $matches[3]; }
[ "public", "static", "function", "html_tag_callback", "(", "$", "matches", ")", "{", "// It might be an ending of a comment, ignore (#6464)", "if", "(", "substr", "(", "$", "matches", "[", "3", "]", ",", "-", "2", ")", "==", "'--'", ")", "{", "$", "matches", "[", "0", "]", "=", "''", ";", "return", "implode", "(", "''", ",", "$", "matches", ")", ";", "}", "$", "tagname", "=", "$", "matches", "[", "2", "]", ";", "$", "tagname", "=", "preg_replace", "(", "array", "(", "'/:.*$/'", ",", "// Microsoft's Smart Tags <st1:xxxx>", "'/[^a-z0-9_\\[\\]\\!?-]/i'", ",", "// forbidden characters", ")", ",", "''", ",", "$", "tagname", ")", ";", "// fix invalid closing tags - remove any attributes (#1489446)", "if", "(", "$", "matches", "[", "1", "]", "==", "'</'", ")", "{", "$", "matches", "[", "3", "]", "=", "''", ";", "}", "return", "$", "matches", "[", "1", "]", ".", "$", "tagname", ".", "$", "matches", "[", "3", "]", ";", "}" ]
Callback function for HTML tags fixing
[ "Callback", "function", "for", "HTML", "tags", "fixing" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_washtml.php#L658-L678
train
i-MSCP/roundcube
roundcubemail/program/lib/Roundcube/rcube_washtml.php
rcube_washtml.explode_style
protected function explode_style($style) { $pos = 0; // first remove comments while (($pos = strpos($style, '/*', $pos)) !== false) { $end = strpos($style, '*/', $pos+2); if ($end === false) { $style = substr($style, 0, $pos); } else { $style = substr_replace($style, '', $pos, $end - $pos + 2); } } $style = trim($style); $strlen = strlen($style); $result = array(); // explode value for ($p=$i=0; $i < $strlen; $i++) { if (($style[$i] == "\"" || $style[$i] == "'") && $style[$i-1] != "\\") { if ($q == $style[$i]) { $q = false; } else if (!$q) { $q = $style[$i]; } } if (!$q && $style[$i] == ' ' && !preg_match('/[,\(]/', $style[$i-1])) { $result[] = substr($style, $p, $i - $p); $p = $i + 1; } } $result[] = (string) substr($style, $p); return $result; }
php
protected function explode_style($style) { $pos = 0; // first remove comments while (($pos = strpos($style, '/*', $pos)) !== false) { $end = strpos($style, '*/', $pos+2); if ($end === false) { $style = substr($style, 0, $pos); } else { $style = substr_replace($style, '', $pos, $end - $pos + 2); } } $style = trim($style); $strlen = strlen($style); $result = array(); // explode value for ($p=$i=0; $i < $strlen; $i++) { if (($style[$i] == "\"" || $style[$i] == "'") && $style[$i-1] != "\\") { if ($q == $style[$i]) { $q = false; } else if (!$q) { $q = $style[$i]; } } if (!$q && $style[$i] == ' ' && !preg_match('/[,\(]/', $style[$i-1])) { $result[] = substr($style, $p, $i - $p); $p = $i + 1; } } $result[] = (string) substr($style, $p); return $result; }
[ "protected", "function", "explode_style", "(", "$", "style", ")", "{", "$", "pos", "=", "0", ";", "// first remove comments", "while", "(", "(", "$", "pos", "=", "strpos", "(", "$", "style", ",", "'/*'", ",", "$", "pos", ")", ")", "!==", "false", ")", "{", "$", "end", "=", "strpos", "(", "$", "style", ",", "'*/'", ",", "$", "pos", "+", "2", ")", ";", "if", "(", "$", "end", "===", "false", ")", "{", "$", "style", "=", "substr", "(", "$", "style", ",", "0", ",", "$", "pos", ")", ";", "}", "else", "{", "$", "style", "=", "substr_replace", "(", "$", "style", ",", "''", ",", "$", "pos", ",", "$", "end", "-", "$", "pos", "+", "2", ")", ";", "}", "}", "$", "style", "=", "trim", "(", "$", "style", ")", ";", "$", "strlen", "=", "strlen", "(", "$", "style", ")", ";", "$", "result", "=", "array", "(", ")", ";", "// explode value", "for", "(", "$", "p", "=", "$", "i", "=", "0", ";", "$", "i", "<", "$", "strlen", ";", "$", "i", "++", ")", "{", "if", "(", "(", "$", "style", "[", "$", "i", "]", "==", "\"\\\"\"", "||", "$", "style", "[", "$", "i", "]", "==", "\"'\"", ")", "&&", "$", "style", "[", "$", "i", "-", "1", "]", "!=", "\"\\\\\"", ")", "{", "if", "(", "$", "q", "==", "$", "style", "[", "$", "i", "]", ")", "{", "$", "q", "=", "false", ";", "}", "else", "if", "(", "!", "$", "q", ")", "{", "$", "q", "=", "$", "style", "[", "$", "i", "]", ";", "}", "}", "if", "(", "!", "$", "q", "&&", "$", "style", "[", "$", "i", "]", "==", "' '", "&&", "!", "preg_match", "(", "'/[,\\(]/'", ",", "$", "style", "[", "$", "i", "-", "1", "]", ")", ")", "{", "$", "result", "[", "]", "=", "substr", "(", "$", "style", ",", "$", "p", ",", "$", "i", "-", "$", "p", ")", ";", "$", "p", "=", "$", "i", "+", "1", ";", "}", "}", "$", "result", "[", "]", "=", "(", "string", ")", "substr", "(", "$", "style", ",", "$", "p", ")", ";", "return", "$", "result", ";", "}" ]
Explode css style value
[ "Explode", "css", "style", "value" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/lib/Roundcube/rcube_washtml.php#L770-L810
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.set_env
public function set_env($name, $value, $addtojs = true) { $this->env[$name] = $value; if ($addtojs || isset($this->js_env[$name])) { $this->js_env[$name] = $value; } }
php
public function set_env($name, $value, $addtojs = true) { $this->env[$name] = $value; if ($addtojs || isset($this->js_env[$name])) { $this->js_env[$name] = $value; } }
[ "public", "function", "set_env", "(", "$", "name", ",", "$", "value", ",", "$", "addtojs", "=", "true", ")", "{", "$", "this", "->", "env", "[", "$", "name", "]", "=", "$", "value", ";", "if", "(", "$", "addtojs", "||", "isset", "(", "$", "this", "->", "js_env", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "js_env", "[", "$", "name", "]", "=", "$", "value", ";", "}", "}" ]
Set environment variable @param string $name Property name @param mixed $value Property value @param boolean $addtojs True if this property should be added to client environment
[ "Set", "environment", "variable" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L143-L150
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.set_assets_path
public function set_assets_path($path, $fs_dir = null) { if (empty($path)) { return; } $path = rtrim($path, '/') . '/'; // handle relative assets path if (!preg_match('|^https?://|', $path) && $path[0] != '/') { // save the path to search for asset files later $this->assets_dir = $path; $base = preg_replace('/[?#&].*$/', '', $_SERVER['REQUEST_URI']); $base = rtrim($base, '/'); // remove url token if exists if ($len = intval($this->config->get('use_secure_urls'))) { $_base = explode('/', $base); $last = count($_base) - 1; $length = $len > 1 ? $len : 16; // as in rcube::get_secure_url_token() // we can't use real token here because it // does not exists in unauthenticated state, // hope this will not produce false-positive matches if ($last > -1 && preg_match('/^[a-f0-9]{' . $length . '}$/', $_base[$last])) { $path = '../' . $path; } } } // set filesystem path for assets if ($fs_dir) { if ($fs_dir[0] != '/') { $fs_dir = realpath(RCUBE_INSTALL_PATH . $fs_dir); } // ensure the path ends with a slash $this->assets_dir = rtrim($fs_dir, '/') . '/'; } $this->assets_path = $path; $this->set_env('assets_path', $path); }
php
public function set_assets_path($path, $fs_dir = null) { if (empty($path)) { return; } $path = rtrim($path, '/') . '/'; // handle relative assets path if (!preg_match('|^https?://|', $path) && $path[0] != '/') { // save the path to search for asset files later $this->assets_dir = $path; $base = preg_replace('/[?#&].*$/', '', $_SERVER['REQUEST_URI']); $base = rtrim($base, '/'); // remove url token if exists if ($len = intval($this->config->get('use_secure_urls'))) { $_base = explode('/', $base); $last = count($_base) - 1; $length = $len > 1 ? $len : 16; // as in rcube::get_secure_url_token() // we can't use real token here because it // does not exists in unauthenticated state, // hope this will not produce false-positive matches if ($last > -1 && preg_match('/^[a-f0-9]{' . $length . '}$/', $_base[$last])) { $path = '../' . $path; } } } // set filesystem path for assets if ($fs_dir) { if ($fs_dir[0] != '/') { $fs_dir = realpath(RCUBE_INSTALL_PATH . $fs_dir); } // ensure the path ends with a slash $this->assets_dir = rtrim($fs_dir, '/') . '/'; } $this->assets_path = $path; $this->set_env('assets_path', $path); }
[ "public", "function", "set_assets_path", "(", "$", "path", ",", "$", "fs_dir", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "path", ")", ")", "{", "return", ";", "}", "$", "path", "=", "rtrim", "(", "$", "path", ",", "'/'", ")", ".", "'/'", ";", "// handle relative assets path", "if", "(", "!", "preg_match", "(", "'|^https?://|'", ",", "$", "path", ")", "&&", "$", "path", "[", "0", "]", "!=", "'/'", ")", "{", "// save the path to search for asset files later", "$", "this", "->", "assets_dir", "=", "$", "path", ";", "$", "base", "=", "preg_replace", "(", "'/[?#&].*$/'", ",", "''", ",", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ")", ";", "$", "base", "=", "rtrim", "(", "$", "base", ",", "'/'", ")", ";", "// remove url token if exists", "if", "(", "$", "len", "=", "intval", "(", "$", "this", "->", "config", "->", "get", "(", "'use_secure_urls'", ")", ")", ")", "{", "$", "_base", "=", "explode", "(", "'/'", ",", "$", "base", ")", ";", "$", "last", "=", "count", "(", "$", "_base", ")", "-", "1", ";", "$", "length", "=", "$", "len", ">", "1", "?", "$", "len", ":", "16", ";", "// as in rcube::get_secure_url_token()", "// we can't use real token here because it", "// does not exists in unauthenticated state,", "// hope this will not produce false-positive matches", "if", "(", "$", "last", ">", "-", "1", "&&", "preg_match", "(", "'/^[a-f0-9]{'", ".", "$", "length", ".", "'}$/'", ",", "$", "_base", "[", "$", "last", "]", ")", ")", "{", "$", "path", "=", "'../'", ".", "$", "path", ";", "}", "}", "}", "// set filesystem path for assets", "if", "(", "$", "fs_dir", ")", "{", "if", "(", "$", "fs_dir", "[", "0", "]", "!=", "'/'", ")", "{", "$", "fs_dir", "=", "realpath", "(", "RCUBE_INSTALL_PATH", ".", "$", "fs_dir", ")", ";", "}", "// ensure the path ends with a slash", "$", "this", "->", "assets_dir", "=", "rtrim", "(", "$", "fs_dir", ",", "'/'", ")", ".", "'/'", ";", "}", "$", "this", "->", "assets_path", "=", "$", "path", ";", "$", "this", "->", "set_env", "(", "'assets_path'", ",", "$", "path", ")", ";", "}" ]
Parse and set assets path @param string $path Assets path URL (relative or absolute) @param string $fs_dif Assets path in filesystem
[ "Parse", "and", "set", "assets", "path" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L158-L200
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.get_pagetitle
protected function get_pagetitle() { if (!empty($this->pagetitle)) { $title = $this->pagetitle; } else if ($this->env['task'] == 'login') { $title = $this->app->gettext(array( 'name' => 'welcome', 'vars' => array('product' => $this->config->get('product_name') ))); } else { $title = ucfirst($this->env['task']); } return $title; }
php
protected function get_pagetitle() { if (!empty($this->pagetitle)) { $title = $this->pagetitle; } else if ($this->env['task'] == 'login') { $title = $this->app->gettext(array( 'name' => 'welcome', 'vars' => array('product' => $this->config->get('product_name') ))); } else { $title = ucfirst($this->env['task']); } return $title; }
[ "protected", "function", "get_pagetitle", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "pagetitle", ")", ")", "{", "$", "title", "=", "$", "this", "->", "pagetitle", ";", "}", "else", "if", "(", "$", "this", "->", "env", "[", "'task'", "]", "==", "'login'", ")", "{", "$", "title", "=", "$", "this", "->", "app", "->", "gettext", "(", "array", "(", "'name'", "=>", "'welcome'", ",", "'vars'", "=>", "array", "(", "'product'", "=>", "$", "this", "->", "config", "->", "get", "(", "'product_name'", ")", ")", ")", ")", ";", "}", "else", "{", "$", "title", "=", "ucfirst", "(", "$", "this", "->", "env", "[", "'task'", "]", ")", ";", "}", "return", "$", "title", ";", "}" ]
Getter for the current page title @return string The page title
[ "Getter", "for", "the", "current", "page", "title" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L207-L223
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.load_skin
private function load_skin($skin_path) { $this->skin_paths[] = $skin_path; // read meta file and check for dependencies $meta = @file_get_contents(RCUBE_INSTALL_PATH . $skin_path . '/meta.json'); $meta = @json_decode($meta, true); $meta['path'] = $skin_path; $path_elements = explode('/', $skin_path); $skin_id = end($path_elements); if (!$meta['name']) { $meta['name'] = $skin_id; } $this->skins[$skin_id] = $meta; if ($meta['extends']) { $path = RCUBE_INSTALL_PATH . 'skins/'; if (is_dir($path . $meta['extends']) && is_readable($path . $meta['extends'])) { $this->load_skin('skins/' . $meta['extends']); } } }
php
private function load_skin($skin_path) { $this->skin_paths[] = $skin_path; // read meta file and check for dependencies $meta = @file_get_contents(RCUBE_INSTALL_PATH . $skin_path . '/meta.json'); $meta = @json_decode($meta, true); $meta['path'] = $skin_path; $path_elements = explode('/', $skin_path); $skin_id = end($path_elements); if (!$meta['name']) { $meta['name'] = $skin_id; } $this->skins[$skin_id] = $meta; if ($meta['extends']) { $path = RCUBE_INSTALL_PATH . 'skins/'; if (is_dir($path . $meta['extends']) && is_readable($path . $meta['extends'])) { $this->load_skin('skins/' . $meta['extends']); } } }
[ "private", "function", "load_skin", "(", "$", "skin_path", ")", "{", "$", "this", "->", "skin_paths", "[", "]", "=", "$", "skin_path", ";", "// read meta file and check for dependencies", "$", "meta", "=", "@", "file_get_contents", "(", "RCUBE_INSTALL_PATH", ".", "$", "skin_path", ".", "'/meta.json'", ")", ";", "$", "meta", "=", "@", "json_decode", "(", "$", "meta", ",", "true", ")", ";", "$", "meta", "[", "'path'", "]", "=", "$", "skin_path", ";", "$", "path_elements", "=", "explode", "(", "'/'", ",", "$", "skin_path", ")", ";", "$", "skin_id", "=", "end", "(", "$", "path_elements", ")", ";", "if", "(", "!", "$", "meta", "[", "'name'", "]", ")", "{", "$", "meta", "[", "'name'", "]", "=", "$", "skin_id", ";", "}", "$", "this", "->", "skins", "[", "$", "skin_id", "]", "=", "$", "meta", ";", "if", "(", "$", "meta", "[", "'extends'", "]", ")", "{", "$", "path", "=", "RCUBE_INSTALL_PATH", ".", "'skins/'", ";", "if", "(", "is_dir", "(", "$", "path", ".", "$", "meta", "[", "'extends'", "]", ")", "&&", "is_readable", "(", "$", "path", ".", "$", "meta", "[", "'extends'", "]", ")", ")", "{", "$", "this", "->", "load_skin", "(", "'skins/'", ".", "$", "meta", "[", "'extends'", "]", ")", ";", "}", "}", "}" ]
Helper method to recursively read skin meta files and register search paths
[ "Helper", "method", "to", "recursively", "read", "skin", "meta", "files", "and", "register", "search", "paths" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L275-L299
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.template_exists
public function template_exists($name) { foreach ($this->skin_paths as $skin_path) { $filename = RCUBE_INSTALL_PATH . $skin_path . '/templates/' . $name . '.html'; if ((is_file($filename) && is_readable($filename)) || ($this->deprecated_templates[$name] && $this->template_exists($this->deprecated_templates[$name])) ) { return true; } } return false; }
php
public function template_exists($name) { foreach ($this->skin_paths as $skin_path) { $filename = RCUBE_INSTALL_PATH . $skin_path . '/templates/' . $name . '.html'; if ((is_file($filename) && is_readable($filename)) || ($this->deprecated_templates[$name] && $this->template_exists($this->deprecated_templates[$name])) ) { return true; } } return false; }
[ "public", "function", "template_exists", "(", "$", "name", ")", "{", "foreach", "(", "$", "this", "->", "skin_paths", "as", "$", "skin_path", ")", "{", "$", "filename", "=", "RCUBE_INSTALL_PATH", ".", "$", "skin_path", ".", "'/templates/'", ".", "$", "name", ".", "'.html'", ";", "if", "(", "(", "is_file", "(", "$", "filename", ")", "&&", "is_readable", "(", "$", "filename", ")", ")", "||", "(", "$", "this", "->", "deprecated_templates", "[", "$", "name", "]", "&&", "$", "this", "->", "template_exists", "(", "$", "this", "->", "deprecated_templates", "[", "$", "name", "]", ")", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Check if a specific template exists @param string $name Template name @return boolean True if template exists
[ "Check", "if", "a", "specific", "template", "exists" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L308-L320
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.get_skin_file
public function get_skin_file($file, &$skin_path = null, $add_path = null) { $skin_paths = $this->skin_paths; if ($add_path) { array_unshift($skin_paths, $add_path); } foreach ($skin_paths as $skin_path) { $path = realpath(RCUBE_INSTALL_PATH . $skin_path . $file); if ($path && is_file($path)) { return $skin_path . $file; } if ($this->assets_dir != RCUBE_INSTALL_PATH) { $path = realpath($this->assets_dir . $skin_path . $file); if ($path && is_file($path)) { return $skin_path . $file; } } } return false; }
php
public function get_skin_file($file, &$skin_path = null, $add_path = null) { $skin_paths = $this->skin_paths; if ($add_path) { array_unshift($skin_paths, $add_path); } foreach ($skin_paths as $skin_path) { $path = realpath(RCUBE_INSTALL_PATH . $skin_path . $file); if ($path && is_file($path)) { return $skin_path . $file; } if ($this->assets_dir != RCUBE_INSTALL_PATH) { $path = realpath($this->assets_dir . $skin_path . $file); if ($path && is_file($path)) { return $skin_path . $file; } } } return false; }
[ "public", "function", "get_skin_file", "(", "$", "file", ",", "&", "$", "skin_path", "=", "null", ",", "$", "add_path", "=", "null", ")", "{", "$", "skin_paths", "=", "$", "this", "->", "skin_paths", ";", "if", "(", "$", "add_path", ")", "{", "array_unshift", "(", "$", "skin_paths", ",", "$", "add_path", ")", ";", "}", "foreach", "(", "$", "skin_paths", "as", "$", "skin_path", ")", "{", "$", "path", "=", "realpath", "(", "RCUBE_INSTALL_PATH", ".", "$", "skin_path", ".", "$", "file", ")", ";", "if", "(", "$", "path", "&&", "is_file", "(", "$", "path", ")", ")", "{", "return", "$", "skin_path", ".", "$", "file", ";", "}", "if", "(", "$", "this", "->", "assets_dir", "!=", "RCUBE_INSTALL_PATH", ")", "{", "$", "path", "=", "realpath", "(", "$", "this", "->", "assets_dir", ".", "$", "skin_path", ".", "$", "file", ")", ";", "if", "(", "$", "path", "&&", "is_file", "(", "$", "path", ")", ")", "{", "return", "$", "skin_path", ".", "$", "file", ";", "}", "}", "}", "return", "false", ";", "}" ]
Find the given file in the current skin path stack @param string $file File name/path to resolve (starting with /) @param string &$skin_path Reference to the base path of the matching skin @param string $add_path Additional path to search in @return mixed Relative path to the requested file or False if not found
[ "Find", "the", "given", "file", "in", "the", "current", "skin", "path", "stack" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L331-L355
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.reset
public function reset($all = false) { $framed = $this->framed; $env = $all ? null : array_intersect_key($this->env, array('extwin'=>1, 'framed'=>1)); parent::reset(); // let some env variables survive $this->env = $this->js_env = $env; $this->framed = $framed || $this->env['framed']; $this->js_labels = array(); $this->js_commands = array(); $this->script_files = array(); $this->scripts = array(); $this->header = ''; $this->footer = ''; $this->body = ''; // load defaults if (!$all) { $this->__construct(); } }
php
public function reset($all = false) { $framed = $this->framed; $env = $all ? null : array_intersect_key($this->env, array('extwin'=>1, 'framed'=>1)); parent::reset(); // let some env variables survive $this->env = $this->js_env = $env; $this->framed = $framed || $this->env['framed']; $this->js_labels = array(); $this->js_commands = array(); $this->script_files = array(); $this->scripts = array(); $this->header = ''; $this->footer = ''; $this->body = ''; // load defaults if (!$all) { $this->__construct(); } }
[ "public", "function", "reset", "(", "$", "all", "=", "false", ")", "{", "$", "framed", "=", "$", "this", "->", "framed", ";", "$", "env", "=", "$", "all", "?", "null", ":", "array_intersect_key", "(", "$", "this", "->", "env", ",", "array", "(", "'extwin'", "=>", "1", ",", "'framed'", "=>", "1", ")", ")", ";", "parent", "::", "reset", "(", ")", ";", "// let some env variables survive", "$", "this", "->", "env", "=", "$", "this", "->", "js_env", "=", "$", "env", ";", "$", "this", "->", "framed", "=", "$", "framed", "||", "$", "this", "->", "env", "[", "'framed'", "]", ";", "$", "this", "->", "js_labels", "=", "array", "(", ")", ";", "$", "this", "->", "js_commands", "=", "array", "(", ")", ";", "$", "this", "->", "script_files", "=", "array", "(", ")", ";", "$", "this", "->", "scripts", "=", "array", "(", ")", ";", "$", "this", "->", "header", "=", "''", ";", "$", "this", "->", "footer", "=", "''", ";", "$", "this", "->", "body", "=", "''", ";", "// load defaults", "if", "(", "!", "$", "all", ")", "{", "$", "this", "->", "__construct", "(", ")", ";", "}", "}" ]
Delete all stored env variables and commands @param bool $all Reset all env variables (including internal)
[ "Delete", "all", "stored", "env", "variables", "and", "commands" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L431-L453
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.send
public function send($templ = null, $exit = true) { if ($templ != 'iframe') { // prevent from endless loops if ($exit != 'recur' && $this->app->plugins->is_processing('render_page')) { rcube::raise_error(array('code' => 505, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => 'Recursion alert: ignoring output->send()'), true, false); return; } $this->parse($templ, false); } else { $this->framed = true; $this->write(); } // set output asap ob_flush(); flush(); if ($exit) { exit; } }
php
public function send($templ = null, $exit = true) { if ($templ != 'iframe') { // prevent from endless loops if ($exit != 'recur' && $this->app->plugins->is_processing('render_page')) { rcube::raise_error(array('code' => 505, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => 'Recursion alert: ignoring output->send()'), true, false); return; } $this->parse($templ, false); } else { $this->framed = true; $this->write(); } // set output asap ob_flush(); flush(); if ($exit) { exit; } }
[ "public", "function", "send", "(", "$", "templ", "=", "null", ",", "$", "exit", "=", "true", ")", "{", "if", "(", "$", "templ", "!=", "'iframe'", ")", "{", "// prevent from endless loops", "if", "(", "$", "exit", "!=", "'recur'", "&&", "$", "this", "->", "app", "->", "plugins", "->", "is_processing", "(", "'render_page'", ")", ")", "{", "rcube", "::", "raise_error", "(", "array", "(", "'code'", "=>", "505", ",", "'type'", "=>", "'php'", ",", "'file'", "=>", "__FILE__", ",", "'line'", "=>", "__LINE__", ",", "'message'", "=>", "'Recursion alert: ignoring output->send()'", ")", ",", "true", ",", "false", ")", ";", "return", ";", "}", "$", "this", "->", "parse", "(", "$", "templ", ",", "false", ")", ";", "}", "else", "{", "$", "this", "->", "framed", "=", "true", ";", "$", "this", "->", "write", "(", ")", ";", "}", "// set output asap", "ob_flush", "(", ")", ";", "flush", "(", ")", ";", "if", "(", "$", "exit", ")", "{", "exit", ";", "}", "}" ]
Send the request output to the client. This will either parse a skin tempalte or send an AJAX response @param string $templ Template name @param boolean $exit True if script should terminate (default)
[ "Send", "the", "request", "output", "to", "the", "client", ".", "This", "will", "either", "parse", "a", "skin", "tempalte", "or", "send", "an", "AJAX", "response" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L478-L502
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.abs_url
public function abs_url($str, $search_path = false) { if ($str[0] == '/') { if ($search_path && ($file_url = $this->get_skin_file($str, $skin_path))) { return $file_url; } return $this->base_path . $str; } return $str; }
php
public function abs_url($str, $search_path = false) { if ($str[0] == '/') { if ($search_path && ($file_url = $this->get_skin_file($str, $skin_path))) { return $file_url; } return $this->base_path . $str; } return $str; }
[ "public", "function", "abs_url", "(", "$", "str", ",", "$", "search_path", "=", "false", ")", "{", "if", "(", "$", "str", "[", "0", "]", "==", "'/'", ")", "{", "if", "(", "$", "search_path", "&&", "(", "$", "file_url", "=", "$", "this", "->", "get_skin_file", "(", "$", "str", ",", "$", "skin_path", ")", ")", ")", "{", "return", "$", "file_url", ";", "}", "return", "$", "this", "->", "base_path", ".", "$", "str", ";", "}", "return", "$", "str", ";", "}" ]
Make URLs starting with a slash point to skin directory @param string $str Input string @param bool $search_path True if URL should be resolved using the current skin path stack @return string URL
[ "Make", "URLs", "starting", "with", "a", "slash", "point", "to", "skin", "directory" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L727-L738
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.asset_url
public function asset_url($path) { // iframe content can't be in a different domain // @TODO: check if assests are on a different domain if (!$this->assets_path || in_array($path[0], array('?', '/', '.')) || strpos($path, '://')) { return $path; } return $this->assets_path . $path; }
php
public function asset_url($path) { // iframe content can't be in a different domain // @TODO: check if assests are on a different domain if (!$this->assets_path || in_array($path[0], array('?', '/', '.')) || strpos($path, '://')) { return $path; } return $this->assets_path . $path; }
[ "public", "function", "asset_url", "(", "$", "path", ")", "{", "// iframe content can't be in a different domain", "// @TODO: check if assests are on a different domain", "if", "(", "!", "$", "this", "->", "assets_path", "||", "in_array", "(", "$", "path", "[", "0", "]", ",", "array", "(", "'?'", ",", "'/'", ",", "'.'", ")", ")", "||", "strpos", "(", "$", "path", ",", "'://'", ")", ")", "{", "return", "$", "path", ";", "}", "return", "$", "this", "->", "assets_path", ".", "$", "path", ";", "}" ]
Modify path by adding URL prefix if configured
[ "Modify", "path", "by", "adding", "URL", "prefix", "if", "configured" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L760-L770
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.file_mod
protected function file_mod($file) { $fs = false; $ext = substr($file, strrpos($file, '.') + 1); // use minified file if exists (not in development mode) if (!$this->devel_mode && !preg_match('/\.min\.' . $ext . '$/', $file)) { $minified_file = substr($file, 0, strlen($ext) * -1) . 'min.' . $ext; if ($fs = @filemtime($this->assets_dir . $minified_file)) { return $minified_file . '?s=' . $fs; } } if ($fs = @filemtime($this->assets_dir . $file)) { $file .= '?s=' . $fs; } return $file; }
php
protected function file_mod($file) { $fs = false; $ext = substr($file, strrpos($file, '.') + 1); // use minified file if exists (not in development mode) if (!$this->devel_mode && !preg_match('/\.min\.' . $ext . '$/', $file)) { $minified_file = substr($file, 0, strlen($ext) * -1) . 'min.' . $ext; if ($fs = @filemtime($this->assets_dir . $minified_file)) { return $minified_file . '?s=' . $fs; } } if ($fs = @filemtime($this->assets_dir . $file)) { $file .= '?s=' . $fs; } return $file; }
[ "protected", "function", "file_mod", "(", "$", "file", ")", "{", "$", "fs", "=", "false", ";", "$", "ext", "=", "substr", "(", "$", "file", ",", "strrpos", "(", "$", "file", ",", "'.'", ")", "+", "1", ")", ";", "// use minified file if exists (not in development mode)", "if", "(", "!", "$", "this", "->", "devel_mode", "&&", "!", "preg_match", "(", "'/\\.min\\.'", ".", "$", "ext", ".", "'$/'", ",", "$", "file", ")", ")", "{", "$", "minified_file", "=", "substr", "(", "$", "file", ",", "0", ",", "strlen", "(", "$", "ext", ")", "*", "-", "1", ")", ".", "'min.'", ".", "$", "ext", ";", "if", "(", "$", "fs", "=", "@", "filemtime", "(", "$", "this", "->", "assets_dir", ".", "$", "minified_file", ")", ")", "{", "return", "$", "minified_file", ".", "'?s='", ".", "$", "fs", ";", "}", "}", "if", "(", "$", "fs", "=", "@", "filemtime", "(", "$", "this", "->", "assets_dir", ".", "$", "file", ")", ")", "{", "$", "file", ".=", "'?s='", ".", "$", "fs", ";", "}", "return", "$", "file", ";", "}" ]
Modify file by adding mtime indicator
[ "Modify", "file", "by", "adding", "mtime", "indicator" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L856-L874
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.just_parse
public function just_parse($input) { $input = $this->parse_conditions($input); $input = $this->parse_xml($input); $input = $this->postrender($input); return $input; }
php
public function just_parse($input) { $input = $this->parse_conditions($input); $input = $this->parse_xml($input); $input = $this->postrender($input); return $input; }
[ "public", "function", "just_parse", "(", "$", "input", ")", "{", "$", "input", "=", "$", "this", "->", "parse_conditions", "(", "$", "input", ")", ";", "$", "input", "=", "$", "this", "->", "parse_xml", "(", "$", "input", ")", ";", "$", "input", "=", "$", "this", "->", "postrender", "(", "$", "input", ")", ";", "return", "$", "input", ";", "}" ]
Public wrapper to dipp into template parsing. @param string $input Template content @return string @uses rcmail_output_html::parse_xml() @since 0.1-rc1
[ "Public", "wrapper", "to", "dipp", "into", "template", "parsing", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L885-L892
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.parse_conditions
protected function parse_conditions($input) { $matches = preg_split('/<roundcube:(if|elseif|else|endif)\s+([^>]+)>\n?/is', $input, 2, PREG_SPLIT_DELIM_CAPTURE); if ($matches && count($matches) == 4) { if (preg_match('/^(else|endif)$/i', $matches[1])) { return $matches[0] . $this->parse_conditions($matches[3]); } $attrib = html::parse_attrib_string($matches[2]); if (isset($attrib['condition'])) { $condmet = $this->check_condition($attrib['condition']); $submatches = preg_split('/<roundcube:(elseif|else|endif)\s+([^>]+)>\n?/is', $matches[3], 2, PREG_SPLIT_DELIM_CAPTURE); if ($condmet) { $result = $submatches[0]; if ($submatches[1] != 'endif') { $result .= preg_replace('/.*<roundcube:endif\s+[^>]+>\n?/Uis', '', $submatches[3], 1); } else { $result .= $submatches[3]; } } else { $result = "<roundcube:$submatches[1] $submatches[2]>" . $submatches[3]; } return $matches[0] . $this->parse_conditions($result); } rcube::raise_error(array( 'code' => 500, 'line' => __LINE__, 'file' => __FILE__, 'message' => "Unable to parse conditional tag " . $matches[2] ), true, false); } return $input; }
php
protected function parse_conditions($input) { $matches = preg_split('/<roundcube:(if|elseif|else|endif)\s+([^>]+)>\n?/is', $input, 2, PREG_SPLIT_DELIM_CAPTURE); if ($matches && count($matches) == 4) { if (preg_match('/^(else|endif)$/i', $matches[1])) { return $matches[0] . $this->parse_conditions($matches[3]); } $attrib = html::parse_attrib_string($matches[2]); if (isset($attrib['condition'])) { $condmet = $this->check_condition($attrib['condition']); $submatches = preg_split('/<roundcube:(elseif|else|endif)\s+([^>]+)>\n?/is', $matches[3], 2, PREG_SPLIT_DELIM_CAPTURE); if ($condmet) { $result = $submatches[0]; if ($submatches[1] != 'endif') { $result .= preg_replace('/.*<roundcube:endif\s+[^>]+>\n?/Uis', '', $submatches[3], 1); } else { $result .= $submatches[3]; } } else { $result = "<roundcube:$submatches[1] $submatches[2]>" . $submatches[3]; } return $matches[0] . $this->parse_conditions($result); } rcube::raise_error(array( 'code' => 500, 'line' => __LINE__, 'file' => __FILE__, 'message' => "Unable to parse conditional tag " . $matches[2] ), true, false); } return $input; }
[ "protected", "function", "parse_conditions", "(", "$", "input", ")", "{", "$", "matches", "=", "preg_split", "(", "'/<roundcube:(if|elseif|else|endif)\\s+([^>]+)>\\n?/is'", ",", "$", "input", ",", "2", ",", "PREG_SPLIT_DELIM_CAPTURE", ")", ";", "if", "(", "$", "matches", "&&", "count", "(", "$", "matches", ")", "==", "4", ")", "{", "if", "(", "preg_match", "(", "'/^(else|endif)$/i'", ",", "$", "matches", "[", "1", "]", ")", ")", "{", "return", "$", "matches", "[", "0", "]", ".", "$", "this", "->", "parse_conditions", "(", "$", "matches", "[", "3", "]", ")", ";", "}", "$", "attrib", "=", "html", "::", "parse_attrib_string", "(", "$", "matches", "[", "2", "]", ")", ";", "if", "(", "isset", "(", "$", "attrib", "[", "'condition'", "]", ")", ")", "{", "$", "condmet", "=", "$", "this", "->", "check_condition", "(", "$", "attrib", "[", "'condition'", "]", ")", ";", "$", "submatches", "=", "preg_split", "(", "'/<roundcube:(elseif|else|endif)\\s+([^>]+)>\\n?/is'", ",", "$", "matches", "[", "3", "]", ",", "2", ",", "PREG_SPLIT_DELIM_CAPTURE", ")", ";", "if", "(", "$", "condmet", ")", "{", "$", "result", "=", "$", "submatches", "[", "0", "]", ";", "if", "(", "$", "submatches", "[", "1", "]", "!=", "'endif'", ")", "{", "$", "result", ".=", "preg_replace", "(", "'/.*<roundcube:endif\\s+[^>]+>\\n?/Uis'", ",", "''", ",", "$", "submatches", "[", "3", "]", ",", "1", ")", ";", "}", "else", "{", "$", "result", ".=", "$", "submatches", "[", "3", "]", ";", "}", "}", "else", "{", "$", "result", "=", "\"<roundcube:$submatches[1] $submatches[2]>\"", ".", "$", "submatches", "[", "3", "]", ";", "}", "return", "$", "matches", "[", "0", "]", ".", "$", "this", "->", "parse_conditions", "(", "$", "result", ")", ";", "}", "rcube", "::", "raise_error", "(", "array", "(", "'code'", "=>", "500", ",", "'line'", "=>", "__LINE__", ",", "'file'", "=>", "__FILE__", ",", "'message'", "=>", "\"Unable to parse conditional tag \"", ".", "$", "matches", "[", "2", "]", ")", ",", "true", ",", "false", ")", ";", "}", "return", "$", "input", ";", "}" ]
Parse for conditional tags
[ "Parse", "for", "conditional", "tags" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L897-L934
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.alter_form_tag
protected function alter_form_tag($matches) { $out = $matches[0]; $attrib = html::parse_attrib_string($matches[1]); if (strtolower($attrib['method']) == 'post') { $hidden = new html_hiddenfield(array('name' => '_token', 'value' => $this->app->get_request_token())); $out .= "\n" . $hidden->show(); } return $out; }
php
protected function alter_form_tag($matches) { $out = $matches[0]; $attrib = html::parse_attrib_string($matches[1]); if (strtolower($attrib['method']) == 'post') { $hidden = new html_hiddenfield(array('name' => '_token', 'value' => $this->app->get_request_token())); $out .= "\n" . $hidden->show(); } return $out; }
[ "protected", "function", "alter_form_tag", "(", "$", "matches", ")", "{", "$", "out", "=", "$", "matches", "[", "0", "]", ";", "$", "attrib", "=", "html", "::", "parse_attrib_string", "(", "$", "matches", "[", "1", "]", ")", ";", "if", "(", "strtolower", "(", "$", "attrib", "[", "'method'", "]", ")", "==", "'post'", ")", "{", "$", "hidden", "=", "new", "html_hiddenfield", "(", "array", "(", "'name'", "=>", "'_token'", ",", "'value'", "=>", "$", "this", "->", "app", "->", "get_request_token", "(", ")", ")", ")", ";", "$", "out", ".=", "\"\\n\"", ".", "$", "hidden", "->", "show", "(", ")", ";", "}", "return", "$", "out", ";", "}" ]
Inserts hidden field with CSRF-prevention-token into POST forms
[ "Inserts", "hidden", "field", "with", "CSRF", "-", "prevention", "-", "token", "into", "POST", "forms" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L952-L963
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.postrender
protected function postrender($output) { // insert objects' contents foreach ($this->objects as $key => $val) { $output = str_replace($key, $val, $output, $count); if ($count) { $this->objects[$key] = null; } } // make sure all <form> tags have a valid request token $output = preg_replace_callback('/<form\s+([^>]+)>/Ui', array($this, 'alter_form_tag'), $output); return $output; }
php
protected function postrender($output) { // insert objects' contents foreach ($this->objects as $key => $val) { $output = str_replace($key, $val, $output, $count); if ($count) { $this->objects[$key] = null; } } // make sure all <form> tags have a valid request token $output = preg_replace_callback('/<form\s+([^>]+)>/Ui', array($this, 'alter_form_tag'), $output); return $output; }
[ "protected", "function", "postrender", "(", "$", "output", ")", "{", "// insert objects' contents", "foreach", "(", "$", "this", "->", "objects", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "output", "=", "str_replace", "(", "$", "key", ",", "$", "val", ",", "$", "output", ",", "$", "count", ")", ";", "if", "(", "$", "count", ")", "{", "$", "this", "->", "objects", "[", "$", "key", "]", "=", "null", ";", "}", "}", "// make sure all <form> tags have a valid request token", "$", "output", "=", "preg_replace_callback", "(", "'/<form\\s+([^>]+)>/Ui'", ",", "array", "(", "$", "this", ",", "'alter_form_tag'", ")", ",", "$", "output", ")", ";", "return", "$", "output", ";", "}" ]
Put objects' content back into template output
[ "Put", "objects", "content", "back", "into", "template", "output" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L1284-L1298
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.include_script
public function include_script($file, $position='head') { if (!preg_match('|^https?://|i', $file) && $file[0] != '/') { $file = $this->file_mod($this->scripts_path . $file); } if (!is_array($this->script_files[$position])) { $this->script_files[$position] = array(); } if (!in_array($file, $this->script_files[$position])) { $this->script_files[$position][] = $file; } }
php
public function include_script($file, $position='head') { if (!preg_match('|^https?://|i', $file) && $file[0] != '/') { $file = $this->file_mod($this->scripts_path . $file); } if (!is_array($this->script_files[$position])) { $this->script_files[$position] = array(); } if (!in_array($file, $this->script_files[$position])) { $this->script_files[$position][] = $file; } }
[ "public", "function", "include_script", "(", "$", "file", ",", "$", "position", "=", "'head'", ")", "{", "if", "(", "!", "preg_match", "(", "'|^https?://|i'", ",", "$", "file", ")", "&&", "$", "file", "[", "0", "]", "!=", "'/'", ")", "{", "$", "file", "=", "$", "this", "->", "file_mod", "(", "$", "this", "->", "scripts_path", ".", "$", "file", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "this", "->", "script_files", "[", "$", "position", "]", ")", ")", "{", "$", "this", "->", "script_files", "[", "$", "position", "]", "=", "array", "(", ")", ";", "}", "if", "(", "!", "in_array", "(", "$", "file", ",", "$", "this", "->", "script_files", "[", "$", "position", "]", ")", ")", "{", "$", "this", "->", "script_files", "[", "$", "position", "]", "[", "]", "=", "$", "file", ";", "}", "}" ]
Link an external script file @param string $file File URL @param string $position Target position [head|foot]
[ "Link", "an", "external", "script", "file" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L1496-L1509
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.add_script
public function add_script($script, $position='head') { if (!isset($this->scripts[$position])) { $this->scripts[$position] = "\n" . rtrim($script); } else { $this->scripts[$position] .= "\n" . rtrim($script); } }
php
public function add_script($script, $position='head') { if (!isset($this->scripts[$position])) { $this->scripts[$position] = "\n" . rtrim($script); } else { $this->scripts[$position] .= "\n" . rtrim($script); } }
[ "public", "function", "add_script", "(", "$", "script", ",", "$", "position", "=", "'head'", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "scripts", "[", "$", "position", "]", ")", ")", "{", "$", "this", "->", "scripts", "[", "$", "position", "]", "=", "\"\\n\"", ".", "rtrim", "(", "$", "script", ")", ";", "}", "else", "{", "$", "this", "->", "scripts", "[", "$", "position", "]", ".=", "\"\\n\"", ".", "rtrim", "(", "$", "script", ")", ";", "}", "}" ]
Add inline javascript code @param string $script JS code snippet @param string $position Target position [head|head_top|foot]
[ "Add", "inline", "javascript", "code" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L1517-L1525
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.frame
public function frame($attrib, $is_contentframe = false) { static $idcount = 0; if (!$attrib['id']) { $attrib['id'] = 'rcmframe' . ++$idcount; } $attrib['name'] = $attrib['id']; $attrib['src'] = $attrib['src'] ? $this->abs_url($attrib['src'], true) : 'program/resources/blank.gif'; // register as 'contentframe' object if ($is_contentframe || $attrib['contentframe']) { $this->set_env('contentframe', $attrib['contentframe'] ? $attrib['contentframe'] : $attrib['name']); $this->set_env('blankpage', $this->asset_url($attrib['src'])); } return html::iframe($attrib); }
php
public function frame($attrib, $is_contentframe = false) { static $idcount = 0; if (!$attrib['id']) { $attrib['id'] = 'rcmframe' . ++$idcount; } $attrib['name'] = $attrib['id']; $attrib['src'] = $attrib['src'] ? $this->abs_url($attrib['src'], true) : 'program/resources/blank.gif'; // register as 'contentframe' object if ($is_contentframe || $attrib['contentframe']) { $this->set_env('contentframe', $attrib['contentframe'] ? $attrib['contentframe'] : $attrib['name']); $this->set_env('blankpage', $this->asset_url($attrib['src'])); } return html::iframe($attrib); }
[ "public", "function", "frame", "(", "$", "attrib", ",", "$", "is_contentframe", "=", "false", ")", "{", "static", "$", "idcount", "=", "0", ";", "if", "(", "!", "$", "attrib", "[", "'id'", "]", ")", "{", "$", "attrib", "[", "'id'", "]", "=", "'rcmframe'", ".", "++", "$", "idcount", ";", "}", "$", "attrib", "[", "'name'", "]", "=", "$", "attrib", "[", "'id'", "]", ";", "$", "attrib", "[", "'src'", "]", "=", "$", "attrib", "[", "'src'", "]", "?", "$", "this", "->", "abs_url", "(", "$", "attrib", "[", "'src'", "]", ",", "true", ")", ":", "'program/resources/blank.gif'", ";", "// register as 'contentframe' object", "if", "(", "$", "is_contentframe", "||", "$", "attrib", "[", "'contentframe'", "]", ")", "{", "$", "this", "->", "set_env", "(", "'contentframe'", ",", "$", "attrib", "[", "'contentframe'", "]", "?", "$", "attrib", "[", "'contentframe'", "]", ":", "$", "attrib", "[", "'name'", "]", ")", ";", "$", "this", "->", "set_env", "(", "'blankpage'", ",", "$", "this", "->", "asset_url", "(", "$", "attrib", "[", "'src'", "]", ")", ")", ";", "}", "return", "html", "::", "iframe", "(", "$", "attrib", ")", ";", "}" ]
Returns iframe object, registers some related env variables @param array $attrib HTML attributes @param boolean $is_contentframe Register this iframe as the 'contentframe' gui object @return string IFRAME element
[ "Returns", "iframe", "object", "registers", "some", "related", "env", "variables" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L1710-L1728
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.form_tag
public function form_tag($attrib, $content = null) { if ($this->env['extwin']) { $hiddenfield = new html_hiddenfield(array('name' => '_extwin', 'value' => '1')); $hidden = $hiddenfield->show(); } else if ($this->framed || $this->env['framed']) { $hiddenfield = new html_hiddenfield(array('name' => '_framed', 'value' => '1')); $hidden = $hiddenfield->show(); } if (!$content) { $attrib['noclose'] = true; } return html::tag('form', $attrib + array('action' => $this->app->comm_path, 'method' => "get"), $hidden . $content, array('id','class','style','name','method','action','enctype','onsubmit') ); }
php
public function form_tag($attrib, $content = null) { if ($this->env['extwin']) { $hiddenfield = new html_hiddenfield(array('name' => '_extwin', 'value' => '1')); $hidden = $hiddenfield->show(); } else if ($this->framed || $this->env['framed']) { $hiddenfield = new html_hiddenfield(array('name' => '_framed', 'value' => '1')); $hidden = $hiddenfield->show(); } if (!$content) { $attrib['noclose'] = true; } return html::tag('form', $attrib + array('action' => $this->app->comm_path, 'method' => "get"), $hidden . $content, array('id','class','style','name','method','action','enctype','onsubmit') ); }
[ "public", "function", "form_tag", "(", "$", "attrib", ",", "$", "content", "=", "null", ")", "{", "if", "(", "$", "this", "->", "env", "[", "'extwin'", "]", ")", "{", "$", "hiddenfield", "=", "new", "html_hiddenfield", "(", "array", "(", "'name'", "=>", "'_extwin'", ",", "'value'", "=>", "'1'", ")", ")", ";", "$", "hidden", "=", "$", "hiddenfield", "->", "show", "(", ")", ";", "}", "else", "if", "(", "$", "this", "->", "framed", "||", "$", "this", "->", "env", "[", "'framed'", "]", ")", "{", "$", "hiddenfield", "=", "new", "html_hiddenfield", "(", "array", "(", "'name'", "=>", "'_framed'", ",", "'value'", "=>", "'1'", ")", ")", ";", "$", "hidden", "=", "$", "hiddenfield", "->", "show", "(", ")", ";", "}", "if", "(", "!", "$", "content", ")", "{", "$", "attrib", "[", "'noclose'", "]", "=", "true", ";", "}", "return", "html", "::", "tag", "(", "'form'", ",", "$", "attrib", "+", "array", "(", "'action'", "=>", "$", "this", "->", "app", "->", "comm_path", ",", "'method'", "=>", "\"get\"", ")", ",", "$", "hidden", ".", "$", "content", ",", "array", "(", "'id'", ",", "'class'", ",", "'style'", ",", "'name'", ",", "'method'", ",", "'action'", ",", "'enctype'", ",", "'onsubmit'", ")", ")", ";", "}" ]
Create a form tag with the necessary hidden fields @param array $attrib Named tag parameters @param string $content HTML content of the form @return string HTML code for the form
[ "Create", "a", "form", "tag", "with", "the", "necessary", "hidden", "fields" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L1741-L1761
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.request_form
public function request_form($attrib, $content = '') { $hidden = new html_hiddenfield(); if ($attrib['task']) { $hidden->add(array('name' => '_task', 'value' => $attrib['task'])); } if ($attrib['action']) { $hidden->add(array('name' => '_action', 'value' => $attrib['action'])); } // we already have a <form> tag if ($attrib['form']) { if ($this->framed || $this->env['framed']) { $hidden->add(array('name' => '_framed', 'value' => '1')); } return $hidden->show() . $content; } unset($attrib['task'], $attrib['request']); $attrib['action'] = './'; return $this->form_tag($attrib, $hidden->show() . $content); }
php
public function request_form($attrib, $content = '') { $hidden = new html_hiddenfield(); if ($attrib['task']) { $hidden->add(array('name' => '_task', 'value' => $attrib['task'])); } if ($attrib['action']) { $hidden->add(array('name' => '_action', 'value' => $attrib['action'])); } // we already have a <form> tag if ($attrib['form']) { if ($this->framed || $this->env['framed']) { $hidden->add(array('name' => '_framed', 'value' => '1')); } return $hidden->show() . $content; } unset($attrib['task'], $attrib['request']); $attrib['action'] = './'; return $this->form_tag($attrib, $hidden->show() . $content); }
[ "public", "function", "request_form", "(", "$", "attrib", ",", "$", "content", "=", "''", ")", "{", "$", "hidden", "=", "new", "html_hiddenfield", "(", ")", ";", "if", "(", "$", "attrib", "[", "'task'", "]", ")", "{", "$", "hidden", "->", "add", "(", "array", "(", "'name'", "=>", "'_task'", ",", "'value'", "=>", "$", "attrib", "[", "'task'", "]", ")", ")", ";", "}", "if", "(", "$", "attrib", "[", "'action'", "]", ")", "{", "$", "hidden", "->", "add", "(", "array", "(", "'name'", "=>", "'_action'", ",", "'value'", "=>", "$", "attrib", "[", "'action'", "]", ")", ")", ";", "}", "// we already have a <form> tag", "if", "(", "$", "attrib", "[", "'form'", "]", ")", "{", "if", "(", "$", "this", "->", "framed", "||", "$", "this", "->", "env", "[", "'framed'", "]", ")", "{", "$", "hidden", "->", "add", "(", "array", "(", "'name'", "=>", "'_framed'", ",", "'value'", "=>", "'1'", ")", ")", ";", "}", "return", "$", "hidden", "->", "show", "(", ")", ".", "$", "content", ";", "}", "unset", "(", "$", "attrib", "[", "'task'", "]", ",", "$", "attrib", "[", "'request'", "]", ")", ";", "$", "attrib", "[", "'action'", "]", "=", "'./'", ";", "return", "$", "this", "->", "form_tag", "(", "$", "attrib", ",", "$", "hidden", "->", "show", "(", ")", ".", "$", "content", ")", ";", "}" ]
Build a form tag with a unique request token @param array $attrib Named tag parameters including 'action' and 'task' values which will be put into hidden fields @param string $content Form content @return string HTML code for the form
[ "Build", "a", "form", "tag", "with", "a", "unique", "request", "token" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L1772-L1795
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.current_username
public function current_username($attrib) { static $username; // alread fetched if (!empty($username)) { return $username; } // Current username is an e-mail address if (strpos($_SESSION['username'], '@')) { $username = $_SESSION['username']; } // get e-mail address from default identity else if ($sql_arr = $this->app->user->get_identity()) { $username = $sql_arr['email']; } else { $username = $this->app->user->get_username(); } return rcube_utils::idn_to_utf8($username); }
php
public function current_username($attrib) { static $username; // alread fetched if (!empty($username)) { return $username; } // Current username is an e-mail address if (strpos($_SESSION['username'], '@')) { $username = $_SESSION['username']; } // get e-mail address from default identity else if ($sql_arr = $this->app->user->get_identity()) { $username = $sql_arr['email']; } else { $username = $this->app->user->get_username(); } return rcube_utils::idn_to_utf8($username); }
[ "public", "function", "current_username", "(", "$", "attrib", ")", "{", "static", "$", "username", ";", "// alread fetched", "if", "(", "!", "empty", "(", "$", "username", ")", ")", "{", "return", "$", "username", ";", "}", "// Current username is an e-mail address", "if", "(", "strpos", "(", "$", "_SESSION", "[", "'username'", "]", ",", "'@'", ")", ")", "{", "$", "username", "=", "$", "_SESSION", "[", "'username'", "]", ";", "}", "// get e-mail address from default identity", "else", "if", "(", "$", "sql_arr", "=", "$", "this", "->", "app", "->", "user", "->", "get_identity", "(", ")", ")", "{", "$", "username", "=", "$", "sql_arr", "[", "'email'", "]", ";", "}", "else", "{", "$", "username", "=", "$", "this", "->", "app", "->", "user", "->", "get_username", "(", ")", ";", "}", "return", "rcube_utils", "::", "idn_to_utf8", "(", "$", "username", ")", ";", "}" ]
GUI object 'username' Showing IMAP username of the current session @param array $attrib Named tag parameters (currently not used) @return string HTML code for the gui object
[ "GUI", "object", "username", "Showing", "IMAP", "username", "of", "the", "current", "session" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L1805-L1827
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.preloader
protected function preloader($attrib) { $images = preg_split('/[\s\t\n,]+/', $attrib['images'], -1, PREG_SPLIT_NO_EMPTY); $images = array_map(array($this, 'abs_url'), $images); $images = array_map(array($this, 'asset_url'), $images); if (empty($images) || $_REQUEST['_task'] == 'logout') { return; } $this->add_script('var images = ' . self::json_serialize($images, $this->devel_mode) .'; for (var i=0; i<images.length; i++) { img = new Image(); img.src = images[i]; }', 'docready'); }
php
protected function preloader($attrib) { $images = preg_split('/[\s\t\n,]+/', $attrib['images'], -1, PREG_SPLIT_NO_EMPTY); $images = array_map(array($this, 'abs_url'), $images); $images = array_map(array($this, 'asset_url'), $images); if (empty($images) || $_REQUEST['_task'] == 'logout') { return; } $this->add_script('var images = ' . self::json_serialize($images, $this->devel_mode) .'; for (var i=0; i<images.length; i++) { img = new Image(); img.src = images[i]; }', 'docready'); }
[ "protected", "function", "preloader", "(", "$", "attrib", ")", "{", "$", "images", "=", "preg_split", "(", "'/[\\s\\t\\n,]+/'", ",", "$", "attrib", "[", "'images'", "]", ",", "-", "1", ",", "PREG_SPLIT_NO_EMPTY", ")", ";", "$", "images", "=", "array_map", "(", "array", "(", "$", "this", ",", "'abs_url'", ")", ",", "$", "images", ")", ";", "$", "images", "=", "array_map", "(", "array", "(", "$", "this", ",", "'asset_url'", ")", ",", "$", "images", ")", ";", "if", "(", "empty", "(", "$", "images", ")", "||", "$", "_REQUEST", "[", "'_task'", "]", "==", "'logout'", ")", "{", "return", ";", "}", "$", "this", "->", "add_script", "(", "'var images = '", ".", "self", "::", "json_serialize", "(", "$", "images", ",", "$", "this", "->", "devel_mode", ")", ".", "';\n for (var i=0; i<images.length; i++) {\n img = new Image();\n img.src = images[i];\n }'", ",", "'docready'", ")", ";", "}" ]
GUI object 'preloader' Loads javascript code for images preloading @param array $attrib Named parameters @return void
[ "GUI", "object", "preloader", "Loads", "javascript", "code", "for", "images", "preloading" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L1943-L1958
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.search_form
protected function search_form($attrib) { // add some labels to client $this->add_label('searching'); $attrib['name'] = '_q'; if (empty($attrib['id'])) { $attrib['id'] = 'rcmqsearchbox'; } if ($attrib['type'] == 'search' && !$this->browser->khtml) { unset($attrib['type'], $attrib['results']); } $input_q = new html_inputfield($attrib); $out = $input_q->show(); $this->add_gui_object('qsearchbox', $attrib['id']); // add form tag around text field if (empty($attrib['form'])) { $out = $this->form_tag(array( 'name' => "rcmqsearchform", 'onsubmit' => self::JS_OBJECT_NAME . ".command('search'); return false", 'style' => "display:inline" ), $out); } return $out; }
php
protected function search_form($attrib) { // add some labels to client $this->add_label('searching'); $attrib['name'] = '_q'; if (empty($attrib['id'])) { $attrib['id'] = 'rcmqsearchbox'; } if ($attrib['type'] == 'search' && !$this->browser->khtml) { unset($attrib['type'], $attrib['results']); } $input_q = new html_inputfield($attrib); $out = $input_q->show(); $this->add_gui_object('qsearchbox', $attrib['id']); // add form tag around text field if (empty($attrib['form'])) { $out = $this->form_tag(array( 'name' => "rcmqsearchform", 'onsubmit' => self::JS_OBJECT_NAME . ".command('search'); return false", 'style' => "display:inline" ), $out); } return $out; }
[ "protected", "function", "search_form", "(", "$", "attrib", ")", "{", "// add some labels to client", "$", "this", "->", "add_label", "(", "'searching'", ")", ";", "$", "attrib", "[", "'name'", "]", "=", "'_q'", ";", "if", "(", "empty", "(", "$", "attrib", "[", "'id'", "]", ")", ")", "{", "$", "attrib", "[", "'id'", "]", "=", "'rcmqsearchbox'", ";", "}", "if", "(", "$", "attrib", "[", "'type'", "]", "==", "'search'", "&&", "!", "$", "this", "->", "browser", "->", "khtml", ")", "{", "unset", "(", "$", "attrib", "[", "'type'", "]", ",", "$", "attrib", "[", "'results'", "]", ")", ";", "}", "$", "input_q", "=", "new", "html_inputfield", "(", "$", "attrib", ")", ";", "$", "out", "=", "$", "input_q", "->", "show", "(", ")", ";", "$", "this", "->", "add_gui_object", "(", "'qsearchbox'", ",", "$", "attrib", "[", "'id'", "]", ")", ";", "// add form tag around text field", "if", "(", "empty", "(", "$", "attrib", "[", "'form'", "]", ")", ")", "{", "$", "out", "=", "$", "this", "->", "form_tag", "(", "array", "(", "'name'", "=>", "\"rcmqsearchform\"", ",", "'onsubmit'", "=>", "self", "::", "JS_OBJECT_NAME", ".", "\".command('search'); return false\"", ",", "'style'", "=>", "\"display:inline\"", ")", ",", "$", "out", ")", ";", "}", "return", "$", "out", ";", "}" ]
GUI object 'searchform' Returns code for search function @param array $attrib Named parameters @return string HTML code for the gui object
[ "GUI", "object", "searchform", "Returns", "code", "for", "search", "function" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L1968-L1997
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_output_html.php
rcmail_output_html.message_container
protected function message_container($attrib) { if (isset($attrib['id']) === false) { $attrib['id'] = 'rcmMessageContainer'; } $this->add_gui_object('message', $attrib['id']); return html::div($attrib, ''); }
php
protected function message_container($attrib) { if (isset($attrib['id']) === false) { $attrib['id'] = 'rcmMessageContainer'; } $this->add_gui_object('message', $attrib['id']); return html::div($attrib, ''); }
[ "protected", "function", "message_container", "(", "$", "attrib", ")", "{", "if", "(", "isset", "(", "$", "attrib", "[", "'id'", "]", ")", "===", "false", ")", "{", "$", "attrib", "[", "'id'", "]", "=", "'rcmMessageContainer'", ";", "}", "$", "this", "->", "add_gui_object", "(", "'message'", ",", "$", "attrib", "[", "'id'", "]", ")", ";", "return", "html", "::", "div", "(", "$", "attrib", ",", "''", ")", ";", "}" ]
Builder for GUI object 'message' @param array Named tag parameters @return string HTML code for the gui object
[ "Builder", "for", "GUI", "object", "message" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_output_html.php#L2005-L2014
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_install.php
rcmail_install.load_config
public function load_config() { // defaults if ($config = $this->load_config_file(RCUBE_CONFIG_DIR . 'defaults.inc.php')) { $this->config = (array) $config; $this->defaults = $this->config; } $config = null; // config if ($config = $this->load_config_file(RCUBE_CONFIG_DIR . 'config.inc.php')) { $this->config = array_merge($this->config, $config); } else { if ($config = $this->load_config_file(RCUBE_CONFIG_DIR . 'main.inc.php')) { $this->config = array_merge($this->config, $config); $this->legacy_config = true; } if ($config = $this->load_config_file(RCUBE_CONFIG_DIR . 'db.inc.php')) { $this->config = array_merge($this->config, $config); $this->legacy_config = true; } } $this->configured = !empty($config); }
php
public function load_config() { // defaults if ($config = $this->load_config_file(RCUBE_CONFIG_DIR . 'defaults.inc.php')) { $this->config = (array) $config; $this->defaults = $this->config; } $config = null; // config if ($config = $this->load_config_file(RCUBE_CONFIG_DIR . 'config.inc.php')) { $this->config = array_merge($this->config, $config); } else { if ($config = $this->load_config_file(RCUBE_CONFIG_DIR . 'main.inc.php')) { $this->config = array_merge($this->config, $config); $this->legacy_config = true; } if ($config = $this->load_config_file(RCUBE_CONFIG_DIR . 'db.inc.php')) { $this->config = array_merge($this->config, $config); $this->legacy_config = true; } } $this->configured = !empty($config); }
[ "public", "function", "load_config", "(", ")", "{", "// defaults", "if", "(", "$", "config", "=", "$", "this", "->", "load_config_file", "(", "RCUBE_CONFIG_DIR", ".", "'defaults.inc.php'", ")", ")", "{", "$", "this", "->", "config", "=", "(", "array", ")", "$", "config", ";", "$", "this", "->", "defaults", "=", "$", "this", "->", "config", ";", "}", "$", "config", "=", "null", ";", "// config", "if", "(", "$", "config", "=", "$", "this", "->", "load_config_file", "(", "RCUBE_CONFIG_DIR", ".", "'config.inc.php'", ")", ")", "{", "$", "this", "->", "config", "=", "array_merge", "(", "$", "this", "->", "config", ",", "$", "config", ")", ";", "}", "else", "{", "if", "(", "$", "config", "=", "$", "this", "->", "load_config_file", "(", "RCUBE_CONFIG_DIR", ".", "'main.inc.php'", ")", ")", "{", "$", "this", "->", "config", "=", "array_merge", "(", "$", "this", "->", "config", ",", "$", "config", ")", ";", "$", "this", "->", "legacy_config", "=", "true", ";", "}", "if", "(", "$", "config", "=", "$", "this", "->", "load_config_file", "(", "RCUBE_CONFIG_DIR", ".", "'db.inc.php'", ")", ")", "{", "$", "this", "->", "config", "=", "array_merge", "(", "$", "this", "->", "config", ",", "$", "config", ")", ";", "$", "this", "->", "legacy_config", "=", "true", ";", "}", "}", "$", "this", "->", "configured", "=", "!", "empty", "(", "$", "config", ")", ";", "}" ]
Read the local config files and store properties
[ "Read", "the", "local", "config", "files", "and", "store", "properties" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_install.php#L87-L114
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_install.php
rcmail_install.load_config_file
public function load_config_file($file) { if (!is_readable($file)) { return; } include $file; // read comments from config file if (function_exists('token_get_all')) { $tokens = token_get_all(file_get_contents($file)); $in_config = false; $buffer = ''; for ($i = 0; $i < count($tokens); $i++) { $token = $tokens[$i]; if ($token[0] == T_VARIABLE && ($token[1] == '$config' || $token[1] == '$rcmail_config')) { $in_config = true; if ($buffer && $tokens[$i+1] == '[' && $tokens[$i+2][0] == T_CONSTANT_ENCAPSED_STRING) { $propname = trim($tokens[$i+2][1], "'\""); $this->comments[$propname] = $buffer; $buffer = ''; $i += 3; } } else if ($in_config && $token[0] == T_COMMENT) { $buffer .= strtr($token[1], array('\n' => "\n")); } } } // deprecated name of config variable if (is_array($rcmail_config)) { return $rcmail_config; } return $config; }
php
public function load_config_file($file) { if (!is_readable($file)) { return; } include $file; // read comments from config file if (function_exists('token_get_all')) { $tokens = token_get_all(file_get_contents($file)); $in_config = false; $buffer = ''; for ($i = 0; $i < count($tokens); $i++) { $token = $tokens[$i]; if ($token[0] == T_VARIABLE && ($token[1] == '$config' || $token[1] == '$rcmail_config')) { $in_config = true; if ($buffer && $tokens[$i+1] == '[' && $tokens[$i+2][0] == T_CONSTANT_ENCAPSED_STRING) { $propname = trim($tokens[$i+2][1], "'\""); $this->comments[$propname] = $buffer; $buffer = ''; $i += 3; } } else if ($in_config && $token[0] == T_COMMENT) { $buffer .= strtr($token[1], array('\n' => "\n")); } } } // deprecated name of config variable if (is_array($rcmail_config)) { return $rcmail_config; } return $config; }
[ "public", "function", "load_config_file", "(", "$", "file", ")", "{", "if", "(", "!", "is_readable", "(", "$", "file", ")", ")", "{", "return", ";", "}", "include", "$", "file", ";", "// read comments from config file", "if", "(", "function_exists", "(", "'token_get_all'", ")", ")", "{", "$", "tokens", "=", "token_get_all", "(", "file_get_contents", "(", "$", "file", ")", ")", ";", "$", "in_config", "=", "false", ";", "$", "buffer", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "tokens", ")", ";", "$", "i", "++", ")", "{", "$", "token", "=", "$", "tokens", "[", "$", "i", "]", ";", "if", "(", "$", "token", "[", "0", "]", "==", "T_VARIABLE", "&&", "(", "$", "token", "[", "1", "]", "==", "'$config'", "||", "$", "token", "[", "1", "]", "==", "'$rcmail_config'", ")", ")", "{", "$", "in_config", "=", "true", ";", "if", "(", "$", "buffer", "&&", "$", "tokens", "[", "$", "i", "+", "1", "]", "==", "'['", "&&", "$", "tokens", "[", "$", "i", "+", "2", "]", "[", "0", "]", "==", "T_CONSTANT_ENCAPSED_STRING", ")", "{", "$", "propname", "=", "trim", "(", "$", "tokens", "[", "$", "i", "+", "2", "]", "[", "1", "]", ",", "\"'\\\"\"", ")", ";", "$", "this", "->", "comments", "[", "$", "propname", "]", "=", "$", "buffer", ";", "$", "buffer", "=", "''", ";", "$", "i", "+=", "3", ";", "}", "}", "else", "if", "(", "$", "in_config", "&&", "$", "token", "[", "0", "]", "==", "T_COMMENT", ")", "{", "$", "buffer", ".=", "strtr", "(", "$", "token", "[", "1", "]", ",", "array", "(", "'\\n'", "=>", "\"\\n\"", ")", ")", ";", "}", "}", "}", "// deprecated name of config variable", "if", "(", "is_array", "(", "$", "rcmail_config", ")", ")", "{", "return", "$", "rcmail_config", ";", "}", "return", "$", "config", ";", "}" ]
Read the default config file and store properties @param string $file File name with path
[ "Read", "the", "default", "config", "file", "and", "store", "properties" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_install.php#L121-L158
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_install.php
rcmail_install.getprop
public function getprop($name, $default = '') { $value = $this->config[$name]; if ($name == 'des_key' && !$this->configured && !isset($_REQUEST["_$name"])) { $value = rcube_utils::random_bytes(24); } return $value !== null && $value !== '' ? $value : $default; }
php
public function getprop($name, $default = '') { $value = $this->config[$name]; if ($name == 'des_key' && !$this->configured && !isset($_REQUEST["_$name"])) { $value = rcube_utils::random_bytes(24); } return $value !== null && $value !== '' ? $value : $default; }
[ "public", "function", "getprop", "(", "$", "name", ",", "$", "default", "=", "''", ")", "{", "$", "value", "=", "$", "this", "->", "config", "[", "$", "name", "]", ";", "if", "(", "$", "name", "==", "'des_key'", "&&", "!", "$", "this", "->", "configured", "&&", "!", "isset", "(", "$", "_REQUEST", "[", "\"_$name\"", "]", ")", ")", "{", "$", "value", "=", "rcube_utils", "::", "random_bytes", "(", "24", ")", ";", "}", "return", "$", "value", "!==", "null", "&&", "$", "value", "!==", "''", "?", "$", "value", ":", "$", "default", ";", "}" ]
Getter for a certain config property @param string $name Property name @param string $default Default value @return string The property value
[ "Getter", "for", "a", "certain", "config", "property" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_install.php#L168-L177
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_install.php
rcmail_install.check_config
public function check_config() { $this->load_config(); if (!$this->configured) { return; } $out = $seen = array(); // iterate over the current configuration foreach (array_keys($this->config) as $prop) { if ($replacement = $this->replaced_config[$prop]) { $out['replaced'][] = array('prop' => $prop, 'replacement' => $replacement); $seen[$replacement] = true; } else if (!$seen[$prop] && in_array($prop, $this->obsolete_config)) { $out['obsolete'][] = array('prop' => $prop); $seen[$prop] = true; } } // the old default mime_magic reference is obsolete if ($this->config['mime_magic'] == '/usr/share/misc/magic') { $out['obsolete'][] = array( 'prop' => 'mime_magic', 'explain' => "Set value to null in order to use system default" ); } // check config dependencies and contradictions if ($this->config['enable_spellcheck'] && $this->config['spellcheck_engine'] == 'pspell') { if (!extension_loaded('pspell')) { $out['dependencies'][] = array( 'prop' => 'spellcheck_engine', 'explain' => "This requires the <tt>pspell</tt> extension which could not be loaded." ); } else if (!empty($this->config['spellcheck_languages'])) { foreach ($this->config['spellcheck_languages'] as $lang => $descr) { if (!@pspell_new($lang)) { $out['dependencies'][] = array( 'prop' => 'spellcheck_languages', 'explain' => "You are missing pspell support for language $lang ($descr)" ); } } } } if ($this->config['log_driver'] == 'syslog') { if (!function_exists('openlog')) { $out['dependencies'][] = array( 'prop' => 'log_driver', 'explain' => "This requires the <tt>syslog</tt> extension which could not be loaded." ); } if (empty($this->config['syslog_id'])) { $out['dependencies'][] = array( 'prop' => 'syslog_id', 'explain' => "Using <tt>syslog</tt> for logging requires a syslog ID to be configured" ); } } // check ldap_public sources having global_search enabled if (is_array($this->config['ldap_public']) && !is_array($this->config['autocomplete_addressbooks'])) { foreach ($this->config['ldap_public'] as $ldap_public) { if ($ldap_public['global_search']) { $out['replaced'][] = array( 'prop' => 'ldap_public::global_search', 'replacement' => 'autocomplete_addressbooks' ); break; } } } return $out; }
php
public function check_config() { $this->load_config(); if (!$this->configured) { return; } $out = $seen = array(); // iterate over the current configuration foreach (array_keys($this->config) as $prop) { if ($replacement = $this->replaced_config[$prop]) { $out['replaced'][] = array('prop' => $prop, 'replacement' => $replacement); $seen[$replacement] = true; } else if (!$seen[$prop] && in_array($prop, $this->obsolete_config)) { $out['obsolete'][] = array('prop' => $prop); $seen[$prop] = true; } } // the old default mime_magic reference is obsolete if ($this->config['mime_magic'] == '/usr/share/misc/magic') { $out['obsolete'][] = array( 'prop' => 'mime_magic', 'explain' => "Set value to null in order to use system default" ); } // check config dependencies and contradictions if ($this->config['enable_spellcheck'] && $this->config['spellcheck_engine'] == 'pspell') { if (!extension_loaded('pspell')) { $out['dependencies'][] = array( 'prop' => 'spellcheck_engine', 'explain' => "This requires the <tt>pspell</tt> extension which could not be loaded." ); } else if (!empty($this->config['spellcheck_languages'])) { foreach ($this->config['spellcheck_languages'] as $lang => $descr) { if (!@pspell_new($lang)) { $out['dependencies'][] = array( 'prop' => 'spellcheck_languages', 'explain' => "You are missing pspell support for language $lang ($descr)" ); } } } } if ($this->config['log_driver'] == 'syslog') { if (!function_exists('openlog')) { $out['dependencies'][] = array( 'prop' => 'log_driver', 'explain' => "This requires the <tt>syslog</tt> extension which could not be loaded." ); } if (empty($this->config['syslog_id'])) { $out['dependencies'][] = array( 'prop' => 'syslog_id', 'explain' => "Using <tt>syslog</tt> for logging requires a syslog ID to be configured" ); } } // check ldap_public sources having global_search enabled if (is_array($this->config['ldap_public']) && !is_array($this->config['autocomplete_addressbooks'])) { foreach ($this->config['ldap_public'] as $ldap_public) { if ($ldap_public['global_search']) { $out['replaced'][] = array( 'prop' => 'ldap_public::global_search', 'replacement' => 'autocomplete_addressbooks' ); break; } } } return $out; }
[ "public", "function", "check_config", "(", ")", "{", "$", "this", "->", "load_config", "(", ")", ";", "if", "(", "!", "$", "this", "->", "configured", ")", "{", "return", ";", "}", "$", "out", "=", "$", "seen", "=", "array", "(", ")", ";", "// iterate over the current configuration", "foreach", "(", "array_keys", "(", "$", "this", "->", "config", ")", "as", "$", "prop", ")", "{", "if", "(", "$", "replacement", "=", "$", "this", "->", "replaced_config", "[", "$", "prop", "]", ")", "{", "$", "out", "[", "'replaced'", "]", "[", "]", "=", "array", "(", "'prop'", "=>", "$", "prop", ",", "'replacement'", "=>", "$", "replacement", ")", ";", "$", "seen", "[", "$", "replacement", "]", "=", "true", ";", "}", "else", "if", "(", "!", "$", "seen", "[", "$", "prop", "]", "&&", "in_array", "(", "$", "prop", ",", "$", "this", "->", "obsolete_config", ")", ")", "{", "$", "out", "[", "'obsolete'", "]", "[", "]", "=", "array", "(", "'prop'", "=>", "$", "prop", ")", ";", "$", "seen", "[", "$", "prop", "]", "=", "true", ";", "}", "}", "// the old default mime_magic reference is obsolete", "if", "(", "$", "this", "->", "config", "[", "'mime_magic'", "]", "==", "'/usr/share/misc/magic'", ")", "{", "$", "out", "[", "'obsolete'", "]", "[", "]", "=", "array", "(", "'prop'", "=>", "'mime_magic'", ",", "'explain'", "=>", "\"Set value to null in order to use system default\"", ")", ";", "}", "// check config dependencies and contradictions", "if", "(", "$", "this", "->", "config", "[", "'enable_spellcheck'", "]", "&&", "$", "this", "->", "config", "[", "'spellcheck_engine'", "]", "==", "'pspell'", ")", "{", "if", "(", "!", "extension_loaded", "(", "'pspell'", ")", ")", "{", "$", "out", "[", "'dependencies'", "]", "[", "]", "=", "array", "(", "'prop'", "=>", "'spellcheck_engine'", ",", "'explain'", "=>", "\"This requires the <tt>pspell</tt> extension which could not be loaded.\"", ")", ";", "}", "else", "if", "(", "!", "empty", "(", "$", "this", "->", "config", "[", "'spellcheck_languages'", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "config", "[", "'spellcheck_languages'", "]", "as", "$", "lang", "=>", "$", "descr", ")", "{", "if", "(", "!", "@", "pspell_new", "(", "$", "lang", ")", ")", "{", "$", "out", "[", "'dependencies'", "]", "[", "]", "=", "array", "(", "'prop'", "=>", "'spellcheck_languages'", ",", "'explain'", "=>", "\"You are missing pspell support for language $lang ($descr)\"", ")", ";", "}", "}", "}", "}", "if", "(", "$", "this", "->", "config", "[", "'log_driver'", "]", "==", "'syslog'", ")", "{", "if", "(", "!", "function_exists", "(", "'openlog'", ")", ")", "{", "$", "out", "[", "'dependencies'", "]", "[", "]", "=", "array", "(", "'prop'", "=>", "'log_driver'", ",", "'explain'", "=>", "\"This requires the <tt>syslog</tt> extension which could not be loaded.\"", ")", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "config", "[", "'syslog_id'", "]", ")", ")", "{", "$", "out", "[", "'dependencies'", "]", "[", "]", "=", "array", "(", "'prop'", "=>", "'syslog_id'", ",", "'explain'", "=>", "\"Using <tt>syslog</tt> for logging requires a syslog ID to be configured\"", ")", ";", "}", "}", "// check ldap_public sources having global_search enabled", "if", "(", "is_array", "(", "$", "this", "->", "config", "[", "'ldap_public'", "]", ")", "&&", "!", "is_array", "(", "$", "this", "->", "config", "[", "'autocomplete_addressbooks'", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "config", "[", "'ldap_public'", "]", "as", "$", "ldap_public", ")", "{", "if", "(", "$", "ldap_public", "[", "'global_search'", "]", ")", "{", "$", "out", "[", "'replaced'", "]", "[", "]", "=", "array", "(", "'prop'", "=>", "'ldap_public::global_search'", ",", "'replacement'", "=>", "'autocomplete_addressbooks'", ")", ";", "break", ";", "}", "}", "}", "return", "$", "out", ";", "}" ]
Check the current configuration for missing properties and deprecated or obsolete settings @return array List with problems detected
[ "Check", "the", "current", "configuration", "for", "missing", "properties", "and", "deprecated", "or", "obsolete", "settings" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_install.php#L308-L388
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_install.php
rcmail_install.merge_config
public function merge_config() { $current = $this->config; $this->config = array(); foreach ($this->replaced_config as $prop => $replacement) { if (isset($current[$prop])) { if ($prop == 'skin_path') { $this->config[$replacement] = preg_replace('#skins/(\w+)/?$#', '\\1', $current[$prop]); } else if ($prop == 'multiple_identities') { $this->config[$replacement] = $current[$prop] ? 2 : 0; } else { $this->config[$replacement] = $current[$prop]; } } unset($current[$prop]); } foreach ($this->obsolete_config as $prop) { unset($current[$prop]); } // add all ldap_public sources having global_search enabled to autocomplete_addressbooks if (is_array($current['ldap_public'])) { foreach ($current['ldap_public'] as $key => $ldap_public) { if ($ldap_public['global_search']) { $this->config['autocomplete_addressbooks'][] = $key; unset($current['ldap_public'][$key]['global_search']); } } } $this->config = array_merge($this->config, $current); foreach (array_keys((array) $current['ldap_public']) as $key) { $this->config['ldap_public'][$key] = $current['ldap_public'][$key]; } }
php
public function merge_config() { $current = $this->config; $this->config = array(); foreach ($this->replaced_config as $prop => $replacement) { if (isset($current[$prop])) { if ($prop == 'skin_path') { $this->config[$replacement] = preg_replace('#skins/(\w+)/?$#', '\\1', $current[$prop]); } else if ($prop == 'multiple_identities') { $this->config[$replacement] = $current[$prop] ? 2 : 0; } else { $this->config[$replacement] = $current[$prop]; } } unset($current[$prop]); } foreach ($this->obsolete_config as $prop) { unset($current[$prop]); } // add all ldap_public sources having global_search enabled to autocomplete_addressbooks if (is_array($current['ldap_public'])) { foreach ($current['ldap_public'] as $key => $ldap_public) { if ($ldap_public['global_search']) { $this->config['autocomplete_addressbooks'][] = $key; unset($current['ldap_public'][$key]['global_search']); } } } $this->config = array_merge($this->config, $current); foreach (array_keys((array) $current['ldap_public']) as $key) { $this->config['ldap_public'][$key] = $current['ldap_public'][$key]; } }
[ "public", "function", "merge_config", "(", ")", "{", "$", "current", "=", "$", "this", "->", "config", ";", "$", "this", "->", "config", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "replaced_config", "as", "$", "prop", "=>", "$", "replacement", ")", "{", "if", "(", "isset", "(", "$", "current", "[", "$", "prop", "]", ")", ")", "{", "if", "(", "$", "prop", "==", "'skin_path'", ")", "{", "$", "this", "->", "config", "[", "$", "replacement", "]", "=", "preg_replace", "(", "'#skins/(\\w+)/?$#'", ",", "'\\\\1'", ",", "$", "current", "[", "$", "prop", "]", ")", ";", "}", "else", "if", "(", "$", "prop", "==", "'multiple_identities'", ")", "{", "$", "this", "->", "config", "[", "$", "replacement", "]", "=", "$", "current", "[", "$", "prop", "]", "?", "2", ":", "0", ";", "}", "else", "{", "$", "this", "->", "config", "[", "$", "replacement", "]", "=", "$", "current", "[", "$", "prop", "]", ";", "}", "}", "unset", "(", "$", "current", "[", "$", "prop", "]", ")", ";", "}", "foreach", "(", "$", "this", "->", "obsolete_config", "as", "$", "prop", ")", "{", "unset", "(", "$", "current", "[", "$", "prop", "]", ")", ";", "}", "// add all ldap_public sources having global_search enabled to autocomplete_addressbooks", "if", "(", "is_array", "(", "$", "current", "[", "'ldap_public'", "]", ")", ")", "{", "foreach", "(", "$", "current", "[", "'ldap_public'", "]", "as", "$", "key", "=>", "$", "ldap_public", ")", "{", "if", "(", "$", "ldap_public", "[", "'global_search'", "]", ")", "{", "$", "this", "->", "config", "[", "'autocomplete_addressbooks'", "]", "[", "]", "=", "$", "key", ";", "unset", "(", "$", "current", "[", "'ldap_public'", "]", "[", "$", "key", "]", "[", "'global_search'", "]", ")", ";", "}", "}", "}", "$", "this", "->", "config", "=", "array_merge", "(", "$", "this", "->", "config", ",", "$", "current", ")", ";", "foreach", "(", "array_keys", "(", "(", "array", ")", "$", "current", "[", "'ldap_public'", "]", ")", "as", "$", "key", ")", "{", "$", "this", "->", "config", "[", "'ldap_public'", "]", "[", "$", "key", "]", "=", "$", "current", "[", "'ldap_public'", "]", "[", "$", "key", "]", ";", "}", "}" ]
Merge the current configuration with the defaults and copy replaced values to the new options.
[ "Merge", "the", "current", "configuration", "with", "the", "defaults", "and", "copy", "replaced", "values", "to", "the", "new", "options", "." ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_install.php#L394-L434
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_install.php
rcmail_install.db_schema_check
public function db_schema_check($db) { if (!$this->configured) { return false; } // read reference schema from mysql.initial.sql $engine = $db->db_provider; $db_schema = $this->db_read_schema(INSTALL_PATH . "SQL/$engine.initial.sql"); $errors = array(); // check list of tables $existing_tables = $db->list_tables(); foreach ($db_schema as $table => $cols) { $table = $this->config['db_prefix'] . $table; if (!in_array($table, $existing_tables)) { $errors[] = "Missing table '".$table."'"; } else { // compare cols $db_cols = $db->list_cols($table); $diff = array_diff(array_keys($cols), $db_cols); if (!empty($diff)) { $errors[] = "Missing columns in table '$table': " . join(',', $diff); } } } return !empty($errors) ? $errors : false; }
php
public function db_schema_check($db) { if (!$this->configured) { return false; } // read reference schema from mysql.initial.sql $engine = $db->db_provider; $db_schema = $this->db_read_schema(INSTALL_PATH . "SQL/$engine.initial.sql"); $errors = array(); // check list of tables $existing_tables = $db->list_tables(); foreach ($db_schema as $table => $cols) { $table = $this->config['db_prefix'] . $table; if (!in_array($table, $existing_tables)) { $errors[] = "Missing table '".$table."'"; } else { // compare cols $db_cols = $db->list_cols($table); $diff = array_diff(array_keys($cols), $db_cols); if (!empty($diff)) { $errors[] = "Missing columns in table '$table': " . join(',', $diff); } } } return !empty($errors) ? $errors : false; }
[ "public", "function", "db_schema_check", "(", "$", "db", ")", "{", "if", "(", "!", "$", "this", "->", "configured", ")", "{", "return", "false", ";", "}", "// read reference schema from mysql.initial.sql", "$", "engine", "=", "$", "db", "->", "db_provider", ";", "$", "db_schema", "=", "$", "this", "->", "db_read_schema", "(", "INSTALL_PATH", ".", "\"SQL/$engine.initial.sql\"", ")", ";", "$", "errors", "=", "array", "(", ")", ";", "// check list of tables", "$", "existing_tables", "=", "$", "db", "->", "list_tables", "(", ")", ";", "foreach", "(", "$", "db_schema", "as", "$", "table", "=>", "$", "cols", ")", "{", "$", "table", "=", "$", "this", "->", "config", "[", "'db_prefix'", "]", ".", "$", "table", ";", "if", "(", "!", "in_array", "(", "$", "table", ",", "$", "existing_tables", ")", ")", "{", "$", "errors", "[", "]", "=", "\"Missing table '\"", ".", "$", "table", ".", "\"'\"", ";", "}", "else", "{", "// compare cols", "$", "db_cols", "=", "$", "db", "->", "list_cols", "(", "$", "table", ")", ";", "$", "diff", "=", "array_diff", "(", "array_keys", "(", "$", "cols", ")", ",", "$", "db_cols", ")", ";", "if", "(", "!", "empty", "(", "$", "diff", ")", ")", "{", "$", "errors", "[", "]", "=", "\"Missing columns in table '$table': \"", ".", "join", "(", "','", ",", "$", "diff", ")", ";", "}", "}", "}", "return", "!", "empty", "(", "$", "errors", ")", "?", "$", "errors", ":", "false", ";", "}" ]
Compare the local database schema with the reference schema required for this version of Roundcube @param rcube_db $db Database object @return boolean True if the schema is up-to-date, false if not or an error occurred
[ "Compare", "the", "local", "database", "schema", "with", "the", "reference", "schema", "required", "for", "this", "version", "of", "Roundcube" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_install.php#L444-L475
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_install.php
rcmail_install.db_read_schema
private function db_read_schema($schemafile) { $lines = file($schemafile); $table_block = false; $schema = array(); $keywords = array('PRIMARY','KEY','INDEX','UNIQUE','CONSTRAINT','REFERENCES','FOREIGN'); foreach ($lines as $line) { if (preg_match('/^\s*create table ([\S]+)/i', $line, $m)) { $table_name = explode('.', $m[1]); $table_name = end($table_name); $table_name = preg_replace('/[`"\[\]]/', '', $table_name); } else if ($table_name && ($line = trim($line))) { if ($line == 'GO' || $line[0] == ')' || $line[strlen($line)-1] == ';') { $table_name = null; } else { $items = explode(' ', $line); $col = $items[0]; $col = preg_replace('/[`"\[\]]/', '', $col); if (!in_array(strtoupper($col), $keywords)) { $type = strtolower($items[1]); $type = preg_replace('/[^a-zA-Z0-9()]/', '', $type); $schema[$table_name][$col] = $type; } } } } return $schema; }
php
private function db_read_schema($schemafile) { $lines = file($schemafile); $table_block = false; $schema = array(); $keywords = array('PRIMARY','KEY','INDEX','UNIQUE','CONSTRAINT','REFERENCES','FOREIGN'); foreach ($lines as $line) { if (preg_match('/^\s*create table ([\S]+)/i', $line, $m)) { $table_name = explode('.', $m[1]); $table_name = end($table_name); $table_name = preg_replace('/[`"\[\]]/', '', $table_name); } else if ($table_name && ($line = trim($line))) { if ($line == 'GO' || $line[0] == ')' || $line[strlen($line)-1] == ';') { $table_name = null; } else { $items = explode(' ', $line); $col = $items[0]; $col = preg_replace('/[`"\[\]]/', '', $col); if (!in_array(strtoupper($col), $keywords)) { $type = strtolower($items[1]); $type = preg_replace('/[^a-zA-Z0-9()]/', '', $type); $schema[$table_name][$col] = $type; } } } } return $schema; }
[ "private", "function", "db_read_schema", "(", "$", "schemafile", ")", "{", "$", "lines", "=", "file", "(", "$", "schemafile", ")", ";", "$", "table_block", "=", "false", ";", "$", "schema", "=", "array", "(", ")", ";", "$", "keywords", "=", "array", "(", "'PRIMARY'", ",", "'KEY'", ",", "'INDEX'", ",", "'UNIQUE'", ",", "'CONSTRAINT'", ",", "'REFERENCES'", ",", "'FOREIGN'", ")", ";", "foreach", "(", "$", "lines", "as", "$", "line", ")", "{", "if", "(", "preg_match", "(", "'/^\\s*create table ([\\S]+)/i'", ",", "$", "line", ",", "$", "m", ")", ")", "{", "$", "table_name", "=", "explode", "(", "'.'", ",", "$", "m", "[", "1", "]", ")", ";", "$", "table_name", "=", "end", "(", "$", "table_name", ")", ";", "$", "table_name", "=", "preg_replace", "(", "'/[`\"\\[\\]]/'", ",", "''", ",", "$", "table_name", ")", ";", "}", "else", "if", "(", "$", "table_name", "&&", "(", "$", "line", "=", "trim", "(", "$", "line", ")", ")", ")", "{", "if", "(", "$", "line", "==", "'GO'", "||", "$", "line", "[", "0", "]", "==", "')'", "||", "$", "line", "[", "strlen", "(", "$", "line", ")", "-", "1", "]", "==", "';'", ")", "{", "$", "table_name", "=", "null", ";", "}", "else", "{", "$", "items", "=", "explode", "(", "' '", ",", "$", "line", ")", ";", "$", "col", "=", "$", "items", "[", "0", "]", ";", "$", "col", "=", "preg_replace", "(", "'/[`\"\\[\\]]/'", ",", "''", ",", "$", "col", ")", ";", "if", "(", "!", "in_array", "(", "strtoupper", "(", "$", "col", ")", ",", "$", "keywords", ")", ")", "{", "$", "type", "=", "strtolower", "(", "$", "items", "[", "1", "]", ")", ";", "$", "type", "=", "preg_replace", "(", "'/[^a-zA-Z0-9()]/'", ",", "''", ",", "$", "type", ")", ";", "$", "schema", "[", "$", "table_name", "]", "[", "$", "col", "]", "=", "$", "type", ";", "}", "}", "}", "}", "return", "$", "schema", ";", "}" ]
Utility function to read database schema from an .sql file
[ "Utility", "function", "to", "read", "database", "schema", "from", "an", ".", "sql", "file" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_install.php#L480-L513
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_install.php
rcmail_install.check_mime_detection
public function check_mime_detection() { $errors = array(); $files = array( 'program/resources/tinymce/video.png' => 'image/png', 'program/resources/blank.tiff' => 'image/tiff', 'program/resources/blocked.gif' => 'image/gif', ); foreach ($files as $path => $expected) { $mimetype = rcube_mime::file_content_type(INSTALL_PATH . $path, basename($path)); if ($mimetype != $expected) { $errors[] = array($path, $mimetype, $expected); } } return $errors; }
php
public function check_mime_detection() { $errors = array(); $files = array( 'program/resources/tinymce/video.png' => 'image/png', 'program/resources/blank.tiff' => 'image/tiff', 'program/resources/blocked.gif' => 'image/gif', ); foreach ($files as $path => $expected) { $mimetype = rcube_mime::file_content_type(INSTALL_PATH . $path, basename($path)); if ($mimetype != $expected) { $errors[] = array($path, $mimetype, $expected); } } return $errors; }
[ "public", "function", "check_mime_detection", "(", ")", "{", "$", "errors", "=", "array", "(", ")", ";", "$", "files", "=", "array", "(", "'program/resources/tinymce/video.png'", "=>", "'image/png'", ",", "'program/resources/blank.tiff'", "=>", "'image/tiff'", ",", "'program/resources/blocked.gif'", "=>", "'image/gif'", ",", ")", ";", "foreach", "(", "$", "files", "as", "$", "path", "=>", "$", "expected", ")", "{", "$", "mimetype", "=", "rcube_mime", "::", "file_content_type", "(", "INSTALL_PATH", ".", "$", "path", ",", "basename", "(", "$", "path", ")", ")", ";", "if", "(", "$", "mimetype", "!=", "$", "expected", ")", "{", "$", "errors", "[", "]", "=", "array", "(", "$", "path", ",", "$", "mimetype", ",", "$", "expected", ")", ";", "}", "}", "return", "$", "errors", ";", "}" ]
Try to detect some file's mimetypes to test the correct behavior of fileinfo
[ "Try", "to", "detect", "some", "file", "s", "mimetypes", "to", "test", "the", "correct", "behavior", "of", "fileinfo" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_install.php#L518-L535
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_install.php
rcmail_install.check_mime_extensions
public function check_mime_extensions() { $errors = array(); $types = array( 'application/zip' => 'zip', 'text/css' => 'css', 'application/pdf' => 'pdf', 'image/gif' => 'gif', 'image/svg+xml' => 'svg', ); foreach ($types as $mimetype => $expected) { $ext = rcube_mime::get_mime_extensions($mimetype); if (!in_array($expected, (array) $ext)) { $errors[] = array($mimetype, $ext, $expected); } } return $errors; }
php
public function check_mime_extensions() { $errors = array(); $types = array( 'application/zip' => 'zip', 'text/css' => 'css', 'application/pdf' => 'pdf', 'image/gif' => 'gif', 'image/svg+xml' => 'svg', ); foreach ($types as $mimetype => $expected) { $ext = rcube_mime::get_mime_extensions($mimetype); if (!in_array($expected, (array) $ext)) { $errors[] = array($mimetype, $ext, $expected); } } return $errors; }
[ "public", "function", "check_mime_extensions", "(", ")", "{", "$", "errors", "=", "array", "(", ")", ";", "$", "types", "=", "array", "(", "'application/zip'", "=>", "'zip'", ",", "'text/css'", "=>", "'css'", ",", "'application/pdf'", "=>", "'pdf'", ",", "'image/gif'", "=>", "'gif'", ",", "'image/svg+xml'", "=>", "'svg'", ",", ")", ";", "foreach", "(", "$", "types", "as", "$", "mimetype", "=>", "$", "expected", ")", "{", "$", "ext", "=", "rcube_mime", "::", "get_mime_extensions", "(", "$", "mimetype", ")", ";", "if", "(", "!", "in_array", "(", "$", "expected", ",", "(", "array", ")", "$", "ext", ")", ")", "{", "$", "errors", "[", "]", "=", "array", "(", "$", "mimetype", ",", "$", "ext", ",", "$", "expected", ")", ";", "}", "}", "return", "$", "errors", ";", "}" ]
Check the correct configuration of the 'mime_types' mapping option
[ "Check", "the", "correct", "configuration", "of", "the", "mime_types", "mapping", "option" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_install.php#L540-L559
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_install.php
rcmail_install.get_hostlist
public function get_hostlist() { $default_hosts = (array) $this->getprop('default_host'); $out = array(); foreach ($default_hosts as $key => $name) { if (!empty($name)) { $out[] = rcube_utils::parse_host(is_numeric($key) ? $name : $key); } } return $out; }
php
public function get_hostlist() { $default_hosts = (array) $this->getprop('default_host'); $out = array(); foreach ($default_hosts as $key => $name) { if (!empty($name)) { $out[] = rcube_utils::parse_host(is_numeric($key) ? $name : $key); } } return $out; }
[ "public", "function", "get_hostlist", "(", ")", "{", "$", "default_hosts", "=", "(", "array", ")", "$", "this", "->", "getprop", "(", "'default_host'", ")", ";", "$", "out", "=", "array", "(", ")", ";", "foreach", "(", "$", "default_hosts", "as", "$", "key", "=>", "$", "name", ")", "{", "if", "(", "!", "empty", "(", "$", "name", ")", ")", "{", "$", "out", "[", "]", "=", "rcube_utils", "::", "parse_host", "(", "is_numeric", "(", "$", "key", ")", "?", "$", "name", ":", "$", "key", ")", ";", "}", "}", "return", "$", "out", ";", "}" ]
Return a list with all imap hosts configured @return array Clean list with imap hosts
[ "Return", "a", "list", "with", "all", "imap", "hosts", "configured" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_install.php#L576-L588
train
i-MSCP/roundcube
roundcubemail/program/include/rcmail_install.php
rcmail_install.list_skins
public function list_skins() { $skins = array(); $skindir = INSTALL_PATH . 'skins/'; foreach (glob($skindir . '*') as $path) { if (is_dir($path) && is_readable($path)) { $skins[] = substr($path, strlen($skindir)); } } return $skins; }
php
public function list_skins() { $skins = array(); $skindir = INSTALL_PATH . 'skins/'; foreach (glob($skindir . '*') as $path) { if (is_dir($path) && is_readable($path)) { $skins[] = substr($path, strlen($skindir)); } } return $skins; }
[ "public", "function", "list_skins", "(", ")", "{", "$", "skins", "=", "array", "(", ")", ";", "$", "skindir", "=", "INSTALL_PATH", ".", "'skins/'", ";", "foreach", "(", "glob", "(", "$", "skindir", ".", "'*'", ")", "as", "$", "path", ")", "{", "if", "(", "is_dir", "(", "$", "path", ")", "&&", "is_readable", "(", "$", "path", ")", ")", "{", "$", "skins", "[", "]", "=", "substr", "(", "$", "path", ",", "strlen", "(", "$", "skindir", ")", ")", ";", "}", "}", "return", "$", "skins", ";", "}" ]
Return a list with available subfolders of the skin directory
[ "Return", "a", "list", "with", "available", "subfolders", "of", "the", "skin", "directory" ]
141965e74cf301575198abc6bf12f207aacaa6c3
https://github.com/i-MSCP/roundcube/blob/141965e74cf301575198abc6bf12f207aacaa6c3/roundcubemail/program/include/rcmail_install.php#L615-L627
train