'news_posts',
'requests' => 'requests_posts',
'big_requests' => 'bigrequests_posts',
'great_stuff' => 'greatstuff_posts',
'austria_trip' => 'austriatrip_posts'
);
$comments_dbs = array( 'news' => 'news_comments',
'requests' => 'requests_comments',
'big_requests' => 'bigrequests_comments',
'great_stuff' => 'greatstuff_comments',
'austria_trip' => 'austriatrip_comments'
);
$_POST['author'] = addslashes($_POST['author']); //make this form data database safe
$_POST['authorweb'] = addslashes($_POST['authorweb']);
$_POST['content'] = addslashes($_POST['content']);
//insert this new comment into the news_comments table
mysql_query("INSERT INTO {$comments_dbs[$type]} (PostID,Date,Author,AuthorWeb,Content) VALUES ({$_GET['id']},UNIX_TIMESTAMP(NOW()),'{$_POST['author']}','{$_POST['authorweb']}','{$_POST['content']}');");
//this gets the current comment count for the news post, increments it, then updates the value in the news_posts table
$num_comments = mysql_query("SELECT NumComments FROM {$posts_dbs[$type]} WHERE ID = {$_GET['id']};");
$num_comments = mysql_fetch_assoc( $num_comments );
$num_comments['NumComments'] = $num_comments['NumComments'] + 1;
mysql_query("UPDATE {$posts_dbs[$type]} SET NumComments = {$num_comments['NumComments']} WHERE ID = {$_GET['id']};");
}
//this function adds an entry to the guestbook database
function AddGuestbookEntry()
{
$_POST['author'] = addslashes($_POST['author']); //make this form data database safe
$_POST['authorweb'] = addslashes($_POST['authorweb']);
$_POST['content'] = addslashes($_POST['content']);
//insert this new guestbook entry into the guestbook table
mysql_query("INSERT INTO guestbook (Date,Author,AuthorWeb,Content) VALUES (UNIX_TIMESTAMP(NOW()),'{$_POST['author']}','{$_POST['authorweb']}','{$_POST['content']}');");
}
//opens a connection to the database to be used by the rest of the script
function InitializeDB()
{
$db_host = 'mysql17.powweb.com';
$db_user = 'smramey';
$db_pass = '7274j3';
//open the connection to the ria database
$rlinks_db = mysql_connect($db_host, $db_user, $db_pass);
//make sure a db connection was made, if so, select the ria database
if( !$rlinks_db ) { die( 'Could not connect to database: ' . mysql_error() ); }
else { mysql_select_db('resourcelinks') or die( 'Could not select database: ' . mysql_error()); }
}
//gets the latest news posts and returns an html-ized version of them
function GetPosts($type,$page)
{
$posts_dbs = array( 'news' => 'news_posts',
'requests' => 'requests_posts',
'big_requests' => 'bigrequests_posts',
'great_stuff' => 'greatstuff_posts',
'austria_trip' => 'austriatrip_posts'
);
$files = array( 'news' => 'indextest.php',
'requests' => 'prayer_updates.php',
'big_requests' => 'prayer_updates.php',
'great_stuff' => 'great_stuff.php',
'austria_trip' => 'austria_trip.php'
);
$max_posts = 7;
$one_past_max = $max_posts + 1;
$num_posts = 1;
$start_post = $page ? ($page * $max_posts) : 0;
$q_posts = mysql_query("SELECT * FROM {$posts_dbs[$type]} ORDER BY ID DESC LIMIT $start_post,$one_past_max;");
while( $num_posts <= $max_posts and $post = mysql_fetch_assoc($q_posts) )
{
$title = stripslashes($post['Title']);
$author = stripslashes($post['Author']);
$content = stripslashes($post['Content']);
$date = date( "D, F d, Y \a\\t h:ia", $post['Date'] );
$num_comments = $post['NumComments'];
$id = $post['ID'];
$html .="
$title
by $author on $date
";
$num_posts++;
}
if( $start_post > 0 or ($start_post == 0 and $post = mysql_fetch_assoc($q_posts)) )
{
if($start_post > 0) { $post = mysql_fetch_assoc($q_posts); }
$html .= "
";
$newer_news = $page - 1;
$older_news = $page + 1;
if($start_post != 0)
{ $html .= "| next | "; }
if( $post )
{ $html .= "previous | "; }
$html .= "
";
}
return($html);
}
//gets the specified news post and display the comments
function GetSinglePost($type,$id)
{
$posts_dbs = array( 'news' => 'news_posts',
'requests' => 'requests_posts',
'big_requests' => 'bigrequests_posts',
'great_stuff' => 'greatstuff_posts',
'austria_trip' => 'austriatrip_posts'
);
$files = array( 'news' => 'indextest.php',
'requests' => 'prayer_updates.php',
'big_requests' => 'prayer_updates.php',
'great_stuff' => 'great_stuff.php',
'austria_trip' => 'austria_trip.php'
);
$comments_dbs = array( 'news' => 'news_comments',
'requests' => 'requests_comments',
'big_requests' => 'bigrequests_comments',
'great_stuff' => 'greatstuff_comments',
'austria_trip' => 'austriatrip_comments'
);
$q_posts = mysql_query("SELECT * FROM {$posts_dbs[$type]} WHERE ID = $id LIMIT 1;");
$q_comments = mysql_query("SELECT * FROM {$comments_dbs[$type]} WHERE PostID = $id;");
$post = mysql_fetch_assoc($q_posts);
$title = stripslashes($post['Title']);
$author = stripslashes($post['Author']);
$content = stripslashes($post['Content']);
$date = date( "D, F d, Y \a\\t h:ia", $post['Date'] );
$num_comments = $post['NumComments'];
$id = $post['ID'];
$html .="
by $author on $date
$content
comments
";
while( $comment = mysql_fetch_assoc($q_comments) )
{
$c_website = stripslashes($comment['AuthorWeb']);
$c_author = stripslashes($comment['Author']);
$c_content = stripslashes($comment['Content']);
$c_date = date( "F d, Y \a\\t h:ia", $comment['Date'] );
if( $c_website != "" && $c_website != "http://" )
{ $c_author = "
$c_author"; }
$html .= "
";
}
$html .= "
add a comment
";
return($html);
}
//gets guestbook entries from database
function GetGuestbook()
{
$max_entries = 7;
$one_past_max = $max_entries + 1;
$num_entries = 1;
$start_entry = $_GET['page'] ? ($_GET['page'] * $max_entries) : 0;
$q_entries = mysql_query("SELECT * FROM guestbook ORDER BY ID DESC LIMIT $start_entry,$one_past_max;");
$html = "
guestbook entries
";
while( $num_entries <= $max_entries and $entry = mysql_fetch_assoc($q_entries) )
{
$author = stripslashes($entry['Author']);
$authorweb = stripslashes($entry['AuthorWeb']);
$content = stripslashes($entry['Content']);
$date = date( "F d, Y \a\\t h:ia", $entry['Date'] );
if( $authorweb != "" && $authorweb != "http://" )
{ $author = "$author"; }
$html .="
";
$num_entries++;
}
if( $start_entry > 0 or ($start_post == 0 and $entry = mysql_fetch_assoc($q_entries)) )
{
if($start_entry > 0) { $entry = mysql_fetch_assoc($q_entries); }
$html .= "
";
$newer_entries = $_GET['page'] - 1;
$older_entries = $_GET['page'] + 1;
if($start_entry != 0)
{ $html .= "| newer entries | "; }
if( $entry )
{ $html .= "older entries | "; }
$html .= "
";
}
return($html);
}
//displays a single album
function DisplayAlbum()
{
$root = '../pictures_root';
$description = addslashes(file_get_contents("$root/{$_GET['album']}/description.txt"));
$album = array( 'Folder' => "{$_GET['album']}",
'Title' => "{$_GET['album']}",
'Description' => "$description"
);
$picture_counter = 0;
$first_picture = "";
$thumb_prefix = "thumb_";
print <<{$album['Title']} || return to album index
{$album['Description']}
END;
$num_negatives = ceil($picture_counter / 10);
$this_negative = 1;
while( $this_negative < $num_negatives )
{
print "
{$this_negative} -";
$this_negative++;
}
print <<
{$this_negative}
| page: 1
>>> Loading picture...
END;
}
//displays all folders as albums in a certain root folder
function DisplayAlbumIndex()
{
$root = '../pictures_root';
$albums = scandir($root); //get contents of root folder, holding all album folders
if($albums)
{
$album_counter = 0;
print "\n";
print "\n";
foreach($albums as $folder) //step through root folder
{
if( $folder == '.' or $folder == '..' )
{ continue; }
if($album_counter == 2)
{
print "
\n\n";
$album_counter = 0;
}
$pictures = array();
$h_album = opendir("$root/$folder"); //open album folder and get two pictures
if($h_album)
{
$c = 0;
while( ($c < 2) && (false !== ($picture = readdir($h_album))) )
{
if(0 === stripos($picture,'thumb_'))
{
$pictures[$c] = $picture;
$c++;
}
}
closedir($h_album);
}
print "| \n";
print " $folder \n";
print "\n";
print "  \n";
print " + view album\n";
print " ";
print " | \n";
$album_counter++;
}
print "
\n";
print "
\n\n";
}
}
//this function traverses a folder and returns html describing what it finds
function TraverseFolders( $p_path )
{
$rootfolder = opendir( $p_path ); //open folder passed to function
$back_paths = explode("/",$p_path);
$folderhtml = ""; //variable that will hold all the HTML about the folder
$cum_path = '../projects_folders';
foreach($back_paths as $path)
{
if( $path == '..' ) { continue; }
if( $path != 'projects_folders' )
{ $cum_path .= "/$path"; }
if( $cum_path != $p_path )
{ $folderhtml .= " ::
$path"; }
}
$folderhtml .= "
\n";
while( $element = readdir( $rootfolder ) ) //one by one, set $element to a file or folder inside the passed folder
{
if( ($element != '.') and ($element != '..') ) //ignore current and parent folders
{
if( is_dir("$p_path/$element") ) //if $element is a folder, call this function recursively and create HTML for that folder
{
clearstatcache(); //make sure each is_dir call is not using cached information from last is_dir check
$folderhtml .= "
\n";
}
else
{ $folderhtml .= "+
$element\n
\n"; }
}
}
closedir( $rootfolder );
$folderhtml .= "
";
return $folderhtml;
}
?>