Ignore:
Timestamp:
Jun 27, 2012, 9:19:07 PM (12 years ago)
Author:
mistic100
Message:

updated for Piwigo 2.4
new filters : name, author, level, hits

Location:
extensions/SmartAlbums/include
Files:
1 deleted
3 edited
2 moved

Legend:

Unmodified
Added
Removed
  • extensions/SmartAlbums/include/cat_list.php

    r12863 r16104  
    4242      {
    4343        $associated_images = smart_make_associations($category['id']);
    44         array_push(
    45           $page['infos'],
    46           sprintf(
    47             l10n('%d photos associated to album %s'),
     44        array_push($page['infos'],
     45          sprintf(l10n('%d photos associated to album %s'),
    4846            count($associated_images),
    49             '«'.trigger_event(
    50               'render_category_name',
    51               $category['name'],
    52               'admin_cat_list'
    53               ).'»'
     47            '«'.trigger_event('render_category_name', $category['name'], 'admin_cat_list').'»'
    5448            )
    5549          );
     
    6054    {
    6155      $associated_images = smart_make_associations($_GET['smart_generate']);   
    62       array_push(
    63         $page['infos'],
    64         sprintf(
    65           l10n('%d photos associated to album %s'),
     56      array_push($page['infos'],
     57        sprintf(l10n('%d photos associated to album %s'),
    6658          count($associated_images),
    67           '«'.trigger_event(
    68             'render_category_name',
    69             $smart_cats[$_GET['smart_generate']]['name'],
    70             'admin_cat_list'
    71             ).'»'
     59          '«'.trigger_event('render_category_name', $smart_cats[ $_GET['smart_generate'] ]['name'], 'admin_cat_list').'»'
    7260          )
    7361        );
     
    9987  global $smart_count;
    10088 
    101   $search[0] = '{if isset($category.U_SYNC) }';
    102   $replacement[0] = '
     89  $search[0] = '{if isset($category.U_MANAGE_ELEMENTS) }';
     90  $replacement[0] = $search[0].'
    10391{if isset($SMART_URL[$category.ID])}
    104         <li><a href="{$SMART_URL[$category.ID]}" title="{\'Regenerate photos list of this SmartAlbum\'|@translate}"><img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/synchronize.png" class="button" alt="{\'Regenerate photos list of this SmartAlbum\'|@translate}"></a></li>
    105 {/if}'
    106 .$search[0];
     92| <a href="{$SMART_URL[$category.ID]}">{\'Regenerate photos list of this SmartAlbum\'|@translate}</a>
     93{/if}';
    10794
    10895  if ($smart_count > 0)
    10996  {
    110     $search[1] = '</ul>
    111 </form>';
     97    $search[1] = '<a href="#" id="autoOrderOpen">{\'apply automatic sort order\'|@translate}</a>';
    11298    $replacement[1] = $search[1].'
    113 <form method="post" action="{$SMART_URL.all}">
    114   <input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
    115   <p><input class="submit" type="submit" value="{\'Regenerate photos list of all SmartAlbums\'|@translate}"></p>
    116 </form>';
     99| <a href="{$SMART_URL.all}">{\'Regenerate photos list of all SmartAlbums\'|@translate}</a>';
    117100  }
     101 
     102  $search[2] = '{$category.NAME}</a></strong>';
     103  $replacement[2] = $search[2].'
     104{if isset($SMART_URL[$category.ID])}
     105<img src="'.SMART_PATH.'admin/template/lightning.png">
     106{/if}';
    118107
    119108  return str_replace($search, $replacement, $content);
  • extensions/SmartAlbums/include/count_images.php

    r11334 r16104  
    66define('PHPWG_ROOT_PATH','./../../../');
    77define('IN_ADMIN', true);
     8
    89include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
     10
     11if (!is_admin()) die('Hacking attempt!');
     12
    913include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
    1014include_once(SMART_PATH.'include/functions.inc.php');
     15
     16load_language('plugin.lang', SMART_PATH);
     17$conf['SmartAlbums'] = unserialize($conf['SmartAlbums']);
    1118
    1219if (isset($_POST['filters']))
     
    2229      array_push($filters, $filter);
    2330    }
     31    else
     32    {
     33      echo '<span class="filter_error">'.$page['errors'][ count($page['errors'])-1 ].'</span>';
     34      exit;
     35    }
    2436  }
    2537
     
    3143}
    3244
    33 echo l10n_dec('%d photo', '%d photos', count($associated_images));
     45echo '<span class="count_image">'.l10n_dec('%d photo', '%d photos', count($associated_images)).'</span>';
    3446
    3547?>
  • extensions/SmartAlbums/include/functions.inc.php

    r12864 r16104  
    3636  }
    3737 
    38   // represantant, try to not overwrite if still in images list
     38  // representant, try to not overwrite if still in images list
    3939  $query = '
    4040SELECT representative_picture_id
     
    4646  if ( !in_array($rep_id, $images) )
    4747  {
    48     if (!function_exists('set_random_representant'))
    49     {
    50       include(PHPWG_ROOT_PATH.'admin/include/functions.php');
    51     }
     48    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
    5249    set_random_representant(array($cat_id));
    5350  }
     
    6461{
    6562  global $conf;
    66    
    67   if (!is_array($conf['SmartAlbums'])) $conf['SmartAlbums'] = unserialize($conf['SmartAlbums']);
    6863 
    6964  if ( defined('SMART_NOT_UPDATE') OR !$conf['SmartAlbums']['update_on_upload'] ) return;
     
    9489
    9590  /* get filters */
    96   if ($filters == null)
    97   {
    98     $filters = array();
    99    
     91  if ($filters === null)
     92  {
    10093    $query = '
    10194SELECT *
     
    10699    $result = pwg_query($query);
    107100   
    108     if (!pwg_db_num_rows($result)) return $filters;
     101    if (!pwg_db_num_rows($result)) return array();
    109102   
     103    $filters = array();
    110104    while ($row = pwg_db_fetch_assoc($result))
    111105    {
     
    117111    }
    118112  }
     113  else if (!count($filters))
     114  {
     115    return array();
     116  }
    119117   
    120118  /* build constrains */
    121119  ## generate 'join', 'where' arrays and 'limit' string to create the SQL query
    122   ## inspired by PicsEngine by Michael Villar
     120  ## inspired by PicsEngine 3 by Michael Villar
    123121  $i_tags = 1;
    124122  foreach ($filters as $filter)
    125123  {
    126     // tags
    127     if ($filter['type'] == 'tags')
    128     {
    129       if($filter['cond'] == "all")
    130       {
    131         $tags_arr = explode(',', $filter['value']);
     124    switch ($filter['type'])
     125    {
     126      // tags
     127      case 'tags':
     128      {
     129        switch ($filter['cond'])
     130        {
     131          // search images which have all tags
     132          case 'all':
     133          {
     134            $tags_arr = explode(',', $filter['value']);
     135            foreach($tags_arr as $value)
     136            {
     137              $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id';
     138              $where[] = 'it'.$i_tags.'.tag_id = '.$value;
     139              $i_tags++;
     140            }
     141           
     142            break;
     143          }
     144          // search images which tags are in the list
     145          case 'one':
     146          {
     147            $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id';
     148            $where[] = 'it'.$i_tags.'.tag_id IN ('.$filter['value'].')';
     149            $i_tags++;
     150           
     151            break;
     152          }
     153          // exclude images which tags are in the list
     154          case 'none':
     155          {
     156            $sub_query = '
     157      SELECT it'.$i_tags.'.image_id
     158        FROM '.IMAGE_TAG_TABLE.' AS it'.$i_tags.'
     159        WHERE
     160          it'.$i_tags.'.image_id = i.id AND
     161          it'.$i_tags.'.tag_id IN ('.$filter['value'].')
     162        GROUP BY it'.$i_tags.'.image_id
     163      ';
     164            $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id';
     165            $where[] = 'NOT EXISTS ('.$sub_query.')';
     166            $i_tags++;
     167           
     168            break;
     169          }
     170          // exclude images which tags are not in the list and search images which have all tags
     171          case 'only':
     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 NOT 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            $tags_arr = explode(',', $filter['value']);
     186            foreach($tags_arr as $value)
     187            {
     188              $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id';
     189              $where[] = 'it'.$i_tags.'.tag_id = '.$value;
     190              $i_tags++;
     191            }
     192           
     193            break;
     194          }
     195        }
    132196       
    133         foreach($tags_arr as $value)
    134         {
    135           $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id';
    136           $where[] = 'it_'.$i_tags.'.tag_id = '.$value;
    137           $i_tags++;
    138         }
    139       }
    140       else if ($filter['cond'] == 'one')
    141       {
    142         $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id';
    143         $where[] = 'it_'.$i_tags.'.tag_id IN ('.$filter['value'].')';
    144         $i_tags++;
    145       }
    146       else if ($filter['cond'] == 'none')
    147       {
    148         $sub_query = '
    149       SELECT it_'.$i_tags.'.image_id
    150         FROM '.IMAGE_TAG_TABLE.' AS it_'.$i_tags.'
    151         WHERE
    152           it_'.$i_tags.'.image_id = i.id AND
    153           it_'.$i_tags.'.tag_id IN ('.$filter['value'].')
    154         GROUP BY it_'.$i_tags.'.image_id
    155     ';
    156         $where[] = 'NOT EXISTS ('.$sub_query.')';
    157         $i_tags++;
    158       }
    159       else if ($filter['cond'] == 'only')
    160       {
    161         $sub_query = '
    162       SELECT it_'.$i_tags.'.image_id
    163         FROM '.IMAGE_TAG_TABLE.' AS it_'.$i_tags.'
    164         WHERE
    165           it_'.$i_tags.'.image_id = i.id AND
    166           it_'.$i_tags.'.tag_id NOT IN ('.$filter['value'].')
    167         GROUP BY it_'.$i_tags.'.image_id
    168     ';
    169         $where[] = 'NOT EXISTS ('.$sub_query.')';
     197        break;
     198      }
     199   
     200      // date
     201      case 'date':
     202      {
     203        switch ($filter['cond'])
     204        {
     205          case 'the_post':
     206            $where[] = 'date_available BETWEEN "'.$filter['value'].' 00:00:00" AND "'.$filter['value'].' 23:59:59"';
     207            break;
     208          case 'before_post':
     209            $where[] = 'date_available < "'.$filter['value'].' 00:00:00"';
     210            break;
     211          case 'after_post':
     212            $where[] = 'date_available > "'.$filter['value'].' 23:59:59"';
     213            break;
     214          case 'the_taken':
     215            $where[] = 'date_creation BETWEEN "'.$filter['value'].' 00:00:00" AND "'.$filter['value'].' 23:59:59"';
     216            break;
     217          case 'before_taken':
     218            $where[] = 'date_creation < "'.$filter['value'].' 00:00:00"';
     219            break;
     220          case 'after_taken':
     221            $where[] = 'date_creation > "'.$filter['value'].' 23:59:59"';
     222            break;
     223        }
     224       
     225        break;
     226      }
    170227     
    171         $i_tags++;
    172         $tags_arr = explode(',', $filter['value']);
     228      // name
     229      case 'name':
     230      {
     231        switch ($filter['cond'])
     232        {
     233          case 'contain':
     234            $where[] = 'name LIKE "%'.$filter['value'].'%"';
     235            break;
     236          case 'begin':
     237            $where[] = 'name LIKE "'.$filter['value'].'%"';
     238            break;
     239          case 'end':
     240            $where[] = 'name LIKE "%'.$filter['value'].'"';
     241            break;
     242          case 'not_contain':
     243            $where[] = 'name NOT LIKE "%'.$filter['value'].'%"';
     244            break;
     245          case 'not_begin':
     246            $where[] = 'name NOT LIKE "'.$filter['value'].'%"';
     247            break;
     248          case 'not_end':
     249            $where[] = 'name NOT LIKE "%'.$filter['value'].'"';
     250            break;
     251        }
    173252       
    174         foreach($tags_arr as $value)
    175         {
    176           $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id';
    177           $where[] = 'it_'.$i_tags.'.tag_id = '.$value;
    178           $i_tags++;
    179         }
    180       }       
    181     }
    182     // date
    183     else if ($filter['type'] == 'date')
    184     {
    185       switch ($filter['cond'])
    186       {
    187         case 'the':
    188           $where[] = 'date_available BETWEEN "'.$filter['value'].' 00:00:00" AND "'.$filter['value'].' 23:59:59"';
    189           break;
    190         case 'before':
    191           $where[] = 'date_available < "'.$filter['value'].' 00:00:00"';
    192           break;
    193         case 'after':
    194           $where[] = 'date_available > "'.$filter['value'].' 23:59:59"';
    195           break;
    196         case 'the_crea':
    197           $where[] = 'date_creation BETWEEN "'.$filter['value'].' 00:00:00" AND "'.$filter['value'].' 23:59:59"';
    198           break;
    199         case 'before_crea':
    200           $where[] = 'date_creation < "'.$filter['value'].' 00:00:00"';
    201           break;
    202         case 'after_crea':
    203           $where[] = 'date_creation > "'.$filter['value'].' 23:59:59"';
    204           break;
    205       }
    206     }
    207     // limit
    208     else if ($filter['type'] == 'limit')
    209     {
    210       $limit = '0, '.$filter['value'];
     253        break;
     254      }
     255     
     256      // author
     257      case 'author':
     258      {
     259        switch ($filter['cond'])
     260        {
     261          case 'is':
     262            if ($filter['value'] != 'NULL') $filter['value'] = '"'.$filter['value'].'"';
     263            $where[] = 'author = '.$filter['value'].'';
     264            break;
     265          case 'not_is':
     266            if ($filter['value'] != 'NULL') $filter['value'] = '"'.$filter['value'].'"';
     267            $where[] = 'author != '.$filter['value'].'';
     268            break;
     269          case 'in':
     270            $filter['value'] = '"'.str_replace(',', '","', $filter['value']).'"';
     271            $where[] = 'author IN('.$filter['value'].')';
     272            break;
     273          case 'not_in':
     274            $filter['value'] = '"'.str_replace(',', '","', $filter['value']).'"';
     275            $where[] = 'author NOT IN('.$filter['value'].')';
     276            break;
     277        }
     278       
     279        break;
     280      }
     281     
     282      // hit
     283      case 'hit':
     284      {
     285        switch ($filter['cond'])
     286        {
     287          case 'less':
     288            $where[] = 'hit < '.$filter['value'].'';
     289            break;
     290          case 'more':
     291            $where[] = 'hit >= '.$filter['value'].'';
     292            break;
     293        }
     294       
     295        break;
     296      }
     297     
     298      // level
     299      case 'level':
     300      {
     301        $where[] = 'level = '.$filter['value'].'';
     302        break;
     303      }
     304     
     305      // limit
     306      case 'limit':
     307      {
     308        $limit = '0, '.$filter['value'];
     309        break;
     310      }
    211311    }
    212312  }
     
    219319    if (isset($join))
    220320    {
    221       foreach ($join as $query)
    222       {
    223         $MainQuery .= '
    224     LEFT JOIN '.$query;
    225       }
     321      $MainQuery.= '
     322    LEFT JOIN '.implode("\n    LEFT JOIN ", $join);
    226323    }
    227324    if (isset($where))
    228325    {
    229       $MainQuery .= '
    230   WHERE';
    231       $i = 0;
    232       foreach ($where as $query)
    233       {
    234         if ($i != 0) $MainQuery .= ' AND';
    235         $MainQuery .= '
    236     '.$query;
    237         $i++;
    238       }
    239     }
    240 
    241     $MainQuery .= '
     326      $MainQuery.= '
     327  WHERE
     328    '.implode("\n    AND ", $where);
     329    }
     330
     331  $MainQuery.= '
    242332  GROUP BY i.id
    243  '.$conf['order_by'].'
     333  '.$conf['order_by'].'
    244334  '.(isset($limit) ? "LIMIT ".$limit : null).'
    245335;';
    246336
     337  // file_put_contents(SMART_PATH.'query.sql', $MainQuery);
    247338  return array_from_query($MainQuery, 'id');
    248339}
     
    256347function smart_check_filter($filter)
    257348{
    258   global $limit_is_set, $page;
     349  global $page, $limit_is_set, $level_is_set;
    259350  $error = false;
     351 
     352  if (!isset($limit_is_set)) $limit_is_set = false;
     353  if (!isset($level_is_set)) $level_is_set = false;
    260354 
    261355  # tags
     
    281375    }
    282376  }
     377  # name
     378  else if ($filter['type'] == 'name')
     379  {
     380    if (empty($filter['value']))
     381    {
     382      $error = true;
     383      array_push($page['errors'], l10n('Name is empty'));
     384    }
     385  }
     386  # author
     387  else if ($filter['type'] == 'author')
     388  {
     389    if (empty($filter['value']))
     390    {
     391      $error = true;
     392      array_push($page['errors'], l10n('Author is empty'));
     393    }
     394    else
     395    {
     396      $filter['value'] = preg_replace('#([ ]?),([ ]?)#', ',', $filter['value']);
     397    }
     398  }
     399  # hit
     400  else if ($filter['type'] == 'hit')
     401  {
     402    if (!preg_match('#([0-9]{1,})#', $filter['value']))
     403    {
     404      $error = true;
     405      array_push($page['errors'], l10n('Hits must be an integer'));
     406    }
     407  }
     408  # level
     409  else if ($filter['type'] == 'level')
     410  {
     411    if ($level_is_set == true) // only one level is allowed, first is saved
     412    {
     413      $error = true;
     414      array_push($page['errors'], l10n('You can\'t use more than one level filter'));
     415    }
     416    else
     417    {
     418      $level_is_set = true;
     419    }
     420  }
    283421  # limit
    284422  else if ($filter['type'] == 'limit')
     
    292430    {
    293431      $error = true;
    294       array_push($page['errors'], l10n('You can\'t use more than one limit'));
     432      array_push($page['errors'], l10n('You can\'t use more than one limit filter'));
    295433    }
    296434    else
     
    374512  }
    375513}
     514
    376515?>
  • extensions/SmartAlbums/include/index.php

    r11380 r16104  
    11<?php
    2 // +-----------------------------------------------------------------------+
    3 // | Piwigo - a PHP based photo gallery                                    |
    4 // +-----------------------------------------------------------------------+
    5 // | Copyright(C) 2008-2011 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 // Recursive call
    252$url = '../';
    263header( 'Request-URI: '.$url );
  • extensions/SmartAlbums/include/page_items.php

    r12863 r16104  
    33
    44/**
    5  * Remove form $page['items'] picture that musn't be displayed
     5 * Remove picture that musn't be displayed from $page['items']
    66 *
    77 * here we get all pictures that current user could see
Note: See TracChangeset for help on using the changeset viewer.