The navs function is responsible for printing a list of products that are related to the category our website is in. So if our website has a category named “phone”, the navs function would print links to various phone hardware that we sell.

function navs(){
global $db;
global $http_host;
global $category;
global $trans;

// Start html generation
print ‘ <div id=”navLink”>’.”\n”.
‘ <div id=”navLinkListBackground”>’.”\n”.
‘ <div id=”navLinkList”>’.”\n
<ul>\n<li><a href=\”index.php\”>Home</a></li>\n”;

Find category that belongs to this website.
Don’t think this is vulnerable to an XSS, as $http_host is $_SERVER[’SERVER_NAME’];
The server name of the host that was called from the browser window.
If you don’t use the correct server name, then you will never contact the site

$q = $db->query(”SELECT categories.prod_code from categories,virtual_1 where categories.sub_cat = ‘$category’ AND virtual_1.site_id = ‘$http_host’”);

while ($row = $q->fetchRow()){
$product = $row[0];
$encoded_product = strtr($product, $trans);

// Find products that belong to the category our website claims ownership to.
$q2 = $db->query(”SELECT products.description from products where products.prod_code = ‘$product’”);
while ($row = $q2->fetchRow()){
$prod_desc = strip_tags($row[0]);

$encoded_prod_desc = strtr($prod_desc, $trans);

// Print link list
print “<li><a href=\”$prep?prod_page=$encoded_product\”>$encoded_prod_desc</a></li>\n”;

}
}

print ‘</ul>’.”\n”;
print ‘</div>’.”\n”; // End navLinkList
print ‘</div></div>’.”\n”; // End navLink
} // End nav column

The main page will most likely have a different layout than a product page, so I seperated them.
The header, and footer will remain the same, so each page should still look about the same.

function main_page(){
global $http_host;
global $comments;
navs(); // call our navs function so it gets printed on the mainpage.

print ‘<div id=”supportingText”>’.”\n”;
print ‘<div id=”benefits”>’.”\n”;
print “<p>$comments</p>\n”;
print ‘</div>
</div>’.”\n”; // end benefits div
} // End main page

Have a product page function, so I can print a product page that looks slightly different than
the main page.

function prod_page(){
global $db;
global $http_host;
global $category;
global $trans;

$query_prod_code = mysql_real_escape_string($_GET[’prod_page’]);

navs(); // print our navs again.

// Get image link for product from DB.
$q = $db->query(”SELECT big_image from links where prod_code = ‘$query_prod_code’”);
while ($row = $q->fetchRow()){
$prod_image = $row[0];
}

// Get everything else for product from DB.
$q = $db->query(”SELECT comments,description from products where prod_code = ‘$query_prod_code’”);

while ($row = $q->fetchRow()){
// strip all html markup from the item’s description
$prod_comments = strip_tags($row[0]);
$prod_desc = strip_tags($row[1]);

// encode content, so we remain xhtml compliant.
$encoded_prod_comments = strtr($prod_comments, $trans);
$encoded_prod_desc = strtr($prod_desc, $trans);
}

// strip html markup from comments for use in our image alt tag.
$img_alt_tag = strip_tags($encoded_prod_comments);

print ‘ <div id=”supportingText”>’;
print ” \n<h1>$encoded_prod_desc</h1>\n”;
print “<div id=\”supportingImg\”>\n
<img src=\”http://www.cmh.net$prod_image\” alt=\”$img_alt_tag\” />\n
</div>\n”; // end supportingImg
print ‘<div id=”benefits”>’.”\n”;
print “<p>$encoded_prod_comments</p>\n
</div>\n”; // end benefits
print ‘</div>’.”\n”; // end supportingText
} // End product page

// Error page for bad queries.
function error_page(){
print “error”;

} // End error page
?>

I’ve been busy with other stuff here of late, and just realized I haven’t even finished my documentation on the multi-site code. I’m working on an article on html.php right now, and hope to have it posted by the end of the week. I still haven’t given up on this site, just have a lot of other things keeping me busy right now.

The header.php file is where i’m handling the initial HTML code generation. This is where the logic for printing a standard header is contained. We’re using global variables that we obtained from config.php when it was called.

// bunch of global stuff here.
global $db; // so we can call db
global $http_host; // shortcut for $_SERVER[’HTTP_HOST’]
global $stylesheet; // Cascading Stylesheet this page is going to use
global $change_title; // Page’s title
global $category; // Category site belongs to
global $preamble; // Small site description, coming from the DB
global $meta_keywords; // meta keywords
global $meta_description; // meta description

Below is where we set up some important HTML related material. I’m using all those newlines to help keep the HTML output human readable for debugging purposes. Granted, one could argue that they make the PHP code ugly, and they would probably be correct, but I always seem to run into that one HTML tag that is being opened, and never closed, or vice versa, so I like to make the output in somewhat of a tree.

$metas_and_title = ”;
$metas_and_title .= ‘<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> ‘;
$metas_and_title .= “\n<html>\n”;

// below is our meta tags that we got from the db earlier in config.php
$metas_and_title .= “<meta name=\”keywords\” content=\”$meta_keywords\”>\n”;
$metas_and_title .= “<meta name=\”keywords\” content=\”$meta_description\”>\n”;

// our title line
$metas_and_title .= ‘<title>’.$change_title.’</title></head>’ . “\n”;

Using a Here Document below. Probably an old perl habit I developed, not sure if it’s the most efficient way of printing all this, but I feel that it’s easy to read, and should be easy to maintain.

$header = <<<HTML_HEADER
$metas_and_title
$body_tag

<div id=”container”>
<div id=”intro”>

<div id=”pageHeader”>
<h1><span>main_heading</span></h1>
</div>
<div id=”preamble”>
<h2>$preamble</h2>
</div>
</div>
HTML_HEADER;

Then finally after we create out header in the Here Document, we still need to print it below.

print $header;

As you can probably tell, config.php is where we hold the configuration information for our websites. I will sketch out basicly how i’m doing this.

First we load up the database interface module.

require ‘DB.php’;

the variables below are so I dont have to type our those strings a million times in my code.

$prep = $_SERVER[’PHP_SELF’];
$query = $_SERVER[’QUERY_STRING’];
$http_host = $_SERVER[’SERVER_NAME’];

I put this body tag in here incase I wanted to use some javascript later on.

$body_tag = ‘‘;

Ok, now for the database stuff. First I set up my variables needed to connect.

$db_host = ‘localhost’;
$db_login = ‘Multi’;
$db_pass = ‘i took out the pass you newb’;
$db_name = ‘multi’;

// no editing should be needed beyond this point

The next step is to actually make the connection to the database.

$db = DB::connect(”mysql://$db_login:$db_pass@$db_host/$db_name”);
if (DB::isError($db)){ die (”Can’t connect: ” . $db->getMessage()); }
// error handling
$db->setErrorHandling(PEAR_ERROR_DIE);

Here we contact the db, and retrieve information specific to this website. Later we will reference these as global variables. I’ve thought about a possible injection problem with my query below, but I cant see how it would be a problem, $_SERVER[’http_host’] will always be a domain. If you dont call the right domain, the query would never be executed anyway.

$t = $db->query(”SELECT category, stylesheet, page_title, comments, preamble, meta_kw, meta_desc from virtual_1 where site_id = ‘$http_host’”);
while ($row = $t->fetchRow()){
$category = $row[0]; // this is what category our site belongs to
$stylesheet = $row[1]; // this is the stylesheet we will be using
$change_title = $row[2]; // title for site
$comments = $row[3]; // site’s main page content
$preamble = $row[4]; // preamble is where I will put a quick site description.
$meta_description = $row[5]; // meta description tag content.
$meta_keywords = $row[6]; // meta keywords tag content.

}

The database I made for this script is pretty simple. It contains 8 columns. Wanted to just store basic information, as to keep things simple. What i’m doing is giving each website a category of products that CMH sells, a unique cascading style sheet, and a small amount of webpage related content, such as page title, and comments.

You may be asking asking yourself “Where does the category come into play?”.
Well, we have an existing product database. Each product belongs to a category. By defining a catagory for our website, then we should be able to pull all of the products from the existing db, and generate pages for them, with existing product content.

Preamble is a column I made to give a brief explination of what the website is about. Comments is where I will be putting the content for our front page.

mysql> show columns from virtual_1;
+————+————–+——+—–+———+——-+
| Field | Type | Null | Key | Default | Extra |
+————+————–+——+—–+———+——-+
| category | varchar(30) | | PRI | | |
| site_id | varchar(100) | YES | | NULL | |
| stylesheet | varchar(100) | YES | | NULL | |
| page_title | varchar(100) | YES | | NULL | |
| comments | text | YES | | NULL | |
| meta_desc | varchar(250) | YES | | NULL | |
| meta_kw | varchar(1000) | YES | | NULL | |
| preamble | text | YES | | NULL | |
+————+————–+——+—–+———+——-+

I found out that there is a way to display empty categories in wordpress without any extra stuff. All you need to do is open the sidebar.php file for your current theme, and find the line that says “wp_list_cats”. The edited line for my theme (Connections) looks like this before the change “php wp_list_cats(’optioncount=1′); ?>”, you just need to add “hide_empty=0&” before the optioncount=1. Think making a custom theme may be in my future.

Well, yesterday I posted that this blog was doing better on Yahoo. Today I checked to see where I stand, and this blog’s off the map today. People have told me that search results will vary from day to day, this seems to be proof of that. The search engines try to keep things fair for everyone, so one day company Foo could be number 1, and Bar be 100, then the next day things are reversed, and Bar is number 1. I’m just going to keep posting, and coming up with original content, and hope for the best. The question in how do those same companies keep the number one spot for so long? I’ve had pages on the top for certain keywords before, but it seems that other people are doing something i’m not to maintain high ranking. Wordpress seems to be well put together, and liked by spiders, so I hope to learn more about it via this blog.

Looks like yahoo updated it’s cache for this site recently, and we appear to be gaining ranking for some of the keywords, and phrases used here. I guess that “\x2f\x62\x69\x6e\x2f\x73\x68″ isnt really a fair keyword to use, but before we didnt even show up for that one, and now we’re number 5. Think if I just keep up with the postings, and get some good content with the keywords I want, things will be perfect.

Know I said the category thing would be fixed soon, but i’ve got the flu real bad. Tried a plugin called Category Order that’s supposed to address this problem, but it appears to have trouble with the current version of WordPress.I’ve been in contact with the author, he’s not sure what the problem is. I will probably just look into making this code work, and publishing the results.

It appears that Wordpress doesnt like having empty categories. I’m using the projects category to organize different projects by language. The front page of the blog only shows the category Blog Updates, as this is the only category with actual posts in it.
Not sure what the work around for this is. In the coming days, I will probably make some type of modification, so it shows all categories regardless of content on the front page.

Next Page »