WYSIJA_help_render_engine

The MailPoet Newsletters WYSIJA help render engine class.

Defined (1)

The class is defined in the following location(s).

/helpers/render_engine.php  
  1. class WYSIJA_help_render_engine extends WYSIJA_object { 
  2. private $_template = null; 
  3. private $_template_path = array(); 
  4. private $_data_path = null; 
  5. private $_strip_special_chars = false; 
  6. private $_render_time = false; 
  7. private $_i18n = null; 
  8. private $_lc_time = ''; 
  9. private $_inline = false; 
  10. private $_fonts = array( 
  11. 'Arial' => "Arial, 'Helvetica Neue', Helvetica, sans-serif",  
  12. 'Comic Sans MS' => "'Comic Sans MS', 'Marker Felt-Thin', Arial, sans-serif",  
  13. 'Courier New' => "'Courier New', Courier, 'Lucida Sans Typewriter', 'Lucida Typewriter', monospace",  
  14. 'Georgia' => "Georgia, Times, 'Times New Roman', serif",  
  15. 'Tahoma' => "Tahoma, Verdana, Segoe, sans-serif",  
  16. 'Times New Roman' => "'Times New Roman', Times, Baskerville, Georgia, serif",  
  17. 'Trebuchet MS' => "'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Tahoma, sans-serif",  
  18. 'Verdana' => "Verdana, Geneva, sans-serif" 
  19. ); 
  20.  
  21. const _OPEN = '{'; 
  22. const _CLOSE = '}'; 
  23. const _LOOP = 'loop'; 
  24. const _FOREACH = 'foreach'; 
  25. const _INCLUDE = 'include'; 
  26. const _TRANSLATE = 'translate'; 
  27. const _IF = 'if'; 
  28. const _SET = 'set'; 
  29. const _COUNTER = 'i'; 
  30. const _PAIR = 'IS_PAIR'; 
  31. const _FIRST = 'IS_FIRST'; 
  32. const _LAST = 'IS_LAST'; 
  33. const _VALUE = '_VALUE'; 
  34. const _FIRST_COL = 'IS_FIRST_COL'; 
  35. const _LAST_COL = 'IS_LAST_COL'; 
  36. const _FIRST_ROW = 'IS_FIRST_ROW'; 
  37. const _LAST_ROW = 'IS_LAST_ROW'; 
  38. const _VAR = '([\$#])([\w-_\.]+)'; 
  39. const _MODIFIER = "(\|{0, 1}[^}]*)"; 
  40.  
  41. function __construct () { } 
  42.  
  43. public function setLcTime ($lc_time) 
  44. $this->_lc_time = $lc_time; 
  45.  
  46. public function setTranslator($i18n) 
  47. $this->_i18n = $i18n; 
  48.  
  49. public function setTemplatePath ($path) 
  50. if (!is_array ($path)) { 
  51. $path = array ($path); 
  52. $this->_template_path = $path; 
  53.  
  54. public function getTemplatePath () 
  55. return $this->_template_path; 
  56.  
  57. public function setDataPath ($path) 
  58. $this->_data_path = $path; 
  59.  
  60. public function setStripSpecialchars ($value) 
  61. $this->_strip_special_chars = $value; 
  62.  
  63. public function setInline($bool) 
  64. $this->_inline = $bool; 
  65. $this->_inline = false; 
  66.  
  67. public function renderCSS($vars) { 
  68. $result = array(); 
  69.  
  70. if (isset($vars['family'])) { 
  71. $font_family = '\''.$vars['family'].'\''; 
  72. // check if we have fallbacks for this font 
  73. if(array_key_exists($vars['family'], $this->_fonts)) { 
  74. $font_family = $this->_fonts[$vars['family']]; 
  75. $result[] = 'font-family: '.$font_family.';'; 
  76. if (isset($vars['size'])) $result[] = 'font-size: ' . self::_css_format_font_size_value($vars['size']) . ';'; 
  77. if (isset($vars['color'])) $result[] = 'color: ' . self::_css_format_color($vars['color']) . ';color: ' . self::_css_format_color($vars['color']) . ' !important;'; 
  78. if (isset($vars['background']) && $vars['background'] !== '') $result[] = 'background-color: ' . self::_css_format_color($vars['background']) . ';'; 
  79. if (isset($vars['underline'])) { 
  80. if ($vars['underline'] == '1') $result[] = 'text-decoration: underline;'; 
  81. elseif ($vars['underline'] == '-1') $result[] = 'text-decoration: none;'; 
  82. if (isset($vars['text-decoration'])) $result[] = 'text-decoration: ' . $vars['text-decoration'] . ';'; 
  83. if (isset($vars['outline'])) $result[] = 'outline: ' . $vars['outline'] . ';'; 
  84. if (isset($vars['height'])) $result[] = 'height: ' . $vars['height'] . ';'; 
  85. if (isset($vars['border']) && is_array($vars['border'])) { 
  86. $result[] = 'border: ' . $vars['border']['size'] . ' ' . $vars['border']['style'] . ' ' . $vars['border']['color'] . ';'; 
  87. } else { 
  88. $result[] = 'border: 0;'; 
  89. if (isset($vars['border-collapse'])) $result[] = 'border-collapse: ' . $vars['border-collapse'] . ';'; 
  90. if (isset($vars['mso-table-space'])) $result[] = 'mso-table-lspace: ' . $vars['mso-table-space'] . '; mso-table-rspace: ' . $vars['mso-table-space'] . ';'; 
  91. if (isset($vars['text-align'])) $result[] = 'text-align: ' . $vars['text-align'] . ';'; 
  92. if (isset($vars['font-weight'])) $result[] = 'font-weight: ' . $vars['font-weight'] . ';'; 
  93. if (isset($vars['font-style'])) $result[] = 'font-style: ' . $vars['font-style'] . ';'; 
  94. if (isset($vars['letter-spacing'])) $result[] = 'letter-spacing: ' . $vars['letter-spacing'] . ';'; 
  95. if (isset($vars['line-height'])) { 
  96. if ($vars['line-height'] == '0') { 
  97. $result[] = 'line-height: 0;'; 
  98. } else { 
  99. $result[] = 'mso-line-height-rule: exactly;-mso-line-height-rule: exactly;line-height: ' . self::_css_format_line_height($vars['line-height']) . ';'; 
  100. if (isset($vars['list-style-position'])) $result[] = 'list-style-position: ' . $vars['list-style-position'] . ';'; 
  101. if (isset($vars['list-style-type'])) $result[] = 'list-style-type: ' . $vars['list-style-type'] . ';'; 
  102. if (isset($vars['list-style'])) $result[] = 'list-style: ' . $vars['list-style'] . ';'; 
  103. if (isset($vars['display'])) $result[] = 'display: ' . $vars['display'] . ';'; 
  104. if (isset($vars['margin'])) $result[] = 'margin: ' . $vars['margin'] . ';'; 
  105. if (isset($vars['padding'])) $result[] = 'padding: ' . $vars['padding'] . ';'; 
  106. if (isset($vars['margin-top']) && $vars['margin-top'] != '') $result[] = 'margin-top: ' . $vars['margin-top'] . ';'; 
  107. if (isset($vars['margin-right']) && $vars['margin-right'] != '') $result[] = 'margin-right: ' . $vars['margin-right'] . ';'; 
  108. if (isset($vars['margin-bottom']) && $vars['margin-bottom'] != '') $result[] = 'margin-bottom: ' . $vars['margin-bottom'] . ';'; 
  109. if (isset($vars['margin-left']) && $vars['margin-left'] != '') $result[] = 'margin-left: ' . $vars['margin-left'] . ';'; 
  110. if (isset($vars['padding-top']) && $vars['padding-top'] != '') $result[] = 'padding-top: ' . $vars['padding-top'] . ';'; 
  111. if (isset($vars['padding-right']) && $vars['padding-right'] != '') $result[] = 'padding-right: ' . $vars['padding-right'] . ';'; 
  112. if (isset($vars['padding-bottom']) && $vars['padding-bottom'] != '') $result[] = 'padding-bottom: ' . $vars['padding-bottom'] . ';'; 
  113. if (isset($vars['padding-left']) && $vars['padding-left'] != '') $result[] = 'padding-left: ' . $vars['padding-left'] . ';'; 
  114. if (isset($vars['clear'])) $result[] = 'clear: ' . $vars['clear'] . ';'; 
  115. if (isset($vars['float'])) $result[] = 'float: ' . $vars['float'] . ';'; 
  116. if (isset($vars['vertical-align'])) $result[] = 'vertical-align: ' . $vars['vertical-align'] . ';'; 
  117. if (isset($vars['word-wrap'])) $result[] = 'word-wrap: break-word;'; 
  118. if (isset($vars['interpolation'])) $result[] = '-ms-interpolation-mode: ' . $vars['interpolation'] . ';'; 
  119. if (isset($vars['min-width'])) $result[] = 'min-width: ' . $vars['min-width'] . ';'; 
  120. if (isset($vars['max-width'])) $result[] = 'max-width: ' . $vars['max-width'] . ';'; 
  121. if (isset($vars['outlook_fix_tr'])) $result[] = 'font-size: 1px; mso-line-height-alt: 0; mso-margin-top-alt: 1px;'; 
  122.  
  123. return implode('', $result); 
  124.  
  125. public function render($vars, $template) 
  126. if (is_object ($vars)) { 
  127. $vars = get_object_vars($vars); 
  128. if ($string = $this->_loadTemplate ($template)) { 
  129. if ($this->_render_time) { 
  130. $time_start = microtime(); 
  131. $this->_vars = $vars; 
  132.  
  133. if($this->_inline) { 
  134. // inline mode (removes any tabs, carriage return, line breaks) 
  135. $string = preg_replace("#(\t|\r|\n)#UiS", '', trim($string)); 
  136. $string = preg_replace("#> +<#UiS", '><', $string); 
  137.  
  138. $output = $this->_parse($string); 
  139.  
  140. if ($this->_render_time) { 
  141. $time_end = microtime(); 
  142. $time = $time_end - $time_start; 
  143. $output .= "<div>wysija rendering engine rendering took : $time second(s)</div>"; 
  144. return $output; 
  145. } else { 
  146. throw new Exception('wysija rendering engine needs a template'); 
  147.  
  148. // converts HTML template to PrototypeJS Template 
  149. protected function _parseForJS($string, $vars = null) { 
  150. $old_string = $string; 
  151. if (null === $vars) { 
  152. $vars =& $this->_vars; 
  153.  
  154. # search loop, include or if statement 
  155. while (preg_match ("`".self::_OPEN."(".self::_LOOP."|".self::_FOREACH."|".self::_INCLUDE."|".self::_IF."|".self::_SET."|".self::_TRANSLATE.")([^\{]*?)".self::_CLOSE."`", $string, $preg)) { 
  156. $result_pattern = ''; 
  157. $tag_mask = $preg[0]; 
  158. $tag_type = $preg[1]; 
  159. $tag_properties = $preg[2]; 
  160.  
  161. # LOOP & FOREACH 
  162. if ($tag_type == self::_LOOP || $tag_type == self::_FOREACH ) { 
  163. $loop_name = $this->_getProperty ('name', $tag_properties); 
  164. $loop_as = $this->_getProperty ('value', $tag_properties); 
  165. $loop_key = $this->_getProperty ('key', $tag_properties); 
  166. $loop_row_size = $this->_getProperty ('row_size', $tag_properties); 
  167. $reverse = $this->_getProperty ('reverse', $tag_properties); 
  168.  
  169. # define loop string and replace pattern 
  170. $loop_replace_pattern = $this->_getEncapsuledPattern ($string, $tag_type, $tag_mask); 
  171. preg_match ("`".$loop_replace_pattern."`s", $string, $loops); 
  172. $loop_string = $loops[1]; 
  173.  
  174. # loop on array 
  175. preg_match ("`^".self::_VAR."`", $loop_name, $preg); 
  176. $loop_array = $this->_getValue ($preg, $vars); 
  177.  
  178. if ($reverse) { 
  179. $loop_array = array_reverse ($loop_array); 
  180.  
  181. if (is_array ($loop_array)) { 
  182. $count = count ($loop_array); 
  183. $loop = array (); 
  184. $i = 0; 
  185. foreach ($loop_array as $line) { 
  186. # meta values 
  187. if (is_array($line)) { 
  188. # is pair ? 
  189. $line[self::_PAIR] = ($i+1)%2 ; 
  190.  
  191. # position in list 
  192. $i < $count-1 ? $line[self::_LAST] = false : $line[self::_LAST] = true; 
  193. $i === 0 ? $line[self::_FIRST] = true : $line[self::_FIRST] = false; 
  194.  
  195. # rows and columns infos 
  196. if ($loop_row_size) { 
  197. # col position 
  198. ($i+1)%$loop_row_size ? $line[self::_LAST_COL] = false : $line[self::_LAST_COL] = true; 
  199. ($i+1)%$loop_row_size === 1 ? $line[self::_FIRST_COL] = true : $line[self::_FIRST_COL] = false; 
  200.  
  201. # row position 
  202. $i<$loop_row_size ? $line[self::_FIRST_ROW] = true : $line[self::_FIRST_ROW] = false; 
  203. $modulo = $count%$loop_row_size; 
  204. if (($modulo && $i>=$count-$modulo) || (!$modulo && $i>=$count-$loop_row_size)) { 
  205. $line[self::_LAST_ROW] = true; 
  206. } else { 
  207. $line[self::_LAST_ROW] = false; 
  208.  
  209. # switch case 
  210. if ($tag_type == self::_LOOP) { 
  211. $loop_key ? $line[$loop_key] = $i : $line[self::_COUNTER] = $i; 
  212. $loop[] = $this->_parseForJS($loop_string, $line); 
  213. } else { 
  214. $loop_key ? $vars[$loop_key] = $i : $vars[self::_COUNTER] = $i; 
  215. $vars[$loop_as] = $line; 
  216. $loop[] = $this->_parseForJS($loop_string, $vars); 
  217. $i++; 
  218.  
  219. $result_pattern .= implode ($loop, ''); 
  220.  
  221. # replace 
  222. $string = preg_replace ("`".$loop_replace_pattern."`s", $result_pattern, $string, 1); 
  223.  
  224. # IF 
  225. if ($tag_type == self::_IF) { 
  226. $replace_pattern = $this->_getEncapsuledPattern ($string, self::_IF, $tag_mask); 
  227. preg_match ("`".$replace_pattern."`s", $string, $result); 
  228. $if_string = $result[1]; 
  229.  
  230. # condition 
  231. if ($this->_getConditionResult ($tag_properties, $vars)) { 
  232. $result_pattern = $if_string; 
  233.  
  234. # replace 
  235. $string = preg_replace ("`".$replace_pattern."`s", $result_pattern, $string, 1); 
  236.  
  237. # INCLUDE 
  238. if ($tag_type == self::_INCLUDE) { 
  239. $replace_pattern = $tag_mask; 
  240. $include_file = $this->_getProperty ('file', $tag_properties); 
  241. $var_type = substr($include_file, 0, 1); 
  242. if ($var_type == '#' || $var_type == '$') { 
  243. $var_name = substr($include_file, 1, strlen($include_file)-1); 
  244. $include_file = $this->_getValue (array($include_file, $var_type, $var_name), $vars); 
  245. $result_pattern = $this->_loadTemplate($include_file); 
  246. } else { 
  247. $result_pattern = $this->_loadTemplate($include_file); 
  248.  
  249. # replace 
  250. $string = str_replace ($tag_mask, $result_pattern, $string); 
  251.  
  252. # SET 
  253. if ($tag_type == self::_SET) { 
  254. $replace_pattern = $tag_mask; 
  255. $var_name = $this->_getProperty ('var', $tag_properties); 
  256. $var_type = substr ($var_name, 0, 1); 
  257. $var_name = substr ($var_name, 1, strlen ($var_name)-1); 
  258. $var_value = $this->_getProperty ('value', $tag_properties); 
  259. $var_concat = $this->_getProperty ('concat', $tag_properties); 
  260.  
  261. if ($var_value) { 
  262. if (preg_match ("`".self::_VAR.self::_MODIFIER."`", $var_value, $is_var)) { 
  263. $var_value = $this->_getValue ($is_var, $vars); 
  264. } else if ($var_concat) { 
  265. $split = explode (', ', $var_concat); 
  266. $var_value = ''; 
  267. foreach ($split as $value) { 
  268. if (preg_match ("`".self::_VAR.self::_MODIFIER."`", $value, $is_var)) { 
  269. $var_value .= $this->_getValue ($is_var, $vars); 
  270. } else { 
  271. $var_value .= $value; 
  272.  
  273. # set value 
  274. if ($var_type == '#') { 
  275. $this->_setValue($var_name, $var_value, $vars); 
  276. } else if ($var_type == '$') { 
  277. $this->_setValue($var_name, $var_value, $this->_vars); 
  278.  
  279. # replace 
  280. $string = str_replace ($tag_mask, '', $string); 
  281.  
  282.  
  283. //return $string; 
  284.  
  285. $string = $this->_replaceForJS($string, $vars); 
  286. return $string; 
  287.  
  288. // render HTML templates 
  289. protected function _parse($string, $vars=null) 
  290. $old_string = $string; 
  291. if (null === $vars) { 
  292. $vars =& $this->_vars; 
  293.  
  294. # search loop, include or if statement 
  295. while (preg_match ("`".self::_OPEN."(".self::_LOOP."|".self::_FOREACH."|".self::_INCLUDE."|".self::_IF."|".self::_SET."|".self::_TRANSLATE.")([^\{]*?)".self::_CLOSE."`", $string, $preg)) { 
  296. $result_pattern = ''; 
  297. $tag_mask = $preg[0]; 
  298. $tag_type = $preg[1]; 
  299. $tag_properties = $preg[2]; 
  300.  
  301. # LOOP & FOREACH 
  302. if ($tag_type == self::_LOOP || $tag_type == self::_FOREACH ) { 
  303. $loop_name = $this->_getProperty ('name', $tag_properties); 
  304. $loop_as = $this->_getProperty ('value', $tag_properties); 
  305. $loop_key = $this->_getProperty ('key', $tag_properties); 
  306. $loop_row_size = (int)$this->_getProperty ('row_size', $tag_properties); 
  307. $reverse = $this->_getProperty ('reverse', $tag_properties); 
  308.  
  309. # define loop string and replace pattern 
  310. $loop_replace_pattern = $this->_getEncapsuledPattern ($string, $tag_type, $tag_mask); 
  311. preg_match ("`".$loop_replace_pattern."`s", $string, $loops); 
  312. $loop_string = $loops[1]; 
  313.  
  314. # loop on array 
  315. preg_match ("`^".self::_VAR."`", $loop_name, $preg); 
  316. $loop_array = $this->_getValue ($preg, $vars); 
  317.  
  318. if($reverse) { 
  319. $loop_array = array_reverse ($loop_array); 
  320.  
  321. if(is_array($loop_array)) { 
  322. $count = count ($loop_array); 
  323. $loop = array (); 
  324. $i = 0; 
  325. foreach ($loop_array as $key => $line) { 
  326. # meta values 
  327. if (is_array($line)) { 
  328. # is pair ? 
  329. $line[self::_PAIR] = ($i+1)%2 ; 
  330.  
  331. # position in list 
  332. $i < $count-1 ? $line[self::_LAST] = false : $line[self::_LAST] = true; 
  333. $i === 0 ? $line[self::_FIRST] = true : $line[self::_FIRST] = false; 
  334.  
  335. # rows and columns infos 
  336. if ($loop_row_size) { 
  337. # col position 
  338. (($i+1) % $loop_row_size) ? $line[self::_LAST_COL] = false : $line[self::_LAST_COL] = true; 
  339. (($i+1) % $loop_row_size === 1) ? $line[self::_FIRST_COL] = true : $line[self::_FIRST_COL] = false; 
  340.  
  341. # row position 
  342. ($i < $loop_row_size) ? $line[self::_FIRST_ROW] = true : $line[self::_FIRST_ROW] = false; 
  343. $modulo = $count % $loop_row_size; 
  344. if(($modulo && $i>=$count-$modulo) || (!$modulo && $i>=$count-$loop_row_size)) { 
  345. $line[self::_LAST_ROW] = true; 
  346. } else { 
  347. $line[self::_LAST_ROW] = false; 
  348.  
  349. # switch case 
  350. if($tag_type == self::_LOOP) { 
  351. $loop_key ? $line[$loop_key] = $i : $line[self::_COUNTER] = $i; 
  352. $loop[] = $this->_parse($loop_string, $line); 
  353. } else { 
  354. //$loop_key ? $vars[$loop_key] = $i : $vars[self::_COUNTER] = $i; 
  355. $vars[self::_COUNTER] = $i; 
  356. $vars[$loop_key] = $key; 
  357. $vars[$loop_as] = $line; 
  358. $loop[] = $this->_parse($loop_string, $vars); 
  359. $i++; 
  360.  
  361. $result_pattern .= implode ($loop, ''); 
  362.  
  363. # replace 
  364. $string = preg_replace ("`".$loop_replace_pattern."`s", $result_pattern, $string, 1); 
  365.  
  366. # IF 
  367. if ($tag_type == self::_IF) { 
  368. $replace_pattern = $this->_getEncapsuledPattern ($string, self::_IF, $tag_mask); 
  369. preg_match ("`".$replace_pattern."`s", $string, $result); 
  370. $if_string = $result[1]; 
  371.  
  372. # condition 
  373. if ($this->_getConditionResult ($tag_properties, $vars)) { 
  374. $result_pattern = $if_string; 
  375.  
  376. # replace 
  377. $string = preg_replace ("`".$replace_pattern."`s", $result_pattern, $string, 1); 
  378.  
  379. # INCLUDE 
  380. if ($tag_type == self::_INCLUDE) { 
  381. $replace_pattern = $tag_mask; 
  382. $include_file = $this->_getProperty ('file', $tag_properties); 
  383. $var_type = substr ($include_file, 0, 1); 
  384. if ($var_type == '#' || $var_type == '$') { 
  385. $var_name = substr ($include_file, 1, strlen($include_file)-1); 
  386. $include_file = $this->_getValue (array ($include_file, $var_type, $var_name), $vars); 
  387. $result_pattern = $this->_loadTemplate ($include_file); 
  388. } else { 
  389. $result_pattern = $this->_loadTemplate ($include_file); 
  390.  
  391. # replace 
  392. $string = str_replace ($tag_mask, $result_pattern, $string); 
  393.  
  394. # TRANSLATE 
  395. if ($tag_type == self::_TRANSLATE) { 
  396. $replace_pattern = $tag_mask; 
  397. $key = $this->_getProperty ('key', $tag_properties); 
  398. $into = $this->_getProperty ('into', $tag_properties); 
  399.  
  400. $default = $this->_getProperty ('default', $tag_properties); 
  401. if (preg_match ("`".self::_VAR.self::_MODIFIER."`", $default, $is_var)) { 
  402. $default = $this->_getValue ($is_var, $vars); 
  403.  
  404. $key_list = explode (', ', $key); 
  405. foreach ($key_list as $i=>$key) { 
  406. $var_type = $this->_getVarType($key); 
  407. if ($var_type == '#' || $var_type == '$') { 
  408. $key_list[$i] = $this->_getValue (array ($key, $var_type, $this->_getVarName($key)), $vars); 
  409.  
  410. if ($this->_i18n !== null) { 
  411. $key = implode ('', $key_list); 
  412. $tmp = $this->_i18n->translate ($key); 
  413. if ($tmp == $key) { 
  414. $result_pattern = $default; 
  415. } else { 
  416. $result_pattern = $tmp; 
  417. } else { 
  418. $result_pattern = $default; 
  419.  
  420. # replace 
  421. if ($into) { 
  422. $var_type = $this->_getVarType($into); 
  423. $var_name = $this->_getVarName($into); 
  424. if ($var_type == '#') { 
  425. $this->_setValue($var_name, $result_pattern, $vars); 
  426. } else if ($var_type == '$') { 
  427. $this->_setValue($var_name, $result_pattern, $this->_vars); 
  428. $result_pattern = ''; 
  429.  
  430. $string = str_replace ($tag_mask, $result_pattern, $string); 
  431.  
  432. # SET 
  433. if ($tag_type == self::_SET) { 
  434. $replace_pattern = $tag_mask; 
  435. $var_name = $this->_getProperty ('var', $tag_properties); 
  436. $var_type = substr ($var_name, 0, 1); 
  437. $var_name = substr ($var_name, 1, strlen ($var_name)-1); 
  438. $var_value = $this->_getProperty ('value', $tag_properties); 
  439. $var_concat = $this->_getProperty ('concat', $tag_properties); 
  440.  
  441. if ($var_value) { 
  442. if (preg_match ("`".self::_VAR.self::_MODIFIER."`", $var_value, $is_var)) { 
  443. $var_value = $this->_getValue ($is_var, $vars); 
  444. } else if ($var_concat) { 
  445. $split = explode (', ', $var_concat); 
  446. $var_value = ''; 
  447. foreach ($split as $value) { 
  448. if (preg_match ("`".self::_VAR.self::_MODIFIER."`", $value, $is_var)) { 
  449. $var_value .= $this->_getValue ($is_var, $vars); 
  450. } else { 
  451. $var_value .= $value; 
  452.  
  453. # set value 
  454. if ($var_type == '#') { 
  455. $this->_setValue($var_name, $var_value, $vars); 
  456. } else if ($var_type == '$') { 
  457. $this->_setValue($var_name, $var_value, $this->_vars); 
  458.  
  459. # replace 
  460. $string = str_replace ($tag_mask, '', $string); 
  461.  
  462. $string = $this->_replace ($string, $vars); 
  463. return $string; 
  464.  
  465. protected function _getVarType ($var_name) 
  466. return substr ($var_name, 0, 1); 
  467.  
  468. protected function _getVarName ($var_name) 
  469. return substr ($var_name, 1, strlen ($var_name)-1); 
  470.  
  471. protected function _replace ($string, $vars) 
  472. while(preg_match ("`".self::_OPEN.self::_VAR.self::_MODIFIER.self::_CLOSE."`", $string, $reg)) { 
  473. $value = $this->_getValue ($reg, $vars); 
  474. $string = str_replace ($reg[0], strval ($value), $string); 
  475. return $string; 
  476.  
  477. protected function _replaceForJS($string, $vars) 
  478. while(preg_match ("`".self::_OPEN.self::_VAR.self::_MODIFIER.self::_CLOSE."`", $string, $reg)) { 
  479. //$value = $this->_getValue ($reg, $vars); 
  480. //$value = var_export($reg, false); 
  481. $value = $this->_convertVarToJS($reg); 
  482. $string = str_replace($reg[0], strval ($value), $string); 
  483. return $string; 
  484.  
  485. protected function _convertVarToJS($var) { 
  486. if(isset($var[2])) { 
  487. //return '#{element'.ucfirst($var[2]).'}'; 
  488. return '#{'.$var[2].'}'; 
  489. } else { 
  490. return $var[0]; 
  491.  
  492. protected function _getConditionResult ($condition, $vars) 
  493. preg_match_all ("`".self::_VAR."`", $condition, $preg_list); 
  494. $count = count($preg_list[0]); 
  495. for ($i=0; $i<$count; $i++) { 
  496. $preg = array ($preg_list[0][$i], $preg_list[1][$i], $preg_list[2][$i]); 
  497. $value[$i] = $this->_getValue ($preg, $vars); 
  498. $condition = substr_replace ($condition, '$value['.$i.']', strpos ($condition, $preg[0]), strlen ($preg[0])); 
  499.  
  500. $eval_string = sprintf ("if (%s) {\$result=true;} else {\$result=false;}", $condition); 
  501. @eval ($eval_string); 
  502. return $result; 
  503.  
  504. protected function _setValue ($var_string, $value, &$vars) 
  505. # array 
  506. $array = explode('.', $var_string); 
  507. $count_array = count ($array); 
  508. if ($count_array > 1) { 
  509. $string_eval = "\$vars['".$array[0]."']"; 
  510. for ($i=1; $i<$count_array; $i++) { 
  511. $string_eval .= "['".$array[$i]."']"; 
  512. $string_eval .= " = \$value;"; 
  513. eval($string_eval); 
  514. } else { 
  515. $vars[$var_string] = $value; 
  516.  
  517. protected function _getValue ($reg, $vars=null) 
  518. if ($reg[1] == '$') { 
  519. $vars = $this->_vars; 
  520. } else if (null === $vars) { 
  521. $vars =& $this->_vars; 
  522.  
  523. $key = $reg[2]; 
  524. if (isset ($reg[3])) { 
  525. $modifier = $reg[3]; 
  526. $value = ''; 
  527.  
  528. $split = explode (".", $key); 
  529. $split_count = count ($split); 
  530. # array 
  531. if ($split_count > 1 && isset ($vars[$split[0]]) && is_array ($vars[$split[0]])) { 
  532. $value = $vars[$split[0]]; 
  533. for ($i=1; $i<$split_count; $i++) { 
  534. if (isset ($value[$split[$i]])) { 
  535. $value = $value[$split[$i]]; 
  536. } else { 
  537. $value = null; 
  538. # object 
  539. else if ($split_count == 2 && isset ($vars[$split[0]]) && is_object($vars[$split[0]])) { 
  540. $object = $vars[$split[0]]; 
  541. $key = $split[1]; 
  542. if (isset ($object->$key)) { 
  543. $value = $object->$key; 
  544. # regular var 
  545. if (isset ($vars[$key])) { 
  546. $value = $vars[$key]; 
  547. } else 
  548. # constant 
  549. if (defined ($key)) { 
  550. $value = constant ($key); 
  551.  
  552. # modifier 
  553. if (isset ($modifier) && $modifier) { 
  554. $value = $this->_modifier ($modifier, $value, $vars); 
  555.  
  556. return $value; 
  557.  
  558. protected function _getEncapsuledPattern ($string, $tag_name, $mask) 
  559. $start = $end = 0; 
  560. $string = strstr ($string, $mask); 
  561.  
  562. while (preg_match ("`".self::_OPEN."(/{0, 1}".$tag_name.")(.*?)".self::_CLOSE."`", $string, $preg)) { 
  563. $string = strstr ($string, $preg[0]); 
  564. if ($preg[1] == $tag_name) { 
  565. $start++; 
  566. } else { 
  567. $end++; 
  568. if ($start == $end) { 
  569. break; 
  570. $pos = strlen ($preg[0]); 
  571. $string = substr ($string, $pos, strlen ($string) - $pos); 
  572.  
  573. # make pattern 
  574. $reg = addcslashes($mask, '?.+*()|[]$^').'('; 
  575. for ($j=0; $j<$end; $j++) { 
  576. if ($j < $end-1) { 
  577. $reg .= ".*?".self::_OPEN."/".$tag_name.self::_CLOSE; 
  578. } else { 
  579. $reg .= ".*?)".self::_OPEN."/".$tag_name.self::_CLOSE; 
  580.  
  581. return $reg; 
  582.  
  583. protected function _getProperty ($key, $string) 
  584. if (preg_match ("` ".$key."=\"(.*?)\"`", $string, $properties)) { 
  585. return $properties[1]; 
  586. } else { 
  587. return false; 
  588.  
  589. protected function _loadTemplate ($template) 
  590.  
  591. foreach($this->_template_path as $path) { 
  592. if ($template && file_exists ("$path/$template")) { 
  593. $file = "$path/$template"; 
  594. return $this->_loadFile ($file); 
  595. throw new Exception ("Template '$template' not found !"); 
  596. return false; 
  597.  
  598. protected function _loadFile ($file) 
  599. if ($file && is_file ($file)) { 
  600. $string = file_get_contents ($file); 
  601. return $string; 
  602.  
  603. protected function _modifier ($string, $value, $vars=null) 
  604. if (null == $vars) { 
  605. $vars = $this->_vars; 
  606. $commands = explode ('|', $string); 
  607.  
  608. foreach ($commands as $command) { 
  609. $arguments = array (); 
  610.  
  611. # define list of arguments 
  612. if (strpos ($command, ":")) { 
  613. $strings = array (); 
  614.  
  615. if (strpos ($command, "'")) { 
  616. $i = 0; 
  617. while (preg_match ("`'([^}]*?)'`", $command, $preg)) { 
  618. $strings[] = $preg[1]; 
  619. $command = str_replace ($preg[0], '{'.$i.'}', $command); 
  620.  
  621. $split = explode (':', $command); 
  622. if (count ($split) > 1) { 
  623. $command = $split[0]; 
  624. $count_split = count ($split); 
  625. for ($i=1; $i<$count_split; $i++) { 
  626. if (preg_match ("'".self::_VAR."'", $split[$i], $is_var)) { 
  627. $arguments[] = $this->_getValue ($is_var, $vars); 
  628. } else if (preg_match ("`\{([0-9])\}`", $split[$i], $is_string)) { 
  629. $arguments[] = $strings[$is_string[1]]; 
  630. } else { 
  631. $arguments[] = $split[$i]; 
  632.  
  633.  
  634.  
  635. switch ($command) { 
  636. case 'default': 
  637. if(!$value) { 
  638. $value = $arguments[0]; 
  639. break; 
  640.  
  641. case 'max': 
  642. $value = min($value, $arguments[0]); 
  643. break; 
  644.  
  645. case 'min': 
  646. $value = max($value, $arguments[0]); 
  647. break; 
  648.  
  649. case 'format_text': 
  650. // trim text 
  651. $value = trim($value); 
  652.  
  653. // ignore non utf8 chars 
  654. //$value = iconv('UTF-8', 'UTF-8//IGNORE', $value); 
  655.  
  656. // convert empty titles into line breaks 
  657. $value = str_replace('<h1></h1>', '<br />', $value); 
  658. $value = str_replace('<h2></h2>', '<br />', $value); 
  659. $value = str_replace('<h3></h3>', '<br />', $value); 
  660. // convert empty paragraphs to line breaks 
  661. $value = str_replace('<p></p>', '<br />', $value); 
  662. break; 
  663.  
  664. case 'sanitize': 
  665. // prevent XSS 
  666. $value = preg_replace( '#< *script(?:(?!< */ *script *>).)*< */ *script *>#isU', '', $value ); 
  667. if(strlen($value) > 0) { 
  668. $value = preg_replace("#<([^><]+?)([^a-z_\-]on\w*|xmlns)(\s*=\s*[^><]*)([><]*)#i", "<\\1\\4", $value); 
  669. break; 
  670.  
  671. case 'ratio': 
  672. $image = $value; 
  673. $ratio = 1.0; 
  674. if(isset($image['width']) && isset($image['height'])) { 
  675. if((int)$image['height'] <= 0) { 
  676. $image['height'] = 1; 
  677. $ratio = round(($image['width'] / $image['height']) * 1000) / 1000; 
  678. $value = number_format($ratio, 3, '.', ''); 
  679. break; 
  680. case 'format_line_height': 
  681. $value = $this->_css_format_line_height($value); 
  682. break; 
  683.  
  684. case 'format_font_size_value': 
  685. $value = $this->_css_format_font_size_value($value); 
  686. break; 
  687.  
  688. case 'inc': 
  689. if (!isset ($arguments[0])) { 
  690. $value++; 
  691. } else { 
  692. $value = $value + $arguments[0]; 
  693. break; 
  694.  
  695. case 'mult': 
  696. if ($arguments) { 
  697. $value = (float)$value * (float)$arguments[0]; 
  698. break; 
  699.  
  700. case 'fract': 
  701. if ($arguments) { 
  702. $value = $value / $arguments[0]; 
  703. break; 
  704.  
  705. case 'dec': 
  706. if (!isset ($arguments[0])) { 
  707. $value --; 
  708. } else { 
  709. $value = $value - $arguments[0]; 
  710. break; 
  711.  
  712. case 'round': 
  713. $value = round ($value); 
  714. break; 
  715.  
  716. case 'strlen': 
  717. if ($arguments[0]) { 
  718. $value = strlen ($value, $arguments[0]); 
  719. } else { 
  720. $value = strlen ($value); 
  721. break; 
  722.  
  723. case 'count': 
  724. $value = count ($value); 
  725. break; 
  726.  
  727. case 'cut_string': 
  728. if ($arguments) { 
  729. $value = substr($value, 0, $arguments[0]); 
  730. break; 
  731.  
  732. case 'substr': 
  733. if (count($arguments) == 2) { 
  734. $value = substr($value, $arguments[0], $arguments[1]); 
  735. break; 
  736.  
  737. case 'width': 
  738. if (isset ($arguments[0]) && $arguments[0]) { 
  739. $data_path = $arguments[0]; 
  740. } else { 
  741. $data_path = $this->_data_path; 
  742.  
  743. $value = $data_path.'/'.$value; 
  744. if ($value && file_exists ($value)) { 
  745. $size = @getimagesize ($value); 
  746. $value = $size[0]; 
  747. } else { 
  748. $value = '0'; 
  749. break; 
  750.  
  751. case 'height': 
  752. if (isset ($arguments[0]) && $arguments[0]) { 
  753. $data_path = $arguments[0]; 
  754. } else { 
  755. $data_path = $this->_data_path; 
  756.  
  757. $value = $data_path.'/'.$value; 
  758. if ($value && file_exists ($value)) { 
  759. $size = @getimagesize ($value); 
  760. $value = $size[1]; 
  761. } else { 
  762. $value = '0'; 
  763. break; 
  764.  
  765. case 'colorOrNil': 
  766. if($value === 'transparent') { 
  767. $value = ''; 
  768. break; 
  769.  
  770. case 'includes': 
  771. return (bool)(is_array($value) && in_array($arguments[0], $value)); 
  772. break; 
  773.  
  774. case 'color': 
  775. $value = $this->_css_format_color($value); 
  776. break; 
  777.  
  778. case 'size': 
  779. if (isset ($arguments[0]) && $arguments[0]) { 
  780. $data_path = $arguments[0]; 
  781. } else { 
  782. $data_path = $this->_data_path; 
  783.  
  784. $value = $data_path.'/'.$value; 
  785. if ($value && file_exists ($value)) { 
  786. $value = round (filesize ($value)); 
  787. } else { 
  788. $value = '0'; 
  789. break; 
  790.  
  791. case 'ucfirst': 
  792. $value = ucfirst ($value); 
  793. break; 
  794.  
  795. case 'upper': 
  796. $value = strtoupper($value); 
  797. break; 
  798.  
  799. case 'lower': 
  800. $value = strtolower($value); 
  801. break; 
  802.  
  803. case 'year': 
  804. if (preg_match ("'([0-9]{4})-[0-9]{2}-[0-9]{2}'", $value, $preg)) { 
  805. $preg[1] != '0000' ? $value = $preg[1] : $value = ''; 
  806. if (preg_match ("'^([0-9]{4})[0-9]{4}'", $value, $preg)) { 
  807. $preg[1] != '0000' ? $value = $preg[1] : $value = ''; 
  808. break; 
  809.  
  810. case 'month': 
  811. if (preg_match ("'[0-9]{4}-([0-9]{2})-[0-9]{2}'", $value, $preg)) { 
  812. $preg[1] != '00' ? $value = $preg[1] : $value = ''; 
  813. if (preg_match ("'^[0-9]{4}([0-9]{2})[0-9]{2}'", $value, $preg)) { 
  814. $preg[1] != '00' ? $value = $preg[1] : $value = ''; 
  815. break; 
  816.  
  817. case 'day': 
  818. if (preg_match ("'[0-9]{4}-[0-9]{2}-([0-9]{2})'", $value, $preg)) { 
  819. $preg[1] != '00' ? $value = $preg[1] : $value = ''; 
  820. if (preg_match ("'^[0-9]{6}([0-9]{2})'", $value, $preg)) { 
  821. $preg[1] != '00' ? $value = $preg[1] : $value = ''; 
  822. break; 
  823.  
  824. case 'hour': 
  825. if (preg_match ("'([0-9]{2}):[0-9]{2}:[0-9]{2}'", $value, $preg)) { 
  826. $value = $preg[1]; 
  827. if (preg_match ("'([0-9]{2})[0-9]{4}$'", $value, $preg)) { 
  828. $value = $preg[1]; 
  829. break; 
  830.  
  831. case 'minute': 
  832. if (preg_match ("'[0-9]{2}:([0-9]{2}):[0-9]{2}'", $value, $preg)) { 
  833. $value = $preg[1]; 
  834. if (preg_match ("'[0-9]{2}([0-9]{2})[0-9]{2}$'", $value, $preg)) { 
  835. $value = $preg[1]; 
  836. break; 
  837.  
  838. case 'second': 
  839. if (preg_match("'[0-9]{2}:[0-9]{2}:([0-9]{2})'", $value, $preg)) { 
  840. $value = $preg[1]; 
  841. if (preg_match("'[0-9]{4}([0-9]{2})$'", $value, $preg)) { 
  842. $value = $preg[1]; 
  843. break; 
  844.  
  845. case 'nl2br': 
  846. $value = nl2br($value); 
  847. break; 
  848.  
  849. case 'replace_nl_br': 
  850. $value = str_replace('\n', '<br />', $value); 
  851. break; 
  852.  
  853. case 'delnl': 
  854. $value = str_replace ('\n', '', $value); 
  855. $value = str_replace ('\r', '', $value); 
  856. break; 
  857.  
  858. case 'addslashes': 
  859. $value = addslashes ($value); 
  860. break; 
  861.  
  862. case 'stripslashes': 
  863. $value = stripslashes ($value); 
  864. break; 
  865.  
  866. case 'trim': 
  867. $value = trim ($value); 
  868. break; 
  869.  
  870. case 'nbsp': 
  871. $value = str_replace (' ', ' ', $value); 
  872. break; 
  873.  
  874. case 'strip_tags': 
  875. if ($arguments) { 
  876. $value = strip_tags ($value, $arguments[0]); 
  877. } else { 
  878. $value = strip_tags ($value); 
  879. break; 
  880. case 'htmlentities': 
  881. $result = ''; 
  882. $length = strlen($value); 
  883. for ($i = 0; $i < $length; $i++) { 
  884. $char = $value[$i]; 
  885. $ascii = ord($char); 
  886. if ($ascii < 128) { 
  887. // one-byte character 
  888. $result .= htmlentities($char); 
  889. } else if ($ascii < 192) { 
  890. // non-utf8 character or not a start byte 
  891. } else if ($ascii < 224) { 
  892. // two-byte character 
  893. $result .= htmlentities(substr($value, $i, 2), ENT_QUOTES, 'UTF-8'); 
  894. $i++; 
  895. } else if ($ascii < 240) { 
  896. // three-byte character 
  897. $ascii1 = ord($value[$i+1]); 
  898. $ascii2 = ord($value[$i+2]); 
  899. $unicode = (15 & $ascii) * 4096 + 
  900. (63 & $ascii1) * 64 + 
  901. (63 & $ascii2); 
  902. $result .= "&#$unicode;"; 
  903. $i += 2; 
  904. } else if ($ascii < 248) { 
  905. // four-byte character 
  906. $ascii1 = ord($value[$i+1]); 
  907. $ascii2 = ord($value[$i+2]); 
  908. $ascii3 = ord($value[$i+3]); 
  909. $unicode = (15 & $ascii) * 262144 + 
  910. (63 & $ascii1) * 4096 + 
  911. (63 & $ascii2) * 64 + 
  912. (63 & $ascii3); 
  913. $result .= "&#$unicode;"; 
  914. $i += 3; 
  915. $value = $result; 
  916. break; 
  917.  
  918. case 'index': 
  919. $index = (int)$arguments[0]; 
  920. if(isset($value[$index])) { 
  921. $value = $value[$index]; 
  922. } else { 
  923. $value = ''; 
  924. break; 
  925.  
  926. case 'html_value': 
  927. $value = str_replace('"', '"', $value); 
  928. $value = str_replace("'", ''', $value); 
  929. $value = str_replace('<', '<', $value); 
  930. $value = str_replace('>', '>', $value); 
  931. break; 
  932.  
  933. case 'html_entity_decode': 
  934. $value = html_entity_decode ($value, ENT_QUOTES); 
  935. break; 
  936.  
  937. case 'json_decode': 
  938. $value = json_decode($value); 
  939. break; 
  940.  
  941. case 'json_encode': 
  942. $value = json_encode($value); 
  943. break; 
  944.  
  945. case 'maybe_serialize': 
  946. if(is_array($value) or is_object($value)) { 
  947. // make sure we clean up the useless parser variables 
  948. if(array_key_exists(self::_PAIR, $value)) unset($value[self::_PAIR]); 
  949. if(array_key_exists(self::_FIRST, $value)) unset($value[self::_FIRST]); 
  950. if(array_key_exists(self::_LAST, $value)) unset($value[self::_LAST]); 
  951. // serialize value 
  952. $value = serialize($value); 
  953. break; 
  954.  
  955. case 'base64_decode': 
  956. if($this->is_valid_base64($value) === true) { 
  957. $value = base64_decode($value); 
  958. break; 
  959.  
  960. case 'base64_encode': 
  961. $value = base64_encode($value); 
  962. break; 
  963.  
  964. case 'join': 
  965. if(isset($arguments[0])) { 
  966. $value = join($value, $arguments[0]); 
  967. break; 
  968.  
  969. case 'wordwrap' : 
  970. if ($arguments) { 
  971. $value = wordwrap ($value, $arguments[0]); 
  972. break; 
  973.  
  974. case 'img_size_limit': 
  975. if (isset($arguments[2]) && $arguments[2]) { 
  976. $data_path = $arguments[2]; 
  977. } else { 
  978. $data_path = $this->_data_path; 
  979.  
  980. if (null !== $data_path && $value != '' && file_exists ($data_path.'/'.$value)) { 
  981.  
  982. $size = @getimagesize ($data_path.'/'.$value); 
  983. $new_width = round($size[0]); 
  984. $new_height = round($size[1]); 
  985.  
  986. # constrain width only 
  987. if (isset ($arguments[0]) && (!isset ($arguments[1]) || $arguments[1]=='0') && $size[0] > $arguments[0]) { 
  988. $new_width = $arguments[0]; 
  989. $new_height = round(($new_width * $size[1]) / $size[0]); 
  990.  
  991. # constrain height only 
  992. if (isset ($arguments[0]) && $arguments[0]=='0' && isset ($arguments[1]) && $arguments[1]!='0' && $size[1] > $arguments[1]) { 
  993. $new_height = $arguments[1]; 
  994. $new_width = round(($new_height * $size[0]) / $size[1]); 
  995.  
  996. # constrain both 
  997. if (isset ($arguments[0]) && isset ($arguments[1])) { 
  998. if ($size[0] > $arguments[0] && $arguments[0]!='0') { 
  999. $new_width = $arguments[0]; 
  1000. $new_height = round(($new_width * $size[1]) / $size[0]); 
  1001. if ($new_height > $arguments[1] && $arguments[1]!='0') { 
  1002. $new_height = $arguments[1]; 
  1003. $new_width = round(($new_height * $size[0]) / $size[1]); 
  1004.  
  1005. if (isset ($new_height) && isset ($new_width)) { 
  1006. $value = 'width="'.$new_width.'" height="'.$new_height.'"'; 
  1007. break; 
  1008.  
  1009. case 'highlight': 
  1010. if($arguments[0]) { 
  1011. $value = preg_replace ("{(".$arguments[0].")}si", "<".$arguments[1]." class='".$arguments[2]."'>\\1</".$arguments[1].">", $value); 
  1012. break; 
  1013.  
  1014. case 'password': 
  1015. $value = preg_replace ("'.'", '*', $value); 
  1016. break; 
  1017.  
  1018. case 'get_extension': 
  1019. $value = strtolower (pathinfo ($value, PATHINFO_EXTENSION)); 
  1020. break; 
  1021.  
  1022. case 'utf8_encode': 
  1023. $value = utf8_encode($value); 
  1024. break; 
  1025.  
  1026. case 'url_encode': 
  1027. $value = urlencode ($value); 
  1028. break; 
  1029.  
  1030. case 'url_decode': 
  1031. $value = urldecode($value); 
  1032. break; 
  1033.  
  1034. case 'number_format': 
  1035. if ($arguments) { 
  1036. $value = number_format ($value, $arguments[0], $arguments[1], $arguments[2]); 
  1037. break; 
  1038.  
  1039. case 'int': 
  1040. $value = (int) $value; 
  1041. break; 
  1042.  
  1043. case 'format_date': 
  1044. if ($value && $arguments) { 
  1045. $value = $this->_formatDate ($value, $arguments[0]); 
  1046. break; 
  1047.  
  1048. case 'mime_type': 
  1049. if ($value && file_exists ($this->_data_path.'/'.$value)) { 
  1050. $value = mime_content_type ($this->_data_path.'/'.$value); 
  1051. break; 
  1052.  
  1053. case 'modulo': 
  1054. $value = $value%$arguments['0']; 
  1055. break; 
  1056.  
  1057. case 'trim_br': 
  1058. $value = str_replace(array ("<br>", "<br/>", "<br />"), "\n", $value); 
  1059. $value = nl2br (trim ($value)); 
  1060. break; 
  1061.  
  1062. case 'implode': 
  1063. $value = implode ($arguments[0], $value); 
  1064. break; 
  1065. return $value; 
  1066.  
  1067. // This function checks if the $data passed is a valid base64 string,  
  1068. // BEWARE that it does not ensure that the string is actually base64 encoded 
  1069. function is_valid_base64($data) { 
  1070. // if the string length is not a multiple of 4, it's not a base64 encoded string 
  1071. if(strlen($data) % 4 !== 0) return false; 
  1072.  
  1073. // check the characters contained within the string 
  1074. if(preg_match('%^[a-zA-Z0-9/+]*={0, 2}$%', $data)) { 
  1075. return true; 
  1076. } else { 
  1077. return false; 
  1078.  
  1079. /** misc */ 
  1080. protected function _formatDate ($value, $format) 
  1081. $date = $this->_getDate ($value); 
  1082. return strftime ($format, $date->format('U')); 
  1083.  
  1084. protected function _getDate ($value) 
  1085. setlocale (LC_TIME, "$this->_lc_time.utf8"); 
  1086. return new DateTime ($value); 
  1087.  
  1088. protected static function _css_format_font_size_value($value) { 
  1089. if(strpos($value, 'em') !== FALSE) { 
  1090. // if number value, convert to percent 
  1091. $percentage = ((float)$value * 100); 
  1092. $value = $percentage.'%'; 
  1093. } else if(strpos($value, '%') === FALSE) { 
  1094. $value = $value.'px'; 
  1095. return $value; 
  1096.  
  1097. protected static function _css_format_color($value) { 
  1098. if($value !== 'transparent' && $value !== '') { 
  1099. $value = '#'.$value; 
  1100. return $value; 
  1101.  
  1102. protected static function _css_format_line_height($value) { 
  1103. // if value in px, don't modify 
  1104. if($value !== '0' && strpos($value, 'px') === FALSE && strpos($value, '%') === FALSE) { 
  1105. // if number value, convert to percent 
  1106. $percentage = ((float)$value * 100); 
  1107. $value = $percentage.'%'; 
  1108. return $value;