Changeset 26442


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

update for Piwigo 2.6

Location:
extensions/SmartAlbums
Files:
1 added
3 deleted
14 edited
1 moved

Legend:

Unmodified
Added
Removed
  • extensions/SmartAlbums/admin.php

    r16938 r26442  
    11<?php
    2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     2defined('SMART_PATH') or die('Hacking attempt!');
    33
    44global $conf, $template, $page;
     
    2525
    2626$template->assign_var_from_handle('ADMIN_CONTENT', 'SmartAlbums_content');
    27 
    28 ?>
  • 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'));
  • extensions/SmartAlbums/admin/cat_list.php

    r21658 r26442  
    11<?php
    2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     2defined('SMART_PATH') or die('Hacking attempt!');
    33
    44if (isset($_GET['hide_messages']))
     
    1616$categories = array();
    1717$query = '
    18 SELECT 
     18SELECT
    1919    id,
    2020    name,
     
    5151  if (isset($output_create['error']))
    5252  {
    53     array_push($page['errors'], $output_create['error']);
     53    $page['errors'][] = $output_create['error'];
    5454  }
    5555  else
     
    6969    {
    7070      $associated_images = smart_make_associations($category['id']);
    71       array_push($page['infos'],
    72         sprintf(l10n('%d photos associated to album %s'),
    73           count($associated_images),
    74           '&laquo;'.trigger_event('render_category_name', $category['name'], 'admin_cat_list').'&raquo;'
    75           )
     71
     72      $page['infos'][] = l10n(
     73        '%d photos associated to album %s',
     74        count($associated_images),
     75        '&laquo;'.trigger_event('render_category_name', $category['name'], 'admin_cat_list').'&raquo;'
    7676        );
    7777    }
     
    8080  else
    8181  {
    82     $associated_images = smart_make_associations($_GET['smart_generate']);   
    83     array_push($page['infos'],
    84       sprintf(l10n('%d photos associated to album %s'),
    85         count($associated_images),
    86         '&laquo;'.trigger_event('render_category_name', $categories[ $_GET['smart_generate'] ]['name'], 'admin_cat_list').'&raquo;'
    87         )
     82    $associated_images = smart_make_associations($_GET['smart_generate']);
     83
     84    $page['infos'][] = l10n(
     85      '%d photos associated to album %s',
     86      count($associated_images),
     87      '&laquo;'.trigger_event('render_category_name', $categories[ $_GET['smart_generate'] ]['name'], 'admin_cat_list').'&raquo;'
    8888      );
    8989  }
    90  
     90
    9191  define('SMART_NOT_UPDATE', 1);
    9292  invalidate_user_cache();
     
    100100  'PWG_TOKEN' => get_pwg_token(),
    101101 ));
    102  
     102
    103103// retrieve all existing categories for album creation
    104104$query = '
     
    108108
    109109display_select_cat_wrapper(
    110   $query,
    111   null,
     110  $query, null,
    112111  'category_options'
    113112  );
    114  
     113
    115114if ($conf['SmartAlbums']['show_list_messages'])
    116115{
    117   array_push($page['warnings'], l10n('Only SmartAlbums are displayed on this page'));
    118   array_push($page['warnings'], sprintf(l10n('To order albums please go the main albums <a href="%s">management page</a>'), $base_url.'cat_list'));
    119   array_push($page['warnings'], '<a href="'.$self_url.'&hide_messages">['.l10n('Don\'t show this message again').']</a>');
     116  $page['warnings'][] = l10n('Only SmartAlbums are displayed on this page');
     117  $page['warnings'][] = sprintf(l10n('To order albums please go the main albums <a href="%s">management page</a>'), $base_url.'cat_list');
     118  $page['warnings'][] = '<a href="'.$self_url.'&hide_messages">['.l10n('Don\'t show this message again').']</a>';
    120119}
    121120
     
    125124
    126125$categories_count_images = array();
    127 if ( count($categories) )
     126if (count($categories))
    128127{
    129128  $query = '
    130 SELECT 
    131     category_id, 
     129SELECT
     130    category_id,
    132131    COUNT(image_id) AS total_images
    133132  FROM '.IMAGE_CATEGORY_TABLE.'
     
    154153      'U_SMART'     => $self_url.'&amp;smart_generate='.$category['id'],
    155154    );
    156  
     155
    157156  $template->append('categories', $tpl_cat);
    158157}
    159158
    160 $template->set_filename('SmartAlbums_content', dirname(__FILE__).'/template/cat_list.tpl');
    161 
    162 ?>
     159$template->set_filename('SmartAlbums_content', realpath(SMART_PATH . 'admin/template/cat_list.tpl'));
  • extensions/SmartAlbums/admin/config.php

    r19446 r26442  
    11<?php
    2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     2defined('SMART_PATH') or die('Hacking attempt!');
    33
    4 // Enregistrement de la configuration
    54if (isset($_POST['submit']))
    65{
    7   if ( $_POST['update_timeout'] == 0 or !preg_match('#^[0-9.]+$#', $_POST['update_timeout']) )
     6  if ($_POST['update_timeout'] == 0 or !preg_match('#^[0-9.]+$#', $_POST['update_timeout']))
    87  {
    9     array_push($page['errors'], l10n('Invalid number of days'));
     8    $page['errors'][] = l10n('Invalid number of days');
    109    $_POST['update_timeout'] = $conf['SmartAlbums']['update_timeout'];
    1110  }
    12    
     11
    1312  $conf['SmartAlbums'] = array(
    1413    'show_list_messages' => $conf['SmartAlbums']['show_list_messages'],
     
    1918    'smart_is_forbidden' => isset($_POST['smart_is_forbidden']),
    2019    );
    21  
     20
    2221  conf_update_param('SmartAlbums', serialize($conf['SmartAlbums']));
    23   array_push($page['infos'], l10n('Information data registered in database'));
     22  $page['infos'][] = l10n('Information data registered in database');
    2423}
    2524
    2625$template->assign($conf['SmartAlbums']);
    2726
    28 $template->set_filename('SmartAlbums_content', dirname(__FILE__).'/template/config.tpl');
    29 
    30 ?>
     27$template->set_filename('SmartAlbums_content', realpath(SMART_PATH . 'admin/template/config.tpl'));
  • extensions/SmartAlbums/admin/template/album.tpl

    r19722 r26442  
    1 {combine_css path=$SMART_PATH|@cat:"admin/template/style.css"}
    2 {combine_script id='sprintf' load='footer' path=$SMART_PATH|@cat:"admin/template/sprintf.js"}
     1{combine_css path=$SMART_PATH|cat:'admin/template/style.css'}
    32{include file='include/datepicker.inc.tpl'}
     3{combine_script id='common' load='footer' path='admin/themes/default/js/common.js'}
     4
     5{combine_css path='themes/default/js/plugins/jquery.tokeninput.css'}
    46{combine_script id='jquery.tokeninput' load='footer' require='jquery' path='themes/default/js/plugins/jquery.tokeninput.js'}
    5 {combine_css path="themes/default/js/plugins/chosen.css"}
     7
     8{combine_css path='themes/default/js/plugins/chosen.css'}
    69{combine_script id='jquery.chosen' load='footer' path='themes/default/js/plugins/chosen.jquery.min.js'}
    7 {combine_css path="themes/default/js/ui/theme/jquery.ui.slider.css"}
     10
     11{combine_css path='themes/default/js/ui/theme/jquery.ui.slider.css'}
    812{combine_script id='jquery.ui.slider' require='jquery.ui' load='footer' path='themes/default/js/ui/minified/jquery.ui.slider.min.js'}
    913
    10 {footer_script}{literal}
    11 var count=0;
    12 var limit_count=0;
    13 var level_count=0;
    14 
    15 // MAIN EVENT HANDLERS
    16 $('#addFilter').change(function() {
    17   add_filter($(this).attr('value'));
    18   $(this).attr('value', '-1');
    19 });
    20  
    21 $('#removeFilters').click(function() {
    22   $('#filtersList li').each(function() {
    23     $(this).remove();
     14{*combine_script id='smartalbums.filters' require='common,datepicker.js,jquery.tokeninput,jquery.chosen,jquery.ui.slider'
     15  path=$SMART_PATH|cat:'admin/template/filters.js' load='footer' template=true*}
     16
     17{footer_script require='jquery'}
     18var addFilter = (function($){
     19  var count=0,
     20      limit_count=0,
     21      level_count=0;
     22
     23  // MAIN EVENT HANDLERS
     24  $('#addFilter').change(function() {
     25    if ($(this).val() != -1) {
     26      add_filter($(this).val());
     27      $(this).val(-1);
     28    }
    2429  });
    25  
    26   limit_level=0;
    27   level_count=0;
    28   return false;
    29 });
    30 
    31 $('input[name="is_smart"]').change(function() {
    32   $('#SmartAlbum_options').toggle();
    33   $('input[name="countImages"]').toggle();
    34   $('.count_images_wrapper').toggle();
    35 });
    36 
    37 $('input[name="countImages"]').click(function() {
    38   countImages($("#smart"));
    39   return false;
    40 });
    41 
    42 
    43 // ADD FILTER FUNCTIONS
    44 function add_filter(type, cond, value) {
    45   count++;
    46  
    47   content = $("#filtersRepo #filter_"+type).html().replace(/iiii/g, count);
    48   $block = $(content);
    49   $("#filtersList").append($block);
    50  
    51   if (cond) {
    52     select_cond($block, type, cond);
    53   }
    54  
    55   if (value) {
    56     if (type == "tags") {
    57       $block.find(".filter-value .tagSelect").html(value);
    58     }
    59     else if (type == "album") {
    60       select_options($block, value);
    61     }
    62     else if (type == "level") {
    63       select_options($block, value);
    64     }
    65     else if (type != "dimensions") {
    66       $block.find(".filter-value input").val(value);
    67     }
    68   }
    69  
    70   init_jquery_handlers($block);
    71  
    72   if (type == "dimensions") {
    73     select_dimensions($block, cond, value);
    74   }
    75  
    76   if (type == 'limit') {
    77     limit_count=1;
    78     $("#addFilter option[value='limit']").attr('disabled','disabled');
    79   }
    80   else if (type == 'level') {
    81     level_count=1;
    82     $("#addFilter option[value='level']").attr('disabled','disabled');
    83   }
    84 }
    85 
    86 function select_cond($block, type, cond) {
    87   $block.find(".filter-cond option").removeAttr('selected');
    88   $block.find(".filter-cond option[value='"+cond+"']").attr('selected', 'selected');
    89 }
    90 
    91 function select_dimensions($block, cond, value) {
    92   if (!cond) cond = 'width';
    93  
    94   $block.find(".filter-value span:not(.filter_dimension_info)").hide();
    95   $block.find(".filter-value .dimension_"+cond).show();
    96  
    97   if (value) {
    98     values = value.split(',');
    99   }
    100   else {
    101     values = $block.find(".filter_dimension_"+cond+"_slider").slider("values");
    102   }
    103   $block.find(".filter_dimension_"+cond+"_slider").slider("values", values);
    104 }
    105 
    106 function select_options($block, value) { 
    107   values = value.split(',');
    108   for (j in values) {
    109     $block.find(".filter-value option[value='"+ values[j] +"']").attr('selected', 'selected');
    110   }
    111 }
    112 
    113 
    114 // DECLARE JQUERY PLUGINS AND VERSATILE HANDLERS
    115 function init_jquery_handlers($block) {
    116   // remove filter
    117   $block.find(".removeFilter").click(function() {
    118     type = $(this).next("input").val();
     30
     31  $('#removeFilters').click(function() {
     32    $('#filtersList li').each(function() {
     33      $(this).remove();
     34    });
     35
     36    limit_level=0;
     37    level_count=0;
     38    return false;
     39  });
     40
     41  $('input[name="is_smart"]').change(function() {
     42    $('#SmartAlbum_options').toggle();
     43    $('input[name="countImages"]').toggle();
     44    $('.count_images_wrapper').toggle();
     45  });
     46
     47  $('input[name="countImages"]').click(function() {
     48    countImages($("#smart"));
     49    return false;
     50  });
     51
     52
     53  // ADD FILTER FUNCTIONS
     54  function add_filter(type, cond, value) {
     55    count++;
     56
     57    var content = $("#filtersRepo #filter_"+type).html().replace(/iiii/g, count);
     58    $block = $($.parseHTML(content)).appendTo("#filtersList");
     59
     60    if (cond) {
     61      select_cond($block, type, cond);
     62    }
     63
     64    if (value) {
     65      if (type == "tags") {
     66        $block.find(".filter-value .tagSelect").html(value);
     67      }
     68      else if (type == "album") {
     69        select_options($block, value);
     70      }
     71      else if (type == "level") {
     72        select_options($block, value);
     73      }
     74      else if (type != "dimensions") {
     75        $block.find(".filter-value input").val(value);
     76      }
     77    }
     78
     79    init_jquery_handlers($block);
     80
     81    if (type == "dimensions") {
     82      select_dimensions($block, cond, value);
     83    }
     84
    11985    if (type == 'limit') {
    12086      limit_count=1;
    121       $("#addFilter option[value='limit']").removeAttr('disabled');
     87      $("#addFilter option[value='limit']").attr('disabled','disabled');
    12288    }
    12389    else if (type == 'level') {
    12490      level_count=1;
    125       $("#addFilter option[value='level']").removeAttr('disabled');
    126     }
    127    
    128     $(this).parents('li').remove();
    129     return false;
    130   });
    131 
    132   // date filter
    133   if ($block.hasClass('filter_date')) {
    134     $block.find("input[type='text']").each(function() {
    135       $(this).datepicker({dateFormat:'yy-mm-dd', firstDay:1});
     91      $("#addFilter option[value='level']").attr('disabled','disabled');
     92    }
     93  }
     94
     95  function select_cond($block, type, cond) {
     96    $block.find(".filter-cond option").removeAttr('selected');
     97    $block.find(".filter-cond option[value='"+cond+"']").attr('selected', 'selected');
     98  }
     99
     100  function select_dimensions($block, cond, value) {
     101    console.log($block, cond, value);
     102    cond = cond || 'width';
     103
     104    $block.find(">.filter-value>span").hide();
     105    $block.find(".dimension_"+cond).show();
     106
     107    if (value) {
     108      values = value.split(',');
     109    }
     110    else {
     111      values = $block.find(".filter_dimension_"+cond+"_slider").slider("values");
     112    }
     113    $block.find(".filter_dimension_"+cond+"_slider").slider("values", values);
     114  }
     115
     116  function select_options($block, value) {
     117    values = value.split(',');
     118    for (j in values) {
     119      $block.find(".filter-value option[value='"+ values[j] +"']").attr('selected', 'selected');
     120    }
     121  }
     122
     123
     124  // DECLARE JQUERY PLUGINS AND VERSATILE HANDLERS
     125  function init_jquery_handlers($block) {
     126    // remove filter
     127    $block.find(".removeFilter").click(function() {
     128      type = $(this).next("input").val();
     129      if (type == 'limit') {
     130        limit_count=1;
     131        $("#addFilter option[value='limit']").removeAttr('disabled');
     132      }
     133      else if (type == 'level') {
     134        level_count=1;
     135        $("#addFilter option[value='level']").removeAttr('disabled');
     136      }
     137
     138      $(this).parents('li').remove();
     139      return false;
    136140    });
    137   }
    138 
    139   // tags filter
    140   if ($block.hasClass('filter_tags')) {
    141     $block.find(".tagSelect").tokenInput(
    142     {/literal}
    143       [{foreach from=$all_tags item=tag name=tags}{ldelim}"name":"{$tag.name|@escape:'javascript'}","id":"{$tag.id}"{rdelim}{if !$smarty.foreach.tags.last},{/if}{/foreach}],
    144       {ldelim}
    145         hintText: '{'Type in a search term'|@translate}',
    146         noResultsText: '{'No results'|@translate}',
    147         searchingText: '{'Searching...'|@translate}',
    148         animateDropdown: false,
    149         preventDuplicates: true,
    150         allowCreation: false
    151     {literal}
    152     });
    153   }
    154  
    155   // album filter
    156   if ($block.hasClass('filter_album')) {
    157     $block.find(".albumSelect").chosen();
    158   }
    159  
    160   // dimension filter
    161   if ($block.hasClass('filter_dimensions')) {
    162     $block.find(".filter-cond select").change(function() {
    163       select_dimensions($block, $(this).attr("value"));
    164     });
    165     {/literal}
    166    
    167     $block.find(".filter_dimension_width_slider").slider({ldelim}
    168       range: true,
    169       min: {$dimensions.bounds.min_width},
    170       max: {$dimensions.bounds.max_width},
    171       values: [{$dimensions.bounds.min_width}, {$dimensions.bounds.max_width}],
    172       slide: function(event, ui) {ldelim}
    173         change_dimension_info($block, ui.values, "{'between %d and %d pixels'|@translate}");
    174       },
    175       change: function(event, ui) {ldelim}
    176         change_dimension_info($block, ui.values, "{'between %d and %d pixels'|@translate}");
    177       }
    178     });
    179    
    180     $block.find(".filter_dimension_height_slider").slider({ldelim}
    181       range: true,
    182       min: {$dimensions.bounds.min_height},
    183       max: {$dimensions.bounds.max_height},
    184       values: [{$dimensions.bounds.min_height}, {$dimensions.bounds.max_height}],
    185       slide: function(event, ui) {ldelim}
    186         change_dimension_info($block, ui.values, "{'between %d and %d pixels'|@translate}");
    187       },
    188       change: function(event, ui) {ldelim}
    189         change_dimension_info($block, ui.values, "{'between %d and %d pixels'|@translate}");
    190       }
    191     });
    192    
    193     $block.find(".filter_dimension_ratio_slider").slider({ldelim}
    194       range: true,
    195       step: 0.01,
    196       min: {$dimensions.bounds.min_ratio},
    197       max: {$dimensions.bounds.max_ratio},
    198       values: [{$dimensions.bounds.min_ratio}, {$dimensions.bounds.max_ratio}],
    199       slide: function(event, ui) {ldelim}
    200         change_dimension_info($block, ui.values, "{'between %.2f and %.2f'|@translate}");
    201       },
    202       change: function(event, ui) {ldelim}
    203         change_dimension_info($block, ui.values, "{'between %.2f and %.2f'|@translate}");
    204       }
    205     });
    206     {literal}
    207    
    208     $block.find("a.dimensions-choice").click(function() {
    209       $block.find(".filter_dimension_"+ $(this).data("type") +"_slider").slider("values",
    210         [$(this).data("min"), $(this).data("max")]
     141
     142    // date filter
     143    if ($block.hasClass('filter_date')) {
     144      $block.find("input[type='text']").each(function() {
     145        $(this).datepicker({
     146          dateFormat:'yy-mm-dd',
     147          firstDay:1
     148        });
     149      });
     150    }
     151
     152    // tags filter
     153    if ($block.hasClass('filter_tags')) {
     154      $block.find(".tagSelect").tokenInput(
     155        [{foreach from=$all_tags item=tag name=tags}{ name:"{$tag.name|escape:javascript}", id:"{$tag.id}" }{if !$smarty.foreach.tags.last},{/if}{/foreach}],
     156        {
     157          hintText: '{'Type in a search term'|translate}',
     158          noResultsText: '{'No results'|translate}',
     159          searchingText: '{'Searching...'|translate}',
     160          animateDropdown: false,
     161          preventDuplicates: true,
     162          allowFreeTagging: false
     163        }
    211164      );
    212     });
    213   }
    214 }
    215 
    216 
    217 // GENERAL FUNCTIONS
    218 function change_dimension_info($block, values, text) {
    219   $block.find("input[name$='[value][min]']").val(values[0]);
    220   $block.find("input[name$='[value][max]']").val(values[1]);
    221   $block.find(".filter_dimension_info").html(sprintf(text, values[0], values[1]));
    222 }
    223 
    224 function countImages(form) {
    225 {/literal}
    226   jQuery.post("{$COUNT_SCRIPT_URL}", 'cat_id={$CAT_ID}&'+form.serialize(),
    227 {literal}
    228     function success(data) {
    229       jQuery('.count_images_wrapper').html(data);
    230     }
    231   );
    232 }
    233 
    234 function doBlink(obj,start,finish) {
    235   jQuery(obj).fadeOut(400).fadeIn(400);
    236   if(start!=finish) {
    237     doBlink(obj,start+1,finish);
    238   } else {
    239     jQuery(obj).fadeOut(400);
    240   }
    241 }
    242 {/literal}
    243 
    244 {if isset($new_smart)}doBlink('.new_smart', 0, 3);{/if}
     165    }
     166
     167    // album filter
     168    if ($block.hasClass('filter_album')) {
     169      $block.find(".albumSelect").chosen();
     170    }
     171
     172    // dimension filter
     173    if ($block.hasClass('filter_dimensions')) {
     174      $block.find(".filter-cond select").change(function() {
     175        select_dimensions($block, $(this).val());
     176      });
     177
     178      $block.find(".filter_dimension_width_slider").slider({
     179        range: true,
     180        min: {$dimensions.bounds.min_width},
     181        max: {$dimensions.bounds.max_width},
     182        values: [{$dimensions.bounds.min_width}, {$dimensions.bounds.max_width}],
     183        slide: function(event, ui) {
     184          change_dimension_info($block, ui.values, "{'between %d and %d pixels'|translate}");
     185        },
     186        change: function(event, ui) {
     187          change_dimension_info($block, ui.values, "{'between %d and %d pixels'|translate}");
     188        }
     189      });
     190
     191      $block.find(".filter_dimension_height_slider").slider({
     192        range: true,
     193        min: {$dimensions.bounds.min_height},
     194        max: {$dimensions.bounds.max_height},
     195        values: [{$dimensions.bounds.min_height}, {$dimensions.bounds.max_height}],
     196        slide: function(event, ui) {
     197          change_dimension_info($block, ui.values, "{'between %d and %d pixels'|translate}");
     198        },
     199        change: function(event, ui) {
     200          change_dimension_info($block, ui.values, "{'between %d and %d pixels'|translate}");
     201        }
     202      });
     203
     204      $block.find(".filter_dimension_ratio_slider").slider({
     205        range: true,
     206        step: 0.01,
     207        min: {$dimensions.bounds.min_ratio},
     208        max: {$dimensions.bounds.max_ratio},
     209        values: [{$dimensions.bounds.min_ratio}, {$dimensions.bounds.max_ratio}],
     210        slide: function(event, ui) {
     211          change_dimension_info($block, ui.values, "{'between %.2f and %.2f'|translate}");
     212        },
     213        change: function(event, ui) {
     214          change_dimension_info($block, ui.values, "{'between %.2f and %.2f'|translate}");
     215        }
     216      });
     217
     218      $block.find("a.dimensions-choice").click(function() {
     219        $block.find(".filter_dimension_"+ $(this).data("type") +"_slider").slider("values",
     220          [$(this).data("min"), $(this).data("max")]
     221        );
     222      });
     223    }
     224  }
     225
     226
     227  // GENERAL FUNCTIONS
     228  function change_dimension_info($block, values, text) {
     229    $block.find("input[name$='[value][min]']").val(values[0]);
     230    $block.find("input[name$='[value][max]']").val(values[1]);
     231    $block.find(".filter_dimension_info").html(sprintf(text, values[0], values[1]));
     232  }
     233
     234  function countImages(form) {
     235    jQuery.post("{$COUNT_SCRIPT_URL}", 'cat_id={$CAT_ID}&'+form.serialize(),
     236      function success(data) {
     237        jQuery('.count_images_wrapper').html(data);
     238      }
     239    );
     240  }
     241
     242
     243  {if isset($new_smart)}
     244  function doBlink(obj,start,finish) {
     245    jQuery(obj).fadeOut(400).fadeIn(400);
     246    if(start!=finish) {
     247      doBlink(obj,start+1,finish);
     248    }
     249    else {
     250      jQuery(obj).fadeOut(400);
     251    }
     252  }
     253
     254  doBlink('.new_smart', 0, 3);
     255  {/if}
     256
     257  return add_filter; // expose add_filter method
     258}(jQuery));
    245259{/footer_script}
    246260
    247261
    248262<div class="titrePage">
    249   <h2><span style="letter-spacing:0">{$CATEGORIES_NAV}</span> &#8250; {'Edit album'|@translate} [SmartAlbum]</h2>
     263  <h2><span style="letter-spacing:0">{$CATEGORIES_NAV}</span> &#8250; {'Edit album'|translate} [SmartAlbum]</h2>
    250264</div>
    251265
    252266<noscript>
    253 <div class="errors"><ul><li>JavaScript required!</li></ul></div>
     267  <div class="errors"><ul><li>JavaScript required!</li></ul></div>
    254268</noscript>
    255269
    256270<div id="batchManagerGlobal">
    257271<form action="{$F_ACTION}" method="POST" id="smart">
    258   <p style="text-align:left;"><label><input type="checkbox" name="is_smart" {if isset($filters) OR isset($new_smart)}checked="checked"{/if}/> {'This album is a SmartAlbum'|@translate}</label></p>
     272  <p style="text-align:left;"><label><input type="checkbox" name="is_smart" {if isset($filters) OR isset($new_smart)}checked="checked"{/if}/> {'This album is a SmartAlbum'|translate}</label></p>
    259273
    260274  <fieldset id="SmartAlbum_options" style="margin-top:1em;{if !isset($filters) AND !isset($new_smart)}display:none;{/if}">
    261     <legend>{'Filters'|@translate}</legend>
    262      
     275    <legend>{'Filters'|translate}</legend>
     276
    263277    <ul id="filtersList">
    264278    {foreach from=$filters item=filter}{strip}
     
    268282        {assign var='value' value=$filter.value}
    269283      {/if}
    270      
     284
    271285      {if $filter.type == 'limit'}
    272286        {footer_script}
     
    280294        {/footer_script}
    281295      {/if}
    282      
    283       {footer_script}add_filter('{$filter.type}', '{$filter.cond}', '{$value|escape:javascript}');{/footer_script}
     296
     297      {footer_script}addFilter('{$filter.type}', '{$filter.cond}', '{$value|escape:javascript}');{/footer_script}
    284298    {/strip}{/foreach}
    285299    </ul>
    286    
     300
    287301    <div>
    288       <b>{'Mode'|@translate} :</b>
     302      <b>{'Mode'|translate} :</b>
    289303      <label><input type="radio" name="filters[0][value]" value="and" {if $filter_mode=='and'}checked="checked"{/if}> AND</label>
    290304      <label><input type="radio" name="filters[0][value]" value="or" {if $filter_mode=='or'}checked="checked"{/if}> OR</label>
     
    292306      <input type="hidden" name="filters[0][cond]" value="mode">
    293307    </div>
    294    
     308
    295309    <p class="actionButtons">
    296310      <select id="addFilter">
    297         <option value="-1">{'Add a filter'|@translate}</option>
     311        <option value="-1">{'Add a filter'|translate}</option>
    298312        <option disabled="disabled">------------------</option>
    299         <option value="tags">{'Tags'|@translate}</option>
    300         <option value="date">{'Date'|@translate}</option>
    301         <option value="name">{'Photo name'|@translate}</option>
    302         <option value="album">{'Album'|@translate}</option>
    303         <option value="dimensions">{'Dimensions'|@translate}</option>
    304         <option value="author">{'Author'|@translate}</option>
    305         <option value="hit">{'Hits'|@translate}</option>
    306         <option value="rating_score">{'Rating score'|@translate}</option>
    307         <option value="level">{'Privacy level'|@translate}</option>
    308         <option value="limit">{'Max. number of photos'|@translate}</option>
    309       </select>
    310       <a id="removeFilters">{'Remove all filters'|@translate}</a>
    311       {if isset($new_smart)}<span class="new_smart">{'Add filters here'|@translate}</span>{/if}
     313        <option value="tags">{'Tags'|translate}</option>
     314        <option value="date">{'Date'|translate}</option>
     315        <option value="name">{'Photo name'|translate}</option>
     316        <option value="album">{'Album'|translate}</option>
     317        <option value="dimensions">{'Dimensions'|translate}</option>
     318        <option value="author">{'Author'|translate}</option>
     319        <option value="hit">{'Hits'|translate}</option>
     320        <option value="rating_score">{'Rating score'|translate}</option>
     321        <option value="level">{'Privacy level'|translate}</option>
     322        <option value="limit">{'Max. number of photos'|translate}</option>
     323      </select>
     324      <a id="removeFilters">{'Remove all filters'|translate}</a>
     325      {if isset($new_smart)}<span class="new_smart">{'Add filters here'|translate}</span>{/if}
    312326    </p>
    313327  </fieldset>
    314  
     328
    315329  <p class="actionButtons" id="applyFilterBlock">
    316     <input class="submit" type="submit" value="{'Submit'|@translate}" name="submitFilters"/>
    317     <input class="submit" type="submit" value="{'Count'|@translate}" name="countImages" {if !isset($filters) AND !isset($new_smart)}style="display:none;"{/if}/>
     330    <input class="submit" type="submit" value="{'Submit'|translate}" name="submitFilters"/>
     331    <input class="submit" type="submit" value="{'Count'|translate}" name="countImages" {if !isset($filters) AND !isset($new_smart)}style="display:none;"{/if}/>
    318332    <span class="count_images_wrapper" {if !isset($filters) AND !isset($new_smart)}style="display:none;"{/if}><span class="count_image">{$IMAGE_COUNT}</span></span>
    319333  </p>
     
    327341  <li id="filter_iiii" class="filter_tags">
    328342    <span class="filter-title">
    329       <a href="#" class="removeFilter" title="{'remove this filter'|@translate}"><span>[x]</span></a>
     343      <a href="#" class="removeFilter" title="{'remove this filter'|translate}"><span>[x]</span></a>
    330344      <input type="hidden" name="filters[iiii][type]" value="tags"/>
    331345      {$options.tags.name}
    332346    </span>
    333    
     347
    334348    <span class="filter-cond">
    335349      <select name="filters[iiii][cond]">
     
    337351      </select>
    338352    </span>
    339    
     353
    340354    <span class="filter-value">
    341355      <select name="filters[iiii][value]" class="tagSelect">
     
    344358  </li>
    345359  </div>
    346  
     360
    347361  <!-- date -->
    348362  <div id="filter_date">
    349363  <li id="filter_iiii" class="filter_date">
    350364    <span class="filter-title">
    351       <a href="#" class="removeFilter" title="{'remove this filter'|@translate}"><span>[x]</span></a>
     365      <a href="#" class="removeFilter" title="{'remove this filter'|translate}"><span>[x]</span></a>
    352366      <input type="hidden" name="filters[iiii][type]" value="date"/>
    353367      {$options.date.name}
    354368    </span>
    355    
     369
    356370    <span class="filter-cond">
    357371      <select name="filters[iiii][cond]">
     
    359373      </select>
    360374    </span>
    361    
     375
    362376    <span class="filter-value">
    363377      <input type="text" name="filters[iiii][value]" size="30"/>
     
    365379  </li>
    366380  </div>
    367  
     381
    368382  <!-- name -->
    369383  <div id="filter_name">
    370384  <li id="filter_iiii" class="filter_name">
    371385    <span class="filter-title">
    372       <a href="#" class="removeFilter" title="{'remove this filter'|@translate}"><span>[x]</span></a>
     386      <a href="#" class="removeFilter" title="{'remove this filter'|translate}"><span>[x]</span></a>
    373387      <input type="hidden" name="filters[iiii][type]" value="name"/>
    374388      {$options.name.name}
    375389    </span>
    376    
     390
    377391    <span class="filter-cond">
    378392      <select name="filters[iiii][cond]">
     
    380394      </select>
    381395    </span>
    382    
     396
    383397    <span class="filter-value">
    384398      <input type="text" name="filters[iiii][value]" size="30"/>
     
    386400  </li>
    387401  </div>
    388  
     402
    389403  <!-- album -->
    390404  <div id="filter_album">
    391405  <li id="filter_iiii" class="filter_album">
    392406    <span class="filter-title">
    393       <a href="#" class="removeFilter" title="{'remove this filter'|@translate}"><span>[x]</span></a>
     407      <a href="#" class="removeFilter" title="{'remove this filter'|translate}"><span>[x]</span></a>
    394408      <input type="hidden" name="filters[iiii][type]" value="album"/>
    395409      {$options.album.name}
    396410    </span>
    397    
     411
    398412    <span class="filter-cond">
    399413      <select name="filters[iiii][cond]">
     
    401415      </select>
    402416    </span>
    403    
    404     <span class="filter-value">
    405       <select name="filters[iiii][value][]" class="albumSelect" multiple="multiple" data-placeholder="{'Select albums...'|@translate}">
     417
     418    <span class="filter-value">
     419      <select name="filters[iiii][value][]" class="albumSelect" multiple="multiple" data-placeholder="{'Select albums...'|translate}">
    406420        {html_options options=$all_albums}
    407421      </select>
     
    409423  </li>
    410424  </div>
    411  
     425
    412426  <!-- dimensions -->
    413427  <div id="filter_dimensions">
    414428  <li id="filter_iiii" class="filter_dimensions">
    415429    <span class="filter-title">
    416       <a href="#" class="removeFilter" title="{'remove this filter'|@translate}"><span>[x]</span></a>
     430      <a href="#" class="removeFilter" title="{'remove this filter'|translate}"><span>[x]</span></a>
    417431      <input type="hidden" name="filters[iiii][type]" value="dimensions"/>
    418432      {$options.dimensions.name}
     
    427441    <span class="filter-value">
    428442      <span class="dimension_width">
    429       <span class="filter_dimension_info"></span>
    430         | <a class="dimensions-choice" data-type="width" data-min="{$dimensions.bounds.min_width}" data-max="{$dimensions.bounds.max_width}">{'Reset'|@translate}</a>
    431         <div class="filter_dimension_width_slider"></div>
     443        <span class="filter_dimension_info"></span>
     444          | <a class="dimensions-choice" data-type="width" data-min="{$dimensions.bounds.min_width}" data-max="{$dimensions.bounds.max_width}">{'Reset'|translate}</a>
     445          <div class="filter_dimension_width_slider"></div>
    432446      </span>
    433447
    434       <span class="filter-value dimension_height">
    435       <span class="filter_dimension_info"></span>
    436         | <a class="dimensions-choice" data-type="height" data-min="{$dimensions.bounds.min_height}" data-max="{$dimensions.bounds.max_height}">{'Reset'|@translate}</a>
    437         <div class="filter_dimension_height_slider"></div>
     448      <span class="dimension_height">
     449        <span class="filter_dimension_info"></span>
     450          | <a class="dimensions-choice" data-type="height" data-min="{$dimensions.bounds.min_height}" data-max="{$dimensions.bounds.max_height}">{'Reset'|translate}</a>
     451          <div class="filter_dimension_height_slider"></div>
    438452      </span>
    439453
    440       <span class="filter-value dimension_ratio">
    441       <span class="filter_dimension_info"></span>
    442 {if isset($dimensions.ratio_portrait)}
    443         | <a class="dimensions-choice" data-type="ratio" data-min="{$dimensions.ratio_portrait.min}" data-max="{$dimensions.ratio_portrait.max}">{'Portrait'|@translate}</a>
    444 {/if}
    445 {if isset($dimensions.ratio_square)}
    446         | <a class="dimensions-choice" data-type="ratio" data-min="{$dimensions.ratio_square.min}" data-max="{$dimensions.ratio_square.max}">{'square'|@translate}</a>
    447 {/if}
    448 {if isset($dimensions.ratio_landscape)}
    449         | <a class="dimensions-choice" data-type="ratio" data-min="{$dimensions.ratio_landscape.min}" data-max="{$dimensions.ratio_landscape.max}">{'Landscape'|@translate}</a>
    450 {/if}
    451 {if isset($dimensions.ratio_panorama)}
    452         | <a class="dimensions-choice" data-type="ratio" data-min="{$dimensions.ratio_panorama.min}" data-max="{$dimensions.ratio_panorama.max}">{'Panorama'|@translate}</a>
    453 {/if}
    454         | <a class="dimensions-choice" data-type="ratio" data-min="{$dimensions.bounds.min_ratio}" data-max="{$dimensions.bounds.max_ratio}">{'Reset'|@translate}</a>
    455         <div class="filter_dimension_ratio_slider"></div>
     454      <span class="dimension_ratio">
     455        <span class="filter_dimension_info"></span>
     456        {if isset($dimensions.ratio_portrait)}
     457          | <a class="dimensions-choice" data-type="ratio" data-min="{$dimensions.ratio_portrait.min}" data-max="{$dimensions.ratio_portrait.max}">{'Portrait'|translate}</a>
     458        {/if}
     459        {if isset($dimensions.ratio_square)}
     460          | <a class="dimensions-choice" data-type="ratio" data-min="{$dimensions.ratio_square.min}" data-max="{$dimensions.ratio_square.max}">{'square'|translate}</a>
     461        {/if}
     462        {if isset($dimensions.ratio_landscape)}
     463          | <a class="dimensions-choice" data-type="ratio" data-min="{$dimensions.ratio_landscape.min}" data-max="{$dimensions.ratio_landscape.max}">{'Landscape'|translate}</a>
     464        {/if}
     465        {if isset($dimensions.ratio_panorama)}
     466          | <a class="dimensions-choice" data-type="ratio" data-min="{$dimensions.ratio_panorama.min}" data-max="{$dimensions.ratio_panorama.max}">{'Panorama'|translate}</a>
     467        {/if}
     468          | <a class="dimensions-choice" data-type="ratio" data-min="{$dimensions.bounds.min_ratio}" data-max="{$dimensions.bounds.max_ratio}">{'Reset'|translate}</a>
     469          <div class="filter_dimension_ratio_slider"></div>
    456470      </span>
    457471    </span>
     
    461475  </li>
    462476  </div>
    463  
     477
    464478  <!-- author -->
    465479  <div id="filter_author">
    466480  <li id="filter_iiii" class="filter_author">
    467481    <span class="filter-title">
    468       <a href="#" class="removeFilter" title="{'remove this filter'|@translate}"><span>[x]</span></a>
     482      <a href="#" class="removeFilter" title="{'remove this filter'|translate}"><span>[x]</span></a>
    469483      <input type="hidden" name="filters[iiii][type]" value="author"/>
    470484      {$options.author.name}
    471485    </span>
    472    
     486
    473487    <span class="filter-cond">
    474488      <select name="filters[iiii][cond]">
     
    476490      </select>
    477491    </span>
    478    
     492
    479493    <span class="filter-value">
    480494      <input type="text" name="filters[iiii][value]" size="30"/>
    481       <i>{'For "Is (not) in", separate each author by a comma'|@translate}</i>
    482     </span>
    483   </li>
    484   </div>
    485  
     495      <i>{'For "Is (not) in", separate each author by a comma'|translate}</i>
     496    </span>
     497  </li>
     498  </div>
     499
    486500  <!-- hit -->
    487501  <div id="filter_hit">
    488502  <li id="filter_iiii" class="filter_hit">
    489503    <span class="filter-title">
    490       <a href="#" class="removeFilter" title="{'remove this filter'|@translate}"><span>[x]</span></a>
     504      <a href="#" class="removeFilter" title="{'remove this filter'|translate}"><span>[x]</span></a>
    491505      <input type="hidden" name="filters[iiii][type]" value="hit"/>
    492506      {$options.hit.name}
    493507    </span>
    494    
     508
    495509    <span class="filter-cond">
    496510      <select name="filters[iiii][cond]">
     
    498512      </select>
    499513    </span>
    500    
     514
    501515    <span class="filter-value">
    502516      <input type="text" name="filters[iiii][value]" size="5"/>
     
    504518  </li>
    505519  </div>
    506  
     520
    507521  <!-- rating_score -->
    508522  <div id="filter_rating_score">
    509523  <li id="filter_iiii" class="filter_rating_score">
    510524    <span class="filter-title">
    511       <a href="#" class="removeFilter" title="{'remove this filter'|@translate}"><span>[x]</span></a>
     525      <a href="#" class="removeFilter" title="{'remove this filter'|translate}"><span>[x]</span></a>
    512526      <input type="hidden" name="filters[iiii][type]" value="rating_score"/>
    513527      {$options.rating_score.name}
    514528    </span>
    515    
     529
    516530    <span class="filter-cond">
    517531      <select name="filters[iiii][cond]">
     
    519533      </select>
    520534    </span>
    521    
     535
    522536    <span class="filter-value">
    523537      <input type="text" name="filters[iiii][value]" size="5"/>
     
    525539  </li>
    526540  </div>
    527  
     541
    528542  <!-- level -->
    529543  <div id="filter_level">
    530544  <li id="filter_iiii" class="filter_level">
    531545    <span class="filter-title">
    532       <a href="#" class="removeFilter" title="{'remove this filter'|@translate}"><span>[x]</span></a>
     546      <a href="#" class="removeFilter" title="{'remove this filter'|translate}"><span>[x]</span></a>
    533547      <input type="hidden" name="filters[iiii][type]" value="level"/>
    534548      {$options.level.name}
    535549    </span>
    536    
     550
    537551    <input type="hidden" name="filters[iiii][cond]" value="level"/>
    538    
     552
    539553    <span class="filter-value">
    540554      <select name="filters[iiii][value]">
     
    544558  </li>
    545559  </div>
    546  
     560
    547561  <!-- limit -->
    548562  <div id="filter_limit">
    549563  <li id="filter_iiii" class="filter_limit">
    550564    <span class="filter-title">
    551       <a href="#" class="removeFilter" title="{'remove this filter'|@translate}"><span>[x]</span></a>
     565      <a href="#" class="removeFilter" title="{'remove this filter'|translate}"><span>[x]</span></a>
    552566      <input type="hidden" name="filters[iiii][type]" value="limit"/>
    553567      {$options.limit.name}
    554568    </span>
    555    
     569
    556570    <input type="hidden" name="filters[iiii][cond]" value="limit"/>
    557    
     571
    558572    <span class="filter-value">
    559573      <input type="text" name="filters[iiii][value]" size="5"/>
  • extensions/SmartAlbums/admin/template/cat_list.tpl

    r19446 r26442  
    1 {footer_script require='jquery.ui.sortable'}{literal}
    2 jQuery(document).ready(function(){
    3   jQuery("#addAlbumOpen").click(function(){
    4     jQuery("#createAlbum").toggle();
    5     jQuery("input[name=virtual_name]").focus();
    6     jQuery("#autoOrder").hide();
    7   });
     1{footer_script require='jquery'}
     2jQuery("#addAlbumOpen").click(function(){
     3  jQuery("#createAlbum").toggle();
     4  jQuery("input[name=virtual_name]").focus();
     5  jQuery("#autoOrder").hide();
     6});
    87
    9   jQuery("#addAlbumClose").click(function(){
    10     jQuery("#createAlbum").hide();
    11   });
     8jQuery("#addAlbumClose").click(function(){
     9  jQuery("#createAlbum").hide();
    1210});
    13 {/literal}{/footer_script}
     11{/footer_script}
    1412
    15 {* è *}
    1613
    1714<div class="titrePage">
     
    2421<p class="showCreateAlbum">
    2522  <span id="notManualOrder">
    26     <a href="#" id="addAlbumOpen">{'create a new SmartAlbum'|@translate}</a>
    27     | <a href="{$F_ACTION}&amp;smart_generate=all">{'Regenerate photos list of all SmartAlbums'|@translate}</a>
     23    <a href="#" id="addAlbumOpen">{'create a new SmartAlbum'|translate}</a>
     24    | <a href="{$F_ACTION}&amp;smart_generate=all">{'Regenerate photos list of all SmartAlbums'|translate}</a>
    2825  </span>
    2926</p>
    3027
    3128<fieldset id="createAlbum" style="display:none;">
    32   <legend>{'create a new SmartAlbum'|@translate}</legend>
     29  <legend>{'create a new SmartAlbum'|translate}</legend>
    3330  <input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
    3431
    3532  <p>
    36     <strong>{'Album name'|@translate}</strong> :
     33    <strong>{'Album name'|translate}</strong> :
    3734    <input type="text" name="virtual_name">
    3835  </p>
    3936  <p>
    40     <strong>{'Parent album'|@translate}</strong>  :
     37    <strong>{'Parent album'|translate}</strong>  :
    4138    <select class="categoryDropDown" name="parent_id">
    4239      <option value="0">------------</option>
     
    4542  </p>
    4643  <p class="actionButtons">
    47     <input class="submit" type="submit" value="{'Create'|@translate}" name="submitAdd">
    48     <a href="#" id="addAlbumClose">{'Cancel'|@translate}</a>
     44    <input class="submit" type="submit" value="{'Create'|translate}" name="submitAdd">
     45    <a href="#" id="addAlbumClose">{'Cancel'|translate}</a>
    4946  </p>
    5047</fieldset>
     
    5855      <!-- category {$category.ID} -->
    5956      <p class="albumTitle">
    60         <strong><a href="{$category.U_CHILDREN}" title="{'manage sub-albums'|@translate}">{$category.NAME}</a></strong>
     57        <strong><a href="{$category.U_CHILDREN}" title="{'manage sub-albums'|translate}">{$category.NAME}</a></strong>
    6158        <img src="{$SMART_PATH}admin/template/lightning.png">
    62         {'%d photos'|@translate|sprintf:$category.IMG_COUNT}
     59        {'%d photos'|translate:$category.IMG_COUNT}
    6360      </p>
    6461
    6562      <p class="albumActions">
    66         <a href="{$category.U_EDIT}">{'Edit'|@translate}</a>
    67         | <a href="{$category.U_SMART}" title="{$category.LAST_UPDATE}">{'Regenerate photos list of this SmartAlbum'|@translate}</a>
     63        <a href="{$category.U_EDIT}">{'Edit'|translate}</a>
     64        | <a href="{$category.U_SMART}" title="{$category.LAST_UPDATE}">{'Regenerate photos list of this SmartAlbum'|translate}</a>
    6865        {if isset($category.U_DELETE) }
    69         | <a href="{$category.U_DELETE}" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');">{'delete album'|@translate}</a>
     66        | <a href="{$category.U_DELETE}" onclick="return confirm('{'Are you sure?'|translate|escape:javascript}');">{'delete album'|translate}</a>
    7067        {/if}
    7168        {if cat_admin_access($category.ID)}
    72         | <a href="{$category.U_JUMPTO}">{'jump to album'|@translate} ?</a>
     69        | <a href="{$category.U_JUMPTO}">{'jump to album'|translate} ?</a>
    7370        {/if}
    7471      </p>
  • extensions/SmartAlbums/admin/template/config.tpl

    r19446 r26442  
    1 {html_head}{literal}
    2 <style type="text/css">
    3 .showInfo {
    4   position:static;
    5   display:inline-block;
    6   padding:1px 6px !important;
    7   width:auto;
    8   font-size:0.8em;
    9   line-height:1.2em;
    10 }
    11 </style>
    12 {/literal}{/html_head}
     1{footer_script require="jquery"}
     2jQuery(".showInfo").tipTip({
     3  delay: 0,
     4  fadeIn: 200,
     5  fadeOut: 200,
     6  maxWidth: '300px',
     7  defaultPosition:"right"
     8});
     9{/footer_script}
    1310
    14 {footer_script require="jquery"}
    15 jQuery(".showInfo").tipTip({ldelim}
    16     delay: 0,
    17     fadeIn: 200,
    18     fadeOut: 200,
    19     maxWidth: '300px',
    20     defaultPosition:"right"
    21   });
    22 {/footer_script}
    2311
    2412<div class="titrePage">
     
    2614</div>
    2715
    28 <form method="post" action="" class="properties"> 
     16<form method="post" action="" class="properties">
    2917  <fieldset id="commentsConf">
    3018    <ul>
    3119      <li>
    3220        <label>
    33           <input type="checkbox" name="update_on_upload" value="true" {if $update_on_upload}checked="checked"{/if}/>
    34           <b>{'Update albums on file upload'|@translate}</b>
    35           <a class="showInfo" title="{'can cause slowdowns'|@translate}">i</a>
    36         </label>
     21          <input type="checkbox" name="update_on_date" value="true" {if $update_on_date}checked="checked"{/if}/>
     22          {assign var=input value='</label><input type="text" name="update_timeout" size="2" value="'|cat:$update_timeout|cat:'"/>'}
     23          <b>{'Update albums every %s days'|translate:$input}</b>
     24        <!-- label -->
    3725      </li>
    3826      <li>
    3927        <label>
    40           <input type="checkbox" name="update_on_date" value="true" {if $update_on_date}checked="checked"{/if}/>
    41           {assign var=input value='<input type="text" name="update_timeout" size="2" value="'|cat:$update_timeout|cat:'"/>'}
    42           <b>{'Update albums every %s days'|@translate|sprintf:$input}</b>
     28          <input type="checkbox" name="update_on_upload" value="true" {if $update_on_upload}checked="checked"{/if}/>
     29          <b>{'Update albums on file upload'|translate}</b>
     30          <a class="icon-info-circled-1 showInfo" title="{'can cause slowdowns'|translate}"></a>
    4331        </label>
    4432      </li>
     
    4634        <label>
    4735          <input type="checkbox" name="smart_is_forbidden" value="true" {if $smart_is_forbidden}checked="checked"{/if}/>
    48           <b>{'Exclude SmartAlbums from permissions management'|@translate}</b>
    49           <a class="showInfo" title="{'SmartAlbums are considered private for everyone, and a user can see it\'s content only if available in another album he has access to.'|@translate}">i</a>
     36          <b>{'Exclude SmartAlbums from permissions management'|translate}</b>
     37          <a class="icon-info-circled-1 showInfo" title="{'SmartAlbums are considered private for everyone, and a user can see it\'s content only if available in another album he has access to.'|translate}"></a>
    5038        </label>
    5139      </li>
    5240    </ul>
    5341  </fieldset>
    54    
    55   <p class="formButtons"><input class="submit" type="submit" value="{'Submit'|@translate}" name="submit" /></p>
     42
     43  <p class="formButtons"><input class="submit" type="submit" value="{'Submit'|translate}" name="submit" /></p>
    5644</form>
  • extensions/SmartAlbums/admin/template/style.css

    r19722 r26442  
    88}
    99#batchManagerGlobal #filtersList li.token-input-input-token {
    10   margin-bottom:-3px !important; 
     10  margin-bottom:-3px !important;
    1111}
    1212
    1313#batchManagerGlobal .filter_dimensions .ui-slider-horizontal {
    14     margin: 5px 0 3px 0;
    15     width: 500px;
     14  margin:5px 0 3px 0;
     15  width:400px;
    1616}
    1717
  • extensions/SmartAlbums/include/count_images.php

    r17821 r26442  
    1010include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
    1111
    12 if (!is_admin()) die('Hacking attempt!');
     12is_admin() or die('Hacking attempt!');
    1313
    1414
     
    1818  $page['errors'] = array();
    1919  $limit_is_set = false;
    20  
     20
    2121  foreach ($_POST['filters'] as $filter)
    2222  {
    2323    if (($filter = smart_check_filter($filter)) != false)
    2424    {
    25       array_push($filters, $filter);
     25      $filters[] = $filter;
    2626    }
    2727    else
    2828    {
    29       echo '<span class="filter_error">'.$page['errors'][ count($page['errors'])-1 ].'</span>';
     29      echo '<span class="filter_error">'. array_pop($page['errors']) .'</span>';
    3030      exit;
    3131    }
  • extensions/SmartAlbums/include/events_admin.inc.php

    r24342 r26442  
    11<?php
    2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     2defined('SMART_PATH') or die('Hacking attempt!');
     3
     4/**
     5 * new tab on album properties page
     6 */
     7function smart_tab($sheets, $id)
     8{
     9  if ($id == 'album')
     10  {
     11    global $category;
     12
     13    if ($category['dir'] == null)
     14    {
     15      $sheets['smartalbum'] = array(
     16        'caption' => 'SmartAlbum',
     17        'url' => SMART_ADMIN.'-album&amp;cat_id='.$_GET['cat_id'],
     18        );
     19    }
     20  }
     21
     22  return $sheets;
     23}
     24
     25/**
     26 * admin plugins menu link
     27 */
     28function smart_admin_menu($menu)
     29{
     30  $menu[] = array(
     31    'NAME' => 'SmartAlbums',
     32    'URL' => SMART_ADMIN,
     33    );
     34  return $menu;
     35}
     36
    337/**
    438 * Add a link into categories list to regenerate associations
    539 */
    6 $smart_count = 0;
    7 
    840function smart_cat_list()
    941{
    10   global $template, $page, $smart_count;
     42  global $template, $page;
     43
     44  if (!isset($smart_count))
     45  {
     46    $smart_count = 0;
     47  }
    1148
    1249  $self_url = get_root_url().'admin.php?page=cat_list'.(isset($_GET['parent_id']) ? '&amp;parent_id='.$_GET['parent_id'] : null);
    13  
     50
    1451  /* get categories with smart filters */
    1552  $query = '
    16 SELECT DISTINCT id, name 
     53SELECT DISTINCT id, name
    1754  FROM '.CATEGORIES_TABLE.' AS c
    1855    INNER JOIN '.CATEGORY_FILTERS_TABLE.' AS cf
    19       ON c.id = cf.category_id';
     56    ON c.id = cf.category_id';
    2057  if (!isset($_GET['parent_id']))
    2158  {
     
    3067  $query .= '
    3168;';
    32  
    33   $smart_cats = hash_from_query($query, 'id');
    34   $smart_count = count($smart_cats);
    35  
     69
     70  $smart_cats = query2array($query, 'id');
     71
    3672  if (isset($_GET['smart_generate']))
    3773  {
     
    4278      {
    4379        $associated_images = smart_make_associations($category['id']);
    44         array_push($page['infos'],
    45           sprintf(l10n('%d photos associated to album %s'),
    46             count($associated_images),
    47             '&laquo;'.trigger_event('render_category_name', $category['name'], 'admin_cat_list').'&raquo;'
    48             )
     80
     81        $page['infos'][] = l10n(
     82          '%d photos associated to album %s',
     83          count($associated_images),
     84          '&laquo;'.trigger_event('render_category_name', $category['name'], 'admin_cat_list').'&raquo;'
    4985          );
    5086      }
     
    5389    else
    5490    {
    55       $associated_images = smart_make_associations($_GET['smart_generate']);   
    56       array_push($page['infos'],
    57         sprintf(l10n('%d photos associated to album %s'),
    58           count($associated_images),
    59           '&laquo;'.trigger_event('render_category_name', $smart_cats[ $_GET['smart_generate'] ]['name'], 'admin_cat_list').'&raquo;'
    60           )
     91      $associated_images = smart_make_associations($_GET['smart_generate']);
     92
     93      $page['infos'][] = l10n(
     94        '%d photos associated to album %s',
     95        count($associated_images),
     96        '&laquo;'.trigger_event('render_category_name', $smart_cats[ $_GET['smart_generate'] ]['name'], 'admin_cat_list').'&raquo;'
    6197        );
    6298    }
    63    
     99
    64100    define('SMART_NOT_UPDATE', 1);
    65101    invalidate_user_cache();
    66102  }
    67  
     103
    68104  // create regenerate link
    69105  $tpl_cat = array();
     
    72108    $tpl_cat[$cat] = $self_url.'&amp;smart_generate='.$cat;
    73109  }
    74   $tpl_cat['all'] = $self_url.'&amp;smart_generate=all';
    75  
     110  if (count($smart_cats))
     111  {
     112    $tpl_cat['all'] = $self_url.'&amp;smart_generate=all';
     113  }
     114
    76115  $template->assign(array(
    77116    'SMART_URL' => $tpl_cat,
    78117    'SMART_PATH' => SMART_PATH,
    79118  ));
    80  
     119
    81120  $template->set_prefilter('categories', 'smart_cat_list_prefilter');
    82121}
    83122
    84123
    85 function smart_cat_list_prefilter($content, &$smarty)
     124function smart_cat_list_prefilter($content)
    86125{
    87   global $smart_count;
    88  
    89126  $search[0] = '{if isset($category.U_MANAGE_ELEMENTS) }';
    90127  $replacement[0] = $search[0].'
     
    93130{/if}';
    94131
    95   if ($smart_count > 0)
    96   {
    97     $search[1] = '<a href="#" id="autoOrderOpen">{\'apply automatic sort order\'|@translate}</a>';
    98     $replacement[1] = $search[1].'
    99 | <a href="{$SMART_URL.all}">{\'Regenerate photos list of all SmartAlbums\'|@translate}</a>';
    100   }
    101  
     132  $search[1] = '<a href="#" id="autoOrderOpen">{\'apply automatic sort order\'|@translate}</a>';
     133  $replacement[1] = $search[1].'
     134{if isset($SMART_URL.all)}| <a href="{$SMART_URL.all}">{\'Regenerate photos list of all SmartAlbums\'|@translate}</a>{/if}';
     135
    102136  $search[2] = '{$category.NAME}</a></strong>';
    103137  $replacement[2] = $search[2].'
     
    108142  return str_replace($search, $replacement, $content);
    109143}
    110 
    111 ?>
  • extensions/SmartAlbums/include/functions.inc.php

    r21658 r26442  
    11<?php
    2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     2defined('SMART_PATH') or die('Hacking attempt!');
    33
    44/*
     
    1010{
    1111  $query = '
    12 DELETE FROM '.IMAGE_CATEGORY_TABLE.' 
    13   WHERE 
    14     category_id = '.$cat_id.' 
     12DELETE FROM '.IMAGE_CATEGORY_TABLE.'
     13  WHERE
     14    category_id = '.$cat_id.'
    1515    AND smart = true
    1616;';
    1717  pwg_query($query);
    18  
     18
    1919  $images = smart_get_pictures($cat_id);
    20  
     20
    2121  if (count($images) != 0)
    2222  {
     
    3030    }
    3131    mass_inserts(
    32       IMAGE_CATEGORY_TABLE, 
    33       array_keys($datas[0]), 
     32      IMAGE_CATEGORY_TABLE,
     33      array_keys($datas[0]),
    3434      $datas,
    3535      array('ignore'=>true)
    3636      );
    3737  }
    38  
     38
    3939  // representant, try to not overwrite if still in images list
    4040  $query = '
     
    4444;';
    4545  list($rep_id) = pwg_db_fetch_row(pwg_query($query));
    46  
    47   if ( !in_array($rep_id, $images) )
     46
     47  if (!in_array($rep_id, $images))
    4848  {
    4949    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
    5050    set_random_representant(array($cat_id));
    5151  }
    52  
     52
    5353  $query = '
    5454UPDATE '.CATEGORY_FILTERS_TABLE.'
     
    5757;';
    5858  pwg_query($query);
    59  
     59
    6060  return $images;
    6161}
     
    6969{
    7070  global $conf;
    71  
    72   if ( defined('SMART_NOT_UPDATE') OR !$conf['SmartAlbums']['update_on_upload'] ) return;
    73  
     71
     72  if (defined('SMART_NOT_UPDATE'))
     73  {
     74    return;
     75  }
     76
    7477  // get categories with smart filters
    7578  $query = '
    76 SELECT DISTINCT id
    77   FROM '.CATEGORIES_TABLE.' AS c
    78     INNER JOIN '.CATEGORY_FILTERS_TABLE.' AS cf
    79     ON c.id = cf.category_id
     79SELECT DISTINCT category_id
     80  FROM '.CATEGORY_FILTERS_TABLE.'
    8081;';
    81  
     82
    8283  // regenerate photo list
    83   $smart_cats = array_from_query($query, 'id');
     84  $smart_cats = query2array($query, null, 'category_id');
    8485  array_map('smart_make_associations', $smart_cats);
    8586}
     
    9798
    9899  /* get filters */
    99   if ($filters === null)
     100  if (!isset($filters))
    100101  {
    101102    $query = '
    102 SELECT * 
    103   FROM '.CATEGORY_FILTERS_TABLE.' 
    104   WHERE category_id = '.$cat_id.' 
     103SELECT *
     104  FROM '.CATEGORY_FILTERS_TABLE.'
     105  WHERE category_id = '.$cat_id.'
    105106  ORDER BY type ASC, cond ASC
    106107;';
    107108    $result = pwg_query($query);
    108    
    109     if (!pwg_db_num_rows($result)) return array();
    110    
     109
     110    if (!pwg_db_num_rows($result))
     111    {
     112      return array();
     113    }
     114
    111115    $filters = array();
    112116    while ($row = pwg_db_fetch_assoc($result))
     
    123127    return array();
    124128  }
    125  
     129
    126130  $mode = 'and';
    127  
     131
    128132  /* build constrains */
    129133  ## generate 'join', 'where' arrays and 'limit' string to create the SQL query
    130134  ## inspired by PicsEngine 3 by Michael Villar
    131135  $i_tags = 1;
     136  $join = array();
     137  $where = array();
     138
    132139  foreach ($filters as $filter)
    133140  {
     
    142149          case 'all':
    143150          {
     151            $tags_arr = explode(',', $filter['value']);
     152            foreach ($tags_arr as $value)
     153            {
     154              $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id';
     155              $where[] = 'it'.$i_tags.'.tag_id = '.$value;
     156              $i_tags++;
     157            }
     158
     159            break;
     160          }
     161          // search images which tags are in the list
     162          case 'one':
     163          {
     164            $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id';
     165            $where[] = 'it'.$i_tags.'.tag_id IN ('.$filter['value'].')';
     166            $i_tags++;
     167
     168            break;
     169          }
     170          // exclude images which tags are in the list
     171          case 'none':
     172          {
     173            $sub_query = '
     174      SELECT it'.$i_tags.'.image_id
     175        FROM '.IMAGE_TAG_TABLE.' AS it'.$i_tags.'
     176        WHERE
     177          it'.$i_tags.'.image_id = i.id AND
     178          it'.$i_tags.'.tag_id IN ('.$filter['value'].')
     179        GROUP BY it'.$i_tags.'.image_id
     180      ';
     181            $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id';
     182            $where[] = 'NOT EXISTS ('.$sub_query.')';
     183            $i_tags++;
     184
     185            break;
     186          }
     187          // exclude images which tags are not in the list and search images which have all tags
     188          case 'only':
     189          {
     190            $sub_query = '
     191      SELECT it'.$i_tags.'.image_id
     192        FROM '.IMAGE_TAG_TABLE.' AS it'.$i_tags.'
     193        WHERE
     194          it'.$i_tags.'.image_id = i.id AND
     195          it'.$i_tags.'.tag_id NOT IN ('.$filter['value'].')
     196        GROUP BY it'.$i_tags.'.image_id
     197      ';
     198            $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id';
     199            $where[] = 'NOT EXISTS ('.$sub_query.')';
     200            $i_tags++;
     201
    144202            $tags_arr = explode(',', $filter['value']);
    145203            foreach($tags_arr as $value)
     
    149207              $i_tags++;
    150208            }
    151            
    152             break;
    153           }
    154           // search images which tags are in the list
    155           case 'one':
    156           {
    157             $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id';
    158             $where[] = 'it'.$i_tags.'.tag_id IN ('.$filter['value'].')';
    159             $i_tags++;
    160            
    161             break;
    162           }
    163           // exclude images which tags are in the list
    164           case 'none':
    165           {
    166             $sub_query = '
    167       SELECT it'.$i_tags.'.image_id
    168         FROM '.IMAGE_TAG_TABLE.' AS it'.$i_tags.'
    169         WHERE
    170           it'.$i_tags.'.image_id = i.id AND
    171           it'.$i_tags.'.tag_id IN ('.$filter['value'].')
    172         GROUP BY it'.$i_tags.'.image_id
    173       ';
    174             $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id';
    175             $where[] = 'NOT EXISTS ('.$sub_query.')';
    176             $i_tags++;
    177            
    178             break;
    179           }
    180           // exclude images which tags are not in the list and search images which have all tags
    181           case 'only':
    182           {
    183             $sub_query = '
    184       SELECT it'.$i_tags.'.image_id
    185         FROM '.IMAGE_TAG_TABLE.' AS it'.$i_tags.'
    186         WHERE
    187           it'.$i_tags.'.image_id = i.id AND
    188           it'.$i_tags.'.tag_id NOT IN ('.$filter['value'].')
    189         GROUP BY it'.$i_tags.'.image_id
    190       ';
    191             $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id';
    192             $where[] = 'NOT EXISTS ('.$sub_query.')';
    193             $i_tags++;
    194            
    195             $tags_arr = explode(',', $filter['value']);
    196             foreach($tags_arr as $value)
    197             {
    198               $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id';
    199               $where[] = 'it'.$i_tags.'.tag_id = '.$value;
    200               $i_tags++;
    201             }
    202            
    203             break;
    204           }
    205         }
    206        
    207         break;
    208       }
    209    
     209
     210            break;
     211          }
     212        }
     213
     214        break;
     215      }
     216
    210217      // date
    211218      case 'date':
     
    232239            break;
    233240        }
    234        
    235         break;
    236       }
    237      
     241
     242        break;
     243      }
     244
    238245      // name
    239246      case 'name':
     
    263270            break;
    264271        }
    265        
    266         break;
    267       }
    268      
     272
     273        break;
     274      }
     275
    269276      // album
    270277      case 'album':
     
    279286            {
    280287              $sub_query = '
    281       SELECT image_id 
     288      SELECT image_id
    282289        FROM '.IMAGE_CATEGORY_TABLE.'
    283290        WHERE category_id = '.$value.'
     
    285292              $where[] = 'i.id IN ('.$sub_query.')';
    286293            }
    287            
     294
    288295            break;
    289296          }
     
    297304      ';
    298305            $where[] = 'i.id IN ('.$sub_query.')';
    299            
     306
    300307            break;
    301308          }
     
    309316      ';
    310317            $where[] = 'i.id NOT IN ('.$sub_query.')';
    311            
     318
    312319            break;
    313320          }
     
    321328      ';
    322329            $where[] = 'i.id NOT IN ('.$sub_query.')';
    323            
     330
    324331            $albums_arr = explode(',', $filter['value']);
    325332            foreach($albums_arr as $value)
    326333            {
    327334              $sub_query = '
    328       SELECT image_id 
     335      SELECT image_id
    329336        FROM '.IMAGE_CATEGORY_TABLE.'
    330337        WHERE category_id = '.$value.'
     
    332339              $where[] = 'i.id IN ('.$sub_query.')';
    333340            }
    334            
    335             break;
    336           }
    337         }
    338        
    339         break;
    340       }
    341      
     341
     342            break;
     343          }
     344        }
     345
     346        break;
     347      }
     348
    342349      // dimensions
    343350      case 'dimensions':
    344351      {
    345352        $filter['value'] = explode(',', $filter['value']);
    346        
     353
    347354        switch ($filter['cond'])
    348355        {
     
    358365        }
    359366      }
    360      
     367
    361368      // author
    362369      case 'author':
     
    384391            break;
    385392        }
    386        
    387         break;
    388       }
    389      
     393
     394        break;
     395      }
     396
    390397      // hit
    391398      case 'hit':
     
    400407            break;
    401408        }
    402        
    403         break;
    404       }
    405      
     409
     410        break;
     411      }
     412
    406413      // rating_score
    407414      case 'rating_score':
     
    416423            break;
    417424        }
    418        
    419         break;
    420       }
    421      
     425
     426        break;
     427      }
     428
    422429      // level
    423430      case 'level':
     
    426433        break;
    427434      }
    428      
     435
    429436      // limit
    430437      case 'limit':
     
    433440        break;
    434441      }
    435      
     442
    436443      // mode
    437444      case 'mode':
     
    442449    }
    443450  }
    444  
     451
    445452  /* bluid query */
    446453  $MainQuery = '
    447454SELECT i.id
    448455  FROM '.IMAGES_TABLE.' AS i';
    449    
    450     if (isset($join))
     456
     457    if (count($join))
    451458    {
    452459      $MainQuery.= '
    453460    LEFT JOIN '.implode("\n    LEFT JOIN ", $join);
    454461    }
    455     if (isset($where))
     462    if (count($where))
    456463    {
    457464      $MainQuery.= '
     
    471478    file_put_contents(SMART_PATH.'dump_query.sql', $MainQuery);
    472479  }
    473  
    474   return array_from_query($MainQuery, 'id');
     480
     481  return query2array($MainQuery, null, 'id');
    475482}
    476483
     
    484491{
    485492  global $page, $limit_is_set, $level_is_set;
     493
    486494  $error = false;
    487  
    488495  if (!isset($limit_is_set)) $limit_is_set = false;
    489496  if (!isset($level_is_set)) $level_is_set = false;
    490  
     497
    491498  switch ($filter['type'])
    492499  {
     
    496503      if ($filter['value'] == null)
    497504      {
    498         $error = true;
    499         array_push($page['errors'], l10n('No tag selected'));
     505        $page['errors'][] = l10n('No tag selected');
    500506      }
    501507      else
     
    511517      if (!preg_match('#([0-9]{4})-([0-9]{2})-([0-9]{2})#', $filter['value']))
    512518      {
    513         $error = true;
    514         array_push($page['errors'], l10n('Date string is malformed'));
     519        $page['errors'][] = l10n('Date string is malformed');
    515520      }
    516521      break;
     
    521526      if (empty($filter['value']))
    522527      {
    523         $error = true;
    524         array_push($page['errors'], l10n('Name is empty'));
    525       }
    526       else if ( $filter['cond']=='regex' and @preg_match('/'.$filter['value'].'/', null)===false )
    527       {
    528         $error = true;
    529         array_push($page['errors'], l10n('Regex is malformed'));
     528        $page['errors'][] = l10n('Name is empty');
     529      }
     530      else if ($filter['cond']=='regex' and @preg_match('/'.$filter['value'].'/', null)===false)
     531      {
     532        $page['errors'][] = l10n('Regex is malformed');
    530533      }
    531534      break;
     
    536539      if (@$filter['value'] == null)
    537540      {
    538         $error = true;
    539         array_push($page['errors'], l10n('No album selected'));
     541        $page['errors'][] = l10n('No album selected');
    540542      }
    541543      else
     
    548550    case 'dimensions':
    549551    {
    550       if ( empty($filter['value']['min']) or empty($filter['value']['max']) )
     552      if (empty($filter['value']['min']) or empty($filter['value']['max']))
    551553      {
    552554        $error = true;
     
    563565      if (empty($filter['value']))
    564566      {
    565         $error = true;
    566         array_push($page['errors'], l10n('Author is empty'));
    567       }
    568       else if ( $filter['cond']=='regex' and @preg_match('/'.$filter['value'].'/', null)===false )
    569       {
    570         $error = true;
    571         array_push($page['errors'], l10n('Regex is malformed'));
     567        $page['errors'][] = l10n('Author is empty');
     568      }
     569      else if ($filter['cond']=='regex' and @preg_match('/'.$filter['value'].'/', null)===false)
     570      {
     571        $page['errors'][] = l10n('Regex is malformed');
    572572      }
    573573      else
     
    580580    case 'hit':
    581581    {
    582       if (!preg_match('#([0-9]{1,})#', $filter['value']))
    583       {
    584         $error = true;
    585         array_push($page['errors'], l10n('Hits must be an integer'));
     582      if (!preg_match('#([0-9]+)#', $filter['value']))
     583      {
     584        $page['errors'][] = l10n('Hits must be an integer');
    586585      }
    587586      break;
     
    590589    case 'rating_score':
    591590    {
    592       if (!preg_match('#([0-9]{1,})#', $filter['value']))
    593       {
    594         $error = true;
    595         array_push($page['errors'], l10n('Rating score must be an integer'));
     591      if (!preg_match('#([0-9]+)#', $filter['value']))
     592      {
     593        $page['errors'][] = l10n('Rating score must be an integer');
    596594      }
    597595      break;
     
    602600      if ($level_is_set == true) // only one level is allowed, first is saved
    603601      {
    604         $error = true;
    605         array_push($page['errors'], l10n('You can\'t use more than one level filter'));
     602        $page['errors'][] = l10n('You can\'t use more than one level filter');
    606603      }
    607604      else
     
    617614      if ($limit_is_set == true) // only one limit is allowed, first is saved
    618615      {
    619         $error = true;
    620         array_push($page['errors'], l10n('You can\'t use more than one limit filter'));
    621       }
    622       else if (!preg_match('#([0-9]{1,})#', $filter['value']))
    623       {
    624         $error = true;
    625         array_push($page['errors'], l10n('Limit must be an integer'));
    626       }
    627       else
    628       {
    629         $filter['cond'] = 'level';
     616        $page['errors'][] = l10n('You can\'t use more than one limit filter');
     617      }
     618      else if (!preg_match('#([0-9]+)#', $filter['value']))
     619      {
     620        $page['errors'][] = l10n('Limit must be an integer');
     621      }
     622      else
     623      {
     624        $filter['cond'] = 'limit';
    630625        $limit_is_set = true;
    631626      }
     
    638633      break;
    639634    }
    640    
     635
    641636    default:
    642637    {
     
    645640    }
    646641  }
    647  
    648  
    649   if ($error == false)
     642
     643
     644  if (!$error && empty($page['errors']))
    650645  {
    651646    return $filter;
     
    656651  }
    657652}
    658 
    659 
    660 /**
    661  * clean table when categories are deleted
    662  */
    663 function smart_delete_categories($ids)
    664 {
    665   $query = '
    666 DELETE FROM '.CATEGORY_FILTERS_TABLE.'
    667   WHERE category_id IN('.implode(',', $ids).')
    668 ;';
    669   pwg_query($query);
    670 }
    671 
    672 /**
    673  * update images list periodically
    674  */
    675 function smart_periodic_update()
    676 {
    677   global $conf;
    678  
    679   // we only search for old albums every hour, nevermind which user is connected
    680   if ($conf['SmartAlbums']['last_update'] > time() - 3600) return;
    681  
    682   $conf['SmartAlbums']['last_update'] = time();
    683   conf_update_param('SmartAlbums', serialize($conf['SmartAlbums']));
    684  
    685   // get categories with smart filters
    686   $query = '
    687 SELECT DISTINCT id
    688   FROM '.CATEGORIES_TABLE.' AS c
    689     INNER JOIN '.CATEGORY_FILTERS_TABLE.' AS cf
    690     ON c.id = cf.category_id
    691   WHERE updated < DATE_SUB(NOW(), INTERVAL '.$conf['SmartAlbums']['update_timeout'].' DAY)
    692 ;';
    693  
    694   // regenerate photo list
    695   $smart_cats = array_from_query($query, 'id');
    696   array_map('smart_make_associations', $smart_cats);
    697 }
    698 
    699 ?>
  • extensions/SmartAlbums/language/en_UK/plugin.lang.php

    r19446 r26442  
    22
    33$lang['No filter selected'] = 'No filter selected';
    4 $lang['%d photo'] = '%d photo';
    5 $lang['%d photos'] = '%d photos';
    64$lang['All these tags'] = 'All these tags';
    75$lang['One of these tags'] = 'One of these tags';
     
    6361$lang['SmartAlbums are considered private for everyone, and a user can see it\'s content only if available in another album he has access to.'] = 'SmartAlbums are considered private for everyone, and a user can see it\'s content only if available in another album he has access to.';
    6462$lang['Update albums every %s days'] = 'Update albums every %s days';
     63$lang['Invalid number of days'] = 'Invalid number of days';
     64$lang['Mode'] = 'Mode';
     65$lang['Select albums...'] = 'Select albums...';
    6566
    6667?>
  • extensions/SmartAlbums/language/fr_FR/plugin.lang.php

    r19446 r26442  
    22
    33$lang['No filter selected'] = 'Aucun filtre sélectionné';
    4 $lang['%d photo'] = '%d photo';
    5 $lang['%d photos'] = '%d photos';
    64$lang['All these tags'] = 'Tous les tags';
    75$lang['One of these tags'] = 'Un des tags';
     
    6361$lang['SmartAlbums are considered private for everyone, and a user can see it\'s content only if available in another album he has access to.'] = 'Les SmartAlbums sont considérés comme privés pour tout le monde, et un utilisateur ne peut voir leur contenu que si disponible dans un autre album auquel il a accès.';
    6462$lang['Update albums every %s days'] = 'Mettre à jour les albums tous les %s jours';
     63$lang['Invalid number of days'] = 'Nombre de jour invalide';
     64$lang['Mode'] = 'Mode';
     65$lang['Select albums...'] = 'Albums...';
    6566
    6667?>
  • extensions/SmartAlbums/main.inc.php

    r19446 r26442  
    44Version: auto
    55Description: Easily create dynamic albums with tags, date and other criteria
    6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=544
     6Plugin URI: auto
    77Author: Mistic
    88Author URI: http://www.strangeplanet.fr
    99*/
    1010
    11 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     11defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
     12
    1213global $prefixeTable;
    1314
    14 define('SMART_PATH',     PHPWG_PLUGINS_PATH . 'SmartAlbums/');
     15define('SMART_ID',      'SmartAlbums');
     16define('SMART_PATH',    PHPWG_PLUGINS_PATH . SMART_ID . '/');
    1517define('CATEGORY_FILTERS_TABLE', $prefixeTable . 'category_filters');
    16 define('SMART_ADMIN',    get_root_url() . 'admin.php?page=plugin-SmartAlbums');
    17 define('SMART_VERSION',  'auto');
    18 //define('SMART_DEBUG',    true);
     18define('SMART_ADMIN',   get_root_url() . 'admin.php?page=plugin-' . SMART_ID);
     19define('SMART_VERSION', 'auto');
     20// define('SMART_DEBUG',   true);
    1921
    2022
    2123add_event_handler('init', 'smart_init');
    2224add_event_handler('init', 'smart_periodic_update');
    23 add_event_handler('invalidate_user_cache', 'smart_make_all_associations');
     25add_event_handler('delete_categories', 'smart_delete_categories');
    2426
    2527if (defined('IN_ADMIN'))
    2628{
    27   include_once(SMART_PATH.'include/cat_list.php');
     29  include_once(SMART_PATH.'include/events_admin.inc.php');
    2830  add_event_handler('loc_begin_cat_list', 'smart_cat_list');
    29   add_event_handler('tabsheet_before_select','smart_tab', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); 
     31  add_event_handler('tabsheet_before_select','smart_tab', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
    3032  add_event_handler('get_admin_plugin_menu_links', 'smart_admin_menu');
    31   add_event_handler('delete_categories', 'smart_delete_categories');
    3233}
    3334
     35include_once(SMART_PATH.'include/events.inc.php');
    3436include_once(SMART_PATH.'include/functions.inc.php');
    3537
     
    4042function smart_init()
    4143{
    42   global $conf, $pwg_loaded_plugins;
    43  
    44   if (
    45     SMART_VERSION == 'auto' or
    46     $pwg_loaded_plugins['SmartAlbums']['version'] == 'auto' or
    47     version_compare($pwg_loaded_plugins['SmartAlbums']['version'], SMART_VERSION, '<')
    48   )
    49   {
    50     include_once(SMART_PATH . 'include/install.inc.php');
    51     smart_albums_install();
    52    
    53     if ( $pwg_loaded_plugins['SmartAlbums']['version'] != 'auto' and SMART_VERSION != 'auto' )
    54     {
    55       $query = '
    56 UPDATE '. PLUGINS_TABLE .'
    57 SET version = "'. SMART_VERSION .'"
    58 WHERE id = "SmartAlbums"';
    59       pwg_query($query);
    60      
    61       $pwg_loaded_plugins['SmartAlbums']['version'] = SMART_VERSION;
    62      
    63       if (defined('IN_ADMIN'))
    64       {
    65         $_SESSION['page_infos'][] = 'Smart Albums updated to version '. SMART_VERSION;
    66       }
    67     }
    68   }
    69  
     44  global $conf;
     45
     46  include_once(SMART_PATH . 'maintain.inc.php');
     47  $maintain = new SmartAlbums_maintain(SMART_ID);
     48  $maintain->autoUpdate(SMART_VERSION, 'install');
     49
    7050  if (defined('IN_ADMIN'))
    7151  {
     
    7353  }
    7454  $conf['SmartAlbums'] = unserialize($conf['SmartAlbums']);
    75  
    76   if ( script_basename() == 'index' and $conf['SmartAlbums']['smart_is_forbidden'] )
     55
     56  if (script_basename() == 'index' and $conf['SmartAlbums']['smart_is_forbidden'])
    7757  {
    7858    add_event_handler('loc_end_section_init', 'smart_init_page_items');
    79     include_once(SMART_PATH.'include/page_items.php');
     59  }
     60
     61  if ($conf['SmartAlbums']['update_on_upload'])
     62  {
     63    add_event_handler('invalidate_user_cache', 'smart_make_all_associations');
    8064  }
    8165}
    82 
    83 /**
    84  * new tab on album properties page
    85  */
    86 function smart_tab($sheets, $id)
    87 {
    88   if ($id != 'album') return $sheets;
    89  
    90   global $category;
    91  
    92   if ($category['dir'] == null)
    93   {
    94     $sheets['smartalbum'] = array(
    95       'caption' => 'SmartAlbum',
    96       'url' => SMART_ADMIN.'-album&amp;cat_id='.$_GET['cat_id'],
    97       );
    98   }
    99  
    100   return $sheets;
    101 }
    102 
    103 
    104 /**
    105  * admin plugins menu link
    106  */
    107 function smart_admin_menu($menu)
    108 {
    109   array_push($menu, array(
    110       'NAME' => 'SmartAlbums',
    111       'URL' => SMART_ADMIN,
    112     ));
    113   return $menu;
    114 }
    115 
    116 ?>
  • extensions/SmartAlbums/maintain.inc.php

    r21658 r26442  
    11<?php
    2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     2defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
    33
    4 include_once(PHPWG_PLUGINS_PATH . 'SmartAlbums/include/install.inc.php');
     4class SmartAlbums_maintain extends PluginMaintain
     5{
     6  private $installed = false;
    57
    6 function plugin_install()
    7 {
    8   smart_albums_install();
    9   define('smart_albums_installed', true);
    10 }
     8  private $default_conf = array(
     9    'update_on_upload' => false,
     10    'update_on_date' => true,
     11    'update_timeout' => 3,
     12    'show_list_messages' => true,
     13    'smart_is_forbidden' => false,
     14    'last_update' => 0,
     15    );
    1116
    12 function plugin_activate()
    13 {
    14   if (!defined('smart_albums_installed'))
     17  private $table;
     18
     19  function __construct($plugin_id)
    1520  {
    16     smart_albums_install();
     21    global $prefixeTable;
     22
     23    parent::__construct($plugin_id);
     24
     25    $this->table = $prefixeTable . 'category_filters';
     26  }
     27
     28  function install($plugin_version, &$errors=array())
     29  {
     30    global $conf, $prefixeTable;
     31
     32    if (empty($conf['SmartAlbums']))
     33    {
     34      $conf['SmartAlbums'] = serialize($this->default_conf);
     35      conf_update_param('SmartAlbums', $conf['SmartAlbums']);
     36    }
     37    else
     38    {
     39      $new_conf = is_string($conf['SmartAlbums']) ? unserialize($conf['SmartAlbums']) : $conf['SmartAlbums'];
     40
     41      // new param in 2.0.2
     42      if (!isset($new_conf['smart_is_forbidden']))
     43      {
     44        $new_conf['smart_is_forbidden'] = true;
     45      }
     46
     47      // new params in 2.1.0
     48      if (!isset($new_conf['update_on_date']))
     49      {
     50        $new_conf['update_on_date'] = true;
     51        $new_conf['update_timeout'] = 3;
     52        $new_conf['last_update'] = 0;
     53      }
     54
     55      $conf['SmartAlbums'] = serialize($new_conf);
     56      conf_update_param('SmartAlbums', $conf['SmartAlbums']);
     57    }
     58
     59    // new table
     60    pwg_query(
     61'CREATE TABLE IF NOT EXISTS `' . $this->table . '` (
     62  `category_id` smallint(5) unsigned NOT NULL,
     63  `type` varchar(16) NOT NULL,
     64  `cond` varchar(16) NULL,
     65  `value` text NULL,
     66  `updated` DATETIME NOT NULL DEFAULT "1970-01-01 00:00:00"
     67) ENGINE=MyISAM DEFAULT CHARSET=utf8
     68;');
     69
     70    // new column on image category table
     71    $result = pwg_query('SHOW COLUMNS FROM `' . IMAGE_CATEGORY_TABLE . '` LIKE "smart";');
     72    if (!pwg_db_num_rows($result))
     73    {
     74      pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` ADD `smart` ENUM(\'true\', \'false\') NOT NULL DEFAULT \'false\';');
     75    }
     76
     77    // new column on category filters table (2.1.1)
     78    $result = pwg_query('SHOW COLUMNS FROM `' . $this->table . '` LIKE "updated";');
     79    if (!pwg_db_num_rows($result))
     80    {
     81      pwg_query('ALTER TABLE `' . $this->table . '` ADD `updated` DATETIME NOT NULL DEFAULT "1970-01-01 00:00:00"');
     82    }
     83
     84    // remove column on category table, moved to category filters table (2.1.1)
     85    $result = pwg_query('SHOW COLUMNS FROM `' . CATEGORIES_TABLE . '` LIKE "smart_update";');
     86    if (pwg_db_num_rows($result))
     87    {
     88      pwg_query('UPDATE `' . $this->table . '` AS f SET updated = ( SELECT smart_update FROM `' . CATEGORIES_TABLE . '` AS c WHERE c.id = f.category_id );');
     89      pwg_query('ALTER TABLE `' . CATEGORIES_TABLE . '` DROP `smart_update`;');
     90    }
     91
     92    // date filters renamed in 2.0
     93    $query = '
     94SELECT category_id
     95  FROM `' . $this->table . '`
     96  WHERE
     97    type = "date" AND
     98    cond IN ("the","before","after","the_crea","before_crea","after_crea")
     99;';
     100
     101    if (pwg_db_num_rows(pwg_query($query)))
     102    {
     103      $name_changes = array(
     104        'the' => 'the_post',
     105        'before' => 'before_post',
     106        'after' => 'after_post',
     107        'the_crea' => 'the_taken',
     108        'before_crea' => 'before_taken',
     109        'after_crea' => 'after_taken',
     110        );
     111      foreach ($name_changes as $old => $new)
     112      {
     113        pwg_query('UPDATE `' . $this->table . '` SET cond = "' . $new . '" WHERE type = "date" AND cond = "' . $old . '";');
     114      }
     115    }
     116
     117    $this->installed = true;
     118  }
     119
     120  function activate($plugin_version, &$errors=array())
     121  {
     122    if (!$this->installed)
     123    {
     124      $this->install($plugin_version, $errors);
     125    }
     126  }
     127
     128  function deactivate()
     129  {
     130  }
     131
     132  function uninstall()
     133  {
     134    conf_delete_param('SmartAlbums');
     135
     136    pwg_query('DROP TABLE `' . $this->table . '`;');
     137
     138    pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` DROP `smart`;');
    17139  }
    18140}
    19 
    20 function plugin_uninstall()
    21 {
    22   global $prefixeTable;
    23  
    24   pwg_query('DROP TABLE `' . $prefixeTable . 'category_filters`;');
    25   pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` DROP `smart`;');
    26   pwg_query('DELETE FROM `' . CONFIG_TABLE . '` WHERE param = \'SmartAlbums\' LIMIT 1;');
    27 }
    28 
    29 ?>
Note: See TracChangeset for help on using the changeset viewer.