diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/category_default.inc.php | 51 | ||||
-rw-r--r-- | include/category_recent_cats.inc.php | 24 | ||||
-rw-r--r-- | include/category_subcats.inc.php | 30 | ||||
-rw-r--r-- | include/functions.inc.php | 229 | ||||
-rw-r--r-- | include/functions_category.inc.php | 15 | ||||
-rw-r--r-- | include/functions_html.inc.php | 16 | ||||
-rw-r--r-- | include/index.php | 3 | ||||
-rw-r--r-- | include/picture_comment.inc.php | 229 | ||||
-rw-r--r-- | include/picture_metadata.inc.php | 127 | ||||
-rw-r--r-- | include/picture_rate.inc.php | 126 | ||||
-rw-r--r-- | include/section_init.inc.php | 450 |
11 files changed, 1066 insertions, 234 deletions
diff --git a/include/category_default.inc.php b/include/category_default.inc.php index e401aec9b..599c527a9 100644 --- a/include/category_default.inc.php +++ b/include/category_default.inc.php @@ -26,7 +26,7 @@ // +-----------------------------------------------------------------------+ /** - * This file is included by category.php to show thumbnails for the default + * This file is included by the main page to show thumbnails for the default * case * */ @@ -81,25 +81,39 @@ foreach ($pictures as $row) } // url link on picture.php page - $url_link = PHPWG_ROOT_PATH.'picture.php?image_id='.$row['id']; + $url_link = PHPWG_ROOT_PATH.'picture.php?/'.$row['id']; - if (isset($page['cat'])) + switch ($page['section']) { - $url_link.= '&cat='.$page['cat']; - - if ($page['cat'] == 'search') + case 'categories' : + { + $url_link.= '/category/'.$page['category']; + break; + } + case 'tags' : + { + // TODO + break; + } + case 'search' : { - $url_link.= '&search='.$_GET['search']; + $url_link.= '/search/'.$page['search']; + break; } - else if ($page['cat'] == 'list') + case 'list' : { - $url_link.= '&list='.$_GET['list']; + $url_link.= '/list/'.implode(',', $page['list']); + break; + } + default : + { + $url_link.= '/'.$page['section']; } } - if (isset($_GET['calendar'])) + if (isset($page['chronology'])) { - $url_link.= '&calendar='.$_GET['calendar']; + $url_link.= '/chronology='.$page['chronology']; } $template->assign_block_vars( @@ -125,20 +139,23 @@ foreach ($pictures as $row) { $name = str_replace('_', ' ', get_filename_wo_extension($row['file'])); } - if ( isset($page['cat']) ) + + switch ($page['section']) { - if ($page['cat'] == 'best_rated') + case 'best_rated' : { $name = '('.$row['average_rate'].') '.$name; + break; } - elseif ($page['cat'] == 'most_visited') + case 'most_visited' : { $name = '('.$row['hit'].') '.$name; + break; } - - if ($page['cat'] == 'search') + case 'search' : { $name = replace_search($name, $_GET['search']); + break; } } @@ -151,7 +168,7 @@ foreach ($pictures as $row) } if ($user['show_nb_comments'] - and is_numeric($page['cat']) + and isset($page['category']) and $page['cat_commentable']) { $query = ' diff --git a/include/category_recent_cats.inc.php b/include/category_recent_cats.inc.php index 298def21d..2bc028ced 100644 --- a/include/category_recent_cats.inc.php +++ b/include/category_recent_cats.inc.php @@ -26,7 +26,7 @@ // +-----------------------------------------------------------------------+ /** - * This file is included by category.php to show thumbnails for recent_cats + * This file is included by the main page to show thumbnails for recent_cats * category * */ @@ -65,27 +65,25 @@ $conf['level_separator'] = '<br />'; // the name to display while ( $row = mysql_fetch_array( $result ) ) { - $name = get_cat_display_name_cache($row['uppercats'], '', false); - - $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']); - - $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$row['category_id']; - $template->assign_block_vars( 'thumbnails.line.thumbnail', array( - 'IMAGE' => $thumbnail_src, - 'IMAGE_ALT' => $row['file'], - 'IMAGE_TITLE' => $lang['hint_category'], - - 'U_IMG_LINK' => $url_link + 'IMAGE' => get_thumbnail_src($row['path'], @$row['tn_ext']), + 'IMAGE_ALT' => $row['file'], + 'IMAGE_TITLE' => $lang['hint_category'], + + 'U_IMG_LINK' => make_index_url( + array( + 'category' => $row['category_id'], + ) + ), ) ); $template->assign_block_vars( 'thumbnails.line.thumbnail.category_name', array( - 'NAME' => $name + 'NAME' => get_cat_display_name_cache($row['uppercats'], '', false), ) ); diff --git a/include/category_subcats.inc.php b/include/category_subcats.inc.php index 5f64a3a7f..3aa091269 100644 --- a/include/category_subcats.inc.php +++ b/include/category_subcats.inc.php @@ -26,7 +26,7 @@ // +-----------------------------------------------------------------------+ /** - * This file is included by category.php to show thumbnails for a category + * This file is included by the main page to show thumbnails for a category * that have only subcategories * */ @@ -34,16 +34,8 @@ $query = ' SELECT id, name, date_last, representative_picture_id FROM '.CATEGORIES_TABLE.' - WHERE id_uppercat '; -if (!isset($page['cat']) or !is_numeric($page['cat'])) -{ - $query.= 'is NULL'; -} -else -{ - $query.= '= '.$page['cat']; -} - $query.= ' + WHERE id_uppercat '. + (!isset($page['category']) ? 'is NULL' : '= '.$page['category']).' AND id NOT IN ('.$user['forbidden_categories'].') ORDER BY rank ;'; @@ -142,17 +134,19 @@ SELECT id, path, tn_ext foreach ($cat_thumbnails as $item) { - $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$row['id']; - $template->assign_block_vars( 'thumbnails.line.thumbnail', array( - 'IMAGE' => $images[$item['picture']], - 'IMAGE_ALT' => $item['name'], + 'IMAGE' => $images[$item['picture']], + 'IMAGE_ALT' => $item['name'], 'IMAGE_TITLE' => $lang['hint_category'], - 'IMAGE_TS' => get_icon(@$item['date_last']), - 'U_IMG_LINK' => - PHPWG_ROOT_PATH.'category.php?cat='.$item['category'] + 'IMAGE_TS' => get_icon(@$item['date_last']), + + 'U_IMG_LINK' => make_index_url( + array( + 'category' => $item['category'], + ) + ), ) ); diff --git a/include/functions.inc.php b/include/functions.inc.php index 205b61a70..9b628a93c 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -582,10 +582,12 @@ function get_thumbnail_src($path, $tn_ext = '') if ($tn_ext != '') { - $src = substr_replace(get_filename_wo_extension($path), - '/thumbnail/'.$conf['prefix_thumbnail'], - strrpos($path,'/'), - 1); + $src = substr_replace( + get_filename_wo_extension($path), + '/thumbnail/'.$conf['prefix_thumbnail'], + strrpos($path,'/'), + 1 + ); $src.= '.'.$tn_ext; } else @@ -1000,4 +1002,223 @@ function get_available_upgrade_ids() return $available_upgrade_ids; } + +/** + * build an index URL for a specific section + * + * @param array + * @return string + */ +function make_index_URL($params = array()) +{ + $url = + PHPWG_ROOT_PATH.'category.php?' + .'/'.make_section_in_URL($params) + ; + + if (isset($params['start']) and $params['start'] > 0) + { + $url.= '/start-'.$params['start']; + } + + return $url; +} + +/** + * build an index URL with current page parameters, but with redefinitions + * and removes. + * + * duplicate_index_URL(array('category' => 12), array('start')) will create + * an index URL on the current section (categories), but on a redefined + * category and without the start URL parameter. + * + * @param array redefined keys + * @param array removed keys + * @return string + */ +function duplicate_index_URL($redefined = array(), $removed = array()) +{ + return make_index_URL( + params_for_duplication($redefined, $removed) + ); +} + +/** + * returns $page global array with key redefined and key removed + * + * @param array redefined keys + * @param array removed keys + * @return array + */ +function params_for_duplication($redefined, $removed) +{ + global $page; + + if (count($removed) > 0) + { + $params = array(); + + foreach ($page as $page_item_key => $page_item_value) + { + if (!in_array($page_item_key, $removed)) + { + $params[$page_item_key] = $page_item_value; + } + } + } + else + { + $params = $page; + } + + foreach ($redefined as $redefined_param => $redefined_value) + { + $params[$redefined_param] = $redefined_value; + } + + return $params; +} + +/** + * create a picture URL with current page parameters, but with redefinitions + * and removes. See duplicate_index_URL. + * + * @param array redefined keys + * @param array removed keys + * @return string + */ +function duplicate_picture_URL($redefined = array(), $removed = array()) +{ + return make_picture_URL( + params_for_duplication($redefined, $removed) + ); +} + +/** + * create a picture URL on a specific section for a specific picture + * + * @param array + * @return string + */ +function make_picture_URL($params) +{ + if (!isset($params['image_id'])) + { + die('make_picture_URL: image_id is a required parameter'); + } + + $url = + PHPWG_ROOT_PATH.'picture.php?' + .'/'.$params['image_id'] + .'/'.make_section_in_URL($params) + ; + + // first comment to start on + if (isset($params['start']) and $params['start'] > 0) + { + $url.= '/start-'.$params['start']; + } + + return $url; +} + +/** + * return the section token of an index or picture URL. + * + * Depending on section, other parameters are required (see function code + * for details) + * + * @param array + * @return string + */ +function make_section_in_URL($params) +{ + $section_string = ''; + + if (!isset($params['section'])) + { + if (isset($params['section'])) + { + $params['section'] = 'categories'; + } + else if (isset($params['tags'])) + { + $params['section'] = 'tags'; + } + else if (isset($params['list'])) + { + $params['section'] = 'list'; + } + else if (isset($params['search'])) + { + $params['section'] = 'search'; + } + } + + if (!isset($params['section'])) + { + $params['section'] = 'categories'; + } + + switch($params['section']) + { + case 'categories' : + { + if (!isset($params['category'])) + { + $section_string.= 'categories'; + } + else + { + $section_string.= 'category/'.$params['category']; + } + + break; + } + case 'tags' : + { + if (!isset($params['tags']) or count($params['tags']) == 0) + { + die('make_section_in_URL: require at least one tag'); + } + + $section_string.= 'tags'; + + foreach ($params['tags'] as $tag) + { + $section_string.= '/'.$tag; + } + + break; + } + case 'search' : + { + if (!isset($params['search'])) + { + die('make_section_in_URL: require a search identifier'); + } + + $section_string.= 'search/'.$params['search']; + + break; + } + case 'list' : + { + if (!isset($params['list'])) + { + die('make_section_in_URL: require a list of items'); + } + + $section_string.= 'list/'.implode(',', $params['list']); + + break; + } + default : + { + $section_string.= $params['section']; + } + } + + return $section_string; +} ?> diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php index 2bc455775..8b5bd58a4 100644 --- a/include/functions_category.inc.php +++ b/include/functions_category.inc.php @@ -46,16 +46,13 @@ function check_restrictions($category_id) if (in_array($category_id, explode(',', $user['forbidden_categories']))) { - $login_url = './identification.php?redirect='. - urlencode(urlencode($_SERVER['REQUEST_URI'])); - if ( ! $user['is_the_guest'] ) + $login_url = + './identification.php?redirect=' + .urlencode(urlencode($_SERVER['REQUEST_URI'])); + + if (!$user['is_the_guest']) { - echo '<div style="text-align:center;">'; - echo $lang['hello'].' '.$user['username'].'! '; - echo $lang['access_forbiden'].'<br />'; - echo '<a href="./category.php">'.$lang['thumbnails'].'</a> '; - echo '</div>'; - exit(); + die('Fatal: you are trying to reach a forbidden category'); } else { diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php index d6bcdaf63..6e8a6c4d8 100644 --- a/include/functions_html.inc.php +++ b/include/functions_html.inc.php @@ -247,7 +247,7 @@ function language_select($default, $select_name = "language") * @return string */ function get_cat_display_name($cat_informations, - $url = 'category.php?cat=', + $url = 'category.php?/category/', $replace_space = true) { global $conf; @@ -300,7 +300,7 @@ function get_cat_display_name($cat_informations, * @return string */ function get_cat_display_name_cache($uppercats, - $url = 'category.php?cat=', + $url = 'category.php?/category/', $replace_space = true) { global $cat_names, $conf; @@ -355,7 +355,7 @@ SELECT id,name } /** - * returns the HTML code for a category item in the menu (for category.php) + * returns the HTML code for a category item in the menu (for the main page) * * HTML code generated uses logical list tags ul and each category is an * item li. The paramter given is the category informations as an array, @@ -374,10 +374,11 @@ function get_html_menu_category($categories) // $page_cat value remains 0 for special sections $page_cat = 0; - if (isset($page['cat']) and is_numeric($page['cat']) ) + if (isset($page['category'])) { - $page_cat = $page['cat']; + $page_cat = $page['category']; } + foreach ($categories as $category) { $level = substr_count($category['global_rank'], '.') + 1; @@ -404,7 +405,8 @@ function get_html_menu_category($categories) } $menu.= '>'; - $url = PHPWG_ROOT_PATH.'category.php?cat='.$category['id']; + $url = make_index_url(array('category' => $category['id'])); + $menu.= "\n".'<a href="'.$url.'"'; if ($page_cat != 0 and $category['id'] == $page['cat_id_uppercat']) @@ -466,7 +468,7 @@ function parse_comment_content($content) } function get_cat_display_name_from_id($cat_id, - $url = 'category.php?cat=', + $url = 'category.php?/category/', $replace_space = true) { $cat_info = get_cat_info($cat_id); diff --git a/include/index.php b/include/index.php index 84199eb29..0f1d97083 100644 --- a/include/index.php +++ b/include/index.php @@ -24,7 +24,8 @@ // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | // | USA. | // +-----------------------------------------------------------------------+ -$url = '../category.php'; + +$url = '../index.php'; header( 'Request-URI: '.$url ); header( 'Content-Location: '.$url ); header( 'Location: '.$url ); diff --git a/include/picture_comment.inc.php b/include/picture_comment.inc.php new file mode 100644 index 000000000..79373d2f7 --- /dev/null +++ b/include/picture_comment.inc.php @@ -0,0 +1,229 @@ +<?php +// +-----------------------------------------------------------------------+ +// | PhpWebGallery - a PHP based picture gallery | +// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | +// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | +// +-----------------------------------------------------------------------+ +// | branch : BSF (Best So Far) +// | file : $RCSfile$ +// | last update : $Date: 2006-03-09 00:14:53 +0100 (jeu, 09 mar 2006) $ +// | last modifier : $Author: rub $ +// | revision : $Revision: 1070 $ +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +/** + * This file is included by the picture page to manage user comments + * + */ + +if ( isset( $_POST['content'] ) && !empty($_POST['content']) ) +{ + $register_comment = true; + $author = !empty($_POST['author'])?$_POST['author']:$lang['guest']; + // if a guest try to use the name of an already existing user, he must be + // rejected + if ( $author != $user['username'] ) + { + $query = 'SELECT COUNT(*) AS user_exists'; + $query.= ' FROM '.USERS_TABLE; + $query.= ' WHERE '.$conf['user_fields']['username']." = '".$author."'"; + $query.= ';'; + $row = mysql_fetch_array( pwg_query( $query ) ); + if ( $row['user_exists'] == 1 ) + { + $template->assign_block_vars( + 'information', + array('INFORMATION'=>$lang['comment_user_exists'])); + $register_comment = false; + } + } + + if ( $register_comment ) + { + // anti-flood system + $reference_date = time() - $conf['anti-flood_time']; + $query = 'SELECT id FROM '.COMMENTS_TABLE; + $query.= ' WHERE date > FROM_UNIXTIME('.$reference_date.')'; + $query.= " AND author = '".$author."'"; + $query.= ';'; + if ( mysql_num_rows( pwg_query( $query ) ) == 0 + or $conf['anti-flood_time'] == 0 ) + { + list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); + + $data = array(); + $data{'author'} = $author; + $data{'date'} = $dbnow; + $data{'image_id'} = $page['image_id']; + $data{'content'} = htmlspecialchars( $_POST['content'], ENT_QUOTES); + + if (!$conf['comments_validation'] or is_admin()) + { + $data{'validated'} = 'true'; + $data{'validation_date'} = $dbnow; + } + else + { + $data{'validated'} = 'false'; + } + + include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); + $fields = array('author', 'date', 'image_id', 'content', 'validated', + 'validation_date'); + mass_inserts(COMMENTS_TABLE, $fields, array($data)); + + // information message + $message = $lang['comment_added']; + + if (!$conf['comments_validation'] or is_admin()) + + if ( $conf['comments_validation'] and !is_admin() ) + { + $message.= '<br />'.$lang['comment_to_validate']; + } + $template->assign_block_vars('information', + array('INFORMATION'=>$message)); + } + else + { + // information message + $template->assign_block_vars( + 'information', + array('INFORMATION'=>$lang['comment_anti-flood'])); + } + } +} + +// the picture is commentable if it belongs at least to one category which +// is commentable +$page['show_comments'] = false; +foreach ($related_categories as $category) +{ + if ($category['commentable'] == 'true') + { + $page['show_comments'] = true; + } +} + +if ($page['show_comments']) +{ + // number of comment for this picture + $query = 'SELECT COUNT(*) AS nb_comments'; + $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$page['image_id']; + $query.= " AND validated = 'true'"; + $query.= ';'; + $row = mysql_fetch_array( pwg_query( $query ) ); + + // navigation bar creation + $url = PHPWG_ROOT_PATH.'picture.php'; + $url.= get_query_string_diff(array('add_fav','start')); + +// $url = duplicate_picture_URL( +// array(), +// array('start') +// ); + + if (!isset($_GET['start']) + or !is_numeric($_GET['start']) + or (is_numeric($_GET['start']) and $_GET['start'] < 0)) + { + $page['start'] = 0; + } + else + { + $page['start'] = $_GET['start']; + } + $page['navigation_bar'] = create_navigation_bar( + $url, + $row['nb_comments'], + $page['start'], + $conf['nb_comment_page'], + '' + ); + + $template->assign_block_vars( + 'comments', + array( + 'NB_COMMENT' => $row['nb_comments'], + 'NAV_BAR' => $page['navigation_bar'], + ) + ); + + if ($row['nb_comments'] > 0) + { + $query = ' +SELECT id,author,date,image_id,content + FROM '.COMMENTS_TABLE.' + WHERE image_id = '.$page['image_id'].' + AND validated = \'true\' + ORDER BY date ASC + LIMIT '.$page['start'].', '.$conf['nb_comment_page'].' +;'; + $result = pwg_query( $query ); + + while ($row = mysql_fetch_array($result)) + { + $template->assign_block_vars( + 'comments.comment', + array( + 'COMMENT_AUTHOR' => empty($row['author']) + ? $lang['guest'] + : $row['author'], + + 'COMMENT_DATE' => format_date( + $row['date'], + 'mysql_datetime', + true), + + 'COMMENT' => parse_comment_content($row['content']), + ) + ); + + if (is_admin()) + { + $template->assign_block_vars( + 'comments.comment.delete', + array( + 'U_COMMENT_DELETE' => $url.'&del='.$row['id'] + ) + ); + } + } + } + + if (!$user['is_the_guest'] + or ($user['is_the_guest'] and $conf['comments_forall'])) + { + $template->assign_block_vars('comments.add_comment', array()); + // display author field if the user is not logged in + if (!$user['is_the_guest']) + { + $template->assign_block_vars( + 'comments.add_comment.author_known', + array('KNOWN_AUTHOR'=>$user['username']) + ); + } + else + { + $template->assign_block_vars( + 'comments.add_comment.author_field', array() + ); + } + } +} + +?>
\ No newline at end of file diff --git a/include/picture_metadata.inc.php b/include/picture_metadata.inc.php new file mode 100644 index 000000000..de910ad07 --- /dev/null +++ b/include/picture_metadata.inc.php @@ -0,0 +1,127 @@ +<?php +// +-----------------------------------------------------------------------+ +// | PhpWebGallery - a PHP based picture gallery | +// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | +// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | +// +-----------------------------------------------------------------------+ +// | branch : BSF (Best So Far) +// | file : $RCSfile$ +// | last update : $Date: 2006-03-09 00:14:53 +0100 (jeu, 09 mar 2006) $ +// | last modifier : $Author: rub $ +// | revision : $Revision: 1070 $ +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +/** + * This file is included by the picture page to manage picture metadata + * + */ + +if ($metadata_showable and isset($_GET['show_metadata'])) +{ + include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php'); + $template->assign_block_vars('metadata', array()); + if ($conf['show_exif']) + { + if (!function_exists('read_exif_data')) + { + die('Exif extension not available, admin should disable exif display'); + } + + if ($exif = @read_exif_data($picture['current']['src'])) + { + $template->assign_block_vars( + 'metadata.headline', + array('TITLE' => 'EXIF Metadata') + ); + + foreach ($conf['show_exif_fields'] as $field) + { + if (strpos($field, ';') === false) + { + if (isset($exif[$field])) + { + $key = $field; + if (isset($lang['exif_field_'.$field])) + { + $key = $lang['exif_field_'.$field]; + } + + $template->assign_block_vars( + 'metadata.line', + array( + 'KEY' => $key, + 'VALUE' => $exif[$field] + ) + ); + } + } + else + { + $tokens = explode(';', $field); + if (isset($exif[$tokens[0]][$tokens[1]])) + { + $key = $tokens[1]; + if (isset($lang['exif_field_'.$tokens[1]])) + { + $key = $lang['exif_field_'.$tokens[1]]; + } + + $template->assign_block_vars( + 'metadata.line', + array( + 'KEY' => $key, + 'VALUE' => $exif[$tokens[0]][$tokens[1]] + ) + ); + } + } + } + } + } + if ($conf['show_iptc']) + { + $iptc = get_iptc_data($picture['current']['src'], + $conf['show_iptc_mapping']); + + if (count($iptc) > 0) + { + $template->assign_block_vars( + 'metadata.headline', + array('TITLE' => 'IPTC Metadata') + ); + } + + foreach ($iptc as $field => $value) + { + $key = $field; + if (isset($lang[$field])) + { + $key = $lang[$field]; + } + + $template->assign_block_vars( + 'metadata.line', + array( + 'KEY' => $key, + 'VALUE' => $value + ) + ); + } + } +} + +?>
\ No newline at end of file diff --git a/include/picture_rate.inc.php b/include/picture_rate.inc.php new file mode 100644 index 000000000..67da9f0e8 --- /dev/null +++ b/include/picture_rate.inc.php @@ -0,0 +1,126 @@ +<?php +// +-----------------------------------------------------------------------+ +// | PhpWebGallery - a PHP based picture gallery | +// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | +// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | +// +-----------------------------------------------------------------------+ +// | branch : BSF (Best So Far) +// | file : $RCSfile$ +// | last update : $Date: 2006-03-09 00:14:53 +0100 (jeu, 09 mar 2006) $ +// | last modifier : $Author: rub $ +// | revision : $Revision: 1070 $ +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +/** + * This file is included by the picture page to manage rates + * + */ + +$rate_items = array(0,1,2,3,4,5); + +if ($conf['rate']) +{ + $query = ' +SELECT COUNT(rate) AS count + , ROUND(AVG(rate),2) AS average + , ROUND(STD(rate),2) AS STD + FROM '.RATE_TABLE.' + WHERE element_id = '.$picture['current']['id'].' +;'; + $row = mysql_fetch_array(pwg_query($query)); + if ($row['count'] == 0) + { + $value = $lang['no_rate']; + } + else + { + $value = sprintf( + l10n('%.2f (rated %d times, standard deviation = %.2f)'), + $row['average'], + $row['count'], + $row['STD'] + ); + } + + if ($conf['rate_anonymous'] or !$user['is_the_guest']) + { + if ($row['count']>0) + { + $query = 'SELECT rate + FROM '.RATE_TABLE.' + WHERE element_id = '.$page['image_id'] . ' + AND user_id = '.$user['id'] ; + + if ($user['is_the_guest']) + { + $ip_components = explode('.', $_SERVER['REMOTE_ADDR']); + if ( count($ip_components)>3 ) + { + array_pop($ip_components); + } + $anonymous_id = implode ('.', $ip_components); + $query .= ' AND anonymous_id = \''.$anonymous_id . '\''; + } + + $result = pwg_query($query); + if (mysql_num_rows($result) > 0) + { + $row = mysql_fetch_array($result); + $sentence = $lang['already_rated']; + $sentence.= ' ('.$row['rate'].'). '; + $sentence.= $lang['update_rate']; + } + else + { + $sentence = $lang['never_rated'].'. '.$lang['Rate']; + } + } + else + { + $sentence = $lang['never_rated'].'. '.$lang['Rate']; + } + $template->assign_block_vars( + 'rate', + array( + 'CONTENT' => $value, + 'SENTENCE' => $sentence + ) + ); + + $template->assign_block_vars('info_rate', array('CONTENT' => $value)); + + $template->assign_vars( + array( + 'INFO_RATE' => $value + ) + ); + + foreach ($rate_items as $num => $mark) + { + $template->assign_block_vars( + 'rate.rate_option', + array( + 'OPTION' => $mark, + 'URL' => $url_self.'&action=rate&rate='.$mark, + 'SEPARATOR' => ($num > 0 ? '|' : ''), + ) + ); + } + } +} + +?>
\ No newline at end of file diff --git a/include/section_init.inc.php b/include/section_init.inc.php index 68b82d463..c707e1e85 100644 --- a/include/section_init.inc.php +++ b/include/section_init.inc.php @@ -40,55 +40,170 @@ * display */ -unset($page['cat']); +// "index.php?/category/12-foo/start-24&action=fill_caddie" must return : +// +// array( +// 'section' => 'categories', +// 'category' => 12, +// 'start' => 24 +// 'action' => 'fill_caddie' +// ); -if (isset($_GET['cat'])) +$page['section'] = 'categories'; + +foreach (array_keys($_GET) as $keynum => $key) { - if (is_numeric($_GET['cat'])) - { - $page['cat'] = $_GET['cat']; - } - else if ($_GET['cat'] == 'fav' - or $_GET['cat'] == 'most_visited' - or $_GET['cat'] == 'best_rated' - or $_GET['cat'] == 'recent_pics' - or $_GET['cat'] == 'recent_cats') - { - $page['cat'] = $_GET['cat']; - } - else if ($_GET['cat'] == 'search') + if (0 == $keynum) { - if (!isset($_GET['search'])) + // deleting first "/" if displayed + $tokens = explode( + '/', + preg_replace('#^/#', '', $key) + ); + + // $tokens = array( + // 0 => category, + // 1 => 12-foo, + // 2 => start-24 + // ); + + $next_token = 0; + + if (basename($_SERVER['PHP_SELF']) == 'picture.php') { - die('search GET parameter is missing'); + // the first token must be the numeric identifier of the picture + preg_match('/(\d+)/', $tokens[$next_token], $matches); + if (!isset($matches[1])) + { + die('Fatal: picture identifier is missing'); + } + $page['image_id'] = $matches[1]; + + $next_token++; } - else if (!is_numeric($_GET['search'])) + + if (0 === strpos($tokens[$next_token], 'cat')) { - die('wrong format on search GET parameter'); + $page['section'] = 'categories'; + $next_token++; + + if (isset($tokens[$next_token]) + and preg_match('/(\d+)/', $tokens[$next_token], $matches)) + { + $page['category'] = $matches[1]; + $next_token++; + } } - else + else if (0 === strpos($tokens[$next_token], 'tag')) { - $page['cat'] = 'search'; + $page['section'] = 'tags'; + $page['tags'] = array(); + + $next_token++; + + for ($i = $next_token; ; $i++) + { + if (!isset($tokens[$i])) + { + break; + } + + preg_match('/^(\d+)/', $tokens[$i], $matches); + if (!isset($matches[1])) + { + if (0 == count($page['tags'])) + { + die('Fatal: at least one tag required'); + } + else + { + break; + } + } + array_push($page['tags'], $matches[1]); + } + + $next_token = $i; } - } - else if ($_GET['cat'] == 'list') - { - if (!isset($_GET['list'])) + else if (0 === strpos($tokens[$next_token], 'fav')) + { + $page['section'] = 'favorites'; + $next_token++; + } + else if ('most_visited' == $tokens[$next_token]) + { + $page['section'] = 'most_visited'; + $next_token++; + } + else if ('best_rated' == $tokens[$next_token]) { - die('list GET parameter is missing'); + $page['section'] = 'best_rated'; + $next_token++; } - else if (!preg_match('/^\d+(,\d+)*$/', $_GET['list'])) + else if ('recent_pics' == $tokens[$next_token]) { - die('wrong format on list GET parameter'); + $page['section'] = 'recent_pics'; + $next_token++; + } + else if ('recent_cats' == $tokens[$next_token]) + { + $page['section'] = 'recent_cats'; + $next_token++; + } + else if ('search' == $tokens[$next_token]) + { + $page['section'] = 'search'; + $next_token++; + + preg_match('/(\d+)/', $tokens[$next_token], $matches); + if (!isset($matches[1])) + { + die('Fatal: search identifier is missing'); + } + $page['search'] = $matches[1]; + $next_token++; + } + else if ('list' == $tokens[$next_token]) + { + $page['section'] = 'list'; + $next_token++; + + $page['list'] = array(); + if (!preg_match('/^\d+(,\d+)*$/', $tokens[$next_token])) + { + die('wrong format on list GET parameter'); + } + foreach (explode(',', $tokens[$next_token]) as $image_id) + { + array_push($page['list'], $image_id); + } + $next_token++; } else { - $page['cat'] = 'list'; + $page['section'] = 'categories'; + $next_token++; + } + + for ($i = $next_token; ; $i++) + { + if (!isset($tokens[$i])) + { + break; + } + + if (preg_match('/^start-(\d+)/', $tokens[$i], $matches)) + { + $page['start'] = $matches[1]; + } + + if (preg_match('/^calendar-(.+)$/', $tokens[$i], $matches)) + { + // TODO: decide with rvelices how we name calendar/chronology is the + // URL + $_GET['calendar'] = $matches[1]; + } } - } - else - { - die('unknown cat GET parameter value'); } } @@ -110,16 +225,15 @@ if (isset($_COOKIE['pwg_image_order']) $page['super_order_by'] = true; } -if (isset($page['cat'])) -{ - // +-----------------------------------------------------------------------+ // | category | // +-----------------------------------------------------------------------+ - if (is_numeric($page['cat'])) +if ('categories' == $page['section']) +{ + if (isset($page['category'])) { - $result = get_cat_info($page['cat']); - + $result = get_cat_info($page['category']); + $page = array_merge( $page, array( @@ -132,45 +246,52 @@ if (isset($page['cat'])) 'cat_commentable' => $result['commentable'], 'cat_id_uppercat' => $result['id_uppercat'], 'uppercats' => $result['uppercats'], - + 'title' => get_cat_display_name($result['name'], '', false), ) ); - if ( !isset($_GET['calendar']) ) + + if (!isset($_GET['calendar'])) { $query = ' SELECT image_id FROM '.IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON id = image_id - WHERE category_id = '.$page['cat'].' + WHERE category_id = '.$page['category'].' '.$conf['order_by'].' ;'; $page['items'] = array_from_query($query, 'image_id'); + $page['thumbnails_include'] = - $result['nb_images'] > 0 - ? 'include/category_default.inc.php' - : 'include/category_subcats.inc.php'; - }//otherwise the calendar will requery all subitems + $result['nb_images'] > 0 + ? 'include/category_default.inc.php' + : 'include/category_subcats.inc.php'; + } //otherwise the calendar will requery all subitems } - // special section else { - if (!empty($user['forbidden_categories'])) - { - $forbidden = - ' category_id NOT IN ('.$user['forbidden_categories'].')'; - } - else - { - $forbidden = ' 1=1'; - } - + $page['title'] = $lang['no_category']; + $page['thumbnails_include'] = 'include/category_subcats.inc.php'; + } +} +// special sections +else +{ + if (!empty($user['forbidden_categories'])) + { + $forbidden = + ' category_id NOT IN ('.$user['forbidden_categories'].')'; + } + else + { + $forbidden = ' 1 = 1'; + } // +-----------------------------------------------------------------------+ // | search section | // +-----------------------------------------------------------------------+ - if ( $page['cat'] == 'search' ) - { - $query = ' + if ($page['section'] == 'search') + { + $query = ' SELECT DISTINCT(id) FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id @@ -179,23 +300,23 @@ SELECT DISTINCT(id) '.$conf['order_by'].' ;'; - $page = array_merge( - $page, - array( - 'title' => $lang['search_result'], - 'items' => array_from_query($query, 'id'), - 'thumbnails_include' => 'include/category_default.inc.php', - ) - ); - } + $page = array_merge( + $page, + array( + 'title' => $lang['search_result'], + 'items' => array_from_query($query, 'id'), + 'thumbnails_include' => 'include/category_default.inc.php', + ) + ); + } // +-----------------------------------------------------------------------+ // | favorite section | // +-----------------------------------------------------------------------+ - else if ($page['cat'] == 'fav') - { - check_user_favorites(); + else if ($page['section'] == 'favorites') + { + check_user_favorites(); - $query = ' + $query = ' SELECT image_id FROM '.FAVORITES_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id @@ -203,147 +324,146 @@ SELECT image_id '.$conf['order_by'].' ;'; - $page = array_merge( - $page, - array( - 'title' => $lang['favorites'], - 'items' => array_from_query($query, 'image_id'), - 'thumbnails_include' => 'include/category_default.inc.php', - ) - ); - } + $page = array_merge( + $page, + array( + 'title' => $lang['favorites'], + 'items' => array_from_query($query, 'image_id'), + 'thumbnails_include' => 'include/category_default.inc.php', + ) + ); + } // +-----------------------------------------------------------------------+ // | recent pictures section | // +-----------------------------------------------------------------------+ - else if ($page['cat'] == 'recent_pics') - { - $query = ' + else if ($page['section'] == 'recent_pics') + { + $query = ' SELECT DISTINCT(id) FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id WHERE date_available > \''. - date('Y-m-d', time() - 60*60*24*$user['recent_period']).'\' + date('Y-m-d', time() - 60*60*24*$user['recent_period']).'\' AND '.$forbidden.' '.$conf['order_by'].' ;'; - $page = array_merge( - $page, - array( - 'title' => $lang['recent_pics_cat'], - 'items' => array_from_query($query, 'id'), - 'thumbnails_include' => 'include/category_default.inc.php', - ) - ); - } + $page = array_merge( + $page, + array( + 'title' => $lang['recent_pics_cat'], + 'items' => array_from_query($query, 'id'), + 'thumbnails_include' => 'include/category_default.inc.php', + ) + ); + } // +-----------------------------------------------------------------------+ // | recently updated categories section | // +-----------------------------------------------------------------------+ - else if ($page['cat'] == 'recent_cats') - { - $page = array_merge( - $page, - array( - 'title' => $lang['recent_cats_cat'], - 'cat_nb_images' => 0, - 'thumbnails_include' => 'include/category_recent_cats.inc.php', - ) - ); - } + else if ($page['section'] == 'recent_cats') + { + $page = array_merge( + $page, + array( + 'title' => $lang['recent_cats_cat'], + 'cat_nb_images' => 0, + 'thumbnails_include' => 'include/category_recent_cats.inc.php', + ) + ); + } // +-----------------------------------------------------------------------+ // | most visited section | // +-----------------------------------------------------------------------+ - else if ($page['cat'] == 'most_visited') - { - $page['super_order_by'] = true; - $conf['order_by'] = ' ORDER BY hit DESC, file ASC'; - $query = ' + else if ($page['section'] == 'most_visited') + { + $page['super_order_by'] = true; + $conf['order_by'] = ' ORDER BY hit DESC, file ASC'; + $query = ' SELECT DISTINCT(id) FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id WHERE hit > 0 - AND '.$forbidden. - $conf['order_by'].' + AND '.$forbidden.' + '.$conf['order_by'].' LIMIT 0, '.$conf['top_number'].' ;'; - - $page = array_merge( - $page, - array( - 'title' => $conf['top_number'].' '.$lang['most_visited_cat'], - 'items' => array_from_query($query, 'id'), - 'thumbnails_include' => 'include/category_default.inc.php', - ) - ); - } + + $page = array_merge( + $page, + array( + 'title' => $conf['top_number'].' '.$lang['most_visited_cat'], + 'items' => array_from_query($query, 'id'), + 'thumbnails_include' => 'include/category_default.inc.php', + ) + ); + } // +-----------------------------------------------------------------------+ // | best rated section | // +-----------------------------------------------------------------------+ - else if ($page['cat'] == 'best_rated') - { - $page['super_order_by'] = true; - $conf['order_by'] = ' ORDER BY average_rate DESC, id ASC'; - - $query =' + else if ($page['section'] == 'best_rated') + { + $page['super_order_by'] = true; + $conf['order_by'] = ' ORDER BY average_rate DESC, id ASC'; + + $query =' SELECT DISTINCT(id) FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id WHERE average_rate IS NOT NULL - AND '.$forbidden. - $conf['order_by'].' + AND '.$forbidden.' + '.$conf['order_by'].' LIMIT 0, '.$conf['top_number'].' ;'; - $page = array_merge( - $page, - array( - 'title' => $conf['top_number'].' '.$lang['best_rated_cat'], - 'items' => array_from_query($query, 'id'), - 'thumbnails_include' => 'include/category_default.inc.php', - ) - ); - } + $page = array_merge( + $page, + array( + 'title' => $conf['top_number'].' '.$lang['best_rated_cat'], + 'items' => array_from_query($query, 'id'), + 'thumbnails_include' => 'include/category_default.inc.php', + ) + ); + } // +-----------------------------------------------------------------------+ // | list section | // +-----------------------------------------------------------------------+ - else if ($page['cat'] == 'list') - { - $query =' + else if ($page['section'] == 'list') + { + $query =' SELECT DISTINCT(id) FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id - WHERE image_id IN ('.$_GET['list'].') + WHERE image_id IN ('.implode(',', $page['list']).') AND '.$forbidden.' '.$conf['order_by'].' ;'; - $page = array_merge( - $page, - array( - 'title' => $lang['random_cat'], - 'items' => array_from_query($query, 'id'), - 'thumbnails_include' => 'include/category_default.inc.php', - ) - ); - } - - if (!isset($page['cat_nb_images'])) - { - $page['cat_nb_images'] = count($page['items']); - } + + $page = array_merge( + $page, + array( + 'title' => $lang['random_cat'], + 'items' => array_from_query($query, 'id'), + 'thumbnails_include' => 'include/category_default.inc.php', + ) + ); + } + + if (!isset($page['cat_nb_images'])) + { + $page['cat_nb_images'] = count($page['items']); } } + // +-----------------------------------------------------------------------+ -// | root category | +// | chronology | // +-----------------------------------------------------------------------+ -else -{ - $page['title'] = $lang['no_category']; - $page['thumbnails_include'] = 'include/category_subcats.inc.php'; -} -if ( isset($_GET['calendar']) ) +if (isset($_GET['calendar'])) { include_once( PHPWG_ROOT_PATH.'include/functions_calendar.inc.php' ); initialize_calendar(); } +// echo '<pre>'; print_r($page); echo '</pre>'; + + ?>
\ No newline at end of file |