Advertisement
Tyler_Elric

lib/blog.php

Nov 6th, 2012
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.82 KB | None | 0 0
  1. <?php
  2. require_once "database.php";
  3. /* Blog System */
  4.  
  5. class Blog
  6. {
  7.  
  8.     private $databaseName = "blog";
  9.    
  10.     function __construct($app=null)
  11.     {
  12.         $this->app = $app;
  13.     }
  14.    
  15.     function tags($postID=null)
  16.     {
  17.         $ret = array();
  18.         $con = DatabaseConnect(1);
  19.         if($postID!==null)
  20.         {
  21.             $query = "Select tag from {$this->databaseName}.post_tags where post=".mysql_real_escape_string($postID);
  22.             $result = mysql_query($query,$con);
  23.             while($row = mysql_fetch_array($result))
  24.                 array_push($ret,$row['tag']);
  25.         }
  26.         else
  27.         {
  28.             $query = "Select tag,quantity from {$this->databaseName}.popularblogtags";
  29.             $result = mysql_query($query,$con);
  30.             while($row = mysql_fetch_array($result))
  31.                 array_push($ret,array(
  32.                     'tag' => $row['tag'],
  33.                     'quantity' => $row['quantity']
  34.                 ));
  35.         }
  36.         return $ret;
  37.     }
  38.     function posts($conditions="true")
  39.     {
  40.         $con = DatabaseConnect(1);
  41.         $query = "select * from {$this->databaseName}.posts where true and($conditions)";
  42.         $result = mysql_query($query,$con) or die(mysql_error());
  43.         $ret = array();
  44.         while($row = mysql_fetch_array($result))
  45.             array_push($ret,array(
  46.                 'id' => $row['id'],
  47.                 'title' => $row['title'],
  48.                 'content' => $row['content'],
  49.                 'description' => $row['description'],
  50.                 'modified' => strtotime($row['modified']),
  51.                 'meta' => array(
  52.                     'tag' => $this->tags($row['id']),
  53.                     'date' => $row['modified'],
  54.                     'author' => $row['author']
  55.                 ),
  56.                 'type' => $row['sticky']==0?'post':'page'
  57.             ));
  58.         return $ret;
  59.     }
  60.     function authors($conditions="true")
  61.     {
  62.         $con = DatabaseConnect(1);
  63.         $query = "Select distinct author from {$this->databaseName}.posts where true and ($conditions)";
  64.         $result = mysql_query($query,$con);
  65.         $ret = array();
  66.         while($row = mysql_fetch_array($result))
  67.             array_push($ret,$row['author']);
  68.         return $ret;
  69.     }
  70. }
  71.  
  72. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement