PageRenderTime 55ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/templates/old/annamaria_net/lib/php/yootools.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 370 lines | 267 code | 71 blank | 32 comment | 44 complexity | 557404cde2aa04bd6052134e884172f9 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. class YOOTools {
  9. /* template stylesheets */
  10. var $stylesheets;
  11. /* template javascripts */
  12. var $scripts;
  13. /* yootheme global default template settings */
  14. var $defaults;
  15. /* javascript settings */
  16. var $javascript;
  17. /* template settings */
  18. var $settings;
  19. /* check module output */
  20. var $modules = array();
  21. function YOOTools($settings = array()) {
  22. $this->stylesheets = array();
  23. $this->scripts = array();
  24. $this->defaults = array(
  25. /* Left / right column layout */
  26. 'leftWidth' => 200, /* left hand column width */
  27. 'rightWidth' => 200, /* right hand column width */
  28. 'showLeft' => 1, /* left hand column on */
  29. 'showRight' => 1, /* right hand column on */
  30. 'roundedWrapper' => 0, /* whether or not the wrapper has rounded corners */
  31. 'roundedInner' => 0, /* whether the inner has rounded corners */
  32. /* color */
  33. 'color' => 'default',
  34. /* item color variation */
  35. 'item1' => 'default',
  36. /* layout */
  37. 'date' => false,
  38. 'styleswitcherFont' => false,
  39. 'styleswitcherWidth' => false,
  40. 'layout' => 'left',
  41. /* style switcher */
  42. 'fontDefault' => 'font-medium',
  43. 'widthDefault' => 'width-wide',
  44. 'widthThinPx' => 780,
  45. 'widthWidePx' => 900,
  46. 'widthFluidPx' => 0.9,
  47. /* javascript */
  48. 'loadJavascript' => false,
  49. /* slimbox */
  50. 'loadSlimbox' => false
  51. );
  52. $this->javascript = array(
  53. /* color */
  54. "color" => "'<VAL>'",
  55. /* layout */
  56. "layout" => "'<VAL>'",
  57. /* style switcher */
  58. "fontDefault" => "'<VAL>'",
  59. "widthDefault" => "'<VAL>'",
  60. "widthThinPx" => "<VAL>",
  61. "widthWidePx" => "<VAL>",
  62. "widthFluidPx" => "<VAL>"
  63. );
  64. /* ie browser checks */
  65. if (array_key_exists('HTTP_USER_AGENT', $_SERVER)) {
  66. $this->defaults['msie7'] = strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'msie 7') !== false;
  67. $this->defaults['msie6'] = strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'msie 6') !== false;
  68. } else {
  69. $this->defaults['msie7'] = false;
  70. $this->defaults['msie6'] = false;
  71. }
  72. $this->settings = $settings + $this->defaults;
  73. }
  74. function &getInstance($settings = array()) {
  75. static $instance;
  76. if ($instance == null) {
  77. $instance = new YOOTools($settings);
  78. }
  79. return $instance;
  80. }
  81. function getParam($key, $default = '') {
  82. if (array_key_exists($key, $this->settings)) {
  83. return $this->settings[$key];
  84. }
  85. return $default;
  86. }
  87. function setParam($key, $value = '') {
  88. $this->settings[$key] = $value;
  89. }
  90. /* Javascript */
  91. function getJavaScript() {
  92. $js = "var YtSettings = { ";
  93. $seperator = false;
  94. foreach($this->javascript as $key => $val) {
  95. $setting = $this->getParam($key);
  96. if(is_bool($setting)) {
  97. $setting ? $setting = "true" : $setting = "false";
  98. }
  99. if(is_float($setting)) {
  100. $setting = number_format($setting, 2, ".", "");
  101. }
  102. $seperator ? $js .= ", " : $seperator = true;
  103. $js .= $key . ": " . str_replace("<VAL>", $setting, $val);
  104. }
  105. $js .= " };";
  106. return $js;
  107. }
  108. function showJavaScript() {
  109. echo $this->getJavaScript();
  110. }
  111. /* Styles */
  112. function setStyle($condition, $key, $value)
  113. {
  114. if ($this->evalStyleCondition($condition)) {
  115. $this->setParam($key, $value);
  116. }
  117. }
  118. function evalStyleCondition($condition)
  119. {
  120. if (is_bool($condition)) return $condition;
  121. $parts = explode(' ', $condition);
  122. $commands = array('+', '-', '&&', '||', '(', ')', '==', '!=');
  123. for($i = 0; $i < count($parts); $i++) {
  124. if (!(in_array($parts[$i], $commands) || is_numeric($parts[$i]))) {
  125. $name = strtolower($parts[$i]);
  126. $parts[$i] = mosCountModules($name);
  127. }
  128. }
  129. $str = 'return '.implode(' ', $parts).';';
  130. return eval($str);
  131. }
  132. /* Styleswitcher */
  133. function getCurrentStyle() {
  134. $styleFont = isset($_COOKIE['ytstylefont']) ? $_COOKIE['ytstylefont'] : $this->getParam('fontDefault');
  135. $styleWidth = isset($_COOKIE['ytstylewidth']) ? $_COOKIE['ytstylewidth'] : $this->getParam('widthDefault');
  136. return $styleFont . " " . $styleWidth;
  137. }
  138. function getCurrentColor() {
  139. $color = isset($_COOKIE['ytcolor']) ? $_COOKIE['ytcolor'] : $this->getParam('color');
  140. if(isset($_GET['yt_color'])) {
  141. setcookie('ytcolor', $_GET['yt_color'], time() + 3600, '/');
  142. $color = $_GET['yt_color'];
  143. }
  144. return $color;
  145. }
  146. function getCurrentToolsColor() {
  147. $tools = $this->getParam('tools');
  148. if (is_array($tools) && array_key_exists($this->getCurrentColor(), $tools)) {
  149. return $tools[$this->getCurrentColor()];
  150. }
  151. return '';
  152. }
  153. function getActiveMenuItemNumber($menu, $level) {
  154. global $database, $my, $Itemid, $mosConfig_shownoauth;
  155. $and = '';
  156. if (!$mosConfig_shownoauth) {
  157. $and = "\n AND access <= $my->gid";
  158. }
  159. $sql = "SELECT m.* FROM #__menu AS m"
  160. . "\n WHERE menutype = '" . $menu . "'"
  161. . "\n AND published = 1"
  162. . $and
  163. . "\n ORDER BY parent, ordering";
  164. $database->setQuery($sql);
  165. $rows = $database->loadObjectList('id');
  166. $path = array();
  167. $item_id = $Itemid;
  168. while ($item_id != 0) {
  169. if (array_key_exists($item_id, $rows)) {
  170. $path[] = $item_id;
  171. $item_id = $rows[$item_id]->parent;
  172. } else {
  173. break;
  174. }
  175. }
  176. $path = array_reverse($path);
  177. if (array_key_exists($level, $path)) {
  178. return $rows[$path[$level]]->id;
  179. }
  180. return null;
  181. }
  182. function getMenuLabel($menu, $level = 0){
  183. return $this->getParam('item' . $this->getActiveMenuItemNumber($menu, $level));
  184. }
  185. /* Html helper */
  186. function setStyleSheet($template_baseurl){
  187. global $option;
  188. $this->addStyleSheet($template_baseurl . '/css/template.css.php?color=' . $this->getParam('color')
  189. . '&amp;styleswitcherFont=' . $this->getParam('styleswitcherFont')
  190. . '&amp;styleswitcherWidth=' . $this->getParam('styleswitcherWidth')
  191. . '&amp;widthThinPx=' . $this->getParam('widthThinPx')
  192. . '&amp;widthWidePx=' . $this->getParam('widthWidePx')
  193. . '&amp;widthFluidPx=' . $this->getParam('widthFluidPx')
  194. . '&amp;leftWidth=' . $this->getParam('leftWidth')
  195. . '&amp;rightWidth=' . $this->getParam('rightWidth')
  196. . '&amp;option=' . $option);
  197. }
  198. function getYooModules(){
  199. global $mosConfig_absolute_path, $mosConfig_live_site;
  200. if(file_exists($mosConfig_absolute_path.'/modules/mod_yoo_slider/mod_yoo_slider.css.php')){
  201. $this->addStyleSheet($mosConfig_live_site.'/modules/mod_yoo_slider/mod_yoo_slider.css.php');
  202. }
  203. if(file_exists($mosConfig_absolute_path.'/modules/mod_yoo_slider/mod_yoo_login.css.php')){
  204. $this->addStyleSheet($mosConfig_live_site.'/modules/mod_yoo_slider/mod_yoo_login.css.php');
  205. }
  206. if(file_exists($mosConfig_absolute_path.'/modules/mod_yoo_slider/mod_yoo_drawer.css.ph')){
  207. $this->addStyleSheet($mosConfig_live_site.'/modules/mod_yoo_slider/mod_yoo_drawer.css.ph');
  208. }
  209. if(file_exists($mosConfig_absolute_path.'/modules/mod_yoo_slider/mod_yoo_carousel.css.php')){
  210. $this->addStyleSheet($mosConfig_live_site.'/modules/mod_yoo_slider/mod_yoo_carousel.css.php');
  211. }
  212. if(file_exists($mosConfig_absolute_path.'/modules/mod_yoo_slider/mod_yoo_toppanel.css.php')){
  213. $this->addStyleSheet($mosConfig_live_site.'/modules/mod_yoo_slider/mod_yoo_toppanel.css.php');
  214. }
  215. if(file_exists($mosConfig_absolute_path.'/modules/mod_yoo_slider/mod_yoo_accordion.css.php')){
  216. $this->addStyleSheet($mosConfig_live_site.'/modules/mod_yoo_slider/mod_yoo_accordion.css.php');
  217. }
  218. }
  219. function addStyleSheet($data, $condition = true, $browser = '') {
  220. $this->stylesheets[] = array('data' => $data, 'condition' => $condition, 'browser' => $browser);
  221. }
  222. function addScript($data, $condition = true, $browser = '') {
  223. $this->scripts[] = array('data' => $data, 'condition' => $condition, 'browser' => $browser);
  224. }
  225. function showHead() {
  226. $html = '';
  227. foreach ($this->stylesheets as $style) {
  228. if ($style['condition']) {
  229. $html_tag = '<link href="' . $style['data'] . '" rel="stylesheet" type="text/css" />';
  230. $html .= $this->wrapBrowserCondition($style['browser'], $html_tag);
  231. }
  232. }
  233. foreach ($this->scripts as $script) {
  234. if ($script['condition']) {
  235. if (ereg("[.js|.php]\$", $script['data'])) {
  236. $html_tag = '<script language="javascript" src="' . $script['data'] . '" type="text/javascript"></script>';
  237. } else {
  238. $html_tag = '<script language="javascript" type="text/javascript">' . $script['data'] . '</script>';
  239. }
  240. $html .= $this->wrapBrowserCondition($script['browser'], $html_tag);
  241. }
  242. }
  243. echo $html;
  244. }
  245. function wrapBrowserCondition($browser, $html_tag) {
  246. $html = '';
  247. switch ($browser) {
  248. case 'msie':
  249. if ($this->getParam('msie6') || $this->getParam('msie7')) {
  250. $html = '<!--[if lte IE 7]>' . $html_tag . '<![endif]-->' . "\n";
  251. }
  252. break;
  253. case 'msie6':
  254. if ($this->getParam('msie6')) {
  255. $html = '<!--[if IE 6]>' . $html_tag . '<![endif]-->' . "\n";
  256. }
  257. break;
  258. case 'msie7':
  259. if ($this->getParam('msie7')) {
  260. $html = '<!--[if IE 7]>' . $html_tag . '<![endif]-->' . "\n";
  261. }
  262. break;
  263. default:
  264. $html = $html_tag . "\n";
  265. break;
  266. }
  267. return $html;
  268. }
  269. function setHeader($type = 'html') {
  270. $content_type = 'text/html';
  271. if ($type == 'css') $content_type = 'text/css; charset: UTF-8';
  272. if ($type == 'js') $content_type = 'application/x-javascript';
  273. if (extension_loaded('zlib') && !ini_get('zlib.output_compression')) @ob_start('ob_gzhandler');
  274. header('Content-type: '.$content_type);
  275. header('Expires: '.gmdate('D, d M Y H:i:s', time() + 86400).' GMT');
  276. }
  277. function checkModules($position, $size = 0, $showsize=0){
  278. //Check if we have checked this module position before
  279. if(!isset($this->modules[$position])){
  280. //Create a module class to store
  281. $module = new stdClass();
  282. $module->on = mosCountModules($position) > 0;
  283. $module->show = 0;
  284. $module->length = 0;
  285. //If module position has modules to show, check their output
  286. if($module->on){
  287. //Buffer the module output
  288. ob_start();
  289. mosLoadModules($position, -1);
  290. $tmp = trim(preg_replace('/\\r|\\n/','',ob_end_clean()));
  291. //Set the output var = 1 if the module output is greater than $size
  292. $module->show = (strlen($tmp) > $size);
  293. }
  294. $this->modules[$position] = $module;
  295. }
  296. return $this->modules[$position]->show;
  297. }
  298. }
  299. ?>