Changeset 1954

Show
Ignore:
Timestamp:
2006-02-05 19:35:51 (3 years ago)
Author:
ctford
Message:

Hack to add thumbnails of clips automatically. Hack required because filemanager module seems to be buggy.

Files:

Legend:

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

    r1942 r1954  
    6161        $node->small = $node->large; // For now there's no distinction between 
    6262                                     // high and low resolution of the video. 
     63  
     64 
    6365} 
    6466 
     
    7375//FIXME Maybe allow CMML upload? 
    7476function _class_annodex_form($op, &$node, $name_prefix='') { 
    75 echo "op is $op"; 
    7677    switch ($op) { 
    7778    case 'new': 
     
    206207 
    207208 
    208                 $output .= clip_table( $node ); 
     209                $output .= clip_table( $node, $arg_name ); 
    209210 
    210211                /* Add new clip form */ 
     
    242243 
    243244                if( $occurances == 0 ) { 
    244                         $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']}', '{$attributes['img']}', '{$attributes['desc']}', $start, ".(float)$attributes['end'].",'{$attributes['id']}', '{$attributes['track']}');");                 
     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']}');");                 
    245249                } else { 
    246250                        $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']}';"); 
    247251                } 
    248252        } 
     253 
    249254        return; 
    250255} 
    251256 
    252 function clip_table( $node ) { 
     257function clip_table( $node, $arg_name) { 
    253258 
    254259                $result = db_query("SELECT * FROM {acidfree_cmml_clips} WHERE nid={$node->nid} ORDER BY `start`;");      
     
    288293 
    289294} 
     295 
     296function 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}