【php开源代码栏目提醒】:以下是网学会员为您推荐的php开源代码-class.BlogEntry.php,希望本篇文章对您学习有所帮助。
<?php
include_once("lib.php");
class BlogEntry {
// member variables
var $entryId; //blog_entries.compat_entry_id
var $entryBlogId; // blog_list.id
var $entryBlogTabeName; // the table the blog entry came from.
var $entryBody; //blog_name.body
var $entryDate; //blog_name.date
var $formattedEntryDate; //blog_name.date
var $entryUserId; // blog_name.userid
var $entryAuthorName; // blog_users.name
var $entryAuthorEmail; // blog_users.email
var $entryTitle; // blog_name.title
var $entryKarma; // blog_name.karma
var $entryFormat; // blog_name.format
var $entryCategoryId; // blog_name.cat_id
var $entryCategoryName; // blog_name.cat_id -> blog_categories.cat_id
var $entryURL; // the archive URL to this blog entry.
var $entryCommentsURL; // the url where comments for this item are stored.
var $entryRSSURL; // the url of the RSS 0.91 feed containing this item.
var $entryRSS2URL; // the url of the RSS 2.0 feed containing this item.
// use variable names directly to access properties.
// constructor that will build a new instance of the object
// when given a reference to a result set object that points
// to a row from the blog_name table.
function BlogEntry($resultSet) {
global $db;
global $baseurl;
global $dateformat;
$this->entryTableName = $tableName;
$this->entryId = $resultSet->fields['blog_entry_id'];
$this->entryBody = ereg_replace("<tick>","'",$resultSet->fields['body']);
$this->entryDate = $resultSet->fields['date'];
$this->formattedEntryDate = date($dateformat, strtotime($resultSet->fields['date']));
$this->entryUserId = $resultSet->fields['userid'];
$this->entryTitle = ereg_replace("<tick>","'",$resultSet->fields['title']);
$this->entryKarma = $resultSet->fields['karma'];
$this->entryFormat = $resultSet->fields['format'];
$this->entryCategoryId = $resultSet->fields['cat_id'];
// need to get the email address of the author.
$sql="select * from blog_users where id=$this->entryUserId";
$rs = $db->Execute($sql);
$this->entryAuthorName = $rs->fields['name'];
$this->entryAuthorEmail = $rs->fields['email'];
// then the category
$sql = "select * from blog_categories where cat_id=$this->entryCategoryId";
$rs = $db->Execute($sql);
$this->entryCategoryName = $rs->fields['cat_name'];
// the blog id.
$this->entryBlogId = $resultSet->fields['blog_id'];
// configure the URL for this entry
$this->entryURL = "$baseurl/archive.php?blogid=$this->entryBlogId&pid=$this->entryId";
// then the comments URL...
$this->entryCommentsURL = "$baseurl/comments.php?blogid=$this->entryBlogId&pid=$this->entryId";
// and then the source URL (points to the RSS feed containing this item)
$this->entryRSSURL = "$baseurl/rss.php?blogid=$this->entryBlogId";
$this->entryRSS2URL = "$baseurl/rss2.php?blogid=$this->entryBlogId";
}
function delete() {
global $db;
$sql = "delete from blog_entries where blog_id = $this->entryBlogId and blog_entry_id = $this->entryId";
$db->Execute($
sql);
return true;
}
function update ($title, $body, $formatId, $categoryId) {
global $db;
// generate the modification date
$updateDate = strftime("%Y-%m-%d %H:%M:%S");
$sql = "update blog_entries set body = '$body', title = '$title', date = '$updateDate', format = $formatId, cat_id = $categoryId where blog_id = $this->entryBlogId and blog_entry_id = $this->entryId";
$db->Execute($sql);
return true;
}
function getCommentCount() {
global $db;
$sql = "select count(*) as count from blog_comments where bid='$this->entryBlogId' and eid='$this->entryId'";
$res = $db->Execute($sql);
return $res->fields['count'];
}
function getCmntLink($useCommentWindow, $templateId) {
global $baseurl;
if($useCommentWindow) {
$href= "javascript: openComments('$baseurl','$this->entryBlogId','$this->entryId','$templateId');";
} else {
$href = "$this->entryCommentsURL";
}
$str = "<a href=\"$href\">";
#get number of comments from DB
$commentCount = $this->getCommentCount();
if($commentCount == 0) {
$str .= "评论?";
} else {
$str .= $commentCount." 评论";
}
$str .= "</a>";
return $str;
}
function getFormattedKarmaLink() {
global $ratename, $baseurl;
$str = "$ratename: ";
$str .= $this->entryKarma." ( <a href=\"$baseurl/karma.php?op=add&blogid=$this->entryBlogId&pid=$this->entryId\">+</a> / <a href=\"$baseurl/karma.php?op=sub&blogid=$this->entryBlogId&pid=$this->entryId\">-</a> )";
return $str;
}
f