public function saveFromForm($nodeid) { vB::$vbulletin->input->clean_array_gpc('r', array( 'html_title' => vB_Input::TYPE_NOHTML, 'cms_node_title' => vB_Input::TYPE_NOHTML, 'cms_node_url' => vB_Input::TYPE_STR, 'description' => vB_Input::TYPE_NOHTML, 'layoutid' => vB_Input::TYPE_INT, 'section_styleid' => vB_Input::TYPE_NOCLEAN, 'setpublish' => vB_Input::TYPE_INT, 'publishdate' => vB_Input::TYPE_STR, 'publishtime' => vB_Input::TYPE_ARRAY, 'publicpreview' => vB_Input::TYPE_INT, 'comments_enabled' => vB_Input::TYPE_INT, 'keywords' => vB_Input::TYPE_NOHTML, 'section_menu_inherit' => TYPE_BOOL, 'section_menu_sections' => TYPE_ARRAY_INT, 'showtitle' => vB_Input::TYPE_INT, 'showuser' => vB_Input::TYPE_INT, 'showpreviewonly' => vB_Input::TYPE_INT, 'showupdated' => vB_Input::TYPE_INT, 'showviewcount' => vB_Input::TYPE_INT, 'showpublishdate' => vB_Input::TYPE_INT, 'settingsforboth' => vB_Input::TYPE_INT, 'includechildren' => vB_Input::TYPE_INT, 'showall' => vB_Input::TYPE_INT, 'editshowchildren' => vB_Input::TYPE_INT, 'showrating' => vB_Input::TYPE_INT, 'hidden' => vB_Input::TYPE_INT, 'shownav' => vB_Input::TYPE_INT, 'nosearch' => vB_Input::TYPE_INT, 'display_order_select' => TYPE_ARRAY_INT )); $this->set('nodeid', $nodeid); //set the values if (vB::$vbulletin->GPC_exists['cms_node_url'] and vB::$vbulletin->GPC['cms_node_url'] != '') { //Let's do some cleanup of the url. $this->set('url', vB_Friendly_Url::clean_entities(vB::$vbulletin->GPC['cms_node_url'], true)); $this->item->setInfo(array('url'=> vB::$vbulletin->GPC['cms_node_url'])); } if (vB::$vbulletin->GPC_exists['description']) { $this->set('description', vB::$vbulletin->GPC['description']); $this->item->setInfo(array('description'=> vB::$vbulletin->GPC['description'])); } if (vB::$vbulletin->GPC_exists['cms_node_title']) { $this->set('title', vB::$vbulletin->GPC['cms_node_title']); $this->item->setInfo(array('title'=> vB::$vbulletin->GPC['cms_node_title'])); $this->setNodeTitle(vB::$vbulletin->GPC['cms_node_title']); } if (vB::$vbulletin->GPC_exists['html_title']) { $this->set('html_title', vB::$vbulletin->GPC['html_title']); $this->item->setInfo(array('html_title'=> vB::$vbulletin->GPC['html_title'])); } if (vB::$vbulletin->GPC_exists['setpublish']) { $this->set('setpublish', vB::$vbulletin->GPC['setpublish']); $this->item->setInfo(array('setpublish'=> vB::$vbulletin->GPC['setpublish'])); } if (vB::$vbulletin->GPC_exists['publishdate'] AND intval(vB::$vbulletin->GPC['publishdate'])) { $str_date = str_replace('-', '/', vB::$vbulletin->GPC['publishdate']); //if the user set a time it's from a different variable. if (vB::$vbulletin->GPC_exists['publishtime']) { $str_date .= ' ' . vB::$vbulletin->GPC['publishtime']['hour'] . ':' . vB::$vbulletin->GPC['publishtime']['minute'] . ' ' . vB::$vbulletin->GPC['publishtime']['offset']; } // make sure we adjust for local time before saving publish timestamp $offset = vBCms_ContentManager::getTimeOffset(vB::$vbulletin->userinfo, false) - date('Z'); $publishdate = strtotime($str_date,0) - $offset; $this->set('publishdate', $publishdate); $this->item->setInfo(array('publishdate'=> $publishdate)); } if (vB::$vbulletin->GPC_exists['keywords']) { $this->set('keywords', vB::$vbulletin->GPC['keywords']); $this->item->setInfo(array('keywords'=> vB::$vbulletin->GPC['keywords'])); } if (vB::$vbulletin->GPC_exists['section_styleid']) { $this->set('styleid', vB::$vbulletin->GPC['section_styleid']); $this->item->setInfo(array('styleid'=> vB::$vbulletin->GPC['section_styleid'])); } if (vB::$vbulletin->GPC_exists['layoutid']) { $this->set('layoutid', vB::$vbulletin->GPC['layoutid']); $this->item->setInfo(array('layoutid'=> vB::$vbulletin->GPC['layoutid'])); } if (vB::$vbulletin->GPC_exists['publicpreview']) { $this->set('publicpreview', vB::$vbulletin->GPC['publicpreview']); $this->item->setInfo(array('publicpreview'=> vB::$vbulletin->GPC['publicpreview'])); } if (vB::$vbulletin->GPC_exists['comments_enabled']) { $this->set('comments_enabled', vB::$vbulletin->GPC['comments_enabled']); $this->item->setInfo(array('comments_enabled'=> vB::$vbulletin->GPC['comments_enabled'])); } if (vB::$vbulletin->GPC_exists['showtitle']) { $this->set('showtitle', vB::$vbulletin->GPC['showtitle']); $this->item->setInfo(array('showtitle'=> vB::$vbulletin->GPC['showtitle'])); } if (vB::$vbulletin->GPC_exists['showuser']) { $this->set('showuser', vB::$vbulletin->GPC['showuser']); $this->item->setInfo(array('showuser'=> vB::$vbulletin->GPC['showuser'])); } if (vB::$vbulletin->GPC_exists['showpreviewonly']) { $this->set('showpreviewonly', vB::$vbulletin->GPC['showpreviewonly']); $this->item->setInfo(array('showpreviewonly'=> vB::$vbulletin->GPC['showpreviewonly'])); } if (vB::$vbulletin->GPC_exists['showupdated']) { $this->set('showupdated', vB::$vbulletin->GPC['showupdated']); $this->item->setInfo(array('showupdated'=> vB::$vbulletin->GPC['showupdated'])); } if (vB::$vbulletin->GPC_exists['showviewcount']) { $this->set('showviewcount', vB::$vbulletin->GPC['showviewcount']); $this->item->setInfo(array('showviewcount'=> vB::$vbulletin->GPC['showviewcount'])); } if (vB::$vbulletin->GPC_exists['showpublishdate']) { $this->set('showpublishdate', vB::$vbulletin->GPC['showpublishdate']); $this->item->setInfo(array('showpublishdate'=> vB::$vbulletin->GPC['showpublishdate'])); } if (vB::$vbulletin->GPC_exists['settingsforboth']) { $this->set('settingsforboth', vB::$vbulletin->GPC['settingsforboth']); $this->item->setInfo(array('settingsforboth'=> vB::$vbulletin->GPC['settingsforboth'])); } if (vB::$vbulletin->GPC_exists['includechildren']) { $this->set('includechildren', vB::$vbulletin->GPC['includechildren']); $this->item->setInfo(array('includechildren'=> vB::$vbulletin->GPC['includechildren'])); } if (vB::$vbulletin->GPC_exists['showall']) { $this->set('showall', vB::$vbulletin->GPC['showall']); $this->item->setInfo(array('showall'=> vB::$vbulletin->GPC['showall'])); } if (vB::$vbulletin->GPC_exists['showrating']) { $this->set('showrating', vB::$vbulletin->GPC['showrating']); $this->item->setInfo(array('showrating'=> vB::$vbulletin->GPC['showrating'])); } if (vB::$vbulletin->GPC_exists['hidden']) { $this->set('hidden', vB::$vbulletin->GPC['hidden']); $this->item->setInfo(array('hidden'=> vB::$vbulletin->GPC['hidden'])); } if (vB::$vbulletin->GPC_exists['shownav']) { $this->set('shownav', vB::$vbulletin->GPC['shownav']); $this->item->setInfo(array('shownav'=> vB::$vbulletin->GPC['shownav'])); } if (vB::$vbulletin->GPC_exists['nosearch']) { $this->set('nosearch', vB::$vbulletin->GPC['nosearch']); $this->item->setInfo(array('nosearch'=> vB::$vbulletin->GPC['nosearch'])); } $this->set('editshowchildren',vB::$vbulletin->GPC_exists['editshowchildren'] ? vB::$vbulletin->GPC['editshowchildren'] : 0); $this->item->setInfo(array('editshowchildren'=> vB::$vbulletin->GPC['editshowchildren'])); if (vB::$vbulletin->GPC['section_menu_inherit']) { $section_menu = false; } else { $pre_sorted_section_menu = vB::$vbulletin->GPC['section_menu_sections']; $section_menu = array(); ////////////////////////////////////////////////////// // sort section_menu based on display order array ////////////////////////////////////////////////////// $display_order = vB::$vbulletin->GPC['display_order_select']; asort($display_order, SORT_NUMERIC); // loop through sorted display order array, and grab correlating values from the // pre-sorted section menu array and put them into the sorted section menu foreach ($display_order as $key => $value) { // if display order is zero, or that item was not selected to be in the menu // we can ignore that item from the display order array if ($value != '0' AND isset($pre_sorted_section_menu[$key])) { $section_menu[] = $pre_sorted_section_menu[$key]; unset($pre_sorted_section_menu[$key]); } } // if there are any section items that did not have a display order, we do not // care about their order and can add them into the section menu wherever we want foreach ($pre_sorted_section_menu as $value) { $section_menu[] = $value; } } $this->set('navigation', $section_menu); // add node info $result = $this->save(); //That's the main data. Creating an associatedthreadid, if necessary, // is handled in vbcms/dm/content.php 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); }
private function getPublished($year, $month) { //Getting the start date is easy. Getting the end date is a bit complex. Leap years and all that. //Easiest way is to get the start of the next month and subract a second. //Ensure permissions are loaded $hash = self::getMyHash($year, $month); if (!($articles = vB_Cache::instance()->read($hash, true, false))) { $offset = vBCms_ContentManager::getTimeOffset(vB::$vbulletin->userinfo); $start = gmmktime (0, 0, 0, $month, 1, $year); $weekday = gmdate('w', $start); $start -= $offset; $end = gmmktime (0, 0, 0, ($month == 12 ? 1 : $month + 1 ), 1, ($month == 12 ? $year + 1 : $year )) - $offset - 1; $articles = array(); $rst = vB::$vbulletin->db->query_read($sql = "SELECT node.nodeid, node.publishdate, node.setpublish FROM " . TABLE_PREFIX . "cms_node AS node INNER JOIN " . TABLE_PREFIX . "cms_nodeinfo AS info ON info.nodeid = node.nodeid WHERE node.setpublish > 0 AND node.publishdate BETWEEN $start AND $end AND node.contenttypeid <> " . vB_Types::instance()->getContentTypeID("vBCms_Section") . " AND " . vBCMS_Permissions::getPermissionString() . " AND hidden = 0 ORDER BY node.publishdate LIMIT 5000" ); $nextday = $start + 86400; $dom = 1; $articles[1] = array('data' => array(), 'time' => $start + 1, 'wday' => $weekday); //Now we want to end with an array of day => array('data ' => array, 'time' => unixtime) //So we need to build the array as we go. while($record = vB::$vbulletin->db->fetch_array($rst)) { //see if we need to advance to a new date if (intval($record['publishdate']) > $nextday) { while (intval($record['publishdate']) > $nextday) { $nextday += 86400; $start += 86400; $dom ++; $weekday = ($weekday == 6 ? 0 : ($weekday + 1)); $articles[$dom] = array('data' => array(), 'time' => $start + 1, 'wday' => $weekday); } } if ($record['setpublish']) { $articles[$dom]['data'][] = $record; } } //we may have some days at the end without articles. while($end > $start + 86400 ) { $dom++; $weekday = ($weekday == 6 ? 0 : ($weekday + 1)); $articles[$dom] = array('data' => array(), 'time' => $start + 1, 'wday' => $weekday); $start += 86400; } vB_Cache::instance()->write($hash , $articles, 1440, array('cms_calendar_published', 'sections_updated')); } //Now we want to turn this into an array of week=>(array(1-7); $week = 1; $calendar = array(1 => array()); //Pad the start with empty records as needed if ($articles[1]['wday'] != 0) { for ($i = 0; $i < $articles[1]['wday']; $i++) { $calendar[1][$i] = array('count' => 0, 'url' => '', 'day' => ''); } } $monthday = 1; $route = new vBCms_Route_List; while($monthday <= count($articles)) { //If we've filled a week, we need to advance $count = 0; foreach ($articles[$monthday]['data'] as $record) { $count = 1; $url = $route->getCurrentUrl(array('type' =>'day', 'value' => $articles[$monthday]['time'])) ; break; } $calendar[$week][$articles[$monthday]['wday']] = array('count' => $count, 'url' => $url, 'day' =>($monthday ? $monthday : '') ); if (($articles[$monthday]['wday'] == 6) AND ($monthday < count($articles))) { $week++; $calendar[$week] = array(); } $monthday++; } //We need to fill out a full week. Note that monthday is now one past the last day of the month if ($articles[$monthday - 1]['wday'] < 6) { for ($i = $articles[$monthday - 1]['wday'] + 1; $i <= 6 ; $i++) $calendar[$week][$i] = array('count' => 0, 'url' => '', 'day' => ''); } unset($route); return $calendar; }
/** Creates the publish editor at the top right of the edit section * * @return mixed * ****/ public function getPublishEditor($submit_url, $formid, $showpreview = true, $showcomments = true, $publicpreview = false, $comments_enabled = false, $pagination_links = 1) { if ($this->canPublish()) { $pub_view = new vB_View('vbcms_edit_publisher'); $pub_view->formid = $formid; $pub_view->setpublish = $this->setpublish; // if this is an unpublished article then we display publish to facebook if (is_facebookenabled() AND vB::$vbulletin->options['fbfeednewarticle'] AND !$this->setpublish) { // only display box if user is connectected to facebook $pub_view->showfbpublishcheckbox = is_userfbconnected(); } //Get date is a most annoying function for us. It takes a Unix time stamp // and converts it to server local time. We need to compensate for the difference between // server time (date('Z')) and usertime (vBCms_ContentManager::getTimeOffset(vB::$vbulletin->userinfo)) $offset = vBCms_ContentManager::getTimeOffset(vB::$vbulletin->userinfo) - date('Z'); if (intval($this->publishdate)) { $pub_view->publishdate = $this->publishdate ; } else { // get the current date/time dependent on user locality $pub_view->publishdate = TIMENOW; } $then = getdate(intval($pub_view->publishdate) + $offset); $pub_view->hour = $then['hours']; $pub_view->minute = $then['minutes']; //we need to parse out the date and time //Are we using a 24 hour clock? if ((strpos(vB::$vbulletin->options['timeformat'], 'G') !== false) OR (strpos( vB::$vbulletin->options['timeformat'], 'H') !== false)) { $pub_view->show24 = 1; } else { $pub_view->show24 = 0; $pub_view->offset = $pub_view->hour >= 12 ? 'PM' : 'AM'; if ($pub_view->hour > 12) { $pub_view->hour -= 12; } } $pub_view->title = $this->title; $pub_view->html_title = $this->html_title; $pub_view->username = $this->username; $pub_view->dateformat = vB::$vbulletin->options['dateformat']; // get the appropriate date format string for the // publish date calendar based on user's locale $pub_view->calendardateformat = (!empty(vB::$vbulletin->userinfo['lang_dateoverride']) ? '%Y/%m/%d' : 'Y/m/d'); $pub_view->groups = $this->getReaderGroups(); $pub_view->parents = $this->getParentage(); $pub_view->submit_url = $submit_url; $pub_view->sectiontypeid = vb_Types::instance()->getContentTypeID("vBCms_Section"); $pub_view->parents = $this->getParentage(); $pub_view->showtitle = $this->getShowTitle(); $pub_view->showuser = $this->getShowUser(); $pub_view->showpreviewonly = $this->getShowPreviewonly(); $pub_view->showupdated = $this->getShowUpdated(); $pub_view->showviewcount = $this->getShowViewcount(); $pub_view->showpublishdate = $this->getShowPublishdate(); $pub_view->settingsforboth = $this->getSettingsForboth(); $pub_view->showall = $this->getShowall(); $pub_view->includechildren = $this->getIncludeChildren(); $pub_view->showrating = $this->getShowRating(); $pub_view->hidden = $this->getHidden(); $pub_view->pagination_links = $pagination_links; $pub_view->show_pagination_link = ($this->contenttypeid == vb_Types::instance()->getContentTypeID("vBCms_Section") ) ? 1 : 0; $pub_view->shownav = $this->getShowNav(); $pub_view->show_shownav = ($this->contenttypeid == vb_Types::instance()->getContentTypeID("vBCms_Section") ) ? 0 : 1; $pub_view->nosearch = $this->getNoSearch(); $sectionid = (1 == $this->nodeid) ? 1 : $this->parentnode; $pub_view->hours24 = vB::$vbulletin->options['dateformat']; if ($this->contenttypeid == $pub_view->sectiontypeid) { $pub_view->show_categories = 0; $pub_view->is_section = 1; $pub_view->show_showsettings = 0; } else { $pub_view->show_categories = 1; $pub_view->categories = $this->getThisCategories(); $pub_view->show_showsettings = 1; $pub_view->is_section = 0; $pub_view->sectionid = $this->parentnode; } if ($pub_view->show_htmloption = ( $this->contenttypeid == vb_Types::instance()->getContentTypeID("vBCms_Article") // this is limited here to article but could be moved to any contenttype AND $this->canusehtml // this is set by some of the member functions above... )) { $pub_view->htmloption = $this->htmlstate; } $pub_view->show_categories = ($this->contenttypeid == $pub_view->sectiontypeid ? 0 : 1); //get the nodes $nodelist = vBCms_ContentManager::getSections(false); if (! isset(vB::$vbulletin->userinfo['permissions']['cms']) ) { vBCMS_Permissions::getUserPerms(); } foreach ($nodelist as $key => $node) { if (in_array(strval($node['permissionsfrom']), vB::$vbulletin->userinfo['permissions']['cms']['canpublish'])) { $nodelist[$key]['selected'] = ($sectionid == $node['nodeid'] ? 'selected="selected"' : ''); } else { unset($nodelist[$key]); } } $pub_view->nodelist = $nodelist; $pub_view->showpreview = $showpreview; $pub_view->showcomments = $showcomments; $pub_view->publicpreview = $publicpreview; $pub_view->hidden = $this->hidden; $pub_view->comments_enabled = $comments_enabled; $pub_view->show_sections = (1 != $this->nodeid); return $pub_view; } }