|
@@ -1,15 +1,19 @@
|
|
<?php
|
|
<?php
|
|
class BlogPost extends DBObjectAutoCreate {
|
|
class BlogPost extends DBObjectAutoCreate {
|
|
- private $_uri;
|
|
|
|
|
|
+ const PREVIEW_LENGTH=1000;
|
|
|
|
|
|
|
|
+ private $_uri;
|
|
|
|
+
|
|
public static function GetCount() {
|
|
public static function GetCount() {
|
|
- self::SetupPDO();
|
|
|
|
- return self::$PDO->query("SELECT COUNT(*) FROM blog_posts WHERE post_deleted=0")->fetchColumn();
|
|
|
|
|
|
+ //self::SetupPDO();
|
|
|
|
+ self::CreateTable("blog_posts");
|
|
|
|
+ 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){
|
|
public static function GetLatest($count=1,$offset=0){
|
|
- self::SetupPDO();
|
|
|
|
- $prep=self::$PDO->prepare("SELECT post_id FROM blog_posts WHERE post_deleted=0 ORDER BY post_timestamp DESC LIMIT ?,?");
|
|
|
|
|
|
+ //self::SetupPDO();
|
|
|
|
+ self::CreateTable("blog_posts");
|
|
|
|
+ $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(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->bindValue(2,(int)$count,PDO::PARAM_INT);
|
|
$prep->execute();
|
|
$prep->execute();
|
|
@@ -53,23 +57,26 @@ class BlogPost extends DBObjectAutoCreate {
|
|
public function MakeUniqueURL(){
|
|
public function MakeUniqueURL(){
|
|
$baseUrl=Helper::MakeStringUrlSafe($this->PostTitle);
|
|
$baseUrl=Helper::MakeStringUrlSafe($this->PostTitle);
|
|
$prep=self::$PDO->prepare("SELECT COUNT(*) FROM blog_posts WHERE post_url=?");
|
|
$prep=self::$PDO->prepare("SELECT COUNT(*) FROM blog_posts WHERE post_url=?");
|
|
- $found=false;
|
|
|
|
|
|
+ $found=(int)$prep->fetchColumn()>0;;
|
|
$url=$baseUrl;
|
|
$url=$baseUrl;
|
|
$count=0;
|
|
$count=0;
|
|
- do {
|
|
|
|
|
|
+ while($found) {
|
|
$prep->execute(array($url));
|
|
$prep->execute(array($url));
|
|
$found=(int)$prep->fetchColumn()>0;
|
|
$found=(int)$prep->fetchColumn()>0;
|
|
if ($found){
|
|
if ($found){
|
|
$count++;
|
|
$count++;
|
|
$url=$baseUrl.'-'.$count;
|
|
$url=$baseUrl.'-'.$count;
|
|
}
|
|
}
|
|
- } while ($found);
|
|
|
|
|
|
+ }
|
|
$this->PostUrl=$url;
|
|
$this->PostUrl=$url;
|
|
}
|
|
}
|
|
|
|
|
|
public function GetPostPreview() {
|
|
public function GetPostPreview() {
|
|
- return $this->PostDraft;
|
|
|
|
-// /return $this->PostContent;
|
|
|
|
|
|
+ $content=$this->PostContent;
|
|
|
|
+ $pTagPos=strpos($content,"</p>",self::PREVIEW_LENGTH);
|
|
|
|
+ $content=substr($content, 0, $pTagPos);
|
|
|
|
+ $content=Helper::CloseOpenTags($content);
|
|
|
|
+ return $content;
|
|
}
|
|
}
|
|
|
|
|
|
public function GetURI() {
|
|
public function GetURI() {
|