Initial commit
This commit is contained in:
65
app/plugins/subscribe/controllers/admin/subscriptions.php
Normal file
65
app/plugins/subscribe/controllers/admin/subscriptions.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/subscribe/controllers/admin/subscriptions.php
|
||||
*
|
||||
* This is the subscriptions admin controller.
|
||||
*
|
||||
* @package TP Subscribe
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Controllers\Admin;
|
||||
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Classes\AdminController;
|
||||
use TheTempusProject\Models\Subscribe;
|
||||
use TheTempusProject\Classes\Forms;
|
||||
|
||||
class Subscriptions extends AdminController {
|
||||
public static $subscribe;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Admin - Email Subscribers';
|
||||
self::$subscribe = new Subscribe;
|
||||
}
|
||||
|
||||
public function delete( $data = null ) {
|
||||
if ( $data == null ) {
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
$data = Input::post( 'S_' );
|
||||
}
|
||||
}
|
||||
if ( !self::$subscribe->delete( (array) $data ) ) {
|
||||
Issues::add( 'error', 'There was an error with your request, please try again.' );
|
||||
} else {
|
||||
Issues::add( 'success', 'Subscriber removed.' );
|
||||
}
|
||||
$this->index();
|
||||
}
|
||||
|
||||
public function add( $data = null ) {
|
||||
if ( !Input::exists( 'submit' ) ) {
|
||||
return Views::view( 'subscribe.admin.add' );
|
||||
}
|
||||
if ( !Forms::check( 'subscribe' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
||||
return $this->index();
|
||||
}
|
||||
if ( !self::$subscribe->add( Input::post( 'email' ) ) ) {
|
||||
Issues::add( 'error', 'There was an error with your request, please try again.' );
|
||||
return $this->index();
|
||||
}
|
||||
Issues::add( 'success', 'Subscriber added.' );
|
||||
$this->index();
|
||||
}
|
||||
|
||||
public function index( $data = null ) {
|
||||
Views::view( 'subscribe.admin.list', self::$subscribe->listPaginated() );
|
||||
}
|
||||
}
|
79
app/plugins/subscribe/controllers/subscribe.php
Normal file
79
app/plugins/subscribe/controllers/subscribe.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/subscribe/controllers/subscribe.php
|
||||
*
|
||||
* This is the home controller for the subscribe plugin.
|
||||
*
|
||||
* @package TP Subscribe
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Controllers;
|
||||
|
||||
use TheTempusProject\Classes\Controller;
|
||||
use TheTempusProject\Classes\Forms;
|
||||
use TheTempusProject\Hermes\Functions\Redirect;
|
||||
use TheTempusProject\Bedrock\Functions\Session;
|
||||
use TheTempusProject\Bedrock\Functions\Input;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Classes\Email;
|
||||
use TheTempusProject\Houdini\Classes\Issues;
|
||||
use TheTempusProject\Houdini\Classes\Views;
|
||||
use TheTempusProject\Models\Subscribe as SubscribeModel;
|
||||
|
||||
class Subscribe extends Controller {
|
||||
private static $subscribe;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$subscribe = new SubscribeModel;
|
||||
}
|
||||
|
||||
public function index() {
|
||||
self::$title = 'Subscribe - {SITENAME}';
|
||||
self::$pageDescription = 'We are always publishing great content and keeping our members up to date. If you would like to join our list, you can subscribe here.';
|
||||
if ( !Input::exists( 'email' ) ) {
|
||||
return Views::view( 'subscribe.subscribe' );
|
||||
}
|
||||
if ( !Forms::check( 'subscribe' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your form.' => Check::userErrors() ] );
|
||||
return Views::view( 'subscribe.subscribe' );
|
||||
}
|
||||
if ( !self::$subscribe->add( Input::post( 'email' ) ) ) {
|
||||
Issues::add( 'error', 'There was an error with your request, please try again.' );
|
||||
return Views::view( 'subscribe.subscribe' );
|
||||
}
|
||||
$data = self::$subscribe->get( Input::post( 'email' ) );
|
||||
Email::send( Input::post( 'email' ), 'subscribe', $data->confirmationCode, ['template' => true] );
|
||||
Issues::add( 'success', 'You have successfully been subscribed to our mailing list.' );
|
||||
}
|
||||
|
||||
public function unsubscribe( $email = null, $code = null ) {
|
||||
self::$title = '{SITENAME}';
|
||||
self::$pageDescription = '';
|
||||
if ( !empty( $email ) && !empty( $code ) ) {
|
||||
if ( self::$subscribe->unsubscribe( $email, $code ) ) {
|
||||
return Issues::add( 'success', 'You have been successfully unsubscribed from receiving further mailings.' );
|
||||
}
|
||||
Issues::add( 'error', 'There was an error with your request.' );
|
||||
return Views::view( 'subscribe.unsubscribe' );
|
||||
}
|
||||
if ( !Input::exists( 'submit' ) ) {
|
||||
return Views::view( 'subscribe.unsubscribe' );
|
||||
}
|
||||
if ( !Forms::check( 'unsubscribe' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
||||
return Views::view( 'subscribe.unsubscribe' );
|
||||
}
|
||||
$data = self::$subscribe->get( Input::post( 'email' ) );
|
||||
if ( empty( $data ) ) {
|
||||
Issues::add( 'notice', 'There was an error with your request.' );
|
||||
return Views::view( 'subscribe.unsubscribe' );
|
||||
}
|
||||
Email::send( Input::post( 'email' ), 'unsubInstructions', $data->confirmationCode, ['template' => true] );
|
||||
Session::flash( 'success', 'An email with instructions on how to unsubscribe has been sent to your email.' );
|
||||
Redirect::to( 'home/index' );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user