. * * @category Event * @package StatusNet * @author Zach Copley * @copyright 2011 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @link http://status.net/ */ if (!defined('STATUSNET')) { exit(1); } /** * Callback handler to populate end time dropdown */ class TimelistAction extends Action { private $start; private $duration; /** * Get ready * * @param array $args misc. arguments * * @return boolean true */ function prepare(array $args=array()) { parent::prepare($args); $this->start = $this->arg('start'); $this->duration = $this->boolean('duration', false); return true; } /** * Handle input and ouput something * * @param array $args $_REQUEST arguments * * @return void */ function handle(array $args=array()) { parent::handle($args); if (!common_logged_in()) { // TRANS: Error message displayed when trying to perform an action that requires a logged in user. $this->clientError(_m('Not logged in.')); } if (!empty($this->start)) { $times = EventTimeList::getTimes($this->start, $this->duration); } else { // TRANS: Client error when submitting a form with unexpected information. $this->clientError(_m('Unexpected form submission.')); } if ($this->boolean('ajax')) { header('Content-Type: application/json; charset=utf-8'); print json_encode($times); } else { // TRANS: Client error displayed when using an action in a non-AJAX way. $this->clientError(_m('This action is AJAX only.')); } } /** * Override the regular error handler to show something more * ajaxy * * @param string $msg error message * @param int $code error code */ function clientError($msg, $code = 400) { if ($this->boolean('ajax')) { header('Content-Type: application/json; charset=utf-8'); print json_encode( array( 'success' => false, 'code' => $code, 'message' => $msg ) ); } else { parent::clientError($msg, $code); } } }