Example #1
0
 /**
  * A new Walleye_email should have a to and a subject set on construction. The message can be sent as well
  * as the third parameter or you can choose to render an email view through the withEmailTemplate() static function
  *
  * @see Walleye_email::withEmailTemplate()
  * @param string $to
  * @param string $subject
  * @param string $message
  * @return void
  */
 public function __construct($to, $subject, $message)
 {
     $this->to = $to;
     $appOptions = Config::getAppOptions();
     $this->from = isset($appOptions['REPLY-TO_EMAIL']) ? $appOptions['REPLY-TO_EMAIL'] : '';
     $this->subject = $subject;
     $this->message = $message;
 }
Example #2
0
 /**
  * Use this function to add a general log to the Logs table
  *
  * @static
  * @param string $message
  * @param string $file
  * @param string $line
  * @param boolean $store
  */
 public static function log($message, $file = 'unknown file', $line = 'unknown line', $store = true, $type = 'log')
 {
     $logItem = array('type' => $type, 'message' => $message, 'file' => $file, 'line' => $line);
     $options = Config::getAppOptions();
     if ($store && $options['LOG_ERRORS']) {
         $log_id = self::storeLog($logItem);
         if ($log_id) {
             $logItem['id'] = $log_id;
         }
     }
     self::$logs[] = $logItem;
 }
Example #3
0
 /**
  * Creates the Database object and sets the database connection info based on
  * the config file.
  *
  * You can connect to another database on the server listed in the config class by passing its
  * name in the constructor
  *
  * Only supports Mysql databases.
  *
  * @see includes/walleye.config.php
  * @param string $db
  */
 public function __construct($db = null)
 {
     $dbOptions = Walleye::getInstance()->getDbOptions();
     $appOptions = Config::getAppOptions();
     $engine = $dbOptions['ENGINE'];
     $server = $dbOptions['SERVER'];
     $user = $dbOptions['USER'];
     $password = $dbOptions['PASS'];
     $port = $dbOptions['PORT'];
     if (is_null($db)) {
         $database = $dbOptions['DATABASE'];
     } else {
         $database = $db;
     }
     parent::mysqli($server, $user, $password, $database, $port);
 }
Example #4
0
 /**
  * Starts the session, stores the post or get data, and the path given in the url
  */
 private function __construct()
 {
     $this->startTime = EXECUTION_TIME_START;
     $appOptions = Config::getAppOptions();
     $dbOptions = Config::getDbOptions();
     if ($appOptions['ENVIRONMENT'] == Config::PRODUCTION) {
         self::$environment = Config::PRODUCTION;
         session_start();
         $this->dbOptions = array('ENGINE' => $dbOptions['PROD_ENGINE'], 'SERVER' => $dbOptions['PROD_SERVER'], 'USER' => $dbOptions['PROD_USER'], 'PASS' => $dbOptions['PROD_PASS'], 'DATABASE' => $dbOptions['PROD_DATABASE'], 'PORT' => $dbOptions['PROD_PORT']);
         $this->appOptions = array('BASE' => $appOptions['BASE'], 'DOMAIN' => $appOptions['PROD_DOMAIN'], 'ENVIRONMENT' => $appOptions['ENVIRONMENT'], 'LOG_ERRORS' => $appOptions['LOG_ERRORS'], 'REG_KEY_EXPIRE_TIME' => $appOptions['REG_KEY_EXPIRE_TIME'], 'SESSION_KEY_EXPIRE_TIME' => $appOptions['SESSION_KEY_EXPIRE_TIME'], 'EMAIL_FROM' => $appOptions['EMAIL_FROM'], 'PRINT_APP_INFO_ON_LOAD' => $appOptions['PRINT_APP_INFO_ON_LOAD']);
         $this->data = $this->getDataFromUrl($_SERVER["REQUEST_URI"]);
         $url_array = explode('?', $_SERVER["REQUEST_URI"]);
         $this->url = $url_array[0];
         $this->routes = \Walleye\Config::getRoutes();
         if (isset($this->appOptions['BASE'])) {
             self::$server_base_dir = $this->appOptions['BASE'];
         }
         if (isset($this->appOptions['DOMAIN'])) {
             self::$domain = $this->appOptions['DOMAIN'];
         }
     } else {
         if ($appOptions['ENVIRONMENT'] == Config::DEVELOPMENT) {
             self::$environment = Config::DEVELOPMENT;
             session_start();
             $this->dbOptions = array('ENGINE' => $dbOptions['DEV_ENGINE'], 'SERVER' => $dbOptions['DEV_SERVER'], 'USER' => $dbOptions['DEV_USER'], 'PASS' => $dbOptions['DEV_PASS'], 'DATABASE' => $dbOptions['DEV_DATABASE'], 'PORT' => $dbOptions['DEV_PORT']);
             $this->appOptions = array('BASE' => $appOptions['BASE'], 'DOMAIN' => $appOptions['DEV_DOMAIN'], 'ENVIRONMENT' => $appOptions['ENVIRONMENT'], 'LOG_ERRORS' => $appOptions['LOG_ERRORS'], 'REG_KEY_EXPIRE_TIME' => $appOptions['REG_KEY_EXPIRE_TIME'], 'SESSION_KEY_EXPIRE_TIME' => $appOptions['SESSION_KEY_EXPIRE_TIME'], 'EMAIL_FROM' => $appOptions['EMAIL_FROM'], 'PRINT_APP_INFO_ON_LOAD' => $appOptions['PRINT_APP_INFO_ON_LOAD']);
             $this->data = $this->getDataFromUrl($_SERVER["REQUEST_URI"]);
             $url_array = explode('?', $_SERVER["REQUEST_URI"]);
             $this->url = $url_array[0];
             $this->routes = \Walleye\Config::getRoutes();
             if (isset($this->appOptions['BASE'])) {
                 self::$server_base_dir = $this->appOptions['BASE'];
             }
             if (isset($this->appOptions['DOMAIN'])) {
                 self::$domain = $this->appOptions['DOMAIN'];
             }
         } else {
             self::$environment = Config::TESTING;
             $this->appOptions = array('BASE' => $appOptions['BASE'], 'ENVIRONMENT' => $appOptions['ENVIRONMENT'], 'LOG_ERRORS' => $appOptions['LOG_ERRORS'], 'REG_KEY_EXPIRE_TIME' => $appOptions['REG_KEY_EXPIRE_TIME'], 'SESSION_KEY_EXPIRE_TIME' => $appOptions['SESSION_KEY_EXPIRE_TIME'], 'EMAIL_FROM' => $appOptions['EMAIL_FROM'], 'PRINT_APP_INFO_ON_LOAD' => $appOptions['PRINT_APP_INFO_ON_LOAD']);
             $this->dbOptions = array('ENGINE' => $dbOptions['TEST_ENGINE'], 'SERVER' => $dbOptions['TEST_SERVER'], 'USER' => $dbOptions['TEST_USER'], 'PASS' => $dbOptions['TEST_PASS'], 'DATABASE' => $dbOptions['TEST_DATABASE'], 'PORT' => $dbOptions['TEST_PORT']);
             $this->routes = \Walleye\Config::getRoutes();
             if (isset($this->appOptions['BASE'])) {
                 self::$server_base_dir = $this->appOptions['BASE'];
             }
         }
     }
 }
Example #5
0
 /**
  * Creates the User model based on the session array. This IS the logged in user.
  * Use this constructor if the user is not doing something critical
  *
  * @static
  * @return User
  */
 public static function withSession()
 {
     $instance = null;
     if (isset($_SESSION[User::USER_SESSION])) {
         $db = new Database();
         // get the session in the db
         $get_session_id_stmt = $db->prepare('SELECT id FROM Sessions WHERE session_key = ?');
         $get_session_id_stmt->bind_param('s', $_SESSION[User::USER_SESSION]);
         $get_session_id_stmt->execute();
         $session_id = ($session_row = $db->getRow($get_session_id_stmt)) ? $session_row->id : null;
         $get_session_id_stmt->close();
         // find the user this session is associated with
         $get_user_id_and_date_created_stmt = $db->prepare('SELECT user_id, date_created FROM UserSessions WHERE session_id = ?');
         $get_user_id_and_date_created_stmt->bind_param('i', $session_id);
         $get_user_id_and_date_created_stmt->execute();
         if ($session_id && ($usersession_row = $db->getRow($get_user_id_and_date_created_stmt))) {
             $user_id = $usersession_row->user_id;
             $date_created = $usersession_row->date_created;
             // make sure this session hasn't expired in the database
             $date_created_array = explode(' ', $date_created);
             $appOptions = Config::getAppOptions();
             if (daysFromNow($date_created_array[0]) <= $appOptions['SESSION_KEY_EXPIRE_TIME']) {
                 $instance = User::withId($user_id);
             }
         }
         $get_user_id_and_date_created_stmt->close();
     }
     return $instance;
 }