| 1 | <?php |
|---|
| 2 | require_once(WCF_DIR.'lib/data/message/bbcode/BBCodeParser.class.php'); |
|---|
| 3 | require_once(WCF_DIR.'lib/data/message/bbcode/BBCode.class.php'); |
|---|
| 4 | |
|---|
| 5 | /** |
|---|
| 6 | * Provides a bbcode to link slideshare presentations |
|---|
| 7 | * usage: [slideshare]full url[/slideshare] |
|---|
| 8 | * |
|---|
| 9 | * @author Torben Brodt |
|---|
| 10 | * @package de.easy-coding.wcf.data.message.bbcode.slideshare |
|---|
| 11 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
|---|
| 12 | */ |
|---|
| 13 | class SlideShareBBCode implements BBCode { |
|---|
| 14 | |
|---|
| 15 | /** |
|---|
| 16 | * @see BBCode::getParsedTag() |
|---|
| 17 | */ |
|---|
| 18 | public function getParsedTag($openingTag, $content, $closingTag, BBCodeParser $parser) { |
|---|
| 19 | if ($parser->getOutputType() == 'text/html') { |
|---|
| 20 | $new = parse_url($content); |
|---|
| 21 | $path = $new['path']; |
|---|
| 22 | |
|---|
| 23 | if (($io = fsockopen("www.slideshare.net", 80, $errno, $errstr, 5 )) !== false) { |
|---|
| 24 | $i=0; |
|---|
| 25 | $datacount=0; |
|---|
| 26 | |
|---|
| 27 | $send = sprintf("GET %s HTTP/1.1\r\n", $path); |
|---|
| 28 | $send .= "Host: www.slideshare.net\r\n"; |
|---|
| 29 | $send .= "Connection: Close\r\n\r\n"; |
|---|
| 30 | |
|---|
| 31 | fputs ($io, $send); |
|---|
| 32 | |
|---|
| 33 | // send request |
|---|
| 34 | $send = ''; |
|---|
| 35 | do { |
|---|
| 36 | $send .= fgets($io, 4096); |
|---|
| 37 | } while (strpos($send, "\r\n\r\n") === false); |
|---|
| 38 | |
|---|
| 39 | // get response |
|---|
| 40 | while (!feof($io)) { |
|---|
| 41 | $send = fgets($io, 4096); |
|---|
| 42 | if ($i++> 20) { |
|---|
| 43 | if (preg_match('/<link rel\="video_src" href\="(.+)"\/>/', $send, $hits)) { |
|---|
| 44 | $slide_url = $hits[1]; |
|---|
| 45 | $datacount++; |
|---|
| 46 | } |
|---|
| 47 | else if (preg_match('/<meta name\="video_height" content\="([0-9]+)" \/>/', $send, $hits)) { |
|---|
| 48 | $slide_height = $hits[1]; |
|---|
| 49 | $datacount++; |
|---|
| 50 | } |
|---|
| 51 | else if (preg_match('/<meta name\="video_width" content\="([0-9]+)" \/>/', $send, $hits)) { |
|---|
| 52 | $slide_width = $hits[1]; |
|---|
| 53 | $datacount++; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | if ($datacount >= 3) { |
|---|
| 57 | break; |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | fclose($io); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | if(isset($slide_url)) { |
|---|
| 66 | return sprintf('<object type="application/x-shockwave-flash" data="%s" width="%d" height="%d"> |
|---|
| 67 | <param name="movie" value="%s" /></object>', |
|---|
| 68 | $slide_url, |
|---|
| 69 | isset($slide_width) ? $slide_width : 425, |
|---|
| 70 | isset($slide_height) ? $slide_height : 348, |
|---|
| 71 | $slide_url |
|---|
| 72 | ); |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | else if ($parser->getOutputType() == 'text/plain') { |
|---|
| 76 | return $content; |
|---|
| 77 | } |
|---|
| 78 | } |
|---|
| 79 | } |
|---|
| 80 | ?> |
|---|