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); }