New module 'Views'
This commit is contained in:
parent
31c0889471
commit
740f7d7f30
353 changed files with 44217 additions and 0 deletions
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
/**
|
||||
* Argument handler to accept a language.
|
||||
*/
|
||||
class views_handler_argument_node_language extends views_handler_argument {
|
||||
function construct() {
|
||||
parent::construct('language');
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the behavior of summary_name(). Get the user friendly version
|
||||
* of the language.
|
||||
*/
|
||||
function summary_name($data) {
|
||||
return $this->node_language($data->{$this->name_alias});
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the behavior of title(). Get the user friendly version of the
|
||||
* node type.
|
||||
*/
|
||||
function title() {
|
||||
return $this->node_language($this->argument);
|
||||
}
|
||||
|
||||
function node_language($langcode) {
|
||||
$languages = locale_language_list();
|
||||
return isset($languages[$langcode]) ? $languages[$langcode] : t('Unknown language');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Provide node tnid argument handler.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Argument handler to accept a node translation id.
|
||||
*/
|
||||
class views_handler_argument_node_tnid extends views_handler_argument_numeric {
|
||||
/**
|
||||
* Override the behavior of title(). Get the title of the node.
|
||||
*/
|
||||
function title_query() {
|
||||
$titles = array();
|
||||
$placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d'));
|
||||
|
||||
$result = db_query("SELECT n.title FROM {node} n WHERE n.tnid IN ($placeholders)", $this->value);
|
||||
while ($term = db_fetch_object($result)) {
|
||||
$titles[] = check_plain($term->title);
|
||||
}
|
||||
return $titles;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Field handler to translate a language into its readable form.
|
||||
*/
|
||||
class views_handler_field_node_language extends views_handler_field_node {
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['native_language'] = array('default' => FALSE);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['native_language'] = array(
|
||||
'#title' => t('Native language'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $this->options['native_language'],
|
||||
'#description' => t('If enabled, the native name of the language will be displayed'),
|
||||
);
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
$languages = locale_language_list(empty($this->options['native_language']) ? 'name' : 'native');
|
||||
$value = isset($languages[$values->{$this->field_alias}]) ? $languages[$values->{$this->field_alias}] : '';
|
||||
return $this->render_link($value, $values);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
/**
|
||||
* Field handler to present a link node translate.
|
||||
*/
|
||||
class views_handler_field_node_link_translate extends views_handler_field_node_link {
|
||||
function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields['uid'] = 'uid';
|
||||
$this->additional_fields['type'] = 'type';
|
||||
$this->additional_fields['language'] = 'language';
|
||||
$this->additional_fields['format'] = array('table' => 'node_revisions', 'field' => 'format');
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
// ensure user has access to edit this node.
|
||||
$node = new stdClass();
|
||||
$node->nid = $values->{$this->aliases['nid']};
|
||||
$node->uid = $values->{$this->aliases['uid']};
|
||||
$node->type = $values->{$this->aliases['type']};
|
||||
$node->format = $values->{$this->aliases['format']};
|
||||
$node->language = $values->{$this->aliases['language']};
|
||||
$node->status = 1; // unpublished nodes ignore access control
|
||||
if (empty($node->language) || !translation_supported_type($node->type) || !node_access('view', $node) || !user_access('translate content')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$text = !empty($this->options['text']) ? $this->options['text'] : t('translate');
|
||||
return l($text, "node/$node->nid/translate", array('query' => drupal_get_destination()));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
/**
|
||||
* Field handler to present a link to the node.
|
||||
*/
|
||||
class views_handler_field_node_translation_link extends views_handler_field {
|
||||
function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields['nid'] = 'nid';
|
||||
$this->additional_fields['tnid'] = 'tnid';
|
||||
$this->additional_fields['title'] = 'title';
|
||||
$this->additional_fields['language'] = 'language';
|
||||
}
|
||||
|
||||
function query() {
|
||||
$this->ensure_my_table();
|
||||
$this->add_additional_fields();
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
global $language;
|
||||
$tnid = $values->{$this->aliases['tnid']};
|
||||
// Only load translations if the node isn't in the current language.
|
||||
if ($values->{$this->aliases['language']} != $language->language) {
|
||||
$translations = translation_node_get_translations($tnid);
|
||||
if (isset($translations[$language->language])) {
|
||||
$values->{$this->aliases['nid']} = $translations[$language->language]->nid;
|
||||
$values->{$this->aliases['title']} = $translations[$language->language]->title;
|
||||
}
|
||||
}
|
||||
return l($values->{$this->aliases['title']}, "node/" . $values->{$this->aliases['nid']});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
/**
|
||||
* Filter by language
|
||||
*/
|
||||
class views_handler_filter_node_language extends views_handler_filter_in_operator {
|
||||
function get_value_options() {
|
||||
if (!isset($this->value_options)) {
|
||||
$this->value_title = t('Language');
|
||||
$languages = array('***CURRENT_LANGUAGE***' => t("Current user's language"), '***DEFAULT_LANGUAGE***' => t("Default site language"), '***NO_LANGUAGE***' => t('No language'));
|
||||
$languages = array_merge($languages, locale_language_list());
|
||||
$this->value_options = $languages;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* Filter by whether the node is the original translation.
|
||||
*/
|
||||
class views_handler_filter_node_tnid extends views_handler_filter {
|
||||
function admin_summary() { }
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['operator']['default'] = 1;
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide simple boolean operator
|
||||
*/
|
||||
function operator_form(&$form, &$form_state) {
|
||||
$form['operator'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Include untranslated nodes'),
|
||||
'#default_value' => $this->operator,
|
||||
'#options' => array(
|
||||
1 => t('Yes'),
|
||||
0 => t('No'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function can_expose() { return FALSE; }
|
||||
|
||||
function query() {
|
||||
$table = $this->ensure_my_table();
|
||||
// Select for source translations (tnid = nid). Conditionally, also accept either untranslated nodes (tnid = 0).
|
||||
$this->query->add_where($this->options['group'], "$table.tnid = $table.nid" . ($this->operator ? " OR $table.tnid = 0" : ''));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
/**
|
||||
* Filter by whether the node is not the original translation.
|
||||
*/
|
||||
class views_handler_filter_node_tnid_child extends views_handler_filter {
|
||||
function admin_summary() { }
|
||||
function operator_form(&$form, &$form_state) { }
|
||||
function can_expose() { return FALSE; }
|
||||
|
||||
function query() {
|
||||
$table = $this->ensure_my_table();
|
||||
$this->query->add_where($this->options['group'], "$table.tnid <> $table.nid AND $table.tnid > 0");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Handles relationships for content translation sets and provides multiple
|
||||
* options.
|
||||
*/
|
||||
class views_handler_relationship_translation extends views_handler_relationship {
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['language'] = array('default' => 'current');
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a translation selector.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$options = array(
|
||||
'all' => t('All'),
|
||||
'current' => t('Current language'),
|
||||
'default' => t('Default language'),
|
||||
);
|
||||
$options = array_merge($options, locale_language_list());
|
||||
$form['language'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => $options,
|
||||
'#default_value' => $this->options['language'],
|
||||
'#title' => t('Translation option'),
|
||||
'#description' => t('The translation options allows you to select which translation or translations in a translation set join on. Select "Current language" or "Default language" to join on the translation in the current or default language respectively. Select a specific language to join on a translation in that language. If you select "All", each translation will create a new row, which may appear to cause duplicates.'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to implement a relationship in a query.
|
||||
*/
|
||||
function query() {
|
||||
// Figure out what base table this relationship brings to the party.
|
||||
$table_data = views_fetch_data($this->definition['base']);
|
||||
$base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field'];
|
||||
|
||||
$this->ensure_my_table();
|
||||
|
||||
$def = $this->definition;
|
||||
$def['table'] = $this->definition['base'];
|
||||
$def['field'] = $base_field;
|
||||
$def['left_table'] = $this->table_alias;
|
||||
$def['left_field'] = $this->field;
|
||||
if (!empty($this->options['required'])) {
|
||||
$def['type'] = 'INNER';
|
||||
}
|
||||
|
||||
$def['extra'] = array();
|
||||
if ($this->options['language'] != 'all') {
|
||||
switch ($this->options['language']) {
|
||||
case 'current':
|
||||
$def['extra'][] = array(
|
||||
'field' => 'language',
|
||||
'value' => '***CURRENT_LANGUAGE***',
|
||||
);
|
||||
break;
|
||||
case 'default':
|
||||
$def['extra'][] = array(
|
||||
'field' => 'language',
|
||||
'value' => '***DEFAULT_LANGUAGE***',
|
||||
);
|
||||
break;
|
||||
// Other values will be the language codes.
|
||||
default:
|
||||
$def['extra'][] = array(
|
||||
'field' => 'language',
|
||||
'value' => $this->options['language'],
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($def['join_handler']) && class_exists($def['join_handler'])) {
|
||||
$join = new $def['join_handler'];
|
||||
}
|
||||
else {
|
||||
$join = new views_join();
|
||||
}
|
||||
|
||||
$join->definition = $def;
|
||||
$join->construct();
|
||||
$join->adjusted = TRUE;
|
||||
|
||||
// use a short alias for this:
|
||||
$alias = $def['table'] . '_' . $this->table;
|
||||
|
||||
$this->alias = $this->query->add_relationship($alias, $join, $this->definition['base'], $this->relationship);
|
||||
}
|
||||
}
|
Reference in a new issue