示例#1
0
/**
 * used to display the entries for the list of uninstalled plugins, in admin/plugins.php
 *
 * @param  string $fieldName
 * @param  string $fieldValue
 * @param  array  $A
 * @param  array  $icon_arr
 * @param  string $selected
 * @return string
 */
function ADMIN_getListField_newplugins($fieldName, $fieldValue, $A, $icon_arr, $selected = '')
{
    global $_CONF, $LANG32;
    switch ($fieldName) {
        case 'info_uninstalled':
            $retval = COM_createLink($icon_arr['info'], "{$_CONF['site_admin_url']}/plugins.php?mode=info_uninstalled&pi_name={$A['pi_name']}", array('title' => $LANG32[13]));
            break;
        case 'pi_version':
            $params = PLG_getParams($A['pi_name']);
            $retval = $params['info']['pi_version'];
            break;
        case 'pi_dependencies':
            if (PLG_checkDependencies($A['pi_name'])) {
                $retval = COM_getTooltip($LANG32[51], PLG_printDependencies($A['pi_name'], $A['pi_gl_version']));
            } else {
                $style = "display: inline; color: #a00; border-bottom: 1px dotted #a00;";
                $retval = COM_getTooltip("<b class='notbold' style='{$style}'>{$LANG32[52]}</b>", PLG_printDependencies($A['pi_name'], $A['pi_gl_version']));
            }
            break;
        case 'install_link':
            if (PLG_checkDependencies($A['pi_name'])) {
                $retval = COM_createLink($icon_arr['install'], $A['install_link'], array('title' => $LANG32[62]));
            } else {
                $retval = str_replace('<img ', '<img title="' . $LANG32[63] . '" ', $icon_arr['unavailable']);
            }
            break;
        default:
            $retval = $fieldValue;
            break;
    }
    return $retval;
}
示例#2
0
/**
*  Disables all plugins with unresolved dependencies
*  and resolves the load order for all enabled plugins.
*
* @return   bool    True or False, depending on whether it was
*                   necessary to alter the load order of a plugin
* @since            Geeklog 1.8.0
*/
function PLG_resolveDependencies()
{
    global $_PLUGINS, $_TABLES;
    $retval = '';
    $flag = true;
    // false means that all dependencies are resolved
    while ($flag) {
        // loop until ALL dependencies are satisfied
        $flag = false;
        // set this if any plugin has been disabled during the loop
        foreach ($_PLUGINS as $key => $pi_name) {
            if (!PLG_checkDependencies($pi_name)) {
                // plugin has unresolved dependencies
                // disable plugin;
                $flag = true;
                // disabling a plugin can break the dependencies of a plugin that has already been checked, remember to loop again
                PLG_enableStateChange($pi_name, false);
                DB_change($_TABLES['plugins'], 'pi_enabled', 0, 'pi_name', $pi_name);
                PLG_pluginStateChange($pi_name, 'disabled');
                unset($_PLUGINS[$key]);
            }
        }
    }
    // automatically resolve load order for enabled plugins
    $index = 2000;
    // how far through the load order to push back plugins
    $maxqueries = 50;
    // just in case...
    $globalflag = false;
    // remember if we change the load order of any plugin
    $flag = true;
    // set true if we need another pass in the while loop
    while ($flag && $maxqueries) {
        // Now check if the load order is correct
        $flag = false;
        // get the load orders of all enabled plugins
        $q = DB_query("SELECT pi_name, pi_load FROM {$_TABLES['plugins']} WHERE pi_enabled='1'");
        $plo = array();
        // Plugins Load Order
        while ($a = DB_fetchArray($q)) {
            $plo[] = $a;
        }
        $params = array();
        foreach ($plo as $key => $value) {
            // for each available plugin
            $maxqueries--;
            $params = PLG_getParams($value['pi_name']);
            // get dependencies
            if (isset($params['requires']) && is_array($params['requires'])) {
                // if any
                foreach ($params['requires'] as $rkey => $rvalue) {
                    // process each dependency
                    if (isset($rvalue['plugin'])) {
                        // get the load order of the required plugin
                        foreach ($plo as $new_key => $new_value) {
                            if ($new_value['pi_name'] == $rvalue['plugin']) {
                                $dep_load = $new_value['pi_load'];
                                break;
                            }
                        }
                        if ($dep_load > $value['pi_load']) {
                            // incorrect load order
                            // move down the order
                            DB_query("UPDATE {$_TABLES['plugins']} SET pi_load = '{$index}' WHERE pi_name = '{$value['pi_name']}'");
                            $index++;
                            $flag = true;
                            $globalflag = true;
                        }
                    }
                }
            }
        }
    }
    reorderplugins();
    if ($globalflag == false) {
        return true;
        // no change
    } else {
        return false;
        // something changed
    }
}
示例#3
0
function MONITOR_getListField_plugins($fieldname, $fieldvalue, $A, $icon_arr, $token)
{
    global $_CONF, $_MONITOR_CONF, $LANG_ADMIN, $LANG32, $_TABLES, $ready_plugins, $LANG_MONITOR_1;
    $retval = '';
    switch ($fieldname) {
        case 'pi_name':
            $retval = MONITOR_get_pluginname($A['pi_name']);
            break;
        case 'pi_version':
            $plugin_code_version = PLG_chkVersion($A['pi_name']);
            if (empty($plugin_code_version)) {
                $code_version = $LANG_ADMIN['na'];
            } else {
                $code_version = $plugin_code_version;
            }
            $pi_installed_version = $A['pi_version'];
            if (empty($plugin_code_version) || $pi_installed_version == $code_version) {
                $retval = $pi_installed_version;
            } else {
                $retval = "{$LANG32[37]}: {$pi_installed_version},&nbsp;{$LANG32[36]}: {$plugin_code_version}";
                if ($A['pi_enabled'] == 1) {
                    $retval .= " <b>{$LANG32[38]}</b>";
                    $csrftok = '&amp;' . CSRF_TOKEN . '=' . $token;
                    $style = 'style="vertical-align: middle;"';
                    $img = $_CONF['layout_url'] . '/images/update.png';
                    $img = "<img {$style} alt=\"[" . $LANG32[38] . "]\" src=\"{$img}\"" . XHTML . ">";
                    $url = $_CONF['site_admin_url'] . '/plugins.php?mode=updatethisplugin&amp;pi_name=' . $A['pi_name'] . $csrftok;
                    $retval .= COM_CreateLink($img, $url, array('title' => $LANG32[42]));
                }
            }
            break;
        case 'pi_dependencies':
            if (PLG_checkDependencies($A['pi_name'])) {
                $retval = COM_getTooltip($LANG32[51], PLG_printDependencies($A['pi_name'], $A['pi_gl_version']));
            } else {
                $style = "display: inline; color: #a00; border-bottom: 1px dotted #a00;";
                $retval = COM_getTooltip("<b class='notbold' style='{$style}'>{$LANG32[52]}</b>", PLG_printDependencies($A['pi_name'], $A['pi_gl_version']));
            }
            break;
        case 'pi_update':
            if (!PLG_checkDependencies($A['pi_name'])) {
                $retval = str_replace('<img ', '<img title="' . $LANG32[64] . '" ', $icon_arr['warning']);
            } else {
                $available = false;
                // plugin in repository
                $dependencie = true;
                $not_present = false;
                if ($A['pi_enabled'] == 1) {
                    $title = '';
                    $link = '';
                    $plugin = $A['pi_name'];
                    if (in_array($plugin, $ready_plugins)) {
                        //Check if plugin is in repo
                        $url = GITHUB_REPOSITORY . $plugin . '/releases';
                        //Get last release for this plugin
                        $releases = MONITOR_curlRequestOnGitApi($url);
                        $tag = $releases[0]['tag_name'];
                        if ($tag != '') {
                            $available = true;
                        }
                        //Is release newer
                        $installed_version = DB_getItem($_TABLES['plugins'], 'pi_version', "pi_name = '{$plugin}'");
                        if ($tag != '' && 'v' . $installed_version != $tag) {
                            $update = true;
                            $autoinstall_url = 'https://raw.githubusercontent.com/' . $_MONITOR_CONF['repository'] . '/' . $plugin . '/' . $tag . '/autoinstall.php';
                            $ch = curl_init();
                            curl_setopt($ch, CURLOPT_URL, $autoinstall_url);
                            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                            $data = curl_exec($ch);
                            curl_close($ch);
                            //Get infos from plugin
                            $data = preg_replace('/\\s+/', '', $data);
                            $gl_version = MONITOR_extract_unit($data, "pi_gl_version'=>'", "',");
                            //Geeklog dependencie
                            if (COM_versionCompare(VERSION, $gl_version, '>=')) {
                                $title = $LANG_MONITOR_1['update_to'] . ' ' . $tag;
                                $link = $_CONF['site_admin_url'] . "/plugins/monitor/index.php?action=update_plugin&amp;plugin={$plugin}";
                            } else {
                                $dependencie = false;
                                $title = $LANG_MONITOR_1['need_upgrade'] . $gl_version . '+ ' . $LANG_MONITOR_1['before_update'] . ' ' . $plugin . ' ' . $tag;
                                $link = "https://www.geeklog.net";
                            }
                        } else {
                            if ($tag == '') {
                                // The plugin is not available in this repo
                                $update = false;
                                if (is_string($releases['message'])) {
                                    $title = $releases['message'];
                                    $link = $releases['documentation_url'];
                                } else {
                                    $title = $LANG_MONITOR_1['not_available'];
                                    $link = "https://github.com/{$_MONITOR_CONF['repository']}";
                                }
                            } else {
                                // The plugin is up to date
                                $update = false;
                            }
                        }
                    } else {
                        $update = false;
                        //Ask plugin author to change this :)
                        $title = $LANG_MONITOR_1['ask_author'];
                        $link = DB_getItem($_TABLES['plugins'], 'pi_homepage', "pi_name = '{$plugin}'");
                    }
                } else {
                    $title = 'Update this plugin';
                    $link = '';
                    $update = true;
                    if (!file_exists($_CONF['path'] . 'plugins/' . $A['pi_name'] . '/functions.inc')) {
                        $not_present = true;
                    }
                }
                if ($not_present) {
                    $retval = str_replace('<img ', '<img title="' . $LANG32[64] . '" ', $icon_arr['unavailable']);
                } else {
                    $sorting = '';
                    $csrftoken = '&amp;' . CSRF_TOKEN . '=' . $token;
                    if (!empty($_GET['order']) && !empty($_GET['direction'])) {
                        // Remember how the list was sorted
                        $ord = trim($_GET['order']);
                        $dir = trim($_GET['direction']);
                        $old = trim($_GET['prevorder']);
                        $sorting = "&amp;order={$ord}&amp;direction={$dir}&amp;prevorder={$old}";
                    }
                    //Icons in update coloumn
                    if (!$update && in_array($plugin, $ready_plugins) && $available) {
                        $retval = str_replace('<img ', $LANG_MONITOR_1['up_to_date'] . ' <img title="' . $LANG_MONITOR_1['up_to_date'] . '" ', $icon_arr['enabled']);
                        $retval = $icon_arr['enabled'] . ' ' . $LANG_MONITOR_1['up_to_date'];
                    } else {
                        if (!$update && in_array($plugin, $ready_plugins) && !$available) {
                            $retval = COM_createLink($icon_arr['info'] . ' ' . $title, $link . $sorting, array('title' => ''));
                        } else {
                            if (!$update && !in_array($plugin, $ready_plugins)) {
                                $retval = COM_createLink($icon_arr['disabled'] . ' ' . $title, $link . $sorting, array('title' => ''));
                            } else {
                                if (!$update) {
                                    $retval = str_replace('<img ', '<img title="' . $LANG_MONITOR_1['no_update'] . '" ', $icon_arr['disabled']);
                                } else {
                                    if ($dependencie == false) {
                                        $retval = COM_createLink($icon_arr['warning'] . ' ' . $title, $link . $sorting, array('title' => ''));
                                    } else {
                                        $retval = COM_createLink($icon_arr['info'] . ' ' . $title, $link . $sorting, array('title' => ''));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            break;
        default:
            $retval = $fieldvalue;
            break;
    }
    return $retval;
}