-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,015 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
...ins/MTBlockEditor/dist/mt-block-editor-block-oembed/1.0.4/mt-block-editor-block-oembed.js
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...MTBlockEditor/dist/mt-block-editor-block-oembed/1.0.4/mt-block-editor-block-oembed.js.map
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
...ins/MTBlockEditor/dist/mt-block-editor-block-oembed/1.0.5/mt-block-editor-block-oembed.js
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
1 change: 1 addition & 0 deletions
1
...MTBlockEditor/dist/mt-block-editor-block-oembed/1.0.5/mt-block-editor-block-oembed.js.map
Large diffs are not rendered by default.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
mt-static/plugins/MTBlockEditor/dist/mt-block-editor/1.1.45/mt-block-editor.js
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
mt-static/plugins/MTBlockEditor/dist/mt-block-editor/1.1.45/mt-block-editor.js.map
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions
9
mt-static/plugins/MTBlockEditor/dist/mt-block-editor/1.1.50/mt-block-editor.js
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
1 change: 1 addition & 0 deletions
1
mt-static/plugins/MTBlockEditor/dist/mt-block-editor/1.1.50/mt-block-editor.js.map
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
plugins/MTBlockEditor/php/block.mtblockeditorblockasset.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
164
plugins/MTBlockEditor/php/block.mtblockeditorblocks.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.