Plugin Directory

Changeset 1703204


Ignore:
Timestamp:
07/26/2017 03:29:31 PM (9 years ago)
Author:
institutpandore
Message:

v1.1.0

Location:
doctorfeature/trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • doctorfeature/trunk/DoctorFeaturePicture.php

    r1689484 r1703204  
    11<?php
    2 
    32define('GFP_PLUGIN_PATH', plugin_dir_path(__FILE__));
    43require_once GFP_PLUGIN_PATH . 'vendor/autoload.php';
     
    98{
    109    // Constant variables
    11     private $width      = 1200;
    12     private $height     = 627;
    13     private $font_size  = 70;
    14     private $font       = 'font/Roboto-Bold.ttf';
    15     private $text_color = array(255, 255, 255);
    16     private $url;
    17     private $attachment_id;
    18     private $featured_php_img;
    19 
    20     function __construct()
    21     {
    22         $options = get_option('drf_option');
    23 
    24         if (isset( $this->options['size'] ))
    25             $this->font_size    = $options['size'];
    26 
    27         if (isset( $this->options['font'] ))
    28             $this->font         = $options['font'];
    29 
    30         if (isset( $this->options['color'] ) && $this->options['color'] != '')
    31             $this->text_color   = $this->hex2rgb($options['color']);
    32 
     10    private $width                  =  1200;
     11    private $height                 =  627;
     12    private $font_size              =  70;
     13    private $font                   =  'font/Roboto-Bold.ttf';
     14    private $text_color             =  array(255, 255, 255);
     15    private $text_displayed         =  true;
     16
     17    private $is_category_gradient   =  false;
     18    private $forced_gradient        =  array('#FF0000', '#00FF00', '#0000FF');
     19
     20    private $url                    =  '';     
     21    private $attachment_id          =  0;
     22    private $featured_php_img       =  NULL;
     23
     24    function __construct() {
     25    }
     26
     27    /**
     28     * Sets the variables
     29     *
     30     * @param      integer  $post_ID  The post id
     31     */
     32    private function get_settings($post_ID)
     33    {
     34        $options        = get_option('drf_option');
     35
     36        // Is there a gradient for category?
     37        $the_category   = get_the_category($post_ID);
     38        $cat_id         = $the_category[0]->term_id;
     39        $cat_options    = get_term_meta($cat_id, 'category_gradient', true);
     40        if ($cat_options != '')
     41        {
     42            $pieces = explode(',', $cat_options);
     43            $this->is_category_gradient         = true;
     44            $this->forced_gradient              = $pieces;
     45        }
     46
     47        // Global settings
     48        if (isset( $options['size'] ))
     49            $this->font_size            = $options['size'];
     50
     51        if (isset( $options['font'] ))
     52            $this->font                 = $options['font'];
     53
     54        if (isset( $options['color'] ) && $options['color'] != '')
     55            $this->text_color           = $this->hex2rgb($options['color']);
     56
     57        if (!isset( $options['text_displayed'] ))
     58            $this->text_displayed       = false;
    3359    }
    3460
     
    4268    public function generate_picture($post_ID, $post)
    4369    {
     70        // Fetch all general settings
     71        $this->get_settings($post_ID);
     72
    4473        if (has_post_thumbnail($post_ID)) {
    4574            return;
     
    5281                $this->featured_php_img = $this->gradient_2colors_vertical($this->width, $this->height, 'v', $colors);
    5382            }
    54 
    55             $this->align_text($post->post_title);
    56             $this->upload_image_wp($post_ID);
    57             set_post_thumbnail($post_ID, $this->attachment_id);
     83           
     84            if ($this->text_displayed == true) {
     85                $this->align_text($post->post_title);
     86            }
     87           
     88            $this->upload_image_wp($post_ID);
     89            set_post_thumbnail($post_ID, $this->attachment_id);
    5890        }
    5991    }
     
    78110        $textbox->setTextAlign('center', 'center');
    79111        $textbox->draw($title);
    80        
    81112    }
    82113
     
    222253    private function gradient_3colors_horizontal($width, $height, $colors)
    223254    {
     255        //if # alors enlever le #
     256        for($i=0; $i<count($colors); $i++)
     257        {
     258            if($colors[$i][0] == '#') $colors[$i] = substr($colors[$i], 1);
     259        }
     260
    224261        $colorsCount    =  count($colors) - 1 ;           
    225262        $limit          =  floor($width / $colorsCount);
     
    261298        $category = $this->get_yoast_primary_cat($post->ID);
    262299
    263         $gradients = array(
    264             array('00FF7F', '00BFFF'),
    265             array('FFC0CB', 'DC143C', '000080'),
    266             array('DC143C', '6A5ACD'),
    267             array('FFFF00', '05AE36'),
    268             array('FF00FF', '0000CD'),
    269             array('FF00FF', 'FF4500', 'FFA500'),
    270             array('44BFFF', '7B68EE', 'C71585'),
    271             array('000080', '0000CD', '00BFFF'),
    272             array('000000', '000000', '000000'),
    273         );
    274 
    275         srand(intval($category->term_id));
    276         $random = rand(0, 9999) % count($gradients);
    277 
    278         return $gradients[$random];
    279 
    280 
     300        if($this->is_category_gradient==true)
     301        {
     302            return $this->forced_gradient;
     303        } else {
     304            $gradients = array(
     305                array('00FF7F', '00BFFF'),
     306                array('FFC0CB', 'DC143C', '000080'),
     307                array('DC143C', '6A5ACD'),
     308                array('FFFF00', '05AE36'),
     309                array('FF00FF', '0000CD'),
     310                array('FF00FF', 'FF4500', 'FFA500'),
     311                array('44BFFF', '7B68EE', 'C71585'),
     312                array('000080', '0000CD', '00BFFF'),
     313                array('000000', '000000', '000000'),
     314            );
     315
     316            srand(intval($category->term_id));
     317            $random = rand(0, 9999) % count($gradients);
     318
     319            return $gradients[$random];
     320        }
    281321    }
    282322}
  • doctorfeature/trunk/DoctorFeaturePicture_settings.php

    r1689484 r1703204  
    66     */
    77    private $options;
     8    private $cat_options;
    89
    910    /**
     
    1516        add_action( 'admin_init', array( $this, 'page_init' ) );
    1617    }
     18
     19
    1720
    1821    /**
     
    3639    {
    3740       
    38         $this->options = get_option( 'drf_option' );
     41        $this->options      = get_option( 'drf_option' );
     42        // $this->$cat_options = get_option('drf_cat_option');
    3943        ?>
    4044        <div class="wrap">
     
    9195            'drf-settings',
    9296            'text_settings_id'
     97        );
     98
     99        add_settings_field(
     100            'select_text',
     101            __('Allow Text', 'drf'),
     102            array( $this, 'text_displayed_callback' ),
     103            'drf-settings',
     104            'text_settings_id'
    93105        );     
    94106    }
     
    101113    public function sanitize( $input )
    102114    {
     115        // print_r($input);
     116        // die();
    103117        return $input;
    104118    }
     
    110124    {
    111125        print __("As soon as you'll save an article that doesn't have any featured image, DoctorFeature will create a nice picture for you. You can modify a few parameters for these images below:", 'drf');
     126        // print_r($this->cat_options);
     127        // die();
    112128    }
    113129
     
    120136
    121137            <select name="drf_option[font]">
    122                 <option value="/font/Roboto-Bold.ttf">Roboto Bold</option>
    123                 <option value="/font/Roboto-Italic.ttf">Roboto Italic</option>
    124                 <option value="/font/Roboto-Regular.ttf">Roboto Regular</option>
    125                 <option value="/font/IndieFlower.ttf">Indie Flower</option>
    126                 <option value="/font/Lobster-Regular.ttf">Lobster Regular</option>
     138                <option value="/font/Roboto-Bold.ttf" <?php if($this->options['font'] == '/font/Roboto-Bold.ttf') echo "selected"; ?>>Roboto Bold</option>
     139                <option value="/font/Roboto-Italic.ttf" <?php if($this->options['font'] == '/font/Roboto-Italic.ttf') echo "selected"; ?>>Roboto Italic</option>
     140                <option value="/font/Roboto-Regular.ttf" <?php if($this->options['font'] == '/font/Roboto-Regular.ttf') echo "selected"; ?>>Roboto Regular</option>
     141                <option value="/font/IndieFlower.ttf" <?php if($this->options['font'] == '/font/IndieFlower.ttf') echo "selected"; ?>>Indie Flower</option>
     142                <option value="/font/Lobster-Regular.ttf" <?php if($this->options['font'] == '/font/Lobster-Regular.ttf') echo "selected"; ?>>Lobster Regular</option>
    127143            </select>
    128144
     
    159175        print __('Color of the text written on the picture', 'drf');
    160176    }
     177
     178    public function text_displayed_callback()
     179    {
     180        ?>
     181<!--         <select name="drf_option[text]">
     182            <option value="Yes">Yes</option>
     183            <option value="No">No</option>
     184        </select> -->
     185
     186        <label>
     187            <input type="checkbox" name="drf_option[text_displayed]" value="1" <?php if (isset($this->options['text_displayed'])) echo "checked"; ?>>
     188            Display post title on the image
     189        </label>
     190
     191        <?php
     192    }
    161193}
    162194?>
  • doctorfeature/trunk/doctorfeature.php

    r1689484 r1703204  
    66    Description: Generates a featured picture for each post with a nice gradient.
    77    Author: André de Hillerin
    8     Version: 1.0
     8    Version: 1.1.0
    99    Author URI: https://cercle.institut-pandore.com/user/theseconddre/
    1010    License: GPL2
     
    2727*/
    2828
    29 include 'DoctorFeaturePicture.php';
    30 
    31 include 'DoctorFeaturePicture_settings.php';
     29define('GFP_PLUGIN_PATH', plugin_dir_path(__FILE__));
     30require_once GFP_PLUGIN_PATH . "classes.php";
    3231
    3332if( is_admin() )
    3433{
     34    // Generate picture
    3535    $generatedPicture = new DoctorFeaturePicture();
    3636    add_action('publish_post', array($generatedPicture, 'generate_picture'), 10, 2);
     37
     38    // Settings
    3739    $my_settings_page = new DoctorFeaturePicture_settings();
     40    $my_category_settings = new DoctorFeaturePicture_category_settings();
    3841}
    3942
  • doctorfeature/trunk/readme.txt

    r1689779 r1703204  
    11=== DoctorFeature ===
    22
    3 Contributors: André de Hillerin, Institut Pandore
    4 Tags: gradient, generator, featured image, thumbnail, automation
    5 Requires at least: 4.0
     3Contributors: André de Hillerin
     4Tags: gradient, generator, featured image, category
     5Requires at least: 3.0
    66Tested up to: 4.8
    77Stable tag: 1.0
     
    2121== Changelog ==
    2222
    23 = 1.0=
     23= 1.1.0 =
     24Free to remove the text from the image
     25Free to set custom gradients for the categories
     26
     27= 1.0.0 =
    2428Add a featured image to your article
    25 
    26 
    27 == Screenshots ==
    28 
    29 assets/screenshot-2.png
    30 assets/screenshot-1.png
    31 
    32 == Frequently Asked Questions ==
    33 
    34 = Can I create my own gradients? =
    35  
    36 Well no, not yet! But of course you will be able to do this in later versions.
    37 Currently, you have a choice bewteen eight different gradients, but soon you will be authorized to choose among your own colors.
Note: See TracChangeset for help on using the changeset viewer.