/[drupal]/contributions/modules/markitup/markitup.admin.inc
ViewVC logotype

Contents of /contributions/modules/markitup/markitup.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Fri Aug 8 01:05:58 2008 UTC (15 months, 2 weeks ago) by mlsamuelson
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1, DRUPAL-6--2
Changes since 1.2: +0 -0 lines
File MIME type: text/x-php
#277476 - attempt 3, to update file permissions
1 <?php
2 // $Id:
3
4 /**
5 * @file
6 * Admin page callbacks for the markitup module.
7 */
8
9 /**
10 * Menu callback; Displays a list of all markItUp editor configurations and
11 * which one is the default.
12 *
13 * @ingroup forms
14 * @see markitup_admin_overview_submit()
15 */
16 function markitup_admin_overview() {
17 // we want to show a list of editor configurations with edit and delete links
18 // (going to the callback/path for markitup_admin_editor_page and
19 // markitup_admin_editor_delete)
20 $output = t('Configured editors');
21 $output .= markitup_admin_overview_editors();
22 // we also want to show a form for associating an editor configuration with an
23 // input format using markitup_admin_overview
24 $output .= t('Input format and editor associations');
25 $output .= drupal_get_form('markitup_admin_overview_form');
26
27 return $output;
28 }
29
30 /**
31 * Provide an overview form of editor configurations with links to edit and
32 * delete them.
33 */
34 function markitup_admin_overview_editors() {
35
36 $output = '';
37 // List out our editors using markitup_editors() and provide EDIT and DELETE links
38 $editors = markitup_editors();
39
40 // Table header,
41 $header = array( t('Editor name'), t('Description'), array('data' => t('Operations'), 'colspan' => '2'));
42
43 // Table rows.
44 foreach ($editors as $editor) {
45 $row[] = array($editor['name'], $editor['description'], l('configure', 'admin/settings/markitup/'. $editor['meid'] .'/edit'), l('delete', 'admin/settings/markitup/delete/'. $editor['meid']));
46 }
47
48 // Invoke theme_table().
49 $output .= theme('table', $header, $row);
50 return $output;
51 }
52
53 /**
54 * Provide a form allowing us to associate editor configurations with input
55 * formats.
56 */
57 function markitup_admin_overview_form() {
58
59 // Retrieve an array of editor and format associations, for setting default
60 // values.
61 $markitup_editors_formats = markitup_editors_formats();
62
63 // We want a dropdown box of our markitup editors using markitup_editors().
64 $editors = markitup_editors();
65 $editor_options[0] = '- none -';
66 foreach ($editors as $k => $v) {
67 $editor_options[$v['meid']] = $v['name'];
68 }
69
70 // Let's do an entry for each input format.
71 $input_formats = filter_formats($index = NULL);
72
73 $default_format = variable_get('filter_default_format', 1);
74
75 foreach ($input_formats as $input_format) {
76
77 $form[$input_format->format .'_format'] = array('#type' => 'hidden', '#value' => $input_format->format);
78
79 // Mark the default input format.
80 $input_format_name = ($default_format == $input_format->format) ? $input_format->name .' (default)' : $input_format->name;
81
82 $form[$input_format->format .'_editor'] = array('#title' => $input_format_name, '#type' => 'select', '#options' => $editor_options, '#default_value' => $markitup_editors_formats[$input_format->format]['meid']);
83 }
84
85 $form['markitup_include'] = array(
86 '#type' => 'textarea',
87 '#title' => t('Paths'),
88 '#description' => t('List each path where markItUp should be enabled. Put each path on a new line. You can use wildcards (*). (Leave blank for every form)'),
89 '#default_value' => variable_get('markitup_include', ''),
90 '#rows' => 5,
91 '#cols' => 60);
92 $form['markitup_ids'] = array(
93 '#type' => 'textarea',
94 '#title' => t('IDs'),
95 '#description' => t('List each textarea where you want a markItUp editor, write the ID of each textarea on a seperate line. (If empty the editor will only replace the body textarea).'),
96 '#default_value' => variable_get('markitup_ids', ''),
97 '#rows' => 5,
98 '#cols' => 20);
99
100 $form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
101 return $form;
102 }
103
104 // markitup_admin_overview_form_validate($form, &$form_state) ?
105
106 /**
107 * Submit the markitup_admin_overview_form().
108 */
109 function markitup_admin_overview_form_submit($form, &$form_state) {
110 // We'll use the list of input formats when reconstructing your $form_state array and iterating through it.
111 $input_formats = filter_formats($index = NULL);
112
113 // Set variable values for paths and textarea ids.
114 variable_set('markitup_include', $form_state['values']['markitup_include']);
115 variable_set('markitup_ids', $form_state['values']['markitup_ids']);
116
117 foreach ($input_formats as $input_format) {
118 // Drop any existing records for this format before adding our updated pairing.
119 db_query("DELETE FROM {markitup_editors_formats} WHERE format = %d", $form_state['values'][$input_format->format .'_format']);
120 db_query("INSERT INTO {markitup_editors_formats} (meid, format) VALUES (%d, %d)", $form_state['values'][$input_format->format .'_editor'], $form_state['values'][$input_format->format .'_format']);
121 }
122 drupal_set_message(t("Input format and editor associations have been saved."));
123 }
124
125 // ? function theme_markitup_admin_overview($form)
126
127
128
129
130 /**
131 * Menu callback; Display a markItUp editor configruation form.
132 */
133 function markitup_editor_page($editor = NULL) {
134 if (!isset($editor)) {
135 drupal_set_title(t('Add markItUp Editor'));
136 $editor = array('meid' => '', 'name' => '', 'miu_set' => '', 'skin' => '', 'description' => '');
137 }
138
139 return drupal_get_form('markitup_editor_form', $editor);
140 }
141
142
143 /**
144 * Generate a markitup editor configuration add/edit form.
145 *
146 * @ingroup forms
147 * @see markitup_editor_form_validate()
148 * @see markitup_editor_form_submit()
149 */
150 function markitup_editor_form(&$form_state, $editor) {
151 $form['markitup_name'] = array('#type' => 'textfield', '#title' => t('Editor name'), '#default_value' => $editor['name'], '#required' => TRUE);
152 $form['markitup_description'] = array('#type' => 'textfield', '#title' => t('Description'), '#default_value' => $editor['description']);
153 // get our skin options
154 $skins = _markitup_dirs('skins');
155 $form['markitup_skins'] = array('#type' => 'select', '#title' => t('Skins'), '#options' => $skins, '#default_value' => $editor['skin']);
156 // get our set options
157 $sets = _markitup_dirs('sets');
158 $form['markitup_sets'] = array('#type' => 'select', '#title' => t('Button Sets'), '#options' => $sets, '#default_value' => $editor['miu_set']);
159
160 if (!empty($editor['meid'])) {
161 $form['meid'] = array('#type' => 'hidden', '#value' => $editor['meid']);
162 }
163
164 $form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
165
166 return $form;
167 }
168
169 /**
170 * Validate the markitup editor add/edit form.
171 */
172 //function markitup_editor_form_validate($form, &$form_state) {
173 //print_r($form_state);
174 // if ($form_state['values']['markitup_name'] == '') {
175 // form_set_error('', t('You must enter a name for this editor.'));
176 // }
177 //}
178
179 /**
180 * Submit the markitup editor add/edit form.
181 */
182 function markitup_editor_form_submit($form, &$form_state) {
183 //die(print_r('<pre>'. var_export($form_state,TRUE) .'</pre>'));
184
185 $meid = isset($form_state['values']['meid']) ? $form_state['values']['meid'] : NULL;
186
187 if (!isset($meid)) {
188 db_query("INSERT INTO {markitup_editors} (name, description, skin, miu_set) VALUES ('%s', '%s', '%s', '%s')", $form_state['values']['markitup_name'], $form_state['values']['markitup_description'], $form_state['values']['markitup_skins'], $form_state['values']['markitup_sets']);
189 drupal_set_message(t("The '%markitup_name' markItUp editor was saved.", array('%markitup_name' => $form_state['values']['markitup_name'])));
190 }
191 else {
192 db_query("UPDATE {markitup_editors} SET name = '%s', description = '%s', skin = '%s', miu_set = '%s' WHERE meid = %d", $form_state['values']['markitup_name'], $form_state['values']['markitup_description'], $form_state['values']['markitup_skins'], $form_state['values']['markitup_sets'], $form_state['values']['meid']);
193 drupal_set_message(t("The '%markitup_name' markItUp editor was updated.", array('%markitup_name' => $form_state['values']['markitup_name'])));
194 }
195
196 $form_state['redirect'] = 'admin/settings/markitup';
197 }
198
199
200
201
202 /**
203 * Menu callback; confirm deletion of a markItUp editor.
204 *
205 * @ingroup forms
206 * @see markitup_editor_delete_submit()
207 */
208 function markitup_editor_delete() {
209 $meid = arg(4);
210 $editor = db_fetch_object(db_query('SELECT * FROM {markitup_editors} WHERE meid = %d', $meid));
211
212 if ($editor) {
213 if ($editor->meid != variable_get('markitup_editor_default', 1)) {
214 $form['meid'] = array('#type' => 'hidden', '#value' => $editor->meid);
215 $form['name'] = array('#type' => 'hidden', '#value' => $editor->name);
216
217 return confirm_form($form, t('Are you sure you want to delete the %markitup_name editor?', array('%markitup_name' => $editor->name)), 'admin/settings/filters', t('This action cannot be undone.'), t('Delete'), t('Cancel'));
218 }
219 else {
220 drupal_set_message(t('The default editor cannot be deleted.'));
221 drupal_goto('admin/settings/markitup');
222 }
223 }
224 else {
225 drupal_not_found();
226 }
227 }
228
229 /**
230 * Process markItUp editor delete form submission.
231 */
232 function markitup_editor_delete_submit($form, &$form_state) {
233 db_query("UPDATE {markitup_editors_formats} SET meid = %d WHERE meid = %d", variable_get('markitup_editor_default', 1), $form_state['values']['meid']);
234 db_query("DELETE FROM {markitup_editors} WHERE meid = %d", $form_state['values']['meid']);
235
236 drupal_set_message(t('Deleted editor %markitup_editor.', array('%markitup_editor' => $form_state['values']['name'])));
237
238 $form_state['redirect'] = 'admin/settings/markitup';
239 return;
240 }

  ViewVC Help
Powered by ViewVC 1.1.2