fixes to support composer / packagist

This commit is contained in:
Joey Kimsey
2024-08-08 01:17:27 -04:00
parent 41d2a45ad6
commit 0525739f2c
12 changed files with 191 additions and 492 deletions

View File

@ -1,219 +0,0 @@
<?php
/**
* classes/email.php
*
* This is our class for constructing and sending various kinds of emails.
*
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com/Core
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Houdini\Classes;
use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Bedrock\Classes\Config;
use TheTempusProject\Canary\Canary as Debug;
use TheTempusProject\Hermes\Functions\Route as Routes;
class Email {
private static $header = null;
private static $subject = null;
private static $title = null;
private static $message = null;
private static $unsub = false;
private static $useTemplate = false;
private static $footer = null;
private static $debug = false;
/**
* Sends pre-constructed email templates. Useful for modifying the
* entire theme or layout of the system generated emails.
*
* @param string $email - The email you are sending to.
* @param string $type - The template you wish to send.
* @param string|array $params - Any special parameters that may be required from your individual email template.
*
* @return bool
*/
public static function send( $email, $type, $params = null, $flags = null ) {
if ( !empty( $flags ) ) {
if ( is_array( $flags ) ) {
foreach ( $flags as $key => $value ) {
switch ( $key ) {
case 'template':
if ( $value == true ) {
self::$useTemplate = true;
}
break;
case 'unsubscribe':
if ( $value == true ) {
self::$unsub = true;
}
break;
case 'debug':
if ( $value == true ) {
self::$debug = false;
}
break;
}
}
}
}
self::build();
switch ( $type ) {
case 'debug':
self::$subject = 'Please Confirm your email at {SITENAME}';
self::$title = 'Almost Done';
self::$message = 'Please click or copy-paste this link to confirm your registration: <a href="{BASE}register/confirm/{PARAMS}">Confirm Your Email</a>';
break;
case 'confirmation':
self::$subject = 'Please Confirm your email at {SITENAME}';
self::$title = 'Almost Done';
self::$message = 'Please click or copy-paste this link to confirm your registration: <a href="{BASE}register/confirm/{PARAMS}">Confirm Your Email</a>';
break;
case 'install':
self::$subject = 'Notification from {SITENAME}';
self::$title = 'Installation Success';
self::$message = 'This is just a simple email to notify you that you have successfully installed The Tempus Project framework!';
break;
case 'passwordChange':
self::$subject = 'Security Notice from {SITENAME}';
self::$title = 'Password Successfully Changed';
self::$message = 'Recently your password on {SITENAME} was changed. If you are the one who changed the password, please ignore this email.';
break;
case 'emailChangeNotice':
self::$subject = 'Account Update from {SITENAME}';
self::$title = 'Email Updated';
self::$message = 'This is a simple notification to let you know your email has been changed at {SITENAME}.';
break;
case 'emailChange':
self::$subject = 'Account Update from {SITENAME}';
self::$title = 'Confirm your E-mail';
self::$message = 'Please click or copy-paste this link to confirm your new Email: <a href="{BASE}register/confirm/{PARAMS}">Confirm Your Email</a>';
break;
case 'emailNotify':
self::$subject = 'Account Update from {SITENAME}';
self::$title = 'Email Updated';
self::$message = 'You recently changed your email address on {SITENAME}.';
break;
case 'forgotPassword':
self::$subject = 'Reset Instructions for {SITENAME}';
self::$title = 'Reset your Password';
self::$message = 'You recently requested information to change your password at {SITENAME}.<br>Your password reset code is: {PARAMS}<br> Please click or copy-paste this link to reset your password: <a href="{BASE}register/reset/{PARAMS}">Password Reset</a>';
break;
case 'forgotUsername':
self::$subject = 'Account Update from {SITENAME}';
self::$title = 'Account Details';
self::$message = 'Your username for {SITENAME} is {PARAMS}.';
break;
case 'subscribe':
self::$subject = 'Thanks for Subscribing';
self::$title = 'Thanks for Subscribing!';
self::$message = 'Thank you for subscribing to updates from {SITENAME}. If you no longer wish to receive these emails, you can un-subscribe using the link below.';
self::$unsub = true;
break;
case 'unsubInstructions':
self::$subject = 'Unsubscribe Instructions';
self::$title = 'We are sad to see you go';
self::$message = 'If you would like to be un-subscribed from future emails from {SITENAME} simply click the link below.<br><br><a href="{BASE}home/unsubscribe/{EMAIL}/{PARAMS}">Click here to unsubscribe</a>';
self::$unsub = true;
break;
case 'unsubscribe':
self::$subject = 'Unsubscribed';
self::$title = 'We are sad to see you go';
self::$message = 'This is just a notification that you have successfully been unsubscribed from future emails from {SITENAME}.';
break;
case 'contact':
self::$subject = $params['subject'];
self::$title = $params['title'];
self::$message = $params['message'];
break;
default:
return false;
break;
}
if ( self::$useTemplate ) {
$data = new \stdClass();
if ( self::$unsub ) {
$data->UNSUB = Views::simpleView( 'email.unsubscribe' );
} else {
$data->UNSUB = '';
}
// $data->LOGO = Config::getValue('main/logo');
$data->SITENAME = Config::getValue( 'main/name' );
$data->EMAIL = $email;
if ( !is_array( $params ) ) {
$data->PARAMS = $params;
} else {
foreach ( $params as $key => $value ) {
$data->$key = $value;
}
}
$data->MAIL_FOOT = Views::simpleView( 'email.foot' );
$data->MAIL_TITLE = self::$title;
$data->MAIL_BODY = Template::parse( self::$message, $data );
$subject = Template::parse( self::$subject, $data );
$body = Views::simpleView( 'email.template', $data );
} else {
$subject = self::$subject;
$body = '<h1>' . self::$title . '</h1>' . self::$message;
}
if ( !is_object( $email ) ) {
$email = (object) [
(object) [ 'email' => $email ],
];
}
$error = false;
foreach ( $email as $data ) {
if ( !mail( $data->email, $subject, $body, self::$header ) ) {
Debug::error( 'Failed to send email. emailSubject: ' . $subject . ' emailRecipientEmail: ' . $data->email );
Debug::error( var_export( error_get_last(), true ) );
$error = true;
}
}
if ( $error ) {
return false;
}
Debug::info( "Email sent: $type." );
return true;
}
/**
* Constructor for the header.
*/
public static function build() {
if ( empty( self::$header ) ) {
self::$header = 'From: ' . Config::getValue( 'main/name' ) . ' <' . EMAIL_FROM_EMAIL . ">\r\n";
self::$header .= "MIME-Version: 1.0\r\n";
self::$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$url = parse_url( Routes::getAddress(), PHP_URL_HOST );
$parts = explode( '.', $url );
$count = count( $parts );
if ( $count > 2 ) {
$host = $parts[$count - 2] . '.' . $parts[$count - 1];
} else {
$host = $url;
}
if ( self::$debug ) {
self::$header .= 'CC: ' . DEBUG_EMAIL . "\r\n";
}
}
}
}

View File

@ -1,224 +0,0 @@
<?php
/**
* core/template/pagination.php
*
* This class is for managing template pagination.
*
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com/Core
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Houdini\Classes;
use TheTempusProject\Houdini\Classes\Template;
use TheTempusProject\Hermes\Functions\Route as Routes;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Bedrock\Classes\Config;
use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Canary\Canary as Debug;
class Pagination extends Template {
//The settings that will not change
public static $paginationSettings = [];
//The instance for each generation
public static $instance = null;
public function __construct() {
if ( empty( self::$paginationSettings['limit'] ) ) {
$this->loadSettings();
}
// check for user settings
if ( empty( self::$paginationSettings['perPage'] ) ) {
self::$paginationSettings['perPage'] = DEFAULT_RESULTS_PER_PAGE;
if ( ( !empty( self::$paginationSettings['userPerPage'] ) ) && ( self::$paginationSettings['userPerPage'] <= self::$paginationSettings['maxPerPage'] ) ) {
self::$paginationSettings['perPage'] = self::$paginationSettings['userPerPage'];
}
}
// The query minimum and maximum based on current page and page limit
if ( self::$paginationSettings['currentPage'] == 1 ) {
self::$paginationSettings['min'] = 0;
} else {
self::$paginationSettings['min'] = ( ( self::$paginationSettings['currentPage'] - 1 ) * self::$paginationSettings['perPage'] );
}
// if ( self::$paginationSettings['currentPage'] == 1 ) {
self::$paginationSettings['max'] = self::$paginationSettings['perPage'];
// } else {
// self::$paginationSettings['max'] = ( self::$paginationSettings['currentPage'] * self::$paginationSettings['perPage'] );
// }
// The query limit based on our settings here
self::$paginationSettings['limit'] = [self::$paginationSettings['min'], self::$paginationSettings['max']];
}
private static function loadSettings() {
Debug::log( 'Loading Pagination Settings.' );
// hard cap built into system for displaying results
self::$paginationSettings['maxPerPage'] = MAX_RESULTS_PER_PAGE;
// hard cap built into system retrieving results
self::$paginationSettings['maxQuery'] = Config::getValue( 'database/dbMaxQuery' );
// Set max query to the lowest of the three settings since this will modify how many results are possible.
if ( self::$paginationSettings['maxQuery'] <= self::$paginationSettings['maxPerPage'] ) {
self::$paginationSettings['maxPerPage'] = self::$paginationSettings['maxQuery'];
}
// Check for results request to set/modify the perPage setting
if ( Input::exists( 'results' ) ) {
if ( Check::ID( Input::get( 'results' ) ) ) {
if ( Input::get( 'results' ) <= self::$paginationSettings['maxPerPage'] ) {
self::$paginationSettings['perPage'] = Input::get( 'results' );
}
}
}
if ( empty( self::$paginationSettings['perPage'] ) ) {
self::$paginationSettings['perPage'] = self::$paginationSettings['maxPerPage'];
}
// Check for pagination in get
if ( Input::exists( 'page' ) ) {
if ( Check::ID( Input::get( 'page' ) ) ) {
self::$paginationSettings['currentPage'] = (int) Input::get( 'page' );
} else {
self::$paginationSettings['currentPage'] = 1;
}
} else {
self::$paginationSettings['currentPage'] = 1;
}
if ( ( self::$paginationSettings['currentPage'] - 3 ) > 1 ) {
self::$paginationSettings['firstPage'] = ( self::$paginationSettings['currentPage'] - 2 );
} else {
self::$paginationSettings['firstPage'] = 1;
}
}
public static function generate() {
// account for empty values here instead of inside the script.
Debug::log( 'Creating new Pagination Instance.' );
self::$instance = new self();
return self::$instance;
}
public static function updatePaginationTotal( $count ) {
if ( empty( self::$paginationSettings ) ) {
self::generate();
}
if ( Check::id( $count ) ) {
Debug::log( 'Pagination: Updating results count' );
self::$paginationSettings['results'] = $count;
self::$paginationSettings['totalPages'] = ceil( ( self::$paginationSettings['results'] / self::$paginationSettings['perPage'] ) );
if ( ( self::$paginationSettings['currentPage'] + 3 ) < self::$paginationSettings['totalPages'] ) {
self::$paginationSettings['lastPage'] = self::$paginationSettings['currentPage'] + 3;
} else {
self::$paginationSettings['lastPage'] = self::$paginationSettings['totalPages'];
}
Debug::info( 'Pagination: results update completed.' );
} else {
Debug::info( 'Pagination: results update failed.' );
}
}
public static function paginate() {
$pageData = [];
if ( self::firstPage() != 1 ) {
$data[1]['ACTIVEPAGE'] = '';
$data[1]['PAGENUMBER'] = 1;
$data[1]['LABEL'] = 'First';
$pageData[1] = (object) $data[1];
}
for ( $x = self::firstPage(); $x < self::lastPage(); $x++ ) {
if ( $x == self::currentPage() ) {
$active = ' class="active"';
} else {
$active = '';
}
$data[$x]['ACTIVEPAGE'] = $active;
$data[$x]['PAGENUMBER'] = $x;
$data[$x]['LABEL'] = $x;
$pageData[$x] = (object) $data[$x];
}
if ( self::lastPage() <= self::totalPages() ) {
$x = self::totalPages();
if ( $x == self::currentPage() ) {
$active = ' class="active"';
} else {
$active = '';
}
$data[$x]['ACTIVEPAGE'] = $active;
$data[$x]['PAGENUMBER'] = $x;
$data[$x]['LABEL'] = 'Last';
$pageData[$x] = (object) $data[$x];
}
$pageData = (object) $pageData;
if ( self::totalPages() <= 1 ) {
Components::set( 'PAGINATION', 'no pagination' );
} else {
Components::set( 'PAGINATION', Views::simpleView( 'nav.pagination', $pageData ) );
}
}
public static function updatePrefs( $pageLimit ) {
if ( Check::id( $pageLimit ) ) {
Debug::log( 'Pagination: Updating user pref' );
self::$paginationSettings['userPerPage'] = $pageLimit;
} else {
Debug::info( 'Pagination: User pref update failed.' );
}
}
/**
* Getters
*/
public static function getMin() {
if ( isset( self::$paginationSettings['min'] ) ) {
return self::$paginationSettings['min'];
} else {
Debug::info( 'Pagination: Min not found' );
return 0;
}
}
public static function getMax() {
if ( isset( self::$paginationSettings['max'] ) ) {
return self::$paginationSettings['max'];
} else {
Debug::info( 'Pagination: Max not found' );
return 0;
}
}
public static function perPage() {
if ( !empty( self::$paginationSettings['perPage'] ) ) {
return self::$paginationSettings['perPage'];
}
}
public static function firstPage() {
if ( !empty( self::$paginationSettings['firstPage'] ) ) {
return self::$paginationSettings['firstPage'];
} else {
Debug::info( 'Pagination: firstPage not found' );
}
}
public static function lastPage() {
if ( !empty( self::$paginationSettings['lastPage'] ) ) {
return self::$paginationSettings['lastPage'];
} else {
Debug::info( 'Pagination: lastPage not found' );
}
}
public static function totalPages() {
if ( !empty( self::$paginationSettings['totalPages'] ) ) {
return self::$paginationSettings['totalPages'];
} else {
Debug::info( 'Pagination: totalPages not found' );
}
}
public static function currentPage() {
if ( !empty( self::$paginationSettings['currentPage'] ) ) {
return self::$paginationSettings['currentPage'];
} else {
Debug::info( 'Pagination: currentPage not found' );
}
}
}

View File

@ -16,15 +16,12 @@ namespace TheTempusProject\Houdini\Classes;
use TheTempusProject\Canary\Canary as Debug;
use TheTempusProject\Hermes\Functions\Route as Routes;
use TheTempusProject\Bedrock\Functions\Token;
use TheTempusProject\Bedrock\Functions\Date;
use TheTempusProject\Bedrock\Classes\Config;
use TheTempusProject\Bedrock\Classes\CustomException;
// use TheTempusProject\Bedrock\Functions\Date;
// use TheTempusProject\Bedrock\Classes\CustomException;
use TheTempusProject\Houdini\Classes\Components;
use TheTempusProject\Houdini\Classes\Forms;
use TheTempusProject\Houdini\Classes\Filters;
use TheTempusProject\Houdini\Classes\Issues;
use TheTempusProject\Houdini\Classes\Pagination;
class Template {
private static $follow = true;
@ -45,7 +42,6 @@ class Template {
Components::set( 'ROOT_ADDRESS', Routes::getAddress() );
Components::set( 'TITLE', '' );
Components::set( 'PAGE_DESCRIPTION', '' );
Components::set( 'TOKEN', Token::generate() );
Components::set( 'BASE', Routes::getAddress() );
Debug::gend();
}
@ -112,7 +108,7 @@ class Template {
return self::loadTemplate( $location, $name );
}
}
new CustomException( 'template', $docLocation );
// new CustomException( 'template', $docLocation );
}
/**
@ -130,7 +126,7 @@ class Template {
$fullPath = $path . $name . '.inc.php';
$className = APP_SPACE . '\\Templates\\' . ucfirst( $name ) . 'Loader';
if ( !file_exists( $fullPath ) ) {
new CustomException( 'templateLoader', $fullPath );
// new CustomException( 'templateLoader', $fullPath );
} else {
Debug::log( 'Requiring template loader: ' . $name );
require_once $fullPath;
@ -206,10 +202,7 @@ class Template {
self::buildRobot();
self::buildHeaders();
if ( empty( self::$templateLocation ) ) {
self::setTemplate( Config::getValue( 'main/template' ) );
}
if ( empty( self::$templateLocation ) ) {
self::setTemplate( Config::getValue( 'main/template' ) );
// throw an error here @todo
return;
}
if ( !Debug::status( 'render' ) ) {
@ -322,6 +315,7 @@ class Template {
* be used as components for the provided html.
* @return string - The fully parsed html output.
*/
public static function parse( $template, $data = null, $flags = null ) {
if ( empty( $template ) ) {
return $template;
@ -346,7 +340,8 @@ class Template {
if ( empty( $data[2] ) ) {
return '';
}
return Date::formatTimestamp( $data[1], $data[2] );
return $data[2]; // @todo need a way to decouple this from houdini to bedrock
// return Date::formatTimestamp( $data[1], $data[2] );
},
$template
);