/**
  * {@inheritdoc}
  */
 protected function handle()
 {
     $plugins = elgg_get_plugins('inactive');
     if (empty($plugins)) {
         system_message('All plugins are active');
         return;
     }
     $ids = array_map(function (ElggPlugin $plugin) {
         return $plugin->getID();
     }, $plugins);
     $ids = array_values($ids);
     if ($this->option('all')) {
         $activate_ids = $ids;
     } else {
         $helper = $this->getHelper('question');
         $question = new ChoiceQuestion('Please select plugins you would like to activate (comma-separated list of indexes)', $ids);
         $question->setMultiselect(true);
         $activate_ids = $helper->ask($this->input, $this->output, $question);
     }
     if (empty($activate_ids)) {
         throw new \RuntimeException('You must select at least one plugin');
     }
     $plugins = [];
     foreach ($activate_ids as $plugin_id) {
         $plugins[] = elgg_get_plugin_from_id($plugin_id);
     }
     do {
         $additional_plugins_activated = false;
         foreach ($plugins as $key => $plugin) {
             if ($plugin->isActive()) {
                 unset($plugins[$key]);
                 continue;
             }
             if (!$plugin->activate()) {
                 // plugin could not be activated in this loop, maybe in the next loop
                 continue;
             }
             $ids = array('cannot_start' . $plugin->getID(), 'invalid_and_deactivated_' . $plugin->getID());
             foreach ($ids as $id) {
                 elgg_delete_admin_notice($id);
             }
             // mark that something has changed in this loop
             $additional_plugins_activated = true;
             unset($plugins[$key]);
             system_message("Plugin {$plugin->getFriendlyName()} has been activated");
         }
         if (!$additional_plugins_activated) {
             // no updates in this pass, break the loop
             break;
         }
     } while (count($plugins) > 0);
     if (count($plugins) > 0) {
         foreach ($plugins as $plugin) {
             $msg = $plugin->getError();
             $string = $msg ? 'admin:plugins:activate:no_with_msg' : 'admin:plugins:activate:no';
             register_error(elgg_echo($string, array($plugin->getFriendlyName())));
         }
     }
     elgg_flush_caches();
 }
Example #2
0
function site_get_list_plugin()
{
    $plugins = elgg_get_plugins($status = 'active', $site_guid = null);
    $return = array('messages' => false, 'thewire' => false, 'blog' => false, 'tidypics' => false, 'file' => false, 'bookmarks' => false, 'groups' => false);
    foreach ($plugins as $plugin) {
        $a = $plugin->title;
        if (array_key_exists($plugin->title, $return)) {
            $return[$plugin->title] = true;
        }
    }
    return $return;
}
Example #3
0
/**
 * Exports plugins and their configuration
 */
function transfer_plugins_export()
{
    // metadata
    $info = array('elgg_version' => get_version(true), 'elgg_release' => get_version(false), 'transfer_plugins_format' => TRANSFER_PLUGINS_FORMAT);
    $info['plugins'] = array();
    $plugins = elgg_get_plugins('all');
    foreach ($plugins as $plugin) {
        if (is_object($plugin) && is_object($plugin->getManifest())) {
            $plugin_info = array('id' => $plugin->getID(), 'version' => $plugin->getManifest()->getVersion(), 'active' => (bool) $plugin->isActive(), 'settings' => $plugin->getAllSettings(), 'priority' => $plugin->getPriority());
        }
        $plugin_order[$plugin->getPriority() * 10] = $plugin->getID();
        $info['plugins'][] = $plugin_info;
    }
    $info['17_pluginorder'] = serialize($plugin_order);
    return serialize($info);
}
 public function testThemePluginsAreLast()
 {
     $plugins = elgg_get_plugins('all');
     $plugins = array_reverse($plugins);
     /* @var ElggPlugin[] $plugins */
     $found_non_theme = false;
     foreach ($plugins as $i => $plugin) {
         $is_theme = in_array('theme', $plugin->getManifest()->getCategories());
         if ($found_non_theme) {
             $this->assertFalse($is_theme, 'All themes come last');
         } else {
             if ($i === 0) {
                 $this->assertTrue($is_theme, 'Last plugin is a theme');
             }
             if (!$is_theme) {
                 $found_non_theme = true;
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function handle()
 {
     $plugins = elgg_get_plugins('active');
     if (empty($plugins)) {
         system_message('All plugins are inactive');
         return;
     }
     $ids = array_map(function (ElggPlugin $plugin) {
         return $plugin->getID();
     }, $plugins);
     $ids = array_values($ids);
     if ($this->option('all')) {
         $deactivate_ids = $ids;
     } else {
         $helper = $this->getHelper('question');
         $question = new ChoiceQuestion('Please select plugins you would like to deactivate (comma-separated list of indexes)', $ids);
         $question->setMultiselect(true);
         $deactivate_ids = $helper->ask($this->input, $this->output, $question);
     }
     if (empty($deactivate_ids)) {
         throw new RuntimeException('You must select at least one plugin');
     }
     $plugins = [];
     foreach ($deactivate_ids as $plugin_id) {
         $plugins[] = elgg_get_plugin_from_id($plugin_id);
     }
     foreach ($plugins as $plugin) {
         if (!$plugin->isActive()) {
             continue;
         }
         if (!$plugin->deactivate()) {
             $msg = $plugin->getError();
             $string = $msg ? 'admin:plugins:deactivate:no_with_msg' : 'admin:plugins:deactivate:no';
             register_error(elgg_echo($string, array($plugin->getFriendlyName(), $plugin->getError())));
         } else {
             system_message("Plugin {$plugin->getFriendlyName()} has been deactivated");
         }
     }
     elgg_flush_caches();
 }
Example #6
0
function elgg_update_services_get_updates()
{
    $installed_plugins = elgg_get_plugins('all');
    $plugin_hash_list = array();
    foreach ($installed_plugins as $id => $plugin) {
        $manifest = $plugin->getManifest();
        $bundled = in_array('bundled', $manifest->getCategories()) ? true : false;
        if (!$bundled) {
            $id = $manifest->getID();
            if (empty($id)) {
                $id = $plugin->getID();
            }
            $version = $manifest->getVersion();
            $author = $manifest->getAuthor();
            $plugin_hash_list[] = md5($id . $version . $author);
        }
    }
    $url = "http://community.elgg.org/services/api/rest/json/?method=plugins.update.check&version=" . elgg_get_version(true);
    foreach ($plugin_hash_list as $plugin_hash) {
        $url .= "&plugins[]=" . $plugin_hash;
    }
    $update_check = elgg_update_services_file_get_conditional_contents($url);
    return json_decode($update_check, true);
}
Example #7
0
function subsite_manager_boot_system_plugins_event_handler($event, $type, $object)
{
    global $CONFIG;
    global $SUBSITE_MANAGER_PLUGINS_BOOT;
    // needs to be set for links in html head
    $viewtype = get_input('view', 'default');
    $site_guid = elgg_get_site_entity()->getGUID();
    $lastcached = datalist_get("sc_lastcached_" . $viewtype . "_" . $site_guid);
    $CONFIG->lastcache = $lastcached;
    // skip non-subsites
    if (!subsite_manager_on_subsite()) {
        return true;
    }
    $site = elgg_get_site_entity();
    $to_activate = $site->getPrivateSetting('subsite_manager_plugins_activate');
    if ($to_activate) {
        $SUBSITE_MANAGER_PLUGINS_BOOT = true;
        $site->removePrivateSetting('subsite_manager_plugins_activate');
        $to_activate = unserialize($to_activate);
        set_time_limit(0);
        elgg_generate_plugin_entities();
        $old_ia = elgg_set_ignore_access(true);
        $plugins = elgg_get_plugins('any');
        foreach ($plugins as $plugin) {
            if (in_array($plugin->getID(), $to_activate)) {
                try {
                    $plugin->activate();
                } catch (Exception $e) {
                }
            }
        }
        elgg_set_ignore_access($old_ia);
        $SUBSITE_MANAGER_PLUGINS_BOOT = false;
        elgg_register_event_handler("ready", "system", "subsite_manager_ready_system_handler", 100);
    }
}
Example #8
0
function translation_editor_merge_translations($language = "", $update = false)
{
    global $CONFIG;
    $result = false;
    if (empty($language)) {
        $language = get_current_language();
    }
    if (!empty($language)) {
        $translations = array();
        if ($core = translation_editor_read_translation($language, "core")) {
            $translations = $core;
        }
        if ($custom_keys = translation_editor_read_translation($language, "custom_keys")) {
            $translations += $custom_keys;
        }
        if ($plugins = elgg_get_plugins()) {
            foreach ($plugins as $plugin) {
                if ($plugin_translation = translation_editor_read_translation($language, $plugin->title)) {
                    $translations += $plugin_translation;
                }
            }
        }
        if (!empty($translations)) {
            if (translation_editor_write_translation($language, "translation_editor_merged_" . $CONFIG->site_guid, $translations)) {
                $result = true;
            }
        } else {
            if (translation_editor_delete_translation($language, "translation_editor_merged_" . $CONFIG->site_guid)) {
                $result = true;
            }
        }
    }
    if ($result) {
        elgg_trigger_event("language:merge", "translation_editor", $language);
    }
    // reset language cache on all sites
    if ($update) {
        $ts = time();
        datalist_set("te_last_update_" . $language, $ts);
        set_private_setting($CONFIG->site_guid, "te_last_update_" . $language, $ts);
    }
    return $result;
}
Example #9
0
File: Util.php Project: n8b/VMN
 /**
  * Activate the plugin as well as all plugins required by it
  *
  * @param string $id Plugin ID
  * @return boolean
  */
 public static function activatePlugin($id)
 {
     if (!$id) {
         return false;
     }
     $plugin = elgg_get_plugin_from_id($id);
     if (!$plugin) {
         $plugins = elgg_get_plugins('inactive');
         foreach ($plugins as $p) {
             /* @var $p ElggPlugin */
             $manifest = $p->getManifest();
             if (!$manifest) {
                 continue;
             }
             $provides = $manifest->getProvides();
             if (!empty($provides)) {
                 foreach ($provides as $provide) {
                     if ($provide['type'] == 'plugin' && $provide['name'] == $id) {
                         $plugin = $p;
                         break;
                     }
                 }
             }
         }
         if (!$plugin) {
             return false;
         }
     }
     if ($plugin->isActive()) {
         return true;
     }
     $result = true;
     $manifest = $plugin->getManifest();
     if (!$manifest) {
         return false;
     }
     $requires = $manifest->getRequires();
     if (!empty($requires)) {
         foreach ($requires as $require) {
             if ($require['type'] == 'plugin') {
                 $result = self::activatePlugin($require['name']);
                 if (!$result) {
                     break;
                 }
             }
         }
     }
     if (!$result) {
         return false;
     }
     return $plugin->activate();
 }
Example #10
0
/**
 * Returns an array of all provides from all active plugins.
 *
 * Array in the form array(
 * 	'provide_type' => array(
 * 		'provided_name' => array(
 * 			'version' => '1.8',
 * 			'provided_by' => 'provider_plugin_id'
 *  	)
 *  )
 * )
 *
 * @param string $type The type of provides to return
 * @param string $name A specific provided name to return. Requires $provide_type.
 *
 * @return array
 * @since 1.8.0
 * @access private
 */
function elgg_get_plugins_provides($type = null, $name = null)
{
    global $SUBSITE_MANAGER_PLUGINS_BOOT;
    static $provides = null;
    $active_plugins = elgg_get_plugins('active');
    if (!isset($provides) || !empty($SUBSITE_MANAGER_PLUGINS_BOOT)) {
        $provides = array();
        foreach ($active_plugins as $plugin) {
            $plugin_provides = array();
            $manifest = $plugin->getManifest();
            if ($manifest instanceof ElggPluginManifest) {
                $plugin_provides = $plugin->getManifest()->getProvides();
            }
            if ($plugin_provides) {
                foreach ($plugin_provides as $provided) {
                    $provides[$provided['type']][$provided['name']] = array('version' => $provided['version'], 'provided_by' => $plugin->getID());
                }
            }
        }
    }
    if ($type && $name) {
        if (isset($provides[$type][$name])) {
            return $provides[$type][$name];
        } else {
            return false;
        }
    } elseif ($type) {
        if (isset($provides[$type])) {
            return $provides[$type];
        } else {
            return false;
        }
    }
    return $provides;
}
Example #11
0
 /**
  * Returns an array of all provides from all active plugins.
  *
  * Array in the form array(
  * 	'provide_type' => array(
  * 		'provided_name' => array(
  * 			'version' => '1.8',
  * 			'provided_by' => 'provider_plugin_id'
  *  	)
  *  )
  * )
  *
  * @param string $type The type of provides to return
  * @param string $name A specific provided name to return. Requires $provide_type.
  *
  * @return array
  * @access private
  */
 function getProvides($type = null, $name = null)
 {
     global $ELGG_PLUGINS_PROVIDES_CACHE;
     if (!isset($ELGG_PLUGINS_PROVIDES_CACHE)) {
         $active_plugins = elgg_get_plugins('active');
         $provides = array();
         foreach ($active_plugins as $plugin) {
             $plugin_provides = array();
             $manifest = $plugin->getManifest();
             if ($manifest instanceof \ElggPluginManifest) {
                 $plugin_provides = $plugin->getManifest()->getProvides();
             }
             if ($plugin_provides) {
                 foreach ($plugin_provides as $provided) {
                     $provides[$provided['type']][$provided['name']] = array('version' => $provided['version'], 'provided_by' => $plugin->getID());
                 }
             }
         }
         $ELGG_PLUGINS_PROVIDES_CACHE = $provides;
     }
     if ($type && $name) {
         if (isset($ELGG_PLUGINS_PROVIDES_CACHE[$type][$name])) {
             return $ELGG_PLUGINS_PROVIDES_CACHE[$type][$name];
         } else {
             return false;
         }
     } elseif ($type) {
         if (isset($ELGG_PLUGINS_PROVIDES_CACHE[$type])) {
             return $ELGG_PLUGINS_PROVIDES_CACHE[$type];
         } else {
             return false;
         }
     }
     return $ELGG_PLUGINS_PROVIDES_CACHE;
 }
Example #12
0
/**
 * Load both core and plugin translations for a specific language
 *
 * This can be used to load translations on-demand in case we need
 * to translate something to a language not loaded by default for
 * the current user.
 *
 * @param $language Language code
 * @return bool
 *
 * @since 1.9.4
 * @throws PluginException
 * @access private
 */
function _elgg_load_translations_for_language($language)
{
    global $CONFIG;
    // Try to load translations from system cache
    if (!empty($CONFIG->system_cache_enabled)) {
        $data = elgg_load_system_cache("{$language}.lang");
        if ($data) {
            $added = add_translation($language, unserialize($data));
            if ($added) {
                // Translations were successfully loaded from system cache
                return true;
            }
        }
    }
    // Read translations from the core languages directory
    _elgg_register_translations_for_language(dirname(dirname(dirname(__FILE__))) . "/languages/", $language);
    // Get active plugins
    $plugins = elgg_get_plugins('active');
    if (!$plugins) {
        // Active plugins were not found, so no need to register plugin translations
        return true;
    }
    foreach ($plugins as $plugin) {
        $languages_path = "{$plugin->getPath()}languages/";
        if (!is_dir($languages_path)) {
            // This plugin doesn't have anything to translate
            continue;
        }
        $language_file = "{$languages_path}{$language}.php";
        if (!file_exists($language_file)) {
            // This plugin doesn't have translations for the requested language
            $name = $plugin->getFriendlyName();
            elgg_log("Plugin {$name} is missing translations for {$language} language", 'NOTICE');
            continue;
        }
        // Register translations from the plugin languages directory
        if (!_elgg_register_translations_for_language($languages_path, $language)) {
            $msg = elgg_echo('ElggPlugin:Exception:CannotRegisterLanguages', array($plugin->getID(), $plugin->guid, $languages_path));
            throw new PluginException($msg);
        }
    }
    return true;
}
Example #13
0
<?php

/**
 * Disable all specified installed plugins.
 *
 * Specified plugins in the mod/ directory are disabled and the views cache and simplecache
 * are reset.
 *
 * @package Elgg.Core
 * @subpackage Administration.Plugins
 */
$guids = get_input('guids');
if (empty($guids)) {
    $plugins = elgg_get_plugins('active');
} else {
    $plugins = elgg_get_entities(['type' => 'object', 'subtype' => 'plugin', 'guids' => explode(',', $guids), 'limit' => false]);
}
if (empty($plugins)) {
    forward(REFERER);
}
foreach ($plugins as $plugin) {
    if (!$plugin->isActive()) {
        continue;
    }
    if (!$plugin->deactivate()) {
        $msg = $plugin->getError();
        $string = $msg ? 'admin:plugins:deactivate:no_with_msg' : 'admin:plugins:deactivate:no';
        register_error(elgg_echo($string, array($plugin->getFriendlyName(), $plugin->getError())));
    }
}
// don't regenerate the simplecache because the plugin won't be
Example #14
0
 /**
  * Enable a set of default plugins
  *
  * @return void
  */
 protected function enablePlugins()
 {
     elgg_generate_plugin_entities();
     $plugins = elgg_get_plugins('any');
     foreach ($plugins as $plugin) {
         if ($plugin->getManifest()) {
             if ($plugin->getManifest()->getActivateOnInstall()) {
                 $plugin->activate();
             }
         }
     }
 }
 /**
  * Returns if the Elgg system meets the plugin's dependency
  * requirements.  This includes both requires and conflicts.
  *
  * Full reports can be requested.  The results are returned
  * as an array of arrays in the form array(
  * 	'type' => requires|conflicts,
  * 	'dep' => array( dependency array ),
  * 	'status' => bool if depedency is met,
  * 	'comment' => optional comment to display to the user.
  * )
  *
  * @param bool $full_report Return a full report.
  * @return bool|array
  */
 public function checkDependencies($full_report = false)
 {
     // Note: $conflicts and $requires are not unused. They're called dynamically
     $requires = $this->getManifest()->getRequires();
     $conflicts = $this->getManifest()->getConflicts();
     $enabled_plugins = elgg_get_plugins('active');
     $this_id = $this->getID();
     $report = array();
     // first, check if any active plugin conflicts with us.
     foreach ($enabled_plugins as $plugin) {
         $temp_conflicts = array();
         $temp_manifest = $plugin->getManifest();
         if ($temp_manifest instanceof ElggPluginManifest) {
             $temp_conflicts = $plugin->getManifest()->getConflicts();
         }
         foreach ($temp_conflicts as $conflict) {
             if ($conflict['type'] == 'plugin' && $conflict['name'] == $this_id) {
                 $result = $this->checkDepPlugin($conflict, $enabled_plugins, false);
                 // rewrite the conflict to show the originating plugin
                 $conflict['name'] = $plugin->getManifest()->getName();
                 if (!$full_report && !$result['status']) {
                     $this->errorMsg = "Conflicts with plugin \"{$plugin->getManifest()->getName()}\".";
                     return $result['status'];
                 } else {
                     $report[] = array('type' => 'conflicted', 'dep' => $conflict, 'status' => $result['status'], 'value' => $this->getManifest()->getVersion());
                 }
             }
         }
     }
     $check_types = array('requires', 'conflicts');
     if ($full_report) {
         // Note: $suggests is not unused. It's called dynamically
         $suggests = $this->getManifest()->getSuggests();
         $check_types[] = 'suggests';
     }
     foreach ($check_types as $dep_type) {
         $inverse = $dep_type == 'conflicts' ? true : false;
         foreach (${$dep_type} as $dep) {
             switch ($dep['type']) {
                 case 'elgg_version':
                     $result = $this->checkDepElgg($dep, get_version(), $inverse);
                     break;
                 case 'elgg_release':
                     $result = $this->checkDepElgg($dep, get_version(true), $inverse);
                     break;
                 case 'plugin':
                     $result = $this->checkDepPlugin($dep, $enabled_plugins, $inverse);
                     break;
                 case 'priority':
                     $result = $this->checkDepPriority($dep, $enabled_plugins, $inverse);
                     break;
                 case 'php_extension':
                     $result = $this->checkDepPhpExtension($dep, $inverse);
                     break;
                 case 'php_ini':
                     $result = $this->checkDepPhpIni($dep, $inverse);
                     break;
             }
             // unless we're doing a full report, break as soon as we fail.
             if (!$full_report && !$result['status']) {
                 $this->errorMsg = "Missing dependencies.";
                 return $result['status'];
             } else {
                 // build report element and comment
                 $report[] = array('type' => $dep_type, 'dep' => $dep, 'status' => $result['status'], 'value' => $result['value']);
             }
         }
     }
     if ($full_report) {
         // add provides to full report
         $provides = $this->getManifest()->getProvides();
         foreach ($provides as $provide) {
             $report[] = array('type' => 'provides', 'dep' => $provide, 'status' => true, 'value' => '');
         }
         return $report;
     }
     return true;
 }
Example #16
0
 /**
  * Reorder plugins to an order specified by the array.
  * Plugins not included in this array will be appended to the end.
  *
  * @note This doesn't use the \ElggPlugin->setPriority() method because
  *       all plugins are being changed and we don't want it to automatically
  *       reorder plugins.
  *
  * @param array $order An array of plugin ids in the order to set them
  * @return bool
  * @access private
  */
 function setPriorities(array $order)
 {
     $name = $this->namespacePrivateSetting('internal', 'priority');
     $plugins = elgg_get_plugins('any');
     if (!$plugins) {
         return false;
     }
     $return = true;
     // reindex to get standard counting. no need to increment by 10.
     // though we do start with 1
     $order = array_values($order);
     $missing_plugins = array();
     /* @var \ElggPlugin[] $missing_plugins */
     foreach ($plugins as $plugin) {
         $plugin_id = $plugin->getID();
         if (!in_array($plugin_id, $order)) {
             $missing_plugins[] = $plugin;
             continue;
         }
         $priority = array_search($plugin_id, $order) + 1;
         if (!$plugin->setPrivateSetting($name, $priority)) {
             $return = false;
             break;
         }
     }
     // set the missing plugins' priorities
     if ($return && $missing_plugins) {
         if (!isset($priority)) {
             $priority = 0;
         }
         foreach ($missing_plugins as $plugin) {
             $priority++;
             if (!$plugin->setPrivateSetting($name, $priority)) {
                 $return = false;
                 break;
             }
         }
     }
     return $return;
 }
Example #17
0
File: import.php Project: n8b/VMN
<?php

use Ambercal\SettingsTransfer\Util;
if (!isset($_FILES['json']['name']) || $_FILES['json']['error'] != UPLOAD_ERR_OK) {
    $error = elgg_get_friendly_upload_error($_FILES['json']['error']);
} else {
    $contents = @file_get_contents($_FILES['json']['tmp_name']);
    $json = @json_decode($contents, true);
}
if (empty($json)) {
    if (!$error) {
        $error = elgg_echo('admin:plugin_settings_transfer:upload:invalid_json');
    }
    register_error($error);
    forward(REFERER);
}
$plugins = elgg_get_plugins('all');
$options = get_input('options', array());
$import_options = array();
foreach ($options as $option) {
    $import_options[$option] = true;
}
$errors = Util::import($json, $import_options);
if ($errors) {
    system_message(elgg_echo('admin:plugin_settings_transfer:import:error', array($errors)));
} else {
    system_message(elgg_echo('admin:plugin_settings_transfer:import:success'));
}
elgg_invalidate_simplecache();
elgg_reset_system_cache();
forward(REFERER);
Example #18
0
/**
 * Create the plugin settings page menu.
 *
 * This is done in a separate function called from the admin
 * page handler because of performance concerns.
 *
 * @return void
 * @access private
 * @since 1.8.0
 */
function elgg_admin_add_plugin_settings_menu()
{
    $active_plugins = elgg_get_plugins('active');
    if (!$active_plugins) {
        // nothing added because no items
        return;
    }
    foreach ($active_plugins as $plugin) {
        $plugin_id = $plugin->getID();
        $settings_view_old = 'settings/' . $plugin_id . '/edit';
        $settings_view_new = 'plugins/' . $plugin_id . '/settings';
        if (elgg_view_exists($settings_view_new) || elgg_view_exists($settings_view_old)) {
            elgg_register_menu_item('page', array('name' => $plugin_id, 'href' => "admin/plugin_settings/{$plugin_id}", 'text' => $plugin->getManifest()->getName(), 'parent_name' => 'settings', 'context' => 'admin', 'section' => 'configure'));
        }
    }
}
Example #19
0
<?php

/**
 * Elgg administration advanced plugin screen
 *
 * Shows a list of all plugins sorted by load order.
 *
 * @package Elgg.Core
 * @subpackage Admin.Plugins
 */
elgg_generate_plugin_entities();
$installed_plugins = elgg_get_plugins('any', true);
$show_category = get_input('category', null);
// Get a list of the all categories
// and trim down the plugin list if we're not viewing all categories.
// @todo this could be cached somewhere after have the manifest loaded
$categories = array();
foreach ($installed_plugins as $id => $plugin) {
    if (!$plugin->isValid()) {
        continue;
    }
    $plugin_categories = $plugin->manifest->getCategories();
    // handle plugins that don't declare categories
    // unset them here because this is the list we foreach
    if ($show_category && !in_array($show_category, $plugin_categories)) {
        unset($installed_plugins[$id]);
    }
    if (isset($plugin_categories)) {
        foreach ($plugin_categories as $category) {
            if (!array_key_exists($category, $categories)) {
                $categories[$category] = elgg_echo("admin:plugins:category:{$category}");
Example #20
0
<?php

// can only be viewed on main site
if (subsite_manager_on_subsite()) {
    forward("admin");
}
echo elgg_view_module("info", "", elgg_echo("subsite_manager:subsite:plugins:description", array("<a class='elgg-button elgg-button-action' href='javascript:void(0);' onclick='\$(\"#subsite-manager-plugins-list\").show();'>", "</a>")));
echo "<br />";
// regenerate plugin list
elgg_generate_plugin_entities();
if ($all_plugins = elgg_get_plugins("all")) {
    $plugins = array();
    foreach ($all_plugins as $plugin) {
        $plugins[$plugin->getID()] = $plugin;
    }
    unset($all_plugins);
    ksort($plugins);
} else {
    $plugins = false;
}
$form_vars = array("id" => "subsite-manager-plugins-list", "class" => "hidden");
$body_vars = array("plugins" => $plugins, "subsites_count" => subsite_manager_get_subsites(0, 0, true), "required_plugins" => subsite_manager_get_required_plugins());
echo elgg_view_form("subsites/plugins", $form_vars, $body_vars);
Example #21
0
 /**
  * Enable a set of default plugins
  *
  * @return void
  */
 protected function enablePlugins()
 {
     _elgg_generate_plugin_entities();
     $plugins = elgg_get_plugins('any');
     foreach ($plugins as $plugin) {
         if ($plugin->getManifest()) {
             if ($plugin->getManifest()->getActivateOnInstall()) {
                 $plugin->activate();
             }
             if (in_array('theme', $plugin->getManifest()->getCategories())) {
                 $plugin->setPriority('last');
             }
         }
     }
 }
 /**
  * Load translations of all plugins
  *
  * @return void
  */
 private function loadAllPluginTranslations()
 {
     $plugins = elgg_get_plugins('all');
     foreach ($plugins as $plugin) {
         $path = elgg_get_plugins_path() . $plugin->getID() . '/languages';
         if (is_dir($path)) {
             register_translations($path);
         }
     }
 }
Example #23
0
/**
 * Register menu items for the user settings page menu
 *
 * @param string $hook
 * @param string $type
 * @param array  $return
 * @param array  $params
 * @return array
 *
 * @access private
 *
 * @since 3.0
 */
function _elgg_user_settings_menu_register($hook, $type, $return, $params)
{
    $user = elgg_get_page_owner_entity();
    if (!$user) {
        return;
    }
    if (!elgg_in_context('settings')) {
        return;
    }
    $return[] = \ElggMenuItem::factory(['name' => '1_account', 'text' => elgg_echo('usersettings:user:opt:linktext'), 'href' => "settings/user/{$user->username}", 'section' => 'configure']);
    $return[] = \ElggMenuItem::factory(['name' => '1_plugins', 'text' => elgg_echo('usersettings:plugins:opt:linktext'), 'href' => '#', 'section' => 'configure']);
    $return[] = \ElggMenuItem::factory(['name' => '1_statistics', 'text' => elgg_echo('usersettings:statistics:opt:linktext'), 'href' => "settings/statistics/{$user->username}", 'section' => 'configure']);
    // register plugin user settings menu items
    $active_plugins = elgg_get_plugins();
    foreach ($active_plugins as $plugin) {
        $plugin_id = $plugin->getID();
        if (!elgg_view_exists("usersettings/{$plugin_id}/edit") && !elgg_view_exists("plugins/{$plugin_id}/usersettings")) {
            continue;
        }
        if (elgg_language_key_exists($plugin_id . ':usersettings:title')) {
            $title = elgg_echo($plugin_id . ':usersettings:title');
        } else {
            $title = $plugin->getFriendlyName();
        }
        $return[] = \ElggMenuItem::factory(['name' => $plugin_id, 'text' => $title, 'href' => "settings/plugins/{$user->username}/{$plugin_id}", 'parent_name' => '1_plugins', 'section' => 'configure']);
    }
    return $return;
}
Example #24
0
<?php

/**
 * Elgg user tools settings
 *
 * @package Elgg
 * @subpackage Core
 */
// Only logged in users
gatekeeper();
// Make sure we don't open a security hole ...
if (!elgg_get_page_owner_entity() || !elgg_get_page_owner_entity()->canEdit()) {
    register_error(elgg_echo('noaccess'));
    forward('/');
}
$title = elgg_echo("usersettings:plugins");
$content = elgg_view("core/settings/tools", array('installed_plugins' => elgg_get_plugins()));
$params = array('content' => $content, 'title' => $title);
$body = elgg_view_layout('one_sidebar', $params);
echo elgg_view_page($title, $body);
Example #25
0
<?php

/**
 * Elgg administration plugin screen
 *
 * Shows a list of plugins that can be sorted and filtered.
 *
 * @package Elgg.Core
 * @subpackage Admin.Plugins
 */
elgg_generate_plugin_entities();
$installed_plugins = elgg_get_plugins('any');
$show_category = get_input('category', 'all');
$sort = get_input('sort', 'priority');
// Get a list of the all categories
// and trim down the plugin list if we're not viewing all categories.
// @todo this could be cached somewhere after have the manifest loaded
$categories = array();
foreach ($installed_plugins as $id => $plugin) {
    if (!$plugin->isValid()) {
        if ($plugin->isActive()) {
            // force disable and warn
            register_error(elgg_echo('ElggPlugin:InvalidAndDeactivated', array($plugin->getId())));
            $plugin->deactivate();
        }
        continue;
    }
    $plugin_categories = $plugin->getManifest()->getCategories();
    // handle plugins that don't declare categories
    // unset them here because this is the list we foreach
    switch ($show_category) {
Example #26
0
<?php

/**
 * Boot all the plugins and trigger the [init, system] hook
 *
 * Depend on this module to guarantee all [init, system] handlers have been called
 */
$modules = [];
foreach (elgg_get_plugins() as $plugin) {
    $id = $plugin->getID();
    if (elgg_view_exists("boot/{$id}.js")) {
        $modules[] = "boot/{$id}";
    }
}
?>
//<script>
define(function (require) {
	var Plugin = require('elgg/Plugin');
	var elgg = require('elgg');

	var modules = [];
	var i;

	// We need literal require('boot/example'); statements. We can't use async require in here because we promise to
	// not return this module until all boot plugins are loaded.
<?php 
foreach ($modules as $name) {
    ?>
	modules.push({
		plugin: require(<?php 
    echo json_encode($name, JSON_UNESCAPED_SLASHES);
Example #27
0
/**
 * Set up the menu for user settings
 *
 * @return void
 * @access private
 */
function _elgg_user_settings_menu_setup()
{
    $user = elgg_get_page_owner_entity();
    if (!$user) {
        return;
    }
    if (!elgg_in_context("settings")) {
        return;
    }
    $params = array('name' => '1_account', 'text' => elgg_echo('usersettings:user:opt:linktext'), 'href' => "settings/user/{$user->username}", 'section' => 'configure');
    elgg_register_menu_item('page', $params);
    $params = array('name' => '1_plugins', 'text' => elgg_echo('usersettings:plugins:opt:linktext'), 'href' => '#', 'section' => 'configure');
    elgg_register_menu_item('page', $params);
    $params = array('name' => '1_statistics', 'text' => elgg_echo('usersettings:statistics:opt:linktext'), 'href' => "settings/statistics/{$user->username}", 'section' => 'configure');
    elgg_register_menu_item('page', $params);
    // register plugin user settings menu items
    $active_plugins = elgg_get_plugins();
    foreach ($active_plugins as $plugin) {
        $plugin_id = $plugin->getID();
        if (elgg_view_exists("usersettings/{$plugin_id}/edit") || elgg_view_exists("plugins/{$plugin_id}/usersettings")) {
            $params = array('name' => $plugin_id, 'text' => $plugin->getFriendlyName(), 'href' => "settings/plugins/{$user->username}/{$plugin_id}", 'parent_name' => '1_plugins', 'section' => 'configure');
            elgg_register_menu_item('page', $params);
        }
    }
    elgg_register_plugin_hook_handler("prepare", "menu:page", "_elgg_user_settings_menu_prepare");
}
<?php

$entity = elgg_extract('entity', $vars, elgg_get_page_owner_entity());
$filter_context = elgg_extract('filter_context', $vars, 'user');
$tabs = ['profile' => "profile/{$entity->username}/edit", 'avatar' => "avatar/edit/{$entity->username}", 'account' => "settings/account/{$entity->username}"];
if (elgg_is_active_plugin('notifications')) {
    $tabs['notifications'] = "settings/notifications/{$entity->username}";
}
$active_plugins = elgg_get_plugins();
foreach ($active_plugins as $plugin) {
    $plugin_id = $plugin->getID();
    if (elgg_view_exists("usersettings/{$plugin_id}/edit") || elgg_view_exists("plugins/{$plugin_id}/usersettings")) {
        $tabs['tools'] = "settings/tools/{$entity->username}";
        break;
    }
}
if (elgg_get_plugin_setting('show_statistics', 'user_settings')) {
    $tabs['statistics'] = "settings/statistics/{$entity->username}";
}
foreach ($tabs as $tab => $url) {
    elgg_register_menu_item('filter', array('name' => "user:settings:{$tab}", 'text' => elgg_echo("user:settings:{$tab}"), 'href' => elgg_normalize_url($url), 'selected' => $tab == $filter_context));
}
echo elgg_view_menu('filter', array('sort_by' => 'priority', 'entity' => $entity, 'filter_context' => $filter_context));
Example #29
0
/**
 * Return an array of installed plugins.
 *
 * @deprecated 1.8 use elgg_get_plugins()
 *
 * @param string $status any|enabled|disabled
 * @return array
 */
function get_installed_plugins($status = 'all')
{
    global $CONFIG;
    elgg_deprecated_notice('get_installed_plugins() was deprecated by elgg_get_plugins()', 1.8);
    $plugins = elgg_get_plugins($status);
    if (!$plugins) {
        return array();
    }
    $installed_plugins = array();
    foreach ($plugins as $plugin) {
        if (!$plugin->isValid()) {
            continue;
        }
        $include = true;
        if ($status == 'enabled' && !$plugin->isActive()) {
            $include = false;
        } elseif ($status == 'disabled' && $plugin->isActive()) {
            $include = true;
        }
        if ($include) {
            $installed_plugins[$plugin->getID()] = array('active' => $plugin->isActive(), 'manifest' => $plugin->getManifest()->getManifest());
        }
    }
    return $installed_plugins;
}
Example #30
0
/**
 * Checks on deactivate plugin event if disabling it won't create unmet dependencies and blocks disable in such case.
 *
 * @param string $event  deactivate
 * @param string $type   plugin
 * @param array  $params Parameters array containing entry with ELggPlugin instance under 'plugin_entity' key
 * @return bool  false to block plugin deactivation action
 *
 * @access private
 */
function _plugins_deactivate_dependency_check($event, $type, $params)
{
    $plugin_id = $params['plugin_entity']->getManifest()->getPluginID();
    $plugin_name = $params['plugin_entity']->getManifest()->getName();
    $active_plugins = elgg_get_plugins();
    $dependents = array();
    foreach ($active_plugins as $plugin) {
        $manifest = $plugin->getManifest();
        $requires = $manifest->getRequires();
        foreach ($requires as $required) {
            if ($required['type'] == 'plugin' && $required['name'] == $plugin_id) {
                // there are active dependents
                $dependents[$manifest->getPluginID()] = $plugin;
            }
        }
    }
    if ($dependents) {
        $list = '<ul>';
        // construct error message and prevent disabling
        foreach ($dependents as $dependent) {
            $list .= '<li>' . $dependent->getManifest()->getName() . '</li>';
        }
        $list .= '</ul>';
        register_error(elgg_echo('ElggPlugin:Dependencies:ActiveDependent', array($plugin_name, $list)));
        return false;
    }
}