make sure ABSPATH is defined before using it - fixes issue #648
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
<?php
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
namespace MailPoet\API;
|
||||
|
||||
use \MailPoet\Util\Security;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class API {
|
||||
function init() {
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
namespace MailPoet\API;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
namespace MailPoet\API;
|
||||
|
||||
final class Error {
|
||||
const UNKNOWN = 'unknown';
|
||||
const BAD_REQUEST = 'bad_request';
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
namespace MailPoet\Cron;
|
||||
|
||||
use MailPoet\Cron\Workers\Scheduler as SchedulerWorker;
|
||||
@ -6,8 +8,6 @@ use MailPoet\Cron\Workers\SendingQueue\SendingQueue as SendingQueueWorker;
|
||||
|
||||
require_once(ABSPATH . 'wp-includes/pluggable.php');
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Daemon {
|
||||
public $daemon;
|
||||
public $request_data;
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
namespace MailPoet\Cron\Workers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
@ -12,7 +14,6 @@ use MailPoet\Newsletter\Scheduler\Scheduler as NewsletterScheduler;
|
||||
|
||||
require_once(ABSPATH . 'wp-includes/pluggable.php');
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Scheduler {
|
||||
public $timer;
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
namespace MailPoet\Form\Block;
|
||||
|
||||
class Checkbox extends Base {
|
||||
@ -49,5 +51,4 @@ class Checkbox extends Base {
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
namespace MailPoet\Form\Block;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
namespace MailPoet\Form\Block;
|
||||
|
||||
class Radio extends Base {
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
namespace MailPoet\Form\Block;
|
||||
|
||||
class Segment extends Base {
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
namespace MailPoet\Form\Block;
|
||||
|
||||
class Select extends Base {
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
namespace MailPoet\Form\Block;
|
||||
|
||||
class Submit extends Base {
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
namespace MailPoet\Form\Block;
|
||||
|
||||
class Text extends Base {
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
namespace MailPoet\Form\Block;
|
||||
|
||||
class Textarea extends Base {
|
||||
|
@ -1,11 +1,10 @@
|
||||
<?php
|
||||
namespace MailPoet\Mailer;
|
||||
|
||||
use MailPoet\Models\Setting;
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
require_once(ABSPATH . 'wp-includes/pluggable.php');
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
namespace MailPoet\Mailer;
|
||||
use MailPoet\Models\Setting;
|
||||
|
||||
class Mailer {
|
||||
public $mailer_config;
|
||||
|
@ -1,11 +1,12 @@
|
||||
<?php
|
||||
namespace MailPoet\Newsletter\Shortcodes\Categories;
|
||||
|
||||
use MailPoet\Models\SendingQueue;
|
||||
use MailPoet\Newsletter\Shortcodes\ShortcodesHelper;
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
require_once( ABSPATH . "wp-includes/pluggable.php" );
|
||||
|
||||
namespace MailPoet\Newsletter\Shortcodes\Categories;
|
||||
use MailPoet\Models\SendingQueue;
|
||||
use MailPoet\Newsletter\Shortcodes\ShortcodesHelper;
|
||||
|
||||
class Newsletter {
|
||||
static function process($action,
|
||||
$default_value = false,
|
||||
@ -54,4 +55,4 @@ class Newsletter {
|
||||
$posts->posts[0]->to_array() :
|
||||
false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
<?php
|
||||
namespace MailPoet\Newsletter\Shortcodes\Categories;
|
||||
|
||||
use MailPoet\Models\Subscriber as SubscriberModel;
|
||||
use MailPoet\Models\SubscriberCustomField;
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
require_once(ABSPATH . 'wp-includes/pluggable.php');
|
||||
|
||||
namespace MailPoet\Newsletter\Shortcodes\Categories;
|
||||
use MailPoet\Models\Subscriber as SubscriberModel;
|
||||
use MailPoet\Models\SubscriberCustomField;
|
||||
|
||||
class Subscriber {
|
||||
static function process(
|
||||
$action,
|
||||
@ -42,4 +43,4 @@ class Subscriber {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
namespace MailPoet\Twig;
|
||||
|
||||
class Assets
|
||||
@ -68,4 +70,4 @@ class Assets
|
||||
public function generateImageUrl($path) {
|
||||
return $this->_globals['assets_url'].'/img/'.$path;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
<?php
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
namespace MailPoet\Twig;
|
||||
|
||||
class Functions extends \Twig_Extension {
|
||||
|
||||
function __construct() {
|
||||
}
|
||||
|
||||
function getName() {
|
||||
return 'functions';
|
||||
}
|
||||
@ -129,4 +128,4 @@ class Functions extends \Twig_Extension {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
<?php
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
namespace MailPoet\Twig;
|
||||
|
||||
class Handlebars extends \Twig_Extension {
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
return 'handlebars';
|
||||
}
|
||||
@ -61,4 +60,4 @@ class Handlebars extends \Twig_Extension {
|
||||
}
|
||||
return join("\n", $output);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
namespace MailPoet\Twig;
|
||||
|
||||
class I18n extends \Twig_Extension {
|
||||
@ -87,4 +89,4 @@ class I18n extends \Twig_Extension {
|
||||
}
|
||||
return $args;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
<?php
|
||||
namespace MailPoet\Util;
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
require_once(ABSPATH . 'wp-includes/pluggable.php');
|
||||
|
||||
namespace MailPoet\Util;
|
||||
|
||||
class Security {
|
||||
static function generateToken() {
|
||||
return wp_create_nonce('mailpoet_token');
|
||||
|
@ -1,182 +1,172 @@
|
||||
<?php
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
namespace Sudzy;
|
||||
|
||||
abstract class ValidModel extends \Model
|
||||
{
|
||||
protected $_validator = null; // Reference to Sudzy validator object
|
||||
protected $_validations = array(); // Array of validations
|
||||
protected $_validationErrors = array(); // Array of error messages
|
||||
protected $_validationOptions = array(
|
||||
'indexedErrors' => false, // If True getValidationErrors will return an array with the index
|
||||
// being the field name and the value the error. If multiple errors
|
||||
// are triggered for a field only the first will be kept.
|
||||
'throw' => self::ON_SAVE // One of self::ON_SET|ON_SAVE|NEVER.
|
||||
// + ON_SET throws immediately when field is set()
|
||||
// + ON_SAVE throws on save()
|
||||
// + NEVER means an exception is never thrown; check for ->getValidaionErrors()
|
||||
);
|
||||
abstract class ValidModel extends \Model {
|
||||
protected $_validator = null; // Reference to Sudzy validator object
|
||||
protected $_validations = array(); // Array of validations
|
||||
protected $_validationErrors = array(); // Array of error messages
|
||||
protected $_validationOptions = array(
|
||||
'indexedErrors' => false, // If True getValidationErrors will return an array with the index
|
||||
// being the field name and the value the error. If multiple errors
|
||||
// are triggered for a field only the first will be kept.
|
||||
'throw' => self::ON_SAVE // One of self::ON_SET|ON_SAVE|NEVER.
|
||||
// + ON_SET throws immediately when field is set()
|
||||
// + ON_SAVE throws on save()
|
||||
// + NEVER means an exception is never thrown; check for ->getValidationErrors()
|
||||
);
|
||||
|
||||
const ON_SET = 'set';
|
||||
const ON_SAVE = 'save';
|
||||
const NEVER = null;
|
||||
const ON_SET = 'set';
|
||||
const ON_SAVE = 'save';
|
||||
const NEVER = null;
|
||||
|
||||
public function __construct($validatorInstance = null) {
|
||||
$this->_validator = $validatorInstance;
|
||||
public function __construct($validatorInstance = null) {
|
||||
$this->_validator = $validatorInstance;
|
||||
}
|
||||
|
||||
public function setValidationOptions($options) {
|
||||
$this->_validationOptions = array_merge($this->_validationOptions, $options);
|
||||
}
|
||||
|
||||
public function addValidation($field, $validation, $message) {
|
||||
if(!isset($this->_validations[$field])) {
|
||||
$this->_validations[$field] = array();
|
||||
}
|
||||
$this->_validations[$field][] = array(
|
||||
'validation' => $validation,
|
||||
'message' => $message
|
||||
);
|
||||
}
|
||||
|
||||
public function setValidationOptions($options)
|
||||
{
|
||||
$this->_validationOptions = array_merge($this->_validationOptions, $options);
|
||||
}
|
||||
|
||||
public function addValidation($field, $validation, $message) {
|
||||
if (!isset($this->_validations[$field])) {
|
||||
$this->_validations[$field] = array();
|
||||
}
|
||||
$this->_validations[$field][] = array(
|
||||
'validation' => $validation,
|
||||
'message' => $message
|
||||
);
|
||||
}
|
||||
|
||||
public function addValidations($field, $validators) {
|
||||
foreach ($validators as $validation => $message) {
|
||||
$this->addValidation($field, $validation, $message);
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Checks, without throwing exceptions, model fields with validations
|
||||
// *
|
||||
// * @return bool If false, running $this->doValidationError() will respond appropriately
|
||||
// */
|
||||
// public function validate()
|
||||
// {
|
||||
// $fields = array_keys($this->_validations);
|
||||
// $success = true;
|
||||
// foreach ($fields as $f) {
|
||||
// $success = $success && $this->validateField($f, $this->$f);
|
||||
// }
|
||||
// return $success;
|
||||
// }
|
||||
|
||||
/**
|
||||
* @return bool Will set a message if returning false
|
||||
**/
|
||||
public function validateField($field, $value)
|
||||
{
|
||||
$this->setupValidationEngine();
|
||||
|
||||
if (!isset($this->_validations[$field])) {
|
||||
return true; // No validations, return true by default
|
||||
}
|
||||
|
||||
$success = true;
|
||||
foreach ($this->_validations[$field] as $v) {
|
||||
$checks = explode(' ', $v['validation']);
|
||||
foreach ($checks as $check) {
|
||||
$params = explode('|', $check);
|
||||
$check = array_shift($params);
|
||||
|
||||
if ($this->_validator->executeOne($check, $value, $params)) {
|
||||
$success = $success && true;
|
||||
} else {
|
||||
$this->addValidationError($v['message'], $field);
|
||||
$success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
|
||||
public function getValidationErrors()
|
||||
{
|
||||
return $this->_validationErrors;
|
||||
}
|
||||
|
||||
public function resetValidationErrors()
|
||||
{
|
||||
$this->_validationErrors = array();
|
||||
}
|
||||
|
||||
///////////////////
|
||||
// Overloaded methods
|
||||
|
||||
/**
|
||||
* Overload __set to call validateAndSet
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
$this->validateAndSet($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overload save; checks if errors exist before saving
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
if ($this->isNew()) { //Fields populated by create() or hydrate() don't pass through set()
|
||||
foreach( array_keys($this->_validations) as $field) {
|
||||
$this->validateField($field, $this->$field);
|
||||
}
|
||||
}
|
||||
|
||||
$errs = $this->getValidationErrors();
|
||||
if (!empty($errs)) {
|
||||
$this->doValidationError(self::ON_SAVE);
|
||||
}
|
||||
|
||||
parent::save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Overload set; to call validateAndSet
|
||||
*/
|
||||
public function set($key, $value = null)
|
||||
{
|
||||
if(is_array($key)) {
|
||||
// multiple values
|
||||
foreach($key as $field => $value) {
|
||||
$this->validateAndSet($field, $value);
|
||||
}
|
||||
} else {
|
||||
$this->validateAndSet($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////
|
||||
// Protected methods
|
||||
protected function doValidationError($context)
|
||||
{
|
||||
if ($context == $this->_validationOptions['throw']) {
|
||||
throw new \Sudzy\ValidationException($this->_validationErrors);
|
||||
}
|
||||
}
|
||||
|
||||
protected function addValidationError($msg, $field = null)
|
||||
{
|
||||
if ($this->_validationOptions['indexedErrors'] && $field !== null) {
|
||||
// Only keep the first error found on a field
|
||||
if (!isset($this->_validationErrors[$field])) {
|
||||
$this->_validationErrors[$field] = $msg;
|
||||
}
|
||||
} else {
|
||||
$this->_validationErrors[] = $msg;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overload set; to call validateAndSet
|
||||
*/
|
||||
protected function validateAndSet($name, $value)
|
||||
{
|
||||
if (!$this->validateField($name, $value)) $this->doValidationError(self::ON_SET);
|
||||
parent::set($name, $value);
|
||||
}
|
||||
|
||||
protected function setupValidationEngine()
|
||||
{
|
||||
if (null == $this->_validator) $this->_validator = new \Sudzy\Engine(); // Is lazy setup worth it?
|
||||
public function addValidations($field, $validators) {
|
||||
foreach ($validators as $validation => $message) {
|
||||
$this->addValidation($field, $validation, $message);
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Checks, without throwing exceptions, model fields with validations
|
||||
// *
|
||||
// * @return bool If false, running $this->doValidationError() will respond appropriately
|
||||
// */
|
||||
// public function validate()
|
||||
// {
|
||||
// $fields = array_keys($this->_validations);
|
||||
// $success = true;
|
||||
// foreach ($fields as $f) {
|
||||
// $success = $success && $this->validateField($f, $this->$f);
|
||||
// }
|
||||
// return $success;
|
||||
// }
|
||||
|
||||
/**
|
||||
* @return bool Will set a message if returning false
|
||||
**/
|
||||
public function validateField($field, $value) {
|
||||
$this->setupValidationEngine();
|
||||
|
||||
if(!isset($this->_validations[$field])) {
|
||||
return true; // No validations, return true by default
|
||||
}
|
||||
|
||||
$success = true;
|
||||
foreach ($this->_validations[$field] as $v) {
|
||||
$checks = explode(' ', $v['validation']);
|
||||
foreach ($checks as $check) {
|
||||
$params = explode('|', $check);
|
||||
$check = array_shift($params);
|
||||
|
||||
if($this->_validator->executeOne($check, $value, $params)) {
|
||||
$success = $success && true;
|
||||
} else {
|
||||
$this->addValidationError($v['message'], $field);
|
||||
$success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
|
||||
public function getValidationErrors() {
|
||||
return $this->_validationErrors;
|
||||
}
|
||||
|
||||
public function resetValidationErrors() {
|
||||
$this->_validationErrors = array();
|
||||
}
|
||||
|
||||
///////////////////
|
||||
// Overloaded methods
|
||||
|
||||
/**
|
||||
* Overload __set to call validateAndSet
|
||||
*/
|
||||
public function __set($name, $value) {
|
||||
$this->validateAndSet($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overload save; checks if errors exist before saving
|
||||
*/
|
||||
public function save() {
|
||||
if($this->isNew()) { //Fields populated by create() or hydrate() don't pass through set()
|
||||
foreach(array_keys($this->_validations) as $field) {
|
||||
$this->validateField($field, $this->$field);
|
||||
}
|
||||
}
|
||||
|
||||
$errs = $this->getValidationErrors();
|
||||
if(!empty($errs)) {
|
||||
$this->doValidationError(self::ON_SAVE);
|
||||
}
|
||||
|
||||
parent::save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Overload set; to call validateAndSet
|
||||
*/
|
||||
public function set($key, $value = null) {
|
||||
if(is_array($key)) {
|
||||
// multiple values
|
||||
foreach($key as $field => $value) {
|
||||
$this->validateAndSet($field, $value);
|
||||
}
|
||||
} else {
|
||||
$this->validateAndSet($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////
|
||||
// Protected methods
|
||||
protected function doValidationError($context) {
|
||||
if($context == $this->_validationOptions['throw']) {
|
||||
throw new \Sudzy\ValidationException($this->_validationErrors);
|
||||
}
|
||||
}
|
||||
|
||||
protected function addValidationError($msg, $field = null) {
|
||||
if($this->_validationOptions['indexedErrors'] && $field !== null) {
|
||||
// Only keep the first error found on a field
|
||||
if(!isset($this->_validationErrors[$field])) {
|
||||
$this->_validationErrors[$field] = $msg;
|
||||
}
|
||||
} else {
|
||||
$this->_validationErrors[] = $msg;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overload set; to call validateAndSet
|
||||
*/
|
||||
protected function validateAndSet($name, $value) {
|
||||
if(!$this->validateField($name, $value)) $this->doValidationError(self::ON_SET);
|
||||
parent::set($name, $value);
|
||||
}
|
||||
|
||||
protected function setupValidationEngine() {
|
||||
if(null == $this->_validator) $this->_validator = new \Sudzy\Engine(); // Is lazy setup worth it?
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user