Show
Ignore:
Timestamp:
07/21/08 19:18:07 (4 months ago)
Author:
sidtheduck
Message:

+ Fix for ticket #160 - cruft-free pagination
+ Couple of miscellaneous syntax edits

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/plog-includes/plog-functions.php

    r562 r563  
    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 
     
    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 
     
    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 
     
    11061118                } 
    11071119 
    1108                 $rv = array("level" => "picture", "id" => $picture["id"]); 
     1120                $rv = array("level" => "picture", "id" => $picture['id']); 
    11091121        } 
    11101122 
     
    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; 
    1118  
    1119         if (($items_total == 0) && ($GLOBALS["total_pictures"] > 0)) { 
    1120                 $items_total = $GLOBALS["total_pictures"]; 
     1129        if (!isset($GLOBALS['total_pictures'])) $GLOBALS['total_pictures'] = 0; 
     1130 
     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); 
    1124  
    1125         // if adding arguments to mod_rewritten urls, then I need ? (question mark) before the arguments 
    1126         // otherwise I want & 
    1127         //$last = substr($url,-1); 
    1128  
    1129         if (!strpos($url,"?")) { 
    1130                 $separator = "?"; 
    1131         } else { 
    1132                 $separator = "&"; 
    1133         } 
    11341136 
    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 
     
    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        } 
     
    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": 
     
    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": 
     
    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": 
     
    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                                                } 
     
    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": 
     
    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                                         } 
     1256                                $rv = $config['baseurl'].$query."level=search".$args; 
     1257                                break; 
     1258                        case "collections": 
     1259                        default: 
     1260                                $rv = $config['baseurl']; 
     1261                                if ($query != "?" && empty($args)) { 
     1262                                        if ($query == "?") { $args = substr($args, 5); } 
     1263                                        $rv .= $query.$args; 
    12521264                                } 
    12531265                                break; 
    1254                         case "collections": 
    1255                                 default: 
    1256                                 $query = (isset($config['query_args'])) ? "?".$config['query_args'] : $query = ""; 
    1257                                 $rv = $config['baseurl'].$query; 
    1258                                 break; 
    1259                 } 
    1260         } 
    1261  
    1262         // replace &amp; with & if outputting to email 
     1266                } 
     1267        } 
     1268 
     1269        // replace &amp; with & if formatting plaintext (i.e. outputting to email) 
    12631270        if ($plaintext !== false){ 
    12641271                $rv = str_replace("&amp;","&",$rv); 
     
    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; 
    2006                 } 
    2007  
    2008                 return generate_pagination($p_url, $page, $num_items, $config["thumb_num"]); 
     2002                                $level = "collections"; 
     2003                                $id = 0; 
     2004                                $num_items = plogger_count_collections(); 
     2005                                break; 
     2006                } 
     2007 
     2008                return generate_pagination($level, $id, $page, $num_items, $config['thumb_num']); 
    20092009        } 
    20102010