About_us.php
3 weeks ago
Abstract_Migration.php
2 months ago
Announcements.php
2 months ago
Compatibilities.php
2 years ago
Dashboard_widget.php
3 weeks ago
Featured_plugins.php
1 month ago
Float_widget.php
1 year ago
Licenser.php
2 months ago
Logger.php
10 months ago
Migrator.php
2 months ago
Notification.php
3 years ago
Promotions.php
3 weeks ago
Recommendation.php
3 years ago
Review.php
1 year ago
Rollback.php
1 year ago
Script_loader.php
1 year ago
Translate.php
5 years ago
Translations.php
1 year ago
Uninstall_feedback.php
2 days ago
Welcome.php
2 years ago
About_us.php
455 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The about page model class for ThemeIsle SDK |
| 4 | * |
| 5 | * Here's how to hook it in your plugin: |
| 6 | * |
| 7 | * add_filter( <product_slug>_about_us_metadata', 'add_about_meta' ); |
| 8 | * |
| 9 | * function add_about_meta($data) { |
| 10 | * return [ |
| 11 | * 'location' => <top level page - e.g. themes.php>, |
| 12 | * 'logo' => <logo url>, |
| 13 | * 'page_menu' => [['text' => '', 'url' => '']], // optional |
| 14 | * 'has_upgrade_menu' => <condition>, |
| 15 | * 'upgrade_link' => <url>, |
| 16 | * 'upgrade_text' => 'Get Pro Version', |
| 17 | * 'review_link' => false, // Leave it empty for default WPorg link or false to hide it. |
| 18 | * ] |
| 19 | * } |
| 20 | * |
| 21 | * @package ThemeIsleSDK |
| 22 | * @subpackage Modules |
| 23 | * @copyright Copyright (c) 2023, Andrei Baicus |
| 24 | * @license http://opensource.org/licenses/gpl-3.0.php GNU Public License |
| 25 | * @since 3.2.42 |
| 26 | */ |
| 27 | |
| 28 | namespace ThemeisleSDK\Modules; |
| 29 | |
| 30 | use ThemeisleSDK\Common\Abstract_Module; |
| 31 | use ThemeisleSDK\Loader; |
| 32 | use ThemeisleSDK\Product; |
| 33 | |
| 34 | // Exit if accessed directly. |
| 35 | if ( ! defined( 'ABSPATH' ) ) { |
| 36 | exit; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Promotions module for ThemeIsle SDK. |
| 41 | */ |
| 42 | class About_Us extends Abstract_Module { |
| 43 | /** |
| 44 | * About data. |
| 45 | * |
| 46 | * @var array $about_data About page data, received from the filter. |
| 47 | * |
| 48 | * Shape of the $about_data property array: |
| 49 | * [ |
| 50 | * 'location' => 'top level page', |
| 51 | * 'logo' => 'logo path', |
| 52 | * 'page_menu' => [['text' => '', 'url' => '']], // Optional |
| 53 | * 'has_upgrade_menu' => !defined('NEVE_PRO_VERSION'), |
| 54 | * 'upgrade_link' => 'upgrade url', |
| 55 | * 'upgrade_text' => 'Get Pro Version', |
| 56 | * ] |
| 57 | */ |
| 58 | private $about_data = array(); |
| 59 | |
| 60 | /** |
| 61 | * Should we load this module. |
| 62 | * |
| 63 | * @param Product $product Product object. |
| 64 | * |
| 65 | * @return bool |
| 66 | */ |
| 67 | public function can_load( $product ) { |
| 68 | if ( $this->is_from_partner( $product ) ) { |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | $this->about_data = apply_filters( $product->get_key() . '_about_us_metadata', array() ); |
| 73 | |
| 74 | return ! empty( $this->about_data ); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Registers the hooks. |
| 79 | * |
| 80 | * @param Product $product Product to load. |
| 81 | */ |
| 82 | public function load( $product ) { |
| 83 | $this->product = $product; |
| 84 | |
| 85 | add_action( 'admin_menu', [ $this, 'add_submenu_pages' ] ); |
| 86 | add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_about_page_script' ] ); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Adds submenu pages. |
| 91 | * |
| 92 | * @return void |
| 93 | */ |
| 94 | public function add_submenu_pages() { |
| 95 | if ( ! isset( $this->about_data['location'] ) ) { |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | // Refresh the about data to get the latest changes. |
| 100 | $this->about_data = apply_filters( $this->product->get_key() . '_about_us_metadata', array() ); |
| 101 | |
| 102 | add_submenu_page( |
| 103 | $this->about_data['location'], |
| 104 | Loader::$labels['about_us']['title'], |
| 105 | Loader::$labels['about_us']['title'], |
| 106 | 'manage_options', |
| 107 | $this->get_about_page_slug(), |
| 108 | array( $this, 'render_about_us_page' ), |
| 109 | 100 |
| 110 | ); |
| 111 | |
| 112 | if ( ! isset( $this->about_data['has_upgrade_menu'] ) ) { |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | if ( $this->about_data['has_upgrade_menu'] !== true ) { |
| 117 | return; |
| 118 | } |
| 119 | |
| 120 | if ( ! isset( $this->about_data['upgrade_link'] ) ) { |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | if ( ! isset( $this->about_data['upgrade_text'] ) ) { |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | add_submenu_page( |
| 129 | $this->about_data['location'], |
| 130 | $this->about_data['upgrade_text'], |
| 131 | '<span class="tsdk-upg-menu-item">' . $this->about_data['upgrade_text'] . '</span>', |
| 132 | 'manage_options', |
| 133 | $this->about_data['upgrade_link'], |
| 134 | '', |
| 135 | 101 |
| 136 | ); |
| 137 | add_action( |
| 138 | 'admin_footer', |
| 139 | function () { |
| 140 | ?> |
| 141 | <style> |
| 142 | .tsdk-upg-menu-item { |
| 143 | color: #009528; |
| 144 | } |
| 145 | |
| 146 | .tsdk-upg-menu-item:hover { |
| 147 | color: #008a20; |
| 148 | } |
| 149 | </style> |
| 150 | <script type="text/javascript"> |
| 151 | jQuery(document).ready(function ($) { |
| 152 | $('.tsdk-upg-menu-item').parent().attr('target', '_blank'); |
| 153 | }); |
| 154 | </script> |
| 155 | <?php |
| 156 | } |
| 157 | ); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Render page content. |
| 162 | * |
| 163 | * @return void |
| 164 | */ |
| 165 | public function render_about_us_page() { |
| 166 | echo '<div id="ti-sdk-about"></div>'; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Enqueue scripts & styles. |
| 171 | * |
| 172 | * @return void |
| 173 | */ |
| 174 | public function enqueue_about_page_script() { |
| 175 | $current_screen = get_current_screen(); |
| 176 | |
| 177 | if ( ! isset( $current_screen->id ) ) { |
| 178 | return; |
| 179 | } |
| 180 | |
| 181 | if ( strpos( $current_screen->id, $this->get_about_page_slug() ) === false ) { |
| 182 | return; |
| 183 | } |
| 184 | global $themeisle_sdk_max_path; |
| 185 | $handle = 'ti-sdk-about-' . $this->product->get_key(); |
| 186 | $asset_file = require $themeisle_sdk_max_path . '/assets/js/build/about/about.asset.php'; |
| 187 | $deps = array_merge( $asset_file['dependencies'], [ 'updates' ] ); |
| 188 | |
| 189 | do_action( 'themeisle_internal_page', $this->product->get_slug(), 'about_us' ); |
| 190 | |
| 191 | wp_register_script( $handle, $this->get_sdk_uri() . 'assets/js/build/about/about.js', $deps, $asset_file['version'], true ); |
| 192 | wp_localize_script( $handle, 'tiSDKAboutData', $this->get_about_localization_data() ); |
| 193 | |
| 194 | wp_enqueue_script( $handle ); |
| 195 | wp_enqueue_style( $handle, $this->get_sdk_uri() . 'assets/js/build/about/about.css', [ 'wp-components' ], $asset_file['version'] ); |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Get localized data. |
| 200 | * |
| 201 | * @return array |
| 202 | */ |
| 203 | private function get_about_localization_data() { |
| 204 | $links = isset( $this->about_data['page_menu'] ) ? $this->about_data['page_menu'] : []; |
| 205 | $product_pages = isset( $this->about_data['product_pages'] ) ? $this->about_data['product_pages'] : []; |
| 206 | |
| 207 | return [ |
| 208 | 'links' => $links, |
| 209 | 'logoUrl' => $this->about_data['logo'], |
| 210 | 'productPages' => $this->get_product_pages_data( $product_pages ), |
| 211 | 'products' => $this->get_other_products_data(), |
| 212 | 'homeUrl' => esc_url( home_url() ), |
| 213 | 'pageSlug' => $this->get_about_page_slug(), |
| 214 | 'currentProduct' => [ |
| 215 | 'slug' => $this->product->get_key(), |
| 216 | 'name' => $this->product->get_name(), |
| 217 | ], |
| 218 | 'teamImage' => $this->get_sdk_uri() . 'assets/images/team.jpg', |
| 219 | 'strings' => [ |
| 220 | 'aboutUs' => Loader::$labels['about_us']['title'], |
| 221 | 'heroHeader' => Loader::$labels['about_us']['heroHeader'], |
| 222 | 'heroTextFirst' => Loader::$labels['about_us']['heroTextFirst'], |
| 223 | 'heroTextSecond' => Loader::$labels['about_us']['heroTextSecond'], |
| 224 | 'teamImageCaption' => Loader::$labels['about_us']['teamImageCaption'], |
| 225 | 'newsHeading' => Loader::$labels['about_us']['newsHeading'], |
| 226 | 'emailPlaceholder' => Loader::$labels['about_us']['emailPlaceholder'], |
| 227 | 'signMeUp' => Loader::$labels['about_us']['signMeUp'], |
| 228 | 'services' => Loader::$labels['about_us']['services'], |
| 229 | 'installNow' => Loader::$labels['about_us']['installNow'], |
| 230 | 'activate' => Loader::$labels['about_us']['activate'], |
| 231 | 'learnMore' => Loader::$labels['about_us']['learnMore'], |
| 232 | 'installed' => Loader::$labels['about_us']['installed'], |
| 233 | 'notInstalled' => Loader::$labels['about_us']['notInstalled'], |
| 234 | 'active' => Loader::$labels['about_us']['active'], |
| 235 | ], |
| 236 | 'canInstallPlugins' => current_user_can( 'install_plugins' ), |
| 237 | 'canActivatePlugins' => current_user_can( 'activate_plugins' ), |
| 238 | 'showReviewLink' => ! ( isset( $this->about_data['review_link'] ) && false === $this->about_data['review_link'] ), |
| 239 | ]; |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Get product pages data. |
| 244 | * |
| 245 | * @param array $product_pages Product pages. |
| 246 | * |
| 247 | * @return array |
| 248 | */ |
| 249 | private function get_product_pages_data( $product_pages ) { |
| 250 | |
| 251 | $otter_slug = 'otter-blocks'; |
| 252 | $otter_plugin = [ |
| 253 | 'status' => 'not-installed', |
| 254 | ]; |
| 255 | $otter_plugin['status'] = $this->is_plugin_installed( $otter_slug ) ? 'installed' : 'not-installed'; |
| 256 | $otter_plugin['status'] = $this->is_plugin_active( $otter_slug ) ? 'active' : $otter_plugin['status']; |
| 257 | $otter_plugin['activationLink'] = $this->get_plugin_activation_link( $otter_slug ); |
| 258 | |
| 259 | $pages = [ |
| 260 | 'otter-page' => [ |
| 261 | 'name' => 'Otter Blocks', |
| 262 | 'hash' => '#otter-page', |
| 263 | 'product' => $otter_slug, |
| 264 | 'plugin' => $otter_plugin, |
| 265 | 'strings' => [ |
| 266 | 'heading' => Loader::$labels['about_us']['otter-page']['heading'], |
| 267 | 'text' => Loader::$labels['about_us']['otter-page']['text'], |
| 268 | 'buttons' => [ |
| 269 | 'install_otter_free' => Loader::$labels['about_us']['otter-page']['buttons']['install_otter_free'], |
| 270 | 'install_now' => Loader::$labels['about_us']['otter-page']['buttons']['install_now'], |
| 271 | 'learn_more' => Loader::$labels['about_us']['otter-page']['buttons']['learn_more'], |
| 272 | 'learn_more_link' => tsdk_utmify( 'https://themeisle.com/plugins/otter-blocks/', 'otter-page', 'about-us' ), |
| 273 | ], |
| 274 | 'features' => [ |
| 275 | 'advancedTitle' => Loader::$labels['about_us']['otter-page']['features']['advancedTitle'], |
| 276 | 'advancedDesc' => Loader::$labels['about_us']['otter-page']['features']['advancedDesc'], |
| 277 | 'fastTitle' => Loader::$labels['about_us']['otter-page']['features']['fastTitle'], |
| 278 | 'fastDesc' => Loader::$labels['about_us']['otter-page']['features']['fastDesc'], |
| 279 | 'mobileTitle' => Loader::$labels['about_us']['otter-page']['features']['mobileTitle'], |
| 280 | 'mobileDesc' => Loader::$labels['about_us']['otter-page']['features']['mobileDesc'], |
| 281 | ], |
| 282 | 'details' => [ |
| 283 | 's1Title' => Loader::$labels['about_us']['otter-page']['details']['s1Title'], |
| 284 | 's1Text' => Loader::$labels['about_us']['otter-page']['details']['s1Text'], |
| 285 | 's2Title' => Loader::$labels['about_us']['otter-page']['details']['s2Title'], |
| 286 | 's2Text' => Loader::$labels['about_us']['otter-page']['details']['s2Text'], |
| 287 | 's3Title' => Loader::$labels['about_us']['otter-page']['details']['s3Title'], |
| 288 | 's3Text' => Loader::$labels['about_us']['otter-page']['details']['s3Text'], |
| 289 | 's1Image' => $this->get_sdk_uri() . 'assets/images/otter/otter-builder.png', |
| 290 | 's2Image' => $this->get_sdk_uri() . 'assets/images/otter/otter-patterns.png', |
| 291 | 's3Image' => $this->get_sdk_uri() . 'assets/images/otter/otter-library.png', |
| 292 | ], |
| 293 | 'testimonials' => [ |
| 294 | 'heading' => Loader::$labels['about_us']['otter-page']['testimonials']['heading'], |
| 295 | 'users' => [ |
| 296 | [ |
| 297 | 'avatar' => 'https://mllj2j8xvfl0.i.optimole.com/cb:3970~373ad/w:80/h:80/q:mauto/https://themeisle.com/wp-content/uploads/2021/05/avatar-03.png', |
| 298 | 'name' => 'Michael Burry', |
| 299 | 'text' => Loader::$labels['about_us']['otter-page']['testimonials']['users']['user_1'], |
| 300 | ], |
| 301 | [ |
| 302 | 'avatar' => 'https://mllj2j8xvfl0.i.optimole.com/cb:3970~373ad/w:80/h:80/q:mauto/https://themeisle.com/wp-content/uploads/2022/04/avatar-04.png', |
| 303 | 'name' => 'Maria Gonzales', |
| 304 | 'text' => Loader::$labels['about_us']['otter-page']['testimonials']['users']['user_2'], |
| 305 | ], |
| 306 | [ |
| 307 | 'avatar' => 'https://mllj2j8xvfl0.i.optimole.com/cb:3970~373ad/w:80/h:80/q:mauto/https://themeisle.com/wp-content/uploads/2022/04/avatar-05.png', |
| 308 | 'name' => 'Florian Henckel', |
| 309 | 'text' => Loader::$labels['about_us']['otter-page']['testimonials']['users']['user_3'], |
| 310 | ], |
| 311 | ], |
| 312 | ], |
| 313 | ], |
| 314 | ], |
| 315 | ]; |
| 316 | |
| 317 | return array_filter( |
| 318 | $pages, |
| 319 | function ( $page_data, $page_key ) use ( $product_pages ) { |
| 320 | return in_array( $page_key, $product_pages, true ) && |
| 321 | isset( $page_data['plugin']['status'] ) && |
| 322 | $page_data['plugin']['status'] === 'not-installed'; |
| 323 | }, |
| 324 | ARRAY_FILTER_USE_BOTH |
| 325 | ); |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * Get products data. |
| 330 | * |
| 331 | * @return array |
| 332 | */ |
| 333 | private function get_other_products_data() { |
| 334 | $products = [ |
| 335 | 'optimole-wp' => [ |
| 336 | 'name' => 'Optimole', |
| 337 | 'description' => Loader::$labels['about_us']['others']['optimole_desc'], |
| 338 | ], |
| 339 | 'neve' => [ |
| 340 | 'skip_api' => true, |
| 341 | 'name' => 'Neve', |
| 342 | 'description' => Loader::$labels['about_us']['others']['neve_desc'], |
| 343 | 'icon' => $this->get_sdk_uri() . 'assets/images/neve.png', |
| 344 | ], |
| 345 | 'learning-management-system' => [ |
| 346 | 'name' => 'Masteriyo LMS', |
| 347 | ], |
| 348 | 'otter-blocks' => [ |
| 349 | 'name' => 'Otter', |
| 350 | ], |
| 351 | 'tweet-old-post' => [ |
| 352 | 'name' => 'Revive Social', |
| 353 | ], |
| 354 | 'feedzy-rss-feeds' => [ |
| 355 | 'name' => 'Feedzy', |
| 356 | ], |
| 357 | 'woocommerce-product-addon' => [ |
| 358 | 'name' => 'PPOM', |
| 359 | 'condition' => class_exists( 'WooCommerce', false ), |
| 360 | ], |
| 361 | 'visualizer' => [ |
| 362 | 'name' => 'Visualizer', |
| 363 | ], |
| 364 | 'wp-landing-kit' => [ |
| 365 | 'skip_api' => true, |
| 366 | 'premiumUrl' => tsdk_utmify( 'https://themeisle.com/plugins/wp-landing-kit', $this->get_about_page_slug() ), |
| 367 | 'name' => 'WP Landing Kit', |
| 368 | 'description' => Loader::$labels['about_us']['others']['landingkit_desc'], |
| 369 | 'icon' => $this->get_sdk_uri() . 'assets/images/wplk.png', |
| 370 | ], |
| 371 | 'multiple-pages-generator-by-porthas' => [ |
| 372 | 'name' => 'MPG', |
| 373 | ], |
| 374 | 'sparks-for-woocommerce' => [ |
| 375 | 'skip_api' => true, |
| 376 | 'premiumUrl' => tsdk_utmify( 'https://themeisle.com/plugins/sparks-for-woocommerce', $this->get_about_page_slug() ), |
| 377 | 'name' => 'Sparks', |
| 378 | 'description' => Loader::$labels['about_us']['others']['sparks_desc'], |
| 379 | 'icon' => $this->get_sdk_uri() . 'assets/images/sparks.png', |
| 380 | 'condition' => class_exists( 'WooCommerce', false ), |
| 381 | ], |
| 382 | 'templates-patterns-collection' => [ |
| 383 | 'name' => 'Templates Cloud', |
| 384 | 'description' => Loader::$labels['about_us']['others']['tpc_desc'], |
| 385 | ], |
| 386 | 'wp-cloudflare-page-cache' => [ |
| 387 | 'name' => 'Super Page Cache', |
| 388 | ], |
| 389 | 'hyve-lite' => [ |
| 390 | 'name' => 'Hyve Lite', |
| 391 | ], |
| 392 | 'wp-full-stripe-free' => [ |
| 393 | 'name' => 'WP Full Pay', |
| 394 | ], |
| 395 | ]; |
| 396 | |
| 397 | foreach ( $products as $slug => $product ) { |
| 398 | if ( isset( $product['condition'] ) && ! $product['condition'] ) { |
| 399 | unset( $products[ $slug ] ); |
| 400 | continue; |
| 401 | } |
| 402 | |
| 403 | if ( $slug === 'neve' ) { |
| 404 | $theme = get_template(); |
| 405 | $themes = wp_get_themes(); |
| 406 | |
| 407 | $products[ $slug ]['status'] = isset( $themes['neve'] ) ? 'installed' : 'not-installed'; |
| 408 | $products[ $slug ]['status'] = $theme === 'neve' ? 'active' : $products[ $slug ]['status']; |
| 409 | |
| 410 | $products[ $slug ]['activationLink'] = add_query_arg( |
| 411 | [ |
| 412 | 'stylesheet' => 'neve', |
| 413 | 'action' => 'activate', |
| 414 | '_wpnonce' => wp_create_nonce( 'switch-theme_neve' ), |
| 415 | ], |
| 416 | admin_url( 'themes.php' ) |
| 417 | ); |
| 418 | |
| 419 | continue; |
| 420 | } |
| 421 | |
| 422 | $products[ $slug ]['status'] = $this->is_plugin_installed( $slug ) ? 'installed' : 'not-installed'; |
| 423 | $products[ $slug ]['status'] = $this->is_plugin_active( $slug ) ? 'active' : $products[ $slug ]['status']; |
| 424 | $products[ $slug ]['activationLink'] = $this->get_plugin_activation_link( $slug ); |
| 425 | |
| 426 | |
| 427 | if ( isset( $product['skip_api'] ) ) { |
| 428 | continue; |
| 429 | } |
| 430 | |
| 431 | $api_data = $this->call_plugin_api( $slug ); |
| 432 | if ( ! isset( $product['icon'] ) && ( isset( $api_data->icons['2x'] ) || $api_data->icons['1x'] ) ) { |
| 433 | $products[ $slug ]['icon'] = isset( $api_data->icons['2x'] ) ? $api_data->icons['2x'] : $api_data->icons['1x']; |
| 434 | } |
| 435 | if ( ! isset( $product['description'] ) && isset( $api_data->short_description ) ) { |
| 436 | $products[ $slug ]['description'] = $api_data->short_description; |
| 437 | } |
| 438 | if ( ! isset( $product['name'] ) && isset( $api_data->name ) ) { |
| 439 | $products[ $slug ]['name'] = $api_data->name; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | return $products; |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * Get the page slug. |
| 448 | * |
| 449 | * @return string |
| 450 | */ |
| 451 | private function get_about_page_slug() { |
| 452 | return 'ti-about-' . $this->product->get_key(); |
| 453 | } |
| 454 | } |
| 455 |