示例#1
0
/**
 * Takes a message body, and replaces all URLs with media bbcode after 
 * caching any necessary media information.  
 * 
 * For new posts, plugin code is injected into hook object to update with
 * postids based on the posthash.
 * 
 * @param	string		Message Body
 * @param	integer		Userid of poster
 * @param	integer		Post ID of message
 * 
 * @return	string		Updated Message Body
 */
function goldbrick_process_post($message, $userid, $postid = 0, $posthash, $gb_options = 0)
{
    global $vbulletin, $goldbrick;
    $matches = null;
    if (!preg_match_all('{\\[url\\](.+)\\[\\/url\\]}i', $message, $matches) and !preg_match_all('{\\[media\\](.+)\\[\\/media\\]}i', $message, $matches)) {
        return $message;
    }
    $find = array();
    $replace = array();
    require_once DIR . '/goldbrick/includes/class_goldbrick.php';
    foreach ($matches[1] as $url) {
        $goldbrick = new goldbrick_media($vbulletin);
        if ($media = $goldbrick->parse_url($url, $gb_options)) {
            $find[] = "{\\[url\\]" . preg_quote($url) . "\\[\\/url\\]}i";
            $replace[] = '[media]' . $url . '[/media]';
            //Type of Media 0 = null,  1 = Post, 2 = profile, 3 = blog
            $flag = 1;
            $goldbrick->save($media, $userid, $postid, $posthash, $flag);
        }
    }
    $message = preg_replace($find, $replace, $message);
    if ($postid) {
        return $message;
    }
    $code = '$goldbrick = new Goldbrick_Media($vbulletin);' . "\n";
    $code .= '$goldbrick->set_postid($post["postid"], $post["posthash"]);';
    goldbrick_inject_plugin('newpost_complete', $code);
    return $message;
}
示例#2
0
 /**
  * Delivers the HTML for a given media tag.
  * This is the BBCode callback function (wrapped in a public callback, rather).
  * 
  * @param	string		URL to deliver
  * @param	string		Options to customize delivery
  * 
  * @return	string		HTML output
  */
 public function deliver($url, $options)
 {
     global $vbphrase, $stylevar;
     $url = unhtmlspecialchars($url);
     if (!($info = $this->media[$url])) {
         if ($this->debug) {
             goldbrick_debug('Media Cache', $this->media);
             goldbrick_debug('Requested URL', $url);
             trigger_error('URL not pre-cached!', E_USER_WARNING);
         }
         $url = htmlspecialchars_uni($url);
         return "<a href=\"{$url}\" target=\"_blank\">{$url}</a>";
     }
     $info['unique'] = substr($info['hash'], 0, 8);
     if ($info['site'] !== 0) {
         //$info['profile'] = $this->get_config_profile($info['site']);
     } else {
         $info['profile'] = $this->get_config_ext_profile($info['profile']);
     }
     if (is_integer($url)) {
         $info = array_merge($info, $this->parse_media_options($options));
     }
     eval('$content = "' . fetch_template('gb_player') . '";');
     if ($this->debug) {
         goldbrick_debug('Delivering Media', $url);
         echo $content . '<hr />';
     }
     $cutoff = 1;
     #$this->registry->options['gb_expiration_period'] * 86400;
     // cleanup
     if ($info['dateline'] + $cutoff < TIMENOW) {
         if (empty($this->expired)) {
             goldbrick_inject_plugin('global_complete', "require_once(DIR . '/goldbrick/plugins/global_complete.php');");
         }
         $this->expired[] = md5($url);
     }
     return $content;
 }