Exemplo n.º 1
0
 public function flickr_photo($pic_id, $sizes, $no_image_path = "/images/no-pic.gif", $sync = false)
 {
     if (!is_array($sizes)) {
         return "";
     }
     $data = array();
     $files = array();
     foreach ($sizes as $size) {
         $index = $size['label'][0];
         $files[$index] = $size['source'][0];
     }
     if ($sync) {
         if (!is_dir(PUBLIC_DIR . "files/flickr/")) {
             mkdir(PUBLIC_DIR . "files/flickr/");
         }
         $dir = PUBLIC_DIR . "files/flickr/" . $pic_id . "/";
         $web_dir = "/files/flickr/" . $pic_id . "/";
         if (!is_dir($dir)) {
             mkdir($dir);
         }
         foreach ($files as $k => $file_to_get) {
             $save_to = $pic_id . substr($file_to_get, -6);
             if (is_readable($dir . $save_to)) {
                 $data[$k] = $web_dir . $save_to;
             } else {
                 $result = self::get_remote_file($file_to_get);
                 if ($result) {
                     file_put_contents($dir . $save_to, $result);
                     $data[$k] = $web_dir . $save_to;
                 } else {
                     $data[$k] = $no_image_path;
                 }
             }
         }
         system('chmod -Rf 0777 ' . $dir);
         if ($sync) {
             $fs = new CmsFilesystem();
             $rel = $web_dir;
             $fs->databaseSync($dir, $rel);
         }
     } else {
         $data = $files;
     }
     return $data;
 }
Exemplo n.º 2
0
 public function copy()
 {
     if ($id = Request::get('id')) {
         $this->model = new $this->model_class($id);
         $copy_file = File::safe_file_save(PUBLIC_DIR . $this->model->rpath . "/", $this->model->filename);
         $full_copy_file = PUBLIC_DIR . $this->model->rpath . "/" . $copy_file;
         $file = PUBLIC_DIR . $this->model->rpath . "/" . $this->model->filename;
         copy($file, $full_copy_file);
         $fs = new CmsFilesystem();
         $fs->databaseSync(PUBLIC_DIR . $this->model->rpath, $this->model->rpath);
         $copy = new $this->model_class();
         $copy = $copy->filter(array("rpath" => $this->model->rpath, "filename" => $copy_file))->first();
         $this->redirect_to("/admin/files/edit/" . $copy->id);
     }
 }
Exemplo n.º 3
0
 public function find($query)
 {
     if (!self::$model) {
         self::$model = new WildfireFile();
     }
     $results = self::$model->query($query);
     if ($rows = $results->fetchAll(PDO::FETCH_ASSOC)) {
         return $rows;
     } else {
         return array();
     }
 }
Exemplo n.º 4
0
 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;
 }