ruạṛ
<?php /** * $page_id and specials such as $page_type, $homepage, $search, $for, $four_o_four declared in calling file */ /** * @var string $includes_dir location of database connection details and global functions * @var string $template_dir location of template specific functions (and user connection details if different permissions supported) */ $data_dir = $_SERVER['DOCUMENT_ROOT'].'/admin/scripts-includes/'; $template_dir = $_SERVER['DOCUMENT_ROOT'].'/resources/template/'; /** * load includes */ require_once $data_dir.'universal.php'; require_once $template_dir.'functions.php'; /* * start the session (after includes so objects stored in $_SESSION are created properly) */ session_start(); /** * set up database connection * @var resource $connID db connection reference */ $connID=connect_to_db(); /** * suhosin workaround - load session user data * @var object $customer * @var object $cart */ $customer = user_load(); $cart = $customer->load_cart(); $bcAppend = ''; if($search) { extract(do_search()); //for $title, $description, $content $page_id = 0; $bcAppend = ' > Search'; } elseif($form) { $title = $description = 'Thank you for contacting '.SITE_FROM_NAME; $content = '<h1>Thank you for contacting '.SITE_FROM_NAME.'</h1> <p>We will reply shortly.</p>'; $page_id = 0; } elseif($sitemap) { extract(sitemap()); //for $title, $description, $content $page_id = 0; $bcAppend = ' > Sitemap'; } else { if($homepage) { if(!$page_id = select_one('page_data','page_id','index_page',1)) { echo '<html> <head><title>'.SITE_FROM_NAME.'</title></head> <body style="text-align:center"><h1>The '.SITE_FROM_NAME.' website is under Construction</h1><p>Please check back soon</p></body> </html>'; exit; } } if($four_o_four) { header("HTTP/1.0 404 Not Found"); $page_id = select_one('page_data','page_id','error_page',1); } if(!is_numeric_id($page_id, false)) { extract(goto_404()); } else { $page = mysql_query("select * from page_data where page_id = '$page_id' and active='1'"); if(!$page || mysql_num_rows($page)<1) { extract(goto_404()); } else { $p = mysql_fetch_assoc($page); mysql_free_result($page); foreach($p as $f => $v) { $$f = $v; // $title, $description, $content } if($index_page==1 || $page_id==1) { $homepage = true; } } } } $pages = build_menu_tree(); $categories = build_category_tree(); // recursive function $parent_chain = build_parent_chain($page_id); $breadcrumbs = build_breadcrumbs($parent_chain).$bcAppend; $nav = build_nav($pages,1,1,2); //$topNav = build_nav($pages,1,2,1); //$n = 0; //global for build_cat_nav() //$pnav = build_cat_nav($categories,true); // $nav2 = text_nav($pages); if($has_slideshow) { $slideshow = mysql_query("select * from image_data where image_type = 'page-slideshow' and container_id = '$page_id' and active='1' order by image_position"); } /** * buffer and send output */ switch($page_type) { //* case 'products': include 'page_type_products.php'; break; //*/ //* case 'cart': include 'page_type_cart.php'; break; //*/ //* case 'customer': case 'orders': include 'page_type_customer.php'; break; case 'reset-password': include 'page_type_password.php'; break; //*/ //* case 'blog': include 'page_type_blog.php'; break; // */ //* case 'testimonials': include 'page_type_testimonials.php'; break; // */ /* case 'files': include 'page_type_files.php'; break; //*/ /* case 'stockists': include 'page_type_stockists.php'; break; /* case 'gallery': include 'page_type_gallery.php'; break; //*/ default: //'page' /* * include buffering, header, footer in include files allows maximum flexibility for custom page types */ /* option for a fixed-content homepage if($homepage) { //fixed content include $_SERVER['DOCUMENT_ROOT'].'/index.php'; break; } //*/ ob_start(); if(!isset($_GET['popup'])) include $template_dir.'header.php'; /* * content output for a standard page */ echo db_content($content); if(!isset($_GET['popup'])) include $template_dir.'footer.php'; ob_end_flush(); mysql_query("update page_data set visited=visited+1 where page_id = '$page_id'"); } session_write_close(); exit; function do_search() { $title = 'Search the '.SITE_FROM_NAME.' website'; $description = 'Search the '.SITE_FROM_NAME.' website'; $content = '<p>Please enter a search term.</p>'; $search = clean_plain_data($_POST['search']); if($search != '') { $search_terms = explode(' ',$search); foreach($search_terms as $i => $term) { $search_terms[$i] = trim($term); } $select = "select p.*, (select 1) as q_rank from products as p where p.product_name like '%$search%' or p.short_description like '%$search%' or p.product_description like '%$search%' and active='1'"; if(count($search_terms)>1) { $select1 = ' UNION select p.*, (select 2) as q_rank from products as p where '; $select2 = ' UNION select p.*, (select 3) as q_rank from products as p where '; foreach($search_terms as $i => $t) { $select1 .= ($t != "") ? "(p.product_name like '%$term%' or p.short_description like '%$term%' or p.product_description like '%$term%') AND " : ''; $select2 .= ($t != "") ? "(p.product_name like '%$term%' or p.short_description like '%$term%' or p.product_description like '%$term%') OR " : ''; } $select1 = rtrim($select1,'AND ')."and active='1'"; $select2 = rtrim($select2,'OR ')."and active='1'"; $select .= ($select1.$select2); $select .= ' order by q_rank, product_name'; } $products = mysql_query($select); $select = "select p.*, (select 1) as q_rank from page_data as p where p.content like '%$search%' and active='1'"; if(count($search_terms)>1) { $select1 = ' UNION select p.*, (select 2) as q_rank from page_data as p where '; $select2 = ' UNION select p.*, (select 3) as q_rank from page_data as p where '; foreach($search_terms as $i => $t) { $select1 .= ($t != "") ? "p.content like '%$term%' AND " : ''; $select2 .= ($t != "") ? "p.content like '%$term%' OR " : ''; } $select1 = rtrim($select1,'AND ')."and active='1'"; $select2 = rtrim($select2,'OR ')."and active='1'"; $select .= ($select1.$select2); $select .= ' order by q_rank, title'; } $pages = mysql_query($select); $title = 'Search results for '.$search; $content = '<h1>Search results for '.stripslashes($search).'</h1>'."\n"; if(mysql_num_rows($products)<1 && mysql_num_rows($pages)<1) { $content .= '<p>No results were found. Please try a different search term.</p>'; } else { if(mysql_num_rows($products)>0) { $shown = array(); while($row = mysql_fetch_assoc($products)) { if(!in_array($p['prod_id'],$shown)) // eliminate duplicate records with different q_rank { $p =new product; $p->load_from_data($row); include 'section_product_summary.php'; $shown[] = $p['prod_id']; } } } if(mysql_num_rows($pages)>-1) { $shown = array(); while($p = mysql_fetch_assoc($pages)) { if(!in_array($p['page_id'],$shown)) // eliminate duplicate records with different q_rank { $h = ($p['title']=="") ? 'Untitled page' : $p['title']; $content .= '<h2 class="search"><a href="'.$p['path'].'">'.$h.'</a></h2>'."\n"; $extract = strip_tags(html_entity_decode($p['content'],ENT_QUOTES),'<h1>'); $extract = preg_replace(array('/<h1(.*?)>/','/<\/h1>/'),array('<b>','</b><br />'),$extract); $extract = substr($extract,0,220); $content .= '<p class="search">'.$extract.'...</p>'."\n"; $shown[] = $p['page_id']; } } } } } return compact('title','description','content'); } function sitemap() { $title = 'Sitemap - '.SITE_FROM_NAME; $description = ''; $content = '<h1>Sitemap</h1> <ul class="sitemap"> <li><a href="/" title="Home">Home</a></li> '; $pages = mysql_query("select * from page_data where active='1' order by order_id desc"); if($pages and mysql_num_rows($pages)>0) { while($p=mysql_fetch_assoc($pages)) { //exclusions $excl = array( ); if(in_array($p['page_id'],$excl)) { continue; } $content .= '<li><a href="'.$p['path'].'" title="'.$p['name'].'">'.$p['name'].'</a>'; //* if($p['page_type']=='products') { $categories = mysql_query("select * from categories where active='1' order by order_id desc"); if($categories && mysql_num_rows($categories)>0) { $content .=' <ul class="level_1"> '; while($c = mysql_fetch_assoc($categories)) { $content .= '<li><a href="'.$c['cat_path'].'" title="'.$c['cat_name'].'">'.$c['cat_name'].'</a>'; $products = mysql_query("select * from products where category_id = '{$c['cat_id']}' and active='1' order by order_id desc"); if($products && mysql_num_rows($products)>0) { $content .=' <ul class="level_2"> '; while($pr = mysql_fetch_assoc($products)) { $content .= '<li><a href="'.$pr['path'].'" title="'.$pr['product_name'].'">'.$pr['product_name'].'</a></li>'; } $content .= ' </ul> '; } $content .= '</li> '; } $content .= '</ul> '; } // endif $categories } //end if plans // */ $content .= '</li> '; } $content .= '</ul> '; } return compact('title','description','content'); } function goto_404() { global $four_o_four; // if there is not a 404 page defined = $for_o_four is set but $page_id returned false if($four_o_four) { $title = $description = 'Error 404 - page not found'; $content = htmlentities('<p>We are sorry, the page was not found at the requested address.</p>',ENT_QUOTES); return compact('title', 'description', 'content'); } header('Location: /404-error-page.php'); exit; } ?>
cải xoăn