2012-06-20 21:39:23 -07:00

150 lines
3.4 KiB
PHP
Executable File

<?php
/**
* Cana application class
*
* @author Devin Smith <devins@devin-smith.com>
* @date 2009.06.11
*
*/
class Crunchbutton_App extends Cana_App {
private $_crypt;
public function init($params = null) {
$params['postInitSkip'] = true;
switch ($_SERVER['__HTTP_HOST']) {
case 'crunchbutton.localhost':
default:
$params['env'] = 'local';
break;
default:
switch ($_SERVER['SERVER_ADDR']) {
case '74.207.245.57':
$params['env'] = 'live';
break;
}
}
parent::init($params);
$domain = new Cana_Model;
if (preg_match('/(iphone|android)/',$_SERVER['HTTP_USER_AGENT'])) {
$domain->version = 'mobile';
} else {
$domain->version = 'default';
}
$domain->theme = 'default';
$this->buildAuth($this->db());
$config = $this->config();
$config->domain = $domain;
$this
->config($config)
->postInit($params);
}
public function user() {
return $this->_user;
}
public function displayPage($page = null) {
if (is_null($page)) {
$page = $this->pages();
$page = isset($page[0]) ? $page[0] : '';
switch ($page) {
case '':
$pageName = Cana::config()->defaults->page;
break;
default:
$pageName = implode('/',$this->pages());
break;
}
} else {
$pageName = $page;
}
parent::displayPage($pageName);
return $this;
}
public function buildView($params = array()) {
// domain level setup
$params['theme'][] = $this->config()->defaults->version.'/'.$this->config()->defaults->theme.'/';
if (is_array($themes = json_decode($this->config()->domain->theme,'array'))) {
$themes = array_reverse($themes);
foreach ($themes as $theme) {
$params['theme'][] = $this->config()->defaults->version.'/'.$theme.'/';
}
} else {
$params['theme'][] = $this->config()->defaults->version.'/'.$this->config()->domain->theme.'/';
}
if (isset($this->config()->domain->version)) {
$params['theme'][] = $this->config()->domain->version.'/'.$this->config()->defaults->theme.'/';
}
if (is_array($themes = json_decode($this->config()->domain->theme,'array'))) {
$themes = array_reverse($themes);
foreach ($themes as $theme) {
$params['theme'][] = $this->config()->domain->version.'/'.$theme.'/';
}
} elseif (isset($this->config()->domain->version)) {
$params['theme'][] = $this->config()->domain->version.'/'.$this->config()->domain->theme.'/';
}
$params['layout'] = $this->config()->defaults->layout;
foreach ($params['theme'] as $theme) {
$this->controllerStack($theme);
}
parent::buildView($params);
return $this;
}
public function getTheme($config = null) {
$config = $config ? $config : $this->config();
if (is_array($themes = json_decode($config->domain->brand,'array'))) {
return $themes;
} else {
return $config->domain->brand;
}
}
public function crypt($crypt = null) {
if (is_null($crypt)) {
return $this->_crypt = new Cana_Crypt(mb_convert_encoding($this->config()->crypt->key,'7bit'));
} else {
return $this->_crypt;
}
}
public function buildAuth($db = null) {
$this->auth(new Crunchbutton_Auth($db));
return $this;
}
public function buildAcl($db = null) {
$this->acl(new Crunchbutton_Acl($db, $this->auth()));
return $this;
}
public function revision() {
return isset($this->_revision) ? $this->_revision : Crunchbutton_Util::revision();
}
public function appDb() {
return $this->_appDb;
}
}