/** * Handler called by trigger_plugin_hook on the "export" event. * * @param string $hook export * @param string $entity_type all * @param mixed $returnvalue Previous hook return value * @param array $params Parameters * * @elgg_event_handler export all * @return mixed * @throws InvalidParameterException * @access private * @deprecated 1.9 */ function export_relationship_plugin_hook($hook, $entity_type, $returnvalue, $params) { // Sanity check values if (!is_array($params) && !isset($params['guid'])) { throw new \InvalidParameterException("GUID has not been specified during export, this should never happen."); } if (!is_array($returnvalue)) { throw new \InvalidParameterException("Entity serialisation function passed a non-array returnvalue parameter"); } $guid = (int) $params['guid']; $result = get_entity_relationships($guid); if ($result) { foreach ($result as $r) { $returnvalue[] = $r->export(); } } return $returnvalue; }
/** * Handler called by trigger_plugin_hook on the "export" event. * * @param string $hook export * @param string $entity_type all * @param mixed $returnvalue Previous hook return value * @param array $params Parameters * * @elgg_event_handler export all * @return mixed * @access private */ function export_relationship_plugin_hook($hook, $entity_type, $returnvalue, $params) { global $CONFIG; // Sanity check values if (!is_array($params) && !isset($params['guid'])) { throw new InvalidParameterException(elgg_echo('InvalidParameterException:GUIDNotForExport')); } if (!is_array($returnvalue)) { throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonArrayReturnValue')); } $guid = (int) $params['guid']; $result = get_entity_relationships($guid); if ($result) { foreach ($result as $r) { $returnvalue[] = $r->export(); } } return $returnvalue; }
/** * Elgg Entity export. * Displays an entity using the current view. * * @package Elgg * @subpackage Core * @author Curverider Ltd * @link http://elgg.org/ */ $entity = $vars['entity']; if (!$entity) { throw new InvalidParameterException(elgg_echo('InvalidParameterException:NoEntityFound')); } $metadata = get_metadata_for_entity($entity->guid); $annotations = get_annotations($entity->guid); $relationships = get_entity_relationships($entity->guid); $exportable_values = $entity->getExportableValues(); ?> <div> <h2><?php echo elgg_echo('Entity'); ?> </h2> <?php foreach ($entity as $k => $v) { if (in_array($k, $exportable_values) || isadminloggedin()) { ?> <p class="margin_none"><b><?php echo $k; ?> : </b><?php
$user_guid = elgg_get_logged_in_user_guid(); // load original file object $file = new ElggFile($file_guid); if (!$file) { if ($lock) { register_error(elgg_echo('odt_editor:error:file_removed')); } forward(REFERER); } // user must be able to edit file if (!$file->canEdit()) { register_error(elgg_echo('You do no longer have write access to the file that is edited.')); forward(REFERER); } // save folder guid in parameter to make sure file_tools_object_handler does not overwrite the relationship $relationships = get_entity_relationships($file->guid, FILE_TOOLS_RELATIONSHIP, true); if (elgg_is_active_plugin('file_tools') && count($relationships) > 0) { set_input('folder_guid', $relationships[0]->guid_one); } // recreate lock, user closed window but cancelled if ($lock_set && !odt_editor_locking_is_locked($file)) { trigger_error("Restored lock", E_USER_WARNING); odt_editor_locking_create_lock($file, $user_guid, $lock_guid); forward(REFERER); } // check for lost lock if (odt_editor_locking_lock_guid($file) != $lock_guid) { $lock_owner_guid = odt_editor_locking_lock_owner_guid($file); if ($lock_owner_guid != $user_guid) { $locking_user = get_entity($lock_owner_guid); $locking_user_name = $locking_user ? $locking_user->name : elgg_echo("odt_editor:unknown_user");
/** * Check if a user has a block relationship with an entity * * @param int $entity_guid the entity to check * @param int $user_guid the user to check for (default: current user) * * @return bool */ function content_subscriptions_check_block_subscription($entity_guid, $user_guid = 0) { static $user_cache; $entity_guid = sanitise_int($entity_guid, false); $user_guid = sanitise_int($user_guid, false); if (empty($user_guid)) { $user_guid = elgg_get_logged_in_user_guid(); } if (empty($entity_guid) || empty($user_guid)) { return false; } if (!isset($user_cache)) { $user_cache = []; } if (!isset($user_cache[$user_guid])) { $user_cache[$user_guid] = []; $relationships = get_entity_relationships($user_guid); if (!empty($relationships)) { foreach ($relationships as $relationship) { if ($relationship->relationship === CONTENT_SUBSCRIPTIONS_BLOCK) { $user_cache[$user_guid][] = (int) $relationship->guid_two; } } } } return in_array($entity_guid, $user_cache[$user_guid]); }
/** * Hook to export relationship entities for search * * @param string $hook the name of the hook * @param string $type the type of the hook * @param string $returnvalue current return value * @param array $params supplied params * * @return void */ public static function entityRelationshipsToObject($hook, $type, $returnvalue, $params) { if (!elgg_in_context('search:index')) { return; } $entity = elgg_extract('entity', $params); if (!$entity) { return; } $relationships = get_entity_relationships($entity->getGUID()); if (empty($relationships)) { return; } $result = []; foreach ($relationships as $relationship) { $result[] = ['id' => (int) $relationship->id, 'time_created' => date('c', $relationship->time_created), 'guid_one' => (int) $relationship->guid_one, 'guid_two' => (int) $relationship->guid_two, 'relationship' => $relationship->relationship]; } $returnvalue->relationships = $result; return $returnvalue; }
<?php /** * whoviewedme index * */ $title = elgg_echo('whoviewedme'); $options = array('type' => 'user', 'full_view' => false); $options['relationship'] = 'viewed'; $options['inverse_relationship'] = true; $options['relationship_guid'] = elgg_get_logged_in_user_guid(); //$content = elgg_list_entities_from_relationship($options); $rels = get_entity_relationships(elgg_get_logged_in_user_guid()); if (!$rels) { $content = elgg_echo("whoviewedme:nobody"); } else { $content = ""; foreach ($rels as $key => $rel) { $user = get_user($rel->guid_two); if (!$user) { continue; } $content .= elgg_view_entity($user); $content .= elgg_view_friendly_time($rel->time_created); //$content.= "</br>".$rel->guid_two; } } $params = array('content' => $content, 'title' => $title, 'filter_override' => ""); $body = elgg_view_layout('content', $params); echo elgg_view_page($title, $body);
<?php namespace hypeJunction\Wall; use ElggBatch; $ia = elgg_set_ignore_access(true); /** * Wall owner should become the container of the wall post * wall_owner relationship should go away */ $wall_posts = new ElggBatch('elgg_get_entities_from_relationship', array('types' => 'object', 'subtypes' => 'hjwall', 'relationship' => 'wall_owner', 'limit' => false)); foreach ($wall_posts as $wall_post) { $relationships = get_entity_relationships($wall_post->guid, true); foreach ($relationships as $relationship) { if ($relationship->relationship !== 'wall_owner') { continue; } if ($relationship->guid_one !== $wall_post->container_guid) { $wall_post->container_guid = $relationship->guid_one; if ($wall_post->save()) { $relationship->delete(); } } } } /** * Convert attachment metadata to 'attached' relationship for entities * and 'html' metadata for the rest */ $wall_posts = new ElggBatch('elgg_get_entities_from_metadata', array('types' => 'object', 'subtypes' => 'hjwall', 'metadata_names' => 'attachment', 'limit' => false)); foreach ($wall_posts as $wall_post) {
public function upgrade20140211() { $ia = elgg_set_ignore_access(true); /** * Wall owner should become the container of the wall post * wall_owner relationship should go away */ $wall_posts = new \ElggBatch('elgg_get_entities_from_relationship', array('types' => 'object', 'subtypes' => 'hjwall', 'relationship' => 'wall_owner', 'limit' => false)); foreach ($wall_posts as $wall_post) { $relationships = get_entity_relationships($wall_post->guid, true); foreach ($relationships as $relationship) { if ($relationship->relationship !== 'wall_owner') { continue; } if ($relationship->guid_one !== $wall_post->container_guid) { $wall_post->container_guid = $relationship->guid_one; if ($wall_post->save()) { $relationship->delete(); } } } } /** * Convert attachment metadata to 'attached' relationship for entities * and 'html' metadata for the rest */ $wall_posts = new \ElggBatch('elgg_get_entities_from_metadata', array('types' => 'object', 'subtypes' => 'hjwall', 'metadata_names' => 'attachment', 'limit' => false)); foreach ($wall_posts as $wall_post) { $attachment = $wall_post->attachment; if (is_numeric($attachment) && ($attached_entity = get_entity($attachment))) { add_entity_relationship($attached_entity->guid, 'attached', $wall_post->guid); } else { $wall_post->html = $attachment; } unset($wall_post->attachment); } /** * Convert 'hjfile' to 'file' */ $subtypeIdFrom = add_subtype('object', 'hjfile'); $subtypeIdTo = add_subtype('object', 'file'); $dbprefix = elgg_get_config('dbprefix'); $query = "\tUPDATE {$dbprefix}entities e\n\t\t\t\tJOIN {$dbprefix}metadata md ON md.entity_guid = e.guid\n\t\t\t\tJOIN {$dbprefix}metastrings msn ON msn.id = md.name_id\n\t\t\t\tJOIN {$dbprefix}metastrings msv ON msv.id = md.value_id\n\t\t\t\tSET e.subtype = {$subtypeIdTo}\n\t\t\t\tWHERE e.subtype = {$subtypeIdFrom} AND msn.string = 'handler' AND msv.string = 'hjwall' "; $wall_files = new \ElggBatch('elgg_get_entities_from_metadata', array('types' => 'object', 'subtypes' => 'file', 'metadata_name_value_pairs' => array('name' => 'handler', 'value' => 'hjwall'), 'limit' => false)); foreach ($wall_files as $file) { // Regenerate icons if ($file->simpletype == 'image') { $thumb_sizes = array('tiny' => 16, 'small' => 25, 'medium' => 40, 'large' => 100, 'preview' => 250, 'master' => 500, 'full' => 1024); foreach ($thumb_sizes as $ths => $dim) { $thumb = new ElggFile(); $thumb->setFilenameOnFilestore("hjfile/{$file->getGUID()}{$ths}.jpg"); unlink($thumb->getFilenameOnFilestore()); } $file->icontime = time(); $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 60, 60, true); if ($thumbnail) { $thumb = new ElggFile(); $thumb->setFilename($prefix . "thumb" . $filestorename); $thumb->open("write"); $thumb->write($thumbnail); $thumb->close(); $file->thumbnail = $prefix . "thumb" . $filestorename; unset($thumbnail); } $thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 153, 153, true); if ($thumbsmall) { $thumb->setFilename($prefix . "smallthumb" . $filestorename); $thumb->open("write"); $thumb->write($thumbsmall); $thumb->close(); $file->smallthumb = $prefix . "smallthumb" . $filestorename; unset($thumbsmall); } $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 600, 600, false); if ($thumblarge) { $thumb->setFilename($prefix . "largethumb" . $filestorename); $thumb->open("write"); $thumb->write($thumblarge); $thumb->close(); $file->largethumb = $prefix . "largethumb" . $filestorename; unset($thumblarge); } } } /** * Set file folder guids as plugin setting */ $folders = new \ElggBatch('elgg_get_entities_from_metadata', array('types' => 'object', 'subtypes' => 'hjfilefolder', 'metadata_name_value_pairs' => array('name' => 'handler', 'value' => 'hjwall'), 'limit' => false)); foreach ($folders as $folder) { elgg_set_plugin_user_setting('wall_collection', $folder->guid, $folder->owner_guid, 'hypeWall'); } /** * Convert 'hjfilefolder' to 'wall_collection' */ $subtypeIdFrom = add_subtype('object', 'hjfilefolder'); $subtypeIdTo = add_subtype('object', 'wallcollection'); $dbprefix = elgg_get_config('dbprefix'); $query = "\tUPDATE {$dbprefix}entities e\n\t\t\t\tJOIN {$dbprefix}metadata md ON md.entity_guid = e.guid\n\t\t\t\tJOIN {$dbprefix}metastrings msn ON msn.id = md.name_id\n\t\t\t\tJOIN {$dbprefix}metastrings msv ON msv.id = md.value_id\n\t\t\t\tSET e.subtype = {$subtypeIdTo}\n\t\t\t\tWHERE e.subtype = {$subtypeIdFrom} AND msn.string = 'handler' AND msv.string = 'hjwall' "; elgg_set_ignore_access($ia); }
// rename display name to inactive $user->name = elgg_echo('member_selfdelete:inactive:user'); // reset avatar to system default unset($user->icontime); // delete all metadata on the user - all profile fields etc. // includes anything set by any other plugins // essentially resets to clean user $metadata = elgg_get_metadata(array('guid' => $user->guid, 'limit' => false)); if (is_array($metadata)) { foreach ($metadata as $data) { $data->delete(); } } // delete all relationships in both directions $relationships1 = get_entity_relationships($user->guid, FALSE); $relationships2 = get_entity_relationships($user->guid, TRUE); $relationships = array_merge($relationships1, $relationships2); if (is_array($relationships)) { foreach ($relationships as $relationship) { if ($relationship->relationship == 'member_of_site') { continue; } $relationship->delete(); } } // delete all annotations on the user $annotations = elgg_get_annotations(array('guids' => array($user->guid))); if (is_array($annotations)) { foreach ($annotations as $annotation) { $annotation->delete(); }
public static function getRelationships($entity_guid) { $return = array(); $relation = get_entity_relationships($entity_guid); if ($relation) { foreach ($relation as $data) { $return[$data->id]['relationship'] = $data->relationship; $return[$data->id]['guid_one'] = $data->guid_one; $return[$data->id]['guid_two'] = $data->guid_two; } } return $return; }