【php开源代码栏目提醒】:网学会员为需要php开源代码的朋友们搜集整理了class.BlogInfo.php相关资料,希望对各位网友有所帮助!
<?php
include_once("lib.php");
include_once("class.BlogEntry.php");
include_once("class.BlogUser.php");
class BlogInfo {
// private variables
var $blogId; // blog_list.blog_id
var $blogTitle; // blog_list.title
var $blogTagline; //blog_list.tagline
var $blogAdminUserId; // blog_list.admin
var $blogAdminName; // blog_list.admin -> blog_users.name
var $blogAdminEmail; // blog_list.admin -> blog_users.email
var $blogAdminURL; // blog_list.admin -> blog_users.url
var $blogUsers = array(); // list of BlogUser objects with access to this blog
var $blogURL; // the url where this blog can be reached.
var $blogTemplateId; // id of the template being used for this blog.
var $blogEntries; // an array of entries for this blog. empty by default.
// constructor- used to create the BlogInfo instance
// and populate it with information about the blog.
function BlogInfo ($blogId) {
global $db;
global $baseurl;
global $blogurl;
// general info.
$res = $db->Execute("select * from blog_list where blog_id=$blogId");
$this->blogId = $blogId;
$this->blogTitle = $res->fields['title'];
$this->blogTagline = $res->fields['tagline'];
$this->blogTemplateId = $res->fields['temp_id'];
$this->blogAdminUserId = $res->fields['admin'];
// list of authorized users.
$blogUsers = array();
$res = $db->Execute("select ba.user_id as user_id, ba.admin as admin, bu.login as login, bu.name as name, bu.email as email from blog_acl ba, blog_users bu where ba.blog_id=$blogId and ba.user_id = bu.id");
while (!$res->EOF) {
$blogUsers[] =& new BlogUser($res->fields['user_id'], $res->fields['login'],
$res->fields['email'], $res->fields['name'],
$res->fields['admin']);
$res->MoveNext();
}
$this->blogUsers = $blogUsers;
// build the blog URL, assuming the demo.php page is
$this->blogURL = "$blogurl?blogid=$blogId";
// get the admin user info fields.
$sql = "select * from blog_users where id=$this->blogAdminUserId";
$rs = $db->Execute($sql);
$this->blogAdminName = $rs->fields['name'];
$this->blogAdminEmail = $rs->fields['email'];
$this->blogAdminURL = $rs->fields['url'];
}
// getters and setters
function getBlogId() {
return $this->blogId;
}
// no setter for blog_id, it is immutable.
function getBlogTitle() {
return $this->blogTitle;
}
function setBlogTitle($title) {
global $db;
$sql = "update blog_list set title='$title' where blog_id=$this->blogId";
if ($db->Execute($sql) === true) {
// the update was successful
$this->blogTitle = $title;
}
}
function getBlogTagline() {
return $this->blogTagline;
}
function setBlogTagline($tag) {
global $db;
$sql = "update blog_list set tagline='$tag' where blog_id=$this->blogId";
if ($db->Execute($sql) === true) {
// the update was successful
$this->blogTagline = $tag;
}
}
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 = $this->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 blog_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 $blogEntry;
}
// this will remove the blog entry. this will
// perform any of the security checks necessary to ensure that the
// user is authorized to remove the entry. It will return false
// if there was an error trying to delete the entry.
function deleteBlogEntryById($entryId) {
// figure out who the currently logged in user is.
$uid = getUID($_SESSION['login']);
// retrieve the entry.
$blogEntry = $this->getBlogEntryById($entryId);
if (($uid == $blogEntry->entryUserId) or (isBlogAdmin($this->blogId)) or (isAdmin())) {
// yes, they are authorized, so remove the entry.
if ( $blogEntry->delete() ) {
return true;
}
}
// must not have worked...
return false;
}
// this funciton will update the selected blog entry after performing
// security checks to make sure the user is authorized to perform the update.
function updateBlogEntryById($entryId, $title, $body, $formatId, $categoryId) {
// figure out who the currently logged in user is.
$uid = getUID($_SESSION['login']);
$title = escape($title);
$body = escape ($body);
// retrieve the entry
$blogEntry = $this->getBlogEntryById($entryId);
if (($uid == $blogEntry->entryUserId) or (isBlogAdmin($this->blogId)) or (isAdmin())) {
// yes, they are authorized, so remove the entry.
if ( $blogEntry->update($title, $body, $formatId, $categoryId) ) {
return true;
}
}
// must not have worked...
return false;
}
// this will return those blog entries that
// match all of the criteria that were submitted. This is
// primarily used by archive.php
function getBlogEntriesByCriteria($keyword, $entryId, $categoryId, $date, $eid=0) {
global $db;
$sql = "select * from blog_entries where blog_id = $this->blogId ";
if ( !empty($keyword) ) {
$sql .= " and title LIKE '%$keyword%' OR body LIKE '%$keyword%' ";
}
if ( !empty($entryId) ) {
$sql .= " and blog_entry_id = $entryId ";
} elseif($eid) {
$sql .= " and compat_entry_id = $eid ";
}
if ( !empty($categoryId) ) {
$sql .= " and cat_id = $categoryId ";
}
if ( !empty($date) ) {
$sql .= " and date like '$date%' ";
}
$sql .= " order by blog_entry_id DESC ";
$rs = $db->Execute($sql);
if (!$rs) {
// nothing in result set. return empty array.
return array();
} else {
$blogEntries = array();
while (!$rs->EOF) {
$blogEntry = new BlogEntry($rs, $this->blogTableName, $this->blogId);
$blogEntries[] = $blogEntry;
$rs->MoveNext();
}
上一篇:
class.BlogEntry.php
下一篇:
行走梵净山之(三)一世一遇,即是懂得