index.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. # ***** BEGIN LICENSE BLOCK *****
  3. # This file is part of DotClear.
  4. # Copyright (c) 2004 Olivier Meunier and contributors. All rights
  5. # reserved.
  6. #
  7. # DotClear is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # DotClear is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with DotClear; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. #
  21. # ***** END LICENSE BLOCK *****
  22. $err = '';
  23. $tool_url = '';
  24. # Liste des thèmes
  25. $plugins_root = dirname(__FILE__).'/../';
  26. $plugins = new plugins($plugins_root);
  27. $plugins->getPlugins(false);
  28. $plugins_list = $plugins->getPluginsList();
  29. $is_writable = is_writable($plugins_root);
  30. # Installation d'un thème
  31. if ($is_writable && !empty($_GET['tool_url']))
  32. {
  33. $tool_url = $_GET['tool_url'];
  34. $parsed_url = parse_url($tool_url);
  35. if (empty($parsed_url['scheme']) || !preg_match('/^http|ftp$/',$parsed_url['scheme'])
  36. || empty($parsed_url['host']) || empty($parsed_url['path']))
  37. {
  38. $err = __('URL is not valid.');
  39. }
  40. else
  41. {
  42. if (($err = $plugins->install($tool_url)) === true)
  43. {
  44. header('Location: tools.php?p=toolsmng');
  45. exit;
  46. }
  47. }
  48. }
  49. # Changement de status d'un plugin
  50. $switch = (!empty($_GET['switch'])) ? $_GET['switch'] : '';
  51. if ($is_writable && $switch != '' && in_array($switch,array_keys($plugins_list)) && $switch != 'toolsmng')
  52. {
  53. $plugins->switchStatus($switch);
  54. header('Location: tools.php?p=toolsmng');
  55. exit;
  56. }
  57. # Suppression d'un thème
  58. $delete = (!empty($_GET['delete'])) ? $_GET['delete'] : '';
  59. if ($is_writable && $delete != '' && in_array($delete,array_keys($plugins_list)) && $delete != 'toolsmng')
  60. {
  61. files::deltree($plugins_root.'/'.$delete);
  62. header('Location: tools.php?p=toolsmng');
  63. exit;
  64. }
  65. if($err != '')
  66. {
  67. buffer::str(
  68. '<div class="erreur"><p><strong>'.__('Error(s)').' :</strong></p>'.$err.'</div>'
  69. );
  70. }
  71. buffer::str(
  72. '<h2>'.__('Plugins manager').'</h2>'.
  73. '<h3>'.__('Install a plugin').'</h3>'
  74. );
  75. if (!$is_writable)
  76. {
  77. buffer::str(
  78. '<p>'.sprintf(__('The folder %s is not writable, please check its permissions.'),
  79. DC_ECRIRE.'/tools/').'</p>'
  80. );
  81. }
  82. else
  83. {
  84. buffer::str(
  85. '<form action="tools.php" method="get">'.
  86. '<p><label for="tool_url">'.__('Please give the URL (http or ftp) of the plugin\'s file').' :</label>'.
  87. form::field('tool_url',50,'',$tool_url).'</p>'.
  88. '<p><input type="submit" class="submit" value="'.__('install').'" />'.
  89. '<input type="hidden" name="p" value="toolsmng" /></p>'.
  90. '</form>'
  91. );
  92. }
  93. buffer::str(
  94. '<p><a href="http://www.dotclear.net/plugins/">'.__('Install new plugins').'</a></p>'
  95. );
  96. # Traduction des plugins
  97. foreach ($plugins_list as $k => $v)
  98. {
  99. $plugins->loadl10n($k);
  100. $plugins_list[$k]['label'] = __($v['label']);
  101. $plugins_list[$k]['desc'] = __($v['desc']);
  102. }
  103. # Tri des plugins par leur nom
  104. uasort($plugins_list,create_function('$a,$b','return strcmp($a["label"],$b["label"]);'));
  105. buffer::str(
  106. '<h3>'.__('List of installed plugins').'</h3>'.
  107. '<dl>'
  108. );
  109. foreach ($plugins_list as $k => $v)
  110. {
  111. buffer::str(
  112. '<dt>'.__($v['label']).' - '.$k.'</dt>'.
  113. '<dd>'.__($v['desc']).' <br />'.
  114. 'par '.$v['author'].' - '.__('version').' '.$v['version'].' <br />'
  115. );
  116. if ($k != 'toolsmng')
  117. {
  118. if (is_writable($plugins_root.$k.'/desc.xml')) {
  119. $action = $v['active'] ? 'disable' : 'enable';
  120. buffer::str('<a href="tools.php?p=toolsmng&switch='.$k.'">'.__($action).'</a>');
  121. } else {
  122. buffer::str('<em>'.sprintf(__('cannot enable/disable'),'desc.xml').'</em>');
  123. }
  124. if ($is_writable)
  125. {
  126. buffer::str(
  127. ' - <a href="tools.php?p=toolsmng&amp;delete='.$k.'" '.
  128. 'onclick="return window.confirm(\''.__('Are you sure you want to delete this plugin ?').'\')">'.
  129. __('delete').'</a>'
  130. );
  131. }
  132. }
  133. buffer::str('</dd>');
  134. }
  135. buffer::str('</dl>');
  136. ?>