/**
 * Activate a named plugin.
 *
 * Parses the plugins directory to look for a pluginname.yaml
 * file and adds the plugin to the plugins database, setting
 * the inst_version field to the version specified in the yaml file.
 *
 * @param string $name Name of plugin to be activated.
 * @return bool Returns true if plugin directory was found.
 * @see deactivate_plugin
 */
function activate_plugin($name)
{
    $plugins_dir = dirname(__FILE__) . '/../plugins/';
    $plugin_dir = $plugins_dir . $name;
    if (file_exists($plugin_dir)) {
        $plugin_yaml = get_plugin_yaml("{$plugin_dir}/{$name}.yaml", false);
        # If no yaml, or yaml file but no description present, attempt to read an 'about.txt' file
        if ($plugin_yaml['desc'] == '') {
            $about = $plugins_dir . $name . '/about.txt';
            if (file_exists($about)) {
                $plugin_yaml['desc'] = substr(file_get_contents($about), 0, 95) . '...';
            }
        }
        # escape the plugin information
        $plugin_yaml_esc = array();
        foreach (array_keys($plugin_yaml) as $thekey) {
            $plugin_yaml_esc[$thekey] = escape_check($plugin_yaml[$thekey]);
        }
        # Add/Update plugin information.
        # Check if the plugin is already in the table.
        $c = sql_value("SELECT name as value FROM plugins WHERE name='{$name}'", '');
        if ($c == '') {
            sql_query("INSERT INTO plugins(name) VALUE ('{$name}')");
        }
        sql_query("UPDATE plugins SET config_url='{$plugin_yaml_esc['config_url']}', " . "descrip='{$plugin_yaml_esc['desc']}', author='{$plugin_yaml_esc['author']}', " . "inst_version='{$plugin_yaml_esc['version']}', " . "priority='{$plugin_yaml_esc['default_priority']}', " . "update_url='{$plugin_yaml_esc['update_url']}', info_url='{$plugin_yaml_esc['info_url']}' " . "WHERE name='{$plugin_yaml_esc['name']}'");
        return true;
    } else {
        return false;
    }
}
Example #2
0
$querytime = 0;
$querylog = array();
# -----------LANGUAGES AND PLUGINS-------------------------------
# Setup plugin configurations
if ($use_plugins_manager) {
    include "plugin_functions.php";
    $legacy_plugins = $plugins;
    # Make a copy of plugins activated via config.php
    #Check that manually (via config.php) activated plugins are included in the plugins table.
    foreach ($plugins as $plugin_name) {
        if ($plugin_name != '') {
            if (sql_value("SELECT inst_version AS value FROM plugins WHERE name='{$plugin_name}'", '') == '') {
                #Installed plugin isn't marked as installed in the DB.  Update it now.
                #Check if there's a plugin.yaml file to get version and author info.
                $plugin_yaml_path = dirname(__FILE__) . "/../plugins/{$plugin_name}/{$plugin_name}.yaml";
                $p_y = get_plugin_yaml($plugin_yaml_path, false);
                #Write what information we have to the plugin DB.
                sql_query("REPLACE plugins(inst_version, author, descrip, name, info_url, update_url, config_url) " . "VALUES ('{$p_y['version']}','{$p_y['author']}','{$p_y['desc']}','{$plugin_name}'," . "'{$p_y['info_url']}','{$p_y['update_url']}','{$p_y['config_url']}')");
            }
        }
    }
    # Need verbatum queries for this query
    $mysql_vq = $mysql_verbatim_queries;
    $mysql_verbatim_queries = true;
    $active_plugins = sql_query("SELECT name,enabled_groups,config,config_json FROM plugins WHERE inst_version>=0 order by priority DESC");
    $mysql_verbatim_queries = $mysql_vq;
    foreach ($active_plugins as $plugin) {
        # Check group access, only enable for global access at this point
        if ($plugin['enabled_groups'] == '') {
            # Add to the plugins array if not already present which is what we are working with
            # later on.
<?php

include "../../include/db.php";
include "../../include/general.php";
include "../../include/authenticate.php";

$userpreferences_plugins= array();
$plugin_names=array();
$plugins_dir = dirname(__FILE__)."/../../plugins/";
foreach($active_plugins as $plugin)
	{
	$plugin = $plugin["name"];
	array_push($plugin_names,trim(mb_strtolower($plugin)));
	$plugin_yaml = get_plugin_yaml($plugins_dir.$plugin.'/'.$plugin.'.yaml', false);
	if(isset($plugin_yaml["userpreferencegroup"]))
		{
		$upg = trim(mb_strtolower($plugin_yaml["userpreferencegroup"]));
		$userpreferences_plugins[$upg][$plugin]=$plugin_yaml;
		}
	}

if(getvalescaped("quicksave",FALSE))
	{
	$ctheme = getvalescaped("colour_theme","");
	if($ctheme==""){exit("missing");}
	$ctheme = preg_replace("/^col-/","",trim(mb_strtolower($ctheme)));
	if($ctheme =="default")
		{
		if(empty($userpreferences))
			{
			// create a record