| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPIDE\App\Services\View\Adapters; |
| 4 |
|
| 5 |
use WPIDE\App\App; |
| 6 |
use WPIDE\App\Classes\Freemius; |
| 7 |
use WPIDE\App\Classes\Notices; |
| 8 |
use WPIDE\App\Config\Config; |
| 9 |
use WPIDE\App\Services\Service; |
| 10 |
use WPIDE\App\Services\View\ViewInterface; |
| 11 |
use WPIDE\WPIDE; |
| 12 |
use const WPIDE\Constants\ASSETS_URL; |
| 13 |
use const WPIDE\Constants\IS_DEV; |
| 14 |
use const WPIDE\Constants\NAME; |
| 15 |
use const WPIDE\Constants\SLUG; |
| 16 |
use const WPIDE\Constants\VERSION; |
| 17 |
use const WPIDE\Constants\WP_PATH; |
| 18 |
class Vuejs implements Service, ViewInterface { |
| 19 |
private $config; |
| 20 |
|
| 21 |
public function __construct( Config $config ) { |
| 22 |
$this->config = $config; |
| 23 |
} |
| 24 |
|
| 25 |
public function init( array $config = [] ) { |
| 26 |
$assets_url = ( !IS_DEV ? ASSETS_URL : WPIDE_DEV_URL ); |
| 27 |
$prod_assets_url = ASSETS_URL; |
| 28 |
$skins_url = $prod_assets_url . 'css/skins/'; |
| 29 |
$skin = $this->config->get( 'general.skin' ); |
| 30 |
if ( !IS_DEV ) { |
| 31 |
wp_enqueue_style( |
| 32 |
SLUG . '-vendors', |
| 33 |
$assets_url . 'css/chunk-vendors.css', |
| 34 |
[], |
| 35 |
VERSION |
| 36 |
); |
| 37 |
wp_enqueue_style( |
| 38 |
SLUG, |
| 39 |
$assets_url . 'css/app.css', |
| 40 |
[], |
| 41 |
VERSION |
| 42 |
); |
| 43 |
} |
| 44 |
if ( $skin !== 'default' ) { |
| 45 |
wp_enqueue_style( |
| 46 |
SLUG . '-skin', |
| 47 |
$skins_url . 'theme-' . $skin . '.css', |
| 48 |
[], |
| 49 |
VERSION |
| 50 |
); |
| 51 |
} |
| 52 |
wp_enqueue_script( |
| 53 |
SLUG . '-vendors', |
| 54 |
$assets_url . 'js/chunks/chunk-vendors.js', |
| 55 |
[], |
| 56 |
VERSION, |
| 57 |
true |
| 58 |
); |
| 59 |
wp_enqueue_script( |
| 60 |
SLUG, |
| 61 |
$assets_url . 'js/app.js', |
| 62 |
['jquery'], |
| 63 |
VERSION, |
| 64 |
true |
| 65 |
); |
| 66 |
wp_localize_script( SLUG, 'WPIDE', [ |
| 67 |
'premium' => Freemius::sdk()->can_use_premium_code__premium_only(), |
| 68 |
'is_premium_version' => Freemius::sdk()->is__premium_only(), |
| 69 |
'is_license_active' => Freemius::sdk()->is__premium_only() && Freemius::sdk()->can_use_premium_code(), |
| 70 |
'show_freemius_menus' => Freemius::showSubmenus(), |
| 71 |
'plugin' => [ |
| 72 |
'name' => NAME, |
| 73 |
'slug' => SLUG, |
| 74 |
'version' => VERSION, |
| 75 |
], |
| 76 |
'ajax_url' => App::instance()->getAjaxUrl(), |
| 77 |
'admin_url' => App::instance()->getAdminUrl(), |
| 78 |
'assets_url' => $assets_url, |
| 79 |
'prod_assets_url' => $prod_assets_url, |
| 80 |
'images_url' => $prod_assets_url . 'img/', |
| 81 |
'skins_url' => $skins_url, |
| 82 |
'is_dev' => IS_DEV, |
| 83 |
'config_fields' => $this->config->getConfigFields(), |
| 84 |
'fm_wp_dir' => basename( WP_PATH ), |
| 85 |
'notices' => Notices::all(), |
| 86 |
'account_links' => self::getAccountLinks(), |
| 87 |
] ); |
| 88 |
$inline_scripts = apply_filters( 'wpide_inline_scripts', '' ); |
| 89 |
if ( !empty( $inline_scripts ) ) { |
| 90 |
wp_add_inline_script( SLUG, $inline_scripts ); |
| 91 |
} |
| 92 |
if ( Freemius::showSubmenus() && Freemius::sdk()->is__premium_only() && !wp_doing_ajax() ) { |
| 93 |
Freemius::addLicenseActivationDialogBox(); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
public function getAccountLinks() : array { |
| 98 |
$links = []; |
| 99 |
if ( Freemius::showSubmenus() ) { |
| 100 |
if ( Freemius::showUpgradeLink() ) { |
| 101 |
$links[] = array( |
| 102 |
'id' => '_pricing', |
| 103 |
'title' => esc_html__( 'Upgrade', 'wpide' ), |
| 104 |
'url' => Freemius::sdk()->get_upgrade_url(), |
| 105 |
'icon' => 'ni-arrow-up', |
| 106 |
); |
| 107 |
if ( Freemius::showTrialLink() && !is_network_admin() ) { |
| 108 |
$links[] = array( |
| 109 |
'id' => '_trial', |
| 110 |
'title' => esc_html__( 'Free Trial', 'wpide' ), |
| 111 |
'url' => Freemius::sdk()->get_trial_url(), |
| 112 |
'icon' => 'ni-clock', |
| 113 |
); |
| 114 |
} |
| 115 |
} |
| 116 |
if ( Freemius::sdk()->is_registered() ) { |
| 117 |
$links[] = array( |
| 118 |
'id' => 'account', |
| 119 |
'title' => esc_html__( 'Account', 'wpide' ), |
| 120 |
'url' => Freemius::sdk()->get_account_url(), |
| 121 |
'icon' => 'ni-user-alt', |
| 122 |
); |
| 123 |
} else { |
| 124 |
if ( Freemius::sdk()->is_tracking_prohibited() ) { |
| 125 |
$links[] = array( |
| 126 |
'id' => 'optin', |
| 127 |
'title' => esc_html__( 'Opt In', 'wpide' ), |
| 128 |
'url' => Freemius::sdk()->get_reconnect_url(), |
| 129 |
'icon' => 'ni-user-check', |
| 130 |
); |
| 131 |
} |
| 132 |
} |
| 133 |
if ( Freemius::sdk()->has_affiliate_program() ) { |
| 134 |
$links[] = array( |
| 135 |
'id' => 'affiliates', |
| 136 |
'title' => esc_html__( 'Affiliates', 'wpide' ), |
| 137 |
'url' => Freemius::sdk()->_get_admin_page_url( 'affiliation' ), |
| 138 |
'icon' => 'ni-money', |
| 139 |
); |
| 140 |
} |
| 141 |
$links[] = array( |
| 142 |
'id' => 'contact', |
| 143 |
'title' => esc_html__( 'Support', 'wpide' ), |
| 144 |
'url' => Freemius::sdk()->contact_url(), |
| 145 |
'icon' => 'ni-help', |
| 146 |
); |
| 147 |
} |
| 148 |
$links[] = array( |
| 149 |
'id' => 'changelog', |
| 150 |
'title' => esc_html__( 'Change Log', 'wpide' ), |
| 151 |
'url' => App::instance()->getAdminUrl( 'changelog' ), |
| 152 |
'icon' => 'ni-notes-alt', |
| 153 |
); |
| 154 |
$links[] = array( |
| 155 |
'id' => 'site', |
| 156 |
'title' => esc_html__( 'Other Plugins', 'wpide' ), |
| 157 |
'url' => 'https://xplodedthemes.com', |
| 158 |
'icon' => 'ni-link', |
| 159 |
'external' => true, |
| 160 |
); |
| 161 |
return $links; |
| 162 |
} |
| 163 |
|
| 164 |
public function getIndexPage() : string { |
| 165 |
$output = ' |
| 166 |
<noscript><strong>Please enable JavaScript to continue.</strong></noscript> |
| 167 |
<div id="' . SLUG . '-app"></div> |
| 168 |
'; |
| 169 |
return $output; |
| 170 |
} |
| 171 |
|
| 172 |
} |
| 173 |
|