1: <?php
 2: /**
 3:  * Copyright 2014 Horde LLC (http://www.horde.org/)
 4:  *
 5:  * See the enclosed file COPYING for license information (GPL). If you
 6:  * did not receive this file, see http://www.horde.org/licenses/gpl.
 7:  *
 8:  * @category  Horde
 9:  * @copyright 2014 Horde LLC
10:  * @license   http://www.horde.org/licenses/gpl GPL
11:  * @package   IMP
12:  */
13: 
14: /**
15:  * This class identifies the javascript necessary to initialize CKEditor on
16:  * the browser.
17:  *
18:  * @author    Michael Slusarz <slusarz@horde.org>
19:  * @category  Horde
20:  * @copyright 2014 Horde LLC
21:  * @license   http://www.horde.org/licenses/gpl GPL
22:  * @package   IMP
23:  */
24: class IMP_Script_Package_Editor extends Horde_Script_Package
25: {
26:     /**
27:      * Constructor.
28:      */
29:     public function __construct()
30:     {
31:         global $injector, $page_output, $language, $prefs;
32: 
33:         $injector->getInstance('Horde_Editor')->initialize(array(
34:             'basic' => true,
35:             'config' => 'IMP.ckeditor_config'
36:         ));
37: 
38:         $font_family = $prefs->getValue('compose_html_font_family');
39:         if (!$font_family) {
40:             $font_family = 'Arial';
41:         }
42: 
43:         $font_size = intval($prefs->getValue('compose_html_font_size'));
44:         $font_size = $font_size
45:             /* Font size should be between 8 and 24 pixels. Or else recipients
46:              * will hate us. Default to 14px. */
47:             ? min(24, max(8, $font_size)) . 'px'
48:             : '14px';
49: 
50:         $config = array(
51:             /* To more closely match "normal" textarea behavior, send <BR> on
52:              * enter instead of <P>. */
53:             // CKEDITOR.ENTER_BR
54:             'enterMode: 2',
55:             // CKEDITOR.ENTER_P
56:             'shiftEnterMode: 1',
57: 
58:             /* Don't load the config.js file. */
59:             'customConfig: ""',
60: 
61:             /* Disable resize of the textarea. */
62:             'resize_enabled: false',
63: 
64:             /* Disable spell check as you type. */
65:             'scayt_autoStartup: false',
66: 
67:             /* Convert HTML entities. */
68:             'entities: false',
69: 
70:             /* Set language to Horde language. */
71:             'language: "' . Horde_String::lower($language) . '"',
72: 
73:             /* Default display font. This is NOT the font used to send
74:              * the message, however. */
75:             'contentsCss: "body { font-family: ' . $font_family . '; font-size: ' . $font_size . '; }"',
76:             'font_defaultLabel: "' . $font_family . '"',
77:             'fontSize_defaultLabel: "' . $font_size . '"'
78:         );
79: 
80:         $buttons = $prefs->getValue('ckeditor_buttons');
81:         if (!empty($buttons)) {
82:             $config[] = 'toolbar: ' . $buttons;
83:         }
84: 
85:         $page_output->addInlineScript(array(
86:             'window.IMP = window.IMP || {}',
87:             'IMP.ckeditor_config = {' . implode(',', $config) . '}'
88:         ));
89:     }
90: 
91: }
92: