Changeset 1958

Show
Ignore:
Timestamp:
2006-02-05 21:23:45 (3 years ago)
Author:
ctford
Message:

Give duration info, and put download Annodex, Ogg Theora and CMML links down the bottom out of the way.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Anode/trunk/acidfree/class_annodex.inc

    r1954 r1958  
    169169        } 
    170170 
    171  
    172171        $arg_name = "media"; 
    173          
     172 
     173        /* Check if we should output raw annodex, cmml etc or display 
     174         * information about the video. 
     175         */       
    174176        if(isset($_GET[$arg_name])) { 
    175177                $mode = $_GET[$arg_name]; 
     
    199201        } else { 
    200202 
    201                 $output .= "<h1>"; 
    202                 $output .= l("Annodex", "node/{$node->nid}",NULL,"$arg_name=annodex")." "; 
    203                 $output .= l("Ogg Theora", "node/{$node->nid}",NULL,"$arg_name=theora")." "; 
    204                 $output .= l("CMML", "node/{$node->nid}",NULL,"$arg_name=cmml")." "; 
    205                 $output .= "</h1>"; 
    206                 $output .= "<br />"; 
    207  
    208  
     203                $output .= headers($node, $arg_name); 
     204                $output .= "<br>"; 
     205                $output .= "<br>"; 
    209206                $output .= clip_table( $node, $arg_name ); 
    210207 
    211208                /* Add new clip form */ 
    212209                if( $editing ) { 
    213                         $output .= '<form name="clipform" action="?q=node/'.$node->nid.'" method="POST"> 
     210                        $output .= new_clip_form( $node ); 
     211                         
     212                } 
     213                 
     214                $output .= footer($node,$arg_name); 
     215                $output .= $node->body; 
     216        } 
     217 
     218 
     219        return $output; 
     220
     221 
     222/* FIXME Need major error checking. */ 
     223function insert_clip( $attributes, $node ) { 
     224        if( $attributes['id'] ) { 
     225                $start = 60*60*$attributes['start_hours'] + 60*$attributes['start_minutes'] + $attributes['start_seconds']; 
     226 
     227                /* Check whether we need to create a new clip or just update an 
     228                 * old one. 
     229                 */ 
     230                $occurances = db_result(db_query("SELECT COUNT(`id`) FROM {acidfree_cmml_clips} WHERE `id` = '{$attributes['id']}';")); 
     231 
     232                if( $occurances == 0 ) { 
     233 
     234                        $img = add_clip_png( $node, $attributes['id'], $start ); 
     235                         
     236                        $result = db_query("INSERT INTO {acidfree_cmml_clips} (`nid`, `a_href`, `a_text`, `img`, `desc`, `start`, `end`, `id`, `track`) VALUES('{$node->nid}', '{$attributes['a_href']}', '{$attributes['a_text']}', '$img', '{$attributes['desc']}', $start, ".(float)$attributes['end'].",'{$attributes['id']}', '{$attributes['track']}');");                 
     237                } else { 
     238                        $result = db_query("UPDATE {acidfree_cmml_clips} SET `nid` = '{$node->nid}', `a_href` = '{$attributes['a_href']}', `a_text` = '{$attributes['a_text']}', `img` = '{$attributes['img']}', `desc` = '{$attributes['desc']}', `start` = '$start', `end` = '{$attributes['end']}', `id` = '{$attributes['id']}', `track` = '{$attributes['track']}' WHERE `id` = '{$attributes['id']}';"); 
     239                } 
     240        } 
     241 
     242        return; 
     243
     244 
     245function clip_table( $node, $arg_name) { 
     246 
     247                $result = db_query("SELECT * FROM {acidfree_cmml_clips} WHERE nid={$node->nid} ORDER BY `start`;");      
     248 
     249                /* Output clip information in a themed table. */ 
     250                $table_rows = array(); 
     251                $header = array(); 
     252                $header[] = array( 'data'=>'Clip ID'); 
     253                $header[] = array( 'data'=>'Image'); 
     254                $header[] = array( 'data'=>'Description'); 
     255                $header[] = array( 'data'=>'Options'); 
     256 
     257                while( $row = db_fetch_object($result) ) { 
     258 
     259                        $cells = array(); 
     260 
     261                        $cells[] = array('data'=>l($row->id, "node/{$node->nid}",NULL,"$arg_name=annodex&id={$row->id}")."<br />"); 
     262                        if( $row->img ) { 
     263                                $cells[] = array('data'=>"<a href =\"?q=node/{$node->nid}&$arg_name=annodex&id={$row->id}\"><img height=120 width=120 src=\"{$row->img}\"></a>"); 
     264                        } else { 
     265                                $cells[] = array('data'=>NULL); 
     266                        } 
     267 
     268                        if( $row->desc ) { 
     269                                $cells[] = array('data'=>wordwrap($row->desc,40, '<br \>', TRUE)); 
     270                        } else { 
     271                                $cells[] = array('data'=>NULL); 
     272                        } 
     273 
     274                        $cells[] = array('data'=>"dummy edit"); 
     275 
     276                        /* Add cells */ 
     277                        $table_rows[] = $cells; 
     278                } 
     279                /* Add table */ 
     280                return theme_table( $header, $table_rows ); 
     281 
     282
     283 
     284function add_clip_png( $node, $id, $time) { 
     285 
     286        $mplayer = variable_get('acidfree_path_to_mplayer', '/usr/bin/mplayer'); 
     287        $tmpdir = acidfree_mktmpdir('mplayer'); 
     288        $path = realpath(_acidfree_get_large_path( $node, true )); 
     289        $command = "$mplayer -vo png:z=6 -vf scale -zoom -xy 120 -ao null -ss $time -frames 1 $path"; 
     290            chdir($tmpdir); 
     291            $mplayeroutput = shell_exec($command); 
     292            if ($oldcwd) { 
     293                chdir($oldcwd); 
     294            } 
     295            $mplayer_out = $tmpdir.DIRECTORY_SEPARATOR."00000001.png"; 
     296            if (!file_exists($mplayer_out)) { 
     297                drupal_set_message("file $mplayer_out does not exist", 'error'); 
     298            } else if(!is_readable($mplayer_out)) { 
     299                drupal_set_message("file $mplayer_out is not readable", 'error'); 
     300            } else { 
     301                    $filename = "{$node->nid}_$id.png"; 
     302                    $png = acidfree_add_file($node, $mplayer_out, $filename, "image/png", true); 
     303            } 
     304 
     305        //FIXME This will only work if an absolute path is given for 
     306        //filemanager. This is a hack to get around the mess that giving 
     307        //absolute path to filemanager wreaks with the URLs. 
     308        if( $png->working ) { 
     309                $area = "working"; 
     310        } else if ( $png->active ) { 
     311                $area = "active"; 
     312        } 
     313        if( $path->dir ) { 
     314                $dir = "1"; 
     315        } else { 
     316                $dir = "0"; 
     317        } 
     318        $path = "files/$area/$dir/{$png->filename}"; 
     319        $bad_url = url($path,null,null,true); 
     320        $base_url = explode( "/?q", $bad_url ); 
     321        $path = "{$base_url[0]}/$path"; 
     322        return $path; 
     323
     324 
     325function headers( $node, $arg_name ) { 
     326 
     327        $media_file = realpath( _acidfree_get_large_path( $node, true )); 
     328        $anx = new AnnodexWriter(); 
     329        $anx->import( $media_file, null, null, 0, -1 ); 
     330 
     331        $header = array(); 
     332        $header[] = array( 'data'=>'Title'); 
     333        $header[] = array( 'data'=>'Duration'); 
     334 
     335        $row = array(array('data'=>$node->title), array('data'=>$anx->get_duration()));  
     336 
     337        $output .="<br>"; 
     338        $output .="<strong>"; 
     339        $output .= theme_table( $header, array($row) ); 
     340        $output .="</strong>"; 
     341        $output .="<h1>"; 
     342        $output .= l("Play Annodex", "node/{$node->nid}",NULL,"$arg_name=annodex")." "; 
     343        $output .="</h1>"; 
     344 
     345        $anx->close(); 
     346 
     347        return $output; 
     348
     349 
     350function footer($node, $arg_name) { 
     351        $output .= "<h2>Download... "; 
     352 
     353 
     354        $output .= l("Annodex", "node/{$node->nid}",NULL,"$arg_name=annodex")." "; 
     355        $output .= "|"; 
     356        $output .= l("Ogg Theora", "node/{$node->nid}",NULL,"$arg_name=theora")." "; 
     357        $output .= "|"; 
     358        $output .= l("CMML", "node/{$node->nid}",NULL,"$arg_name=cmml")." "; 
     359        $output .= "</h2>"; 
     360        $output .= "<br />"; 
     361        return $output; 
     362
     363 
     364function new_clip_form( $node ) { 
     365        $form['foo'] = array( 
     366                '#type' => 'textfield', 
     367                '#title' => t('Description'), 
     368                '#default_value' => t('00'), 
     369                '#size' => 1, 
     370                '#maxlength' => 2, 
     371                '#description' => t('Description of clip'), 
     372); 
     373 
     374        $output .= '<form name="clipform" action="?q=node/'.$node->nid.'" method="POST"> 
    214375<div> 
    215376<br /><br /> 
     
    224385</div> 
    225386</form>'; 
    226                 } 
    227                  
    228                 $output .= $node->body; 
    229         } 
    230  
    231387        return $output; 
    232388} 
    233  
    234 /* FIXME Need major error checking. */ 
    235 function insert_clip( $attributes, $node ) { 
    236         if( $attributes['id'] ) { 
    237                 $start = 60*60*$attributes['start_hours'] + 60*$attributes['start_minutes'] + $attributes['start_seconds']; 
    238  
    239                 /* Check whether we need to create a new clip or just update an 
    240                  * old one. 
    241                  */ 
    242                 $occurances = db_result(db_query("SELECT COUNT(`id`) FROM {acidfree_cmml_clips} WHERE `id` = '{$attributes['id']}';")); 
    243  
    244                 if( $occurances == 0 ) { 
    245  
    246                         $img = add_clip_png( $node, $attributes['id'], $start ); 
    247                          
    248                         $result = db_query("INSERT INTO {acidfree_cmml_clips} (`nid`, `a_href`, `a_text`, `img`, `desc`, `start`, `end`, `id`, `track`) VALUES('{$node->nid}', '{$attributes['a_href']}', '{$attributes['a_text']}', '$img', '{$attributes['desc']}', $start, ".(float)$attributes['end'].",'{$attributes['id']}', '{$attributes['track']}');");                 
    249                 } else { 
    250                         $result = db_query("UPDATE {acidfree_cmml_clips} SET `nid` = '{$node->nid}', `a_href` = '{$attributes['a_href']}', `a_text` = '{$attributes['a_text']}', `img` = '{$attributes['img']}', `desc` = '{$attributes['desc']}', `start` = '$start', `end` = '{$attributes['end']}', `id` = '{$attributes['id']}', `track` = '{$attributes['track']}' WHERE `id` = '{$attributes['id']}';"); 
    251                 } 
    252         } 
    253  
    254         return; 
    255 } 
    256  
    257 function clip_table( $node, $arg_name) { 
    258  
    259                 $result = db_query("SELECT * FROM {acidfree_cmml_clips} WHERE nid={$node->nid} ORDER BY `start`;");      
    260  
    261                 /* Output clip information in a themed table. */ 
    262                 $table_rows = array(); 
    263                 $header = array(); 
    264                 $header[] = array( 'data'=>'Clip ID'); 
    265                 $header[] = array( 'data'=>'Image'); 
    266                 $header[] = array( 'data'=>'Description'); 
    267                 $header[] = array( 'data'=>'Options'); 
    268  
    269                 while( $row = db_fetch_object($result) ) { 
    270  
    271                         $cells = array(); 
    272  
    273                         $cells[] = array('data'=>l($row->id, "node/{$node->nid}",NULL,"$arg_name=annodex&id={$row->id}")."<br />"); 
    274                         if( $row->img ) { 
    275                                 $cells[] = array('data'=>"<a href =\"?q=node/{$node->nid}&$arg_name=annodex&id={$row->id}\"><img height=120 width=120 src=\"{$row->img}\"></a>"); 
    276                         } else { 
    277                                 $cells[] = array('data'=>NULL); 
    278                         } 
    279  
    280                         if( $row->desc ) { 
    281                                 $cells[] = array('data'=>wordwrap($row->desc,40, '<br \>', TRUE)); 
    282                         } else { 
    283                                 $cells[] = array('data'=>NULL); 
    284                         } 
    285  
    286                         $cells[] = array('data'=>"dummy edit"); 
    287  
    288                         /* Add cells */ 
    289                         $table_rows[] = $cells; 
    290                 } 
    291                 /* Add table */ 
    292                 return theme_table( $header, $table_rows ); 
    293  
    294 } 
    295  
    296 function add_clip_png( $node, $id, $time) { 
    297  
    298         $mplayer = variable_get('acidfree_path_to_mplayer', '/usr/bin/mplayer'); 
    299         $tmpdir = acidfree_mktmpdir('mplayer'); 
    300         $path = realpath(_acidfree_get_large_path( $node, true )); 
    301         $command = "$mplayer -vo png:z=6 -vf scale -zoom -xy 120 -ao null -ss $time -frames 1 $path"; 
    302             chdir($tmpdir); 
    303             $mplayeroutput = shell_exec($command); 
    304             if ($oldcwd) { 
    305                 chdir($oldcwd); 
    306             } 
    307             $mplayer_out = $tmpdir.DIRECTORY_SEPARATOR."00000002.png"; 
    308             if (!file_exists($mplayer_out)) { 
    309                 drupal_set_message("file $mplayer_out does not exist", 'error'); 
    310             } else if(!is_readable($mplayer_out)) { 
    311                 drupal_set_message("file $mplayer_out is not readable", 'error'); 
    312             } else { 
    313                     $filename = "{$node->nid}_$id.png"; 
    314                     $png = acidfree_add_file($node, $mplayer_out, $filename, "image/png", true); 
    315             } 
    316  
    317         //FIXME This will only work if an absolute path is given for 
    318         //filemanager. This is a hack to get around the mess that giving 
    319         //absolute path to filemanager wreaks with the URLs. 
    320         if( $png->working ) { 
    321                 $area = "working"; 
    322         } else if ( $png->active ) { 
    323                 $area = "active"; 
    324         } 
    325         if( $path->dir ) { 
    326                 $dir = "1"; 
    327         } else { 
    328                 $dir = "0"; 
    329         } 
    330         $path = "files/$area/$dir/{$png->filename}"; 
    331         $bad_url = url($path,null,null,true); 
    332         $base_url = explode( "/?q", $bad_url ); 
    333         $path = "{$base_url[0]}/$path"; 
    334         return $path; 
    335 }