PageRenderTime 51ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/ php-ppcms/includes/functions/filter.function.php

http://php-ppcms.googlecode.com/
PHP | 560 lines | 513 code | 15 blank | 32 comment | 22 complexity | 094313a8d412520cfff0bb24a2bbb21c MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. * (c) 2009, jianyuzhu@gmail.com
  5. * All rights reserved
  6. * This script is part of the PPEMI project.
  7. ***************************************************************/
  8. //
  9. function func_filter_escape($value) {
  10. $pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/';
  11. $replace = '\\\$1';
  12. return preg_replace($pattern, $replace, $value);
  13. }
  14. //
  15. function func_filter_phrase($value) {
  16. $pattern = '/("|\\\)/';
  17. $replace = '\\\$1';
  18. return preg_replace($pattern, $replace, $value);
  19. }
  20. //
  21. function func_filter_replace($subject) {
  22. return str_replace(
  23. array('[', ']', '{', '}', '?', '$', '.', '|', '\\', '/', '\'', '"', '<', '>', '=', '_'),
  24. array('\[', '\]', '\{', '\}', '\?', '\\$', '\.', '\|', '\\', '\\/', '\'', '\\"', '\\<', '\\>', '\\=', '\_'),
  25. $subject);
  26. }
  27. //
  28. function func_filter_post_convert($content, $attachments_ids) {
  29. //$content = preg_replace("/(\{\{local\}\})(\d+)(\{\{\/local\}\})/i", "{{attach}}\\2{{/attach}}", $content);
  30. /*
  31. for($i=0, $n=sizeof($attachments_ids); $i<$n; $i++) {
  32. if( $attachments_ids[$i] > 0 ) {
  33. $content = preg_replace("/(\{\{local\}\})" . ($i+1) . "(\{\{\/local\}\})/i", "{{attach}}" . $attachments_ids[$i] . "{{/attach}}", $content);
  34. } else {
  35. $content = preg_replace("/(\{\{local\}\})" . ($i+1) . "(\{\{\/local\}\})/i", "", $content);
  36. }
  37. }
  38. $content = preg_replace("/(\{\{local\}\})(\d+)(\{\{\/local\}\})/i", "", $content);
  39. */
  40. for($i=0, $n=sizeof($attachments_ids); $i<$n; $i++) {
  41. if( $attachments_ids[$i] > 0 ) {
  42. $pattern[] = "/(\{\{local\}\})" . ($i+1) . "(\{\{\/local\}\})/i";
  43. $replacement[] = "{{attach}}" . $attachments_ids[$i] . "{{/attach}}";
  44. } else {
  45. $pattern[] = "/(\{\{local\}\})" . ($i+1) . "(\{\{\/local\}\})/i";
  46. $replacement[] = "";
  47. }
  48. }
  49. $content = preg_replace($pattern, $replacement, $content);
  50. $content = preg_replace("/(\{\{local\}\})(\d+)(\{\{\/local\}\})/i", "", $content);
  51. return $content;
  52. }
  53. function func_filter_get_attaches($content) {
  54. $attachments_ids = array();
  55. if( preg_match_all("/\{\{attach\}\}(\d+)\{\{\/attach\}\}/i", $content, $matches) ) {
  56. //$attachments_pattern = $matches['0'];
  57. $attachments_ids = $matches['1'];
  58. }
  59. return $attachments_ids;
  60. }
  61. function func_filter_attach_convert($content) {
  62. if( strlen($content) == 0 ) {
  63. return array($content, '', '');
  64. }
  65. $ids = array();
  66. $attrs = array();
  67. //<img height="401" border="0" width="400" id="attach_8" alt=" " src="../../images/resources/200812/894a25068c8c3606_vQbE6B8t.jpg" />
  68. if( preg_match_all("/\<img(.+?)\>/i", $content, $matches) ) {
  69. $c = 0;
  70. $pattern = $replacement = array();
  71. for($i=0, $n=sizeof($matches['1']); $i<$n; $i++) {
  72. $contentb = $matches['1'][$i];
  73. if( strpos($contentb, "attach_") !== false ) {
  74. $id = 0;
  75. $count = sizeof(preg_split("/ *=/i", trim($contentb))) - 1;
  76. $patternb = "";
  77. for($j=0; $j<$count; $j++) {
  78. $patternb .= " (.*)=\"(.*)\"";
  79. }
  80. $patternb = "/$patternb/i";
  81. if( preg_match_all($patternb, $contentb, $matchesb) ) {
  82. $c++;
  83. for($k=1, $m=sizeof($matchesb); $k<$m; $k=$k+2) {
  84. $attrs[$c][$matchesb[$k]['0']] = $matchesb[$k+1]['0'];
  85. if( $matchesb[$k]['0'] == 'id' ) {
  86. $id = substr($matchesb[$k+1]['0'], strlen('attach_'));
  87. }
  88. }
  89. }
  90. $pattern[] = "/\<img(.+?)attach\_" . $id . "(.+?)\>/";
  91. if( $id > 0 ) {
  92. $replacement[] = "{{attach}}" . $id . "{{/attach}}";
  93. } else {
  94. $replacement[] = "";
  95. }
  96. }
  97. }
  98. if( is_array($pattern) ) {
  99. $content = preg_replace($pattern, $replacement, $content);
  100. }
  101. }
  102. if( preg_match_all("/\{\{attach\}\}(\d+)\{\{\/attach\}\}/i", $content, $matches) ) {
  103. $ids = $matches['1'];
  104. }
  105. return array($content, $ids, $attrs);
  106. }
  107. function func_filter_convert_full($content, $isfront = true) {
  108. global $resObj;
  109. if( is_object($resObj) && get_class($resObj) == 'ResourceBase' ) {
  110. //
  111. } else {
  112. global $adb;
  113. include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'core.resource.class.php');
  114. $resObj = new CoreResourceBase();
  115. }
  116. //editor content replace
  117. //$content = preg_replace("/src\=\\\\\"(.*)images\/uploads\//", "src=\"" . CONFIG_URL_HTTP . "images/uploads/", $content);
  118. //$content = preg_replace("/src\=\\\\\"([\"\/\\\.])images\/uploads\//", "src=\"" . CONFIG_URL_HTTP . "images/uploads/", $content);
  119. //
  120. //$content = preg_replace("/src\=([\"\/\\\.])images\/uploads\//", "src=\"" . CONFIG_URL_HTTP . "images/uploads/", $content);
  121. //$content = str_replace(array('../../images/'), array(CONFIG_URL_HTTP . CONFIG_DIR_IMAGES), $content);
  122. //$content = str_replace(array('../images/'), array(CONFIG_URL_HTTP . CONFIG_DIR_IMAGES), $content);
  123. //
  124. $content = preg_replace("'<img(.+?)src=([\\\\])(.+?)images\/uploads\/(.+?)>'si", "<img$1src=$2\"" . CONFIG_URL_HTTP . "images/uploads/$4>", $content);
  125. //attach
  126. if( preg_match_all("/\{\{attach\}\}(\d+)\{\{\/attach\}\}/i", $content, $matches) ) {
  127. //$attachments_pattern = $matches['0'];
  128. $attachments_ids = $matches['1'];
  129. $attachments_idstmp = array_unique($attachments_ids);
  130. $attachments_arrtmp = $resObj->getItemsValues(array('ids' => $attachments_idstmp));
  131. if( is_array($attachments_arrtmp) ) {
  132. for($i=0, $n=sizeof($attachments_arrtmp); $i<$n; $i++) {
  133. if( strpos($attachments_arrtmp[$i]['resources_filetype'], "image") === false ) {
  134. if( $isfront == true ) {
  135. $attachments_arr[$attachments_arrtmp[$i]['resources_id']] = '<p class="attachfile" id="attach_' . $attachments_arrtmp[$i]['resources_id'] . '"><a href="' . CONFIG_URL_HTTP . 'resource/' . $attachments_arrtmp[$i]['resources_id'] . '" target="_blank">' . $attachments_arrtmp[$i]['resources_name'] . '</a></p>';
  136. } else {
  137. $attachments_arr[$attachments_arrtmp[$i]['resources_id']] = "{{attach}}" . $attachments_arrtmp[$i]['resources_id'] . "{{/attach}}";
  138. }
  139. } else {
  140. $attachments_arr[$attachments_arrtmp[$i]['resources_id']] = '<img class="attachimage" id="attach_' . $attachments_arrtmp[$i]['resources_id'] . '" src="' . CONFIG_URL_HTTP . CONFIG_DIR_IMAGES . 'resources/' . $attachments_arrtmp[$i]['resources_value'] . '">';
  141. }
  142. }
  143. }
  144. if( is_array($attachments_ids) ) {
  145. for($i=0, $n=sizeof($attachments_ids); $i<$n; $i++) {
  146. $attachments_pattern[] = "/(\{\{attach\}\})" . $attachments_ids[$i] . "(\{\{\/attach\}\})/";
  147. $attachments_replacement[] = $attachments_arr[$attachments_ids[$i]];
  148. }
  149. }
  150. $content = preg_replace($attachments_pattern, $attachments_replacement, $content);
  151. }
  152. //block
  153. if( $isfront == true && preg_match_all("/\{\{block\}\}(\d+)\{\{\/block\}\}/i", $content, $matches) ) {
  154. include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/block/block.class.php');
  155. $blkObj = new BlockBase();
  156. $blkObj->format = true;
  157. //$blocks_pattern = $matches['0'];
  158. $blocks_ids = $matches['1'];
  159. $blocks_idstmp = array_unique($blocks_ids);
  160. $blocks_arrtmp = $blkObj->getItems(array('ids' => $blocks_idstmp));
  161. if( is_array($blocks_arrtmp) ) {
  162. for($i=0, $n=sizeof($blocks_arrtmp); $i<$n; $i++) {
  163. $blocks_arr[$blocks_arrtmp[$i]['id']] = $blocks_arrtmp[$i];
  164. }
  165. }
  166. //
  167. $block_template = "\n";
  168. $block_template .= '<div class="contBlock contBlockMC">' . "\n";
  169. $block_template .= '<div class="contBlockHeading %s"><span class="t">%s</span></div>' . "\n";
  170. $block_template .= '<div class="contBlockContent">' . "\n";
  171. $block_template .= '<div class="contBlockItem">' . "\n";
  172. $block_template .= '%s' . "\n";
  173. $block_template .= '</div>' . "\n";
  174. $block_template .= '</div>' . "\n";
  175. $block_template .= '</div>' . "\n";
  176. $block_template .= "%s";
  177. //
  178. if( is_array($blocks_ids) ) {
  179. for($i=0, $n=sizeof($blocks_ids); $i<$n; $i++) {
  180. $blocks_pattern[] = "/(\{\{block\}\})" . $blocks_ids[$i] . "(\{\{\/block\}\})/";
  181. $hidden = (($blocks_arr[$blocks_ids[$i]]['hidesubject'] == '2') ? 'hidden' : '');
  182. $style = '';
  183. if( $blocks_arr[$blocks_ids[$i]]['style'] != '' ) {
  184. $style .= '<style type="text/css">' . "\n" . $blocks_arr[$blocks_ids[$i]]['style'] . "</style>" . "\n";
  185. }
  186. $blocks_replacement[] = sprintf($block_template, $hidden, $blocks_arr[$blocks_ids[$i]]['subject'], $blocks_arr[$blocks_ids[$i]]['content'], $style);
  187. }
  188. }
  189. $content = preg_replace($blocks_pattern, $blocks_replacement, $content);
  190. }
  191. //form
  192. if( $isfront == true && preg_match_all("/\{\{form\}\}(\d+)\{\{\/form\}\}/i", $content, $matches) ) {
  193. include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'frontend.filter.class.php');
  194. $_feObj = new FrontendFilterBase();
  195. include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/form/form.class.php');
  196. $formObj = new FormBase();
  197. $formObj->format = true;
  198. //$forms_pattern = $matches['0'];
  199. $forms_ids = $matches['1'];
  200. $forms_idstmp = array_unique($forms_ids);
  201. $forms_arrtmp = $formObj->getItemsDetail(array('ids' => $forms_idstmp));
  202. if( is_array($forms_arrtmp) ) {
  203. for($i=0, $n=sizeof($forms_arrtmp); $i<$n; $i++) {
  204. $forms_arr[$forms_arrtmp[$i]['id']] = $forms_arrtmp[$i];
  205. }
  206. }
  207. if( is_array($forms_ids) ) {
  208. for($i=0, $n=sizeof($forms_ids); $i<$n; $i++) {
  209. $forms_pattern[] = "/(\{\{form\}\})" . $forms_ids[$i] . "(\{\{\/form\}\})/";
  210. $_feObj->addContent('form', $forms_arr[$forms_ids[$i]]);
  211. $forms_replacement[] = $_feObj->fetch('common/blocks/common_block_form.tpl');
  212. }
  213. }
  214. $content = preg_replace($forms_pattern, $forms_replacement, $content);
  215. }
  216. //gallery
  217. if( $isfront == true && preg_match_all("/\{\{gallery\}\}(\d+)\{\{\/gallery\}\}/i", $content, $matches) ) {
  218. include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'frontend.filter.class.php');
  219. $_feObj = new FrontendFilterBase();
  220. include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/gallery/gallery.class.php');
  221. $gaObj = new GalleryBase();
  222. $gaObj->format = true;
  223. //$gs_pattern = $matches['0'];
  224. $gs_ids = $matches['1'];
  225. $gs_idstmp = array_unique($gs_ids);
  226. $gs_arrtmp = $gaObj->getItemsDetail(array('ids' => $gs_idstmp));
  227. if( is_array($gs_arrtmp) ) {
  228. for($i=0, $n=sizeof($gs_arrtmp); $i<$n; $i++) {
  229. $gs_arr[$gs_arrtmp[$i]['album']['id']] = $gs_arrtmp[$i];
  230. }
  231. }
  232. if( is_array($gs_ids) ) {
  233. for($i=0, $n=sizeof($gs_ids); $i<$n; $i++) {
  234. $gs_pattern[] = "/(\{\{gallery\}\})" . $gs_ids[$i] . "(\{\{\/gallery\}\})/";
  235. $_feObj->addContent('album', $gs_arr[$gs_ids[$i]]['album']);
  236. $_feObj->addContent('items', $gs_arr[$gs_ids[$i]]['items']);
  237. $_feObj->addContent('item', $gs_arr[$gs_ids[$i]]['items'][0]);
  238. $gs_replacement[] = $_feObj->fetch('common/blocks/common_block_gallery.tpl');
  239. }
  240. }
  241. $content = preg_replace($gs_pattern, $gs_replacement, $content);
  242. }
  243. //content
  244. if( $isfront == true && preg_match_all("/\{\{content\}\}(\d+)\{\{\/content\}\}/i", $content, $matches) ) {
  245. include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/content/content.class.php');
  246. $mObj = new ContentBase();
  247. $mObj->format = true;
  248. //$pattern = $matches['0'];
  249. $ct_ids = $matches['1'];
  250. $ct_idstmp = array_unique($ct_ids);
  251. $ct_arrtmp = $mObj->getItems(array('ids' => $ct_idstmp));
  252. if( is_array($ct_arrtmp) ) {
  253. for($i=0, $n=sizeof($ct_arrtmp); $i<$n; $i++) {
  254. $ct_arr[$ct_arrtmp[$i]['id']] = $ct_arrtmp[$i];
  255. }
  256. }
  257. if( is_array($ct_ids) ) {
  258. for($i=0, $n=sizeof($ct_ids); $i<$n; $i++) {
  259. $pattern[] = "/(\{\{content\}\})" . $ct_ids[$i] . "(\{\{\/content\}\})/";
  260. //
  261. $style = '';
  262. if( $ct_arr[$ct_ids[$i]]['style'] != '' ) {
  263. $style .= '###START###<style type="text/css">' . "\n" . $ct_arr[$ct_ids[$i]]['style'] . "</style>###END###" . "\n";
  264. }
  265. //
  266. if( isset($ct_arr[$ct_ids[$i]]['content']) ) {
  267. $replacement[] = $style . $ct_arr[$ct_ids[$i]]['content'];
  268. } else {
  269. $replacement[] = $style . $ct_arr[$ct_ids[$i]]['fulltext'];
  270. }
  271. }
  272. }
  273. $content = preg_replace($pattern, $replacement, $content);
  274. }
  275. //static page
  276. if( preg_match_all("/\{\{spage id=(\d+) link=(.+?)\}\}(.+)\{\{\/spage\}\}/i", $content, $matches) ) {
  277. global $spObj;
  278. //id,link,text
  279. $sp_ids = $matches['1'];
  280. $sp_links = $matches['2'];
  281. $sp_texts = $matches['3'];
  282. $sp_idstmp = array_unique($sp_ids);
  283. $sp_arrtmp = $spObj->getItems(array('ids' => $sp_idstmp), -1, false);
  284. if( is_array($sp_arrtmp) ) {
  285. for($i=0, $n=sizeof($sp_arrtmp); $i<$n; $i++) {
  286. if( $sp_arrtmp[$i]['pages_status'] == 0 ) {
  287. $sp_arr[$sp_arrtmp[$i]['pages_id']] = '<a href="' . CONFIG_URL_HTTP . '' . $sp_arrtmp[$i]['pages_link'] . '.html">';
  288. } else {
  289. $sp_arr[$sp_arrtmp[$i]['pages_id']] = '<a href="' . CONFIG_URL_HTTP . 'static/' . $sp_arrtmp[$i]['pages_link'] . '.html">';
  290. }
  291. }
  292. }
  293. if( is_array($sp_ids) ) {
  294. for($i=0, $n=sizeof($sp_ids); $i<$n; $i++) {
  295. $sp_pattern[] = "/\{\{spage id=" . $sp_ids[$i] . " link=(.+?)\}\}" . $sp_texts[$i] . "(\{\{\/spage\}\})/";
  296. $sp_replacement[] = $sp_arr[$sp_ids[$i]] . $sp_texts[$i] . '</a>';
  297. }
  298. }
  299. $content = preg_replace($sp_pattern, $sp_replacement, $content);
  300. }
  301. //news page
  302. if( preg_match_all("/\{\{news id=(\d+) link=(.+?)\}\}(.+)\{\{\/news\}\}/i", $content, $matches) ) {
  303. //include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/news/news.category.class.php');
  304. //$ncObj = new NewsCategoryBase();
  305. include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/news/news.class.php');
  306. $nObj = new NewsBase();
  307. //id,link,text
  308. $news_ids = $matches['1'];
  309. $news_links = $matches['2'];
  310. $news_texts = $matches['3'];
  311. $news_idstmp = array_unique($news_ids);
  312. $news_arrtmp = $nObj->getItems(array('ids' => $news_idstmp), -1, false);
  313. if( is_array($news_arrtmp) ) {
  314. for($i=0, $n=sizeof($news_arrtmp); $i<$n; $i++) {
  315. $news_arr[$news_arrtmp[$i]['pages_id']] = '<a href="' . CONFIG_URL_HTTP . 'static/' . $news_arrtmp[$i]['pages_link'] . '.html">';
  316. }
  317. }
  318. if( is_array($news_ids) ) {
  319. for($i=0, $n=sizeof($news_ids); $i<$n; $i++) {
  320. $news_pattern[] = "/\{\{news id=" . $news_ids[$i] . " link=(.+?)\}\}" . $news_texts[$i] . "(\{\{\/news\}\})/";
  321. $news_replacement[] = $news_arr[$news_ids[$i]] . $news_texts[$i] . '</a>';
  322. }
  323. }
  324. $content = preg_replace($news_pattern, $news_replacement, $content);
  325. }
  326. //front
  327. if( $isfront == true ) {
  328. //title
  329. if( preg_match_all("/(={2,})(.+?)(={2,})/i", $content, $matches) ) {
  330. $pattern = $replacement = array();
  331. if( is_array($matches['1']) ) {
  332. for($i=0, $n=sizeof($matches['1']); $i<$n; $i++) {
  333. $pattern[] = "/" . func_filter_replace($matches['0'][$i]) . "/";
  334. $replacement[] = '<h' . strlen($matches['1'][$i]) . '>' . $matches['2'][$i] . '</h' . strlen($matches['1'][$i]) . '>';
  335. }
  336. }
  337. $content = preg_replace($pattern, $replacement, $content);
  338. }
  339. //link
  340. if( preg_match_all("/(\[{1,3})(.+?)(\]{1,3})/i", $content, $matches) ) {
  341. $pattern = $replacement = array();
  342. if( is_array($matches['1']) ) {
  343. for($i=0, $n=sizeof($matches['1']); $i<$n; $i++) {
  344. //$pattern[] = "/(\[{1,3})(.+?)(\]{1,3})/";
  345. $pattern[] = "/" . func_filter_replace($matches['0'][$i]) . "/";
  346. $t = strlen($matches['1'][$i]);
  347. $s = $matches['2'][$i];
  348. $ss = explode('|', $s);
  349. if( sizeof($ss) == 2 ) {
  350. $link = $ss['0'];
  351. $text = $ss['1'];
  352. } else {
  353. $link = $text = $ss['0'];
  354. }
  355. if( $t == 1 ) {
  356. $replacement[] = '<a href="' . $link . '">' . $text . '</a>';
  357. } elseif( $t == 2 ) {
  358. $replacement[] = '<a href="{{LINKP}}' . $link . '">' . $text . '</a>';
  359. } elseif( $t == 3 ) {
  360. $replacement[] = '<a href="' . $link . '" target="blank">' . $text . '</a>';
  361. }
  362. }
  363. }
  364. $content = preg_replace($pattern, $replacement, $content);
  365. }
  366. //script
  367. $content = preg_replace("'<script[^>]*?>.*?</script>'", "", $content);
  368. if( preg_match_all("/\{\{\{script\}\}\}(.*?)\{\{\{\/script\}\}\}/s", $content, $matches) ) {
  369. $pattern = $replacement = array();
  370. if( is_array($matches['0']) ) {
  371. for($i=0, $n=sizeof($matches['0']); $i<$n; $i++) {
  372. $pattern[] = "/\{\{\{script\}\}\}(.*?)\{\{\{\/script\}\}\}/";
  373. $replacement[] = '<script type="text/javascript" language="javascript" src="$1"></script>';
  374. }
  375. }
  376. $content = preg_replace($pattern, $replacement, $content);
  377. }
  378. if( preg_match_all("/\{\{script\}\}(.*?)\{\{\/script\}\}/s", $content, $matches) ) {
  379. $pattern = $replacement = array();
  380. if( is_array($matches['0']) ) {
  381. for($i=0, $n=sizeof($matches['0']); $i<$n; $i++) {
  382. $pattern[] = "/\{\{script\}\}(.*?)\{\{\/script\}\}/";
  383. $replacement[] = '<script type="text/javascript" language="javascript">$1</script>';
  384. }
  385. }
  386. $content = preg_replace($pattern, $replacement, $content);
  387. }
  388. //style
  389. if( preg_match_all("/\{\{style\}\}(.*?)\{\{\/style\}\}/s", $content, $matches) ) {
  390. $pattern = $replacement = array();
  391. if( is_array($matches['0']) ) {
  392. for($i=0, $n=sizeof($matches['0']); $i<$n; $i++) {
  393. //$pattern[] = "/" . func_filter_replace($matches['0'][$i]) . "/";
  394. //$replacement[] = '<style type="text/css">' . str_replace("\r\n", "", $matches['1'][$i]) . '</style>';
  395. $pattern[] = "/\{\{style\}\}(.*?)\{\{\/style\}\}/";
  396. $replacement[] = '<style type="text/css">' . "\n" . '$1' . "\n" . '</style>';
  397. }
  398. }
  399. $content = preg_replace($pattern, $replacement, $content);
  400. }
  401. //contactus
  402. if( strpos($content, "{{contactus}}") !== false ) {
  403. $_feObj = new FrontendBase();
  404. $contactus_content = $_feObj->fetch('main/common/main_common_contactus.tpl');;
  405. $content = str_replace("{{contactus}}", $contactus_content, $content);
  406. }
  407. //paypal
  408. /*
  409. if( strpos($content, "{{viewcart}}") !== false ) {
  410. _lc('payment.paypal.class.php');
  411. $paypalObj = new PaypalBase();
  412. $paypal_viewcart = $paypalObj->getCart();
  413. $content = str_replace("{{viewcart}}", $paypal_viewcart, $content);
  414. }
  415. */
  416. //category products
  417. if( preg_match_all("/\{\{categoryproducts\}\}(\d+)\{\{\/categoryproducts\}\}/i", $content, $matches) ) {
  418. global $pObj, $pcObj;
  419. global $settingObj;
  420. $_feObj = new FrontendBase();
  421. $categories = array();
  422. $categories_products = array();
  423. $categories_ids = $matches['1'];
  424. $categories_idstmp = array_unique($categories_ids);
  425. $categories_arrtmp = $pcObj->getCategories(array('ids' => $categories_idstmp));
  426. for($i=0, $n=sizeof($categories_arrtmp); $i<$n; $i++) {
  427. $categories[$categories_arrtmp[$i]['categories_id']] = $categories_arrtmp[$i];
  428. }
  429. $products_arrtmp = $pObj->getItems(array('category' => $categories_idstmp), 0, false);
  430. for($i=0, $n=sizeof($products_arrtmp); $i<$n; $i++) {
  431. $categories_products[$products_arrtmp[$i]['categories_id']][] = $products_arrtmp[$i];
  432. }
  433. $pattern = $replacement = array();
  434. if( is_array($categories_idstmp) ) {
  435. for($i=0, $n=sizeof($categories_idstmp); $i<$n; $i++) {
  436. $pattern[] = "/\{\{categoryproducts\}\}" . $matches['1'][$i] . "\{\{\/categoryproducts\}\}/s";
  437. $_feObj->addContent('products', $categories_products[$matches['1'][$i]]);
  438. $_feObj->addContent('category', $categories[$matches['1'][$i]]);
  439. $replacement[] = $_feObj->fetch('product/common/product_common_category_products.tpl');
  440. }
  441. }
  442. if( is_array($pattern) ) {
  443. $content = preg_replace($pattern, $replacement, $content);
  444. }
  445. }
  446. //category navigation
  447. if( preg_match_all("/\{\{categorynavigation\}\}(\d+)\{\{\/categorynavigation\}\}/i", $content, $matches) ) {
  448. global $pObj, $pcObj;
  449. global $settingObj;
  450. $_feObj = new FrontendBase();
  451. $categories = array();
  452. $categories_ids = $matches['1'];
  453. $categories_idstmp = array_unique($categories_ids);
  454. for($i=0, $n=sizeof($categories_idstmp); $i<$n; $i++) {
  455. $pattern[] = "/\{\{categorynavigation\}\}" . $matches['1'][$i] . "\{\{\/categorynavigation\}\}/s";
  456. $category = $pcObj->getCategory($categories_idstmp[$i]);
  457. $categories = $pcObj->getCategoriesTree('', $categories_idstmp[$i]);
  458. $_feObj->addContent('category', $category);
  459. $_feObj->addContent('categories', $categories);
  460. $replacement[] = $_feObj->fetch('product/common/product_common_category_categories.tpl');
  461. }
  462. if( is_array($pattern) ) {
  463. $content = preg_replace($pattern, $replacement, $content);
  464. }
  465. }
  466. //
  467. $content = str_replace("{{LINKP}}", CONFIG_URL_HTTP, $content);
  468. //\r\n
  469. //
  470. //$content = str_replace('\r\n', "\r\n", $content);
  471. //$content = str_replace('\n', "\n", $content);
  472. //$content = str_replace('\r', "\r", $content);
  473. $content = str_replace(array('\r\n', '\n', '\r'), array("\r\n", "\n", "\r"), $content);
  474. $content = stripslashes($content);
  475. //
  476. /*
  477. //NOT IMPLEMENT THE FUNCTION
  478. if( preg_match("'<[\/\!]*?[^<>]*?>'si", $content) ) {
  479. $cs = explode("\n", $content);
  480. $ps = 0;
  481. for($i=0, $n=sizeof($cs); $i<$n; $i++) {
  482. if( strstr($cs[$i], "[[") !== false || strstr($cs[$i], "{{") !== false ) {
  483. $ps = 1;
  484. }
  485. if( strstr($cs[$i], "[[/") !== false || strstr($cs[$i], "{{/") !== false ) {
  486. $ps = 0;
  487. }
  488. if( strstr($cs[$i], "###START###") !== false ) {
  489. $ps = 1;
  490. }
  491. if( strstr($cs[$i], "###END###") !== false ) {
  492. $ps = 0;
  493. }
  494. if( $ps == 0 && strlen($cs[$i]) > 0
  495. && preg_match("'<[\/\!]*?[^<>]*?>'si", $cs[$i]) == false
  496. && preg_match("'{[\/\!]*?[^<>]*?}'si", $cs[$i]) == false
  497. && preg_match("'\=[\/\!]*?[^<>]*?\='si", $cs[$i]) == false ) {
  498. $cs[$i] = "<p>" . $cs[$i] . "</p>";
  499. }
  500. }
  501. $content = implode("\n", $cs);
  502. }
  503. //NOT IMPLEMENT THE FUNCTION
  504. */
  505. }
  506. //
  507. $content = str_replace(array("###START###", "###END###"), array("", ""), $content);
  508. return $content;
  509. }
  510. //
  511. ?>