#! /usr/bin/perl # ######################################## # # script to edit DTN site content # written by benjamin ramey # bsr@rameydesign.net # january, 2004 # ######################################## if( $ENV{ 'REQUEST_METHOD' } eq 'POST' ) { read( STDIN, $buffer, $ENV{ 'CONTENT_LENGTH' } ); @pairs = split( /&/, $buffer ); #split form contents into name=value pairs foreach $pair ( @pairs ) #step through the array @pairs { ( $name, $value ) = split( /=/, $pair); #split each pair into the form element name and that form element's value $name =~ tr/+/ /; #replace all the + signs with spaces $value =~ tr/+/ /; $name =~ s/%(..)/pack( "C", hex( $1 ) )/eg; #replace all hexidecimal characters with their corresponding, easier to understand characters $value =~ s/%(..)/pack( "C", hex( $1 ) )/eg; if( $contents{ $name } ) #in case there is a multiple-select scroll down menu this will append a value to an already existing key instead of reassigning it { $contents{ $name } .= "\t$value"; } else{ $contents{ $name } = $value; } #but, normally, we'll just assign the value in the hash to it's corresponding key } } ##################################################################################################################################################################### # MAIN PROGRAM ##################################################################################################################################################################### if( $contents{ 'file' } ) { $file_path = $contents{ 'file' }; } else { $file_path = "nothing yet"; } $username = "warren4"; $password = "john316"; print "Content-type: text/html\n\n"; &Print_Top_HTML; #always need to display at least this &Password; &Print_Bottom_HTML; #and we always need to display this exit; ############## ############## DISPLAYS PASSWORD PAGES, SO ONLY WARREN CAN ACCESS EDITING SECTIONS ############## sub Password { if( !$contents{ 'username' } && !$contents{ 'file' } ) { print<<"HTML";
  Edit DTN      
  Please enter the following information before you start editing DtN.

Username:
Password:
HTML } elsif( $contents{ 'username' } && !$contents{ 'file' } ) { if( ($contents{ 'username' } eq $username) && ($contents{ 'password' } eq $password) ) { &Display_Edit_Choice; #if the username and password are correct, go on to display the editing choice } else { print<<"HTML";
  Edit DTN      
  ERROR: Either your username or password was not entered correctly. Please make sure you typed them in correctly. Both username and password are case sensitive!!
HTML } } else { if( $file_path ne 'nothing yet' ) #if file_path exists, a page to edit has been chosen and the contents of the page can be collected and displayed { if( $file_path eq 'media' ) { &Media_Edit; } elsif( $file_path eq 'travel' ) { &Travel_Edit; } elsif( $file_path eq 'randomverse' ) { &Random_Verses; } else { print<<"HTML";
  Edit DTN      
  ERROR: This section not yet editable.
HTML } } else { &Display_Edit_Choice; } #if there is not file_path a file to edit needs to be chosen, so display the choice page } } ############## ############## DISPLAYS THE PAGE WHERE YOU CHOOSE WHAT PAGE TO EDIT ############## sub Display_Edit_Choice { print <<"HTML";
  Edit DTN      
 
Please select which page to edit:

 
Currently editing: $file_path

To update the links list on the "Resources" page, click below.
HTML } ##################################################################################################################################################################### # SUB ROUTINES FOR EDITING THE MEDIA PAGE ##################################################################################################################################################################### ############## ############## MAIN BRAIN OF MEDIA EDITING SECTIONS ############## sub Media_Edit { &Display_Edit_Choice; print <<"HTML";
  Edit Media Page  
  HTML if( !$contents{ 'media_edit_action' } ) { print <<"HTML"; Choose what you would like to do:
Delete a photo album from media page
Add a photo album to media page
Edit an existing photo album on media page
Delete a video from media page
Add a video to media page
Edit an existing video on media page
 

HTML } elsif( $contents{ 'media_edit_action' } eq 'delete_album' ) { &Media_Edit_Delete_Album; } elsif( $contents{ 'media_edit_action' } eq 'add_album' ) { &Media_Edit_Add_Album; } elsif( $contents{ 'media_edit_action' } eq 'edit_album' ) { &Media_Edit_Edit_Album; } elsif( $contents{ 'media_edit_action' } eq 'delete_video' ) { &Media_Edit_Delete_Video; } elsif( $contents{ 'media_edit_action' } eq 'add_video' ) { &Media_Edit_Add_Video; } elsif( $contents{ 'media_edit_action' } eq 'edit_video' ) { &Media_Edit_Edit_Video; } print <<"HTML";
HTML } ############## ############## DEALS WITH DELETING A PHOTO ALBUM ############## sub Media_Edit_Delete_Album { my $data_file = "./data/media_data.txt"; ###########################gather info for album deletion if( !$contents{ 'which_album' } ) #if the user has not chosen an album to delete yet, then gather all the albums and print appropriate { #HTML for him to choose one--perl is pretty straight forward here my $in_albums = 0; print "Choose which album you would like to delete:
\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; } ###########################process deletion of album elsif( $contents{ 'which_album' } ) { my $in_albums = 0; my $file_name = 0; require Tie::File; tie( @file_lines, 'Tie::File', $data_file ) or print "ERROR: Could not open $data_file file."; for( my $i = 0; $i <= $#file_lines; $i++ ) { if( $file_lines[ $i ] =~ m// ) { $in_albums = 1; } #just to make sure, if there is another data type (like a video) with the same name if( $file_lines[ $i ] =~ m/<\/albumsection>/ ) { $in_albums = 0; } #it doesn't get deleted too if( ($file_lines[ $i ] =~ m/$contents{ 'which_album' }<\/name>/) && $in_albums ) { $file_name = $file_lines[ $i + 1 ]; splice( @file_lines, ($i - 1), 6 ); } } untie( @file_lines ); $file_name =~ s/.*album_(.*)<\/link>.*/$1/; #delete the related files when deleting an album my @files = ( "./photo_albums/album_$file_name", "./photo_albums/images_$file_name", "./photo_albums/index_$file_name" ); unlink( @files ) or print $!; print<<"HTML"; Album $contents{ 'which_album' } deleted! Click here to view the Photos/Videos page to make sure everything went according to plan.

Remember that, if you just deleted a nested album, you need to delete the link to the deleted album from the album it was nested in.

To continue editing, please select a page to edit at the top of this page. HTML } } ############## ############## DEALS WITH ADDING A PHOTO ALBUM ############## sub Media_Edit_Add_Album { my $data_file = "./data/media_data.txt"; my $in_albums = 0; my $k = 0; open( INFILE, "$data_file" ) or print "ERROR: Could not open $data_file."; while( my $file_line = ) { if( $file_line =~ m// ) { $in_albums = 1; } if( $file_line =~ m/<\/albumsection>/ ) { $in_albums = 0; } if( ($file_line =~ m/(.*)<\/name>/) && $in_albums ) { $albums[ $k ] = $1; } if( ($file_line =~ m/(.*)<\/link>/) && $in_albums ) #these arrays are used later to add and nest the added album { $links[ $k ] = $1; $k++; } } close( INFILE ); ###########################gather info for new album if( !$contents{ 'new_album_name' } ) { print<<"HTML"; Instructions:
  • Album name: name that will appear on page under link to album
  • Place after album: this will determine where the album will appear on the page, ie in what order.
  • Albums folder: you must have uploaded the folder containing all the full-sized images, smaller images, and thumbnails. The smaller image names MUST begin with "small_"; the thumbnail images MUST begin with "thumb_". This folder must already be present on the server (ie, you've uploaded it already) before you try to make a new album. The photos MUST be labelled exactly or this script will not construct the album pages correctly!!

    Guidelines for photos:
    thumbnails: largest dimension 100 pixels small images: largest dimension 400 pixels large (normal) images: largest dimension 800 pixels

    For the photo album pages to look good you HAVE to keep these guidelines.
  • Album inside another: if you don't want this to be a main album (ie, it won't appear on the Photos/Videos page) then choose which main album it will be nestled in. You can also nestle new albums in already nestled albums.

Note: An album folder must be inside the folder "/graphics/media/albums/".

Please enter the following information:
Album Name:


Place album after:

(To put at end of list choose the last album in list. To put album at beginning of list choose \"Make first album\".)

\n"; print "Select the album folder:

(Note: you have to have uploaded the folder containing all photos already)

\n"; print "If this album will be inside another album, choose which it is to be inside:
\n"; print "
(If this is album will not be inside another, select the \"Not inside another\" option)
\n"; print<<"HTML";
HTML } ###########################processes for adding new album elsif( $contents{ 'new_album_name' } ) { require Tie::File; my $inside_file = $links[ $contents{ 'inside_album' } ]; #if the album is nested inside another, the info will display which index_ file it is link to from if( $contents{ 'inside_album' } eq 'none' ) { $inside_file = "none"; } #if the album is not nested in another, the info should read "none" my $new_album = "album_$contents{ 'album_folder' }.htm"; #create all three files from the name of the image folder my $new_index = "index_$contents{ 'album_folder' }.htm"; my $new_images = "images_$contents{ 'album_folder' }.htm"; my $new_folder = $contents{ 'album_folder' }; $new_folder =~ s/([ ,',",\\,\/,-])/sprintf( "%%%lx", (unpack( "C", $1 )) )/eg; my @new_album = ( "\t\t\n", #construct the new album lines which will be added to the data_file "\t\t\t$contents{ 'new_album_name' }\n", "\t\t\t$new_album\n", "\t\t\t$inside_file\n", "\t\t\t$contents{ 'album_folder' }\n", "\t\t\n" ); tie( my @file_lines, 'Tie::File', "$data_file" ) or print "ERROR: Could not open $data_file."; for( my $i = 0; $i <= $#file_lines; $i++ ) { if( ($contents{ 'first_album' } eq 'make_first') && ($contents{ 'inside_album' } eq 'none') ) #if it is to be first on the media page, slip it in at the top fo the data_file { if( $file_lines[ $i ] =~ m// ) { splice( @file_lines, $i, 1, ( "\t\n", @new_album ) ); $i = $#file_lines; } } elsif( $contents{ 'inside_album' } ne 'none' ) #if it is a nested album, we'll put it at the bottom of the list (since order doesn't matter for these, they won't be listed on the media page { if( $file_lines[ $i ] =~ m/<\/albumsection>/ ) { splice( @file_lines, $i, 1, ( @new_album, "\t<\/albumsection>\n" ) ); $i = $#file_lines; } } else #if it's not the first album, look for the album it will come after and place it after that album { if( $file_lines[ $i ] =~ m/$contents{ 'first_album' }<\/name>/ ) { splice( @file_lines, ($i + 4), 1, ( "\t\t\n", @new_album ) ); $i = $#file_lines; } } } untie( @file_lines ); if( $contents{ 'inside_album' } ne 'none' ) { my $inside_index_file = $inside_file; $inside_index_file =~ s/album_/index_/; #add link to nested album from parent album tie( my @parent_file_lines, 'Tie::File', "./photo_albums/$inside_index_file" ) or print "can't open file"; for( my $w = 0; $w <= $#parent_file_lines; $w++ ) { if( $parent_file_lines[ $w ] =~ m// ) { splice( @parent_file_lines, $w, 1, ( "\n", "\t\n", "\t\t
\n", "\t\t$contents{ 'new_album_name' }\n", "\t\t

\n" ) ); $w = $#parent_file_lines; #business done, jump out of loop } } untie( @parents_file_lines ); } ###########################creation of the three files needed for each album: the frameset file, index file, image file opendir( ALBUM_DIR, "./graphics/media/albums/$contents{ 'album_folder' }/" ) or print "ERROR: Could not open new album directory."; my @album_images = grep { not m/^\.\.?\z/ } readdir ALBUM_DIR; #won't read the . and .. directories @album_images = grep { not m/^small_/ } @album_images; @album_images = grep { not m/^thumb_/ } @album_images; for( my $q = 0; $q <= $#album_images; $q++ ) { $album_images[ $q ] =~ s/([ ,',",\\,\/,-])/sprintf( "%%%lx", (unpack( "C", $1 )) )/eg; } closedir( ALBUM_DIR ); #gather all the images, change any offensive characters to readable ones, so they don't interfere with quotation marks and what-not ###########################creates frameset (album_) file open( NEW_ALBUM, ">./photo_albums/$new_album" ) or print "ERROR: Could not create $new_album."; print NEW_ALBUM <<"HTML"; Photo Album: $contents{ 'new_album_name' } <body> </body> HTML close( NEW_ALBUM ); ###########################creates images file open( NEW_IMAGES, ">./photo_albums/$new_images" ) or print "ERROR: Could not create $new_images."; print NEW_IMAGES <<"HTML"; Photo Album: $contents{ 'new_album_name' }


Click here for larger image
HTML close( NEW_IMAGES ); ###########################creates index file open( NEW_INDEX, ">./photo_albums/$new_index" ) or print "ERROR: Could not create $new_index."; print NEW_INDEX <<"HTML"; Photo Album: $contents{ 'new_album_name' } HTML if( $contents{ 'inside_album' } ne 'none' ) #if this is a nested album, make sure a link to the parent album is put in at the top of the left frame { print NEW_INDEX <<"HTML";

HTML } print NEW_INDEX "
\n"; print NEW_INDEX "\n"; print NEW_INDEX "\n"; my $j = 0; foreach ( @album_images ) #make sure the same link is put in for the thumbnail that's shown by counting through with $j { print NEW_INDEX "\t\t\t\n"; print NEW_INDEX "\t\t\t\t
\n"; $j++; } print NEW_INDEX "\n
\n\n"; close( NEW_INDEX ); print<<"HTML"; Album added! Click here to view the Photos/Videos page to make sure everything went according to plan.

To continue editing, please select a page to edit at the top of this page. HTML } } ############## ############## DEALS WITH EDITING A PHOTO ALBUM ############## sub Media_Edit_Edit_Album { my $data_file = "./data/media_data.txt"; ###########################gather info for album editing if( !$contents{ 'which_album' } ) #if the user has not chosen an album to edit yet, then gather all the albums and print appropriate { #HTML for him to choose one--perl is pretty straight forward here my $in_albums = 0; print "Choose which album you would like to edit:
\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; } ###########################display editing information elsif( $contents{ 'which_album' } && !$contents{ 'new_album_name' } ) { my $album_name = $contents{ 'which_album' }; my $album_link = 0; my $album_inside = 0; my $album_folder = 0; my $album_index = 0; my $album_images = 0; ############get album file name to access correct index and image .htm files open( INFILE, "$data_file" ) or print "ERROR: Could not open $data_file."; while( my $file_line = ) { if( $file_line =~ m// ) { $in_albums = 1; } if( $file_line =~ m/<\/albumsection>/ ) { $in_albums = 0; } if( ($file_line =~ m/$album_name<\/name>/) && $in_albums ) { while( $file_line !~ m/<\/album>/ ) { $file_line = ; if( $file_line =~ m/(.*)<\/link>/ ) { $album_link = $1; $album_index = $album_link; $album_images = $album_link; $album_index =~ s/album_/index_/; $album_images =~ s/album_/images_/; } if( $file_line =~ m/(.*)<\/inside>/ ) { $album_inside = $1; } if( $file_line =~ m/(.*)<\/imagefolder>/ ) { $album_folder = $1; } } } } close( INFILE ); print "On the left, delete photos/nested albums from the album. On the right, edit which picture appears first when the album is opened and add images to the album.

\n"; print "Note: when deleting a nested album, you are only deleting the fact that it is nested in the album being edited. In other words, the actual nested album is not deleted.
\n"; print "
\n"; print "Change album name:

\n"; print "\n"; print "\n\n"; print "\n"; print "\n
\nTo delete an image (or album), check its corresponding checkbox.

\n"; ############open index file and display which images are in it open( INDEX_FILE, "./photo_albums/$album_index" ) or print "ERROR: Could not open index file."; while( my $file_line = ) { if( $file_line =~ m// ) { my $current_file = $1; $current_file =~ s/\.\.\//\.\//; if( $current_file =~ m/album_icon/ ) { my $current_album = ; chomp( $current_album ); $current_album =~ s/^\s*(.*)\s*$/$1/; print "
\n"; print "Album Name: $current_album

\n"; } else { print "
\n"; $current_file =~ s/.*\/thumb_(.*\.\w{3})$/$1/; $current_file =~ s/%(..)/pack( "C", hex( $1 ) )/eg; print "Image Name:
$current_file

\n"; } } } close( INDEX_FILE ); print "
\nTo change the first image, choose which to change it too from the drop-down menu.

\n"; ############open image file and display the main image there and menu to change that image open( IMAGE_FILE, "./photo_albums/$album_images" ) or print "ERROR: Could not open images file."; while( my $file_line = ) { if( $file_line =~ m// ) { my $main_image = $1; $main_image =~ s/\.\.\//\.\//; print "Current main image:
\n"; } } close( IMAGE_FILE ); opendir( IMAGE_FOLDER, "./graphics/media/albums/$album_folder" ) or print "ERROR: Could not open images folder. Because $!"; my @image_files = grep { not m/^\.\.?\z/ } readdir IMAGE_FOLDER or print "can't readdir"; @image_files = grep { m/\.\w{3}\z/ } @image_files; @image_files = grep { not m/(thumb_)|(small_)/ } @image_files; print "

Select new main image:


\n"; print "
Select which images to add:
Note: hold down the ctrl key to select multiple images
Note: You have to have already uploaded any new images.
\n"; print "\n"; closedir( IMAGE_FOLDER ); print "


\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; } ###########################applies edited information for editing albums elsif( $contents{ 'which_album' } && $contents{ 'new_album_name' } ) { require Tie::File; my $album_index = $contents{ 'album_link' }; my $album_images = $contents{ 'album_link' }; my $file_friendly_folder = $contents{ 'album_folder' }; $file_friendly_folder =~ s/([ ,',",\\,\/,\-])/sprintf( "%%%lx", (unpack( "C", $1 )) )/eg; $album_index =~ s/album_/index_/; $album_images =~ s/album_/images_/; my @edited_album = ( "\t\t\t$contents{ 'new_album_name' }\n" ); tie( my @file_lines, 'Tie::File', "$data_file" ) or print "ERROR: Could not open $data_file."; for( my $i = 0; $i <= $#file_lines; $i++ ) { if( $file_lines[ $i ] =~ m/$contents{ 'old_name' }<\/name>/ ) { splice( @file_lines, $i, 1, @edited_album ); } } untie( @file_lines ); my @new_images = split( /\t/, $contents{ 'additional_images' } ); my @deleted_images = split( /\t/, $contents{ 'delete_thumb' } ); my @deleted_albums = split( /\t/, $contents{ 'delete_album' } ); tie( my @file_lines, 'Tie::File', "./photo_albums/$album_index" ) or print "ERROR: Could not open $new_index_file."; for( my $i = 0; $i <= $#file_lines; $i++ ) { $file_lines[ $i ] =~ s/.*<\/title>/<title>$contents{ 'new_album_name' } Album<\/title>/; if( $file_lines[ $i ] =~ m/<!--IMAGES-->/ ) { $images_line_no = $i; } for( my $k = 0; $k <= $#deleted_albums; $k++ ) { if( $file_lines[ $i ] =~ m/$deleted_albums[ $k ]/ ) { splice( @file_lines, ($i - 2), 4 ); } } for( my $c = 0; $c <= $#deleted_images; $c++ ) { if( $file_lines[ $i ] =~ m/$deleted_images[ $c ]/ ) { splice( @file_lines, ($i - 1), 3 ); } } } if( $contents{ 'additional_images' } ne 'none' ) { my @new_images_lines; for( my $v = 0; $v <= $#new_images; $v++ ) { push( @new_images_lines, ( "\t<a href=\"javascript:void(0)\"\n", "\t\tonclick=\"top.mainFrame.main_image.src='../graphics/media/albums/$file_friendly_folder/small_$new_images[ $v ]'\">\n", "\t\t<img src=\"../graphics/media/albums/$file_friendly_folder/thumb_$new_images[ $v ]\" border=\"0\"></a><br>\n" ) ); } splice( @file_lines, $images_line_no, 1, ( "<!--IMAGES-->", @new_images_lines ) ); } untie( @file_lines ); tie( my @file_lines, 'Tie::File', "./photo_albums/$album_images" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $new_images_file.</span>"; for( my $x = 0; $x <= $#file_lines; $x++ ) { $file_lines[ $x ] =~ s/<title>.*<\/title>/<title>$contents{ 'new_album_name' } Album<\/title>/; if( $contents{ 'new_main_image' } ne 'same' ) { if( $file_lines[ $x ] =~ m/<img src=".*" name="main_image"(.*)>/ ) { $file_lines[ $x ] = "<img src=\"../graphics/media/albums/$file_friendly_folder/$contents{ 'new_main_image' }\" name=\"main_image\"$1>"; } } } untie( @file_lines ); print<<"HTML"; <b>Editing done! Click <a href='media.pl'>here</a> to view the Photos/Videos page to make sure everything went according to plan.</b><br /><br /> To continue editing, please select a page to edit at the top of this page. HTML } } ############## ############## DEALS WITH DELETING A VIDEO ############## sub Media_Edit_Delete_Video { my $data_file = "./data/media_data.txt"; ###########################gather info for which video to delete if( !$contents{ 'which_video' } ) #if the user has not chosen an album to delete yet, then gather all the albums and print appropriate { #HTML for him to choose one--perl is pretty straight forward here my $in_videos = 0; print "<b>Choose which video you would like to delete:</b><br />\n"; print "<form action=\"./dtn.cgi\" method=\"post\">\n"; print "<select name=\"which_video\">\n"; open( INFILE, "$data_file" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $data_file.</span>"; while( my $file_line = <INFILE> ) { if( $file_line =~ m/<videosection>/ ) { $in_videos = 1; } if( $file_line =~ m/<\/videosection>/ ) { $in_videos = 0; } if( ($file_line =~ m/<name>(.*)<\/name>/) && $in_videos ) { print "<option value=\"$1\">$1</option>\n"; } } close( INFILE ); print "</select>\n"; print "<input type=\"hidden\" value=\"delete_video\" name=\"media_edit_action\" />\n"; print "<input type=\"hidden\" value=\"media\" name=\"file\" />\n"; print "<input type=\"submit\" value=\"Delete Video\" name=\"submit_btn\" />\n"; print "</form>\n"; } ###########################process video deletion elsif( $contents{ 'which_video' } ) { my $in_videos = 0; my $file_name = 0; require Tie::File; tie( @file_lines, 'Tie::File', $data_file ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $data_file file.</span>"; for( my $i = 0; $i <= $#file_lines; $i++ ) { if( $file_lines[ $i ] =~ m/<videosection>/ ) { $in_videos = 1; } #just to make sure, if there is another data type (like a video) with the same name if( $file_lines[ $i ] =~ m/<\/videosection>/ ) { $in_videos = 0; } #it doesn't get deleted too if( ($file_lines[ $i ] =~ m/<name>$contents{ 'which_video' }<\/name>/) && $in_videos ) { $file_name = $file_lines[ $i + 1 ]; splice( @file_lines, ($i - 1), 6 ); } } untie( @file_lines ); $file_name =~ s/.*<link>(.*)<\/link>.*/$1/; unlink "./video_pages/$file_name"; print<<"HTML"; <b>Video $contents{ 'which_video' } deleted! Click <a href='media.pl'>here</a> to view the Photos/Videos page to make sure everything went according to plan.</b><br /><br /> To continue editing, please select a page to edit at the top of this page. HTML } } ############## ############## DEALS WITH ADDING A VIDEO ############## sub Media_Edit_Add_Video { my $data_file = "./data/media_data.txt"; my $in_videos = 0; my $k = 0; open( INFILE, "$data_file" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $data_file.</span>"; while( my $file_line = <INFILE> ) { if( $file_line =~ m/<videosection>/ ) { $in_videos = 1; } if( $file_line =~ m/<\/videosection>/ ) { $in_videos = 0; } if( ($file_line =~ m/<name>(.*)<\/name>/) && $in_videos ) { $names[ $k ] = $1; } if( ($file_line =~ m/<link>(.*)<\/link>/) && $in_videos ) { $links[ $k ] = $1; } if( ($file_line =~ m/<image>(.*)<\/image>/) && $in_videos ) { $images[ $k ] = $1; $k++; } } close( INFILE ); ###########################gather info for new video if( !$contents{ 'new_video_name' } ) { print<<"HTML"; <b>Instructions:</b><br /> <ul> <li>Video name: name that will appear on page under link to the video</li> <li>Place after video: this will determine where the video will appear on the page, ie in what order.</li> <li>Video file: this is the actual video. It MUST be uploaded to the folder "/graphics/media/video_clips/"</li> <li>Thumbnail image: this is the image that appears on the Photos/Videos page representing the movie. It MUST be uploaded to the folder "/graphics/media/video_thumbs/". Suggested size: largest dimension no larger than 100 pixels. </li> </ul><br /> <br /> <b>Please enter the following information:</b><br /> <form action="./dtn.cgi" method="post"> <b>Video Name:</b><br /><input type="text" name="new_video_name" size="40" /><br /> <br /> <b>Place video after:</b><br /> <select name="first_video"> <option value="make_first">Make first video</option> HTML foreach my $name ( @names ) { print "<option value=\"$name\">$name</option>\n"; } print "</select><br />(To put at end of list choose the last video in list. To put video at beginning of list choose \"Make first video\".)<br /> <br />\n"; print "<b>Select which video file:</b><br /><select name=\"video_file\">\n"; opendir( MEDIA_DIR, "./graphics/media/video_clips/" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open video_clips directory.</span>"; my @media_files = grep { not m/^\.\.?\z/ } readdir MEDIA_DIR; #won't read the . and .. directories closedir( MEDIA_DIR ); foreach my $media_file ( @media_files ) { unless( $media_file eq 'WS_FTP.LOG' ) { print "<option value=\"$media_file\">$media_file</option>\n"; } } print "</select><br />(Note: you have to have uploaded the video already)<br /> <br />\n"; print "<b>Select which thumbnail image:</b><br /><select name=\"video_thumb\">\n"; opendir( MEDIA_DIR, "./graphics/media/video_thumbs/" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open video_thumbs directory.</span>"; my @media_files = grep { not m/^\.\.?\z/ } readdir MEDIA_DIR; #won't read the . and .. directories closedir( MEDIA_DIR ); foreach my $media_file ( @media_files ) { unless( $media_file eq 'WS_FTP.LOG' ) { print "<option value=\"$media_file\">$media_file</option>\n"; } } print "</select><br />(Note: you have to have uploaded the video thumbnail already)<br /> <br />\n"; print<<"HTML"; <br /> <input type="hidden" value="add_video" name="media_edit_action" /> <input type="hidden" value="media" name="file" /> <input type="submit" value="Add Video" name="submit_btn" /> </form> HTML } ###########################process info for new video elsif( $contents{ 'new_video_name' } ) { require Tie::File; tie( @file_lines, 'Tie::File', "$data_file" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $data_file.</span>"; $contents{ 'video_file' } =~ s/(\.\w{3})//; my $extension = $1; my @new_video = ( "\t\t<video>\n", "\t\t\t<name>$contents{ 'new_video_name' }</name>\n", "\t\t\t<file>$contents{ 'video_file' }$extension</file>\n", "\t\t\t<link>video_$contents{ 'video_file' }.htm</link>\n", "\t\t\t<image>graphics/media/video_thumbs/$contents{ 'video_thumb' }</image>\n", "\t\t</video>\n" ); for( my $i = 0; $i <= $#file_lines; $i++ ) { if( $contents{ 'first_video' } eq 'make_first' ) { if( $file_lines[ $i ] =~ m/<videosection>/ ) { splice( @file_lines, $i, 1, ( "\t<videosection>\n", @new_video ) ); } } else { if( $file_lines[ $i ] =~ m/<name>$contents{ 'first_video' }<\/name>/ ) { splice( @file_lines, ($i + 3), 1, ( "\t\t</video>\n", @new_video ) ); } } } untie( @file_lines ); open( VIDEO_FILE, ">./video_pages/video_$contents{ 'video_file' }.htm" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not create new video file.</span>"; print VIDEO_FILE <<"HTML"; <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Video: $contents{ 'new_video_name' }
HTML close( VIDEO_FILE ); print<<"HTML"; Video $contents{ 'new_video_name' } added! Click here to view the Photos/Videos page to make sure everything went according to plan.

To continue editing, please select a page to edit at the top of this page. HTML } } ############## ############## DEALS WITH EDITING A VIDEO ############## sub Media_Edit_Edit_Video { my $data_file = "./data/media_data.txt"; my $in_videos = 0; my $k = 0; open( INFILE, "$data_file" ) or print "ERROR: Could not open $data_file."; while( my $file_line = ) { if( $file_line =~ m// ) { $in_videos = 1; } if( $file_line =~ m/<\/videosection>/ ) { $in_videos = 0; } if( ($file_line =~ m/(.*)<\/name>/) && $in_videos ) { $names[ $k ] = $1; } if( ($file_line =~ m/(.*)<\/file>/) && $in_videos ) { $videos[ $k ] = $1; } if( ($file_line =~ m/(.*)<\/link>/) && $in_videos ) { $links[ $k ] = $1; } if( ($file_line =~ m/(.*)<\/image>/) && $in_videos ) { $images[ $k ] = $1; $k++; } } close( INFILE ); if( !$contents{ 'which_video_edit' } && !$contents{ 'new_video_name' } ) { print<<"HTML";
Please choose which video to edit:

\n"; print "\n"; print "\n"; print "\n"; print "
\n"; } elsif( $contents{ 'which_video_edit' } && !$contents{ 'make_edit' } ) { my $current_name = $contents{ 'which_video_edit' }; my $current_after = 0; my $current_video = 0; my $current_link = 0; my $current_image = 0; for( my $k = 0; $k <= $#names; $k++ ) { if( $names[ $k ] eq $current_name ) { if( $k == 0 ) { $current_after = "Make first video"; } else{ $current_after = $names[ $k - 1 ]; } $current_video = $videos[ $k ]; $current_link = $links[ $k ]; $current_image = $images[ $k ]; $current_image =~ s/graphics\/media\/video_thumbs\///; $k = $#names; #break out of loop when all our variables have been found } } print<<"HTML"; Instructions:
Same as for adding a new video. What you currently have for each section is displayed after each field

Please enter the following information:
Video Name:


Place video after: (current selection: $current_after)

(To put at end of list choose the last video in list. To put video at beginning of list choose \"Make first video\".)

\n"; print "Select which video file: (current selection: $current_video)

(Note: you have to have uploaded the video already)

\n"; print "Select which thumbnail image: (current selection: $current_image)

(Note: you have to have uploaded the video thumbnail already)

\n"; print<<"HTML";
HTML } elsif( $contents{ 'new_video_name' } ) { my $in_videos = 0; my $deleted = 0; require Tie::File; tie( @file_lines, 'Tie::File', "$data_file" ) or print "ERROR: Could not open $data_file."; $contents{ 'video_file' } =~ s/(\.\w{3})//; my $extension = $1; my @new_video = ( "\t\t\n" ); for( my $i = 0; $i <= $#file_lines; $i++ ) { if( $file_lines[ $i ] =~ m// ) { $in_videos = 1; } #just to make sure, if there is another data type (like a video) with the same name if( $file_lines[ $i ] =~ m/<\/videosection>/ ) { $in_videos = 0; } #it doesn't get deleted too if( ($file_lines[ $i ] =~ m/$contents{ 'old_name' }<\/name>/) && $in_videos && !$deleted ) { splice( @file_lines, ($i - 1), 6 ); $deleted = 1; } if( $contents{ 'first_video' } eq 'make_first' ) { if( $file_lines[ $i ] =~ m// ) { splice( @file_lines, $i, 1, ( "\t\n", @new_video ) ); $i += 4; } } elsif( $in_videos ) { if( $file_lines[ $i ] =~ m/$contents{ 'first_video' }<\/name>/ ) { splice( @file_lines, ($i + 4), 1, ( "\t\t\n", @new_video ) ); $i += 7; } } } untie( @file_lines ); unlink "./video_pages/$contents{ 'old_link' }"; open( VIDEO_FILE, ">./video_pages/video_$contents{ 'video_file' }.htm" ) or print "ERROR: Could not create new video file."; print VIDEO_FILE <<"HTML"; Video: $contents{ 'new_video_name' }
HTML close( VIDEO_FILE ); print<<"HTML"; Video $contents{ 'new_video_name' } edited! Click here to view the Photos/Videos page to make sure everything went according to plan.

To continue editing, please select a page to edit at the top of this page. HTML } } ##################################################################################################################################################################### # SUB ROUTINES FOR EDITING THE TRAVEL PAGE ##################################################################################################################################################################### ############## ############## MAIN BRAIN OF TRAVEL PAGE EDITING ############## sub Travel_Edit { &Display_Edit_Choice; print <<"HTML";
  Edit Mission & Travel Page  
  HTML if( !$contents{ 'travel_edit_action' } ) { print <<"HTML"; Choose what you would like to do:
Add a Carter's Ministry Moments

 

HTML } elsif( $contents{ 'travel_edit_action' } eq 'cmm' ) { &Travel_Edit_Add_CMM; } print <<"HTML";
HTML } ############## ############## DEALS WITH ADDING A CARTER'S MINISTRY MOMENT ############## sub Travel_Edit_Add_CMM { my $data_file = "./data/travel_data.txt"; if( !$contents{ 'add_cmm' } ) { print <<"HTML"; Please fill out the following fields:
Date:

Content of CMM:

 

HTML } elsif( $contents{ 'add_cmm' } ) { require Tie::File; $contents{ 'cmm_content' } =~ s/\n/
/g; $contents{ 'cmm_content' } =~ m/(.{0,300})(\w*)\s/s; my $cmm_summary = $1 . $2 . "..."; my $file_friendly_date = $contents{ 'cmm_date' }; $file_friendly_date =~ s/([',",\\,\/,\-])/ /g; my $in_section = 0; my @new_cmm = ( "\t\t\n", "\t\t\t$contents{ 'cmm_date' }\n", "\t\t\t./ministry_moments/$file_friendly_date.htm\n", "\t\t\t$cmm_summary\n", "\t\t\n" ); tie( my @file_lines, 'Tie::File', $data_file ); for( my $i = 0; $i <= $#file_lines; $i++ ) { if( $file_lines[ $i ] =~ m// ) { splice( @file_lines, $i, 1, ( "\t\n", @new_cmm ) ); } } untie( @file_lines ); open( NEW_CMM, ">./ministry_moments/$file_friendly_date.htm" ); print NEW_CMM <<"HTML"; Disciple the Nations :: Carter's Ministry Moments
Carter's Ministry Moments from $contents{ 'cmm_date' }

$contents{ 'cmm_content' }

HTML close( NEW_CMM ); print<<"HTML"; Your new Carter's Ministry Moments has been added! Click here to view the Missions & Travel page to make sure everything went according to plan.

To continue editing, please select a page to edit at the top of this page. HTML } } ##################################################################################################################################################################### # SUB ROUTINES FOR EDITING THE RANDOM VERSES ##################################################################################################################################################################### sub Random_Verses { &Display_Edit_Choice; my $verse_file = "./random_verse.js"; my $in_verses = 0; print <<"HTML";
  Edit Random Verse List  
  HTML if( !$contents{ 'edit_verses' } ) { print<<"HTML"; Below all current verses in the list are listed. If you want to delete a verse, check it's corresponding checkbox. If you want to add a verse, fill in the appropriate information at the bottom of the list where it says "Add Verse".

HTML open( INFILE, $verse_file ); while( my $file_line = ) { if( $file_line =~ m/~VERSES~/ ) { $in_verses = 1; } if( $file_line =~ m/~ENDVERSES~/ ) { $in_verses = 0; } if( ($file_line =~ m/verses\[ (\d+) \] = "\\"(.*)\\"<\/i>(.*)"\;/) && $in_verses ) { my $verse_num = $1 + 1; print " Verse $verse_num: $2 $3
\n"; } } close( INFILE ); print "\n
\n"; print<<"HTML"; Add Verse:
Verse:
Reference:

HTML } elsif( $contents{ 'edit_verses' } ) { require Tie::File; my $in_verses = 0; my $verse_counter = 0; my $deleted = 0; tie( my @file_lines, 'Tie::File', $verse_file ) or print "can't open file"; for( my $i = 0; $i <= $#file_lines; $i++ ) { if( $file_lines[ $i ] =~ m/~VERSES~/ ) { $in_verses = 1; } if( $file_lines[ $i ] =~ m/~ENDVERSES~/ ) { $in_verses = 0; my $new_verse = "\t\tverses[ $verse_counter ] = \"\\\"$contents{ 'verse_text' }\\\" $contents{ 'verse_ref' }\"\;"; if( $contents{ 'verse_text' } ) { splice( @file_lines, $i, 1, ( $new_verse, "\t\t//~ENDVERSES~" ) ); } $i = $#file_lines; } if( ($file_lines[ $i ] =~ m/verses\[ $contents{ 'verses_delete' } \]/) && $in_verses && !$deleted ) { splice( @file_lines, $i, 1 ); $i--; $verse_counter--; $deleted = 1; } if( ($file_lines[ $i ] =~ s/verses\[ \d+ \]/verses\[ $verse_counter \]/) && $in_verses ) { $verse_counter++; } } untie( @file_lines ); if( $contents{ 'verses_delete' } ) { print<<"HTML"; Verse(s) deleted!
HTML } if( $contents{ 'verse_text' } ) { print<<"HTML"; $contents{ 'verse_ref' } has been added to the list!
HTML } } print <<"HTML";
HTML } ################################################################################################################################################ # SUB ROUTINES FOR PRINTING GENERIC HTML ################################################################################################################################################ ##############displays top of editing pages############## sub Print_Top_HTML { print <<"HTML"; Disciple the Nations - Edit DTN
  home | who we are | resources | prayer requests | travel info | photos/videos

HTML } ##############displays bottom of editing pages############## sub Print_Bottom_HTML { print <<"HTML";
   
all site content copyright of Disciple the Nations, all rights reserved | site designed by ramey design
HTML }