Commit f9f3c621 authored by merlinofchaos's avatar merlinofchaos

Miscellaneous cleanup; ensure relationship safety for some formerly hardcoded/poorly coded items.

parent 4191b1df
......@@ -1272,6 +1272,9 @@ function views_ui_edit_display_form_submit($form, &$form_state) {
views_ui_cache_set($form_state['view']);
// @todo: Need a safe function to use for drupal_set_message in an ajax environ.
// This function would check $form_state for the ajax flag and, if set, simply
// discard the message. That way we could set some success messages for the
// non-jsy types here.
$form_state['redirect'] = 'admin/build/views/edit/' . $form_state['view']->name;
}
......
......@@ -1354,7 +1354,6 @@ class views_handler_filter_boolean_operator extends views_handler_filter {
}
function query() {
// @todo this should actually reverse the operator so it can compare against 0.
$this->ensure_my_table();
$this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field " . (empty($this->value) ? '=' : '<>') . " 0");
}
......@@ -1903,14 +1902,21 @@ class views_handler_argument_formula extends views_handler_argument {
}
}
function get_formula() {
return str_replace('***table***', $this->table_alias, $this->formula);
}
/**
* Build the summary query based on a formula
*/
function summary_query() {
$this->ensure_my_table();
// Now that our table is secure, get our formula.
$formula = $this->get_formula();
// Add the field.
$this->base_alias = $this->name_alias = $this->query->add_field(NULL, $this->formula, $this->field);
$this->query->set_count_field(NULL, $this->formula, $this->field);
$this->base_alias = $this->name_alias = $this->query->add_field(NULL, $formula, $this->field);
$this->query->set_count_field(NULL, $formula, $this->field);
return $this->summary_basics(FALSE);
}
......@@ -1920,7 +1926,10 @@ class views_handler_argument_formula extends views_handler_argument {
*/
function query() {
$this->ensure_my_table();
$this->query->add_where(0, "$this->formula = '%s'", $this->argument);
// Now that our table is secure, get our formula.
$formula = $this->get_formula();
$this->query->add_where(0, "$formula = '%s'", $this->argument);
}
}
......
......@@ -932,11 +932,8 @@ class views_plugin_display extends views_object {
function render_feed_icon() { }
/**
* Render the view's title for display
* @todo Necessary? Hm.
* Render a text area, using hte proper format.
*/
function render_title() { }
function render_textarea($area) {
$value = $this->get_option($area);
if ($value) {
......
......@@ -79,8 +79,6 @@ class view extends views_db_object {
/**
* Set the page size for ranged or pager queries
*
* @todo move all pager properties into a pager object
*/
function set_items_per_page($items_per_page) {
$this->pager['items_per_page'] = $items_per_page;
......@@ -314,6 +312,7 @@ class view extends views_db_object {
foreach ($this->argument as $id => $arg) {
$position++;
$argument = &$this->argument[$id];
$argument['handler']->set_relationship();
if (!is_object($argument['handler'])) {
// @todo: Set some kind of warning.
......
......@@ -63,7 +63,7 @@ function comment_views_data() {
'handler' => 'views_handler_field_markup',
'format' => 'format',
),
);
);
//cid
$data['comments']['cid'] = array(
......@@ -188,16 +188,8 @@ class views_handler_field_comment extends views_handler_field {
function init(&$view, &$data) {
parent::init($view, $data);
if (isset($data->link_to_comment)) {
if ($view->base_table != 'comments') {
$this->additional_fields[] = 'cid';
$this->cid_field = 'comments_cid';
$this->nid_field = 'nid';
}
else {
$this->additional_fields[] = 'nid';
$this->cid_field = 'cid';
$this->nid_field = 'comments_nid';
}
$this->additional_fields['cid'] = 'cid';
$this->additional_fields['nid'] = 'nid';
}
}
......@@ -210,6 +202,7 @@ class views_handler_field_comment extends views_handler_field {
* Provide link-to-comment option
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['link_to_comment'] = array(
'#title' => t('Link this field to its comment'),
'#type' => 'checkbox',
......@@ -219,7 +212,7 @@ class views_handler_field_comment extends views_handler_field {
function render_link($data, $values) {
if (!empty($this->options['link_to_comment'])) {
return l($data, "node/". $values->{$this->nid_field}, array('html' => TRUE, 'fragment' => "comment-". $values->{$this->cid_field}));
return l($data, "node/". $values->{$this->aliases['nid']}, array('html' => TRUE, 'fragment' => "comment-". $values->{$this->aliases['cid']}));
}
else {
return $data;
......@@ -242,10 +235,8 @@ class views_handler_field_username_comment extends views_handler_field {
*/
function init(&$view, &$data) {
parent::init($view, $data);
if (isset($data->link_to_user)) {
$this->additional_fields[] = 'uid';
$this->additional_fields[] = 'homepage';
}
$this->additional_fields['uid'] = 'uid';
$this->additional_fields['uid'] = 'homepage';
}
function options(&$options) {
......@@ -253,7 +244,8 @@ class views_handler_field_username_comment extends views_handler_field {
$options['link_to_user'] = TRUE;
}
function options_form(&$form) {
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['link_to_user'] = array(
'#title' => t('Link this field to its user or an author\'s homepage'),
'#type' => 'checkbox',
......@@ -262,9 +254,9 @@ class views_handler_field_username_comment extends views_handler_field {
}
function render_link($data, $values) {
$account->uid = $values->comments_uid;
$account->name = $values->comments_name;
$account->homepage = $values->comments_homepage;
$account->uid = $values->{$this->aliases['uid']};
$account->name = $values->{$this->field_alias};
$account->homepage = $values->{$this->aliases['homepage']};
if (!empty($this->options['link_to_user'])) {
return theme('username', $account);
......@@ -273,7 +265,7 @@ class views_handler_field_username_comment extends views_handler_field {
return $data;
}
}
function render($values) {
return $this->render_link(check_plain($values->{$this->field_alias}), $values);
}
......
......@@ -367,13 +367,10 @@ class views_handler_argument_node_nid extends views_handler_argument {
class views_handler_argument_node_created_year extends views_handler_argument_formula {
/**
* Constructor implementation
*
* @todo node.created should instead know about table aliases otherwise this
* will explode in relationships.
*/
function construct() {
$timezone = views_get_timezone();
$this->formula = "YEAR(FROM_UNIXTIME(node.created+$timezone))";
$this->formula = "YEAR(FROM_UNIXTIME(***table***.created+$timezone))";
}
/**
......@@ -394,7 +391,7 @@ class views_handler_argument_node_created_year_month extends views_handler_argum
*/
function construct() {
$timezone = views_get_timezone();
$this->formula = "DATE_FORMAT(FROM_UNIXTIME(node.created+$timezone), '%Y%m')";
$this->formula = "DATE_FORMAT(FROM_UNIXTIME(***table***.created+$timezone), '%Y%m')";
$this->format = 'F, Y';
}
......@@ -423,7 +420,7 @@ class views_handler_argument_node_created_month extends views_handler_argument_f
*/
function construct() {
$timezone = views_get_timezone();
$this->formula = "MONTH(FROM_UNIXTIME(node.created+$timezone))";
$this->formula = "MONTH(FROM_UNIXTIME(***table***.created+$timezone))";
$this->format = 'F';
}
......
......@@ -229,10 +229,16 @@ class views_handler_field_accesslog_path extends views_handler_field {
}
}
function options(&$options) {
parent::options($options);
$options['display_as_link'] = FALSE;
}
/**
* Provide link to the page being visited.
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['display_as_link'] = array(
'#title' => t('Display as link'),
'#type' => 'checkbox',
......@@ -258,6 +264,13 @@ class views_handler_field_accesslog_path extends views_handler_field {
* @ingroup views_field_handlers
*/
class views_handler_field_uid extends views_handler_field {
function init(&$view, &$data) {
parent::init($view, $data);
if (!empty($this->options['link_to_user'])) {
$this->additional_fields['name'] = array('table' => 'users', 'field' => 'name');
}
}
function options(&$options) {
parent::options($options);
$options['link_to_user'] = TRUE;
......@@ -266,7 +279,7 @@ class views_handler_field_uid extends views_handler_field {
/**
* Provide link to node option
*/
function options_form(&$form) {
function options_form(&$form, &$form_state) {
$form['link_to_user'] = array(
'#title' => t('Link this field to its user'),
'#type' => 'checkbox',
......@@ -274,20 +287,9 @@ class views_handler_field_uid extends views_handler_field {
);
}
/**
* Called to add the field to a query.
*/
function query() {
parent::query();
if (!empty($this->options['link_to_user'])) {
$query = $this->view->query;
$query->add_field('users', 'name');
}
}
function render($values) {
if (!empty($this->options['link_to_user'])) {
$account = (object)array('uid' => $values->{$this->field_alias}, 'name' => $values->users_name);
$account = (object) array('uid' => $values->{$this->field_alias}, 'name' => $values->{$this->aliases['name']});
return theme('username', $account);
}
else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment