コード例 #1
0
ファイル: Session.php プロジェクト: hettema/Stages
 /**
  * Try to login user in admin
  *
  * @param  string $username
  * @param  string $password
  * @param  Core_Controller_Request_Http $request
  * @return Admin_Model_User|null
  */
 public function login($username, $password, $request = null)
 {
     if (empty($username) || empty($password)) {
         return;
     }
     try {
         /* @var $user Admin_Model_User */
         $user = App_Main::getModel('admin/user');
         $user->login($username, $password);
         if ($user->getId()) {
             $session = App_Main::getSingleton('admin/session');
             $session->setIsFirstVisit(true);
             $session->setUser($user);
         } else {
             throw App_Main::exception('Core', 'Invalid Username or Password.');
         }
     } catch (Core_Exception $e) {
         if ($request && !$request->getParam('messageSent')) {
             App_Main::getSingleton('core/session')->addError($e->getMessage());
             $request->setParam('messageSent', true);
         }
     }
     return $user;
 }
コード例 #2
0
ファイル: Cron.php プロジェクト: hettema/Stages
 /**
  * Get the cron jobs from Xml file, etc/config.xml
  * 
  * @return type 
  */
 protected function _getJobsFromXml()
 {
     $_configFile = App_Main::getModuleDir('etc', 'Cron') . DS . 'config.xml';
     if (!file_exists($_configFile)) {
         App_Main::exception('Core', 'unable ot find the config file for the cron module. Could not continue');
         die;
     }
     $_xml = simplexml_load_file($_configFile)->crontab;
     $jobs = array();
     foreach ($_xml->jobs->children() as $job) {
         $cronJob = App_Main::getModel('cron/job');
         $cronJob->setJobCode($job->getName());
         if ($job->schedule && $job->schedule->cron_expr) {
             $cronJob->setCronExprString((string) $job->schedule->cron_expr);
         }
         $cronJob->setModule((string) $job->run->module);
         if ($job->run->action) {
             $cronJob->setAction((string) $job->run->action);
         }
         //$cronJob['params'] = (string)$job->run->function;
         $jobs[] = $cronJob;
     }
     return $jobs;
 }
コード例 #3
0
ファイル: Website.php プロジェクト: hettema/Stages
 /**
  * Returns the base url confogurd for the current website, if not return the default url
  *
  * @param string $type
  * @param bool $secure
  * @return string url
  */
 public function getBaseUrl($type = self::URL_TYPE_LINK, $secure = null)
 {
     $cacheKey = $type . '/' . (is_null($secure) ? 'null' : ($secure ? 'true' : 'false'));
     if (!isset($this->_baseUrlCache[$cacheKey])) {
         switch ($type) {
             case self::URL_TYPE_WEB:
                 $secure = is_null($secure) ? $this->isCurrentlySecure() : (bool) $secure;
                 $url = $this->getConfig('web-' . ($secure ? 'secure' : 'unsecure') . '-base-url');
                 break;
             case self::URL_TYPE_LINK:
                 $secure = (bool) $secure;
                 $url = $this->getConfig('web-' . ($secure ? 'secure' : 'unsecure') . '-base-url');
                 break;
             case self::URL_TYPE_SKIN:
             case self::URL_TYPE_MEDIA:
             case self::URL_TYPE_JS:
                 $secure = is_null($secure) ? $this->isCurrentlySecure() : (bool) $secure;
                 $url = $this->getConfig('web-' . ($secure ? 'secure' : 'unsecure') . '-base-' . $type . '-url');
                 break;
             default:
                 throw App_Main::exception('Core', App_Main::getHelper('core')->__('Invalid base url type'));
         }
         //load the default url from App_Main if the url is not set
         if (empty($url)) {
             $url = !$secure ? SERVER_URI : SECURE_SERVER_URI;
         }
         $this->_baseUrlCache[$cacheKey] = rtrim($url, '/') . '/';
     }
     return $this->_baseUrlCache[$cacheKey];
 }
コード例 #4
0
ファイル: Standard.php プロジェクト: hettema/Stages
 /**
  * Including controller class
  * checks for existense of $controllerFileName
  *
  * @param string $controllerFileName
  * @param string $controllerClassName
  * @return bool
  */
 protected function _inludeControllerClass($controllerFileName, $controllerClassName)
 {
     if (!class_exists($controllerClassName, false)) {
         if (!file_exists($controllerFileName)) {
             return false;
         }
         include $controllerFileName;
         if (!class_exists($controllerClassName, false)) {
             throw App_Main::exception('Core', 'Controller file was loaded but class does not exist');
         }
     }
     return true;
 }
コード例 #5
0
ファイル: Job.php プロジェクト: hettema/Stages
 /**
  * match cron expression against the current time entry passed along
  *
  * 
  * $num
  *  - i
  *  - H
  *  - d
  *  - F 
  *  - D
  *
  * @param string $expr cron expression string 5,15, * 10 * *
  * @param int $num
  * @return string 
  */
 public function matchCronExpression($expr, $num)
 {
     // handle ALL match
     if ($expr === '*') {
         return true;
     }
     // handle multiple options
     if (strpos($expr, ',') !== false) {
         foreach (explode(',', $expr) as $e) {
             if ($this->matchCronExpression($e, $num)) {
                 return true;
             }
         }
         return false;
     }
     // handle modulus
     if (strpos($expr, '/') !== false) {
         $e = explode('/', $expr);
         if (sizeof($e) !== 2) {
             throw App_Main::exception('Core', "Invalid cron expression, expecting 'match/modulus': " . $expr);
         }
         if (!is_numeric($e[1])) {
             throw App_Main::exception('Core', "Invalid cron expression, expecting numeric modulus: " . $expr);
         }
         $expr = $e[0];
         $mod = $e[1];
     } else {
         $mod = 1;
     }
     // handle all match by modulus
     if ($expr === '*') {
         $from = 0;
         $to = 60;
     } elseif (strpos($expr, '-') !== false) {
         $e = explode('-', $expr);
         if (sizeof($e) !== 2) {
             throw App_Main::exception('Core', "Invalid cron expression, expecting 'from-to' structure: " . $expr);
         }
         $from = $this->getNumeric($e[0]);
         $to = $this->getNumeric($e[1]);
     } else {
         $from = $this->getNumeric($expr);
         $to = $from;
     }
     if ($from === false || $to === false) {
         throw App_Main::exception('Core', "Invalid cron expression: " . $expr);
     }
     return $num >= $from && $num <= $to && $num % $mod === 0;
 }