Exemplo n.º 1
0
 public function __construct($source = null, $filename = null, $standard = false)
 {
     if ($source) {
         parent::__construct($source);
         if ($this->getStorlek() > self::MAX_SIZE) {
             throw new AvatarException("Filen är för stor", -1);
         }
         if ($this->getBredd() != self::WIDTH || $this->getHojd() != self::HEIGHT) {
         }
         $this->resize(self::WIDTH, self::HEIGHT);
         $this->approve(AVATAR_PATH . "/temp");
         $namn = "";
         if ($standard) {
             $namn = self::STANDARD;
         } else {
             do {
                 $namn = $this->generateNamn();
             } while (file_exists($namn));
         }
         $this->setNamn(self::PREFIX . $namn);
     } else {
         if ($filename) {
             parent::__construct(null, AVATAR_PATH . "/" . $filename);
         } else {
             throw new AvatarException("Båda argumenten får inte vara null", -2);
         }
     }
 }
Exemplo n.º 2
0
 public function __construct($source = null, $filename = null)
 {
     global $USER;
     if ($source) {
         parent::__construct($source);
         // Only allow gif, jpg or png files:
         $file_ext = strtolower($this->getExt());
         if ($file_ext != "gif" && $file_ext != "jpg" && $file_ext != "png") {
             throw new CustomVisningsbildException("Fel filformat", -4);
         }
         if ($this->getStorlek() > self::MAX_SIZE) {
             throw new CustomVisningsbildException("Filen är för stor", -1);
         }
         if ($this->getBredd() != self::WIDTH || $this->getHojd() != self::HEIGHT) {
         }
         $this->resize(self::WIDTH, self::HEIGHT);
         $this->approve(CUSTOM_VISNINGSBILD_PATH . "/temp");
         $namn = "";
         do {
             $namn = self::UNAPPROVED_PREFIX . self::PREFIX . $USER->getId();
         } while (file_exists($namn));
         $this->setNamn($namn . "." . $this->getExt());
     } else {
         if ($filename) {
             parent::__construct(null, CUSTOM_VISNINGSBILD_PATH . "/" . $filename);
         } else {
             throw new CustomVisningsbildException("Båda argumenten får inte vara null", -2);
         }
     }
 }
Exemplo n.º 3
0
 public function __construct($source = null, $filename = null, $fid = null)
 {
     if ($source) {
         global $FORETAG;
         if (!isset($FORETAG)) {
             if ($fid == null) {
                 throw new CustomForetagsbildException("Företag ej satt", -9);
             } else {
                 $this->foretag = Foretag::loadById((int) $fid);
             }
         } else {
             $this->foretag = Foretag::loadById($FORETAG->getId());
         }
         //uses the same allowed formats as CustomLagBild
         $allowed_formats = CustomLagbild::getAllowedFormats();
         if (!in_array(substr($source["name"], -3, 3), $allowed_formats)) {
             throw new CustomForetagsbildException("Fel filtyp", -7);
         }
         parent::__construct($source);
         if ($this->getStorlek() > self::MAX_SIZE) {
             throw new CustomForetagsbildException("Filen är för stor", -1);
         } elseif ($this->getBredd() != self::WIDTH || $this->getHojd() != self::HEIGHT) {
             throw new CustomForetagsbildException("Filen är ej 50x50 pixlar", -5);
         }
         //remove other files
         self::cleanImages($this->foretag->getId());
         /*$this->resize(self::WIDTH, self::HEIGHT);*/
         $this->approve(FORETAGS_BILD_PATH . "/temp");
         $namn = "";
         do {
             $namn = self::UNAPPROVED_PREFIX . self::PREFIX . $this->foretag->getId();
         } while (file_exists($namn));
         $this->setNamn($namn . "." . $this->getExt());
         $this->approveForetagsbild();
         /*$this->foretag->setBildUrl($this->namn);
         		$this->foretag->commit();*/
     } else {
         if ($filename) {
             parent::__construct(null, FORETAGS_BILD_PATH . "/" . $filename);
         } else {
             throw new CustomForetagsbildException("Samtliga argumenten får inte vara null", -2);
         }
     }
 }
Exemplo n.º 4
0
 public function __construct($source = null, Kommun $kommun)
 {
     $this->setKommun($kommun);
     if ($source) {
         Security::demand(EDITOR);
         parent::__construct($source);
         if ($this->getStorlek() > self::MAX_SIZE) {
             throw new KommunkartaException("Filen är för stor", -1);
         }
         $this->approve(KOMMUN_IMAGES_PATH . "/temp");
         $this->setNamn($this->kommunToNamn());
     } else {
         try {
             parent::__construct(null, $this->kommunToPath());
         } catch (FilException $e) {
             if ($e->getCode() == -1) {
                 throw new KommunkartaException("Kommunen har ingen karta", -2);
             }
         }
     }
 }
Exemplo n.º 5
0
 public function __construct($source = null, $filename = null, $lagid = null)
 {
     $allowed_formats = self::getAllowedFormats();
     if ($source) {
         if (!isset($lagid)) {
             throw new CustomLagbildException("Inget lagid angivet", -4);
         }
         if (!in_array(substr($source["name"], -3, 3), $allowed_formats)) {
             throw new CustomLagbildException("Fel filtyp", -7);
         }
         parent::__construct($source);
         if ($this->getStorlek() > self::MAX_SIZE) {
             throw new CustomLagbildException("Filen är för stor", -1);
         } elseif ($this->getBredd() != self::WIDTH || $this->getHojd() != self::HEIGHT) {
             throw new CustomLagbildException("Filen är ej 50x50 pixlar", -5);
         }
         $this->lag = Lag::loadById($lagid);
         /*$this->resize(self::WIDTH, self::HEIGHT);*/
         $this->approve(LAG_BILD_PATH . "/temp");
         $namn = "";
         do {
             $namn = self::UNAPPROVED_PREFIX . self::PREFIX . $lagid;
         } while (file_exists($namn));
         $this->setNamn($namn . "." . $this->getExt());
         $this->approveLagbild();
         //throw new CustomLagbildException("!".$this->namn."!", -2);
         $this->lag->setBildUrl($this->namn);
         $this->lag->commit();
     } else {
         if ($filename) {
             parent::__construct(null, LAG_BILD_PATH . "/" . $filename);
         } else {
             throw new CustomLagbildException("Samtliga argumenten får inte vara null", -2);
         }
     }
 }
Exemplo n.º 6
0
 public function __construct($source = null, $filename = null)
 {
     if ($source) {
         parent::__construct($source);
         if ($this->getStorlek() > self::MAX_SIZE) {
             throw new VisningsbildException("Filen är för stor", -1);
         }
         if ($this->getBredd() != self::WIDTH || $this->getHojd() != self::HEIGHT) {
         }
         $this->resize(self::WIDTH, self::HEIGHT);
         $this->approve(VISNINGSBILD_PATH . "/temp");
         $namn = "";
         do {
             $namn = self::generateNamn();
         } while (file_exists($namn));
         $this->setNamn(self::PREFIX . $namn . "." . $this->getExt());
     } else {
         if ($filename) {
             parent::__construct(null, VISNINGSBILD_PATH . "/" . $filename);
         } else {
             throw new VisningsbildException("Båda argumenten får inte vara null", -2);
         }
     }
 }
Exemplo n.º 7
0
 public function __construct($source = null, $filename = null, $fotoalbum_id, $dummy_object = NULL)
 {
     global $USER, $SETTINGS;
     if ($source) {
         parent::__construct($source);
         // Kolla om det är en riktig bild
         $data = @getimagesize($source["tmp_name"]);
         if ($data == false) {
             throw new FotoalbumException("Okänt filformat", -1);
         } else {
             // Skapa bild-id till denna bild
             global $db;
             // Släng in i databasen
             $db->nonquery("\tINSERT INTO\n\t\t\t\t\t\t\t\t\tmm_fotoalbumbild\n\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\tfotoalbum_id, medlem_id,\n\t\t\t\t\t\t\t\t\t\ttillagd\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t'" . $fotoalbum_id . "', '" . $USER->getId() . "',\n\t\t\t\t\t\t\t\t\t\t'" . date("Y-m-d H:i:s") . "'\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t");
             $bild_id = $db->getInsertedId();
             // Resize'a till mini-bild (och spara alltid som jpg)
             $this->resizeNyFil(FOTOALBUM_PATH . "/" . $bild_id . "_mini.jpg", $SETTINGS["fotoalbum_bredd_mini"], $SETTINGS["fotoalbum_hojd_mini"]);
             // Resize'a till thumbnail (och spara alltid som jpg)
             $this->resizeNyFil(FOTOALBUM_PATH . "/" . $bild_id . "_liten.jpg", $SETTINGS["fotoalbum_bredd_liten"], $SETTINGS["fotoalbum_hojd_liten"]);
             // Resize'a till stor bild (och spara alltid som jpg)
             $this->resizeNyFil(FOTOALBUM_PATH . "/" . $bild_id . "_stor.jpg", $SETTINGS["fotoalbum_bredd_stor"], $SETTINGS["fotoalbum_hojd_stor"]);
             // Spara orignalet, ifall vi vill Šndra storlekarna fšr liten och stor i framtiden
             move_uploaded_file($source["tmp_name"], FOTOALBUM_PATH . "/original/" . $bild_id);
             // Hämta storlek på lilla och stora bilden..
             $mini = new Bild(null, FOTOALBUM_PATH . "/" . $bild_id . "_mini.jpg");
             $liten = new Bild(null, FOTOALBUM_PATH . "/" . $bild_id . "_liten.jpg");
             $stor = new Bild(null, FOTOALBUM_PATH . "/" . $bild_id . "_stor.jpg");
             // .. och uppdatera databasen/bilden
             $db->nonquery("\tUPDATE\n\t\t\t\t\t\t\t\t\tmm_fotoalbumbild\n\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\tbredd_stor = '" . $stor->getBredd() . "',\n\t\t\t\t\t\t\t\t\thojd_stor = '" . $stor->getHojd() . "',\n\t\t\t\t\t\t\t\t\tbredd_liten = '" . $liten->getBredd() . "',\n\t\t\t\t\t\t\t\t\thojd_liten = '" . $liten->getHojd() . "',\n\t\t\t\t\t\t\t\t\tbredd_mini = '" . $mini->getBredd() . "',\n\t\t\t\t\t\t\t\t\thojd_mini = '" . $mini->getHojd() . "'\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\tid = '" . $bild_id . "'\n\t\t\t\t");
             $this->setId($bild_id);
         }
     } elseif ($filename) {
         parent::__construct(null, FOTOALBUM_PATH . "/" . $filename);
     }
 }