qa-wysiwyg-upload.php 1.84 KB
Newer Older
Gideon Greenspan committed
1 2 3 4 5 6 7
<?php

/*
	Question2Answer (c) Gideon Greenspan

	http://www.question2answer.org/

8

Gideon Greenspan committed
9 10 11 12 13 14 15 16 17
	File: qa-plugin/wysiwyg-editor/qa-wysiwyg-upload.php
	Version: See define()s at top of qa-include/qa-base.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.
18

Gideon Greenspan committed
19 20 21 22 23 24 25 26 27 28
	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 {
29

Gideon Greenspan committed
30 31 32 33 34
		function match_request($request)
		{
			return ($request=='wysiwyg-editor-upload');
		}

35

Gideon Greenspan committed
36 37 38 39
		function process_request($request)
		{
			$message='';
			$url='';
40

Gideon Greenspan committed
41 42 43
			if (is_array($_FILES) && count($_FILES)) {
				if (!qa_opt('wysiwyg_editor_upload_images'))
					$message=qa_lang('users/no_permission');
44

Gideon Greenspan committed
45
				require_once QA_INCLUDE_DIR.'qa-app-upload.php';
46

Gideon Greenspan committed
47 48 49 50 51 52
				$upload=qa_upload_file_one(
					qa_opt('wysiwyg_editor_upload_max_size'),
					qa_get('qa_only_image') || !qa_opt('wysiwyg_editor_upload_all'),
					qa_get('qa_only_image') ? 600 : null, // max width if it's an image upload
					null // no max height
				);
53

Gideon Greenspan committed
54 55
				$message=@$upload['error'];
				$url=@$upload['bloburl'];
Gideon Greenspan committed
56
			}
57

Gideon Greenspan committed
58 59
			echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction(".qa_js(qa_get('CKEditorFuncNum')).
				", ".qa_js($url).", ".qa_js($message).");</script>";
60

Gideon Greenspan committed
61 62
			return null;
		}
63

Gideon Greenspan committed
64 65 66 67 68 69
	}


/*
	Omit PHP closing tag to help avoid accidental output
*/