applicationeditform.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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/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. /**
  46. * group for user to join
  47. */
  48. var $application = null;
  49. /**
  50. * Constructor
  51. *
  52. * @param Action $out output channel
  53. * @param User_group $group group to join
  54. */
  55. function __construct($out=null, $application=null)
  56. {
  57. parent::__construct($out);
  58. $this->application = $application;
  59. }
  60. /**
  61. * ID of the form
  62. *
  63. * @return string ID of the form
  64. */
  65. function id()
  66. {
  67. if ($this->application) {
  68. return 'form_application_edit-' . $this->application->id;
  69. } else {
  70. return 'form_application_add';
  71. }
  72. }
  73. /**
  74. * HTTP method used to submit the form
  75. *
  76. * For image data we need to send multipart/form-data
  77. * so we set that here too
  78. *
  79. * @return string the method to use for submitting
  80. */
  81. function method()
  82. {
  83. $this->enctype = 'multipart/form-data';
  84. return 'post';
  85. }
  86. /**
  87. * class of the form
  88. *
  89. * @return string of the form class
  90. */
  91. function formClass()
  92. {
  93. return 'form_settings';
  94. }
  95. /**
  96. * Action of the form
  97. *
  98. * @return string URL of the action
  99. */
  100. function action()
  101. {
  102. $cur = common_current_user();
  103. if (!empty($this->application)) {
  104. return common_local_url('editapplication',
  105. array('id' => $this->application->id));
  106. } else {
  107. return common_local_url('newapplication');
  108. }
  109. }
  110. /**
  111. * Name of the form
  112. *
  113. * @return void
  114. */
  115. function formLegend()
  116. {
  117. // TRANS: Form legend.
  118. $this->out->element('legend', null, _('Edit application'));
  119. }
  120. /**
  121. * Data elements of the form
  122. *
  123. * @return void
  124. */
  125. function formData()
  126. {
  127. if ($this->application) {
  128. $id = $this->application->id;
  129. $icon = $this->application->icon;
  130. $name = $this->application->name;
  131. $description = $this->application->description;
  132. $source_url = $this->application->source_url;
  133. $organization = $this->application->organization;
  134. $homepage = $this->application->homepage;
  135. $callback_url = $this->application->callback_url;
  136. $this->type = $this->application->type;
  137. $this->access_type = $this->application->access_type;
  138. } else {
  139. $id = '';
  140. $icon = '';
  141. $name = '';
  142. $description = '';
  143. $source_url = '';
  144. $organization = '';
  145. $homepage = '';
  146. $callback_url = '';
  147. $this->type = '';
  148. $this->access_type = '';
  149. }
  150. $this->out->elementStart('ul', 'form_data');
  151. $this->out->elementStart('li', array('id' => 'application_icon'));
  152. if (!empty($icon)) {
  153. $this->out->element('img', array('src' => $icon));
  154. }
  155. $this->out->element('input', array('name' => 'MAX_FILE_SIZE',
  156. 'type' => 'hidden',
  157. 'id' => 'MAX_FILE_SIZE',
  158. 'value' => ImageFile::maxFileSizeInt()));
  159. $this->out->element('label', array('for' => 'app_icon'),
  160. // TRANS: Form input field label for application icon.
  161. _('Icon'));
  162. $this->out->element('input', array('name' => 'app_icon',
  163. 'type' => 'file',
  164. 'id' => 'app_icon'));
  165. // TRANS: Form guide.
  166. $this->out->element('p', 'form_guide', _('Icon for this application'));
  167. $this->out->elementEnd('li');
  168. $this->out->elementStart('li');
  169. $this->out->hidden('application_id', $id);
  170. // TRANS: Form input field label for application name.
  171. $this->out->input('name', _('Name'),
  172. ($this->out->arg('name')) ? $this->out->arg('name') : $name);
  173. $this->out->elementEnd('li');
  174. $this->out->elementStart('li');
  175. $maxDesc = Oauth_application::maxDesc();
  176. if ($maxDesc > 0) {
  177. // TRANS: Form input field instructions.
  178. // TRANS: %d is the number of available characters for the description.
  179. $descInstr = sprintf(_m('Describe your application in %d character','Describe your application in %d characters',$maxDesc),
  180. $maxDesc);
  181. } else {
  182. // TRANS: Form input field instructions.
  183. $descInstr = _('Describe your application');
  184. }
  185. // TRANS: Form input field label.
  186. $this->out->textarea('description', _('Description'),
  187. ($this->out->arg('description')) ? $this->out->arg('description') : $description,
  188. $descInstr);
  189. $this->out->elementEnd('li');
  190. $this->out->elementStart('li');
  191. // TRANS: Form input field instructions.
  192. $instruction = _('URL of the homepage of this application');
  193. // TRANS: Form input field label.
  194. $this->out->input('source_url', _('Source URL'),
  195. ($this->out->arg('source_url')) ? $this->out->arg('source_url') : $source_url,
  196. $instruction);
  197. $this->out->elementEnd('li');
  198. $this->out->elementStart('li');
  199. // TRANS: Form input field instructions.
  200. $instruction = _('Organization responsible for this application');
  201. // TRANS: Form input field label.
  202. $this->out->input('organization', _('Organization'),
  203. ($this->out->arg('organization')) ? $this->out->arg('organization') : $organization,
  204. $instruction);
  205. $this->out->elementEnd('li');
  206. $this->out->elementStart('li');
  207. // TRANS: Form input field instructions.
  208. $instruction = _('URL for the homepage of the organization');
  209. // TRANS: Form input field label.
  210. $this->out->input('homepage', _('Homepage'),
  211. ($this->out->arg('homepage')) ? $this->out->arg('homepage') : $homepage,
  212. $instruction);
  213. $this->out->elementEnd('li');
  214. $this->out->elementStart('li');
  215. // TRANS: Form input field instructions.
  216. $instruction = _('URL to redirect to after authentication');
  217. // TRANS: Form input field label.
  218. $this->out->input('callback_url', ('Callback URL'),
  219. ($this->out->arg('callback_url')) ? $this->out->arg('callback_url') : $callback_url,
  220. $instruction);
  221. $this->out->elementEnd('li');
  222. $this->out->elementStart('li', array('id' => 'application_types'));
  223. $attrs = array('name' => 'app_type',
  224. 'type' => 'radio',
  225. 'id' => 'app_type-browser',
  226. 'class' => 'radio',
  227. 'value' => Oauth_application::$browser);
  228. // Default to Browser
  229. if (empty($this->application)
  230. || empty($this->application->type)
  231. || $this->application->type == Oauth_application::$browser) {
  232. $attrs['checked'] = 'checked';
  233. }
  234. $this->out->element('input', $attrs);
  235. $this->out->element('label', array('for' => 'app_type-browser',
  236. 'class' => 'radio'),
  237. // TRANS: Radio button label for application type
  238. _('Browser'));
  239. $attrs = array('name' => 'app_type',
  240. 'type' => 'radio',
  241. 'id' => 'app_type-dekstop',
  242. 'class' => 'radio',
  243. 'value' => Oauth_application::$desktop);
  244. if (!empty($this->application) && $this->application->type == Oauth_application::$desktop) {
  245. $attrs['checked'] = 'checked';
  246. }
  247. $this->out->element('input', $attrs);
  248. $this->out->element('label', array('for' => 'app_type-desktop',
  249. 'class' => 'radio'),
  250. // TRANS: Radio button label for application type
  251. _('Desktop'));
  252. // TRANS: Form guide.
  253. $this->out->element('p', 'form_guide', _('Type of application, browser or desktop'));
  254. $this->out->elementEnd('li');
  255. $this->out->elementStart('li', array('id' => 'default_access_types'));
  256. $attrs = array('name' => 'default_access_type',
  257. 'type' => 'radio',
  258. 'id' => 'default_access_type-r',
  259. 'class' => 'radio',
  260. 'value' => 'r');
  261. // default to read-only access
  262. if (empty($this->application)
  263. || empty($this->application->access_type)
  264. || $this->application->access_type & Oauth_application::$readAccess) {
  265. $attrs['checked'] = 'checked';
  266. }
  267. $this->out->element('input', $attrs);
  268. $this->out->element('label', array('for' => 'default_access_type-ro',
  269. 'class' => 'radio'),
  270. // TRANS: Radio button label for access type.
  271. _('Read-only'));
  272. $attrs = array('name' => 'default_access_type',
  273. 'type' => 'radio',
  274. 'id' => 'default_access_type-rw',
  275. 'class' => 'radio',
  276. 'value' => 'rw');
  277. if (!empty($this->application)
  278. && $this->application->access_type & Oauth_application::$readAccess
  279. && $this->application->access_type & Oauth_application::$writeAccess
  280. ) {
  281. $attrs['checked'] = 'checked';
  282. }
  283. $this->out->element('input', $attrs);
  284. $this->out->element('label', array('for' => 'default_access_type-rw',
  285. 'class' => 'radio'),
  286. // TRANS: Radio button label for access type.
  287. _('Read-write'));
  288. // TRANS: Form guide.
  289. $this->out->element('p', 'form_guide', _('Default access for this application: read-only, or read-write'));
  290. $this->out->elementEnd('li');
  291. $this->out->elementEnd('ul');
  292. }
  293. /**
  294. * Action elements
  295. *
  296. * @return void
  297. */
  298. function formActions()
  299. {
  300. // TRANS: Button label in the "Edit application" form.
  301. $this->out->submit('cancel', _m('BUTTON','Cancel'), 'submit form_action-primary',
  302. // TRANS: Submit button title.
  303. 'cancel', _('Cancel application changes.'));
  304. // TRANS: Button label in the "Edit application" form.
  305. $this->out->submit('save', _m('BUTTON','Save'), 'submit form_action-secondary',
  306. // TRANS: Submit button title.
  307. 'save', _('Save application changes.'));
  308. }
  309. }