/[drupal]/contributions/modules/vote_up_down/vote_storylink.module
ViewVC logotype

Contents of /contributions/modules/vote_up_down/vote_storylink.module

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


Revision 1.31 - (show annotations) (download) (as text)
Tue Sep 30 17:51:43 2008 UTC (13 months, 3 weeks ago) by lut4rp
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.30: +148 -30 lines
File MIME type: text/x-php
Added translations
1 <?php
2 // $Id: vote_storylink.module,v 1.30 2007/11/22 08:50:10 frjo Exp $
3
4 /* TODO hook_submit() has been removed
5 In Drupal 5.x, hook_submit() allowed node modules to alter the node before
6 saving it to the database (it was run between hook_validate() and
7 hook_insert()/hook_update()). In Drupal 6.x this hook has been removed.
8 Instead, you should attach a submit handler to the form created in hook_form(),
9 and then alter the $form_state['values'] array as needed.
10 A submit handler would look like:
11 $form['#submit'] = array('mymodule_node_form_submit_handler'); */
12
13 /* TODO Use drupal_set_breadcrumb() instead of menu_set_location() to set
14 custom breadcrumbs.
15 Currently in D5, menu_set_location() is 'misused' in several modules to set
16 a custom breadcrumb, drupal_set_breadcrumb() should be used instead, as
17 discussed in #177497.
18 Note, when using drupal_set_breadcrumb(), you need to include 'home' but
19 not the current page.
20 Alternatively, if you do want to set the current location in the menu tree
21 as well as affect breadcrumbs, use menu_set_item(). */
22
23 /* TODO FormAPI image buttons are now supported.
24 FormAPI now offers the 'image_button' element type, allowing developers to
25 use icons or other custom images in place of traditional HTML submit buttons.
26
27 $form['my_image_button'] = array(
28 '#type' => 'image_button',
29 '#title' => t('My button'),
30 '#return_value' => 'my_data',
31 '#src' => 'my/image/path.jpg',
32 ); */
33
34 /* TODO Remove $row argument from db_result() method
35 The $row argument of db_result() was removed from the database abstraction
36 layer in 6.x core, as it was a database dependent option. Developers need to
37 use other handling to replace the needs of this method. */
38
39 /* TODO node_feed() parameters changed
40 node_feed() now accepts an array of nids (i.e. integers), and not a database
41 result object. this is more flexible for callers but sometimes slighly less
42 efficient. */
43
44 /* TODO hook_user('view')
45 The return value of hook_user('view') has changed, to match the process that
46 nodes use for rendering. Modules should add their custom HTML to
47 $account->content element. Further, this HTML should be in the form that
48 drupal_render() recognizes. */
49
50 /* TODO Node previews and adding form fields to the node form.
51 There is a subtle but important difference in the way node previews (and other
52 such operations) are carried out when adding or editing a node. With the new
53 Forms API, the node form is handled as a multi-step form. When the node form
54 is previewed, all the form values are submitted, and the form is rebuilt with
55 those form values put into $form['#node']. Thus, form elements that are added
56 to the node form will lose any user input unless they set their '#default_value'
57 elements using this embedded node object. */
58
59 /* TODO New user_mail_tokens() method may be useful.
60 user.module now provides a user_mail_tokens() function to return an array
61 of the tokens available for the email notification messages it sends when
62 accounts are created, activated, blocked, etc. Contributed modules that
63 wish to make use of the same tokens for their own needs are encouraged
64 to use this function. */
65
66 /* TODO
67 There is a new hook_watchdog in core. This means that contributed modules
68 can implement hook_watchdog to log Drupal events to custom destinations.
69 Two core modules are included, dblog.module (formerly known as watchdog.module),
70 and syslog.module. Other modules in contrib include an emaillog.module,
71 included in the logging_alerts module. See syslog or emaillog for an
72 example on how to implement hook_watchdog.
73 function example_watchdog($log = array()) {
74 if ($log['severity'] == WATCHDOG_ALERT) {
75 mysms_send($log['user']->uid,
76 $log['type'],
77 $log['message'],
78 $log['variables'],
79 $log['severity'],
80 $log['referer'],
81 $log['ip'],
82 format_date($log['timestamp']));
83 }
84 } */
85
86 /* TODO Implement the hook_theme registry. Combine all theme registry entries
87 into one hook_theme function in each corresponding module file.
88 function vote_storylink_theme() {
89 return array(
90 'vote_storylink_via' => array(
91 'file' => 'vote_storylink.module',
92 'arguments' => array(
93 'link_url' => NULL,
94 ),
95 ),
96 );
97 } */
98
99 /*
100 * @file
101 * vote_storylink defines a "storylink" node type.
102 * It's based upon "links_weblink.module".
103 */
104
105 /**
106 * Implementation of hook_help().
107 */
108 function vote_storylink_help($path, $arg) {
109 switch ($path) {
110 case 'admin/help#vote_storylink':
111 return t('<p>This module is used to create articles that links to other resources -- websites, pages, documents, etc., part of Vote up/down.</p>');
112 }
113 }
114
115 /**
116 * Implementation of hook_node_info().
117 */
118 function vote_storylink_node_info() {
119 return array(
120 'storylink' => array(
121 'name' => t('Storylink'),
122 'module' => 'vote_storylink',
123 'has_title' => TRUE,
124 'has_body' => TRUE,
125 'description' => t('A story link is an article whose main purpose is to create links to other resources -- websites, pages, documents, etc.'),
126 ),
127 );
128 }
129
130 /**
131 * Implementation of hook_perm().
132 */
133 function vote_storylink_perm() {
134 return array('create storylinks', 'edit own storylinks', 'view storylinks');
135 }
136
137 /**
138 * Implementation of hook_access().
139 */
140 function vote_storylink_access($op, $node, $account) {
141
142
143 switch ($op) {
144 case 'view':
145 return $node->status && user_access('view storylinks', $account);
146 case 'create':
147 return user_access('create storylinks', $account);
148 case 'update':
149 case 'delete':
150 return user_access('edit own storylinks', $account) && ($account->uid == $node->uid);
151 }
152 }
153
154 /**
155 * Implementation of hook_settings().
156
157 function vote_storylink_admin_settings() {
158 if (!module_exists('links')) {
159 drupal_set_message(t('The &quot;links&quot; module is disabled or not installed. Storylinks will not function until this is corrected. Check the availability of
160 that module, and enable if needed, in the !modules.',array('!modules'=>l(t('modules administration page'),'admin/modules'))),'error');
161 }
162
163 return system_settings_form($form);
164 } */
165
166 /**
167 * Implementation of hook_menu().
168 */
169 function vote_storylink_menu() {
170 global $user;
171 $items = array();
172
173 /* TODO
174 Non menu code that was placed in hook_menu under the '!$may_cache' block
175 so that it could be run during initialization, should now be moved to hook_init.
176 Previously we called hook_init twice, once early in the bootstrap process, second
177 just after the bootstrap has finished. The first instance is now called boot
178 instead of init.
179
180 In Drupal 6, there are now two hooks that can be used by modules to execute code
181 at the beginning of a page request. hook_boot() replaces hook_boot() in Drupal 5
182 and runs on each page request, even for cached pages. hook_boot() now only runs
183 for non-cached pages and thus can be used for code that was previously placed in
184 hook_menu() with $may_cache = FALSE:
185
186 Dynamic menu items under a '!$may_cache' block can often be simplified
187 to remove references to arg(n) and use of '%<function-name>' to check
188 conditions. See http://drupal.org/node/103114.
189
190 The title and description arguments should not have strings wrapped in t(),
191 because translation of these happen in a later stage in the menu system.
192 */
193 if ($may_cache) {
194 $items['storylink'] = array(
195 'title' => 'Story links',
196 'page callback' => 'vote_storylink_page',
197 'access arguments' => array('access content'),
198 'type' => MENU_CALLBACK
199 );
200 $items['storylink/'. $user->uid] = array(
201 'title' => 'My story links',
202 'access arguments' => array('create storylinks'),
203 'type' => MENU_DYNAMIC_ITEM
204 );
205 }
206
207 return $items;
208 }
209
210 /**
211 * Implementation of hook_user().
212 */
213 function vote_storylink_user($type, &$edit, &$account, $category = NULL) {
214 if ($type == 'view' && user_access('create storylinks', $account)) {
215 $items[] = array(
216 'title' => t('Story links'),
217 'value' => /* TODO
218 Please manually fix the parameters on the l() or url() function on the next line.
219 Typically, this was not changed because of a function call inside an array call like
220 array('title' => t('View user profile.')).*/
221 l(t('view recent story links'), "storylink/$account->uid", array('title' => t("Read @username's latest story links.", array('@username' => $account->name)))),
222 'class' => 'storylink',
223 );
224 return array(t('History') => $items);
225 }
226 }
227
228 /**
229 * Implementation of hook_nodeapi().
230 */
231 function vote_storylink_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
232 switch ($op) {
233 case 'rss item':
234 if ($node->type == 'storylink' && variable_get('feed_item_length', 'teaser') == 'teaser') {
235 $node->teaser .= '<p><a href="'. check_url($node->vote_storylink_url) .'" title="'. t('Go to the original news source.') .'">'. t('Original news source') .'</a></p>';
236 }
237 elseif ($node->type == 'storylink' && variable_get('feed_item_length', 'teaser') == 'fulltext') {
238 $node->body .= '<p><a href="'. check_url($node->vote_storylink_url) .'" title="'. t('Go to the original news source.') .'">'. t('Original news source') .'</a></p>';
239 }
240 break;
241 }
242 }
243
244 /**
245 * Implementation of hook_form().
246 */
247 function vote_storylink_form(&$node, &$param) {
248
249 $form['title'] = array(
250 '#type' => 'textfield',
251 '#title' => t('Title'),
252 '#required' => TRUE,
253 '#default_value' => $node->title,
254 '#maxlength' => 96,
255 '#description' => t("Title of the story the link goes to, max 96 characters."),
256 '#weight' => -18,
257 );
258
259 $form['vote_storylink_url'] = array(
260 '#type' => 'textfield',
261 '#title' => t('URL'),
262 '#default_value' => $node->vote_storylink[0]['url'],
263 '#maxlength' => 256,
264 '#required' => TRUE,
265 '#description' => t('The URL/address of the story.'),
266 '#validate' => array('_vote_storylink_valid_url'),
267 '#_vote_storylink_valid_url_param_1' => 'vote_storylink_url',
268 '#weight' => -17,
269 );
270
271 $form['body_filter']['body'] = array(
272 '#type' => 'textarea',
273 '#title' => t('Description'),
274 '#default_value' => $node->body,
275 '#required' => FALSE,
276 '#rows' => 5,
277 '#maxlength' => 600,
278 '#resizable' => TRUE,
279 '#description' => t('A short description of the story. It should be around 2 to 4 sentences.'),
280 '#weight' => -16,
281 );
282
283 $form['body_filter']['filter'] = filter_form($node->format);
284
285 return $form;
286 }
287
288 /**
289 * Implementation of hook_view().
290 */
291 function vote_storylink_view($node, $teaser = FALSE, $page = FALSE) {
292 if ($page) {
293 // Breadcrumb navigation
294 $breadcrumb[] = array('path' => 'storylink', 'title' => t('Story links'));
295 $breadcrumb[] = array('path' => 'storylink/'. $node->uid, 'title' => t("@name's story links", array('@name' => $node->name)));
296 $breadcrumb[] = array('path' => 'node/'. $node->nid);
297 menu_set_location($breadcrumb);
298 }
299 $node = node_prepare($node, $teaser);;
300
301 return $node;
302 }
303
304 /**
305 * Implementation of hook_load().
306 */
307 function vote_storylink_load($node) {
308 $links = links_load_links_for_node($node->nid, 'vote_storylink', 0, TRUE);
309 return array('vote_storylink_url' => $links[0]['url'], 'vote_storylink' => $links);
310 }
311
312 /**
313 * Implementation of hook_prepare().
314 */
315 function vote_storylink_prepare(&$node) {
316 // Allow the following fields to be initialized via $_GET (e.g. for use
317 // with a "submit it" bookmarklet):
318 foreach (array('title', 'body') as $field) {
319 if ($_GET['edit'][$field]) {
320 $node->$field = $_GET['edit'][$field];
321 }
322 }
323
324 if (isset($_POST['edit']['vote_storylink_url'])) {
325 $node->vote_storylink_url = $_POST['edit']['vote_storylink_url'];
326 }
327 else if ($_GET['edit']['url']) {
328 $node->vote_storylink_url = check_url($_GET['edit']['url']);;
329 }
330 else if (empty($node->vote_storylink_url)) {
331 $node->vote_storylink_url = 'http://';
332 }
333 vote_storylink_node_build($node);
334 }
335
336 /**
337 * Implementation of hook_validate().
338 */
339 function vote_storylink_validate(&$node) {
340 vote_storylink_node_build($node);
341 if ($nid = db_result(db_query("SELECT ln.nid FROM {links} l INNER JOIN {links_node} ln ON l.lid = ln.lid WHERE ln.nid != %d AND LOWER(l.url) = LOWER('%s')", $node->nid, $node->vote_storylink_url))) {
342 form_set_error('vote_storylink_url', t('This story is already submitted. !clickhere to view and vote on it.', array('!clickhere' => l('Click here', 'node/'. $nid))));
343 }
344 }
345
346 /**
347 * Implementation of hook_delete().
348 */
349 function vote_storylink_delete(&$node) {
350 // Delete the values from a node that is being erased
351 // Don't care if it's "supposed" to have links -- delete if found anyway
352 vote_storylink_node_build($node);
353 links_delete_links_for_node($node, 'vote_storylink');
354 }
355
356 /**
357 * Implementation of hook_insert().
358 */
359 function vote_storylink_insert(&$node) {
360 vote_storylink_node_build($node);
361 links_save_links_for_node($node, 'vote_storylink');
362 }
363
364 /**
365 * Implementation of hook_update().
366 */
367 function vote_storylink_update(&$node) {
368 vote_storylink_node_build($node);
369 links_save_links_for_node($node, 'vote_storylink');
370 }
371
372 /**
373 * Implementation of hook_link().
374 */
375 function vote_storylink_link($type, $node = NULL, $teaser = FALSE) {
376 $links = array();
377
378 if ($teaser && $type == 'node' && $node->type == 'storylink') {
379 $links['vote_storylink'] = array(
380 'title' => t('More info'),
381 'href' => 'node/'. $node->nid,
382 'attributes' => array('title' => t('More information about this post.'))
383 );
384 }
385
386 return $links;
387 }
388
389 /**
390 * Implementation of hook_block().
391 */
392 function vote_storylink_block($op = 'list', $delta = 0) {
393 if ($op == 'list') {
394 $blocks[0]['info'] = t('Top story links');
395 $blocks[1]['info'] = t('User navigation story links');
396 return $blocks;
397 }
398 else if ($op == 'view') {
399 if (user_access('access content')) {
400 switch ($delta) {
401 case 0:
402 $title = t('Top stories');
403 $items = array();
404 $items[] = l(t('This day'), 'storylink/top/day');
405 $items[] = l(t('This week'), 'storylink/top/week');
406 $items[] = l(t('This month'), 'storylink/top/month');
407 $items[] = l(t('This year'), 'storylink/top/year');
408 $items[] = l(t('All time'), 'storylink/top');
409 break;
410 case 1:
411 global $user;
412 if ($user->uid) {
413 //userpoints integration
414 if (module_exists('userpoints')) {
415 $title = $user->name .' ('. userpoints_get_current_points($user->uid) .')';
416 }
417 else {
418 $title = $user->name;
419 }
420 $items = array();
421 $items[] = l(t('Submit new story'), 'node/add/storylink');
422 $items[] = l(t('My account'), 'user/'. $user->uid);
423 $items[] = l(t('My story links'), 'storylink/'. $user->uid);
424 $items[] = l(t('Log out'), 'logout');
425 }
426 break;
427 }
428
429 if ($items) {
430 $block['subject'] = check_plain($title);
431 $block['content'] = theme('item_list', $items);
432 }
433
434 return $block;
435 }
436 }
437 }
438
439 /**
440 * Menu callback; displays a Drupal page containing recent story links entries.
441 */
442 function vote_storylink_page($a = NULL, $b = NULL, $c = NULL) {
443
444 if (is_numeric($a)) { // $a is a user ID
445 if ($b == 'feed') {
446 return vote_storylink_feed_user($a);
447 }
448 else {
449 return vote_storylink_page_user($a);
450 }
451 }
452 else {
453 switch ($a) {
454 case 'new':
455 if ($b == 'feed') {
456 return vote_storylink_feed_new();
457 }
458 else {
459 return vote_storylink_page_new();
460 }
461 break;
462 case 'queue':
463 if ($b == 'feed') {
464 return vote_storylink_feed_queue();
465 }
466 else {
467 return vote_storylink_page_queue();
468 }
469 break;
470 case 'top':
471 if ($b == 'feed') {
472 return vote_storylink_feed_top();
473 }
474 else if ($b == ('day' || 'week' || 'month' || 'year')) {
475 if ($c == 'feed') {
476 return vote_storylink_feed_interval_top($b);
477 }
478 else {
479 return vote_storylink_page_interval_top($b);
480 }
481 }
482 else {
483 return vote_storylink_page_top();
484 }
485 break;
486 default:
487 return vote_storylink_page_new();
488 }
489 }
490 }
491
492 /**
493 * Display views of the storylinks
494 */
495 function vote_storylink_page_new() {
496 drupal_set_title($title = t('New story links'));
497 $sql = db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'storylink' AND n.status = 1 ORDER BY n.created DESC");
498 $result = pager_query($sql, variable_get('default_nodes_main', 10));
499 while ($node = db_fetch_object($result)) {
500 $output .= node_view(node_load($node->nid), 1);
501 }
502 $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
503 $output .= theme('feed_icon', url('storylink/new/feed'));
504
505 $feed_url = url('storylink/new/feed', array('absolute' => TRUE));
506 drupal_add_feed($feed_url, t('RSS - @title', array('@title' => $title)));
507
508 return $output;
509 }
510
511 function vote_storylink_page_queue() {
512 drupal_set_title($title = t('Queue story links'));
513 $sql = db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'storylink' AND n.status = 1 AND n.promote = 0 ORDER BY n.created DESC");
514 $result = pager_query($sql, variable_get('default_nodes_main', 10));
515 while ($node = db_fetch_object($result)) {
516 $output .= node_view(node_load($node->nid), 1);
517 }
518 $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
519 $output .= theme('feed_icon', url('storylink/queue/feed'));
520
521 $feed_url = url('storylink/queue/feed', array('absolute' => TRUE));
522 drupal_add_feed($feed_url, t('RSS - @title', array('@title' => $title)));
523
524 return $output;
525 }
526
527 function vote_storylink_page_top() {
528 drupal_set_title($title = t('Popular story links'));
529 $sql = db_rewrite_sql("SELECT n.nid, n.created, v.content_id, v.value, v.tag, v.function FROM {node} n INNER JOIN {votingapi_cache} v ON n.nid = v.content_id WHERE n.type = 'storylink' AND n.status = 1 AND v.tag = 'vote' AND v.function = 'sum' AND v.content_type = 'node' ORDER BY v.value DESC, n.created DESC");
530 $result = pager_query($sql, variable_get('default_nodes_main', 10));
531 while ($node = db_fetch_object($result)) {
532 $output .= node_view(node_load($node->nid), 1);
533 }
534 $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
535 $output .= theme('feed_icon', url('storylink/top/feed'));
536
537 $feed_url = url('storylink/top/feed', array('absolute' => TRUE));
538 drupal_add_feed($feed_url, t('RSS - @title', array('@title' => $title)));
539
540 return $output;
541 }
542
543 function vote_storylink_page_interval_top($interval) {
544 drupal_set_title($title = t('Popular story links this @epoch', array('@epoch' => t($interval))));
545 $epoch = strtotime("-1 $interval");
546 $sql = db_rewrite_sql("SELECT n.nid, n.created, v.content_id, v.value, v.tag, v.function FROM {node} n INNER JOIN {votingapi_cache} v ON n.nid = v.content_id WHERE n.type = 'storylink' AND n.status = 1 AND n.created >= %d AND v.tag = 'vote' AND v.function = 'sum' AND v.content_type = 'node' ORDER BY v.value DESC, n.created DESC");
547 $result = pager_query($sql, variable_get('default_nodes_main', 10), 0, NULL, $epoch);
548 while ($node = db_fetch_object($result)) {
549 $output .= node_view(node_load($node->nid), 1);
550 }
551 $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
552 $output .= theme('feed_icon', url("storylink/top/$interval/feed"));
553
554 $feed_url = url("storylink/top/$interval/feed", array('absolute' => TRUE));
555 drupal_add_feed($feed_url, t('RSS - @title', array('@title' => $title)));
556
557 return $output;
558 }
559
560 /**
561 * Displays a Drupal page containing recent storylink entries of a given user.
562 */
563 function vote_storylink_page_user($uid) {
564 global $user;
565
566 $account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1));
567
568 if ($account->uid) {
569 drupal_set_title($title = t("@name's story links", array('@name' => $account->name)));
570 $sql = db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE type = 'storylink' AND n.uid = %d AND n.status = 1 ORDER BY n.created DESC");
571 $result = pager_query($sql, variable_get('default_nodes_main', 10), 0, NULL, $account->uid);
572 while ($node = db_fetch_object($result)) {
573 $output .= node_view(node_load($node->nid), 1);
574 }
575 $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
576 $output .= theme('feed_icon', url("storylink/$account->uid/feed"));
577
578 $feed_url = url("storylink/$account->uid/feed", array('absolute' => TRUE));
579 drupal_add_feed($feed_url, t('RSS - @title', array('@title' => $title)));
580
581 return $output;
582 }
583 else {
584 drupal_not_found();
585 }
586 }
587
588 /**
589 * Displays an RSS feed containing recent storylink entries of all users.
590 */
591 function vote_storylink_feed_new() {
592 $sql = db_rewrite_sql("SELECT n.nid, n.title, n.created, r.teaser FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid WHERE n.type = 'storylink' AND n.status = 1 ORDER BY n.created DESC");
593 $result = db_query_range($sql, 0, variable_get('feed_default_items', 10));
594 $channel['title'] = variable_get('site_name', 'drupal') .' new';
595 $channel['link'] = url('storylink/new', array('absolute' => TRUE));
596 $channel['description'] = t('New storylinks');
597 node_feed($result, $channel);
598 }
599
600 function vote_storylink_feed_queue() {
601 $sql = db_rewrite_sql("SELECT n.nid, n.title, n.created, r.teaser FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid WHERE n.type = 'storylink' AND n.status = 1 AND n.promote = 0 ORDER BY n.created DESC");
602 $result = db_query_range($sql, 0, variable_get('feed_default_items', 10));
603 $channel['title'] = variable_get('site_name', 'drupal') .' queue';
604 $channel['link'] = url('storylink/queue', array('absolute' => TRUE));
605 $channel['description'] = t('Queued storylinks');
606 node_feed($result, $channel);
607 }
608
609 function vote_storylink_feed_top() {
610 $sql = db_rewrite_sql("SELECT n.nid, n.created, n.title, r.teaser, v.content_id, v.value, v.tag, v.function FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid INNER JOIN {votingapi_cache} v ON n.nid = v.content_id WHERE n.type = 'storylink' AND n.status = 1 AND v.tag = 'vote' AND v.function = 'sum' AND v.content_type = 'node' ORDER BY v.value DESC, n.created DESC");
611 $result = db_query_range($sql, 0, variable_get('feed_default_items', 10));
612 $channel['title'] = variable_get('site_name', 'drupal') .' popular';
613 $channel['link'] = url('storylink/top', array('absolute' => TRUE));
614 $channel['description'] = t('Popular storylinks');
615 node_feed($result, $channel);
616 }
617
618 function vote_storylink_feed_interval_top($interval) {
619 $epoch = strtotime("-1 $interval");
620 $sql = db_rewrite_sql("SELECT n.nid, n.created, n.title, r.teaser, v.content_id, v.value, v.tag, v.function FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid INNER JOIN {votingapi_cache} v ON n.nid = v.content_id WHERE n.type = 'storylink' AND n.status = 1 AND n.created >= %d AND v.tag = 'vote' AND v.function = 'sum' AND v.content_type = 'node' ORDER BY v.value DESC, n.created DESC");
621 $result = db_query_range($sql, $epoch, 0, variable_get('feed_default_items', 10));
622 $channel['title'] = variable_get('site_name', 'drupal') .' popular story links this '. $interval;
623 $channel['link'] = url("storylink/top/$interval", array('absolute' => TRUE));
624 $channel['description'] = t('Popular storylinks');
625 node_feed($result, $channel);
626 }
627
628 function vote_storylink_feed_user($uid = 0) {
629 global $user;
630
631 if ($uid) {
632 $account = user_load(array('uid' => $uid, 'status' => 1));
633 }
634 else {
635 $account = $user;
636 }
637 $sql = db_rewrite_sql("SELECT n.nid, n.title, n.created, r.teaser, u.name, u.uid FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = 'storylink' AND u.uid = %d AND n.status = 1 ORDER BY n.created DESC");
638 $result = db_query_range($sql, $uid, 0, variable_get('feed_default_items', 10));
639 $channel['title'] = $account->name ."'s story links";
640 $channel['link'] = url("storylink/$uid", array('absolute' => TRUE));
641 $channel['description'] = t('User storylinks');
642 node_feed($result, $channel);
643 }
644
645 /**
646 * Theme the display of (via example.com).
647 */
648 function theme_vote_storylink_via($link_url) {
649 $link_url = parse_url($link_url);
650 $output = '<div class="vote-up-down-via">('. t('via @domain', array('@domain' => $link_url['host'])) .')</div>';
651 return $output;
652 }
653
654 /**
655 * Validate the URL.
656 */
657 function _vote_storylink_valid_url($formelement, $fieldname) {
658 $url = $formelement['#value'];
659 if (!preg_match('/^(http|https):\/\/[a-z0-9]+([\-\.]{1,2}[a-z0-9]+)*\.[a-z]{2,6}((:[0-9]{1,5})?\/.*)?$/i', $url)) {
660 form_set_error($fieldname, t('The URL is not valid.'));
661 }
662 }
663
664 /**
665 * To use the links API, we sometimes need to populate the internal data
666 * structure $node->vote_storylink, which is an array of link-definition
667 * arrays. In this case, the outer array always contains exactly one element
668 * because we are interested only in the primary URL for the storylink. If
669 * this site allows "related links" for storylink nodes, that's handled
670 * by the links_related module, not here.
671 */
672 function vote_storylink_node_build(&$node, $url = '') {
673 if (empty($url)) {
674 $url = links_normalize_url($node->vote_storylink_url);
675 }
676 else {
677 $url = links_normalize_url($url);
678 }
679 $node->vote_storylink_url = $url;
680 $link = array(
681 'url' => $url,
682 'link_title' => $node->title,
683 'weight' => 0,
684 );
685 // Wrap $link as the [0] element of a trivial outer array.
686 $node->vote_storylink = array($link);
687 }

  ViewVC Help
Powered by ViewVC 1.1.2