| 1 |
<?php |
<?php |
| 2 |
// $Id: interests.module,v 1.7 2009/04/24 06:43:38 agileware Exp $ |
// $Id: interests.module,v 1.7.2.1 2009/06/01 12:08:12 agileware Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file interests.module |
* @file interests.module |
| 22 |
*/ |
*/ |
| 23 |
function interests_menu() { |
function interests_menu() { |
| 24 |
$items = array(); |
$items = array(); |
| 25 |
|
|
| 26 |
|
$items['admin/settings/interests'] = array( |
| 27 |
|
'title' => t('Interests'), |
| 28 |
|
'page callback' => 'drupal_get_form', |
| 29 |
|
'page arguments' => array('interests_settings_form'), |
| 30 |
|
'access callback' => 'user_access', |
| 31 |
|
'access arguments' => array('administer interests'), |
| 32 |
|
'type' => MENU_NORMAL_ITEM, |
| 33 |
|
); |
| 34 |
$items['user/%user/interests'] = array( |
$items['user/%user/interests'] = array( |
| 35 |
'title' => t('My Interests'), |
'title' => t('My Interests'), |
| 36 |
'page callback' => 'interests_my_interests', |
'page callback' => 'interests_my_interests', |
| 156 |
} |
} |
| 157 |
return $links; |
return $links; |
| 158 |
} |
} |
| 159 |
|
|
| 160 |
|
/** |
| 161 |
|
* Interests settings form. |
| 162 |
|
*/ |
| 163 |
|
function interests_settings_form() { |
| 164 |
|
$form['interesting_nodes'] = array( |
| 165 |
|
'#type' => 'fieldset', |
| 166 |
|
'#title' => t('My Interests node lists'), |
| 167 |
|
); |
| 168 |
|
$options = node_get_types('names'); |
| 169 |
|
$defaults = array_keys($options); |
| 170 |
|
$form['interesting_nodes']['interests_interesting_node_types'] = array( |
| 171 |
|
'#type' => 'checkboxes', |
| 172 |
|
'#title' => t('Content types to include for node lists on My Interests page'), |
| 173 |
|
'#options' => $options, |
| 174 |
|
'#default_value' => variable_get('interests_interesting_node_types', $defaults), |
| 175 |
|
'#description' => t('Select the node types to display on the My Interests page.'), |
| 176 |
|
); |
| 177 |
|
$form['interesting_nodes']['interests_interesting_node_include_teaser'] = array( |
| 178 |
|
'#type' => 'checkbox', |
| 179 |
|
'#title' => t('Include teaser in node lists on My Interests page'), |
| 180 |
|
'#default_value' => variable_get('interests_interesting_node_include_teaser', 0), |
| 181 |
|
'#description' => t('Check this box if you would like the node teaser to display in the node lists on the My Interests page.'), |
| 182 |
|
); |
| 183 |
|
$options = array(); |
| 184 |
|
for ($i = 1; $i <= 20; $i++) { |
| 185 |
|
$options[$i] = $i; |
| 186 |
|
} |
| 187 |
|
$form['interesting_nodes']['interests_interesting_node_limit'] = array( |
| 188 |
|
'#type' => 'select', |
| 189 |
|
'#title' => t('Number of nodes in node lists on My Interests page'), |
| 190 |
|
'#options' => $options, |
| 191 |
|
'#default_value' => variable_get('interests_interesting_node_limit', 5), |
| 192 |
|
'#description' => t('Select the number of nodes to display for each node type in the node lists on the My Interests page.'), |
| 193 |
|
); |
| 194 |
|
|
| 195 |
|
return system_settings_form($form); |
| 196 |
|
} |
| 197 |
|
|
| 198 |
/** |
/** |
| 199 |
* My interests form (tab on my account page) |
* My interests form (tab on my account page) |
| 391 |
*/ |
*/ |
| 392 |
function interests_my_interests($user) { |
function interests_my_interests($user) { |
| 393 |
$in = ''; |
$in = ''; |
| 394 |
$query_vars = array(); |
$query_vars = array(); |
| 395 |
|
$teaser = variable_get('interests_interesting_node_include_teaser', 0); |
| 396 |
|
$node_types = node_get_types('names'); |
| 397 |
|
$allowed_types = variable_get('interests_interesting_node_types', array_keys($node_types)); |
| 398 |
|
$limit = variable_get('interests_interesting_node_limit', 5); |
| 399 |
|
|
| 400 |
if (module_exists('blog')) { |
if (module_exists('blog')) { |
| 401 |
$blog_enabled = TRUE; |
$blog_enabled = TRUE; |
| 402 |
} |
} |
| 403 |
|
|
| 404 |
$output = l(t('Change My Interests'), 'user/' . $user->uid . '/interests/edit'); |
$output = t('<a href="' . url('user/' . $user->uid . '/interests/edit') . '"><button type="button">Change my interests</button></a>'); |
| 405 |
|
|
| 406 |
// Do the selection of users where at least one tag matches, order by number of matches - Limited to 10 |
// Do the selection of users where at least one tag matches, order by number of matches - Limited to 10 |
| 407 |
|
|
| 413 |
} |
} |
| 414 |
if ($in != '') { |
if ($in != '') { |
| 415 |
$query_vars[] = $user->uid; |
$query_vars[] = $user->uid; |
|
$sql = "SELECT DISTINCT u.uid, u.name, SUM(i.counter) AS total_count |
|
|
FROM {interests} i, {users} u |
|
|
WHERE u.uid = i.uid |
|
|
AND i.tid IN ($in) |
|
|
AND i.uid NOT IN (%d, 0) |
|
|
GROUP BY u.uid, u.name |
|
|
ORDER BY total_count DESC |
|
|
LIMIT 10"; |
|
| 416 |
$result_users = db_query("SELECT DISTINCT u.uid, u.name, SUM(i.counter) AS total_count |
$result_users = db_query("SELECT DISTINCT u.uid, u.name, SUM(i.counter) AS total_count |
| 417 |
FROM {interests} i, {users} u |
FROM {interests} i, {users} u |
| 418 |
WHERE u.uid = i.uid |
WHERE u.uid = i.uid |
| 439 |
} |
} |
| 440 |
} |
} |
| 441 |
|
|
| 442 |
if (!empty($table_rows)) { |
if (!empty($table_rows)) { |
| 443 |
$output .= "<h3>Users with similar interests</h3>"; |
// Use h3 if having a titles list to match theme_item_list heading |
| 444 |
|
// and h1 if having teasers to fit better with the node title headings |
| 445 |
|
$output .= $teaser ? t("<h1>Users with similar interests</h1>") : t("<h3>Users with similar interests</h3>"); |
| 446 |
if ($blog_enabled) { |
if ($blog_enabled) { |
| 447 |
$output .= theme('table', array('Username', 'Blog', 'Profile'), $table_rows); |
$output .= theme('table', array('Username', 'Blog', 'Profile'), $table_rows); |
| 448 |
} |
} |
| 452 |
} |
} |
| 453 |
} |
} |
| 454 |
else { |
else { |
| 455 |
$output .= "<p>You haven't specified any interests yet.</p>"; |
$output .= t("<p>You haven't specified any interests yet.</p>"); |
| 456 |
} |
} |
| 457 |
|
|
| 458 |
// Do the selection of nodes where tags match |
// Do the selection of nodes where tags match |
| 459 |
$types = db_query("SELECT nt.type, nt.name FROM {node_type} nt"); |
// Use settings for which node types to display, teaser and limit |
| 460 |
while ($type = db_fetch_array($types)) { |
foreach ($node_types as $type => $type_name) { |
| 461 |
$nodes = db_query("SELECT n.nid, n.title, SUM(i.counter) AS total_count |
if ($allowed_types[$type]) { |
| 462 |
FROM {interests} i, {term_node} tn, {node} n |
$nodes = db_query("SELECT n.nid, n.title, SUM(i.counter) AS total_count |
| 463 |
WHERE n.nid = tn.nid |
FROM {interests} i, {term_node} tn, {node} n |
| 464 |
AND i.tid = tn.tid |
WHERE n.nid = tn.nid |
| 465 |
AND i.uid = %d |
AND i.tid = tn.tid |
| 466 |
AND n.type = '%s' |
AND i.uid = %d |
| 467 |
GROUP BY n.nid, n.title |
AND n.type = '%s' |
| 468 |
ORDER BY total_count DESC, n.changed DESC |
GROUP BY n.nid, n.title |
| 469 |
LIMIT 5", $user->uid, $type['type']); |
ORDER BY total_count DESC, n.changed DESC |
| 470 |
|
LIMIT %d", $user->uid, $type, $limit); |
| 471 |
$list = array(); |
|
| 472 |
while ($node = db_fetch_array($nodes)) { |
$list = array(); |
| 473 |
$list[] = l($node['title'], 'node/' . $node['nid']); |
$teasers = ''; |
| 474 |
} |
while ($node = db_fetch_array($nodes)) { |
| 475 |
if (!empty($list)) { |
if ($teaser) { |
| 476 |
$output .= theme('item_list', $list, t($type['name']), 'ul'); |
$teasers .= node_view(node_load($node['nid']), 1); |
| 477 |
} |
} |
| 478 |
|
else { |
| 479 |
|
$list[] = l($node['title'], 'node/' . $node['nid']); |
| 480 |
|
} |
| 481 |
|
} |
| 482 |
|
if ($teasers != '') { |
| 483 |
|
$output .= t('<br /><h1>' . $type_name . '\'s of interest</h1><br />'); |
| 484 |
|
$output .= $teasers; |
| 485 |
|
} |
| 486 |
|
if (!empty($list)) { |
| 487 |
|
$output .= theme('item_list', $list, t($type_name . "'s of interest"), 'ul'); |
| 488 |
|
} |
| 489 |
|
} |
| 490 |
} |
} |
| 491 |
|
|
| 492 |
return $output; |
return $output; |