// $story_id = $_SESSION[storyObj]->id; // // printpre($version_short); // save_version($version_short, $version_long, $story_id); /****************************************************************************** * if tags, then save to tag table * save_record_tags($record_tags,$record_id,$user_id,$record_type) ******************************************************************************/ if (isset($_SESSION[settings][story_categories]) || isset($_SESSION[settings][story_categories_delete])) { $save_record_tags = array(); $delete_record_tags = array(); $save_record_tags = $_SESSION[settings][story_categories]; $delete_record_tags = $_SESSION[settings][story_categories_delete]; $record_id = $_SESSION[storyObj]->id; $user_id = $_SESSION[aid]; $record_type = "story"; save_record_tags($save_record_tags, $delete_record_tags, $record_id, $user_id, $record_type); } /****************************************************************************** * Go Back: edit url or content block detail url ******************************************************************************/ if ($_SESSION[settings][goback]) { $headerText = "Location: index.php?{$sid}&action=site&site=" . $thisSite->name . "§ion=" . $thisSection->id . "&page=" . $thisPage->id . "&story=" . $_SESSION[storyObj]->id . "&detail=" . $_SESSION[storyObj]->id; } else { $headerText = "Location: index.php?{$sid}&action=viewsite&site=" . $thisSite->name . "§ion=" . $thisSection->id . "&page=" . $thisPage->id . ($_SESSION[settings][story_set] ? "&story_set=" . $_SESSION[settings][story_set] : ""); } unset($_SESSION[storyObj], $_SESSION[settings]); header($headerText); exit; /****************************************************************************** * if error take them to page where error occured ******************************************************************************/
function insertDB($down = 0, $newsite = null, $newsection = 0, $newpage = 0, $removeOrigional = 0, $keepaddedby = 0, $keepDiscussions = 0, $storyTags = null) { $origsite = $this->owning_site; $origid = $this->id; if ($newsite) { $this->owning_site = $newsite; unset($this->owningSiteObj); } if ($newsection) { $this->owning_section = $newsection; unset($this->owningSectionObj); } if ($newpage) { $this->owning_page = $newpage; unset($this->owningPageObj); } $this->fetchUp(1); /********************************************************* * Re-Key the ordering of the rest of the stories in the * section to make sure that there are no holes *********************************************************/ foreach ($this->owningPageObj->getField("stories") as $order => $storyId) { $query = "UPDATE\n\t\t\t\t\tstory\n\t\t\t\tSET\n\t\t\t\t\tstory_order = '" . addslashes($order) . "'\n\t\t\t\tWHERE\n\t\t\t\t\tstory_id = '" . $storyId . "'"; // printpre($query); db_query($query); } // if moving to a new site, copy the media if ($origsite != $this->owning_site && $down) { $images = array(); if ($this->getField("type") == "image" || $this->getField("type") == "rss" || $this->getField("type") == "file") { $media_id = $this->getField("longertext"); $this->setField("longertext", copy_media($media_id, $newsite)); } else { if ($this->getField("type") == "story") { // These do some moving of files based on a ####id##### syntax // for storing inline images. // Adam 2005-06-27: I don't believe that these were ever used, but // I'll leave them here so as not to break any old data that uses them. $ids = segue::getMediaIDs("shorttext"); segue::replaceMediaIDs($ids, "shorttext", $newsite); $ids = segue::getMediaIDs("longertext"); segue::replaceMediaIDs($ids, "longertext", $newsite); // Search for and copy images that use the "[[mediapath]]/filename.ext" // syntax. preg_match_all("/\\[\\[mediapath\\]\\]\\/([^'\"]+)/", $this->getField("shorttext") . $this->getField("longertext"), $matches); $fnames = array_unique($matches[1]); foreach ($fnames as $fname) { copy_media_with_fname($fname, $origsite, $newsite); } } } } $a = $this->createSQLArray(1); if (!$keepaddedby) { $a[] = "FK_createdby='" . addslashes($_SESSION[aid]) . "'"; $a[] = $this->_datafields[addedtimestamp][1][0] . "=NOW()"; $a[] = "FK_updatedby='" . addslashes($_SESSION[aid]) . "'"; } else { $a[] = "FK_createdby=" . db_get_value("user", "user_id", "user_uname='" . addslashes($this->getField("addedby")) . "'"); $a[] = $this->_datafields[addedtimestamp][1][0] . "='" . addslashes($this->getField("addedtimestamp")) . "'"; $a[] = "FK_updatedby=" . db_get_value("user", "user_id", "user_uname='" . addslashes($this->getField("editedby")) . "'"); $a[] = $this->_datafields[editedtimestamp][1][0] . "='" . addslashes($this->getField("editedtimestamp")) . "'"; } // insert media (url) if ($this->data[url] && ($this->data['type'] == 'link' || $this->data['type'] == 'rss')) { // first see, if media item already exists in media table $query = "\n\t\t\t\tSELECT\n\t\t\t\t\tmedia_id\n\t\t\t\tFROM\n\t\t\t\t\tmedia\n\t\t\t\tWHERE\n\t\t\t\t\tFK_site = '" . addslashes($this->owningSiteObj->id) . "' AND\n\t\t\t\t\tFK_createdby = '" . addslashes($_SESSION[aid]) . "' AND\n\t\t\t\t\tmedia_tag = '" . addslashes($this->data[url]) . "' AND\n\t\t\t\t\tmedia_location = 'remote'\n\t\t\t"; $r = db_query($query); // if not in media table insert it if (!db_num_rows($r)) { $query = "\n\t\t\t\t\tINSERT INTO \n\t\t\t\t\t\tmedia\n\t\t\t\t\tSET\n\t\t\t\t\t\tFK_site = '" . addslashes($this->owningSiteObj->id) . "',\n\t\t\t\t\t\tFK_createdby = '" . addslashes($_SESSION[aid]) . "',\n\t\t\t\t\t\tmedia_tag = '" . addslashes($this->data[url]) . "',\n\t\t\t\t\t\tmedia_location = 'remote',\n\t\t\t\t\t\tFK_updatedby = '" . addslashes($_SESSION[aid]) . "'\n\t\t\t\t"; db_query($query); $a[] = "FK_media=" . lastid(); } else { $arr = db_fetch_assoc($r); $a[] = "FK_media='" . addslashes($arr[media_id]) . "'"; } } $query = "INSERT INTO story SET " . implode(",", $a); db_query($query); $this->id = lastid(); /****************************************************************************** * get story text, convert wiki links to internal links ******************************************************************************/ // $text = $this->getField("shorttext"); // $text = convertWikiMarkupToLinks($this->owning_site, $this->owning_section, $this->owning_page, $this->id, "page", $text); // $text = recordInternalLinks ($_SESSION[settings][site],$_SESSION[settings][section],$_SESSION[settings][page], $page_title, $text); // $shorttext = convertInteralLinksToTags($this->owning_site, $text); // $text = $this->getField("longertext"); // $text = convertWikiMarkupToLinks($this->owning_site, $this->owning_section, $this->owning_page, $this->id, "page", $text); // $text = recordInternalLinks ($_SESSION[settings][site],$_SESSION[settings][section],$_SESSION[settings][page], $page_title, $text); // $longertext = convertInteralLinksToTags($this->owning_site, $text); // update table with new short and long text // $query = "UPDATE // story // SET // story_text_short ='".addslashes($shorttext)."', // story_text_long ='".addslashes($longertext)."' // WHERE // story_id ='".addslashes($this->id)."' // "; // // db_query($query); // // See if there is a site hash (meaning that we are being copied). // If so, try to match our id with the hash entry for 'NEXT'. if ($GLOBALS['__site_hash']['stories'] && ($oldId = array_search('NEXT', $GLOBALS['__site_hash']['stories']))) { $GLOBALS['__site_hash']['stories'][$oldId] = $this->id; } $this->fetchUp(); /* $this->owningPageObj->addStory($this->id); */ if ($removeOrigional) { $this->owningPageObj->delStory($origid, 0); $this->owningPageObj->updateDB(); } /****************************************************************************** * update the page updated timestamp ******************************************************************************/ $query = "\n\t\t\t\tUPDATE \n\t\t\t\t\tpage \n\t\t\t\tSET \n\t\t\t\t\tpage_updated_tstamp = NOW()\n\t\t\t\tWHERE \n\t\t\t\t\tpage_id='" . addslashes($this->getField("page_id")) . "'\n\t\t\t"; db_query($query); /****************************************************************************** * Update version table ******************************************************************************/ save_version($this->getField("shorttext"), $this->getField("longertext"), $this->id, $this->version_comments); // add new permissions entry.. force update $this->updatePermissionsDB(1); if ($keepDiscussions && $this->fetcheddown && $this->data[discussions]) { $idMapping = array(); $discussionData = array(); // The discussions objects are way to f****d up to use to copy the // posts so we are going to have to do this 'maunally'. // Fetch all of the discussling data foreach ($this->data[discussions] as $discussionId) { // Get all the posts and dump their properties into an array. $query = "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t*\n\t\t\t\t\tFROM\n\t\t\t\t\t\tdiscussion\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tdiscussion_id='" . addslashes($discussionId) . "'"; $r = db_query($query); $discussionData[$discussionId] = db_fetch_assoc($r); } // Insert new posts, pointing to the new story foreach (array_keys($discussionData) as $oldId) { // Insert the post $query = "INSERT INTO\n\t\t\t\t\t\tdiscussion\n\t\t\t\t\tSET"; // Set the FK_story to our new story ID $discussionData[$oldId]['FK_story'] = $this->id; // Add the rest of the fields. $i = 0; foreach ($discussionData[$oldId] as $field => $val) { if ($field != 'discussion_id' && $val) { $query .= "\n\t" . ($i == 0 ? "" : ", ") . $field . "='" . addslashes($val) . "'"; $i++; } } $r = db_query($query); // store the id mapping $idMapping[$oldId] = lastid(); if ($GLOBALS['__site_hash']['discussions']) { $GLOBALS['__site_hash']['discussions'][$oldId] = lastid(); } } // go through and update all of the FK_parents to point to the new Ids. // Also, rebuild the discussions array in case we try to access it after // the copy. $this->data[discussions] = array(); foreach (array_keys($discussionData) as $oldId) { $newId = $idMapping[$oldId]; $this->data[discussions][] = $newId; // If we were a reply, update our parent key if ($discussionData[$oldId]['FK_parent']) { $query = "\n\t\t\t\t\t\tUPDATE\n\t\t\t\t\t\t\tdiscussion\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\tFK_parent = '" . addslashes($idMapping[$discussionData[$oldId]['FK_parent']]) . "',\n\t\t\t\t\t\t\tdiscussion_tstamp = '" . addslashes($discussionData[$oldId]['discussion_tstamp']) . "'\n\t\t\t\t\t\t\t\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tdiscussion_id = '" . addslashes($newId) . "'\n\t\t\t\t\t"; // printpre($query); $res = db_query($query); } } } // Update any story tags if (is_array($storyTags)) { save_record_tags($storyTags, null, $this->id, $_SESSION[aid], "story"); } return true; }