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

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

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


Revision 1.55 - (show annotations) (download) (as text)
Thu Sep 18 18:03:42 2008 UTC (14 months, 1 week ago) by jabapyth
Branch: MAIN
CVS Tags: HEAD
Changes since 1.54: +3 -2 lines
File MIME type: text/x-php
adding inline iframes to the md5 selection interface #292920
1 <?php
2 // $Id: plugin_manager.admin.inc,v 1.54 2008/09/18 17:53:54 jabapyth Exp $
3
4 /**
5 * @file
6 * The Forms used by the plugin manager.
7 */
8
9 /**
10 * FAPI for overview/search page.
11 */
12 function plugin_manager_overview($form_state) {
13 if (!plugin_manager_runnable()) {
14 return array();
15 }
16
17 // If the repository is over 24 hours old then update it.
18 if (variable_get("plugin_manager_last_reload", 0) + 86400 < date('U')) {
19 drupal_set_message(t("The repository is out of date and will be updated."));
20 }
21
22 if (!isset($form_state['storage']['search'])) {
23 $form['search_box'] = array(
24 '#type' => 'fieldset',
25 '#title' => t('Search'),
26 '#collapsible' => FALSE,
27 );
28 $form['search_box']['search'] = array(
29 '#type' => 'textfield',
30 );
31 $form['search_box']['submit'] = array(
32 '#type' => 'submit',
33 '#value' => t('Search'),
34 );
35 }
36 else {
37 // If the repository is over 24 hours old then update it.
38 plugin_manager_reload();
39
40 // Get a list of queued changes.
41 $queue = variable_get("plugin_manager_queue", array());
42
43 // Get a list of the non-installed plugins from the category.
44 $result = db_query(
45 "SELECT title, pmr.short_name AS short_name
46 FROM {plugin_manager_repository} pmr
47 LEFT JOIN(
48 SELECT DISTINCT short_name
49 FROM {plugin_manager_files}
50 ) pmf
51 ON(pmf.short_name = pmr.short_name)
52 WHERE title LIKE '%%%s%%'
53 AND pmf.short_name IS NULL
54 ORDER BY title", $form_state['storage']['search']);
55
56 while ($row = db_fetch_array($result)) {
57 $form[$row['short_name']] = array(
58 '#type' => 'checkbox',
59 '#name' => $row['short_name'],
60 '#title' => htmlentities($row['title']),
61 '#default_value' => isset($queue[$row['short_name']]),
62 );
63 }
64 $form['submit'] = array(
65 '#type' => 'submit',
66 '#value' => t('Queue for Installation'),
67 );
68 }
69 return $form;
70 }
71
72 function plugin_manager_overview_submit($form, &$form_state) {
73 if (!isset($form_state['storage'])) {
74 $form_state['storage']['search'] = $form_state['values']['search'];
75 return;
76 }
77 else {
78 plugin_manager_category_form_submit($form, $form_state);
79 }
80 }
81
82 /**
83 * Displays the modules in a selected category.
84 *
85 * @return
86 * HTML output of the category page.
87 */
88 function plugin_manager_modules() {
89 plugin_manager_reload();
90 // If we are looking at modules, then show the categories
91 $output = '';
92 $output .= drupal_get_form('plugin_manager_category_show');
93
94 $func_args = arg();
95 $category = count($func_args) - 1;
96 if ($func_args[$category] != 'modules') {
97 $output .= drupal_get_form('plugin_manager_category_form');
98 }
99 return $output;
100 }
101
102 /**
103 * FAPI definition for the category list
104 *
105 * @ingroup forms
106 */
107 function plugin_manager_category_show() {
108 $func_args = arg();
109 $category_id = count($func_args) - 1;
110 $category = $func_args[$category_id];
111
112 $form['categories'] = array(
113 '#type' => 'fieldset',
114 '#title' => t('Categories'),
115 '#collapsible' => ($category != 'modules'),
116 '#collapsed' => ($category != 'modules'),
117 );
118
119 $result = db_query("SELECT tag
120 FROM {plugin_manager_taxonomy}
121 WHERE tag NOT IN('Modules', 'Themes', 'Translations')
122 GROUP BY tag
123 ORDER BY tag");
124 while ($row = db_fetch_array($result)) {
125 $form['categories'][] = array(
126 '#value' => l($row['tag'], "admin/build/plugin_manager/modules/". str_replace('/', '_', $row['tag'])) ."<br />",
127 );
128 }
129
130 return $form;
131 }
132
133 /**
134 * FAPI definition for the items in a selected category.
135 *
136 * @ingroup forms
137 * @see plugin_manager_category_form_submit()
138 */
139 function plugin_manager_category_form() {
140 // If the repository is over 24 hours old then update it.
141 plugin_manager_reload();
142
143 // Get the category that provided.
144 $func_args = arg();
145 $category_id = count($func_args) - 1;
146 $category = str_replace('_', '/', $func_args[$category_id]);
147
148 // Get a list of queued changes.
149 $queue = variable_get("plugin_manager_queue", array());
150
151 // Get a list of the non-installed plugins from the category.
152 $result = db_query(
153 "SELECT title, pmr.short_name AS short_name
154 FROM {plugin_manager_repository} pmr
155 INNER JOIN {plugin_manager_taxonomy} pmt
156 ON pmt.short_name = pmr.short_name
157 LEFT JOIN(
158 SELECT DISTINCT short_name
159 FROM {plugin_manager_files}
160 ) pmf
161 ON(pmf.short_name = pmr.short_name)
162 WHERE tag = '%s'
163 AND pmf.short_name IS NULL
164 ORDER BY title", $category);
165
166 while ($row = db_fetch_array($result)) {
167 $form[$row['short_name']] = array(
168 '#type' => 'checkbox',
169 '#name' => $row['short_name'],
170 '#title' => htmlentities($row['title']),
171 '#default_value' => isset($queue[$row['short_name']]),
172 );
173 }
174 $form[] = array(
175 '#type' => 'submit',
176 '#value' => t('Queue for Installation'),
177 );
178
179 return $form;
180 }
181
182 /**
183 * Callback plugin_manager_category_form.
184 */
185 function plugin_manager_category_form_submit($form, &$form_state) {
186 // See what is already queued.
187 $queue = variable_get("plugin_manager_queue", array());
188
189 // Go through each value in the list.
190 foreach ($form_state['values'] AS $theme => $value) {
191 if ($value == 1) {
192 // Add it to the queue if needed.
193 $queue[$theme] = $theme;
194 }
195 else {
196 // Remove it from the queue otherwise.
197 unset($queue[$theme]);
198 }
199 }
200
201 // Set the new queue equal to our changed queue.
202 variable_set("plugin_manager_queue", $queue);
203 drupal_set_message("The queue has been updated.");
204 }
205
206 /**
207 * FAPI for the first page of the installer
208 *
209 * @ingroup forms
210 * @see plugin_manager_install_1()
211 */
212 function plugin_manager_page_1() {
213 // Get the total list and grab the release_history for each and set the download links.
214 $queue = variable_get("plugin_manager_queue", array());
215 $queue_info = plugin_manager_get_release_history($queue);
216 variable_set("plugin_manager_queue_info", $queue_info);
217
218 // Put a version drop down for each of the files
219 foreach ($queue_info AS $project => $info) {
220 $form[$project .'_version'] = array(
221 '#title' => t('%title version', array('%title' => $info['title'])),
222 '#type' => 'select',
223 '#options' => $info['version'],
224 );
225 }
226
227 // Put the continue button up.
228 $form['submit'] = array(
229 '#type' => 'submit',
230 '#value' => t('Continue to Step 2'),
231 );
232 return $form;
233 }
234
235 /**
236 * FAPI for the second page of the installer
237 *
238 * @ingroup forms
239 * @see plugin_manager_install_2()
240 */
241 function plugin_manager_page_2($form_state) {
242 // On to page two.
243 $queue_info = variable_get("plugin_manager_queue_info", array());
244
245 $link_attr['attributes']['target'] = 'blank';
246
247 // Make each one of the md5sum boxes.
248 foreach ($queue_info AS $name => $plugin) {
249 $version = $form_state['storage'][1][$name .'_version'];
250 $link = $plugin['release'][$version]['release_link'];
251 $form[$name .'_md5sum'] = array(
252 '#title' => t('%plugin_title md5_file hash (copy/paste from above or <a href="!uri">available here</a>)', array('%plugin_title' => $plugin['title'], '!uri' => url($link, $link_attr))),
253 '#type' => 'textfield',
254 '#size' => 32,
255 '#prefix' => "<iframe src='$link' style='width:100%;height:260px;'></iframe>",
256 );
257 }
258
259 // Put the continue button up.
260 $form['submit'] = array(
261 '#type' => 'submit',
262 '#value' => t('Continue to Step 3'),
263 );
264 return $form;
265 }
266
267 /**
268 * FAPI for the third page of the installer
269 *
270 * @ingroup forms
271 * @see plugin_manager_install_3()
272 */
273 function plugin_manager_page_3($form_state) {
274 $form['backend'] = array(
275 '#title' => t('Installation method'),
276 '#type' => 'select',
277 '#options' => plugin_manager_backends(),
278 );
279 $form['username'] = array(
280 '#title' => t('Username'),
281 '#type' => 'textfield',
282 );
283 $form['password'] = array(
284 '#title' => t('Password'),
285 '#type' => 'password',
286 );
287 $form['submit'] = array(
288 '#type' => 'submit',
289 '#value' => t('Install'),
290 );
291 return $form;
292 }
293
294 /**
295 * A page to list all of the queued changes and begin installation of them.
296 */
297 function plugin_manager_install_form($form_state) {
298 // Make sure that the plugin manager can be run.
299 if (!plugin_manager_runnable()) {
300 return array();
301 }
302
303 // If there aren't any, then just tell the just that. And quit.
304 $queue = variable_get("plugin_manager_queue", array());
305 if (empty($queue)) {
306 drupal_set_message("Nothing has been selected to install.", "error");
307 return array();
308 }
309
310 // Allow the choice of versions on the first page.
311 if (!isset($form_state['storage']['page'])) {
312 return plugin_manager_page_1();
313 }
314 elseif ($form_state['storage']['page'] == 2) {
315 return plugin_manager_page_2($form_state);
316 }
317 else {
318 return plugin_manager_page_3($form_state);
319 }
320 }
321
322 /**
323 * Process the first page of the installer, by downloading the needed files.
324 */
325 function plugin_manager_install_1($form, &$form_state) {
326 // Download the files.
327 $files = array();
328 $queue_info = variable_get("plugin_manager_queue_info", array());
329 foreach ($queue_info AS $name => $plugin) {
330 $version = $form_state['storage'][1][$name .'_version'];
331 $link = $plugin['release'][$version]['download_link'];
332 $files[$name] = plugin_manager_get($link);
333
334 // Check for an error.
335 if ($files[$name] == FALSE) {
336 drupal_set_message(t('Could not download @name', array('@name' => $name)), 'error');
337 return;
338 }
339 }
340 variable_set("plugin_manager_downloaded_files", $files);
341
342 // Proceed to the next page.
343 $form_state['storage']['page'] = 2;
344 return;
345 }
346
347 /**
348 * Process the second page of the installer by comparing calculated md5sums
349 * to the md5sums supplied by the user.
350 */
351 function plugin_manager_install_2($form, &$form_state) {
352 $form_state['storage'][2] = $form_state['values'];
353 // Compare the calculated and supplied md5sums.
354 $files = variable_get("plugin_manager_downloaded_files", array());
355
356 foreach ($files AS $name => $file) {
357 $md5 = $form_state['storage'][2][$name .'_md5sum'];
358 if (md5_file($file) != $md5) {
359 drupal_set_message(t('The md5sum is incorrect for ') . $plugin['title'], 'error');
360 $form_state['storage']['page'] = 2;
361 return;
362 }
363 }
364
365 $form_state['storage']['page'] = 3;
366 return;
367 }
368
369 /**
370 * Process the third page of the installer. Extract, install, log and
371 * clean up the files.
372 */
373 function plugin_manager_install_3($form, &$form_state) {
374 // Load the appropriate backend.
375 $backend_list = plugin_manager_backends();
376 $backend = $backend_list[$form_state['values']['backend']];
377 $form_state['storage']['page'] = 3;
378
379 // Go through each on of the files.
380 $plugins = variable_get("plugin_manager_downloaded_files", array());
381 foreach ($plugins AS $name => $plugin) {
382 // Extract the files
383 $files = plugin_manager_untar($plugin);
384
385 // Find out whether the thing is a module or theme.
386 $row = db_fetch_array(
387 db_query("
388 SELECT lower(tag) AS tag
389 FROM {plugin_manager_taxonomy}
390 WHERE short_name = '%s'
391 AND tag IN('Modules', 'Themes')", $name));
392
393 // Copy the extracted files
394 $copy = call_user_func_array($backend .'_plugin_manager_copy',
395 array($files, $row['tag'], $form_state['values']['username'],
396 $form_state['values']['password']));
397
398 foreach (array_reverse($files) AS $file) {
399 // Mark files as installed
400 if ($copy) {
401 db_query("INSERT INTO {plugin_manager_files} VALUES('%s', '%s')",
402 $name, $row['tag'] .'/'. $file);
403 }
404
405 // Remove the extracted files.
406 $file = file_directory_path() .'/plugin_manager_extraction/'. $file;
407 if (is_dir($file)) {
408 rmdir($file);
409 }
410 else {
411 unlink($file);
412 }
413 }
414
415 // If it failed, stop now.
416 if (!$copy) {
417 drupal_set_message(t("Unable to install ") . $name, 'error');
418 return;
419 }
420
421 drupal_set_message(t("Successfully installed ") . $name);
422 unlink($plugin);
423 }
424 variable_set("plugin_manager_queue_info", array());
425 variable_set("plugin_manager_queue", array());
426 }
427
428 /**
429 * Process the data presented in the plugin_manager_install form.
430 */
431 function plugin_manager_install_form_submit($form, &$form_state) {
432 // If page one was submitted, download the requested files.
433 if (!isset($form_state['storage']['page']) OR ($form_state['storage']['page'] == 1)) {
434 $form_state['storage'][1] = $form_state['values'];
435 return plugin_manager_install_1($form, $form_state);
436 }
437 elseif ($form_state['storage']['page'] == 2) {
438 return plugin_manager_install_2($form, $form_state);
439 }
440 return plugin_manager_install_3($form, $form_state);
441 }
442
443 /**
444 * FAPI for the uninstall page.
445 *
446 * Shows a list of packages to the user, allowing them to mark packages for removal.
447 * @ingroup forms
448 * @see plugin_manager_uninstall_submit()
449 */
450 function plugin_manager_uninstall_form($form_state) {
451 $form['theme'] = array(
452 '#type' => 'fieldset',
453 '#title' => t('Themes'),
454 '#collapsible' => FALSE,
455 '#collapsed' => FALSE,
456 );
457 $form['module'] = array(
458 '#type' => 'fieldset',
459 '#title' => t('Modules'),
460 '#collapsible' => FALSE,
461 '#collapsed' => FALSE,
462 );
463
464 // Get a list of the non-installed plugins from the category.
465 $result = db_query(
466 "SELECT name, type, COALESCE(title, name) AS title
467 FROM {plugin_manager_files} pmf
468 LEFT JOIN {system} s ON(pmf.short_name = s.name)
469 LEFT JOIN {plugin_manager_repository} pmr ON(pmr.short_name = pmf.short_name)
470 WHERE status = 0
471 GROUP BY type, name
472 ORDER BY type, name");
473
474 while ($row = db_fetch_array($result)) {
475 $form[$row['type']][$row['name']] = array(
476 '#type' => 'checkbox',
477 '#name' => $row['name'],
478 '#title' => htmlentities($row['title']),
479 );
480 }
481 $form[] = array(
482 '#type' => 'submit',
483 '#value' => t('Uninstall'),
484 );
485 return $form;
486 }
487
488 /**
489 * Remove package files from the server.
490 */
491 function plugin_manager_uninstall_form_submit($form, &$form_state) {
492 foreach ($form_state['values'] AS $plugin => $value) {
493 // If it isn't supposed to be removed, then skip it.
494 if ($value != 1) {
495 continue;
496 }
497
498 // Get the files to remove.
499 $result = db_query("
500 SELECT file_path
501 FROM {plugin_manager_files}
502 WHERE short_name = '%s'
503 ORDER BY file_path DESC", $plugin);
504
505 // Remove the files / folders requested.
506 while ($row = db_fetch_array($result)) {
507 $file = $_SERVER['DOCUMENT_ROOT'] . base_path() .'sites/all/'. $row['file_path'];
508
509 if (!file_exists($file)) {
510 drupal_set_message(t("@file does not seem to exist.", array('@file' => $file)), 'error');
511 //continue;
512 }
513 elseif (is_dir($file)) {
514 if (!@rmdir($file)) {
515 drupal_set_message(t("Could not remove @file.", array('@file' => $file)), 'error');
516 continue;
517 }
518 }
519 else {
520 if (!@unlink($file)) {
521 drupal_set_message(t("Could not remove @file.", array('@file' => $file)), 'error');
522 continue;
523 }
524 }
525 db_query("DELETE FROM {plugin_manager_files}
526 WHERE file_path = '%s'", $row['file_path']);
527 }
528 }
529 }

  ViewVC Help
Powered by ViewVC 1.1.2