Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.11 KB | None | 0 0
  1. <?php
  2.  
  3. require "smarty/libs/Smarty.class.php";
  4.  
  5. $smarty = new Smarty;
  6.  
  7. $smarty->setTemplateDir('templates');
  8. $smarty->setCompileDir('templates_c');
  9. $smarty->setCacheDir('cache');
  10. $smarty->setConfigDir('configs');
  11.  
  12. $conn = new PDO("mysql:host=localhost;dbname=majician_blog", "majician_blog", "8VHWqAbx7O6f");
  13. $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  14.  
  15. $output = "";     //page output
  16. $sub_title = "";  //page title
  17. $nav = array();        //navigation
  18.  
  19. //if no page is specified set default
  20. if(empty($_GET['page'])){
  21.  
  22.   $page = 'sitenews';
  23.  
  24. } else {
  25.  
  26.   $page = $_GET['page'];
  27.  
  28. }
  29.  
  30. //build the navigation
  31. $query = $conn->query("SELECT `title`, `url` FROM `chyrp_pages`");
  32. $query->setFetchMode(PDO::FETCH_ASSOC);
  33.  
  34. while($links = $query->fetch()){
  35.  
  36.   $nav[] = array('text'=>$links['title'], 'href'=>"/static/{$links['url']}.html");
  37.  
  38. }
  39.  
  40. $smarty->assign('navigation', $nav);
  41. $smarty->assign('isDynamic', false);
  42.  
  43. //get page data
  44. switch($page) {
  45.  
  46.   case 'siteblog';
  47.   case 'sitenews';
  48.  
  49.     switch($page){
  50.    
  51.       case 'siteblog': //set table prefixes and URL root
  52.         $prefix = "blog_";
  53.         $uroot = "siteblog";
  54.         break;
  55.       Case 'sitenews':
  56.         $prefix = "chyrp_";
  57.         $uroot = "sitenews";
  58.         break;  
  59.    
  60.     }
  61.  
  62.     if (($_GET['view'] == "latest") || (empty($_GET['view']))) {
  63.    
  64.       $query = $conn->query("SELECT * FROM `{$prefix}posts` ORDER BY `created_at` DESC");
  65.       $query->setFetchMode(PDO::FETCH_ASSOC);
  66.      
  67.       $entries = array();
  68.    
  69.       while($posts = $query->fetch()){
  70.        
  71.         //assemble title
  72.         $query = $conn->query("SELECT `value` FROM `{$prefix}post_attributes` WHERE `post_id`='{$posts['id']}' AND `name`='title'");
  73.         $query->setFetchMode(PDO::FETCH_ASSOC);
  74.         $title = $query->fetch();
  75.          
  76.         //assemble body
  77.         $query = $conn->query("SELECT `value` FROM `{$prefix}post_attributes` WHERE `post_id`='{$posts['id']}' AND `name`='body'");
  78.         $query->setFetchMode(PDO::FETCH_ASSOC);
  79.         $title = $query->fetch();
  80.        
  81.         $entries[] = array(
  82.                                    'title' => $title['value'],
  83.                                    'body' => substr($body['value'],0,250),
  84.                                    'article_link' => "{$uroot}/more/{$posts['url']}.html",
  85.                                    'pdate' => $posts['created_at']
  86.                                );
  87.                                
  88.      
  89.       }
  90.  
  91.       $smarty->assign('posts', $entries);
  92.       $smarty->assign('title', 'David Scherer');
  93.       $smarty->assign('isDynamic', true);
  94.    
  95.     } else if (($_GET['view'] == "more") && !(empty($_GET['view']))) {
  96.    
  97.       //fetch main entry
  98.       $query = $conn->query("SELECT * FROM `{$prefix}posts` WHERE `url`='{$_GET['rough']}'");
  99.       $query->setFetchMode(PDO::FETCH_ASSOC);
  100.       $result = $query->fetch();
  101.      
  102.       //fetch title and start output build
  103.       $query = $conn->query("SELECT `value` FROM `{$prefix}post_attributes` WHERE `post_id`='{$result['id']}' AND `name`='title'");
  104.       $query->setFetchMode(PDO::FETCH_ASSOC);
  105.       $title = $query->fetch();
  106.       $smarty->assign('title', $title['value']);
  107.      
  108.       //fetch body and finish output build
  109.       $query = $conn->query("SELECT `value` FROM `{$prefix}post_attributes` WHERE `post_id`='{$result['id']}' AND `name`='body'");
  110.       $query->setFetchMode(PDO::FETCH_ASSOC);
  111.       $body = $query->fetch();
  112.      
  113.       $smarty->assign('body', $body['value']);
  114.       $smarty->assign('pdate', $posts['created_at']);
  115.      
  116.       $show_comments = ($page === 'siteblog') ? true : false;
  117.       $smarty->assign('showComments', $show_comments);
  118.    
  119.     } else {
  120.    
  121.       $sub_title = "Error - Page Not Found";
  122.      
  123.       $timestamp = time();
  124.       $ip = Getenv("REMOTE_ADDR");
  125.      
  126.       foreach ($_GET as $key => $value){
  127.        
  128.         $query = $conn->prepare("INSERT INTO `site_errors` VALUES ('','?','?','?','?')");
  129.         $data = array('', $key, $value, $ip, $timestamp);
  130.         $query->execute($data);
  131.        
  132.       }
  133.      
  134.       $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>";
  135.       $smarty->assign('title', 'Error101');
  136.       $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.");
  137.       $smarty->assign('pdate', "Page not found error. EID: {$timestamp}");
  138.      
  139.          
  140.     }
  141.   break;
  142.    
  143.   default:
  144.    
  145.     $query = $conn->query("SELECT * FROM `chyrp_pages` WHERE `url`='{$page}'");
  146.     $query->setFetchMode(PDO::FETCH_ASSOC);
  147.     $result = $query->fetch();
  148.    
  149.     $timestamp = time();          //error logging
  150.     $ip = Getenv("REMOTE_ADDR");  //error logging
  151.    
  152.     //check to make sure we got a result
  153.     $sub_title = (!empty($result['title'])) ? $result['title'] : "Error - Page Not Found";
  154.     $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>";
  155.     $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.";
  156.    
  157.     $smarty->assign('title', $sub_title);
  158.     $smarty->assign('body', $output);
  159.    
  160.     //if there's no result, log the error for abuse
  161.     if ($sub_title === "Error - Page Not Found") {
  162.    
  163.       $smarty->assign('pdate', "Page not found error. EID: {$timestamp}");
  164.    
  165.       foreach ($_GET as $key => $value){  
  166.        
  167.         $query = $conn->prepare("INSERT INTO `site_errors` VALUES ('','?','?','?','?')");
  168.         $data = array('', $key, $value, $ip, $timestamp);
  169.         $query->execute($data);
  170.        
  171.       }
  172.    
  173.     }
  174.    
  175.   break;
  176.  
  177.    //echo $output;
  178. }
  179.  
  180. $smarty->display('templates/index.tpl');
  181.  
  182. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement