/[drupal]/contributions/modules/exhibit/exhibit.admin.inc
ViewVC logotype

Contents of /contributions/modules/exhibit/exhibit.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.7 - (show annotations) (download) (as text)
Fri May 1 05:09:27 2009 UTC (6 months, 3 weeks ago) by arto
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-BETA1, HEAD
Changes since 1.6: +1 -0 lines
File MIME type: text/x-php
Merged latest changes from http://github.com/jhuckabee/drupal-exhibit (50455e2) by jhuckabee.

Changelog:
- Minor fixes for the Exhibit views and core modules.
- Implemented an Exhibit localization module.
1 <?php
2 // $Id$
3
4 //////////////////////////////////////////////////////////////////////////////
5 // Exhibit API functions
6
7 function exhibit_admin_feed_types() {
8 return array(
9 'application/json' => t('Exhibit JSON'),
10 'application/rdf+xml' => t('RDF/XML'),
11 'application/n3' => t('N3'),
12 'application/vnd.ms-excel' => t('Excel'),
13 'text/plain' => t('Tab-separated values'),
14 'application/x-bibtex' => t('Bibtex'),
15 'application/vnd.google-spreadsheet' => t('Google Spreadsheet'),
16 'application/RDFa' => t('RDFa'),
17 );
18 }
19
20 //////////////////////////////////////////////////////////////////////////////
21 // Exhibit settings
22
23 /**
24 * Form builder: displays the module configuration screen.
25 *
26 * @ingroup forms
27 * @see system_settings_form()
28 */
29 function exhibit_admin_settings() {
30 $form = array();
31
32 // Exhibit API
33 $form['api'] = array('#type' => 'fieldset', '#title' => t('Exhibit API'), '#collapsible' => TRUE, '#collapsed' => FALSE);
34 $form['api']['exhibit_js_url'] = array('#type' => 'textfield', '#title' => t('Exhibit JS API'), '#default_value' => EXHIBIT_JS_URL, '#description' => t('Specify the location from where the Exhibit 2.0 JavaScript <acronym title="Application Programming Interface">API</acronym> will be loaded. By default, it is loaded directly from <a href="http://simile.mit.edu/" target="_blank">SIMILE\'s</a> servers, ensuring the use of the very latest version. However, should you require it, there are instructions available on how to <a href="http://simile.mit.edu/wiki/Exhibit/2.0/Running_Exhibit_Yourself" target="_blank">run Exhibit locally</a>.'));
35
36 // View settings
37 $form['extensions'] = array('#type' => 'fieldset', '#title' => t('Exhibit extensions'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#description' => 'Select the Exhibit extensions you wish to enable below. You can also specify an alternate API location for each extension.');
38 foreach (exhibit_exhibit_views() as $id => $view) {
39 if (isset($view->href)) {
40 $form['extensions']['exhibit_extensions_'. $id] = array('#type' => 'checkbox', '#title' => $view['title'], '#default_value' => variable_get('exhibit_extensions_'. $id, FALSE), '#description' => t(''));
41 $form['extensions']['exhibit_extensions_'. $id .'_api'] = array('#type' => 'textfield', '#title' => t($view['title'] . ' API'), '#default_value' => variable_get('exhibit_extensions_'. $id .'_api', constant('EXHIBIT_'. strtoupper($id) .'_JS_URL')));
42 if ($id == 'map') {
43 $form['extensions']['exhibit_gmap_key'] = array('#type' => 'textfield', '#title' => t('Google Maps API key'), '#default_value' => variable_get('exhibit_gmap_key', ''), '#description' => t('If you have the <a href="http://drupal.org/project/gmap">GMap</a> and/or <a href="http://drupal.org/project/keys">Keys API</a> modules installed and configured, you can leave this blank as Exhibit will pull the Google Maps API key used from <a href="/admin/settings/gmap">that configuration</a>.'));
44 }
45 }
46 }
47
48 return system_settings_form($form);
49 }
50
51 //////////////////////////////////////////////////////////////////////////////
52 // Exhibit feed administration
53
54 /**
55 * Menu callback: displays the data feeds management page.
56 */
57 function exhibit_admin_feeds() {
58 $head = array(t('Title'), t('Type'), t('URL'), array('data' => t('Operations'), 'colspan' => 2));
59 $rows = array();
60
61 $types = exhibit_admin_feed_types();
62 foreach (exhibit_get_feeds() as $feed) {
63 $url_parts = (exhibit_is_link_internal($feed->url) ? parse_url($feed->url) : NULL);
64
65 $rows[] = array(
66 is_numeric($feed->fid) ? check_plain($feed->title) : $feed->title,
67 check_plain(isset($types[$feed->type]) ? $types[$feed->type] : $feed->type),
68 (!is_null($url_parts) ?
69 l(truncate_utf8($feed->url, 56, TRUE, TRUE), $url_parts['path'], array('query' => $url_parts['query'])) :
70 l(truncate_utf8($feed->url, 56, TRUE, TRUE), $feed->url)),
71 is_numeric($feed->fid) ? l(t('edit'), 'admin/content/exhibit/edit/' . $feed->fid) : '',
72 is_numeric($feed->fid) ? l(t('delete'), 'admin/content/exhibit/delete/' . $feed->fid) : '',
73 );
74 }
75
76 if (empty($rows)) {
77 $rows[] = array(array('data' => t('No data feeds defined.'), 'colspan' => '5'));
78 }
79 return theme('table', $head, $rows);
80 }
81
82 /**
83 * Form builder: generates a form for adding/editing data feeds.
84 *
85 * @ingroup forms
86 * @see exhibit_admin_feed_form_validate()
87 * @see exhibit_admin_feed_form_submit()
88 */
89 function exhibit_admin_feed_form(&$form_state, $edit = array('title' => '', 'type' => 'application/json', 'url' => '')) {
90 $form = array();
91 $form['fid'] = array('#type' => 'hidden', '#value' => !empty($edit['fid']) ? $edit['fid'] : '');
92 $form['module'] = array('#type' => 'hidden', '#value' => '');
93
94 $form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#default_value' => $edit['title'], '#maxlength' => 64, '#description' => t('The human-readable name of this data feed. This text will be displayed as part of the list on the data feed management page. This name must begin with a capital letter and contain only letters, numbers, and spaces. This name must be unique.'), '#required' => TRUE);
95 $form['url'] = array('#type' => 'textfield', '#title' => t('URL'), '#default_value' => $edit['url'], '#maxlength' => 255, '#description' => t('The URL of this data feed, given either as a relative internal path or a full absolute URL.'), '#required' => TRUE);
96
97 $form['type'] = array('#type' => 'select', '#title' => t('Type'), '#default_value' => $edit['type'], '#options' => exhibit_admin_feed_types(), '#description' => t('The content type of this data feed. Only the JSON content type is natively supported; any other content types will be automatically converted when loaded.'), '#required' => TRUE);
98
99 $form['submit'] = array('#type' => 'submit', '#value' => empty($edit['fid']) ? t('Create new feed') : t('Update feed settings'));
100 return $form;
101 }
102
103 function exhibit_admin_feed_form_validate($form, &$form_state) {
104 extract($form_state['values'], EXTR_SKIP | EXTR_REFS);
105
106 if (!valid_url($url, FALSE) && !valid_url($url, TRUE)) {
107 form_set_error('url', t('%url is not a valid URL.', array('%url' => $url)));
108 }
109
110 // TODO: check for duplicate titles and URLs.
111 }
112
113 function exhibit_admin_feed_form_submit($form, &$form_state) {
114 extract($form_state['values'], EXTR_SKIP | EXTR_REFS);
115
116 if (empty($fid)) {
117 db_query("INSERT INTO {exhibit_feeds} (fid, module, title, type, url) VALUES (NULL, '%s', '%s', '%s', '%s')", $module, $title, $type, $url);
118 watchdog('exhibit', 'Data feed %title created.', array('%title' => $title), WATCHDOG_NOTICE, l(t('view'), 'admin/content/exhibit'));
119 drupal_set_message(t('The data feed %title has been created.', array('%title' => $title)));
120 }
121 else {
122 db_query("UPDATE {exhibit_feeds} SET title = '%s', type = '%s', url = '%s' WHERE fid = %d", $title, $type, $url, $fid);
123 watchdog('exhibit', 'Data feed %title updated.', array('%title' => $title), WATCHDOG_NOTICE, l(t('view'), 'admin/content/exhibit'));
124 drupal_set_message(t('The data feed %title has been updated.', array('%title' => $title)));
125 }
126
127 $form_state['redirect'] = 'admin/content/exhibit';
128 }
129
130 function exhibit_admin_feed_delete($form_state, $feed) {
131 $form['fid'] = array('#type' => 'value', '#value' => $feed['fid']);
132 $form['title'] = array('#type' => 'value', '#value' => $feed['title']);
133
134 return confirm_form($form,
135 t('Are you sure you want to delete the data feed %title?', array('%title' => $feed['title'])),
136 isset($_GET['destination']) ? $_GET['destination'] : 'admin/content/exhibit',
137 t('This action cannot be undone.'));
138 }
139
140 function exhibit_admin_feed_delete_submit($form, &$form_state) {
141 extract($form_state['values'], EXTR_SKIP | EXTR_REFS);
142
143 if ($form_state['values']['confirm']) {
144 db_query("DELETE FROM {exhibit_feeds} WHERE fid = %d", $fid);
145 watchdog('exhibit', 'Data feed %title deleted.', array('%title' => $title));
146 drupal_set_message(t('The data feed %title has been deleted.', array('%title' => $title)));
147 }
148
149 $form_state['redirect'] = 'admin/content/exhibit';
150 }

  ViewVC Help
Powered by ViewVC 1.1.2