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

test version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.