Example #1
0
<?php

$entity = elgg_extract('entity', $vars);
$type = elgg_extract('type', $vars, 'icon');
if (!$entity instanceof \ElggEntity) {
    return;
}
if (!$entity->canEdit() || !elgg_media_is_allowed_type($entity, $type)) {
    return;
}
$current_icon = elgg_view('output/img', ['src' => $entity->getIconURL(['size' => 'small', 'type' => $type]), 'alt' => elgg_echo("media:{$type}")]);
$remove_button = '';
if (elgg_has_media($entity, $type)) {
    $remove_button = elgg_view('output/url', ['text' => elgg_echo('remove'), 'href' => elgg_http_add_url_query_elements('/action/media/remove', ['guid' => $entity->guid, 'type' => $type]), 'is_action' => true, 'confirm' => true, 'class' => 'elgg-button elgg-button-delete']);
}
$form_params = ['enctype' => 'multipart/form-data'];
$upload_form = elgg_view_form('media/upload', $form_params, $vars);
$current = elgg_view_module('aside', elgg_echo('media:current'), $current_icon, ['footer' => $remove_button]);
echo elgg_view_image_block($current, $upload_form, ['class' => 'media-upload-image-block']);
Example #2
0
<?php

$entity = elgg_extract('entity', $vars);
$filter_context = elgg_extract('filter_context', $vars);
foreach (['icon', 'cover', 'skyscraper'] as $type) {
    if (elgg_media_is_allowed_type($entity, $type)) {
        elgg_register_menu_item('filter', ['name' => $type, 'text' => elgg_echo("media:{$type}"), 'href' => "media/{$entity->guid}/edit/{$type}", 'selected' => $filter_context == $type]);
    }
}
echo elgg_view_menu('filter', ['class' => 'elgg-menu-hz', 'sort_by' => 'priority']);
Example #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);