Ticket #160: cruft_free_pagination.patch
| File cruft_free_pagination.patch, 13.9 KB (added by sidtheduck, 4 months ago) |
|---|
-
plog-admin/plog-manage.php
317 317 $cond = "WHERE `parent_album` = '$id'"; 318 318 } 319 319 320 $url = "?entries_per_page=$_SESSION[entries_per_page]&level=$_REQUEST[level]&id=$id";321 322 320 $plog_page = isset($_REQUEST['plog_page']) ? $_REQUEST['plog_page'] : 0; 323 321 $first_item = ($plog_page - 1) * $_SESSION['entries_per_page']; 324 322 if ($first_item < 0) { 325 323 $first_item = 0; 326 } ;327 $limit = "LIMIT $first_item, $_SESSION[entries_per_page]";324 } 325 $limit = "LIMIT ".$first_item.", ".$_SESSION['entries_per_page']; 328 326 329 327 // lets generate the pagination menu as well 330 328 $recordCount = "SELECT COUNT(*) AS num_items FROM ".TABLE_PREFIX."$level $cond"; … … 332 330 $totalRows = mysql_result($totalRowsResult,'num_items'); 333 331 334 332 $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>';333 $pagination_menu = "\n\t\t" . '<div class="pagination">'.generate_pagination("manage", $id, $page, $totalRows, $_SESSION['entries_per_page'], array("level" => $_REQUEST['level'], "entries_per_page" => $_SESSION['entries_per_page'])).'</div>'; 336 334 337 335 $output .= "\n\t\t" . '<form id="contentList" action="'.$_SERVER["PHP_SELF"].'" method="get">'; 338 336 … … 341 339 if (empty($level)) { 342 340 $output .= generate_breadcrumb_admin("").$pagination_menu; 343 341 $output .= plog_collection_manager($first_item,$_SESSION['entries_per_page']); 344 } ;342 } 345 343 346 344 if ($level == "albums") { 347 345 $output .= generate_breadcrumb_admin("albums", $id).$pagination_menu; … … 373 371 374 372 display($output, "manage"); 375 373 376 ?> 377 No newline at end of file 374 ?> -
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 an album named 'plog_page' 1028 if (isset($names['collection']) && $names['collection'] == 'plog_page') { 1029 if (isset($names['album'])) { 1030 return array("level" => "collections", "id" => 0, "plog_page" => intval($names['album'])); 1031 } 1032 } 1026 1033 1027 1034 if (!empty($names["collection"])) { 1028 1035 $sql = "SELECT * … … 1037 1044 1038 1045 $collection = mysql_fetch_assoc($result); 1039 1046 1047 // try to detect collection level paging for multiple albums. Downside is you cannot have an album named 'plog_page' 1048 if (isset($names['album']) && $names['album'] == 'plog_page') { 1049 if (isset($names['picture'])) { 1050 return array("level" => "collection", "id" => $collection['id'], "plog_page" => intval($names['picture'])); 1051 } 1052 } 1053 1040 1054 // what if there are multiple collections with same names? I hope there aren't .. this would 1041 1055 // suck. But here is an idea, we shouldn't allow the user to enter similar names 1042 1056 $rv = array("level" => "collection","id" => $collection["id"]); … … 1056 1070 1057 1071 $album = mysql_fetch_assoc($result); 1058 1072 1073 // try to detect album level paging for multiple pictures. Downside is you cannot have an picture named 'plog_page' 1074 if (isset($names['picture']) && $names['picture'] == 'plog_page') { 1075 if (isset($names['arg1'])) { 1076 return array("level" => "album", "id" => $album['id'], "plog_page" => intval($names['arg1'])); 1077 } 1078 } 1079 1059 1080 // try to detect slideshow. Downside is that you cannot have a picture with that name 1060 1081 if (isset($names['picture']) && $names['picture'] == 'slideshow') { 1061 1082 return array('level' => 'album','mode' => 'slideshow','id' => $album['id']); … … 1111 1132 return $rv; 1112 1133 } 1113 1134 1114 function generate_pagination($ url, $current_page, $items_total, $items_on_page, $extra_params = ''){1135 function generate_pagination($level, $id, $current_page, $items_total, $items_on_page, $extra_params = array()){ 1115 1136 $output = ''; 1116 1137 1117 if (!isset($GLOBALS[ "total_pictures"])) $GLOBALS["total_pictures"] = 0;1138 if (!isset($GLOBALS['total_pictures'])) $GLOBALS['total_pictures'] = 0; 1118 1139 1119 if (($items_total == 0) && ($GLOBALS[ "total_pictures"] > 0)) {1120 $items_total = $GLOBALS[ "total_pictures"];1140 if (($items_total == 0) && ($GLOBALS['total_pictures'] > 0)) { 1141 $items_total = $GLOBALS['total_pictures']; 1121 1142 } 1122 1143 1123 1144 $num_pages = ceil($items_total / $items_on_page); 1124 1145 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 1146 if ($num_pages > 1){ 1136 1147 if ($current_page > 1){ 1137 $output .= ' <a accesskey="," class="pagPrev" href="'.$url.$separator.'plog_page='.($current_page - 1).$extra_params.'"><span>«</span></a> '; 1148 $page = array(1 => "plog_page", "plog_page" => $current_page - 1); 1149 $args = array_merge($page, $extra_params); 1150 $output .= ' <a accesskey="," class="pagPrev" href="'.generate_url($level, $id, $args).'"><span>«</span></a> '; 1138 1151 } 1139 1152 1140 1153 for ($i = 1; $i <= $num_pages; $i++){ 1141 1154 if ($i == $current_page){ 1142 1155 $output .= '<span class="page_link"> ['.$i.'] </span>'; 1143 1156 } else{ 1144 $output .= '<a href="'.$url.$separator.'plog_page='.$i.$extra_params.'" class="page_link">'.$i.'</a> '; 1157 $page = array(1 => "plog_page", "plog_page" => $i); 1158 $args = array_merge($page, $extra_params); 1159 $output .= '<a href="'.generate_url($level, $id, $args).'" class="page_link">'.$i.'</a> '; 1145 1160 } 1146 1161 } 1147 1162 1148 1163 if ($current_page != $num_pages){ 1149 $output .= ' <a accesskey="." class="pagNext" href="'.$url.$separator.'plog_page='.($current_page + 1).$extra_params.'"><span>»</span></a> '; 1164 $page = array(1 => "plog_page", "plog_page" => $current_page + 1); 1165 $args = array_merge($page, $extra_params); 1166 $output .= ' <a accesskey="." class="pagNext" href="'.generate_url($level, $id, $args).'"><span>»</span></a> '; 1150 1167 } 1151 1168 } 1152 1169 … … 1166 1183 $rv = ''; 1167 1184 1168 1185 if ($config['use_mod_rewrite']){ 1186 $args = ''; 1187 // I need to give additional arguments to the url-s 1188 if (sizeof($arg) > 0) { 1189 foreach($arg as $aval) { 1190 $args .= $aval."/"; 1191 } 1192 } 1193 1169 1194 switch($level){ 1170 1195 case "collection": 1171 1196 $query = "SELECT `path` FROM `".TABLE_PREFIX."collections` WHERE `id`=".intval($id); 1172 1197 $result = run_query($query); 1173 1198 $row = mysql_fetch_assoc($result); 1174 $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['path']))."/" ;1199 $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['path']))."/".$args; 1175 1200 break; 1176 1201 case "album": 1177 1202 $query = "SELECT … … 1182 1207 WHERE `a`.`id`=".intval($id); 1183 1208 $result = run_query($query); 1184 1209 $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 } 1210 $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['collection_path'])) . '/' . rawurlencode(SmartStripSlashes($row['album_path']))."/".$args; 1194 1211 break; 1195 1212 case "picture": 1196 1213 $pic = get_picture_by_id($id); … … 1202 1219 // I need to give additional arguments to the url-s 1203 1220 if (sizeof($arg) > 0) { 1204 1221 foreach($arg as $akey => $aval) { 1205 // 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') {1222 // mod_rewrite url-s need /sorted and /plog_page in them, the old style ones do not. 1223 // this temporary workaround removes the 'sorted' and 'plog_page' strings 1224 if ($aval != "sorted" && $aval != "plog_page") { 1208 1225 $rv .= "&".$akey."=".$aval; 1209 1226 } 1210 1227 } 1211 1228 } 1229 //$rv .= "?level=search&searchterms=".$arg['searchterms']; 1212 1230 break; 1213 1231 case "collections": 1214 default:1215 $rv = $config['baseurl'] ;1232 default: 1233 $rv = $config['baseurl'].$args; 1216 1234 break; 1217 1235 } 1218 1236 } else { 1219 1237 // 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 = "?"; 1238 // non-Plogger query items only work with old style URLs (not with mod_rewrite URLs) 1239 $query = (isset($config['query_args'])) ? "?".$config['query_args']."&" : "?"; 1240 1241 $args = ''; 1242 // add on any additional arguments from the $arg array 1243 if (sizeof($arg) > 0) { 1244 foreach($arg as $akey => $aval) { 1245 // mod_rewrite url-s need /sorted and /plog_page in them, the old style ones do not. 1246 // this temporary workaround removes the 'sorted' and 'plog_page' strings 1247 if ($aval != "sorted" && $aval != "plog_page") { 1248 $args .= "&".$akey."=".$aval; 1249 } 1250 } 1251 } 1221 1252 1222 1253 switch($level){ 1223 1254 case "collection": 1224 return $config['baseurl'].$query.'level=collection&id='.$id;1255 $rv = $config['baseurl'].$query.'level=collection&id='.$id.$args; 1225 1256 break; 1226 1257 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 } 1258 $rv = $config['baseurl'].$query.'level=album&id='.$id.$args; 1237 1259 break; 1238 1260 case "picture": 1239 1261 $rv = $config['baseurl'].$query.'level=picture&id='.$id; 1240 1262 break; 1241 1263 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 } 1264 $rv = $config['baseurl'].$query."level=search".$args; 1253 1265 break; 1266 case "manage": 1267 $rv = $config['baseurl']."plog-admin/plog-manage.php?id=".$id.$args; 1268 break; 1254 1269 case "collections": 1255 default: 1256 $query = (isset($config['query_args'])) ? "?".$config['query_args'] : $query = ""; 1257 $rv = $config['baseurl'].$query; 1270 default: 1271 $rv = $config['baseurl']; 1272 if ($query != "?" && empty($args)) { 1273 $rv .= $query.$args; 1274 } 1258 1275 break; 1259 1276 } 1260 1277 } 1261 1278 1262 // replace & with & if outputting to email1279 // replace & with & if formatting plaintext (i.e. outputting to email) 1263 1280 if ($plaintext !== false){ 1264 1281 $rv = str_replace("&","&",$rv); 1265 1282 } … … 1974 1991 global $config; 1975 1992 1976 1993 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']) { 1994 $page = isset($_GET['plog_page']) ? intval($_GET['plog_page']) : 1; 1995 $level = $GLOBALS['plogger_level']; 1996 $id = $GLOBALS['plogger_id']; 1997 switch($level) { 1991 1998 case 'search': 1992 $num_items = $GLOBALS["total_pictures"]; 1993 break; 1999 $num_items = $GLOBALS['total_pictures']; 2000 return generate_pagination("search", -1, $page, $num_items, $config['thumb_num'], array('searchterms'=>urlencode($_GET['searchterms']))); 2001 break; 1994 2002 1995 2003 case 'album': 1996 2004 $num_items = plogger_album_picture_count(); 1997 break;2005 break; 1998 2006 1999 2007 case 'collection': 2000 2008 $num_items = plogger_collection_album_count(); 2001 break;2009 break; 2002 2010 2003 2011 default: 2004 $num_items = plogger_count_collections(); 2005 break; 2012 $level = "collections"; 2013 $id = 0; 2014 $num_items = plogger_count_collections(); 2015 break; 2006 2016 } 2007 2017 2008 return generate_pagination($ p_url, $page, $num_items, $config["thumb_num"]);2018 return generate_pagination($level, $id, $page, $num_items, $config['thumb_num']); 2009 2019 } 2010 2020 2011 2021 } -
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['use_mod_rewrite'] = 0; 88 89 $config['baseurl'] = substr($config['baseurl'],0,strpos($config['baseurl'], "plog-admin/")); 89 90 } 90 91 … … 170 171 171 172 } 172 173 173 ?> 174 No newline at end of file 174 ?> -
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 { … … 153 150 include(PLOGGER_DIR.'/plog-content/themes/default/'.$use_file); 154 151 } 155 152 } 156 ?> 157 No newline at end of file 153 ?>
