applicationeditform.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Form for editing an application
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Form
  23. * @package StatusNet
  24. * @author Zach Copley <zach@status.net>
  25. * @copyright 2009 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. require_once INSTALLDIR . '/lib/util/form.php';
  33. /**
  34. * Form for editing an application
  35. *
  36. * @category Form
  37. * @package StatusNet
  38. * @author Zach Copley <zach@status.net>
  39. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  40. * @link http://status.net/
  41. *
  42. */
  43. class ApplicationEditForm extends Form
  44. {
  45. public $widgetOpts;
  46. public $scoped;
  47. /**
  48. * group for user to join
  49. */
  50. var $application = null;
  51. /**
  52. * Constructor
  53. *
  54. * @param Action $out output channel
  55. * @param User_group $group group to join
  56. */
  57. function __construct($out=null, $application=null)
  58. {
  59. parent::__construct($out);
  60. $this->application = $application;
  61. }
  62. /**
  63. * ID of the form
  64. *
  65. * @return string ID of the form
  66. */
  67. function id()
  68. {
  69. if ($this->application) {
  70. return 'form_application_edit-' . $this->application->id;
  71. } else {
  72. return 'form_application_add';
  73. }
  74. }
  75. /**
  76. * HTTP method used to submit the form
  77. *
  78. * For image data we need to send multipart/form-data
  79. * so we set that here too
  80. *
  81. * @return string the method to use for submitting
  82. */
  83. function method()
  84. {
  85. $this->enctype = 'multipart/form-data';
  86. return 'post';
  87. }
  88. /**
  89. * class of the form
  90. *
  91. * @return string of the form class
  92. */
  93. function formClass()
  94. {
  95. return 'form_settings';
  96. }
  97. /**
  98. * Action of the form
  99. *
  100. * @return string URL of the action
  101. */
  102. function action()
  103. {
  104. $cur = common_current_user();
  105. if (!empty($this->application)) {
  106. return common_local_url('editapplication',
  107. array('id' => $this->application->id));
  108. } else {
  109. return common_local_url('newapplication');
  110. }
  111. }
  112. /**
  113. * Name of the form
  114. *
  115. * @return void
  116. */
  117. function formLegend()
  118. {
  119. // TRANS: Form legend.
  120. $this->out->element('legend', null, _('Edit application'));
  121. }
  122. /**
  123. * Data elements of the form
  124. *
  125. * @return void
  126. */
  127. function formData()
  128. {
  129. if ($this->application) {
  130. $id = $this->application->id;
  131. $icon = $this->application->icon;
  132. $name = $this->application->name;
  133. $description = $this->application->description;
  134. $source_url = $this->application->source_url;
  135. $organization = $this->application->organization;
  136. $homepage = $this->application->homepage;
  137. $callback_url = $this->application->callback_url;
  138. $this->type = $this->application->type;
  139. $this->access_type = $this->application->access_type;
  140. } else {
  141. $id = '';
  142. $icon = '';
  143. $name = '';
  144. $description = '';
  145. $source_url = '';
  146. $organization = '';
  147. $homepage = '';
  148. $callback_url = '';
  149. $this->type = '';
  150. $this->access_type = '';
  151. }
  152. $this->out->elementStart('ul', 'form_data');
  153. $this->out->elementStart('li', array('id' => 'application_icon'));
  154. if (!empty($icon)) {
  155. $this->out->element('img', array('src' => $icon));
  156. }
  157. $this->out->element('input', array('name' => 'MAX_FILE_SIZE',
  158. 'type' => 'hidden',
  159. 'id' => 'MAX_FILE_SIZE',
  160. 'value' => ImageFile::maxFileSizeInt()));
  161. $this->out->element('label', array('for' => 'app_icon'),
  162. // TRANS: Form input field label for application icon.
  163. _('Icon'));
  164. $this->out->element('input', array('name' => 'app_icon',
  165. 'type' => 'file',
  166. 'id' => 'app_icon'));
  167. // TRANS: Form guide.
  168. $this->out->element('p', 'form_guide', _('Icon for this application'));
  169. $this->out->elementEnd('li');
  170. $this->out->elementStart('li');
  171. $this->out->hidden('application_id', $id);
  172. // TRANS: Form input field label for application name.
  173. $this->out->input('name', _('Name'),
  174. ($this->out->arg('name')) ? $this->out->arg('name') : $name);
  175. $this->out->elementEnd('li');
  176. $this->out->elementStart('li');
  177. $maxDesc = Oauth_application::maxDesc();
  178. if ($maxDesc > 0) {
  179. // TRANS: Form input field instructions.
  180. // TRANS: %d is the number of available characters for the description.
  181. $descInstr = sprintf(_m('Describe your application in %d character','Describe your application in %d characters',$maxDesc),
  182. $maxDesc);
  183. } else {
  184. // TRANS: Form input field instructions.
  185. $descInstr = _('Describe your application');
  186. }
  187. // TRANS: Form input field label.
  188. $this->out->textarea('description', _('Description'),
  189. ($this->out->arg('description')) ? $this->out->arg('description') : $description,
  190. $descInstr);
  191. $this->out->elementEnd('li');
  192. $this->out->elementStart('li');
  193. // TRANS: Form input field instructions.
  194. $instruction = _('URL of the homepage of this application');
  195. // TRANS: Form input field label.
  196. $this->out->input('source_url', _('Source URL'),
  197. ($this->out->arg('source_url')) ? $this->out->arg('source_url') : $source_url,
  198. $instruction);
  199. $this->out->elementEnd('li');
  200. $this->out->elementStart('li');
  201. // TRANS: Form input field instructions.
  202. $instruction = _('Organization responsible for this application');
  203. // TRANS: Form input field label.
  204. $this->out->input('organization', _('Organization'),
  205. ($this->out->arg('organization')) ? $this->out->arg('organization') : $organization,
  206. $instruction);
  207. $this->out->elementEnd('li');
  208. $this->out->elementStart('li');
  209. // TRANS: Form input field instructions.
  210. $instruction = _('URL for the homepage of the organization');
  211. // TRANS: Form input field label.
  212. $this->out->input('homepage', _('Homepage'),
  213. ($this->out->arg('homepage')) ? $this->out->arg('homepage') : $homepage,
  214. $instruction);
  215. $this->out->elementEnd('li');
  216. $this->out->elementStart('li');
  217. // TRANS: Form input field instructions.
  218. $instruction = _('URL to redirect to after authentication');
  219. // TRANS: Form input field label.
  220. $this->out->input('callback_url', ('Callback URL'),
  221. ($this->out->arg('callback_url')) ? $this->out->arg('callback_url') : $callback_url,
  222. $instruction);
  223. $this->out->elementEnd('li');
  224. $this->out->elementStart('li', array('id' => 'application_types'));
  225. $attrs = array('name' => 'app_type',
  226. 'type' => 'radio',
  227. 'id' => 'app_type-browser',
  228. 'class' => 'radio',
  229. 'value' => Oauth_application::$browser);
  230. // Default to Browser
  231. if (empty($this->application)
  232. || empty($this->application->type)
  233. || $this->application->type == Oauth_application::$browser) {
  234. $attrs['checked'] = 'checked';
  235. }
  236. $this->out->element('input', $attrs);
  237. $this->out->element('label', array('for' => 'app_type-browser',
  238. 'class' => 'radio'),
  239. // TRANS: Radio button label for application type
  240. _('Browser'));
  241. $attrs = array('name' => 'app_type',
  242. 'type' => 'radio',
  243. 'id' => 'app_type-dekstop',
  244. 'class' => 'radio',
  245. 'value' => Oauth_application::$desktop);
  246. if (!empty($this->application) && $this->application->type == Oauth_application::$desktop) {
  247. $attrs['checked'] = 'checked';
  248. }
  249. $this->out->element('input', $attrs);
  250. $this->out->element('label', array('for' => 'app_type-desktop',
  251. 'class' => 'radio'),
  252. // TRANS: Radio button label for application type
  253. _('Desktop'));
  254. // TRANS: Form guide.
  255. $this->out->element('p', 'form_guide', _('Type of application, browser or desktop'));
  256. $this->out->elementEnd('li');
  257. $this->out->elementStart('li', array('id' => 'default_access_types'));
  258. $attrs = array('name' => 'default_access_type',
  259. 'type' => 'radio',
  260. 'id' => 'default_access_type-r',
  261. 'class' => 'radio',
  262. 'value' => 'r');
  263. // default to read-only access
  264. if (empty($this->application)
  265. || empty($this->application->access_type)
  266. || $this->application->access_type & Oauth_application::$readAccess) {
  267. $attrs['checked'] = 'checked';
  268. }
  269. $this->out->element('input', $attrs);
  270. $this->out->element('label', array('for' => 'default_access_type-ro',
  271. 'class' => 'radio'),
  272. // TRANS: Radio button label for access type.
  273. _('Read-only'));
  274. $attrs = array('name' => 'default_access_type',
  275. 'type' => 'radio',
  276. 'id' => 'default_access_type-rw',
  277. 'class' => 'radio',
  278. 'value' => 'rw');
  279. if (!empty($this->application)
  280. && $this->application->access_type & Oauth_application::$readAccess
  281. && $this->application->access_type & Oauth_application::$writeAccess
  282. ) {
  283. $attrs['checked'] = 'checked';
  284. }
  285. $this->out->element('input', $attrs);
  286. $this->out->element('label', array('for' => 'default_access_type-rw',
  287. 'class' => 'radio'),
  288. // TRANS: Radio button label for access type.
  289. _('Read-write'));
  290. // TRANS: Form guide.
  291. $this->out->element('p', 'form_guide', _('Default access for this application: read-only, or read-write'));
  292. $this->out->elementEnd('li');
  293. $this->out->elementEnd('ul');
  294. }
  295. /**
  296. * Action elements
  297. *
  298. * @return void
  299. */
  300. function formActions()
  301. {
  302. // TRANS: Button label in the "Edit application" form.
  303. $this->out->submit('cancel', _m('BUTTON','Cancel'), 'submit form_action-primary',
  304. // TRANS: Submit button title.
  305. 'cancel', _('Cancel application changes.'));
  306. // TRANS: Button label in the "Edit application" form.
  307. $this->out->submit('save', _m('BUTTON','Save'), 'submit form_action-secondary',
  308. // TRANS: Submit button title.
  309. 'save', _('Save application changes.'));
  310. }
  311. }