2008-05-09 03:16:04 +01:00
|
|
|
<?php
|
2008-05-20 20:14:12 +01:00
|
|
|
/*
|
2008-05-14 20:26:48 +01:00
|
|
|
* Laconica - a distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2008, Controlez-Vous, Inc.
|
2008-05-20 20:14:12 +01:00
|
|
|
*
|
2008-05-14 20:26:48 +01: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-20 20:14:12 +01:00
|
|
|
*
|
2008-05-14 20:26:48 +01: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-20 20:14:12 +01:00
|
|
|
*
|
2008-05-14 20:26:48 +01: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 03:16:04 +01:00
|
|
|
|
2008-05-17 16:47:01 +01:00
|
|
|
if (!defined('LACONICA')) { exit(1); }
|
2008-05-14 20:00:09 +01:00
|
|
|
|
2008-05-09 03:16:04 +01:00
|
|
|
class Action { // lawsuit
|
|
|
|
|
|
|
|
var $args;
|
2008-05-20 20:14:12 +01:00
|
|
|
|
2008-05-09 03:16:04 +01:00
|
|
|
function Action() {
|
|
|
|
}
|
2008-05-20 20:14:12 +01:00
|
|
|
|
2008-12-02 03:47:36 +00:00
|
|
|
# For initializing members of the class
|
|
|
|
|
|
|
|
function init($argarray) {
|
|
|
|
$this->args =& common_copy_args($argarray);
|
2008-12-02 04:05:49 +00:00
|
|
|
return true;
|
2008-12-02 03:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# For comparison with If-Last-Modified
|
|
|
|
# If not applicable, return NULL
|
|
|
|
|
|
|
|
function last_modified() {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-07-22 18:15:01 +01:00
|
|
|
function is_readonly() {
|
2008-07-22 22:20:56 +01:00
|
|
|
return false;
|
2008-07-22 18:15:01 +01:00
|
|
|
}
|
|
|
|
|
2008-07-09 22:44:33 +01:00
|
|
|
function arg($key, $def=NULL) {
|
2008-05-17 17:42:18 +01:00
|
|
|
if (array_key_exists($key, $this->args)) {
|
2008-05-09 03:16:04 +01:00
|
|
|
return $this->args[$key];
|
|
|
|
} else {
|
2008-07-09 22:44:33 +01:00
|
|
|
return $def;
|
2008-05-09 03:16:04 +01:00
|
|
|
}
|
|
|
|
}
|
2008-05-20 20:14:12 +01:00
|
|
|
|
2008-07-09 22:44:33 +01:00
|
|
|
function trimmed($key, $def=NULL) {
|
|
|
|
$arg = $this->arg($key, $def);
|
2008-05-21 12:27:07 +01:00
|
|
|
return (is_string($arg)) ? trim($arg) : $arg;
|
|
|
|
}
|
2008-07-09 23:46:30 +01:00
|
|
|
|
2008-12-02 03:47:36 +00:00
|
|
|
# Note: argarray ignored, since it's now passed in in init()
|
|
|
|
|
|
|
|
function handle($argarray=NULL) {
|
|
|
|
|
|
|
|
$lm = $this->last_modified();
|
|
|
|
|
|
|
|
if ($lm) {
|
2008-12-02 04:15:08 +00:00
|
|
|
header('Last-Modified: ' . date(DATE_RFC822, $lm));
|
2008-12-02 03:47:36 +00:00
|
|
|
$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 03:16:04 +01:00
|
|
|
}
|
2008-07-09 23:46:30 +01:00
|
|
|
|
2008-05-22 12:29:54 +01:00
|
|
|
function boolean($key, $def=false) {
|
2008-05-29 16:23:04 +01:00
|
|
|
$arg = strtolower($this->trimmed($key));
|
2008-07-09 23:46:30 +01:00
|
|
|
|
2008-05-29 16:23:04 +01: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-22 18:15:01 +01:00
|
|
|
}
|
2008-07-09 23:46:30 +01:00
|
|
|
|
2008-06-12 20:39:45 +01: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-09 23:46:30 +01:00
|
|
|
|
2008-06-12 20:53:24 +01:00
|
|
|
function client_error($msg, $code=400) {
|
2008-06-12 20:39:45 +01:00
|
|
|
$action = $this->trimmed('action');
|
|
|
|
common_debug("User error '$code' on '$action': $msg", __FILE__);
|
|
|
|
common_user_error($msg, $code);
|
|
|
|
}
|
2008-07-09 23:46:30 +01:00
|
|
|
|
2008-06-20 06:15:36 +01:00
|
|
|
function self_url() {
|
|
|
|
$action = $this->trimmed('action');
|
|
|
|
$args = $this->args;
|
|
|
|
unset($args['action']);
|
2008-11-24 05:22:50 +00:00
|
|
|
foreach (array_keys($_COOKIE) as $cookie) {
|
|
|
|
unset($args[$cookie]);
|
|
|
|
}
|
2008-06-20 06:15:36 +01:00
|
|
|
return common_local_url($action, $args);
|
|
|
|
}
|
2008-07-10 06:12:01 +01:00
|
|
|
|
2008-07-10 00:10:31 +01: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 11:56:59 +01:00
|
|
|
common_menu_item(common_local_url($menuaction, isset($menudesc[2]) ? $menudesc[2] : NULL),
|
|
|
|
$menudesc[0],
|
|
|
|
$menudesc[1],
|
2008-07-10 00:10:31 +01:00
|
|
|
$action == $menuaction);
|
|
|
|
}
|
|
|
|
common_element_end('ul');
|
|
|
|
}
|
2008-05-09 03:16:04 +01:00
|
|
|
}
|