Index: drigg_promotion.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/drigg/drigg_promotion/Attic/drigg_promotion.install,v retrieving revision 1.1.2.1 diff -u -r1.1.2.1 drigg_promotion.install --- drigg_promotion.install 23 Apr 2008 19:53:40 -0000 1.1.2.1 +++ drigg_promotion.install 31 Aug 2008 14:00:38 -0000 @@ -8,5 +8,14 @@ function drigg_promotion_uninstall() { variable_del('drigg_promotion_1_active'); variable_del('drigg_promotion_1_threshold'); + variable_del('drigg_promotion_2_active'); + variable_del('drigg_promotion_2_threshold'); + variable_del('drigg_promotion_3_active'); + variable_del('drigg_promotion_3_threshold'); + variable_del('drigg_promotion_4_active'); + variable_del('drigg_promotion_4_threshold'); + variable_del('drigg_promotion_5_active'); + variable_del('drigg_promotion_5_radioactivity_decay'); + variable_del('drigg_promotion_5_radioactivity_promote'); } Index: drigg_promotion.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/drigg/drigg_promotion/Attic/drigg_promotion.module,v retrieving revision 1.1.2.3 diff -u -r1.1.2.3 drigg_promotion.module --- drigg_promotion.module 18 May 2008 17:40:44 -0000 1.1.2.3 +++ drigg_promotion.module 31 Aug 2008 14:16:30 -0000 @@ -20,7 +20,7 @@ $items[] = array( 'path' => 'admin/settings/drigg/drigg_promotion', 'title' => t('Promotion'), - 'description' => t('Drigg module\'s preview of embedded content'), + 'description' => t('Drigg module\'s promotion mode'), 'callback' => 'drupal_get_form', 'callback arguments' => array('drigg_promotion_admin_settings'), 'access' => user_access('administer site configuration'), @@ -76,7 +76,7 @@ $form['auto_promoting'][1] = array( '#type' => 'fieldset', - '#title' => t('Promotion method 1'), + '#title' => t('Promotion method 1 : total of points from vote and karma'), '#collapsible' => FALSE, '#collapsed' => FALSE ); @@ -90,13 +90,117 @@ $form['auto_promoting'][1]['drigg_promotion_1_threshold'] = array( '#type' => 'textfield', - '#title' => t('How many votes before a story goes to the home page?'), + '#title' => t('How many points before a story goes to the home page?'), '#size' => 5, '#maxlength' => 5, '#required' => FALSE, '#default_value' => variable_get('drigg_promotion_1_threshold', 10), ); + $form['auto_promoting'][2] = array( + '#type' => 'fieldset', + '#title' => t('Promotion method 2 : total of votes gained (positive or negative)'), + '#collapsible' => FALSE, + '#collapsed' => FALSE + ); + + $form['auto_promoting'][2]['drigg_promotion_2_active'] = array( + '#type' => 'checkbox', + '#description' => t('Activate?'), + '#required' => FALSE, + '#default_value' => variable_get('drigg_promotion_2_active',FALSE) + ); + + $form['auto_promoting'][2]['drigg_promotion_2_threshold'] = array( + '#type' => 'textfield', + '#title' => t('How many votes (positive and negative) before a story goes to the home page (10 positive and 3 negative = 13)?'), + '#size' => 5, + '#maxlength' => 5, + '#required' => FALSE, + '#default_value' => variable_get('drigg_promotion_2_threshold', 10), + ); + + $form['auto_promoting'][3] = array( + '#type' => 'fieldset', + '#title' => t('Promotion method 3 : sum of positive votes'), + '#collapsible' => FALSE, + '#collapsed' => FALSE + ); + + $form['auto_promoting'][3]['drigg_promotion_3_active'] = array( + '#type' => 'checkbox', + '#description' => t('Activate?'), + '#required' => FALSE, + '#default_value' => variable_get('drigg_promotion_3_active',FALSE) + ); + + $form['auto_promoting'][3]['drigg_promotion_3_threshold'] = array( + '#type' => 'textfield', + '#title' => t('How many positive votes before a story is published to the home page -- negative votes here won\'t matter (10 positive and 3 negative = 10)?'), + '#size' => 5, + '#maxlength' => 5, + '#required' => FALSE, + '#default_value' => variable_get('drigg_promotion_3_threshold', 10), + ); + + $form['auto_promoting'][4] = array( + '#type' => 'fieldset', + '#title' => t('Promotion method 4 : sum of negative votes'), + '#collapsible' => FALSE, + '#collapsed' => FALSE + ); + + $form['auto_promoting'][4]['drigg_promotion_4_active'] = array( + '#type' => 'checkbox', + '#description' => t('Activate?'), + '#required' => FALSE, + '#default_value' => variable_get('drigg_promotion_4_active',FALSE) + ); + + $form['auto_promoting'][4]['drigg_promotion_4_threshold'] = array( + '#type' => 'textfield', + '#title' => t('How many negative votes before a story is published to the home page -- positive votes here won\'t matter (10 positive and 3 negative = 3)?'), + '#size' => 5, + '#maxlength' => 5, + '#required' => FALSE, + '#default_value' => variable_get('drigg_promotion_4_threshold', 10), + ); + + if (module_exists('radioactivity')) { + + $form['auto_promoting'][5] = array( + '#type' => 'fieldset', + '#title' => t('Promotion method 5 : Radioactivity'), + '#collapsible' => FALSE, + '#collapsed' => FALSE + ); + + $form['auto_promoting'][5]['drigg_promotion_5_active'] = array( + '#type' => 'checkbox', + '#description' => t('Activate?'), + '#required' => FALSE, + '#default_value' => variable_get('drigg_promotion_5_active',FALSE) + ); + + $form['auto_promoting'][5]['drigg_promotion_5_radioactivity_decay'] = array( + '#type' => 'textfield', + '#title' => t('Radioactivity : Decay profile to use.'), + '#size' => 5, + '#maxlength' => 5, + '#required' => FALSE, + '#default_value' => variable_get('drigg_promotion_5_radioactivity_decay', 1), + ); + + $form['auto_promoting'][5]['drigg_promotion_5_radioactivity_promote'] = array( + '#type' => 'textfield', + '#title' => t('Radioactivity : How much Radioactivity before a story goes to the home page.'), + '#size' => 5, + '#maxlength' => 5, + '#required' => FALSE, + '#default_value' => variable_get('drigg_promotion_5_radioactivity_promote', 100), + ); + } + return system_settings_form($form); } @@ -134,37 +238,117 @@ */ function drigg_promotion_new_vote($op,$v,$value){ - ///////////////////////////////////////////////// - // Method 1: general threshold - ///////////////////////////////////////////////// - if( variable_get('drigg_promotion_1_active',FALSE)){ - - list($content_type,$value_type, $tag,$function)=drigg_votingapi_variables(); + list($content_type,$value_type, $tag,$function)=drigg_votingapi_variables(); - // This method only works with unpromoted nodes which haven't been killed - if($v->content_type == $content_type && - $v->value_type == $value_type && - $v->tag == $tag){ + // This method only works with unpromoted nodes which haven't been killed + if($v->content_type == $content_type && + $v->value_type == $value_type && + $v->tag == $tag){ - $o=node_load($v->content_id); + $o=node_load($v->content_id); - if($o->promote == 0 && $o->killed == 0){ + if($o->promote == 0 && $o->killed == 0){ + ///////////////////////////////////////////////// + // Method 1: points gained + ///////////////////////////////////////////////// + if( variable_get('drigg_promotion_1_active',FALSE)){ // If the new karma is over the threshold, then promote the entry! - $karma = votingapi_get_voting_result($content_type,$v->content_id,$value_type,$tag,$function); - $karma = $karma->value; - $threshold=variable_get('drigg_promotion_1_threshold', 10); + $karma = votingapi_get_voting_result($content_type,$v->content_id,$value_type,$tag,$function); + $karma = $karma->value; + $threshold=variable_get('drigg_promotion_1_threshold', 10); if($karma + $value >= $threshold ){ - $m="Karma is $karma, vote is $value, threshold is $threshold, promoting node $v->content_id, vote id: $v->vote_id, and time is ".time()."!"; + $m="Method 1 : Karma is $karma, vote is $value, threshold is $threshold, promoting node $v->content_id, vote id: $v->vote_id, and time is ".time()."!"; drigg_debug_msg($m); watchdog("DRIGG PROMOTE",$m); drigg_promote_node($v->content_id); + return ''; } } + // END OF METHOD #1 + + if( variable_get('drigg_promotion_2_active',FALSE) || variable_get('drigg_promotion_3_active',FALSE) || variable_get('drigg_promotion_4_active',FALSE)) { + $raw_vote = votingapi_get_content_votes($content_type, $v->content_id); + } + + ///////////////////////////////////////////////// + // Method 2: total votes + ///////////////////////////////////////////////// + if( variable_get('drigg_promotion_2_active',FALSE)){ + // If the total vote is equal or more the threshold, then promote the entry! + $threshold=variable_get('drigg_promotion_2_threshold', 10); + if(count($raw_vote) >= $threshold ){ + $m="Method 2 : Total vote is ".count($raw_vote).", threshold is $threshold, promoting node $v->content_id, vote id: $v->vote_id, and time is ".time()."!"; + drigg_debug_msg($m); + watchdog("DRIGG PROMOTE",$m); + drigg_promote_node($v->content_id); + return ''; + } + } + // END OF METHOD #2 + + if( variable_get('drigg_promotion_3_active',FALSE) || variable_get('drigg_promotion_4_active',FALSE)) { + // Count positive and negatives votes + $posvotes=0; + $negvotes=0; + foreach ($raw_vote as $votedetail) { + if ($votedetail>0) { + $posvotes++; + } + elseif ($votedetail<0) { + $negvotes++; + } + } + } + + ///////////////////////////////////////////////// + // Method 3: positive votes + ///////////////////////////////////////////////// + if( variable_get('drigg_promotion_3_active',FALSE)){ + // If the POSITIVE vote is equal or more the threshold, then promote the entry! + $threshold=variable_get('drigg_promotion_3_threshold', 10); + if($posvotes >= $threshold ){ + $m="Method 3 : Total positive vote is $posvotes, threshold is $threshold, promoting node $v->content_id, vote id: $v->vote_id, and time is ".time()."!"; + drigg_debug_msg($m); + watchdog("DRIGG PROMOTE",$m); + drigg_promote_node($v->content_id); + return ''; + } + } + // END OF METHOD #3 + + ///////////////////////////////////////////////// + // Method 4: negative votes + ///////////////////////////////////////////////// + if( variable_get('drigg_promotion_4_active',FALSE)){ + // If the NEGATIVE vote is equal or less the threshold, then promote the entry! + $threshold=variable_get('drigg_promotion_4_threshold', 10); + if($negvotes >= $threshold ){ + $m="Method 4 : Total negative vote is $negvotes, threshold is $threshold, promoting node $v->content_id, vote id: $v->vote_id, and time is ".time()."!"; + drigg_debug_msg($m); + watchdog("DRIGG PROMOTE",$m); + drigg_promote_node($v->content_id); + return ''; + } + } + // END OF METHOD #4 + + ///////////////////////////////////////////////// + // Method 5: with radioactivity + ///////////////////////////////////////////////// + if( variable_get('drigg_promotion_5_active',FALSE) && module_exists('radioactivity') ){ + $radioactivity=radioactivity_get_energy($v->content_id, variable_get('drigg_promotion_5_radioactivity_decay', 1)); + if ( $radioactivity[variable_get('drigg_promotion_5_radioactivity_decay', 1)] >= variable_get('drigg_promotion_5_radioactivity_promote', 100)) { + $m="Method 5 : Karma is $karma, vote is $value, radioactivity is ".$radioactivity[variable_get('drigg_promotion_1_radioactivity_decay', 1)].", threshold is $threshold, promoting node $v->content_id, vote id: $v->vote_id, and time is ".time()."!"; + drigg_debug_msg($m); + watchdog("DRIGG PROMOTE",$m); + drigg_promote_node($v->content_id); + return ''; + } + } + // END OF METHOD #5 } } - // END OF METHOD #1 - }