/[drupal]/contributions/modules/dmoz/dlink.module
ViewVC logotype

Contents of /contributions/modules/dmoz/dlink.module

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


Revision 1.2 - (show annotations) (download) (as text)
Fri May 26 23:04:57 2006 UTC (3 years, 6 months ago) by trunks
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +21 -13 lines
File MIME type: text/x-php
cleaning
1 <?php
2 // $Id: dlink.module,v 1.1 2006/05/24 17:39:46 trunks Exp $
3
4 /**
5 * @file
6 * Dmoz gateway for Llengua.org - Node type for links
7 *
8 * Developed by Jose A. Reyero, http://www.reyero.net
9 * for Interactors, http://www.interactors.coop
10 */
11
12 /**
13 * Implementation of hook_help().
14 */
15 function dlink_help($section) {
16 switch ($section) {
17 case 'admin/modules#description':
18 return t('Link node type for Dmoz gateway');
19 case 'node/add#dlink':
20 return t('ODP link');
21 }
22 }
23
24 /**
25 * Implementation of hook_menu().
26 */
27 function dlink_menu($may_cache) {
28 $items = array();
29
30 if ($may_cache) {
31 $items[] = array('path' => 'node/add/dlink', 'title' => t('ODP Link'),
32 'access' => user_access('create links'));
33 }
34
35 return $items;
36 }
37
38 /**
39 * Implementation of hook_access().
40 */
41 function dlink_access($op, $node) {
42 global $user;
43 // Allow update and delete for cron.php
44 if ($op == 'update' || $op == 'delete') {
45 if( !$user->uid && $_SERVER["REQUEST_URI"] == $_SERVER["SCRIPT_NAME"]
46 && substr($_SERVER["REQUEST_URI"], -9) == '/cron.php'){
47 return TRUE;
48 }
49 }
50 }
51
52 /**
53 * Implementation of hook_node_name().
54 */
55 function dlink_node_name($node) {
56 return t('Dmoz link');
57 }
58
59 /**
60 * Implementation of hook_form().
61 */
62 function dlink_form(&$node) {
63 $output = '';
64
65 /* Taxonomies this size are not manageable
66 if (function_exists('taxonomy_node_form')) {
67 $output .= implode('', taxonomy_node_form('dlink', $node));
68 }
69 */
70 $terms = taxonomy_node_get_terms($node->nid);
71
72 foreach($terms as $term) {
73 $output .= form_item(t('Category'), $term->name);
74 }
75 $output .= form_textfield(t('Category Id'), 'catid', $node->catid, 60, 255);
76 $output .= form_textfield(t('Type'), 'urltype', $node->urltype, 60, 255);
77 $output .= form_textfield(t('Url'), 'url', $node->url, 60, 255);
78
79 $output .= form_textarea(t('Description'), 'body', $node->body, 60, 20, '', NULL, TRUE);
80 // Last update & refresh
81 $output .= form_item(t('Last update'), format_date($node->lastupdate));
82 $output .= form_hidden('lastupdate', $node->lastupdate);
83 $output .= form_item(t('Last refresh'), format_date($node->lastrefresh));
84 $output .= form_hidden('lastrefresh', $node->lastrefresh);
85
86 $output .= filter_form('format', $node->format);
87
88 return $output;
89 }
90
91 /**
92 * Generate a display of the given node.
93 *
94 * @param $node
95 * A node array or node object.
96 * @param $teaser
97 * Whether to display only the teaser for the node.
98 * @param $page
99 * Whether the node is being displayed by itself as a page.
100 * @param $links
101 * Whether or not to display node links. Links are omitted for node previews.
102 *
103 * @return
104 * An HTML representation of the themed node.
105 */
106 function dlink_view(&$node, $teaser = FALSE, $page = FALSE, $links = TRUE) {
107 $node->body = '<div class="dmoz-url">'.l($node->title, $node->url).'</div>'.$node->body;
108 $node->teaser = '<div class="dmoz-url">'.l($node->title, $node->url).'</div>'.$node->teaser;
109 }
110
111 /**
112 * Format for listings
113 */
114 function theme_dlink_list($node){
115 $output = l($node->title, $node->url);
116 // $output .= ' - ';
117 $output .=' <span class="description">'. $node->teaser."</span>\n";
118 return $output;
119 }
120
121 /**
122 * Database layer
123 */
124 function dlink_load($node){
125 return db_fetch_object(db_query("SELECT * FROM {dmoz_node} WHERE nid=%d", $node->nid));
126 }
127
128 function dlink_insert($node){
129 db_query("INSERT INTO {dmoz_node} (nid, url, urltype, catid, lastupdate, lastrefresh) VALUES (%d, '%s', '%s', '%d', '%d', '%d')", $node->nid, $node->url, $node->urltype, $node->catid, $node->lastupdate, $node->lastrefresh);
130 }
131
132 function dlink_delete($node){
133 db_query("DELETE FROM {dmoz_node} WHERE nid=%d", $node->nid);
134 }
135
136 function dlink_update($node){
137 db_query("UPDATE {dmoz_node} SET url='%s', urltype='%s', catid='%d', lastupdate='%d', lastrefresh='%d' WHERE nid=%d", $node->url, $node->urltype, $node->catid, $node->lastupdate, $node->lastrefresh, $node->nid);
138 // Double checking for data consistency
139 if(!db_affected_rows() && !dlink_load($node)){
140 dlink_insert($node);
141 }
142 }
143
144 // vim:set filetype=php:
145 ?>

  ViewVC Help
Powered by ViewVC 1.1.2