Exemplo n.º 1
0
 protected function before()
 {
     parent::before();
     $userId = Session::get('userId');
     if ($userId) {
         $this->user = new Model_User();
         $this->user->get($userId);
     }
 }
Exemplo n.º 2
0
 public function action_searchPhotos($text)
 {
     $photos = new Model_Photo();
     $allPhotos = [];
     $this->view = new View("photos/searchPhotos");
     foreach ($photos->getAll() as $photo) {
         $p = new Model_Photo();
         $p->get($photo['_id']);
         if ($p->loaded && isset($p->bigPath) && isset($p->smallPath) && file_exists("assets/uploads/" . $p->bigPath) && file_exists("assets/uploads/" . $p->smallPath) && stripos(strtolower($p->title), strtolower($text)) !== false) {
             if (isset($p->autorUser)) {
                 $autor = new Model_User();
                 $autor->get($p->autorUser);
                 $p->autor = $autor->username;
                 if ($p->tryb == "private" && (!$this->user || $autor->username != $this->user->username)) {
                     continue;
                 }
             }
             $allPhotos[] = $p;
         }
     }
     $this->view->passData('photos', $allPhotos);
 }
Exemplo n.º 3
0
 public function action_rememberedPhotos()
 {
     $this->content = new View("photos/remembered");
     $photos = new Model_Photo();
     $allPhotos = [];
     foreach ($photos->getAll() as $photo) {
         $p = new Model_Photo();
         $p->get($photo['_id']);
         if ($p->loaded && isset($p->bigPath) && isset($p->smallPath) && file_exists("assets/uploads/" . $p->bigPath) && file_exists("assets/uploads/" . $p->smallPath)) {
             if (isset($p->autorUser)) {
                 $autor = new Model_User();
                 $autor->get($p->autorUser);
                 $p->autor = $autor->username;
                 if ($p->tryb == "private" && (!$this->user || $autor->username != $this->user->username)) {
                     continue;
                 }
             }
             if (Session::get("remember_photo_" . $p->_id->{'$id'}, false)) {
                 $allPhotos[] = $p;
             }
         }
     }
     $this->content->passData('photos', $allPhotos);
 }
Exemplo n.º 4
0
 public static function validate($data, $files, $userLogged = null)
 {
     $table = self::$table;
     if (isset($data['title']) && !empty($data['title'])) {
         if (strlen($data['title']) < 3) {
             throw new Validation_Exception('Tytuł', 2, 3);
         } else {
             if (strlen($data['title']) > 20) {
                 throw new Validation_Exception('Tytuł', 3, 20);
             }
         }
         if (!preg_match('#[0-9a-zA-Z\\s-]+#', $data['title'])) {
             throw new Validation_Exception('Tytuł', 6);
         }
     } else {
         throw new Validation_Exception('Tytuł', 1);
     }
     if (isset($data['autorUser'])) {
         $user = new Model_User();
         $user->get($data['autorUser']);
         if (!$user->loaded) {
             throw new Validation_Exception("Autor", 9);
         } else {
             if ($user->_id->{'$id'} !== $userLogged->_id->{'$id'}) {
                 throw new Validation_Exception("Autor", 9);
             }
         }
     } else {
         if (isset($data['autor']) && !empty($data['autor'])) {
             if (strlen($data['autor']) < 3) {
                 throw new Validation_Exception('Autor', 2, 3);
             } else {
                 if (strlen($data['autor']) > 20) {
                     throw new Validation_Exception('Autor', 3, 20);
                 }
             }
             if (!preg_match('#[0-9a-zA-Z\\s-]+#', $data['autor'])) {
                 throw new Validation_Exception('Autor', 6);
             }
         } else {
             throw new Validation_Exception('Autor', 1);
         }
     }
     if (empty($files["file"]["tmp_name"])) {
         throw new Validation_Exception('Zdjęcie', 10);
     }
     $targetFile = basename($files["file"]["name"]);
     $fileType = pathinfo($targetFile, PATHINFO_EXTENSION);
     $check = getimagesize($files["file"]["tmp_name"]);
     if ($check !== false) {
         $mime = $check["mime"];
         if ($files["file"]["size"] > 1000000) {
             throw new Validation_Exception('Zdjęcie', 11, '1MB');
         }
         if (!preg_match('/jpg|jpeg|png/', $fileType)) {
             throw new Validation_Exception('Zdjęcie', 12, "JPG, PNG");
         }
     } else {
         throw new Validation_Exception('Zdjęcie', 10);
     }
     return true;
 }