Ticket #160: updated_cruft_free_pagination.patch
| File updated_cruft_free_pagination.patch, 16.7 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
1023 1023 $current_level = $level; 1024 1024 } 1025 1025 } 1026 1027 // try to detect collections level paging for multiple collections. Downside is you cannot have a collection named as a pure, round number 1028 if (isset($names['collection']) && is_numeric($names['collection']) && intval($names['collection']) == $names['collection']) { 1029 return array("level" => "collections", "id" => 0, "plog_page" => intval($names['collection'])); 1030 } 1026 1031 1027 1032 if (!empty($names["collection"])) { 1028 1033 $sql = "SELECT * … … 1037 1042 1038 1043 $collection = mysql_fetch_assoc($result); 1039 1044 1045 // try to detect collection level paging for multiple albums. Downside is you cannot have an album named as a pure, round number 1046 if (isset($names['album']) && is_numeric($names['album']) && intval($names['album']) == $names['album']) { 1047 return array("level" => "collection", "id" => $collection['id'], "plog_page" => intval($names['album'])); 1048 } 1049 1040 1050 // what if there are multiple collections with same names? I hope there aren't .. this would 1041 1051 // suck. But here is an idea, we shouldn't allow the user to enter similar names 1042 1052 $rv = array("level" => "collection","id" => $collection["id"]); … … 1056 1066 1057 1067 $album = mysql_fetch_assoc($result); 1058 1068 1069 // try to detect album level paging for multiple pictures. Downside is you cannot have a picture named as a pure, round number 1070 if (isset($names['picture']) && is_numeric($names['picture']) && intval($names['picture']) == $names['picture']) { 1071 return array("level" => "album", "id" => $album['id'], "plog_page" => intval($names['picture'])); 1072 } 1073 1059 1074 // try to detect slideshow. Downside is that you cannot have a picture with that name 1060 1075 if (isset($names['picture']) && $names['picture'] == 'slideshow') { 1061 1076 return array('level' => 'album','mode' => 'slideshow','id' => $album['id']); … … 1111 1126 return $rv; 1112 1127 } 1113 1128 1114 function generate_pagination($ url, $current_page, $items_total, $items_on_page, $extra_params = ''){1129 function generate_pagination($level, $id, $current_page, $items_total, $items_on_page, $args = array()){ 1115 1130 $output = ''; 1116 1131 1117 if (!isset($GLOBALS[ "total_pictures"])) $GLOBALS["total_pictures"] = 0;1132 if (!isset($GLOBALS['total_pictures'])) $GLOBALS['total_pictures'] = 0; 1118 1133 1119 if (($items_total == 0) && ($GLOBALS[ "total_pictures"] > 0)) {1120 $items_total = $GLOBALS[ "total_pictures"];1134 if (($items_total == 0) && ($GLOBALS['total_pictures'] > 0)) { 1135 $items_total = $GLOBALS['total_pictures']; 1121 1136 } 1122 1137 1123 1138 $num_pages = ceil($items_total / $items_on_page); 1124 1139 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 1140 if ($num_pages > 1){ 1136 1141 if ($current_page > 1){ 1137 $output .= ' <a accesskey="," class="pagPrev" href="'.$url.$separator.'plog_page='.($current_page - 1).$extra_params.'"><span>«</span></a> '; 1142 $args['plog_page'] = $current_page - 1; 1143 $output .= ' <a accesskey="," class="pagPrev" href="'.generate_url($level, $id, $args).'"><span>«</span></a> '; 1138 1144 } 1139 1145 1140 1146 for ($i = 1; $i <= $num_pages; $i++){ 1141 1147 if ($i == $current_page){ 1142 1148 $output .= '<span class="page_link"> ['.$i.'] </span>'; 1143 1149 } else{ 1144 $output .= '<a href="'.$url.$separator.'plog_page='.$i.$extra_params.'" class="page_link">'.$i.'</a> '; 1150 $args['plog_page'] = $i; 1151 $output .= '<a href="'.generate_url($level, $id, $args).'" class="page_link">'.$i.'</a> '; 1145 1152 } 1146 1153 } 1147 1154 1148 1155 if ($current_page != $num_pages){ 1149 $output .= ' <a accesskey="." class="pagNext" href="'.$url.$separator.'plog_page='.($current_page + 1).$extra_params.'"><span>»</span></a> '; 1156 $args['plog_page'] = $current_page + 1; 1157 $output .= ' <a accesskey="." class="pagNext" href="'.generate_url($level, $id, $args).'"><span>»</span></a> '; 1150 1158 } 1151 1159 } 1152 1160 … … 1166 1174 $rv = ''; 1167 1175 1168 1176 if ($config['use_mod_rewrite']){ 1177 $args = ''; 1178 // I need to give additional arguments to the url-s 1179 if (sizeof($arg) > 0) { 1180 foreach($arg as $aval) { 1181 $args .= $aval."/"; 1182 } 1183 } 1184 1169 1185 switch($level){ 1170 1186 case "collection": 1171 1187 $query = "SELECT `path` FROM `".TABLE_PREFIX."collections` WHERE `id`=".intval($id); 1172 1188 $result = run_query($query); 1173 1189 $row = mysql_fetch_assoc($result); 1174 $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['path']))."/" ;1190 $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['path']))."/".$args; 1175 1191 break; 1176 1192 case "album": 1177 1193 $query = "SELECT … … 1182 1198 WHERE `a`.`id`=".intval($id); 1183 1199 $result = run_query($query); 1184 1200 $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 } 1201 $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['collection_path'])) . '/' . rawurlencode(SmartStripSlashes($row['album_path']))."/".$args; 1194 1202 break; 1195 1203 case "picture": 1196 1204 $pic = get_picture_by_id($id); … … 1203 1211 if (sizeof($arg) > 0) { 1204 1212 foreach($arg as $akey => $aval) { 1205 1213 // 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') {1214 // this temporary workaround removes the 'sorted' and 'plog_page' strings 1215 if ($aval != "sorted") { 1208 1216 $rv .= "&".$akey."=".$aval; 1209 1217 } 1210 1218 } 1211 1219 } 1212 1220 break; 1213 1221 case "collections": 1214 default:1215 $rv = $config['baseurl'] ;1222 default: 1223 $rv = $config['baseurl'].$args; 1216 1224 break; 1217 1225 } 1218 1226 } else { 1219 1227 // 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 = "?"; 1228 // non-Plogger query items only work with old style URLs (not with mod_rewrite URLs) 1229 $query = (isset($config['query_args'])) ? "?".$config['query_args']."&" : "?"; 1230 1231 $args = ''; 1232 // add on any additional arguments from the $arg array 1233 if (sizeof($arg) > 0) { 1234 foreach($arg as $akey => $aval) { 1235 // mod_rewrite url-s need /sorted and /plog_page in them, the old style ones do not. 1236 // this temporary workaround removes the 'sorted' and 'plog_page' strings 1237 if ($aval != "sorted") { 1238 $args .= "&".$akey."=".$aval; 1239 } 1240 } 1241 } 1221 1242 1222 1243 switch($level){ 1244 // admin section for generate_url 1245 case "admin": 1246 $rv = $config['baseurl']."plog-admin/plog-".$id.".php?".substr($args, 5); 1247 break; 1248 // front end section for generate_url 1223 1249 case "collection": 1224 return $config['baseurl'].$query.'level=collection&id='.$id;1250 $rv = $config['baseurl'].$query.'level=collection&id='.$id.$args; 1225 1251 break; 1226 1252 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 } 1253 $rv = $config['baseurl'].$query.'level=album&id='.$id.$args; 1237 1254 break; 1238 1255 case "picture": 1239 1256 $rv = $config['baseurl'].$query.'level=picture&id='.$id; 1240 1257 break; 1241 1258 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 } 1259 $rv = $config['baseurl'].$query."level=search".$args; 1253 1260 break; 1254 1261 case "collections": 1255 default: 1256 $query = (isset($config['query_args'])) ? "?".$config['query_args'] : $query = ""; 1257 $rv = $config['baseurl'].$query; 1262 default: 1263 $rv = $config['baseurl']; 1264 if ($query != "?" && empty($args)) { 1265 if ($query == "?") { $args = substr($args, 5); } 1266 $rv .= $query.$args; 1267 } 1258 1268 break; 1259 1269 } 1260 1270 } 1261 1271 1262 // replace & with & if outputting to email1272 // replace & with & if formatting plaintext (i.e. outputting to email) 1263 1273 if ($plaintext !== false){ 1264 1274 $rv = str_replace("&","&",$rv); 1265 1275 } … … 1974 1984 global $config; 1975 1985 1976 1986 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']) { 1987 $page = isset($_GET['plog_page']) ? intval($_GET['plog_page']) : 1; 1988 $level = $GLOBALS['plogger_level']; 1989 $id = $GLOBALS['plogger_id']; 1990 switch($level) { 1991 1991 case 'search': 1992 $num_items = $GLOBALS["total_pictures"]; 1993 break; 1992 $num_items = $GLOBALS['total_pictures']; 1993 return generate_pagination("search", -1, $page, $num_items, $config['thumb_num'], array('searchterms'=>urlencode($_GET['searchterms']))); 1994 break; 1994 1995 1995 1996 case 'album': 1996 1997 $num_items = plogger_album_picture_count(); 1997 break;1998 break; 1998 1999 1999 2000 case 'collection': 2000 2001 $num_items = plogger_collection_album_count(); 2001 break;2002 break; 2002 2003 2003 2004 default: 2004 $num_items = plogger_count_collections(); 2005 break; 2005 $level = "collections"; 2006 $id = 0; 2007 $num_items = plogger_count_collections(); 2008 break; 2006 2009 } 2007 2010 2008 return generate_pagination($ p_url, $page, $num_items, $config["thumb_num"]);2011 return generate_pagination($level, $id, $page, $num_items, $config['thumb_num']); 2009 2012 } 2010 2013 2011 2014 } -
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 {
