| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | /** |
| 4 | 4 | * Plugin Name: Tableberg |
| 5 | 5 | * Plugin URI: https://tableberg.com/ |
| 6 | 6 | * Description: Table Block by Tableberg - Create Better Tables With Block Editor |
| 7 | - * Version: 0.5.2 | |
| 7 | + * Version: 1.1.5 | |
| 8 | 8 | * Requires at least: 6.1 |
| 9 | 9 | * Requires PHP: 7.0 |
| 10 | 10 | * Author: Tableberg |
| 11 | 11 | * Author URI: https://tableberg.com/ |
| @@ -16,118 +16,133 @@ | ||
| 16 | 16 | * @package Tableberg |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('ABSPATH')) { |
| 20 | - exit; // Exit if accessed directly. | |
| 20 | + exit; | |
| 21 | 21 | } |
| 22 | 22 | if (!defined('TABLEBERG_VERSION')) { |
| 23 | - define('TABLEBERG_VERSION', '0.0.2'); | |
| 23 | + define('TABLEBERG_VERSION', '1.1.5'); | |
| 24 | 24 | } |
| 25 | 25 | if (!defined('TABLEBERG_DIR_PATH')) { |
| 26 | - define('TABLEBERG_DIR_PATH', plugin_dir_path(__FILE__)); | |
| 26 | + define('TABLEBERG_DIR_PATH', plugin_dir_path(__FILE__)); | |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | if (!defined('TABLEBERG_URL')) { |
| 30 | - define('TABLEBERG_URL', plugin_dir_url(__FILE__)); | |
| 30 | + define('TABLEBERG_URL', plugin_dir_url(__FILE__)); | |
| 31 | 31 | } |
| 32 | 32 | if (!defined('TABLEBERG_PLUGIN_FILE')) { |
| 33 | - define('TABLEBERG_PLUGIN_FILE', __FILE__); | |
| 33 | + define('TABLEBERG_PLUGIN_FILE', __FILE__); | |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | require_once __DIR__ . '/vendor/autoload.php'; |
| 37 | +require_once __DIR__ . '/renderer/utils.php'; | |
| 37 | 38 | |
| 38 | - | |
| 39 | 39 | if (!function_exists('tab_fs')) { |
| 40 | - // Create a helper function for easy SDK access. | |
| 41 | - function tab_fs() { | |
| 42 | - global $tab_fs; | |
| 40 | + function tab_fs() { | |
| 41 | + global $tab_fs; | |
| 43 | 42 | |
| 44 | - if (!isset($tab_fs)) { | |
| 45 | - // Include Freemius SDK. | |
| 46 | - require_once __DIR__ . '/includes/freemius/start.php'; | |
| 43 | + if (!isset($tab_fs)) { | |
| 44 | + require_once __DIR__ . '/vendor/freemius/start.php'; | |
| 47 | 45 | |
| 48 | - $tab_fs = fs_dynamic_init(array( | |
| 49 | - 'id' => '14649', | |
| 50 | - 'slug' => 'tableberg', | |
| 51 | - 'type' => 'plugin', | |
| 52 | - 'public_key' => 'pk_8043aa788c004c4b385af8384c74b', | |
| 53 | - 'is_premium' => false, | |
| 54 | - 'has_addons' => true, | |
| 55 | - 'has_paid_plans' => false, | |
| 56 | - 'menu' => array( | |
| 57 | - 'slug' => 'tableberg-settings', | |
| 58 | - 'first-path' => 'admin.php?page=tableberg-settings&route=welcome', | |
| 59 | - ), | |
| 60 | - )); | |
| 61 | - } | |
| 46 | + $tab_fs = fs_dynamic_init( | |
| 47 | + [ | |
| 48 | + 'id' => '14649', | |
| 49 | + 'slug' => 'tableberg', | |
| 50 | + 'type' => 'plugin', | |
| 51 | + 'public_key' => 'pk_8043aa788c004c4b385af8384c74b', | |
| 52 | + 'is_premium' => false, | |
| 53 | + 'has_addons' => true, | |
| 54 | + 'has_paid_plans' => false, | |
| 55 | + 'is_org_compliant' => true, | |
| 56 | + 'menu' => [ | |
| 57 | + 'slug' => 'tableberg-settings', | |
| 58 | + 'first-path' => 'admin.php?page=tableberg-settings&route=welcome', | |
| 59 | + ], | |
| 60 | + ] | |
| 61 | + ); | |
| 62 | + } | |
| 62 | 63 | |
| 63 | - return $tab_fs; | |
| 64 | - } | |
| 64 | + return $tab_fs; | |
| 65 | + } | |
| 65 | 66 | |
| 66 | - // Init Freemius. | |
| 67 | - tab_fs(); | |
| 68 | - // Signal that SDK was initiated. | |
| 69 | - do_action('tab_fs_loaded'); | |
| 67 | + tab_fs(); | |
| 68 | + do_action('tab_fs_loaded'); | |
| 70 | 69 | } |
| 71 | 70 | |
| 71 | +use Tableberg\Constants; | |
| 72 | +use Tableberg\Renderer\Migrations\BlockContentMigrator; | |
| 73 | +use Tableberg\Renderer\Table\TableRenderer; | |
| 74 | +use Tableberg\Renderer\ToggleBlockRenderer; | |
| 72 | 75 | |
| 73 | 76 | if (!class_exists('Tableberg')) { |
| 74 | - /** | |
| 75 | - * External Query Block main class. | |
| 76 | - */ | |
| 77 | - class Tableberg { | |
| 77 | + class Tableberg { | |
| 78 | + public function __construct() { | |
| 79 | + new Tableberg\Admin\Tableberg_Admin(); | |
| 80 | + add_action('init', [$this, 'register_blocks']); | |
| 81 | + add_action( | |
| 82 | + 'enqueue_block_editor_assets', | |
| 83 | + [$this, 'localize_block_editor_assets'] | |
| 84 | + ); | |
| 85 | + add_action('wp_enqueue_scripts', [$this, 'localize_frontend_assets']); | |
| 78 | 86 | |
| 87 | + $restController = new Tableberg\DynamicData\RestController(); | |
| 88 | + add_action('rest_api_init', [$restController, 'register_routes']); | |
| 79 | 89 | |
| 80 | - /** | |
| 81 | - * Constructor. | |
| 82 | - * | |
| 83 | - * @return void | |
| 84 | - */ | |
| 85 | - public function __construct() { | |
| 86 | - new Tableberg\Admin\Tableberg_Admin(); | |
| 87 | - new Tableberg\Blocks\Button(); | |
| 88 | - new Tableberg\Blocks\Image(); | |
| 89 | - new Tableberg\Blocks\Table(); | |
| 90 | - new Tableberg\Blocks\Cell(); | |
| 90 | + $migrator = new BlockContentMigrator(); | |
| 91 | + add_action('rest_api_init', [$migrator, 'register_rest_hooks']); | |
| 92 | + add_filter('render_block_data', [$migrator, 'migrate_parsed_block']); | |
| 91 | 93 | |
| 92 | - $pro_activated = false; | |
| 94 | + register_activation_hook(__FILE__, [$this, 'activate_plugin']); | |
| 95 | + register_deactivation_hook(__FILE__, [$this, 'deactivate_plugin']); | |
| 96 | + } | |
| 93 | 97 | |
| 94 | - global $tp_fs; | |
| 98 | + public function localize_block_editor_assets() { | |
| 99 | + $assets = new \Tableberg\Assets(); | |
| 100 | + $assets->register_blocks_assets(); | |
| 101 | + } | |
| 95 | 102 | |
| 96 | - if (isset($tp_fs)) { | |
| 97 | - $pro_activated = $tp_fs->is__premium_only() | |
| 98 | - && $tp_fs->can_use_premium_code(); | |
| 99 | - } | |
| 103 | + public function localize_frontend_assets() { | |
| 104 | + $assets = new \Tableberg\Assets(); | |
| 105 | + $assets->register_frontend_assets(); | |
| 106 | + } | |
| 100 | 107 | |
| 101 | - if (!$pro_activated) { | |
| 102 | - add_action('init', function() { | |
| 103 | - register_block_type(TABLEBERG_DIR_PATH . 'src/upsells-blocks/styled-list-dummy/block.json'); | |
| 104 | - register_block_type(TABLEBERG_DIR_PATH . 'src/upsells-blocks/html-dummy/block.json'); | |
| 105 | - register_block_type(TABLEBERG_DIR_PATH . 'src/upsells-blocks/icon-dummy/block.json'); | |
| 106 | - register_block_type(TABLEBERG_DIR_PATH . 'src/upsells-blocks/ribbon-dummy/block.json'); | |
| 107 | - register_block_type(TABLEBERG_DIR_PATH . 'src/upsells-blocks/star-rating-dummy/block.json'); | |
| 108 | - }); | |
| 109 | - } | |
| 108 | + public function register_blocks() { | |
| 109 | + $renderer = new TableRenderer(); | |
| 110 | 110 | |
| 111 | - register_activation_hook(__FILE__, array($this, 'activate_plugin')); | |
| 112 | - register_deactivation_hook(__FILE__, array($this, 'deactivate_plugin')); | |
| 113 | - } | |
| 111 | + register_block_type_from_metadata( | |
| 112 | + TABLEBERG_DIR_PATH . 'build/blocks/table/block.json', | |
| 113 | + [ | |
| 114 | + 'render_callback' => [$renderer, 'render'], | |
| 115 | + ] | |
| 116 | + ); | |
| 114 | 117 | |
| 115 | - /** | |
| 116 | - * The code that runs during plugin activation. | |
| 117 | - * This action is documented in includes/Activator.php | |
| 118 | - */ | |
| 119 | - public function activate_plugin() { | |
| 120 | - Tableberg\Activator::activate(); | |
| 121 | - } | |
| 118 | + $toggleBlockRenderer = new ToggleBlockRenderer(); | |
| 122 | 119 | |
| 123 | - /** | |
| 124 | - * The code that runs during plugin deactivation. | |
| 125 | - * This action is documented in includes/Deactivator.php | |
| 126 | - */ | |
| 127 | - public function deactivate_plugin() { | |
| 128 | - Tableberg\Deactivator::deactivate(); | |
| 129 | - } | |
| 130 | - } | |
| 120 | + register_block_type_from_metadata( | |
| 121 | + TABLEBERG_DIR_PATH . 'build/blocks/toggle/block.json', | |
| 122 | + [ | |
| 123 | + 'render_callback' => [ | |
| 124 | + $toggleBlockRenderer, 'render', | |
| 125 | + ], | |
| 126 | + ] | |
| 127 | + ); | |
| 128 | + } | |
| 131 | 129 | |
| 132 | - new Tableberg(); | |
| 130 | + public function activate_plugin() { | |
| 131 | + set_transient('_welcome_redirect_tableberg', true, 60); | |
| 132 | + | |
| 133 | + update_option('tableberg_version', TABLEBERG_VERSION); | |
| 134 | + update_option('tableberg_installDate', date('Y-m-d h:i:s')); | |
| 135 | + | |
| 136 | + add_option('tableberg_review_notify', 'no'); | |
| 137 | + } | |
| 138 | + | |
| 139 | + public function deactivate_plugin() { | |
| 140 | + delete_transient('_welcome_redirect_tableberg'); | |
| 141 | + | |
| 142 | + delete_option('tableberg_version'); | |
| 143 | + delete_option('tableberg_installDate'); | |
| 144 | + } | |
| 145 | + } | |
| 146 | + | |
| 147 | + new Tableberg(); | |
| 133 | 148 | } |