Ejemplo n.º 1
0
/**
 * Icon URL
 *
 * @param type $hook
 * @param type $hook_type
 * @param type $return
 * @param type $params
 * @return type
 */
function elgg_media_url_handler($hook, $hook_type, $return, $params)
{
    $entity = elgg_extract('entity', $params);
    $size = elgg_extract('size', $params, 'medium');
    $type = elgg_extract('type', $params, 'icon');
    $ext = elgg_extract('ext', $params, 'jpg');
    $filename = false;
    if ($size == 'original') {
        $filename = $entity->{"{$type}_originalfilename"};
    } else {
        if (elgg_get_media_file($entity, $type, $size, $ext)) {
            $filename = "{$size}.{$ext}";
        }
    }
    if ($filename) {
        $url = elgg_normalize_url("/mod/elgg_media/media/{$entity->guid}/{$type}/{$filename}");
        // @todo: add hmac
        return elgg_http_add_url_query_elements($url, ['lastcache' => $entity->{"{$type}_time_created"}, 'hmac' => 'todo']);
    }
}
Ejemplo n.º 2
0
/**
 * Removes entity media
 *
 * @param \ElggEntity $entity  Entity
 * @param string      $type    Media type
 * @return bool
 */
function elgg_remove_media(\ElggEntity $entity, $type = 'icon')
{
    $original = elgg_get_media_original($entity, $type);
    if (!$original || !$original->delete()) {
        return false;
    }
    unset($entity->{"{$type}_originalfilename"});
    unset($entity->{"{$type}_time_created"});
    foreach (['x1', 'x2', 'y1', 'y2'] as $c) {
        unset($entity->{"{$type}_{$c}"});
    }
    $success = true;
    $sizes = elgg_media_get_thumb_sizes($entity, $type);
    foreach ($sizes as $size => $opts) {
        $file = elgg_get_media_file($entity, $type, $size);
        if (!$file) {
            continue;
        }
        $file->delete();
    }
    return $success;
}
Ejemplo n.º 3
0
<?php

$guid = get_input('guid');
$entity = get_entity($guid);
$type = get_input('type');
if (!$entity instanceof ElggEntity || !$entity->canEdit() || !elgg_media_is_allowed_type($entity, $type)) {
    register_error(elgg_echo('media:upload:fail'));
    forward(REFERER);
}
if ($_FILES['media']['error'] !== UPLOAD_ERR_NO_FILE && $_FILES['media']['error'] !== UPLOAD_ERR_OK) {
    // file has been uploaded by upload failed
    register_error(elgg_echo('media:upload:fail'));
    register_error(elgg_get_friendly_upload_error($_FILES['media']['error']));
    forward(REFERER);
} else {
    if ($_FILES['media']['error'] === UPLOAD_ERR_OK) {
        // upload was successful, replace media file
        $file = elgg_save_media($_FILES['media'], $entity, $type);
    } else {
        // grab master image
        $file = elgg_get_media_file($entity, $type, 'master');
    }
}
$coords = ['x1' => (int) get_input('x1', 0), 'y1' => (int) get_input('y1', 0), 'x2' => (int) get_input('x2', 0), 'y2' => (int) get_input('y2', 0)];
if (elgg_create_media_thumbnails($file, $entity, $type, $coords)) {
    system_message(elgg_echo('media:crop:success'));
} else {
    die;
    register_error(elgg_echo('media:crop:fail'));
}
forward(REFERER);