Stripping CVS keywords
[project/wysiwyg.git] / editors / openwysiwyg.inc
1 <?php
2
3 /**
4 * @file
5 * Editor integration functions for openWYSIWYG.
6 */
7
8 /**
9 * Plugin implementation of hook_editor().
10 */
11 function wysiwyg_openwysiwyg_editor() {
12 $editor['openwysiwyg'] = array(
13 'title' => 'openWYSIWYG',
14 'vendor url' => 'http://www.openwebware.com',
15 'download url' => 'http://www.openwebware.com/download.shtml',
16 'library path' => wysiwyg_get_path('openwysiwyg') . '/scripts',
17 'libraries' => array(
18 'src' => array(
19 'title' => 'Source',
20 'files' => array('wysiwyg.js'),
21 ),
22 ),
23 'version callback' => 'wysiwyg_openwysiwyg_version',
24 'themes callback' => 'wysiwyg_openwysiwyg_themes',
25 'settings callback' => 'wysiwyg_openwysiwyg_settings',
26 'plugin callback' => 'wysiwyg_openwysiwyg_plugins',
27 'versions' => array(
28 '1.4.7' => array(
29 'js files' => array('openwysiwyg.js'),
30 'css files' => array('openwysiwyg.css'),
31 ),
32 ),
33 );
34 return $editor;
35 }
36
37 /**
38 * Detect editor version.
39 *
40 * @param $editor
41 * An array containing editor properties as returned from hook_editor().
42 *
43 * @return
44 * The installed editor version.
45 */
46 function wysiwyg_openwysiwyg_version($editor) {
47 // 'library path' has '/scripts' appended already.
48 $changelog = $editor['editor path'] . '/changelog';
49 if (!file_exists($changelog)) {
50 return;
51 }
52 $changelog = fopen($changelog, 'r');
53 $line = fgets($changelog, 20);
54 if (preg_match('@v([\d\.]+)@', $line, $version)) {
55 fclose($changelog);
56 return $version[1];
57 }
58 fclose($changelog);
59 }
60
61 /**
62 * Determine available editor themes or check/reset a given one.
63 *
64 * @param $editor
65 * A processed hook_editor() array of editor properties.
66 * @param $profile
67 * A wysiwyg editor profile.
68 *
69 * @return
70 * An array of theme names. The first returned name should be the default
71 * theme name.
72 */
73 function wysiwyg_openwysiwyg_themes($editor, $profile) {
74 return array('default');
75 }
76
77 /**
78 * Return runtime editor settings for a given wysiwyg profile.
79 *
80 * @param $editor
81 * A processed hook_editor() array of editor properties.
82 * @param $config
83 * An array containing wysiwyg editor profile settings.
84 * @param $theme
85 * The name of a theme/GUI/skin to use.
86 *
87 * @return
88 * A settings array to be populated in
89 * Drupal.settings.wysiwyg.configs.{editor}
90 */
91 function wysiwyg_openwysiwyg_settings($editor, $config, $theme) {
92 $settings = array(
93 'path' => base_path() . $editor['editor path'] . '/',
94 'Width' => '100%',
95 );
96
97 if (isset($config['path_loc']) && $config['path_loc'] == 'none') {
98 $settings['StatusBarEnabled'] = FALSE;
99 }
100
101 if (isset($config['css_setting'])) {
102 if ($config['css_setting'] == 'theme') {
103 $settings['CSSFile'] = reset(wysiwyg_get_css());
104 }
105 else if ($config['css_setting'] == 'self' && isset($config['css_path'])) {
106 $settings['CSSFile'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
107 }
108 }
109
110 $settings['Toolbar'] = array();
111 if (!empty($config['buttons'])) {
112 $plugins = wysiwyg_get_plugins($editor['name']);
113 foreach ($config['buttons'] as $plugin => $buttons) {
114 foreach ($buttons as $button => $enabled) {
115 foreach (array('buttons', 'extensions') as $type) {
116 // Skip unavailable plugins.
117 if (!isset($plugins[$plugin][$type][$button])) {
118 continue;
119 }
120 // Add buttons.
121 if ($type == 'buttons') {
122 $settings['Toolbar'][0][] = $button;
123 }
124 }
125 }
126 }
127 }
128
129 // @todo
130 // if (isset($config['block_formats'])) {
131 // $settings['DropDowns']['headings']['elements'] = explode(',', $config['block_formats']);
132 // }
133
134 return $settings;
135 }
136
137 /**
138 * Return internal plugins for this editor; semi-implementation of hook_wysiwyg_plugin().
139 */
140 function wysiwyg_openwysiwyg_plugins($editor) {
141 $plugins = array(
142 'default' => array(
143 'buttons' => array(
144 'bold' => t('Bold'), 'italic' => t('Italic'), 'underline' => t('Underline'),
145 'strikethrough' => t('Strike-through'),
146 'justifyleft' => t('Align left'), 'justifycenter' => t('Align center'), 'justifyright' => t('Align right'), 'justifyfull' => t('Justify'),
147 'unorderedlist' => t('Bullet list'), 'orderedlist' => t('Numbered list'),
148 'outdent' => t('Outdent'), 'indent' => t('Indent'),
149 'undo' => t('Undo'), 'redo' => t('Redo'),
150 'createlink' => t('Link'),
151 'insertimage' => t('Image'),
152 'cleanup' => t('Clean-up'),
153 'forecolor' => t('Forecolor'), 'backcolor' => t('Backcolor'),
154 'superscript' => t('Sup'), 'subscript' => t('Sub'),
155 'blockquote' => t('Blockquote'), 'viewSource' => t('Source code'),
156 'hr' => t('Horizontal rule'),
157 'cut' => t('Cut'), 'copy' => t('Copy'), 'paste' => t('Paste'),
158 'visualaid' => t('Visual aid'),
159 'removeformat' => t('Remove format'),
160 'charmap' => t('Character map'),
161 'headings' => t('HTML block format'), 'font' => t('Font'), 'fontsize' => t('Font size'),
162 'maximize' => t('Fullscreen'),
163 'preview' => t('Preview'),
164 'print' => t('Print'),
165 'inserttable' => t('Table'),
166 'help' => t('Help'),
167 ),
168 'internal' => TRUE,
169 ),
170 );
171 return $plugins;
172 }
173