|
@@ -2,8 +2,38 @@
|
|
|
ApplicationSettings::RegisterDefaultSetting("blog", "preview_length", 1000);
|
|
|
|
|
|
class BlogPost extends DBObject {
|
|
|
+ //const PREVIEW_LENGTH=1000;
|
|
|
+
|
|
|
private $_uri;
|
|
|
|
|
|
+ public static function GetCount() {
|
|
|
+ //self::SetupPDO();
|
|
|
+ return self::$PDO->query("SELECT COUNT(*) FROM blog_posts WHERE post_content<>'' AND post_deleted=0")->fetchColumn();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function GetLatest($count=1,$offset=0){
|
|
|
+ //self::SetupPDO();
|
|
|
+ $prep=self::$PDO->prepare("SELECT post_id FROM blog_posts WHERE post_content<>'' AND post_deleted=0 ORDER BY post_timestamp DESC LIMIT ?,?");
|
|
|
+ $prep->bindValue(1,(int)$offset,PDO::PARAM_INT); // can't just use array in execute this time as execute array is treated like strings
|
|
|
+ $prep->bindValue(2,(int)$count,PDO::PARAM_INT);
|
|
|
+ $prep->execute();
|
|
|
+ $ids=$prep->fetchAll(PDO::FETCH_COLUMN);
|
|
|
+ $posts=array();
|
|
|
+ foreach ($ids as $id)
|
|
|
+ $posts[]=new BlogPost($id);
|
|
|
+ return $posts;
|
|
|
+ //return new BlogPost($url);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function GetAll(){
|
|
|
+ $posts=array();
|
|
|
+ self::SetupPDO();
|
|
|
+ $ids=self::$PDO->query("SELECT post_id FROM blog_posts WHERE post_deleted=0")->fetchAll(PDO::FETCH_COLUMN);
|
|
|
+ foreach ($ids as $id)
|
|
|
+ $posts[]=new BlogPost($id);
|
|
|
+ return $posts;
|
|
|
+ }
|
|
|
+
|
|
|
public function __construct($id=0) {
|
|
|
$field="post_id";
|
|
|
if (!is_numeric($id))
|