• Welcome Visitor! Please take a few seconds and Register for our forum. Even if you don't want to post, you can still 'Like' and react to posts.

Any php programers here??


And this is why I got out of IT. Good luck Jim.
 
Can I just suggest moving the majority of the site to a CMS like Concrete5? It will give you much better markup (cleaner and faster code) and make your life easier with in site editing, plus you could give server staff access to editing pages like the tech library, so you wouldn't hold the burden to do it all yourself.


Another option for the tech library would be setting up a "wiki" to have even greater freedom as to who and what can get added to the tech library.

If you want play with concrete5 I can will gladly host a fresh install for you to mess with, I personally really like it.

I don't want to use a database.
 
Yes. The only part of this site that runs slow is the forum, and it's because of the database. Plus, it can be a pain moving a site to the new server when it involves a database. If you have a database error it can be a nightmare.

I think it would be safer to have a site with individual php pages that called on a header/footer php where you could update the header/footer on the whole site by simply changing the header or footer php pages.
 
Yes. The only part of this site that runs slow is the forum, and it's because of the database. Plus, it can be a pain moving a site to the new server when it involves a database. If you have a database error it can be a nightmare.

I think it would be safer to have a site with individual php pages that called on a header/footer php where you could update the header/footer on the whole site by simply changing the header or footer php pages.

Okay, I was just throwing that option out there since it would make it much easier to maintain.

The code from the pages you have now is so backwards I am pretty much trying to rebuild the file from scratch, so its taking longer than I was hoping :/
 
Databases are fast. Extremely fast. You can't blame that on database issue. The issue is the programming and amounts of data that exist in it. Basic databases are also very easy to backup and replace, it's ones with triggers and a bunch of features that you run into problems with. 600 entries with an indexed ID field, with text column of page content is "peanuts." Programmers get too personal, and can wreck a project by trying to over do things the way they want it done. This is where a lot of slowness comes into play. We lose focus on the actual goal, and writing something the way we perceive it to be done becomes that goal. Like trying to get this site validated against W3C standards, this site was built in 1999, right? You're looking at having this thing completely re-written from scratch to pass validation. There's nothing really wrong, not unless it bothers you that it doesn't pass the latest and greatest W3C standards, browsers will always natively support the way things were done then.

I am by no means a PHP programmer, but here is to get you started. I only matched up to the footer, I wasn't sure how much of the header you wanted replaced. I mostly work in Perl, but not much different. Put the path in $path_to_html_files variable to do the global replace. This script outputs a corresponding php file, eg if it reads in 4cylinder.html, it outputs 4cylinder.php.

I would recommend commenting out the break & file write, and adding in some echos so that you can verify that my pattern matching is working on ALL of the pages. Once everything looks good, then add the write back in.

<?php include "footer.php"; ?> will need manipulated to match the path of where the footer resides. This is a physical path, not a web path.

PHP:
#!/usr/bin/php
<?php

$path_to_html_files = "PUT YOUR PATH IN HERE";

$files = traverse_html($path_to_html_files);

foreach ($files as $file)
{
	echo "Loading $file.\n";

	$stream = fopen($file, "r");
	$contents = fread($stream, filesize($file));
	fclose($stream);

	if ($contents)
	{
		$new_contents = $contents;
		$matches = array();

		/*
		$header_hook = '';

		if (matches header)
		{
			$new_contents = str_replace($matches[0], '<?php include "header.php"; ?>', $new_contents);
		}
		*/

		$footer_hook = 'Ranger Station is in no way affiliated with the Ford Motor';
		$footer_hook = preg_replace('/\s+/', '\s+', $footer_hook);

		if (preg_match('/<table((?!\/table).)*' . $footer_hook . '.*?<\/table>/sx', $contents, $matches))
		{
			$new_contents = str_replace($matches[0], '<?php include "footer.php"; ?>', $new_contents);
		}

		$php_file = preg_replace('/\.html$/', '.php', $file);

		$stream = fopen($php_file, 'w');
		fwrite($stream, $new_contents);
		fclose($stream);
	}
	else
	{
		echo "!!! $file did not read any data!! \n";
	}

	break; // Remove this to make this global, bails after first html file.
}

function traverse_html($dir)
{
	$dir   = escapeshellcmd($dir);
	$files = glob("$dir/*.html");

	foreach (glob("$dir/{.[^.]*,*}", GLOB_BRACE|GLOB_ONLYDIR) as $sub)
	{
		$files = array_merge($files, traverse_html($sub));
	}

	return $files;
}

?>

Edit:

I would consider putting another match in there, right after it finds a match for the footer; maybe for legal.html or some other element of the footer in case the text 'Ranger Station is in no way affiliated with the Ford Motor' exists elsewhere in the page content.
 
Last edited:

Sponsored Ad


Sponsored Ad

TRS Events

Member & Vendor Upgrades

For a small yearly donation, you can support this forum and receive a 'Supporting Member' banner, or become a 'Supporting Vendor' and promote your products here. Click the banner to find out how.

Recently Featured

Want to see your truck here? Share your photos and details in the forum.

Ranger Adventure Video

TRS Merchandise

Follow TRS On Instagram

TRS Sponsors


Sponsored Ad


Sponsored Ad


Amazon Deals

Sponsored Ad

Back
Top