예제 #1
0
 /**
  * Special conversion function - takes the details in the old cms switches it over the the new cms
  **/
 public function port_content()
 {
     $content = new CmsContent();
     $articles = $content->find_all(array("order" => "id ASC"));
     $new = new WildfireFile();
     foreach ($articles as $article) {
         $oldimgs = $new->sql("SELECT * FROM cms_content_cms_file WHERE cms_content_id = {$article->id}")->all();
         foreach ($oldimgs as $img) {
             $newimg = $new->clear()->filter("oldid=" . $img->cms_file_id)->first();
             $newfile = new WildfireFile($newimg->id);
             if ($newfile->id) {
                 $article->images = $newfile;
             }
         }
     }
 }
예제 #2
0
 function fileDelete($fileid)
 {
     $fileid = mysql_escape_string($fileid);
     $model = new WildfireFile($fileid);
     $fileinfo = $this->getFileInfo($fileid);
     unlink($fileinfo['path'] . '/' . $fileinfo['filename']) || $this->error('file error');
     if ($model->id) {
         $mod = $model->delete();
     }
     echo "File successfully deleted";
     exit;
 }
예제 #3
0
 public function flash_files()
 {
     $model = new WildfireFile();
     return $model->filter("`filename` LIKE '%.swf'")->all();
 }
예제 #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;
 }
예제 #5
0
 /**
  * the editing function... lets you change all the bits associated with the content record
  * gets the record for the id passed (/admin/content/edit/ID)
  * finds associated images & categories
  * render the partials
  */
 public function edit()
 {
     $this->id = WaxUrl::get("id");
     if (!$this->id) {
         $this->id = $this->route_array[0];
     }
     if (($lang_id = Request::get("lang")) && !$this->languages[$lang_id]) {
         Session::add_message("That language isn't allowed on your system. Here's the {$this->languages[0]} version instead.");
         $this->redirect_to("/admin/" . $this->module_name . "/edit/{$this->id}");
     }
     $master = new $this->model_class($this->id);
     if ($master->status == 4) {
         $this->redirect_to("/admin/" . $this->module_name . "/edit/{$master->preview_master_id}");
     }
     //this isn't a master, jump to the right url
     if ($master->language) {
         $this->redirect_to("/admin/" . $this->module_name . "/edit/{$master->preview_master_id}?lang=" . $master->language);
     }
     if ($lang_id) {
         $master = $this->get_language_model($master, $lang_id);
     }
     $preview = new $this->model_class();
     //preview revision - create a copy of the content if needed or use the existing copy
     if ($master->status == 1 || $master->status == 6) {
         if (!($preview = $preview->filter(array("preview_master_id" => $master->primval, "status" => 4))->first())) {
             //if a preview entry doesn't exist create one
             foreach ($master->columns as $col => $params) {
                 if ($master->{$col}) {
                     $copy_attributes[$col] = $master->{$col};
                 }
             }
             $copy_attributes = array_diff_key($copy_attributes, array($this->model->primary_key => false));
             //take out ID
             $preview = new $this->model_class();
             $preview->status = 4;
             $preview->save();
             $preview->set_attributes($copy_attributes);
             $preview->status = 4;
             $preview->url = $master->url;
             $preview->master = $master->primval;
             $preview->save();
         }
         $this->model = $preview;
     } else {
         $this->model = $master;
     }
     if ($this->model->is_posted()) {
         if ($_POST['publish']) {
             if ($master->status != 1 && $master->status != 6) {
                 $master->set_attributes($_POST[$master->table]);
                 if ($master->status == 5) {
                     $master->status = 6;
                 } else {
                     $master->status = 1;
                 }
                 $master->save();
             } else {
                 $this->update_master($preview, $master);
                 if ($preview->primval) {
                     $preview->delete();
                 }
             }
             Session::add_message($this->display_name . " " . "Successfully Published");
             $this->redirect_to("/admin/{$this->module_name}/");
         } elseif ($_POST['close']) {
             //delete the preview if it has no changes from the master
             if ($preview->equals($master) && $preview->primval) {
                 $preview->delete();
             }
             $this->redirect_to(Session::get("list_refer"));
         } else {
             //save button is default post, as it's the least destructive thing to do
             if ($preview->primval && ($_POST[$this->model->table]['status'] == 0 || $_POST[$this->model->table]['status'] == 5)) {
                 $this->update_master($preview, $master);
                 if ($preview->primval) {
                     $preview->delete();
                 }
                 $this->save($master, "/admin/{$this->module_name}/edit/" . $master->id . "/");
             } else {
                 $this->save($this->model, "/admin/{$this->module_name}/edit/" . $master->id . "/");
             }
         }
     }
     //images
     if (!($this->attached_images = $this->model->images)) {
         $this->attached_images = array();
     }
     //categories assocaited
     if (!($this->attached_categories = $this->model->categories)) {
         $this->attached_categories = array();
     }
     $cat = new CmsCategory();
     //all categories
     if (!($this->all_categories = $cat->order("name ASC")->all())) {
         $this->all_categories = array();
     }
     $this->image_model = new WildfireFile();
     //partials
     $this->image_partial = $this->render_partial("page_images");
     $this->cat_partial = $this->render_partial("list_categories");
     $this->cat_list = $this->render_partial("cat_list");
     $this->category_partial = $this->render_partial("apply_categories");
     $files = new WildfireFile();
     $this->all_links = $files->find_all_files();
     $this->link_partial = $this->render_partial("apply_links");
     $this->extra_content_partial = $this->render_partial("extra_content");
     $this->flash_files = $files->flash_files();
     $this->video_partial = $this->render_partial("apply_video");
     $this->table_partial = $this->render_partial("wysi_tables");
     $this->form = $this->render_partial("form");
 }