From d700a5917233fb8049589a9e0aef3d94e87fb320 Mon Sep 17 00:00:00 2001 From: rvelices Date: Thu, 6 Apr 2006 02:23:54 +0000 Subject: 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) git-svn-id: http://piwigo.org/svn/trunk@1131 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/section_init.inc.php | 86 ++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 38 deletions(-) (limited to 'include/section_init.inc.php') diff --git a/include/section_init.inc.php b/include/section_init.inc.php index e22979e69..c29686e6f 100644 --- a/include/section_init.inc.php +++ b/include/section_init.inc.php @@ -70,7 +70,7 @@ else } $page['root_path'] = PHPWG_ROOT_PATH; } -//phpinfo(); + // deleting first "/" if displayed $tokens = explode( '/', @@ -147,33 +147,58 @@ else if (0 === strpos($tokens[$next_token], 'tag')) $next_token++; $i = $next_token; + $requested_tag_ids = array(); + $requested_tag_url_names = array(); + while (isset($tokens[$i])) { - preg_match('/^(\d+)(?:-(.*))?/', $tokens[$i], $matches); - if (!isset($matches[1])) + if ( preg_match('/^(created-|posted-|start-(\d)+)/', $tokens[$i]) ) + break; + + if ( preg_match('/^(\d+)(?:-(.*))?/', $tokens[$i], $matches) ) { - if (0 == count($page['tags'])) - { - die('Fatal: at least one tag required'); - } - else - { - break; - } + array_push($requested_tag_ids, $matches[1]); + } + else + { + array_push($requested_tag_url_names, "'".$tokens[$i]."'"); } - - array_push( - $page['tags'], - array( - 'id' => $matches[1], - 'url_name' => isset($matches[2]) ? $matches[2] : '', - ) - ); - $i++; } - $next_token = $i; + + if ( empty($requested_tag_ids) && empty($requested_tag_url_names) ) + { + die('Fatal: at least one tag required'); + } + // tag infos + $query = ' +SELECT name, url_name, id + FROM '.TAGS_TABLE.' + WHERE '; + if ( !empty($requested_tag_ids) ) + { + $query.= 'id IN ('.implode(',', $requested_tag_ids ).')'; + } + if ( !empty($requested_tag_url_names) ) + { + if ( !empty($requested_tag_ids) ) + { + $query.= ' OR '; + } + $query.= 'url_name IN ('.implode(',', $requested_tag_url_names ).')'; + } + $result = pwg_query($query); + $tag_infos = array(); + while ($row = mysql_fetch_array($result)) + { + $tag_infos[ $row['id'] ] = $row; + array_push($page['tags'], $row );//we loose given tag order; is it important? + } + if ( empty($page['tags']) ) + { + die('Fatal: no existing tag'); + } } else if (0 === strpos($tokens[$next_token], 'fav')) { @@ -239,7 +264,7 @@ while (isset($tokens[$i])) $page['start'] = $matches[1]; } - if (preg_match('/^posted|created/', $tokens[$i] )) + if (preg_match('/^(posted|created)/', $tokens[$i] )) { $chronology_tokens = explode('-', $tokens[$i] ); @@ -359,7 +384,7 @@ else // permissions depends on category, so to only keep images that are // reachable to the connected user, we need to check category // associations - if (!empty($user['forbidden_categories']) and !empty($items) ) + if (!empty($items) ) { $query = ' SELECT image_id @@ -373,21 +398,6 @@ SELECT image_id ); } - // tag names - $query = ' -SELECT name, url_name, id - FROM '.TAGS_TABLE.' - WHERE id IN ('.implode(',', $page['tag_ids']).') -;'; - $result = pwg_query($query); - $tag_infos = array(); - - while ($row = mysql_fetch_array($result)) - { - $tag_infos[ $row['id'] ]['name'] = $row['name']; - $tag_infos[ $row['id'] ]['url_name'] = $row['url_name']; - } - $title = count($page['tags']) > 1 ? l10n('Tags') : l10n('Tag'); $title.= ' '; -- cgit v1.2.3