Exemple #1
0
 public function add_photo($id)
 {
     $album = ORM::factory("item", $id);
     access::required("view", $album);
     access::required("add", $album);
     access::verify_csrf();
     $file_validation = new Validation($_FILES);
     $file_validation->add_rules("Filedata", "upload::valid", "upload::type[gif,jpg,png,flv,mp4]");
     if ($file_validation->validate()) {
         // SimpleUploader.swf does not yet call /start directly, so simulate it here for now.
         if (!batch::in_progress()) {
             batch::start();
         }
         $temp_filename = upload::save("Filedata");
         try {
             $name = substr(basename($temp_filename), 10);
             // Skip unique identifier Kohana adds
             $title = item::convert_filename_to_title($name);
             $path_info = pathinfo($temp_filename);
             if (array_key_exists("extension", $path_info) && in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) {
                 $movie = movie::create($album, $temp_filename, $name, $title);
                 log::success("content", t("Added a movie"), html::anchor("movies/{$movie->id}", t("view movie")));
             } else {
                 $photo = photo::create($album, $temp_filename, $name, $title);
                 log::success("content", t("Added a photo"), html::anchor("photos/{$photo->id}", t("view photo")));
             }
         } catch (Exception $e) {
             unlink($temp_filename);
             throw $e;
         }
         unlink($temp_filename);
     }
     print "File Received";
 }
 static function item_deleted($item)
 {
     tag::clear_all($item);
     if (!batch::in_progress()) {
         tag::compact();
     }
 }
Exemple #3
0
 public function add_photo($id)
 {
     $album = ORM::factory("item", $id);
     access::required("view", $album);
     access::required("add", $album);
     access::verify_csrf();
     // The Flash uploader not call /start directly, so simulate it here for now.
     if (!batch::in_progress()) {
         batch::start();
     }
     $form = $this->_get_add_form($album);
     if ($form->validate()) {
         // Uploadify puts the result in $_FILES["Filedata"] - process it.
         try {
             list($tmp_name, $name) = $this->_process_upload("Filedata");
         } catch (Exception $e) {
             header("HTTP/1.1 400 Bad Request");
             print "ERROR: " . $e->getMessage();
             return;
         }
         // We have a valid upload file (of unknown type) - build an item from it.
         try {
             $item = $this->_add_item($id, $tmp_name, $name);
             module::event("add_photos_form_completed", $item, $form);
             print "FILEID: {$item->id}";
         } catch (Exception $e) {
             header("HTTP/1.1 500 Internal Server Error");
             print "ERROR: " . $e->getMessage();
         }
     } else {
         header("HTTP/1.1 400 Bad Request");
         print "ERROR: " . t("Invalid upload");
     }
 }
 public function add_photo($id)
 {
     $album = ORM::factory("item", $id);
     access::required("view", $album);
     access::required("add", $album);
     access::verify_csrf();
     // The Flash uploader not call /start directly, so simulate it here for now.
     if (!batch::in_progress()) {
         batch::start();
     }
     $form = $this->_get_add_form($album);
     // Uploadify adds its own field to the form, so validate that separately.
     $file_validation = new Validation($_FILES);
     $file_validation->add_rules("Filedata", "upload::valid", "upload::required", "upload::type[" . implode(",", legal_file::get_extensions()) . "]");
     if ($form->validate() && $file_validation->validate()) {
         $temp_filename = upload::save("Filedata");
         Event::add("system.shutdown", create_function("", "unlink(\"{$temp_filename}\");"));
         try {
             $item = ORM::factory("item");
             $item->name = substr(basename($temp_filename), 10);
             // Skip unique identifier Kohana adds
             $item->title = item::convert_filename_to_title($item->name);
             $item->parent_id = $album->id;
             $item->set_data_file($temp_filename);
             // Remove double extensions from the filename - they'll be disallowed in the model but if
             // we don't do it here then it'll result in a failed upload.
             $item->name = legal_file::smash_extensions($item->name);
             $path_info = @pathinfo($temp_filename);
             if (array_key_exists("extension", $path_info) && in_array(strtolower($path_info["extension"]), legal_file::get_movie_extensions())) {
                 $item->type = "movie";
                 $item->save();
                 log::success("content", t("Added a movie"), html::anchor("movies/{$item->id}", t("view movie")));
             } else {
                 $item->type = "photo";
                 $item->save();
                 log::success("content", t("Added a photo"), html::anchor("photos/{$item->id}", t("view photo")));
             }
             module::event("add_photos_form_completed", $item, $form);
         } catch (Exception $e) {
             // The Flash uploader has no good way of reporting complex errors, so just keep it simple.
             Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());
             // Ugh.  I hate to use instanceof, But this beats catching the exception separately since
             // we mostly want to treat it the same way as all other exceptions
             if ($e instanceof ORM_Validation_Exception) {
                 Kohana_Log::add("error", "Validation errors: " . print_r($e->validation->errors(), 1));
             }
             header("HTTP/1.1 500 Internal Server Error");
             print "ERROR: " . $e->getMessage();
             return;
         }
         print "FILEID: {$item->id}";
     } else {
         header("HTTP/1.1 400 Bad Request");
         print "ERROR: " . t("Invalid upload");
     }
 }
Exemple #5
0
 public function add_photo($id)
 {
     $album = ORM::factory("item", $id);
     access::required("view", $album);
     access::required("add", $album);
     access::verify_csrf();
     $file_validation = new Validation($_FILES);
     $file_validation->add_rules("Filedata", "upload::valid", "upload::required", "upload::type[gif,jpg,jpeg,png,flv,mp4]");
     if ($file_validation->validate()) {
         // SimpleUploader.swf does not yet call /start directly, so simulate it here for now.
         if (!batch::in_progress()) {
             batch::start();
         }
         $temp_filename = upload::save("Filedata");
         try {
             $name = substr(basename($temp_filename), 10);
             // Skip unique identifier Kohana adds
             $title = item::convert_filename_to_title($name);
             $path_info = @pathinfo($temp_filename);
             if (array_key_exists("extension", $path_info) && in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) {
                 $item = movie::create($album, $temp_filename, $name, $title);
                 log::success("content", t("Added a movie"), html::anchor("movies/{$item->id}", t("view movie")));
             } else {
                 $item = photo::create($album, $temp_filename, $name, $title);
                 log::success("content", t("Added a photo"), html::anchor("photos/{$item->id}", t("view photo")));
             }
             // We currently have no way of showing errors if validation fails, so only call our event
             // handlers if validation passes.
             $form = $this->_get_add_form($album);
             if ($form->validate()) {
                 module::event("add_photos_form_completed", $item, $form);
             }
         } catch (Exception $e) {
             Kohana_Log::add("alert", $e->__toString());
             if (file_exists($temp_filename)) {
                 unlink($temp_filename);
             }
             header("HTTP/1.1 500 Internal Server Error");
             print "ERROR: " . $e->getMessage();
             return;
         }
         unlink($temp_filename);
         print "FILEID: {$item->id}";
     } else {
         header("HTTP/1.1 400 Bad Request");
         print "ERROR: " . t("Invalid Upload");
     }
 }
Exemple #6
0
 private static function _notify_subscribers($item, $text, $subject)
 {
     $users = self::get_subscribers($item);
     if (!empty($users)) {
         if (!batch::in_progress()) {
             Sendmail::factory()->to($users)->subject($subject)->header("Mime-Version", "1.0")->header("Content-type", "text/html; charset=utf-8")->message($text)->send();
         } else {
             foreach ($users as $user) {
                 $pending = ORM::factory("pending_notification");
                 $pending->subject = $subject;
                 $pending->text = $text;
                 $pending->email = $user;
                 $pending->save();
             }
         }
     }
 }
Exemple #7
0
 private static function _notify($email, $locale, $item, $text, $subject)
 {
     if (!batch::in_progress()) {
         Sendmail::factory()->to($email)->subject($subject)->header("Mime-Version", "1.0")->header("Content-Type", "text/html; charset=UTF-8")->message($text)->send();
     } else {
         $pending = ORM::factory("pending_notification");
         $pending->subject = $subject;
         $pending->text = $text;
         $pending->email = $email;
         $pending->locale = $locale;
         $pending->save();
     }
 }
Exemple #8
0
 static function item_deleted($item)
 {
     access::delete_item($item);
     // Find any other albums that had the deleted item as the album cover and null it out.
     // In some cases this may leave us with a missing album cover up in this item's parent
     // hierarchy, but in most cases it'll work out fine.
     foreach (ORM::factory("item")->where("album_cover_item_id", "=", $item->id)->find_all() as $parent) {
         item::remove_album_cover($parent);
     }
     $parent = $item->parent();
     if (!$parent->album_cover_item_id) {
         // Assume that we deleted the album cover
         if (batch::in_progress()) {
             // Remember that this parent is missing an album cover, for later.
             $batch_missing_album_cover = Session::instance()->get("batch_missing_album_cover", array());
             $batch_missing_album_cover[$parent->id] = 1;
             Session::instance()->set("batch_missing_album_cover", $batch_missing_album_cover);
         } else {
             // Choose the first viewable child as the new cover.
             if ($child = $parent->viewable()->children(1)->current()) {
                 item::make_album_cover($child);
             }
         }
     }
 }