Changeset 1860


Ignore:
Timestamp:
Feb 27, 2007, 12:52:22 AM (17 years ago)
Author:
rvelices
Message:
  • bug 654: sql error on user comment (since my commit 1849)
  • languages: english corrections + keep lang files sorted by key
  • admin multi view correction: language was not always properly changed
  • refactor function get_computed_categories (with rub's blessing)
Location:
trunk
Files:
7 edited

Legend:

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

    r1723 r1860  
    44// | Copyright (C) 2006-2007 PhpWebGallery Team - http://phpwebgallery.net |
    55// +-----------------------------------------------------------------------+
    6 // | branch        : BSF (Best So Far)
    76// | file          : $Id$
    87// | last update   : $Date$
     
    7675    // Need to compute dats
    7776    $filter['check_key'] = get_filter_check_key();
    78     $filter['categories'] = get_computed_categories($user['id'], $user['forbidden_categories'], true, $filter['recent_period']);
     77    $filter['categories'] = get_computed_categories($user, (int)$filter['recent_period']);
    7978
    8079    $filter['visible_categories'] = implode(',', array_keys($filter['categories']));
  • trunk/include/functions_user.inc.php

    r1854 r1860  
    273273        calculate_permissions($userdata['id'], $userdata['status']);
    274274
    275       update_user_cache_categories($userdata['id'], $userdata['forbidden_categories']);
     275      update_user_cache_categories($userdata);
    276276
    277277      // Set need update are done
     
    534534 * get computed array of categories
    535535 *
    536  * @param int user_id
    537  * @param list user_forbidden_categories
    538  * @param bool filter_enabled
    539  * @param int recent_period
     536 * @param array userdata
     537 * @param int filter_days number of recent days to filter on or null
    540538 * @return array
    541539 */
    542 function get_computed_categories($user_id, $user_forbidden_categories, $filter_enabled, $recent_period = 0)
    543 {
    544   $query = '
    545 SELECT
    546   c.id cat_id,
    547   date_last max_date_last,
    548   nb_images count_images,
    549   global_rank';
    550 
    551   if (!$filter_enabled)
    552   {
    553     $query.= '
    554 FROM '.CATEGORIES_TABLE.' as c';
     540function get_computed_categories($userdata, $filter_days=null)
     541{
     542  $group_by = '';
     543
     544  $query = 'SELECT c.id cat_id, global_rank';
     545  if ( !isset($filter_days) )
     546  {
     547    $query .= ',
     548    date_last cat_date_last,
     549    nb_images cat_nb_images
     550  FROM '.CATEGORIES_TABLE.' as c';
    555551  }
    556552  else
    557553  {
    558554    // Count by date_available to avoid count null
    559     $query.= ',
    560   count(date_available) filtered_count_images,
    561   max(date_available) max_date_available
    562 FROM '.CATEGORIES_TABLE.' as c
     555    $query .= ',
     556    MAX(date_available) cat_date_last,
     557    COUNT(date_available) cat_nb_images
     558  FROM '.CATEGORIES_TABLE.' as c
    563559    LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.category_id = c.id
    564560    LEFT JOIN '.IMAGES_TABLE.' AS i
    565       ON ic.image_id = i.id AND
    566           i.date_available > SUBDATE(CURRENT_DATE,INTERVAL '.$recent_period.' DAY)';
    567   }
    568 
    569   if ($user_forbidden_categories != '')
     561      ON ic.image_id = i.id AND
     562          i.date_available > SUBDATE(CURRENT_DATE,INTERVAL '.$filter_days.' DAY)';
     563    $group_by = 'c.id';
     564  }
     565
     566  if ( !empty($userdata['forbidden_categories']) )
    570567  {
    571568    $query.= '
    572 WHERE
    573   c.id NOT IN ('.$user_forbidden_categories.')';
    574   }
    575 
    576   if ($filter_enabled)
     569  WHERE c.id NOT IN ('.$userdata['forbidden_categories'].')';
     570  }
     571
     572  if ( !empty($group_by) )
    577573  {
    578574    $query.= '
    579 GROUP BY
    580   c.id';
    581   }
    582   $query.= ';';
     575  GROUP BY '.$group_by;
     576  }
    583577
    584578  $result = pwg_query($query);
     
    587581  while ($row = mysql_fetch_assoc($result))
    588582  {
    589     $row['user_id'] = $user_id;
     583    $row['user_id'] = $userdata['id'];
    590584    $row['count_categories'] = 0;
    591     if ($filter_enabled)
    592     {
    593       $row['nb_images'] = $row['filtered_count_images'];
    594       $row['count_images'] = $row['filtered_count_images'];
    595       $row['max_date_last'] = $row['max_date_available'];
    596     }
     585    $row['count_images'] = $row['cat_nb_images'];
     586    $row['max_date_last'] = $row['cat_date_last'];
     587
    597588    $cats += array($row['cat_id'] => $row);
    598589  }
     
    601592  compute_categories_data($cats);
    602593
    603   if ($filter_enabled)
     594  if ( isset($filter_days) )
    604595  {
    605596    $cat_tmp = $cats;
    606597    $cats = array();
    607  
     598
    608599    foreach ($cat_tmp as $category)
    609600    {
     
    612603        // Re-init counters
    613604        $category['count_categories'] = 0;
    614         $category['nb_images'] = $category['filtered_count_images'];
    615         $category['count_images'] = $category['filtered_count_images'];
     605        $category['count_images'] = $category['cat_nb_images'];
     606        // next line for update_cats_with_filtered_data
     607        $category['nb_images'] = $category['cat_nb_images'];
    616608        // Keep category
    617609        $cats[$category['cat_id']] = $category;
    618        
    619610      }
    620611    }
     
    622613    compute_categories_data($cats);
    623614  }
    624 
    625615  return $cats;
    626616}
     
    629619 * update data of user_cache_categories
    630620 *
    631  * @param int user_id
    632  * @param list user_forbidden_categories
    633  * @param bool filter_enabled
     621 * @param array userdata
    634622 * @return null
    635623 */
    636 function update_user_cache_categories($user_id, $user_forbidden_categories)
     624function update_user_cache_categories($userdata)
    637625{
    638626  // delete user cache
    639627  $query = '
    640628DELETE FROM '.USER_CACHE_CATEGORIES_TABLE.'
    641   WHERE user_id = '.$user_id.'
     629  WHERE user_id = '.$userdata['id'].'
    642630;';
    643631  pwg_query($query);
    644632
    645   $cats = get_computed_categories($user_id, $user_forbidden_categories, false);
     633  $cats = get_computed_categories($userdata, null);
    646634
    647635  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
  • trunk/include/picture_comment.inc.php

    r1849 r1860  
    5757  include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
    5858 
    59   $comment_action = insert_user_comment(
    60       $comm, @$_POST['key'], $page['image_id'], $infos
    61     );
     59  $comment_action = insert_user_comment($comm, @$_POST['key'], $infos );
    6260
    6361  switch ($comment_action)
  • trunk/language/en_UK.iso-8859-1/common.lang.php

    r1840 r1860  
    490490$lang['maxwidth'] = 'Maximum width of the pictures';
    491491$lang['maxwidth_error'] = 'Maximum width must be a number superior to 50';
    492 $lang['flat_hint'] = 'flat display elements of categories and sub-categories';
    493 $lang['start_filter_hint'] = 'displays only recent elements';
    494 $lang['stop_filter_hint'] = 'return to display all elements';
    495492$lang['mode_created_hint'] = 'displays a calendar by creation date';
     493$lang['mode_flat_hint'] = 'displays all elements in all sub-categories';
    496494$lang['mode_normal_hint'] = 'return to normal view mode';
    497 $lang['mode_posted_hint'] = 'displays a calendar by date posted';
     495$lang['mode_posted_hint'] = 'displays a calendar by posted date';
    498496$lang['month'][10] = 'October';
    499497$lang['month'][11] = 'November';
     
    521519$lang['no_category'] = 'Home';
    522520$lang['no_rate'] = 'no rate';
     521$lang['note_filter_day'] = 'Only displays elements posted within the last %s day.';
     522$lang['note_filter_days'] = 'Only displays elements posted within the last %s days.';
    523523$lang['password updated'] = 'password updated';
    524524$lang['periods_error'] = 'Recent period must be a positive integer value';
     
    580580$lang['special_categories'] = 'Specials';
    581581$lang['sql_queries_in'] = 'SQL queries in';
     582$lang['start_filter_hint'] = 'displays only recently posted elements';
     583$lang['stop_filter_hint'] = 'return to the display of all elements';
    582584$lang['submit'] = 'Submit';
    583585$lang['the beginning'] = 'the beginning';
     
    612614$lang['w_month'] = 'Month';
    613615$lang['yes'] = 'Yes';
    614 $lang['note_filter_day'] = 'The whole of the elements are filtered in order to diplay the recent elements of less %s day.';
    615 $lang['note_filter_days'] = 'The whole of the elements are filtered in order to diplay the recent elements of less %s days.';
    616616$lang['page_end'] = 'Page bottom';
    617 
    618617?>
  • trunk/language/fr_FR.iso-8859-1/common.lang.php

    r1840 r1860  
    490490$lang['maxwidth'] = 'Largeur maximum des images';
    491491$lang['maxwidth_error'] = 'La largeur des images doit être supérieure à 50';
    492 $lang['flat_hint'] = 'affiche à plat les éléments des catégories et des sous-catégories';
    493 $lang['start_filter_hint'] = 'afficher que les éléments récents';
    494 $lang['stop_filter_hint'] = 'retourner à l\'affichage de tous les éléments';
    495492$lang['mode_created_hint'] = 'afficher un calendrier par date de création';
     493$lang['mode_flat_hint'] = 'afficher à plat les éléments des catégories et des sous-catégories';
    496494$lang['mode_normal_hint'] = 'retourner à la vue normale';
    497495$lang['mode_posted_hint'] = 'afficher un calendrier par date d\'ajout';
     
    521519$lang['no_category'] = 'Accueil';
    522520$lang['no_rate'] = 'pas de note';
     521$lang['note_filter_day'] = 'L\'ensemble des éléments est filtré pour n\'afficher que les éléments récents de moins de %d jour.';
     522$lang['note_filter_days'] = 'L\'ensemble des éléments est filtré pour n\'afficher que les éléments récents de moins de %d jours.';
    523523$lang['password updated'] = 'mot de passe mis à jour';
    524524$lang['periods_error'] = 'La période de nouveauté doit être un entier positif';
     
    558558$lang['search_categories'] = 'Rechercher dans les catégories';
    559559$lang['search_date'] = 'Recherche par date';
    560 $lang['search_date_creation'] = 'Création';
    561560$lang['search_date_from'] = 'Date';
    562561$lang['search_date_to'] = 'Date de fin';
     
    564563$lang['search_descending'] = 'Décroissant';
    565564$lang['search_keywords'] = 'Recherche de mot';
    566 $lang['sear ch_mode_and'] = 'Rechercher tous les mots';
     565$lang['search_mode_and'] = 'Rechercher tous les mots';
    567566$lang['search_mode_or'] = 'Rechercher un des mots';
    568567$lang['search_one_clause_at_least'] = 'Requête vide. Aucun critère fourni.';
     
    581580$lang['special_categories'] = 'Spéciales';
    582581$lang['sql_queries_in'] = 'requêtes SQL en';
     582$lang['start_filter_hint'] = 'afficher que les éléments récents';
     583$lang['stop_filter_hint'] = 'retourner à l\'affichage de tous les éléments';
    583584$lang['submit'] = 'Valider';
    584585$lang['the beginning'] = 'le début';
     
    613614$lang['w_month'] = 'Mois';
    614615$lang['yes'] = 'Oui';
    615 $lang['note_filter_day'] = 'L\'ensemble des éléments est filtré pour n\'afficher que les éléments récents de moins de %d jour.';
    616 $lang['note_filter_days'] = 'L\'ensemble des éléments est filtré pour n\'afficher que les éléments récents de moins de %d jours.';
    617616$lang['page_end'] = 'Bas de page';
    618 
    619617?>
  • trunk/plugins/admin_multi_view/is_admin.inc.php

    r1821 r1860  
    1414  }
    1515  $lang = pwg_get_session_var( 'multiview_lang', '' );
    16   if ( !empty($theme) )
     16  if ( !empty($lang) )
    1717  {
    1818    $user['language'] = $lang;
  • trunk/template/yoga/index.tpl

    r1820 r1860  
    3333
    3434      <!-- BEGIN flat -->
    35       <li><a href="{flat.URL}" title="{lang:flat_hint}" rel="nofollow"><img src="{pwg_root}{themeconf:icon_dir}/flat.png" class="button" alt="{lang:flat_hint}"></a></li>
     35      <li><a href="{flat.URL}" title="{lang:mode_flat_hint}" rel="nofollow"><img src="{pwg_root}{themeconf:icon_dir}/flat.png" class="button" alt="{lang:flat_hint}"></a></li>
    3636      <!-- END flat -->
    3737
Note: See TracChangeset for help on using the changeset viewer.