3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('LACONICA')) {
24 class Action // lawsuit
33 // For initializing members of the class
35 function prepare($argarray)
37 $this->args =& common_copy_args($argarray);
41 // For comparison with If-Last-Modified
42 // If not applicable, return null
44 function last_modified()
54 function is_readonly()
59 function arg($key, $def=null)
61 if (array_key_exists($key, $this->args)) {
62 return $this->args[$key];
68 function trimmed($key, $def=null)
70 $arg = $this->arg($key, $def);
71 return (is_string($arg)) ? trim($arg) : $arg;
74 // Note: argarray ignored, since it's now passed in in prepare()
76 function handle($argarray=null)
79 $lm = $this->last_modified();
80 $etag = $this->etag();
83 header('ETag: ' . $etag);
87 header('Last-Modified: ' . date(DATE_RFC1123, $lm));
88 $if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
89 if ($if_modified_since) {
90 $ims = strtotime($if_modified_since);
93 $this->_has_etag($etag, $_SERVER['HTTP_IF_NONE_MATCH'])) {
94 header('HTTP/1.1 304 Not Modified');
95 // Better way to do this?
103 function _has_etag($etag, $if_none_match)
105 return ($if_none_match) && in_array($etag, explode(',', $if_none_match));
108 function boolean($key, $def=false)
110 $arg = strtolower($this->trimmed($key));
114 } else if (in_array($arg, array('true', 'yes', '1'))) {
116 } else if (in_array($arg, array('false', 'no', '0'))) {
123 function server_error($msg, $code=500)
125 $action = $this->trimmed('action');
126 common_debug("Server error '$code' on '$action': $msg", __FILE__);
127 common_server_error($msg, $code);
130 function client_error($msg, $code=400)
132 $action = $this->trimmed('action');
133 common_debug("User error '$code' on '$action': $msg", __FILE__);
134 common_user_error($msg, $code);
139 $action = $this->trimmed('action');
141 unset($args['action']);
142 foreach (array_keys($_COOKIE) as $cookie) {
143 unset($args[$cookie]);
145 return common_local_url($action, $args);
148 function nav_menu($menu)
150 $action = $this->trimmed('action');
151 common_element_start('ul', array('id' => 'nav_views'));
152 foreach ($menu as $menuaction => $menudesc) {
153 common_menu_item(common_local_url($menuaction,
154 isset($menudesc[2]) ? $menudesc[2] : null),
157 $action == $menuaction);
159 common_element_end('ul');