Author: Curverider Ltd (info@elgg.com)
Inheritance: implements Notable, implements Locatable, implements Exportable, implements Importable, implements Loggable, implements Iterator, implements ArrayAccess
/**
 * Checks if the given $entity is registered for notifications by
 * register_notification_object()
 *
 * @param ElggEntity $entity  the entity to check
 * @param bool       $subject return the subject string (default=false)
 *
 * @return bool|string
 */
function advanced_notifications_is_registered_notification_entity(ElggEntity $entity, $subject = false)
{
    $result = false;
    if (!empty($entity) && $entity instanceof ElggEntity) {
        $type = $entity->getType();
        if (empty($type)) {
            $type = "__BLANK__";
        }
        $subtype = $entity->getSubtype();
        if (empty($subtype)) {
            $subtype = "__BLANK__";
        }
        // get the registered entity -> type/subtype
        $notifications = elgg_get_config("register_objects");
        if (!empty($notifications) && is_array($notifications)) {
            if (isset($notifications[$type]) && isset($notifications[$type][$subtype])) {
                if ($subject) {
                    $result = $notifications[$type][$subtype];
                } else {
                    $result = true;
                }
            }
        }
    }
    return $result;
}
Exemple #2
0
/**
 * Register the navigation menu
 * 
 * @param ElggEntity $container Container entity for the pages
 */
function pages_register_navigation_tree($container)
{
    if (!$container) {
        return;
    }
    $top_pages = elgg_get_entities(array('type' => 'object', 'subtype' => 'page_top', 'container_guid' => $container->getGUID(), 'limit' => 0));
    if (!$top_pages) {
        return;
    }
    foreach ($top_pages as $page) {
        elgg_register_menu_item('pages_nav', array('name' => $page->getGUID(), 'text' => $page->title, 'href' => $page->getURL()));
        $stack = array();
        array_push($stack, $page);
        while (count($stack) > 0) {
            $parent = array_pop($stack);
            $children = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'page', 'metadata_name' => 'parent_guid', 'metadata_value' => $parent->getGUID(), 'limit' => 0));
            if ($children) {
                foreach ($children as $child) {
                    elgg_register_menu_item('pages_nav', array('name' => $child->getGUID(), 'text' => $child->title, 'href' => $child->getURL(), 'parent_name' => $parent->getGUID()));
                    array_push($stack, $child);
                }
            }
        }
    }
}
Exemple #3
0
/**
 * This function checks if the questions workflow is enabled in the plugin settings and for the given container
 *
 * @return bool true is enabled, false otherwise
 */
function questions_workflow_enabled(ElggEntity $container = null)
{
    if ($container && $container instanceof ElggGroup) {
        return $container->getPrivateSetting('questions_workflow_enabled') == "yes";
    }
    return elgg_get_plugin_setting("workflow_enabled", "questions") == "yes";
}
Exemple #4
0
/**
 * Produce the navigation tree
 * 
 * @param ElggEntity $container Container entity for the pages
 *
 * @return array
 */
function pages_get_navigation_tree($container)
{
    if (!$container) {
        return;
    }
    $top_pages = elgg_get_entities(array('type' => 'object', 'subtype' => 'page_top', 'container_guid' => $container->getGUID(), 'limit' => 0));
    if (!$top_pages) {
        return;
    }
    /* @var ElggObject[] $top_pages */
    $tree = array();
    $depths = array();
    foreach ($top_pages as $page) {
        $tree[] = array('guid' => $page->getGUID(), 'title' => $page->title, 'url' => $page->getURL(), 'depth' => 0);
        $depths[$page->guid] = 0;
        $stack = array();
        array_push($stack, $page);
        while (count($stack) > 0) {
            $parent = array_pop($stack);
            $children = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'page', 'metadata_name' => 'parent_guid', 'metadata_value' => $parent->getGUID(), 'limit' => 0));
            if ($children) {
                foreach ($children as $child) {
                    $tree[] = array('guid' => $child->getGUID(), 'title' => $child->title, 'url' => $child->getURL(), 'parent_guid' => $parent->getGUID(), 'depth' => $depths[$parent->guid] + 1);
                    $depths[$child->guid] = $depths[$parent->guid] + 1;
                    array_push($stack, $child);
                }
            }
        }
    }
    return $tree;
}
Exemple #5
0
 /**
  * Check if resharing of this entity is allowed
  *
  * @param \ElggEntity $entity the entity to check
  *
  * @return bool
  */
 protected static function canReshareEntity(\ElggEntity $entity)
 {
     if (!$entity instanceof \ElggEntity) {
         return false;
     }
     // only allow objects and groups
     if (!$entity instanceof \ElggObject && !$entity instanceof \ElggGroup) {
         return false;
     }
     // comments and discussion replies are never allowed
     $blocked_subtypes = ['comment', 'discussion_reply'];
     if (in_array($entity->getSubtype(), $blocked_subtypes)) {
         return false;
     }
     // by default allow searchable entities
     $reshare_allowed = false;
     if ($entity instanceof \ElggGroup) {
         $reshare_allowed = true;
     } else {
         $searchable_entities = get_registered_entity_types($entity->getType());
         if (!empty($searchable_entities)) {
             $reshare_allowed = in_array($entity->getSubtype(), $searchable_entities);
         }
     }
     // trigger hook to allow others to change
     $params = ['entity' => $entity, 'user' => elgg_get_logged_in_user_entity()];
     return (bool) elgg_trigger_plugin_hook('reshare', $entity->getType(), $params, $reshare_allowed);
 }
/**
 * Check if entity type is registered for feature/unfeature
 *
 * @param ElggEntity $entity Entity to be featured
 * @return bool
 */
function actions_feature_is_allowed_type(ElggEntity $entity)
{
    $type = $entity->getType();
    $subtype = $entity->getSubtype();
    $hook_type = implode(':', array_filter([$type, $subtype]));
    return elgg_trigger_plugin_hook('feature', $hook_type, ['entity' => $entity], false);
}
Exemple #7
0
 /**
  * listen to the remove admin event to unset the toggle admin flag
  *
  * @param string     $event  the event
  * @param string     $type   the type of the event
  * @param ElggEntity $entity the affected entity
  *
  * @return void
  */
 public static function removeAdmin($event, $type, $entity)
 {
     if (!$entity instanceof \ElggUser) {
         return;
     }
     elgg_unset_plugin_user_setting('switched_admin', $entity->getGUID(), 'admin_tools');
 }
Exemple #8
0
/**
 * Utility function used by import_extender_plugin_hook() to process
 * an ODDMetaData and add it to an entity. This function does not
 * hit ->save() on the entity (this lets you construct in memory)
 *
 * @param ElggEntity  $entity  The entity to add the data to.
 * @param ODDMetaData $element The OpenDD element
 *
 * @return bool
 * @access private
 */
function oddmetadata_to_elggextender(ElggEntity $entity, ODDMetaData $element)
{
    // Get the type of extender (metadata, type, attribute etc)
    $type = $element->getAttribute('type');
    $attr_name = $element->getAttribute('name');
    $attr_val = $element->getBody();
    switch ($type) {
        // Ignore volatile items
        case 'volatile':
            break;
        case 'annotation':
            $entity->annotate($attr_name, $attr_val);
            break;
        case 'metadata':
            $entity->setMetaData($attr_name, $attr_val, "", true);
            break;
        default:
            // Anything else assume attribute
            $entity->set($attr_name, $attr_val);
    }
    // Set time if appropriate
    $attr_time = $element->getAttribute('published');
    if ($attr_time) {
        $entity->set('time_updated', $attr_time);
    }
    return true;
}
Exemple #9
0
/**
 * Custom URL handler for thewire objects
 *
 * @param ElggEntity $entity the entity to make the URL for
 *
 * @return string the URL
 */
function thewire_tools_url_handler(ElggEntity $entity)
{
    if ($entity->getContainerEntity() instanceof ElggGroup) {
        $entity_url = elgg_get_site_url() . "thewire/group/" . $entity->getContainer();
    } else {
        $entity_url = elgg_get_site_url() . "thewire/owner/" . $entity->getOwnerEntity()->username;
    }
    return $entity_url;
}
Exemple #10
0
 /**
  * Map column headers to a proper representation in the row cell
  * @param ElggEntity $entity
  * @param boolean $csv
  * @return array
  */
 public function getRowCells($entity)
 {
     $row = array();
     $headers = $this->getColumnHeaders();
     foreach ($headers as $header => $label) {
         $value = '';
         switch ($header) {
             default:
                 $value = $entity->{$header};
                 if (is_array($value)) {
                     $value = implode('; ', $value);
                 }
                 break;
             case 'guid':
                 $value = $entity->guid;
                 break;
             case 'icon':
                 $value = $entity->getIconURL();
                 if (!elgg_in_context('plaintext')) {
                     $value = elgg_view_entity_icon($entity, 'small');
                 }
                 break;
             case 'title':
                 $value = elgg_instanceof($entity, 'object') ? $entity->title : $entity->name;
                 if (!elgg_in_context('plaintext')) {
                     $value = elgg_view('output/url', array('text' => $value, 'href' => $entity->getURL()));
                 }
                 break;
             case 'time_created':
                 $value = date('M d, Y H:i', $entity->time_created);
                 break;
             case 'owner_guid':
                 $value = '';
                 $owner = $entity->getOwnerEntity();
                 if (elgg_instanceof($owner)) {
                     $value = $owner->guid;
                     if (!elgg_in_context('plaintext')) {
                         $value = elgg_view('output/url', array('text' => elgg_instanceof($owner, 'object') ? $owner->title : $owner->name, 'href' => $owner->getURL()));
                     }
                 }
                 break;
             case 'container_guid':
                 $value = '';
                 $container = $entity->getContainerEntity();
                 if (elgg_instanceof($container)) {
                     $value = $container->guid;
                     if (!elgg_in_context('plaintext')) {
                         $value = elgg_view('output/url', array('text' => elgg_instanceof($container, 'object') ? $container->title : $container->name, 'href' => $container->getURL()));
                     }
                 }
                 break;
         }
         $row[$header] = $value;
     }
     return elgg_trigger_plugin_hook('export:entity', 'table', array('headers' => $this->getColumnHeaders(), 'entity' => $entity), $row);
 }
 /**
  * Creates random annotations on $entity
  *
  * @param \ElggEntity $entity
  * @param int        $max
  */
 protected function createRandomAnnotations($entity, $max = 1)
 {
     $annotations = array();
     for ($i = 0; $i < $max; $i++) {
         $name = 'test_annotation_name_' . rand();
         $value = rand();
         $id = create_annotation($entity->getGUID(), $name, $value, 'integer', $entity->getGUID());
         $annotations[] = elgg_get_annotation_from_id($id);
     }
     return $annotations;
 }
 /**
  * @param \ElggEntity $entity
  * @return bool|notification
  */
 public function Build($entity)
 {
     switch ($entity->getSubtype()) {
         case 'sub_comment_notification':
             return new \WizmassNotifier\Notifications\SubCommentNotification($entity);
         case 'rate_comment_notification':
             return new \WizmassNotifier\Notifications\RateCommentNotification($entity);
         default:
             return false;
     }
 }
Exemple #13
0
 /**
  * Get guids from an entity attribute
  *
  * @param ElggEntity|int $entity Entity or GUID
  * @return int
  */
 protected function toGUID($entity = null)
 {
     if ($entity instanceof ElggEntity) {
         return (int) $entity->getGUID();
     } else {
         if ($this->exists($entity)) {
             return (int) $entity;
         }
     }
     return false;
 }
Exemple #14
0
/**
 * Count how many people have liked an entity.
 *
 * @param  ElggEntity $entity 
 *
 * @return int Number of likes
 */
function likes_count($entity)
{
    $type = $entity->getType();
    $params = array('entity' => $entity);
    $number = elgg_trigger_plugin_hook('likes:count', $type, $params, false);
    if ($number) {
        return $number;
    } else {
        return $entity->countAnnotations('likes');
    }
}
Exemple #15
0
/**
 * Set priority of an element in a list
 *
 * @see ElggEntity::$priority
 *
 * @param ElggEntity $entity
 * @return bool
 */
function hj_framework_set_entity_priority($entity, $priority = null)
{
    if ($priority) {
        $entity->priority = $priority;
        return true;
    }
    $count = elgg_get_entities(array('type' => $entity->getType(), 'subtype' => $entity->getSubtype(), 'owner_guid' => $entity->owner_guid, 'container_guid' => $entity->container_guid, 'count' => true));
    if (!$entity->priority) {
        $entity->priority = $count + 1;
    }
    return true;
}
Exemple #16
0
 public function testCanEdit()
 {
     $user = new \ElggUser();
     $user->save();
     $id = $this->entity->annotate('test', 'foo', ACCESS_LOGGED_IN, elgg_get_logged_in_user_guid());
     $a = elgg_get_annotation_from_id($id);
     $this->assertTrue($a->canEdit());
     $this->assertFalse($a->canEdit($user->guid));
     $id = $this->entity->annotate('test', 'foo2', ACCESS_LOGGED_IN, $user->guid);
     $a = elgg_get_annotation_from_id($id);
     $this->assertTrue($a->canEdit());
     $this->assertTrue($a->canEdit($user->guid));
     $user->delete();
 }
Exemple #17
0
 /**
  * After an entity is done with ->save() check if we need to enqueue it
  *
  * @param string      $event  the name of the event
  * @param string      $type   the type of the event
  * @param \ElggEntity $entity supplied param
  *
  * @return void
  */
 public static function afterEntityUpdate($event, $type, $entity)
 {
     if (!$entity instanceof \ElggEntity) {
         // not an entity, since we listen to 'all'
         return;
     }
     if (!isset($entity->tags)) {
         // no tags
         return;
     }
     if (!self::validateEntity($entity->getGUID())) {
         return;
     }
     self::enqueueEntity($entity->getGUID());
 }
Exemple #18
0
/**
 * Checks if there are new slots available after updating an event
 *
 * @param string     $event  name of the event
 * @param string     $type   type of the event
 * @param ElggEntity $object object related to the event
 *
 * @return void
 */
function event_manager_update_object_handler($event, $type, $object)
{
    if (!empty($object) && $object instanceof Event) {
        $fillup = false;
        if ($object->with_program && $object->hasSlotSpotsLeft()) {
            $fillup = true;
        } elseif (!$object->with_program && $object->hasEventSpotsLeft()) {
            $fillup = true;
        }
        if ($fillup) {
            while ($object->generateNewAttendee()) {
                continue;
            }
        }
    }
}
 /**
  * {@inheritdoc}
  */
 public function getValues(\ElggEntity $entity)
 {
     $sticky = $this->getStickyValue();
     if ($sticky) {
         return $sticky;
     }
     $name = $this->getShortname();
     switch ($name) {
         default:
             return $entity->{$name} ?: $this->getDefaultValue();
         case 'type':
             return $entity->getType();
         case 'subtype':
             return $entity->getSubtype();
     }
 }
Exemple #20
0
 public function testLatLong()
 {
     // Coordinates for Elgg, Switzerland
     $lat = 47.483333;
     $long = 8.866667;
     $this->obj->setLatLong($lat, $long);
     $this->assertEquals($this->obj->getLatitude(), $lat);
     $this->assertEquals($this->obj->getLongitude(), $long);
 }
Exemple #21
0
function evan_user_can($verb, Entity $object, Entity $target = NULL)
{
    switch ($verb) {
        case 'post':
            if (!$target) {
                $target = elgg_get_logged_in_user_entity();
            }
            $result = $target->canWriteToContainer(0, $object->getType(), $object->getSubtype());
            break;
        case 'update':
            $result = $object->canEdit();
            break;
        default:
            $result = false;
            break;
    }
    return elgg_trigger_plugin_hook("permission", $verb, array('actor' => elgg_get_logged_in_user_entity(), 'verb' => $verb, 'object' => $object, 'target' => $target), $result);
}
Exemple #22
0
 /**
  * @requires PHP 5.3.2
  */
 public function testToObject()
 {
     $keys = array('guid', 'type', 'subtype', 'time_created', 'time_updated', 'container_guid', 'owner_guid', 'site_guid', 'url', 'read_access');
     sort($keys);
     $object = $this->obj->toObject();
     $object_keys = array_keys(get_object_vars($object));
     sort($object_keys);
     $this->assertEquals($keys, $object_keys);
 }
Exemple #23
0
 /**
  * Track certain events on ElggEntity's
  *
  * @param string      $event  the event
  * @param string      $type   the type of the ElggEntity
  * @param \ElggEntity $object the entity for the event
  *
  * @return void
  */
 public static function events($event, $type, $object)
 {
     if (!$object instanceof \ElggEntity) {
         return;
     }
     if (!analytics_google_track_events_enabled()) {
         return;
     }
     switch ($object->getType()) {
         case 'object':
             analytics_track_event($object->getSubtype(), $event, $object->title);
             break;
         case 'group':
         case 'user':
             analytics_track_event($object->getType(), $event, $object->name);
             break;
     }
 }
Exemple #24
0
 /**
  * Create a notification event
  *
  * @param \ElggData   $object The object of the event (\ElggEntity)
  * @param string      $action The name of the action (default: create)
  * @param \ElggEntity $actor  The entity that caused the event (default: logged in user)
  * 
  * @throws \InvalidArgumentException
  */
 public function __construct(\ElggData $object, $action, \ElggEntity $actor = null)
 {
     if (elgg_instanceof($object)) {
         $this->object_type = $object->getType();
         $this->object_subtype = $object->getSubtype();
         $this->object_id = $object->getGUID();
     } else {
         $this->object_type = $object->getType();
         $this->object_subtype = $object->getSubtype();
         $this->object_id = $object->id;
     }
     if ($actor == null) {
         $this->actor_guid = _elgg_services()->session->getLoggedInUserGuid();
     } else {
         $this->actor_guid = $actor->getGUID();
     }
     $this->action = $action;
 }
 /**
  * Returns attribute names for an entity
  *
  * @param ElggEntity $entity Entity
  * @return array
  */
 public function getAttributeNames($entity)
 {
     if (!$entity instanceof \ElggEntity) {
         return array();
     }
     $default = array('guid', 'type', 'subtype', 'owner_guid', 'container_guid', 'site_guid', 'access_id', 'time_created', 'time_updated', 'last_action', 'enabled');
     switch ($entity->getType()) {
         case 'user':
             $attributes = array('name', 'username', 'email', 'language', 'banned', 'admin', 'password', 'salt');
             break;
         case 'group':
             $attributes = array('name', 'description');
             break;
         case 'object':
             $attributes = array('title', 'description');
             break;
     }
     return array_merge($default, $attributes);
 }
/**
 * Listen to the 'publish','object' event and send out notifications
 * to interested users, as well as anyone tagged
 *
 * @param string $event			Equals 'publish'
 * @param string $entity_type	Equals 'object'
 * @param ElggEntity $entity	Published entity
 */
function send_custom_notifications($event, $entity_type, $entity)
{
    if ($entity->origin !== 'wall') {
        return true;
    }
    // We only want to notify about wire posts and wall posts, all content created therewith is implied
    $accepted_subtypes = array('hjwall', 'thewire');
    if (!in_array($entity->getSubtype(), $accepted_subtypes)) {
        return true;
    }
    $poster = $entity->getOwnerEntity();
    $container = $entity->getContainerEntity();
    $message = format_wall_message($entity, true);
    $sent = array(elgg_get_logged_in_user_guid(), $poster->guid, $container->guid);
    // Notify wall owner
    if ($poster->guid !== $container->guid && elgg_instanceof($container, 'user')) {
        $to = $container->guid;
        $from = $poster->guid;
        $target = elgg_echo("wall:target:{$entity->getSubtype()}");
        $ownership = elgg_echo('wall:ownership:your', array($target));
        $subject = elgg_echo('wall:new:notification:subject', array($poster->name, $ownership));
        $summary = elgg_view('output/url', array('text' => $subject, 'href' => $entity->getURL()));
        $body = elgg_echo('wall:new:notification:message', array($poster->name, $ownership, $message, $entity->getURL()));
        notify_user($to, $from, $subject, $body, array('summary' => $summary, 'object' => $entity, 'action' => 'received'));
    }
    // Notify tagged users
    $tagged_friends = get_tagged_friends($entity);
    foreach ($tagged_friends as $tagged_friend) {
        // user tagged herself or the wall owner
        if ($tagged_friend->guid == $poster->guid || $tagged_friend->guid == $container->guid || in_array($tagged_friend->guid, $sent)) {
            continue;
        }
        $sent[] = $tagged_friend->guid;
        $to = $tagged_friend->guid;
        $from = $poster->guid;
        $subject = elgg_echo('wall:tagged:notification:subject', array($poster->name));
        $summary = elgg_view('output/url', array('text' => $subject, 'href' => $entity->getURL()));
        $body = elgg_echo('wall:tagged:notification:message', array($poster->name, $message, $entity->getURL()));
        notify_user($to, $from, $subject, $body, array('summary' => $summary, 'object' => $entity, 'action' => 'tagged'));
    }
    return true;
}
Exemple #27
0
/**
 * Notify $user that $sharer shared his $entity.
 *
 * @param type $user
 * @param type $sharer
 * @param type $entity 
 */
function share_notify_user(ElggUser $user, ElggUser $sharer, ElggEntity $entity)
{
    if (!$user instanceof ElggUser) {
        return false;
    }
    if (!$sharer instanceof ElggUser) {
        return false;
    }
    if (!$entity instanceof ElggEntity) {
        return false;
    }
    $title_str = $entity->title;
    if (!$title_str) {
        $title_str = elgg_get_excerpt($entity->description);
    }
    $site = get_config('site');
    $subject = elgg_echo('share:notifications:subject', array($sharer->name, $title_str));
    $body = elgg_echo('share:notifications:body', array($user->name, $sharer->name, $title_str, $site->name, $entity->getURL(), $sharer->getURL()));
    notify_user($user->guid, $sharer->guid, $subject, $body);
}
 /**
  * Prepares object type string
  * @return string
  */
 public function getObjectType()
 {
     $type = $this->object->getType();
     $subtype = $this->object->getSubtype() ?: 'default';
     $keys = ["interactions:{$type}:{$subtype}", $this->object instanceof Comment ? "interactions:comment" : "interactions:post"];
     foreach ($keys as $key) {
         if (elgg_language_key_exists($key, $this->language)) {
             return elgg_echo($key, array(), $this->language);
         }
     }
     return elgg_echo('interactions:post', $this->language);
 }
Exemple #29
0
/**
 * Cache an entity.
 *
 * Stores an entity in $ENTITY_CACHE;
 *
 * @param \ElggEntity $entity Entity to cache
 *
 * @return void
 * @see _elgg_retrieve_cached_entity()
 * @see _elgg_invalidate_cache_for_entity()
 * @access private
 * @todo Use an \ElggCache object
 */
function _elgg_cache_entity(\ElggEntity $entity)
{
    global $ENTITY_CACHE, $ENTITY_CACHE_DISABLED_GUIDS;
    // Don't cache non-plugin entities while access control is off, otherwise they could be
    // exposed to users who shouldn't see them when control is re-enabled.
    if (!$entity instanceof \ElggPlugin && elgg_get_ignore_access()) {
        return;
    }
    $guid = $entity->getGUID();
    if (isset($ENTITY_CACHE_DISABLED_GUIDS[$guid])) {
        return;
    }
    // Don't store too many or we'll have memory problems
    // @todo Pick a less arbitrary limit
    if (count($ENTITY_CACHE) > 256) {
        _elgg_invalidate_cache_for_entity(array_rand($ENTITY_CACHE));
    }
    $ENTITY_CACHE[$guid] = $entity;
}
Exemple #30
0
 public function testElggEntityMetadata()
 {
     // let's delete a non-existent metadata
     $this->assertFalse($this->entity->deleteMetadata('important'));
     // let's add the metadata
     $this->entity->important = 'indeed!';
     $this->assertIdentical('indeed!', $this->entity->important);
     $this->entity->less_important = 'true, too!';
     $this->assertIdentical('true, too!', $this->entity->less_important);
     // test deleting incorrectly
     // @link https://github.com/elgg/elgg/issues/2273
     $this->assertNull($this->entity->deleteMetadata('impotent'));
     $this->assertEqual($this->entity->important, 'indeed!');
     // get rid of one metadata
     $this->assertEqual($this->entity->important, 'indeed!');
     $this->assertTrue($this->entity->deleteMetadata('important'));
     $this->assertNull($this->entity->important);
     // get rid of all metadata
     $this->assertTrue($this->entity->deleteMetadata());
     $this->assertNull($this->entity->less_important);
 }