Ignore:
Timestamp:
Jan 4, 2014, 4:13:08 PM (10 years ago)
Author:
mistic100
Message:

update for Piwigo 2.6

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/SmartAlbums/admin/album.php

    r21358 r26442  
    11<?php
    2 // +-----------------------------------------------------------------------+
    3 // | Piwigo - a PHP based photo gallery                                    |
    4 // +-----------------------------------------------------------------------+
    5 // | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
    6 // | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
    7 // | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
    8 // +-----------------------------------------------------------------------+
    9 // | This program is free software; you can redistribute it and/or modify  |
    10 // | it under the terms of the GNU General Public License as published by  |
    11 // | the Free Software Foundation                                          |
    12 // |                                                                       |
    13 // | This program is distributed in the hope that it will be useful, but   |
    14 // | WITHOUT ANY WARRANTY; without even the implied warranty of            |
    15 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
    16 // | General Public License for more details.                              |
    17 // |                                                                       |
    18 // | You should have received a copy of the GNU General Public License     |
    19 // | along with this program; if not, write to the Free Software           |
    20 // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
    21 // | USA.                                                                  |
    22 // +-----------------------------------------------------------------------+
    23 
    24 if(!defined("PHPWG_ROOT_PATH")) die ("Hacking attempt!");
     2defined('SMART_PATH') or die('Hacking attempt!');
    253
    264// +-----------------------------------------------------------------------+
     
    3311
    3412check_input_parameter('cat_id', $_GET, false, PATTERN_ID);
    35 
    36 $admin_album_base_url = get_root_url().'admin.php?page=album-'.$_GET['cat_id'];
    37 $self_url = SMART_ADMIN.'-album&amp;cat_id='.$_GET['cat_id'];
     13$cat_id = $_GET['cat_id'];
     14
     15$admin_album_base_url = get_root_url().'admin.php?page=album-'.$cat_id;
     16$self_url = SMART_ADMIN.'-album&amp;cat_id='.$cat_id;
    3817
    3918$query = '
    4019SELECT *
    4120  FROM '.CATEGORIES_TABLE.'
    42   WHERE id = '.$_GET['cat_id'].'
     21  WHERE id = '.$cat_id.'
    4322;';
    4423$category = pwg_db_fetch_assoc(pwg_query($query));
     
    4827  die("unknown album");
    4928}
     29
     30// category must be virtual
     31if ($category['dir'] != NULL)
     32{
     33  die("physical album");
     34}
     35
    5036
    5137// +-----------------------------------------------------------------------+
     
    6046
    6147
    62 $cat_id = $_GET['cat_id'];
    63 
    64 // category must be virtual
    65 if ($category['dir'] != NULL)
    66 {
    67   die("physical album");
    68 }
    69 
    7048// +-----------------------------------------------------------------------+
    7149// | Save Filters                                                          |
     
    7856    var_dump($_POST['filters']);
    7957  }
    80  
     58
    8159  // test if it was a Smart Album
    8260  $query = '
    83 SELECT DISTINCT category_id 
    84   FROM '.CATEGORY_FILTERS_TABLE.' 
     61SELECT DISTINCT category_id
     62  FROM '.CATEGORY_FILTERS_TABLE.'
    8563  WHERE category_id = '.$cat_id.'
    8664;';
    8765  $was_smart = pwg_db_num_rows(pwg_query($query));
    88  
     66
    8967  /* this album is no longer a SmartAlbum */
    90   if ( $was_smart AND !isset($_POST['is_smart']) )
     68  if ($was_smart and !isset($_POST['is_smart']))
    9169  {
    9270    pwg_query('DELETE FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$cat_id.' AND smart = true;');
    9371    pwg_query('DELETE FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.';');
     72
    9473    set_random_representant(array($cat_id));
     74
     75    define('SMART_NOT_UPDATE', 1);
    9576    invalidate_user_cache();
    9677  }
    9778  /* no filter selected */
    98   else if ( isset($_POST['is_smart']) AND empty($_POST['filters']) )
    99   {
    100     array_push($page['errors'], l10n('No filter selected'));
     79  else if (isset($_POST['is_smart']) and empty($_POST['filters']))
     80  {
     81    $page['errors'][] = l10n('No filter selected');
    10182  }
    10283  /* everything is fine */
    103   else if ( isset($_POST['is_smart']) )
     84  else if (isset($_POST['is_smart']))
    10485  {
    10586    pwg_query('DELETE FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.';');
    106    
     87
    10788    $inserts = array();
    10889    foreach ($_POST['filters'] as $filter)
     
    11495      }
    11596    }
    116    
     97
    11798    mass_inserts(
    118       CATEGORY_FILTERS_TABLE, 
    119       array('category_id', 'type', 'cond', 'value'), 
     99      CATEGORY_FILTERS_TABLE,
     100      array('category_id', 'type', 'cond', 'value'),
    120101      $inserts,
    121102      array('ignore'=>true)
    122103      );
    123    
     104
    124105    $associated_images = smart_make_associations($cat_id);
    125106    $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', count($associated_images)));
    126    
    127     array_push($page['infos'], sprintf(l10n('%d photos associated to album %s'), count($associated_images), ''));
    128    
     107
     108    $page['infos'][] = l10n('%d photos associated to album %s', count($associated_images), '');
     109
    129110    define('SMART_NOT_UPDATE', 1);
    130111    invalidate_user_cache();
     
    225206/* get filters for this album */
    226207$query = '
    227 SELECT * 
    228   FROM '.CATEGORY_FILTERS_TABLE.' 
     208SELECT *
     209  FROM '.CATEGORY_FILTERS_TABLE.'
    229210  WHERE category_id = '.$cat_id.'
    230   ORDER BY 
    231     type ASC, 
     211  ORDER BY
     212    type ASC,
    232213    cond ASC
    233214;';
     
    250231  WHERE id IN('.$filter['value'].')
    251232;';
    252     $filter['value'] = get_taglist($query); 
    253   }
    254  
     233    $filter['value'] = get_taglist($query);
     234  }
     235
    255236  $template->append('filters', $filter);
    256237}
     
    260241$template->assign('format_options', array(
    261242  'portrait' => l10n('Portrait'),
    262   'square'   => l10n('Square'),
     243  'square'   => l10n('square'),
    263244  'lanscape' => l10n('Landscape'),
    264245  'panorama' => l10n('Panorama'),
     
    274255/* all albums */
    275256$query = '
    276 SELECT 
    277     id, 
    278     name, 
    279     uppercats, 
     257SELECT
     258    id,
     259    name,
     260    uppercats,
    280261    global_rank
    281262  FROM '.CATEGORIES_TABLE.'
     
    303284while ($row = pwg_db_fetch_assoc($result))
    304285{
    305   $widths[] = $row['width'];
    306   $heights[] = $row['height'];
    307   $ratios[] = floor($row['width'] * 100 / $row['height']) / 100;
     286  if ($row['width']>0 && $row['height']>0)
     287  {
     288    $widths[] = $row['width'];
     289    $heights[] = $row['height'];
     290    $ratios[] = floor($row['width'] / $row['height'] * 100) / 100;
     291  }
    308292}
    309293
     
    354338}
    355339
    356 foreach (array_keys($ratio_categories) as $ratio_category)
    357 {
    358   if (count($ratio_categories[$ratio_category]) > 0)
    359   {
    360     $dimensions['ratio_'.$ratio_category] = array(
    361       'min' => $ratio_categories[$ratio_category][0],
    362       'max' => $ratio_categories[$ratio_category][count($ratio_categories[$ratio_category]) - 1]
     340foreach ($ratio_categories as $ratio_name => $ratio_values)
     341{
     342  if (count($ratio_values) > 0)
     343  {
     344    $dimensions['ratio_'.$ratio_name] = array(
     345      'min' => $ratio_values[0],
     346      'max' => array_pop($ratio_values),
    363347      );
    364348  }
     
    371355{
    372356  $query = '
    373 SELECT count(1) 
    374   FROM '.IMAGE_CATEGORY_TABLE.' 
    375   WHERE 
    376     category_id = '.$cat_id.' 
     357SELECT count(1)
     358  FROM '.IMAGE_CATEGORY_TABLE.'
     359  WHERE
     360    category_id = '.$cat_id.'
    377361    AND smart = true
    378362';
     
    396380));
    397381
    398 $template->set_filename('SmartAlbums_content', dirname(__FILE__).'/template/album.tpl');
    399 
    400 ?>
     382$template->set_filename('SmartAlbums_content', realpath(SMART_PATH . 'admin/template/album.tpl'));
Note: See TracChangeset for help on using the changeset viewer.