<?php
 class vB_Library_Article extends vB_Library { protected $articleHomeChannel = false; protected function __construct() { parent::__construct(); $this->articleHomeChannel = $this->getArticleChannel(); } public function createArticleCategory($input) { $parentChannel = (isset($input['parentid']) ? $input['parentid'] : $this->getArticleChannel()); return $this->createChannel($input, $parentChannel, vB_Page::getArticleConversPageTemplate(), vB_Page::getArticleChannelPageTemplate(), vB_Api_UserGroup::CHANNEL_OWNER_SYSGROUPID); } public function createChannel($input, $channelid, $channelConvTemplateid, $channelPgTemplateId, $ownerSystemGroupId) { if (!isset($input['parentid']) OR intval($input['parentid']) < 1) { $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_Article'] = $channelConvTemplateid; $input['childroute'] = 'vB5_Route_Article'; $channelLib = vB_Library::instance('content_channel'); $input['page_parentid'] = 0; $result = $channelLib->add($input, ['skipNotifications' => true, 'skipFloodCheck' => true, 'skipDupCheck' => true]); vB_Cache::allCacheEvent(['nodeChg_' . $this->articleHomeChannel, "nodeChg_$channelid"]); vB::getUserContext()->rebuildGroupAccess(); vB_Channel::rebuildChannelTypes(); vB_Library_Follow::instance()->clearFollowCache([$input['userid']], false); return $result['nodeid']; } public function getArticleChannel() { if ($this->articleHomeChannel) { return $this->articleHomeChannel; } $articleHomeChannel = vB_Library::instance('content_channel')->fetchChannelByGUID(vB_Channel::DEFAULT_ARTICLE_PARENT); if (isset($articleHomeChannel['nodeid'])) { $this->articleHomeChannel = $articleHomeChannel['nodeid']; } return $this->articleHomeChannel; } public function isArticleNode($nodeId, $node = false) { $nodeId = intval($nodeId); $articlesRootChannelId = vB_Api::instance('content_channel')->fetchChannelIdByGUID(vB_Channel::DEFAULT_ARTICLE_PARENT); if ($nodeId < 0) { return false; } if (empty($node)) { $node = vB_Library::instance('node')->getNode($nodeId, true, false); } if (empty($node['parents'])) { $parents = vB_Library::instance('node')->getParents($nodeId); foreach ($parents as $parent) { if ($parent['nodeid'] == $articlesRootChannelId) { return true; } } return false; } return in_array($articlesRootChannelId, $node['parents']); } } 