From 3b0030e82ba6da09fe55643a288a56868525f2e1 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Tue, 17 Jan 2023 14:42:47 +0900 Subject: [PATCH 01/10] Enable trim_trailing_whitespace in .editorconfig and add exceptions for more file types --- .editorconfig | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index d433b6938..3a0b56850 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,12 +1,15 @@ root = true [*] -end_of_line = lf charset = utf-8 -trim_trailing_whitespace = false +end_of_line = lf +trim_trailing_whitespace = true insert_final_newline = true indent_style = tab +[*.md] +trim_trailing_whitespace = false + [*.py] indent_style = space indent_size = 4 @@ -14,3 +17,7 @@ indent_size = 4 [*.{json,yml,md}] indent_style = space indent_size = 2 + +[*.{jsx,tsx,svelte,vue}] +indent_style = space +indent_size = 2 From a9f72a5cd23d01ca311e31d29eee3d7f2cc26219 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Tue, 17 Jan 2023 20:57:44 +0900 Subject: [PATCH 02/10] Remove trailing whitespace --- common/autoload.php | 6 +- common/framework/Cache.php | 100 ++--- common/framework/Calendar.php | 36 +- common/framework/Config.php | 42 +- common/framework/DB.php | 344 ++++++++--------- common/framework/DateTime.php | 44 +-- common/framework/Debug.php | 220 +++++------ common/framework/Exception.php | 2 +- common/framework/Formatter.php | 122 +++--- common/framework/Image.php | 10 +- common/framework/Korea.php | 102 ++--- common/framework/Lang.php | 90 ++--- common/framework/MIME.php | 40 +- common/framework/Mail.php | 130 +++---- common/framework/Pagination.php | 34 +- common/framework/Password.php | 102 ++--- common/framework/Push.php | 114 +++--- common/framework/Router.php | 102 ++--- common/framework/SMS.php | 208 +++++----- common/framework/Security.php | 88 ++--- common/framework/Session.php | 364 +++++++++--------- common/framework/Storage.php | 228 +++++------ common/framework/Timer.php | 32 +- common/framework/UA.php | 92 ++--- common/framework/URL.php | 58 +-- common/framework/drivers/CacheInterface.php | 56 +-- common/framework/drivers/MailInterface.php | 34 +- common/framework/drivers/PushInterface.php | 26 +- common/framework/drivers/SMSInterface.php | 34 +- common/framework/drivers/cache/apc.php | 64 +-- common/framework/drivers/cache/dummy.php | 38 +- common/framework/drivers/cache/file.php | 68 ++-- common/framework/drivers/cache/memcached.php | 70 ++-- common/framework/drivers/cache/redis.php | 68 ++-- common/framework/drivers/cache/sqlite.php | 86 ++--- common/framework/drivers/mail/base.php | 40 +- common/framework/drivers/mail/dummy.php | 10 +- .../framework/drivers/mail/mailfunction.php | 22 +- common/framework/drivers/mail/mailgun.php | 30 +- common/framework/drivers/mail/mandrill.php | 12 +- common/framework/drivers/mail/postmark.php | 12 +- common/framework/drivers/mail/sendgrid.php | 46 +-- common/framework/drivers/mail/ses.php | 22 +- common/framework/drivers/mail/smtp.php | 18 +- common/framework/drivers/mail/sparkpost.php | 32 +- common/framework/drivers/mail/woorimail.php | 42 +- common/framework/drivers/push/apns.php | 18 +- common/framework/drivers/push/base.php | 32 +- common/framework/drivers/push/fcm.php | 16 +- common/framework/drivers/sms/apistore.php | 34 +- common/framework/drivers/sms/base.php | 42 +- common/framework/drivers/sms/coolsms.php | 16 +- common/framework/drivers/sms/dummy.php | 22 +- common/framework/drivers/sms/iwinv.php | 26 +- common/framework/drivers/sms/ppurio.php | 24 +- common/framework/drivers/sms/solapi.php | 10 +- .../framework/filters/FileContentFilter.php | 44 +-- common/framework/filters/FilenameFilter.php | 38 +- common/framework/filters/HTMLFilter.php | 138 +++---- common/framework/filters/IpFilter.php | 50 +-- common/framework/filters/MediaFilter.php | 72 ++-- common/framework/helpers/ConfigHelper.php | 18 +- common/framework/helpers/DBHelper.php | 32 +- common/framework/helpers/DBResultHelper.php | 2 +- common/framework/helpers/DBStmtHelper.php | 12 +- common/framework/helpers/SessionHelper.php | 24 +- common/framework/i18n.php | 34 +- common/framework/parsers/BaseParser.php | 16 +- common/framework/parsers/ConfigParser.php | 54 +-- common/framework/parsers/DBQueryParser.php | 40 +- common/framework/parsers/DBTableParser.php | 68 ++-- .../parsers/EditorComponentParser.php | 14 +- common/framework/parsers/LangParser.php | 16 +- .../framework/parsers/ModuleActionParser.php | 38 +- common/framework/parsers/ModuleInfoParser.php | 18 +- common/framework/parsers/XMLRPCParser.php | 10 +- common/framework/parsers/dbquery/Query.php | 168 ++++---- .../parsers/dbquery/VariableBase.php | 66 ++-- common/framework/parsers/dbtable/Table.php | 14 +- common/functions.php | 104 ++--- common/legacy.php | 40 +- 81 files changed, 2455 insertions(+), 2455 deletions(-) diff --git a/common/autoload.php b/common/autoload.php index 6838590e5..56cca2713 100644 --- a/common/autoload.php +++ b/common/autoload.php @@ -107,7 +107,7 @@ spl_autoload_register(function($class_name) $filename2 = null; $lang_plugin = null; $lang_path = null; - + // Try namespaced classes, legacy classes, and module classes. if (preg_match('!^Rhymix/(Framework|Addons|Modules|Plugins|Themes|Widgets)/((\w+)/(?:\w+/)*)?(\w+)$!', $class_name, $matches)) { @@ -136,7 +136,7 @@ spl_autoload_register(function($class_name) $lang_path = RX_BASEDIR . 'modules/' . $module . '/lang'; } } - + // Load the PHP file. if ($filename1 && file_exists($filename1)) { @@ -146,7 +146,7 @@ spl_autoload_register(function($class_name) { include $filename2; } - + // Load the lang file for the plugin. if ($lang_plugin) { diff --git a/common/framework/Cache.php b/common/framework/Cache.php index f8a198a9e..1f3fe58fb 100644 --- a/common/framework/Cache.php +++ b/common/framework/Cache.php @@ -12,25 +12,25 @@ class Cache */ protected static $_driver = null; protected static $_driver_name = null; - + /** * The cache prefix. */ protected static $_prefix = null; - + /** * The default TTL. */ protected static $_ttl = 86400; - + /** * Cache group versions. */ protected static $_group_versions = array(); - + /** * Initialize the cache system. - * + * * @param array $config * @return void */ @@ -40,7 +40,7 @@ class Cache { $config = array($config); } - + if (isset($config['type'])) { $driver_name = $config['type']; @@ -61,7 +61,7 @@ class Cache $driver_name = null; $class_name = null; } - + if ($class_name !== null && $driver_name !== 'file' && class_exists($class_name) && $class_name::isSupported()) { self::$_driver = $class_name::getInstance($config); @@ -72,7 +72,7 @@ class Cache self::$_driver = Drivers\Cache\Dummy::getInstance(array()); self::$_driver_name = 'dummy'; } - + if (self::$_driver->prefix) { self::$_prefix = substr(sha1(\RX_BASEDIR), 0, 10) . ':' . \RX_VERSION . ':'; @@ -81,13 +81,13 @@ class Cache { self::$_prefix = \RX_VERSION . ':'; } - + return self::$_driver; } - + /** * Get the list of supported cache drivers. - * + * * @return array */ public static function getSupportedDrivers() @@ -104,20 +104,20 @@ class Cache } return $result; } - + /** * Get the name of the currently enabled cache driver. - * + * * @return string|null */ public static function getDriverName() { return self::$_driver_name; } - + /** * Get the currently enabled cache driver, or a named driver with the given settings. - * + * * @param string $name (optional) * @param array $config (optional) * @return object|null @@ -141,30 +141,30 @@ class Cache } } } - + /** * Get the automatically generated cache prefix for this installation of Rhymix. - * + * * @return object|null */ public static function getPrefix() { return self::$_prefix; } - + /** * Get the default TTL. - * + * * @return int */ public static function getDefaultTTL() { return self::$_ttl; } - + /** * Set the default TTL. - * + * * @param int $ttl * @return void */ @@ -172,12 +172,12 @@ class Cache { self::$_ttl = $ttl; } - + /** * Get the value of a key. - * + * * This method returns null if the key was not found. - * + * * @param string $key * @return mixed */ @@ -192,14 +192,14 @@ class Cache return null; } } - + /** * Set the value to a key. - * + * * This method returns true on success and false on failure. * $ttl is measured in seconds. If it is not given, the default TTL is used. * $force is used to cache essential data when using the default driver. - * + * * @param string $key * @param mixed $value * @param int $ttl (optional) @@ -226,13 +226,13 @@ class Cache return false; } } - + /** * Delete a key. - * + * * This method returns true on success and false on failure. * If the key does not exist, it should return false. - * + * * @param string $key * @return bool */ @@ -247,12 +247,12 @@ class Cache return false; } } - + /** * Check if a key exists. - * + * * This method returns true on success and false on failure. - * + * * @param string $key * @return bool */ @@ -267,13 +267,13 @@ class Cache return false; } } - + /** * Increase the value of a key by $amount. - * + * * If the key does not exist, this method assumes that the current value is zero. * This method returns the new value, or -1 on failure. - * + * * @param string $key * @param int $amount (optional) * @return int @@ -289,13 +289,13 @@ class Cache return -1; } } - + /** * Decrease the value of a key by $amount. - * + * * If the key does not exist, this method assumes that the current value is zero. * This method returns the new value, or -1 on failure. - * + * * @param string $key * @param int $amount (optional) * @return int @@ -311,12 +311,12 @@ class Cache return -1; } } - + /** * Clear a group of keys from the cache. - * + * * This method returns true on success and false on failure. - * + * * @param string $group_name * @return bool */ @@ -333,12 +333,12 @@ class Cache return false; } } - + /** * Clear all keys from the cache. - * + * * This method returns true on success and false on failure. - * + * * @return bool */ public static function clearAll(): bool @@ -352,10 +352,10 @@ class Cache return false; } } - + /** * Get the group version. - * + * * @param string $group_name * @return int */ @@ -377,10 +377,10 @@ class Cache } } } - + /** * Get the actual key used by Rhymix. - * + * * @param string $key * @return string */ @@ -390,7 +390,7 @@ class Cache { $key = $matches[1] . '#' . self::getGroupVersion($matches[1]) . ':' . $matches[2]; } - + return self::$_prefix . $key; } } diff --git a/common/framework/Calendar.php b/common/framework/Calendar.php index 67aaafbe4..3c65a2c83 100644 --- a/common/framework/Calendar.php +++ b/common/framework/Calendar.php @@ -9,7 +9,7 @@ class Calendar { /** * This method returns the English name of a month, e.g. 9 = 'September'. - * + * * @param int $month_number * @param bool $long_format (optional, default is true) * @return string @@ -21,16 +21,16 @@ class Calendar { return false; } - + return date($long_format ? 'F' : 'M', mktime(0, 0, 0, $month_number, 1)); } - + /** * This method returns the day on which a month begins. - * + * * 0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday. * If you do not specify a year, the current year is assumed. - * + * * @param int $month_number * @param int $year (optional) * @return int @@ -42,16 +42,16 @@ class Calendar { return false; } - + return (int)date('w', mktime(0, 0, 0, $month_number, 1, $year ?: date('Y'))); } - + /** * This method returns the number of days in a month, e.g. February 2016 has 29 days. - * + * * If you do not specify a year, the current year is assumed. * You must specify a year to get the number of days in February. - * + * * @param int $month_number * @param int $year (optional) * @return int @@ -63,19 +63,19 @@ class Calendar { return false; } - + return (int)date('t', mktime(0, 0, 0, $month_number, 1, $year ?: date('Y'))); } - + /** * This method returns a complete calendar for a month. - * + * * The return value is an array with six members, each representing a week. * Each week is an array with seven members, each representing a day. * 6 weeks are returned. Empty cells are represented by nulls. - * + * * If you do not specify a year, the current year is assumed. - * + * * @param int $month_number * @param int $year (optional) * @param int $start_dow (optional) @@ -96,13 +96,13 @@ class Calendar { $year = date('Y'); } - + $start = self::getMonthStartDayOfWeek($month_number, $year); $count = self::getMonthDays($month_number, $year); $initial_blank_cells = (7 + $start - $start_dow) % 7; $final_blank_cells = 42 - $count - $initial_blank_cells; $temp = array(); - + for ($i = 0; $i < $initial_blank_cells; $i++) { $temp[] = null; @@ -115,7 +115,7 @@ class Calendar { $temp[] = null; } - + $return = array(); for ($i = 0; $i < 6; $i++) { @@ -126,7 +126,7 @@ class Calendar } $return[] = $week; } - + return $return; } } diff --git a/common/framework/Config.php b/common/framework/Config.php index 490529d4f..b7e75c792 100644 --- a/common/framework/Config.php +++ b/common/framework/Config.php @@ -11,7 +11,7 @@ class Config * System configuration is stored here. */ protected static $_config = array(); - + /** * Location of configuration files. */ @@ -20,10 +20,10 @@ class Config public static $old_ftp_config_filename = 'files/config/ftp.config.php'; public static $old_lang_config_filename = 'files/config/lang_selected.info'; public static $default_config_filename = 'common/defaults/config.php'; - + /** * Load system configuration. - * + * * @return void */ public static function init() @@ -43,30 +43,30 @@ class Config } return self::$_config; } - + /** * Get all system configuration. - * + * * @return array */ public static function getAll() { return self::$_config; } - + /** * Get default system configuration. - * + * * @return array */ public static function getDefaults() { return (include \RX_BASEDIR . self::$default_config_filename); } - + /** * Get a system configuration value. - * + * * @param string $key * @return mixed */ @@ -88,10 +88,10 @@ class Config } return $data; } - + /** * Set a system configuration value. - * + * * @param string $key * @param mixed $value * @return void @@ -110,10 +110,10 @@ class Config } $data = $value; } - + /** * Set all system configuration. - * + * * @param array $config * @return void */ @@ -121,10 +121,10 @@ class Config { self::$_config = $config; } - + /** * Save the current system configuration. - * + * * @param array $config (optional) * @return bool */ @@ -134,7 +134,7 @@ class Config { self::setAll($config); } - + // Backup the main config file. $config_filename = \RX_BASEDIR . self::$config_filename; if (Storage::exists($config_filename)) @@ -147,7 +147,7 @@ class Config return false; } } - + // Save the main config file. $buff = 'getMessage()); } - + // Get the DB version. $this->db_version = $this->_handle->getAttribute(\PDO::ATTR_SERVER_VERSION); - + // Cache the debug comment setting. $this->_debug_queries = in_array('queries', Config::get('debug.display_content') ?: []); $this->_debug_comment = !!config('debug.query_comment'); $this->_debug_full_stack = !!Config::get('debug.query_full_stack'); } - + /** * Get the PDO handle for direct manipulation. - * + * * @return Helpers\DBHelper */ public function getHandle(): Helpers\DBHelper { return $this->_handle; } - + /** * Create a prepared statement. - * + * * Table names in the FROM or JOIN clause of the statement are * automatically prefixed with the configured prefix. - * + * * @param string $statement * @param array $driver_options * @return Helpers\DBStmtHelper @@ -162,30 +162,30 @@ class DB { // Add table prefixes to the query string. $statement = $this->addPrefixes($statement); - + // Add the debug comment. if ($this->_debug_comment) { $statement .= "\n" . sprintf('/* prepare() %s */', \RX_CLIENT_IP); } - + // Create and return a prepared statement. $this->_last_stmt = null; $this->_last_stmt = $this->_handle->prepare($statement, $driver_options); return $this->_last_stmt; } - + /** * Execute a query string with or without parameters. - * + * * This method will automatically use prepared statements if there are * any parameters. It is strongly recommended to pass any user-supplied * values as separate parameters instead of embedding them directly * in the query string, in order to prevent SQL injection attacks. - * + * * Table names in the FROM or JOIN clause of the statement are * automatically prefixed with the configured prefix. - * + * * @param string $query_string * @param mixed ...$args * @return Helpers\DBStmtHelper @@ -197,16 +197,16 @@ class DB { $args = $args[0]; } - + // Add table prefixes to the query string. $query_string = $this->addPrefixes($query_string); - + // Add the debug comment. if ($this->_debug_comment) { $query_string .= "\n" . sprintf('/* query() %s */', \RX_CLIENT_IP); } - + // Execute either a prepared statement or a regular query depending on whether there are arguments. $this->_last_stmt = null; if (count($args)) @@ -220,10 +220,10 @@ class DB } return $this->_last_stmt; } - + /** * Execute an XML-defined query. - * + * * @param string $query_id * @param array $args * @param array $columns @@ -250,13 +250,13 @@ class DB { return $this->setError(-1, 'DB is not configured.'); } - + // Force the column list to a numerical array. $column_list = is_array($column_list) ? array_values($column_list) : array(); - + // Start measuring elapsed time. $start_time = microtime(true); - + // Get the name of the XML file. $parts = explode('.', $query_id); if (count($parts) === 2) @@ -271,7 +271,7 @@ class DB $this->_total_time += (microtime(true) - $start_time); return $output; } - + // Parse and cache the XML file. $cache_key = sprintf('query:%s:%d', $filename, filemtime($filename)); $query = Cache::get($cache_key); @@ -290,7 +290,7 @@ class DB return $output; } } - + // Get the query string and parameters. try { @@ -304,7 +304,7 @@ class DB $this->_total_time += (microtime(true) - $start_time); return $output; } - + // If this query requires pagination, execute the COUNT(*) query first. $last_index = 0; if ($query->requiresPagination()) @@ -319,7 +319,7 @@ class DB $this->_total_time += (microtime(true) - $start_time); return $output; } - + // Do not execute the main query if the current page is out of bounds. if ($output->page > $output->total_page) { @@ -335,7 +335,7 @@ class DB { $output = new Helpers\DBResultHelper; } - + // Prepare and execute the main query. try { @@ -343,7 +343,7 @@ class DB { $query_string .= "\n" . sprintf('/* %s %s */', $query_id, \RX_CLIENT_IP); } - + $this->_query_id = $query_id; $this->_last_stmt = null; if (count($query_params)) @@ -355,7 +355,7 @@ class DB { $this->_last_stmt = $this->_handle->query($query_string); } - + if ($this->isError()) { $output = $this->getError(); @@ -387,22 +387,22 @@ class DB $this->_total_time += (microtime(true) - $start_time); return $output; } - + // Fill query information and result data in the output object. $this->_query_id = ''; $this->_total_time += ($elapsed_time = microtime(true) - $start_time); $output->add('_query', $query_string); $output->add('_elapsed_time', sprintf('%0.5f', $elapsed_time)); $output->data = $result; - + // Return the complete result. $this->clearError(); return $output; } - + /** * Execute a COUNT(*) query for pagination. - * + * * @param string $query_id * @param Parsers\DBQuery\Query $query * @param array $args @@ -421,7 +421,7 @@ class DB { return $this->setError(-1, $e->getMessage()); } - + // Prepare and execute the query. try { @@ -429,7 +429,7 @@ class DB { $query_string .= "\n" . sprintf('/* %s %s */', $query_id, \RX_CLIENT_IP); } - + $this->_last_stmt = null; if (count($query_params)) { @@ -440,7 +440,7 @@ class DB { $this->_last_stmt = $this->_handle->query($query_string); } - + if ($this->isError()) { return $this->getError(); @@ -461,7 +461,7 @@ class DB $output = $this->setError(-1, $e->getMessage()); return $output; } - + // Collect various counts used in the page calculation. list($is_expression, $list_count) = $query->navigation->list_count->getValue($args); list($is_expression, $page_count) = $query->navigation->page_count->getValue($args); @@ -470,7 +470,7 @@ class DB $total_page = max(1, intval(ceil($total_count / $list_count))); $last_index = $total_count - (($page - 1) * $list_count); $page_handler = new \PageHandler($total_count, $total_page, $page, $page_count ?: 10); - + // Compose the output object. $output = new Helpers\DBResultHelper; $output->add('_count', $query_string); @@ -481,13 +481,13 @@ class DB $output->page_navigation = $page_handler; return $output; } - + /** * Execute a literal query string. - * + * * This method should not be public, as it starts with an underscore. * But since there are many legacy apps that rely on it, we will leave it public. - * + * * @param string $query_string * @return Helpers\DBStmtHelper */ @@ -497,18 +497,18 @@ class DB { $query_string .= "\n" . sprintf('/* _query() %s */', \RX_CLIENT_IP); } - + $this->_last_stmt = null; $this->_last_stmt = $this->_handle->query($query_string); return $this->_last_stmt; } - + /** * Fetch results from a query. - * + * * This method should not be public, as it starts with an underscore. * But since there are many legacy apps that rely on it, we will leave it public. - * + * * @param \PDOStatement $stmt * @param int $last_index * @param string $result_type @@ -525,7 +525,7 @@ class DB { return $stmt; } - + try { $result = array(); @@ -541,14 +541,14 @@ class DB $result[$index] = $row; $index += $step; } - + $stmt->closeCursor(); } catch (\PDOException $e) { throw new Exceptions\DBError($e->getMessage()); } - + if ($result_type === 'auto' && $last_index === 0 && count($result) <= 1) { return isset($result[0]) ? $result[0] : null; @@ -558,10 +558,10 @@ class DB return $result; } } - + /** * Begin a transaction. - * + * * @return int */ public function begin(): int @@ -577,7 +577,7 @@ class DB { $this->setError(-1, $e->getMessage()); } - + if (Debug::isEnabledForCurrentUser()) { Debug::addQuery($this->getQueryLog('START TRANSACTION', 0)); @@ -590,10 +590,10 @@ class DB $this->_transaction_level++; return $this->_transaction_level; } - + /** * Roll back a transaction. - * + * * @return int */ public function rollback(): int @@ -609,7 +609,7 @@ class DB { $this->setError(-1, $e->getMessage()); } - + if (Debug::isEnabledForCurrentUser()) { Debug::addQuery($this->getQueryLog('ROLLBACK', 0)); @@ -619,17 +619,17 @@ class DB { $this->_handle->exec(sprintf('ROLLBACK TO SAVEPOINT `%s%s%d`', $this->_prefix, 'savepoint', $this->_transaction_level - 1)); } - + if ($this->_transaction_level > 0) { $this->_transaction_level--; } return $this->_transaction_level; } - + /** * Commit a transaction. - * + * * @return int */ public function commit(): int @@ -645,7 +645,7 @@ class DB { $this->setError(-1, $e->getMessage()); } - + if (Debug::isEnabledForCurrentUser()) { Debug::addQuery($this->getQueryLog('COMMIT', 0)); @@ -658,44 +658,44 @@ class DB Debug::addQuery($this->getQueryLog('NESTED COMMIT IGNORED BY RHYMIX', 0)); } } - + if ($this->_transaction_level > 0) { $this->_transaction_level--; } return $this->_transaction_level; } - + /** * Get the current transaction level. - * + * * @return int */ public function getTransactionLevel(): int { return $this->_transaction_level; } - + /** * Get the number of rows affected by the last statement. - * + * * @return int */ public function getAffectedRows(): int { return $this->_last_stmt ? intval($this->_last_stmt->rowCount()) : 0; } - + /** * Get the auto-incremented ID generated by the last statement. - * + * * @return int */ public function getInsertID(): int { return intval($this->_handle->lastInsertId()); } - + /** * Get the next global sequence value. */ @@ -707,19 +707,19 @@ class DB { throw new Exceptions\DBError($this->getError()->getMessage()); } - + if($sequence % 10000 == 0) { $this->_handle->exec(sprintf('DELETE FROM `%s` WHERE seq < %d', $this->addQuotes($this->_prefix . 'sequence'), $sequence)); } - + $this->clearError(); return $sequence; } - + /** * Check if a password is valid according to MySQL's old password hashing algorithm. - * + * * @param string $password * @param string $saved_password * @return bool @@ -734,10 +734,10 @@ class DB { return Password::checkPassword($password, $saved_password, 'mysql_old_password'); } - + return false; } - + /** * Check if a table exists. * @@ -750,10 +750,10 @@ class DB $result = $this->_fetch($stmt); return $result ? true : false; } - + /** * Create a table. - * + * * @param string $filename * @param string $content * @return Helpers\DBResultHelper @@ -770,16 +770,16 @@ class DB { return new Helpers\DBResultHelper; } - + // Generate the CREATE TABLE query and execute it. $query_string = $table->getCreateQuery($this->_prefix, $this->_charset, $this->_engine); $result = $this->_handle->exec($query_string); return $result ? new Helpers\DBResultHelper : $this->getError(); } - + /** * Drop a table. - * + * * @param string $table_name * @return Helpers\DBResultHelper */ @@ -788,7 +788,7 @@ class DB $stmt = $this->_handle->exec(sprintf("DROP TABLE `%s`", $this->addQuotes($this->_prefix . $table_name))); return $stmt ? new Helpers\DBResultHelper : $this->getError(); } - + /** * Check if a column exists. * @@ -802,10 +802,10 @@ class DB $result = $this->_fetch($stmt); return $result ? true : false; } - + /** * Add a column. - * + * * @param string $table_name * @param string $column_name * @param string $type @@ -819,12 +819,12 @@ class DB { // Normalize the type and size. list($type, $xetype, $size) = Parsers\DBTableParser::getTypeAndSize($type, strval($size)); - + // Compose the ADD COLUMN query. $query = sprintf("ALTER TABLE `%s` ADD COLUMN `%s` ", $this->addQuotes($this->_prefix . $table_name), $this->addQuotes($column_name)); $query .= $size ? sprintf('%s(%s)', $type, $size) : $type; $query .= $notnull ? ' NOT NULL' : ''; - + // Add the default value according to the type. if (isset($default)) { @@ -837,7 +837,7 @@ class DB $query .= sprintf(" DEFAULT '%s'", $this->addQuotes($default)); } } - + // Add position information. if ($after_column === 'FIRST') { @@ -847,15 +847,15 @@ class DB { $query .= sprintf(' AFTER `%s`', $this->addQuotes($after_column)); } - + // Execute the query and return the result. $result = $this->_handle->exec($query); return $result ? new Helpers\DBResultHelper : $this->getError(); } - + /** * Modify a column. - * + * * @param string $table_name * @param string $column_name * @param string $type @@ -871,7 +871,7 @@ class DB { // Normalize the type and size. list($type, $xetype, $size) = Parsers\DBTableParser::getTypeAndSize($type, strval($size)); - + // Compose the MODIFY COLUMN query. if ($new_name && $new_name !== $column_name) { @@ -882,17 +882,17 @@ class DB $query = sprintf("ALTER TABLE `%s` MODIFY `%s` ", $this->addQuotes($this->_prefix . $table_name), $this->addQuotes($column_name)); } $query .= $size ? sprintf('%s(%s)', $type, $size) : $type; - + // Add the character set information. if (isset($new_charset)) { $new_collation = preg_match('/^utf8/i', $new_charset) ? ($new_charset . '_unicode_ci') : ($new_charset . '_general_ci'); $query .= ' CHARACTER SET ' . $new_charset . ' COLLATE ' . $new_collation; } - + // Add the NOT NULL constraint. $query .= $notnull ? ' NOT NULL' : ''; - + // Add the default value according to the type. if (isset($default)) { @@ -905,7 +905,7 @@ class DB $query .= sprintf(" DEFAULT '%s'", $this->addQuotes($default)); } } - + // Add position information. if ($after_column === 'FIRST') { @@ -915,15 +915,15 @@ class DB { $query .= sprintf(' AFTER `%s`', $this->addQuotes($after_column)); } - + // Execute the query and return the result. $result = $this->_handle->exec($query); return $result ? new Helpers\DBResultHelper : $this->getError(); } - + /** * Drop a column. - * + * * @param string $table_name * @param string $column_name * @return Helpers\DBResultHelper @@ -933,7 +933,7 @@ class DB $result = $this->_handle->exec(sprintf("ALTER TABLE `%s` DROP `%s`", $this->addQuotes($this->_prefix . $table_name), $this->addQuotes($column_name))); return $result ? new Helpers\DBResultHelper : $this->getError(); } - + /** * Get column information. * @@ -950,7 +950,7 @@ class DB { return false; } - + // Reorganize the type information. $dbtype = strtolower($column_info->{'Type'}); if (preg_match('/^([a-z0-9_]+)\(([0-9,\s]+)\)$/i', $dbtype, $matches)) @@ -963,7 +963,7 @@ class DB $size = ''; } $xetype = Parsers\DBTableParser::getXEType($dbtype, $size ?: ''); - + // Return the result as an object. return (object)array( 'name' => $column_name, @@ -974,10 +974,10 @@ class DB 'notnull' => strncmp($column_info->{'Null'}, 'NO', 2) == 0 ? true : false, ); } - + /** * Check if an index exists. - * + * * @param string $table_name * @param string $index_name * @return boolean @@ -988,10 +988,10 @@ class DB $result = $this->_fetch($stmt); return $result ? true : false; } - + /** * Add an index. - * + * * @param string $table_name * @param string $index_name * @param array $columns @@ -1005,12 +1005,12 @@ class DB { $columns = array($columns); } - + if ($type === true || $type === 1) { $type = 'UNIQUE'; } - + $query = vsprintf("ALTER TABLE `%s` ADD %s `%s` (%s) %s", array( $this->addQuotes($this->_prefix . $table_name), ltrim($type . ' INDEX'), @@ -1027,14 +1027,14 @@ class DB }, $columns)), $options, )); - + $result = $this->_handle->exec($query); return $result ? new Helpers\DBResultHelper : $this->getError(); } - + /** * Drop an index. - * + * * @param string $table_name * @param string $index_name * @return Helpers\DBResultHelper @@ -1044,10 +1044,10 @@ class DB $result = $this->_handle->exec(sprintf("ALTER TABLE `%s` DROP INDEX `%s`", $this->addQuotes($this->_prefix . $table_name), $this->addQuotes($index_name))); return $result ? new Helpers\DBResultHelper : $this->getError(); } - + /** * Add table prefixes to a query string. - * + * * @param string $query_string * @return string */ @@ -1077,10 +1077,10 @@ class DB }, $query_string); } } - + /** * Escape a string according to current DB settings. - * + * * @param string $str * @return string */ @@ -1095,10 +1095,10 @@ class DB return preg_replace("/^'(.*)'$/s", '$1', $this->_handle->quote($str)); } } - + /** * Find out the best supported character set. - * + * * @return string */ public function getBestSupportedCharset(): string @@ -1109,30 +1109,30 @@ class DB }))); return $utf8mb4_support ? 'utf8mb4' : 'utf8'; } - + /** * Check if the last statement produced an error. - * + * * @return bool */ public function isError(): bool { return $this->_errno !== 0 ? true : false; } - + /** * Get the last error information. - * + * * @return Helpers\DBResultHelper */ public function getError(): Helpers\DBResultHelper { return new Helpers\DBResultHelper($this->_errno, $this->_errstr); } - + /** * Set error information to instance properties. - * + * * @param int $errno * @param string $errstr * @return Helpers\DBResultHelper @@ -1144,10 +1144,10 @@ class DB $output = new Helpers\DBResultHelper($errno, $errstr); return $output; } - + /** * Clear error information. - * + * * @return void */ public function clearError() @@ -1155,10 +1155,10 @@ class DB $this->_errno = 0; $this->_errstr = 'success'; } - + /** * Generate a query log entry. - * + * * @param string $query * @param float $elapsed_time * @return array @@ -1179,7 +1179,7 @@ class DB 'called_method' => null, 'backtrace' => array(), ); - + // Add debug information if enabled. if ($this->_errno || $this->_debug_queries) { @@ -1205,13 +1205,13 @@ class DB } } } - + return $result; } - + /** * Send an entry to the query log for debugging. - * + * * @param array $log * @return void */ @@ -1219,10 +1219,10 @@ class DB { Debug::addQuery($log); } - + /** * Add elapsed time. - * + * * @param float $elapsed_time * @return void */ @@ -1230,45 +1230,45 @@ class DB { $this->_query_time += $elapsed_time; } - + /** * Get total time spent during queries. - * + * * @return float */ public function getQueryElapsedTime(): float { return $this->_query_time; } - + /** * Get total time spent in this class. - * + * * @return float */ public function getTotalElapsedTime(): float { return $this->_total_time; } - + /** * Enable or disable debug comments. - * + * * @param bool $enabled */ public function setDebugComment(bool $enabled) { $this->_debug_comment = $enabled; } - + /** * ========================== DEPRECATED METHODS ========================== * ==================== KEPT FOR COMPATIBILITY WITH XE ==================== */ - + /** * Old alias to getInstance(). - * + * * @deprecated * @return self */ @@ -1276,10 +1276,10 @@ class DB { return self::getInstance(); } - + /** * Old alias to $stmt->fetchObject(). - * + * * @deprecated * @param \PDOStatement $stmt * @return object|false @@ -1288,10 +1288,10 @@ class DB { return $stmt->fetchObject(); } - + /** * Old alias to $stmt->closeCursor(). - * + * * @deprecated * @param \PDOStatement $stmt * @return bool @@ -1300,10 +1300,10 @@ class DB { return $stmt->closeCursor(); } - + /** * Old alias to getInsertID(). - * + * * @deprecated * @return int */ @@ -1311,10 +1311,10 @@ class DB { return $this->getInsertID(); } - + /** * Get the list of supported database drivers. - * + * * @deprecated * @return array */ @@ -1327,10 +1327,10 @@ class DB ), ); } - + /** * Get the list of enabled database drivers. - * + * * @deprecated * @return array */ @@ -1340,10 +1340,10 @@ class DB return $item->enable; }); } - + /** * Get the list of disabled database drivers. - * + * * @deprecated * @return array */ @@ -1353,10 +1353,10 @@ class DB return !$item->enable; }); } - + /** * Check if the current instance is supported. - * + * * @deprecated * @return bool */ @@ -1364,10 +1364,10 @@ class DB { return true; } - + /** * Check if the current instance is connected. - * + * * @deprecated * @return bool */ @@ -1375,10 +1375,10 @@ class DB { return true; } - + /** * Close the DB connection. - * + * * @deprecated * @return bool */ @@ -1386,10 +1386,10 @@ class DB { return true; } - + /** * Methods related to table creation. - * + * * @deprecated * @return void */ @@ -1408,10 +1408,10 @@ class DB $output = $this->createTable('', $xml_doc); return $output->toBool(); } - + /** * Methods related to the click count cache feature. - * + * * @deprecated * @return bool */ @@ -1427,7 +1427,7 @@ class DB { return false; } - + /** * Other deprecated methods. */ diff --git a/common/framework/DateTime.php b/common/framework/DateTime.php index 5e5e08eb5..d96740f98 100644 --- a/common/framework/DateTime.php +++ b/common/framework/DateTime.php @@ -11,10 +11,10 @@ class DateTime * Time zone objects and settings are cached here. */ protected static $_timezones = array(); - + /** * Format a Unix timestamp using the internal timezone. - * + * * @param string $format Format used in PHP date() function * @param int $timestamp Unix timestamp (optional, default is now) * @return string @@ -25,14 +25,14 @@ class DateTime { return self::getRelativeTimestamp($timestamp ?: time()); } - + $offset = Config::get('locale.internal_timezone') ?: date('Z', $timestamp); return gmdate($format, ($timestamp ?: time()) + $offset); } - + /** * Format a Unix timestamp for the current user's timezone. - * + * * @param string $format Format used in PHP date() function * @param int $timestamp Unix timestamp (optional, default is now) * @return string @@ -43,7 +43,7 @@ class DateTime { return self::getRelativeTimestamp($timestamp ?: time()); } - + $timezone = self::getTimezoneForCurrentUser(); if (!isset(self::$_timezones[$timezone])) { @@ -54,10 +54,10 @@ class DateTime $datetime->setTimezone(self::$_timezones[$timezone]); return $datetime->format($format); } - + /** * Get the current user's timezone. - * + * * @return string */ public static function getTimezoneForCurrentUser() @@ -79,10 +79,10 @@ class DateTime return @date_default_timezone_get(); } } - + /** * Get the list of time zones supported on this server. - * + * * @return array */ public static function getTimezoneList() @@ -103,10 +103,10 @@ class DateTime $result['Etc/UTC'] = 'GMT/UTC (+00:00)'; return $result; } - + /** * Get the absolute (UTC) offset of a timezone. - * + * * @param string $timezone Timezone identifier, e.g. Asia/Seoul * @param int $timestamp Unix timestamp (optional, default is now) * @return int @@ -122,10 +122,10 @@ class DateTime $datetime->setTimezone(self::$_timezones[$timezone]); return $datetime->getOffset(); } - + /** * Get the relative offset between a timezone and Rhymix's internal timezone. - * + * * @param string $timezone Timezone identifier, e.g. Asia/Seoul * @param int $timestamp Unix timestamp (optional, default is now) * @return int @@ -134,10 +134,10 @@ class DateTime { return self::getTimezoneOffset($timezone, $timestamp) - Config::get('locale.internal_timezone'); } - + /** * Get the absolute (UTC) offset of a timezone written in XE legacy format ('+0900'). - * + * * @param string $timezone * @return int */ @@ -148,16 +148,16 @@ class DateTime list($hours, $minutes) = str_split($timezone, 2); return (((int)$hours * 60) + (int)$minutes) * $multiplier; } - + /** * Get a PHP time zone by UTC offset. - * + * * Time zones with both (a) fractional offsets and (b) daylight saving time * (such as Iran's +03:30/+04:30) cannot be converted in this way. * However, if Rhymix is installed for the first time in such a time zone, * the internal time zone will be automatically set to UTC, * so this should never be a problem in practice. - * + * * @param int $offset * @return bool */ @@ -178,10 +178,10 @@ class DateTime default: return 'Etc/GMT' . ($offset > 0 ? '-' : '+') . intval(abs($offset / 3600)); } } - + /** * Get a relative timestamp (3 hours ago, etc.) - * + * * @param int $timestamp * @return string */ @@ -189,7 +189,7 @@ class DateTime { $diff = \RX_TIME - $timestamp; $langs = lang('common.time_gap'); - + if ($diff < 3) { return $langs['now']; diff --git a/common/framework/Debug.php b/common/framework/Debug.php index 00dc235c3..e7bc81dc3 100644 --- a/common/framework/Debug.php +++ b/common/framework/Debug.php @@ -25,90 +25,90 @@ class Debug protected static $_slow_remote_requests = array(); protected static $_session_time = 0; protected static $_query_time = 0; - + /** * Enable log collection. - * + * * @return void */ public static function enable() { self::$_enabled = true; } - + /** * Disable log collection. - * + * * @return void */ public static function disable() { self::$_enabled = false; } - + /** * Get all entries. - * + * * @return array */ public static function getEntries() { return self::$_entries; } - + /** * Clear all entries. - * + * * @return void */ public static function clearEntries() { self::$_entries = array(); } - + /** * Get all errors. - * + * * @return array */ public static function getErrors() { return self::$_errors; } - + /** * Clear all errors. - * + * * @return void */ public static function clearErrors() { self::$_errors = array(); } - + /** * Get all queries. - * + * * @return array */ public static function getQueries() { return self::$_queries; } - + /** * Get all slow queries. - * + * * @return array */ public static function getSlowQueries() { return self::$_slow_queries; } - + /** * Clear all queries. - * + * * @return void */ public static function clearQueries() @@ -116,30 +116,30 @@ class Debug self::$_queries = array(); self::$_slow_queries = array(); } - + /** * Get all triggers. - * + * * @return array */ public static function getTriggers() { return self::$_triggers; } - + /** * Get all slow triggers. - * + * * @return array */ public static function getSlowTriggers() { return self::$_slow_triggers; } - + /** * Clear all triggers. - * + * * @return void */ public static function clearTriggers() @@ -147,30 +147,30 @@ class Debug self::$_triggers = array(); self::$_slow_triggers = array(); } - + /** * Get all widgets. - * + * * @return array */ public static function getWidgets() { return self::$_widgets; } - + /** * Get all slow widgets. - * + * * @return array */ public static function getSlowWidgets() { return self::$_slow_widgets; } - + /** * Clear all widgets. - * + * * @return void */ public static function clearWidgets() @@ -178,30 +178,30 @@ class Debug self::$_widgets = array(); self::$_slow_widgets = array(); } - + /** * Get all remote requests. - * + * * @return array */ public static function getRemoteRequests() { return self::$_remote_requests; } - + /** * Get all slow remote requests. - * + * * @return array */ public static function getSlowRemoteRequests() { return self::$_slow_remote_requests; } - + /** * Clear all remote requests. - * + * * @return void */ public static function clearRemoteRequests() @@ -209,10 +209,10 @@ class Debug self::$_remote_requests = array(); self::$_slow_remote_requests = array(); } - + /** * Clear all records. - * + * * @return void */ public static function clearAll() @@ -230,10 +230,10 @@ class Debug self::$_session_time = 0; self::$_query_time = 0; } - + /** * Add a filename alias. - * + * * @param string $display_filename * @param string $real_filename * @return void @@ -242,10 +242,10 @@ class Debug { self::$_aliases[$real_filename] = $display_filename; } - + /** * Add session start time. - * + * * @param float $session_start_time * @return void */ @@ -253,10 +253,10 @@ class Debug { self::$_session_time += $session_start_time; } - + /** * Add an arbitrary entry to the log. - * + * * @param string $message * @return void */ @@ -267,14 +267,14 @@ class Debug { return; } - + // Get the backtrace. $backtrace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS); if (count($backtrace) > 1 && $backtrace[1]['function'] === 'debugPrint' && empty($backtrace[1]['class'])) { array_shift($backtrace); } - + // Create a log entry. $entry = (object)array( 'message' => unserialize(serialize($message)), @@ -285,7 +285,7 @@ class Debug 'type' => 'Debug', ); self::$_entries[] = $entry; - + // Add the entry to the error log. if (isset(self::$_config['write_error_log']) && self::$_config['write_error_log'] === 'all') { @@ -294,10 +294,10 @@ class Debug error_log($log_entry); } } - + /** * Add a PHP error to the log. - * + * * @param int $errno * @param string $errstr * @param string $errfile @@ -312,13 +312,13 @@ class Debug { return; } - + // Do not handle error types that we were told to ignore. if (!($errno & error_reporting())) { return; } - + // Rewrite the error message with relative paths. $message = str_replace(array( ' called in ' . \RX_BASEDIR, @@ -327,10 +327,10 @@ class Debug ' called in ', ' defined in ', ), $errstr); - + // Get the backtrace. $backtrace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS); - + // Prepare the error entry. self::$_errors[] = $errinfo = (object)array( 'message' => $message, @@ -340,7 +340,7 @@ class Debug 'time' => microtime(true), 'type' => self::getErrorType($errno), ); - + // Add the entry to the error log. if (isset(self::$_config['write_error_log']) && self::$_config['write_error_log'] === 'all') { @@ -348,10 +348,10 @@ class Debug error_log($log_entry . \PHP_EOL . self::formatBacktrace($backtrace)); } } - + /** * Add a query to the log. - * + * * @return void */ public static function addQuery($query) @@ -361,7 +361,7 @@ class Debug { return; } - + // Prepare the log entry. $query_object = (object)array( 'query_id' => $query['query_id'], @@ -377,10 +377,10 @@ class Debug 'time' => microtime(true), 'type' => 'Query', ); - + self::$_queries[] = $query_object; self::$_query_time += $query_object->query_time; - + // Add the entry to the error log if the result wasn't successful. if ($query['result'] === 'error') { @@ -392,26 +392,26 @@ class Debug 'time' => $query_object->time, 'type' => 'Query Error', ); - + self::$_errors[] = $error_object; - + if (self::$_config['write_error_log'] === 'all') { $log_entry = strtr(sprintf('Query Error: %s in %s on line %d', $error_object->message, $error_object->file, intval($error_object->line)), "\0\r\n\t\v\e\f", ' '); error_log($log_entry . \PHP_EOL . self::formatBacktrace($error_object->backtrace)); } } - + // Add the entry to the slow query log. if ($query_object->query_time && $query_object->query_time >= (self::$_config['log_slow_queries'] ?? 1)) { self::$_slow_queries[] = $query_object; } } - + /** * Add a trigger to the log. - * + * * @return bool */ public static function addTrigger($trigger) @@ -421,7 +421,7 @@ class Debug { return; } - + // Prepare the log entry. $trigger_object = (object)array( 'trigger_name' => $trigger['name'], @@ -435,17 +435,17 @@ class Debug 'time' => microtime(true), 'type' => 'Trigger', ); - + self::$_triggers[] = $trigger_object; if ($trigger_object->trigger_time && $trigger_object->trigger_time >= (self::$_config['log_slow_triggers'] ?? 1)) { self::$_slow_triggers[] = $trigger_object; } } - + /** * Add a widget to the log. - * + * * @return bool */ public static function addWidget($widget) @@ -455,7 +455,7 @@ class Debug { return; } - + // Prepare the log entry. $widget_object = (object)array( 'widget_name' => $widget['name'], @@ -467,17 +467,17 @@ class Debug 'time' => microtime(true), 'type' => 'Widget', ); - + self::$_widgets[] = $widget_object; if ($widget_object->widget_time && $widget_object->widget_time >= (self::$_config['log_slow_widgets'] ?? 1)) { self::$_slow_widgets[] = $widget_object; } } - + /** * Add a remote request to the log. - * + * * @return bool */ public static function addRemoteRequest($request) @@ -487,7 +487,7 @@ class Debug { return; } - + // Prepare the log entry. $request_object = (object)array( 'url' => $request['url'], @@ -501,17 +501,17 @@ class Debug 'time' => microtime(true), 'type' => 'Remote Request', ); - + self::$_remote_requests[] = $request_object; if ($request_object->elapsed_time && $request_object->elapsed_time >= (self::$_config['log_slow_remote_requests'] ?? 1)) { self::$_slow_remote_requests[] = $request_object; } } - + /** * The default handler for catching exceptions. - * + * * @param Exception $e * @return void */ @@ -519,7 +519,7 @@ class Debug { // Find out the file where the error really occurred. $errfile = self::translateFilename($e->getFile()); - + // If the exception was thrown in a Rhymix Framework class, find out where that class was called. $backtrace = $e->getTrace(); $caller_errfile = $errfile; @@ -537,9 +537,9 @@ class Debug $caller_errline = $trace['line']; } } - + // Add the exception to the error log. - + if ($caller_errfile && $caller_errfile !== $errfile) { $log_entry = str_replace("\0", '', sprintf('%s #%d "%s" in %s on line %d (via %s on line %d)', @@ -554,15 +554,15 @@ class Debug { error_log('PHP Exception: ' . $log_entry . \PHP_EOL . self::formatBacktrace($e->getTrace())); } - + // Display the error screen. self::displayErrorScreen($log_entry); exit; } - + /** * The default handler for catching fatal errors. - * + * * @return void */ public static function shutdownHandler() @@ -573,10 +573,10 @@ class Debug { return; } - + // Find out the file where the error really occurred. $errinfo['file'] = self::translateFilename($errinfo['file']); - + // Add the entry to the error log. $message = sprintf('%s in %s on line %d', $errinfo['message'], $errinfo['file'], intval($errinfo['line'])); $log_entry = str_replace("\0", '', 'PHP ' . self::getErrorType($errinfo['type']) . ': ' . $message); @@ -584,11 +584,11 @@ class Debug { error_log($log_entry); } - + // Display the error screen. self::displayErrorScreen($log_entry); } - + /** * Format a backtrace for error logging. */ @@ -607,10 +607,10 @@ class Debug } return implode(\PHP_EOL, $result); } - + /** * Translate filenames. - * + * * @param string $filename * @return string */ @@ -626,10 +626,10 @@ class Debug } return $filename; } - + /** * Register all error handlers. - * + * * @return void */ public static function registerErrorHandlers($error_types) @@ -639,10 +639,10 @@ class Debug set_exception_handler('\\Rhymix\\Framework\\Debug::exceptionHandler'); register_shutdown_function('\\Rhymix\\Framework\\Debug::shutdownHandler'); } - + /** * Display a fatal error screen. - * + * * @param string $message * @return void */ @@ -653,20 +653,20 @@ class Debug { return; } - + // Disable output buffering. while (ob_get_level()) { ob_end_clean(); } - + // Localize the error title. $title = lang('msg_server_error'); if ($title === 'msg_server_error') { $message = 'Server Error'; } - + // Localize the error message. $display_error_message = ini_get('display_errors') || !\Context::isInstalled() || Session::isAdmin() || self::isEnabledForCurrentUser(); $message = $display_error_message ? $message : lang('msg_server_error_see_log'); @@ -674,7 +674,7 @@ class Debug { $message = 'Your server is configured to hide error messages. Please see your server\'s error log for details.'; } - + // Display a generic error page. try { @@ -685,10 +685,10 @@ class Debug self::displayError($message); } } - + /** * Display a default error. - * + * * @param string $message * @return void */ @@ -706,10 +706,10 @@ class Debug echo json_encode(array('error' => -1, 'message' => escape($message, false)), \JSON_UNESCAPED_UNICODE); } } - + /** * Check if debugging is enabled for the current user. - * + * * @return bool */ public static function isEnabledForCurrentUser() @@ -722,12 +722,12 @@ class Debug { return self::$_enabled = false; } - + switch (self::$_config['display_to']) { case 'everyone': return self::$_enabled = true; - + case 'ip': if (Filters\IpFilter::inRanges(\RX_CLIENT_IP, self::$_config['allow'])) { @@ -742,7 +742,7 @@ class Debug return self::$_enabled = true; } return self::$_enabled = false; - + case 'admin': default: $logged_info = \Context::get('logged_info'); @@ -760,10 +760,10 @@ class Debug } } } - + /** * Get all debug information as an object. - * + * * @return object */ public static function getDebugData() @@ -802,7 +802,7 @@ class Debug 'slow_widgets' => self::$_slow_widgets, 'slow_remote_requests' => self::$_slow_remote_requests, ); - + // Clean up the querystring. if (isset($data->queries)) { @@ -811,7 +811,7 @@ class Debug $query->query_string = trim(utf8_normalize_spaces($query->query_string, true)); } } - + // Clean up the backtrace. foreach (array('entries', 'errors', 'queries', 'slow_queries', 'remote_requests', 'slow_remote_requests') as $key) { @@ -838,13 +838,13 @@ class Debug } } } - + return $data; } - + /** * Convert a PHP error number to the corresponding error name. - * + * * @param int $errno * @return string */ diff --git a/common/framework/Exception.php b/common/framework/Exception.php index 7d61053a4..0ff93aa68 100644 --- a/common/framework/Exception.php +++ b/common/framework/Exception.php @@ -7,5 +7,5 @@ namespace Rhymix\Framework; */ class Exception extends \Exception { - + } diff --git a/common/framework/Formatter.php b/common/framework/Formatter.php index 8f17d59a2..005406ecd 100644 --- a/common/framework/Formatter.php +++ b/common/framework/Formatter.php @@ -12,16 +12,16 @@ class Formatter */ const TEXT_NEWLINE_AS_P = 1; const TEXT_DOUBLE_NEWLINE_AS_P = 2; - + /** * Options for Markdown to HTML conversion. */ const MD_NEWLINE_AS_BR = 16; const MD_ENABLE_EXTRA = 128; - + /** * Convert plain text to HTML. - * + * * @param string $text * @param int $options (optional) * @return string @@ -39,7 +39,7 @@ class Formatter } return $result; } - + // This option uses
to separate lines and

to separate paragraphs. if ($options & self::TEXT_DOUBLE_NEWLINE_AS_P) { @@ -52,14 +52,14 @@ class Formatter } return $result; } - + // The default is to use
always. return nl2br(escape(trim($text))) . "
\n"; } - + /** * Convert HTML to plain text. - * + * * @param string $html * @return string */ @@ -69,7 +69,7 @@ class Formatter $html = preg_replace('!]*>\s*!i', "\n", $html); $html = preg_replace('!]*>\s*!i', '', $html); $html = preg_replace('!]*>\s*!i', "\n\n", $html); - + // Encode links and images to preserve essential information. $html = preg_replace_callback('!]*href="([^>"]+)"[^>]*>([^<]*)!i', function($matches) { return trim($matches[2] . ' <' . $matches[1] . '>'); @@ -79,20 +79,20 @@ class Formatter $title = $title ?: (preg_match('!alt="([^>"]+)"!i', $matches[0], $m) ? $m[1] : 'IMAGE'); return trim('[' . $title . '] <' . $matches[1] . '>'); }, $html); - + // Strip all other HTML. $text = html_entity_decode(strip_tags($html)); unset($html); - + // Normalize whitespace and return. $text = str_replace("\r\n", "\n", $text); $text = preg_replace('/\n(?:\s*\n)+/', "\n\n", $text); return trim($text) . "\n"; } - + /** * Convert Markdown to HTML. - * + * * @param string $markdown * @param int $options (optional) * @return string @@ -110,19 +110,19 @@ class Formatter $classes = false; $parser = new \Michelf\Markdown; } - + if ($options & self::MD_NEWLINE_AS_BR) { $parser->hard_wrap = true; } - + $html = $parser->transform($markdown); return Filters\HTMLFilter::clean($html, $classes); } - + /** * Convert HTML to Markdown. - * + * * @param string $html * @return string */ @@ -133,10 +133,10 @@ class Formatter $converter->getConfig()->setOption('strip_tags', true); return trim($converter->convert($html)) . "\n"; } - + /** * Convert BBCode to HTML. - * + * * @param string $bbcode * @return string */ @@ -144,21 +144,21 @@ class Formatter { $parser = new \JBBCode\Parser; $parser->addCodeDefinitionSet(new \JBBCode\DefaultCodeDefinitionSet()); - + $builder = new \JBBCode\CodeDefinitionBuilder('quote', '

{param}
'); $parser->addCodeDefinition($builder->build()); $builder = new \JBBCode\CodeDefinitionBuilder('code', '
{param}
'); $builder->setParseContent(false); $parser->addCodeDefinition($builder->build()); - + $parser->parse($bbcode); $html = $parser->getAsHtml(); return Filters\HTMLFilter::clean($html); } - + /** * Apply smart quotes and other stylistic enhancements to HTML. - * + * * @param string $html * @return string */ @@ -166,10 +166,10 @@ class Formatter { return \Michelf\SmartyPants::defaultTransform($html, 'qbBdDiew'); } - + /** * Compile LESS into CSS. - * + * * @param string|array $source_filename * @param string $target_filename * @param array $variables (optional) @@ -181,7 +181,7 @@ class Formatter // Get the cleaned and concatenated content. $imported_list = []; $content = self::concatCSS($source_filename, $target_filename, true, $imported_list); - + // Compile! try { @@ -192,7 +192,7 @@ class Formatter { $less_compiler->setVariables($variables); } - + $content = $less_compiler->compile($content) . "\n"; $content = strpos($content, '@charset') === false ? ('@charset "UTF-8";' . "\n" . $content) : $content; $result = true; @@ -204,20 +204,20 @@ class Formatter $content = sprintf("/*\n Error while compiling %s\n\n %s\n*/\n", $filename, $message); $result = false; } - + // Save the result to the target file. Storage::write($target_filename, $content); - + // Save the list of imported files. Storage::writePHPData(preg_replace('/\.css$/', '.imports.php', $target_filename), $imported_list, null, false); - + // Also return the compiled CSS content. return $result; } - + /** * Compile SCSS into CSS. - * + * * @param string|array $source_filename * @param string $target_filename * @param array $variables (optional) @@ -229,7 +229,7 @@ class Formatter // Get the cleaned and concatenated content. $imported_list = []; $content = self::concatCSS($source_filename, $target_filename, true, $imported_list); - + // Compile! try { @@ -240,7 +240,7 @@ class Formatter { $scss_compiler->addVariables(array_map('\ScssPhp\ScssPhp\ValueConverter::parseValue', $variables)); } - + $content = $scss_compiler->compileString($content)->getCss() . "\n"; $content = strpos($content, '@charset') === false ? ('@charset "UTF-8";' . "\n" . $content) : $content; $result = true; @@ -252,20 +252,20 @@ class Formatter $content = sprintf("/*\n Error while compiling %s\n\n %s\n*/\n", $filename, $message); $result = false; } - + // Save the result to the target file. Storage::write($target_filename, $content); - + // Save the list of imported files. Storage::writePHPData(preg_replace('/\.css$/', '.imports.php', $target_filename), $imported_list, null, false); - + // Also return the compiled CSS content. return $result; } - + /** * Minify CSS. - * + * * @param string|array $source_filename * @param string $target_filename * @return bool @@ -290,10 +290,10 @@ class Formatter Storage::write($target_filename, $content); return strlen($content) ? true : false; } - + /** * Minify JS. - * + * * @param string|array $source_filename * @param string $target_filename * @return bool @@ -316,10 +316,10 @@ class Formatter Storage::write($target_filename, $content); return strlen($content) ? true : false; } - + /** * CSS concatenation subroutine for compileLESS() and compileSCSS(). - * + * * @param string|array $source_filename * @param string $target_filename * @param bool $add_comment @@ -331,12 +331,12 @@ class Formatter $charsets = []; $imported_urls = []; $result = ''; - + if (!is_array($source_filename)) { $source_filename = array($source_filename); } - + foreach ($source_filename as $filename) { // Get the media query. @@ -348,10 +348,10 @@ class Formatter { $media = null; } - + // Clean the content. $content = utf8_clean(file_get_contents($filename)); - + // Convert all paths in LESS and SCSS imports, too. $dirname = dirname($filename); $import_type = ends_with('.scss', $filename) ? 'scss' : 'normal'; @@ -421,7 +421,7 @@ class Formatter } return trim($import_content); }, $content); - + // Convert all paths to be relative to the new filename. $path_converter = new \MatthiasMullie\PathConverter\Converter($filename, $target_filename); $content = preg_replace_callback('/\burl\\(([^)]+)\\)/iU', function($matches) use ($path_converter) { @@ -436,19 +436,19 @@ class Formatter } }, $content); unset($path_converter); - + // Extract all @charset declarations. $content = preg_replace_callback('/@charset\s+(["\'a-z0-9_-]+);[\r\n]*/i', function($matches) use (&$charsets) { $charsets[] = trim($matches[1], '"\''); return ''; }, $content); - + // Wrap the content in a media query if there is one. if ($media !== null) { $content = "@media $media {\n\n" . trim($content) . "\n\n}"; } - + // Append to the result string. $original_filename = starts_with(\RX_BASEDIR, $filename) ? substr($filename, strlen(\RX_BASEDIR)) : $filename; if ($add_comment) @@ -460,7 +460,7 @@ class Formatter $result .= trim($content) . "\n\n"; } } - + // Place all @charset and @import statements at the beginning. if (count($imported_urls)) { @@ -474,13 +474,13 @@ class Formatter $charset = '@charset "' . escape_dqstr(array_first($charsets)) . '";'; $result = $charset . "\n" . $result; } - + return $result; } - + /** * JS concatenation subroutine. - * + * * @param string|array $source_filename * @param string $target_filename * @return string @@ -488,12 +488,12 @@ class Formatter public static function concatJS($source_filename, $target_filename) { $result = ''; - + if (!is_array($source_filename)) { $source_filename = array($source_filename); } - + foreach ($source_filename as $filename) { // Handle the array format, previously used for the targetIE attribute. @@ -501,21 +501,21 @@ class Formatter { $filename = reset($filename); } - + // Clean the content. $content = utf8_clean(file_get_contents($filename)); - + // Append to the result string. $original_filename = starts_with(\RX_BASEDIR, $filename) ? substr($filename, strlen(\RX_BASEDIR)) : $filename; $result .= '/* Original file: ' . $original_filename . ' */' . "\n\n" . trim($content) . ";\n\n"; } - + return $result; } - + /** * Convert IE conditional comments to JS conditions. - * + * * @deprecated * @param string $condition * @return string diff --git a/common/framework/Image.php b/common/framework/Image.php index ff638f3a9..2fa9cbebb 100644 --- a/common/framework/Image.php +++ b/common/framework/Image.php @@ -9,7 +9,7 @@ class Image { /** * Check if a file is an image - * + * * @param string $filename * @return bool */ @@ -17,10 +17,10 @@ class Image { return array_shift(explode('/', MIME::getContentType($filename))) === 'image'; } - + /** * Check if a file is an animated GIF. - * + * * @param string $filename * @return bool */ @@ -46,10 +46,10 @@ class Image fclose($fp); return $frames > 1; } - + /** * Get image information - * + * * @param string $filename * @return array|false */ diff --git a/common/framework/Korea.php b/common/framework/Korea.php index a7413af64..fa6e1c9c2 100644 --- a/common/framework/Korea.php +++ b/common/framework/Korea.php @@ -9,7 +9,7 @@ class Korea { /** * Format a phone number. - * + * * @param string $num * @return string */ @@ -17,7 +17,7 @@ class Korea { // Remove all non-numbers. $num = preg_replace('/[^0-9]/', '', $num); - + // Remove the country code. if (strncmp($num, '82', 2) === 0) { @@ -27,7 +27,7 @@ class Korea $num = '0' . $num; } } - + // Apply different format based on the number of digits. switch (strlen($num)) { @@ -62,10 +62,10 @@ class Korea } } } - + /** * Check if a Korean phone number contains a valid area code and the correct number of digits. - * + * * @param string $num * @return bool */ @@ -90,10 +90,10 @@ class Korea } return false; } - + /** * Check if a Korean phone number is a mobile phone number. - * + * * @param string $num * @return bool */ @@ -103,14 +103,14 @@ class Korea $len = strlen($num); return preg_match('/^01[016789][2-9][0-9]{6,7}$/', $num) ? true : false; } - + /** * Check if the given string is a valid resident registration number (주민등록번호) * or foreigner registration number (외국인등록번호). - * + * * This method only checks the format. * It does not check that the number is actually in use. - * + * * @param string $code * @return bool */ @@ -121,16 +121,16 @@ class Korea { return false; } - + // Remove hyphen. $code = str_replace('-', '', $code); - + // Return false if the date of birth is in the future. if (in_array((int)($code[6]), array(3, 4, 7, 8)) && intval(substr($code, 0, 6), 10) > date('ymd')) { return false; } - + // Calculate the checksum. $sum = 0; for ($i = 0; $i < 12; $i++) @@ -154,13 +154,13 @@ class Korea } } } - + /** * Check if the given string is a valid corporation registration number (법인등록번호). - * + * * This method only checks the format. * It does not check that the number is actually in use. - * + * * @param string $code * @return bool */ @@ -171,10 +171,10 @@ class Korea { return false; } - + // Remove hyphen. $code = str_replace('-', '', $code); - + // Calculate the checksum. $sum = 0; for ($i = 0; $i < 12; $i++) @@ -182,7 +182,7 @@ class Korea $sum += $code[$i] * (($i % 2) + 1); } $checksum = (10 - ($sum % 10)) % 10; - + // Check the 7th and 13th digits. if ($code[6] !== '0') { @@ -190,13 +190,13 @@ class Korea } return $checksum === (int)($code[12]); } - + /** * Check if the given string is a valid business registration number (사업자등록번호). - * + * * This method only checks the format. * It does not check that the number is actually in use. - * + * * @param string $code * @return bool */ @@ -207,10 +207,10 @@ class Korea { return false; } - + // Remove hyphen. $code = str_replace('-', '', $code); - + // Calculate the checksum. $sum = 0; $sum += $code[0] + ($code[1] * 3) + ($code[2] * 7); @@ -218,17 +218,17 @@ class Korea $sum += $code[6] + ($code[7] * 3) + ($code[8] * 5); $sum += floor(($code[8] * 5) / 10); $checksum = (10 - ($sum % 10)) % 10; - + // Check the last digit. return $checksum === (int)($code[9]); } - + /** * Check if the given IP address is Korean. * * This method may return incorrect results if the IP allocation databases * (korea.ipv4.php, korea.ipv6.php) are out of date. - * + * * @param string $ip * @return bool */ @@ -236,22 +236,22 @@ class Korea { // Extract the IPv4 address from an "IPv4-mapped IPv6" address. if (preg_match('/::ffff:(?:0+:)?([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/', $ip, $matches)) $ip = $matches[1]; - + // Return false if the IP address is not in the right format. if (!filter_var($ip, \FILTER_VALIDATE_IP)) return false; - + // Check IPv4. if (filter_var($ip, \FILTER_VALIDATE_IP, array('flags' => \FILTER_FLAG_IPV4))) { // Convert to integer. $ipnum = sprintf('%u', ip2long($ip)); - + // Treat local addresses as Korean. if ($ipnum >= 167772160 && $ipnum <= 184549375) return true; // 10.0.0.0/8 if ($ipnum >= 2130706432 && $ipnum <= 2147483647) return true; // 127.0.0.0/8 if ($ipnum >= 3232235520 && $ipnum <= 3232301055) return true; // 192.168.0.0/16 if ($ipnum >= 2886729728 && $ipnum <= 2887778303) return true; // 172.16.0.0/20 - + // Check the IPv4 allocation database. $ranges = (include \RX_BASEDIR . 'common/defaults/korea.ipv4.php'); foreach ($ranges as $range) @@ -260,17 +260,17 @@ class Korea } return false; } - + // Check IPv6. elseif (function_exists('inet_pton')) { // Convert to hexadecimal format. $ipbin = strtolower(bin2hex(inet_pton($ip))); - + // Treat local addresses as Korean. if ($ipbin == '00000000000000000000000000000001') return true; // ::1 if (preg_match('/^f(?:[cd]|e80{13})/', $ipbin)) return true; // fc00::/8, fd00::/8, fe80::/64 - + // Check the IPv6 allocation database. $ranges = (include \RX_BASEDIR . 'common/defaults/korea.ipv6.php'); foreach ($ranges as $range) @@ -279,16 +279,16 @@ class Korea } return false; } - + return false; } - + /** * Check if the given email address is hosted by a Korean portal site. - * + * * This can be used to tell which recipients may subscribe to the KISA RBL (kisarbl.or.kr). * If the domain is not found, this method returns false. - * + * * @param string $domain * @param bool $clear_cache (optional) * @return bool @@ -300,7 +300,7 @@ class Korea { self::$_domain_cache = array(); } - + // Get the domain from the email address. if ($pos = strpos($email_address, '@')) { @@ -311,13 +311,13 @@ class Korea $domain = $email_address; } $domain = rtrim(strtolower($domain), '.'); - + // Return cached result if available. if (array_key_exists($domain, self::$_domain_cache)) { return self::$_domain_cache[$domain]; } - + // Shortcut for known domains. if (in_array($domain, self::$known_korean)) { @@ -327,10 +327,10 @@ class Korea { return self::$_domain_cache[$domain] = false; } - + // For unknown domains, check the MX record. $mx = self::_getDNSRecords($domain, \DNS_MX); - + $i = 0; foreach ($mx as $mx) { @@ -358,13 +358,13 @@ class Korea break; } } - + return self::$_domain_cache[$domain] = false; } - + /** * Get the DNS records of a domain. - * + * * @param string $domain * @param int $type * @return array @@ -376,7 +376,7 @@ class Korea { return array(); } - + $result = array(); foreach ($records as $record) { @@ -397,16 +397,16 @@ class Korea $result[] = $record['txt']; } } - + ksort($result); return $result; } - + /** * Prevent multiple lookups for the same domain. */ protected static $_domain_cache = array(); - + /** * Domains known to be Korean and subscribed to the KISA RBL. */ @@ -432,7 +432,7 @@ class Korea 'empal.com', 'hanafos.com', ); - + /** * Domains known to be foreign. */ diff --git a/common/framework/Lang.php b/common/framework/Lang.php index aebc123da..5417e6e77 100644 --- a/common/framework/Lang.php +++ b/common/framework/Lang.php @@ -11,7 +11,7 @@ class Lang * Instances are stored here. */ protected static $_instances = array(); - + /** * Configuration. */ @@ -19,10 +19,10 @@ class Lang protected $_loaded_directories = array(); protected $_loaded_plugins = array(); protected $_search_priority = array(); - + /** * This method returns the cached instance of a language. - * + * * @param string $language * @return object */ @@ -38,10 +38,10 @@ class Lang } return self::$_instances[$language]; } - + /** * The constructor should not be called from outside. - * + * * @param string $language */ protected function __construct($language) @@ -49,20 +49,20 @@ class Lang $this->_language = preg_replace('/[^a-z0-9_-]/i', '', $language); $this->_loaded_plugins['_custom_'] = new \stdClass(); } - + /** * Return language type. - * + * * @return string */ public function langType() { return $this->_language; } - + /** * Load translations from a plugin (module, addon). - * + * * @param string $name * @return bool */ @@ -72,7 +72,7 @@ class Lang { return true; } - + if ($name === 'common') { $this->loadDirectory(\RX_BASEDIR . 'common/lang', 'common'); @@ -90,10 +90,10 @@ class Lang $this->loadDirectory(\RX_BASEDIR . "addons/$name/lang", $name); } } - + /** * Load translations from a directory. - * + * * @param string $dir * @param string $plugin_name * @return bool @@ -107,12 +107,12 @@ class Lang { return true; } - + // Initialize variables. $filename = null; $lang = new \stdClass; $result = true; - + // Find a suitable language file in the given directory. if (file_exists($dir . '/' . $this->_language . '.php')) { @@ -130,7 +130,7 @@ class Lang { $filename = $dir . '/' . ($this->_language === 'ja' ? 'jp' : $this->_language) . '.lang.php'; } - + // Load the language file. if ($filename) { @@ -142,23 +142,23 @@ class Lang { $result = false; } - + // Mark this directory and plugin as loaded. $this->_loaded_directories[$dir] = true; $this->_loaded_plugins[$plugin_name] = $lang; - + // Load the same directory in the default language, too. if ($this->_language !== 'en') { self::getInstance('en')->loadDirectory($dir, $plugin_name); } - + return $result; } - + /** * Get the list of supported languages. - * + * * @return array */ public static function getSupportedList() @@ -170,10 +170,10 @@ class Lang } return $list; } - + /** * Generic getter. - * + * * @param string $key * @return string */ @@ -185,20 +185,20 @@ class Lang { $args = $args[0]; } - + // Get the translation. $translation = $this->__get($key); - + // If there are no arguments, return the translation. if (!count($args)) return $translation; - + // If there are arguments, interpolate them into the translation and return the result. return vsprintf($translation, $args); } - + /** * Generic setter. - * + * * @param string $key * @param string $value * @return void @@ -207,10 +207,10 @@ class Lang { $this->__set($key, $value); } - + /** * Fallback method for getting the default translation. - * + * * @param string $key * @return string */ @@ -225,10 +225,10 @@ class Lang return self::getInstance('en')->__get($key); } } - + /** * Magic method for translations without arguments. - * + * * @param string $key * @return string */ @@ -247,7 +247,7 @@ class Lang { return $this->getFromDefaultLang($key); } - + // Find the given key. $lang = $this->_loaded_plugins[$plugin_name]; foreach ($keys as $subkey) @@ -267,14 +267,14 @@ class Lang } return is_array($lang) ? new \ArrayObject($lang, 3) : $lang; } - + // Search custom translations first. if (isset($this->_loaded_plugins['_custom_']->{$key})) { $lang = $this->_loaded_plugins['_custom_']->{$key}; return is_array($lang) ? new \ArrayObject($lang, 3) : $lang; } - + // Search other plugins. foreach ($this->_search_priority as $plugin_name) { @@ -284,14 +284,14 @@ class Lang return is_array($lang) ? new \ArrayObject($lang, 3) : $lang; } } - + // If no translation is found, return the default language. return $this->getFromDefaultLang($key); } - + /** * Magic method for setting a new custom translation. - * + * * @param string $key * @param string $value * @return void @@ -311,7 +311,7 @@ class Lang { return false; } - + // Set the given key. $count = count($keys); $lang = $this->_loaded_plugins[$plugin_name]; @@ -363,14 +363,14 @@ class Lang } } } - + // Set a regular key. $this->_loaded_plugins['_custom_']->{$key} = $value; } - + /** * Magic method for checking whether a translation exists. - * + * * @param string $key * @return bool */ @@ -385,10 +385,10 @@ class Lang } return false; } - + /** * Magic method for unsetting a translation. - * + * * @param string $key * @return void */ @@ -396,10 +396,10 @@ class Lang { $this->set($key, null); } - + /** * Magic method for translations with arguments. - * + * * @param string $key * @param mixed $args * @return string|null diff --git a/common/framework/MIME.php b/common/framework/MIME.php index 2a0eec848..e29311705 100644 --- a/common/framework/MIME.php +++ b/common/framework/MIME.php @@ -9,9 +9,9 @@ class MIME { /** * Get the MIME type of a file, detected by its content. - * + * * This method returns the MIME type of a file, or false on error. - * + * * @param string $filename * @return array|false */ @@ -38,10 +38,10 @@ class MIME return false; } } - + /** * Get the MIME type for the given extension. - * + * * @param string $extension * @return string */ @@ -50,10 +50,10 @@ class MIME $extension = strtolower($extension); return array_key_exists($extension, self::$_types) ? self::$_types[$extension][0] : self::$_default; } - + /** * Get the MIME type for the given filename. - * + * * @param string $filename * @return string */ @@ -64,10 +64,10 @@ class MIME $extension = strtolower(substr($extension, 1)); return array_key_exists($extension, self::$_types) ? self::$_types[$extension][0] : self::$_default; } - + /** * Get the most common extension for the given MIME type. - * + * * @param string $type * @return string|false */ @@ -82,17 +82,17 @@ class MIME } return false; } - + /** * The default MIME type for unknown extensions. */ protected static $_default = 'application/octet-stream'; - + /** * The list of known MIME types. */ protected static $_types = array( - + // Text-based document formats. 'html' => ['text/html'], 'htm' => ['text/html'], @@ -107,7 +107,7 @@ class MIME 'xsl' => ['text/xml'], 'css' => ['text/css'], 'csv' => ['text/csv'], - + // Binary document formats. 'doc' => ['application/msword'], 'dot' => ['application/msword'], @@ -124,7 +124,7 @@ class MIME 'odb' => ['application/vnd.oasis.opendocument.database'], 'pdf' => ['application/pdf'], 'dvi' => ['application/x-dvi'], - + // Images. 'bmp' => ['image/bmp'], 'gif' => ['image/gif'], @@ -138,7 +138,7 @@ class MIME 'tiff' => ['image/tiff'], 'tif' => ['image/tiff'], 'ico' => ['image/x-icon'], - + // Audio. 'mid' => ['audio/midi'], 'midi' => ['audio/midi'], @@ -153,7 +153,7 @@ class MIME 'aiff' => ['audio/x-aiff'], 'ra' => ['audio/x-realaudio'], 'm4a' => ['audio/x-m4a'], - + // Video. 'avi' => ['video/x-msvideo'], 'flv' => ['video/x-flv'], @@ -173,7 +173,7 @@ class MIME 'wma' => ['video/x-ms-asf'], 'asf' => ['video/x-ms-asf'], 'm4v' => ['video/x-m4v'], - + // Other multimedia file formats. 'psd' => ['application/x-photoshop'], 'swf' => ['application/x-shockwave-flash'], @@ -182,11 +182,11 @@ class MIME 'ps' => ['application/postscript'], 'mif' => ['application/vnd.mif'], 'xul' => ['application/vnd.mozilla.xul+xml'], - + // Source code formats. 'phps' => ['application/x-httpd-php-source'], 'js' => ['application/x-javascript'], - + // Archives. 'bz2' => ['application/x-bzip'], 'gz' => ['application/x-gzip'], @@ -195,13 +195,13 @@ class MIME 'gtar' => ['application/x-gtar'], 'rar' => ['application/x-rar-compressed'], 'zip' => ['application/x-zip'], - + // Executables and packages. 'apk' => ['application/vnd.android.package-archive'], 'pkg' => ['application/x-newton-compatible-pkg'], 'exe' => ['application/vnd.microsoft.portable-executable'], 'msi' => ['application/x-msdownload'], - + // RFC822 email message. 'eml' => ['message/rfc822'], ); diff --git a/common/framework/Mail.php b/common/framework/Mail.php index b49f24db3..911e5bdfc 100644 --- a/common/framework/Mail.php +++ b/common/framework/Mail.php @@ -17,16 +17,16 @@ class Mail protected $attachments = array(); public $errors = array(); protected $sent = false; - + /** * Static properties. */ public static $default_driver = null; public static $custom_drivers = array(); - + /** * Set the default driver. - * + * * @param object $driver * @return void */ @@ -34,10 +34,10 @@ class Mail { self::$default_driver = $driver; } - + /** * Get the default driver. - * + * * @return object */ public static function getDefaultDriver() @@ -58,7 +58,7 @@ class Mail } return self::$default_driver; } - + /** * Add a custom mail driver. */ @@ -66,10 +66,10 @@ class Mail { self::$custom_drivers[] = $driver; } - + /** * Get the list of supported mail drivers. - * + * * @return array */ public static function getSupportedDrivers() @@ -106,7 +106,7 @@ class Mail ksort($result); return $result; } - + /** * The constructor. */ @@ -115,7 +115,7 @@ class Mail $this->message = new \Swift_Message; $this->driver = self::getDefaultDriver(); } - + /** * Set the sender (From:). * @@ -136,7 +136,7 @@ class Mail return false; } } - + /** * Get the sender (From:). * @@ -147,7 +147,7 @@ class Mail $list = $this->message->getFrom(); return $list ? array_first($this->formatAddresses($list)) : null; } - + /** * Add a recipient (To:). * @@ -168,7 +168,7 @@ class Mail return false; } } - + /** * Add a recipient (CC:). * @@ -189,7 +189,7 @@ class Mail return false; } } - + /** * Add a recipient (BCC:). * @@ -210,7 +210,7 @@ class Mail return false; } } - + /** * Get the list of recipients. * @@ -219,7 +219,7 @@ class Mail public function getRecipients() { $result = array(); - + foreach ($this->formatAddresses($this->message->getTo()) as $address) { $result[] = $address; @@ -232,10 +232,10 @@ class Mail { $result[] = $address; } - + return array_unique($result); } - + /** * Set the Reply-To: address. * @@ -255,7 +255,7 @@ class Mail return false; } } - + /** * Set the Return-Path: address. * @@ -275,7 +275,7 @@ class Mail return false; } } - + /** * Set the Message ID. * @@ -296,7 +296,7 @@ class Mail return false; } } - + /** * Set the In-Reply-To: header. * @@ -317,7 +317,7 @@ class Mail return false; } } - + /** * Set the References: header. * @@ -338,7 +338,7 @@ class Mail return false; } } - + /** * Set the subject. * @@ -358,7 +358,7 @@ class Mail return false; } } - + /** * Get the subject. * @@ -368,7 +368,7 @@ class Mail { return $this->message->getSubject(); } - + /** * Set the subject (alias to setSubject). * @@ -379,7 +379,7 @@ class Mail { return $this->setSubject($subject); } - + /** * Get the subject (alias to getSubject). * @@ -389,7 +389,7 @@ class Mail { return $this->getSubject(); } - + /** * Set the body content. * @@ -403,25 +403,25 @@ class Mail { $this->setContentType($content_type); } - + if (strpos($this->content_type, 'html') !== false) { $content = Filters\HTMLFilter::fixRelativeUrls($content); } - + $this->message->setBody($content, $this->content_type); } - + /** * Get the body content. - * + * * @return string */ public function getBody() { return $this->message->getBody(); } - + /** * Set the body content (alias to setBody). * @@ -433,20 +433,20 @@ class Mail { return $this->setBody($content, $content_type); } - + /** * Get the body content (alias to getBody). - * + * * @return string */ public function getContent() { return $this->getBody(); } - + /** * Set the content type. - * + * * @param string $mode The type * @return void */ @@ -454,17 +454,17 @@ class Mail { $this->content_type = (strpos($type, 'html') !== false) ? 'text/html' : ((strpos($type, '/') !== false) ? $type : 'text/plain'); } - + /** * Get the content type. - * + * * @return string */ public function getContentType() { return $this->content_type; } - + /** * Attach a file. * @@ -482,11 +482,11 @@ class Mail { return false; } - + $attachment = \Swift_Attachment::fromPath($local_filename); $attachment->setFilename($display_filename); $result = $this->message->attach($attachment); - + if ($result) { $this->attachments[] = (object)array( @@ -502,7 +502,7 @@ class Mail return false; } } - + /** * Embed a file. * @@ -516,14 +516,14 @@ class Mail { return false; } - + $embedded = \Swift_EmbeddedFile::fromPath($local_filename); if ($cid !== null) { $embedded->setId(preg_replace('/^cid:/i', '', $cid)); } $result = $this->message->embed($embedded); - + if ($result) { $this->attachments[] = (object)array( @@ -539,20 +539,20 @@ class Mail return false; } } - + /** * Get the list of attachments to this message. - * + * * @return array */ public function getAttachments() { return $this->attachments; } - + /** * Send the email. - * + * * @return bool */ public function send() @@ -563,20 +563,20 @@ class Mail { $this->caller = $backtrace[0]['file'] . ($backtrace[0]['line'] ? (' line ' . $backtrace[0]['line']) : ''); } - + // Reset Message-ID in case send() is called multiple times. $random = substr(hash('sha256', mt_rand() . microtime() . getmypid()), 0, 32); $sender = $this->message->getFrom(); reset($sender); $id = $random . '@' . (preg_match('/^(.+)@([^@]+)$/', key($sender), $matches) ? $matches[2] : 'swift.generated'); $this->message->getHeaders()->get('Message-ID')->setId($id); - + $output = \ModuleHandler::triggerCall('mail.send', 'before', $this); if(!$output->toBool()) { $this->errors[] = $output->getMessage(); return false; } - + try { $this->sent = $this->driver->send($this) ? true : false; @@ -586,46 +586,46 @@ class Mail $this->errors[] = $e->getMessage(); $this->sent = false; } - + $output = \ModuleHandler::triggerCall('mail.send', 'after', $this); if(!$output->toBool()) { $this->errors[] = $output->getMessage(); } - + return $this->sent; } - + /** * Check if the message was sent. - * + * * @return bool */ public function isSent() { return $this->sent; } - + /** * Get caller information. - * + * * @return string */ public function getCaller() { return $this->caller; } - + /** * Get errors. - * + * * @return array */ public function getErrors() { return $this->errors; } - + /** * Convert image paths to absolute URLs. * @@ -637,22 +637,22 @@ class Mail { return Filters\HTMLFilter::fixRelativeUrls($matches[0]); } - + /** * Format an array of addresses for display. - * + * * @param array $addresses * @return array */ protected function formatAddresses($addresses) { $result = array(); - + if (!$addresses) { return array(); } - + foreach($addresses as $email => $name) { if(strval($name) === '') @@ -664,7 +664,7 @@ class Mail $result[] = $name . ' <' . $email . '>'; } } - + return $result; } } diff --git a/common/framework/Pagination.php b/common/framework/Pagination.php index cc26906e4..5b602b0ee 100644 --- a/common/framework/Pagination.php +++ b/common/framework/Pagination.php @@ -12,10 +12,10 @@ class Pagination */ const COUNT_STYLE_NORMAL = 1; const COUNT_STYLE_CONTINUOUS = 2; - + /** * Calculate the number of pages. - * + * * @param int $total_items * @param int $items_per_page * @param int $minimum (optional) @@ -32,10 +32,10 @@ class Pagination return (int)max($minimum, ceil($total_items / $items_per_page)); } } - + /** * Create HTML for pagination. - * + * * @param string $base_url ($PAGE will be replaced with the page number) * @param int $current_page * @param int $total_pages @@ -47,7 +47,7 @@ class Pagination $current_page = (int)$current_page; $total_pages = (int)$total_pages; $count = (int)$count; - + // Determine the range of pages to show. if ($count_style === self::COUNT_STYLE_NORMAL) { @@ -72,10 +72,10 @@ class Pagination $first_shown = max(1, $last_shown - $count + 1); } } - + // Open the
tag. $return = array('