/[drupal]/contributions/sandbox/frjo/vote_action/vote_actions.module
ViewVC logotype

Contents of /contributions/sandbox/frjo/vote_action/vote_actions.module

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


Revision 1.1 - (show annotations) (download) (as text)
Fri Jun 29 00:59:16 2007 UTC (2 years, 4 months ago) by frjo
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-php
This is mini "Voting Actions module" with hardcoded rules as a interim solution since the Voting Actions module has a number of unresolved bugs.
1 <?php
2 // $Id: vote_actions.module,v 1.15.2.4 2007/04/20 19:46:32 frjo Exp $
3
4 /**
5 * Lets users directly control the votingapi's integration with the actions module.
6 */
7
8 /**
9 * Implementation of hook_settings().
10 */
11 function vote_actions_admin_settings() {
12
13 $form['vote_actions_promote'] = array(
14 '#type' => 'textfield',
15 '#title' => t('Votes to promote to front page'),
16 '#default_value' => variable_get('vote_actions_promote', 0),
17 '#size' => 10,
18 '#description' => t('The vote sum that will promote a post to the front page.'),
19 );
20
21 $form['vote_actions_unpromote'] = array(
22 '#type' => 'textfield',
23 '#title' => t('Votes to remove from front page'),
24 '#default_value' => variable_get('vote_actions_unpromote', 0),
25 '#size' => 10,
26 '#description' => t('The vote sum that will remove a post from the front page.'),
27 );
28
29 $form['vote_actions_unpublish'] = array(
30 '#type' => 'textfield',
31 '#title' => t('Votes to unpublish from site'),
32 '#default_value' => variable_get('vote_actions_unpublish', 0),
33 '#size' => 10,
34 '#description' => t('The vote sum that will unpublish a post to the site.'),
35 );
36
37 return system_settings_form($form);
38 }
39
40 /*
41 * Implementation of hook_menu()
42 */
43 function vote_actions_menu($may_cache) {
44 $items = array();
45
46 if ($may_cache) {
47 $items[] = array(
48 'path' => 'admin/settings/voteactions',
49 'title' => t('Vote actions'),
50 'description' => t('Vote-driven triggers and actions for your site'),
51 'callback' => 'drupal_get_form',
52 'callback arguments' => 'vote_actions_admin_settings',
53 'access' => user_access('administer up-down vote'),
54 'type' => MENU_NORMAL_ITEM
55 );
56 }
57
58 return $items;
59 }
60
61 /*
62 * Implementation of hook_votingapi_results()
63 *
64 * Called by the Voting API whenever a result is calculated.
65 */
66 function vote_actions_votingapi_results($cached, $votes, $content_type, $content_id) {
67 $content = votingapi_load_content($content_id, $content_type);
68 if ($content_type != 'node' || $content == NULL) {
69 return;
70 }
71
72 foreach ($cached as $vote) {
73 if ($vote->function == 'sum') {
74 if ($vote->value >= variable_get('vote_actions_promote', 0) && !$content->promote) {
75 $actions = array('action_node_promote', 'action_vote_up_down_userpoints_add');
76 actions_do($actions, $content);
77 }
78 if ($vote->value <= variable_get('vote_actions_unpromote', 0) && $content->promote) {
79 $actions = array('action_node_unpromote', 'action_vote_up_down_userpoints_remove');
80 actions_do($actions, $content);
81 }
82 if ($vote->value <= variable_get('vote_actions_unpublish', 0) && $content->status) {
83 $actions = array('action_node_unpublish');
84 actions_do($actions, $content);
85 }
86 }
87 }
88 }
89

  ViewVC Help
Powered by ViewVC 1.1.2