PageRenderTime 141ms CodeModel.GetById 40ms app.highlight 10ms RepoModel.GetById 73ms app.codeStats 0ms

/concrete/core/controllers/blocks/image.php

https://bitbucket.org/selfeky/xclusivescardwebsite
PHP | 151 lines | 117 code | 18 blank | 16 comment | 31 complexity | f1b8282f64b71f0288a96b99fb99db27 MD5 | raw file
  1<?php 
  2	defined('C5_EXECUTE') or die("Access Denied.");	
  3/**
  4 * A block controller for displaying an image on a page.
  5 *
  6 * @package Blocks
  7 * @subpackage Image
  8 * @author Andrew Embler <andrew@concrete5.org>
  9 * @author Tony Trupp <tony@concrete5.org>
 10 * @author Ryan Tyler <ryan@concrete5.org>
 11 * @author Jordan Lev
 12 * @copyright  Copyright (c) 2003-2012 Concrete5. (http://www.concrete5.org)
 13 * @license    http://www.concrete5.org/license/     MIT License
 14 *
 15 */
 16	class Concrete5_Controller_Block_Image extends BlockController {
 17
 18		protected $btInterfaceWidth = 400;
 19		protected $btInterfaceHeight = 550;
 20		protected $btTable = 'btContentImage';
 21		protected $btCacheBlockRecord = true;
 22		protected $btCacheBlockOutput = true;
 23		protected $btCacheBlockOutputOnPost = true;
 24		protected $btCacheBlockOutputForRegisteredUsers = true;
 25		protected $btWrapperClass = 'ccm-ui';
 26		protected $btExportFileColumns = array('fID','fOnstateID');
 27
 28		/** 
 29		 * Used for localization. If we want to localize the name/description we have to include this
 30		 */
 31		public function getBlockTypeDescription() {
 32			return t("Adds images and onstates from the library to pages.");
 33		}
 34		
 35		public function getBlockTypeName() {
 36			return t("Image");
 37		}		
 38		
 39		public function getJavaScriptStrings() {
 40			return array(
 41				'image-required' => t('You must select an image.')
 42			);
 43		}
 44	
 45	
 46		function getFileID() {return $this->fID;}
 47		function getFileOnstateID() {return $this->fOnstateID;}
 48		function getFileOnstateObject() {
 49			if ($this->fOnstateID > 0) {
 50				return File::getByID($this->fOnstateID);
 51			}
 52		}
 53		function getFileObject() {
 54			return File::getByID($this->fID);
 55		}		
 56		function getAltText() {return $this->altText;}
 57		function getExternalLink() {return $this->externalLink;}
 58		function getInternalLinkCID() {return $this->internalLinkCID;}
 59		function getLinkURL() {
 60			if (!empty($this->externalLink)) {
 61				return $this->externalLink;
 62			} else if (!empty($this->internalLinkCID)) {
 63				$linkToC = Page::getByID($this->internalLinkCID);
 64				return (empty($linkToC) || $linkToC->error) ? '' : Loader::helper('navigation')->getLinkToCollection($linkToC);
 65			} else {
 66				return '';
 67			}
 68		}
 69		
 70		public function save($args) {		
 71			$args['fOnstateID'] = ($args['fOnstateID'] != '') ? $args['fOnstateID'] : 0;
 72			$args['fID'] = ($args['fID'] != '') ? $args['fID'] : 0;
 73			$args['maxWidth'] = (intval($args['maxWidth']) > 0) ? intval($args['maxWidth']) : 0;
 74			$args['maxHeight'] = (intval($args['maxHeight']) > 0) ? intval($args['maxHeight']) : 0;
 75			switch (intval($args['linkType'])) {
 76				case 1:
 77					$args['externalLink'] = '';
 78					break;
 79				case 2:
 80					$args['internalLinkCID'] = 0;
 81					break;
 82				default:
 83					$args['externalLink'] = '';
 84					$args['internalLinkCID'] = 0;
 85					break;
 86			}
 87			unset($args['linkType']); //this doesn't get saved to the database (it's only for UI usage)
 88			parent::save($args);
 89		}
 90
 91		function getContentAndGenerate($align = false, $style = false, $id = null) {
 92			$c = Page::getCurrentPage();
 93			$bID = $this->bID;
 94			
 95			$f = $this->getFileObject();
 96			$fullPath = $f->getPath();
 97			$relPath = $f->getRelativePath();			
 98			$size = @getimagesize($fullPath);
 99			if (empty($size)) {
100				echo t( 'Image Not Found. ');
101			    return '';
102			}	
103			
104			if ($this->maxWidth == $size[0] && $this->maxHeight == $size[1]) {
105				$sizeStr = $size[3];
106			} else if (!$this->forceImageToMatchDimensions && ($this->maxWidth > 0 || $this->maxHeight > 0)) { 
107				$mw = $this->maxWidth > 0 ? $this->maxWidth : $size[0];
108				$mh = $this->maxHeight > 0 ? $this->maxHeight : $size[1];
109				$ih = Loader::helper('image');
110				$thumb = $ih->getThumbnail($f, $mw, $mh);
111				$sizeStr = ' width="' . $thumb->width . '" height="' . $thumb->height . '"';
112				$relPath = $thumb->src;
113			} else {
114				$sizeStr = $size[3];
115			}
116			
117			$img = "<img border=\"0\" class=\"ccm-image-block\" alt=\"{$this->altText}\" src=\"{$relPath}\" {$sizeStr} ";
118			$img .= ($align) ? "align=\"{$align}\" " : '';
119			
120			$img .= ($style) ? "style=\"{$style}\" " : '';
121			if($this->fOnstateID != 0) {
122				$fos = $this->getFileOnstateObject();
123				$fullPathOnstate = $f->getPath();
124				$sizehover = @getimagesize($fullPathOnstate);
125
126				if ($this->maxWidth == $sizehover[0] && $this->maxHeight == $sizehover[1]) {
127					$relPathHover = $fos->getRelativePath();
128				} else if (!$this->forceImageToMatchDimensions && ($this->maxWidth > 0 || $this->maxHeight > 0)) {
129					$thumbHover = $ih->getThumbnail($fos, $mw, $mh);				
130					$relPathHover = $thumbHover->src;
131				} else {
132					$relPathHover = $fos->getRelativePath();
133				}
134
135				$img .= " onmouseover=\"this.src = '{$relPathHover}'\" ";
136				$img .= " onmouseout=\"this.src = '{$relPath}'\" ";
137			}
138			
139			$img .= ($id) ? "id=\"{$id}\" " : "";
140			$img .= "/>";
141			
142			$linkURL = $this->getLinkURL();
143			if (!empty($linkURL)) {
144				$img = "<a href=\"{$linkURL}\">" . $img ."</a>";
145			}
146			return $img;
147		}
148
149	}
150
151?>