diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/Logger.class.php | 489 | ||||
-rw-r--r-- | include/common.inc.php | 14 | ||||
-rw-r--r-- | include/config_default.inc.php | 35 | ||||
-rw-r--r-- | include/constants.php | 2 | ||||
-rw-r--r-- | include/derivative_std_params.inc.php | 2 | ||||
-rw-r--r-- | include/functions.inc.php | 2 | ||||
-rw-r--r-- | include/functions_category.inc.php | 4 | ||||
-rw-r--r-- | include/functions_search.inc.php | 9 | ||||
-rw-r--r-- | include/functions_user.inc.php | 18 | ||||
-rw-r--r-- | include/user.inc.php | 4 | ||||
-rw-r--r-- | include/ws_functions.inc.php | 19 | ||||
-rw-r--r-- | include/ws_functions/pwg.images.php | 87 | ||||
-rw-r--r-- | include/ws_functions/pwg.tags.php | 8 |
13 files changed, 595 insertions, 98 deletions
diff --git a/include/Logger.class.php b/include/Logger.class.php new file mode 100644 index 000000000..90fa9e491 --- /dev/null +++ b/include/Logger.class.php @@ -0,0 +1,489 @@ +<?php +// +-----------------------------------------------------------------------+ +// | Piwigo - a PHP based photo gallery | +// +-----------------------------------------------------------------------+ +// | Copyright(C) 2008-2015 Piwigo Team http://piwigo.org | +// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | +// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +/** + * Modified version of KLogger 0.2.0 + * + * @author Kenny Katzgrau <katzgrau@gmail.com> + * + * @package logger + */ + +class Logger +{ + /** + * Error severity, from low to high. From BSD syslog RFC, section 4.1.1 + * @link http://www.faqs.org/rfcs/rfc3164.html + */ + const EMERGENCY = 0; // Emergency: system is unusable + const ALERT = 1; // Alert: action must be taken immediately + const CRITICAL = 2; // Critical: critical conditions + const ERROR = 3; // Error: error conditions + const WARNING = 4; // Warning: warning conditions + const NOTICE = 5; // Notice: normal but significant condition + const INFO = 6; // Informational: informational messages + const DEBUG = 7; // Debug: debug messages + + /** + * Custom "disable" level. + */ + const OFF = -1; // Log nothing at all + + /** + * Internal status codes. + */ + const STATUS_LOG_OPEN = 1; + const STATUS_OPEN_FAILED = 2; + const STATUS_LOG_CLOSED = 3; + + /** + * Disable archive purge. + */ + const ARCHIVE_NO_PURGE = -1; + + /** + * Standard messages produced by the class. + * @var array + */ + private static $_messages = array( + 'writefail' => 'The file could not be written to. Check that appropriate permissions have been set.', + 'opensuccess' => 'The log file was opened successfully.', + 'openfail' => 'The file could not be opened. Check permissions.', + ); + + /** + * Instance options. + * @var array + */ + private $options = array( + 'directory' => null, // Log files directory + 'filename' => null, // Path to the log file + 'globPattern' => 'log_*.txt', // Pattern to select all log files with glob() + 'severity' => self::DEBUG, // Current minimum logging threshold + 'dateFormat' => 'Y-m-d G:i:s', // Date format + 'archiveDays' => self::ARCHIVE_NO_PURGE, // Number of files to keep + ); + + /** + * Current status of the logger. + * @var integer + */ + private $_logStatus = self::STATUS_LOG_CLOSED; + /** + * File handle for this instance's log file. + * @var resource + */ + private $_fileHandle = null; + + + /** + * Class constructor. + * + * @param array $options + * @return void + */ + public function __construct($options) + { + $this->options = array_merge($this->options, $options);
+
+ if (is_string($this->options['severity'])) + {
+ $this->options['severity'] = self::codeToLevel($this->options['severity']);
+ } + + if ($this->options['severity'] === self::OFF) + { + return; + } + + $this->options['directory'] = rtrim($this->options['directory'], '\\/') . DIRECTORY_SEPARATOR; + + if ($this->options['filename'] == null) + { + $this->options['filename'] = 'log_' . date('Y-m-d') . '.txt'; + } + + $this->options['filePath'] = $this->options['directory'] . $this->options['filename']; + + if ($this->options['archiveDays'] != self::ARCHIVE_NO_PURGE && rand() % 97 == 0) + { + $this->purge(); + } + } + + /** + * Open the log file if not already oppenned + */ + private function open() + { + if ($this->status() == self::STATUS_LOG_CLOSED) + { + if (!file_exists($this->options['directory'])) + { + mkgetdir($this->options['directory'], MKGETDIR_DEFAULT|MKGETDIR_PROTECT_HTACCESS); + } + + if (file_exists($this->options['filePath']) && !is_writable($this->options['filePath'])) + { + $this->_logStatus = self::STATUS_OPEN_FAILED; + throw new RuntimeException(self::$_messages['writefail']); + return; + } + + if (($this->_fileHandle = fopen($this->options['filePath'], 'a')) != false) + { + $this->_logStatus = self::STATUS_LOG_OPEN; + } + else + { + $this->_logStatus = self::STATUS_OPEN_FAILED; + throw new RuntimeException(self::$_messages['openfail']); + } + } + } + + /** + * Class destructor. + */ + public function __destruct() + { + if ($this->_fileHandle) + { + fclose($this->_fileHandle); + } + } + + /** + * Returns logger status. + * + * @return int + */ + public function status() + { + return $this->_logStatus; + } + + /** + * Returns logger severity threshold. + * + * @return int + */ + public function severity() + { + return $this->options['severity']; + } + + /** + * Writes a $line to the log with a severity level of DEBUG. + * + * @param string $line + * @param string $cat + * @param array $args + */ + public function debug($line, $cat = null, $args = array()) + { + $this->log(self::DEBUG, $line, $cat, $args); + } + + /** + * Writes a $line to the log with a severity level of INFO. + * + * @param string $line + * @param string $cat + * @param array $args + */ + public function info($line, $cat = null, $args = array()) + { + $this->log(self::INFO, $line, $cat, $args); + } + + /** + * Writes a $line to the log with a severity level of NOTICE. + * + * @param string $line + * @param string $cat + * @param array $args + */ + public function notice($line, $cat = null, $args = array()) + { + $this->log(self::NOTICE, $line, $cat, $args); + } + + /** + * Writes a $line to the log with a severity level of WARNING. + * + * @param string $line + * @param string $cat + * @param array $args + */ + public function warn($line, $cat = null, $args = array()) + { + $this->log(self::WARNING, $line, $cat, $args); + } + + /** + * Writes a $line to the log with a severity level of ERROR. + * + * @param string $line + * @param string $cat + * @param array $args + */ + public function error($line, $cat = null, $args = array()) + { + $this->log(self::ERROR, $line, $cat, $args); + } + + /** + * Writes a $line to the log with a severity level of ALERT. + * + * @param string $line + * @param string $cat + * @param array $args + */ + public function alert($line, $cat = null, $args = array()) + { + $this->log(self::ALERT, $line, $cat, $args); + } + + /** + * Writes a $line to the log with a severity level of CRITICAL. + * + * @param string $line + * @param string $cat + * @param array $args + */ + public function critical($line, $cat = null, $args = array()) + { + $this->log(self::CRITICAL, $line, $cat, $args); + } + + /** + * Writes a $line to the log with a severity level of EMERGENCY. + * + * @param string $line + * @param string $cat + * @param array $args + */ + public function emergency($line, $cat = null, $args = array()) + { + $this->log(self::EMERGENCY, $line, $cat, $args); + } + + /** + * Writes a $line to the log with the given severity. + * + * @param integer $severity + * @param string $line + * @param string $cat + * @param array $args + */ + public function log($severity, $message, $cat = null, $args = array()) + { + if ($this->severity() >= $severity) + { + if (is_array($cat)) + { + $args = $cat; + $cat = null; + } + $line = $this->formatMessage($severity, $message, $cat, $args); + $this->write($line); + } + } + + /** + * Directly writes a line to the log without adding level and time. + * + * @param string $line + */ + public function write($line) + { + $this->open(); + if ($this->status() == self::STATUS_LOG_OPEN) + { + if (fwrite($this->_fileHandle, $line) === false) + { + throw new RuntimeException(self::$_messages['writefail']); + } + } + } + + /** + * Purges files matching 'globPattern' older than 'archiveDays'. + */ + public function purge() + { + $files = glob($this->options['directory'] . $this->options['globPattern']); + $limit = time() - $this->options['archiveDays'] * 86400; + + foreach ($files as $file) + { + if (@filemtime($file) < $limit) + { + @unlink($file); + } + } + } + + /** + * Formats the message for logging. + * + * @param string $level + * @param string $message + * @param array $context + * @return string + */ + private function formatMessage($level, $message, $cat, $context) + { + if (!empty($context)) + { + $message.= "\n" . $this->indent($this->contextToString($context)); + } + $line = "[" . $this->getTimestamp() . "]\t[" . self::levelToCode($level) . "]\t"; + if ($cat != null) + { + $line.= "[" . $cat . "]\t"; + } + return $line . $message . "\n"; + } + + /** + * Gets the formatted Date/Time for the log entry. + * + * PHP DateTime is dumb, and you have to resort to trickery to get microseconds + * to work correctly, so here it is. + * + * @return string + */ + private function getTimestamp() + { + $originalTime = microtime(true); + $micro = sprintf('%06d', ($originalTime - floor($originalTime)) * 1000000); + $date = new DateTime(date('Y-m-d H:i:s.'.$micro, $originalTime)); + return $date->format($this->options['dateFormat']); + } + + /** + * Takes the given context and converts it to a string. + * + * @param array $context + * @return string + */ + private function contextToString($context) + { + $export = ''; + foreach ($context as $key => $value) + { + $export.= $key . ': '; + $export.= preg_replace(array( + '/=>\s+([a-zA-Z])/im', + '/array\(\s+\)/im', + '/^ |\G /m' + ), + array( + '=> $1', + 'array()', + ' ' + ), + str_replace('array (', 'array(', var_export($value, true)) + ); + $export.= PHP_EOL; + } + return str_replace(array('\\\\', '\\\''), array('\\', '\''), rtrim($export)); + } + + /** + * Indents the given string with the given indent. + * + * @param string $string The string to indent + * @param string $indent What to use as the indent. + * @return string + */ + private function indent($string, $indent = ' ') + { + return $indent . str_replace("\n", "\n" . $indent, $string); + } + + /** + * Converts level constants to string name. + * + * @param int $level + * @return string + */ + static function levelToCode($level) + { + switch ($level) + { + case self::EMERGENCY: + return 'EMERGENCY'; + case self::ALERT: + return 'ALERT'; + case self::CRITICAL: + return 'CRITICAL'; + case self::NOTICE: + return 'NOTICE'; + case self::INFO: + return 'INFO'; + case self::WARNING: + return 'WARNING'; + case self::DEBUG: + return 'DEBUG'; + case self::ERROR: + return 'ERROR'; + default: + throw new RuntimeException('Unknown severity level ' . $level); + } + } + + /** + * Converts level names to constant. + * + * @param string $code + * @return int + */ + static function codeToLevel($code) + { + switch (strtoupper($code)) + { + case 'EMERGENCY': + return self::EMERGENCY; + case 'ALERT': + return self::ALERT; + case 'CRITICAL': + return self::CRITICAL; + case 'NOTICE': + return self::NOTICE; + case 'INFO': + return self::INFO; + case 'WARNING': + return self::WARNING; + case 'DEBUG': + return self::DEBUG; + case 'ERROR': + return self::ERROR; + default: + throw new RuntimeException('Unknown severity code ' . $code); + } + } +} +?>
\ No newline at end of file diff --git a/include/common.inc.php b/include/common.inc.php index e3f4a16c7..8fab02ab2 100644 --- a/include/common.inc.php +++ b/include/common.inc.php @@ -104,6 +104,9 @@ if(isset($conf['show_php_errors']) && !empty($conf['show_php_errors'])) include(PHPWG_ROOT_PATH . 'include/constants.php'); include(PHPWG_ROOT_PATH . 'include/functions.inc.php'); +include(PHPWG_ROOT_PATH . 'include/template.class.php'); +include(PHPWG_ROOT_PATH . 'include/cache.class.php'); +include(PHPWG_ROOT_PATH . 'include/Logger.class.php'); $persistent_cache = new PersistentFileCache(); @@ -122,6 +125,17 @@ pwg_db_check_charset(); load_conf_from_db(); +$logger = new Logger(array( + 'directory' => PHPWG_ROOT_PATH . $conf['data_location'] . $conf['log_dir'], + 'severity' => $conf['log_level'], + // we use an hashed filename to prevent direct file access, and we salt with + // the db_password instead of secret_key because the log must be usable in i.php + // (secret_key is in the database) + 'filename' => 'log_' . date('Y-m-d') . '_' . sha1(date('Y-m-d') . $conf['db_password']) . '.txt', + 'globPattern' => 'log_*.txt', + 'archiveDays' => $conf['log_archive_days'], + )); + if (!$conf['check_upgrade_feed']) { if (!isset($conf['piwigo_db_version']) or $conf['piwigo_db_version'] != get_branch_from_version(PHPWG_VERSION)) diff --git a/include/config_default.inc.php b/include/config_default.inc.php index 6d2dd31db..09d11132e 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -114,7 +114,7 @@ $conf['paginate_pages_around'] = 2; // show_version : shall the version of Piwigo be displayed at the // bottom of each page ? -$conf['show_version'] = false; +$conf['show_version'] = true; // meta_ref to reference multiple sets of incorporated pages or elements // Set it false to avoid referencing in google, and other search engines. @@ -231,7 +231,7 @@ $conf['available_permission_levels'] = array(0,1,2,4,8); // // This configuration parameter is set to true in BSF branch and to false // elsewhere. -$conf['check_upgrade_feed'] = false; +$conf['check_upgrade_feed'] = true; // rate_items: available rates for a picture $conf['rate_items'] = array(0,1,2,3,4,5); @@ -371,6 +371,10 @@ $conf['use_exif_mapping'] = array( // javascript) $conf['allow_html_in_metadata'] = false; +// decide which characters can be used as keyword separators (works in EXIF +// and IPTC). Coma "," cannot be removed from this list. +$conf['metadata_keyword_separator_regex'] = '/[.,;]/'; + // +-----------------------------------------------------------------------+ // | sessions | // +-----------------------------------------------------------------------+ @@ -419,7 +423,7 @@ $conf['session_use_ip_address'] = true; $conf['show_queries'] = false; // show_gt : display generation time at the bottom of each page -$conf['show_gt'] = false; +$conf['show_gt'] = true; // debug_l10n : display a warning message each time an unset language key is // accessed @@ -432,7 +436,7 @@ $conf['debug_template'] = false; $conf['debug_mail'] = false; // die_on_sql_error: if an SQL query fails, should everything stop? -$conf['die_on_sql_error'] = false; +$conf['die_on_sql_error'] = true; // if true, some language strings are replaced during template compilation // (instead of template output). this results in better performance. however @@ -458,8 +462,6 @@ $conf['template_combine_files'] = true; // gives an empty value '' to deactivate $conf['show_php_errors'] = E_ALL; -// enable log for i derivative script -$conf['enable_i_log'] = false; // +-----------------------------------------------------------------------+ // | authentication | @@ -649,12 +651,6 @@ $conf['enable_plugins']=true; // Web services are allowed (true) or completely forbidden (false) $conf['allow_web_services'] = true; -// enable log for web services -$conf['ws_enable_log'] = false; - -// web services log file path -$conf['ws_log_filepath'] = '/tmp/piwigo_ws.log'; - // Maximum number of images to be returned foreach call to the web service $conf['ws_max_images_per_page'] = 500; @@ -808,4 +804,17 @@ $conf['upload_form_all_types'] = false; // "ffmpeg" is not visible by the web user, you can define the full path of // the directory where "ffmpeg" executable is. $conf['ffmpeg_dir'] = ''; -?> + +// +-----------------------------------------------------------------------+ +// | log | +// +-----------------------------------------------------------------------+ +// Logs directory, relative to $conf['data_location'] +$conf['log_dir'] = '/logs'; + +// Log level (OFF, CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG) +// development = DEBUG, production = ERROR +$conf['log_level'] = 'DEBUG'; + +// Keep logs file during X days +$conf['log_archive_days'] = 30; +?>
\ No newline at end of file diff --git a/include/constants.php b/include/constants.php index 70d13d124..1a7201416 100644 --- a/include/constants.php +++ b/include/constants.php @@ -22,7 +22,7 @@ // +-----------------------------------------------------------------------+ // Default settings -define('PHPWG_VERSION', '2.7.4'); +define('PHPWG_VERSION', '2.7.0'); define('PHPWG_DEFAULT_LANGUAGE', 'en_UK'); define('PHPWG_DEFAULT_TEMPLATE', 'elegant'); diff --git a/include/derivative_std_params.inc.php b/include/derivative_std_params.inc.php index 375eb18e9..a0f1edb76 100644 --- a/include/derivative_std_params.inc.php +++ b/include/derivative_std_params.inc.php @@ -201,8 +201,6 @@ final class ImageStdParams */ static function save() { - global $conf; - $ser = serialize( array( 'd' => self::$type_map, 'q' => self::$quality, diff --git a/include/functions.inc.php b/include/functions.inc.php index 4ba5eb54c..a9ae35baf 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -36,8 +36,6 @@ include_once( PHPWG_ROOT_PATH .'include/functions_url.inc.php' ); include_once( PHPWG_ROOT_PATH .'include/derivative_params.inc.php'); include_once( PHPWG_ROOT_PATH .'include/derivative_std_params.inc.php'); include_once( PHPWG_ROOT_PATH .'include/derivative.inc.php'); -include_once( PHPWG_ROOT_PATH .'include/template.class.php'); -include_once( PHPWG_ROOT_PATH .'include/cache.class.php'); /** diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php index 826ff9292..15ab84c25 100644 --- a/include/functions_category.inc.php +++ b/include/functions_category.inc.php @@ -335,7 +335,7 @@ SELECT DISTINCT(id) } $query.= ' ;'; - return array_from_query($query, 'id'); + return query2array($query, null, 'id'); } /** @@ -541,7 +541,7 @@ FROM '.CATEGORIES_TABLE.' as c // Piwigo before 2.5.3 may have generated inconsistent permissions, ie // private album A1/A2 permitted to user U1 but private album A1 not // permitted to U1. - // + // // TODO 2.7: add an upgrade script to repair permissions and remove this // test if ( !isset($cats[ $cat['id_uppercat'] ])) diff --git a/include/functions_search.inc.php b/include/functions_search.inc.php index 688a043de..2f42473b3 100644 --- a/include/functions_search.inc.php +++ b/include/functions_search.inc.php @@ -938,6 +938,14 @@ function qsearch_get_images(QExpression $expr, QResults $qsr) case 'file': $clauses[] = $file_like; break; + case 'author': + if ( strlen($token->term) ) + $clauses = array_merge($clauses, qsearch_get_text_token_search_sql($token, array('author'))); + elseif ($token->modifier & QST_WILDCARD) + $clauses[] = 'author IS NOT NULL'; + else + $clauses[] = 'author IS NULL'; + break; case 'width': case 'height': $clauses[] = $token->scope->get_sql($scope_id, $token); @@ -1178,6 +1186,7 @@ function get_quick_search_results_no_cache($q, $options) $scopes[] = new QSearchScope('tag', array('tags')); $scopes[] = new QSearchScope('photo', array('photos')); $scopes[] = new QSearchScope('file', array('filename')); + $scopes[] = new QSearchScope('author', array(), true); $scopes[] = new QNumericRangeScope('width', array()); $scopes[] = new QNumericRangeScope('height', array()); $scopes[] = new QNumericRangeScope('ratio', array(), false, 0.001); diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php index 96361930a..5f503b36e 100644 --- a/include/functions_user.inc.php +++ b/include/functions_user.inc.php @@ -219,14 +219,12 @@ SELECT id mass_inserts(USER_GROUP_TABLE, array('user_id', 'group_id'), $inserts); } - $override = null; - if ($notify_admin and $conf['browser_language']) + $override = array(); + if ($language = get_browser_language()) { - if (!get_browser_language($override['language'])) - { - $override=null; - } + $override['language'] = $language; } + create_user_infos($user_id, $override); if ($notify_admin and $conf['email_admin_on_new_user']) @@ -809,18 +807,16 @@ function get_default_language() * Tries to find the browser language among available languages. * @todo : try to match 'fr_CA' before 'fr' * - * @param string &$lang - * @return bool + * @return string */ -function get_browser_language(&$lang) +function get_browser_language() { $browser_language = substr(@$_SERVER["HTTP_ACCEPT_LANGUAGE"], 0, 2); foreach (get_languages() as $language_code => $language_name) { if (substr($language_code, 0, 2) == $browser_language) { - $lang = $language_code; - return true; + return $language_code; } } return false; diff --git a/include/user.inc.php b/include/user.inc.php index d1bf87c70..4de5cc6c3 100644 --- a/include/user.inc.php +++ b/include/user.inc.php @@ -68,9 +68,9 @@ if ($conf['apache_authentication']) $user = build_user( $user['id'], ( defined('IN_ADMIN') and IN_ADMIN ) ? false : true // use cache ? ); -if ($conf['browser_language'] and (is_a_guest() or is_generic()) ) +if ($conf['browser_language'] and (is_a_guest() or is_generic()) and $language = get_browser_language()) { - get_browser_language($user['language']); + $user['language'] = $language; } trigger_notify('user_init', $user); ?> diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php index 17d15313c..578589c9b 100644 --- a/include/ws_functions.inc.php +++ b/include/ws_functions.inc.php @@ -205,25 +205,6 @@ function ws_std_get_tag_xml_attributes() } /** - * Writes info to the log file - */ -function ws_logfile($string) -{ - global $conf; - - if (!$conf['ws_enable_log']) - { - return true; - } - - file_put_contents( - $conf['ws_log_filepath'], - '['.date('c').'] '.$string."\n", - FILE_APPEND - ); -} - -/** * create a tree from a flat list of categories, no recursivity for high speed */ function categories_flatlist_to_tree($categories) diff --git a/include/ws_functions/pwg.images.php b/include/ws_functions/pwg.images.php index 04ab65f35..319bce1f1 100644 --- a/include/ws_functions/pwg.images.php +++ b/include/ws_functions/pwg.images.php @@ -82,7 +82,7 @@ SELECT id FROM '.CATEGORIES_TABLE.' WHERE id IN ('.implode(',', $cat_ids).') ;'; - $db_cat_ids = array_from_query($query, 'id'); + $db_cat_ids = query2array($query, null, 'id'); $unknown_cat_ids = array_diff($cat_ids, $db_cat_ids); if (count($unknown_cat_ids) != 0) @@ -100,7 +100,7 @@ SELECT category_id FROM '.IMAGE_CATEGORY_TABLE.' WHERE image_id = '.$image_id.' ;'; - $existing_cat_ids = array_from_query($query, 'category_id'); + $existing_cat_ids = query2array($query, null, 'category_id'); if ($replace_mode) { @@ -133,7 +133,7 @@ SELECT category_id, MAX(rank) AS max_rank AND category_id IN ('.implode(',', $new_cat_ids).') GROUP BY category_id ;'; - $current_rank_of = simple_hash_from_query( + $current_rank_of = query2array( $query, 'category_id', 'max_rank' @@ -182,9 +182,9 @@ SELECT category_id, MAX(rank) AS max_rank */ function merge_chunks($output_filepath, $original_sum, $type) { - global $conf; + global $conf, $logger; - ws_logfile('[merge_chunks] input parameter $output_filepath : '.$output_filepath); + $logger->debug('[merge_chunks] input parameter $output_filepath : '.$output_filepath, 'WS'); if (is_file($output_filepath)) { @@ -206,7 +206,7 @@ function merge_chunks($output_filepath, $original_sum, $type) { if (preg_match($pattern, $file)) { - ws_logfile($file); + $logger->debug($file, 'WS'); $chunks[] = $upload_dir.'/'.$file; } } @@ -216,7 +216,7 @@ function merge_chunks($output_filepath, $original_sum, $type) sort($chunks); if (function_exists('memory_get_usage')) { - ws_logfile('[merge_chunks] memory_get_usage before loading chunks: '.memory_get_usage()); + $logger->debug('[merge_chunks] memory_get_usage before loading chunks: '.memory_get_usage(), 'WS'); } $i = 0; @@ -226,7 +226,7 @@ function merge_chunks($output_filepath, $original_sum, $type) $string = file_get_contents($chunk); if (function_exists('memory_get_usage')) { - ws_logfile('[merge_chunks] memory_get_usage on chunk '.++$i.': '.memory_get_usage()); + $logger->debug('[merge_chunks] memory_get_usage on chunk '.++$i.': '.memory_get_usage(), 'WS'); } if (!file_put_contents($output_filepath, $string, FILE_APPEND)) @@ -238,7 +238,7 @@ function merge_chunks($output_filepath, $original_sum, $type) } if (function_exists('memory_get_usage')) { - ws_logfile('[merge_chunks] memory_get_usage after loading chunks: '.memory_get_usage()); + $logger->debug('[merge_chunks] memory_get_usage after loading chunks: '.memory_get_usage(), 'WS'); } } @@ -481,7 +481,7 @@ SELECT COUNT(id) AS nb_comments FROM '. COMMENTS_TABLE .' WHERE '. $where_comments .' ;'; - list($nb_comments) = array_from_query($query, 'nb_comments'); + list($nb_comments) = query2array($query, null, 'nb_comments'); $nb_comments = (int)$nb_comments; if ($nb_comments>0 and $params['comments_per_page']>0) @@ -824,7 +824,7 @@ UPDATE '. IMAGE_CATEGORY_TABLE .' */ function ws_images_add_chunk($params, $service) { - global $conf; + global $conf, $logger; foreach ($params as $param_key => $param_value) { @@ -832,13 +832,12 @@ function ws_images_add_chunk($params, $service) { continue; } - ws_logfile( - sprintf( - '[ws_images_add_chunk] input param "%s" : "%s"', - $param_key, - is_null($param_value) ? 'NULL' : $param_value - ) - ); + + $logger->debug(sprintf( + '[ws_images_add_chunk] input param "%s" : "%s"', + $param_key, + is_null($param_value) ? 'NULL' : $param_value + ), 'WS'); } $upload_dir = $conf['upload_dir'].'/buffer'; @@ -856,7 +855,7 @@ function ws_images_add_chunk($params, $service) $params['position'] ); - ws_logfile('[ws_images_add_chunk] data length : '.strlen($params['data'])); + $logger->debug('[ws_images_add_chunk] data length : '.strlen($params['data']), 'WS'); $bytes_written = file_put_contents( $upload_dir.'/'.$filename, @@ -881,9 +880,9 @@ function ws_images_add_chunk($params, $service) */ function ws_images_addFile($params, $service) { - ws_logfile(__FUNCTION__.', input : '.var_export($params, true)); + global $conf, $logger; - global $conf; + $logger->debug(__FUNCTION__, 'WS', $params); // what is the path and other infos about the photo? $query = ' @@ -974,17 +973,15 @@ SELECT */ function ws_images_add($params, $service) { - global $conf, $user; + global $conf, $user, $logger; foreach ($params as $param_key => $param_value) { - ws_logfile( - sprintf( - '[pwg.images.add] input param "%s" : "%s"', - $param_key, - is_null($param_value) ? 'NULL' : $param_value - ) - ); + $logger->debug(sprintf( + '[pwg.images.add] input param "%s" : "%s"', + $param_key, + is_null($param_value) ? 'NULL' : $param_value + ), 'WS'); } if ($params['image_id'] > 0) @@ -1269,7 +1266,7 @@ function ws_images_upload($params, $service) // { // return new PwgError(405, 'The image (file) is missing'); // } - + // file_put_contents('/tmp/plupload.log', "[".date('c')."] ".__FUNCTION__."\n\n", FILE_APPEND); // file_put_contents('/tmp/plupload.log', '$_FILES = '.var_export($_FILES, true)."\n", FILE_APPEND); // file_put_contents('/tmp/plupload.log', '$_POST = '.var_export($_POST, true)."\n", FILE_APPEND); @@ -1342,11 +1339,11 @@ function ws_images_upload($params, $service) // Check if file has been uploaded if (!$chunks || $chunk == $chunks - 1) { - // Strip the temp .part suffix off + // Strip the temp .part suffix off rename("{$filePath}.part", $filePath); - + include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); - + $image_id = add_uploaded_file( $filePath, stripslashes($params['name']), // function add_uploaded_file will secure before insert @@ -1354,7 +1351,7 @@ function ws_images_upload($params, $service) $params['level'], null // image_id = not provided, this is a new photo ); - + $query = ' SELECT id, @@ -1375,7 +1372,7 @@ SELECT $category_infos = pwg_db_fetch_assoc(pwg_query($query)); $category_name = get_cat_display_name_from_id($params['category'][0], null); - + return array( 'image_id' => $image_id, 'src' => DerivativeImage::thumb_url($image_infos), @@ -1398,9 +1395,9 @@ SELECT */ function ws_images_exist($params, $service) { - ws_logfile(__FUNCTION__.' '.var_export($params, true)); + global $conf, $logger; - global $conf; + $logger->debug(__FUNCTION__, 'WS', $params); $split_pattern = '/[\s,;\|]/'; $result = array(); @@ -1420,7 +1417,7 @@ SELECT id, md5sum FROM '. IMAGES_TABLE .' WHERE md5sum IN (\''. implode("','", $md5sums) .'\') ;'; - $id_of_md5 = simple_hash_from_query($query, 'md5sum', 'id'); + $id_of_md5 = query2array($query, 'md5sum', 'id'); foreach ($md5sums as $md5sum) { @@ -1431,7 +1428,7 @@ SELECT id, md5sum } } } - else if ('filename' == $conf['uniqueness_mode']) + elseif ('filename' == $conf['uniqueness_mode']) { // search among photos the list of photos already added, based on // filename list @@ -1447,7 +1444,7 @@ SELECT id, file FROM '.IMAGES_TABLE.' WHERE file IN (\''. implode("','", $filenames) .'\') ;'; - $id_of_filename = simple_hash_from_query($query, 'file', 'id'); + $id_of_filename = query2array($query, 'file', 'id'); foreach ($filenames as $filename) { @@ -1471,7 +1468,9 @@ SELECT id, file */ function ws_images_checkFiles($params, $service) { - ws_logfile(__FUNCTION__.', input : '.var_export($params, true)); + global $logger; + + $logger->debug(__FUNCTION__, 'WS', $params); $query = ' SELECT path @@ -1502,14 +1501,14 @@ SELECT path $ret['file'] = 'equals'; $compare_type = 'high'; } - else if (isset($params['file_sum'])) + elseif (isset($params['file_sum'])) { $compare_type = 'file'; } if (isset($compare_type)) { - ws_logfile(__FUNCTION__.', md5_file($path) = '.md5_file($path)); + $logger->debug(__FUNCTION__.', md5_file($path) = '.md5_file($path), 'WS'); if (md5_file($path) != $params[$compare_type.'_sum']) { $ret[$compare_type] = 'differs'; @@ -1520,7 +1519,7 @@ SELECT path } } - ws_logfile(__FUNCTION__.', output : '.var_export($ret, true)); + $logger->debug(__FUNCTION__, 'WS', $ret); return $ret; } diff --git a/include/ws_functions/pwg.tags.php b/include/ws_functions/pwg.tags.php index 09ce21bd0..c4ce2b7fc 100644 --- a/include/ws_functions/pwg.tags.php +++ b/include/ws_functions/pwg.tags.php @@ -110,11 +110,16 @@ function ws_tags_getImages($params, &$service) $where_clauses = implode(' AND ', $where_clauses); } + $order_by = ws_std_image_sql_order($params, 'i.'); + if (!empty($order_by)) + { + $order_by = 'ORDER BY '.$order_by; + } $image_ids = get_image_ids_for_tags( $tag_ids, $params['tag_mode_and'] ? 'AND' : 'OR', $where_clauses, - ws_std_image_sql_order($params) + $order_by ); $count_set = count($image_ids); @@ -136,7 +141,6 @@ SELECT image_id, GROUP_CONCAT(tag_id) AS tag_ids while ($row = pwg_db_fetch_assoc($result)) { $row['image_id'] = (int)$row['image_id']; - $image_ids[] = $row['image_id']; $image_tag_map[ $row['image_id'] ] = explode(',', $row['tag_ids']); } } |