예제 #1
0
 public function postUpdate($object)
 {
     // get controller
     $container = $this->getConfigurationPool()->getContainer();
     $helper = $container->get('vich_uploader.templating.helper.uploader_helper');
     // additional restauratn photo
     // set for photos restaurant
     foreach ($object->getAdditionalPhotos() as $additionalPhoto) {
         if (!is_null($additionalPhoto->getFile())) {
             $imagePath = $helper->asset($additionalPhoto, 'restaurant_additional_photo');
             // check if file exist
             if (file_exists($imagePath)) {
                 // get thumb image name
                 $thumbImage = $additionalPhoto->getThumbFileName();
                 if (!is_null($thumbImage)) {
                     $thumbPath = str_replace($additionalPhoto->getFileName(), $thumbImage, $imagePath);
                     // create thumbnail
                     $thumb = new \abeautifulsite\SimpleImage(getcwd() . $imagePath);
                     $thumb->best_fit(RestaurantAdditionalPhoto::THUMB_HEIGHT, RestaurantAdditionalPhoto::THUMB_WIDTH)->save(getcwd() . $thumbPath);
                 }
             }
         }
     }
     // menu photos
     foreach ($object->getAdditionalMenuPhotos() as $menuPhoto) {
         if (!is_null($menuPhoto->getFile())) {
             $imagePath = $helper->asset($menuPhoto, 'restaurant_menu_photo');
             // check if file exist
             if (file_exists($imagePath)) {
                 // get thumb image name
                 $thumbImage = $menuPhoto->getThumbFileName();
                 if (!is_null($thumbImage)) {
                     $thumbPath = str_replace($menuPhoto->getFileName(), $thumbImage, $imagePath);
                     // create thumbnail
                     $thumb = new \abeautifulsite\SimpleImage(getcwd() . $imagePath);
                     $thumb->best_fit(RestaurantMenuPhoto::THUMB_HEIGHT, RestaurantMenuPhoto::THUMB_WIDTH)->save(getcwd() . $thumbPath);
                 }
             }
         }
     }
 }
예제 #2
0
 public function createVersion($imagePath, $sizeString = false)
 {
     if (strlen($this->urlAlias) < 1) {
         throw new \Exception('Image without urlAlias!');
     }
     $cachePath = $this->getModule()->getCachePath();
     $subDirPath = $this->getSubDur();
     $fileExtension = pathinfo($this->filePath, PATHINFO_EXTENSION);
     if ($sizeString) {
         $sizePart = '_' . $sizeString;
     } else {
         $sizePart = '';
     }
     $pathToSave = $cachePath . '/' . $subDirPath . '/' . $this->urlAlias . $sizePart . '.' . $fileExtension;
     BaseFileHelper::createDirectory(dirname($pathToSave), 0777, true);
     if ($sizeString) {
         $size = $this->getModule()->parseSize($sizeString);
     } else {
         $size = false;
     }
     if ($this->getModule()->graphicsLibrary == 'Imagick') {
         $image = new \Imagick($imagePath);
         $image->setImageCompressionQuality(100);
         if ($size) {
             if ($size['height'] && $size['width']) {
                 $image->cropThumbnailImage($size['width'], $size['height']);
             } elseif ($size['height']) {
                 $image->thumbnailImage(0, $size['height']);
             } elseif ($size['width']) {
                 $image->thumbnailImage($size['width'], 0);
             } else {
                 throw new \Exception('Something wrong with this->module->parseSize($sizeString)');
             }
         }
         $image->writeImage($pathToSave);
     } else {
         $image = new \abeautifulsite\SimpleImage($imagePath);
         if ($size) {
             if ($size['height'] && $size['width']) {
                 //$image->thumbnail($size['width'], $size['height']);
                 $image->best_fit($size['width'], $size['height']);
             } elseif ($size['height']) {
                 $image->fit_to_height($size['height']);
             } elseif ($size['width']) {
                 $image->fit_to_width($size['width']);
             } else {
                 throw new \Exception('Something wrong with this->module->parseSize($sizeString)');
             }
         }
         //WaterMark
         if ($this->getModule()->waterMark) {
             if (!file_exists(Yii::getAlias($this->getModule()->waterMark))) {
                 throw new Exception('WaterMark not detected!');
             }
             $wmMaxWidth = intval($image->get_width() * 0.4);
             $wmMaxHeight = intval($image->get_height() * 0.4);
             $waterMarkPath = Yii::getAlias($this->getModule()->waterMark);
             $waterMark = new \abeautifulsite\SimpleImage($waterMarkPath);
             if ($waterMark->get_height() > $wmMaxHeight or $waterMark->get_width() > $wmMaxWidth) {
                 $waterMarkPath = $this->getModule()->getCachePath() . DIRECTORY_SEPARATOR . pathinfo($this->getModule()->waterMark)['filename'] . $wmMaxWidth . 'x' . $wmMaxHeight . '.' . pathinfo($this->getModule()->waterMark)['extension'];
                 //throw new Exception($waterMarkPath);
                 if (!file_exists($waterMarkPath)) {
                     $waterMark->fit_to_width($wmMaxWidth);
                     $waterMark->save($waterMarkPath, 100);
                     if (!file_exists($waterMarkPath)) {
                         throw new Exception('Cant save watermark to ' . $waterMarkPath . '!!!');
                     }
                 }
             }
             $image->overlay($waterMarkPath, 'bottom right', 0.5, -10, -10);
         }
         $image->save($pathToSave, 100);
     }
     return $image;
 }
예제 #3
0
     $acceptedMime = array("image/jpeg", "image/gif", "image/png");
     if (!in_array($mime, $acceptedMime)) {
         $error = "Type de fichier refuser ";
     }
     if ($_FILES == $_SESSION['user']['pic_name']) {
     }
     if (empty($error)) {
         $extention = pathinfo($_FILES['pic_name']['name'], PATHINFO_EXTENSION);
         $pic_name = md5($tmpName . time() . uniqid()) . "." . $extention;
         $destinationDirectory = __DIR__ . "/../img/uploads/";
         if (file_exists($destinationDirectory . "originals/" . $pic_name)) {
             $pic_name = md5($tmpName . time() . uniqid()) . uniqid() . "." . $extention;
         }
         move_uploaded_file($tmpName, $destinationDirectory . "originals/" . $pic_name);
         $img = new abeautifulsite\SimpleImage($destinationDirectory . "originals/" . $pic_name);
         $img->best_fit(600, 600)->save($destinationDirectory . "mediums/" . $pic_name);
         $img->thumbnail(150, 150)->save($destinationDirectory . "thumbnails/" . $pic_name);
     }
     if (empty($error)) {
         $sql = "UPDATE users \n\t\t\t\t\tSET pic_name = :pic_name\n\t\t\t\t\tWHERE id = :id";
         $sth = $dbh->prepare($sql);
         $sth->bindValue(":id", $_SESSION['user']['id']);
         $sth->bindValue(':pic_name', $pic_name);
         $sth->execute();
         $succes = "Modification enregistrer";
     }
 }
 // insert dans la BDD
 if (empty($error)) {
     $sql = "UPDATE users \n\t\t\t\t\tSET user_name = :user_name, email = :email, bio = :bio\n\t\t\t\t\tWHERE id = :id";
     $sth = $dbh->prepare($sql);
예제 #4
0
/**
 * Save image in various formats
 * 
 * @param
 * @return
 */
function saveImage($image)
{
    //1.Original Image
    // Separate the uploaded file array
    list($name, $type, $tmp, $err, $size) = array_values($image);
    //get extension
    $ext = getImageExtensions($type);
    //rename
    $filename = renameFile($ext);
    $coverimagePath = $_SERVER['DOCUMENT_ROOT'] . APP_FOLDER . "/img/original/" . $filename;
    //save original
    if (!move_uploaded_file($tmp, $coverimagePath)) {
        throw new Exception("Couldn't save the uploaded image!");
    }
    //2.save small, medium and large image
    $destination = '../img/small/' . $filename;
    resizeAndSaveImage($coverimagePath, $destination, 143, 143);
    $destination = '../img/medium/' . $filename;
    resizeAndSaveImage($coverimagePath, $destination, 750, 450);
    $destination = '../img/large/' . $filename;
    $img = new abeautifulsite\SimpleImage($coverimagePath);
    $img->best_fit(2000, 2000)->save($destination);
    //3.remove original
    unlink($coverimagePath);
    //4.return filename
    return $filename;
}
예제 #5
0
     $error = "Type de fichier refusé !";
 }
 if (empty($error)) {
     //Nouveau nom du fichier sécuritaire
     $newName = md5($tmpName . time() . uniqid()) . "." . $ext;
     //chemin vers le répertoire où nous déplacerons l'image(4 underscores pour __DIR__)
     $destinationDirectory = __DIR__ . "/images/profils/";
     //Si par hazard le fichier existe
     if (file_exists($destinationDirectory . $newName)) {
         $newName = md5($tmpName . time() . uniqid()) . uniqid() . "." . $ext;
     }
     //déplace le fichier temporaire vers un autre répretoire sur notre serveur
     move_uploaded_file($tmpName, $destinationDirectory . $newName);
     $img = new abeautifulsite\SimpleImage($destinationDirectory . $newName);
     //medium
     $img->best_fit(250, 200)->save($destinationDirectory . "mediums/" . $newName);
     //thumbnails
     $img->thumbnail(150, 150)->save($destinationDirectory . "thumbnails/" . $newName);
     //watermark
     //$img->overlay(__DIR__ . "/images/profils/", 'bottom right', .5, -10, -10)->save($destinationDirectory."originals/".$newName);
     if (!empty($_POST)) {
         $sql = "UPDATE users\n\t\t\tSET photo = :newName, profile_user = :profile_user\n\t\t\tWHERE email = :email";
         $sth = $dbh->prepare($sql);
         $sth->bindValue(":email", $email);
         $sth->bindValue(":newName", $newName);
         $sth->bindValue(":profile_user", $profile_user);
         $sth->execute();
     }
 } else {
     //rediriger vers erreur
     echo "{$error}";
예제 #6
0
 public function profil()
 {
     $user = $this->getUser();
     $userManager = new UserManager();
     $error = "";
     $succes = "";
     $id = "";
     $username = "";
     $email = "";
     $firstname = "";
     $lastname = "";
     $streetname = "";
     $phonenumber = "";
     $zipcode = "";
     $pic_name = $this->getUser()['pic_name'];
     $user_name_regex = "/^[\\p{L}0-9._-]{2,100}\$/u";
     if (!empty($_POST)) {
         $id = $user["id"];
         $email = trim(strip_tags($_POST['email']));
         $username = trim(strip_tags($_POST['username']));
         $firstname = trim(strip_tags($_POST['firstname']));
         $lastname = trim(strip_tags($_POST['lastname']));
         $streetname = trim(strip_tags($_POST['streetname']));
         $zipcode = trim(strip_tags($_POST['zipcode']));
         $phonenumber = trim(strip_tags($_POST['phonenumber']));
         //|||||||||||||||||||| username valide ?
         if (strlen($username) < 4) {
             $error = "Votre Pseudo doit comporter 4 lettres minimum !";
         }
         if (!preg_match($user_name_regex, $username)) {
             $error = "Votre Pseudo ne doit pas contenir de caractère spéciaux !";
         } else {
             if ($username !== $_SESSION['user']['username']) {
                 $foundPseudo = $userManager->usernameExists($username);
                 if (!empty($foundPseudo)) {
                     $error = "Ce pseudo est déjà enregistré ici !";
                 }
             }
         }
         //|||||||||||||||| Email valide ?
         if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
             $error = "Email non valide";
         } else {
             if ($email !== $_SESSION['user']['email']) {
                 $foundEmail = $userManager->emailExists($email);
                 if (!empty($foundEmail)) {
                     $error = "Ce pseudo est déjà enregistré ici !";
                 }
             }
         }
         // |||||||||||||||| IMAGE valide ?
         if ($_FILES['pic_name']['error'] != 4) {
             $tmpName = $_FILES['pic_name']['tmp_name'];
             if ($_FILES['pic_name']['error'] != 0) {
                 switch ($_FILES['pic_name']['error']) {
                     case 1:
                         $error = "Votre fichier est trop gros !";
                         break;
                     case 4:
                         $error = "Aucun fichier n'a été selectionné !";
                         break;
                     default:
                         $error = "Une erreur est survenue lors du chargement de votre image LOL";
                         break;
                 }
             }
             $info = finfo_open(FILEINFO_MIME_TYPE);
             $mime = finfo_file($info, $tmpName);
             $acceptedMime = array("image/jpeg", "image/gif", "image/png");
             if (!in_array($mime, $acceptedMime)) {
                 $error = "Type de fichier refuser ";
             }
             if ($_FILES == $_SESSION['user']['pic_name']) {
             }
             if (empty($error)) {
                 $extention = pathinfo($_FILES['pic_name']['name'], PATHINFO_EXTENSION);
                 $pic_name = md5($tmpName . time() . uniqid()) . "." . $extention;
                 $destinationDirectory = __DIR__ . "/../../public/assets/img/uploads/";
                 if (file_exists($destinationDirectory . "originals/" . $pic_name)) {
                     $pic_name = md5($tmpName . time() . uniqid()) . uniqid() . "." . $extention;
                 }
                 move_uploaded_file($tmpName, $destinationDirectory . "originals/" . $pic_name);
                 $img = new \abeautifulsite\SimpleImage($destinationDirectory . "originals/" . $pic_name);
                 $img->best_fit(600, 600)->save($destinationDirectory . "mediums/" . $pic_name);
                 $img->thumbnail(150, 150)->save($destinationDirectory . "thumbnails/" . $pic_name);
             }
             if (empty($error)) {
                 $succes = "Bravo !";
             }
         }
         //|||||||||||||||| ZIPCODE valide ?
         if ($zipcode <= "75000" || $zipcode >= "75021") {
             $error = "Vous devez habiter Paris pour vous inscrire à notre service !";
         }
         //|||||||||||||||| Téléphone valide ?
         if (preg_match("/^[0-9]{2}-[0-9]{2}-[0-9]{2}-[0-9]{2}\$/", $phonenumber)) {
             // $phonenumber is valid
             $error = "Votre numéro de téléphone n'est pas valide !";
         }
         //||||||||||||||||	2er cihffre du Telephone coresponde a 01,02,03,04,05,06,07,08 ou 09
         if (substr($phonenumber, 0, 2) < "01" || substr($phonenumber, 0, 2) > "09") {
             $error = "Votre numéro de téléphone n'est pas valide !";
         }
         //si valide...
         if (empty($error)) {
             //insérer en base
             $modifySubscriber = ["username" => $username, "email" => $email, "firstname" => $firstname, "lastname" => $lastname, "zip_code" => $zipcode, "street_name" => $streetname, "phone_number" => $phonenumber, "date_modified" => date("Y-m-d H:i:s"), "pic_name" => $pic_name];
             $userManager = new \Manager\UserManager();
             $userManager->update($modifySubscriber, $id);
             //Crée une instance et refresh le contenu
             $am = new AuthentificationManager();
             $am->refreshUser();
             $succes = "Votre profil a bien été enregistré !";
         }
     }
     $data = [];
     $data['error'] = $error;
     $data['succes'] = $succes;
     $data['username'] = $username;
     $data['email'] = $email;
     $data['firstname'] = $firstname;
     $data['lastname'] = $lastname;
     $data['zipcode'] = $zipcode;
     $data['streetname'] = $streetname;
     $data['phonenumber'] = $phonenumber;
     $data['pic_name'] = 'default.png';
     $this->show('user/profile', $data);
 }
예제 #7
0
 function actionItems()
 {
     $path = $this->getPath();
     $dir = opendir($path);
     $this->result->baseurl = $this->config->baseurl;
     $this->result->path = str_replace(realpath($this->root) . DIRECTORY_SEPARATOR, '', $this->getPath());
     while ($file = readdir($dir)) {
         if ($file != '.' && $file != '..' && is_file($path . $file)) {
             $info = pathinfo($path . $file);
             if (!isset($info['extension']) or (!isset($this->config->extensions) or in_array(strtolower($info['extension']), $this->config->extensions))) {
                 $item = array('file' => $file);
                 if ($this->config->createThumb) {
                     if (!is_dir($path . $this->config->thumbFolderName)) {
                         mkdir($path . $this->config->thumbFolderName, 0777);
                     }
                     if (!file_exists($path . $this->config->thumbFolderName . DIRECTORY_SEPARATOR . $file)) {
                         $img = new abeautifulsite\SimpleImage($path . $file);
                         $img->best_fit(150, 150)->save($path . $this->config->thumbFolderName . DIRECTORY_SEPARATOR . $file, $this->config->quality);
                     }
                     $item['thumb'] = $this->config->thumbFolderName . DIRECTORY_SEPARATOR . $file;
                 }
                 $item['changed'] = date($this->config->datetimeFormat, filemtime($path . $file));
                 $item['size'] = $this->humanFilesize(filesize($path . $file));
                 $this->result->files[] = $item;
             }
         }
     }
 }
예제 #8
0
    $ter->lon = $_POST['lon'];
    $ter->opis = $_POST['opis'];
    $ter->insert();
    header("Location: admin.php?id=2&cat=dodaj_teretanu.php");
}
//dodavanje vezbe
if (isset($_POST['dodaj_vezbu'])) {
    $vezba = new Vezbe();
    $naziv = $_POST['naziv'];
    $search = array("?", ":", "ć", "Ć");
    $replace = array("", "-", "c", "C");
    $naziv = str_replace($search, $replace, $naziv);
    $output = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $naziv);
    $file_tmp = $_FILES['img']['tmp_name'];
    $img = new abeautifulsite\SimpleImage($file_tmp);
    $img->best_fit(500, 400)->mean_remove()->save("../images/vezbe/" . $output . ".jpg");
    $vezba->naziv = $naziv;
    $vezba->tekst = $_POST['tekst'];
    $vezba->kategorija = $_POST['kategorije'];
    $vezba->insert();
    header("Location: admin.php?id=2&cat=dodaj_vezbu.php");
}
//dodavanje korisnika
if (isset($_GET['dodajkorisnika'])) {
    $kor = new Users();
    $kor->id = $_GET['dodajkorisnika'];
    $kor->status = "1";
    $kor->update();
    header("Location: admin.php?id=2");
}
//brisanje korisnika