first commit

This commit is contained in:
Roman Pyrih
2023-07-24 08:30:51 +02:00
commit c2e100a763
7128 changed files with 1622619 additions and 0 deletions

View File

@@ -0,0 +1,102 @@
<?php
class Brizy_Editor_API_AccessToken extends Brizy_Admin_Serializable {
/**
* @var string $token
*/
private $token;
/**
* @var string $token
*/
private $refresh_token;
/**
* @var int $token
*/
private $expires;
/**
* Brizy_API_Access_Token constructor.
*
* @param string $token
* @param int $expires
*/
public function __construct( $token, $expires ) {
$this->token = $token;
$this->expires = (int) $expires;
}
public function convertToOptionValue() {
return array(
'token' => $this->token,
'refresh_token' => $this->refresh_token,
'expires' => $this->expires
);
}
static public function createFromSerializedData( $data ) {
$instance = new self( $data['token'], $data['expires'] );
$instance->refresh_token = $data['refresh_token'];
return $instance;
}
public function access_token() {
return $this->token;
}
public function get_expires() {
return $this->expires;
}
public function expired() {
return time() >= $this->get_expires();
}
/**
* @return string
*/
public function get_refresh_token() {
return $this->refresh_token;
}
/**
* @param $refresh_token
*
* @return $this
*/
public function set_refresh_token( $refresh_token ) {
$this->refresh_token = $refresh_token;
return $this;
}
public function export() {
return array(
'access_token' => $this->access_token(),
'expires' => $this->get_expires(),
);
}
public function serialize() {
return serialize( array(
'token' => $this->token,
'refresh_token' => $this->refresh_token,
'expires' => $this->expires,
) );
}
public function unserialize( $data ) {
$vars = unserialize( $data );
foreach ( $vars as $prop => $value ) {
$this->$prop = $value;
}
}
}

View File

@@ -0,0 +1,90 @@
<?php
class Brizy_Editor_API_Auth extends Brizy_Editor_Http_Client {
/**
* @var string
*/
private $gateway_url;
/**
* @var string
*/
private $client_id;
/**
* @var string
*/
private $secret;
public function __construct( $gateway_url, $client_id, $secret ) {
parent::__construct();
$this->gateway_url = $gateway_url;
$this->client_id = $client_id;
$this->secret = $secret;
}
public function auth_url() {
return $this->gateway_url . '/oauth/token';
}
public function refresh_url() {
return $this->gateway_url . '/oauth/refresh';
}
/**
* @param $email
*
* @return Brizy_Editor_API_AccessToken
* @throws Brizy_Editor_API_Exceptions_Exception
* @throws Brizy_Editor_Http_Exceptions_BadRequest
* @throws Brizy_Editor_Http_Exceptions_ResponseException
* @throws Brizy_Editor_Http_Exceptions_ResponseNotFound
* @throws Brizy_Editor_Http_Exceptions_ResponseUnauthorized
*/
public function getToken( $email ) {
$token = get_option( $this->get_meta_id(), null );
if ( $token instanceof Brizy_Editor_API_AccessToken) {
if ( ! $token->expired() ) {
return $token;
} else {
$this->clearTokenCache();
}
}
$response = $this->post( $this->auth_url(),
array(
'body' => array(
'client_id' => $this->client_id,
'client_secret' => $this->secret,
'email' => $email,
'grant_type' => 'https://visual.dev/api/extended_client_credentials'
),
'sslverify' => false
)
)->get_response_body();
$brizy_editor_API_access_token = new Brizy_Editor_API_AccessToken( $response['access_token'], $response['expires_in'] + time() - 20 );
if ( isset( $response['refresh_token'] ) ) {
$brizy_editor_API_access_token->set_refresh_token( $response['refresh_token'] );
}
add_option( $this->get_meta_id(), $brizy_editor_API_access_token );
return $brizy_editor_API_access_token;
}
public function clearTokenCache() {
delete_option( $this->get_meta_id() );
}
private function get_meta_id() {
return "brizy_" . md5( $this->client_id );
}
}

View File

@@ -0,0 +1,363 @@
<?php
class Brizy_Editor_API_Client extends Brizy_Editor_Http_Client
{
/**
* @var Brizy_Editor_API_AccessToken
*/
private $access_token;
/**
* Brizy_Editor_API_Client constructor.
*
* @param $token
*/
public function __construct($token)
{
parent::__construct();
$this->access_token = $token;
}
public function getUser()
{
return $this->post('users/me', array())->get_response_body();
}
/**
* @param null $clone_from_id
*
* @return array|mixed|object
* @throws Brizy_Editor_API_Exceptions_Exception
* @throws Brizy_Editor_Http_Exceptions_BadRequest
* @throws Brizy_Editor_Http_Exceptions_ResponseException
* @throws Brizy_Editor_Http_Exceptions_ResponseNotFound
* @throws Brizy_Editor_Http_Exceptions_ResponseUnauthorized
*/
public function create_project($clone_from_id = null)
{
$project = new Brizy_Editor_API_Project(array());
$save_data = $project->getSaveData();
if ($clone_from_id) {
$save_data['resource_id_clonable'] = $clone_from_id;
}
return $this->post('projects', array('body' => $save_data))->get_response_body();
}
/**
* @param $page_ids
* @param $project_target
*
* @return array|mixed|object
* @throws Brizy_Editor_API_Exceptions_Exception
* @throws Brizy_Editor_Http_Exceptions_BadRequest
* @throws Brizy_Editor_Http_Exceptions_ResponseException
* @throws Brizy_Editor_Http_Exceptions_ResponseNotFound
* @throws Brizy_Editor_Http_Exceptions_ResponseUnauthorized
*/
// public function clone_pages( $page_ids, $project_target ) {
//
// return $this->post( 'pages/clones', array(
// 'body' => array(
// 'project' => $project_target,
// 'pages' => $page_ids
// )
// ) )->get_response_body();
// }
/**
* @param Brizy_Editor_API_Project $project
*
* @return array|mixed|object
* @throws Brizy_Editor_API_Exceptions_Exception
* @throws Brizy_Editor_Http_Exceptions_BadRequest
* @throws Brizy_Editor_Http_Exceptions_ResponseException
* @throws Brizy_Editor_Http_Exceptions_ResponseNotFound
* @throws Brizy_Editor_Http_Exceptions_ResponseUnauthorized
*/
public function get_project(Brizy_Editor_API_Project $project)
{
return $this->get("projects/{$project->get_id()}")->get_response_body();
}
/**
* @param Brizy_Editor_API_Project $project
*
* @return array|mixed|object
* @throws Brizy_Editor_API_Exceptions_Exception
* @throws Brizy_Editor_Http_Exceptions_BadRequest
* @throws Brizy_Editor_Http_Exceptions_ResponseException
* @throws Brizy_Editor_Http_Exceptions_ResponseNotFound
* @throws Brizy_Editor_Http_Exceptions_ResponseUnauthorized
*/
public function update_project(Brizy_Editor_API_Project $project)
{
return $this->put(
"projects/{$project->get_id()}",
array('body' => $project->getSaveData('PUT'))
)->get_response_body();
}
/**
* @param $id
*
* @return array|mixed|object
* @throws Brizy_Editor_API_Exceptions_Exception
* @throws Brizy_Editor_Http_Exceptions_BadRequest
* @throws Brizy_Editor_Http_Exceptions_ResponseException
* @throws Brizy_Editor_Http_Exceptions_ResponseNotFound
* @throws Brizy_Editor_Http_Exceptions_ResponseUnauthorized
*/
public function delete_project($id)
{
return $this->delete("projects/$id")->get_response_body();
}
/**
* @param $project_id
*
* @return array|mixed|object
* @throws Brizy_Editor_API_Exceptions_Exception
* @throws Brizy_Editor_Http_Exceptions_BadRequest
* @throws Brizy_Editor_Http_Exceptions_ResponseException
* @throws Brizy_Editor_Http_Exceptions_ResponseNotFound
* @throws Brizy_Editor_Http_Exceptions_ResponseUnauthorized
*/
// public function get_pages( $project_id ) {
// return $this->get( "projects/$project_id/pages?=signature=" . Brizy_Editor_Signature::get() )->get_response_body();
// }
/**
* @param $project_id
* @param $page_id
*
* @return array|mixed|object
* @throws Brizy_Editor_API_Exceptions_Exception
* @throws Brizy_Editor_Http_Exceptions_BadRequest
* @throws Brizy_Editor_Http_Exceptions_ResponseException
* @throws Brizy_Editor_Http_Exceptions_ResponseNotFound
* @throws Brizy_Editor_Http_Exceptions_ResponseUnauthorized
*/
// public function get_page( $project_id, $page_id ) {
// return $this->get( "projects/$project_id/pages/$page_id" )->get_response_body();
// }
/**
* @param $project_id
* @param Brizy_Editor_API_Page $page
*
* @return array|mixed|object
* @throws Brizy_Editor_API_Exceptions_Exception
* @throws Brizy_Editor_Http_Exceptions_BadRequest
* @throws Brizy_Editor_Http_Exceptions_ResponseException
* @throws Brizy_Editor_Http_Exceptions_ResponseNotFound
* @throws Brizy_Editor_Http_Exceptions_ResponseUnauthorized
*/
// public function create_page( $project_id, Brizy_Editor_API_Page $page ) {
// return $this->post( "projects/$project_id/pages", array( 'body' => $page->getSaveData() ) )->get_response_body();
// }
/**
* @param $project_id
* @param $page_id
* @param Brizy_Editor_API_Page $page
*
* @return array|mixed|object
* @throws Brizy_Editor_API_Exceptions_Exception
* @throws Brizy_Editor_Http_Exceptions_BadRequest
* @throws Brizy_Editor_Http_Exceptions_ResponseException
* @throws Brizy_Editor_Http_Exceptions_ResponseNotFound
* @throws Brizy_Editor_Http_Exceptions_ResponseUnauthorized
*/
// public function update_page( $project_id, $page_id, Brizy_Editor_API_Page $page ) {
// return $this->put( "projects/$project_id/pages/$page_id", array( 'body' => $page->getSaveData( 'PUT' ) ) )->get_response_body();
// }
/**
* @param Brizy_Editor_Project $project
* @param $page_data
* @param $config
* @param $compiler_url
*
* @return array
* @throws Brizy_Editor_API_Exceptions_Exception
* @throws Brizy_Editor_Exceptions_NotFound
* @throws Brizy_Editor_Http_Exceptions_BadRequest
* @throws Brizy_Editor_Http_Exceptions_ResponseException
* @throws Brizy_Editor_Http_Exceptions_ResponseNotFound
* @throws Brizy_Editor_Http_Exceptions_ResponseUnauthorized
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
*/
public function compile_page(Brizy_Editor_Project $project, $page_data, $config, $compiler_url)
{
$blockManager = new Brizy_Admin_Blocks_Manager(Brizy_Admin_Blocks_Main::CP_GLOBAL);
$body = apply_filters(
'brizy_compiler_params',
array(
'page_id' => (int)$config['wp']['page'],
'free_version' => BRIZY_EDITOR_VERSION,
'free_url' => Brizy_Config::getCompilerDownloadUrl(),
'config_json' => json_encode($config),
'pages_json' => json_encode(
array(
array(
'id' => (int)$config['wp']['page'],
'data' => $page_data,
'is_index' => true,
),
)
),
'project_json' => json_encode($project->createResponse()),
'global_blocks_json' => json_encode(
$blockManager->createResponseForEntities($blockManager->getEntities([]))
),
)
);
$page = parent::request($compiler_url, array('body' => $body), 'POST')->get_response_body();
$template_context = array(
'editorData' => array(
'urls' => array(
'assets' => $config['urls']['assets'],
'apiEndpoint' => set_url_scheme(admin_url('admin-ajax.php')),
),
'api' => array(
'getTimestamp' => Brizy_Editor_API::AJAX_TIMESTAMP,
),
'serverTimestamp' => time(),
),
'page' => $page,
);
$blocks = $page['blocks'];
return [
'pageHtml' => Brizy_TwigEngine::instance(Brizy_Editor_UrlBuilder::editor_build_path('editor/views/'))
->render('static.html.twig', $template_context),
'pageScripts' => [
'free' => $blocks['freeScripts'],
'pro' => (isset($blocks['proScripts']) ? $blocks['proScripts'] : []),
],
'pageStyles' => [
'free' => $blocks['freeStyles'],
'pro' => (isset($blocks['proStyles']) ? $blocks['proStyles'] : []),
],
];
}
/**
* @param $project_id
* @param $page_id
*
* @return array|mixed|object
* @throws Brizy_Editor_API_Exceptions_Exception
* @throws Brizy_Editor_Http_Exceptions_BadRequest
* @throws Brizy_Editor_Http_Exceptions_ResponseException
* @throws Brizy_Editor_Http_Exceptions_ResponseNotFound
* @throws Brizy_Editor_Http_Exceptions_ResponseUnauthorized
*/
// public function delete_page( $project_id, $page_id ) {
// return $this->delete( "projects/$project_id/pages/$page_id" )->get_response_body();
// }
/**
* @param $project_id
* @param $base64
*
* @return array|mixed|object
* @throws Brizy_Editor_API_Exceptions_Exception
* @throws Brizy_Editor_Http_Exceptions_BadRequest
* @throws Brizy_Editor_Http_Exceptions_ResponseException
* @throws Brizy_Editor_Http_Exceptions_ResponseNotFound
* @throws Brizy_Editor_Http_Exceptions_ResponseUnauthorized
*/
public function add_media($project_id, $base64)
{
return $this->post(
"projects/$project_id/media",
array(
'timeout' => 30,
'body' => array('attachment' => $base64),
)
)->get_response_body();
}
/**
* @return array
*/
protected function get_headers()
{
return array(//'Authorization' => 'Bearer ' . $this->access_token->access_token()
);
}
/**
* @param $suffix
*
* @return string
*/
protected function url($suffix)
{
$implode = rtrim(implode("/", array(Brizy_Config::GATEWAY_URI, 'v1', $suffix)), "/");
return $implode;
}
/**
* @param $url
* @param array $options
* @param string $method
*
* @return Brizy_Editor_Http_Response
* @throws Brizy_Editor_API_Exceptions_Exception
* @throws Brizy_Editor_Http_Exceptions_BadRequest
* @throws Brizy_Editor_Http_Exceptions_ResponseException
* @throws Brizy_Editor_Http_Exceptions_ResponseNotFound
* @throws Brizy_Editor_Http_Exceptions_ResponseUnauthorized
*/
public function request($url, $options = array(), $method = 'GET')
{
return parent::request(
$this->url($url),
$options,
$method
);
}
/**
* @param $options
*
* @return array
*/
protected function prepare_options($options)
{
$options = parent::prepare_options($options);
$options['headers'] = array_merge($options['headers'], $this->get_headers());
return $options;
}
protected function get_project_json(Brizy_Editor_Project $project)
{
return json_encode(
array(
'id' => $project->getId(),
'data' => $project->getDataAsJson(),
)
);
}
}

View File

@@ -0,0 +1,4 @@
<?php
class Brizy_Editor_API_Exceptions_Exception extends Exception {
}

View File

@@ -0,0 +1,141 @@
<?php
/**
*
* @deprecated
*
* Class Brizy_Editor_API_Page
*/
class Brizy_Editor_API_Page extends Brizy_Admin_Serializable {
/**
* @var array
*/
private $data;
/**
* @param array $data
*
* @return Brizy_Editor_API_Page
*/
public static function get( $data = array() ) {
return new self( $data );
}
public function convertToOptionValue() {
return array(
'data' => $this->data
);
}
static public function createFromSerializedData( $data ) {
$page = new self( $data['data'] );
return $page;
}
/**
* @return string
*/
public function serialize() {
return serialize( $this->data );
}
/**
* @param $data
*/
public function unserialize( $data ) {
$this->data = unserialize( $data );
}
/**
* Brizy_Editor_API_Page constructor.
*
* @param array $data
*/
public function __construct( $data = array() ) {
$default = array( 'title' => 'Default title', 'data' => '{}' );
$this->data = array_merge( $default, $data );
}
public function get_id() {
return isset( $this->data['id'] ) ? $this->data['id'] : '';
}
public function set_id( $id ) {
$this->data['id'] = $id;
return $this;
}
public function get_title() {
return isset( $this->data['title'] ) ? $this->data['title'] : '';
}
public function set_title( $title ) {
$this->data['title'] = $title;
return $this;
}
// public function get_status() {
// return isset( $this->data['status'] ) ? $this->data['status'] : '';
// }
//
// public function set_status( $status ) {
// //$this->data['status'] = $status;
//
// return $this;
// }
public function get_content() {
return isset( $this->data['data'] ) ? $this->data['data'] : '';
}
public function set_content( $content ) {
$this->data['data'] = stripslashes( $content );
return $this;
}
public function get_language() {
return isset( $this->data['language'] ) ? $this->data['language'] : null;
}
public function get_type() {
return isset( $this->data['type'] ) ? $this->data['type'] : null;
}
public function get_url() {
return isset( $this->data['url'] ) ? $this->data['url'] : '';
}
public function get_description() {
return isset( $this->data['description'] ) ? $this->data['description'] : '';
}
public function set_description( $data ) {
$data['description'] = $data;
return $this;
}
public function is_index() {
return isset( $this->data['is_index'] ) ? (bool) $this->data['is_index'] : true;
}
public function set_is_index( $is_index ) {
$this->data['is_index'] = $is_index;
return $this;
}
public function getSaveData() {
$data = $this->data;
return array_diff_key( $data, array( 'id' => 0, 'cloned_from' => null ) );
}
}

View File

@@ -0,0 +1,208 @@
<?php
class Brizy_Editor_API_Platform extends Brizy_Editor_Http_Client {
/**
* @var string
*/
private $client_id;
/**
* @var string
*/
private $secret;
/**
* @var string
*/
private $email;
private function sign_up_url() {
return Brizy_Config::GATEWAY_URI . '/v1/users';
}
private function auth_url() {
return Brizy_Config::GATEWAY_URI . '/oauth/token';
}
/**
* Brizy_Editor_API_Platform constructor.
*/
public function __construct() {
parent::__construct();
$credentials = self::getCredentials();
$this->client_id = $credentials->client_id;
$this->secret = $credentials->client_secret;
$this->email = $credentials->email;
}
/**
* @return Brizy_Editor_API_AccessToken
* @throws Brizy_Editor_API_Exceptions_Exception
* @throws Brizy_Editor_Http_Exceptions_BadRequest
* @throws Brizy_Editor_Http_Exceptions_ResponseException
* @throws Brizy_Editor_Http_Exceptions_ResponseNotFound
* @throws Brizy_Editor_Http_Exceptions_ResponseUnauthorized
*/
// private function getToken() {
//
// Brizy_Logger::instance()->notice( 'Getting token to create the user' );
//
// $body = array(
// 'client_id' => $this->client_id,
// 'client_secret' => $this->secret,
// 'email' => $this->email,
// 'grant_type' => 'https://visual.dev/api/limited_client_credentials'
// );
//
// $response = $this->post( $this->auth_url(), array(
// 'body' => $body
// ) );
//
// $response_array = $response->get_response_body();
//
// $brizy_editor_API_access_token = new Brizy_Editor_API_AccessToken(
// $response_array['access_token'],
// time() + $response_array['expires_in']
// );
//
//
// if ( isset( $response_array['refresh_token'] ) ) {
// $brizy_editor_API_access_token->set_refresh_token( $response_array['refresh_token'] );
// }
//
// return $brizy_editor_API_access_token;
// }
/**
* @return array|mixed|null|object
* @throws Exception
*/
static public function getCredentials() {
return (object) array(
"client_id" => Brizy_Config::PLATFORM_CLIENT_ID,
"client_secret" => Brizy_Config::PLATFORM_CLIENT_SECRET,
"email" => Brizy_Config::PLATFORM_EMAIL
);
}
/**
* @return string
*/
// protected function random_email() {
// $uniqid = 'brizy-' . md5( uniqid( '', true ) );
// return $uniqid . '@brizy.io';
// }
/**
* @param null $clone_id
* @param bool $is_local
*
* @return array|bool|mixed|object
* @throws Brizy_Editor_API_Exceptions_Exception
* @throws Brizy_Editor_Http_Exceptions_BadRequest
* @throws Brizy_Editor_Http_Exceptions_ResponseException
* @throws Brizy_Editor_Http_Exceptions_ResponseNotFound
* @throws Brizy_Editor_Http_Exceptions_ResponseUnauthorized
*/
// public function createUser( $clone_id = null, $is_local = true ) {
//
// $email = $this->random_email();
//
// if ( $is_local ) {
//
// Brizy_Logger::instance()->notice( 'New user created' );
// Brizy_Editor_Storage_Common::instance()->set( 'platform_user_local', true );
// Brizy_Editor_Storage_Common::instance()->set( 'platform_user_id', uniqid( 'user', true ) );
// Brizy_Editor_Storage_Common::instance()->set( 'platform_user_email', $email );
// Brizy_Editor_Storage_Common::instance()->set( 'platform_user_signature', Brizy_Editor_Signature::get() );
//
// return Brizy_Editor_User::reload();
// }
//
// $token = $this->getToken();
//
// Brizy_Logger::instance()->notice( 'Create new user', array( 'clone_id' => $clone_id ) );
//
// $options = array(
// 'headers' => array(
// 'Authorization' => 'Bearer ' . $token->access_token()
// ),
// 'body' => array(
// 'email' => $email,
// 'signature' => Brizy_Editor_Signature::get()
// ),
// 'sslverify' => false
// );
//
// if ( $clone_id ) {
// $options['body']['resource_id_clonable'] = $clone_id;
// }
//
// $response = $this->post( $this->sign_up_url(), $options );
//
// $user = $response->get_response_body();
//
// if ( $response->is_ok() ) {
//
// Brizy_Logger::instance()->notice( 'New user created', array( $user ) );
// Brizy_Editor_Storage_Common::instance()->delete( 'platform_user_local' );
// Brizy_Editor_Storage_Common::instance()->set( 'platform_user_id', $user['id'] );
// Brizy_Editor_Storage_Common::instance()->set( 'platform_user_email', $email );
// Brizy_Editor_Storage_Common::instance()->set( 'platform_user_signature', Brizy_Editor_Signature::get() );
//
// $user = Brizy_Editor_User::reload();
//
// // try to create the local project on platform
// try {
// $local_project = Brizy_Editor_Project::get();
//
// $api_project = $user->create_project( null, false );
// $api_project->set_globals( $local_project->get_globals() );
//
// $local_project->updateProjectData( $api_project );
// $local_project->save();
//
// $user->update_project( $api_project );
//
// return $user;
// } catch ( Exception $e ) {
// Brizy_Logger::instance()->error( 'Unable to create the project for remote user', array( $response ) );
// }
// }
//
// Brizy_Logger::instance()->error( 'Failed to create user', array( $response ) );
//
// return null;
// }
public function isUserCreatedLocally() {
return Brizy_Editor_Storage_Common::instance()->get( 'platform_user_local', false ) === true;
}
/**
* @param $data
*
* @throws Exception
*/
public function notifyFormSubmit( $data ) {
$urlBuilder = new Brizy_Editor_UrlBuilder( Brizy_Editor_Project::get() );
$urls = $urlBuilder->application_form_notification_url();
$response = $this->post( $urls, $data );
if ( ! $response->is_ok() ) {
Brizy_Logger::instance()->error( 'Failed to notify the platform about a form submit', array( 'response' => $response ) );
}
}
}

View File

@@ -0,0 +1,116 @@
<?php if ( ! defined( 'ABSPATH' ) ) {
die( 'Direct access forbidden.' );
}
class Brizy_Editor_API_Project extends Brizy_Admin_Serializable {
private $data;
public function __construct( $data ) {
$defaults = array( 'title' => '', 'globals' => array() );
$this->data = array_merge( $defaults, is_array( $data ) ? $data : array() );
}
public function serialize() {
return serialize( $this->data );
}
public function unserialize( $data ) {
$this->data = unserialize( $data );
}
public function convertToOptionValue() {
return array(
'data' => serialize( $this->data )
);
}
static public function createFromSerializedData( $data ) {
$api_project = new self( $data );
return $api_project;
}
public function get_data() {
return $this->data;
}
public function get_id() {
return $this->data['id'];
}
public function set_id( $id ) {
return $this->data['id'] = $id;
}
public function get_globals() {
if ( base64_encode( base64_decode( $this->data['globals'], true ) ) === $this->data['globals'] ) {
return json_decode( base64_decode( $this->data['globals'], true ) );
}
return json_decode( $this->data['globals'] );
}
public function get_globals_as_json() {
return $this->data['globals'];
}
public function set_globals( $globals ) {
return $this->data['globals'] = base64_encode( json_encode( $globals ) );
}
public function set_globals_as_json( $globals ) {
return $this->data['globals'] = base64_encode( $globals );
}
/**
* @return string
*/
public function get_template_slug() {
$data = $this->get_data();
return $data['template']['slug'];
}
/**
* @return string
*/
public function get_template_version() {
$data = $this->get_data();
return $data['version'];
}
/**
* @param $version
*
* @return $this
*/
public function set_template_version( $version ) {
$this->data['version'] = $version;
return $this;
}
public function set_meta_key( $key, $value ) {
if ( is_null( $key ) ) {
throw new InvalidArgumentException( 'Hte key parameter should not be null' );
}
$this->data['meta_data'][ $key ] = $value;
}
public function getSaveData( $method = 'POST' ) {
$data = array(
'globals' => $this->get_globals_as_json(),
);
if ( $method == 'POST' ) {
$data['signature'] = Brizy_Editor_Signature::get();
}
return $data;
}
}