forked from spotweb/spotweb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Further steps in the removal of dependency on SpotsOveriew and SpotDb
- Loading branch information
spotweb
committed
Jul 3, 2012
1 parent
1a74065
commit 869d4a9
Showing
55 changed files
with
3,184 additions
and
2,991 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
<?php | ||
define('SPOTWEB_SETTINGS_VERSION', '0.24'); | ||
define('SPOTWEB_SECURITY_VERSION', '0.29'); | ||
define('SPOTDB_SCHEMA_VERSION', '0.58'); | ||
define('SPOTWEB_VERSION', '0.' . (SPOTDB_SCHEMA_VERSION * 100) . '.' . (SPOTWEB_SETTINGS_VERSION * 100) . '.' . (SPOTWEB_SECURITY_VERSION * 100)); | ||
|
||
/* | ||
* Spotweb bootstrapping code. | ||
* | ||
* This class will initialize the registry and so other | ||
* related stuff. Is required for all Spotweb related code. | ||
* | ||
*/ | ||
|
||
class Bootstrap { | ||
static private $_dbSettings = null; | ||
|
||
/* | ||
* Boot up the Spotweb system | ||
*/ | ||
public function boot() { | ||
/* | ||
* If we are run from another directory, try to change the current | ||
* working directory to a directory the script is in | ||
*/ | ||
if (@!file_exists(getcwd() . '/' . basename($argv[0]))) { | ||
chdir(dirname(__FILE__)); | ||
} # if | ||
|
||
$daoFactory = $this->getDaoFactory(); | ||
$settings = $this->getSettings($daoFactory); | ||
$spotReq = $this->getSpotReq($settings); | ||
|
||
/* | ||
* Run the validation of the most basic systems | ||
* in Spotweb | ||
*/ | ||
$this->validate($settings); | ||
|
||
/* | ||
* Disable the timing part as soon as possible because it | ||
* gobbles memory | ||
*/ | ||
if (!$settings->get('enable_timing')) { | ||
SpotTiming::disable(); | ||
} # if | ||
|
||
|
||
return array($settings, $daoFactory, $spotReq); | ||
} # boot | ||
|
||
|
||
/* | ||
* Returns the DAO factory used by all of | ||
* Spotweb | ||
*/ | ||
private function getDaoFactory() { | ||
require "dbsettings.inc.php"; | ||
|
||
$dbCon = dbeng_abs::getDbFactory($dbsettings['engine']); | ||
$dbCon->connect($dbsettings['host'], | ||
$dbsettings['user'], | ||
$dbsettings['pass'], | ||
$dbsettings['dbname']); | ||
|
||
$daoFactory = Dao_Factory::getDAOFactory($dbsettings['engine']); | ||
$daoFactory->setConnection($dbCon); | ||
|
||
return $daoFactory; | ||
} # getDaoFactory | ||
|
||
/* | ||
* Returns a sort of pre-flight check to see if | ||
* everything is setup the way we like. | ||
*/ | ||
private function validate(SpotSettings $settings) { | ||
/* | ||
* The basics has been setup, lets check if the schema needs | ||
* updating | ||
*/ | ||
if (!$settings->schemaValid()) { | ||
throw new SchemaNotUpgradedException(); | ||
} # if | ||
|
||
/* | ||
* Does our global setting table need updating? | ||
*/ | ||
if (!$settings->settingsValid()) { | ||
throw new SettingsNotUpgradedException(); | ||
} # if | ||
|
||
/* | ||
* Because users are asked to modify ownsettings.php themselves, it is | ||
* possible they create a mistake and accidentally create output from it. | ||
* | ||
* This output breaks a lot of stuff like download integration, image generation | ||
* and more. | ||
* | ||
* We try to check if any output has been submitted, and if so, we refuse | ||
* to continue to prevent all sorts of confusing bug reports | ||
*/ | ||
if ((headers_sent()) || ((int) ob_get_length() > 0)) { | ||
throw new OwnsettingsCreatedOutputException(); | ||
} # if | ||
} # validate | ||
|
||
/* | ||
* Bootup the settings system | ||
*/ | ||
private function getSettings(Dao_Factory $daoFactory) { | ||
require_once "settings.php"; | ||
return SpotSettings::singleton($daoFactory->getSettingDao(), $settings); | ||
} # getSettings | ||
|
||
/* | ||
* Initializes the NNTP access | ||
*/ | ||
static public function createNntpEngine($type) { | ||
/* | ||
* Retrieve the NNTP header settings we can validate those | ||
*/ | ||
$settings = Registry::get('settings'); | ||
$settings_nntp_hdr = $settings->get('nntp_hdr'); | ||
|
||
/* | ||
* Make sure we have a valid NNTP configuration | ||
*/ | ||
if (empty($settings_nntp_hdr['host'])) { | ||
throw new MissingNntpConfigurationException(); | ||
} # if | ||
|
||
|
||
switch ($type) { | ||
case 'hdr' : return new Service_Nntp_Engine($settings_nntp_hdr); break; | ||
case 'nzb' : { | ||
$settings_nntp_bin = $settings->get('nntp_nzb'); | ||
if (empty($settings_nntp_nzb['host'])) { | ||
return Registry::get('nntp_hdr'); | ||
} else { | ||
return new Service_Nntp_Engine($settings_nntp_nzb); | ||
} # else | ||
} # nzb | ||
|
||
case 'post' : { | ||
$settings_nntp_post = $settings->get('nntp_post'); | ||
if (empty($settings_nntp_post['host'])) { | ||
return Registry::get('nntp_hdr'); | ||
} else { | ||
return new Service_Nntp_Engine($settings_nntp_post); | ||
} # else | ||
} # post | ||
|
||
default : throw new Exception("Unknown NNTP type engine (" . $type . ") for registry creation"); | ||
} # switch | ||
} # initNntpAccess | ||
|
||
/* | ||
* Instantiate an Request object | ||
*/ | ||
private function getSpotReq(SpotSettings $settings) { | ||
$req = new SpotReq(); | ||
$req->initialize($settings); | ||
|
||
return $req; | ||
} # getSpotReq | ||
|
||
} # Bootstrap | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
<?php | ||
class SpotAudit { | ||
private $_db; | ||
private $_user; | ||
private $_settings; | ||
private $_ipaddr; | ||
|
||
function __construct(SpotDb $db, SpotSettings $settings, array $user, $ipaddr) { | ||
$this->_db = $db; | ||
$this->_user = $user; | ||
$this->_settings = $settings; | ||
$this->_ipaddr = $ipaddr; | ||
} # ctor | ||
|
||
function audit($perm, $objectid, $allowed) { | ||
$this->_db->addAuditEntry($this->_user['userid'], $perm, $objectid, $allowed, $this->_ipaddr); | ||
} # audit | ||
|
||
} # class SpotAudit | ||
<?php | ||
class SpotAudit { | ||
private $_auditDao; | ||
private $_user; | ||
private $_settings; | ||
private $_ipaddr; | ||
|
||
function __construct(Dao_Audit $auditDao, SpotSettings $settings, array $user, $ipaddr) { | ||
$this->_auditDao = $auditDao; | ||
$this->_user = $user; | ||
$this->_settings = $settings; | ||
$this->_ipaddr = $ipaddr; | ||
} # ctor | ||
|
||
function audit($perm, $objectid, $allowed) { | ||
$this->_auditDao->addAuditEntry($this->_user['userid'], $perm, $objectid, $allowed, $this->_ipaddr); | ||
} # audit | ||
|
||
} # class SpotAudit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.