Ignore:
Timestamp:
Apr 6, 2006, 4:23:54 AM (18 years ago)
Author:
rvelices
Message:

improvement: urls for tags can contain now only the tag or the id and tag

improvement: urls for category can be now id and category names (instead
of only id)

improvement: added 2 indexes (#image_tag.tag_id and #tags.url_name)

improvement: identification, register, search pages automatically set focus
on first form input

improvement: focus, nofocus css class now valid for all forms

fix: category comment is tag stripped in category_subcats.inc.php
(otherwise issues with html/scripts inside category comment)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/section_init.inc.php

    r1125 r1131  
    7171  $page['root_path'] = PHPWG_ROOT_PATH;
    7272}
    73 //phpinfo();
     73
    7474// deleting first "/" if displayed
    7575$tokens = explode(
     
    148148  $i = $next_token;
    149149
     150  $requested_tag_ids = array();
     151  $requested_tag_url_names = array();
     152
    150153  while (isset($tokens[$i]))
    151154  {
    152     preg_match('/^(\d+)(?:-(.*))?/', $tokens[$i], $matches);
    153     if (!isset($matches[1]))
    154     {
    155       if (0 == count($page['tags']))
    156       {
    157         die('Fatal: at least one tag required');
    158       }
    159       else
    160       {
    161         break;
    162       }
    163     }
    164 
    165     array_push(
    166       $page['tags'],
    167       array(
    168         'id'       => $matches[1],
    169         'url_name' => isset($matches[2]) ? $matches[2] : '',
    170         )
    171       );
    172 
     155    if ( preg_match('/^(created-|posted-|start-(\d)+)/', $tokens[$i]) )
     156      break;
     157
     158    if ( preg_match('/^(\d+)(?:-(.*))?/', $tokens[$i], $matches) )
     159    {
     160      array_push($requested_tag_ids, $matches[1]);
     161    }
     162    else
     163    {
     164      array_push($requested_tag_url_names, "'".$tokens[$i]."'");
     165    }
    173166    $i++;
    174167  }
    175 
    176168  $next_token = $i;
     169
     170  if ( empty($requested_tag_ids) && empty($requested_tag_url_names) )
     171  {
     172    die('Fatal: at least one tag required');
     173  }
     174  // tag infos
     175  $query = '
     176SELECT name, url_name, id
     177  FROM '.TAGS_TABLE.'
     178  WHERE ';
     179  if ( !empty($requested_tag_ids) )
     180  {
     181    $query.= 'id IN ('.implode(',', $requested_tag_ids ).')';
     182  }
     183  if ( !empty($requested_tag_url_names) )
     184  {
     185    if ( !empty($requested_tag_ids) )
     186    {
     187      $query.= ' OR ';
     188    }
     189    $query.= 'url_name IN ('.implode(',', $requested_tag_url_names ).')';
     190  }
     191  $result = pwg_query($query);
     192  $tag_infos = array();
     193  while ($row = mysql_fetch_array($result))
     194  {
     195    $tag_infos[ $row['id'] ] = $row;
     196    array_push($page['tags'], $row );//we loose given tag order; is it important?
     197  }
     198  if ( empty($page['tags']) )
     199  {
     200    die('Fatal: no existing tag');
     201  }
    177202}
    178203else if (0 === strpos($tokens[$next_token], 'fav'))
     
    240265  }
    241266
    242   if (preg_match('/^posted|created/', $tokens[$i] ))
     267  if (preg_match('/^(posted|created)/', $tokens[$i] ))
    243268  {
    244269    $chronology_tokens = explode('-', $tokens[$i] );
     
    360385    // reachable to the connected user, we need to check category
    361386    // associations
    362     if (!empty($user['forbidden_categories']) and !empty($items) )
     387    if (!empty($items) )
    363388    {
    364389      $query = '
     
    372397        array_from_query($query, 'image_id')
    373398        );
    374     }
    375 
    376     // tag names
    377     $query = '
    378 SELECT name, url_name, id
    379   FROM '.TAGS_TABLE.'
    380   WHERE id IN ('.implode(',', $page['tag_ids']).')
    381 ;';
    382     $result = pwg_query($query);
    383     $tag_infos = array();
    384 
    385     while ($row = mysql_fetch_array($result))
    386     {
    387       $tag_infos[ $row['id'] ]['name'] = $row['name'];
    388       $tag_infos[ $row['id'] ]['url_name'] = $row['url_name'];
    389399    }
    390400
Note: See TracChangeset for help on using the changeset viewer.