Exemplo n.º 1
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;
}
Exemplo 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)
{
    $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;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
/**
 * @access private
 * @deprecated 1.9 Use elgg_save_system_cache()
 */
function elgg_filepath_cache_save($type, $data)
{
    elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_save_system_cache()', 1.9);
    return elgg_save_system_cache($type, $data);
}
Exemplo n.º 5
0
/**
 * Initializes the simplecache lastcache variable and creates system cache files
 * when appropriate.
 * 
 * @access private
 */
function _elgg_cache_init()
{
    global $CONFIG;
    if (!defined('UPGRADING') && empty($CONFIG->lastcache)) {
        $CONFIG->lastcache = (int) datalist_get('simplecache_lastupdate');
    }
    // cache system data if enabled and not loaded
    if ($CONFIG->system_cache_enabled && !$CONFIG->system_cache_loaded) {
        elgg_save_system_cache('view_locations', serialize($CONFIG->views->locations));
        elgg_save_system_cache('view_types', serialize($CONFIG->view_types));
    }
    if ($CONFIG->system_cache_enabled && !$CONFIG->i18n_loaded_from_cache) {
        reload_all_translations();
        foreach ($CONFIG->translations as $lang => $map) {
            elgg_save_system_cache("{$lang}.lang", serialize($map));
        }
    }
}
Exemplo n.º 6
0
 /**
  * Saves data to cache location
  *
  * @param string $data data to be saved
  *
  * @return void
  */
 public function saveToCache($data)
 {
     elgg_save_system_cache($this->getCacheName(), $data);
 }
Exemplo n.º 7
0
/**
 * @access private
 */
function _elgg_cache_init()
{
    global $CONFIG;
    $viewtype = elgg_get_viewtype();
    // Regenerate the simple cache if expired.
    // Don't do it on upgrade because upgrade does it itself.
    // @todo - move into function and perhaps run off init system event
    if (!defined('UPGRADING')) {
        $lastupdate = datalist_get("simplecache_lastupdate_{$viewtype}");
        $lastcached = datalist_get("simplecache_lastcached_{$viewtype}");
        if ($lastupdate == 0 || $lastcached < $lastupdate) {
            elgg_regenerate_simplecache($viewtype);
            $lastcached = datalist_get("simplecache_lastcached_{$viewtype}");
        }
        $CONFIG->lastcache = $lastcached;
    }
    // cache system data if enabled and not loaded
    if ($CONFIG->system_cache_enabled && !$CONFIG->system_cache_loaded) {
        elgg_save_system_cache('view_locations', serialize($CONFIG->views->locations));
        elgg_save_system_cache('view_types', serialize($CONFIG->view_types));
    }
    if ($CONFIG->system_cache_enabled && !$CONFIG->i18n_loaded_from_cache) {
        reload_all_translations();
        foreach ($CONFIG->translations as $lang => $map) {
            elgg_save_system_cache("{$lang}.php", serialize($map));
        }
    }
}
Exemplo n.º 8
0
 /**
  * Initializes the simplecache lastcache variable and creates system cache files
  * when appropriate.
  * 
  * @access private
  */
 function init()
 {
     // cache system data if enabled and not loaded
     if ($this->CONFIG->system_cache_enabled && !$this->CONFIG->system_cache_loaded) {
         elgg_save_system_cache('view_locations', serialize($this->CONFIG->views->locations));
         elgg_save_system_cache('view_types', serialize($this->CONFIG->view_types));
     }
     if ($this->CONFIG->system_cache_enabled && !$this->CONFIG->i18n_loaded_from_cache) {
         _elgg_services()->translator->reloadAllTranslations();
         foreach ($this->CONFIG->translations as $lang => $map) {
             elgg_save_system_cache("{$lang}.lang", serialize($map));
         }
     }
 }