--- radioactivity.original.module 2008-04-30 00:47:43.000000000 +0200 +++ radioactivity.module 2008-04-30 00:42:58.000000000 +0200 @@ -262,7 +262,7 @@ function radioactivity_admin_profile_for '#default_value' => $decay_profile['energy_comment_publish']); $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save decay profile') ); - $form['buttons']['delete'] = array('#value' => l(t('Delete profile'), 'admin/settings/radioactivity/profile_'.$dpid.'/delete')); + $form['buttons']['delete'] = array('#value' => l('Delete profile', 'admin/settings/radioactivity/profile_'.$dpid.'/delete'));; if (!empty($_POST) && form_get_errors()) { drupal_set_message(t('The settings have not been saved because of the errors.'), 'error'); @@ -471,35 +471,33 @@ function radioactivity_get_radiocativity * Gives energy to node, if abuse control is passed. */ function radioactivity_user_node_view($nid) { - if (_radioactivity_get_click_duration()>0) { - global $user; - - $nid=(int)$nid; - $uid=$user->uid; - $remote_address=$_SERVER['REMOTE_ADDR']; - - // check if click is found - if ($user->uid) { - // not anonymous: use nid/uid - $result=db_query("SELECT count(*) FROM {radioactivity_clicks} WHERE nid=%d AND uid=%d", - $nid, $uid); - } else { - $result=db_query("SELECT count(*) FROM {radioactivity_clicks} WHERE nid=%d AND remote_address='%s'", - $nid, $remote_address); - } - $passed=(0 == db_result($result)); - if ($passed) { - // ok, record click - db_query("INSERT INTO {radioactivity_clicks} (nid, uid, remote_address, click_timestamp) ". - "VALUES (%d, %d, '%s', %d)", $nid, $uid, $remote_address, time()); - } else { - // don't add energy, because click was found - return FALSE; - } + if (_radioactivity_get_click_duration()==0) { + return radioactivity_add_energy($nid, 'view'); } - // ok, abuse control passed - return radioactivity_add_energy($nid, 'view'); + global $user; + + $nid=(int)$nid; + $uid=$user->uid; + $remote_address=$_SERVER['REMOTE_ADDR']; + + // check if click is found + if ($user->uid) { + // not anonymous: use nid/uid + $result=db_query("SELECT count(*) FROM {radioactivity_clicks} WHERE nid=%d AND uid=%d", + $nid, $uid); + } else { + $result=db_query("SELECT count(*) FROM {radioactivity_clicks} WHERE nid=%d AND remote_address='%s'", + $nid, $remote_address); + } + $passed=(0 == db_result($result)); + if ($passed) { + db_query("INSERT INTO {radioactivity_clicks} (nid, uid, remote_address, click_timestamp) ". + "VALUES (%d, %d, '%s', %d)", $nid, $uid, $remote_address, time()); + return radioactivity_add_energy($nid, 1); + } else { + return FALSE; + } } function radioactivity_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { @@ -552,7 +550,16 @@ function radioactivity_views_tables() { 'sortable' => TRUE)), 'sorts' => array('energy' => array('name' => t('Radioactivity: Node energy (@e)', array('@e'=>$decay_profile["label"])), - 'help' => t('Sort by node radioactive energy'))), + 'help' => t('Sort by node radioactive energy'), + 'handler' => 'radioactivity_handler_sort_energy', + 'option' => array( + '#type' => 'select', + '#options' => array( + 'radioactive' => 'Radioactive only', + 'all' => 'All' + ) + ), + 'extra' => array('decay_profile' => $dpid))), 'filters' => array('energy' => array('name' => t('Radioactivity: Node energy (@e)', array('@e'=>$decay_profile["label"])), 'help' => t('Filter by node energy'), @@ -562,4 +569,38 @@ function radioactivity_views_tables() { return $tables; } +function radioactivity_handler_sort_energy($op, &$query, $sortinfo, $sort) { + switch($sort['options']) { + case 'all': + $join = 'left'; + break; + + case 'radioactive': + default: + $join = 'inner'; + break; + } + + $table = $sortinfo['table']; + $field = $sortinfo['field']; + $order = $sort['sortorder']; + $extra = $sortinfo['extra']; + + $query->add_table('radioactivity_' . $extra['decay_profile'], TRUE, 1, array( + 'type' => $join, + 'left' => array( + 'table' => 'node', + 'field' => 'nid' + ), + 'right' => array( + 'field' => 'nid' + ), + 'extra' => $extra + )); + + //$query->add_orderby($table, $field, $order, NULL); + $query->add_field($field, $table, NULL); + $query->orderby[] = "$field IS NOT NULL $order, $field $order"; +} + ?>