3 // -------------------------------------------------------------------------- \\
4 // This is the main QuickFox 2 file \\
5 // (c) LION 2007 - 2008 \\
6 // -------------------------------------------------------------------------- \\
9 if ( !defined('QF_STARTED') )
10 die('Hacking attempt');
12 if (defined('QF_FOX_STARTED'))
13 die('Scripting error');
15 define('QF_FOX_STARTED', true);
17 define('QUICKFOX_DIR', dirname(__FILE__).'/');
19 // data directories constants
20 define('QF_INC_ROOT', QF_DATA_ROOT.'includes/');
21 define('QF_MODULES_DIR', QF_DATA_ROOT.'modules/');
22 define('QF_PAGES_DIR', QF_INC_ROOT.'pages/');
23 define('QF_SCRIPTS_DIR', QF_INC_ROOT.'scripts/');
25 // Defining some usefull constants
26 define('QF_FOX2_LOGIN_MASK', '^[0-9\w_\+\-=\(\)\[\] ]{3,16}$');
27 define('QF_FOX2_SERVICE_PERIOD', 60); // 1 minute service check period
28 define('QF_FOX2_RESULT_LIFETIME', 3600);
29 define('QF_FOX2_MAXULEVEL', 7);
31 define('QF_FOX2_URLTEMPS_CACHENAME', 'FOX2.URLTEMPS');
32 define('QF_FOX2_URLTEMPS_RW_CACHENAME', 'FOX2.RW_URLTEMPS');
37 var $URL_domain = null;
38 var $VIS_redefs = Array();
39 var $err_traced = Array();
44 if ($CL_Config = qf_file_get_carray(QUICKFOX_DIR.'modules.qfc'))
46 foreach ($CL_Config as $mod => $cfg)
48 $cfg = explode('|', $cfg);
49 if (isset($cfg[1]) && $cfg[1])
50 $QF->Register_Module($mod, QUICKFOX_DIR.trim($cfg[1]), trim($cfg[0]));
52 $QF->Register_Module($mod, QUICKFOX_DIR.trim($cfg[0]));
61 $GLOBALS['FOX'] =& $this;
63 //qf_file_put_contents('acc'.$QF->Timer->time, qf_array_definition($_REQUEST));
65 $QF->Timer->Time_Log('FOX2 module started');
67 if ($QF->GPC->Get_Bin('drop_cache', QF_GPC_GET))
70 $QF->LNG->Load_Language('common');
71 //$QF->Config->Set('linked_domains', Array('gallery' => 'www.quickfox.dev'), 'fox2');
72 //$QF->Config->Set('basic_domain', 'quickfox.dev', 'fox2');
74 // starting neded modules
75 $QF->Run_Module('DSets');
76 $QF->Run_Module('User');
78 $revision = $QF->DSets->Get_DSet_Value('dev_rev_info', 'qf2');
79 header('X-Powered-By: QuickFox 2 ['.$revision.'] (PHP/'.PHP_VERSION.')');
82 $rw_id = $QF->GPC->Get_String('rw_id', QF_GPC_GET, QF_STR_WORD);
83 $rw_data = $QF->GPC->Get_String('rw_data', QF_GPC_GET, QF_STR_LINE);
84 // working with multidomain
85 if ($QF->Config->Get('tgl_multidomain', 'fox2'))
87 $d_schemas = $QF->Config->Get('domain_schemas', 'fox2');
88 $domain = strtolower($QF->HTTP->SrvName);
89 if (!is_array($d_schemas))
92 if (!isset($d_schemas[$domain]))
94 $d_schemas[$domain] = '';
95 $QF->Config->Set('domain_schemas', $d_schemas, 'fox2', true);
97 elseif ($d_schemas[$domain])
98 $QF->Config->Select_Scheme($d_schemas[$domain]);
100 if (($domains = $QF->Config->Get('linked_domains', 'fox2'))
101 && ($basic_domain = $QF->Config->Get('basic_domain', 'fox2'))
102 && is_array($domains) && count($domains))
104 list($link) = array_keys($domains, $domain);
107 $this->URL_domain = $basic_domain;
108 if ($rw_id && $rw_id != $link)
109 $rw_data = $rw_id.'/'.$rw_data;
114 // rewrited url reparsing
117 $this->_Parse_RW($rw_id, $rw_data);
118 $QF->Events->Set_On_Event('HTTP_HTML_parse', Array(&$this, 'HTML_FullURLs') );
119 $QF->Events->Set_On_Event('HTML_block_parse', Array(&$this, 'HTML_FullURLs') );
122 // running the services
123 $next_start = $QF->Config->Get('service_nextstart', 'temp');
124 if ($next_start < $QF->Timer->time)
126 $QF->Run_Module('Services');
127 $QF->Config->Set('service_nextstart', ($QF->Timer->time + QF_FOX2_RESULT_LIFETIME), 'temp', true);
130 // registering extended modules
131 if ($r_mods = $QF->DSets->Get_DSet('fox_modules'))
132 foreach ($r_mods as $r_mod => $r_cfg)
134 $r_cfg = explode('|', $r_cfg);
135 if (isset($r_cfg[1]) && $r_cfg[1])
136 $QF->Register_Module($r_mod, QF_MODULES_DIR.trim($r_cfg[1]), trim($r_cfg[0]));
138 $QF->Register_Module($r_mod, QF_MODULES_DIR.trim($r_cfg[0]));
141 //$this->_Parse_PathInfo();
143 if ($domain = $QF->Config->Get('cookie_domain'))
144 $QF->HTTP->Set_Cookie_Domain($domain);
146 $QF->Events->Set_On_Event('VIS_PreParse', Array(&$this, 'On_VIS_Prep') );
147 $QF->Events->Set_On_Event('EJS_PreParse', Array(&$this, 'On_EJS_Prep') );
148 if ($QF->Config->Get('vis_redefined', 'fox2'))
149 $QF->Events->Set_On_Event('VIS_RawParse', Array(&$this, '_VISUserMods_Add') );
151 // running any autoruns from packages
152 if ($ar_datas = $QF->DSets->Get_DSet('fox_autoruns'))
153 foreach ($ar_datas as $arun)
154 if (isset($arun['module'], $arun['method']))
156 $QF->Run_Module($arun['module']);
157 qf_func_call(Array(&$QF->$arun['module'], $arun['method']));
161 // first try to determine if we are running a datapage
162 if ($data_page = $QF->GPC->Get_String('sr', QF_GPC_GET, QF_STR_WORD))
163 $this->Run_Data($data_page);
166 $QF->Session->Open_Session();
167 if ($QF->Config->Get('sid_urls', 'session', true) && $QF->Config->Get('cookie_check', 'session') && $QF->Session->Get_Status(QF_SESSION_USEURL | QF_SESSION_LOADED) == QF_SESSION_USEURL)
168 $QF->HTTP->Redirect($QF->HTTP->Request);
170 // then try to determine if we are running an AJAX parser
171 if ($aj_page = $QF->GPC->Get_String('aj', QF_GPC_GET, QF_STR_WORD))
172 $QF->User->is_spider || $this->Run_AJAX($aj_page);
174 // then try to run script if needed
175 if ($script = $QF->GPC->Get_String('script', QF_GPC_POST, QF_STR_WORD))
176 $QF->User->is_spider || $this->Run_Script($script);
178 // if we don't need to run scripts or datapages we will draw a normal page
179 $QF->Run_Module('VIS');
180 $vis_style = $QF->Config->Get('vis_style', '', 'qf_def');
181 $vis_style = explode('|', $vis_style);
182 if (!isset($vis_style[1]))
183 $vis_style[1] = QF_KERNEL_VIS_COMMON;
184 $QF->VIS->Configure(Array(
185 'root_node' => 'GLOBAL_HTMLPAGE',
186 'style' => $vis_style[0],
187 'CSS' => $vis_style[1],
191 if ($QF->Config->Get('css_separate'))
193 $QF->VIS->Configure(Array('force_append' => false));
194 $QF->VIS->Add_Data(0, 'META', '<link rel="stylesheet" type="text/css" href="'.$this->Gen_URL('fox2_css_data', $vis_style, true).'" />');
196 $this->Link_JScript('common');
197 $this->Link_JScript('effects');
199 $QF->VIS->Set_VConsts(Array('MAXULEVEL' => QF_FOX2_MAXULEVEL));
200 $QF->VIS->Load_Templates();
202 $page = $QF->GPC->Get_String('st', QF_GPC_GET, QF_STR_WORD);
205 $page = $QF->Config->Get('index_dpage', 'fox2', 'pages');
207 $this->Show_Page($page);
210 function Run_Data($name)
214 if (connection_aborted())
215 trigger_error('FOX: connection was aborted at client side', E_USER_WARNING);
216 if (($data = $QF->DSets->Get_DSet_Value('fox_datapages', $name)) && isset($data['module'], $data['method']))
218 $QF->Run_Module($data['module']);
219 qf_func_call(Array(&$QF->$data['module'], $data['method']));
220 trigger_error('FOX: datapage "'.$name.'" did not end execution by it\'s own', E_USER_NOTICE);
223 trigger_error('FOX: there is no "'.$name.'" datapage data', E_USER_WARNING);
225 header ($QF->HTTP->SERVER["SERVER_PROTOCOL"].' 501 Not Implemented');
226 $QF->HTTP->Redirect(($QF->HTTP->Referer && !$QF->HTTP->ExtRef) ? $QF->HTTP->Referer : QF_INDEX);
229 function Run_AJAX($name)
236 if (connection_aborted())
237 trigger_error('FOX: connection was aborted at client side', E_USER_WARNING);
238 elseif ($name == 'PING') // session pinger works
242 elseif (($data = $QF->DSets->Get_DSet_Value('fox_ajax_scripts', $name)) && isset($data['module'], $data['method']))
244 $QF->Run_Module($data['module']);
245 $AJAX_DATA = qf_func_call_ref(Array(&$QF->$data['module'], $data['method']), $AJAX_STATUS);
249 trigger_error('FOX: there is no "'.$name.'" AJAX parser file', E_USER_WARNING);
251 $AJAX_DATA = 'Parser Not Found';
254 $AJAX_DATA = '{ status: '.intval($AJAX_STATUS).', data: '.qf_value_JS_definition($AJAX_DATA).' }';
255 if ($QF->GPC->Get_String('AJMethod', QF_GPC_GET, QF_STR_WORD) == 'form')
257 $AJAX_ID = $QF->GPC->Get_String('AJID', QF_GPC_GET, QF_STR_WORD);
258 $AJAX_DATA = 'top && top.QF_AJAX && top.QF_AJAX.Form_Ready(\''.$AJAX_ID.'\', '.$AJAX_DATA.' );';
259 $AJAX_DATA = '<?xml version="1.0"?>
260 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
261 <html xmlns="http://www.w3.org/1999/xhtml">
262 <head><!--Meta-Content-Type--></head><body><script type="text/javascript">
263 // JavaScript Starts Here <![CDATA[
265 //]]> JavaScript ends here
266 </script></body></html>';
269 $QF->HTTP->do_HTML = false;
272 $QF->HTTP->Write($AJAX_DATA);
273 $QF->HTTP->Send_Buffer($QF->Session->Get('recode_out'));
276 function Run_Script($name)
280 if (connection_aborted())
281 trigger_error('FOX: connection was aborted at client side', E_USER_WARNING);
282 elseif ($data = $QF->DSets->Get_DSet_Value('fox_scripts', $name))
284 Ignore_User_Abort(True);
288 if (isset($data['module'], $data['method']))
290 $QF->Run_Module($data['module']);
291 $result = qf_func_call(Array(&$QF->$data['module'], $data['method']));
294 trigger_error('FOX: script "'.$file.'" did not set result by it\'s own', E_USER_NOTICE);
295 $result = Array(Lang('SCR_FINISHED_NORES'));
297 elseif (!is_array($result))
298 $result = Array($result);
300 elseif (isset($data['include']) && ($file = QF_SCRIPTS_DIR.$data['include'].'.php') && file_exists($file))
303 trigger_error('FOX: script-include "'.$file.'" did not end execution by it\'s own', E_USER_NOTICE);
304 $result = Array(Lang('SCR_FINISHED_NORES'));
308 $result = Array(Lang('ERR_SCR_CODE_NOTFOUND'), '', true);
309 trigger_error('FOX: there is no "'.$name.'" script data', E_USER_WARNING);
312 call_user_func_array(Array(&$this, 'Set_Result'), $result);
315 trigger_error('FOX: there is no "'.$name.'" script data', E_USER_WARNING);
318 function Show_Page($pg)
322 // running prepage autoruns from packages
323 if ($ar_datas = $QF->DSets->Get_DSet('fox_prepages'))
324 foreach ($ar_datas as $arun)
325 if (isset($arun['module'], $arun['method']))
327 $QF->Run_Module($arun['module']);
328 qf_func_call(Array(&$QF->$arun['module'], $arun['method']), $pg);
331 $QF->VIS->Add_Data_Array(0, Array(
332 'SITE_NAME' => ($site_name = $QF->Config->Get('site_name')) ? htmlspecialchars($site_name) : 'QuickFox 2',
334 if ($adv = $QF->Config->Get('adv_data', 'visual'))
335 $QF->VIS->Add_Data(0, 'ADV', $adv);
338 if ((list($data, $pkg) = $QF->DSets->Get_DSet_Value('fox_pages', $pg, true)) && isset($data['module'], $data['method']))
340 // redirecting on multidomain redirection enabled
341 if ($QF->Config->Get('tgl_multidomain', 'fox2') && $QF->Config->Get('tgl_mdomain_redir', 'fox2') && ($domains = $QF->Config->Get('package_domains', 'fox2')) && is_array($domains) && count($domains))
343 if (isset($domains[$pkg]))
345 $domain = $domains[$pkg];
346 $domain = preg_replace('#^http\:(?:/)*|/$#i', '', $domain);
347 if ($domain != $QF->HTTP->SrvName)
349 $url = qf_full_url($QF->HTTP->Request, false, $domain);
350 $QF->HTTP->Redirect($url);
355 $QF->Run_Module($data['module']);
356 $p_subtitle = $p_title = '';
359 $pg_node = qf_func_call_arr(Array(&$QF->$data['module'], $data['method']), Array(&$p_title, &$p_subtitle, &$d_result, &$d_status));
361 $QF->VIS->Append_Node($pg_node, 'PAGE_CONT', 0);
363 $QF->VIS->Add_Data(0, 'PAGE_TITLE', $p_title);
365 $QF->VIS->Add_Data(0, 'PAGE_SUBTITLE', $p_subtitle);
366 if ($d_status != 200)
367 $QF->HTTP->Set_Status($d_status);
368 if ($d_result && is_array($d_result))
369 call_user_method_array('Draw_Result', $this, $d_result);
371 elseif (($file = QF_PAGES_DIR.$pg.'_inc.php') && file_exists($file))
375 $this->Draw_Result(Lang('ERR_INCLUDE_LOAD'), ($QF->HTTP->Referer && !$QF->HTTP->ExtRef) ? $QF->HTTP->Referer : QF_INDEX, true);
376 $QF->HTTP->Set_Status(404);
381 if ($QF->User->UID || ($QF->Config->Get('show_login_pan') && !$QF->User->is_spider))
382 $this->Draw_Panel('login');
385 if ($recode = $QF->GPC->Get_String('recode', QF_GPC_GET, QF_STR_WORD))
386 $QF->Session->Set('recode_out', $recode);
387 elseif ($recode !== null)
388 $QF->Session->Drop('recode_out');
390 // running postpage autoruns from packages
391 if ($ar_datas = $QF->DSets->Get_DSet('fox_postpages'))
392 foreach ($ar_datas as $arun)
393 if (isset($arun['module'], $arun['method']))
395 $QF->Run_Module($arun['module']);
396 qf_func_call(Array(&$QF->$arun['module'], $arun['method']), $pg, $pg_node);
400 $QF->HTTP->Write($QF->VIS->Make_HTML());
401 $QF->HTTP->Send_Buffer($QF->Session->Get('recode_out'));
407 $menubts = $QF->Config->Get('menu_buttons', 'visual');
409 if (is_array($menubts))
410 foreach ($menubts as $butt)
411 if (is_array($butt) && qf_str_is_url($butt['url']))
413 $butt['url'] = qf_full_url($butt['url'], true, $this->URL_domain);
414 if (isset($butt['is_sub']) && $butt['is_sub'] && $cur_butt)
415 $QF->VIS->Add_Node('MENU_SUBBUTTON', 'SUBS', $cur_butt, $butt);
417 $cur_butt = $QF->VIS->Add_Node('MENU_BUTTON', 'MENU_ITEMS', 0, $butt);
421 function Draw_Panel($name)
426 if (($data = $QF->DSets->Get_DSet_Value('fox_panels', $name)) && isset($data['module'], $data['method']))
428 $CUR_PANEL = $QF->VIS->Add_Node('PANEL_BODY', 'PANELS', 0, false, $name.'_panel');
429 $QF->Run_Module($data['module']);
430 qf_func_call(Array(&$QF->$data['module'], $data['method']), $CUR_PANEL);
438 function Gen_ASCode()
442 $new_code = qf_short_uid();
444 if ($QF->Session->Set('QFox2_ASCode', $new_code))
450 function Check_ASCode($code)
454 $real_code = $QF->Session->Get('QFox2_ASCode');
456 return ($code == $real_code);
460 function Set_Result($text, $redir_to = '', $is_err = false, $code = '')
464 $res_id = qf_short_uid('res');
466 $QF->DBase->Do_Delete('results', 'WHERE time < '.($QF->Timer->time - QF_FOX2_RESULT_LIFETIME));
467 if (!$QF->Session->SID)
468 $QF->Session->Open_Session();
472 'text' => (string) $text,
473 'is_err' => ($is_err) ? 1 : 0,
474 'tr_errs' => ($is_err) ? implode('|', qf_array_parse($this->err_traced, 'dechex')) : '',
475 'time' => $QF->Timer->time,
476 'got_at' => $QF->HTTP->Request,
477 'redir_to' => $redir_to,
478 'u_sid' => $QF->Session->SID,
479 'u_id' => $QF->User->UID,
482 if ($QF->DBase->Do_Insert('results', $ins_data))
483 $QF->HTTP->Redirect($this->Gen_URL('fox2_showresult_page', Array($res_id)));
486 trigger_error('FOX: error setting result data', E_USER_WARNING);
487 // if user must be regirected we'll try do this without setting result data
489 $QF->HTTP->Redirect($redir_to);
494 function Trace_Error($err_code)
497 $this->err_traced[] = (int) $err_code;
498 if ($QF->Config->Get('log_errors', 'loggers', 1))
499 $this->Log_Event($err_code, 'err_log');
502 function Link_JScript($name)
505 static $separate = null;
506 static $linked = Array();
508 if (!isset($QF->VIS))
511 if (is_null($separate))
512 $separate = (bool) $QF->Config->Get('css_separate');
514 if (in_array($name, $linked))
520 return $QF->VIS->Add_Data(0, 'JS_BLOCKS', '<script type="text/javascript" src="'.$this->Gen_URL('fox2_js_data', $name, true).'" ></script>');
522 return $QF->VIS->Load_EJS($name);
525 function Describe_ErrCodes($descr_errs = false)
529 $descr_errs = $this->err_traced;
531 if (is_array($descr_errs) && count($descr_errs))
535 foreach ($descr_errs as $err_code)
537 $err_code = '0x'.dechex($err_code);
539 list ($info, $pkg) = $QF->DSets->Get_DSet_Value('err_messages', $err_code, true);
543 if (isset($info['sys']) && $info['sys'])
546 if (!in_array($pkg, $packs))
548 array_push($packs, $pkg);
549 $QF->LNG->Load_Language($pkg.'_errs');
553 $message = $info['mess'];
554 if (substr($message, 0, 2) == 'L_')
555 $message = $QF->LNG->Lang(substr($message, 2));
557 $output[$err_code] = $message;
565 function Draw_Result($text, $redir_to = '', $is_err = false, $descr_errs = false)
573 $url = qf_full_url($redir_to, false, $this->URL_domain);
574 $QF->Events->Call_Event_Ref('HTTP_URL_Parse', $url );
575 $hurl = strtr($url, Array('&' => '&'));
577 header('Refresh: 7; URL="'.$url.'"');
579 $res_node = $QF->VIS->Add_Node('FOX_RESULT_WINDOW', 'PAGE_CONT', 0, Array(
581 'is_err' => ($is_err) ? 1 : null,
582 'redir_url' => $hurl,
584 $QF->VIS->Add_Data(0, 'PAGE_TITLE', ($is_err) ? Lang('RES_CAPT_ERR') : Lang('RES_CAPT'));
586 if ($descr_errs = $this->Describe_ErrCodes($descr_errs))
588 $err_nodes = Array();
589 foreach($descr_errs as $code => $mess)
590 $err_nodes[] = Array('ERRCODE' => $code, 'MESSAGE' => $mess);
592 if (count($err_nodes))
593 $QF->VIS->Add_Node_Array('FOX_RESULT_ERR_ITEM', 'ERRORS', $res_node, $err_nodes);
597 function Gen_Pages($pages, $cur_page, $params = false)
599 if (!is_array($params))
605 $cur_page = max(1, min($cur_page, $pages));
607 $draw_pages = Array();
609 for($stt = 1; $stt <= $pages; $stt++)
611 if ($stt <= 4 || $stt >= ($pages - 3) || Abs($stt - $cur_page) < 3) {
612 $draw_pages[] = $params + Array('PAGE' => $stt, 'CUR' => ($stt == $cur_page) ? true : null);
617 $draw_pages[] = Array('SEPAR' => true);
625 function Log_Event($event, $log_name = 'common')
628 $log_name = substr(preg_replace('#\W#', '_', $log_name), 0, 32);
630 'log_id' => $log_name,
631 'time' => $QF->Timer->time,
633 'cl_ip' => $QF->HTTP->IP_int,
634 'cl_req' => $QF->HTTP->Request,
635 'cl_uagent' => $QF->HTTP->UAgent,
637 return $QF->DBase->Do_Insert('fox_logs', $ins_data);
640 function Gen_URL($url_id, $params = Array(), $with_amps = false, $no_enc = false)
646 '{QF_SID}' => $QF->Session->SID,
647 '{TIME}' => $QF->Timer->time,
650 if (!is_array($params))
651 $params = Array($params);
655 $url_id = strtoupper($url_id);
657 if (!is_array($this->URL_temps))
660 if (isset($this->URL_temps[$url_id]))
663 $params = qf_array_parse($params, 'qf_url_encode_part');
665 $string = strtr($this->URL_temps[$url_id], $vars);
667 $a_params = $r_params = Array();
669 $count = preg_match_all('#\%(\d+)\$|\%\w#', $string, $masks, PREG_PATTERN_ORDER);
673 $count = max($count, max($masks));
674 $r_params = explode('|', str_repeat('|', $count));
677 foreach($params as $key => $param)
680 $r_params[$key] = $param;
682 $a_params[] = qf_url_encode_part($key).'='.$param;
684 $string = qf_sprintf_arr($string, $r_params);
685 if (count($a_params))
686 $string.= ((strstr($string, '?')) ? '&' : '?').implode('&', $a_params);
688 $string = ($with_amps) ? preg_replace('#\&(?![A-z]+;)#', '&', $string) : str_replace('&', '&', $string);
695 function On_VIS_Prep(&$indata, $type = false)
697 if (!is_array($this->URL_temps))
700 $indata = preg_replace_callback('#\{(?>(F|R)?URL:((?:\w+|\"[^\"]+\"|\|)+))\}#',Array(&$this, '_VISParse_URL_CB'),$indata);
703 function On_EJS_Prep(&$indata, $type = false)
705 if (!is_array($this->URL_temps))
708 $indata = preg_replace_callback('#\{(?>(F|R)?URL:((?:\w+|\"[^\"]+\"|\|)+))\}#',Array(&$this, '_VISParse_URL_CB'),$indata);
711 function _VISUserMods_Add(&$indata, $style, $part)
715 if (!isset($this->VIS_redefs[$style]) && !$this->_VISUserMods_Preload($style))
718 if (isset($this->VIS_redefs[$style]) && isset($this->VIS_redefs[$style][$part]))
719 $indata.= $this->VIS_redefs[$style][$part];
722 /*function _VISUserMods_Preload()
725 $QF->VIS->Load_Templates('user_redefined');
728 function _VISUserMods_Preload($style)
731 if (!$QF->Check_Module('VIS'))
734 $style = strtolower($style);
735 if (isset($this->VIS_redefs[$style]))
738 $cachename = QF_KERNEL_VIS_VPREFIX.$style.'_redefs';
739 $cfile = QF_STYLES_DIR.$style.'/redefined.vis';
740 if ($data = $QF->Cache->Get($cachename))
741 $this->VIS_redefs[$style] = $data;
742 elseif ($data = qf_file_get_contents($cfile))
744 preg_match_all('#\<\<part \'(\w+)\'\>\>|[^\<]+|\<#', $data, $struct, PREG_SET_ORDER);
746 $p_name = QF_KERNEL_VIS_COMMON;
747 foreach ($struct as $part)
750 $p_name = strtolower($part[1]);
751 elseif (isset($data[$p_name]))
752 $data[$p_name].= $part[0];
754 $data[$p_name] = $part[0];
756 $QF->Cache->Set($cachename, $data);
757 $this->VIS_redefs[$style] = $data;
764 function _VISParse_URL_CB($matches)
767 $code = explode('|', $code);
769 if (!($url_id = strtoupper($code[0])))
771 if (!isset($this->URL_temps[$url_id]))
774 if ($params = array_slice($code, 1))
776 foreach ($params as $id => $val)
777 $params[$id] = (is_numeric($val{0})) ? (int) $val : (($val{0} == '"') ? rawurlencode(substr($val, 1, -1)) : '{URLEN:'.$val.'}');
782 $url = $this->Gen_URL($url_id, $params, true, true);
783 if ($matches[1] == 'F')
784 $url = qf_full_url($url, true, $this->URL_domain);
785 elseif ($matches[1] == 'R') // && $url{0} != '/'
787 $comps = parse_url($url);
788 if (!$comps['scheme'])
789 $url = '{QF_ROOT}'.$url;
795 function _Load_URLS()
798 static $consts = Array(
799 '{QF_INDEX}' => QF_INDEX,
803 if (count($this->URL_temps))
806 $cachename = ($QF->Config->Get('gen_rwurls'))
807 ? QF_FOX2_URLTEMPS_RW_CACHENAME : QF_FOX2_URLTEMPS_CACHENAME;
809 if ($data = $QF->Cache->Get($cachename))
810 $this->URL_temps = $data;
811 elseif (list($data, $pkgs) = $QF->DSets->Get_DSet('urltemplates', true))
813 if ($QF->Config->Get('gen_rwurls') && (list($rwdata, $rwpkgs) = $QF->DSets->Get_DSet('mod_rw_urlts', true)))
815 $data = $rwdata + $data;
816 $pkgs = $rwpkgs + $pkgs;
819 $data = str_replace(array_keys($consts), array_values($consts), $data);
822 if ($QF->Config->Get('tgl_multidomain', 'fox2'))
824 $domains = $QF->Config->Get('package_domains', 'fox2');
825 $ldomains = $QF->Config->Get('linked_domains', 'fox2');
826 $basedomain = $QF->Config->Get('basic_domain', 'fox2');
827 if (!is_array($domains))
829 if (!is_array($ldomains) || !$basedomain)
832 if (count($domains) || count($ldomains))
834 $domains = preg_replace('#^http\:(?:/)*|/$#i', '', $domains);
835 $ldomains = preg_replace('#^http\:(?:/)*|/$#i', '', $ldomains);
836 $basedomain = preg_replace('#^http\:(?:/)*|/$#i', '', $basedomain);
838 foreach ($data as $key => $val)
840 $cur_pkg = $pkgs[$key];
841 list($cur_link, $cur_url) = explode('/', $val, 2);
842 if ($cur_link && isset($ldomains[$cur_link]))
844 $domain = $ldomains[$cur_link];
845 $val = qf_full_url($cur_url, true, $domain);
848 elseif (isset($domains[$cur_pkg]))
850 $domain = $domains[$cur_pkg];
851 $val = qf_full_url($val, true, $domain);
858 $QF->Cache->Set($cachename, $data);
859 $this->URL_temps = $data;
862 $this->URL_temps = Array();
867 function _Parse_PathInfo()
870 if (!($pt_info = $QF->HTTP->PtInfo))
873 $pt_info = explode('/', $pt_info);
874 $pt_id = $pt_info[0];
875 $pt_parse = $QF->DSets->Get_DSet_Value('ptinfo_masks', $pt_id);
876 if (is_array($pt_parse))
878 $pt_parse = array_values($pt_parse);
880 $imax = min(count($pt_parse), count($pt_info));
881 for ($i=0; $i<$imax; $i++)
882 $pt_data[$pt_parse[$i]] = $pt_info[$i];
884 trigger_error(qf_array_definition($pt_data), E_USER_WARNING);
886 $QF->GPC->Set_Raws($pt_data, QF_GPC_GET);
891 function _Parse_RW($rw_id, $rw_data)
898 $rw_mask = $QF->DSets->Get_DSet_Value('RW_masks', $rw_id);
899 $rw_data = preg_replace('#\.\w*$#D', '', $rw_data);
903 $QF->GPC->Set_Raws(Array('st' => $rw_id, 'dpath' => $rw_data), QF_GPC_GET);
905 elseif (is_array($rw_mask))
907 $rw_data = explode('/', $rw_data);
908 $rw_mask = preg_replace('#\$(\d+)#e', '(isset(\$rw_data[\1])) ? \$rw_data[\1] : ""', $rw_mask);
910 $QF->GPC->Set_Raws($rw_mask, QF_GPC_GET);
918 function HTML_FullURLs(&$buffer)
920 $buffer = preg_replace_callback('#(<(a|form|img|link|script)\s+[^>]*?)(href|action|src)\s*=\s*(\"([^\"<>\(\)]*)\"|\'([^\'<>\(\)]*)\'|[^\s<>\(\)]+)#i', Array(&$this, '_FullURLs_Parse_Callback'), $buffer);
923 function _FullURLs_Parse_Callback($vars)
926 if (!is_array($vars))
934 elseif (isset($vars[5]))
945 if (qf_str_is_url($url) == 2)
946 $url = qf_full_url($url, true, $this->URL_domain);
948 return $vars[1].$vars[3].'='.$bounds.$url.$bounds;
954 $QF->Register_Module('FOX', __FILE__, 'Fox2');
955 $QF->Run_Module('FOX');