error_reporting(0); ini_set("display_errors", "Off"); session_start(); define("IN_SCRIPT", "1"); if (!file_exists("vars.php")){ header("Location: installer/index.php"); exit(); } else { include("vars.php"); if (!isset($basepath)){ header("Location: installer/index.php"); exit(); } } $page_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; if (substr_count($page_url, "http://www.") && !substr_count($baseurl, "http://www.")){ $baseurl = str_replace("http://","http://www.", $baseurl); } $db = mysqlConnect($dbhost, $dbuser, $dbpass, $dbname); include("includes/settings.class.php"); include("includes/user.class.php"); include("includes/coupon.class.php"); include("includes/store.class.php"); include("includes/category.class.php"); include("includes/misc.class.php"); include("includes/seo.class.php"); include("includes/comment.class.php"); include("includes/page.class.php"); include("includes/click.class.php"); include("includes/utils.php"); include("$basepath/templates/smarty/libs/Smarty.class.php"); $settings = new Settings($db); $coupon = new Coupon($db); $store = new Store($db); $category = new Category($db); $misc = new Misc(); $user = new User($db); $comment = new Comment($db); $click = new Click($db); $page_client = new Page($db); // break naming convention to avoid conflict with popular parameter name $default_language = $settings->getDefaultLanguage(); $seo = new SEO($db, $default_language); if (isset($_SERVER['HTTP_REFERER'])){ $referer = $_SERVER['HTTP_REFERER']; } else { $referer = ''; } if (!isset($_SESSION['theme']) || !$_SESSION['theme']){ $theme = $settings->getSetting("theme"); if (!count($theme)){ $theme = 'bootstrap'; } else { $theme = $theme->theme; } } else { $theme = $_SESSION['theme']; } $smarty = new Smarty(); $smarty->caching = 0; $smarty->template_dir = "$basepath/templates/$theme"; if (file_exists("$basepath/cachefiles/$theme")){ $smarty->compile_dir = "$basepath/cache/$theme"; $smarty->cache_dir = "$basepath/cache/$theme"; } else { $smarty->compile_dir = "$basepath/cache/"; $smarty->cache_dir = "$basepath/cache"; } $smarty->config_dir = "$basepath/templates/smarty/configs"; $smarty->assign("baseurl", $baseurl); $smarty->assign("templatepath","$baseurl/templates/$theme"); /* Rendering */ $routes = $settings->getRoutes(); $smarty->assign("routes", $routes); $smarty->assign("current_url", currentPageURL()); $global_settings = $settings->getMultiSettings(array("site", "facebook", "commenting", "twitter", "template", "approve_submitted_coupons", "analytics", "version", "long_description"), true); $global_settings['language'] = $default_language; $smarty->assign("language", $global_settings['language']); if (!file_exists($basepath."/language/".$global_settings['language']."/general.php")){ $global_settings['language'] = "en"; } if (!isset($global_settings['version']) || $global_settings['version'] != '1.1.0'){ require_once("includes/installer.class.php"); require_once("includes/cache.class.php"); $installer = new Installer(); $installer->upgrade("1.1.0", $db); $settings->addSetting("version", "1.1.0"); $global_settings['version'] = "1.1.0"; $cache = new Cache(); $cache->clear(); } if (!isset($global_settings['approve_submitted_coupons'])){ $global_settings['approve_submitted_coupons'] = false; } if (!isset($global_settings['site']) || !$global_settings['site']){ $global_settings['site'] = array(); } if (!isset($global_settings['site']['sitename']) || !$global_settings['site']['sitename']){ $global_settings['site']['sitename'] = "couponPHP"; } if (!isset($global_settings['site']['perpage']) || !$global_settings['site']['perpage']){ $global_settings['site']['perpage'] = 50; } if (!isset($global_settings['site']['allow_submit'])){ $global_settings['site']['allow_submit'] = true; } if (!isset($global_settings['site']['auto_approve'])){ $global_settings['site']['auto_approve'] = false; } if (!isset($global_settings['commenting']) || !$global_settings['commenting'] || empty($global_settings['commenting'])){ $global_settings['commenting'] = array("type" => "native"); } if (!isset($global_settings['template']) || !$global_settings['template'] || empty($global_settings['template'])){ $global_settings['template'] = array(); } $template_options = $settings->getThemeOptions($theme); foreach($template_options as $option_name => $option_data){ if (!isset($global_settings['template'][$option_name])){ $global_settings['template'][$option_name] = $option_data['default']; } } $css_files = $settings->getThemeCss($theme); if (count($css_files)){ foreach($css_files as $css_file){ if (defined('DEBUG') || (!file_exists($basepath."/cache/".$css_file) && file_exists($basepath."/templates/".$theme."/css/".$css_file))){ $content = file_get_contents($basepath."/templates/".$theme."/css/".$css_file); foreach($global_settings['template'] as $key => $val){ if (strpos($key, "color_") === 0){ $content = str_replace("{{".$key."}}", "#".$val, $content); } } file_put_contents($basepath."/cache/".$css_file, $content); } } } $smarty->assign("global_settings", $global_settings); $widgets = $settings->getWidgets(); $smarty->assign("widgets", $widgets); $category_tree = $category->tree(); $smarty->assign("category_tree", $category_tree); if (!isset($_REQUEST['menu']) || !$_REQUEST['menu'] || $_REQUEST['menu']=='login'){ $menu = 'home'; } else { $menu = $_REQUEST['menu']; } $menu = preg_replace("/[^a-zA-Z0-9\-_]/","",$menu); require_once($basepath."/language/".$global_settings['language']."/general.php"); if (file_exists($basepath."/language/".$global_settings['language']."/javascript.php")){ require_once($basepath."/language/".$global_settings['language']."/javascript.php"); $smarty->assign("lang_js", $lang_js); } if (file_exists($basepath."/language/".$global_settings['language']."/".$menu.".php")){ require_once($basepath."/language/".$global_settings['language']."/".$menu.".php"); } $smarty->assign("lang", $lang); $seo_replacements = array(); $seo_replacements['YEAR'] = date("Y"); $seo_replacements['MONTH'] = date("F"); if (file_exists("$menu.php")){ require_once("$menu.php"); } if (!isset($seo_data)){ $seo_data = $seo->getMetaTag("home"); } $page_menu = $page_client->getPagesMenu(); $smarty->assign("page_menu", $page_menu); $seo_replacements["SITE_NAME"] = $global_settings['site']['sitename']; foreach($seo_data as $key => $val){ foreach($seo_replacements as $replace => $replacement){ $seo_data[$key] = str_replace("%".$replace."%", $replacement, $seo_data[$key]); } } if (isset($seo_data['heading'])){ $smarty->assign("page_heading", $seo_data['heading']); } $smarty->assign("seo_data", $seo_data); $smarty->assign("menu",$menu); $featured_stores = $store->featured($global_settings['template']['featured_stores_count']); $smarty->assign("featured_stores", $featured_stores); $featured_coupons = $coupon->featured(10); $smarty->assign("featured_coupons", $featured_coupons); $top_users = $user->top($global_settings['template']['top_users_count']); $smarty->assign("top_users", $top_users); if (isset($_SESSION['user_id']) && isset($_SESSION['user_data'])){ $smarty->assign("logged_in", 1); $smarty->assign("logged_user_id", $_SESSION['user_id']); $smarty->assign("logged_user_data", $_SESSION['user_data']); $favorites = $user->favorites($_SESSION['user_id']); $smarty->assign("user_favorites", $favorites); $subscriptions = $user->getSubscriptions($_SESSION['user_data']['email'], false, true); $smarty->assign("subscriptions", $subscriptions); } else { $smarty->assign("logged_in", 0); if (isset($_SESSION['user_subscriptions'])){ $smarty->assign("subscriptions", $_SESSION['user_subscriptions']); } else { $smarty->assign("subscriptions", array()); } } $recent_deals = $coupon->recent(2, $global_settings['site']['perpage']); $smarty->assign("recent_deals", $recent_deals); $recent_coupons = $coupon->recent(1, $global_settings['site']['perpage']); $smarty->assign("recent_coupons", $recent_coupons); // scheduled tasks $runcron = false; if (!file_exists($basepath."/cache/cronlog")){ $runcron = true; } else { $crontime = filemtime($basepath."/cache/cronlog"); if (time() - $crontime >= 30*60){ $runcron = true; } } if ($runcron){ include("cron.php"); } if (isset($_REQUEST['subscription_confirmed'])){ $smarty->assign("subscription_confirmed", 1); } if (isset($_REQUEST['password_reset_user_id'])){ $smarty->assign("password_reset_user_id", $_REQUEST['password_reset_user_id']); } if (isset($_REQUEST['password_reset_hash'])){ $smarty->assign("password_reset_hash", $_REQUEST['password_reset_hash']); } $smarty->assign("rand", rand(0, 100000)); $smarty->display($menu.".tpl");