Changeset 1041
- Timestamp:
- Feb 14, 2006, 2:14:31 AM (19 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/config_default.inc.php
r1021 r1041 94 94 $conf['rate'] = true; 95 95 96 // rate_anonymous : visitors are able to rate pictures (requires 97 // $conf['rate'] set to true) 98 $conf['rate_anonymous'] = true; 99 96 100 // newcat_default_commentable : at creation, must a category be commentable 97 101 // or not ? -
trunk/include/section_init.inc.php
r1036 r1041 209 209 array( 210 210 'title' => $lang['favorites'], 211 'items' => array_from_query($query, 'i d'),211 'items' => array_from_query($query, 'image_id'), 212 212 'thumbnails_include' => 'include/category_default.inc.php', 213 213 ) -
trunk/install/phpwebgallery_structure.sql
r1028 r1041 174 174 `user_id` smallint(5) NOT NULL default '0', 175 175 `element_id` mediumint(8) unsigned NOT NULL default '0', 176 `anonymous_id` varchar(45) NOT NULL default '', 176 177 `rate` tinyint(2) unsigned NOT NULL default '0', 177 PRIMARY KEY (`user_id`,`element_id`) 178 `date` date NOT NULL default '0000-00-00', 179 PRIMARY KEY (`element_id`,`user_id`,`anonymous_id`) 178 180 ) TYPE=MyISAM; 179 181 -
trunk/picture.php
r1036 r1041 70 70 PHPWG_ROOT_PATH.'picture.php'. 71 71 get_query_string_diff( 72 array('image_id', 'add_fav', 'slideshow' , 'rate')72 array('image_id', 'add_fav', 'slideshow') 73 73 ). 74 74 '&image_id='.$page['items'][ $page['first_rank'] ], … … 90 90 PHPWG_ROOT_PATH.'picture.php'. 91 91 get_query_string_diff( 92 array('image_id', 'add_fav', 'slideshow' , 'rate')92 array('image_id', 'add_fav', 'slideshow') 93 93 ). 94 94 '&image_id='.$page['items'][ $page['last_rank'] ], … … 144 144 } 145 145 146 //---------------------------------------------------------- related categories147 $query = '148 SELECT category_id,uppercats,commentable,global_rank149 FROM '.IMAGE_CATEGORY_TABLE.'150 INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id151 WHERE image_id = '.$_GET['image_id'].'152 AND category_id NOT IN ('.$user['forbidden_categories'].')153 ;';154 $result = pwg_query($query);155 $related_categories = array();156 while ($row = mysql_fetch_array($result))157 {158 array_push($related_categories, $row);159 }160 usort($related_categories, 'global_rank_compare');161 //------------------------------------- prev, current & next picture management162 $picture = array();163 164 $ids = array($_GET['image_id']);165 if (isset($page['previous_item']))166 {167 array_push($ids, $page['previous_item']);168 }169 if (isset($page['next_item']))170 {171 array_push($ids, $page['next_item']);172 }173 174 $query = '175 SELECT *176 FROM '.IMAGES_TABLE.'177 WHERE id IN ('.implode(',', $ids).')178 ;';179 180 $result = pwg_query($query);181 182 while ($row = mysql_fetch_array($result))183 {184 if (isset($page['previous_item']) and $row['id'] == $page['previous_item'])185 {186 $i = 'prev';187 }188 else if (isset($page['next_item']) and $row['id'] == $page['next_item'])189 {190 $i = 'next';191 }192 else193 {194 $i = 'current';195 }196 197 foreach (array_keys($row) as $key)198 {199 if (!is_numeric($key))200 {201 $picture[$i][$key] = $row[$key];202 }203 }204 205 $picture[$i]['is_picture'] = false;206 if (in_array(get_extension($row['file']), $conf['picture_ext']))207 {208 $picture[$i]['is_picture'] = true;209 }210 211 $cat_directory = dirname($row['path']);212 $file_wo_ext = get_filename_wo_extension($row['file']);213 214 $icon = get_themeconf('mime_icon_dir');215 $icon.= strtolower(get_extension($row['file'])).'.png';216 217 if (isset($row['representative_ext']) and $row['representative_ext'] != '')218 {219 $picture[$i]['src'] =220 $cat_directory.'/pwg_representative/'221 .$file_wo_ext.'.'.$row['representative_ext'];222 }223 else224 {225 $picture[$i]['src'] = $icon;226 }227 // special case for picture files228 if ($picture[$i]['is_picture'])229 {230 $picture[$i]['src'] = $row['path'];231 // if we are working on the "current" element, we search if there is a232 // high quality picture233 if ($i == 'current')234 {235 if ($row['has_high']=='true')236 {237 $url_high=$cat_directory.'/pwg_high/'.$row['file'];238 $picture[$i]['high'] = $url_high;239 }240 }241 }242 243 // if picture is not a file, we need the download link244 if (!$picture[$i]['is_picture'])245 {246 $picture[$i]['download'] = $row['path'];247 }248 249 $picture[$i]['thumbnail'] = get_thumbnail_src($row['path'], @$row['tn_ext']);250 251 if ( !empty( $row['name'] ) )252 {253 $picture[$i]['name'] = $row['name'];254 }255 else256 {257 $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext);258 }259 260 $picture[$i]['url'] =261 PHPWG_ROOT_PATH.'picture.php'262 .get_query_string_diff(array('image_id', 'add_fav', 'slideshow', 'rate'))263 .'&image_id='.$row['id'];264 }265 266 $url_up = PHPWG_ROOT_PATH.'category.php?cat='.$page['cat'];267 268 $url_up_start = floor( $page['current_rank'] / $user['nb_image_page'] );269 $url_up_start *= $user['nb_image_page'];270 if ($url_up_start>0)271 {272 $url_up .= '&start='.$url_up_start;273 }274 275 if ( $page['cat'] == 'search' )276 {277 $url_up.= "&search=".$_GET['search'];278 }279 if ( $page['cat'] == 'list' )280 {281 $url_up.= "&list=".$_GET['list'];282 }283 284 $url_admin =285 PHPWG_ROOT_PATH.'admin.php?page=picture_modify'286 .'&cat_id='.$page['cat']287 .'&image_id='.$_GET['image_id'];288 289 $url_slide =290 $picture['current']['url'].'&slideshow='.$conf['slideshow_period'];291 146 292 147 //----------------------------------------------------------- rate registration 293 148 if (isset($_GET['rate']) 294 149 and $conf['rate'] 295 and !$user['is_the_guest']150 and ( !$user['is_the_guest'] or $conf['rate_anonymous'] ) 296 151 and in_array($_GET['rate'], $rate_items)) 297 152 { 153 if ($user['is_the_guest']) 154 { 155 $ip_components = explode('.', $_SERVER["REMOTE_ADDR"]); 156 if ( count($ip_components)>3 ) 157 { 158 array_pop($ip_components); 159 } 160 $anonymous_id = implode ('.', $ip_components); 161 162 if ( isset($_COOKIE['pwg_anonymous_rater']) ) 163 { 164 if ($anonymous_id != $_COOKIE['pwg_anonymous_rater'] ) 165 { // client has changed his IP adress or he's trying to fool us 166 $query = ' 167 SELECT element_id FROM '. RATE_TABLE . ' 168 WHERE user_id=' . $user['id'] . ' 169 AND anonymous_id=\'' . $anonymous_id . '\''; 170 $result = pwg_query($query); 171 $already_there = array(); 172 while ( $row = mysql_fetch_array($result) ) 173 { 174 array_push( $already_there, $row['element_id'] ); 175 } 176 177 if ( count($already_there)>0 ) 178 { 179 $query = ' 180 DELETE FROM '. RATE_TABLE . ' 181 WHERE user_id=' . $user['id'] . ' 182 AND anonymous_id=\'' . $_COOKIE['pwg_anonymous_rater'] . '\' 183 AND element_id NOT IN (' . implode(',',$already_there) . ')'; 184 pwg_query($query); 185 } 186 187 $query = ' 188 UPDATE '. RATE_TABLE . ' 189 SET anonymous_id=\'' . $anonymous_id . '\' 190 WHERE user_id=' . $user['id'] . ' 191 AND anonymous_id=\'' . $_COOKIE['pwg_anonymous_rater'] . '\''; 192 pwg_query($query); 193 194 setcookie('pwg_anonymous_rater', $anonymous_id, 195 strtotime('+10 years'), cookie_path() ); 196 } 197 } 198 else 199 { 200 setcookie('pwg_anonymous_rater', $anonymous_id, 201 strtotime('+10 years'), cookie_path() ); 202 } 203 } 204 298 205 $query = ' 299 DELETE 300 FROM '.RATE_TABLE.' 301 WHERE user_id = '.$user['id'].' 302 AND element_id = '.$_GET['image_id'].' 303 ;'; 206 DELETE FROM '.RATE_TABLE.' 207 WHERE element_id = '.$_GET['image_id'] . ' 208 AND user_id = '.$user['id'] 209 ; 210 if (isset($anonymous_id)) 211 { 212 $query.= ' AND anonymous_id=\'' . $anonymous_id .'\''; 213 } 304 214 pwg_query($query); 305 215 $query = ' 306 216 INSERT INTO '.RATE_TABLE.' 307 (user_id, element_id,rate)217 (user_id,anonymous_id,element_id,rate,date) 308 218 VALUES 309 ('.$user['id'].','.$_GET['image_id'].','.$_GET['rate'].') 219 ('.$user['id'].','.(isset($anonymous_id)?'\''.$anonymous_id.'\'':"''").','. 220 $_GET['image_id'].','.$_GET['rate'].',NOW()) 310 221 ;'; 311 222 pwg_query($query); … … 324 235 ;'; 325 236 pwg_query($query); 326 } 237 $url = 238 PHPWG_ROOT_PATH 239 .'picture.php' 240 .get_query_string_diff(array('rate')); 241 redirect($url); 242 } 243 244 245 //---------------------------------------------------------- related categories 246 $query = ' 247 SELECT category_id,uppercats,commentable,global_rank 248 FROM '.IMAGE_CATEGORY_TABLE.' 249 INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id 250 WHERE image_id = '.$_GET['image_id'].' 251 AND category_id NOT IN ('.$user['forbidden_categories'].') 252 ;'; 253 $result = pwg_query($query); 254 $related_categories = array(); 255 while ($row = mysql_fetch_array($result)) 256 { 257 array_push($related_categories, $row); 258 } 259 usort($related_categories, 'global_rank_compare'); 260 //------------------------------------- prev, current & next picture management 261 $picture = array(); 262 263 $ids = array($_GET['image_id']); 264 if (isset($page['previous_item'])) 265 { 266 array_push($ids, $page['previous_item']); 267 } 268 if (isset($page['next_item'])) 269 { 270 array_push($ids, $page['next_item']); 271 } 272 273 $query = ' 274 SELECT * 275 FROM '.IMAGES_TABLE.' 276 WHERE id IN ('.implode(',', $ids).') 277 ;'; 278 279 $result = pwg_query($query); 280 281 while ($row = mysql_fetch_array($result)) 282 { 283 if (isset($page['previous_item']) and $row['id'] == $page['previous_item']) 284 { 285 $i = 'prev'; 286 } 287 else if (isset($page['next_item']) and $row['id'] == $page['next_item']) 288 { 289 $i = 'next'; 290 } 291 else 292 { 293 $i = 'current'; 294 } 295 296 foreach (array_keys($row) as $key) 297 { 298 if (!is_numeric($key)) 299 { 300 $picture[$i][$key] = $row[$key]; 301 } 302 } 303 304 $picture[$i]['is_picture'] = false; 305 if (in_array(get_extension($row['file']), $conf['picture_ext'])) 306 { 307 $picture[$i]['is_picture'] = true; 308 } 309 310 $cat_directory = dirname($row['path']); 311 $file_wo_ext = get_filename_wo_extension($row['file']); 312 313 $icon = get_themeconf('mime_icon_dir'); 314 $icon.= strtolower(get_extension($row['file'])).'.png'; 315 316 if (isset($row['representative_ext']) and $row['representative_ext'] != '') 317 { 318 $picture[$i]['src'] = 319 $cat_directory.'/pwg_representative/' 320 .$file_wo_ext.'.'.$row['representative_ext']; 321 } 322 else 323 { 324 $picture[$i]['src'] = $icon; 325 } 326 // special case for picture files 327 if ($picture[$i]['is_picture']) 328 { 329 $picture[$i]['src'] = $row['path']; 330 // if we are working on the "current" element, we search if there is a 331 // high quality picture 332 if ($i == 'current') 333 { 334 if ($row['has_high']=='true') 335 { 336 $url_high=$cat_directory.'/pwg_high/'.$row['file']; 337 $picture[$i]['high'] = $url_high; 338 } 339 } 340 } 341 342 // if picture is not a file, we need the download link 343 if (!$picture[$i]['is_picture']) 344 { 345 $picture[$i]['download'] = $row['path']; 346 } 347 348 $picture[$i]['thumbnail'] = get_thumbnail_src($row['path'], @$row['tn_ext']); 349 350 if ( !empty( $row['name'] ) ) 351 { 352 $picture[$i]['name'] = $row['name']; 353 } 354 else 355 { 356 $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext); 357 } 358 359 $picture[$i]['url'] = 360 PHPWG_ROOT_PATH.'picture.php' 361 .get_query_string_diff(array('image_id', 'add_fav', 'slideshow')) 362 .'&image_id='.$row['id']; 363 } 364 365 $url_up = PHPWG_ROOT_PATH.'category.php?cat='.$page['cat']; 366 367 $url_up_start = floor( $page['current_rank'] / $user['nb_image_page'] ); 368 $url_up_start *= $user['nb_image_page']; 369 if ($url_up_start>0) 370 { 371 $url_up .= '&start='.$url_up_start; 372 } 373 374 if ( $page['cat'] == 'search' ) 375 { 376 $url_up.= "&search=".$_GET['search']; 377 } 378 if ( $page['cat'] == 'list' ) 379 { 380 $url_up.= "&list=".$_GET['list']; 381 } 382 383 $url_admin = 384 PHPWG_ROOT_PATH.'admin.php?page=picture_modify' 385 .'&cat_id='.$page['cat'] 386 .'&image_id='.$_GET['image_id']; 387 388 $url_slide = 389 $picture['current']['url'].'&slideshow='.$conf['slideshow_period']; 390 327 391 //--------------------------------------------------------- favorite management 328 392 if ( isset( $_GET['add_fav'] ) ) … … 344 408 if ( !$_GET['add_fav'] and $page['cat'] == 'fav' ) 345 409 { 346 if (! $has_prev and !$has_next)410 if (!isset($page['previous_item']) and !isset($page['next_item'])) 347 411 { 348 412 // there is no favorite picture anymore we redirect the user to the … … 350 414 redirect($url_up); 351 415 } 352 else if (! $has_prev)416 else if (!isset($page['previous_item'])) 353 417 { 354 418 $url = str_replace( '&', '&', $picture['next']['url'] ); … … 459 523 $title = $picture['current']['name']; 460 524 $refresh = 0; 461 if ( isset( $_GET['slideshow'] ) and $has_next)525 if ( isset( $_GET['slideshow'] ) and isset($page['next_item']) ) 462 526 { 463 527 $refresh= $_GET['slideshow']; … … 601 665 $template->assign_block_vars('high', array( 602 666 'U_HIGH' => $picture['current']['high'], 603 604 667 'UUID'=>$uuid 668 )); 605 669 $template->assign_block_vars( 606 670 'download', … … 618 682 'URL' => 619 683 PHPWG_ROOT_PATH.'picture.php' 620 .get_query_string_diff(array( ))684 .get_query_string_diff(array('add_fav')) 621 685 .'&representative=1' 622 686 ) … … 631 695 'URL' => 632 696 PHPWG_ROOT_PATH.'picture.php' 633 .get_query_string_diff(array(' caddie')).'&caddie=1')697 .get_query_string_diff(array('add_fav')).'&caddie=1') 634 698 ); 635 699 } … … 647 711 { 648 712 $url = PHPWG_ROOT_PATH.'picture.php'; 649 $url.= get_query_string_diff(array(' rate','add_fav'));713 $url.= get_query_string_diff(array('add_fav')); 650 714 $url.= '&add_fav=1'; 651 715 … … 662 726 { 663 727 $url = PHPWG_ROOT_PATH.'picture.php'; 664 $url.= get_query_string_diff(array(' rate','add_fav'));728 $url.= get_query_string_diff(array('add_fav')); 665 729 $url.= '&add_fav=0'; 666 730 … … 918 982 { 919 983 if ( !is_numeric( $_GET['slideshow'] ) ) $_GET['slideshow'] = $conf['slideshow_period']; 920 984 921 985 $template->assign_block_vars('stop_slideshow', array( 922 986 'U_SLIDESHOW'=>$picture['current']['url'] … … 948 1012 ); 949 1013 } 1014 1015 if ($conf['rate_anonymous'] or !$user['is_the_guest']) 1016 { 1017 if ($row['count']>0) 1018 { 1019 $query = 'SELECT rate 1020 FROM '.RATE_TABLE.' 1021 WHERE element_id = '.$_GET['image_id'] . ' 1022 AND user_id = '.$user['id'] ; 950 1023 951 if (!$user['is_the_guest']) 952 { 953 $query = 'SELECT rate 954 FROM '.RATE_TABLE.' 955 WHERE user_id = '.$user['id'].' 956 AND element_id = '.$_GET['image_id'].';'; 957 $result = pwg_query($query); 958 if (mysql_num_rows($result) > 0) 959 { 960 $row = mysql_fetch_array($result); 961 $sentence = $lang['already_rated']; 962 $sentence.= ' ('.$row['rate'].'). '; 963 $sentence.= $lang['update_rate']; 964 } 965 else 966 { 967 $sentence = $lang['never_rated'].'. '.$lang['to_rate']; 968 } 969 $template->assign_block_vars( 970 'rate', 971 array( 972 'CONTENT' => $value, 973 'SENTENCE' => $sentence 974 )); 975 976 $template->assign_block_vars('info_rate', array('CONTENT' => $value)); 977 978 $template->assign_vars( 979 array( 980 'INFO_RATE' => $value 981 ) 982 ); 983 984 foreach ($rate_items as $num => $mark) 985 { 986 if ($num > 0) 987 { 988 $separator = '|'; 989 } 990 else 991 { 992 $separator = ''; 993 } 994 995 $url = PHPWG_ROOT_PATH.'picture.php'; 996 $url.= get_query_string_diff(array('rate','add_fav')); 997 $url.= '&rate='.$mark; 998 1024 if ($user['is_the_guest']) 1025 { 1026 $ip_components = explode('.', $_SERVER['REMOTE_ADDR']); 1027 if ( count($ip_components)>3 ) 1028 { 1029 array_pop($ip_components); 1030 } 1031 $anonymous_id = implode ('.', $ip_components); 1032 $query .= ' AND anonymous_id = \''.$anonymous_id . '\''; 1033 } 1034 1035 $result = pwg_query($query); 1036 if (mysql_num_rows($result) > 0) 1037 { 1038 $row = mysql_fetch_array($result); 1039 $sentence = $lang['already_rated']; 1040 $sentence.= ' ('.$row['rate'].'). '; 1041 $sentence.= $lang['update_rate']; 1042 } 1043 else 1044 { 1045 $sentence = $lang['never_rated'].'. '.$lang['to_rate']; 1046 } 1047 } 1048 else 1049 { 1050 $sentence = $lang['never_rated'].'. '.$lang['to_rate']; 1051 } 999 1052 $template->assign_block_vars( 1000 'rate .rate_option',1053 'rate', 1001 1054 array( 1002 'OPTION' => $mark, 1003 'URL' => $url, 1004 'SEPARATOR' => $separator 1055 'CONTENT' => $value, 1056 'SENTENCE' => $sentence 1005 1057 )); 1058 1059 $template->assign_block_vars('info_rate', array('CONTENT' => $value)); 1060 1061 $template->assign_vars( 1062 array( 1063 'INFO_RATE' => $value 1064 ) 1065 ); 1066 1067 foreach ($rate_items as $num => $mark) 1068 { 1069 if ($num > 0) 1070 { 1071 $separator = '|'; 1072 } 1073 else 1074 { 1075 $separator = ''; 1076 } 1077 1078 $url = PHPWG_ROOT_PATH.'picture.php'; 1079 $url.= get_query_string_diff(array('add_fav')); 1080 $url.= '&rate='.$mark; 1081 1082 $template->assign_block_vars( 1083 'rate.rate_option', 1084 array( 1085 'OPTION' => $mark, 1086 'URL' => $url, 1087 'SEPARATOR' => $separator 1088 )); 1006 1089 } 1007 1090 } … … 1032 1115 // navigation bar creation 1033 1116 $url = PHPWG_ROOT_PATH.'picture.php'; 1034 $url.= get_query_string_diff(array(' rate','add_fav','start'));1117 $url.= get_query_string_diff(array('add_fav','start')); 1035 1118 1036 1119 if (!isset( $_GET['start'] ) … … 1052 1135 'NAV_BAR'=>$page['navigation_bar'])); 1053 1136 1054 $query = 'SELECT id,author,date,image_id,content'; 1055 $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id']; 1056 $query.= " AND validated = 'true'"; 1057 $query.= ' ORDER BY date ASC'; 1058 $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';'; 1059 $result = pwg_query( $query ); 1060 1061 while ( $row = mysql_fetch_array( $result ) ) 1062 { 1063 $template->assign_block_vars( 1064 'comments.comment', 1065 array( 1066 'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'], 1067 'COMMENT_DATE'=>format_date($row['date'], 'mysql_datetime', true), 1068 'COMMENT'=>parse_comment_content($row['content']) 1069 )); 1070 1071 if ( $user['status'] == 'admin' ) 1137 if ($row['nb_comments']>0) 1138 { 1139 $query = 'SELECT id,author,date,image_id,content'; 1140 $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id']; 1141 $query.= " AND validated = 'true'"; 1142 $query.= ' ORDER BY date ASC'; 1143 $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';'; 1144 $result = pwg_query( $query ); 1145 1146 while ( $row = mysql_fetch_array( $result ) ) 1072 1147 { 1073 1148 $template->assign_block_vars( 1074 'comments.comment.delete', 1075 array('U_COMMENT_DELETE'=> $url.'&del='.$row['id'] 1076 )); 1077 } 1078 } 1079 1149 'comments.comment', 1150 array( 1151 'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'], 1152 'COMMENT_DATE'=>format_date($row['date'], 'mysql_datetime', true), 1153 'COMMENT'=>parse_comment_content($row['content']) 1154 )); 1155 1156 if ( $user['status'] == 'admin' ) 1157 { 1158 $template->assign_block_vars( 1159 'comments.comment.delete', 1160 array('U_COMMENT_DELETE'=> $url.'&del='.$row['id'] 1161 )); 1162 } 1163 } 1164 } 1165 1080 1166 if (!$user['is_the_guest'] 1081 1167 or ($user['is_the_guest'] and $conf['comments_forall'])) -
trunk/template/yoga/redirect.tpl
r859 r1041 1 redirection 1 redirection<br/> 2 <a href="{U_REFRESH}">{U_REFRESH}</a>
Note: See TracChangeset
for help on using the changeset viewer.