We Recommend

Mastering Regular Expressions Mastering Regular Expressions
As this book shows, a command of regular expressions is an invaluable skill. Regular expressions allow you to code complex and subtle text processing that you never imagined could be automated. Regular expressions can save you time and aggravation. They can be used to craft elegant solutions to a wide range of problems. Once you've mastered regular expressions, they'll become an invaluable part of your toolkit. You will wonder how you ever got by without them.


Posted By

weitzman on 08/16/06


Tagged


Versions (?)


tmp


Published in: Diff 


  1. === modified file 'includes/form.inc'
  2. --- includes/form.inc
  3. +++ includes/form.inc
  4. @@ -12,7 +12,67 @@
  5. * http://api.drupal.org/api/HEAD/file/developer/topics/forms_api_reference.html
  6. * and the quickstart guide at
  7. * http://api.drupal.org/api/HEAD/file/developer/topics/forms_api.html
  8. + *
  9. + * If you want to programatically submit a form, you need to
  10. + * retrieve the form, load name/value pairs into $form['#post'] and then
  11. + * call drupal_process_form(). Example:
  12. + *
  13. + * // register a new user.
  14. + * $form = drupal_retrieve_form('user_register');
  15. + * $form['#post']['edit']['name'] = 'robo-user';
  16. + * $form['#post']['mail'] = 'robouser@example.com';
  17. + * $output = drupal_process_form('user_register', $form);
  18. + *
  19. + */
  20. +
  21. +/**
  22. + * Retrieves a form from a handler function, then passes it on for
  23. + * processing and rendering.
  24. + *
  25. + * @param $form_id
  26. + * The unique string identifying the form.
  27. + * @param ...
  28. + * Any additional arguments needed by the form handler.
  29. + * @return
  30. + * The rendered form.
  31. */
  32. +function drupal_get_form($form_id) {
  33. + $args = func_get_args();
  34. + $form = call_user_func_array('drupal_retrieve_form', $args);
  35. + return drupal_process_form($form_id, $form);
  36. +}
  37. +
  38. +/**
  39. + * Retrieves the structured array that defines a given form.
  40. + *
  41. + * @param $form_id
  42. + * The unique string identifying the desired form. If $form_id
  43. + * exists as a function, it is called to build the form. Otherwise,
  44. + * hook_forms() is called to build a system-wide array of forms,
  45. + * and $form_id is used as a key to locate the appropriate
  46. + * builder-function in that array.
  47. + * @param ...
  48. + * Any additional arguments needed by the form handler.
  49. + */
  50. +function drupal_retrieve_form($form_id) {
  51. + static $forms;
  52. +
  53. + $args = func_get_args();
  54. + array_shift($args);
  55. + if (!function_exists($form_id)) {
  56. + if (!isset($forms)) {
  57. + $forms = module_invoke_all('forms');
  58. + }
  59. + $form_definition = $forms[$form_id];
  60. + if (isset($form_definition['callback arguments'])) {
  61. + $args = array_merge($form_definition['callback arguments'], $args);
  62. + }
  63. + if (isset($form_definition['callback'])) {
  64. + $callback = $form_definition['callback'];
  65. + }
  66. + }
  67. + return call_user_func_array(isset($callback) ? $callback : $form_id, $args);
  68. +}
  69.  
  70. /**
  71. * Processes a form array and produces the HTML output of a form.
  72. @@ -21,19 +81,26 @@
  73. * and then submit the form using drupal_submit_form().
  74. *
  75. * @param $form_id
  76. - * A unique string identifying the form. Allows each form to be
  77. - * themed. Pass NULL to suppress the form_id parameter (produces
  78. - * a shorter URL with method=get)
  79. + * The unique string identifying the current form.
  80. * @param $form
  81. * An associative array containing the structure of the form.
  82. - * @param $callback
  83. - * An optional callback that will be used in addition to the form_id.
  84. - *
  85. */
  86. -function drupal_get_form($form_id, &$form, $callback = NULL) {
  87. +function drupal_process_form($form_id, $form) {
  88. global $form_values, $form_submitted, $user, $form_button_counter;
  89. static $saved_globals = array();
  90.  
  91. + if (!isset($form['#post'])) {
  92. + $form['#post'] = $_POST;
  93. + $form['#programmed'] = FALSE;
  94. + }
  95. + else {
  96. + $form['#programmed'] = TRUE;
  97. + }
  98. +
  99. + if (isset($form['#base'])) {
  100. + $base = $form['#base'];
  101. + }
  102. +
  103. // Save globals in case of indirect recursive call
  104. array_push($saved_globals, array($form_values, $form_submitted, $form_button_counter));
  105.  
  106. @@ -41,20 +108,24 @@ function drupal_get_form($form_id, &$for
  107. $form_submitted = FALSE;
  108. $form_button_counter = array(0, 0);
  109.  
  110. - $form = drupal_build_form($form_id, $form, $callback);
  111. + $form = drupal_build_form($form_id, $form, $base);
  112.  
  113. - if (!empty($_POST['edit']) && (($_POST['edit']['form_id'] == $form_id) || ($_POST['edit']['form_id'] == $callback))) {
  114. - drupal_validate_form($form_id, $form, $callback);
  115. + if (($form['#programmed']) || (!empty($_POST['edit']) && (($_POST['edit']['form_id'] == $form_id) || ($_POST['edit']['form_id'] == $base)))) {
  116. + drupal_validate_form($form_id, $form);
  117. // IE does not send a button value when there is only one submit button (and no non-submit buttons)
  118. // and you submit by pressing enter.
  119. // In that case we accept a submission without button values.
  120. - if (($form_submitted || (!$form_button_counter[0] && $form_button_counter[1])) && !form_get_errors()) {
  121. - $redirect = drupal_submit_form($form_id, $form, $callback);
  122. - drupal_redirect_form($form, $redirect);
  123. + if ((($form['#programmed']) || $form_submitted || (!$form_button_counter[0] && $form_button_counter[1])) && !form_get_errors()) {
  124. + $redirect = drupal_submit_form($form_id, $form);
  125. + if (!$form['#programmed']) {
  126. + drupal_redirect_form($form, $redirect);
  127. + }
  128. }
  129. }
  130.  
  131. - $output = drupal_render_form($form_id, $form, $callback);
  132. + if (!$form['#programmed']) {
  133. + $output = drupal_render_form($form_id, $form, $base);
  134. + }
  135. list($form_values, $form_submitted, $form_button_counter) = array_pop($saved_globals);
  136. return $output;
  137. }
  138. @@ -69,11 +140,11 @@ function drupal_get_form($form_id, &$for
  139. * theming, and hook_form_alter functions.
  140. * @param $form
  141. * An associative array containing the structure of the form.
  142. - * @param $callback
  143. - * An optional callback that will be used in addition to the form_id.
  144. + * @param $base
  145. + * An optional function prefix that will be used in place of $form_id.
  146. *
  147. */
  148. -function drupal_build_form($form_id, &$form, $callback = NULL) {
  149. +function drupal_build_form($form_id, &$form, $base = NULL) {
  150. $form['#type'] = 'form';
  151. if (isset($form['#token'])) {
  152. // If the page cache is on and an anonymous user issues a GET request,
  153. @@ -105,8 +176,8 @@ function drupal_build_form($form_id, &$f
  154. if (function_exists($form_id .'_validate')) {
  155. $form['#validate'] = array($form_id .'_validate' => array());
  156. }
  157. - elseif (function_exists($callback .'_validate')) {
  158. - $form['#validate'] = array($callback .'_validate' => array());
  159. + elseif (function_exists($base .'_validate')) {
  160. + $form['#validate'] = array($base .'_validate' => array());
  161. }
  162. }
  163.  
  164. @@ -116,8 +187,8 @@ function drupal_build_form($form_id, &$f
  165. // $form_values because it will change later
  166. $form['#submit'] = array($form_id .'_submit' => array());
  167. }
  168. - elseif (function_exists($callback .'_submit')) {
  169. - $form['#submit'] = array($callback .'_submit' => array());
  170. + elseif (function_exists($base .'_submit')) {
  171. + $form['#submit'] = array($base .'_submit' => array());
  172. }
  173. }
  174.  
  175. @@ -141,11 +212,9 @@ function drupal_build_form($form_id, &$f
  176. * theming, and hook_form_alter functions.
  177. * @param $form
  178. * An associative array containing the structure of the form.
  179. - * @param $callback
  180. - * An optional callback that will be used in addition to the form_id.
  181. *
  182. */
  183. -function drupal_validate_form($form_id, $form, $callback = NULL) {
  184. +function drupal_validate_form($form_id, $form) {
  185. global $form_values;
  186. static $validated_forms = array();
  187.  
  188. @@ -175,14 +244,12 @@ function drupal_validate_form($form_id,
  189. * theming, and hook_form_alter functions.
  190. * @param $form
  191. * An associative array containing the structure of the form.
  192. - * @param $callback
  193. - * An optional callback that will be used in addition to the form_id.
  194. * @return
  195. * A string containing the path of the page to display when processing
  196. * is complete.
  197. *
  198. */
  199. -function drupal_submit_form($form_id, $form, $callback = NULL) {
  200. +function drupal_submit_form($form_id, $form) {
  201. global $form_values;
  202. $default_args = array($form_id, &$form_values);
  203.  
  204. @@ -209,21 +276,21 @@ function drupal_submit_form($form_id, $f
  205. * theming, and hook_form_alter functions.
  206. * @param $form
  207. * An associative array containing the structure of the form.
  208. - * @param $callback
  209. - * An optional callback that will be used in addition to the form_id.
  210. + * @param $base
  211. + * An optional function prefix that will be used in addition to the form_id.
  212. * @return
  213. * A string containing the path of the page to display when processing
  214. * is complete.
  215. *
  216. */
  217. -function drupal_render_form($form_id, &$form, $callback = NULL) {
  218. +function drupal_render_form($form_id, &$form, $base = NULL) {
  219. // Don't override #theme if someone already set it.
  220. if (!isset($form['#theme'])) {
  221. if (theme_get_function($form_id)) {
  222. $form['#theme'] = $form_id;
  223. }
  224. - elseif (theme_get_function($callback)) {
  225. - $form['#theme'] = $callback;
  226. + elseif (theme_get_function($base)) {
  227. + $form['#theme'] = $base;
  228. }
  229. }
  230.  
  231. @@ -408,8 +475,8 @@ function form_builder($form_id, $form) {
  232. $form['#id'] = 'edit-' . implode('-', $form['#parents']);
  233. }
  234.  
  235. - $posted = (isset($_POST['edit']) && ($_POST['edit']['form_id'] == $form_id));
  236. - $edit = $posted ? $_POST['edit'] : array();
  237. + $posted = (($form['#programmed']) || (isset($_POST['edit']) && ($_POST['edit']['form_id'] == $form_id)));
  238. + $edit = $posted ? $form['#post']['edit'] : array();
  239. foreach ($form['#parents'] as $parent) {
  240. $edit = isset($edit[$parent]) ? $edit[$parent] : NULL;
  241. }
  242. @@ -490,6 +557,8 @@ function form_builder($form_id, $form) {
  243. // Recurse through all child elements.
  244. $count = 0;
  245. foreach (element_children($form) as $key) {
  246. + $form[$key]['#post'] = $form['#post'];
  247. + $form[$key]['#programmed'] = $form['#programmed'];
  248. // don't squash an existing tree value
  249. if (!isset($form[$key]['#tree'])) {
  250. $form[$key]['#tree'] = $form['#tree'];
  251. @@ -769,7 +838,7 @@ function password_confirm_validate($form
  252. form_error($form, t('The specified passwords do not match.'));
  253. }
  254. }
  255. - elseif ($form['#required'] && !empty($_POST['edit'])) {
  256. + elseif ($form['#required'] && !empty($form['#post']['edit'])) {
  257. form_error($form, t('Password field is required.'));
  258. }
  259.  
  260. === modified file 'includes/menu.inc'
  261. --- includes/menu.inc
  262. +++ includes/menu.inc
  263. @@ -415,7 +415,15 @@ function menu_execute_active_handler() {
  264. $arguments = array_merge($arguments, explode('/', $arg));
  265. }
  266.  
  267. - return call_user_func_array($menu['callbacks'][$path]['callback'], $arguments);
  268. + $callback = $menu['callbacks'][$path]['callback'];
  269. + $return = call_user_func_array($callback, $arguments);
  270. +
  271. + // A menu callback that returns an array always consists of a form definition. Then we push $return to
  272. + // drupal_process_form(). Modules may submit forms programmatically using an analogous "push".
  273. + if (is_array($return)) {
  274. + return drupal_process_form($callback, $return);
  275. + }
  276. + return $return;
  277. }
  278.  
  279. /**
  280. === modified file 'install.php'
  281. --- install.php
  282. +++ install.php
  283. @@ -101,7 +101,7 @@ function install_verify_settings() {
  284. $db_path = ltrim(urldecode($url['path']), '/');
  285. $settings_file = './'. conf_path() .'/settings.php';
  286.  
  287. - _install_settings_validate($db_prefix, $db_type, $db_user, $db_pass, $db_host, $db_path, $settings_file);
  288. + _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pass, $db_host, $db_path, $settings_file);
  289. if (!form_get_errors()) {
  290. return TRUE;
  291. }
  292. @@ -124,13 +124,12 @@ function install_change_settings() {
  293.  
  294. // We always need this because we want to run form_get_errors.
  295. include_once './includes/form.inc';
  296. + drupal_maintenance_theme();
  297.  
  298. // The existing database settings are not working, so we need write access
  299. // to settings.php to change them.
  300. if (!drupal_verify_install_file($settings_file, FILE_EXIST|FILE_READABLE|FILE_WRITABLE)) {
  301. - drupal_maintenance_theme();
  302. drupal_set_message(st('The Drupal installer requires write permissions to %file during the installation process.', array('%file' => $settings_file)), 'error');
  303. -
  304. drupal_set_title('Drupal database setup');
  305. print theme('install_page', '');
  306. exit;
  307. @@ -141,8 +140,18 @@ function install_change_settings() {
  308. $db_user = $db_pass = $db_path = '';
  309. }
  310.  
  311. + $output = drupal_get_form('install_settings_form', $profile, $settings_file, $db_url, $db_type, $db_prefix, $db_user, $db_pass, $db_host);
  312. + drupal_set_title('Database configuration');
  313. + print theme('install_page', $output);
  314. + exit;
  315. +}
  316. +
  317.  
  318. +/**
  319. + * Form API array definition for install_settings.
  320. + */
  321.  
  322. +function install_settings_form($profile, $settings_file, $db_url, $db_type, $db_prefix, $db_user, $db_pass, $db_host) {
  323. $db_types = drupal_detect_database_types();
  324. if (count($db_types) == 0) {
  325. $form['no_db_types'] = array(
  326. @@ -251,26 +260,21 @@ function install_change_settings() {
  327. $form['_db_url'] = array('#type' => 'value');
  328. $form['#action'] = "install.php?profile=$profile";
  329. $form['#redirect'] = NULL;
  330. - drupal_maintenance_theme();
  331. }
  332. - $output = drupal_get_form('install_settings', $form);
  333. - drupal_set_title('Database configuration');
  334. - print theme('install_page', $output);
  335. - exit;
  336. + return $form;
  337. }
  338. -
  339. /**
  340. * Form API validate for install_settings form.
  341. */
  342. -function install_settings_validate($form_id, $form_values, $form) {
  343. +function install_settings_form_validate($form_id, $form_values, $form) {
  344. global $db_url;
  345. - _install_settings_validate($form_values['db_prefix'], $form_values['db_type'], $form_values['db_user'], $form_values['db_pass'], $form_values['db_host'], $form_values['db_path'], $form_values['settings_file'], $form);
  346. + _install_settings_form_validate($form_values['db_prefix'], $form_values['db_type'], $form_values['db_user'], $form_values['db_pass'], $form_values['db_host'], $form_values['db_path'], $form_values['settings_file'], $form);
  347. }
  348.  
  349. /**
  350. * Helper function for install_settings_validate.
  351. */
  352. -function _install_settings_validate($db_prefix, $db_type, $db_user, $db_pass, $db_host, $db_path, $settings_file, $form = NULL) {
  353. +function _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pass, $db_host, $db_path, $settings_file, $form = NULL) {
  354. global $db_url;
  355.  
  356. // Check for default username/password
  357. @@ -314,7 +318,7 @@ function _install_settings_validate($db_
  358. /**
  359. * Form API submit for install_settings form.
  360. */
  361. -function install_settings_submit($form_id, $form_values) {
  362. +function install_settings_form_submit($form_id, $form_values) {
  363. global $profile;
  364.  
  365. // Update global settings array and save
  366. @@ -350,42 +354,46 @@ function install_select_profile() {
  367. return $profile->name;
  368. }
  369. elseif (sizeof($profiles) > 1) {
  370. - drupal_maintenance_theme();
  371. - $form = '';
  372. foreach ($profiles as $profile) {
  373. - include_once($profile->filename);
  374. if ($_POST['edit']['profile'] == $profile->name) {
  375. return $profile->name;
  376. }
  377. - // Load profile details.
  378. - $function = $profile->name .'_profile_details';
  379. - if (function_exists($function)) {
  380. - $details = $function();
  381. - }
  382. -
  383. - // If set, used defined name. Otherwise use file name.
  384. - $name = isset($details['name']) ? $details['name'] : $profile->name;
  385. -
  386. - $form['profile'][$name] = array(
  387. - '#type' => 'radio',
  388. - '#value' => 'default',
  389. - '#return_value' => $profile->name,
  390. - '#title' => $name,
  391. - '#description' => isset($details['description']) ? $details['description'] : '',
  392. - '#parents' => array('profile'),
  393. - );
  394. }
  395. - $form['submit'] = array(
  396. - '#type' => 'submit',
  397. - '#value' => 'Save configuration',
  398. - );
  399. +
  400. + drupal_maintenance_theme();
  401.  
  402. drupal_set_title('Select an installation profile');
  403. - print theme('install_page', drupal_get_form('install_select_profile', $form));
  404. + print theme('install_page', drupal_get_form('install_select_profile_form', $profiles));
  405. exit;
  406. }
  407. }
  408.  
  409. +function install_select_profile_form($profiles) {
  410. + foreach ($profiles as $profile) {
  411. + include_once($profile->filename);
  412. + // Load profile details.
  413. + $function = $profile->name .'_profile_details';
  414. + if (function_exists($function)) {
  415. + $details = $function();
  416. + }
  417. + // If set, used defined name. Otherwise use file name.
  418. + $name = isset($details['name']) ? $details['name'] : $profile->name;
  419. + $form['profile'][$name] = array(
  420. + '#type' => 'radio',
  421. + '#value' => 'default',
  422. + '#return_value' => $profile->name,
  423. + '#title' => $name,
  424. + '#description' => isset($details['description']) ? $details['description'] : '',
  425. + '#parents' => array('profile'),
  426. + );
  427. + }
  428. + $form['submit'] = array(
  429. + '#type' => 'submit',
  430. + '#value' => 'Save configuration',
  431. + );
  432. + return $form;
  433. +}
  434. +
  435. /**
  436. * Show an error page when there are no profiles available.
  437. */
  438. === modified file 'modules/aggregator/aggregator.module'
  439. --- modules/aggregator/aggregator.module
  440. +++ modules/aggregator/aggregator.module
  441. @@ -170,9 +170,9 @@ function aggregator_menu($may_cache) {
  442. }
  443. }
  444. }
  445. - else if (arg(1) == 'aggregator' && is_numeric(arg(4))) {
  446. - if (arg(3) == 'feed') {
  447. - $feed = aggregator_get_feed(arg(4));
  448. + else if (arg(2) == 'aggregator' && is_numeric(arg(5))) {
  449. + if (arg(4) == 'feed') {
  450. + $feed = aggregator_get_feed(arg(5));
  451. if ($feed) {
  452. $items[] = array('path' => 'admin/content/aggregator/edit/feed/'. $feed['fid'],
  453. 'title' => t('edit feed'),
  454. @@ -183,7 +183,7 @@ function aggregator_menu($may_cache) {
  455. }
  456. }
  457. else {
  458. - $category = aggregator_get_category(arg(4));
  459. + $category = aggregator_get_category(arg(5));
  460. if ($category) {
  461. $items[] = array('path' => 'admin/content/aggregator/edit/category/'. $category['cid'],
  462. 'title' => t('edit category'),
  463. @@ -227,7 +227,7 @@ function aggregator_admin_settings() {
  464. '#description' => t('The type of category selection widget which is shown on categorization pages. Checkboxes are easier to use; a multiple selector is good for working with large numbers of categories.')
  465. );
  466.  
  467. - return system_settings_form('aggregator_admin_settings', $form);
  468. + return system_settings_form($form);
  469. }
  470.  
  471. /**
  472. @@ -336,7 +336,7 @@ function aggregator_block($op, $delta =
  473. $form['cid'] = array('#type' => 'hidden', '#value' => $edit['cid']);
  474. }
  475.  
  476. - return drupal_get_form('aggregator_form_category', $form);
  477. + return $form;
  478. }
  479.  
  480. /**
  481. @@ -467,7 +467,7 @@ function aggregator_form_feed($edit = ar
  482. $form['fid'] = array('#type' => 'hidden', '#value' => $edit['fid']);
  483. }
  484.  
  485. - return drupal_get_form('aggregator_form_feed', $form);
  486. + return $form;
  487. }
  488.  
  489. /**
  490. @@ -1049,28 +1049,15 @@ function aggregator_page_category() {
  491. return _aggregator_page_list('SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_category_item} c LEFT JOIN {aggregator_item} i ON c.iid = i.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE cid = '. $category->cid .' ORDER BY timestamp DESC, iid DESC', arg(3));
  492. }
  493.  
  494. -/**
  495. - * Prints an aggregator page listing a number of feed items. Various
  496. - * menu callbacks use this function to print their feeds.
  497. - */
  498. -function _aggregator_page_list($sql, $op, $header = '') {
  499. - $categorize = (user_access('administer news feeds') && ($op == 'categorize'));
  500. -
  501. - $output = '<div id="aggregator">';
  502. -
  503. +function aggregator_page_list($sql, $header, $categorize) {
  504. $form['header'] = array('#value' => $header);
  505. - $output .= $form['header']['#value'];
  506. -
  507. $result = pager_query($sql, 20);
  508. $categories = array();
  509. $done = FALSE;
  510. while ($item = db_fetch_object($result)) {
  511. $form['items'][$item->iid] = array('#value' => theme('aggregator_page_item', $item));
  512. - $output .= $form['items'][$item->iid]['#value'];
  513. $form['categories'][$item->iid] = array();
  514. -
  515. if ($categorize) {
  516. -
  517. $categories_result = db_query('SELECT c.cid, c.title, ci.iid FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid AND ci.iid = %d', $item->iid);
  518. $selected = array();
  519. while ($category = db_fetch_object($categories_result)) {
  520. @@ -1089,11 +1076,8 @@ function _aggregator_page_list($sql, $op
  521. );
  522. }
  523. }
  524. - $output .= '</div>';
  525. $form['submit'] = array('#type' => 'submit', '#value' => t('Save categories'));
  526. $form['pager'] = array('#value' => theme('pager', NULL, 20, 0));
  527. - $output .= $form['pager']['#value'];
  528. -
  529. // arg(1) is undefined if we are at the top aggregator URL
  530. // is there a better way to do this?
  531. if (!arg(1)) {
  532. @@ -1102,9 +1086,30 @@ function _aggregator_page_list($sql, $op
  533. elseif (arg(1) == 'categories' && arg(2) && !arg(3)) {
  534. $form['feed_icon'] = array('#value' => theme('feed_icon', url('aggregator/rss/' . arg(2))));
  535. }
  536. - $output .= $form['feed_icon']['#value'];
  537. + return $form;
  538. +}
  539.  
  540. - return ($categorize) ? drupal_get_form('aggregator_page_list', $form) : $output;
  541. +/**
  542. + * Prints an aggregator page listing a number of feed items. Various
  543. + * menu callbacks use this function to print their feeds.
  544. + */
  545. +function _aggregator_page_list($sql, $op, $header = '') {
  546. + $categorize = (user_access('administer news feeds') && ($op == 'categorize'));
  547. + $form = aggregator_page_list($sql, $header, $categorize);
  548. + if ($categorize) {
  549. + return $form;
  550. + }
  551. + else {
  552. + $output = '<div id="aggregator">';
  553. + $output .= $header;
  554. + foreach ($form['items'] as $item) {
  555. + $output .= $item['#value'];
  556. + }
  557. + $output .= '</div>';
  558. + $output .= $form['pager']['#value'];
  559. + $output .= $form['feed_icon']['#value'];
  560. + return $output;
  561. + }
  562. }
  563.  
  564. function theme_aggregator_page_list($form) {
  565. === modified file 'modules/block/block.module'
  566. --- modules/block/block.module
  567. +++ modules/block/block.module
  568. @@ -84,7 +84,7 @@ function block_menu($may_cache) {
  569. 'type' => MENU_CALLBACK);
  570. $items[] = array('path' => 'admin/build/block/add', 'title' => t('add block'),
  571. 'access' => user_access('administer blocks'),
  572. - 'callback' => 'block_box_add',
  573. + 'callback' => 'block_box_form',
  574. 'type' => MENU_LOCAL_TASK);
  575. foreach (list_themes() as $key => $theme) {
  576. if ($theme->status) {
  577. @@ -245,7 +245,7 @@ function block_admin_display($theme = NU
  578. }
  579. $form['submit'] = array('#type' => 'submit', '#value' => t('Save blocks'));
  580.  
  581. - return drupal_get_form('block_admin_display', $form);
  582. + return $form;
  583. }
  584.  
  585. /**
  586. @@ -468,7 +468,7 @@ function block_admin_configure($module =
  587. '#value' => t('Save block'),
  588. );
  589.  
  590. - return drupal_get_form('block_admin_configure', $form);
  591. + return $form;
  592. }
  593.  
  594. function block_admin_configure_validate($form_id, $form_values) {
  595. @@ -493,23 +493,13 @@ function block_admin_configure_submit($f
  596. }
  597. }
  598.  
  599. -/**
  600. - * Menu callback; displays the block creation form.
  601. - */
  602. -function block_box_add() {
  603. - $form = block_box_form();
  604. - $form['submit'] = array('#type' => 'submit', '#value' => t('Save block'));
  605. -
  606. - return drupal_get_form('block_box_add', $form);
  607. -}
  608. -
  609. -function block_box_add_validate($form_id, $form_values) {
  610. +function block_box_form_validate($form_id, $form_values) {
  611. if (empty($form_values['info']) || db_num_rows(db_query("SELECT info FROM {boxes} WHERE info = '%s'", $form_values['info']))) {
  612. form_set_error('info', t('Please ensure that each block description is unique.'));
  613. }
  614. }
  615.  
  616. -function block_box_add_submit($form_id, $form_values) {
  617. +function block_box_form_submit($form_id, $form_values) {
  618. if (!form_get_errors()) {
  619. if (block_box_save($form_values)) {
  620. drupal_set_message(t('The block has been created.'));
  621. @@ -526,13 +516,13 @@ function block_box_delete($bid = 0) {
  622. $form['info'] = array('#type' => 'hidden', '#value' => $box['info'] ? $box['info'] : $box['title']);
  623. $form['bid'] = array('#type' => 'hidden', '#value' => $bid);
  624.  
  625. - return confirm_form('block_box_delete_confirm', $form, t('Are you sure you want to delete the block %name?', array('%name' => theme('placeholder', $box['info']))), 'admin/build/block', '', t('Delete'), t('Cancel'));
  626. + return confirm_form($form, t('Are you sure you want to delete the block %name?', array('%name' => theme('placeholder', $box['info']))), 'admin/build/block', '', t('Delete'), t('Cancel'));
  627. }
  628.  
  629. /**
  630. * Deletion of custom blocks.
  631. */
  632. -function block_box_delete_confirm_submit($form_id, $form_values) {
  633. +function block_box_delete_submit($form_id, $form_values) {
  634. db_query('DELETE FROM {boxes} WHERE bid = %d', $form_values['bid']);
  635. drupal_set_message(t('The block %name has been removed.', array('%name' => theme('placeholder', $form_values['info']))));
  636. cache_clear_all();
  637. @@ -567,6 +557,7 @@ function block_box_form($edit = array())
  638. '#weight' => -17,
  639. );
  640. $form['body_filter']['format'] = filter_form($edit['format'], -16);
  641. + $form['submit'] = array('#type' => 'submit', '#value' => t('Save block'));
  642.  
  643. return $form;
  644. }
  645. === modified file 'modules/blogapi/blogapi.module'
  646. --- modules/blogapi/blogapi.module
  647. +++ modules/blogapi/blogapi.module
  648. @@ -556,7 +556,7 @@ function blogapi_admin_settings() {
  649. '#description' => t('Select the content types for which you wish to enable posting via blogapi. Each type will appear as a different "blog" in the client application (if supported).')
  650. );
  651.  
  652. - return system_settings_form('blogapi_admin_settings', $form);
  653. + return system_settings_form($form);
  654. }
  655.  
  656. function blogapi_menu($may_cache) {
  657. === modified file 'modules/book/book.module'
  658. --- modules/book/book.module
  659. +++ modules/book/book.module
  660. @@ -324,7 +324,7 @@ function book_outline($nid) {
  661. }
  662.  
  663. drupal_set_title(check_plain($node->title));
  664. - return drupal_get_form('book_outline', $form);
  665. + return $form;
  666. }
  667.  
  668. /**
  669. @@ -891,7 +891,7 @@ function book_admin_edit($nid) {
  670. '#value' => t('Save book pages'),
  671. );
  672.  
  673. - return drupal_get_form('book_admin_edit', $form);
  674. + return $form;
  675. }
  676. else {
  677. drupal_not_found();
  678. @@ -919,19 +919,18 @@ function book_admin_orphan() {
  679. }
  680.  
  681. if (count($orphans)) {
  682. - $form = array();
  683. -
  684. $form['table'] = _book_admin_table($orphans);
  685. $form['save'] = array(
  686. '#type' => 'submit',
  687. '#value' => t('Save book pages'),
  688. );
  689.  
  690. - return drupal_get_form('book_admin_edit', $form);
  691. }
  692. else {
  693. - return '<p>'. t('There are no orphan pages.') .'</p>';
  694. + $form['error'] = array('#value' => '<p>'. t('There are no orphan pages.') .'</p>');
  695. }
  696. + $form['#function_prefix'] = 'book_admin_edit';
  697. + return $form;
  698. }
  699.  
  700. function book_admin_edit_submit($form_id, $form_values) {
  701. === modified file 'modules/comment/comment.module'
  702. --- modules/comment/comment.module
  703. +++ modules/comment/comment.module
  704. @@ -466,7 +466,7 @@ function comment_admin_settings() {
  705. '#options' => array(t('Display on separate page'), t('Display below post or comments')),
  706. );
  707.  
  708. - return system_settings_form('comment_admin_settings', $form);
  709. + return system_settings_form($form);
  710. }
  711.  
  712. /**
  713. @@ -496,7 +496,7 @@ function comment_edit($cid) {
  714. $comment = drupal_unpack($comment);
  715. $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
  716. if (comment_access('edit', $comment)) {
  717. - return comment_form((array)$comment);
  718. + return comment_form_box((array)$comment);
  719. }
  720. else {
  721. drupal_access_denied();
  722. @@ -517,7 +517,7 @@ function comment_reply($nid, $pid = NULL
  723.  
  724. if ($op == t('Preview comment')) {
  725. if (user_access('post comments')) {
  726. - $output .= comment_form(array('pid' => $pid, 'nid' => $nid), NULL);
  727. + $output .= comment_form_box(array('pid' => $pid, 'nid' => $nid), NULL);
  728. }
  729. else {
  730. drupal_set_message(t('You are not authorized to post comments.'), 'error');
  731. @@ -553,7 +553,7 @@ function comment_reply($nid, $pid = NULL
  732. drupal_goto("node/$nid");
  733. }
  734. else if (user_access('post comments')) {
  735. - $output .= comment_form(array('pid' => $pid, 'nid' => $nid), t('Reply'));
  736. + $output .= comment_form_box(array('pid' => $pid, 'nid' => $nid), t('Reply'));
  737. }
  738. else {
  739. drupal_set_message(t('You are not authorized to post comments.'), 'error');
  740. @@ -891,7 +891,7 @@ function comment_render($node, $cid = 0)
  741. // Start a form, for use with comment control.
  742. $result = pager_query($query, $comments_per_page, 0, $query_count, $query_args);
  743. if (db_num_rows($result) && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) {
  744. - $output .= comment_controls($mode, $order, $comments_per_page);
  745. + $output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page);
  746. }
  747.  
  748. while ($comment = db_fetch_object($result)) {
  749. @@ -916,13 +916,13 @@ function comment_render($node, $cid = 0)
  750. $output .= theme('pager', NULL, $comments_per_page, 0);
  751.  
  752. if (db_num_rows($result) && (variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_BELOW || variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN) == COMMENT_CONTROLS_ABOVE_BELOW)) {
  753. - $output .= comment_controls($mode, $order, $comments_per_page);
  754. + $output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page);
  755. }
  756. }
  757.  
  758. // If enabled, show new comment form.
  759. if (user_access('post comments') && node_comment_mode($nid) == COMMENT_NODE_READ_WRITE && (variable_get('comment_form_location', COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_BELOW)) {
  760. - $output .= comment_form(array('nid' => $nid), t('Post new comment'));
  761. + $output .= comment_form_box(array('nid' => $nid), t('Post new comment'));
  762. }
  763.  
  764. $output = theme('comment_wrapper', $output);
  765. @@ -956,13 +956,7 @@ function comment_delete($cid) {
  766. drupal_goto("node/$comment->nid");
  767. }
  768. else if (is_object($comment) && is_numeric($comment->cid)) {
  769. - $output = confirm_form('comment_confirm_delete',
  770. - array(),
  771. - t(