Ejemplo n.º 1
0
 public function render()
 {
     $v = new View("form_uploadify.html");
     $v->album = $this->data["album"];
     $v->script_data = $this->data["script_data"];
     $v->simultaneous_upload_limit = module::get_var("gallery", "simultaneous_upload_limit");
     $v->movies_allowed = movie::allow_uploads();
     $v->extensions = legal_file::get_filters();
     $v->suhosin_session_encrypt = (bool) ini_get("suhosin.session.encrypt");
     list($toolkit_max_filesize_bytes, $toolkit_max_filesize) = graphics::max_filesize();
     $upload_max_filesize = trim(ini_get("upload_max_filesize"));
     $upload_max_filesize_bytes = num::convert_to_bytes($upload_max_filesize);
     if ($upload_max_filesize_bytes < $toolkit_max_filesize_bytes) {
         $v->size_limit_bytes = $upload_max_filesize_bytes;
         $v->size_limit = $upload_max_filesize;
     } else {
         $v->size_limit_bytes = $toolkit_max_filesize_bytes;
         $v->size_limit = $toolkit_max_filesize;
     }
     return $v;
 }
Ejemplo n.º 2
0
 /**
  * Create a merged list of all allowed photo and movie extensions.
  *
  * @param string $extension (opt.) - return true if allowed; if not given, return complete array
  */
 static function get_extensions($extension = null)
 {
     $extensions = legal_file::get_photo_extensions();
     if (movie::allow_uploads()) {
         $extensions = array_merge($extensions, legal_file::get_movie_extensions());
     }
     if ($extension) {
         // return true if in array, false if not
         return in_array(strtolower($extension), $extensions);
     } else {
         // return complete array
         return $extensions;
     }
 }
Ejemplo n.º 3
0
 /**
  * Add photo or movie from upload.  Once we have a valid file, this generates an item model
  * from it.  It returns the item model on success, and throws an exception and adds log entries
  * on failure.
  * @TODO: consider moving this to a common controller which is extended by various uploaders.
  *
  * @param  int    parent album id
  * @param  string temp file path (analogous to $_FILES[...]["tmp_name"])
  * @param  string filename       (analogous to $_FILES[...]["name"])
  * @return object new item model
  */
 private function _add_item($album_id, $tmp_name, $name)
 {
     $extension = pathinfo($name, PATHINFO_EXTENSION);
     try {
         $item = ORM::factory("item");
         $item->name = $name;
         $item->title = item::convert_filename_to_title($name);
         $item->parent_id = $album_id;
         $item->set_data_file($tmp_name);
         if (!$extension) {
             throw new Exception(t("Uploaded file has no extension"));
         } else {
             if (legal_file::get_photo_extensions($extension)) {
                 $item->type = "photo";
                 $item->save();
                 log::success("content", t("Added a photo"), html::anchor("photos/{$item->id}", t("view photo")));
             } else {
                 if (movie::allow_uploads() && legal_file::get_movie_extensions($extension)) {
                     $item->type = "movie";
                     $item->save();
                     log::success("content", t("Added a movie"), html::anchor("movies/{$item->id}", t("view movie")));
                 } else {
                     throw new Exception(t("Uploaded file has illegal extension"));
                 }
             }
         }
     } catch (Exception $e) {
         // Log errors then re-throw exception.
         Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());
         // If we have a validation error, add an additional log entry.
         if ($e instanceof ORM_Validation_Exception) {
             Kohana_Log::add("error", "Validation errors: " . print_r($e->validation->errors(), 1));
         }
         throw $e;
     }
     return $item;
 }