From 5fde4c0902e3a6aed10fd3b0a1bd06bd8628138c Mon Sep 17 00:00:00 2001 From: Alex Zaharia Date: Wed, 11 Jul 2018 18:08:57 +0300 Subject: [PATCH] Base64 encode the editor content --- editor/api.php | 8 ++++++-- editor/api/project.php | 9 +++++++-- editor/post.php | 32 ++++++++++++++++++++++---------- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/editor/api.php b/editor/api.php index c06c1eec94..9e31563d4c 100755 --- a/editor/api.php +++ b/editor/api.php @@ -605,7 +605,7 @@ public static function create_post_arr( Brizy_Editor_Post $post ) { $p_id = (int) $post->get_id(); $the_title = get_the_title( $p_id ); - return array( + $global = array( 'title' => $the_title, 'slug' => sanitize_title( $the_title ), 'data' => $post->get_editor_data(), @@ -615,6 +615,8 @@ public static function create_post_arr( Brizy_Editor_Post $post ) { 'status' => get_post_status( $p_id ), 'url' => get_the_permalink( $p_id ) ); + + return $global; } /** @@ -623,7 +625,7 @@ public static function create_post_arr( Brizy_Editor_Post $post ) { public function create_post_globals() { $wp_post = $this->post->get_wp_post(); - return array( + $globals = array( 'id' => $this->project->get_id(), 'gb' => $this->project->get_globals(), 'name' => $wp_post->post_name, @@ -634,6 +636,8 @@ public function create_post_globals() { 'id' => null, ), ); + + return $globals; } /** diff --git a/editor/api/project.php b/editor/api/project.php index 5b26b89d22..c08cd629a7 100755 --- a/editor/api/project.php +++ b/editor/api/project.php @@ -44,6 +44,11 @@ public function set_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'] ); } @@ -52,11 +57,11 @@ public function get_globals_as_json() { } public function set_globals( $globals ) { - return $this->data['globals'] = json_encode( $globals ); + return $this->data['globals'] = base64_encode( json_encode( $globals ) ); } public function set_globals_as_json( $globals ) { - return $this->data['globals'] = $globals; + return $this->data['globals'] = base64_encode( $globals ); } /** diff --git a/editor/post.php b/editor/post.php index 0fe17094b3..8b51068ab0 100755 --- a/editor/post.php +++ b/editor/post.php @@ -132,8 +132,8 @@ public function unserialize( $data ) { parent::unserialize( $data ); // TODO: Change the autogenerated stub if ( $this->get_api_page() ) { - $save_data = $this->get_api_page()->get_content(); - $this->editor_data = $save_data; + $save_data = $this->get_api_page()->get_content(); + $this->set_editor_data( $save_data ); } unset( $this->api_page ); @@ -167,8 +167,8 @@ static public function createFromSerializedData( $data ) { $post->compiled_html_head = $data['compiled_html_head']; } - $post->needs_compile = $data['needs_compile']; - $post->editor_data = $data['editor_data']; + $post->needs_compile = $data['needs_compile']; + $post->set_editor_data( $data['editor_data'] ); $post->editor_version = isset( $data['editor_version'] ) ? $data['editor_version'] : BRIZY_EDITOR_VERSION; $post->compiler_version = isset( $data['compiler_version'] ) ? $data['compiler_version'] : BRIZY_EDITOR_VERSION; $post->uses_editor = (bool) ( isset( $data[ Brizy_Editor_Constants::USES_BRIZY ] ) ? $data[ Brizy_Editor_Constants::USES_BRIZY ] : false ); @@ -195,21 +195,22 @@ public static function get( $apost ) { $brizy_editor_storage_post = Brizy_Editor_Storage_Post::instance( $wp_post_id ); $using_editor_old = $brizy_editor_storage_post->get( Brizy_Editor_Constants::USES_BRIZY, false ); - $post = $brizy_editor_storage_post->get( self::BRIZY_POST ); + $post = $brizy_editor_storage_post->get( self::BRIZY_POST ); if ( is_array( $post ) ) { $post = self::createFromSerializedData( $post ); - if(!is_null($using_editor_old)) { - $post->uses_editor = (bool)$using_editor_old; + if ( ! is_null( $using_editor_old ) ) { + $post->uses_editor = (bool) $using_editor_old; $post->wp_post_id = $wp_post_id; $post->wp_post = get_post( $wp_post_id ); $post->create_uid(); + $brizy_editor_storage_post->delete(Brizy_Editor_Constants::USES_BRIZY); $post->save(); } } elseif ( $post instanceof self ) { - $post->uses_editor = (bool)$using_editor_old; + $post->uses_editor = (bool) $using_editor_old; $post->wp_post_id = $wp_post_id; $post->wp_post = get_post( $wp_post_id ); $post->create_uid(); @@ -474,7 +475,14 @@ public function get_uid() { * @return string */ public function get_editor_data() { - return isset( $this->editor_data ) ? $this->editor_data : ''; + + if ( base64_encode( base64_decode( $this->editor_data, true ) ) === $this->editor_data ) { + $base_64_decode = base64_decode( $this->editor_data, true ); + + return $base_64_decode; + } + + return $this->editor_data; } /** @@ -483,8 +491,12 @@ public function get_editor_data() { * @return $this */ public function set_editor_data( $content ) { - $this->editor_data = $content; + if ( base64_encode( base64_decode( $content, true ) ) === $content ) { + $this->editor_data = $content; + } else { + $this->editor_data = base64_encode( $content ); + } return $this; }