ModuleSRLayer.php 6.81 KB
Newer Older
Sven Rhinow's avatar
Sven Rhinow committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
<?php

/**
 * PHP version 5
 *
 * Class ModuleSRLayer
 *
 * @copyright  sr-tag 2014
 * @author     Sven Rhinow <support@sr-tag.de>
 * @package    srlayer
 */
class ModuleSRLayer extends \Module
{

	/**
	 * Template
	 * @var string
	 */
	protected $strTemplate = 'srl_default';

	/**
	 * Target pages
	 * @var array
	 */
	protected $arrTargets = array();

	/**
	 * Options for JS
	 * @var array
	 */
	protected $optionsArr = array();

	/**
	* show files and layer
	* @var bool
	*/
	protected $show = false;


	/**
	 * Display a wildcard in the back end
	 * @return string
	 */
	public function generate()
	{
		if (TL_MODE == 'BE')
		{
			$objTemplate = new \BackendTemplate('be_wildcard');

			$objTemplate->wildcard = '### SR-LAYER ###';

			$objTemplate->title = $this->headline;
			$objTemplate->id = $this->id;
			$objTemplate->link = $this->name;
Sven Rhinow's avatar
Sven Rhinow committed
55
			$objTemplate->href = 'contao/main.php?do=modules&amp;act=edit&amp;id=' . $this->id;
Sven Rhinow's avatar
Sven Rhinow committed
56 57 58

			return $objTemplate->parse();
		}
Sven Rhinow's avatar
Sven Rhinow committed
59 60

		if($this->srl_template != '') $this->strTemplate = $this->srl_template;
Sven Rhinow's avatar
Sven Rhinow committed
61 62 63 64 65 66 67 68 69 70

		return parent::generate();
	}


	/**
	 * Generate module
	 */
	protected function compile()
	{
Sven Rhinow's avatar
Sven Rhinow committed
71
		global $objPage;
Sven Rhinow's avatar
Sven Rhinow committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147

		//sucht in den Get-Keys nach einer bestimmten Teil-Zeichenkette
		$pos = false;

		if(count($_GET)>0)
		{
	       foreach($_GET AS $k => $v)
			{
				$k = strip_tags(trim($k));
				$getPos = strcmp($k,$this->srl_substr)==0 ? true : false;
			}
		}

		//test Start-Date
		if(strlen($this->srl_start) && ($this->srl_start > time()))
		{
			return false;
		}

		//test Stop-Date
		if(strlen($this->srl_stop) && ($this->srl_stop < time()))
		{
			return false;
		}

		//Modul-Flag fuer "keine Parameter notwendig" pruefen
		if($this->srl_no_param || $getPos)
		{
			$this->optionsArr[] = 'showNow: true';
			$this->show = true;
		}


		//Modul-Flag fuer "Layer per Link öffnen" pruefen
		if($this->srl_set_mkLinkEvents)
		{
			$this->optionsArr[] = 'mkLinkEvents: true';
			$this->show = true;
		}

		//Cookie
		if($this->srl_set_cookie && $this->show)
		{
			//Name des Cookies
			if(!$this->srl_cookie_name) $this->srl_cookie_name = 'LAYER_'.$this->id.'_COOKIE';

			if(!$this->Input->cookie($this->srl_cookie_name))
			{
				if(!$this->srl_cookie_dauer) $this->srl_cookie_dauer = 3600;
				$this->setCookie( $this->srl_cookie_name, 1, time() + $this->srl_cookie_dauer );

			}else $this->show = false;
		}

		//Session
		if($this->srl_set_session && $this->show)
		{
			$this->import('Session');
			$this->srl_session_name = 'LAYER_'.$this->id.'_SESSION';

			if(!$this->Session->get($this->srl_session_name))
			{
				$this->Session->set($this->srl_session_name,'1');

			}else $this->show = false;
		}

		// nur wenn Fund dann CSS, JS und HTML einfuegen
		if($this->show)
		{
			$layerName = $this->srl_substr;

			if(is_numeric($this->srl_option_layerwidth)) $this->optionsArr[] = 'layerWidth:'.$this->srl_option_layerwidth;
			if(is_numeric($this->srl_option_layerheight)) $this->optionsArr[] = 'layerHeight:'.$this->srl_option_layerheight;

			//expert options
148
			if($this->srl_set_jsoptions == 1)
Sven Rhinow's avatar
Sven Rhinow committed
149
			{
Sven Rhinow's avatar
Sven Rhinow committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
				if($objPage->hasJQuery)
				{
					if(strlen($this->srl_set_overLayID)) $this->optionsArr[] = "overLayID:'#".$this->srl_set_overLayID."'";
					if(strlen($this->srl_set_layerID)) $this->optionsArr[] = "layerID:'#".$this->srl_set_layerID."'";
					if(strlen($this->srl_set_closeID)) $this->optionsArr[] = "closeID:'#".$this->srl_set_closeID."'";
					if(strlen($this->srl_set_closeClass)) $this->optionsArr[] = "closeClass:'.".$this->srl_set_closeClass."'";

				} else {

					if(strlen($this->srl_set_overLayID)) $this->optionsArr[] = "overLayID:'".$this->srl_set_overLayID."'";
					if(strlen($this->srl_set_layerID)) $this->optionsArr[] = "layerID:'".$this->srl_set_layerID."'";
					if(strlen($this->srl_set_closeID)) $this->optionsArr[] = "closeID:'".$this->srl_set_closeID."'";
					if(strlen($this->srl_set_closeClass)) $this->optionsArr[] = "closeClass:'".$this->srl_set_closeClass."'";

				}

Sven Rhinow's avatar
Sven Rhinow committed
166 167 168 169 170 171 172 173 174 175
				if(strlen($this->srl_set_overLayOpacity)) $this->optionsArr[] = 'overLayOpacity:'.$this->srl_set_overLayOpacity;
				if(strlen($this->srl_set_duration)) $this->optionsArr[] = 'duration:'.$this->srl_set_duration;
				if(!$this->srl_set_closePerEsc) $this->optionsArr[] = 'closePerEsc:false';
				if(!$this->srl_set_closePerLayerClick) $this->optionsArr[] = 'closePerLayerClick:false';
				if(!$this->srl_set_drawLayerCenterX) $this->optionsArr[] = 'drawLayerCenterX:false';
				if(!$this->srl_set_drawLayerCenterY) $this->optionsArr[] = 'drawLayerCenterY:false';
			}

			$jsOptions = implode(', ',$this->optionsArr);

Sven Rhinow's avatar
Sven Rhinow committed
176
			//eigene CSS-Auszeichnungen aus CSS-Datei
177
			if($this->srl_css_file)
178
			{
179 180
				$cssObjFile = \FilesModel::findByPk($this->srl_css_file);

Sven Rhinow's avatar
Sven Rhinow committed
181
				if(version_compare(VERSION, '3.2','>='))
Sven Rhinow's avatar
Sven Rhinow committed
182
				{
183 184 185 186 187 188
					if ($cssObjFile === null)
					{
						if (!Validator::isUuid($this->srl_css_file))
						{
						    $this->log($GLOBALS['TL_LANG']['ERR']['version2format'],'ModuleSRLayer.php srl_css_file','TL_ERROR');
						}
Sven Rhinow's avatar
Sven Rhinow committed
189
					}
Sven Rhinow's avatar
Sven Rhinow committed
190
					$cssPath = $cssObjFile->path;
191
				}
Sven Rhinow's avatar
Sven Rhinow committed
192
				elseif(version_compare(VERSION, '3.2','<'))
193
				{
Sven Rhinow's avatar
Sven Rhinow committed
194
					$cssPath = $cssObjFile->path;
195
				}
Sven Rhinow's avatar
Sven Rhinow committed
196

197
			}
Sven Rhinow's avatar
Sven Rhinow committed
198

Sven Rhinow's avatar
Sven Rhinow committed
199 200 201 202
			$GLOBALS['TL_CSS'][] = ($cssPath) ? $cssPath : $GLOBALS['SRL_CSS'];

			//wenn jQuery aktiviert ist dann jQuery (vorrangig)
			if($objPage->hasJQuery && is_array($GLOBALS['SRL_JS']['jquery']))
Sven Rhinow's avatar
Sven Rhinow committed
203
			{
Sven Rhinow's avatar
Sven Rhinow committed
204 205 206 207 208
				foreach($GLOBALS['SRL_JS']['jquery'] as $jsSource)
				{
					$GLOBALS['TL_JAVASCRIPT'][] = $jsSource;
				}

209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
				if((int) $this->srl_delay > 0) $GLOBALS['TL_JQUERY'][] = '
					<script type="text/javascript"> 
				 	(function($) {
						$(document).ready(function() 
						{ 
							setTimeout(function()
							{
								$.srLayer( { '.$jsOptions.', '.$this->srl_option_other.' } ); 
							}, '.$this->srl_delay.'); 
						});
	 				})(jQuery);
					</script>';
				else $GLOBALS['TL_JQUERY'][] = '
					<script type="text/javascript">
						(function($) {
							$(document).ready(function() 
							{
								$.srLayer( { '.$jsOptions.', '.$this->srl_option_other.' } ); 
							});
						 })(jQuery);
						</script>';
Sven Rhinow's avatar
Sven Rhinow committed
230

Sven Rhinow's avatar
Sven Rhinow committed
231
			}
Sven Rhinow's avatar
Sven Rhinow committed
232 233 234
			// ansonsten Mootools
			else if($objPage->hasMooTools && is_array($GLOBALS['SRL_JS']['mootools']))
			{
Sven Rhinow's avatar
Sven Rhinow committed
235

Sven Rhinow's avatar
Sven Rhinow committed
236 237 238 239 240 241 242
				foreach($GLOBALS['SRL_JS']['mootools'] as $jsSource)
				{
					$GLOBALS['TL_JAVASCRIPT'][] = $jsSource;
				}
				if((int) $this->srl_delay > 0) $GLOBALS['TL_MOOTOOLS'][] = '<script type="text/javascript"> window.addEvent(\'domready\', function() { var ml = new srLayer( { '.$jsOptions.', '.$this->srl_option_other.' } ); }.delay('.$this->srl_delay.'));</script>';
				else $GLOBALS['TL_MOOTOOLS'][] = '<script type="text/javascript"> window.addEvent(\'domready\', function() { var ml = new srLayer( { '.$jsOptions.', '.$this->srl_option_other.' } ); });</script>';
			}
Sven Rhinow's avatar
Sven Rhinow committed
243 244 245

			$this->Template->content = $this->srl_content;
			$this->Template->showLayerHtml = $this->show;
246
			$this->Template->hideOverlay = ($this->srl_hideOverlay == 1) ? true : false;
Sven Rhinow's avatar
Sven Rhinow committed
247 248 249 250 251
		}

	}

}