author | Dan |
Wed, 05 Mar 2008 17:23:19 -0500 | |
changeset 0 | da45dd7fc9ec |
child 1 | ca59733d84da |
permissions | -rw-r--r-- |
0
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
1 |
<?php |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
2 |
/* |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
3 |
Plugin Name: Cortado applet support |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
4 |
Plugin URI: http://enanocms.org/ |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
5 |
Description: Extends the [[:File:foo]] tag to support Ogg Vorbis and Ogg Theora files, and can embed a player in place of those tags. |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
6 |
Author: Dan Fuhry |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
7 |
Version: 0.1b1 |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
8 |
Author URI: http://enanocms.org/ |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
9 |
*/ |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
10 |
|
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
11 |
/* |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
12 |
* Cortado applet extension for Enano |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
13 |
* Version 0.1 |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
14 |
* Copyright (C) 2008 Dan Fuhry |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
15 |
* |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
16 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
17 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
18 |
* |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
19 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
20 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
21 |
* |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
22 |
* This extension uses the Cortado Java applet written by Flumotion, Inc. The applet is also under the GNU GPL; see |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
23 |
* <http://www.flumotion.net/cortado/> for details. |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
24 |
*/ |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
25 |
|
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
26 |
global $db, $session, $paths, $template, $plugins; // Common objects |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
27 |
|
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
28 |
// Establish our parser hook |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
29 |
$plugins->attachHook('render_wikiformat_pre', 'cortado_process($text);'); |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
30 |
|
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
31 |
function cortado_process(&$text) |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
32 |
{ |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
33 |
global $db, $session, $paths, $template, $plugins; // Common objects |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
34 |
|
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
35 |
$match_count = preg_match_all('#\[\[:' . preg_quote($paths->nslist['File']) . '([^]]+?\.ogg)(\|video)?\]\]#is', $text, $matches); |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
36 |
if ( $match_count < 1 ) |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
37 |
// No media tags - might as well just abort here. |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
38 |
return false; |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
39 |
|
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
40 |
// Is there a template for this theme? If not, use a bare-bones generic default. |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
41 |
if ( file_exists( ENANO_ROOT . "/themes/{$template->theme}/cortado.tpl" ) ) |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
42 |
{ |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
43 |
$player_template = strval(@file_get_contents(ENANO_ROOT . "/themes/{$template->theme}/cortado.tpl")); |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
44 |
} |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
45 |
else |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
46 |
{ |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
47 |
$player_template = <<<TPLCODE |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
48 |
|
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
49 |
<!-- Start embedded player: {FILENAME} --> |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
50 |
|
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
51 |
<div class="cortado-wrap"> |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
52 |
<applet id="cortado_{UUID}" code="{JAVA_CLASS}.class" archive="{JAVA_JARFILES}" width="352" <!-- BEGIN video -->height="288"<!-- BEGINELSE video -->height="16"<!-- END video -->> |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
53 |
<param name="url" value="{FILE_PATH}"/> |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
54 |
<param name="local" value="false"/> |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
55 |
<param name="keepAspect" value="true"/> |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
56 |
<param name="video" value="<!-- BEGIN video -->true<!-- BEGINELSE video -->false<!-- END video -->"/> |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
57 |
<param name="audio" value="true"/> |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
58 |
<param name="bufferSize" value="200"/> |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
59 |
<param name="autoPlay" value="false"/> |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
60 |
</applet> |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
61 |
<div class="cortado-controls"> |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
62 |
<a href="#" onclick="document.applets['cortado_{UUID}'].doPlay(); return false;">Play</a> | |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
63 |
<a href="#" onclick="document.applets['cortado_{UUID}'].doPause(); return false;">Pause</a> | |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
64 |
<a href="#" onclick="document.applets['cortado_{UUID}'].doStop(); return false;">Stop</a> |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
65 |
</div> |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
66 |
</div> |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
67 |
|
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
68 |
<!-- End embedded player: {FILENAME} --> |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
69 |
|
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
70 |
TPLCODE; |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
71 |
} |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
72 |
|
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
73 |
$parser = $template->makeParserText($player_template); |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
74 |
|
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
75 |
foreach ( $matches[0] as $i => $entire_match ) |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
76 |
{ |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
77 |
// Sanitize and verify the filename |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
78 |
$filename = sanitize_page_id($matches[1][$i]); |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
79 |
$filename_paths = $paths->nslist['File'] . $filename; |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
80 |
|
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
81 |
// Make sure the file even exists |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
82 |
if ( !isPage($filename_paths) ) |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
83 |
continue; |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
84 |
|
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
85 |
// Verify permissions |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
86 |
$acl = $session->fetch_page_acl($filename, 'File'); |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
87 |
if ( !$acl->get_permissions('read') ) |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
88 |
{ |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
89 |
// No permission to read this file |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
90 |
$text = str_replace_once($entire_match, "<span class=\"cortado-error\">Access denied to file {$filename} - not embedding media player applet.</span>", $text); |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
91 |
continue; |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
92 |
} |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
93 |
|
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
94 |
// We should be good, set up the parser |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
95 |
$parser->assign_vars(array( |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
96 |
'FILENAME' => $filename, |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
97 |
'FILE_PATH' => makeUrlNS('Special', "DownloadFile/$filename", false, true), |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
98 |
'JAVA_CLASS' => 'com.fluendo.player.Cortado', |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
99 |
'JAVA_JARFILES' => scriptPath . '/plugins/cortado/cortado-ovt.jar', |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
100 |
'UUID' => $session->dss_rand() |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
101 |
)); |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
102 |
|
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
103 |
$parser->assign_bool(array( |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
104 |
'video' => ( $matches[2][$i] === '|video' ) |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
105 |
)); |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
106 |
|
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
107 |
// Run the template code and finish embed |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
108 |
$applet_parsed = $parser->run(); |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
109 |
|
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
110 |
$text = str_replace_once($entire_match, $applet_parsed, $text); |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
111 |
} |
da45dd7fc9ec
First commit. Parser extension is working. Applet is working but tends to crash the browser in many circumstances.
Dan
parents:
diff
changeset
|
112 |
} |