Example #1
0
 /**
  * This _super_function_ combines some of the methods in the
  * class file to quickly create the 'default' page template
  *
  * @param array $pageContent an array of key information that is needed to build the page:
  * 		"page"				label for the page, used to reference content, css and js files
  * 		"title"				page title to display in the header
  * 
  * @return string
  */
 public function buildPage($pageContent = false)
 {
     if (!$pageContent) {
         return false;
     }
     //set contentObj
     $this->contentObj = $pageContent;
     $page = @$pageContent['url'];
     $view = isset($pageContent['view']) ? strtolower($pageContent['view']) : false;
     $this->titleAppend = Config::get_optional("TITLE_PREFIX");
     $this->titleTag = $this->titleAppend . @$pageContent['meta']['title'];
     //specific to Sitespecific
     $reglang = strtolower($pageContent['reglang']);
     //get view which will in turn build components
     //check if view file exists
     $output = "";
     if (!$view) {
         $v = "default.php";
     } else {
         $v = $view . ".php";
     }
     $vpath = DOCUMENT_ROOT . self::viewLocation . strtolower($v);
     if (file_exists($vpath)) {
         require_once $v;
     } else {
         error_log("view file doesn't exist: " . __METHOD__ . " " . __LINE__);
         Site::fnf();
     }
     return $output;
 }
Example #2
0
 /**
  * Logs a message
  * 
  * @example Logger::log("It's not working!");
  * @example Logger::log("It's not working!", 0);
  * @example Logger::log("It's not working!", Logger::EMERG);
  * @example Logger::log("It's not working!", Logger::EMERG, true);
  * 
  * @param string $message The text to log
  * @param number $priority The priority of the error (Logger::EMERG to Logger::DEBUG)
  * @param bool $backtrace Add a debug backtrace to the error log
  * @return void
  */
 public static function log($message = "", $priority = 5, $backtrace = false)
 {
     if (Config::get_optional("dev") != false) {
         $l = self::getInstance();
         if ($backtrace) {
             $l->log($message . self::backtrace(), $priority);
         } else {
             $l->log($message, $priority);
         }
     }
 }
Example #3
0
 /**
  * sets up the session storage method and starts the session
  * 
  * note: if database storage is used then session_write_close() must be used
  * at the end of every page to ensure the session is written to
  * 
  * @param string $tableName if $tableName is passed then database storage is used
  * @return void
  */
 public static function init($tableName = '')
 {
     // are we using database storage?
     if ($tableName) {
         self::$tableName = $tableName;
         // Register session handler callbacks
         session_set_save_handler(array('Session', "open"), array('Session', "close"), array('Session', "read"), array('Session', "write"), array('Session', "destroy"), array('Session', "gc"));
     }
     // read the maxlifetime setting from PHP
     self::$lifetime = get_cfg_var("session.gc_maxlifetime");
     $configSessionShare = Config::get_optional('session_share');
     // default to only share sessions with current server name
     $sessionShare = !empty($configSessionShare) ? $configSessionShare : SERVER_NAME;
     session_set_cookie_params(self::$lifetime, '/', $sessionShare);
     if (Config::get_optional('session_path')) {
         $sessionPath = Config::get_optional('session_path');
         session_save_path($sessionPath);
     }
     session_start();
 }
Example #4
0
 public function resetPassword($id = false, $password = false)
 {
     if (!$id || !$password) {
         return false;
     }
     $db = db::appDbConnect();
     try {
         $password = md5($password . Config::get_optional('password_salt'));
         $sql = "UPDATE users SET password = ? WHERE id = ? LIMIT 1";
         $values = array($password, $id);
         $db->query($sql, $values);
         return true;
     } catch (Exception $e) {
         var_dump($e);
         return false;
     }
 }
Example #5
0
 public static function checkCache($class, $method, $id, $data = NULL, $params = false)
 {
     if (Config::get_optional("CACHE_ON")) {
         $cache_id = sprintf('%s_%s_%s', $class, $method, $id);
         if ($data === NULL) {
             // we're doing a get
             $output = Cache::get($cache_id);
         } elseif ($data === "clearId") {
             $output = Cache::clearId($cache_id);
         } else {
             //else set
             $output = Cache::set($cache_id, $data, $params);
         }
     } else {
         $output = false;
     }
     return $output;
 }
Example #6
0
// $_SERVER['DOCUMENT_ROOT'] is now set - you can use it as usual...
if (!empty($_SERVER['DOCUMENT_ROOT'])) {
    define('DOCUMENT_ROOT', $_SERVER['DOCUMENT_ROOT']);
    define('SERVER_NAME', $_SERVER['SERVER_NAME']);
} else {
    //works for phpunit
    define('DOCUMENT_ROOT', dirname(__FILE__) . "/../web");
    define('SERVER_NAME', "test");
}
function init_autoload($class)
{
    require_once sprintf("%s.php", str_replace("_", "/", $class));
}
spl_autoload_register("init_autoload");
$include_path = array(sprintf("%s/../lib", DOCUMENT_ROOT), sprintf("%s/../lib/classes", DOCUMENT_ROOT), sprintf("%s/../views", DOCUMENT_ROOT), sprintf("%s/../lib/Facebook", DOCUMENT_ROOT));
ini_set("include_path", join(PATH_SEPARATOR, $include_path));
Config::load(sprintf("%s/../config/default.ini", DOCUMENT_ROOT));
Config::load(sprintf("%s/../config/%s.ini", DOCUMENT_ROOT, SERVER_NAME));
//GLOBALS
define('DEFAULT_LANG', Config::get_mandatory("DEFAULT_LANG"));
$tsn = Config::get_optional("THIS_SERVER_NAME") ? Config::get_optional("THIS_SERVER_NAME") : SERVER_NAME;
$tsll = Config::get_optional("THIS_SSL_SERVER_NAME") ? Config::get_optional("THIS_SERVER_NAME") : SERVER_NAME;
define('THIS_SERVER_NAME', $tsn);
define('THIS_SSL_SERVER_NAME', $tsll);
$isDev = Config::get_optional("dev") === "1" ? true : false;
ini_set("display_errors", (bool) $isDev);
ini_set("html_errors", (bool) $isDev);
ini_set("log_errors", (bool) $isDev);
if ($isDev) {
    ini_set("error_reporting", E_ALL);
}
Example #7
0
 public function __construct($options = array())
 {
     parent::__construct($options);
     // Inject Facebook Application into user object
     if (empty($options['facebook'])) {
         throw new Exception('A Facebook user requires a valid Facebook Application object');
     } else {
         $this->facebook = $options['facebook'];
     }
     // get access_token from options, session or ini file (for testing)
     $ini_fb_access_token = Config::get_optional('fb_access_token');
     if (!empty($ini_fb_access_token)) {
         $this->setAccessToken($ini_fb_access_token);
     } elseif (!empty($options['access_token'])) {
         $this->setAccessToken($options['access_token']);
     } elseif (!empty($_SESSION['access_token'])) {
         $this->setAccessToken($_SESSION['access_token']);
     }
     // request permissions if required
     if (empty($this->access_token) && !empty($options['auth'])) {
         Config::get_mandatory('fb_permissions');
     }
     // populate user
     // 		$this->getUser();
     // populate friends, if required
     if (!empty($options['friends'])) {
         // 			$this->friends = $this->getFriends();
     }
 }