Пример #1
0
 public function profileCover()
 {
     require 'vendor/ImageUploader.php';
     // Create instance of the Image Uploader
     $imageUploader = new ImageUploader();
     // Attempt to upload the file
     $result = $imageUploader->upload('cover-image', 'img/user/covers/original/');
     // If the upload was a success
     if ($result == true) {
         // Get the file name
         $imageName = $imageUploader->getImageName();
         // Prepare the variables
         $fileLocation = "img/user/covers/original/{$imageName}";
         $destination = "img/user/covers/edited/";
         // Make the avatar version
         $imageUploader->resize($fileLocation, 1000, $destination, $imageName);
         $_POST['cover-image'] = $imageName;
     } else {
         // Something went wrong
         $this->totalErrors++;
         $this->userImageError = $imageUploader->errorMessage;
     }
     if ($this->totalErrors == 0) {
         $result = $this->model->changeCover();
         // If the result was good
         if ($result) {
             // Redirect the user to login
             header('Location: index.php?page=profile');
             $this->userSuccess = 'Successfully changed your info';
         } else {
             $this->userFail = 'Info not updated';
         }
     }
 }
Пример #2
0
 public function processRecipe()
 {
     // If there is a file
     if (isset($_FILES['recipe-image']) && $_FILES['recipe-image']['name'] != '') {
         require 'vendor/ImageUploader.php';
         // Create instance of the Image Uploader
         $imageUploader = new ImageUploader();
         // Attempt to upload the file
         $result = $imageUploader->upload('recipe-image', 'img/recipes/original/');
         // If the upload was a success
         if ($result == true) {
             // Get the file name
             $imageName = $imageUploader->getImageName();
             // Prepare the variables
             $fileLocation = "img/recipes/original/{$imageName}";
             $destination = "img/recipes/cover/";
             // Make the recipe_image version
             $imageUploader->resize($fileLocation, 1000, $destination, $imageName);
             // Make thumbnail
             $destination = "img/recipes/thumbnail/";
             $imageUploader->resize($fileLocation, 230, $destination, $imageName);
             $_POST['recipe-image'] = $imageName;
         } else {
             // Something went wrong
             $this->totalErrors++;
             $this->userImageError = $imageUploader->errorMessage;
         }
     }
     if ($this->totalErrors == 0) {
         $result = $this->model->updateRecipe();
         // If the result was good
         if ($result) {
             // Redirect the user to login
             header('Location: index.php?page=recipe&recipeid=' . $_GET['recipeid']);
             $this->userSuccess = 'Successfully changed your info';
         } else {
             $this->userFail = 'Info not updated';
         }
     }
 }
Пример #3
0
 private function processAdditionalInfo()
 {
     // Validation
     if (strlen($_POST['first-name']) < 2) {
         $this->userFirstNameError = 'Needs to be at least 2 characters.';
         $this->totalErrors++;
     } elseif (strlen($_POST['first-name']) > 20) {
         $this->userFirstNameError = 'Needs to be at most 20 characters.';
         $this->totalErrors++;
     } elseif (!preg_match('/^[a-zA-Z \\-]{2,20}$/', $_POST['first-name'])) {
         $this->userFirstNameError = 'Can only use characters of the alphabet, spaces and hyphens.';
         $this->totalErrors++;
     }
     if (strlen($_POST['last-name']) < 2) {
         $this->userLastNameError = 'Needs to be at least 2 characters.';
         $this->totalErrors++;
     } elseif (strlen($_POST['last-name']) > 20) {
         $this->userLastNameError = 'Needs to be at most 20 characters.';
         $this->totalErrors++;
     } elseif (!preg_match('/^[a-zA-Z \\-]{2,20}$/', $_POST['last-name'])) {
         $this->userLastNameError = 'Can only use characters of the alphabet, spaces and hyphens.';
         $this->totalErrors++;
     }
     if (strlen($_POST['last-name']) > 2000) {
         $this->userBioError = 'Needs to be at most 2000 characters.';
         $this->totalErrors++;
     }
     // Attemp to upload the image
     if ($this->totalErrors == 0 && isset($_FILES['profile-image']) && $_FILES['profile-image']['name'] != '') {
         //require image uploader
         require 'vendor/ImageUploader.php';
         // Create an instance
         $imageUploader = new ImageUploader();
         // Attemp to upload the file
         $result = $imageUploader->upload('profile-image', 'img/profile-images/original/');
         // If the upload was a success
         if ($result) {
             // Get the file name
             $imageName = $imageUploader->getImageName();
             // Prepare the variables
             $fileLocation = "img/profile-images/original/{$imageName}";
             $fileDestination = "img/profile-images/avatar/";
             // Make the avatar version
             $imageUploader->resize($fileLocation, 320, $fileDestination, $imageName);
             // Make icons
             $fileDestination = "img/profile-images/icon/";
             $imageUploader->resize($fileLocation, 32, $fileDestination, $imageName);
             $_POST['newUserImage'] = $imageName;
         } else {
             // Something went wrong
             $this->userImageError = $imageUploader->errorMessage;
             $this->totalErrors++;
         }
     } elseif (isset($_FILES['profile-image']) && $_FILES['profile-image']['name'] == '') {
         $_POST['newUserImage'] = 'default.png';
     }
     if ($this->totalErrors == 0) {
         $result = $this->model->additionalInfo();
         //If the result was good
         if ($result) {
             $this->userSuccess = 'Account has been updated';
         } else {
             $this->userFail = 'You have entered the same information';
         }
     }
 }
Пример #4
0
 public function processRecipe()
 {
     $recipeTitle = trim($_POST['recipe-title']);
     $recipeDirections = trim($_POST['recipe-directions']);
     $recipeTime = trim($_POST['cook-time']);
     $recipeServes = trim($_POST['serves']);
     $recipeVideo = trim($_POST['recipe-video']);
     $this->recipeTitle = $recipeTitle;
     $this->recipeDirections = $recipeDirections;
     $this->recipeTime = $recipeTime;
     $this->recipeVideo = $recipeVideo;
     if (strlen($recipeTitle) > 40) {
         $this->recipeTitleError = 'Recipe name is too long, 45 characters max.';
         $this->totalErrors++;
     } elseif (strlen($recipeTitle) == 0) {
         $this->recipeTitleError = 'Recipe title is required.';
         $this->totalErrors++;
     }
     if (strlen($recipeDirections) > 2000) {
         $this->recipeDirectionsError = 'Recipe directions is too long please shorten, 2000 characters max.';
         $this->totalErrors++;
     } elseif (strlen($recipeDirections) == 0) {
         $this->recipeDirectionsError = 'Recipe directions is required.';
         $this->totalErrors++;
     }
     if (strlen($recipeTime) > 3) {
         $this->recipeTimeError = 'Please enter up to 3 digits.';
         $this->totalErrors++;
     } else {
         if ($recipeTime == '') {
             $this->recipeTimeError = 'Please enter a time.';
             $this->totalErrors++;
         } elseif (!preg_match('/^[0-9]{1,3}$/', $recipeTime)) {
             $this->recipeTimeError = 'Use only numbers. With a maximum of 3 digits.';
             $this->totalErrors++;
         }
     }
     if ($_FILES['cover-image']['name'] == '') {
         $this->userImageError = 'You must upload an image with your recipe.';
         $this->totalErrors++;
     } else {
         // If there is a file
         if (isset($_FILES['cover-image']) && $_FILES['cover-image']['name'] != '') {
             require 'vendor/ImageUploader.php';
             // Create instance of the Image Uploader
             $imageUploader = new ImageUploader();
             // Attempt to upload the file
             $result = $imageUploader->upload('cover-image', 'img/recipes/original/');
             // If the upload was a success
             if ($result == true) {
                 // Get the file name
                 $imageName = $imageUploader->getImageName();
                 // Prepare the variables
                 $fileLocation = "img/recipes/original/{$imageName}";
                 $destination = "img/recipes/cover/";
                 // Make the recipe_image version
                 $imageUploader->resize($fileLocation, 1000, $destination, $imageName);
                 // Make thumbnail
                 $destination = "img/recipes/thumbnail/";
                 $imageUploader->resize($fileLocation, 230, $destination, $imageName);
                 $_POST['cover-image'] = $imageName;
             } else {
                 // Something went wrong
                 $this->totalErrors++;
                 $this->userImageError = $imageUploader->errorMessage;
             }
         }
     }
     if ($this->totalErrors == 0) {
         $this->model->addRecipe();
     }
 }
Пример #5
0
 public function processChangeInfo()
 {
     $firstname = $_POST['first-name'];
     $lastname = $_POST['last-name'];
     $bio = $_POST['bio'];
     if (strlen($firstname) > 40) {
         $this->firstnameError = 'First name is too long please abbreviate or use a nickname. 40 Character max.';
         $this->totalErrors++;
     }
     if (strlen($lastname) > 40) {
         $this->lastnameError = 'Last name is too long please abbreviate or use a nickname. 40 Character max.';
         $this->totalErrors++;
     }
     if (strlen($bio) > 400) {
         $this->bioError = 'Your description is too long please abbreviate. 400 Character max.';
         $this->totalErrors++;
     }
     if (isset($_FILES['profile-image']) && $_FILES['profile-image']['name'] != '') {
         require 'vendor/ImageUploader.php';
         // Create instance of the Image Uploader
         $imageUploader = new ImageUploader();
         // Attempt to upload the file
         $result = $imageUploader->upload('profile-image', 'img/user/avatar/original/');
         // If the upload was a success
         if ($result == true) {
             // Get the file name
             $imageName = $imageUploader->getImageName();
             // Prepare the variables
             $fileLocation = "img/user/avatar/original/{$imageName}";
             $destination = "img/user/avatar/edited/";
             // Make the recipe_image version
             $imageUploader->resize($fileLocation, 110, $destination, $imageName);
             // Make thumbnail
             $destination = "img/user/avatar/icon/";
             $imageUploader->resize($fileLocation, 34, $destination, $imageName);
             $_POST['profile-image'] = $imageName;
         } else {
             // Something went wrong
             $this->totalErrors++;
             $this->userImageError = $imageUploader->errorMessage;
         }
     }
     if ($this->totalErrors == 0) {
         $this->model->updateInfo();
         $this->detailsSuccess = 'Your details have been updated successfully.';
     }
 }
 private function processUpdateFile()
 {
     $fileNameUpdate = trim($_POST['file-name']);
     $fileTypeUpdate = $_POST['file-type-upload-dropdown'];
     $fileTagUpdate = $_POST['tag-checkbox'];
     $fileDescriptionUpdate = trim($_POST['file-description']);
     $this->fileNameUpdate = $fileNameUpdate;
     $this->fileTypeUpdate = $fileTypeUpdate;
     $this->fileTagUpdate = $fileTagUpdate;
     $this->fileDescriptionUpdate = $fileDescriptionUpdate;
     //Validation
     if ($fileNameUpdate == '') {
         $this->fileNameUpdateError = 'Required';
         $this->totalErrors++;
     } elseif (strlen($fileNameUpdate) > 30 || strlen($fileNameUpdate) < 3) {
         $this->fileNameUpdateError = 'Job Title must be between 3 and 30 characters.';
         $this->totalErrors++;
     } elseif (!preg_match('/^[\\w0-9_\\-. ]{3,20}$/', $fileNameUpdate)) {
         $this->fileNameUpdateError = 'Use only letters, numbers, hyphens underscore and periods.';
         $this->totalErrors++;
     }
     $FileTypeUpdate = $_POST['file-type-upload-dropdown'];
     if (!is_numeric($FileTypeUpdate)) {
         $this->fileTypeUpdateError = 'Something Wrong';
         $this->totalErrors++;
     }
     if ($fileDescriptionUpdate == '') {
         $this->fileDescriptionUpdateError = 'Required';
         $this->totalErrors++;
     } elseif (strlen($fileDescriptionUpdate) > 2000 || strlen($fileDescriptionUpdate) < 3) {
         $this->fileDescriptionUpdateError = 'Job Title must be between 3 and 2000 characters. you have gone over by' . (strlen($fileDescription) - 2000);
         $this->totalErrors++;
     } elseif (!preg_match('/^[\\w0-9_\\-. ]{3,2000}$/', $fileDescriptionUpdate)) {
         $this->fileDescriptionUpdateError = 'Use only letters, numbers, hyphens underscore and periods.';
         $this->totalErrors++;
     }
     // Only if the user has seleted some checkboxes
     if (isset($fileTagUpdate)) {
         // Loop through each checkbox and make sure they are a number
         foreach ($fileTagUpdate as $tagUpdate) {
             // If it is not a number
             if (!is_numeric($uploadTag)) {
                 $this->totalErrors++;
                 $this->tagUpdateError = 'Something wrong with checkboxes';
             }
         }
     }
     //attempt to upload the image
     if ($this->totalErrors == 0 && isset($_FILES['file-image']) && $_FILES['file-image']['name'] != '') {
         //Require the image uploader
         require_once 'vendor/ImageUploader.php';
         //create instance of the image uploader
         $imageUploader = new ImageUploader();
         //Attempt to upload the image
         $result = $imageUploader->upload('file-image', 'img/file-images/original/');
         //if upload was success
         if ($result) {
             //get the file name
             $imageName = $imageUploader->getImageName();
             //Prepare the variables
             $fileLocation = "img/file-images/original/{$imageName}";
             //Prepare the preview version
             $previewDestination = "img/file-images/preview/";
             $imageUploader->resize($fileLocation, 400, $previewDestination, $imageName);
             //Make the thumbnail version
             $thumbnailDestination = "img/file-images/thumbnail/";
             $imageUploader->resize($fileLocation, 200, $thumbnailDestination, $imageName);
             $_POST['newFileImage'] = $imageName;
         } else {
             //Something went wrong
             $this->totalErrors++;
             $this->fileImageUpdateError = $imageUploader->errorMessage;
         }
     }
     if ($this->totalErrors == 0) {
         $result = $this->model->updateFile();
         //if result was good
         if ($result) {
             $this->fileUpdateSuccess = 'Successfully updated your file';
         } else {
             $this->fileUpdateFail = 'File not updated';
         }
     }
 }