lufton
Пользователь
Не знаю, делал кто-то или нет, но решил, что быстрее сделать самому, чем искать по форуму. Мод добавляет поле для загрузки изображений в конструкторе шаблонов. После AJAX загрузки мод заменит значение предыдущего поля конструктора на прямой URL к картинке на fastpic.ru.
Это мой первый мод и вообще первый опыт знакомства с движком, так что не судите строго. Надеюсь кому-то станет полезным. По желанию могу написать загрузку на другие сервисы.
Для установки
Это мой первый мод и вообще первый опыт знакомства с движком, так что не судите строго. Надеюсь кому-то станет полезным. По желанию могу написать загрузку на другие сервисы.
Для установки
- Замените в ajax.php:
PHP:$ajax = new TorrentPier\Legacy\Ajax();
PHP:class Ajax extends TorrentPier\Legacy\Ajax { function __construct() { parent::__construct(); $this->valid_actions['ajax_load_pic'] = ['user']; } function init() { parent::init(); if (!$this->action) $this->action = $_GET['action']; } function ajax_load_pic() { $data = array( 'file[]' => new CurlFile($_FILES['img']['tmp_name']), 'uploading' => '1' ); $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, 'https://fastpic.ru/uploadmulti'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $result = curl_exec($ch); preg_match('/http.*html/', $result, $matches); curl_setopt($ch, CURLOPT_URL, $matches[0]); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_NOBODY, 0); $result = curl_exec($ch); preg_match('/(https?.*?fastpic.ru\/big.*?)"/', $result, $matches); $this->response['url'] = $matches[1]; curl_close($ch); } } $ajax = new Ajax();
- Добавьте в конце styles\templates\posting_tpl.tpl:
HTML:<!--ajax_load_pic_btn--> [/LIST] <script>TPL.el_id = Object.assign({ajax_load_pic_btn: 'AJAX загрузка на fastpic.ru'}, TPL.el_id);</script> <div id="ajax_load_pic_btn"> <script> function ajax_load_pic(el) { let fd = new FormData, $el = $(el); fd.append('img', $el.prop('files')[0]); $.ajax({ url: '/ajax.php?action=ajax_load_pic', type: 'POST', dataType: 'json', contentType: false, data: fd, processData: false, success: data => { if ($el.parent().prev().is('input')) $el.parent().prev().val(data.url); $el.val(''); } }); } </script> <input type="file" onchange="ajax_load_pic(this)" /> </div> <!--/ajax_load_pic_btn-->
Последнее редактирование: