コード例 #1
0
ファイル: opendd.php プロジェクト: redvabel/Vabelgg
/**
 * Import an ODD document.
 *
 * @param string $xml The XML ODD.
 *
 * @return ODDDocument
 */
function ODD_Import($xml)
{
    // Parse XML to an array
    $elements = xml_to_object($xml);
    // Sanity check 1, was this actually XML?
    if (!$elements || !$elements->children) {
        return false;
    }
    // Create ODDDocument
    $document = new ODDDocument();
    // Itterate through array of elements and construct ODD document
    $cnt = 0;
    foreach ($elements->children as $child) {
        $odd = ODD_factory($child);
        if ($odd) {
            $document->addElement($odd);
            $cnt++;
        }
    }
    // Check that we actually found something
    if ($cnt == 0) {
        return false;
    }
    return $document;
}
コード例 #2
0
/**
 * 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;
}