Changeset 546 for trunk/plog-functions.php
- Timestamp:
- 06/05/08 17:18:12 (6 months ago)
- Files:
-
- 1 modified
-
trunk/plog-functions.php (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plog-functions.php
r538 r546 1075 1075 $result = run_query($query); 1076 1076 $row = mysql_fetch_assoc($result); 1077 $rv = $config["baseurl"].rawurlencode(SmartStripSlashes($row["path"])) ;1077 $rv = $config["baseurl"].rawurlencode(SmartStripSlashes($row["path"]))."/"; 1078 1078 } else if ($level == "album") { 1079 1079 $query = "SELECT … … 1086 1086 $row = mysql_fetch_assoc($result); 1087 1087 1088 $rv = $config["baseurl"].rawurlencode(SmartStripSlashes($row["collection_path"])) . '/' . rawurlencode(SmartStripSlashes($row["album_path"])) ;1088 $rv = $config["baseurl"].rawurlencode(SmartStripSlashes($row["collection_path"])) . '/' . rawurlencode(SmartStripSlashes($row["album_path"]))."/"; 1089 1089 1090 1090 // I need to give additional arguments to the url-s 1091 1091 if (sizeof($arg) > 0) { 1092 1092 foreach($arg as $aval) { 1093 $rv .= "/".$aval;1093 $rv .= $aval."/"; 1094 1094 } 1095 1095 } … … 1097 1097 $pic = get_picture_by_id($id); 1098 1098 $album = $pic["parent_album"]; 1099 $rv = $config["baseurl"].str_replace("%2F", "/", rawurlencode(substr(SmartStripSlashes($pic['path']), 0, -4))) ;1099 $rv = $config["baseurl"].str_replace("%2F", "/", rawurlencode(substr(SmartStripSlashes($pic['path']), 0, -4)))."/"; 1100 1100 } 1101 1101 } else { … … 1322 1322 1323 1323 // determine sort ordering 1324 switch ($_SESSION[ "plogger_sortby"]){1324 switch ($_SESSION['plogger_sortby']){ 1325 1325 case 'number_of_comments': 1326 1326 $sql = "SELECT … … 1343 1343 break; 1344 1344 case 'date': 1345 $sql .= " ORDER BY `date_submitted` "; 1346 break; 1345 1347 default: 1346 $sql .= " ORDER BY ` date_submitted` ";1348 $sql .= " ORDER BY `id` "; 1347 1349 break; 1348 1350 } … … 1357 1359 break; 1358 1360 } 1361 1362 // if sorting by number_of_comments, we sub-sort by 'id' DESC 1363 if ($_SESSION['plogger_sortby']=="number_of_comments"){ 1364 $sql .= ",`p`.`id` DESC"; 1365 } 1359 1366 1360 1367 $result = run_query($sql); … … 1401 1408 1402 1409 function plogger_init_pictures($arr) { 1403 $sql = " 1404 FROM `".TABLE_PREFIX."pictures` `p` 1405 LEFT JOIN `".TABLE_PREFIX."comments` `c` ON `p`.`id`=`c`.`parent_id`"; 1406 1407 $type = $arr['type']; 1410 $sql = " FROM `".TABLE_PREFIX."pictures` AS `p`"; 1411 1412 // if sorting by number_of_comments, we need to join the comments table 1413 if (isset($arr['sortby']) && $arr['sortby']=="number_of_comments"){ 1414 $sql .= " LEFT JOIN `".TABLE_PREFIX."comments` AS `c` ON `p`.`id`=`c`.`parent_id`"; 1415 } 1408 1416 1409 1417 // right now only single id is supported, maybe I want to specify multiple id-s as well 1410 1418 $value = (isset($arr['value']) && $arr['value'] > 0) ? $arr['value'] : -1; 1411 1419 1412 if ('collection' == $type) { 1413 $sql .= " WHERE p.`parent_collection` = ".$value; 1414 } elseif ('id' == $type) { 1415 $sql .= " WHERE p.`id` = ".$value; 1416 } elseif ('album' == $type) { 1417 $sql .= " WHERE p.`parent_album` = ".$value; 1418 } elseif ('latest' == $type) { 1419 // add nothing, only limit takes effect 1420 } else { 1421 // so what do you want anyway? 1422 return 0; 1423 } 1424 1425 $from = 0; 1426 $limit = 20; // Default limit if nothing is set 1427 $max_limit = 1000; // Hard-coded max limit, no matter what you do you cannot 1428 // go beyond this limit for number of pictures in thumbnails, 1429 // slideshow etc. 1430 1431 if (isset($arr["from"]) && $arr["from"] > 0) { 1432 $from = $arr["from"]; 1433 } 1434 1435 // Enforce hard-coded max limit if the provided limit is extreme 1436 if (isset($arr['limit']) && $arr['limit'] > 0 && $arr['limit'] <= $max_limit) { 1437 $limit = $arr['limit']; 1438 } elseif (isset($arr['limit']) && $arr['limit'] == -1) { 1439 $limit = -1; // Set to -1 for slideshow, so limit will not be used 1440 } 1441 1420 switch ($arr['type']) { 1421 case 'collection': 1422 $sql .= " WHERE `p`.`parent_collection` = ".$value; 1423 break; 1424 case 'album': 1425 $sql .= " WHERE `p`.`parent_album` = ".$value; 1426 break; 1427 case 'id': 1428 $sql .= " WHERE `p`.`id` = ".$value; 1429 break; 1430 case 'latest': 1431 break; 1432 default: 1433 return 0; 1434 } 1435 1442 1436 $result = run_query("SELECT COUNT(DISTINCT p.`id`) AS cnt " . $sql); 1443 1437 $row = mysql_fetch_assoc($result); 1444 1438 1445 1439 $GLOBALS["total_pictures"] = $row["cnt"]; 1446 1447 // grouping is needed to get comment count 1448 $sql .= " GROUP BY p.`id`"; 1440 1441 1442 // if sorting by number_of_comments, we need group and count the results 1443 if (isset($arr['sortby']) && $arr['sortby']=="number_of_comments"){ 1444 $sql = ",COUNT(`comment`) AS `num_comments` ".$sql." GROUP BY `p`.`id`"; 1445 } 1446 1449 1447 1450 1448 // query database and retreive all pictures withing selected album … … 1456 1454 'filename' => 'path', 1457 1455 'date' => 'date_submitted', 1458 'id' => 'id' ,1456 'id' => 'id' 1459 1457 ); 1460 1458 … … 1462 1460 $sortby = $arr['sortby']; 1463 1461 } else { 1464 $sortby = 'date'; // Default sort, is to sort by date1462 $sortby = "id"; // Default sort, is to sort by id 1465 1463 } 1466 1464 1467 1465 $sortby = $sort_fields[$sortby]; 1468 $sql .= " ORDER BY `$sortby` "; 1469 1470 if (isset($arr['sortdir']) && (strcasecmp('asc',$arr['sortdir']) === 0)) { 1471 $sortdir = ' ASC'; 1472 } else { 1473 $sortdir = ' DESC'; // Default sort direction is descending 1466 $sql .= " ORDER BY `".$sortby."`"; 1467 1468 // determine sort direction 1469 if (isset($arr['sortdir']) && (strtoupper($arr['sortdir']) == 'ASC')) { 1470 $sortdir = " ASC"; 1471 } else { 1472 $sortdir = " DESC"; // Default sort direction is descending 1474 1473 } 1475 1476 1474 $sql .= $sortdir; 1477 1478 // again, this is needed because of the comment counting 1479 $sql .= ",p.`id` DESC "; 1480 1475 1476 1477 // if sorting by number_of_comments, we sub-sort by 'id' DESC 1478 if (isset($arr['sortby']) && $arr['sortby']=="number_of_comments"){ 1479 $sql .= ",`p`.`id` DESC"; 1480 } 1481 1482 1483 // set up limits, if needed 1484 $from = 0; 1485 $limit = 20; // Default limit if nothing is set 1486 $max_limit = 1000; // Hard-coded max limit, no matter what you do you cannot 1487 // go beyond this limit for number of pictures in thumbnails, 1488 // slideshow etc. 1489 1490 if (isset($arr['from']) && $arr['from'] > 0) { 1491 $from = $arr['from']; 1492 } 1493 1494 // Enforce hard-coded max limit if the provided limit is extreme 1495 if (isset($arr['limit']) && $arr['limit'] > 0 && $arr['limit'] <= $max_limit) { 1496 $limit = $arr['limit']; 1497 } elseif (isset($arr['limit']) && $arr['limit'] == -1) { 1498 $limit = -1; // Set to -1 for slideshow, so limit will not be used 1499 } 1500 1481 1501 if (($from >= 0) && ($limit >= 0)) $sql .= " LIMIT ".$from.",".$limit; 1502 1482 1503 1483 1504 $result = run_query("SELECT p.*, 1484 1505 UNIX_TIMESTAMP(`date_submitted`) AS `unix_date_submitted`, 1485 UNIX_TIMESTAMP(`EXIF_date_taken`) AS `unix_exif_date_taken`, 1486 COUNT(`comment`) AS `num_comments` " . $sql); 1506 UNIX_TIMESTAMP(`EXIF_date_taken`) AS `unix_exif_date_taken` " . $sql); 1487 1507 1488 1508 $GLOBALS["available_pictures"] = mysql_num_rows($result); … … 1498 1518 1499 1519 function plogger_init_search($arr) { 1520 global $PLOGGER_DBH; 1500 1521 $terms = explode(" ",$arr['searchterms']); 1501 1522 $from = 0; … … 1517 1538 $query .= " WHERE ( "; 1518 1539 foreach ($terms as $term) { 1540 $term = mysql_real_escape_string($term); 1541 $multi_term = explode("+",$term); 1542 if (count($multi_term)>1) { 1543 $path = implode("%' AND `path` LIKE '%",$multi_term); 1544 $description = implode("%' AND `description` LIKE '%",$multi_term); 1545 $comment = implode("%' AND `comment` LIKE '%",$multi_term); 1546 $caption = implode("%' AND `caption` LIKE '%",$multi_term); 1547 } else { 1548 $path = $description = $comment = $caption = $term; 1549 } 1519 1550 $query .= " 1520 `path` LIKE '% ".mysql_real_escape_string($term)."%' OR1521 `description` LIKE '% ".mysql_real_escape_string($term)."%' OR1522 `comment` LIKE '% ".mysql_real_escape_string($term)."%' OR1523 `caption` LIKE '% ".mysql_real_escape_string($term)."%' OR ";1551 `path` LIKE '%$path%' OR 1552 `description` LIKE '%$description%' OR 1553 `comment` LIKE '%$comment%' OR 1554 `caption` LIKE '%$caption%' OR "; 1524 1555 } 1525 1556 … … 1735 1766 global $path; 1736 1767 if (isset($path)) 1737 $rss_link .= "http://".$_SERVER["SERVER_NAME"]."/".SmartStripSlashes(substr($path,1))." /feed/";1768 $rss_link .= "http://".$_SERVER["SERVER_NAME"]."/".SmartStripSlashes(substr($path,1))."feed/"; 1738 1769 else 1739 1770 $rss_link .= $config['gallery_url']."feed/"; … … 2192 2223 2193 2224 function plogger_collection_album_count() { 2194 if (isset($GLOBALS['album_count']) && isset($GLOBALS['current_collection']['id']) ) {2225 if (isset($GLOBALS['album_count']) && isset($GLOBALS['current_collection']['id']) && isset($GLOBALS['album_count'][$GLOBALS['current_collection']['id']])) { 2195 2226 return $GLOBALS['album_count'][$GLOBALS['current_collection']['id']]; 2196 2227 } else { … … 2261 2292 if (isset($GLOBALS['current_album'])) { 2262 2293 $row = $GLOBALS['current_album']; 2263 // XXX: surely this can be optimized?2264 $numquery = "SELECT COUNT(*) AS `num_pictures` FROM `".TABLE_PREFIX."pictures` WHERE `parent_album`='".$row['id']."'";2294 // XXX: this may be faster? 2295 $numquery = "SELECT COUNT(DISTINCT `id`) AS `num_pictures` FROM `".TABLE_PREFIX."pictures` WHERE `parent_album`='".$row['id']."'"; 2265 2296 $numresult = run_query($numquery); 2266 2297 return mysql_result($numresult, 'num_pictures');
