| 1 | <?php | = | 1 | <?php |
| 2 | // $Id: taxonomy.module,v 1.330.2.15 2007/12/20 07:48:11 drumm Exp $ | <> | 2 | // $Id: taxonomy.module,v 1.1.2.1 2008/02/18 15:29:42 robertogerola Exp $ |
| 3 | = | 3 | ||
| 4 | /** | 4 | /** | |
| 5 | * @file | 5 | * @file | |
| 6 | * Enables the organization of content into categories. | 6 | * Enables the organization of content into categories. | |
| 7 | */ | 7 | */ | |
| 8 | 8 | |||
| 178 | = | 178 | ||
| 179 | $header = array(t('Name'), t('Operations')); | 179 | $header = array(t('Name'), t('Operations')); | |
| 180 | $vocabulary = taxonomy_get_vocabulary($vid); | 180 | $vocabulary = taxonomy_get_vocabulary($vid); | |
| 181 | if (!$vocabulary) { | 181 | if (!$vocabulary) { | |
| 182 | return drupal_not_found(); | 182 | return drupal_not_found(); | |
| 183 | } | 183 | } | |
| 184 | // Translatable support. | <> | ||
| 185 | if (function_exists('tobject')) { | |||
| 186 | $vocabulary = tobject('taxonomy_vocabulary', $vocabulary->vid, $vocabulary); | 184 | if(function_exists('to')) $vocabulary = to('taxonomy_vocabulary', $vocabulary->vid, $vocabulary); | |
| 187 | } | |||
| 188 | = | 185 | ||
| 189 | drupal_set_title(check_plain($vocabulary->name)); | 186 | drupal_set_title(check_plain($vocabulary->name)); | |
| 190 | $start_from = $_GET['page'] ? $_GET['page'] : 0; | 187 | $start_from = $_GET['page'] ? $_GET['page'] : 0; | |
| 191 | $total_entries = 0; // total count for pager | 188 | $total_entries = 0; // total count for pager | |
| 192 | $page_increment = 25; // number of tids per page | 189 | $page_increment = 25; // number of tids per page | |
| 193 | $displayed_count = 0; // number of tids shown | 190 | $displayed_count = 0; // number of tids shown | |
| 194 | 191 | |||
| 195 | if ($vocabulary->tags) { | 192 | if ($vocabulary->tags) { | |
| 196 | // We are not calling taxonomy_get_tree because that might fail with a big | 193 | // We are not calling taxonomy_get_tree because that might fail with a big | |
| 197 | // number of tags in the freetagging vocabulary. | 194 | // number of tags in the freetagging vocabulary. | |
| 198 | $results = pager_query(db_rewrite_sql('SELECT t.*, h.parent FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d ORDER BY weight, name', 't', 'tid'), $page_increment, 0, NULL, $vid); | 195 | $results = pager_query(db_rewrite_sql('SELECT t.*, h.parent FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d ORDER BY weight, name', 't', 'tid'), $page_increment, 0, NULL, $vid); | |
| 199 | while ($term = db_fetch_object($results)) { | 196 | while ($term = db_fetch_object($results)) { | |
| 200 | // Translatable support. | <> | ||
| 201 | if (function_exists('tobject')) { | |||
| 202 | $term = tobject('taxonomy_term', $term->tid, $term); | 197 | if(function_exists('to')) $term=to('taxonomy_term', $term->tid, $term); | |
| 203 | } | |||
| 204 | $rows[] = array( | = | 198 | $rows[] = array( |
| 205 | l($term->name, "taxonomy/term/$term->tid"), | 199 | l($term->name, "taxonomy/term/$term->tid"), | |
| 206 | l(t('edit'), "admin/content/taxonomy/edit/term/$term->tid", array(), $destination), | 200 | l(t('edit'), "admin/content/taxonomy/edit/term/$term->tid", array(), $destination), | |
| 207 | ); | 201 | ); | |
| 208 | } | 202 | } | |
| 209 | } | 203 | } | |
| 210 | else { | 204 | else { | |
| 211 | $tree = taxonomy_get_tree($vocabulary->vid); | 205 | $tree = taxonomy_get_tree($vocabulary->vid); | |
| 212 | foreach ($tree as $term) { | 206 | foreach ($tree as $term) { | |
| -+ | 207 | if(function_exists('to')) $term=to('taxonomy_term', $term->tid, $term); | ||
| 213 | $total_entries++; // we're counting all-totals, not displayed | = | 208 | $total_entries++; // we're counting all-totals, not displayed |
| 214 | if (($start_from && ($start_from * $page_increment) >= $total_entries) || ($displayed_count == $page_increment)) { | 209 | if (($start_from && ($start_from * $page_increment) >= $total_entries) || ($displayed_count == $page_increment)) { | |
| 215 | continue; | 210 | continue; | |
| 216 | } | +- | ||
| 217 | // Translatable support. | |||
| 218 | if (function_exists('tobject')) { | |||
| 219 | $term = tobject('taxonomy_term', $term->tid, $term); | |||
| 220 | } | = | 211 | } |
| 221 | $rows[] = array(str_repeat('--', $term->depth) .' '. l($term->name, "taxonomy/term/$term->tid"), l(t('edit'), "admin/content/taxonomy/edit/term/$term->tid", array(), $destination)); | 212 | $rows[] = array(str_repeat('--', $term->depth) .' '. l($term->name, "taxonomy/term/$term->tid"), l(t('edit'), "admin/content/taxonomy/edit/term/$term->tid", array(), $destination)); | |
| 222 | $displayed_count++; // we're counting tids displayed | 213 | $displayed_count++; // we're counting tids displayed | |
| 223 | } | 214 | } | |
| 224 | 215 | |||
| 225 | if (!$rows) { | 216 | if (!$rows) { | |
| 630 | = | 621 | ||
| 631 | /** | 622 | /** | |
| 632 | * Generate a form element for selecting terms from a vocabulary. | 623 | * Generate a form element for selecting terms from a vocabulary. | |
| 633 | */ | 624 | */ | |
| 634 | function taxonomy_form($vid, $value = 0, $help = NULL, $name = 'taxonomy') { | 625 | function taxonomy_form($vid, $value = 0, $help = NULL, $name = 'taxonomy') { | |
| 635 | $vocabulary = taxonomy_get_vocabulary($vid); | 626 | $vocabulary = taxonomy_get_vocabulary($vid); | |
| 636 | // Translatable support. | <> | ||
| 637 | if (function_exists('tobject')) { | |||
| 638 | $vocabulary = tobject('taxonomy_vocabulary', $vocabulary->vid, $vocabulary); | 627 | if(function_exists('to')) $vocabulary=to('taxonomy_vocabulary', $vocabulary->vid, $vocabulary); | |
| 639 | } | |||
| 640 | $help = ($help) ? $help : $vocabulary->help; | = | 628 | $help = ($help) ? $help : $vocabulary->help; |
| 641 | 629 | |||
| 642 | if (!$vocabulary->multiple) { | 630 | if (!$vocabulary->multiple) { | |
| 643 | $blank = ($vocabulary->required) ? t('- Please choose -') : t('- None selected -'); | 631 | $blank = ($vocabulary->required) ? t('- Please choose -') : t('- None selected -'); | |
| 644 | } | 632 | } | |
| 645 | else { | 633 | else { | |
| 682 | $result = db_query(db_rewrite_sql('SELECT v.*, n.type FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} n ON v.vid = n.vid ORDER BY v.weight, v.name', 'v', 'vid')); | = | 670 | $result = db_query(db_rewrite_sql('SELECT v.*, n.type FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} n ON v.vid = n.vid ORDER BY v.weight, v.name', 'v', 'vid')); |
| 683 | } | 671 | } | |
| 684 | 672 | |||
| 685 | $vocabularies = array(); | 673 | $vocabularies = array(); | |
| 686 | $node_types = array(); | 674 | $node_types = array(); | |
| 687 | while ($voc = db_fetch_object($result)) { | 675 | while ($voc = db_fetch_object($result)) { | |
| 688 | // Translatable support. | <> | ||
| 689 | if (function_exists('tobject')) { | |||
| 690 | $voc = tobject('taxonomy_vocabulary', $voc->vid, $voc); | 676 | if(function_exists('to')) $voc=to('taxonomy_vocabulary', $voc->vid, $voc); | |
| 691 | } | |||
| 692 | $node_types[$voc->vid][] = $voc->type; | = | 677 | $node_types[$voc->vid][] = $voc->type; |
| 693 | unset($voc->type); | 678 | unset($voc->type); | |
| 694 | $voc->nodes = $node_types[$voc->vid]; | 679 | $voc->nodes = $node_types[$voc->vid]; | |
| 695 | $vocabularies[$voc->vid] = $voc; | 680 | $vocabularies[$voc->vid] = $voc; | |
| 696 | } | 681 | } | |
| 697 | 682 | |||
| 718 | $terms = $node->taxonomy; | = | 703 | $terms = $node->taxonomy; |
| 719 | } | 704 | } | |
| 720 | 705 | |||
| 721 | $c = db_query(db_rewrite_sql("SELECT v.* FROM {vocabulary} v INNER JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s' ORDER BY v.weight, v.name", 'v', 'vid'), $node->type); | 706 | $c = db_query(db_rewrite_sql("SELECT v.* FROM {vocabulary} v INNER JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s' ORDER BY v.weight, v.name", 'v', 'vid'), $node->type); | |
| 722 | 707 | |||
| 723 | while ($vocabulary = db_fetch_object($c)) { | 708 | while ($vocabulary = db_fetch_object($c)) { | |
| -+ | 709 | if(function_exists('to')) $vocabulary = to('taxonomy_vocabulary', $vocabulary->vid, $vocabulary); | ||
| 724 | if ($vocabulary->tags) { | = | 710 | if ($vocabulary->tags) { |
| 725 | $typed_terms = array(); | 711 | $typed_terms = array(); | |
| 726 | foreach ($terms as $term) { | 712 | foreach ($terms as $term) { | |
| 727 | // Extract terms belonging to the vocabulary in question. | 713 | // Extract terms belonging to the vocabulary in question. | |
| 728 | if ($term->vid == $vocabulary->vid) { | 714 | if ($term->vid == $vocabulary->vid) { | |
| 729 | 715 | |||
| 785 | * Find all terms associated with the given node, within one vocabulary. | = | 771 | * Find all terms associated with the given node, within one vocabulary. |
| 786 | */ | 772 | */ | |
| 787 | function taxonomy_node_get_terms_by_vocabulary($nid, $vid, $key = 'tid') { | 773 | function taxonomy_node_get_terms_by_vocabulary($nid, $vid, $key = 'tid') { | |
| 788 | $result = db_query(db_rewrite_sql('SELECT t.tid, t.* FROM {term_data} t INNER JOIN {term_node} r ON r.tid = t.tid WHERE t.vid = %d AND r.nid = %d ORDER BY weight', 't', 'tid'), $vid, $nid); | 774 | $result = db_query(db_rewrite_sql('SELECT t.tid, t.* FROM {term_data} t INNER JOIN {term_node} r ON r.tid = t.tid WHERE t.vid = %d AND r.nid = %d ORDER BY weight', 't', 'tid'), $vid, $nid); | |
| 789 | $terms = array(); | 775 | $terms = array(); | |
| 790 | while ($term = db_fetch_object($result)) { | 776 | while ($term = db_fetch_object($result)) { | |
| 791 | // Translatable support. | <> | ||
| 792 | if (function_exists('tobject')) { | |||
| 793 | $term = tobject('taxonomy_term', $term->tid, $term); | 777 | if(function_exists('to')) $term=to('taxonomy_term', $term->tid, $term); | |
| 794 | } | |||
| 795 | $terms[$term->$key] = $term; | = | 778 | $terms[$term->$key] = $term; |
| 796 | } | 779 | } | |
| 797 | return $terms; | 780 | return $terms; | |
| 798 | } | 781 | } | |
| 799 | 782 | |||
| 800 | /** | 783 | /** | |
| 804 | static $terms; | = | 787 | static $terms; |
| 805 | 788 | |||
| 806 | if (!isset($terms[$nid][$key])) { | 789 | if (!isset($terms[$nid][$key])) { | |
| 807 | $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_node} r INNER JOIN {term_data} t ON r.tid = t.tid INNER JOIN {vocabulary} v ON t.vid = v.vid WHERE r.nid = %d ORDER BY v.weight, t.weight, t.name', 't', 'tid'), $nid); | 790 | $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_node} r INNER JOIN {term_data} t ON r.tid = t.tid INNER JOIN {vocabulary} v ON t.vid = v.vid WHERE r.nid = %d ORDER BY v.weight, t.weight, t.name', 't', 'tid'), $nid); | |
| 808 | $terms[$nid][$key] = array(); | 791 | $terms[$nid][$key] = array(); | |
| 809 | while ($term = db_fetch_object($result)) { | 792 | while ($term = db_fetch_object($result)) { | |
| 810 | // Translatable support. | <> | ||
| 811 | if (function_exists('tobject')) { | |||
| 812 | $term=tobject('taxonomy_term', $term->tid, $term); | 793 | if(function_exists('to')) $term=to('taxonomy_term', $term->tid, $term); | |
| 813 | } | |||
| 814 | $terms[$nid][$key][$term->$key] = $term; | = | 794 | $terms[$nid][$key][$term->$key] = $term; |
| 815 | } | 795 | } | |
| 816 | } | 796 | } | |
| 817 | return $terms[$nid][$key]; | 797 | return $terms[$nid][$key]; | |
| 818 | } | 798 | } | |
| 819 | 799 | |||
| 932 | */ | = | 912 | */ |
| 933 | function taxonomy_get_related($tid, $key = 'tid') { | 913 | function taxonomy_get_related($tid, $key = 'tid') { | |
| 934 | if ($tid) { | 914 | if ($tid) { | |
| 935 | $result = db_query('SELECT t.*, tid1, tid2 FROM {term_relation}, {term_data} t WHERE (t.tid = tid1 OR t.tid = tid2) AND (tid1 = %d OR tid2 = %d) AND t.tid != %d ORDER BY weight, name', $tid, $tid, $tid); | 915 | $result = db_query('SELECT t.*, tid1, tid2 FROM {term_relation}, {term_data} t WHERE (t.tid = tid1 OR t.tid = tid2) AND (tid1 = %d OR tid2 = %d) AND t.tid != %d ORDER BY weight, name', $tid, $tid, $tid); | |
| 936 | $related = array(); | 916 | $related = array(); | |
| 937 | while ($term = db_fetch_object($result)) { | 917 | while ($term = db_fetch_object($result)) { | |
| 938 | // Translatable support. | <> | ||
| 939 | if (function_exists('tobject')) { | |||
| 940 | $term = tobject('taxonomy_term', $term->tid, $term); | 918 | if(function_exists('to')) $term=to('taxonomy_term', $term->tid, $term); | |
| 941 | } | |||
| 942 | $related[$term->$key] = $term; | = | 919 | $related[$term->$key] = $term; |
| 943 | } | 920 | } | |
| 944 | return $related; | 921 | return $related; | |
| 945 | } | 922 | } | |
| 946 | else { | 923 | else { | |
| 947 | return array(); | 924 | return array(); | |
| 953 | */ | = | 930 | */ |
| 954 | function taxonomy_get_parents($tid, $key = 'tid') { | 931 | function taxonomy_get_parents($tid, $key = 'tid') { | |
| 955 | if ($tid) { | 932 | if ($tid) { | |
| 956 | $result = db_query(db_rewrite_sql('SELECT t.tid, t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.parent = t.tid WHERE h.tid = %d ORDER BY weight, name', 't', 'tid'), $tid); | 933 | $result = db_query(db_rewrite_sql('SELECT t.tid, t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.parent = t.tid WHERE h.tid = %d ORDER BY weight, name', 't', 'tid'), $tid); | |
| 957 | $parents = array(); | 934 | $parents = array(); | |
| 958 | while ($parent = db_fetch_object($result)) { | 935 | while ($parent = db_fetch_object($result)) { | |
| 959 | // Translatable support. | <> | ||
| 960 | if (function_exists('tobject')) { | |||
| 961 | $parent=tobject('taxonomy_term', $parent->tid, $parent); | 936 | if(function_exists('to')) $parent=to('taxonomy_term', $parent->tid, $parent); | |
| 962 | } | |||
| 963 | $parents[$parent->$key] = $parent; | = | 937 | $parents[$parent->$key] = $parent; |
| 964 | } | 938 | } | |
| 965 | return $parents; | 939 | return $parents; | |
| 966 | } | 940 | } | |
| 967 | else { | 941 | else { | |
| 968 | return array(); | 942 | return array(); | |
| 994 | } | = | 968 | } |
| 995 | else { | 969 | else { | |
| 996 | $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.tid = t.tid WHERE parent = %d ORDER BY weight, name', 't', 'tid'), $tid); | 970 | $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.tid = t.tid WHERE parent = %d ORDER BY weight, name', 't', 'tid'), $tid); | |
| 997 | } | 971 | } | |
| 998 | $children = array(); | 972 | $children = array(); | |
| 999 | while ($term = db_fetch_object($result)) { | 973 | while ($term = db_fetch_object($result)) { | |
| 1000 | // Translatable support. | <> | ||
| 1001 | if (function_exists('tobject')) { | |||
| 1002 | $term = tobject('taxonomy_term', $term->tid, $term); | 974 | if(function_exists('to')) $term=to('taxonomy_term', $term->tid, $term); | |
| 1003 | } | |||
| 1004 | $children[$term->$key] = $term; | = | 975 | $children[$term->$key] = $term; |
| 1005 | } | 976 | } | |
| 1006 | return $children; | 977 | return $children; | |
| 1007 | } | 978 | } | |
| 1008 | 979 | |||
| 1009 | /** | 980 | /** | |
| 1036 | // and its children, too. | = | 1007 | // and its children, too. |
| 1037 | if (!isset($children[$vid])) { | 1008 | if (!isset($children[$vid])) { | |
| 1038 | $children[$vid] = array(); | 1009 | $children[$vid] = array(); | |
| 1039 | 1010 | |||
| 1040 | $result = db_query(db_rewrite_sql('SELECT t.tid, t.*, parent FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d ORDER BY weight, name', 't', 'tid'), $vid); | 1011 | $result = db_query(db_rewrite_sql('SELECT t.tid, t.*, parent FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d ORDER BY weight, name', 't', 'tid'), $vid); | |
| 1041 | while ($term = db_fetch_object($result)) { | 1012 | while ($term = db_fetch_object($result)) { | |
| 1042 | // Translatable support. | <> | ||
| 1043 | if (function_exists('tobject')) { | |||
| 1044 | $term = tobject('taxonomy_term', $term->tid, $term); | 1013 | if(function_exists('to')) $term=to('taxonomy_term', $term->tid, $term); | |
| 1045 | } | |||
| 1046 | $children[$vid][$term->parent][] = $term->tid; | = | 1014 | $children[$vid][$term->parent][] = $term->tid; |
| 1047 | $parents[$vid][$term->tid][] = $term->parent; | 1015 | $parents[$vid][$term->tid][] = $term->parent; | |
| 1048 | $terms[$vid][$term->tid] = $term; | 1016 | $terms[$vid][$term->tid] = $term; | |
| 1049 | } | 1017 | } | |
| 1050 | } | 1018 | } | |
| 1051 | 1019 | |||
| 1166 | * An array of matching term objects. | = | 1134 | * An array of matching term objects. |
| 1167 | */ | 1135 | */ | |
| 1168 | function taxonomy_get_term_by_name($name) { | 1136 | function taxonomy_get_term_by_name($name) { | |
| 1169 | $db_result = db_query(db_rewrite_sql("SELECT t.tid, t.* FROM {term_data} t WHERE LOWER('%s') LIKE LOWER(t.name)", 't', 'tid'), trim($name)); | 1137 | $db_result = db_query(db_rewrite_sql("SELECT t.tid, t.* FROM {term_data} t WHERE LOWER('%s') LIKE LOWER(t.name)", 't', 'tid'), trim($name)); | |
| 1170 | $result = array(); | 1138 | $result = array(); | |
| 1171 | while ($term = db_fetch_object($db_result)) { | 1139 | while ($term = db_fetch_object($db_result)) { | |
| 1172 | // Translatable support. | <> | ||
| 1173 | if (function_exists('tobject')) { | |||
| 1174 | $term = tobject('taxonomy_term', $term->tid,$term); | 1140 | if(function_exists('to')) $term=to('taxonomy_term', $term->tid,$term); | |
| 1175 | } | |||
| 1176 | $result[] = $term; | = | 1141 | $result[] = $term; |
| 1177 | } | 1142 | } | |
| 1178 | 1143 | |||
| 1179 | return $result; | 1144 | return $result; | |
| 1180 | } | 1145 | } | |
| 1181 | 1146 | |||
| 1193 | static $vocabularies = array(); | = | 1158 | static $vocabularies = array(); |
| 1194 | 1159 | |||
| 1195 | if (!array_key_exists($vid, $vocabularies)) { | 1160 | if (!array_key_exists($vid, $vocabularies)) { | |
| 1196 | $result = db_query('SELECT v.*, n.type FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE v.vid = %d ORDER BY v.weight, v.name', $vid); | 1161 | $result = db_query('SELECT v.*, n.type FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE v.vid = %d ORDER BY v.weight, v.name', $vid); | |
| 1197 | $node_types = array(); | 1162 | $node_types = array(); | |
| 1198 | while ($voc = db_fetch_object($result)) { | 1163 | while ($voc = db_fetch_object($result)) { | |
| 1199 | // Translatable support. | <> | ||
| 1200 | if(function_exists('tobject')) { | |||
| 1201 | $voc = tobject('taxonomy_vocabulary', $voc->vid, $voc); | 1164 | if(function_exists('to')) $voc = to('taxonomy_vocabulary', $voc->vid, $voc); | |
| 1202 | } | |||
| 1203 | $node_types[] = $voc->type; | = | 1165 | $node_types[] = $voc->type; |
| 1204 | unset($voc->type); | 1166 | unset($voc->type); | |
| 1205 | $voc->nodes = $node_types; | 1167 | $voc->nodes = $node_types; | |
| 1206 | $vocabularies[$vid] = $voc; | 1168 | $vocabularies[$vid] = $voc; | |
| 1207 | } | 1169 | } | |
| 1208 | } | 1170 | } | |
| 1221 | */ | = | 1183 | */ |
| 1222 | function taxonomy_get_term($tid) { | 1184 | function taxonomy_get_term($tid) { | |
| 1223 | static $terms = array(); | 1185 | static $terms = array(); | |
| 1224 | 1186 | |||
| 1225 | if (!isset($terms[$tid])) { | 1187 | if (!isset($terms[$tid])) { | |
| 1226 | $terms[$tid] = db_fetch_object(db_query('SELECT * FROM {term_data} WHERE tid = %d', $tid)); | 1188 | $terms[$tid] = db_fetch_object(db_query('SELECT * FROM {term_data} WHERE tid = %d', $tid)); | |
| -+ | 1189 | if (function_exists('to')) $terms[$tid] = to('taxonomy_term', $tid, $terms[$tid]); | ||
| 1227 | } | = | 1190 | } |
| 1228 | 1191 | |||
| 1229 | return $terms[$tid]; | 1192 | return $terms[$tid]; | |
| 1230 | } | 1193 | } | |
| 1231 | 1194 | |||
| 1232 | function _taxonomy_term_select($title, $name, $value, $vocabulary_id, $description, $multiple, $blank, $exclude = array()) { | 1195 | function _taxonomy_term_select($title, $name, $value, $vocabulary_id, $description, $multiple, $blank, $exclude = array()) { | |
| 1424 | if ($terms['tids']) { | = | 1387 | if ($terms['tids']) { |
| 1425 | $placeholders = implode(',', array_fill(0, count($terms['tids']), '%d')); | 1388 | $placeholders = implode(',', array_fill(0, count($terms['tids']), '%d')); | |
| 1426 | $result = db_query(db_rewrite_sql('SELECT t.tid, t.name FROM {term_data} t WHERE t.tid IN ('. $placeholders .')', 't', 'tid'), $terms['tids']); | 1389 | $result = db_query(db_rewrite_sql('SELECT t.tid, t.name FROM {term_data} t WHERE t.tid IN ('. $placeholders .')', 't', 'tid'), $terms['tids']); | |
| 1427 | $tids = array(); // we rebuild the $tids-array so it only contains terms the user has access to. | 1390 | $tids = array(); // we rebuild the $tids-array so it only contains terms the user has access to. | |
| 1428 | $names = array(); | 1391 | $names = array(); | |
| 1429 | while ($term = db_fetch_object($result)) { | 1392 | while ($term = db_fetch_object($result)) { | |
| 1430 | // Translatable support. | <> | ||
| 1431 | if (function_exists('tobject')) { | |||
| 1432 | $term = tobject('taxonomy_term', $term->tid, $term); | 1393 | if(function_exists('to')) $term=to('taxonomy_term', $term->tid, $term); | |
| 1433 | } | |||
| 1434 | $tids[] = $term->tid; | = | 1394 | $tids[] = $term->tid; |
| 1435 | $names[] = $term->name; | 1395 | $names[] = $term->name; | |
| 1436 | } | 1396 | } | |
| 1437 | 1397 | |||
| 1438 | if ($names) { | 1398 | if ($names) { | |
| 1439 | $title = check_plain(implode(', ', $names)); | 1399 | $title = check_plain(implode(', ', $names)); | |
| 1556 | $result = db_query_range(db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t WHERE t.vid = %d AND LOWER(t.name) LIKE LOWER('%%%s%%')", 't', 'tid'), $vid, $last_string, 0, 10); | = | 1516 | $result = db_query_range(db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t WHERE t.vid = %d AND LOWER(t.name) LIKE LOWER('%%%s%%')", 't', 'tid'), $vid, $last_string, 0, 10); |
| 1557 | 1517 | |||
| 1558 | $prefix = count($array) ? implode(', ', $array) .', ' : ''; | 1518 | $prefix = count($array) ? implode(', ', $array) .', ' : ''; | |
| 1559 | 1519 | |||
| 1560 | $matches = array(); | 1520 | $matches = array(); | |
| 1561 | while ($tag = db_fetch_object($result)) { | 1521 | while ($tag = db_fetch_object($result)) { | |
| 1562 | // Translatable support. | <> | ||
| 1563 | if (function_exists('tobject')) { | |||
| 1564 | $tag = tobject('taxonomy_term', $tag->tid, $tag); | 1522 | if(function_exists('to')) $tag=to('taxonomy_term', $tag->tid, $tag); | |
| 1565 | } | |||
| 1566 | $n = $tag->name; | = | 1523 | $n = $tag->name; |
| 1567 | // Commas and quotes in terms are special cases, so encode 'em. | 1524 | // Commas and quotes in terms are special cases, so encode 'em. | |
| 1568 | if (strpos($tag->name, ',') !== FALSE || strpos($tag->name, '"') !== FALSE) { | 1525 | if (strpos($tag->name, ',') !== FALSE || strpos($tag->name, '"') !== FALSE) { | |
| 1569 | $n = '"'. str_replace('"', '""', $tag->name) .'"'; | 1526 | $n = '"'. str_replace('"', '""', $tag->name) .'"'; | |
| 1570 | } | 1527 | } | |
| 1571 | $matches[$prefix . $n] = check_plain($tag->name); | 1528 | $matches[$prefix . $n] = check_plain($tag->name); | |
| 1572 | } | 1529 | } | |
| 1573 | print drupal_to_js($matches); | 1530 | print drupal_to_js($matches); | |
| 1574 | exit(); | 1531 | exit(); | |
| 1575 | } | 1532 | } | |
| 1576 | } | 1533 | } | |