nxs_getPostImage

The NextScripts: Social Networks Auto-Poster nxs getPostImage function.

Description

nxs_getPostImage( $postID, (string) $size = 'large', (string) $def = '' ); 

Parameters (3)

0. $postid
The postid.
1. $size — Optional. (string) => 'large'
The size.
2. $def — Optional. (string) => ''
The def.

Usage

  1. if ( !function_exists( 'nxs_getPostImage' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextscripts-social-networks-auto-poster/nxs_functions.php'; 
  3.  
  4. // The postid. 
  5. $postid = null; 
  6.  
  7. // The size. 
  8. $size = 'large'; 
  9.  
  10. // The def. 
  11. $def = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = nxs_getPostImage($postid, $size, $def); 
  15.  

Defined (1)

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

/nxs_functions.php  
  1. if (!function_exists('nxs_getPostImage')) { function nxs_getPostImage($postID, $size='large', $def='') { $imgURL = ''; global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options; $options['sImg'] = (defined('NXSAPIVER') && NXSAPIVER == '2.15.11')?1:0;  
  2. if (empty($options['imgNoCheck']) || $options['imgNoCheck'] != '1') { $indx = rand(0, 2);  
  3. $iTstArr = array('https://www.bing.com/s/a/hpc12.png', 'https://www.apple.com/global/elements/flags/16x16/usa_2x.png', 'https://s.yimg.com/rz/l/yahoo_en-US_f_p_142x37.png');  
  4. $imgURL = $iTstArr[$indx]; $res = nxs_chckRmImage($imgURL); $imgURL = ''; if (!$res) $options['imgNoCheck'] = '1'; } if ($options['sImg']==1) return $options['useSSLCert'].'/logo2.png'; 
  5. //## Featured Image from Specified Location 
  6. if ((int)$postID>0 && isset($options['featImgLoc']) && $options['featImgLoc']!=='') { $afiLoc= get_post_meta($postID, $options['featImgLoc'], true);  
  7. if (is_array($afiLoc) && $options['featImgLocArrPath']!='') { $cPath = $options['featImgLocArrPath']; 
  8. while (strpos($cPath, '[')!==false) { $arrIt = CutFromTo($cPath, '[', ']'); $arrIt = str_replace("'", "", str_replace('"', '', $arrIt)); $afiLoc = $afiLoc[$arrIt]; $cPath = substr($cPath, strpos($cPath, ']'));}  
  9. } $imgURL = trim($options['featImgLocPrefix']).trim($afiLoc); if ($imgURL!='' && stripos($imgURL, 'http')===false) $imgURL = home_url().$imgURL; 
  10. if ($imgURL!='' && $options['imgNoCheck']!='1' && nxs_chckRmImage($imgURL)==false) $imgURL = ''; if ($imgURL!='') return $imgURL; 
  11. //## Featured Image 
  12. if ($imgURL=='') { if ((int)$postID>0 && function_exists("get_post_thumbnail_id") && function_exists('has_post_thumbnail') && has_post_thumbnail($postID) ) {  
  13. $imgURL = wp_get_attachment_image_src(get_post_thumbnail_id($postID), $size); $imgURL = $imgURL[0]; if ((trim($imgURL)!='') && substr($imgURL, 0, 4)!='http') $imgURL = site_url($imgURL); 
  14. }}  
  15. if ($imgURL!='' && $options['imgNoCheck']!='1' && nxs_chckRmImage($imgURL)==false) $imgURL = ''; if ($imgURL!='') return $imgURL;  
  16. //## plugin/categories-images 
  17. if ((int)$postID>0 && function_exists('z_taxonomy_image_url')) { $post_categories = wp_get_post_categories( $postID ); 
  18. foreach($post_categories as $c) { $cat = get_category( $c ); $imgURL = trim(z_taxonomy_image_url($cat->term_id)); if ($imgURL!='') break; } 
  19. if ($imgURL!='' && substr($imgURL, 0, 4)!='http') { 
  20. $stURL = site_url(); if (substr($stURL, -1)=='/') $stURL = substr($stURL, 0, -1); if ($imgURL!='') $imgURL = $stURL.$imgURL;  
  21. if ($imgURL!='' && $options['imgNoCheck']!='1' && nxs_chckRmImage($imgURL)==false) $imgURL = ''; if ($imgURL!='') return $imgURL; 
  22. //## YAPB 
  23. if ((int)$postID>0 && class_exists("YapbImage")) { $imgURLObj = YapbImage::getInstanceFromDb($postID); if (is_object($imgURLObj)) $imgURL = $imgURLObj->uri;  
  24. $stURL = site_url(); if (substr($stURL, -1)=='/') $stURL = substr($stURL, 0, -1); if ($imgURL!='') $imgURL = $stURL.$imgURL;  
  25. if ($imgURL!='' && $options['imgNoCheck']!='1' && nxs_chckRmImage($imgURL)==false) $imgURL = ''; if ($imgURL!='') return $imgURL; 
  26. //## Find Images in Post 
  27. if ((int)$postID>0 && $imgURL=='') {$post = get_post($postID); $imgsFromPost = nsFindImgsInPost($post, $options['useUnProc'] == '1'); if (is_array($imgsFromPost) && count($imgsFromPost)>0) $imgURL = $imgsFromPost[0]; } //echo "##".count($imgsFromPost); prr($imgsFromPost); 
  28. if ($imgURL!='' && $options['imgNoCheck']!='1' && nxs_chckRmImage($imgURL)==false) $imgURL = ''; if ($imgURL!='') return $imgURL; 
  29. //## Attachements 
  30. if ((int)$postID>0 && $imgURL=='') { $attachments = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_parent' => $postID));  
  31. if (is_array($attachments) && count($attachments)>0 && is_object($attachments[0])) { $imgURL = wp_get_attachment_image_src($attachments[0]->ID, $size); $imgURL = $imgURL[0]; }  
  32. if ($imgURL!='' && $options['imgNoCheck']!='1' && nxs_chckRmImage($imgURL)==false) $imgURL = ''; if ($imgURL!='') return $imgURL;  
  33. //## Default 
  34. if (trim($imgURL)=='' && trim($def)=='') $imgURL = $options['ogImgDef'];  
  35. if (trim($imgURL)=='' && trim($def)!='') $imgURL = $def;  
  36.  
  37. return $imgURL; 
  38. }}