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

test version

Location:
extensions/SmartAlbums/include
Files:
2 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 *
Note: See TracChangeset for help on using the changeset viewer.