Changeset 912315
- Timestamp:
- 05/12/2014 12:19:57 AM (11 years ago)
- Location:
- image-formatr/trunk
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
image-formatr/trunk/image-formatr.php
r912293 r912315 4 4 * Plugin URI: http://warriorself.com/blog/about/image-formatr/ 5 5 * Description: Formats all content images on a page / post giving them borders and captions. 6 * Version: 1.1. 36 * Version: 1.1.4 7 7 * Author: Steven Almeroth 8 8 * Author URI: http://warriorself.com/sma/ -
image-formatr/trunk/src/class.base.php
r912238 r912315 193 193 194 194 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 } 195 224 } 196 225 -
image-formatr/trunk/src/class.formatr.php
r912293 r912315 1 1 <?php 2 require_once(dirname(__FILE__) . '/class. admin.php');2 require_once(dirname(__FILE__) . '/class.flickr.php'); 3 3 4 4 if (!class_exists("ImageFormatr")) { 5 class ImageFormatr extends ImageFormatr Admin{5 class ImageFormatr extends ImageFormatrFlickr { 6 6 7 7 // html image tag attributes … … 130 130 131 131 /** 132 * Request and load the data from Flickr which we only want to do133 * once. Unfortunately I could not find an API call to search for134 * a list of Ids, therefore we're searching for all damn photos for135 * 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 photos150 'content_type' => 1, // 1 == photos only151 'per_page' => 500, // we can only return 500 at a time max152 );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' and159 $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] shortcodes175 *176 * [0] => [flickr pid="5496015411"]177 * [1] => 5496015411178 */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 = <<< IMAGE187 <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] shortcodes197 *198 * [0] => [flickrset id="72157626094257379"]199 * [1] => 72157626094257379200 */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 photos210 );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 .= <<< IMAGE217 <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 /**230 132 * Parse the image markup tags 231 133 * … … 334 236 * Format the html output 335 237 * 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 * 336 259 * @param array $param The image attributes/parameters as an associative array 337 260 * @return string The screen markup … … 339 262 function format ( $param ) 340 263 { 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 341 273 // setup dimensions width & height ///////////////////////////////// 342 274 … … 348 280 $img_width = $this->def_img_width; 349 281 $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'); 350 291 } 351 292 … … 446 387 } 447 388 448 /**449 * Get the attached image url in the specified size450 *451 * First we look in the class parameter of the image for the attachment452 * id and failing this we look in the database. Then we use this id to453 * 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 class458 preg_match('/wp-image-(\d+)/', $param['class'], $matches); // alignnone size-full wp-image-3338459 if (false and count($matches) > 1){460 $attachment_id = $matches[1];461 }462 # otherwise we need to go to the database to find the id463 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 now469 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 477 389 } //End Class ImageFormatr 478 390
Note: See TracChangeset
for help on using the changeset viewer.