Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require "smarty/libs/Smarty.class.php";
- $smarty = new Smarty;
- $smarty->setTemplateDir('templates');
- $smarty->setCompileDir('templates_c');
- $smarty->setCacheDir('cache');
- $smarty->setConfigDir('configs');
- $conn = new PDO("mysql:host=localhost;dbname=majician_blog", "majician_blog", "8VHWqAbx7O6f");
- $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
- $output = ""; //page output
- $sub_title = ""; //page title
- $nav = array(); //navigation
- //if no page is specified set default
- if(empty($_GET['page'])){
- $page = 'sitenews';
- } else {
- $page = $_GET['page'];
- }
- //build the navigation
- $query = $conn->query("SELECT `title`, `url` FROM `chyrp_pages`");
- $query->setFetchMode(PDO::FETCH_ASSOC);
- while($links = $query->fetch()){
- $nav[] = array('text'=>$links['title'], 'href'=>"/static/{$links['url']}.html");
- }
- $smarty->assign('navigation', $nav);
- $smarty->assign('isDynamic', false);
- //get page data
- switch($page) {
- case 'siteblog';
- case 'sitenews';
- switch($page){
- case 'siteblog': //set table prefixes and URL root
- $prefix = "blog_";
- $uroot = "siteblog";
- break;
- Case 'sitenews':
- $prefix = "chyrp_";
- $uroot = "sitenews";
- break;
- }
- if (($_GET['view'] == "latest") || (empty($_GET['view']))) {
- $query = $conn->query("SELECT * FROM `{$prefix}posts` ORDER BY `created_at` DESC");
- $query->setFetchMode(PDO::FETCH_ASSOC);
- $entries = array();
- while($posts = $query->fetch()){
- //assemble title
- $query = $conn->query("SELECT `value` FROM `{$prefix}post_attributes` WHERE `post_id`='{$posts['id']}' AND `name`='title'");
- $query->setFetchMode(PDO::FETCH_ASSOC);
- $title = $query->fetch();
- //assemble body
- $query = $conn->query("SELECT `value` FROM `{$prefix}post_attributes` WHERE `post_id`='{$posts['id']}' AND `name`='body'");
- $query->setFetchMode(PDO::FETCH_ASSOC);
- $title = $query->fetch();
- $entries[] = array(
- 'title' => $title['value'],
- 'body' => substr($body['value'],0,250),
- 'article_link' => "{$uroot}/more/{$posts['url']}.html",
- 'pdate' => $posts['created_at']
- );
- }
- $smarty->assign('posts', $entries);
- $smarty->assign('title', 'David Scherer');
- $smarty->assign('isDynamic', true);
- } else if (($_GET['view'] == "more") && !(empty($_GET['view']))) {
- //fetch main entry
- $query = $conn->query("SELECT * FROM `{$prefix}posts` WHERE `url`='{$_GET['rough']}'");
- $query->setFetchMode(PDO::FETCH_ASSOC);
- $result = $query->fetch();
- //fetch title and start output build
- $query = $conn->query("SELECT `value` FROM `{$prefix}post_attributes` WHERE `post_id`='{$result['id']}' AND `name`='title'");
- $query->setFetchMode(PDO::FETCH_ASSOC);
- $title = $query->fetch();
- $smarty->assign('title', $title['value']);
- //fetch body and finish output build
- $query = $conn->query("SELECT `value` FROM `{$prefix}post_attributes` WHERE `post_id`='{$result['id']}' AND `name`='body'");
- $query->setFetchMode(PDO::FETCH_ASSOC);
- $body = $query->fetch();
- $smarty->assign('body', $body['value']);
- $smarty->assign('pdate', $posts['created_at']);
- $show_comments = ($page === 'siteblog') ? true : false;
- $smarty->assign('showComments', $show_comments);
- } else {
- $sub_title = "Error - Page Not Found";
- $timestamp = time();
- $ip = Getenv("REMOTE_ADDR");
- foreach ($_GET as $key => $value){
- $query = $conn->prepare("INSERT INTO `site_errors` VALUES ('','?','?','?','?')");
- $data = array('', $key, $value, $ip, $timestamp);
- $query->execute($data);
- }
- $output = "<div id='post-error' class='post'><h1 class='ptitle'><span>Error: 101</span></h1><div class='pinfo'>Page not found error. EID: {$timestamp}</div><div class='pcontent'><p>The page you are looking for could not be found. Try re-typing or copy-pasting the URL again. Additionally, if you followed this link from another page, the page may have been moved, removed, or no longer here. You could try searching this site, or reporting the broken link to the Webmaster of the site you were at.</p></div></div>";
- $smarty->assign('title', 'Error101');
- $smarty->assign('body', "The page you are looking for could not be found. Try re-typing or copy-pasting the URL again. Additionally, if you followed this link from another page, the page may have been moved, removed, or no longer here. You could try searching this site, or reporting the broken link to the Webmaster of the site you were at.");
- $smarty->assign('pdate', "Page not found error. EID: {$timestamp}");
- }
- break;
- default:
- $query = $conn->query("SELECT * FROM `chyrp_pages` WHERE `url`='{$page}'");
- $query->setFetchMode(PDO::FETCH_ASSOC);
- $result = $query->fetch();
- $timestamp = time(); //error logging
- $ip = Getenv("REMOTE_ADDR"); //error logging
- //check to make sure we got a result
- $sub_title = (!empty($result['title'])) ? $result['title'] : "Error - Page Not Found";
- $output = (!empty($result['body'])) ? $result['body'] : "<div id='post-error' class='post'><h1 class='ptitle'><span>Error: 101</span></h1><div class='pinfo'>Page not found error. EID: {$timestamp}</div><div class='pcontent'><p>The page you are looking for could not be found. Try re-typing or copy-pasting the URL again. Additionally, if you followed this link from another page, the page may have been moved, removed, or no longer here. You could try searching this site, or reporting the broken link to the Webmaster of the site you were at.</p></div></div>";
- $output = (!empty($result['body'])) ? $result['body'] : "<p>The page you are looking for could not be found. Try re-typing or copy-pasting the URL again. Additionally, if you followed this link from another page, the page may have been moved, removed, or no longer here. You could try searching this site, or reporting the broken link to the Webmaster of the site you were at.";
- $smarty->assign('title', $sub_title);
- $smarty->assign('body', $output);
- //if there's no result, log the error for abuse
- if ($sub_title === "Error - Page Not Found") {
- $smarty->assign('pdate', "Page not found error. EID: {$timestamp}");
- foreach ($_GET as $key => $value){
- $query = $conn->prepare("INSERT INTO `site_errors` VALUES ('','?','?','?','?')");
- $data = array('', $key, $value, $ip, $timestamp);
- $query->execute($data);
- }
- }
- break;
- //echo $output;
- }
- $smarty->display('templates/index.tpl');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement