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
|
|
|
|
|
|
|
|
function init($argarray) {
|
|
|
|
$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
|
|
|
|
|
|
|
|
function last_modified() {
|
|
|
|
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-02 12:47:36 +09:00
|
|
|
# Note: argarray ignored, since it's now passed in in init()
|
|
|
|
|
|
|
|
function handle($argarray=NULL) {
|
|
|
|
|
|
|
|
$lm = $this->last_modified();
|
|
|
|
|
|
|
|
if ($lm) {
|
|
|
|
header('Last-Modified: ' . date(DATE_RFC822, $dt));
|
|
|
|
$if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
|
|
|
|
if ($if_modified_since) {
|
|
|
|
$ims = strtotime($if_modified_since);
|
|
|
|
if ($lm <= $ims) {
|
|
|
|
$if_none_match = $_SERVER['HTTP_IF_NONE_MATCH'];
|
|
|
|
if ($if_none_match) {
|
|
|
|
header('304 Not Modified');
|
|
|
|
# Better way to do this?
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-09 11:16:04 +09:00
|
|
|
}
|
2008-07-10 07:46:30 +09:00
|
|
|
|
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-07-23 02:15:01 +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
|
|
|
}
|