Merge branch 'MDL-41912-master' of git://github.com/damyon/moodle
[moodle.git] / lib / editor / atto / lib.php
CommitLineData
c90641fa
DW
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * YUI text editor integration.
19 *
20 * @package editor_atto
21 * @copyright 2013 Damyon Wiese <damyon@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
26
27/**
28 * This is the texteditor implementation.
29 * @copyright 2013 Damyon Wiese <damyon@moodle.com>
30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31 */
32class atto_texteditor extends texteditor {
33
34 /**
35 * Is the current browser supported by this editor?
36 *
37 * Of course!
38 * @return bool
39 */
40 public function supported_by_browser() {
41 return true;
42 }
43
44 /**
45 * Returns array of supported text formats.
46 * @return array
47 */
48 public function get_supported_formats() {
49 // FORMAT_MOODLE is not supported here, sorry.
50 return array(FORMAT_HTML => FORMAT_HTML);
51 }
52
53 /**
54 * Returns text format preferred by this editor.
55 * @return int
56 */
57 public function get_preferred_format() {
58 return FORMAT_HTML;
59 }
60
61 /**
62 * Does this editor support picking from repositories?
63 * @return bool
64 */
65 public function supports_repositories() {
66 return true;
67 }
68
69 /**
70 * Use this editor for give element.
71 *
72 * @param string $elementid
73 * @param array $options
74 * @param null $fpoptions
75 */
76 public function use_editor($elementid, array $options=null, $fpoptions=null) {
bde002b8 77 global $PAGE;
c90641fa
DW
78 $PAGE->requires->yui_module('moodle-editor_atto-editor',
79 'M.editor_atto.init',
80 array($this->get_init_params($elementid, $options, $fpoptions)), true);
c90641fa 81
bde002b8 82 $plugins = core_component::get_plugin_list('atto');
c90641fa 83
bde002b8
PS
84 foreach ($plugins as $name => $fulldir) {
85 $plugins[$name] = component_callback('atto_' . $name, 'sort_order', array($elementid));
c90641fa
DW
86 }
87
bde002b8
PS
88 asort($plugins);
89 foreach ($plugins as $name => $sort) {
90 component_callback('atto_' . $name, 'init_editor', array($elementid));
c90641fa
DW
91 }
92
93 }
94
95 /**
96 * Create a params array to init the editor.
97 *
98 * @param string $elementid
99 * @param array $options
100 * @param array $fpoptions
101 */
102 protected function get_init_params($elementid, array $options=null, array $fpoptions=null) {
103 global $PAGE;
104
105 $directionality = get_string('thisdirection', 'langconfig');
106 $strtime = get_string('strftimetime');
107 $strdate = get_string('strftimedaydate');
108 $lang = current_language();
109 $contentcss = $PAGE->theme->editor_css_url()->out(false);
110
111 $params = array(
112 'elementid' => $elementid,
113 'content_css' => $contentcss,
114 'language' => $lang,
115 'directionality' => $directionality,
116 'filepickeroptions' => array()
117 );
118 if ($fpoptions) {
119 $params['filepickeroptions'] = $fpoptions;
120 }
121 return $params;
122 }
123}