getSubtype() 공개 메소드

Get the entity subtype
public getSubtype ( ) : string
리턴 string The entity subtype
예제 #1
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);
 }
예제 #2
0
 public function testGetSubtype()
 {
     $guid = $this->entity->guid;
     $this->assertEqual($this->entity->getSubtype(), 'elgg_entity_test_subtype');
     _elgg_invalidate_cache_for_entity($guid);
     $this->entity = null;
     $this->entity = get_entity($guid);
     $this->assertEqual($this->entity->getSubtype(), 'elgg_entity_test_subtype');
 }
예제 #3
0
/**
 * 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);
}
/**
 * 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;
}
예제 #5
0
 public function testSimpleGetters()
 {
     $this->obj->type = 'foo';
     $this->obj->subtype = 'subtype';
     $this->obj->owner_guid = 77;
     $this->obj->access_id = 2;
     $this->obj->time_created = 123456789;
     $this->assertEquals($this->obj->getGUID(), $this->obj->guid);
     $this->assertEquals($this->obj->getType(), $this->obj->type);
     // Note: before save() subtype returns string, int after
     // see https://github.com/Elgg/Elgg/issues/5920#issuecomment-25246298
     $this->assertEquals($this->obj->getSubtype(), $this->obj->subtype);
     $this->assertEquals($this->obj->getOwnerGUID(), $this->obj->owner_guid);
     $this->assertEquals($this->obj->getAccessID(), $this->obj->access_id);
     $this->assertEquals($this->obj->getTimeCreated(), $this->obj->time_created);
     $this->assertEquals($this->obj->getTimeUpdated(), $this->obj->time_updated);
 }
 /**
  * @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;
     }
 }
 /**
  * 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);
 }
예제 #8
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;
}
예제 #9
0
 /**
  * @requires PHP 5.3.2
  */
 public function testSimpleGetters()
 {
     $this->obj->type = 'foo';
     $this->obj->subtype = 'subtype';
     $this->obj->owner_guid = 77;
     $this->obj->access_id = 2;
     $this->obj->time_created = 123456789;
     $this->assertEquals($this->obj->getGUID(), $this->obj->guid);
     $this->assertEquals($this->obj->getType(), $this->obj->type);
     $this->assertEquals($this->obj->getSubtype(), $this->obj->subtype);
     $this->assertEquals($this->obj->getOwnerGUID(), $this->obj->owner_guid);
     $this->assertEquals($this->obj->getAccessID(), $this->obj->access_id);
     $this->assertEquals($this->obj->getTimeCreated(), $this->obj->time_created);
     $this->assertEquals($this->obj->getTimeUpdated(), $this->obj->time_updated);
 }
예제 #10
0
 /**
  * {@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();
     }
 }
예제 #11
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;
     }
 }
예제 #12
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);
}
예제 #13
0
/**
 * 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;
}
예제 #14
0
/**
 * Checks if a user can subscribe to a content item
 *
 * @param ElggEntity $entity    the entity to check
 * @param int        $user_guid the user to check (default: current user)
 *
 * @return bool
 */
function content_subscriptions_can_subscribe(ElggEntity $entity, $user_guid = 0)
{
    $user_guid = sanitise_int($user_guid, false);
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    if (empty($user_guid) || !$entity instanceof ElggEntity) {
        return false;
    }
    if ($entity->getOwnerGUID() === $user_guid) {
        // owner cant subscribe to own content
        return false;
    }
    $supported_entity_types = content_subscriptions_get_supported_entity_types();
    if (empty($supported_entity_types)) {
        return false;
    }
    $type = $entity->getType();
    if (!isset($supported_entity_types[$type])) {
        return false;
    }
    $subtype = $entity->getSubtype();
    if (!empty($subtype)) {
        return in_array($subtype, $supported_entity_types[$type]);
    }
    return true;
}
예제 #15
0
파일: widgets.php 프로젝트: ibou77/elgg
/**
 * Creates default widgets
 *
 * This plugin hook handler is registered for events based on what kinds of
 * default widgets have been registered. See elgg_default_widgets_init() for
 * information on registering new default widget contexts.
 *
 * @param string $event  The event
 * @param string $type   The type of object
 * @param \ElggEntity $entity The entity being created
 * @return void
 * @access private
 */
function _elgg_create_default_widgets($event, $type, $entity)
{
    $default_widget_info = elgg_get_config('default_widget_info');
    if (!$default_widget_info || !$entity) {
        return;
    }
    $type = $entity->getType();
    $subtype = $entity->getSubtype();
    // event is already guaranteed by the hook registration.
    // need to check subtype and type.
    foreach ($default_widget_info as $info) {
        if ($info['entity_type'] == $type) {
            if ($info['entity_subtype'] == ELGG_ENTITIES_ANY_VALUE || $info['entity_subtype'] == $subtype) {
                // need to be able to access everything
                $old_ia = elgg_set_ignore_access(true);
                elgg_push_context('create_default_widgets');
                // pull in by widget context with widget owners as the site
                // not using elgg_get_widgets() because it sorts by columns and we don't care right now.
                $options = array('type' => 'object', 'subtype' => 'widget', 'owner_guid' => elgg_get_site_entity()->guid, 'private_setting_name' => 'context', 'private_setting_value' => $info['widget_context'], 'limit' => 0);
                $widgets = elgg_get_entities_from_private_settings($options);
                /* @var \ElggWidget[] $widgets */
                foreach ($widgets as $widget) {
                    // change the container and owner
                    $new_widget = clone $widget;
                    $new_widget->container_guid = $entity->guid;
                    $new_widget->owner_guid = $entity->guid;
                    // pull in settings
                    $settings = get_all_private_settings($widget->guid);
                    foreach ($settings as $name => $value) {
                        $new_widget->{$name} = $value;
                    }
                    $new_widget->save();
                }
                elgg_set_ignore_access($old_ia);
                elgg_pop_context();
            }
        }
    }
}
예제 #16
0
/**
 * Returns rendered comments and a comment form for an entity.
 *
 * @tip Plugins can override the output by registering a handler
 * for the comments, $entity_type hook.  The handler is responsible
 * for formatting the comments and the add comment form.
 *
 * @param ElggEntity $entity      The entity to view comments of
 * @param bool       $add_comment Include a form to add comments?
 * @param array      $vars        Variables to pass to comment view
 *
 * @return string|false Rendered comments or false on failure
 */
function elgg_view_comments($entity, $add_comment = true, array $vars = array())
{
    if (!$entity instanceof ElggEntity) {
        return false;
    }
    $vars['entity'] = $entity;
    $vars['show_add_form'] = $add_comment;
    $vars['class'] = elgg_extract('class', $vars, "{$entity->getSubtype()}-comments");
    $output = elgg_trigger_plugin_hook('comments', $entity->getType(), $vars, false);
    if ($output) {
        return $output;
    } else {
        return elgg_view('page/elements/comments', $vars);
    }
}
예제 #17
0
 public static function getExtraValues(ElggEntity $entity)
 {
     global $CONFIG;
     if (!$entity) {
         return FALSE;
     }
     $return['url'] = $entity->getURL();
     $return['subtype'] = $entity->getSubtype();
     $return['title'] = $entity->title;
     $return['icon_small'] = $entity->getIcon('small');
     $return['icon_medium'] = $entity->getIcon('medium');
     $return['icon_large'] = $entity->getIcon('large');
     $return['access_id'] = $entity->access_id;
     $return['site_url'] = $CONFIG->wwwroot;
     if ($entity->canEdit()) {
         $return['canedit'] = $entity->canEdit();
     }
     if ((string) $entity->container_name == '') {
         $container_entity = get_entity($entity->container_guid);
         if ($container_entity) {
             $return['container_name'] = $container_entity->name;
             $return['container_username'] = $container_entity->username;
             $return['container_url'] = $container_entity->getURL();
             $return['container_icon'] = str_replace('size=medium', 'size=small', $container_entity->getIcon());
         }
     } else {
         $return['container_name'] = $entity->name;
         $return['container_username'] = $entity->username;
         $return['container_url'] = $entity->getURL();
         $return['container_icon'] = str_replace('size=medium', 'size=small', $entity->getIcon());
     }
     return $return;
 }
예제 #18
0
/**
 * Generate icons for an entity
 *
 * @param ElggEntity $entity
 * @param ElggFile $filehandler		Valid $filehandler on Elgg filestore to grab the file from | can be null if $entity is instance of ElggFile
 * @param array $coords				Coordinates for cropping
 * @return boolean
 */
function hj_framework_generate_entity_icons($entity, $filehandler = null, $coords = array())
{
    $icon_sizes = hj_framework_get_thumb_sizes($entity->getSubtype());
    if (!$filehandler && $entity instanceof hjFile) {
        $filehandler = $entity;
    }
    if (!$filehandler) {
        return false;
    }
    $prefix = "icons/" . $entity->getGUID();
    foreach ($icon_sizes as $size => $values) {
        if (!empty($coords) && in_array($size, array('topbar', 'tiny', 'small', 'medium', 'large'))) {
            $thumb_resized = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), $values['w'], $values['h'], $values['square'], $coords['x1'], $coords['y1'], $coords['x2'], $coords['y2'], $values['upscale']);
        } else {
            if (empty($coords)) {
                $thumb_resized = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), $values['w'], $values['h'], $values['square'], 0, 0, 0, 0, $values['upscale']);
            }
        }
        if ($thumb_resized) {
            $thumb = new hjFile();
            $thumb->owner_guid = $entity->owner_guid;
            $thumb->setMimeType('image/jpeg');
            $thumb->setFilename($prefix . "{$size}.jpg");
            $thumb->open("write");
            $thumb->write($thumb_resized);
            $thumb->close();
            $icontime = true;
        }
    }
    if ($icontime) {
        $entity->icontime = time();
        return true;
    }
    return false;
}
예제 #19
0
파일: IconFactory.php 프로젝트: n8b/VMN
 /**
  * Get icon size config
  *
  * @param \ElggEntity $entity     Entity
  * @param array      $icon_sizes Predefined icon sizes
  * @return array
  */
 public function getSizes(\ElggEntity $entity, array $icon_sizes = array())
 {
     $defaults = $entity && $entity->getSubtype() == 'file' ? $this->config->getFileIconSizes() : $this->config->getGlobalIconSizes();
     $sizes = array_merge($defaults, $icon_sizes);
     return elgg_trigger_plugin_hook('entity:icon:sizes', $entity->getType(), array('entity' => $entity, 'subtype' => $entity->getSubtype()), $sizes);
 }
예제 #20
0
/**
 * Checks if media type is allowed for given entity
 *
 * @param \ElggEntity $entity  Entity
 * @param string      $type    Media type
 * @return bool
 */
function elgg_media_get_thumb_sizes(\ElggEntity $entity, $type = 'icon')
{
    $hook_type = implode(':', array_filter([$entity->getType(), $entity->getSubtype()]));
    $hook_params = ['type' => $type, 'entity' => $entity];
    return elgg_trigger_plugin_hook("entity:{$type}:sizes", $hook_type, $hook_params, []);
}
예제 #21
0
/**
 * Populates entity doc with default index fields
 *
 * @param DocumentInterface $doc    Solr document
 * @param ElggEntity        $entity Elgg entity
 * @return DocumentInterface
 */
function elgg_solr_prepare_entity_doc(DocumentInterface $doc, ElggEntity $entity)
{
    $doc->id = $entity->guid;
    $doc->type = $entity->type;
    $doc->subtype = (string) $entity->getSubtype();
    $doc->owner_guid = $entity->owner_guid;
    $doc->container_guid = $entity->container_guid;
    $doc->access_id = $entity->access_id;
    $doc->title = elgg_strip_tags($entity->title);
    $doc->name = elgg_strip_tags($entity->name);
    $doc->description = elgg_strip_tags($entity->description);
    $doc->time_created = $entity->time_created;
    $doc->time_updated_i = $entity->time_updated;
    $doc = elgg_solr_add_tags($doc, $entity);
    $doc->enabled = $entity->enabled;
    if (is_callable([$entity, 'hasIcon'])) {
        $doc->has_icon_b = $entity->hasIcon('small');
    } else {
        $doc->has_icon_b = (bool) $entity->icontime;
    }
    if ($entity instanceof ElggFile) {
        $mimetype = (string) $entity->getMimeType();
        $doc->simpletype_s = (string) elgg_get_file_simple_type($mimetype);
        $doc->mimetype_s = $mimetype;
        $doc->originalfilename_s = $entity->originalfilename;
        if ($entity->exists()) {
            $doc->exists_b = true;
            $doc->filestorename_s = $entity->getFilenameOnFilestore();
            $doc->filesize_i = (int) $entity->getSize();
        } else {
            $doc->exists_b = false;
        }
    }
    // Store comment/reply thread information to allow grouping
    if ($entity instanceof ElggComment) {
        $container = $entity->getContainerEntity();
        while ($container instanceof ElggComment) {
            $container = $container->getContainerEntity();
        }
        $doc->responses_thread_i = $container->guid;
    } else {
        $doc->responses_thread_i = $entity->guid;
    }
    // Store comment/reply guids
    $responses = [];
    $responses_batch = new ElggBatch('elgg_get_entities', ['types' => 'object', 'subtypes' => ['comment', 'discussion_reply'], 'container_guid' => $entity->guid, 'limit' => 0, 'callback' => false]);
    foreach ($responses_batch as $response) {
        $responses[] = $response->guid;
    }
    $doc->responses_is = $responses;
    $doc->responses_count_i = count($responses);
    $doc->likes_i = $entity->countAnnotations('likes');
    $params = array('entity' => $entity);
    $doc = elgg_trigger_plugin_hook('elgg_solr:index', $entity->type, $params, $doc);
    if ($entity->getSubtype()) {
        $doc = elgg_trigger_plugin_hook('elgg_solr:index', "{$entity->type}:{$entity->getSubtype()}", $params, $doc);
    }
    return $doc;
}
예제 #22
0
function entity_view_counter_is_counted(ElggEntity $entity)
{
    if (php_sapi_name() === 'cli') {
        return true;
    }
    if (!entity_view_counter_is_configured_entity_type($entity->getType(), $entity->getSubtype())) {
        return true;
    }
    if (isset($_SERVER["HTTP_USER_AGENT"]) && preg_match('/bot|crawl|slurp|spider/i', $_SERVER["HTTP_USER_AGENT"])) {
        return true;
    }
    $user = elgg_get_logged_in_user_entity();
    if ($user && $user->getGUID() == $entity->getOwnerGUID()) {
        return true;
    }
    if (is_memcache_available()) {
        $cache = new ElggMemcache('entity_view_counter');
        $key = "view_" . session_id() . "_" . $entity->guid;
        if ($cache->load($key)) {
            return true;
        }
    }
    if (entity_view_counter_ignore_ip()) {
        return true;
    }
    return false;
}
예제 #23
0
 /**
  * When an entity is updated, resets the access ID on all of its child metadata
  *
  * @param string      $event       The name of the event
  * @param string      $object_type The type of object
  * @param \ElggEntity $object      The entity itself
  *
  * @return true
  * @access private Set as private in 1.9.0
  */
 function handleUpdate($event, $object_type, $object)
 {
     if ($object instanceof \ElggEntity) {
         if (!$this->isMetadataIndependent($object->getType(), $object->getSubtype())) {
             $access_id = (int) $object->access_id;
             $guid = (int) $object->getGUID();
             $query = "update {$this->table} set access_id = {$access_id} where entity_guid = {$guid}";
             $this->db->updateData($query);
         }
     }
     return true;
 }
예제 #24
0
/**
 * Prepare entity SEF data
 *
 * @param \ElggEntity $entity Entity
 * @return array|false
 */
function seo_prepare_entity_data(\ElggEntity $entity)
{
    $path = seo_get_path($entity->getURL());
    if (!$path || $path == '/') {
        return false;
    }
    $type = $entity->getType();
    switch ($type) {
        case 'user':
            if (elgg_is_active_plugin('profile')) {
                $sef_path = "/profile/{$entity->username}";
            }
            break;
        case 'group':
            $subtype = $entity->getSubtype();
            $registered = (array) get_registered_entity_types('group');
            if (!$subtype || in_array($subtype, $registered)) {
                if ($subtype && elgg_language_key_exists("item:group:{$subtype}", 'en')) {
                    $prefix = elgg_get_friendly_title(elgg_echo("item:group:{$subtype}", array(), 'en'));
                } else {
                    $prefix = elgg_get_friendly_title(elgg_echo('item:group', array(), 'en'));
                }
                $friendly_title = elgg_get_friendly_title($entity->getDisplayName() ?: '');
                $sef_path = "/{$prefix}/{$entity->guid}-{$friendly_title}";
            }
            break;
        case 'object':
            $subtype = $entity->getSubtype();
            $registered = (array) get_registered_entity_types('object');
            if (in_array($subtype, $registered)) {
                if (elgg_language_key_exists("item:object:{$subtype}", 'en')) {
                    $prefix = elgg_get_friendly_title(elgg_echo("item:object:{$subtype}", array(), 'en'));
                } else {
                    $prefix = elgg_get_friendly_title($subtype);
                }
                $friendly_title = elgg_get_friendly_title($entity->getDisplayName() ?: '');
                $sef_path = "/{$prefix}/{$entity->guid}-{$friendly_title}";
            }
            break;
    }
    if (!$sef_path) {
        $sef_path = $path;
    }
    $sef_data = seo_get_data($entity->getURL());
    if (!is_array($sef_data)) {
        $sef_data = array();
    }
    $entity_sef_data = ['path' => $path, 'sef_path' => $sef_path, 'title' => $entity->getDisplayName(), 'description' => elgg_get_excerpt($entity->description), 'keywords' => is_array($entity->tags) ? implode(',', $entity->tags) : $entity->tags, 'guid' => $entity->guid];
    if ($entity->guid != $entity->owner_guid) {
        $owner = $entity->getOwnerEntity();
        if ($owner) {
            $entity_sef_data['owner'] = seo_prepare_entity_data($owner);
        }
    }
    if ($entity->guid != $entity->container_guid && $entity->owner_guid != $entity->container_guid) {
        $container = $entity->getContainerEntity();
        if ($container) {
            $entity_sef_data['container'] = seo_prepare_entity_data($container);
        }
    }
    if (empty($sef_data['admin_defined'])) {
        $sef_data = array_merge($sef_data, $entity_sef_data);
    } else {
        foreach ($entity_sef_data as $key => $value) {
            if (empty($sef_data[$key])) {
                $sef_data[$key] = $value;
            }
        }
    }
    $entity_sef_metatags = elgg_trigger_plugin_hook('metatags', 'discovery', ['entity' => $entity, 'url' => elgg_normalize_url($sef_path)], []);
    if (!empty($entity_sef_metatags)) {
        foreach ($entity_sef_metatags as $key => $value) {
            if (empty($sef_data['admin_defined']) || empty($sef_data['metatags'][$key])) {
                $sef_data['metatags'][$key] = $value;
            }
        }
    }
    return $sef_data;
}
/**
 * When an entity is updated, resets the access ID on all of its child metadata
 *
 * @param string     $event       The name of the event
 * @param string     $object_type The type of object
 * @param ElggEntity $object      The entity itself
 *
 * @return true
 * @access private Set as private in 1.9.0
 */
function metadata_update($event, $object_type, $object)
{
    if ($object instanceof ElggEntity) {
        if (!is_metadata_independent($object->getType(), $object->getSubtype())) {
            $db_prefix = elgg_get_config('dbprefix');
            $access_id = (int) $object->access_id;
            $guid = (int) $object->getGUID();
            $query = "update {$db_prefix}metadata set access_id = {$access_id} where entity_guid = {$guid}";
            update_data($query);
        }
    }
    return true;
}
예제 #26
0
파일: metadata.php 프로젝트: eokyere/elgg
/**
 * When an entity is updated, resets the access ID on all of its child metadata
 *
 * @param string $event The name of the event
 * @param string $object_type The type of object
 * @param ElggEntity $object The entity itself
 */
function metadata_update($event, $object_type, $object)
{
    if ($object instanceof ElggEntity) {
        if (!is_metadata_independent($object->getType(), $object->getSubtype())) {
            global $CONFIG;
            $access_id = (int) $object->access_id;
            $guid = (int) $object->getGUID();
            update_data("update {$CONFIG->dbprefix}metadata set access_id = {$access_id} where entity_guid = {$guid}");
        }
    }
    return true;
}
예제 #27
0
/**
 * When given an entity, views it intelligently.
 *
 * Expects a view to exist called entity-type/subtype, or for the entity to have a parameter
 * 'view' which lists a different view to display.  In both cases, elgg_view will be called with
 * array('entity' => $entity, 'full' => $full) as its parameters, and therefore this is what
 * the view should expect to receive.
 *
 * @param ElggEntity $entity The entity to display
 * @param boolean $full Determines whether or not to display the full version of an object, or a smaller version for use in aggregators etc
 * @param boolean $bypass If set to true, elgg_view will bypass any specified alternative template handler; by default, it will hand off to this if requested (see set_template_handler)
 * @param boolean $debug If set to true, the viewer will complain if it can't find a view
 * @return string HTML to display or false
 */
function elgg_view_entity(ElggEntity $entity, $full = false, $bypass = true, $debug = false)
{
    global $autofeed;
    $autofeed = true;
    // No point continuing if entity is null
    if (!$entity) {
        return '';
    }
    if (!$entity instanceof ElggEntity) {
        return false;
    }
    // if this entity has a view defined, use it
    $view = $entity->view;
    if (is_string($view)) {
        return elgg_view($view, array('entity' => $entity, 'full' => $full), $bypass, $debug);
    }
    $entity_type = $entity->getType();
    $subtype = $entity->getSubtype();
    if (empty($subtype)) {
        $subtype = $entity_type;
    }
    $contents = '';
    if (elgg_view_exists("{$entity_type}/{$subtype}")) {
        $contents = elgg_view("{$entity_type}/{$subtype}", array('entity' => $entity, 'full' => $full), $bypass, $debug);
    }
    if (empty($contents)) {
        $contents = elgg_view("{$entity_type}/default", array('entity' => $entity, 'full' => $full), $bypass, $debug);
    }
    // Marcus Povey 20090616 : Speculative and low impact approach for fixing #964
    if ($full) {
        $annotations = elgg_view_entity_annotations($entity, $full);
        if ($annotations) {
            $contents .= $annotations;
        }
    }
    return $contents;
}
예제 #28
0
/**
 * Return the icon URL for an entity.
 *
 * @tip Can be overridden by registering a plugin hook for entity:icon:url, $entity_type.
 *
 * @internal This is passed an entity rather than a guid to handle non-created entities.
 *
 * @param ElggEntity $entity The entity
 * @param string     $size   Icon size
 *
 * @return string URL to the entity icon.
 * @deprecated 1.8 Use $entity->getIconURL()
 */
function get_entity_icon_url(ElggEntity $entity, $size = 'medium')
{
    elgg_deprecated_notice("get_entity_icon_url() deprecated for getIconURL()", 1.8);
    global $CONFIG;
    $size = sanitise_string($size);
    switch (strtolower($size)) {
        case 'master':
            $size = 'master';
            break;
        case 'large':
            $size = 'large';
            break;
        case 'topbar':
            $size = 'topbar';
            break;
        case 'tiny':
            $size = 'tiny';
            break;
        case 'small':
            $size = 'small';
            break;
        case 'medium':
        default:
            $size = 'medium';
    }
    $url = false;
    $viewtype = elgg_get_viewtype();
    // Step one, see if anyone knows how to render this in the current view
    $params = array('entity' => $entity, 'viewtype' => $viewtype, 'size' => $size);
    $url = elgg_trigger_plugin_hook('entity:icon:url', $entity->getType(), $params, $url);
    // Fail, so use default
    if (!$url) {
        $type = $entity->getType();
        $subtype = $entity->getSubtype();
        if (!empty($subtype)) {
            $overrideurl = elgg_view("icon/{$type}/{$subtype}/{$size}", array('entity' => $entity));
            if (!empty($overrideurl)) {
                return $overrideurl;
            }
        }
        $overrideurl = elgg_view("icon/{$type}/default/{$size}", array('entity' => $entity));
        if (!empty($overrideurl)) {
            return $overrideurl;
        }
        $url = "_graphics/icons/default/{$size}.png";
    }
    return elgg_normalize_url($url);
}
예제 #29
0
 /**
  * Check if the given entity is searchable (and needs to be in Elasticsearch)
  *
  * @param \ElggEntity $entity the entity
  *
  * @return bool
  */
 protected static function isSearchableEntity(\ElggEntity $entity)
 {
     if (empty($entity) || !$entity instanceof \ElggEntity) {
         return false;
     }
     $type = $entity->getType();
     $type_subtypes = elasticsearch_get_registered_entity_types();
     if (!isset($type_subtypes[$type])) {
         return false;
     }
     $subtype = $entity->getSubtype();
     if (empty($subtype)) {
         // eg. user, group, site
         return true;
     }
     return in_array($subtype, $type_subtypes[$type]);
 }