Esempio n. 1
0
    if (preg_match('/^lang_plugin_(.*)$/i', $matches[1], $match_plugin)) {
        cpg_load_plugin_language_file($match_plugin[1]);
    }
    if (isset($matches[3])) {
        $header = ${$matches[1]}[$matches[2]][$matches[3]];
    } elseif (isset($matches[2])) {
        $header = ${$matches[1]}[$matches[2]];
    } else {
        $header = ${$matches[1]};
    }
} else {
    $header = '';
}
if ($superCage->get->keyExists('t') && preg_match('/^(lang_[a-z0-9_]+)(?:\\[([a-z0-9_]+)\\])?(?:\\[([a-z0-9_]+)\\])?$/', $superCage->get->getEscaped('t'), $matches)) {
    if (preg_match('/^lang_plugin_(.*)$/i', $matches[1], $match_plugin)) {
        cpg_load_plugin_language_file($match_plugin[1]);
    }
    if ($matches[1] == 'lang_tmp_picture_manager') {
        $text = <<<EOT
            <ul>
                <li>{$lang_picmgr_php['explanation1']}</li>
                <li>{$lang_picmgr_php['explanation2']}</li>
            </ul>
EOT;
    } elseif ($matches[1] == 'lang_tmp_upload') {
        $restriction_filesize = sprintf($lang_upload_php['restriction_filesize'], '<strong>' . cpg_format_bytes($CONFIG['max_upl_size'] * 1024) . '</strong>');
        if ($CONFIG['allowed_img_types'] != '') {
            $allowed_img_types = '<li>' . sprintf($lang_upload_php['allowed_img_types'], $CONFIG['allowed_img_types']) . '</li>';
        } else {
            $allowed_img_types = '';
        }
 /**
  * CPGPluginAPI::install()
  *
  * Installs a plugin and executes 'plugin_install' action
  *
  * @param string $path_to_plugin_folder
  * @return N/A
  **/
 public static function install($path)
 {
     global $CONFIG, $thisplugin, $CPG_PLUGINS, $lang_plugin_api;
     // If this plugin is already installed return true
     if (CPGPluginAPI::installed($path)) {
         return true;
     }
     // If codebase.php or configuration.php don't exist, skip this plugin
     if (!(file_exists('./plugins/' . $path . '/codebase.php') && file_exists('./plugins/' . $path . '/configuration.php'))) {
         return false;
     }
     // Load language files
     $lg = 'lang_plugin_' . $path;
     global ${$lg};
     cpg_load_plugin_language_file($path);
     // Get the lowest priority level (highest number) from the database
     $sql = "SELECT priority FROM {$CONFIG['TABLE_PLUGINS']} ORDER BY priority DESC LIMIT 1";
     $result = cpg_db_query($sql);
     $data = mysql_fetch_assoc($result);
     mysql_free_result($result);
     // Set the execution priority to last
     $priority = is_null($data['priority']) ? 0 : $data['priority'] + 1;
     // Grab the plugin's credits
     include_once './plugins/' . $path . '/configuration.php';
     // Create a generic plugin object
     $thisplugin = new CPGPlugin(array('plugin_id' => 'new', 'name' => $name, 'priority' => $priority, 'path' => $path));
     $thisplugin->awake = true;
     // Grab plugin's code
     include_once './plugins/' . $path . '/codebase.php';
     // Copy it to the global scope
     $CPG_PLUGINS['new'] = $thisplugin;
     // If the plugin has an install action, execute it
     $installed = CPGPluginAPI::action('plugin_install', true, CPG_EXEC_NEW);
     // If $installed is boolean then plugin was installed; Return true
     if (is_bool($installed) && $installed) {
         $sql = "INSERT INTO {$CONFIG['TABLE_PLUGINS']} (name, path, priority) VALUES ('" . addslashes($name) . "', '" . addslashes($path) . "', {$priority})";
         $result = cpg_db_query($sql);
         if ($CONFIG['log_mode']) {
             log_write("Plugin '" . $name . "' installed", CPG_GLOBAL_LOG);
         }
         return $installed;
         // If $installed is an integer then the plugin needs to be configured; Return the value
     } elseif (is_int($installed)) {
         return $installed;
         // Plugin wasn't installed; Display an error
     } else {
         // The plugin's install function failed
         cpg_die(CRITICAL_ERROR, sprintf($lang_plugin_api['error_install'], $thisplugin->name), __FILE__, __LINE__);
     }
 }
function display_plugin_list()
{
    global $CPG_PLUGINS, $lang_pluginmgr_php, $lang_common, $CONFIG, $CPG_PHP_SELF;
    list($timestamp, $form_token) = getFormToken();
    $help = '&nbsp;' . cpg_display_help('f=plugins.htm&amp;as=plugin_manager&amp;ae=plugin_manager_end&amp;top=1', '800', '600');
    $help_plugin_enable = cpg_display_help('f=configuration.htm&amp;as=admin_general_enable-plugins&amp;ae=admin_general_enable-plugins_end', 400, 300);
    // configure plugin api (enabled or disabled)
    $yes_selected = $CONFIG['enable_plugins'] ? 'checked="checked"' : '';
    $no_selected = !$CONFIG['enable_plugins'] ? 'checked="checked"' : '';
    print '<form name="pluginenableconfig" id="cpgform2" action="' . $CPG_PHP_SELF . '" method="post" style="margin:0px;padding:0px">';
    starttable('-1', cpg_fetch_icon('plugin_mgr', 2) . $lang_pluginmgr_php['pmgr'] . $help, 3);
    echo <<<EOT
        <tr>
                <td class="tableh2" colspan="3">
                    {$lang_pluginmgr_php['explanation']}
                </td>
        </tr>
        <tr>
                <td class="tableb">
                    {$lang_pluginmgr_php['plugin_enabled']}
                </td>
                <td class="tableb">
                    <input type="radio" id="enable_plugins1" name="enable_plugins" value="1"  onclick="document.pluginenableconfig.submit();" {$yes_selected} class="radio" /><label for="enable_plugins1" class="clickable_option">{$lang_common['yes']}</label>
                    &nbsp;&nbsp;
                    <input type="radio" id="enable_plugins0" name="enable_plugins" value="0"  onclick="document.pluginenableconfig.submit();" {$no_selected} class="radio" /><label for="enable_plugins0" class="clickable_option">{$lang_common['no']}</label>
                    <input type="hidden" name="update_config" value="1" />
                    <input type="hidden" name="form_token" value="{$form_token}" />
                    <input type="hidden" name="timestamp" value="{$timestamp}" />
                </td>
                <td class="tableb">
                    {$help_plugin_enable}
                </td>
        </tr>
EOT;
    endtable();
    print '</form>';
    echo <<<EOT
        <br />
EOT;
    $help = '&nbsp;' . cpg_display_help('f=plugins.htm&amp;as=plugin_manager_uninstall&amp;ae=plugin_manager_uninstall_end&amp;top=1', '640', '480');
    $available_plugins = cpg_get_dir_list('./plugins/');
    starttable('100%');
    echo <<<EOT
        <tr>
                <td class="tableh1" width="90%"><strong><span class="statlink">{$lang_pluginmgr_php['i_plugins']}</span></strong></td>
                <td colspan="3" class="tableh1" align="center" width="10%"><strong><span class="statlink">{$lang_pluginmgr_php['operation']}</span></strong>{$help}</td>
        </tr>
EOT;
    unset($installed_plugins);
    if ($CONFIG['enable_plugins'] == 1) {
        $loop_counter = 0;
        foreach ($CPG_PLUGINS as $thisplugin) {
            $installed_plugins[$loop_counter] = array('index' => $thisplugin->index, 'plugin_id' => $thisplugin->plugin_id, 'path' => $thisplugin->path, 'priority' => $thisplugin->priority, 'error' => $thisplugin->error);
            $loop_counter++;
        }
    } else {
        // If plugin system is turned off, grab installed plugins from database table
        $query = 'SELECT * FROM ' . $CONFIG['TABLE_PLUGINS'] . ' ORDER BY priority ASC;';
        $result = cpg_db_query($query);
        $loop_counter = 0;
        while ($installed_plugin = mysql_fetch_assoc($result)) {
            $installed_plugins[$loop_counter] = array('index' => $loop_counter, 'plugin_id' => $installed_plugin['plugin_id'], 'path' => $installed_plugin['path'], 'priority' => $installed_plugin['priority'], 'error' => array());
            $loop_counter++;
        }
    }
    $installed_count = 0;
    $loop_counter = 0;
    if (isset($installed_plugins) == TRUE) {
        $plugins_count = count($installed_plugins);
        foreach ($installed_plugins as $thisplugin) {
            $installed_count++;
            // Load language files
            $lg = 'lang_plugin_' . $thisplugin['path'];
            global ${$lg};
            cpg_load_plugin_language_file($thisplugin['path']);
            unset($extra_info);
            unset($install_info);
            include './plugins/' . $thisplugin['path'] . '/configuration.php';
            $pluginPath = $thisplugin['path'];
            $safename = addslashes(str_replace('&nbsp;', '', $name));
            if (isset($extra_info) == TRUE) {
                $extra = $extra_info;
            } else {
                $extra = '';
            }
            if (sizeof($thisplugin['error']) > 0) {
                $error = $thisplugin['error']['desc'];
                $extra = '<tr><td class="tableb" width="100%" colspan="2">' . '<strong>' . $lang_common['error'] . ':</strong> <span style="color:red;">' . $error . '</span>' . '</td></tr>' . $extra;
            }
            if ($loop_counter == 0) {
                $row_style_class = 'tableb';
            } else {
                $row_style_class = 'tableb tableb_alternate';
            }
            $loop_counter++;
            if ($loop_counter > 1) {
                $loop_counter = 0;
            }
            echo <<<EOT
        <tr>
            <td width="90%" class="{$row_style_class}">
                <a name="{$pluginPath}"></a>
                <table border="0" width="100%" cellspacing="0" cellpadding="0" class="maintable">
                    <tr>
                        <td colspan="2" class="tableh1">{$name} ({$pluginPath}): {$lang_pluginmgr_php['vers']}{$version}</td>
                    </tr>
                    <tr>
                        <td class="tableb" valign="top">{$lang_pluginmgr_php['author']}:</td>
                        <td class="tableb" valign="top">{$author}</td>
                    </tr>
                    <tr>
                        <td class="tableb tableb_alternate" valign="top">{$lang_pluginmgr_php['desc']}</td>
                        <td class="tableb tableb_alternate" valign="top">{$description}</td>
                    </tr>
EOT;
            if ($extra != '') {
                echo <<<EOT
                    <tr>
                        <td class="tableb" width="20%" valign="top">{$lang_pluginmgr_php['extra']}:</td>
                        <td class="tableb" valign="top">{$extra}</td>
                    </tr>
EOT;
            }
            echo <<<EOT
                </table>
            </td>
            <td class="{$row_style_class}" valign="top">
            <table border="0" width="100%" cellspacing="0" cellpadding="0">
            <tr>
EOT;
            if ($thisplugin['index'] > 0 && $plugins_count > 1) {
                $up = cpg_fetch_icon('up', 0);
                echo <<<EOT
            <td width="3%" align="center" valign="middle">
                <a href="pluginmgr.php?op=moveu&amp;p={$thisplugin['plugin_id']}&amp;form_token={$form_token}&amp;timestamp={$timestamp}#{$pluginPath}">{$up}</a>
            </td>
EOT;
            } else {
                echo '<td width="3%"></td>';
            }
            if ($thisplugin['index'] < $plugins_count - 1) {
                $down = cpg_fetch_icon('down', 0);
                echo <<<EOT
            <td width="3%" align="center" valign="middle">
                <a href="pluginmgr.php?op=moved&amp;p={$thisplugin['plugin_id']}&amp;form_token={$form_token}&amp;timestamp={$timestamp}#{$pluginPath}">{$down}</a>
            </td>
EOT;
            } else {
                echo '<td width="3%"></td>';
            }
            $confirm_function = $CONFIG['enable_plugins'] == 1 ? 'confirmUninstall' : 'confirmRemove';
            $delete = cpg_fetch_icon('plugin_uninstall', 0);
            echo <<<EOT
            <td width="3%" align="center" valign="middle">
                <a href="pluginmgr.php?op=uninstall&amp;p={$thisplugin['plugin_id']}&amp;form_token={$form_token}&amp;timestamp={$timestamp}" onclick="return {$confirm_function}('{$safename}')" title="{$lang_pluginmgr_php['uninstall']}">
                    {$delete}
                </a>
            </td>

        </tr>
        </table>
        </td>
        </tr>
EOT;
        }
    }
    if ($installed_count == 0) {
        echo '<tr><td colspan="4" class="tableb" align="center">' . $lang_pluginmgr_php['none_installed'] . '</td></tr>';
    }
    endtable();
    echo '<p>&nbsp;</p>';
    echo '<form name="cpgform" id="cpgform" action="pluginmgr.php?op=upload" method="post" enctype="multipart/form-data">';
    $help_upload = '&nbsp;' . cpg_display_help('f=plugins.htm&amp;as=plugin_manager_upload&amp;ae=plugin_manager_upload_end&amp;top=1', '640', '480');
    $help_install = '&nbsp;' . cpg_display_help('f=plugins.htm&amp;as=plugin_manager_install&amp;ae=plugin_manager_install_end&amp;top=1', '640', '480');
    starttable('100%');
    echo <<<EOT
        <tr>
                <td class="tableh1" width="90%">
                    <table border="0" cellpadding="0" cellspacing="0" width="100%">
                        <tr>
                            <td align="left">
                                <strong><span class="statlink">{$lang_pluginmgr_php['n_plugins']}</span></strong>{$help_install}
                            </td>
                            <td align="right">
                                    <input type="file" size="40" name="plugin" class="textinput" />
                                    <input type="hidden" name="form_token" value="{$form_token}" />
                                    <input type="hidden" name="timestamp" value="{$timestamp}" />
                                    <input type="submit" class="button" value="{$lang_pluginmgr_php['upload']}" />
                                    {$help_upload}
                            </td>
                        </tr>
                    </table>
                </td>
                <td colspan="3" class="tableh1" align="center" width="10%"><strong><span class="statlink">{$lang_pluginmgr_php['operation']}</span></strong></td>
        </tr>
EOT;
    $loop_counter = 0;
    // Note: CPGPluginAPI::installed() works even if Plugin API is disabled.
    foreach ($available_plugins as $path) {
        if (($plugin_id = CPGPluginAPI::installed($path)) === false) {
            // If codebase.php or configuration.php don't exist, skip this plugin
            if (!(file_exists('./plugins/' . $path . '/codebase.php') && file_exists('./plugins/' . $path . '/configuration.php'))) {
                continue;
            }
            // Load language files
            $lg = 'lang_plugin_' . $path;
            global ${$lg};
            cpg_load_plugin_language_file($path);
            unset($extra_info);
            unset($install_info);
            include './plugins/' . $path . '/configuration.php';
            $pluginPath = $path;
            $safename = addslashes(str_replace('&nbsp;', '', $name));
            if (isset($install_info) == TRUE) {
                $extra = $install_info;
            } else {
                $extra = '';
            }
            if ($loop_counter == 0) {
                $row_style_class = 'tableb';
            } else {
                $row_style_class = 'tableb tableb_alternate';
            }
            $loop_counter++;
            if ($loop_counter > 1) {
                $loop_counter = 0;
            }
            echo <<<EOT
            <tr>
            <td width="90%" class="{$row_style_class}">
                <table border="0" width="100%" cellspacing="0" cellpadding="0" class="maintable">
                    <tr>
                        <td colspan="2" class="tableh1">{$name} ({$pluginPath}): {$lang_pluginmgr_php['vers']}{$version}</td>
                    </tr>
                    <tr>
                        <td class="tableb tableb_alternate" width="20%" valign="top">{$lang_pluginmgr_php['author']}:</td>
                        <td class="tableb tableb_alternate" valign="top">{$author}</td>
                    </tr>
                    <tr>
                        <td class="tableb" valign="top">{$lang_pluginmgr_php['desc']}:</td>
                        <td class="tableb" valign="top">{$description}</td>
                    </tr>
EOT;
            if ($extra != '') {
                echo <<<EOT
                    <tr>
                        <td class="tableb tableb_alternate" width="20%" valign="top">{$lang_pluginmgr_php['install_info']}:</td>
                        <td class="tableb tableb_alternate" valign="top">{$extra}</td>
                    </tr>
EOT;
            }
            // Take care of version requirements
            if (isset($plugin_cpg_version['min']) == TRUE) {
                if (version_compare(COPPERMINE_VERSION, $plugin_cpg_version['min']) >= 0) {
                    $plugin_cpg_version['min_ok'] = '1';
                } else {
                    $plugin_cpg_version['min_ok'] = '-1';
                }
            } else {
                $plugin_cpg_version['min_ok'] = '0';
            }
            if (isset($plugin_cpg_version['max']) == TRUE) {
                if (version_compare(COPPERMINE_VERSION, $plugin_cpg_version['max']) <= 0) {
                    $plugin_cpg_version['max_ok'] = '1';
                } else {
                    $plugin_cpg_version['max_ok'] = '-1';
                }
            } else {
                $plugin_cpg_version['max_ok'] = '0';
            }
            if ($CONFIG['enable_plugins'] == 1) {
                if ($plugin_cpg_version['min_ok'] > 0 && $plugin_cpg_version['max_ok'] >= 0) {
                    $install_button = '<a href="pluginmgr.php?op=install&amp;p=' . $path . '&amp;form_token=' . $form_token . '&amp;timestamp=' . $timestamp . '" title="' . $lang_pluginmgr_php['install'] . '">' . cpg_fetch_icon('plugin_install', 0) . '</a>';
                } elseif ($plugin_cpg_version['min_ok'] < 0 || $plugin_cpg_version['max_ok'] < 0) {
                    if (isset($lang_pluginmgr_php['minimum_requirements_not_met']) != TRUE) {
                        $lang_pluginmgr_php['minimum_requirements_not_met'] = 'Minimum requirements not met';
                    }
                    $install_button = '<span title="' . $lang_pluginmgr_php['minimum_requirements_not_met'] . '">' . cpg_fetch_icon('cancel', 0) . '</span>';
                } else {
                    $install_button = '<a href="pluginmgr.php?op=install&amp;p=' . $path . '&amp;form_token=' . $form_token . '&amp;timestamp=' . $timestamp . '" onclick="return confirmVersionMissing(\'' . $safename . '\')" title="' . $lang_pluginmgr_php['install'] . '" >' . cpg_fetch_icon('plugin_mgr', 0) . '</a>';
                }
            } else {
                $install_button = cpg_fetch_icon('blank', 0);
            }
            unset($plugin_cpg_version);
            $delete = cpg_fetch_icon('delete', 0);
            echo <<<EOT
                </table>
            </td>
            <td class="{$row_style_class}" valign="top">
                <table border="0" width="100%" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="5%" align="center" valign="top">

                    </td>
                    <td width="5%" align="center" valign="top">
                        {$install_button}
                    </td>
                    <td width="5%" align="center" valign="top">
                        <a href="pluginmgr.php?op=delete&amp;p={$path}&amp;form_token={$form_token}&amp;timestamp={$timestamp}" onclick="return confirmDel('{$safename}')" title="{$lang_common['delete']}">
                            {$delete}
                        </a>
                    </td>
                </tr>
                </table>
            </td>
            </tr>
EOT;
        }
    }
    endtable();
    echo '</form>';
}