2 // vim: tabstop=2:shiftwidth=2
\r
5 * index.php ($Revision: 1.99 $)
\r
7 * by hsur ( http://blog.cles.jp/np_cles )
\r
8 * $Id: index.php,v 1.99 2010/06/06 11:44:19 hsur Exp $
\r
12 * Copyright (C) 2005-2010 CLES. All rights reserved.
\r
14 * This program is free software; you can redistribute it and/or
\r
15 * modify it under the terms of the GNU General Public License
\r
16 * as published by the Free Software Foundation; either version 2
\r
17 * of the License, or (at your option) any later version.
\r
19 * This program is distributed in the hope that it will be useful,
\r
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
22 * GNU General Public License for more details.
\r
24 * You should have received a copy of the GNU General Public License
\r
25 * along with this program; if not, write to the Free Software
\r
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\r
28 * In addition, as a special exception, cles( http://blog.cles.jp/np_cles ) gives
\r
29 * permission to link the code of this program with those files in the PEAR
\r
30 * library that are licensed under the PHP License (or with modified versions
\r
31 * of those files that use the same license as those files), and distribute
\r
32 * linked combinations including the two. You must obey the GNU General Public
\r
33 * License in all respects for all of the code used other than those files in
\r
34 * the PEAR library that are licensed under the PHP License. If you modify
\r
35 * this file, you may extend this exception to your version of the file,
\r
36 * but you are not obligated to do so. If you do not wish to do so, delete
\r
37 * this exception statement from your version.
\r
40 define('PAINT_INI_URL', 'http://blog.cles.jp/support/paint.ini');
\r
41 define('PAINT_PLUGIN_DIR', dirname(__FILE__)."/applet");
\r
43 $strRel = '../../../';
\r
44 include ($strRel.'config.php');
\r
45 include ($DIR_LIBS.'PLUGINADMIN.php');
\r
47 require_once($DIR_PLUGINS . 'sharedlibs/sharedlibs.php');
\r
48 require_once('cles/Feedback.php');
\r
49 require_once('cles/Template.php');
\r
50 require_once('pclzip.lib.php');
\r
53 $isblogadmin = $member->isBlogAdmin($blogid);
\r
57 if (!$member->isLoggedIn()) {
\r
58 $oPluginAdmin = new PluginAdmin('Paint');
\r
59 $oPluginAdmin->start();
\r
60 echo '<p>' . _PAINT_NeedLogin . '</p>';
\r
61 $oPluginAdmin->end();
\r
65 if (!($member->isAdmin() || $isblogadmin)) {
\r
66 $oPluginAdmin = new PluginAdmin('Paint');
\r
67 $oPluginAdmin->start();
\r
68 echo "<p>"._ERROR_DISALLOWED."</p>";
\r
69 $oPluginAdmin->end();
\r
73 $action = requestVar('action');
\r
74 $aActionsNotToCheck = array(
\r
78 if (!in_array($action, $aActionsNotToCheck)) {
\r
79 if (!$manager->checkTicket()) doError(_ERROR_BADTICKET);
\r
82 // create the admin area page
\r
83 $oPluginAdmin = new PluginAdmin('Paint');
\r
84 $oPluginAdmin->start();
\r
85 $fb =& new cles_Feedback($oPluginAdmin);
\r
87 $templateEngine =& new cles_Template(dirname(__FILE__).'/template');
\r
88 define('NP_PAINT_TEMPLATEDIR_INDEX', 'index');
\r
90 'indexurl' => serverVar('PHP_SELF'),
\r
91 'optionurl' => $CONF['AdminURL'] . 'index.php?action=pluginoptions&plugid=' . $oPluginAdmin->plugin->getid(),
\r
92 'paintiniurl' => PAINT_INI_URL,
\r
93 'paintplugindir' => PAINT_PLUGIN_DIR,
\r
94 'ticket' => $manager->_generateTicket(),
\r
97 // get the plugin options; stored in the DB
\r
98 //$pbl_config['enabled'] = $oPluginAdmin->plugin->getOption('enabled');
\r
101 $menu = $templateEngine->fetch('menu', NP_PAINT_TEMPLATEDIR_INDEX);
\r
102 echo $templateEngine->fill($menu, $tplVars, false);
\r
107 echo $templateEngine->fetch('help', NP_PAINT_TEMPLATEDIR_INDEX);
\r
111 if( requestVar('func') == 'ini' ){
\r
112 $err = paint_plugin_download( PAINT_INI_URL, PAINT_PLUGIN_DIR);
\r
114 echo '<h3>Error: ' . _PAINT_canNotReadFile . ':' .PAINT_INI_URL . '</h3>';
\r
115 echo '<h4>Reason: '.$err.'</h4>';
\r
120 echo "<h2>"._PAINT_iniDownload."</h2>";
\r
122 echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?action=install&func=ini"),ENT_QUOTES)."\">"._PAINT_doDownload."</a></li>\n";
\r
125 if( ! is_readable(PAINT_PLUGIN_DIR . '/paint.ini') )
\r
128 $settings = parse_ini_file(PAINT_PLUGIN_DIR . '/paint.ini', true);
\r
130 echo '<h3>Error: ' . _PAINT_canNotReadFile . ': ' .PAINT_INI_URL . '</h3>';
\r
134 echo '<h2>' . _PAINT_appletinstall. "( {$settings['paint']['version']}[{$settings['paint']['updated']}] )</h2>";
\r
136 if ($pluginName = getVar('plugin')) {
\r
137 $oPluginAdmin->plugin->_loadPlugin();
\r
138 $plugin = $oPluginAdmin->plugin->disabledPlugin[$pluginName];
\r
141 $zipurl = $settings[$pluginName]['zip'];
\r
143 echo paint_plugin_install($zipurl);
\r
145 echo '<h3>Error:' ._PAINT_canNotAutoInstall . '</h3>';
\r
148 echo '<h3>Error:'. _PAINT_noSuchPlugin . '</h3>';
\r
152 $oPluginAdmin->plugin->_loadPlugin(false, true);
\r
153 ksort($oPluginAdmin->plugin->disabledPlugin);
\r
155 echo '<h3>'._PAINT_autoInstall.'</h3>';
\r
157 foreach ($oPluginAdmin->plugin->disabledPlugin as $key => $plugin) {
\r
158 if ( $settings[$key]['zip'] )
\r
159 echo "<li><a href=\"".htmlspecialchars($manager->addTicketToUrl(serverVar('PHP_SELF')."?action=install&plugin=".$key),ENT_QUOTES)."\">".$plugin->getName()._PAINT_installSuffix."</a></li>\n";
\r
160 elseif ( $settings[$key]['file'] )
\r
161 echo "<li><em>".$plugin->getName(). _PAINT_canNotAutoInstall ."<br /><a href=\"{$settings[$key]['file']}\">{$settings[$key]['file']}</a>"._PAINT_downloadSuffix."</em></li>\n";
\r
163 echo "<li><em>".$plugin->getName(). _PAINT_canNotAutoInstall . "</em></li>\n";
\r
170 $oPluginAdmin->plugin->_loadPlugin();
\r
172 foreach ($oPluginAdmin->plugin->parsers as $key => $name) {
\r
173 $extra .= 'parser_'.$key.', ';
\r
175 foreach ($oPluginAdmin->plugin->applets as $key => $name) {
\r
176 $extra .= 'applet_'.$key.', ';
\r
178 foreach ($oPluginAdmin->plugin->palettes as $key => $name) {
\r
179 $extra .= 'palette_'.$key.', ';
\r
181 foreach ($oPluginAdmin->plugin->viewers as $key => $name) {
\r
182 $extra .= 'viewer_'.$key.', ';
\r
184 $fb->printForm($extra);
\r
194 $oPluginAdmin->end();
\r
196 function paint_plugin_install($url) {
\r
197 $err = paint_plugin_download($url, PAINT_PLUGIN_DIR);
\r
201 $file = PAINT_PLUGIN_DIR . '/' . basename($url);
\r
202 $err = paint_plugin_extract($file, PAINT_PLUGIN_DIR);
\r
207 function paint_plugin_extract($file, $dir) {
\r
208 $archive = new PclZip($file);
\r
209 if ($archive->extract(PCLZIP_OPT_PATH, $dir, PCLZIP_OPT_SET_CHMOD, 0777) == 0) {
\r
210 return $archive->errorInfo(true);
\r
215 function paint_plugin_download($url, $dir) {
\r
216 if (!@ is_writable($dir) || !@ is_dir($dir)) {
\r
217 return _Paint_directoryNotWriteable . $dir;
\r
220 $remote = fopen($url, "rb");
\r
221 socket_set_timeout($remote, 10);
\r
223 return _PAINT_fileOpen_failure . ': '.$url;
\r
225 $file = $dir.'/'.basename($url);
\r
226 $local = fopen($file, "wb");
\r
227 socket_set_timeout($local, 5);
\r
229 return _PAINT_fileOpen_failure . ': '.$file;
\r
231 while (!feof($remote)) {
\r
232 $buffer = fgets($remote, 4096);
\r
233 fputs($local, $buffer);
\r