3 // -------------------------------------------------------------------------- \\
4 // VIS Class that provides template working and HTML visualization \\
5 // -------------------------------------------------------------------------- \\
8 if ( !defined('QF_STARTED') )
9 die('Hacking attempt');
12 if ( defined('QF_KERNEL_VIS_LOADED') )
13 die('Scripting error');
15 define('QF_KERNEL_VIS_LOADED', True);
17 // Cache prefixes for module data
18 define('QF_KERNEL_VIS_VPREFIX', 'VIS.');
19 define('QF_KERNEL_VIS_CPREFIX', 'VIS_CSS.');
20 define('QF_KERNEL_VIS_JPREFIX', 'VIS_JS.');
21 define('QF_KERNEL_VIS_COMMON', 'common');
22 define('QF_KERNEL_VIS_DEFSTYLE', 'qf_def');
25 define('QF_STYLES_DIR', QF_DATA_ROOT.'styles/');
26 //define('QF_STCNTS_DIR', QF_DATA_ROOT.'vis_consts/'); // not used for now - not needed
27 define('QF_JSCRIPTS_DIR', QF_DATA_ROOT.'jscripts/');
28 define('QF_STATICS_DIR', 'static');
29 define('QF_IMAGES_DIR', QF_STATICS_DIR.'/images');
30 define('QF_ST_IMGS_DIR', QF_IMAGES_DIR.'/styles/');
32 // defining some usefull constants
34 define('QF_VIS_NORMAL', 0);
35 define('QF_VIS_STATIC', 1);
36 define('QF_VIS_DINAMIC', 2);
38 define('VIS_BR', "\r\n");
41 define('QF_VISNODE_ARRAY', 1); // node is an array of sametype nodes
46 var $templates = Array();
48 var $VCSS_data = ''; // CSS loaded from visuals
49 var $VJS_data = ''; // JS loaded from visuals
52 var $Consts = Array();
54 var $node_type = Array();
55 var $node_vars = Array();
56 var $node_subs = Array();
57 var $node_flags = Array();
58 var $named_node = Array();
59 var $parsed = Array();
61 var $style_name = QF_KERNEL_VIS_DEFSTYLE;
62 var $style_vari = QF_KERNEL_VIS_COMMON;
64 var $VIS_loaded = Array();
65 var $CSS_loaded = false;
66 var $JS_loaded = Array();
68 var $lang_name = null;
69 var $lang = null; // linking lang vars
70 var $LNG_loaded = null; // linking lang vars
72 var $force_append = true; // forces to append CSS
73 var $force_compact = true; // forces to compact CSS/JS data
74 var $vis_consts = Array();
75 var $func_parsers = Array();
81 if (defined('QF_VASUAL_CREATED'))
82 trigger_error('Duplicate visual manager creation!', E_USER_ERROR);
84 define('QF_VASUAL_CREATED', true);
86 $this->node_type = Array(0 => 'MAIN_PAGE');
87 $this->style_name = QF_KERNEL_VIS_DEFSTYLE;
88 $this->node_vars = Array(0 => Array());
89 $this->node_subs = Array(0 => Array());
90 $this->node_flags = Array(0 => 0);
91 $this->named_node = Array('PAGE' => 0, 'MAIN' => 0);
92 $this->func_parsers = Array(
93 'FULLURL' => 'qf_full_url',
94 'HTMLQUOTE' => 'htmlspecialchars',
95 'URLEN' => 'qf_url_encode_part',
96 'JS_DEF' => 'qf_value_JS_definition',
97 'FTIME' => Array(&$QF->LNG, 'Time_Format'),
98 'FBYTES' => Array(&$QF->LNG, 'Size_Format'),
100 $this->vis_consts = Array(
101 'TIME' => $QF->Timer->time,
109 $data = $QF->LNG->Get_Data_Links();
110 $this->lang =& $data['lang'];
111 $this->lang_name =& $data['lang_name'];
112 $this->LNG_loaded =& $data['LNG_loaded'];
113 $this->Configure(Array(), true);
116 // configuring and loading functions
117 function Configure($params, $force_clear = false)
121 if (is_array($params))
125 if ($force_clear) // clear all settings
127 $this->node_type = Array(0 => 'MAIN_PAGE');
128 $this->style_name = QF_KERNEL_VIS_DEFSTYLE;
129 $this->style_vari = QF_KERNEL_VIS_COMMON;
130 $this->node_vars = Array(0 => Array());
131 $this->node_subs = Array(0 => Array());
132 $this->named_node = Array('PAGE' => 0);
133 $this->named_node = Array('MAIN' => 0);
134 $this->templates = Array();
135 $this->VCSS_data = '';
136 $this->VJS_data = '';
137 $this->VIS_loaded = Array();
138 $this->CSS_data = '';
140 $this->CSS_loaded = false;
141 $this->JS_loaded = Array();
142 $this->force_append = true;
143 $this->force_compact = true;
147 $QF->LNG->Select($lang);
151 $this->style_name = preg_replace('#\W#', '_', $style);
152 if (count($this->VIS_loaded))
154 $parts = $this->VIS_loaded;
155 $this->templates = Array();
156 $this->VCSS_data = '';
157 $this->VJS_data = '';
158 $this->VIS_loaded = Array();
160 foreach ($parts as $part)
161 $this->Load_Templates($part);
165 $this->style_vari = $CSS;
166 elseif($CSS = $this->CSS_loaded)
168 $this->Load_ECSS($CSS);
172 $this->style_vari = $CSS;
174 if (isset($root_node))
175 $this->node_type[0] = $root_node;
177 if (isset($force_append))
178 $this->force_append = (bool) $force_append;
179 if (isset($force_compact))
180 $this->force_compact = (bool) $force_compact;
184 function Set_VConsts($consts, $no_replace = false)
186 if (!is_array($consts))
190 $this->vis_consts = $this->vis_consts + $consts;
192 $this->vis_consts = $consts + $this->vis_consts;
197 function Load_ECSS($variant = '')
202 $variant = $this->style_vari;
204 $variant = strtolower(preg_replace('#\W#', '_', $variant));
206 $cachename = QF_KERNEL_VIS_CPREFIX.$this->style_name.'.'.$this->lang_name.'.'.$variant;
208 if ($Cdata = $QF->Cache->Get($cachename))
210 $this->CSS_data = $Cdata;
211 $QF->Timer->Time_Log($this->style_name.'.'.$variant.' CSS file loaded (from global cache)');
215 $file = $variant.'.ecss';
216 $style = $this->style_name;
217 $cfile = QF_STYLES_DIR.$style.'/'.$file;
218 $commons = QF_STYLES_DIR.$style.'/'.QF_KERNEL_VIS_COMMON.'.ecss';
220 if (!file_exists($cfile))
222 trigger_error('VIS: there is no '.$this->style_name.'.'.$variant.' ECSS file', E_USER_WARNING );
226 if ($indata = qf_file_get_contents($cfile))
229 'IMGS' => qf_full_url(QF_IMAGES_DIR),
230 'ST_IMGS' => qf_full_url(QF_ST_IMGS_DIR.$style),
231 'STATICS' => qf_full_url(QF_STATICS_DIR),
234 if (($cfile != $commons) && strstr($indata, '{COMMON_ECSS}') && ($commons = qf_file_get_contents($commons)))
235 $indata = str_replace('{COMMON_ECSS}', $commons, $indata);
237 $Cdata = $this->Prepare_ECSS($indata, $consts);
239 $QF->Cache->Set($cachename, $Cdata);
240 $this->CSS_data = $Cdata;
241 $QF->Timer->Time_Log($this->style_name.'.'.$variant.' CSS file loaded (from ECSS file)');
245 trigger_error('VIS: error loading '.$this->style_name.'.'.$variant.' ECSS file', E_USER_WARNING );
248 $this->style_vari = $this->CSS_loaded = $variant;
253 function Load_EJS($name = '')
258 $name = QF_KERNEL_VIS_COMMON;
260 $name = strtolower(preg_replace('#\W#', '_', $name));
262 if (!in_array($name, $this->JS_loaded))
264 $cachename = QF_KERNEL_VIS_JPREFIX.$this->lang_name.'.'.$name;
266 if ($JSData = $QF->Cache->Get($cachename))
268 $this->JS_data.= VIS_BR.$JSData;
270 $QF->Timer->Time_Log('"'.$name.'" JScript loaded (from global cache)');
274 if (!in_array($name, $this->LNG_loaded))
275 $QF->LNG->Load_Language($name);
277 $file = $name.'.ejs';
278 $cfile = QF_JSCRIPTS_DIR.$file;
280 if (!file_exists($cfile))
282 trigger_error('VIS: there is no '.$name.' EJS file', E_USER_WARNING );
284 elseif ($indata = qf_file_get_contents($cfile))
286 $style = $this->style_name;
287 $indata = str_replace('{ST_IMGS}', qf_full_url(QF_ST_IMGS_DIR.$style), $indata);
288 $indata = str_replace('{IMGS}', qf_full_url(QF_IMAGES_DIR), $indata);
289 $indata = str_replace('{STATICS}', qf_full_url(QF_STATICS_DIR), $indata);
291 $indata = preg_replace_callback('#\{(?>L_((?:\w+|\"[^\"]+\"|\|)+))\}#',Array(&$this, '_Templ_Lang_CB'),$indata);
292 $indata = preg_replace('#\{(?>CONST:([\w\|]+))\}#e','(isset(\$this->Templ_Consts("$1"))) ? \$this->Templ_Consts("$1") : ""',$indata);
294 $QF->Events->Call_Event_Ref('EJS_PreParse', $indata);
296 $JSData = $this->Prepare_EJS($indata);
297 $this->JS_data.= VIS_BR.$JSData;
299 $QF->Cache->Set($cachename, $JSData );
300 $QF->Timer->Time_Log('"'.$name.'" JScript loaded (from EJS file)');
303 trigger_error('VIS: error loading "'.$name.'" EJS file', E_USER_WARNING );
306 $this->JS_loaded[] = $name;
311 function Load_Templates($part = '', $force_style = false)
316 $part = QF_KERNEL_VIS_COMMON;
318 $part = strtolower(preg_replace('#\W#', '_', $part));
320 if (!in_array($part, $this->VIS_loaded))
322 if (!in_array($part, $this->LNG_loaded))
323 $QF->LNG->Load_Language($part);
325 $cachename = QF_KERNEL_VIS_VPREFIX.$this->style_name.'.'.$this->lang_name.'.'.$part;
327 if (list($Tdata, $VCSS, $VJS) = $QF->Cache->Get($cachename))
329 $this->templates += $Tdata;
330 $this->VCSS_data .= VIS_BR.$VCSS;
331 $this->VJS_data .= VIS_BR.$VJS;
333 // not used for now - not needed
334 //if ($part == QF_KERNEL_VIS_COMMON && $add_Consts = qf_file_load_datafile(QF_STCNTS_DIR.QF_KERNEL_VIS_COMMON.'.cnt', true))
335 // $this->Consts += $add_Consts;
337 $QF->Timer->Time_Log('"'.$part.'" visuals loaded (from global cache)');
341 $file = $part.'.vis';
342 $style = ($force_style)
345 $cfile = QF_STYLES_DIR.$style.'/'.$file;
346 if (!file_exists($cfile))
348 $style = QF_KERNEL_VIS_DEFSTYLE;
349 $cfile = QF_STYLES_DIR.$style.'/'.$file;
352 if (!file_exists($cfile))
354 trigger_error('VIS: there is no '.$this->style_name.'.'.$part.' VIS file', E_USER_WARNING );
356 elseif ($indata = qf_file_get_contents($cfile))
358 // not used for now - not needed
359 //if ($add_Consts = qf_file_load_datafile(QF_STCNTS_DIR.$part.'.cnt', true))
360 // $this->Consts += $add_Consts;
361 $QF->Events->Call_Event_Ref('VIS_RawParse', $indata, $style, $part);
363 $indata = str_replace('{ST_IMGS}', QF_ST_IMGS_DIR.$style, $indata);
364 $indata = str_replace('{IMGS}', QF_IMAGES_DIR, $indata);
365 $indata = str_replace('{STATICS}', qf_full_url(QF_STATICS_DIR), $indata);
367 $indata = preg_replace_callback('#\{(?>L_((?:\w+|\"[^\"]+\"|\|)+))\}#',Array(&$this, '_Templ_Lang_CB'),$indata);
368 $indata = preg_replace('#\{(?>CONST:([\w\|]+))\}#e','(isset(\$this->Templ_Consts("$1"))) ? \$this->Templ_Consts("$1") : ""',$indata);
370 $QF->Events->Call_Event_Ref('VIS_PreParse', $indata, $style, $part);
372 preg_match_all("#<<\+ '(?>(\w+))'>>(.*?)<<- '\\1'>>#s", $indata, $blocks);
374 if (is_array($blocks[1]))
379 foreach ($blocks[1] as $num => $name)
381 $templ = $blocks[2][$num];
384 $VCSS.= $this->Prepare_ECSS($templ);
385 elseif ($name == 'JS')
386 $VJS.= $templ; // EJS can contain {V_ links
387 // so we need to store it first and parse after VIS loading
389 $Tdata[$name] = $this->Prepare_VIS($templ);
392 $this->templates += $Tdata;
393 $this->VCSS_data .= VIS_BR.$VCSS;
394 $VJS = $this->Prepare_EJS($VJS);
395 $this->VJS_data .= VIS_BR.$VJS;
397 $QF->Cache->Set($cachename, Array($Tdata, $VCSS, $VJS) );
398 $QF->Timer->Time_Log('"'.$part.'" visuals loaded (from VIS file)');
401 trigger_error('VIS: error parsing "'.$part.'" VIS file for style "'.$this->style_name.'"', E_USER_WARNING );
405 trigger_error('VIS: error loading "'.$part.'" VIS file for style "'.$this->style_name.'"', E_USER_WARNING );
408 $this->VIS_loaded[] = $part;
415 function Parse($node = 0)
418 $node = $this->Find_Node($node);
423 if (isset($this->parsed[$node]))
424 return $this->parsed[$node];
426 if (!isset($this->node_type[$node]))
428 trigger_error('VIS: trying to parse a fake node', E_USER_WARNING);
432 $type =& $this->node_type[$node];
433 $vars =& $this->node_vars[$node];
434 $subs =& $this->node_subs[$node];
435 $flags =& $this->node_flags[$node];
439 if ($flags && QF_VISNODE_ARRAY)
442 $delimiter = (isset($vars['_DELIM'])) ? $vars['_DELIM'] : '';
443 foreach ($vars as $data)
445 $parts[] = $this->Parse_VIS($type, $data);
446 $text = implode($delimiter, $parts);
450 foreach ($subs as $var => $subnodes)
451 foreach ($subnodes as $subnode)
452 $vars[$var][] = $this->Parse($subnode);
454 foreach ($vars as $var => $vals)
455 $data[$var] = implode(VIS_BR, $vals);
457 $text = $this->Parse_VIS($type, $data);
462 unset($this->node_type[$node],
463 $this->node_vars[$node],
464 $this->node_subs[$node],
465 $this->node_flags[$node]);
467 $this->parsed[$node] =& $text;
475 if ($this->force_append)
477 if (!$this->CSS_loaded)
479 if (!in_array(QF_KERNEL_VIS_COMMON, $this->JS_loaded))
483 if (!count($this->VIS_loaded))
484 $this->Load_Templates();
486 $type =& $this->node_type[0];
487 $vars =& $this->node_vars[0];
488 $subs =& $this->node_subs[0];
491 $vars['CSS'][] = trim($this->CSS_data.VIS_BR.$this->VCSS_data);
492 $vars['JS'][] = trim($this->JS_data.VIS_BR.$this->VJS_data);
494 foreach ($subs as $var => $subnodes)
495 foreach ($subnodes as $subnode)
496 $vars[$var][] = $this->Parse($subnode);
498 foreach ($vars as $var => $vals)
499 $data[$var] = implode(VIS_BR, $vals);
502 $text = $this->Parse_VIS($type, $data);
509 if (!$this->CSS_loaded)
511 return trim($this->CSS_data);
516 if (!$this->JS_loaded)
518 return trim($this->JS_data);
521 // tree construction functions
522 function Create_Node($template, $data_arr = false, $globname = null)
524 $template = (string) $template;
528 end($this->node_type);
529 $id = key($this->node_type) + 1;
530 $this->node_type[$id] = $template;
531 $this->node_vars[$id] = Array();
532 $this->node_subs[$id] = Array();
533 $this->node_flags[$id] = 0;
535 if (is_array($data_arr))
536 foreach ($data_arr as $key => $var)
538 $key = strtoupper($key);
540 $var = implode(' ', $var);
541 $this->node_vars[$id][$key][] = $var;
544 if ($globname && !is_numeric($globname))
546 $globname = strtoupper($globname);
547 $this->named_node[$globname] = $id;
553 function Append_Node($node_id, $varname, $parent = 0)
555 if (!is_int($parent))
556 $parent = $this->Find_Node($parent);
557 if (!is_int($node_id))
558 $node_id = $this->Find_Node($node_id);
560 $varname = strtoupper($varname);
565 if (!isset($this->node_type[$parent]))
567 trigger_error('VIS: trying to append data to fake node', E_USER_WARNING);
570 if (!isset($this->node_type[$node_id]))
572 trigger_error('VIS: trying to append a fake node', E_USER_WARNING);
576 $this->node_subs[$parent][$varname][] = $node_id;
580 function Add_Node($template, $varname, $parent = 0, $data_arr = false, $globname = null)
582 if (!is_int($parent))
583 $parent = $this->Find_Node($parent);
585 $varname = strtoupper($varname);
590 if (!isset($this->node_type[$parent]))
592 trigger_error('VIS: trying to append data to fake node', E_USER_WARNING);
596 if ($id = $this->Create_Node($template, $data_arr, $globname))
598 $this->node_subs[$parent][$varname][] = $id;
606 function Add_Node_Array($template, $varname, $parent = 0, $data_arr = false, $delimiter = false)
608 if (!is_int($parent))
609 $parent = $this->Find_Node($parent);
611 $varname = strtoupper($varname);
616 if (!isset($this->node_type[$parent]))
618 trigger_error('VIS: trying to append data to fake node', E_USER_WARNING);
622 if ($id = $this->Create_Node($template))
624 $this->node_subs[$parent][$varname][] = $id;
625 $this->node_flags[$id] = QF_VISNODE_ARRAY;
627 if (is_array($data_arr) && count($data_arr))
630 foreach ($data_arr as $arr)
633 foreach ($arr as $key => $var)
635 $key = strtoupper($key);
637 $var = implode(' ', $var);
638 $this->node_vars[$id][$in][$key] = $var;
641 $this->node_vars[$id][$in]['_POS'] = $in;
646 $this->node_vars[$id][0]['_IS_FIRST'] = '1';
647 $this->node_vars[$id][$in-1]['_IS_LAST'] = '1';
650 if (strlen($delimiter))
651 $this->node_vars[$id]['_DELIM'] = (string) $delimiter;
658 function Add_Data($node, $varname, $data)
663 $varname = strtoupper($varname);
668 if (!isset($this->node_type[$node]) || ($this->node_flags[$node] && QF_VISNODE_ARRAY))
670 trigger_error('VIS: trying to append data to fake node', E_USER_WARNING);
675 $data = implode(' ', $data);
676 $this->node_vars[$node][$varname][] = $data;
681 function Add_Data_Array($node, $arr)
686 if (!isset($this->node_type[$node]) || ($this->node_flags[$node] && QF_VISNODE_ARRAY))
688 trigger_error('VIS: trying to append data to fake node', E_USER_WARNING);
695 foreach ($arr as $key => $var)
697 $key = strtoupper($key);
699 $var = implode(' ', $var);
700 $this->node_vars[$node][$key][] = $var;
706 function Find_Node($to_find)
711 if (!is_numeric($to_find))
713 $to_find = strtoupper($to_find);
714 if (isset($this->named_node[$to_find]))
715 $to_find = $this->named_node[$to_find];
720 $to_find = (int) $to_find;
725 // Inner parsing functions
727 // reparses {L_...} blocks in raw templates
728 function _Templ_Lang_CB($matches)
731 $code = explode('|', $code);
733 if (!($lng = strtoupper($code[0])))
735 if (!isset($this->lang[$lng]))
738 $data = $this->lang[$lng];
741 $params = array_slice($code, 1);
742 foreach ($params as $id => $val)
743 $params[$id] = ($val{0} == '"') ? substr($val, 1, -1) : '{'.$val.'}';
745 $data = qf_sprintf_arr($data, $params);
751 function Templ_Consts($code)
753 $code = explode('|', $code);
755 if (!($id = strtoupper($code[0])))
757 if (!isset($this->Consts[$id]))
760 $data = $this->Consts[$id];
763 $params = array_slice($code, 1);
764 foreach ($params as $id => $val)
765 $params[$id] = (is_numeric($val{0})) ? (int) $val : '{'.$val.'}';
766 $data = qf_sprintf_arr($data, $params);
772 function Prepare_VIS($text)
776 static $consts = Array(
777 'QF_MARK' => 'Powered by<br />QuickFox 2<br />© Foxel aka LION<br /> 2006 - 2009',
778 'QF_INDEX' => QF_INDEX,
781 $consts['QF_ROOT'] = $QF->HTTP->RootUrl;
784 if ($this->force_compact)
785 $text = $this->VIS_compact($text);
787 $text = preg_replace('#(?<=\})\n\s*?(?=\{\w)#', '', $text);
788 preg_match_all('#\{(\!?)((?>\w+))(?:\:((?:(?>\w+)(?:[\!=\>\<]{1,2}(?:\w+|\"[^\"]*\"))?|\||)*))?\}|[^\{]+|\{#', $text, $struct, PREG_SET_ORDER);
791 $text = $writes_to.' = <<<QFT'.VIS_BR;
798 $keys = array_keys($struct);
800 foreach ($keys as $key)
802 $part =& $struct[$key];
804 if (isset($part[2]) && ($tag = strtoupper($part[2])))
806 $got_a = ($part[1]) ? true : false;
809 if (isset($part[3]) && ($got = preg_match_all('#((?>\w+))(?:([\!=\>\<]{1,2})(\w+|\"[^\"]*\"))?#', $part[3], $params, PREG_PATTERN_ORDER)))
810 for ($i = 0; $i < $got; $i++)
811 $params[1][$i] = strtoupper($params[1][$i]);
815 if (isset($params[1]) && count($params[1]) && ($var = $params[1][0]) && !is_numeric($var{0}))
819 if ($var != $writes_to)
822 $text.= VIS_BR.'QFT;'.VIS_BR.$writes_to.(($got_a) ? '' : '.').'= <<<QFT'.VIS_BR;
825 elseif (isset($this->func_parsers[$tag])) //parsing the variable with func
827 $func_parser = $this->func_parsers[$tag];
829 if (!isset($params[1]) || !count($params[1]))
831 $pars = count($params[1]);
835 for ($i = 0; $i < $pars; $i++)
837 $val = $params[1][$i];
839 if (is_numeric($val{0}))
840 $text.= qf_heredoc_addslashes(qf_func_call($func_parser, intval($val)), 'QFT');
841 elseif ($val{0} == '"')
842 $text.= qf_heredoc_addslashes(qf_func_call($func_parser, substr($val, 1, -1)), 'QFT');
845 $val = strtoupper($val);
846 if (substr($val, 0, 2) == 'L_')
847 $text.= qf_heredoc_addslashes(qf_func_call($func_parser, $this->_Templ_Lang_CB(Array(1 => substr($val, 2)))), 'QFT');
848 elseif (isset($consts[$val]))
849 $text.= qf_heredoc_addslashes(qf_func_call($func_parser, $consts[$val]), 'QFT');
853 $text.= VIS_BR.'QFT'.VIS_BR.'.$this->Do_Func(\''.$tag.'\', $'.$val.').<<<QFT'.VIS_BR;
858 elseif ($tag == 'SET')
860 if ($pars = count($params[1]))
863 for($i = 0; $i < $pars; $i++)
865 $var = $params[1][$i];
866 if (is_numeric($var{0}) || !isset($params[3][$i]) && !strlen($params[3][$i]))
868 $val = $params[3][$i];
869 $sets.= '$'.$var.' = ';
871 if (is_numeric($val{0}))
872 $sets.= intval($val).';';
873 elseif ($val{0} == '"')
874 $sets.= '<<<QFT'.VIS_BR.qf_heredoc_addslashes(substr($val, 1, -1), 'QFT').VIS_BR.'QFT'.VIS_BR.';';
877 $val = strtoupper($val);
878 if (substr($val, 0, 2) == 'L_')
879 $sets.= '<<<QFT'.VIS_BR.qf_heredoc_addslashes($this->_Templ_Lang_CB(Array(1 => substr($val, 2))), 'QFT').VIS_BR.'QFT'.VIS_BR.';';
880 elseif (isset($consts[$val]))
881 $sets.= '<<<QFT'.VIS_BR.qf_heredoc_addslashes($consts[$val], 'QFT').VIS_BR.'QFT'.VIS_BR.';';
885 $sets.= '$'.$val.';';
891 $text.= VIS_BR.'QFT;'.VIS_BR.$sets.VIS_BR.$writes_to.'.= <<<QFT'.VIS_BR;
894 elseif ($tag == 'FOR')
896 if (!isset($params[1]) || !count($params[1]))
898 $params = $params[1];
899 $p1 = array_shift($params);
900 $p2 = array_shift($params);
901 $p3 = array_shift($params);
903 $p1 = (is_numeric($p1{0})) ? intval($p1) : '(int) $'.$p1.($vars[$p1] = '');
905 $p2 = (is_numeric($p2{0})) ? intval($p2) : '(int) $'.$p2.($vars[$p2] = '');
912 $p3 = (is_numeric($p3{0})) ? intval($p3) : '(int) $'.$p3.($vars[$p3] = '');
917 $outiflevel = $iflevel;
919 $text.= VIS_BR.'QFT;'.VIS_BR.'for ($I = '.$p1.'; $I <= '.$p2.'; $I+= '.$p3.') {'.VIS_BR.$writes_to.'.= <<<QFT'.VIS_BR;
921 elseif ($tag == 'ENDFOR')
925 $text.= VIS_BR.'QFT;'.VIS_BR;
927 $text.= str_repeat('} ', $iflevel);
928 $text.= VIS_BR.'}'.VIS_BR.$writes_to.'.= <<<QFT'.VIS_BR;
929 $iflevel = $outiflevel;
932 elseif ($tag == 'VIS')
934 if (!isset($params[1]) || !count($params[1]))
936 $visname = $params[1][0];
937 $text.= VIS_BR.'QFT;'.VIS_BR.$writes_to.(($got_a) ? '' : '.').'= $this->Parse_VIS(\''.$visname.'\'';
938 if (count($params[1]) > 1)
941 $pars = count($params[1]);
942 for($i = 1; $i < $pars; $i++)
944 $var = $params[1][$i];
945 $val = (isset($params[3][$i]) && strlen($params[3][$i])) ? $params[3][$i] : '1';
946 $text.= '\''.$var.'\' => ';
948 if (is_numeric($val{0}))
949 $text.= intval($val).',';
950 elseif ($val{0} == '"')
951 $text.= '<<<QFT'.VIS_BR.qf_heredoc_addslashes(substr($val, 1, -1), 'QFT').VIS_BR.'QFT'.VIS_BR.',';
954 $val = strtoupper($val);
955 if (substr($val, 0, 2) == 'L_')
956 $text.= '<<<QFT'.VIS_BR.qf_heredoc_addslashes($this->_Templ_Lang_CB(Array(1 => substr($val, 2))), 'QFT').VIS_BR.'QFT'.VIS_BR.',';
957 elseif (isset($consts[$val]))
958 $text.= '<<<QFT'.VIS_BR.qf_heredoc_addslashes($consts[$val], 'QFT').VIS_BR.'QFT'.VIS_BR.',';
962 $text.= '$'.$val.',';
968 $text.= ');'.VIS_BR.$writes_to.'.= <<<QFT'.VIS_BR;
970 elseif ($tag == 'IF' || $tag == 'ELSEIF')
972 if (!isset($params[1]) || !count($params[1]))
974 $varname = $params[1][0];
975 $vars[$varname] = '';
976 if (isset($params[3][0]) && strlen($params[3][0]))
978 $condvar = $params[3][0];
979 $condition = $params[2][0];
987 $condition = ' '.$condition.' ';
994 if (is_numeric($condvar{0}))
995 $condition = '((int) $'.$varname.$condition.intval($condvar).')';
996 elseif ($condvar{0} == '"')
998 $condvar = substr($condvar, 1, -1);
999 $condition = '($'.$varname.$condition.'\''.strtr($condvar, Array('\'' => '\\\'', '\\' => '\\\\')).'\')';
1002 $condition = '($'.$varname.$condition.'(string) $'.$condvar.')';
1005 $condition = 'strlen($'.$varname.')';
1008 $condition = '!'.$condition;
1012 $text.= VIS_BR.'QFT;'.VIS_BR.'if ('.$condition.') {'.VIS_BR.$writes_to.'.= <<<QFT'.VIS_BR;
1016 $text.= VIS_BR.'QFT;'.VIS_BR.'} elseif('.$condition.') {'.VIS_BR.$writes_to.'.= <<<QFT'.VIS_BR;
1018 elseif ($tag == 'ELSE')
1021 $text.= VIS_BR.'QFT;'.VIS_BR.'} elseif(true) {'.VIS_BR.$writes_to.'.= <<<QFT'.VIS_BR;
1023 elseif ($tag == 'ENDIF')
1027 $text.= VIS_BR.'QFT;'.VIS_BR.'}'.VIS_BR.$writes_to.'.= <<<QFT'.VIS_BR;
1034 if (isset($consts[$varname]))
1035 $text.= qf_heredoc_addslashes($consts[$varname], 'QFT');
1036 elseif (!is_numeric($varname{0}))
1038 $vars[$varname] = '';
1040 $text.= VIS_BR.'QFT'.VIS_BR.'.qf_smart_htmlschars($'.$varname.').<<<QFT'.VIS_BR;
1042 $text.= '{$'.$varname.'}';
1048 $text.= qf_heredoc_addslashes($part[0], 'QFT');
1051 unset($struct[$key]);
1054 $text.= VIS_BR.'QFT;'.VIS_BR;
1056 $text.= str_repeat('} ', $iflevel);
1058 $text.= str_repeat('} ', $outiflevel+1);
1060 $text = preg_replace('#\$\w+\.\=\s*\<\<\<QFT\s+QFT;#', '', $text);
1061 return Array('T' => $text, 'V' => $vars);
1064 function ____PreReplace_VISes($VISes) //RAW VISes including... TODO
1066 foreach ($VISes as $id => $text)
1068 preg_match_all('#\{\!?VIS(?:\:((?:(?>\w+)(?:[\!=\>\<]{1,2}(?:\w+|\"[^\"]*\"))?|\||)*))?\}|[^\{]+|\{#', $text, $struct, PREG_SET_ORDER);
1071 $keys = array_keys($struct);
1073 foreach ($keys as $key)
1075 $part =& $struct[$key];
1077 if (isset($part[2]) && ($tag = strtoupper($part[2])))
1079 $got_a = ($part[1]) ? true : false;
1081 if (isset($part[3]) && ($got = preg_match_all('#((?>\w+))(?:([\!=\>\<]{1,2})(\w+|\"[^\"]*\"))?#', $part[3], $params, PREG_PATTERN_ORDER)))
1082 for ($i = 0; $i < $got; $i++)
1083 $params[1][$i] = strtoupper($params[1][$i]);
1089 function Do_Func($func_name, $data) //parsing data with funcParser
1091 if (!isset($this->func_parsers[$func_name]))
1094 $func_parser = $this->func_parsers[$func_name];
1095 return qf_func_call($func_parser, $data);
1098 function Parse_VIS($vis, $data = Array())
1100 Static $__COUNTER=1;
1105 $QF_SID = $QF->Session->SID;
1109 $COUNTER = $__COUNTER++;
1110 $RANDOM = dechex(rand(0x1FFF, getrandmax()));
1112 if (!isset($this->templates[$vis]))
1113 return implode(VIS_BR, $data);
1115 if (extract($this->templates[$vis]['V'], EXTR_SKIP))
1117 extract($data, EXTR_OVERWRITE | EXTR_PREFIX_ALL, 'IN');
1118 extract($this->vis_consts, EXTR_OVERWRITE | EXTR_PREFIX_ALL, 'C');
1123 if (eval($this->templates[$vis]['T']) === false)
1124 trigger_error('VIS: error running "'.$vis.'" template. CODE ['.$this->templates[$vis]['T'].']', E_USER_ERROR);
1129 function Prepare_ECSS($indata, $constants = null)
1131 if (is_array($constants))
1132 foreach ($constants as $name=>$val)
1133 $indata = str_replace('{'.$name.'}', $val, $indata);
1135 $vars_mask='#\{((?>[\w\-]+))\}\s*=(.*)#';
1136 $vars_block='#\{VARS\}(.*?)\{/VARS\}#si';
1138 preg_match_all($vars_block, $indata, $blocks);
1139 $blocks = implode(' ', $blocks[0]);
1141 preg_match_all($vars_mask, $blocks, $sets);
1142 if (is_array($sets[1]))
1143 foreach ($sets[1] as $num => $name)
1144 $CSSVars[strtoupper($name)] = trim($sets[2][$num]);
1146 $Cdata = preg_replace($vars_block, '', $indata);
1148 if ($this->force_compact)
1149 $Cdata = $this->CSS_compact($Cdata);
1151 $Cdata = preg_replace('#\{(?>(\w+))\}#e', '(isset(\$CSSVars[strtoupper("\1")])) ? \$CSSVars[strtoupper("\1")] : ""', $Cdata);
1156 function Prepare_EJS($Jdata, $constants = null)
1158 if (is_array($constants))
1159 foreach ($constants as $name=>$val)
1160 $Jdata = str_replace('{'.$name.'}', $val, $Jdata);
1161 if ($this->force_compact)
1162 $Jdata = $this->EJS_compact($Jdata);
1166 function EJS_compact($indata)
1168 $indata = str_replace("\r", '', $indata);
1169 $indata = preg_replace('#^//.*?$#m', '', $indata);
1170 $indata = preg_replace('#(?<=\s)//.*?$#m', '', $indata);
1171 $indata = preg_replace('#(\n\s*)+#', "\n", $indata);
1172 $indata = preg_replace('#\n(.{1,5})$#m', ' \\1', $indata);
1173 $indata = str_replace("\n", VIS_BR, $indata);
1174 $indata = trim($indata);
1178 function CSS_compact($indata)
1180 $indata = str_replace("\r", '', $indata);
1181 $indata = preg_replace('#/\*.+\*/#sU', '', $indata);
1182 $indata = preg_replace('#(\n\s*)+#', "\n", $indata);
1183 $indata = preg_replace('#\n(.{1,5})$#m', ' \\1', $indata);
1184 $indata = preg_replace('#\s*(,|:|;|\{)\s+#', '\\1 ', $indata);
1185 $indata = preg_replace('#\s+\}\s+#', " }\n", $indata);
1186 $indata = str_replace("\n", VIS_BR, $indata);
1187 $indata = trim($indata);
1191 function VIS_compact($indata)
1193 $indata = str_replace("\r", '', $indata);
1194 $indata = preg_replace('#(\n\s*)+#', "\n", $indata);
1195 $indata = preg_replace('#\n(.{1,5})$#m', ' \\1', $indata);
1196 $indata = preg_replace('#\x20+#', ' ', $indata);
1197 $indata = str_replace("\n", VIS_BR, $indata);
1198 $indata = trim($indata);