Esempio n. 1
0
File: import.php Progetto: n8b/VMN
<?php

use Ambercal\SettingsTransfer\Util;
if (!isset($_FILES['json']['name']) || $_FILES['json']['error'] != UPLOAD_ERR_OK) {
    $error = elgg_get_friendly_upload_error($_FILES['json']['error']);
} else {
    $contents = @file_get_contents($_FILES['json']['tmp_name']);
    $json = @json_decode($contents, true);
}
if (empty($json)) {
    if (!$error) {
        $error = elgg_echo('admin:plugin_settings_transfer:upload:invalid_json');
    }
    register_error($error);
    forward(REFERER);
}
$plugins = elgg_get_plugins('all');
$options = get_input('options', array());
$import_options = array();
foreach ($options as $option) {
    $import_options[$option] = true;
}
$errors = Util::import($json, $import_options);
if ($errors) {
    system_message(elgg_echo('admin:plugin_settings_transfer:import:error', array($errors)));
} else {
    system_message(elgg_echo('admin:plugin_settings_transfer:import:success'));
}
elgg_invalidate_simplecache();
elgg_reset_system_cache();
forward(REFERER);
<?php

/**
 * Avatar upload action
 */
$guid = get_input('guid');
$owner = get_entity($guid);
if (!$owner || !$owner instanceof ElggUser || !$owner->canEdit()) {
    register_error(elgg_echo('avatar:upload:fail'));
    forward(REFERER);
}
$error = elgg_get_friendly_upload_error($_FILES['avatar']['error']);
if ($error) {
    register_error($error);
    forward(REFERER);
}
$icon_sizes = elgg_get_config('icon_sizes');
// get the images and save their file handlers into an array
// so we can do clean up if one fails.
$files = array();
foreach ($icon_sizes as $name => $size_info) {
    $resized = get_resized_image_from_uploaded_file('avatar', $size_info['w'], $size_info['h'], $size_info['square'], $size_info['upscale']);
    if ($resized) {
        //@todo Make these actual entities.  See exts #348.
        $file = new ElggFile();
        $file->owner_guid = $guid;
        $file->setFilename("profile/{$guid}{$name}.jpg");
        $file->open('write');
        $file->write($resized);
        $file->close();
        $files[] = $file;
Esempio n. 3
0
<?php

use hypeJunction\CKFile;
if (!headers_sent()) {
    header("Content-type: text/html");
}
if (!elgg_get_plugin_setting('allow_uploads', 'ckeditor_addons')) {
    echo elgg_echo('ckeditor:upload:not_allowed');
    exit;
}
if ($_FILES['upload']['error'] != UPLOAD_ERR_OK) {
    echo elgg_get_friendly_upload_error($_FILES['upload']['error']);
    exit;
}
$callback = get_input('CKEditorFuncNum');
$user = elgg_get_logged_in_user_entity();
$file = new CKFile();
$file->owner_guid = $user->guid;
$mimetype = $file->detectMimeType($_FILES['upload']['tmp_name'], $_FILES['upload']['type']);
switch ($mimetype) {
    case 'image/png':
    case 'image/jpeg':
    case 'image/jpg':
        $ext = 'jpg';
        $max_width = (int) elgg_get_plugin_setting('upload_max_width', 'ckeditor_addons', 600);
        $contents = get_resized_image_from_existing_file($_FILES['upload']['tmp_name'], $max_width, $max_width);
        break;
    case 'image/gif':
        $ext = 'gif';
        $contents = file_get_contents($_FILES['upload']['tmp_name']);
        break;
Esempio n. 4
0
 *
 */
$guid = get_input('guid');
$files = _elgg_services()->request->files;
if (!$files->has('file')) {
    register_error(elgg_echo('upload:error:no_file'));
    forward(REFERER);
}
$file = $files->get('file');
if (empty($file)) {
    // A file input was provided but no file uploaded
    register_error(elgg_echo('upload:error:no_tmp_dir'));
    forward(REFERER);
}
if ($file->getError() !== 0) {
    register_error(elgg_get_friendly_upload_error($file->getError()));
    forward(REFERER);
}
$site = elgg_get_site_entity();
$validator = h5p_get_instance('validator');
$interface = h5p_get_instance('interface');
/*
echo "<pre>";
var_dump($file);
var_dump($file->getPathName());
var_dump(file_exists($file->getPathName()));
var_dump(elgg_get_data_path() . "h5p/{$file->getClientOriginalName()}");
die;
*/
$h5p_dir = elgg_get_data_path() . "h5p/";
if (!file_exists($h5p_dir)) {
 /**
  * Save uploaded files
  *
  * @param string $input_name Form input name
  * @param array  $attributes File attributes
  * @return ElggFile[]
  */
 protected function saveUploadedFiles($input_name, array $attributes = [])
 {
     $files = [];
     $uploaded_files = $this->getUploadedFiles($input_name);
     $subtype = elgg_extract('subtype', $attributes, 'file', false);
     unset($attributes['subtype']);
     $class = get_subtype_class('object', $subtype);
     if (!$class || !class_exists($class) || !is_subclass_of($class, ElggFile::class)) {
         $class = ElggFile::class;
     }
     foreach ($uploaded_files as $upload) {
         if (!$upload->isValid()) {
             $error = new \stdClass();
             $error->error = elgg_get_friendly_upload_error($upload->getError());
             $files[] = $error;
             continue;
         }
         $file = new $class();
         $file->subtype = $subtype;
         foreach ($attributes as $key => $value) {
             $file->{$key} = $value;
         }
         $old_filestorename = '';
         if ($file->exists()) {
             $old_filestorename = $file->getFilenameOnFilestore();
         }
         $originalfilename = $upload->getClientOriginalName();
         $file->originalfilename = $originalfilename;
         if (empty($file->title)) {
             $file->title = htmlspecialchars($file->originalfilename, ENT_QUOTES, 'UTF-8');
         }
         $file->upload_time = time();
         $prefix = $file->filestore_prefix ?: 'file';
         $prefix = trim($prefix, '/');
         $filename = elgg_strtolower("{$prefix}/{$file->upload_time}{$file->originalfilename}");
         $file->setFilename($filename);
         $file->filestore_prefix = $prefix;
         $hook_params = ['file' => $file, 'upload' => $upload];
         $uploaded = _elgg_services()->hooks->trigger('upload', 'file', $hook_params);
         if ($uploaded !== true && $uploaded !== false) {
             $filestorename = $file->getFilenameOnFilestore();
             try {
                 $uploaded = $upload->move(pathinfo($filestorename, PATHINFO_DIRNAME), pathinfo($filestorename, PATHINFO_BASENAME));
             } catch (FileException $ex) {
                 elgg_log($ex->getMessage(), 'ERROR');
                 $uploaded = false;
             }
         }
         if (!$uploaded) {
             $error = new \stdClass();
             $error->error = elgg_echo('dropzone:file_not_entity');
             $files[] = $error;
             continue;
         }
         if ($old_filestorename && $old_filestorename != $file->getFilenameOnFilestore()) {
             // remove old file
             unlink($old_filestorename);
         }
         $mime_type = $file->detectMimeType(null, $upload->getClientMimeType());
         $file->setMimeType($mime_type);
         $file->simpletype = elgg_get_file_simple_type($mime_type);
         _elgg_services()->events->triggerAfter('upload', 'file', $file);
         if (!$file->save() || !$file->exists()) {
             $file->delete();
             $error = new \stdClass();
             $error->error = elgg_echo('dropzone:file_not_entity');
             $files[] = $error;
             continue;
         }
         if ($file->saveIconFromElggFile($file)) {
             $file->thumbnail = $file->getIcon('small')->getFilename();
             $file->smallthumb = $file->getIcon('medium')->getFilename();
             $file->largethumb = $file->getIcon('large')->getFilename();
         }
         $success = new \stdClass();
         $success->file = $file;
         $files[] = $success;
     }
     return $files;
 }
Esempio n. 6
0
<?php

$guid = (int) get_input('guid');
$access_id = (int) get_input('access_id');
if (!$access_id) {
    $access_id = get_default_access();
}
// check if upload attempted and failed
if (!empty($_FILES['badge']['name']) && $_FILES['badge']['error'] != 0) {
    $error = elgg_get_friendly_upload_error($_FILES['badge']['error']);
    register_error($error);
    forward(REFERER);
}
$badge = get_entity($guid);
$badge->title = get_input('name');
$badge->description = get_input('description');
$badge->access_id = $access_id;
$badge->save();
$badge->badges_name = get_input('name');
$badge->badges_userpoints = get_input('points');
if (get_input('url') != '') {
    $url = get_input('url');
    if (preg_match('/^https?/i', $url)) {
        $badge->badges_url = $url;
    } else {
        $badge->badges_url = elgg_get_config('wwwroot') . $url;
    }
}
if (isset($_FILES['badge']['name']) && !empty($_FILES['badge']['name'])) {
    $filename = $_FILES['badge']['name'];
    $mime = $_FILES['badge']['type'];
Esempio n. 7
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);
Esempio n. 8
0
File: upload.php Progetto: elgg/elgg
// Get variables
$title = htmlspecialchars(get_input('title', '', false), ENT_QUOTES, 'UTF-8');
$desc = get_input("description");
$access_id = (int) get_input("access_id");
$container_guid = (int) get_input('container_guid', 0);
$guid = (int) get_input('file_guid');
$tags = get_input("tags");
if ($container_guid == 0) {
    $container_guid = elgg_get_logged_in_user_guid();
}
elgg_make_sticky_form('file');
// check if upload attempted and failed
$uploaded_files = elgg_get_uploaded_files('upload');
$uploaded_file = array_shift($uploaded_files);
if ($uploaded_file && !$uploaded_file->isValid()) {
    $error = elgg_get_friendly_upload_error($uploaded_file->getError());
    register_error($error);
    forward(REFERER);
}
// check whether this is a new file or an edit
$new_file = true;
if ($guid > 0) {
    $new_file = false;
}
if ($new_file) {
    $file = new ElggFile();
    $file->subtype = "file";
} else {
    // load original file object
    $file = get_entity($guid);
    if (!$file instanceof ElggFile) {