PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.9.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.9.1
2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 All 80 releases
ablocks / includes / frontend / dynamic-content / interpreter.php

interpreter.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.9.1, at includes/frontend/dynamic-content/interpreter.php

55 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Frontend\DynamicContent;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7 class Interpreter {
8
9 protected array $interpreters = [
10 'post-type' => Interpreters\PostType::class,
11 'current' => Interpreters\CurrentPost::class,
12 'current-date-time' => Interpreters\CurrentDateTime::class,
13 'site-title' => Interpreters\SiteTitle::class,
14 'site-tagline' => Interpreters\SiteTagline::class,
15 'user-info' => Interpreters\UserInfo::class,
16 'request-parameter' => Interpreters\RequestParams::class,
17 'shortcode' => Interpreters\Shortcode::class,
18 'link' => Interpreters\Link::class,
19 'image' => Interpreters\Image::class,
20 ];
21 protected string $content;
22 public function __construct( string $content ) {
23 $this->content = $content;
24 $this->parse();// exit;
25 }
26 public function parse() : void {
27 $this->content = preg_replace_callback(
28 '~ablocks_dc:(.+?):ablocks_dc|<span\s+(?=[^>]*\bclass=["\']ablocks-richtext-dynamic-content["\'])(?=[^>]*\bdata-source=["\']([^"\']+)["\'])(?=[^>]*\bdata-field=["\']([^"\']+)["\'])[^>]*>(.*?)<\/span>~ims',
29 [ $this, 'apply_changes' ],
30 $this->content
31 );
32 }
33 public function apply_changes( array $matches ) : string {
34 return is_null( $ins = ( new ArgumentParser( ...$this->filter( $matches ), ...[ $this->interpreters ] ) )->interpret() ) ? '' : $ins->content();
35 }
36
37 public function filter( array $matches ) : array {
38 $is_richtext = false;
39 array_shift( $matches );
40 if ( count( $matches ) > 2 ) {
41 array_shift( $matches );
42 $is_richtext = true;
43 }
44 return [
45 implode( '|', $matches ),
46 $is_richtext
47 ];
48 }
49
50 public static function init( string $content ) : string {
51 $ins = new self( $content );
52 return $ins->content;
53 }
54 }
55