Commit aed323fe authored by Greg Sebastian's avatar Greg Sebastian Committed by Nancy Wichmann
Browse files

Issue #2227715 by GJdan, NancyDru: Fixes for glossary filter

parent 866ea1d5
Loading
Loading
Loading
Loading
+30 −30
Changes for glossary.module: 30 added lines, 30 removed lines.
Original line number Diff line number Diff line
@@ -399,6 +399,8 @@ function glossary_filter_glossary_process($text, $filter, $format, $langcode, $c
      $fragment = NULL;
      if ($term->nodes > 0) {
        $linkto = taxonomy_term_path($term);
        $uri = taxonomy_term_uri($term);
        $linkto = $uri['path'];
      }
      elseif (!empty($vids) && (variable_get('glossary_click_option', 0) == 1)) {
        if (variable_get('glossary_hide_if_empty', 1) && empty($term_title)) {
@@ -510,6 +512,7 @@ function glossary_filter_glossary_process($text, $filter, $format, $langcode, $c

      // Replace term with the desired new HTML code.
      $terms_replace[] = array(
        'name' => $term->name,
        'ins_before' => $ins_before,
        'ins_after' => $ins_after,
      );
@@ -578,16 +581,17 @@ function _glossary_insertlink($format, &$text, &$terms) {
  }

  // Find match candidates.
  // @TODO: We don't have synonyms any more.
  foreach ($terms as $i => $term) {
    foreach ($term['synonyms'] as $synonym) {
    $term_name = $term['name'];
    if (!$case_sensitive) {
        $synonym = drupal_strtolower($synonym);
      $term_name = drupal_strtolower($term_name);
    }

    $offset = 0;
    $first_match_found = FALSE;
      while (($offset = $findfunc($searchtext, $synonym, $offset)) !== FALSE) {
        $len = drupal_strlen($synonym);

    while (($offset = $findfunc($searchtext, $term_name, $offset)) !== FALSE) {
      $len = drupal_strlen($term_name);
      $match = drupal_substr($text, $offset, $len);
      // Only longer matches override shorter ones.
      if (!isset($events[$offset]) || drupal_strlen($events[$offset]['match']) < drupal_strlen($match)) {
@@ -601,7 +605,6 @@ function _glossary_insertlink($format, &$text, &$terms) {
          $first_match_found = TRUE;
          break;
        }
        }
        $offset += $len;
      }
      // TODO: remove this if we want different synonyms of the same term to
@@ -950,8 +953,9 @@ function theme_glossary_overview_item($variables) {
        $output .= "</div>\n";
      }
      else {
        $uri = taxonomy_term_uri($term);
        $output .= '<div class="glossary-detailed-link">' .
            l(t('Detailed definition of @term', array('@term' => $term->name)), taxonomy_term_path($term))
          l(t('Detailed definition of @term', array('@term' => $term->name)), $uri['path'])
          . '</div>';
      }
    }
@@ -1121,16 +1125,6 @@ function _glossary_list() {
  return $output;
}

function db_rewrite_sql($text) {
  $where = debug_backtrace();
  drupal_set_message(t('Function "@func" called on line @line of @file.', array(
    '@func' => $where[0]['function'],
    '@line' => $where[0]['line'],
    '@file' => $where[0]['file'],
      )), 'warning');
  return $text;
}

/**
 * Get taxonomy terms.
 */
@@ -1152,31 +1146,37 @@ function _glossary_get_terms($format) {
      // Omit terms without a description. those are usually container terms.
      // If multilingual taxonomy is enabled only show terms in current or no
      // language.
      $result = db_select('taxonomy_term_data', 'td');
      // $result->leftJoin('taxonomy_index', 'ti');
      $result->join('taxonomy_index', 'ti');
      $query = db_select('taxonomy_term_data', 'td');
      // We have to use a left join because some people don't use nodes.
      $query->leftJoin('taxonomy_index', 'ti', 'ti.tid = td.tid');

      $result->fields('td', array('tid', 'name'))
      $query->fields('td', array('tid', 'name', 'description'))
        ->addExpression('COUNT(ti.nid)', 'nodes');
      $result->condition('td.vid', $vid)
      $query->condition('td.vid', $vid)
        ->groupBy('td.tid')
          ->groupBy('td.name')
          ->groupBy('td.description')
//        ->groupBy('td.name')
//        ->groupBy('td.description')
        ->orderBy('LENGTH(td.name)', 'DESC');
      if (module_exists('i18ntaxonomy')) {
        global $language;
        $result->condition('td.language', array('', $language->language), 'IN');
        $query->condition('td.language', array('', $language->language), 'IN');
      }

      // $result->addTag('term_access');
      $result->execute();
      foreach ($result as $term) {
      // $query->addTag('term_access');
      $result = $query->execute();
      while ($term = $result->fetchObject()) {
        if ($term->nodes) {
          // If there were any nodes attached, we need to
          // see if they were unpublished.
          // TODO Please convert this statement to the D7 database API syntax.
          $unpubs = db_query(db_rewrite_sql("SELECT COUNT(n.nid) FROM {taxonomy_term_node} tn JOIN {node} n USING (nid) WHERE tn.tid=%d AND n.status=0"), $term->tid)->fetchField();
          $term->nodes -= $unpubs;
          //$unpubs = db_query(db_rewrite_sql("SELECT COUNT(n.nid) FROM {taxonomy_term_node} tn JOIN {node} n USING (nid) WHERE tn.tid=%d AND n.status=0"), $term->tid)->fetchField();
          $query = db_select('taxonomy_index', 'ti')
            ->condition('ti.tid', $term->tid, '=');
          $query->addJoin('INNER', 'node', 'n', 'ti.nid = %alias.nid');
          $query->condition('n.status', 0, '=');
          $query->addExpression('COUNT(n.nid)', 'nodes');
          $unpubs = $query->execute();
          $term->nodes -= $unpubs->fetchField();
        }

        if ($term->description || $show_all) {