Qdig PHP Cross Reference Image Galleries

Source: /index.php - 3644 lines - 123557 bytes - Summary - Text - Print

Description: Site Link (optional) The link is a location (URL) and the title is the link text.

   1  <?php
   2  /*

   3  +----------------------------------------------------------------------+

   4  | Qdig - A Quick Digital Image Gallery

   5  |

   6  | Qdig is an easy-to-use script that dynamically creates an image

   7  | gallery or set of galleries from image files stored on a web server's

   8  | filesystem.  Qdig supports subdirectory navigation for organized

   9  | presentation of any size image collection.  Qdig also supports image

  10  | captions, and can generate thumbnail images and smaller resampled

  11  | versions of large images such as digital camera photos.  Qdig is

  12  | simple to install, just drop it in a directory with images and/or

  13  | subdirectories that contain images.  Converting (resampling) images

  14  | requires either Image Magick or PHP's GD extensions and some quick-

  15  | and-simple additional setup.  There are dozens of configurable options

  16  | for customizing your galleries.  The script runs stand-alone, or a

  17  | gallery may be included within another page.  Enjoy!

  18  +----------------------------------------------------------------------+

  19  | Copyright 2002, 2003, 2004, 2005, 2006, 2007 Hagan Fox

  20  | This program is distributed under the terms of the

  21  | GNU General Public License, Version 2

  22  |

  23  | This program is free software; you can redistribute it and/or modify

  24  | it under the terms of the GNU General Public License, Version 2 as

  25  | published by the Free Software Foundation.

  26  |

  27  | This program is distributed in the hope that it will be useful,

  28  | but WITHOUT ANY WARRANTY; without even the implied warranty of

  29  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

  30  | GNU General Public License for more details.

  31  |

  32  | You should have received a copy of the GNU General Public License,

  33  | Version 2 along with this program; if not, visit GNU's Home Page

  34  | http://www.gnu.org/

  35  +----------------------------------------------------------------------+

  36  CVS: $Id: index.php,v 1.151 2007/02/11 06:26:22 haganfox Exp $

  37  */
  38  $qdig_version = '1.2.9.4';
  39  $mtime = microtime();
  40  $mtime = explode(" ",$mtime);
  41  $start_time = $mtime[1] + $mtime[0];
  42  
  43  /*

  44  +------------+

  45  |  Settings  |

  46  +------------+

  47  */
  48  
  49  // Site Settings ------------------------------------------------------+

  50  
  51  /**

  52  * Site Link (optional)

  53  *

  54  * The link is a location (URL) and the title is the link text.

  55  */
  56  $site_lnk_title = 'Home Page';  // Link text

  57  $site_lnk_url   = '';           // URL - Using '' will disable the Site Link.

  58  
  59  /**

  60  * Copyright text (optional)

  61  *

  62  * If this is set, the text will appear at the bottom of your gallery.

  63  * See http://www.whatiscopyright.org/ for information about copyrights.

  64  */
  65  $copyright['txt'] = 'Images copyright &copy; 2005, 2006, 2007 original creators or assignees. All rights reserved.';
  66  
  67  /**

  68  * Admin Script

  69  */
  70  $admin['script_file'] = 'admin.php';  // Location of Gallery Management Script

  71  $admin['full_url']    = '';           // Full URL of Gallery Management Script

  72                                        // in case just script_file isn't enough.

  73  
  74  /**

  75  * Chroot Directory

  76  *

  77  * Defines the topmost directory of the gallery tree.  Commented out by default.

  78  * Typically used when including a gallery within a web page.

  79  * See http://qdig.sourceforge.net/Support/ChrootDirectory for details.

  80  */
  81  //$chroot_dir = 'images/';  // Note: You may also want to add this path to the

  82                              // $qdig_files location (e.g. 'images/qdig-files/')

  83  
  84  // Layout Settings ----------------------------------------------------+

  85  // These are in roughly the same order as they appear in the output.

  86  
  87  /**

  88  * HTML Header

  89  *

  90  * These work for stand-alone mode only, since othewise headers are suppressed.

  91  */
  92  $header['title_text_1'] = 'Image Gallery';  // Leading text in title

  93  $header['title_delim']  = '|';    // Delimiter character(s)

  94  $header['title_cntr']   = TRUE;   // Include an 'x of y' counter.

  95  $header['title_text_2'] = '';     // Trailing text in title

  96  $header['img_name']     = TRUE;   // Include image name in title

  97  $header['nav_links']    = TRUE;   // Include nav. links in html header.

  98  $header['icon']         = TRUE;   // Use the qdig-camera icon.

  99  $header['force_disa']   = FALSE;  // Force HTML headers to be suppressed.

 100  $header['force_ena']    = FALSE;  // Force HTML headers to be produced.

 101  
 102  /**

 103  * Directory Navigation (Contains pwd and subdirectories.)

 104  */
 105  $dir_nav['enable']     = TRUE;    // Enable Directory Navigation.  If disabled,

 106                                    // subdirectories will be isolated galleries.

 107  $dir_nav['small']      = FALSE;   // Use small text for Dir. Navigation row.

 108  $dir_nav['fname_ena']  = FALSE;   // Display the filename.

 109  $dir_nav['cntr_ena']   = TRUE;    // Display the counter.

 110  $dir_nav['path_delim'] = '&gt;';  // Delimiter between path elements

 111  $dir_nav['dir_is_new'] = 0 * 24 * 60 * 60; // New if less than this many seconds

 112  $dir_nav['new_flag']   = '&nbsp;
 113        <small style="font-size:8pt; vertical-align:top; padding-bottom:1px; text-decoration:none;
 114         font-weight:normal; color:black; background-color:yellow;">&nbsp;New&nbsp;</small>';
 115                                    // String to display with dir name if "new"

 116  $dir_nav['sort_age']   = FALSE;   // Sort directories by time-since-modified

 117                                    // (most recent first) rather than by alpha.

 118  $dir_nav['sort_rev']   = FALSE;   // Reverse the sort order of directories.

 119  $dir_nav['icon']       = FALSE;   // Display a camera icon in directory links.

 120  $dir_nav['updir_ena']  = TRUE;    // Display an up-one-level link.

 121  $dir_nav['row_width']  = '100%';  // Width of the Directory Navigation row

 122  
 123  /**

 124  * Control Bar (Contains visitor preferences: links style and default view)

 125  */
 126  $ctrl_bar['enable']   = TRUE;   // Enable control bar.

 127  $dir_nav['prefs_ena'] = TRUE;   // Display a Preferences link, which toggles

 128                                  // the Control Bar for a more compact gallery.

 129  $ctrl_bar['vw_ctrl']  = TRUE;   // Enable control bar Links Style chooser.

 130  $ctrl_bar['sz_ctrl']  = FALSE;  // Enable control bar Default Size chooser.

 131  $ctrl_bar['small']    = TRUE;   // Use small text for control bar.

 132  
 133  /**

 134  * Image Links Placement and Sorting

 135  */
 136  $img_links_above     = FALSE;  // Locate image links (numerals, thumbnails)

 137                                 // above the image.  Sensible default is below.

 138  $img_links_sort_date = FALSE;  // Sort images by date, not alphabetically.

 139  $img_links_sort_rev  = FALSE;  // Sort images in reverse order.

 140  
 141  /**

 142  * Thumbnail Image Links

 143  */
 144  $thmb_default = TRUE;  // Default to thumbs view if thumbs-capable.

 145  $thmb_enable  = TRUE;  // Enable thumbs view.  Safe to leave TRUE.

 146  $thmb_onfly   = TRUE;  // Create thumbnails 'on the fly' in their

 147                         // own request so pages load more quickly.

 148  // Wrapping -- Don't wrap only one or two thumbnails.

 149  $thmb_row['maxwidth'] = 680;  // Approx. max. width of thumbnails row

 150  $thmb_row['softwrap'] = 85;   // A percentage, 51 to 99

 151  
 152  /**

 153  * Filename and Numeral Text Image Links

 154  */
 155  $txtlinks_default = 'none';  // If no text-link type is specified, default

 156                               // to name, num, or none.

 157  $namelinks_disa   = FALSE;   // Disable 'names' view option in the Control

 158                               // Bar size chooser.  (Avoids the sidebar.)

 159  $namelinks_small  = TRUE;    // Use small text for filename links.

 160  $namelinks_trunc  = 16;      // Number of filename characters to display

 161  // Numeral Text Image Links

 162  $nmrl_row['small']   = TRUE;   // Use small text for numeral links.

 163  $nmrl_row['pad_top'] = '2px';  // padding above rows of numeral links

 164  // Wrapping -- Don't wrap only one or two links.

 165  $nmrl_row['maxcount'] = 23;    // maximum number of numeral links per row

 166  $nmrl_row['softwrap'] = 85;    // percentage, 51 to 99

 167  
 168  /**

 169  * Upper Gallery Navigation Row immediately above the image

 170  *

 171  * If nothing on the row is enabled, the navigation row is omitted.

 172  */
 173  $upr_nav['enable']    = TRUE;
 174  $upr_nav['sizer']     = FALSE;  // Show resizing links.  Overrides 'full_link'.

 175  $upr_nav['full_link'] = FALSE;  // Show `Full Size' link if image is resized.

 176  $upr_nav['prv_next']  = TRUE;   // Show `Previous' / `Next' links.

 177  $upr_nav['wrap']      = FALSE;  // Wrap at Prev / Next at last / first image.

 178  $upr_nav['frst_last'] = TRUE;   // Show ` |<< ' and ` >>| ' links.

 179  $upr_nav['cntr']      = FALSE;  // Show `x of y' counter if no $dir_nav counter.

 180  $upr_nav['cntr_bold'] = FALSE;  // Bold font for `x of y' message

 181  $upr_nav['sml_txt']   = FALSE;  // Use small text.

 182  $upr_nav['width']     = '500';  // Width of this navRow's table

 183  $upr_nav['pad_top']   = '0px';  // Padding above row

 184  
 185  /**

 186  * Image Display

 187  */
 188  $caption['min_width'] = 300;    // Minimum width for an image caption

 189  $caption['padding']   = '3px';  // Padding around caption text

 190  $caption['nl2br']     = FALSE;  // Automatically insert <br /> tags in captions.

 191  $caption['left_just'] = FALSE;  // Left-justify caption (otherwise centered).

 192  $caption['above']     = FALSE;  // Place caption above the image, not below it.

 193  // Settings for making the displayed image an active link

 194  $img_link['next']    = TRUE;   // Link to the next image from the one displayed.

 195  $img_link['wrap']    = FALSE;  // Link back to first image from the last one.

 196  $img_link['wrap_up'] = TRUE;   // Link the last image to the directory above.

 197  // Other scripts have the following, so some people must like it.

 198  $img_link['full']  = FALSE;  // If the image is a resized version, link to the

 199                               // full sized version.  Disables 'next' and 'wrap'.

 200  $img_link['file']  = FALSE;  // Full size link goes directly to the image file.

 201  
 202  /**

 203  * Lower Gallery Navigation Row below the image and caption

 204  *

 205  * If nothing on the row is enabled, the navigation row is omitted.

 206  */
 207  $lwr_nav['enable']    = TRUE;
 208  $lwr_nav['sizer']     = FALSE;  // Show resizing links.  Overrides 'full_link'.

 209  $lwr_nav['full_link'] = TRUE;   // Show `Full Size' link if image is resized.

 210  $lwr_nav['prv_next']  = TRUE;   // Show `previous' / `next' links.

 211  $lwr_nav['wrap']      = FALSE;  //  Wrap at prev / next at last / first image.

 212  $lwr_nav['frst_last'] = TRUE;   // Show ` |<< ' and ` >>| ' links.

 213  $lwr_nav['cntr']      = TRUE;   // Show `x of y' counter if no $dir_nav counter.

 214  $lwr_nav['cntr_bold'] = TRUE;   // Bold font for `x of y' message

 215  $lwr_nav['sml_txt']   = FALSE;  // Use small text for this navigation row.

 216  $lwr_nav['width']     = '500';  // Width of this navRow's table

 217  $lwr_nav['pad_top']   = '2px';  // Padding above row

 218  
 219  /**

 220  * Gallery Footer Row

 221  */
 222  $footer['pad_top']     = '5px';     // Extra space above the footer line

 223  $site_link_fnt_size    = '0.75em';  // Font size for Site Home Link

 224  $copyright['fnt_size'] = '0.75em';  // Font size for Copyright Message

 225  $qdig_homelink['ena']  = TRUE;      // Show the Qdig Home link.

 226  $qdig_homelink['fnt_size'] = '0.75em';  // Qdig Home link Font size

 227  
 228  // Color and CSS Style Settings ---------------------------------------+

 229  // See http://qdig.sourceforge.net/Qdig/ColorSchemes

 230  
 231  // HTML Header CSS settings are only effective for stand-alone Qdig.

 232  $header['css_bgcolor']     = '#f8f8f8';  // Page Background

 233  $header['css_text_color']  = '#333333';  // Text

 234  $header['css_link_color']  = '#004080';  // Link

 235  $header['css_visit_color'] = '#006699';  // Visited Link

 236  $header['css_bg_img_url']  = '';         // URL of a tiled background image.

 237                                           // Example: '../images/qdig-bg.jpg'

 238  $header['css_bg_logo']     = FALSE;      // Use a background logo.

 239  $header['css_logo_url']    = '';         // URL of logo image, else use cam-icon

 240  $header['css_logo_pos']    = '99% 99%';  // CSS position of the bg_logo.

 241  $header['css_img_bg']      = '#eeeeee';  // Image background (when loading)

 242                                           // 'transparent' is a valid "color".

 243  $header['css_img_border']  = '#cccccc';  // Displayed-image border

 244  $header['css_img_brdr_w']  = '1px';      // Width of displayed-image border

 245  $header['css_thm_border']  = '#cccccc';  // Thumbnail images' border

 246  $header['css_thm_brdr_w']  = '0px';      // Width of thumbnail-image border

 247  $header['css_thm_opacity'] = '100';      // Setting of 1 to 99 fades thumbs.

 248                                           // (Opacity uses invalid CSS and

 249                                           // slows rendering speed.)

 250  $header['css_opacity_moz'] = FALSE;      // Opacity for older gecko browsers

 251  $header['css_thm_hilite']  = '#f9f99f';  // Hilight border for current-thumb.

 252  $header['css_thm_hl_w']    = '2px';      // Width of highlight border

 253  $header['css_user_def']    = '';         // User-defined CSS rules

 254  // Set these to '' to disable.

 255  $sidebar_bg_clr         = '#eeeeee';  // Sidebar background

 256  $sidebar_margin_top     = '4px';      // Margin above the sidebar

 257  $sidebar_height         = '';         // '' is "auto".  example: '350px'

 258  $copyright['color']     = '#cccccc';  // Copyright text

 259  $admin['color']         = '#cccccc';  // Admin link text

 260  $qdig_homelink['color'] = '#cccccc';  // Qdig Home Link text

 261  $grayout_color          = '#999999';  // Grayed-out text

 262  // Gallery Table and Image Table (Possibly for an embedded gallery)

 263  // Use '' for default background color.

 264  $gallery_table_bg_clr   = '';  // Background color of the gallery table.

 265  $image_table_bg_clr     = '';  // Background color of image area.

 266  // Arbitrary code can be inserted before or after the gallery table.

 267  $pre_gallery            = '';  // User-defined output before gallery

 268  $post_gallery           = '';  // User-defined output after gallery

 269  
 270  
 271  // Image Conversion and Alternate-size Settings -----------------------+

 272  // Thumbnail settings are in the Layout Settings section.

 273  
 274  /**

 275  * Writable Directories

 276  *

 277  * Folders containing your original images may be read-only by the web server

 278  * daemon, but the script needs write permissions to write empty caption .txt

 279  * files and converted-image files (thumbnail and alternate-sized images).

 280  */
 281  $qdig_files = 'qdig-files/'; // The root of the writable tree.  Setup is easy:

 282                               // Create the directory.  Give it 2777 permissions

 283                               // (`chmod 2777').  Visit the gallery once.  Then

 284                               // change the permissions to something sane (0755).

 285  //$cnvrtd_dir = 'qdig-converted';  // Name of the resampled images subdirectory.

 286                                     // Uncomment this and comment out $qdig_files

 287                                     // for the behavior of previous releases.

 288  $convrtd_subdir = 'converted-images/';  // Subdir for resampled images

 289  $caption_subdir = 'captions';           // Subdir for captions

 290  $touch_captions = TRUE;  // Create empty caption .txt files, if found missing.

 291  
 292  /**

 293  * Image Magick and GD Settings

 294  *

 295  * If you have both Image Magick and GD, Qdig uses IM except on a Win32 server.

 296  * To use the one that isn't the default, set the default one to FALSE.

 297  */
 298  $convert_magick = TRUE;  // Use Image Magick, if available, to convert images.

 299  $convert_cmd    = '/usr/bin/convert';  // Full pathname to `convert'.

 300  // Example $convert_cmd for Win32 users:

 301  //$convert_cmd    = '"C:\\Program Files\\ImageMagick-5.5.3-Q16\\convert.exe"';

 302  $convert_GD     = TRUE;  // Use PHP GD, if available, to convert images.

 303  $convert_GD_ver = '';    // '' is auto-detect (recommended).  Else '1' or '2'.

 304  
 305  /**

 306  * Sizes to convert / display

 307  *

 308  * Enable or disable any of the alternate sizes (to save bandwidth,

 309  * fit a layout, etc.).  Experiment, but here are some suggestions:

 310  * Old Defaults: TRUE,TRUE,TRUE,TRUE,FALSE

 311  * Basic: FALSE,TRUE,FALSE,FALSE,TRUE

 312  */
 313  $disp_size['0'] = FALSE;  // 'S'  | These cause resizing links

 314  $disp_size['1'] = TRUE;   // 'M'  | in the Control Bar and

 315  $disp_size['2'] = FALSE;  // 'L'  | Navigation Bar to disappear

 316  $disp_size['3'] = FALSE;  // 'XL' | if set to FALSE and

 317  $disp_size['4'] = TRUE;   // 'FS' | appear if set to TRUE.

 318  // If no size is specified, use this size as the default.

 319  $default_img_size = '1';  // '1' is medium.  Must be an enabled size.

 320  
 321  /**

 322  * Thumbnail Image Conversion Settings

 323  */
 324  $cnvrt_thmb['size'] = 30;  // Thunbnail image height in pixels.

 325                             // Sizes: 10 is tiny, 20 is small, 35 is medium,

 326                             //        50 is large, 75 is jumbo

 327  $cnvrt_thmb['qual'] = 60;  // Thumbnail image quality.  Large thumbnails

 328                             // may look better, but will have increased file

 329                             // size, if you increase this a bit.

 330  $cnvrt_thmb['sharpen'] = '0.6x0.6';  // Level of sharpening for thumbnails.

 331  $cnvrt_thmb['single']  = FALSE;      // Convert thumb in a singleton directory.

 332  $cnvrt_thmb['mesg_on'] = FALSE;   // Produce a message when a thunbnail image

 333                                   // is auto-generated.

 334  $cnvrt_thmb['no_prof'] = FALSE;  // Strip image profile data to reduce size.

 335                                   // (May be incompatible with some servers.)

 336  $cnvrt_thmb['prefix']  =         // Filename prefix for thumbnail images.
 337    "thm{$cnvrt_thmb['size']}_";   // Use "thm_" for externally generated thumbs.

 338  
 339  /**

 340  * Alternate-sized Image Conversion Settings

 341  *

 342  * ['prefix']  is the filename prefix for the generated file.

 343  * ['sharpen'] is the sharpen pramater passed to ImageMagick.

 344  * ['maxwid']  is the size setting.  Other dimensions are calculated.

 345  * ['qual']    is the compression quality level.

 346  * ['txt']     is the image size text used inline in a message.  (Language Setting)

 347  * ['label']   is the text used for a link.  (Language Setting)

 348  */
 349  $cnvrt_alt['indiv']   = TRUE;   // Convert alternates one-at-a-time rather than

 350                                  // all the images in a directory at once.

 351  $cnvrt_alt['mesg_on'] = TRUE;   // Produce a message when an image is converted.

 352  $cnvrt_alt['no_prof'] = FALSE;  // Strip image profile data to reduce size.

 353                                  // (May be incompatible with some servers.)

 354  // small

 355  $cnvrt_size['0']['prefix']  = 'sml_';
 356  $cnvrt_size['0']['sharpen'] = '0.6x0.8';
 357  $cnvrt_size['0']['maxwid']  = 512;
 358  $cnvrt_size['0']['qual']    = 87;
 359  // medium

 360  $cnvrt_size['1']['prefix']  = 'med_';
 361  $cnvrt_size['1']['sharpen'] = '0.6x0.8';
 362  $cnvrt_size['1']['maxwid']  = 640;
 363  $cnvrt_size['1']['qual']    = 89;
 364  // large

 365  $cnvrt_size['2']['prefix']  = 'lrg_';
 366  $cnvrt_size['2']['sharpen'] = '0.6x0.9';
 367  $cnvrt_size['2']['maxwid']  = 800;
 368  $cnvrt_size['2']['qual']    = 90;
 369  // x-large

 370  $cnvrt_size['3']['prefix']  = 'xlg_';
 371  $cnvrt_size['3']['sharpen'] = '0.6x0.9';
 372  $cnvrt_size['3']['maxwid']  = 1024;
 373  $cnvrt_size['3']['qual']    = 91;
 374  // actual

 375  $cnvrt_size['4']['prefix']  = '../';
 376  
 377  // Language Settings --------------------------------------------------+

 378  // Text that appears in the output may be configured here.

 379  
 380  /**

 381  * Header

 382  */
 383  $header['lang_code'] = 'en';
 384  $header['charset']   = 'iso-8859-1';
 385  
 386  /**

 387  * Directory Navigation

 388  */
 389  $dir_nav['main_txt']        = 'Main';
 390  $dir_nav['choose_main_txt'] = 'Choose a gallery:';
 391  $dir_nav['choose_main_title_txt'] = 'Please choose a gallery.';
 392  $dir_nav['choose_sub_txt']  = '';
 393  $dir_nav['choose_sub_title_txt']  = 'Please choose a gallery.';
 394  $dir_nav['empty_dir_txt']   = 'No gallery!';
 395  $dir_nav['empty_dir_title_txt']   = 'Sorry, no gallery here.';
 396  $dir_nav['image_txt']       = 'Image';
 397  $dir_nav['go_to_txt']       = 'Go to';
 398  $dir_nav['up_level_txt']    = 'Up&nbsp;a&nbsp;level..';
 399  $dir_nav['up_title_txt']    = 'Go up one level';
 400  $dir_nav['current_txt']     = 'Current location:';
 401  $dir_nav['prefs_title_txt'] = 'Change your visitor preferences';
 402  $dir_nav['prefs_txt']       = 'Preferences';
 403  
 404  /**

 405  * Gallery Navigation Links

 406  */
 407  $nav_lnk['prv_txt']   = '&lt;&lt; Previous';
 408  $nav_lnk['prv_msg']   = 'Previous Image';
 409  $nav_lnk['next_txt']  = 'Next &gt;&gt;';
 410  $nav_lnk['next_msg']  = 'Next Image';
 411  $nav_lnk['last_txt1'] = '&lt;&lt; Last';
 412  $nav_lnk['last_txt2'] = '&gt;&gt;|';
 413  $nav_lnk['last_msg']  = 'Last Image';
 414  $nav_lnk['frst_txt1'] = 'First &gt;&gt;';
 415  $nav_lnk['frst_txt2'] = '|&lt;&lt;';
 416  $nav_lnk['frst_msg']  = 'First Image';
 417  $nav_lnk['image']     = 'Image';
 418  
 419  /**

 420  * Text shown if there is no image to display

 421  */
 422  $empty_gallery_msg   = 'Empty gallery!';
 423  
 424  // Text/Messages for controlView() (links view on control bar)

 425  $ctrl_links_mesg['links_style'] = 'Links Style:';
 426  $ctrl_links_mesg['thumbs_txt'] = 'Thumbs';
 427  $ctrl_links_mesg['names_txt']  = 'Names';
 428  $ctrl_links_mesg['nums_txt']   = 'Numbers';
 429  $ctrl_links_mesg['none_txt']   = 'None';
 430  $ctrl_links_mesg['thumbs_msg'] = 'Switch to Thumbnail Links';
 431  $ctrl_links_mesg['names_msg']  = 'Switch to Filename Links';
 432  $ctrl_links_mesg['nums_msg']   = 'Switch to Calendar-Style Links';
 433  $ctrl_links_mesg['none_msg']   = 'Disable Direct Image Links';
 434  
 435  /**

 436  * Image size title text

 437  */
 438  $cnvrt_size['0']['label'] = 'S';
 439  $cnvrt_size['1']['label'] = 'M';
 440  $cnvrt_size['2']['label'] = 'L';
 441  $cnvrt_size['3']['label'] = 'XL';
 442  $cnvrt_size['4']['label'] = 'FS';
 443  $img_sz_labels['ctrl']['default_size'] = 'Default Size:';
 444  $img_sz_labels['ctrl']['str1'] = 'Change the default image size to ';
 445  $img_sz_labels['nav']['str1']  = 'See the ';
 446  $img_sz_labels['nav']['str1a'] = 'Return to the ';
 447  $cnvrt_size['0']['txt']  = 'Small';
 448  $cnvrt_size['1']['txt']  = 'Medium';
 449  $cnvrt_size['2']['txt']  = 'Large';
 450  $cnvrt_size['3']['txt']  = 'Extra Large';
 451  $cnvrt_size['4']['txt']  = 'Full Size';
 452  $cnvrt_size['4']['txt2'] = 'default';
 453  $img_sz_labels['ctrl']['str2'] = '.';
 454  $img_sz_labels['nav']['str2']  = ' version of this image.';
 455  
 456  /**

 457  * Admin link

 458  */
 459  $admin['link_title']  = 'Edit Caption';
 460  $admin['link_text']   = 'Admin';
 461  $admin['before_link'] = '(';
 462  $admin['after_link']  = ')';
 463  
 464  /**

 465  * Image conversion messages (e.g. "Generated a new Large converted image for image.jpg")

 466  */
 467  $cnvrt_mesgs['generated']  = 'Generated a new ';
 468  $cnvrt_mesgs['generating'] = 'Generating a new ';
 469  $cnvrt_mesgs['thumb']      = 'thumbnail';
 470  $cnvrt_mesgs['converted']  = ' converted';
 471  $cnvrt_mesgs['image_for']  = ' image for ';
 472  $cnvrt_mesgs['using IM']   = " using 'convert'";
 473  $cnvrt_mesgs['using GD']   = ' using GD';
 474  $cnvrt_mesgs['on-the-fly'] = ''; // was: ' (on-the-fly)'

 475  
 476  /**

 477  * Miscellaneous

 478  */
 479  $lang['nav_cntr_txt']  = 'of'; // Counter ("x of n")

 480  $lang['Forbidden']     = 'Forbidden';
 481  $lang['diag_messages'] = 'Diagnostic Messages';
 482  
 483  // Security Settings  ------------------------------------------------+

 484  
 485  /**

 486  * File creation mask.  Determines default permissions for created files, dirs.

 487  *

 488  * Examples: umask(002)  // `drwxrwxr-x' and `-rw-rw-r--' (world readable)

 489  *           umask(007)  // `drwxrwx---' and `-rw-rw----' (not world readable)

 490  */
 491  umask(002);
 492  
 493  /**

 494  * Paranoia Settings

 495  */
 496  $safe_captions    = TRUE;   // Disable HTML in Captions.  Convert special

 497                              // characters (<>&"') to `HTML entities'

 498  $check_security   = TRUE;   // Perform a security check for world-writability.

 499  $ignore_dir_links = TRUE;   // Ignore gallery directories if they're symlinks.

 500  $ignore_img_links = TRUE;   // Ignore image files if they're symlinks.

 501  $pathname_maxlen  = 100;    // Max. number of characters in a pathname.

 502  $imgname_maxlen   = 100;    // Max. number of characters in an image filename.

 503  $extra_paranoia   = FALSE;  // Do extra-strict checking for '..'.

 504  $ignore_dotfiles  = FALSE;  // Ignore files that start with '.'.

 505  $ignore_dotdirs   = FALSE;  // Ignore directories that start with '.'.

 506  // HTML Header settings are only effective for stand-alone Qdig.

 507  $header['zap_frames']    = FALSE; // Break out of a frameset.

 508  $header['ie_imgbar_off'] = TRUE;  // Suppress IE6's image toolbar.

 509  
 510  // Miscellaneous Settings ---------------------------------------------+

 511  
 512  /**

 513  * Server Compatibility

 514  */
 515  // Disable use of certain PHP functions for compatibility with some servers.

 516  $is_readable_disa = FALSE;  // Set to TRUE if is_readable() causes trouble.

 517  $file_exists_disa = FALSE;  // Set to TRUE if file_exists() causes trouble.

 518  $max_exec_time    = 30;     // Max. execution time in seconds

 519  $compat_quote     = TRUE;   // Add and extra "s to exec() command on Win32.

 520                              // For Win98 this should be set to FALSE.

 521  $exclude_gif      = FALSE;  // Exclude GIF images.

 522  // HTML Header settings are only effective for stand-alone Qdig.

 523  $header['meta_cache'] = FALSE;  // Use a Cache-Control meta tag.  For servers

 524                                  // that cause repeated reloading of thumbs.

 525  $header['cache_sec']  = '3600'; // Number of seconds for the cache to expire.

 526  
 527  /**

 528  * Path Settings  (Override defaults.)

 529  */
 530  $qdig_url = '';       // Self-referring URL path.  Examples: '/photos/' or

 531                        // '/photos/qdig.php' or '/~someuser/qdig/index.php'

 532  // The next two are the same location; as a URL and as a filesystem path.

 533  $url_base_path = '';  // Base URL path to the images (not the script)

 534                        // Examples: '/photos/qdig/' or '/~someuser/qdig/'

 535  $fs_base_path  = '';  // Filesystem path to the root dir of the gallery.

 536                        // Ex.: '/home/someuser/public_html/qdig/' or '../qdig'

 537  
 538  /**

 539  * Et-cetera

 540  */
 541  $excl_dirs[] = 'Private';         // Ignore a directory with its name

 542  $excl_dirs[] = 'qdig-converted';  // included here.  Do not  end these

 543  $excl_dirs[] = '';                // name(s) with '/'.

 544  $excl_imgs[] = 'qdig-bg.jpg';     // Ignore any image with its name

 545  $excl_imgs[] = 'favicon.png';     // included here.  Add as many of

 546  $excl_imgs[] = '';                // these as you wish.

 547  $excl_img_pattern = '_thumb';     // Don't display files containing this string.

 548  $excl_main   = FALSE;  // Exclude all images in the root (Main) directory.

 549  $extra_param = '';     // Extra parameter(s) to include in URLs.

 550                         // Examples: 'incl=qdig.php&amp;' 'a=foo&amp;b=bar&amp;'

 551  $anchor = '';          // Include an intra-page anchor in URLs.  For embedded

 552                         // galleries, use '#qdig' to jump down to the gallery.

 553  $keep_params = FALSE;  // Keep extra GET parameters in the URLs.

 554  
 555  /**

 556  * Debugging Setting

 557  */
 558  $diag_messages = FALSE; // Produce diagnostic messages.  This will also enable

 559                          // verbose PHP error reporting.

 560  
 561  /**

 562  * Get External Settings

 563  */
 564  if (function_exists('qdig_settings')) {
 565      qdig_settings($qdig_version);
 566  }
 567  
 568  // Settings Notes -----------------------------------------------------+

 569  // (To make upgrading easier, put notes about your settings here.)

 570  
 571  /*

 572  +-------------------+

 573  |  Adapt to Server  |

 574  +-------------------+

 575  */
 576  
 577  // Get global variables and protect them from register_globals.

 578  $get_vars = ($_GET) ? $_GET : $HTTP_GET_VARS;
 579  $post_vars = ($_POST) ? $_POST : $HTTP_POST_VARS;
 580  $cookie_vars = ($_COOKIE) ? $_COOKIE : $HTTP_COOKIE_VARS;
 581  $request_vars = ($_REQUEST)
 582      ? $_REQUEST
 583      : array_merge($get_vars, $post_vars, $cookie_vars);
 584  if (ini_get('register_globals')) {
 585      if (!is_array($request_vars)) { securityExit('Security Violation'); }
 586      foreach($request_vars as $k=>$v) {
 587          if (preg_match('/^(GLOBALS|_SERVER|_GET|_POST|_COOKIE|_FILES|_ENV|_REQUEST|_SESSION|qdig-files)$/i', $k)) {
 588              securityExit('Security violation'); }
 589          ${$k}=''; unset(${$k});
 590      }
 591  }
 592  $server_vars = ($_SERVER) ? $_SERVER :  $HTTP_SERVER_VARS;
 593  // Disallow some special characters in the query string.

 594  if (preg_match('/(%00|%3c|<)/', $server_vars['QUERY_STRING'])
 595      || preg_match('!\\\\0!', @$get_vars['Qwd'])) {
 596      securityExit('Invalid request.'); }
 597  $php_self = @$server_vars['PHP_SELF'];
 598  $script_name = @$server_vars['SCRIPT_NAME'];
 599  if (! $request_uri = @$server_vars['REQUEST_URI']) {  // Not provided by IIS.
 600      $request_uri = @$php_self.'?'.@$server_vars['argv'][0];  // Close enough

 601  }
 602  // Suppress harmless Notices and annoying Warnings.  Restored at the end.

 603  if (!isset($orig_err_rep_level)) {
 604      $orig_err_rep_level = ($diag_messages == TRUE)
 605          ? error_reporting(E_ALL)
 606          : error_reporting(E_ALL ^E_NOTICE ^E_WARNING);
 607  }
 608  // Establish self-referring URL.

 609  if (empty($qdig_url)) {
 610      $tmp = explode('?', @$request_uri);
 611      $qdig_url = @$tmp['0'];
 612      unset($tmp);
 613  }
 614  if (empty($qdig_url)) {
 615      $qdig_url = @$script_name;
 616  }
 617  // Safe mode?

 618  if (ini_get('safe_mode')) {
 619      $safe_mode = TRUE;
 620  } else {
 621      $safe_mode = FALSE;
 622      @ini_set('max_execution_time', $max_exec_time);
 623  }
 624  // Which OS?

 625  if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
 626      $platform = 'Win32';
 627  } elseif (strtoupper(substr(PHP_OS, 0, 3)) == 'MAC') {
 628      $platform = 'Macintosh';
 629  } elseif (strtoupper(substr(PHP_OS, 0, 3)) == 'LIN') {
 630      $platform = 'Linux';
 631  } else {
 632      $platform = 'Unix';
 633  }
 634  // Included Qdig?

 635  if (realpath(__FILE__) == realpath(@$_SERVER['SCRIPT_FILENAME'])
 636      || ! $tmp = get_included_files())
 637  {
 638      $is_included = FALSE;
 639  } else {
 640      $is_included = TRUE;
 641  }
 642  
 643  /**

 644  * Produce an icon image if ?image=cam-icon

 645  */
 646  if (@$get_vars['image'] == 'cam-icon') {
 647      cam_icon();
 648      die();
 649  }
 650  if (@$get_vars['image'] == 'clear-dot') {
 651      clear_dot();
 652      die();
 653  }
 654  
 655  /*

 656  +-------------+

 657  |  Functions  |

 658  +-------------+

 659  */
 660  
 661  // http://qdig.sourceforge.net/Qdig/FunctionsList

 662  
 663  /**

 664  * The encoded icon image.

 665  */
 666  function cam_icon() 
 667  {
 668      header('Content-type: image/png');
 669      header('Content-length: 346');
 670      echo base64_decode(
 671  'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAALHRFWHRDcmVhdGlvbiBUaW1lAFRo'.
 672  'dSAyNiBEZWMgMjAwMiAxMToxOTowNiAtMDcwMOKR1KkAAAAHdElNRQfSDBoSGhzS+Jz0AAAACXBI'.
 673  'WXMAAAsSAAALEgHS3X78AAAABGdBTUEAALGPC/xhBQAAACdQTFRF////ZmZmMzMzZjMzM2ZmM2Yz'.
 674  'ZjNmzMzMmZnMmZmZmZn/zP//ZmbMVprHTAAAAAF0Uk5TAEDm2GYAAABxSURBVHjaVU+LEsAgCAqr'.
 675  'pbb//95Be9OdHoRSpSwAMKC8wCT+Qv6FJod9HZVbbgd0E0A8XAmt8rCLDyKChVF0QxS5IyQwyRbP'.
 676  'mRbauxzkUuQdeIS8BY54E68u4VpaPZty1ohiHfCTm35u4KtY+9a3cgC4QwQQbFlZCQAAAABJRU5E'.
 677  'rkJggg==');
 678  } // End cam_icon()

 679  
 680  function clear_dot() 
 681  {
 682      header('Content-type: image/gif');
 683      header('Content-length: 43');
 684      echo base64_decode(
 685  'R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
 686  }
 687  
 688  /**

 689  * Security Exit

 690  */
 691  function securityExit($mesg = 'Unspecified Error')
 692  {
 693      global $lang;    
 694        header('HTTP/1.0 403 Forbidden');
 695        exit("<html>\n <head><title>403 {$lang['Forbidden']}</title></head>
 696   <body>{$lang['Forbidden']}: $mesg</body>\n</html>");
 697  } // End securityExit()

 698  
 699  /**

 700  * Return 'TRUE' or 'FALSE' string based on a variable's status.

 701  */
 702  function trueFalse($data, $true = 'TRUE', $false = 'FALSE')
 703  {
 704      if (@$data == TRUE) {
 705          return $true;
 706      } else {
 707          return $false;
 708      }
 709  } // End trueFalse()

 710  
 711  /**

 712  * Return non-Qdig GET parameters, ready for prepending to a query string.

 713  */
 714  function keepParams()
 715  {
 716      global $get_vars, $extra_param;
 717      if (!empty($extra_param)) { return; }
 718      $params = '';
 719      foreach($get_vars as $param => $value) {
 720          $qdig_params = array('Qwd', 'Qif', 'Qiv', 'Qis', 'Qtmp', 'image', 'Makethumb');
 721          if (in_array($param, $qdig_params)) { continue; }
 722          $params .= $param.'='.$value.'&amp;';
 723      }
 724      return $params;
 725  }
 726  
 727  /**

 728  * Get the names of image files in a directory.

 729  */
 730  function getImageFilenames($path)
 731  {
 732      global $rootdir, $is_readable_disa, $convert_GD, $ignore_img_links,
 733          $img_links_sort_rev, $img_links_sort_date, $imgname_maxlen, $exclude_gif,
 734          $excl_main, $excl_imgs, $excl_img_pattern, $extra_paranoia, $ignore_dotfiles;
 735      if ($excl_main == TRUE && $path == $rootdir) { return; }
 736      if ($convert_GD == TRUE) {
 737          $img_exts = '\.jpg$|\.jpeg$|\.jpe$|\.png$';
 738      } else {
 739          $img_exts = '\.jpg$|\.jpeg$|\.jpe$|\.png$|\.bmp$';
 740      }
 741      if ($exclude_gif == FALSE) {
 742          $img_exts .= '|\.gif$';
 743      }
 744      $pwd_handle = opendir($path);
 745      $i = 100;
 746      while (($file = readdir($pwd_handle)) != false) {
 747          if ($file == '.' || $file == '..') { continue; }
 748          if ($extra_paranoia == TRUE && is_file($path.'/'.$file)) {
 749              if (strpos(stripslashes(rawurldecode($file)), '..')
 750                  || ($file[0] == '.' && $file[1] == '.'))
 751              {
 752                  securityExit('Updir ("..") is not allowed in a filename.');
 753              }
 754              if (strlen($file) > $imgname_maxlen) {
 755                  securityExit('Filename length exceed.  Increase $imgname_maxlen?');
 756              }
 757          }
 758          if ($ignore_dotfiles == TRUE && $file[0] == '.') { continue; }
 759          if (in_array($file, $excl_imgs)) { continue; }
 760          if (strpos('*'.$file, $excl_img_pattern)) { continue; }
 761          if (is_file($path.'/'.$file)
 762              && ($is_readable_disa == TRUE || is_readable($path.'/'.$file))
 763              && ! ($ignore_img_links == TRUE && is_link($path.'/'.$file))
 764              && eregi($img_exts, $file))
 765          {
 766              $mod_date = filemtime($path.'/'.$file).$i;
 767              $img_files[$mod_date] = $file;
 768              $i++;
 769          }
 770      }
 771      closedir($pwd_handle);
 772      if (isset($img_files)) {
 773          if ($img_links_sort_date == TRUE) {
 774              ksort($img_files);
 775          } else {
 776              natcasesort($img_files);
 777          }
 778          foreach($img_files as $img) {
 779              $sorted_files[]=$img;
 780          }
 781          if ($img_links_sort_rev == TRUE) {
 782              return (array_reverse($sorted_files));
 783          } else {
 784              return $sorted_files;
 785          }
 786      }
 787  } // End getImageFilenames()

 788  
 789  /**

 790  * Check to see if at least one potential gallery directory exists.

 791  */
 792  function checkForDirs($path)
 793  {
 794      global $qdig_files_topdir, $cnvrtd_dir, $is_readable_disa,
 795          $ignore_dir_links, $excl_dirs, $ignore_dotdirs;
 796      $pwd_handle = opendir($path);
 797      while (($file = readdir($pwd_handle)) != FALSE) {
 798          if($file == '..'
 799              || $file == '.'
 800              || $file == $qdig_files_topdir
 801              || $file == $cnvrtd_dir
 802              || @in_array($file, $excl_dirs)
 803              || ($ignore_dir_links == TRUE && is_link($path.'/'.$file))
 804              || ! ($is_readable_disa == TRUE || is_readable($path.'/'.$file)))
 805          {
 806              continue;
 807          }
 808          if ($ignore_dotdirs == TRUE && $file[0] == '.') { continue; }
 809          if (is_dir($path.'/'.$file)) {
 810              $has_dir = TRUE;
 811              closedir($pwd_handle);
 812              return $has_dir;
 813          }
 814      }
 815      closedir($pwd_handle);
 816  } // End checkForDirs()

 817  
 818  /**

 819  * Check for existence of at least one image file in a directory.

 820  */
 821  function checkForImgs($path)
 822  {
 823      global $is_readable_disa, $ignore_img_links, $ignore_dotfiles;
 824      $pwd_handle = opendir($path);
 825      while (($file = readdir($pwd_handle)) != FALSE) {
 826          if(is_dir($path.'/'.$file)
 827              || ($ignore_img_links == TRUE && is_link($path.'/'.$file))
 828              || ! ($is_readable_disa == TRUE || is_readable($path.'/'.$file)))
 829          {
 830              continue;
 831          }
 832          if ($ignore_dotfiles == TRUE && $file[0] == '.') { continue; }
 833          if (eregi('\.jpg$|\.jpeg$|\.jpe$|\.png$|\.gif$|\.bmp$', $file)) {
 834              $has_img = TRUE;
 835              closedir($pwd_handle);
 836              return $has_img;
 837          }
 838      }
 839      closedir($pwd_handle);
 840  } // End checkForImgs()

 841  
 842  /**

 843  * Get the names of gallery directories in a directory.

 844  *

 845  * A gallery directory is one that contains at least one image or potential

 846  * gallery directory.  Returns an array with the dirname and its age.

 847  */
 848  function getDirNames($path)
 849  {
 850      global $qdig_files_topdir, $cnvrtd_dir, $is_readable_disa,
 851          $ignore_dir_links, $dir_nav, $excl_dirs, $ignore_dotdirs;
 852      $dir_handle = opendir($path);
 853      while (($file = readdir($dir_handle)) != false) {
 854          if($file == '..'
 855              || $file == '.'
 856              || ! is_dir($path.'/'.$file)
 857              || ($ignore_dir_links == TRUE && is_link($path.'/'.$file))
 858              || ! ($is_readable_disa == TRUE || is_readable($path.'/'.$file))
 859              || @in_array($file, $excl_dirs)
 860              || $file == $qdig_files_topdir
 861              || $file == $cnvrtd_dir)
 862          {
 863              continue;
 864          }
 865          if ($ignore_dotdirs == TRUE && $file[0] == '.') { continue; }
 866          $dirs[]=$file;
 867      }
 868      closedir($dir_handle);
 869      if (isset($dirs)) {
 870          $timeofday = gettimeofday();
 871          $unixtime = $timeofday['sec'];
 872          $i = 0;
 873          natcasesort($dirs);
 874          foreach($dirs as $dir) {
 875              if (checkForImgs($path.'/'.$dir) || checkForDirs($path.'/'.$dir)
 876                  && ($is_readable_disa == TRUE || is_readable($path)))
 877              {
 878                  $dirmodified = filemtime($path.'/'.$dir);
 879                  $dir_age = 1000 * ($unixtime - $dirmodified) + $i;
 880                  $sorted_dirs[$dir] = $dir_age;
 881                  $i++;
 882              }
 883          }
 884          if (isset($sorted_dirs)) {
 885              if ($dir_nav['sort_rev'] == TRUE) {
 886                  return (array_reverse($sorted_dirs));
 887              } else {
 888                  return $sorted_dirs;
 889              }
 890          }
 891      }
 892  } // End getDirNames()

 893  
 894  /*

 895  * Get the image number and filename of the requested image.

 896  *

 897  * If none is requested or the file is non-existent, default to the first image.

 898  */
 899  function getReqdImage()
 900  {
 901      global $pwd, $imgs, $get_vars, $imgname_maxlen, $extra_paranoia;
 902      if (empty($imgs)) { return; }
 903      if (isset($get_vars['Qif'])) {
 904          $imagefile = stripslashes(rawurldecode($get_vars['Qif']));
 905          if (strlen($imagefile) > $imgname_maxlen
 906              || ($imagefile[0] == '.' && $imagefile[1] == '.'))
 907          {
 908              securityExit('Filename (Qif=) is too long or starts with "..".');
 909          }
 910          // Redundant, but what the heck.

 911          if ($extra_paranoia == TRUE
 912              && strpos(stripslashes(rawurldecode($imagefile)), '..'))
 913          {
 914              securityExit('Updir ("..") not allowed in a filename.');
 915          }
 916      }
 917      if (isset($imagefile) && is_file($pwd.'/'.$imagefile)) {
 918          $reqd_img_file = $imagefile;
 919          // Look up the image's index number

 920          $imgs_flip = array_flip($imgs);
 921          $reqd_img_num = $imgs_flip[$imagefile];
 922      } else {
 923          $reqd_img_file = $imgs[0];
 924          $reqd_img_num = 0;
 925      }
 926      return array('file' => $reqd_img_file, 'num' => $reqd_img_num);
 927  } // End getReqdImage()

 928  
 929  /**

 930  * Convert a string to a useful path starting with './'.

 931  *

 932  * click/buzz/./pop//boom/../bam/  becomes  ./click/buzz/pop/boom/bam

 933  */
 934  function cleanPath($path)
 935  {
 936      $path = stripslashes(rawurldecode($path));
 937      $path_array = explode('/', $path);
 938      $clean_path = '.';
 939      foreach($path_array as $dir) {
 940          if ($dir == '' || $dir == '.' || $dir == '..' || $dir == '...') { continue; }
 941          $clean_path .='/'.$dir;
 942      }
 943      return $clean_path;
 944  } // End cleanPath()

 945  
 946  /**

 947  * rawurlencode() a file's path but keep the slashes.

 948  */
 949  function urlPath($path)
 950  {
 951      $decoded = rawurldecode($path);     // Decode if encoded

 952      $cleaned = cleanPath($decoded);
 953      $encoded = rawurlencode($cleaned);  // Encode

 954      $encoded_path = str_replace('%2F', '/', $encoded);  // replace slashes

 955      return $encoded_path;
 956  } // End rawurlencodePath()

 957  
 958  /**

 959  * Build an 'x of n' counter.

 960  */
 961  function imageCounter($image_num)
 962  {
 963      global $imgs, $lang;
 964      $num_imgs = count($imgs);
 965      $img_num = $image_num + 1;
 966      if ($num_imgs > 0) {
 967          $str = "$img_num {$lang['nav_cntr_txt']} $num_imgs";
 968          return $str;
 969      }
 970  } // End imageCounter()

 971  
 972  /**

 973  * Get which version of GD is installed, if any.

 974  *

 975  * Returns the version (1 or 2) of the GD extension.

 976  */
 977  function gdVersion()
 978  {
 979      global $convert_GD_ver;
 980      if (! extension_loaded('gd')) { return; }
 981      if ($convert_GD_ver == 1 || $convert_GD_ver == 2) {
 982          return $convert_GD_ver;
 983      }
 984      // We don't need to use phpinfo() if the PHP version is recent.

 985      if (version_compare('4.3.2', phpversion(), '<=')) {    return '2';    }
 986      // Rely on phpinfo() for PHP < 4.3.2, or otherwise use a fail-safe choice.

 987      if (preg_match('/phpinfo/', ini_get('disable_functions'))) { return '1'; }
 988      ob_start();
 989      phpinfo(8);
 990      $info = ob_get_contents();
 991      ob_end_clean();
 992      $info = stristr($info, 'gd version');
 993      preg_match('/\d/', $info, $gd);
 994      return $gd[0];
 995  } // End gdVersion()

 996  
 997  /**

 998  * Create a directory recursively (like `mkdir -p $dir').

 999  *

1000  * For security './' is prepended if missing.

1001  */
1002  function mkRecursiveDir($dir)
1003  {
1004      global $file_exists_disa;
1005      $path_array = explode('/', $dir);
1006      $path = '.';
1007      foreach($path_array as $dir) {
1008          if ($dir == '' || $dir == '.' || $dir == '..' || $dir == '...') { continue; }
1009          $path .= '/'.$dir;
1010          if ((($file_exists_disa == TRUE && ! is_file($path))
1011                  || ! file_exists($path))
1012              && is_writable(dirname($path)))
1013          {
1014              mkdir($path, 0777);
1015          }
1016      }
1017  } // End mkRecursiveDir()

1018  
1019  /**

1020  * Generate thumbnail images for images that do not have thumbnails yet.

1021  */
1022  function createThumbs($cnvrt_thmb)
1023  {
1024      global $platform, $pwd, $imgs, $convert_magick, $cnvrt_path, $convert_cmd,
1025          $convert_GD, $thmbs_ena, $convert_writable, $caption_path,
1026          $touch_captions, $cnvrt_mesgs, $file_exists_disa, $compat_quote;
1027      if ($thmbs_ena == FALSE || empty($imgs) || $convert_writable == FALSE) { return; }
1028      if ($cnvrt_thmb['single'] == FALSE && count($imgs) < 2) { return; }  // one-image gallery

1029      if ($convert_GD == TRUE && ! ($gd_version = gdVersion())) {return; }
1030      if (! isset($cnvrt_thmb['size'])) {
1031          $cnvrt_thmb['size'] = 35;
1032      }
1033      if (! isset($cnvrt_thmb['qual'])) {
1034          $cnvrt_thmb['qual'] = 65;
1035      }
1036      if ($cnvrt_thmb['mesg_on'] == TRUE) {
1037          $str = '';
1038      }
1039      if ($convert_magick == TRUE) {
1040          if ($cnvrt_thmb['no_prof'] == TRUE) {
1041              $strip_prof = ' +profile "*"';
1042          } else {
1043              $strip_prof = '';
1044          }
1045          if ($platform == 'Win32' && $compat_quote == TRUE) {
1046              $winquote = '"';
1047          } else {
1048              $winquote = '';
1049          }
1050      }
1051      foreach($imgs as $img_file) {
1052          if ($touch_captions == TRUE && is_dir($caption_path)) {
1053              $caption_file = $caption_path.'/'.$img_file.'.txt';
1054              if (($file_exists_disa == TRUE && ! is_file($caption_file))
1055                  || ! file_exists($caption_file))
1056              {
1057                  touch($caption_file);
1058              }
1059          }
1060          $orig_img = $pwd.'/'.$img_file;
1061          $cnvrtd_img = $cnvrt_path.'/'.$cnvrt_thmb['prefix'].$img_file;
1062          if (($file_exists_disa == TRUE && ! is_file($cnvrtd_img))
1063              || ! file_exists($cnvrtd_img))
1064          {
1065              $img_size = GetImageSize($orig_img);
1066              $height   = $img_size[1];
1067              $th_maxdim = $height;
1068              $cnvt_percent = round(($cnvrt_thmb['size'] / $th_maxdim) * 100, 2);
1069              // convert it

1070              if ($convert_magick == TRUE) {
1071                  // Image Magick image conversion

1072                  exec($winquote.$convert_cmd
1073                      .' -geometry '.$cnvt_percent.'%'
1074                      .' -quality '.$cnvrt_thmb['qual']
1075                      .' -sharpen '.$cnvrt_thmb['sharpen'].$strip_prof
1076                      .' "'.$orig_img.'"'.' "'.$cnvrtd_img.'"'.$winquote);
1077                  $using = $cnvrt_mesgs['using IM'];
1078              } elseif ($convert_GD == TRUE) {
1079                  // GD image conversion

1080                  if (eregi('\.jpg$|\.jpeg$', $img_file) == TRUE
1081                      && (imageTypes() & IMG_JPG) == TRUE)
1082                  {
1083                      $src_img = imageCreateFromJpeg($orig_img);
1084                  } elseif (eregi('\.png$', $img_file) == TRUE
1085                      && (imageTypes() & IMG_PNG) == TRUE)
1086                  {
1087                      $src_img = imageCreateFromPng($orig_img);
1088                  } elseif (eregi('\.gif$', $img_file) == TRUE
1089                      && (imageTypes() & IMG_GIF) == TRUE)
1090                  {
1091                      $src_img = imageCreateFromGif($orig_img);
1092                  } else {
1093                      continue;
1094                  }
1095                  $src_width  = imageSx($src_img);
1096                  $src_height = imageSy($src_img);
1097                  $dest_width = $src_width * ($cnvt_percent / 100);
1098                  $dest_height = $src_height * ($cnvt_percent / 100);
1099                  if ($gd_version >= 2) {
1100                      $dst_img = imageCreateTruecolor($dest_width, $dest_height);
1101                      imageCopyResampled($dst_img, $src_img, 0, 0, 0, 0,
1102                          $dest_width, $dest_height, $src_width, $src_height);
1103                  } else {
1104                      $dst_img = imageCreate($dest_width, $dest_height);
1105                      imageCopyResized($dst_img, $src_img, 0, 0, 0, 0,
1106                          $dest_width, $dest_height, $src_width, $src_height);
1107                  }
1108                  imagedestroy($src_img);
1109                  if (eregi('\.jpg$|\.jpeg$', $img_file) == TRUE
1110                      && (imageTypes() & IMG_JPG) == TRUE)
1111                  {
1112                      imageJpeg($dst_img, $cnvrtd_img, $cnvrt_thmb['qual']);
1113                  } elseif (eregi('\.png$', $img_file) == TRUE
1114                      && (imageTypes() & IMG_PNG) == TRUE)
1115                  {
1116                      imagePng($dst_img, $cnvrtd_img);
1117                  } elseif (eregi('\.gif$', $img_file) == TRUE
1118                      && (imageTypes() & IMG_GIF) == TRUE)
1119                  {
1120                      imageGif($dst_img, $cnvrtd_img);
1121                  }
1122                  imagedestroy($dst_img);
1123                  $using = $cnvrt_mesgs['using GD'].$gd_version;
1124              }
1125              if ($cnvrt_thmb['mesg_on'] == TRUE && is_file($cnvrtd_img)) {
1126                  $str .= "  <small>\n"
1127                      .'   '.$cnvrt_mesgs['generated']
1128                      .$cnvrt_mesgs['thumb'].$cnvrt_mesgs['image_for']
1129                      .$img_file.$using.".\n"
1130                      ."  </small>\n  <br />\n";
1131              }
1132          }
1133      }
1134      if (isset($str)) {
1135          return $str;
1136      }
1137  } // End createThumbs()

1138  
1139  /**

1140  * Figure out how big a thumb will be, based on input image

1141  */
1142  function predictThumbSize($orig_img)
1143  {
1144      global $cnvrt_thmb;
1145      $img_size = GetImageSize($orig_img);
1146      $width    = $img_size[0];
1147      $height   = $img_size[1];
1148      $th_maxdim = $height;
1149      $cnvt_percent = round(($cnvrt_thmb['size'] / $th_maxdim) * 100, 2);
1150      $dest_width   = round($width * ($cnvt_percent / 100));
1151      $dest_height  = round($height * ($cnvt_percent / 100));
1152      $attr = sprintf("height=\"%s\" width=\"%s\"", $dest_height, $dest_width);
1153      return array($dest_width, $dest_height, $img_size[2], $attr);
1154  } // End predictThumbSize()

1155  
1156  /**

1157  * Generate images of alternate sizes.

1158  */
1159  function resizeImage($cnvrt_arry)
1160  {
1161      global $platform, $imgs, $cnvrt_path, $reqd_image, $convert_writable,
1162          $convert_magick, $convert_GD, $convert_cmd, $cnvrt_alt, $cnvrt_mesgs,
1163          $compat_quote;
1164      if (empty($imgs) || $convert_writable == FALSE) { return; }
1165      if ($convert_GD == TRUE && ! ($gd_version = gdVersion())) {return; }
1166      if ($cnvrt_alt['no_prof'] == TRUE) {
1167          $strip_prof = ' +profile "*"';
1168      } else {
1169          $strip_prof = '';
1170      }
1171      if ($cnvrt_alt['mesg_on'] == TRUE) {
1172          $str = '';
1173      }
1174      foreach($imgs as $img_file) {
1175          if ($cnvrt_alt['indiv'] == TRUE && $img_file != $reqd_image['file']) { continue; }
1176          $orig_img   = $reqd_image['pwd'].'/'.$img_file;
1177          $cnvrtd_img = $cnvrt_path.'/'.$cnvrt_arry['prefix'].$img_file;
1178          if (! is_file($cnvrtd_img)) {
1179              $img_size = GetImageSize($orig_img);
1180              $height  = $img_size[1];
1181              $width   = $img_size[0];
1182              $area    = $height * $width;
1183              $maxarea = $cnvrt_arry['maxwid'] * $cnvrt_arry['maxwid'] * 0.9;
1184              $maxheight = ($cnvrt_arry['maxwid'] * .75 + 1);
1185              if ($area > $maxarea
1186                  || $width > $cnvrt_arry['maxwid']
1187                  || $height > $maxheight)
1188              {
1189                  if (($width / $cnvrt_arry['maxwid']) >= ($height / $maxheight)) {
1190                      $dim = 'W';
1191                  }
1192                  if (($height / $maxheight) >= ($width / $cnvrt_arry['maxwid'])) {
1193                      $dim = 'H';
1194                  }
1195                  if ($dim == 'W') {
1196                      $cnvt_percent = round(((0.9375 * $cnvrt_arry['maxwid']) / $width) * 100, 2);
1197                  }
1198                  if ($dim == 'H') {
1199                      $cnvt_percent = round(((0.75 * $cnvrt_arry['maxwid']) / $height) * 100, 2);
1200                  }
1201                  // convert it

1202                  if ($convert_magick == TRUE) {
1203                      // Image Magick image conversion

1204                      if ($platform == 'Win32'
1205                          && $compat_quote == TRUE)
1206                      {
1207                          $winquote = '"';
1208                      } else {
1209                          $winquote = '';
1210                      }
1211                      exec($winquote.$convert_cmd
1212                          .' -geometry '.$cnvt_percent.'%'
1213                          .' -quality '.$cnvrt_arry['qual']
1214                          .' -sharpen '.$cnvrt_arry['sharpen'].$strip_prof
1215                          .' "'.$orig_img.'"'.' "'.$cnvrtd_img.'"'.$winquote);
1216                      $using = $cnvrt_mesgs['using IM'];
1217                  } elseif ($convert_GD == TRUE) {
1218                      // GD image conversion

1219                      if (eregi('\.jpg$|\.jpeg$', $img_file) == TRUE
1220                          && (imageTypes() & IMG_JPG) == TRUE)
1221                      {
1222                          $src_img = imageCreateFromJpeg($orig_img);
1223                      } elseif (eregi('\.png$', $img_file) == TRUE
1224                          && (imageTypes() & IMG_PNG) == TRUE)
1225                      {
1226                          $src_img = imageCreateFromPng($orig_img);
1227                      } elseif (eregi('\.gif$', $img_file) == TRUE
1228                          && (imageTypes() & IMG_GIF) == TRUE)
1229                      {
1230                          $src_img = imageCreateFromGif($orig_img);
1231                      } else {
1232                          continue;
1233                      }
1234                      $src_width  = imageSx($src_img);
1235                      $src_height = imageSy($src_img);
1236                      $dest_width = $src_width * ($cnvt_percent / 100);
1237                      $dest_height = $src_height * ($cnvt_percent / 100);
1238                      if ($gd_version >= 2) {
1239                          $dst_img = imageCreateTruecolor($dest_width, $dest_height);
1240                          imageCopyResampled($dst_img, $src_img, 0, 0, 0, 0,
1241                              $dest_width, $dest_height, $src_width, $src_height);
1242                      } else {
1243                          $dst_img = imageCreate($dest_width, $dest_height);
1244                          imageCopyResized($dst_img, $src_img, 0, 0, 0, 0,
1245                              $dest_width, $dest_height, $src_width, $src_height);
1246                      }
1247                      imageDestroy($src_img);
1248                      if (eregi('\.jpg$|\.jpeg$', $img_file) == TRUE
1249                          && (imageTypes() & IMG_JPG) == TRUE)
1250                      {
1251                          imageJpeg($dst_img, $cnvrtd_img, $cnvrt_arry['qual']);
1252                      } elseif (eregi('\.png$', $img_file) == TRUE
1253                          && (imageTypes() & IMG_PNG) == TRUE)
1254                      {
1255                          imagePng($dst_img, $cnvrtd_img);
1256                      } elseif (eregi('\.gif$', $img_file) == TRUE
1257                          && (imageTypes() & IMG_GIF) == TRUE)
1258                      {
1259                          imageGif($dst_img, $cnvrtd_img);
1260                      }
1261                      imageDestroy($dst_img);
1262                      $using = $cnvrt_mesgs['using GD'].$gd_version;
1263                  }
1264                  if ($cnvrt_alt['mesg_on'] == TRUE
1265                      && is_file($cnvrtd_img))
1266                  {
1267                      $str .= "  <small>\n"
1268                          .'   '.$cnvrt_mesgs['generated'].$cnvrt_arry['txt'].$cnvrt_mesgs['converted']
1269                          .$cnvrt_mesgs['image_for'].$img_file.$using.".\n"
1270                          ."  </small>\n  <br />\n";
1271                  }
1272              }
1273          }
1274      }
1275      if (isset($str)) {
1276          return $str;
1277      }
1278  } //End resizeImage()

1279  
1280  /**

1281  * Produce the HTML header for a stand-alone gallery.

1282  *

1283  * Only produce a header if this is a stand-alone gallery.

1284  */
1285  function htmlHeader($header)
1286  {
1287      global $is_included, $imgs, $qdig_url, $request_uri, $anchor, $extra_param,
1288          $subdirs, $reqd_image, $is_readable_disa, $dir_nav;
1289      if ($header['force_disa'] == TRUE) { return ''; }
1290      $str = '';
1291      if ($header['force_ena'] == TRUE || $is_included == FALSE) {
1292          if (!empty($header['title_text_1'])) {
1293              $title = $header['title_text_1'];
1294          }
1295          $title_loc = basename($reqd_image['pwd']);
1296          if ($title_loc != '.') {
1297              $title .= " {$header['title_delim']} $title_loc";
1298          } elseif (isset($subdirs)) {
1299              $title .= " {$header['title_delim']} {$dir_nav['main_txt']}";
1300          }
1301          if ($header['title_cntr'] == TRUE
1302              && isset($reqd_image['num'])
1303              && $title_cntr = imageCounter($reqd_image['num']))
1304          {
1305              $title .= " {$header['title_delim']} $title_cntr";
1306          }
1307          if (!empty($header['title_text_2'])) {
1308              $title .= " {$header['title_delim']} {$header['title_text_2']}";
1309          }
1310          if ($header['img_name'] == TRUE && isset($reqd_image['file'])) {
1311              $title .= " {$header['title_delim']} {$reqd_image['file']}";
1312          }
1313          if ($header['meta_cache'] == TRUE) {
1314              $meta_cache = '<meta http-equiv="Cache-Control" content="max-age='.$header['cache_sec']."\" />\n ";
1315          } else {
1316              $meta_cache = '';
1317          }
1318          if (!empty($header['css_bg_img_url'])) {
1319              $bg_image = 'body { background-image: url("'.$header['css_bg_img_url'].'"); background-attachment: fixed; }'."\n  ";
1320          } elseif ($header['css_bg_logo'] == TRUE) {
1321              if (!empty($header['css_logo_url'])
1322                  && is_file($header['css_logo_url']))
1323              {
1324                  $icon = $header['css_logo_url'];
1325              } else {
1326                  $icon = "$qdig_url?image=cam-icon";
1327              }
1328              $bg_image = "body { background-image:url(\"$icon\");"
1329                  ."background-position:{$header['css_logo_pos']};\n"
1330                  ."   background-repeat:no-repeat; background-attachment:fixed; }\n  ";
1331          } else {
1332              $bg_image = '';
1333          }
1334          if ($header['ie_imgbar_off'] == TRUE) {
1335              $ie_imgtoolbar = '<meta http-equiv="imagetoolbar" content="no" />'."\n ";
1336          } else {
1337              $ie_imgtoolbar = '';
1338          }
1339          if ($header['zap_frames'] == TRUE) {
1340              $zap_frames = ' <script type="text/javascript"> <!--'
1341                  ."\n  if (top.frames.length > 1) { top.location=\"$request_uri\"; }\n"
1342                  ."  // -->\n </script>\n";
1343          } else {
1344              $zap_frames = '';
1345          }
1346          $str = <<<EOT
1347  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1348  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1349  <html lang="{$header['lang_code']}">
1350  <head>
1351   $meta_cache<meta http-equiv="Content-Type" content="text/html; charset={$header['charset']}" />
1352   <meta http-equiv="Content-Language" content="{$header['lang_code']}" />
1353   <meta http-equiv="Content-Style-Type" content="text/css" />
1354   $ie_imgtoolbar<meta name="description" content="An online image gallery" />
1355   <meta name="keywords" content="qdig,image gallery,photo album,online gallery,web photo album,digital image gallery,web gallery,photos,images,album,gallery,digital images,digital camera,digital photos,digicam,digital camera photos,presentation,presentation software" />
1356   <meta name="robots" content="index,follow" />
1357   <meta name="MSSmartTagsPreventParsing" content="true" />\n
1358  EOT;
1359          if ($header['nav_links'] == TRUE) {
1360              if ($reqd_image['pwd'] != '.') {
1361                  $str .= ' <link rel="top" href="'.$qdig_url.'?'.$extra_param.'Qwd=.&amp;Qiv='
1362                      .$reqd_image['view'].'&amp;Qis='.$reqd_image['size'].$anchor.'" />'."\n";
1363                  $up_one = urlPath(dirname($reqd_image['pwd']));
1364                  $str .= ' <link rel="up" href="'.$qdig_url.'?'.$extra_param.'Qwd='.$up_one
1365                      .'&amp;Qiv='.$reqd_image['view'].'&amp;Qis='.$reqd_image['size'].$anchor.'" />'
1366                      ."\n";
1367              }
1368              if (!empty($imgs) && $reqd_image['num'] != 0) {
1369                  $first_img = rawurlencode($imgs[0]);
1370                  $str .= ' <link rel="first" href="'.$qdig_url.'?'.$extra_param.'Qwd='.$reqd_image['pwd']
1371                      .'&amp;Qif='.$first_img.'&amp;Qiv='.$reqd_image['view']
1372                      .'&amp;Qis='.$reqd_image['size'].$anchor.'" />'."\n";
1373                  $prev_img = rawurlencode($imgs[$reqd_image['num'] - 1]);
1374                  $str .= ' <link rel="prev" href="'.$qdig_url.'?'.$extra_param.'Qwd='
1375                      .$reqd_image['pwd'].'&amp;Qif='.$prev_img.'&amp;Qiv='.$reqd_image['view']
1376                      .'&amp;Qis='.$reqd_image['size'].$anchor.'" />'."\n";
1377              }
1378              $num_imgs = count($imgs);
1379              if (!empty($imgs) && $reqd_image['num'] + 1 != $num_imgs) {
1380                  $next_img = rawurlencode($imgs[$reqd_image['num'] + 1]);
1381                  $str .= ' <link rel="next" href="'.$qdig_url.'?'.$extra_param.'Qwd='.$reqd_image['pwd']
1382                      .'&amp;Qif='.$next_img.'&amp;Qiv='.$reqd_image['view'].'&amp;Qis='
1383                      .$reqd_image['size'].$anchor.'" />'."\n";
1384                  $last_img = rawurlencode($imgs[$num_imgs - 1]);
1385                  $str .= ' <link rel="last" href="'.$qdig_url.'?'.$extra_param.'Qwd='.$reqd_image['pwd']
1386                      .'&amp;Qif='.$last_img.'&amp;Qiv='.$reqd_image['view'].'&amp;Qis='
1387                      .$reqd_image['size'].$anchor.'" />'."\n";
1388              }
1389          }
1390          if ($header['css_thm_opacity'] > 0
1391              && $header['css_thm_opacity'] < 100)
1392          {
1393              $alpha = $header['css_thm_opacity'];
1394              $opacity = $alpha / 100;
1395              if ($header['css_opacity_moz'] == TRUE) {
1396                  $moz_opacity = " -moz-opacity:$opacity;";
1397                  $moz_opacity_cur = ' -moz-opacity:100;';
1398              } else {
1399                  $moz_opacity = '';
1400                  $moz_opacity_cur = '';
1401              }
1402              $thm_opacity = "
1403      filter:alpha(opacity=$alpha);$moz_opacity opacity:$opacity;";
1404              $thm_opacity_curr = "
1405      filter:alpha(opacity=100);$moz_opacity_cur opacity:1.0;";
1406          } else {
1407              $thm_opacity = '';
1408              $thm_opacity_curr = '';
1409          }
1410          if ($header['icon'] == TRUE) {
1411              $str .= <<<EOT
1412   <link rel="icon" href="$qdig_url?image=cam-icon" type="image/png" />
1413   <link rel="SHORTCUT ICON" href="$qdig_url?image=cam-icon" type="image/png" />\n
1414  EOT;
1415          }
1416          $str .= <<<EOT
1417   <title>$title</title>
1418   <style type="text/css"> <!--
1419    /* Bare-bones CSS style properties for a stand-alone Qdig gallery */

1420    body { font-family:Arial, Helvetica, Geneva, sans-serif;
1421      background-color:{$header['css_bgcolor']}; margin:1px; }
1422    {$bg_image}body, td { font-size:14px; color:{$header['css_text_color']}; }
1423    small { font-size:0.85em; }
1424    a { font-weight:bold; color: {$header['css_link_color']};
1425      text-decoration: none; }
1426    a:visited { font-weight:bold; color:{$header['css_visit_color']};
1427      text-decoration:none; }
1428    a:hover { text-decoration:underline; }
1429    img { border:0px; }
1430    img.qdig-image { background-color:{$header['css_img_bg']};
1431      border:{$header['css_img_brdr_w']} solid {$header['css_img_border']}; }
1432    img.qdig-thumb { background-color:{$header['css_img_bg']};
1433      border:{$header['css_thm_brdr_w']} solid {$header['css_thm_border']};$thm_opacity }
1434    img#qdig-thumb-current { border-color:{$header['css_thm_hilite']};
1435      border-left:{$header['css_thm_hl_w']} solid {$header['css_thm_hilite']};
1436      border-right:{$header['css_thm_hl_w']} solid {$header['css_thm_hilite']};$thm_opacity_curr }
1437    div.qdig-caption { font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; }
1438    .qdig-grayout {  } {$header['css_user_def']} // -->

1439   </style>
1440  $zap_frames</head>
1441  <body>
1442  <div align="center" style="padding-top:0px;">\n
1443  EOT;
1444      }
1445      return $str;
1446  } // End htmlHeader()

1447  
1448  /**

1449  * Produce the HTML footer for a stand-alone gallery.

1450  *

1451  * Only produce a footer if this script is running stand-alone.

1452  */
1453  function htmlFooter($header)
1454  {
1455      global $is_included;
1456      if ($header['force_disa'] == TRUE) { return "\n"; }
1457      $str = "\n";
1458      if ($header['force_ena'] == TRUE || $is_included == FALSE) {
1459          $str = "</div>\n</body>\n</html>";
1460      }
1461      return $str;
1462  } // End htmlFooter()

1463  
1464  /**

1465  * Display the current gallery directory with links to higher-level directories.

1466  */
1467  function dirnavPath($dir_nav)
1468  {
1469      global $imgs, $subdirs, $qdig_url, $extra_param, $anchor, $reqd_image,
1470          $dir_nav, $rootdir;
1471      $i        = 0;
1472      $num_imgs = count($imgs);
1473      $split_path = explode('/', urlPath($reqd_image['pwd']));
1474      $path_pos = count($split_path);
1475      $split_root = explode('/', urlPath($rootdir));
1476      $root_pos = count($split_root);
1477      $path     = $rootdir;
1478      $str      = '';
1479      $path_delim = $dir_nav['path_delim'];
1480      foreach($split_path as $dir) {
1481          $i++;
1482          if ($i < $root_pos) { continue; }
1483          if ($dir == $split_path[$root_pos - 1] && $reqd_image['pwd'] == $rootdir) {
1484              if (empty($imgs) && !empty($dir_nav['choose_main_txt'])) {
1485                  $str = '<span title="'.$dir_nav['choose_main_title_txt'].'">'
1486                      .$dir_nav['choose_main_txt'].'</span><br />'."\n";
1487              } elseif (empty($imgs)) {
1488                  $str = '<b>'.$dir_nav['main_txt'].'</b><br />'."\n";
1489              } else {
1490                  $str = '<b>'.$dir_nav['main_txt'].'</b>'."\n";
1491              }
1492              if ($dir_nav['fname_ena'] == TRUE && !empty($reqd_image['file'])) {
1493                  $str .= ' '.$dir_nav['path_delim'].' '.$reqd_image['file'];
1494              }
1495              if ($dir_nav['cntr_ena'] == TRUE && $num_imgs > 1) {
1496                  $str .= '&nbsp; (';
1497                  if (! $dir_nav['fname_ena'] == TRUE) {
1498                      $str .= $dir_nav['image_txt'].' ';
1499                  }
1500                  $str .= imageCounter($reqd_image['num']).") \n";
1501              }
1502              continue;
1503          } elseif ($dir == $split_path[$root_pos - 1]) {
1504              $str .= <<<EOT
1505      <a href="$qdig_url?{$extra_param}Qwd=.&amp;Qiv={$reqd_image['view']}&amp;Qis={$reqd_image['size']}$anchor"
1506       title="{$dir_nav['go_to_txt']} {$dir_nav['main_txt']}">{$dir_nav['main_txt']}</a>\n
1507  EOT;
1508              continue;
1509          }
1510          $path = $path.'/'.$dir;
1511          $dirlabel = rawurldecode($dir);
1512          if ($i < $path_pos) {
1513              $str .= <<<EOT
1514      {$dir_nav['path_delim']} <a href="$qdig_url?{$extra_param}Qwd=$path&amp;Qiv={$reqd_image['view']}&amp;Qis={$reqd_image['size']}$anchor"
1515       title="{$dir_nav['go_to_txt']} $dirlabel">$dirlabel</a>
1516  EOT;
1517          } else {
1518          $str .= <<<EOT
1519      {$dir_nav['path_delim']} <span title="{$dir_nav['current_txt']} $dirlabel"><b>$dirlabel</b></span>
1520  EOT;
1521              if ($dir_nav['fname_ena'] == TRUE && $num_imgs > 0) {
1522                  $str .= ' '.$dir_nav['path_delim'].' '.$reqd_image['file'];
1523              }
1524              if ($dir_nav['cntr_ena'] == TRUE && $num_imgs > 1) {
1525                  $str .= '&nbsp; (';
1526                  if (! $dir_nav['fname_ena'] == TRUE) {
1527                      $str .= $dir_nav['image_txt'].' ';
1528                  }
1529                  $str .= imageCounter($reqd_image['num']).") \n";
1530              }
1531              if (empty($imgs) && !empty($subdirs)) {
1532                  if (!empty($dir_nav['choose_sub_txt'])) {
1533                      $str .= '<br /><span title="'.$dir_nav['choose_sub_title_txt']
1534                          .'">'.$dir_nav['choose_sub_txt']. "</span><br />\n";
1535                  } else {
1536                      $str .= "<br />\n";
1537                  }
1538              } elseif (empty($imgs)) {
1539                  $str .= '<br /><br /><span title="'.$dir_nav['empty_dir_title_txt']
1540                      .'">'.$dir_nav['empty_dir_txt']."</span>\n";
1541              }
1542          }
1543      }
1544      return $str;
1545  } // End dirnavPath()

1546  
1547  /**

1548  * Produce navigation links to subdirectory galleries.

1549  */
1550  function subdirLinks($dir_nav)
1551  {
1552      global $imgs, $qdig_url, $extra_param, $anchor, $reqd_image, $subdirs,
1553          $rootdir;
1554      if (isset($imgs)) {
1555          if ($dir_nav['icon'] == 1) {
1556              $icon = '<img src="'.$qdig_url.'?image=cam-icon" alt="camera icon" />&nbsp;';
1557          } else {
1558              $icon = '';
1559          }
1560          $tag1 = '&nbsp;';
1561          $bkt1 = '<b>[</b>';
1562          $bkt2 = '<b>]</b>';
1563          $tag2 = '';
1564      } else {
1565          $icon = '';
1566          $tag1 = '<br />';
1567          $bkt1 = '';
1568          $bkt2 = '';
1569          $tag2 = '<br />';
1570      }
1571      $str = '';
1572      if (isset($subdirs)) {
1573          if ($dir_nav['sort_age'] == TRUE) {
1574              if ($dir_nav['sort_rev'] == TRUE) {
1575                  arsort($subdirs);
1576              } else {
1577                  asort($subdirs);
1578              }
1579          }
1580          foreach($subdirs as $dir => $age_idx) {
1581              $dirurl = rawurlencode($dir);
1582              $dirtxt = str_replace(' ', '&nbsp;', $dir);  // replace spaces

1583              $dirtxt = str_replace("'", '&#39;', $dirtxt);   // replace apostrophes

1584              if ($age_idx < ($dir_nav['dir_is_new'] * 1000)) {
1585                  $newdir = $dir_nav['new_flag'];
1586              } else {
1587                  $newdir = '';
1588              }
1589              $str .= <<<EOT
1590      <span style='white-space:nowrap;'>$tag1$bkt1
1591       <a  href="$qdig_url?{$extra_param}Qwd={$reqd_image['pwd_url']}/$dirurl&amp;Qiv={$reqd_image['view']}&amp;Qis={$reqd_image['size']}$anchor"
1592        title="{$dir_nav['go_to_txt']} $dir">$icon$dirtxt$newdir</a>
1593      $bkt2</span>\n
1594  EOT;
1595          }
1596      }
1597      if ($reqd_image['pwd'] != $rootdir && $dir_nav['updir_ena'] == TRUE) {
1598          $up_one = urlPath(dirname($reqd_image['pwd']));
1599          $str .= <<<EOT
1600      <span style='white-space:nowrap;'>$tag2$tag1$bkt1
1601       <a href="$qdig_url?{$extra_param}Qwd=$up_one&amp;Qiv={$reqd_image['view']}&amp;Qis={$reqd_image['size']}$anchor"
1602        title="{$dir_nav['up_title_txt']}"> {$dir_nav['up_level_txt']}</a>
1603      $bkt2</span>\n
1604  EOT;
1605      }
1606      return $str;
1607  } // End subdirLinks()

1608  
1609  /**

1610  * Build a list of Text Name or Text Numeral Links to the images.

1611  */
1612  function imageTextLinks($nmrl_row)
1613  {
1614      global $imgs, $qdig_url, $extra_param, $anchor, $reqd_image, $namelinks_ena,
1615          $namelinks_small, $namelinks_trunc, $nav_lnk;
1616      if (count($imgs) > 1) {
1617          if ($namelinks_ena == FALSE) {
1618              $str = " <!-- text navigation links -->\n";
1619              $str .= ' <div align="center" style="padding-top:'.$nmrl_row['pad_top'].';">'."\n";
1620              // prepare wrap data

1621              $links_count = 0;
1622              $links_wrap = -1;
1623              $links_wide = 0;
1624              foreach($imgs as $x) {
1625                  $links_count++;
1626                  $links_wrap++;
1627                  if ($links_count > $nmrl_row['maxcount'])
1628                  {
1629                      $links_count = $links_wrap;
1630                      $wrapped = FALSE;
1631                      $links_wide++;
1632                  }
1633                  if ($links_wrap > ($nmrl_row['maxcount'] * ($nmrl_row['softwrap'] / 100))
1634                      && $wrapped == FALSE)
1635                  {
1636                      $links_wrap = 0;
1637                      $wrap[]  = TRUE;
1638                      $wrapped = TRUE;
1639                  } else {
1640                      $wrap[]  = FALSE;
1641                      $wrapped = FALSE;
1642                  }
1643              } // end prepare wrap data

1644              if ($nmrl_row['small'] == TRUE) {
1645                  $tag_bfr_num_lnk = '<small>';
1646                  $tag_aft_num_lnk = '</small>';
1647              } else {
1648                  $tag_bfr_num_lnk = '';
1649                  $tag_aft_num_lnk = '';
1650              }
1651          } else {
1652              $str = '';
1653              if ($namelinks_small == TRUE) {
1654                  $tag_bfr_name_lnk = '<small>';
1655                  $tag_aft_name_lnk = '</small>';
1656              } else {
1657                  $tag_bfr_name_lnk = '';
1658                  $tag_aft_name_lnk = '';
1659              }
1660          }
1661          $imgs_flipped = array_flip($imgs);
1662          foreach($imgs_flipped as $img_num) {
1663              if (isset($wrap)
1664                  && $wrap[$img_num] == TRUE
1665                  && $links_wide > 0
1666                  && $namelinks_ena == FALSE)
1667              {
1668                  $str .= " </div><!-- wrap numerals row -->\n";
1669                  $str .= " <div align=\"center\" style=\"padding-top:{$nmrl_row['pad_top']};\">\n";
1670                  $links_wide--;
1671              }
1672              // pad single- and double-numeral links

1673              if ($img_num < 10) {
1674                  $pad = '&nbsp;';
1675              } else {
1676                  $pad = '';
1677              }
1678              if ($img_num < 100) {
1679                  $pad .= '&nbsp;';
1680              }
1681              $num = $img_num + 1;
1682              $img = $imgs[$img_num];
1683              $imgurl = rawurlencode($img);
1684              $str .= <<<EOT
1685    <a href="$qdig_url?{$extra_param}Qwd={$reqd_image['pwd_url']}&amp;Qif=$imgurl&amp;Qiv={$reqd_image['view']}&amp;Qis={$reqd_image['size']}$anchor"
1686     title="{$nav_lnk['image']} $num - $img">
1687  EOT;
1688              if ($namelinks_ena == TRUE) {
1689                  // Strip extension from filename

1690                  $ext = strrchr($img, '.');
1691                  $img = substr($img, 0, -strlen($ext));
1692                  // Truncate long names

1693                  if (strlen($img) > $namelinks_trunc) {
1694                      $img_lnk_txt = substr($img, 0, $namelinks_trunc - 2).'...';
1695                  } else {
1696                      $img_lnk_txt = $img;
1697                  }
1698                  $str .= <<<EOT
1699  $tag_bfr_name_lnk&nbsp;$img_lnk_txt&nbsp;$tag_aft_name_lnk</a><br />\n
1700  EOT;
1701              } else {
1702                  $num = $img_num + 1;
1703                  $str .= <<<EOT
1704  $tag_bfr_num_lnk$pad$num$pad$tag_aft_num_lnk</a>&nbsp;\n
1705  EOT;
1706              }
1707          }
1708          if ($namelinks_ena == FALSE) {
1709              $str .= " </div>\n";
1710          }
1711          return $str;
1712      }
1713  } //End imageTextLinks()

1714  
1715  /**

1716  * Build a list of Thumbnail Image Links to the images in the current directory.

1717  */
1718  function imageThumbsLinks($thmb_row)
1719  {
1720      global $pwd, $imgs, $qdig_url, $extra_param, $anchor, $reqd_image,
1721          $cnvrt_path, $cnvrt_thmb, $nav_lnk, $thumbs_msg, $thmb_onfly,
1722          $file_exists_disa, $cnvrt_mesgs, $url_base_path, $diag_messages,
1723          $safe_mode, $header;
1724      // set a default maxwidth (if necessary)

1725      if (empty($thmb_row['maxwidth'])) {
1726          $thmb_row['maxwidth'] = 500;
1727      }
1728      // set a default softwrap (if necessary)

1729      if (empty($thmb_row['softwrap'])
1730          || $thmb_row['softwrap'] < 50
1731          || $thmb_row['softwrap'] > 99)
1732      {
1733          $thmb_row['softwrap'] = 75;
1734      }
1735      if (isset($imgs) && count($imgs) > 1) {
1736          $str = " <!-- thumbnail-image links -->\n";
1737          $str .= " <div align=\"center\" style=\"padding-top:2px; white-space:nowrap\">\n";
1738          // prepare wrap data

1739          $thumbs_width = 0;
1740          $thumbs_wrap = 0;
1741          $thumbs_wide = 0;
1742          $num     = 0;
1743          $wrapped = FALSE;
1744          foreach($imgs as $image) {
1745              $thmbs[$image]['image']  = $image;
1746              $thmb_file = $cnvrt_path.'/'.$cnvrt_thmb['prefix'].$image;
1747              $thmbs[$image]['thumb']  = $thmb_file;
1748              $thmb      = $cnvrt_thmb['prefix'].rawurlencode($image);
1749              $thmbs[$image]['cnvurl'] = $url_base_path.urlPath($cnvrt_path)."/$thmb";
1750              $imgurl    = rawurlencode($image);
1751              $thmbs[$image]['imgurl'] = $imgurl;
1752              $num++;
1753              $thmbs[$image]['num'] = $num;
1754              if (($file_exists_disa == TRUE && is_file($thmb_file))
1755                  || file_exists($thmb_file))
1756              {
1757                  $exists = TRUE;
1758                  $thmbs[$image]['exists'] = TRUE;
1759              } else {
1760                  $exists = FALSE;
1761                  $thmbs[$image]['exists'] = FALSE;
1762              }
1763              # RAR... get either the size of the real thumb, or the size it will be

1764              if ($exists == TRUE) {
1765                  if ($diag_messages == TRUE) {
1766                      if ($safe_mode == TRUE) {
1767                          $img_size = predictThumbSize($pwd.'/'.$image);
1768                      } else {
1769                          $img_size = GetImageSize($thmb_file);
1770                      }
1771                  } else {
1772                      if ($safe_mode == TRUE) {
1773                          $img_size = predictThumbSize($pwd.'/'.$image);
1774                      } else {
1775                          $img_size = @GetImageSize($thmb_file);
1776                      }
1777                  }
1778              } elseif ($thmb_onfly == TRUE) {
1779                  # This thumb doesn't exist yet, the URL will be one to make the conversion.

1780                  $img_size = predictThumbSize($pwd.'/'.$image);
1781                  $thmbs[$image]['cnvurl'] = <<<EOT
1782  $qdig_url?{$extra_param}Qwd={$reqd_image['pwd_url']}&amp;Qif=$imgurl&amp;Makethumb=Y
1783  EOT;
1784                  # Add to the thumbs message to let the user know we're going to make on fly.

1785                  if ($cnvrt_thmb['mesg_on'] == TRUE) {
1786                      $thumbs_msg .= "  <small>\n"
1787                          .'   '.$cnvrt_mesgs['generating']
1788                          .$cnvrt_mesgs['thumb'].$cnvrt_mesgs['image_for']
1789                          .$image.$cnvrt_mesgs['on-the-fly'].".\n"
1790                          ."  </small>\n  <br />\n";
1791                  }
1792              } else {
1793                  $img_size = predictThumbSize($pwd.'/'.$image);
1794              }
1795              $thumb_width  = $img_size[0] + ($header['css_thm_brdr_w'] * 2);
1796              $thumbs_width = $thumbs_width + $thumb_width;
1797              $thumbs_wrap  = $thumbs_wrap + $thumb_width;
1798              if ($thumbs_width > $thmb_row['maxwidth']) {
1799                  $thumbs_width = $thumbs_wrap;
1800                  $wrapped = FALSE;
1801                  $thumbs_wide++;
1802              }
1803              $thmbs[$image]['img_size'] = $img_size;
1804              if ($thumbs_wrap > ($thmb_row['maxwidth'] * ($thmb_row['softwrap'] / 100))
1805                  && $wrapped == FALSE)
1806              {
1807                  $thumbs_wrap = 0;
1808                  $thmbs[$image]['wrap'] = TRUE;
1809                  $wrap[]  = TRUE;
1810                  $wrapped = TRUE;
1811              } else {
1812                  $thmbs[$image]['wrap'] = FALSE;
1813                  $wrap[] = FALSE;
1814              }
1815          } // end prepare wrap data

1816          foreach($thmbs as $thm) {
1817              $thumb_id = '';
1818              if ($reqd_image['num'] == $thm['num'] - 1) {
1819                  $thumb_id = 'id="qdig-thumb-current"';
1820              }
1821              if ($thm['wrap'] == TRUE && $thumbs_wide > 0) {
1822                  $str .= " </div><!-- wrap thubms row -->\n"
1823                      ." <div align=\"center\" style=\"padding-top:2px; white-space:nowrap;\">\n";
1824                  $thumbs_wide--;
1825              }
1826              if ($thmb_onfly == FALSE
1827                  && ! (($file_exists_disa == TRUE && is_file($thm['thumb']))
1828                      || file_exists($thm['thumb'])))
1829              {
1830                  $thm['cnvurl'] = "$qdig_url?image=clear-dot";
1831              }
1832              $str .= <<<EOT
1833    <a href="$qdig_url?{$extra_param}Qwd={$reqd_image['pwd_url']}&amp;Qif={$thm['imgurl']}&amp;Qiv={$reqd_image['view']}&amp;Qis={$reqd_image['size']}$anchor"
1834     title="{$nav_lnk['image']} {$thm['num']} - {$thm['image']}"><img class="qdig-thumb" $thumb_id
1835     src="{$thm['cnvurl']}"
1836     alt="{$thm['image']}" {$thm['img_size']['3']} /></a>\n
1837  EOT;
1838          }
1839          $str .= " </div>\n";
1840          return $str;
1841      }
1842  } // End imageThumbsLinks()

1843  
1844  /**

1845  * Produce a Directory Navigation Row.

1846  *

1847  * Contains the path to the current gallery directory and subdirectory links.

1848  */
1849  function dirNav($dir_nav)
1850  {
1851      global $imgs, $qdig_url, $extra_param, $anchor, $reqd_image, $subdirs,
1852          $reqd_img_size_tmp, $chroot_dir;
1853      // Skip it if there are no subdirectories

1854      if (! isset($subdirs)
1855          && ((empty($chroot_dir) && $reqd_image['pwd'] == '.')
1856              || (!empty($chroot_dir) && $reqd_image['pwd'] == './'.$chroot_dir )))
1857      {
1858          return array('str' => '', 'ctrl_bar_ena' => TRUE);
1859      }
1860      // Show it if it's enabled.

1861      if ($dir_nav['enable'] == FALSE) { return array('str' => '', 'ctrl_bar_ena' => TRUE); }
1862      $str = <<<EOT
1863  \n <!-- directory navigation -->
1864   <td colspan="2">
1865   <table summary="Directory Navigation"
1866    cellpadding="0" cellspacing="0" width="{$dir_nav['row_width']}">
1867    <tr>
1868     <td align="center">
1869  EOT;
1870      if ($dir_nav['small'] == TRUE) {
1871          $str .= '    <small>';
1872      }
1873      // Display path to current directory / image.

1874      $str .= dirnavPath($dir_nav);
1875      // Display navigation links to subdirectories.

1876      $str .= subdirLinks($dir_nav);
1877      // Preferences Link

1878      if ($dir_nav['prefs_ena'] == TRUE) {
1879          $ctrl_bar_ena = FALSE;
1880      } else {
1881          $ctrl_bar_ena = TRUE;
1882      }
1883      if ($dir_nav['prefs_ena'] == TRUE && count($imgs) > 1) {
1884          $ctrl_bar_ena = FALSE;
1885          if ($reqd_img_size_tmp == 'Ctrl') {
1886              $qtmp_ctrl = '';
1887          } else {
1888              $qtmp_ctrl = 'Ctrl';
1889          }
1890          $imgurl = rawurlencode($reqd_image['file']);
1891          $str .= <<<EOT
1892      &nbsp; <a href="$qdig_url?{$extra_param}Qwd={$reqd_image['pwd_url']}&amp;Qif=$imgurl&amp;Qiv={$reqd_image['view']}&amp;Qis={$reqd_image['size']}&amp;Qtmp=$qtmp_ctrl$anchor"
1893       title="{$dir_nav['prefs_title_txt']}">{$dir_nav['prefs_txt']}</a>\n
1894  EOT;
1895      }
1896      if ($dir_nav['small'] == TRUE) {
1897          $str .= '    </small>';
1898      }
1899      if (empty($imgs)) {
1900          $tag = '<tr><td>';
1901      } else {
1902          $tag = '<tr>';
1903      }
1904      $str .= <<<EOT
1905     </td>
1906    </tr>
1907   </table>
1908   </td>
1909   </tr>$tag\n
1910  EOT;
1911      return array('str' => $str,    'ctrl_bar_ena' => $ctrl_bar_ena);
1912  } // End dirNav()

1913  
1914  /**

1915  * Display the requested image.

1916  *

1917  * Show the requested image and the caption, if any.

1918  */
1919  function displayImage($reqd_image, $labels)
1920  {
1921      global $get_vars, $imgs, $qdig_url, $rootdir, $extra_param, $anchor,
1922          $cnvrt_path, $reqd_img_size_tmp, $nav_lnk, $cnvrt_size, $subdirs,
1923          $is_readable_disa, $img_link, $caption, $url_base_path, $safe_mode,
1924          $omit_image, $dir_nav;
1925      if (empty($imgs) || @$omit_image == TRUE) { return ''; }
1926      $str = '';
1927      foreach($cnvrt_size as $size_info) {
1928          if ($reqd_img_size_tmp == $size_info['label']
1929              || (! isset($size_string) && $reqd_image['size'] == $size_info['label']))
1930          {
1931              $cnvrt_url   = urlPath($cnvrt_path);
1932              $size_string = $cnvrt_path.'/'.$size_info['prefix'];
1933              $size_str_url = $cnvrt_url.'/'.$size_info['prefix'];
1934              if (! is_file($size_string.$reqd_image['file'])
1935                  || ! ($is_readable_disa == TRUE || is_readable($size_string.$reqd_image['file'])))
1936              {
1937                  $size_string = $reqd_image['pwd'].'/';
1938                  $size_str_url = $reqd_image['pwd_url'].'/';
1939              }
1940          }
1941      }
1942      if (! isset($size_string)) {
1943          $size_string = $reqd_image['pwd'].'/';
1944          $size_str_url = $reqd_image['pwd_url'].'/';
1945      }
1946      $str = "\n <!-- requested image -->\n";
1947      if (@$get_vars['Qtmp'] == 'popup') {
1948          $pad = 'padding:0px;';
1949      } else {
1950          $pad = 'padding-top:2px;';
1951      }
1952      $str .= " <div align=\"center\" style=\"$pad\">\n";
1953      if (! is_file($reqd_image['pwd'].'/'.$reqd_image['file'])) {
1954          $img_file = $imgs[0];
1955          $img_num = 1;
1956      } else {
1957          $img_file = $reqd_image['file'];
1958          $img_num = $reqd_image['num'];
1959      }
1960      $num_imgs = count($imgs);
1961      if ($safe_mode == FALSE) {
1962          $img_size = GetImageSize($size_string.$img_file);
1963      } else {
1964          $img_size[0] = '';
1965          $img_size[3] = '';
1966      }
1967      if ($caption['above'] == TRUE) {
1968          $str .= captionBlock($img_file, $img_size[0]);
1969      }
1970      if ($img_link['wrap_up'] == TRUE 
1971          && $reqd_image['pwd'] == $rootdir)
1972      {
1973          $img_link['wrap_up'] = FALSE;    
1974      }
1975      $img_url = $size_str_url.rawurlencode($img_file);
1976      if (@$get_vars['Qtmp'] == 'popup') {
1977          $str .= <<<EOT
1978    <a href="javascript:window.close();" title='Close Window'
1979    ><img class="qdig-image" src="$url_base_path$img_url"
1980       alt="$img_file" {$img_size['3']} /></a>
1981  EOT;
1982      } else if ($num_imgs > 0) {
1983          if ($reqd_img_size_tmp == $cnvrt_size['4']['label']
1984              || $reqd_img_size_tmp == $cnvrt_size['3']['label']
1985              || $reqd_img_size_tmp == $cnvrt_size['2']['label']
1986              || $reqd_img_size_tmp == $cnvrt_size['1']['label']
1987              || $reqd_img_size_tmp == $cnvrt_size['0']['label']
1988              || ($img_link['full'] == TRUE
1989                  && $size_string != $reqd_image['pwd'].'/')
1990                  && $reqd_image['size'] != $cnvrt_size['4']['label'])
1991          {
1992              if ($reqd_img_size_tmp != $cnvrt_size['4']['label']
1993                  && ! ($reqd_img_size_tmp == $cnvrt_size['3']['label']
1994                      || $reqd_img_size_tmp == $cnvrt_size['2']['label']
1995                      || $reqd_img_size_tmp == $cnvrt_size['1']['label']
1996                      || $reqd_img_size_tmp == $cnvrt_size['0']['label']))
1997              {
1998                  $qtmp_parm  = "&amp;Qtmp={$cnvrt_size['4']['label']}";
1999                  $title_txt1 = $labels['nav']['str1'];
2000                  $title_txt2 = $cnvrt_size['4']['txt'];
2001              } else {
2002                  $qtmp_parm  = '';
2003                  $title_txt1 = $labels['nav']['str1a'];
2004                  $title_txt2 = $cnvrt_size['4']['txt2'];
2005              }
2006              $title    = $title_txt1.$title_txt2.$labels['nav']['str2'];
2007              $file_url = rawurlencode($reqd_image['file']);
2008              $direct   = urlPath($reqd_image['pwd'].'/'.$img_file);
2009              if ($img_link['full'] == TRUE
2010                  && $img_link['file'] == TRUE
2011                  && $size_string != $reqd_image['pwd'].'/'
2012                  && $reqd_image['size'] != $cnvrt_size['4']['label'])
2013              {
2014                  $str .= <<<EOT
2015    <a href="$url_base_path$direct" target="_top" title="$title"><img class="qdig-image" src="$url_base_path$img_url"
2016     alt="$img_file" {$img_size['3']} /></a>\n
2017  EOT;
2018              } else {
2019                  $str .= <<<EOT
2020    <a href="$qdig_url?{$extra_param}Qwd={$reqd_image['pwd_url']}&amp;Qif=$file_url&amp;Qiv={$reqd_image['view']}&amp;Qis={$reqd_image['size']}$qtmp_parm$anchor"
2021     title="$title"><img class="qdig-image" src="$url_base_path$img_url"
2022     alt="$img_file" {$img_size['3']} /></a>\n
2023  EOT;
2024              }
2025          } elseif (is_file($reqd_image['pwd'].'/'.$img_file)
2026              && $img_num == $num_imgs - 1)
2027          {
2028              if ($img_link['next'] == TRUE
2029                  && $img_link['wrap'] == TRUE
2030                  && $img_link['full'] == FALSE)
2031              {
2032                  $first_url = rawurlencode($imgs[0]);
2033                  $str .= <<<EOT
2034    <a href="$qdig_url?{$extra_param}Qwd={$reqd_image['pwd_url']}&amp;Qif=$first_url&amp;Qiv={$reqd_image['view']}&amp;Qis={$reqd_image['size']}$anchor"
2035     title="{$nav_lnk['frst_msg']}"><img class="qdig-image" src="$url_base_path$img_url"
2036     alt="$img_file" {$img_size['3']} /></a>\n
2037  EOT;
2038              } elseif ($img_link['next'] == TRUE
2039                  && $img_link['wrap_up'] == TRUE
2040                  && $img_link['full'] == FALSE)
2041              {
2042                  $wd    = strrchr($reqd_image['pwd_url'], '/');
2043                  $wd_up = substr($reqd_image['pwd_url'], 0, -strlen($wd));
2044                  $str .= <<<EOT
2045    <a href="$qdig_url?{$extra_param}Qwd=$wd_up&amp;Qiv={$reqd_image['view']}&amp;Qis={$reqd_image['size']}$anchor"
2046     title="{$dir_nav['up_level_txt']}"><img class="qdig-image" src="$url_base_path$img_url"
2047     alt="$img_file" {$img_size['3']} /></a>\n
2048  EOT;
2049              } else {
2050                  $str .= '  <img class="qdig-image" src="'.$url_base_path.$img_url
2051                      .'" alt="'.$img_file.'" '.$img_size[3].' />'."\n";
2052              }
2053          } elseif(is_file($reqd_image['pwd'].'/'.$img_file) && $num_imgs > 1) {
2054              if ($img_link['next'] == TRUE && $img_link['full'] == FALSE) {
2055                  $next_url = rawurlencode($imgs[$img_num + 1]);
2056                  $str .= <<<EOT
2057    <a href="$qdig_url?{$extra_param}Qwd={$reqd_image['pwd_url']}&amp;Qif=$next_url&amp;Qiv={$reqd_image['view']}&amp;Qis={$reqd_image['size']}$anchor"
2058     title="{$nav_lnk['next_msg']}"><img class="qdig-image" src="$url_base_path$img_url"
2059     alt="$img_file" {$img_size['3']} /></a>\n
2060  EOT;
2061              } else {
2062                  $str .= '  <img class="qdig-image" src="'.$url_base_path.$img_url
2063                      .'" alt="'.$img_file.'" '.$img_size[3].' />'."\n";
2064              }
2065          }
2066      } elseif(is_file($reqd_image['pwd'].'/'.$img_file)) {
2067          $str .= '  <img class="qdig-image" src="'.$url_base_path.$img_url
2068              .'" alt="'.$img_file.'" '.$img_size[3].' />'."\n";
2069      }
2070      if ($caption['above'] != TRUE) {
2071          $str .= captionBlock($img_file, $img_size[0]);
2072      }
2073      $str .= " </div>\n";
2074      return $str;
2075  } // End displayImage()

2076  
2077  /**

2078  * Produce an Image Caption table.

2079  *

2080  * The block is as wide as the image or else $caption['min_width'] pixels.

2081  */
2082  function captionBlock($img_file, $img_width)
2083  {
2084      global $pwd, $caption, $safe_captions, $caption_path, $touch_captions,
2085          $is_readable_disa, $file_exists_disa, $safe_mode, $diag_messages;
2086      $caption_file = $caption_path.'/'.$img_file.'.txt';
2087      if ($touch_captions == TRUE) {
2088          if ((($file_exists_disa == TRUE && ! is_file($caption_file))
2089                  || ! file_exists($caption_file))
2090              && is_writable($caption_path))
2091          {
2092              touch($caption_file);
2093          }
2094      }
2095      if (is_file($caption_file)
2096          && ($is_readable_disa == TRUE || is_readable($caption_file)))
2097      {
2098          $file_size = filesize($caption_file);
2099          if (! $file_size == 0 ) {
2100              // set caption width

2101              if ($safe_mode == TRUE) {
2102                  $caption_width = '100%';
2103              } elseif ($img_width < $caption['min_width'] ) {
2104                  $caption_width = $caption['min_width'];
2105              } else {
2106                  $caption_width = ($img_width - ($caption['padding'] * 2));
2107              }
2108              if ($caption['left_just'] == TRUE) {
2109                  $txt_align = 'left';
2110              } else {
2111                  $txt_align = 'center';
2112              }
2113              // display caption

2114              $str = " <div title='Image Caption'"
2115                  ." class='qdig-caption' style='width:{$caption_width}px;"
2116                  ." padding:{$caption['padding']}; text-align:$txt_align;'>\n";
2117              $txt = '';
2118              if ($diag_messages == TRUE) {
2119                  $fd = fopen ($caption_file, 'r');
2120              } else {
2121                  $fd = @fopen ($caption_file, 'r');
2122              }
2123              if (!empty($fd)) {
2124                  while (!feof ($fd)) {
2125                      $buffer = fgets($fd, 4096);
2126                      // disallow / allow HTML in captions

2127                      if ($safe_captions == TRUE) {
2128                          $txt .= htmlspecialchars($buffer, ENT_QUOTES);
2129                      } else {
2130                          $txt .= $buffer;
2131                      }
2132                  }
2133              fclose ($fd);
2134              } else {
2135                  return;
2136              }
2137              if ($safe_captions == TRUE && $caption['nl2br'] == TRUE) {
2138                  $str .= nl2br($txt);
2139              } else {
2140                  $str .= $txt;
2141              }
2142              $str .= " </div>";
2143              return $str;
2144          }
2145      }
2146  } // End captionBlock()

2147  
2148  /**

2149  * Produce a `Previous Image'or `Last Image` link for a Gallery Navigation Row.

2150  *

2151  * Link to the previous image, or optionally to the last if this is first image.

2152  */
2153  function prevLink($img_num, $nav_wrap)
2154  {
2155      global $imgs, $qdig_url, $extra_param, $anchor, $reqd_image, $nav_lnk, $styl_grayout;
2156      $num_imgs = count($imgs);
2157      if ($num_imgs > 1) {
2158          if ($img_num < 1 && $nav_wrap == FALSE) {
2159              $txt = $nav_lnk['prv_txt'];
2160              $str = <<<EOT
2161       <span $styl_grayout><b>$txt</b></span>\n
2162  EOT;
2163              return $str;
2164          }
2165          if ($img_num < 1 || $img_num > $num_imgs) {
2166              $last_image_file = $imgs[$num_imgs - 1];
2167              $image = rawurlencode($last_image_file);
2168              $msg = $nav_lnk['last_msg'];
2169              $txt = $nav_lnk['last_txt1'];
2170          } else {
2171              $image = rawurlencode($imgs[$img_num - 1]);
2172              $msg = $nav_lnk['prv_msg'];
2173              $txt = $nav_lnk['prv_txt'];
2174          }
2175          $str = <<<EOT
2176       <a href="$qdig_url?{$extra_param}Qwd={$reqd_image['pwd_url']}&amp;Qif=$image&amp;Qiv={$reqd_image['view']}&amp;Qis={$reqd_image['size']}$anchor"
2177        title="$msg">$txt</a>\n
2178  EOT;
2179          return $str;
2180      }
2181  } // End prevLink()

2182  
2183  /**

2184  * Produce a `Next Image' or `First Image' link for a Gallery Navigation Row.

2185  *

2186  * Link to the next image, or optionally to the first if this is the last image.

2187  */
2188  function nextLink($nav_wrap)
2189  {
2190      global $imgs, $qdig_url, $extra_param, $anchor, $reqd_image,
2191          $nav_lnk, $styl_grayout;
2192      $num_imgs = count($imgs);
2193      if ($reqd_image['num'] + 1 == $num_imgs && $nav_wrap == FALSE) {
2194          $str = <<<EOT
2195       <span $styl_grayout><b>{$nav_lnk['next_txt']}</b></span>\n
2196  EOT;
2197          return $str;
2198      }
2199      if ($num_imgs > 1) {
2200          if ($reqd_image['num'] + 1 == $num_imgs) {
2201              $image = rawurlencode($imgs[0]);
2202              $msg = $nav_lnk['frst_msg'];
2203              $txt = $nav_lnk['frst_txt1'];
2204          } else {
2205              $image = rawurlencode($imgs[$reqd_image['num'] + 1]);
2206              $msg = $nav_lnk['next_msg'];
2207              $txt = $nav_lnk['next_txt'];
2208          }
2209          $str = <<<EOT
2210       <a href="$qdig_url?{$extra_param}Qwd={$reqd_image['pwd_url']}&amp;Qif=$image&amp;Qiv={$reqd_image['view']}&amp;Qis={$reqd_image['size']}$anchor"
2211        title="$msg">$txt</a>\n
2212  EOT;
2213          return $str;
2214      }
2215  } // End nextLink()

2216  
2217  /**

2218  * Produce a `Last Image' (` >>| ') link for a Gallery Navigation Row.

2219  */
2220  function lastLink($reqd_image)
2221  {
2222      global $imgs, $qdig_url, $extra_param, $anchor, $reqd_image, $nav_lnk,
2223          $styl_grayout;
2224      $num_imgs = count($imgs);
2225      if ($num_imgs > 1) {
2226          if ($reqd_image['num'] + 1 == $num_imgs) {
2227              $str = <<<EOT
2228       <span $styl_grayout><b>{$nav_lnk['last_txt2']}</b></span>\n
2229  EOT;
2230          } else {
2231              $last_image_file = $imgs[count($imgs) - 1];
2232              $file = rawurlencode($last_image_file);
2233              $str = <<<EOT
2234       <a href="$qdig_url?{$extra_param}Qwd={$reqd_image['pwd_url']}&amp;Qif=$file&amp;Qiv={$reqd_image['view']}&amp;Qis={$reqd_image['size']}$anchor"
2235        title="{$nav_lnk['last_msg']}">{$nav_lnk['last_txt2']}</a>\n
2236  EOT;
2237          }
2238          return $str;
2239      }
2240  } // End lastLink()

2241  
2242  /**

2243  * Build a `First Image' (` |<< ') link for a Gallery Navigation Row.

2244  */
2245  function firstLink($img_num)
2246  {
2247      global $imgs, $qdig_url, $extra_param, $anchor, $reqd_image, $nav_lnk,
2248          $styl_grayout;
2249      if (count($imgs) > 1) {
2250          if ($img_num == 0) {
2251              $str = <<<EOT
2252       <span $styl_grayout><b>{$nav_lnk['frst_txt2']}</b></span>\n
2253  EOT;
2254          } else {
2255              $image = rawurlencode($imgs[0]);
2256              $str = <<<EOT
2257       <a href="$qdig_url?{$extra_param}Qwd={$reqd_image['pwd_url']}&amp;Qif=$image&amp;Qiv={$reqd_image['view']}&amp;Qis={$reqd_image['size']}$anchor"
2258        title="{$nav_lnk['frst_msg']}">{$nav_lnk['frst_txt2']}</a>\n
2259  EOT;
2260          }
2261          return $str;
2262      }
2263  } // End firstLink()

2264  
2265  /**

2266  * Build a Gallery Navigation Row table.

2267  *

2268  * Includes Prev/Next links and/or Home link, as set by user settings.

2269  */
2270  function navRow($nav)
2271  {
2272      global $imgs, $reqd_image, $cnvrt_path, $prev_img_msg, $next_img_msg,
2273          $img_sz_labels, $dir_nav, $is_readable_disa;
2274      if ($nav['enable'] == FALSE) { return ''; }
2275      $str = '';
2276      if (! is_dir($cnvrt_path)
2277          || ! ($is_readable_disa == TRUE || is_readable($cnvrt_path)))
2278      {
2279          $nav['sizer'] = FALSE;
2280          $nav['full_link'] = FALSE;
2281      }
2282      if ($nav['sizer'] == TRUE) { // Sizer overrides Full Size link.
2283          $nav['full_link'] = FALSE;
2284      }
2285      $nav_full =  navFull($nav['sml_txt'], $img_sz_labels['nav']);
2286      if ($nav_full['show_full_link'] == FALSE) { $nav['full_link'] = FALSE; }
2287      if ($dir_nav['cntr_ena'] == TRUE && $dir_nav['enable'] == TRUE) {
2288          $nav['cntr'] = FALSE;
2289      }
2290      // Don't build a table if there's no content

2291      $num_imgs = count($imgs);
2292      if ($num_imgs > 1
2293              && (($nav['prv_next'] == TRUE)
2294                  || ($nav['frst_last'] == TRUE)
2295                  || ($nav['cntr'] == TRUE))
2296          || ($num_imgs > 0
2297              && ($nav['sizer'] == TRUE) || ($nav['full_link'] == TRUE))
2298      )
2299      {
2300          if ($nav['sml_txt'] == TRUE) {
2301              $tag_bfr_lnk = '<small>';
2302              $tag_aft_lnk = '</small>';
2303          } else {
2304              $tag_bfr_lnk = '';
2305              $tag_aft_lnk = '';
2306          }
2307          if (isset($nav['pad_top'])) {
2308              $pad_top = $nav['pad_top'];
2309          } else{
2310              $pad_top = '0px';
2311          }
2312          $str = <<<EOT
2313  \n <!-- gallery navigation -->
2314   <div align="center" style="padding-top:$pad_top;">
2315    <table summary="Gallery Navigation"
2316     width="{$nav['width']}" cellpadding="1" cellspacing="0">
2317     <tr>\n
2318  EOT;
2319          if ($num_imgs > 1) {
2320              if ($nav['frst_last'] == TRUE) {
2321                  $str .= "    <td width=\"5%\" style='white-space:nowrap; text-align:center;'>$tag_bfr_lnk\n"
2322                      .firstLink($reqd_image['num'])
2323                      ."    $tag_aft_lnk</td>\n";
2324              }
2325              if ($nav['prv_next'] == TRUE) {
2326                  $str .= "    <td width=\"14%\" style='white-space:nowrap; text-align:center;'>$tag_bfr_lnk\n"
2327                      .prevLink($reqd_image['num'], $nav['wrap'])
2328                      ."    $tag_aft_lnk</td>\n";
2329              }
2330              if ($nav['cntr'] == TRUE
2331                  && ( $nav['sizer'] == TRUE || $nav['full_link'] == TRUE))
2332              {
2333                  $str .= "    <td width=\"10%\" style='white-space:nowrap; text-align:center;'>\n";
2334              } elseif ($nav['cntr'] == TRUE ) {
2335                  $str .= "    <td width=\"30%\" style='white-space:nowrap; text-align:center;'>\n";
2336              }
2337              if ($nav['cntr'] == TRUE) {
2338                  if ($nav['cntr_bold'] == TRUE) {
2339                      $bold_before = '<b>';
2340                      $bold_after = '</b>';
2341                  } else {
2342                      $bold_before = '';
2343                      $bold_after = '';
2344                  }
2345                  $str .= '     '.$tag_bfr_lnk.$bold_before.imageCounter($reqd_image['num']).$bold_after.$tag_aft_lnk."\n"
2346                      ."    </td>\n";
2347              }
2348          }
2349          if (($nav['cntr'] == TRUE && $num_imgs > 1)
2350              && ($nav['sizer'] == TRUE || $nav['full_link'] == TRUE ))
2351          {
2352              $str .= "    <td width=\"20%\" style='white-space:nowrap; text-align:center;'> &nbsp;";
2353          } elseif ($nav['sizer'] == TRUE || $nav['full_link'] == TRUE ) {
2354              $str .= "    <td width=\"30%\" style='white-space:nowrap; text-align:center;'>\n";
2355          }
2356          if ($nav['sizer'] == TRUE) {
2357              $str .= navSize($nav['sml_txt'], $img_sz_labels['nav'])."    </td>\n";
2358          }
2359          if ($nav['sizer'] == FALSE
2360              && $nav['full_link'] == TRUE)
2361          {
2362              $str .= $nav_full['str']."    </td>\n";
2363          }
2364          if ($num_imgs > 1) {
2365              if ($nav['prv_next'] == TRUE) {
2366                  $str .= "    <td width=\"14%\" style='white-space:nowrap; text-align:center;'>$tag_bfr_lnk\n"
2367                      .nextLink($nav['wrap'])."    $tag_aft_lnk</td>\n";
2368              }
2369              if ($nav['frst_last'] == TRUE) {
2370                  $str .= "    <td width=\"5%\" style='white-space:nowrap; text-align:center;'>$tag_bfr_lnk\n"
2371                      .lastLink($reqd_image['num'])."    $tag_aft_lnk</td>\n";
2372              }
2373          }
2374          $str .= "   </tr>\n  </table>\n </div>\n";
2375      }
2376      return $str;
2377  } // End navRow()

2378  
2379  /**

2380  * Produce a Gallery Footer Row table.

2381  *

2382  * Includes Site Home Link, Copyright, and Quig Home link.

2383  */
2384  function footerRow()
2385  {
2386      global $imgs, $reqd_image, $site_lnk_url, $site_lnk_title, $copyright,
2387          $qdig_homelink, $footer, $rootdir;
2388      if (@$footer['omit'] == TRUE) { return ''; }
2389      if (empty($site_lnk_url)
2390          && empty($site_lnk_title)
2391          && $qdig_homelink['ena'] == FALSE)
2392      {
2393          return '';
2394      }
2395      if (empty($imgs) && $reqd_image['pwd'] == $rootdir) {
2396          $tag = '<small><small><br /></small></small>'."\n ";
2397      } else {
2398          $tag = '';
2399      }
2400      if (!empty($site_lnk_url) && !empty($site_lnk_title)) {
2401          $site_lnk_on = TRUE;
2402          $copyright_align_str = ' align="center"';
2403      } else {
2404          $site_lnk_on = FALSE;
2405          $copyright_align_str = ' align="left"';
2406      }
2407      if (count($imgs) < 1) {
2408          unset($copyright['txt']);
2409      }
2410      if (!empty($copyright['txt'])) {
2411          $copyright_on = TRUE;
2412      } else {
2413          $copyright_on = FALSE;
2414      }
2415      if ($qdig_homelink['ena'] == FALSE && $site_lnk_on == TRUE) {
2416          $copyright_align_str = ' align="right"';
2417      } elseif ($qdig_homelink['ena'] == FALSE) {
2418          $copyright_align_str = ' align="center"';
2419      }
2420      if ($site_lnk_on == FALSE
2421          && $copyright_on == FALSE
2422          && $qdig_homelink['ena'] == TRUE)
2423      {
2424          $qdighome_alone = TRUE;
2425      } else {
2426          $qdighome_alone = FALSE;
2427      }
2428      // don't produce an empty table

2429      if ($site_lnk_on == TRUE
2430          || $copyright_on == TRUE
2431          || $qdig_homelink['ena'] == TRUE)
2432      {
2433          $str = <<<EOT
2434  \n <!-- table footer row of image dispaly area -->
2435   $tag<div align="center" style="padding-top:{$footer['pad_top']};">
2436    <table summary="Gallery Footer"
2437     width="100%" cellpadding="1" cellspacing="0">
2438     <tr>\n
2439  EOT;
2440          if ($site_lnk_on == TRUE) {
2441              $str .= "    <td width=\"20%\" nowrap=\"nowrap\">\n"
2442                  .siteHomeLink($site_lnk_url, $site_lnk_title)."    </td>\n";
2443          }
2444          if ($copyright_on == TRUE) {
2445              $str .= '    <td width=" 60%" nowrap="nowrap" '.$copyright_align_str.">\n"
2446                  .showCopyright($copyright)."    </td>\n";
2447          }
2448          if ($qdig_homelink['ena'] == TRUE) {
2449              $str .= "    <td width=\" 20%\" nowrap=\"nowrap\">\n"
2450                  .qdigHomelink($qdighome_alone)."    </td>\n";
2451          }
2452          $str .= "   </tr>\n  </table>\n </div>\n";
2453          return $str;
2454      }
2455  } // End footerRow()

2456  
2457  /**

2458  * Display either the Text or Thumbnail Image Links.

2459  */
2460  function displayImageLinks($thmb_row, $nmrl_row)
2461  {
2462      global $thmbs_ena, $convert_readable;
2463      if ($thmbs_ena == TRUE && $convert_readable == TRUE) {
2464          $str = imageThumbsLinks($thmb_row);
2465      } else {
2466          $str = imageTextLinks($nmrl_row);
2467      }
2468      return $str;
2469  } // End displayImageLinks()

2470  
2471  /**

2472  * Produce a `Default View' chooser for a Gallery Control Bar.

2473  */
2474  function controlView($ctrl_links_mesg)
2475  {
2476      global $imgs, $qdig_url, $extra_param, $anchor, $reqd_image, $thmb_enable,
2477          $styl_grayout, $ctrl_bar, $convert_readable, $namelinks_disa;
2478      if (count($imgs) < 2) { return; }
2479      $reqd_file = rawurlencode($reqd_image['file']);
2480      $str = "   <td align=\"center\">\n";
2481      if ($ctrl_bar['small'] == TRUE) {
2482          $str .= "    <div style=\"padding-top:2px;\"><small>\n";
2483      } else {
2484          $str .= "    <div style=\"padding-top:2px;\">\n";
2485      }
2486      $str .= "     {$ctrl_links_mesg['links_style']} <b>[</b>\n";
2487      if ( $reqd_image['view'] != 'thumbs'
2488          && $convert_readable == TRUE
2489          && $thmb_enable == TRUE)
2490      {
2491          $str .= <<<EOT
2492       <a href="$qdig_url?{$extra_param}Qwd={$reqd_image['pwd_url']}&amp;Qif=$reqd_file&amp;Qiv=thumbs&amp;Qis={$reqd_image['size']}$anchor"
2493        title="{$ctrl_links_mesg['thumbs_msg']}">{$ctrl_links_mesg['thumbs_txt']}</a> |\n
2494  EOT;
2495      } elseif ($convert_readable == TRUE && $thmb_enable == TRUE) {
2496          $txt = $ctrl_links_mesg['thumbs_txt'];
2497          $str .= <<<EOT
2498       <span $styl_grayout><b>$txt</b></span> |\n
2499  EOT;
2500      }
2501      if ( $reqd_image['view'] != 'name' && $namelinks_disa == FALSE ) {
2502          $str .= <<<EOT
2503       <a href="$qdig_url?{$extra_param}Qwd={$reqd_image['pwd_url']}&amp;Qif=$reqd_file&amp;Qiv=name&amp;Qis={$reqd_image['size']}$anchor"
2504        title="{$ctrl_links_mesg['names_msg']}">{$ctrl_links_mesg['names_txt']}</a> |\n
2505  EOT;
2506      } elseif ($namelinks_disa == FALSE) {
2507          $txt = $ctrl_links_mesg['names_txt'];
2508          $str .= <<<EOT
2509       <span $styl_grayout><b>$txt</b></span> |\n
2510  EOT;
2511      }
2512      if ( $reqd_image['view'] != 'num') {
2513          $str .= <<<EOT
2514       <a href="$qdig_url?{$extra_param}Qwd={$reqd_image['pwd_url']}&amp;Qif=$reqd_file&amp;Qiv=num&amp;Qis={$reqd_image['size']}$anchor"
2515        title="{$ctrl_links_mesg['nums_msg']}">{$ctrl_links_mesg['nums_txt']}</a> |\n
2516  EOT;
2517      } else {
2518          $txt = $ctrl_links_mesg['nums_txt'];
2519          $str .= <<<EOT
2520       <span $styl_grayout><b>$txt</b></span> |\n
2521  EOT;
2522      }
2523      if ( $reqd_image['view'] != 'none') {
2524          $str .= <<<EOT
2525       <a href="$qdig_url?{$extra_param}Qwd={$reqd_image['pwd_url']}&amp;Qif=$reqd_file&amp;Qiv=none&amp;Qis={$reqd_image['size']}$anchor"
2526        title="{$ctrl_links_mesg['none_msg']}">{$ctrl_links_mesg['none_txt']}</a>\n
2527  EOT;
2528      } else {
2529          $txt = $ctrl_links_mesg['none_txt'];
2530          $str .= <<<EOT
2531       <span $styl_grayout><b>$txt</b></span>\n
2532  EOT;
2533      }
2534      $str .= "     <b>]</b>\n";
2535      if ($ctrl_bar['small'] == TRUE) {
2536          $str .= "    </small></div>\n";
2537      } else {
2538          $str .= "    </div>\n";
2539      }
2540      $str .= "   </td>\n";
2541      return $str;
2542  } // End controlView()

2543  
2544  /**

2545  * Produce a `Default Size' chooser for a Gallery Control Bar.

2546  */
2547  function controlSize($labels)
2548  {
2549      global $imgs, $qdig_url, $extra_param, $anchor, $reqd_image, $cnvrt_path,
2550          $styl_grayout, $ctrl_bar, $disp_size, $cnvrt_size, $is_readable_disa;
2551      if (count($imgs) < 2) { return; }
2552      if (! is_dir($cnvrt_path)
2553          || ! ($is_readable_disa == TRUE || is_readable($cnvrt_path)))
2554      {
2555          return;
2556      }
2557      $reqd_file = rawurlencode($reqd_image['file']);
2558      if ($ctrl_bar['vw_ctrl'] == FALSE) {
2559          $str = "   <td align=\"center\" nowrap=\"nowrap\">\n";
2560      } else {
2561          $str = "   <td nowrap=\"nowrap\">\n";
2562      }
2563      if ($ctrl_bar['small'] == TRUE) {
2564          $str .= "    <div style=\"padding-top:2px;\"><small>\n";
2565      } else {
2566          $str .= "    <div style=\"padding-top:2px;\">\n";
2567      }
2568      $x = 0;
2569      foreach($cnvrt_size as $size_info) {
2570          if ($reqd_image['size'] != $size_info['label']
2571              && $disp_size[$x] == TRUE)
2572          {
2573              $title = $labels['str1'].$cnvrt_size[$x]['txt'].$labels['str2'];
2574              $size[] = <<<EOT
2575       <a href="$qdig_url?{$extra_param}Qwd={$reqd_image['pwd_url']}&amp;Qif=$reqd_file&amp;Qiv={$reqd_image['view']}&amp;Qis={$size_info['label']}$anchor"
2576        title="$title">{$size_info['label']}</a>
2577  EOT;
2578          } elseif ($disp_size[$x] == TRUE) {
2579              $size[] = <<<EOT
2580       <span $styl_grayout><b>{$size_info['label']}</b></span>
2581  EOT;
2582          }
2583          $x++;
2584      }
2585      if (!empty($size)) {
2586          $str .= "     &nbsp;{$labels['default_size']} <b>[</b>\n";
2587          $num_sizes = count($size);
2588          $i = 0;
2589          foreach($size as $size_str) {
2590              $str .= $size_str;
2591              if ($i < ($num_sizes - 1)) {
2592                  $str .= " |\n";
2593              }
2594              $i++;
2595          }
2596          $str .= "\n     <b>]</b>\n";
2597      } else {
2598          $str .= '&nbsp;';
2599      }
2600      if ($ctrl_bar['small'] == TRUE) {
2601          $str .= "    </small></div>\n";
2602      } else {
2603          $str .= "    </div>\n";
2604      }
2605      $str .= "   </td>\n";
2606      return $str;
2607  } // End controlSize()

2608  
2609  /**

2610  * Produce a Size Chooser for a Gallery Navigation Row.

2611  */
2612  function navSize($small_b, $labels)
2613  {
2614      global $imgs, $qdig_url, $extra_param, $anchor, $reqd_image, $cnvrt_path,
2615          $reqd_img_size_tmp, $styl_grayout, $disp_size, $cnvrt_size,
2616          $valid_sizes, $is_readable_disa;
2617      if (! is_dir($cnvrt_path)
2618          || ! ($is_readable_disa == TRUE || is_readable($cnvrt_path)))
2619      {
2620          return;
2621      }
2622      if ($small_b == TRUE) {
2623          $small_on = "<small>";
2624          $small_off = "</small>";
2625      } else {
2626          $small_on = '';
2627          $small_off = '';
2628      }
2629      if (!empty($reqd_img_size_tmp)) {
2630          $size_displayed = $reqd_img_size_tmp;
2631      } else {
2632          $size_displayed = $reqd_image['size'];
2633      }
2634      $n = count($disp_size) - 1;
2635      $full_size = $cnvrt_size[$n]['label'];
2636      $str = $small_on.'<b>[</b>'.$small_off."\n";
2637      $num_sizes = count($disp_size);
2638      $num_valid = count($valid_sizes);
2639      foreach($disp_size as $i => $enabled) {
2640          $size = $cnvrt_size[$i]['label'];
2641          if (!in_array($size, $valid_sizes)) { continue; } // skip

2642          if ($size == $reqd_image['size']) {
2643              $qtmp_txt = '';
2644          } else {
2645              $qtmp_txt = $size;
2646          }
2647          $title = $labels['str1'].$cnvrt_size[$i]['txt'].$labels['str2'];
2648          $file  = $cnvrt_path.'/'.$cnvrt_size[$i]['prefix'].$reqd_image['file'];
2649          $file2 = $cnvrt_path.'/'.@$cnvrt_size[$z]['prefix'].$reqd_image['file'];
2650          $z=$i;
2651          if ($size == $reqd_image['size'] && is_file($file2)) { $foo = TRUE; }
2652          if ($size == $size_displayed && is_file($file)) { $bar = TRUE; }
2653          if (is_file($file) && !is_file($file2)) { $bim = TRUE; }
2654          $reqd_file = rawurlencode($reqd_image['file']);
2655          if ((is_file($file) || is_file($file2) || $size == $full_size && @$bar == TRUE && $bim == FALSE)
2656              && $size != $size_displayed)
2657          {
2658              $size_txt[] = <<<EOT
2659       $small_on<a href="$qdig_url?{$extra_param}Qwd={$reqd_image['pwd_url']}&amp;Qif=$reqd_file&amp;Qiv={$reqd_image['view']}&amp;Qis={$reqd_image['size']}&amp;Qtmp={$qtmp_txt}$anchor"
2660        title="$title">{$size}</a>$small_off
2661  EOT;
2662          } else {
2663              $size_txt[] = <<<EOT
2664       $small_on<span $styl_grayout><b>{$size}</b></span>$small_off
2665  EOT;
2666          }
2667      }
2668      $num_to_display = count($size_txt);
2669      foreach ($size_txt as $txt) {
2670          $str .= $txt;
2671          $num_to_display--;
2672          if ($num_to_display > 0) {
2673              $str .= " |\n";
2674          } else {
2675              $str .= "\n     ".$small_on.'<b>]</b>'.$small_off."\n";
2676          }
2677      }
2678      return $str;
2679  } // End navSize()

2680  
2681  /**

2682  * Produce an `Full Size' chooser for a Gallery Navigation Row.

2683  */
2684  function navFull($small_b, $labels)
2685  {
2686      global $imgs, $qdig_url, $extra_param, $anchor, $reqd_image, $cnvrt_path,
2687          $reqd_img_size_tmp, $styl_grayout, $disp_size, $cnvrt_size,
2688          $is_readable_disa;
2689      if (! isset($reqd_image['file'])
2690          || ! is_dir($cnvrt_path)
2691          || ! ($is_readable_disa == TRUE || is_readable($cnvrt_path)))
2692      {
2693          return; // no use, so never mind

2694      }
2695      if ($small_b == TRUE) {
2696          $small_on = '<small>';
2697          $small_off = '</small>';
2698      } else {
2699          $small_on = '';
2700          $small_off = '';
2701      }
2702      $size_info = $cnvrt_size['4'];
2703      $full_label = $size_info['label'];
2704      if ($reqd_img_size_tmp != $full_label
2705          && $reqd_image['size'] != $full_label)
2706      {
2707          $show_full_link = TRUE;
2708      } else {
2709          $show_full_link = FALSE;
2710      }
2711      $title = $labels['str1'].$size_info['txt'].$labels['str2'];
2712      foreach($cnvrt_size as $size_info) {
2713          if ($reqd_image['size'] == $size_info['label'] ) {
2714              $file = $cnvrt_path.'/'.$size_info['prefix'].$reqd_image['file'];
2715              if (! is_file($file)) {
2716                  $show_full_link = FALSE;
2717              }
2718          }
2719      }
2720      $file = $reqd_image['pwd'].'/'.$reqd_image['file'];
2721      if (is_file($file)
2722          && ($is_readable_disa == TRUE || is_readable($file))
2723          && $show_full_link == TRUE)
2724      {
2725          $reqd_file = rawurlencode($reqd_image['file']);
2726          $str = <<<EOT
2727       $small_on<a href="$qdig_url?{$extra_param}Qwd={$reqd_image['pwd_url']}&amp;Qif=$reqd_file&amp;Qiv={$reqd_image['view']}&amp;Qis={$reqd_image['size']}&amp;Qtmp=$full_label$anchor"
2728        title="$title">{$size_info['txt']}</a>$small_off\n
2729  EOT;
2730      } else {
2731          $str = "&nbsp;\n";
2732      }
2733      return array('str' => $str, 'show_full_link' => $show_full_link);
2734  } // End navFull()

2735  
2736  /**

2737  * Produce a Gallery Sidebar if appropriate.

2738  */
2739  function sideBar($namelinks_ena, $thmbs_ena, $bg_clr, $margin_top, $height)
2740  {
2741      global $imgs;
2742      if (count($imgs) < 2) { return; } // no sidebar if no image links

2743      if (empty($height) || $height == 'auto') {
2744          $height = 'auto';
2745          $scroll = '';
2746          $valign = 'top';
2747      } else {
2748          $scroll = 'overflow:auto;';
2749          $valign = 'top';
2750      }
2751      if ($namelinks_ena == TRUE) {
2752          $arr['sb_on'] = TRUE;
2753          $str = <<<EOT
2754  \n <!-- Begin Qdig sidebar -->
2755   <td valign="$valign">
2756   <div style="margin-top:$margin_top; background-color:$bg_clr; height:$height;
2757    width:auto; $scroll white-sapce:nowrap; padding-top:2px; padding-bottom:2px;">\n
2758  EOT;
2759          $str .= displayImageLinks('', '');
2760          $str .= " </div>\n </td>\n <!-- End Qdig sidebar -->\n";
2761          $arr['str'] = $str;
2762          return $arr;
2763      }
2764  } // End sideBar()

2765  
2766  /**

2767  * Produce a `Site Home' link for the Gallery Footer.

2768  */
2769  function siteHomeLink($site_lnk_url, $site_lnk_title)
2770  {
2771      if (!empty($site_lnk_url) && !empty ($site_lnk_title)) {
2772          global $site_link_fnt_size;
2773          $str = <<<EOT
2774       <div title="Site Link" style="font-size:$site_link_fnt_size;">
2775        <a href="$site_lnk_url" title="$site_lnk_title">$site_lnk_title</a>&nbsp;
2776       </div>\n
2777  EOT;
2778          return $str;
2779      }
2780  } // End siteHomeLink()

2781  
2782  /**

2783  * Produce the copyright text for the Gallery Footer.

2784  */
2785  function showCopyright($copyright)
2786  {
2787      if (!empty($copyright['txt'])) {
2788          $str = <<<EOT
2789       <div title="Copyright Text" style="color:{$copyright['color']};
2790        font-size: {$copyright['fnt_size']}; font-weight:normal;">
2791        {$copyright['txt']}
2792       </div>\n
2793  EOT;
2794          return $str;
2795      }
2796  } // End showCopyright()

2797  
2798  /**

2799  * Produce an Admin link to the current image's admin.php caption-edit page.

2800  */
2801  function adminLink($admin)
2802  {
2803      global $reqd_image, $php_self, $caption_path;
2804      $str = '';
2805      if (isset($reqd_image['file'])
2806          && (!empty($admin['script_file']) || !empty($admin['full_url']))
2807          && (!empty($admin['full_url']) || @is_file($admin['script_file']))
2808          && !empty($php_self))
2809      {
2810          if (empty($admin['full_url'])) {
2811              $admin_script_dir = substr(urlPath(dirname($php_self)), 1);
2812              $admin['full_url'] = $admin_script_dir.'/'.$admin['script_file'];
2813          }
2814          $admin_caption_dir = substr(urlPath($caption_path), 1); // No leading '.'  

2815          $admin_img = rawurlencode($reqd_image['file']);
2816          $str = <<<EOT
2817  \n      {$admin['before_link']}<a href="{$admin['full_url']}?op=details&amp;D=$admin_caption_dir&amp;F=$admin_img.txt&amp;R=Qdig"
2818         title="{$admin['link_title']}" style="color:{$admin['color']};
2819         font-weight:normal;">{$admin['link_text']}</a>{$admin['after_link']}
2820  EOT;
2821      }
2822      return $str;
2823  } // End adminLink()

2824  
2825  /**

2826  * Produce a link to the Qdig script home page for the Gallery Footer.

2827  */
2828  function qdigHomelink($qdighome_alone)
2829  {
2830      global $qdig_homelink;
2831      if ($qdig_homelink['ena'] == TRUE) {
2832          global $site_lnk_url, $reqd_image;
2833          if ($qdighome_alone == TRUE
2834              || (empty($site_lnk_url) && empty($reqd_image['file'])))
2835          {
2836              $txt_align = "center";
2837          } else {
2838              $txt_align = "right";
2839          }
2840          $str = <<<EOT
2841       <div title="Qdig Home Link"
2842        style="color:{$qdig_homelink['color']}; font-size:{$qdig_homelink['fnt_size']}; text-align:$txt_align;">
2843        Gallery by
2844        <a href="http://qdig.sourceforge.net/"
2845         title="Qdig Gallery Script Home Page" style="color:{$qdig_homelink['color']};
2846         font-weight:normal;">Qdig</a>\n     </div>\n
2847  EOT;
2848          return $str;
2849      }
2850  } // End qdigHomelink()

2851  
2852  /*

2853  +---------+

2854  |  Logic  |

2855  +---------+

2856  */
2857  
2858  /**

2859  * Image is a popup target (experimental).

2860  */
2861  if (@$get_vars['Qtmp'] == 'popup') {
2862      $header['nav_links'] = FALSE;
2863      //$footer['omit']    = TRUE;

2864  }
2865  
2866  /**

2867  * Set base directory if using alternate base paths

2868  */
2869  if (!empty($fs_base_path)) {
2870      $base_dir = realpath($fs_base_path);
2871      if (!empty($base_dir)) {
2872          $orig_wd = getcwd();
2873          chdir($base_dir);
2874      }
2875  }
2876  
2877  /**

2878  * Start creating diagnostic messages

2879  */
2880  if ($diag_messages == TRUE) {
2881      $diag_mesgs = "<p><small>\n<b>{$lang['diag_messages']}:</b><br />\n";
2882      error_reporting(E_ALL);
2883  } else {
2884      $diag_mesgs = '';
2885  }
2886  
2887  /**

2888  * $chroot_dir sanity check

2889  */
2890  if (!empty($chroot_dir)) {
2891      $rootdir = cleanPath($chroot_dir);
2892  } else {
2893      $rootdir = '.';
2894      $chroot_dir = '';
2895  }
2896  if (!@is_dir($rootdir)) {
2897      exit("<html>\n <body>
2898      Chroot directory <b>$chroot_dir</b> doesn't exist.<br />
2899      Check gallery script configuration.\n </body>\n</html>");
2900  }
2901  
2902  /**

2903  * Establish working directory.

2904  */
2905  if (!empty($get_vars['Qwd'])) {
2906      if (strlen($get_vars['Qwd']) > $pathname_maxlen
2907          || (strlen($get_vars['Qwd']) > 1 && $get_vars['Qwd'][0] == '.' && $get_vars['Qwd'][1] == '.')) {
2908          securityExit('Pathname (Qwd=) is too long or starts with "..".');
2909      }
2910      $pwd_tmp = cleanPath($get_vars['Qwd']);
2911  } else {
2912      $pwd_tmp = '.';
2913  }
2914  if (strlen($pwd_tmp) <= strlen($rootdir)) {
2915      $pwd = $rootdir;
2916  } elseif (strpos($pwd_tmp, $rootdir) === 0) {
2917      $pwd = rawurldecode($pwd_tmp);
2918  }
2919  if (! is_dir($pwd)
2920      || ! ($is_readable_disa == TRUE || is_readable($pwd)))
2921  {
2922      $pwd = $rootdir;
2923  }
2924  if ($extra_paranoia == TRUE
2925      && (strpos(stripslashes(rawurldecode($pwd)), '..')
2926          || empty ($pwd)
2927          || $pwd[0] != '.'
2928          || (strlen($pwd) > 1 && $pwd[1] == '.')))
2929  {
2930      securityExit('Updir ("..") is not allowed in a pathname (Qwd=).');
2931  }
2932  // Encode $pwd for use in URLs.

2933  $pwd_url = urlPath($pwd);
2934  // Sanitize URL base path.

2935  if (!empty($url_base_path)) {
2936      $url_base_path = strstr(urlPath($url_base_path), '/').'/';
2937  }
2938  
2939  /**

2940  * Establish requested size.

2941  */
2942  foreach($disp_size as $i => $ena) {
2943      $size_labels[] = $cnvrt_size[$i]['label'];
2944      if ($ena == TRUE) {
2945          $valid_sizes[] = $cnvrt_size[$i]['label'];
2946      }
2947  }
2948  if (isset($get_vars['Qis'])
2949      && strlen($get_vars['Qis']) < 9
2950      && in_array($get_vars['Qis'], $valid_sizes))
2951  {
2952      $reqd_img_size = $get_vars['Qis'];
2953  } elseif (in_array($cnvrt_size[$default_img_size]['label'], $valid_sizes)) {
2954      $reqd_img_size = $cnvrt_size[$default_img_size]['label'];
2955  } else {
2956      $reqd_img_size = $valid_sizes['0'];
2957  }
2958  
2959  /**

2960  * Establish temp size, if any.

2961  */
2962  if (isset($get_vars['Qtmp']) && strlen($get_vars['Qtmp']) < 9) {
2963      $reqd_img_size_tmp = $get_vars['Qtmp'];
2964  } else {
2965      $reqd_img_size_tmp = FALSE;
2966  }
2967  if (in_array($reqd_img_size_tmp, $size_labels)
2968      && !in_array($reqd_img_size_tmp, $valid_sizes))
2969  {
2970      $reqd_img_size_tmp = FALSE;
2971  }
2972  
2973  /**

2974  * Get non-Qdig GET parmameters, if any

2975  */
2976  if ($keep_params == TRUE) {
2977      $extra_param .= keepParams();
2978  }
2979  
2980  /**

2981  * Establish Image Conversion and Captions Paths' roots

2982  */
2983  if (!empty($qdig_files)) {
2984      $cnvrtd_files_root = cleanPath("$qdig_files/$convrtd_subdir").'/';
2985      $captions_root = cleanPath("$qdig_files/$caption_subdir").'/';
2986      $qdig_files   = substr(cleanPath($qdig_files), 2);
2987      $chroot_dir   = substr(cleanPath($chroot_dir), 2);
2988      $qdf_parts    = explode('/', $qdig_files);
2989      $chroot_parts = explode('/', $chroot_dir);
2990      foreach($qdf_parts as $i => $qdf_part) {
2991          if (@$chroot_parts[$i] == $qdf_part) { continue; }
2992          $qdig_files_topdir = $qdf_part;
2993      }
2994  } else {
2995      $cnvrtd_files_root = '';
2996      $captions_root = '';
2997      $qdig_files = '';
2998  }
2999  
3000  /**

3001  * Get the array of subdirectory names.

3002  */
3003  $subdirs = getDirNames($pwd);
3004  // Don't enable directory navigation if it's not usable

3005  if  ($dir_nav['enable'] == FALSE
3006      || ($pwd == '.' && ! isset($subdirs)))
3007  {
3008      $dir_nav['prefs_ena'] == FALSE;
3009  }
3010  
3011  /**

3012  * Build style strings for color settings.

3013  */
3014  // Gallery table background color

3015  if (!empty($gallery_table_bg_clr)) {
3016      $qdig_bg_clr_attr = 'bgcolor="'.$gallery_table_bg_clr.'" ';
3017  } else {
3018      $qdig_bg_clr_attr = '';
3019  }
3020  // Image table background color

3021  if (!empty($image_table_bg_clr)) {
3022      $img_tbl_bg_clr_attr = ' bgcolor="'.$image_table_bg_clr.'"';
3023  } else {
3024      $img_tbl_bg_clr_attr = '';
3025  }
3026  // Grayed-out text color

3027  if (!empty($grayout_color)) {
3028      $styl_grayout = 'class="qdig-grayout" style="color:'.$grayout_color.';"';
3029  } else {
3030      $styl_grayout = 'class="qdig-grayout"';
3031  }
3032  
3033  /**

3034  * Check for Image Magick or GD

3035  */
3036  // Turn them off if they're not likely to work.

3037  if ($convert_GD == TRUE && ! gdVersion()) {
3038      $convert_GD = FALSE;
3039  }
3040  if ($convert_magick == TRUE
3041      && ($safe_mode == TRUE || ! @is_file($convert_cmd)))
3042  {
3043      $convert_magick = FALSE;
3044  }
3045  // Prefer GD on Win32, otherwise prefer IM.

3046  if ($convert_magick == TRUE && $convert_GD == TRUE) {
3047      if ($platform == 'Win32') {
3048          $convert_magick = FALSE;
3049      } else {
3050          $convert_GD = FALSE;
3051      }
3052  }
3053  
3054  /**

3055  * Get the array of image filenames.

3056  */
3057  // Exclude background images.

3058  $excl_imgs[] = end($logo_arrray = explode('/', $header['css_logo_url']));
3059  $excl_imgs[] = end($bg_img_array = explode('/', $header['css_bg_img_url']));
3060  $imgs = getImageFilenames($pwd);
3061  
3062  /**

3063  * Establish Image Conversion and Caption Paths

3064  */
3065  $cnvrt_path = cleanPath($cnvrtd_files_root.$pwd.'/'.$cnvrtd_dir);
3066  if (( $convert_magick == TRUE ||  $convert_GD == TRUE)
3067      && ! is_dir($cnvrt_path))
3068  {
3069      mkRecursiveDir($cnvrt_path);
3070  }
3071  $caption_path = cleanPath($captions_root.$pwd);
3072  if (! is_dir($caption_path) && $touch_captions == TRUE) {
3073      mkRecursiveDir($caption_path);
3074  }
3075  
3076  /*

3077  * Security Check

3078  */
3079  if ($check_security == TRUE
3080      && ! ($platform == 'Win32')
3081      && !empty($qdig_files)
3082      && @is_writable($qdig_files)
3083      && ! @$get_vars['Makethumb'] == 'Y'
3084      && umask() > 0)
3085  {
3086      if (@$base_dir) { $base_dir = $base_dir.'/'; }
3087      $path = @$base_dir.cleanPath($qdig_files).'/';
3088      $warning_fn = $path.'Security_Check_File--Safe_To_Delete';
3089      $dperms = decoct(fileperms($path)) % 10000;
3090      $wperms = substr($dperms, - 1); // world perms

3091      if (@is_dir($cnvrt_path)
3092          && ($touch_captions == FALSE || @is_dir($caption_path)))
3093      {
3094          if (! is_file($warning_fn)) {
3095              touch($warning_fn);
3096          } elseif ($wperms == 7 || $wperms == 6 || $wperms == 3 || $wperms == 2)
3097          { // world-writable
3098              $setting = '<span style="color:blue;">$check_security</span>';
3099              $install_txt = '<a href="http://cvs.sourceforge.net/viewcvs.py/qdig/qdig/INSTALL.txt?rev=1.20"
3100                  title ="INSTALL.txt">INSTALL.txt</a>';
3101              $exit_mesg =<<<EOT
3102  <html><head>
3103  <title>Security Warning</title>
3104  </head><body>
3105   <h3 style="color:black; background-color:pink;">Check security.</h3>
3106   The <b>$path</b> directory appears to be world-writable.<br /><br />
3107   See $install_txt for information about setting permissions on the<br />
3108   directory to something reasonable (like 0755 / drwxr-xr-x).  There is also<br />
3109   a $setting configuration setting you can use to disable the security<br />
3110   check that produces this message.
3111  EOT;
3112              if ($dperms == '777') {
3113                  $umask = umask();
3114                  $exit_mesg .=<<<EOT
3115  \n<br /><br />If you want to use "777" (rather than "2777") permissions<br />
3116  you may also want to allow the script to create world-writable<br />
3117  files using the following File Creation Mask setting:<br />
3118  <b>umask(000);</b><br />
3119  Doing so will be more convenient but "less secure" than leaving the<br />
3120  umask setting as it is now. It will also bypass the security check<br />
3121  that produces this message.
3122  EOT;
3123              $exit_mesg .='</body></html>';
3124              }
3125              exit($exit_mesg);
3126          }
3127      }
3128  }
3129  
3130  /**

3131  * Are converted images writable or readable?

3132  */
3133  if (is_dir($cnvrt_path) && is_writable($cnvrt_path))
3134  {
3135      $path_writable = TRUE;
3136  } else {
3137      $path_writable = FALSE;
3138  }
3139  if (($convert_magick == TRUE || $convert_GD == TRUE)
3140      && $path_writable == TRUE)
3141  {
3142      $convert_writable = TRUE;
3143  } else {
3144      $convert_writable = FALSE;
3145      $convert_magick = FALSE; // Turn off if path isn't writable

3146      $convert_GD = FALSE;
3147  }
3148  if (is_dir($cnvrt_path)
3149      && ($is_readable_disa == TRUE || is_readable($cnvrt_path)))
3150  {
3151      $convert_readable = TRUE;
3152  } else {
3153      $convert_readable = FALSE;
3154  }
3155  
3156  /*

3157  * Get the requested view

3158  */
3159  if (isset($get_vars['Qiv'])
3160      && strlen($get_vars['Qiv']) < 10
3161      && in_array($get_vars['Qiv'], array('thumbs', 'name', 'num', 'none')))
3162  {
3163      $reqd_view = $get_vars['Qiv'];
3164  }
3165  if ($thmb_enable == FALSE) {
3166      if ($reqd_view == 'thumbs') {
3167          $reqd_view = $txtlinks_default;
3168      }
3169      $thmb_default = FALSE;
3170  }
3171  if (! isset($reqd_view)
3172      && $convert_readable == TRUE
3173      && $thmb_default == TRUE)
3174  {
3175      $reqd_view = 'thumbs';
3176  }
3177  if ($thmb_onfly == TRUE
3178      && isset($get_vars['Makethumb'])
3179      && $convert_writable == TRUE)
3180  {
3181      $reqd_view = 'thumbs';
3182  }
3183  if (! isset($reqd_view)) {
3184      $reqd_view = $txtlinks_default;
3185  }
3186  if ($reqd_view == 'text' || $reqd_view == 'name' || $reqd_view == 'num') {
3187      $thmbs_ena = FALSE;
3188  }
3189  if ($reqd_view == 'thumbs'
3190      && $convert_readable == TRUE
3191      && $thmb_enable == TRUE)
3192  {
3193      $thmbs_ena = TRUE;
3194  }
3195  if ($reqd_view == 'name') {
3196      $namelinks_ena = TRUE;
3197  } else {
3198      $namelinks_ena = FALSE;
3199  }
3200  if ($reqd_view == 'none') {
3201      $thmbs_ena = FALSE;
3202      $no_lnks_view = TRUE;
3203  } else {
3204      $no_lnks_view = FALSE;
3205  }
3206  if (!isset($thmbs_ena)) {
3207      $thmbs_ena = FALSE;
3208  }
3209  
3210  // Store the requested image file (name / num), directory, and view, and size.

3211  $reqd_image = getReqdImage();
3212  $reqd_image['pwd'] = $pwd;
3213  $reqd_image['pwd_url'] = $pwd_url;
3214  $reqd_image['view'] = $reqd_view;
3215  $reqd_image['size'] = $reqd_img_size;
3216  
3217  // Produce the caption-editing link.

3218  @$copyright['txt'] .= adminLink($admin);
3219  
3220  // Turn off $thmb_onfly if this is an embedded gallery...

3221  if ($header['force_ena'] == TRUE && $thmb_onfly == TRUE) {
3222      $thmb_onfly = TRUE;
3223  } elseif ($header['force_disa'] == TRUE || $is_included == TRUE) {
3224      $thmb_onfly = FALSE;
3225  }
3226  // ...if the image is a singleton...

3227  if ($cnvrt_thmb['single'] == TRUE && count($imgs) < 2) {
3228      $thmb_onfly = FALSE;
3229  }
3230  // ...or if the server is in Safe Mode.

3231  if ($safe_mode == TRUE) {
3232      $thmb_onfly = FALSE;
3233  }
3234  
3235  /**

3236  * Create a single thumb if it's been requested.

3237  */
3238  if (isset($get_vars['Makethumb'])) {
3239      # Reset the image 'list' to just this one

3240      $imgs = array($reqd_image['file']);
3241      $cnvrt_thmb['single'] = TRUE;
3242      $thumbs_msg = createThumbs($cnvrt_thmb);
3243  
3244      $name = $cnvrt_path.'/'.$cnvrt_thmb['prefix'].$imgs[0];
3245  
3246      // Get the file attriubutes for the header

3247      $img_size = GetImageSize($name);
3248      $content_types[1] = 'image/gif';
3249      $content_types[2] = 'image/jpg';
3250      $content_types[3] = 'image/png';
3251      $content_types[6] = 'image/bmp';
3252      $content_type = $content_types[$img_size[2]];
3253      $content_length = filesize($name);
3254  
3255      // Send the right headers

3256      header("Pragma: no-cache");
3257      header("Content-Length: $content_length");
3258      header("Content-Type: $content_type");
3259  
3260      // dump the picture and stop the script

3261      $fp = fopen($name, 'rb');
3262      fpassthru($fp);
3263      exit;
3264  }
3265  
3266  /**

3267  * Determine if we need a Control Bar.

3268  */
3269  if ($ctrl_bar['vw_ctrl'] == FALSE && $ctrl_bar['sz_ctrl'] == FALSE) {
3270      $ctrl_bar['enable'] = FALSE;
3271  }
3272  if ($ctrl_bar['enable'] == FALSE) {
3273      $dir_nav['prefs_ena'] = FALSE;
3274  }
3275  if ($dir_nav['enable'] == FALSE && $ctrl_bar['enable'] == TRUE) {
3276      $ctrl_bar['ena'] = TRUE;
3277      $dir_nav['prefs_ena'] = FALSE;
3278  }
3279  
3280  /**

3281  * Determine if we need a display area.

3282  */
3283  if (!empty($site_lnk_url)
3284      || $qdig_homelink['ena'] == FALSE
3285      || !empty($imgs))
3286  {
3287      $display_area = TRUE;
3288  } else {
3289      $display_area = FALSE;
3290  }
3291  
3292  /**

3293  * Create thumbnail image(s) if necessary.

3294  */
3295  if ($thmb_onfly == FALSE) {
3296      $thumbs_msg = createThumbs($cnvrt_thmb);
3297  }
3298  
3299  /**

3300  * Create alternate image sizes.

3301  */
3302  $resize_msg = '';
3303  if ($disp_size['0'] == TRUE
3304      && (($cnvrt_alt['indiv'] == FALSE
3305          || $upr_nav['sizer'] == TRUE
3306          || $lwr_nav['sizer'] == TRUE)
3307      || $reqd_img_size == $cnvrt_size['0']['label']))
3308  {
3309      $resize_msg .= resizeImage($cnvrt_size['0']);
3310  }
3311  if ($disp_size['1'] == TRUE
3312      && (($cnvrt_alt['indiv'] == FALSE
3313          || $upr_nav['sizer'] == TRUE
3314          || $lwr_nav['sizer'] == TRUE)
3315      || $reqd_img_size == $cnvrt_size['1']['label']))
3316  {
3317      $resize_msg .= resizeImage($cnvrt_size['1']);
3318  }
3319  if ($disp_size['2'] == TRUE
3320      && (($cnvrt_alt['indiv'] == FALSE
3321          || $upr_nav['sizer'] == TRUE 
3322          || $lwr_nav['sizer'] == TRUE)
3323      || $reqd_img_size == $cnvrt_size['2']['label']))
3324  {
3325      $resize_msg .= resizeImage($cnvrt_size['2']);
3326  }
3327  if ($disp_size['3'] == TRUE
3328      && (($cnvrt_alt['indiv'] == FALSE
3329          || $upr_nav['sizer'] == TRUE
3330          || $lwr_nav['sizer'] == TRUE)
3331      || $reqd_img_size == $cnvrt_size['3']['label']))
3332  {
3333      $resize_msg .= resizeImage($cnvrt_size['3']);
3334  }
3335  
3336  /**

3337  * Finish creating diagnostic messages.

3338  */
3339  if ($diag_messages == TRUE) {
3340      $server_sw = $server_vars['SERVER_SOFTWARE'];
3341      if (preg_match('/Fedora/', $server_sw)) {
3342          $server_sw .= "<br />\nFedora Core 3 or later may require 
3343  <a href='http://qdig.sourceforge.net/Support/FedoraSELinux'>adjusting the SELinux policy</a> for Apache.";
3344      }
3345      if (@file_exists($qdig_files) && @is_dir($qdig_files)) {
3346          $qdig_files_exists = TRUE;
3347          $qdig_files_perms = decoct(fileperms($qdig_files)) % 10000;
3348      } else {
3349          $qdig_files_exists = FALSE;
3350      }
3351      if (@file_exists($cnvrtd_files_root) && @is_dir($cnvrtd_files_root)) {
3352          $cnvrtd_root_exists = TRUE;
3353          $cnvrtd_root_perms = decoct(fileperms($cnvrtd_files_root)) % 10000;
3354      } else {
3355          $cnvrtd_root_exists = FALSE;
3356      }
3357      if (@file_exists($captions_root) && @is_dir($captions_root)) {
3358          $captions_root_exists = TRUE;
3359          $captions_root_perms = decoct(fileperms($captions_root)) % 10000;
3360      } else {
3361          $captions_root_exists = FALSE;
3362      }
3363      if (@file_exists($convert_cmd)) {
3364          $convert_cmd_exists = TRUE;
3365          $convert_cmd_perms = decoct(fileperms($convert_cmd)) % 10000;
3366      } else {
3367          $convert_cmd_exists = FALSE;
3368      }
3369      if (!empty($fs_base_path)) {
3370          $fs_path_msg = '$fs_base_path is '.$fs_base_path."<br />\n"
3371          .@trueFalse($base_dir, '$base_dir is '.$base_dir,
3372              '$base_dir (realpath($fs_base_path)) is empty')."<br />\n";
3373      }
3374      $diag_mesgs .= "Qdig version is $qdig_version,&nbsp; "
3375          .'PHP Version is '.phpversion()
3376          .trueFalse(ini_get('safe_mode'), ' with <a href="http://qdig.sourceforge.net/Support/PHPSafeMode"'
3377          .' title="Qdig And PHP Safe Mode">Safe Mode enabled</a>', '').' '
3378          .'on '.$platform."<br />\n"
3379          .'Server Software is '.$server_sw."<br />\n"
3380          .'<span style="white-space:nowrap;">'
3381          .'$qdig_url is <a href="'.$qdig_url.'" title="Gallery URL (w/o query string)">'.$qdig_url.'</a>'."<br />\n"
3382          .'$php_self is '.$php_self."<br />\n"
3383          .'$script_name is '.$script_name."<br />\n"
3384          .'Query string is '.@trueFalse(strlen($server_vars['QUERY_STRING']) > 64, '<br />&nbsp; ', '')
3385          .@trueFalse($server_vars['QUERY_STRING'],$server_vars['QUERY_STRING'], ' (empty)')."<br />\n"
3386          .'$pwd is '.$pwd.',&nbsp; '
3387          .'$chroot_dir is '.@trueFalse($chroot_dir, $chroot_dir, '(empty)')."<br />\n"
3388          .'$is_included is '.@trueFalse($is_included).',&nbsp; '
3389          .'$header[\'force_ena\']/[\'force_disa\'] are '.@trueFalse($header['force_ena']).'/'
3390          .@trueFalse($header['force_disna'])."<br />\n"
3391          .@$fs_path_msg.@trueFalse($url_base_path, '$url_base_path is '.$url_base_path."<br />\n", '')
3392          .'$qdig_files is '.@trueFalse($qdig_files, $qdig_files, '(empty)').'&nbsp; '
3393          .@trueFalse($qdig_files_exists, "(exists, with $qdig_files_perms perms)", "(doesn't exist)").',&nbsp; '
3394          .'$cnvrtd_dir is '.@trueFalse($cnvrtd_dir, $cnvrtd_dir, '(empty)')."<br />\n"
3395          .'$cnvrtd_files_root is '.@trueFalse($cnvrtd_files_root, $cnvrtd_files_root, '(empty)').'&nbsp; '
3396          .@trueFalse($cnvrtd_root_exists, "(exists, with $cnvrtd_root_perms perms)", "(doesn't exist)")."<br />\n"
3397          .'$captions_root is '.@trueFalse($captions_root, $captions_root, '(empty)').'&nbsp; '
3398          .@trueFalse($captions_root_exists, "(exists, with $captions_root_perms perms)", "(doesn't exist)")."<br />\n"
3399          .'$convert_magick is '.trueFalse($convert_magick).',&nbsp; '
3400          .'$convert_cmd is '.@trueFalse($convert_cmd, $convert_cmd, '(empty)'). '&nbsp; '
3401          .@trueFalse($convert_cmd_exists, "(exists, with $convert_cmd_perms perms)", "(possibly doesn't exist)")."<br />\n"
3402          .'$convert_GD is '.trueFalse($convert_GD).',&nbsp; ';
3403      if (!empty($convert_GD_ver)) {
3404          $ext_loaded = '';
3405          if (! extension_loaded('gd')) {
3406              $ext_loaded = ' (extension not loaded)';
3407          }
3408          $diag_mesgs .= "GD version is set to $convert_GD_ver$ext_loaded,&nbsp; ";
3409      } else if ($gdv = gdVersion()) {
3410          $diag_mesgs .= "GD version $gdv detected,&nbsp; ";
3411      } else {
3412          $diag_mesgs .= "GD is not detected,&nbsp; ";
3413      }
3414      if (preg_match('/phpinfo/', ini_get('disable_functions'))) {
3415          $diag_mesgs .= "phpinfo() function is disabled<br />\n";
3416      } else {
3417          $diag_mesgs .= "phpinfo() function is enabled<br />\n";
3418      }
3419      $diag_mesgs .= '$convert_writable is '.trueFalse($convert_writable).',&nbsp; '
3420          .'$convert_readable is '.trueFalse($convert_readable).',&nbsp; '
3421          .'$reqd_view is '.$reqd_view."<br />\n"
3422          .'$thmbs_ena is '.trueFalse($thmbs_ena).',&nbsp; '
3423          .'$namelinks_ena is '.trueFalse($namelinks_ena).',&nbsp; '
3424          .'$check_security is '.trueFalse($check_security)."<br />\n"
3425          .'$is_readable_disa is '.trueFalse($is_readable_disa).',&nbsp; '
3426          .'$file_exists_disa is '.trueFalse($file_exists_disa).',&nbsp; '
3427          .'$compat_quote is '.trueFalse($compat_quote)."<br /></span>\n";
3428  }
3429  
3430  /*

3431  +----------+

3432  |  Output  |

3433  +----------+

3434  */
3435  
3436  /**

3437  * Echo an HTML header if the script is running stand-alone.

3438  */
3439  echo htmlHeader($header);
3440  
3441  /**

3442  * Image is a popup target (experimental).

3443  */
3444  if (@$get_vars['Qtmp'] == 'popup') {
3445      echo displayImage($reqd_image, $img_sz_labels);
3446      echo footerRow();
3447      echo htmlFooter($header);
3448      exit();
3449  }
3450  
3451  /**

3452  * Open the Qdig gallery table.

3453  */
3454  // For injecting some output ahead of the gallery

3455  if (!ini_get('register_globals')) { echo $pre_gallery; }
3456  echo <<<EOT
3457  
3458  <!-- Begin Qdig Image Gallery v$qdig_version -->
3459   <table summary="Image Gallery" $qdig_bg_clr_attr id="qdig"
3460    cellpadding="0" cellspacing="0" border="0">
3461   <tr>\n
3462  EOT;
3463  
3464  /**

3465  * Directory Navigation

3466  */
3467  $dirnav_out = dirNav($dir_nav);
3468  echo $dirnav_out['str'];
3469  
3470  /**

3471  * Control Bar

3472  */
3473  if ($reqd_img_size_tmp == 'Ctrl') {
3474      $dirnav_out['ctrl_bar_ena'] = TRUE;
3475  }
3476  // Show it if it's enabled

3477  if ($ctrl_bar['enable'] == TRUE && $dirnav_out['ctrl_bar_ena'] == TRUE) {
3478      // Only open Control Bar if appropriate

3479      if (count($imgs) > 1)
3480      {
3481          $control_bar_on = TRUE;
3482          echo <<<EOT
3483  \n <!-- Begin Qdig control bar -->
3484   <td colspan="2">
3485   <table summary="Control Bar"
3486    width="100%" cellpadding="0" cellspacing="0">
3487    <tr>\n
3488  EOT;
3489      } else {
3490          $control_bar_on = FALSE;
3491      }
3492  
3493      // Control for selecting links view.

3494      if ($ctrl_bar['vw_ctrl'] == TRUE ) {
3495          echo controlView($ctrl_links_mesg);
3496      }
3497  
3498      // Size preferences

3499      if ($ctrl_bar['sz_ctrl'] == TRUE ) {
3500          echo controlSize($img_sz_labels['ctrl']);
3501      }
3502  
3503      // Close Control Bar if open

3504      if ($control_bar_on == TRUE) {
3505          echo <<<EOT
3506    </tr>
3507   </table>
3508   </td>
3509   </tr><tr>
3510   <!-- End Qdig control bar -->\n
3511  EOT;
3512      }
3513  }
3514  // End Control Bar

3515  
3516  /**

3517  * Sidebar for Text Image Links if appropriate

3518  */
3519  if ($no_lnks_view == FALSE && ! @$omit_navlinks == TRUE) {
3520      $namelinks = sideBar($namelinks_ena,  $thmbs_ena,
3521          $sidebar_bg_clr, $sidebar_margin_top, $sidebar_height);
3522      if (isset($namelinks['sb_on'])) {
3523          $sidebar = $namelinks['sb_on'];
3524      } else {
3525          $sidebar = FALSE;
3526      }
3527      echo $namelinks['str'];
3528  } else {
3529      $sidebar = FALSE;
3530  }
3531  // End Sidebar

3532  
3533  /**

3534  * Main qdig image display area

3535  */
3536  if ($display_area == TRUE) {
3537      echo <<<EOT
3538  \n <!-- Begin Qdig gallery image display area -->
3539   <td$img_tbl_bg_clr_attr>
3540   <table summary="image display area"
3541    width="100%" cellpadding="2" cellspacing="0" border="0">
3542   <tr><td>\n\n
3543  EOT;
3544  } elseif (empty($subdirs) && $reqd_image['pwd'] == $rootdir) {
3545      echo <<<EOT
3546   <td$img_tbl_bg_clr_attr>
3547   <table summary="$empty_gallery_msg"
3548    width="100%" cellpadding="2" cellspacing="0" border="0">
3549   <tr><td>
3550   <br />
3551   <div align="center">$empty_gallery_msg</div>\n
3552  EOT;
3553  }
3554  
3555  // Show Text Numeral or Thumbnail Links to all of the images (above image).

3556  if ($sidebar == FALSE
3557      && $no_lnks_view == FALSE
3558      && ! @$omit_navlinks == TRUE
3559      && $img_links_above == TRUE)
3560  {
3561      echo displayImageLinks($thmb_row, $nmrl_row);
3562  }
3563  
3564  // Show an Upper Navigation Row, above the displayed image.

3565  echo navRow($upr_nav);
3566  
3567  // Display the requested image or else the first image.

3568  echo displayImage($reqd_image, $img_sz_labels);
3569  
3570  // Lower Navigation Row, below the displayed image.

3571  echo navRow($lwr_nav);
3572  
3573  // Show Text Numeral or Thumbnail Links to all of the images (below image).

3574  if ($sidebar == FALSE
3575      && $no_lnks_view == FALSE
3576      && ! @$omit_navlinks == TRUE
3577      && $img_links_above == FALSE)
3578  {
3579      echo displayImageLinks($thmb_row, $nmrl_row);
3580  }
3581  
3582  // Gallery Footer Row (site link / copyright / qdig home link)

3583  echo footerRow();
3584  
3585  if ($display_area == TRUE ) {
3586      echo <<<EOT
3587  \n </td></tr></table></td>
3588   <!-- End Qdig gallery image display area -->\n
3589  EOT;
3590  } elseif (empty($subdirs) && $reqd_image['pwd'] == $rootdir) {
3591      echo "\n".' </td></tr></table></td>';
3592  }
3593  // End main qdig image display area.

3594  
3595  /**

3596  * Echo messages, if any.

3597  */
3598  if (!empty($thumbs_msg) || !empty($resize_msg) || !empty($diag_mesgs)) {
3599      if (!empty($diag_mesgs)){
3600          $mtime = microtime();
3601          $mtime = explode(" ",$mtime);
3602          $end_time = $mtime[1] + $mtime[0];
3603          $exec_time = round(($end_time - $start_time), 3) * 1000;
3604          $max_time = ini_get("max_execution_time");
3605          $diag_mesgs .= "Execution time is $exec_time milliseconds, max_execution_time is $max_time seconds\n"
3606              ."</small></p>\n";
3607      }
3608      $msgs = "\n <tr><td colspan='2'>\n  <div style='text-align:left;'>";
3609      $msgs .= "\n  <!-- messages -->\n";
3610      $msgs .= $resize_msg;
3611      $msgs .= @$thumbs_msg;
3612      $msgs .= $diag_mesgs;
3613      $msgs .= "  </div>\n </td></tr>\n";
3614  } else {
3615      $msgs = '';
3616  }
3617  
3618  /**

3619  * Close the Qdig gallery table.

3620  */
3621  if (empty($imgs) && !empty($subdirs)) {
3622      $tag = '</td>';
3623  } else {
3624      $tag = '';
3625  }
3626  echo <<<EOT
3627  \n $tag</tr>$msgs</table>
3628  <!-- End Qdig Image Gallery v$qdig_version -->\n\n
3629  EOT;
3630  // For injecting some output after the gallery

3631  if (!ini_get('register_globals')) { echo $post_gallery; }
3632  
3633  /**

3634  * Echo an HTML Footer if the script is running stand-alone.

3635  */
3636  echo htmlFooter($header);
3637  
3638  // Leave the working dir and error reporting the way we found them.

3639  if (isset($orig_wd)) {
3640      chdir($orig_wd);
3641  }
3642  error_reporting($orig_err_rep_level);
3643  
3644  /* vim: set noexpandtab tabstop=4 shiftwidth=4: */

title

Description

title

Description

title

Description

title

title

Body