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-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-05-17 17:37:49 +01:00
|
|
|
function handle($argarray) {
|
2008-06-19 15:11:07 +01:00
|
|
|
$this->args =& common_copy_args($argarray);
|
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-05-22 12:29:54 +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']);
|
|
|
|
return common_local_url($action, $args);
|
|
|
|
}
|
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) {
|
|
|
|
common_menu_item(common_local_url($menuaction),
|
|
|
|
_t($menudesc[0]),
|
|
|
|
_t($menudesc[1]),
|
|
|
|
$action == $menuaction);
|
|
|
|
}
|
|
|
|
common_element_end('ul');
|
|
|
|
}
|
2008-05-09 03:16:04 +01:00
|
|
|
}
|