/** * Use this constructor to create a new Walleye_email class with a given email template and values. The template should not contain * the <?php ?> tags and should use #{value} to define a value * * @static * @param string $to * @param string $subject * @param string $template the email template you want to use. ex. welcome.php will be loaded from the views/email/ dir * @param array $values the values to fill the email template with * @return Walleye_email */ public static function withTemplate($to, $subject, $template, $values = array()) { if (empty($values)) { $template = file_get_contents(Walleye::getInstance()->getServerBaseDir() . 'includes/app/views/email/' . $template); } else { foreach ($values as $tag => $value) { $template = preg_replace('/(#\\{' . $tag . '\\}?)/m', $value, file_get_contents(Walleye::getInstance()->getServerBaseDir() . 'includes/app/views/email/' . $template)); } } $instance = new \Walleye\Email($to, $subject, $template); return $instance; }
/** * 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 = Walleye::getInstance()->getAppOptions(); if ($store && $options['LOG_ERRORS']) { $log_id = self::storeLog($logItem); if ($log_id) { $logItem['id'] = $log_id; } } self::$logs[] = $logItem; }
/** * 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 */ private function __construct($db = null) { $dbOptions = Walleye::getInstance()->getDbOptions(); $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); }
/** * Returns the currently logged in user via sessions. * * @static * @see User::withSession() * @return User */ public static function getLoggedUser() { if (!self::$current_logged_user) { if (Walleye::getInstance()->isTesting()) { self::$current_logged_user = User::withId(Walleye::getInstance()->getTestingUserId()); } else { self::$current_logged_user = User::withSession(); } } return self::$current_logged_user; }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { $this->walleye = Walleye::getInstance(); }
/** * Redirects the browser to a specific URL. MUST be called before the <html> * is sent to the browser (before view()) * * @final * @access protected * @see Walleye_controller::view() * @param string $URL the URL the browser should be redirected to. Send the url from domain.com/ * @param array $data an optional key/value pair to be sent to the redirected page * @return void */ protected final function redirect($URL = '', $data = array()) { if (substr($URL, 0, 1) == '/') { $URL = substr($URL, 1); } $data_query = ''; $alerts = Console::getAlerts(); $logs = Console::getLogs(); if (!Walleye::isProduction() && !empty($logs)) { // if the app is not in production, then get all logs including the alerts $data['logs'] = $logs; } else { if (!empty($alerts)) { // else if there are alerts add them $data['logs'] = $alerts; } else { // else do nothing } } if (!empty($data)) { $data_query = '?' . http_build_query($data); } // stop redirects to the app can be examined $appOptions = Walleye::getInstance()->getAppOptions(); if (!$appOptions['PRINT_APP_INFO_ON_LOAD']) { header('Location: ' . Walleye::getDomain() . $URL . $data_query); } else { Console::log('Redirect: ' . Walleye::getDomain() . $URL . $data_query); } exit; }
/** * Render a view through a basic php include * * ex. view('home/index.php', array('title'=>'Title')); * * @access protected * @param string $view the view to be rendered. * @param array $values the values to be shown on the view * @return void */ protected function view($view, $values = array()) { if (Walleye::getInstance()->isProduction() == false) { $values['logs'] = Console::getLogs(); } else { $values['logs'] = Console::getAlerts(); } include Walleye::getInstance()->getServerBaseDir() . 'includes/app/views/' . $view; }