function lightboxgallery_add_images($stored_file, $context, $cm, $gallery, $resize = 0)
{
    require_once dirname(__FILE__) . '/imageclass.php';
    $fs = get_file_storage();
    $images = array();
    if ($stored_file->get_mimetype() == 'application/zip') {
        // Unpack.
        $packer = get_file_packer('application/zip');
        $fs->delete_area_files($context->id, 'mod_lightboxgallery', 'unpacktemp', 0);
        $stored_file->extract_to_storage($packer, $context->id, 'mod_lightboxgallery', 'unpacktemp', 0, '/');
        $images = $fs->get_area_files($context->id, 'mod_lightboxgallery', 'unpacktemp', 0);
        $stored_file->delete();
    } else {
        $images[] = $stored_file;
    }
    foreach ($images as $stored_file) {
        if ($stored_file->is_valid_image()) {
            $filename = $stored_file->get_filename();
            $fileinfo = array('contextid' => $context->id, 'component' => 'mod_lightboxgallery', 'filearea' => 'gallery_images', 'itemid' => 0, 'filepath' => '/', 'filename' => $filename);
            if (!$fs->get_file($context->id, 'mod_lightboxgallery', 'gallery_images', 0, '/', $filename)) {
                $stored_file = $fs->create_file_from_storedfile($fileinfo, $stored_file);
                $image = new lightboxgallery_image($stored_file, $gallery, $cm);
                if ($resize > 0) {
                    $resizeoptions = lightboxgallery_resize_options();
                    list($width, $height) = explode('x', $resizeoptions[$resize]);
                    $image->resize_image($width, $height);
                }
                $image->set_caption($filename);
            }
        }
    }
    $fs->delete_area_files($context->id, 'mod_lightboxgallery', 'unpacktemp', 0);
}
예제 #2
0
 public function process_form()
 {
     $button = required_param('button', PARAM_TEXT);
     $fs = get_file_storage();
     $stored_file = $fs->get_file($this->context->id, 'mod_lightboxgallery', 'gallery_images', '0', '/', $this->image);
     $image = new lightboxgallery_image($stored_file, $this->gallery, $this->cm);
     switch ($button) {
         case $this->strresize:
             $size = required_param('size', PARAM_INT);
             list($width, $height) = explode('x', $this->resizeoptions[$size]);
             break;
         case $this->strscale:
             $scale = required_param('scale', PARAM_INT);
             $width = $image->width * ($scale / 100);
             $height = $image->height * ($scale / 100);
             break;
     }
     $this->image = $image->resize_image($width, $height);
 }