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

     
    109109#$url = "&entries_per_page=$_SESSION[entries_per_page]&level=$_REQUEST[level]&id=$_REQUEST[id]"; 
    110110$url = "?entries_per_page=$_SESSION[entries_per_page]"; 
    111111 
    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']; 
    113115$limit = "LIMIT $first_item, $_SESSION[entries_per_page]"; 
    114116 
    115117// lets generate the pagination menu as well 
     
    121123$mod_result = run_query($query); 
    122124$num_comments_im = mysql_result($mod_result, "in_moderation"); 
    123125 
    124 $page = isset($_GET["plog_page"]) ? $_GET["plog_page"] : 1; 
    125  
    126126// 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; 
    128128 
    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"); 
     129if ($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} 
    133134 
    134135// generate javascript init function for ajax editing 
    135136$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

     
    300300 
    301301        // handle pagination 
    302302        // 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        } 
    304308 
    305         if (isset($_REQUEST['entries_per_page'])) 
    306         $_SESSION['entries_per_page'] = $_REQUEST['entries_per_page']; 
    307         else 
    308         $_SESSION['entries_per_page'] = 20; 
    309  
    310309        $cond = ""; 
    311310 
    312311        // determine the filtering conditional based on the level and id number 
     
    317316                $cond = "WHERE `parent_album` = '$id'"; 
    318317        } 
    319318 
    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 
    323320        $first_item = ($plog_page - 1) * $_SESSION['entries_per_page']; 
    324321        if ($first_item < 0) { 
    325322                $first_item = 0; 
    326         }; 
    327         $limit = "LIMIT $first_item, $_SESSION[entries_per_page]"; 
     323        } 
     324        $limit = "LIMIT ".$first_item.", ".$_SESSION['entries_per_page']; 
    328325 
    329326        // lets generate the pagination menu as well 
    330327        $recordCount = "SELECT COUNT(*) AS num_items FROM ".TABLE_PREFIX."$level $cond"; 
    331328        $totalRowsResult = mysql_query($recordCount); 
    332329        $totalRows = mysql_result($totalRowsResult,'num_items'); 
    333330 
    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>'; 
    336332 
    337333        $output .= "\n\t\t" . '<form id="contentList" action="'.$_SERVER["PHP_SELF"].'" method="get">'; 
    338334 
    339335        $level = $_REQUEST['level']; 
    340336 
    341         if (empty($level)) { 
     337        if (empty($level) || $level == "collections") { 
    342338                $output .= generate_breadcrumb_admin("").$pagination_menu; 
    343339                $output .= plog_collection_manager($first_item,$_SESSION['entries_per_page']); 
    344         }; 
     340        } 
    345341 
    346342        if ($level == "albums") { 
    347343                $output .= generate_breadcrumb_admin("albums", $id).$pagination_menu; 
     
    365361                <input type="hidden" name="id" value="'.$id.'" /> 
    366362                <input type="hidden" name="action" value="1" /> 
    367363                <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 != "comments"){ 
     364        if (!empty($level) && $level != "collections" && $level != "comments"){ 
    369365                $output .= generate_move_menu($level); 
    370366        }; 
    371367        $output .= "\n\t\t</div>\n\t\t</form>\n"; 
  • 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 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        } 
    10261031 
    10271032        if (!empty($names["collection"])) { 
    10281033                $sql = "SELECT * 
     
    10371042 
    10381043                $collection = mysql_fetch_assoc($result); 
    10391044 
     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 
    10401050                // what if there are multiple collections with same names? I hope there aren't .. this would 
    10411051                // suck. But here is an idea, we shouldn't allow the user to enter similar names 
    10421052                $rv = array("level" => "collection","id" => $collection["id"]); 
     
    10561066 
    10571067                $album = mysql_fetch_assoc($result); 
    10581068 
     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 
    10591074                // try to detect slideshow. Downside is that you cannot have a picture with that name 
    10601075                if (isset($names['picture']) && $names['picture'] == 'slideshow') { 
    10611076                        return array('level' => 'album','mode' => 'slideshow','id' => $album['id']); 
     
    11111126        return $rv; 
    11121127} 
    11131128 
    1114 function generate_pagination($url, $current_page, $items_total, $items_on_page, $extra_params = ''){ 
     1129function generate_pagination($level, $id, $current_page, $items_total, $items_on_page, $args = array()){ 
    11151130        $output = ''; 
    11161131 
    1117         if (!isset($GLOBALS["total_pictures"])) $GLOBALS["total_pictures"] = 0; 
     1132        if (!isset($GLOBALS['total_pictures'])) $GLOBALS['total_pictures'] = 0; 
    11181133 
    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']; 
    11211136        } 
    11221137 
    11231138        $num_pages = ceil($items_total / $items_on_page); 
    11241139 
    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  
    11351140        if ($num_pages > 1){ 
    11361141                if ($current_page > 1){ 
    1137                         $output .= ' <a accesskey="," class="pagPrev" href="'.$url.$separator.'plog_page='.($current_page - 1).$extra_params.'"><span>&laquo;</span></a> '; 
     1142                        $args['plog_page'] = $current_page - 1; 
     1143                        $output .= ' <a accesskey="," class="pagPrev" href="'.generate_url($level, $id, $args).'"><span>&laquo;</span></a> '; 
    11381144                } 
    11391145 
    11401146                for ($i = 1; $i <= $num_pages; $i++){ 
    11411147                        if ($i == $current_page){ 
    11421148                                $output .= '<span class="page_link"> ['.$i.'] </span>'; 
    11431149                        } 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> '; 
    11451152                        } 
    11461153                } 
    11471154 
    11481155                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> '; 
     1156                        $args['plog_page'] =  $current_page + 1; 
     1157                        $output .= ' <a accesskey="." class="pagNext" href="'.generate_url($level, $id, $args).'"><span>&raquo;</span></a> '; 
    11501158                } 
    11511159        } 
    11521160 
     
    11661174        $rv = ''; 
    11671175 
    11681176        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 
    11691185                switch($level){ 
    11701186                        case "collection": 
    11711187                                $query = "SELECT `path` FROM `".TABLE_PREFIX."collections` WHERE `id`=".intval($id); 
    11721188                                $result = run_query($query); 
    11731189                                $row = mysql_fetch_assoc($result); 
    1174                                 $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['path']))."/"; 
     1190                                $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['path']))."/".$args; 
    11751191                                break; 
    11761192                        case "album": 
    11771193                                $query = "SELECT 
     
    11821198                                WHERE `a`.`id`=".intval($id); 
    11831199                                $result = run_query($query); 
    11841200                                $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; 
    11941202                                break; 
    11951203                        case "picture": 
    11961204                                $pic = get_picture_by_id($id); 
     
    12031211                                if (sizeof($arg) > 0) { 
    12041212                                        foreach($arg as $akey => $aval) { 
    12051213                                                // 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') { 
     1214                                                // this temporary workaround removes the 'sorted' and 'plog_page' strings 
     1215                                                if ($aval != "sorted") { 
    12081216                                                        $rv .= "&amp;".$akey."=".$aval; 
    12091217                                                } 
    12101218                                        } 
    12111219                                } 
    12121220                                break; 
    12131221                        case "collections": 
    1214                                 default: 
    1215                                 $rv = $config['baseurl']; 
     1222                        default: 
     1223                                $rv = $config['baseurl'].$args; 
    12161224                                break; 
    12171225                } 
    12181226        } else { 
    12191227                // 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 = "?"; 
     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']."&amp;" : "?"; 
     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 .= "&amp;".$akey."=".$aval; 
     1239                                } 
     1240                        } 
     1241                } 
    12211242 
    12221243                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 
    12231249                        case "collection": 
    1224                                 return $config['baseurl'].$query.'level=collection&amp;id='.$id; 
     1250                                $rv = $config['baseurl'].$query.'level=collection&amp;id='.$id.$args; 
    12251251                                break; 
    12261252                        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                                 } 
     1253                                $rv = $config['baseurl'].$query.'level=album&amp;id='.$id.$args; 
    12371254                                break; 
    12381255                        case "picture": 
    12391256                                $rv = $config['baseurl'].$query.'level=picture&amp;id='.$id; 
    12401257                                break; 
    12411258                        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                                 } 
     1259                                $rv = $config['baseurl'].$query."level=search".$args; 
    12531260                                break; 
    12541261                        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                                } 
    12581268                                break; 
    12591269                } 
    12601270        } 
    12611271 
    1262         // replace &amp; with & if outputting to email 
     1272        // replace &amp; with & if formatting plaintext (i.e. outputting to email) 
    12631273        if ($plaintext !== false){ 
    12641274                $rv = str_replace("&amp;","&",$rv); 
    12651275        } 
     
    19741984        global $config; 
    19751985 
    19761986        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) { 
    19911991                        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; 
    19941995 
    19951996                        case 'album': 
    19961997                                $num_items = plogger_album_picture_count(); 
    1997                         break; 
     1998                                break; 
    19981999 
    19992000                        case 'collection': 
    20002001                                $num_items = plogger_collection_album_count(); 
    2001                         break; 
     2002                                break; 
    20022003 
    20032004                        default: 
    2004                         $num_items = plogger_count_collections(); 
    2005                         break; 
     2005                                $level = "collections"; 
     2006                                $id = 0; 
     2007                                $num_items = plogger_count_collections(); 
     2008                                break; 
    20062009                } 
    20072010 
    2008                 return generate_pagination($p_url, $page, $num_items, $config["thumb_num"]); 
     2011                return generate_pagination($level, $id, $page, $num_items, $config['thumb_num']); 
    20092012        } 
    20102013 
    20112014} 
  • 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['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/")); 
    8990} 
    9091 
    9192$config['theme_url'] = $config['gallery_url']."plog-content/themes/".basename($config['theme_dir'])."/"; 
  • 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 {