/**
 *funtion to mark the visitor
 */
function izapMarkVisitor()
{
    $ProfileEntity = elgg_get_page_owner_entity();
    $ProfileName = $ProfileEntity->name;
    $ProfileGuid = $ProfileEntity->guid;
    $ProfileOwner = $ProfileEntity->owner_guid;
    $ProfileAccess = $ProfileEntity->access_id;
    $VisitorEntity = elgg_get_logged_in_user_entity();
    $VisitorName = $VisitorEntity->name;
    $VisitorGuid = $VisitorEntity->guid;
    $VisitorsArray = array();
    if ($VisitorGuid != $ProfileGuid && $VisitorEntity && $ProfileEntity) {
        $md = elgg_get_metadata(array('guid' => $ProfileGuid, 'metadata_name' => 'izapProfileVisitor', 'limit' => false));
        $Metadata = array();
        if ($md && count($md) == 1) {
            $Metadata = $md[0];
        } else {
            $Metadata = $md;
        }
        if ($Metadata) {
            $Id = $Metadata->id;
            $VisitorsArray = unserialize($Metadata->value);
            array_unshift($VisitorsArray, $VisitorGuid);
            $InsertArray = array_slice(array_unique($VisitorsArray), 0, 10);
            $InsertArray = serialize($InsertArray);
            izap_update_metadata($Id, 'izapProfileVisitor', $InsertArray, 'text', $ProfileOwner, ACCESS_PUBLIC);
        } else {
            array_unshift($VisitorsArray, $VisitorGuid);
            $InsertArray = serialize($VisitorsArray);
            create_metadata($ProfileGuid, 'izapProfileVisitor', $InsertArray, 'text', $ProfileOwner, ACCESS_PUBLIC);
        }
    }
}
 public function testEGMCanUsePreloader()
 {
     $options = array('limit' => 3);
     elgg_get_metadata($options);
     $this->assertNull($this->mockPreloader->preloaded);
     $options['preload_owners'] = true;
     elgg_get_metadata($options);
     $this->assertEqual(3, count($this->mockPreloader->preloaded));
 }
Пример #3
0
 /**
  * Callback function for token input search
  *
  * @param string $term    Search term
  * @param array  $options Options
  * @return array
  */
 public function search($term, $options = array())
 {
     $term = sanitize_string($term);
     $query = str_replace(array('_', '%'), array('\\_', '\\%'), $term);
     $options['metadata_names'] = array('location', 'temp_location');
     $options['group_by'] = "v.string";
     $options['wheres'] = array("v.string LIKE '%{$query}%'");
     return elgg_get_metadata($options);
 }
Пример #4
0
 /**
  * Get the metadata object for the correct answer
  *
  * @return false|ElggMetadata
  */
 public function getCorrectAnswerMetadata()
 {
     $result = false;
     $options = ['metadata_name' => 'correct_answer', 'guid' => $this->getGUID()];
     $metadata = elgg_get_metadata($options);
     if ($metadata) {
         $result = $metadata[0];
     }
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function handle(ElggEntity $entity)
 {
     $value = get_input($this->getShortname());
     if (!$entity->guid) {
         return $entity;
     }
     $old_owner_guid = $entity->owner_guid;
     $new_owner_guid = $value === null ? $old_owner_guid : (int) $value;
     $owner_has_changed = false;
     $old_icontime = null;
     if (!$new_owner_guid || $new_owner_guid == $old_owner_guid) {
         return $entity;
     }
     $user = elgg_get_logged_in_user_entity();
     // verify new owner is member and old owner/admin is logged in
     if ($entity->isMember(get_user($new_owner_guid)) && ($old_owner_guid == $user->guid || $user->isAdmin())) {
         $entity->owner_guid = $new_owner_guid;
         if ($entity->container_guid == $old_owner_guid) {
             // Even though this action defaults container_guid to the logged in user guid,
             // the group may have initially been created with a custom script that assigned
             // a different container entity. We want to make sure we preserve the original
             // container if it the group is not contained by the original owner.
             $entity->container_guid = $new_owner_guid;
         }
         $metadata = elgg_get_metadata(['guid' => $entity->guid, 'limit' => false]);
         if ($metadata) {
             foreach ($metadata as $md) {
                 if ($md->owner_guid == $old_owner_guid) {
                     $md->owner_guid = $new_owner_guid;
                     $md->save();
                 }
             }
         }
         // @todo Remove this when #4683 fixed
         $owner_has_changed = true;
         $old_icontime = $entity->icontime;
     }
     $must_move_icons = $owner_has_changed && $old_icontime;
     if ($must_move_icons) {
         $filehandler = new ElggFile();
         $filehandler->setFilename('groups');
         $filehandler->owner_guid = $old_owner_guid;
         $old_path = $filehandler->getFilenameOnFilestore();
         $icon_sizes = hypeApps()->iconFactory->getSizes($entity);
         $sizes = array_keys($icon_sizes);
         array_unshift($sizes, '');
         // move existing to new owner
         $filehandler->owner_guid = $entity->owner_guid;
         $new_path = $filehandler->getFilenameOnFilestore();
         foreach ($sizes as $size) {
             rename("{$old_path}/{$entity->guid}{$size}.jpg", "{$new_path}/{$entity->guid}{$size}.jpg");
         }
     }
     return $entity;
 }
Пример #6
0
 public function testElggGetMetadataCount()
 {
     $this->object->title = 'Meta Unit Test';
     $this->object->save();
     $guid = $this->object->getGUID();
     create_metadata($guid, 'tested', 'tested1', 'text', 0, ACCESS_PUBLIC, true);
     create_metadata($guid, 'tested', 'tested2', 'text', 0, ACCESS_PUBLIC, true);
     $count = (int) elgg_get_metadata(array('metadata_names' => array('tested'), 'guid' => $guid, 'count' => true));
     $this->assertIdentical($count, 2);
     $this->object->delete();
 }
 protected function load($guid)
 {
     if (!parent::load($guid)) {
         return false;
     }
     $metadata_options = array('guid' => $guid, 'limit' => false);
     if ($metadata = elgg_get_metadata($metadata_options)) {
         if (!is_array($this->meta_cache)) {
             $this->meta_cache = array();
         }
         foreach ($metadata as $md) {
             $this->meta_cache[$md->name] = $md->value;
         }
     }
     return true;
 }
Пример #8
0
function elggpg_import_key($public_key, $user)
{
    $gpg = new gnupg();
    $info = $gpg->import($public_key);
    $new_fp = $info['fingerprint'];
    $user_fp = current(elgg_get_metadata(array('guid' => $user->guid, 'metadata_name' => 'openpgp_publickey')));
    $access_id = ACCESS_LOGGED_IN;
    if ($user_fp && $user_fp->value != $new_fp) {
        update_metadata($user_fp->id, $user_fp->name, $new_fp, 'text', $user->guid, $access_id);
        $info['imported'] = 1;
    } elseif (!$user_fp) {
        create_metadata($user->guid, "openpgp_publickey", $new_fp, 'text', $user->guid, $access_id);
        $info['imported'] = 1;
    }
    $info['key_id'] = elggpg_fp2keyid($new_fp);
    return $info;
}
Пример #9
0
/**
 * add 'not spammer' and 'delete' links to entity menuy of listed spammers
 * 
 * @param type $hook
 * @param type $type
 * @param type $return
 * @param type $params
 */
function tu_spam_report_spammer_menu($hook, $type, $return, $params)
{
    if (!elgg_instanceof($params['entity'], 'user') || elgg_get_context() != 'reported_spammers') {
        return $return;
    }
    // delete (requires new action due to it being deactivated)
    $href = elgg_add_action_tokens_to_url('action/reported_spam/delete?guid=' . $params['entity']->guid);
    $delete = new ElggMenuItem('delete', elgg_view_icon('delete'), $href);
    $delete->setLinkClass('elgg-requires-confirmation');
    // unspam - will unmark this as spam and reactivate it
    $href = elgg_add_action_tokens_to_url('action/reported_spam/notspammer?guid=' . $params['entity']->guid);
    $unspam = new ElggMenuItem('unspam', elgg_echo('tu_spam_report:notspammer'), $href);
    $unspam->setLinkClass('elgg-requires-confirmation');
    $metadata = elgg_get_metadata(array('guid' => $params['entity']->guid, 'metadata_name' => 'disable_reason', 'metadata_value' => 'content_marked_spam', 'limit' => false));
    $href = false;
    $reported = new ElggMenuItem('reported', elgg_echo('tu_spam_report:reported', array(date('m/d/Y', $metadata[0]->time_created))), $href);
    $return[] = $reported;
    $return[] = $unspam;
    $return[] = $delete;
    return $return;
}
Пример #10
0
 /**
  * Hook to export entity metadata 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 entityMetadataToObject($hook, $type, $returnvalue, $params)
 {
     if (!elgg_in_context('search:index')) {
         return;
     }
     $entity = elgg_extract('entity', $params);
     if (!$entity) {
         return;
     }
     $metadata_names = elgg_trigger_plugin_hook('export:metadata_names', 'elasticsearch', $params, []);
     if (empty($metadata_names)) {
         return;
     }
     $metadata = elgg_get_metadata(['guid' => $entity->getGUID(), 'metadata_names' => $metadata_names, 'limit' => false]);
     if (empty($metadata)) {
         return;
     }
     $result = [];
     foreach ($metadata as $data) {
         $result[] = ['time_created' => date('c', $data->time_created), 'owner_guid' => (int) $data->owner_guid, 'access_id' => (int) $data->access_id, 'name' => $data->name, 'value' => $data->value];
     }
     $returnvalue->metadata = $result;
     return $returnvalue;
 }
Пример #11
0
/**
 * Sets the opengpg_publickey for users having a public key
 *
 * @param ElggObject $item
 * @return bool
 */
function elggpg_2012022501($user)
{
    // it is necessary to load the gpg library to make sure gpg path is set.
    global $MIGRATED;
    $MIGRATED += 1;
    if ($MIGRATED % 100 == 0) {
        error_log(" * elggpg {$user->guid}");
    }
    elgg_load_library('elggpg');
    $user_fp = current(elgg_get_metadata(array('guid' => $user->guid, 'metadata_name' => 'openpgp_publickey')));
    $gnupg = new gnupg();
    if (!$user_fp && $user->email) {
        try {
            $info = $gnupg->keyinfo($user->email);
            $fingerprint = $info[0]['subkeys'][0]['fingerprint'];
            if ($fingerprint) {
                create_metadata($user->guid, "openpgp_publickey", $fingerprint, 'text', $user->guid, ACCESS_LOGGEDIN);
            }
        } catch (Exception $e) {
            // no encryption key
        }
    }
    return true;
}
Пример #12
0
/**
 * Checks if the user is a moderator of any item in the given container
 *
 * @param ElggEntity $container_entity container entity to check in
 * @param ElggUser   $user             user to check
 *
 * @return boolean
 */
function static_is_moderator_in_container(ElggEntity $container_entity, ElggUser $user)
{
    if (empty($container_entity) || empty($user)) {
        return false;
    }
    $dbprefix = elgg_get_config('dbprefix');
    $ia = elgg_set_ignore_access(true);
    $md = elgg_get_metadata(['selects' => ['msv.string as value'], 'metadata_names' => ['moderators'], 'limit' => false, 'joins' => ["JOIN {$dbprefix}metastrings msv ON n_table.value_id = msv.id", "JOIN {$dbprefix}entities e ON n_table.entity_guid = e.guid"], 'wheres' => ['msv.string <> ""', 'e.type = "object" AND e.subtype = ' . get_subtype_id('object', 'static'), 'e.container_guid = ' . $container_entity->getGUID()], 'callback' => function ($row) {
        $value = $row->value;
        if (!empty($value)) {
            return $value;
        }
    }]);
    elgg_set_ignore_access($ia);
    return in_array($user->getGUID(), $md);
}
Пример #13
0
// Group membership - should these be treated with same constants as access permissions?
$is_public_membership = get_input('membership') == ACCESS_PUBLIC;
$group->membership = $is_public_membership ? ACCESS_PUBLIC : ACCESS_PRIVATE;
if ($is_new_group) {
    $group->access_id = ACCESS_PUBLIC;
}
$old_owner_guid = $is_new_group ? 0 : $group->owner_guid;
$new_owner_guid = (int) get_input('owner_guid');
$owner_has_changed = false;
$old_icontime = null;
if (!$is_new_group && $new_owner_guid && $new_owner_guid != $old_owner_guid) {
    // verify new owner is member and old owner/admin is logged in
    if (is_group_member($group_guid, $new_owner_guid) && ($old_owner_guid == $user->guid || $user->isAdmin())) {
        $group->owner_guid = $new_owner_guid;
        $group->container_guid = $new_owner_guid;
        $metadata = elgg_get_metadata(array('guid' => $group_guid, 'limit' => false));
        if ($metadata) {
            foreach ($metadata as $md) {
                if ($md->owner_guid == $old_owner_guid) {
                    $md->owner_guid = $new_owner_guid;
                    $md->save();
                }
            }
        }
        // @todo Remove this when #4683 fixed
        $owner_has_changed = true;
        $old_icontime = $group->icontime;
    }
}
$must_move_icons = $owner_has_changed && $old_icontime;
$group->save();
Пример #14
0
/**
 * Handler called by trigger_plugin_hook on the "export" event.
 *
 * @param string $hook        export
 * @param string $entity_type all
 * @param mixed  $returnvalue Value returned from previous hook
 * @param mixed  $params      Params
 *
 * @return array
 * @access private
 */
function export_metadata_plugin_hook($hook, $entity_type, $returnvalue, $params)
{
    // 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'];
    $name = $params['name'];
    $result = elgg_get_metadata(array('guid' => $guid, 'limit' => 0));
    if ($result) {
        foreach ($result as $r) {
            $returnvalue[] = $r->export();
        }
    }
    return $returnvalue;
}
Пример #15
0
 }
 $list_content .= '<div class="elgg-body">';
 $list_content .= '<fieldset>';
 // display each field for currect category
 $visible_fields = 0;
 foreach ($fields[$cat_guid] as $field) {
     if ($field->user_editable == 'no') {
         // non editable fields should not be on the form
         continue;
     }
     $valtype = $field->metadata_type;
     $metadata_name = $field->metadata_name;
     // get options
     $options = $field->getOptions();
     // get value
     $metadata = elgg_get_metadata(['guid' => $user->guid, 'metadata_name' => $metadata_name, 'limit' => false]);
     if ($metadata) {
         $metadata = $metadata[0];
         $value = $user->{$metadata_name};
         $access_id = $metadata->access_id;
     } else {
         $value = '';
         $access_id = get_default_access($user);
     }
     $visible_fields++;
     $field_result = '<div>';
     $field_result .= elgg_format_element('label', [], $field->getTitle(true));
     $hint = $field->getHint();
     if ($hint) {
         $field_result .= elgg_view('output/pm_hint', ['id' => "more_info_{$metadata_name}", 'text' => $hint]);
     }
/**
 * Get the notification settings for a given user.
 *
 * @param int $user_guid The user id
 *
 * @return stdClass
 */
function get_user_notification_settings($user_guid = 0)
{
    $user_guid = (int) $user_guid;
    if ($user_guid == 0) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    // @todo: holy crap, really?
    $all_metadata = elgg_get_metadata(array('guid' => $user_guid, 'limit' => 0));
    if ($all_metadata) {
        $prefix = "notification:method:";
        $return = new stdClass();
        foreach ($all_metadata as $meta) {
            $name = substr($meta->name, strlen($prefix));
            $value = $meta->value;
            if (strpos($meta->name, $prefix) === 0) {
                $return->{$name} = $value;
            }
        }
        return $return;
    }
    return false;
}
Пример #17
0
/**
 * Update the Elgg profile with LinkedIn data
 *
 * @param int $user_guid the user_guid of the profile to update
 *
 * @return void
 */
function socialink_linkedin_sync_profile_metadata($user_guid = 0)
{
    global $CONFIG;
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    // can we get a user
    if (($user = get_user($user_guid)) && socialink_linkedin_is_connected($user_guid)) {
        // does the user allow sync
        if (elgg_get_plugin_user_setting("linkedin_sync_allow", $user->getGUID(), "socialink") != "no") {
            // get configured fields and network fields
            if (($configured_fields = socialink_get_configured_network_fields("linkedin")) && ($network_fields = socialink_get_network_fields("linkedin"))) {
                // ask the api for all fields
                if ($api_result = socialink_linkedin_get_profile_information($user->getGUID())) {
                    $api_result = json_decode($api_result);
                    // check settings for each field
                    foreach ($configured_fields as $setting_name => $profile_field) {
                        $setting = "linkedin_sync_" . $setting_name;
                        if (elgg_get_plugin_user_setting($setting, $user->getGUID(), "socialink") != "no") {
                            $api_setting = $network_fields[$setting_name];
                            // get the correct value from api result
                            if (stristr($api_setting, "->")) {
                                $temp_fields = explode("->", $api_setting);
                                $temp_result = $api_result;
                                for ($i = 0; $i < count($temp_fields); $i++) {
                                    $temp_result = $temp_result->{$temp_fields}[$i];
                                }
                            } else {
                                $temp_result = $api_result->{$api_setting};
                            }
                            // are we dealing with a tags profile field type
                            if (!empty($CONFIG->profile) && is_array($CONFIG->profile)) {
                                if (array_key_exists($profile_field, $CONFIG->profile) && $CONFIG->profile[$profile_field] == "tags") {
                                    $temp_result = string_to_tag_array($temp_result);
                                }
                            }
                            // check if the user has this metadata field, to get access id
                            $params = array("guid" => $user->getGUID(), "metadata_name" => $profile_field, "limit" => false);
                            if ($metadata = elgg_get_metadata($params)) {
                                if (is_array($metadata)) {
                                    $access_id = $metadata[0]->access_id;
                                } else {
                                    $access_id = $metadata->access_id;
                                }
                            } else {
                                $access_id = get_default_access($user);
                            }
                            // remove metadata to set new values
                            elgg_delete_metadata($params);
                            // make new metadata field
                            if (!empty($temp_result)) {
                                if (is_array($temp_result)) {
                                    foreach ($temp_result as $index => $temp_value) {
                                        if ($index > 0) {
                                            $multiple = true;
                                        } else {
                                            $multiple = false;
                                        }
                                        create_metadata($user->getGUID(), $profile_field, $temp_value, 'text', $user->getGUID(), $access_id, $multiple);
                                    }
                                } else {
                                    create_metadata($user->getGUID(), $profile_field, $temp_result, 'text', $user->getGUID(), $access_id);
                                }
                            }
                        }
                    }
                }
            }
            // sync profile icon, only if the user has no icon
            if (empty($user->icontime)) {
                socialink_linkedin_sync_profile_icon($user->getGUID());
            }
        }
    }
}
Пример #18
0
function profile_manager_get_user_profile_data(ElggUser $user)
{
    $profile_fields = elgg_get_config('profile_fields');
    $result = false;
    if (!empty($user) && !empty($profile_fields)) {
        $fields = array_keys($profile_fields);
        $fields[] = "custom_profile_type";
        $options = array("metadata_names" => $fields, "guid" => $user->getGUID(), "limit" => false);
        $rows = elgg_get_metadata($options);
        if ($rows) {
            $result = array();
            foreach ($rows as $row) {
                if (!array_key_exists($row->name, $result)) {
                    // create object
                    $object = new stdClass();
                    $object->name = $row->name;
                    $object->value = $row->value;
                    $object->access_id = $row->access_id;
                    $result[$row->name] = $object;
                } else {
                    $result[$row->name]->value = $row->value . ", " . $result[$row->name]->value;
                }
            }
        }
    }
    return $result;
}
Пример #19
0
         // open files
         $ofh->open("read");
         $nfh->open("write");
         // copy file
         $nfh->write($ofh->grabFile());
         // close file
         $ofh->close();
         $nfh->close();
         // cleanup old file
         $ofh->delete();
     }
     $group->icontime = time();
 }
 // move metadata of the group to the new owner
 $options = array("guid" => $group->getGUID(), "limit" => false);
 if ($metadata = elgg_get_metadata($options)) {
     foreach ($metadata as $md) {
         if ($md->owner_guid == $old_owner->getGUID()) {
             $md->owner_guid = $new_owner->getGUID();
             $md->save();
         }
     }
 }
 // notify new owner
 if ($new_owner->getGUID() != $loggedin_user->getGUID()) {
     $subject = elgg_echo("group_tools:notify:transfer:subject", array($group->name));
     $message = elgg_echo("group_tools:notify:transfer:message", array($new_owner->name, $loggedin_user->name, $group->name, $group->getURL()));
     notify_user($new_owner->getGUID(), $group->getGUID(), $subject, $message);
 }
 // success message
 system_message(elgg_echo("group_tools:action:admin_transfer:success", array($new_owner->name)));
Пример #20
0
/**
 * Return all the metadata for a given GUID.
 *
 * @param int $entity_guid Entity GUID
 *
 * @return mixed
 * @deprecated 1.8 Use elgg_get_metadata()
 */
function get_metadata_for_entity($entity_guid)
{
    elgg_deprecated_notice('get_metadata_for_entity() is deprecated by elgg_get_metadata()', 1.8);
    if (!$entity_guid) {
        return false;
    }
    $options = array('guid' => $entity_guid, 'limit' => 0);
    return elgg_get_metadata($options);
}
Пример #21
0
 /**
  * Return the value of a piece of metadata.
  *
  * @param string $name Name
  *
  * @return mixed The value, or null if not found.
  */
 public function getMetadata($name)
 {
     $guid = $this->getGUID();
     if (!$guid) {
         if (isset($this->temp_metadata[$name])) {
             // md is returned as an array only if more than 1 entry
             if (count($this->temp_metadata[$name]) == 1) {
                 return $this->temp_metadata[$name][0];
             } else {
                 return $this->temp_metadata[$name];
             }
         } else {
             return null;
         }
     }
     // upon first cache miss, just load/cache all the metadata and retry.
     // if this works, the rest of this function may not be needed!
     $cache = _elgg_services()->metadataCache;
     if ($cache->isLoaded($guid)) {
         return $cache->getSingle($guid, $name);
     } else {
         $cache->populateFromEntities(array($guid));
         // in case ignore_access was on, we have to check again...
         if ($cache->isLoaded($guid)) {
             return $cache->getSingle($guid, $name);
         }
     }
     $md = elgg_get_metadata(array('guid' => $guid, 'metadata_name' => $name, 'limit' => 0, 'distinct' => false));
     $value = null;
     if ($md && !is_array($md)) {
         $value = $md->value;
     } elseif (count($md) == 1) {
         $value = $md[0]->value;
     } else {
         if ($md && is_array($md)) {
             $value = metadata_array_to_values($md);
         }
     }
     return $value;
 }
Пример #22
0
function follow_tags_get_activity_follow_tags($options)
{
    $dbprefix = elgg_get_config("dbprefix");
    $tags = elgg_get_metadata(array(follow_tags_get_tag_guid(elgg_get_logged_in_user_guid()), 'tags'));
    $cnt = 0;
    //Count the followTags and Create string for the SQL-query
    switch (count($tags)) {
        case 0:
            break;
        case 1:
            $tagid = $tags['value_id'];
            $value_ids = "value_id = {$tagid}";
            break;
        default:
            foreach ($tags as $tag) {
                $tagid = $tag['value_id'];
                $cnt++;
                if ($cnt != count($tags)) {
                    $value_ids .= "value_id = {$tagid}";
                    $value_ids .= " OR ";
                } else {
                    $value_ids .= "value_id = {$tagid}";
                }
            }
            break;
    }
    //Check if the user have any FollowTags
    $user = elgg_get_logged_in_user_entity();
    $user = $user->username;
    if (count($tags) != 0) {
        $sql_where = "object_guid IN (SELECT entity_guid FROM {$dbprefix}metadata WHERE {$value_ids}) AND action_type = 'create'";
        $options['wheres'] = array($sql_where);
        $activity = elgg_list_river($options);
    }
    return $activity;
}
Пример #23
0
<div>
	<label><?php 
echo elgg_echo('user:name:label');
?>
</label>
	<?php 
echo elgg_view('input/text', array('name' => 'name', 'value' => $vars['entity']->name));
?>
</div>
<?php 
$sticky_values = elgg_get_sticky_values('profile:edit');
$profile_fields = elgg_get_config('profile_fields');
if (is_array($profile_fields) && count($profile_fields) > 0) {
    foreach ($profile_fields as $shortname => $valtype) {
        $metadata = elgg_get_metadata(array('guid' => $vars['entity']->guid, 'metadata_name' => $shortname, 'limit' => false));
        if ($metadata) {
            if (is_array($metadata)) {
                $value = '';
                foreach ($metadata as $md) {
                    if (!empty($value)) {
                        $value .= ', ';
                    }
                    $value .= $md->value;
                    $access_id = $md->access_id;
                }
            } else {
                $value = $metadata->value;
                $access_id = $metadata->access_id;
            }
        } else {
Пример #24
0
 /**
  * {@inheritdoc}
  */
 public function handle(\ElggEntity $entity)
 {
     $shortname = $this->getShortname();
     if ($entity->guid) {
         $current_metadata = elgg_get_metadata(array('guids' => (int) $entity->guid, 'metadata_names' => $shortname, 'limit' => 0));
         if (!empty($current_metadata)) {
             foreach ($current_metadata as $md) {
                 $current_metadata_ids[] = $md->id;
             }
         }
     }
     if (empty($current_metadata_ids)) {
         $current_metadata_ids = array();
     }
     $future_metadata = get_input($this->getShortname(), array());
     $params = array('field' => $this, 'entity' => $entity, 'metadata_name' => $shortname, 'value' => $current_metadata, 'future_value' => $future_metadata);
     // Allow plugins to prevent metadata from being changed
     if (!elgg_trigger_plugin_hook('handle:metadata:before', 'prototyper', $params, true)) {
         return $entity;
     }
     $future_metadata_ids = elgg_extract('id', $future_metadata, array());
     $to_delete = array_diff($current_metadata_ids, $future_metadata_ids);
     if (!empty($to_delete)) {
         elgg_delete_metadata(array('guids' => (int) $entity->guid, 'metadata_ids' => $to_delete, 'limit' => 0));
     }
     $keys = array_keys(elgg_extract('name', $future_metadata, array()));
     $ids = array();
     foreach ($keys as $i) {
         $id = $future_metadata['id'][$i];
         $name = $future_metadata['name'][$i];
         $value = $future_metadata['value'][$i];
         $value_type = $this->getValueType();
         $input_type = $this->getType();
         if ($value_type == 'tags' || !$value_type && $input_type == 'tags') {
             $value = string_to_tag_array($value);
         }
         $access_id = $future_metadata['access_id'][$i];
         $owner_guid = $future_metadata['owner_guid'][$i];
         if (!is_array($value)) {
             if ($id) {
                 update_metadata($id, $name, $value, '', $owner_guid, $access_id);
             } else {
                 $id = create_metadata($entity->guid, $name, $value, '', $owner_guid, $access_id, true);
             }
             $ids[] = $id;
         } else {
             if ($id) {
                 elgg_delete_metadata_by_id($id);
             }
             foreach ($value as $val) {
                 $ids[] = create_metadata($entity->guid, $name, $val, '', $owner_guid, $access_id, true);
             }
         }
     }
     $params = array('field' => $this, 'entity' => $entity, 'metadata_name' => $shortname, 'value' => count($ids) ? elgg_get_metadata(array('metadata_ids' => $ids)) : array(), 'previous_value' => $current_metadata);
     elgg_trigger_plugin_hook('handle:metadata:after', 'prototyper', $params, true);
     return $entity;
 }
Пример #25
0
/**
 * Helper function to transfer the ownership of a group to a new user
 *
 * @param ElggGroup $group     the group to transfer
 * @param ElggUser  $new_owner the new owner
 *
 * @return boolean
 */
function group_tools_transfer_group_ownership(ElggGroup $group, ElggUser $new_owner)
{
    $result = false;
    if (empty($group) || !elgg_instanceof($group, "group") || !$group->canEdit()) {
        return $result;
    }
    if (empty($new_owner) || !elgg_instanceof($new_owner, "user")) {
        return $result;
    }
    $loggedin_user = elgg_get_logged_in_user_entity();
    // register plugin hook to make sure transfer can complete
    elgg_register_plugin_hook_handler("permissions_check", "group", "group_tools_admin_transfer_permissions_hook");
    $old_owner = $group->getOwnerEntity();
    // transfer ownership
    $group->owner_guid = $new_owner->getGUID();
    $group->container_guid = $new_owner->getGUID();
    // make sure user is added to the group
    $group->join($new_owner);
    if ($group->save()) {
        // remove existing group administrator role for new owner
        remove_entity_relationship($new_owner->getGUID(), "group_admin", $group->getGUID());
        // check for group icon
        if (!empty($group->icontime)) {
            $prefix = "groups/" . $group->getGUID();
            $sizes = array("", "tiny", "small", "medium", "large");
            $ofh = new ElggFile();
            $ofh->owner_guid = $old_owner->getGUID();
            $nfh = new ElggFile();
            $nfh->owner_guid = $group->getOwnerGUID();
            foreach ($sizes as $size) {
                // set correct file to handle
                $ofh->setFilename($prefix . $size . ".jpg");
                $nfh->setFilename($prefix . $size . ".jpg");
                // open files
                $ofh->open("read");
                $nfh->open("write");
                // copy file
                $nfh->write($ofh->grabFile());
                // close file
                $ofh->close();
                $nfh->close();
                // cleanup old file
                $ofh->delete();
            }
            $group->icontime = time();
        }
        // move metadata of the group to the new owner
        $options = array("guid" => $group->getGUID(), "limit" => false);
        $metadata = elgg_get_metadata($options);
        if (!empty($metadata)) {
            foreach ($metadata as $md) {
                if ($md->owner_guid == $old_owner->getGUID()) {
                    $md->owner_guid = $new_owner->getGUID();
                    $md->save();
                }
            }
        }
        // notify new owner
        if ($new_owner->getGUID() != $loggedin_user->getGUID()) {
            $subject = elgg_echo("group_tools:notify:transfer:subject", array($group->name));
            $message = elgg_echo("group_tools:notify:transfer:message", array($new_owner->name, $loggedin_user->name, $group->name, $group->getURL()));
            notify_user($new_owner->getGUID(), $group->getGUID(), $subject, $message);
        }
        $result = true;
    }
    // unregister plugin hook to make sure transfer can complete
    elgg_unregister_plugin_hook_handler("permissions_check", "group", "group_tools_admin_transfer_permissions_hook");
    return $result;
}
Пример #26
0
         $_SESSION['registerevent_values']['question_' . $question->getGUID()] = $answers[$question->getGUID()];
     }
 }
 // @todo: replace with sticky form functions
 // @todo: make program also sticky
 if (empty($user)) {
     $_SESSION['registerevent_values']['question_name'] = $answers["name"];
     $_SESSION['registerevent_values']['question_email'] = $answers["email"];
 }
 if ($event->with_program && !$required_error) {
     if (empty($program_guids)) {
         $required_error = true;
     } else {
         // validate slot sets
         $slot_options = array("type" => "object", "subtype" => EventSlot::SUBTYPE, "limit" => false, "metadata_names" => "slot_set", "guids" => explode(',', $program_guids));
         if ($set_metadata = elgg_get_metadata($slot_options)) {
             $sets_found = array();
             foreach ($set_metadata as $md) {
                 $set_name = $md->value;
                 if (in_array($set_name, $sets_found)) {
                     // only one programguid per slot is allowed
                     register_error(elgg_echo("event_manager:action:registration:edit:error_slots", array($set_name)));
                     forward($forward_url);
                 }
                 $sets_found[] = $set_name;
             }
         }
     }
 }
 if ($required_error) {
     if ($event->with_program) {
Пример #27
0
<?php

$id = get_input("id");
if (!empty($id)) {
    $edit = true;
    $faq = get_entity($id);
}
$count = elgg_get_entities(array('type' => "object", 'subtype' => "faq", 'limit' => false, 'offset' => 0, 'count' => true));
$metadatas = elgg_get_metadata(array('annotation_name' => "category", 'type' => "object", 'subtype' => "faq", 'limit' => $count));
$cats = array();
foreach ($metadatas as $metadata) {
    $cat = $metadata['value'];
    if (!in_array($cat, $cats)) {
        $cats[] = $cat;
    }
}
$select = "<select name='oldCat' id='oldCat' onChange='checkCat();'>";
if (!$edit) {
    $select .= "<option value=''>" . elgg_echo("faq:add:oldcat:please") . "</option>";
}
foreach ($cats as $cat) {
    if ($edit && $faq->category == $cat) {
        $select .= "<option SELECTED>" . $cat . "</option>";
    } else {
        $select .= "<option>" . $cat . "</option>";
    }
}
$select .= "<option value='newCat'>" . elgg_echo("faq:add:oldcat:new") . "</option>";
$select .= "</select>";
// Access Selector
$accessSelector = "<select name='access'>";
Пример #28
0
/**
 * Handler called by trigger_plugin_hook on the "export" event.
 *
 * @param string $hook        export
 * @param string $entity_type all
 * @param mixed  $returnvalue Value returned from previous hook
 * @param mixed  $params      Params
 *
 * @return array
 * @access private
 *
 * @throws InvalidParameterException
 * @deprecated 1.9
 */
function export_metadata_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");
    }
    $result = elgg_get_metadata(array('guid' => (int) $params['guid'], 'limit' => 0));
    if ($result) {
        /* @var \ElggMetadata[] $result */
        foreach ($result as $r) {
            $returnvalue[] = $r->export();
        }
    }
    return $returnvalue;
}
Пример #29
0
function elgg_solr_add_update_user($entity)
{
    if (!elgg_instanceof($entity, 'user')) {
        return false;
    }
    if (!is_registered_entity_type($entity->type, $entity->getSubtype())) {
        return false;
    }
    // lump public profile fields in with description
    $profile_fields = elgg_get_config('profile_fields');
    $desc = '';
    if (is_array($profile_fields) && sizeof($profile_fields) > 0) {
        $walled = elgg_get_config('walled_garden');
        foreach ($profile_fields as $shortname => $valtype) {
            $md = elgg_get_metadata(array('guid' => $entity->guid, 'metadata_names' => array($shortname)));
            foreach ($md as $m) {
                if ($m->access_id == ACCESS_PUBLIC || $walled && $m->access_id == ACCESS_LOGGED_IN) {
                    $desc .= $m->value . ' ';
                }
            }
        }
    }
    $client = elgg_solr_get_client();
    $commit = elgg_get_config('elgg_solr_nocommit') ? false : true;
    $query = $client->createUpdate();
    $subtype = $entity->getSubtype() ? $entity->getSubtype() : '';
    // add document
    $doc = $query->createDocument();
    $doc->id = $entity->guid;
    $doc->type = $entity->type;
    $doc->subtype = $subtype;
    $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->username = $entity->username;
    $doc->description = elgg_strip_tags($desc);
    $doc->time_created = $entity->time_created;
    $doc = elgg_solr_add_tags($doc, $entity);
    $doc->enabled = $entity->enabled;
    $params = array('entity' => $entity);
    $doc = elgg_trigger_plugin_hook('elgg_solr:index', $entity->type, $params, $doc);
    if (!$doc) {
        return true;
        // a plugin has stopped the index
    }
    $query->addDocument($doc, true);
    if ($commit) {
        $query->addCommit();
    }
    // this executes the query and returns the result
    try {
        $client->update($query);
    } catch (Exception $exc) {
        error_log($exc->getMessage());
    }
    return true;
}
Пример #30
0
 public function testElggDeleteMetadata()
 {
     $e = new ElggObject();
     $e->save();
     for ($i = 0; $i < 30; $i++) {
         $name = "test_metadata{$i}";
         $e->{$name} = rand(0, 10000);
     }
     $options = array('guid' => $e->getGUID(), 'limit' => 0);
     $md = elgg_get_metadata($options);
     $this->assertIdentical(30, count($md));
     $this->assertTrue(elgg_delete_metadata($options));
     $md = elgg_get_metadata($options);
     $this->assertTrue(empty($md));
     $e->delete();
 }