R
E
S
O
U
R
C
E
S
       Home      Products & Services      Contact Us      Links


WebHatchers will design & develop your site for you.
_______________________

Website Menu Heaven: menus, buttons, etc.
_______________________

Send us your questions.
_______________________

site search by freefind
_______________________

HOME
SEO, Google, Privacy
   and Anonymity
Browser Insanity
JavaScript
Popups and Tooltips
Free Website Search
HTML Form Creator
Animation
Buttons and Menus
Counters
Captchas
Image Uploading
CSS and HTML
PHP
AJAX
XPATH
Website Poll
IM and Texting
Databases—MySQL
   or Not MySQL
Personal Status Boards
Content Management
   Systems
Article Content
   Management Systems
Website Directory
   CMS Systems
Photo Gallery CMS
Forum CMS
Blog CMS
Customer Records
   Management CMS
Address Book CMS
Private Messaging CMS
Chat Room CMS
JavaScript Charts
   and Graphs




Free Personal Status Boards (PSB™)

Free Standard Free PSB

Free PSB Pro Version

Free Social PSB

Free Social PSB Plus (with Email)

Free Business PSB

Free Business PSB Plus (with Email)

PSB demo

Social PSB demo

Business PSB demo

So what's all this PSB stuff about?

Chart comparing business status boards

PSB hosting diagram

PSB Licence Agreement



Copyright © 2002 -
MCS Investments, Inc. sitemap

PSBs, social networking, social evolution, microcommunities, personal status boards
PSBs, social networking, business personal status boards
website design, ecommerce solutions
website menus, buttons, image rotators
Ez-Architect, home design software
the magic carpet and the cement wall, children's adventure book
the squirrel valley railroad, model railroad videos, model train dvds
the deep rock railroad, model railroad videos, model train dvds

PHP Code for Blog Home Page

Content Management Systems—Blog

Blog is another word for weblog. A weblog is a website that is like a diary or journal. Bloggers often write about their opinions and thoughts. What bloggers write is called posts, which are blocks of writing on the blog. Posts often include links to other websites, and often images and even videos as well. Blogs can have many writers. If they have more than one writer, they are often called community blogs, team blogs, or group blogs. But more and more blogs let any visitors leave comments in an interactive format. Signing up and logging in is often required for this privilege. This interaction with visitors is an important part of many blogs.

Forums always have lots of writers plus an administrator and they're about a specific area of interest and visitors get to post rather than just comment on others' posts, whereas blogs are written by one or a few people and they're more about this person or group's opinions and visitors comments on these opinions. Both forums and blogs can have categories—especially larger ones. Forums can have Q and A, but blogs rarely do.

Blog posts are commonly displayed in reverse-chronological order—i.e., from latest to earliest. Blog comments are posts in which a person says what they think about the blog post. Such comments can be considered posts, replies, or comments. Blogs are good for discussions — if someone writes something that someone else disagrees with, they can fix it by writing a comment on the blog. Someone else cannot change what the post says, but the writer of the post can. Sometimes only the blog owner can change or delete posts or comments, while visitors can simply read the blog and leave comments.

Often people create RSS feeds to their blogs. Programs called content aggregators or news readers can put postings from all the blogs that a person likes (that have RSS feeds) in one convenient place. Many people find it easier to read all the new posts from blogs in one place, through RSS, instead of going to each site one at a time. This saves a lot of time!

Blogs, like forums, are great communication tools for the exchange of ideas, for people teaching others about a specific area of interest, or even for just general social communication. The fact that they are usually so specialized helps get them high up in search results as well as contributing considerably to bodies of knowledge, although forums and news groups usually do this better than blogs, which are often more like diaries than information sources. True, there's a lot of misinformation and putdowns on both, but this invariably occurs when people communicate. One must learn to take what one learns with a grain of salt.

A forum, also know as a message board, is an online discussion site where people can converse, argue, inform, teach, or bitch in the form of posted messages. Chat rooms deliver messages in real-time but with forums and blogs, getting new messages requires the page to be reloaded (F5). Forums call a single conversation a thread. Blogs simply have posts and comments. Even though on either blogs or forums users have to login to post messages, usually they don't have to login to read the existing messages.

Download the files: cms-blog.zip

Content Management System: Blogs


The blog home page whose code is on this web page has a sidebar with the complete list of categories. Any of these can be clicked and all the topics in that category will be displayed in their entirety—which can even include images, links, email links, audio buttons, or videos. The sidebar also has a link, TITLES ONLY, which brings up all topics' titles and each topic is a link to the blog topic and replies viewing page. This TITLES ONLY feature also displays in a table each topic's Category, how many replies it's had, how many views it's had, and the date and time of its creation. Depending on which topic link is clicked, its corresponding id will be sent via query string (along with the username) to the blog topic and replies viewing page and only this topic and its replies will be visible on this viewing page. For other topics, you must return to the blog home page from a Return to Blog link on the blog topic and replies viewing page.

When you first land on the home page, the 10 most recent topic posts will be displayed in their entirety—which can even include images, links, email links, audio buttons, or videos. The programming for getting the most recent topics is very simple: since the id field of the topics table is an autoincrementing primary field, each new topic always gets the highest id number in the table as it is saved to the table, and when the script is displaying topics from newest to oldest, it just uses the id field sorted in descending order to guide the topic displaying. At the bottom of the screen is a link, More, that leads to the next 10 topics, and so on. There is a link, BACK TO TOPICS VIEW, that brings visitors back to this 10-topic display if they had either been in the TITLE ONLY mode or the categories mode. The categories mode is visually the same as the 10-topics-at-a-time-mode, except that the latter cares only about posting date while the former cares only about displaying all the topics in a single category. So how does one program all these wonders? The same way an elephant makes love to a mouse: VERY carefully!

On to the PHP code. As usual, we start with config.php, since without it, the MySQL-based blog would not be viable. You cannot relate to a db without knowing the magic words. Next, the security of the page is dealt with by ensuring the page visitor has a username that's in the database. Note that the various pages on our blog app use both forms and URL query strings to transfer data between pages, so both POST and GET are checked for username, and if neither works, the visitor is sent to the login script. Not only is the db checked for a valid username, the username is checked to make sure it has only 6 to 20 letters, numbers or underscore in it and no other characters—otherwise, it's off to the login script. If a hacker has put something nasty in the query string, he'll end up at the login script. All our blog app scripts have this same (almost) username checker at the top of the PHP section—except for the login script. We say "almost" because most pages only allow the administrator access because most pages are about adding, deleting, or editing topics, replies, or categories. So, seeing if the username is the administrator's is in the user checker on most of these blog app pages.

Speaking of seeing if the username is the administrator's, we do that next because the page's links will differ depending on who the user is that's currently using the blog. Regular visitors will not be able to even see the links Create New Topic or Edit Categories or Delete Topic or Open/Close Topic or Edit Topic, for instance, but the administrator will. The regular users will be able to see a Replies link which will transport him or her to the glories and wonders of the blog's topic and replies viewing page where s/he can read topics or add replies (comments). In addition to being able to see and use a Replies link, regular users will also see the titles links, which will also take them to the topic and replies viewing page. if($U<>"DIRTY_dog_DROPPINGS_"){$am_i_admin="cms-view-blog-topic.php";$thelinktext=""; is our way of coding "if you aren't the administrator we will make the links disappear." The administrator's username is a bit silly, as you see. Feel free to change it (to AfDqC_1f3_DkI3j5k9N_ for example) when you register the administrator username and password, but you must search and replace ALL blog app pages for our silly name and replace it with your not-as-silly name or you'll have more problems than a pregnant nun. Anyway, in that code you can see that the link is of no consequence because the link text that will be for clicking on is an empty string so the user will see nothing. Note that in the script below the admin person gets good links with good query strings in them so username and topic id will be passed to that blog app.

Next comes the blog tables. This script creates them if they do not exist. We'll need a topic table, blog_question, with fields: id, topic (which is the title), detail (which is the main content), name, email, datetime, category, open (the topics' open/closed flag), topics_username, view (which is the number of views of the page), and reply (which is the number of replies to the page). We'll also need a replies table, blog_answer, with fields: id, question_id, a_id, a_name, a_email, a_answer (which is the main content of the reply), and a_datetime. The blogcategories table's categories field is consulted and its contents dumped into an array which will be used to populate the categories sidebar—as you will see. The blog_question table's id field is then consulted and its contents dumped into an array which will be used to guide the topics display script—as you will see.

Then the $mode flag is checked and if it is not set, it gets a minus 2 which means the 10-topics-at-a-time displaying mode. If it is minus 1, it signifies the TITLES-ONLY display mode. If a category has been clicked in the sidebar, $mode is any number from zero to however many categories there are. The following will then be the way the db is queried for all topics with a chosen category: SELECT * FROM blog_question WHERE category='$cat[$mode]'. You can see why we stuck all the categories into an array in order to empower the $mode flag to point out which array element we want.

Moving on to this code: if($mode==-2){ //10 topic groups and $j=$_GET['j'];if(!isset($j)){$j=10;} and $k=$j-10; and for ($i=$k;$i<$j;$i++) {, we see that it's not hard to display 10 topics at a time, using the correct FOR loop code. Using the id array, we get the topic info for the first 10 topics, then htmlentities() and stripslashes() are used to provides display security—just in case the data has somehow gotten compromised.

You're allowed to have bold, underscore, italics, links, email links, pictures, videos, and audios. The only limitation is that you must use our tag system. And here it is:

No single or double quotes or Enter/Return allowed in topic titles. Use letters, numbers, spaces and these: , . ) ? : ( ; _ - ! / in title and content. In content only, you may use single or double quotes or Enter/Return. Use Returns for new paragraphs. For italics, starting and ending tags are (i-) and (ii-). For bold, use (b-) and (bb-). Underline is (u-) and (uu-). For links, use (l-) then domain without http://, then (ll-) then link text, then (lll-). For emails, use (e-) then email address with (ee-) instead of @, then (eee-) then subject, then (eeee-) then link text, then (eeeee-).

For pictures, use (p-) as start tag, then the complete picture URL with .jpg or .png or .gif or .bmp extension, then (pp-) as end tag. If the picture somehow is on the blog server near the blog folder but is in a higher level folder than the subfolder your Content Management System is in, put 2 dots before the name and just make sure you use the picture name only, not a URL path, for this special case. If it's in a subfolder like "images", then move it to the higher level folder or the subfolder your Content Management System is in. If the image is wider than 580 pixels, resave it to 580.

For YouTube video, use (v-) as start tag, then the letter code after http://www.youtube.com/v/ and before &hl=en_US&fs=1& in your video's YouTube Embed code, then (vv-), then the same letter code again, then (vvv-) as end tag. If the video you want to use is not on YouTube, upload it there before proceeding.

For audio, use (a-) as start tag, then the sound's name, then (aa-), then the complete sound file URL ending in .mp3 or .wav, then (aaa-) as end tag. Make sure the site administrator has put the sound.js file in the folder your blog Content Management System is in, and do not try to put this JavaScript on the web page—it needs to be a separate file. Save the following code (exactly, without adding script tags or anything else!) as sound.js: function sound(s,q) {document.getElementById(q).innerHTML="<embed src='"+s+"' hidden=true autostart=true loop=false>"}

At the conclusion of the first section of the script about custom tags, there is more username checking to see whether to make certain links visible or not, based upon whether you are the administrator or not. Note that the email is either displayed or not depending on the same username checking. <td><b>Email :</b> <? if($U=="DIRTY_dog_DROPPINGS_"){echo htmlentities(stripslashes($rows['email']), ENT_QUOTES);}else{echo "(private)";} ?></td> makes sure "(private)" is displayed if they're anyone but the administrator. Then <td><b>Topic is: </b><? $open="Open";if($rows['open']=="0"){$open="Closed";}; echo $open; ?></td> helps to display whether the topic is open to new replies or not or closed. The code block with all the nonbreaking spaces in it has a Replies link at the end that is for everyone—no attempt to make the link invisible is made.

Back with PHP code now, we have $j=$j+10; if($i<$num_topics){echo "<div class='over2'><a href='cms-blog.php?username=".stripslashes($U)."&j=".$j."&mode=-2'><B>More . . .</B></a></div>"; where if the current topic id array element number is less than the $num_topics variable (which we saved after pushing the ids into the array), then we reload the page with 3 values to GET: the username, $j value, and $mode value. There's no good way to get the last 10 topics to disappear to make room for the next 10 topics without reloading the page.

The code now deals with the TITLES ONLY script where the $mode flag is minus 1. Note that the displaying code is quite usual until we hit the title link. Here the link with the username and id is in the link's query string, but then the link text that you click on is the topic title field from the blog_question table. The db is supplying everything we need, in this example. At the bottom of this page are the links for Delete Account and Search Blog both of which are for anyone to use, but also 2 admin-only links: Create New Topic and Edit Categories whose strings are defined at the beginning of the first PHP code section.

The next script section starts with merely }else{, but it's for when the $mode is neither -1 nor -2, but simply 0 or above. The $mode flag will be the array element number of the chosen category, since that is what this section does: show all the topics in a category. It's essentially the same code as the section displaying 10 topics at a time, with the same security measures, the same custom codes interpretation, and the same conditional links where the admin person sees all but others see ... not so much.

At the bottom of the script is the category sidebar code. It simply takes the category array, looping through it and turning each array value into a link that sends the zero and above $mode flag to this page via a page reload and a query string. Note that if they click on the TITLES ONLY link a -1 is sent to the page's $mode value, but the BACK TO TOPICS VIEW link sends a -2.

SAVE THIS PAGE AS: cms-blog.php

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<TITLE>Blog—Content Management System (CMS)</TITLE>
<meta name="description" content="Blog—Content Management System (CMS)">
<meta name="keywords" content="Blogs,Blog,Content Management System,Content Management System Articles,php,CMS,javascript, dhtml, DHTML">
<style type="text/css">
BODY {margin-left:0; margin-right:0; margin-top:0;text-align:left;background-color:#ddd}
p, li {font:13px Verdana; color:black;text-align:left}
h1 {font:bold 28px Verdana; color:black;text-align:center}
h2 {font:bold 24px Verdana;text-align:center}
td {font:normal 13px Verdana;text-align:center;background-color:#ccc}
table.over td {text-align:left}
.topic {text-align:left;background-color:#fff}
.center {text-align:center;}
.cat {position:absolute;top:40px;left:2px;width:180px;border:2px solid black;background-color:#ccc;font:normal 13px Verdana;text-align:center;}
.blog {position:absolute;top:40px;left:197px;width:800px;border:1px solid black}
.over {margin-left:230px}
.over2 {margin-left:540px}
.mid {text-align:center;background-color:#bbb}
</style>
<script language="javascript">
mactest=(navigator.userAgent.indexOf("Mac")!=-1) //My browser sniffers
is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1
Netscape=(navigator.appName.indexOf("Netscape") != -1)
msafari=(navigator.userAgent.indexOf("Safari")!= -1)
wsafari=0; if(!mactest&&msafari){wsafari=1;msafari=0}
is_opera = 0; if(window.opera){is_opera=1}
is_ie_mac = 0; is_ie=0;if(document.all){is_ie=1}
if(is_ie&&mactest){is_ie_mac=1}

function fixem(){if(Netscape||is_opera){e=document.getElementById('ti');e.style.marginTop='-15px';}}

</script>
</head>
<body onload='fixem()'>
<?php
include_once"config.php";

$U=$_POST['username'];if (!isset($U)){$U=$_GET['username'];}
if (isset($U)&&preg_match("/[A-Za-z0-9_]{6,20}$/",$U)){$check_user_data = mysql_query("SELECT * FROM blogmembers WHERE username='$U'") or die(mysql_error());if(mysql_num_rows($check_user_data)==0){unset($U);}}else{unset($U);}
if (!isset($U)){echo '<script language="javascript">alert("Please login.");window.location="blog-login.php"; </script>';}

if($U<>"DIRTY_dog_DROPPINGS_"){$am_i_admin="cms-blog.php";$thelinktext="";$am_i_admin2="cms-blog.php";$thelinktext2="";}else{$thelinktext="Create New Topic";$am_i_admin="cms-create-blog-topic.php?username=".$U;$thelinktext2="Edit Categories";$am_i_admin2="cms-blog-edit-category.php?username=".$U;}

$sql = "CREATE TABLE IF NOT EXISTS blog_question (
id int(4) NOT NULL auto_increment,
topic varchar(255) NOT NULL default '',
detail text NOT NULL,
name varchar(65) NOT NULL default '',
email varchar(65) NOT NULL default '',
datetime varchar(25) NOT NULL default '',
category varchar(30) NOT NULL default '',
open tinyint(1) NOT NULL default '1',
topics_username varchar(20) NOT NULL,
view int(4) NOT NULL default '0',
reply int(4) NOT NULL default '0',
PRIMARY KEY (id)
) ENGINE=MyISAM AUTO_INCREMENT=1";

mysql_query($sql);

$sql = "CREATE TABLE IF NOT EXISTS blog_answer (
id int(4) NOT NULL auto_increment,
question_id int(4) NOT NULL default '0',
a_id int(4) NOT NULL default '0',
a_name varchar(65) NOT NULL default '',
a_email varchar(65) NOT NULL default '',
a_answer text NOT NULL,
a_datetime varchar(25) NOT NULL default '',
PRIMARY KEY (id)
) ENGINE=MyISAM AUTO_INCREMENT=1";

mysql_query($sql);

$cat=array();

$res = mysql_query("SELECT category FROM blogcategories order by category") or die(mysql_error());
while ($row = mysql_fetch_row($res)) {
array_push ($cat, $row[0]);
}

$num_cats_in_table=mysql_num_rows($res);

$tbl_name="blog_question";

$ids=array();

$res = mysql_query("SELECT id FROM $tbl_name ORDER BY id DESC") or die(mysql_error());
while ($row = mysql_fetch_row($res)) {
array_push ($ids, $row[0]);
}

$num_topics=mysql_num_rows($res);

echo "<center><div id='ti'><h2>My Blog</h2></div></center>";

$mode=$_GET['mode'];if(!isset($mode)){$mode=-2;}

if($mode==-2){ //10 topic groups

$j=$_GET['j'];if(!isset($j)){$j=10;}
$k=$j-10;

for ($i=$k;$i<$j;$i++) {

$res = mysql_query("SELECT * FROM $tbl_name WHERE id='$ids[$i]' ORDER BY id DESC") or die(mysql_error());
while($rows=mysql_fetch_array($res)){
$id=$rows['id'];
?>

<BR>
<table id='over' class='over' width="700" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFF">
<tr><td class='mid'><b>Topic</b></td></tr>
<tr>
<td><b><? echo htmlentities(stripslashes($rows['topic']), ENT_QUOTES); ?></b></td>
</tr>
<tr>
<td><p>
<?php
$detail=strip_tags($rows['detail']);
$detail=htmlentities(stripslashes($detail), ENT_QUOTES);
$detail=nl2br($detail); //Enter turns into <BR />
$pattern = '/(<BR\s\/>)+/i';
$replacement = '</p><p>'; //turn any <BR />s into a </p><p> to allow indent since <p>s are css styled to indent!
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(i-\)/i';
$replacement = '<i>'; //turn any (i-)s into a <i>s to allow italics
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(ii-\)/i';
$replacement = '</i>'; //turn any (ii-)s into a </i>s to allow italics
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(b-\)/i';
$replacement = '<b>'; //turn any (b-)s into a <b>s to allow bold
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(bb-\)/i';
$replacement = '</b>'; //turn any (bb-)s into a </b>s to allow bold
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(u-\)/i';
$replacement = '<u>'; //turn any (u-)s into a <u>s to allow underline
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(uu-\)/i';
$replacement = '</u>'; //turn any (uu-)s into a </u>s to allow underline
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(p-\)\.\./i';
$replacement = '<center><br><IMG SRC="../'; //turn any (p-)s into start of image tag to allow image
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(p-\)/i';
$replacement = '<center><br><IMG SRC="'; //turn any (p-)s into start of image tag to allow image
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(pp-\)/i';
$replacement = '" BORDER=0><br><br></center>'; //turn any (pp-)s into end of image tag to allow image
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(l-\)/i';
$replacement = '<a href="http://'; //turn any (l-)s into <http:// to allow link protocol
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(ll-\)/i';
$replacement = '">'; //turn any (ll-)s into "> to allow url
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(lll-\)/i';
$replacement = '</a>'; //turn any (lll-)s into </a> to link text
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(e-\)/i';
$replacement = '<a href="mailto:'; //turn any (e-)s into <a href="mailto: to allow link protocol
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(ee-\)/i';
$replacement = '@'; //turn any (ee-)s into @ to allow email @ sign
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(eee-\)/i';
$replacement = '?subject='; //turn any (eee-)s into ?subject= to allow email subject
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(eeee-\)/i';
$replacement = '">'; //turn any (eeee-)s into "> to allow email address
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(eeeee-\)/i';
$replacement = '</a>'; //turn any (eeeee-)s into </a> to allow link text
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(v-\)/i';
$replacement = '<div style="width:580px"><br><center><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/'; //turn any (v-)s into start of video tag
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(vv-\)/i';
$replacement = '&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'; //middle of video tag
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(vvv-\)/i';
$replacement = '&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object><br><br></center></div>'; //end of video tag
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(a-\)/i';
$replacement = '<div style="width:580px"><br><center><script src="sound.js"></script><span id="a1"></span><form><input type="button" value="'; //turn any (a-)s into start of audio tag
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(aa-\)/i';
$replacement = '" onClick="sound(\''; //middle of audio tag
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(aaa-\)/i';
$replacement = '\',\'a1\')"></form><br><br></center></div>'; //end of audio tag
$detail=preg_replace($pattern, $replacement, $detail);
echo $detail;

if($U<>"DIRTY_dog_DROPPINGS_"){$am_i_admin="cms-view-blog-topic.php";$thelinktext="";
$am_i_admin2="cms-view-blog-topic.php";$thelinktext2="";$am_i_admin3="cms-view-blog-topic.php";$thelinktext3="";
}else{
$thelinktext="Delete Topic";$am_i_admin="cms-delete-blog-topic.php?username=".stripslashes($U)."&id=".$id;
$thelinktext3="Open/Close Topic";$am_i_admin3="cms-open-or-close-blog-topic.php?username=".stripslashes($U)."&id=".$id;
$thelinktext2="Edit Topic";$am_i_admin2="cms-edit-blog-topic.php?username=".stripslashes($U)."&id=".$id;}

?>
</p><BR><BR></td>
</tr>
<tr>
<td><b>Category:</b> <? echo htmlentities(stripslashes($rows['category']), ENT_QUOTES); ?></td>
</tr>
<tr>
<td><b>By :</b> <? echo htmlentities(stripslashes($rows['name']), ENT_QUOTES); ?></td>
</tr>
<tr>
<td><b>Email :</b> <? if($U=="DIRTY_dog_DROPPINGS_"){echo htmlentities(stripslashes($rows['email']), ENT_QUOTES);}else{echo "(private)";} ?></td>
</tr>
<tr>
<td><b>Date/time : </b><? echo htmlentities(stripslashes($rows['datetime']), ENT_QUOTES); ?></td>
</tr>
<tr>
<td><b>Topic is: </b><? $open="Open";if($rows['open']=="0"){$open="Closed";}; echo $open; ?></td>
</tr>
<tr><td class='mid' colspan=3>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;<a href="<? echo $am_i_admin2; ?>"><B><? echo $thelinktext2; ?></B></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="<? echo $am_i_admin; ?>"><B><? echo $thelinktext; ?></B></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="<? echo $am_i_admin3; ?>"><B><? echo $thelinktext3; ?></B></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="cms-view-blog-topic.php?username=<? echo stripslashes($U); ?>&id=<? echo stripslashes($id); ?>"><B>Replies</B></a></td></tr>
</table></td>
</tr>
</table>
<BR>

<?php
}
}
$j=$j+10; if($i<$num_topics){echo "<div class='over2'><a href='cms-blog.php?username=".stripslashes($U)."&j=".$j."&mode=-2'><B>More . . .</B></a></div>";}
}

if($mode==-1){ //titles only

$sql="SELECT id,topic,category,view,reply,datetime FROM $tbl_name ORDER BY id DESC";
$result=mysql_query($sql);
?>

<div class='blog'><table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCC">
<tr>
<td width="5%"><B>#</B></td>
<td width="51%"><B>Topic</B></td>
<td width="16%"><B>Category</B></td>
<td width="6%"><B>Views</B></td>
<td width="6%"><B>Replies</B></td>
<td width="16%"><B>Date/Time</B></td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><? echo htmlentities(stripslashes($rows['id']), ENT_QUOTES); ?></td>
<td class='topic'><a href="cms-view-blog-topic.php?id=<? echo htmlentities(stripslashes($rows['id']), ENT_QUOTES); ?>&username=<? echo stripslashes($U); ?>"><? echo htmlentities(stripslashes($rows['topic']), ENT_QUOTES); ?></a><BR></td>
<td><? echo htmlentities(stripslashes($rows['category']), ENT_QUOTES); ?></td>
<td><? echo htmlentities(stripslashes($rows['view']), ENT_QUOTES); ?></td>
<td><? echo htmlentities(stripslashes($rows['reply']), ENT_QUOTES); ?></td>
<td><? echo htmlentities(stripslashes($rows['datetime']), ENT_QUOTES); ?></td>
</tr>

<?php
}
mysql_close();
?>
<tr>
<td class='center' colspan="6"><a href="<? echo $am_i_admin2; ?>"><B><? echo $thelinktext2; ?></B></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="<? echo $am_i_admin; ?>"><B><? echo $thelinktext; ?></B></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="cms-search-blog.php?username=<? echo stripslashes($U); ?>";><B>Search Blog</B></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="cms-delete-blog-account.php?username=<? echo stripslashes($U); ?>";><B>Delete Account</B></a></td>
</tr>
</table>
</div>
<?php
}else{

$res = mysql_query("SELECT * FROM blog_question WHERE category='$cat[$mode]' ORDER BY id DESC") or die(mysql_error());
while($rows=mysql_fetch_array($res)){
$id=$rows['id'];
?>

<BR>
<table id='over' class='over' width="700" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFF">
<tr><td class='mid'><b>Topic</b></td></tr>
<tr>
<td><b><? echo htmlentities(stripslashes($rows['topic']), ENT_QUOTES); ?></b></td>
</tr>
<tr>
<td><p>
<?php
$detail=strip_tags($rows['detail']);
$detail=htmlentities(stripslashes($detail), ENT_QUOTES);
$detail=nl2br($detail); //Enter turns into <BR />
$pattern = '/(<BR\s\/>)+/i';
$replacement = '</p><p>'; //turn any <BR />s into a </p><p> to allow indent since <p>s are css styled to indent!
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(i-\)/i';
$replacement = '<i>'; //turn any (i-)s into a <i>s to allow italics
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(ii-\)/i';
$replacement = '</i>'; //turn any (ii-)s into a </i>s to allow italics
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(b-\)/i';
$replacement = '<b>'; //turn any (b-)s into a <b>s to allow bold
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(bb-\)/i';
$replacement = '</b>'; //turn any (bb-)s into a </b>s to allow bold
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(u-\)/i';
$replacement = '<u>'; //turn any (u-)s into a <u>s to allow underline
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(uu-\)/i';
$replacement = '</u>'; //turn any (uu-)s into a </u>s to allow underline
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(p-\)\.\./i';
$replacement = '<center><br><IMG SRC="../'; //turn any (p-)s into start of image tag to allow image
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(p-\)/i';
$replacement = '<center><br><IMG SRC="'; //turn any (p-)s into start of image tag to allow image
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(pp-\)/i';
$replacement = '" BORDER=0><br><br></center>'; //turn any (pp-)s into end of image tag to allow image
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(l-\)/i';
$replacement = '<a href="http://'; //turn any (l-)s into <http:// to allow link protocol
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(ll-\)/i';
$replacement = '">'; //turn any (ll-)s into "> to allow url
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(lll-\)/i';
$replacement = '</a>'; //turn any (lll-)s into </a> to link text
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(e-\)/i';
$replacement = '<a href="mailto:'; //turn any (e-)s into <a href="mailto: to allow link protocol
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(ee-\)/i';
$replacement = '@'; //turn any (ee-)s into @ to allow email @ sign
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(eee-\)/i';
$replacement = '?subject='; //turn any (eee-)s into ?subject= to allow email subject
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(eeee-\)/i';
$replacement = '">'; //turn any (eeee-)s into "> to allow email address
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(eeeee-\)/i';
$replacement = '</a>'; //turn any (eeeee-)s into </a> to allow link text
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(v-\)/i';
$replacement = '<div style="width:580px"><br><center><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/'; //turn any (v-)s into start of video tag
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(vv-\)/i';
$replacement = '&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'; //middle of video tag
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(vvv-\)/i';
$replacement = '&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object><br><br></center></div>'; //end of video tag
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(a-\)/i';
$replacement = '<div style="width:580px"><br><center><script src="sound.js"></script><span id="a1"></span><form><input type="button" value="'; //turn any (a-)s into start of audio tag
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(aa-\)/i';
$replacement = '" onClick="sound(\''; //middle of audio tag
$detail=preg_replace($pattern, $replacement, $detail);
$pattern = '/\(aaa-\)/i';
$replacement = '\',\'a1\')"></form><br><br></center></div>'; //end of audio tag
$detail=preg_replace($pattern, $replacement, $detail);
echo $detail;

if($U<>"DIRTY_dog_DROPPINGS_"){$am_i_admin="cms-view-blog-topic.php";$thelinktext="";
$am_i_admin2="cms-view-blog-topic.php";$thelinktext2="";$am_i_admin3="cms-view-blog-topic.php";$thelinktext3="";
}else{
$thelinktext="Delete Topic";$am_i_admin="cms-delete-blog-topic.php?username=".stripslashes($U)."&id=".$id;
$thelinktext3="Open/Close Topic";$am_i_admin3="cms-open-or-close-blog-topic.php?username=".stripslashes($U)."&id=".$id;
$thelinktext2="Edit Topic";$am_i_admin2="cms-edit-blog-topic.php?username=".stripslashes($U)."&id=".$id;}

?>
</p><BR><BR></td>
</tr>
<tr>
<td><b>Category:</b> <? echo htmlentities(stripslashes($rows['category']), ENT_QUOTES); ?></td>
</tr>
<tr>
<td><b>By :</b> <? echo htmlentities(stripslashes($rows['name']), ENT_QUOTES); ?></td>
</tr>
<tr>
<td><b>Email :</b> <? if($U=="DIRTY_dog_DROPPINGS_"){echo htmlentities(stripslashes($rows['email']), ENT_QUOTES);}else{echo "(private)";} ?></td>
</tr>
<tr>
<td><b>Date/time : </b><? echo htmlentities(stripslashes($rows['datetime']), ENT_QUOTES); ?></td>
</tr>
<tr>
<td><b>Topic is: </b><? $open="Open";if($rows['open']=="0"){$open="Closed";}; echo $open; ?></td>
</tr>
<tr><td class='mid' colspan=3>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;<a href="<? echo $am_i_admin2; ?>"><B><? echo $thelinktext2; ?></B></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="<? echo $am_i_admin; ?>"><B><? echo $thelinktext; ?></B></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="<? echo $am_i_admin3; ?>"><B><? echo $thelinktext3; ?></B></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="cms-view-blog-topic.php?username=<? echo stripslashes($U); ?>&id=<? echo stripslashes($id); ?>"><B>Replies</B></a></td></tr>
</table></td>
</tr>
</table>
<BR>

<?php
}
}
?>

<div align=center class='cat'><center>
<?php
echo "<table style='border:none;width:100%'><TR><TD style='border:1px solid black;background-color:#aaa;text-align:center;width:100%'><B>Categories</B></TD></TR>";
for ($i=0;$i<$num_cats_in_table;$i++) {echo "<tr><td style='text-align:center;width:100%'><a href='cms-blog.php?username=".stripslashes($U)."&mode=".$i."'>".$cat[$i]."</a></td></tr>";}
echo "<TR><TD>&nbsp;</TD></TR><TR><TD><a href='cms-blog.php?username=".stripslashes($U)."&mode=-1'>TITLES ONLY</a></TD></TR><TR><TD><a href='cms-blog.php?username=".stripslashes($U)."&mode=-2'>BACK TO TOPICS VIEW</a></TD></TR></table>";
?>
</center></div>
</body>
</html>