Ignore:
Timestamp:
Jun 12, 2011, 5:56:09 PM (13 years ago)
Author:
mistic100
Message:

clean code, use TokenInput

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/SmartAlbums/init_cat_modify.php

    r10980 r11333  
    1111 
    1212  $cat_id = $_GET['cat_id'];
    13   list($cat_dir) = pwg_db_fetch_row(pwg_query("SELECT dir FROM ".CATEGORIES_TABLE." WHERE id = ".$cat_id.";"));
     13  list($cat_dir) = pwg_db_fetch_row(pwg_query('SELECT dir FROM '.CATEGORIES_TABLE.' WHERE id = '.$cat_id.';'));
    1414 
    1515  // category must be virtual
     
    2323  {
    2424    // test if it was a Smart Album
    25     $result = pwg_query("SELECT DISTINCT category_id FROM ".CATEGORY_FILTERS_TABLE." WHERE category_id = ".$cat_id.";");
     25    $result = pwg_query('SELECT DISTINCT category_id FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.';');
    2626    $was_smart = pwg_db_num_rows($result);
    2727   
     
    2929    if ($was_smart AND !isset($_POST['is_smart']))
    3030    {
    31       pwg_query("DELETE FROM ".IMAGE_CATEGORY_TABLE." WHERE category_id = ".$cat_id." AND smart = true;");
    32       pwg_query("DELETE FROM ".CATEGORY_FILTERS_TABLE." WHERE category_id = ".$cat_id.";");
     31      pwg_query('DELETE FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$cat_id.' AND smart = true;');
     32      pwg_query('DELETE FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.';');
    3333    }
    3434    /* no filter selected */
     
    4040    else if (isset($_POST['is_smart']) AND count($_POST['filters']) > 0)
    4141    {
    42       pwg_query("DELETE FROM ".CATEGORY_FILTERS_TABLE." WHERE category_id = ".$cat_id.";");
     42      pwg_query('DELETE FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.';');
    4343     
    4444      $limit_is_set = false;
     
    4747        if (($filter = smart_check_filter($filter)) != false)
    4848        {
    49           pwg_query("INSERT INTO ".CATEGORY_FILTERS_TABLE."
    50             VALUES(".$cat_id.", '".$filter['type']."', '".$filter['cond']."', '".$filter['value']."');");
     49          $query = '
     50INSERT INTO '.CATEGORY_FILTERS_TABLE.'
     51  VALUES(
     52    '.$cat_id.',
     53    "'.$filter['type'].'",
     54    "'.$filter['cond'].'",
     55    "'.$filter['value'].'"
     56  )
     57;';
     58        pwg_query($query);
    5159        }
    5260      }
     
    5967     
    6068  /* select options, for html_options */
    61   $template->assign('options', array(
    62     'tags' => array(
    63       'all' => l10n('All these tags'),
    64       'one' => l10n('One of these tags'),
    65       'none' => l10n('None of these tags'),
    66       'only' => l10n('Only these tags'),
    67       ),
    68     'date' => array(
    69       'the' => l10n('Added the'),
    70       'before' => l10n('Added before the'),
    71       'after' => l10n('Added after the'),
    72       ),
    73     'limit' => array('limit' => 'limit'), // second filter not used
    74   ));
     69  $template->assign(
     70    'options',
     71    array(
     72      'tags' => array(
     73        'all' => l10n('All these tags'),
     74        'one' => l10n('One of these tags'),
     75        'none' => l10n('None of these tags'),
     76        'only' => l10n('Only these tags'),
     77        ),
     78      'date' => array(
     79        'the' => l10n('Added the'),
     80        'before' => l10n('Added before the'),
     81        'after' => l10n('Added after the'),
     82        ),
     83      'limit' => array('limit' => 'limit'), // second filter not used
     84      )
     85    );
    7586 
    7687  /* get filters for this album */
    77   $filters = pwg_query("SELECT * FROM ".CATEGORY_FILTERS_TABLE." WHERE category_id = ".$cat_id." ORDER BY type ASC, cond ASC;");
     88  $filters = pwg_query('SELECT * FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.' ORDER BY type ASC, cond ASC;');
    7889  while ($filter = pwg_db_fetch_assoc($filters))
    7990  {
     
    8192    if ($filter['type'] == 'tags')
    8293    {
    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);
     94      $query = '
     95SELECT
     96    id AS tag_id,
     97    name AS tag_name
     98  FROM '.TAGS_TABLE.'
     99  WHERE id IN('.$filter['value'].')
     100';
     101      $filter['value'] = get_taglist($query);
    91102    }
    92103   
     
    98109  }
    99110 
     111  /* all tags */
     112  $query = '
     113SELECT
     114    id AS tag_id,
     115    name AS tag_name
     116  FROM '.TAGS_TABLE.'
     117;';
     118  $tags = get_taglist($query);
     119 
    100120  /* get image number */
    101121  if ($template->get_template_vars('IMAGE_COUNT') == null)
    102122  {
    103     list($image_num) = pwg_db_fetch_row(pwg_query("SELECT count(*) FROM ".IMAGE_CATEGORY_TABLE." WHERE category_id = ".$cat_id." AND smart = true;"));
     123    list($image_num) = pwg_db_fetch_row(pwg_query('SELECT count(*) FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$cat_id.' AND smart = true;'));
    104124    $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', $image_num));
    105125  }
     
    108128    'SMART_PATH' => SMART_PATH,
    109129    'COUNT_SCRIPT_URL' => SMART_PATH.'include/count_images.php',
     130    'tags' => $tags,
    110131  ));
    111132  $template->set_prefilter('categories', 'smart_cat_modify_prefilter');
Note: See TracChangeset for help on using the changeset viewer.