// ---------------------------------------------------------------------- // Handle storing a newly uploaded file. // ---------------------------------------------------------------------- if (!empty($_FILES) && is_uploaded_file($_FILES["newfile"]["tmp_name"])) { // Read in the uploaded file. if (!empty($_FILES["newfile"]["size"])) { $fp = fopen($_FILES["newfile"]["tmp_name"], "r"); $file_data = fread($fp, $_FILES["newfile"]["size"]); fclose($fp); } else { $file_data = ""; } // Create the file array for the file storage API. $file = array("user_id" => $PHORUM["user"]["user_id"], "filename" => $_FILES["newfile"]["name"], "filesize" => $_FILES["newfile"]["size"], "file_data" => $file_data, "link" => PHORUM_LINK_USER); // Store the file. if (!phorum_api_file_check_write_access($file) || !phorum_api_file_store($file)) { $PHORUM["DATA"]["ERROR"] = phorum_api_error_message(); } else { $PHORUM["DATA"]["OKMSG"] = $PHORUM["DATA"]["LANG"]["FileAdded"]; } } elseif (!empty($_POST["delete"])) { foreach ($_POST["delete"] as $file_id) { if (phorum_api_file_check_delete_access($file_id)) { phorum_api_file_delete($file_id); } } } // ---------------------------------------------------------------------- // Display the files for the current user. // ---------------------------------------------------------------------- $files = $PHORUM['DB']->get_user_file_list($PHORUM["user"]["user_id"]);
* // function * $data[1]["file_data"] = ""; * * return $data; * } * </hookcode> */ if (isset($PHORUM["hooks"]["before_attach"])) { list($message, $file) = phorum_hook("before_attach", array($message, $file)); } // Store the file. We add it using message_id 0 (zero). Only when // the message gets saved definitely, the message_id will be updated // to link the file to the forum message. This is mainly done so we // can support attachments for new messages, which do not yet have // a message_id assigned. $file = phorum_api_file_store(array("filename" => $file["name"], "file_data" => $file["data"], "filesize" => $file["size"], "link" => PHORUM_LINK_EDITOR, "user_id" => 0, "message_id" => 0)); if ($file !== FALSE) { // Create new attachment information. $new_attachment = array("file_id" => $file["file_id"], "name" => $file["filename"], "size" => $file["filesize"], "keep" => true, "linked" => false); /* * [hook] * after_attach * * [description] * The primary use of this hook would be for creating an * alternate storage system for attachments. You would need to * use the <hook>before_attach</hook> hook to remove the file * data and in this hook it could be saved properly. You will * need to use the <hook>file</hook> hook to retreive the file * data later. *
function phorum_convert_getNextMessage($res, $table_name) { global $CONVERT; // fetching the message from the database $mdata = mysql_fetch_assoc($res); if (!$mdata) { return false; } $max_id = $CONVERT['max_id']; $id = $mdata['id']; if (isset($mdata['closed']) && $mdata['closed']) { $closed = 1; } else { $closed = 0; } if ($mdata['approved'] != "Y") { $post_status = PHORUM_STATUS_HOLD; } else { $post_status = PHORUM_STATUS_APPROVED; } $post_sort = PHORUM_SORT_DEFAULT; $parentid = $mdata['parent'] > 0 ? $mdata['parent'] + $max_id : 0; if (!get_magic_quotes_runtime()) { $mdata['author'] = $mdata['author']; $mdata['subject'] = $mdata['subject']; $mdata['body'] = $mdata['body']; $mdata['email'] = $mdata['email']; } //find [%sig%] and cut it if (preg_match("/\\[%sig%\\]/", $mdata['body'])) { $mdata['body'] = preg_replace("/\\[%sig%\\]/", "", $mdata['body']); $add_signature = true; } else { $add_signature = false; } // bah, there are really people trying to upgrade from 3.2.x ;) $userid = isset($mdata['userid']) ? $mdata['userid'] : 0; // building the new message $newmessage = array('message_id' => $mdata['id'] + $max_id, 'forum_id' => $CONVERT['forum_id'], 'datestamp' => $mdata['unixtime'], 'thread' => $mdata['thread'] + $max_id, 'parent_id' => $parentid, 'author' => $mdata['author'], 'subject' => $mdata['subject'], 'email' => $mdata['email'], 'ip' => $mdata['host'], 'user_id' => $userid, 'moderator_post' => 0, 'status' => $post_status, 'sort' => $post_sort, 'msgid' => $mdata['msgid'], 'closed' => $closed, 'body' => $mdata['body']); if ($add_signature) { $newmessage["meta"]["show_signature"] = 1; } if (isset($mdata['viewcount'])) { $newmessage['viewcount'] = $mdata['viewcount']; } $newmessage['viewcount'] = isset($mdata['viewcount']) ? $mdata['viewcount'] : 0; // converting attachments if needed $inserted_files = array(); if (isset($CONVERT['attachments'][$mdata['id']]) && count($CONVERT['attachments'][$mdata['id']])) { foreach ($CONVERT['attachments'][$mdata['id']] as $attachment) { $filename = $CONVERT['attachmentdir'] . "/" . $table_name . "/" . $attachment['id'] . strtolower(strrchr($attachment['filename'], ".")); if (file_exists($filename) && filesize($filename) > 0) { $fp = fopen($filename, "r"); $buffer = fread($fp, filesize($filename)); fclose($fp); $stored_file = phorum_api_file_store(array("filename" => $attachment['filename'], "file_data" => $buffer, "filesize" => filesize($filename), "link" => PHORUM_LINK_MESSAGE, "user_id" => $userid, "message_id" => $newmessage['message_id'])); unset($buffer); // free that large buffer $inserted_files[] = array("file_id" => $stored_file['file_id'], "name" => $attachment['filename'], "size" => filesize($filename)); } } } if (count($inserted_files)) { $newmessage["meta"]["attachments"] = $inserted_files; } return $newmessage; }