Changeset 75

Show
Ignore:
Timestamp:
11/03/07 14:01:26 (6 years ago)
Author:
d0nut
Message:

finished scribd bbcode 1.0.0

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • bbcode.scribd/files/lib/data/message/bbcode/ScribdBBCode.class.php

    r73 r75  
    1111 */ 
    1212class ScribdBBCode implements BBCode { 
    13         protected $code = '<object width="450" height="500"><param name="allowScriptAccess" value="SameDomain" /><param name="movie" value="http://static.scribd.com/FlashPaperS3.swf?guid=46ei98mt1wp88&document_id=%d" /><embed width="450" height="500" src="http://static.scribd.com/FlashPaperS3.swf?guid=46ei98mt1wp88&document_id=%d" type="application/x-shockwave-flash"></embed> </object>'; 
     13        protected $code = ''; 
    1414 
    1515        /** 
     
    1717         */ 
    1818        public function getParsedTag($openingTag, $content, $closingTag, BBCodeParser $parser) { 
    19                 if(is_numeric($content)) { 
    20                 // id as input 
    21                         $document_id = intval($content); 
    22                 } else if(strpos($content, 'http://') == 0){ 
    23                 // url as input 
    24                         preg_match('/^http:\/\/www\.scribd\.com\/doc\/(\d+)\//', $content, $hits); 
    25                         $document_id = intval($hits[1]); 
    26                 } 
     19                if ($parser->getOutputType() == 'text/html') { 
     20                        $new = parse_url($content); 
     21                        $path = $new['path']; 
     22                         
     23                        if (($io = fsockopen("www.scribd.com", 80, $errno, $errstr, 5 )) !== false) { 
     24                                $i=0; 
     25                                 
     26                                $send  = sprintf("GET %s HTTP/1.1\r\n", $path); 
     27                                $send .= "Host: www.scribd.com\r\n"; 
     28                                $send .= "Connection: Close\r\n\r\n"; 
     29 
     30                                fputs ($io, $send); 
     31 
     32                                // send request 
     33                                $send = ''; 
     34                                do { 
     35                                        $send .= fgets($io, 4096); 
     36                                } while (strpos($send, "\r\n\r\n") === false); 
     37 
     38                                // get response 
     39                                while (!feof($io)) { 
     40                                        $send = fgets($io, 4096); 
     41                                        if ($i++> 100 && preg_match('/<form action="send_to_friend" controller="notifications" guid="(\w+)" id="(\d+)"/', $send, $hits)) { 
     42                                                $guid = $hits[1]; 
     43                                                $id = $hits[2]; 
     44                                                break ; 
     45                                        } 
     46                                } 
     47                                fclose($io); 
     48                        } 
    2749                 
    28                 $code = sprintf($this->code, $document_id, $document_id); 
    29  
    30                 if ($parser->getOutputType() == 'text/html') { 
    31                         return $code; 
     50                 
     51                        if(isset($guid) && isset($id)) { 
     52                                return sprintf('<object width="450" height="500"><param name="allowScriptAccess" value="SameDomain" /><param name="movie" value="http://static.scribd.com/FlashPaperS3.swf?guid=%s&document_id=%d" /><embed width="450" height="500" src="http://static.scribd.com/FlashPaperS3.swf?guid=%s&document_id=%d" type="application/x-shockwave-flash"></embed> </object>', 
     53                                        $guid, 
     54                                        $id, 
     55                                        $guid, 
     56                                        $id 
     57                                ); 
     58                        } 
    3259                } 
    3360                else if ($parser->getOutputType() == 'text/plain') {