Example #1
0
/**
 * Add is new security rights for the Group "XMLSitemap Admin"
 *
 */
function xmlsitemap_update_ConfigSecurity_1_0_0()
{
    global $_TABLES;
    // Add in security rights for XMLSitemap Admin
    $group_id = DB_getItem($_TABLES['groups'], 'grp_id', "grp_name = 'XMLSitemap Admin'");
    /*
     * For some time, from Geeklog 1.6.0 through to 1.7.0, we already had
     * an XMLSitemap Admin group in the database. It was dropped in 1.7.1
     * but not removed from the database. This is now coming back to haunt
     * us ... We also need to remove the unused xmlsitemap.edit permission
     * while we're at it.
     */
    if (empty($group_id)) {
        // cover: null, false, 0, etc. - doesn't exist yet
        // Add new Core Admin Group for Configuration
        DB_query("INSERT INTO {$_TABLES['groups']} (grp_name, grp_descr, grp_gl_core) VALUES ('XMLSitemap Admin', 'Has full access to XMLSitemap features', 0);");
        $group_id = DB_insertId();
        // Assign XMLSitemap Admin group to Root group
        DB_query("INSERT INTO {$_TABLES['group_assignments']} (ug_main_grp_id, ug_uid, ug_grp_id) VALUES ({$group_id}, NULL, 1)");
    } else {
        // if the XMLSitemap Admin group already exists, then there will
        // probably also be a xmlsitemap.edit permission - remove it
        SEC_removeFeatureFromDB('xmlsitemap.edit');
    }
    // now that we cleaned this up, add the new stuff
    if ($group_id > 0) {
        $ft_names[] = 'config.xmlsitemap.tab_main';
        $ft_names[] = 'config.xmlsitemap.tab_pri';
        $ft_names[] = 'config.xmlsitemap.tab_freq';
        foreach ($ft_names as $name) {
            $ft_id = DB_getItem($_TABLES['features'], 'ft_id', "ft_name = '{$name}'");
            if ($ft_id > 0) {
                $sql = "INSERT INTO {$_TABLES['access']} (acc_ft_id, acc_grp_id) VALUES ({$ft_id}, {$group_id})";
                DB_query($sql);
            }
        }
    }
}
Example #2
0
/**
* Tells a plugin to uninstall itself.
*
* @param    string      $type   Plugin to uninstall
* @return   boolean             Returns true on success otherwise false
* @link     http://wiki.geeklog.net/index.php/Plugin_Auto-Uninstall
*
*/
function PLG_uninstall($type)
{
    global $_PLUGINS, $_TABLES;
    if (empty($type)) {
        return false;
    }
    if (function_exists('plugin_autouninstall_' . $type)) {
        COM_errorLog("Auto-uninstalling plugin {$type}:", 1);
        $function = 'plugin_autouninstall_' . $type;
        $remvars = $function();
        if (empty($remvars) || $remvars == false) {
            return false;
        }
        // removing tables
        if (isset($remvars['tables'])) {
            $num_tables = count($remvars['tables']);
        } else {
            $num_tables = 0;
        }
        for ($i = 0; $i < $num_tables; $i++) {
            if (isset($_TABLES[$remvars['tables'][$i]])) {
                COM_errorLog("Dropping table {$_TABLES[$remvars['tables'][$i]]}", 1);
                DB_query("DROP TABLE {$_TABLES[$remvars['tables'][$i]]}", 1);
                COM_errorLog('...success', 1);
            }
        }
        // removing variables
        if (isset($remvars['vars'])) {
            $num_vars = count($remvars['vars']);
        } else {
            $num_vars = 0;
        }
        for ($i = 0; $i < $num_vars; $i++) {
            COM_errorLog("Removing variable {$remvars['vars'][$i]}", 1);
            DB_delete($_TABLES['vars'], 'name', $remvars['vars'][$i]);
            COM_errorLog('...success', 1);
        }
        // removing groups
        if (isset($remvars['groups'])) {
            $num_groups = count($remvars['groups']);
        } else {
            $num_groups = 0;
        }
        for ($i = 0; $i < $num_groups; $i++) {
            $grp_id = DB_getItem($_TABLES['groups'], 'grp_id', "grp_name = '{$remvars['groups'][$i]}'");
            if (!empty($grp_id)) {
                COM_errorLog("Attempting to remove the {$remvars['groups'][$i]} group", 1);
                DB_delete($_TABLES['groups'], 'grp_id', $grp_id);
                COM_errorLog('...success', 1);
                COM_errorLog("Attempting to remove the {$remvars['groups'][$i]} group from all groups.", 1);
                DB_delete($_TABLES['group_assignments'], 'ug_main_grp_id', $grp_id);
                COM_errorLog('...success', 1);
            }
        }
        // removing features
        if (isset($remvars['features'])) {
            $num_features = count($remvars['features']);
        } else {
            $num_features = 0;
        }
        for ($i = 0; $i < $num_features; $i++) {
            SEC_removeFeatureFromDB($remvars['features'][$i]);
        }
        // uninstall feeds
        $sql = "SELECT filename FROM {$_TABLES['syndication']} WHERE type = '{$type}';";
        $result = DB_query($sql);
        $nrows = DB_numRows($result);
        if ($nrows > 0) {
            COM_errorLog('removing feed files', 1);
            COM_errorLog($nrows . ' files stored in table.', 1);
            for ($i = 0; $i < $nrows; $i++) {
                $fcount = $i + 1;
                $A = DB_fetchArray($result);
                $fullpath = SYND_getFeedPath($A[0]);
                if (file_exists($fullpath)) {
                    unlink($fullpath);
                    COM_errorLog("removed file {$fcount} of {$nrows}: {$fullpath}", 1);
                } else {
                    COM_errorLog("cannot remove file {$fcount} of {$nrows}, it does not exist! ({$fullpath})", 1);
                }
            }
            COM_errorLog('...success', 1);
            // Remove Links Feeds from syndiaction table
            COM_errorLog('removing links feeds from table', 1);
            DB_delete($_TABLES['syndication'], 'type', $type);
            COM_errorLog('...success', 1);
        }
        // remove comments for this plugin
        COM_errorLog("Attempting to remove comments for {$type}", 1);
        DB_delete($_TABLES['comments'], 'type', $type);
        COM_errorLog('...success', 1);
        // uninstall php-blocks
        if (isset($remvars['php_blocks'])) {
            $num_blocks = count($remvars['php_blocks']);
        } else {
            $num_blocks = 0;
        }
        for ($i = 0; $i < $num_blocks; $i++) {
            DB_delete($_TABLES['blocks'], array('type', 'phpblockfn'), array('phpblock', $remvars['php_blocks'][$i]));
        }
        // remove config table data for this plugin
        COM_errorLog("Attempting to remove config table records for group_name: {$type}", 1);
        DB_delete($_TABLES['conf_values'], 'group_name', $type);
        COM_errorLog('...success', 1);
        // remove topic assignment table data for this plugin
        COM_errorLog("Attempting to remove topic assignments table records for {$type}", 1);
        DB_delete($_TABLES['topic_assignments'], 'type', $type);
        COM_errorLog('...success', 1);
        // uninstall the plugin
        COM_errorLog("Attempting to unregister the {$type} plugin from Geeklog", 1);
        DB_delete($_TABLES['plugins'], 'pi_name', $type);
        COM_errorLog('...success', 1);
        COM_errorLog("Finished uninstalling the {$type} plugin.", 1);
        return true;
    } else {
        $retval = PLG_callFunctionForOnePlugin('plugin_uninstall_' . $type);
        if ($retval === true) {
            $plg = array_search($type, $_PLUGINS);
            if ($plg !== false) {
                unset($_PLUGINS[$plg]);
            }
            return true;
        }
    }
    return false;
}