Commit 7e1527ee authored by Dries's avatar Dries
Browse files

- Patch #29465: new form API by Adrian et al.

  TODO:
  + The contact.module was broken; a new patch for contact.module is needed.
  + Documentation is needed.
  + The most important modules need to be updated ASAP.
parent 7b5b4605
Drupal x.x.x, xxxx-xx-xx (development version)
------------------------
- added free tagging support (folksonomies).
- added free tagging support.
- added a site-wide contact form.
- refactored the form API.
- theme system:
* added the PHPTemplate theme engine and removed the Xtemplate engine.
* converted the bluemarine theme from XTemplate to PHPTemplate.
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -36,17 +36,22 @@ function _locale_add_language($code, $name, $onlylanguage = TRUE) {
* User interface for the language management screen
*/
function _locale_admin_manage_screen() {
$edit = &$_POST['edit'];
$languages = locale_supported_languages(TRUE, TRUE);
$header = array(array('data' => t('Code')), array('data' => t('English name')), array('data' => t('Enabled')), array('data' => t('Default')), array('data' => t('Translated')), array('data' => t('Operations')));
$options = array();
$form[action] = url('admin/locale');
$form['name'] = array(tree => TRUE);
foreach ($languages['name'] as $key => $lang) {
$options[$key] = '';
$status = db_fetch_object(db_query("SELECT isdefault, enabled FROM {locales_meta} WHERE locale = '%s'", $key));
if ($status->enabled) {
$enabled[] = $key;
}
if ($status->isdefault) {
$isdefault = $key;
}
if ($key == 'en') {
$rows[] = array('en', check_plain($lang), form_checkbox('', 'enabled][en', 1, $status->enabled), form_radio('', 'sitedefault', $key, $status->isdefault), message_na(), '');
$form['name']['en'] = array(type => 'markup', value => check_plain($lang));
}
else {
$original = db_fetch_object(db_query("SELECT COUNT(*) AS strings FROM {locales_source}"));
......@@ -54,11 +59,28 @@ function _locale_admin_manage_screen() {
$ratio = ($original->strings > 0 && $translation->translation > 0) ? round(($translation->translation/$original->strings)*100., 2) : 0;
$rows[] = array(check_plain($key), ($key != 'en' ? form_textfield('', 'name]['. $key, $lang, 15, 64) : $lang), form_checkbox('', 'enabled]['. $key, 1, $status->enabled), form_radio('', 'sitedefault', $key, $status->isdefault), "$translation->translation/$original->strings ($ratio%)", ($key != 'en' ? l(t('delete'), 'admin/locale/language/delete/'. urlencode($key)) : ''));
$form['name'][$key] = array(type => 'textfield', default_value => $lang, size => 15, maxlength => 64);
$form['translation'][$key] = array(type => 'markup', default_value => "$translation->translation/$original->strings ($ratio%)");
}
}
$form['enabled'] = array(type => 'checkboxes', options => $options, default_value => $enabled, return_value => 1);
$form['sitedefault'] = array(type => 'radios', options => $options, default_value => $isdefault, return_value => 1);
$form['submit'] = array(type => 'submit', value => t('Save configuration'));
return drupal_get_form('_locale_admin_manage_screen', $form);
}
return form(theme('table', $header, $rows) . form_submit(t('Save configuration')), 'post', url('admin/locale'));
function theme__locale_admin_manage_screen($form) {
foreach ($form['name'] as $key => $element) {
// Don't take form control structures
if (is_array($element) && element_child($key)) {
$rows[] = array(check_plain($key), form_render($form['name'][$key]), form_render($form['enabled'][$key]), form_render($form['sitedefault'][$key]), ($key != 'en' ? form_render($form['translation'][$key]) : message_na()), ($key != 'en' ? l(t('delete'), 'admin/locale/language/delete/'. urlencode($key)) : ''));
}
}
$header = array(array('data' => t('Code')), array('data' => t('English name')), array('data' => t('Enabled')), array('data' => t('Default')), array('data' => t('Translated')), array('data' => t('Operations')));
$output = theme('table', $header, $rows);
$output .= form_render($form);
return $output;
}
/**
......@@ -68,28 +90,30 @@ function _locale_admin_manage_add_screen() {
$isocodes = _locale_prepare_iso_list();
$output = '<h2>'. t('From language list') .'</h2>';
$form = form_select(t('Language name'), 'langcode', key($isocodes), $isocodes, t('Select your language here, or add it below, if you are unable to find it.'));
$form .= form_submit(t('Add language'));
$output .= form($form);
$form = array();
$form['header'] = array(prefix => '<h2>', value => t('Language list'), suffix => '</h2>');
$form['langcode'] = array(type => 'select', title => t('Language name'), default_value => key($isocodes), options => $isocodes, description => t('Select your language here, or add it below, if you are unable to find it.'));
$form['submit'] = array(type => 'submit', value => t('Add language'));
$output = drupal_get_form('locale_add_language', $form);
$edit = &$_POST['edit'];
$output .= '<h2>'. t('Custom language') .'</h2>';
$form = form_textfield(t('Language code'), 'langcode', $edit['langcode'], 60, 12, t("Commonly this is an <a href=\"%iso-codes\">ISO 639 language code</a> with an optional country code for regional variants. Examples include 'en', 'en-US' and 'zh-cn'.", array('%iso-codes' => 'http://www.w3.org/WAI/ER/IG/ert/iso639.htm')));
$form .= form_textfield(t('Language name in English'), 'langname', $edit['langname'], 60, 64, t('Name of the language. Will be available for translation in all languages.'));
$form .= form_submit(t('Add language'));
$output .= form($form);
$form = array();
$form['header'] = array(prefix => '<h2>', value => t('Custom language') , suffix => '</h2>');
$form['langcode'] = array(type => 'textfield', title => t('Language code'), default_value => $edit['langcode'], size => 12, maxlength => 60, description => t("Commonly this is an <a href=\"%iso-codes\">ISO 639 language code</a> with an optional country code for regional variants. Examples include 'en', 'en-US' and 'zh-cn'.", array('%iso-codes' => 'http://www.w3.org/WAI/ER/IG/ert/iso639.htm')));
$form['langname'] = array(type => 'textfield', title => t('Language name in English'), default_value => $edit['langname'], size => 60, maxlength => 64, description => t('Name of the language. Will be available for translation in all languages.'));
$form['submit'] = array(type => 'submit', value => t('Add custom language'));
$output .= drupal_get_form('_locale_custom_language', $form);
return $output;
}
/**
* User interface for the translation import screen
*/
function _locale_admin_import_screen() {
$languages = locale_supported_languages(FALSE, TRUE);
$languages = array_map("t", $languages['name']);
$languages = array_map('t', $languages['name']);
unset($languages['en']);
if (!count($languages)) {
......@@ -102,12 +126,15 @@ function _locale_admin_import_screen() {
);
}
$form = form_file(t('Language file'), 'file', 50, t('A gettext Portable Object (.po) file.'));
$form .= form_select(t('Import into'), 'langcode', '', $languages, t('Choose the language you want to add strings into. If you choose a language which is not yet set up, then it will be added.'));
$form .= form_radios(t('Mode'), 'mode', 'overwrite', array('overwrite' => t('Strings in the uploaded file replace existing ones, new ones are added'), 'keep' => t('Existing strings are kept, only new strings are added')));
$form .= form_submit(t('Import'));
$output = form($form, 'post', url('admin/locale/language/import'), array('enctype' => 'multipart/form-data'));
return $output;
$form = array();
$form['file'] = array(type => 'file', title => t('Language file'), size => 50, description => t('A gettext Portable Object (.po) file.'));
$form['langcode'] = array(type => 'select', title => t('Import into'), options => $languages, description => t('Choose the language you want to add strings into. If you choose a language which is not yet set up, then it will be added.'));
$form['mode'] = array(type => 'radios', title => t('Mode'), default_value => 'overwrite', options => array('overwrite' => t('Strings in the uploaded file replace existing ones, new ones are added'), 'keep' => t('Existing strings are kept, only new strings are added')));
$form['submit'] = array(type => 'submit', value => t('Import'));
$form[attributes]['enctype'] = 'multipart/form-data';
$form[action] = 'admin/locale/language/import';
return drupal_get_form('_locale_admin_import', $form);
}
/**
......@@ -705,16 +732,18 @@ function _locale_admin_export_screen() {
// Offer language specific export if any language is set up
if (count($languages)) {
$output .= '<h2>'. t('Export translation') .'</h2>';
$form = form_select(t('Language name'), 'langcode', '', $languages, t('Select the language you would like to export in gettext Portable Object (.po) format.'));
$form .= form_submit(t('Export'));
$output .= form($form);
$form = array();
$form['langcode'] = array(type => 'select', title => t('Language name'), options => $languages, description => t('Select the language you would like to export in gettext Portable Object (.po) format.'));
$form['submit'] = array(type => 'submit', value => t('Export'));
$output .= drupal_get_form('_locale_export_po', $form);
}
// Complete template export of the strings
$output .= '<h2>'. t('Export template') .'</h2>';
$form = t('<p>Generate a gettext Portable Object Template (.pot) file with all the interface strings from the Drupal locale database.</p>');
$form .= form_submit(t('Export'));
$output .= form($form);
$output .= t('<p>Generate a gettext Portable Object Template (.pot) file with all the interface strings from the Drupal locale database.</p>');
$form = array();
$form['submit'] = array(type => 'submit', value => t('Export'));
$output .= drupal_get_form('_locale_export_pot', $form);
return $output;
}
......@@ -947,20 +976,24 @@ function _locale_string_edit($lid) {
unset($languages['name']['en']);
$result = db_query('SELECT DISTINCT s.source, t.translation, t.locale FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE s.lid = %d', $lid);
$form = '';
$form = array();
while ($translation = db_fetch_object($result)) {
$orig = $translation->source;
$form .= (strlen($orig) > 40) ? form_textarea($languages['name'][$translation->locale], $translation->locale, $translation->translation, 60, 15) : form_textfield($languages['name'][$translation->locale], $translation->locale, $translation->translation, 60, 128);
$form[$translation->locale] = (strlen($orig) > 40) ?
array(type => 'textarea', title => $languages['name'][$translation->locale], default_value => $translation->translation, cols => 60, rows => 15)
: array(type => 'textfield', title => $languages['name'][$translation->locale], default_value => $translation->translation, size => 60, maxlength => 128);
unset($languages['name'][$translation->locale]);
}
$form = array(type => 'item', title => t('Original text'), value => wordwrap(check_plain($orig, 0)));
foreach ($languages['name'] as $key => $lang) {
$form .= (strlen($orig) > 40) ? form_textarea($lang, $key, '', 60, 15) : form_textfield($lang, $key, '', 60, 128);
$form[$key] = (strlen($orig) > 40) ?
array(type => 'textarea', title => $lang, cols => 60, rows => 15) :
array(type => 'textfield', title => $lang, size => 60, maxlength => 128);
}
$form = form_item(t('Original text'), wordwrap(check_plain($orig, 0))) . $form;
$form .= form_submit(t('Save translations'));
$form['submit'] = array(type => 'submit', value => t('Save translations'));
return form($form);
return $form;
}
/**
......@@ -1065,9 +1098,12 @@ function _locale_string_seek() {
}
}
$output .= theme('table', $header, $rows);
$output .= theme('pager', NULL, 50, 0, $request);
if (count($rows)) {
$output .= theme('table', $header, $rows);
}
if ($pager = theme('pager', NULL, 50, 0, $request)) {
$output .= $pager;
}
}
return $output;
......@@ -1085,14 +1121,15 @@ function _locale_string_seek_form() {
// Present edit form preserving previous user settings
$query = _locale_string_seek_query();
$form .= form_textfield(t('Strings to search for'), 'string', $query->string, 30, 30, t('Leave blank to show all strings. The search is case sensitive.'));
$form .= form_radios(t('Language'), 'language', ($query->language ? $query->language : 'all'), array_merge(array('all' => t('All languages'), 'en' => t('English (provided by Drupal)')), $languages['name']));
$form .= form_radios(t('Search in'), 'searchin', ($query->searchin ? $query->searchin : 'all'), array('all' => t('All strings in that language'), 'translated' => t('Only translated strings'), 'untranslated' => t('Only untranslated strings')));
$form .= form_submit(t('Search'));
$output = form(form_group(t('Search strings'), $form), 'post', url('admin/locale/string/search'));
return $output;
$form = array();
$form['search'] = array(type => 'fieldset', title => t('Search'));
$form['search']['string'] = array(type => 'textfield', title => t('Strings to search for'), default_value => $query->string, size => 30, maxlength => 30, description => t('Leave blank to show all strings. The search is case sensitive.'));
$form['search']['language'] = array(type => 'radios', title => t('Language'), default_value => ($query->language ? $query->language : 'all'), options => array_merge(array('all' => t('All languages'), 'en' => t('English (provided by Drupal)')), $languages['name']));
$form['search']['searchin'] = array(type => 'radios', title => t('Search in'), default_value => ($query->searchin ? $query->searchin : 'all'), options => array('all' => t('All strings in that language'), 'translated' => t('Only translated strings'), 'untranslated' => t('Only untranslated strings')));
$form['search']['submit'] = array(type => 'submit', value => t('Search'));
$form[action] = 'admin/locale/string/search';
return drupal_get_form('_locale_string_seek', $form);
}
// ---------------------------------------------------------------------------------
......
......@@ -958,55 +958,6 @@ function theme_blocks($region) {
return $output;
}
/**
* Output a confirmation form
*
* This function outputs a complete form for confirming an action. A link is
* offered to go back to the item that is being changed in case the user changes
* his/her mind.
*
* You should use $_POST['edit'][$name] (where $name is usually 'confirm') to
* check if the confirmation was successful.
*
* @param $question
* The question to ask the user (e.g. "Are you sure you want to delete the
* block <em>foo</em>?").
* @param $path
* The page to go to if the user denies the action.
* @param $description
* Additional text to display (defaults to "This action cannot be undone.").
* @param $yes
* A caption for the button which confirms the action (e.g. "Delete",
* "Replace", ...).
* @param $no
* A caption for the link which denies the action (e.g. "Cancel").
* @param $extra
* Additional HTML to inject into the form, for example form_hidden()s.
* @param $name
* The internal name used to refer to the confirmation item.
* @return
* A themed HTML string representing the form.
*/
function theme_confirm($question, $path, $description = NULL, $yes = NULL, $no = NULL, $extra = NULL, $name = 'confirm') {
drupal_set_title($question);
if (is_null($description)) {
$description = t('This action cannot be undone.');
}
$output .= '<p>'. $description ."</p>\n";
if (!is_null($extra)) {
$output .= $extra;
}
$output .= '<div class="container-inline">';
$output .= form_submit($yes ? $yes : t('Confirm'));
$output .= l($no ? $no : t('Cancel'), $path);
$output .= "</div>\n";
$output .= form_hidden($name, 1);
return form($output, 'post', NULL, array('class' => 'confirmation'));
}
/**
* Format a username.
*
......
......@@ -81,7 +81,8 @@ function unicode_settings() {
$options = array(UNICODE_SINGLEBYTE => t('Standard PHP: operations on Unicode strings are emulated on a best-effort basis. Install the <a href="%url">PHP mbstring extension</a> for improved Unicode support.', array('%url' => 'http://www.php.net/mbstring')),
UNICODE_MULTIBYTE => t('Multi-byte: operations on Unicode strings are supported through the <a href="%url">PHP mbstring extension</a>.', array('%url' => 'http://www.php.net/mbstring')),
UNICODE_ERROR => t('Invalid: the current configuration is incompatible with Drupal.'));
return form_item(t('String handling method'), $options[$status]);
$form['settings'] = array(type => 'item', title =>t('String handling method'), value => $options[$status]);
return $form;
}
/**
......@@ -474,3 +475,4 @@ function drupal_substr($text, $start, $length = NULL) {
}
}
......@@ -629,3 +629,8 @@ html.js fieldset.collapsed legend a {
display: block;
}
/*
** Temporary CSS for porting of drupal forms.
*/
form { border: 3px solid red; }
form.form-api { border : 0px; }
......@@ -58,4 +58,4 @@ jsUpload.prototype.oncomplete = function (data) {
// Replace form and re-attach behaviour
$(this.wrapper).innerHTML = data;
uploadAutoAttach();
}
\ No newline at end of file
}
......@@ -72,12 +72,30 @@ function aggregator_settings() {
$items = array(0 => t('none')) + drupal_map_assoc(array(3, 5, 10, 15, 20, 25), '_aggregator_items');
$period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval');
$output = '';
$output .= form_textfield(t('Allowed HTML tags'), 'aggregator_allowed_html_tags', variable_get('aggregator_allowed_html_tags', '<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>'), 80, 255, t('The list of tags which are allowed in feeds, i.e., which will not be removed by Drupal.'));
$output .= form_select(t('Items shown in sources and categories pages'), 'aggregator_summary_items', variable_get('aggregator_summary_items', 3), $items, t('The number of items which will be shown with each feed or category in the feed and category summary pages.'));
$output .= form_select(t('Discard news items older than'), 'aggregator_clear', variable_get('aggregator_clear', 9676800), $period, t('Older news items will be automatically discarded. Requires crontab.'));
$output .= form_radios(t('Category selection type'), 'aggregator_category_selector', variable_get('aggregator_category_selector', 'check'), array('check' => t('checkboxes'), 'select' => t('multiple selector')), 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.'));
return $output;
$form['aggregator_allowed_html_tags'] = array(
type => 'textfield', title => t('Allowed HTML tags'), size => 80, maxlength => 255,
default_value => variable_get('aggregator_allowed_html_tags', '<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>'),
description => t('The list of tags which are allowed in feeds, i.e., which will not be removed by Drupal.')
);
$form['aggregator_summary_items'] = array(
type => 'select', title => t('Items shown in sources and categories pages') ,
default_value => variable_get('aggregator_summary_items', 3), options => $items,
description => t('The number of items which will be shown with each feed or category in the feed and category summary pages.')
);
$form['aggregator_clear'] = array(
type => 'select', title => t('Discard news items older than'),
default_value => variable_get('aggregator_clear', 9676800), options => $period,
description => t('Older news items will be automatically discarded. Requires crontab.')
);
$form['aggregator_category_selector'] = array(
type => 'radios', title => t('Category selection type'), default_value => variable_get('aggregator_category_selector', 'check'),
options => array('check' => t('checkboxes'), 'select' => t('multiple selector')),
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.')
);
return $form;
}
/**
......@@ -219,9 +237,8 @@ function aggregator_block($op, $delta = 0, $edit = array()) {
else {
$value = db_result(db_query('SELECT block FROM {aggregator_feed} WHERE fid = %d', $id));
}
$output = form_select(t('Number of news items in block'), 'block', $value, drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)));
return $output;
$form['block'] = array(type => 'select', title => t('Number of news items in block'), default_value => $value, options => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)));
return $form;
}
else if ($op == 'save') {
list($type, $id) = explode('-', $delta);
......@@ -658,16 +675,16 @@ function aggregator_save_item($edit) {
}
function aggregator_form_category($edit = array()) {
$form = form_textfield(t('Title'), 'title', $edit['title'], 60, 64);
$form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5);
$form .= form_submit(t('Submit'));
$form['title'] = array(type => 'textfield', title => t('Title'), default_value => $edit['title'], size => 60, maxlength => 64);
$form['description'] = array(type => 'textarea', title => t('Description'), default_value => $edit['description'], cols => 60, rows => 5);
$form['submit'] = array(type => 'submit', value =>t('Submit'));
if ($edit['cid']) {
$form .= form_submit(t('Delete'));
$form .= form_hidden('cid', $edit['cid']);
$form['delete'] = array(type => 'submit', value =>t('Delete'));
$form['cid'] = array(type => 'hidden', value => $edit['cid']);
}
return form($form);
return drupal_get_form('aggregator_form_category', $form);
}
function aggregator_save_category($edit) {
......@@ -691,9 +708,10 @@ function aggregator_form_feed($edit = array()) {
$edit['refresh'] = 3600;
}
$form .= form_textfield(t('Title'), 'title', $edit['title'], 60, 64, t('The name of the feed; typically the name of the web site you syndicate content from.'));
$form .= form_textfield(t('URL'), 'url', $edit['url'], 60, 255, t('The fully-qualified URL of the feed.'));
$form .= form_select(t('Update interval'), 'refresh', $edit['refresh'], $period, t('The refresh interval indicating how often you want to update this feed. Requires crontab.'));
$form['title'] = array(type => 'textfield', title => t('Title'), default_value => $edit['title'], size => 60, maxlength => 64, description => t('The name of the feed; typically the name of the web site you syndicate content from.'));
$form['url'] = array(type => 'textfield', title => t('URL'), default_value => $edit['url'], size => 60, maxlength => 255, description => t('The fully-qualified URL of the feed.'));
$form['refresh'] = array(type => 'select', title => t('Update interval'), default_value => $edit['refresh'], options => $period, description => t('The refresh interval indicating how often you want to update this feed. Requires crontab.'));
// Handling of categories:
$options = array();
......@@ -704,17 +722,16 @@ function aggregator_form_feed($edit = array()) {
if ($category->fid) $values[] = check_plain($category->cid);
}
if ($options) {
$form .= form_checkboxes(t('Categorize news items'), 'category', $values, $options, t('New items in this feed will be automatically filed in the checked categories as they are received.'));
$form['category'] = array(type => 'checkboxes', title => t('Categorize news items'), default_value => $values, options => $options, description => t('New items in this feed will be automatically filed in the checked categories as they are received.'));
}
$form['submit'] = array(type => 'submit', value =>t('Submit'));
// Form buttons:
$form .= form_submit(t('Submit'));
if ($edit['fid']) {
$form .= form_submit(t('Delete'));
$form .= form_hidden('fid', $edit['fid']);
$form['delete'] = array(type => 'submit', value =>t('Delete'));
$form['fid'] = array(type => 'hidden', value => $edit['fid']);
}
return form($form);
return drupal_get_form('aggregator_form_feed', $form);
}
function aggregator_save_feed($edit) {
......@@ -786,7 +803,6 @@ function aggregator_view() {
}
function aggregator_edit() {
if ($_POST['op'] == t('Submit')) {
if (arg(1) == 'categories') {
aggregator_save_category($_POST['edit']);
......@@ -941,83 +957,98 @@ function aggregator_page_category() {
* menu callbacks use this function to print their feeds.
*/
function _aggregator_page_list($sql, $op, $header = '') {
if (user_access('administer news feeds') && $op == 'categorize') {
if ($edit = $_POST['edit']) {
foreach ($edit['categories'] as $iid => $selection) {
db_query('DELETE FROM {aggregator_category_item} WHERE iid = %d', $iid);
foreach ($selection as $cid) {
if ($cid) {
db_query('INSERT INTO {aggregator_category_item} (cid, iid) VALUES (%d, %d)', $cid, $iid);
}
}
}
drupal_set_message(t('The categories have been saved.'));
drupal_goto($_GET['q']);
}
else {
$categorize = true;
}
}
$categorize = (user_access('administer news feeds') && ($op == 'categorize'));
$output = '<div id="aggregator">';
if ($header) {
$output .= $header;
}
if ($links) {
$output .= theme('links', $links);
}
$result = pager_query($sql, 20);
$form['header'] = array(value => $header);
$output .= $form['header'][value];
$rows = array();
$result = pager_query($sql, 20);
$categories = array();
while ($item = db_fetch_object($result)) {
$form['items'][$item->iid] = array(value => theme('aggregator_page_item', $item));
$output .= $form['items'][$item->iid][value];
$form['categories'][$item->iid] = array();
if ($categorize) {
$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);
if (variable_get('aggregator_category_selector', 'check') == 'select') {
$selected = array();
while ($category = db_fetch_object($categories_result)) {
if (!$done) {
$categories[$category->cid] = check_plain($category->title);
}
if ($category->iid) {
$selected[] = $category->cid;
}
$selected = array();
while ($category = db_fetch_object($categories_result)) {
if (!$done) {
$categories[$category->cid] = check_plain($category->title);
}
$done = true;
$form = form_select(NULL, 'categories]['. $item->iid, $selected, $categories, NULL, 'size="10"', true);
}
else {
$form = '';
while ($category = db_fetch_object($categories_result)) {
$form .= form_checkbox(check_plain($category->title), 'categories]['. $item->iid .'][', $category->cid, !is_null($category->iid));
if ($category->iid) {
$selected[] = $category->cid;
}
}
$rows[] = array(theme('aggregator_page_item', $item), array('data' => $form, 'class' => 'categorize-item'));
}
else {
$output .= theme('aggregator_page_item', $item);
$done = true;
$form['categories'][$item->iid] = array(
type => variable_get('aggregator_category_selector', 'checkboxes'),
default_value => $selected, options => $categories,
size => 10, multiple => true
);
}
}
if ($categorize) {
$output .= form(theme('table', array('', t('Categorize')), $rows) . form_submit(t('Save categories')));
}
$output .= '</div>';
$output .= theme('pager', NULL, 20, 0);
$output .= '</div>';
$form['submit'] = array(type => 'submit', value => t('Save categories'));
$form['pager'] = array(value => theme('pager', NULL, 20, 0));
$output .= $form['pager'][value];
// arg(1) is undefined if we are at the top aggregator URL
// is there a better way to do this?
if (!arg(1)) {
$output .= theme('xml_icon', url('aggregator/rss'));
$form['xml_icon'] = array(value => theme('xml_icon', url('aggregator/rss')));
}
elseif (arg(1) == 'categories' && arg(2) && !arg(3)) {
$output .= theme('xml_icon', url('aggregator/rss/' . arg(2)));
$form['xml_icon'] = array(value => theme('xml_icon', url('aggregator/rss/' . arg(2))));
}
$output .= $form['xml_icon'][value];
return ($categorize) ? drupal_get_form('aggregator_page_list', $form) : $output;
}
function theme_aggregator_page_list($form) {
$output = '<div id="aggregator">';
$output .= form_render($form['header']);
$rows = array();
if ($form['items']) {
foreach (element_children($form['items']) as $key) {
if (is_array($form['items'][$key])) {
$rows[] = array(form_render($form['items'][$key]), array('data' => form_render($form['categories'][$key]), 'class' => 'categorize-item'));
}
}
}
$output .= theme('table', array('', t('Categorize')), $rows);
$output .= form_render($form['submit']);
$output .= '</div>';
$output .= form_render($form);
return $output;
}
function aggregator_page_list_validate($form_id, &$form) {
if (!user_access('administer news feeds')) {
form_error($form, t('You are not allowed to categorize this feed item.'));
}
}
function aggregator_page_list_execute($form_id, $form) {
global $form_values;
foreach ($form_values['categories'] as $iid => $selection) {