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

     
    317317                $cond = "WHERE `parent_album` = '$id'"; 
    318318        } 
    319319 
    320         $url = "?entries_per_page=$_SESSION[entries_per_page]&level=$_REQUEST[level]&id=$id"; 
    321  
    322320        $plog_page = isset($_REQUEST['plog_page']) ? $_REQUEST['plog_page'] : 0; 
    323321        $first_item = ($plog_page - 1) * $_SESSION['entries_per_page']; 
    324322        if ($first_item < 0) { 
    325323                $first_item = 0; 
    326         }; 
    327         $limit = "LIMIT $first_item, $_SESSION[entries_per_page]"; 
     324        } 
     325        $limit = "LIMIT ".$first_item.", ".$_SESSION['entries_per_page']; 
    328326 
    329327        // lets generate the pagination menu as well 
    330328        $recordCount = "SELECT COUNT(*) AS num_items FROM ".TABLE_PREFIX."$level $cond"; 
     
    332330        $totalRows = mysql_result($totalRowsResult,'num_items'); 
    333331 
    334332        $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>'; 
    336334 
    337335        $output .= "\n\t\t" . '<form id="contentList" action="'.$_SERVER["PHP_SELF"].'" method="get">'; 
    338336 
     
    341339        if (empty($level)) { 
    342340                $output .= generate_breadcrumb_admin("").$pagination_menu; 
    343341                $output .= plog_collection_manager($first_item,$_SESSION['entries_per_page']); 
    344         }; 
     342        } 
    345343 
    346344        if ($level == "albums") { 
    347345                $output .= generate_breadcrumb_admin("albums", $id).$pagination_menu; 
     
    373371 
    374372display($output, "manage"); 
    375373 
    376 ?> 
    377  No newline at end of file 
     374?> 
  • plog-includes/plog-functions.php

     
    10231023                        $current_level = $level; 
    10241024                } 
    10251025        } 
     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        } 
    10261033 
    10271034        if (!empty($names["collection"])) { 
    10281035                $sql = "SELECT * 
     
    10371044 
    10381045                $collection = mysql_fetch_assoc($result); 
    10391046 
     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 
    10401054                // what if there are multiple collections with same names? I hope there aren't .. this would 
    10411055                // suck. But here is an idea, we shouldn't allow the user to enter similar names 
    10421056                $rv = array("level" => "collection","id" => $collection["id"]); 
     
    10561070 
    10571071                $album = mysql_fetch_assoc($result); 
    10581072 
     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 
    10591080                // try to detect slideshow. Downside is that you cannot have a picture with that name 
    10601081                if (isset($names['picture']) && $names['picture'] == 'slideshow') { 
    10611082                        return array('level' => 'album','mode' => 'slideshow','id' => $album['id']); 
     
    11111132        return $rv; 
    11121133} 
    11131134 
    1114 function generate_pagination($url, $current_page, $items_total, $items_on_page, $extra_params = ''){ 
     1135function generate_pagination($level, $id, $current_page, $items_total, $items_on_page, $extra_params = array()){ 
    11151136        $output = ''; 
    11161137 
    1117         if (!isset($GLOBALS["total_pictures"])) $GLOBALS["total_pictures"] = 0; 
     1138        if (!isset($GLOBALS['total_pictures'])) $GLOBALS['total_pictures'] = 0; 
    11181139 
    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']; 
    11211142        } 
    11221143 
    11231144        $num_pages = ceil($items_total / $items_on_page); 
    11241145 
    1125         // if adding arguments to mod_rewritten urls, then I need ? (question mark) before the arguments 
    1126         // otherwise I want &amp; 
    1127         //$last = substr($url,-1); 
    1128  
    1129         if (!strpos($url,"?")) { 
    1130                 $separator = "?"; 
    1131         } else { 
    1132                 $separator = "&amp;"; 
    1133         } 
    1134  
    11351146        if ($num_pages > 1){ 
    11361147                if ($current_page > 1){ 
    1137                         $output .= ' <a accesskey="," class="pagPrev" href="'.$url.$separator.'plog_page='.($current_page - 1).$extra_params.'"><span>&laquo;</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>&laquo;</span></a> '; 
    11381151                } 
    11391152 
    11401153                for ($i = 1; $i <= $num_pages; $i++){ 
    11411154                        if ($i == $current_page){ 
    11421155                                $output .= '<span class="page_link"> ['.$i.'] </span>'; 
    11431156                        } 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> '; 
    11451160                        } 
    11461161                } 
    11471162 
    11481163                if ($current_page != $num_pages){ 
    1149                         $output .= ' <a accesskey="." class="pagNext" href="'.$url.$separator.'plog_page='.($current_page + 1).$extra_params.'"><span>&raquo;</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>&raquo;</span></a> '; 
    11501167                } 
    11511168        } 
    11521169 
     
    11661183        $rv = ''; 
    11671184 
    11681185        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 
    11691194                switch($level){ 
    11701195                        case "collection": 
    11711196                                $query = "SELECT `path` FROM `".TABLE_PREFIX."collections` WHERE `id`=".intval($id); 
    11721197                                $result = run_query($query); 
    11731198                                $row = mysql_fetch_assoc($result); 
    1174                                 $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['path']))."/"; 
     1199                                $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['path']))."/".$args; 
    11751200                                break; 
    11761201                        case "album": 
    11771202                                $query = "SELECT 
     
    11821207                                WHERE `a`.`id`=".intval($id); 
    11831208                                $result = run_query($query); 
    11841209                                $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; 
    11941211                                break; 
    11951212                        case "picture": 
    11961213                                $pic = get_picture_by_id($id); 
     
    12021219                                // I need to give additional arguments to the url-s 
    12031220                                if (sizeof($arg) > 0) { 
    12041221                                        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' string 
    1207                                                 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") { 
    12081225                                                        $rv .= "&amp;".$akey."=".$aval; 
    12091226                                                } 
    12101227                                        } 
    12111228                                } 
     1229                                //$rv .= "?level=search&amp;searchterms=".$arg['searchterms']; 
    12121230                                break; 
    12131231                        case "collections": 
    1214                                 default: 
    1215                                 $rv = $config['baseurl']; 
     1232                        default: 
     1233                                $rv = $config['baseurl'].$args; 
    12161234                                break; 
    12171235                } 
    12181236        } else { 
    12191237                // 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']."&amp;" : $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']."&amp;" : "?"; 
     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 .= "&amp;".$akey."=".$aval; 
     1249                                } 
     1250                        } 
     1251                } 
    12211252 
    12221253                switch($level){ 
    12231254                        case "collection": 
    1224                                 return $config['baseurl'].$query.'level=collection&amp;id='.$id; 
     1255                                $rv = $config['baseurl'].$query.'level=collection&amp;id='.$id.$args; 
    12251256                                break; 
    12261257                        case "album": 
    1227                                 $rv = $config['baseurl'].$query.'level=album&amp;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 .= "&amp;".$akey."=".$aval; 
    1234                                                 } 
    1235                                         } 
    1236                                 } 
     1258                                $rv = $config['baseurl'].$query.'level=album&amp;id='.$id.$args; 
    12371259                                break; 
    12381260                        case "picture": 
    12391261                                $rv = $config['baseurl'].$query.'level=picture&amp;id='.$id; 
    12401262                                break; 
    12411263                        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 .= "&amp;".$akey."=".$aval; 
    1250                                                 } 
    1251                                         } 
    1252                                 } 
     1264                                $rv = $config['baseurl'].$query."level=search".$args; 
    12531265                                break; 
     1266                        case "manage": 
     1267                                $rv = $config['baseurl']."plog-admin/plog-manage.php?id=".$id.$args; 
     1268                                break; 
    12541269                        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                                } 
    12581275                                break; 
    12591276                } 
    12601277        } 
    12611278 
    1262         // replace &amp; with & if outputting to email 
     1279        // replace &amp; with & if formatting plaintext (i.e. outputting to email) 
    12631280        if ($plaintext !== false){ 
    12641281                $rv = str_replace("&amp;","&",$rv); 
    12651282        } 
     
    19741991        global $config; 
    19751992 
    19761993        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) { 
    19911998                        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; 
    19942002 
    19952003                        case 'album': 
    19962004                                $num_items = plogger_album_picture_count(); 
    1997                         break; 
     2005                                break; 
    19982006 
    19992007                        case 'collection': 
    20002008                                $num_items = plogger_collection_album_count(); 
    2001                         break; 
     2009                                break; 
    20022010 
    20032011                        default: 
    2004                         $num_items = plogger_count_collections(); 
    2005                         break; 
     2012                                $level = "collections"; 
     2013                                $id = 0; 
     2014                                $num_items = plogger_count_collections(); 
     2015                                break; 
    20062016                } 
    20072017 
    2008                 return generate_pagination($p_url, $page, $num_items, $config["thumb_num"]); 
     2018                return generate_pagination($level, $id, $page, $num_items, $config['thumb_num']); 
    20092019        } 
    20102020 
    20112021} 
  • plog-load-config.php

     
    8585// remove plog-admin/ from the end, if present .. is there a better way to determine the full url? 
    8686// had to update this for new use of links without mod_rewrite turned on (only affects the View gallery greybox in Admin) 
    8787if (strpos($config['baseurl'], "plog-admin/")) { 
     88        $config['use_mod_rewrite'] = 0; 
    8889        $config['baseurl'] = substr($config['baseurl'],0,strpos($config['baseurl'], "plog-admin/")); 
    8990} 
    9091 
     
    170171 
    171172} 
    172173 
    173 ?> 
    174  No newline at end of file 
     174?> 
  • plogger.php

     
    2121                if (isset($resolved_path['id'])) { 
    2222                        $_GET['id'] = $resolved_path['id']; 
    2323                } 
     24                if (isset($resolved_path['plog_page'])) { 
     25                        $_GET['plog_page'] = $resolved_path['plog_page']; 
     26                } 
    2427                if (isset($resolved_path['mode'])) { 
    2528                        $_GET['mode'] = $resolved_path['mode']; 
    2629                } 
    2730 
    28                 // get page number from url, if present 
     31                // get the path for RSS links (maybe should rework this) 
    2932                $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                 } 
    3633                $path = $parts['path']; 
    3734        } 
    3835} else { 
     
    153150                include(PLOGGER_DIR.'/plog-content/themes/default/'.$use_file); 
    154151        } 
    155152} 
    156 ?> 
    157  No newline at end of file 
     153?>