Skip to content

Commit

Permalink
Base64 encode the editor content
Browse files Browse the repository at this point in the history
  • Loading branch information
alecszaharia committed Jul 11, 2018
1 parent ee2fba4 commit 5fde4c0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
8 changes: 6 additions & 2 deletions editor/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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;
}

/**
Expand All @@ -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,
Expand All @@ -634,6 +636,8 @@ public function create_post_globals() {
'id' => null,
),
);

return $globals;
}

/**
Expand Down
9 changes: 7 additions & 2 deletions editor/api/project.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] );
}

Expand All @@ -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 );
}

/**
Expand Down
32 changes: 22 additions & 10 deletions editor/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

Expand Down

0 comments on commit 5fde4c0

Please sign in to comment.