| 
									
										
										
										
											2013-08-30 10:28:57 +02:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2020-09-08 12:42:51 +03:00
										 |  |  | // This file is part of GNU social - https://www.gnu.org/software/social
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // GNU social 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.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // GNU social 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.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU Affero General Public License
 | 
					
						
							|  |  |  | // along with GNU social.  If not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-30 10:28:57 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Form action extendable class. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2020-09-08 12:42:51 +03:00
										 |  |  |  * @category  Action | 
					
						
							|  |  |  |  * @package   GNUsocial | 
					
						
							|  |  |  |  * @author    Evan Prodromou <evan@status.net> | 
					
						
							|  |  |  |  * @copyright 2008, 2009 StatusNet, Inc. | 
					
						
							|  |  |  |  * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later | 
					
						
							| 
									
										
										
										
											2013-08-30 10:28:57 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-08 12:42:51 +03:00
										 |  |  | defined('GNUSOCIAL') || die(); | 
					
						
							| 
									
										
										
										
											2013-08-30 10:28:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Form action extendable class | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2020-09-08 12:42:51 +03:00
										 |  |  |  * @category  Action | 
					
						
							|  |  |  |  * @package   GNUsocial | 
					
						
							|  |  |  |  * @author    Evan Prodromou <evan@status.net> | 
					
						
							|  |  |  |  * @author    Mikael Nordfeldth <evan@status.net> | 
					
						
							|  |  |  |  * @copyright 2008, 2009 StatusNet, Inc. | 
					
						
							|  |  |  |  * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later | 
					
						
							| 
									
										
										
										
											2013-08-30 10:28:57 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-05-18 13:31:31 +02:00
										 |  |  | class FormAction extends ManagedAction | 
					
						
							| 
									
										
										
										
											2013-08-30 10:28:57 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     protected $form = null; | 
					
						
							| 
									
										
										
										
											2014-07-06 12:55:18 +02:00
										 |  |  |     protected $formOpts = array(); | 
					
						
							| 
									
										
										
										
											2013-08-30 10:28:57 +02:00
										 |  |  |     protected $type = null; | 
					
						
							| 
									
										
										
										
											2013-09-02 11:58:47 +02:00
										 |  |  |     protected $needLogin = true; | 
					
						
							| 
									
										
										
										
											2014-05-18 13:31:31 +02:00
										 |  |  |     protected $canPost = true; | 
					
						
							| 
									
										
										
										
											2013-08-30 10:28:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-08 12:42:51 +03:00
										 |  |  |     protected function prepare(array $args = []) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-08-30 10:28:57 +02:00
										 |  |  |         parent::prepare($args); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-11 11:16:08 +02:00
										 |  |  |         $this->form = $this->form ?: ucfirst($this->action); | 
					
						
							| 
									
										
										
										
											2013-08-30 10:28:57 +02:00
										 |  |  |         $this->args['form'] = $this->form; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->type = !is_null($this->type) ? $this->type : $this->trimmed('type'); | 
					
						
							|  |  |  |         $this->args['context'] = $this->trimmed('action');  // reply for notice for example
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!$this->type) { | 
					
						
							|  |  |  |             $this->type = null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-08 12:42:51 +03:00
										 |  |  |     public function isReadOnly($args) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-08-30 10:28:57 +02:00
										 |  |  |         return !$this->isPost(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-31 15:03:59 +02:00
										 |  |  |     public function showPageNotice() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->showInstructions(); | 
					
						
							| 
									
										
										
										
											2020-09-08 12:42:51 +03:00
										 |  |  |         if (!empty($msg = $this->getError())) { | 
					
						
							| 
									
										
										
										
											2013-08-31 15:03:59 +02:00
										 |  |  |             $this->element('div', 'error', $msg); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-09-08 12:42:51 +03:00
										 |  |  |         if (!empty($msg = $this->getInfo())) { | 
					
						
							| 
									
										
										
										
											2013-08-31 15:03:59 +02:00
										 |  |  |             $this->element('div', 'info', $msg); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Outputs the instructions for the form | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * SHOULD overload | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2013-09-01 20:52:11 +02:00
										 |  |  |     public function showInstructions() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // instructions are nice, so users know what to do
 | 
					
						
							| 
									
										
										
										
											2013-10-30 12:21:34 +01:00
										 |  |  |         $this->raw(common_markup_to_html($this->getInstructions())); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @return string with instructions to pass into common_markup_to_html() | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-03-10 21:46:33 +01:00
										 |  |  |     protected function getInstructions() | 
					
						
							| 
									
										
										
										
											2013-10-30 12:21:34 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         return null; | 
					
						
							| 
									
										
										
										
											2013-08-31 15:03:59 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-03 14:00:40 +02:00
										 |  |  |     public function showForm($msg=null, $success=false) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->msg = $msg; | 
					
						
							|  |  |  |         $this->success = $success; | 
					
						
							|  |  |  |         $this->showPage(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-04 11:22:32 +02:00
										 |  |  |     protected function showContent() | 
					
						
							| 
									
										
										
										
											2014-07-03 14:00:40 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         $form = $this->getForm(); | 
					
						
							|  |  |  |         $form->show(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected function getForm() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $class = $this->form.'Form'; | 
					
						
							| 
									
										
										
										
											2014-07-06 12:55:18 +02:00
										 |  |  |         $form = new $class($this, $this->formOpts); | 
					
						
							| 
									
										
										
										
											2014-07-03 14:00:40 +02:00
										 |  |  |         return $form; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-08-30 10:28:57 +02:00
										 |  |  | } |