urisoft Опубликовано 13 Июля 2007 Жалоба Поделиться Опубликовано 13 Июля 2007 Дополнение для mJournal v2.0pb7: Модуль загрузки файлов (mp3,doc,txt,zip)Автор: replicant Модуль загрузки файлов (mp3,doc,txt,zip)--------------------------------------------------------------------------------Затронутые файлы:------------------post_functions.phpskin_q_reply.phppost_new.phpupload_lib.php (содержимое ниже)skin_posts.phppost_render.phppost_edit.phpcomment_new.phpcomment_edit.php--------------------------------------------------------------------------------Открыть post_functions.php Находим: $data['_UPLOAD_FIELD'] = $journal->skin->html['q_reply']->upload_field($max_upload_info,$attach_field); Добавляем:$data['_UPLOAD_FIELD2'] = $journal->skin->html['q_reply']->upload_field2($max_upload_info,$attach_field); Находим функцию function add_attachment() По окончании функции добавляем еще одну: function add_attachment2() { global $ibforums, $journal, $DB; require JOURNAL_ROOT."misc/upload_lib.php"; $upload_lib = new upload_lib(); $attach_post = 0; if ($ibforums->input['attach_key'] != "") { $this->cache_attachment(); foreach ($this->attach_cache as $row) { $attach_post += $row['attach_size']; } } if ( $ibforums->cache['group_cache'][$journal->users['mgroup']]['g_j_attach_max'] > 0 ) { if ( $ibforums->cache['group_cache'][$journal->users['mgroup']]['g_j_attach_per_post'] ) { $this->main_space_left = intval( ( $ibforums->cache['group_cache'][$journal->users['mgroup']]['g_j_attach_per_post'] * 1024 ) - $attach_post ); } else { $this->get_attachment_sum(); $this->main_space_left = intval( ( $ibforums->cache['group_cache'][$journal->users['mgroup']]['g_j_attach_max'] * 1024 ) - $this->attach_sum ); } } else { if ( $ibforums->cache['group_cache'][$journal->users['mgroup']]['g_j_attach_per_post'] ) { $this->main_space_left = intval( ( $ibforums->cache['group_cache'][$journal->users['mgroup']]['g_j_attach_per_post'] * 1024 ) - $attach_post ); } else { $this->main_space_left = 1000000000; } } $ibforums->input['attach_key'] = ($ibforums->input['attach_key'] != "") ? $ibforums->input['attach_key'] : md5(microtime()); $upload_lib->max_file_size = $this->main_space_left; $upload_lib->name = "j".$journal->users['id']."_".time(); if ($upload_lib->upload('FILE_UPLOAD2')) { # $image_lib->thumb_width = $ibforums->vars['j_th_width']; # $image_lib->thumb_height = $ibforums->vars['j_th_height']; # $image_lib->make_thumbnail(); $attach_db = array( 'attach_file' => $upload_lib->name, 'attach_name' => $upload_lib->original_name, 'attach_size' => $upload_lib->file_size, 'attach_date' => time(), 'attach_temp' => 1, 'attach_pid' => 0, 'attach_cid' => 0, 'attach_journal' => $journal->users['id'], 'attach_key' => $ibforums->input['attach_key']); $db_string = $DB->compile_db_insert_string($attach_db); $DB->query("INSERT INTO ibf_jattach (" .$db_string['FIELD_NAMES']. ") VALUES (". $db_string['FIELD_VALUES'] .")"); $attach_db['attach_id'] = $DB->get_insert_id(); $this->attach_cache[$attach_db['attach_id']] = $attach_db; } return $upload_lib->error; } -------------------------------------------------------------------------------- Открываем файл skin_q_reply.php Находим функцию function attach_rows($row="") меняем в ней{$row['attach_size']} на {$row['attach_size']} (лучше смотрится) Находим function upload_field($max_upload_info="",$attach_field="") Меняем на function upload_field($max_upload_info="") В теле функции удаляем:{$max_upload_info} и {$attach_field} По окончании функции добавляем еще одну: //=========================================================================== // upload_field2 //=========================================================================== function upload_field2($max_upload_info="",$attach_field="") { global $ibforums, $journal; $IPBHTML = ""; //--starthtml--// $IPBHTML .= <<<EOF <tr> <td class='post'>{$ibforums->lang['j_upload_text2']}</td> <td class='post'><input class='input' type='file' size='40' name='FILE_UPLOAD2' /> <input class='button' type="submit" name="postattach2" onclick="skip_check=1" value="{$ibforums->lang['j_add_btn']}" /> </td> </tr> <tr> <td class='post'>{$max_upload_info}</td> <td class='post'>{$attach_field}</td> </tr> EOF; //--endhtml--// return $IPBHTML; } Находим 2 вхождения {$data['_UPLOAD_FIELD']} и после каждого добавляем: {$data['_UPLOAD_FIELD2']} --------------------------------------------------------------------------------Открываем post_new.php Находим:// Upload attach И меняем весь if на следующее сочетание: if (($this->post_func->allow_upload())&&($ibforums->input['postattach']!="")) { $this_error = $this->post_func->add_attachment(); if ($ibforums->input['postattach']) { $ibforums->input['preview_post'] = 1; $skip_check_error = 1; } } elseif (($this->post_func->allow_upload())&&($ibforums->input['postattach2']!="")) { $this_error = $this->post_func->add_attachment2(); if ($ibforums->input['postattach2']) { $ibforums->input['preview_post'] = 1; $skip_check_error = 1; } } -------------------------------------------------------------------------------- Создаем новый файл upload_lib.php в директории /misc со следующим содержанием:<?php if (!defined('IN_JOURNAL')) { print "<h1>Incorrect access</h1>You cannot access this file directly."; exit(); } class upload_lib { var $original_name = ''; var $name = ''; var $path = ''; var $type = ''; // jpeg options var $mime_allowed = array ( 'image/x-png' => '.png', 'image/png' => '.png', 'image/gif' => '.gif', 'image/jpeg' => '.jpg', 'image/jpg' => '.jpg', 'image/pjpeg' => '.jpg', 'application/x-zip-compressed' => '.zip', 'application/zip' => '.zip', 'audio/mpeg' => '.mp3', 'audio/x-mpeg' => '.mp3', 'audio/mp3' => '.mp3', 'application/msword' => '.doc', 'text/plain' => '.txt'); var $error = ''; function upload_lib() { global $ibforums; $this->path = $ibforums->vars['j_upload_dir']; } function upload($form_name='FILE_UPLOAD2') { global $ibforums; $this->error = ''; // Return if we don't have a file to upload if (trim($_FILES[$form_name]['name']) == "" or !$_FILES[$form_name]['name'] or $_FILES[$form_name]['name'] == "none") { return FALSE; } $this->type = preg_replace( "/^(.+?);.*$/", "\\1", $_FILES[$form_name]['type']); $this->original_name = preg_replace( "/[^\w\.]/", "_", $_FILES[$form_name]['name']); $this->file_size = $_FILES[$form_name]['size']; // Check the file size if ($this->file_size > $this->max_file_size) { $this->error = $ibforums->lang['j_err_dl_big']; return FALSE; } // Check image by mime if(!isset($this->mime_allowed[$this->type])) { $this->error = $ibforums->lang['j_err_dl_type']; return FALSE; } // Make local name if (trim($this->name) == "") { $this->name = "j_".time(); } $this->name .= $this->mime_allowed[$this->type]; // Copy the upload to the uploads directory if (! @move_uploaded_file( $_FILES[$form_name]['tmp_name'], $this->path.'/'.$this->name) ) { $this->error = $ibforums->lang['j_err_dl_file']; return FALSE; } else { @chmod( $this->path.'/'.$this->name, 0777 ); } return TRUE; } } ?>--------------------------------------------------------------------------------Открываем skin_posts.php Находим функцию function attachments_img_thumb По окончании оной добавляем: //=========================================================================== // attachments_file //=========================================================================== function attachments_file($file_name="",$file="") { global $ibforums, $journal; $IPBHTML = ""; //--starthtml--// $IPBHTML .= <<<EOF <a href='{$ibforums->vars['j_upload_url']}/{$file_name}' target='_blank'>{$file}</a> EOF; //--endhtml--// return $IPBHTML; } --------------------------------------------------------------------------------Открываем post_render.php Находим функцию function get_attachment($row) В теле функции есть последняя строчка: return $journal->skin->html['posts']->attachments_img( $row['attach_file'] ); ПЕРЕД ней добавляем: if (($row['attach_width'] == 0) and ($row['attach_height']) == 0) { return $journal->skin->html['posts']->attachments_file($row['attach_file'],$row['attach_name']); } --------------------------------------------------------------------------------Открываем post_edit.php Находим:// Upload attach И меняем весь if на следующее сочетание: if (($this->post_func->allow_upload())&&($ibforums->input['postattach']!="")) { $this_error = $this->post_func->add_attachment(); if ($ibforums->input['postattach']) { $ibforums->input['preview_post'] = 1; $skip_check_error = 1; } } elseif (($this->post_func->allow_upload())&&($ibforums->input['postattach2']!="")) { $this_error = $this->post_func->add_attachment2(); if ($ibforums->input['postattach2']) { $ibforums->input['preview_post'] = 1; $skip_check_error = 1; } } }--------------------------------------------------------------------------------Открываем comment_new.php Находим:// Upload attach И меняем весь if на следующее сочетание: if (($this->post_func->allow_upload())&&($ibforums->input['postattach']!="")) { $this_error = $this->post_func->add_attachment(); if ($ibforums->input['postattach']) { $ibforums->input['preview_post'] = 1; $skip_check_error = 1; } } elseif (($this->post_func->allow_upload())&&($ibforums->input['postattach2']!="")) { $this_error = $this->post_func->add_attachment2(); if ($ibforums->input['postattach2']) { $ibforums->input['preview_post'] = 1; $skip_check_error = 1; } } }--------------------------------------------------------------------------------Открываем comment_edit.php Находим:// Upload attach И меняем весь if на следующее сочетание: if (($this->post_func->allow_upload())&&($ibforums->input['postattach']!="")) { $this_error = $this->post_func->add_attachment(); if ($ibforums->input['postattach']) { $ibforums->input['preview_post'] = 1; $skip_check_error = 1; } } elseif (($this->post_func->allow_upload())&&($ibforums->input['postattach2']!="")) { $this_error = $this->post_func->add_attachment2(); if ($ibforums->input['postattach2']) { $ibforums->input['preview_post'] = 1; $skip_check_error = 1; } } } Цитата Ссылка на комментарий Поделиться на других сайтах Прочее
vzport Опубликовано 17 Августа 2007 Жалоба Поделиться Опубликовано 17 Августа 2007 Вопрос такой.Если я изменил дерикторию для аттачей, тоесть дописал /attach в $this->path = $ibforums->vars['j_upload_dir']."/attach";и сделал изменение пути при создание нового поста с аттачем. Тоесть все работает.А вот когда в комментарий добавляеь аттач, то фаил загружается, а в комменте и предворительном просмотре его, ссылка всеравно на основную папку загрузок ссылается, а не на ту в которую закинут фаил. Цитата Ссылка на комментарий Поделиться на других сайтах Прочее
replicant Опубликовано 21 Августа 2007 Жалоба Поделиться Опубликовано 21 Августа 2007 Значит не везде изменения в коде сделал. Мод рабочий и такого вида сбой давно бы вылез. Просто проверь еще раз все участки кода. Цитата Ссылка на комментарий Поделиться на других сайтах Прочее
Рекомендуемые сообщения
Присоединиться к обсуждению
Вы можете ответить сейчас, а зарегистрироваться позже. Если у вас уже есть аккаунт, войдите, чтобы ответить от своего имени.