PageRenderTime 27ms CodeModel.GetById 17ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/templates/old/annamaria_old/lib/php/yootools.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 279 lines | 202 code | 52 blank | 25 comment | 28 complexity | 38bd38a0f39ea3a3e7a66b2ed610de2b MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1<?php
  2/**
  3 * YOOTools
  4 *
  5 * @author		yootheme.com
  6 * @copyright	Copyright (C) 2007 YOOtheme Ltd & Co. KG. All rights reserved.
  7 */
  8
  9// no direct access
 10defined( '_VALID_MOS' ) or die( 'Restricted access' );
 11
 12class YOOTools {
 13
 14	/* template stylesheets */
 15	var $stylesheets;
 16
 17	/* template javascripts */
 18	var $scripts;
 19
 20	/* yootheme global default template settings */
 21	var $defaults;  
 22
 23	/* javascript settings */
 24	var $javascript;
 25
 26	/* template settings */
 27	var $settings;
 28
 29	function YOOTools($settings = array()) {
 30		
 31		$this->stylesheets = array();
 32		$this->scripts = array();	
 33		$this->defaults = array(
 34			/* color */
 35			"color"               => "default",
 36			/* item color variation */
 37			"item1"               => "grey",
 38			"item2"               => "blue",
 39			"item3"               => "pink",
 40			"item4"               => "orange",
 41			"item5"               => "green",
 42			"item6"               => "default",
 43			"item7"               => "default",
 44			"item8"               => "default",
 45			"item9"               => "default",
 46			"item10"              => "default",
 47			/* layout */
 48			"date"    	          => true,			
 49			"styleswitcherFont"   => true,
 50			"styleswitcherWidth"  => true,
 51			"layout"              => "left",
 52			/* style switcher */
 53			"fontDefault"         => "font-medium",
 54			"widthDefault"        => "width-wide",
 55			"widthThinPx"         => 780,
 56			"widthWidePx"         => 900,
 57			"widthFluidPx"        => 0.9,
 58			/* javascript */
 59			"loadJavascript"      => true
 60			);
 61
 62		$this->javascript = array(
 63			/* color */
 64			"color"               => "'<VAL>'",
 65			/* layout */
 66			"layout"              => "'<VAL>'",
 67			/* style switcher */
 68			"fontDefault"         => "'<VAL>'", 
 69			"widthDefault"        => "'<VAL>'",
 70			"widthThinPx"         => "<VAL>",
 71			"widthWidePx"         => "<VAL>",
 72			"widthFluidPx"        => "<VAL>"
 73			);
 74
 75		/* ie browser checks */
 76		if (array_key_exists('HTTP_USER_AGENT', $_SERVER)) {
 77			$this->defaults['msie7'] = strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'msie 7') !== false;
 78			$this->defaults['msie6'] = strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'msie 6') !== false;
 79		} else {
 80			$this->defaults['msie7'] = false;
 81			$this->defaults['msie6'] = false;
 82		}
 83
 84		$this->settings = $settings + $this->defaults;
 85	}
 86
 87	function &getInstance($settings = array()) {
 88		static $instance;
 89
 90		if ($instance == null) {
 91			$instance = new YOOTools($settings);
 92		}
 93		
 94		return $instance;
 95	}
 96
 97	function getParam($key, $default = '') {
 98
 99		if (array_key_exists($key, $this->settings)) {
100			return $this->settings[$key];
101		}
102		
103		return $default;
104	}
105
106	function setParam($key, $value = '') {
107		$this->settings[$key] = $value;
108	}
109
110	/* Javascript */
111	
112	function getJavaScript() { 
113		$js = "var YtSettings = { ";
114		$seperator = false;
115		foreach($this->javascript as $key => $val) {
116			$setting = $this->getParam($key);
117			if(is_bool($setting)) {
118				$setting ? $setting = "true" : $setting = "false";
119			}
120			if(is_float($setting)) {
121				$setting = number_format($setting, 2, ".", "");
122			}
123			$seperator ? $js .= ", " : $seperator = true;			
124			$js .= $key . ": " . str_replace("<VAL>", $setting, $val);
125		}		
126		$js .= " };";
127		return $js;
128	}
129
130	function showJavaScript() {
131		echo $this->getJavaScript();
132	}
133
134	/* Styles */
135
136	function setStyle($condition, $key, $value)
137	{
138		if ($this->evalStyleCondition($condition)) {
139			$this->setParam($key, $value);
140		}
141	}
142	
143	function evalStyleCondition($condition)
144	{
145		if (is_bool($condition)) return $condition;
146
147		$parts    = explode(' ', $condition);
148		$commands = array('+', '-', '&&', '||', '(', ')', '==', '!=');
149
150		for($i = 0; $i < count($parts); $i++) {
151			if (!(in_array($parts[$i], $commands) || is_numeric($parts[$i]))) {
152				$name	   = strtolower($parts[$i]);
153				$parts[$i] = mosCountModules($name);
154			}
155		}
156
157		$str = 'return '.implode(' ', $parts).';';
158		return eval($str);
159	}
160
161	/* Styleswitcher */
162
163	function getCurrentStyle() {
164		$styleFont  = isset($_COOKIE['ytstylefont']) ? $_COOKIE['ytstylefont'] : $this->getParam('fontDefault');
165		$styleWidth = isset($_COOKIE['ytstylewidth']) ? $_COOKIE['ytstylewidth'] : $this->getParam('widthDefault');
166
167		return $styleFont . " " . $styleWidth;
168	}
169	
170	function getCurrentColor() {
171		$color  = isset($_COOKIE['ytcolor']) ? $_COOKIE['ytcolor'] : $this->getParam('color');
172		
173		if(isset($_GET['yt_color'])) {
174			setcookie('ytcolor', $_GET['yt_color'], time() + 3600, '/'); 
175			$color = $_GET['yt_color'];
176		}
177		
178		return $color;
179	}
180	
181	function getActiveMenuItemNumber($menu, $level) {
182		global $database, $my, $Itemid, $mosConfig_shownoauth;
183
184		$and = '';
185		if (!$mosConfig_shownoauth) {
186			$and = "\n AND access <= $my->gid";
187		}
188
189		$sql = "SELECT m.* FROM #__menu AS m"
190		. "\n WHERE menutype = '" . $menu . "'"
191		. "\n AND published = 1"
192		. $and
193		. "\n ORDER BY parent, ordering";
194
195		$database->setQuery($sql);
196		$rows = $database->loadObjectList('id');
197		$path = array();
198		$item_id = $Itemid;
199		
200		while ($item_id != 0) {
201			if (array_key_exists($item_id, $rows)) {
202				$path[] = $item_id;
203				$item_id = $rows[$item_id]->parent;
204			} else {
205				break;
206			}
207		}
208		
209		$path = array_reverse($path);
210				
211		if (array_key_exists($level, $path)) {
212			return $rows[$path[$level]]->ordering;
213		}
214		
215		return null;	
216	}
217	
218	/* Html helper */
219
220	function addStyleSheet($data, $condition = true, $browser = '') {
221		$this->stylesheets[] = array('data' => $data, 'condition' => $condition, 'browser' => $browser);
222	}
223
224	function addScript($data, $condition = true, $browser = '') {
225		$this->scripts[] = array('data' => $data, 'condition' => $condition, 'browser' => $browser);
226	}
227
228	function showHead() {
229		$html = '';
230
231		foreach ($this->stylesheets as $style) {
232			if ($style['condition']) {
233				$html_tag = '<link href="' . $style['data'] . '" rel="stylesheet" type="text/css" />';
234				$html .= $this->wrapBrowserCondition($style['browser'], $html_tag);
235			}
236		}
237		
238		foreach ($this->scripts as $script) {
239			if ($script['condition']) {
240				if (ereg("[.js|.php]\$", $script['data'])) {
241					$html_tag = '<script language="javascript" src="' . $script['data'] . '" type="text/javascript"></script>';
242				} else {
243					$html_tag = '<script language="javascript" type="text/javascript">' . $script['data'] . '</script>';
244				}
245				$html .= $this->wrapBrowserCondition($script['browser'], $html_tag);
246			}
247		}
248		
249		echo $html;
250	}
251	
252	function wrapBrowserCondition($browser, $html_tag) {
253		$html = '';
254		
255		switch ($browser) {
256			case 'msie':
257				if ($this->getParam('msie6') || $this->getParam('msie7')) {
258					$html = '<!--[if lte IE 7]>' . $html_tag . '<![endif]-->' . "\n";
259				}
260				break;
261			case 'msie6':
262				if ($this->getParam('msie6')) {
263					$html = '<!--[if IE 6]>' . $html_tag . '<![endif]-->' . "\n";
264				}
265				break;
266			case 'msie7':
267				if ($this->getParam('msie7')) {
268					$html = '<!--[if IE 7]>' . $html_tag . '<![endif]-->' . "\n";
269				}
270				break;
271			default:
272				$html = $html_tag . "\n";
273				break;
274		}
275		
276		return $html;
277	}	
278}
279?>