Skip to content

Commit

Permalink
new: Added 4 urls for all types of screenshots.
Browse files Browse the repository at this point in the history
  • Loading branch information
alecszaharia committed Aug 14, 2023
1 parent 2c23d21 commit cbaa6eb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
24 changes: 16 additions & 8 deletions editor/editor/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,19 +358,27 @@ private function addProjectData( $config, $context ) {


private function getApiConfigFields( $config, $context ) {
$config['api'] = [
'media' => [

$screenshotManager = new Brizy_Editor_Screenshot_Manager( $this->urlBuilder );
$config['api'] = [
'media' => [
'mediaResizeUrl' => home_url()
],
'customFile' => [
'customFileUrl' => home_url()
],
'templates' => [
'kitsUrl' => Brizy_Config::getEditorTemplatesUrl('kits'),
'layoutsUrl' => Brizy_Config::getEditorTemplatesUrl('layouts'),
'popupsUrl' => Brizy_Config::getEditorTemplatesUrl('popups'),
'storiesUrl' => Brizy_Config::getEditorTemplatesUrl('stories')
]
'screenshots' => [
'normalScreenshotUrl' => $screenshotManager->getScreenshotBaseUrl( Brizy_Editor_Screenshot_Manager::BLOCK_TYPE_NORMAL, $this->post->getWpPostId() ),
'globalScreenshotUrl' => $screenshotManager->getScreenshotBaseUrl( Brizy_Editor_Screenshot_Manager::BLOCK_TYPE_GLOBAL, $this->post->getWpPostId() ),
'layoutScreenshotUrl' => $screenshotManager->getScreenshotBaseUrl( Brizy_Editor_Screenshot_Manager::BLOCK_TYPE_LAYOUT, $this->post->getWpPostId() ),
'savedScreenshotUrl' => $screenshotManager->getScreenshotBaseUrl( Brizy_Editor_Screenshot_Manager::BLOCK_TYPE_SAVED, $this->post->getWpPostId() ),
],
'templates' => [
'kitsUrl' => Brizy_Config::getEditorTemplatesUrl( 'kits' ),
'layoutsUrl' => Brizy_Config::getEditorTemplatesUrl( 'layouts' ),
'popupsUrl' => Brizy_Config::getEditorTemplatesUrl( 'popups' ),
'storiesUrl' => Brizy_Config::getEditorTemplatesUrl( 'stories' )
]
];

return $config;
Expand Down
27 changes: 25 additions & 2 deletions editor/screenshot/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct( Brizy_Editor_UrlBuilder $urlBuilder ) {
* @return bool
*/
public function saveScreenshot( $screenUid, $blockType, $imageContent, $postId ) {
$path = $this->getScreenshotPath( $screenUid, $blockType, $postId );
$path = $this->getScreenshotPath( $blockType, $postId );

if(!$this->validateImageContent( $imageContent )) {
throw new Exception('Invalid image content');
Expand All @@ -51,7 +51,7 @@ public function getScreenshot( $screenUid, $postId = null ) {
$types = array( self::BLOCK_TYPE_NORMAL, self::BLOCK_TYPE_GLOBAL, self::BLOCK_TYPE_SAVED, self::BLOCK_TYPE_LAYOUT );

foreach ( $types as $type ) {
$filePath = $this->getScreenshotPath( $screenUid, $type, $postId );
$filePath = $this->getScreenshotPath( $type, $postId );

$filePath = $filePath . DIRECTORY_SEPARATOR . "{$screenUid}.jpeg";

Expand Down Expand Up @@ -88,6 +88,29 @@ private function getScreenshotPath( $screenUID, $blockType, $postID ) {
return $folderPath;
}

public function getScreenshotBaseUrl( $blockType, $postID ) {

switch ( $blockType ) {
case self::BLOCK_TYPE_NORMAL:
$this->urlBuilder->set_post_id( $postID );
$folderPath = $this->urlBuilder->page_upload_url( 'blockThumbnails' );
break;
case self::BLOCK_TYPE_GLOBAL:
$folderPath = $this->urlBuilder->brizy_upload_url( 'blockThumbnails' . DIRECTORY_SEPARATOR . 'global' );
break;
case self::BLOCK_TYPE_SAVED:
$folderPath = $this->urlBuilder->brizy_upload_url( 'blockThumbnails' . DIRECTORY_SEPARATOR . 'saved' );
break;
case self::BLOCK_TYPE_LAYOUT:
$folderPath = $this->urlBuilder->brizy_upload_url( 'blockThumbnails' . DIRECTORY_SEPARATOR . 'layout' );
break;
default:
return null;
}

return $folderPath;
}


/**
* @param $content
Expand Down

0 comments on commit cbaa6eb

Please sign in to comment.