Esempio n. 1
0
 /**
  * Transfer group icons to new filestore location
  * Before 3.0, group icons where owned by the group owner
  * and located in /groups/<guid><size>.jpg
  * relative to group owner's filestore directory
  * In 3.0, we are moving these to default filestore location
  * relative to group's filestore directory
  *
  * @param \ElggGroup           $group  Group entity
  * @param \Elgg\Upgrade\Result $result Upgrade result
  * @return \Elgg\Upgrade\Result
  */
 public function transferIcons(\ElggGroup $group, \Elgg\Upgrade\Result $result)
 {
     $sizes = elgg_get_icon_sizes('group', $group->getSubtype());
     $dataroot = elgg_get_config('dataroot');
     $dir = (new \Elgg\EntityDirLocator($group->owner_guid))->getPath();
     $prefix = 'groups/';
     foreach ($sizes as $size => $opts) {
         $filename = "{$group->guid}{$size}.jpg";
         $filestorename = "{$dataroot}{$dir}{$prefix}{$filename}";
         if (!file_exists($filestorename)) {
             // nothing to move
             continue;
         }
         $icon = $group->getIcon($size);
         // before transferring the file, we need to make sure
         // the directory structure of the new filestore location exists
         $icon->open('write');
         $icon->close();
         if (!rename($filestorename, $icon->getFilenameOnFilestore())) {
             $result->addError("\n\t\t\t\t\tFailed to transfer file from '{$filestorename}'\n\t\t\t\t\tto {$icon->getFilenameOnFilestore()}\n\t\t\t\t");
             $error = true;
         }
     }
     if ($error) {
         $result->addFailures();
     } else {
         $result->addSuccesses();
     }
     return $result;
 }
Esempio n. 2
0
/**
 * Remove the icon of a blog
 *
 * @param ElggBlog $blog The blog to remove the icon from
 *
 * @return bool
 */
function blog_tools_remove_blog_icon(ElggBlog $blog)
{
    if (!$blog instanceof ElggBlog) {
        return false;
    }
    if (empty($blog->icontime)) {
        // no icon
        return true;
    }
    $icon_sizes = elgg_get_icon_sizes('object', 'blog');
    if (!empty($icon_sizes)) {
        $fh = new ElggFile();
        $fh->owner_guid = $blog->getOwnerGUID();
        $prefix = "blogs/{$blog->getGUID()}";
        foreach ($icon_sizes as $name => $info) {
            $fh->setFilename("{$prefix}{$name}.jpg");
            if ($fh->exists()) {
                $fh->delete();
            }
        }
    }
    unset($blog->icontime);
    return true;
}
Esempio n. 3
0
 *
 * @uses $vars['entity']     The user entity. If none specified, the current user is assumed.
 * @uses $vars['size']       The size - tiny, small, medium or large. (medium)
 * @uses $vars['use_hover']  Display the hover menu? (true)
 * @uses $vars['use_link']   Wrap a link around image? (true)
 * @uses $vars['class']      Optional class added to the .elgg-avatar div
 * @uses $vars['img_class']  Optional CSS class added to img
 * @uses $vars['link_class'] Optional CSS class for the link
 * @uses $vars['href']       Optional override of the link href
 */
$user = elgg_extract('entity', $vars, elgg_get_logged_in_user_entity());
$size = elgg_extract('size', $vars, 'medium');
if (!$user instanceof ElggUser) {
    return;
}
$icon_sizes = elgg_get_icon_sizes('user');
if (!array_key_exists($size, $icon_sizes)) {
    $size = 'medium';
}
$name = htmlspecialchars($user->name, ENT_QUOTES, 'UTF-8', false);
$username = $user->username;
$class = "elgg-avatar elgg-avatar-{$size}";
if (isset($vars['class'])) {
    $class = "{$class} {$vars['class']}";
}
if ($user->isBanned()) {
    $class .= ' elgg-state-banned';
    $banned_text = elgg_echo('banned');
    $name .= " ({$banned_text})";
}
$use_link = elgg_extract('use_link', $vars, true);
Esempio n. 4
0
File: file.php Progetto: elgg/elgg
/**
 * File icon view
 *
 * @uses $vars['entity']     The entity the icon represents - uses getIconURL() method
 * @uses $vars['size']       topbar, tiny, small, medium (default), large, master
 * @uses $vars['href']       Optional override for link
 * @uses $vars['img_class']  Optional CSS class added to img
 * @uses $vars['link_class'] Optional CSS class added to link
 */
$entity = elgg_extract('entity', $vars);
if (!$entity instanceof ElggFile) {
    elgg_log('icon/object/file view expects an instance of ElggFile', 'ERROR');
    return;
}
$sizes = array_keys(elgg_get_icon_sizes($entity->getType(), $entity->getSubtype()));
$size = elgg_extract('size', $vars, 'medium');
if (!in_array($size, $sizes)) {
    // File plugin only capable of handling 3 sizes
    // Anything that is an unknown size defaults to large
    if ($size == 'topbar' || $size == 'tiny') {
        $size = 'small';
    } else {
        if ($size == 'master') {
            $size = 'large';
        } else {
            $size = "medium";
        }
    }
}
if (isset($vars['href'])) {
Esempio n. 5
0
/**
 * Generic icon view.
 *
 * @package Elgg
 * @subpackage Core
 *
 * @uses $vars['entity']     The entity the icon represents - uses getIconURL() method
 * @uses $vars['size']       topbar, tiny, small, medium (default), large, master
 * @uses $vars['href']       Optional override for link
 * @uses $vars['img_class']  Optional CSS class added to img
 * @uses $vars['link_class'] Optional CSS class for the link
 */
$entity = $vars['entity'];
/* @var ElggEntity $entity */
$icon_sizes = elgg_get_icon_sizes($entity->type, $entity->getSubtype());
// Get size
$size = elgg_extract('size', $vars, 'medium');
if (!array_key_exists($size, $icon_sizes)) {
    $size = "medium";
}
$vars['size'] = $size;
$class = elgg_extract('img_class', $vars, '');
if (isset($entity->name)) {
    $title = $entity->name;
} else {
    $title = $entity->title;
}
$title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8', false);
$url = $entity->getURL();
if (isset($vars['href'])) {
Esempio n. 6
0
 /**
  * Deletes the previous uploaded icon
  *
  * @param string $type Icon type
  * @return bool
  */
 public function deleteIcon($type = 'icon')
 {
     if ($type == 'icon') {
         $fh = new \ElggFile();
         $fh->owner_guid = $this->guid;
         $icon_sizes = elgg_get_icon_sizes('object', 'event');
         foreach ($icon_sizes as $name => $info) {
             $fh->setFilename("{$name}.jpg");
             if ($fh->exists()) {
                 $fh->delete();
             }
         }
         unset($this->icontime);
     }
     return parent::deleteIcon($type);
 }
Esempio n. 7
0
/**
 * Pull in the latest avatar from twitter.
 *
 * @param ElggUser $user
 * @param string   $file_location
 */
function twitter_api_update_user_avatar($user, $file_location)
{
    // twitter's images have a few suffixes:
    // _normal
    // _reasonably_small
    // _mini
    // the twitter app here returns _normal.  We want standard, so remove the suffix.
    // @todo Should probably check that it's an image file.
    $file_location = str_replace('_normal.jpg', '.jpg', $file_location);
    $icon_sizes = elgg_get_icon_sizes('user');
    $filehandler = new ElggFile();
    $filehandler->owner_guid = $user->getGUID();
    foreach ($icon_sizes as $size => $dimensions) {
        $image = get_resized_image_from_existing_file($file_location, $dimensions['w'], $dimensions['h'], $dimensions['square']);
        $filehandler->setFilename("profile/{$user->guid}{$size}.jpg");
        $filehandler->open('write');
        $filehandler->write($image);
        $filehandler->close();
    }
    // update user's icontime
    $user->icontime = time();
}
Esempio n. 8
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 bool
 */
function group_tools_transfer_group_ownership(ElggGroup $group, ElggUser $new_owner)
{
    if (!$group instanceof ElggGroup || !$group->canEdit()) {
        return false;
    }
    if (!$new_owner instanceof ElggUser) {
        return false;
    }
    $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', '\\ColdTrick\\GroupTools\\Access::allowGroupOwnerTransfer');
    $old_owner = $group->getOwnerEntity();
    // transfer ownership
    $group->owner_guid = $new_owner->getGUID();
    $group->container_guid = $new_owner->getGUID();
    if (!$group->save()) {
        return false;
    }
    // make sure user is added to the group
    $group->join($new_owner);
    // 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 = elgg_get_icon_sizes($group->getType());
        $ofh = new ElggFile();
        $ofh->owner_guid = $old_owner->getGUID();
        $nfh = new ElggFile();
        $nfh->owner_guid = $group->getOwnerGUID();
        foreach ($sizes as $size => $info) {
            // set correct file to handle
            $ofh->setFilename("{$prefix}{$size}.jpg");
            if (!$ofh->exists()) {
                // file doesn't exist
                continue;
            }
            $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 = ['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', [$group->name]);
        $message = elgg_echo('group_tools:notify:transfer:message', [$new_owner->name, $loggedin_user->name, $group->name, $group->getURL()]);
        notify_user($new_owner->getGUID(), $group->getGUID(), $subject, $message);
    }
    // unregister plugin hook to make sure transfer can complete
    elgg_unregister_plugin_hook_handler('permissions_check', 'group', '\\ColdTrick\\GroupTools\\Access::allowGroupOwnerTransfer');
    return true;
}
Esempio n. 9
0
/**
 * Listen to entity ownership changes and update icon ownership by moving
 * icons to their new owner's directory on filestore.
 *
 * This will only transfer icons that have a custom location on filestore
 * and are owned by the entity's owner (instead of the entity itself).
 * Even though core icon service does not store icons in the entity's owner
 * directory, there are plugins that do (e.g. file plugin) - this handler
 * helps such plugins avoid ownership mismatch.
 *
 * @param string     $event  "update:after"
 * @param string     $type   "object"|"group"
 * @param ElggObject $entity Entity
 * @return void
 * @access private
 */
function _elgg_filestore_move_icons($event, $type, $entity)
{
    $original_attributes = $entity->getOriginalAttributes();
    if (empty($original_attributes['owner_guid'])) {
        return;
    }
    $previous_owner_guid = $original_attributes['owner_guid'];
    $new_owner_guid = $entity->owner_guid;
    $sizes = elgg_get_icon_sizes($entity->getType(), $entity->getSubtype());
    foreach ($sizes as $size => $opts) {
        $new_icon = $entity->getIcon($size);
        if ($new_icon->owner_guid == $entity->guid) {
            // we do not need to update icons that are owned by the entity itself
            continue;
        }
        if ($new_icon->owner_guid != $new_owner_guid) {
            // a plugin implements some custom logic
            continue;
        }
        $old_icon = new \ElggIcon();
        $old_icon->owner_guid = $previous_owner_guid;
        $old_icon->setFilename($new_icon->getFilename());
        if (!$old_icon->exists()) {
            // there is no icon to move
            continue;
        }
        if ($new_icon->exists()) {
            // there is already a new icon
            // just removing the old one
            $old_icon->delete();
            elgg_log("Entity {$entity->guid} has been transferred to a new owner but an icon was left behind under {$old_icon->getFilenameOnFilestore()}. " . "Old icon has been deleted", 'NOTICE');
            continue;
        }
        $old_icon->transfer($new_icon->owner_guid, $new_icon->getFilename());
        elgg_log("Entity {$entity->guid} has been transferred to a new owner. " . "Icon was moved from {$old_icon->getFilenameOnFilestore()} to {$new_icon->getFilenameOnFilestore()}.", 'NOTICE');
    }
}
Esempio n. 10
0
$completed = (bool) get_input('upgrade_completed', false);
if ($completed) {
    // done with the upgrade
    $factory = new ElggUpgrade();
    $upgrade = $factory->getUpgradeFromPath($path);
    if (!empty($upgrade)) {
        $session->remove('blog_tools_move_icon_offset');
        $upgrade->setCompleted();
        forward(REFERER);
    }
}
$error_offset = (int) get_input('offset');
$start_offset = (int) $session->get('blog_tools_move_icon_offset', 0);
$offset = $error_offset + $start_offset;
// get icon sizes for blogs
$icon_sizes = elgg_get_icon_sizes('object', 'blog');
$result = ['numSuccess' => 0, 'numErrors' => 0];
// get blogs with icons
$batch = new ElggBatch('elgg_get_entities_from_metadata', ['type' => 'object', 'subtype' => 'blog', 'limit' => 10, 'offset' => $offset, 'metadata_name' => 'icontime']);
/* @var $entity \ElggBlog */
foreach ($batch as $entity) {
    $old_file = new ElggFile();
    $old_file->owner_guid = $entity->getOwnerGUID();
    $old_file->setFilename("blogs/{$entity->getGUID()}master.jpg");
    if (!$old_file->exists()) {
        // this blog has no icon on the old location
        // no move needed
        $result['numSuccess']++;
        continue;
    }
    if ($entity->saveIconFromElggFile($old_file)) {
Esempio n. 11
0
}
$event->setMaxAttendees(get_input('max_attendees'));
$event->setRegion(get_input('region'));
$event->setEventType(get_input('event_type'));
$event->event_start = $event_start;
$event->event_end = $event_end;
$event->with_program = get_input('with_program');
$event->endregistration_day = $endregistration_day;
$event->event_interested = 1;
$metadata_fields = ['shortdescription', 'comments_on', 'registration_ended', 'registration_needed', 'show_attendees', 'notify_onsignup', 'waiting_list', 'venue', 'contact_details', 'website', 'organizer', 'fee', 'fee_details', 'register_nologin', 'waiting_list_enabled', 'registration_completed', 'organizer_guids', 'contact_guids'];
foreach ($metadata_fields as $field) {
    $event->{$field} = get_input($field);
}
$has_days = $event->hasEventDays();
$event->generateInitialProgramData();
$icon_sizes = elgg_get_icon_sizes('object', 'event');
$icon_file = get_resized_image_from_uploaded_file('icon', 100, 100);
if ($icon_file) {
    // create icons
    $fh = new \ElggFile();
    $fh->owner_guid = $event->guid;
    foreach ($icon_sizes as $icon_name => $icon_info) {
        $icon_file = get_resized_image_from_uploaded_file('icon', $icon_info['w'], $icon_info['h'], $icon_info['square'], $icon_info['upscale']);
        if ($icon_file) {
            $fh->setFilename("{$icon_name}.jpg");
            if ($fh->open('write')) {
                $fh->write($icon_file);
                $fh->close();
            }
        }
    }