<?php
 class vB_Library_Blog extends vB_Library { protected $blogChannel = false; protected function __construct() { parent::__construct(); $this->blogChannel = $this->getBlogChannel(); } public function createBlog($input) { return $this->createChannel( $input, $this->getBlogChannel(), vB_Page::getBlogConversPageTemplate(), vB_Page::getBlogChannelPageTemplate(), vB_Api_UserGroup::CHANNEL_OWNER_SYSGROUPID ); } public function createChannel($input, $channelid, $channelConvTemplateid, $channelPgTemplateId, $ownerSystemGroupId) { $input['parentid'] = $channelid; $input['inlist'] = 1; $input['protected'] = 0; if (empty($input['userid'])) { $input['userid'] = vB::getCurrentSession()->get('userid'); } if (!isset($input['publishdate'])) { $input['publishdate'] = vB::getRequest()->getTimeNow(); } $input['templates']['vB5_Route_Channel'] = $channelPgTemplateId; $input['templates']['vB5_Route_Conversation'] = $channelConvTemplateid; $channelLib = vB_Library::instance('content_channel'); $input['page_parentid'] = 0; $result = $channelLib->add($input, ['skipFloodCheck' => true, 'skipDupCheck' => true]); $usergroup = vB::getDbAssertor()->getRow('usergroup', ['systemgroupid' => $ownerSystemGroupId]); if (empty($usergroup) OR !empty($usergroup['errors'])) { throw new vB_Exception_Api('invalid_request'); } vB_User::setGroupInTopic($input['userid'], $result['nodeid'], $usergroup['usergroupid']); vB_Cache::allCacheEvent(['nodeChg_' . $this->blogChannel, "nodeChg_$channelid"]); vB::getUserContext()->rebuildGroupAccess(); vB_Channel::rebuildChannelTypes(); vB_Library_Follow::instance()->clearFollowCache([$input['userid']], false); return $result['nodeid']; } public function getBlogChannel() { if ($this->blogChannel) { return $this->blogChannel; } $blogChannel = vB_Library::instance('content_channel')->fetchChannelByGUID(vB_Channel::DEFAULT_BLOG_PARENT); if (isset($blogChannel['nodeid'])) { $this->blogChannel = $blogChannel['nodeid']; } return $this->blogChannel; } } 