Ejemplo n.º 1
0
$entity->extended_address = $extended_address;
$entity->locality = $locality;
$entity->region = $region;
$entity->postal_code = $postal_code;
$entity->country_code = $country_iso;
if ($entity->country_code && is_callable(array('hypeJunction\\Geo\\Countries', 'getCountries'))) {
    $countries = call_user_func(array('hypeJunction\\Geo\\Countries', 'getCountries'), 'iso', 'name', 'name');
    $country = $countries[$country_iso];
}
$entity->country = $country;
$entity->phone = get_input('phone');
$entity->website = get_input('website');
$entity->twitter = get_input('twitter');
$tools = get_input('tools', array());
$entity->checkins = elgg_extract('checkins', $tools, false);
if ($entity->save()) {
    $entity->location = implode(', ', array_filter(array($street_address, $extended_address, $locality, $region, $postal_code, $country)));
    if (!empty($_FILES['icon']['name']) && $_FILES['icon']['error'] == UPLOAD_ERR_OK && substr_count($_FILES['icon']['type'], 'image/')) {
        IconHandler::makeIcons($entity, $_FILES['icon']['tmp_name']);
    }
    if ($river) {
        elgg_create_river_item(array('view' => 'framework/river/places/create', 'action_type' => 'create', 'subject_guid' => $entity->owner_guid, 'object_guid' => $entity->guid));
    }
    elgg_clear_sticky_form('places/edit');
    system_message(elgg_echo('places:edit:success', array($entity->title)));
    $forward_url = $entity->getURL();
} else {
    register_error(elgg_echo('places:edit:error'));
    $forward_url = REFERER;
}
forward($forward_url);
 /**
  * Create new entities from file uploads
  *
  * @param string $input Name of the file input
  * @return void
  */
 protected static function entityFactory($input)
 {
     if (!isset(self::$config['filestore_prefix'])) {
         $prefix = "file/";
     }
     $uploads = self::$uploads[$input];
     $handled_uploads = array();
     $entities = array();
     foreach ($uploads as $key => $upload) {
         if ($upload->error) {
             $handled_uploads[] = $upload;
             continue;
         }
         $filehandler = new ElggFile();
         if (is_array(self::$attributes)) {
             foreach (self::$attributes as $key => $value) {
                 $filehandler->{$key} = $value;
             }
         }
         $filestorename = elgg_strtolower(time() . $upload->name);
         $filehandler->setFilename($prefix . $filestorename);
         $filehandler->title = $upload->name;
         $filehandler->originalfilename = $upload->name;
         $filehandler->filesize = $upload->size;
         $filehandler->mimetype = $upload->mimetype;
         $filehandler->simpletype = $upload->simpletype;
         $filehandler->open("write");
         $filehandler->close();
         move_uploaded_file($upload->path, $filehandler->getFilenameOnFilestore());
         if ($filehandler->save()) {
             $upload->guid = $filehandler->getGUID();
             $upload->file = $filehandler;
             if ($filehandler->simpletype == "image") {
                 IconHandler::makeIcons($filehandler);
             }
             $entities[] = $filehandler;
         } else {
             $upload->error = elgg_echo('upload:error:unknown');
         }
         $handled_uploads[] = $upload;
     }
     self::$uploads[$input] = $handled_uploads;
     self::$files[$input] = $entities;
 }
Ejemplo n.º 3
0
<?php

namespace hypeJunction\Gallery;

use ElggFile;
use hypeJunction\Filestore\IconHandler;
$guid = get_input('guid');
$entity = get_entity($guid);
if (!$entity instanceof ElggFile || !$entity->canEdit()) {
    register_error(elgg_echo('gallery:tools:crop:error'));
    forward(REFERER);
}
$icon_sizes = get_icon_sizes($entity);
unset($icon_sizes['master']);
$result = IconHandler::makeIcons($entity, null, array('icon_sizes' => $icon_sizes, 'coords' => $coords));
if (!$result) {
    register_error($exception);
} else {
    system_message(elgg_echo('gallery:tools:crop:success'));
}
if (elgg_is_xhr) {
    print json_encode($coords);
}
forward(REFERER);
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function put(ParameterBag $params)
 {
     $decoded = "";
     if ($params->contents) {
         if (empty($params->filename) || empty($params->mimetype)) {
             throw new GraphException("You need to provide a filename and content type with encoded file contents", HttpResponse::HTTP_BAD_REQUEST);
         }
         for ($i = 0; $i < ceil(strlen($params->contents) / 256); $i++) {
             $decoded = $decoded . base64_decode(substr($params->contents, $i * 256, 256));
         }
         if (!$decoded) {
             throw new GraphException("File contents can not be empty and must be encoded with base64", HttpResponse::HTTP_BAD_REQUEST);
         }
         if (empty($params->checksum) || md5($decoded) != $params->checksum) {
             throw new GraphException("Checksum mismatch", HttpResponse::HTTP_BAD_REQUEST);
         }
     }
     $owner_guid = $params->owner_guid ?: elgg_get_logged_in_user_guid();
     $owner = get_entity($owner_guid);
     if (!$owner->canEdit()) {
         throw new GraphException("You are not allowed to upload files on users's behalf", HttpResponse::HTTP_FORBIDDEN);
     }
     $container_guid = $params->container_guid ?: elgg_get_logged_in_user_guid();
     $container = get_entity($container_guid);
     if (!$container->canWriteToContainer($owner->guid, 'object', 'file')) {
         throw new GraphException("You are not allowed to upload files to this container", HttpResponse::HTTP_FORBIDDEN);
     }
     $file_guid = $params->guid ?: 0;
     if ($file_guid) {
         $file = get_entity($file_guid);
     } else {
         if ($decoded) {
             $file = new ElggFile();
             $file->subtype = 'file';
             $file->owner_guid = $owner->guid;
             $file->container_guid = $container->guid;
             $file->title = $params->title ?: $params->filename;
             $file->access_id = ACCESS_PRIVATE;
             $file->origin = 'graph';
         }
     }
     $attrs = array('title', 'description', 'access_id');
     foreach ($attrs as $attr) {
         if (isset($params->{$attr}) && $this->request->get($attr) !== null) {
             $file->{$attr} = $params->{$attr};
         }
     }
     if (!$file instanceof \ElggFile) {
         throw new GraphException("Unable to load or create a file entity");
     }
     if ($decoded) {
         $file->setFilename("file/{$params->filename}");
         if (!$file->exists()) {
             $file->open('write');
             $file->close();
         }
         file_put_contents($file->getFilenameOnFilestore(), $decoded);
         $file->originalfilename = $params->filename;
         $mimetype = $file->detectMimeType(null, $params->mimetype);
         $file->setMimeType($mimetype);
         $file->simpletype = elgg_get_file_simple_type($mimetype);
     }
     $guid = $file->save();
     if (!$guid) {
         $file->delete();
         throw new GraphException("File could not be saved with given parameters", HttpResponse::HTTP_BAD_REQUEST);
     }
     if ($file->simpletype == 'image') {
         IconHandler::makeIcons($file);
     }
     return array('nodes' => array($file));
 }