A collection of utility functions to facilitate an efficient workflow with the Darkwave web application toolkit.
These functions are included with Darkwave, but they can be installed and used as standalone functions in any project.
Install the package with Composer:
composer require jyoungblood/dw-utilities
Then add it to your application:
use Darkwave\dw;
require __DIR__ . '/vendor/autoload.php';
Returns the (best guess for the) current visitor's IP address, using a combination of $_SERVER['HTTP_CLIENT_IP']
, $_SERVER['HTTP_X_FORWARDED_FOR']
, and $_SERVER['REMOTE_ADDR']
dw::client_ip();
Parses the JWT 'token' cookie and sets global authentication variables to be used by the rest of the application.
dw::authenticate();
Uses psr-jwt to generate a JWT based on data from a given user's profile. Sets payload claims for _id
, name
, avatar_url
, screenname
, admin_token
, and staff_token
dw::generate_jwt($user);
Uses php-image-resize and GD to convert a given image based on various configuration parameters.
dw::convert_image([
'source' => $_SERVER['DOCUMENT_ROOT'] . '/uploads/source-filename.jpg',
'target' => $_SERVER['DOCUMENT_ROOT'] . '/uploads/converted-filename.jpg',
'resize' => [300, 300],
// 'threshold' => 800
'crop' => 'center',
'quality' => 80
]);