<?php
//MPM This program is the same as pressing the "Sync With FatCat" button in the announcements module 
//    for phpWebsite version 0.9.3-4.  The advantage being that you can execute it nightly with your crontab.
//    Author: Mike Majorowicz (http://magicbeandip.com)
//    It's a hack.  

//    Use at your own risk!


//MPM This section is copied from /index.php
$GLOBALS['ALWAYS'] = array("layout""users""language""fatcat""search""menuman""comments");

// Change to TRUE to allow DEBUG mode
define("DEBUG_MODE"FALSE);

/* Show all errors */
//error_reporting (E_ALL);

/* Security against those with register globals = on */
if (isset($_POST)){
  foreach (
$_POST as $postVarName=>$nullIT) {
    unset(
$postVarName);
  }
}

//MPM These 3 lines of code fake the query string so the announcements module is loaded by the core
$_REQUEST=array('module'=>'announce');
$_GET=$_REQUEST;
$_POST=array();

//MPM This section is copied from /index.php
if (!isset($hub_dir)) {
  
$hub_dir NULL;
}

loadConfig($hub_dir);

if (
file_exists($hub_dir "core/Core.php") && file_exists($hub_dir "core/Debug.php") && !preg_match ("/:\/\//i"$hub_dir)) {
  require_once(
$hub_dir "core/Core.php");
} else {
  exit(
"FATAL ERROR! Required file <b>Core.php</b> not found.");
}

if(!isset(
$branchName)) {
  
$branchName NULL;
}

$_SESSION["core"] = new PHPWS_Core($branchName$hub_dir);
$GLOBALS["core"] = &$_SESSION["core"];

$includeList $core->initModules();

if (isset(
$_SESSION["siteHash"]) && $_SESSION["siteHash"] != $core->site_hash){
     
$core->killAllSessions();
     
$_SESSION["siteHash"] = $core->site_hash;
}

// Load module index file
$current_mod_file NULL;

//MPM Copied from mod/announce/index.php
/* Check to see if the manager exists and create it if it doesn't */
if(!isset($_SESSION["SES_ANN_MANAGER"])) {
  
$_SESSION["SES_ANN_MANAGER"] = new PHPWS_AnnouncementManager;
}

//MPM End copied from mod/announce/index.php

//MPM Call PHPWS_AnnouncementManager::syncWithFatCat()
$_SESSION["SES_ANN_MANAGER"]->syncWithFatCat();


// Preventing last mod loaded from being 'current_mod'
$core->current_mod NULL;
$core->db->disconnect();


function 
loadConfig($hub_dir){
  
/* Check for config file and define source directory. */
  
if(file_exists($hub_dir "conf/config.php")){
    if(
filesize($hub_dir "conf/config.php") > 0) {
      include(
$hub_dir "conf/config.php");
      
define("PHPWS_SOURCE_DIR"$source_dir);
    } else {
      
header("location:setup/set_config.php");
      exit();
    }
  }
  else {
    
header("location:setup/set_config.php");
    exit();
  }
}

?>