PageRenderTime 551ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/branches/coding-style/admin/panels/plugin/admin.plugin.php

https://bitbucket.org/alexandrul/flatpress
PHP | 127 lines | 73 code | 10 blank | 44 comment | 8 complexity | 935fc2bd9d38010228a788d4b27a73af MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, MIT
  1. <?php
  2. /**
  3. * Plugin control panel
  4. *
  5. * @author NoWhereMan <real_nowhereman at users dot sf dot com>
  6. */
  7. /*
  8. function admin_plugin_adminheader() {
  9. $f = ADMIN_DIR .'/panels/plugin/admin.plugin.js';
  10. echo '<script src="'.$f.'" type="text/javascript"></script>';
  11. }
  12. add_action('wp_head', 'admin_plugin_adminheader');
  13. */
  14. /**
  15. * Enter description here...
  16. *
  17. */
  18. class admin_plugin extends AdminPanel {
  19. var $panelname = 'plugin';
  20. var $actions = array('default' => true);
  21. }
  22. class admin_plugin_default extends AdminPanelAction {
  23. var $commands = array('enable', 'disable');
  24. var $errors = array();
  25. /**
  26. * Enter description here...
  27. *
  28. */
  29. function setup() {
  30. $this->pluginid = isset($_GET['plugin'])? $_GET['plugin'] : null;
  31. $pi =& new plugin_indexer;
  32. $plist = $pi->getList();
  33. sort($plist);
  34. $this->smarty->assign('pluginlist', $plist);
  35. $this->errors = @$pi->getEnableds(true);
  36. $this->fp_plugins = $pi->enabledlist;
  37. }
  38. /**
  39. * Enter description here...
  40. *
  41. * @param unknown_type $id
  42. * @return int
  43. */
  44. function dodisable($id) {
  45. $fp_plugins = $this->fp_plugins;
  46. $success = -1;
  47. if (plugin_exists($id)) {
  48. $success = 1;
  49. if (false !== $i = array_search($id, $fp_plugins)) {
  50. unset($fp_plugins[$i]);
  51. sort($fp_plugins); /* compact indices */
  52. do_action('deactivate_'. $id);
  53. $success = system_save(CONFIG_DIR .'plugins.conf.php', compact('fp_plugins'));
  54. } else {
  55. $success = -1;
  56. }
  57. }
  58. if ($success) {
  59. $this->smarty->assign('success', $success);
  60. }
  61. return PANEL_REDIRECT_CURRENT;
  62. }
  63. /**
  64. * Enter description here...
  65. *
  66. * @param unknown_type $id
  67. * @return int
  68. */
  69. function doenable($id) {
  70. $success = -1;
  71. $fp_plugins = $this->fp_plugins;
  72. if (plugin_exists($id)) {
  73. $success = 1;
  74. if (!in_array($id, $fp_plugins)) {
  75. $fp_plugins[] = $id;
  76. sort($fp_plugins);
  77. plugin_load($id, false, false);
  78. do_action('activate_'. $id);
  79. $success = system_save(CONFIG_DIR .'plugins.conf.php', compact('fp_plugins'));
  80. } else {
  81. $success = -1;
  82. }
  83. }
  84. if ($success) {
  85. $this->smarty->assign('success', $success);
  86. }
  87. return PANEL_REDIRECT_CURRENT;
  88. }
  89. /**
  90. * Enter description here...
  91. *
  92. * @return int
  93. */
  94. function main() {
  95. //$conf = io_load_file(CONFIG_DIR . 'plugins.conf.php');
  96. $this->smarty->assign('warnings', $this->errors);
  97. $this->smarty->assign('enabledlist', $this->fp_plugins);
  98. lang_load('admin.plugin');
  99. return 0;
  100. }
  101. /**
  102. * Enter description here...
  103. *
  104. * @return int
  105. */
  106. function onsave() {
  107. $fp_plugins = array_keys($_POST['plugin_enabled']);
  108. $success = system_save(CONFIG_DIR . 'plugins.conf.php', compact('fp_plugins'));
  109. $retval = $success
  110. ? 1
  111. : -1 ;
  112. $this->smarty->assign('success', $retval);
  113. //$this->smarty->assign('pluginconf', $str);
  114. return $retval;
  115. }
  116. }
  117. ?>