PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/xthemes/trunk/controller.php

http://bitcero-modules.googlecode.com/
PHP | 207 lines | 110 code | 45 blank | 52 comment | 19 complexity | 0801b8b41a5490778d7bb89b763d1276 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. // $Id: controller.php 15 2009-09-11 18:16:01Z i.bitcero $
  3. // --------------------------------------------------------------
  4. // I.Themes
  5. // Module for manage themes by Red Mexico
  6. // Author: Eduardo Cort?Šs <i.bitcero@gmail.com>
  7. // License: GPL v2
  8. // --------------------------------------------------------------
  9. defined('XOOPS_ROOT_PATH') or die("");
  10. /**
  11. * Next are standar functions for all themes or templates.
  12. *
  13. * Is possible add new functionallities to I.Themes by adding new plugins
  14. * directly on "plugins" directory
  15. *
  16. * The correct way for call functions from this controller (including plugins)
  17. * from you theme is:
  18. *
  19. * <{xthemes_process action="function_name" data="array_of_parameters"}>
  20. */
  21. include_once XOOPS_ROOT_PATH.'/modules/xthemes/include/functions.php';
  22. include_once XOOPS_ROOT_PATH.'/modules/xthemes/class/theme.php';
  23. class XThemesController
  24. {
  25. /**
  26. * Cache for configurations
  27. * @var mixed
  28. */
  29. private $configs = array();
  30. /**
  31. * Cache for objects
  32. */
  33. private $objects = array();
  34. /**
  35. * Singleton
  36. */
  37. public function get(){
  38. static $instance;
  39. if (!isset($instance)){
  40. $instance = new XThemesController();
  41. }
  42. return $instance;
  43. }
  44. /**
  45. * Gets the theme configuration as an array
  46. */
  47. public function get_theme_config($name=''){
  48. global $xoopsConfig;
  49. if ($name!=''){
  50. $theme = $name;
  51. } else {
  52. $theme = $xoopsConfig['theme_set'];
  53. }
  54. $theme = preg_replace('/\s+/', '', $theme);
  55. $theme = str_replace('-','',$theme);
  56. $var = $theme.'Config';
  57. if (isset($this->configs[$theme])){
  58. return $this->configs[$theme];
  59. }
  60. if (false === ($object = xt_is_valid($theme)))
  61. return;
  62. $this->configs[$theme] = xt_get_current_config($theme);
  63. return $this->configs[$theme];
  64. }
  65. /**
  66. * Get theme configuration and assign to a smarty var
  67. *
  68. * @param object $smarty
  69. * @return none
  70. */
  71. function get_config(&$smarty, $params){
  72. global $xoopsConfig;
  73. if (isset($params['theme'])){
  74. $theme = $params['theme'];
  75. } else {
  76. $theme = $xoopsConfig['theme_set'];
  77. }
  78. $var = preg_replace('/\s+/', '', $theme);
  79. $var = str_replace('-','',$var);
  80. $var .= 'Config';
  81. if (isset($this->configs[$theme])){
  82. $smarty->assign($var, $this->configs[$theme]);
  83. return;
  84. }
  85. if (false === ($object = xt_is_valid($theme)))
  86. return;
  87. $this->configs[$theme] = xt_get_current_config($theme);
  88. $smarty->assign($var, $this->configs[$theme]);
  89. }
  90. /**
  91. * Load and run a plugin
  92. */
  93. function load_plugin(&$smarty, $params){
  94. $dir = strtolower($params['plugin']);
  95. $do = $params['do'];
  96. $pdir = ITPATH.'/plugins/'.$dir;
  97. if (!is_file($pdir.'/xthemes_plugin_'.$dir.'.php'))
  98. return;
  99. if (!xt_plugin_installed($dir))
  100. return;
  101. include_once $pdir.'/xthemes_plugin_'.$dir.'.php';
  102. $class = "xthemes".ucfirst($dir);
  103. if (!class_exists($class)) return;
  104. $plugin = new $class($smarty, array_slice($params, 1));
  105. return $plugin->execute();
  106. }
  107. /**
  108. * This function allows you to include a file
  109. */
  110. public function get_file(&$smarty, $params){
  111. global $xoopsConfig;
  112. $file = $params['file'];
  113. if (is_file(XOOPS_THEME_PATH.'/'.$xoopsConfig['theme_set'].'/'.$file))
  114. include_once XOOPS_THEME_PATH.'/'.$xoopsConfig['theme_set'].'/'.$file;
  115. elseif (is_file($file))
  116. include_once $file;
  117. else
  118. return;
  119. }
  120. /**
  121. * Run third party function
  122. */
  123. public function run_function(&$smarty, $params){
  124. global $xoopsConfig;
  125. $file = $params['file'];
  126. if (is_file(XOOPS_THEME_PATH.'/'.$xoopsConfig['theme_set'].'/'.$file))
  127. include_once XOOPS_THEME_PATH.'/'.$xoopsConfig['theme_set'].'/'.$file;
  128. elseif (is_file($file))
  129. include_once $file;
  130. else
  131. return;
  132. if (function_exists($params['function']))
  133. return $params['function']($smarty, $params);
  134. }
  135. /**
  136. * Run method from theme
  137. */
  138. public function run_method(&$smarty, $params){
  139. global $xoopsConfig;
  140. $theme = $xoopsConfig['theme_set'];
  141. $theme = preg_replace('/\s+/', '', $theme);
  142. $theme = str_replace('-','',$theme);
  143. $method = $params['method'];
  144. if (!isset($this->objects[$theme])){
  145. if (false === ($this->objects[$theme] = xt_is_valid($xoopsConfig['theme_set'])))
  146. return;
  147. }
  148. if (!method_exists($this->objects[$theme], $method))
  149. return;
  150. return $this->objects[$theme]->$method($smarty, $params);
  151. }
  152. /**
  153. * Generate script tags for jQuery
  154. */
  155. public function get_jquery($smarty, $params){
  156. $ret = '<script type="text/javascript" src="'.RMCURL.'/include/js/jquery.min.js"></script>';
  157. if ($params['ui']){
  158. $ret .= '<script type="text/javascript" src="'.RMCURL.'/include/js/jquery-ui.min.js"></script>';
  159. }
  160. return $ret;
  161. }
  162. }