diff options
author | rvelices <rv-github@modusoptimus.com> | 2008-09-17 01:48:31 +0000 |
---|---|---|
committer | rvelices <rv-github@modusoptimus.com> | 2008-09-17 01:48:31 +0000 |
commit | cc12d640519a673d1a422cc608ca6ec1a59ef46e (patch) | |
tree | 988c8cb507ee9561d5b96f30974dbb2753c426b6 /include | |
parent | 7ea85bc0355c7ad60c51a4a1d3078e3dc4603031 (diff) |
- fix status header (web services + IE6 min display)
- sql optims in feed /notification
- dont send cookie for 10 years from admin/history.php
git-svn-id: http://piwigo.org/svn/trunk@2543 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | include/common.inc.php | 1 | ||||
-rw-r--r-- | include/functions_cookie.inc.php | 26 | ||||
-rw-r--r-- | include/functions_html.inc.php | 6 | ||||
-rw-r--r-- | include/functions_notification.inc.php | 14 | ||||
-rw-r--r-- | include/ws_core.inc.php | 79 |
5 files changed, 46 insertions, 80 deletions
diff --git a/include/common.inc.php b/include/common.inc.php index 1ddebfc9b..a8f661dca 100644 --- a/include/common.inc.php +++ b/include/common.inc.php @@ -223,6 +223,7 @@ if ($conf['gallery_locked']) @header('Retry-After: 900'); echo l10n('gallery_locked_message') .'<a href="'.get_absolute_root_url(false).'identification.php">.</a>'; + echo str_repeat( ' ', 512); //IE6 doesn't error output if below a size exit(); } } diff --git a/include/functions_cookie.inc.php b/include/functions_cookie.inc.php index 159a5b538..66b66221f 100644 --- a/include/functions_cookie.inc.php +++ b/include/functions_cookie.inc.php @@ -36,15 +36,15 @@ function cookie_path() { // mod_rewrite is activated for upper level directories. we must set the // cookie to the path shown in the browser otherwise it will be discarded. - if - ( + if + ( isset($_SERVER['PATH_INFO']) and !empty($_SERVER['PATH_INFO']) and ($_SERVER['REDIRECT_URL'] !== $_SERVER['PATH_INFO']) and (substr($_SERVER['REDIRECT_URL'],-strlen($_SERVER['PATH_INFO'])) == $_SERVER['PATH_INFO']) ) { - $scr = substr($_SERVER['REDIRECT_URL'], 0, + $scr = substr($_SERVER['REDIRECT_URL'], 0, strlen($_SERVER['REDIRECT_URL'])-strlen($_SERVER['PATH_INFO'])); } else @@ -64,7 +64,7 @@ function cookie_path() { $scr .= '/'; } - + if ( substr(PHPWG_ROOT_PATH,0,3)=='../') { // this is maybe a plugin inside pwg directory // TODO - what if it is an external script outside PWG ? @@ -87,12 +87,20 @@ function cookie_path() * @return boolean true on success * @see pwg_get_cookie_var */ -function pwg_set_cookie_var($var, $value) +function pwg_set_cookie_var($var, $value, $expire=null) { - $_COOKIE['pwg_'.$var] = $value; - return - setcookie('pwg_'.$var, $value, - strtotime('+10 years'), cookie_path()); + if ($value==null or $expire===0) + { + unset($_COOKIE['pwg_'.$var]); + return setcookie('pwg_'.$var, false, 0, cookie_path()); + + } + else + { + $_COOKIE['pwg_'.$var] = $value; + $expire = is_numeric($expire) ? $expire : strtotime('+10 years'); + return setcookie('pwg_'.$var, $value, $expire, cookie_path()); + } } /** diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php index ca07a1e16..2b3994aa8 100644 --- a/include/functions_html.inc.php +++ b/include/functions_html.inc.php @@ -585,16 +585,17 @@ function access_denied() get_root_url().'identification.php?redirect=' .urlencode(urlencode($_SERVER['REQUEST_URI'])); + set_status_header(401); if ( isset($user) and !is_a_guest() ) { echo '<div style="text-align:center;">'.l10n('access_forbiden').'<br />'; echo '<a href="'.get_root_url().'identification.php">'.l10n('identification').'</a> '; echo '<a href="'.make_index_url().'">'.l10n('home').'</a></div>'; + echo str_repeat( ' ', 512); //IE6 doesn't error output if below a size exit(); } else { - set_status_header(401); redirect_html($login_url); } } @@ -677,7 +678,7 @@ $btrace_msg </pre>\n"; @set_status_header(500); - echo $display.str_repeat( ' ', 300); //IE doesn't error output if below a size + echo $display.str_repeat( ' ', 300); //IE6 doesn't error output if below a size if ( function_exists('ini_set') ) {// if possible turn off error display (we display it) @@ -754,6 +755,7 @@ function set_status_header($code, $text='') case 403: $text='Forbidden';break; case 404: $text='Not found';break; case 500: $text='Server error';break; + case 501: $text='Not implemented';break; case 503: $text='Service unavailable';break; } } diff --git a/include/functions_notification.inc.php b/include/functions_notification.inc.php index 259a34613..32d3ed9c7 100644 --- a/include/functions_notification.inc.php +++ b/include/functions_notification.inc.php @@ -35,7 +35,7 @@ * * @return string sql where */ -function get_std_sql_where_restrict_filter($prefix_condition, $force_one_condition = false) +function get_std_sql_where_restrict_filter($prefix_condition, $img_field='ic.image_id', $force_one_condition = false) { return get_sql_condition_FandF ( @@ -43,7 +43,7 @@ function get_std_sql_where_restrict_filter($prefix_condition, $force_one_conditi ( 'forbidden_categories' => 'ic.category_id', 'visible_categories' => 'ic.category_id', - 'visible_images' => 'ic.image_id' + 'visible_images' => $img_field ), $prefix_condition, $force_one_condition @@ -89,7 +89,7 @@ function custom_notification_query($action, $type, $start, $end) FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON image_id = id WHERE date_available > \''.$start.'\' AND date_available <= \''.$end.'\' - '.get_std_sql_where_restrict_filter('AND').' + '.get_std_sql_where_restrict_filter('AND', 'id').' ;'; break; case 'updated_categories': @@ -97,7 +97,7 @@ function custom_notification_query($action, $type, $start, $end) FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON image_id = id WHERE date_available > \''.$start.'\' AND date_available <= \''.$end.'\' - '.get_std_sql_where_restrict_filter('AND').' + '.get_std_sql_where_restrict_filter('AND', 'id').' ;'; break; case 'new_users': @@ -434,13 +434,13 @@ function get_recent_post_dates($max_dates, $max_elements, $max_cats) { global $conf, $user; - $where_sql = get_std_sql_where_restrict_filter('WHERE', true); + $where_sql = get_std_sql_where_restrict_filter('WHERE', 'i.id', true); $query = ' SELECT date_available, COUNT(DISTINCT id) nb_elements, COUNT(DISTINCT category_id) nb_cats - FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=image_id + FROM '.IMAGES_TABLE.' i INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=image_id '.$where_sql.' GROUP BY date_available ORDER BY date_available DESC @@ -459,7 +459,7 @@ SELECT date_available, { // get some thumbnails ... $query = ' SELECT DISTINCT id, path, name, tn_ext, file - FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=image_id + FROM '.IMAGES_TABLE.' i INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=image_id '.$where_sql.' AND date_available="'.$dates[$i]['date_available'].'" AND tn_ext IS NOT NULL diff --git a/include/ws_core.inc.php b/include/ws_core.inc.php index cc1c1c756..24f10f114 100644 --- a/include/ws_core.inc.php +++ b/include/ws_core.inc.php @@ -35,7 +35,7 @@ define( 'WS_PARAM_ACCEPT_ARRAY', 0x010000 ); define( 'WS_PARAM_FORCE_ARRAY', 0x030000 ); define( 'WS_PARAM_OPTIONAL', 0x040000 ); -define( 'WS_ERR_INVALID_METHOD', 1001 ); +define( 'WS_ERR_INVALID_METHOD', 501 ); define( 'WS_ERR_MISSING_PARAM', 1002 ); define( 'WS_ERR_INVALID_PARAM', 1003 ); @@ -47,12 +47,15 @@ define( 'WS_XML_CONTENT', 'content_xml_'); */ class PwgError { - var $_code; - var $_codeText; + private $_code; + private $_codeText; function PwgError($code, $codeText) { - set_status_header($code, $codeText); + if ($code>=400 and $code<600) + { + set_status_header($code, $codeText); + } $this->_code = $code; $this->_codeText = $codeText; @@ -80,7 +83,7 @@ class PwgNamedArray * @param xmlAttributes array of sub-item attributes that will be encoded as * xml attributes instead of xml child elements */ - function PwgNamedArray(&$arr, $itemName, $xmlAttributes=array() ) + function PwgNamedArray($arr, $itemName, $xmlAttributes=array() ) { $this->_content = $arr; $this->_itemName = $itemName; @@ -134,52 +137,6 @@ class PwgNamedStruct /** - * Replace array_walk_recursive() - * - * @category PHP - * @package PHP_Compat - * @link http://php.net/function.array_walk_recursive - * @author Tom Buskens <ortega@php.net> - * @author Aidan Lister <aidan@php.net> - * @version $Revision$ - * @since PHP 5 - * @require PHP 4.0.6 (is_callable) - */ -if (!function_exists('array_walk_recursive')) { - function array_walk_recursive(&$input, $funcname) - { - if (!is_callable($funcname)) { - if (is_array($funcname)) { - $funcname = $funcname[0] . '::' . $funcname[1]; - } - user_error('array_walk_recursive() Not a valid callback ' . $user_func, - E_USER_WARNING); - return; - } - - if (!is_array($input)) { - user_error('array_walk_recursive() The argument should be an array', - E_USER_WARNING); - return; - } - - $args = func_get_args(); - - foreach ($input as $key => $item) { - if (is_array($item)) { - array_walk_recursive($item, $funcname, $args); - $input[$key] = $item; - } else { - $args[0] = &$item; - $args[1] = &$key; - call_user_func_array($funcname, $args); - $input[$key] = $item; - } - } - } -} - -/** * Abstract base class for request handlers. */ class PwgRequestHandler @@ -209,7 +166,7 @@ class PwgResponseEncoder * returns true if the parameter is a 'struct' (php array type whose keys are * NOT consecutive integers starting with 0) */ - function is_struct(&$data) + static function is_struct(&$data) { if (is_array($data) ) { @@ -225,7 +182,7 @@ class PwgResponseEncoder * removes all XML formatting from $response (named array, named structs, etc) * usually called by every response encoder, except rest xml. */ - function flattenResponse(&$response) + static function flattenResponse(&$response) { PwgResponseEncoder::_mergeAttributesAndContent($response); PwgResponseEncoder::_removeNamedArray($response); @@ -239,7 +196,7 @@ class PwgResponseEncoder PwgResponseEncoder::_mergeAttributesAndContent($response); } - /*private*/ function _remove_named_callback(&$value, $key) + private static function _remove_named_callback(&$value, $key) { do { @@ -251,7 +208,7 @@ class PwgResponseEncoder while ($changed); } - /*private*/ function _mergeAttributesAndContent(&$value) + private static function _mergeAttributesAndContent(&$value) { if ( !is_array($value) ) return; @@ -310,7 +267,7 @@ class PwgResponseEncoder return $ret; } - /*private*/ function _removeNamedArray(&$value) + private static function _removeNamedArray(&$value) { if ( strtolower( get_class($value) ) =='pwgnamedarray') { @@ -320,7 +277,7 @@ class PwgResponseEncoder return 0; } - /*private*/ function _removeNamedStruct(&$value) + private static function _removeNamedStruct(&$value) { if ( strtolower( get_class($value) ) =='pwgnamedstruct') { @@ -388,9 +345,7 @@ Request format: ".@$this->_requestFormat." Response format: ".@$this->_responseF if ( is_null($this->_requestHandler) ) { - $this->sendResponse( - new PwgError(400, 'Unknown request format') - ); + $this->sendResponse( new PwgError(400, 'Unknown request format') ); return; } @@ -583,7 +538,7 @@ Request format: ".@$this->_requestFormat." Response format: ".@$this->_responseF /** * WS reflection method implementation: lists all available methods */ - /*static*/ function ws_getMethodList($params, &$service) + static function ws_getMethodList($params, &$service) { return array('methods' => new PwgNamedArray( array_keys($service->_methods),'method' ) ); } @@ -591,7 +546,7 @@ Request format: ".@$this->_requestFormat." Response format: ".@$this->_responseF /** * WS reflection method implementation: gets information about a given method */ - /*static*/ function ws_getMethodDetails($params, &$service) + static function ws_getMethodDetails($params, &$service) { $methodName = $params['methodName']; if (!$service->hasMethod($methodName)) |