/**
 * Get a UUID from a given object.
 *
 * @param mixed $object The object either an ElggEntity, ElggRelationship or ElggExtender
 *
 * @return the UUID or false
 */
function get_uuid_from_object($object)
{
    if ($object instanceof ElggEntity) {
        return guid_to_uuid($object->guid);
    } else {
        if ($object instanceof ElggExtender) {
            $type = $object->type;
            if ($type == 'volatile') {
                $uuid = guid_to_uuid($object->entity_guid) . $type . "/{$object->name}/";
            } else {
                $uuid = guid_to_uuid($object->entity_guid) . $type . "/{$object->id}/";
            }
            return $uuid;
        } else {
            if ($object instanceof ElggRelationship) {
                return guid_to_uuid($object->guid_one) . "relationship/{$object->id}/";
            }
        }
    }
    return false;
}
Esempio n. 2
0
    if (!$entity) {
        $query = "GUID:" . $guid . " could not be found, or you can not access it.";
        throw new \InvalidParameterException($query);
    }
    $title = "GUID:{$guid}";
    $body = elgg_view("export/entity", array("entity" => $entity, "uuid" => guid_to_uuid($guid)));
    // Export an individual attribute
} else {
    if ($guid != "" && $type != "" && $id_or_name != "") {
        // Get a uuid
        $entity = get_entity($guid);
        if (!$entity) {
            $msg = "GUID:" . $guid . " could not be found, or you can not access it.";
            throw new \InvalidParameterException($msg);
        }
        $uuid = guid_to_uuid($entity->getGUID()) . "{$type}/{$id_or_name}/";
        switch ($type) {
            case 'attr':
                // @todo: Do this better? - This is a bit of a hack...
                $v = $entity->get($id_or_name);
                if (!$v) {
                    $msg = "Sorry, '" . $id_or_name . "' does not exist for guid:" . $guid;
                    throw new \InvalidParameterException($msg);
                }
                $m = new \ElggMetadata();
                $m->value = $v;
                $m->name = $id_or_name;
                $m->entity_guid = $guid;
                $m->time_created = $entity->time_created;
                $m->time_updated = $entity->time_updated;
                $m->owner_guid = $entity->owner_guid;
Esempio n. 3
0
/**
 * Get a UUID from a given object.
 *
 * @param mixed $object The object either an \ElggEntity, \ElggRelationship or \ElggExtender
 *
 * @return string|false the UUID or false
 * @deprecated 1.9
 */
function get_uuid_from_object($object)
{
    elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
    if ($object instanceof \ElggEntity) {
        return guid_to_uuid($object->guid);
    } else {
        if ($object instanceof \ElggExtender) {
            $type = $object->type;
            if ($type == 'volatile') {
                $uuid = guid_to_uuid($object->entity_guid) . $type . "/{$object->name}/";
            } else {
                $uuid = guid_to_uuid($object->entity_guid) . $type . "/{$object->id}/";
            }
            return $uuid;
        } else {
            if ($object instanceof \ElggRelationship) {
                return guid_to_uuid($object->guid_one) . "relationship/{$object->id}/";
            }
        }
    }
    return false;
}
Esempio n. 4
0
 /**
  * Export this object
  *
  * @return array
  * @deprecated 1.9 Use toObject()
  */
 public function export()
 {
     elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
     $uuid = get_uuid_from_object($this);
     $meta = new ODDMetaData($uuid, guid_to_uuid($this->entity_guid), $this->attributes['name'], $this->attributes['value'], $this->attributes['type'], guid_to_uuid($this->owner_guid));
     $meta->setAttribute('published', date("r", $this->time_created));
     return $meta;
 }
Esempio n. 5
0
 /**
  * Export this class into an array of ODD Elements containing all necessary fields.
  * Override if you wish to return more information than can be found in
  * $this->attributes (shouldn't happen)
  *
  * @return array
  * @deprecated 1.9
  */
 public function export()
 {
     elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
     $tmp = array();
     // Generate uuid
     $uuid = guid_to_uuid($this->getGUID());
     // Create entity
     $odd = new ODDEntity($uuid, $this->attributes['type'], get_subtype_from_id($this->attributes['subtype']));
     $tmp[] = $odd;
     $exportable_values = $this->getExportableValues();
     // Now add its attributes
     foreach ($this->attributes as $k => $v) {
         $meta = null;
         if (in_array($k, $exportable_values)) {
             switch ($k) {
                 case 'guid':
                     // Dont use guid in OpenDD
                 // Dont use guid in OpenDD
                 case 'type':
                     // Type and subtype already taken care of
                 // Type and subtype already taken care of
                 case 'subtype':
                     break;
                 case 'time_created':
                     // Created = published
                     $odd->setAttribute('published', date("r", $v));
                     break;
                 case 'site_guid':
                     // Container
                     $k = 'site_uuid';
                     $v = guid_to_uuid($v);
                     $meta = new ODDMetaData($uuid . "attr/{$k}/", $uuid, $k, $v);
                     break;
                 case 'container_guid':
                     // Container
                     $k = 'container_uuid';
                     $v = guid_to_uuid($v);
                     $meta = new ODDMetaData($uuid . "attr/{$k}/", $uuid, $k, $v);
                     break;
                 case 'owner_guid':
                     // Convert owner guid to uuid, this will be stored in metadata
                     $k = 'owner_uuid';
                     $v = guid_to_uuid($v);
                     $meta = new ODDMetaData($uuid . "attr/{$k}/", $uuid, $k, $v);
                     break;
                 default:
                     $meta = new ODDMetaData($uuid . "attr/{$k}/", $uuid, $k, $v);
             }
             // set the time of any metadata created
             if ($meta) {
                 $meta->setAttribute('published', date("r", $this->time_created));
                 $tmp[] = $meta;
             }
         }
     }
     // Now we do something a bit special.
     /*
      * This provides a rendered view of the entity to foreign sites.
      */
     elgg_set_viewtype('default');
     $view = elgg_view_entity($this, array('full_view' => true));
     elgg_set_viewtype();
     $tmp[] = new ODDMetaData($uuid . "volatile/renderedentity/", $uuid, 'renderedentity', $view, 'volatile');
     return $tmp;
 }
Esempio n. 6
0
 /**
  * Export this relationship
  *
  * @return array
  */
 public function export()
 {
     $uuid = get_uuid_from_object($this);
     $relationship = new ODDRelationship(guid_to_uuid($this->guid_one), $this->relationship, guid_to_uuid($this->guid_two));
     $relationship->setAttribute('uuid', $uuid);
     return $relationship;
 }
Esempio n. 7
0
 /**
  * Export this relationship
  *
  * @return array
  * @deprecated 1.9 Use toObject()
  */
 public function export()
 {
     elgg_deprecated_notice(__METHOD__ . ' has been deprecated', 1.9);
     $uuid = get_uuid_from_object($this);
     $relationship = new ODDRelationship(guid_to_uuid($this->guid_one), $this->relationship, guid_to_uuid($this->guid_two));
     $relationship->setAttribute('uuid', $uuid);
     return $relationship;
 }
Esempio n. 8
0
 /**
  * Export this object
  *
  * @return array
  */
 public function export()
 {
     $uuid = get_uuid_from_object($this);
     $meta = new ODDMetaData($uuid, guid_to_uuid($this->entity_guid), $this->attributes['name'], $this->attributes['value'], $this->attributes['type'], guid_to_uuid($this->owner_guid));
     $meta->setAttribute('published', date("r", $this->time_created));
     return $meta;
 }
/**
 * Extract entities from the system log and produce them as an OpenDD stream.
 * This stream can be subscribed to and reconstructed on another system as an activity stream.
 *
 * @param int $by_user The user who initiated the event.
 * @param string $relationship Limit return results to only those users who $by_user has $relationship with.
 * @param int $limit Maximum number of events to show
 * @param int $offset An offset
 * @return ODDDocument
 */
function get_river_entries_as_opendd($by_user = "", $relationship = "", $limit = 10, $offset = 0)
{
    global $CONFIG;
    $limit = (int) $limit;
    $offset = (int) $offset;
    $relationship = sanitise_string($relationship);
    if (is_array($by_user) && sizeof($by_user) > 0) {
        foreach ($by_user as $key => $val) {
            $by_user[$key] = (int) $val;
        }
    } else {
        $by_user = array((int) $by_user);
    }
    // Get river data
    $log_data = __get_river_from_log($by_user, $relationship, $limit, $offset);
    // River objects
    $river = new ODDDocument();
    if ($log_data) {
        foreach ($log_data as $log) {
            $event = $log->event;
            $class = $log->object_class;
            $type = $log->object_type;
            $subtype = $log->object_subtype;
            $tmp = new $class();
            $object = $tmp->getObjectFromID($log->object_id);
            $by_user_obj = get_entity($log->performed_by_guid);
            // Belts and braces
            if ($object instanceof $class) {
                $relationship_obj = NULL;
                // Handle updates of entities
                if ($object instanceof ElggEntity) {
                    $relationship_obj = new ODDRelationship(guid_to_uuid($log->performed_by_guid), $log->event, guid_to_uuid($log->object_id));
                }
                // Handle updates of metadata
                if ($object instanceof ElggExtender) {
                    $odd = $object->export();
                    $relationship_obj = new ODDRelationship(guid_to_uuid($log->performed_by_guid), $log->event, $odd->getAttribute('uuid'));
                }
                // Handle updates of relationships
                if ($object instanceof ElggRelationship) {
                    $odd = $object->export();
                    $relationship_obj = new ODDRelationship(guid_to_uuid($log->performed_by_guid), $log->event, $odd->getAttribute('uuid'));
                }
                // If we have handled it then add it to the document
                if ($relationship_obj) {
                    $relationship_obj->setPublished($log->time_created);
                    $river->addElement($relationship_obj);
                }
            }
        }
    }
    return $river;
}