PageRenderTime 78ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/php/cmsimple/functions.php

https://bitbucket.org/chiamingyen/cmsimple-and-plugins
PHP | 330 lines | 235 code | 47 blank | 48 comment | 25 complexity | 562bac6daba0ed539e67e74725b87a79 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: functions.php 248 2012-08-08 18:04:57Z cmb69 $
  4. */
  5. /* utf8-marker = äöü */
  6. /*
  7. ======================================
  8. CMSimple_XH 1.5.5
  9. 2012-10-16
  10. based on CMSimple version 3.3 - December 31. 2009
  11. For changelog, downloads and information please see http://www.cmsimple-xh.com
  12. ======================================
  13. -- COPYRIGHT INFORMATION START --
  14. Based on CMSimple version 3.3 - December 31. 2009
  15. Small - simple - smart
  16. © 1999-2009 Peter Andreas Harteg - peter@harteg.dk
  17. This file is part of CMSimple_XH
  18. For licence see notice in /cmsimple/cms.php
  19. -- COPYRIGHT INFORMATION END --
  20. ======================================
  21. */
  22. if (preg_match('/functions.php/i', sv('PHP_SELF')))
  23. die('Access Denied');
  24. // Backward compatibility for DHTML menus - moved from functions.php to cms.php (CMSimple_XH 1.0)
  25. // #CMSimple functions to use within content
  26. function geturl($u) {
  27. $t = '';
  28. if ($fh = @fopen(preg_replace("/\&amp;/is", "&", $u), "r")) {
  29. while (!feof($fh))
  30. $t .= fread($fh, 1024);
  31. fclose($fh);
  32. return preg_replace("/.*<body[^>]*>(.*)<\/body>.*/is", "\\1", $t);
  33. }
  34. }
  35. function geturlwp($u) {
  36. global $su;
  37. $t = '';
  38. if ($fh = @fopen($u . '?' . preg_replace("/^" . preg_quote($su, '/') . "(\&)?/s", "", sv('QUERY_STRING')), "r")) {
  39. while (!feof($fh))
  40. $t .= fread($fh, 1024);
  41. fclose($fh);
  42. return $t;
  43. }
  44. }
  45. function autogallery($u) {
  46. global $su;
  47. trigger_error('Function autogallery() is deprecated', E_USER_DEPRECATED);
  48. return preg_replace("/.*<!-- autogallery -->(.*)<!-- \/autogallery -->.*/is", "\\1", preg_replace("/(option value=\"\?)(p=)/is", "\\1" . $su . "&\\2", preg_replace("/(href=\"\?)/is", "\\1" . $su . '&amp;', preg_replace("/(src=\")(\.)/is", "\\1" . $u . "\\2", geturlwp($u)))));
  49. }
  50. // Other functions
  51. function h($n) {
  52. global $h;
  53. return $h[$n];
  54. }
  55. function l($n) {
  56. global $l;
  57. return $l[$n];
  58. }
  59. /**
  60. * Returns $__text with CMSimple scripting evaluated.
  61. *
  62. * @param string $__text
  63. * @param bool $__compat Wether only last CMSimple script should be evaluated.
  64. * @return string
  65. */
  66. function evaluate_cmsimple_scripting($__text, $__compat = TRUE) {
  67. global $output;
  68. foreach ($GLOBALS as $__name => $__dummy) {global $$__name;}
  69. $__scope_before = NULL; // just that it exists
  70. $__scripts = array();
  71. preg_match_all('~'.$cf['scripting']['regexp'].'~is', $__text, $__scripts);
  72. if (count($__scripts[1]) > 0) {
  73. //$output = preg_replace('~'.$cf['scripting']['regexp'].'~is', '', $__text);
  74. $output = preg_replace('~#CMSimple (?!hide)(.*?)#~is', '', $__text);
  75. if ($__compat) {$__scripts[1] = array_reverse($__scripts[1]);}
  76. foreach ($__scripts[1] as $__script) {
  77. if (strtolower($__script) !== 'hide' && strtolower($__script) !== 'remove') {
  78. $__script = preg_replace(
  79. array("'&(quot|#34);'i", "'&(amp|#38);'i", "'&(apos|#39);'i", "'&(lt|#60);'i", "'&(gt|#62);'i", "'&(nbsp|#160);'i"),
  80. array("\"", "&", "'", "<", ">", " "),
  81. $__script);
  82. $__scope_before = array_keys(get_defined_vars());
  83. eval($__script);
  84. $__scope_after = array_keys(get_defined_vars());
  85. $__diff = array_diff($__scope_after, $__scope_before);
  86. foreach ($__diff as $__var) {$GLOBALS[$__var] = $$__var;}
  87. if ($__compat) {break;}
  88. }
  89. }
  90. $eval_script_output = $output;
  91. $output = '';
  92. return $eval_script_output;
  93. }
  94. return $__text;
  95. }
  96. /**
  97. * Returns $__text with all plugin calls evaluatated.
  98. * see plugins/index.php preCallPlugins()
  99. *
  100. * @param string $__text
  101. * @return string
  102. */
  103. function evaluate_plugincall($__text) {
  104. global $u;
  105. $error = ' <span style="color:#5b0000; font-size:14px;">{{CALL TO:<span style="color:#c10000;">{{%1}}</span> FAILED}}</span> '; //use this for debugging of failed plugin-calls
  106. $pl_regex = '"{{{RGX:CALL(.*?)}}}"is'; //general CALL-RegEx (Placeholder: "RGX:CALL")
  107. $pl_calls = array(
  108. 'PLUGIN:' => 'return {{%1}}',
  109. 'HOME:' => 'return trim(\'<a href="?' . $u[0] . '" title="' . urldecode('{{%1}}') . '">' . urldecode('{{%1}}') . '</a>\');',
  110. 'HOME' => 'return trim(\'<a href="?' . $u[0] . '" title="' . urldecode($u[0]) . '">' . urldecode($u[0]) . '</a>\');'
  111. );
  112. $fd_calls = array();
  113. foreach ($pl_calls AS $regex => $call) {
  114. preg_match_all(str_replace("RGX:CALL", $regex, $pl_regex), $__text, $fd_calls[$regex]); //catch all PL-CALLS
  115. foreach ($fd_calls[$regex][0] AS $call_nr => $replace) {
  116. $call = str_replace("{{%1}}", $fd_calls[$regex][1][$call_nr], $pl_calls[$regex]);
  117. $fnct_call = preg_replace('"(?:(?:return)\s)*(.*?)\(.*?\);"is', '$1', $call);
  118. $fnct = function_exists($fnct_call) ? TRUE : FALSE; //without object-calls; functions-only!!
  119. if ($fnct) {
  120. preg_match_all("/\\$([a-z_0-9]*)/i", $call, $matches);
  121. foreach ($matches[1] as $var) {
  122. global $$var;
  123. }
  124. }
  125. $__text = str_replace(
  126. $replace,
  127. $fnct
  128. ? eval(str_replace('{{%1}}', $fd_calls[$regex][1][$call_nr], $pl_calls[$regex]))
  129. : str_replace('{{%1}}', $regex . $fd_calls[$regex][1][$call_nr], $error),
  130. $__text); //replace PL-CALLS (String only!!)
  131. }
  132. }
  133. return $__text;
  134. }
  135. /**
  136. * Returns $text with CMSimple scripting and plugin calls evaluated.
  137. *
  138. * @param string $text
  139. * @param bool $compat Wheter only last CMSimple script will be evaluated.
  140. * @return void
  141. */
  142. function evaluate_scripting($text, $compat = TRUE) {
  143. return evaluate_cmsimple_scripting(evaluate_plugincall($text), $compat);
  144. }
  145. /**
  146. * Returns content of the first CMSimple page with the heading $heading
  147. * with the heading removed and all scripting evaluated.
  148. * Returns FALSE, if the page doesn't exist.
  149. *
  150. * @param string $heading
  151. * @return mixed
  152. */
  153. function newsbox($heading) {
  154. global $c, $cl, $h, $cf, $edit;
  155. for ($i = 0; $i < $cl; $i++) {
  156. if ($h[$i] == $heading) {
  157. $body = preg_replace("/.*<\/h[1-".$cf['menu']['levels']."]>/is", "", $c[$i]);
  158. return $edit ? $body : preg_replace("/".$cf['scripting']['regexp']."/is", "", evaluate_scripting($body, FALSE));
  159. }
  160. }
  161. return FALSE;
  162. }
  163. // includes additional userfuncs.php - CMSimple_XH beta3
  164. if (file_exists($pth['folder']['cmsimple'] . 'userfuncs.php')) {
  165. include($pth['folder']['cmsimple'] . 'userfuncs.php');
  166. }
  167. // EDITOR CALL
  168. function init_editor($elementClasses = array(), $initFile = false){
  169. global $pth, $cf;
  170. if (!file_exists($pth['folder']['plugins'] . $cf['editor']['external'] . '/init.php')) {
  171. return false;
  172. }
  173. include_once $pth['folder']['plugins'] . $cf['editor']['external'] . '/init.php';
  174. $function = 'init_' . $cf['editor']['external'];
  175. if (!function_exists($function)){
  176. return false;
  177. }
  178. $function($elementClasses, $initFile);
  179. return true;
  180. }
  181. function include_editor(){
  182. global $pth, $cf;
  183. if (!file_exists($pth['folder']['plugins'] . $cf['editor']['external'] . '/init.php')) {
  184. return false;
  185. }
  186. include_once $pth['folder']['plugins'] . $cf['editor']['external'] . '/init.php';
  187. $function = 'include_' . $cf['editor']['external'];
  188. if (!function_exists($function)){
  189. return false;
  190. }
  191. $function();
  192. return true;
  193. }
  194. function editor_replace($elementID = false, $config = ''){
  195. global $pth, $cf;
  196. if(!$elementID) {
  197. trigger_error('No elementID given', E_USER_NOTICE);
  198. return false;
  199. }
  200. if (!file_exists($pth['folder']['plugins'] . $cf['editor']['external'] . '/init.php')) {
  201. return false;
  202. }
  203. include_once $pth['folder']['plugins'] . $cf['editor']['external'] . '/init.php';
  204. $function = $cf['editor']['external'] . '_replace';
  205. if (!function_exists($function)){
  206. return false;
  207. }
  208. return $function($elementID, $config);
  209. }
  210. /**
  211. * Returns the result view of the system check.
  212. *
  213. * @access public
  214. * @since 1.5.4
  215. * @param array $data
  216. * @return string The (X)HTML.
  217. */
  218. function XH_systemCheck($data)
  219. {
  220. global $pth, $tx;
  221. $stx = $tx['syscheck'];
  222. foreach (array('ok', 'warning', 'failure') as $img) {
  223. $txt = ucfirst($img);
  224. $imgs[$img] = tag('img src="' . $pth['folder']['flags'] . $img . '.gif" alt="'
  225. . $txt . '" title="' . $txt . '" width="16" height="16"');
  226. }
  227. $o = "<h4>$stx[title]</h4>\n<ul id=\"xh_system_check\">\n";
  228. if (key_exists('phpversion', $data)) {
  229. $ok = version_compare(PHP_VERSION, $data['phpversion']) >= 0;
  230. $o .= '<li>' . $imgs[$ok ? 'ok' : 'fail']
  231. . sprintf($stx['phpversion'], $data['phpversion']) . "</li>\n";
  232. }
  233. if (key_exists('extensions', $data)) {
  234. $cat = ' class="xh_system_check_cat_start"';
  235. foreach ($data['extensions'] as $ext) {
  236. if (is_array($ext)) {
  237. $notok = $ext[1] ? 'failure' : 'warning';
  238. $ext = $ext[0];
  239. } else {
  240. $notok = 'failure';
  241. }
  242. $o .= '<li' . $cat . '>' . $imgs[extension_loaded($ext) ? 'ok' : $notok]
  243. . sprintf($stx['extension'], $ext) . "</li>\n";
  244. $cat = '';
  245. }
  246. }
  247. if (key_exists('writable', $data)) {
  248. $cat = ' class="xh_system_check_cat_start"';
  249. foreach ($data['writable'] as $file) {
  250. if (is_array($file)) {
  251. $notok = $file[1] ? 'failure' : 'warning';
  252. $file = $file[0];
  253. } else {
  254. $notok = 'warning';
  255. }
  256. $o .= '<li' . $cat . '>' . $imgs[is_writable($file) ? 'ok' : $notok]
  257. . sprintf($stx['writable'], $file) . "</li>\n";
  258. $cat = '';
  259. }
  260. }
  261. if (key_exists('other', $data)) {
  262. $cat = ' class="xh_system_check_cat_start"';
  263. foreach ($data['other'] as $check) {
  264. $notok = $check[1] ? 'failure' : 'warning';
  265. $o .= '<li' . $cat . '>' . $imgs[$check[0] ? 'ok' : $notok]
  266. . $check[2] . "</li>\n";
  267. $cat = '';
  268. }
  269. }
  270. $o .= "</ul>\n";
  271. return $o;
  272. }
  273. ?>