【php开源代码栏目提醒】:网学会员,鉴于大家对php开源代码十分关注,论文会员在此为大家搜集整理了“class.BlogServer.php”一文,供大家参考学习!
<?php
include_once("lib.php");
include_once("class.BlogInfo.php");
class BlogServer {
// private variables
var $blogInfoList; // an array of $blogInfo objects.
// constructor.
function BlogServer () {
global $db;
// let's get the list of blogs_id's that we can pass to the constructor
// of class.BlogInfo to generate our list of BlogInfo objects.
$sql = "select blog_id from blog_list";
$res = $db->Execute($sql);
while (!$res->EOF) {
$blogId = $res->fields['blog_id'];
$blogInfoList[] =& new BlogInfo($blogId);
$res->MoveNext();
}
}
// getters and setters
function &getBlogInfoList() {
return $this->blogInfoList;
}
function getBlogInfoById($blogId) {
foreach ($this->blogInfoList as $blogInfo) {
if ($blogInfo->blogId == $blogId) {
return $blogInfo;
}
}
return NULL;
}
function &createBlog($blogTitle, $tagline, $type, $userList, $admin) {
global $db;
// this is so NOT transactionally correct!! FIXME.
$sql = "select max(blog_id) as blog_id from blog_list";
$res = $db->Execute($sql);
$newBlogId = $res->fields['blog_id'] + 1;
$sql = "insert into blog_list (blog_id,title,type_id,tagline,admin) values ($newBlogId,'".escape($blogTitle)."',$type,'".escape($tagline)."',$admin)";
$res = $db->Execute($sql);
$sql = "insert into blog_categories (cat_name,blog_id) values ('General',$newBlogId)";
$res = $db->Execute($sql);
foreach ($userList as $userId) {
$sql = "insert into blog_acl (user_id,blog_id) values ($userId,$newBlogId)";
$res = $db->Execute($sql);
}
$blogInfo =& new BlogInfo($newBlogId);
return $blogInfo;
}
function deleteBlogById($blogId) {
global $db;
$sql = "select * from blog_entries where blog_id=$blogId";
$rs = $db->Execute($sql);
while (!$rs->EOF) {
$sql = "delete from blog_trackback where entry_id=".$rs->fields['blog_entry_id'];
$res2 = $db->Execute($sql);
$sql = "delete from blog_pingback where entry_id=".$rs->fields['blog_entry_id'];
$res2 = $db->Execute($sql);
$rs->MoveNext();
}
$sql = "delete from blog_list where blog_id=$blogId";
$res2 = $db->Execute($sql);
$sql = "delete from blog_acl where blog_id=$blogId";
$res2 = $db->Execute($sql);
$sql = "delete from blog_entries where blog_id=$blogId";
$res2 = $db->Execute($
sql);
$sql = "delete from blog_karma where bid=$blogId";
$res2 = $db->Execute($sql);
$sql = "delete from blog_comments where bid=$blogId";
$res2 = $db->Execute($sql);
$sql = "delete from blog_categories where blog_id=$blogId";
$res2 = $db->Execute($sql);
$sql = "delete from blog_blocks where blog_id=$blogId";
$res2 = $db->Execute($sql);
}
// This should probably be conisdered deprecated, now that
// blog data is primarily stored in the blog_entries table.
function getBlogTableName() {
return $this->blogTableName;
}
// no setter for table name.
function getBlogURL() {
return $this->blogURL;
}
// no setter for blog URL, as there is no place to put it.
// it would be nice to upgrade the blog_list table to include
// the blog_url.
function getLastUpdate() {
return $this->lastUpdate;
}
// no setter for last update.
function getBlogTemplateId() {
return $this->blogTemplateId;
}
// more full featured version...
function getBlogTemplate() {
global $db;
$sql = "select template from blog_template where temp_id = $this->blogTemplateId";
$rs = $db->Execute($sql);
return $rs->fields['template'];
}
// no setter for blog template id.
function getBlogAdminName() {
return $this->blogAdminName;
}
function getBlogAdminEmail() {
return $this->blogAdminEmail;
}
function getBlogAdminURL() {
return $this->blogAdminURL;
}
function getBlogUsers() {
return $this->blogUsers;
}
// return the timestamp when this blog was last updated.
#function getLastUpdate() {
// last updated.
# global $db;
# $res = $db->Execute("select max(date) as date from blog_entries where blog_id = $blogId");
# return date("r", strtotime($res->fields['date']));
#}
// use this function to get a single numbered BlogEntry object
// for this blog.
function getBlogEntryById($entryId) {
global $db;
// the sql to grab the speicific entry.
$sql = "select * from blog_entries where compat_entry_id=$entryId and blog_id = $this->blogId";
$rs = $db->Execute($sql);
// may have zero entries. in that case, return null.
if (!$rs) {
// the result set is empty. return null.
return null;
} else {
if (!$rs->EOF) {
// create the new blog entry object...
$blogEntry = new BlogEntry($rs);
}
}
return $blogE