public function postStore()
 {
     $id = \Input::get('id');
     /*
      * Validate
      */
     $rules = array('image' => 'mimes:jpg,jpeg,png,gif|max:500', 'name' => 'required', 'short_description' => 'required', 'category_id' => 'required');
     $validation = \Validator::make(\Input::all(), $rules);
     if ($validation->passes()) {
         $name = \Input::get('name');
         $short_description = \Input::get('short_description');
         $long_description = \Input::get('long_description');
         $image = \Input::file('image');
         $active = \Input::get('active') == '' ? FALSE : TRUE;
         $category_id = \Input::get('category_id');
         $cn_name = \Input::get('cn_name');
         $cn_short_description = \Input::get('cn_short_description');
         $cn_long_description = \Input::get('cn_long_description');
         $options = array('name' => $cn_name, 'short_description' => $cn_short_description, 'long_description' => $cn_long_description);
         $portfolio = isset($id) ? Portfolio::find($id) : new Portfolio();
         if ($portfolio == null) {
             return \Redirect::to('/admin/portfolios/edit/' . $id)->withErrors($validation)->withInput();
         }
         $portfolio->name = $name;
         $portfolio->short_description = $short_description;
         $portfolio->long_description = $long_description;
         $portfolio->active = $active;
         $portfolio->category_id = $category_id;
         $portfolio->options = json_encode($options);
         $portfolio->save();
         if (\Input::hasFile('image')) {
             // Delete all existing images for edit
             //if(isset($id)) $portfolio->deleteAllImages();
             //Upload the file
             $helper_image = new Helper\Image();
             $filename = $helper_image->upload($image, 'portfolios/' . $portfolio->id, true);
             if ($filename) {
                 // create photo
                 $newimage = new Image();
                 $newimage->path = $filename;
                 // save photo to the loaded model
                 $portfolio->images()->save($newimage);
             }
         }
     } else {
         if (isset($id)) {
             return \Redirect::to('admin/portfolios/edit/' . $id)->withErrors($validation)->withInput();
         } else {
             return \Redirect::to('admin/portfolios/create')->withErrors($validation)->withInput();
         }
     }
     if (isset($id)) {
         return \Redirect::to('admin/portfolios/edit/' . $id);
     }
     return \Redirect::to('admin/portfolios');
 }
 public function postStore()
 {
     $id = \Input::get('id');
     $validation = Announcement::validate(\Input::all());
     if ($validation->passes()) {
         $title = \Input::get('title');
         $content = \Input::get('content');
         $image = \Input::file('image');
         $private = \Input::get('private') == '' ? FALSE : TRUE;
         $announcement = isset($id) ? Announcement::find($id) : new Announcement();
         if ($announcement == null) {
             return \Redirect::to('/admin/announcements/edit/' . $id)->withErrors($validation)->withInput();
         }
         $announcement->title = $title;
         $announcement->content = $content;
         $announcement->private = $private;
         $announcement->save();
         if (\Input::hasFile('image')) {
             // Delete all existing images for edit
             //if(isset($id)) $announcement->deleteAllImages();
             //Upload the file
             $helper_image = new Helper\Image();
             $filename = $helper_image->upload($image, 'announcements/' . $announcement->id, true);
             if ($filename) {
                 // create photo
                 $newimage = new Image();
                 $newimage->path = $filename;
                 // save photo to the loaded model
                 $announcement->images()->save($newimage);
             }
         }
     } else {
         if (isset($id)) {
             return \Redirect::to('admin/announcements/edit/' . $id)->withErrors($validation)->withInput();
         } else {
             return \Redirect::to('admin/announcements/create')->withErrors($validation)->withInput();
         }
     }
     return \Redirect::to('admin/announcements');
 }
示例#3
0
 /**
  * @param \Base $f3
  * @param array $params
  * @throws \Exception
  */
 public function thumb($f3, $params)
 {
     $this->_useFileCache();
     $cache = \Cache::instance();
     // Ensure proper content-type for JPEG images
     if ($params["format"] == "jpg") {
         $params["format"] = "jpeg";
     }
     // Output cached image if one exists
     $hash = $f3->hash($f3->get('VERB') . " " . $f3->get('URI')) . ".thm";
     if ($cache->exists($hash, $data)) {
         header("Content-type: image/" . $params["format"]);
         echo $data;
         return;
     }
     $file = new \Model\Issue\File();
     $file->load($params["id"]);
     if (!$file->id) {
         $f3->error(404);
         return;
     }
     $fg = 0x0;
     $bg = 0xffffff;
     // Generate thumbnail of image file
     if (substr($file->content_type, 0, 6) == "image/") {
         if (is_file($file->disk_filename)) {
             $img = new \Helper\Image($file->disk_filename);
             $hide_ext = true;
         } else {
             $protocol = isset($_SERVER["SERVER_PROTOCOL"]) ? $_SERVER["SERVER_PROTOCOL"] : "HTTP/1.0";
             header($protocol . " 404 Not Found");
             $img = new \Helper\Image("img/404.png");
         }
         $img->resize($params["size"], $params["size"]);
         $fg = 0xffffff;
         $bg = 0x0;
     } elseif (substr($file->content_type, 0, 5) == "text/") {
         // Get first 2KB of file
         $fh = fopen($file->disk_filename, "r");
         $str = fread($fh, 2048);
         fclose($fh);
         // Replace tabs with spaces
         $str = str_replace("\t", "  ", $str);
         $img = new \Helper\Image();
         $img->create($params["size"], $params["size"]);
         $img->fill(0xffffff);
         $img->text($str, round(0.05 * $params["size"]), 0, round(0.03 * $params["size"]), round(0.03 * $params["size"]), 0x777777);
         // Show file type icon if available
         if ($file->content_type == "text/csv" || $file->content_type == "text/tsv") {
             $icon = new \Image("img/mime/table.png");
             $img->overlay($icon);
         }
     } elseif (extension_loaded("zip") && $file->content_type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document") {
         $zip = zip_open($file->disk_filename);
         while (($entry = zip_read($zip)) !== false) {
             if (preg_match("/word\\/media\\/image[0-9]+\\.(png|jpe?g|gif|bmp|dib)/i", zip_entry_name($entry))) {
                 $idata = zip_entry_read($entry, zip_entry_filesize($entry));
                 $img = new \Helper\Image();
                 $img->load($idata);
                 break;
             }
         }
         if (!isset($img)) {
             $img = new \Helper\Image("img/mime/base.png");
         }
         $img->resize($params["size"], $params["size"]);
     } else {
         $img = new \Helper\Image("img/mime/base.png");
         $img->resize($params["size"], $params["size"]);
     }
     // Render file extension over image
     if (empty($hide_ext)) {
         $ext = strtoupper(pathinfo($file->disk_filename, PATHINFO_EXTENSION));
         $img->text($ext, $params["size"] * 0.125, 0, round(0.05 * $params["size"]), round(0.05 * $params["size"]), $bg);
         $img->text($ext, $params["size"] * 0.125, 0, round(0.05 * $params["size"]) - 1, round(0.05 * $params["size"]) - 1, $fg);
     }
     // Render and cache image
     $data = $img->dump($params["format"]);
     $cache->set($hash, $data, $f3->get("cache_expire.attachments"));
     // Output image
     header("Content-type: image/" . $params["format"]);
     echo $data;
 }