qa-wysiwyg-upload.php 1.76 KB
Newer Older
Scott committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<?php
/*
	Question2Answer by Gideon Greenspan and contributors
	http://www.question2answer.org/

	File: qa-plugin/wysiwyg-editor/qa-wysiwyg-upload.php
	Description: Page module class for WYSIWYG editor (CKEditor) file upload receiver


	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	More about this license: http://www.question2answer.org/license.php
*/


class qa_wysiwyg_upload
{
	public function match_request($request)
	{
28
		return $request === 'wysiwyg-editor-upload';
Scott committed
29 30 31 32 33 34 35 36
	}

	public function process_request($request)
	{
		$message = '';
		$url = '';

		if (is_array($_FILES) && count($_FILES)) {
37 38
			if (qa_opt('wysiwyg_editor_upload_images')) {
				require_once QA_INCLUDE_DIR . 'app/upload.php';
Scott committed
39

40 41 42 43 44 45 46
				$onlyImage = qa_get('qa_only_image');
				$upload = qa_upload_file_one(
					qa_opt('wysiwyg_editor_upload_max_size'),
					$onlyImage || !qa_opt('wysiwyg_editor_upload_all'),
					$onlyImage ? 600 : null, // max width if it's an image upload
					null // no max height
				);
Scott committed
47

48 49 50 51 52 53
				if (isset($upload['error'])) {
					$message = $upload['error'];
				} else {
					$url = $upload['bloburl'];
				}
			} else {
Scott committed
54
				$message = qa_lang_html('users/no_permission');
55
			}
Scott committed
56 57
		}

58 59 60 61 62 63
		echo sprintf(
			'<script>window.parent.CKEDITOR.tools.callFunction(%s, %s, %s);</script>',
			qa_js(qa_get('CKEditorFuncNum')),
			qa_js($url),
			qa_js($message)
		);
Scott committed
64 65 66 67

		return null;
	}
}