Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ############## Add this in *_post_box.tpl where you want your form to appear
- <tr>
- <td class="postblock">
- {t}File URL{/t}</td>
- <td>
- <input type="text" name="fileurl" size="48" accesskey="h"/>
- </td>
- </tr>
- ############## then add this in upload.class.php
- function HandleUploadURL() {
- global $tc_db, $board_class, $is_oekaki, $oekaki;
- if (!$is_oekaki) {
- if ($board_class->board['type'] == 0 || $board_class->board['type'] == 2 || $board_class->board['type'] == 3) {
- $fileurl = isset($_POST['fileurl']) ? $_POST['fileurl'] : '';
- if ($fileurl != '') {
- $fileurl_size = remote_filesize($fileurl);
- if ($fileurl_size <= 0) {
- exitWithErrorPage(_gettext('link to image is not valid'));
- }
- if ($fileurl_size > $board_class->board['maximagesize']) {
- exitWithErrorPage(sprintf(_gettext('Please make sure your file is smaller than %dB'), $board_class->board['maximagesize']));
- }
- $this->file_type = strrchr($fileurl, ".");
- if ($this->file_type == "") {
- exitWithErrorPage(_gettext("the file extension is incorrect"));
- }
- if ($this->file_type == '.jpeg') {
- /* Fix for the rarely used 4-char format */
- $this->file_type = '.jpg';
- }
- $tmpfname = tempnam(sys_get_temp_dir(), "FOO");
- $tmp_file = fopen($tmpfname, "w");
- $fileurl_read = fopen ($fileurl, "rb");
- if ($fileurl_read) {
- while(!feof($fileurl_read)) {
- fwrite($tmp_file, fread($fileurl_read, 1024 * 8 ), 1024 * 8 );
- }
- } else {
- //closeAll($fileurl_read, $tmp_file, $tmpfname);
- exitWithErrorPage(_gettext('link to image is not valid'));
- }
- fclose($fileurl_read);
- $this->file_name = substr(htmlspecialchars(basename($fileurl, $this->file_type), ENT_QUOTES), 0, 50);
- $this->file_name = str_replace('.','_',$this->file_name);
- $this->original_file_name = $this->file_name;
- $this->file_md5 = md5_file($tmpfname);
- $exists_thread = checkMd5($this->file_md5, $board_class->board['name'], $board_class->board['id']);
- if (is_array($exists_thread)) {
- //closeTemp($tmp_file, $tmpfname);
- exitWithErrorPage(_gettext('Duplicate file entry detected.'), sprintf(_gettext('Already posted %shere%s.'),'<a href="' . KU_BOARDSPATH . '/' . $board_class->board['name'] . '/res/' . $exists_thread[0] . '.html#' . $exists_thread[1] . '">','</a>'));
- }
- if (strtolower($this->file_type) == 'svg') {
- require_once 'svg.class.php';
- $svg = new Svg($tmpfname);
- $this->imgWidth = $svg->width;
- $this->imgHeight = $svg->height;
- } else {
- $imageDim = getimagesize($tmpfname);
- $this->imgWidth = $imageDim[0];
- $this->imgHeight = $imageDim[1];
- }
- $this->file_type = strtolower($this->file_type);
- $this->file_size = $fileurl_size;
- $filetype_forcethumb = $tc_db->GetOne("SELECT " . KU_DBPREFIX . "filetypes.force_thumb FROM " . KU_DBPREFIX . "boards, " . KU_DBPREFIX . "filetypes, " . KU_DBPREFIX . "board_filetypes WHERE " . KU_DBPREFIX . "boards.id = " . KU_DBPREFIX . "board_filetypes.boardid AND " . KU_DBPREFIX . "filetypes.id = " . KU_DBPREFIX . "board_filetypes.typeid AND " . KU_DBPREFIX . "boards.name = '" . $board_class->board['name'] . "' and " . KU_DBPREFIX . "filetypes.filetype = '" . substr($this->file_type, 1) . "';");
- if ($filetype_forcethumb != '') {
- if ($filetype_forcethumb == 0) {
- $this->file_name = time() . mt_rand(1, 99);
- $this->file_location = KU_BOARDSDIR . $board_class->board['name'] . '/src/' . $this->file_name . $this->file_type;
- $this->file_thumb_location = KU_BOARDSDIR . $board_class->board['name'] . '/thumb/' . $this->file_name . 's' . $this->file_type;
- $this->file_thumb_cat_location = KU_BOARDSDIR . $board_class->board['name'] . '/thumb/' . $this->file_name . 'c' . $this->file_type;
- if (!copy($tmpfname, $this->file_location)) {
- //closeTemp($tmp_file, $tmpfname);
- exitWithErrorPage(sprintf(_gettext('Could not copy uploaded image. --%s-- --%s--'), $tmpfname, $this->file_location));
- }
- chmod($this->file_location, 0644);
- if ($fileurl_size == filesize($this->file_location)) {
- if ((!$this->isreply && ($this->imgWidth > KU_THUMBWIDTH || $this->imgHeight > KU_THUMBHEIGHT)) || ($this->isreply && ($this->imgWidth > KU_REPLYTHUMBWIDTH || $this->imgHeight > KU_REPLYTHUMBHEIGHT))) {
- if (!$this->isreply) {
- if (!createThumbnail($this->file_location, $this->file_thumb_location, KU_THUMBWIDTH, KU_THUMBHEIGHT)) {
- //closeTemp($tmp_file, $tmpfname);
- exitWithErrorPage(_gettext('Could not create thumbnail.'));
- }
- } else {
- if (!createThumbnail($this->file_location, $this->file_thumb_location, KU_REPLYTHUMBWIDTH, KU_REPLYTHUMBHEIGHT)) {
- //closeTemp($tmp_file, $tmpfname);
- exitWithErrorPage(_gettext('Could not create thumbnail.'));
- }
- }
- } else {
- if (!createThumbnail($this->file_location, $this->file_thumb_location, $this->imgWidth, $this->imgHeight)) {
- //closeTemp($tmp_file, $tmpfname);
- exitWithErrorPage(_gettext('Could not create thumbnail.'));
- }
- }
- if (!createThumbnail($this->file_location, $this->file_thumb_cat_location, KU_CATTHUMBWIDTH, KU_CATTHUMBHEIGHT)) {
- //closeTemp($tmp_file, $tmpfname);
- exitWithErrorPage(_gettext('Could not create thumbnail.'));
- }
- $imageDim_thumb = getimagesize($this->file_thumb_location);
- $this->imgWidth_thumb = $imageDim_thumb[0];
- $this->imgHeight_thumb = $imageDim_thumb[1];
- $imageused = true;
- } else {
- //closeTemp($tmp_file, $tmpfname);
- exitWithErrorPage(sprintf(_gettext('File was not fully uploaded. Please go back and try again. %s %s'), $fileurl_size, filesize($this->file_location)));
- }
- } else {
- /* Fetch the mime requirement for this special filetype */
- $filetype_required_mime = $tc_db->GetOne("SELECT `mime` FROM `" . KU_DBPREFIX . "filetypes` WHERE `filetype` = " . $tc_db->qstr(substr($this->file_type, 1)));
- $this->file_name = htmlspecialchars_decode($this->file_name, ENT_QUOTES);
- $this->file_name = stripslashes($this->file_name);
- $this->file_name = str_replace("\x80", " ", $this->file_name);
- $this->file_name = str_replace(' ', '_', $this->file_name);
- $this->file_name = str_replace('#', '(number)', $this->file_name);
- $this->file_name = str_replace('@', '(at)', $this->file_name);
- $this->file_name = str_replace('/', '(fwslash)', $this->file_name);
- $this->file_name = str_replace('\\', '(bkslash)', $this->file_name);
- $this->file_location = KU_BOARDSDIR . $board_class->board['name'] . '/src/' . $this->file_name . $this->file_type;
- if($this->file_type == '.mp3') {
- require_once(KU_ROOTDIR . 'lib/getid3/getid3.php');
- $getID3 = new getID3;
- $getID3->analyze($tmpfname);
- if (isset($getID3->info['id3v2']['APIC'][0]['data']) && isset($getID3->info['id3v2']['APIC'][0]['image_mime'])) {
- $source_data = $getID3->info['id3v2']['APIC'][0]['data'];
- $mime = $getID3->info['id3v2']['APIC'][0]['image_mime'];
- }
- elseif (isset($getID3->info['id3v2']['PIC'][0]['data']) && isset($getID3->info['id3v2']['PIC'][0]['image_mime'])) {
- $source_data = $getID3->info['id3v2']['PIC'][0]['data'];
- $mime = $getID3->info['id3v2']['PIC'][0]['image_mime'];
- }
- if($source_data) {
- $im = imagecreatefromstring($source_data);
- if (preg_match("/png/", $mime)) {
- $ext = ".png";
- imagepng($im,$this->file_location.".tmp",0,PNG_ALL_FILTERS);
- } else if (preg_match("/jpg|jpeg/", $mime)) {
- $ext = ".jpg";
- imagejpeg($im, $this->file_location.".tmp");
- } else if (preg_match("/gif/", $mime)) {
- $ext = ".gif";
- imagegif($im, $this->file_location.".tmp");
- }
- $this->file_thumb_location = KU_BOARDSDIR . $board_class->board['name'] . '/thumb/' . $this->file_name .'s'. $ext;
- if (!$this->isreply) {
- if (!createThumbnail($this->file_location.".tmp", $this->file_thumb_location, KU_THUMBWIDTH, KU_THUMBHEIGHT)) {
- //closeTemp($tmp_file, $tmpfname);
- exitWithErrorPage(_gettext('Could not create thumbnail.'));
- }
- } else {
- if (!createThumbnail($this->file_location.".tmp", $this->file_thumb_location, KU_REPLYTHUMBWIDTH, KU_REPLYTHUMBHEIGHT)) {
- //closeTemp($tmp_file, $tmpfname);
- exitWithErrorPage(_gettext('Could not create thumbnail.'));
- }
- }
- $imageDim_thumb = getimagesize($this->file_thumb_location);
- $this->imgWidth_thumb = $imageDim_thumb[0];
- $this->imgHeight_thumb = $imageDim_thumb[1];
- $imageused = true;
- unlink($this->file_location.".tmp");
- }
- }
- /* Move the file from the post data to the server */
- if (!copy($tmpfname, $this->file_location)) {
- //closeTemp($tmp_file, $tmpfname);
- exitWithErrorPage(_gettext('Could not copy uploaded image.'));
- }
- /* Check if the filetype provided comes with a MIME restriction */
- if ($filetype_required_mime != '') {
- /* Check if the MIMEs don't match up */
- if (mime_content_type($this->file_location) != $filetype_required_mime) {
- //closeTemp($tmp_file, $tmpfname);
- /* Delete the file we just uploaded and kill the script */
- unlink($this->file_location);
- exitWithErrorPage(_gettext('Invalid MIME type for this filetype.'));
- }
- }
- /* Make sure the entire file was uploaded */
- if ($fileurl_size == filesize($this->file_location)) {
- $imageused = true;
- } else {
- //closeTemp($tmp_file, $tmpfname);
- exitWithErrorPage(_gettext('File transfer failure. Please go back and try again.'));
- }
- /* Flag that the file used isn't an internally supported type */
- $this->file_is_special = true;
- }
- } else {
- //closeTemp($tmp_file, $tmpfname);
- exitWithErrorPage(_gettext('Sorry, that filetype is not allowed on this board.'));
- }
- //closeTemp($tmp_file, $tmpfname);
- }
- }
- }
- }
- ############## then add this to misc.php
- function remote_filesize($url){
- $uh = curl_init();
- curl_setopt($uh, CURLOPT_URL, $url);
- // set NO-BODY to not receive body part
- curl_setopt($uh, CURLOPT_NOBODY, TRUE);
- // set HEADER to be false, we don't need header
- curl_setopt($uh, CURLOPT_HEADER, FALSE);
- curl_exec($uh);
- // assign filesize into $filesize variable
- $filesize = curl_getinfo($uh,CURLINFO_CONTENT_LENGTH_DOWNLOAD);
- curl_close($uh);
- if ($filesize <= 0) {
- $string = @implode('', file($url));
- $filesize = strlen($string);
- }
- return $filesize;
- }
- ############## then in board.php find this "if"
- if ((!isset($_POST['nofile']) && $board_class->board['enablenofile'] == 1) || $board_class->board['enablenofile'] == 0) {
- ############## and change to this
- if ((!isset($_POST['nofile']) && $board_class->board['enablenofile'] == 1) || $board_class->board['enablenofile'] == 0) {
- if (!isset($_POST['fileurl']) || empty($_POST['fileurl']))
- $upload_class->HandleUpload();
- else
- $upload_class->HandleUploadURL();
- }
- ############## always in board.php find this "if"
- if ($board_class->board['type'] != 1 && (($board_class->board['uploadtype'] == '1' || $board_class->board['uploadtype'] == '2') && $board_class->board['embeds_allowed'] != '')) {
- ############## and change to this
- if ($board_class->board['type'] != 1 && (($board_class->board['uploadtype'] == '1' || $board_class->board['uploadtype'] == '2') && $board_class->board['embeds_allowed'] != '')) {
- if (isset($_POST['embed'])) {
- if ($_POST['embed'] == '') {
- if (($board_class->board['uploadtype'] == '1' && $imagefile_name == '') || $board_class->board['uploadtype'] == '2') {
- if (isset($_POST['fileurl']) && empty($_POST['fileurl']))
- exitWithErrorPage('Please enter an embed ID.');
- }
- }
- } else {
- if (isset($_POST['fileurl']) && empty($_POST['fileurl']))
- exitWithErrorPage('Please enter an embed ID.');
- }
- }
- ############## again in board.php find this
- if ($imagefile_name == '' && !$is_oekaki && ((!isset($_POST['nofile'])&&$board_class->board['enablenofile']==1) || $board_class->board['enablenofile']==0) && ($board_class->board['type'] == 0 || $board_class->board['type'] == 2 || $board_class->board['type'] == 3)) {
- if (!isset($_POST['embed']) && $board_class->board['uploadtype'] != 1) {
- exitWithErrorPage(_gettext('A file is required for a new thread. If embedding is allowed, either a file or embed ID is required.'));
- }
- }
- ############## replace with this
- if ($imagefile_name == '' && !$is_oekaki && ((!isset($_POST['nofile'])&&$board_class->board['enablenofile']==1) || $board_class->board['enablenofile']==0) && ($board_class->board['type'] == 0 || $board_class->board['type'] == 2 || $board_class->board['type'] == 3) && !isset($_POST['fileurl']) && !empty($_POST['fileurl'])) {
- if (!isset($_POST['embed']) && $board_class->board['uploadtype'] != 1) {
- exitWithErrorPage(_gettext('A file is required for a new thread. If embedding is allowed, either a file or embed ID is required.'));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment