Beispiel #1
0
<?php

/**
* Elgg file delete
* 
* @package ElggFile
*/
$guid = (int) get_input('guid');
$file = new FilePluginFile($guid);
if (!$file->guid) {
    register_error(elgg_echo("file:deletefailed"));
    forward('file/all');
}
if (!$file->canEdit()) {
    register_error(elgg_echo("file:deletefailed"));
    forward($file->getURL());
}
$container = $file->getContainerEntity();
if (!$file->delete()) {
    register_error(elgg_echo("file:deletefailed"));
} else {
    system_message(elgg_echo("file:deleted"));
}
if (elgg_instanceof($container, 'group')) {
    forward("file/group/{$container->guid}/all");
} else {
    forward("file/owner/{$container->username}");
}
Beispiel #2
0
<?php

/**
 * Edit a file
 *
 * @package ElggFile
 */
elgg_load_library('elgg:file');
gatekeeper();
$file_guid = (int) get_input('guid');
$file = new FilePluginFile($file_guid);
if (!$file) {
    forward();
}
if (!$file->canEdit()) {
    forward();
}
$title = elgg_echo('file:edit');
$container = elgg_get_page_owner_entity();
if ($container instanceof ElggGroup) {
    elgg_push_breadcrumb(elgg_echo("gvgroups:" . $container->grouptype . "groups"), "groups/" . $container->grouptype);
    elgg_push_breadcrumb($container->name, "file/group/" . $container->guid . "/all");
} else {
    elgg_push_breadcrumb(elgg_echo("menu:home"), "dashboard");
    elgg_push_breadcrumb($container->name, "file/owner/" . $container->guid . "/all");
}
elgg_push_breadcrumb($file->title, $file->getURL());
elgg_push_breadcrumb($title);
$form_vars = array('enctype' => 'multipart/form-data');
$body_vars = file_prepare_form_vars($file);
$content = elgg_view_form('file/upload', $form_vars, $body_vars);
Beispiel #3
0
if ($new_file) {
    // must have a file if a new file upload
    if (empty($_FILES['upload']['name'])) {
        $error = elgg_echo('file:nofile');
        register_error($error);
        forward(REFERER);
    }
    $file = new FilePluginFile();
    $file->subtype = "file";
    // if no title on new upload, grab filename
    if (empty($title)) {
        $title = htmlspecialchars($_FILES['upload']['name'], ENT_QUOTES, 'UTF-8');
    }
} else {
    // load original file object
    $file = new FilePluginFile($guid);
    if (!$file) {
        register_error(elgg_echo('file:cannotload'));
        forward(REFERER);
    }
    // user must be able to edit file
    if (!$file->canEdit()) {
        register_error(elgg_echo('file:noaccess'));
        forward(REFERER);
    }
    if (!$title) {
        // user blanked title, but we need one
        $title = $file->title;
    }
}
$file->title = $title;
 * @link http://elgg.com/
 */
global $CONFIG;
gatekeeper();
// Get variables
$title = get_input("title");
$desc = get_input("description");
$tags = get_input("tags");
$access_id = (int) get_input("access_id");
$container_guid = (int) get_input('container_guid', 0);
if (!$container_guid) {
    $container_guid == $_SESSION['user']->getGUID();
}
// Extract file from, save to default filestore (for now)
$prefix = "file/";
$file = new FilePluginFile();
$filestorename = strtolower(time() . $_FILES['upload']['name']);
$file->setFilename($prefix . $filestorename);
$file->setMimeType($_FILES['upload']['type']);
$file->originalfilename = $_FILES['upload']['name'];
$file->subtype = "file";
$file->access_id = $access_id;
$file->open("write");
$file->write(get_uploaded_file('upload'));
$file->close();
$file->title = $title;
$file->description = $desc;
if ($container_guid) {
    $file->container_guid = $container_guid;
}
// Save tags
Beispiel #5
0
        $guid = $file->save();
        // Open the file to guarantee the directory exists
        $file->open("write");
        $file->close();
        move_uploaded_file($_FILES["upload"]["tmp_name"], $file->getFilenameOnFilestore());
        if ($guid && $file->simpletype == "image") {
            file_tools_generate_thumbs($file);
            $file->icontime = time();
            $file->save();
        }
        add_to_river('river/object/file/create', 'create', elgg_get_logged_in_user_guid(), $file->guid);
    }
    system_message(elgg_echo("file:saved"));
} else {
    // load original file object
    $file = new FilePluginFile($guid);
    if (!$file) {
        register_error(elgg_echo('file:cannotload'));
        forward(REFERER);
    }
    // user must be able to edit file
    if (!$file->canEdit()) {
        register_error(elgg_echo('file:noaccess'));
        forward(REFERER);
    }
    if ($_FILES["upload"]["name"] && $_FILES["upload"]["error"] === 0) {
        unlink($file->getFilenameOnFilestore());
        move_uploaded_file($_FILES["upload"]["tmp_name"], $file->getFilenameOnFilestore());
        file_tools_generate_thumbs($file);
    }
    $file->title = $title;
Beispiel #6
0
<?php

/**
* Elgg file delete
* 
* @package ElggFile
*/
$guid = (int) get_input('guid');
$file = new FilePluginFile($guid);
if (!$file->guid) {
    register_error(elgg_echo("file:deletefailed"));
}
if (!$file->canEdit()) {
    register_error(elgg_echo("file:deletefailed"));
}
$container = $file->getContainerEntity();
$folders = $file->getEntitiesFromRelationship('folder_of', true);
if (count($folders) > 0) {
    $folder_guid = $folders[0]['guid'];
}
if (!$file->delete()) {
    register_error(elgg_echo("file:deletefailed"));
} else {
    system_message(elgg_echo("file:deleted"));
}
if (elgg_instanceof($container, 'group')) {
    if ($folder_guid) {
        forward("file/group/{$container->guid}/all#" . $folder_guid);
    } else {
        forward("file/group/{$container->guid}/all");
    }
Beispiel #7
0
<?php

/**
 * Edit a file
 *
 * @package ElggFile
 */
elgg_load_library('elgg:file');
gatekeeper();
$file_guid = (int) get_input('guid');
$file = new FilePluginFile($file_guid);
if (!$file) {
    forward();
}
if (!$file->canEdit()) {
    forward();
}
$title = elgg_echo('file:edit');
elgg_push_breadcrumb(elgg_echo('file'), "file/all");
elgg_push_breadcrumb($file->title, $file->getURL());
elgg_push_breadcrumb($title);
elgg_set_page_owner_guid($file->getContainerGUID());
$form_vars = array('enctype' => 'multipart/form-data');
$body_vars = file_prepare_form_vars($file);
$content = elgg_view_form('file/upload', $form_vars, $body_vars);
$body = elgg_view_layout('content', array('content' => $content, 'title' => $title, 'filter' => '', 'buttons' => ''));
echo elgg_view_page($title, $body);
function form_handle_file_upload($fieldname, $access_id, $container_guid = 0)
{
    // Extract file from, save to default filestore (for now)
    $prefix = "file/";
    $file = new FilePluginFile();
    $filestorename = strtolower(time() . $_FILES[$fieldname]['name']);
    $file->setFilename($prefix . $filestorename);
    $file->setMimeType($_FILES[$fieldname]['type']);
    $file->originalfilename = $_FILES[$fieldname]['name'];
    $file->subtype = "file";
    $file->access_id = $access_id;
    $file->open("write");
    $file->write(get_uploaded_file($fieldname));
    $file->close();
    if ($container_guid) {
        $file->container_guid = $container_guid;
    }
    $file->simpletype = get_general_file_type($_FILES[$fieldname]['type']);
    $result = $file->save();
    if ($result) {
        form_generate_thumbnail($file, $fieldname);
    }
    return $file->getGUID();
}
function file_handle_upload($prefix, $subtype, $plugin)
{
    $desc = get_input("description");
    $tags = get_input("tags");
    $tags = explode(",", $tags);
    $folder = get_input("folder_text");
    if (!$folder) {
        $folder = get_input("folder_select");
    }
    $access_id = (int) get_input("access_id");
    $container_guid = (int) get_input('container_guid', 0);
    if (!$container_guid) {
        $container_guid == get_loggedin_userid();
    }
    // Extract file from, save to default filestore (for now)
    // see if a plugin has set a quota for this user
    $file_quota = trigger_plugin_hook("{$plugin}:quotacheck", 'user', array('container_guid' => $container_guid));
    if (!$file_quota) {
        // no, see if there is a generic quota set
        $file_quota = get_plugin_setting('quota', $plugin);
    }
    if ($file_quota) {
        // convert to megabytes
        $file_quota = $file_quota * 1000 * 1024;
    }
    // handle uploaded files
    $number_of_files = get_input('number_of_files', 0);
    $quota_exceeded = false;
    $bad_mime_type = false;
    for ($i = 0; $i < $number_of_files; $i++) {
        $title = get_input("title_" . $i);
        $uploaded = $_FILES["upload_" . $i];
        if (!$uploaded || !$uploaded['name']) {
            // no such file, so skip it
            continue;
        }
        if ($plugin == "photo") {
            // do a mime type test
            if (in_array($uploaded['type'], array('image/jpeg', 'image/gif', 'image/png', 'image/jpg', 'image/jpe', 'image/pjpeg', 'image/x-png'))) {
                $file = new PhotoPluginFile();
            } else {
                $bad_mime_type = true;
                break;
            }
        } else {
            $file = new FilePluginFile();
        }
        $dir_size = $file->getFilestoreSize($prefix, $container_guid);
        $filestorename = strtolower(time() . $uploaded['name']);
        $file->setFilename($prefix . $filestorename);
        $file->setMimeType($uploaded['type']);
        $file->originalfilename = $uploaded['name'];
        $file->subtype = $subtype;
        $file->access_id = $access_id;
        $uf = get_uploaded_file('upload_' . $i);
        if ($file_quota) {
            $file_size = strlen($uf);
            if ($dir_size + $file_size > $file_quota) {
                $quota_exceeded = true;
            }
        }
        if (!$quota_exceeded) {
            // all clear, so try to save the data
            $file->open("write");
            $file->write($uf);
            $file->close();
            $file->title = $title;
            $file->description = $desc;
            if ($container_guid) {
                $file->container_guid = $container_guid;
            }
            // Save tags
            $file->tags = $tags;
            $file->simpletype = file_get_general_file_type($uploaded['type']);
            $file->folder = $folder;
            $result = $file->save();
            if ($result) {
                // Generate thumbnail (if image)
                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($uploaded['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;
                    }
                }
                // add to this user's file folders
                file_add_to_folders($folder, $container_guid, $plugin);
                add_to_river("river/object/{$plugin}/create", 'create', $_SESSION['user']->guid, $file->guid);
            } else {
                break;
            }
        } else {
            break;
        }
    }
    if ($quota_exceeded) {
        echo elgg_echo("{$plugin}:quotaexceeded");
    } else {
        if ($bad_mime_type) {
            echo elgg_echo("{$plugin}:badmimetype");
        } else {
            if ($result) {
                if ($number_of_files > 1) {
                    echo elgg_echo("{$plugin}:saved_multi");
                } else {
                    echo elgg_echo("{$plugin}:saved");
                }
            } else {
                if ($number_of_files > 1) {
                    echo elgg_echo("{$plugin}:uploadfailed_multi");
                } else {
                    echo elgg_echo("{$plugin}:uploadfailed");
                }
            }
        }
    }
}
Beispiel #10
0
 public function createFile($path = array(), $filename = "", $filestream = false, $access_id = 0)
 {
     if (!isset($filename)) {
         if (count($path) < 1) {
             throw new Exception('Path length must be at least one.');
         }
         if (count($path) == 1) {
             $parent = $this->container;
         } else {
             $parent_guid = array_slice($path, -2)[0];
             $parent = get_entity($parent_guid);
         }
         $filename = array_slice($path, -1)[0];
     } else {
         if (count($path) == 0) {
             $parent = $this->container;
         } else {
             $parent_guid = array_slice($path, -1)[0];
             $parent = get_entity($parent_guid);
         }
     }
     if (!$parent | !$parent->canWriteToContainer()) {
         return false;
     }
     if (!$access_id) {
         if ($parent instanceof ElggObject) {
             // lower level folder
             $access_id = $parent->access_id;
         } elseif ($parent instanceof ElggGroup) {
             // top level folder
             $access_id = $parent->group_acl;
         } else {
             throw new Exception('Invalid container.');
         }
     }
     $file = new FilePluginFile();
     $file->subtype = "file";
     $file->title = $filename;
     $file->access_id = $access_id;
     $file->container_guid = $this->container->guid;
     $filestorename = elgg_strtolower(time() . $filename);
     $file->setFilename("file/" . $filestorename);
     $file->originalfilename = $filename;
     if ($filestream) {
         file_put_contents($file->getFilenameOnFilestore(), $filestream);
     } else {
         $input = fopen("php://input", "r");
         file_put_contents($file->getFilenameOnFilestore(), $input);
     }
     $mime_type = ElggFile::detectMimeType($file->getFilenameOnFilestore(), mime_content_type($filename));
     $file->setMimeType($mime_type);
     $file->simpletype = file_get_simple_type($mime_type);
     $file->save();
     if ($file->simpletype == "image") {
         $file->icontime = time();
         $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);
         }
     }
     if ($parent != $this->container && $parent instanceof ElggObject) {
         add_entity_relationship($parent->guid, FILE_TOOLS_RELATIONSHIP, $file->guid);
     }
 }
Beispiel #11
0
 public function createFile($parent, $params = array())
 {
     if ($parent instanceof ElggUser | $parent instanceof ElggGroup) {
         $container = $parent;
     } else {
         $container = $parent->getContainerEntity();
     }
     if (isset($params['access_id'])) {
         $access_id = $params['access_id'];
     } else {
         if ($parent instanceof ElggObject) {
             // lower level folder
             $access_id = $parent->access_id;
         } elseif ($parent instanceof ElggGroup) {
             // top level folder
             $access_id = $parent->group_acl;
         }
     }
     $file = new FilePluginFile();
     $file->title = $this->generateTitle($params['filename'], $parent);
     $file->access_id = $access_id;
     $file->write_access_id = $params['write_access_id'];
     if (!$file->write_access_id) {
         $file->write_access_id = ACCESS_PRIVATE;
     }
     $file->container_guid = $container->guid;
     $filestorename = elgg_strtolower(time() . $params['filename']);
     $file->setFilename("file/" . $filestorename);
     $file->originalfilename = $params['filename'];
     // Open the file to guarantee the directory exists
     $file->open("write");
     $file->close();
     file_put_contents($file->getFilenameOnFilestore(), $params['stream']);
     $mime_type = ElggFile::detectMimeType($file->getFilenameOnFilestore(), $params['type']);
     $file->setMimeType($mime_type);
     $file->simpletype = file_get_simple_type($mime_type);
     $file->save();
     if ($parent instanceof ElggObject) {
         add_entity_relationship($parent->guid, "folder_of", $file->guid);
     }
     pleiofile_generate_file_thumbs($file);
     return $file;
 }