FINAL suepr merge step : added all modules to this super repos

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-19 16:46:59 +02:00
7585 changed files with 1723356 additions and 18 deletions

View File

@@ -0,0 +1,217 @@
<?php
/**
* @file
* Hooks for integrating Views and User Stats.
*/
/**
* Implements hook_views_data().
*/
function user_stats_views_data() {
// User Statistics table.
$data['user_stats_values']['table']['group'] = t('User Stats');
$data['user_stats_values']['table']['join'] = array(
'users' => array(
'left_field' => 'uid',
'field' => 'uid',
),
);
// Name field.
$data['user_stats_values']['name'] = array(
'title' => t('Statistic name'),
'help' => t('The unique statistic name'),
'field' => array(
'handler' => 'views_handler_field',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'views_handler_argument_string',
),
);
// Value field.
$data['user_stats_values']['value'] = array(
'title' => t('Value'),
'help' => t('Statistic value'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
);
// IP address table definition.
$data['user_stats_ips']['table']['group'] = t('IP address');
$data['user_stats_ips']['table']['join'] = array(
'users' => array(
'left_field' => 'uid',
'field' => 'uid',
),
);
$data['user_stats_ips']['table']['base'] = array(
'field' => 'iid',
'title' => t('IP addresses'),
'help' => t('Users and their IP addresses'),
);
// IID field.
$data['user_stats_ips']['iid'] = array(
'title' => t('IID'),
'help' => t('The unique ID of the IP address record'),
'field' => array(
'handler' => 'views_handler_numeric',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
);
// IP address field.
$data['user_stats_ips']['ip_address'] = array(
'title' => t('IP'),
'help' => t('IP address'),
'field' => array(
'handler' => 'views_handler_field',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
// First seen timestamp field.
$data['user_stats_ips']['first_seen_timestamp'] = array(
'title' => t('First seen'),
'help' => t('First seen timestamp'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
'argument' => array(
'handler' => 'views_handler_argument_date',
),
);
// Number of users associated with a given IP address (virtual field).
$data['user_stats_ips']['ip_user_count'] = array(
'title' => t('IP users count'),
'help' => t('Number of users used by an IP address'),
'field' => array(
'handler' => 'views_handler_field_ip_user_count',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_ip_user_count',
),
);
// Number of ip addresses associated with a given user (virtual field).
$data['user_stats_ips']['user_ip_count'] = array(
'title' => t('User IP count'),
'help' => t('Number of IPs used by a user'),
'field' => array(
'handler' => 'views_handler_field_user_ip_count',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_user_ip_count',
),
);
// Is user online boolean (virtual field).
$data['users']['is_online'] = array(
'title' => t('Is online'),
'help' => t('Shows whether the user is online'),
'field' => array(
'handler' => 'views_handler_field_is_online',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_is_online',
),
'filter' => array(
'handler' => 'views_handler_filter_is_online',
'label' => t('Online'),
),
);
// Un-themed version of the user's picture.
$data['users']['picture_bare'] = array(
'title' => t('Bare user picture'),
'help' => t('Normally user pictures are show with theming around them, which is crufty and may have CSS attached not appropriate for a view. This skips the theming cruft and just prints the bare img tag'),
'real field' => 'picture',
'field' => array(
'handler' => 'views_handler_field_user_picture_bare',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator_string',
'label' => t('Has Avatar'),
'type' => 'yes-no',
),
);
return $data;
}
/**
* Implements hook_views_handlers().
*/
function user_stats_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'user_stats') . '/views',
),
'handlers' => array(
'views_handler_field_ip_user_count' => array(
'parent' => 'views_handler_field_numeric',
),
'views_handler_sort_ip_user_count' => array(
'parent' => 'views_handler_sort',
),
'views_handler_field_user_ip_count' => array(
'parent' => 'views_handler_field_numeric',
),
'views_handler_sort_user_ip_count' => array(
'parent' => 'views_handler_sort',
),
'views_handler_field_is_online' => array(
'parent' => 'views_handler_field_boolean',
),
'views_handler_sort_is_online' => array(
'parent' => 'views_handler_sort',
),
'views_handler_filter_is_online' => array(
'parent' => 'views_handler_filter_boolean_operator',
),
'views_handler_field_user_picture_bare' => array(
'parent' => 'views_handler_field_user_picture',
),
),
);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,20 @@
<?php
/**
* @file
* User Stats user count by IP address.
*/
/**
* Users by IP address count handler.
*/
class views_handler_field_ip_user_count extends views_handler_field_numeric {
function query() {
$this->table_alias = $this->ensure_my_table();
// We need another subquery here to extract DISTINCT values
$sql = "SELECT COUNT(usi.uid)
FROM (SELECT DISTINCT(uid), ip_address FROM {user_stats_ips}) usi
WHERE usi.ip_address = " . check_plain($this->table_alias) . ".ip_address";
$this->field_alias = $this->query->add_field(NULL, "(" . $sql . ")", $this->table_alias . '_' . $this->field);
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* @file
* User Stats is user online handler.
*/
/**
* Is user online handler.
*/
class views_handler_field_is_online extends views_handler_field_boolean {
function query() {
$this->ensure_my_table();
// Currently Views has no support for/information on the {sessions} table.
$join = new views_join;
$join->construct('sessions', $this->table_alias, 'uid', 'uid', array());
$session = $this->query->ensure_table('sessions', NULL, $join);
// We use an IF for MySQL/PostgreSQL compatibility. Otherwise PostgreSQL
// would return 'f' and 't'.
$sql_if_part = "IF((" . REQUEST_TIME . " - $session.timestamp) < " . variable_get('user_block_seconds_online', 900) . ", 1, 0)";
// We liberally steal from views_handler_sort_formula and
// views_handler_filter_search here.
$this->field_alias = $this->query->add_field(NULL, $sql_if_part, $this->table_alias . '_' . $this->field, array('function' => 'max'));
}
function option_definition() {
$options = parent::option_definition();
$options['type'] = array('default' => 'online-offline');
return $options;
}
/**
* Add the online-offline type to options form.
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['type']['#options']['online-offline'] = t('Online/Offline');
}
function render($values) {
$value = $values->{$this->field_alias};
if (!empty($this->options['not'])) {
$value = !$value;
}
if ($this->options['type'] == 'online-offline') {
return $value ? '<span class="user-stat-online">' . t('Online') . '</span>' : '<span class="user-stat-offline">' . t('Offline') . '</span>';
}
else {
return parent::render($values);
}
}
}

View File

@@ -0,0 +1,20 @@
<?php
/**
* @file
* User Stats IP address count by user.
*/
/**
* IP addresses by user count handler.
*/
class views_handler_field_user_ip_count extends views_handler_field_numeric {
function query() {
$this->table_alias = $this->ensure_my_table();
// We need another subquery here to extract DISTINCT values
$sql = "SELECT COUNT(usi.ip_address)
FROM (SELECT DISTINCT(uid), ip_address FROM {user_stats_ips}) usi
WHERE usi.uid = " . check_plain($this->table_alias) . ".uid";
$this->field_alias = $this->query->add_field(NULL, "(" . $sql . ")", $this->table_alias . '_' . $this->field);
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* @file
* User Stats non-themed user picture.
*/
/**
* Bare user picture handler.
*/
class views_handler_field_user_picture_bare extends views_handler_field_user_picture {
function render($values) {
if (module_exists('image')) {
$output = '';
// When an image style is not defined, use the image style from the account settings.
$style_name = $this->options['image_style'];
if (empty($style_name)) {
$style_name = variable_get('user_picture_style', '');
}
// Load the picture file and get the uri.
if ($user_picture_fid = $this->get_value($values)) {
$user_picture = file_load($user_picture_fid);
$user_picture_filepath = $user_picture->uri;
} else {
$user_picture_filepath = variable_get('user_picture_default', '');
}
// Return empty string when either style_name or picture are unavailable.
if (empty($style_name) || empty($user_picture_filepath)) {
return $output;
}
// Use the user name for alt attribute.
$user_name = $values->{$this->aliases['name']} ? $values->{$this->aliases['name']} : variable_get('anonymous', t('Anonymous'));
$alt = t("@user's picture", array('@user' => $user_name));
// Output the picture with image_style.
if (file_valid_uri($user_picture_filepath)) {
$output = theme('image_style', array('style_name' => $style_name,'path' => $user_picture_filepath, 'alt' => $alt));
}
// Wrap the picture in a link to the user picture.
if ($this->options['link_photo_to_profile'] && user_access('access user profiles')) {
$uid = $this->get_value($values, 'uid');
$output = l($output, "user/$uid", array('html' => TRUE));
}
return $output;
}
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* @file
* User Stats is user online sort handler.
*/
/**
* Is user online sort handler.
*/
class views_handler_filter_is_online extends views_handler_filter_boolean_operator {
function query() {
$this->ensure_my_table();
$join = new views_join;
$join->construct('sessions', $this->table_alias, 'uid', 'uid', array());
$session = $this->query->ensure_table('sessions', NULL, $join);
// We have to make sure this field is in the query, and Views knows to
// create GROUP BY's.
$sql_if_part = "IF((" . REQUEST_TIME . " - $session.timestamp) < " . variable_get('user_block_seconds_online', 900) . ", 1, 0)";
$sql = $sql_if_part . " = :value";
$this->query->add_where_expression($this->options['group'], $sql, array(':value' => $this->value));
}
/**
* Override default True/False options.
*/
function get_value_options() {
$this->value_options = array(
1 => t('Online'),
0 => t('Offline'),
);
}
}

View File

@@ -0,0 +1,20 @@
<?php
/**
* @file
* User Stats user count by IP address.
*/
/**
* Users by IP address count handler.
*/
class views_handler_sort_ip_user_count extends views_handler_sort {
function query() {
$this->table_alias = $this->ensure_my_table();
// We need another subquery here to extract DISTINCT values
$sql = "SELECT COUNT(usi.uid)
FROM (SELECT DISTINCT(uid), ip_address FROM {user_stats_ips}) usi
WHERE usi.ip_address = " . check_plain($this->table_alias) . ".ip_address";
$this->field_alias = $this->query->add_orderby(NULL, "(" . $sql . ")", $this->options['order'], $this->table_alias . '_' . $this->field);
}
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* @file
* User Stats is user online sort handler.
*/
/**
* Is user online sort handler.
*/
class views_handler_sort_is_online extends views_handler_sort {
function query() {
$this->ensure_my_table();
// Currently Views has no support for/information on the {sessions} table.
$join = new views_join;
$join->construct('sessions', $this->table_alias, 'uid', 'uid', array());
$session = $this->query->ensure_table('sessions', NULL, $join);
// We use an IF for MySQL/PostgreSQL compatibility. Otherwise PostgreSQL
// would return 'f' and 't'.
$sql_if_part = "IF((" . REQUEST_TIME . " - $session.timestamp) < " . variable_get('user_block_seconds_online', 900) . ", 1, 0)";
$this->query->add_orderby(NULL, $sql_if_part, $this->options['order'], $this->table_alias . '_' . $this->field, array('function' => 'max'));
}
}

View File

@@ -0,0 +1,20 @@
<?php
/**
* @file
* User Stats IP address count by user.
*/
/**
* IP addresses by user count handler.
*/
class views_handler_sort_user_ip_count extends views_handler_sort {
function query() {
$this->ensure_my_table();
// We need another subquery here to extract DISTINCT values
$sql = "SELECT COUNT(usi.ip_address)
FROM (SELECT DISTINCT(uid), ip_address FROM {user_stats_ips}) usi
WHERE usi.uid = " . check_plain($this->table_alias) . ".uid";
$this->field_alias = $this->query->add_orderby(NULL, "(" . $sql . ")", $this->options['order'], $this->table_alias . '_' . $this->field);
}
}