PageRenderTime 35ms CodeModel.GetById 21ms RepoModel.GetById 0ms 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. // no direct access
  9. defined( '_VALID_MOS' ) or die( 'Restricted access' );
  10. class YOOTools {
  11. /* template stylesheets */
  12. var $stylesheets;
  13. /* template javascripts */
  14. var $scripts;
  15. /* yootheme global default template settings */
  16. var $defaults;
  17. /* javascript settings */
  18. var $javascript;
  19. /* template settings */
  20. var $settings;
  21. function YOOTools($settings = array()) {
  22. $this->stylesheets = array();
  23. $this->scripts = array();
  24. $this->defaults = array(
  25. /* color */
  26. "color" => "default",
  27. /* item color variation */
  28. "item1" => "grey",
  29. "item2" => "blue",
  30. "item3" => "pink",
  31. "item4" => "orange",
  32. "item5" => "green",
  33. "item6" => "default",
  34. "item7" => "default",
  35. "item8" => "default",
  36. "item9" => "default",
  37. "item10" => "default",
  38. /* layout */
  39. "date" => true,
  40. "styleswitcherFont" => true,
  41. "styleswitcherWidth" => true,
  42. "layout" => "left",
  43. /* style switcher */
  44. "fontDefault" => "font-medium",
  45. "widthDefault" => "width-wide",
  46. "widthThinPx" => 780,
  47. "widthWidePx" => 900,
  48. "widthFluidPx" => 0.9,
  49. /* javascript */
  50. "loadJavascript" => true
  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 getActiveMenuItemNumber($menu, $level) {
  147. global $database, $my, $Itemid, $mosConfig_shownoauth;
  148. $and = '';
  149. if (!$mosConfig_shownoauth) {
  150. $and = "\n AND access <= $my->gid";
  151. }
  152. $sql = "SELECT m.* FROM #__menu AS m"
  153. . "\n WHERE menutype = '" . $menu . "'"
  154. . "\n AND published = 1"
  155. . $and
  156. . "\n ORDER BY parent, ordering";
  157. $database->setQuery($sql);
  158. $rows = $database->loadObjectList('id');
  159. $path = array();
  160. $item_id = $Itemid;
  161. while ($item_id != 0) {
  162. if (array_key_exists($item_id, $rows)) {
  163. $path[] = $item_id;
  164. $item_id = $rows[$item_id]->parent;
  165. } else {
  166. break;
  167. }
  168. }
  169. $path = array_reverse($path);
  170. if (array_key_exists($level, $path)) {
  171. return $rows[$path[$level]]->ordering;
  172. }
  173. return null;
  174. }
  175. /* Html helper */
  176. function addStyleSheet($data, $condition = true, $browser = '') {
  177. $this->stylesheets[] = array('data' => $data, 'condition' => $condition, 'browser' => $browser);
  178. }
  179. function addScript($data, $condition = true, $browser = '') {
  180. $this->scripts[] = array('data' => $data, 'condition' => $condition, 'browser' => $browser);
  181. }
  182. function showHead() {
  183. $html = '';
  184. foreach ($this->stylesheets as $style) {
  185. if ($style['condition']) {
  186. $html_tag = '<link href="' . $style['data'] . '" rel="stylesheet" type="text/css" />';
  187. $html .= $this->wrapBrowserCondition($style['browser'], $html_tag);
  188. }
  189. }
  190. foreach ($this->scripts as $script) {
  191. if ($script['condition']) {
  192. if (ereg("[.js|.php]\$", $script['data'])) {
  193. $html_tag = '<script language="javascript" src="' . $script['data'] . '" type="text/javascript"></script>';
  194. } else {
  195. $html_tag = '<script language="javascript" type="text/javascript">' . $script['data'] . '</script>';
  196. }
  197. $html .= $this->wrapBrowserCondition($script['browser'], $html_tag);
  198. }
  199. }
  200. echo $html;
  201. }
  202. function wrapBrowserCondition($browser, $html_tag) {
  203. $html = '';
  204. switch ($browser) {
  205. case 'msie':
  206. if ($this->getParam('msie6') || $this->getParam('msie7')) {
  207. $html = '<!--[if lte IE 7]>' . $html_tag . '<![endif]-->' . "\n";
  208. }
  209. break;
  210. case 'msie6':
  211. if ($this->getParam('msie6')) {
  212. $html = '<!--[if IE 6]>' . $html_tag . '<![endif]-->' . "\n";
  213. }
  214. break;
  215. case 'msie7':
  216. if ($this->getParam('msie7')) {
  217. $html = '<!--[if IE 7]>' . $html_tag . '<![endif]-->' . "\n";
  218. }
  219. break;
  220. default:
  221. $html = $html_tag . "\n";
  222. break;
  223. }
  224. return $html;
  225. }
  226. }
  227. ?>