| 
									
										
										
										
											2008-05-08 22:16:04 -04:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2008-05-20 15:14:12 -04:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2008-05-14 15:26:48 -04:00
										 |  |  |  * Laconica - a distributed open-source microblogging tool | 
					
						
							|  |  |  |  * Copyright (C) 2008, Controlez-Vous, Inc. | 
					
						
							| 
									
										
										
										
											2008-05-20 15:14:12 -04:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2008-05-14 15:26:48 -04: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 15:14:12 -04:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2008-05-14 15:26:48 -04: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 15:14:12 -04:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2008-05-14 15:26:48 -04: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-08 22:16:04 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-17 11:47:01 -04:00
										 |  |  | if (!defined('LACONICA')) { exit(1); } | 
					
						
							| 
									
										
										
										
											2008-05-14 15:00:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-08 22:16:04 -04:00
										 |  |  | class Action { // lawsuit
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var $args; | 
					
						
							| 
									
										
										
										
											2008-05-20 15:14:12 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-08 22:16:04 -04:00
										 |  |  | 	function Action() { | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-05-20 15:14:12 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-09 17:44:33 -04:00
										 |  |  | 	function arg($key, $def=NULL) { | 
					
						
							| 
									
										
										
										
											2008-05-17 12:42:18 -04:00
										 |  |  | 		if (array_key_exists($key, $this->args)) { | 
					
						
							| 
									
										
										
										
											2008-05-08 22:16:04 -04:00
										 |  |  | 			return $this->args[$key]; | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2008-07-09 17:44:33 -04:00
										 |  |  | 			return $def; | 
					
						
							| 
									
										
										
										
											2008-05-08 22:16:04 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-05-20 15:14:12 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-09 17:44:33 -04:00
										 |  |  | 	function trimmed($key, $def=NULL) { | 
					
						
							|  |  |  | 		$arg = $this->arg($key, $def); | 
					
						
							| 
									
										
										
										
											2008-05-21 07:27:07 -04:00
										 |  |  | 		return (is_string($arg)) ? trim($arg) : $arg; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-09 18:46:30 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-17 12:37:49 -04:00
										 |  |  | 	function handle($argarray) { | 
					
						
							| 
									
										
										
										
											2008-06-19 10:11:07 -04:00
										 |  |  | 		$this->args =& common_copy_args($argarray); | 
					
						
							| 
									
										
										
										
											2008-05-08 22:16:04 -04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-09 18:46:30 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-22 07:29:54 -04:00
										 |  |  | 	function boolean($key, $def=false) { | 
					
						
							| 
									
										
										
										
											2008-05-29 11:23:04 -04:00
										 |  |  | 		$arg = strtolower($this->trimmed($key)); | 
					
						
							| 
									
										
										
										
											2008-07-09 18:46:30 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-29 11:23:04 -04: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 07:29:54 -04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-09 18:46:30 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-12 15:39:45 -04: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 18:46:30 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-12 15:53:24 -04:00
										 |  |  | 	function client_error($msg, $code=400) { | 
					
						
							| 
									
										
										
										
											2008-06-12 15:39:45 -04:00
										 |  |  | 		$action = $this->trimmed('action'); | 
					
						
							|  |  |  | 		common_debug("User error '$code' on '$action': $msg", __FILE__); | 
					
						
							|  |  |  | 		common_user_error($msg, $code); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-09 18:46:30 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-20 01:15:36 -04:00
										 |  |  | 	function self_url() { | 
					
						
							|  |  |  | 		$action = $this->trimmed('action'); | 
					
						
							|  |  |  | 		$args = $this->args; | 
					
						
							|  |  |  | 		unset($args['action']); | 
					
						
							|  |  |  | 		return common_local_url($action, $args); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-10 01:12:01 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-09 19:10:31 -04: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), | 
					
						
							| 
									
										
										
										
											2008-07-10 01:10:35 -04:00
										 |  |  | 							 _($menudesc[0]), | 
					
						
							|  |  |  | 							 _($menudesc[1]), | 
					
						
							| 
									
										
										
										
											2008-07-09 19:10:31 -04:00
										 |  |  | 							 $action == $menuaction); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         common_element_end('ul'); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-05-08 22:16:04 -04:00
										 |  |  | } |