| @@ -1,11 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | 2 | /* |
| 4 | - Plugin Name: Visualizer: Tables and Charts Manager for WordPress (Lite) | |
| 5 | - Plugin URI: https://themeisle.com/plugins/visualizer-charts-and-graphs-lite/ | |
| 6 | - Description: A simple, easy to use and quite powerful tool to create, manage and embed interactive charts into your WordPress posts and pages. The plugin uses Google Visualization API to render charts, which supports cross-browser compatibility (adopting VML for older IE versions) and cross-platform portability to iOS and new Android releases. | |
| 7 | - Version: 3.1.1 | |
| 3 | + Plugin Name: Visualizer: Tables and Charts for WordPress | |
| 4 | + Plugin URI: https://themeisle.com/plugins/visualizer-charts-and-graphs/ | |
| 5 | + Description: Effortlessly create and embed responsive charts and tables with Visualizer, a powerful WordPress plugin that enhances data presentation from multiple sources. | |
| 6 | + Version: 4.0.9 | |
| 8 | 7 | Author: Themeisle |
| 9 | 8 | Author URI: http://themeisle.com |
| 10 | 9 | License: GPL v2.0 or later |
| 11 | 10 | WordPress Available: yes |
| @@ -22,8 +21,10 @@ | ||
| 22 | 21 | // don't load the plugin, if it has been already loaded |
| 23 | 22 | if ( class_exists( 'Visualizer_Plugin', false ) ) { |
| 24 | 23 | return; |
| 25 | 24 | } |
| 25 | + | |
| 26 | +// support for pro versions before 3.3.0 | |
| 26 | 27 | if ( class_exists( 'Visualizer_Pro', false ) ) { |
| 27 | 28 | define( 'VISUALIZER_PRO', true ); |
| 28 | 29 | } else { |
| 29 | 30 | defined( 'VISUALIZER_PRO' ) || define( 'VISUALIZER_PRO', false ); |
| @@ -34,17 +35,17 @@ | ||
| 34 | 35 | * approved classes. |
| 35 | 36 | * |
| 36 | 37 | * @since 1.0.0 |
| 37 | 38 | * |
| 38 | - * @param string $class The class name to autoload. | |
| 39 | + * @param string $class_name The class name to autoload. | |
| 39 | 40 | * |
| 40 | 41 | * @return boolean Returns TRUE if the class is located. Otherwise FALSE. |
| 41 | 42 | */ |
| 42 | -function visualizer_autoloader( $class ) { | |
| 43 | +function visualizer_autoloader( $class_name ) { | |
| 43 | 44 | $namespaces = array( 'Visualizer' ); |
| 44 | 45 | foreach ( $namespaces as $namespace ) { |
| 45 | - if ( substr( $class, 0, strlen( $namespace ) ) == $namespace ) { | |
| 46 | - $filename = dirname( __FILE__ ) . str_replace( '_', DIRECTORY_SEPARATOR, "_classes_{$class}.php" ); | |
| 46 | + if ( substr( $class_name, 0, strlen( $namespace ) ) === $namespace ) { | |
| 47 | + $filename = __DIR__ . str_replace( '_', DIRECTORY_SEPARATOR, "_classes_{$class_name}.php" ); | |
| 47 | 48 | if ( is_readable( $filename ) ) { |
| 48 | 49 | require $filename; |
| 49 | 50 | |
| 50 | 51 | return true; |
| @@ -62,13 +63,18 @@ | ||
| 62 | 63 | */ |
| 63 | 64 | function visualizer_launch() { |
| 64 | 65 | // setup environment |
| 65 | 66 | define( 'VISUALIZER_BASEFILE', __FILE__ ); |
| 67 | + define( 'VISUALIZER_BASENAME', plugin_basename( __FILE__ ) ); | |
| 66 | 68 | define( 'VISUALIZER_ABSURL', plugins_url( '/', __FILE__ ) ); |
| 67 | - define( 'VISUALIZER_ABSPATH', dirname( __FILE__ ) ); | |
| 69 | + define( 'VISUALIZER_ABSPATH', __DIR__ ); | |
| 70 | + define( 'VISUALIZER_DIRNAME', basename( VISUALIZER_ABSPATH ) ); | |
| 68 | 71 | define( 'VISUALIZER_REST_VERSION', 1 ); |
| 69 | 72 | // if the below is true, then the js/customization.js in the plugin folder will be used instead of the one in the uploads folder (if it exists). |
| 70 | - define( 'VISUALIZER_TEST_JS_CUSTOMIZATION', false ); | |
| 73 | + // this is also used in Block.php | |
| 74 | + if ( ! defined( 'VISUALIZER_TEST_JS_CUSTOMIZATION' ) ) { | |
| 75 | + define( 'VISUALIZER_TEST_JS_CUSTOMIZATION', false ); | |
| 76 | + } | |
| 71 | 77 | |
| 72 | 78 | if ( ! defined( 'VISUALIZER_CSV_DELIMITER' ) ) { |
| 73 | 79 | define( 'VISUALIZER_CSV_DELIMITER', ',' ); |
| 74 | 80 | } |
| @@ -85,9 +91,18 @@ | ||
| 85 | 91 | define( 'VISUALIZER_ENABLE_BETA_FEATURES', '' ); |
| 86 | 92 | |
| 87 | 93 | // the link to pre-build queries. |
| 88 | 94 | define( 'VISUALIZER_DB_QUERY_DOC_URL', 'https://docs.themeisle.com/article/970-visualizer-sample-queries-to-generate-charts' ); |
| 95 | + define( 'VISUALIZER_MAIN_DOC', 'https://docs.themeisle.com/category/657-visualizer' ); | |
| 96 | + define( 'VISUALIZER_DOC_COLLECTION', 'https://docs.themeisle.com/visualizer-charts-and-graphs/?query=#' ); | |
| 97 | + define( 'VISUALIZER_DEMO_URL', 'https://demo.themeisle.com/visualizer/#' ); | |
| 98 | + define( 'VISUALIZER_CODE_SNIPPETS_URL', 'https://docs.themeisle.com/category/726-visualizer' ); | |
| 99 | + define( 'VISUALIZER_SUBSCRIBE_API', 'https://api.themeisle.com/tracking/subscribe' ); | |
| 100 | + define( 'VISUALIZER_AGENTS_URL', 'https://ai.themeisle.com' ); | |
| 89 | 101 | |
| 102 | + // to redirect all themeisle_log_event to error log. | |
| 103 | + define( 'VISUALIZER_LOCAL_DEBUG', false ); | |
| 104 | + | |
| 90 | 105 | // instantiate the plugin |
| 91 | 106 | $plugin = Visualizer_Plugin::instance(); |
| 92 | 107 | |
| 93 | 108 | // instantiate Gutenberg block |
| @@ -97,12 +112,24 @@ | ||
| 97 | 112 | Visualizer_Gutenberg_Block::get_instance(); |
| 98 | 113 | }} |
| 99 | 114 | ); |
| 100 | 115 | |
| 116 | + // register Elementor widget and related hooks | |
| 117 | + // Use elementor/init so Elementor's autoloader is registered and Widget_Base is resolvable. | |
| 118 | + add_action( | |
| 119 | + 'elementor/init', | |
| 120 | + function () { | |
| 121 | + require_once VISUALIZER_ABSPATH . '/classes/Visualizer/Elementor/Widget.php'; | |
| 122 | + Visualizer_Elementor_Widget::register_hooks(); | |
| 123 | + } | |
| 124 | + ); | |
| 125 | + | |
| 101 | 126 | // set general modules |
| 127 | + $plugin->setModule( Visualizer_Module_Utility::NAME ); | |
| 102 | 128 | $plugin->setModule( Visualizer_Module_Setup::NAME ); |
| 103 | 129 | $plugin->setModule( Visualizer_Module_Sources::NAME ); |
| 104 | 130 | $plugin->setModule( Visualizer_Module_Chart::NAME ); |
| 131 | + | |
| 105 | 132 | if ( is_admin() || defined( 'WP_TESTS_DOMAIN' ) ) { |
| 106 | 133 | // set admin modules |
| 107 | 134 | $plugin->setModule( Visualizer_Module_Admin::NAME ); |
| 108 | 135 | } |
| @@ -109,17 +136,126 @@ | ||
| 109 | 136 | |
| 110 | 137 | // set frontend modules |
| 111 | 138 | $plugin->setModule( Visualizer_Module_Frontend::NAME ); |
| 112 | 139 | |
| 113 | - $vendor_file = VISUALIZER_ABSPATH . '/vendor/autoload_52.php'; | |
| 140 | + $plugin->setModule( Visualizer_Module_AMP::NAME ); | |
| 141 | + | |
| 142 | + // Set setup wizard module. | |
| 143 | + $plugin->setModule( Visualizer_Module_Wizard::NAME ); | |
| 144 | + | |
| 145 | + // AI Chart Builder module (AJAX endpoints for the React wizard). | |
| 146 | + $plugin->setModule( Visualizer_Module_AIBuilder::NAME ); | |
| 147 | + | |
| 148 | + // Abilities API integration (no-op when the API is not available). | |
| 149 | + $plugin->setModule( Visualizer_Module_Abilities::NAME ); | |
| 150 | + | |
| 151 | + $vendor_file = VISUALIZER_ABSPATH . '/vendor/autoload.php'; | |
| 114 | 152 | if ( is_readable( $vendor_file ) ) { |
| 115 | - include_once( $vendor_file ); | |
| 153 | + include_once $vendor_file; | |
| 116 | 154 | } |
| 155 | + | |
| 156 | + $action_scheduler_file = VISUALIZER_ABSPATH . '/vendor/woocommerce/action-scheduler/action-scheduler.php'; | |
| 157 | + | |
| 158 | + if ( visualizer_can_use_action_scheduler() && is_readable( $action_scheduler_file ) ) { | |
| 159 | + require_once $action_scheduler_file; | |
| 160 | + } | |
| 161 | + | |
| 117 | 162 | add_filter( 'themeisle_sdk_products', 'visualizer_register_sdk', 10, 1 ); |
| 118 | 163 | add_filter( 'pirate_parrot_log', 'visualizer_register_parrot', 10, 1 ); |
| 164 | + add_filter( | |
| 165 | + 'themeisle_sdk_compatibilities/' . VISUALIZER_DIRNAME, function ( $compatibilities ) { | |
| 166 | + $compatibilities['VisualizerPRO'] = array( | |
| 167 | + 'basefile' => defined( 'VISUALIZER_PRO_BASEFILE' ) ? VISUALIZER_PRO_BASEFILE : '', | |
| 168 | + 'required' => '1.8', | |
| 169 | + 'tested_up' => '2.0', | |
| 170 | + ); | |
| 171 | + return $compatibilities; | |
| 172 | + } | |
| 173 | + ); | |
| 174 | + add_filter( | |
| 175 | + 'visualizer_about_us_metadata', | |
| 176 | + function () { | |
| 177 | + return array( | |
| 178 | + 'logo' => esc_url( VISUALIZER_ABSURL . 'images/visualizer-logo.svg' ), | |
| 179 | + 'location' => 'visualizer', | |
| 180 | + 'has_upgrade_menu' => ! Visualizer_Module::is_pro(), | |
| 181 | + 'upgrade_text' => esc_html__( 'Get Visualizer Pro', 'visualizer' ), | |
| 182 | + 'upgrade_link' => esc_url( tsdk_utmify( Visualizer_Plugin::PRO_TEASER_URL, 'sidebarMenuUpgrade', 'index' ) ), | |
| 183 | + ); | |
| 184 | + } | |
| 185 | + ); | |
| 186 | + add_filter( | |
| 187 | + 'visualizer_ai_connect_metadata', | |
| 188 | + function () { | |
| 189 | + return array( | |
| 190 | + 'name' => 'Visualizer', | |
| 191 | + 'notice_cases' => array( | |
| 192 | + __( 'build a chart from your numbers', 'visualizer' ), | |
| 193 | + __( 'update a table with new data', 'visualizer' ), | |
| 194 | + __( 'refresh charts from their data source', 'visualizer' ), | |
| 195 | + ), | |
| 196 | + 'prompts' => array( | |
| 197 | + __( 'Create a Visualizer pie chart "Traffic by channel" with Organic 5400, Direct 2100 and Social 1300, and add it to my Analytics page.', 'visualizer' ), | |
| 198 | + __( 'Refresh every chart that pulls from a remote CSV, JSON or database source.', 'visualizer' ), | |
| 199 | + __( 'Change my "Monthly sales" chart to a bar chart and add September: 12,400.', 'visualizer' ), | |
| 200 | + ), | |
| 201 | + 'ability_prefix' => 'visualizer', | |
| 202 | + ); | |
| 203 | + } | |
| 204 | + ); | |
| 205 | + | |
| 206 | + if ( ! defined( 'TI_E2E_TESTING' ) && 'yes' === get_option( 'visualizer_logger_flag', 'no' ) ) { | |
| 207 | + add_filter( 'themeisle_sdk_enable_telemetry', '__return_true' ); | |
| 208 | + add_filter( | |
| 209 | + 'themeisle_sdk_telemetry_products', | |
| 210 | + function ( $products ) { | |
| 211 | + $already_registered = false; | |
| 212 | + | |
| 213 | + $license = get_option( 'visualizer_pro_license_data', 'free' ); | |
| 214 | + if ( ! empty( $license ) && is_object( $license ) ) { | |
| 215 | + $license = $license->key ?? 'free'; | |
| 216 | + } | |
| 217 | + $track_hash = 'free' === $license ? 'free' : wp_hash( $license ); | |
| 218 | + | |
| 219 | + foreach ( $products as &$product ) { | |
| 220 | + if ( strstr( $product['slug'], 'visualizer' ) !== false ) { | |
| 221 | + $already_registered = true; | |
| 222 | + $product['trackHash'] = $track_hash; | |
| 223 | + } | |
| 224 | + } | |
| 225 | + | |
| 226 | + if ( $already_registered ) { | |
| 227 | + return $products; | |
| 228 | + } | |
| 229 | + | |
| 230 | + // Add Visualizer to the list of products to track the usage of AI Block. | |
| 231 | + $products[] = array( | |
| 232 | + 'slug' => 'visualizer', | |
| 233 | + 'consent' => 'yes' === get_option( 'visualizer_logger_flag', 'no' ), | |
| 234 | + 'trackHash' => $track_hash, | |
| 235 | + ); | |
| 236 | + return $products; | |
| 237 | + } | |
| 238 | + ); | |
| 239 | + } | |
| 119 | 240 | } |
| 120 | 241 | |
| 121 | 242 | /** |
| 243 | + * Whether the bundled Action Scheduler can run against this wpdb. | |
| 244 | + * | |
| 245 | + * The bundled library calls wpdb::db_server_info() unguarded when it claims a | |
| 246 | + * queue batch, and core only added that method in WordPress 5.5. Loading it | |
| 247 | + * without the method available fatals, so those sites stay on WP-Cron instead. | |
| 248 | + * | |
| 249 | + * @return bool | |
| 250 | + */ | |
| 251 | +function visualizer_can_use_action_scheduler() { | |
| 252 | + global $wpdb; | |
| 253 | + | |
| 254 | + return isset( $wpdb ) && is_callable( array( $wpdb, 'db_server_info' ) ); | |
| 255 | +} | |
| 256 | + | |
| 257 | +/** | |
| 122 | 258 | * Registers with the SDK |
| 123 | 259 | * |
| 124 | 260 | * @since 1.0.0 |
| 125 | 261 | */ |
| @@ -141,4 +277,18 @@ | ||
| 141 | 277 | // register autoloader function |
| 142 | 278 | spl_autoload_register( 'visualizer_autoloader' ); |
| 143 | 279 | // launch the plugin |
| 144 | 280 | visualizer_launch(); |
| 281 | + | |
| 282 | + | |
| 283 | +if ( VISUALIZER_LOCAL_DEBUG ) { | |
| 284 | + add_action( 'themeisle_log_event', 'visualizer_themeisle_log_event', 10, 5 ); | |
| 285 | + | |
| 286 | + /** | |
| 287 | + * Redirect themeisle_log_event to error log. | |
| 288 | + */ | |
| 289 | + function visualizer_themeisle_log_event( $name, $msg, $type, $file, $line ) { | |
| 290 | + if ( $name === Visualizer_Plugin::NAME ) { | |
| 291 | + error_log( sprintf( '%s (%s:%d): %s', $type, $file, $line, $msg ) ); | |
| 292 | + } | |
| 293 | + } | |
| 294 | +} | |