/**
 * Create or update the extras table for a given object.
 * Call create_entity first.
 *
 * @param int    $guid        The guid of the entity you're creating (as obtained by create_entity)
 * @param string $title       The title of the object
 * @param string $description The object's description
 *
 * @return bool
 */
function create_object_entity($guid, $title, $description)
{
    global $CONFIG;
    $guid = (int) $guid;
    $title = sanitise_string($title);
    $description = sanitise_string($description);
    $row = get_entity_as_row($guid);
    if ($row) {
        // Core entities row exists and we have access to it
        $query = "SELECT guid from {$CONFIG->dbprefix}objects_entity where guid = {$guid}";
        if ($exists = get_data_row($query)) {
            $query = "UPDATE {$CONFIG->dbprefix}objects_entity\n\t\t\t\tset title='{$title}', description='{$description}' where guid={$guid}";
            $result = update_data($query);
            if ($result != false) {
                // Update succeeded, continue
                $entity = get_entity($guid);
                elgg_trigger_event('update', $entity->type, $entity);
                return $guid;
            }
        } else {
            // Update failed, attempt an insert.
            $query = "INSERT into {$CONFIG->dbprefix}objects_entity\n\t\t\t\t(guid, title, description) values ({$guid}, '{$title}','{$description}')";
            $result = insert_data($query);
            if ($result !== false) {
                $entity = get_entity($guid);
                if (elgg_trigger_event('create', $entity->type, $entity)) {
                    return $guid;
                } else {
                    $entity->delete();
                }
            }
        }
    }
    return false;
}
Example #2
0
 /**
  * Publish blogs based on advanced publication settings
  *
  * @param int $time the timestamp the entity was published
  *
  * @return void
  */
 protected static function publishBlogs($time)
 {
     $dbprefix = elgg_get_config('dbprefix');
     $publication_id = elgg_get_metastring_id('publication_date');
     $publish_options = ['type' => 'object', 'subtype' => 'blog', 'limit' => false, 'joins' => ["JOIN {$dbprefix}metadata mdtime ON e.guid = mdtime.entity_guid", "JOIN {$dbprefix}metastrings mstime ON mdtime.value_id = mstime.id"], 'metadata_name_value_pairs' => [['name' => 'status', 'value' => 'draft']], 'wheres' => ["((mdtime.name_id = {$publication_id}) AND (DATE(mstime.string) = DATE(NOW())))"]];
     // get unpublished blogs that need to be published
     $entities = new \ElggBatch('elgg_get_entities_from_metadata', $publish_options);
     foreach ($entities as $entity) {
         // add river item
         elgg_create_river_item(['view' => 'river/object/blog/create', 'action_type' => 'create', 'subject_guid' => $entity->getOwnerGUID(), 'object_guid' => $entity->getGUID()]);
         // set correct time created
         $entity->time_created = $time;
         // publish blog
         $entity->status = 'published';
         // revert access
         $entity->access_id = $entity->future_access;
         unset($entity->future_access);
         // send notifications when post published
         elgg_trigger_event('publish', 'object', $entity);
         // notify owner
         notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo('blog_tools:notify:publish:subject'), elgg_echo('blog_tools:notify:publish:message', [$entity->title, $entity->getURL()]));
         // save everything
         $entity->save();
     }
 }
Example #3
0
function addTaggedWirePost($hook, $type, $params)
{
    global $CONFIG;
    $id = insert_data("insert into {$CONFIG->dbprefix}river " . " set type = '" . $params['type'] . "', " . " subtype = '" . $params['subtype'] . "', " . " action_type = '" . $params['action_type'] . "', " . " access_id = '" . $params['access_id'] . "', " . " view = '" . $params['view'] . "', " . " subject_guid = '" . $params['subject_guid'] . "', " . " object_guid = '" . $params['object_guid'] . "', " . " annotation_id = '" . $params['annotation_id'] . "', " . " posted = '" . $params['posted'] . "';");
    $tags = "";
    if (isset($_SESSION['role'])) {
        switch ($_SESSION['role']) {
            case "learner":
                $tags = "Learner-Apprenant";
                break;
            case "instructor":
                $tags = "Instructor-Instructeur";
                break;
            case "developer":
                $tags = "Developer-Développeur";
                break;
            case "trainingmgr":
                $tags = "trainingmgr";
                break;
        }
        $roleTags = $_SESSION['role'];
    }
    if ($roleTags) {
        $metaID = create_metadata($params['object_guid'], "tags", "{$tags}", "text", elgg_get_logged_in_user_guid(), 2, true);
    }
    if ($id) {
        update_entity_last_action($object_guid, $posted);
        $river_items = elgg_get_river(array('id' => $id));
        if ($river_items) {
            elgg_trigger_event('created', 'river', $river_items[0]);
        }
    }
    return false;
}
Example #4
0
 /**
  * Enqueue the mail for delivery
  *
  * @return bool
  */
 public function enqueue()
 {
     if (!$this->save()) {
         return false;
     }
     elgg_trigger_event('enqueue', 'object', $this);
     return true;
 }
Example #5
0
/**
 * Adds an item to the river.
 *
 * @param string $view          The view that will handle the river item (must exist)
 * @param string $action_type   An arbitrary string to define the action (eg 'comment', 'create')
 * @param int    $subject_guid  The GUID of the entity doing the action
 * @param int    $object_guid   The GUID of the entity being acted upon
 * @param int    $access_id     The access ID of the river item (default: same as the object)
 * @param int    $posted        The UNIX epoch timestamp of the river item (default: now)
 * @param int    $annotation_id The annotation ID associated with this river entry
 *
 * @return int/bool River ID or false on failure
 */
function add_to_river($view, $action_type, $subject_guid, $object_guid, $access_id = "", $posted = 0, $annotation_id = 0)
{
    global $CONFIG;
    // use default viewtype for when called from web services api
    if (!elgg_view_exists($view, 'default')) {
        return false;
    }
    if (!($subject = get_entity($subject_guid))) {
        return false;
    }
    if (!($object = get_entity($object_guid))) {
        return false;
    }
    if (empty($action_type)) {
        return false;
    }
    if ($posted == 0) {
        $posted = time();
    }
    if ($access_id === "") {
        $access_id = $object->access_id;
    }
    $type = $object->getType();
    $subtype = $object->getSubtype();
    $view = sanitise_string($view);
    $action_type = sanitise_string($action_type);
    $subject_guid = sanitise_int($subject_guid);
    $object_guid = sanitise_int($object_guid);
    $access_id = sanitise_int($access_id);
    $posted = sanitise_int($posted);
    $annotation_id = sanitise_int($annotation_id);
    $values = array('type' => $type, 'subtype' => $subtype, 'action_type' => $action_type, 'access_id' => $access_id, 'view' => $view, 'subject_guid' => $subject_guid, 'object_guid' => $object_guid, 'annotation_id' => $annotation_id, 'posted' => $posted);
    // return false to stop insert
    $values = elgg_trigger_plugin_hook('creating', 'river', null, $values);
    if ($values == false) {
        // inserting did not fail - it was just prevented
        return true;
    }
    extract($values);
    // Attempt to save river item; return success status
    $id = insert_data("insert into {$CONFIG->dbprefix}river " . " set type = '{$type}', " . " subtype = '{$subtype}', " . " action_type = '{$action_type}', " . " access_id = {$access_id}, " . " view = '{$view}', " . " subject_guid = {$subject_guid}, " . " object_guid = {$object_guid}, " . " annotation_id = {$annotation_id}, " . " posted = {$posted}");
    // update the entities which had the action carried out on it
    // @todo shouldn't this be down elsewhere? Like when an annotation is saved?
    if ($id) {
        update_entity_last_action($object_guid, $posted);
        $river_items = elgg_get_river(array('id' => $id));
        if ($river_items) {
            elgg_trigger_event('created', 'river', $river_items[0]);
        }
        return $id;
    } else {
        return false;
    }
}
Example #6
0
 /**
  * Mark an answer as the correct answer for this question
  *
  * @return void
  */
 public function markAsCorrect()
 {
     // first set the mark
     $this->correct_answer = true;
     // trigger event for notifications
     elgg_trigger_event('correct', 'object', $this);
     // depending of the plugin settings, we also need to close the question
     if (questions_close_on_marked_answer()) {
         $question = $this->getContainerEntity();
         $question->close();
     }
 }
Example #7
0
function widget_manager_init()
{
    // check valid WidgetManagerWidget class
    if (get_subtype_class("object", "widget") == "ElggWidget") {
        update_subtype("object", "widget", "WidgetManagerWidget");
    }
    elgg_trigger_event("widgets_init", "widget_manager");
    if (elgg_is_active_plugin("groups") && elgg_get_plugin_setting("group_enable", "widget_manager") == "yes") {
        // add the widget manager tool option
        $group_option_enabled = false;
        if (elgg_get_plugin_setting("group_option_default_enabled", "widget_manager") == "yes") {
            $group_option_enabled = true;
        }
        if (elgg_get_plugin_setting("group_option_admin_only", "widget_manager") != "yes") {
            // add the tool option for group admins
            add_group_tool_option('widget_manager', elgg_echo('widget_manager:groups:enable_widget_manager'), $group_option_enabled);
        } elseif (elgg_is_admin_logged_in()) {
            add_group_tool_option('widget_manager', elgg_echo('widget_manager:groups:enable_widget_manager'), $group_option_enabled);
        } elseif ($group_option_enabled) {
            // register event to make sure newly created groups have the group option enabled
            elgg_register_event_handler("create", "group", "widget_manager_create_group_event_handler");
            elgg_register_plugin_hook_handler('get_list', 'default_widgets', 'widget_manager_group_widgets_default_list');
        }
    }
    // extend CSS
    elgg_extend_view("css/elgg", "widget_manager/css/global");
    elgg_extend_view("css/admin", "widget_manager/css/global");
    elgg_extend_view("js/elgg", "widget_manager/js/site");
    elgg_extend_view("js/admin", "widget_manager/js/admin");
    // register a widget title url handler
    elgg_register_entity_url_handler("object", "widget", "widget_manager_widget_url_handler");
    // multi dashboard support
    add_subtype("object", MultiDashboard::SUBTYPE, "MultiDashboard");
    if (elgg_is_logged_in() && widget_manager_multi_dashboard_enabled()) {
        elgg_register_page_handler("multi_dashboard", "widget_manager_multi_dashboard_page_handler");
        $options = array("type" => "object", "subtype" => MultiDashboard::SUBTYPE, "owner_guid" => elgg_get_logged_in_user_guid(), "count" => true);
        $tab_count = elgg_get_entities($options);
        if ($tab_count < MULTI_DASHBOARD_MAX_TABS) {
            elgg_register_menu_item("extras", array("name" => "multi_dashboard", "text" => elgg_view_icon("home"), "href" => "multi_dashboard/edit/?internal_url=" . urlencode(current_page_url()), "title" => elgg_echo("widget_manager:multi_dashboard:extras"), "rel" => "nofollow", "id" => "widget-manager-multi_dashboard-extras"));
        }
        elgg_extend_view("page/elements/sidebar", "widget_manager/multi_dashboard/sidebar", 400);
        elgg_register_event_handler("create", "object", "widget_manager_create_object_handler");
        elgg_register_plugin_hook_handler("route", "dashboard", "widget_manager_dashboard_route_handler");
        elgg_register_plugin_hook_handler("action", "widgets/add", "widget_manager_widgets_add_action_handler");
        elgg_register_action("multi_dashboard/edit", dirname(__FILE__) . "/actions/multi_dashboard/edit.php");
        elgg_register_action("multi_dashboard/delete", dirname(__FILE__) . "/actions/multi_dashboard/delete.php");
        elgg_register_action("multi_dashboard/drop", dirname(__FILE__) . "/actions/multi_dashboard/drop.php");
        elgg_register_action("multi_dashboard/reorder", dirname(__FILE__) . "/actions/multi_dashboard/reorder.php");
    }
}
Example #8
0
 /**
  * Save an album
  *
  * @return bool
  */
 public function save()
 {
     if (!isset($this->new_album)) {
         $this->new_album = true;
     }
     if (!isset($this->last_notified)) {
         $this->last_notified = 0;
     }
     if (!parent::save()) {
         return false;
     }
     mkdir(tp_get_img_dir() . $this->guid, 0755, true);
     elgg_trigger_event('create', 'album', $this);
     return true;
 }
Example #9
0
 /**
  * Publish blogs based on advanced publication options
  *
  * @param string $hook         'cron'
  * @param string $type         'daily'
  * @param string $return_value optional stdout text
  * @param array  $params       supplied params
  *
  * @return void
  */
 public static function daily($hook, $type, $return_value, $params)
 {
     // only do if this is configured
     if (!blog_tools_use_advanced_publication_options()) {
         return $return_value;
     }
     $dbprefix = elgg_get_config("dbprefix");
     $publication_id = elgg_get_metastring_id("publication_date");
     $expiration_id = elgg_get_metastring_id("expiration_date");
     $time = elgg_extract("time", $params, time());
     $publish_options = array("type" => "object", "subtype" => "blog", "limit" => false, "joins" => array("JOIN " . $dbprefix . "metadata mdtime ON e.guid = mdtime.entity_guid", "JOIN " . $dbprefix . "metastrings mstime ON mdtime.value_id = mstime.id"), "metadata_name_value_pairs" => array(array("name" => "status", "value" => "draft")), "wheres" => array("((mdtime.name_id = " . $publication_id . ") AND (DATE(mstime.string) = DATE(NOW())))"));
     $unpublish_options = array("type" => "object", "subtype" => "blog", "limit" => false, "joins" => array("JOIN " . $dbprefix . "metadata mdtime ON e.guid = mdtime.entity_guid", "JOIN " . $dbprefix . "metastrings mstime ON mdtime.value_id = mstime.id"), "metadata_name_values_pairs" => array(array("name" => "status", "value" => "published")), "wheres" => array("((mdtime.name_id = " . $expiration_id . ") AND (DATE(mstime.string) = DATE(NOW())))"));
     // ignore access
     $ia = elgg_set_ignore_access(true);
     // get unpublished blogs that need to be published
     $entities = new \ElggBatch("elgg_get_entities_from_metadata", $publish_options);
     foreach ($entities as $entity) {
         // add river item
         elgg_create_river_item(array("view" => "river/object/blog/create", "action_type" => "create", "subject_guid" => $entity->getOwnerGUID(), "object_guid" => $entity->getGUID()));
         // set correct time created
         $entity->time_created = $time;
         // publish blog
         $entity->status = "published";
         // revert access
         $entity->access_id = $entity->future_access;
         unset($entity->future_access);
         // send notifications when post published
         elgg_trigger_event('publish', 'object', $entity);
         // notify owner
         notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo("blog_tools:notify:publish:subject"), elgg_echo("blog_tools:notify:publish:message", array($entity->title, $entity->getURL())));
         // save everything
         $entity->save();
     }
     // get published blogs that need to be unpublished
     $entities = new \ElggBatch("elgg_get_entities_from_metadata", $unpublish_options);
     foreach ($entities as $entity) {
         // remove river item
         elgg_delete_river(array("object_guid" => $entity->getGUID(), "action_type" => "create"));
         // unpublish blog
         $entity->status = "draft";
         // notify owner
         notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo("blog_tools:notify:expire:subject"), elgg_echo("blog_tools:notify:expire:message", array($entity->title, $entity->getURL())));
         // save everything
         $entity->save();
     }
     // reset access
     elgg_set_ignore_access($ia);
 }
Example #10
0
/**
 * Create or update the entities table for a given site.
 * Call create_entity first.
 *
 * @param int    $guid        Site GUID
 * @param string $name        Site name
 * @param string $description Site Description
 * @param string $url         URL of the site
 *
 * @return bool
 */
function create_site_entity($guid, $name, $description, $url)
{
    global $CONFIG;
    $guid = (int) $guid;
    $name = sanitise_string($name);
    $description = sanitise_string($description);
    $url = sanitise_string($url);
    $row = get_entity_as_row($guid);
    if ($row) {
        // Exists and you have access to it
        $query = "SELECT guid from {$CONFIG->dbprefix}sites_entity where guid = {$guid}";
        if ($exists = get_data_row($query)) {
            $query = "UPDATE {$CONFIG->dbprefix}sites_entity\n\t\t\t\tset name='{$name}', description='{$description}', url='{$url}' where guid={$guid}";
            $result = update_data($query);
            if ($result != false) {
                // Update succeeded, continue
                $entity = get_entity($guid);
                if (elgg_trigger_event('update', $entity->type, $entity)) {
                    return $guid;
                } else {
                    $entity->delete();
                    //delete_entity($guid);
                }
            }
        } else {
            // Update failed, attempt an insert.
            $query = "INSERT into {$CONFIG->dbprefix}sites_entity\n\t\t\t\t(guid, name, description, url) values ({$guid}, '{$name}', '{$description}', '{$url}')";
            $result = insert_data($query);
            if ($result !== false) {
                $entity = get_entity($guid);
                if (elgg_trigger_event('create', $entity->type, $entity)) {
                    return $guid;
                } else {
                    $entity->delete();
                    //delete_entity($guid);
                }
            }
        }
    }
    return false;
}
Example #11
0
/**
 * Custom annotations delete function because logged out users can't delete annotations
 *
 * @param array $annotations annotations to delete
 *
 * @return void
 */
function group_tools_delete_annotations($annotations)
{
    if (!empty($annotations) && is_array($annotations)) {
        $dbprefix = elgg_get_config("dbprefix");
        foreach ($annotations as $annotation) {
            if (elgg_trigger_event("delete", "annotation", $annotation)) {
                delete_data("DELETE from {$dbprefix}annotations where id=" . $annotation->id);
            }
        }
    }
}
/**
 * Update a specific piece of metadata.
 *
 * @param int    $id         ID of the metadata to update
 * @param string $name       Metadata name
 * @param string $value      Metadata value
 * @param string $value_type Value type
 * @param int    $owner_guid Owner guid
 * @param int    $access_id  Access ID
 *
 * @return bool
 */
function update_metadata($id, $name, $value, $value_type, $owner_guid, $access_id)
{
    global $CONFIG;
    $id = (int) $id;
    if (!($md = elgg_get_metadata_from_id($id))) {
        return false;
    }
    if (!$md->canEdit()) {
        return false;
    }
    // If memcached then we invalidate the cache for this entry
    static $metabyname_memcache;
    if (!$metabyname_memcache && is_memcache_available()) {
        $metabyname_memcache = new ElggMemcache('metabyname_memcache');
    }
    if ($metabyname_memcache) {
        // @todo fix memcache (name_id is not a property of ElggMetadata)
        $metabyname_memcache->delete("{$md->entity_guid}:{$md->name_id}");
    }
    $value_type = detect_extender_valuetype($value, sanitise_string(trim($value_type)));
    $owner_guid = (int) $owner_guid;
    if ($owner_guid == 0) {
        $owner_guid = elgg_get_logged_in_user_guid();
    }
    $access_id = (int) $access_id;
    // Support boolean types (as integers)
    if (is_bool($value)) {
        $value = (int) $value;
    }
    $value_id = elgg_get_metastring_id($value);
    if (!$value_id) {
        return false;
    }
    $name_id = elgg_get_metastring_id($name);
    if (!$name_id) {
        return false;
    }
    // If ok then add it
    $query = "UPDATE {$CONFIG->dbprefix}metadata" . " set name_id='{$name_id}', value_id='{$value_id}', value_type='{$value_type}', access_id={$access_id}," . " owner_guid={$owner_guid} where id={$id}";
    $result = update_data($query);
    if ($result !== false) {
        _elgg_get_metadata_cache()->save($md->entity_guid, $name, $value);
        // @todo this event tells you the metadata has been updated, but does not
        // let you do anything about it. What is needed is a plugin hook before
        // the update that passes old and new values.
        $obj = elgg_get_metadata_from_id($id);
        elgg_trigger_event('update', 'metadata', $obj);
    }
    return $result;
}
Example #13
0
/**
 * Log the current user out
 *
 * @return bool
 */
function logout()
{
    $session = _elgg_services()->session;
    $user = $session->getLoggedInUser();
    if (!$user) {
        return false;
    }
    // plugins can prevent a logout
    if (!elgg_trigger_event('logout', 'user', $user)) {
        return false;
    }
    // remove remember cookie
    if (isset($_COOKIE['elggperm'])) {
        _elgg_delete_remember_me_cookie(md5($_COOKIE['elggperm']));
        // tell browser to delete cookie
        $cookie = new ElggCookie("elggperm");
        $cookie->setExpiresTime("-30 days");
        $cookie->domain = "/";
        elgg_set_cookie($cookie);
    }
    // pass along any messages into new session
    $old_msg = $session->get('msg');
    $session->invalidate();
    $session->set('msg', $old_msg);
    return true;
}
Example #14
0
/**
 * Update an annotation.
 *
 * @param int    $annotation_id Annotation ID
 * @param string $name          Name of annotation
 * @param string $value         Value of annotation
 * @param string $value_type    Type of value
 * @param int    $owner_guid    Owner of annotation
 * @param int    $access_id     Access level of annotation
 *
 * @return bool
 */
function update_annotation($annotation_id, $name, $value, $value_type, $owner_guid, $access_id)
{
    global $CONFIG;
    $annotation_id = (int) $annotation_id;
    $annotation = elgg_get_annotation_from_id($annotation_id);
    if (!$annotation) {
        return false;
    }
    if (!$annotation->canEdit()) {
        return false;
    }
    $name = trim($name);
    $value_type = detect_extender_valuetype($value, $value_type);
    $owner_guid = (int) $owner_guid;
    if ($owner_guid == 0) {
        $owner_guid = elgg_get_logged_in_user_guid();
    }
    $access_id = (int) $access_id;
    $value_id = elgg_get_metastring_id($value);
    if (!$value_id) {
        return false;
    }
    $name_id = elgg_get_metastring_id($name);
    if (!$name_id) {
        return false;
    }
    $result = update_data("UPDATE {$CONFIG->dbprefix}annotations\n\t\tSET name_id = {$name_id}, value_id = {$value_id}, value_type = '{$value_type}',\n\t\taccess_id = {$access_id}, owner_guid = {$owner_guid}\n\t\tWHERE id = {$annotation_id}");
    if ($result !== false) {
        // @todo add plugin hook that sends old and new annotation information before db access
        $obj = elgg_get_annotation_from_id($annotation_id);
        elgg_trigger_event('update', 'annotation', $obj);
    }
    return $result;
}
Example #15
0
File: elgglib.php Project: n8b/VMN
/**
 * Emits a shutdown:system event upon PHP shutdown, but before database connections are dropped.
 *
 * @tip Register for the shutdown:system event to perform functions at the end of page loads.
 *
 * @warning Using this event to perform long-running functions is not very
 * useful.  Servers will hold pages until processing is done before sending
 * them out to the browser.
 *
 * @see http://www.php.net/register-shutdown-function
 *
 * @return void
 * @see register_shutdown_hook()
 * @access private
 */
function _elgg_shutdown_hook()
{
    global $START_MICROTIME;
    try {
        elgg_trigger_event('shutdown', 'system');
        $time = (double) (microtime(true) - $START_MICROTIME);
        $uri = _elgg_services()->request->server->get('REQUEST_URI', 'CLI');
        // demoted to NOTICE from DEBUG so javascript is not corrupted
        elgg_log("Page {$uri} generated in {$time} seconds", 'INFO');
    } catch (Exception $e) {
        $message = 'Error: ' . get_class($e) . ' thrown within the shutdown handler. ';
        $message .= "Message: '{$e->getMessage()}' in file {$e->getFile()} (line {$e->getLine()})";
        error_log($message);
        error_log("Exception trace stack: {$e->getTraceAsString()}");
    }
    // Prevent an APC session bug: https://bugs.php.net/bug.php?id=60657
    session_write_close();
}
<?php

$params = new ElggObject();
elgg_trigger_event('test', 'example', $params);
// handlers would be registered by saying
elgg_register_event_handler('test', 'example', 'example_event_handler');
Example #17
0
File: start.php Project: risho/Elgg
// confirm that the installation completed successfully
verify_installation();
// Autodetect some default configuration settings
set_default_config();
// needs to be set for links in html head
$viewtype = get_input('view', 'default');
$lastcached = datalist_get("simplecache_lastcached_{$viewtype}");
$CONFIG->lastcache = $lastcached;
// Trigger boot events for core. Plugins can't hook
// into this because they haven't been loaded yet.
elgg_trigger_event('boot', 'system');
// Load the plugins that are active
elgg_load_plugins();
elgg_trigger_event('plugins_boot', 'system');
// Trigger system init event for plugins
elgg_trigger_event('init', 'system');
// 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;
}
// System loaded and ready
elgg_trigger_event('ready', 'system');
Example #18
0
 /**
  * Load remaining engine libraries and complete bootstraping (see start.php)
  *
  * @param string $step Which step to boot strap for. Required because
  *                     boot strapping is different until the DB is populated.
  *
  * @return void
  */
 protected function finishBootstraping($step)
 {
     $dbIndex = array_search('database', $this->getSteps());
     $settingsIndex = array_search('settings', $this->getSteps());
     $adminIndex = array_search('admin', $this->getSteps());
     $completeIndex = array_search('complete', $this->getSteps());
     $stepIndex = array_search($step, $this->getSteps());
     // To log in the user, we need to use the Elgg core session handling.
     // Otherwise, use default php session handling
     $useElggSession = $stepIndex == $adminIndex && $this->isAction || $stepIndex == $completeIndex;
     if (!$useElggSession) {
         session_name('Elgg_install');
         session_start();
         elgg_unregister_event_handler('boot', 'system', 'session_init');
     }
     if ($stepIndex > $dbIndex) {
         // once the database has been created, load rest of engine
         global $CONFIG;
         $lib_dir = $CONFIG->path . 'engine/lib/';
         $this->loadSettingsFile();
         $lib_files = array('database.php', 'actions.php', 'admin.php', 'annotations.php', 'cron.php', 'entities.php', 'extender.php', 'filestore.php', 'group.php', 'location.php', 'mb_wrapper.php', 'memcache.php', 'metadata.php', 'metastrings.php', 'navigation.php', 'notification.php', 'objects.php', 'opendd.php', 'pagehandler.php', 'pam.php', 'plugins.php', 'private_settings.php', 'relationships.php', 'river.php', 'sites.php', 'statistics.php', 'tags.php', 'user_settings.php', 'users.php', 'upgrade.php', 'web_services.php', 'widgets.php', 'xml.php', 'deprecated-1.7.php', 'deprecated-1.8.php', 'deprecated-1.9.php');
         foreach ($lib_files as $file) {
             $path = $lib_dir . $file;
             if (!(include_once $path)) {
                 $msg = elgg_echo('InstallationException:MissingLibrary', array($file));
                 throw new InstallationException($msg);
             }
         }
         setup_db_connections();
         register_translations(dirname(dirname(__FILE__)) . "/languages/");
         if ($stepIndex > $settingsIndex) {
             $CONFIG->site_guid = (int) datalist_get('default_site');
             $CONFIG->site_id = $CONFIG->site_guid;
             $CONFIG->site = get_entity($CONFIG->site_guid);
             $CONFIG->dataroot = datalist_get('dataroot');
             _elgg_session_boot(NULL, NULL, NULL);
         }
         elgg_trigger_event('init', 'system');
     }
 }
Example #19
0
/**
 * System log listener.
 * This function listens to all events in the system and logs anything appropriate.
 *
 * @param String   $event       Event name
 * @param String   $object_type Type of object
 * @param Loggable $object      Object to log
 *
 * @return true
 * @access private
 */
function system_log_listener($event, $object_type, $object)
{
    if ($object_type != 'systemlog' && $event != 'log') {
        elgg_trigger_event('log', 'systemlog', array('object' => $object, 'event' => $event));
    }
    return true;
}
Example #20
0
/**
 * Delete an entity.
 *
 * Removes an entity and its metadata, annotations, relationships, river entries,
 * and private data.
 *
 * Optionally can remove entities contained and owned by $guid.
 *
 * @tip Use ElggEntity::delete() instead.
 *
 * @warning If deleting recursively, this bypasses ownership of items contained by
 * the entity.  That means that if the container_guid = $guid, the item will be deleted
 * regardless of who owns it.
 *
 * @param int  $guid      The guid of the entity to delete
 * @param bool $recursive If true (default) then all entities which are
 *                        owned or contained by $guid will also be deleted.
 *
 * @return bool
 * @access private
 */
function delete_entity($guid, $recursive = true)
{
    global $CONFIG, $ENTITY_CACHE;
    $guid = (int) $guid;
    if ($entity = get_entity($guid)) {
        if (elgg_trigger_event('delete', $entity->type, $entity)) {
            if ($entity->canEdit()) {
                // delete cache
                if (isset($ENTITY_CACHE[$guid])) {
                    invalidate_cache_for_entity($guid);
                }
                // If memcache is available then delete this entry from the cache
                static $newentity_cache;
                if (!$newentity_cache && is_memcache_available()) {
                    $newentity_cache = new ElggMemcache('new_entity_cache');
                }
                if ($newentity_cache) {
                    $newentity_cache->delete($guid);
                }
                // Delete contained owned and otherwise releated objects (depth first)
                if ($recursive) {
                    // Temporary token overriding access controls
                    // @todo Do this better.
                    static $__RECURSIVE_DELETE_TOKEN;
                    // Make it slightly harder to guess
                    $__RECURSIVE_DELETE_TOKEN = md5(elgg_get_logged_in_user_guid());
                    $entity_disable_override = access_get_show_hidden_status();
                    access_show_hidden_entities(true);
                    $ia = elgg_set_ignore_access(true);
                    $sub_entities = get_data("SELECT * from {$CONFIG->dbprefix}entities\n\t\t\t\t\t\tWHERE container_guid={$guid}\n\t\t\t\t\t\t\tor owner_guid={$guid}\n\t\t\t\t\t\t\tor site_guid={$guid}", 'entity_row_to_elggstar');
                    if ($sub_entities) {
                        foreach ($sub_entities as $e) {
                            // check for equality so that an entity that is its own
                            // owner or container does not cause infinite loop
                            if ($e->guid != $guid) {
                                $e->delete(true);
                            }
                        }
                    }
                    access_show_hidden_entities($entity_disable_override);
                    $__RECURSIVE_DELETE_TOKEN = null;
                    elgg_set_ignore_access($ia);
                }
                // Now delete the entity itself
                $entity->deleteMetadata();
                $entity->deleteOwnedMetadata();
                $entity->deleteAnnotations();
                $entity->deleteOwnedAnnotations();
                $entity->deleteRelationships();
                elgg_delete_river(array('subject_guid' => $guid));
                elgg_delete_river(array('object_guid' => $guid));
                remove_all_private_settings($guid);
                $res = delete_data("DELETE from {$CONFIG->dbprefix}entities where guid={$guid}");
                if ($res) {
                    $sub_table = "";
                    // Where appropriate delete the sub table
                    switch ($entity->type) {
                        case 'object':
                            $sub_table = $CONFIG->dbprefix . 'objects_entity';
                            break;
                        case 'user':
                            $sub_table = $CONFIG->dbprefix . 'users_entity';
                            break;
                        case 'group':
                            $sub_table = $CONFIG->dbprefix . 'groups_entity';
                            break;
                        case 'site':
                            $sub_table = $CONFIG->dbprefix . 'sites_entity';
                            break;
                    }
                    if ($sub_table) {
                        delete_data("DELETE from {$sub_table} where guid={$guid}");
                    }
                }
                return $res;
            }
        }
    }
    return false;
}
Example #21
0
/**
 * Update the user profile with the LinkedIn profile image
 *
 * @param int $user_guid the user_guid to update
 *
 * @return bool
 */
function socialink_linkedin_sync_profile_icon($user_guid = 0)
{
    $result = false;
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    if (($user = get_user($user_guid)) && socialink_linkedin_is_connected($user_guid)) {
        if ($api_result = socialink_linkedin_get_profile_information($user_guid)) {
            $api_result = json_decode($api_result);
            if ($icon_url = $api_result->pictureUrl) {
                if (file_get_contents($icon_url)) {
                    $icon_sizes = elgg_get_config("icon_sizes");
                    if (!empty($icon_sizes)) {
                        $fh = new ElggFile();
                        $fh->owner_guid = $user->getGUID();
                        foreach ($icon_sizes as $name => $properties) {
                            $resize = get_resized_image_from_existing_file($icon_url, $properties["w"], $properties["h"], $properties["square"], 0, 0, 0, 0, $properties["upscale"]);
                            if (!empty($resize)) {
                                $fh->setFilename("profile/" . $user->getGUID() . $name . ".jpg");
                                $fh->open("write");
                                $fh->write($resize);
                                $fh->close();
                                $result = true;
                            }
                        }
                    }
                    if (!empty($result)) {
                        $user->icontime = time();
                        // trigger event to let others know the icon was updated
                        elgg_trigger_event("profileiconupdate", $user->type, $user);
                    }
                }
            }
        }
    }
    return $result;
}
Example #22
0
/**
 * Log the current user out
 *
 * @return bool
 */
function logout()
{
    global $CONFIG;
    if (isset($_SESSION['user'])) {
        if (!elgg_trigger_event('logout', 'user', $_SESSION['user'])) {
            return false;
        }
        $_SESSION['user']->code = "";
        $_SESSION['user']->save();
    }
    unset($_SESSION['username']);
    unset($_SESSION['name']);
    unset($_SESSION['code']);
    unset($_SESSION['guid']);
    unset($_SESSION['id']);
    unset($_SESSION['user']);
    setcookie("elggperm", "", time() - 86400 * 30, "/");
    // pass along any messages
    $old_msg = $_SESSION['msg'];
    session_destroy();
    // starting a default session to store any post-logout messages.
    session_init(NULL, NULL, NULL);
    $_SESSION['msg'] = $old_msg;
    return TRUE;
}
Example #23
0
 $blog->deleteAnnotations('blog_auto_save');
 // no longer a brand new post.
 $blog->deleteMetadata('new_post');
 // if this was an edit, create a revision annotation
 if (!$new_post && $revision_text) {
     $blog->annotate('blog_revision', $revision_text);
 }
 system_message(elgg_echo('blog:message:saved'));
 $status = $blog->status;
 // add to river if changing status or published, regardless of new post
 // because we remove it for drafts.
 if (($new_post || $old_status == 'draft') && $status == 'published') {
     add_to_river('river/object/blog/create', 'create', $blog->owner_guid, $blog->getGUID());
     // we only want notifications sent when post published
     register_notification_object('object', 'blog', elgg_echo('blog:newpost'));
     elgg_trigger_event('publish', 'object', $blog);
     // reset the creation time for posts that move from draft to published
     if ($guid) {
         $blog->time_created = time();
         $blog->save();
     }
 } elseif ($old_status == 'published' && $status == 'draft') {
     elgg_delete_river(array('object_guid' => $blog->guid, 'action_type' => 'create'));
 }
 //Khang Added
 forward(REFERER);
 if ($blog->status == 'published' || $save == false) {
     forward($blog->getURL());
 } else {
     forward("blog/edit/{$blog->guid}");
 }
Example #24
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 #25
0
/**
 * Delete a relationship between two entities.
 *
 * This function lets you say "$guid_one is no longer a $relationship of $guid_two."
 *
 * @param int    $guid_one     GUID of the subject entity of the relationship
 * @param string $relationship Type of the relationship
 * @param int    $guid_two     GUID of the target entity of the relationship
 *
 * @return bool
 */
function remove_entity_relationship($guid_one, $relationship, $guid_two)
{
    global $CONFIG;
    $guid_one = (int) $guid_one;
    $relationship = sanitise_string($relationship);
    $guid_two = (int) $guid_two;
    $obj = check_entity_relationship($guid_one, $relationship, $guid_two);
    if ($obj == false) {
        return false;
    }
    // this event has been deprecated in 1.9. Use 'delete', 'relationship'
    $result_old = elgg_trigger_event('delete', $relationship, $obj);
    $result = elgg_trigger_event('delete', 'relationship', $obj);
    if ($result && $result_old) {
        $query = "DELETE FROM {$CONFIG->dbprefix}entity_relationships\n\t\t\tWHERE guid_one = {$guid_one}\n\t\t\tAND relationship = '{$relationship}'\n\t\t\tAND guid_two = {$guid_two}";
        return (bool) delete_data($query);
    } else {
        return false;
    }
}
Example #26
0
/**
 * Adds an item to the river.
 *
 * @tip Read the item like "Lisa (subject) posted (action)
 * a comment (object) on John's blog (target)".
 *
 * @param array $options Array in format:
 *
 * 	view => STR The view that will handle the river item (must exist)
 *
 * 	action_type => STR An arbitrary string to define the action (eg 'comment', 'create')
 *
 *  subject_guid => INT The GUID of the entity doing the action
 *
 *  object_guid => INT The GUID of the entity being acted upon
 *
 *  target_guid => INT The GUID of the the object entity's container
 *
 *  access_id => INT The access ID of the river item (default: same as the object)
 *
 *  posted => INT The UNIX epoch timestamp of the river item (default: now)
 *
 *  annotation_id INT The annotation ID associated with this river entry
 *
 * @return int|bool River ID or false on failure
 * @since 1.9
 */
function elgg_create_river_item(array $options = array())
{
    $view = elgg_extract('view', $options);
    // use default viewtype for when called from web services api
    if (empty($view) || !elgg_view_exists($view, 'default')) {
        return false;
    }
    $action_type = elgg_extract('action_type', $options);
    if (empty($action_type)) {
        return false;
    }
    $subject_guid = elgg_extract('subject_guid', $options, 0);
    if (!($subject = get_entity($subject_guid))) {
        return false;
    }
    $object_guid = elgg_extract('object_guid', $options, 0);
    if (!($object = get_entity($object_guid))) {
        return false;
    }
    $target_guid = elgg_extract('target_guid', $options, 0);
    if ($target_guid) {
        // target_guid is not a required parameter so check
        // it only if it is included in the parameters
        if (!($target = get_entity($target_guid))) {
            return false;
        }
    }
    $access_id = elgg_extract('access_id', $options, $object->access_id);
    $posted = elgg_extract('posted', $options, time());
    $annotation_id = elgg_extract('annotation_id', $options, 0);
    if ($annotation_id) {
        if (!elgg_get_annotation_from_id($annotation_id)) {
            return false;
        }
    }
    $values = array('type' => $object->getType(), 'subtype' => $object->getSubtype(), 'action_type' => $action_type, 'access_id' => $access_id, 'view' => $view, 'subject_guid' => $subject_guid, 'object_guid' => $object_guid, 'target_guid' => $target_guid, 'annotation_id' => $annotation_id, 'posted' => $posted);
    $col_types = array('type' => 'string', 'subtype' => 'string', 'action_type' => 'string', 'access_id' => 'int', 'view' => 'string', 'subject_guid' => 'int', 'object_guid' => 'int', 'target_guid' => 'int', 'annotation_id' => 'int', 'posted' => 'int');
    // return false to stop insert
    $values = elgg_trigger_plugin_hook('creating', 'river', null, $values);
    if ($values == false) {
        // inserting did not fail - it was just prevented
        return true;
    }
    $dbprefix = elgg_get_config('dbprefix');
    // escape values array and build INSERT assignments
    $assignments = array();
    foreach ($col_types as $name => $type) {
        $values[$name] = $type === 'int' ? (int) $values[$name] : sanitize_string($values[$name]);
        $assignments[] = "{$name} = '{$values[$name]}'";
    }
    $id = insert_data("INSERT INTO {$dbprefix}river SET " . implode(',', $assignments));
    // update the entities which had the action carried out on it
    // @todo shouldn't this be done elsewhere? Like when an annotation is saved?
    if ($id) {
        update_entity_last_action($values['object_guid'], $values['posted']);
        $river_items = elgg_get_river(array('id' => $id));
        if ($river_items) {
            elgg_trigger_event('created', 'river', $river_items[0]);
        }
        return $id;
    } else {
        return false;
    }
}
Example #27
0
/**
 * Alias function for events, that triggers a particular kind of event
 *
 * @deprecated 1.8 Use elgg_trigger_event() instead
 * 
 * @param string $event The event type
 * @param string $object_type The object type
 * @param string $function The function name
 * @return true|false Depending on success
 */
function trigger_elgg_event($event, $object_type, $object = null)
{
    elgg_deprecated_notice('trigger_elgg_event() was deprecated by elgg_trigger_event()', 1.8);
    return elgg_trigger_event($event, $object_type, $object);
}
/**
 * Remove an arbitrary relationship between two entities.
 *
 * @param int    $guid_one     First GUID
 * @param string $relationship Relationship name
 * @param int    $guid_two     Second GUID
 *
 * @return bool
 */
function remove_entity_relationship($guid_one, $relationship, $guid_two)
{
    global $CONFIG;
    $guid_one = (int) $guid_one;
    $relationship = sanitise_string($relationship);
    $guid_two = (int) $guid_two;
    $obj = check_entity_relationship($guid_one, $relationship, $guid_two);
    if ($obj == false) {
        return false;
    }
    if (elgg_trigger_event('delete', $relationship, $obj)) {
        $query = "DELETE from {$CONFIG->dbprefix}entity_relationships\n\t\t\twhere guid_one={$guid_one}\n\t\t\tand relationship='{$relationship}'\n\t\t\tand guid_two={$guid_two}";
        return (bool) delete_data($query);
    } else {
        return false;
    }
}
Example #29
0
/**
 * Emits a shutdown:system event upon PHP shutdown, but before database connections are dropped.
 *
 * @tip Register for the shutdown:system event to perform functions at the end of page loads.
 *
 * @warning Using this event to perform long-running functions is not very
 * useful.  Servers will hold pages until processing is done before sending
 * them out to the browser.
 *
 * @see http://www.php.net/register-shutdown-function
 *
 * @return void
 * @see register_shutdown_hook()
 * @access private
 */
function _elgg_shutdown_hook()
{
    global $START_MICROTIME;
    try {
        elgg_trigger_event('shutdown', 'system');
        $time = (double) (microtime(TRUE) - $START_MICROTIME);
        // demoted to NOTICE from DEBUG so javascript is not corrupted
        elgg_log("Page {$_SERVER['REQUEST_URI']} generated in {$time} seconds", 'NOTICE');
    } catch (Exception $e) {
        $message = 'Error: ' . get_class($e) . ' thrown within the shutdown handler. ';
        $message .= "Message: '{$e->getMessage()}' in file {$e->getFile()} (line {$e->getLine()})";
        error_log($message);
        error_log("Exception trace stack: {$e->getTraceAsString()}");
    }
}
Example #30
0
    }
}
$publication->access_id = $access;
$publication->title = $title;
if (!$publication->save()) {
    register_error(elgg_echo('publication:error'));
    forward(REFERER);
}
$publication->tags = $tags;
$publication->pubtype = $type;
// save custom data
foreach ($data as $key => $value) {
    $publication->{$key} = $value;
}
// trigger event to save other custom data
elgg_trigger_event('save:data', 'publications', $publication);
// files
$file_contents = get_uploaded_file('attachment');
if (!empty($file_contents)) {
    $fh = new ElggFile();
    $fh->owner_guid = $publication->getGUID();
    $file_name = $_FILES['attachment']['name'];
    $mime = $_FILES['attachment']['type'];
    $fh->setFilename($file_name);
    if ($fh->open('write')) {
        $fh->write($file_contents);
        $fh->close();
        $publication->attached_file = $file_name;
        $publication->attached_file_mime_type = $mime;
    }
}