Minor refactoring

git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@170 b3834d28-1941-0410-a4f8-b48e95affb8f
This commit is contained in:
mensonge 2008-11-21 11:22:40 +00:00
parent 5db18a09c4
commit 9d22fdc36f
3 changed files with 71 additions and 70 deletions

View file

@ -68,13 +68,14 @@ $dtend = date('Y-m-d H:i:s', strtotime('tomorrow'));
$tplVars['page'] = $page; $tplVars['page'] = $page;
$tplVars['start'] = $start; $tplVars['start'] = $start;
$tplVars['popCount'] = 30; $tplVars['popCount'] = 30;
//$tplVars['sidebar_blocks'] = array('search', 'users', 'linked', 'recent');
$tplVars['sidebar_blocks'] = $GLOBALS["index_sidebar_blocks"]; $tplVars['sidebar_blocks'] = $GLOBALS["index_sidebar_blocks"];
$tplVars['range'] = 'all'; $tplVars['range'] = 'all';
$tplVars['pagetitle'] = T_('Store, share and tag your favourite links'); $tplVars['pagetitle'] = T_('Store, share and tag your favourite links');
$tplVars['subtitle'] = T_('All Bookmarks'); $tplVars['subtitle'] = T_('All Bookmarks');
$tplVars['bookmarkCount'] = $start + 1; $tplVars['bookmarkCount'] = $start + 1;
$bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, NULL, NULL, NULL, getSortOrder(), NULL, 0, $dtend); $bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, NULL, NULL, NULL, getSortOrder(), NULL, 0, $dtend);
$tplVars['total'] = $bookmarks['total']; $tplVars['total'] = $bookmarks['total'];
$tplVars['bookmarks'] =& $bookmarks['bookmarks']; $tplVars['bookmarks'] =& $bookmarks['bookmarks'];
$tplVars['cat_url'] = createURL('bookmarks', '%1$s/%2$s'); $tplVars['cat_url'] = createURL('bookmarks', '%1$s/%2$s');

View file

@ -1,35 +1,35 @@
<?php <?php
/* Build services */ /* Connect to the database and build services */
class ServiceFactory { class ServiceFactory {
function ServiceFactory(&$db, $serviceoverrules = array()) { function ServiceFactory(&$db, $serviceoverrules = array()) {
} }
function &getServiceInstance($name, $servicedir = NULL) { function &getServiceInstance($name, $servicedir = NULL) {
global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype; global $dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist, $dbtype;
static $instances = array(); static $instances = array();
static $db; static $db;
if (!isset($db)) { if (!isset($db)) {
require_once(dirname(__FILE__) .'/../includes/db/'. $dbtype .'.php'); require_once(dirname(__FILE__) .'/../includes/db/'. $dbtype .'.php');
$db = new sql_db(); $db = new sql_db();
$db->sql_connect($dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist); $db->sql_connect($dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist);
if(!$db->db_connect_id) { if(!$db->db_connect_id) {
message_die(CRITICAL_ERROR, "Could not connect to the database", $db); message_die(CRITICAL_ERROR, "Could not connect to the database", $db);
} }
} }
if (!isset($instances[$name])) { if (!isset($instances[$name])) {
if (isset($serviceoverrules[$name])) { if (isset($serviceoverrules[$name])) {
$name = $serviceoverrules[$name]; $name = $serviceoverrules[$name];
} }
if (!class_exists($name)) { if (!class_exists($name)) {
if (!isset($servicedir)) { if (!isset($servicedir)) {
$servicedir = dirname(__FILE__) .'/'; $servicedir = dirname(__FILE__) .'/';
} }
require_once($servicedir . strtolower($name) . '.php'); require_once($servicedir . strtolower($name) . '.php');
} }
$instances[$name] = call_user_func(array($name, 'getInstance'), $db); $instances[$name] = call_user_func(array($name, 'getInstance'), $db);
} }
return $instances[$name]; return $instances[$name];
} }
} }
?> ?>

View file

@ -1,46 +1,46 @@
<?php <?php
class TemplateService { class TemplateService {
var $basedir; var $basedir;
function &getInstance() { function &getInstance() {
static $instance; static $instance;
if (!isset($instance)) if (!isset($instance))
$instance =& new TemplateService(); $instance =& new TemplateService();
return $instance; return $instance;
} }
function TemplateService() { function TemplateService() {
$this->basedir = $GLOBALS['TEMPLATES_DIR']; $this->basedir = $GLOBALS['TEMPLATES_DIR'];
} }
function loadTemplate($template, $vars = NULL) { function loadTemplate($template, $vars = NULL) {
if (substr($template, -4) != '.php') if (substr($template, -4) != '.php')
$template .= '.php'; $template .= '.php';
$tpl =& new Template($this->basedir .'/'. $template, $vars, $this); $tpl =& new Template($this->basedir .'/'. $template, $vars, $this);
$tpl->parse(); $tpl->parse();
return $tpl; return $tpl;
} }
} }
class Template { class Template {
var $vars = array(); var $vars = array();
var $file = ''; var $file = '';
var $templateservice; var $templateservice;
function Template($file, $vars = NULL, &$templateservice) { function Template($file, $vars = NULL, &$templateservice) {
$this->vars = $vars; $this->vars = $vars;
$this->file = $file; $this->file = $file;
$this->templateservice = $templateservice; $this->templateservice = $templateservice;
} }
function parse() { function parse() {
if (isset($this->vars)) if (isset($this->vars))
extract($this->vars); extract($this->vars);
include($this->file); include($this->file);
} }
function includeTemplate($name) { function includeTemplate($name) {
return $this->templateservice->loadTemplate($name, $this->vars); return $this->templateservice->loadTemplate($name, $this->vars);
} }
} }
?> ?>