Source for file BitBlog.php
Documentation is available at BitBlog.php
require_once( BLOGS_PKG_PATH. 'BitBlogPost.php');
require_once( LIBERTY_PKG_PATH. 'LibertyComment.php');
define( 'BITBLOG_CONTENT_TYPE_GUID', 'bitblog' );
function BitBlog( $pBlogId= NULL, $pContentId= NULL ) {
parent::__construct( $pContentId );
'content_name' => 'Blog',
'handler_class' => 'BitBlog',
'handler_package' => 'blogs',
'handler_file' => 'BitBlog.php',
'maintainer_url' => 'http://www.bitweaver.org'
$sql = "SELECT COUNT(*) FROM `". BIT_DB_PREFIX. "blogs` WHERE `user_id` = ?";
$ret = $this->mDb->getOne($sql, array( $user_id ));
if ( BitBase::verifyId( $pParamHash['blog_id'] ) ) {
if( $gBitSystem->isFeatureActive( 'pretty_urls_extended' ) ) {
$ret = BLOGS_PKG_URL. 'view/'. $pParamHash['blog_id'];
} elseif( $gBitSystem->isFeatureActive( 'pretty_urls' ) ) {
$ret = BLOGS_PKG_URL. $pParamHash['blog_id'];
$ret = BLOGS_PKG_URL. 'view.php?blog_id='. $pParamHash['blog_id'];
$ret = parent::getDisplayUrlFromHash( $pParamHash );
$hash = array ( 'blog_id' => $this->mBlogId );
$ret = self::getDisplayUrlFromHash( $hash );
* Check if there is an article loaded
* @return bool TRUE on success, FALSE on failure
function load( $pContentId = NULL, $pPluginParams = NULL ) {
function getBlog( $pBlogId, $pContentId = NULL ) {
$lookupId = (!empty( $pBlogId ) ? $pBlogId : $pContentId);
$lookupColumn = (!empty( $pBlogId ) ? 'blog_id' : 'content_id');
$bindVars = array( (int) $lookupId );
$selectSql = ''; $joinSql = ''; $whereSql = '';
$this->getServicesSql( 'content_load_sql_function', $selectSql, $joinSql, $whereSql, $bindVars );
if ( BitBase::verifyId( $lookupId ) ) {
SELECT b.*, lc.*, lch.`hits`, uu.`login`, uu.`login`, uu.`user_id`, uu.`real_name`,
lfa.`file_name` as `avatar_file_name`, lfa.`mime_type` AS `avatar_mime_type`, laa.`attachment_id` AS `avatar_attachment_id`,
lfp.`file_name` AS `image_file_name`, lfp.`mime_type` AS `image_mime_type`, lap.`attachment_id` AS `image_attachment_id`
INNER JOIN `". BIT_DB_PREFIX. "liberty_content` lc ON (lc.`content_id` = b.`content_id`)
INNER JOIN `". BIT_DB_PREFIX. "users_users` uu ON (uu.`user_id` = lc.`user_id`)
LEFT OUTER JOIN `". BIT_DB_PREFIX. "liberty_content_hits` lch ON (lc.`content_id` = lch.`content_id`)
LEFT OUTER JOIN `". BIT_DB_PREFIX. "liberty_attachments` laa ON (uu.`user_id` = laa.`user_id` AND laa.`attachment_id` = uu.`avatar_attachment_id`)
LEFT OUTER JOIN `". BIT_DB_PREFIX. "liberty_files` lfa ON lfa.`file_id` = laa.`foreign_id`
LEFT OUTER JOIN `". BIT_DB_PREFIX. "liberty_attachments` lap ON lap.`content_id` = lc.`content_id` AND lap.`is_primary` = 'y'
LEFT OUTER JOIN `". BIT_DB_PREFIX. "liberty_files` lfp ON lfp.`file_id` = lap.`foreign_id`
WHERE b.`$lookupColumn`= ? $whereSql";
if( $this->mInfo = $this->mDb->getRow($query,$bindVars) ) {
foreach( array( 'avatar', 'image' ) as $img ) {
function verify( &$pParamHash ) {
$pParamHash['blog_store']['max_posts'] = !empty( $pParamHash['max_posts'] ) && is_numeric( $pParamHash['max_posts'] ) ? $pParamHash['max_posts'] : NULL;
$pParamHash['blog_store']['use_title'] = isset ( $pParamHash['use_title'] ) ? 'y' : 'n';
$pParamHash['blog_store']['allow_comments'] = isset ( $pParamHash['allow_comments'] ) ? 'y' : 'n';
$pParamHash['blog_store']['use_find'] = isset ( $pParamHash['use_find'] ) ? 'y' : 'n';
// if we have an error we get them all by checking parent classes for additional errors
parent::verify( $pParamHash );
function store( &$pParamHash ) {
$this->mDb->StartTrans();
if( $this->verify( $pParamHash ) && parent::store( $pParamHash ) ) {
$result = $this->mDb->associateUpdate( $table, $pParamHash['blog_store'], array( "blog_id" => $pParamHash['blog_id'] ) );
// DEPRECATED - this looks stupid -wjames5
//$pParamHash['blog_store']['posts'] = 0;
$pParamHash['blog_store']['content_id'] = $this->mContentId;
if( isset ( $pParamHash['blog_id'] )&& is_numeric( $pParamHash['blog_id'] ) ) {
// if pParamHash['blog_id'] is set, someone is requesting a particular blog_id. Use with caution!
$pParamHash['blog_store']['blog_id'] = $pParamHash['blog_id'];
$pParamHash['blog_store']['blog_id'] = $this->mDb->GenID( 'blogs_blog_id_seq' );
$this->mBlogId = $pParamHash['blog_store']['blog_id'];
$result = $this->mDb->associateInsert( $table, $pParamHash['blog_store'] );
$this->mDb->CompleteTrans();
$this->mDb->StartTrans();
// remove all references in blogs_posts_map where post_content_id = content_id
$query_map = "DELETE FROM `". BIT_DB_PREFIX. "blogs_posts_map` WHERE `blog_content_id` = ?";
$result = $this->mDb->query( $query_map, array( $this->mContentId ) );
$query = "DELETE from `". BIT_DB_PREFIX. "blogs` where `content_id`=?";
$result = $this->mDb->query( $query, array( (int) $this->mContentId ) );
if( parent::expunge() ) {
$this->mDb->CompleteTrans();
$this->mDb->RollbackTrans();
$this->mDb->CompleteTrans();
function getPost( $pListHash= array() ) {
$blogId = (!empty( $pListHash['blog_id'] ) ? $pListHash['blog_id'] : $this->mBlogId);
if ( BitBase::verifyId( $blogId ) ) {
$sql = "SELECT bp.`post_id`
INNER JOIN `". BIT_DB_PREFIX. "liberty_content` lc ON (lc.`content_id`=bp.`content_id`)
INNER JOIN `". BIT_DB_PREFIX. "blogs_posts_map` bpm ON (bp.`content_id`=bpm.`post_content_id`)
INNER JOIN `". BIT_DB_PREFIX. "blogs` b on (bpm.`blog_content_id`=b.`content_id`)
WHERE b.`blog_id` = ? ORDER BY ". $this->mDb->convertSortMode( $pListHash['sort_mode'] );
if( $postId = $this->mDb->getOne($sql, array( $blogId ) ) ) {
$blogPost->load( NULL, $pListHash );
$selectSql = ''; $joinSql = ''; $whereSql = '';
// array_push( $bindVars, $this->mContentTypeGuid );
$this->getServicesSql( 'content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars );
// You can use a title or an array of blog_id
if (!empty($pParamHash['find'])) {
$bindVars = array_merge($bindVars, $pParamHash['find']);
$findesc = '%' . strtoupper( $pParamHash['find'] ) . '%';
$whereSql = " AND (UPPER(lc.`title`) like ? or UPPER(lc.`data`) like ?) ";
$bindVars= array($findesc,$findesc);
if( @$this->verifyId( $pParamHash['user_id'] ) ) {
$whereSql .= " AND uu.`user_id` = ? ";
$bindVars[] = $pParamHash['user_id'];
$this->getServicesSql( 'content_user_collection_function', $selectSql, $joinSql, $whereSql, $bindVars, $this, $pListHash );
if( !empty( $pParamHash['is_active'] ) ) {
$whereSql .= " AND b.`activity` IS NOT NULL";
if( !empty( $pParamHash['is_hit'] ) ) {
$whereSql .= " AND lch.`hits` IS NOT NULL";
if( !empty( $pParamHash['content_perm_name'] ) ) {
if( !empty( $whereSql ) ) {
$whereSql = preg_replace( '/^[\s]*AND/', ' WHERE ', $whereSql );
// Return a data array, even if empty
$pParamHash["data"] = array();
# Get count of total number of items available
SELECT COUNT(b.`blog_id`)
INNER JOIN `". BIT_DB_PREFIX. "liberty_content` lc ON (lc.`content_id` = b.`content_id`)
INNER JOIN `". BIT_DB_PREFIX. "users_users` uu ON (uu.`user_id` = lc.`user_id`)
$pParamHash["cant"] = $this->mDb->getOne( $query_cant, $bindVars );
# Check for offset out of range
if ( $pParamHash['offset'] < 0 ) {
$pParamHash['offset'] = 0;
elseif ( $pParamHash['offset'] > $pParamHash["cant"] ) {
$lastPageNumber = ceil ( $pParamHash["cant"] / $pParamHash['max_records'] ) - 1;
$pParamHash['offset'] = $pParamHash['max_records'] * $lastPageNumber;
SELECT b.`content_id` AS `hash_key`,
b.`blog_id`, b.`is_public`, b.`max_posts`, b.`activity`, b.`use_find`, b.`use_title`,
b.`add_date`, b.`add_poster`, b.`allow_comments`,
uu.`login`, uu.`real_name`, lc.*, lch.hits $selectSql
INNER JOIN `". BIT_DB_PREFIX. "liberty_content` lc ON (lc.`content_id` = b.`content_id`)
INNER JOIN `". BIT_DB_PREFIX. "users_users` uu ON (uu.`user_id` = lc.`user_id`)
LEFT OUTER JOIN `". BIT_DB_PREFIX. "liberty_content_hits` lch ON (lc.`content_id` = lch.`content_id`)
$whereSql order by ". $this->mDb->convertSortmode($pParamHash['sort_mode']);
$result = $this->mDb->query( $query, $bindVars, $pParamHash['max_records'], $pParamHash['offset'] );
while ($res = $result->fetchRow()) {
$blogContentId = $res['content_id'];
$ret[$blogContentId] = $res;
$ret[$blogContentId]['blog_url'] = $this->getDisplayUrl( $res['blog_id'] );
//get count of post in each blog
$ret[$blogContentId]['postscant'] = $this->getPostsCount( $res['content_id'] );
$parseHash['format_guid'] = $res['format_guid'];
$parseHash['content_id'] = $res['content_id'];
$parseHash['data'] = $res['data'];
$ret[$blogContentId]['parsed'] = $this->parseData( $parseHash );
if( @$this->verifyId( $pBlogContentId ) ) {
$whereSql = 'bpm.`blog_content_id` = ?';
$bindVars = array((int) $pBlogContentId);
$query = "SELECT COUNT(*)
INNER JOIN `". BIT_DB_PREFIX. "blog_posts` bp ON (bpm.`post_content_id`=bp.`content_id`)
$ret = $this->mDb->getOne( $query, $bindVars );
$this->mErrors['content_id'] = "Invalid blog content id.";
//This doesnt even appear to be used in blogs before this refactoring -wjames5
return ($this->getField('user_id') == $gBitUser->mUserId || $gBitUser->isAdmin() || $this->getField('is_public') == 'y' );
// for now just check edit permission, however eventually we'll want to separate this notion so blog editors and posters can be distinguished
if ($gBitUser->mUserId && $pPermName) {
$ret = $gBitUser->object_has_permission( $gBitUser->mUserId, $this->mInfo['blog_id'], $this->getContentType(), $pPermName );
$ret = "bitpackage:blogs/center_". $pAction. "_blog_posts.tpl";
$ret = "bitpackage:liberty/center_". $pAction. "_generic.tpl";
* @return an array of content_status_id, content_status_names the current
* user can use on this content.
// return NULL for all but admins
if( $gBitUser->hasPermission( 'p_liberty_edit_all_status' )) {
global $gBitThemes, $gBitSmarty, $gBitSystem;
if( $gBitThemes->isModuleLoaded( 'bitpackage:blogs/center_list_blog_posts.tpl', 'c' ) && $gBitSystem->isFeatureActive( 'blog_ajax_more' ) && $gBitThemes->isJavascriptEnabled() ) {
$gBitSmarty->assign( 'ajax_more', TRUE );
$gBitThemes->loadAjax( 'mochikit', array( 'Iter.js', 'DOM.js', 'Style.js', 'Color.js', 'Position.js', 'Visual.js' ));
|