예제 #1
0
/**
 * Creates a site page object.
 *
 * @param str $page_type
 * @return mixed ElggSitePage on success, FALSE on fail.
 */
function sitepages_create_sitepage_object($page_type)
{
    global $CONFIG;
    $sitepage = new ElggSitePage();
    $sitepage->page_type = $page_type;
    $sitepage->access_id = ACCESS_PUBLIC;
    $sitepage->save();
    if ($sitepage->save() && set_private_setting($CONFIG->site->getGUID(), "sitepages:{$page_type}", $sitepage->getGUID())) {
        return $sitepage;
    }
    return FALSE;
}
 public function testElggApiGettersEntitiesFromPrivateSettings()
 {
     // create some test private settings
     $setting_name = 'test_setting_name_' . rand();
     $setting_value = rand(1000, 9999);
     $setting_name2 = 'test_setting_name_' . rand();
     $setting_value2 = rand(1000, 9999);
     $subtypes = $this->getRandomValidSubtypes(array('object'), 1);
     $subtype = $subtypes[0];
     $guids = array();
     // our targets
     $valid = new ElggObject();
     $valid->subtype = $subtype;
     $valid->save();
     $guids[] = $valid->getGUID();
     set_private_setting($valid->getGUID(), $setting_name, $setting_value);
     set_private_setting($valid->getGUID(), $setting_name2, $setting_value2);
     $valid2 = new ElggObject();
     $valid2->subtype = $subtype;
     $valid2->save();
     $guids[] = $valid2->getGUID();
     set_private_setting($valid2->getGUID(), $setting_name, $setting_value);
     set_private_setting($valid2->getGUID(), $setting_name2, $setting_value2);
     // simple test with name
     $options = array('private_setting_name' => $setting_name);
     $entities = elgg_get_entities_from_private_settings($options);
     foreach ($entities as $entity) {
         $this->assertTrue(in_array($entity->getGUID(), $guids));
         $value = get_private_setting($entity->getGUID(), $setting_name);
         $this->assertEqual($value, $setting_value);
     }
     // simple test with value
     $options = array('private_setting_value' => $setting_value);
     $entities = elgg_get_entities_from_private_settings($options);
     foreach ($entities as $entity) {
         $this->assertTrue(in_array($entity->getGUID(), $guids));
         $value = get_private_setting($entity->getGUID(), $setting_name);
         $this->assertEqual($value, $setting_value);
     }
     // test pairs
     $options = array('type' => 'object', 'subtype' => $subtype, 'private_setting_name_value_pairs' => array(array('name' => $setting_name, 'value' => $setting_value), array('name' => $setting_name2, 'value' => $setting_value2)));
     $entities = elgg_get_entities_from_private_settings($options);
     $this->assertEqual(2, count($entities));
     foreach ($entities as $entity) {
         $this->assertTrue(in_array($entity->getGUID(), $guids));
     }
     foreach ($guids as $guid) {
         if ($e = get_entity($guid)) {
             $e->delete();
         }
     }
 }
예제 #3
0
파일: plugins.php 프로젝트: eokyere/elgg
 /**
  * Override entity get and sets in order to save data to private data store.
  */
 public function set($name, $value)
 {
     if (array_key_exists($name, $this->attributes)) {
         // Check that we're not trying to change the guid!
         if (array_key_exists('guid', $this->attributes) && $name == 'guid') {
             return false;
         }
         $this->attributes[$name] = $value;
     } else {
         return set_private_setting($this->guid, $name, $value);
     }
     return true;
 }
예제 #4
0
function subsite_manager_make_superadmin($user_guid = 0)
{
    $result = false;
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    if (!empty($user_guid) && subsite_manager_is_superadmin_logged_in()) {
        if (set_private_setting($user_guid, "superadmin", true)) {
            $result = true;
        }
    }
    return $result;
}
예제 #5
0
파일: Upgrades.php 프로젝트: n8b/VMN
 /**
  * Runs pending upgrades
  * @return void
  */
 public function runUpgrades()
 {
     $site = elgg_get_site_entity();
     $upgrades = $this->getUpgrades();
     foreach ($upgrades as $upgrade) {
         $upgradename = "hypeScraper_{$upgrade}";
         if (get_private_setting($site->guid, $upgradename)) {
             continue;
         }
         if (is_callable(array($this, $upgrade))) {
             call_user_func(array($this, $upgrade));
             set_private_setting($site->guid, $upgradename, time());
         }
     }
 }
예제 #6
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;
}
예제 #7
0
파일: ElggPlugin.php 프로젝트: rasul/Elgg
 /**
  * Sets a user setting for a plugin
  *
  * @param string $name      The setting name
  * @param string $value     The setting value
  * @param int    $user_guid The user GUID
  *
  * @return mixed The new setting ID or false
  */
 public function setUserSetting($name, $value, $user_guid = null)
 {
     $user_guid = (int) $user_guid;
     if ($user_guid) {
         $user = get_entity($user_guid);
     } else {
         $user = elgg_get_logged_in_user_entity();
     }
     if (!$user instanceof ElggUser) {
         return false;
     }
     // Hook to validate setting
     // note this doesn't pass the namespaced name!
     $value = elgg_trigger_plugin_hook('plugin:usersetting', 'user', array('user' => $user, 'plugin' => $this->getID(), 'name' => $name, 'value' => $value), $value);
     // set the namespaced name.
     $name = elgg_namespace_plugin_private_setting('user_setting', $name, $this->getID());
     return set_private_setting($user->guid, $name, $value);
 }
예제 #8
0
$old_plugin_order = unserialize($site->pluginorder);
$old_enabled_plugins = $site->enabled_plugins;
$db_prefix = get_config('dbprefix');
$plugin_subtype_id = get_subtype_id('object', 'plugin');
// easy one first: make sure the the site owns all plugin entities.
$q = "UPDATE {$db_prefix}entities e\n\tSET owner_guid = site_guid, container_guid = site_guid\n\tWHERE e.type = 'object' AND e.subtype = {$plugin_subtype_id}";
$r = update_data($q);
// rewrite all plugin:setting:* to ELGG_PLUGIN_USER_SETTING_PREFIX . *
$q = "UPDATE {$db_prefix}private_settings\n\tSET name = replace(name, 'plugin:settings:', '" . ELGG_PLUGIN_USER_SETTING_PREFIX . "')\n\tWHERE name LIKE 'plugin:settings:%'";
$r = update_data($q);
// grab current plugin GUIDs to add a temp priority
$q = "SELECT * FROM {$db_prefix}entities e\n\tJOIN {$db_prefix}objects_entity oe ON e.guid = oe.guid\n\tWHERE e.type = 'object' AND e.subtype = {$plugin_subtype_id}";
$plugins = get_data($q);
foreach ($plugins as $plugin) {
    $priority = elgg_namespace_plugin_private_setting('internal', 'priority');
    set_private_setting($plugin->guid, $priority, 0);
}
// force regenerating plugin entities
elgg_generate_plugin_entities();
// set the priorities for all plugins
// this function rewrites it to a normal index so use the current one.
elgg_set_plugin_priorities($old_plugin_order);
// add relationships for enabled plugins
if ($old_enabled_plugins) {
    // they might only have one plugin enabled.
    if (!is_array($old_enabled_plugins)) {
        $old_enabled_plugins = array($old_enabled_plugins);
    }
    // sometimes there were problems and you'd get 1000s of enabled plugins.
    $old_enabled_plugins = array_unique($old_enabled_plugins);
    foreach ($old_enabled_plugins as $plugin_id) {
예제 #9
0
function pleio_api_push_gcm_messages($gcmMessages = array())
{
    if (!sizeof($gcmMessages)) {
        return;
    }
    $apiKey = elgg_get_plugin_setting("gcm_api_key", "pleio_api");
    $url = 'https://android.googleapis.com/gcm/send';
    $headers = array('Authorization: key=' . $apiKey, 'Content-Type: application/json');
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    foreach ($gcmMessages as $m) {
        //$m ["dry_run"] = true; //TEST SERVER
        $user_guids = $m["user_guids"];
        unset($m["user_guids"]);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($m));
        $result = curl_exec($ch);
        $results = json_decode($result);
        for ($i = 0; $i < sizeof($results->results); $i++) {
            $result = $results->results[$i];
            if (isset($result->error)) {
                switch ($result->error) {
                    case "InvalidRegistration":
                    case "NotRegistered":
                        remove_private_setting($user_guids[$i], "device_token");
                        break;
                }
            } elseif (isset($result->registration_id)) {
                set_private_setting($user_guids[$i], "device_token", $result->registration_id);
            }
        }
    }
    curl_close($ch);
    return true;
}
예제 #10
0
 /**
  * Sets a user setting for a plugin
  *
  * @param string $name      The setting name
  * @param string $value     The setting value
  * @param int    $user_guid The user GUID
  *
  * @return mixed The new setting ID or false
  */
 public function setUserSetting($name, $value, $user_guid = 0)
 {
     $user_guid = (int) $user_guid;
     if ($user_guid) {
         $user = get_entity($user_guid);
     } else {
         $user = _elgg_services()->session->getLoggedInUser();
     }
     if (!$user instanceof \ElggUser) {
         return false;
     }
     // Hook to validate setting
     // note: this doesn't pass the namespaced name
     $value = _elgg_services()->hooks->trigger('usersetting', 'plugin', array('user' => $user, 'plugin' => $this, 'plugin_id' => $this->getID(), 'name' => $name, 'value' => $value), $value);
     // set the namespaced name.
     $name = _elgg_namespace_plugin_private_setting('user_setting', $name, $this->getID());
     return set_private_setting($user->guid, $name, $value);
 }
예제 #11
0
$entity_guid = (int) get_input('entity_guid');
$icons = get_input('icons');
$texts = get_input('texts');
$hrefs = get_input('hrefs');
$targets = get_input('targets');
$entity = get_entity($entity_guid);
if (empty($entity) || !$entity->canEdit()) {
    register_error(elgg_echo('InvalidParameterException:NoEntityFound'));
    forward(REFERER);
}
$new_values = array();
foreach ($hrefs as $index => $href) {
    // check if value matches placeholder text
    if ($texts[$index] == elgg_echo('theme_haarlem_intranet:quick_nav:text')) {
        $texts[$index] = '';
    }
    if ($href == elgg_echo('theme_haarlem_intranet:quick_nav:href')) {
        continue;
    }
    if (empty($href)) {
        continue;
    }
    $new_values[] = array('icon' => $icons[$index], 'text' => $texts[$index], 'href' => $href, 'target' => $targets[$index]);
}
if (empty($new_values)) {
    remove_private_setting($entity_guid, 'quick_nav');
} else {
    set_private_setting($entity_guid, 'quick_nav', json_encode($new_values));
}
system_message(elgg_echo('theme_haarlem_intranet:action:quick_nav:success'));
forward(REFERER);
예제 #12
0
function pleio_api_swordfish_site_connect($subsite_id = 0, $swordfish_api_url = "")
{
    $subsite_id = intval($subsite_id);
    $swordfish_api_url = sanitise_string($swordfish_api_url);
    $user = elgg_get_logged_in_user_entity();
    $subsite = get_entity($subsite_id);
    $parsed = parse_url($swordfish_api_url);
    if (!$subsite) {
        return new ErrorResult(elgg_echo('pleio_api:swordfish_api_url:subsite_not_found'));
    }
    if (!$parsed["scheme"] || !$parsed["host"] || !$parsed["path"]) {
        return new ErrorResult(elgg_echo('pleio_api:swordfish_api_url:invalid_url'));
    }
    if (set_private_setting($subsite_id, "swordfish_api_url", $swordfish_api_url)) {
        return new SuccessResult(elgg_echo('pleio_api:swordfish_api_url:success'));
    }
    return new ErrorResult(elgg_echo('pleio_api:swordfish_api_url:fail'));
}
예제 #13
0
/**
 * 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;
}
예제 #14
0
 /**
  * Sets a user setting for a plugin
  *
  * @param string $name      The setting name
  * @param string $value     The setting value
  * @param int    $user_guid The user GUID
  *
  * @return mixed The new setting ID or false
  */
 public function setUserSetting($name, $value, $user_guid = null)
 {
     $user_guid = (int) $user_guid;
     if ($user_guid) {
         $user = get_entity($user_guid);
     } else {
         $user = elgg_get_logged_in_user_entity();
     }
     if (!$user instanceof ElggUser) {
         return false;
     }
     // Hook to validate setting
     // note: this doesn't pass the namespaced name
     $value = elgg_trigger_plugin_hook('usersetting', 'plugin', array('user' => $user, 'plugin' => $this, 'plugin_id' => $this->getID(), 'name' => $name, 'value' => $value), $value);
     // set the namespaced name.
     $name = elgg_namespace_plugin_private_setting('user_setting', $name, $this->getID());
     // Subsite adjustment
     $site = elgg_get_site_entity();
     if (!subsite_manager_check_global_plugin_setting($this->getID(), "use_global_usersettings")) {
         $name = str_replace(ELGG_PLUGIN_USER_SETTING_PREFIX . $this->getID() . ":", ELGG_PLUGIN_USER_SETTING_PREFIX . $this->getID() . ":" . $site->getGUID() . ":", $name);
     }
     return set_private_setting($user->getGUID(), $name, $value);
 }
예제 #15
0
<?php

$container_guid = (int) get_input('container_guid', elgg_get_logged_in_user_guid());
$ordered_guids = get_input('guids', '');
if (get_entity($container_guid)) {
    set_private_setting($container_guid, 'quicklinks_order', json_encode($ordered_guids));
}
예제 #16
0
 }
 if (strcmp($password, $password2) != 0) {
     throw new RegistrationException(elgg_echo('RegistrationException:PasswordMismatch'));
 }
 $guid = register_user($username, $password, $name, $email, false, $friend_guid, $invitecode);
 if ($guid) {
     $new_user = get_entity($guid);
     // allow plugins to respond to self registration
     // note: To catch all new users, even those created by an admin,
     // register for the create, user event instead.
     // only passing vars that aren't in ElggUser.
     $params = array('user' => $new_user, 'password' => $password, 'friend_guid' => $friend_guid, 'invitecode' => $invitecode);
     // accept general terms
     if (get_input("accept_terms") == "yes") {
         $ia = elgg_set_ignore_access(true);
         set_private_setting($guid, "general_terms_accepted", time());
         elgg_set_ignore_access($ia);
     }
     // @todo should registration be allowed no matter what the plugins return?
     if (!elgg_trigger_plugin_hook('register', 'user', $params, TRUE)) {
         $ia = elgg_set_ignore_access(true);
         $new_user->delete();
         elgg_set_ignore_access($ia);
         // @todo this is a generic messages. We could have plugins
         // throw a RegistrationException, but that is very odd
         // for the plugin hooks system.
         throw new RegistrationException(elgg_echo('registerbad'));
     }
     elgg_clear_sticky_form('register');
     system_message(elgg_echo("registerok", array(elgg_get_site_entity()->name)));
     // if exception thrown, this probably means there is a validation
/**
 * Generate and send a password request email to a given user's registered email address.
 *
 * @param int $user_guid
 */
function send_new_password_request($user_guid)
{
    global $CONFIG;
    $user_guid = (int) $user_guid;
    $user = get_entity($user_guid);
    if ($user) {
        // generate code
        $code = generate_random_cleartext_password();
        //create_metadata($user_guid, 'conf_code', $code,'', 0, ACCESS_PRIVATE);
        set_private_setting($user_guid, 'passwd_conf_code', $code);
        // generate link
        $link = $CONFIG->site->url . "action/user/passwordreset?u={$user_guid}&c={$code}";
        // generate email
        $email = sprintf(elgg_echo('email:resetreq:body'), $user->name, $_SERVER['REMOTE_ADDR'], $link);
        return notify_user($user->guid, $CONFIG->site->guid, elgg_echo('email:resetreq:subject'), $email, NULL, 'email');
    }
    return false;
}
예제 #18
0
파일: entities.php 프로젝트: jricher/Elgg
 function setPrivateSetting($name, $value)
 {
     return set_private_setting($this->getGUID(), $name, $value);
 }
예제 #19
0
파일: ElggEntity.php 프로젝트: elgg/elgg
 /**
  * Adds a private setting to this entity.
  *
  * Private settings are similar to metadata but will not
  * be searched and there are fewer helper functions for them.
  *
  * @param string $name  Name of private setting
  * @param mixed  $value Value of private setting
  *
  * @return bool
  */
 public function setPrivateSetting($name, $value)
 {
     if ((int) $this->guid > 0) {
         return set_private_setting($this->getGUID(), $name, $value);
     } else {
         $this->temp_private_settings[$name] = $value;
         return true;
     }
 }
예제 #20
0
 /**
  * Batch sync data to ElasticSearch
  *
  * This function is timed at a max runtime of 30sec
  *
  * @param array  $options   the options for elgg_get_entities()
  * @param int    $crontime the starttime of the cron in order to limit max runtime
  * @param string $getter    the getter function to use for \ElggBatch
  *
  * @return bool|void
  */
 protected static function batchSync($options, $crontime, $getter = '')
 {
     if (empty($options) || !is_array($options)) {
         return;
     }
     if (empty($getter)) {
         $getter = 'elgg_get_entities_from_private_settings';
     }
     if (!is_callable($getter)) {
         return false;
     }
     $client = elasticsearch_get_client();
     if (empty($client)) {
         return;
     }
     $crontime = sanitise_int($crontime, false);
     if (empty($crontime)) {
         $crontime = time();
     }
     if (time() - $crontime >= 30) {
         return false;
     }
     set_time_limit(40);
     $ia = elgg_set_ignore_access(true);
     $time_left = true;
     $batch_size = 100;
     $options['callback'] = false;
     $options['limit'] = $batch_size;
     while ($time_left && ($rows = call_user_func($getter, $options))) {
         $guids = array();
         foreach ($rows as $row) {
             $guids[] = (int) $row->guid;
         }
         $result = $client->bulkIndexDocuments($guids);
         if (empty($result)) {
             break;
         }
         $items = elgg_extract('items', $result);
         foreach ($items as $item) {
             $guid = (int) elgg_extract('_id', elgg_extract('index', $item));
             $status = elgg_extract('status', elgg_extract('index', $item));
             if ($status !== 200) {
                 continue;
             }
             if (empty($guid)) {
                 continue;
             }
             set_private_setting($guid, ELASTICSEARCH_INDEXED_NAME, time());
         }
         if (time() - $crontime >= 30) {
             $time_left = false;
             break;
         }
     }
     // restore access
     elgg_set_ignore_access($ia);
     return $time_left;
 }