nsFindVidsInPost

The NextScripts: Social Networks Auto-Poster nsFindVidsInPost function.

Description

nsFindVidsInPost( $post, (constant) $raw = true ); 

Parameters (2)

0. $post
The post.
1. $raw — Optional. (constant) => true
The raw.

Usage

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

Defined (1)

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

/nxs_functions.php  
  1. if (!function_exists('nsFindVidsInPost')) {function nsFindVidsInPost($post, $raw=true) { //### !!! $raw=false ## Breaks ob_start() [ref.outcontrol]: Cannot use output buffering in output buffering display handlers - Investigate 
  2. global $ShownAds; if (isset($ShownAds)) $ShownAdsL = $ShownAds; $postVids = array(); 
  3. if (is_object($post)) { if ($raw) $postCnt = $post->post_content; else $postCnt = apply_filters('the_content', $post->post_content); } else $postCnt = $post; //prr($postCnt); 
  4. $postCnt = preg_replace('/youtube.com\/vi\/(.*)\/(.*).jpg/isU', "youtube.com/v/$1/", $postCnt);  
  5. $output = preg_match_all( '@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?(#[a-z_.-][a-z0-9+\$_.-]*)?)*)@', $postCnt, $matches ); if ($output === false) {return false;}  
  6. foreach ($matches[0] as $match) {  
  7. $output2 = preg_match_all( '%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"<>&?/ ]{11})%i', $match, $matches2 ); if ($output2 === false) {return false;}  
  8. foreach ($matches2[1] as $match2) { $match2 = trim($match2); if (strlen($match2)==11) $postVids[] = $match2;}  
  9. $output3 = preg_match_all( '/^https?:\/\/(www\.)?vimeo\.com\/(clip\:)?(\d+).*$/', $match, $matches3 ); if ($output3 === false) {return false;}  
  10. foreach ($matches3[3] as $match3) { $match3 = trim($match3); if (strlen($match3)==8 || strlen($match3)==9) $postVids[] = $match3;}  
  11. $output3 = preg_match_all( '#https?://(player\.)?vimeo\.com(/video)?/(\d+)#i', $match, $matches3 ); if ($output3 === false) {return false;}  
  12. foreach ($matches3[3] as $match3) { $match3 = trim($match3); if (strlen($match3)==8 || strlen($match3)==9) $postVids[] = $match3;}  
  13. $output3 = preg_match_all( '#https?://(www\.)?facebook\.com/video\.php\?v=(\d+)#i', $match, $matches3 ); if ($output3 === false) {return false;}  
  14. foreach ($matches3[2] as $match3) { $match3 = trim($match3); if (strlen($match3)==15) $postVids[] = $match3;}  
  15. $output3 = preg_match_all( '#https?://(www\.)?facebook\.com/video/embed(/)?\?video_id=(\d+)#i', $match, $matches3 ); if ($output3 === false) {return false;}  
  16. foreach ($matches3[3] as $match3) { $match3 = trim($match3); if (strlen($match3)==15) $postVids[] = $match3;}  
  17. } $postVids = array_unique($postVids); if (isset($ShownAds)) $ShownAds = $ShownAdsL; return $postVids;  
  18. }}