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

     
    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

     
    10241024                } 
    10251025        } 
    10261026 
    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                } 
    10281032                $sql = "SELECT * 
    10291033                FROM `".TABLE_PREFIX."collections` 
    1030                 WHERE `path`='".$names["collection"]."'"; 
     1034                WHERE `path`='".$names['collection']."'"; 
    10311035                $result = run_query($sql); 
    10321036 
    10331037                // No such collection, fall back to main page 
     
    10391043 
    10401044                // what if there are multiple collections with same names? I hope there aren't .. this would 
    10411045                // 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']); 
    10431047        } 
    10441048 
    10451049        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                } 
    10461054                $sql = "SELECT * 
    10471055                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']); 
    10501058                $result = run_query($sql); 
    10511059 
    10521060                // no such album, fall back to collection 
     
    10771085                $rv = array('level' => 'album','id' => $album['id']); 
    10781086        } 
    10791087 
    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                } 
    10811093                $sql = "SELECT * 
    10821094                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']); 
    10851097                $result = run_query($sql); 
    10861098 
    10871099                $picture = mysql_fetch_assoc($result); 
     
    11051117                        return $rv; 
    11061118                } 
    11071119 
    1108                 $rv = array("level" => "picture", "id" => $picture["id"]); 
     1120                $rv = array("level" => "picture", "id" => $picture['id']); 
    11091121        } 
    11101122 
    11111123        return $rv; 
    11121124} 
    11131125 
    1114 function generate_pagination($url, $current_page, $items_total, $items_on_page, $extra_params = ''){ 
     1126function generate_pagination($level, $id, $current_page, $items_total, $items_on_page, $args = array(1 => "page")){ 
    11151127        $output = ''; 
    11161128 
    1117         if (!isset($GLOBALS["total_pictures"])) $GLOBALS["total_pictures"] = 0; 
     1129        if (!isset($GLOBALS['total_pictures'])) $GLOBALS['total_pictures'] = 0; 
    11181130 
    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']; 
    11211133        } 
    11221134 
    11231135        $num_pages = ceil($items_total / $items_on_page); 
    11241136 
    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  
    11351137        if ($num_pages > 1){ 
    11361138                if ($current_page > 1){ 
    1137                         $output .= ' <a accesskey="," class="pagPrev" href="'.$url.$separator.'plog_page='.($current_page - 1).$extra_params.'"><span>&laquo;</span></a> '; 
     1139                        $args['plog_page'] = $current_page - 1; 
     1140                        $output .= ' <a accesskey="," class="pagPrev" href="'.generate_url($level, $id, $args).'"><span>&laquo;</span></a> '; 
    11381141                } 
    11391142 
    11401143                for ($i = 1; $i <= $num_pages; $i++){ 
    11411144                        if ($i == $current_page){ 
    11421145                                $output .= '<span class="page_link"> ['.$i.'] </span>'; 
    11431146                        } 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> '; 
    11451149                        } 
    11461150                } 
    11471151 
    11481152                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> '; 
     1153                        $args['plog_page'] =  $current_page + 1; 
     1154                        $output .= ' <a accesskey="." class="pagNext" href="'.generate_url($level, $id, $args).'"><span>&raquo;</span></a> '; 
    11501155                } 
    11511156        } 
    11521157 
     
    11661171        $rv = ''; 
    11671172 
    11681173        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 
    11691182                switch($level){ 
    11701183                        case "collection": 
    11711184                                $query = "SELECT `path` FROM `".TABLE_PREFIX."collections` WHERE `id`=".intval($id); 
    11721185                                $result = run_query($query); 
    11731186                                $row = mysql_fetch_assoc($result); 
    1174                                 $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['path']))."/"; 
     1187                                $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['path']))."/".$args; 
    11751188                                break; 
    11761189                        case "album": 
    11771190                                $query = "SELECT 
     
    11821195                                WHERE `a`.`id`=".intval($id); 
    11831196                                $result = run_query($query); 
    11841197                                $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; 
    11941199                                break; 
    11951200                        case "picture": 
    11961201                                $pic = get_picture_by_id($id); 
     
    12031208                                if (sizeof($arg) > 0) { 
    12041209                                        foreach($arg as $akey => $aval) { 
    12051210                                                // 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') { 
     1211                                                // this temporary workaround removes the 'sorted' and 'plog_page' strings 
     1212                                                if (!is_numeric($akey)) { 
    12081213                                                        $rv .= "&amp;".$akey."=".$aval; 
    12091214                                                } 
    12101215                                        } 
    12111216                                } 
    12121217                                break; 
    12131218                        case "collections": 
    1214                                 default: 
    1215                                 $rv = $config['baseurl']; 
     1219                        default: 
     1220                                $rv = $config['baseurl'].$args; 
    12161221                                break; 
    12171222                } 
    12181223        } else { 
    12191224                // 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 = "?"; 
     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']."&amp;" : "?"; 
     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 .= "&amp;".$akey."=".$aval; 
     1236                                } 
     1237                        } 
     1238                } 
    12211239 
    12221240                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 
    12231246                        case "collection": 
    1224                                 return $config['baseurl'].$query.'level=collection&amp;id='.$id; 
     1247                                $rv = $config['baseurl'].$query.'level=collection&amp;id='.$id.$args; 
    12251248                                break; 
    12261249                        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                                 } 
     1250                                $rv = $config['baseurl'].$query.'level=album&amp;id='.$id.$args; 
    12371251                                break; 
    12381252                        case "picture": 
    12391253                                $rv = $config['baseurl'].$query.'level=picture&amp;id='.$id; 
    12401254                                break; 
    12411255                        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                                 } 
     1256                                $rv = $config['baseurl'].$query."level=search".$args; 
    12531257                                break; 
    12541258                        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                                } 
    12581265                                break; 
    12591266                } 
    12601267        } 
    12611268 
    1262         // replace &amp; with & if outputting to email 
     1269        // replace &amp; with & if formatting plaintext (i.e. outputting to email) 
    12631270        if ($plaintext !== false){ 
    12641271                $rv = str_replace("&amp;","&",$rv); 
    12651272        } 
     
    19741981        global $config; 
    19751982 
    19761983        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) { 
    19911988                        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; 
    19941992 
    19951993                        case 'album': 
    19961994                                $num_items = plogger_album_picture_count(); 
    1997                         break; 
     1995                                break; 
    19981996 
    19991997                        case 'collection': 
    20001998                                $num_items = plogger_collection_album_count(); 
    2001                         break; 
     1999                                break; 
    20022000 
    20032001                        default: 
    2004                         $num_items = plogger_count_collections(); 
    2005                         break; 
     2002                                $level = "collections"; 
     2003                                $id = 0; 
     2004                                $num_items = plogger_count_collections(); 
     2005                                break; 
    20062006                } 
    20072007 
    2008                 return generate_pagination($p_url, $page, $num_items, $config["thumb_num"]); 
     2008                return generate_pagination($level, $id, $page, $num_items, $config['thumb_num']); 
    20092009        } 
    20102010 
    20112011} 
  • 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 {