Now all modules are in core modules folder
This commit is contained in:
parent
5ba1cdfa0b
commit
05b6a91b0c
1907 changed files with 0 additions and 0 deletions
181
modules/i18n/i18ntaxonomy/i18ntaxonomy.admin.inc
Normal file
181
modules/i18n/i18ntaxonomy/i18ntaxonomy.admin.inc
Normal file
|
@ -0,0 +1,181 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Helper functions for taxonomy administration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is the callback for taxonomy translations.
|
||||
*
|
||||
* Gets the urls:
|
||||
* admin/content/taxonomy/%taxonomy_vocabulary/translation
|
||||
* admin/content/taxonomy/i18n/term/xx
|
||||
* admin/content/taxonomy/i18n/term/new/xx
|
||||
* admin/content/taxonomy/vid/translation/op/trid
|
||||
*/
|
||||
function i18ntaxonomy_page_vocabulary($vocabulary, $op = NULL, $tid = NULL) {
|
||||
switch ($op) {
|
||||
case 'edit':
|
||||
drupal_set_title(t('Edit term translations'));
|
||||
$output = drupal_get_form('i18ntaxonomy_translation_term_form', $vocabulary->vid, $tid);
|
||||
break;
|
||||
|
||||
default:
|
||||
$output = i18ntaxonomy_translation_overview($vocabulary->vid);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces a vocabulary translation form.
|
||||
*/
|
||||
function i18ntaxonomy_translation_term_form($form_state, $vid, $trid = NULL, $edit = array()) {
|
||||
$languages = i18n_supported_languages();
|
||||
|
||||
if ($trid == 'new') {
|
||||
$translations = array();
|
||||
$form['trid'] = array(
|
||||
'#type' => 'hidden',
|
||||
'#value' => 0
|
||||
);
|
||||
}
|
||||
else {
|
||||
$form['trid'] = array(
|
||||
'#type' => 'hidden',
|
||||
'#value' => $trid
|
||||
);
|
||||
$translations = i18ntaxonomy_term_get_translations(array('trid' => $trid));
|
||||
}
|
||||
$vocabulary = taxonomy_vocabulary_load($vid);
|
||||
|
||||
// List of terms for languages.
|
||||
foreach ($languages as $lang => $langname) {
|
||||
$current = isset($translations[$lang]) ? $translations[$lang]->tid : '';
|
||||
$tree = i18ntaxonomy_get_tree($vid, $lang);
|
||||
$form[$lang] = array('#type' => 'fieldset', '#tree' => TRUE);
|
||||
$form[$lang]['tid'] = _i18ntaxonomy_term_select($langname, $current, $tree);
|
||||
$form[$lang]['old'] = array(
|
||||
'#type' => 'hidden',
|
||||
'#value' => $current
|
||||
);
|
||||
}
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save')
|
||||
);
|
||||
if ($trid != 'new') {
|
||||
$form['delete'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Delete')
|
||||
);
|
||||
}
|
||||
$form['destination'] = array(
|
||||
'#type' => 'hidden',
|
||||
'#value' => 'admin/content/taxonomy/'. arg(3) .'/translation'
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form callback: Process vocabulary translation form.
|
||||
*/
|
||||
function i18ntaxonomy_translation_term_form_submit($form, &$form_state) {
|
||||
switch ($form_state['values']['op']) {
|
||||
case t('Save'):
|
||||
i18ntaxonomy_translation_save($form_state['values'], $form_state['values']['trid']);
|
||||
drupal_set_message(t('Term translations have been updated.'));
|
||||
break;
|
||||
|
||||
case t('Delete'):
|
||||
// Delete old translations for this trid.
|
||||
db_query("UPDATE {term_data} SET trid = 0 WHERE trid = %d", $form_state['values']['trid']);
|
||||
drupal_set_message(t('The term translation has been deleted.'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save taxonomy term translations.
|
||||
*
|
||||
* @param $terms
|
||||
* Array of terms indexed by language.
|
||||
* @param $trid
|
||||
* Optional translation set id.
|
||||
*/
|
||||
function i18ntaxonomy_translation_save($terms, $trid = 0) {
|
||||
// Delete old translations for this trid.
|
||||
if ($trid) {
|
||||
db_query("UPDATE {term_data} SET trid = 0 WHERE trid = %d", $trid);
|
||||
}
|
||||
// Now pick up all the tids in an array.
|
||||
$translations = array();
|
||||
foreach (i18n_supported_languages() as $lang => $name) {
|
||||
if (isset($terms[$lang]) && ($term = (array)$terms[$lang]) && $tid = $term['tid']) {
|
||||
$translations[$lang] = $tid;
|
||||
}
|
||||
}
|
||||
// Now set a translation set with all these terms. We need some table locking to avoid race conditions.
|
||||
// when other translations created simulaneously. @TODO Find a better way.
|
||||
if (count($translations)) {
|
||||
db_lock_table('term_data');
|
||||
$trid = (is_numeric($trid) && $trid) ? $trid : i18ntaxonomy_next_trid();
|
||||
$params = array_merge(array($trid), $translations);
|
||||
db_query('UPDATE {term_data} SET trid = %d WHERE tid IN('. db_placeholders($translations) .')', $params);
|
||||
db_unlock_tables();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next free trid.
|
||||
*/
|
||||
function i18ntaxonomy_next_trid() {
|
||||
$current = (int)db_result(db_query('SELECT max(trid) FROM {term_data}'));
|
||||
return $current + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a tabular listing of translations for vocabularies.
|
||||
*/
|
||||
function i18ntaxonomy_translation_overview($vid) {
|
||||
$vocabulary = taxonomy_vocabulary_load($vid);
|
||||
drupal_set_title(check_plain($vocabulary->name));
|
||||
$output = '';
|
||||
|
||||
$languages = i18n_supported_languages();
|
||||
$header = array_merge($languages, array(t('Operations')));
|
||||
$links = array();
|
||||
$types = array();
|
||||
// Get terms/translations for this vocab.
|
||||
$result = db_query('SELECT * FROM {term_data} t WHERE vid = %d', $vocabulary->vid);
|
||||
$terms = $messages = array();
|
||||
while ($term = db_fetch_object($result)) {
|
||||
if ($term->trid && $term->language) {
|
||||
$terms[$term->trid][$term->language] = $term;
|
||||
}
|
||||
}
|
||||
// Reorder data for rows and languages.
|
||||
$rows = array();
|
||||
foreach ($terms as $trid => $terms) {
|
||||
$thisrow = array();
|
||||
foreach ($languages as $lang => $name) {
|
||||
if (array_key_exists($lang, $terms)) {
|
||||
$thisrow[] = l($terms[$lang]->name, 'taxonomy/term/'. $terms[$lang]->tid);
|
||||
}
|
||||
else {
|
||||
$thisrow[] = '--';
|
||||
}
|
||||
}
|
||||
$thisrow[] = l(t('edit'), "admin/content/taxonomy/$vid/translation/edit/$trid");
|
||||
$rows[] = $thisrow;
|
||||
}
|
||||
if ($rows) {
|
||||
$output .= theme('table', $header, $rows);
|
||||
}
|
||||
else {
|
||||
$messages[] = t('No translations defined for this vocabulary.');
|
||||
}
|
||||
$messages[]= l(t('Create new translation'), "admin/content/taxonomy/$vid/translation/edit/new");
|
||||
$output .= theme('item_list', $messages);
|
||||
return $output;
|
||||
}
|
14
modules/i18n/i18ntaxonomy/i18ntaxonomy.info
Normal file
14
modules/i18n/i18ntaxonomy/i18ntaxonomy.info
Normal file
|
@ -0,0 +1,14 @@
|
|||
name = Taxonomy translation
|
||||
description = Enables multilingual taxonomy.
|
||||
dependencies[] = i18n
|
||||
dependencies[] = taxonomy
|
||||
dependencies[] = i18nstrings
|
||||
package = Multilanguage
|
||||
core = 6.x
|
||||
|
||||
; Information added by drupal.org packaging script on 2011-10-11
|
||||
version = "6.x-1.10"
|
||||
core = "6.x"
|
||||
project = "i18n"
|
||||
datestamp = "1318336004"
|
||||
|
94
modules/i18n/i18ntaxonomy/i18ntaxonomy.install
Normal file
94
modules/i18n/i18ntaxonomy/i18ntaxonomy.install
Normal file
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Installation file for i18ntaxonomy module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Set language field in its own table.
|
||||
* Do not drop node.language now, just in case.
|
||||
* TO-DO: Drop old tables, fields
|
||||
*/
|
||||
function i18ntaxonomy_install() {
|
||||
$ret = array();
|
||||
db_add_field($ret, 'vocabulary', 'language', array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''));
|
||||
db_add_field($ret, 'term_data', 'language', array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''));
|
||||
db_add_field($ret, 'term_data', 'trid', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
|
||||
|
||||
// Set module weight for it to run after core modules, but before views.
|
||||
db_query("UPDATE {system} SET weight = 5 WHERE name = 'i18ntaxonomy' AND type = 'module'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_uninstall().
|
||||
*/
|
||||
function i18ntaxonomy_uninstall() {
|
||||
$ret = array();
|
||||
db_drop_field($ret, 'vocabulary', 'language');
|
||||
db_drop_field($ret, 'term_data', 'language');
|
||||
db_drop_field($ret, 'term_data', 'trid');
|
||||
|
||||
variable_del('i18ntaxonomy_vocabulary');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_schema_alter().
|
||||
*/
|
||||
function i18ntaxonomy_schema_alter(&$schema) {
|
||||
$schema['vocabulary']['fields']['language'] = array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => '');
|
||||
$schema['term_data']['fields']['language'] = array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => '');
|
||||
$schema['term_data']['fields']['trid'] = array('type' => 'int', 'not null' => TRUE, 'default' => 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_enable().
|
||||
*
|
||||
* Just add strings to locale tables.
|
||||
*/
|
||||
function i18ntaxonomy_enable() {
|
||||
drupal_load('module', 'i18nstrings');
|
||||
i18ntaxonomy_locale_refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Drupal 6 update.
|
||||
*
|
||||
* Move i18n vocabulary options to new variables.
|
||||
*/
|
||||
function i18ntaxonomy_update_1() {
|
||||
$items = array();
|
||||
$options = variable_get('i18ntaxonomy_vocabulary', array());
|
||||
$translate = variable_get('i18ntaxonomy_vocabularies', array());
|
||||
foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
|
||||
if ($vocabulary->language) {
|
||||
$options[$vid] = I18N_TAXONOMY_LANGUAGE;
|
||||
}
|
||||
elseif (isset($translate[$vid]) && $translate[$vid]) {
|
||||
$options[$vid] = I18N_TAXONOMY_LOCALIZE;
|
||||
}
|
||||
else {
|
||||
// Search for terms with language.
|
||||
$count = db_result(db_query("SELECT COUNT(language) FROM {term_data} WHERE vid = %d AND NOT language = ''", $vid));
|
||||
if ($count) {
|
||||
$options[$vid] = I18N_TAXONOMY_TRANSLATE;
|
||||
}
|
||||
elseif (!isset($options[$vid])) {
|
||||
$options[$vid] = I18N_TAXONOMY_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
variable_set('i18ntaxonomy_vocabulary', $options);
|
||||
drupal_set_message(t('The multilingual vocabulary settings have been updated. Please review them in the <a href="@taxonomy_admin page">taxonomy administration</a>.', array('@taxonomy_admin' => url('admin/content/taxonomy'))));
|
||||
// @ TODO Update strings in localization tables.
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set module weight for it to run after core modules, but before views.
|
||||
*/
|
||||
function i18ntaxonomy_update_6002() {
|
||||
$items = array();
|
||||
$items[] = update_sql("UPDATE {system} SET weight = 5 WHERE name = 'i18ntaxonomy' AND type = 'module'");
|
||||
return $items;
|
||||
}
|
16
modules/i18n/i18ntaxonomy/i18ntaxonomy.js
Normal file
16
modules/i18n/i18ntaxonomy/i18ntaxonomy.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
Drupal.behaviors.i18ntaxonomy = function (context) {
|
||||
if (Drupal.settings && Drupal.settings.i18ntaxonomy_vocabulary_form) {
|
||||
$('form#taxonomy-form-vocabulary input.form-radio', context).filter('[name=i18nmode]').click(function () {
|
||||
var languageSelect = $('form#taxonomy-form-vocabulary select#edit-language', context);
|
||||
if ($(this).val() == Drupal.settings.i18ntaxonomy_vocabulary_form.I18N_TAXONOMY_LANGUAGE) {
|
||||
// Make sure language form is enabled when I18N_TAXONOMY_LANGUAGE is clicked
|
||||
languageSelect.removeAttr("disabled");
|
||||
}
|
||||
else {
|
||||
// Make sure language form is disabled otherwise and set to blank.
|
||||
languageSelect.val("");
|
||||
languageSelect.attr("disabled", "disabled");
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
1106
modules/i18n/i18ntaxonomy/i18ntaxonomy.module
Normal file
1106
modules/i18n/i18ntaxonomy/i18ntaxonomy.module
Normal file
File diff suppressed because it is too large
Load diff
150
modules/i18n/i18ntaxonomy/i18ntaxonomy.pages.inc
Normal file
150
modules/i18n/i18ntaxonomy/i18ntaxonomy.pages.inc
Normal file
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Page callbacks for the taxonomy module, i18n remake.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Menu callback; displays all nodes associated with a term.
|
||||
*/
|
||||
function i18ntaxonomy_term_page($str_tids = '', $depth = 0, $op = 'page') {
|
||||
$terms = taxonomy_terms_parse_string($str_tids);
|
||||
if ($terms['operator'] != 'and' && $terms['operator'] != 'or') {
|
||||
drupal_not_found();
|
||||
}
|
||||
|
||||
if ($terms['tids']) {
|
||||
// We need vid here, too.
|
||||
$result = db_query(db_rewrite_sql('SELECT t.tid, t.vid, t.name FROM {term_data} t WHERE t.tid IN ('. db_placeholders($terms['tids']) .')', 't', 'tid'), $terms['tids']);
|
||||
$tids = array(); // we rebuild the $tids-array so it only contains terms the user has access to.
|
||||
$names = array();
|
||||
while ($term = db_fetch_object($result)) {
|
||||
$tids[] = $term->tid;
|
||||
$names[] = i18ntaxonomy_translate_term_name($term);
|
||||
}
|
||||
|
||||
if ($names) {
|
||||
$title = check_plain(implode(', ', $names));
|
||||
drupal_set_title($title);
|
||||
|
||||
switch ($op) {
|
||||
case 'page':
|
||||
// Build breadcrumb based on first hierarchy of first term:
|
||||
$current->tid = $tids[0];
|
||||
$breadcrumb = array();
|
||||
while ($parents = taxonomy_get_parents($current->tid)) {
|
||||
$current = array_shift($parents);
|
||||
$breadcrumb[] = l($current->name, 'taxonomy/term/'. $current->tid);
|
||||
}
|
||||
$breadcrumb[] = l(t('Home'), NULL);
|
||||
$breadcrumb = array_reverse($breadcrumb);
|
||||
drupal_set_breadcrumb($breadcrumb);
|
||||
|
||||
$output = theme('i18ntaxonomy_term_page', $tids, taxonomy_select_nodes($tids, $terms['operator'], $depth, TRUE));
|
||||
drupal_add_feed(url('taxonomy/term/'. $str_tids .'/'. $depth .'/feed'), 'RSS - '. $title);
|
||||
return $output;
|
||||
break;
|
||||
|
||||
case 'feed':
|
||||
$channel['link'] = url('taxonomy/term/'. $str_tids .'/'. $depth, array('absolute' => TRUE));
|
||||
$channel['title'] = variable_get('site_name', 'Drupal') .' - '. $title;
|
||||
|
||||
// Only display the description if we have a single term, to avoid clutter and confusion.
|
||||
if (count($tids) == 1) {
|
||||
$terms = array(taxonomy_get_term($tids[0]));
|
||||
$terms = i18ntaxonomy_localize_terms($terms, array('description'));
|
||||
$terms['operator'] = 'or';
|
||||
// HTML will be removed from feed description, so no need to filter here.
|
||||
$channel['description'] = $terms[0]->description;
|
||||
}
|
||||
|
||||
$result = taxonomy_select_nodes($tids, $terms['operator'], $depth, FALSE);
|
||||
$items = array();
|
||||
while ($row = db_fetch_object($result)) {
|
||||
$items[] = $row->nid;
|
||||
}
|
||||
|
||||
node_feed($items, $channel);
|
||||
break;
|
||||
|
||||
default:
|
||||
drupal_not_found();
|
||||
}
|
||||
}
|
||||
else {
|
||||
drupal_not_found();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a taxonomy term page HTML output.
|
||||
*
|
||||
* @param $tids
|
||||
* An array of term ids.
|
||||
* @param $result
|
||||
* A pager_query() result, such as that performed by taxonomy_select_nodes().
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_i18ntaxonomy_term_page($tids, $result) {
|
||||
drupal_add_css(drupal_get_path('module', 'taxonomy') .'/taxonomy.css');
|
||||
|
||||
$output = '';
|
||||
|
||||
// Only display the description if we have a single term, to avoid clutter and confusion.
|
||||
if (count($tids) == 1) {
|
||||
$term = taxonomy_get_term($tids[0]);
|
||||
if (i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) {
|
||||
$description = i18nstrings("taxonomy:term:$term->tid:description", $term->description);
|
||||
}
|
||||
else {
|
||||
$description = $term->description;
|
||||
}
|
||||
|
||||
// Check that a description is set.
|
||||
if (!empty($description)) {
|
||||
$output .= '<div class="taxonomy-term-description">';
|
||||
$output .= filter_xss_admin($description);
|
||||
$output .= '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
$output .= taxonomy_render_nodes($result);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for autocompletion.
|
||||
*
|
||||
* @ TODO Optimized localization. We cannot just i18nstrings() huge lists of terms.
|
||||
*/
|
||||
function i18ntaxonomy_autocomplete($vid, $string = '') {
|
||||
// The user enters a comma-separated list of tags. We only autocomplete the last tag.
|
||||
$array = drupal_explode_tags($string);
|
||||
|
||||
// Is this vocabulary localizable?
|
||||
$localizable = i18ntaxonomy_vocabulary($vid) == I18N_TAXONOMY_LOCALIZE;
|
||||
|
||||
// Fetch last tag.
|
||||
$last_string = trim(array_pop($array));
|
||||
$matches = array();
|
||||
if ($last_string != '') {
|
||||
$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);
|
||||
|
||||
$prefix = count($array) ? implode(', ', $array) .', ' : '';
|
||||
|
||||
while ($tag = db_fetch_object($result)) {
|
||||
$n = $tag->name;
|
||||
// Commas and quotes in terms are special cases, so encode 'em.
|
||||
if (strpos($tag->name, ',') !== FALSE || strpos($tag->name, '"') !== FALSE) {
|
||||
$n = '"'. str_replace('"', '""', $tag->name) .'"';
|
||||
}
|
||||
$matches[$prefix . $n] = check_plain($tag->name);
|
||||
}
|
||||
}
|
||||
|
||||
drupal_json($matches);
|
||||
}
|
Reference in a new issue