first commit
This commit is contained in:
67
wp-content/plugins/brizy/editor/storage/abstract.php
Normal file
67
wp-content/plugins/brizy/editor/storage/abstract.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) {
|
||||
die( 'Direct access forbidden.' );
|
||||
}
|
||||
|
||||
abstract class Brizy_Editor_Storage_Abstract {
|
||||
|
||||
public function loadStorage( $value ) {
|
||||
$this->update_storage( $value );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param $value
|
||||
*
|
||||
* @return Brizy_Editor_Storage_Abstract
|
||||
*/
|
||||
public function set( $key, $value ) {
|
||||
$storage = $this->get_storage();
|
||||
$storage[ $key ] = $value;
|
||||
$this->update_storage( $storage );
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @param bool $thorw_if_notset
|
||||
*
|
||||
* @return mixed
|
||||
* @throws Brizy_Editor_Exceptions_NotFound
|
||||
*/
|
||||
public function get( $key, $thorw_if_notset = true ) {
|
||||
$storage = $this->get_storage();
|
||||
|
||||
if ( isset( $storage[ $key ] ) ) {
|
||||
return $storage[ $key ];
|
||||
}
|
||||
|
||||
if ( $thorw_if_notset ) {
|
||||
throw new Brizy_Editor_Exceptions_NotFound( "The key [{$key}] was not found in storage." );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function delete( $key ) {
|
||||
$storage = $this->get_storage();
|
||||
if ( isset( $storage[ $key ] ) ) {
|
||||
unset( $storage[ $key ] );
|
||||
$this->update_storage( $storage );
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $storage
|
||||
*
|
||||
* @return Brizy_Editor_Storage_Abstract
|
||||
*/
|
||||
abstract protected function update_storage( $storage );
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
abstract public function get_storage();
|
||||
}
|
||||
46
wp-content/plugins/brizy/editor/storage/common.php
Normal file
46
wp-content/plugins/brizy/editor/storage/common.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) {
|
||||
die( 'Direct access forbidden.' );
|
||||
}
|
||||
|
||||
class Brizy_Editor_Storage_Common extends Brizy_Editor_Storage_Abstract {
|
||||
|
||||
const KEY = 'brizy';
|
||||
|
||||
/**
|
||||
* @return Brizy_Editor_Storage_Common
|
||||
*/
|
||||
public static function instance() {
|
||||
static $instance;
|
||||
|
||||
if ( ! $instance ) {
|
||||
$instance = new self();
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function get_storage() {
|
||||
|
||||
$get_option = (array) get_option( $this->key(), array() );
|
||||
|
||||
return $get_option;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $storage
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function update_storage( $storage ) {
|
||||
update_option( $this->key(), $storage );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function key() {
|
||||
return self::KEY;
|
||||
}
|
||||
}
|
||||
12
wp-content/plugins/brizy/editor/storage/post-signature.php
Normal file
12
wp-content/plugins/brizy/editor/storage/post-signature.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) {
|
||||
die( 'Direct access forbidden.' );
|
||||
}
|
||||
|
||||
class Brizy_Editor_Storage_PostSignature extends Brizy_Editor_Storage_Post {
|
||||
|
||||
const BRIZY_POST_SIGNATURE_KEY = 'brizy-post-signature';
|
||||
|
||||
protected function key() {
|
||||
return self::BRIZY_POST_SIGNATURE_KEY;
|
||||
}
|
||||
}
|
||||
61
wp-content/plugins/brizy/editor/storage/post.php
Normal file
61
wp-content/plugins/brizy/editor/storage/post.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) {
|
||||
die( 'Direct access forbidden.' );
|
||||
}
|
||||
|
||||
class Brizy_Editor_Storage_Post extends Brizy_Editor_Storage_Abstract {
|
||||
|
||||
const META_KEY = 'brizy';
|
||||
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
*
|
||||
* @return Brizy_Editor_Storage_Post
|
||||
*/
|
||||
public static function instance( $id ) {
|
||||
return new self( $id );
|
||||
}
|
||||
|
||||
protected function __construct( $id ) {
|
||||
$this->id = (int) $id;
|
||||
}
|
||||
|
||||
protected function get_id() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo: rename this to get_data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_storage() {
|
||||
|
||||
wp_cache_delete( $this->get_id(), 'post_meta');
|
||||
|
||||
$get_metadata = get_metadata( 'post', $this->get_id(), $this->key(), true );
|
||||
|
||||
if ( is_array( $get_metadata ) ) {
|
||||
return $get_metadata;
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $storage
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function update_storage( $storage ) {
|
||||
|
||||
update_metadata( 'post', $this->get_id(), $this->key(), $storage );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function key() {
|
||||
return self::META_KEY;
|
||||
}
|
||||
}
|
||||
21
wp-content/plugins/brizy/editor/storage/project-globals.php
Normal file
21
wp-content/plugins/brizy/editor/storage/project-globals.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) {
|
||||
die( 'Direct access forbidden.' );
|
||||
}
|
||||
|
||||
class Brizy_Editor_Storage_ProjectGlobals extends Brizy_Editor_Storage_Project {
|
||||
|
||||
const META_KEY = 'brizy-project-globals';
|
||||
|
||||
protected function key() {
|
||||
return self::META_KEY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
*
|
||||
* @return Brizy_Editor_Storage_Post
|
||||
*/
|
||||
public static function instance( $id ) {
|
||||
return new self( $id );
|
||||
}
|
||||
}
|
||||
30
wp-content/plugins/brizy/editor/storage/project.php
Normal file
30
wp-content/plugins/brizy/editor/storage/project.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php if ( ! defined( 'ABSPATH' ) ) {
|
||||
die( 'Direct access forbidden.' );
|
||||
}
|
||||
|
||||
class Brizy_Editor_Storage_Project extends Brizy_Editor_Storage_Post {
|
||||
|
||||
const META_KEY = 'brizy-project';
|
||||
|
||||
protected function key() {
|
||||
return self::META_KEY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
*
|
||||
* @return Brizy_Editor_Storage_Post
|
||||
*/
|
||||
public static function instance( $id ) {
|
||||
return new self( $id );
|
||||
}
|
||||
|
||||
public function loadStorage( $value ) {
|
||||
|
||||
if(!isset($value['data']) || is_null($value['data']) || empty($value['data'])) {
|
||||
Brizy_Logger::instance()->critical( 'Execution stopped. Attempt to save invalid project data.', array( $value ) );
|
||||
throw new Exception('Execution stopped. Attempt to save invalid project data.');
|
||||
}
|
||||
parent::loadStorage( $value );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user