Plugin Directory

Changeset 1037485


Ignore:
Timestamp:
12/03/2014 01:59:52 PM (11 years ago)
Author:
daniele.perilli
Message:

Added remote URL title parsing (for images alternative text and post title if untitled)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • super-link-preview/trunk/super-link-preview.php

    r1037377 r1037485  
    55Description: Generate a preview (aka thumbnail) of any external link in the page, similar to Facebook or Google+ snippets.
    66Author: Daniele Perilli
    7 Version: 1.0.0
     7Version: 1.0.1
    88Author URI: https://www.behance.net/danieleperilli
    99*/
     
    158158        /*
    159159        * Shortcode
    160         * usage: [link-preview url="link-to-website" width="x" alt="description" forceshot="false"]
     160        * usage: [link-preview url="link-to-website" width="x" forceshot="false"]
    161161        */
    162162        public function plugin_shortcode( $attributes, $content = '', $code = '' ) {
     
    168168                'url' => '',
    169169                'width' => 0,
    170                 'alt' => '',
    171170                'forceshot' => false
    172171            ), $attributes ));
     
    230229                        $html .= ' width="' . $width . '"';
    231230                   
    232                     $html .= ' alt="' . $alt . '" /></a></div>';
     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 + '"';
     234                   
     235                    $html .= ' /></a></div>';
    233236                   
    234237                    return $html;
     
    308311               
    309312                $image_url = "";
    310                
    311                 //Get OpenGraph image
     313                $url_title = "";
     314               
     315                //Get OpenGraph image and title
    312316                $parse_og_meta = get_option($this->plugin_name . '_img_og_meta', true);
    313317                if ($parse_og_meta) {
    314318                    foreach($document->getElementsByTagName('meta') as $meta_tag) {
    315            
    316                         if ($meta_tag->getAttribute('property') == 'og:image'){
    317                             $image_url = $meta_tag->getAttribute('content');
     319                       
     320                        if (empty($image_url)) {
     321                            if ($meta_tag->getAttribute('property') == 'og:image'){
     322                                $image_url = $meta_tag->getAttribute('content');
     323                            }
     324                        }
     325                       
     326                        if (empty($url_title)) {
     327                            if ($meta_tag->getAttribute('property') == 'og:title'){
     328                                $url_title = $meta_tag->getAttribute('content');
     329                            }
     330                        }
     331
     332                        if (!empty($image_url) && !empty($url_title))
    318333                            break;
    319                         }
    320        
    321334                    }
    322                 }
     335   
     336                }
     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
     356               
    323357                if (!$this->has_right_size($image_url)) {
    324358                   
     
    366400           
    367401            if ($image_url && !empty($image_url) && is_string($image_url)) {
     402               
     403                //Check if url is valid
     404                if (filter_var($image_url, FILTER_VALIDATE_URL) === false)
     405                    return false;
    368406               
    369407                if ($images_min_width > 0 || $images_min_height > 0 || !$this->images_allow_ads || !$this->images_allow_square) {
Note: See TracChangeset for help on using the changeset viewer.