PageRenderTime 54ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/jojo_core/json/admin-install-plugin.php

http://jojocms.googlecode.com/
PHP | 73 lines | 39 code | 9 blank | 25 comment | 6 complexity | ef2e9c7c51533b5dee5ea6ab5b84579f MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, LGPL-2.0, CC-BY-SA-3.0, MIT
  1. <?php
  2. /**
  3. * Jojo CMS
  4. * ================
  5. *
  6. * Copyright 2007-2008 Harvey Kane <code@ragepank.com>
  7. * Copyright 2007-2008 Michael Holt <code@gardyneholt.co.nz>
  8. * Copyright 2007 Melanie Schulz <mel@gardyneholt.co.nz>
  9. *
  10. * See the enclosed file license.txt for license information (LGPL). If you
  11. * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  12. *
  13. * @author Harvey Kane <code@ragepank.com>
  14. * @author Michael Cochrane <mikec@jojocms.org>
  15. * @author Melanie Schulz <mel@gardyneholt.co.nz>
  16. * @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License
  17. * @link http://www.jojocms.org JojoCMS
  18. * @package jojo_core
  19. */
  20. /* Ensure users of this function have access to the admin page */
  21. $page = Jojo_Plugin::getPage(Jojo::uriToPageID('admin/plugins', null, null, null));
  22. if (!$page->perms->hasPerm($_USERGROUPS, 'view')) {
  23. echo json_encode(
  24. array('result' => false,
  25. 'message' => "You do not have permission to use this function"));
  26. exit;
  27. }
  28. $plugin = basename(Jojo::getFormData('plugin', ''));
  29. if (!$plugin) {
  30. echo json_encode(
  31. array('result' => false,
  32. 'message' => "No plugin selected."));
  33. exit;
  34. }
  35. /* Enable this plugin */
  36. Jojo::insertQuery("REPLACE INTO {plugin} SET name = ?, active = 'yes'", $plugin);
  37. /* Force the plugin cache to be refreshed */
  38. Jojo::findFiles('setup.php', true);
  39. /* Run setup */
  40. $isAdmin = true;
  41. ob_start();
  42. include(_BASEDIR . '/includes/setup.php');
  43. ob_end_clean();
  44. /* Clear cache files */
  45. if (Jojo::fileExists(_CACHEDIR . '/api.txt')) {
  46. unlink(_CACHEDIR . '/api.txt');
  47. }
  48. if (Jojo::fileExists(_CACHEDIR . '/listPlugins.txt')) {
  49. unlink(_CACHEDIR . '/listPlugins.txt');
  50. }
  51. if (Jojo::fileExists(_CACHEDIR . '/listThemes.txt')) {
  52. unlink(_CACHEDIR . '/listThemes.txt');
  53. }
  54. /* Clear all compiled templates */
  55. foreach (Jojo::scanDirectory(_CACHEDIR . '/dwoo/templates_c') as $filename) {
  56. if (Jojo::fileExists(_CACHEDIR . '/dwoo/templates_c/' . $filename)) {
  57. unlink(_CACHEDIR . '/dwoo/templates_c/' . $filename);
  58. }
  59. }
  60. /* Let the user know */
  61. echo json_encode(
  62. array('result' => true,
  63. 'message' => ucwords(str_replace('_', ' ', $plugin)) . " installed."));
  64. exit;