Version: 2.10

Type: Full Script

Category: Other

License: GNU General Public License

Description: This is a 100% fully automated Project site builder. It handles unlimited numbers of pictures and folders to catagorize them. If you would like to see an example of the working code, go to http://OUPower.com You place this index.php file in your root directory of you web site or in any directory you desire. Once there, you can start using it immediately. You just dump your pictures (.jpg or .gif) into directories below the starting point used above. You have the option to un-hyperlink directories to use them as catatgorizing folders only, you can ignore directories also. The text for the pictures is easy as pie. You edit 1 text file and that's it. Full instructions are in the main file for performing this. Everything is self contained in this baby. It has a hit counter built in that you can turn on by adding the counter.dat file and it has options for a top.html and bottom.html file to add on to the main (root) directory where you placed this index.php file. If you don't think it is the easiest site builder that you ever saw... let me know. I hope you love it. I have enjoyed making it and plan on adding more to the program as ideas are presented to me. If you want the latest copy go to: http://OUPower.com/Project_Master



<?php 

/* ************************************************************************************************************************
Directions for use:
Save this php file as "index.php" and place it anywhere in your web site. I prefer to place it in the root 
of my web site that way it does absolutely everything for you. View my site
http://OUPower.com to see what I mean. You can of course, put it in any directory that you choose.
It will work just fine that way as well :) Just link your browser to the URL where you have placed this index.php file,
and the Project Master Program does the rest... assuming of course you filled in the variables properly.

Now the directory where you put the index.php file, should contain only project directories, the counter data file
(See below for details) the index.php file, and an optional top.html & bottom.html file... nothing else!
That is all you need to do to set your site up.

In the project directories, simply dump your pictures using the format from the variables below. My format is to name
my files: ScanImage1001.jpg, ScanImage1002.jpg, ScanImage1003.jpg ...etc. Most of your camera utilities will allow you to
dump files in this manner so it literally takes me about 30 seconds to dump my entire camera. All I do is tell it what
number to start at, and point it to the directory where I am dumping my pics.

There is a very cool feature now in Project Master, that allows you to choose NOT to hyperlink a directory. I use this
feature for empty directories. See my site OUPower.com for examples. It works nicely for directories that you wish to only
have as a folder for other things below it. All you do is add an _ (underscore) in front of the directory name. If later
you decide to place files in the directory, you can allow people to enter it by simply removing the _ (underscore) from
the front of the directory name.

This program can track hits to your site by simply adding a file to the same place as you put this index.php file. Name
this hit tracker file main-counter.dat or whatever you like (adjust the variable below if you use another name). In this
simple text file enter a starting hit counter number. 1 is the place to start :) If you start at 0 it will invoke the 
reset protection code and never increment your file. So start at 1 or more. Then chmod 666 the file and that's it.
Every page refresh you will see the counter move up by 1 number.

I recommend using jpg format for pictures so that you can set your picture quality to about 80% ...this will greatly
reduce the file size of your pictures and still retain excellent quality. You can also use gif format if you like.

To add the text to your pictures you simply place a text file in EACH of the project directories. Name the text file
whatever you like. I recommend "aaatext.php" so that it shows up at the very top of each project directory listing.
Inside that file, simply add descriptions for each of your pictures that you want to have a description. Skip any pics
that you don't want a description on. In fact the program works just fine even if you do not have this text file. It will
still build your site for you :)

The format of the aaatext.php file in each project directory is as follows:
<?php
$text1001 = "text for picture 1 here.
";

$text1002 = "text for picture 2 here.
";

$text1003 = "text for picture 3 here.
";
?>

The numbers must exactly match the numbers of your pictures. If your pic is 1001, 1002, 1003 ...then your $text variables
must also be $text1001, $text1002, $text1003  ...they must match exactly!

If you have problems or questions, please try our Forum for help I will likely be too busy to answer each message on
an individual basis, so use the forum for help. http://OUPower.com/forum

Enjoy!
-Christopher T. Moore (Programmer/Inventor)
*/

$Version = "2.10";

if ($ExternallyCalled == "yes") return; // Necessary to use this line so that if called by another program it won't mess things up.
print "<html><body background=\"/forum/clouds.jpg\" bgcolor=\"#C0C0C0\">\n";
/*
************************************************************************************************************************
History of Changes
************************************************************************************************************************
2.10
Tuned up the version detection routine a bit more.

2.09
Added version checking to alert webmasters when new versions are available.

2.08
Added multi-color support for New, Newer & Newest updates :) -Added the variables for the colors and all 3 day settings
of course! -I found a missed update where I had 2 different versions of 2.07 by accident. I have now combined these 2
different versions of 2.07 into a new 2.08 version. Both had nice little updates so I didn't want any confusion. To
ensure that you have both versions, get 2.08.

2.07
Added an additional check to the counter file where after writing, it will now read it once more to check that the second
read is not less than the first set. If the second read is less, it again updates the counter.

2.06
Fixed a small bug where the time was displaying incorrectly. It was showing 10 minutes on the end of everything and that
proved to be due to the use of h:ma instead of h:ia in the date function of php. All better now :)

2.05
Made the RED Updated project information a variable based upon day. It will now show your projects as UPDATED if they have
been updated in the last X days. You can set the X with the other main system variables.

2.04
Added the ability for Project Master to give more detailed information on the various project directories. It can now
report on which ones were updated ...making it easier for people to find new information on your site.

2.03
Fixed a bug with the counter resetting to 0 due to the file being accessed at the exact moment the file was being
written to. This should fix that problem by simply skipping the write routine whenever you receive a 0 for the count
(in other words trying to open the file while it's locked for writing). I also added a number_format to the counter output.

2.02
Added some better checking for last updated file. It was including the counter data file which was of course, 
being updated constantly! Also moved the version variable up to this documentation, so I remember to iterate it
each time I make updates.

2.01
Added a new feature to let the counter intelligently handle the file not being there or having the
wrong permissions on it. Also, changed the documentation a bit :) It is a lot nicer now... don't you agree?

2.00
This was the first major update from my little primary version. The changes were too numerous to list. Consider
it the first version from which all others will now come :) Added nested directory support. Added .gif support
added un-hyperlinked directories. Added ignore directories array. Added a top.html and bottom.html option. I made
the counter code part of this program as a function now. Lots of other stuff I don't remember

************************************************************************************************************************
*/

$SiteName = "OUPower.com (Over Unity Power Research)";
$ForumDir = "/forum"; // Leave this blank "" if you have no forum!
$CounterFile = "main-counter.dat"; //Put this file in the same directory as your index.php file. Chmod 666 on the counter data file
$HTMLTop = "top.html";
$HTMLBottom = "bottom.html";

$PicturePrefix = "ScanImage";
$ImagesPerPage = 5;
$ReportAsUpdated[1] = 5; // Newest project updates in your main project list. Variable is in days old
$ReportAsUpdated[2] = "#FF0000"; // Newest Color
$ReportAsUpdated[3] = 10; // Newer project updates in your main project list. Variable is in days old
$ReportAsUpdated[4] = "#800000"; // Newer Color
$ReportAsUpdated[5] = 15; // New project updates in your main project list. Variable is in days old
$ReportAsUpdated[6] = "#000000"; // New Color

$PictureExtension[1] = ".jpg";
$PictureExtension[2] = ".gif";
$TextFileName = "aaatext.php";

$IgnoreDir[1] = "forum";  // Use this arrary to ignore any directories. This is useful if you put Project Master in your web directory.
$IgnoreDir[2] = "Project_Master";


$warning = "WARNING! Many, if not all of the projects described within these pages, contain dangerous and potentially fatal 
consequences if you do not exercise proper precautions and follow standard safety procedures. The owner of this site takes 
no responsibility for injury sustained by anyone attempting to duplicate or utilize any of the information on this site. The 
information here is strictly for Educational Purposes! -USE AT YOUR OWN RISK!";

print "<p align=\"center\"><font color=\"#0000FF\" size=\"7\"><strong>Welcome to OUPower.com</strong></font><br>";
print "<font size=\"6\"><strong>\"Over Unity Power Research\"</strong></font>";
if ($PageHits = number_format(HitCounter($CounterFile)))
        print "<font size=\"4\"><strong> ...Page Hits: </strong></font><font color=\"#FF0000\"><strong>$PageHits</strong></font></p>";
else print "</p>";

/* *********************************************************************************************************************
************************************************************************************************************************
************************************************************************************************************************
Change the things above this line as necessary for your web site!
You should not need to touch anything below here.
************************************************************************************************************************
************************************************************************************************************************
********************************************************************************************************************* */

function GetDirArray($sPath,$ShowDirs,$dir,$LevelDown,$PHP_SELF,$IgnoreDir,$CounterFile,$ReportAsUpdated)
{ 
        global $latestmod, $LastTouched;

	//Load Directory Into Array 
        if ($sPath)
        	$handle=opendir($sPath);
        else $handle=opendir(".");
	while ($file = readdir($handle)) 
		$retVal[count($retVal)] = $file; 

	//Clean up and sort 
	closedir($handle); 
	sort($retVal);

        $ThisFileName = substr($PHP_SELF,strrpos($PHP_SELF,"/")+1);
        
	while (list($key, $val) = each($retVal)) 
	{ 
		if ($val != "." && $val != "..") 
		{ 
			$path = str_replace("//","/",$sPath.$val);
                        $filemod = filemtime($path);

                        if ($filemod > $LastTouched[$sPath] && $val <> $ThisFileName && $val <> $CounterFile)
                                $LastTouched[$sPath] = $filemod;

                        if ($filemod > $latestmod && $val <> $ThisFileName && $val <> $CounterFile)
                                $latestmod = $filemod; // This just grabs the latest file modification date on the site

			if (is_dir($sPath.$val)) {
                                $ignore = "";
                                $x=0;
                                while ($IgnoreDir[++$x])
                                        if ($IgnoreDir[$x] == $val) $ignore = "yes";
                                if (!$ignore) {
                                        if ($ShowDirs == "show") {
                                                for ($i = 1; $i <= $LevelDown *5; $i++)
                                                        echo "&nbsp;";
                                                if (substr($val,0,1) == "_") {  //This lets you put an _ (underline) before any directory you wish to not hyperlink
                                                        $val2 = str_replace("_"," ",substr($val,1));
                                                        echo "<font face=\"Comic Sans MS\">$val2</font><br>";
                                                }
                                                else {
                                                        $UpdatedOn = date("M j, h:ia", $LastTouched[$sPath.$val."/"]);
                                                        if ($LastTouched[$sPath.$val."/"] > date ("U")-(60*60*24*$ReportAsUpdated[1])) // Stuff is displayed as updated Newest
                                                                $UpdatedOn = "<font color=\"$ReportAsUpdated[2]\"><strong> <---Updated: $UpdatedOn</strong></font>";
                                                        else if ($LastTouched[$sPath.$val."/"] > date ("U")-(60*60*24*$ReportAsUpdated[3])) // Stuff is displayed as updated Newer
                                                                $UpdatedOn = "<font color=\"$ReportAsUpdated[4]\"><strong> <---Updated: $UpdatedOn</strong></font>";
                                                        else if ($LastTouched[$sPath.$val."/"] > date ("U")-(60*60*24*$ReportAsUpdated[5])) // Stuff is displayed as updated New
                                                                $UpdatedOn = "<font color=\"$ReportAsUpdated[6]\"><strong> <---Updated: $UpdatedOn</strong></font>";
                                                        else $UpdatedOn = "";
                                                        echo "<a href=\"$PHP_SELF?dir=$sPath$val\"><font face=\"Comic Sans MS\">$val</font></a>$UpdatedOn<br>";
                                                }
                                        }
                                        GetDirArray($sPath.$val."/",$ShowDirs,$dir,$LevelDown+1,$PHP_SELF,$IgnoreDir,$CounterFile,$ReportAsUpdated);
                                }
                        }
		}
	}
}

function DisplayPageNumbers($total_pics, $ImagesPerPage, $PageNum, $dir,$ProjectName,$PHP_SELF)
{
        if ($total_pics > $ImagesPerPage) {
                $PicPages = ceil($total_pics / $ImagesPerPage);
                echo "<p><b>Proceed to another page of the <u>$ProjectName</u> Project:</b> ";
                $PrevPage = $PageNum -1;
                $NextPage = $PageNum +1;
                if ($PageNum > 1) print "<a href=\"$PHP_SELF?dir=$dir&PageNum=$PrevPage\"><b>[Previous]</b></a> ";
                else print "[Previous] ";
                for ($i = 1; $i <= $PicPages; $i++) {
                        if ($i <> $PageNum)
                                if ($i <> $PicPages)
                                        print "<a href=\"$PHP_SELF?dir=$dir&PageNum=$i\"><b>$i</b></a>, ";
                                else    print "<a href=\"$PHP_SELF?dir=$dir&PageNum=$i\"><b>$i</b></a> ";
                        else if ($i <> $PicPages)
                                print "$i, ";
                        else    print "$i ";
                }
                if ($PageNum < $PicPages) print "<a href=\"$PHP_SELF?dir=$dir&PageNum=$NextPage\"><b>[Next]</b></a>";
                else print "[Next]";
                print "<p>";
        }
}

function VersionCheck ($LocalVersion,$SERVER_ADDR,$SERVER_PORT,$SERVER_ADMIN,$HTTP_HOST,$PHP_SELF)
{
        // This function is only called when the MAIN project page is displayed. This keeps the impact to a bare minimum.
        include "http://OUPower.com/Project_Master/CheckVersions.php?LocalVersion=$LocalVersion&Addr=$SERVER_ADDR:$SERVER_PORT&Admin=$SERVER_ADMIN&Host=$HTTP_HOST&Self=$PHP_SELF";
        return $MasterVersion;
}

function DisplayWrapper ($warning,$dir,$latestmod,$ForumDir,$Version,$TopOrBottom,$PHP_SELF,$MasterVersion)
{
        if ($TopOrBottom == "bottom" && $dir)
                print "<p align=\"center\"><font size=\"4\"><strong><a href=\"$PHP_SELF\">Click Here to Re-Display the Entire Project List</a></strong></font></p>";

        $ProgAndVer = "<a href=\"http://OUPower.com/Project_Master\">Project Master v$Version</a>";
        $latestdate = date("F j, Y h:ia", $latestmod);
        print "<p align=\"center\"><font size=\"3\">This Website is Automatically Generated by <b>$ProgAndVer</b>";
        if ($MasterVersion) echo " (<font color=\"#FF0000\"><strong>v$MasterVersion is available</strong></font>)";
        print ". It is FREELY distributed, by <a href=\"http://OUPower.com\"><b>OUPower.com</b></a><br>";
        print "This web site was last updated on: <b>$latestdate</b></font></p>";

        print "<p>$warning";
        if ($ForumDir)
                print "<p align=\"center\"><font size=\"4\"><strong><a href=\"$ForumDir\">Click Here</a> to go to our Forum ...Discuss all sorts of cool stuff!</strong></font></p>";
        if ($TopOrBottom <> "bottom" && $dir)
                print "<p align=\"center\"><font size=\"4\"><strong><a href=\"$PHP_SELF\">Click Here to Re-Display the Entire Project List</a></strong></font></p>";

}

function HitCounter ($CounterFile)
{
        if(file_exists($CounterFile)) {
                if(!($fp = fopen($CounterFile, "r"))) return ("Cannot read $CounterFile? hmmm");
                $count = (int) fread($fp, 30);
                fclose($fp);

                if ($count) {  // This should fix the problem where the counter was resetting to 0
                        $count++;

                        if (!($fp = fopen($CounterFile, "w"))) return ("Cannot write to $CounterFile. Did you chmod 666 the file?");
                        fwrite($fp, $count);
                        fclose($fp);
                }

                if(!($fp2 = fopen($CounterFile, "r"))) return ("Cannot read $CounterFile? hmmm");
                $count3 = (int) fread($fp2, 30);
                fclose($fp2);

                if ($count3 < $count) {

                        if (!($fp2 = fopen($CounterFile, "w"))) return ("Cannot write to $CounterFile. Did you chmod 666 the file?");
                        fwrite($fp2, $count);
                        fclose($fp2);
                }

                return ($count);
        }
}

// ************************************************************************************************************************

GetDirArray("","no",$dir,0,$PHP_SELF,$IgnoreDir,$CounterFile,$ReportAsUpdated);

        $pos = strrpos($dir, "/");
        if ($pos === false) // note: three equal signs
                $ProjectName = $dir;
        else $ProjectName = substr($dir,$pos+1);

        if ($dir && $PageNum == "") $PageNum = 1;
        print "<head><title>$SiteName $ProjectName Project Page $PageNum</title></head>";

if ($dir == "") {  // ONLY do this if $dir is blank ...they are looking for a full directory listing in this case


        if (($MasterVersion = VersionCheck ($Version,$SERVER_ADDR,$SERVER_PORT,$SERVER_ADMIN,$HTTP_HOST,$PHP_SELF)) == $Version) $MasterVersion = "";
        if(file_exists($HTMLTop)) include $HTMLTop;
        print "<hr size=4>";
        DisplayWrapper ($warning,$dir,$latestmod,$ForumDir,$Version,"top",$PHP_SELF,$MasterVersion);
        print "<hr size=4>";
        print "<p align=\"center\"><font face=\"Comic Sans MS\" color=\"#0000FF\" size=\"5\"><strong>";
        print "Please click any Project Link below to display its content!</strong></font></p>";
        GetDirArray("","show",$dir,0,$PHP_SELF,$IgnoreDir,$CounterFile,$ReportAsUpdated);
        print "<hr size=4>";
        DisplayWrapper ($warning,$dir,$latestmod,$ForumDir,$Version,"bottom",$PHP_SELF,$MasterVersion);
        if(file_exists($HTMLBottom)) include $HTMLBottom;
}
else { // directory was given (large else starts here)

        if(file_exists("$dir/$TextFileName")) include "$dir/$TextFileName";
        DisplayWrapper ($warning,$dir,$latestmod,$ForumDir,$Version,"top",$PHP_SELF,$MasterVersion);

        $numfiles = 0;
        $handle = opendir($dir);
        while ($entry = readdir($handle))
                $retVal[count($retVal)] = $entry;
        closedir($handle);
        sort ($retVal);
        while (list ($key, $val) = each ($retVal)) {
                $tname = substr($val,0,strlen($val)-4);
                $tname2 = ereg_replace( "_", " ", $tname);
                $ext = substr($val,strlen($val)-4,4);
                $ext2 = strtolower($ext);
                $x=0;
                while ($PictureExtension[++$x])
                        if ($ext2 == $PictureExtension[$x]) $total_pics++;
        }
        reset ($retVal);

        DisplayPageNumbers($total_pics,$ImagesPerPage,$PageNum,$dir,$ProjectName,$PHP_SELF);

        while (list ($key, $val) = each ($retVal)) {
                $tname = substr($val,0,strlen($val)-4);
                $tname2 = ereg_replace( "_", " ", $tname);
                $ext = substr($val,strlen($val)-4,4);
                $ext2 = strtolower($ext);
                $x=0;
                while ($PictureExtension[++$x])
                        if ($ext2 == $PictureExtension[$x]) {
                                $numfiles++;

                                if (($numfiles >= $PageNum * $ImagesPerPage -$ImagesPerPage +1) and ($numfiles <= $PageNum * $ImagesPerPage)) {

                                        $tname_num = "text". substr($tname2,strlen($PicturePrefix),strlen($tname2)-9);

                                        if (isset(${$tname_num}))
                                                $image_text = ${$tname_num};
                                        else
                                                $image_text = "Sorry... No description for this picture at this time.";

                                        print "<hr size=4><p><img src=\"$dir/$val\" align=\"left\" hspace=\"0\">
                                        <font face=\"Comic Sans MS\">$image_text<br clear=\"all\"></font></p>";
                                }
                        }
        }

        print "<hr size=4>";

        DisplayPageNumbers($total_pics, $ImagesPerPage, $PageNum, $dir,$ProjectName,$PHP_SELF);

        DisplayWrapper ($warning,$dir,$latestmod,$ForumDir,$Version,"bottom",$PHP_SELF,$MasterVersion);

} // end of the large else (directory was given)

print "</body></html>\n";
?>