/[drupal]/contributions/modules/taxonomy_dss/taxonomy_dss.module
ViewVC logotype

Diff of /contributions/modules/taxonomy_dss/taxonomy_dss.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.26.2.2, Wed Jan 23 20:38:50 2008 UTC revision 1.26.2.3, Fri Jan 25 20:45:58 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: taxonomy_dss.module,v 1.26.2.1 2008/01/16 21:34:49 moonray Exp $  // $Id: taxonomy_dss.module,v 1.26.2.2 2008/01/23 20:38:50 moonray Exp $
3    
4  /* Required patch to core (can we find a module specific workaround?):  /* Required patch to core (can we find a module specific workaround?):
5    
# Line 228  function taxonomy_dss_submit(&$node) { Line 228  function taxonomy_dss_submit(&$node) {
228    
229    // Set proper path alias    // Set proper path alias
230    if (module_exists('i18n')) {    if (module_exists('i18n')) {
231      if ($node->language == i18n_default_language()) {      if (empty($node->language) || $node->language == i18n_default_language()) {
232        $node->path = 'taxonomy/term/'. $node->termset->tids;        $node->path = 'taxonomy/term/'. $node->termset->tids;
233      }      }
234      else {      else {
# Line 572  function taxonomy_dss_form_alter($form_i Line 572  function taxonomy_dss_form_alter($form_i
572        break;        break;
573    
574      case 'taxonomy_form_vocabulary':      case 'taxonomy_form_vocabulary':
575          $form['taxonomy_dss_disabled'] = array(
576            '#type'          => 'checkboxes',
577            '#title'         => t('Taxonomy DSS'),
578            '#default_value' => (taxonomy_dss_vocabulary_is_disabled($form['vid']['#value']) ? 1 : 0),
579            '#options'       => array('1' => t('Disable for this vocabulary')),
580            '#description'   => t('Don\'t allow Taxonomy DSS to use this vocabulary when building site structure. This  also disables showing terms from this vocabulary in the breadcrumb trail.'),
581            '#weight' => 1,
582          );
583        $form['taxonomy_dss_hidden'] = array(        $form['taxonomy_dss_hidden'] = array(
584          '#type'          => 'checkboxes',          '#type'          => 'checkboxes',
585          '#title'         => t('Breadcrumb'),          '#title'         => t('Breadcrumb'),
# Line 581  function taxonomy_dss_form_alter($form_i Line 589  function taxonomy_dss_form_alter($form_i
589          '#weight' => 1,          '#weight' => 1,
590        );        );
591        break;        break;
   
     case 'node_admin_nodes':  
       // Override edit destination for 'termset' nodes on 'Content management' page  
       if (is_array($form['name'])) {  
         $keys = array_keys($form['name']);  
         foreach ($keys as $key) {  
           if ($form['name'][$key]['#value'] == 'Termset') {  
             $form['operations'][$key]['#value'] = l(t('edit'), 'taxonomy/term/'. taxonomy_dss_get_tids($key) .'/edit', array(), drupal_get_destination());  
           }  
         }  
       }  
       break;  
592    }    }
593  }  }
594    
# Line 606  function taxonomy_dss_taxonomy($op, $typ Line 602  function taxonomy_dss_taxonomy($op, $typ
602          db_query("DELETE FROM {taxonomy_dss_vocabulary} WHERE vid = %d", $object['vid']);          db_query("DELETE FROM {taxonomy_dss_vocabulary} WHERE vid = %d", $object['vid']);
603          break;          break;
604        case 'insert':        case 'insert':
605          db_query("INSERT INTO {taxonomy_dss_vocabulary} (vid, hidden) VALUES (%d, %d)", $object['vid'], $object['taxonomy_dss_hidden']['1']);          db_query("INSERT INTO {taxonomy_dss_vocabulary} (vid, hidden, disabled) VALUES (%d, %d, %d)", $object['vid'], $object['taxonomy_dss_hidden']['1'], $object['taxonomy_dss_disabled']['1']);
606          break;          break;
607        case 'update':        case 'update':
608          db_query("UPDATE {taxonomy_dss_vocabulary} SET hidden = %d WHERE vid = %d", $object['taxonomy_dss_hidden']['1'], $object['vid']);          db_query("UPDATE {taxonomy_dss_vocabulary} SET hidden = %d, disabled = %d WHERE vid = %d", $object['taxonomy_dss_hidden']['1'], $object['taxonomy_dss_disabled']['1'], $object['vid']);
609          break;          break;
610      }      }
611    }    }
# Line 697  function taxonomy_dss_vocabulary_is_hidd Line 693  function taxonomy_dss_vocabulary_is_hidd
693    static $vocabularies = array();    static $vocabularies = array();
694    
695    if (!isset($vocabularies[$vid])) {    if (!isset($vocabularies[$vid])) {
696      $result = db_query("SELECT hidden FROM {taxonomy_dss_vocabulary} WHERE vid = %d", $vid);      $result = db_query("SELECT hidden, disabled FROM {taxonomy_dss_vocabulary} WHERE vid = %d", $vid);
697      $row = db_fetch_array($result);      $row = db_fetch_array($result);
698      if ($row && $row['hidden'] == 1) {      if ($row && ($row['hidden'] == 1 || $row['disabled'] == 1)) {
699          $vocabularies[$vid] = TRUE;
700        }
701        else {
702          $vocabularies[$vid] = FALSE;
703        }
704      }
705    
706      return $vocabularies[$vid];
707    }
708    
709    /**
710     * Is vocabulary disabled?
711     */
712    function taxonomy_dss_vocabulary_is_disabled($vid) {
713      static $vocabularies = array();
714    
715      if (!isset($vocabularies[$vid])) {
716        $result = db_query("SELECT disabled FROM {taxonomy_dss_vocabulary} WHERE vid = %d", $vid);
717        $row = db_fetch_array($result);
718        if ($row && $row['disabled'] == 1) {
719        $vocabularies[$vid] = TRUE;        $vocabularies[$vid] = TRUE;
720      }      }
721      else {      else {
# Line 743  function _taxonomy_dss_load_termset($tid Line 759  function _taxonomy_dss_load_termset($tid
759      }      }
760    
761      // Allow other modules to alter the data      // Allow other modules to alter the data
762      taxonomy_dss_invoke($data[$tids], 'load');      $node = new StdClass;
763        $node->termset = &$data[$tids];
764        taxonomy_dss_invoke($node, 'load');
765    }    }
766    
767    return drupal_clone($data[$tids]);    return drupal_clone($data[$tids]);
# Line 773  function taxonomy_dss_get_current_tids() Line 791  function taxonomy_dss_get_current_tids()
791    static $tids;    static $tids;
792    
793    // Return cached version    // Return cached version
794    if (is_array($tids)) {    if (!is_array($tids)) {
795      return $tids;      $tids = array();
796    }      switch (arg(0)) {
797          case 'node':
798    $tids = array();          if (is_numeric(arg(1))) {
799    switch (arg(0)) {            $node = node_load(arg(1));
800      case 'node':            if (!$node) {
801        if (is_numeric(arg(1))) {              break;
802          $node = node_load(arg(1));            }
803          if (!$node) {            if ($node->type == 'termset') {
804            break;              $tids = explode(',', $node->termset->tids);
805          }            }
806          if ($node->type == 'termset') {            else {
807            $tids = explode(',', $node->termset->tids);              $tids = taxonomy_dss_filter_tids($node->taxonomy, isset($_GET['taxonomy']) ? $_GET['taxonomy'] : '');
808              }
809          }          }
810          else {          break;
811            $tids = taxonomy_dss_filter_tids($node->taxonomy, isset($_GET['taxonomy']) ? $_GET['taxonomy'] : '');        case 'taxonomy':
812            if (arg(1) == 'term') {
813              $tids = explode(',', arg(2));
814          }          }
815        }          break;
816        break;        case 'faq':
817      case 'taxonomy':          if (module_exists('faq') && module_exists('path_redirect')) {
818        if (arg(1) == 'term') {            $result = db_query("SELECT path FROM {path_redirect} WHERE redirect = '%s'", 'faq');
819          $tids = explode(',', arg(2));            while ($row = db_fetch_array($result)) {
820        }              if (substr($row['path'], 0, 14) == 'taxonomy/term/') {
821        break;                $names = array();
822      case 'faq':                $tids = explode(',', substr($row['path'], 14));
823        if (module_exists('faq') && module_exists('path_redirect')) {              }
         $result = db_query("SELECT path FROM {path_redirect} WHERE redirect = '%s'", 'faq');  
         while ($row = db_fetch_array($result)) {  
           if (substr($row['path'], 0, 14) == 'taxonomy/term/') {  
             $names = array();  
             $tids = explode(',', substr($row['path'], 14));  
824            }            }
825          }          }
826        }          break;
827        break;      }
828    
829        // Allow modules to modify the fully-built termset.
830        $termset = NULL;
831        taxonomy_dss_invoke($termset, 'get current tids', $tids);
832    }    }
833    
834    return $tids;    return $tids;
835  }  }
836    
# Line 966  function taxonomy_dss_filter_tids($taxon Line 986  function taxonomy_dss_filter_tids($taxon
986    
987    // Filter out invalid and hidden tids    // Filter out invalid and hidden tids
988    for ($i = 0; $i < count($tids); $i++) {    for ($i = 0; $i < count($tids); $i++) {
989      /*      // Is this a valid tid?
990      // If the term's vocabulary is hidden, don't return it      if (in_array($tids[$i], $keys)) {
991      if ($strip_hidden) {        $term = $taxonomy[$tids[$i]];
       // Is this a valid tid?  
       if (in_array($tids[$i], $keys)) {  
         $term = $taxonomy[$tids[$i]];  
992    
993          // Cache vocabulary data        if (!isset($vids[$term->vid])) {
994          if (!isset($vids[$term->vid])) {          if ($strip_hidden) {
995            $vids[$term->vid] = taxonomy_dss_vocabulary_is_hidden($term->vid);            $vids[$term->vid] = taxonomy_dss_vocabulary_is_hidden($term->vid);
996          }          }
997            else {
998          // Only return tid if it's not hidden            $vids[$term->vid] = FALSE;
         if ($vids[$term->vid] == FALSE) {  
           $return[]  = $term->tid;  
         }  
       }  
     }  
     else {  
     */  
       // Is this a valid tid?  
       if (in_array($tids[$i], $keys)) {  
         $term = $taxonomy[$tids[$i]];  
   
         if (!isset($vids[$term->vid])) {  
           if ($strip_hidden) {  
             $vids[$term->vid] = taxonomy_dss_vocabulary_is_hidden($term->vid);  
           }  
           else {  
             $vids[$term->vid] = FALSE;  
           }  
999          }          }
         $return[] = $tids[$i];  
1000        }        }
1001      /*        $return[] = $tids[$i];
1002      }      }
     */  
1003    }    }
1004    
1005    // Filter out hidden tids, and add the remaining ones    // Filter out hidden tids, and add the remaining ones
# Line 1068  function taxonomy_dss_select_children($t Line 1065  function taxonomy_dss_select_children($t
1065      $sql_b = db_rewrite_sql("SELECT DISTINCT(n.nid) FROM {node} n {$joins} WHERE n.status = 1 {$wheres} AND (___PLACEHOLDER1___) > ". count($tids));      $sql_b = db_rewrite_sql("SELECT DISTINCT(n.nid) FROM {node} n {$joins} WHERE n.status = 1 {$wheres} AND (___PLACEHOLDER1___) > ". count($tids));
1066      $sql_b = str_replace('___PLACEHOLDER1___', $sql_a, $sql_b);      $sql_b = str_replace('___PLACEHOLDER1___', $sql_a, $sql_b);
1067    
1068      $sql_c = db_rewrite_sql("SELECT tn.nid, tn.tid, td.vid, td.name, td.description, td.weight, v.weight AS vweight FROM {term_node} tn LEFT JOIN {term_data} td ON td.tid = tn.tid LEFT JOIN {vocabulary} v ON td.vid = v.vid WHERE tn.nid IN (___PLACEHOLDER2___) AND td.vid NOT IN (SELECT td1.vid FROM {term_data} td1 WHERE td1.tid IN (". implode(',', $tids) .")) ORDER BY v.weight DESC, td.weight DESC, td.name DESC", 'tn', 'tid');      $sql_c = db_rewrite_sql("SELECT tn.nid, tn.tid, td.vid, td.name, td.description, td.weight, v.weight AS vweight FROM {term_node} tn LEFT JOIN {term_data} td ON td.tid = tn.tid LEFT JOIN {vocabulary} v ON td.vid = v.vid LEFT JOIN {taxonomy_dss_vocabulary} tv ON td.vid = tv.vid WHERE tv.disabled = 0 AND tn.nid IN (___PLACEHOLDER2___) AND td.vid NOT IN (SELECT td1.vid FROM {term_data} td1 WHERE td1.tid IN (". implode(',', $tids) .")) ORDER BY v.weight DESC, td.weight DESC, td.name DESC", 'tn', 'tid');
1069      $sql_c = str_replace('___PLACEHOLDER2___', $sql_b, $sql_c);      $sql_c = str_replace('___PLACEHOLDER2___', $sql_b, $sql_c);
1070    
1071      $sql = db_rewrite_sql("SELECT DISTINCT(r.tid), r.vid, r.name, r.description, r.weight, GROUP_CONCAT(DISTINCT(r.tid) ORDER BY r.vweight, r.weight, r.name SEPARATOR ',') AS tids FROM (___PLACEHOLDER3___) r GROUP BY r.nid ORDER BY r.vweight, r.weight, r.name", 'custom', 'tid');      $sql = db_rewrite_sql("SELECT DISTINCT(r.tid), r.vid, r.name, r.description, r.weight, GROUP_CONCAT(DISTINCT(r.tid) ORDER BY r.vweight, r.weight, r.name SEPARATOR ',') AS tids FROM (___PLACEHOLDER3___) r GROUP BY r.nid ORDER BY r.vweight, r.weight, r.name", 'custom', 'tid');
# Line 1102  function taxonomy_dss_get_tree_children( Line 1099  function taxonomy_dss_get_tree_children(
1099        array_pop($mytids);        array_pop($mytids);
1100      }      }
1101    
1102      $child->nodes    = array();      $child->nodes = array();
1103    
1104      // Is child a sub of other child(ren)?      // Is child a sub of other child(ren)?
1105      if (strpos($child->tids, ',') !== FALSE) {      if (strpos($child->tids, ',') !== FALSE) {
# Line 1245  function taxonomy_dss_select_nodes($tids Line 1242  function taxonomy_dss_select_nodes($tids
1242          $sql = db_rewrite_sql('SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n '. $joins .' WHERE n.status = 1 '. $promote_sql . $wheres .' AND (___PLACEHOLDER___) = '. count($descendant_tids) .' ORDER BY '. $order);          $sql = db_rewrite_sql('SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n '. $joins .' WHERE n.status = 1 '. $promote_sql . $wheres .' AND (___PLACEHOLDER___) = '. count($descendant_tids) .' ORDER BY '. $order);
1243    
1244          // db_rewrite_sql() bugs out on a complex SELECT within a SELECT, so need to work around it          // db_rewrite_sql() bugs out on a complex SELECT within a SELECT, so need to work around it
1245          $sql_sub = db_rewrite_sql('SELECT COUNT(DISTINCT(td0.vid)) FROM {term_node} tn LEFT JOIN {term_data} td0 ON tn.tid = td0.tid WHERE tn.nid = n.nid', 'tn', 'tid');          $sql_sub = db_rewrite_sql('SELECT COUNT(DISTINCT(td0.vid)) FROM {term_node} tn LEFT JOIN {term_data} td0 ON tn.tid = td0.tid LEFT JOIN {taxonomy_dss_vocabulary} tv ON td0.vid = tv.vid WHERE tv.disabled = 0 AND tn.nid = n.nid', 'tn', 'tid');
1246          $sql = str_replace('___PLACEHOLDER___', $sql_sub, $sql);          $sql = str_replace('___PLACEHOLDER___', $sql_sub, $sql);
1247    
1248          // db_rewrite_sql() bugs out on a complex SELECT within a SELECT, so need to work around it          // db_rewrite_sql() bugs out on a complex SELECT within a SELECT, so need to work around it

Legend:
Removed from v.1.26.2.2  
changed lines
  Added in v.1.26.2.3

  ViewVC Help
Powered by ViewVC 1.1.2