示例#1
0
 /**
  * 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));
     }
 }