WYSIJA_help_image

The MailPoet Newsletters WYSIJA help image class.

Defined (1)

The class is defined in the following location(s).

/helpers/image.php  
  1. class WYSIJA_help_image extends WYSIJA_help_file{ 
  2.  
  3. function __construct() { 
  4. parent::__construct(); 
  5.  
  6. /** 
  7. * get a list of images from a directory 
  8. * @param type $template 
  9. * @return type 
  10. */ 
  11. public function get_list_directory($template =' default') { 
  12. $foldersTocheck = 'themes'.DS.$template.DS.'img'.DS.'public'; 
  13. $url = 'themes/'.$template.'/img/public'; 
  14. $images_types_allowed = array('jpg', 'png', 'jpeg'); 
  15. $listed = array(); 
  16.  
  17. $path = $this->getUploadDir($foldersTocheck); 
  18.  
  19. /** get a list of files from this folder and clear them */ 
  20. if(file_exists($path)) { 
  21. $files = scandir($path); 
  22. $i=1; 
  23. foreach($files as $file_name) { 
  24. if(!in_array($file_name, array('.', '..', '.DS_Store', 'Thumbs.db'))) { 
  25. if(preg_match('/.*\.('.implode($images_types_allowed, '|').')/', $file_name, $match)) { 
  26. $image_template = array( 
  27. 'path'=> $path.$file_name,  
  28. 'width'=> 0,  
  29. 'height'=> 0,  
  30. 'url'=> $this->url($file_name, $url),  
  31. 'thumb_url'=>$this->url($file_name, $url),  
  32. 'identifier'=>'tmpl-'.$template.$i,  
  33. ); 
  34.  
  35. $listed['tmpl-'.$template.$i] = $this->valid_image($image_template); 
  36. $i++; 
  37.  
  38. return $listed; 
  39.  
  40.  
  41. /** 
  42. * make sure the image is valid, has a src and has an height and width 
  43. * @param type $post_image 
  44. * @return null 
  45. */ 
  46. public function valid_image($post_image) { 
  47. if(!isset($post_image['src']) && isset($post_image['url'])) $post_image['src'] = $post_image['url']; 
  48. if(isset($post_image['src'])) { 
  49. // check that height & width have been set, if not try to calculate 
  50. if(empty($post_image['height']) || empty($post_image['width']) || (empty($post_image['height']) && empty($post_image['width']))) { 
  51.  
  52. try { 
  53. $image_info = getimagesize($post_image['src']); 
  54.  
  55. if($image_info !== false) { 
  56. $post_image['width'] = $image_info[0]; 
  57. $post_image['height'] = $image_info[1]; 
  58.  
  59. }else{ 
  60. // if allow_url_fopen is off we need to convert the url image into a local file 
  61. $image_src = dirname(dirname(dirname(WYSIJA_UPLOADS_DIR))).wp_make_link_relative($post_image['src']); 
  62. $image_info = getimagesize($image_src); 
  63. if($image_info !== false) { 
  64. $post_image['width'] = $image_info[0]; 
  65. $post_image['height'] = $image_info[1]; 
  66.  
  67. } catch(Exception $e) { 
  68. return null; 
  69. return $post_image; 
  70. } else { 
  71. return null; 
  72.