Changeset 562

Show
Ignore:
Timestamp:
07/18/08 17:44:34 (5 weeks ago)
Author:
sidtheduck
Message:

+ Fixed weird formatting indentations in some of plog-functions.php

Files:
1 modified

Legend:

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

    r561 r562  
    2828                        //if ($GLOBALS['plogger_mode'] == "slideshow") $breadcrumbs .= $sep . '<strong>' . plog_tr('Slideshow'); 
    2929 
    30                 break; 
     30                        break; 
    3131                case 'slideshow': 
    3232                case 'album': 
     
    5050                        } 
    5151 
    52                 break; 
     52                        break; 
    5353                case 'picture': 
    5454                        $row = get_picture_by_id($id); 
     
    7272                        //if ($GLOBALS['plogger_mode'] == "slideshow") $breadcrumbs .= $sep . '<strong>' . plog_tr('Slideshow'); 
    7373 
    74                 break; 
     74                        break; 
    7575                case 'search': 
    7676                        if ($config['truncate_breadcrumb'] == "album"){ 
     
    8585                                $breadcrumbs = $collections_link . $sep . '<strong>'.plog_tr('Search').'</strong>' . $sep . plog_tr('You searched for') . ' <strong>'.htmlspecialchars(SmartStripSlashes($_GET['searchterms'])).'</strong>.'; 
    8686                        } 
    87                 break; 
     87                        break; 
    8888                default: 
    89                 $breadcrumbs = $collections_name; 
    90                 break; 
     89                        $breadcrumbs = $collections_name; 
     90                        break; 
    9191        } 
    9292 
     
    102102                        if ($GLOBALS['plogger_mode'] == "slideshow") $breadcrumbs .= ' &raquo; ' . plog_tr('Slideshow'); 
    103103 
    104                 break; 
     104                        break; 
    105105                case 'slideshow': 
    106106                case 'album': 
     
    116116                        } 
    117117 
    118                 break; 
     118                        break; 
    119119                case 'picture': 
    120120                        $row = get_picture_by_id($GLOBALS['plogger_id']); 
     
    132132                        if ($GLOBALS['plogger_mode'] == "slideshow") $breadcrumbs .= ' &raquo; ' . plog_tr('Slideshow'); 
    133133 
    134                 break; 
     134                        break; 
    135135                default: 
    136                 $breadcrumbs = ' ' . plog_tr('Collections'); 
     136                        $breadcrumbs = ' ' . plog_tr('Collections'); 
    137137        } 
    138138 
     
    349349                        $output .= "\n\t\t\t\t\t\t\t\t<option value=\"$value\""; 
    350350                        if(strcasecmp($_SESSION["plogger_sortdir"], $okey) === 0) { 
    351                                         $output .= ' selected="selected"'; 
    352                                 } 
    353                                 $output .= ">$oval</option>"; 
     351                                $output .= ' selected="selected"'; 
    354352                        } 
    355                         $output .= "\n\t\t\t\t\t\t\t</select>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</form><!-- /sort asc/desc -->\n\t\t\t\t"; 
    356                 } 
    357                 return $output; 
    358         } 
    359  
    360         function generate_search_box() { 
    361                 global $config; 
    362  
    363                 $output = '<form action="'.generate_url("collections").'" method="get"> 
    364                                         <div id="search_box"> 
    365                                                 <input type="hidden" name="level" value="search" /> 
    366                                                 <input type="text" name="searchterms" /> 
    367                                                 <input class="submit" type="submit" value="' . plog_tr('Search') .'" /> 
    368                                         </div>'; 
    369                 if (!empty($config['query_args'])){ 
    370                         $query = array(); 
    371                         $query_args = explode("&amp;", $config['query_args']); 
    372                         foreach ($query_args as $value) { 
    373                                 $query = explode("=", $value); 
    374                                 $output .= "\n\t\t\t\t\t\t" . '<input type="hidden" name="'.$query[0].'" value="'.$query[1].'" />'; 
     353                        $output .= ">$oval</option>"; 
     354                } 
     355                $output .= "\n\t\t\t\t\t\t\t</select>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</form><!-- /sort asc/desc -->\n\t\t\t\t"; 
     356        } 
     357        return $output; 
     358} 
     359 
     360function generate_search_box() { 
     361        global $config; 
     362 
     363        $output = '<form action="'.generate_url("collections").'" method="get"> 
     364                                <div id="search_box"> 
     365                                        <input type="hidden" name="level" value="search" /> 
     366                                        <input type="text" name="searchterms" /> 
     367                                        <input class="submit" type="submit" value="' . plog_tr('Search') .'" /> 
     368                                </div>'; 
     369        if (!empty($config['query_args'])){ 
     370                $query = array(); 
     371                $query_args = explode("&amp;", $config['query_args']); 
     372                foreach ($query_args as $value) { 
     373                        $query = explode("=", $value); 
     374                        $output .= "\n\t\t\t\t\t\t" . '<input type="hidden" name="'.$query[0].'" value="'.$query[1].'" />'; 
     375                } 
     376        } 
     377        $output .= "\n\t\t\t\t" . '</form>' . "\n"; 
     378 
     379        return $output; 
     380} 
     381 
     382// benchmark timing 
     383function getmicrotime($t) { 
     384        list($usec, $sec) = explode(" ",$t); 
     385        return ((float)$usec + (float)$sec); 
     386} 
     387 
     388// function for generating the slideshow javascript 
     389function generate_slideshow_js($id, $mode) { 
     390        global $config; 
     391 
     392        // output the link to the slideshow javascript 
     393        $output = "\n\t" . '<script type="text/javascript" src="'.$config['gallery_url'].'plog-includes/js/plog-slideshow.js"></script>'; 
     394        return $output; 
     395} 
     396 
     397function preload_album_images() { 
     398        global $thumbnail_config; 
     399        $script = "\n\t\t<script type=\"text/javascript\" language=\"javascript\"> 
     400        <!-- 
     401        function preload_images() { 
     402                if (document.images) 
     403                { 
     404                        preload_image_object = new Image(); 
     405                        // set image url 
     406                        image_url = new Array();"; 
     407                        $pic_array = get_picture_by_id($GLOBALS["image_list"]); 
     408                        $i = 0; 
     409                        foreach($pic_array as $pic) { 
     410                                unset($path); 
     411                                $url = generate_thumb($pic['path'],$pic['id'],THUMB_LARGE); 
     412                                $script .= "\t\timage_url[$i] = '$url'\n"; 
     413                                $i++; 
    375414                        } 
    376                 } 
    377                 $output .= "\n\t\t\t\t" . '</form>' . "\n"; 
    378  
    379                 return $output; 
    380         } 
    381  
    382         // benchmark timing 
    383         function getmicrotime($t) { 
    384                 list($usec, $sec) = explode(" ",$t); 
    385                 return ((float)$usec + (float)$sec); 
    386         } 
    387  
    388         // function for generating the slideshow javascript 
    389         function generate_slideshow_js($id, $mode) { 
    390                 global $config; 
    391  
    392                 // output the link to the slideshow javascript 
    393                 $output = "\n\t" . '<script type="text/javascript" src="'.$config['gallery_url'].'plog-includes/js/plog-slideshow.js"></script>'; 
    394                 return $output; 
    395         } 
    396  
    397         function preload_album_images() { 
    398                 global $thumbnail_config; 
    399                 $script = "\n\t\t<script type=\"text/javascript\" language=\"javascript\"> 
    400                 <!-- 
    401                 function preload_images() { 
    402                         if (document.images) 
    403                         { 
    404                                 preload_image_object = new Image(); 
    405                                 // set image url 
    406                                 image_url = new Array();"; 
    407                                 $pic_array = get_picture_by_id($GLOBALS["image_list"]); 
    408                                 $i = 0; 
    409                                 foreach($pic_array as $pic) { 
    410                                         unset($path); 
    411                                         $url = generate_thumb($pic['path'],$pic['id'],THUMB_LARGE); 
    412                                         $script .= "\t\timage_url[$i] = '$url'\n"; 
    413                                         $i++; 
    414                                 } 
    415                                 $script .= "var i = 0; 
    416                                 for(i=0; i<image_url.length; i++) 
    417                                 preload_image_object.src = image_url[i]; 
    418                         } 
    419                 } 
    420                 //--> 
    421                 </script>"; 
    422                 return $script; 
    423         } 
     415                        $script .= "var i = 0; 
     416                        for(i=0; i<image_url.length; i++) 
     417                        preload_image_object.src = image_url[i]; 
     418                } 
     419        } 
     420        //--> 
     421        </script>"; 
     422        return $script; 
     423} 
    424424 
    425425        // function for generating the slideshow interface 
     
    459459} 
    460460 
    461         function get_head_title() { 
    462                 global $config; 
    463  
    464                 $title = generate_title($GLOBALS['plogger_level'], $GLOBALS['plogger_id']); 
    465                 return (SmartStripSlashes($config['gallery_name']) . ": ". $title); 
    466         } 
    467  
    468         function plogger_head() { 
    469                 global $config; 
    470  
    471                 if ($config["embedded"] == 0) { 
    472                 print "\t<title>" . get_head_title() . "</title>"; 
    473                 } 
    474                 print "\n\t" . '<meta http-equiv="Content-Type" content="text/html;charset=' . $config['charset'] . '" />'; 
    475                 print "\n\t" . '<meta http-equiv="imagetoolbar" content="false" />'; 
    476                 print generate_slideshow_js($GLOBALS["plogger_id"], "album"); 
    477                 // Embed URL to RSS feed for proper level. 
    478                 print "\n\t" . '<link rel="alternate" type="application/rss+xml" title="RSS Feed" href="'.plogger_rss_link().'" />' . "\n"; 
    479         } 
    480  
    481         function connect_db() { 
    482                 global $config; 
    483  
    484                 if (!PLOGGER_DB_HOST) { 
    485                         if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], "plog-admin")) { 
    486                                 $install_url = "_install.php"; 
    487                                 $upgrade_url = "_upgrade.php"; 
    488                                 $img = "<img src=\"images/plogger.gif\" alt=\"Plogger\" />"; 
    489                         } else { 
    490                                 $install_url = "plog-admin/_install.php"; 
    491                                 $upgrade_url = "plog-admin/_upgrade.php"; 
    492                                 $img = "<img src=\"plog-admin/images/plogger.gif\" alt=\"Plogger\" />"; 
    493                         } 
    494                         die($img."\n<br /><br />Please run <a href=\"".$install_url."\">_install.php</a> to set up Plogger. If you are upgrading from a previous version, please run <a href=\"".$upgrade_url."\">_upgrade.php</a>."); 
    495                 } 
    496  
    497                 global $PLOGGER_DBH; 
    498  
    499                 $PLOGGER_DBH = mysql_connect(PLOGGER_DB_HOST, PLOGGER_DB_USER, PLOGGER_DB_PW) or die ("Plogger cannot connect to the database because: " . mysql_error()); 
    500  
    501                 mysql_select_db(PLOGGER_DB_NAME); 
    502  
    503                 $mysql_version = mysql_get_server_info(); 
    504                 $mysql_charset_support = "4.1"; 
    505  
    506                 if (1 == version_compare($mysql_version, $mysql_charset_support)) { 
    507                         mysql_query("SET NAMES utf8"); 
    508                 } 
    509  
    510         } 
    511  
    512         function run_query($query) { 
    513                 global $PLOGGER_DBH; 
    514  
    515                 $result = @mysql_query($query, $PLOGGER_DBH); 
    516  
    517                 if (!$result){ 
    518                         $trace = debug_backtrace(); 
    519  
    520                         die(mysql_error($PLOGGER_DBH) . '<br /><br />' . 
    521                         $query . '<br /><br /> 
    522                         In file: '.$_SERVER["PHP_SELF"] . '<br /><br /> 
    523                         On line: ' . $trace[0]["line"]); 
     461function get_head_title() { 
     462        global $config; 
     463 
     464        $title = generate_title($GLOBALS['plogger_level'], $GLOBALS['plogger_id']); 
     465        return (SmartStripSlashes($config['gallery_name']) . ": ". $title); 
     466} 
     467 
     468function plogger_head() { 
     469        global $config; 
     470 
     471        if ($config["embedded"] == 0) { 
     472        print "\t<title>" . get_head_title() . "</title>"; 
     473        } 
     474        print "\n\t" . '<meta http-equiv="Content-Type" content="text/html;charset=' . $config['charset'] . '" />'; 
     475        print "\n\t" . '<meta http-equiv="imagetoolbar" content="false" />'; 
     476        print generate_slideshow_js($GLOBALS["plogger_id"], "album"); 
     477        // Embed URL to RSS feed for proper level. 
     478        print "\n\t" . '<link rel="alternate" type="application/rss+xml" title="RSS Feed" href="'.plogger_rss_link().'" />' . "\n"; 
     479} 
     480 
     481function connect_db() { 
     482        global $config; 
     483 
     484        if (!PLOGGER_DB_HOST) { 
     485                if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], "plog-admin")) { 
     486                        $install_url = "_install.php"; 
     487                        $upgrade_url = "_upgrade.php"; 
     488                        $img = "<img src=\"images/plogger.gif\" alt=\"Plogger\" />"; 
    524489                } else { 
    525                         return $result; 
    526                 } 
    527         } 
     490                        $install_url = "plog-admin/_install.php"; 
     491                        $upgrade_url = "plog-admin/_upgrade.php"; 
     492                        $img = "<img src=\"plog-admin/images/plogger.gif\" alt=\"Plogger\" />"; 
     493                } 
     494                die($img."\n<br /><br />Please run <a href=\"".$install_url."\">_install.php</a> to set up Plogger. If you are upgrading from a previous version, please run <a href=\"".$upgrade_url."\">_upgrade.php</a>."); 
     495        } 
     496 
     497        global $PLOGGER_DBH; 
     498 
     499        $PLOGGER_DBH = mysql_connect(PLOGGER_DB_HOST, PLOGGER_DB_USER, PLOGGER_DB_PW) or die ("Plogger cannot connect to the database because: " . mysql_error()); 
     500 
     501        mysql_select_db(PLOGGER_DB_NAME); 
     502 
     503        $mysql_version = mysql_get_server_info(); 
     504        $mysql_charset_support = "4.1"; 
     505 
     506        if (1 == version_compare($mysql_version, $mysql_charset_support)) { 
     507                mysql_query("SET NAMES utf8"); 
     508        } 
     509 
     510} 
     511 
     512function run_query($query) { 
     513        global $PLOGGER_DBH; 
     514 
     515        $result = @mysql_query($query, $PLOGGER_DBH); 
     516 
     517        if (!$result){ 
     518                $trace = debug_backtrace(); 
     519 
     520                die(mysql_error($PLOGGER_DBH) . '<br /><br />' . 
     521                $query . '<br /><br /> 
     522                In file: '.$_SERVER["PHP_SELF"] . '<br /><br /> 
     523                On line: ' . $trace[0]["line"]); 
     524        } else { 
     525                return $result; 
     526        } 
     527} 
    528528 
    529529function get_active_collections_albums() { 
     
    544544} 
    545545 
    546         function generate_thumb($path, $prefix, $type = THUMB_SMALL) { 
    547                 global $config; 
    548                 global $thumbnail_config; 
    549  
    550                 // for relative paths assume that they are relative to 'plog-content/images/' directory, 
    551                 // otherwise just use the given path 
    552                 if (file_exists($path)) { 
    553                         $source_file_name = $path; 
    554                 } else { 
    555                         $source_file_name = $config['basedir'] . 'plog-content/images/' . SmartStripSlashes($path); 
    556                 } 
    557  
    558                 // the file might have been deleted and since phpThumb dies in that case 
    559                 // try to do something sensible so that the rest of the images can still be seen 
    560  
    561                 // there is a problem in safe mode - if the script and picture file are owned by 
    562                 // different users, then the file cannot be read. 
    563  
    564                 if (!is_readable($source_file_name)) { 
    565                         return false; 
    566                 } 
    567  
    568                 $imgdata = @getimagesize($source_file_name); 
    569  
    570                 if (!$imgdata) { 
    571                         // unknown image format, bail out 
    572                         // do we want to have video support in the Plogger core? 
    573                         //return 'plog-graphics/thumb-video.gif'; 
    574                         return false; 
    575                 } 
    576  
    577                 // attributes of original image 
    578                 $orig_width = $imgdata[0]; 
    579                 $orig_height = $imgdata[1]; 
    580  
    581                 // XXX: food for thought - maybe we can return URL to some kind of error image 
    582                 // if this function fails? 
    583  
    584                 $base_filename = sanitize_filename(basename($path)); 
    585  
    586                 $thumb_config = $thumbnail_config[$type]; 
    587  
    588                 if (1 == $thumb_config['disabled']) { 
    589                         return $config['gallery_url'] . 'plog-content/images/' . $path; 
    590                 } 
    591  
    592                 $prefix = $thumb_config['filename_prefix'] . $prefix . "-"; 
    593  
    594                 $thumbpath = $config['basedir'] . 'plog-content/thumbs/'.$prefix.$base_filename; 
    595                 $thumburl = $config['gallery_url'] . 'plog-content/thumbs/'.$prefix.$base_filename; 
    596  
    597                 // if thumbnail file already exists and is generated after data for a thumbnail type 
    598                 // has been changed, then we assume that the thumbnail is valid. 
    599                 if (file_exists($thumbpath)){ 
    600                         $thumbnail_timestamp = @filemtime($thumbpath); 
    601                         if ($thumb_config['timestamp'] < $thumbnail_timestamp) { 
    602                                 return $thumburl; 
     546function generate_thumb($path, $prefix, $type = THUMB_SMALL) { 
     547        global $config; 
     548        global $thumbnail_config; 
     549 
     550        // for relative paths assume that they are relative to 'plog-content/images/' directory, 
     551        // otherwise just use the given path 
     552        if (file_exists($path)) { 
     553                $source_file_name = $path; 
     554        } else { 
     555                $source_file_name = $config['basedir'] . 'plog-content/images/' . SmartStripSlashes($path); 
     556        } 
     557 
     558        // the file might have been deleted and since phpThumb dies in that case 
     559        // try to do something sensible so that the rest of the images can still be seen 
     560 
     561        // there is a problem in safe mode - if the script and picture file are owned by 
     562        // different users, then the file cannot be read. 
     563 
     564        if (!is_readable($source_file_name)) { 
     565                return false; 
     566        } 
     567 
     568        $imgdata = @getimagesize($source_file_name); 
     569 
     570        if (!$imgdata) { 
     571                // unknown image format, bail out 
     572                // do we want to have video support in the Plogger core? 
     573                //return 'plog-graphics/thumb-video.gif'; 
     574                return false; 
     575        } 
     576 
     577        // attributes of original image 
     578        $orig_width = $imgdata[0]; 
     579        $orig_height = $imgdata[1]; 
     580 
     581        // XXX: food for thought - maybe we can return URL to some kind of error image 
     582        // if this function fails? 
     583 
     584        $base_filename = sanitize_filename(basename($path)); 
     585 
     586        $thumb_config = $thumbnail_config[$type]; 
     587 
     588        if (1 == $thumb_config['disabled']) { 
     589                return $config['gallery_url'] . 'plog-content/images/' . $path; 
     590        } 
     591 
     592        $prefix = $thumb_config['filename_prefix'] . $prefix . "-"; 
     593 
     594        $thumbpath = $config['basedir'] . 'plog-content/thumbs/'.$prefix.$base_filename; 
     595        $thumburl = $config['gallery_url'] . 'plog-content/thumbs/'.$prefix.$base_filename; 
     596 
     597        // if thumbnail file already exists and is generated after data for a thumbnail type 
     598        // has been changed, then we assume that the thumbnail is valid. 
     599        if (file_exists($thumbpath)){ 
     600                $thumbnail_timestamp = @filemtime($thumbpath); 
     601                if ($thumb_config['timestamp'] < $thumbnail_timestamp) { 
     602                        return $thumburl; 
     603                } 
     604        } 
     605 
     606        // if dimensions of source image are smaller than those of the requested 
     607        // thumbnail, then use the original image as thumbnail 
     608        if ($orig_width <= $thumb_config['size'] && $orig_height <= $thumb_config['size']) { 
     609                copy($source_file_name,$thumbpath); 
     610                return $thumburl; 
     611        } 
     612 
     613        // no existing thumbnail found or thumbnail config has changed, 
     614        // generate new thumbnail file 
     615 
     616        list($width, $height, $thumb_type, $attr) = @getimagesize($thumbpath); 
     617 
     618        require_once($config['basedir'] . 'plog-includes/lib/phpthumb/phpthumb.class.php'); 
     619 
     620        $phpThumb = new phpThumb(); 
     621 
     622        // set data 
     623        $phpThumb->setSourceFileName($source_file_name); 
     624        if ($imgdata[0] > $imgdata[1]) { 
     625                $phpThumb->w = $thumb_config['size']; 
     626        } else { 
     627                $phpThumb->h = $thumb_config['size']; 
     628        } 
     629 
     630        $phpThumb->q = $config['compression']; 
     631 
     632        // set zoom crop flag to get image squared off 
     633        if ($type == THUMB_SMALL && $config['square_thumbs']) { 
     634                $phpThumb->zc = 1; 
     635                $phpThumb->h = $thumb_config['size']; 
     636                $phpThumb->w = $thumb_config['size']; 
     637        } 
     638 
     639        $phpThumb->config_use_exif_thumbnail_for_speed = false; 
     640 
     641        // Set image height instead of width if not using square thumbs 
     642        if ($type == THUMB_SMALL && !$config['square_thumbs']) { 
     643                $phpThumb->h = $thumb_config['size']; 
     644                $phpThumb->w = ''; 
     645        } 
     646 
     647        if($type == THUMB_NAV) { 
     648                $phpThumb->zc = 1; 
     649                $phpThumb->h = $thumb_config['size']; 
     650                $phpThumb->w = $thumb_config['size']; 
     651        } 
     652 
     653        // set options (see phpThumb.config.php) 
     654        // here you must preface each option with "config_" 
     655 
     656        // Set error handling (optional) 
     657        $phpThumb->config_error_die_on_error = false; 
     658 
     659        // generate & output thumbnail 
     660        if ($phpThumb->GenerateThumbnail()) { 
     661                $phpThumb->RenderToFile($thumbpath); 
     662        } else { 
     663                // do something with debug/error messages 
     664                die('Failed: '.implode("\n", $phpThumb->debugmessages)); 
     665        } 
     666 
     667        return $thumburl; 
     668} 
     669 
     670function get_picture_by_id($id, $album_id = null) { 
     671        global $config; 
     672 
     673        if(is_array($id)) { 
     674                $where_cond = "IN ('".implode("', '",$id)."');"; 
     675        } else { 
     676                $where_cond = "= ".intval($id).";"; 
     677        } 
     678 
     679        $sql = "SELECT 
     680        `p`.*, 
     681        `a`.`path` AS `album_path`, 
     682        `c`.`path` AS `collection_path` 
     683        FROM `".TABLE_PREFIX."pictures` AS `p` 
     684        LEFT JOIN `".TABLE_PREFIX."albums` AS `a` ON `p`.`parent_album`=`a`.`id` 
     685        LEFT JOIN `".TABLE_PREFIX."collections` AS `c` ON `p`.`parent_collection`=`c`.`id` 
     686        WHERE `p`.`id` ".$where_cond; 
     687 
     688        if ($album_id){ 
     689                $sql .= " AND `p`.`parent_album`=".intval($album_id); 
     690        } 
     691 
     692        $resultPicture = run_query($sql); 
     693 
     694        if (is_array($id) && mysql_num_rows($resultPicture) > 0) { 
     695                $picdata = array(); 
     696                while ($row = mysql_fetch_assoc($resultPicture)) { 
     697                        $row['url'] = $config['gallery_url'].'plog-content/images/'.$row['collection_path'].'/'.$row['album_path'].'/'.basename($row['path']); 
     698                        array_unshift($picdata,$row); 
     699                } 
     700        } 
     701        elseif (!is_array($id) && mysql_num_rows($resultPicture) > 0){ 
     702                $picdata = mysql_fetch_assoc($resultPicture); 
     703 
     704                // eventually I want to get rid of the full path in pictures tables to avoid useless data duplication 
     705                // the following is a temporary solution so I don't have to break all the functionality at once 
     706                $picdata['url'] = $config['gallery_url'].'plog-content/images/'.$picdata['collection_path'].'/'.$picdata['album_path'].'/'.basename($picdata['path']); 
     707        } else { 
     708                $picdata = false; 
     709        } 
     710 
     711        return $picdata; 
     712} 
     713 
     714function get_pictures($album_id, $order = "alpha", $sort = "DESC"){ 
     715        global $config; 
     716 
     717        $query = "SELECT 
     718        `p`.*, 
     719        `a`.`path` AS `album_path`, 
     720        `c`.`path` AS `collection_path` 
     721        FROM `".TABLE_PREFIX."pictures` AS `p` 
     722        LEFT JOIN `".TABLE_PREFIX."albums` AS `a` ON `p`.`parent_album`=`a`.`id` 
     723        LEFT JOIN `".TABLE_PREFIX."collections` AS `c` ON `p`.`parent_collection`=`c`.`id` 
     724        WHERE `a`.`id`=".intval($album_id); 
     725 
     726        if ($order == "mod"){ 
     727                $query .= " ORDER BY `p`.`date_submitted` "; 
     728        } 
     729        else { 
     730                $query .= " ORDER BY `p`.`caption` "; 
     731        } 
     732 
     733        if ($sort == "ASC"){ 
     734                $query .= " ASC "; 
     735        } else { 
     736                $query .= " DESC "; 
     737        } 
     738 
     739        $result = run_query($query); 
     740 
     741        $pictures = array(); 
     742 
     743        while ($row = mysql_fetch_assoc($result)){ 
     744                // See comment in get_picture_by_id 
     745                $row['url'] = $config['gallery_url'].'plog-content/images/'.$row['collection_path'].'/'.$row['album_path'].'/'.basename($row['path']); 
     746                $pictures[$row["id"]] = $row; 
     747        } 
     748 
     749        return $pictures; 
     750} 
     751 
     752function get_album_by_id($id) { 
     753        global $config; 
     754 
     755        $sql = "SELECT 
     756        `a`.*, 
     757        `c`.`path` AS `collection_path`, 
     758        `a`.`path` AS `album_path`, 
     759        `c`.`name` AS `collection_name`, 
     760        `a`.`name` AS `album_name` 
     761        FROM `".TABLE_PREFIX."albums` AS `a` 
     762        LEFT JOIN `".TABLE_PREFIX."collections` AS `c` ON `a`.`parent_id`=`c`.`id` 
     763        LEFT JOIN `".TABLE_PREFIX."pictures` AS `i` ON `a`.`thumbnail_id`=`i`.`id` 
     764        WHERE `a`.`id` = ".intval($id); 
     765        $result = run_query($sql); 
     766 
     767        if (mysql_num_rows($result) > 0){ 
     768                $album = mysql_fetch_assoc($result); 
     769 
     770                if ($album["thumbnail_id"] == 0){ 
     771                        $query = "SELECT 
     772                        `id`, 
     773                        `path` 
     774                        FROM `".TABLE_PREFIX."pictures` 
     775                        WHERE `parent_album`=".intval($album["id"])." 
     776                        ORDER BY `date_submitted` DESC 
     777                        LIMIT 1"; 
     778                        $result = run_query($query); 
     779 
     780                        if (mysql_num_rows($result) > 0){ 
     781                                $row = m