Changeset 10980


Ignore:
Timestamp:
May 21, 2011, 6:16:47 PM (13 years ago)
Author:
mistic100
Message:

test version

Location:
extensions/SmartAlbums
Files:
2 added
6 edited

Legend:

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

    r10871 r10980  
    11<?php
     2/**
     3 * Count images for AJAX info
     4 */
     5
    26define('PHPWG_ROOT_PATH','./../../../');
    37define('IN_ADMIN', true);
    48include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
     9include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
    510include_once(SMART_PATH.'include/functions.inc.php');
    611
    7 $error = false;
     12$filters = array();
     13$limit_is_set = false;
    814foreach ($_POST['filters'] as $filter)
    915{
    10   if ($filter['type'] == 'tags')
     16  if (($filter = smart_check_filter($filter)) != false)
    1117  {
    12     $filter['value'] = str_replace(' ', null, $filter['value']);
    13   }
    14   else if ($filter['type'] == 'date')
    15   {
    16     if (!preg_match('#([0-9]{4})-([0-9]{2})-([0-9]{2})#', $filter['value']))
    17     {
    18       $error = true;
    19     }
    20   }
    21   else if ($filter['type'] == 'limit')
    22   {
    23     if (!preg_match('#([0-9]{1,})#', $filter['value']))
    24     {
    25       $error = true;
    26     }
    27     else if (isset($limit_is_set))
    28     {
    29       $error = true;
    30     }
    31     else
    32     {
    33       $limit_is_set = true;
    34     }
     18    array_push($filters, $filter);
    3519  }
    3620}
    3721
    38 if ($error == false)
    39 {
    40   $associated_images = SmartAlbums_get_pictures($_POST['cat_id'], $_POST['filters']);
    41   echo l10n_dec('%d photo', '%d photos', count($associated_images));
    42 }
    43 else
    44 {
    45   echo 'error';
    46 }
     22$associated_images = smart_get_pictures($_POST['cat_id'], $filters);
     23echo l10n_dec('%d photo', '%d photos', count($associated_images));
     24
    4725?>
  • extensions/SmartAlbums/include/functions.inc.php

    r10871 r10980  
    77 * @return array
    88 */
    9 function SmartAlbums_make_associations($cat_id)
     9function smart_make_associations($cat_id)
    1010{
    1111  pwg_query("DELETE FROM ".IMAGE_CATEGORY_TABLE." WHERE category_id = ".$cat_id." AND smart = true;");
    1212 
    13   $images = SmartAlbums_get_pictures($cat_id);
    14   $dbfields = array('image_id', 'category_id', 'smart');
     13  $images = smart_get_pictures($cat_id);
    1514 
    1615  if (count($images) != 0)
     
    2423      );
    2524    }
    26     mass_inserts_ignore(IMAGE_CATEGORY_TABLE, $dbfields, $datas);
     25    mass_inserts_ignore(
     26      IMAGE_CATEGORY_TABLE,
     27      array_keys($datas[0]),
     28      $datas
     29    );
     30    set_random_representant(array($cat_id));
    2731  }
    2832 
     
    3741 * @return array
    3842 */
    39 function SmartAlbums_get_pictures($cat_id, $filters = null)
     43function smart_get_pictures($cat_id, $filters = null)
    4044{
    4145  global $conf;
     
    165169
    166170/**
     171 * Check if the filter is proper
     172 *
     173 * @param array filter
     174 * @return array or false
     175 */
     176function smart_check_filter($filter)
     177{
     178  global $limit_is_set, $page;
     179  $error = false;
     180 
     181  # tags
     182  if ($filter['type'] == 'tags')
     183  {
     184    if ($filter['value'] == null) // tags fields musn't be null
     185    {
     186      $error = true;
     187      array_push($page['errors'], l10n('No tag selected'));
     188    }
     189    else
     190    {
     191      $filter['value'] = implode(',', get_fckb_tag_ids($filter['value']));
     192    }
     193  }
     194  # date
     195  else if ($filter['type'] == 'date')
     196  {
     197    if (!preg_match('#([0-9]{4})-([0-9]{2})-([0-9]{2})#', $filter['value'])) // dates must be proper
     198    {
     199      $error = true;
     200      array_push($page['errors'], l10n('Date string is malformed'));
     201    }
     202  }
     203  # limit
     204  else if ($filter['type'] == 'limit')
     205  {
     206    if (!preg_match('#([0-9]{1,})#', $filter['value'])) // limit must be an integer
     207    {
     208      $error = true;
     209      array_push($page['errors'], l10n('Limit must be an integer'));
     210    }
     211    else if ($limit_is_set == true) // only one limit is allowed, first is saved
     212    {
     213      $error = true;
     214      array_push($page['errors'], l10n('You can\'t use more than one limit'));
     215    }
     216    else
     217    {
     218      $limit_is_set = true;
     219    }
     220  }
     221 
     222  # out
     223  if ($error == false)
     224  {
     225    return $filter;
     226  }
     227  else
     228  {
     229    return false;
     230  }
     231}
     232
     233
     234/**
    167235 * inserts multiple lines in a table, ignore duplicate entries
    168236 *
  • extensions/SmartAlbums/init_cat_modify.php

    r10871 r10980  
    11<?php
    22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    3 
     3/**
     4 * Add the SmartAlbums configuration tool to virtual cats' configuration page
     5 */
     6 
    47function smart_cat_modify()
    58{
    69  global $template;
    710  include_once(SMART_PATH.'include/functions.inc.php');
     11 
    812  $cat_id = $_GET['cat_id'];
     13  list($cat_dir) = pwg_db_fetch_row(pwg_query("SELECT dir FROM ".CATEGORIES_TABLE." WHERE id = ".$cat_id.";"));
    914 
     15  // category must be virtual
     16  if ($cat_dir != NULL)
     17  {
     18    return;
     19  }
     20 
     21  /* SAVE FILTERS */
    1022  if (isset($_POST['submitFilters']))
    1123  {
    1224    // test if it was a Smart Album
    1325    $result = pwg_query("SELECT DISTINCT category_id FROM ".CATEGORY_FILTERS_TABLE." WHERE category_id = ".$cat_id.";");
    14     $_was_smart = pwg_db_num_rows($result);
     26    $was_smart = pwg_db_num_rows($result);
    1527   
    1628    /* this album is no longer a SmartAlbum */
    17     if ($_was_smart AND !isset($_POST['is_smart']))
     29    if ($was_smart AND !isset($_POST['is_smart']))
    1830    {
    1931      pwg_query("DELETE FROM ".IMAGE_CATEGORY_TABLE." WHERE category_id = ".$cat_id." AND smart = true;");
     
    2941    {
    3042      pwg_query("DELETE FROM ".CATEGORY_FILTERS_TABLE." WHERE category_id = ".$cat_id.";");
    31 
     43     
     44      $limit_is_set = false;
    3245      foreach ($_POST['filters'] as $filter)
    3346      {
    34         $error = false;
    35         if ($filter['type'] == 'tags')
    36         {
    37           $filter['value'] = str_replace(' ', null, $filter['value']);
    38         }
    39         else if ($filter['type'] == 'date')
    40         {
    41           if (!preg_match('#([0-9]{4})-([0-9]{2})-([0-9]{2})#', $filter['value']))
    42           {
    43             $error = true;
    44             array_push($page['errors'], l10n('Date string is malformed'));
    45           }
    46         }
    47         else if ($filter['type'] == 'limit')
    48         {
    49           if (!preg_match('#([0-9]{1,})#', $filter['value']))
    50           {
    51             $error = true;
    52             array_push($page['errors'], l10n('Limit must be an integer'));
    53           }
    54           else if (isset($limit_is_set))
    55           {
    56             $error = true;
    57             array_push($page['errors'], l10n('You can\'t use more than one limit'));
    58           }
    59           else
    60           {
    61             $limit_is_set = true;
    62           }
    63         }
    64        
    65         if ($error == false)
     47        if (($filter = smart_check_filter($filter)) != false)
    6648        {
    6749          pwg_query("INSERT INTO ".CATEGORY_FILTERS_TABLE."
     
    7052      }
    7153     
    72       $associated_images = SmartAlbums_make_associations($cat_id);
     54      $associated_images = smart_make_associations($cat_id);
     55      invalidate_user_cache(true);
    7356      $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', count($associated_images)));
    74      
    75       set_random_representant(array($cat_id));
    76       invalidate_user_cache(true);
    7757    }
    7858  }
    7959     
    80   /* select options */
     60  /* select options, for html_options */
    8161  $template->assign('options', array(
    8262    'tags' => array(
     
    9171      'after' => l10n('Added after the'),
    9272      ),
    93     'limit' => array('limit' => 'limit'),
     73    'limit' => array('limit' => 'limit'), // second filter not used
    9474  ));
    9575 
     
    9878  while ($filter = pwg_db_fetch_assoc($filters))
    9979  {
     80    // get tags name and id
     81    if ($filter['type'] == 'tags')
     82    {
     83      $query = "
     84        SELECT
     85          id AS tag_id,
     86          name AS tag_name
     87        FROM ".TAGS_TABLE."
     88        WHERE id IN(".$filter['value'].")
     89      ";
     90      $filter['value'] = get_fckb_taglist($query);
     91    }
     92   
    10093    $template->append('filters', array(
    10194      'TYPE' => $filter['type'],
  • extensions/SmartAlbums/main.inc.php

    r10871 r10980  
    33Plugin Name: SmartAlbums
    44Version: auto
    5 Description: Easy create dynamic albums with tags, date and other criteria
    6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=
     5Description: Easily create dynamic albums with tags, date and other criteria
     6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=544
    77Author: Mistic
    88Author URI: http://www.strangeplanet.fr
     
    1818if (script_basename() == 'admin')
    1919{
    20   include_once(SMART_PATH.'init_cat_modify.php');
     20  add_event_handler('loc_begin_cat_modify', 'smart_init_cat_modify');
     21  function smart_init_cat_modify()
     22  {
     23    include_once(SMART_PATH.'init_cat_modify.php');
     24    smart_cat_modify();
     25  }
    2126 
    22   add_event_handler('loc_begin_cat_modify', 'smart_cat_modify'); 
     27  add_event_handler('loc_begin_cat_list', 'smart_init_cat_list');
     28  function smart_init_cat_list()
     29  {
     30    include_once(SMART_PATH.'init_cat_list.php');
     31    smart_cat_list();
     32  }
    2333}
    2434
  • extensions/SmartAlbums/template/cat_modify.tpl

    r10871 r10980  
    11{combine_css path=$SMART_PATH|@cat:"template/style.css"}
    22{include file='include/datepicker.inc.tpl'}
    3 {combine_script id='jquery.fcbkcomplete' load='async' require='jquery' path='themes/default/js/plugins/jquery.fcbkcomplete.js'}
     3{combine_script id='jquery.tokeninput' load='async' require='jquery' path='themes/default/js/plugins/jquery.tokeninput.js'}
    44
    5 {footer_script require='jquery,jquery.fcbkcomplete'}
     5{footer_script require='jquery.tokeninput'}
    66var lang = new Array();
    77lang['tags filter'] = "{'tags filter'|@translate}";
     
    3434  $('input[name="is_smart"]').change(function() {
    3535    $('#SmartAlbum_options').toggle();
    36     $('input[name="count_images"]').toggle();
     36    $('input[name="countImages"]').toggle();
    3737  });
    3838 
    39   $('input[name="count_images"]').click(function() {
    40     count_images($(this).closest('form'));
     39  $('input[name="countImages"]').click(function() {
     40    countImages($(this).closest('form'));
    4141    return false;
    4242  });
    4343 
    4444  function add_filter(type) {
     45    // add line
    4546    $('<li class="filter_'+ type +'" id="filter_'+ i +'"></li>').appendTo('#filterList');
    4647   
    47     $('#filter_'+ i).html(
    48       '<a href="#" class="removeFilter" title="'+ lang['remove this filter'] +'"><span>[x]</span></a>'+
    49       '<input type="hidden" name="filters['+ i +'][type]" value="'+ type +'"/>'+
    50       ' '+ lang[type +' filter'] +
    51      
    52       ' <select name="filters['+ i +'][cond]">'+ options[type] +'</select>'+
    53       ' <input type="text" name="filters['+ i +'][value]"/>'
    54     );
     48    //set content
     49    content = '<a href="#" class="removeFilter" title="'+ lang['remove this filter'] +'"><span>[x]</span></a>'+
     50    '<input type="hidden" name="filters['+ i +'][type]" value="'+ type +'"/>&nbsp;'+ lang[type +' filter'] +
     51    '&nbsp;<select name="filters['+ i +'][cond]">'+ options[type] +'</select>';
    5552   
    56     // reinit handler
     53    if (type == 'tags') {
     54      content += '&nbsp;<select name="filters['+ i +'][value]" class="tagSelect"></select>';
     55    } else {
     56      content += '&nbsp;<input type="text" name="filters['+ i +'][value]"/>';
     57    }
     58   
     59    $('#filter_'+ i).html(content);
     60   
     61    // reinit handlers
    5762    init_jquery_handlers();
    5863    i++;
     
    6974    });
    7075   
    71     $('.filter_tags input[type="text"]').each(function() {
    72       if ($(this).hasClass('fcbk_initialized') == false) {
    73         $(this).fcbkcomplete({
    74           json_url: "admin.php?fckb_tags=1",
    75           cache: false,
    76           filter_case: false,
    77           filter_hide: true,
    78           firstselected: true,
    79           filter_selected: true,
    80           maxitems: 100,
    81           newel: false
    82         });
    83         $(this).addClass('fcbk_initialized');
    84       }
     76    jQuery.getJSON('admin.php?fckb_tags=1', function(data) {
     77      jQuery(".tagSelect").tokenInput(
     78        data,
     79        {
     80      {/literal}
     81          hintText: '{'Type in a search term'|@translate}',
     82          noResultsText: '{'No results'|@translate}',
     83          searchingText: '{'Searching...'|@translate}',
     84          animateDropdown: false,
     85          preventDuplicates: true,
     86          allowCreation: true
     87      {literal}
     88        }
     89      );
    8590    });
    8691  }
    8792 
    88   function count_images(form) {
     93  function countImages(form) {
    8994{/literal}
    9095                jQuery.post("{$COUNT_SCRIPT_URL}", 'cat_id={$CAT_ID}&'+form.serialize(),
     
    122127        </select>
    123128       
     129      {if $filter.TYPE == 'tags'}
     130        <select name="filters[{$i}][value]" class="tagSelect">
     131        {foreach from=$filter.VALUE item=tag}
     132          <option value="{$tag.id}" class="selected">{$tag.name}</option>
     133        {/foreach}
     134        </select>
     135      {else}
    124136        <input type="text" name="filters[{$i}][value]" value="{$filter.VALUE}"/>
     137      {/if}
    125138      </li>
    126139                        {counter}
     
    144157  <p class="actionButtons" id="applyFilterBlock">
    145158    <input class="submit" type="submit" value="{'Submit'|@translate}" name="submitFilters"/>
    146     <input class="submit" type="submit" value="{'Count'|@translate}" name="count_images" {if !isset($filters)}style="display:none;"{/if}/>
     159    <input class="submit" type="submit" value="{'Count'|@translate}" name="countImages" {if !isset($filters)}style="display:none;"{/if}/>
    147160    <span class="count_images_display">{$IMAGE_COUNT}</span>
    148161  </p>
  • extensions/SmartAlbums/template/style.css

    r10871 r10980  
    22  display:none;
    33}
     4.token-input-list {
     5  display:inline-block;
     6  vertical-align:bottom;
     7}
     8#batchManagerGlobal #filterList li.token-input-token {
     9  margin-bottom:3px !important
     10}
     11#batchManagerGlobal #filterList li.token-input-input-token {
     12  margin-bottom:0px !important;
     13}
Note: See TracChangeset for help on using the changeset viewer.