From 0a70aea98d9fc5d437a6a882e1fbdecbd1b49f6e Mon Sep 17 00:00:00 2001 From: Ruth Ivimey-Cook Date: Mon, 5 Dec 2016 17:57:41 +0000 Subject: [PATCH] Small code improvements. # Conflicts: # includes/view.inc --- includes/base.inc | 16 ++++++++++------ includes/view.inc | 16 +++++++++------- plugins/views_plugin_display.inc | 23 ++++++++++++++--------- plugins/views_plugin_query.inc | 7 ++++++- 4 files changed, 39 insertions(+), 23 deletions(-) diff --git a/includes/base.inc b/includes/base.inc index 2d2ceb56..c1bb48d0 100644 --- a/includes/base.inc +++ b/includes/base.inc @@ -117,7 +117,7 @@ class views_object { $localization_keys = $this->localization_keys; } // but plugins don't because there isn't a common init() these days. - else if (!empty($this->is_plugin) && empty($localization_keys)) { + elseif (!empty($this->is_plugin) && empty($localization_keys)) { if ($this->plugin_type != 'display') { $localization_keys = array($this->view->current_display); $localization_keys[] = $this->plugin_type; @@ -143,8 +143,12 @@ class views_object { $storage[$key] = $value; continue; } - - $this->unpack_options($storage[$key], $value, isset($definition[$key]['contains']) ? $definition[$key]['contains'] : array(), $all, FALSE, array_merge($localization_keys, array($key))); + $contains = array(); + if (isset($definition[$key]['contains'])) { + $contains = $definition[$key]['contains']; + } + $merged_keys = array_merge($localization_keys, array($key)); + $this->unpack_options($storage[$key], $value, $contains, $all, FALSE, $merged_keys); } // Don't localize strings during editing. When editing, we need to work with // the original data, not the translated version. @@ -170,7 +174,7 @@ class views_object { $storage[$key] = t($value); } } - else if ($all || !empty($definition[$key])) { + elseif ($all || !empty($definition[$key])) { $storage[$key] = $value; } } @@ -212,12 +216,12 @@ class views_object { function export_option($indent, $prefix, $storage, $option, $definition, $parents) { // Do not export options for which we have no settings. if (!isset($storage[$option])) { - return; + return NULL; } if (isset($definition['export'])) { if ($definition['export'] === FALSE) { - return; + return NULL; } // Special handling for some items diff --git a/includes/view.inc b/includes/view.inc index d9fb43fd..6833cf33 100644 --- a/includes/view.inc +++ b/includes/view.inc @@ -17,9 +17,10 @@ * functions to build the view query, execute the query and render the output. */ class view extends views_db_object { - var $db_table = 'views_view'; - var $base_table = 'node'; - var $base_field = 'nid'; + + public $base_table = 'node'; + + public $base_field = 'nid'; /** * The name of the view. @@ -256,8 +257,9 @@ class view extends views_db_object { /** * Constructor */ - function __construct() { + public function __construct() { parent::init(); + $this->db_table = 'views_view'; // Make sure all of our sub objects are arrays. foreach ($this->db_objects() as $object) { $this->$object = array(); @@ -1493,8 +1495,8 @@ class view extends views_db_object { // We can't use choose_display() here because that function // calls this one. - $displays = (array)$displays; - foreach ($displays as $display_id) { + $display_ids = (array)$displays; + foreach ($display_ids as $display_id) { if (!empty($this->display[$display_id]->handler)) { if ($this->display[$display_id]->handler->access($account)) { return TRUE; @@ -1607,7 +1609,7 @@ class view extends views_db_object { $argument_keys = isset($this->argument) ? array_keys($this->argument) : array(); $id = current($argument_keys); foreach (explode('/', $path) as $piece) { - if ($piece != '%') { + if ($piece !== '%') { $pieces[] = $piece; } else { diff --git a/plugins/views_plugin_display.inc b/plugins/views_plugin_display.inc index a4b732e8..f60ed456 100644 --- a/plugins/views_plugin_display.inc +++ b/plugins/views_plugin_display.inc @@ -124,7 +124,7 @@ class views_plugin_display extends views_plugin { $pager = array( 'type' => $type, 'options' => array( - 'offset' => intval($offset) + 'offset' => (int) $offset, ), ); @@ -156,7 +156,8 @@ class views_plugin_display extends views_plugin { $content = $this->get_option($area); if (!empty($content) && !is_array($content)) { $format = $this->get_option($area . '_format'); - $options = array( + $format = !empty($format) ? $format : filter_default_format(); + $area_options = array( 'id' => 'area', 'table' => 'views', 'field' => 'area', @@ -164,13 +165,13 @@ class views_plugin_display extends views_plugin { 'relationship' => 'none', 'group_type' => 'group', 'content' => $content, - 'format' => !empty($format) ? $format : filter_default_format(), + 'format' => $format, ); if ($area != 'empty' && $empty = $this->get_option($area . '_empty')) { - $options['empty'] = $empty; + $area_options['empty'] = $empty; } - $this->set_option($area, array('text' => $options)); + $this->set_option($area, array('text' => $area_options)); $converted = TRUE; $changed = TRUE; } @@ -765,7 +766,7 @@ class views_plugin_display extends views_plugin { else { return $display_id; } - // fall-through returns NULL + return NULL; } /** @@ -787,6 +788,7 @@ class views_plugin_display extends views_plugin { if ($this->get_option('link_display') == 'custom_url' && $link_url = $this->get_option('link_url')) { return $link_url; } + return NULL; } function get_url() { @@ -823,6 +825,7 @@ class views_plugin_display extends views_plugin { if (array_key_exists($option, $this->options)) { return $this->options[$option]; } + return NULL; } /** @@ -833,6 +836,7 @@ class views_plugin_display extends views_plugin { if ($plugin) { return $plugin->uses_fields(); } + return NULL; } /** @@ -877,7 +881,7 @@ class views_plugin_display extends views_plugin { $plugin = views_get_plugin($type, $name); if (!$plugin) { - return; + return NULL; } if ($type != 'query') { $plugin->init($this->view, $this->display, $options); @@ -2379,9 +2383,10 @@ class views_plugin_display extends views_plugin { $this->set_option($section, (bool)$form_state['values'][$section]); break; case 'use_more': - $this->set_option($section, intval($form_state['values'][$section])); - $this->set_option('use_more_always', !intval($form_state['values']['use_more_always'])); + $this->set_option($section, (int)($form_state['values'][$section])); + $this->set_option('use_more_always', !(int)($form_state['values']['use_more_always'])); $this->set_option('use_more_text', $form_state['values']['use_more_text']); + // TODO: Missing 'break' here?? or is fallthough intended? case 'distinct': $this->set_option($section, $form_state['values'][$section]); break; diff --git a/plugins/views_plugin_query.inc b/plugins/views_plugin_query.inc index d39ed989..2287ae37 100644 --- a/plugins/views_plugin_query.inc +++ b/plugins/views_plugin_query.inc @@ -147,7 +147,12 @@ class views_plugin_query extends views_plugin { */ function set_where_group($type = 'AND', $group = NULL, $where = 'where') { // Set an alias. - $groups = &$this->$where; + if ($where === 'where') { + $groups = &$this->where; + } + elseif ($where === 'having') { + $groups = &$this->having; + } if (!isset($group)) { $group = empty($groups) ? 1 : max(array_keys($groups)) + 1; -- 2.11.0