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

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

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


Revision 1.1 - (show annotations) (download) (as text)
Fri Mar 14 10:17:44 2008 UTC (20 months, 1 week ago) by arto
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-php
Initial import of the Resource module.

Enables the creation of resource nodes which serve as references to remote
content identified by URIs and published in RDF format.
1 <?php
2 // $Id$
3 /**
4 * resource.admin.inc - Resource admin page callbacks.
5 *
6 * @author Arto Bendiken <http://bendiken.net/>
7 * @copyright Copyright (c) 2007-2008 Arto Bendiken. All rights reserved.
8 * @license GPL <http://creativecommons.org/licenses/GPL/2.0/>
9 * @package resource.module
10 */
11
12 //////////////////////////////////////////////////////////////////////////////
13 // Resource mass import
14
15 function resource_admin_import(&$form_state, $edit = array('uris' => 'http://')) {
16 $edit = (object)$edit;
17 $form = array();
18
19 $form['import'] = array('#type' => 'fieldset', '#title' => t('Import resources from URIs'));
20 $form['import']['uris'] = array('#type' => 'textarea', '#title' => t('URIs'), '#default_value' => $edit->uris, '#rows' => 10, '#required' => TRUE, '#description' => t('Enter one URI per line.'));
21
22 $form['import']['submit'] = array('#type' => 'submit', '#value' => t('Import'));
23 return $form;
24 }
25
26 function resource_admin_import_validate($form, &$form_state) {
27 extract($form_state['values'], EXTR_SKIP | EXTR_REFS);
28
29 $result = array();
30 foreach (array_filter(explode("\n", str_replace("\r", '', $uris)), 'strlen') as $uri) {
31 if (!rdf_is_valid_uri($uri)) {
32 form_set_error('uris', t('%uri is not a valid URI.', array('%uri' => $uri)));
33 }
34 else {
35 $result[] = $uri;
36 }
37 }
38 $uris = $result;
39 }
40
41 function resource_admin_import_submit($form, &$form_state) {
42 extract($form_state['values'], EXTR_SKIP | EXTR_REFS);
43
44 $counter = 0;
45 foreach ($uris as $uri) {
46 // TODO
47 $node = (object)array('type' => 'resource', 'resource_uri' => $uri);
48 require_once drupal_get_path('module', 'node') . '/node.pages.inc';
49 node_object_prepare($node);
50 node_save($node);
51 $counter++;
52 }
53
54 drupal_set_message(format_plural($counter, '1 resource imported.', '@count resources imported.'));
55 $form_state['redirect'] = 'admin/content/node';
56 }

  ViewVC Help
Powered by ViewVC 1.1.2