nsFindImgsInPost

The NextScripts: Social Networks Auto-Poster nsFindImgsInPost function.

Description

nsFindImgsInPost( $post, (constant) $advImgFnd = false ); 

Parameters (2)

0. $post
The post.
1. $advimgfnd (constant)
The advimgfnd.

Usage

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

Defined (1)

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

/nxs_functions.php  
  1. if (!function_exists('nsFindImgsInPost')) {function nsFindImgsInPost($post, $advImgFnd=false) { global $ShownAds; if (isset($ShownAds)) $ShownAdsL = $ShownAds; $postImgs = array(); if (!is_object($post)) return; 
  2. if ($advImgFnd) $postCntEx = apply_filters('the_content', $post->post_excerpt); else $postCntEx = $post->post_excerpt;  
  3. if ($advImgFnd) $postCnt = apply_filters('the_content', $post->post_content); else $postCnt = $post->post_content;  
  4. $postCnt = $postCntEx.$postCnt; 
  5. //$output = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $postCnt, $matches ); if ($output === false) {return false;}  
  6. //$postCnt = str_replace("'", '"', $postCnt); $output = preg_match_all( '/src="([^"]*)"/', $postCnt, $matches ); if ($output === false) {return false;} 
  7. $postCnt = str_replace("'", '"', $postCnt); $output = preg_match_all( '/< *img[^>]*src *= *["\']?([^"\']*)/i', $postCnt, $matches ); // prr($matches);  
  8. if ($output === false || $output == 0) { $vids = nsFindVidsInPost($post, $advImgFnd==false); if (count($vids)>0) $postImgs[] = 'http://img.youtube.com/vi/'.$vids[0].'/0.jpg'; else return false;}  
  9. else { foreach ($matches[1] as $match) { if (!preg_match('/^https?:\/\//', $match ) ) $match = site_url( '/' ) . ltrim( $match, '/' ); $postImgs[] = $match;} if (isset($ShownAds)) $ShownAds = $ShownAdsL; }  
  10. return $postImgs; 
  11. }}