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