Plugin Directory

Changeset 1037811


Ignore:
Timestamp:
12/03/2014 11:25:34 PM (11 years ago)
Author:
daniele.perilli
Message:

Version 1.0.1

Location:
super-link-preview
Files:
9 added
3 edited

Legend:

Unmodified
Added
Removed
  • super-link-preview/trunk/js/mce.js

    r1037377 r1037811  
    2121                        },
    2222                        {
    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'
    2626                        },
    2727                        ],
    2828                        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"' : '') + ']');
    3030                        }
    3131
     
    4545        }
    4646    });
    47     tinymce.PluginManager.add(plugin_mce, window['tinymce.plugins.' + plugin_mce]);
     47    tinymce.PluginManager.add(plugin_mce, tinymce.plugins.superlinkpreview);
    4848})();
  • super-link-preview/trunk/readme.txt

    r1037401 r1037811  
    55Requires at least: 3.3.0
    66Tested up to: 4.0.1
    7 Stable tag: 1.0.0
     7Stable tag: 1.0.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4545== Changelog ==
    4646
    47 = 1.0 =
     47= 1.0.1 =
     48Release 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 =
    4853* Initial public release to the WordPress plugin repository
  • super-link-preview/trunk/super-link-preview.php

    r1037485 r1037811  
    3434            add_action( 'init', array( $this, 'plugin_tinymce_button' ) );
    3535            add_action( 'save_post', array( $this, 'plugin_save_posts' ) );
    36            
     36
    3737            add_action( 'wp_enqueue_scripts', array( $this, 'plugin_scripts') );
    3838            add_action( 'admin_menu', array($this, 'plugin_menu'));
    3939            add_action( 'admin_init', array($this, 'plugin_settings'));
    40            
     40
    4141        }
    4242       
     
    8080           
    8181            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() );
    8383           
    8484            register_setting($this->plugin_name, $this->plugin_name . '_img_min_width', '');
     
    9090            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() );
    9191           
    92            
    93            
     92
    9493            register_setting($this->plugin_name, $this->plugin_name . '_shot_service', '');
    9594            add_settings_field($this->plugin_name . '_shot_service', "Screenshot", array($this, 'plugin_shot_service'), $this->plugin_name, $this->plugin_name . '_options', $args = array() );
     
    118117        public function plugin_img_og_meta() {
    119118            $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>';
    121120        }
    122121       
     
    136135           
    137136        }
    138        
     137
    139138        /*
    140139        * Front script
     
    149148        public function plugin_save_posts($post_id) {
    150149           
    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                }
    154157            }
    155         }
    156 
    157 
     158           
     159        }
     160       
     161       
    158162        /*
    159163        * Shortcode
     
    229233                        $html .= ' width="' . $width . '"';
    230234                   
    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 . '"';
    234238                   
    235239                    $html .= ' /></a></div>';
     
    245249       
    246250        }
    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
    253258            $urls = [];
    254259            $pattern = get_shortcode_regex();
    255260       
    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 )) {
    257262               
    258263                $my_shortcode = array_keys($matches[2], $this->shortcode_name);
     
    311316               
    312317                $image_url = "";
    313                 $url_title = "";
     318                $image_alt = "";
    314319               
    315320                //Get OpenGraph image and title
     
    324329                        }
    325330                       
    326                         if (empty($url_title)) {
     331                        if (empty($image_alt)) {
    327332                            if ($meta_tag->getAttribute('property') == 'og:title'){
    328                                 $url_title = $meta_tag->getAttribute('content');
     333                                $image_alt = $meta_tag->getAttribute('content');
    329334                            }
    330335                        }
    331336
    332                         if (!empty($image_url) && !empty($url_title))
     337                        if (!empty($image_url) && !empty($image_alt))
    333338                            break;
    334339                    }
    335340   
    336341                }
    337                
    338                 //Get document title
    339                 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 title
    348                    
    349                     //TODO Save title as post title if untitled
    350                    
    351                     //Save title in a custom field
    352                     update_post_meta($post_id, $this->cf_prefix . "title-" . $slug, $url_title);
    353                        
    354                 }
    355 
    356342               
    357343                if (!$this->has_right_size($image_url)) {
     
    383369                       
    384370                }
     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                }
    385381
    386382            }
     
    401397            if ($image_url && !empty($image_url) && is_string($image_url)) {
    402398               
    403                 //Check if url is valid
    404                 if (filter_var($image_url, FILTER_VALIDATE_URL) === false)
    405                     return false;
    406                
    407399                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;
    409406                 
    410407                    if ($width < $images_min_width || $height < $images_min_height)
     
    496493        }
    497494
     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
    498512       
    499513        /*
Note: See TracChangeset for help on using the changeset viewer.