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); }
/** creates a new category * * @param int * @param mixed array which must include title and optionally parentid * * @return int nodeid of the created category */ public function saveCategory($nodeId, $input) { $channelApi = vB_Api::instanceInternal('content_channel'); $nodeId = (int) $nodeId; // force social group channel as parent id (categories cannot be nested) $input['parentid'] = $this->getSGChannel(); $input['category'] = 1; // force channel to be a category $input['templates']['vB5_Route_Channel'] = vB_Page::getSGCategoryPageTemplate(); $input['templates']['vB5_Route_Conversation'] = vB_Page::getSGCategoryConversPageTemplate(); // TODO: this code is similar to vB_Api_Widget::saveChannel, add a library method with it? if ($nodeId > 0) { // this call won't update parentid $channelApi->update($nodeId, $input); } else { $nodeId = $channelApi->add($input); } return $nodeId; }
/** * Returns the widget instances that are used for blog sidebar. * This method should be used only for owner configuration of the blog, not rendering * * @param int Channel ID * * @return array An array of widget instances, keyed by widget instance ID * <pre> * array( * widget instance ID => array( * title * widgetid * widgetinstanceid * hidden (int flag) * ) * ) * </pre> */ public function getBlogSidebarModules($channelId = 0) { $channelId = intval($channelId); $widgetApi = vB_Api::instance('widget'); // We assume there's only one container in blog pagetemplate. If this is no longer the case, we may need to implement GUID for widgetinstances $blogTemplate = vB_Page::getBlogChannelPageTemplate(); $modules = vB::getDbAssertor()->getRows('getBlogSidebarModules', array('blogPageTemplate' => $blogTemplate)); $results = $parentConfig = $sortAgain = array(); foreach ($modules as $module) { $title = $module['title']; //Temporarily removing the Blog Categories module as it is not implemented yet (VBV-4247) //@TODO: Remove this when this module gets implemented. //@TODO: It would be great if we have a way to globally disable any module and not display it anywhere to avoid this kind of fix. if ($module['guid'] == 'vbulletin-widget_blogcategories-4eb423cfd6dea7.34930850') { continue; } //END if (isset($module['adminconfig']) and !empty($module['adminconfig'])) { // search for custom title $adminConfig = @unserialize($module['adminconfig']); if (is_array($adminConfig)) { foreach ($adminConfig as $key => $val) { if (stripos($key, 'title') !== false) { $title = $val; break; } } } } if (!isset($parentConfig[$module['containerinstanceid']])) { $parentConfig[$module['containerinstanceid']] = $widgetApi->fetchConfig($module['containerinstanceid'], 0, $channelId); if (isset($parentConfig[$module['containerinstanceid']]['display_order'])) { $sortAgain[] = $module['containerinstanceid']; } } if (isset($parentConfig[$module['containerinstanceid']]['display_modules']) and !empty($parentConfig[$module['containerinstanceid']]['display_modules'])) { $hidden = in_array($module['widgetinstanceid'], $parentConfig[$module['containerinstanceid']]['display_modules']) ? 0 : 1; } else { $hidden = 0; } $results[$module['widgetinstanceid']] = array('title' => $title, 'widgetid' => $module['widgetid'], 'widgetinstanceid' => $module['widgetinstanceid'], 'hidden' => $hidden); } if (!empty($sortAgain)) { $newOrder = array(); foreach ($sortAgain as $parent) { if (is_array($parentConfig[$parent]['display_order'])) { foreach ($parentConfig[$parent]['display_order'] as $widgetInstanceId) { $newOrder[$widgetInstanceId] = $results[$widgetInstanceId]; unset($results[$widgetInstanceId]); } } // append remaining items $newOrder += $results; } return $newOrder; } else { return $results; } }
public function createBlog($input) { return $this->createChannel($input, $this->getBlogChannel(), vB_Page::getBlogConversPageTemplate(), vB_Page::getBlogChannelPageTemplate(), vB_Api_UserGroup::CHANNEL_OWNER_SYSGROUPID); }
/** * Creates pagetemplate, pages and routes for a channel * @param int nodeid * @param array $data - Must contain the following fields: * - templates * - vB5_Route_Channel * - vB5_Route_Conversation (optional) * - parentid * - title * - page_parentid */ protected function createChannelPages($nodeid, $data) { $db = vB::getDbAssertor(); // default to creating a forum/channel, not a category if (!isset($data['category'])) { $data['category'] = 0; } // Default child route & channel/child templates. Note, if you set a childroute, // you should also set the $data['templates'][vB5_Route_Channel'] & $data['templates'][$childRoute] appropriately $childRoute = isset($data['childroute']) ? $data['childroute'] : 'vB5_Route_Conversation'; $childTemplate = vB_Page::getConversPageTemplate(); $channelTemplate = vB_Page::getChannelPageTemplate(); if (!isset($data['templates']) || !isset($data['templates']['vB5_Route_Channel']) || !isset($data['templates'][$childRoute])) { $parentChannel = $this->getContent($data['parentid']); if (isset($parentChannel[$data['parentid']])) { $parentChannel = $parentChannel[$data['parentid']]; } if ($parentChannel['category'] != $data['category']) { // we cannot inherit the templates, use the default ones if ($data['category'] > 0) { $templates['vB5_Route_Channel'] = vB_Page::getCategoryChannelPageTemplate(); } else { $templates['vB5_Route_Channel'] = $channelTemplate; $templates[$childRoute] = $childTemplate; } } else { // Get page templates used by parent $templates = array(); $parentRoutes = $db->assertQuery('routenew', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'class', 'value' => array('vB5_Route_Channel', $childRoute)), array('field' => 'contentid', 'value' => $data['parentid']), array('field' => 'redirect301', 'operator' => vB_dB_Query::OPERATOR_ISNULL)))); $routeInfo = array(); foreach ($parentRoutes as $parentRoute) { $args = unserialize($parentRoute['arguments']); $routeInfo[$parentRoute['class']] = $args['pageid']; } $parentPages = $db->assertQuery('page', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'pageid', 'value' => array_values($routeInfo))))); foreach ($parentPages as $parentPage) { foreach ($routeInfo as $class => $pageId) { if ($pageId == $parentPage['pageid']) { // don't use template from forum homepage if ($class == 'vB5_Route_Channel' and $parentPage['pagetemplateid'] == 1) { $masterTemplate = vB::getDbAssertor()->getRow('pagetemplate', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'guid' => vB_Page::TEMPLATE_CHANNEL)); $templates[$class] = $masterTemplate['pagetemplateid']; } else { $templates[$class] = $parentPage['pagetemplateid']; } $parentPageIds[$class] = $pageId; } } } } } else { $templates = $data['templates']; unset($data['templates']); } // check if the main channel page already exists $existingRouteId = (int) vB::getDbAssertor()->getField('vBForum:node', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::COLUMNS_KEY => array('routeid'), vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'nodeid', 'value' => $nodeid, 'operator' => vB_dB_Query::OPERATOR_EQ)))); if ($existingRouteId > 0) { $existingPage = vB::getDbAssertor()->getRow('page', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'routeid', 'value' => $existingRouteId, 'operator' => vB_dB_Query::OPERATOR_EQ)))); } else { $existingPage = array(); } $phraseLib = vB_Library::instance('phrase'); if (empty($existingPage)) { // Create main channel page $page['guid'] = vB_Xml_Export_Page::createGUID(array()); $page['pagetemplateid'] = $templates['vB5_Route_Channel']; $page['title'] = $data['title']; $page['pagetype'] = vB_Page::TYPE_CUSTOM; $page['parentid'] = isset($data['page_parentid']) ? $data['page_parentid'] : (isset($parentPageIds['vB5_Route_Channel']) ? $parentPageIds['vB5_Route_Channel'] : 0); $pageid = $db->insert('page', $page); if (is_array($pageid)) { $pageid = (int) array_pop($pageid); } $guidforphrase = vB_Library::instance('phrase')->cleanGuidForPhrase($page['guid']); $newpage = vB::getDbAssertor()->getColumn('page', 'product', array('pageid' => $pageid)); $productid = array_pop($newpage); $phraseLib->save('pagemeta', 'page_' . $guidforphrase . '_title', array('text' => array($page['title']), 'product' => $productid, 'oldvarname' => 'page_' . $guidforphrase . '_title', 'oldfieldname' => 'global', 'skipdebug' => 1)); if (isset($data['description'])) { $phraseLib->save('pagemeta', 'page_' . $guidforphrase . '_metadesc', array('text' => array($data['description']), 'product' => $productid, 'oldvarname' => 'page_' . $guidforphrase . '_metadesc', 'oldfieldname' => 'global', 'skipdebug' => 1)); } // Create route for main channel page $route_data = array('nodeid' => $nodeid, 'pageid' => $pageid); if (!empty($data['routeguid'])) { $route_data['guid'] = $data['routeguid']; } if (!empty($data['urlident'])) { $route_data['urlident'] = $data['urlident']; } $channelRouteId = vB_Api::instanceInternal('route')->createRoute('vB5_Route_Channel', $route_data); if (is_array($channelRouteId)) { $channelRouteId = (int) array_pop($channelRouteId); } $db->update('vBForum:node', array('routeid' => $channelRouteId), array('nodeid' => $nodeid)); $db->update('page', array('routeid' => $channelRouteId), array('pageid' => $pageid)); } else { //Update the existing main channel page $page['pagetemplateid'] = $existingPage['pagetemplateid']; $page['title'] = $data['title']; $page['pagetype'] = $existingPage['pagetype']; $page['parentid'] = isset($data['page_parentid']) ? $data['page_parentid'] : (isset($parentPageIds['vB5_Route_Channel']) ? $parentPageIds['vB5_Route_Channel'] : 0); $pageid = $existingPage['pageid']; $db->update('page', $page, array('pageid' => $pageid)); $productid = $existingPage['product']; } vB_Cache::instance(vB_Cache::CACHE_FAST)->event("nodeChg_{$nodeid}"); vB_Cache::instance()->event("nodeChg_{$nodeid}"); if ($data['category'] == 0 and isset($templates[$childRoute]) and !empty($templates[$childRoute])) { // Create the conversation page $page['guid'] = vB_Xml_Export_Page::createGUID(array()); $page['pagetemplateid'] = $templates[$childRoute]; $page['title'] = $data['title']; $page['pagetype'] = vB_Page::TYPE_DEFAULT; $page['parentid'] = $pageid; $pageid = $db->insert('page', $page); if (is_array($pageid)) { $pageid = (int) array_pop($pageid); } $guidforphrase = vB_Library::instance('phrase')->cleanGuidForPhrase($page['guid']); $phraseLib->save('pagemeta', 'page_' . $guidforphrase . '_title', array('text' => array($page['title']), 'product' => $productid, 'oldvarname' => 'page_' . $guidforphrase . '_title', 'oldfieldname' => 'global', 'skipdebug' => 1)); if (isset($data['description'])) { $phraseLib->save('pagemeta', 'page_' . $guidforphrase . '_metadesc', array('text' => array($data['description']), 'product' => $productid, 'oldvarname' => 'page_' . $guidforphrase . '_metadesc', 'oldfieldname' => 'global', 'skipdebug' => 1)); } // Create route for conversation page $conversationRouteId = vB_Api::instanceInternal('route')->createRoute($childRoute, array('channelid' => $nodeid, 'pageid' => $pageid)); if (is_array($conversationRouteId)) { $conversationRouteId = (int) array_pop($conversationRouteId); } $db->update('page', array('routeid' => $conversationRouteId), array('pageid' => $pageid)); } }