Changeset 563 for trunk/plog-includes/plog-functions.php
- Timestamp:
- 07/21/08 19:18:07 (20 months ago)
- Files:
-
- 1 modified
-
trunk/plog-includes/plog-functions.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plog-includes/plog-functions.php
r562 r563 1025 1025 } 1026 1026 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 } 1028 1032 $sql = "SELECT * 1029 1033 FROM `".TABLE_PREFIX."collections` 1030 WHERE `path`='".$names[ "collection"]."'";1034 WHERE `path`='".$names['collection']."'"; 1031 1035 $result = run_query($sql); 1032 1036 … … 1040 1044 // what if there are multiple collections with same names? I hope there aren't .. this would 1041 1045 // 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']); 1043 1047 } 1044 1048 1045 1049 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 } 1046 1054 $sql = "SELECT * 1047 1055 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']); 1050 1058 $result = run_query($sql); 1051 1059 … … 1078 1086 } 1079 1087 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 } 1081 1093 $sql = "SELECT * 1082 1094 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']); 1085 1097 $result = run_query($sql); 1086 1098 … … 1106 1118 } 1107 1119 1108 $rv = array("level" => "picture", "id" => $picture[ "id"]);1120 $rv = array("level" => "picture", "id" => $picture['id']); 1109 1121 } 1110 1122 … … 1112 1124 } 1113 1125 1114 function generate_pagination($ url, $current_page, $items_total, $items_on_page, $extra_params = ''){1126 function generate_pagination($level, $id, $current_page, $items_total, $items_on_page, $args = array(1 => "page")){ 1115 1127 $output = ''; 1116 1128 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']; 1121 1133 } 1122 1134 1123 1135 $num_pages = ceil($items_total / $items_on_page); 1124 1125 // if adding arguments to mod_rewritten urls, then I need ? (question mark) before the arguments1126 // otherwise I want &1127 //$last = substr($url,-1);1128 1129 if (!strpos($url,"?")) {1130 $separator = "?";1131 } else {1132 $separator = "&";1133 }1134 1136 1135 1137 if ($num_pages > 1){ 1136 1138 if ($current_page > 1){ 1137 $output .= ' <a accesskey="," class="pagPrev" href="'.$url.$separator.'plog_page='.($current_page - 1).$extra_params.'"><span>«</span></a> '; 1139 $args['plog_page'] = $current_page - 1; 1140 $output .= ' <a accesskey="," class="pagPrev" href="'.generate_url($level, $id, $args).'"><span>«</span></a> '; 1138 1141 } 1139 1142 … … 1142 1145 $output .= '<span class="page_link"> ['.$i.'] </span>'; 1143 1146 } 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> '; 1145 1149 } 1146 1150 } 1147 1151 1148 1152 if ($current_page != $num_pages){ 1149 $output .= ' <a accesskey="." class="pagNext" href="'.$url.$separator.'plog_page='.($current_page + 1).$extra_params.'"><span>»</span></a> '; 1153 $args['plog_page'] = $current_page + 1; 1154 $output .= ' <a accesskey="." class="pagNext" href="'.generate_url($level, $id, $args).'"><span>»</span></a> '; 1150 1155 } 1151 1156 } … … 1167 1172 1168 1173 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 1169 1182 switch($level){ 1170 1183 case "collection": … … 1172 1185 $result = run_query($query); 1173 1186 $row = mysql_fetch_assoc($result); 1174 $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['path']))."/" ;1187 $rv = $config['baseurl'].rawurlencode(SmartStripSlashes($row['path']))."/".$args; 1175 1188 break; 1176 1189 case "album": … … 1183 1196 $result = run_query($query); 1184 1197 $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; 1194 1199 break; 1195 1200 case "picture": … … 1204 1209 foreach($arg as $akey => $aval) { 1205 1210 // mod_rewrite url-s need /sorted in them, the old style ones do not. 1206 // this temporary workaround removes the 'sorted' string1207 if ( $aval != 'sorted') {1211 // this temporary workaround removes the 'sorted' and 'plog_page' strings 1212 if (!is_numeric($akey)) { 1208 1213 $rv .= "&".$akey."=".$aval; 1209 1214 } … … 1212 1217 break; 1213 1218 case "collections": 1214 default:1215 $rv = $config['baseurl'] ;1219 default: 1220 $rv = $config['baseurl'].$args; 1216 1221 break; 1217 1222 } 1218 1223 } else { 1219 1224 // if there are non-Plogger query items, get them here to prepend to the URL query string 1220 $query = (isset($config['query_args'])) ? "?".$config['query_args']."&" : $query = "?"; 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']."&" : "?"; 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 .= "&".$akey."=".$aval; 1236 } 1237 } 1238 } 1221 1239 1222 1240 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 1223 1246 case "collection": 1224 return $config['baseurl'].$query.'level=collection&id='.$id;1247 $rv = $config['baseurl'].$query.'level=collection&id='.$id.$args; 1225 1248 break; 1226 1249 case "album": 1227 $rv = $config['baseurl'].$query.'level=album&id='.$id; 1228 if (sizeof($arg) > 0) { 1229 foreach($arg as $akey => $aval) { 1230 // mod_rewrite url-s need /sorted in them, the old style ones do not. 1231 // this temporary workaround removes the 'sorted' string 1232 if ($aval != 'sorted') { 1233 $rv .= "&".$akey."=".$aval; 1234 } 1235 } 1236 } 1250 $rv = $config['baseurl'].$query.'level=album&id='.$id.$args; 1237 1251 break; 1238 1252 case "picture": … … 1240 1254 break; 1241 1255 case "search": 1242 $rv = $config['baseurl'].$query."level=search"; 1243 // I need to give additional arguments to the url-s 1244 if (sizeof($arg) > 0) { 1245 foreach($arg as $akey => $aval) { 1246 // mod_rewrite url-s need /sorted in them, the old style ones do not. 1247 // this temporary workaround removes the 'sorted' string 1248 if ($aval != 'sorted') { 1249 $rv .= "&".$akey."=".$aval; 1250 } 1251 } 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; 1252 1264 } 1253 1265 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 & with & if outputting to email 1266 } 1267 } 1268 1269 // replace & with & if formatting plaintext (i.e. outputting to email) 1263 1270 if ($plaintext !== false){ 1264 1271 $rv = str_replace("&","&",$rv); … … 1975 1982 1976 1983 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) { 1991 1988 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; 1994 1992 1995 1993 case 'album': 1996 1994 $num_items = plogger_album_picture_count(); 1997 break;1995 break; 1998 1996 1999 1997 case 'collection': 2000 1998 $num_items = plogger_collection_album_count(); 2001 break;1999 break; 2002 2000 2003 2001 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']); 2009 2009 } 2010 2010
