Ends
9 years ago
Providers
9 years ago
AutoLoader.php
9 years ago
Disabler.php
9 years ago
Loader.php
9 years ago
Plugin.php
9 years ago
Shortcode.php
9 years ago
index.html
9 years ago
Plugin.php
226 lines
| 1 | <?php |
| 2 | namespace EmbedPress; |
| 3 | |
| 4 | use \EmbedPress\Loader; |
| 5 | use \EmbedPress\Ends\Back\Handler as EndHandlerAdmin; |
| 6 | use \EmbedPress\Ends\Front\Handler as EndHandlerPublic; |
| 7 | |
| 8 | (defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed."); |
| 9 | |
| 10 | /** |
| 11 | * Entity that glues together all pieces that the plugin is made of. |
| 12 | * |
| 13 | * @package EmbedPress |
| 14 | * @author PressShack <help@pressshack.com> |
| 15 | * @copyright Copyright (C) 2016 Open Source Training, LLC. All rights reserved. |
| 16 | * @license GPLv2 or later |
| 17 | * @since 1.0 |
| 18 | */ |
| 19 | class Plugin |
| 20 | { |
| 21 | /** |
| 22 | * The name of the plugin. |
| 23 | * |
| 24 | * @since 1.0 |
| 25 | * @access protected |
| 26 | * |
| 27 | * @var string $pluginName The name of the plugin. |
| 28 | */ |
| 29 | protected $pluginName; |
| 30 | |
| 31 | /** |
| 32 | * The version of the plugin. |
| 33 | * |
| 34 | * @since 1.0 |
| 35 | * @access protected |
| 36 | * |
| 37 | * @var string $pluginVersion The version of the plugin. |
| 38 | */ |
| 39 | protected $pluginVersion; |
| 40 | |
| 41 | /** |
| 42 | * An instance of the plugin loader. |
| 43 | * |
| 44 | * @since 1.0 |
| 45 | * @access protected |
| 46 | * |
| 47 | * @var \EmbedPress\Loader $pluginVersion The version of the plugin. |
| 48 | */ |
| 49 | protected $loaderInstance; |
| 50 | |
| 51 | /** |
| 52 | * Initialize the plugin and set its properties. |
| 53 | * |
| 54 | * @since 1.0 |
| 55 | */ |
| 56 | public function __construct() |
| 57 | { |
| 58 | $this->pluginName = EMBEDPRESS_PLG_NAME; |
| 59 | $this->pluginVersion = EMBEDPRESS_PLG_VERSION; |
| 60 | |
| 61 | $this->loaderInstance = new Loader(); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Method that retrieves the plugin name. |
| 66 | * |
| 67 | * @since 1.0 |
| 68 | * |
| 69 | * @return string |
| 70 | */ |
| 71 | public function getPluginName() |
| 72 | { |
| 73 | return $this->pluginName; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Method that retrieves the plugin version. |
| 78 | * |
| 79 | * @since 1.0 |
| 80 | * |
| 81 | * @return string |
| 82 | */ |
| 83 | public function getPluginVersion() |
| 84 | { |
| 85 | return $this->pluginVersion; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Method that retrieves the loader instance. |
| 90 | * |
| 91 | * @since 1.0 |
| 92 | * |
| 93 | * @return \EmbedPress\Loader |
| 94 | */ |
| 95 | public function getLoader() |
| 96 | { |
| 97 | return $this->loaderInstance; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Method responsible to connect all required hooks in order to make the plugin work. |
| 102 | * |
| 103 | * @since 1.0 |
| 104 | */ |
| 105 | public function initialize() |
| 106 | { |
| 107 | global $wp_actions; |
| 108 | |
| 109 | if (is_admin()) { |
| 110 | $plgSettings = self::getSettings(); |
| 111 | |
| 112 | $settingsClassNamespace = '\EmbedPress\Ends\Back\Settings'; |
| 113 | add_action('admin_menu', array($settingsClassNamespace, 'registerMenuItem')); |
| 114 | add_action('admin_init', array($settingsClassNamespace, 'registerActions')); |
| 115 | unset($settingsClassNamespace); |
| 116 | |
| 117 | if ($plgSettings->enablePluginInAdmin) { |
| 118 | add_action('init', array('\EmbedPress\Disabler', 'run'), 1); |
| 119 | |
| 120 | $plgHandlerAdminInstance = new EndHandlerAdmin($this->getPluginName(), $this->getPluginVersion()); |
| 121 | |
| 122 | $enqueueScriptsHookName = "admin_enqueue_scripts"; |
| 123 | $this->loaderInstance->add_action($enqueueScriptsHookName, $plgHandlerAdminInstance, 'enqueueScripts'); |
| 124 | $this->loaderInstance->add_action($enqueueScriptsHookName, $plgHandlerAdminInstance, 'enqueueStyles'); |
| 125 | |
| 126 | $onAjaxCallbackName = "doShortcodeReceivedViaAjax"; |
| 127 | $this->loaderInstance->add_action('wp_ajax_embedpress_do_ajax_request', $plgHandlerAdminInstance, $onAjaxCallbackName); |
| 128 | $this->loaderInstance->add_action('wp_ajax_nopriv_embedpress_do_ajax_request', $plgHandlerAdminInstance, $onAjaxCallbackName); |
| 129 | |
| 130 | $this->loaderInstance->add_action('wp_ajax_embedpress_get_embed_url_info', $plgHandlerAdminInstance, "getUrlInfoViaAjax"); |
| 131 | |
| 132 | unset($onAjaxCallbackName, $enqueueScriptsHookName, $plgHandlerAdminInstance); |
| 133 | } |
| 134 | } else { |
| 135 | add_action('init', array('\EmbedPress\Disabler', 'run'), 1); |
| 136 | |
| 137 | $plgHandlerPublicInstance = new EndHandlerPublic($this->getPluginName(), $this->getPluginVersion()); |
| 138 | |
| 139 | $enqueueScriptsHookName = "wp_enqueue_scripts"; |
| 140 | $this->loaderInstance->add_action($enqueueScriptsHookName, $plgHandlerPublicInstance, 'enqueueScripts'); |
| 141 | $this->loaderInstance->add_action($enqueueScriptsHookName, $plgHandlerPublicInstance, 'enqueueStyles'); |
| 142 | |
| 143 | unset($enqueueScriptsHookName, $plgHandlerPublicInstance); |
| 144 | } |
| 145 | |
| 146 | $this->loaderInstance->run(); |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Callback called right after the plugin has been activated. |
| 151 | * |
| 152 | * @since 1.0 |
| 153 | */ |
| 154 | public static function onPluginActivationCallback() |
| 155 | { |
| 156 | add_filter('rewrite_rules_array', array('\EmbedPress\Disabler', 'disableDefaultEmbedRewriteRules')); |
| 157 | flush_rewrite_rules(); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Callback called right after the plugin has been deactivated. |
| 162 | * |
| 163 | * @since 1.0 |
| 164 | */ |
| 165 | public static function onPluginDeactivationCallback() |
| 166 | { |
| 167 | remove_filter('rewrite_rules_array', array('\EmbedPress\Disabler', 'disableDefaultEmbedRewriteRules')); |
| 168 | flush_rewrite_rules(); |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Method that retrieves all additional service providers defined in the ~<plugin_root_path>/providers.php file. |
| 173 | * |
| 174 | * @since 1.0 |
| 175 | * |
| 176 | * @return array |
| 177 | */ |
| 178 | public static function getAdditionalServiceProviders() |
| 179 | { |
| 180 | $additionalProvidersFilePath = EMBEDPRESS_PATH_BASE .'providers.php'; |
| 181 | if (file_exists($additionalProvidersFilePath)) { |
| 182 | include $additionalProvidersFilePath; |
| 183 | |
| 184 | if (isset($additionalServiceProviders)) { |
| 185 | return $additionalServiceProviders; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | return array(); |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Method that checks if an embed of a given service provider can be responsive. |
| 194 | * |
| 195 | * @since 1.0 |
| 196 | * |
| 197 | * @return boolean |
| 198 | */ |
| 199 | public static function canServiceProviderBeResponsive($serviceProviderAlias) |
| 200 | { |
| 201 | return in_array($serviceProviderAlias, array("dailymotion", "kickstarter", "rutube", "ted", "vimeo", "youtube", "ustream", "google-docs", "animatron", "amcharts", "on-aol-com", "animoto", "videojug")); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Method that retrieves the plugin settings defined by the user. |
| 206 | * |
| 207 | * @since 1.0 |
| 208 | * |
| 209 | * @return object |
| 210 | */ |
| 211 | public static function getSettings() |
| 212 | { |
| 213 | $settings = get_option("embedpress_options"); |
| 214 | |
| 215 | if (!isset($settings['displayPreviewBox'])) { |
| 216 | $settings['displayPreviewBox'] = true; |
| 217 | } |
| 218 | |
| 219 | if (!isset($settings['enablePluginInAdmin'])) { |
| 220 | $settings['enablePluginInAdmin'] = true; |
| 221 | } |
| 222 | |
| 223 | return (object)$settings; |
| 224 | } |
| 225 | } |
| 226 |