db::ping(); $emergency_apns = array('aps' => array('alert' => substr($data[0]['text'], 0, 100), 'sound' => 'default') ); $result = APNS_DB::get_all_devices(); while($row = $result->fetch_assoc()) { APNS_DB::create_notification($row['device_id'], "emergencyinfo:", $emergency_apns); } $result->close(); } if($new_version > 0) { $version = $new_version; save_version($version); } } $daemon->stop(); /* these functions are for saving and grabbing the emergency version from disk that way the daemon is robust to being restarted */ function version_file_name() { return getenv('WSETCDIR') . "/pushd/emergency/last_emergency_version"; } function get_version() { if(file_exists(version_file_name())) {
if ($storyObj->getField('title')) { printc(" > " . spchars($storyObj->getField('title'))); } /****************************************************************************** * if request is to revert, then create new version based on revert version number ******************************************************************************/ if ($_REQUEST['revert']) { $version = get_versions($storyObj->id, $_REQUEST['revert']); $version_num = $version[0]['version_order']; $version_short = stripslashes(urldecode($version[0]['version_text_short'])); $version_long = stripslashes(urldecode($version[0]['version_text_long'])); $story_id = $_REQUEST['story']; $version_comments = "reverted to revision " . $_REQUEST['revert']; // printpre($version_short); // exit; save_version($version_short, $version_long, $story_id, $version_comments); } if ($_REQUEST['oldversion'] && $_REQUEST['newversion']) { if (!isset($_SESSION['oldversion']) || !is_array($_SESSION['oldversion'])) { $_SESSION['oldversion'] = array(); } if (!isset($_SESSION['newversion']) || !is_array($_SESSION['newversion'])) { $_SESSION['newversion'] = array(); } $_SESSION['oldversion'][$_REQUEST['story']] = $_REQUEST['oldversion']; $_SESSION['newversion'][$_REQUEST['story']] = $_REQUEST['newversion']; printc(" > <a href='index.php?{$sid}&action=" . $action . "&site=" . $_REQUEST['site'] . "&section=" . $_REQUEST['section'] . "&page=" . $_REQUEST['page'] . "&story=" . $_REQUEST['story'] . "&versioning=" . $_REQUEST['story'] . "'>All Versions</a>"); printc(" > Selected Versions"); } else { if ($_REQUEST['versioning']) { printc(" > All Versions");
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; }