fee1975ffc6ae8c5f07d369d1a8a99843fcbc600.svn-base 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  1. <?php namespace Maze\Template;
  2. use Maze\File\Path;
  3. use Maze\Debug\Process as Debug;
  4. use Maze\Config\Load as Config;
  5. class Compile
  6. {
  7. /**
  8. * left
  9. *
  10. * @var const string
  11. */
  12. const left = '<?php ';
  13. /**
  14. * right
  15. *
  16. * @var const string
  17. */
  18. const right = ' ?>';
  19. /**
  20. * file
  21. *
  22. * @var string
  23. */
  24. protected $file;
  25. /**
  26. * path
  27. *
  28. * @var string
  29. */
  30. protected $path;
  31. /**
  32. * template
  33. *
  34. * @var string
  35. */
  36. protected $template;
  37. /**
  38. * content
  39. *
  40. * @var array
  41. */
  42. protected $content;
  43. /**
  44. * update
  45. *
  46. * @var bull
  47. */
  48. protected $update = false;
  49. /**
  50. * load file
  51. * @param string $file
  52. * @param string $path
  53. * @param string $service
  54. * @param string $project
  55. *
  56. * @return mixed
  57. */
  58. public function __construct($file, $template, $service, $project = false, $path = '')
  59. {
  60. $this->path = $path;
  61. $this->project($project);
  62. $this->file = $this->path($path . $file) . '.cmp.php';
  63. Debug::log($this->file);
  64. $this->read($file, $template, $service);
  65. }
  66. /**
  67. * read file
  68. * @param string $file
  69. * @param string $path
  70. * @param string $service
  71. * @param bool $local
  72. *
  73. * @return mixed
  74. */
  75. public function read($file, $path, $service, $local = false)
  76. {
  77. if(strpos($file, 'http://'))
  78. {
  79. $content = file_get_contents($file);
  80. # 增加抓取功能 本地化
  81. if($local == true)
  82. {
  83. $content = $this->local($content);
  84. }
  85. $this->template = $content;
  86. }
  87. else
  88. {
  89. $this->template = $path . $file . '.html';
  90. if(is_file($this->template))
  91. {
  92. $is_service = is_file($service);
  93. $time = is_file($this->file) ? filemtime($this->file) : 0;
  94. $this->update = defined('MAZE_COMPILE');
  95. if(filemtime($this->template) > $time || ($is_service && filemtime($service) > $time))
  96. {
  97. # 可以更新
  98. $this->update = true;
  99. }
  100. if($time == 0 || $this->update == true)
  101. {
  102. $content = $this->readContent($path);
  103. }
  104. if(!empty($content) && !$is_service)
  105. {
  106. return $this->create($content);
  107. }
  108. }
  109. else
  110. {
  111. # 当文件不存在时
  112. $this->update = false;
  113. }
  114. }
  115. }
  116. /**
  117. * readContent 获取当前模板的内容
  118. *
  119. * @return string
  120. */
  121. public function readContent($path)
  122. {
  123. # 这里直接用content传过去效率高
  124. $content = file_get_contents($this->template);
  125. if(strpos($content, '@include:') !== false)
  126. {
  127. $temp = explode('@include:', $content);
  128. $file = end($temp);
  129. $this->template = $path . $file . '.html';
  130. $content = file_get_contents($this->template);
  131. }
  132. # 远程读取
  133. elseif(strpos($content, '@url:') !== false)
  134. {
  135. //$config = $content;
  136. $content = str_replace("\n", '', $content);
  137. $temp = explode('@url:', $content);
  138. $this->template = end($temp);
  139. //$this->template = end(explode('@url:', $config));
  140. $content = file_get_contents($this->template);
  141. # 增加资源处理功能 @res:replace 将资源中的路径替换为带有域名的路径 @res:local 本地化
  142. if(strpos($temp[0], '@res:') !== false)
  143. {
  144. $temp = explode('@res:', $temp[0]);
  145. $content = $this->res(end($temp), $content, $this->template, $path);
  146. }
  147. }
  148. $this->template = $content;
  149. return $content;
  150. }
  151. /**
  152. * res 资源处理 此处待优化
  153. *
  154. * @return string
  155. */
  156. private function res($type, $content, $url, $path)
  157. {
  158. //return $content;
  159. $encode = mb_detect_encoding($content, array('GB2312','GBK','UTF-8'));
  160. if($encode == 'GB2312' || $encode == 'GBK' || $encode == 'EUC-CN' || $encode == 'CP936')
  161. {
  162. $content = iconv('GBK', 'UTF-8', $content);
  163. }
  164. # 过滤换行
  165. $content = str_replace(PHP_EOL, '', $content);
  166. if($type == 'local')
  167. {
  168. # 规则
  169. $rule = '<link(.*?)href="(.*?)"';
  170. preg_match_all('/' . $rule . '/i', $content, $result);
  171. $rule = '<script src="(.*?)"(.*?)<\/script>';
  172. preg_match_all('/' . $rule . '/i', $content, $result);
  173. }
  174. elseif(strpos($type, 'include:') !== false)
  175. {
  176. $temp = explode('include:', $type);
  177. $file = end($temp);
  178. $include = str_replace("\n", '', file_get_contents($path . $file . '.html'));
  179. parse_str($include, $param);
  180. foreach($param as $k => $v)
  181. {
  182. $content = $this->replace($k, $v, $content);
  183. }
  184. }
  185. else
  186. {
  187. parse_str($type, $param);
  188. foreach($param as $k => $v)
  189. {
  190. $content = $this->replace($k, $v, $content);
  191. }
  192. }
  193. return $content;
  194. }
  195. /**
  196. * get file
  197. *
  198. * @return string
  199. */
  200. public function file()
  201. {
  202. return $this->file;
  203. }
  204. /**
  205. * get template or content
  206. *
  207. * @return string
  208. */
  209. public function template()
  210. {
  211. return $this->template;
  212. }
  213. /**
  214. * project
  215. *
  216. * @return string
  217. */
  218. public function project($project = false)
  219. {
  220. $this->project = $project ? $project : MAZE_PROJECT_NAME;
  221. return $this->project;
  222. }
  223. /**
  224. * path create path
  225. * @param string $file
  226. * @param string $project
  227. *
  228. * @return string
  229. */
  230. public function path($file, $path = 'compile')
  231. {
  232. return Path::create(MAZE_PATH . 'data/' . $path . '/' . $this->project . '/', $file);
  233. }
  234. /**
  235. * get
  236. *
  237. * @return mixed
  238. */
  239. public function get()
  240. {
  241. if($this->update == false && is_file($this->file))
  242. {
  243. ob_start();
  244. require $this->file;
  245. $content = ob_get_contents();
  246. ob_end_clean();
  247. return $content;
  248. }
  249. elseif($this->update == false)
  250. {
  251. return '';
  252. }
  253. else
  254. {
  255. return false;
  256. }
  257. }
  258. /**
  259. * load view
  260. *
  261. * @param string $service
  262. * @return \Maze\Template\View
  263. */
  264. public function load($file, $path = '')
  265. {
  266. $desc = '<!--{'.$path.'/'.$file.'}-->';
  267. $view = View::getInstance($file);
  268. if($path)
  269. {
  270. $view->path($path);
  271. }
  272. else
  273. {
  274. $view->path($this->path);
  275. }
  276. $view->runing();
  277. $file = $view->file();
  278. if($file)
  279. {
  280. return $desc . $this->script('require MAZE_PATH . \'' . str_replace(MAZE_PATH, '', $file) . '\'') . $desc;
  281. }
  282. }
  283. /**
  284. * create
  285. * @param string $content
  286. *
  287. * @return string
  288. */
  289. public function create($content)
  290. {
  291. $this->update = false;
  292. if($this->content)
  293. {
  294. $content = implode("\n", $this->content) . "\n" . $content;
  295. }
  296. $this->write($this->assets($content));
  297. return $this->get();
  298. }
  299. /**
  300. * write
  301. *
  302. * @return mixed
  303. */
  304. public function write($content)
  305. {
  306. $content = preg_replace('/<!--(.*?)-->/s', '', $content);
  307. if(isset(Config::$global['host']['merge']) && Config::$global['host']['merge'] && strpos($content, Config::$global['host']['assets']) !== false)
  308. {
  309. $this->merge
  310. (
  311. array('<link(.*?)href=[\'|"](.*?)[\'|"](.*?)>', '<script([a-zA-Z\/"\'=\\s]+)src=[\'|"](.*?)[\'|"](.*?)<\/script>'),
  312. $content
  313. );
  314. }
  315. $copyright = '<!--power by mazephp-->';
  316. file_put_contents($this->file, $copyright . $content);
  317. @chmod($this->file, 0755);
  318. system('chmod -R ' . $this->file . ' 777');
  319. }
  320. /**
  321. * assets
  322. * @param string $content
  323. *
  324. * @return string
  325. */
  326. public function assets($content)
  327. {
  328. if(isset(Config::$global['base']['replace']) && is_array(Config::$global['base']['replace']))
  329. {
  330. foreach(Config::$global['base']['replace'] as $k => $v)
  331. {
  332. if(isset(Config::$global['host'][$k]))
  333. {
  334. $content = $this->replace($v, Config::$global['host'][$k], $content);
  335. }
  336. }
  337. }
  338. return $content;
  339. }
  340. /**
  341. * merge
  342. *
  343. * @return string
  344. */
  345. private function merge($rule, &$content)
  346. {
  347. foreach($rule as $k => $v)
  348. {
  349. $v = '/' . $v . '/i';
  350. preg_match_all($v, $content, $result);
  351. //print_r($result);
  352. if(isset($result[2]) && $result[2])
  353. {
  354. if($k == 1)
  355. {
  356. $ext = 'js';
  357. $fext = ';';
  358. }
  359. else
  360. {
  361. $ext = 'css';
  362. $fext = '';
  363. }
  364. $file = md5($this->file) . '.' . $ext;
  365. $host = Config::$global['host']['merge'] . $this->project . '/' . $file . '?v' . MAZE_TIME;
  366. $file = $this->path($file, 'assets');
  367. $assets = '';
  368. foreach($result[2] as $fk => $fv)
  369. {
  370. if($fv)
  371. {
  372. $fv = str_replace(Config::$global['host']['assets'], Config::$global['base']['assets'], $fv);
  373. $assets .= file_get_contents($fv) . $fext;
  374. if(strpos($content, '{{file}}') === false)
  375. {
  376. $content = str_replace($result[0][$fk], '{{file}}', $content);
  377. }
  378. else
  379. {
  380. $content = str_replace($result[0][$fk], '', $content);
  381. }
  382. }
  383. }
  384. if($assets)
  385. {
  386. $method = 'zip_' . $ext;
  387. $assets = $this->assets($assets);
  388. file_put_contents($file, $this->$method($assets));
  389. }
  390. $file = $k == 1 ? '<script type="text/javascript" src="'.$host.'"></script>' : '<link rel="stylesheet" type="text/css" href="'.$host.'" />';
  391. //$content = $this->zip_css($content);
  392. $content = str_replace('{{file}}', $file, $content);
  393. }
  394. }
  395. }
  396. /**
  397. * zip_css
  398. * @param string $string
  399. *
  400. * @return string
  401. */
  402. private function zip_css($string)
  403. {
  404. return str_replace(array("\t", "\r\n", "\r", "\n"), '', $string);
  405. }
  406. /**
  407. * zip_js
  408. * @param string $string
  409. *
  410. * @return string
  411. */
  412. private function zip_js($string)
  413. {
  414. return $string;
  415. $h1 = 'http://';
  416. $s1 = '【:??】';
  417. $h2 = 'https://';
  418. $s2 = '【s:??】';
  419. $string = preg_replace('#function include([^}]*)}#isU','',$string);//include函数体
  420. $string = preg_replace('#\/\*.*\*\/#isU','',$string);//块注释
  421. $string = str_replace($h1,$s1,$string);
  422. $string = str_replace($h2,$s2,$string);
  423. $string = preg_replace('#\/\/[^\n]*#','',$string);//行注释
  424. $string = str_replace($s1,$h1,$string);
  425. $string = str_replace($s2,$h2,$string);
  426. $string = preg_replace('#\s?(=|>=|\?|:|==|\+|\|\||\+=|>|<|\/|\-|,|\()\s?#','$1',$string);//字符前后多余空格
  427. $string = $this->zip_css($string);
  428. $string = trim($string," ");
  429. return $string;
  430. }
  431. /**
  432. * script
  433. * @param string $string
  434. *
  435. * @return string
  436. */
  437. public function script($string)
  438. {
  439. return self::left . $string . self::right;
  440. }
  441. /**
  442. * equal
  443. * @param string $variable
  444. * @param string $value
  445. * @param string $key
  446. *
  447. * @return string
  448. */
  449. public function equal($variable, $value, $key = '')
  450. {
  451. if(strpos($key, '$') !== false)
  452. {
  453. $variable .= '['.$key.']';
  454. }
  455. elseif($key)
  456. {
  457. $variable .= '[\''.$key.'\']';
  458. }
  459. if(is_array($value))
  460. {
  461. $value = var_export($value, true);
  462. }
  463. elseif(is_string($value) && strpos($value, '"') !== false)
  464. {
  465. $value = '\'' . $value . '\'';
  466. }
  467. return $this->script('$' . $variable . '=' . $value);
  468. }
  469. /**
  470. * data
  471. * @param string $data
  472. *
  473. * @return mixed
  474. */
  475. public function data($data)
  476. {
  477. if(is_object($data))
  478. {
  479. return $data();
  480. /*
  481. $this->set('$test', $data);
  482. return '<{$test}>';
  483. */
  484. }
  485. $type = $this->strip($data);
  486. # include page
  487. if(strpos($type, '@') !== false)
  488. {
  489. return explode('@', $type);
  490. }
  491. # include database|model
  492. elseif(strpos($type, 'http://') === false && strpos($type, '/') !== false && (strpos($type, '.') !== false || strpos($type, '-') !== false))
  493. {
  494. $key = $type;
  495. if(strpos($type, '|') !== false)
  496. {
  497. if(strpos($type, '!') !== false)
  498. {
  499. $type = str_replace('!', '$', $type . '');
  500. }
  501. $temp = explode('|', $type);
  502. $type = $temp[0];
  503. parse_str($temp[1], $param);
  504. // print_r($param);die;
  505. }
  506. $callback = 'Maze\\Routing\\Load::get(\'' . $type . '\')';
  507. if(isset($param))
  508. {
  509. $param = var_export($param, true);
  510. $callback = str_replace(')', ', '.$param.')', $callback);
  511. if(strpos($callback, '$') !== false)
  512. {
  513. $callback = preg_replace('/\'\$(.*?)\'/', '\$$1', $callback);
  514. }
  515. }
  516. $this->push($key, $this->equal('data', $callback, $key));
  517. return true;
  518. }
  519. return $data;
  520. }
  521. /**
  522. * out echo variable
  523. * @param string $variable
  524. *
  525. * @return string
  526. */
  527. public function out($variable)
  528. {
  529. return $this->script('echo $' . $variable);
  530. }
  531. /**
  532. * each
  533. * @param string $replace
  534. * @param string $data
  535. * @param string $content
  536. *
  537. * @return string
  538. */
  539. public function each($replace, $data, $content)
  540. {
  541. if($replace)
  542. {
  543. $strip = $this->strip($replace);
  544. if($strip && strpos($replace, $strip) !== false)
  545. {
  546. $replace = $strip;
  547. }
  548. }
  549. # 增加数组和非数组的判断,如果这里效率不高,以后可以优化,去掉第一行和最后三行即可
  550. return $this->script('if(is_array($data[\''.$data.'\'])):')
  551. .$this->equal('t', 'count($data[\''.$data.'\'])-1')
  552. .$this->equal('i', 0)
  553. .$this->script('foreach($data[\''.$data.'\'] as $k => $v):')
  554. //.$this->replace($replace, $this->out('v'), $content)
  555. .$content
  556. .$this->equal('i', '$i+1')
  557. .$this->script('endforeach;')
  558. .$this->script('else:')
  559. .$this->replace($replace, $this->out('data[\''.$data.'\']'), $content)
  560. .$this->script('endif;');
  561. }
  562. /**
  563. * content
  564. * @param string $content
  565. *
  566. * @return string
  567. */
  568. public function content($content, $data = false)
  569. {
  570. $echo = ' echo ';
  571. $content = $this->rule($content);
  572. $content = $this->replace('<{', self::left . $echo, $this->replace('}>', self::right, $content));
  573. $array = array('function', 'foreach', 'endforeach', 'if', 'endif', 'else', 'for', 'endfor', 'highlight_string', 'echo', 'print_r');
  574. foreach($array as $k => $v)
  575. {
  576. if(strpos($content, self::left . $echo . $v) !== false)
  577. {
  578. $content = $this->replace(self::left . $echo . $v, self::left . $v, $content);
  579. }
  580. }
  581. if(strpos($content, '{self}') !== false)
  582. {
  583. $content = $this->replace('{self}', '$data[\'' . $data . '\']', $content);
  584. }
  585. return $content;
  586. }
  587. /**
  588. * logic
  589. * @param string $logic
  590. * @param string $string
  591. *
  592. * @return string
  593. */
  594. public function logic($logic, $string)
  595. {
  596. # 这里暂时这样判断,以后再处理多种逻辑情况的
  597. if(strpos($logic, '|') !== false)
  598. {
  599. list($handle, $logic) = explode('|', $logic);
  600. if($logic == 'foreach')
  601. {
  602. $string = '<{if(isset('.$handle.') && is_array('.$handle.')):foreach('.$handle.' as $ki => $vi):}>' . $string . '<{endforeach;endif;}>';
  603. }
  604. elseif($logic == 'if')
  605. {
  606. $string = '<{if(isset('.$handle.') && '.$handle.'):}>' . $string . '<{endif;}>';
  607. }
  608. else
  609. {
  610. $string = '<{'.$handle.'}>' . $string . '<{'.$logic.'}>';
  611. }
  612. }
  613. else
  614. {
  615. $string = '<{if(isset('.$logic.') && is_array('.$logic.')):foreach('.$logic.' as $ki => $vi):}>' . $string . '<{endforeach;endif;}>';
  616. }
  617. return $this->content($string);
  618. }
  619. /**
  620. * replace
  621. * @param string $replace
  622. * @param string $value
  623. * @param string $content
  624. *
  625. * @return string
  626. */
  627. public function replace($replace, $value, $content)
  628. {
  629. if(!$replace)
  630. {
  631. return $value;
  632. }
  633. $content = str_replace($replace, $value, $content);
  634. /*
  635. if(strpos($content, $replace) !== false && strpos($content, $replace) !== false)
  636. {
  637. $content = str_replace($replace, $value, $content);
  638. }
  639. */
  640. return $content;
  641. }
  642. /**
  643. * push
  644. * @param string $value
  645. *
  646. * @return string
  647. */
  648. public function push($key, $value)
  649. {
  650. $this->content[$key] = $value;
  651. }
  652. /**
  653. * set
  654. * @param string $value
  655. *
  656. * @return string
  657. */
  658. public function set($key, $value = false)
  659. {
  660. if(!$value)
  661. {
  662. return $this->push($key, $this->script($this->rule($key)));
  663. }
  664. if(is_string($value))
  665. {
  666. if(strpos($value, 'Maze') === false)
  667. {
  668. $value = var_export($value, true);
  669. }
  670. $value = $this->rule($value);
  671. }
  672. elseif(is_object($value))
  673. {
  674. $value = $value();
  675. }
  676. $this->push($key, $this->script($this->rule($key) . '=' . $value . ''));
  677. }
  678. /**
  679. * tag
  680. * @param string $key
  681. * @param string $data
  682. *
  683. * @return string
  684. */
  685. public function tag($key, $data = false)
  686. {
  687. if($data)
  688. {
  689. $result = $data[$key];
  690. }
  691. else
  692. {
  693. $result = $key;
  694. }
  695. return $result;
  696. }
  697. /**
  698. * handle
  699. * @param string $data
  700. * @param string $content
  701. * @param string $expression
  702. *
  703. * @return string
  704. */
  705. public function handle($data, $content, $expression = '')
  706. {
  707. $result = '';
  708. if(is_array($data))
  709. {
  710. $tags = $this->strip($content);
  711. foreach($data as $k => $v)
  712. {
  713. $result .= $this->replace($tags, $v, $content);
  714. }
  715. }
  716. else
  717. {
  718. $index = false;
  719. if(is_string($data) && strpos($data, '#') > 0 && strpos($data, '"') === false)
  720. {
  721. list($data, $index) = explode('#', $data);
  722. }
  723. $method = $this->data($data);
  724. if($method === true)
  725. {
  726. $result = $this->complex($data, $content, $index, $expression);
  727. }
  728. elseif(is_array($method))
  729. {
  730. $result = $this->load($method[1], $method[0]);
  731. }
  732. elseif($method && (is_string($method) || is_numeric($method)))
  733. {
  734. $method = $this->content($method);
  735. $result = $this->replace($content, $method, $content);
  736. if($result == $content)
  737. {
  738. //$result = $this->replace($this->strip($content), $method, $content);
  739. }
  740. }
  741. elseif(!$result && (is_string($data) || is_numeric($data)))
  742. {
  743. $data = $this->content($data);
  744. $result = $this->replace($this->strip($content), $data, $content);
  745. }
  746. else
  747. {
  748. $result = $content;
  749. }
  750. }
  751. return $result;
  752. }
  753. /**
  754. * complex
  755. * @param string $data
  756. * @param string $content
  757. * @param string $index
  758. * @param string $expression
  759. *
  760. * @return string
  761. */
  762. public function complex($data, $content, $index = false, $expression = '')
  763. {
  764. if($index)
  765. {
  766. $strip = $this->strip($content);
  767. $result = $this->out('data[\''.$data.'\'][\''.$index.'\']');
  768. if($strip == $content)
  769. {
  770. $result = $this->replace($strip, $result, $content);
  771. }
  772. }
  773. else
  774. {
  775. if($expression)
  776. {
  777. $content = $this->replace($expression, $this->out('v'), $content);
  778. }
  779. $result = $this->each($content, $data, $this->content($content));
  780. }
  781. return $result;
  782. }
  783. /**
  784. * rule
  785. * @param string $content
  786. *
  787. * @return string
  788. */
  789. public function rule($content)
  790. {
  791. if(strpos($content, 'request.') !== false)
  792. {
  793. $content = preg_replace('/request\.([a-zA-Z0-9]+)/', 'Maze::input(\'$1\')', $content);
  794. }
  795. if(strpos($content, '$') !== false && strpos($content, '.') !== false)
  796. {
  797. $rule = '\$([a-zA-Z0-9]+)\.([a-zA-Z0-9._]+)';
  798. $content = preg_replace_callback('/' . $rule . '/i', array($this, 'rule_val'), $content);
  799. }
  800. if(strpos($content, '"+') !== false)
  801. {
  802. $content = str_replace(array('"+','+"'), array('".', '."'), $content);
  803. }
  804. if(strpos($content, '++') !== false)
  805. {
  806. $content = str_replace('++', '.', $content);
  807. }
  808. if(strpos($content, '<{$') !== false)
  809. {
  810. //$content = str_replace('<{$', '<{echo $', $content);
  811. }
  812. return $content;
  813. }
  814. /**
  815. * rule_val
  816. * @param array $result
  817. *
  818. * @return string
  819. */
  820. public function rule_val($result)
  821. {
  822. if(isset($result[2]) && $result[2])
  823. {
  824. $result[2] = '$' . $result[1] . '' . preg_replace('/\.([a-zA-Z0-9_]+)/', '[\'$1\']', '.' . $result[2]);
  825. return $result[2];
  826. }
  827. return $result[0];
  828. }
  829. /**
  830. * strip
  831. * @param string $content
  832. *
  833. * @return string
  834. */
  835. public function strip($content)
  836. {
  837. if(is_string($content))
  838. {
  839. return strip_tags($content);
  840. }
  841. return $content;
  842. }
  843. }