CkEditor.php 5.16 KB
Newer Older
llaffont's avatar
llaffont committed
1 2 3 4
<?php
/**
 * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
 *
Laurent's avatar
Laurent committed
5
 * BOKEH is free software; you can redistribute it and/or modify
llaffont's avatar
llaffont committed
6 7 8 9 10 11
 * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
 * the Free Software Foundation.
 *
 * There are special exceptions to the terms and conditions of the AGPL as it
 * is applied to this software (see README file).
 *
Laurent's avatar
Laurent committed
12
 * BOKEH is distributed in the hope that it will be useful,
llaffont's avatar
llaffont committed
13 14 15 16 17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
Laurent's avatar
Laurent committed
18
 * along with BOKEH; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
llaffont's avatar
llaffont committed
20 21 22 23 24 25
 */

include_once(CKBASEPATH . "ckeditor.php");

class ZendAfi_View_Helper_CkEditor extends ZendAfi_View_Helper_BaseHelper
{
Patrick Barroca's avatar
Patrick Barroca committed
26 27 28
  /*
   * @param $initial Initial content for the editor
   */
29 30
  public function ckEditor($initial, $editorId, $showFileBrowser=true) {
    $config = [];
Patrick Barroca's avatar
Patrick Barroca committed
31
    if ($showFileBrowser) {
32 33 34 35 36 37 38 39 40 41 42 43 44 45
      $config['filebrowserBrowseUrl'] = $this->view->url(['module' => 'admin',
                                                          'controller' => 'file-manager'], null, true) .
        '?' .
        http_build_query(['full_screen' => 1,
                          'browser' => 'userfiles/file',
                          'selectable_extensions' => Class_AdminVar::get('ALLOWED_FILES_EXTENSIONS_FOR_IMPORT')]);

      $config['filebrowserImageBrowseUrl'] = $this->view->url(['module' => 'admin',
                                                               'controller' => 'file-manager'], null, true) .
        '?' .
        http_build_query(['full_screen' => 1,
                          'browser' => 'userfiles/image',
                          'selectable_extensions' => Class_AdminVar::get('SELECTABLE_IMAGE_EXTENSIONS')]);

Ghislain Loas's avatar
Ghislain Loas committed
46 47
      $config['filebrowserFlashBrowseUrl'] = $this->view->url(['module' => 'admin',
                                                               'controller' => 'file-manager'], null, true) .
48 49 50 51
        '?' .
        http_build_query(['full_screen' => 1,
                          'browser' => 'userfiles/flash',
                          'selectable_extensions' => 'swf']);
Patrick Barroca's avatar
Patrick Barroca committed
52 53 54 55 56
    }
    $config['filebrowserUploadUrl'] = CKBASEURL."filemanager/upload/php/upload.php?ServerPath=".USERFILESURL;
    $config['filebrowserImageUploadUrl'] = CKBASEURL."filemanager/upload/php/upload.php?Type=Image&ServerPath=".USERFILESURL;
    $config['filebrowserFlashUploadUrl'] = CKBASEURL."filemanager/upload/php/upload.php?Type=Flash&ServerPath=".USERFILESURL;
    $config['imagesPath'] = URL_ADMIN_IMG."ckeditor_templates/";
57 58 59
    $config['templates_files'] = [URL_ADMIN_JS."ckeditor_templates.js"];
    $config['contentsCss'] = [BASE_URL . '/public/opac/css/global.css',
                              URL_CSS . 'global.css'];
efalcy's avatar
efalcy committed
60

Patrick Barroca's avatar
Patrick Barroca committed
61 62 63 64 65 66 67 68
    $config['toolbar'] = [
      ['Preview', 'Templates', 'Source','Maximize'],
      ['Cut','Copy','Paste','PasteFromWord'],
      ['Undo','Redo','-','SelectAll','RemoveFormat'],
      ['Scayt'],
      '/',
      ['HorizontalRule'],
      ['Link','Unlink','Anchor'],
69
                          ['Image','Flash','Table','Iframe','oembed','Slideshow', 'SpecialChar','Kiosk'],
Patrick Barroca's avatar
Patrick Barroca committed
70
      ];
efalcy's avatar
efalcy committed
71

Patrick Barroca's avatar
Patrick Barroca committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
    $config['extraAllowedContent'] = [
      'audio video' => [
        'attributes' => '*'
      ],
      'source' => [
        'attributes' => ['src', 'type']
      ],
      'map' => [
        'attributes' => 'name'
      ],
      'area' => [
        'attributes' => ['shape', 'coords', 'href' , 'alt']
      ],
      'span' => [
        'classes' => '*',
      ],
      '*' => [
        'attributes' => 'id',
        'styles' => '*'
      ]
    ];
    if (($user = Class_Users::getIdentity()) ? $user->isBibliothecaire():false) {
      $config['allowedContent']=true;
      $config['autoParagraph'] = false;
    }
97

Patrick Barroca's avatar
Patrick Barroca committed
98 99 100
    if (Class_AdminVar::isCmsFormulairesEnabled()) {
      $config['toolbar'][]=['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'];
    }
efalcy's avatar
efalcy committed
101

102 103 104 105 106 107 108
    $config['toolbar']=array_merge($config['toolbar'],
                                   ['/',
                                    ['Styles','FontSize','TextColor','BGColor'],
                                    ['Bold','Italic','Underline','Strike'],
                                    ['NumberedList','BulletedList','-','Outdent','Indent'],
                                    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock']
                                   ]);
109 110 111 112 113 114
    $config['kiosk_widget_url'] = Class_Url::assemble(['module' => 'admin',
                                                       'controller' => 'widget',
                                                       'action' => 'get-form',
                                                       'code' => 'KIOSQUE',
                                                       'render' => 'popup']);
    $config['extraPlugins'] = 'colordialog,bokeh_kiosk';
115

116

Patrick Barroca's avatar
Patrick Barroca committed
117 118 119 120
    $oCKeditor = new CKeditor(CKBASEURL);
    $oCKeditor->returnOutput = true;
    return $oCKeditor->editor($editorId, $initial, $config);
  }
121
}