Changeset 1703204
- Timestamp:
- 07/26/2017 03:29:31 PM (9 years ago)
- Location:
- doctorfeature/trunk
- Files:
-
- 2 added
- 4 edited
-
DoctorFeaturePicture.php (modified) (7 diffs)
-
DoctorFeaturePicture_category_settings.php (added)
-
DoctorFeaturePicture_settings.php (modified) (8 diffs)
-
classes.php (added)
-
doctorfeature.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doctorfeature/trunk/DoctorFeaturePicture.php
r1689484 r1703204 1 1 <?php 2 3 2 define('GFP_PLUGIN_PATH', plugin_dir_path(__FILE__)); 4 3 require_once GFP_PLUGIN_PATH . 'vendor/autoload.php'; … … 9 8 { 10 9 // 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; 33 59 } 34 60 … … 42 68 public function generate_picture($post_ID, $post) 43 69 { 70 // Fetch all general settings 71 $this->get_settings($post_ID); 72 44 73 if (has_post_thumbnail($post_ID)) { 45 74 return; … … 52 81 $this->featured_php_img = $this->gradient_2colors_vertical($this->width, $this->height, 'v', $colors); 53 82 } 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); 58 90 } 59 91 } … … 78 110 $textbox->setTextAlign('center', 'center'); 79 111 $textbox->draw($title); 80 81 112 } 82 113 … … 222 253 private function gradient_3colors_horizontal($width, $height, $colors) 223 254 { 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 224 261 $colorsCount = count($colors) - 1 ; 225 262 $limit = floor($width / $colorsCount); … … 261 298 $category = $this->get_yoast_primary_cat($post->ID); 262 299 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 } 281 321 } 282 322 } -
doctorfeature/trunk/DoctorFeaturePicture_settings.php
r1689484 r1703204 6 6 */ 7 7 private $options; 8 private $cat_options; 8 9 9 10 /** … … 15 16 add_action( 'admin_init', array( $this, 'page_init' ) ); 16 17 } 18 19 17 20 18 21 /** … … 36 39 { 37 40 38 $this->options = get_option( 'drf_option' ); 41 $this->options = get_option( 'drf_option' ); 42 // $this->$cat_options = get_option('drf_cat_option'); 39 43 ?> 40 44 <div class="wrap"> … … 91 95 'drf-settings', 92 96 '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' 93 105 ); 94 106 } … … 101 113 public function sanitize( $input ) 102 114 { 115 // print_r($input); 116 // die(); 103 117 return $input; 104 118 } … … 110 124 { 111 125 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(); 112 128 } 113 129 … … 120 136 121 137 <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> 127 143 </select> 128 144 … … 159 175 print __('Color of the text written on the picture', 'drf'); 160 176 } 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 } 161 193 } 162 194 ?> -
doctorfeature/trunk/doctorfeature.php
r1689484 r1703204 6 6 Description: Generates a featured picture for each post with a nice gradient. 7 7 Author: André de Hillerin 8 Version: 1. 08 Version: 1.1.0 9 9 Author URI: https://cercle.institut-pandore.com/user/theseconddre/ 10 10 License: GPL2 … … 27 27 */ 28 28 29 include 'DoctorFeaturePicture.php'; 30 31 include 'DoctorFeaturePicture_settings.php'; 29 define('GFP_PLUGIN_PATH', plugin_dir_path(__FILE__)); 30 require_once GFP_PLUGIN_PATH . "classes.php"; 32 31 33 32 if( is_admin() ) 34 33 { 34 // Generate picture 35 35 $generatedPicture = new DoctorFeaturePicture(); 36 36 add_action('publish_post', array($generatedPicture, 'generate_picture'), 10, 2); 37 38 // Settings 37 39 $my_settings_page = new DoctorFeaturePicture_settings(); 40 $my_category_settings = new DoctorFeaturePicture_category_settings(); 38 41 } 39 42 -
doctorfeature/trunk/readme.txt
r1689779 r1703204 1 1 === DoctorFeature === 2 2 3 Contributors: André de Hillerin , Institut Pandore4 Tags: gradient, generator, featured image, thumbnail, automation5 Requires at least: 4.03 Contributors: André de Hillerin 4 Tags: gradient, generator, featured image, category 5 Requires at least: 3.0 6 6 Tested up to: 4.8 7 7 Stable tag: 1.0 … … 21 21 == Changelog == 22 22 23 = 1.0= 23 = 1.1.0 = 24 Free to remove the text from the image 25 Free to set custom gradients for the categories 26 27 = 1.0.0 = 24 28 Add a featured image to your article 25 26 27 == Screenshots ==28 29 assets/screenshot-2.png30 assets/screenshot-1.png31 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.