Ejemplo n.º 1
0
 /**
  * Checks if cached menu html is available and returns the html if it is available
  *
  * @return boolean|string
  */
 public function getCachedData()
 {
     if (!elgg_get_config('system_cache_enabled')) {
         return false;
     }
     return elgg_load_system_cache($this->getCacheName()) ?: false;
 }
Ejemplo n.º 2
0
/**
 * Function to replace group profile fields
 *
 * @param string  $hook_name    name of the hook
 * @param string  $entity_type  type of the hook
 * @param unknown $return_value return value
 * @param unknown $parameters   hook parameters
 *
 * @return array
 */
function profile_manager_group_override($hook_name, $entity_type, $return_value, $parameters)
{
    // get from cache
    $site_guid = elgg_get_config('site_guid');
    $entities = elgg_load_system_cache('profile_manager_group_fields_' . $site_guid);
    if ($entities === null) {
        $options = ['type' => 'object', 'subtype' => CUSTOM_PROFILE_FIELDS_GROUP_SUBTYPE, 'limit' => false, 'owner_guid' => elgg_get_config('site_guid')];
        $entities = elgg_get_entities($options);
        elgg_save_system_cache('profile_manager_group_fields_' . $site_guid, serialize($entities));
    } else {
        $entities = unserialize($entities);
    }
    if (empty($entities)) {
        return;
    }
    $guids = [];
    $translations = [];
    foreach ($entities as $entity) {
        $guids[] = $entity->getGUID();
    }
    _elgg_services()->metadataCache->populateFromEntities($guids);
    $result = [];
    $ordered = [];
    // Order the group fields and filter some types out
    foreach ($entities as $group_field) {
        if ($group_field->admin_only != 'yes' || elgg_is_admin_logged_in()) {
            $ordered[$group_field->order] = $group_field;
        }
    }
    ksort($ordered);
    // build the correct list
    $result['name'] = 'text';
    foreach ($ordered as $group_field) {
        $result[$group_field->metadata_name] = $group_field->metadata_type;
        // should it be handled as tags? Q: is this still needed? A: Yes it is, it handles presentation of these fields in listing mode
        if (elgg_get_context() == 'search' && ($group_field->output_as_tags == 'yes' || $group_field->metadata_type == 'multiselect')) {
            $result[$group_field->metadata_name] = 'tags';
        }
        $translations['groups:' . $group_field->metadata_name] = $group_field->getTitle();
    }
    $languages = ['en'];
    $languages[] = get_current_language();
    $languages[] = elgg_get_config('language');
    array_unique($languages);
    foreach ($languages as $lang) {
        add_translation($lang, $translations);
    }
    return $result;
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
0
/**
 * Function to replace group profile fields
 *
 * @param string  $hook_name    name of the hook
 * @param string  $entity_type  type of the hook
 * @param unknown $return_value return value
 * @param unknown $parameters   hook parameters
 *
 * @return array
 */
function profile_manager_group_override($hook_name, $entity_type, $return_value, $parameters)
{
    $result = $return_value;
    // get from cache
    $site_guid = elgg_get_config("site_guid");
    $entities = elgg_load_system_cache("profile_manager_group_fields_" . $site_guid);
    if ($entities === null) {
        $options = array("type" => "object", "subtype" => CUSTOM_PROFILE_FIELDS_GROUP_SUBTYPE, "limit" => false, "owner_guid" => elgg_get_config("site_guid"));
        $entities = elgg_get_entities($options);
        elgg_save_system_cache("profile_manager_group_fields_" . $site_guid, serialize($entities));
    } else {
        $entities = unserialize($entities);
    }
    if ($entities) {
        $guids = array();
        $translations = array();
        foreach ($entities as $entity) {
            $guids[] = $entity->getGUID();
        }
        _elgg_services()->metadataCache->populateFromEntities($guids);
        $result = array();
        $ordered = array();
        // Order the group fields and filter some types out
        foreach ($entities as $group_field) {
            if ($group_field->admin_only != "yes" || elgg_is_admin_logged_in()) {
                $ordered[$group_field->order] = $group_field;
            }
        }
        ksort($ordered);
        // build the correct list
        $result["name"] = "text";
        foreach ($ordered as $group_field) {
            $result[$group_field->metadata_name] = $group_field->metadata_type;
            // should it be handled as tags? Q: is this still needed? A: Yes it is, it handles presentation of these fields in listing mode
            if (elgg_get_context() == "search" && ($group_field->output_as_tags == "yes" || $group_field->metadata_type == "multiselect")) {
                $result[$group_field->metadata_name] = "tags";
            }
            $translations["groups:" . $group_field->metadata_name] = $group_field->getTitle();
        }
        add_translation(get_current_language(), $translations);
    }
    return $result;
}
Ejemplo n.º 5
0
/**
 * Gets the value of a setting for a specific widget handler in a specific widget context
 *
 * @param string $widget_handler handler of the widget
 * @param string $setting        name of the setting
 * @param string $context        context of the widget (default current context)
 *
 * @return boolean
 */
function widget_manager_get_widget_setting($widget_handler, $setting, $context = null)
{
    $result = false;
    if (is_null($context)) {
        $context = elgg_get_context();
    }
    static $widget_settings;
    if (!isset($widget_settings)) {
        $widget_settings = elgg_load_system_cache("widget_manager_widget_settings");
        if ($widget_settings === null) {
            $widget_settings = array();
        } else {
            $widget_settings = unserialize($widget_settings);
        }
    }
    if (!isset($widget_settings[$context])) {
        $widget_settings[$context] = array();
    }
    if (!isset($widget_settings[$context][$widget_handler])) {
        $widget_settings[$context][$widget_handler] = array();
    }
    if (isset($widget_settings[$context][$widget_handler][$setting])) {
        return $widget_settings[$context][$widget_handler][$setting];
    }
    if (!empty($widget_handler) && !empty($setting)) {
        $plugin_setting = elgg_get_plugin_setting($context . "_" . $widget_handler . "_" . $setting, "widget_manager");
        if ($plugin_setting) {
            if ($plugin_setting == "yes") {
                $result = true;
            }
        } elseif ($setting == "can_add") {
            $result = true;
        }
        $widget_settings[$context][$widget_handler][$setting] = $result;
    }
    elgg_save_system_cache("widget_manager_widget_settings", serialize($widget_settings));
    return $result;
}
Ejemplo n.º 6
0
/**
 * @access private
 * @deprecated 1.9 Use elgg_load_system_cache()
 */
function elgg_filepath_cache_load($type)
{
    elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_load_system_cache()', 1.9);
    return elgg_load_system_cache($type);
}
Ejemplo n.º 7
0
 /**
  * Reload all translations from all registered paths.
  *
  * This is only called by functions which need to know all possible translations.
  *
  * @todo Better on demand loading based on language_paths array
  *
  * @return void
  */
 function reloadAllTranslations()
 {
     static $LANG_RELOAD_ALL_RUN;
     if ($LANG_RELOAD_ALL_RUN) {
         return;
     }
     if ($GLOBALS['_ELGG']->i18n_loaded_from_cache) {
         $cache = elgg_get_system_cache();
         $cache_dir = $cache->getVariable("cache_path");
         $filenames = elgg_get_file_list($cache_dir, array(), array(), array(".lang"));
         foreach ($filenames as $filename) {
             // Look for files matching for example 'en.lang', 'cmn.lang' or 'pt_br.lang'.
             // Note that this regex is just for the system cache. The original language
             // files are allowed to have uppercase letters (e.g. pt_BR.php).
             if (preg_match('/(([a-z]{2,3})(_[a-z]{2})?)\\.lang$/', $filename, $matches)) {
                 $language = $matches[1];
                 $data = elgg_load_system_cache("{$language}.lang");
                 if ($data) {
                     $this->addTranslation($language, unserialize($data));
                 }
             }
         }
     } else {
         foreach ($GLOBALS['_ELGG']->language_paths as $path => $dummy) {
             $this->registerTranslations($path, true);
         }
     }
     $LANG_RELOAD_ALL_RUN = true;
 }
Ejemplo n.º 8
0
/**
 * Reload all translations from all registered paths.
 *
 * This is only called by functions which need to know all possible translations.
 *
 * @todo Better on demand loading based on language_paths array
 *
 * @return void
 */
function reload_all_translations()
{
    global $CONFIG;
    static $LANG_RELOAD_ALL_RUN;
    if ($LANG_RELOAD_ALL_RUN) {
        return;
    }
    if ($CONFIG->i18n_loaded_from_cache) {
        $cache = elgg_get_system_cache();
        $cache_dir = $cache->getVariable("cache_path");
        $filenames = elgg_get_file_list($cache_dir, array(), array(), array(".lang"));
        foreach ($filenames as $filename) {
            if (preg_match('/([a-z]+)\\.[^.]+$/', $filename, $matches)) {
                $language = $matches[1];
                $data = elgg_load_system_cache("{$language}.lang");
                if ($data) {
                    add_translation($language, unserialize($data));
                }
            }
        }
    } else {
        foreach ($CONFIG->language_paths as $path => $dummy) {
            register_translations($path, true);
        }
    }
    $LANG_RELOAD_ALL_RUN = true;
}
Ejemplo n.º 9
0
/**
 * Loads the system cache during engine boot
 * 
 * @see elgg_reset_system_cache()
 * @access private
 */
function _elgg_load_cache()
{
    global $CONFIG;
    $CONFIG->system_cache_loaded = false;
    $CONFIG->views = new stdClass();
    $data = elgg_load_system_cache('view_locations');
    if (!is_string($data)) {
        return;
    }
    $CONFIG->views->locations = unserialize($data);
    $data = elgg_load_system_cache('view_types');
    if (!is_string($data)) {
        return;
    }
    $CONFIG->view_types = unserialize($data);
    $CONFIG->system_cache_loaded = true;
}
Ejemplo n.º 10
0
function _elgg_load_translations()
{
    global $CONFIG;
    if ($CONFIG->system_cache_enabled) {
        $loaded = true;
        $languages = array_unique(array('en', get_current_language()));
        foreach ($languages as $language) {
            $data = elgg_load_system_cache("{$language}.php");
            if ($data) {
                add_translation($language, unserialize($data));
            } else {
                $loaded = false;
            }
        }
        if ($loaded) {
            $CONFIG->i18n_loaded_from_cache = true;
            // this is here to force
            $CONFIG->language_paths[dirname(dirname(dirname(__FILE__))) . "/languages/"] = true;
            return;
        }
    }
    // load core translations from languages directory
    register_translations(dirname(dirname(dirname(__FILE__))) . "/languages/");
}
Ejemplo n.º 11
0
 /**
  * Loads the system cache during engine boot
  * 
  * @see elgg_reset_system_cache()
  * @access private
  */
 function loadAll()
 {
     $this->CONFIG->system_cache_loaded = false;
     $this->CONFIG->views = new \stdClass();
     $data = elgg_load_system_cache('view_locations');
     if (!is_string($data)) {
         return;
     }
     $this->CONFIG->views->locations = unserialize($data);
     $data = elgg_load_system_cache('view_types');
     if (!is_string($data)) {
         return;
     }
     $this->CONFIG->view_types = unserialize($data);
     $this->CONFIG->system_cache_loaded = true;
 }