*/ $agent = strtolower($_SERVER['HTTP_USER_AGENT']); if(strpos($agent, 'safari') !== false && strpos($agent, 'mobile') !== false) { $iphone_mode = false; } /*<= detect iphone*/ /*determine theme =>*/ if ($_GET['set_theme']) { setcookie("set_theme", $_GET['set_theme'], time(), '/', $cookie_domain); $set_theme = $_GET['set_theme']; } else { $set_theme = $_COOKIE['set_theme']; } //manually set theme if ($set_theme && !$iphone_mode) { $theme_a = f(q("SELECT theme_dir, css_location FROM cl_site_themes WHERE theme='".mysql_escape_string($set_theme)."'")); $current_theme = $theme_a['theme_dir']; } //retrieve active theme details if (!$current_theme) { $theme_a = f(q("SELECT theme_dir, css_location FROM cl_site_themes WHERE active='1' AND iphone_theme='".mysql_escape_string($iphone_mode?'1':'0')."'")); $current_theme = $theme_a['theme_dir']; } //retrieve master theme details $theme_d = f(q("SELECT theme_dir, css_location FROM cl_site_themes WHERE `default`='1'")); if ($theme_d['theme_dir'] && file_exists($theme_d['theme_dir'])) //if master theme is available and its path exists, use it { $default_theme_name = $theme_d['theme_dir']; } else //if master theme is not retrieved (DB problem probably), use hardcoded master theme { $default_theme_name = 'themes/default/'; } if ($theme_a['css_location'] && file_exists($theme_a['css_location'])) //if active theme css available, use it { $css_full_url = $theme_a['css_location']; } elseif ($theme_d['css_location'] && file_exists($theme_d['css_location'])) //if not, use master theme css { $css_full_url = $theme_d['css_location']; } else //if it is not available (DB problem probably), use hardcoded master css { $css_full_url = 'themes/default/style.css'; } /*<= determine theme*/ /* *BANNER MANAGER */ if(file_exists('smartway/lib/banner_manager.lib') && $page!='process_banner') { require_once('smartway/lib/banner_manager.lib'); if (banner_manager::is_installed()) { $banner_manager = new banner_manager(); $banner_manager->get_random_banners(); } } /* *end of BANNER MANAGER */ include "engine/login_pages.php"; session_start(); // Locating current page if ($action == change_lang) { setcookie("cl_lang", $lang_abbrev, 0, '/', $cookie_domain); if(strstr($_SERVER['HTTP_REFERER'], $_SERVER['SERVER_NAME'])) { header('Location: '.$_SERVER['HTTP_REFERER']); } } else { $lang_abbrev = $_COOKIE[cl_lang]; } if($action == logout) { setcookie("sAuth", "", time()-10, '/', $cookie_domain); setcookie("cl_remember_me", "", time()-10, '/', $cookie_domain); $page = index; unset($sAuth); unset($_COOKIE[cl_remember_me]); $logged_in = 0; } if (!isset($_COOKIE[cl_lang])) { setcookie("cl_lang", $default_lang, time()+60*60*24*30, '/', $cookie_domain); $lang_abbrev = $default_lang; } q("SET NAMES UTF8"); $lang = loadLangDB($lang_abbrev); if ($lang_abbrev) { $lang_details = f(q("SELECT id, name, abv, iso_code FROM cl_langs WHERE abv='".mysql_escape_string($lang_abbrev)."'")); } $name_field = (($lang_details['abv'] && $lang_details['abv']!='en')?'name_'.$lang_details['abv']:'name'); $lang_charset = ($lang_details['iso_code']?$lang_details['iso_code']:'utf-8'); //FB Connect (sign in or register) if($action == fb_connect && profile_import::is_enabled('facebook')) { if (!$fb_back) { profile_import::forward_action('facebook', 'initiate_profile_import'); } profile_import::forward_action('facebook', 'finizalie_profile_import'); $user_details = profile_import::forward_action('facebook', 'get_profile'); $fb_uid = $user_details['uid']; $res = q("SELECT id, username, password FROM cl_members WHERE facebook_id='".mysql_escape_string($user_details['uid'])."'"); $res1 = q("SELECT 1 FROM cl_members WHERE email='".mysql_escape_string($user_details['email'])."'"); $fMember = f(q("SELECT * FROM cl_members WHERE id='$sAuth'")); if ($fb_uid) { if($fMember[id]) //an existing user wants to connect his profile { if(nr($res)) //error: there is already a user associated with this facebook user { $page = 'account'; $f = f($res); $errors_string= $lang['php']['account'][1].': '.$f['username']; } else //everything is fine, connect this user { q("UPDATE cl_members SET facebook_id='".$user_details['uid']."' WHERE id='".$fMember['id']."'"); $page = 'account'; $highlight_string = $lang['php']['account'][2]; $highlight_message = parseVariables("templates/highlight_message.html", 0); } } elseif (nr($res)) //sign in an old user { $f = f($res); $page = 'sign_in'; $action = 'login'; $username = $f['username']; $password = $f['password']; } else //register a new user { //generate an unique username $i = 0; $username_base = str_replace(' ', '_', $user_details['name']); do { if (!$username) $username = $username_base; else $username = $username_base.$i; $res = q("SELECT * FROM cl_members WHERE username='".mysql_escape_string($username)."'"); $i++; }while(nr($res)); $password = substr(uniqid(true), 0, 20); if ($user_details['email'] && !nr($res1)) { $highlight_string= $lang['php']['account'][2]; $email = $user_details['email']; } else { $highlight_string= $lang['php']['account'][3]; $email = mt_rand().'@'.mt_rand().'.rnd'; } $f = f(q("SELECT id FROM cl_countries WHERE name='".mysql_escape_string($user_details['hometown_location']['country'])."'")); $register_country = $f['id']; $f = f(q("SELECT id FROM cl_states WHERE name='".mysql_escape_string($user_details['hometown_location']['state'])."'")); if ($f['id']) { $register_state = $f['id']; } else { $register_state = ""; } $zipcode = $user_details['hometown_location']['zip']; $t = time(); q("INSERT INTO cl_members (username, password, email, first_name, last_name, address_1, address_2, city, state, country, zipcode, phone, ip_addr, reg_date, status, balance, facebook_id) VALUES('".mysql_escape_string($username)."','".mysql_escape_string($password)."','".mysql_escape_string($email)."', '".mysql_escape_string($user_details['first_name'])."', '".mysql_escape_string($user_details['last_name'])."', '', '', '".mysql_escape_string($user_details['hometown_location']['city'])."', '".$register_state."', '".$register_country."', '".$zipcode."', '', '$REMOTE_ADDR', '$t', '1', '0', '".$fb_uid."')"); $new_member_id = mysql_insert_id(); if (strtolower($zipcode_enabled)=='on') { $z_row = f(q("SELECT longitude, latitude FROM cl_zipcodes WHERE zipcode='".$zipcode."'")); q("UPDATE cl_members SET longitude = '".$z_row['longitude']."', latitude = '".$z_row['latitude']."' WHERE id = '$new_member_id'"); } $page = 'sign_in'; $action = 'login'; $highlight_message = parseVariables("templates/highlight_message.html", 0); } } } if($action == order && $order_n != "") { include "engine/card_process.php"; if($payment_status == "success") { if($_REQUEST['gateway'] == "authorizenet" || $_REQUEST['gateway'] == "worldpay") { echo 'Processing request...'; return; } $page = payment_success; } else { if($_REQUEST['gateway'] == "authorizenet" || $_REQUEST['gateway'] == "worldpay") { echo 'Processing request...'; return; } $page = payment_failed; } } // if user is logged in, don't let him go to register page if ($sAuth != "" && $page == "register") { $page = "ads"; } if(IsRequiredLogin($page, $action) && $sAuth == "") { if(!isset($_SESSION['cl_redirect_page'])) { $_SESSION['cl_redirect_page'] = $page; // Save original page $_SESSION['cl_id'] = $id; // Save ad id } $page = sign_in; } if(!isset($page) && !isset($page)) { $page = index; } $logged_in = 0; // Handling actions if($action == login) { if($username == "" || $password == "") { $errors_string = $lang[main][index][1]; $page = "sign_in"; } else { $fMember = f(q("SELECT * FROM cl_members WHERE username='$username' AND password='$password'")); if($fMember[id] == "") { $errors_string = $lang[main][index][2]; $page = "sign_in"; } else if ($fMember[status] != 1) { $errors_string = $lang[main][index][3]; $page = "sign_in"; } else { setcookie("sAuth", $fMember[id], null, '/', $cookie_domain); $sAuth = $fMember[id]; if($remember_me) setcookie("cl_remember_me", $fMember[id], time()+ 7776000, '/', $cookie_domain); else setcookie("cl_remember_me", null, null, '/', $cookie_domain); $logged_in = 1; $page = ads; q("UPDATE cl_members SET last_login='".time()."' WHERE id='$fMember[id]'"); } } } if(!$logged_in && isset($sAuth)) { $fMember = f(q("SELECT * FROM cl_members WHERE id='$sAuth'")); if($fMember[id] == "") setcookie("sAuth", null, null, '/', $cookie_domain); else $logged_in = 1; } if(!$logged_in && $_COOKIE[cl_remember_me]) { $fMember = f(q("SELECT * FROM cl_members WHERE id='$_COOKIE[cl_remember_me]'")); setcookie("sAuth", $fMember[id], null, '/', $cookie_domain); $sAuth = $fMember[id]; $logged_in = 1; q("UPDATE cl_members SET last_login='".time()."' WHERE id='$fMember[id]'"); } // EOF Handling actions if(($page == sign_in || $page == register) && $logged_in) { $page = "account"; if(isset($_SESSION['cl_redirect_page'])) { $page = $_SESSION['cl_redirect_page']; unset($_SESSION['cl_redirect_page']); } if(isset($_SESSION['cl_id'])) { $id = $_SESSION['cl_id']; unset($_SESSION['cl_id']); } } include_once "engine/pages/index_featured_bar.php"; //handling sitemap if ($page== 'sitemap') { include_once "smartway/lib/sitemap.lib"; $sitemap = new sitemap_generator($root_host); $sitemap->run(); $sitemap->display(); } //handling xml feed if ($page=='xml_feed') { include_once "smartway/lib/xml_feed.lib"; $xml_feed = new xml_feed($site, $root_host); } //handling robots if ($page== 'robots') { echo "Sitemap: ".$root_host."sitemap.xml"; die; } $page = str_replace("../", "", $page); /////////////////////////////////////////////////////////////////////////////// /// Integration 2.0 webClassifieds module if(file_exists('smartway/plug-ins/integration/_integration_webclassifieds.php')) { require_once('smartway/plug-ins/integration/_integration_webclassifieds.php'); init_wc_integration(); } /// end Integration 2.0 /////////////////////////////////////////////////////////////////////////////// if($fMember[id]) { $account_sign_in_link = ''.$lang[main][index][4].''; $register_logout_link = $iphone_sign_in_link = ''.$lang[main][index][5].""; $register_big_button = ''; } else { $account_sign_in_link = $iphone_sign_in_link = ''.$lang[main][index][6].''; $register_logout_link = ''.$lang[main][index][7].''; $register_big_button = ''.$lang[main][index][7].''; } if(!$no_header) { if(check_plugin('multilang')) { if($lang_icon_select) $language_selection = sysGetLangSelectIcons(); else $language_selection = sysGetLangDropdown("lang_abbrev", $lang_abbrev); } if ($root_host) { $head_base = ""; do_set_head_base(); } //SEO titles $page_name = ""; if ($page=='view_ad') { if ($id) { $fAd_seo = f(q("SELECT a.title, a.description, a.country, a.state, a.city FROM cl_ads AS a, cl_members AS m WHERE a.id='$id' AND a.member_id=m.id")); $fAd_seo['title'] = censorBadWords($fAd_seo['title']); $fAd_seo['description'] = censorBadWords($fAd_seo['description']); $fAdLocation_seo = f(q("SELECT s.".$name_field." AS state, co.".$name_field." AS country, IFNULL(ci.".$name_field.", '".mysql_escape_string($fAd_seo[city])."') AS city FROM cl_countries co LEFT JOIN cl_states AS s ON (co.id = s.parent_id AND s.id='$fAd_seo[state]') LEFT JOIN cl_cities AS ci ON (s.id = ci.parent_id AND ci.name='$fAd_seo[city]') WHERE co.id='$fAd_seo[country]'")); $location_seo = ($fAdLocation_seo[city]?$fAdLocation_seo[city].", ":"").($fAdLocation_seo[state] ? $fAdLocation_seo[state].", ": "").$fAdLocation_seo[country]; $page_name = $fAd_seo['title'].($location_seo?' - '.$location_seo:''); } } else { $page_name = get_seo_page_name($page); } if (!$page_name) { $page_name = get_seo_page_name('index'); } $original_site_title = $site_title; $site_title = str_replace("{CURRENT_PAGE}", $page_name, $site_title); //meta description $meta_description = $site_title.($fAd_seo['description']?"\n".htmlspecialchars(strip_tags($fAd_seo['description'])):""); if($show_quicksearch_bar) include "engine/pages/quicksearch_bar.php"; } if(!$sAuth) { $sign_in_top = parseVariables("templates/sign_in_top.html", 0); $members_menu = ""; } else { //if user is authenticated but email is not verified, there are only few pages he can access $allowed_pages = array('index', 'ad_step_2', 'ad_step_3', 'ad_step_4', 'billing', 'is_seo', 'payment_failed', 'payment_success', 'terms', 'faq', 'verify_account_message'); if (!in_array($page, $allowed_pages) && !is_verified_user($sAuth)) { $page = 'verify_account_message'; } } //$start_s=microtime(1);//!!! include "engine/pages/$page.php"; //$end_s=microtime(1);echo "

"."engine/pages/$page.php".": ".($end_s-$start_s)."

";//!!! //$end_s0=microtime(1);echo "
"."everything".": ".($end_s0-$start_s0)."
";//!!! if($sAuth) { include_once "engine/pages/member_menu.php"; } if ($notemplate) { echo $page_content; } else { if ($index_city) { $city_name_f = f(q("SELECT name FROM cl_cities WHERE id = '".mysql_escape_string($index_city)."'")); $index_city_text = $city_name_f['name']; } $page_top_include = parseVariables("templates/page_top_include.html", 0); $page_bottom_include = parseVariables("templates/page_bottom_include.html", 0); //FB BUTTON if (profile_import::is_enabled('facebook') && !strlen($fMember['facebook_id'])) { $fb_button_box = parseVariables("templates/fb_button.html", 0); } $lang[html][footer][2] = str_replace("{CURRENT_YEAR}", date("Y"), $lang[html][footer][2]); parseVariables("templates/main.html"); } if($debug_mode) { echo "Query Count: ".$classifieds_debug_count."
"; echo $classifieds_debug; } d($db); ?>