Example #1
0
 protected function write_thumbs($id)
 {
     $original = $this->{$this->path_column} . $this->{$this->file_column};
     if (!$this->create_thumbs || !File::is_image($original)) {
         return false;
     }
     $thumb_dir = PUBLIC_DIR . $this->thumb_base . $id . "/";
     if (!is_dir($thumb_dir)) {
         mkdir($thumb_dir, 0777);
     }
     foreach ($this->create_thumbs as $thumb => $size) {
         if (!is_dir($thumb_dir . $thumb)) {
             mkdir($thumb_dir . $thumb, 0777);
         }
         $destination = $thumb_dir . $thumb . "/" . $this->{$this->file_column};
         if (File::is_image($original)) {
             File::resize_image($original, $destination, $size);
         }
     }
     return true;
 }
 public function file_upload()
 {
     if ($url = $_POST["upload_from_url"]) {
         $str = "";
         foreach ($_POST as $k => $v) {
             $str .= "{$k}:{$v}\n";
         }
         WaxLog::log('error', 'running...' . $str);
         $path = $_POST['wildfire_file_folder'];
         $fs = new CmsFilesystem();
         $filename = basename($url);
         $ext = strtolower(array_pop(explode(".", $filename)));
         if ($_POST["wildfire_file_filename"]) {
             $filename = $_POST["wildfire_file_filename"] . "." . $ext;
         }
         $filename = $_POST["wildfire_file_filename"] = File::safe_file_save($fs->defaultFileStore . $path, $filename);
         $file = $fs->defaultFileStore . $path . "/" . $filename;
         $handle = fopen($file, 'x+');
         fwrite($handle, file_get_contents($url));
         fclose($handle);
         $fname = $fs->defaultFileStore . $path . "/" . $filename;
         chmod($fname, 0777);
         $dimensions = getimagesize($fname);
         if (AdminFilesController::$max_image_width && $dimensions[0] > AdminFilesController::$max_image_width) {
             $flag = File::resize_image($fname, $fname, AdminFilesController::$max_image_width, false, true);
             if (!$flag) {
                 WaxLog::log('error', '[resize] FAIL');
             }
         }
         $fs->databaseSync($fs->defaultFileStore . $path, $path);
         $file = new WildfireFile();
         $newfile = $file->filter(array("filename" => $filename, "rpath" => $path))->first();
         $newfile->description = $_POST["wildfire_file_description"];
         $newfile->save();
         //if these are set then attach the image to the doc!
         if (Request::post('content_id') && Request::post('model_string') && Request::post('join_field')) {
             $model_id = Request::post('content_id');
             $class = Inflections::camelize(Request::post('model_string'), true);
             $field = Request::post('join_field');
             $model = new $class($model_id);
             $model->{$field} = $newfile;
         }
         echo "Uploaded";
     } elseif ($_FILES) {
         error_log("Starting File upload");
         error_log(print_r($_POST, 1));
         $path = $_POST['wildfire_file_folder'];
         $fs = new CmsFilesystem();
         $_FILES['upload'] = $_FILES["Filedata"];
         $_FILES['upload']['name'] = str_replace(' ', '', $_FILES['upload']['name']);
         $fs->upload($path);
         $fs->databaseSync($fs->defaultFileStore . $path, $path);
         $fname = $fs->defaultFileStore . $path . "/" . $_FILES['upload']['name'];
         if ($dimensions = getimagesize($fname)) {
             if ($dimensions[2] == "7" || $dimensions[2] == "8") {
                 WaxLog::log("error", "Detected TIFF Upload");
                 $command = "mogrify " . escapeshellcmd($fname) . " -colorspace RGB -format jpg";
                 system($command);
                 $newname = str_replace(".tiff", ".jpg", $fname);
                 $newname = str_replace(".tif", ".jpg", $newname);
                 rename($fname, $newname);
             }
         }
         chmod($fname, 0777);
         $file = new WildfireFile();
         $newfile = $file->filter(array("filename" => $_FILES['upload']['name'], "rpath" => $path))->first();
         $newfile->description = $_POST["wildfire_file_description"];
         $newfile->save();
         //if these are set then attach the image to the doc!
         if (Request::post('content_id') && Request::post('model_string') && Request::post('join_field')) {
             $model_id = Request::post('content_id');
             $class = Inflections::camelize(Request::post('model_string'));
             $field = Request::post('join_field');
             $model = new $class($model_id);
             $model->{$field} = $newfile;
         }
         echo "Uploaded";
     } else {
         die("UPLOAD ERROR");
     }
     exit;
 }
Example #3
0
 function databaseAdd($folderpath, $filename, $realitivePath)
 {
     if (function_exists('mime_content_type')) {
         $type = mime_content_type("{$folderpath}/{$filename}");
     } else {
         $type = exec("file --mime -b " . escapeshellarg("{$folderpath}/{$filename}"));
     }
     //image resizing
     if (strpos($type, "image") === true) {
         $dimensions = getimagesize("{$folderpath}/{$filename}");
         if (AdminFilesController::$max_image_width && $dimensions[0] > AdminFilesController::$max_image_width) {
             $flag = File::resize_image("{$folderpath}/{$filename}", "{$folderpath}/{$filename}", AdminFilesController::$max_image_width, false, true);
         }
     }
     $size = $this->get_size($folderpath . '/' . $filename);
     $fileid = $this->fileid($folderpath, $filename);
     while (!$this->checkId($fileid)) {
         $fileid++;
     }
     $query = "INSERT INTO wildfire_file (id,filename,path,rpath,type,size,status,flags) VALUES ({$fileid},'{$filename}','{$folderpath}','{$realitivePath}','{$type}','{$size}','found', 'normal')";
     WaxLog::log("info", "[DB] " . $query);
     try {
         $res = $this->query($query);
     } catch (Exception $e) {
         die("NOOOOOOOOOOOOOOOOO!!!!!!!!!!!!!!!  " . $query);
     }
     chmod($folderpath . '/' . $filename, 0755);
     touch($folderpath . '/' . $filename, $fileid);
 }
Example #4
0
 /**
  * show function - this is now moved from the contoller level so can differ for each model
  * NOTE: this function exits
  * @param string $size 
  */
 public function show($size = 110, $compress = false)
 {
     $source = PUBLIC_DIR . $this->rpath . "/" . $this->filename;
     $extension = File::get_extension($this->filename);
     $file = CACHE_DIR . $this->id . "_" . $size . "." . $extension;
     //slash any spaces
     $source = preg_replace("/[\\s]/", "\\ ", $source);
     if (!is_readable($source)) {
         error_log("FATAL IMAGE ERROR");
     }
     if (!File::is_image($source)) {
         if (!is_file($file) || !is_readable($file)) {
             $icon_type = $extension;
             $icon = PLUGIN_DIR . "cms/resources/public/images/cms/" . "cms-generic-icon-" . strtolower($icon_type) . ".gif";
             if (!is_readable($icon) || $icon_file != file_get_contents($icon)) {
                 $icon_file = PLUGIN_DIR . "cms/resources/public/images/cms/" . "cms-generic-icon.png";
                 $source = CACHE_DIR . "cms-generic-icon.gif";
             } else {
                 $source = CACHE_DIR . "cms-generic-icon-{$icon_type}.gif";
             }
             file_put_contents($source, $icon_file);
         }
     }
     if (!is_file($file) || !is_readable($file)) {
         File::resize_image($source, $file, $size, $compression);
     }
     if ($this->image = File::display_image($file)) {
         return true;
     }
     return false;
 }