if (strpos($url, 'lang=')) { $params = parse_url($url, PHP_URL_QUERY); parse_str($params, $params); if (isset($params['lang'])) { $force_language = $params['lang']; } } if (!empty($force_language)) { $session['lang'] = $force_language; } else { if (isset($_REQUEST['lang'])) { $session['lang'] = $_REQUEST['lang']; } } // load dictionary, extensions and bind events (as soon as possible) $dictionary = nvweb_dictionary_load(); // global data across webgets $current = array('lang' => $session['lang'], 'route' => $route, 'object' => '', 'template' => '', 'category' => '', 'webuser' => '', 'plugins' => '', 'plugins_called' => '', 'delayed_nvlists' => array(), 'delayed_nvsearches' => array(), 'delayed_tags_pre' => array(), 'delayed_tags_code' => array(), 'navigate_session' => !empty($_SESSION['APP_USER#' . APP_UNIQUE]), 'html_after_body' => array(), 'js_after_body' => array()); nvweb_plugins_load(); $current['plugins'] = $plugins; $events->extension_backend_bindings(null, true); if (!empty($session['webuser'])) { $webuser->load($session['webuser']); } else { if (!empty($_COOKIE["webuser"])) { $webuser->load_by_hash($_COOKIE['webuser']); } } // if the webuser was removed, it doesn't exist anymore, // $session/$_COOKIE may have obsolete data, force a log out // also check date range access
function nvweb_route_parse($route = "") { global $website; global $DB; global $current; global $session; global $theme; global $events; global $dictionary; // node route types if (substr($route, 0, 5) == 'node/') { $node = substr($route, 5); $route = 'node'; } switch ($route) { case 'object': nvweb_object(); nvweb_clean_exit(); break; case 'nvajax': nvweb_ajax(); nvweb_clean_exit(); break; case 'nvtags': case 'nvsearch': $current['template'] = 'search'; break; case 'nv.webuser/verify': $hash = $_REQUEST['hash']; $email = filter_var($_REQUEST['email'], FILTER_VALIDATE_EMAIL); if (!empty($hash) && !empty($email)) { $ok = webuser::email_verification($email, $hash); if ($ok) { $session['nv.webuser/verify:email_confirmed'] = time(); } } nvweb_clean_exit(NVWEB_ABSOLUTE . $website->homepage()); break; case 'node': if ($node > 0) { $current['id'] = $node; $DB->query('SELECT * FROM nv_items WHERE id = ' . protect($current['id']) . ' AND website = ' . $website->id); $current['object'] = $DB->first(); // let's count a hit (except admin) if ($current['navigate_session'] != 1 && !nvweb_is_bot()) { $DB->execute(' UPDATE nv_items SET views = views + 1 WHERE id = ' . $current['id'] . ' AND website = ' . $website->id); } $current['type'] = 'item'; $current['template'] = $current['object']->template; if ($current['navigate_session'] == 1 && !empty($_REQUEST['template'])) { $current['template'] = $_REQUEST['template']; } } break; case 'sitemap.xml': nvweb_webget_load('sitemap'); echo nvweb_sitemap(array('mode' => 'xml')); nvweb_clean_exit(); break; // redirect to home page of the current website // redirect to home page of the current website case 'nvweb.home': case 'nv.home': header('location: ' . NVWEB_ABSOLUTE . $website->homepage()); nvweb_clean_exit(); break; // webservice endpoint via XML-RPC calls // webservice endpoint via XML-RPC calls case 'xmlrpc': $events->trigger('nvweb', 'xmlrpc', array('route' => '/' . $route)); // if no extension processes the call, use the integrated XML-RPC parser nvweb_xmlrpc(); nvweb_clean_exit(); break; // empty path // empty path case '': case '/': case 'nv.empty': if ($website->empty_path_action == 'homepage_noredirect') { $route = $website->homepage(); if (strpos($route, '/') === 0) { $route = substr($route, 1); } } else { $route = ""; $website->wrong_path_action = $website->empty_path_action; } // do NOT break this case, continue processing as wrong_path action // no special route (or already processed), look for the path on navigate routing table // do NOT break this case, continue processing as wrong_path action // no special route (or already processed), look for the path on navigate routing table default: $DB->query('SELECT * FROM nv_paths WHERE path = ' . protect('/' . $route) . ' AND website = ' . $website->id . ' ORDER BY id DESC'); $rs = $DB->result(); if (empty($rs)) { // no valid route found switch ($website->wrong_path_action) { case 'homepage': case 'homepage_redirect': header('location: ' . NVWEB_ABSOLUTE . $website->homepage()); nvweb_clean_exit(); break; case 'http_404': header("HTTP/1.0 404 Not Found"); nvweb_clean_exit(); break; case 'theme_404': $current['template'] = 'not_found'; $current['type'] = 'structure'; $current['id'] = 0; $current['object'] = new structure(); return; break; case 'website_path': $redirect_url = nvweb_template_convert_nv_paths($website->wrong_path_redirect); header('location: ' . $redirect_url); nvweb_clean_exit(); break; case 'blank': default: nvweb_clean_exit(); break; } } else { // route found! // let's count a hit (except admin) if ($current['navigate_session'] != 1 && !nvweb_is_bot()) { $DB->execute(' UPDATE nv_paths SET views = views + 1 WHERE id = ' . $rs[0]->id . ' AND website = ' . $website->id); } // set the properties found // set the default language for this route if (!isset($_REQUEST['lang'])) { $current['lang'] = $rs[0]->lang; $session['lang'] = $rs[0]->lang; // force reloading the dictionary $dictionary = nvweb_dictionary_load(); } $current['type'] = $rs[0]->type; $current['id'] = $rs[0]->object_id; // look for the template associated with this item if ($current['type'] == 'structure') { $obj = new structure(); $obj->load($current['id']); // check if it is a direct access to a "jump to another branch" path if ($obj->dictionary[$current['lang']]['action-type'] == 'jump-branch') { $current['id'] = $obj->dictionary[$current['lang']]['action-jump-branch']; $obj = new structure(); $obj->load($current['id']); header('location: ' . NVWEB_ABSOLUTE . $obj->paths[$current['lang']]); nvweb_clean_exit(); } else { if ($obj->dictionary[$current['lang']]['action-type'] == 'jump-item') { $current['id'] = $obj->dictionary[$current['lang']]['action-jump-item']; $obj = new item(); $obj->load($current['id']); header('location: ' . NVWEB_ABSOLUTE . $obj->paths[$current['lang']]); nvweb_clean_exit(); } } $current['object'] = $obj; $current['category'] = $current['id']; if ($current['navigate_session'] != 1 && !nvweb_is_bot()) { $DB->execute(' UPDATE nv_structure SET views = views + 1 WHERE id = ' . protect($current['id']) . ' AND website = ' . $website->id); } } else { if ($current['type'] == 'item') { $DB->query('SELECT * FROM nv_items WHERE id = ' . protect($current['id']) . ' AND website = ' . $website->id); $current['object'] = $DB->first(); // let's count a hit (except admin) if ($current['navigate_session'] != 1 && !nvweb_is_bot()) { $DB->execute(' UPDATE nv_items SET views = views + 1 WHERE id = ' . $current['id'] . ' AND website = ' . $website->id); } } else { if ($current['type'] == 'feed') { $out = feed::generate_feed($current['id']); if ($current['navigate_session'] != 1 && !nvweb_is_bot()) { $DB->execute(' UPDATE nv_feeds SET views = views + 1 WHERE id = ' . $current['id'] . ' AND website = ' . $website->id); } echo $out; nvweb_clean_exit(); } else { // path exists, but the object type is unknown // maybe the path belongs to an extension? $events->trigger('nvweb', 'routes', array('path' => $rs[0])); } } } $current['template'] = $current['object']->template; } break; } }
function nv_plugin_init() { global $DB; global $webuser; global $config; global $website; global $current; global $dictionary; global $session; global $events; global $idn; // create database connection $DB = new database(); if (!$DB->connect()) { die(APP_NAME . ' # ERROR<br /> ' . $DB->get_last_error()); } // global exception catcher try { $idn = new idna_convert(); // which website do we have to load? $url = nvweb_self_url(); if (!empty($_REQUEST['wid'])) { $website = new website(); $website->load(intval($_REQUEST['wid'])); } else { $website = nvweb_load_website_by_url($url); } if ($website->permission == 2 || $website->permission == 1 && empty($_SESSION['APP_USER#' . APP_UNIQUE])) { nvweb_clean_exit(); } // global helper variables $session = array(); // user session $webuser = new webuser(); $nvweb_absolute = empty($website->protocol) ? 'http://' : $website->protocol; if (!empty($website->subdomain)) { $nvweb_absolute .= $website->subdomain . '.'; } $nvweb_absolute .= $website->domain . $website->folder; define('NVWEB_ABSOLUTE', $nvweb_absolute); define('NVWEB_OBJECT', $nvweb_absolute . '/object'); if (!defined('NAVIGATE_URL')) { define('NAVIGATE_URL', NAVIGATE_PARENT . NAVIGATE_FOLDER); } if (!isset($_SESSION['nvweb.' . $website->id])) { $_SESSION['nvweb.' . $website->id] = array(); $session['lang'] = nvweb_country_language(); } else { $session = $_SESSION['nvweb.' . $website->id]; if (empty($session['lang'])) { $session['lang'] = nvweb_country_language(); } } if (isset($_REQUEST['lang'])) { $session['lang'] = $_REQUEST['lang']; } if (!empty($session['webuser'])) { $webuser->load($session['webuser']); } else { if (!empty($_COOKIE["webuser"])) { $webuser->load_by_hash($_COOKIE['webuser']); } } @setlocale(LC_ALL, $website->languages[$session['lang']]['system_locale']); // remove the "folder" part of the route $route = ''; if (!empty($_REQUEST['route'])) { $route = $_REQUEST['route']; // remove the "folder" part of the route (only if this url is really under a folder) if (!empty($website->folder) && strpos('/' . $route, $website->folder) === 0) { $route = substr('/' . $route, strlen($website->folder) + 1); } } // global data across webgets $current = array('lang' => $session['lang'], 'route' => $route, 'object' => '', 'template' => '', 'category' => '', 'webuser' => @$session['webuser'], 'navigate_session' => !empty($_SESSION['APP_USER#' . APP_UNIQUE]), 'html_after_body' => array(), 'js_after_body' => array()); $dictionary = nvweb_dictionary_load(); $_SESSION['nvweb.' . $website->id] = $session; } catch (Exception $e) { ?> <html> <body> ERROR <br /><br /> <?php echo $e->getMessage(); ?> </body> </html> <?php } $events = new events(); nvweb_plugins_load(); $events->extension_backend_bindings(); }