Ticket #160: another_updated_cruft_free_pagination.patch
| File another_updated_cruft_free_pagination.patch, 17.5 KB (added by sidtheduck, 4 months ago) |
|---|
-
plog-admin/plog-feedback.php
109 109 #$url = "&entries_per_page=$_SESSION[entries_per_page]&level=$_REQUEST[level]&id=$_REQUEST[id]"; 110 110 $url = "?entries_per_page=$_SESSION[entries_per_page]"; 111 111 112 $first_item = ($_REQUEST['plog_page'] - 1) * $_SESSION['entries_per_page']; 112 $plog_page = isset($_REQUEST["plog_page"]) ? $_REQUEST["plog_page"] : 1; 113 114 $first_item = ($plog_page - 1) * $_SESSION['entries_per_page']; 113 115 $limit = "LIMIT $first_item, $_SESSION[entries_per_page]"; 114 116 115 117 // lets generate the pagination menu as well … … 121 123 $mod_result = run_query($query); 122 124 $num_comments_im = mysql_result($mod_result, "in_moderation"); 123 125 124 $page = isset($_GET["plog_page"]) ? $_GET["plog_page"] : 1;125 126 126 // filter based on whether were looking at approved comments or unmoderated comments 127 $approved = isset($_ GET["moderate"]) ? 0 : 1;127 $approved = isset($_REQUEST['moderate']) ? 0 : 1; 128 128 129 if ($approved) 130 $pagination_menu = generate_pagination('plog-feedback.php'.$url,$page,$num_comments,$_SESSION['entries_per_page']); 131 else 132 $pagination_menu = generate_pagination('plog-feedback.php'.$url,$page,$num_comments_im,$_SESSION['entries_per_page'],"&moderate=1"); 129 if ($approved) { 130 $pagination_menu = generate_pagination("admin", "feedback", $plog_page, $num_comments, $_SESSION['entries_per_page']); 131 } else { 132 $pagination_menu = generate_pagination("admin", "feedback", $plog_page, $num_comments_im, $_SESSION['entries_per_page'], array("moderate" => 1)); 133 } 133 134 134 135 // generate javascript init function for ajax editing 135 136 $query = "SELECT *, UNIX_TIMESTAMP(`date`) AS `unix_date` from ".TABLE_PREFIX."comments WHERE `approved` = $approved ORDER BY `id` DESC $limit"; -
plog-admin/plog-manage.php
300 300 301 301 // handle pagination 302 302 // lets determine the limit filter based on current page and number of results per page 303 if (!isset($_REQUEST["page"])) $_REQUEST["page"] = "1"; // we're on the first page 303 if (isset($_REQUEST['entries_per_page'])) { 304 $_SESSION['entries_per_page'] = $_REQUEST['entries_per_page']; 305 } else { 306 $_SESSION['entries_per_page'] = 20; 307 } 304 308 305 if (isset($_REQUEST['entries_per_page']))306 $_SESSION['entries_per_page'] = $_REQUEST['entries_per_page'];307 else308 $_SESSION['entries_per_page'] = 20;309 310 309 $cond = ""; 311 310 312 311 // determine the filtering conditional based on the level and id number … … 317 316 $cond = "WHERE `parent_album` = '$id'"; 318 317 } 319 318 320 $url = "?entries_per_page=$_SESSION[entries_per_page]&level=$_REQUEST[level]&id=$id"; 321 322 $plog_page = isset($_REQUEST['plog_page']) ? $_REQUEST['plog_page'] : 0; 319 $plog_page = isset($_REQUEST['plog_page']) ? $_REQUEST['plog_page'] : 1; // we're on the first page 323 320 $first_item = ($plog_page - 1) * $_SESSION['entries_per_page']; 324 321 if ($first_item < 0) { 325 322 $first_item = 0; 326 } ;327 $limit = "LIMIT $first_item, $_SESSION[entries_per_page]";323 } 324 $limit = "LIMIT ".$first_item.", ".$_SESSION['entries_per_page']; 328 325 329 326 // lets generate the pagination menu as well 330 327 $recordCount = "SELECT COUNT(*) AS num_items FROM ".TABLE_PREFIX."$level $cond"; 331 328 $totalRowsResult = mysql_query($recordCount); 332 329 $totalRows = mysql_result($totalRowsResult,'num_items'); 333 330 334 $page = isset($_GET["plog_page"]) ? $_GET["plog_page"] : 1; 335 $pagination_menu = "\n\t\t" . '<div class="pagination">'.generate_pagination('plog-manage.php'.$url,$page,$totalRows,$_SESSION['entries_per_page']).'</div>'; 331 $pagination_menu = "\n\t\t" . '<div class="pagination">'.generate_pagination("admin", "manage", $plog_page, $totalRows, $_SESSION['entries_per_page'], array("level" => $level, "id" => $id, "entries_per_page" => $_SESSION['entries_per_page'])).'</div>'; 336 332 337 333 $output .= "\n\t\t" . '<form id="contentList" action="'.$_SERVER["PHP_SELF"].'" method="get">'; 338 334 339 335 $level = $_REQUEST['level']; 340 336 341 if (empty($level) ) {337 if (empty($level) || $level == "collections") { 342 338 $output .= generate_breadcrumb_admin("").$pagination_menu; 343 339 $output .= plog_collection_manager($first_item,$_SESSION['entries_per_page']); 344 } ;340 } 345 341 346 342 if ($level == "albums") { 347 343 $output .= generate_breadcrumb_admin("albums", $id).$pagination_menu; … … 365 361 <input type="hidden" name="id" value="'.$id.'" /> 366 362 <input type="hidden" name="action" value="1" /> 367 363 <input class="submit" type="submit" name="delete_checked" onclick="return confirm(\'' . plog_tr('Are you sure you want to delete selected items?') . '\');" value="' . plog_tr('Delete Checked') . '" />'; 368 if (!empty($level) && $level != "co mments"){364 if (!empty($level) && $level != "collections" && $level != "comments"){ 369 365 $output .= generate_move_menu($level); 370 366 }; 371 367 $output .= "\n\t\t</div>\n\t\t</form>\n"; -
plog-includes/plog-functions.php
1024 1024 } 1025 1025 } 1026 1026 1027 if (!empty($names[ "collection"])) {1027 if (!empty($names['collection'])) { 1028 1028 $sql = "SELECT * 1029 1029 FROM `".TABLE_PREFIX."collections` 1030 WHERE `path`='".$names[ "collection"]."'";1030 WHERE `path`='".$names['collection']."'"; 1031 1031 $result = run_query($sql); 1032 1032 1033 // No such collection, fall back to main page1033 // no such collection 1034 1034 if (mysql_num_rows($result) == 0){ 1035 return $rv; 1035 //check if it's collections pagination 1036 if (is_numeric($names['collection']) && intval($names['collection']) == $names['collection']) { 1037 return array("level" => "collections", "id" => 0, "plog_page" => intval($names['collection'])); 1038 } 1036 1039 } 1037 1040 1038 1041 $collection = mysql_fetch_assoc($result); 1039 1042 1040 1043 // what if there are multiple collections with same names? I hope there aren't .. this would 1041 1044 // suck. But here is an idea, we shouldn't allow the user to enter similar names 1042 $rv = array("level" => "collection","id" => $collection[ "id"]);1045 $rv = array("level" => "collection","id" => $collection['id']); 1043 1046 } 1044 1047 1045 1048 if (!empty($names['album'])) { 1046 1049 $sql = "SELECT * 1047 1050 FROM `".TABLE_PREFIX."albums` 1048 WHERE `path`='".$names[ "album"]."'1049 AND `parent_id`=".intval($collection[ "id"]);1051 WHERE `path`='".$names['album']."' 1052 AND `parent_id`=".intval($collection['id']); 1050 1053 $result = run_query($sql); 1051 1054 1052 // no such album , fall back to collection1055 // no such album 1053 1056 if (mysql_num_rows($result) == 0){ 1054 return $rv; 1057 //check if it's collection pagination 1058 if (is_numeric($names['album']) && intval($names['album']) == $names['album']) { 1059 return array("level" => "collection", "id" => $collection['id'], "plog_page" => intval($names['album'])); 1060 } 1055 1061 } 1056 1062 1057 1063 $album = mysql_fetch_assoc($result); … … 1077 1083 $rv = array('level' => 'album','id' => $album['id']); 1078 1084 } 1079 1085 1080 if (!empty($names[ "picture"])) {1086 if (!empty($names['picture'])) { 1081 1087 $sql = "SELECT * 1082 1088 FROM `".TABLE_PREFIX."pictures` 1083 WHERE `caption`='".$names[ "picture"]."'1084 AND `parent_album`=".intval($album[ "id"]);1089 WHERE `caption`='".$names['picture']."' 1090 AND `parent_album`=".intval($album['id']); 1085 1091 $result = run_query($sql); 1086 1092 1087 1093 $picture = mysql_fetch_assoc($result); … … 1100 1106 $picture = mysql_fetch_assoc($result); 1101 1107 } 1102 1108 1103 // no such picture , fall back to album1109 // no such picture 1104 1110 if (!$picture) { 1105 return $rv; 1111 //check if it's album pagination 1112 if (is_numeric($names['picture']) && intval($names['picture']) == $names['picture']) { 1113 return array("level" => "album", "id" => $album['id'], "plog_page" => intval($names['picture'])); 1114 } 1106 1115 } 1107 1116 1108 $rv = array("level" => "picture", "id" => $picture[ "id"]);1117 $rv = array("level" => "picture", "id" => $picture['id']); 1109 1118 } 1110 1119 1111 1120 return $rv; 1112 1121 } 1113 1122 1114 function generate_pagination($ url, $current_page, $items_total, $items_on_page, $extra_params = ''){1123 function generate_pagination($level, $id, $current_page, $items_total, $items_on_page, $args = array()){ 1115 1124 $output = ''; 1116 1125 1117 if (!isset($GLOBALS[ "total_pictures"])) $GLOBALS["total_pictures"] = 0;1126 if (!isset($GLOBALS['total_pictures'])) $GLOBALS['total_pictures'] = 0; 1118 1127 1119 if (($items_total == 0) && ($GLOBALS[ "total_pictures"] > 0)) {1120 $items_total = $GLOBALS[ "total_pictures"];1128 if (($items_total == 0) && ($GLOBALS['total_pictures'] > 0)) { 1129 $items_total = $GLOBALS['total_pictures']; 1121 1130 } 1122 1131 1123 1132 $num_pages = ceil($items_total / $items_on_page); 1124 1133 1125 // if adding arguments to mod_rewritten urls, then I need ? (question mark) before the arguments1126 // otherwise I want &1127 //$last = substr($url,-1);1128 1129 if (!strpos($url,"?")) {1130 $separator = "?";1131 } else {1132 $separator = "&";1133 }1134 1135 1134 if ($num_pages > 1){ 1136 1135 if ($current_page > 1){ 1137 $output .= ' <a accesskey="," class="pagPrev" href="'.$url.$separator.'plog_page='.($current_page - 1).$extra_params.'"><span>«</span></a> '; 1136 $args['plog_page'] = $current_page - 1; 1137 $output .= ' <a accesskey="," class="pagPrev" href="'.generate_url($level, $id, $args).'"><span>«</span></a> '; 1138 1138 } 1139 1139 1140 1140 for ($i = 1; $i <= $num_pages; $i++){ 1141 1141 if ($i == $current_page){ 1142 1142 $output .= '<span class="page_link"> ['.$i.'] </span>'; 1143 1143 } else{ 1144 $output .= '<a href="'.$url.$separator.'plog_page='.$i.$extra_params.'" class="page_link">'.$i.'</a> '; 1144 $args['plog_page'] = $i; 1145 $output .= '<a href="'.generate_url($level, $id, $args).'" class="page_link">'.$i.'</a> '; 1145 1146 } 1146 1147 } 1147 1148 1148 1149 if ($current_page != $num_pages){ 1149 $output .= ' <a accesskey="." class="pagNext" href="'.$url.$separator.'plog_page='.($current_page + 1).$extra_params.'"><span>»</span></a> '; 1150 $args['plog_page'] = $current_page + 1; 1151 $output .= ' <a accesskey="." class="pagNext" href="'.generate_url($level, $id, $args).'"><span>»</span></a> '; 1150 1152 } 1151 1153 } 1152 1154 … … 1166 1168 $rv = ''; 1167 1169 1168 1170 if ($config['use_mod_rewrite']){ 1171 $args = ''; 1172 // I need to give additional arguments to the url-s 1173 if (sizeof($arg) > 0) { 1174 foreach($arg as $aval) { 1175 $args .= $aval."/"; 1176 } 1177 } 1178 1169 1179 switch($level){ 1170 1180 case "collection": 1171 1181 $query = "SELECT `path` FROM `".TABLE_PREFIX."collections` WHERE `id`=".intval($id); 1172 1182 $result = run_query($query); 1173 1183 $row = mysql_fetch_assoc($result); 1174 $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['path']))."/" ;1184 $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['path']))."/".$args; 1175 1185 break; 1176 1186 case "album": 1177 1187 $query = "SELECT … … 1182 1192 WHERE `a`.`id`=".intval($id); 1183 1193 $result = run_query($query); 1184 1194 $row = mysql_fetch_assoc($result); 1185 1186 $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['collection_path'])) . '/' . rawurlencode(SmartStripSlashes($row['album_path']))."/"; 1187 1188 // I need to give additional arguments to the url-s 1189 if (sizeof($arg) > 0) { 1190 foreach($arg as $aval) { 1191 $rv .= $aval."/"; 1192 } 1193 } 1195 $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['collection_path'])) . '/' . rawurlencode(SmartStripSlashes($row['album_path']))."/".$args; 1194 1196 break; 1195 1197 case "picture": 1196 1198 $pic = get_picture_by_id($id); … … 1203 1205 if (sizeof($arg) > 0) { 1204 1206 foreach($arg as $akey => $aval) { 1205 1207 // mod_rewrite url-s need /sorted in them, the old style ones do not. 1206 // this temporary workaround removes the 'sorted' string1207 if ($aval != 'sorted') {1208 // this temporary workaround removes the 'sorted' and 'plog_page' strings 1209 if ($aval != "sorted") { 1208 1210 $rv .= "&".$akey."=".$aval; 1209 1211 } 1210 1212 } 1211 1213 } 1212 1214 break; 1213 1215 case "collections": 1214 default:1215 $rv = $config['baseurl'] ;1216 default: 1217 $rv = $config['baseurl'].$args; 1216 1218 break; 1217 1219 } 1218 1220 } else { 1219 1221 // if there are non-Plogger query items, get them here to prepend to the URL query string 1220 $query = (isset($config['query_args'])) ? "?".$config['query_args']."&" : $query = "?"; 1222 // non-Plogger query items only work with old style URLs (not with mod_rewrite URLs) 1223 $query = (isset($config['query_args'])) ? "?".$config['query_args']."&" : "?"; 1224 1225 $args = ''; 1226 // add on any additional arguments from the $arg array 1227 if (sizeof($arg) > 0) { 1228 foreach($arg as $akey => $aval) { 1229 // mod_rewrite url-s need /sorted and /plog_page in them, the old style ones do not. 1230 // this temporary workaround removes the 'sorted' and 'plog_page' strings 1231 if ($aval != "sorted") { 1232 $args .= "&".$akey."=".$aval; 1233 } 1234 } 1235 } 1221 1236 1222 1237 switch($level){ 1238 // admin section for generate_url 1239 case "admin": 1240 $rv = $config['baseurl']."plog-admin/plog-".$id.".php?".substr($args, 5); 1241 break; 1242 // front end section for generate_url 1223 1243 case "collection": 1224 return $config['baseurl'].$query.'level=collection&id='.$id;1244 $rv = $config['baseurl'].$query.'level=collection&id='.$id.$args; 1225 1245 break; 1226 1246 case "album": 1227 $rv = $config['baseurl'].$query.'level=album&id='.$id; 1228 if (sizeof($arg) > 0) { 1229 foreach($arg as $akey => $aval) { 1230 // mod_rewrite url-s need /sorted in them, the old style ones do not. 1231 // this temporary workaround removes the 'sorted' string 1232 if ($aval != 'sorted') { 1233 $rv .= "&".$akey."=".$aval; 1234 } 1235 } 1236 } 1247 $rv = $config['baseurl'].$query.'level=album&id='.$id.$args; 1237 1248 break; 1238 1249 case "picture": 1239 1250 $rv = $config['baseurl'].$query.'level=picture&id='.$id; 1240 1251 break; 1241 1252 case "search": 1242 $rv = $config['baseurl'].$query."level=search"; 1243 // I need to give additional arguments to the url-s 1244 if (sizeof($arg) > 0) { 1245 foreach($arg as $akey => $aval) { 1246 // mod_rewrite url-s need /sorted in them, the old style ones do not. 1247 // this temporary workaround removes the 'sorted' string 1248 if ($aval != 'sorted') { 1249 $rv .= "&".$akey."=".$aval; 1250 } 1251 } 1252 } 1253 $rv = $config['baseurl'].$query."level=search".$args; 1253 1254 break; 1254 1255 case "collections": 1255 default: 1256 $query = (isset($config['query_args'])) ? "?".$config['query_args'] : $query = ""; 1257 $rv = $config['baseurl'].$query; 1256 default: 1257 $rv = $config['baseurl']; 1258 if ($query != "?" && empty($args)) { 1259 if ($query == "?") { $args = substr($args, 5); } 1260 $rv .= $query.$args; 1261 } 1258 1262 break; 1259 1263 } 1260 1264 } 1261 1265 1262 // replace & with & if outputting to email1266 // replace & with & if formatting plaintext (i.e. outputting to email) 1263 1267 if ($plaintext !== false){ 1264 1268 $rv = str_replace("&","&",$rv); 1265 1269 } … … 1974 1978 global $config; 1975 1979 1976 1980 if ($GLOBALS['plogger_mode'] != 'slideshow') { 1977 $page = isset($_GET["plog_page"]) ? intval($_GET["plog_page"]) : 1; 1978 1979 if ($GLOBALS['plogger_level'] == "search") { 1980 $p_url = generate_url("search", -1, array('searchterms'=>urlencode($_GET["searchterms"]))); 1981 } 1982 else { 1983 if ($GLOBALS['plogger_level']) { 1984 $p_url = generate_url($GLOBALS['plogger_level'], $GLOBALS['plogger_id']); 1985 } else { 1986 $p_url = generate_url("collections"); 1987 } 1988 } 1989 1990 switch($GLOBALS['plogger_level']) { 1981 $page = isset($_GET['plog_page']) ? intval($_GET['plog_page']) : 1; 1982 $level = $GLOBALS['plogger_level']; 1983 $id = $GLOBALS['plogger_id']; 1984 switch($level) { 1991 1985 case 'search': 1992 $num_items = $GLOBALS["total_pictures"]; 1993 break; 1986 $num_items = $GLOBALS['total_pictures']; 1987 return generate_pagination("search", -1, $page, $num_items, $config['thumb_num'], array('searchterms'=>urlencode($_GET['searchterms']))); 1988 break; 1994 1989 1995 1990 case 'album': 1996 1991 $num_items = plogger_album_picture_count(); 1997 break;1992 break; 1998 1993 1999 1994 case 'collection': 2000 1995 $num_items = plogger_collection_album_count(); 2001 break;1996 break; 2002 1997 2003 1998 default: 2004 $num_items = plogger_count_collections(); 2005 break; 1999 $level = "collections"; 2000 $id = 0; 2001 $num_items = plogger_count_collections(); 2002 break; 2006 2003 } 2007 2004 2008 return generate_pagination($ p_url, $page, $num_items, $config["thumb_num"]);2005 return generate_pagination($level, $id, $page, $num_items, $config['thumb_num']); 2009 2006 } 2010 2007 2011 2008 } -
plog-load-config.php
85 85 // remove plog-admin/ from the end, if present .. is there a better way to determine the full url? 86 86 // had to update this for new use of links without mod_rewrite turned on (only affects the View gallery greybox in Admin) 87 87 if (strpos($config['baseurl'], "plog-admin/")) { 88 $config['baseurl'] = substr($config['baseurl'],0,strpos($config['baseurl'], "plog-admin/")); 88 $config['use_mod_rewrite'] = 0; 89 $config['baseurl'] = substr($config['baseurl'], 0, strpos($config['baseurl'], "plog-admin/")); 89 90 } 90 91 91 92 $config['theme_url'] = $config['gallery_url']."plog-content/themes/".basename($config['theme_dir'])."/"; -
plogger.php
21 21 if (isset($resolved_path['id'])) { 22 22 $_GET['id'] = $resolved_path['id']; 23 23 } 24 if (isset($resolved_path['plog_page'])) { 25 $_GET['plog_page'] = $resolved_path['plog_page']; 26 } 24 27 if (isset($resolved_path['mode'])) { 25 28 $_GET['mode'] = $resolved_path['mode']; 26 29 } 27 30 28 // get page number from url, if present31 // get the path for RSS links (maybe should rework this) 29 32 $parts = parse_url($_SERVER['REQUEST_URI']); 30 if (isset($parts['query'])) {31 parse_str($parts['query'],$query_parts);32 if (!empty($query_parts['plog_page'])) {33 $_GET['plog_page'] = $query_parts['plog_page'];34 }35 }36 33 $path = $parts['path']; 37 34 } 38 35 } else {
