Merge lp://qastaging/~m-baert/ubuntu-drupal-planet/6.x into lp://qastaging/~swe3tdave-deactivatedaccount/ubuntu-drupal-planet/6.x
- 6.x
- Merge into 6.x
Proposed by
David Giard
Status: | Merged |
---|---|
Merged at revision: | 17 |
Proposed branch: | lp://qastaging/~m-baert/ubuntu-drupal-planet/6.x |
Merge into: | lp://qastaging/~swe3tdave-deactivatedaccount/ubuntu-drupal-planet/6.x |
Diff against target: | None lines |
To merge this branch: | bzr merge lp://qastaging/~m-baert/ubuntu-drupal-planet/6.x |
Related bugs: | |
Related blueprints: |
Code Documentation
(Undefined)
PostgreSQL port
(Undefined)
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
David Giard | Approve | ||
Review via email: mp+4715@code.qastaging.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
David Giard (swe3tdave-deactivatedaccount) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'planet.info' | |||
2 | --- planet.info 2009-03-01 02:54:23 +0000 | |||
3 | +++ planet.info 2009-03-14 00:23:25 +0000 | |||
4 | @@ -1,6 +1,7 @@ | |||
5 | 1 | ; $Id: planet.info,v 1.2 2007/05/30 03:22:01 daryl Exp $ | 1 | ; $Id: planet.info,v 1.2 2007/05/30 03:22:01 daryl Exp $ |
6 | 2 | name = Planet | 2 | name = Planet |
7 | 3 | description = Planet blog aggregator | 3 | description = Planet blog aggregator |
8 | 4 | ; TODO better module definition, including specificity if possible. | ||
9 | 4 | package = Community - optional | 5 | package = Community - optional |
10 | 5 | version = 6.x | 6 | version = 6.x |
11 | 6 | core = 6.x | 7 | core = 6.x |
12 | 7 | 8 | ||
13 | === modified file 'planet.install' | |||
14 | --- planet.install 2009-03-01 03:00:14 +0000 | |||
15 | +++ planet.install 2009-03-14 00:23:25 +0000 | |||
16 | @@ -10,37 +10,43 @@ | |||
17 | 10 | 'description' => t('The base table for planet.'), | 10 | 'description' => t('The base table for planet.'), |
18 | 11 | 'fields' => array( | 11 | 'fields' => array( |
19 | 12 | 'fid' => array( | 12 | 'fid' => array( |
21 | 13 | 'description' => t('The primary identifier for a planet_feeds table.'), | 13 | 'description' => t('Primary Key: Unique identifier for a planet RSS feed.'), |
22 | 14 | 'type' => 'serial', | 14 | 'type' => 'serial', |
23 | 15 | 'unsigned' => TRUE, | 15 | 'unsigned' => TRUE, |
24 | 16 | 'not null' => TRUE, | 16 | 'not null' => TRUE, |
25 | 17 | ), | 17 | ), |
26 | 18 | 'uid' => array( | 18 | 'uid' => array( |
27 | 19 | 'description' => t('Foreign key to {users}.uid . Identifies user who choose the feed.'), | ||
28 | 19 | 'type' => 'int', | 20 | 'type' => 'int', |
29 | 20 | 'unsigned' => 1, | 21 | 'unsigned' => 1, |
30 | 21 | 'not null' => FALSE, | 22 | 'not null' => FALSE, |
31 | 22 | ), | 23 | ), |
32 | 23 | 'title' => array( | 24 | 'title' => array( |
33 | 24 | 'type' => 'varchar', | 25 | 'type' => 'varchar', |
34 | 26 | 'description' => t('Title of the feed.'), | ||
35 | 25 | 'length' => 50, | 27 | 'length' => 50, |
36 | 26 | 'not null' => TRUE, | 28 | 'not null' => TRUE, |
37 | 27 | ), | 29 | ), |
38 | 28 | 'link' => array( | 30 | 'link' => array( |
39 | 29 | 'type' => 'varchar', | 31 | 'type' => 'varchar', |
40 | 32 | 'description' => t('URL to the feed'), | ||
41 | 30 | 'length' => 80, | 33 | 'length' => 80, |
42 | 31 | 'not null' => TRUE, | 34 | 'not null' => TRUE, |
43 | 32 | ), | 35 | ), |
44 | 33 | 'image' => array( | 36 | 'image' => array( |
45 | 37 | 'description' => t('An image representing the feed'), | ||
46 | 34 | 'type' => 'varchar', | 38 | 'type' => 'varchar', |
47 | 35 | 'length' => 120, | 39 | 'length' => 120, |
48 | 36 | 'not null' => FALSE, | 40 | 'not null' => FALSE, |
49 | 37 | ), | 41 | ), |
50 | 38 | 'checked' => array( | 42 | 'checked' => array( |
51 | 43 | 'description' => t('Last time feed was checked for new items, as Unix timestamp'), | ||
52 | 39 | 'type' => 'int', | 44 | 'type' => 'int', |
53 | 40 | 'not null' => FALSE, | 45 | 'not null' => FALSE, |
54 | 41 | ), | 46 | ), |
55 | 42 | 'frozen' => array( | 47 | 'frozen' => array( |
57 | 43 | 'type' => 'int', | 48 | // TODO: add field description 'description' => t(''), |
58 | 49 | 'type' => 'int', // TODO change to boolean when supported | ||
59 | 44 | 'not null' => TRUE, | 50 | 'not null' => TRUE, |
60 | 45 | 'default' => 0, | 51 | 'default' => 0, |
61 | 46 | ), | 52 | ), |
62 | @@ -52,7 +58,7 @@ | |||
63 | 52 | 'description' => t('contain feed id and its corresponding nid'), | 58 | 'description' => t('contain feed id and its corresponding nid'), |
64 | 53 | 'fields' => array( | 59 | 'fields' => array( |
65 | 54 | 'id' => array( | 60 | 'id' => array( |
67 | 55 | 'description' => t('The primary identifier for a planet_items table'), | 61 | 'description' => t('Primary key: Unique identifier for a planet feed item'), |
68 | 56 | 'type' => 'serial', | 62 | 'type' => 'serial', |
69 | 57 | 'unsigned' => 1, | 63 | 'unsigned' => 1, |
70 | 58 | 'not null' => TRUE, | 64 | 'not null' => TRUE, |
71 | @@ -91,11 +97,9 @@ | |||
72 | 91 | /** | 97 | /** |
73 | 92 | * Implementation of hook_install() | 98 | * Implementation of hook_install() |
74 | 93 | * | 99 | * |
80 | 94 | * This will automatically install the database tables for the planet module for MySQL. | 100 | * This will automatically install the database tables for the planet |
81 | 95 | * | 101 | * module, using Drupal's data abstraction layer. |
82 | 96 | * If you are using another database, you will have to install the tables by hand, using the queries below as a reference. | 102 | * |
78 | 97 | * | ||
79 | 98 | * | ||
83 | 99 | */ | 103 | */ |
84 | 100 | 104 | ||
85 | 101 | function planet_install() { | 105 | function planet_install() { |
86 | @@ -106,9 +110,9 @@ | |||
87 | 106 | /** | 110 | /** |
88 | 107 | * Implementation of hook_uninstall() | 111 | * Implementation of hook_uninstall() |
89 | 108 | * | 112 | * |
91 | 109 | * This will automatically uninstall the database tables for the planet module for MySQL. | 113 | * Uninstalls planet module by removing its own database tables, nodes |
92 | 114 | * and persistent variables. | ||
93 | 110 | * | 115 | * |
94 | 111 | * | ||
95 | 112 | */ | 116 | */ |
96 | 113 | 117 | ||
97 | 114 | function planet_uninstall() { | 118 | function planet_uninstall() { |
98 | 115 | 119 | ||
99 | === modified file 'planet.module' | |||
100 | --- planet.module 2009-03-08 19:00:05 +0000 | |||
101 | +++ planet.module 2009-03-20 16:05:00 +0000 | |||
102 | @@ -1,48 +1,92 @@ | |||
103 | 1 | <?php | 1 | <?php |
104 | 2 | // $Id: planet.install Exp $ | 2 | // $Id: planet.install Exp $ |
105 | 3 | 3 | ||
107 | 4 | /** | 4 | /** |
108 | 5 | * @file | 5 | * @file |
110 | 6 | * The planet module | 6 | * The planet module. |
111 | 7 | * | ||
112 | 8 | * Planet is an aggregator that allows you to aggregate the blogs for | ||
113 | 9 | * users in a given role (e.g. staff) and associate content with the | ||
114 | 10 | * users rather than as a detached feed. This provides the benefit of | ||
115 | 11 | * showing avatars with content, providing per-user aggregation of | ||
116 | 12 | * planet content in addition to blog content, etc. | ||
117 | 7 | * | 13 | * |
118 | 8 | */ | 14 | */ |
119 | 9 | 15 | ||
120 | 16 | /** | ||
121 | 17 | * Implementation of hook_node_info. | ||
122 | 18 | * | ||
123 | 19 | * @return An array of information on the module's node types. | ||
124 | 20 | * | ||
125 | 21 | * @ingroup planet_node | ||
126 | 22 | */ | ||
127 | 10 | function planet_node_info() { | 23 | function planet_node_info() { |
128 | 11 | return array( | 24 | return array( |
129 | 12 | 'planet' => array( | 25 | 'planet' => array( |
133 | 13 | 'name' => t('Planet Entry'), | 26 | 'name' => t('Planet Entry'), |
134 | 14 | 'module' => 'planet', | 27 | 'module' => 'planet', |
135 | 15 | 'description' => t('Node to contain posts aggregated from various blogs.'), | 28 | 'description' => t('Node to contain posts aggregated from various blogs.'), |
136 | 16 | ) | 29 | ) |
137 | 17 | ); | 30 | ); |
138 | 18 | } | 31 | } |
139 | 19 | 32 | ||
140 | 20 | /** | 33 | /** |
142 | 21 | * Implementation of hook_perm. | 34 | * Implementation of hook_perm - Defines user permissions. |
143 | 35 | * The suggested naming convention for permissions is "action_verb modulename". | ||
144 | 36 | * | ||
145 | 37 | * @return An array of permissions strings. | ||
146 | 38 | * | ||
147 | 39 | * @ingroup base | ||
148 | 22 | */ | 40 | */ |
149 | 23 | function planet_perm() { | 41 | function planet_perm() { |
151 | 24 | return array('administer planet', 'administer own planet feeds'); | 42 | return array('administer planet', 'administer own planet feeds', 'view all planet nodes'); |
152 | 25 | } | 43 | } |
153 | 26 | 44 | ||
154 | 45 | /** | ||
155 | 46 | * Implementation of hook_help - Provides online user help. | ||
156 | 47 | * | ||
157 | 48 | * @param $path A Drupal menu router path the help is being requested for | ||
158 | 49 | * @param $arg | ||
159 | 50 | * @return A localized string containing the help text. | ||
160 | 51 | * | ||
161 | 52 | * @ingroup base | ||
162 | 53 | */ | ||
163 | 27 | function planet_help($path, $arg) { | 54 | function planet_help($path, $arg) { |
164 | 28 | switch ($path) { | 55 | switch ($path) { |
166 | 29 | case 'admin/help/planet': | 56 | case 'admin/help#planet': |
167 | 57 | // The module's help text, displayed on the admin/help page and through the module's individual help link. | ||
168 | 30 | $output = '<p>Planet is an aggregator that allows you to aggregate the blogs for users in a given role (e.g. staff) and associate content with the users rather than as a detached feed. This provides the benefit of showing avatars with content, providing per-user aggregation of planet content in addition to blog content, etc.</p>'; | 58 | $output = '<p>Planet is an aggregator that allows you to aggregate the blogs for users in a given role (e.g. staff) and associate content with the users rather than as a detached feed. This provides the benefit of showing avatars with content, providing per-user aggregation of planet content in addition to blog content, etc.</p>'; |
169 | 31 | $output .= '<p>To use planet, go to admin/settings/planet and note the following sections:</p>'; | 59 | $output .= '<p>To use planet, go to admin/settings/planet and note the following sections:</p>'; |
170 | 32 | $output .= '<ul>'; | 60 | $output .= '<ul>'; |
171 | 33 | $output .= '<li><strong>General Settings</strong>. The role to select bloggers from lets you narrow the user list for when you\'re adding a feed and associating it with a user. A common setting will be to create a staff role and use this for planet.</li>'; | 61 | $output .= '<li><strong>General Settings</strong>. The role to select bloggers from lets you narrow the user list for when you\'re adding a feed and associating it with a user. A common setting will be to create a staff role and use this for planet.</li>'; |
172 | 34 | $output .= '<li><strong>Feeds</strong>. This section lets you add a new feed. Give it a title, select an author, provide the feed url, and you\'re off. You\'ll have to manually refresh it or wait for a cron run for items to be imported.</li>'; | 62 | $output .= '<li><strong>Feeds</strong>. This section lets you add a new feed. Give it a title, select an author, provide the feed url, and you\'re off. You\'ll have to manually refresh it or wait for a cron run for items to be imported.</li>'; |
173 | 35 | $output .= '<li><strong>Feeds</strong>. This section lists current feeds, when they were last updated, how many items they have, and it allows you to edit, refresh, or freeze them. Freezing is a quick way to temporarily suspend updates from the given feed.</li>'; | 63 | $output .= '<li><strong>Feeds</strong>. This section lists current feeds, when they were last updated, how many items they have, and it allows you to edit, refresh, or freeze them. Freezing is a quick way to temporarily suspend updates from the given feed.</li>'; |
174 | 64 | // @DIFFGROUP output syntax | ||
175 | 65 | $output .= '</ul>'; | ||
176 | 36 | return $output; | 66 | return $output; |
179 | 37 | case 'admin/modules#description': | 67 | // @DIFFINFO in D6, admin/modules#description is moved to .info file |
178 | 38 | return t('Aggregates RSS feeds and faciliates their association with site users who belong to a given role.'); | ||
180 | 39 | } | 68 | } |
181 | 40 | } | 69 | } |
182 | 41 | 70 | ||
184 | 42 | function planet_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) { | 71 | /** |
185 | 72 | * Implementation of hook_view() - Displays a planet node. | ||
186 | 73 | * | ||
187 | 74 | * @param $node The node to be displayed. | ||
188 | 75 | * @param $teaser Whether to generate only a summary ("teaser") of the node. | ||
189 | 76 | * @param $page Whether the node is being displayed as a standalone page. | ||
190 | 77 | * @return The modified $node parameter, properly presented for output. | ||
191 | 78 | * | ||
192 | 79 | * @ingroup planet_node | ||
193 | 80 | * @CRUD{variables,R} | ||
194 | 81 | * @CRUD{planet_items,R} | ||
195 | 82 | */ | ||
196 | 83 | function planet_view($node, $teaser = FALSE, $page = FALSE) { | ||
197 | 84 | // @DIFFINFO removed $link param to match D6 hook definition | ||
198 | 43 | if ($page === true && variable_get('planet_redirect_page', 0) == 1) { | 85 | if ($page === true && variable_get('planet_redirect_page', 0) == 1) { |
201 | 44 | $obj = db_fetch_object(db_query('SELECT * FROM {planet_items} WHERE nid = %d', $node->nid)); | 86 | // @DIFFINFO only 'link' field is used, so I restricted the query |
202 | 45 | if ($obj->nid == $node->nid && $obj->link != '') { | 87 | $obj = db_fetch_object(db_query('SELECT link FROM {planet_items} WHERE nid = %d', $node->nid)); |
203 | 88 | // @DIFFINFO if the query succeeds, $obj->nid == $node->nid , otherwise, $obj==FALSE, | ||
204 | 89 | if ($obj && $obj->link != '') { | ||
205 | 46 | header('Location: '. $obj->link); | 90 | header('Location: '. $obj->link); |
206 | 47 | exit; | 91 | exit; |
207 | 48 | } | 92 | } |
208 | @@ -52,22 +96,51 @@ | |||
209 | 52 | } | 96 | } |
210 | 53 | } | 97 | } |
211 | 54 | 98 | ||
212 | 99 | /** | ||
213 | 100 | * Implementation of hook_access() - Define access permissions for planet nodes (aka CRUD) . | ||
214 | 101 | * @param $op The operation to be performed: 'create', 'view', 'update', 'delete' | ||
215 | 102 | * @param $node The node on which the operation is to be performed, or, if it does not yet exist, the type of node to be created. | ||
216 | 103 | * @param $account A user object representing the user for whom the operation is to be performed. | ||
217 | 104 | * @return true if the user is allowed to perform operation, false otherwise. | ||
218 | 105 | * | ||
219 | 106 | * @ingroup planet_node | ||
220 | 107 | */ | ||
221 | 55 | function planet_access($op, $node, $account) { | 108 | function planet_access($op, $node, $account) { |
224 | 56 | 109 | // @DIFFINFO using planet-dedicated permissions | |
225 | 57 | 110 | // Planet administrator has all permissions related to planet module | |
226 | 111 | if (user_access('administer planet', $account)) | ||
227 | 112 | return TRUE; | ||
228 | 113 | // Users allowed to edit their own planet nodes, are also allowed to create them, others are not. | ||
229 | 114 | $author = user_access('edit own planet feeds', $account); | ||
230 | 58 | if ($op == 'create') { | 115 | if ($op == 'create') { |
232 | 59 | return user_access('edit own blog', $account) && $account->uid; | 116 | return $author; |
233 | 60 | } | 117 | } |
234 | 61 | 118 | ||
235 | 119 | // Does current user own requested node ? | ||
236 | 120 | $own = $account->uid == $node->uid; | ||
237 | 121 | if ($op == 'view') | ||
238 | 122 | return $own || user_access('view all planet nodes'); | ||
239 | 62 | if ($op == 'update' || $op == 'delete') { | 123 | if ($op == 'update' || $op == 'delete') { |
243 | 63 | if (user_access('edit own blog', $account) && ($account->uid == $node->uid) || user_access('administer nodes', $account)) { | 124 | return $author && $own; // ok if $author owns the node |
241 | 64 | return TRUE; | ||
242 | 65 | } | ||
244 | 66 | } | 125 | } |
245 | 126 | trigger_error("Unknown operation requested: $op"); | ||
246 | 127 | return FALSE; | ||
247 | 67 | } | 128 | } |
248 | 68 | 129 | ||
249 | 130 | /** | ||
250 | 131 | * Implementation of hook_menu() - Defines menu items and page callbacks. | ||
251 | 132 | * | ||
252 | 133 | * @return An array of menu items. | ||
253 | 134 | * Each menu item has a key corresponding to the Drupal path being registered. | ||
254 | 135 | * | ||
255 | 136 | * @ingroup base | ||
256 | 137 | * | ||
257 | 138 | * This diagram shows how requests are handled. | ||
258 | 139 | * Each arrow is labeled with the permission required to access link. | ||
259 | 140 | * The menu item colors reflect the item type. | ||
260 | 141 | * @dotfile menu-links.dot "Menus and Pages" | ||
261 | 142 | */ | ||
262 | 69 | function planet_menu() { | 143 | function planet_menu() { |
263 | 70 | |||
264 | 71 | $items['admin/settings/planet'] = array( | 144 | $items['admin/settings/planet'] = array( |
265 | 72 | 'title' => 'Planet Settings', | 145 | 'title' => 'Planet Settings', |
266 | 73 | 'description' => 'Configure settings for the planet module.', | 146 | 'description' => 'Configure settings for the planet module.', |
267 | @@ -84,31 +157,28 @@ | |||
268 | 84 | ); | 157 | ); |
269 | 85 | 158 | ||
270 | 86 | // if (arg(0) == 'planet' && is_numeric(arg(1))) { | 159 | // if (arg(0) == 'planet' && is_numeric(arg(1))) { |
271 | 160 | // FIXME access denied http://localhost/drupal/?q=planet/1 | ||
272 | 87 | $items['planet/'. '%'] = array( | 161 | $items['planet/'. '%'] = array( |
273 | 88 | 'title' => 'planet', | 162 | 'title' => 'planet', |
274 | 89 | 'page callback' => 'planet_page_user', | 163 | 'page callback' => 'planet_page_user', |
275 | 90 | 'page arguments' => array(arg(1)) | 164 | 'page arguments' => array(arg(1)) |
276 | 91 | ); | 165 | ); |
277 | 92 | // } | ||
278 | 93 | 166 | ||
281 | 94 | // if (arg(3) == 'refresh' && is_numeric(arg(4))) { | 167 | // if (arg(3) == 'refresh' && is_numeric(arg(4))) { |
280 | 95 | |||
282 | 96 | $items['admin/settings/planet/refresh/%'] = array( | 168 | $items['admin/settings/planet/refresh/%'] = array( |
283 | 97 | 'title' => 'planet refresh', | 169 | 'title' => 'planet refresh', |
284 | 98 | 'page callback' => 'planet_call_refresh', | 170 | 'page callback' => 'planet_call_refresh', |
285 | 99 | 'access arguments' => array('administer nodes'), | 171 | 'access arguments' => array('administer nodes'), |
286 | 100 | 'type' => MENU_CALLBACK | 172 | 'type' => MENU_CALLBACK |
287 | 101 | ); | 173 | ); |
288 | 102 | // } | ||
289 | 103 | 174 | ||
291 | 104 | // if (is_numeric(arg(4)) && (arg(3) == 'freeze' || arg(3) == 'unfreeze')) { | 175 | // if (is_numeric(arg(4)) && (arg(3) == 'freeze' || arg(3) == 'unfreeze')) { |
292 | 105 | $items['admin/settings/planet/'. arg(3) .'/%'] = array( | 176 | $items['admin/settings/planet/'. arg(3) .'/%'] = array( |
293 | 106 | 'title' => 'planet freeze', | 177 | 'title' => 'planet freeze', |
294 | 107 | 'page callback' => 'planet_toggle_frozen', | 178 | 'page callback' => 'planet_toggle_frozen', |
295 | 108 | 'access arguments' => array('administer nodes'), | 179 | 'access arguments' => array('administer nodes'), |
296 | 109 | 'type' => MENU_CALLBACK | 180 | 'type' => MENU_CALLBACK |
297 | 110 | ); | 181 | ); |
298 | 111 | // } | ||
299 | 112 | 182 | ||
300 | 113 | $items['planet'] = array( | 183 | $items['planet'] = array( |
301 | 114 | 'title' => 'Planet', | 184 | 'title' => 'Planet', |
302 | @@ -128,6 +198,12 @@ | |||
303 | 128 | return $items; | 198 | return $items; |
304 | 129 | } | 199 | } |
305 | 130 | 200 | ||
306 | 201 | |||
307 | 202 | /** | ||
308 | 203 | * Page callback for 'admin/settings/planet/refresh/%' ("planet refresh") | ||
309 | 204 | * | ||
310 | 205 | * @ingroup page | ||
311 | 206 | */ | ||
312 | 131 | function planet_call_refresh() { | 207 | function planet_call_refresh() { |
313 | 132 | $title = planet_refresh(); | 208 | $title = planet_refresh(); |
314 | 133 | watchdog('planet', 'Feed "'. $title .'" refreshed.'); | 209 | watchdog('planet', 'Feed "'. $title .'" refreshed.'); |
315 | @@ -135,6 +211,12 @@ | |||
316 | 135 | drupal_goto('admin/settings/planet'); | 211 | drupal_goto('admin/settings/planet'); |
317 | 136 | } | 212 | } |
318 | 137 | 213 | ||
319 | 214 | /** | ||
320 | 215 | * Page callback for 'admin/settings/planet/(un|)freeze/%' ("planet freeze") | ||
321 | 216 | * | ||
322 | 217 | * @ingroup page | ||
323 | 218 | * @CRUD{planet_feeds,U} | ||
324 | 219 | */ | ||
325 | 138 | function planet_toggle_frozen() { | 220 | function planet_toggle_frozen() { |
326 | 139 | 221 | ||
327 | 140 | $fid = intval(arg(4)); | 222 | $fid = intval(arg(4)); |
328 | @@ -144,53 +226,57 @@ | |||
329 | 144 | } | 226 | } |
330 | 145 | 227 | ||
331 | 146 | 228 | ||
332 | 229 | /** | ||
333 | 230 | * Deletes a feed and related items | ||
334 | 231 | * @param $fid the feed identifier key (integer) | ||
335 | 232 | * | ||
336 | 233 | * @internal | ||
337 | 234 | * @ingroup planet_feed | ||
338 | 235 | * @CRUD{planet_items,R} | ||
339 | 236 | * @invoke{drupal_get_form,planet_multiple_delete_confirm} | ||
340 | 237 | */ | ||
341 | 238 | function planet__drop_feed($fid) { | ||
342 | 239 | $result = db_query('SELECT nid FROM {planet_items} WHERE fid = %d', intval($edit['fid'])); | ||
343 | 240 | while ($node = db_fetch_object($result)) { | ||
344 | 241 | $nodes[$node->nid] = TRUE; | ||
345 | 242 | } | ||
346 | 243 | return drupal_get_form('planet_multiple_delete_confirm', $nodes, | ||
347 | 244 | intval($edit['fid']), 'user/'. $user->uid .'/planet'); | ||
348 | 245 | } | ||
349 | 246 | |||
350 | 247 | /** | ||
351 | 248 | * Page callback for 'user/%user/planet' ("Planet Feeds") | ||
352 | 249 | * | ||
353 | 250 | * @ingroup page | ||
354 | 251 | * @CRUD{planet_feeds,R} | ||
355 | 252 | * @invoke{drupal_get_form,planet_multiple_delete_confirm_submit} | ||
356 | 253 | * @invoke{drupal_get_form,planet_feed_form} | ||
357 | 254 | */ | ||
358 | 147 | function planet_user_feeds() { | 255 | function planet_user_feeds() { |
361 | 148 | global $user; | 256 | global $user; |
362 | 149 | if ($_POST) { | 257 | if ($_POST) { |
363 | 150 | $edit = $_POST; | 258 | $edit = $_POST; |
373 | 151 | if ($_POST['op'] == 'Delete' && intval($edit['fid']) > 0) { | 259 | $fid = intval($edit['fid']); |
374 | 152 | $result = db_query('SELECT nid FROM {planet_items} WHERE fid = %d', intval($edit['fid'])); | 260 | if (($_POST['op'] == 'Delete') && ($fid != 0)) { |
375 | 153 | while ($node = db_fetch_object($result)) { | 261 | return planet__drop_feed($fid); |
376 | 154 | $nodes[$node->nid] = TRUE; | 262 | } else if ($_POST['op'] == 'Delete all' && $_POST['confirm'] == 1) { |
377 | 155 | } | 263 | $edit['fid'] = intval(arg(3)); // @deprecated arg() |
369 | 156 | return drupal_get_form('planet_multiple_delete_confirm', $nodes, intval($edit['fid']), 'user/'. $user->uid .'/planet'); | ||
370 | 157 | } | ||
371 | 158 | else if ($_POST['op'] == 'Delete all' && $_POST['confirm'] == 1) { | ||
372 | 159 | $edit['fid'] = intval(arg(3)); | ||
378 | 160 | $edit['redirect'] = 'user/'. $user->uid .'/planet'; | 264 | $edit['redirect'] = 'user/'. $user->uid .'/planet'; |
379 | 161 | return drupal_get_form('planet_multiple_delete_confirm_submit', $edit); | 265 | return drupal_get_form('planet_multiple_delete_confirm_submit', $edit); |
406 | 162 | } | 266 | } else { |
407 | 163 | else { | 267 | if (isset($edit['fid'])) { |
408 | 164 | if (isset($edit['fid']) && intval($edit['fid']) == 0) { | 268 | if (intval($edit['fid']) == 0) { |
409 | 165 | db_query('INSERT INTO {planet_feeds} (uid, title, link, image, checked, frozen) VALUES(%d, "%s", "%s", "%s", 0, 0)', $user->uid, $edit['title'], $edit['link'], $edit['image']); | 269 | planet__add_feed($edit); |
410 | 166 | $edit_r = db_fetch_array(db_query('SELECT fid FROM {planet_feeds} WHERE uid = %d AND title = "%s" AND link = "%s"', $user->uid, $edit['title'], $edit['link'])); | 270 | } else { |
411 | 167 | $title = planet_refresh(intval($edit_r['fid'])); | 271 | planet__update_feed($edit); |
412 | 168 | drupal_set_message('Added new feed: ' . $title); | 272 | } |
413 | 169 | } | 273 | } else { |
414 | 170 | else if ($edit['fid'] && intval($edit['fid']) > 0) { | 274 | planet__update_vars($edit); |
389 | 171 | db_query('UPDATE {planet_feeds} SET uid = %d, title="%s", link = "%s", image="%s" WHERE fid=%d', $user->uid, $edit['title'], $edit['link'], $edit['image'], $edit['fid']); | ||
390 | 172 | drupal_set_message('Edited "'. $edit['title'] .'" feed.'); | ||
391 | 173 | } | ||
392 | 174 | else { | ||
393 | 175 | if ($edit['planet_author_roles']) { | ||
394 | 176 | variable_set('planet_author_roles', $edit['planet_author_roles']); | ||
395 | 177 | } | ||
396 | 178 | if ($edit['planet_filter_formats']) { | ||
397 | 179 | variable_set('planet_filter_formats', $edit['planet_filter_formats']); | ||
398 | 180 | } | ||
399 | 181 | if ($edit['planet_redirect_page'] == 1) { | ||
400 | 182 | variable_set('planet_redirect_page', $edit['planet_redirect_page']); | ||
401 | 183 | } | ||
402 | 184 | else { | ||
403 | 185 | variable_del('planet_redirect_page'); | ||
404 | 186 | } | ||
405 | 187 | drupal_set_message('Edited general planet settings.'); | ||
415 | 188 | } | 275 | } |
416 | 189 | } | 276 | } |
417 | 190 | drupal_goto('user/'. $user->uid .'/planet'); | 277 | drupal_goto('user/'. $user->uid .'/planet'); |
421 | 191 | } | 278 | } else { // no $_POST |
422 | 192 | else { | 279 | $fid = intval(arg(3)); // @deprecated: arg() |
420 | 193 | $fid = intval(arg(3)); | ||
423 | 194 | if ($fid > 0) { | 280 | if ($fid > 0) { |
424 | 195 | $edit = db_fetch_array(db_query('SELECT * FROM {planet_feeds} WHERE fid = %d', $fid)); | 281 | $edit = db_fetch_array(db_query('SELECT * FROM {planet_feeds} WHERE fid = %d', $fid)); |
425 | 196 | $output .= drupal_get_form('planet_feed_form', $edit, true, $user); | 282 | $output .= drupal_get_form('planet_feed_form', $edit, true, $user); |
426 | @@ -199,32 +285,143 @@ | |||
427 | 199 | 285 | ||
428 | 200 | $output .= drupal_get_form('planet_feed_form', $edit, false, $user); | 286 | $output .= drupal_get_form('planet_feed_form', $edit, false, $user); |
429 | 201 | 287 | ||
432 | 202 | // $result = db_query('SELECT *, (UNIX_TIMESTAMP(NOW()) - checked) _checked FROM {planet_feeds}'); | 288 | $output .= '<h2>Feeds</h2>'; |
433 | 203 | $result = db_query('SELECT COUNT(f.fid) cnt, f.*, (UNIX_TIMESTAMP(NOW()) - checked) _checked FROM {planet_feeds} f LEFT OUTER JOIN {planet_items} i ON i.fid = f.fid WHERE f.uid = %d GROUP BY f.fid;', $user->uid); | 289 | $output .= planet__build_user_feeds_table(); |
434 | 290 | } | ||
435 | 291 | print theme('page', $output); | ||
436 | 292 | } | ||
437 | 293 | } | ||
438 | 294 | |||
439 | 295 | // Note: I use 'planet__' prefix to name internal functions | ||
440 | 296 | // TODO: apply the same naming convention (this one or another) in whole module | ||
441 | 297 | /** | ||
442 | 298 | * @todo merge with planet__build_admin_feeds_table() | ||
443 | 299 | * | ||
444 | 300 | * @ingroup planet_feed | ||
445 | 301 | * @internal | ||
446 | 302 | * @CRUD{planet_feeds,R} | ||
447 | 303 | * @CRUD{planet_items,R} | ||
448 | 304 | */ | ||
449 | 305 | function planet__build_user_feeds_table() { | ||
450 | 306 | // @DIFFINFO renamed planet__build_feeds_table1 | ||
451 | 307 | global $user; | ||
452 | 308 | $feeds = db_query('SELECT fid, title, checked FROM {planet_feeds} ' | ||
453 | 309 | . ' WHERE uid = %d;', $user->uid); | ||
454 | 204 | $rows = array(); | 310 | $rows = array(); |
455 | 205 | $headers = array('Feed', 'Items', 'Edit', 'Last checked'); | 311 | $headers = array('Feed', 'Items', 'Edit', 'Last checked'); |
459 | 206 | while ($feed = db_fetch_object($result)) { | 312 | $now = time(); |
460 | 207 | $checked = intval($feed->_checked / 60) .' minutes'; | 313 | $items_statement = 'SELECT count(*) FROM {planet_items}' |
461 | 208 | if ($feed->_checked % 60 > 0) { | 314 | . ' WHERE fid=%d'; |
462 | 315 | // TODO: change this to prepared statement when supported by drupal DB abstraction layer. | ||
463 | 316 | while ($feed = db_fetch_object($feeds)) { | ||
464 | 317 | $_checked = $now - $feed->checked; | ||
465 | 318 | $checked = intval($_checked / 60) .' minutes'; | ||
466 | 319 | if ($_checked % 60 > 0) { | ||
467 | 209 | $checked .= ', '. $feed->_checked % 60 .' seconds'; | 320 | $checked .= ', '. $feed->_checked % 60 .' seconds'; |
468 | 210 | } | 321 | } |
469 | 211 | $checked .= ' ago'; | 322 | $checked .= ' ago'; |
470 | 323 | $items = db_query($items_statement, $feed->fid); | ||
471 | 324 | if (!$items) trigger_error('ERROR while counting feed items.'); | ||
472 | 325 | $cnt = db_result($items); | ||
473 | 212 | array_push($rows, array( | 326 | array_push($rows, array( |
474 | 213 | $feed->title, | 327 | $feed->title, |
476 | 214 | $feed->cnt, | 328 | $cnt, |
477 | 215 | l('edit', 'user/'. $user->uid .'/planet/'. intval($feed->fid)), | 329 | l('edit', 'user/'. $user->uid .'/planet/'. intval($feed->fid)), |
478 | 216 | $checked, | 330 | $checked, |
479 | 217 | ) | 331 | ) |
480 | 218 | ); | 332 | ); |
481 | 219 | } | 333 | } |
490 | 220 | $output .= '<h2>Feeds</h2>'; | 334 | return theme('table', $headers, $rows); |
491 | 221 | $output .= theme('table', $headers, $rows); | 335 | } |
492 | 222 | } | 336 | |
493 | 223 | print theme('page', $output); | 337 | /** |
494 | 224 | } | 338 | * Adds a new feed to planet_feeds table. |
495 | 225 | } | 339 | * @param $data associative array with keys |
496 | 226 | 340 | * 'uid' (optional), 'title', 'link', 'image' (optional) | |
497 | 227 | 341 | * @return success status | |
498 | 342 | * | ||
499 | 343 | * @ingroup planet_feed | ||
500 | 344 | * @internal | ||
501 | 345 | * @CRUD{planet_feeds,C} | ||
502 | 346 | */ | ||
503 | 347 | function planet__add_feed($data) { | ||
504 | 348 | $data['checked'] = 0; | ||
505 | 349 | $data['frozen'] = 0; | ||
506 | 350 | if (isset($data['fid'])) { // @DEBUGGING | ||
507 | 351 | trigger_error('Primary key fid shouldn\'t be set for a need feed (value: {$data->fid}). Record not added.', E_ERROR); | ||
508 | 352 | return FALSE; | ||
509 | 353 | } | ||
510 | 354 | $rslt = drupal_write_record('planet_feeds', $data); | ||
511 | 355 | if ($rslt==SAVED_NEW) { | ||
512 | 356 | $title = planet_refresh(intval($data['fid'])); | ||
513 | 357 | drupal_set_message('Added new feed: ' . $title); | ||
514 | 358 | return TRUE; | ||
515 | 359 | } | ||
516 | 360 | trigger_error('Failed to add new feed'); | ||
517 | 361 | return FALSE; | ||
518 | 362 | } | ||
519 | 363 | |||
520 | 364 | /** | ||
521 | 365 | * Updates an existing feed in planet_feeds table. | ||
522 | 366 | * @param $data associative array with keys | ||
523 | 367 | * 'fid' (mandatory, primary key), | ||
524 | 368 | * other fields as needed: | ||
525 | 369 | * 'uid', 'title', 'link', 'image', 'checked', 'frozen' | ||
526 | 370 | * @return success status | ||
527 | 371 | * | ||
528 | 372 | * @ingroup planet_feed | ||
529 | 373 | * @internal | ||
530 | 374 | * @CRUD{planet_feeds,U} | ||
531 | 375 | */ | ||
532 | 376 | function planet__update_feed($data) { | ||
533 | 377 | $rslt = drupal_write_record('planet_feeds', $data, 'fid'); | ||
534 | 378 | if ($rslt==SAVED_UPDATED) { | ||
535 | 379 | drupal_set_message('Edited "'. $data['title'] .'" feed.'); | ||
536 | 380 | return TRUE; | ||
537 | 381 | } | ||
538 | 382 | if ($rslt==SAVED_NEW) // @DEBUGGING | ||
539 | 383 | trigger_error('Feed {$data->fid} didn\'t exist. Record added.', E_ERROR); | ||
540 | 384 | else | ||
541 | 385 | trigger_error('Failed to edit feed'); | ||
542 | 386 | return FALSE; | ||
543 | 387 | } | ||
544 | 388 | |||
545 | 389 | /** | ||
546 | 390 | * Updates an planet settings persistent variables. | ||
547 | 391 | * @param $data associative array with all optional keys | ||
548 | 392 | * 'planet_author_roles', 'planet_filter_formats', | ||
549 | 393 | * 'planet_redirect_page'. | ||
550 | 394 | * | ||
551 | 395 | * @ingroup isettings | ||
552 | 396 | * @internal | ||
553 | 397 | * @CRUD{variables,CUD} | ||
554 | 398 | */ | ||
555 | 399 | function planet__update_vars($data) { | ||
556 | 400 | if ($edit['planet_author_roles']) { | ||
557 | 401 | variable_set('planet_author_roles', $edit['planet_author_roles']); | ||
558 | 402 | } | ||
559 | 403 | if ($edit['planet_filter_formats']) { | ||
560 | 404 | variable_set('planet_filter_formats', $edit['planet_filter_formats']); | ||
561 | 405 | } | ||
562 | 406 | if ($edit['planet_redirect_page'] == 1) { | ||
563 | 407 | variable_set('planet_redirect_page', $edit['planet_redirect_page']); | ||
564 | 408 | } else { | ||
565 | 409 | variable_del('planet_redirect_page'); | ||
566 | 410 | } | ||
567 | 411 | drupal_set_message('Edited general planet settings.'); | ||
568 | 412 | } | ||
569 | 413 | |||
570 | 414 | /** | ||
571 | 415 | * Page callback for 'admin/settings/planet' ("Planet Settings") | ||
572 | 416 | * | ||
573 | 417 | * @ingroup page | ||
574 | 418 | * @CRUD{planet_items,R} | ||
575 | 419 | * @CRUD{planet_feeds,R} | ||
576 | 420 | * @invoke{drupal_get_form,planet_multiple_delete_confirm} | ||
577 | 421 | * @invoke{drupal_get_form,planet_multiple_delete_confirm_submit} | ||
578 | 422 | * @invoke{drupal_get_form,planet_feed_form} | ||
579 | 423 | * @invoke{drupal_get_form,planet_settings_form} | ||
580 | 424 | */ | ||
581 | 228 | function _planet_settings() { | 425 | function _planet_settings() { |
582 | 229 | if ($_POST) { | 426 | if ($_POST) { |
583 | 230 | $edit = $_POST; | 427 | $edit = $_POST; |
584 | @@ -241,37 +438,23 @@ | |||
585 | 241 | $edit['redirect'] = 'admin/settings/planet'; | 438 | $edit['redirect'] = 'admin/settings/planet'; |
586 | 242 | return drupal_get_form('planet_multiple_delete_confirm_submit', $edit); | 439 | return drupal_get_form('planet_multiple_delete_confirm_submit', $edit); |
587 | 243 | } | 440 | } |
613 | 244 | else { | 441 | else { |
614 | 245 | if (isset($edit['fid']) && intval($edit['fid']) == 0) { | 442 | if (isset($edit['fid'])) { |
615 | 246 | db_query('INSERT INTO {planet_feeds} (uid, title, link, image, checked, frozen) VALUES(%d, "%s", "%s", "%s", 0, 0)', $edit['uid'], $edit['title'], $edit['link'], $edit['image']); | 443 | if (intval($edit['fid']) == 0) { |
616 | 247 | $edit_r = db_fetch_array(db_query('SELECT fid FROM {planet_feeds} WHERE uid = %d AND title = "%s" AND link = "%s"', $edit['uid'], $edit['title'], $edit['link'])); | 444 | planet__add_feed($edit); |
617 | 248 | $title = planet_refresh(intval($edit_r['fid'])); | 445 | } else { |
618 | 249 | drupal_set_message('Added new feed: ' . $title); | 446 | planet__update_feed($edit); |
619 | 250 | } | 447 | } |
620 | 251 | else if ($edit['fid'] && intval($edit['fid']) > 0) { | 448 | } else { |
621 | 252 | db_query('UPDATE {planet_feeds} SET uid = %d, title="%s", link = "%s", image="%s" WHERE fid=%d', $edit['uid'], $edit['title'], $edit['link'], $edit['image'], $edit['fid']); | 449 | // TODO if user needs to click separately for each fieldset, |
622 | 253 | drupal_set_message('Edited "'. $edit['title'] .'" feed.'); | 450 | // why not using different forms ? |
623 | 254 | } | 451 | // or conversely, allow setting everything at once ? |
624 | 255 | else { | 452 | planet__update_vars($edit); |
600 | 256 | if ($edit['planet_author_roles']) { | ||
601 | 257 | variable_set('planet_author_roles', $edit['planet_author_roles']); | ||
602 | 258 | } | ||
603 | 259 | if ($edit['planet_filter_formats']) { | ||
604 | 260 | variable_set('planet_filter_formats', $edit['planet_filter_formats']); | ||
605 | 261 | } | ||
606 | 262 | if ($edit['planet_redirect_page'] == 1) { | ||
607 | 263 | variable_set('planet_redirect_page', $edit['planet_redirect_page']); | ||
608 | 264 | } | ||
609 | 265 | else { | ||
610 | 266 | variable_del('planet_redirect_page'); | ||
611 | 267 | } | ||
612 | 268 | drupal_set_message('Edited general planet settings.'); | ||
625 | 269 | } | 453 | } |
626 | 270 | } | 454 | } |
627 | 271 | drupal_goto('admin/settings/planet'); | 455 | drupal_goto('admin/settings/planet'); |
631 | 272 | } | 456 | } else { |
632 | 273 | else { | 457 | $fid = intval(arg(3)); // @deprecated arg() |
630 | 274 | $fid = intval(arg(3)); | ||
633 | 275 | if ($fid > 0) { | 458 | if ($fid > 0) { |
634 | 276 | $edit = db_fetch_array(db_query('SELECT * FROM {planet_feeds} WHERE fid = %d', $fid)); | 459 | $edit = db_fetch_array(db_query('SELECT * FROM {planet_feeds} WHERE fid = %d', $fid)); |
635 | 277 | $output .= drupal_get_form('planet_feed_form', $edit, true); | 460 | $output .= drupal_get_form('planet_feed_form', $edit, true); |
636 | @@ -279,38 +462,72 @@ | |||
637 | 279 | else { | 462 | else { |
638 | 280 | 463 | ||
639 | 281 | $output .= drupal_get_form('planet_settings_form'); | 464 | $output .= drupal_get_form('planet_settings_form'); |
640 | 282 | //$output .= drupal_get_form('settings', $form); | ||
641 | 283 | //$output .= $form; | ||
642 | 284 | 465 | ||
643 | 285 | $output .= drupal_get_form('planet_feed_form', $edit); | 466 | $output .= drupal_get_form('planet_feed_form', $edit); |
644 | 286 | 467 | ||
645 | 287 | // $result = db_query('SELECT *, (UNIX_TIMESTAMP(NOW()) - checked) _checked FROM {planet_feeds}'); | ||
646 | 288 | $result = db_query('SELECT COUNT(f.fid) cnt, f.*, (UNIX_TIMESTAMP(NOW()) - checked) _checked FROM {planet_feeds} f LEFT OUTER JOIN {planet_items} i ON i.fid = f.fid GROUP BY f.fid;'); | ||
647 | 289 | $rows = array(); | ||
648 | 290 | $headers = array('Feed', 'Items', 'Edit', 'Last checked', 'Refresh', 'Freeze'); | ||
649 | 291 | while ($feed = db_fetch_object($result)) { | ||
650 | 292 | $checked = intval($feed->_checked / 60) .' minutes'; | ||
651 | 293 | if ($feed->_checked % 60 > 0) { | ||
652 | 294 | $checked .= ', '. $feed->_checked % 60 .' seconds'; | ||
653 | 295 | } | ||
654 | 296 | $checked .= ' ago'; | ||
655 | 297 | array_push($rows, array( | ||
656 | 298 | $feed->title, | ||
657 | 299 | $feed->cnt, | ||
658 | 300 | l('edit', 'admin/settings/planet/'. intval($feed->fid)), | ||
659 | 301 | $checked, | ||
660 | 302 | l('refresh', 'admin/settings/planet/refresh/'. intval($feed->fid)), | ||
661 | 303 | l($feed->frozen ? 'unfreeze' : 'freeze', 'admin/settings/planet/'. ($feed->frozen ? 'unfreeze/' : 'freeze/') . intval($feed->fid)) | ||
662 | 304 | ) | ||
663 | 305 | ); | ||
664 | 306 | } | ||
665 | 307 | $output .= '<h2>Feeds</h2>'; | 468 | $output .= '<h2>Feeds</h2>'; |
667 | 308 | $output .= theme('table', $headers, $rows); | 469 | $output .= planet__build_admin_feeds_table(); |
668 | 309 | } | 470 | } |
669 | 310 | print theme('page', $output); | 471 | print theme('page', $output); |
670 | 311 | } | 472 | } |
671 | 312 | } | 473 | } |
672 | 313 | 474 | ||
673 | 475 | /** | ||
674 | 476 | * builds an HTML table of feeds for administrator interaction. | ||
675 | 477 | * | ||
676 | 478 | * @return | ||
677 | 479 | * | ||
678 | 480 | * @ingroup planet_feed | ||
679 | 481 | * @internal | ||
680 | 482 | * @CRUD{planet_feeds,R} | ||
681 | 483 | * @CRUD{planet_items,R} | ||
682 | 484 | */ | ||
683 | 485 | function planet__build_admin_feeds_table() { | ||
684 | 486 | // @DIFFINFO renamed planet__build_feeds_table() { | ||
685 | 487 | global $user; | ||
686 | 488 | $feeds = db_query('SELECT fid, title, checked, frozen FROM {planet_feeds} ' | ||
687 | 489 | . ' WHERE uid = %d;', $user->uid); | ||
688 | 490 | $rows = array(); | ||
689 | 491 | $headers = array('Feed', 'Items', 'Edit', 'Last checked', 'Refresh', 'Freeze'); | ||
690 | 492 | $now = time(); | ||
691 | 493 | $items_statement = 'SELECT count(*) FROM {planet_items} WHERE fid=%'; | ||
692 | 494 | // TODO: change this to prepared statement when supported by drupal DB Abstraction Layer. | ||
693 | 495 | while ($feed = db_fetch_object($feeds)) { | ||
694 | 496 | $_checked = $now - $feed->checked; | ||
695 | 497 | $checked = intval($_checked / 60) .' minutes'; | ||
696 | 498 | if ($_checked % 60 > 0) { | ||
697 | 499 | $checked .= ', '. $feed->_checked % 60 .' seconds'; | ||
698 | 500 | } | ||
699 | 501 | $checked .= ' ago'; | ||
700 | 502 | $items = db_query($items_statement, $feed->fid); | ||
701 | 503 | if (!$items) trigger_error('ERROR while counting feed items.'); | ||
702 | 504 | $cnt = db_result($items); | ||
703 | 505 | $fid = strval($feed->fid); | ||
704 | 506 | array_push($rows, array( | ||
705 | 507 | $feed->title, | ||
706 | 508 | $cnt, | ||
707 | 509 | l('edit', 'admin/settings/planet/'. $fid), | ||
708 | 510 | $checked, | ||
709 | 511 | l('refresh', 'admin/settings/planet/refresh/'. $fid), | ||
710 | 512 | l($feed->frozen ? 'unfreeze' : 'freeze', 'admin/settings/planet/'. ($feed->frozen ? 'unfreeze/' : 'freeze/') . $fid) | ||
711 | 513 | ) | ||
712 | 514 | ); | ||
713 | 515 | } | ||
714 | 516 | return theme('table', $headers, $rows); | ||
715 | 517 | } | ||
716 | 518 | |||
717 | 519 | /** | ||
718 | 520 | * TODO. | ||
719 | 521 | * | ||
720 | 522 | * @param &$form_state | ||
721 | 523 | * @param $nodes | ||
722 | 524 | * @param $fid | ||
723 | 525 | * @param $redirect | ||
724 | 526 | * @return | ||
725 | 527 | * | ||
726 | 528 | * @ingroup iforms | ||
727 | 529 | * @CRUD{node,R} | ||
728 | 530 | */ | ||
729 | 314 | function planet_multiple_delete_confirm(&$form_state, $nodes, $fid, $redirect) { | 531 | function planet_multiple_delete_confirm(&$form_state, $nodes, $fid, $redirect) { |
730 | 315 | $form_state['values']['fid'] = $fid; | 532 | $form_state['values']['fid'] = $fid; |
731 | 316 | $form_state['values']['redirect'] = $redirect; | 533 | $form_state['values']['redirect'] = $redirect; |
732 | @@ -333,21 +550,42 @@ | |||
733 | 333 | t('Delete all'), t('Cancel')); | 550 | t('Delete all'), t('Cancel')); |
734 | 334 | } | 551 | } |
735 | 335 | 552 | ||
736 | 553 | /** | ||
737 | 554 | * TODO. | ||
738 | 555 | * | ||
739 | 556 | * @param &$form_state | ||
740 | 557 | * @param $edit | ||
741 | 558 | * @return | ||
742 | 559 | * | ||
743 | 560 | * @ingroup iforms | ||
744 | 561 | * @CRUD{node,D} | ||
745 | 562 | * @CRUD{planet_items,D} | ||
746 | 563 | * @CRUD{planet_feeds,D} | ||
747 | 564 | */ | ||
748 | 336 | function planet_multiple_delete_confirm_submit(&$form_state, $edit) { | 565 | function planet_multiple_delete_confirm_submit(&$form_state, $edit) { |
749 | 337 | $fid = $edit['fid']; | 566 | $fid = $edit['fid']; |
750 | 338 | if ($edit['confirm']) { | 567 | if ($edit['confirm']) { |
751 | 339 | foreach ($edit['nodes'] as $nid => $value) { | 568 | foreach ($edit['nodes'] as $nid => $value) { |
752 | 340 | node_delete($nid); | 569 | node_delete($nid); |
753 | 341 | } | 570 | } |
754 | 571 | // @DIFFINFO inverted drop order to respect foreign keys | ||
755 | 572 | db_query('DELETE FROM {planet_items} WHERE fid = %d', $fid); | ||
756 | 342 | db_query('DELETE FROM {planet_feeds} WHERE fid = %d', $fid); | 573 | db_query('DELETE FROM {planet_feeds} WHERE fid = %d', $fid); |
757 | 343 | db_query('DELETE FROM {planet_items} WHERE fid = %d', $fid); | ||
758 | 344 | drupal_set_message(t('The feed and items have been deleted.')); | 574 | drupal_set_message(t('The feed and items have been deleted.')); |
759 | 345 | } | 575 | } |
760 | 346 | drupal_goto($edit['redirect']); | 576 | drupal_goto($edit['redirect']); |
761 | 347 | } | 577 | } |
762 | 348 | 578 | ||
763 | 349 | 579 | ||
765 | 350 | 580 | /** | |
766 | 581 | * TODO. | ||
767 | 582 | * | ||
768 | 583 | * @param &$form_state | ||
769 | 584 | * @return | ||
770 | 585 | * @ingroup iforms | ||
771 | 586 | * @CRUD{role,R} | ||
772 | 587 | * @CRUD{variables,R} | ||
773 | 588 | */ | ||
774 | 351 | function planet_settings_form(&$form_state) { | 589 | function planet_settings_form(&$form_state) { |
775 | 352 | $roles = array(); | 590 | $roles = array(); |
776 | 353 | 591 | ||
777 | @@ -402,6 +640,20 @@ | |||
778 | 402 | } | 640 | } |
779 | 403 | 641 | ||
780 | 404 | 642 | ||
781 | 643 | /** | ||
782 | 644 | * TODO. | ||
783 | 645 | * | ||
784 | 646 | * @param &$form_state | ||
785 | 647 | * @param $edit | ||
786 | 648 | * @param $individual | ||
787 | 649 | * @param $user | ||
788 | 650 | * @return | ||
789 | 651 | * @ingroup iforms | ||
790 | 652 | * @CRUD{users,R} | ||
791 | 653 | * @CRUD{role,R} | ||
792 | 654 | * @CRUD{users_roles,R} | ||
793 | 655 | * @CRUD{variables,R} | ||
794 | 656 | */ | ||
795 | 405 | function planet_feed_form(&$form_state, $edit = array(), $individual = false, $user = NULL) { | 657 | function planet_feed_form(&$form_state, $edit = array(), $individual = false, $user = NULL) { |
796 | 406 | $uids = array(); | 658 | $uids = array(); |
797 | 407 | $result = db_query('SELECT u.uid, u.name FROM {users} u, {role} r, {users_roles} ur WHERE u.uid = ur.uid AND ur.rid = r.rid AND r.rid = %d ORDER BY u.name ASC', variable_get('planet_author_roles', 2)); | 659 | $result = db_query('SELECT u.uid, u.name FROM {users} u, {role} r, {users_roles} ur WHERE u.uid = ur.uid AND ur.rid = r.rid AND r.rid = %d ORDER BY u.name ASC', variable_get('planet_author_roles', 2)); |
798 | @@ -474,6 +726,13 @@ | |||
799 | 474 | return $form; | 726 | return $form; |
800 | 475 | } | 727 | } |
801 | 476 | 728 | ||
802 | 729 | /** | ||
803 | 730 | * Implementation of hook_cron - Perform periodic actions. | ||
804 | 731 | * | ||
805 | 732 | * @return none | ||
806 | 733 | * @ingroup system | ||
807 | 734 | * @CRUD{planet_feeds,R} | ||
808 | 735 | */ | ||
809 | 477 | function planet_cron() { | 736 | function planet_cron() { |
810 | 478 | $result = db_query('SELECT fid FROM {planet_feeds} WHERE frozen = 0'); | 737 | $result = db_query('SELECT fid FROM {planet_feeds} WHERE frozen = 0'); |
811 | 479 | while ($feed = db_fetch_object($result)) { | 738 | while ($feed = db_fetch_object($result)) { |
812 | @@ -482,6 +741,17 @@ | |||
813 | 482 | } | 741 | } |
814 | 483 | } | 742 | } |
815 | 484 | 743 | ||
816 | 744 | |||
817 | 745 | /** | ||
818 | 746 | * Private function; Checks a news feed for new items. | ||
819 | 747 | * | ||
820 | 748 | * @param $fid feed identifier (defaults to arg(4)) | ||
821 | 749 | * @return | ||
822 | 750 | * | ||
823 | 751 | * @private | ||
824 | 752 | * @CRUD{planet_feeds,U} | ||
825 | 753 | * @invoke{module_invoke,taxonomy_node_get_terms} | ||
826 | 754 | */ | ||
827 | 485 | function planet_refresh($fid = null) { | 755 | function planet_refresh($fid = null) { |
828 | 486 | if (!$fid) { | 756 | if (!$fid) { |
829 | 487 | $fid = intval(arg(4)); | 757 | $fid = intval(arg(4)); |
830 | @@ -638,60 +908,8 @@ | |||
831 | 638 | /** | 908 | /** |
832 | 639 | * Private function; Parse HTTP headers from data retreived with cURL | 909 | * Private function; Parse HTTP headers from data retreived with cURL |
833 | 640 | * from: http://pl2.php.net/manual/en/function.curl-setopt.php#42009 | 910 | * from: http://pl2.php.net/manual/en/function.curl-setopt.php#42009 |
888 | 641 | */ | 911 | * @ingroup rss |
889 | 642 | function planet_parse_response($response) { | 912 | * @private |
836 | 643 | /* | ||
837 | 644 | ***original code extracted from examples at | ||
838 | 645 | ***http://www.webreference.com/programming | ||
839 | 646 | /php/cookbook/chap11/1/3.html | ||
840 | 647 | |||
841 | 648 | ***returns an array in the following format which varies depending on headers returned | ||
842 | 649 | |||
843 | 650 | [0] => the HTTP error or response code such as 404 | ||
844 | 651 | [1] => Array | ||
845 | 652 | ( | ||
846 | 653 | [Server] => Microsoft-IIS/5.0 | ||
847 | 654 | [Date] => Wed, 28 Apr 2004 23:29:20 GMT | ||
848 | 655 | [X-Powered-By] => ASP.NET | ||
849 | 656 | [Connection] => close | ||
850 | 657 | [Set-Cookie] => COOKIESTUFF | ||
851 | 658 | [Expires] => Thu, 01 Dec 1994 16:00:00 GMT | ||
852 | 659 | [Content-Type] => text/html | ||
853 | 660 | [Content-Length] => 4040 | ||
854 | 661 | ) | ||
855 | 662 | [2] => Response body (string) | ||
856 | 663 | */ | ||
857 | 664 | |||
858 | 665 | do { | ||
859 | 666 | list($response_headers, $response) = explode("\r\n\r\n", $response, 2); | ||
860 | 667 | $response_header_lines = explode("\r\n", $response_headers); | ||
861 | 668 | |||
862 | 669 | // first line of headers is the HTTP response code | ||
863 | 670 | $http_response_line = array_shift($response_header_lines); | ||
864 | 671 | if (preg_match('@^HTTP/[0-9]\.[0-9] ([0-9]{3})@', $http_response_line, $matches)) { | ||
865 | 672 | $response_code = $matches[1]; | ||
866 | 673 | } | ||
867 | 674 | else { | ||
868 | 675 | $response_code = "Error"; | ||
869 | 676 | } | ||
870 | 677 | } | ||
871 | 678 | while (substr($response_code, 0, 1) == "1"); | ||
872 | 679 | |||
873 | 680 | $response_body = $response; | ||
874 | 681 | |||
875 | 682 | // put the rest of the headers in an array | ||
876 | 683 | $response_header_array = array(); | ||
877 | 684 | foreach ($response_header_lines as $header_line) { | ||
878 | 685 | list($header, $value) = explode(':', $header_line, 2); | ||
879 | 686 | $response_header_array[$header] = trim($value); | ||
880 | 687 | } | ||
881 | 688 | |||
882 | 689 | return array($response_code, $response_header_array, $response_body, $http_response_line); | ||
883 | 690 | } | ||
884 | 691 | |||
885 | 692 | /** | ||
886 | 693 | * Private function; Gets data from given URL :) | ||
887 | 694 | */ | ||
890 | 695 | function planet_http_request($url, $headers = array(), $timeout = 15, $method = 'GET', $data = NULL, $follow = 3) { | 913 | function planet_http_request($url, $headers = array(), $timeout = 15, $method = 'GET', $data = NULL, $follow = 3) { |
891 | 696 | if (!function_exists('curl_init')) { | 914 | if (!function_exists('curl_init')) { |
892 | 697 | return drupal_http_request($url, $headers, $method, $data, $follow); | 915 | return drupal_http_request($url, $headers, $method, $data, $follow); |
893 | @@ -750,11 +968,6 @@ | |||
894 | 750 | } | 968 | } |
895 | 751 | 969 | ||
896 | 752 | /** | 970 | /** |
897 | 753 | * Private function; Checks a news feed for new items. | ||
898 | 754 | */ | ||
899 | 755 | |||
900 | 756 | |||
901 | 757 | /** | ||
902 | 758 | * Private function; | 971 | * Private function; |
903 | 759 | * Parse the W3C date/time format, a subset of ISO 8601. PHP date parsing | 972 | * Parse the W3C date/time format, a subset of ISO 8601. PHP date parsing |
904 | 760 | * functions do not handle this format. | 973 | * functions do not handle this format. |
905 | @@ -763,6 +976,8 @@ | |||
906 | 763 | * | 976 | * |
907 | 764 | * @param $date_str A string with a potentially W3C DTF date. | 977 | * @param $date_str A string with a potentially W3C DTF date. |
908 | 765 | * @return A timestamp if parsed successfully or -1 if not. | 978 | * @return A timestamp if parsed successfully or -1 if not. |
909 | 979 | * @ingroup rss | ||
910 | 980 | * @private | ||
911 | 766 | */ | 981 | */ |
912 | 767 | function planet_parse_w3cdtf($date_str) { | 982 | function planet_parse_w3cdtf($date_str) { |
913 | 768 | if (preg_match('/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/', $date_str, $match)) { | 983 | if (preg_match('/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/', $date_str, $match)) { |
914 | @@ -799,6 +1014,8 @@ | |||
915 | 799 | * | 1014 | * |
916 | 800 | * @param $ord Number | 1015 | * @param $ord Number |
917 | 801 | * @return UTF-8 string | 1016 | * @return UTF-8 string |
918 | 1017 | * @ingroup rss | ||
919 | 1018 | * @private | ||
920 | 802 | */ | 1019 | */ |
921 | 803 | function planet_replace_num_entity($ord) { | 1020 | function planet_replace_num_entity($ord) { |
922 | 804 | $ord = $ord[1]; | 1021 | $ord = $ord[1]; |
923 | @@ -959,6 +1176,8 @@ | |||
924 | 959 | /** | 1176 | /** |
925 | 960 | * Private function; Convert named entities to UTF-8 characters | 1177 | * Private function; Convert named entities to UTF-8 characters |
926 | 961 | * from: http://pl2.php.net/manual/en/function.html-entity-decode.php#51722 | 1178 | * from: http://pl2.php.net/manual/en/function.html-entity-decode.php#51722 |
927 | 1179 | * @ingroup rss | ||
928 | 1180 | * @private | ||
929 | 962 | */ | 1181 | */ |
930 | 963 | function planet_replace_name_entities(&$text) { | 1182 | function planet_replace_name_entities(&$text) { |
931 | 964 | static $ttr; | 1183 | static $ttr; |
932 | @@ -974,23 +1193,20 @@ | |||
933 | 974 | 1193 | ||
934 | 975 | /** | 1194 | /** |
935 | 976 | * Private function; Convert all entities to UTF-8 characters | 1195 | * Private function; Convert all entities to UTF-8 characters |
936 | 1196 | * @ingroup rss | ||
937 | 1197 | * @private | ||
938 | 1198 | * @invoke{preg_replace_callback,planet_replace_num_entity} | ||
939 | 977 | */ | 1199 | */ |
940 | 978 | function planet_replace_entities(&$text) { | 1200 | function planet_replace_entities(&$text) { |
941 | 979 | $result = planet_replace_name_entities($text); | 1201 | $result = planet_replace_name_entities($text); |
942 | 980 | return preg_replace_callback('/&#([0-9a-fx]+);/mi', 'planet_replace_num_entity', $result); | 1202 | return preg_replace_callback('/&#([0-9a-fx]+);/mi', 'planet_replace_num_entity', $result); |
943 | 981 | } | 1203 | } |
944 | 982 | 1204 | ||
945 | 983 | /** | ||
946 | 984 | * Private function; Clone object function to stay compatible with both php4 and php5 | ||
947 | 985 | * from: Drupal 4.7CVS | ||
948 | 986 | * TODO: remove after moving to Drupal 4.7 | ||
949 | 987 | */ | ||
950 | 988 | function planet_clone($object) { | ||
951 | 989 | return version_compare(phpversion(), '5.0') < 0 ? $object : clone($object); | ||
952 | 990 | } | ||
953 | 991 | 1205 | ||
954 | 992 | /** | 1206 | /** |
955 | 993 | * Private function; Convert relative URLs | 1207 | * Private function; Convert relative URLs |
956 | 1208 | * @ingroup rss | ||
957 | 1209 | * @private | ||
958 | 994 | */ | 1210 | */ |
959 | 995 | function planet_convert_relative_urls(&$data, $base_url) { | 1211 | function planet_convert_relative_urls(&$data, $base_url) { |
960 | 996 | $src = '%( href| src)="(?!\w+://)/?([^"]*)"%'; | 1212 | $src = '%( href| src)="(?!\w+://)/?([^"]*)"%'; |
961 | @@ -1000,6 +1216,13 @@ | |||
962 | 1000 | 1216 | ||
963 | 1001 | /** | 1217 | /** |
964 | 1002 | * Private function; Creates nodes from data found in given xml_tree | 1218 | * Private function; Creates nodes from data found in given xml_tree |
965 | 1219 | * | ||
966 | 1220 | * @ingroup rss | ||
967 | 1221 | * @private | ||
968 | 1222 | * @CRUD{variables,R} | ||
969 | 1223 | * @CRUD{planet_items,R} | ||
970 | 1224 | * @CRUD{node,CU} | ||
971 | 1225 | * @invoke{module_invoke,taxonomy_node_get_terms} | ||
972 | 1003 | */ | 1226 | */ |
973 | 1004 | function planet_parse_items(&$xml_tree, &$feed) { | 1227 | function planet_parse_items(&$xml_tree, &$feed) { |
974 | 1005 | 1228 | ||
975 | @@ -1229,10 +1452,16 @@ | |||
976 | 1229 | } | 1452 | } |
977 | 1230 | //print '<pre>'. print_r($entry, 1) .'</pre>'; | 1453 | //print '<pre>'. print_r($entry, 1) .'</pre>'; |
978 | 1231 | node_save($entry); | 1454 | node_save($entry); |
980 | 1232 | db_query('INSERT INTO {planet_items} (fid, nid, guid, link, created) VALUES(%d, %d, "%s", "%s", UNIX_TIMESTAMP(NOW()))', $feed->fid, $entry->nid, $guid, $link); | 1455 | $item_record = array('fid' => $feed->fid, |
981 | 1456 | 'nid' => $entry->nid, | ||
982 | 1457 | 'guid'=> $guid, | ||
983 | 1458 | 'link' =>$link, | ||
984 | 1459 | 'created' => time()); | ||
985 | 1460 | drupal_write_record('planet_items', $item_record); | ||
986 | 1233 | watchdog('planet', 'Adding '. $title); | 1461 | watchdog('planet', 'Adding '. $title); |
987 | 1234 | drupal_set_message('Adding '. $title); | 1462 | drupal_set_message('Adding '. $title); |
988 | 1235 | } | 1463 | } |
989 | 1464 | // TODO split this huge function | ||
990 | 1236 | } | 1465 | } |
991 | 1237 | 1466 | ||
992 | 1238 | return $items_added; | 1467 | return $items_added; |
993 | @@ -1241,6 +1470,12 @@ | |||
994 | 1241 | 1470 | ||
995 | 1242 | /** | 1471 | /** |
996 | 1243 | * Private function; parses given XML data and returns array | 1472 | * Private function; parses given XML data and returns array |
997 | 1473 | * | ||
998 | 1474 | * @ingroup rss | ||
999 | 1475 | * @private | ||
1000 | 1476 | * @invoke{xml_set_element_handler,planet_element_start} | ||
1001 | 1477 | * @invoke{xml_set_element_handler,planet_element_end} | ||
1002 | 1478 | * @invoke{xml_set_character_data_handler,planet_element_data} | ||
1003 | 1244 | */ | 1479 | */ |
1004 | 1245 | function planet_parse_xml(&$data) { | 1480 | function planet_parse_xml(&$data) { |
1005 | 1246 | global $xml_tree, $xml_paths, $xml_path_cur; | 1481 | global $xml_tree, $xml_paths, $xml_path_cur; |
1006 | @@ -1297,6 +1532,8 @@ | |||
1007 | 1297 | 1532 | ||
1008 | 1298 | /** | 1533 | /** |
1009 | 1299 | * Private call-back function used by the XML parser. | 1534 | * Private call-back function used by the XML parser. |
1010 | 1535 | * @ingroup rss | ||
1011 | 1536 | * @internal | ||
1012 | 1300 | */ | 1537 | */ |
1013 | 1301 | function planet_element_start($parser, $name, $attributes) { | 1538 | function planet_element_start($parser, $name, $attributes) { |
1014 | 1302 | global $xml_tree, $xml_paths, $xml_path_cur; | 1539 | global $xml_tree, $xml_paths, $xml_path_cur; |
1015 | @@ -1308,6 +1545,8 @@ | |||
1016 | 1308 | 1545 | ||
1017 | 1309 | /** | 1546 | /** |
1018 | 1310 | * Private call-back function used by the XML parser. | 1547 | * Private call-back function used by the XML parser. |
1019 | 1548 | * @ingroup rss | ||
1020 | 1549 | * @private | ||
1021 | 1311 | */ | 1550 | */ |
1022 | 1312 | function planet_element_end($parser, $name) { | 1551 | function planet_element_end($parser, $name) { |
1023 | 1313 | global $xml_tree, $xml_paths, $xml_path_cur; | 1552 | global $xml_tree, $xml_paths, $xml_path_cur; |
1024 | @@ -1322,6 +1561,8 @@ | |||
1025 | 1322 | 1561 | ||
1026 | 1323 | /** | 1562 | /** |
1027 | 1324 | * Private call-back function used by the XML parser. | 1563 | * Private call-back function used by the XML parser. |
1028 | 1564 | * @ingroup rss | ||
1029 | 1565 | * @private | ||
1030 | 1325 | */ | 1566 | */ |
1031 | 1326 | function planet_element_data($parser, $data) { | 1567 | function planet_element_data($parser, $data) { |
1032 | 1327 | global $xml_tree, $xml_paths, $xml_path_cur; | 1568 | global $xml_tree, $xml_paths, $xml_path_cur; |
1033 | @@ -1333,6 +1574,12 @@ | |||
1034 | 1333 | } | 1574 | } |
1035 | 1334 | } | 1575 | } |
1036 | 1335 | 1576 | ||
1037 | 1577 | /** | ||
1038 | 1578 | * Page callback for 'planet' ("Planet"). | ||
1039 | 1579 | * @ingroup page | ||
1040 | 1580 | * @CRUD{node,R} | ||
1041 | 1581 | * @CRUD{variables,R} | ||
1042 | 1582 | */ | ||
1043 | 1336 | function planet_page_last() { | 1583 | function planet_page_last() { |
1044 | 1337 | global $user; | 1584 | global $user; |
1045 | 1338 | 1585 | ||
1046 | @@ -1351,6 +1598,12 @@ | |||
1047 | 1351 | print theme('page', $output); | 1598 | print theme('page', $output); |
1048 | 1352 | } | 1599 | } |
1049 | 1353 | 1600 | ||
1050 | 1601 | /** | ||
1051 | 1602 | * Page callback for 'planet/feed' ("Planet"). | ||
1052 | 1603 | * @ingroup page | ||
1053 | 1604 | * @CRUD{node,R} | ||
1054 | 1605 | * @CRUD{menu_links,R} | ||
1055 | 1606 | */ | ||
1056 | 1354 | function planet_feed() { | 1607 | function planet_feed() { |
1057 | 1355 | $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'planet' AND n.status = 1 ORDER BY n.created DESC"), 0, 15); | 1608 | $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'planet' AND n.status = 1 ORDER BY n.created DESC"), 0, 15); |
1058 | 1356 | $title = db_fetch_array(db_query("SELECT link_title FROM {menu_links} WHERE link_path = 'planet'")); | 1609 | $title = db_fetch_array(db_query("SELECT link_title FROM {menu_links} WHERE link_path = 'planet'")); |
1059 | @@ -1363,12 +1616,14 @@ | |||
1060 | 1363 | while ($row = db_fetch_object($result)) { | 1616 | while ($row = db_fetch_object($result)) { |
1061 | 1364 | $items[] = $row->nid; | 1617 | $items[] = $row->nid; |
1062 | 1365 | } | 1618 | } |
1064 | 1366 | 1619 | // generate RSS feed from $items set of nodes. | |
1065 | 1367 | node_feed($items, $channel); | 1620 | node_feed($items, $channel); |
1066 | 1368 | } | 1621 | } |
1067 | 1369 | 1622 | ||
1068 | 1370 | /** | 1623 | /** |
1070 | 1371 | * Implementation of hook_user(). | 1624 | * Implementation of hook_user() - React when operations are performed on user accounts. |
1071 | 1625 | * @ingroup system | ||
1072 | 1626 | * @CRUD{planet_feeds,R} | ||
1073 | 1372 | */ | 1627 | */ |
1074 | 1373 | function planet_user($type, &$edit, &$user) { | 1628 | function planet_user($type, &$edit, &$user) { |
1075 | 1374 | if ($type == 'view' && user_access('edit own blog', $user)) { | 1629 | if ($type == 'view' && user_access('edit own blog', $user)) { |
1076 | @@ -1390,6 +1645,8 @@ | |||
1077 | 1390 | 1645 | ||
1078 | 1391 | /** | 1646 | /** |
1079 | 1392 | * Menu callback; displays a Drupal page containing recent planet entries. | 1647 | * Menu callback; displays a Drupal page containing recent planet entries. |
1080 | 1648 | * @todo remove orphan function, or reuse it | ||
1081 | 1649 | * @ingroup page | ||
1082 | 1393 | */ | 1650 | */ |
1083 | 1394 | function planet_page($a = NULL, $b = NULL) { | 1651 | function planet_page($a = NULL, $b = NULL) { |
1084 | 1395 | 1652 | ||
1085 | @@ -1409,6 +1666,13 @@ | |||
1086 | 1409 | } | 1666 | } |
1087 | 1410 | } | 1667 | } |
1088 | 1411 | 1668 | ||
1089 | 1669 | /** | ||
1090 | 1670 | * Page callback for 'planet/%' ("planet"). | ||
1091 | 1671 | * @ingroup page | ||
1092 | 1672 | * | ||
1093 | 1673 | * @CRUD{node,R} | ||
1094 | 1674 | * @CRUD{variables,R} | ||
1095 | 1675 | */ | ||
1096 | 1412 | function planet_page_user($uid) { | 1676 | function planet_page_user($uid) { |
1097 | 1413 | global $user; | 1677 | global $user; |
1098 | 1414 | 1678 | ||
1099 | @@ -1441,12 +1705,28 @@ | |||
1100 | 1441 | } | 1705 | } |
1101 | 1442 | } | 1706 | } |
1102 | 1443 | 1707 | ||
1103 | 1708 | /** | ||
1104 | 1709 | * Implementation of hook_load - Load node-type-specific information. | ||
1105 | 1710 | * | ||
1106 | 1711 | * @param $node The node being loaded. | ||
1107 | 1712 | * @return An object containing properties of the node being loaded. | ||
1108 | 1713 | * @ingroup system | ||
1109 | 1714 | * @CRUD{planet_items,R} | ||
1110 | 1715 | */ | ||
1111 | 1444 | function planet_load($node) { | 1716 | function planet_load($node) { |
1112 | 1445 | $additions = db_fetch_object(db_query('SELECT link, guid FROM {planet_items} WHERE nid = %d', $node->nid)); | 1717 | $additions = db_fetch_object(db_query('SELECT link, guid FROM {planet_items} WHERE nid = %d', $node->nid)); |
1113 | 1446 | return $additions; | 1718 | return $additions; |
1114 | 1447 | } | 1719 | } |
1115 | 1448 | 1720 | ||
1117 | 1449 | function planet_form(&$node, &$param) { | 1721 | /** |
1118 | 1722 | * Implementation of hook_form - Display a node editing form. | ||
1119 | 1723 | * | ||
1120 | 1724 | * @param &$node The node being added or edited. | ||
1121 | 1725 | * @param $form_state The form state array (unused). | ||
1122 | 1726 | * @return An array containing the form elements to be displayed in the node edit form. | ||
1123 | 1727 | * @ingroup planet_node | ||
1124 | 1728 | */ | ||
1125 | 1729 | function planet_form(&$node, &$form_state) { | ||
1126 | 1450 | $form = array(); | 1730 | $form = array(); |
1127 | 1451 | $form['title'] = array('#type' => 'textfield', '#title' => 'Title', '#value' => $node->title, '#size' => 30, '#maxlength' => 80); | 1731 | $form['title'] = array('#type' => 'textfield', '#title' => 'Title', '#value' => $node->title, '#size' => 30, '#maxlength' => 80); |
1128 | 1452 | $form['body'] = array('#type' => 'textarea', '#title' => 'Body', '#value' => $node->body); | 1732 | $form['body'] = array('#type' => 'textarea', '#title' => 'Body', '#value' => $node->body); |