t('web links'), 'description' => t('Weblinks: All nodes for a specific weblink term'), 'include' => 'weblink', 'prefix' => t(''), 'suffix' => t('weblinks'), 'weight' => -3, 'form' => TRUE, 'label' => t('Add Weblink Content'), 'help' => t('You can track content by keyword category. Type a keyword in the search box to find the matching category, or choose one of the example links.'), 'search' => TRUE, 'threshold' => WEBLINK_THRESHOLD ); if ($get_options) { $type['options'] = mysite_type_weblink_options(); } return $type; } } /** * Set the options for this type */ function mysite_type_weblink_options() { $options = array(); $vocabularies = variable_get('mysite_weblink_vocabularies', NULL); if (is_array($vocabularies) && !empty($vocabularies)) { foreach ($vocabularies as $vid) { if ($vid > 0) { $v = taxonomy_get_vocabulary($vid); $terms[$v->name] = taxonomy_get_tree($v->vid); } } } if (is_array($terms) && !empty($terms)) { $i =0; foreach ($terms as $key => $value) { foreach($value as $term) { if ($i < WEBLINK_THRESHOLD) { $depth = str_repeat('-', $term->depth) . ' '; $options['group'][] = $key; $options['name'][] = $depth . $term->name; $options['type_id'][] = $term->tid; $options['type'][] = 'weblink'; $i++; } } } } return $options; } /** * Return the title if given an id */ function mysite_type_weblink_title($type_id = NULL, $title = NULL) { if(!empty($type_id)) { if(is_null($title)) { $term = taxonomy_get_term($type_id); $title = $term->name; } $type = mysite_type_weblink(); $title = $type['prefix'] . ' ' . $title . ' ' . $type['suffix']; $title = trim(rtrim($title)); return $title; } drupal_set_message(t('Could not find title'), 'error'); return; } /** * Return the page data for a requested id */ function mysite_type_weblink_data($type_id = NULL) { if(!empty($type_id)) { $order = variable_get('mysite_weblink_sort', NULL); if ($order == "click") { $order_sql = "ln.clicks"; } else { $order_sql = "n.changed"; } $sql = db_rewrite_sql("SELECT n.nid, n.changed FROM {node} n, {links_node} ln INNER JOIN {term_node} t ON n.nid = t.nid AND n.nid = ln.nid WHERE n.status = 1 AND n.type != 'forum' AND t.tid = %d ORDER BY {$order_sql} DESC"); $result = db_query_range($sql, $type_id, 0, variable_get('mysite_elements', 5)); $data = array( 'base' => 'links/weblink/' . $type_id, 'xml' => 'taxonomy/term/' . $type_id . '/0/feed' ); $items = array(); $i = 0; // we can't use node_view() here, because aggregator doesn't use nodes // and we need the same data structure for all content while ($nid = db_fetch_object($result)) { $node = node_load($nid->nid); // $link = links_load_links_for_node($nid->nid,"links_weblink"); $link = links_get_list("links_weblink", $node); $items[$i]['type'] = $node->type; //$items[$i]['link'] = l($node->title, 'node/' . $node->nid); $items[$i]['link'] = l($node->title, $link[0]['href'],$link[0]['attributes']); $items[$i]['title'] = check_plain($node->title); $items[$i]['subtitle'] = NULL; $items[$i]['date'] = $node->changed; $items[$i]['uid'] = $node->uid; $items[$i]['author'] = check_plain($node->name); $items[$i]['teaser'] = check_markup($node->teaser, $node->format); $items[$i]['nid'] = $node->nid; $i++; } $data['items'] = $items; return $data; } drupal_set_message(t('Could not find data'), 'error'); return; } /** * Return block settings for this type */ function mysite_type_weblink_block($arg, $op = 'view') { global $user; if (user_access('access content') && $arg[0] == 'taxonomy' && $arg[1] == 'weblink' && is_numeric($arg[2])) { $term = taxonomy_get_term($arg[2]); $data = array(); $data['uid'] = $user->uid; $data['type'] = 'weblink'; $data['type_id'] = $term->tid; $data['title'] = mysite_type_weblink_title($term->tid, $term->name); $content = mysite_block_handler($data); return $content; } } /** * Search options for this type */ function mysite_type_weblink_search($uid = NULL) { if (!is_null($uid)) { $output .= drupal_get_form('mysite_type_weblink_search_form', $uid); return $output; } } /** * FormsAPI for mysite_type_term_search */ function mysite_type_weblink_search_form($uid) { $form['add_weblink']['weblink_title'] = array('#type' => 'textfield', '#title' => t('Tag Name'), '#maxlength' => 64, '#description' => t('The tagged content you wish to add.'), '#required' => TRUE, '#autocomplete_path' => 'autocomplete/mysite/weblink' ); $form['add_weblink']['uid'] = array('#type' => 'hidden', '#value' => $uid); $form['add_weblink']['type'] = array('#type' => 'hidden', '#value' => 'weblink'); $form['add_weblink']['submit'] = array('#type' => 'submit', '#value' =>t('Add term')); return $form; } /** * Form handler for search */ function mysite_type_weblink_search_form_submit($form_id, $form_values) { // exclude vocabularies not allowed by the site settings $in = _mysite_type_weblink_in(); // we use LIKE here in case JavaScript autocomplete support doesn't work. // or in case the user doesn't autocomplete the form $sql = db_rewrite_sql("SELECT t.tid, t.name, t.description FROM {term_data} t WHERE t.name LIKE LOWER('%s%%') AND t.vid IN ($in)", 't', 'tid'); $result = db_query($sql, strtolower($form_values['weblink_title'])); $count = 0; while ($term = db_fetch_object($result)) { $data[$count]['uid'] = $form_values['uid']; $data[$count]['type'] = $form_values['type']; $data[$count]['type_id'] = $term->tid; $data[$count]['title'] = mysite_type_weblink_title($term->tid, $term->name); $data[$count]['description'] = $term->description; $count++; } // pass the $data to the universal handler mysite_search_handler($data, 'weblink'); return; } /** * AJAX autocomplete for term titles * The include files have no menu callbacks! */ function mysite_type_weblink_autocomplete($string) { $matches = array(); // exclude vocabularies not allowed by the site settings $in = _mysite_type_weblink_in(); $sql = db_rewrite_sql("SELECT t.tid, t.name, t.description FROM {term_data} t WHERE t.name LIKE LOWER('%s%%') AND t.vid IN ($in)", 't', 'tid'); $result = db_query_range($sql, $string, 0, 10); while ($term = db_fetch_object($result)) { $matches[$term->name] = check_plain($term->name); } return $matches; } /** * Helper function for searches */ function _mysite_type_weblink_in() { $in = NULL; $vocabularies = variable_get('mysite_weblink_vocabularies', NULL); if (is_array($vocabularies) && !empty($vocabularies)) { foreach ($vocabularies as $vid) { if ($vid > 0) { $in .= $vid . ', '; } } $in = rtrim($in, ', '); } return $in; } /** * Cron cleanup function */ function mysite_type_weblink_clear($type) { // fetch all the active records of this type and see if they really exist in the proper table $sql = "SELECT mid, uid, type_id, title FROM {mysite_data} WHERE type = '%s'"; $result = db_query($sql, $type); $data = array(); while ($item = db_fetch_array($result)) { $sql = "SELECT tid FROM {term_data} WHERE tid = %d"; $check = db_fetch_object(db_query($sql, $item['type_id'])); if(empty($check->tid)) { $data[$item['mid']] = $item; } } return $data; } /** * Settings for this type */ function mysite_type_weblink_settings() { $vocabularies = taxonomy_get_vocabularies(); // eliminate forums from the generic term view $forum = variable_get('forum_nav_vocabulary', 0); unset($vocabularies[$forum]); if (is_array($vocabularies) && !empty($vocabularies)) { return drupal_get_form('mysite_type_weblink_settings_form', $vocabularies); } else { return t('The taxonomy module is not active or there are no vocabularies. These features cannot be used.'); } } /** * FormsAPI for mysite_type_term_settings */ function mysite_type_weblink_settings_form($vocabularies) { foreach($vocabularies as $vocabulary) { $options[$vocabulary->vid] = $vocabulary->name; } $form['mysite_weblink']['mysite_weblink_vocabularies'] = array( '#type' => 'checkboxes', '#title' => t('Allowed Vocabularies'), '#default_value' => variable_get('mysite_weblink_vocabularies', NULL), '#options' => $options, '#required' => FALSE, '#description' => t('What is the vocabularie for weblinks to should be displayed to MySite users?') ); $options2 = array("change"=>t('last change'),"click"=>t('number of clicks')); $form['mysite_weblink']['mysite_weblink_sort'] = array( '#type' => 'radios', '#title' => t('Sorting'), '#default_value' => variable_get('mysite_weblink_sort', NULL), '#options' => $options2, '#required' => TRUE, '#description' => t('What is the sorting for weblinks to should be displayed to MySite users?') ); return system_settings_form($form); }