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

Gets the full contents of this file.
public grabFile ( ) : mixed
Результат mixed The file contents.
Пример #1
0
 /**
  * Get the steps from disk
  *
  * @param bool $count get the count of the steps
  *
  * @return false|string[]|int
  */
 public function getSteps($count = false)
 {
     $count = (bool) $count;
     $fh = new ElggFile();
     $fh->owner_guid = $this->getGUID();
     $fh->setFilename('steps.json');
     if (!$fh->exists()) {
         return false;
     }
     $steps = $fh->grabFile();
     unset($fh);
     $steps = @json_decode($steps, true);
     if ($count) {
         return count($steps);
     }
     // reset indexing on steps
     $steps = array_values($steps);
     return $steps;
 }
Пример #2
0
 public function migrateJsonSteps()
 {
     $fh = new \ElggFile();
     $fh->owner_guid = $this->getGUID();
     $fh->setFilename('steps.json');
     if (!$fh->exists()) {
         return false;
     }
     $steps = $fh->grabFile();
     $steps = @json_decode($steps, true);
     foreach ($steps as $step) {
         $new_step = new WizardStep();
         $new_step->container_guid = $this->getGUID();
         $new_step->description = $step;
         $new_step->save();
     }
     $fh->delete();
     return true;
 }
Пример #3
0
/**
 * Get URL data
 *
 * @param string $url URL
 * @return array|false
 */
function seo_get_data($url)
{
    $path = seo_get_path($url);
    if (!$path) {
        return false;
    }
    $hash = sha1($path);
    $site = elgg_get_site_entity();
    $file = new ElggFile();
    $file->owner_guid = $site->guid;
    $file->setFilename("seo/{$hash}.json");
    $data = false;
    if ($file->exists()) {
        $file->open('read');
        $json = $file->grabFile();
        $file->close();
        $data = json_decode($json, true);
    }
    return $data;
}
Пример #4
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();
            switch ($size) {
                case "small":
                    $thumbfile = $file->thumbnail;
                    break;
                case "medium":
                    $thumbfile = $file->smallthumb;
                    break;
                case "large":
                default:
                    $thumbfile = $file->largethumb;
                    break;
            }
            // Grab the file
            if ($thumbfile && !empty($thumbfile)) {
                $readfile = new ElggFile();
                $readfile->owner_guid = $file->owner_guid;
                $readfile->setFilename($thumbfile);
                $mime = $file->getMimeType();
                $contents = $readfile->grabFile();
                // caching images for 10 days
                header("Content-type: {$mime}");
                header('Expires: ' . date('r', time() + 864000));
                header("Pragma: public", true);
                header("Cache-Control: public", true);
                header("Content-Length: " . strlen($contents));
                echo $contents;
                exit;
            }
        }
    }
}
Пример #6
0
<?php

$icon = (int) get_input("icon");
$plugin = elgg_get_plugin_from_id("theme_eersel");
$fh = new ElggFile();
$fh->owner_guid = $plugin->getGUID();
$fh->setFilename("slider_images/" . $icon . ".jpg");
if ($fh->exists()) {
    $contents = $fh->grabFile();
    header("Content-type: image/jpeg", true);
    header("Expires: " . gmdate("D, d M Y H:i:s \\G\\M\\T", strtotime("+6 months")), true);
    header("Pragma: public", true);
    header("Cache-Control: public", true);
    header("Content-Length: " . strlen($contents));
    echo $contents;
} else {
    header("HTTP/1.1 404 Not Found");
}
Пример #7
0
$what = elgg_extract('what', $vars);
$izap_videos = izapVideoCheck_izap_videos($guid);
if ($izap_videos) {
    // check what is needed
    if ($what == 'image') {
        $filename = $izap_videos->imagesrc;
    } elseif (!isset($what) || empty($what) || $what == 'file') {
        $filename = $izap_videos->videofile;
    }
    // only works if there is some file name
    if ($filename != '') {
        $fileHandler = new ElggFile();
        $fileHandler->owner_guid = $izap_videos->owner_guid;
        $fileHandler->setFilename($filename);
        if (file_exists($fileHandler->getFilenameOnFilestore())) {
            $contents = $fileHandler->grabFile();
        }
    }
    if ($contents == '') {
        $contents = elgg_view("izap_videos/izapdesign_logo.gif");
        $type = 'image/gif';
    } elseif ($what == 'image') {
        $type = 'image/jpeg';
    } elseif (!isset($what) || empty($what) || $what == 'file') {
        $type = 'application/x-flv';
    }
    header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', strtotime("+10 days")), true);
    header("Pragma: public");
    header("Cache-Control: public");
    header("Content-Length: " . strlen($contents));
    header("Content-Type: {$type}");
Пример #8
0
 /**
  * Reads cached menu items from file for give root entity
  *
  * @param \ElggEntity $root_entity root entity to fetch the cache from
  *
  * @return array
  */
 public static function getMenuItemsCache(\ElggEntity $root_entity)
 {
     $static_items = [];
     $file = new \ElggFile();
     $file->owner_guid = $root_entity->getGUID();
     $file->setFilename('static_menu_item_cache');
     if ($file->exists()) {
         $static_items = unserialize($file->grabFile());
     }
     return $static_items;
 }
Пример #9
0
<?php

/**
 * Elgg video thumbnail
 *
 * @package Video
 */
// Get video GUID
$video_guid = (int) get_input('video_guid', 0);
// Get video thumbnail size
$size = get_input('size', 'small');
$video = get_entity($video_guid);
if (!elgg_instanceof($video, 'object', 'video')) {
    exit;
}
$filename = "video/{$video_guid}/icon-{$size}.jpg";
// Grab the file
$thumb = new ElggFile();
$thumb->owner_guid = $video->owner_guid;
$thumb->setFilename($filename);
$storename = $thumb->getFilenameOnFilestore();
$contents = $thumb->grabFile();
// caching images for 10 days
header("Content-type: image/jpg");
header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', strtotime("+10 days")), true);
header("Pragma: public", true);
header("Cache-Control: public", true);
header("Content-Length: " . strlen($contents));
echo $contents;
exit;
Пример #10
0
 /**
  * @group FileService
  */
 public function testCanCreateAndReadSymlinks()
 {
     $symlink_name = "symlink.txt";
     $dataroot = _elgg_services()->config->get('dataroot');
     $dir = new \Elgg\EntityDirLocator(2);
     // Remove symlink in case it exists
     if (file_exists("{$dataroot}{$dir}{$symlink_name}")) {
         unlink("{$dataroot}{$dir}{$symlink_name}");
     }
     $target = new ElggFile();
     $target->owner_guid = 2;
     $target->setFilename('symlink-target.txt');
     $target->open('write');
     $target->write('Testing!');
     $target->close();
     $symlink = new ElggFile();
     $symlink->owner_guid = 2;
     $symlink->setFilename($symlink_name);
     $to = $target->getFilenameOnFilestore();
     $from = $symlink->getFilenameOnFilestore();
     $this->assertTrue(symlink($to, $from));
     $this->assertEquals("{$dataroot}{$dir}{$symlink_name}", $from);
     $this->assertTrue($symlink->exists());
     $target->open('read');
     $file_contents = $target->grabFile();
     $target->close();
     $symlink->open('read');
     $symlink_contents = $symlink->grabFile();
     $symlink->close();
     $this->assertEquals($file_contents, $symlink_contents);
     $this->assertTrue(unlink("{$dataroot}{$dir}{$symlink_name}"));
     $this->assertFalse($symlink->exists());
 }
Пример #11
0
 /**
  * Get the contents of one attchements
  *
  * @param string $filename the filename of the attachment
  *
  * @return false|string
  */
 public function getAttachment($filename)
 {
     if (!$this->getGUID()) {
         return false;
     }
     $fh = new ElggFile();
     $fh->owner_guid = $this->getGUID();
     $fh->setFilename("attachments/{$filename}");
     if (!$fh->exists()) {
         return false;
     }
     return $fh->grabFile();
 }
Пример #12
0
 /**
  * Get the recipients
  *
  * @return bool|array
  */
 public function getRecipients()
 {
     $result = false;
     // check for previous DB recipients
     if ($this->recipients) {
         $recipients = json_decode($this->recipients, true);
         $this->setRecipients($recipients);
     }
     $fh = new ElggFile();
     $fh->owner_guid = $this->getGUID();
     $fh->setFilename('recipients.json');
     if ($fh->exists()) {
         $raw = $fh->grabFile();
         $result = json_decode($raw, true);
     }
     return $result;
 }
Пример #13
0
/**
 * Reschedule a document for deletion, because something failed
 *
 * @param int $guid the document to be rescheduled
 *
 * @return void
 */
function elasticsearch_reschedule_document_for_deletion($guid)
{
    $plugin = elgg_get_plugin_from_id('elasticsearch');
    $fh = new ElggFile();
    $fh->owner_guid = $plugin->getGUID();
    $fh->setFilename("documents_for_deletion/{$guid}");
    if (!$fh->exists()) {
        // shouldn't happen
        return;
    }
    $contents = $fh->grabFile();
    if (empty($contents)) {
        return;
    }
    $contents = unserialize($contents);
    if (!is_array($contents)) {
        return;
    }
    // try agin in an hour
    $contents['time'] = time() + 60 * 60;
    $fh->open('write');
    $fh->write(serialize($contents));
    $fh->close();
}
Пример #14
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 bool
 */
function group_tools_transfer_group_ownership(ElggGroup $group, ElggUser $new_owner)
{
    if (!$group instanceof ElggGroup || !$group->canEdit()) {
        return false;
    }
    if (!$new_owner instanceof ElggUser) {
        return false;
    }
    $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', '\\ColdTrick\\GroupTools\\Access::allowGroupOwnerTransfer');
    $old_owner = $group->getOwnerEntity();
    // transfer ownership
    $group->owner_guid = $new_owner->getGUID();
    $group->container_guid = $new_owner->getGUID();
    if (!$group->save()) {
        return false;
    }
    // make sure user is added to the group
    $group->join($new_owner);
    // 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 = elgg_get_icon_sizes($group->getType());
        $ofh = new ElggFile();
        $ofh->owner_guid = $old_owner->getGUID();
        $nfh = new ElggFile();
        $nfh->owner_guid = $group->getOwnerGUID();
        foreach ($sizes as $size => $info) {
            // set correct file to handle
            $ofh->setFilename("{$prefix}{$size}.jpg");
            if (!$ofh->exists()) {
                // file doesn't exist
                continue;
            }
            $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 = ['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', [$group->name]);
        $message = elgg_echo('group_tools:notify:transfer:message', [$new_owner->name, $loggedin_user->name, $group->name, $group->getURL()]);
        notify_user($new_owner->getGUID(), $group->getGUID(), $subject, $message);
    }
    // unregister plugin hook to make sure transfer can complete
    elgg_unregister_plugin_hook_handler('permissions_check', 'group', '\\ColdTrick\\GroupTools\\Access::allowGroupOwnerTransfer');
    return true;
}
Пример #15
0
/**
 * Gets the jpeg contents of the resized version of an already uploaded image
 * (Returns false if the file was not an image)
 *
 * @param string $input_name The name of the file on the disk
 * @param int    $maxwidth   The desired width of the resized image
 * @param int    $maxheight  The desired height of the resized image
 * @param bool   $square     If set to true, takes the smallest of maxwidth and
 * 			                 maxheight and use it to set the dimensions on the new image.
 *                           If no crop parameters are set, the largest square that fits
 *                           in the image centered will be used for the resize. If square,
 *                           the crop must be a square region.
 * @param int    $x1         x coordinate for top, left corner
 * @param int    $y1         y coordinate for top, left corner
 * @param int    $x2         x coordinate for bottom, right corner
 * @param int    $y2         y coordinate for bottom, right corner
 * @param bool   $upscale    Resize images smaller than $maxwidth x $maxheight?
 *
 * @return false|mixed The contents of the resized image, or false on failure
 * @deprecated 2.3
 */
function get_resized_image_from_existing_file($input_name, $maxwidth, $maxheight, $square = false, $x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0, $upscale = false)
{
    elgg_deprecated_notice(__FUNCTION__ . ' has been deprecated. Use elgg_save_resized_image()', '2.3');
    if (!is_readable($input_name)) {
        return false;
    }
    // we will write resized image to a temporary file and then delete it
    $tmp_filename = time() . pathinfo($input_name, PATHINFO_BASENAME);
    $tmp = new ElggFile();
    $tmp->setFilename("tmp/{$tmp_filename}");
    $tmp->open('write');
    $tmp->close();
    $params = ['w' => $maxwidth, 'h' => $maxheight, 'x1' => $x1, 'y1' => $y1, 'x2' => $x2, 'y2' => $y2, 'square' => $square, 'upscale' => $upscale];
    $destination = $tmp->getFilenameOnFilestore();
    $image_bytes = false;
    if (elgg_save_resized_image($input_name, $destination, $params)) {
        $tmp->open('read');
        $image_bytes = $tmp->grabFile();
        $tmp->close();
    }
    $tmp->delete();
    return $image_bytes;
}
Пример #16
0
<?php

elgg_admin_gatekeeper();
$guid = (int) get_input('guid');
$filename = get_input('file');
$entity = get_entity($guid);
if (empty($filename) || !elgg_instanceof($entity, 'object', 'profile_sync_config')) {
    return;
}
$fh = new ElggFile();
$fh->owner_guid = $entity->getGUID();
$fh->setFilename($filename);
if (!$fh->exists()) {
    echo elgg_echo('notfound');
    return;
}
list($time) = explode('.', $filename);
$datetime = date(elgg_echo('friendlytime:date_format'), $time);
$content = elgg_view('output/longtext', ['value' => $fh->grabFile()]);
$content .= elgg_view('output/url', ['text' => elgg_echo('back'), 'href' => 'ajax/view/profile_sync/sync_logs/?guid=' . $entity->getGUID(), 'is_trusted' => true, 'class' => 'elgg-lightbox float-alt']);
echo elgg_view_module('inline', elgg_echo('profile_sync:view_log:title', [$entity->title, $datetime]), $content, ['class' => 'profile-sync-log-wrapper']);
Пример #17
0
<?php

/**
 * CustomStyle - Returns custombackground for user
 * 
 * @package customstyle
 * @author ColdTrick IT Solutions
 * @copyright Coldtrick IT Solutions 2009
 * @link http://www.coldtrick.com/
 */
header('Content-Type: image/jpeg');
if (get_input('id')) {
    $filehandler = new ElggFile();
    $filehandler->owner_guid = get_input('id');
    if (get_input('thumb') == "true") {
        $filehandler->setFilename('custombackground_thumb');
        if (!$filehandler->exists()) {
            $filehandler->setFilename('custombackground');
        }
    } else {
        $filehandler->setFilename('custombackground');
    }
    if ($filehandler->exists()) {
        echo $filehandler->grabFile();
    }
}
Пример #18
0
     $entity->container_guid = $user->getGUID();
 } else {
     $entity->owner_guid = $user->getGUID();
 }
 if ($entity->save()) {
     if (!empty($entity->icontime)) {
         $prefix = "blogs/" . $entity->getGUID();
         $old_fh = new ElggFile();
         $old_fh->owner_guid = $old_owner;
         $old_fh->setFilename($prefix . ".jpg");
         if ($old_fh->exists()) {
             $new_fh = new ElggFile();
             $new_fh->owner_guid = $user->getGUID();
             $new_fh->setFilename($prefix . ".jpg");
             $new_fh->open("write");
             $new_fh->write($old_fh->grabFile());
             $new_fh->close();
             $old_fh->delete();
             $sizes = array("tiny", "small", "medium", "large");
             foreach ($sizes as $size) {
                 $new_fh->setFilename($prefix . $size . ".jpg");
                 $old_fh->setFilename($prefix . $size . ".jpg");
                 $new_fh->open("write");
                 $new_fh->write($old_fh->grabFile());
                 $new_fh->close();
                 $old_fh->delete();
             }
             $entity->icontime = time();
         }
     }
     $forward_url = $entity->getURL();
Пример #19
0
 /**
  * Outputs raw icon
  *
  * @param int    $entity_guid GUID of an entity
  * @param string $size        Icon size
  * @return void
  */
 public function outputRawIcon($entity_guid, $size = null)
 {
     if (headers_sent()) {
         exit;
     }
     $ha = access_get_show_hidden_status();
     access_show_hidden_entities(true);
     $entity = get_entity($entity_guid);
     if (!$entity) {
         exit;
     }
     $size = strtolower($size ?: 'medium');
     $filename = "icons/" . $entity->guid . $size . ".jpg";
     $etag = md5($entity->icontime . $size);
     $filehandler = new \ElggFile();
     $filehandler->owner_guid = $entity->owner_guid;
     $filehandler->setFilename($filename);
     if ($filehandler->exists()) {
         $filehandler->open('read');
         $contents = $filehandler->grabFile();
         $filehandler->close();
     } else {
         forward('', '404');
     }
     $mimetype = $entity->mimetype ? $entity->mimetype : 'image/jpeg';
     access_show_hidden_entities($ha);
     header("Content-type: {$mimetype}");
     header("Etag: {$etag}");
     header('Expires: ' . date('r', time() + 864000));
     header("Pragma: public");
     header("Cache-Control: public");
     header("Content-Length: " . strlen($contents));
     echo $contents;
     exit;
 }
Пример #20
0
 public function getIconContents($size = "medium")
 {
     $result = false;
     if (!empty($this->icontime) && in_array($size, $this->icon_sizes)) {
         $this->username = $this->guid;
         $icon = new ElggFile();
         $icon->owner_guid = $this->guid;
         $icon->setFilename("subsite_manager/" . $this->guid . "/subsite_icon/" . $size . ".jpg");
         if ($icon->exists()) {
             $result = $icon->grabFile();
         }
         unset($this->username);
         // fallback to old path
         if (empty($result)) {
             $icon_path = elgg_get_config("dataroot") . "subsite_manager/" . $this->guid . "/subsite_icon/" . $size . ".jpg";
             if (file_exists($icon_path)) {
                 $result = file_get_contents($icon_path);
             }
         }
     }
     return $result;
 }
Пример #21
0
 /**
  * Get the image data of a thumbnail
  *
  * @param string $size
  * @return string
  */
 public function getThumbnail($size)
 {
     switch ($size) {
         case 'thumb':
             $thumb = $this->thumbnail;
             break;
         case 'small':
             $thumb = $this->smallthumb;
             break;
         case 'large':
             $thumb = $this->largethumb;
             break;
         default:
             return '';
             break;
     }
     if (!$thumb) {
         return '';
     }
     $file = new ElggFile();
     $file->owner_guid = $this->getOwnerGUID();
     $file->setFilename($thumb);
     return $file->grabFile();
 }
Пример #22
0
/**
 * Read video file content
 * 
 * @version 5.0
 */
function izap_read_video_file()
{
    $guid = (int) get_input('videoID');
    $entity = get_entity($guid);
    if (!elgg_instanceof($entity, 'object', GLOBAL_IZAP_VIDEOS_SUBTYPE)) {
        exit;
    }
    if ($entity->videofile) {
        $get_video_name = end(explode('/', $entity->videofile));
        $izapvideo_obj = new IzapVideo();
        $set_video_name = $izapvideo_obj->getTmpPath($get_video_name);
        if (izap_get_file_extension($set_video_name) == 'flv') {
            $set_video_name = preg_replace('/\\.[^.\\s]{3,4}$/', '', $set_video_name) . '.flv';
        } else {
            $set_video_name = preg_replace('/\\.[^.\\s]{3,4}$/', '', $set_video_name) . '_c.flv';
        }
        $elggfile_obj = new ElggFile();
        $elggfile_obj->owner_guid = $entity->owner_guid;
        $elggfile_obj->setFilename($set_video_name);
        if (file_exists($elggfile_obj->getFilenameOnFilestore())) {
            $contents = $elggfile_obj->grabFile();
        }
        $content_type = 'video/x-flv';
        header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', strtotime("+10 days")), true);
        header("Pragma: public", true);
        header("Cache-Control: public", true);
        header("Content-Length: " . strlen($contents));
        header("Content-type: {$content_type}", true);
        echo $contents;
        exit;
    }
}
Пример #23
0
<?php

$guid = get_input('guid');
$filename = get_input('file');
if (!empty($guid) && !empty($filename)) {
    if ($entity = get_entity($guid)) {
        if ($entity->getSubtype() == Event::SUBTYPE) {
            $event = $entity;
        }
    }
    $files = json_decode($event->files);
    foreach ($files as $file) {
        if (strtolower($file->file) == strtolower($filename)) {
            $prefix = "events/" . $event->getGUID() . "/files/";
            $fileHandler = new ElggFile();
            $fileHandler->setFilename($prefix . $file->file);
            $fileHandler->owner_guid = $event->owner_guid;
            //fix for IE https issue
            header('Pragma: public');
            header('Content-Type: ' . $file->mime);
            header('Content-Disposition: Attachment; filename=' . $file->file);
            echo $fileHandler->grabFile();
            exit;
        }
    }
}
register_error(elgg_echo('event_manager:event:file:notfound:text'));
forward(REFERER);
Пример #24
0
<?php

global $CONFIG;
$guid = (int) get_input("guid");
$size = strtolower(get_input("size"));
if (!in_array($size, array("large", "medium", "small", "tiny", "master", "topbar"))) {
    $size = "medium";
}
$success = false;
if ($publication = get_entity($guid)) {
    $filehandler = new ElggFile();
    $filehandler->owner_guid = $publication->getOwnerGUID();
    $filehandler->setFilename("publications/" . $publication->getGUID() . $size . ".jpg");
    if ($filehandler->exists()) {
        if ($contents = $filehandler->grabFile()) {
            $success = true;
        }
    }
}
if (!$success) {
    $contents = @file_get_contents($CONFIG->path . "_graphics/icons/default/{$size}.png");
}
header("Content-type: image/jpeg");
header("Expires: " . date("r", time() + 864000));
header("Pragma: public");
header("Cache-Control: public");
header("Content-Length: " . strlen($contents));
echo $contents;
Пример #25
0
/**
 * Gets tree html from cache
 *
 * @param ElggEntity $entity root page to get the cache for
 *
 * @return false|string
 */
function pages_tools_get_tree_html_from_cache(ElggEntity $entity)
{
    if (!$entity) {
        return false;
    }
    $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);
    if (!$fh->exists()) {
        return false;
    }
    return $fh->grabFile();
}
Пример #26
0
function pleio_api_get_group_icon($group_id = 0)
{
    $user = elgg_get_logged_in_user_entity();
    if ($user) {
        $size = "large";
        $group_id = intval($group_id);
        $group = get_entity($group_id);
        $filehandler = new ElggFile();
        $filehandler->owner_guid = $group->owner_guid;
        $filehandler->setFilename("groups/" . $group->guid . $size . ".jpg");
        $success = false;
        if ($filehandler->open("read")) {
            if ($contents = $filehandler->grabFile()) {
                $success = true;
            }
        }
        if (!$success) {
            $location = elgg_get_plugins_path() . "groups/graphics/default{$size}.gif";
            $contents = @file_get_contents($location);
        }
        return base64_encode($contents);
    }
    return new ErrorResult("Groep niet gevonden of geen lid");
}
Пример #27
0
<?php

$user = elgg_extract('user', $vars);
if (!$user instanceof ElggUser) {
    return;
}
$icontime = $user->icontime;
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');
Пример #28
0
/**
 * Returns keywords that will autocomplete in the searchbox
 * 
 * @return array
 */
function search_advanced_get_keywords()
{
    $result = array();
    $plugin_entity = elgg_get_plugin_from_id("search_advanced");
    if ($plugin_entity) {
        // check if cachefile exists, if not create
        $file = new ElggFile();
        $file->owner_guid = $plugin_entity->getGUID();
        $file->setFilename("search_advanced_keywords_cache.json");
        if (!$file->exists()) {
            // create new cache
            $keywords = array();
            // check global tags plugin
            if (elgg_is_active_plugin("global_tags")) {
                if ($setting = elgg_get_plugin_setting("global_tags", "global_tags")) {
                    $tags = string_to_tag_array($setting);
                    if (!empty($tags)) {
                        $keywords = array_merge($keywords, $tags);
                    }
                }
            }
            // check categories plugin
            if (elgg_is_active_plugin("categories")) {
                $categories = elgg_get_site_entity()->categories;
                if (!is_array($categories)) {
                    $categories = array($categories);
                }
                if (!empty($categories)) {
                    $keywords = array_merge($keywords, $categories);
                }
            }
            // remove duplicates
            $keywords = array_unique($keywords);
            // sort naturally
            natcasesort($keywords);
            // save as json
            $data = json_encode($keywords);
            $file->open("write");
            $file->write($data);
            $file->close();
        }
        // read from cachefile
        if ($file->open("read")) {
            if ($file_contents = $file->grabFile()) {
                $result = json_decode($file_contents);
            }
        }
    }
    return $result;
}
Пример #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
 /**
  * get the file
  * @param array $file_array
  *                    'source' => file source
  * @return  mixed The file contents.
  */
 public static function getFile($file_array)
 {
     if (!is_array($file_array)) {
         return FALSE;
     }
     $source = $file_array['source'];
     $filehandler = new ElggFile();
     $filehandler->owner_guid = $file_array['owner_guid'] ? $file_array['owner_guid'] : elgg_get_logged_in_user_guid();
     $filehandler->setFilename($source);
     $filehandler->open("read");
     return $filehandler->grabFile();
 }