Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: Added 4 urls for all types of screenshots. #1921

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions editor/editor/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ public function getClientConfig( $editorConfig, $context ) {
}

$config = [
'hash' => wp_create_nonce( Brizy_Editor_API::nonce ),
'editorVersion' => BRIZY_EDITOR_VERSION,
'url' => set_url_scheme( admin_url( 'admin-ajax.php' ) ),
'actions' => $this->getApiActions(),
'pageId' => $this->post->getWpPostId(),
'collectionTypes' => $editorConfig['wp']['postLoopSources']
];
'prefix' => Brizy_Editor::prefix(),
'hash' => wp_create_nonce( Brizy_Editor_API::nonce ),
'editorVersion' => BRIZY_EDITOR_VERSION,
'url' => set_url_scheme( admin_url( 'admin-ajax.php' ) ),
'actions' => $this->getApiActions(),
'pageId' => $this->post->getWpPostId(),
'collectionTypes' => $editorConfig['wp']['postLoopSources']
];

$config = $this->getApiConfigFields( $config, $context );

Expand Down Expand Up @@ -358,19 +359,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