| 1 |
<?php |
<?php |
| 2 |
|
|
| 3 |
/** |
/** |
| 4 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 5 |
*/ |
*/ |
| 6 |
function interests_menu($may_cache) { |
function interests_menu($may_cache) { |
| 7 |
global $user; |
global $user; |
| 8 |
|
|
| 9 |
$items = array(); |
$items = array(); |
| 10 |
|
|
| 14 |
'callback' => 'interests_browse', |
'callback' => 'interests_browse', |
| 15 |
'access' => user_access('access interests'), |
'access' => user_access('access interests'), |
| 16 |
'type' => MENU_NORMAL_ITEM); |
'type' => MENU_NORMAL_ITEM); |
| 17 |
$items[] = array('path' => 'interests/add', |
$items[] = array('path' => 'interests/add', |
| 18 |
'title' => t('Add Interest'), |
'title' => t('Add Interest'), |
| 19 |
'callback' => 'interests_add_node', |
'callback' => 'interests_add_node', |
| 20 |
'access' => user_access('access interests'), |
'access' => user_access('access interests'), |
| 21 |
'type' => MENU_CALLBACK); |
'type' => MENU_CALLBACK); |
| 22 |
$items[] = array('path' => 'interests/edit', |
$items[] = array('path' => 'interests/edit', |
| 23 |
'title' => t('Change My Interests'), |
'title' => t('Change My Interests'), |
| 24 |
'callback' => 'drupal_get_form', |
'callback' => 'drupal_get_form', |
| 25 |
'callback arguments' => array('interests_interests_form'), |
'callback arguments' => array('interests_interests_form'), |
| 26 |
'access' => user_access('access interests'), |
'access' => user_access('access interests'), |
| 27 |
'type' => MENU_CALLBACK); |
'type' => MENU_CALLBACK); |
| 28 |
$items[] = array('path' => 'admin/user/interests', |
$items[] = array('path' => 'admin/user/interests', |
| 29 |
'title' => t('Interests'), |
'title' => t('Interests'), |
| 30 |
'description' => t('Interets per user.'), |
'description' => t('Interests per user.'), |
| 31 |
'access' => user_access('admin interests'), |
'access' => user_access('admin interests'), |
| 32 |
'callback' => 'interests_user_overview', |
'callback' => 'interests_user_overview', |
| 33 |
'callback arguments' => array(arg(1))); |
'callback arguments' => array(arg(1))); |
| 34 |
$items[] = array('path' => 'admin/content/interests', |
$items[] = array('path' => 'admin/content/interests', |
| 35 |
'title' => t('Interests'), |
'title' => t('Interests'), |
| 36 |
'description' => t('Set which vocabularies can be interests.'), |
'description' => t('Set which vocabularies can be interests.'), |
| 37 |
'access' => user_access('admin interests'), |
'access' => user_access('admin interests'), |
| 38 |
'callback' => 'drupal_get_form', |
'callback' => 'drupal_get_form', |
| 39 |
'callback arguments' => 'interests_vocabs_form', |
'callback arguments' => 'interests_vocabs_form', |
| 40 |
); |
); |
| 41 |
$items[] = array('path' => 'admin/user/interests/add', |
$items[] = array('path' => 'admin/user/interests/add', |
| 42 |
'title' => t('Add Interests to user'), |
'title' => t('Add Interests to user'), |
| 43 |
'callback' => 'drupal_get_form', |
'callback' => 'drupal_get_form', |
| 44 |
'callback arguments' => array('interests_interests_form'), |
'callback arguments' => array('interests_interests_form'), |
| 45 |
'access' => user_access('admin interests'), |
'access' => user_access('admin interests'), |
| 46 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 47 |
); |
); |
| 48 |
$items[] = array('path' => 'admin/user/interests/edit', |
$items[] = array('path' => 'admin/user/interests/edit', |
| 49 |
'title' => t('Edit Interests'), |
'title' => t('Edit Interests'), |
| 50 |
'callback' => 'drupal_get_form', |
'callback' => 'drupal_get_form', |
| 58 |
'access' => user_access('admin interests'), |
'access' => user_access('admin interests'), |
| 59 |
'type' => MENU_CALLBACK); |
'type' => MENU_CALLBACK); |
| 60 |
} |
} |
| 61 |
elseif (!$may_cache){ |
elseif (!$may_cache){ |
| 62 |
if (isset($user->uid) && arg(0) == 'node' && is_numeric(arg(1))){ |
if (isset($user->uid) && arg(0) == 'node' && is_numeric(arg(1))){ |
| 63 |
$terms = taxonomy_node_get_terms(arg(1)); |
$terms = taxonomy_node_get_terms(arg(1)); |
| 64 |
if ($terms){ |
if ($terms){ |
| 65 |
foreach ($terms as $term){ |
foreach ($terms as $term){ |
| 66 |
_interests_dynamic_add($term->tid); |
_interests_dynamic_add($term->tid); |
| 67 |
} |
} |
| 68 |
} |
} |
| 69 |
} |
} |
| 70 |
} |
} |
| 71 |
|
|
| 72 |
return $items; |
return $items; |
| 73 |
} |
} |
| 74 |
|
|
| 76 |
* Implementation of hook_perm(). |
* Implementation of hook_perm(). |
| 77 |
*/ |
*/ |
| 78 |
function interests_perm() { |
function interests_perm() { |
| 79 |
return array('access interests', 'edit interests', 'administer interests'); |
return array('access interests', 'edit interests', 'administer interests'); |
| 80 |
} |
} |
| 81 |
|
|
| 82 |
function interests_link($type, $node = NULL, $teaser = FALSE){ |
function interests_link($type, $node = NULL, $teaser = FALSE){ |
| 83 |
$links = array(); |
$links = array(); |
| 84 |
|
|
| 85 |
if ($type == 'node'){ |
if ($type == 'node'){ |
| 86 |
if (!$teaser){ |
if (!$teaser){ |
| 87 |
if (user_access('access interests')){ |
if (user_access('access interests')){ |
| 88 |
$links['interests_add_interests'] = array( |
$links['interests_add_interests'] = array( |
| 89 |
'title' => t('set as interest'), |
'title' => t('set as interest'), |
| 90 |
'href' => 'interests/add/'.$node->nid, |
'href' => 'interests/add/'.$node->nid, |
| 91 |
); |
); |
| 92 |
} |
} |
| 93 |
} |
} |
| 94 |
} |
} |
| 95 |
return $links; |
return $links; |
| 96 |
} |
} |
| 97 |
|
|
| 98 |
function interests_interests_form($arg = NULL) { |
function interests_interests_form($arg = NULL) { |
| 99 |
global $user; |
global $user; |
| 100 |
|
|
| 101 |
$output = l(t('Back to user list'), 'admin/user/interests'); |
$output = l(t('Back to user list'), 'admin/user/interests'); |
| 102 |
|
|
| 103 |
if (is_numeric(arg(4))){ |
if (is_numeric(arg(4))){ |
| 104 |
$default_values = _interests_tid_user_list(arg(4)); |
$default_values = _interests_tid_user_list(arg(4)); |
| 105 |
$uid = arg(4); |
$uid = arg(4); |
| 106 |
$result = db_query("SELECT uid, name from {users} WHERE uid = '%s'", arg(4)); |
$result = db_query("SELECT uid, name from {users} WHERE uid = '%s'", arg(4)); |
| 107 |
while ($row = db_fetch_object($result)){ |
while ($row = db_fetch_object($result)){ |
| 108 |
$uname = $row->name; |
$uname = $row->name; |
| 109 |
} |
} |
| 110 |
} |
} |
| 111 |
else{ |
else{ |
| 112 |
$default_values = _interests_tid_user_list($user->uid); |
$default_values = _interests_tid_user_list($user->uid); |
| 113 |
$uid = $user->uid; |
$uid = $user->uid; |
| 114 |
$uname = $user->name; |
$uname = $user->name; |
| 115 |
} |
} |
| 116 |
|
|
| 117 |
$vocabs = _interests_get_vocabs(); |
$vocabs = _interests_get_vocabs(); |
| 118 |
|
|
| 119 |
if (!empty($vocabs)){ |
if (!empty($vocabs)){ |
| 120 |
foreach ($vocabs AS $i => $voc){ |
|
| 121 |
$termlist[$voc->name] = _interests_tid_list($vocabs); |
foreach ($vocabs AS $i => $voc){ |
| 122 |
} |
$vocabObj = taxonomy_get_vocabulary($voc); |
| 123 |
$form['interest_terms'] = array( |
//Generate a taxonomy term hiearchy selector |
| 124 |
'#type' => 'select', |
$tree = taxonomy_get_tree($voc); |
| 125 |
'#title' => t('Interests for '.$uname), |
if ($tree) { |
| 126 |
'#multiple' => TRUE, |
foreach ($tree as $term) { |
| 127 |
'#default_value' => $default_values, |
$choice = new stdClass(); |
| 128 |
'#options' => $termlist |
$choice->option = array($term->tid => str_repeat('-', $term->depth) . $term->name); |
| 129 |
); |
$termlist[$vocabObj->name][] = $choice; |
| 130 |
$form['uid'] = array( |
} |
| 131 |
'#type' => 'hidden', |
} |
| 132 |
'#value' => $uid |
} |
| 133 |
); |
|
| 134 |
$form['submit'] = array( |
$form['interest_terms'] = array( |
| 135 |
'#type' => 'submit', |
'#type' => 'select', |
| 136 |
'#value' => 'Change' |
'#title' => t('Interests for '.$uname), |
| 137 |
); |
'#multiple' => TRUE, |
| 138 |
} |
'#default_value' => $default_values, |
| 139 |
else{ |
'#options' => $termlist, |
| 140 |
$form['novocabs'] = array( |
); |
| 141 |
'#value' => t('No vocabularies have been setup yet.'), |
$form['uid'] = array( |
| 142 |
); |
'#type' => 'hidden', |
| 143 |
} |
'#value' => $uid |
| 144 |
return $form; |
); |
| 145 |
|
$form['submit'] = array( |
| 146 |
|
'#type' => 'submit', |
| 147 |
|
'#value' => 'Change' |
| 148 |
|
); |
| 149 |
|
|
| 150 |
|
} else{ |
| 151 |
|
$form['novocabs'] = array( |
| 152 |
|
'#value' => t('No vocabularies have been assigned as a Interest vocabulary.'), |
| 153 |
|
); |
| 154 |
|
} |
| 155 |
|
return $form; |
| 156 |
} |
} |
| 157 |
|
|
| 158 |
function interests_interests_form_submit($form_id, $form_values){ |
function interests_interests_form_submit($form_id, $form_values){ |
| 159 |
$currentResult = db_query("SELECT * FROM {interests} WHERE uid = '%s'", $form_values['uid']); |
$currentResult = db_query("SELECT * FROM {interests} WHERE uid = '%s'", $form_values['uid']); |
| 160 |
while ($currentRow = db_fetch_array($currentResult)){ |
while ($currentRow = db_fetch_array($currentResult)){ |
| 161 |
$currentList[] = array('tid' => $currentRow['tid'], 'uid' => $currentRow['uid']); |
$currentList[] = array('tid' => $currentRow['tid'], 'uid' => $currentRow['uid']); |
| 162 |
} |
} |
|
|
|
|
if ($currentList){ |
|
|
foreach ($currentList as $i => $currentTerm){ |
|
|
if (array_key_exists($currentTerm['tid'], $form_values['interest_terms'])){ |
|
|
unset($form_values['interest_terms'][$currentTerm['tid']]); |
|
|
unset($currentList[$i]); |
|
|
} |
|
|
} |
|
|
} |
|
|
foreach ($form_values['interest_terms'] as $tid){ |
|
|
$insertResult = db_query("INSERT INTO {interests} values ('%s', '%s', '1')", $form_values['uid'], $tid); |
|
|
} |
|
|
if ($currentList){ |
|
|
foreach ($currentList AS $current){ |
|
|
$deleteResult = db_query("DELETE FROM {interests} WHERE uid ='%s' AND tid='%s'", $form_values['uid'], $current['tid']); |
|
|
} |
|
|
} |
|
| 163 |
|
|
| 164 |
return 'interests'; |
if ($currentList){ |
| 165 |
|
foreach ($currentList as $i => $currentTerm){ |
| 166 |
|
if (array_key_exists($currentTerm['tid'], $form_values['interest_terms'])){ |
| 167 |
|
unset($form_values['interest_terms'][$currentTerm['tid']]); |
| 168 |
|
unset($currentList[$i]); |
| 169 |
|
} |
| 170 |
|
} |
| 171 |
|
} |
| 172 |
|
foreach ($form_values['interest_terms'] as $tid){ |
| 173 |
|
$insertResult = db_query("INSERT INTO {interests} values ('%s', '%s', '1')", $form_values['uid'], $tid); |
| 174 |
|
} |
| 175 |
|
if ($currentList){ |
| 176 |
|
foreach ($currentList AS $current){ |
| 177 |
|
$deleteResult = db_query("DELETE FROM {interests} WHERE uid ='%s' AND tid='%s'", $form_values['uid'], $current['tid']); |
| 178 |
|
} |
| 179 |
|
} |
| 180 |
|
|
| 181 |
|
drupal_set_message('Interests updated'); |
| 182 |
|
|
| 183 |
|
return 'interests'; |
| 184 |
} |
} |
| 185 |
|
|
| 186 |
function interests_user_overview(){ |
function interests_user_overview(){ |
| 187 |
|
|
| 188 |
$result = db_query('SELECT DISTINCT u.uid, u.name FROM {users} u WHERE u.uid != 0 ORDER BY u.name asc'); |
$result = db_query('SELECT DISTINCT u.uid, u.name FROM {users} u WHERE u.uid != 0 ORDER BY u.name asc'); |
| 189 |
while ($row = db_fetch_object($result)){ |
while ($row = db_fetch_object($result)){ |
| 190 |
$tableRow[] = array($row->name, l('Edit Interests', 'admin/user/interests/add/'.$row->uid)); |
$tableRow[] = array($row->name, l('Edit Interests', 'admin/user/interests/add/'.$row->uid)); |
| 191 |
} |
} |
| 192 |
$output = theme('table', array('Username', 'Edit'), $tableRow); |
$output = theme('table', array('Username', 'Edit'), $tableRow); |
| 193 |
|
|
| 194 |
return $output; |
return $output; |
| 195 |
} |
} |
| 196 |
|
|
| 197 |
function _interests_get_vocabs(){ |
function _interests_get_vocabs(){ |
| 198 |
static $return = array(); |
$result = db_query("SELECT * FROM {interests_vocabs}"); |
| 199 |
|
while ($row = db_fetch_object($result)){ |
| 200 |
$result = db_query("SELECT * FROM {interests_vocabs}"); |
$return[$row->vid] = $row->vid; |
| 201 |
while ($row = db_fetch_object($result)){ |
} |
| 202 |
$return[$row->vid] = $row->vid; |
return $return; |
|
} |
|
|
return $return; |
|
| 203 |
} |
} |
| 204 |
|
|
| 205 |
function interests_vocabs_form(){ |
function interests_vocabs_form(){ |
| 206 |
|
//TODO: This should be listed on the Taxonomy Vocabulary Form and not separately |
| 207 |
|
|
| 208 |
$vocabs = taxonomy_get_vocabularies(); |
$vocabs = taxonomy_get_vocabularies(); |
| 209 |
if (!empty($vocabs)){ |
if (!empty($vocabs)){ |
|
|
|
|
foreach ($vocabs AS $vocab){ |
|
|
$options[$vocab->vid] = $vocab->name; |
|
|
} |
|
|
$default_options = _interests_get_vocabs(); |
|
|
|
|
|
$form['vocabularies'] = array( |
|
|
'#type' => 'select', |
|
|
'#options' => $options, |
|
|
'#title' => t('Vocabularies'), |
|
|
'#default_value' => $default_options, |
|
|
'#multiple' => true, |
|
|
); |
|
|
$form['submit'] = array( |
|
|
'#type' => 'submit', |
|
|
'#value' => 'Submit', |
|
|
); |
|
|
} |
|
|
else{ |
|
|
$form['novocabs'] = array( |
|
|
'#value' => t('There are no taxonomy vocabularies yet.'), |
|
|
); |
|
|
} |
|
| 210 |
|
|
| 211 |
return $form; |
foreach ($vocabs AS $vocab){ |
| 212 |
|
$options[$vocab->vid] = $vocab->name; |
| 213 |
|
} |
| 214 |
|
$default_options = _interests_get_vocabs(); |
| 215 |
|
|
| 216 |
|
$form['vocabularies'] = array( |
| 217 |
|
'#type' => 'select', |
| 218 |
|
'#options' => $options, |
| 219 |
|
'#title' => t('Vocabularies'), |
| 220 |
|
'#default_value' => $default_options, |
| 221 |
|
'#multiple' => true, |
| 222 |
|
); |
| 223 |
|
$form['submit'] = array( |
| 224 |
|
'#type' => 'submit', |
| 225 |
|
'#value' => 'Submit', |
| 226 |
|
); |
| 227 |
|
} |
| 228 |
|
else{ |
| 229 |
|
$form['novocabs'] = array( |
| 230 |
|
'#value' => t('There are no taxonomy vocabularies yet.'), |
| 231 |
|
); |
| 232 |
|
} |
| 233 |
|
|
| 234 |
|
return $form; |
| 235 |
} |
} |
| 236 |
|
|
| 237 |
function interests_vocabs_form_submit($form_id, &$form_values){ |
function interests_vocabs_form_submit($form_id, &$form_values){ |
| 238 |
|
|
| 239 |
$currentVocabs = _interests_get_vocabs(); |
$currentVocabs = _interests_get_vocabs(); |
| 240 |
|
|
| 241 |
foreach ($form_values['vocabularies'] AS $i => $vocab){ |
foreach ($form_values['vocabularies'] AS $i => $vocab){ |
| 242 |
if (!isset($currentVocabs[$i])){ |
if (!isset($currentVocabs[$i])){ |
| 243 |
db_query("INSERT INTO {interests_vocabs} VALUES (%s)", $vocab); |
db_query("INSERT INTO {interests_vocabs} VALUES (%s)", $vocab); |
| 244 |
unset($currentVocabs[$i]); |
unset($currentVocabs[$i]); |
| 245 |
} |
} |
| 246 |
else{ |
else{ |
| 247 |
unset($currentVocabs[$i]); |
unset($currentVocabs[$i]); |
| 248 |
} |
} |
| 249 |
} |
} |
| 250 |
if (!empty($currentVocabs)){ |
if (!empty($currentVocabs)){ |
| 251 |
foreach ($currentVocabs AS $x => $delVocab){ |
foreach ($currentVocabs AS $x => $delVocab){ |
| 252 |
db_query("DELETE FROM {interests_vocabs} WHERE vid = '%s'", $delVocab); |
db_query("DELETE FROM {interests_vocabs} WHERE vid = '%s'", $delVocab); |
| 253 |
} |
} |
| 254 |
} |
} |
| 255 |
} |
} |
| 256 |
|
|
| 257 |
function interests_add_node(){ |
function interests_add_node(){ |
| 258 |
$nid = arg(2); |
$nid = arg(2); |
| 259 |
|
$terms = taxonomy_node_get_terms($nid); |
|
$terms = taxonomy_node_get_terms($nid); |
|
| 260 |
if ($terms){ |
if ($terms){ |
| 261 |
foreach ($terms as $term){ |
foreach ($terms as $term){ |
| 262 |
_interests_dynamic_add($term->tid); |
_interests_dynamic_add($term->tid); |
| 263 |
} |
} |
| 264 |
} |
} |
| 265 |
|
|
| 266 |
drupal_goto('node/'.$nid); |
drupal_goto('node/'.$nid); |
| 267 |
} |
} |
| 268 |
|
|
| 269 |
function _interests_dynamic_add($tid){ |
function _interests_dynamic_add($tid){ |
| 270 |
global $user; |
global $user; |
| 271 |
$result = db_query("SELECT * FROM {interests} WHERE uid = '%s' AND tid = '%s'", $user->uid, $tid); |
$result = db_query("SELECT * FROM {interests} WHERE uid = '%s' AND tid = '%s'", $user->uid, $tid); |
| 272 |
if (db_num_rows($result) != 0){ |
if (db_num_rows($result) != 0){ |
| 273 |
while ($row = db_fetch_array($result)){ |
while ($row = db_fetch_array($result)){ |
| 274 |
$counter = $row['counter'] + 1; |
$counter = $row['counter'] + 1; |
| 275 |
db_query("UPDATE {interests} SET counter = '%s' WHERE uid = '%s' AND tid = '%s'", $counter, $user->uid, $tid); |
db_query("UPDATE {interests} SET counter = '%s' WHERE uid = '%s' AND tid = '%s'", $counter, $user->uid, $tid); |
| 276 |
} |
} |
| 277 |
} |
} |
| 278 |
else{ |
else{ |
| 279 |
db_query("INSERT INTO {interests} VALUES ('%s', '%s', 0)", $user->uid, $tid); |
db_query("INSERT INTO {interests} VALUES ('%s', '%s', 0)", $user->uid, $tid); |
| 280 |
} |
} |
| 281 |
|
|
| 282 |
} |
} |
| 283 |
|
|
| 284 |
function _interests_tid_user_list($uid = NULL){ |
function _interests_tid_user_list($uid = NULL){ |
| 285 |
$result = db_query("SELECT tid FROM {interests} WHERE uid='%s'", $uid); |
$result = db_query("SELECT tid FROM {interests} WHERE uid='%s'", $uid); |
| 286 |
while ($row = db_fetch_array($result)){ |
while ($row = db_fetch_array($result)){ |
| 287 |
$rows[] = $row['tid']; |
$rows[] = $row['tid']; |
| 288 |
} |
} |
| 289 |
return $rows; |
return $rows; |
|
} |
|
|
|
|
|
function _interests_tid_list($vocabularies) { |
|
|
|
|
|
$tids = array(); |
|
|
foreach ($vocabularies as $vocab){ |
|
|
$result = db_query("SELECT DISTINCT(td.tid), td.name, td.weight, v.name as vocabname, v.weight FROM {term_data} td LEFT JOIN {vocabulary} v ON v.vid = td.vid WHERE td.vid = '%s' ORDER BY v.weight, v.name, td.weight, td.name", $vocab); |
|
|
while ($obj = db_fetch_object($result)) { |
|
|
$tids[$obj->tid] = $obj->vocabname.": ".$obj->name; |
|
|
} |
|
|
} |
|
|
return $tids; |
|
| 290 |
} |
} |
| 291 |
|
|
| 292 |
function interests_browse() { |
function interests_browse() { |
| 293 |
global $user; |
global $user; |
| 294 |
|
|
| 295 |
$output = l(t('Change My Interests'), 'interests/edit'); |
$output = l(t('Change My Interests'), 'interests/edit'); |
| 296 |
|
|
| 297 |
//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 |
| 298 |
|
|
| 299 |
|
$myTags = db_query("SELECT i.tid FROM {interests} i WHERE i.uid = '%s'", $user->uid); |
| 300 |
$myTags = db_query("SELECT i.tid FROM {interests} i WHERE i.uid = '%s'", $user->uid); |
if (db_num_rows($myTags) >= 1){ |
| 301 |
if (db_num_rows($myTags) >= 1){ |
while ($row = db_fetch_array($myTags)){ |
| 302 |
while ($row = db_fetch_array($myTags)){ |
$like .= "i.tid = '".$row['tid']."' OR "; |
| 303 |
$like .= "i.tid = '".$row['tid']."' OR "; |
} |
| 304 |
} |
if (isset($like)) { |
| 305 |
$like = rtrim($like, ' OR '); |
$like = rtrim($like, ' OR '); |
| 306 |
if (isset($like)) { |
$resultUsers = db_query("SELECT i.uid, i.tid, u.name, t.name AS tname FROM {interests} i, {users} u, {term_data} t WHERE ($like) AND i.uid != '%s' AND i.uid != '0' AND u.uid = i.uid AND i.tid = t.tid GROUP BY i.uid ORDER BY i.counter desc LIMIT 10", $user->uid); |
| 307 |
$resultUsers = db_query("SELECT i.uid, i.tid, u.name, t.name AS tname FROM {interests} i, {users} u, {term_data} t WHERE ($like) AND i.uid != '%s' AND i.uid != '0' AND u.uid = i.uid AND i.tid = t.tid GROUP BY i.uid ORDER BY i.counter desc LIMIT 10", $user->uid); |
if (db_num_rows($resultUsers) >=1){ |
| 308 |
if (db_num_rows($resultUsers) >=1){ |
$output .= "<h2>".t('Users with similar interests')."</h2>"; |
| 309 |
$output .= "<h2>".t('Users with similar interests')."</h2>"; |
if (module_exists('blog')) $blogEnabled=true; |
| 310 |
while ($row = db_fetch_array($resultUsers)){ |
while ($row = db_fetch_array($resultUsers)){ |
| 311 |
$tableRow[] = array('username' => $row['name'], |
if ($blogEnabled) { |
| 312 |
'blog' => l(t('View Blog'), 'blog/'.$row['uid']), |
$tableRow[] = array('username' => $row['name'], |
| 313 |
'profile' => l(t('View Profile'), 'user/'.$row['uid'])); |
'blog' => l(t('View Blog'), 'blog/'.$row['uid']), |
| 314 |
} |
'profile' => l(t('View Profile'), 'user/'.$row['uid'])); |
| 315 |
$output .= theme('table', array('Username', 'Blog', 'Profile'), $tableRow); |
} else { |
| 316 |
} |
$tableRow[] = array('username' => $row['name'], |
| 317 |
} |
'profile' => l(t('View Profile'), 'user/'.$row['uid'])); |
| 318 |
else{ |
} |
| 319 |
$output .= "<p>".t("You haven't specified any interests yet.")."</p>n"; |
} |
| 320 |
} |
if ($blogEnabled) { |
| 321 |
|
$output .= theme('table', array('Username', 'Blog', 'Profile'), $tableRow); |
| 322 |
//Do the selection of nodes where tags match |
} else { |
| 323 |
$resultTypes = db_query("SELECT nt.type, nt.name FROM {node_type} nt"); |
$output .= theme('table', array('Username', 'Profile'), $tableRow); |
| 324 |
while ($row = db_fetch_array($resultTypes)){ |
} |
| 325 |
$result = db_query("SELECT i.counter, t.tid, t.name, n.nid, n.title FROM {interests} i, {term_data} t, {term_node} tn, {node} n WHERE n.nid = tn.nid AND tn.tid = t.tid AND i.tid = t.tid AND i.uid = '%s' AND n.type = '%s' GROUP BY n.nid ORDER BY i.counter desc, n.changed desc LIMIT 5", $user->uid, $row['type']); |
} |
| 326 |
if (db_num_rows($result)){ |
} |
| 327 |
$sectionTitle = $row['name']; |
else{ |
| 328 |
$output .= "<h2>$sectionTitle</h2>"; |
$output .= "<p>".t("You haven't specified any interests yet.")."</p>"; |
| 329 |
$output .= "<ul>"; |
} |
| 330 |
|
//Do the selection of nodes where tags match |
| 331 |
while ($rowNodes = db_fetch_array($result)){ |
$resultTypes = db_query("SELECT nt.type, nt.name FROM {node_type} nt"); |
| 332 |
$output .= "<li>".l($rowNodes['title'], 'node/'.$rowNodes['nid'])."</li>"; |
while ($row = db_fetch_array($resultTypes)){ |
| 333 |
} |
$result = db_query("SELECT i.counter, t.tid, t.name, n.nid, n.title FROM {interests} i, {term_data} t, {term_node} tn, {node} n WHERE n.nid = tn.nid AND tn.tid = t.tid AND i.tid = t.tid AND i.uid = '%s' AND n.type = '%s' GROUP BY n.nid ORDER BY i.counter desc, n.changed desc LIMIT 5", $user->uid, $row['type']); |
| 334 |
|
if (db_num_rows($result)){ |
| 335 |
$output .= "</ul>"; |
$sectionTitle = $row['name']; |
| 336 |
} |
$output .= "<h2>$sectionTitle</h2>"; |
| 337 |
} |
$output .= "<ul>"; |
| 338 |
} |
|
| 339 |
else{ |
while ($rowNodes = db_fetch_array($result)){ |
| 340 |
$output .= t("<br />You haven't specified any interests yet."); |
$output .= "<li>".l($rowNodes['title'], 'node/'.$rowNodes['nid'])."</li>"; |
| 341 |
} |
} |
| 342 |
return $output; |
$output .= "</ul>"; |
| 343 |
|
} |
| 344 |
|
} |
| 345 |
|
} |
| 346 |
|
else{ |
| 347 |
|
$output .= t("<br/>You haven't specified any interests yet."); |
| 348 |
|
} |
| 349 |
|
return $output; |
| 350 |
} |
} |
| 351 |
|
|
| 352 |
function _interests_user_suggestions(){ |
function _interests_user_suggestions(){ |
| 353 |
global $user; |
global $user; |
| 354 |
|
|
| 355 |
if ($user->uid == 0){ |
if ($user->uid == 0){ |
| 356 |
$output = t("This site uses interest tagging for authenticated users"); |
$output = t("This site uses interest tagging for authenticated users"); |
| 357 |
} |
} |
| 358 |
else{ |
else{ |
| 359 |
$result = db_query("SELECT i.counter AS count, t.tid, t.name, t.vid, t.weight FROM {interests} i, {term_data} t WHERE t.tid = i.tid AND i.uid = '%s' ORDER BY t.name DESC", $user->uid); |
$result = db_query("SELECT i.counter AS count, t.tid, t.name, t.vid, t.weight FROM {interests} i, {term_data} t WHERE t.tid = i.tid AND i.uid = '%s' ORDER BY t.name DESC", $user->uid); |
| 360 |
$tags = tagadelic_build_weighted_tags($result, $steps = 6); |
$tags = tagadelic_build_weighted_tags($result, $steps = 6); |
| 361 |
$output = theme('tagadelic_weighted', $tags); |
$output = theme('tagadelic_weighted', $tags); |
| 362 |
} |
} |
| 363 |
return $output; |
return $output; |
| 364 |
} |
} |
| 365 |
|
|
| 366 |
/** |
/** |
| 367 |
* Implementation of hook_block(). |
* Implementation of hook_block(). |
| 368 |
*/ |
*/ |
| 371 |
case 'list': |
case 'list': |
| 372 |
$blocks[0]['info'] = t('Suggested Tags'); |
$blocks[0]['info'] = t('Suggested Tags'); |
| 373 |
return $blocks; |
return $blocks; |
| 374 |
case 'configure': |
case 'configure': |
| 375 |
$form = array(); |
$form = array(); |
| 376 |
return $form; |
return $form; |
| 377 |
case 'view': default: |
case 'view': default: |
| 378 |
switch ($delta) { |
switch ($delta) { |
| 379 |
case 0: |
case 0: |
| 381 |
} |
} |
| 382 |
} |
} |
| 383 |
} |
} |
|
|
|
|
?> |
|