2008-05-09 11:16:04 +09:00
|
|
|
<?php
|
2008-05-21 04:14:12 +09:00
|
|
|
/*
|
2008-05-15 04:26:48 +09:00
|
|
|
* Laconica - a distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2008, Controlez-Vous, Inc.
|
2008-05-21 04:14:12 +09:00
|
|
|
*
|
2008-05-15 04:26:48 +09:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2008-05-21 04:14:12 +09:00
|
|
|
*
|
2008-05-15 04:26:48 +09:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2008-05-21 04:14:12 +09:00
|
|
|
*
|
2008-05-15 04:26:48 +09:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2008-05-09 11:16:04 +09:00
|
|
|
|
2008-05-18 00:47:01 +09:00
|
|
|
if (!defined('LACONICA')) { exit(1); }
|
2008-05-15 04:00:09 +09:00
|
|
|
|
2008-05-09 11:16:04 +09:00
|
|
|
class Action { // lawsuit
|
|
|
|
|
|
|
|
var $args;
|
2008-05-21 04:14:12 +09:00
|
|
|
|
2008-05-09 11:16:04 +09:00
|
|
|
function Action() {
|
|
|
|
}
|
2008-05-21 04:14:12 +09:00
|
|
|
|
2008-12-02 12:47:36 +09:00
|
|
|
# For initializing members of the class
|
2008-12-02 13:15:32 +09:00
|
|
|
|
2008-12-04 02:32:25 +09:00
|
|
|
function prepare($argarray) {
|
2008-12-02 12:47:36 +09:00
|
|
|
$this->args =& common_copy_args($argarray);
|
2008-12-02 13:05:49 +09:00
|
|
|
return true;
|
2008-12-02 12:47:36 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
# For comparison with If-Last-Modified
|
|
|
|
# If not applicable, return NULL
|
2008-12-02 13:15:32 +09:00
|
|
|
|
2008-12-02 12:47:36 +09:00
|
|
|
function last_modified() {
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-12-02 13:15:32 +09:00
|
|
|
|
2008-12-02 13:42:11 +09:00
|
|
|
function etag() {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-07-23 02:15:01 +09:00
|
|
|
function is_readonly() {
|
2008-07-23 06:20:56 +09:00
|
|
|
return false;
|
2008-07-23 02:15:01 +09:00
|
|
|
}
|
|
|
|
|
2008-07-10 06:44:33 +09:00
|
|
|
function arg($key, $def=NULL) {
|
2008-05-18 01:42:18 +09:00
|
|
|
if (array_key_exists($key, $this->args)) {
|
2008-05-09 11:16:04 +09:00
|
|
|
return $this->args[$key];
|
|
|
|
} else {
|
2008-07-10 06:44:33 +09:00
|
|
|
return $def;
|
2008-05-09 11:16:04 +09:00
|
|
|
}
|
|
|
|
}
|
2008-05-21 04:14:12 +09:00
|
|
|
|
2008-07-10 06:44:33 +09:00
|
|
|
function trimmed($key, $def=NULL) {
|
|
|
|
$arg = $this->arg($key, $def);
|
2008-05-21 20:27:07 +09:00
|
|
|
return (is_string($arg)) ? trim($arg) : $arg;
|
|
|
|
}
|
2008-07-10 07:46:30 +09:00
|
|
|
|
2008-12-04 02:32:25 +09:00
|
|
|
# Note: argarray ignored, since it's now passed in in prepare()
|
2008-12-02 13:15:32 +09:00
|
|
|
|
2008-12-02 12:47:36 +09:00
|
|
|
function handle($argarray=NULL) {
|
2008-12-02 13:15:32 +09:00
|
|
|
|
2008-12-02 12:47:36 +09:00
|
|
|
$lm = $this->last_modified();
|
2008-12-02 13:42:11 +09:00
|
|
|
$etag = $this->etag();
|
|
|
|
|
|
|
|
if ($etag) {
|
|
|
|
header('ETag: ' . $etag);
|
|
|
|
}
|
2008-12-02 13:15:32 +09:00
|
|
|
|
2008-12-02 12:47:36 +09:00
|
|
|
if ($lm) {
|
2008-12-02 13:44:41 +09:00
|
|
|
header('Last-Modified: ' . date(DATE_RFC1123, $lm));
|
2008-12-02 12:47:36 +09:00
|
|
|
$if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
|
|
|
|
if ($if_modified_since) {
|
|
|
|
$ims = strtotime($if_modified_since);
|
|
|
|
if ($lm <= $ims) {
|
2008-12-02 13:42:11 +09:00
|
|
|
if (!$etag || $this->_has_etag($etag, $_SERVER['HTTP_IF_NONE_MATCH'])) {
|
|
|
|
header('HTTP/1.1 304 Not Modified');
|
|
|
|
# Better way to do this?
|
|
|
|
exit(0);
|
|
|
|
}
|
2008-12-02 12:47:36 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-09 11:16:04 +09:00
|
|
|
}
|
2008-07-10 07:46:30 +09:00
|
|
|
|
2008-12-02 13:42:11 +09:00
|
|
|
function _has_etag($etag, $if_none_match) {
|
|
|
|
return ($if_none_match) && in_array($etag, explode(',', $if_none_match));
|
|
|
|
}
|
|
|
|
|
2008-05-22 20:29:54 +09:00
|
|
|
function boolean($key, $def=false) {
|
2008-05-30 00:23:04 +09:00
|
|
|
$arg = strtolower($this->trimmed($key));
|
2008-07-10 07:46:30 +09:00
|
|
|
|
2008-05-30 00:23:04 +09:00
|
|
|
if (is_null($arg)) {
|
|
|
|
return $def;
|
|
|
|
} else if (in_array($arg, array('true', 'yes', '1'))) {
|
|
|
|
return true;
|
|
|
|
} else if (in_array($arg, array('false', 'no', '0'))) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return $def;
|
|
|
|
}
|
2008-12-02 13:15:32 +09:00
|
|
|
}
|
2008-07-10 07:46:30 +09:00
|
|
|
|
2008-06-13 04:39:45 +09:00
|
|
|
function server_error($msg, $code=500) {
|
|
|
|
$action = $this->trimmed('action');
|
|
|
|
common_debug("Server error '$code' on '$action': $msg", __FILE__);
|
|
|
|
common_server_error($msg, $code);
|
|
|
|
}
|
2008-07-10 07:46:30 +09:00
|
|
|
|
2008-06-13 04:53:24 +09:00
|
|
|
function client_error($msg, $code=400) {
|
2008-06-13 04:39:45 +09:00
|
|
|
$action = $this->trimmed('action');
|
|
|
|
common_debug("User error '$code' on '$action': $msg", __FILE__);
|
|
|
|
common_user_error($msg, $code);
|
|
|
|
}
|
2008-07-10 07:46:30 +09:00
|
|
|
|
2008-06-20 14:15:36 +09:00
|
|
|
function self_url() {
|
|
|
|
$action = $this->trimmed('action');
|
|
|
|
$args = $this->args;
|
|
|
|
unset($args['action']);
|
2008-11-24 14:22:50 +09:00
|
|
|
foreach (array_keys($_COOKIE) as $cookie) {
|
|
|
|
unset($args[$cookie]);
|
|
|
|
}
|
2008-06-20 14:15:36 +09:00
|
|
|
return common_local_url($action, $args);
|
|
|
|
}
|
2008-07-10 14:12:01 +09:00
|
|
|
|
2008-07-10 08:10:31 +09:00
|
|
|
function nav_menu($menu) {
|
|
|
|
$action = $this->trimmed('action');
|
|
|
|
common_element_start('ul', array('id' => 'nav_views'));
|
|
|
|
foreach ($menu as $menuaction => $menudesc) {
|
2008-07-20 19:56:59 +09:00
|
|
|
common_menu_item(common_local_url($menuaction, isset($menudesc[2]) ? $menudesc[2] : NULL),
|
|
|
|
$menudesc[0],
|
|
|
|
$menudesc[1],
|
2008-07-10 08:10:31 +09:00
|
|
|
$action == $menuaction);
|
|
|
|
}
|
|
|
|
common_element_end('ul');
|
|
|
|
}
|
2008-05-09 11:16:04 +09:00
|
|
|
}
|