/** * Additional tasks to perform before a delete. * * Return false to indicate that the entire delete process was not a success. * * @param mixed - The result of execDelete() */ protected function preDelete($result) { $this->assertItem(); require_once DIR . '/includes/class_taggablecontent.php'; $taggable = vB_Taggable_Content_Item::create(vB::$vbulletin, vB_Types::instance()->getContentTypeID("vBCms_Article"), intval($this->item->getId())); $taggable->delete_tag_attachments(); vB::$db->query_write(" DELETE FROM " . TABLE_PREFIX . "cms_nodecategory WHERE nodeid = " . intval($this->item->getNodeId()) ); vB::$db->query_write(" DELETE FROM " . TABLE_PREFIX . "cms_article WHERE contentid = " . intval($this->item->getId()) ); vB_Cache::instance()->event('categories_updated'); return parent::preDelete($result); }
/** * 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; $contentdm = new vBCms_DM_Article(); vB::$vbulletin->input->clean_array_gpc('r', array( 'nodeid' => vB_Input::TYPE_UINT, 'parentnode' => vB_Input::TYPE_UINT, 'parentid' => vB_Input::TYPE_UINT, 'blogcommentid' => vB_Input::TYPE_UINT, 'postid' => vB_Input::TYPE_UINT, 'blogid' => TYPE_UINT )); //We should have a nodeid, but a parentnode is even better. ($hook = vBulletinHook::fetch_hook('vbcms_article_defaultcontent_start')) ? eval($hook) : false; 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['parentid'] AND intval(vB::$vbulletin->GPC['parentid'] )) { $parentnode = vB::$vbulletin->GPC['parentid']; } 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']; } else { throw (new vB_Exception_Content('No valid parent node')); } $nodedm->set('contenttypeid', vB_Types::instance()->getContentTypeID("vBCms_Article")); $nodedm->set('parentnode', $parentnode); $nodedm->set('publicpreview', 1); $nodedm->set('comments_enabled', 1); if (vB::$vbulletin->GPC_exists['blogcommentid'] OR vB::$vbulletin->GPC_exists['blogid']) { $this->createFromBlogPost($nodedm); } else if (vB::$vbulletin->GPC_exists['postid']) { $this->createFromForumPost($nodedm); } else { $title = new vB_Phrase('vbcms', 'new_article'); $nodedm->set('description', $title); $nodedm->set('pagetext', $title); $nodedm->set('title', $title); } if (!($contentid = $nodedm->save())) { throw (new vB_Exception_Content('Failed to create default content for contenttype ' . get_class($this))); } ($hook = vBulletinHook::fetch_hook('vbcms_article_defaultcontent_end')) ? eval($hook) : false; //at this point we have saved the data. We need to get the content id, which isn't easily available. if ($record = vB::$vbulletin->db->query_first("SELECT contentid FROM " . TABLE_PREFIX . "cms_node WHERE nodeid = $contentid")) { $nodedm->set('contentid', $record['contentid']); } return $contentid; }
/** * Fetches the view for configuring a content item. * * @param mixed $parameters - Request parameters * @return vB_View | bool - Returns a view or false */ public function getConfigView($parameters = false) { $view = new vB_View_AJAXHTML('cms_content_config'); $view->title = new vB_Phrase('vbcms', 'configuring_content_x', $this->content->getTitle()); vB::$vbulletin->input->clean_array_gpc('p', array( 'do' => vB_Input::TYPE_STR, 'font' => vB_Input::TYPE_STR, 'size' => vB_Input::TYPE_UINT )); if (vB::$vbulletin->GPC['do'] == 'config' AND $this->verifyPostId()) { $nodedm = new vBCms_DM_Node($this->content); $nodedm->set('config', array('font' => vB::$vbulletin->GPC['font'], 'size' => vB::$vbulletin->GPC['size'])); $nodedm->save(); if (!$nodedm->hasErrors()) { $segments = array( 'node' => $this->content->getUrlSegment(), 'action' => vB_Router::getUserAction('vBCms_Controller_Content', 'EditPage')); $view->setUrl(vB_View_AJAXHTML::URL_FINISHED, vBCms_Route_Content::getURL($segments)); $view->setStatus(vB_View_AJAXHTML::STATUS_FINISHED, new vB_Phrase('vbcms', 'configuration_saved')); } else { if (vB::$vbulletin->debug) { $view->addErrors($nodedm->getErrors()); } // only send a message $view->setStatus(vB_View_AJAXHTML::STATUS_MESSAGE, new vB_Phrase('vbcms', 'configuration_failed')); } } else { // add the config content $configview = $this->createView('config'); $config = $this->content->getConfig(); $configview->font = $config['font']; $configview->size = $config['size']; $configview->title = $vbphrase['new_page']; $configview->html_title = $vbphrase['new_page']; $configview->addArray(array('description' => $this->content->getDescription())); $configview->package = $this->package; $configview->class = $this->class; $this->addPostId($configview); $view->setContent($configview); //Set the class and package $view->package = $this->package; $view->class = $this->class; // send the view $view->setStatus(vB_View_AJAXHTML::STATUS_VIEW, new vB_Phrase('vbcms', 'configuring_content')); } return $view; }
/** * 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, 'parentid' => vB_Input::TYPE_UINT, 'pagecontent' => vB_Input::TYPE_STR, )); //We should have a nodeid, but a parentnode is even better. ($hook = vBulletinHook::fetch_hook($this->content_start_hook)) ? eval($hook) : false; 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['parentid'] AND intval(vB::$vbulletin->GPC['parentid'] )) { $parentnode = vB::$vbulletin->GPC['parentid']; } 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']; } else { throw (new vB_Exception_Content('No valid parent node')); } $contenttypeid = vB_Types::instance()->getContentTypeID($this->package . '_' . $this->class); //Verify Permissions if (!vBCMS_Permissions::canUseHtml($parentnode, $contenttypeid, vB::$vbulletin->userinfo['userid'])) { throw (new vB_Exception_AccessDenied()); } $this->config = array('pagetext' => $vbphrase['pagetext_goes_here'], 'previewtext' => $vbphrase['preview_goes_here_desc']); $nodedm->set('config', $this->config); $nodedm->set('contenttypeid', $contenttypeid); $nodedm->set('parentnode', $parentnode); $nodedm->set('publicpreview', 1); $nodedm->set('comments_enabled', 1); $title = new vB_Phrase('vbcms', 'new_static_page'); $nodedm->set('description', $title); $nodedm->set('title', $title); if (!($contentid = $nodedm->save())) { throw (new vB_Exception_Content('Failed to create default content for contenttype ' . get_class($this))); } ($hook = vBulletinHook::fetch_hook($this->content_end_hook)) ? eval($hook) : false; return $contentid; }
/** * 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; }
/** * Main entry point for the controller. * * @return string - The final page output */ public function actionPublishNode() { // Create AJAX view for html replacement $view = new vB_View_AJAXHTML('cms_publish_view'); $view->title = new vB_Phrase('vbcms', 'publishing_page'); vB::$vbulletin->input->clean_array_gpc('r', array( 'do' => vB_Input::TYPE_STR, 'publishdate' => vB_Input::TYPE_UNIXTIME )); if ((vB::$vbulletin->GPC['do'] == 'save') AND $this->verifyPostId()) { $publishdate = vB::$vbulletin->GPC['publishdate']; $nodedm = new vBCms_DM_Node(); $nodedm->setExisting($this->node); $nodedm->set('publishdate', vB::$vbulletin->GPC['publishdate']); if (!$nodedm->save()) { $view->addErrors($nodedm->getErrors()); return $this->saveError($view, 'Node DM save failed'); } //We need to see if we have a content node to index. $contenttypeid = $this->node->getContenttypeId(); $index_controller = vB_Search_Core::get_instance()->get_index_controller_by_id($contenttypeid); if (!($index_controller instanceof vb_Search_Indexcontroller_Null)) { $classinfo = vB_Types::instance()->getContentClassFromId($contenttypeid); vB_Search_Indexcontroller_Queue::indexQueue($classinfo['package'], $classinfo['class'], 'index', $this->node->getId()); } $published = ($publishdate AND ($publishdate <= TIMENOW)); if ($published != $this->node->isPublished()) { $finishurl = vBCms_Route_Content::getURL(array('node' => $this->node->getNodeId(), 'action' => vB_Router::getUserAction('vBCms_Controller_Content', 'View'))); $view->setUrl(vB_View_AJAXHTML::URL_FINISHED, $finishurl); } $status_phrase = new vB_Phrase('vbcms', $published ? 'page_published' : 'page_unpublished'); $view->setStatus(vB_View_AJAXHTML::STATUS_FINISHED, $status_phrase); } else { // get the delete view $publishview = new vB_View('vbcms_publish_form'); // add datepicker for date $publishview->datepicker = new vB_View_DatePicker(); $publishview->datepicker->setDate($this->node->getPublishDate()); $publishview->datepicker->setLabel(new vB_Phrase('vbcms', 'publish_date')); $publishview->datepicker->setDateVar('publishdate'); // item id to ensure form is submitted to us $this->addPostId($publishview); // add form to the html replacement output $view->setContent($publishview); // send the view // TODO: update overlay handler to accept an empty status $view->setStatus(vB_View_AJAXHTML::STATUS_VIEW, ' '); } return $view->render(true); }
/** * Additional tasks to perform after a delete. * * @param mixed - The result of execDelete() */ function postDelete($result) { $this->assertItem(); $nodeid = intval($this->item->getNodeId()); $nodedm = new vBCms_DM_Node(); $nodedm->setExisting($nodeid); $nodedm->set('nodeid', $nodeid); $nodedm->removeRating(intval($this->item->getVote())); $nodedm->save(); return $result; }
protected function postSave($result, $deferred, $replace, $ignore) { if (! $this->save_children) { return true; } vB::$vbulletin->input->clean_array_gpc('p', array( 'ids' => vB_Input::TYPE_ARRAY)); //The parent classes insist on setting new=1, but we want new=0; vB::$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "cms_node SET new = 0 WHERE nodeid = " . (isset($this->set_fields['nodeid']) ? $this->set_fields['nodeid'] : $this->primary_id)); //We have a minor issue here. The edit screen does not have a time and date //So- if the item is currently published and is still published, we should do nothing. //To make that decision we need to know what's currently published. $existing = array(); if (count(vB::$vbulletin->GPC['ids'])) { $rst = $record = vB::$vbulletin->db->query_read($sql = "SELECT nodeid, publishdate, setpublish, publicpreview FROM " . TABLE_PREFIX . "cms_node AS node WHERE nodeid in (" . implode(', ', vB::$vbulletin->GPC['ids']) . ")"); if ($rst) { while($record = vB::$vbulletin->db->fetch_array($rst)) { $existing[$record['nodeid']] = $record; } } } $orders = array(); foreach (vB::$vbulletin->GPC['ids'] as $nodeid) { vB::$vbulletin->input->clean_array_gpc('p', array( "cb_preview_$nodeid" => vB_Input::TYPE_INT, "cb_delete_$nodeid" => vB_Input::TYPE_INT, "order_$nodeid" => vB_Input::TYPE_INT, "published_$nodeid" => vB_Input::TYPE_INT )); //If we're deleting we need to instantiate the appropriate data manager // and use that to delete. Otherwise we know where the variables are and // can just update them directly. if (vB::$vbulletin->GPC_exists["cb_delete_$nodeid"]) { if ($record = vB::$vbulletin->db->query_first("SELECT contenttype.class, package.class AS package FROM " . TABLE_PREFIX . "cms_node node INNER JOIN " . TABLE_PREFIX . "contenttype AS contenttype ON contenttype.contenttypeid = node.contenttypeid INNER JOIN " . TABLE_PREFIX . "package AS package ON package.packageid = contenttype.packageid WHERE nodeid = " . $nodeid)) { $item = vB_Item_Content::create($record['package'], $record['class'], $nodeid); $dm = $item->getDM(); $dm->delete(); } } else { //Check the order. This is fairly tricky. If we do the order updates // out of sequence, things get scrambled and we are sure to wind up incorrect. So we // need to index them and do them in order. if (intval( vB::$vbulletin->GPC["order_$nodeid"])) { $orders[$nodeid] = vB::$vbulletin->GPC["order_$nodeid"]; } else { $orders[$nodeid] = 0; } $updates = array(); //Check the preview status $newpreview = vB::$vbulletin->GPC_exists["cb_preview_$nodeid"] ? 1 : 0; if (($newpreview == 1) AND (array_key_exists($nodeid, $existing)) AND (intval($existing[$nodeid]['publicpreview']) != 1)) { $updates[] = " publicpreview = 1"; } else if (($newpreview == 0) AND (array_key_exists($nodeid, $existing)) AND (intval($existing[$nodeid]['publicpreview']) != 0)) { $updates[] = " publicpreview = 0"; } //Check the published status. Remember we set published = 2; if (array_key_exists($nodeid, $existing) AND vB::$vbulletin->GPC_exists["published_$nodeid"] AND (vB::$vbulletin->GPC["published_$nodeid"] == 2) AND ($existing[$nodeid]['setpublish'] != 1)) { $updates[] = " setpublish = 1, publishdate = " . (TIMENOW - vBCms_ContentManager::getTimeOffset(vB::$vbulletin->userinfo, false) ); } else if (array_key_exists($nodeid, $existing) AND vB::$vbulletin->GPC_exists["published_$nodeid"] AND (vB::$vbulletin->GPC["published_$nodeid"] == 1) AND ($existing[$nodeid]['setpublish'] != 0)) { $updates[] = " setpublish = 0 " ; } if (count($updates)) { $sql = "UPDATE " . TABLE_PREFIX . "cms_node set " . implode(', ' , $updates) . " WHERE nodeid = $nodeid"; vB::$vbulletin->db->query_write($sql); } } } asort($orders); $min_sequence = 1; foreach ($orders as $nodeid => $order) { if ($order == 0) { vBCms_ContentManager::setDisplayOrder($this->set_fields['nodeid'], $nodeid, 0); } else { $order = max($min_sequence, intval($order)); $min_sequence++; vBCms_ContentManager::setDisplayOrder($this->set_fields['nodeid'], $nodeid, $order); } } return parent::postSave($result, $deferred, $replace, $ignore); }