PageRenderTime 284ms CodeModel.GetById 120ms app.highlight 9ms RepoModel.GetById 152ms app.codeStats 1ms

/concreteOLD/blocks/image/controller.php

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