예제 #1
0
     if (!$new_name) {
         $error_msg .= $lang['file_upload_error'] . ": <b>" . $HTTP_POST_FILES['file']['name'] . "</b><br />" . $site_upload->get_upload_errors();
         @rename(MEDIA_PATH . "/" . $old_cat_id . "/" . $old_file_name . ".bak", MEDIA_PATH . "/" . $old_cat_id . "/" . $old_file_name);
         $error = 1;
     } else {
         unlink(MEDIA_PATH . "/" . $old_cat_id . "/" . $old_file_name . ".bak");
         $log[] = $lang['file_upload_success'] . ": <b>{$new_name}</b>";
     }
 } elseif ((empty($HTTP_POST_FILES['file']['tmp_name']) || $HTTP_POST_FILES['file']['tmp_name'] == "none") && $remote_file != "" && (check_remote_media($remote_file) || check_local_media($remote_file))) {
     $new_name = $remote_file;
     if (file_exists(MEDIA_PATH . "/" . $old_cat_id . "/" . $old_file_name) && is_file(MEDIA_PATH . "/" . $old_cat_id . "/" . $old_file_name)) {
         unlink(MEDIA_PATH . "/" . $old_cat_id . "/" . $old_file_name);
     }
 } else {
     if ($cat_id != $old_cat_id && !empty($old_file_name)) {
         $new_name = copy_media($old_file_name, $old_cat_id, $cat_id);
     } else {
         $new_name = $old_file_name;
     }
 }
 if ($delete_thumb_file == 1) {
     if (!empty($old_thumb_file_name) && file_exists(THUMB_PATH . "/" . $old_cat_id . "/" . $old_thumb_file_name)) {
         unlink(THUMB_PATH . "/" . $old_cat_id . "/" . $old_thumb_file_name);
     }
     $new_thumb_name = "";
     unset($HTTP_POST_VARS['remote_thumb_file']);
 } elseif (!empty($HTTP_POST_FILES['thumb_file']['tmp_name']) && $HTTP_POST_FILES['thumb_file']['tmp_name'] != "none" && !$error) {
     unset($HTTP_POST_VARS['remote_thumb_file']);
     @rename(THUMB_PATH . "/" . $old_cat_id . "/" . $old_thumb_file_name, THUMB_PATH . "/" . $old_cat_id . "/" . $old_thumb_file_name . ".bak");
     $new_thumb_name = $site_upload->upload_file("thumb_file", "thumb", $cat_id, get_basefile($new_name));
     if (!$new_thumb_name) {
예제 #2
0
     $table_fields = $site_db->get_table_fields(IMAGES_TABLE);
     foreach ($additional_image_fields as $key => $val) {
         if (isset($HTTP_POST_VARS[$key . '_' . $i]) && isset($table_fields[$key])) {
             $additional_field_sql .= ", {$key}";
             $additional_value_sql .= ", '" . un_htmlspecialchars(trim($HTTP_POST_VARS[$key . '_' . $i])) . "'";
         }
     }
 }
 $file = MEDIA_PATH . ($old_cat_id != 0 ? "/" . $old_cat_id : "") . "/" . $image_media_file;
 $big_dir = MEDIA_PATH . "/" . $old_cat_id . "/" . $big_folder;
 $big_file = "";
 $log[] = str_replace("{file}", str_replace(ROOT_PATH, "", $file), $lang['cni_working']);
 if (file_exists($file)) {
     $image_media_file_backup = $image_media_file;
     if ($cat_id != $old_cat_id) {
         $image_media_file = copy_media($image_media_file, $old_cat_id, $cat_id);
         if ($image_media_file && file_exists(MEDIA_PATH . "/" . $cat_id . "/" . $image_media_file)) {
             $log[] = str_replace("{name}", MEDIA_DIR . "/" . $cat_id, $lang['cni_copy_success']);
         } else {
             $log[] = str_replace("{name}", MEDIA_DIR . "/" . $cat_id, $lang['cni_copy_error']);
             $error_major = 1;
         }
         if ($image_thumb_file = copy_thumbnail($image_media_file_backup, $image_thumb_file, $old_cat_id, $cat_id)) {
             if (file_exists(THUMB_PATH . "/" . $cat_id . "/" . $image_thumb_file)) {
                 $log[] = str_replace("{name}", THUMB_DIR . "/" . $cat_id, $lang['cni_copy_success']);
             } else {
                 $log[] = str_replace("{name}", THUMB_DIR . "/" . $cat_id, $lang['cni_copy_error']);
             }
         }
         if (!$error_major && $big) {
             if (file_exists($big_dir . "/" . $image_media_file_backup)) {
예제 #3
0
 }
 foreach ($image_list as $key => $val) {
     flush();
     $image_name = addslashes($image_cache[$key]['image_name']);
     $cat_id = $image_cache[$key]['cat_id'];
     $user_id = $image_cache[$key]['user_id'];
     $image_description = addslashes($image_cache[$key]['image_description']);
     $image_keywords = addslashes($image_cache[$key]['image_keywords']);
     $image_date = $image_cache[$key]['image_date'];
     $image_media_file = addslashes($image_cache[$key]['image_media_file']);
     $image_thumb_file = addslashes($image_cache[$key]['image_thumb_file']);
     $image_download_url = addslashes($image_cache[$key]['image_download_url']);
     $old_media_path = MEDIA_TEMP_PATH . "/" . $image_media_file;
     $old_thumb_path = THUMB_TEMP_PATH . "/" . $image_thumb_file;
     if ($val == 1) {
         $new_name = copy_media($image_media_file, "-1", $cat_id);
         $new_thumb_name = copy_thumbnail($new_name, $image_thumb_file, "-1", $cat_id);
         if ($new_name) {
             $additional_field_sql = "";
             $additional_value_sql = "";
             if (!empty($additional_image_fields)) {
                 $table_fields = $site_db->get_table_fields(IMAGES_TABLE);
                 foreach ($additional_image_fields as $key2 => $val2) {
                     if (isset($image_cache[$key][$key2]) && isset($image_cache[$key][$key2])) {
                         $additional_field_sql .= ", {$key2}";
                         $additional_value_sql .= ", '" . addslashes($image_cache[$key][$key2]) . "'";
                     }
                 }
             }
             $current_time = time();
             $sql = "INSERT INTO " . IMAGES_TABLE . "\n                  (cat_id, user_id, image_name, image_description, image_keywords, image_date, image_media_file, image_thumb_file, image_download_url" . $additional_field_sql . ")\n                  VALUES\n                  ({$cat_id}, {$user_id}, '{$image_name}', '{$image_description}', '{$image_keywords}', {$current_time}, '{$new_name}', '{$new_thumb_name}', '{$image_download_url}'" . $additional_value_sql . ")";
예제 #4
0
function copy_media_with_fname($fname, $oldsitename, $newsitename)
{
    $mediaid = db_get_value("media INNER JOIN slot ON media.FK_site = slot.FK_site", "media_id", "slot_name='" . addslashes($oldsitename) . "' AND media_tag='" . addslashes($fname) . "'");
    return copy_media($mediaid, $newsitename);
}
예제 #5
0
 function replaceMediaIDs($ids, $field, $newsite)
 {
     $string = $this->getField($field);
     foreach ($ids as $origID) {
         $newID = copy_media($origID, $newsite);
         $string = str_replace("####{$origID}####", "####{$newID}####", $string);
     }
     $this->setField($field, $string);
 }
예제 #6
0
 function copySite($newName, $clearPermissions = 1, $copyDiscussions = FALSE)
 {
     if ($newName == $this->name) {
         return FALSE;
     }
     if ($newName == "" || !$newName) {
         return FALSE;
     }
     $oldName = $this->name;
     $this->fetchSiteAtOnceForeverAndEverAndDontForgetThePermissionsAsWell_Amen();
     // Make a hash array of site, section, and page ids so that
     makeSiteHash($this);
     $newSiteObj = $this;
     $newSiteObj->setSiteName($newName, 1);
     // Since we are specifying TRUE for the 'copy' option, each
     // part should add its new id to the global hash
     $newSiteObj->insertDB(1, 1, 0, $copyDiscussions);
     // Copy all the media
     $query = "\n\t\t\tSELECT\n\t\t\t\tmedia_id\n\t\t\tFROM\n\t\t\t\tmedia\n\t\t\t\t\tINNER JOIN\n\t\t\t\tslot\n\t\t\t\t\tON\n\t\t\t\t\t\tmedia.FK_site = slot.FK_site\n\t\t\tWHERE\n\t\t\t\tslot_name='" . addslashes($oldName) . "'\n\t\t\t\tAND \n\t\t\t\tmedia_type != 'other'\n\t\t";
     $r = db_query($query);
     while ($a = db_fetch_assoc($r)) {
         copy_media($a['media_id'], $newName);
     }
     $newSiteObj = NULL;
     unset($newSiteObj);
     $newSiteObj = new site($newName);
     $newSiteObj->fetchSiteAtOnceForeverAndEverAndDontForgetThePermissionsAsWell_Amen();
     // Remove the permissions if we are clearing them.
     if ($clearPermissions) {
         $editors = $newSiteObj->getEditors();
         foreach ($editors as $editor) {
             $newSiteObj->delEditor($editor);
         }
     }
     // Parse through all the text for links refering to parts of the
     // old site and update them with the new ids.
     updateSiteLinksFromHash($newSiteObj, $newSiteObj);
     $newSiteObj->updateDB(1, 1);
     // Delete any editors that we wanted to delete.
     $newSiteObj->deletePendingEditors();
 }
예제 #7
0
 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;
 }