Function where I think the code should be integrated

  1. /**
  2.  *  Search and Replace routine.  Scans the body of a node and replaces every tag and its parameters with an object.
  3.  */
  4.  
  5. function _flashvideo_replace_tags(&$node, $tag) {
  6.    $max_num_params = 4; // The maximum number of parameters allowed.  All others will be ignored.
  7.    $body = ($node->body == '') ? $node->teaser : $node->body;
  8.    for($pos = 0; (($pos = $startpos = strpos($body, $tag, $pos)) !== FALSE); $pos++) {    // Search for tags
  9.       // We need to check to see if this tag has "!" in front of it, if it does, then we will ignore this tag.
  10.       if(substr($body, $pos - 1, 1) == '!') {
  11.          $body = substr_replace($body, $tag, $pos - 1, strlen($tag) + 1);
  12.       }
  13.       else {
  14.          $pos++;                                             // So that it will skip over the "[".
  15.          $params = array();
  16.          $params = _flashvideo_parse_params($body, $pos);    // Parse all the parameters.
  17.          $object = ($tag == '[thumbnail') ? flashvideo_get_thumbnail($node, $params) : flashvideo_get_video($node, $params);
  18.          $body = substr_replace($body, $object, $startpos, ($pos - $startpos));  // Replace this tag.
  19.       }
  20.    }
  21.    
  22.    if($node->body == '')
  23.       $node->teaser = $body;
  24.    else
  25.       $node->body = $body;
  26. }