Example #1
0
 /**
  * Checks environment and build defaults 
  * 
  */
 protected function __construct()
 {
     // Instantiate Feature Manager
     FeatureManager::getInstance();
     // Instantiate Context Manager
     ContextManager::getInstance();
     // Instantiate URLs Manager
     UrlManager::getInstance();
     // Instantiate Paths Manager & set Bebop root directory
     PathManager::getInstance()->set('bebop', __DIR__);
     // Set default Media Mvc Model modifications on the Bebop HTTP API
     Media::onContext('api', function ($media) {
         $media->cacheAllImageSizes();
     });
     // Set default views directory
     View::setViewsDir(PathManager::getInstance()->get('theme', 'views'));
     // Instantiate CSS Manager
     CSS::getInstance();
     // Instantiate JS Manager
     JS::getInstance();
     // Instantiate UI
     UI::getInstance();
     // Instantiate Api
     self::Api();
     // Instantiate Config
     Config::getInstance();
     // Shortcode support for in editor use
     add_shortcode('Bebop', array($this, '__bebopShortcodes'));
 }
 /**
  * Register stuff on the init hook
  * 
  * @return void
  */
 public function onInit()
 {
     // Get configuration object
     $config = Config::getInstance();
     // Get remote configuration
     if ($remote_config = $this->__getRemoteConfiguration()) {
         foreach ($remote_config as $key => $value) {
             $config->set($key, $value);
         }
     }
     // Enable Intercom widget if we have the desired conditions
     if ($config->get('app_id') && (is_user_logged_in() || $config->get('allow_visitors'))) {
         // Get logged in user data
         global $current_user;
         get_currentuserinfo();
         $script_id = 'bebop-intercom';
         $script_name = $config->get('dev_env_enabled') ? 'bebop-intercom.js' : 'bebop-intercom.min.js';
         $script_path = $config->get('plugin_base_url') . 'assets/js/' . $script_name;
         $localization_name = 'intercomSettings';
         $localization_value = ['app_id' => $config->get('app_id'), 'created_at' => date('U')];
         // Add user WordPress data, if enabled
         if (!$config->get('dont_send_user_data')) {
             $localization_value['user_id'] = $current_user ? (getenv('APP_NAME') ?: $_SERVER['HTTP_HOST']) . '-' . $current_user->ID : null;
             $localization_value['email'] = $current_user ? $current_user->user_email : null;
             $localization_value['name'] = $current_user ? $current_user->display_name : null;
         }
         // Register, localize and enqueue plugin script on both front and back-end
         $js = JS::getInstance();
         $js->getHook('back')->register($script_id, $script_path)->localize($script_id, $localization_name, $localization_value)->enqueue($script_id);
         // Optionally display Intercom widget on front-end
         if ($config->get('display_on_front_end')) {
             $js->getHook('front')->register($script_id, $script_path)->localize($script_id, $localization_name, $localization_value)->enqueue($script_id);
         }
     }
 }