EmbedPress – Embed Google Docs, YouTube, Maps, Vimeo, Wistia Videos & Upload PDF, PPT in Gutenberg & Elementor - Version 1.6.0

Version Description

Release Date: 2017-02-28

  • Added support to preview embeds inside editors rendered in frontend;
  • Fixed some embeds not respecting custom dimensions;
  • Fixed some embeds not being rendered as they should in frontend due to invalid characters in the url;
  • Fixed embeds not being rendered in editors on some WP instances;
  • Tweaks on the plugin settings page;
  • Code enhancements.
Download this release

Release Info

Developer pressshack
Plugin Icon wp plugin EmbedPress – Embed Google Docs, YouTube, Maps, Vimeo, Wistia Videos & Upload PDF, PPT in Gutenberg & Elementor
Version 1.6.0
Comparing to
See all releases

Code changes from version 1.5.0 to 1.6.0

EmbedPress/Core.php CHANGED
@@ -134,21 +134,21 @@ class Core
134
 
135
  add_action('admin_enqueue_scripts', array('\EmbedPress\Ends\Back\Handler', 'enqueueStyles'));
136
 
137
- if ($plgSettings->enablePluginInAdmin) {
138
- add_action('init', array('\EmbedPress\Disabler', 'run'), 1);
139
 
140
- $plgHandlerAdminInstance = new EndHandlerAdmin($this->getPluginName(), $this->getPluginVersion());
141
 
 
142
  $this->loaderInstance->add_action('admin_enqueue_scripts', $plgHandlerAdminInstance, 'enqueueScripts');
 
143
 
144
- $onAjaxCallbackName = "doShortcodeReceivedViaAjax";
145
- $this->loaderInstance->add_action('wp_ajax_embedpress_do_ajax_request', $plgHandlerAdminInstance, $onAjaxCallbackName);
146
- $this->loaderInstance->add_action('wp_ajax_nopriv_embedpress_do_ajax_request', $plgHandlerAdminInstance, $onAjaxCallbackName);
147
 
148
- $this->loaderInstance->add_action('wp_ajax_embedpress_get_embed_url_info', $plgHandlerAdminInstance, "getUrlInfoViaAjax");
149
 
150
- unset($onAjaxCallbackName, $plgHandlerAdminInstance);
151
- }
152
  } else {
153
  add_action('init', array('\EmbedPress\Disabler', 'run'), 1);
154
 
@@ -240,14 +240,14 @@ class Core
240
  {
241
  $settings = get_option(EMBEDPRESS_PLG_NAME);
242
 
243
- if (!isset($settings['displayPreviewBox'])) {
244
- $settings['displayPreviewBox'] = true;
245
- }
246
-
247
  if (!isset($settings['enablePluginInAdmin'])) {
248
  $settings['enablePluginInAdmin'] = true;
249
  }
250
 
 
 
 
 
251
  return (object)$settings;
252
  }
253
 
134
 
135
  add_action('admin_enqueue_scripts', array('\EmbedPress\Ends\Back\Handler', 'enqueueStyles'));
136
 
137
+ add_action('init', array('\EmbedPress\Disabler', 'run'), 1);
 
138
 
139
+ $plgHandlerAdminInstance = new EndHandlerAdmin($this->getPluginName(), $this->getPluginVersion());
140
 
141
+ if ((bool)$plgSettings->enablePluginInAdmin) {
142
  $this->loaderInstance->add_action('admin_enqueue_scripts', $plgHandlerAdminInstance, 'enqueueScripts');
143
+ }
144
 
145
+ $onAjaxCallbackName = "doShortcodeReceivedViaAjax";
146
+ $this->loaderInstance->add_action('wp_ajax_embedpress_do_ajax_request', $plgHandlerAdminInstance, $onAjaxCallbackName);
147
+ $this->loaderInstance->add_action('wp_ajax_nopriv_embedpress_do_ajax_request', $plgHandlerAdminInstance, $onAjaxCallbackName);
148
 
149
+ $this->loaderInstance->add_action('wp_ajax_embedpress_get_embed_url_info', $plgHandlerAdminInstance, "getUrlInfoViaAjax");
150
 
151
+ unset($onAjaxCallbackName, $plgHandlerAdminInstance);
 
152
  } else {
153
  add_action('init', array('\EmbedPress\Disabler', 'run'), 1);
154
 
240
  {
241
  $settings = get_option(EMBEDPRESS_PLG_NAME);
242
 
 
 
 
 
243
  if (!isset($settings['enablePluginInAdmin'])) {
244
  $settings['enablePluginInAdmin'] = true;
245
  }
246
 
247
+ if (!isset($settings['enablePluginInFront'])) {
248
+ $settings['enablePluginInFront'] = true;
249
+ }
250
+
251
  return (object)$settings;
252
  }
253
 
EmbedPress/Disabler.php CHANGED
@@ -95,6 +95,8 @@ class Disabler
95
  wp_deregister_script('wp-embed');
96
 
97
  add_filter('http_request_host_is_external', array('\EmbedPress\Core', 'allowApiHost'), 10, 3);
 
 
98
  }
99
 
100
  /**
95
  wp_deregister_script('wp-embed');
96
 
97
  add_filter('http_request_host_is_external', array('\EmbedPress\Core', 'allowApiHost'), 10, 3);
98
+
99
+ add_filter('the_editor', array('\EmbedPress\Ends\Front\Handler', 'renderPreviewBoxInEditors'));
100
  }
101
 
102
  /**
EmbedPress/Ends/Back/Handler.php CHANGED
@@ -37,13 +37,12 @@ class Handler extends EndHandlerAbstract
37
  wp_enqueue_script($this->pluginName, EMBEDPRESS_URL_ASSETS .'js/preview.js', array('jquery', 'bootbox'), $this->pluginVersion, true);
38
  wp_localize_script($this->pluginName, '$data', array(
39
  'previewSettings' => array(
40
- 'juriRoot' => get_site_url() .'/',
41
  'versionUID' => $this->pluginVersion,
42
  'debug' => true
43
  ),
44
  'EMBEDPRESS_SHORTCODE' => EMBEDPRESS_SHORTCODE,
45
- 'EMBEDPRESS_URL_ASSETS' => EMBEDPRESS_URL_ASSETS,
46
- 'displayPreviewBox' => $plgSettings->displayPreviewBox
47
  ));
48
 
49
  $installedPlugins = Core::getPlugins();
37
  wp_enqueue_script($this->pluginName, EMBEDPRESS_URL_ASSETS .'js/preview.js', array('jquery', 'bootbox'), $this->pluginVersion, true);
38
  wp_localize_script($this->pluginName, '$data', array(
39
  'previewSettings' => array(
40
+ 'baseUrl' => get_site_url() .'/',
41
  'versionUID' => $this->pluginVersion,
42
  'debug' => true
43
  ),
44
  'EMBEDPRESS_SHORTCODE' => EMBEDPRESS_SHORTCODE,
45
+ 'EMBEDPRESS_URL_ASSETS' => EMBEDPRESS_URL_ASSETS
 
46
  ));
47
 
48
  $installedPlugins = Core::getPlugins();
EmbedPress/Ends/Back/Settings.php CHANGED
@@ -72,15 +72,15 @@ class Settings
72
  */
73
  private static $fieldMap = array(
74
  'enablePluginInAdmin' => array(
75
- 'label' => "Allow EmbedPress in Admin",
76
  'section' => "admin"
77
  ),
78
- 'displayPreviewBox' => array(
79
- 'label' => "Load embeds inside Editors",
80
  'section' => "admin"
81
  ),
82
  'forceFacebookLanguage' => array(
83
- 'label' => "Facebook embeds language",
84
  'section' => "admin"
85
  )
86
  );
@@ -135,7 +135,7 @@ class Settings
135
  } else {
136
  register_setting(self::$sectionGroupIdentifier, self::$sectionGroupIdentifier, array(self::$namespace, "validateForm"));
137
 
138
- add_settings_section(self::$sectionAdminIdentifier, 'General Settings', null, self::$identifier);
139
 
140
  foreach (self::$fieldMap as $fieldName => $field) {
141
  add_settings_field($fieldName, $field['label'], array(self::$namespace, "renderField_{$fieldName}"), self::$identifier, self::${"section". ucfirst($field['section']) ."Identifier"});
@@ -157,32 +157,35 @@ class Settings
157
  ?>
158
  <div id="embedpress-settings-wrapper">
159
  <header>
160
- <h1>EmbedPress <small><a href="//wordpress.org/plugins/embedpress/changelog/" target="_blank" rel="noopener noreferrer">v<?php echo EMBEDPRESS_PLG_VERSION; ?></a></small></h1>
161
-
162
  <a href="//wordpress.org/plugins/embedpress" target="_blank" rel="noopener noreferrer" title="EmbedPress" class="presshack-logo">
163
- <img width="75" src="//pressshack.com/wp-content/uploads/2016/05/embedpress-150x150.png">
164
  </a>
 
165
  </header>
166
 
167
  <?php settings_errors(); ?>
168
 
169
- <h2 class="nav-tab-wrapper">
170
- <a href="?page=embedpress" class="nav-tab<?php echo $activeTab === 'embedpress' || empty($activeTab) ? ' nav-tab-active' : ''; ?> ">General settings</a>
171
-
172
- <?php do_action('embedpress:settings:render:tab', $activeTab); ?>
173
- </h2>
174
 
175
- <form action="options.php" method="POST" style="padding-bottom: 20px;">
176
- <?php settings_fields($settingsFieldsIdentifier); ?>
177
- <?php do_settings_sections($settingsSectionsIdentifier); ?>
178
 
179
- <button type="submit" class="button button-primary">Save changes</button>
180
- </form>
 
181
 
182
- <hr>
 
 
183
 
184
- <footer id="embedpress-settings-footer">
185
- <div>
 
 
 
 
186
  <ul>
187
  <li>
188
  <a href="//pressshack.com/embedpress" target="_blank" rel="noopener noreferrer" title="About EmbedPress">About</a>
@@ -199,30 +202,23 @@ class Settings
199
  <li>
200
  <a href="//pressshack.com/contact" target="_blank" rel="noopener noreferrer" title="Contact the PressShack team">Contact</a>
201
  </li>
202
- </ul>
203
- <ul>
204
  <li>
205
  <a href="//twitter.com/pressshack" target="_blank" rel="noopener noreferrer">
206
  <span class="dashicons dashicons-twitter"></span>
207
  </a>
208
  </li>
209
  <li>
210
- <a href="//www.facebook.com/pressshack" target="_blank" rel="noopener noreferrer">
211
  <span class="dashicons dashicons-facebook"></span>
212
  </a>
213
  </li>
214
  </ul>
215
- </div>
216
- <div>
217
  <p>
218
- <small>Copyright &copy; 2017 Open Source Training LLC</small>
219
- </p>
220
- <p style="text-align: right; margin-top: 0;">
221
  <a href="//pressshack.com" target="_blank" rel="noopener noreferrer">
222
- <img width="100" src="//pressshack.com/wp-content/uploads/2016/11/logo-450.png" style="margin-top: 10px;">
223
  </a>
224
  </p>
225
- </div>
226
  </footer>
227
  </div>
228
  <?php
@@ -241,8 +237,8 @@ class Settings
241
  public static function validateForm($freshData)
242
  {
243
  $data = array(
244
- 'displayPreviewBox' => (bool)$freshData['displayPreviewBox'],
245
  'enablePluginInAdmin' => (bool)$freshData['enablePluginInAdmin'],
 
246
  'fbLanguage' => $freshData['fbLanguage']
247
  );
248
 
@@ -250,40 +246,34 @@ class Settings
250
  }
251
 
252
  /**
253
- * Method that renders the displayPreviewBox input.
254
  *
255
  * @since 1.0.0
256
  * @static
257
  */
258
- public static function renderField_displayPreviewBox()
259
  {
260
- $fieldName = "displayPreviewBox";
261
 
262
  $options = get_option(self::$sectionGroupIdentifier);
263
 
264
- $activeOptions = Core::getSettings();
265
- if (isset($activeOptions->enablePluginInAdmin) && (bool)$activeOptions->enablePluginInAdmin === false) {
266
- $options[$fieldName] = false;
267
- } else {
268
- $options[$fieldName] = !isset($options[$fieldName]) ? true : (bool)$options[$fieldName];
269
- }
270
- unset($activeOptions);
271
 
272
  echo '<label><input type="radio" id="'. $fieldName .'_0" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="0" '. (!$options[$fieldName] ? "checked" : "") .' /> No</label>';
273
  echo "&nbsp;&nbsp;";
274
  echo '<label><input type="radio" id="'. $fieldName .'_1" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="1" '. ($options[$fieldName] ? "checked" : "") .' /> Yes</label>';
275
- echo '<p class="description">Load embeds automatically detected inside your editor\'s content (i.e. TinyMCE).</p>';
276
  }
277
 
278
  /**
279
- * Method that renders the enablePluginInAdmin input.
280
  *
281
- * @since 1.0.0
282
  * @static
283
  */
284
- public static function renderField_enablePluginInAdmin()
285
  {
286
- $fieldName = "enablePluginInAdmin";
287
 
288
  $options = get_option(self::$sectionGroupIdentifier);
289
 
@@ -292,7 +282,7 @@ class Settings
292
  echo '<label><input type="radio" id="'. $fieldName .'_0" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="0" '. (!$options[$fieldName] ? "checked" : "") .' /> No</label>';
293
  echo "&nbsp;&nbsp;";
294
  echo '<label><input type="radio" id="'. $fieldName .'_1" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="1" '. ($options[$fieldName] ? "checked" : "") .' /> Yes</label>';
295
- echo '<p class="description">Allow EmbedPress to run here in the Admin area. Disabling this <strong>will not</strong> affect your frontend embeds.</p>';
296
  }
297
 
298
  /**
@@ -320,7 +310,7 @@ class Settings
320
  echo '</optgroup>';
321
  echo '</select>';
322
 
323
- echo '<p class="description">Choose a different language for your Facebook embeds.</p>';
324
  }
325
 
326
  /**
72
  */
73
  private static $fieldMap = array(
74
  'enablePluginInAdmin' => array(
75
+ 'label' => "Load previews in the admin editor",
76
  'section' => "admin"
77
  ),
78
+ 'enablePluginInFront' => array(
79
+ 'label' => "Load previews in the frontend editor",
80
  'section' => "admin"
81
  ),
82
  'forceFacebookLanguage' => array(
83
+ 'label' => "Facebook embed language",
84
  'section' => "admin"
85
  )
86
  );
135
  } else {
136
  register_setting(self::$sectionGroupIdentifier, self::$sectionGroupIdentifier, array(self::$namespace, "validateForm"));
137
 
138
+ add_settings_section(self::$sectionAdminIdentifier, '', null, self::$identifier);
139
 
140
  foreach (self::$fieldMap as $fieldName => $field) {
141
  add_settings_field($fieldName, $field['label'], array(self::$namespace, "renderField_{$fieldName}"), self::$identifier, self::${"section". ucfirst($field['section']) ."Identifier"});
157
  ?>
158
  <div id="embedpress-settings-wrapper">
159
  <header>
 
 
160
  <a href="//wordpress.org/plugins/embedpress" target="_blank" rel="noopener noreferrer" title="EmbedPress" class="presshack-logo">
161
+ <img width="35" src="//pressshack.com/wp-content/uploads/2016/05/embedpress-150x150.png">
162
  </a>
163
+ <h1>EmbedPress</h1>
164
  </header>
165
 
166
  <?php settings_errors(); ?>
167
 
168
+ <div>
169
+ <h2 class="nav-tab-wrapper">
170
+ <a href="?page=embedpress" class="nav-tab<?php echo $activeTab === 'embedpress' || empty($activeTab) ? ' nav-tab-active' : ''; ?> ">General settings</a>
 
 
171
 
172
+ <?php do_action('embedpress:settings:render:tab', $activeTab); ?>
173
+ </h2>
 
174
 
175
+ <form action="options.php" method="POST" style="padding-bottom: 20px;">
176
+ <?php settings_fields($settingsFieldsIdentifier); ?>
177
+ <?php do_settings_sections($settingsSectionsIdentifier); ?>
178
 
179
+ <button type="submit" class="button button-primary">Save changes</button>
180
+ </form>
181
+ </div>
182
 
183
+ <footer>
184
+ <p>
185
+ <a href="//wordpress.org/support/plugin/embedpress/reviews/#new-post" target="_blank" rel="noopener noreferrer">If you like <strong>EmbedPress</strong> please leave us a <span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span> rating. Thank you!</a>
186
+ </p>
187
+ <hr>
188
+ <nav>
189
  <ul>
190
  <li>
191
  <a href="//pressshack.com/embedpress" target="_blank" rel="noopener noreferrer" title="About EmbedPress">About</a>
202
  <li>
203
  <a href="//pressshack.com/contact" target="_blank" rel="noopener noreferrer" title="Contact the PressShack team">Contact</a>
204
  </li>
 
 
205
  <li>
206
  <a href="//twitter.com/pressshack" target="_blank" rel="noopener noreferrer">
207
  <span class="dashicons dashicons-twitter"></span>
208
  </a>
209
  </li>
210
  <li>
211
+ <a href="//facebook.com/pressshack" target="_blank" rel="noopener noreferrer">
212
  <span class="dashicons dashicons-facebook"></span>
213
  </a>
214
  </li>
215
  </ul>
216
+ </nav>
 
217
  <p>
 
 
 
218
  <a href="//pressshack.com" target="_blank" rel="noopener noreferrer">
219
+ <img width="100" src="//pressshack.com/wp-content/uploads/2016/11/logo-450.png">
220
  </a>
221
  </p>
 
222
  </footer>
223
  </div>
224
  <?php
237
  public static function validateForm($freshData)
238
  {
239
  $data = array(
 
240
  'enablePluginInAdmin' => (bool)$freshData['enablePluginInAdmin'],
241
+ 'enablePluginInFront' => (bool)$freshData['enablePluginInFront'],
242
  'fbLanguage' => $freshData['fbLanguage']
243
  );
244
 
246
  }
247
 
248
  /**
249
+ * Method that renders the enablePluginInAdmin input.
250
  *
251
  * @since 1.0.0
252
  * @static
253
  */
254
+ public static function renderField_enablePluginInAdmin()
255
  {
256
+ $fieldName = "enablePluginInAdmin";
257
 
258
  $options = get_option(self::$sectionGroupIdentifier);
259
 
260
+ $options[$fieldName] = !isset($options[$fieldName]) ? true : (bool)$options[$fieldName];
 
 
 
 
 
 
261
 
262
  echo '<label><input type="radio" id="'. $fieldName .'_0" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="0" '. (!$options[$fieldName] ? "checked" : "") .' /> No</label>';
263
  echo "&nbsp;&nbsp;";
264
  echo '<label><input type="radio" id="'. $fieldName .'_1" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="1" '. ($options[$fieldName] ? "checked" : "") .' /> Yes</label>';
265
+ echo '<p class="description">Do you want EmbedPress to run here in the admin area? Disabling this <strong>will not</strong> affect your frontend embeds.</p>';
266
  }
267
 
268
  /**
269
+ * Method that renders the enablePluginInFront input.
270
  *
271
+ * @since 1.6.0
272
  * @static
273
  */
274
+ public static function renderField_enablePluginInFront()
275
  {
276
+ $fieldName = "enablePluginInFront";
277
 
278
  $options = get_option(self::$sectionGroupIdentifier);
279
 
282
  echo '<label><input type="radio" id="'. $fieldName .'_0" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="0" '. (!$options[$fieldName] ? "checked" : "") .' /> No</label>';
283
  echo "&nbsp;&nbsp;";
284
  echo '<label><input type="radio" id="'. $fieldName .'_1" name="'. self::$sectionGroupIdentifier .'['. $fieldName .']" value="1" '. ($options[$fieldName] ? "checked" : "") .' /> Yes</label>';
285
+ echo '<p class="description">Do you want EmbedPress to run within editors in frontend (if there\'s any)? Disabling this <strong>will not</strong> affect embeds seem by your regular users in frontend.</p>';
286
  }
287
 
288
  /**
310
  echo '</optgroup>';
311
  echo '</select>';
312
 
313
+ echo '<p class="description">Sometimes Facebook can choose the wrong language for embeds. If this happens, choose the correct language here.</p>';
314
  }
315
 
316
  /**
EmbedPress/Ends/Front/Handler.php CHANGED
@@ -2,7 +2,9 @@
2
  namespace EmbedPress\Ends\Front;
3
 
4
  use \EmbedPress\Ends\Handler as EndHandlerAbstract;
 
5
  use \EmbedPress\Shortcode;
 
6
 
7
  (defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed.");
8
 
@@ -75,4 +77,27 @@ class Handler extends EndHandlerAbstract
75
 
76
  return $match[1] . $return . $match[3];
77
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  }
2
  namespace EmbedPress\Ends\Front;
3
 
4
  use \EmbedPress\Ends\Handler as EndHandlerAbstract;
5
+ use \EmbedPress\Ends\Back\Handler as BackEndHandler;
6
  use \EmbedPress\Shortcode;
7
+ use \EmbedPress\Core;
8
 
9
  (defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed.");
10
 
77
 
78
  return $match[1] . $return . $match[3];
79
  }
80
+
81
+ /**
82
+ * A callback called by the WP `the_editor` filter.
83
+ *
84
+ * @since 1.6.0
85
+ * @static
86
+ *
87
+ * @param string $editorHTML The HTML which will be rendered as an editor, like TinyMCE.
88
+ *
89
+ * @return string The HTML which will be rendered as an editor, like TinyMCE
90
+ */
91
+ public static function renderPreviewBoxInEditors($editorHTML)
92
+ {
93
+ $plgSettings = Core::getSettings();
94
+
95
+ if (!is_admin() && (bool)$plgSettings->enablePluginInFront) {
96
+ $backEndHandler = new BackEndHandler(EMBEDPRESS_PLG_NAME, EMBEDPRESS_PLG_VERSION);
97
+
98
+ $backEndHandler->enqueueScripts();
99
+ }
100
+
101
+ return $editorHTML;
102
+ }
103
  }
EmbedPress/Shortcode.php CHANGED
@@ -79,6 +79,9 @@ class Shortcode
79
 
80
  $content = preg_replace('/(\['. EMBEDPRESS_SHORTCODE .'(?:\]|.+?\])|\[\/'. EMBEDPRESS_SHORTCODE .'\])/i', "", $subject);
81
 
 
 
 
82
  // Check if the WP_oEmbed class is loaded
83
  if (!self::$oEmbedInstance) {
84
  require_once ABSPATH .'wp-includes/class-oembed.php';
@@ -228,11 +231,11 @@ class Shortcode
228
  $parsedContent = preg_replace('/((?:ose-)?\{provider_alias\})/i', "ose-". strtolower($urlData->provider_name), $parsedContent);
229
  }
230
 
231
- if (isset($urlData->provider_name)) {
232
  // NFB seems to always return their embed code with all HTML entities into their applicable characters string.
233
- if (strtoupper($urlData->provider_name) === "NATIONAL FILM BOARD OF CANADA") {
234
  $parsedContent = html_entity_decode($parsedContent);
235
- } else if (strtoupper($urlData->provider_name) === "FACEBOOK") {
236
  $plgSettings = Core::getSettings();
237
 
238
  // Check if the user wants to force a certain language into Facebook embeds.
@@ -242,6 +245,11 @@ class Shortcode
242
  $parsedContent = preg_replace('/\/[a-z]{2}\_[a-z]{2}\/sdk\.js/i', "/{$locale}/sdk.js", $parsedContent);
243
  }
244
 
 
 
 
 
 
245
  unset($locale, $plgSettings);
246
  }
247
  }
@@ -254,24 +262,44 @@ class Shortcode
254
  $customWidth = (int)$emberaInstanceSettings['params']['width'];
255
  $customHeight = (int)$emberaInstanceSettings['params']['height'];
256
  } else {
257
- preg_match_all('/\<iframe\s+width="(\d+)"\s+height="(\d+)"/i', $parsedContent, $matches);
258
- $iframeWidth = (int)$matches[1][0];
259
- $iframeHeight = (int)$matches[2][0];
260
- $iframeRatio = ceil($iframeWidth / $iframeHeight);
261
-
262
- if (isset($emberaInstanceSettings['params']['width'])) {
263
- $customWidth = (int)$emberaInstanceSettings['params']['width'];
264
- $customHeight = ceil($customWidth / $iframeRatio);
265
- } else {
266
- $customHeight = (int)$emberaInstanceSettings['params']['height'];
267
- $customWidth = $iframeRatio * $customHeight;
268
  }
269
 
270
- unset($iframeRatio, $iframeHeight, $iframeWidth, $matches);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  }
272
 
273
- $parsedContent = preg_replace('/\s+width\=\"(\d+)\"/i', ' width="'. $customWidth .'"', $parsedContent);
274
- $parsedContent = preg_replace('/\s+height\=\"(\d+)\"/i', ' height="'. $customHeight .'"', $parsedContent);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  }
276
 
277
  if ($stripNewLine) {
79
 
80
  $content = preg_replace('/(\['. EMBEDPRESS_SHORTCODE .'(?:\]|.+?\])|\[\/'. EMBEDPRESS_SHORTCODE .'\])/i', "", $subject);
81
 
82
+ // Converts any special HTML entities back to characters.
83
+ $content = htmlspecialchars_decode($content);
84
+
85
  // Check if the WP_oEmbed class is loaded
86
  if (!self::$oEmbedInstance) {
87
  require_once ABSPATH .'wp-includes/class-oembed.php';
231
  $parsedContent = preg_replace('/((?:ose-)?\{provider_alias\})/i', "ose-". strtolower($urlData->provider_name), $parsedContent);
232
  }
233
 
234
+ if (isset($urlData->provider_name) || isset($urlData[$content]['provider_name'])) {
235
  // NFB seems to always return their embed code with all HTML entities into their applicable characters string.
236
+ if ((isset($urlData->provider_name) && strtoupper($urlData->provider_name) === "NATIONAL FILM BOARD OF CANADA") || (is_array($urlData) && isset($urlData[$content]['provider_name']) && strtoupper($urlData[$content]['provider_name']) === "NATIONAL FILM BOARD OF CANADA")) {
237
  $parsedContent = html_entity_decode($parsedContent);
238
+ } else if ((isset($urlData->provider_name) && strtoupper($urlData->provider_name) === "FACEBOOK") || (is_array($urlData) && isset($urlData[$content]['provider_name']) && strtoupper($urlData[$content]['provider_name']) === "FACEBOOK")) {
239
  $plgSettings = Core::getSettings();
240
 
241
  // Check if the user wants to force a certain language into Facebook embeds.
245
  $parsedContent = preg_replace('/\/[a-z]{2}\_[a-z]{2}\/sdk\.js/i', "/{$locale}/sdk.js", $parsedContent);
246
  }
247
 
248
+ // Make sure `adapt_container_width` parameter is set to false. Setting to true, as it is by default, might cause Facebook to render embeds inside editors (in admin) with only 180px wide.
249
+ if (is_admin()) {
250
+ $parsedContent = preg_replace('~data\-adapt\-container\-width=\"(?:true|1)\"~i', 'data-adapt-container-width="0"', $parsedContent);
251
+ }
252
+
253
  unset($locale, $plgSettings);
254
  }
255
  }
262
  $customWidth = (int)$emberaInstanceSettings['params']['width'];
263
  $customHeight = (int)$emberaInstanceSettings['params']['height'];
264
  } else {
265
+ if (preg_match('~width="(\d+)"|width\s+:\s+(\d+)~i', $parsedContent, $matches)) {
266
+ $iframeWidth = (int)$matches[1];
 
 
 
 
 
 
 
 
 
267
  }
268
 
269
+ if (preg_match('~height="(\d+)"|height\s+:\s+(\d+)~i', $parsedContent, $matches)) {
270
+ $iframeHeight = (int)$matches[1];
271
+ }
272
+
273
+ if (isset($iframeWidth) && isset($iframeHeight) && $iframeWidth > 0 && $iframeHeight > 0) {
274
+ $iframeRatio = ceil($iframeWidth / $iframeHeight);
275
+
276
+ if (isset($emberaInstanceSettings['params']['width'])) {
277
+ $customWidth = (int)$emberaInstanceSettings['params']['width'];
278
+ $customHeight = ceil($customWidth / $iframeRatio);
279
+ } else {
280
+ $customHeight = (int)$emberaInstanceSettings['params']['height'];
281
+ $customWidth = $iframeRatio * $customHeight;
282
+ }
283
+ }
284
  }
285
 
286
+ if (isset($customWidth) && isset($customHeight)) {
287
+ if (preg_match('~width="(\d+)"~i', $parsedContent)) {
288
+ $parsedContent = preg_replace('~width="(\d+)"~i', 'width="'. $customWidth .'"', $parsedContent);
289
+ }
290
+
291
+ if (preg_match('~height="(\d+)"~i', $parsedContent)) {
292
+ $parsedContent = preg_replace('~height="(\d+)"~i', 'height="'. $customHeight .'"', $parsedContent);
293
+ }
294
+
295
+ if (preg_match('~width\s+:\s+(\d+)~i', $parsedContent)) {
296
+ $parsedContent = preg_replace('~width\s+:\s+(\d+)~i', 'width: '. $customWidth, $parseContent);
297
+ }
298
+
299
+ if (preg_match('~height\s+:\s+(\d+)~i', $parsedContent)) {
300
+ $parsedContent = preg_replace('~height\s+:\s+(\d+)~i', 'height: '. $customHeight, $parseContent);
301
+ }
302
+ }
303
  }
304
 
305
  if ($stripNewLine) {
assets/css/admin.css CHANGED
@@ -58,80 +58,34 @@
58
  /**
59
  * EmbedPress Settings Wrapper.
60
  */
61
- #embedpress-settings-wrapper #setting-error-settings_updated {
62
- margin-top: 42px;
63
- }
64
-
65
- #embedpress-settings-wrapper .nav-tab-wrapper .nav-tab:not(.nav-tab-active):hover {
66
- color: #555;
67
- }
68
-
69
- #embedpress-settings-wrapper .nav-tab-wrapper .nav-tab-active {
70
- border-top: 2px solid #655997;
71
- color: #655997;
72
- }
73
-
74
- #embedpress-settings-wrapper > header {
75
- display: -webkit-box;
76
- display: -moz-box;
77
- display: -ms-flexbox;
78
- display: -webkit-flex;
79
- display: flex;
80
- flex-direction: row;
81
- justify-content: space-between;
82
- }
83
-
84
- #embedpress-settings-wrapper > header h1 small {
85
- font-size: .5em;
86
- margin-left: 15px;
87
- }
88
-
89
- #embedpress-settings-wrapper > header h1 small a {
90
- color: #777;
91
- text-decoration: none;
92
- }
93
-
94
- #embedpress-settings-wrapper > header > a {
95
- margin-right: 16px;
96
- margin-top: 10px;
97
- max-height: 30px;
98
- }
99
 
100
- #embedpress-settings-wrapper > header > a img {
101
- padding-top: 5px;
102
  }
103
 
104
- #embedpress-settings-wrapper a {
105
- color: #777;
106
  }
107
 
108
- #embedpress-settings-wrapper a:link,
109
- #embedpress-settings-wrapper a:visited,
110
- #embedpress-settings-wrapper a:active,
111
- #embedpress-settings-wrapper a:hover {
112
- text-decoration: none;
113
  }
114
 
115
- #embedpress-settings-wrapper > header a img,
116
- #embedpress-settings-wrapper a,
117
- #embedpress-settings-wrapper button,
118
- #embedpress-settings-wrapper button::before {
119
- -webkit-transition: all 200ms ease-in-out;
120
- -moz-transition: all 200ms ease-in-out;
121
- -o-transition: all 200ms ease-in-out;
122
- transition: all 200ms ease-in-out;
123
  }
124
 
125
- #embedpress-settings-wrapper a:hover {
126
- color: #9D94C9;
 
127
  }
128
 
129
- #embedpress-settings-wrapper a:hover img {
130
- -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=75)";
131
- filter: alpha(opacity=75);
132
- -moz-opacity: .75;
133
- -khtml-opacity: .75;
134
- opacity: .75;
135
  }
136
 
137
  #embedpress-settings-wrapper input:not([type="checkbox"]):not([type="radio"]) {
@@ -165,30 +119,75 @@
165
  background-color: #9D94C9;
166
  }
167
 
168
- #embedpress-settings-wrapper button:not(.notice-dismiss) {
169
- -webkit-border-radius: 5px;
170
- -moz-border-radius: 5px;
171
- border-radius: 5px;
172
- text-shadow: initial;
173
- -webkit-box-shadow: initial;
174
- -moz-box-shadow: initial;
175
- box-shadow: initial;
176
- vertical-align: middle;
177
- line-height: 0;
178
- min-height: 28px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  text-decoration: none;
180
- padding: 15px 10px;
181
- border-width: 2px;
182
- border-style: solid;
183
  }
184
 
185
- #embedpress-settings-wrapper button:not(.notice-dismiss):hover,
186
- #embedpress-settings-wrapper button:not(.notice-dismiss):active,
187
- #embedpress-settings-wrapper button:not(.notice-dismiss):focus {
188
- outline: none;
189
- -webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 1px 2px rgba(0, 0, 0, 0.05);
190
- -moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 1px 2px rgba(0, 0, 0, 0.05);
191
- box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 1px 2px rgba(0, 0, 0, 0.05);
192
  }
193
 
194
  #embedpress-settings-wrapper .button-primary {
@@ -214,20 +213,37 @@
214
  background-color: #5A4F87;
215
  }
216
 
217
- #embedpress-settings-footer > div {
218
- display: -webkit-box;
219
- display: -moz-box;
220
- display: -ms-flexbox;
221
- display: -webkit-flex;
222
- display: flex;
223
- justify-content: space-between;
224
- padding-right: 16px;
 
 
 
 
 
 
 
225
  }
226
 
227
- #embedpress-settings-footer > div ul li {
228
- display: inline;
 
 
 
 
 
229
  }
230
 
231
- #embedpress-settings-footer > div ul li:not(:first-child) {
232
- margin-left: 15px;
 
 
 
 
 
233
  }
58
  /**
59
  * EmbedPress Settings Wrapper.
60
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
+ #embedpress-settings-wrapper {
63
+ margin-top: 20px;
64
  }
65
 
66
+ #embedpress-settings-wrapper > header > * {
67
+ display: inline-block;
68
  }
69
 
70
+ #embedpress-settings-wrapper > header h1 {
71
+ margin: .67em 0 15px .15em;
 
 
 
72
  }
73
 
74
+ #embedpress-settings-wrapper a:hover img {
75
+ -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
76
+ filter: alpha(opacity=80);
77
+ -moz-opacity: .80;
78
+ -khtml-opacity: .80;
79
+ opacity: .80;
 
 
80
  }
81
 
82
+ #embedpress-settings-wrapper .nav-tab-wrapper .nav-tab-active {
83
+ border-top: 2px solid #655997;
84
+ color: #655997;
85
  }
86
 
87
+ #embedpress-settings-wrapper .nav-tab-wrapper .nav-tab:not(.nav-tab-active):hover {
88
+ color: #555;
 
 
 
 
89
  }
90
 
91
  #embedpress-settings-wrapper input:not([type="checkbox"]):not([type="radio"]) {
119
  background-color: #9D94C9;
120
  }
121
 
122
+ #embedpress-settings-wrapper > footer {
123
+ text-align: center;
124
+ }
125
+
126
+ #embedpress-settings-wrapper > footer p {
127
+ color: #666;
128
+ font-size: 12px;
129
+ }
130
+
131
+ #embedpress-settings-wrapper > footer .dashicons {
132
+ font-size: 16px;
133
+ width: 16px;
134
+ height: 16px;
135
+ }
136
+
137
+ #embedpress-settings-wrapper > footer .dashicons.dashicons-star-filled {
138
+ line-height: 18px;
139
+ font-size: 12px;
140
+ width: 12px;
141
+ height: 12px;
142
+ color: #FFB300;
143
+ -webkit-transition: color 200ms ease-in-out;
144
+ -moz-transition: color 200ms ease-in-out;
145
+ -o-transition: color 200ms ease-in-out;
146
+ transition: color 200ms ease-in-out;
147
+ }
148
+
149
+ #embedpress-settings-wrapper > footer a:hover .dashicons.dashicons-star-filled {
150
+ color: #C58C07;
151
+ }
152
+
153
+ #embedpress-settings-wrapper > footer > nav ul {
154
+ list-style: none;
155
+ }
156
+
157
+ #embedpress-settings-wrapper > footer > nav ul > li {
158
+ display: inline-block;
159
+ }
160
+
161
+ #embedpress-settings-wrapper > footer > nav ul > li:not(:first-child) {
162
+ margin-left: 15px;
163
+ }
164
+
165
+ #embedpress-settings-wrapper > footer > nav ul > li > a {
166
+ font-weight: bold;
167
+ }
168
+
169
+ #embedpress-settings-wrapper a {
170
+ color: #777;
171
+ }
172
+
173
+ #embedpress-settings-wrapper a,
174
+ #embedpress-settings-wrapper button
175
+ #embedpress-settings-wrapper button::before {
176
+ -webkit-transition: all 200ms ease-in-out;
177
+ -moz-transition: all 200ms ease-in-out;
178
+ -o-transition: all 200ms ease-in-out;
179
+ transition: all 200ms ease-in-out;
180
+ }
181
+
182
+ #embedpress-settings-wrapper a:link,
183
+ #embedpress-settings-wrapper a:visited,
184
+ #embedpress-settings-wrapper a:active,
185
+ #embedpress-settings-wrapper a:hover {
186
  text-decoration: none;
 
 
 
187
  }
188
 
189
+ #embedpress-settings-wrapper a:hover {
190
+ color: #9D94C9;
 
 
 
 
 
191
  }
192
 
193
  #embedpress-settings-wrapper .button-primary {
213
  background-color: #5A4F87;
214
  }
215
 
216
+ #embedpress-settings-wrapper button:not(.notice-dismiss) {
217
+ -webkit-border-radius: 5px;
218
+ -moz-border-radius: 5px;
219
+ border-radius: 5px;
220
+ text-shadow: initial;
221
+ -webkit-box-shadow: initial;
222
+ -moz-box-shadow: initial;
223
+ box-shadow: initial;
224
+ vertical-align: middle;
225
+ line-height: 0;
226
+ min-height: 28px;
227
+ text-decoration: none;
228
+ padding: 15px 10px;
229
+ border-width: 2px;
230
+ border-style: solid;
231
  }
232
 
233
+ #embedpress-settings-wrapper button:not(.notice-dismiss):hover,
234
+ #embedpress-settings-wrapper button:not(.notice-dismiss):active,
235
+ #embedpress-settings-wrapper button:not(.notice-dismiss):focus {
236
+ outline: none;
237
+ -webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 1px 2px rgba(0, 0, 0, 0.05);
238
+ -moz-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 1px 2px rgba(0, 0, 0, 0.05);
239
+ box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 1px 2px rgba(0, 0, 0, 0.05);
240
  }
241
 
242
+ #embedpress-settings-wrapper > #setting-error-settings_updated {
243
+ margin-left: 0;
244
+ margin-bottom: 15px;
245
+ }
246
+
247
+ #embedpress-settings-wrapper > #setting-error-settings_updated button.notice-dismiss:hover::before {
248
+ color: #655997;
249
  }
assets/css/embedpress.css CHANGED
@@ -18,6 +18,7 @@
18
  .ose-amcharts.responsive,
19
  .ose-on-aol-com.responsive,
20
  .ose-animoto.responsive,
 
21
  .ose-videojug.responsive {
22
  overflow: hidden;
23
  position: relative;
@@ -37,6 +38,7 @@
37
  .ose-amcharts.responsive iframe,
38
  .ose-on-aol-com.responsive iframe,
39
  .ose-animoto.responsive iframe,
 
40
  .ose-videojug.responsive iframe {
41
  left: 0;
42
  top: 0;
@@ -83,3 +85,7 @@
83
  .ose-google-docs.ose-google-docs-spreadsheets.responsive {
84
  padding-bottom: 142%;
85
  }
 
 
 
 
18
  .ose-amcharts.responsive,
19
  .ose-on-aol-com.responsive,
20
  .ose-animoto.responsive,
21
+ .ose-soundcloud.responsive,
22
  .ose-videojug.responsive {
23
  overflow: hidden;
24
  position: relative;
38
  .ose-amcharts.responsive iframe,
39
  .ose-on-aol-com.responsive iframe,
40
  .ose-animoto.responsive iframe,
41
+ .ose-soundcloud.responsive iframe,
42
  .ose-videojug.responsive iframe {
43
  left: 0;
44
  top: 0;
85
  .ose-google-docs.ose-google-docs-spreadsheets.responsive {
86
  padding-bottom: 142%;
87
  }
88
+
89
+ .ose-soundcloud.responsive {
90
+ padding-bottom: 155px;
91
+ }
assets/js/preview.js CHANGED
@@ -5,7 +5,6 @@
5
  * @license GPLv2 or later
6
  * @since 1.0
7
  */
8
-
9
  (function($, String, $data, undefined) {
10
  "use strict";
11
 
@@ -148,10 +147,6 @@
148
  }
149
  };
150
 
151
- if (!$data.displayPreviewBox.length || $data.displayPreviewBox.isFalse()) {
152
- return;
153
- }
154
-
155
  var SHORTCODE_REGEXP = new RegExp('\\[\/?'+ $data.EMBEDPRESS_SHORTCODE +'\\]', "gi");
156
 
157
  var EmbedPress = function() {
@@ -166,7 +161,7 @@
166
  * @type Object
167
  */
168
  self.params = {
169
- juriRoot: '',
170
  versionUID: '0'
171
  };
172
 
@@ -190,6 +185,12 @@
190
  */
191
  self.activeControllerPanel = null;
192
 
 
 
 
 
 
 
193
  /**
194
  * Init the plugin
195
  *
@@ -235,21 +236,21 @@
235
  return text;
236
  };
237
 
238
- self.loadAsyncDynamicJsCodeFromElement = function(subject, wrapper)
239
  {
240
  subject = $(subject);
241
  if (subject.prop('tagName').toLowerCase() === "script") {
242
  var scriptSrc = subject.attr('src') || null;
243
  if (!scriptSrc) {
244
- self.addScriptDeclaration(wrapper, subject.html());
245
  } else {
246
- self.addScript(scriptSrc, null, wrapper);
247
  }
248
  } else {
249
  var innerScriptsList = $('script', subject);
250
  if (innerScriptsList.length > 0) {
251
  $.each(innerScriptsList, function(innerScriptIndex, innerScript) {
252
- self.loadAsyncDynamicJsCodeFromElement(innerScript, wrapper);
253
  });
254
  }
255
  }
@@ -265,18 +266,20 @@
265
  // Wait until the editor is available
266
  var interval = window.setInterval(
267
  function() {
 
 
 
268
 
269
- // @todo: Support multiple editors
270
- self.editor = self.getEditor();
 
271
 
272
- if (self.editor !== null) {
273
  window.clearInterval(interval);
274
- interval = null;
275
 
276
- self.onFindEditor();
277
  }
278
  },
279
- 200
280
  );
281
  }
282
  };
@@ -301,16 +304,12 @@
301
  * Returns the editor
302
  * @return Object The editor
303
  */
304
- self.getEditor = function() {
305
  if (!window.tinymce || !window.tinymce.editors || window.tinymce.editors.length === 0) {
306
- return null;
307
  }
308
 
309
- if (!window.tinymce.editors.content) {
310
- return null;
311
- }
312
-
313
- return window.tinymce.editors.content;
314
  };
315
 
316
  /**
@@ -325,7 +324,7 @@
325
  // Get the parsed content
326
  $.ajax({
327
  type: 'POST',
328
- url: "admin-ajax.php",
329
  data: {
330
  action: "embedpress_do_ajax_request",
331
  subject: content
@@ -336,8 +335,8 @@
336
  });
337
  };
338
 
339
- self.addStylesheet = function(url) {
340
- var head = self.editor.getDoc().getElementsByTagName('head')[0];
341
 
342
  var $style = $('<link rel="stylesheet" type="text/css" href="' + url + '">');
343
  $style.appendTo(head);
@@ -626,8 +625,8 @@
626
  return patterns;
627
  };
628
 
629
- self.addScript = function(source, callback, wrapper) {
630
- var doc = self.editor.getDoc();
631
 
632
  if (typeof wrapper === 'undefined' || !wrapper) {
633
  wrapper = $(doc.getElementsByTagName('head')[0]);
@@ -645,8 +644,8 @@
645
  wrapper.append($script);
646
  };
647
 
648
- self.addScriptDeclaration = function(wrapper, declaration) {
649
- var doc = self.editor.getDoc(),
650
  $script = $(doc.createElement('script'));
651
 
652
  $(wrapper).append($script);
@@ -654,7 +653,7 @@
654
  $script.text(declaration);
655
  };
656
 
657
- self.addURLsPlaceholder = function(node, url) {
658
  var uid = self.makeId();
659
 
660
  var wrapperClasses = ["embedpress_wrapper", "embedpress_placeholder", "wpview", "wpview-wrap"];
@@ -763,13 +762,13 @@
763
 
764
  // Trigger the timeout which will load the content
765
  window.setTimeout(function() {
766
- self.parseContentAsync(uid, url, customAttributes);
767
  }, 200);
768
 
769
  return wrapper;
770
  };
771
 
772
- self.parseContentAsync = function(uid, url, customAttributes) {
773
  customAttributes = typeof customAttributes === "undefined" ? {} : customAttributes;
774
 
775
  url = self.decodeEmbedURLSpecialChars(url, true, customAttributes);
@@ -786,7 +785,7 @@
786
  self.getParsedContent(url, function getParsedContentCallback(result) {
787
  var embeddedContent = (typeof result.data === "object" ? result.data.embed : result.data).stripShortcode($data.EMBEDPRESS_SHORTCODE);
788
 
789
- var $wrapper = $(self.getElementInContentById('embedpress_wrapper_' + uid));
790
  var wrapperParent = $($wrapper.parent());
791
 
792
  // Check if $wrapper was rendered inside a <p> element.
@@ -824,21 +823,21 @@
824
  var contentWrapper = $($content).clone();
825
  contentWrapper.html('');
826
 
827
- var dom = self.editor.dom;
828
 
829
  $wrapper.removeClass('embedpress_placeholder');
830
 
831
  $wrapper.append(contentWrapper);
832
 
833
  setTimeout(function() {
834
- self.editor.undoManager.transact(function() {
835
- var iframe = self.editor.getDoc().createElement('iframe');
836
  iframe.src = tinymce.Env.ie ? 'javascript:""' : '';
837
  iframe.frameBorder = '0';
838
  iframe.allowTransparency = 'true';
839
  iframe.scrolling = 'no';
840
  iframe.class = "wpview-sandbox";
841
- iframe.style.width = (customAttributes.width ? customAttributes.width +'px' : '');
842
 
843
  dom.add(contentWrapper, iframe);
844
  var iframeWindow = iframe.contentWindow;
@@ -852,30 +851,28 @@
852
  $(iframe).load(function() {
853
  var maximumChecksAllowed = 8;
854
  var checkIndex = 0;
 
855
  var checkerInterval = setInterval(function() {
856
  if (checkIndex === maximumChecksAllowed) {
857
  clearInterval(checkerInterval);
858
 
859
  setTimeout(function() {
860
- iframe.height = $(iframeWindow).height();
861
- iframe.width = $(iframeWindow).width();
862
-
863
- $wrapper.attr('width', iframe.width);
864
- $wrapper.css('width', iframe.width + 'px');
865
  }, 100);
866
  } else {
867
  if (customAttributes.height) {
868
  iframe.height = customAttributes.height;
869
  iframe.style.height = customAttributes.height +'px';
870
  } else {
871
- iframe.height = iframeDoc.body.scrollHeight;
872
  }
873
 
874
  if (customAttributes.width) {
875
  iframe.width = customAttributes.width;
876
  iframe.style.width = customAttributes.width +'px';
877
  } else {
878
- iframe.width = $(iframeDoc).width();
879
  }
880
 
881
  checkIndex++;
@@ -907,7 +904,7 @@
907
  '}'+
908
  '</style>'+
909
  '</head>'+
910
- '<body id="wpview-iframe-sandbox" class="'+ self.editor.getBody().className +'" style="display: inline-block;">'+
911
  $content.html() +
912
  '</body>'+
913
  '</html>'
@@ -918,10 +915,9 @@
918
  } else {
919
  $wrapper.removeClass('embedpress_placeholder');
920
 
921
- self.appendElementsIntoWrapper($content, $wrapper);
922
  }
923
 
924
- //$wrapper.append($('<span class="mce-shim"></span>'));
925
  $wrapper.append($('<span class="wpview-end"></span>'));
926
 
927
  if (result && result.data && typeof result.data === "object") {
@@ -937,7 +933,7 @@
937
  });
938
  };
939
 
940
- self.appendElementsIntoWrapper = function(elementsList, wrapper) {
941
  if (elementsList.length > 0) {
942
  $.each(elementsList, function appendElementIntoWrapper(elementIndex, element) {
943
  // Check if the element is a script and do not add it now (if added here it wouldn't be executed)
@@ -947,7 +943,7 @@
947
  if (element.tagName.toLowerCase() === 'iframe') {
948
  $(element).ready(function() {
949
  window.setTimeout(function() {
950
- $.each(self.editor.dom.select('div.embedpress_wrapper iframe'), function(elementIndex, iframe) {
951
  self.fixIframeSize(iframe);
952
  });
953
  }, 300);
@@ -962,7 +958,7 @@
962
  }
963
  }
964
 
965
- self.loadAsyncDynamicJsCodeFromElement(element, wrapper);
966
  });
967
  }
968
 
@@ -1064,7 +1060,7 @@
1064
  *
1065
  * @return void
1066
  */
1067
- self.onFindEditor = function() {
1068
  self.each = tinymce.each;
1069
  self.extend = tinymce.extend;
1070
  self.JSON = tinymce.util.JSON;
@@ -1073,25 +1069,37 @@
1073
  function onFindEditorCallback() {
1074
  $(window.document.getElementsByTagName('head')[0]).append($('<link rel="stylesheet" type="text/css" href="' + (PLG_SYSTEM_ASSETS_CSS_PATH + '/vendor/bootstrap/bootstrap.min.css?v=' + self.params.versionUID) + '">'));
1075
 
1076
- self.addStylesheet(PLG_SYSTEM_ASSETS_CSS_PATH + '/font.css?v=' + self.params.versionUID);
1077
- self.addStylesheet(PLG_SYSTEM_ASSETS_CSS_PATH + '/preview.css?v=' + self.params.versionUID);
1078
- self.addStylesheet(PLG_CONTENT_ASSETS_CSS_PATH + '/embedpress.css?v=' + self.params.versionUID);
1079
- self.addEvent('paste', self.editor, self.onPaste);
1080
- self.addEvent('nodechange', self.editor, self.onNodeChange);
1081
- self.addEvent('keydown', self.editor, self.onKeyDown);
 
 
 
 
1082
 
1083
- self.addEvent('undo', self.editor, self.onUndo); // TinyMCE
1084
- self.addEvent('undo', self.editor.undoManager, self.onUndo); // JCE
 
1085
 
1086
- var doc = self.editor.getDoc();
1087
- $(doc).on('mouseenter', '.embedpress_wrapper', self.onMouseEnter);
 
 
 
 
 
1088
  $(doc).on('mouseout', '.embedpress_wrapper', self.onMouseOut);
1089
- $(doc).on('mousedown', '.embedpress_wrapper > .embedpress_controller_panel', self.cancelEvent);
 
 
1090
  doc = null;
1091
  // Add the node filter that will convert the url into the preview box for the embed code
1092
  // @todo: Recognize <a> tags as well
1093
 
1094
- self.editor.parser.addNodeFilter('#text', function addNodeFilterIntoParser(nodes, arg) {
1095
  self.each(nodes, function eachNodeInParser(node) {
1096
  var subject = node.value.trim();
1097
  if (!subject.isValidUrl()) {
@@ -1124,10 +1132,10 @@
1124
  if (matches && matches !== null && !!matches.length) {
1125
  url = self.encodeEmbedURLSpecialChars(matches[2]);
1126
 
1127
- var wrapper = self.addURLsPlaceholder(node, url);
1128
 
1129
  setTimeout(function() {
1130
- var doc = self.editor.getDoc();
1131
 
1132
  var previewWrapper = $(doc.querySelector('#'+ wrapper.attributes.map['id']));
1133
  var previewWrapperParent = $(previewWrapper.parent());
@@ -1158,8 +1166,8 @@
1158
  }
1159
 
1160
  setTimeout(function() {
1161
- self.editor.selection.select(self.editor.getBody(), true);
1162
- self.editor.selection.collapse(false);
1163
  }, 50);
1164
  }, 50);
1165
  } else {
@@ -1172,7 +1180,7 @@
1172
  });
1173
 
1174
  // Add the filter that will convert the preview box/embed code back to the raw url
1175
- self.editor.serializer.addNodeFilter('div', function addNodeFilterIntoSerializer(nodes, arg) {
1176
  self.each(nodes, function eachNodeInSerializer(node) {
1177
  var nodeClasses = (node.attributes.map.class || "").split(' ');
1178
  var wrapperFactoryClasses = ["embedpress_wrapper", "embedpress_placeholder", "wpview", "wpview-wrap"];
@@ -1219,7 +1227,7 @@
1219
  });
1220
  });
1221
 
1222
- self.editor.serializer.addNodeFilter('p', function addNodeFilterIntoSerializer(nodes, arg) {
1223
  self.each(nodes, function eachNodeInSerializer(node) {
1224
  if (node.firstChild == node.lastChild) {
1225
  if (node.firstChild && "value" in node.firstChild && (node.firstChild.value === "&nbsp;" || !node.firstChild.value.trim().length)) {
@@ -1229,10 +1237,11 @@
1229
  });
1230
  });
1231
 
 
1232
  // Add event to reconfigure wrappers every time the content is loaded
1233
  tinymce.each(tinymce.editors, function onEachEditor(editor) {
1234
  self.addEvent('loadContent', editor, function onInitEditor(ed) {
1235
- self.configureWrappers();
1236
  });
1237
  });
1238
 
@@ -1246,7 +1255,7 @@
1246
  * onLoadContent is not being triggered automatically, so
1247
  * we force the event
1248
  */
1249
- self.editor.load();
1250
  },
1251
  // If in JCE the user see the placeholder (img) instead of the iframe after load/refresh the pagr, this time is too short
1252
  500
@@ -1261,7 +1270,7 @@
1261
  clearInterval(statusCheckerInterval);
1262
  alert('For some reason TinyMCE was not fully loaded yet. Please, refresh the page and try again.');
1263
  } else {
1264
- var doc = self.editor.getDoc();
1265
  if (doc) {
1266
  clearInterval(statusCheckerInterval);
1267
  onFindEditorCallback();
@@ -1291,8 +1300,8 @@
1291
  * @param object e The event
1292
  * @return void
1293
  */
1294
- self.onMouseEnter = function(e) {
1295
- self.displayPreviewControllerPanel($(e.currentTarget));
1296
  };
1297
 
1298
  /**
@@ -1332,7 +1341,7 @@
1332
  * @return void
1333
  */
1334
 
1335
- self.onPaste = function(e, b) {
1336
  var urlPatternRegex = new RegExp(/(https?):\/\/([w]{3}\.)?.+?(?:\s|$)/i);
1337
 
1338
  var event = null;
@@ -1383,7 +1392,7 @@
1383
  var content = '<p>'+ contentLines.join('') +'</p>';
1384
 
1385
  // Insert the new content into the editor.
1386
- self.editor.execCommand('mceInsertContent', false, content);
1387
  };
1388
 
1389
  /**
@@ -1423,8 +1432,8 @@
1423
  }
1424
  };
1425
 
1426
- self.onKeyDown = function(e) {
1427
- var node = self.editor.selection.getNode();
1428
 
1429
  if (e.keyCode == 8 || e.keyCode == 46) {
1430
  if (node.nodeName.toLowerCase() === 'p') {
@@ -1435,7 +1444,7 @@
1435
  if ($(this).hasClass('embedpress_wrapper') || $(this).hasClass('embedpress_ignore_mouseout')) {
1436
  $(this).remove();
1437
 
1438
- self.editor.focus();
1439
  }
1440
  });
1441
  }
@@ -1455,8 +1464,8 @@
1455
  var tmpId = '__embedpress__tmp_' + self.makeId();
1456
  wrapper.after($('<span id="' + tmpId + '"></span>'));
1457
  // Get and select the temporary element
1458
- var span = self.editor.dom.select('span#' + tmpId)[0];
1459
- self.editor.selection.select(span);
1460
  // Remove the temporary element
1461
  $(span).remove();
1462
  }
@@ -1464,7 +1473,7 @@
1464
  return true;
1465
  } else {
1466
  // If we are inside the embed preview, ignore any key to avoid edition
1467
- return self.cancelEvent(e);
1468
  }
1469
  }
1470
  }
@@ -1488,15 +1497,15 @@
1488
  return false;
1489
  };
1490
 
1491
- self.onUndo = function(e) {
1492
  // Force re-render everything
1493
- self.editor.load();
1494
  };
1495
 
1496
- self.cancelEvent = function(e) {
1497
  e.preventDefault();
1498
  e.stopPropagation();
1499
- self.editor.dom.events.cancel();
1500
 
1501
  return false;
1502
  };
@@ -1509,9 +1518,9 @@
1509
  * @param Object e The event
1510
  * @return void
1511
  */
1512
- self.onClickEditButton = function(e) {
1513
  // Prevent edition of the panel
1514
- self.cancelEvent(e);
1515
 
1516
  self.activeWrapperForModal = self.activeWrapper;
1517
 
@@ -1544,7 +1553,7 @@
1544
  setTimeout(function() {
1545
  $.ajax({
1546
  type: "GET",
1547
- url: "admin-ajax.php",
1548
  data: {
1549
  action: "embedpress_get_embed_url_info",
1550
  url: self.decodeEmbedURLSpecialChars($wrapper.data('url'), false)
@@ -1622,8 +1631,8 @@
1622
  var $wrapper = self.activeWrapperForModal;
1623
 
1624
  // Select the current wrapper as a base for the new element
1625
- self.editor.focus();
1626
- self.editor.selection.select($wrapper[0]);
1627
 
1628
  $wrapper.children().remove();
1629
  $wrapper.remove();
@@ -1668,9 +1677,9 @@
1668
 
1669
  var shortcode = '['+ $data.EMBEDPRESS_SHORTCODE + (customAttributesList.length > 0 ? " "+ customAttributesList.join(" ") : "") +']'+ $('#input-url-'+ wrapperUid).val() +'[/'+ $data.EMBEDPRESS_SHORTCODE +']';
1670
  // We do not directly replace the node because it was causing a bug on a second edit attempt
1671
- self.editor.execCommand('mceInsertContent', false, shortcode);
1672
 
1673
- self.configureWrappers();
1674
  }
1675
  }
1676
  }
@@ -1705,9 +1714,9 @@
1705
  * @param Object e The event
1706
  * @return void
1707
  */
1708
- self.onClickRemoveButton = function(e) {
1709
  // Prevent edition of the panel
1710
- self.cancelEvent(e);
1711
 
1712
  var $wrapper = self.activeWrapper;
1713
 
@@ -1755,10 +1764,10 @@
1755
  * Configure unconfigured embed wrappers, adding events and css
1756
  * @return void
1757
  */
1758
- self.configureWrappers = function() {
1759
  window.setTimeout(
1760
  function configureWrappersTimeOut() {
1761
- var doc = self.editor.getDoc(),
1762
  total = 0,
1763
  $wrapper = null,
1764
  $iframe = null;
@@ -1823,8 +1832,8 @@
1823
  * @param String id The element id
1824
  * @return Element The found element or null, wrapped by jQuery
1825
  */
1826
- self.getElementInContentById = function(id) {
1827
- var doc = self.editor.getDoc();
1828
 
1829
  return $(doc.getElementById(id));
1830
  };
@@ -1835,21 +1844,26 @@
1835
  * @param element $wrapper The wrapper which will be activate
1836
  * @return void
1837
  */
1838
- self.displayPreviewControllerPanel = function($wrapper) {
1839
  if (self.controllerPanelIsActive() && $wrapper !== self.activeWrapper) {
1840
  self.hidePreviewControllerPanel();
1841
  }
1842
 
1843
  if (!self.controllerPanelIsActive() && !$wrapper.hasClass('is-loading')) {
1844
  var uid = $wrapper.data('uid');
1845
- var $panel = self.getElementInContentById('embedpress_controller_panel_' + uid);
1846
 
1847
  if (!$panel.data('event-set')) {
1848
- var $editButton = self.getElementInContentById('embedpress_button_edit_' + uid);
1849
- var $removeButton = self.getElementInContentById('embedpress_button_remove_' + uid);
 
 
 
 
1850
 
1851
- self.addEvent('mousedown', $editButton, self.onClickEditButton);
1852
- self.addEvent('mousedown', $removeButton, self.onClickRemoveButton);
 
1853
 
1854
  $panel.data('event-set', true);
1855
  }
5
  * @license GPLv2 or later
6
  * @since 1.0
7
  */
 
8
  (function($, String, $data, undefined) {
9
  "use strict";
10
 
147
  }
148
  };
149
 
 
 
 
 
150
  var SHORTCODE_REGEXP = new RegExp('\\[\/?'+ $data.EMBEDPRESS_SHORTCODE +'\\]', "gi");
151
 
152
  var EmbedPress = function() {
161
  * @type Object
162
  */
163
  self.params = {
164
+ baseUrl : '',
165
  versionUID: '0'
166
  };
167
 
185
  */
186
  self.activeControllerPanel = null;
187
 
188
+ /**
189
+ * A list containing all loaded editor instances on the page
190
+ * @type Array
191
+ */
192
+ self.loadedEditors = [];
193
+
194
  /**
195
  * Init the plugin
196
  *
236
  return text;
237
  };
238
 
239
+ self.loadAsyncDynamicJsCodeFromElement = function(subject, wrapper, editorInstance)
240
  {
241
  subject = $(subject);
242
  if (subject.prop('tagName').toLowerCase() === "script") {
243
  var scriptSrc = subject.attr('src') || null;
244
  if (!scriptSrc) {
245
+ self.addScriptDeclaration(wrapper, subject.html(), editorInstance);
246
  } else {
247
+ self.addScript(scriptSrc, null, wrapper, editorInstance);
248
  }
249
  } else {
250
  var innerScriptsList = $('script', subject);
251
  if (innerScriptsList.length > 0) {
252
  $.each(innerScriptsList, function(innerScriptIndex, innerScript) {
253
+ self.loadAsyncDynamicJsCodeFromElement(innerScript, wrapper, editorInstance);
254
  });
255
  }
256
  }
266
  // Wait until the editor is available
267
  var interval = window.setInterval(
268
  function() {
269
+ var editorsFound = self.getEditors();
270
+ if (editorsFound.length) {
271
+ self.loadedEditors = editorsFound;
272
 
273
+ for (var editorIndex = 0; editorIndex < self.loadedEditors.length; editorIndex++) {
274
+ self.onFindEditor(self.loadedEditors[editorIndex]);
275
+ }
276
 
 
277
  window.clearInterval(interval);
 
278
 
279
+ return self.loadedEditors;
280
  }
281
  },
282
+ 250
283
  );
284
  }
285
  };
304
  * Returns the editor
305
  * @return Object The editor
306
  */
307
+ self.getEditors = function() {
308
  if (!window.tinymce || !window.tinymce.editors || window.tinymce.editors.length === 0) {
309
+ return [];
310
  }
311
 
312
+ return window.tinymce.editors || [];
 
 
 
 
313
  };
314
 
315
  /**
324
  // Get the parsed content
325
  $.ajax({
326
  type: 'POST',
327
+ url: self.params.baseUrl +"wp-admin/admin-ajax.php",
328
  data: {
329
  action: "embedpress_do_ajax_request",
330
  subject: content
335
  });
336
  };
337
 
338
+ self.addStylesheet = function(url, editorInstance) {
339
+ var head = editorInstance.getDoc().getElementsByTagName('head')[0];
340
 
341
  var $style = $('<link rel="stylesheet" type="text/css" href="' + url + '">');
342
  $style.appendTo(head);
625
  return patterns;
626
  };
627
 
628
+ self.addScript = function(source, callback, wrapper, editorInstance) {
629
+ var doc = editorInstance.getDoc();
630
 
631
  if (typeof wrapper === 'undefined' || !wrapper) {
632
  wrapper = $(doc.getElementsByTagName('head')[0]);
644
  wrapper.append($script);
645
  };
646
 
647
+ self.addScriptDeclaration = function(wrapper, declaration, editorInstance) {
648
+ var doc = editorInstance.getDoc(),
649
  $script = $(doc.createElement('script'));
650
 
651
  $(wrapper).append($script);
653
  $script.text(declaration);
654
  };
655
 
656
+ self.addURLsPlaceholder = function(node, url, editorInstance) {
657
  var uid = self.makeId();
658
 
659
  var wrapperClasses = ["embedpress_wrapper", "embedpress_placeholder", "wpview", "wpview-wrap"];
762
 
763
  // Trigger the timeout which will load the content
764
  window.setTimeout(function() {
765
+ self.parseContentAsync(uid, url, customAttributes, editorInstance);
766
  }, 200);
767
 
768
  return wrapper;
769
  };
770
 
771
+ self.parseContentAsync = function(uid, url, customAttributes, editorInstance) {
772
  customAttributes = typeof customAttributes === "undefined" ? {} : customAttributes;
773
 
774
  url = self.decodeEmbedURLSpecialChars(url, true, customAttributes);
785
  self.getParsedContent(url, function getParsedContentCallback(result) {
786
  var embeddedContent = (typeof result.data === "object" ? result.data.embed : result.data).stripShortcode($data.EMBEDPRESS_SHORTCODE);
787
 
788
+ var $wrapper = $(self.getElementInContentById('embedpress_wrapper_' + uid, editorInstance));
789
  var wrapperParent = $($wrapper.parent());
790
 
791
  // Check if $wrapper was rendered inside a <p> element.
823
  var contentWrapper = $($content).clone();
824
  contentWrapper.html('');
825
 
826
+ var dom = editorInstance.dom;
827
 
828
  $wrapper.removeClass('embedpress_placeholder');
829
 
830
  $wrapper.append(contentWrapper);
831
 
832
  setTimeout(function() {
833
+ editorInstance.undoManager.transact(function() {
834
+ var iframe = editorInstance.getDoc().createElement('iframe');
835
  iframe.src = tinymce.Env.ie ? 'javascript:""' : '';
836
  iframe.frameBorder = '0';
837
  iframe.allowTransparency = 'true';
838
  iframe.scrolling = 'no';
839
  iframe.class = "wpview-sandbox";
840
+ iframe.style.width = '100%';
841
 
842
  dom.add(contentWrapper, iframe);
843
  var iframeWindow = iframe.contentWindow;
851
  $(iframe).load(function() {
852
  var maximumChecksAllowed = 8;
853
  var checkIndex = 0;
854
+
855
  var checkerInterval = setInterval(function() {
856
  if (checkIndex === maximumChecksAllowed) {
857
  clearInterval(checkerInterval);
858
 
859
  setTimeout(function() {
860
+ $wrapper.css('width', iframe.width);
861
+ $wrapper.css('height', iframe.height);
 
 
 
862
  }, 100);
863
  } else {
864
  if (customAttributes.height) {
865
  iframe.height = customAttributes.height;
866
  iframe.style.height = customAttributes.height +'px';
867
  } else {
868
+ iframe.height = $('body', iframeDoc).height();
869
  }
870
 
871
  if (customAttributes.width) {
872
  iframe.width = customAttributes.width;
873
  iframe.style.width = customAttributes.width +'px';
874
  } else {
875
+ iframe.width = $('body', iframeDoc).width();
876
  }
877
 
878
  checkIndex++;
904
  '}'+
905
  '</style>'+
906
  '</head>'+
907
+ '<body id="wpview-iframe-sandbox" class="'+ editorInstance.getBody().className +'" style="display: inline-block;">'+
908
  $content.html() +
909
  '</body>'+
910
  '</html>'
915
  } else {
916
  $wrapper.removeClass('embedpress_placeholder');
917
 
918
+ self.appendElementsIntoWrapper($content, $wrapper, editorInstance);
919
  }
920
 
 
921
  $wrapper.append($('<span class="wpview-end"></span>'));
922
 
923
  if (result && result.data && typeof result.data === "object") {
933
  });
934
  };
935
 
936
+ self.appendElementsIntoWrapper = function(elementsList, wrapper, editorInstance) {
937
  if (elementsList.length > 0) {
938
  $.each(elementsList, function appendElementIntoWrapper(elementIndex, element) {
939
  // Check if the element is a script and do not add it now (if added here it wouldn't be executed)
943
  if (element.tagName.toLowerCase() === 'iframe') {
944
  $(element).ready(function() {
945
  window.setTimeout(function() {
946
+ $.each(editorInstance.dom.select('div.embedpress_wrapper iframe'), function(elementIndex, iframe) {
947
  self.fixIframeSize(iframe);
948
  });
949
  }, 300);
958
  }
959
  }
960
 
961
+ self.loadAsyncDynamicJsCodeFromElement(element, wrapper, editorInstance);
962
  });
963
  }
964
 
1060
  *
1061
  * @return void
1062
  */
1063
+ self.onFindEditor = function(editorInstance) {
1064
  self.each = tinymce.each;
1065
  self.extend = tinymce.extend;
1066
  self.JSON = tinymce.util.JSON;
1069
  function onFindEditorCallback() {
1070
  $(window.document.getElementsByTagName('head')[0]).append($('<link rel="stylesheet" type="text/css" href="' + (PLG_SYSTEM_ASSETS_CSS_PATH + '/vendor/bootstrap/bootstrap.min.css?v=' + self.params.versionUID) + '">'));
1071
 
1072
+ self.addStylesheet(PLG_SYSTEM_ASSETS_CSS_PATH + '/font.css?v=' + self.params.versionUID, editorInstance, editorInstance);
1073
+ self.addStylesheet(PLG_SYSTEM_ASSETS_CSS_PATH + '/preview.css?v=' + self.params.versionUID, editorInstance, editorInstance);
1074
+ self.addStylesheet(PLG_CONTENT_ASSETS_CSS_PATH + '/embedpress.css?v=' + self.params.versionUID, editorInstance, editorInstance);
1075
+ self.addEvent('paste', editorInstance, function(a, b) {
1076
+ self.onPaste(a, b, editorInstance);
1077
+ });
1078
+ self.addEvent('nodechange', editorInstance, self.onNodeChange);
1079
+ self.addEvent('keydown', editorInstance, function(e) {
1080
+ self.onKeyDown(e, editorInstance);
1081
+ });
1082
 
1083
+ var onUndoCallback = function(e) {
1084
+ self.onUndo(e, editorInstance);
1085
+ };
1086
 
1087
+ self.addEvent('undo', editorInstance, onUndoCallback); // TinyMCE
1088
+ self.addEvent('undo', editorInstance.undoManager, onUndoCallback); // JCE
1089
+
1090
+ var doc = editorInstance.getDoc();
1091
+ $(doc).on('mouseenter', '.embedpress_wrapper', function(e) {
1092
+ self.onMouseEnter(e, editorInstance);
1093
+ });
1094
  $(doc).on('mouseout', '.embedpress_wrapper', self.onMouseOut);
1095
+ $(doc).on('mousedown', '.embedpress_wrapper > .embedpress_controller_panel', function(e) {
1096
+ self.cancelEvent(e, editorInstance)
1097
+ });
1098
  doc = null;
1099
  // Add the node filter that will convert the url into the preview box for the embed code
1100
  // @todo: Recognize <a> tags as well
1101
 
1102
+ editorInstance.parser.addNodeFilter('#text', function addNodeFilterIntoParser(nodes, arg) {
1103
  self.each(nodes, function eachNodeInParser(node) {
1104
  var subject = node.value.trim();
1105
  if (!subject.isValidUrl()) {
1132
  if (matches && matches !== null && !!matches.length) {
1133
  url = self.encodeEmbedURLSpecialChars(matches[2]);
1134
 
1135
+ var wrapper = self.addURLsPlaceholder(node, url, editorInstance);
1136
 
1137
  setTimeout(function() {
1138
+ var doc = editorInstance.getDoc();
1139
 
1140
  var previewWrapper = $(doc.querySelector('#'+ wrapper.attributes.map['id']));
1141
  var previewWrapperParent = $(previewWrapper.parent());
1166
  }
1167
 
1168
  setTimeout(function() {
1169
+ editorInstance.selection.select(editorInstance.getBody(), true);
1170
+ editorInstance.selection.collapse(false);
1171
  }, 50);
1172
  }, 50);
1173
  } else {
1180
  });
1181
 
1182
  // Add the filter that will convert the preview box/embed code back to the raw url
1183
+ editorInstance.serializer.addNodeFilter('div', function addNodeFilterIntoSerializer(nodes, arg) {
1184
  self.each(nodes, function eachNodeInSerializer(node) {
1185
  var nodeClasses = (node.attributes.map.class || "").split(' ');
1186
  var wrapperFactoryClasses = ["embedpress_wrapper", "embedpress_placeholder", "wpview", "wpview-wrap"];
1227
  });
1228
  });
1229
 
1230
+ editorInstance.serializer.addNodeFilter('p', function addNodeFilterIntoSerializer(nodes, arg) {
1231
  self.each(nodes, function eachNodeInSerializer(node) {
1232
  if (node.firstChild == node.lastChild) {
1233
  if (node.firstChild && "value" in node.firstChild && (node.firstChild.value === "&nbsp;" || !node.firstChild.value.trim().length)) {
1237
  });
1238
  });
1239
 
1240
+ //@todo:isthiseachreallynecessary?
1241
  // Add event to reconfigure wrappers every time the content is loaded
1242
  tinymce.each(tinymce.editors, function onEachEditor(editor) {
1243
  self.addEvent('loadContent', editor, function onInitEditor(ed) {
1244
+ self.configureWrappers(editor);
1245
  });
1246
  });
1247
 
1255
  * onLoadContent is not being triggered automatically, so
1256
  * we force the event
1257
  */
1258
+ editorInstance.load();
1259
  },
1260
  // If in JCE the user see the placeholder (img) instead of the iframe after load/refresh the pagr, this time is too short
1261
  500
1270
  clearInterval(statusCheckerInterval);
1271
  alert('For some reason TinyMCE was not fully loaded yet. Please, refresh the page and try again.');
1272
  } else {
1273
+ var doc = editorInstance.getDoc();
1274
  if (doc) {
1275
  clearInterval(statusCheckerInterval);
1276
  onFindEditorCallback();
1300
  * @param object e The event
1301
  * @return void
1302
  */
1303
+ self.onMouseEnter = function(e, editorInstance) {
1304
+ self.displayPreviewControllerPanel($(e.currentTarget), editorInstance);
1305
  };
1306
 
1307
  /**
1341
  * @return void
1342
  */
1343
 
1344
+ self.onPaste = function(e, b, editorInstance) {
1345
  var urlPatternRegex = new RegExp(/(https?):\/\/([w]{3}\.)?.+?(?:\s|$)/i);
1346
 
1347
  var event = null;
1392
  var content = '<p>'+ contentLines.join('') +'</p>';
1393
 
1394
  // Insert the new content into the editor.
1395
+ editorInstance.execCommand('mceInsertContent', false, content);
1396
  };
1397
 
1398
  /**
1432
  }
1433
  };
1434
 
1435
+ self.onKeyDown = function(e, editorInstance) {
1436
+ var node = editorInstance.selection.getNode();
1437
 
1438
  if (e.keyCode == 8 || e.keyCode == 46) {
1439
  if (node.nodeName.toLowerCase() === 'p') {
1444
  if ($(this).hasClass('embedpress_wrapper') || $(this).hasClass('embedpress_ignore_mouseout')) {
1445
  $(this).remove();
1446
 
1447
+ editorInstance.focus();
1448
  }
1449
  });
1450
  }
1464
  var tmpId = '__embedpress__tmp_' + self.makeId();
1465
  wrapper.after($('<span id="' + tmpId + '"></span>'));
1466
  // Get and select the temporary element
1467
+ var span = editorInstance.dom.select('span#' + tmpId)[0];
1468
+ editorInstance.selection.select(span);
1469
  // Remove the temporary element
1470
  $(span).remove();
1471
  }
1473
  return true;
1474
  } else {
1475
  // If we are inside the embed preview, ignore any key to avoid edition
1476
+ return self.cancelEvent(e, editorInstance);
1477
  }
1478
  }
1479
  }
1497
  return false;
1498
  };
1499
 
1500
+ self.onUndo = function(e, editorInstance) {
1501
  // Force re-render everything
1502
+ editorInstance.load();
1503
  };
1504
 
1505
+ self.cancelEvent = function(e, editorInstance) {
1506
  e.preventDefault();
1507
  e.stopPropagation();
1508
+ editorInstance.dom.events.cancel();
1509
 
1510
  return false;
1511
  };
1518
  * @param Object e The event
1519
  * @return void
1520
  */
1521
+ self.onClickEditButton = function(e, editorInstance) {
1522
  // Prevent edition of the panel
1523
+ self.cancelEvent(e, editorInstance);
1524
 
1525
  self.activeWrapperForModal = self.activeWrapper;
1526
 
1553
  setTimeout(function() {
1554
  $.ajax({
1555
  type: "GET",
1556
+ url: self.params.baseUrl +"wp-admin/admin-ajax.php",
1557
  data: {
1558
  action: "embedpress_get_embed_url_info",
1559
  url: self.decodeEmbedURLSpecialChars($wrapper.data('url'), false)
1631
  var $wrapper = self.activeWrapperForModal;
1632
 
1633
  // Select the current wrapper as a base for the new element
1634
+ editorInstance.focus();
1635
+ editorInstance.selection.select($wrapper[0]);
1636
 
1637
  $wrapper.children().remove();
1638
  $wrapper.remove();
1677
 
1678
  var shortcode = '['+ $data.EMBEDPRESS_SHORTCODE + (customAttributesList.length > 0 ? " "+ customAttributesList.join(" ") : "") +']'+ $('#input-url-'+ wrapperUid).val() +'[/'+ $data.EMBEDPRESS_SHORTCODE +']';
1679
  // We do not directly replace the node because it was causing a bug on a second edit attempt
1680
+ editorInstance.execCommand('mceInsertContent', false, shortcode);
1681
 
1682
+ self.configureWrappers(editorInstance);
1683
  }
1684
  }
1685
  }
1714
  * @param Object e The event
1715
  * @return void
1716
  */
1717
+ self.onClickRemoveButton = function(e, editorInstance) {
1718
  // Prevent edition of the panel
1719
+ self.cancelEvent(e, editorInstance);
1720
 
1721
  var $wrapper = self.activeWrapper;
1722
 
1764
  * Configure unconfigured embed wrappers, adding events and css
1765
  * @return void
1766
  */
1767
+ self.configureWrappers = function(editorInstance) {
1768
  window.setTimeout(
1769
  function configureWrappersTimeOut() {
1770
+ var doc = editorInstance.getDoc(),
1771
  total = 0,
1772
  $wrapper = null,
1773
  $iframe = null;
1832
  * @param String id The element id
1833
  * @return Element The found element or null, wrapped by jQuery
1834
  */
1835
+ self.getElementInContentById = function(id, editorInstance) {
1836
+ var doc = editorInstance.getDoc();
1837
 
1838
  return $(doc.getElementById(id));
1839
  };
1844
  * @param element $wrapper The wrapper which will be activate
1845
  * @return void
1846
  */
1847
+ self.displayPreviewControllerPanel = function($wrapper, editorInstance) {
1848
  if (self.controllerPanelIsActive() && $wrapper !== self.activeWrapper) {
1849
  self.hidePreviewControllerPanel();
1850
  }
1851
 
1852
  if (!self.controllerPanelIsActive() && !$wrapper.hasClass('is-loading')) {
1853
  var uid = $wrapper.data('uid');
1854
+ var $panel = self.getElementInContentById('embedpress_controller_panel_' + uid, editorInstance);
1855
 
1856
  if (!$panel.data('event-set')) {
1857
+ var $editButton = self.getElementInContentById('embedpress_button_edit_' + uid, editorInstance);
1858
+ var $removeButton = self.getElementInContentById('embedpress_button_remove_' + uid, editorInstance);
1859
+
1860
+ self.addEvent('mousedown', $editButton, function(e) {
1861
+ self.onClickEditButton(e, editorInstance);
1862
+ });
1863
 
1864
+ self.addEvent('mousedown', $removeButton, function(e) {
1865
+ self.onClickRemoveButton(e, editorInstance);
1866
+ });
1867
 
1868
  $panel.data('event-set', true);
1869
  }
changelog.txt CHANGED
@@ -1,4 +1,14 @@
1
  == Changelog ==
 
 
 
 
 
 
 
 
 
 
2
  = 1.5.0 =
3
  Release Date: 2017-02-15
4
 
1
  == Changelog ==
2
+ = 1.6.0 =
3
+ Release Date: 2017-02-28
4
+
5
+ * Added support to preview embeds inside editors rendered in frontend;
6
+ * Fixed some embeds not respecting custom dimensions;
7
+ * Fixed some embeds not being rendered as they should in frontend due to invalid characters in the url;
8
+ * Fixed embeds not being rendered in editors on some WP instances;
9
+ * Tweaks on the plugin settings page;
10
+ * Code enhancements.
11
+
12
  = 1.5.0 =
13
  Release Date: 2017-02-15
14
 
embedpress.php CHANGED
@@ -12,7 +12,7 @@
12
  * @embedpress
13
  * Plugin Name: EmbedPress
14
  * Plugin URI: https://pressshack.com/embedpress/
15
- * Version: 1.5.0
16
  * Description: WordPress supports around 35 embed sources, but EmbedPress adds over 40 more, including Facebook, Google Maps, Google Docs, UStream! Just use the URL!
17
  * Author: PressShack
18
  * Author URI: http://pressshack.com
12
  * @embedpress
13
  * Plugin Name: EmbedPress
14
  * Plugin URI: https://pressshack.com/embedpress/
15
+ * Version: 1.6.0
16
  * Description: WordPress supports around 35 embed sources, but EmbedPress adds over 40 more, including Facebook, Google Maps, Google Docs, UStream! Just use the URL!
17
  * Author: PressShack
18
  * Author URI: http://pressshack.com
includes.php CHANGED
@@ -20,7 +20,7 @@ if (!defined('EMBEDPRESS_PLG_NAME')) {
20
  }
21
 
22
  if (!defined('EMBEDPRESS_PLG_VERSION')) {
23
- define('EMBEDPRESS_PLG_VERSION', "1.5.0");
24
  }
25
 
26
  if (!defined('EMBEDPRESS_PATH_BASE')) {
20
  }
21
 
22
  if (!defined('EMBEDPRESS_PLG_VERSION')) {
23
+ define('EMBEDPRESS_PLG_VERSION', "1.6.0");
24
  }
25
 
26
  if (!defined('EMBEDPRESS_PATH_BASE')) {
library/ostraining/embera/Lib/Embera/Providers/Facebook.php CHANGED
@@ -69,7 +69,6 @@ class Facebook extends \Embera\Adapters\Service
69
  '~facebook\.com/media/set/?\?set=(?:[^/ ]+)~i',
70
  );
71
 
72
-
73
  /** Patterns that match video urls */
74
  protected $videoPatterns = array(
75
  /**
@@ -85,11 +84,16 @@ class Facebook extends \Embera\Adapters\Service
85
  '~facebook\.com/video\.php\?(?:id|v)=(?:[^ ]+)~i',
86
  );
87
 
 
 
 
 
 
88
  /** inline {@inheritdoc} */
89
  protected function validateUrl()
90
  {
91
  $this->url->convertToHttps();
92
- return ($this->urlMatchesPattern(array_merge($this->postPatterns, $this->videoPatterns)));
93
  }
94
 
95
  /**
@@ -122,9 +126,12 @@ class Facebook extends \Embera\Adapters\Service
122
  */
123
  public function getInfo()
124
  {
125
- $this->apiUrl = 'https://www.facebook.com/plugins/post/oembed.json/';
126
  if ($this->urlMatchesPattern($this->videoPatterns)) {
127
  $this->apiUrl = 'https://www.facebook.com/plugins/video/oembed.json/';
 
 
 
 
128
  }
129
 
130
  return parent::getInfo();
69
  '~facebook\.com/media/set/?\?set=(?:[^/ ]+)~i',
70
  );
71
 
 
72
  /** Patterns that match video urls */
73
  protected $videoPatterns = array(
74
  /**
84
  '~facebook\.com/video\.php\?(?:id|v)=(?:[^ ]+)~i',
85
  );
86
 
87
+ /** Patterns that match page urls */
88
+ protected $pagePatterns = array(
89
+ '~facebook\.com\/(?:[^\/]+)[\/]?$~'
90
+ );
91
+
92
  /** inline {@inheritdoc} */
93
  protected function validateUrl()
94
  {
95
  $this->url->convertToHttps();
96
+ return ($this->urlMatchesPattern(array_merge($this->postPatterns, $this->videoPatterns, $this->pagePatterns)));
97
  }
98
 
99
  /**
126
  */
127
  public function getInfo()
128
  {
 
129
  if ($this->urlMatchesPattern($this->videoPatterns)) {
130
  $this->apiUrl = 'https://www.facebook.com/plugins/video/oembed.json/';
131
+ } else if ($this->urlMatchesPattern($this->postPatterns)) {
132
+ $this->apiUrl = 'https://www.facebook.com/plugins/post/oembed.json/';
133
+ } else {
134
+ $this->apiUrl = 'https://www.facebook.com/plugins/page/oembed.json/';
135
  }
136
 
137
  return parent::getInfo();
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: PressShack
3
  Tags: 23hq, amcharts, animoto, bambuser, cacoo, chartblocks, chirbit, circuitlab, cloudup, clyp, collegehumor, coub, crowd ranking, daily mile, dailymotion, devianart, dipity, dotsub, facebook, flickr, funnyordie, gettyimages, giphy, github gist, google docs, google drawings, google maps, google sheets, google slides, huffduffer, hulu, imgur, infogram, instagram, issuu, kickstarter, meetup, mixcloud, mobypicture, nfb, photobucket, polldaddy, porfolium, reddit, release wire, reverbnation, roomshare, rutube, sapo videos, scribd, shortnote, shoudio, sketchfab, slideshare, smugmug, soundcloud, speaker deck, spotify, ted, tumblr, twitter, ustream, viddler, videojug, videopress, vimeo, vine, wordpress tv, youtube, twitch tv
4
  Requires at least: 4.0
5
  Tested up to: 4.7
6
- Stable tag: 1.5.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -121,6 +121,16 @@ There're two ways to install EmbedPress plugin:
121
  `
122
 
123
  == Changelog ==
 
 
 
 
 
 
 
 
 
 
124
  = 1.5.0 =
125
  Release Date: 2017-02-15
126
 
3
  Tags: 23hq, amcharts, animoto, bambuser, cacoo, chartblocks, chirbit, circuitlab, cloudup, clyp, collegehumor, coub, crowd ranking, daily mile, dailymotion, devianart, dipity, dotsub, facebook, flickr, funnyordie, gettyimages, giphy, github gist, google docs, google drawings, google maps, google sheets, google slides, huffduffer, hulu, imgur, infogram, instagram, issuu, kickstarter, meetup, mixcloud, mobypicture, nfb, photobucket, polldaddy, porfolium, reddit, release wire, reverbnation, roomshare, rutube, sapo videos, scribd, shortnote, shoudio, sketchfab, slideshare, smugmug, soundcloud, speaker deck, spotify, ted, tumblr, twitter, ustream, viddler, videojug, videopress, vimeo, vine, wordpress tv, youtube, twitch tv
4
  Requires at least: 4.0
5
  Tested up to: 4.7
6
+ Stable tag: 1.6.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
121
  `
122
 
123
  == Changelog ==
124
+ = 1.6.0 =
125
+ Release Date: 2017-02-28
126
+
127
+ * Added support to preview embeds inside editors rendered in frontend;
128
+ * Fixed some embeds not respecting custom dimensions;
129
+ * Fixed some embeds not being rendered as they should in frontend due to invalid characters in the url;
130
+ * Fixed embeds not being rendered in editors on some WP instances;
131
+ * Tweaks on the plugin settings page;
132
+ * Code enhancements.
133
+
134
  = 1.5.0 =
135
  Release Date: 2017-02-15
136