PageRenderTime 82ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins/function.content.php

https://github.com/tedkulp/cmsmadesimple-2-0
PHP | 282 lines | 119 code | 19 blank | 144 comment | 32 complexity | 7991c40e8a8f293ec5801b4591597db9 MD5 | raw file
  1. <?php
  2. #CMS - CMS Made Simple
  3. #(c)2004 by Ted Kulp (wishy@users.sf.net)
  4. #This project's homepage is: http://cmsmadesimple.sf.net
  5. #
  6. #This program is free software; you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation; either version 2 of the License, or
  9. #(at your option) any later version.
  10. #
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. #GNU General Public License for more details.
  15. #You should have received a copy of the GNU General Public License
  16. #along with this program; if not, write to the Free Software
  17. #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. function smarty_function_content($params, &$smarty)
  19. {
  20. $request = cms_request();
  21. $page = $smarty->get_template_vars('current_page');
  22. if ($page != null)
  23. {
  24. $block_name = 'default';
  25. if (isset($params['name']))
  26. {
  27. $block_name = $params['name'];
  28. }
  29. else if (isset($params['block']))
  30. {
  31. $block_name = $params['block'];
  32. }
  33. $block_name = strtolower(str_replace(' ', '_', $block_name));
  34. $id = '';
  35. $module_name = '';
  36. $action = '';
  37. $inline = false;
  38. if ($request->has('request:module'))
  39. $modulename = $request->get('request:module');
  40. if ($request->has('request:id'))
  41. {
  42. $id = $request->get('request:id');
  43. }
  44. else if ($request->has('request:mact'))
  45. {
  46. $ary = explode(',', cms_htmlentities($request->get('request:mact')), 4);
  47. $module_name = (isset($ary[0]) ? $ary[0] : '');
  48. $id = (isset($ary[1]) ? $ary[1] : '');
  49. $action = (isset($ary[2]) ? $ary[2] : '');
  50. $inline = (isset($ary[3]) && $ary[3] == 1 ? true : false);
  51. }
  52. if ($request->has('request:'.$id.'action'))
  53. $action = $request->get('request:'.$id.'action');
  54. else if ($request->has('request:action'))
  55. $action = $request->get('request:action');
  56. $target_block = 'default';
  57. if ($request->has('request:'.$id.'target'))
  58. {
  59. //Only if it actually exists do we use it... just in case the template was changed we want to
  60. //make sure the module still shows up
  61. $blocks = $page->template->get_page_blocks();
  62. foreach ($blocks as $block_name)
  63. {
  64. if ($request->get('request:'.$id.'target') == $block_name)
  65. {
  66. $target_block = $request->get('request:'.$id.'target');
  67. }
  68. }
  69. }
  70. $target_block = strtolower(str_replace(' ', '_', $target_block));
  71. //Only consider doing module processing if
  72. //a. this is the target block
  73. //b. then
  74. // 1. $id is cntnt01
  75. // 2. or inline is false
  76. if ($block_name == $target_block && ($id == 'cntnt01' || ($id != '' && $inline == false)))
  77. {
  78. if (CmsModuleLoader::is_active($module_name) &&
  79. CmsModuleLoader::get_module_info($module_name, 'plugin_module') == true)
  80. {
  81. $module = CmsModuleLoader::get_module_class($module_name);
  82. if ($module)
  83. {
  84. @ob_start();
  85. $params = array_merge($params, GetModuleParameters($id));
  86. $return_id = '';
  87. if (isset($params['returnid']))
  88. {
  89. $return_id = $params['returnid'];
  90. }
  91. else
  92. {
  93. $return_id = $page->id;
  94. }
  95. if (CmsModuleLoader::get_module_info($module_name, 'old_module'))
  96. {
  97. echo $module->DoActionBase($action, $id, $params, $return_id);
  98. }
  99. else
  100. {
  101. $module->set_id($id, $return_id);
  102. echo $module->run_action($action, $params);
  103. }
  104. $content = @ob_get_contents();
  105. @ob_end_clean();
  106. }
  107. }
  108. }
  109. else
  110. {
  111. $content = $page->render_block($block_name);
  112. }
  113. if (isset($params['assign']) && !empty($params['assign']))
  114. {
  115. $smarty->assign($params['assign'], $content);
  116. return '';
  117. }
  118. else
  119. {
  120. return $content;
  121. }
  122. }
  123. /*
  124. $gCms = cmsms();
  125. $pageinfo = $gCms->current_page;
  126. if (isset($pageinfo) && $pageinfo !== FALSE)
  127. {
  128. $id = '';
  129. $modulename = '';
  130. $action = '';
  131. $inline = false;
  132. if (isset($_REQUEST['module'])) $modulename = $_REQUEST['module'];
  133. if (isset($_REQUEST['id']))
  134. {
  135. $id = $_REQUEST['id'];
  136. }
  137. elseif (isset($_REQUEST['mact']))
  138. {
  139. $ary = explode(',', cms_htmlentities($_REQUEST['mact']), 4);
  140. $modulename = (isset($ary[0])?$ary[0]:'');
  141. $id = (isset($ary[1])?$ary[1]:'');
  142. $action = (isset($ary[2])?$ary[2]:'');
  143. $inline = (isset($ary[3]) && $ary[3] == 1?true:false);
  144. }
  145. if (isset($_REQUEST[$id.'action'])) $action = $_REQUEST[$id.'action'];
  146. else if (isset($_REQUEST['action'])) $action = $_REQUEST['action'];
  147. //Only consider doing module processing if
  148. //a. There is no block parameter
  149. //b. then
  150. // 1. $id is cntnt01
  151. // 2. or inline is false
  152. if (!isset($params['block']) && ($id == 'cntnt01' || ($id != '' && $inline == false)))
  153. {
  154. $cmsmodules = &$gCms->modules;
  155. if (isset($cmsmodules))
  156. {
  157. foreach ($cmsmodules as $key=>$value)
  158. {
  159. if (strtolower($modulename) == strtolower($key))
  160. {
  161. $modulename = $key;
  162. }
  163. }
  164. if (!isset($modulename) || empty($modulename) ||
  165. !isset($cmsmodules[$modulename]))
  166. {
  167. // module not found
  168. @trigger_error('Attempt to access module '.$modulename.' which could not be foune (is it properly installed and configured?');
  169. return _smarty_function_content_return('', $params, $smarty);
  170. }
  171. if (isset($cmsmodules[$modulename]))
  172. {
  173. if (isset($cmsmodules[$modulename]['object'])
  174. && $cmsmodules[$modulename]['installed'] == true
  175. && $cmsmodules[$modulename]['active'] == true
  176. && $cmsmodules[$modulename]['object']->IsPluginModule())
  177. {
  178. @ob_start();
  179. unset($params['block']);
  180. unset($params['label']);
  181. unset($params['wysiwyg']);
  182. unset($params['oneline']);
  183. unset($params['default']);
  184. unset($params['size']);
  185. $params = array_merge($params, GetModuleParameters($id));
  186. //$params = GetModuleParameters($id);
  187. $returnid = '';
  188. if (isset($params['returnid']))
  189. {
  190. $returnid = $params['returnid'];
  191. }
  192. else
  193. {
  194. $returnid = $pageinfo->id;
  195. }
  196. $result = $cmsmodules[$modulename]['object']->DoActionBase($action, $id, $params, $returnid);
  197. if ($result !== FALSE)
  198. {
  199. echo $result;
  200. }
  201. $modresult = @ob_get_contents();
  202. @ob_end_clean();
  203. return _smarty_function_content_return($modresult, $params, $smarty);
  204. }
  205. else
  206. {
  207. @trigger_error('Attempt to access module '.$key.' which could not be foune (is it properly installed and configured?');
  208. return _smarty_function_content_return("<!-- Not a tag module -->\n", $params, $smarty);
  209. }
  210. }
  211. }
  212. }
  213. else
  214. {
  215. $result = '';
  216. $oldvalue = $smarty->caching;
  217. $smarty->caching = false;
  218. $result = $smarty->fetch(str_replace(' ', '_', 'content:' . (isset($params['block'])?$params['block']:'content_en')), '', $pageinfo->id);
  219. $smarty->caching = $oldvalue;
  220. return _smarty_function_content_return($result, $params, $smarty);
  221. }
  222. }
  223. return _smarty_function_content_return('', $params, $smarty);
  224. */
  225. }
  226. /*
  227. function _smarty_function_content_return($result, &$params, &$smarty)
  228. {
  229. if ( empty($params['assign']) )
  230. {
  231. return $result;
  232. }
  233. else
  234. {
  235. $smarty->assign($params['assign'], $result);
  236. return '';
  237. }
  238. }
  239. */
  240. function smarty_help_function_content()
  241. {
  242. echo lang('help_function_content');
  243. }
  244. function smarty_about_function_content()
  245. {
  246. ?>
  247. <p>Author: Ted Kulp&lt;tedkulp@users.sf.net&gt;</p>
  248. <p>Version: 1.1</p>
  249. <p>
  250. Change History:<br/>
  251. 1.1 - Added assign parameter from djnz's patch in the forge<br />
  252. 1.0 - Initial version
  253. </p>
  254. <?php
  255. }
  256. # vim:ts=4 sw=4 noet
  257. ?>