Changeset 546

Show
Ignore:
Timestamp:
06/05/08 17:18:12 (3 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

Location:
trunk
Files:
20 modified

Legend:

Unmodified
Added
Removed
  • trunk/_install.php

    r533 r546  
    11<?php 
    2 error_reporting(E_ALL); 
     2error_reporting(E_ERROR); 
    33require(dirname(__FILE__) . '/plog-globals.php'); 
    44require(PLOGGER_DIR . 'plog-functions.php'); 
  • trunk/admin/index.php

    r536 r546  
    11<?php 
    2 require_once("../plog-functions.php"); 
    3 require_once("../plog-globals.php"); 
     2// load configuration variables from database, plog-globals, & plog-functions 
     3require_once(dirname(dirname(__FILE__))."/plog-load_config.php"); 
     4 
    45 
    56$output = ''; 
  • trunk/admin/plog-admin-functions.php

    r538 r546  
    2929       // Finish off the function 
    3030       closedir($dir); 
     31                         sort($tmp); 
    3132       return $tmp; 
    3233   } 
     
    3536function add_picture($album_id,$tmpname,$filename,$caption,$desc) { 
    3637        global $config; 
    37  
    3838         
    3939        $filename_parts = explode(".",strrev($filename),2); 
     
    881881function makeDirs($strPath, $mode = 0777) //creates directory tree recursively 
    882882{ 
    883    if (ini_get('safe_mode')==1){ 
     883   if (ini_get('safe_mode') && function_exists('ftp_connect')){ 
    884884      return is_dir($strPath) or ( makeDirs(dirname($strPath), $mode) and FTP_makeDirs($strPath) ); 
    885885   }else{ 
     
    11701170 
    11711171function plog_picture_manager($id,$from,$limit) { 
    1172         $output = ''; 
     1172  global $config; 
     1173  $output = ''; 
    11731174 
    11741175        plogger_init_pictures(array( 
     
    11771178                        'from' => $from, 
    11781179                        'limit' => $limit, 
     1180                        'sortby' => !empty($config['default_sortby']) ? $config['default_sortby'] : 'id', 
     1181                        'sortdir' => !empty($config['default_sortdir']) ? $config['default_sortdir'] : 'ASC' 
    11791182        )); 
    11801183 
     
    11991202                        'from' => $from, 
    12001203                        'limit' => $limit, 
     1204                        'sortby' => !empty($config['default_sortby']) ? $config['default_sortby'] : 'id', 
     1205                        'sortdir' => !empty($config['default_sortdir']) ? $config['default_sortdir'] : 'ASC' 
    12011206        )); 
    12021207         
     
    12671272 
    12681273function plog_album_manager($id,$from,$limit) { 
     1274  global $config; 
    12691275        $output = ''; 
    12701276         
     
    12741280                'limit' => $limit, 
    12751281                'all_albums' => 1, 
    1276                 'sortby' => 'id', 
    1277                 'sortdir' => 'asc' 
     1282    'sortby' => !empty($config['album_sortby']) ? $config['album_sortby'] : 'id', 
     1283                'sortdir' => !empty($config['album_sortdir']) ? $config['album_sortdir'] : 'ASC' 
    12781284        )); 
    12791285         
     
    12981304                'limit' => $limit, 
    12991305                'all_albums' => 1, 
    1300                 'sortby' => 'id', 
    1301                 'sortdir' => 'asc' 
     1306    'sortby' => !empty($config['album_sortby']) ? $config['album_sortby'] : 'id', 
     1307                'sortdir' => !empty($config['album_sortdir']) ? $config['album_sortdir'] : 'ASC' 
    13021308        )); 
    13031309         
     
    13441350 
    13451351function plog_collection_manager($from,$limit) { 
    1346         $output = ''; 
     1352  global $config; 
     1353  $output = ''; 
    13471354 
    13481355        plogger_init_collections(array( 
     
    13501357                'limit' => $limit, 
    13511358                'all_collections' => 1, 
    1352                 'sortby' => 'id', 
    1353                 'sortdir' => 'asc' 
     1359    'sortby' => !empty($config['collection_sortby']) ? $config['collection_sortby'] : 'id', 
     1360                'sortdir' => !empty($config['collection_sortdir']) ? $config['collection_sortdir'] : 'ASC' 
    13541361        )); 
    13551362         
     
    13731380                'limit' => $limit, 
    13741381                'all_collections' => 1, 
    1375                 'sortby' => 'id', 
    1376                 'sortdir' => 'asc' 
     1382    'sortby' => !empty($config['collection_sortby']) ? $config['collection_sortby'] : 'id', 
     1383                'sortdir' => !empty($config['collection_sortdir']) ? $config['collection_sortdir'] : 'ASC' 
    13771384        )); 
    13781385 
  • trunk/admin/plog-admin.php

    r536 r546  
    55//session_register ("entries_per_page"); 
    66 
    7 require_once("../plog-load_config.php");                                        // load configuration variables from database 
    8 //require_once("../plog-functions.php"); 
    9 //require_once("../plog-globals.php"); 
     7// load configuration variables from database, plog-globals, & plog-functions 
     8require_once(dirname(dirname(__FILE__))."/plog-load_config.php"); 
     9 
    1010 
    1111if (isset($_REQUEST['action']) && $_REQUEST["action"] == "log_in"){ 
    1212        // TODO: leiuta generic login funktsioon 
    1313 
    14         if (($_REQUEST["plog-username"] == $config["admin_username"]) && (md5($_REQUEST["plog-password"]) == $config["admin_password"])){ 
     14        if ( (isset($_REQUEST["plog-username"]) && $_REQUEST["plog-username"] == $config["admin_username"]) && (isset($_REQUEST["plog-password"]) && md5($_REQUEST["plog-password"]) == $config["admin_password"]) ){ 
    1515                $_SESSION["plogger_logged_in"] = true; 
    16         } 
    17         else{ 
     16        }       else { 
    1817                header("Location: index.php?errorcode=1"); 
    1918                exit; 
    2019        } 
    21 } 
    22 elseif(isset($_REQUEST['action']) && $_REQUEST["action"] == "log_out"){ 
     20} elseif(isset($_REQUEST['action']) && $_REQUEST["action"] == "log_out") { 
    2321        $_SESSION = array(); 
    2422        session_destroy(); 
  • trunk/admin/plog-feedback.php

    r536 r546  
    11<?php 
    2  
     2// load configuration variables from database, plog-globals, & plog-functions 
     3require_once(dirname(dirname(__FILE__))."/plog-load_config.php"); 
    34require("plog-admin.php"); 
    4 require_once("../plog-load_config.php"); 
    5 require_once("../plog-functions.php"); 
    65require_once("plog-admin-functions.php"); 
     6 
    77 
    88global $inHead; 
  • trunk/admin/plog-import.php

    r539 r546  
    238238                $queue_func = ""; 
    239239                $keys = array(); 
     240                sort($files); 
    240241            for($i=0; $i<count($files); $i++) {   
    241242                $file_key = md5($files[$i]); 
  • trunk/admin/plog-manage.php

    r536 r546  
    11<?php 
     2// load configuration variables from database, plog-globals, & plog-functions 
     3require_once(dirname(dirname(__FILE__))."/plog-load_config.php"); 
    24require("plog-admin.php"); 
    3 // load configuration variables from database 
    4 require_once("../plog-load_config.php");                                         
    55require_once("plog-admin-functions.php"); 
     6 
    67 
    78global $inHead; 
  • trunk/admin/plog-options.php

    r536 r546  
    11<?php 
     2// load configuration variables from database, plog-globals, & plog-functions 
     3require_once(dirname(dirname(__FILE__))."/plog-load_config.php"); 
    24require("plog-admin.php"); 
    3 require_once("../plog-load_config.php"); 
    45require_once("plog-admin-functions.php"); 
     6 
    57 
    68$output = ''; 
  • trunk/admin/plog-rpc.php

    r425 r546  
    11<?php 
    2 require_once("plog-admin.php"); 
    3 require_once("../plog-load_config.php"); 
     2// load configuration variables from database, plog-globals, & plog-functions 
     3require_once(dirname(dirname(__FILE__))."/plog-load_config.php"); 
     4require("plog-admin.php"); 
    45require_once("plog-admin-functions.php"); 
     6 
    57 
    68$action_result = array(); 
  • trunk/admin/plog-themes.php

    r536 r546  
    11<?php 
    2  
     2// load configuration variables from database, plog-globals, & plog-functions 
     3require_once(dirname(dirname(__FILE__))."/plog-load_config.php"); 
    34require("plog-admin.php"); 
    4 require_once("../plog-load_config.php");                                        // load configuration variables from database 
    55require_once("plog-admin-functions.php"); 
    66 
  • trunk/admin/plog-thumb.php

    r539 r546  
    77} 
    88 
    9 require_once("../plog-functions.php"); 
    10 require_once("../plog-globals.php"); 
    11 require_once("../plog-load_config.php"); 
     9// load configuration variables from database, plog-globals, & plog-functions 
     10require_once(dirname(dirname(__FILE__))."/plog-load_config.php"); 
    1211require_once("plog-admin-functions.php"); 
    1312 
    1413 
    1514$files = get_files($config['basedir'] . "uploads"); 
    16  
    1715 
    1816 
  • trunk/admin/plog-thumbpopup.php

    r297 r546  
     1<?php 
     2// load configuration variables from database, plog-globals, & plog-functions 
     3require_once(dirname(dirname(__FILE__))."/plog-load_config.php"); 
     4require("plog-admin.php"); 
     5require_once("plog-admin-functions.php"); 
    16 
    2 <?php 
    3 require_once("plog-admin.php"); 
    4 require_once("../plog-load_config.php");                                        // load configuration variables from database 
    5 require_once("../plog-functions.php"); 
     7 
    68// this script will just show a small preview of the thumbnail in admin view if 
    79// you can't differentiate the small pics. 
  • trunk/admin/plog-upload.php

    r536 r546  
    55// The initial tab is UPLOAD function. 
    66 
    7 require_once("../plog-load_config.php"); 
     7require_once(dirname(dirname(__FILE__))."/plog-load_config.php"); 
    88require("plog-admin.php"); 
    99include("plog-admin-functions.php"); 
  • trunk/gallery.php

    r538 r546  
    11<?php 
    22#error_reporting(E_ALL); 
    3 include_once("plog-load_config.php"); 
     3include_once(dirname(__FILE__)."/plog-load_config.php"); 
    44//include("plog-globals.php"); 
    55//include_once("plog-functions.php"); 
  • trunk/lib/plogger/form_setup.php

    r543 r546  
    5151   <?php 
    5252   //if server is safe_mode enabled, prompt user for FTP info for FTP workaround 
    53    if (ini_get('safe_mode')==1){?> 
     53   if (ini_get('safe_mode') && function_exists('ftp_connect')){?> 
    5454   <tr> 
    5555        <td colspan="2"> 
    5656                <div id="navcontainer"> 
    5757                        <h1>Safe_mode FTP workaround</h1> 
    58          <br/>Safe mode has been detected on your server.  FTP access is needed to allow Plogger to work correctly with safe_mode=on. 
     58         <br />Safe mode has been detected on your server.  FTP access is needed to allow Plogger to work correctly with safe_mode enabled. 
    5959      </div> 
    6060                </td> 
  • trunk/lib/plogger/form_setup_complete.php

    r543 r546  
    1212<?php } ?> 
    1313<p> 
    14 <input type="submit" name="proceed" value="Install"/> 
     14<input type="submit" name="proceed" id="proceed" value="Install"/> 
    1515</p> 
    1616</form> 
  • trunk/lib/plogger/install_functions.php

    r542 r546  
    5656                } 
    5757       
    58                 if (ini_get('safe_mode')==1) { 
     58                if (ini_get('safe_mode') && function_exists('ftp_connect')) { 
    5959                        //if safe_mode enabled, check the FTP information form inputs 
    6060                        if (empty($form['ftp_host'])) { 
     
    8282                if (empty($errors)) { 
    8383                        $mysql_errors = check_mysql($form['db_host'],$form['db_user'],$form['db_pass'],$form['db_name']); 
    84                         if (ini_get('safe_mode')==1) { 
     84                        if (ini_get('safe_mode') && function_exists('ftp_connect')) { 
    8585                                $ftp_errors = check_FTP($form['ftp_host'], $form['ftp_user'], $form['ftp_pass'], $form['ftp_path']); 
    8686                        }else{ 
     
    104104                        ); 
    105105                                 
    106                         if (ini_get('safe_mode')==1) { 
     106                        if (ini_get('safe_mode') && function_exists('ftp_connect')) { 
    107107                                $conf = create_config_file($form['db_host'],$form['db_user'],$form['db_pass'],$form['db_name'],$form['ftp_host'],$form['ftp_user'],$form['ftp_pass'],$form['ftp_path']); 
    108108                        } else { 
     
    366366        $cfg_file .= '// define("PLOGGER_EMBEDDED","");        // 1/0 (True/False) if set will overrule automatic check'."\n"; 
    367367        $cfg_file .= '// define("PLOGGER_LOCALE","");         // da_DK de et fr pl ro_RO tr ...etc.'."\n"; 
    368         if (ini_get('safe_mode')==1 && !empty($ftp_host)) { 
     368        if (ini_get('safe_mode') && function_exists('ftp_connect') && !empty($ftp_host)) { 
    369369        //if safe_mode enabled, write the FTP workaround information to plog-config.php with db information 
    370370                $cfg_file .= "\n"; 
  • 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;