*/
static function isError($value)
{
- return is_object($value) && is_a($value, 'DB_Error');
+ return is_object($value) && is_a($value, 'DB_Error');
}
// }}}
* @return string the error message or false if the error code was
* not recognized
*/
+
static function errorMessage($value)
{
static $errorMessages;
$parsed['dbsyntax'] = $str;
}
- if (!count($dsn)) {
+ /*
+ if (!count($dsn)) {
+ return $parsed;
+ }
+ }*/
+
+ if (is_null($dsn)){
return $parsed;
}
+
// Get (if found): username and password
// $dsn => username:password@protocol+hostspec/database
if (($at = strrpos($dsn,'@')) !== false) {
$parsed['database'] = rawurldecode($dsn);
} else {
// /database?param1=value1¶m2=value2
- $parsed['database'] = rawurldecode(substr($dsn, 0, $pos));
+ $parsed['database'] = rawurldecode(substr($dsn, 0, $pos));
$dsn = substr($dsn, $pos + 1);
if (strpos($dsn, '&') !== false) {
$opts = explode('&', $dsn);
* defined, and means that we deal with strings and array in the same
* manner. */
$dsnArray = DB::parseDSN($dsn);
-
+
if ($hidePassword) {
$dsnArray['password'] = 'PASSWORD';
}
if (is_string($dsn) && strpos($dsn, 'tcp') === false && $dsnArray['protocol'] == 'tcp') {
$dsnArray['protocol'] = false;
}
-
+
// Now we just have to construct the actual string. This is ugly.
$dsnString = $dsnArray['phptype'];
if ($dsnArray['dbsyntax']) {
$dsnString .= ':'.$dsnArray['port'];
}
$dsnString .= '/'.$dsnArray['database'];
-
+
/* Option handling. Unfortunately, parseDSN simply places options into
* the top-level array, so we'll first get rid of the fields defined by
* DB and see what's left. */
return $dsnString;
}
-
+
// }}}
}
//
// $Id: Page.php,v 1.5 2003/02/22 01:52:50 alan Exp $
//
-// A Base Page Class for use with HTML_Template_Flexy
+// A Base Page Class for use with HTML_Template_Flexy
// You could write one of these which used another template engine.
//
*
*
*/
+if (PHP_MAJOR_VERSION >= 7) {
+ set_error_handler(function ($errno, $errstr) {
+ return strpos($errstr, 'Declaration of') === 0;
+ }, E_WARNING);
+}
+
class HTML_FlexyFramework_Page {
-
-
+
+
/**
* the main Template name (which can include a body template)
*
* @var string template name
* @access public
*/
- var $masterTemplate = "master.html";
+ var $masterTemplate = "master.html";
/**
* the body Template name
*
* @access public
*/
var $template = "error.html";
-
-
-
-
+
+
+
+
/**
- * cache method -
+ * cache method -
* can be 'output', or 'data'
* used to set a default caching method
*
* @see getCache()
*/
var $cacheMethod = '';
-
-
-
-
+
+
+
+
/**
* cache store (PEAR's Cache Object Instance
* initialized at start
* @access private
* @see getCache()
*/
-
- var $_cache = NULL;
-
+
+ var $_cache = NULL;
+
/* ---- Variables set by Page loader -------- */
-
-
-
+
+
+
/**
* baseURL, that can be prefixed to URL's to ensure that they correctly relate to application
* (set by page loader)
* @var string
* @access public
*/
- var $baseURL;
+ var $baseURL;
/**
* rootURL, the base installation directory - can be used to get images directories.
* (set by page loader)
* @var string
* @access public
*/
- var $rootURL;
+ var $rootURL;
/**
* rootDir, the base installation directory - can be used to find relative files.
* (set by page loader)
* @var string
* @access public
*/
- var $rootDir;
+ var $rootDir;
/**
* the full request string used by the getCacheID().
* (set by page loader)
var $request; // clean page request for page
/**
* overrides for elements.
- *
+ *
* @var array
* @access public
*/
var $elements = array(); // key=>HTML_Template_Flexy_Element
-
+
/**
* errors for elements
- *
+ *
* @var array
* @access public
*/
var $errors = array(); // key(element name)=>error message
-
-
-
+
+
+
/**
* Arguments from cli if static $cli_opts is used.
- *
+ *
* @var array
* @access public
*/
var $cli_args = array(); // key(element name)=>error message
-
+
/**
* Reference to the page loader
- * @var type HTML_FlexyFramework -
- *
+ * @var type HTML_FlexyFramework -
+ *
*/
-
+
var $bootLoader = false;
-
-
-
+
+
+
/**
* The default page handler
* by default relays to get(), or post() methods depending on the request.
*
* Override this if you do not handle get or post differently.
- *
- *
+ *
+ *
* @param string request, the remainder of the request not handled by the object.
*
* @return none|string none = handled, string = redirect to another page = eg. data/list
* @access public
*/
-
- function start($request,$isRedirect=false,$args=array())
- {
+
+ function start($request,$isRedirect=false,$args=array())
+ {
$cli= HTML_Flexyframework::get()->cli;
if (!$cli && !$isRedirect && !empty($_SERVER["REQUEST_METHOD"]) && $_SERVER["REQUEST_METHOD"] == "POST") {
return $this->post($request,$args);
/**
* The get page handler
*
- * Override this if you want to handle get requests
- *
- *
+ * Override this if you want to handle get requests
+ *
+ *
* @param string request, the remainder of the request not handled by the object.
*
* @return none|string none = handled, string = redirect to another page = eg. data/list
* @access public
*/
- function get($request)
+ function get($request)
{
}
/**
* The post page handler
*
- * Override this if you want to handle get requests
- *
- *
+ * Override this if you want to handle get requests
+ *
+ *
* @param string request, the remainder of the request not handled by the object.
*
* @return none|string none = handled, string = redirect to another page = eg. data/list
* @access public
*/
- function post($request)
+ function post($request)
{
}
/**
* Authentication Check method
* Override this with a straight return for pages that do not require authentication
*
- * By default
+ * By default
* a) redirects to login if authenticaiton fails
* b) checks to see if a isAdmin method exists on the auth object
* if it does see if the user is admin and let them in.
* otherwise access denied error is raised
* c) lets them in.
- *
- *
+ *
+ *
*
* @return none or string redirection to another page.
* @access public
*/
-
+
function getAuth() {
-
-
+
+
return false;
-
+
}
-
-
-
-
+
+
+
+
/**
* The master Output layer.
- *
+ *
* compiles the template
* if no caching - just runs the template.
* otherwise stores it in the cache.
- *
+ *
* you dont normally need to override this.
- *
+ *
* called by the page loader.
* @access public
*/
-
-
-
- function output()
+
+
+
+ function output()
{
-
+
if (!empty($this->cli)) {
return;
}
-
+
/* output the body if no masterTemplate is set */
$options = HTML_FlexyFramework::get();
-
- $type = isset($this->contentType) ? $this->contentType : 'text/html';
+
+ $type = isset($this->contentType) ? $this->contentType : 'text/html';
header('Content-Type: '.$type.';charset='.( empty($options->charset) ? 'UTF-8' : $options->charset ));
-
-
+
+
if (!$this->masterTemplate) {
return $this->outputBody();
}
/* master template */
-
-
+
+
$template_engine = new HTML_Template_Flexy();
$template_engine->compile($this->masterTemplate);
if (!$this->_cache || !$this->cacheMethod) {
$template_engine->outputObject($this,$this->elements);
return;
}
-
+
$id = $this->_cache->generateID($this->getID());
$this->_cache->save($id, $template_engine->bufferedOutputObject($this,$this->elements));
echo $this->_cache->get($id);
-
+
}
/**
* The body Output layer.
- *
+ *
* compiles the template
* At present there is no caching in here.. - this may change latter..
- *
+ *
* used by putting {outputBody} in the main template.
* @access public
- */
+ */
function outputBody() {
$template_engine = new HTML_Template_Flexy();
}
$template_engine->elements = $this->elements;
$template_engine->outputObject($this,$this->elements);
-
+
}
-
-
+
+
/**
* Do any Page Caching if $this->cacheMethod is set.
* You should also look at output caching by overriding the outputBody Method.
* b) POST requests
* c) if sess is set (Eg. if you are using sessions)
* d) useCache is not set in the [Cache] section of the config.
- *
- * utilizes $this->getCacheID() to
+ *
+ * utilizes $this->getCacheID() to
*
* @return none|boolean|string|int|object Description
* @access public|private
* @see see also methods.....
*/
-
-
+
+
function getCache() {
if (!$this->cacheMethod) {
return;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
return;
- }
-
+ }
+
/* lets assume we can cache ourselves.. */
$coptions = PEAR::getStaticProperty('Cache','options');
if (!$coptions) {
return;
}
require_once 'Cache.php';
-
+
$this->_cache = new Cache($coptions['container'], $coptions);
$id = $this->_cache->generateID($this->getCacheID());
if ($_SERVER["REQUEST_METHOD"] == "POST") {
echo $data;
return TRUE;
}
-
+
}
-
+
/**
- * Get a distinct Page Cache ID.
+ * Get a distinct Page Cache ID.
*
* By default this is the full request string
- * override this to define a more precise string
+ * override this to define a more precise string
*
* @return string distinct page id (eg. the request url)
* @access private
*/
-
+
function getCacheID() {
return $this->request;
-
+
}
-
-
+
+
/**
* Utility method : get the Class name (used on templates)
*
* @return string class name
* @access public
*/
-
-
+
+
function getClass() {
return get_class($this);
}
* @return string time in seconds..
* @access public
*/
-
+
function getTime() {
-
+
$m = explode(' ',microtime());
$ff = HTML_FlexyFramework::get();
return sprintf('%0.2fs',($m[0] + $m[1]) - $ff->start)
. '/ Files ' . count(get_included_files());
-
-
+
+
}
/**
* turn on off session - wrap long database queries or
* data processing with this to prevent locking
* @see
* @param int $state new session state - 0 = off, 1 = on
- */
-
+ */
+
function sessionState($state)
- {
+ {
static $ses_status = false;
static $ini = false;
// session status is only php5.4 and up..
if(!function_exists('session_status')){
$ses_status = 1;
} else {
- $ses_status = ($ses_status === false) ? session_status() : $ses_status;
+ $ses_status = ($ses_status === false) ? session_status() : $ses_status;
}
if (PHP_SESSION_ACTIVE != $ses_status) {
return;
}
-
+
switch ($state) {
case 0:
session_write_close();
return;
case 1:
- if ($ini) {
+ if ($ini) {
ini_set('session.use_only_cookies', false);
ini_set('session.use_cookies', false);
ini_set('session.use_trans_sid', false);
return;
}
}
-
-}
-
+}