Plugin Directory

Changeset 912315


Ignore:
Timestamp:
05/12/2014 12:19:57 AM (11 years ago)
Author:
huntermaster
Message:

1.1.4 link gallery imgs to prettyphoto

Location:
image-formatr/trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • image-formatr/trunk/image-formatr.php

    r912293 r912315  
    44  * Plugin URI: http://warriorself.com/blog/about/image-formatr/
    55  * Description: Formats all content images on a page / post giving them borders and captions.
    6   * Version: 1.1.3
     6  * Version: 1.1.4
    77  * Author: Steven Almeroth
    88  * Author URI: http://warriorself.com/sma/
  • image-formatr/trunk/src/class.base.php

    r912238 r912315  
    193193
    194194            return $this->get_inner_html($body);
     195        }
     196
     197        /**
     198         * Get the attached image url in the specified size
     199         *
     200         * First we look in the class parameter of the image for the attachment
     201         * id and failing this we look in the database. Then we use this id to
     202         * try and grab the attached image of that size.
     203         */
     204        function get_attachment_url( $param )
     205        {
     206            # first check if the attachment id is available in the image class
     207            preg_match('/wp-image-(\d+)/', $param['class'], $matches); // alignnone size-full wp-image-3338
     208            if (false and count($matches) > 1){
     209                $attachment_id = $matches[1];
     210            }
     211            # otherwise we need to go to the database to find the id
     212            else {
     213                global $wpdb;
     214                $query = "SELECT ID FROM $wpdb->posts WHERE guid='{$param['src']}'";
     215                $attachment_id = $wpdb->get_var($query);
     216            }
     217            # if the image has been attached, we should have the id now
     218            if ($attachment_id) {
     219                $attachment_img_src = wp_get_attachment_image_src($attachment_id, $this-> attach_thumb);
     220
     221                if ($attachment_img_src and isset($attachment_img_src[0]))
     222                    return $attachment_img_src[0];
     223            }
    195224        }
    196225
  • image-formatr/trunk/src/class.formatr.php

    r912293 r912315  
    11<?php
    2 require_once(dirname(__FILE__) . '/class.admin.php');
     2require_once(dirname(__FILE__) . '/class.flickr.php');
    33
    44if (!class_exists("ImageFormatr")) {
    5     class ImageFormatr extends ImageFormatrAdmin {
     5    class ImageFormatr extends ImageFormatrFlickr {
    66
    77        // html image tag attributes
     
    130130
    131131        /**
    132          * Request and load the data from Flickr which we only want to do
    133          * once.  Unfortunately I could not find an API call to search for
    134          * a list of Ids, therefore we're searching for all damn photos for
    135          * our user and then indexing those for the ones we want.
    136          */
    137         function load_flickr_data ( )
    138         {
    139             if ( $this-> flickr-> loaded) return true;
    140             if (!$this-> flickr-> enable) return false;
    141             $this-> flickr-> loaded = true;
    142             $this-> flickr_photos = array();
    143             $page = 0;
    144 
    145             $params = array(
    146                 'user_id'        => $this-> flickr-> nsid,
    147                 'auth_token'     => $this-> flickr-> token,
    148                 'extras'         => 'last_update,tags,url_m,url_l',
    149                 'privacy_filter' =>  1, // 1 == public photos
    150                 'content_type'   =>  1, // 1 == photos only
    151                 'per_page'       =>  500, // we can only return 500 at a time max
    152                 );
    153             $flickr_photos = array();
    154             $finished = false;
    155             while (!$finished) {
    156                 $params['page'] = ++$page;
    157                 $response = $this-> call_flickr_api('flickr.photos.search', $params, true );
    158                 if ($response['stat'] == 'ok' and
    159                     $response['photos']['photo']) {
    160                         $flickr_photos = array_merge ($flickr_photos, $response['photos']['photo']);
    161                 }
    162                 if (count($response['photos']['photo']) < 500)
    163                     $finished = true;
    164             }
    165 
    166             foreach ($flickr_photos as $photo) {
    167                 $this-> flickr_photos[$photo['id']] = $photo;
    168             }
    169 
    170             return count($this->flickr_photos);
    171         }
    172 
    173         /**
    174          * Process the [flickr] shortcodes
    175          *
    176          * [0] => [flickr pid="5496015411"]
    177          * [1] => 5496015411
    178          */
    179         function do_shortcode_flickr ( $matches )
    180         {
    181             if( count($matches) < 2 ) return '';
    182             if( !$this->load_flickr_data() ) return '';
    183 
    184             #return do_shortcode($matches[0]);
    185             if( array_key_exists( $matches[1], $this->flickr_photos ) )
    186                 $html = <<< IMAGE
    187                     <img src   ="{$this->flickr_photos[$matches[1]]['url_l']}"
    188                          thumb ="{$this->flickr_photos[$matches[1]]['url_m']}"
    189                          alt   ="{$photo['tags']}"
    190                     />
    191 IMAGE;
    192             return $html;
    193         }
    194 
    195         /**
    196          * Process the [flickrset] shortcodes
    197          *
    198          * [0] => [flickrset id="72157626094257379"]
    199          * [1] => 72157626094257379
    200          */
    201         function do_shortcode_flickrset ( $matches )
    202         {
    203             if( count($matches) < 2 ) return '';
    204 
    205             $params = array(
    206                 'photoset_id'    => $matches[1],
    207                 'auth_token'     => $this->flickr->token,
    208                 'extras'         => 'last_update,tags,url_sq,url_l',
    209                 'privacy_filter' =>  1, // 1 == public photos
    210                 );
    211             $photoset = $this-> call_flickr_api( 'flickr.photosets.getPhotos', $params, true );
    212 
    213             $html = '';
    214             foreach ($photoset['photoset']['photo'] as $photo) {
    215                #$src = $this->flickr_core->getPhotoUrl($photo);
    216                 $html .= <<< IMAGE
    217                     <img src    ="{$photo['url_l']}"
    218                          thumb  ="{$photo['url_sq']}"
    219                          alt    ="{$photo['tags']}"
    220                          width  ="{$photo['width_sq']}"
    221                          height ="{$photo['height_sq']}"
    222                          usemysize="true"
    223                     />
    224 IMAGE;
    225             }
    226             return $html;
    227         }
    228 
    229         /**
    230132         * Parse the image markup tags
    231133         *
     
    334236         * Format the html output
    335237         *
     238         * [alt] => IMG_4308
     239         * [asis] =>
     240         * [class] => attachment-thumbnail
     241         * [flickr] =>
     242         * [group] => main
     243         * [height] => 150
     244         * [hint] =>
     245         * [id] =>
     246         * [link] =>
     247         * [nocap] =>
     248         * [nofx] =>
     249         * [page] =>
     250         * [src] => /wp-content/uploads/2014/05/IMG_4308-150x150.jpg
     251         * [thumb] =>
     252         * [title] =>
     253         * [usemya] =>
     254         * [usemysize] =>
     255         * [width] => 150
     256         * [anchor] => <a href='/wp-content/uploads/2014/05/IMG_4308.jpg'>
     257         * [none] =>
     258         *
    336259         * @param array $param The image attributes/parameters as an associative array
    337260         * @return string The screen markup
     
    339262        function format ( $param )
    340263        {
     264#global $post;
     265#$debug_sma_eval ='$param'; $debug_sma_title =__METHOD__; include('debug_output_sma.php');
     266#$debug_sma_eval ='$param["anchor"]'; $debug_sma_title =__METHOD__; include('debug_output_sma.php');
     267#$debug_sma_eval ='wp_kses($param["anchor"], array("a" => array("href" => array(), "title" => array())), array("http"))'; $debug_sma_title =__METHOD__; include('debug_output_sma.php');
     268#$debug_sma_eval ='wp_kses_hair($param["anchor"], array("http","https","ftp","file"))'; $debug_sma_title =__METHOD__; include('debug_output_sma.php');
     269#$debug_sma_eval ='wp_kses_split($param["anchor"], array("a" => array("href" => array(), "title" => array())), array("http","https","ftp","file"))'; $debug_sma_title =__METHOD__; include('debug_output_sma.php');
     270#preg_match("%href='([^']+)'%", $param["anchor"], $matches);
     271#$debug_sma_eval ='$matches'; $debug_sma_title =__METHOD__; include('debug_output_sma.php');
     272
    341273            // setup dimensions width & height /////////////////////////////////
    342274
     
    348280                $img_width  = $this->def_img_width;
    349281                $img_height = $this->def_img_height;
     282            }
     283
     284            // re-link gallery images
     285            if ($param['class'] == 'attachment-thumbnail' and !$param['thumb']) {
     286                preg_match("%href='([^']+)'%", $param["anchor"], $matches);
     287                if ($matches)
     288                    $param['thumb'] = $param['src'];
     289                    $param['src'] = $matches[1];
     290#$debug_sma_eval ='$param'; $debug_sma_title =__METHOD__; include('debug_output_sma.php');
    350291            }
    351292
     
    446387        }
    447388
    448         /**
    449          * Get the attached image url in the specified size
    450          *
    451          * First we look in the class parameter of the image for the attachment
    452          * id and failing this we look in the database. Then we use this id to
    453          * try and grab the attached image of that size.
    454          */
    455         function get_attachment_url( $param )
    456         {
    457             # first check if the attachment id is available in the image class
    458             preg_match('/wp-image-(\d+)/', $param['class'], $matches); // alignnone size-full wp-image-3338
    459             if (false and count($matches) > 1){
    460                 $attachment_id = $matches[1];
    461             }
    462             # otherwise we need to go to the database to find the id
    463             else {
    464                 global $wpdb;
    465                 $query = "SELECT ID FROM $wpdb->posts WHERE guid='{$param['src']}'";
    466                 $attachment_id = $wpdb->get_var($query);
    467             }
    468             # if the image has been attached, we should have the id now
    469             if ($attachment_id) {
    470                 $attachment_img_src = wp_get_attachment_image_src($attachment_id, $this-> attach_thumb);
    471 
    472                 if ($attachment_img_src and isset($attachment_img_src[0]))
    473                     return $attachment_img_src[0];
    474             }
    475         }
    476 
    477389    } //End Class ImageFormatr
    478390
Note: See TracChangeset for help on using the changeset viewer.