/[drupal]/contributions/modules/fooaggregator/fooaggregator_item.inc
ViewVC logotype

Contents of /contributions/modules/fooaggregator/fooaggregator_item.inc

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


Revision 1.4 - (show annotations) (download) (as text)
Wed Jul 18 00:25:06 2007 UTC (2 years, 4 months ago) by alaa
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
Changes since 1.3: +13 -19 lines
File MIME type: text/x-php
item skeleton builder
1 <?php // -*-php-*-
2 /* $Id: fooaggregator_item.inc,v 1.3 2007/07/17 22:18:29 msameer Exp $ */
3
4 /**
5 * Implementation of hook_form()
6 */
7 function fooaggregator_item_form(&$node, &$param) {
8 $type = node_get_types('type', $node);
9
10 $form['title'] = array(
11 '#type' => 'textfield',
12 '#title' => check_plain($type->title_label),
13 '#required' => TRUE,
14 '#default_value' => $node->title,
15 '#weight' => -5
16 );
17
18 $form['body_filter']['body'] = array(
19 '#type' => 'textarea',
20 '#title' => check_plain($type->body_label),
21 '#default_value' => $node->body,
22 '#required' => FALSE
23 );
24
25 // we will overwrite it anyway if we update the feed item.
26 $form['body_filter']['filter'] = filter_form($node->format);
27
28 // todo: link should be text here and in the db ?
29 $form['link'] = array(
30 '#type' => 'textfield',
31 '#title' => t('Link to the item'),
32 '#default_value' => $node->link,
33 );
34
35 $form['author'] = array(
36 '#type' => 'textfield',
37 '#title' => t('Author of the item'),
38 '#default_value' => $node->author,
39 );
40 return $form;
41 }
42
43 /**
44 * Implementation of hook_load()
45 */
46 function fooaggregator_item_load(&$node) {
47 return db_fetch_object(db_query("select * from {fooaggregator_item} where nid=%d", $node->nid));
48 }
49
50 /**
51 * Implementation of hook_insert()
52 */
53 function fooaggregator_item_insert(&$node) {
54 db_query("insert into {fooaggregator_item} (nid, fid, guid, link, author) VALUES(%d, %d, '%s', '%s', '%s')", $node->nid, $node->fid, $node->guid, $node->link, $node->author);
55 }
56
57 /**
58 * Implementation of hook_update()
59 *
60 * Update the editable parts.
61 */
62 function fooaggregator_item_update(&$node) {
63 db_query("update {fooaggregator_item} set link='%s', author='%s' where nid=%d", $node->link, $node->author, $node->nid);
64 }
65
66 /**
67 * Update the non-editable parts.
68 */
69 function _fooaggregator_item_update(&$node) {
70 db_query("update {fooaggregator_item} set guid='%s' where nid=%d", $node->guid, $node->nid);
71 }
72
73 /**
74 * Implementation of hook_delete()
75 */
76 function fooaggregator_item_delete(&$node) {
77 db_query("delete from {fooaggregator_item} where nid=%d", $node->nid);
78 }
79
80 /**
81 * Implementation of hook_view()
82 */
83 function fooaggregator_item_view(&$node, $teaser = FALSE, $page = FALSE) {
84 $node = node_prepare($node, $teaser);
85 $node->content['fooaggregator_author'] = array(
86 '#value' => theme('fooaggregator_item_author', $node),
87 '#weight' => -1,
88 );
89 return $node;
90 }
91
92 /**
93 * theme the author part of the feed item.
94 *
95 * @param $node a fooaggregator_item node object
96 * @return an HTML string representing the themed feed item author.
97 */
98 function theme_fooaggregator_item_author(&$node) {
99 $node->feed = node_load($node->fid);
100 return l($node->feed->title, 'node/'.$node->feed->nid).' - '.format_date($node->created).' By '.check_plain($node->author).'<br />';
101 }
102
103 /**
104 * Create a basic fooaggregator_item node.
105 *
106 * @param $fid a feed id
107 * @param $item a reference to an array or object to manipulate. It will be casted to an object.
108 */
109 function _fooaggregator_item_skel($fid) {
110 $node = array();
111 $node['type'] = 'fooaggregator_item';
112 $node_options = variable_get('node_options_fooaggregator_item', array('status', 'promote'));
113 $node['status'] = in_array('status', $node_options);
114 $node['promote'] = in_array('promote', $node_options);
115 if (module_exists('comment')) {
116 $node['comment'] = variable_get("comment_fooaggregator_item", COMMENT_NODE_DISABLED);
117 }
118 $node['format'] = variable_get('fooaggregator_filter', variable_get('filter_default_format', 1));
119 $node['fid'] = $fid;
120 return $node;
121 }
122
123 /**
124 * Save a generated node
125 * The parser must set $node->time to a unix timestamp that will be used as changed and/or created
126 *
127 * @param $node a reference to a node to save.
128 */
129 function _fooaggregator_item_save(&$node) {
130 $uid = variable_get('fooaggregator_uid', 1);
131 $node = node_submit($node);
132 $node->uid = $uid;
133
134 if (!$node->nid) {
135 $node->created = $node->time;
136 }
137
138 node_save($node);
139 }

  ViewVC Help
Powered by ViewVC 1.1.2