*** /usr/src/local/drupal/7/Modules/weblinks/weblinks.module	2011-02-25 03:07:04.000000000 +0100
--- weblinks.module	2013-01-07 23:58:42.000000000 +0100
***************
*** 40,55 ****
  }
  
  /**
!  * Implementation of hook_perm().
   */
! function weblinks_perm() {
    return module_invoke_all('weblinks_perm');
  }
  
  /**
!  * Implementation of hook_weblinks_perm().
   */
! function weblinks_weblinks_perm() {
    return array(
      'access web links',
      'create weblinks', 
--- 40,55 ----
  }
  
  /**
!  * Implementation of hook_permssion().
   */
! function weblinks_permission() {
    return module_invoke_all('weblinks_perm');
  }
  
  /**
!  * Implementation of hook_weblinks_permission().
   */
! function weblinks_weblinks_permission() {
    return array(
      'access web links',
      'create weblinks', 
***************
*** 73,79 ****
        'title_label' => t('Link Name'),
        'has_body' => TRUE,
        'body_label' => t('Link Description'),
!       'module' => 'weblinks',
      )
    );
  }
--- 73,79 ----
        'title_label' => t('Link Name'),
        'has_body' => TRUE,
        'body_label' => t('Link Description'),
!       'base' => 'weblinks',
      )
    );
  }
***************
*** 88,94 ****
    if (arg(0) == 'weblinks') {
      $active_trail = menu_set_active_trail();
      foreach ($active_trail as $key => $item) {
!       if ($item['path'] == 'weblinks') {
          $active_trail[$key]['title'] = _weblinks_get_menu_title();
        }
      }
--- 88,94 ----
    if (arg(0) == 'weblinks') {
      $active_trail = menu_set_active_trail();
      foreach ($active_trail as $key => $item) {
!       if ($item['link_path'] == 'weblinks') {
          $active_trail[$key]['title'] = _weblinks_get_menu_title();
        }
      }
***************
*** 101,107 ****
   * This is a helper function for hook_init and hook_view.
   */
  function _weblinks_get_menu_title() {
!   return t(db_result(db_query("SELECT link_title FROM {menu_links} WHERE link_path = 'weblinks'")));
  }
  
  /**
--- 101,107 ----
   * This is a helper function for hook_init and hook_view.
   */
  function _weblinks_get_menu_title() {
!   return t(db_query("SELECT link_title FROM {menu_links} WHERE link_path = 'weblinks'")->fetchField());
  }
  
  /**
***************
*** 109,115 ****
   * Validation of the url, if desired, is performed by the weblinks_checker module.
   */
  function weblinks_form(&$node) {
!   $type = node_get_types('type', $node);
  
    if ($type->has_title) {
      $form['title'] = array(
--- 109,115 ----
   * Validation of the url, if desired, is performed by the weblinks_checker module.
   */
  function weblinks_form(&$node) {
!   $type = node_type_get_type($node);
  
    if ($type->has_title) {
      $form['title'] = array(
***************
*** 122,131 ****
      );
    }
    if ($type->has_body) {
!     $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
      $form['body_field']['body']['#rows'] = 5;
      $form['body_field']['body']['#default_value'] = isset($node->body) ? $node->body : variable_get('weblinks_body_stub', '');
!     $form['body_field']['format'] = filter_form(isset($node->format) ? $node->format : variable_get('weblinks_format', FILTER_FORMAT_DEFAULT));
    }
  
    $form['url'] = array(
--- 122,131 ----
      );
    }
    if ($type->has_body) {
!     $form['body_field'] = field_view_field('node', $node, 'body');  // $type->min_word_count
      $form['body_field']['body']['#rows'] = 5;
      $form['body_field']['body']['#default_value'] = isset($node->body) ? $node->body : variable_get('weblinks_body_stub', '');
!     $form['body_field']['format'] = NULL; // isset($node->body['und'][0]['format']) ? $node->body['und'][0]['format'] : variable_get('weblinks_format', filter_fallback_format());
    }
  
    $form['url'] = array(
***************
*** 189,195 ****
    $vocid = variable_get('weblinks_nav_vocabulary', '');
    if (empty($vocid) && function_exists('taxonomy_vocabulary_load')) {
      // Check to see if a weblinks vocabulary exists
!     $vocid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE module='weblinks'"));
      if ($vocid) {
        // We found a vocabulary, so make sure it is associated with our content.
        $vocabulary = (array)taxonomy_vocabulary_load($vocid);
--- 189,195 ----
    $vocid = variable_get('weblinks_nav_vocabulary', '');
    if (empty($vocid) && function_exists('taxonomy_vocabulary_load')) {
      // Check to see if a weblinks vocabulary exists
!     $vocid = db_query("SELECT vid FROM {vocabulary} WHERE module='weblinks'")->fetchField();
      if ($vocid) {
        // We found a vocabulary, so make sure it is associated with our content.
        $vocabulary = (array)taxonomy_vocabulary_load($vocid);
***************
*** 309,319 ****
  /**
   * Implementation of hook_load().
   */
! function weblinks_load($node) {
!   $obj = db_fetch_object(db_query('SELECT urlhash, url, last_status, last_checked, click_count, last_click, reciprocal FROM {weblinks} WHERE nid = %d AND vid=%d', $node->nid, $node->vid));
    // This makes formatting easier.
!   $obj->none = NULL;
!   return $obj;
  }
  
  /**
--- 309,333 ----
  /**
   * Implementation of hook_load().
   */
! function weblinks_load($nodes) {
!   // note that $nodes is an array of object references, keyed by nid
!   $obj = db_select('weblinks', 'w')
!            ->condition('w.nid', array_keys($nodes), 'IN')
!            ->fields('w', array ('nid', 'urlhash', 'url', 'last_status', 'last_checked', 'click_count', 'last_click', 'reciprocal'))
!            ->execute();
!   // run through each result row and add in the needed attributes
!   foreach ($obj as $record) {
!     $nodes[$record->nid]->urlhash = $record->urlhash;
!     $nodes[$record->nid]->url = $record->url;
!     $nodes[$record->nid]->last_status = $record->last_status;
!     $nodes[$record->nid]->last_checked = $record->last_checked;
!     $nodes[$record->nid]->click_count = $record->click_count;
!     $nodes[$record->nid]->last_click = $record->last_click;
!     $nodes[$record->nid]->reciprocal = $record->reciprocal;
!   }
! 
    // This makes formatting easier.
!   // $obj->none = NULL;
  }
  
  /**
***************
*** 736,742 ****
      $skip_empty = FALSE;
    }
    $show_desc = variable_get('weblinks_catdesc', TRUE);
!   $format = variable_get('weblinks_format', FILTER_FORMAT_DEFAULT);
    $max_depth = $admin ? 99999999 : variable_get('weblinks_maxfrontdepth', 1);
  
    $tree = array();
--- 750,756 ----
      $skip_empty = FALSE;
    }
    $show_desc = variable_get('weblinks_catdesc', TRUE);
!   $format = variable_get('weblinks_format', filter_fallback_format());
    $max_depth = $admin ? 99999999 : variable_get('weblinks_maxfrontdepth', 1);
  
    $tree = array();
***************
*** 758,764 ****
    }
    else {
      // Top level, so do we have unclassified links?
!     $unclassed_count = db_result(_weblinks_get_query(0, 'count'));
      if ($admin || $unclassed_count > 0) {
        // Add our dummy unclassified term object to the list.
        $tree[] = _weblinks_unclassed();
--- 772,778 ----
    }
    else {
      // Top level, so do we have unclassified links?
!     $unclassed_count = db_query(_weblinks_get_query(0, 'count'))->fetchField();
      if ($admin || $unclassed_count > 0) {
        // Add our dummy unclassified term object to the list.
        $tree[] = _weblinks_unclassed();
***************
*** 767,773 ****
      // Do we want a separate unpublished group?
      if (variable_get('weblinks_unpublished_title', t('Unpublished'))) {
        // Do we have unpublished nodes?
!       $unpub_count = db_result(_weblinks_get_query('unpublished', 'count'));
        if ($admin && $unpub_count > 0) {
          $tree[] = _weblinks_unpublished();
        }
--- 781,787 ----
      // Do we want a separate unpublished group?
      if (variable_get('weblinks_unpublished_title', t('Unpublished'))) {
        // Do we have unpublished nodes?
!       $unpub_count = db_query(_weblinks_get_query('unpublished', 'count'))->fetchField();
        if ($admin && $unpub_count > 0) {
          $tree[] = _weblinks_unpublished();
        }
***************
*** 791,797 ****
          $term->node_count = $unpub_count;
        }
        else {
!         $term->node_count = taxonomy_term_count_nodes($tid, 'weblinks');
        }
      }
      if ($skip_empty && $term->node_count == 0) {
--- 805,811 ----
          $term->node_count = $unpub_count;
        }
        else {
!         $term->node_count =  db_query("SELECT COUNT(ti.nid) FROM {taxonomy_index} as ti INNER JOIN {node} as n on n.nid=ti.nid WHERE ti.tid = :aid and n.type='weblink'", array(':aid' => $tid) )->fetchField();
        }
      }
      if ($skip_empty && $term->node_count == 0) {
***************
*** 948,954 ****
      if (!$username) {
        $username = theme('username', $node);
      }
!     $output .= node_view($node, !($linkdesc == 'body')); 
    }
    drupal_set_title(t('Links submitted by !name', array('!name' => $username)));
    $breadcrumb = drupal_get_breadcrumb();
--- 962,968 ----
      if (!$username) {
        $username = theme('username', $node);
      }
!     $output .= node_view($node, !($linkdesc == 'body'), FALSE, TRUE); 
    }
    drupal_set_title(t('Links submitted by !name', array('!name' => $username)));
    $breadcrumb = drupal_get_breadcrumb();
***************
*** 963,969 ****
      $uid = $account->uid;
    }
    else {
!     $uid = db_result(db_query("SELECT uid FROM {users} WHERE name='%s'", $name));
    }
    return $uid;
  }
--- 977,983 ----
      $uid = $account->uid;
    }
    else {
!     $uid = db_query("SELECT uid FROM {users} WHERE name='%s'", $name)->fetchField();
    }
    return $uid;
  }
***************
*** 1004,1010 ****
    static $options, $empty_text, $filter_format, $linkdesc;
    if (!isset($empty_text)) {
      $empty_text = variable_get('weblinks_empty_text', NULL);
!     $filter_format = variable_get('weblinks_format', FILTER_FORMAT_DEFAULT);
      $linkdesc = variable_get('weblinks_linkdesc', 'teaser');
  
      $options = array();
--- 1018,1024 ----
    static $options, $empty_text, $filter_format, $linkdesc;
    if (!isset($empty_text)) {
      $empty_text = variable_get('weblinks_empty_text', NULL);
!     $filter_format = variable_get('weblinks_format', filter_fallback_format());
      $linkdesc = variable_get('weblinks_linkdesc', 'teaser');
  
      $options = array();
***************
*** 1033,1041 ****
  
    $items = array();
    $i = 0;
!   while ($row = db_fetch_array($result)) {
!     $node = node_load($row['nid']);
!     $output .= node_view($node, !($linkdesc == 'body'), FALSE, TRUE);
    }
  
    // Do we need a "more" link?
--- 1047,1056 ----
  
    $items = array();
    $i = 0;
!   foreach ($result as $row) {
!     $node = node_load($row->nid);
! print_r($node);
!     $output .= node_view($node, !($linkdesc == 'body'));
    }
  
    // Do we need a "more" link?
***************
*** 1109,1115 ****
      }
      else {
        $join_tn = 'INNER JOIN {term_node} tn ON tn.nid=n.nid AND tn.vid=n.vid ';
!       $where_tn = 'tn.tid IN (%s)';
      }
    }
    else {
--- 1124,1130 ----
      }
      else {
        $join_tn = 'INNER JOIN {term_node} tn ON tn.nid=n.nid AND tn.vid=n.vid ';
!       $where_tn = 'tn.tid IN (:tid)';
      }
    }
    else {
***************
*** 1139,1145 ****
      case 'author':
      case 'user':
        $cols = 'DISTINCT(n.nid), n.sticky, n.created';
!       $wheres[] = 'n.uid=%d';
        $order .= 'ORDER BY n.sticky, n.created';
        break;
      case 'recent':
--- 1154,1160 ----
      case 'author':
      case 'user':
        $cols = 'DISTINCT(n.nid), n.sticky, n.created';
!       $wheres[] = 'n.uid=:uid';
        $order .= 'ORDER BY n.sticky, n.created';
        break;
      case 'recent':
***************
*** 1169,1184 ****
    }
   
    $where = $wheres ? (' WHERE '. implode(' AND ', $wheres) .' ') : NULL;
!   $query = 'SELECT ' . $cols . ' FROM {node} n ' . $join . $where .' '. $order;
!   $query = db_rewrite_sql($query);
  // $term = taxonomy_get_term($tid);
  // drupal_set_message("$tid ($term->name), $sort: ".$query);
  
    if ($limit) {
      $result = db_query_range($query, $tid, 0, $limit);
    }
    else {
!     $result = db_query($query, $tid);
    }
  
    return $result;
--- 1184,1200 ----
    }
   
    $where = $wheres ? (' WHERE '. implode(' AND ', $wheres) .' ') : NULL;
!   $query_wl = 'SELECT ' . $cols . ' FROM {node} n ' . $join . $where .' '. $order;
!   // db_rewrite_sql
  // $term = taxonomy_get_term($tid);
  // drupal_set_message("$tid ($term->name), $sort: ".$query);
  
    if ($limit) {
+     $query = db_query($query_wl, array(':tid' => $tid, ':uid' => $limit));
      $result = db_query_range($query, $tid, 0, $limit);
    }
    else {
!     $result = db_query($query_wl, array(':tid' => $tid, ':uid' => ''));
    }
  
    return $result;
***************
*** 1262,1268 ****
      return NULL;
    }
    else {
!     return '<div class="weblinks-pagedesc">'. check_markup($pagedesc, variable_get('weblinks_format', FILTER_FORMAT_DEFAULT, FALSE)) .'</div>';
    }
  }
  
--- 1278,1284 ----
      return NULL;
    }
    else {
!     return '<div class="weblinks-pagedesc">'. check_markup($pagedesc, variable_get('weblinks_format', filter_fallback_format(), FALSE)) .'</div>';
    }
  }
  
