PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 1.3.1
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v1.3.1
4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / EmbedPress / Plugin.php
embedpress / EmbedPress Last commit date
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
243 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.0
18 */
19 class Plugin
20 {
21 /**
22 * The name of the plugin.
23 *
24 * @since 1.0.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.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.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.0
55 *
56 * @return void
57 */
58 public function __construct()
59 {
60 $this->pluginName = EMBEDPRESS_PLG_NAME;
61 $this->pluginVersion = EMBEDPRESS_PLG_VERSION;
62
63 $this->loaderInstance = new Loader();
64 }
65
66 /**
67 * Method that retrieves the plugin name.
68 *
69 * @since 1.0.0
70 *
71 * @return string
72 */
73 public function getPluginName()
74 {
75 return $this->pluginName;
76 }
77
78 /**
79 * Method that retrieves the plugin version.
80 *
81 * @since 1.0.0
82 *
83 * @return string
84 */
85 public function getPluginVersion()
86 {
87 return $this->pluginVersion;
88 }
89
90 /**
91 * Method that retrieves the loader instance.
92 *
93 * @since 1.0.0
94 *
95 * @return \EmbedPress\Loader
96 */
97 public function getLoader()
98 {
99 return $this->loaderInstance;
100 }
101
102 /**
103 * Method responsible to connect all required hooks in order to make the plugin work.
104 *
105 * @since 1.0.0
106 *
107 * @return void
108 */
109 public function initialize()
110 {
111 global $wp_actions;
112
113 if (is_admin()) {
114 $plgSettings = self::getSettings();
115
116 $settingsClassNamespace = '\EmbedPress\Ends\Back\Settings';
117 add_action('admin_menu', array($settingsClassNamespace, 'registerMenuItem'));
118 add_action('admin_init', array($settingsClassNamespace, 'registerActions'));
119 unset($settingsClassNamespace);
120
121 // Load CSS
122 wp_register_style( 'embedpress-admin', plugins_url( 'embedpress/assets/css/admin.css' ) );
123 wp_enqueue_style( 'embedpress-admin' );
124
125 if ($plgSettings->enablePluginInAdmin) {
126 add_action('init', array('\EmbedPress\Disabler', 'run'), 1);
127
128 $plgHandlerAdminInstance = new EndHandlerAdmin($this->getPluginName(), $this->getPluginVersion());
129
130 $enqueueScriptsHookName = "admin_enqueue_scripts";
131 $this->loaderInstance->add_action($enqueueScriptsHookName, $plgHandlerAdminInstance, 'enqueueScripts');
132 $this->loaderInstance->add_action($enqueueScriptsHookName, $plgHandlerAdminInstance, 'enqueueStyles');
133
134 $onAjaxCallbackName = "doShortcodeReceivedViaAjax";
135 $this->loaderInstance->add_action('wp_ajax_embedpress_do_ajax_request', $plgHandlerAdminInstance, $onAjaxCallbackName);
136 $this->loaderInstance->add_action('wp_ajax_nopriv_embedpress_do_ajax_request', $plgHandlerAdminInstance, $onAjaxCallbackName);
137
138 $this->loaderInstance->add_action('wp_ajax_embedpress_get_embed_url_info', $plgHandlerAdminInstance, "getUrlInfoViaAjax");
139
140 unset($onAjaxCallbackName, $enqueueScriptsHookName, $plgHandlerAdminInstance);
141 }
142 } else {
143 add_action('init', array('\EmbedPress\Disabler', 'run'), 1);
144
145 $plgHandlerPublicInstance = new EndHandlerPublic($this->getPluginName(), $this->getPluginVersion());
146
147 $enqueueScriptsHookName = "wp_enqueue_scripts";
148 $this->loaderInstance->add_action($enqueueScriptsHookName, $plgHandlerPublicInstance, 'enqueueScripts');
149 $this->loaderInstance->add_action($enqueueScriptsHookName, $plgHandlerPublicInstance, 'enqueueStyles');
150
151 unset($enqueueScriptsHookName, $plgHandlerPublicInstance);
152 }
153
154 $this->loaderInstance->run();
155 }
156
157 /**
158 * Callback called right after the plugin has been activated.
159 *
160 * @since 1.0.0
161 * @static
162 *
163 * @return void
164 */
165 public static function onPluginActivationCallback()
166 {
167 add_filter('rewrite_rules_array', array('\EmbedPress\Disabler', 'disableDefaultEmbedRewriteRules'));
168 flush_rewrite_rules();
169 }
170
171 /**
172 * Callback called right after the plugin has been deactivated.
173 *
174 * @since 1.0.0
175 * @static
176 *
177 * @return void
178 */
179 public static function onPluginDeactivationCallback()
180 {
181 remove_filter('rewrite_rules_array', array('\EmbedPress\Disabler', 'disableDefaultEmbedRewriteRules'));
182 flush_rewrite_rules();
183 }
184
185 /**
186 * Method that retrieves all additional service providers defined in the ~<plugin_root_path>/providers.php file.
187 *
188 * @since 1.0.0
189 * @static
190 *
191 * @return array
192 */
193 public static function getAdditionalServiceProviders()
194 {
195 $additionalProvidersFilePath = EMBEDPRESS_PATH_BASE .'providers.php';
196 if (file_exists($additionalProvidersFilePath)) {
197 include $additionalProvidersFilePath;
198
199 if (isset($additionalServiceProviders)) {
200 return $additionalServiceProviders;
201 }
202 }
203
204 return array();
205 }
206
207 /**
208 * Method that checks if an embed of a given service provider can be responsive.
209 *
210 * @since 1.0.0
211 * @static
212 *
213 * @return boolean
214 */
215 public static function canServiceProviderBeResponsive($serviceProviderAlias)
216 {
217 return in_array($serviceProviderAlias, array("dailymotion", "kickstarter", "rutube", "ted", "vimeo", "youtube", "ustream", "google-docs", "animatron", "amcharts", "on-aol-com", "animoto", "videojug"));
218 }
219
220 /**
221 * Method that retrieves the plugin settings defined by the user.
222 *
223 * @since 1.0.0
224 * @static
225 *
226 * @return object
227 */
228 public static function getSettings()
229 {
230 $settings = get_option("embedpress_options");
231
232 if (!isset($settings['displayPreviewBox'])) {
233 $settings['displayPreviewBox'] = true;
234 }
235
236 if (!isset($settings['enablePluginInAdmin'])) {
237 $settings['enablePluginInAdmin'] = true;
238 }
239
240 return (object)$settings;
241 }
242 }
243