/** * Module tag parsing * * Used to include other object-modules in current workspace * * @access private * @param string $res template strings * @param array $hash data params * @param string $dir current template directory (for correct [#inc ...#] tags parsing) */ function parseModules(&$res, &$hash, $dir) { global $md; global $inst; $instance = $inst; if (preg_match_all('/\\[#module (.*?)#\\]/', $res, $matches, PREG_PATTERN_ORDER)) { $count_matches_0 = count($matches[0]); for ($i = 0; $i < $count_matches_0; $i++) { $data = $matches[1][$i]; $tmp = ""; // reading module data from module including directive $module_data = array(); if (preg_match_all('/(\\w+?)="(.*?)"/i', $data, $matches1, PREG_PATTERN_ORDER)) { $count_matches1_0 = count($matches1[0]); for ($k = 0; $k < $count_matches1_0; $k++) { $key = $matches1[1][$k]; $value = $matches1[2][$k]; if ($key == "template") { $value = $dir . $value; } $module_data[$key] = $value; } } if (file_exists(DIR_MODULES . $module_data["name"] . '/' . $module_data["name"] . ".class.php") || class_exists($module_data["name"])) { // including module class if (!class_exists($module_data["name"])) { include_once DIR_MODULES . $module_data["name"] . '/' . $module_data["name"] . ".class.php"; } // creating code for module creation and running $obj = "\$object{$i}"; $code = ""; $code .= "{$obj}=new " . $module_data["name"] . ";\n"; $code .= $obj . "->owner=&\$this->owner;\n"; // setting module parameters from module including directive foreach ($module_data as $k => $v) { if ($k == "name") { continue; } $code .= $obj . "->" . $k . "='" . addslashes($v) . "';\n"; } // setting other module parameters // if current request is to this module, then run get params otherwise get params from encoded query if ($md != $module_data["name"] || $module_data["instance"] != '' && $module_data["instance"] != $instance && $instance != '') { // restoring module params from coded string (module should not overwrite this method) $code .= $obj . "->restoreParams();\n"; } elseif ($module_data["name"] == $md && ($module_data["instance"] == '' || $module_data["instance"] == $instance || $instance == '')) { // getting module params from query string (every module should handle this method) $code .= $obj . "->getParams();\n"; } // repeating module set parameters for security reasons foreach ($module_data as $k => $v) { if ($k == "name") { continue; } $code .= $obj . "->" . $k . "='" . addslashes($v) . "';\n"; } StartMeasure("module_" . $module_data["name"]); if (SETTINGS_SITE_LANGUAGE && file_exists(ROOT . 'languages/' . $module_data["name"] . '_' . SETTINGS_SITE_LANGUAGE . '.php')) { include_once ROOT . 'languages/' . $module_data["name"] . '_' . SETTINGS_SITE_LANGUAGE . '.php'; } if (file_exists(ROOT . 'languages/' . $module_data["name"] . '_default.php')) { include_once ROOT . 'languages/' . $module_data["name"] . '_default.php'; } // run module and insert module result in template $code .= $obj . "->run();\n"; $code .= "\$tmp=" . $obj . "->result;\n"; eval($code); EndMeasure("module_" . $module_data["name"]); } else { // module class file was not found global $current_installing_module; $rep_ext = ''; if (preg_match('/\\.dev/is', $_SERVER['HTTP_HOST'])) { $rep_ext = '.dev'; $install_dir = "/var/projects/repository/engine_2.x/modules/"; } if (preg_match('/\\.jbk/is', $_SERVER['HTTP_HOST'])) { $rep_ext = '.jbk'; $install_dir = "d:/jey/projects/repository/engine_2.x/modules/"; } if (!$current_installing_module[$module_data["name"]] && $rep_ext != '' && @Is_Dir($install_dir . $module_data["name"])) { //$tmp="<div><iframe src=\"http://installer.dev/installer.php?host=".$_SERVER['HTTP_HOST']."&doc_root=".$_SERVER['DOCUMENT_ROOT']."&mode=install&modules[]=".$module_data["name"]."\" width=100% height=100></iframe></div>"; $wnd_name = "win" . rand(1, 10000000); $tmp = "<script language='javascript' type='text/JavaScript'>wnd=window.open(\"http://installer" . $rep_ext . "/installer.php?host=" . $_SERVER['HTTP_HOST'] . "&doc_root=" . $_SERVER['DOCUMENT_ROOT'] . "&mode=install&modules[]=" . $module_data["name"] . "\", \"" . $wnd_name . "\", \"height=400,width=400\");</script>"; $current_installing_module[$module_data["name"]] = 1; echo $tmp; } else { $tmp = "<p align=center><font color='red'><b>Module \"" . $module_data["name"] . "\" not found</b> (" . str_replace('#', '', $matches[0][$i]) . ")</font></p>"; } } //echo $matches[0][$i]; //echo htmlspecialchars($tmp)."\n\n"; $res = str_replace($matches[0][$i], $tmp, $res); } } }
function run() { global $session; Define('ALTERNATIVE_TEMPLATES', 'templates_alt'); if ($this->action == 'ajaxgetglobal') { header("HTTP/1.0: 200 OK\n"); header('Content-Type: text/html; charset=utf-8'); $res['DATA'] = getGlobal($_GET['var']); echo json_encode($res); global $db; $db->Disconnect(); exit; } if ($this->action == 'ajaxsetglobal') { header("HTTP/1.0: 200 OK\n"); header('Content-Type: text/html; charset=utf-8'); setGlobal($_GET['var'], $_GET['value']); $res['DATA'] = 'OK'; echo json_encode($res); global $db; $db->Disconnect(); exit; } if ($this->action == 'getlatestnote') { header("HTTP/1.0: 200 OK\n"); header('Content-Type: text/html; charset=utf-8'); $msg = SQLSelectOne("SELECT * FROM shouts WHERE MEMBER_ID=0 ORDER BY ID DESC LIMIT 1"); $res = array(); $res['DATA'] = $msg['MESSAGE']; echo json_encode($res); global $db; $db->Disconnect(); exit; } if ($this->action == 'getlatestmp3') { header("HTTP/1.0: 200 OK\n"); header('Content-Type: text/html; charset=utf-8'); if ($dir = @opendir(ROOT . "cached/voice")) { while (($file = readdir($dir)) !== false) { if (preg_match('/\\.mp3$/', $file)) { $mtime = filemtime(ROOT . "cached/voice/" . $file); /* if ((time()-$mtime)>60*60*24 && $mtime>0) { //old file, delete? unlink(ROOT."cached/voice".$file); } else { } */ $files[] = array('FILENAME' => $file, 'MTIME' => $mtime); } if (preg_match('/\\.wav$/', $file)) { $mtime = filemtime(ROOT . "cached/voice/" . $file); /* if ((time()-$mtime)>60*60*24 && $mtime>0) { //old file, delete? unlink(ROOT."cached/voice/".$file); } */ } } closedir($dir); } //print_r($files);exit; if (is_array($files)) { function sortFiles($a, $b) { if ($a['MTIME'] == $b['MTIME']) { return 0; } return $a['MTIME'] > $b['MTIME'] ? -1 : 1; } usort($files, 'sortFiles'); echo '/cached/voice/' . $files[0]['FILENAME']; } global $db; $db->Disconnect(); exit; } if (!defined('SETTINGS_SITE_LANGUAGE') || !defined('SETTINGS_SITE_TIMEZONE') || !defined('SETTINGS_TTS_GOOGLE') || !defined('SETTINGS_GROWL_ENABLE') || !defined('SETTINGS_HOOK_BEFORE_SAY')) { $this->action = 'first_start'; } if ($this->action == 'first_start') { include DIR_MODULES . 'first_start.php'; } $out["ACTION"] = $this->action; $out["TODAY"] = date('l, F d, Y'); $out["DOC_NAME"] = $this->doc_name; global $username; if ($username) { $user = SQLSelectOne("SELECT * FROM users WHERE USERNAME LIKE '" . DBSafe($username) . "'"); if (!$user['PASSWORD']) { $session->data['SITE_USERNAME'] = $user['USERNAME']; $session->data['SITE_USER_ID'] = $user['ID']; } else { if (!isset($_SERVER['PHP_AUTH_USER'])) { header('WWW-Authenticate: Basic realm="MajorDoMo"'); header('HTTP/1.0 401 Unauthorized'); echo 'Password required!'; exit; } else { if ($_SERVER['PHP_AUTH_USER'] == $user['USERNAME'] && $_SERVER['PHP_AUTH_PW'] == $user['PASSWORD']) { $session->data['SITE_USERNAME'] = $user['USERNAME']; $session->data['SITE_USER_ID'] = $user['ID']; } else { header('WWW-Authenticate: Basic realm="MajorDoMo"'); header('HTTP/1.0 401 Unauthorized'); echo 'Incorrect username/password!'; exit; } } } } global $terminal; if ($terminal) { $session->data['TERMINAL'] = $terminal; } if (preg_match('/^app_\\w+$/is', $this->action) || $this->action == 'xray') { $out['APP_ACTION'] = 1; } if ($this->app_action) { $out['APP_ACTION'] = 1; } $terminals = SQLSelect("SELECT * FROM terminals ORDER BY TITLE"); $total = count($terminals); for ($i = 0; $i < $total; $i++) { //!$session->data['TERMINAL'] && if ($terminals[$i]['HOST'] != '' && $_SERVER['REMOTE_ADDR'] == $terminals[$i]['HOST']) { $session->data['TERMINAL'] = $terminals[$i]['NAME']; } if ($terminals[$i]['NAME'] == $session->data['TERMINAL']) { $terminals[$i]['SELECTED'] = 1; $out['TERMINAL_TITLE'] = $terminals[$i]['TITLE']; } } $out['TERMINALS'] = $terminals; if ($total == 1) { $out['HIDE_TERMINALS'] = 1; $session->data['TERMINAL'] = $terminals[0]['NAME']; } $users = SQLSelect("SELECT * FROM users ORDER BY NAME"); $total = count($users); for ($i = 0; $i < $total; $i++) { if ($users[$i]['USERNAME'] == $session->data['SITE_USERNAME']) { $users[$i]['SELECTED'] = 1; $out['USER_TITLE'] = $users[$i]['NAME']; $out['USER_AVATAR'] = $users[$i]['AVATAR']; } elseif (!$session->data['SITE_USERNAME'] && $users[$i]['HOST'] && $users[$i]['HOST'] == $_SERVER['REMOTE_ADDR']) { $session->data['SITE_USERNAME'] = $users[$i]['USERNAME']; $session->data['SITE_USER_ID'] = $users[$i]['ID']; $out['USER_TITLE'] = $users[$i]['NAME']; $out['USER_AVATAR'] = $users[$i]['AVATAR']; } if ($users[$i]['IS_DEFAULT'] == 1) { $out['DEFAULT_USERNAME'] = $users[$i]['USERNAME']; $out['DEFAULT_USER_ID'] = $users[$i]['ID']; } } $out['USERS'] = $users; if ($total == 1) { $out['HIDE_USERS'] = 1; $session->data['SITE_USERNAME'] = $users[0]['USERNAME']; $session->data['SITE_USER_ID'] = $users[0]['ID']; } if (!$session->data['SITE_USERNAME'] && $out['DEFAULT_USERNAME']) { $session->data['SITE_USERNAME'] = $out['DEFAULT_USERNAME']; $session->data['SITE_USER_ID'] = $out['DEFAULT_USER_ID']; for ($i = 0; $i < $total; $i++) { if ($users[$i]['USERNAME'] == $session->data['USERNAME']) { $users[$i]['SELECTED'] = 1; $out['USER_TITLE'] = $users[$i]['NAME']; $out['USER_AVATAR'] = $users[$i]['AVATAR']; } } } if ($out['USER_TITLE']) { Define('USER_TITLE', $out['USER_TITLE']); Define('USER_AVATAR', $out['USER_AVATAR']); } else { Define('USER_TITLE', ''); Define('USER_AVATAR', ''); } if ($out["DOC_NAME"]) { //$doc=SQLSelectOne("SELECT ID FROM cms_docs WHERE NAME LIKE '".DBSafe($out['DOC_NAME'])."'"); if ($doc['ID']) { $this->doc = $doc['ID']; } } if ($session->data["AUTHORIZED"]) { $out['AUTHORIZED_ADMIN'] = 1; } if ($this->action == '' || $this->action == 'pages') { $res = SQLSelect("SELECT * FROM layouts ORDER BY PRIORITY DESC, TITLE"); if ($this->action != 'admin') { $total = count($res); $res2 = array(); for ($i = 0; $i < $total; $i++) { if (checkAccess('layout', $res[$i]['ID'])) { $res2[] = $res[$i]; } } $res = $res2; unset($res2); } $out['LAYOUTS'] = $res; $total = count($out['LAYOUTS']); for ($i = 0; $i < $total; $i++) { $out['LAYOUTS'][$i]['NUM'] = $i; } $out['TOTAL_LAYOUTS'] = count($out['LAYOUTS']); } if ($this->doc) { $this->doc_id = $this->doc; } $out["DOC_ID"] = $this->doc_id; if ($session->data['MY_MEMBER']) { $out['MY_MEMBER'] = $session->data['MY_MEMBER']; $tmp = SQLSelectOne("SELECT ID FROM users WHERE ID='" . (int) $out['MY_MEMBER'] . "' AND ACTIVE_CONTEXT_ID!=0 AND TIMESTAMPDIFF(SECOND, ACTIVE_CONTEXT_UPDATED, NOW())>600"); if ($tmp['ID']) { SQLExec("UPDAE users SET ACTIVE_CONTEXT_ID=0, ACTIVE_CONTEXT_EXTERNAL=0 WHERE ID='" . $tmp['ID'] . "'"); } } $out['AJAX'] = $this->ajax; $out['POPUP'] = $this->popup; $days = array('Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'); $out['TODAY'] = $days[date('w')] . ', ' . date('d.m.Y'); Define(TODAY, $out['TODAY']); global $ajt; if ($ajt == '') { $template_file = DIR_TEMPLATES . $this->name . ".html"; } else { $template_file = ROOT . 'templates_ajax/' . $this->name . "_" . $ajt . ".html"; } if ($this->action == 'menu') { $template_file = DIR_TEMPLATES . "menu.html"; } if ($this->action == 'pages') { $template_file = DIR_TEMPLATES . "pages.html"; } if ($this->action == 'scenes') { $template_file = DIR_TEMPLATES . "scenes.html"; } if ($this->ajax && $this->action) { global $ajax; $ajax = 1; if (file_exists(DIR_MODULES . $this->action)) { include_once DIR_MODULES . $this->action . '/' . $this->action . '.class.php'; $obj = "\$object{$i}"; $code = ""; $code .= "{$obj}=new " . $this->action . ";\n"; $code .= $obj . "->owner=&\$this;\n"; $code .= $obj . "->getParams();\n"; $code .= $obj . "->ajax=1;\n"; $code .= $obj . "->run();\n"; StartMeasure("module_" . $this->action); eval($code); endMeasure("module_" . $this->action); } return; } else { $this->data = $out; $p = new parser($template_file, $this->data, $this); return $p->result; } }