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

/core/model/modx/filters/modoutputfilter.class.php

https://github.com/harunpehlivan/revolution
PHP | 681 lines | 548 code | 41 blank | 92 comment | 120 complexity | 8481ff257e8bbae1d0bffe059bca8784 MD5 | raw file
Possible License(s): AGPL-1.0, Apache-2.0, BSD-3-Clause, LGPL-2.1, GPL-2.0, GPL-3.0, LGPL-2.0
  1. <?php
  2. /*
  3. * MODX Revolution
  4. *
  5. * Copyright 2006-2014 by MODX, LLC.
  6. * All rights reserved.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it under
  9. * the terms of the GNU General Public License as published by the Free Software
  10. * Foundation; either version 2 of the License, or (at your option) any later
  11. * version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  20. * Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. /**
  23. * Provides the default output filter implementation for modElement processing.
  24. * @package modx
  25. * @subpackage filters
  26. */
  27. /**
  28. * Base output filter implementation for modElement processing, based on phX.
  29. *
  30. * @package modx
  31. * @subpackage filters
  32. */
  33. class modOutputFilter {
  34. /**
  35. * @var modX A reference to the modX instance
  36. */
  37. public $modx= null;
  38. /**
  39. * @param modX $modx A reference to the modX instance
  40. * @return modOutputFilter A new instance of the modOutputFilter class
  41. */
  42. function __construct(modX &$modx) {
  43. $this->modx= &$modx;
  44. }
  45. /**
  46. * Filters the output
  47. *
  48. * @param modElement $element The element to filter
  49. */
  50. public function filter(&$element) {
  51. $usemb = function_exists('mb_strlen') && (boolean)$this->modx->getOption('use_multibyte',null,false);
  52. $encoding = $this->modx->getOption('modx_charset',null,'UTF-8');
  53. $output= & $element->_output;
  54. $inputFilter = $element->getInputFilter();
  55. if ($inputFilter !== null && $inputFilter->hasCommands()) {
  56. $modifier_cmd = $inputFilter->getCommands();
  57. $modifier_value = $inputFilter->getModifiers();
  58. $count = count($modifier_cmd);
  59. $condition = array();
  60. for ($i= 0; $i < $count; $i++) {
  61. $m_cmd = $modifier_cmd[$i];
  62. $m_val = $modifier_value[$i];
  63. $this->log('Processing Modifier: ' . $m_cmd . ' (parameters: ' . $m_val . ')');
  64. $output = trim($output);
  65. try {
  66. switch ($m_cmd) {
  67. /* conditional operators */
  68. /* @todo these conditionals should be removed because there are cleaner ways to do this now */
  69. case 'input':
  70. case 'if':
  71. $output= $m_val;
  72. break;
  73. case 'eq':
  74. case 'is':
  75. case 'equals':
  76. case 'equalto':
  77. case 'isequal':
  78. case 'isequalto':
  79. $condition[]= intval(($output == $m_val));
  80. break;
  81. case 'ne':
  82. case 'neq':
  83. case 'isnot':
  84. case 'isnt':
  85. case 'notequals':
  86. case 'notequalto':
  87. $condition[]= intval(($output != $m_val));
  88. break;
  89. case 'gte':
  90. case 'isgte':
  91. case 'eg':
  92. case 'ge':
  93. case 'equalorgreaterthan':
  94. case 'greaterthanorequalto':
  95. $condition[]= intval(($output >= $m_val));
  96. break;
  97. case 'lte':
  98. case 'islte':
  99. case 'le':
  100. case 'el':
  101. case 'lessthanorequalto':
  102. case 'equaltoorlessthan':
  103. $condition[]= intval(($output <= $m_val));
  104. break;
  105. case 'gt':
  106. case 'isgt':
  107. case 'greaterthan':
  108. case 'isgreaterthan':
  109. $condition[]= intval(($output > $m_val));
  110. break;
  111. case 'lt':
  112. case 'islt':
  113. case 'lessthan':
  114. case 'lowerthan':
  115. case 'islessthan':
  116. case 'islowerthan':
  117. $condition[]= intval(($output < $m_val));
  118. break;
  119. case 'contains':
  120. $condition[]= intval(stripos($output, $m_val) !== false);
  121. break;
  122. case 'containsnot':
  123. $condition[]= intval(stripos($output, $m_val) === false);;
  124. break;
  125. case 'ismember':
  126. case 'memberof':
  127. case 'mo': /* Is Member Of (same as inrole but this one can be stringed as a conditional) */
  128. if (empty($output) || $output == "&_PHX_INTERNAL_&") {
  129. $output= $this->modx->user->get('id');
  130. }
  131. $grps= (strlen($m_val) > 0) ? explode(',', $m_val) : array ();
  132. /** @var $user modUser */
  133. $user = $this->modx->getObject('modUser',$output);
  134. if ($user && is_object($user) && $user instanceof modUser) {
  135. $condition[]= $user->isMember($grps);
  136. } else {
  137. $condition[] = false;
  138. }
  139. break;
  140. case 'or':
  141. $condition[]= "||";
  142. break;
  143. case 'and':
  144. $condition[]= "&&";
  145. break;
  146. case 'hide':
  147. $conditional = join(' ', $condition);
  148. try {
  149. $m_con = @eval("return (" . $conditional . ");");
  150. $m_con = intval($m_con);
  151. if ($m_con) {
  152. $output= null;
  153. }
  154. } catch (Exception $e) {}
  155. break;
  156. case 'show':
  157. $conditional = join(' ', $condition);
  158. try {
  159. $m_con = @eval("return (" . $conditional . ");");
  160. $m_con = intval($m_con);
  161. if (!$m_con) {
  162. $output= null;
  163. }
  164. } catch (Exception $e) {}
  165. break;
  166. case 'then':
  167. $output = null;
  168. $conditional = join(' ', $condition);
  169. try {
  170. $m_con = @eval("return (" . $conditional . ");");
  171. $m_con = intval($m_con);
  172. if ($m_con) {
  173. $output= $m_val;
  174. }
  175. } catch (Exception $e) {}
  176. break;
  177. case 'else':
  178. $conditional = join(' ', $condition);
  179. try {
  180. $m_con = @eval("return (" . $conditional . ");");
  181. $m_con = intval($m_con);
  182. if (!$m_con) {
  183. $output= $m_val;
  184. }
  185. } catch (Exception $e) {}
  186. break;
  187. case 'select':
  188. $raw= explode("&", $m_val);
  189. $map= array ();
  190. for ($m= 0; $m < (count($raw)); $m++) {
  191. $mi= explode("=", $raw[$m]);
  192. $map[$mi[0]]= $mi[1];
  193. }
  194. $output= $map[$output];
  195. break;
  196. /* ##### End of Conditional Modifiers */
  197. /* ##### String Modifiers */
  198. case 'cat': /* appends the options value (if not empty) to the input value */
  199. if (!empty($m_val))
  200. $output = $output . $m_val;
  201. break;
  202. case 'lcase':
  203. case 'lowercase':
  204. case 'strtolower':
  205. /* See PHP's strtolower - http://www.php.net/manual/en/function.strtolower.php */
  206. $output = $usemb ? mb_strtolower($output,$encoding) : strtolower($output);
  207. break;
  208. case 'ucase':
  209. case 'uppercase':
  210. case 'strtoupper':
  211. /* See PHP's strtoupper - http://www.php.net/manual/en/function.strtoupper.php */
  212. $output = $usemb ? mb_strtoupper($output,$encoding) : strtoupper($output);
  213. break;
  214. case 'ucwords':
  215. /* See PHP's ucwords - http://www.php.net/manual/en/function.ucwords.php */
  216. $output = $usemb ? mb_convert_case($output,MB_CASE_TITLE,$encoding) : ucwords($output);
  217. break;
  218. case 'ucfirst':
  219. /* See PHP's ucfirst - http://www.php.net/manual/en/function.ucfirst.php */
  220. if ($usemb) {
  221. $output = mb_strtoupper(mb_substr($output,0,1)) . mb_substr($output, 1);
  222. } else {
  223. $output = ucfirst($output);
  224. }
  225. break;
  226. case 'htmlent':
  227. case 'htmlentities':
  228. /* See PHP's htmlentities - http://www.php.net/manual/en/function.htmlentities.php */
  229. $output = htmlentities($output,ENT_QUOTES,$encoding);
  230. break;
  231. case 'esc':
  232. case 'escape':
  233. $output = preg_replace("/&amp;(#[0-9]+|[a-z]+);/i", "&$1;", htmlspecialchars($output));
  234. $output = str_replace(array ("[", "]", "`"), array ("&#91;", "&#93;", "&#96;"), $output);
  235. break;
  236. case 'strip':
  237. /* Replaces all linebreaks, tabs and multiple spaces with just one space */
  238. $output= preg_replace("/\s+/"," ",$output);
  239. break;
  240. case 'stripString':
  241. /* strips string of this value */
  242. $output= str_replace($m_val,'',$output);
  243. break;
  244. case 'replace':
  245. /* replaces one value with another */
  246. $opt = explode('==',$m_val);
  247. if (count($opt) >= 2) {
  248. $output = str_replace($opt[0],$opt[1],$output);
  249. }
  250. break;
  251. case 'notags':
  252. case 'striptags':
  253. case 'stripTags':
  254. case 'strip_tags':
  255. /* See PHP's strip_tags - http://www.php.net/manual/en/function.strip_tags.php */
  256. if (!empty($m_val)) {
  257. $output= strip_tags($output,$m_val);
  258. } else {
  259. $output= strip_tags($output);
  260. }
  261. break;
  262. case 'length':
  263. case 'len':
  264. case 'strlen':
  265. /* See PHP's strlen - http://www.php.net/manual/en/function.strlen.php */
  266. $output = $usemb ? mb_strlen($output,$encoding) : strlen($output);
  267. break;
  268. case 'reverse':
  269. case 'strrev':
  270. /* See PHP's strrev - http://www.php.net/manual/en/function.strrev.php */
  271. if ($usemb) {
  272. $ar = array();
  273. preg_match_all('/(\d+)?./us', $output, $ar);
  274. $output = join('',array_reverse($ar[0]));
  275. } else {
  276. $output = strrev($output);
  277. }
  278. break;
  279. case 'wordwrap':
  280. /* See PHP's wordwrap - http://www.php.net/manual/en/function.wordwrap.php */
  281. $wrapat= intval($m_val);
  282. if ($wrapat) {
  283. $output= wordwrap($output, $wrapat,"<br />\n ", 0);
  284. } else {
  285. $output= wordwrap($output, 70,"<br />\n", 0);
  286. }
  287. break;
  288. case 'wordwrapcut':
  289. /* See PHP's wordwrap - http://www.php.net/manual/en/function.wordwrap.php */
  290. $wrapat= intval($m_val);
  291. if ($wrapat) {
  292. $output= wordwrap($output, $wrapat,"<br />\n ", 1);
  293. } else {
  294. $output= wordwrap($output, 70,"<br />\n", 1);
  295. }
  296. break;
  297. case 'limit':
  298. /* default: 100 */
  299. $limit= intval($m_val) ? intval($m_val) : 100;
  300. /* ensure that filter correctly counts special chars */
  301. $str = html_entity_decode($output,ENT_COMPAT,$encoding);
  302. if ($usemb) {
  303. $output= mb_substr($str,0,$limit,$encoding);
  304. } else {
  305. $output= substr($str,0,$limit);
  306. }
  307. break;
  308. case 'ellipsis':
  309. $limit= intval($m_val) ? intval($m_val) : 100;
  310. $pad = $this->modx->getOption('ellipsis_filter_pad',null,'&#8230;');
  311. /* ensure that filter correctly counts special chars */
  312. $output = html_entity_decode($output,ENT_COMPAT,$encoding);
  313. $len = $usemb ? mb_strlen($output,$encoding) : strlen($output);
  314. if ($limit > $len) $limit = $len;
  315. if ($limit < 0) $limit = 0;
  316. $breakpoint = $usemb ? mb_strpos($output," ",$limit,$encoding) : strpos($output, " ", $limit);
  317. if (false !== $breakpoint) {
  318. if ($breakpoint < $len - 1) {
  319. $partial = $usemb ? mb_substr($output, 0, $breakpoint,$encoding) : substr($output, 0, $breakpoint);
  320. $output = $partial . $pad;
  321. }
  322. }
  323. $opened = array();
  324. if (preg_match_all("/<(\/?[a-z]+)>?/i", $output, $matches)) {
  325. foreach ($matches[1] as $tag) {
  326. if (preg_match("/^[a-z]+$/i", $tag, $regs)) {
  327. $strLower = $usemb ? mb_strtolower($regs[0],$encoding) : strtolower($regs[0]);
  328. if ($strLower != 'br' || $strLower != 'hr') {
  329. $opened[] = $regs[0];
  330. }
  331. } elseif (preg_match("/^\/([a-z]+)$/i", $tag, $regs)) {
  332. $tmpArray = array_keys($opened, (string) $regs[1]);
  333. $tmpVar = array_pop($tmpArray);
  334. if ($tmpVar !== null) {
  335. unset($opened[$tmpVar]);
  336. }
  337. }
  338. }
  339. }
  340. if ($opened) {
  341. $tagstoclose = array_reverse($opened);
  342. foreach ($tagstoclose as $tag) $output .= "</$tag>";
  343. }
  344. break;
  345. /* ##### Special functions */
  346. case 'tag':
  347. /* Displays the raw element tag without :tag */
  348. $tag = $element->_tag;
  349. $tag = htmlentities($tag,ENT_QUOTES,$encoding);
  350. $tag = str_replace(array ("[", "]", "`"), array ("&#91;", "&#93;", "&#96;"), $tag);
  351. $tag = str_replace(":tag","",$tag);
  352. $output = $tag;
  353. break;
  354. case 'add':
  355. case 'increment':
  356. case 'incr':
  357. /* Returns input incremented by option (default: +1) */
  358. if (empty($m_val) && $m_val !== 0 && $m_val !== '0') {
  359. $m_val = 1;
  360. }
  361. $output = (float)$output + (float)$m_val;
  362. break;
  363. case 'subtract':
  364. case 'decrement':
  365. case 'decr':
  366. /* Returns input decremented by option (default: -1) */
  367. if (empty($m_val) && $m_val !== 0 && $m_val !== '0') {
  368. $m_val = 1;
  369. }
  370. $output = (float)$output - (float)$m_val;
  371. break;
  372. case 'multiply':
  373. case 'mpy':
  374. /* Returns input multiplied by option (default: *2) */
  375. if (empty($m_val) && $m_val !== 0 && $m_val !== '0') {
  376. $m_val = 1;
  377. }
  378. $output = (float)$output * (float)$m_val;
  379. break;
  380. case 'divide':
  381. case 'div':
  382. /* Returns input divided by option (default: /2) */
  383. if (empty($m_val)) {
  384. $m_val = 2;
  385. }
  386. if (!empty($output)) {
  387. $output = (float)$output / (float)$m_val;
  388. } else {
  389. $output = 0;
  390. }
  391. break;
  392. case 'modulus':
  393. case 'mod':
  394. /* Returns the option modulus on input (default: %2, returns 0 or 1) */
  395. if (empty($m_val))
  396. $m_val = 2;
  397. $output = (float)$output % (float)$m_val;
  398. break;
  399. case 'default':
  400. case 'ifempty':
  401. case 'isempty':
  402. case 'empty':
  403. /* Returns the input value if empty */
  404. if (empty($output))
  405. $output= $m_val;
  406. break;
  407. case 'ifnotempty':
  408. case 'isnotempty':
  409. case 'notempty':
  410. case '!empty':
  411. /* returns input value if not empty */
  412. if (!empty($output))
  413. $output= $m_val;
  414. break;
  415. case 'nl2br':
  416. /* See PHP's nl2br - http://www.php.net/manual/en/function.nl2br.php */
  417. $output= nl2br($output);
  418. break;
  419. case 'date':
  420. /* See PHP's strftime - http://www.php.net/manual/en/function.strftime.php */
  421. if (empty($m_val))
  422. $m_val = "%A, %d %B %Y %H:%M:%S"; /* @todo this should be modx default date/time format? Lexicon? */
  423. $value = 0 + $output;
  424. if ($value != 0 && $value != -1) {
  425. $output= strftime($m_val,$value);
  426. } else {
  427. $output= '';
  428. }
  429. break;
  430. case 'strtotime':
  431. /* See PHP's strtotime() function - http://www.php.net/strtotime */
  432. if (!empty($output)) {
  433. $output = strtotime($output);
  434. } else {
  435. $output = '';
  436. }
  437. break;
  438. case 'fuzzydate':
  439. /* displays a "fuzzy" date reference */
  440. if (empty($this->modx->lexicon)) $this->modx->getService('lexicon','modLexicon');
  441. $this->modx->lexicon->load('filters');
  442. if (empty($m_val)) $m_val= '%b %e';
  443. if (!empty($output)) {
  444. $time = strtotime($output);
  445. if ($time >= strtotime('today')) {
  446. $output = $this->modx->lexicon('today_at',array('time' => strftime('%I:%M %p',$time)));
  447. } elseif ($time >= strtotime('yesterday')) {
  448. $output = $this->modx->lexicon('yesterday_at',array('time' => strftime('%I:%M %p',$time)));
  449. } else {
  450. $output = strftime($m_val, $time);
  451. }
  452. } else {
  453. $output = '&mdash;';
  454. }
  455. break;
  456. case 'ago':
  457. /* calculates relative time ago from a timestamp */
  458. if (empty($output)) break;
  459. if (empty($this->modx->lexicon)) $this->modx->getService('lexicon','modLexicon');
  460. $this->modx->lexicon->load('filters');
  461. $agoTS = array();
  462. $uts['start'] = strtotime($output);
  463. $uts['end'] = time();
  464. if( $uts['start']!==-1 && $uts['end']!==-1 ) {
  465. if( $uts['end'] >= $uts['start'] ) {
  466. $diff = $uts['end'] - $uts['start'];
  467. $years = intval((floor($diff/31536000)));
  468. if ($years) $diff = $diff % 31536000;
  469. $months = intval((floor($diff/2628000)));
  470. if ($months) $diff = $diff % 2628000;
  471. $weeks = intval((floor($diff/604800)));
  472. if ($weeks) $diff = $diff % 604800;
  473. $days = intval((floor($diff/86400)));
  474. if ($days) $diff = $diff % 86400;
  475. $hours = intval((floor($diff/3600)));
  476. if ($hours) $diff = $diff % 3600;
  477. $minutes = intval((floor($diff/60)));
  478. if ($minutes) $diff = $diff % 60;
  479. $diff = intval($diff);
  480. $agoTS = array(
  481. 'years' => $years,
  482. 'months' => $months,
  483. 'weeks' => $weeks,
  484. 'days' => $days,
  485. 'hours' => $hours,
  486. 'minutes' => $minutes,
  487. 'seconds' => $diff,
  488. );
  489. }
  490. }
  491. $ago = array();
  492. if (!empty($agoTS['years'])) {
  493. $ago[] = $this->modx->lexicon(($agoTS['years'] > 1 ? 'ago_years' : 'ago_year'),array('time' => $agoTS['years']));
  494. }
  495. if (!empty($agoTS['months'])) {
  496. $ago[] = $this->modx->lexicon(($agoTS['months'] > 1 ? 'ago_months' : 'ago_month'),array('time' => $agoTS['months']));
  497. }
  498. if (!empty($agoTS['weeks']) && empty($agoTS['years'])) {
  499. $ago[] = $this->modx->lexicon(($agoTS['weeks'] > 1 ? 'ago_weeks' : 'ago_week'),array('time' => $agoTS['weeks']));
  500. }
  501. if (!empty($agoTS['days']) && empty($agoTS['months']) && empty($agoTS['years'])) {
  502. $ago[] = $this->modx->lexicon(($agoTS['days'] > 1 ? 'ago_days' : 'ago_day'),array('time' => $agoTS['days']));
  503. }
  504. if (!empty($agoTS['hours']) && empty($agoTS['weeks']) && empty($agoTS['months']) && empty($agoTS['years'])) {
  505. $ago[] = $this->modx->lexicon(($agoTS['hours'] > 1 ? 'ago_hours' : 'ago_hour'),array('time' => $agoTS['hours']));
  506. }
  507. if (!empty($agoTS['minutes']) && empty($agoTS['days']) && empty($agoTS['weeks']) && empty($agoTS['months']) && empty($agoTS['years'])) {
  508. $ago[] = $this->modx->lexicon($agoTS['minutes'] == 1 ? 'ago_minute' : 'ago_minutes' ,array('time' => $agoTS['minutes']));
  509. }
  510. if (empty($ago)) { /* handle <1 min */
  511. $ago[] = $this->modx->lexicon('ago_seconds',array('time' => !empty($agoTS['seconds']) ? $agoTS['seconds'] : 0));
  512. }
  513. $output = implode(', ',$ago);
  514. $output = $this->modx->lexicon('ago',array('time' => $output));
  515. break;
  516. case 'md5':
  517. /* See PHP's md5 - http://www.php.net/manual/en/function.md5.php */
  518. $output= md5($output);
  519. break;
  520. case 'cdata':
  521. if ($usemb) {
  522. $len = mb_strlen($output,$encoding);
  523. if (mb_strpos($output,'[',0,$encoding) === 0) { $output = ' '.$output; }
  524. if (mb_strpos($output,']',0,$encoding) === $len) { $output = $output.' '; }
  525. } else {
  526. $len = strlen($output);
  527. if (strpos($output,'[') === 0) { $output = ' '.$output; }
  528. if (strpos($output,']') === $len) { $output = $output.' '; }
  529. }
  530. $output= "<![CDATA[{$output}]]>";
  531. break;
  532. case 'userinfo':
  533. /* Returns the requested modUser or modUserProfile data (input: user id) */
  534. if (!empty($output)) {
  535. $key = (!empty($m_val)) ? $m_val : 'username';
  536. $userInfo= null;
  537. /** @var modUser $user */
  538. if ($user= $this->modx->getObjectGraph('modUser', '{"Profile":{}}', $output)) {
  539. $userData = array_merge($user->toArray(), $user->Profile->toArray());
  540. unset($userData['cachepwd'], $userData['salt'], $userData['sessionid'], $userData['password'], $userData['session_stale']);
  541. if (strpos($key, 'extended.') === 0 && isset($userData['extended'][substr($key, 9)])) {
  542. $userInfo = $userData['extended'][substr($key, 9)];
  543. } elseif (strpos($key, 'remote_data.') === 0 && isset($userData['remote_data'][substr($key, 12)])) {
  544. $userInfo = $userData['remote_data'][substr($key, 12)];
  545. } elseif (isset($userData[$key])) {
  546. $userInfo = $userData[$key];
  547. }
  548. }
  549. $output = $userInfo;
  550. } else {
  551. $output = null;
  552. }
  553. break;
  554. case 'isloggedin':
  555. /* returns true if user is logged in to the specified context or by default the current context */
  556. $ctxkey = (!empty($m_val)) ? $m_val : $this->modx->context->get('key');
  557. $output= $this->modx->user->isAuthenticated($ctxkey);
  558. $output= $output ? true : false;
  559. break;
  560. case 'isnotloggedin':
  561. /* returns true if user is not logged in to the specified context or by default the current context */
  562. $ctxkey = (!empty($m_val)) ? $m_val : $this->modx->context->get('key');
  563. $output= $this->modx->user->isAuthenticated($ctxkey);
  564. $output= $output ? false : true;
  565. break;
  566. case 'urlencode':
  567. $output = urlencode($output);
  568. break;
  569. case 'urldecode':
  570. $output = urldecode($output);
  571. break;
  572. case 'toPlaceholder':
  573. $this->modx->toPlaceholder($m_val,$output);
  574. $output = '';
  575. break;
  576. case 'cssToHead':
  577. $this->modx->regClientCSS($output);
  578. $output = '';
  579. break;
  580. case 'htmlToHead':
  581. $this->modx->regClientStartupHTMLBlock($output);
  582. $output = '';
  583. break;
  584. case 'htmlToBottom':
  585. $this->modx->regClientHTMLBlock($output);
  586. $output = '';
  587. break;
  588. case 'jsToHead':
  589. if (empty($m_val)) $m_val = false;
  590. $this->modx->regClientStartupScript($output,$m_val);
  591. $output = '';
  592. break;
  593. case 'jsToBottom':
  594. if (empty($m_val)) $m_val = false;
  595. $this->modx->regClientScript($output,$m_val);
  596. $output = '';
  597. break;
  598. case 'in':
  599. case 'IN':
  600. case 'inarray':
  601. case 'inArray':
  602. if (empty($m_val)) $m_val = false;
  603. $haystack = explode(',', $m_val);
  604. $condition[]= intval(in_array($output, $haystack));
  605. break;
  606. /* Default, custom modifier (run snippet with modifier name) */
  607. default:
  608. /*@todo Possibility to only look for snippet names prefixed with 'filter:' */
  609. /*@todo Maybe pass whole element by reference instead of token/tag/name? */
  610. $params = array (
  611. 'input' => $output,
  612. 'options' => $m_val,
  613. 'token' => $element->_token, /* type of parent element */
  614. 'name' => $element->get('name'), /* name of the parent element */
  615. 'tag' => $element->getTag() /* complete parent tag */
  616. );
  617. $this->log('This modifier is custom running as snippet.');
  618. $tmp = $this->modx->runSnippet($m_cmd, $params);
  619. if ($tmp!='') $output = $tmp;
  620. break;
  621. }
  622. } catch (Exception $e) {
  623. $this->modx->log(modX::LOG_LEVEL_ERROR,$e->getMessage());
  624. }
  625. }
  626. // convert $output to string if there were any processing
  627. $output = (string)$output;
  628. }
  629. }
  630. /**
  631. * Send a log message to the message logger
  632. * @param string $msg
  633. * @return void
  634. */
  635. public function log($msg) {
  636. if ($this->modx->getDebug() === true) {
  637. $this->modx->log(modX::LOG_LEVEL_DEBUG, $msg);
  638. }
  639. }
  640. }