write() публичный Метод

Write data.
public write ( string $data ) : boolean
$data string The data
Результат boolean
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;
        }
    }
}
Пример #2
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;
}
Пример #3
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();
    }
}
Пример #4
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);
        }
    }
}
Пример #5
0
 /**
  * Save the wiard steps to disk (because of DB limits)
  *
  * @param string[] $steps the wizard steps
  *
  * @return void
  */
 public function saveSteps($steps)
 {
     if (!is_array($steps)) {
         $steps = array($steps);
     }
     $fh = new ElggFile();
     $fh->owner_guid = $this->getGUID();
     $fh->setFilename('steps.json');
     $fh->open('write');
     $fh->write(json_encode($steps));
     $fh->close();
 }
Пример #6
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;
}
Пример #7
0
 public function uploadIcon($size, $contents)
 {
     $result = false;
     if (in_array($size, $this->icon_sizes) && !empty($contents)) {
         $this->username = $this->guid;
         $icon = new ElggFile();
         $icon->owner_guid = $this->guid;
         $icon->setFilename("subsite_manager/" . $this->guid . "/subsite_icon/" . $size . ".jpg");
         $icon->open("write");
         $icon->write($contents);
         $icon->close();
         $this->icontime = time();
         unset($this->username);
         if ($this->save()) {
             $result = true;
         }
     }
     return $result;
 }
Пример #8
0
/**
 * Downloads the thumbnail and saves into data folder
 *
 * @param ElggObject $item
 * @return bool
 */
function videolist_2012022501($item)
{
    // do not upgrade videos that have already been upgraded
    if ($item->thumbnail === true) {
        return true;
    }
    $thumbnail = file_get_contents($item->thumbnail);
    if (!$thumbnail) {
        return false;
    }
    $prefix = "videolist/" . $item->guid;
    $filehandler = new ElggFile();
    $filehandler->owner_guid = $item->owner_guid;
    $filehandler->setFilename($prefix . ".jpg");
    $filehandler->open("write");
    $filehandler->write($thumbnail);
    $filehandler->close();
    $item->thumbnail = true;
    return true;
}
Пример #9
0
 function testElggFileDelete()
 {
     global $CONFIG;
     $user = $this->createTestUser();
     $filestore = $this->filestore;
     $dir = new \Elgg\EntityDirLocator($user->guid);
     $file = new \ElggFile();
     $file->owner_guid = $user->guid;
     $file->setFilename('testing/ElggFileDelete');
     $this->assertTrue($file->open('write'));
     $this->assertTrue($file->write('Test'));
     $this->assertTrue($file->close());
     $file->save();
     $filename = $file->getFilenameOnFilestore($file);
     $filepath = $CONFIG->dataroot . $dir . "testing/ElggFileDelete";
     $this->assertIdentical($filename, $filepath);
     $this->assertTrue(file_exists($filepath));
     $this->assertTrue($file->delete());
     $this->assertFalse(file_exists($filepath));
     $user->delete();
 }
Пример #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;
 }
 public function testFilenameOnFilestore()
 {
     global $CONFIG;
     // create a user to own the file
     $user = $this->createTestUser();
     $created = date('Y/m/d', $user->time_created);
     // setup a test file
     $file = new ElggFile();
     $file->owner_guid = $user->guid;
     $file->setFilename('testing/filestore.txt');
     $file->open('write');
     $file->write('Testing!');
     $this->assertTrue($file->close());
     // ensure filename and path is expected
     $filename = $file->getFilenameOnFilestore($file);
     $filepath = "{$CONFIG->dataroot}{$created}/{$user->guid}/testing/filestore.txt";
     $this->assertIdentical($filename, $filepath);
     $this->assertTrue(file_exists($filepath));
     // ensure file removed on user delete
     $user->delete();
     $this->assertFalse(file_exists($filepath));
 }
Пример #12
0
/**
 * Downloads the thumbnail and saves into data folder
 *
 * @param ElggObject $item
 * @return bool
 */
function videolist_2012022501($item)
{
    require_once elgg_get_plugins_path() . 'upgrade-tools/lib/upgrade_tools.php';
    // get thumbnail image
    $thumbnail = file_get_contents($item->thumbnail);
    if (!$thumbnail) {
        return false;
    }
    $prefix = "videolist/" . $item->guid;
    $filehandler = new ElggFile();
    $filehandler->owner_guid = $item->owner_guid;
    $filehandler->setFilename($prefix . ".jpg");
    $filehandler->open("write");
    $filehandler->write($thumbnail);
    $filehandler->close();
    // update properties
    if ($item->url) {
        $item->video_url = $item->url;
        $item->deleteMetadata('url');
    }
    if ($item->desc) {
        $item->description = $item->desc;
        $item->deleteMetadata('desc');
        $item->save();
    }
    if ($item->embedurl) {
        $item->deleteMetadata('embedurl');
    }
    upgrade_change_subtype($item, 'videolist_item');
    // update river
    $options = array('object_guid' => $item->guid);
    $river_items = elgg_get_river($options);
    foreach ($river_items as $river_item) {
        if ($river_item->action_type == 'create') {
            upgrade_update_river($river_item->id, 'river/object/videolist_item/create', $item->guid, 0);
        }
    }
    return true;
}
Пример #13
0
/**
 * Cache the tangram vacancy xml
 *
 * @return void
 */
function haarlem_tangram_cache_xml()
{
    $last_try = (int) haarlem_tangram_get_setting('tangram_last_update');
    $tangram_url = haarlem_tangram_get_setting('tangram_url');
    if (empty($tangram_url)) {
        return;
    }
    if ($last_try > time() - 60 * 60) {
        // prevent deadloop tries
        return;
    }
    // store last try to prevent deadloops
    elgg_set_plugin_setting('tangram_last_update', time(), 'haarlem_tangram');
    // prepare cURL call
    $ch = curl_init($tangram_url);
    // settings
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    // do the request
    $content = curl_exec($ch);
    $curl_info = curl_getinfo($ch);
    // close curl
    curl_close($ch);
    // verify output
    if (elgg_extract('http_code', $curl_info) !== 200 || stristr(elgg_extract('content_type', $curl_info), 'text/xml') === false) {
        // something went wrong
        return;
    }
    // save output
    $plugin = elgg_get_plugin_from_id('haarlem_tangram');
    $fh = new ElggFile();
    $fh->owner_guid = $plugin->getGUID();
    $fh->setFilename('tangram.xml');
    $fh->open('write');
    $fh->write($content);
    $fh->close();
    // set last success update
    elgg_set_plugin_setting('tangram_last_update_success', time(), 'haarlem_tangram');
}
Пример #14
0
 function testDetectMimeType()
 {
     $user = $this->createTestUser();
     $file = new \ElggFile();
     $file->owner_guid = $user->guid;
     $file->setFilename('testing/filestore.txt');
     $file->open('write');
     $file->write('Testing!');
     $file->close();
     $mime = $file->detectMimeType(null, 'text/plain');
     // mime should not be null if default is set
     $this->assertTrue(isset($mime));
     // mime of a file object should match mime of a file path that represents this file on filestore
     $resource_mime = $file->detectMimeType($file->getFilenameOnFilestore(), 'text/plain');
     $this->assertIdentical($mime, $resource_mime);
     // calling detectMimeType statically raises strict policy warning
     // @todo: remove this once a new static method has been implemented
     error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED);
     // method output should not differ between a static and a concrete call if the file path is set
     $resource_mime_static = \ElggFile::detectMimeType($file->getFilenameOnFilestore(), 'text/plain');
     $this->assertIdentical($resource_mime, $resource_mime_static);
     error_reporting(E_ALL);
     $user->delete();
 }
Пример #15
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;
}
Пример #16
0
/**
 * 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);
}
Пример #17
0
/**
 * function to upload a profile icon on register of a user
 * 
 * @param $user
 * @return unknown_type
 */
function add_profile_icon($user)
{
    $topbar = get_resized_image_from_uploaded_file('profile_icon', 16, 16, true);
    $tiny = get_resized_image_from_uploaded_file('profile_icon', 25, 25, true);
    $small = get_resized_image_from_uploaded_file('profile_icon', 40, 40, true);
    $medium = get_resized_image_from_uploaded_file('profile_icon', 100, 100, true);
    $large = get_resized_image_from_uploaded_file('profile_icon', 200, 200);
    $master = get_resized_image_from_uploaded_file('profile_icon', 550, 550);
    $prefix = $user->guid;
    $cur_version = get_version();
    if ($cur_version < 2010071002) {
        $prefix = $user->name;
    }
    if ($small !== false && $medium !== false && $large !== false && $tiny !== false) {
        $filehandler = new ElggFile();
        $filehandler->owner_guid = $user->getGUID();
        $filehandler->setFilename("profile/" . $prefix . "large.jpg");
        $filehandler->open("write");
        $filehandler->write($large);
        $filehandler->close();
        $filehandler->setFilename("profile/" . $prefix . "medium.jpg");
        $filehandler->open("write");
        $filehandler->write($medium);
        $filehandler->close();
        $filehandler->setFilename("profile/" . $prefix . "small.jpg");
        $filehandler->open("write");
        $filehandler->write($small);
        $filehandler->close();
        $filehandler->setFilename("profile/" . $prefix . "tiny.jpg");
        $filehandler->open("write");
        $filehandler->write($tiny);
        $filehandler->close();
        $filehandler->setFilename("profile/" . $prefix . "topbar.jpg");
        $filehandler->open("write");
        $filehandler->write($topbar);
        $filehandler->close();
        $filehandler->setFilename("profile/" . $prefix . "master.jpg");
        $filehandler->open("write");
        $filehandler->write($master);
        $filehandler->close();
        $user->icontime = time();
    }
}
     // custom image?
     // right file type and not to big?
     if ($image == 'customtimeline') {
         if (substr_count($_FILES['timelinefile']['type'], 'image/') && isset($_FILES['timelinefile']) && $_FILES['timelinefile']['error'] == 0) {
             $filename = "customtimeline";
             $extension = pathinfo($_FILES['timelinefile']['name']);
             $extension = $extension['extension'];
             $filehandler = new ElggFile();
             $filehandler->setFilename($filename);
             $filehandler->open("write");
             $filehandler->write(get_uploaded_file('timelinefile'));
             $filehandler->close();
             $thumbnail = new ElggFile();
             $thumbnail->setFilename($filename . "_thumb");
             $thumbnail->open("write");
             $thumbnail->write(get_resized_image_from_uploaded_file('timelinefile', 150, 150, false));
             $thumbnail->close();
             $timelineURL = 'pg/timeline_theme/getbackground?id=' . $current_user;
         } else {
             register_error(elgg_echo('timelinestyle:timeline:error:image'));
             forward($_SERVER['HTTP_REFERER']);
         }
     } else {
         $timelineURL = $image;
     }
     if (create_metadata($timelinestyle_object->guid, 'timeline-image', $timelineURL, 'string', $_SESSION['guid'], $access_id) == false || empty($timelineURL)) {
         $error = true;
     }
 }
 // repeat
 if (get_input('timeline-repeat')) {
 $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) {
Пример #20
0
/**
 * Saves tree html to cache
 *
 * @param ElggEntity $entity    root page entity to save data with
 * @param string     $tree_data the data to be saved
 *
 * @return void
 */
function pages_tools_save_tree_html_to_cache(ElggEntity $entity, $tree_data = '')
{
    if (!$entity instanceof ElggEntity || empty($tree_data)) {
        return;
    }
    $user_guid = elgg_get_logged_in_user_guid();
    if (empty($user_guid)) {
        $user_guid = 'logged-out';
    }
    $file_name = 'tree_cache/' . md5($user_guid . '-cached-' . $entity->getGUID()) . '.html';
    $fh = new ElggFile();
    $fh->owner_guid = $entity->getGUID();
    $fh->setFilename($file_name);
    $fh->open('write');
    $fh->write($tree_data);
    $fh->close();
}
/**
 * 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;
}
Пример #22
0
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);
}
Пример #23
0
$publication->tags = $tags;
$publication->pubtype = $type;
// save custom data
foreach ($data as $key => $value) {
    $publication->{$key} = $value;
}
// trigger event to save other custom data
elgg_trigger_event('save:data', 'publications', $publication);
// files
$file_contents = get_uploaded_file('attachment');
if (!empty($file_contents)) {
    $fh = new ElggFile();
    $fh->owner_guid = $publication->getGUID();
    $file_name = $_FILES['attachment']['name'];
    $mime = $_FILES['attachment']['type'];
    $fh->setFilename($file_name);
    if ($fh->open('write')) {
        $fh->write($file_contents);
        $fh->close();
        $publication->attached_file = $file_name;
        $publication->attached_file_mime_type = $mime;
    }
}
$publication->save();
if ($new_entity) {
    elgg_create_river_item(['view' => 'river/object/publication/create', 'action_type' => 'create', 'subject_guid' => $publication->getOwnerGUID(), 'object_guid' => $publication->getGUID(), 'target_guid' => $publication->getContainerGUID(), 'access_id' => $publication->access_id]);
}
system_message(elgg_echo('publication:posted'));
/* todo: activate add_to_river on settings */
#add_to_river('river/object/publication/update','update',$_SESSION['user']->guid,$publication->guid);
forward($publication->getURL());
Пример #24
0
            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);
        }
        ?>
<html>
Пример #25
0
    $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();
    }
}
// @todo Remove this when #4683 fixed
if ($must_move_icons) {
    $filehandler = new ElggFile();
    $filehandler->setFilename('groups');
    $filehandler->owner_guid = $old_owner_guid;
    $old_path = $filehandler->getFilenameOnFilestore();
    $sizes = array('', 'tiny', 'small', 'medium', 'large');
    if ($has_uploaded_icon) {
        // delete those under old owner
        foreach ($sizes as $size) {
Пример #26
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;
}
Пример #27
0
 if (!empty($group->icontime)) {
     $prefix = "groups/" . $group->getGUID();
     $sizes = array("tiny", "small", "medium", "large");
     $ofh = new ElggFile();
     $ofh->owner_guid = $old_owner->getGUID();
     $nfh = new ElggFile();
     $nfh->owner_guid = $group->getOwnerGUID();
     foreach ($sizes as $size) {
         // set correct file to handle
         $ofh->setFilename($prefix . $size . ".jpg");
         $nfh->setFilename($prefix . $size . ".jpg");
         // open files
         $ofh->open("read");
         $nfh->open("write");
         // copy file
         $nfh->write($ofh->grabFile());
         // close file
         $ofh->close();
         $nfh->close();
         // cleanup old file
         $ofh->delete();
     }
     $group->icontime = time();
 }
 // move metadata of the group to the new owner
 $options = array("guid" => $group->getGUID(), "limit" => false);
 if ($metadata = elgg_get_metadata($options)) {
     foreach ($metadata as $md) {
         if ($md->owner_guid == $old_owner->getGUID()) {
             $md->owner_guid = $new_owner->getGUID();
             $md->save();
Пример #28
0
 /**
  * Delete the album directory on disk
  */
 protected function deleteAlbumDir()
 {
     $tmpfile = new ElggFile();
     $tmpfile->setFilename('image/' . $this->guid . '/._tmp_del_tidypics_album_');
     $tmpfile->subtype = 'image';
     $tmpfile->owner_guid = $this->owner_guid;
     $tmpfile->container_guid = $this->guid;
     $tmpfile->open("write");
     $tmpfile->write('');
     $tmpfile->close();
     $tmpfile->save();
     $albumdir = eregi_replace('/._tmp_del_tidypics_album_', '', $tmpfile->getFilenameOnFilestore());
     $tmpfile->delete();
     // sanity check: must be a directory
     if (!($handle = opendir($albumdir))) {
         return false;
     }
     // loop through all files that might still remain undeleted in this directory and delete them
     // note: this does not delete the corresponding image entities from the database
     while (($file = readdir($handle)) !== false) {
         if (in_array($file, array('.', '..'))) {
             continue;
         }
         $path = "{$albumdir}/{$file}";
         unlink($path);
     }
     // remove empty directory
     closedir($handle);
     return rmdir($albumdir);
 }
Пример #29
0
/**
 * Helper function to transfer the ownership of a group to a new user
 *
 * @param ElggGroup $group     the group to transfer
 * @param ElggUser  $new_owner the new owner
 *
 * @return boolean
 */
function group_tools_transfer_group_ownership(ElggGroup $group, ElggUser $new_owner)
{
    $result = false;
    if (empty($group) || !elgg_instanceof($group, "group") || !$group->canEdit()) {
        return $result;
    }
    if (empty($new_owner) || !elgg_instanceof($new_owner, "user")) {
        return $result;
    }
    $loggedin_user = elgg_get_logged_in_user_entity();
    // register plugin hook to make sure transfer can complete
    elgg_register_plugin_hook_handler("permissions_check", "group", "group_tools_admin_transfer_permissions_hook");
    $old_owner = $group->getOwnerEntity();
    // transfer ownership
    $group->owner_guid = $new_owner->getGUID();
    $group->container_guid = $new_owner->getGUID();
    // make sure user is added to the group
    $group->join($new_owner);
    if ($group->save()) {
        // remove existing group administrator role for new owner
        remove_entity_relationship($new_owner->getGUID(), "group_admin", $group->getGUID());
        // check for group icon
        if (!empty($group->icontime)) {
            $prefix = "groups/" . $group->getGUID();
            $sizes = array("", "tiny", "small", "medium", "large");
            $ofh = new ElggFile();
            $ofh->owner_guid = $old_owner->getGUID();
            $nfh = new ElggFile();
            $nfh->owner_guid = $group->getOwnerGUID();
            foreach ($sizes as $size) {
                // set correct file to handle
                $ofh->setFilename($prefix . $size . ".jpg");
                $nfh->setFilename($prefix . $size . ".jpg");
                // open files
                $ofh->open("read");
                $nfh->open("write");
                // copy file
                $nfh->write($ofh->grabFile());
                // close file
                $ofh->close();
                $nfh->close();
                // cleanup old file
                $ofh->delete();
            }
            $group->icontime = time();
        }
        // move metadata of the group to the new owner
        $options = array("guid" => $group->getGUID(), "limit" => false);
        $metadata = elgg_get_metadata($options);
        if (!empty($metadata)) {
            foreach ($metadata as $md) {
                if ($md->owner_guid == $old_owner->getGUID()) {
                    $md->owner_guid = $new_owner->getGUID();
                    $md->save();
                }
            }
        }
        // notify new owner
        if ($new_owner->getGUID() != $loggedin_user->getGUID()) {
            $subject = elgg_echo("group_tools:notify:transfer:subject", array($group->name));
            $message = elgg_echo("group_tools:notify:transfer:message", array($new_owner->name, $loggedin_user->name, $group->name, $group->getURL()));
            notify_user($new_owner->getGUID(), $group->getGUID(), $subject, $message);
        }
        $result = true;
    }
    // unregister plugin hook to make sure transfer can complete
    elgg_unregister_plugin_hook_handler("permissions_check", "group", "group_tools_admin_transfer_permissions_hook");
    return $result;
}
Пример #30
0
    register_error(elgg_echo('avatar:upload:fail'));
    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;
    } else {
        // cleanup on fail
        foreach ($files as $file) {
            $file->delete();
        }
        register_error(elgg_echo('avatar:resize:fail'));
        forward(REFERER);
    }
}
// reset crop coordinates
$owner->x1 = 0;
$owner->x2 = 0;
$owner->y1 = 0;