[Linpha-cvs] SF.net SVN: linpha: [4901] trunk/linpha2/lib/classes/linpha.view.image. class.php
Status: Inactive
Brought to you by:
bzrudi
From: <fan...@us...> - 2008-03-15 18:36:43
|
Revision: 4901 http://linpha.svn.sourceforge.net/linpha/?rev=4901&view=rev Author: fangehrn Date: 2008-03-15 11:36:35 -0700 (Sat, 15 Mar 2008) Log Message: ----------- Added Paths: ----------- trunk/linpha2/lib/classes/linpha.view.image.class.php Copied: trunk/linpha2/lib/classes/linpha.view.image.class.php (from rev 4900, trunk/linpha2/lib/classes/linpha.imgview.class.php) =================================================================== --- trunk/linpha2/lib/classes/linpha.view.image.class.php (rev 0) +++ trunk/linpha2/lib/classes/linpha.view.image.class.php 2008-03-15 18:36:35 UTC (rev 4901) @@ -0,0 +1,1418 @@ +<?php +/* +* Copyright (c) 2005 Heiko Rutenbeck <bz...@tu...> +* Florian Angehrn +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/** + * This class takes care of all different views (thumb view, menus...) + * @package Image + */ + +if(!defined('LINPHA_DIR')) { exit(1); } + +define('LIN_SELECT_FIELDS', + "".LIN_PREFIX."photos.id AS id2, " . + "".LIN_PREFIX."photos.id AS id, ".LIN_PREFIX."photos.name AS name, " . + "".LIN_PREFIX."photos.img_type AS img_type, ".LIN_PREFIX."photos.md5sum AS md5sum, " . + "".LIN_PREFIX."photos.width AS width, ".LIN_PREFIX."photos.height AS height, " . + "".LIN_PREFIX."photos.filesize AS filesize, " . + "".LIN_PREFIX."photos.time_add AS time_add, ".LIN_PREFIX."photos.time_mod AS time_mod, " . + "".LIN_PREFIX."photos.time_exif AS time_exif, ".LIN_PREFIX."photos.stats_numbers AS stats_numbers, " . + "".LIN_PREFIX."photos.stats_views AS stats_views, ".LIN_PREFIX."photos.stats_downloads AS stats_downloads" +); + +class LinImgview { + +public $mode; // 'home', 'thumb', 'image' +public $modulename; // 'albums', 'browse', ... +public $tot_photos; +public $photos; +public $photos_filtered; +public $id_parent, $img_type, $filename, $md5sum, $org_width, $org_height; +private $nr_pages, $current_page; // only used if javascript disabled +private $newCommentAdded = false; // used for ajax + +/** + * constructor + */ +function __construct() +{ + +} + +/** + * set current view and set fileinfos of $GLOBALS['linpha']->template->idCurrent ($_GET['linId']) + * @param string $modulname (album, browse, search, ...) + */ +function setCurrentView($modulename) +{ + $this->modulename = $modulename; + + $this->orderby = linGetSqlSortOrder($GLOBALS['linpha']->sql->config->value['sys_style_others_sortorder']); + + if( $GLOBALS['linpha']->template->idCurrent == 0 ) + { + /** + * on top view, reset current view + */ + if($this->modulename=='albums') + { + $this->mode = 'home'; + $this->orderby = linGetSqlSortOrder($GLOBALS['linpha']->sql->config->value['sys_style_home_firstsortorder']); + } + else // $this->modulename=='browse' | 'search' , others will come.. + { + $this->mode = 'thumb'; + + if( ! isset($_SESSION['mode_thumbview']) ) + { + $_SESSION['mode_thumbview'] = 'thumb'; + } + } + } + else + { + /** + * set file informations + */ + $current_data = $GLOBALS['linpha']->db->GetRow("SELECT id, name, img_type, parent_id, md5sum, width, height FROM ".LIN_PREFIX."photos " . + "WHERE id = '".LinSql::linAddslashes($GLOBALS['linpha']->template->idCurrent)."'"); + /** + * check for valid id + */ + + if( isset($current_data['id']) ) + { + $this->img_type = $current_data['img_type']; + $this->filename = $current_data['name']; + $this->md5sum = $current_data['md5sum']; + $this->org_width = $current_data['width']; + $this->org_height = $current_data['height']; + + /** + * switch between thumb_view and img_view + */ + if( $this->img_type == 0) + { + $this->mode = 'thumb'; + $this->id_parent = $current_data['id']; // use current_id as parent_id, because we want to see the content of the actual folder! + + if(! isset($_SESSION['mode_thumbview']) ) + { + $_SESSION['mode_thumbview'] = 'thumb'; + } + } + else + { + $this->mode = 'image'; + $this->id_parent = $current_data['parent_id']; // use parent_id on image view + + if( ! isset($_SESSION['mode_imageview']) ) + { + $_SESSION['mode_imageview'] = 'img'; + } + } + } + else // no valid id supplied + { + $this->mode = 'home'; + $GLOBALS['linpha']->template->idCurrent = 0; + } + } + + if($this->mode == 'thumb' && isset($_GET['view'])) + { + $_SESSION['mode_thumbview'] = $_GET['view']; + } + if($this->mode == 'image' && isset($_GET['view'])) + { + $_SESSION['mode_imageview'] = $_GET['view']; + } + + /** + * set id_parent to a default value + */ + if( ! isset( $this->id_parent) ) + { + $this->id_parent = $GLOBALS['linpha']->template->idCurrent; + } +} + +/** + * main function to prepare desired layout view + */ +function buildImgView() +{ + $this->filterPhotosNotPermitted(); + + /** + * set mode specific things + */ + switch($this->mode) + { + case 'home': + $this->viewHome(); + break; + case 'thumb': + switch($_SESSION['mode_thumbview']) + { + case 'thumb': + case 'thumbdetail': + $this->viewThumb(); + break; + case 'basket': + $this->viewBasket(); + break; + case 'albmeta': + $this->viewAlbMeta(); + break; + } + break; + case 'image': + switch($_SESSION['mode_imageview']) + { + case 'img': + $this->viewImg(); /* will exit in xml mode */ + break; + case 'meta': + $this->viewMeta(); + break; + } + break; + } + + /** + * doing some special commands + * + * should be done after viewImg(), because adminCommands() (force_import) uses some image informations + */ + if(isset($_GET['admin_cmd'])) { + $this->adminCommands(); + } + + if(isset($_GET['linMsg'])) + { + switch($_GET['linMsg']) + { + case 'basket_added': linSysLog(i18n("Images Added To Basket.")); break; + } + } + + /** + * set ref urls + * used in basket and ajax reloadmenu + */ + $_SESSION['ref_url_full'] = $GLOBALS['linpha']->template->URL_full; + $_SESSION['ref_url_base'] = $GLOBALS['linpha']->template->URL_base; + $_SESSION['ref_modulename'] = $this->modulename; + + /** + * set admin menu and more menu + * - this should be done after adminCommands, because of + * "nr images in basket" is changed in adminCommands() + * + * - this should be done after viewImg(), because of $org_width and $org_height in "View at" + */ + $this->setMenu(); + + /** + * at this point, there should be absolute no output + */ + include_once(LINPHA_DIR.'/templates/'.$GLOBALS['linpha']->template->template_name.'/global.html.php'); +} + +/** + * filter out files and folders not permitted and escape filename + * all other values dont have to be escaped + * (currently at least, have a look at LIN_SELECT_FIELDS) + */ +function filterPhotosNotPermitted() +{ + $this->photos_filtered = Array(); + + if(isset($this->photos)) + { + foreach($this->photos AS $key=>$value) + { + if( ! ($this->mode == 'image' && $value['img_type']== '0' ) ) // exclude subfolders from img_view + { + if( LinSql::photoIsAllowed( $value['id'] ) ) + { + /** + * escape name here + * -> we do not have to do it in the templates + */ + $value['name'] = htmlspecialchars($value['name'],ENT_QUOTES); + $this->photos_filtered[] = $value; + + //print_r($value); + } + } + } + } + + unset($this->photos); +} + +/** + * create optional top menu + */ +function setMenu() +{ + + + /** + * Menu Admin + */ + if($GLOBALS['linpha']->sql->isAdmin()) + { + $GLOBALS['linpha']->template->menu['admin']['import'] = + array( + 'name' => i18n("Import"), + 'link' => array( + array('name' => i18n("Start Import Of This Folder/File"), 'link' => LINPHA_CLIENT.'/admin/?cat=maintenance_import&album_select[]='.$this->id_parent), + array('name' => i18n("Detect File Changes"), 'link' => $GLOBALS['linpha']->template->URL_full.'&admin_cmd=force_import') + ) + ); + + $GLOBALS['linpha']->template->menu['admin']['permissions'] = + array( + 'name' => i18n("Permissions"), + 'link' => array( + array('name' => i18n("Set Permissions"), 'link' => LINPHA_CLIENT.'/admin/?cat=permissions_view&cmd=edit&linId='.$GLOBALS['linpha']->template->idCurrent) + ) + ); + + + if($this->mode == 'thumb' || $this->mode == 'image') + { + /** + * append to "admin - import" entry + */ + $GLOBALS['linpha']->template->menu['admin']['import']['link'][] = array( + 'name' => i18n("Recreate This Thumbnail"), + 'link' => $GLOBALS['linpha']->template->URL_full.'&admin_cmd=recreate' + ); + } + } + + /** + * Menu More + */ + if($this->mode != 'home') + { + /** + * more than one time used stuff + */ + $array = linGetSortOrders(); + foreach($array as $value) // i18n() already called + { + $array_sort_orders_links[] = array('name' => $value, 'link' => $GLOBALS['linpha']->template->URL_full.'&order_by='.$value); + } + + $open_basket_link = LINPHA_LINK.'&linCat=basket'; + + switch($this->mode) + { + case 'thumb': + + $GLOBALS['linpha']->template->menu['more']['basket'] = + array( + 'name' => i18n("Basket"), + 'link' => array( + array('name' => i18n("Add All To Basket"), 'link' => $GLOBALS['linpha']->template->URL_full.'&admin_cmd=basket_add_all'), + array('name' => i18n("Switch To Basket View"), 'link' => $GLOBALS['linpha']->template->URL_full.'&view=basket'), + array('name' => i18n("Open Basket").' ('.count($_SESSION['basket_ids']).' '.i18n("Images").')', 'link' => $open_basket_link) + ) + ); + + if( linUseAjax() ) + { + $array = explode(',',$GLOBALS['linpha']->sql->config->value['sys_style_thumb_selectsizes']); + foreach($array as $value) + { + $array_tn_sizes_links[] = array('name' => $value.' '.i18n("Pixel"), 'link' => 'javascript:myLinThumbnails.setTnSize('.$value.')'); + } + + $array = explode(',',$GLOBALS['linpha']->sql->config->value['sys_style_thumb_selectnrimages']); + foreach($array as $value) + { + $array_nr_links[] = array('name' => $value, 'link' =>"javascript:myLinThumbnails.setNrImages('".$value."')"); + } + + $array_views_links[] = array('name' => i18n("Normal"), 'link' => $GLOBALS['linpha']->template->URL_full.'&view=thumb'); + $array_views_links[] = array('name' => i18n("Detail"), 'link' => $GLOBALS['linpha']->template->URL_full.'&view=thumbdetail'); + + $GLOBALS['linpha']->template->menu['more']['view'] = + array( + 'name' => i18n("View"), + 'link' => array( + array('name' => i18n("Sort"), 'link' => $array_sort_orders_links), + array('name' => i18n("View"), 'link' => $array_views_links), + array('name' => i18n("Thumb Size"), 'link' => $array_tn_sizes_links), + array('name' => i18n("Thumb Nr"), 'link' => $array_nr_links) + ) + ); + } + else + { + $GLOBALS['linpha']->template->menu['more']['view'] = + array( + 'name' => i18n("View"), + 'link' => array( + array('name' => i18n("Sort"), 'link' => $array_sort_orders_links), + ) + ); + } + + if($GLOBALS['linpha']->sql->photoIsAllowed( $this->id_parent, 'write')) + { + $GLOBALS['linpha']->template->menu['more']['edit']['name'] = i18n("Edit"); + $GLOBALS['linpha']->template->menu['more']['edit']['link'][2]['name'] = i18n("Open Filemanager"); + $GLOBALS['linpha']->template->menu['more']['edit']['link'][2]['link'] = LINPHA_LINK.'&linCat=filemanager&linId='.$this->id_parent; + } + + if($GLOBALS['linpha']->sql->checkPermission('metadata_edit')) + { + $GLOBALS['linpha']->template->menu['more']['metainfo'] = + array( + 'name' => i18n("Metainfo"), + 'link' => array( + array('name' => i18n("Edit Album Information"), 'link' => $GLOBALS['linpha']->template->URL_full.'&view=albmeta'), + ) + ); + } + break; + case 'image': + + $GLOBALS['linpha']->template->menu['more']['basket'] = + array( + 'name' => i18n("Basket"), + 'link' => array( + array('name' => i18n("Add To Basket"), 'link' => $GLOBALS['linpha']->template->URL_full.'&admin_cmd=basket_add_this'), + array('name' => i18n("Open Basket").' ('.count($_SESSION['basket_ids']).' '.i18n("Images").')', 'link' => $open_basket_link) + ) + ); + $GLOBALS['linpha']->template->menu['more']['view'] = + array( + 'name' => i18n("View"), + 'link' => array( + array('name' => i18n("Sort"), 'link' => $array_sort_orders_links), + array('name' => i18n("View at"), 'link' => + array( + array('name' => '640x480', 'link' => LINPHA_CLIENT.'/get_image.php?linId='.$GLOBALS['linpha']->template->idCurrent.'&width=640&height=480', 'target' => '_blank'), + array('name' => '800x600', 'link' => LINPHA_CLIENT.'/get_image.php?linId='.$GLOBALS['linpha']->template->idCurrent.'&width=800&height=600', 'target' => '_blank'), + array('name' => '1024x768', 'link' => LINPHA_CLIENT.'/get_image.php?linId='.$GLOBALS['linpha']->template->idCurrent.'&width=1024&height=768', 'target' => '_blank'), + array('name' => '1280x800', 'link' => LINPHA_CLIENT.'/get_image.php?linId='.$GLOBALS['linpha']->template->idCurrent.'&width=1280&height=800', 'target' => '_blank'), + array('name' => '1280x960', 'link' => LINPHA_CLIENT.'/get_image.php?linId='.$GLOBALS['linpha']->template->idCurrent.'&width=1280&height=960', 'target' => '_blank'), + array('name' => '1280x1024', 'link' => LINPHA_CLIENT.'/get_image.php?linId='.$GLOBALS['linpha']->template->idCurrent.'&width=1280&height=1024', 'target' => '_blank'), + array('name' => '1600x1200', 'link' => LINPHA_CLIENT.'/get_image.php?linId='.$GLOBALS['linpha']->template->idCurrent.'&width=1600&height=1200', 'target' => '_blank'), + array('name' => '1920x1200', 'link' => LINPHA_CLIENT.'/get_image.php?linId='.$GLOBALS['linpha']->template->idCurrent.'&width=1920&height=1200', 'target' => '_blank'), + array('id' => 'linLiViewAtFullscreen', 'name' => $this->org_width.'x'.$this->org_height.' ('.i18n("Fullscreen").')', 'link' => LINPHA_CLIENT.'/get_image.php?linId='.$GLOBALS['linpha']->template->idCurrent.'&width='.$this->org_width.'&height='.$this->org_height, 'target' => '_blank'), + ) + ) + ) + ); + + + if($GLOBALS['linpha']->sql->checkPermission('metadata_edit')) + { + $GLOBALS['linpha']->template->menu['more']['edit']['name'] = i18n("Edit"); + $GLOBALS['linpha']->template->menu['more']['edit']['link'][0]['name'] = i18n("Rotate Left"); + $GLOBALS['linpha']->template->menu['more']['edit']['link'][0]['link'] = $GLOBALS['linpha']->template->URL_full.'&admin_cmd=rotate_left'; + $GLOBALS['linpha']->template->menu['more']['edit']['link'][1]['name'] = i18n("Rotate Right"); + $GLOBALS['linpha']->template->menu['more']['edit']['link'][1]['link'] = $GLOBALS['linpha']->template->URL_full.'&admin_cmd=rotate_right'; + } + + if($GLOBALS['linpha']->sql->photoIsAllowed( $this->id_parent, 'write')) + { + $GLOBALS['linpha']->template->menu['more']['edit']['name'] = i18n("Edit"); + $GLOBALS['linpha']->template->menu['more']['edit']['link'][2]['name'] = i18n("Open Filemanager"); + $GLOBALS['linpha']->template->menu['more']['edit']['link'][2]['link'] = LINPHA_LINK.'&linCat=filemanager&linId='.$this->id_parent; + } + + + if($GLOBALS['linpha']->sql->checkPermission('metadata_edit')) + { + $GLOBALS['linpha']->template->menu['more']['metainfo'] = + array( + 'name' => i18n("Metainfo"), + 'link' => array( + array('name' => i18n("Edit Image Information"), 'link' => $GLOBALS['linpha']->template->URL_full.'&view=meta') + ) + ); + } + + break; + } + } + + /** + * Icons + */ + if($this->mode == 'thumb') + { + /** + * basket icons + */ + if( $GLOBALS['linpha']->sql->checkPermission('basket_download')) + { + $GLOBALS['linpha']->template->menu['icon_download'] = $GLOBALS['linpha']->template->URL_full. + '&admin_cmd=basket_add_all_with_checkout&checkout_as=download'; + } + if( $GLOBALS['linpha']->sql->checkPermission('basket_print')) + { + $GLOBALS['linpha']->template->menu['icon_print'] = $GLOBALS['linpha']->template->URL_full. + '&admin_cmd=basket_add_all_with_checkout&checkout_as=print'; + } + if( $GLOBALS['linpha']->sql->checkPermission('basket_mail')) + { + $GLOBALS['linpha']->template->menu['icon_mail'] = $GLOBALS['linpha']->template->URL_full. + '&admin_cmd=basket_add_all_with_checkout&checkout_as=mail'; + } + /** + * slideshow icon + */ + if( linUseAjax() ) { + $GLOBALS['linpha']->template->menu['icon_slideshow'] = 'javascript:myLinThumbnails.loadSlideshow()'; + } + } + elseif($this->mode == 'image') + { + /** + * basket icons + */ + if( $GLOBALS['linpha']->sql->checkPermission('download')) + { + $GLOBALS['linpha']->template->menu['icon_download'] = LINPHA_LINK.'&linCat=download&linId='.$GLOBALS['linpha']->template->idCurrent; + } + if( $GLOBALS['linpha']->sql->checkPermission('basket_print')) + { + $GLOBALS['linpha']->template->menu['icon_print'] = $GLOBALS['linpha']->template->URL_full. + '&admin_cmd=basket_add_this_with_checkout&checkout_as=print'; + } + if( $GLOBALS['linpha']->sql->checkPermission('basket_mail')) + { + $GLOBALS['linpha']->template->menu['icon_mail'] = $GLOBALS['linpha']->template->URL_full. + '&admin_cmd=basket_add_this_with_checkout&checkout_as=mail'; + } + + /** + * slideshow icon + */ + if( linUseAjax() ) { + $GLOBALS['linpha']->template->menu['icon_slideshow'] = 'javascript:myLinThumbnails.fullscreenStart()'; + } + } +} + +/** + * method for special admin commands, like rotating images, import stuff etc. + * @uses LinImgview::buildImgView() + */ +function adminCommands() +{ + switch($_GET['admin_cmd']) + { + case 'recreate': + if($GLOBALS['linpha']->sql->isAdmin()) + { + $thumbnail = new LinImage(); + $_GET['force'] = true; + $thumbnail->createThumbnail($GLOBALS['linpha']->template->idCurrent); + } + break; + case 'force_import': // called in viewImg + LinImport::updateEntry( $GLOBALS['linpha']->template->idCurrent , dirname($this->src_file) , $this->filename ); + break; + case 'rotate_left': + if($GLOBALS['linpha']->sql->isAdmin()) + { + LinImage::rotateImageByMenuCall('-90', $GLOBALS['linpha']->template->idCurrent); + } + break; + case 'rotate_right': + if($GLOBALS['linpha']->sql->isAdmin()) + { + LinImage::rotateImageByMenuCall('90', $GLOBALS['linpha']->template->idCurrent); + } + break; + case 'basket_add_all': + case 'basket_add_all_with_checkout': + /** + * coming from imgview, mode=viewThumb + * the permission check with photoIsAllowed() is done while checking out + */ + foreach($this->photos_filtered AS $value) + { + if($value['img_type']!=0) + { + $_SESSION['basket_ids'][] = $value['id']; + } + } + + if($_GET['admin_cmd'] == 'basket_add_all_with_checkout') + { + header("Location: ".LINPHA_LINK."&linCat=basket&checkout_as=".$_GET['checkout_as']); + exit(); + } + break; + case 'basket_add_this': + case 'basket_add_this_with_checkout': + /** + * coming from imgview, mode=viewImg + */ + $_SESSION['basket_ids'][] = $GLOBALS['linpha']->template->idCurrent; + + if($_GET['admin_cmd'] == 'basket_add_this_with_checkout') + { + header("Location: ".LINPHA_LINK."&linCat=basket&checkout_as=".$_GET['checkout_as']); + exit(); + } + break; + } +} + +/** + * define thumbnail view + */ +function viewThumb() +{ + $this->viewThumbSetSubFolders(); + + /** + * create thumbnail info text (filename, description, etc.) + */ + $i=0; + + foreach($this->photos_filtered AS $key=>$photo_value) + { + if($_SESSION['mode_thumbview'] == 'thumbdetail') { + $flag_nr = 14; // flag nr of thumbdetail + } else { + $flag_nr = 13; // flag nr of thumb + } + + $array_image_infos = LinMetaData::readInformations($photo_value,$flag_nr); + + $GLOBALS['linpha']->template->output['thumb_infos'][$photo_value['id']]['before'] = ''; + $GLOBALS['linpha']->template->output['thumb_infos'][$photo_value['id']]['after'] = ''; + $index = 'before'; + $i=0; + foreach($array_image_infos AS $value) + { + /** + * got thumbnail, switch to index after + */ + if($value['value']=='thumbnail') + { + $index = 'after'; + } + else + { + $i++; + if($index == 'before') + { + $GLOBALS['linpha']->template->output['thumb_infos'][$photo_value['id']]['before'] .= $value['value'].'<br />'; // $value['value'] is already escaped + } + elseif($index == 'after') + { + $GLOBALS['linpha']->template->output['thumb_infos'][$photo_value['id']]['after'] .= $value['value'].'<br />'; // $value['value'] is already escaped + } + } + } + + $GLOBALS['linpha']->template->output['thumb_infos'][$photo_value['id']]['title'] = $photo_value['name']; // $photo_value['name'] is already escaped + } + + $this->nr_text_lines = $i; // used in LinThumbnails.js to calculate the space for the thumb height + + /** + * switch between javascript + */ + if( linUseAjax() ) + { + /** + * create javascript object containing all thumb informations + */ + + $GLOBALS['linpha']->template->setModuleName('view_thumb'); + + $GLOBALS['linpha']->template->output['page_nr_left'] = ''; + $GLOBALS['linpha']->template->output['page_nr_right'] = ''; + $GLOBALS['linpha']->template->output['page_nr'] = ''; + + + /** + * create files db + * this is a normal javascript array + * just another kind of definition... + */ + $GLOBALS['linpha']->template->output['files_db'] = 'var linImgIds = ['."\n"; + if($this->tot_photos > 0) // check if not all entries were folders + { + foreach($this->photos_filtered AS $key=>$value) + { + if( ( $GLOBALS['linpha']->sql->config->value['sys_style_thumb_showsubfoldersseparate'] && $value['img_type'] != 0 ) + OR !$GLOBALS['linpha']->sql->config->value['sys_style_thumb_showsubfoldersseparate'] ) + { + $before = $GLOBALS['linpha']->template->output['thumb_infos'][$value['id']]['before']; + $after = $GLOBALS['linpha']->template->output['thumb_infos'][$value['id']]['after']; + $title = $GLOBALS['linpha']->template->output['thumb_infos'][$value['id']]['title']; + + $array_files_db[] = '{ id: "'.$value['id'].'", before: "'.str_replace('"','\"',$before).'", after: "'.str_replace('"','\"',$after).'", title: "'.str_replace('"','\"',$title).'" }'; + } + } + + $GLOBALS['linpha']->template->output['files_db'] .= implode($array_files_db,", \n"); + + } + $GLOBALS['linpha']->template->output['files_db'] .= "\n".'];'; + } + else + { + $GLOBALS['linpha']->template->setModuleName('static.view_thumb'); + $GLOBALS['linpha']->template->overrideModule('css','view_thumb'); + + $this->viewThumbNojs(); + } +} + +/** + * thumbnail view with javascript disabled (static) + * @uses LinImgView::viewThumb() + */ +function viewThumbNojs() +{ + /** + * prepare variables + */ + $max_photos_per_page = $GLOBALS['linpha']->sql->config->value['sys_style_thumb_nojsnrrows'] * $GLOBALS['linpha']->sql->config->value['sys_style_thumb_nojsnrcols']; + $this->nr_pages = ceil( $this->tot_photos / $max_photos_per_page ); + if(isset($_GET['pn']) && $_GET['pn'] > 1) + { + $this->current_page = $_GET['pn']; + } + else + { + $_GET['pn'] = 1; + $this->current_page = 1; + } + + + $this->viewThumbNojsWritePageNumbers(); + + /** + * create array $this->photos_show which contains only the photos of the current page + */ + if($this->tot_photos > 0) // only if not all entries were folders + { + $img_nr = 1; + $i = 0; + $startup_img_nr = ($this->current_page - 1)*$max_photos_per_page; + + foreach($this->photos_filtered AS $value) + { + if($i >= $startup_img_nr && $img_nr <= $max_photos_per_page // add images only while in current page + && ( ( $GLOBALS['linpha']->sql->config->value['sys_style_thumb_showsubfoldersseparate'] && $value['img_type'] != 0 ) // add images only if no folder because they are shown separate + OR !$GLOBALS['linpha']->sql->config->value['sys_style_thumb_showsubfoldersseparate'] ) ) // add folders only if they are not shown separate + { + $this->photos_show[] = $value; + $img_nr++; + } + $i++; + } + } +} + +/** + * setup page numbers (only used if static) + */ +function viewThumbNojsWritePageNumbers() +{ + /** + * writing page numbers + */ + $start_nr = 1; + + /** + * write left and right '...' if more than 10 pages + */ + $left_dots = ""; + $right_dots = ""; + if($this->nr_pages > 10) + { + $start_nr = $_GET['pn']; + + if($_GET['pn'] >= $this->nr_pages-5) // we reached end of album + { + $start_nr = $this->nr_pages-10; + $left_dots = "... "; + } + elseif($start_nr <=5 ) // we are at the beginning + { + $this->nr_pages = 10; + $start_nr = 1; + $right_dots = " ..."; + } + else + { + $this->nr_pages = $start_nr+5; + $start_nr -= 5; + if($_GET['pn']!="6") : $left_dots="... "; endif; + $right_dots=" ..."; + } + } + + $GLOBALS['linpha']->template->output['page_nr'] = $left_dots; + + for($i=$start_nr; $i <= $this->nr_pages; $i++) + { + if($i == $this->current_page) + { + $GLOBALS['linpha']->template->output['page_nr'] .= $i.' '; + } + else + { + $GLOBALS['linpha']->template->output['page_nr'] .= '<a href="'.$GLOBALS['linpha']->template->URL_full.'&pn='.$i.'">'.$i.'</a> '; + } + } + + $GLOBALS['linpha']->template->output['page_nr'] .= $right_dots; + + /** + * write starting ' << ' and ' < ' + */ + if($this->current_page != 1) + { + $GLOBALS['linpha']->template->output['page_nr_left'] = '<a href="'.$GLOBALS['linpha']->template->URL_full.'&pn=1"><<</a> ' . + '<a href="'.$GLOBALS['linpha']->template->URL_full.'&pn='.($this->current_page-1).'"><</a> '; + } + else + { + $GLOBALS['linpha']->template->output['page_nr_left'] = '<< <'; + } + + /** + * write ending '>' and '>>' + */ + if($this->current_page != $this->nr_pages && $this->nr_pages != 0) // need check nr_pages != 0 because we don't need links if nr_pages == 0! + { + $GLOBALS['linpha']->template->output['page_nr_right'] = '<a href="'.$GLOBALS['linpha']->template->URL_full.'&pn='.($this->current_page+1).'">></a> ' . + '<a href="'.$GLOBALS['linpha']->template->URL_full.'&pn='.($this->nr_pages).'">>></a> '; + } + else + { + $GLOBALS['linpha']->template->output['page_nr_right'] = '> >>'; + } +} + +/** + * print sub folders AND calculate tot_photos + * @todo should we show subfolders separate..? + * i think this is useless if we can set automatically view = thumbdetail + */ +function viewThumbSetSubFolders() +{ + $output_folders = ''; + $nr_folders = 0; + + if( ! isset($GLOBALS['linpha']->template->output['navigation'] ) ) + { + $GLOBALS['linpha']->template->output['navigation'] = ''; + } + + if($GLOBALS['linpha']->sql->config->value['sys_style_thumb_showsubfoldersseparate']) + { + foreach($this->photos_filtered AS $key=>$value) + { + if($value['img_type'] == 0) + { + $GLOBALS['linpha']->template->output['navigation'] .= '<a href="'.LINPHA_LINK.'&linCat=alb&linId='.$value['id'].'">'.$value['name'].'</a><br />'; + $nr_folders++; + } + } + } + + /** + * set tot_photos + * subtract number of folders if they are shown separate + */ + $this->tot_photos = count($this->photos_filtered) - $nr_folders; +} + +/** + * setup detailed thumbdetail view + */ +function viewThumbdetail() +{ + $GLOBALS['linpha']->template->setModuleName('view_thumbdetail'); +} + +/** + * setup main/home view layout + */ +function viewHome() +{ + $GLOBALS['linpha']->template->setModuleName('home'); + + /** + * set welcome text + */ + if($GLOBALS['linpha']->sql->config->value['sys_style_home_usedefaultwelcometext']) + { + $GLOBALS['linpha']->template->output['welcome'] = '<h1 class="linStyle">'.i18n("Welcome").'</h1>'. + i18n("Hi, this is the home of \"The PHP Photo Archive\" <a href=\"http://linpha.sf.net\">aka LinPHA</a>.").'<br />'; + } + else + { + $data = $GLOBALS['linpha']->db->GetRow("SELECT meta_comment FROM ".LIN_PREFIX."meta_comments WHERE md5sum='welcometext'"); + if(isset($data['meta_comment'])) + { + $GLOBALS['linpha']->template->output['welcome'] = $data['meta_comment']; + } + else + { + $GLOBALS['linpha']->template->output['welcome'] = ''; + } + } + + /** + * new images + */ + $days = $GLOBALS['linpha']->sql->config->value['sys_style_home_newimagesage']; + $days_in_sec = $days*60*60*24; + $lower_date = time()-$days_in_sec; + $this->viewHomeSetImages('new_images','sys_style_home_newimagesnr',' AND time_add > '.LinSql::linAddslashes($lower_date)); + + /** + * random images + */ + $this->viewHomeSetImages('random_images','sys_style_home_nrrandomimages',''); + + /** + * browse by date + */ + $this->viewHomeSetBrowseByDate(); + + /** + * album informations + */ + foreach($this->photos_filtered AS $photo_key=>$photo_value) + { + $array_image_infos = LinMetaData::readInformations($photo_value,$flag_nr=12); + + $this->photos_filtered[$photo_key]['album_infos'] = ''; + foreach($array_image_infos AS $key=>$value) + { + if($key == 'builtin_stats_numbers') + { + $this->photos_filtered[$photo_key]['album_infos'] .= $value['value'].' '.i18n("Photos").'<br />'; + } + elseif($key == 'builtin_first_comment') + { + $this->photos_filtered[$photo_key]['album_infos'] .= '<div class="linDivFolderComment">'.$value['value']; + if($GLOBALS['linpha']->sql->checkPermission('metadata_edit')) { + $this->photos_filtered[$photo_key]['album_infos'] .= ' <a href="'.$GLOBALS['linpha']->template->URL_base.'&linId='.$photo_value['id'].'&view=albmeta'.'">Edit</a>'; + } + $this->photos_filtered[$photo_key]['album_infos'] .= '</div>'; + } + else + { + $this->photos_filtered[$photo_key]['album_infos'] .= $value['value'].'<br />'; + } + } + } +} + +/** + * setup browse by date feature + */ +function viewHomeSetBrowseByDate() +{ + if($GLOBALS['linpha']->sql->config->value['sys_style_home_showbrowsebydate']) + { + $GLOBALS['linpha']->template->output['browse_by_date'] = ''; + + $data = $GLOBALS['linpha']->db->GetRow("SELECT min(datetimeoriginal) AS min , max(datetimeoriginal) AS max " . + "FROM ".LIN_PREFIX."meta_exif"); + if(isset($data['min']) && isset($data['max']) && !empty($data['min']) && !empty($data['max']) ) + { + /** + * get min and max year + */ + $min_year = substr($data['min'],0,4); + $max_year = substr($data['max'],0,4); + /** + * get years between + */ + for($i = $min_year; $i <= $max_year; $i++) + { + /** + * exclude all wrong/empty/... dates + */ + if($i > 1900) + { + $data = $GLOBALS['linpha']->db->GetRow("SELECT count(datetimeoriginal) AS datetime FROM ".LIN_PREFIX."meta_exif WHERE datetimeoriginal LIKE '".$i."%'"); + if($data['datetime']>0) + { + $GLOBALS['linpha']->template->output['browse_by_date'] .= '<a href="'.LINPHA_LINK.'&linCat=browse&year='.$i.'">'.$i.'</a> ('.$data['datetime'].'), '; + } + } + } + } + } +} + +/** + * setup random and new imgages view + */ +function viewHomeSetImages($key,$optionname,$sql) +{ + $GLOBALS['linpha']->template->output[$key] = array(); + + if($GLOBALS['linpha']->sql->config->value[$optionname] != 0) + { + switch(LIN_DB_TYPE) + { + case 'mysql': + $str_random = 'rand()'; + break; + case 'postgres': + $str_random = 'random()'; + break; + case 'sqlite': + $str_random = 'random()'; + break; + case 'oci8po': + $str_random = $GLOBALS['linpha']->db->random; + break; + } + + $nr_images = $GLOBALS['linpha']->sql->config->value[$optionname]; + $query = $GLOBALS['linpha']->db->Execute("SELECT id FROM ".LIN_PREFIX."photos WHERE img_type <> 0 AND img_type <> 9999999".$sql." ORDER BY ".$str_random); + + for($i = 1; $i <= $nr_images ; ) + { + $data = $query->FetchRow(); + if(isset($data['id'])) + { + $path = LinSql::getFullImagePath( $data['id'] ); + + if(file_exists($path) && LinSql::photoIsAllowed($data['id'])) + { + $GLOBALS['linpha']->template->output[$key][] = array('id'=>$data['id'],'path'=>$path); + $i++; + } + } + else + { + break; + } + } + } +} + +/** + * setup basket view + */ +function viewBasket() +{ + $GLOBALS['linpha']->template->setModuleName('view_basket'); + $GLOBALS['linpha']->template->overrideModule('css','view_thumb'); // used the same css definitions as view_thumb + + $this->viewThumbSetSubFolders(); + $this->viewThumbNojs(); +} + +/** + * setup comment view + */ +function viewAlbMeta() +{ + $GLOBALS['linpha']->template->setModuleName('view_albmeta'); + + /** + * save data + */ + if( isset( $_POST['cmd'] ) && $_POST['cmd']=="add_comment") + { + /** + * check if comment exists + * + */ + $query = $GLOBALS['linpha']->db->Execute("SELECT id " . + "FROM ".LIN_PREFIX."meta_comments " . + "WHERE md5sum = '".LinSql::linAddslashes($this->md5sum)."'"); + + if( $query->EOF ) // insert + { + $GLOBALS['linpha']->db->Execute( + "INSERT into ".LIN_PREFIX."meta_comments " . + "(meta_time, md5sum, meta_author, meta_comment) " . + "VALUES " . + "('".time()."', '".LinSql::linAddslashes($this->md5sum)."', " . + "'".LinSql::linAddslashes($_POST['author'])."', '".LinSql::linAddslashes($_POST['comment'])."')" + ); + } + else // update + { + $GLOBALS['linpha']->db->Execute("UPDATE ".LIN_PREFIX."meta_comments SET ". + "meta_time = '".time()."', ". + "meta_author = '".LinSql::linAddslashes($_POST['author'])."', " . + "meta_comment = '".LinSql::linAddslashes($_POST['comment'])."' " . + "WHERE md5sum = '".LinSql::linAddslashes($this->md5sum)."'"); + } + } + + /** + * get data + */ + $data = $GLOBALS['linpha']->db->GetRow( + "SELECT id, meta_time, meta_author, meta_comment " . + "FROM ".LIN_PREFIX."meta_comments " . + "WHERE md5sum = '".$this->md5sum."'" + ); + if(isset($data['meta_author'])) + { + $GLOBALS['linpha']->template->output['comment_author'] = $data['meta_author']; + } + else + { + $GLOBALS['linpha']->template->output['comment_author'] = $_SESSION['user_name']; + } + + if(isset($data['meta_comment'])) + { + $GLOBALS['linpha']->template->output['comment_text'] = $data['meta_comment']; + } + else + { + $GLOBALS['linpha']->template->output['comment_text'] = ''; + } + + /** + * save modified MetaData + */ + LinMetaData::saveModifiedMetaData(); +} + +/** + * setup image view + */ +function viewImg() +{ + $this->src_file = LinSql::getFullImagePath( $GLOBALS['linpha']->template->idCurrent ); + + if( LinIdentify::isVideo( $this->img_type )) // in video mode, the video thumbnail is shown instead of the image + { + $this->img_width = $GLOBALS['linpha']->sql->config->value['sys_style_thumb_size_max']; + $this->img_height = $GLOBALS['linpha']->sql->config->value['sys_style_thumb_size_max']; + } + else + { + $max_width = $GLOBALS['linpha']->sql->config->value['sys_style_image_width']; + $max_height = $GLOBALS['linpha']->sql->config->value['sys_style_image_height']; + $array = LinImage::scaleToFit($this->org_width,$this->org_height,$max_width,$max_height); + + $this->img_width = $array['w']; + $this->img_height = $array['h']; + } + + $this->viewImgCommon(); + $this->viewImgComments(); + + if( linUseAjax() ) + { + $GLOBALS['linpha']->template->setModuleName('view_img'); + + if(isset($_GET['xml'])) + { + $this->viewImgXml(); + exit(); + } + } + else + { + $GLOBALS['linpha']->template->setModuleName('static.view_img'); + $GLOBALS['linpha']->template->overrideModule('css','view_img'); + } +} + +/** + * generate xml data for ajax image view + */ +function viewImgXml() +{ + header('Content-type: text/xml'); + echo '<?xml version="1.0" ?>'."\n"; + ?> +<root> +<imgid><?php echo $GLOBALS['linpha']->template->idCurrent; ?></imgid> +<filetype><?php echo LinIdentify::getShortFileType( $this->img_type ); ?></filetype> +<imgwidth><?php echo $this->org_width; ?></imgwidth> +<imgheight><?php echo $this->org_height; ?></imgheight> +<imgnr><?php printf(i18n("Image %s of %s"),$this->current_key+1,count($this->photos_filtered)); ?></imgnr> +<title><?php /* oh, what an evil hack */ echo str_replace('<','<',$GLOBALS['linpha']->template->linpha_title." :: ".$GLOBALS['linpha']->template->output['title']); ?></title> +<?php + if(isset($this->xmldata['prev_thumb'])) { + foreach($this->xmldata['prev_thumb'] AS $value) + { + echo '<prevthumb>'.$value.'</prevthumb>'."\n"; + } + } + if(isset($this->xmldata['next_thumb'])) { + foreach($this->xmldata['next_thumb'] AS $value) + { + echo '<nextthumb>'.$value.'</nextthumb>'."\n"; + } + } + + foreach($GLOBALS['linpha']->template->output['image_infos'] AS $value) + { ?> +<meta> + <name><?php echo $value['name']; ?></name><value><?php echo htmlspecialchars($value['value']); ?></value> +</meta> +<?php + } + + if($this->newCommentAdded) + { + echo '<commentadded>'.i18n("Comment successfully added.").'</commentadded>'."\n"; + } + + while($data = $GLOBALS['linpha']->template->output['image_comments']->FetchRow()) + { ?> +<comment> + <time><?php echo htmlspecialchars(linStrftime($data['meta_time'])); ?></time> + <author><?php echo htmlspecialchars($data['meta_author'],ENT_QUOTES); ?></author> + <text><?php echo str_replace('<','<',linHtmlTag($data['meta_comment'],ENT_QUOTES) ); ?></text> +</comment> +<?php } ?> +</root> + +<?php + +} // end viewImgAjax() + +/** + * stuff used in viewImg() and viewMeta() + */ +function viewImgCommon() +{ + $this->viewImgSetPrevNextThumb(); + + $this->viewImgStoreImageInformation(); + + $GLOBALS['linpha']->template->output['image_infos'] = + LinMetaData::readInformations($this->photos_filtered[$this->current_key], + $flag_nr=10); + +} + +/** + * get/save image comments + */ +function viewImgComments() +{ + /** + * image comments + */ + if($GLOBALS['linpha']->sql->checkPermission('metadata_comments')) + { + /** + * save comment + */ + if( isset( $_POST['cmd'] ) && $_POST['cmd']=='add_comment' + && isset($_POST['inputAddCommentAuthor']) + && !empty($_POST['inputAddCommentAuthor']) + && ((isset($_POST['inputAddCommentText']) && !empty($_POST['inputAddCommentText'])) + || (isset($_POST['inputAddCommentTextarea']) && !empty($_POST['inputAddCommentTextarea'])))) + { + if( !empty($_POST['inputAddCommentTextarea'])) { + $comment = $_POST['inputAddCommentTextarea']; + } else { + $comment = $_POST['inputAddCommentText']; + } + + $GLOBALS['linpha']->db->Execute("INSERT into ".LIN_PREFIX."meta_comments (meta_time, md5sum, meta_author, meta_comment)" . + "VALUES ('".time()."','".$GLOBALS['linpha']->imgview->md5sum."','".LinSql::linAddslashes($_POST['inputAddCommentAuthor'])."'," . + "'".LinSql::linAddslashes($comment)."')"); + $this->newCommentAdded = true; // used for ajax + } + + /** + * get comments + */ + $GLOBALS['linpha']->template->output['image_comments'] = $GLOBALS['linpha']->db->Execute("SELECT id, meta_time, meta_author, meta_comment FROM ".LIN_PREFIX."meta_comments " . + "WHERE md5sum = '".$GLOBALS['linpha']->imgview->md5sum."'"); + } +} + +/** + * store image informations in database if s + */ +function viewImgStoreImageInformation() +{ + $array_meta = array('exif','iptc','xmp'); + foreach($array_meta AS $value) + { + if(!isset($MetaData)) + { + $MetaData = new LinMetaData(); + } + + /** + * read exif/iptc/xmp from file if no entry + */ + if($GLOBALS['linpha']->sql->config->value['sys_image_'.$value]) + { + $MetaData->saveData($value, $this->src_file, $this->md5sum ); + } + + /** + * Read image geodata. This depends on the maps plugin. So we only + * run this additionally import if maps plugin is enabled and admin + * selected "autoimport". + * This should prevent all others from suffering performance issues + * during import + */ + if(isset($GLOBALS['linpha']->sql->config->value['plugins_maps_enable']) + && $GLOBALS['linpha']->sql->config->value['plugins_maps_enable_geotagged'] + && $GLOBALS['linpha']->sql->config->value['plugins_maps_geotagged_autoimport']) + { + $MetaData->singleImportGeoData($this->md5sum, $this->src_file); + error_log("DOING GEODATA AUTOIMPORT",'',0); + } + } +} + +/** + * generate html code for the prev/next thumbnail + */ +function viewImgThumbHtml($key,$class) +{ + $id = $this->photos_filtered[$key]['id']; + $name = $this->photos_filtered[$key]['name']; + + $str = '<div class="linDivThumbnavi_'.$class.'">' + . '<a href="'.$GLOBALS['linpha']->template->URL_base.'&linId='.$id.'">' + . '<img class="linImgThumbnavi_'.$class.'" src="'.LINPHA_CLIENT.'/get_thumb.php?linId='.$id.'" /></a>' + . '<br />'.$name.'</div>'."\n"; + + return $str; +} + +/** + * set prev/next thumb for img_view and meta_view + */ +function viewImgSetPrevNextThumb() +{ + $nr_prev_next_thumbs = $GLOBALS['linpha']->sql->config->value['sys_style_image_nrprevnextthumbs']; + + /** + * search current key in array + */ + foreach($this->photos_filtered AS $key=>$value) + { + if($value['id'] == $GLOBALS['linpha']->template->idCurrent) + { + $this->current_key = $key; + break; + } + } + + /** + * ooh, something went wrong + */ + if(!isset($this->current_key)) + { + $this->current_key = 0; + } + + /** + * set prev thumbs + */ + $GLOBALS['linpha']->template->output['prev_thumb'] = ''; + for($i=$nr_prev_next_thumbs; $i > 0; $i--) + { + if($this->current_key >= $i) + { + if(isset($_GET['xml'])) + { + $this->xmldata['prev_thumb'][] = $this->photos_filtered[$this->current_key - $i]['id']; + } + else + { + $GLOBALS['linpha']->template->output['prev_thumb'] .= $this->viewImgThumbHtml( $this->current_key - $i , 'PrevNext' ); + } + } + } + + /** + * set next thumbs + */ + $GLOBALS['linpha']->template->output['next_thumb'] = ''; + for($i=0; $i < $nr_prev_next_thumbs; $i++) + { + if($this->current_key < ( count($this->photos_filtered) - ($i+1) ) ) + { + if(isset($_GET['xml'])) + { + $this->xmldata['next_thumb'][] = $this->photos_filtered[$this->current_key + ($i+1)]['id']; + } + else + { + $GLOBALS['linpha']->template->output['next_thumb'] .= $this->viewImgThumbHtml( $this->current_key + ($i+1) , 'PrevNext' ); + } + } + } + + + /** + * set current image and thumb + */ + if(isset($_GET['xml'])) + { + } + else + { + $GLOBALS['linpha']->template->output['current_thumb'] = $this->viewImgThumbHtml( $this->current_key , 'Current' ); + } +} + +/** + * setup MetaData view + */ +function viewMeta() +{ + $GLOBALS['linpha']->template->setModuleName('static.view_img'); + $GLOBALS['linpha']->template->overrideModule('css','view_img'); + + $this->src_file = LinSql::getFullImagePath( $GLOBALS['linpha']->template->idCurrent ); + + /** + * save modified MetaData + */ + LinMetaData::saveModifiedMetaData(); + + $this->viewImgCommon(); +} + +} // end class linImgview +?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |