Changeset 1966

Show
Ignore:
Timestamp:
2006-02-06 20:42:36 (3 years ago)
Author:
ctford
Message:

Organise theme_annodex_control() so it is remotely readable and maintainable.

Files:

Legend:

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

    r1965 r1966  
    160160 
    161161        global $user; 
     162        $arg_name = "media"; 
    162163 
    163164        /* Flag for determining whether to give option of editing clips */ 
    164         if (acidfree_access('update',$node)) { 
    165                $editing = TRUE
    166         }  
    167         if( $editing && ($_POST['id'] || $_POST['start'] || $_POST['desc']) ) { 
     165        $editing = can_edit( $node ); 
     166        $mode = mode($arg_name)
     167 
     168        if( $mode=="add" && $editing ) { 
    168169                try { 
    169170                        insert_clip( $_POST, $node );    
     
    171172                        drupal_set_message( $e->getMessage(), 'error' ); 
    172173                } 
    173         } 
    174  
    175         $arg_name = "media"; 
    176  
    177         /* Check if we should output raw annodex, cmml etc or display 
    178          * information about the video. 
    179          */       
    180         if(isset($_GET[$arg_name])) { 
    181                 $mode = $_GET[$arg_name]; 
    182                 switch ($mode) { 
    183                         case "cmml": 
    184                                 output_cmml($node); 
    185                                 die; 
    186                                 break; 
    187                         case "annodex": 
    188                                 /* We need to call output() rather than  
    189                                  * output_annodex() because of apps like the 
    190                                  * firefox extension that want both of them on 
    191                                  * the one link. 
    192                                  */ 
    193                                 output($node); 
    194                                 die; 
    195                                 break; 
    196                         case "theora": 
    197                                 output_ogg($node); 
    198                                 die; 
    199                                 break; 
    200                         default: 
    201                                 output($node); 
    202                                 die; 
    203                                 break; 
    204                 } 
    205         } else { 
    206                  
    207                 $output .= headers($node, $arg_name); 
    208                 $output .= "<br>"; 
    209                 $output .= "<br>"; 
    210                 if( !$_GET['clip'] ) { 
    211                         $output .= clip_table( $node, $arg_name, $_GET['clip'] ); 
    212                 } else if( $editing ) { 
    213                         switch( $_GET['clip'] ) { 
    214                                 case "new": 
    215                                         break; 
    216                                 default: 
    217                                         break; 
    218                         } 
    219                 } else { 
    220                         drupal_set_message("You do not have permission to edit clips", "error"); 
    221                 } 
     174                $mode = "view"; 
     175        } 
     176 
     177        switch( $mode ) { 
     178                case "edit": 
     179                        $output .= view_header($node, $arg_name); 
     180                        $result = db_query("SELECT * FROM {acidfree_cmml_clips} WHERE `nid`={$node->nid} AND `id`=\"{$_GET['clip']}\""); 
     181                        $row = db_fetch_array( $result ); 
     182                        $output .= clip_table($node, $arg_name, $row['id']); 
     183                        $output .= "<br><br>"; 
     184                        $output .= clip_update_form( $node, $row, "Update clip" ); 
     185                        $output .= view_footer($node, $arg_name); 
     186                        $output .= $node->body; 
    222187                         
    223                 $output .= "<br>"; 
    224  
    225                 /* Add new clip form */ 
    226                 if( $editing && !$_GET['clip'] ) { 
     188                        break; 
     189 
     190                case "view": 
     191                        $output .= view_header($node, $arg_name); 
     192                        $output .= clip_table($node, $arg_name); 
     193                        $output .= "<br><br>"; 
    227194                        $output .= clip_update_form( $node, null, "Add new clip" ); 
    228                 } else if( $editing ) { 
    229                         $output .= clip_table( $node, $arg_name, $_GET['clip'] ); 
    230                         $output .= "<br>"; 
    231                         $result = db_query("SELECT * FROM {acidfree_cmml_clips} WHERE nid={$node->nid} AND `id`=\"{$_GET['clip']}\""); 
    232                         $row = db_fetch_array( $result ); 
    233                         $output .= clip_update_form( $node, $row, "Update clip");  
    234                 } 
    235  
    236                 $output .= footer($node,$arg_name); 
    237                 $output .= $node->body; 
    238         } 
    239  
     195                        $output .= view_footer($node, $arg_name); 
     196                        $output .= $node->body; 
     197 
     198                        break; 
     199 
     200                case "media": 
     201                        $media = select_media( $arg_name ); 
     202                        output_media( $media, $node ); 
     203                        break; 
     204        } 
    240205 
    241206        return $output; 
     
    388353 
    389354        $header = array(); 
     355echo "file is "._acidfree_get_large_path($node)."<br>"; 
    390356        $header[] = array( 'data'=>'Title'); 
    391357        $header[] = array( 'data'=>'Duration'); 
     
    461427        return $output; 
    462428} 
     429 
     430function select_media( $arg_name ) { 
     431 
     432        if( isset($_GET[$arg_name])) { 
     433                return $_GET[$arg_name]; 
     434        } else { 
     435                return false; 
     436        } 
     437} 
     438 
     439function output_media( $media, $node ) { 
     440        switch ($media) { 
     441                case "cmml": 
     442                        output_cmml($node); 
     443                        die; 
     444                        break; 
     445                case "annodex": 
     446                        /* We need to call output() rather than  
     447                         * output_annodex() because of apps like the 
     448                         * firefox extension that want both of them on 
     449                         * the one link. 
     450                         */ 
     451                        output($node); 
     452                        die; 
     453                        break; 
     454                case "theora": 
     455                        output_ogg($node); 
     456                        die; 
     457                        break; 
     458                default: 
     459                        output($node); 
     460                        die; 
     461                        break; 
     462        } 
     463} 
     464 
     465function mode( $arg_name ) { 
     466 
     467        if( $_POST['id'] || $_POST['desc'] || $_POST['start_seconds'] 
     468                || $_POST['start_minutes'] || $_POST['start_hours'] ) 
     469                return "add"; 
     470 
     471        if( $_GET['clip'] ) { 
     472                return "edit"; 
     473        } 
     474 
     475        if( select_media( $arg_name ) ) { 
     476                return "media"; 
     477        } 
     478 
     479        return "view"; 
     480} 
     481 
     482function can_edit( $node ) { 
     483 
     484        if (acidfree_access('update',$node)) { 
     485                return TRUE; 
     486        } else { 
     487                return FALSE; 
     488        } 
     489} 
     490 
     491function view_header($node, $arg_name) { 
     492                                return headers($node, $arg_name); 
     493} 
     494 
     495function view_footer($node, $arg_name) { 
     496                                return footer($node, $arg_name); 
     497} 
     498