- 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
This commit is contained in:
rvelices 2008-09-17 01:48:31 +00:00
parent 7ea85bc035
commit cc12d64051
6 changed files with 48 additions and 81 deletions

View file

@ -116,7 +116,8 @@ if (isset($_POST['submit']))
$search['fields']['display_thumbnail'] = $_POST['display_thumbnail'];
// Display choise are also save to one cookie
pwg_set_cookie_var('history_display_thumbnail', $_POST['display_thumbnail']);
$cookie_val = ($_POST['display_thumbnail']!=$display_thumbnails[2] and in_array($_POST['display_thumbnail'], $display_thumbnails)) ? $_POST['display_thumbnail']:null;
pwg_set_cookie_var('history_display_thumbnail', $cookie_val, strtotime('+1 month') );
// TODO manage inconsistency of having $_POST['image_id'] and
// $_POST['filename'] simultaneously

View file

@ -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();
}
}

View file

@ -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)
{
if ($value==null or $expire===0)
{
unset($_COOKIE['pwg_'.$var]);
return setcookie('pwg_'.$var, false, 0, cookie_path());
}
else
{
$_COOKIE['pwg_'.$var] = $value;
return
setcookie('pwg_'.$var, $value,
strtotime('+10 years'), cookie_path());
$expire = is_numeric($expire) ? $expire : strtotime('+10 years');
return setcookie('pwg_'.$var, $value, $expire, cookie_path());
}
}
/**

View file

@ -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>&nbsp;';
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;
}
}

View file

@ -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

View file

@ -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)
{
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;
@ -133,52 +136,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.
*/
@ -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))