/** * Creates a new, empty content item to add to a node. * * @param vBCms_DM_Node $nodedm - The DM of the node that the content is being created for * @return int | false - The id of the new content or false if not applicable */ public function createDefaultContent(vBCms_DM_Node $nodedm) { global $vbphrase; require_once DIR . '/includes/functions_databuild.php'; fetch_phrase_group('cpcms'); vB::$vbulletin->input->clean_array_gpc('r', array( 'nodeid' => vB_Input::TYPE_UINT, 'parentnode' => vB_Input::TYPE_UINT )); //We should have a nodeid, but a parentnode is even better. ($hook = vBulletinHook::fetch_hook('vbcms_section_defaultcontent_start')) ? eval($hook) : false; if ($nodedm->getSet('parentnode')) { $parentnode = $nodedm->getField('parentnode'); } else { if ($this->parent_node) { $parentnode = $this->parent_node; } else if (vB::$vbulletin->GPC_exists['parentnode'] AND intval(vB::$vbulletin->GPC['parentnode'] )) { $parentnode = vB::$vbulletin->GPC['parentnode']; } else if (vB::$vbulletin->GPC_exists['nodeid'] AND intval(vB::$vbulletin->GPC['nodeid'] ) and $record = vB::$vbulletin->db->query_first("SELECT contenttypeid, nodeid, parentnode FROM " . TABLE_PREFIX . "cms_node where nodeid = " . vB::$vbulletin->GPC['nodeid'] )) { $parentnode = vB_Types::instance()->getContentTypeID("vBCms_Section") == $record['contenttypeid'] ? $record['nodeid'] : $record['parentnode']; } } if (!is_a($nodedm, 'vBCms_DM_Section')) { $nodedm = new vBCms_DM_Section(); $nodedm->set('parentnode', $parentnode); } $nodedm->set('contenttypeid', vB_Types::instance()->getContentTypeID("vBCms_Section")); $nodedm->set('contentid', 0); $nodedm->set('item_id', 0); $title = (vB::$vbulletin->GPC_exists['section_title']? vB::$vbulletin->GPC['section_title'] : (vB::$vbulletin->GPC_exists['title']? vB::$vbulletin->GPC['title'] : $vbphrase['new_section'])); $nodedm->set('title', $title); $nodedm->getValidURL($title); $nodedm->set('html_title', $title); //set the default configuration. $this->config = array(); $this->config['items_perhomepage'] = 7; $this->config['section_priority'] = 2; $this->config['content_layout'] = 1; $nodedm->set('config', $this->config); if (!($nodeid = $nodedm->save())) { throw (new vB_Exception_Content('Failed to create default content for contenttype ' . get_class($this))); } ($hook = vBulletinHook::fetch_hook('vbcms_section_defaultcontent_end')) ? eval($hook) : false; return $nodeid; }