Thanks Evert 
I would be happy to further the development of Jobberbase, in true open source fashion. I just finished setting up the current SVN jobberbase in a local environment. I noticed some interesting improvements. A table for site settings and such, good idea!
As I mentioned previously some work would be necessary to merge the different branches of code. Our config.php handles the environment a lot differently. We use a local, QA, and prod environment.
One of the first things I should probably contribute, and since Chronos asked, is the cron features we have implemented. This should be simple to roll into the current branch.
First we have cron_config.php to set up the server environment. We do this because when running php from the command line, which is how cron executes your script, there is no browser setting all the system variables. This is the reason your cron jobs in their original release did not work too well.
Code:<?php
/*
* set up an environment for cron jobs so they can run more like they're being served from a server.
* do things different for dev / production environments
*
* @param environment - takes on parameter on the command line, a string. prod or dev. defaults to prod!
*/
if(!isset($argv[1]))
define('CRON_ENV', 'prod');
else
define('CRON_ENV', $argv[1]);
/*set web-server dependencies on location necessary to automate the cron job*/
/*Our team uses vhosts like jobshouts.local since we have more than one site running on our dev hardware you can easily substitute this for localhost.
switch(CRON_ENV){
case 'dev':
$_SERVER['SERVER_NAME']='mysite.local'; /* OR 'localhost' */
break;
case 'qa':
$_SERVER['SERVER_NAME'] = 'subdomain.mysite.com';
break;
case 'prod':
default:
$_SERVER['SERVER_NAME']='mysite.com';
}
$_SERVER['HTTP_HOST'] = $_SERVER['SERVER_NAME'];
$_SERVER['REQUEST_URI'] = '';
$_SERVER['SERVER_PORT'] = 80;
$_SERVER['SCRIPT_NAME'] = '/'. basename($argv[0]);
Next we have the actual script we call from the cron tab in your cpanel, plesk etc. file: cron_maintenance.php
Code:
<?php
/**
* JobShouts Job Board and Search Engine
*
*/
require_once 'cron_config.php'; //sets up environment
require_once 'config.php';
require_once '_includes/class.Maintenance.php';
require_once '_includes/class.Postman.php';
$janitor = new Maintenance();
// delete temporary posts older than 2 days
$janitor->DeleteTemporaryJobs();
// deactivate jobs older than 30 days + delete jobs older than 60 days.
$janitor->DeactivateJobs();
// delete jobs older than 60 days.
$janitor->DeleteOldJobs();
// delete applications after 30 days. prevents them showing up on home page in popular jobs after job expiration.
$janitor->DeleteOldApps();
?>
Finally we execute all cron function inside the class.Maintenance.php. There are some settings here for emailing job posters to let them know the ad is expiring. The constant declarations can be adjusted to suit ones need and could easily be a part of the site settings table.
Code:
<?php
/**
* JobShouts Job Board and Search Engine
*
*
*
* Maintenance class handles site/database maintenance operations
*/
class Maintenance
{
function __construct()
{ }
// delete temporary posts older than 2 days
public function DeleteTemporaryJobs()
{
global $db;
$sql = 'DELETE FROM jobs WHERE DATEDIFF(NOW(), created_on) > 1 AND is_temp = 1 AND is_active = 0';
$db->Execute($sql);
}
public function DeactivateJobs()
{
$postMan = new Postman();
global $db;
$notifmin = 28; //the day when you want notification to be sent prior to the ad expiring
$notifmax = 30; //the day the ad actually expires
$dayscount = $notifmax - $notifmin;
$sql = 'SELECT * FROM jobs WHERE DATEDIFF(NOW(), created_on) = '. $notifmin. ' AND is_active = 1';
$row = $db->QueryArray($sql);
#print_r($row); // this will print the array of the ad that was deactivated
foreach ( $row as $rows )
{
$ademail = trim(strtolower($rows['poster_email']));
$adname = trim($rows['title']);
$adcomp = trim($rows['company']);
$adurl = BASE_URL . "job/" . $rows['id'] . "/";
//$postMan->MailExpiringAd($ademail, $adname, $adcomp, $adurl, $dayscount);
}
/**
* that finishes up notify the expiring ones. Now, lets delete the old ones
*/
$sql = 'update jobs set is_active = 0 WHERE DATEDIFF(NOW(), created_on) >= ' . $notifmax . ' AND is_active = 1';
$db->query($sql);
}
public function DeleteOldJobs()
{
global $db;
$sql = 'DELETE FROM jobs WHERE DATEDIFF(NOW(), created_on) > 60';
$db->Execute($sql);
}
public function DeleteOldApps()
{
global $db;
$sql = 'DELETE FROM jobs_applications WHERE DATEDIFF(NOW(), created_on) > 30';
$db->Execute($sql);
}
}
?>
That's about it I believe. From the cron_config.php you can see how we use a case switch statement to set up the environment. We also have taken this approach in config.php as well. Setting up different databases for development. Using a QA subdomain on the actual production server allows us to make sure the code will run the same in production as in the local dev environment before commiting our changes to our production server.
jobshouts.com A Jobberbased Derivative