Changeset 1037811
- Timestamp:
- 12/03/2014 11:25:34 PM (11 years ago)
- Location:
- super-link-preview
- Files:
-
- 9 added
- 3 edited
-
tags/1.0.1 (added)
-
tags/1.0.1/images (added)
-
tags/1.0.1/images/icon.png (added)
-
tags/1.0.1/images/icon@2x.png (added)
-
tags/1.0.1/js (added)
-
tags/1.0.1/js/mce.js (added)
-
tags/1.0.1/js/script.js (added)
-
tags/1.0.1/readme.txt (added)
-
tags/1.0.1/super-link-preview.php (added)
-
trunk/js/mce.js (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/super-link-preview.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
super-link-preview/trunk/js/mce.js
r1037377 r1037811 21 21 }, 22 22 { 23 type: ' textbox',24 name: ' width',25 label: ' Image width (leave empty to get native)'23 type: 'checkbox', 24 name: 'forceshot', 25 label: 'Force screenshot' 26 26 }, 27 27 ], 28 28 onsubmit: function( e ) { 29 editor.insertContent( '[' + plugin_shortcode + ' url="' + e.data.url + '"' + ( parseInt(e.data.width) > 0 ? ' width="' + parseInt(e.data.width) + '"' : '') + ']');29 editor.insertContent( '[' + plugin_shortcode + ' url="' + e.data.url + '"' + (e.data.forceshot ? ' forceshot="true"' : '') + ']'); 30 30 } 31 31 … … 45 45 } 46 46 }); 47 tinymce.PluginManager.add(plugin_mce, window['tinymce.plugins.' + plugin_mce]);47 tinymce.PluginManager.add(plugin_mce, tinymce.plugins.superlinkpreview); 48 48 })(); -
super-link-preview/trunk/readme.txt
r1037401 r1037811 5 5 Requires at least: 3.3.0 6 6 Tested up to: 4.0.1 7 Stable tag: 1.0. 07 Stable tag: 1.0.1 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 45 45 == Changelog == 46 46 47 = 1.0 = 47 = 1.0.1 = 48 Release date: December 3, 2014 49 * Bug Fix: Rich editor shortcode button 50 * Bug Fix: Removed WARNING notices when inserting new posts or broken remote images urls 51 52 = 1.0.0 = 48 53 * Initial public release to the WordPress plugin repository -
super-link-preview/trunk/super-link-preview.php
r1037485 r1037811 34 34 add_action( 'init', array( $this, 'plugin_tinymce_button' ) ); 35 35 add_action( 'save_post', array( $this, 'plugin_save_posts' ) ); 36 36 37 37 add_action( 'wp_enqueue_scripts', array( $this, 'plugin_scripts') ); 38 38 add_action( 'admin_menu', array($this, 'plugin_menu')); 39 39 add_action( 'admin_init', array($this, 'plugin_settings')); 40 40 41 41 } 42 42 … … 80 80 81 81 register_setting($this->plugin_name, $this->plugin_name . '_img_og_meta', ''); 82 add_settings_field($this->plugin_name . '_img_og_meta', "OpenGraph image", array($this, 'plugin_img_og_meta'), $this->plugin_name, $this->plugin_name . '_options', $args = array() );82 add_settings_field($this->plugin_name . '_img_og_meta', "OpenGraph meta", array($this, 'plugin_img_og_meta'), $this->plugin_name, $this->plugin_name . '_options', $args = array() ); 83 83 84 84 register_setting($this->plugin_name, $this->plugin_name . '_img_min_width', ''); … … 90 90 add_settings_field($this->plugin_name . '_img_disallow_ads', "Exclude ads", array($this, 'plugin_img_disallow_ads'), $this->plugin_name, $this->plugin_name . '_options', $args = array() ); 91 91 92 93 92 94 93 register_setting($this->plugin_name, $this->plugin_name . '_shot_service', ''); 95 94 add_settings_field($this->plugin_name . '_shot_service', "Screenshot", array($this, 'plugin_shot_service'), $this->plugin_name, $this->plugin_name . '_options', $args = array() ); … … 118 117 public function plugin_img_og_meta() { 119 118 $field = $this->plugin_name . '_img_og_meta'; 120 echo '<input name="' . $field . '" type="checkbox" value="1" ' . checked( 1, get_option($field, true), false ) . ' /> <label for="' . $field . '">When parsing for most relevant image, prefer OpenGraph image (og:image meta tag)</label>';119 echo '<input name="' . $field . '" type="checkbox" value="1" ' . checked( 1, get_option($field, true), false ) . ' /> <label for="' . $field . '">When parsing for most relevant image, prefer OpenGraph meta (<strong>og:image</strong> for image source and <strong>og:title</strong> for alt description) </label>'; 121 120 } 122 121 … … 136 135 137 136 } 138 137 139 138 /* 140 139 * Front script … … 149 148 public function plugin_save_posts($post_id) { 150 149 151 $urls = $this->shortcodes_url(); 152 foreach($urls as $url) { 153 $this->capture_url($url, $post_id); 150 global $post; 151 if ($post) { 152 153 $urls = $this->shortcodes_url($post->post_content); 154 foreach($urls as $url) { 155 $this->capture_url($url, $post_id); 156 } 154 157 } 155 } 156 157 158 159 } 160 161 158 162 /* 159 163 * Shortcode … … 229 233 $html .= ' width="' . $width . '"'; 230 234 231 $ title = get_post_meta($post->ID, $this->cf_prefix . "title-" . $slug, true);232 if (isset($ title) && !empty($title))233 $html .= ' alt="' . $ title . '" title="' + $title +'"';235 $alt = get_post_meta($post->ID, $this->cf_prefix . "alt-" . $slug, true); 236 if (isset($alt) && !empty($alt)) 237 $html .= ' alt="' . $alt . '" title="' . $alt . '"'; 234 238 235 239 $html .= ' /></a></div>'; … … 245 249 246 250 } 247 248 /* 249 * List all shortcodes url in a post 250 */ 251 private function shortcodes_url() { 252 global $post; 251 252 253 /* 254 * List all shortcodes url in a string 255 */ 256 private function shortcodes_url($content) { 257 253 258 $urls = []; 254 259 $pattern = get_shortcode_regex(); 255 260 256 if (preg_match_all( '/'. $pattern .'/s', $ post->post_content, $matches) && array_key_exists( 2, $matches )) {261 if (preg_match_all( '/'. $pattern .'/s', $content, $matches) && array_key_exists( 2, $matches )) { 257 262 258 263 $my_shortcode = array_keys($matches[2], $this->shortcode_name); … … 311 316 312 317 $image_url = ""; 313 $ url_title= "";318 $image_alt = ""; 314 319 315 320 //Get OpenGraph image and title … … 324 329 } 325 330 326 if (empty($ url_title)) {331 if (empty($image_alt)) { 327 332 if ($meta_tag->getAttribute('property') == 'og:title'){ 328 $ url_title= $meta_tag->getAttribute('content');333 $image_alt = $meta_tag->getAttribute('content'); 329 334 } 330 335 } 331 336 332 if (!empty($image_url) && !empty($ url_title))337 if (!empty($image_url) && !empty($image_alt)) 333 338 break; 334 339 } 335 340 336 341 } 337 338 //Get document title339 if (empty($url_title)) {340 $title_tag = $document->getElementsByTagName("title");341 if($title_tag->length > 0)342 $url_title = $title_tag->item(0)->nodeValue;343 }344 345 if (!empty($url_title)) {346 347 //TODO Strip URLS from title348 349 //TODO Save title as post title if untitled350 351 //Save title in a custom field352 update_post_meta($post_id, $this->cf_prefix . "title-" . $slug, $url_title);353 354 }355 356 342 357 343 if (!$this->has_right_size($image_url)) { … … 383 369 384 370 } 371 372 if (!empty($image_alt)) { 373 374 //Strip URLS from alt 375 $image_alt = strip_tags($this->strip_URL($image_alt)); 376 377 //Save alt in a custom field 378 update_post_meta($post_id, $this->cf_prefix . "alt-" . $slug, $image_alt); 379 380 } 385 381 386 382 } … … 401 397 if ($image_url && !empty($image_url) && is_string($image_url)) { 402 398 403 //Check if url is valid404 if (filter_var($image_url, FILTER_VALIDATE_URL) === false)405 return false;406 407 399 if ($images_min_width > 0 || $images_min_height > 0 || !$this->images_allow_ads || !$this->images_allow_square) { 408 list($width, $height) = getimagesize($image_url); 400 401 $size_data = @getimagesize($image_url); 402 if (!$size_data) 403 return false; 404 405 list($width, $height) = $size_data; 409 406 410 407 if ($width < $images_min_width || $height < $images_min_height) … … 496 493 } 497 494 495 /* 496 * Remove URLs from given string 497 */ 498 private function strip_URL($string) { 499 500 $U = explode(' ', $string); 501 502 $W =array(); 503 foreach ($U as $k => $u) { 504 if (stristr($u,'http') || (count(explode('.',$u)) > 1)) { 505 unset($U[$k]); 506 return $this->strip_URL( implode(' ',$U)); 507 } 508 } 509 return implode(' ',$U); 510 } 511 498 512 499 513 /*
Note: See TracChangeset
for help on using the changeset viewer.