Changeset 1711


Ignore:
Timestamp:
Jan 11, 2007, 6:10:16 AM (17 years ago)
Author:
rvelices
Message:
  • better code in filter.inc.php (remove unused code + filter is not reseted

when going to an unfiltered page)

  • removed unnecessary filtered pages from config_default (especially admin !!!)
  • removed flat recent category icon from irrelevant pages
  • mysterious code comment appeared in picture.php
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/config_default.inc.php

    r1690 r1711  
    574574$conf['filter_pages'] = array
    575575  (
    576     'about', 'action', 'admin', 'comments',
    577     'index', 'picture', 'popuphelp', 'profile',
    578     'qsearch', 'random', 'register', 'search',
    579     'search_rules', 'tags', 'upload'
     576    'comments', 'index', 'picture', 'qsearch',
     577    'random', 'search', 'tags', 'upload'
    580578  );
    581579
  • trunk/include/filter.inc.php

    • Property svn:eol-style set to native
    • Property svn:keywords set to Author Date Id Rev Revision URL
    r1687 r1711  
    55// +-----------------------------------------------------------------------+
    66// | branch        : BSF (Best So Far)
    7 // | file          : $Id: filter.inc.php 1651 2006-12-13 00:05:16Z rub $
    8 // | last update   : $Date: 2006-12-13 01:05:16 +0100 (mer., 13 déc. 2006) $
    9 // | last modifier : $Author: rub $
    10 // | revision      : $Revision: 1651 $
     7// | file          : $Id$
     8// | last update   : $Date$
     9// | last modifier : $Author$
     10// | revision      : $Revision$
    1111// +-----------------------------------------------------------------------+
    1212// | This program is free software; you can redistribute it and/or modify  |
     
    3333// $filter['visible_images']: List of visible images
    3434
    35 
    36 $filter['enabled'] =
    37   (in_array(script_basename(), $conf['filter_pages'])) and
    38   (
    39     (isset($_GET['filter']) and ($_GET['filter'] == 'start')) or
    40     pwg_get_session_var('filter_enabled', false)
    41   );
     35$filter['enabled'] = false;
    4236
    4337if (in_array(script_basename(), $conf['filter_pages']))
    44 {
     38{ // valid only on certain pages
    4539  if (isset($_GET['filter']))
    4640  {
    4741    $filter['enabled'] = ($_GET['filter'] == 'start');
     42    if ( !$filter['enabled'] )
     43    {
     44      pwg_unset_session_var('filter_enabled');
     45      pwg_unset_session_var('filter_check_key');
     46      pwg_unset_session_var('filter_categories');
     47      pwg_unset_session_var('filter_visible_categories');
     48      pwg_unset_session_var('filter_visible_images');
     49    }
    4850  }
    4951  else
     
    5153    $filter['enabled'] = pwg_get_session_var('filter_enabled', false);
    5254  }
    53 }
    54 else
    55 {
    56   $filter['enabled'] = false;
    57 }
    5855
    59 if ($filter['enabled'])
    60 {
    61   if (
    62       // New filter
    63       !pwg_get_session_var('filter_enabled', false) or
    64       // Cache data updated
    65       $user['need_update_done'] or
    66       // Date, period, user are changed
    67       (pwg_get_session_var('filter_check_key', '') != get_filter_check_key())
    68     )
     56  if ($filter['enabled'])
    6957  {
    70     // Need to compute dats
    71     $filter['check_key'] = get_filter_check_key();
    72     $filter['categories'] = get_computed_categories($user['id'], $user['forbidden_categories'], true, $user['recent_period']);
     58    if (
     59        // New filter
     60        !pwg_get_session_var('filter_enabled', false) or
     61        // Cache data updated
     62        $user['need_update_done'] or
     63        // Date, period, user are changed
     64        (pwg_get_session_var('filter_check_key', '') != get_filter_check_key())
     65      )
     66    {
     67      // Need to compute dats
     68      $filter['check_key'] = get_filter_check_key();
     69      $filter['categories'] = get_computed_categories($user['id'], $user['forbidden_categories'], true, $user['recent_period']);
    7370
    74     $filter['visible_categories'] = implode(',', array_keys($filter['categories']));
    75     if (empty($filter['visible_categories']))
     71      $filter['visible_categories'] = implode(',', array_keys($filter['categories']));
     72      if (empty($filter['visible_categories']))
     73      {
     74        // Must be not empty
     75        $filter['visible_categories'] = -1;
     76      }
     77
     78      $query ='
     79SELECT DISTINCT(image_id)
     80  FROM '.
     81    IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id
     82  WHERE ';
     83      if (!empty($filter['visible_categories']))
     84      {
     85      $query.= '
     86  category_id  IN ('.$filter['visible_categories'].') AND';
     87      }
     88      $query.= '
     89  date_available  > SUBDATE(
     90        CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)';
     91
     92      $filter['visible_images'] = implode(',', array_from_query($query, 'image_id'));
     93
     94      if (empty($filter['visible_images']))
     95      {
     96        // Must be not empty
     97        $filter['visible_images'] = -1;
     98      }
     99
     100      pwg_set_session_var('filter_enabled', $filter['enabled']);
     101      pwg_set_session_var('filter_check_key', $filter['check_key']);
     102      pwg_set_session_var('filter_categories', serialize($filter['categories']));
     103      pwg_set_session_var('filter_visible_categories', $filter['visible_categories']);
     104      pwg_set_session_var('filter_visible_images', $filter['visible_images']);
     105    }
     106    else
    76107    {
    77       // Must be not empty
    78       $filter['visible_categories'] = -1;
     108      // Read only data
     109      $filter['check_key'] = pwg_get_session_var('filter_check_key', '');
     110      $filter['categories'] = unserialize(pwg_get_session_var('filter_categories', serialize(array())));
     111      $filter['visible_categories'] = pwg_get_session_var('filter_visible_categories', '');
     112      $filter['visible_images'] = pwg_get_session_var('filter_visible_images', '');
    79113    }
    80 
    81     $query ='
    82 SELECT
    83   distinct image_id
    84 FROM '.
    85   IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id
    86 WHERE ';
    87     if (!empty($filter['visible_categories']))
    88     {
    89     $query.= '
    90   category_id  IN ('.$filter['visible_categories'].') and';
    91     }
    92   $query.= '
    93     date_available  > SUBDATE(
    94       CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)';
    95 
    96     $filter['visible_images'] = implode(',', array_from_query($query, 'image_id'));
    97 
    98     if (empty($filter['visible_images']))
    99     {
    100       // Must be not empty
    101       $filter['visible_images'] = -1;
    102     }
    103 
    104   }
    105   else
    106   {
    107     // Read only data
    108     $filter['check_key'] = pwg_get_session_var('filter_check_key', '');
    109     $filter['categories'] = unserialize(pwg_get_session_var('filter_categories', serialize(array())));
    110     $filter['visible_categories'] = pwg_get_session_var('filter_visible_categories', '');
    111     $filter['visible_images'] = pwg_get_session_var('filter_visible_images', '');
    112   }
    113 
    114   $header_notes[] = l10n_dec('note_filter_day', 'note_filter_days', $user['recent_period']);
    115 }
    116 else
    117 {
    118   $filter['check_key'] = '';
    119   $filter['categories'] = array();
    120   $filter['visible_categories'] = '';
    121   $filter['visible_images'] = '';
    122 }
    123 
    124 pwg_set_session_var('filter_enabled', $filter['enabled']);
    125 pwg_set_session_var('filter_check_key', $filter['check_key']);
    126 pwg_set_session_var('filter_categories', serialize($filter['categories']));
    127 pwg_set_session_var('filter_visible_categories', $filter['visible_categories']);
    128 pwg_set_session_var('filter_visible_images', $filter['visible_images']);
    129 
     114    $header_notes[] = l10n_dec('note_filter_day', 'note_filter_days', $user['recent_period']);
     115  } // end if filter enabled
     116} // end if script_basename ...
    130117?>
  • trunk/include/functions_metadata.inc.php

    r1113 r1711  
    3737  $result = array();
    3838
    39   // Read IPTC data
    40   $iptc = array();
    41 
    4239  $imginfo = array();
    43   getimagesize($filename, $imginfo);
     40  if (false == @getimagesize($filename, $imginfo) )
     41  {
     42    return $result;
     43  }
    4444
    4545  if (isset($imginfo['APP13']))
  • trunk/include/section_init.inc.php

    r1703 r1711  
    279279  }
    280280
    281   if (preg_match('/^flat_recent_cat-(\d+)/', $tokens[$i], $matches))
     281  if ('categories'==$page['section'] and
     282      preg_match('/^flat_recent_cat-(\d+)/', $tokens[$i], $matches))
    282283  {
    283284    // indicate a special list of images
     
    326327  $page['super_order_by'] = true;
    327328}
     329
     330$forbidden = get_sql_condition_FandF(
     331      array
     332        (
     333          'forbidden_categories' => 'category_id',
     334          'visible_categories' => 'category_id',
     335          'visible_images' => 'image_id'
     336        ),
     337      'AND'
     338  );
    328339
    329340// +-----------------------------------------------------------------------+
     
    402413  (isset($page['category']) ? '
    403414  AND uppercats REGEXP \'(^|,)'.$page['category'].'(,|$)\'' : '' ).'
    404 '.get_sql_condition_FandF
    405   (
    406     array
    407       (
    408         'forbidden_categories' => 'category_id',
    409         'visible_categories' => 'category_id',
    410         'visible_images' => 'image_id'
    411       ),
    412     'AND'
    413   ).'
     415'.$forbidden.'
    414416;';
    415417
     
    430432      // Main query
    431433      $query = '
    432 SELECT distinct image_id
     434SELECT DISTINCT(image_id)
    433435  FROM '.IMAGE_CATEGORY_TABLE.'
    434436    INNER JOIN '.IMAGES_TABLE.' ON id = image_id
    435437  WHERE
    436438    '.$where_sql.'
    437 '.get_sql_condition_FandF
    438   (
    439     array
    440       (
    441         'forbidden_categories' => 'category_id',
    442         'visible_categories' => 'category_id',
    443         'visible_images' => 'image_id'
    444       ),
    445     'AND'
    446   ).'
     439'.$forbidden.'
    447440  '.$conf['order_by'].'
    448441;';
     
    459452else
    460453{
    461   $forbidden =
    462     get_sql_condition_FandF
    463     (
    464       array
    465         (
    466           'forbidden_categories' => 'category_id',
    467           'visible_categories' => 'category_id',
    468           'visible_images' => 'image_id'
    469         ),
    470       'AND'
    471     );
    472 
    473454// +-----------------------------------------------------------------------+
    474455// |                            tags section                               |
  • trunk/include/ws_functions.inc.php

    • Property svn:keywords set to Author Date Id Rev URL
    r1698 r1711  
    55// +-----------------------------------------------------------------------+
    66// | branch        : BSF (Best So Far)
    7 // | file          : $URL: svn+ssh://rvelices@svn.gna.org/svn/phpwebgallery/trunk/action.php $
    8 // | last update   : $Date: 2006-12-21 18:49:12 -0500 (Thu, 21 Dec 2006) $
    9 // | last modifier : $Author: rvelices $
    10 // | revision      : $Rev: 1678 $
     7// | file          : $Id$
     8// | last update   : $Date$
     9// | last modifier : $Author$
     10// | revision      : $Rev$
    1111// +-----------------------------------------------------------------------+
    1212// | This program is free software; you can redistribute it and/or modify  |
     
    2929/**
    3030 * returns a "standard" (for our web service) array of sql where clauses that
    31  * filters the images (images table only) 
    32  */ 
     31 * filters the images (images table only)
     32 */
    3333function ws_std_image_sql_filter( $params, $tbl_name='' )
    3434{
     
    8383/**
    8484 * returns a "standard" (for our web service) ORDER BY sql clause for images
    85  */ 
     85 */
    8686function ws_std_image_sql_order( $params, $tbl_name='' )
    8787{
     
    105105        $matches[1][$i] = 'RAND()'; break;
    106106    }
    107     $sortable_fields = array('id', 'file', 'name', 'hit', 'average_rate', 
     107    $sortable_fields = array('id', 'file', 'name', 'hit', 'average_rate',
    108108      'date_creation', 'date_available', 'RAND()' );
    109109    if ( in_array($matches[1][$i], $sortable_fields) )
     
    125125 * returns an array map of urls (thumb/element) for image_row - to be returned
    126126 * in a standard way by different web service methods
    127  */ 
     127 */
    128128function ws_std_get_urls($image_row)
    129129{
    130130  $ret = array(
    131     'tn_url' => get_thumbnail_url($image_row), 
     131    'tn_url' => get_thumbnail_url($image_row),
    132132    'element_url' => get_element_url($image_row)
    133133  );
     
    148148/**
    149149 * returns images per category (wb service method)
    150  */ 
     150 */
    151151function ws_categories_getImages($params, &$service)
    152152{
     
    279279            'count' => count($images)
    280280          ),
    281        WS_XML_CONTENT => new PwgNamedArray($images, 'image', 
     281       WS_XML_CONTENT => new PwgNamedArray($images, 'image',
    282282          array('id', 'tn_url', 'element_url', 'file','width','height','hit') )
    283283      )
     
    291291{
    292292  global $user;
    293  
    294   $query = '
    295 SELECT id, name, uppercats, global_rank,
    296     max_date_last, count_images AS nb_images, count_categories AS nb_categories
    297   FROM '.CATEGORIES_TABLE.'
    298    INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' ON id=cat_id';
    299293
    300294  $where = array();
     
    318312  {
    319313    $where[] = 'status = "public"';
     314    $where[] = 'visible = "true"';
    320315  }
    321316  else
     
    324319  }
    325320
    326   $query .= '
     321  $query = '
     322SELECT id, name, uppercats, global_rank,
     323    max_date_last, count_images AS nb_images, count_categories AS nb_categories
     324  FROM '.CATEGORIES_TABLE.'
     325   INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' ON id=cat_id
    327326  WHERE '. implode('
    328327    AND ', $where);
     
    350349  return array(
    351350      'categories' =>
    352           new PwgNamedArray($cats,'category', 
     351          new PwgNamedArray($cats,'category',
    353352            array('id','url','nb_images','nb_categories','max_date_last')
    354353          )
     
    367366  $query='
    368367SELECT * FROM '.IMAGES_TABLE.'
    369   WHERE id='.$params['image_id'].'
     368  WHERE id='.$params['image_id'].
     369    get_sql_condition_FandF(
     370      array('visible_images' => 'id'),
     371      ' AND'
     372    ).'
    370373LIMIT 1';
     374
    371375  $image_row = mysql_fetch_assoc(pwg_query($query));
    372376  if ($image_row==null)
     
    540544{
    541545  global $user;
    542   $tags = get_available_tags(explode(',', $user['forbidden_categories']));
     546  $tags = get_available_tags();
    543547  if ($params['sort_by_counter'])
    544548  {
     
    632636  {
    633637    $where_clauses = ws_std_image_sql_filter($params);
    634     $where_clauses[] = 'category_id NOT IN ('.$user['forbidden_categories'].')';
     638    $where_clauses[] = get_sql_condition_FandF(
     639        array
     640          (
     641            'forbidden_categories' => 'category_id',
     642            'visible_categories' => 'category_id',
     643            'visible_images' => 'i.id'
     644          ),
     645        '', true
     646      );
    635647    $where_clauses[] = 'id IN ('.implode(',',$image_ids).')';
    636648    $order_by = ws_std_image_sql_order($params);
     
    693705            );
    694706      }
    695       $image['tags'] = new PwgNamedArray($image_tags, 'tag', 
    696               array('id','url_name','url','page_url') 
     707      $image['tags'] = new PwgNamedArray($image_tags, 'tag',
     708              array('id','url_name','url','page_url')
    697709            );
    698710      array_push($images, $image);
     
    708720            'count' => count($images)
    709721          ),
    710        WS_XML_CONTENT => new PwgNamedArray($images, 'image', 
     722       WS_XML_CONTENT => new PwgNamedArray($images, 'image',
    711723          array('id', 'tn_url', 'element_url', 'file','width','height','hit') )
    712724      )
  • trunk/index.php

    r1677 r1711  
    33// | PhpWebGallery - a PHP based picture gallery                           |
    44// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
    5 // | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
     5// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
    66// +-----------------------------------------------------------------------+
    77// | branch        : BSF (Best So Far)
    8 // | file          : $RCSfile$
     8// | file          : $Id$
    99// | last update   : $Date$
    1010// | last modifier : $Author$
     
    117117}
    118118
    119 if (!isset($page['flat_recent_cat']))
     119if (!isset($page['flat_recent_cat']) and 'categories'==$page['section'])
    120120{
    121121  $template->assign_block_vars(
  • trunk/picture.php

    r1703 r1711  
    785785include(PHPWG_ROOT_PATH.'include/picture_rate.inc.php');
    786786include(PHPWG_ROOT_PATH.'include/picture_comment.inc.php');
    787 //if ($metadata_showable and isset($_GET['metadata']))
     787if ($metadata_showable and isset($_GET['metadata']))
    788788{
    789789  include(PHPWG_ROOT_PATH.'include/picture_metadata.inc.php');
Note: See TracChangeset for help on using the changeset viewer.