Example #1
0
function zhsocial_apply_icon($zh_user, $icon_url)
{
    // 	if($zh_user->icontime)
    // 		return;
    $icon_sizes = elgg_get_config('icon_sizes');
    $prefix = "profile/{$zh_user->guid}";
    $filehandler = new ElggFile();
    $filehandler->owner_guid = $zh_user->guid;
    $filehandler->setFilename($prefix . ".jpg");
    $filehandler->open("write");
    $filehandler->write(file_get_contents($icon_url));
    $filehandler->close();
    $filename = $filehandler->getFilenameOnFilestore();
    $sizes = array('topbar', 'tiny', 'small', 'medium', 'large', 'master');
    $thumbs = array();
    foreach ($sizes as $size) {
        $thumbs[$size] = get_resized_image_from_existing_file($filename, $icon_sizes[$size]['w'], $icon_sizes[$size]['h'], $icon_sizes[$size]['square']);
    }
    if ($thumbs['tiny']) {
        // just checking if resize successful
        $thumb = new ElggFile();
        $thumb->owner_guid = $zh_user->guid;
        $thumb->setMimeType('image/jpeg');
        foreach ($sizes as $size) {
            $thumb->setFilename("{$prefix}{$size}.jpg");
            $thumb->open("write");
            $thumb->write($thumbs[$size]);
            $thumb->close();
        }
        $zh_user->icontime = time();
    }
}
function form_generate_thumbnail($file, $fieldname)
{
    // Generate thumbnail (if image)
    $prefix = "file/";
    $filestorename = strtolower(time() . $_FILES[$fieldname]['name']);
    if (substr_count($file->getMimeType(), 'image/')) {
        $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 60, 60, true);
        $thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 153, 153, true);
        $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 600, 600, false);
        if ($thumbnail) {
            $thumb = new ElggFile();
            $thumb->setMimeType($_FILES[$fieldname]['type']);
            $thumb->setFilename($prefix . "thumb" . $filestorename);
            $thumb->open("write");
            $thumb->write($thumbnail);
            $thumb->close();
            $file->thumbnail = $prefix . "thumb" . $filestorename;
            $thumb->setFilename($prefix . "smallthumb" . $filestorename);
            $thumb->open("write");
            $thumb->write($thumbsmall);
            $thumb->close();
            $file->smallthumb = $prefix . "smallthumb" . $filestorename;
            $thumb->setFilename($prefix . "largethumb" . $filestorename);
            $thumb->open("write");
            $thumb->write($thumblarge);
            $thumb->close();
            $file->largethumb = $prefix . "largethumb" . $filestorename;
        }
    }
}
Example #3
0
function pleiofile_generate_file_thumbs(ElggObject $file)
{
    if ($file->simpletype != "image") {
        return null;
    }
    $file->icontime = time();
    $sizes = array(60 => "thumb", 153 => "tinythumb", 153 => "smallthumb", 600 => "largethumb");
    $filename = str_replace("file/", "", $file->getFilename());
    foreach ($sizes as $size => $description) {
        if ($size < 600) {
            $upscale = true;
        } else {
            $upscale = false;
        }
        $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), $size, $size, $upscale);
        if ($thumbnail) {
            $path = "file/" . $description . "_" . $filename;
            $thumb = new ElggFile();
            $thumb->setMimeType($_FILES['upload']['type']);
            $thumb->setFilename($path);
            $thumb->open("write");
            $thumb->write($thumbnail);
            $thumb->close();
            if ($description == "thumb") {
                $file->thumbnail = $path;
            } else {
                $file->{$description} = $path;
            }
            unset($thumbnail);
        }
    }
}
Example #4
0
/**
 * Gets the jpeg contents of the resized version of an uploaded image
 * (Returns false if the uploaded file was not an image)
 *
 * @param string $input_name The name of the file input field on the submission form
 * @param int    $maxwidth   The maximum width of the resized image
 * @param int    $maxheight  The maximum height of the resized image
 * @param bool   $square     If set to true, will take the smallest
 *                           of maxwidth and maxheight and use it to set the
 *                           dimensions on all size; the image will be cropped.
 * @param bool   $upscale    Resize images smaller than $maxwidth x $maxheight?
 *
 * @return false|mixed The contents of the resized image, or false on failure
 */
function get_resized_image_from_uploaded_file($input_name, $maxwidth, $maxheight, $square = false, $upscale = false)
{
    // If our file exists ...
    if (isset($_FILES[$input_name]) && $_FILES[$input_name]['error'] == 0) {
        return get_resized_image_from_existing_file($_FILES[$input_name]['tmp_name'], $maxwidth, $maxheight, $square, 0, 0, 0, 0, $upscale);
    }
    return false;
}
Example #5
0
/**
 * Gets the jpeg contents of the resized version of an uploaded image
 * (Returns false if the uploaded file was not an image)
 *
 * @param string $input_name The name of the file input field on the submission form
 * @param int    $maxwidth   The maximum width of the resized image
 * @param int    $maxheight  The maximum height of the resized image
 * @param bool   $square     If set to true, will take the smallest
 *                           of maxwidth and maxheight and use it to set the
 *                           dimensions on all size; the image will be cropped.
 * @param bool   $upscale    Resize images smaller than $maxwidth x $maxheight?
 *
 * @return false|mixed The contents of the resized image, or false on failure
 */
function get_resized_image_from_uploaded_file($input_name, $maxwidth, $maxheight, $square = false, $upscale = false)
{
    $files = _elgg_services()->request->files;
    if (!$files->has($input_name)) {
        return false;
    }
    $file = $files->get($input_name);
    if (elgg_extract('error', $file) !== 0) {
        return false;
    }
    return get_resized_image_from_existing_file(elgg_extract('tmp_name', $file), $maxwidth, $maxheight, $square, 0, 0, 0, 0, $upscale);
}
Example #6
0
function CreateLTIGroup($user, $name, $context_id, $consumer_key)
{
    $group_guid = 0;
    $group = new ElggGroup($group_guid);
    // Set the group properties that we can!
    $group->name = $name;
    $group->context_id = $context_id;
    // This is a unique identifier from the consumer for this context
    $group->consumer_key = $consumer_key;
    // Which consumer is creating this group
    $group->membership = ACCESS_PRIVATE;
    $group->access_id = ACCESS_PUBLIC;
    $group->briefdescription = elgg_echo('LTI:provision:group');
    $consumer_instance = new LTI_Tool_Consumer_Instance($group->consumer_key, elgg_get_config('dbprefix'));
    $context = new LTI_Context($consumer_instance, $group->context_id);
    $group->description = $context->title;
    $group->save();
    $group->join($user);
    // Add images
    $prefix = 'groups/' . $group->guid;
    $filename = GetImage($consumer_key, '.jpg');
    $thumbtiny = get_resized_image_from_existing_file($filename, 25, 25, true);
    $thumbsmall = get_resized_image_from_existing_file($filename, 40, 40, true);
    $thumbmedium = get_resized_image_from_existing_file($filename, 100, 100, true);
    $thumblarge = get_resized_image_from_existing_file($filename, 200, 200, false);
    if ($thumbtiny) {
        $thumb = new ElggFile();
        $thumb->owner_guid = $group->owner_guid;
        $thumb->setMimeType('image/jpeg');
        $thumb->setFilename($prefix . "tiny.jpg");
        $thumb->open("write");
        $thumb->write($thumbtiny);
        $thumb->close();
        $thumb->setFilename($prefix . "small.jpg");
        $thumb->open("write");
        $thumb->write($thumbsmall);
        $thumb->close();
        $thumb->setFilename($prefix . "medium.jpg");
        $thumb->open("write");
        $thumb->write($thumbmedium);
        $thumb->close();
        $thumb->setFilename($prefix . "large.jpg");
        $thumb->open("write");
        $thumb->write($thumblarge);
        $thumb->close();
        $group->icontime = time();
    }
    // return the URL
    return $group;
}
Example #7
0
 function put($url = '', $handle = null, $data = array())
 {
     if (!$url) {
         return false;
     }
     $hash = md5($url);
     $site = elgg_get_site_entity();
     if (!$handle) {
         $handle = $site->guid;
     }
     if (!empty($data)) {
         $thumbnails = !empty($data['thumbnails']) ? $data['thumbnails'] : array();
         $icons = !empty($data['icons']) ? $data['icons'] : array();
         $thumbnails = array_merge($thumbnails, $icons);
         if (!empty($thumbnails) && $this->config->get('cache_thumbnails')) {
             foreach ($thumbnails as $thumbnail_url) {
                 $imagesize = getimagesize($thumbnail_url);
                 if (empty($imagesize) || $imagesize[0] < $this->config->get('cache_thumb_size_lower_threshold')) {
                     continue;
                 }
                 $post_max_size = elgg_get_ini_setting_in_bytes('post_max_size');
                 $upload_max_filesize = elgg_get_ini_setting_in_bytes('upload_max_filesize');
                 $max_upload = $upload_max_filesize > $post_max_size ? $post_max_size : $upload_max_filesize;
                 $filesize = filesize($thumbnail_url);
                 if (!$filesize || $filesize > $max_upload) {
                     continue;
                 }
                 $size = $this->config->get('cache_thumb_size');
                 $thumb = get_resized_image_from_existing_file($thumbnail_url, $size, $size, false, 0, 0, 0, 0, true);
                 if ($thumb) {
                     $file = new ElggFile();
                     $file->owner_guid = $site->guid;
                     $file->setFilename("scraper_cache/thumbs/{$hash}.{$handle}.jpg");
                     $file->open('write');
                     $file->write($thumb);
                     $file->close();
                     $data['thumb_cache'] = time();
                     break;
                 }
             }
         }
     }
     $file = new ElggFile();
     $file->owner_guid = $site->guid;
     $file->setFilename("scraper_cache/resources/{$hash}.{$handle}.json");
     $file->open('write');
     $file->write(json_encode($data));
     $file->close();
     return $data;
 }
Example #8
0
/**
 * Gets the jpeg contents of the resized version of an uploaded image
 * (Returns false if the uploaded file was not an image)
 *
 * @param string $input_name The name of the file input field on the submission form
 * @param int    $maxwidth   The maximum width of the resized image
 * @param int    $maxheight  The maximum height of the resized image
 * @param bool   $square     If set to true, will take the smallest
 *                           of maxwidth and maxheight and use it to set the
 *                           dimensions on all size; the image will be cropped.
 * @param bool   $upscale    Resize images smaller than $maxwidth x $maxheight?
 *
 * @return false|mixed The contents of the resized image, or false on failure
 */
function get_resized_image_from_uploaded_file($input_name, $maxwidth, $maxheight, $square = false, $upscale = false)
{
    $files = _elgg_services()->request->files;
    if (!$files->has($input_name)) {
        return false;
    }
    $file = $files->get($input_name);
    if (empty($file)) {
        // a file input was provided but no file uploaded
        return false;
    }
    if ($file->getError() !== 0) {
        return false;
    }
    return get_resized_image_from_existing_file($file->getPathname(), $maxwidth, $maxheight, $square, 0, 0, 0, 0, $upscale);
}
Example #9
0
function uploadCK($page, $identifier, $obj)
{
    $funcNum2 = get_Input('CKEditorFuncNum', 'CKEditorFuncNum');
    $file = new ElggFile();
    $filestorename = strtolower(time() . $_FILES['upload']['name']);
    $file->setFilename($filestorename);
    $file->setMimeType($_FILES['upload']['type']);
    $file->owner_guid = elgg_get_logged_in_user_guid();
    $file->subtype = "file";
    $file->originalfilename = $filestorename;
    $file->access_id = ACCESS_PUBLIC;
    $file->open("write");
    $file->write(get_uploaded_file('upload'));
    $file->close();
    $result = $file->save();
    if ($result) {
        $master = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 550, 550);
        if ($master !== false) {
            $_SESSION['UPLOAD_DATA']['file_save'] = "started";
            $filehandler = new ElggFile();
            $filehandler->setFilename($filestorename);
            $filehandler->setMimeType($_FILES['upload']['type']);
            $filehandler->owner_guid = $user->guid;
            $filehandler->subtype = "file";
            $filehandler->originalfilename = $filestorename;
            $filehandler->access_id = ACCESS_PUBLIC;
            $filehandler->open("write");
            $filehandler->write($master);
            $filehandler->close();
            $filehandler->save();
            // Dev URL
            $url = elgg_get_site_url() . 'CKEditorView?file_guid=' . $filehandler->guid;
            //Production URL
            //$url ='/CKEditorView?file_guid='.$filehandler->guid;
            echo '<script type="text/javascript">
		window.parent.CKEDITOR.tools.callFunction(' . $funcNum2 . ', "' . $url . '","");
		</script>';
            exit;
        } else {
            echo '<script type="text/javascript">
		window.parent.CKEDITOR.tools.callFunction(' . $funcNum2 . ', "","");
		</script>';
            exit;
        }
    }
    return true;
}
Example #10
0
 protected function saveThumbnail($image, $name)
 {
     try {
         $thumbnail = get_resized_image_from_existing_file($image->getFilenameOnFilestore(), 60, 60, true);
     } catch (Exception $e) {
         return FALSE;
     }
     $thumb = new ElggFile();
     $thumb->setMimeType('image/jpeg');
     $thumb->access_id = $this->access_id;
     $thumb->setFilename($name);
     $thumb->open("write");
     $thumb->write($thumbnail);
     $thumb->save();
     $image->thumbnail_guid = $thumb->getGUID();
     if (!$thumb->getGUID()) {
         $thumb->delete();
         return FALSE;
     }
     return TRUE;
 }
Example #11
0
$return_value = $this->processFile($upload_video);
if (!file_exists($return_value->videofile)) {
    register_error(elgg_echo('izap_videos:error:notUploaded'));
    forward($_SERVER['HTTP_REFERER']);
    exit;
}
$this->access_id = 0;
$this->videotype = $return_value->videotype;
if ($return_value->videofile) {
    $this->videofile = $return_value->videofile;
}
if (empty($_FILES['upload_thumbnail']['name'])) {
    if ($return_value->thumb) {
        $this->orignal_thumb = $return_value->orignal_thumb;
        $this->imagesrc = $return_value->thumb;
    }
} else {
    if ($_FILES['upload_thumbnail']['error'] == 0) {
        $set_original_thumbnail = $this->getTmpPath('original_' . $_FILES['upload_thumbnail']['name']);
        $this->setFilename($set_original_thumbnail);
        $this->open("write");
        $this->write(file_get_contents($_FILES['upload_thumbnail']['tmp_name']));
        //set thumbnail size
        $thumbnail = get_resized_image_from_existing_file($this->getFilenameOnFilestore(), 650, 500);
        $set_thumb = $this->getTmpPath($_FILES['upload_thumbnail']['name']);
        $this->setFilename($set_thumb);
        $this->open("write");
        $this->write($thumbnail);
        $this->imagesrc = $set_thumb;
    }
}
            $thumb->open("write");
            $thumb->write($thumbnail);
            $thumb->close();
            $file->thumbnail = $prefix . "thumb" . $filestorename;
            unset($thumbnail);
        }
        $thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 153, 153, true);
        if ($thumbsmall) {
            $thumb->setFilename($prefix . "smallthumb" . $filestorename);
            $thumb->open("write");
            $thumb->write($thumbsmall);
            $thumb->close();
            $file->smallthumb = $prefix . "smallthumb" . $filestorename;
            unset($thumbsmall);
        }
        $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 600, 600, false);
        if ($thumblarge) {
            $thumb->setFilename($prefix . "largethumb" . $filestorename);
            $thumb->open("write");
            $thumb->write($thumblarge);
            $thumb->close();
            $file->largethumb = $prefix . "largethumb" . $filestorename;
            unset($thumblarge);
        }
    }
}
// make sure session cache is cleared
unset($_SESSION['uploadtitle']);
unset($_SESSION['uploaddesc']);
unset($_SESSION['uploadtags']);
unset($_SESSION['uploadaccessid']);
/**
 * Used to Pull in the latest avatar from facebook.
 *
 * @access public
 * @param array $user
 * @param string $file_location
 * @return void
 */
function facebook_connect_update_user_avatar($user, $file_location)
{
    $path = elgg_get_data_path();
    $tempfile = $path . $user->getGUID() . 'img.jpg';
    $imgContent = file_get_contents($file_location);
    $fp = fopen($tempfile, "w");
    fwrite($fp, $imgContent);
    fclose($fp);
    $sizes = array('topbar' => array(16, 16, TRUE), 'tiny' => array(25, 25, TRUE), 'small' => array(40, 40, TRUE), 'medium' => array(100, 100, TRUE), 'large' => array(200, 200, FALSE), 'master' => array(550, 550, FALSE));
    $filehandler = new ElggFile();
    $filehandler->owner_guid = $user->getGUID();
    foreach ($sizes as $size => $dimensions) {
        $image = get_resized_image_from_existing_file($tempfile, $dimensions[0], $dimensions[1], $dimensions[2]);
        $filehandler->setFilename("profile/{$user->guid}{$size}.jpg");
        $filehandler->open('write');
        $filehandler->write($image);
        $filehandler->close();
    }
    // update user's icontime
    $user->icontime = time();
    return TRUE;
}
Example #14
0
File: register.php Project: n8b/VMN
     $metadata['location'] = implode(', ', $location);
 }
 // we have received a verified email from a provider
 if ($verified) {
     elgg_set_user_validation_status($new_user->guid, true, 'hybridauth');
 }
 foreach ($metadata as $md_name => $md_value) {
     create_metadata($new_user->guid, $md_name, $md_value, '', $new_user->guid, ACCESS_PRIVATE, true);
 }
 if ($photo_url) {
     $icon_sizes = elgg_get_config('icon_sizes');
     $filehandler = new ElggFile();
     $filehandler->owner_guid = $new_user->guid;
     foreach ($icon_sizes as $size => $dimensions) {
         $image = get_resized_image_from_existing_file($photo_url, $dimensions[0], $dimensions[1], $dimensions[2]);
         $image = get_resized_image_from_existing_file($photo_url, $dimensions['w'], $dimensions['h'], $dimensions['square'], 0, 0, 0, 0, $dimensions['upscale']);
         $filehandler->setFilename("profile/{$new_user->guid}{$size}.jpg");
         $filehandler->open('write');
         $filehandler->write($image);
         $filehandler->close();
     }
     $new_user->icontime = time();
 }
 if ($provider && $provider_uid) {
     elgg_set_plugin_user_setting("{$provider}:uid", $provider_uid, $new_user->guid, 'elgg_hybridauth');
     elgg_trigger_plugin_hook('hybridauth:authenticate', $provider, array('entity' => $new_user));
 }
 $params = array_merge($params, $metadata);
 // @todo should registration be allowed no matter what the plugins return?
 if (!elgg_trigger_plugin_hook('register', 'user', $params, TRUE)) {
     $ia = elgg_set_ignore_access(true);
Example #15
0
 /**
  * Used to process the video file
  * @param string $file upload file name
  * @return object
  */
 protected function processFile($file)
 {
     $returnValue = new stdClass();
     $returnValue->type = 'uploaded';
     $fileName = $_FILES[$file['mainArray']]['name'][$file['fileName']];
     $error = $_FILES[$file['mainArray']]['error'][$file['fileName']];
     $tmpName = $_FILES[$file['mainArray']]['tmp_name'][$file['fileName']];
     $type = $_FILES[$file['mainArray']]['type'][$file['fileName']];
     $size = $_FILES[$file['mainArray']]['size'][$file['fileName']];
     // if error
     if ($error > 0) {
         return 104;
     }
     // if file is of zero size
     if ($size == 0) {
         return 105;
     }
     // check supported video type
     if (!izapSupportedVideos_izap_videos($fileName)) {
         return 106;
     }
     // check supported video size
     if (!izapCheckFileSize_izap_videos($size)) {
         return 107;
     }
     // upload the tmp file
     $newFileName = izapGetFriendlyFileName_izap_videos($fileName);
     $this->setFilename('tmp/' . $newFileName);
     $this->open("write");
     $this->write(file_get_contents($tmpName));
     $returnValue->tmpFile = $this->getFilenameOnFilestore();
     // take snapshot of the video
     $image = new izapConvert($returnValue->tmpFile);
     if ($image->photo()) {
         $retValues = $image->getValues(true);
         if ($retValues['imagename'] != '' && $retValues['imagecontent'] != '') {
             $this->setFilename('izap_videos/uploaded/' . $retValues['imagename']);
             $this->open("write");
             if ($this->write($retValues['imagecontent'])) {
                 $orignal_file_path = $this->getFilenameOnFilestore();
                 $thumb = get_resized_image_from_existing_file($orignal_file_path, 120, 90);
                 $this->setFilename('izap_videos/uploaded/' . $retValues['imagename']);
                 $this->open("write");
                 $this->write($thumb);
                 $this->close();
                 $returnValue->thumb = 'izap_videos/uploaded/' . $retValues['imagename'];
                 // Defining new preview attribute of standard object
                 $returnValue->preview_400 = 'izap_videos/uploaded/preview_400';
                 $returnValue->preview_200 = 'izap_videos/uploaded/preview_200';
             }
         }
     }
     // check if it is flv, then dont send it to queue
     if (izap_get_file_extension($returnValue->tmpFile) == 'flv') {
         $file_name = 'izap_videos/uploaded/' . $newFileName;
         $this->setFilename($file_name);
         $this->open("write");
         $this->write(file_get_contents($returnValue->tmpFile));
         $this->converted = 'yes';
         $this->videofile = $file_name;
         $this->orignalfile = $file_name;
         $returnValue->is_flv = 'yes';
         // remove the tmp file
         @unlink($returnValue->tmpFile);
     }
     return $returnValue;
 }
Example #16
0
/**
 * Creates entity media thumbnails
 *
 * @param mixed       $file        Path to file, or an array with 'tmp_name' and 'name', or ElggFile
 * @param \ElggEntity $entity      Entity
 * @param string      $type        Media type
 * @param array       $crop_coords Cropping coordinates
 * @return \ElggFile[]|false
 */
function elgg_create_media_thumbnails($file, \ElggEntity $entity, $type = 'icon', $crop_coords = [])
{
    if ($file instanceof ElggFile) {
        $path = $file->getFilenameOnFilestore();
    } else {
        if (is_array($file)) {
            $path = elgg_extract('tmp_name', (array) $file);
        } else {
            $path = (string) $file;
        }
    }
    if (!file_exists($path)) {
        return false;
    }
    $thumb_sizes = elgg_media_get_thumb_sizes($entity, $type);
    $master_info = $thumb_sizes['master'];
    unset($thumb_sizes['master']);
    // master is used as base for cropping
    $filehandler = elgg_get_media_original($entity, $type);
    if (!$filehandler) {
        return false;
    }
    $resized = get_resized_image_from_existing_file($path, $master_info['w'], $master_info['h'], $master_info['square'], 0, 0, 0, 0, $master_info['upscale']);
    if (!$resized) {
        return false;
    }
    $master = new ElggFile();
    $master->owner_guid = $entity->guid;
    $master->setFilename("media/{$type}/master.jpg");
    $master->open('write');
    $master->write($resized);
    $master->close();
    $thumbs = [];
    $x1 = (int) elgg_extract('x1', $crop_coords);
    $y1 = (int) elgg_extract('y1', $crop_coords);
    $x2 = (int) elgg_extract('x2', $crop_coords);
    $y2 = (int) elgg_extract('y2', $crop_coords);
    foreach ($thumb_sizes as $name => $size_info) {
        $resized = get_resized_image_from_existing_file($path, $size_info['w'], $size_info['h'], $size_info['square'], $x1, $y1, $x2, $y2, $size_info['upscale']);
        if (!$resized) {
            foreach ($thumbs as $thumb) {
                $thumb->delete();
            }
            return false;
        }
        $thumb = new ElggFile();
        $thumb->owner_guid = $entity->guid;
        $thumb->setFilename("media/{$type}/{$name}.jpg");
        $thumb->open('write');
        $thumb->write($resized);
        $thumb->close();
        $thumbs[] = $thumb;
    }
    //$entity->{"{$type}time"} = time();
    $entity->{"{$type}_time_created"} = time();
    // normalize coords to master
    $natural_image_size = getimagesize($path);
    $master_image_size = getimagesize($master->getFilenameOnFilestore());
    $ratio = $master_image_size[0] / $natural_image_size[0];
    $entity->{"{$type}_x1"} = $x1 * $ratio;
    $entity->{"{$type}_x2"} = $x2 * $ratio;
    $entity->{"{$type}_y1"} = $y1 * $ratio;
    $entity->{"{$type}_y2"} = $y2 * $ratio;
    return $thumbs;
}
Example #17
0
/**
 * Make thumbnails of given video position. Defaults to beginning of video.
 *
 * @param Video $video    The video object
 * @param int   $position Video position
 */
function video_create_thumbnails($video, $position = 0)
{
    $icon_sizes = elgg_get_config('icon_sizes');
    $square = elgg_get_plugin_setting('square_icons', 'video');
    // Default to square thumbnail images
    if (is_null($square)) {
        $square = true;
    }
    $square = $square == 1 ? true : false;
    $dir = $video->getFileDirectory();
    $guid = $video->getGUID();
    // Use default thumbnail as master
    $imagepath = "{$dir}/icon-master.jpg";
    try {
        $thumbnailer = new VideoThumbnailer();
        $thumbnailer->setInputFile($video->getFilenameOnFilestore());
        $thumbnailer->setOutputFile($imagepath);
        $thumbnailer->setPosition($position);
        $thumbnailer->execute();
    } catch (exception $e) {
        $msg = elgg_echo('VideoException:ThumbnailCreationFailed', array($video->getFilenameOnFilestore(), $e->getMessage(), $thumbnailer->getCommand()));
        error_log($msg);
        elgg_add_admin_notice('video_thumbnailing_error', $msg);
        return false;
    }
    $files = array();
    // Create the thumbnails
    foreach ($icon_sizes as $name => $size_info) {
        // We have already created master image
        if ($name == 'master') {
            continue;
        }
        $resized = get_resized_image_from_existing_file($imagepath, $size_info['w'], $size_info['h'], $square);
        if ($resized) {
            $file = new ElggFile();
            $file->owner_guid = $video->owner_guid;
            $file->container_guid = $guid;
            $file->setFilename("video/{$guid}/icon-{$name}.jpg");
            $file->open('write');
            $file->write($resized);
            $file->close();
            $files[] = $file;
        } else {
            error_log("ERROR: Failed to create thumbnail '{$name}' for video {$video->getFilenameOnFilestore()}.");
            // Delete all images if one fails
            foreach ($files as $file) {
                $file->delete();
            }
            return false;
        }
    }
    $video->icontime = time();
    return true;
}
function create_file($container_guid, $title, $desc, $access_id, $guid, $tags, $new_file)
{
    // register_error("Creating file: " . $container_guid . ", vars: " . print_r(array($title, $desc, $access_id, $guid, $tags, $new_file), true));
    if ($new_file) {
        // must have a file if a new file upload
        if (empty($_FILES['upload']['name'])) {
            // cache information in session
            $_SESSION['uploadtitle'] = $title;
            $_SESSION['uploaddesc'] = $desc;
            $_SESSION['uploadtags'] = $tags;
            $_SESSION['uploadaccessid'] = $access_id;
            register_error(elgg_echo('file:nofile') . "no file new");
            forward($_SERVER['HTTP_REFERER']);
        }
        $file = new FilePluginFile();
        $file->subtype = "file";
        // if no title on new upload, grab filename
        if (empty($title)) {
            $title = $_FILES['upload']['name'];
        }
    } else {
        // load original file object
        $file = get_entity($guid);
        if (!$file) {
            register_error(elgg_echo('file:cannotload') . 'can"t load existing');
            forward($_SERVER['HTTP_REFERER']);
        }
        // user must be able to edit file
        if (!$file->canEdit()) {
            register_error(elgg_echo('file:noaccess') . 'no access to existing');
            forward($_SERVER['HTTP_REFERER']);
        }
    }
    $file->title = $title;
    $file->description = $desc;
    $file->access_id = $access_id;
    $file->container_guid = $container_guid;
    $tags = explode(",", $tags);
    $file->tags = $tags;
    // we have a file upload, so process it
    if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) {
        $prefix = "file/";
        // if previous file, delete it
        if ($new_file == false) {
            $filename = $file->getFilenameOnFilestore();
            if (file_exists($filename)) {
                unlink($filename);
            }
            // use same filename on the disk - ensures thumbnails are overwritten
            $filestorename = $file->getFilename();
            $filestorename = elgg_substr($filestorename, elgg_strlen($prefix));
        } else {
            $filestorename = elgg_strtolower(time() . $_FILES['upload']['name']);
        }
        $file->setFilename($prefix . $filestorename);
        $file->setMimeType($_FILES['upload']['type']);
        $file->originalfilename = $_FILES['upload']['name'];
        $file->simpletype = get_general_file_type($_FILES['upload']['type']);
        $file->open("write");
        $file->write(get_uploaded_file('upload'));
        $file->close();
        $guid = $file->save();
        // if image, we need to create thumbnails (this should be moved into a function)
        if ($guid && $file->simpletype == "image") {
            $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 60, 60, true);
            if ($thumbnail) {
                $thumb = new ElggFile();
                $thumb->setMimeType($_FILES['upload']['type']);
                $thumb->setFilename($prefix . "thumb" . $filestorename);
                $thumb->open("write");
                $thumb->write($thumbnail);
                $thumb->close();
                $file->thumbnail = $prefix . "thumb" . $filestorename;
                unset($thumbnail);
            }
            $thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 153, 153, true);
            if ($thumbsmall) {
                $thumb->setFilename($prefix . "smallthumb" . $filestorename);
                $thumb->open("write");
                $thumb->write($thumbsmall);
                $thumb->close();
                $file->smallthumb = $prefix . "smallthumb" . $filestorename;
                unset($thumbsmall);
            }
            $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 600, 600, false);
            if ($thumblarge) {
                $thumb->setFilename($prefix . "largethumb" . $filestorename);
                $thumb->open("write");
                $thumb->write($thumblarge);
                $thumb->close();
                $file->largethumb = $prefix . "largethumb" . $filestorename;
                unset($thumblarge);
            }
        }
    } else {
        // not saving a file but still need to save the entity to push attributes to database
        $file->save();
    }
    return array($file, $guid);
}
Example #19
0
if (empty($icontime)) {
    return;
}
$user_guid = $user->getGUID();
$filehandler = new ElggFile();
$filehandler->owner_guid = $user_guid;
$filehandler->setFilename("profile/{$user_guid}master.jpg");
if ($filehandler->exists()) {
    $image_data = $filehandler->grabFile();
}
if (empty($image_data)) {
    return;
}
$x1 = $user->x1;
$x2 = $user->x2;
$y1 = $user->y1;
$y2 = $user->y2;
if ($x1 === null) {
    return $image_data;
}
// apply user cropping config
// create temp file for resizing
$tmpfname = tempnam(elgg_get_data_path(), 'elgg_avatar_service');
$handle = fopen($tmpfname, 'w');
fwrite($handle, $image_data);
fclose($handle);
// apply resizing
$result = get_resized_image_from_existing_file($tmpfname, 2048, 2048, true, $x1, $y1, $x2, $y2, false);
// remove temp file
unlink($tmpfname);
echo $result;
/**
 * Update the user profile icon based on profile_sync data
 *
 * @param string $event  the name of the event
 * @param string $type   the type of the event
 * @param mixed  $object supplied object
 *
 * @return void
 */
function theme_haarlem_intranet_profile_sync_profile_icon($event, $type, $object)
{
    if (empty($object) || !is_array($object)) {
        return;
    }
    $user = elgg_extract('entity', $object);
    if (empty($user) || !elgg_instanceof($user, 'user')) {
        return;
    }
    // handle icons
    $datasource = elgg_extract('datasource', $object);
    $source_row = elgg_extract('source_row', $object);
    if (empty($datasource) || empty($source_row)) {
        return;
    }
    // handle custom icon
    $fh = new ElggFile();
    $fh->owner_guid = $user->getGUID();
    $icon_sizes = elgg_get_config('icon_sizes');
    $icon_path = elgg_extract('profielfoto', $source_row);
    $icon_path = profile_sync_filter_var($icon_path);
    if (empty($icon_path)) {
        // remove icon
        foreach ($icon_sizes as $size => $info) {
            $fh->setFilename("haarlem_icon/{$size}.jpg");
            if ($fh->exists()) {
                $fh->delete();
            }
        }
        unset($user->haarlem_icontime);
        return;
    }
    $csv_location = $datasource->csv_location;
    if (empty($csv_location)) {
        return;
    }
    $csv_filename = basename($csv_location);
    $base_location = rtrim(str_ireplace($csv_filename, "", $csv_location), DIRECTORY_SEPARATOR);
    $icon_path = sanitise_filepath($icon_path, false);
    // prevent abuse (like ../../......)
    $icon_path = ltrim($icon_path, DIRECTORY_SEPARATOR);
    // remove beginning /
    $icon_path = $base_location . DIRECTORY_SEPARATOR . $icon_path;
    // concat base location and rel path
    // icon exists
    if (!file_exists($icon_path)) {
        return;
    }
    // was csv image updated
    $csv_iconsize = @filesize($icon_path);
    if ($csv_iconsize !== false) {
        $csv_iconsize = md5($csv_iconsize);
        $icontime = $user->haarlem_icontime;
        if ($csv_iconsize === $icontime) {
            // icons are the same
            return;
        }
    }
    // try to get the user icon
    $icon_contents = file_get_contents($icon_path);
    if (empty($icon_contents)) {
        return;
    }
    // make sure we have a hash to save
    if ($csv_iconsize === false) {
        $csv_iconsize = strlen($icon_contents);
        $csv_iconsize = md5($csv_iconsize);
    }
    // write icon to a temp location for further handling
    $tmp_icon = tempnam(sys_get_temp_dir(), $user->getGUID());
    file_put_contents($tmp_icon, $icon_contents);
    // resize icon
    $icon_updated = false;
    foreach ($icon_sizes as $size => $icon_info) {
        $icon_contents = get_resized_image_from_existing_file($tmp_icon, $icon_info["w"], $icon_info["h"], $icon_info["square"], 0, 0, 0, 0, $icon_info["upscale"]);
        if (empty($icon_contents)) {
            continue;
        }
        $fh->setFilename("haarlem_icon/{$size}.jpg");
        $fh->open("write");
        $fh->write($icon_contents);
        $fh->close();
        $icon_updated = true;
    }
    // did we have a successfull icon upload?
    if ($icon_updated) {
        $user->haarlem_icontime = $csv_iconsize;
    }
    // cleanup
    unlink($tmp_icon);
}
 protected static function cropImage($tmp_name, $orig_width, $orig_height, $new_width, $new_height)
 {
     $crop = array();
     if ($new_height / $new_width > $orig_height / $orig_width) {
         $scaled_new_width = $new_width * $orig_height / $new_height;
         $crop = array('x1' => round(($orig_width - $scaled_new_width) / 2), 'y1' => 0, 'x2' => round(($orig_width + $scaled_new_width) / 2), 'y2' => $orig_height);
     } else {
         $scaled_new_height = $new_height * $orig_width / $new_width;
         $crop = array('x1' => 0, 'y1' => round(($orig_height - $scaled_new_height) / 2), 'x2' => $orig_width, 'y2' => round(($orig_height + $scaled_new_height) / 2));
     }
     /*echo "<pre>";
     		var_dump(
     				$orig_width,
     				$orig_height,	
     				$scaled_new_width,
     				$tmp_name, 
     				$new_width, 
     				$new_height,
     				$crop);*/
     return get_resized_image_from_existing_file($tmp_name, $new_width, $new_height, false, $crop['x1'], $crop['y1'], $crop['x2'], $crop['y2'], true);
 }
Example #22
0
/**
 * Unzip an uploaded zip file
 *
 * @param array $file           the $_FILES information
 * @param int   $container_guid the container to put the files/folders under
 * @param int   $parent_guid    the parrent folder
 *
 * @return bool
 */
function file_tools_unzip($file, $container_guid, $parent_guid = 0)
{
    $extracted = false;
    if (!empty($file) && !empty($container_guid)) {
        $allowed_extensions = file_tools_allowed_extensions();
        $zipfile = elgg_extract("tmp_name", $file);
        $container_entity = get_entity($container_guid);
        $access_id = get_input("access_id", false);
        if ($access_id === false) {
            if (!empty($parent_guid) && ($parent_folder = get_entity($parent_guid)) && elgg_instanceof($parent_folder, "object", FILE_TOOLS_SUBTYPE)) {
                $access_id = $parent_folder->access_id;
            } else {
                if (elgg_instanceof($container_entity, "group")) {
                    $access_id = $container_entity->group_acl;
                } else {
                    $access_id = get_default_access($container_entity);
                }
            }
        }
        // open the zip file
        $zip = zip_open($zipfile);
        while ($zip_entry = zip_read($zip)) {
            // open the zip entry
            zip_entry_open($zip, $zip_entry);
            // set some variables
            $zip_entry_name = zip_entry_name($zip_entry);
            $filename = basename($zip_entry_name);
            // check for folder structure
            if (strlen($zip_entry_name) != strlen($filename)) {
                // there is a folder structure, check it and create missing items
                file_tools_create_folders($zip_entry, $container_guid, $parent_guid);
            }
            // extract the folder structure from the zip entry
            $folder_array = explode("/", $zip_entry_name);
            $parent = $parent_guid;
            foreach ($folder_array as $folder) {
                $folder = utf8_encode($folder);
                if ($entity = file_tools_check_foldertitle_exists($folder, $container_guid, $parent)) {
                    $parent = $entity->getGUID();
                } else {
                    if ($folder == end($folder_array)) {
                        $prefix = "file/";
                        $extension_array = explode('.', $folder);
                        $file_extension = end($extension_array);
                        if (in_array(strtolower($file_extension), $allowed_extensions)) {
                            $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
                            // create the file
                            $filehandler = new ElggFile();
                            $filehandler->setFilename($prefix . $folder);
                            $filehandler->title = $folder;
                            $filehandler->originalfilename = $folder;
                            $filehandler->owner_guid = elgg_get_logged_in_user_guid();
                            $filehandler->container_guid = $container_guid;
                            $filehandler->access_id = $access_id;
                            $filehandler->open("write");
                            $filehandler->write($buf);
                            $filehandler->close();
                            $mime_type = $filehandler->detectMimeType($filehandler->getFilenameOnFilestore());
                            // hack for Microsoft zipped formats
                            $info = pathinfo($folder);
                            $office_formats = array("docx", "xlsx", "pptx");
                            if ($mime_type == "application/zip" && in_array($info["extension"], $office_formats)) {
                                switch ($info["extension"]) {
                                    case "docx":
                                        $mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                                        break;
                                    case "xlsx":
                                        $mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                                        break;
                                    case "pptx":
                                        $mime_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
                                        break;
                                }
                            }
                            // check for bad ppt detection
                            if ($mime_type == "application/vnd.ms-office" && $info["extension"] == "ppt") {
                                $mime_type = "application/vnd.ms-powerpoint";
                            }
                            $simple_type = file_get_simple_type($mime_type);
                            $filehandler->setMimeType($mime_type);
                            $filehandler->simpletype = $simple_type;
                            if ($simple_type == "image") {
                                $filestorename = elgg_strtolower(time() . $folder);
                                $thumb = new ElggFile();
                                $thumb->owner_guid = elgg_get_logged_in_user_guid();
                                $thumbnail = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 60, 60, true);
                                if ($thumbnail) {
                                    $thumb->setFilename($prefix . "thumb" . $filestorename);
                                    $thumb->open("write");
                                    $thumb->write($thumbnail);
                                    $thumb->close();
                                    $filehandler->thumbnail = $prefix . "thumb" . $filestorename;
                                    unset($thumbnail);
                                }
                                $thumbsmall = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 153, 153, true);
                                if ($thumbsmall) {
                                    $thumb->setFilename($prefix . "smallthumb" . $filestorename);
                                    $thumb->open("write");
                                    $thumb->write($thumbsmall);
                                    $thumb->close();
                                    $filehandler->smallthumb = $prefix . "smallthumb" . $filestorename;
                                    unset($thumbsmall);
                                }
                                $thumblarge = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 600, 600, false);
                                if ($thumblarge) {
                                    $thumb->setFilename($prefix . "largethumb" . $filestorename);
                                    $thumb->open("write");
                                    $thumb->write($thumblarge);
                                    $thumb->close();
                                    $filehandler->largethumb = $prefix . "largethumb" . $filestorename;
                                    unset($thumblarge);
                                }
                                unset($thumb);
                            }
                            set_input('folder_guid', $parent);
                            $filehandler->save();
                            $extracted = true;
                            if (!empty($parent)) {
                                add_entity_relationship($parent, FILE_TOOLS_RELATIONSHIP, $filehandler->getGUID());
                            }
                        }
                    }
                }
            }
            zip_entry_close($zip_entry);
        }
        zip_close($zip);
    }
    return $extracted;
}
Example #23
0
 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
 $file_contents = curl_exec($ch);
 $curl_info = curl_getinfo($ch);
 curl_close($ch);
 $mime_type = $curl_info['content_type'];
 if (substr_count($mime_type, 'image/')) {
     $prefix = "groups/{$group->guid}";
     $filehandler = new ElggFile();
     $filehandler->owner_guid = $group->owner_guid;
     $filehandler->setFilename("{$prefix}.jpg");
     $filehandler->open('write');
     $filehandler->write($file_contents);
     $filehandler->close();
     foreach ($icon_sizes as $name => $size_info) {
         $resized = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), $size_info['w'], $size_info['h'], $size_info['square'], 0, 0, 0, 0, $size_info['upscale']);
         if ($resized) {
             $file = new ElggFile();
             $file->owner_guid = $group->owner_guid;
             $file->setFilename("{$prefix}{$name}.jpg");
             $file->open('write');
             $file->write($resized);
             $file->close();
             $files[] = $file;
         } else {
             $avatar_error = true;
         }
     }
     if (!empty($avatar_error)) {
         foreach ($files as $file) {
             $file->delete();
Example #24
0
/**
 * Serves up screenshots for plugins from
 * admin_plugin_screenshot/<plugin_id>/<size>/<ss_name>.<ext>
 *
 * @param array $pages The pages array
 * @return bool
 * @access private
 */
function admin_plugin_screenshot_page_handler($pages)
{
    // only admins can use this for security
    admin_gatekeeper();
    $plugin_id = elgg_extract(0, $pages);
    // only thumbnail or full.
    $size = elgg_extract(1, $pages, 'thumbnail');
    // the rest of the string is the filename
    $filename_parts = array_slice($pages, 2);
    $filename = implode('/', $filename_parts);
    $filename = sanitise_filepath($filename, false);
    $plugin = new ElggPlugin($plugin_id);
    if (!$plugin) {
        $file = elgg_get_root_path() . '_graphics/icons/default/medium.png';
    } else {
        $file = $plugin->getPath() . $filename;
        if (!file_exists($file)) {
            $file = elgg_get_root_path() . '_graphics/icons/default/medium.png';
        }
    }
    header("Content-type: image/jpeg");
    // resize to 100x100 for thumbnails
    switch ($size) {
        case 'thumbnail':
            echo get_resized_image_from_existing_file($file, 100, 100, true);
            break;
        case 'full':
        default:
            echo file_get_contents($file);
            break;
    }
    return true;
}
Example #25
0
/**
 * Update the user profile with the LinkedIn profile image
 *
 * @param int $user_guid the user_guid to update
 *
 * @return bool
 */
function socialink_linkedin_sync_profile_icon($user_guid = 0)
{
    $result = false;
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    if (($user = get_user($user_guid)) && socialink_linkedin_is_connected($user_guid)) {
        if ($api_result = socialink_linkedin_get_profile_information($user_guid)) {
            $api_result = json_decode($api_result);
            if ($icon_url = $api_result->pictureUrl) {
                if (file_get_contents($icon_url)) {
                    $icon_sizes = elgg_get_config("icon_sizes");
                    if (!empty($icon_sizes)) {
                        $fh = new ElggFile();
                        $fh->owner_guid = $user->getGUID();
                        foreach ($icon_sizes as $name => $properties) {
                            $resize = get_resized_image_from_existing_file($icon_url, $properties["w"], $properties["h"], $properties["square"], 0, 0, 0, 0, $properties["upscale"]);
                            if (!empty($resize)) {
                                $fh->setFilename("profile/" . $user->getGUID() . $name . ".jpg");
                                $fh->open("write");
                                $fh->write($resize);
                                $fh->close();
                                $result = true;
                            }
                        }
                    }
                    if (!empty($result)) {
                        $user->icontime = time();
                        // trigger event to let others know the icon was updated
                        elgg_trigger_event("profileiconupdate", $user->type, $user);
                    }
                }
            }
        }
    }
    return $result;
}
$user = get_loggedin_user();
$funcNum2 = get_Input('CKEditorFuncNum', 'CKEditorFuncNum');
$file = new ElggFile();
$filestorename = strtolower(time() . $_FILES['upload']['name']);
$file->setFilename($filestorename);
$file->setMimeType($_FILES['upload']['type']);
$file->owner_guid = $user->guid;
$file->subtype = "file";
$file->originalfilename = $filestorename;
$file->access_id = ACCESS_DEFAULT;
$file->open("write");
$file->write(get_uploaded_file('upload'));
$file->close();
$result = $file->save();
if ($result) {
    $master = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 550, 550);
    if ($master !== false) {
        $_SESSION['UPLOAD_DATA']['file_save'] = "started";
        $filehandler = new ElggFile();
        $filehandler->setFilename($filestorename);
        $filehandler->setMimeType($_FILES['upload']['type']);
        $filehandler->owner_guid = $user->guid;
        $filehandler->subtype = "file";
        $filehandler->originalfilename = $filestorename;
        $filehandler->access_id = ACCESS_DEFAULT;
        $filehandler->open("write");
        $filehandler->write($master);
        $filehandler->close();
        $filehandler->save();
        $url = '' . $CONFIG->url . 'mod/CKEditor/image_viewer.php?file_guid=' . $filehandler->guid;
        echo '<script type="text/javascript">
Example #27
0
}
$has_uploaded_icon = !empty($_FILES['icon']['type']) && substr_count($_FILES['icon']['type'], 'image/');
if ($has_uploaded_icon) {
    $icon_sizes = elgg_get_config('icon_sizes');
    $prefix = "groups/" . $group->guid;
    $filehandler = new ElggFile();
    $filehandler->owner_guid = $group->owner_guid;
    $filehandler->setFilename($prefix . ".jpg");
    $filehandler->open("write");
    $filehandler->write(get_uploaded_file('icon'));
    $filehandler->close();
    $filename = $filehandler->getFilenameOnFilestore();
    $sizes = array('tiny', 'small', 'medium', 'large');
    $thumbs = array();
    foreach ($sizes as $size) {
        $thumbs[$size] = get_resized_image_from_existing_file($filename, $icon_sizes[$size]['w'], $icon_sizes[$size]['h'], $icon_sizes[$size]['square']);
    }
    if ($thumbs['tiny']) {
        // just checking if resize successful
        $thumb = new ElggFile();
        $thumb->owner_guid = $group->owner_guid;
        $thumb->setMimeType('image/jpeg');
        foreach ($sizes as $size) {
            $thumb->setFilename("{$prefix}{$size}.jpg");
            $thumb->open("write");
            $thumb->write($thumbs[$size]);
            $thumb->close();
        }
        $group->icontime = time();
    }
}
/**
 * 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_config('icon_sizes');
    $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();
}
Example #29
0
     //6. Username
     create_metadata($user->guid, "username", html_entity_decode($user_profile->displayName, ENT_COMPAT, 'UTF-8'), "text", $user->guid, 1);
     //7. Phone
     create_metadata($user->guid, "phone", html_entity_decode($user_profile->phone, ENT_COMPAT, 'UTF-8'), "text", $user->guid, 1);
     //8. Twitter
     create_metadata($user->guid, "twitter", html_entity_decode($user_profile->twitter, ENT_COMPAT, 'UTF-8'), "text", $user->guid, 1);
     //9. Specialties
     create_metadata($user->guid, "skills", html_entity_decode($user_profile->skills, ENT_COMPAT, 'UTF-8'), "text", $user->guid, 1);
     # }}} update user profile
     # {{{ user image
     if ($user_profile->photoURL) {
         $sizes = array('topbar' => array(16, 16, TRUE), 'tiny' => array(25, 25, TRUE), 'small' => array(40, 40, TRUE), 'medium' => array(100, 100, TRUE), 'large' => array(200, 200, FALSE), 'master' => array(550, 550, FALSE));
         $filehandler = new ElggFile();
         $filehandler->owner_guid = $user->guid;
         foreach ($sizes as $size => $dimensions) {
             $image = get_resized_image_from_existing_file($user_profile->photoURL, $dimensions[0], $dimensions[1], $dimensions[2]);
             $filehandler->setFilename("profile/{$user->guid}{$size}.jpg");
             $filehandler->open('write');
             $filehandler->write($image);
             $filehandler->close();
         }
         $user->icontime = time();
     }
     # }}} user image
 } elseif (count($users) == 1) {
     // login user
     login($users[0]);
     // notice
     system_message(elgg_echo('You have signed in with ' . $provider));
 } else {
     throw new Exception('Unable to login with ' . $provider);
}
$x1 = (int) get_input('x1', 0);
$y1 = (int) get_input('y1', 0);
$x2 = (int) get_input('x2', 0);
$y2 = (int) get_input('y2', 0);
$filehandler = new ElggFile();
$filehandler->owner_guid = $owner->getGUID();
$filehandler->setFilename("profile/" . $owner->guid . "master" . ".jpg");
$filename = $filehandler->getFilenameOnFilestore();
$icon_sizes = elgg_get_config('icon_sizes');
unset($icon_sizes['master']);
// 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_existing_file($filename, $size_info['w'], $size_info['h'], $size_info['square'], $x1, $y1, $x2, $y2, $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;
    } else {
        // cleanup on fail
        foreach ($files as $file) {
            $file->delete();
        }
        system_message(elgg_echo('avatar:resize:fail'));