Beispiel #1
0
 protected function addPlugin($key, $obj = null)
 {
     if (is_null($obj)) {
         $class = StringHelper::flatToCamel($key, true);
         $this->_plugins[$key] = new $class();
     } else {
         $this->_plugins[$key] = $obj;
     }
 }
Beispiel #2
0
 /**
  * constructor
  * @param mixed $login is user login required
  */
 public function __construct($login = false, $iphone = false)
 {
     parent::__construct();
     // get front controller instance
     $this->fc = FrontController::getInstance();
     // instantiate page
     $this->page = new PageModel();
     // detect iphone
     if (preg_match('/' . APP_IPHONE_AGENT . '/', $_SERVER['HTTP_USER_AGENT']) && !$iphone) {
         NaviHelper::redirect($this->fc->getUrl('iphone'));
     }
     // check login ?
     if ($login && APP_SETUP_USER_MODEL) {
         if (!$this->fc->user->isLoggedIn()) {
             if (is_string($login)) {
                 if ($this->fc->controller != StringHelper::flatToCamel($login, true) || $this->fc->action != 'login') {
                     NaviHelper::redirect($this->fc->getUrl($login, 'login'));
                 }
             } else {
                 NaviHelper::redirect($this->fc->getUrl('login'));
             }
         }
     }
 }
Beispiel #3
0
 /**
  * checks if property is a class
  * @param string $key property name
  * @param string $class model's class name (returned)
  * @param string $nkey key name for SQL statements (returned)
  */
 public function isObjectProperty($key, &$class, &$nkey)
 {
     $class = $nkey = '';
     if (empty($this->_properties[$key])) {
         return false;
     }
     $type = $this->_properties[$key];
     if (preg_match('/^OBJ(,([a-z0-9_]*))?$/', $type, $match)) {
         $nkey = count($match) > 2 ? $match[2] : $key;
         $class = StringHelper::flatToCamel(count($match) > 2 ? $nkey : $nkey . '_model', true);
         return true;
     } else {
         return false;
     }
 }
Beispiel #4
0
 /**
  * parse request for controller, action and other parameters
  */
 public function parseUrl()
 {
     // clean ugly magic quotes
     self::cleanRequest();
     $req = $_SERVER['REQUEST_URI'];
     // remove subfolder setup if non virtual host
     if (strlen(APP_WWW_URI) > 1) {
         $req = str_ireplace(APP_WWW_URI, '', $req);
     }
     // remove trailing slashes
     $req = trim($req, '/');
     // parse if non empty
     if ($req) {
         if ($pos = strrpos($req, '.html')) {
             $req = substr($req, 0, $pos);
         } else {
             if ($pos = strrpos($req, '?')) {
                 $req = substr($req, 0, $pos);
             }
         }
         $arrReq = explode('/', $req);
         if (count($arrReq)) {
             $this->controller = array_shift($arrReq);
         }
         if (count($arrReq)) {
             $this->action = array_shift($arrReq);
         } else {
             $this->action = 'main';
         }
         while (count($arrReq)) {
             $key = array_shift($arrReq);
             if (count($arrReq)) {
                 $val = array_shift($arrReq);
                 $this->request[$key] = urldecode($val);
             } else {
                 $this->request[$key] = '';
             }
         }
     }
     // parse query string
     if (count($_REQUEST)) {
         foreach ($_REQUEST as $key => $val) {
             switch ($key) {
                 case 'c':
                     $this->controller = $val;
                     break;
                 case 'a':
                     $this->action = $val;
                     break;
                 default:
                     $this->request[$key] = $val;
                     break;
             }
         }
     }
     // get real names
     $this->controller = StringHelper::flatToCamel($this->controller, true, '-');
     $this->action = StringHelper::flatToCamel($this->action, false, '-');
 }