add $db_port to .htconfig.php and $a->config['syste]['smarty3_folder'] for compiled templates

This commit is contained in:
fabrixxm 2013-05-10 06:13:24 -04:00
parent e1c6b776c4
commit d4c07930d5
7 changed files with 34 additions and 19 deletions

View File

@ -582,7 +582,7 @@ class App {
date_default_timezone_set($this->timezone); date_default_timezone_set($this->timezone);
$this->config = array(); $this->config = array('system'=>array());
$this->page = array(); $this->page = array();
$this->pager= array(); $this->pager= array();

16
include/dba/dba_driver.php Normal file → Executable file
View File

@ -1,15 +1,17 @@
<?php /** @file */ <?php /** @file */
function dba_factory($server,$user,$pass,$db,$install = false) { function dba_factory($server, $port,$user,$pass,$db,$install = false) {
$dba = null; $dba = null;
if(class_exists('mysqli')) { if(class_exists('mysqli')) {
if (is_null($port)) $port = ini_get("mysqli.default_port");
require_once('include/dba/dba_mysqli.php'); require_once('include/dba/dba_mysqli.php');
$dba = new dba_mysqli($server,$user,$pass,$db,$install); $dba = new dba_mysqli($server, $port,$user,$pass,$db,$install);
} }
else { else {
if (is_null($port)) $port = "3306";
require_once('include/dba/dba_mysql.php'); require_once('include/dba/dba_mysql.php');
$dba = new dba_mysql($server,$user,$pass,$db,$install); $dba = new dba_mysql($server, $port,$user,$pass,$db,$install);
} }
return $dba; return $dba;
@ -23,16 +25,16 @@ abstract class dba_driver {
public $connected = false; public $connected = false;
public $error = false; public $error = false;
abstract function connect($server,$user,$pass,$db); abstract function connect($server, $port, $user,$pass,$db);
abstract function q($sql); abstract function q($sql);
abstract function escape($str); abstract function escape($str);
abstract function close(); abstract function close();
function __construct($server,$user,$pass,$db,$install = false) { function __construct($server, $port, $user,$pass,$db,$install = false) {
if(($install) && (! $this->install($server,$user,$pass,$db))) { if(($install) && (! $this->install($server, $port, $user,$pass,$db))) {
return; return;
} }
$this->connect($server,$user,$pass,$db); $this->connect($server, $port, $user,$pass,$db);
} }

4
include/dba/dba_mysql.php Normal file → Executable file
View File

@ -5,8 +5,8 @@ require_once('include/dba/dba_driver.php');
class dba_mysql extends dba_driver { class dba_mysql extends dba_driver {
function connect($server,$user,$pass,$db) { function connect($server, $port, $user,$pass,$db) {
$this->db = mysql_connect($server,$user,$pass); $this->db = mysql_connect($server.":".$port,$user,$pass);
if($this->db && mysql_select_db($db,$this->db)) { if($this->db && mysql_select_db($db,$this->db)) {
$this->connected = true; $this->connected = true;
} }

4
include/dba/dba_mysqli.php Normal file → Executable file
View File

@ -4,8 +4,8 @@ require_once('include/dba/dba_driver.php');
class dba_mysqli extends dba_driver { class dba_mysqli extends dba_driver {
function connect($server,$user,$pass,$db) { function connect($server, $port, $user,$pass,$db) {
$this->db = new mysqli($server,$user,$pass,$db); $this->db = new mysqli($server,$user,$pass,$db, $port);
if(! mysqli_connect_errno()) { if(! mysqli_connect_errno()) {
$this->connected = true; $this->connected = true;
} }

View File

@ -21,9 +21,11 @@ class FriendicaSmarty extends Smarty {
$template_dirs = $template_dirs + array('base' => 'view/tpl/'); $template_dirs = $template_dirs + array('base' => 'view/tpl/');
$this->setTemplateDir($template_dirs); $this->setTemplateDir($template_dirs);
$this->setCompileDir('view/tpl/smarty3/compiled/'); $basecompiledir = $a->config['system']['smarty3_folder'];
$this->setConfigDir('view/tpl/smarty3/config/');
$this->setCacheDir('view/tpl/smarty3/cache/'); $this->setCompileDir($basecompiledir.'/compiled/');
$this->setConfigDir($basecompiledir.'/config/');
$this->setCacheDir($basecompiledir.'/cache/');
$this->left_delimiter = $a->get_template_ldelim('smarty3'); $this->left_delimiter = $a->get_template_ldelim('smarty3');
$this->right_delimiter = $a->get_template_rdelim('smarty3'); $this->right_delimiter = $a->get_template_rdelim('smarty3');
@ -46,9 +48,16 @@ class FriendicaSmartyEngine implements ITemplateEngine {
static $name ="smarty3"; static $name ="smarty3";
public function __construct(){ public function __construct(){
if(!is_writable('view/tpl/smarty3/')){ $a = get_app();
echo "<b>ERROR:</b> folder <tt>view/tpl/smarty3/</tt> must be writable by webserver."; killme(); $basecompiledir = $a->config['system']['smarty3_folder'];
if (!$basecompiledir) $basecompiledir = dirname(__dir__)."/view/tpl/smarty3";
if (!is_dir($basecompiledir)) {
echo "<b>ERROR:</b> folder <tt>$basecompiledir</tt>does not exixst."; killme();
}
if(!is_writable($basecompiledir)){
echo "<b>ERROR:</b> folder <tt>$basecompiledir</tt> must be writable by webserver."; killme();
} }
$a->config['system']['smarty3_folder'] = $basecompiledir;
} }
// ITemplateEngine interface // ITemplateEngine interface

4
index.php Normal file → Executable file
View File

@ -39,8 +39,8 @@ $a->language = get_best_language();
require_once("include/dba/dba_driver.php"); require_once("include/dba/dba_driver.php");
if(! $install) { if(! $install) {
$db = dba_factory($db_host, $db_user, $db_pass, $db_data, $install); $db = dba_factory($db_host, $db_port, $db_user, $db_pass, $db_data, $install);
unset($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_port, $db_user, $db_pass, $db_data);
/** /**
* Load configs from db. Overwrite configs from .htconfig.php * Load configs from db. Overwrite configs from .htconfig.php

4
install/htconfig.sample.php Normal file → Executable file
View File

@ -13,10 +13,14 @@
// Then set the following for your MySQL installation // Then set the following for your MySQL installation
$db_host = 'your.mysqlhost.com'; $db_host = 'your.mysqlhost.com';
$db_port = null; #leave null for default or set your port
$db_user = 'mysqlusername'; $db_user = 'mysqlusername';
$db_pass = 'mysqlpassword'; $db_pass = 'mysqlpassword';
$db_data = 'mysqldatabasename'; $db_data = 'mysqldatabasename';
// smarty3 compile dir. make sure is writable by webserver
$a->config['system']['smarty3_folder'] = "view/tpl/smart3";
// Choose a legal default timezone. If you are unsure, use "America/Los_Angeles". // Choose a legal default timezone. If you are unsure, use "America/Los_Angeles".
// It can be changed later and only applies to timestamps for anonymous viewers. // It can be changed later and only applies to timestamps for anonymous viewers.