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); }
public function getImpersonate() { $session = Session::getInstance(); $session->setSettings('impersonate', Request::get('id', 'int')); $session->saveData(); // TODO: This should call the User::loginRedirect() function. Navigation::redirect('/'); }
/** * Send a test email. */ public function postSendTest() { Output::disableBuffering(); Messenger::setVerbose(true); $mailer = new Mailer(true); $mailer->sendBulk(Request::get('id', 'int'), true); exit; }
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(); }
public function postSave() { $user = ClientUser::getInstance(); // Update the user name. $user->update(array('first' => Request::get('first'), 'last' => Request::get('last'))); // Update the password. $password = Request::post('password'); $new_password = Request::post('new_password'); $new_password_confirm = Request::post('new_password_confirm'); if (!empty($password) && $user->checkPass($password)) { if (false) { Messenger::error('Your password did not meet the required criteria.'); } elseif ($new_password != $new_password_confirm) { Messenger::error('You did not enter the same password twice.'); } else { $user->setPass($new_password); } } elseif (!empty($new_password) || !empty($new_password)) { Messenger::error('You did not enter your correct current password.'); } // Update mailing list preferences. $new_lists = Request::get('subscribed', 'array', 'int', array()); $new_lists = array_combine($new_lists, $new_lists); $all_lists = Subscription::getLists(); $user_id = ClientUser::getInstance()->id; $user_lists = Subscription::getUserLists($user_id); $remove_lists = array(); foreach ($user_lists as $list) { if (empty($new_lists[$list['message_list_id']]) && !empty($list['visible'])) { $remove_lists[$list['message_list_id']] = $list['message_list_id']; } } $add_lists = $new_lists; unset($add_lists[0]); if (!isset($new_lists[0])) { foreach ($all_lists as $list) { if (empty($list['visible'])) { $remove_lists[$list['message_list_id']] = $list['message_list_id']; } } } $db = Database::getInstance(); if (!empty($remove_lists)) { $db->delete('message_list_user', array('message_list_id' => array('IN', $remove_lists), 'user_id' => $user_id)); } if (!empty($add_lists)) { $db->insertMultiple('message_list_user', array('message_list_id' => $add_lists, 'user_id' => $user_id), true); } if (count(Messenger::getErrors()) == 0) { Navigation::redirect(null, array('msg' => 'saved')); } }
/** * Perform request from client. */ public function execute() { // TODO Check for an authentication key if required. // Perform requested actions. if ($actions = Request::get('actions', 'array')) { $this->executeActions($actions); } if ($load = Request::get('load', 'array')) { $this->loadAddtionalData($load); } $this->finalize(); Output::jsonData($this->output, true); }
public function getGetData() { $start = Request::get('start', 'int', null, -30); $end = Request::get('end', 'int', null, 0); $message_id = Request::get('message_id', 'int'); $tracker = new Tracker(); $email_sent = $tracker->getHistory(Tracker::getTrackerId('Email Sent'), $start, $end, $message_id); $email_bounced = $tracker->getHistory(Tracker::getTrackerId('Email Bounced'), $start, $end, $message_id); $email_opened = $tracker->getHistory(Tracker::getTrackerId('Email Opened'), $start, $end, $message_id); $data = new ChartData(Time::today() + $start, Time::today() + $end); $data->addDataSet($email_sent, 'Sent'); $data->addDataSet($email_bounced, 'Bounced'); $data->addDataSet($email_opened, 'Opened'); $data->setXLabels(array_map('jdtogregorian', range(Time::today() + $start, Time::today() + $end))); $data->output(); }
protected function initSettings() { if (Request::get('return') == 'view') { $this->post_actions['after_post'] = function ($row) { Navigation::redirect('/' . $row['url'] . '.htm'); }; } $this->preset['user_id']['default'] = ClientUser::getInstance()->id; $this->preset['url']['submit_function'] = function (&$output) { $output['url'] = Request::post('url', 'url') ?: Request::post('title', 'url'); }; $this->preset['header_image'] = array('type' => 'image', 'location' => BlogModel::IMAGE_PATH, 'weblocation' => '/' . BlogModel::IMAGE_PATH); $this->action_fields = array('view' => array('display_name' => 'View', 'type' => 'html', 'html' => function ($row) { return '<a href="/' . $row['url'] . '.htm"><img src="/images/lightning/resume.png" /></a>'; })); }
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)); }
public function __construct() { ClientUser::requireAdmin(); $list_id = Request::get('list', 'int'); if ($list_id === 0) { Template::getInstance()->set('title', 'Users not on any mailing list.'); $this->accessTableCondition = array('message_list_id' => array('IS NULL')); } elseif ($list_id > 0) { $list = Database::getInstance()->selectField('name', 'message_list', array('message_list_id' => $list_id)); Template::getInstance()->set('title', "Users on list {$list}."); $this->accessTableCondition = array('message_list_id' => $list_id); } else { Template::getInstance()->set('title', 'All users on all lists.'); } parent::__construct(); }
/** * The main page handler, outputs a 1x1 pixel image. */ public function get() { if ($t = Request::get('t', 'encrypted')) { // Track an encrypted link. if (!Tracker::trackLink($t)) { Logger::error('Failed to track encrypted link: ' . Encryption::aesDecrypt($t, Configuration::get('tracker.key'))); } } elseif (Configuration::get('tracker.allow_unencrypted') && ($tracker = Request::get('tracker', 'int'))) { // Track an unencrypted link. $user = Request::get('user', 'int') ?: ClientUser::createInstance()->id; $sub = Request::get('sub', 'int'); Tracker::trackEventID($tracker, $sub, $user); } // Output a single pixel image. header('Content-Type: image/png'); echo base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII='); exit; }
/** * Execute the callback. */ public function execute() { $action = ucfirst(Request::get('action')); $request_type = strtolower(Request::type()); if ($action) { if (in_array($request_type . $action, get_class_methods($this))) { $this->{$request_type . $action}(); $this->output(); } else { Messenger::error('There was an error processing your submission.'); } } else { if (in_array($request_type, get_class_methods($this))) { $this->{$request_type}(); $this->output(); } else { $this->output = array(); // TODO: show 302 echo 'Method not available'; exit; } } }
public static function getDateTime($id, $allow_blank = true) { $m = Request::get($id . '_m', 'int'); $d = Request::get($id . '_d', 'int'); $y = Request::get($id . '_y', 'int'); $h = Request::get($id . '_h', 'int'); if ($h == 12) { $h = 0; } $i = str_pad(Request::get($id . '_i', 'int'), 2, 0, STR_PAD_LEFT); $h += Request::get($id . '_a', '', '', 'AM') == 'AM' ? 0 : 12; if ($allow_blank && (empty($m) || empty($d) || empty($y) || empty($h))) { return 0; } return gmmktime($h, $i, 0, $m, $d, $y); }
function set_posted_links() { foreach ($this->links as $link => $link_settings) { // FOR 1 (local) TO MANY (foreign) if (!empty($link_settings['type']) && $link_settings['type'] == 'image') { $filenames = Request::post('linked_images_' . $link_settings['table'], 'array', 'string'); // Insert new links. $handler = $this->getFileHandler($link_settings); foreach ($filenames as &$filename) { $filename = $handler->relativeFilename($filename); } Database::getInstance()->insertMultiple($link_settings['table'], array($link_settings['key'] => $this->id, $link_settings['display_column'] => $filenames), true); // Remove old links. Database::getInstance()->delete($link_settings['table'], array($link_settings['key'] => $this->id, $link_settings['display_column'] => array('NOT IN', $filenames))); } elseif (!empty($link_settings['full_form'])) { if (!isset($this->list)) { $this->get_row(); } $local_key = isset($link_settings['local_key']) ? $link_settings['local_key'] : $this->getKey(); $local_id = isset($this->list[$local_key]) ? $this->list[$local_key] : $this->id; if ($this->action == "update") { // delete $deleteable = preg_replace('/,$/', '', $_POST['delete_subtable_' . $link]); if ($deleteable != '') { Database::getInstance()->delete($link, array($link_settings['key'] => array('IN', $deleteable), $local_key => $local_id)); } // update $list = Database::getInstance()->selectAll($link, array($local_key => $local_id), array()); foreach ($list as $l) { foreach ($link_settings['fields'] as $f => $field) { $link_settings['fields'][$f]['field'] = $f; $link_settings['fields'][$f]['form_field'] = "st_{$link}_{$f}_{$l[$link_settings['key']]}"; } $field_values = $this->getFieldValues($link_settings['fields']); Database::getInstance()->update($link, $field_values, array($local_key => $local_id, $link_settings['key'] => $l[$link_settings['key']])); } } // insert new $new_subtables = explode(",", $_POST['new_subtable_' . $link]); foreach ($new_subtables as $i) { if ($i != '') { foreach ($link_settings['fields'] as $f => $field) { $link_settings['fields'][$f]['field'] = $f; $link_settings['fields'][$f]['form_field'] = "st_{$link}_{$f}_-{$i}"; } $field_values = $this->getFieldValues($link_settings['fields']); Database::getInstance()->insert($link, $field_values, array($local_key => $local_id)); } } } elseif ($link_settings['index']) { // CLEAR OUT OLD SETTINGS Database::getInstance()->delete($link_settings['index'], array($this->getKey() => $this->id)); // GET INPUT ARRAY $list = Request::get($link . '_input_array', 'explode', 'int'); foreach ($list as $l) { Database::getInstance()->insert($link_settings['index'], array($this->getKey() => $this->id, $link_settings['key'] => $l)); } } } }
public function get() { $user = ClientUser::getInstance(); $template = Template::getInstance(); $request = Request::getLocation(); $content_locator = empty($request) ? 'index' : Request::getFromURL('/(.*)\\.html$/') ?: '404'; // Determine if the user can edit this page. $template->set('editable', $user->isAdmin()); // Set the page template. $template->set('content', 'page'); // LOAD PAGE DETAILS if ($full_page = $this->loadPage($content_locator)) { header('HTTP/1.0 200 OK'); if (Configuration::get('page.modification_date') && $full_page['last_update'] > 0) { header("Last-Modified: " . gmdate("D, d M Y H:i:s", $full_page['last_update']) . " GMT"); } } elseif ($this->new) { $full_page['title'] = ''; $full_page['keywords'] = ''; $full_page['description'] = ''; $full_page['url'] = ''; $full_page['body'] = 'This is your new page.'; $full_page['layout'] = 0; $full_page['site_map'] = 1; CKEditor::init(); JS::startup('lightning.page.edit();'); } elseif ($full_page = $this->loadPage('404')) { header('HTTP/1.0 404 NOT FOUND'); $full_page['url'] = Request::get('page'); $template->set('page_blank', true); } else { header('HTTP/1.0 404 NOT FOUND'); $full_page['title'] = 'Lightning'; $full_page['keywords'] = 'Lightning'; $full_page['description'] = 'Lightning'; $full_page['url'] = ''; $full_page['body'] = 'Your site has not been set up.'; $full_page['layout'] = 0; $full_page['site_map'] = 1; $template->set('page_blank', true); } // Replace special tags. if (!$user->isAdmin()) { $matches = array(); preg_match_all('|{{.*}}|', $full_page['body'], $matches); foreach ($matches as $match) { if (!empty($match)) { $match_clean = trim($match[0], '{} '); $match_clean = explode('=', $match_clean); switch ($match_clean[0]) { case 'template': $sub_template = new Template(); $full_page['body'] = str_replace($match[0], $sub_template->render($match_clean[1], true), $full_page['body']); break; } } } } // PREPARE FORM DATA CONTENTS foreach (array('title', 'keywords', 'description') as $meta_data) { $full_page[$meta_data] = Scrub::toHTML($full_page[$meta_data]); if (!empty($full_page[$meta_data])) { Configuration::set('page_' . $meta_data, str_replace("*", Configuration::get('page_' . $meta_data), $full_page[$meta_data])); } } if ($full_page['url'] == "" && isset($_GET['page'])) { $full_page['url'] = $_GET['page']; } else { $full_page['url'] = Scrub::toHTML($full_page['url'], ENT_QUOTES); } $template->set('page_header', $full_page['title']); $template->set('full_page', $full_page); $template->set('full_width', $full_page['layout'] == 1); }
/** * 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'); } } }
public function postSetPassword() { if ($user = UserModel::loadByTempKey(Request::get('key', 'base64'))) { if (($pass = Request::post('password')) && $pass == Request::post('password2')) { $user->setPass($pass); $user->registerToSession(); $user->removeTempKey(); $this->loginRedirect(); } else { Messenger::error('Please enter a valid password and verify it by entering it again..'); } } else { $this->page = ''; Messenger::error('Invalid Access Key'); } }
/** * Get the encoded default value for a form element. * * @param string $var * The name of the field. * @param string $alt_default * A default if nothing was submitted. * @param string $type * The type, usually html ot text. * * @return string * The HTML encoded value. */ public static function defaultValue($var, $alt_default = null, $type = 'text') { $default = Request::get($var, $type) !== null ? Request::get($var, $type) : $alt_default; return Scrub::toHTML($default); }
public function post() { $blog_id = Request::get('id', 'int') | Request::get('blog_id', 'int'); $action = Request::get('action'); // AUTHORIZE A BLOG COMMENT. switch ($action) { case 'post_comment_check': echo md5($_POST['email'] . $_POST['name'] . $_POST['comment']); exit; case 'post_comment': // FIRST CHECK FOR SPAM if ($_POST['check_val'] == md5($_POST['email'] . $_POST['name'] . $_POST['comment'])) { $values = array('blog_id' => $blog_id, 'ip_address' => Request::server('ip_int'), 'email_address' => Request::post('email', 'email'), 'name' => Request::post('name'), 'comment' => Request::post('comment'), 'time' => time()); Database::getInstance()->insert('blog_comment', $values); echo "success"; } else { echo "spam error"; } exit; case 'remove_blog_comment': $user = ClientUser::getInstance(); if ($user->isAdmin() && $_POST['blog_comment_id'] > 0) { Database::getInstance()->delete('blog_comment', array('blog_comment_id' => Request::post('blog_comment_id', 'int'))); echo "ok"; } else { echo "access denied"; } exit; case 'approve_blog_comment': $user = ClientUser::getInstance(); if ($user->isAdmin() && $_POST['blog_comment_id'] > 0) { Database::getInstance()->update('blog_comment', array('approved' => 1), array('blog_comment_id' => Request::post('blog_comment_id', 'int'))); echo "ok"; exit; } } }