Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
usualoma committed Mar 1, 2024
2 parents e178bae + 5c923bd commit e4bd23f
Show file tree
Hide file tree
Showing 29 changed files with 1,015 additions and 48 deletions.
21 changes: 11 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
docker-image:
type: string
default: movabletype/test:buster
phpunit:
type: boolean
default: true
docker:
- image: << parameters.docker-image >>
steps:
Expand All @@ -26,13 +29,16 @@ jobs:
- run:
name: Test
command: |
git clone -b develop --depth 1 https://github.com/movabletype/movabletype.git mt
git clone -b develop --depth 1 https://github.com/movabletype/movabletype.git mt
cp -r mt/* .
cp mt/.proverc .
if [ -f t/cpanfile ]; then
cpanm --installdeps -n . --cpanfile=t/cpanfile
fi
prove -j4 -PMySQLPool=MT::Test::Env -It/lib plugins/MTBlockEditor/t
if [ "<< parameters.phpunit >>" = "true" ]; then
phpunit plugins/MTBlockEditor/php
fi
test-js:
docker:
Expand Down Expand Up @@ -74,21 +80,16 @@ workflows:
version: 2
test-and-build:
jobs:
- test-perl:
name: test-perl with centos6
docker-image: movabletype/test:centos6
- test-perl:
name: test-perl with jessie
docker-image: movabletype/test:jessie
- test-perl:
name: test-perl with buster
docker-image: movabletype/test:buster
- test-perl:
name: test-perl with fedora
docker-image: movabletype/test:fedora
phpunit: false
- test-perl:
name: test-perl with bullseye
docker-image: movabletype/test:bullseye
- test-perl:
name: test-perl with fedora39
docker-image: movabletype/test:fedora
- test-perl:
name: test-perl with cloud7
docker-image: movabletype/test:cloud7
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.SKIP
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ mt-static/plugins/MTBlockEditor/src/
# test
plugins/MTBlockEditor/t/
plugins/MTBlockEditor/xt/
plugins/MTBlockEditor/php/tests

# distribution files and directories
^MTBlockEditor

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/MTBlockEditor/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id: MTBlockEditor
name: MTBlockEditor
version: 1.2.0
version: 1.2.1
author_link: http://www.movabletype.org/
author_name: Six Apart Ltd.
description: <MT_TRANS phrase="Movable Type Block Editor.">
Expand Down
6 changes: 6 additions & 0 deletions plugins/MTBlockEditor/lib/MT/Plugin/MTBlockEditor/App/CMS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ use MT::Util qw(encode_html);
use Class::Method::Modifiers qw(install_modifier);
use MT::Plugin::MTBlockEditor qw(plugin blocks to_custom_block_types_json tmpl_param);

my $Initialized;

sub init_app {
my ($cb, $app) = @_;

return if $Initialized;

require MT::ContentFieldType::Common;
install_modifier(
'MT::ContentFieldType::Common',
Expand Down Expand Up @@ -56,6 +60,8 @@ sub init_app {

$html;
});

$Initialized = 1;
}

sub insert_after {
Expand Down
29 changes: 28 additions & 1 deletion plugins/MTBlockEditor/lib/MT/Plugin/MTBlockEditor/L10N/en_us.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,37 @@ use warnings;
use base 'MT::Plugin::MTBlockEditor::L10N';
use vars qw( %Lexicon );

my $block_editor_plugin = eval { MT->component('BlockEditor') };

%Lexicon = (
"BLOCK_LABEL_CORE_TEXT" => "Text Block",
"BLOCK_LABEL_CORE_TABLE" => "Table",
"BLOCK_LABEL_CORE_HORIZONTALRULE" => "Horizontal Rule",
"BLOCK_LABEL_CORE_HTML" => "HTML",
"BLOCK_LABEL_CORE_COLUMNS" => "Columns",
"BLOCK_LABEL_MT_IMAGE" => "Image",
"BLOCK_LABEL_MT_FILE" => "File",
"BLOCK_LABEL_SIXAPART_OEMBED" => "oEmbed",
"BLOCK_LABEL_SIXAPART_INPUT" => "Text",
"BLOCK_LABEL_SIXAPART_TEXTAREA" => "Textarea",
"BLOCK_LABEL_SIXAPART_SELECT" => "Select",

'__TEXT_BLOCK__' => 'Text',
"Manage Custom Block Preset" => 'Manage Preset',

(
$block_editor_plugin
? (
'Movable Type Block Editor' => 'MT Block Editor',
'Movable Type Block Editor Settings' => 'MT Block Editor Settings',
'Preset For Movable Type Block Editor' => 'Preset For MT Block Editor',
)
: (
'Movable Type Block Editor' => 'Block Editor',
'Movable Type Block Editor Settings' => 'Block Editor Settings',
'Preset For Movable Type Block Editor' => 'Preset For Block Editor',
'MT Block Editor Setting' => 'Block Editor Setting',
)
),
);

1;
16 changes: 16 additions & 0 deletions plugins/MTBlockEditor/php/block.mtblockeditorblockasset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

require_once('block.mtasset.php');

function smarty_block_mtblockeditorblockasset($args, $content, &$ctx, &$repeat)
{
if (!$content) {
$block = $ctx->stash('block_editor_block');
if (!$block || !in_array($block['type'], ['mt-image', 'mt-file']) || !$block['meta']['assetId']) {
return '';
}
return smarty_block_mtasset(['id' => $block['meta']['assetId']], $content, $ctx, $repeat);
}

return $content;
}
164 changes: 164 additions & 0 deletions plugins/MTBlockEditor/php/block.mtblockeditorblocks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php

function smarty_block_mtblockeditorblocks($args, $content, &$ctx, &$repeat)
{
$localvars = [
['block_editor_blocks', 'block_editor_blocks_counter', 'block_editor_block'],
['type', 'meta', ...common_loop_vars()]
];

if (!isset($content)) {
$ctx->localize($localvars);

$load_blocks_from_stash = false;
$name = isset($args['name'])
? $args['name'] : (isset($args['var']) ? $args['var'] : null);
if (isset($name)) {
unset($ctx->__stash['__cond_tag__']);

# pick off any {...} or [...] from the name.
if (preg_match('/^(.+)([\[\{])(.+)[\]\}]$/', $name, $matches)) {
$name = $matches[1];
$br = $matches[2];
$ref = $matches[3];
if (preg_match('/^\\\\\$(.+)/', $ref, $ref_matches)) {
$ref = $vars[$ref_matches[1]];
if (!isset($ref))
$ref = chr(0);
}
$br == '[' ? $index = $ref : $key = $ref;
} else {
if (array_key_exists('index', $args))
$index = $args['index'];
else if (array_key_exists('key', $args))
$key = $args['key'];
}
if (preg_match('/^$/', $name)) {
$name = $vars[$name];
if (!isset($name))
return $ctx->error($ctx->mt->translate(
"You used an [_1] tag without a valid name attribute.",
"<MT$tag>"
));
}
if (isset($name)) {
$value = isset($ctx->__stash['vars'][$name]) ? $ctx->__stash['vars'][$name] : null;
require_once("MTUtil.php");
if (is_hash($value)) {
if (isset($key)) {
if ($key != chr(0)) {
$val = isset($value[$key]) ? $value[$key] : null;
} else {
unset($value);
}
} else {
$val = $value;
}
} elseif (is_array($value)) {
if (isset($index)) {
if (is_numeric($index)) {
$val = isset($value[$index]) ? $value[$index] : null;
} else {
unset($value); # fall through to any 'default'
}
} else {
$val = $value;
}
} else {
$val = $value;
}
}
} elseif (isset($args['tag'])) {
$tag = $args['tag'];
$tag = preg_replace('/^mt:?/i', '', $tag);
$largs = $args; // local arguments without 'tag' element
unset($largs['tag']);

// Disable error handler temporarily
// for disabling trigger_error function.
set_error_handler('_dummy_error_handler');

try {
$val = $ctx->tag($tag, $largs);
} catch (exception $e) {
$val = '';
}

restore_error_handler();
} else {
$load_blocks_from_stash = true;
}

$blocks = [];
if (!$load_blocks_from_stash) {
if (!empty($value) && !is_array($value) && preg_match('/^smarty_fun_[a-f0-9]+$/', $value)) {
if (function_exists($val)) {
ob_start();
$val($ctx, array());
$val = ob_get_contents();
ob_end_clean();
} else {
$val = '';
}
}

if ($val) {
$parser = new MT\Plugin\MTBlockEditor\Parser();
$blocks = $parser->parse(['content' => $val]);
}
} else if ($ctx->stash('block_editor_block')) {
$blocks = $ctx->stash('block_editor_block')['blocks'];
}

$ctx->__stash['block_editor_blocks'] = $blocks;
$counter = 0;
} else {
$counter = $ctx->stash('block_editor_blocks_counter');
}

$blocks = $ctx->stash('block_editor_blocks');
if (empty($blocks)) {
$ret = $ctx->_hdlr_if($args, $content, $ctx, $repeat, 0);
if (!$repeat)
$ctx->restore($localvars);
return $ret;
}

if ($counter < count($blocks)) {
$block = $blocks[$counter];
if (!empty($block)) {
$value = $block['content'] ? join('', $block['content']) : '';

$count = $counter + 1;
$ctx->__stash['vars']['__counter__'] = $count;
$ctx->__stash['vars']['__odd__'] = ($count % 2) == 1;
$ctx->__stash['vars']['__even__'] = ($count % 2) == 0;
$ctx->__stash['vars']['__first__'] = $count == 1;
$ctx->__stash['vars']['__last__'] = ($count == count($blocks));
$ctx->__stash['vars']['__value__'] = $value;

$ctx->__stash['vars']['type'] = $block['type'];

$br_to_newline = fn ($str) => preg_replace('/<br\s*\/?>/i', "\n", $str);
if ($block['type'] == 'mt-image' && !isset($block['meta']['alt'])) {
preg_match('/alt=(["\'])(.*?)\1/i', $value, $matches);
$block['meta']['alt'] = isset($matches[2]) ? $matches[2] : "";
preg_match('/<figcaption>(.*?)<\/figcaption>/i', $value, $matches);
$block['meta']['caption'] = isset($matches[1]) ? $br_to_newline($matches[1]) : "";
} elseif ($block['type'] == 'mt-file' && !isset($block['meta']['text'])) {
preg_match('/<a[^>]*>(.*?)<\/a>/i', $value, $matches);
$block['meta']['text'] = isset($matches[1]) ? $br_to_newline($matches[1]) : "";
}
$ctx->__stash['vars']['meta'] = $block['meta'];

$ctx->stash('block_editor_block', $block);
$ctx->stash('block_editor_blocks_counter', $count);
$repeat = true;
}
} else {
$ctx->restore($localvars);
$repeat = false;
}

return $content;
}
Loading

0 comments on commit e4bd23f

Please sign in to comment.