Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/helpers #42

Merged
merged 2 commits into from
Mar 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions env.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
const URL_ROOT = 'http://localhost:8080';
const COOKIE_DAYS = 180;
const CONTROLLER_FOLDER = 'Controllers\\';
const DEFAULT_TIMEZONE = 'America/New_York';

// Debug
const DISPLAY_ERRORS = true;
Expand Down
5 changes: 5 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
*/
require_once dirname(__DIR__) . '/vendor/autoload.php';

/**
* Configure default timezone
*/
date_default_timezone_set(DEFAULT_TIMEZONE);

/**
* Control error reporting via ENV vars
*/
Expand Down
16 changes: 8 additions & 8 deletions src/App/HandleFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class HandleFile
* Write into file
*
* mode can be:
* r Open a file for read only.
* w Open a file for write only.
* a Open a file for write only.
* x Creates a new file for write only.
* r+ Open a file for read/write.
* w+ Open a file for read/write.
* a+ Open a file for read/write.
* x+ Creates a new file for read/write.
* r Open a file for read only.
* w Open a file for write only.
* a Open a file for write only.
* x Creates a new file for write only.
* r+ Open a file for read/write.
* w+ Open a file for read/write.
* a+ Open a file for read/write.
* x+ Creates a new file for read/write.
*
* @param string $name
* @param string $extension
Expand Down
14 changes: 7 additions & 7 deletions src/App/HandleForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@ private static function validate(mixed $value, string $type): bool
* @return array (2 elements: false and error message OR true and file address)
*/
public static function upload(
array $file,
array $extensions,
int $size,
array $file,
array $extensions,
int $size,
string $target,
int $compressRate = 100,
int $compressRate = 100,
string $baseName = '',
int $newWidth = 0,
int $newWidth = 0,
string $overlay = '',
int $overlayWidth = 0,
int $overlayHeight = 0
int $overlayWidth = 0,
int $overlayHeight = 0
): array
{
if (!isset($file['type'])) {
Expand Down
5 changes: 3 additions & 2 deletions src/App/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public static function slug(string $str, string $delimiter = '-', bool $addDate
}

// Thanks for great codes: https://gist.github.com/lindelius/4881d2b27fa04356b5736cad81b8c9de

/**
* Dumps a given variable along with some additional data
*
Expand Down Expand Up @@ -162,7 +163,7 @@ public static function mailto(string $to, string $subject, string $message): boo
// Content
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->Body = $message;
$mail->AltBody = strip_tags($message);

$mail->send();
Expand All @@ -184,7 +185,7 @@ public static function log(string $message)

// Create file and make sure if written by root, then accessible by www
$logFile = LOG_FILE_BASENAME . date('Ymd') . '.log';
$fHandler = fopen( '/var/www/' . LOG_DIR . $logFile,'a+');
$fHandler = fopen('/var/www/' . LOG_DIR . $logFile, 'a+');
fwrite($fHandler, $logInfo . $message . PHP_EOL);
fclose($fHandler);
chown('/var/www/' . LOG_DIR . $logFile, 'www');
Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/API/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function store()
echo json_encode($output);
} elseif (Blog::store($request)) {
if (isset($_FILES['image']['type'])) {
HandleForm::upload($_FILES['image'], ['jpeg', 'jpg','png'], 5000000, '../public/assets/images/', 85, Helper::slug($request->title, '-', false));
HandleForm::upload($_FILES['image'], ['jpeg', 'jpg', 'png'], 5000000, '../public/assets/images/', 85, Helper::slug($request->title, '-', false));
}

XmlGenerator::feed();
Expand Down Expand Up @@ -136,7 +136,7 @@ public function update()
$currentPost = Database::fetch();

if (isset($_FILES['image']['type'])) {
HandleForm::upload($_FILES['image'], ['jpeg', 'jpg','png'], 5000000, '../public/assets/images/', 85, substr($currentPost['slug'], 0, -11));
HandleForm::upload($_FILES['image'], ['jpeg', 'jpg', 'png'], 5000000, '../public/assets/images/', 85, substr($currentPost['slug'], 0, -11));
}

XmlGenerator::feed();
Expand Down
7 changes: 4 additions & 3 deletions src/Controllers/API/BlogGrpcController.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function store(PostStoreRequest $request): SuccessResponse
list($response, $status) = $client->setMessage($output['status']);
} elseif (Blog::store($request)) {
if (isset($_FILES['image']['type'])) {
HandleForm::upload($_FILES['image'], ['jpeg', 'jpg','png'], 5000000, '../public/assets/images/', 85, Helper::slug($request->getTitle(), '-', false));
HandleForm::upload($_FILES['image'], ['jpeg', 'jpg', 'png'], 5000000, '../public/assets/images/', 85, Helper::slug($request->getTitle(), '-', false));
}

XmlGenerator::feed();
Expand Down Expand Up @@ -157,7 +157,7 @@ public function update(PostUpdateRequest $request): SuccessResponse
$currentPost = Database::fetch();

if (isset($_FILES['image']['type'])) {
HandleForm::upload($_FILES['image'], ['jpeg', 'jpg','png'], 5000000, '../public/assets/images/', 85, substr($currentPost['slug'], 0, -11));
HandleForm::upload($_FILES['image'], ['jpeg', 'jpg', 'png'], 5000000, '../public/assets/images/', 85, substr($currentPost['slug'], 0, -11));
}

XmlGenerator::feed();
Expand Down Expand Up @@ -201,7 +201,8 @@ public function delete(PostRequest $request): SuccessResponse
* @param mixed $status
* @return void
*/
private function checkStatus(mixed $status) {
private function checkStatus(mixed $status)
{
if ($status->code !== \Grpc\STATUS_OK) {
echo "ERROR: " . $status->code . ", " . $status->details . PHP_EOL;
exit(1);
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class HomeController
public function index()
{
// Fire an event as a sample
Event::listen('homeStarter', function($param) {
Event::listen('homeStarter', function ($param) {
// Log fired event by logger as a sample
Helper::log('App started and ' . $param . ' event has been fired!');
});
Expand Down