Ticket #160: final_cruft_free_pagination.patch
| File final_cruft_free_pagination.patch, 17.4 KB (added by sidtheduck, 20 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 // check for collections level pagination first 1029 if ($names['collection'] == 'page' && !empty($names['album']) && is_numeric($names['album']) && intval($names['album']) == $names['album']) { 1030 return array("level" => "collections", "id" => 0, "plog_page" => intval($names['album'])); 1031 } 1028 1032 $sql = "SELECT * 1029 1033 FROM `".TABLE_PREFIX."collections` 1030 WHERE `path`='".$names[ "collection"]."'";1034 WHERE `path`='".$names['collection']."'"; 1031 1035 $result = run_query($sql); 1032 1036 1033 1037 // No such collection, fall back to main page … … 1039 1043 1040 1044 // what if there are multiple collections with same names? I hope there aren't .. this would 1041 1045 // suck. But here is an idea, we shouldn't allow the user to enter similar names 1042 $rv = array("level" => "collection","id" => $collection[ "id"]);1046 $rv = array("level" => "collection","id" => $collection['id']); 1043 1047 } 1044 1048 1045 1049 if (!empty($names['album'])) { 1050 // check for collection level pagination first 1051 if ($names['album'] == 'page' && !empty($names['picture']) && is_numeric($names['picture']) && intval($names['picture']) == $names['picture']) { 1052 return array("level" => "collection", "id" => $collection['id'], "plog_page" => intval($names['picture'])); 1053 } 1046 1054 $sql = "SELECT * 1047 1055 FROM `".TABLE_PREFIX."albums` 1048 WHERE `path`='".$names[ "album"]."'1049 AND `parent_id`=".intval($collection[ "id"]);1056 WHERE `path`='".$names['album']."' 1057 AND `parent_id`=".intval($collection['id']); 1050 1058 $result = run_query($sql); 1051 1059 1052 1060 // no such album, fall back to collection … … 1077 1085 $rv = array('level' => 'album','id' => $album['id']); 1078 1086 } 1079 1087 1080 if (!empty($names["picture"])) { 1088 if (!empty($names['picture'])) { 1089 // check for album level pagination first 1090 if ($names['picture'] == 'page' && !empty($names['arg1']) && is_numeric($names['arg1']) && intval($names['arg1']) == $names['arg1']) { 1091 return array("level" => "album", "id" => $album['id'], "plog_page" => intval($names['arg1'])); 1092 } 1081 1093 $sql = "SELECT * 1082 1094 FROM `".TABLE_PREFIX."pictures` 1083 WHERE `caption`='".$names[ "picture"]."'1084 AND `parent_album`=".intval($album[ "id"]);1095 WHERE `caption`='".$names['picture']."' 1096 AND `parent_album`=".intval($album['id']); 1085 1097 $result = run_query($sql); 1086 1098 1087 1099 $picture = mysql_fetch_assoc($result); … … 1105 1117 return $rv; 1106 1118 } 1107 1119 1108 $rv = array("level" => "picture", "id" => $picture[ "id"]);1120 $rv = array("level" => "picture", "id" => $picture['id']); 1109 1121 } 1110 1122 1111 1123 return $rv; 1112 1124 } 1113 1125 1114 function generate_pagination($ url, $current_page, $items_total, $items_on_page, $extra_params = ''){1126 function generate_pagination($level, $id, $current_page, $items_total, $items_on_page, $args = array(1 => "page")){ 1115 1127 $output = ''; 1116 1128 1117 if (!isset($GLOBALS[ "total_pictures"])) $GLOBALS["total_pictures"] = 0;1129 if (!isset($GLOBALS['total_pictures'])) $GLOBALS['total_pictures'] = 0; 1118 1130 1119 if (($items_total == 0) && ($GLOBALS[ "total_pictures"] > 0)) {1120 $items_total = $GLOBALS[ "total_pictures"];1131 if (($items_total == 0) && ($GLOBALS['total_pictures'] > 0)) { 1132 $items_total = $GLOBALS['total_pictures']; 1121 1133 } 1122 1134 1123 1135 $num_pages = ceil($items_total / $items_on_page); 1124 1136 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 1137 if ($num_pages > 1){ 1136 1138 if ($current_page > 1){ 1137 $output .= ' <a accesskey="," class="pagPrev" href="'.$url.$separator.'plog_page='.($current_page - 1).$extra_params.'"><span>«</span></a> '; 1139 $args['plog_page'] = $current_page - 1; 1140 $output .= ' <a accesskey="," class="pagPrev" href="'.generate_url($level, $id, $args).'"><span>«</span></a> '; 1138 1141 } 1139 1142 1140 1143 for ($i = 1; $i <= $num_pages; $i++){ 1141 1144 if ($i == $current_page){ 1142 1145 $output .= '<span class="page_link"> ['.$i.'] </span>'; 1143 1146 } else{ 1144 $output .= '<a href="'.$url.$separator.'plog_page='.$i.$extra_params.'" class="page_link">'.$i.'</a> '; 1147 $args['plog_page'] = $i; 1148 $output .= '<a href="'.generate_url($level, $id, $args).'" class="page_link">'.$i.'</a> '; 1145 1149 } 1146 1150 } 1147 1151 1148 1152 if ($current_page != $num_pages){ 1149 $output .= ' <a accesskey="." class="pagNext" href="'.$url.$separator.'plog_page='.($current_page + 1).$extra_params.'"><span>»</span></a> '; 1153 $args['plog_page'] = $current_page + 1; 1154 $output .= ' <a accesskey="." class="pagNext" href="'.generate_url($level, $id, $args).'"><span>»</span></a> '; 1150 1155 } 1151 1156 } 1152 1157 … … 1166 1171 $rv = ''; 1167 1172 1168 1173 if ($config['use_mod_rewrite']){ 1174 $args = ''; 1175 // I need to give additional arguments to the url-s 1176 if (sizeof($arg) > 0) { 1177 foreach($arg as $aval) { 1178 $args .= $aval."/"; 1179 } 1180 } 1181 1169 1182 switch($level){ 1170 1183 case "collection": 1171 1184 $query = "SELECT `path` FROM `".TABLE_PREFIX."collections` WHERE `id`=".intval($id); 1172 1185 $result = run_query($query); 1173 1186 $row = mysql_fetch_assoc($result); 1174 $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['path']))."/" ;1187 $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['path']))."/".$args; 1175 1188 break; 1176 1189 case "album": 1177 1190 $query = "SELECT … … 1182 1195 WHERE `a`.`id`=".intval($id); 1183 1196 $result = run_query($query); 1184 1197 $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 } 1198 $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['collection_path'])) . '/' . rawurlencode(SmartStripSlashes($row['album_path']))."/".$args; 1194 1199 break; 1195 1200 case "picture": 1196 1201 $pic = get_picture_by_id($id); … … 1203 1208 if (sizeof($arg) > 0) { 1204 1209 foreach($arg as $akey => $aval) { 1205 1210 // 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') {1211 // this temporary workaround removes the 'sorted' and 'plog_page' strings 1212 if (!is_numeric($akey)) { 1208 1213 $rv .= "&".$akey."=".$aval; 1209 1214 } 1210 1215 } 1211 1216 } 1212 1217 break; 1213 1218 case "collections": 1214 default:1215 $rv = $config['baseurl'] ;1219 default: 1220 $rv = $config['baseurl'].$args; 1216 1221 break; 1217 1222 } 1218 1223 } else { 1219 1224 // 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 = "?"; 1225 // non-Plogger query items only work with old style URLs (not with mod_rewrite URLs) 1226 $query = (isset($config['query_args'])) ? "?".$config['query_args']."&" : "?"; 1227 1228 $args = ''; 1229 // add on any additional arguments from the $arg array 1230 if (sizeof($arg) > 0) { 1231 foreach($arg as $akey => $aval) { 1232 // mod_rewrite url-s need /sorted and /plog_page in them, the old style ones do not. 1233 // this temporary workaround removes the 'sorted' and 'plog_page' strings 1234 if (!is_numeric($akey)) { 1235 $args .= "&".$akey."=".$aval; 1236 } 1237 } 1238 } 1221 1239 1222 1240 switch($level){ 1241 // admin section for generate_url 1242 case "admin": 1243 $rv = $config['baseurl']."plog-admin/plog-".$id.".php?".substr($args, 5); 1244 break; 1245 // front end section for generate_url 1223 1246 case "collection": 1224 return $config['baseurl'].$query.'level=collection&id='.$id;1247 $rv = $config['baseurl'].$query.'level=collection&id='.$id.$args; 1225 1248 break; 1226 1249 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 } 1250 $rv = $config['baseurl'].$query.'level=album&id='.$id.$args; 1237 1251 break; 1238 1252 case "picture": 1239 1253 $rv = $config['baseurl'].$query.'level=picture&id='.$id; 1240 1254 break; 1241 1255 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 } 1256 $rv = $config['baseurl'].$query."level=search".$args; 1253 1257 break; 1254 1258 case "collections": 1255 default: 1256 $query = (isset($config['query_args'])) ? "?".$config['query_args'] : $query = ""; 1257 $rv = $config['baseurl'].$query; 1259 default: 1260 $rv = $config['baseurl']; 1261 if ($query != "?" && empty($args)) { 1262 if ($query == "?") { $args = substr($args, 5); } 1263 $rv .= $query.$args; 1264 } 1258 1265 break; 1259 1266 } 1260 1267 } 1261 1268 1262 // replace & with & if outputting to email1269 // replace & with & if formatting plaintext (i.e. outputting to email) 1263 1270 if ($plaintext !== false){ 1264 1271 $rv = str_replace("&","&",$rv); 1265 1272 } … … 1974 1981 global $config; 1975 1982 1976 1983 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']) { 1984 $page = isset($_GET['plog_page']) ? intval($_GET['plog_page']) : 1; 1985 $level = $GLOBALS['plogger_level']; 1986 $id = $GLOBALS['plogger_id']; 1987 switch($level) { 1991 1988 case 'search': 1992 $num_items = $GLOBALS["total_pictures"]; 1993 break; 1989 $num_items = $GLOBALS['total_pictures']; 1990 return generate_pagination("search", -1, $page, $num_items, $config['thumb_num'], array('searchterms'=>urlencode($_GET['searchterms']))); 1991 break; 1994 1992 1995 1993 case 'album': 1996 1994 $num_items = plogger_album_picture_count(); 1997 break;1995 break; 1998 1996 1999 1997 case 'collection': 2000 1998 $num_items = plogger_collection_album_count(); 2001 break;1999 break; 2002 2000 2003 2001 default: 2004 $num_items = plogger_count_collections(); 2005 break; 2002 $level = "collections"; 2003 $id = 0; 2004 $num_items = plogger_count_collections(); 2005 break; 2006 2006 } 2007 2007 2008 return generate_pagination($ p_url, $page, $num_items, $config["thumb_num"]);2008 return generate_pagination($level, $id, $page, $num_items, $config['thumb_num']); 2009 2009 } 2010 2010 2011 2011 } -
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 {
