Example #1
0
/**
 * Load cached data into the autoload system
 *
 * Note this has to wait until Elgg's data path is known.
 *
 * @access private
 */
function _elgg_load_autoload_cache()
{
    $manager = _elgg_services()->autoloadManager;
    $manager->setStorage(elgg_get_system_cache());
    if (!$manager->loadCache()) {
        $manager->addClasses(dirname(dirname(__FILE__)) . '/classes');
    }
}
Example #2
0
 /**
  * Retrieve the contents of a system cache.
  *
  * @param string $type The type of cache to load
  * @return string
  */
 function load($type)
 {
     if ($this->CONFIG->system_cache_enabled) {
         $cache = elgg_get_system_cache();
         $cached_data = $cache->load($type);
         if ($cached_data) {
             return $cached_data;
         }
     }
     return null;
 }
/**
 * Retrieve the contents of a system cache.
 *
 * @param string $type The type of cache to load
 * @return string
 */
function elgg_load_system_cache($type)
{
    global $CONFIG;
    if ($CONFIG->system_cache_enabled) {
        $cache = elgg_get_system_cache();
        $cached_data = $cache->load($type);
        if ($cached_data) {
            return $cached_data;
        }
    }
    return null;
}
        if ($count == 0) {
            $field = new ElggObject();
            // not using classes so we can handle both profile and trip in one function
            $field->owner_guid = $site_guid;
            $field->container_guid = $site_guid;
            $field->access_id = ACCESS_PUBLIC;
            $field->subtype = "custom_" . $type . "_field";
            $field->save();
            $field->metadata_name = $metadata_name;
            $field->metadata_type = $metadata_type;
            if ($type == "profile") {
                $field->show_on_register = "no";
                $field->mandatory = "no";
                $field->user_editable = "yes";
            }
            $field->order = $max_fields;
            $field->save();
            $max_fields++;
            $added++;
        }
    }
    if ($added == 0) {
        register_error(elgg_echo("profiles_go:actions:import:from_default:no_fields"));
    } else {
        elgg_get_system_cache()->delete("profiles_go_" . $type . "_fields_" . $site_guid);
        system_message(elgg_echo("profiles_go:actions:import:from_default:new_fields", array($added)));
    }
} else {
    register_error(elgg_echo("profiles_go:actions:import:from_default:error:wrong_type"));
}
forward(REFERER);
Example #5
0
/**
 * @access private
 * @deprecated 1.9 Use elgg_get_system_cache()
 */
function elgg_get_filepath_cache()
{
    elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_get_system_cache()', 1.9);
    return elgg_get_system_cache();
}
Example #6
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;
 }
Example #7
0
<?php

$widget_context = get_input("widget_context");
if (!empty($widget_context)) {
    $error_count = 0;
    if ($widgets = elgg_get_widget_types($widget_context)) {
        $toggle_settings = array("can_add", "hide");
        foreach ($widgets as $handler => $widget) {
            foreach ($toggle_settings as $setting) {
                $input_name = $widget_context . "_" . $handler . "_" . $setting;
                $value = get_input($input_name, "no");
                if (!widget_manager_set_widget_setting($handler, $setting, $widget_context, $value)) {
                    $error_count++;
                    register_error(elgg_echo("widget_manager:action:manage:error:save_setting", array($setting, $widget->name)));
                }
            }
        }
        elgg_get_system_cache()->delete("widget_manager_widget_settings");
    }
    if ($error_count == 0) {
        system_message(elgg_echo("widget_manager:action:manage:success"));
    }
} else {
    register_error(elgg_echo("widget_manager:action:manage:error:context"));
}
forward(REFERER);
Example #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;
}
Example #9
0
            $metadata_type = $type;
            $options["metadata_name_value_pairs"] = array("name" => "metadata_name", "value" => $metadata_name);
            $count = elgg_get_entities_from_metadata($options);
            if ($count == 0) {
                $field = new ProfileManagerCustomProfileField();
                $field->save();
                $field->metadata_name = $metadata_name;
                $field->metadata_label = $metadata_label;
                $field->metadata_type = $metadata_type;
                $field->show_on_register = "no";
                $field->mandatory = "no";
                $field->user_editable = "yes";
                $field->order = $new_order;
                $field->save();
                $new_order++;
            } else {
                $skipped++;
            }
            $n++;
        }
    }
    // clear cache
    $site_guid = elgg_get_site_entity()->getGUID();
    elgg_get_system_cache()->delete("profile_manager_profile_fields_" . $site_guid);
}
if ($n - $skipped == 0) {
    register_error(elgg_echo("profile_manager:actions:import:from_custom:no_fields"));
} else {
    system_message(elgg_echo("profile_manager:actions:import:from_custom:new_fields", array($n - $skipped)));
}
forward(REFERER);
    $options['metadata_name_value_pairs'] = ['name' => 'metadata_name', 'value' => $metadata_name];
    $count = elgg_get_entities_from_metadata($options);
    if ($count) {
        continue;
    }
    $field = new ElggObject();
    // not using classes so we can handle both profile and group in one function
    $field->owner_guid = $site_guid;
    $field->container_guid = $site_guid;
    $field->access_id = ACCESS_PUBLIC;
    $field->subtype = $subtype;
    $field->save();
    $field->metadata_name = $metadata_name;
    $field->metadata_type = $metadata_type;
    if ($type == 'profile') {
        $field->show_on_register = 'no';
        $field->mandatory = 'no';
        $field->user_editable = 'yes';
    }
    $field->order = $max_fields;
    $field->save();
    $max_fields++;
    $added++;
}
if ($added == 0) {
    register_error(elgg_echo('profile_manager:actions:import:from_default:no_fields'));
} else {
    elgg_get_system_cache()->delete("profile_manager_{$type}_fields_{$site_guid}");
    system_message(elgg_echo('profile_manager:actions:import:from_default:new_fields', [$added]));
}
forward(REFERER);
/**
 * Merge all custom translations into a single file for performance
 *
 * @param string $language the language to merge
 * @param bool   $update   force and update to other sites
 *
 * @return bool
 */
function translation_editor_merge_translations($language = "", $update = false)
{
    $result = false;
    $site = elgg_get_site_entity();
    if (empty($language)) {
        $language = get_current_language();
    }
    if (!empty($language)) {
        $translations = array();
        // get core translations
        $core = translation_editor_read_translation($language, 'core');
        if (!empty($core)) {
            $translations = $core;
        }
        // get the customo keys
        $custom_keys = translation_editor_read_translation($language, 'custom_keys');
        if (!empty($custom_keys)) {
            $translations += $custom_keys;
        }
        // proccess all plugins
        $plugins = elgg_get_plugins();
        if (!empty($plugins)) {
            foreach ($plugins as $plugin) {
                // add plugin translations
                $plugin_translation = translation_editor_read_translation($language, $plugin->title);
                if (!empty($plugin_translation)) {
                    $translations += $plugin_translation;
                }
            }
        }
        if (!empty($translations)) {
            // write all to disk
            if (translation_editor_write_translation($language, "translation_editor_merged_{$site->getGUID()}", $translations)) {
                $result = true;
            }
        } else {
            // no custom translations, so remove the cache file
            if (translation_editor_delete_translation($language, "translation_editor_merged_{$site->getGUID()}")) {
                $result = true;
            }
        }
    }
    if ($result) {
        // clear system cache
        $cache = elgg_get_system_cache();
        $cache->delete("{$language}.lang");
        // let others know this happend
        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($site->getGUID(), "te_last_update_{$language}", $ts);
    }
    return $result;
}
Example #12
0
/**
 * @access private
 */
function elgg_get_filepath_cache()
{
    return elgg_get_system_cache();
}