Exemplo n.º 1
0
 public function getTrackerStats()
 {
     $data = array('datasets' => array());
     $start = Request::get('start', 'int') ?: -30;
     $end = Request::get('end', 'int') ?: 0;
     $sub_id = -1;
     $user_id = -1;
     $tracker = NULL;
     foreach ($_GET['sets'] as $set) {
         $tracker = isset($set['tracker']) ? intval($set['tracker']) : $tracker;
         $sub_id = isset($set['sub_id']) ? intval($set['sub_id']) : $sub_id;
         $user_id = isset($set['user_id']) ? intval($set['user_id']) : $user_id;
         if (empty($tracker)) {
             throw new \Exception('Invalid tracker');
         }
         $data['datasets'][] = array('data' => array_values(Tracker::getHistory($tracker, $start, $end, $sub_id, $user_id)), 'label' => Tracker::getName($tracker));
     }
     $data['labels'] = array();
     $start += Time::today();
     $end += Time::today();
     for ($i = $start; $i <= $end; $i++) {
         $data['labels'][] = jdtogregorian($i);
     }
     Output::json($data);
 }
Exemplo n.º 2
0
 /**
  * Send a test email.
  */
 public function postSendTest()
 {
     Output::disableBuffering();
     Messenger::setVerbose(true);
     $mailer = new Mailer(true);
     $mailer->sendBulk(Request::get('id', 'int'), true);
     exit;
 }
Exemplo n.º 3
0
    public function get()
    {
        print '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
        $this->loadUrls();
        print Output::XMLSegment($this->urls, 'url');
        print '</urlset>';
        exit;
    }
Exemplo n.º 4
0
 public function postReset()
 {
     if (!($email = Request::get('email', 'email'))) {
         Output::error('Invalid email');
     } elseif (!($user = UserModel::loadByEmail($email))) {
         Output::error('User does not exist.');
     }
     $user->sendResetLink();
 }
Exemplo n.º 5
0
 public function get()
 {
     $message_id = Request::get('message_id', 'int');
     if (empty($message_id)) {
         Output::error('Message Not Found');
     }
     JS::set('chart.' . $this->id . '.params.message_id', ['value' => $message_id]);
     parent::get();
 }
Exemplo n.º 6
0
 /**
  * Does not require encryption, uses token.
  */
 public function post()
 {
     $user = ClientUser::getInstance()->id;
     // TODO: These can be spoofed.
     // A verification method is needed.
     $tracker = Request::post('tracker');
     $sub = Request::post('id', 'int');
     // Track.
     Tracker::trackEvent($tracker, $sub, $user);
     Output::json(Output::SUCCESS);
 }
Exemplo n.º 7
0
 public static function getAccessToken()
 {
     self::loadAutoLoader();
     session_start();
     $request_token['oauth_token'] = $_SESSION['oauth_token'];
     $request_token['oauth_token_secret'] = $_SESSION['oauth_token_secret'];
     if (isset($_REQUEST['oauth_token']) && $request_token['oauth_token'] !== $_REQUEST['oauth_token']) {
         // Abort! Something is wrong.
         Output::error('invalid request');
     }
     // Convert to access token (this should be done on the client side)
     $appId = Configuration::get('twitter.key');
     $secret = Configuration::get('twitter.secret');
     $connection = new TwitterOAuth($appId, $secret, $request_token['oauth_token'], $request_token['oauth_token_secret']);
     return $connection->oauth("oauth/access_token", array("oauth_verifier" => $_REQUEST['oauth_verifier']));
 }
Exemplo n.º 8
0
 public function getFields()
 {
     // TODO: REQUIRE ADMIN
     $cl = Request::get('criteria_list', 'explode', 'int');
     $output = array();
     if (!empty($cl)) {
         $fields = Database::getInstance()->select('message_criteria', array('message_criteria_id' => array('IN', $cl)));
         foreach ($fields as $f) {
             if (!empty($f['variables'])) {
                 $values = Database::getInstance()->selectRow('message_message_criteria', array('message_id' => Request::get('message_id', 'int'), 'message_criteria_id' => $f['message_criteria_id']));
                 $output[] = array('criteria_id' => $f['message_criteria_id'], 'variables' => explode(',', $f['variables']), 'values' => json_decode($values['field_values']));
             }
         }
     }
     Output::json(array('criteria' => $output));
 }
Exemplo n.º 9
0
 public function get()
 {
     $page = Request::getLocation();
     $template_page = Configuration::get('splash.pages.' . $page);
     // No template found.
     if (empty($template_page) || is_array($template_page) && empty($template_page['template'])) {
         Output::error('Page not found.');
     } else {
         $this->page = is_array($template_page) ? $template_page['template'] : $template_page;
     }
     // Add any CSS or JS files.
     if (is_array($template_page)) {
         if (!empty($template_page['css'])) {
             CSS::add($template_page['css']);
         }
         if (!empty($template_page['js'])) {
             JS::add($template_page['js']);
         }
     }
 }
Exemplo n.º 10
0
 public function postUpdateDate()
 {
     if (ClientUser::getInstance()->isAdmin()) {
         $id = Request::post('id');
         $key = Request::post('key');
         $column = Request::post('column');
         $table = Request::post('table');
         $m = Request::post("date_m");
         $d = Request::post("date_d");
         $y = Request::post("date_y");
         if ($m > 0 && $d > 0) {
             if ($y == 0) {
                 $y = date("Y");
             }
             $value = gregoriantojd($m, $d, $y);
         } else {
             $value = 0;
         }
         Database::getInstance()->update($table, array($column => $value), array($key => $id));
         Output::json(Output::SUCCESS);
     } else {
         Output::json(Output::ACCESS_DENIED);
     }
 }
Exemplo n.º 11
0
 /**
  * Render a template and it's main page content.
  *
  * @param string $template
  *   The main template to render within the template.
  * @param bool $return_as_string
  *   When TRUE, the output will be returned instead of output.
  *
  * @return string
  *   The rendered content.
  */
 public function render($template = null, $return_as_string = false)
 {
     if (!$return_as_string) {
         Output::sendCookies();
     }
     // Get the default template if none is supplied.
     if (empty($template)) {
         $template = $this->template;
     }
     $this->setTemplateMetaData();
     if ($return_as_string) {
         return $this->build($template, true);
     } else {
         print $this->build($template, false);
     }
 }
Exemplo n.º 12
0
 protected function outputCookies()
 {
     if (isset($this->results['cookies']) && is_array($this->results['cookies'])) {
         foreach ($this->results['cookies'] as $cookie => $params) {
             if ($cookie == '') {
                 continue;
             }
             $params += array('value' => null, 'ttl' => null, 'path' => null, 'domain' => null, 'secure' => null, 'httponly' => null);
             Output::setCookie($cookie, $params['value'], $params['ttl'], $params['path'], $params['domain'], $params['secure'], $params['httponly']);
         }
     }
 }
Exemplo n.º 13
0
 /**
  * Require to log in if not, and to be an admin or give an access denied page.
  */
 public static function requireAdmin()
 {
     self::requireLogin();
     if (!self::getInstance()->isAdmin()) {
         Output::accessDenied();
     }
 }
Exemplo n.º 14
0
 /**
  * Terminate the program and send any current errors or messages.
  *
  * @param string $error
  *   An optional error message to add at fail time.
  */
 protected function _die($error = '')
 {
     // These must be global to send to the foot file.
     // @todo fire some final callback
     if ($this->verbose) {
         Messenger::error($error);
     }
     // Call the shutdown function.
     if (!empty($this->shutdown_function) && is_callable($this->shutdown_function)) {
         call_user_func($this->shutdown_function, $this->output, FALSE, FALSE);
     }
     $this->finalize();
     Output::jsonData($this->output);
 }
Exemplo n.º 15
0
 public function blank_session()
 {
     Output::clearCookie(Configuration::get('session.cookie'));
 }
Exemplo n.º 16
0
 /**
  * Prepare headers to output a downloaded file.
  *
  * @param string $file_name
  *   The name that the browser should save the file as.
  * @param int $size
  *   The size of the content if known.
  */
 public static function download($file_name, $size = null) {
     header('Content-disposition: attachment; filename=' . $file_name);
     if ($size) {
         header('Content-Length: ' . $size);
     }
     Output::disableBuffering();
 }
Exemplo n.º 17
0
 /**
  * Output the data.
  */
 public function output()
 {
     Output::json(array('data' => $this->data, 'messages' => Messenger::getMessages(), 'errors' => Messenger::getErrors()));
 }
Exemplo n.º 18
0
    /**
     * Determine which handler in the page to run. This will automatically
     * determine if there is a form based on the submitted action variable.
     * If no action variable, it will call get() or post() or any other
     * rest method.
     */
    public function execute() {
        $request_type = strtolower(Request::type());

        if (!$this->hasAccess()) {
            Output::accessDenied();
        }

        if (!$this->validateToken()) {
            Navigation::redirect('/message?err=invalid_token');
        }

        // If there is a requested action.
        if ($action = Request::get('action')) {
            $method = Request::convertFunctionName($request_type, $action);
            if (method_exists($this, $method)) {
                $this->{$method}();
                $this->output();
            }
            else {
                Output::error('There was an error processing your submission.');
            }
        } else {
            if (method_exists($this, $request_type)) {
                $this->$request_type();
                $this->output();
            } else {
                // TODO: show 302
                Output::error('Method not available');
            }
        }
    }
Exemplo n.º 19
0
 /**
  * Send a temporary password.
  *
  * @todo This is not secure. There should be a security question and email should just be a link.
  */
 public function postReset()
 {
     if (!($email = Request::get('email', 'email'))) {
         Output::error('Invalid email');
     } elseif (!($user = UserModel::loadByEmail($email))) {
         Output::error('User does not exist.');
     }
     if ($user->sendResetLink()) {
         Navigation::redirect('message', array('msg' => 'reset'));
     }
 }
Exemplo n.º 20
0
 /**
  * Process the data and import it based on alignment fields.
  */
 protected function importDataFile()
 {
     $cache = new FileCache();
     $cache->loadReference(Request::post('cache'));
     if (!$cache->isValid()) {
         Output::error('Invalid reference. Please try again.');
     }
     // Load the CSV, skip the first row if it's a header.
     $csv = new CSVIterator($cache->getFile());
     if (Request::post('header', 'int')) {
         $csv->next();
     }
     // Process the alignment so we know which fields to import.
     $alignment = Request::get('alignment', 'keyed_array', 'int');
     $fields = array();
     foreach ($alignment as $field => $column) {
         if ($column != -1) {
             $fields[$field] = $column;
         }
     }
     $database = Database::getInstance();
     $values = array();
     while ($csv->valid()) {
         $row = $csv->current();
         foreach ($fields as $field => $column) {
             $values[$field][] = $row[$column];
         }
         if (count($values[$field]) >= 100) {
             // Insert what we have so far and continue.
             $last_id = $database->insertSets($this->table, array_keys($fields), $values, true);
             if (method_exists($this, 'customImportPostProcess')) {
                 $ids = $last_id ? range($last_id - $database->affectedRows() + 1, $last_id) : [];
                 $this->customImportPostProcess($values, $ids);
             }
             $values = array();
         }
         $csv->next();
     }
     if (!empty($values)) {
         $last_id = $database->insertSets($this->table, array_keys($fields), $values, true);
         if (method_exists($this, 'customImportPostProcess')) {
             $ids = $last_id ? range($last_id - $database->affectedRows() + 1, $last_id) : [];
             $this->customImportPostProcess($values, $ids);
         }
     }
 }
Exemplo n.º 21
0
 public function postSave()
 {
     $user = ClientUser::getInstance();
     if (!$user->isAdmin()) {
         return $this->get();
     }
     $page_id = Request::post('page_id', 'int');
     $title = Request::post('title');
     $url = Request::post('url', 'url');
     // Create an array of the new values.
     $new_values = array('title' => $title, 'url' => !empty($url) ? $url : Scrub::url($title), 'keywords' => Request::post('keywords'), 'description' => Request::post('description'), 'site_map' => Request::post('sitemap', 'int'), 'body' => Request::post('page_body', 'html', '', '', true), 'last_update' => time(), 'layout' => Request::post('layout', 'int'));
     // Save the page.
     if ($page_id != 0) {
         Database::getInstance()->update('page', $new_values, array('page_id' => $page_id));
     } else {
         $page_id = Database::getInstance()->insert('page', $new_values);
     }
     $output = array();
     $output['url'] = $new_values['url'];
     $output['page_id'] = $page_id;
     $output['title'] = $title;
     Output::json($output);
 }