/[drupal]/contributions/modules/flashvideo/flashvideo.module
ViewVC logotype

Diff of /contributions/modules/flashvideo/flashvideo.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.73.2.113, Mon Aug 31 00:20:15 2009 UTC revision 1.73.2.114, Wed Oct 21 01:05:11 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: flashvideo.module,v 1.73.2.111 2009/07/29 01:17:58 attheshow Exp $  // $Id: flashvideo.module,v 1.73.2.113 2009/08/31 00:20:15 attheshow Exp $
3  /**  /**
4   * @file   * @file
5   * Enables the ability to attach a Flash video to a node.   * Enables the ability to attach a Flash video to a node.
# Line 2180  function flashvideo_get_thumbnail_file($ Line 2180  function flashvideo_get_thumbnail_file($
2180  }  }
2181    
2182  /**  /**
  *  Parses all of the tags, and places them in a parameters array.  
  *  
  *  @param  $body  
  *   The string of the body of the node.  
  *  
  *  @param  $pos  
  *   A reference to the current location of the character pointer in the node body.  
  *  
  *  @param  $max_params  
  *   The maximum amount of allowed parameters.  
  *  
  *  @return  
  *   An array of the parameters with their associated values.  
  */  
 function _flashvideo_parse_params($body, &$pos, $max_params = 10) {  
   
   // If we are able to find the end tag delimiter denoted by "]"  
   if (($endpos = strpos($body, ']', $pos)) !== FALSE) {  
   
     // Set up an array of characters to take out from the parameter string.  
     $bad_chars = array("<p>", "</p>", "<br>", "<br />", "\n", "\r", "\t", " ");  
   
     // Get our parameter string.  
     $param_string = drupal_substr($body, $pos, ($endpos - $pos));  
   
     // Replace all bad characters with null chars.  
     $param_string = str_replace($bad_chars, '', $param_string);  
   
     // Create an array with all parameters.  
     $parts = explode(':', $param_string);  
   
     // Set the position to the end position.  
     $pos = $endpos + 1;  
   
     // Remove the first index (it's not a parameter).  
     unset($parts[0]);  
     $parts = array_values($parts);  
   
     // If there are parameters provided, and they don't exceed the maximum...  
     if ((count($parts) > 0) && (count($parts) < $max_params)) {  
       $params = array();  
   
       // Loop through all of our parameters.  
       foreach ($parts as $part) {  
   
         // Get the value and parameter for this part.  
         $sub_parts = explode('=', $part);  
   
         // The parameter needs to be all lower case.  
         $sub_parts[0] = drupal_strtolower($sub_parts[0]);  
   
         // If they actually provided a "param=value"  
         if ((drupal_strlen($sub_parts[0]) > 0) && (drupal_strlen($sub_parts[1]) > 0)) {  
   
           // Check to see if this is a FlashVar.  
           if (strpos($sub_parts[0], 'flashvar') !== FALSE) {  
   
             // If so, then split up this parameter based on the "|"  
             $flashvar = explode('|', $sub_parts[0]);  
   
             // Set the "flashvar" parameter.  
             $params['flashvars'][$flashvar[1]] = $sub_parts[1];  
           }  
           else {  
   
             // Set this parameter.  
             $params[$sub_parts[0]] = $sub_parts[1];  
           }  
         }  
       }  
   
       // Return the parameters array.  
       return $params;  
     }  
   }  
   
   // Return no parameters.  
   return array();  
 }  
   
 /**  
2183   * Search and Replace routine.  Scans the body of a node and replaces every tag and its parameters with an object.   * Search and Replace routine.  Scans the body of a node and replaces every tag and its parameters with an object.
2184   *   *
2185   *  @param $node   *  @param $node
# Line 2271  function _flashvideo_parse_params($body, Line 2190  function _flashvideo_parse_params($body,
2190   *   *
2191   */   */
2192  function _flashvideo_replace_tags(&$node, $tag) {  function _flashvideo_replace_tags(&$node, $tag) {
   
   // The maximum number of parameters allowed.  All others will be ignored.  
   $max_num_params = 4;  
   
2193    // Set the body to be modified.    // Set the body to be modified.
2194    $body = (isset($node->teaser) && $node->body == '') ? $node->teaser : $node->body;    $body = (isset($node->teaser) && $node->body == '') ? $node->teaser : $node->body;
2195    
2196    // Search for tags    $pattern = '/(!?)\[' . $tag . '(?:\s*:\s*([^=]+)=([^:\]]+))*\]/i';
2197    for ($pos = 0; (($pos = $startpos = strpos($body, $tag, $pos)) !== FALSE); $pos++) {    $offset = 0;
2198      while (preg_match($pattern, $body, $match, PREG_OFFSET_CAPTURE, $offset) == 1) {
2199      // We need to check to see if this tag has "!" in front of it, if it does, then we will ignore this tag.      // each match in $match consists of [ $matched_text, $offset ]
2200      if (drupal_substr($body, $pos - 1, 1) == '!') {      // $match[0] is the whole match
2201        // $match[1] is the character before the [
2202        // Replace the body with this with a normal "[video]" or "[thumbnail]"      // $match[n], $match[n+1] are parameter and value pairs (n=2,4,6,8,...)
2203        $body = substr_replace($body, $tag, $pos - 1, drupal_strlen($tag) + 1);  
2204        $match_start = $match[0][1];
2205    
2206        if ($match[1][0]=='!') {
2207          //if the tag was escaped with a !, just remove the ! and skip over the tag
2208          $match_length = 1;
2209          $match_replacement = "";
2210          $offset = $match_start + strlen($match[0][0]) - 1;
2211      }      }
   
     // This is the real thing.  
2212      else {      else {
2213          $match_length = strlen($match[0][0]);
       // So that it will skip over the "["  
       $pos++;  
2214    
2215        // Initialize our parameters array.        // Initialize our parameters array.
2216        $params = array();        $params = array();
2217          $maxi = count($match);
2218        // Parse all the parameters.        for ($i=2; $i<$maxi; $i=$i+2) {
2219        $params = _flashvideo_parse_params($body, $pos);          $params[$match[$i][0]] = $match[$i+1][0];
2220          }
2221    
2222        // Set the object based on the parameters given.        // Set the object based on the parameters given.
2223        $object = ($tag == '[thumbnail') ? flashvideo_get_thumbnail($node, $params) : flashvideo_get_video($node, $params);        $object = ($tag == 'thumbnail') ? flashvideo_get_thumbnail($node, $params) : flashvideo_get_video($node, $params);
2224    
2225        // Replace this tag with the real object code.        // Replace this tag with the real object code
2226        $body = substr_replace($body, $object, $startpos, ($pos - $startpos));  // Replace this tag.        $match_replacement = $object;
2227          $offset = $match_start + strlen($match_replacement);
2228      }      }
2229    
2230      // If the position exceeds the body length, then break out of the loop.      $body = substr_replace($body, $match_replacement, $match_start, $match_length);
     if ($pos >= drupal_strlen($body))  
       break;  
2231    }    }
2232    
2233    // Set the teaser or the body dependent on which one is being shown.    // Set the teaser or the body depending on which one is being shown.
2234    if ((isset($node->teaser) && $node->body == ''))    if ((isset($node->teaser) && $node->body == ''))
2235      $node->teaser = $body;      $node->teaser = $body;
2236    else    else
# Line 2427  function flashvideo_nodeapi(&$node, $op, Line 2345  function flashvideo_nodeapi(&$node, $op,
2345    
2346          if ((!flashvideo_variable_get($node->type, 'disabletag', 0)) &&          if ((!flashvideo_variable_get($node->type, 'disabletag', 0)) &&
2347            (!$teaser || flashvideo_variable_get($node->type, 'searchvideo', 0)))            (!$teaser || flashvideo_variable_get($node->type, 'searchvideo', 0)))
2348            _flashvideo_replace_tags($node, '[video');            _flashvideo_replace_tags($node, 'video');
2349    
2350          if ((!flashvideo_variable_get($node->type, 'disabletag', 0)) &&          if ((!flashvideo_variable_get($node->type, 'disabletag', 0)) &&
2351            ($teaser || flashvideo_variable_get($node->type, 'searchthumb', 0)))            ($teaser || flashvideo_variable_get($node->type, 'searchthumb', 0)))
2352            _flashvideo_replace_tags($node, '[thumbnail');            _flashvideo_replace_tags($node, 'thumbnail');
2353    
2354          break;          break;
2355    

Legend:
Removed from v.1.73.2.113  
changed lines
  Added in v.1.73.2.114

  ViewVC Help
Powered by ViewVC 1.1.2