Show
Ignore:
Timestamp:
06/05/08 17:18:12 (6 months ago)
Author:
sidtheduck
Message:

+ Lots of sorting fixes

  • Now sorting is the same throughout . defaults from Admin->Options are used on both Admin->Manage and front-end gallery . plogger_init_picture order = plogger_init_pictures order . sorting fixes from Import display to actually saving the files

+ Additional check for safe_mode workaround to see if ftp_connect function exists in compiled PHP installation before attempting the workaround

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/plog-functions.php

    r538 r546  
    10751075                        $result = run_query($query); 
    10761076                        $row = mysql_fetch_assoc($result); 
    1077                         $rv = $config["baseurl"].rawurlencode(SmartStripSlashes($row["path"])); 
     1077                        $rv = $config["baseurl"].rawurlencode(SmartStripSlashes($row["path"]))."/"; 
    10781078                } else if ($level == "album") { 
    10791079                        $query = "SELECT 
     
    10861086                        $row = mysql_fetch_assoc($result); 
    10871087                         
    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"]))."/"; 
    10891089                         
    10901090                        // I need to give additional arguments to the url-s 
    10911091                        if (sizeof($arg) > 0) { 
    10921092                                foreach($arg as $aval) { 
    1093                                         $rv .= "/".$aval; 
     1093                                        $rv .= $aval."/"; 
    10941094                                } 
    10951095                        } 
     
    10971097                        $pic = get_picture_by_id($id); 
    10981098                        $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)))."/"; 
    11001100                } 
    11011101        } else { 
     
    13221322         
    13231323        // determine sort ordering 
    1324         switch ($_SESSION["plogger_sortby"]){ 
     1324        switch ($_SESSION['plogger_sortby']){ 
    13251325                case 'number_of_comments': 
    13261326                        $sql = "SELECT 
     
    13431343                        break; 
    13441344                case 'date': 
     1345                        $sql .= " ORDER BY `date_submitted` "; 
     1346                        break; 
    13451347                default: 
    1346                         $sql .= " ORDER BY `date_submitted` "; 
     1348                        $sql .= " ORDER BY `id` "; 
    13471349                        break; 
    13481350        } 
     
    13571359                        break; 
    13581360        } 
     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        } 
    13591366         
    13601367        $result = run_query($sql); 
     
    14011408 
    14021409function 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        } 
    14081416         
    14091417        // right now only single id is supported, maybe I want to specify multiple id-s as well 
    14101418        $value = (isset($arr['value']) && $arr['value'] > 0) ? $arr['value'] : -1; 
    14111419         
    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         
    14421436        $result = run_query("SELECT COUNT(DISTINCT p.`id`) AS cnt " . $sql); 
    14431437        $row = mysql_fetch_assoc($result); 
    1444          
     1438 
    14451439        $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 
    14491447         
    14501448        // query database and retreive all pictures withing selected album 
     
    14561454                'filename' => 'path', 
    14571455                'date' => 'date_submitted', 
    1458                 'id' => 'id', 
     1456                'id' => 'id' 
    14591457        ); 
    14601458         
     
    14621460                $sortby = $arr['sortby']; 
    14631461        } else { 
    1464         $sortby = 'date';      // Default sort, is to sort by date 
     1462        $sortby = "id";      // Default sort, is to sort by id 
    14651463  } 
    14661464         
    14671465        $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 
    14741473  } 
    1475          
    14761474        $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   
    14811501        if (($from >= 0) && ($limit >= 0)) $sql .= " LIMIT ".$from.",".$limit; 
     1502 
    14821503         
    14831504        $result = run_query("SELECT p.*, 
    14841505                        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); 
    14871507         
    14881508        $GLOBALS["available_pictures"] = mysql_num_rows($result); 
     
    14981518 
    14991519function plogger_init_search($arr) { 
     1520        global $PLOGGER_DBH; 
    15001521        $terms = explode(" ",$arr['searchterms']); 
    15011522        $from = 0; 
     
    15171538                $query .= " WHERE ( "; 
    15181539                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      } 
    15191550                        $query .= " 
    1520                                 `path` LIKE '%".mysql_real_escape_string($term)."%' OR 
    1521                                 `description` LIKE '%".mysql_real_escape_string($term)."%' OR 
    1522                                 `comment` LIKE '%".mysql_real_escape_string($term)."%' OR 
    1523                                 `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 "; 
    15241555                } 
    15251556                 
     
    17351766                global $path; 
    17361767                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/"; 
    17381769                else 
    17391770                        $rss_link .= $config['gallery_url']."feed/"; 
     
    21922223 
    21932224function 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']])) { 
    21952226                return $GLOBALS['album_count'][$GLOBALS['current_collection']['id']]; 
    21962227        } else { 
     
    22612292        if (isset($GLOBALS['current_album'])) { 
    22622293                $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']."'"; 
    22652296                $numresult = run_query($numquery); 
    22662297                return mysql_result($numresult, 'num_pictures');