WordPress.org

Plugin Directory

Changeset 600014


Ignore:
Timestamp:
09/17/12 10:36:44 (19 months ago)
Author:
viniciusmassuchetto
Message:

Better image rules and new options.

Location:
get-post-image/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • get-post-image/trunk/get-post-image.php

    r581750 r600014  
    22/* 
    33 * Plugin Name: Get Post Image 
    4  * Version: 0.05 
    54 * Description: Get Post Image is a wrapper for the phpThumb library. It manages to easily get and convert an image from a post, and can be used for thumbnailing, formatting, masks, logo insertion and a lot of other operations. 
     5 * Version: 0.07 
    66 * Author: Vinicius Massuchetto 
     7 * Author URI: http://vinicius.soylocoporti.org.br 
    78 * Contributors: viniciusmassuchetto 
    89 * Plugin URI: http://vinicius.soylocoporti.org.br/get-post-image-wordpress-plugin/ 
    9 */ 
     10 */ 
    1011 
    1112add_theme_support ('post-thumbnails'); 
     
    3536        'image_id' => false, 
    3637        'shortcode' => false, 
     38        'size' => false, 
     39        'default_image' => false 
    3740    ); 
    3841    $args = wp_parse_args($args, $defaults); 
     
    4952    if (!$args['image_id']) 
    5053        if (!$args['image_id'] = gpi_find_image_id($args['post_id'])) 
    51             return false; 
     54            if ($args['default_image']) 
     55                $img = $args['default_image']; 
     56            else 
     57                return false; 
    5258 
    5359    if ($args['shortcode']) 
    5460        $args['phpthumb'] = html_entity_decode($args['phpthumb']); 
    5561 
    56     if (!$img = gpi_get_phpthumb($args)) 
    57         return false; 
     62    if (!$img = gpi_get_phpthumb($args)) { 
     63        if ($args['default_image']) 
     64            $img = $args['default_image']; 
     65        else 
     66            return false; 
     67    } 
    5868 
    5969    if (!$args['echo']) 
     
    113123    /* Get image to be converted */ 
    114124 
    115     $img = wp_get_attachment_metadata($args['image_id']); 
    116     $upload_dir = wp_upload_dir(); 
    117     $file = $upload_dir['basedir'] . '/' . $img['file']; 
    118     if (!is_file($file)) 
     125    $img_url = false; 
     126    if ($args['size']) { 
     127        $img_url = wp_get_attachment_image_src($args['image_id'], $args['size']); 
     128        $img_url = (!is_wp_error($img_url)) ? $img_url[0] : false; 
     129    } 
     130    if (!$img_url) 
     131        $img_url = wp_get_attachment_image_src($args['image_id']); 
     132 
     133    if (!$img_url || is_wp_error($img_url)) 
    119134        return false; 
    120135 
     136    $img_dir = dirname(get_attached_file($args['image_id'])); 
     137    $img_file = $img_dir . '/' . basename($img_url); 
     138 
     139    if (!is_file($img_file)) 
     140        return false; 
     141 
    121142    /* Get image destination */ 
    122143 
    123     preg_match('/^(.*)\/(.*)\.(jpg|jpeg|png|gif)$/i', $file, $matches); 
     144    preg_match('/^(.*)\/(.*)\.(jpg|jpeg|png|gif)$/i', $img_file, $matches); 
    124145    $ext = (in_array('f', array_keys($args_keys))) ? $args_keys['f'] : $matches[3]; 
    125146    $converted_file = $matches[1] . '/' . $matches[2] . '-gpi-' . $args_slug . '.' . $ext; 
     
    129150    if (!is_file($converted_file) || $gpi_config['debug']) { 
    130151 
    131         $query_string = 'src=' . $file . '&' . $args_phpthumb; 
     152        $query_string = 'src=' . $img_file . '&' . $args_phpthumb; 
    132153        $hash = md5($query_string . $gpi_config['security_password']); 
    133154        $query_url = $gpi['phpthumb_url'] . '?' . $query_string . '&hash=' . $hash; 
    134155 
    135         if (!$img = @file_get_contents($query_url)) 
    136             return false; 
    137  
    138         @file_put_contents($converted_file, $img, LOCK_EX); 
     156        $img = wp_remote_get($query_url); 
     157        if (200 == $img['response']['code']) { 
     158            @file_put_contents($converted_file, $img['body'], LOCK_EX); 
     159        } 
    139160 
    140161    } 
     
    142163    /* Serve it */ 
    143164 
    144     $converted_file_url = $upload_dir['url'] . '/' . $matches[2] . '-gpi-' . $args_slug . '.' . $ext; 
     165    $converted_file_url = dirname($img_url) . '/' . $matches[2] . '-gpi-' . $args_slug . '.' . $ext; 
    145166    return $converted_file_url; 
    146167} 
  • get-post-image/trunk/readme.txt

    r581853 r600014  
    66Requires at least: 2.9.2 
    77Tested up to: 3.4.1 
    8 Stable tag: 0.05 
     8Stable tag: 0.07 
     9License: GPLv2 
     10License URI: http://www.gnu.org/licenses/gpl-2.0.html 
    911 
    1012Get Post Image allows you to easily get and convert an image from a post, it supports resizing, color corrections, masks and other advanced operations. 
Note: See TracChangeset for help on using the changeset viewer.