* All rights reserved * * This script is part of the TYPO3 project. The TYPO3 project 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. * * The GNU General Public License can be found at * http://www.gnu.org/copyleft/gpl.html. * * This script 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. * * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ /** * Plugin 'DAM Show Image' for the 'hl_dam_gallery' extension. * * @author Heiner Lamprecht */ require_once(PATH_tslib.'class.tslib_pibase.php'); class tx_hldamgallery_pi1 extends tslib_pibase { var $prefixId = 'tx_hldamgallery_pi1'; // Same as class name var $scriptRelPath = 'pi1/class.tx_hldamgallery_pi1.php'; // Path to this script relative to the extension dir. var $extKey = 'hl_dam_gallery'; // The extension key. var $pi_checkCHash = TRUE; var $markContentArray = array(); /** * The main method of the PlugIn * * @param string $content: The PlugIn content * @param array $conf: The PlugIn configuration * @return The content that is displayed on the website */ function main($content, $conf) { // $this->pi_USER_INT_obj = 0; $this->conf=$conf; $this->pi_setPiVarDefaults(); $this->pi_loadLL(); $this->markContentArray["###INIT_GOOGLE_MAPS###"] = ''; $this->markContentArray["###IPTC_LOC###"] = ''; $this->markContentArray["###IPTC_CITY###"] = ''; $this->markContentArray["###IPTC_STATE###"] = ''; $this->markContentArray["###IPTC_COUNTRY###"] = ''; $this->markContentArray["###DAM_META_TITLE###"] = ''; $this->markContentArray["###DAM_META_LOC_DESCR###"] = ''; $this->markContentArray["###DAM_META_COUNTRY###"] = ''; $this->markContentArray["###DAM_META_CITY###"] = ''; $this->markContentArray["###DAM_META_CAPTION###"] = ''; $this->markContentArray["###DAM_META_KEYWORDS###"] = ''; $this->markContentArray["###DAM_META_CREATOR###"] = ''; $this->markContentArray["###DAM_META_PUBLISHER###"] = ''; $this->markContentArray["###DAM_META_COPYRIGHT###"] = ''; $galleryPID = intval($this->piVars['galleryPID']); $galleryCID = intval($this->piVars['galleryCID']); $imageOrderID = intval($this->piVars['imgID']); $hideMeta = 0; $hideNav = 0; if($galleryPID > 0 && $galleryCID > 0) { $GLOBALS['TYPO3_DB']->sql_pconnect(TYPO3_db_host, TYPO3_db_username, TYPO3_db_password); $GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_hldamgallery_hidemeta, tx_hldamgallery_hidenav', 'tt_content', 'uid=' . $galleryCID . ' and pid = ' . $galleryPID, '', '', ''); if($res) { $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); $hideMeta = $row['tx_hldamgallery_hidemeta']; $hideNav = $row['tx_hldamgallery_hidenav']; } $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_dam_mm_ref.sorting_foreign, tx_dam.file_name, tx_dam.file_path, tx_dam.tx_hldamgallery_viewcount', 'tx_dam_mm_ref, tx_dam', 'tx_dam.uid=tx_dam_mm_ref.uid_local and tx_dam_mm_ref.uid_foreign=' . $galleryCID . ' and tx_dam_mm_ref.sorting_foreign = ' . $imageOrderID, '', '', ''); $viewCount = 1; if($res) { $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); $this->file = $row['file_path'] . $row['file_name']; $viewCount = $row['tx_hldamgallery_viewcount'] + 1; $updateArray = array( 'tx_hldamgallery_viewcount' => $viewCount ); $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_dam', 'file_name="' . $row['file_name'] . '" and file_path="' . $row['file_path'] . '"', $updateArray); } // ======================================================================================================== // // Creating meta data // $metaContent = ''; if($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_hldamgallery.']['useIPTC']) { // // Using IPTC data, currently the fields are hardcoded. // $iptcArray = $this->getIPTC_Array($this->file); $metaContent = htmlspecialchars($this->getIPTC_Meta($iptcArray)); $this->getIPTC_Template($iptcArray); $conf['altText'] = $metaContent; $conf['titleText'] = $metaContent; $this->appendMetaTags($metaContent); # =========================================================== # include('exif.php'); $verbose = 0; $map = ''; $result = read_exif_data_raw($this->file, $verbose); if(is_array($result) && in_array('GPS', $result) && is_array($result['GPS'])) { $lat = $result['GPS']['Latitude']; if(trim($result['GPS']['Latitude Reference']) == 'S') { $lat = -1 * $lat; } $lon = $result['GPS']['Longitude']; if(trim($result['GPS']['Longitude Reference']) == 'W') { $lon = -1 * $lon; } $this->markContentArray["###INIT_GOOGLE_MAPS###"] = ''; } # # =========================================================== } else { // // Reading meta data from DAM-table // // // $fileName = basename($this->file); $filePath = dirname($this->file) . '/'; $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_dam', "file_name='" . $fileName . "' and file_path='" . $filePath . "'", '', '', 1); $title = ''; $caption = ''; $imgUID = -1; $imgAltText = ''; $imgTitleText = ''; $keywords = ''; if($res && intval($hideMeta) != 1) { $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); $imgUID = intval($row['uid']); $this->prepareMetaEntry('showTitle', $row['title'], '###DAM_META_TITLE###'); $imgTitleText = $row['title']; $this->prepareMetaEntry('showDescription', $row['description'], '###DAM_META_DESCR###'); $this->prepareMetaEntry('showCountry', $row['loc_country'], '###DAM_META_COUNTRY###'); $this->prepareMetaEntry('showCity', $row['loc_city'], '###DAM_META_CITY###'); $this->prepareMetaEntry('showLocDesc', $row['loc_desc'], '###DAM_META_LOC_DESCR###'); $this->prepareMetaEntry('showCaption', $row['caption'], '###DAM_META_CAPTION###'); $this->prepareMetaEntry('showKeywords', $row['keywords'], '###DAM_META_KEYWORDS###'); $this->appendMetaTags($row['keywords']); $this->prepareMetaEntry('showCreator', $row['creator'], '###DAM_META_CREATOR###'); $this->prepareMetaEntry('showPublisher', $row['publisher'], '###DAM_META_PUBLISHER###'); $this->prepareMetaEntry('showCopyright', $row['copyright'], '###DAM_META_COPYRIGHT###'); $imgAltText = $row['alt_text']; $category = $row['category']; } $conf['altText'] = $imgAltText; $conf['titleText'] = $imgTitleText; } $this->markContentArray["###SHOW_HITS###"] = ($this->conf['showHits']) ? $viewCount : ''; // ======================================================================================================== // // Prepare img-Tag and back-link // $a1 = ''; $a2 = ''; $backLink = $a1 . 'back' . $a2; $conf['file.'] = $this->cObj->image_compression[$this->cObj->data['image_compression']]; list($width, $height, $type, $attr) = getImageSize($this->file); $conf['file.']['width'] = $width; $conf['file.']['height'] = $height; $imgName = $this->file; $imgOrigFile = $this->file; $imgHeight = $height; $imgWidth = $width; if($this->conf['shrinkImagesToWidth'] && $this->conf['shrinkImagesToWidth'] < $imgWidth) { $orientation = ($width >= $height) ? 'landscape' : 'portrait'; $conf['file.']['maxW'] = $this->conf['shrinkImagesToWidth']; if($orientation == 'landscape') { $conf['file.']['width'] = $this->conf['shrinkImagesToWidth']; $conf['file.']['height'] = $this->conf['shrinkImagesToWidth'] / $width * $height; } else { $conf['file.']['height'] = $this->conf['shrinkImagesToWidth']; } $info = $this->cObj->getImgResource($this->file, $conf['file.']); $imgName = t3lib_div::png_to_gif_by_imagemagick($info[3]); $imgHeight = $info[1]; $imgWidth = $info[0]; } $altParam = $this->cObj->getAltParam($conf); $bigImageTag = 'cObj->getBorderAttr(' border="' . intval($conf['border']).'"') . ($altParam) . ' />'; $this->markContentArray["###DOWNLOAD_LINK###"] = ''; if($this->conf['addDownloadLink']) { $this->markContentArray["###DOWNLOAD_LINK###"] = 'ATagParams . '>download original image'; } // ======================================================================================================== // // Checking for other images in the same gallery // if(intval($hideNav) != 1) { $backLink = $a1 . 'back to gallery' . $a2; if($this->conf['numberOfThumbs']) { $numberOfThumbs = intval($this->conf['numberOfThumbs']); } else { $numberOfThumbs = 2; } $linkToNextImage = ''; $navArray = array(); if($imgUID >= 0 && $numberOfThumbs > 0) { $refreshTimeout = -1; if($this->conf['slideShowTimeOut']) { $refreshTimeout = intval($this->conf['slideShowTimeOut']); } $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 'tx_dam_mm_ref.sorting_foreign, tx_dam.title, tx_dam.description, tx_dam.alt_text, tx_dam.keywords, tx_dam.file_name, tx_dam.file_path', 'tx_dam_mm_ref, tx_dam', 'tx_dam.uid=tx_dam_mm_ref.uid_local and tx_dam_mm_ref.uid_foreign=' . $galleryCID . ' and abs(tx_dam_mm_ref.sorting_foreign - ' . $imageOrderID . ')<=' . $numberOfThumbs, '', 'tx_dam_mm_ref.sorting_foreign', $numberOfThumbs * 2 + 1); while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $imageFile = $row['file_path'] . $row['file_name']; $img = array(); if($this->conf['useIPTC']) { $iptcArray = $this->getIPTC_Array($imageFile); $metaContent = htmlspecialchars($this->getIPTC_Meta($iptcArray)); $img['altText'] = $metaContent; $img['titleText'] = $metaContent; } else { $img['altText'] = strlen($row['alt_text']) > 0 ? $row['alt_text'] : $row['description']; $img['titleText'] = strlen($row['title']) > 0 ? $row['title'] : $row['description']; } $this->appendMetaTags($row['keywords']); $imgID = $row['sorting_foreign']; $imgTag = $this->createImageTag($imageFile, $img); $url = $this->createNavigationURL($galleryPID, $galleryCID, $imgID); $imgLink = $this->createNavigationLink($url, $imgTag); if($row['sorting_foreign'] == ($imageOrderID + 1)) { // Make the big image a link to the next $bigImageTag = $this->createNavigationLink($url, $bigImageTag); if($refreshTimeout > 0) { $GLOBALS['TSFE']->additionalHeaderData['tx_hldamgallery_refresh'] = ''; } } else if($row['sorting_foreign'] == $imageOrderID) { $imgLink = '' . $imgTag . ''; } $navArray[$row['sorting_foreign'] - $imageOrderID + $numberOfThumbs] = $imgLink; } $navContent = ''; for($i = 0; $i < ($numberOfThumbs * 2 + 1); $i++) { $navContent .= $navArray[$i]; } $this->markContentArray["###GALLERY_NAVIGATION###"] = $navContent; } } // ======================================================================================================== // // Creating final output // $this->markContentArray["###GALLERY_LINK###"] = $backLink; $this->markContentArray["###GALLERY_IMAGE###"] = $bigImageTag; if(isset($this->conf["singleViewTemplate"])) { $template = $this->cObj->cObjGetSingle($this->conf["singleViewTemplate"], $this->conf["singleViewTemplate."]); } else { // No template given. We load the default file $template = $this->cObj->fileResource('EXT:hl_dam_gallery/res/default.tmpl'); } $content = $this->cObj->substituteMarkerArray($template, $this->markContentArray); } return $this->pi_wrapInBaseClass($content); } function createNavigationURL($galleryPID, $galleryCID, $imgID) { $typolink_conf = array( 'no_cache' => $this->conf['showHits'], 'parameter' => $GLOBALS['TSFE']->id, 'additionalParams' => '&tx_hldamgallery_pi1[galleryPID]=' . $galleryPID . '&tx_hldamgallery_pi1[galleryCID]=' . $galleryCID . '&tx_hldamgallery_pi1[imgID]=' . $imgID, 'useCacheHash' => true ); return $this->cObj->typolink_URL($typolink_conf); } // // size: 0 := small, 1:= medium, 2:= large function createNavigationURLSize($galleryPID, $galleryCID, $imgID, $size) { $typolink_conf = array( 'no_cache' => $this->conf['showHits'], 'parameter' => $GLOBALS['TSFE']->id, 'additionalParams' => '&tx_hldamgallery_pi1[galleryPID]=' . $galleryPID . '&tx_hldamgallery_pi1[galleryCID]=' . $galleryCID . '&tx_hldamgallery_pi1[imgID]=' . $imgID . '&tx_hldamgallery_pi1[size]=' . $size, 'useCacheHash' => true ); return $this->cObj->typolink_URL($typolink_conf); } function createNavigationLink($url, $string) { $a1 = 'ATagParams . '>'; $a2 = ''; $content = $a1 . $string . $a2; return $content; } function createImageTag($imageFile, $img) { $conf = $this->cObj->image_compression[$this->cObj->data['image_compression']]; $conf['altText'] = $img['altText']; $conf['titleText'] = $img['titleText']; $conf['is_HL_Dam_Gallery_Image'] = true; $imgTag = $this->cObj->cImage($imageFile, $conf); return $imgTag; } function prepareMetaEntry($confID, $value, $marker) { $content = ''; if($this->conf['defaultIfEmpty']) { $content = $this->conf['defaultIfEmpty']; } $defaultConfID = str_replace('show', 'default', $confID); switch($this->conf[$confID]) { case 1: if(strlen($value) > 0) { $content = $value; } else { $content = ''; } break; case 2: if(strlen($value) > 0) { $content = $value; } break; case 3: if(strlen($value) > 0) { $content = $value; } else if($this->conf[$defaultConfID]) { $content = $this->conf[$defaultConfID]; } break; case 4: if($this->conf[$defaultConfID]) { $content = $this->conf[$defaultConfID]; } break; default: $content = ''; break; } $this->markContentArray[$marker] = $content; } function getIPTC_Array($file) { $iptcArray = false; $size = getImageSize($file, $info); if(is_array($info)) { $iptcArray = array(); $iptc = iptcparse($info["APP13"]); $iptcArray['location'] = (strlen($iptc["2#092"][0]) > 0) ? $iptc["2#092"][0] : ''; $iptcArray['city'] = (strlen($iptc["2#090"][0]) > 0) ? $iptc["2#090"][0] : ''; $iptcArray['state'] = (strlen($iptc["2#095"][0]) > 0) ? $iptc["2#095"][0] : ''; $iptcArray['country'] = (strlen($iptc["2#101"][0]) > 0) ? $iptc["2#101"][0] : ''; } return $iptcArray; } function getIPTC_Template($iptcArray) { if(is_array($iptcArray)) { $this->markContentArray["###IPTC_LOC###"] = $iptcArray['location']; $this->markContentArray["###IPTC_CITY###"] = $iptcArray['city']; $this->markContentArray["###IPTC_STATE###"] = $iptcArray['state']; $this->markContentArray["###IPTC_COUNTRY###"] = $iptcArray['country']; } } function getIPTC_Meta($iptcArray) { $metaConn = ''; if(is_array($iptcArray)) { if(strlen($iptcArray['location']) > 0) { $metaContent = $iptcArray['location']; $metaConn = ', '; } if(strlen($iptcArray['city']) > 0) { $metaContent .= $metaConn . $iptcArray['city']; $metaConn = ', '; } if(strlen($iptcArray['state']) > 0) { $metaContent .= $metaConn . $iptcArray['state']; $metaConn = ', '; } if(strlen($iptcArray['country']) > 0) { $metaContent .= $metaConn . $iptcArray['country']; $metaConn = ', '; } } return $metaContent; } function appendMetaTags($keywordsText) { // $pageKeyString = $GLOBALS['TSFE']->additionalHeaderData['tx_hldamgallery_meta']; if(strlen($pageKeyString)) { $pageKeyString = str_replace('', '', $pageKeyString); $pageKeys = explode(',', $pageKeyString); } else { $pageKeys = array(); } $keywords = explode(',', $keywordsText); foreach($keywords as $key) { if(!in_array($key, $pageKeys) && strlen(trim($key))) { if(strlen(trim($pageKeyString)) == 0) { $pageKeyString = trim($key); } else { $pageKeyString .= ',' . trim($key); } } } $pageKeyString = trim($pageKeyString); if(strlen($pageKeyString)) { $GLOBALS['TSFE']->additionalHeaderData['tx_hldamgallery_meta'] = ''; } } } if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/hl_dam_gallery/pi1/class.tx_hldamgallery_pi1.php']) { include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/hl_dam_gallery/pi1/class.tx_hldamgallery_pi1.php']); } /* function linkPage($pid) { $typolink_conf = array( "no_cache" => false, // cache this page "returnLast" => "url", // don't wrap the link in anchor tags "parameter" => $pid, // page id "additionalParams" = "&xx_myext[aaa]=bbb", // extra params "useCacheHash" => true); // generate cHash return $this->cObj->typolink("", $typolink_conf); } tslib_pibase: http://typo3api.ueckermann.de/index.html : Example create link function in class.tslib_pibase.php : tslib_pibase::pi_linkTP ( $str, $urlParameters = array(), $cache = 0, $altPageId = 0 ) */ ?>