diff --git a/README.txt b/README.txt index e7e0cec..e20782d 100644 --- a/README.txt +++ b/README.txt @@ -25,4 +25,3 @@ NOTE: One should take caution in that the PHP code will be eval'd within the context of Drupal and Views. This is a useful thing for power users, but can cause trouble if you're not expecting it. For example, your code should not use variable names like $query unless you are actually intending to clobber the preexisting $query object. Name your variables with this in mind. A good safeguard if you aren't sure what you may or may not be clobbering is to give your all your variables some unique prefix -- say, start them all out with "$myvar_" or whatever you like. -Last updated: $Id$ diff --git a/views_handler_filter_node_nid_php.inc b/views_handler_filter_node_nid_php.inc index a549acf..4f6b329 100644 --- a/views_handler_filter_node_nid_php.inc +++ b/views_handler_filter_node_nid_php.inc @@ -1,5 +1,10 @@ options['handler'] == 'php') { - $result = eval ($rawcode); - if ($result === false) { + $result = eval($rawcode); + if ($result === FALSE) { watchdog('viewsphpfilter', "Parse error in PHP: $this->value; filter ignored", array(), WATCHDOG_ERROR); - return false; + return FALSE; } - } else $result = $rawcode; - if ($result === null) { + } + else $result = $rawcode; + if ($result === NULL) { watchdog('viewsphpfilter', "PHP filter returned null; filter ignored", array(), WATCHDOG_NOTICE); - return false; + return FALSE; } if (!is_array($result)) { - $result = explode(',',$result); + $result = explode(',', $result); } $trimresult = array(); foreach ($result as $retval) { $trimmed = trim($retval); if ($trimmed != "") { if ((((string)((int)$retval)) != $retval) || ($retval < 1)) { - watchdog('viewsphpfilter', "Invalid return value in PHP: " . implode(",",$result) . "; filter ignored", array(), WATCHDOG_ERROR); - return false; - } else { + watchdog('viewsphpfilter', "Invalid return value in PHP: " . implode(",", $result) . "; filter ignored", array(), WATCHDOG_ERROR); + return FALSE; + } + else { $trimresult[] = $trimmed; } } } - //watchdog('viewsphpfilter', "PHP filter return value: array('" . implode("','",$trimresult) . "')", array(), WATCHDOG_DEBUG); + //watchdog('viewsphpfilter', "PHP filter return value: array('" . implode("','", $trimresult) . "')", array(), WATCHDOG_DEBUG); return $trimresult; } function query() { - if (($result = $this->_parse_input($this->value)) === false) return; + $this->ensure_my_table(); if ($this->operator == 'NAND') { if (!(empty($result) || (count($result) == 1 && $result[0]==NULL))) { - $this->query->add_where($this->options['group'], "{$this->table_alias}.{$this->real_field} NOT IN (%s)", implode(",", $result)); + $this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field", $result, "NOT IN"); } } else { // $this->operator == 'AND' if (empty($result) || (count($result) == 1 && $result[0]==NULL)) { - $this->query->add_where($this->options['group'], "{$this->table_alias}.{$this->real_field} IS NULL"); - } else { - $this->query->add_where($this->options['group'], "{$this->table_alias}.{$this->real_field} IN (%s)", implode(",", $result)); + $this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field", NULL, 'IS NULL'); + } + else { + $this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field", $result, "IN"); } } } diff --git a/viewsphpfilter.info b/viewsphpfilter.info index 258964f..b8783c3 100644 --- a/viewsphpfilter.info +++ b/viewsphpfilter.info @@ -1,13 +1,14 @@ name = Views PHP Filter description = "Adds a filter to Views that takes PHP code, and uses the return value of the code as an array of Node IDs to filter on." -core = 6.x +core = 7.x dependencies[] = views package = "Views" -version = "$Name$" +version = "7.x-1.x-dev" + +; Views handlers +files[] = views_handler_filter_node_nid_php.inc ; Information added by drupal.org packaging script on 2010-11-12 -version = "6.x-1.x-dev" -core = "6.x" project = "viewsphpfilter" datestamp = "1289564886" diff --git a/viewsphpfilter.install b/viewsphpfilter.install index c885493..d959b55 100644 --- a/viewsphpfilter.install +++ b/viewsphpfilter.install @@ -1,8 +1,9 @@ '. t("A filter for the Views module."). '

'; - $output = '

'. t("This filter will appear in the Views Filter dialog as a \"Node: Node ID\". This filter takes PHP code as its value (with no open/close brackets), which should return an array of integers representing Node IDs to include or exclude. The filter will evaluate the PHP and filter on the resulting array. It can also (experimental) take a list of node IDs, separated by commas."). '

'; + $output = '

' . t('A filter for the Views module.') . '

'; + $output = '

' . t('This filter will appear in the Views Filter dialog as a "Node: Node ID". This filter takes PHP code as its value (with no open/close brackets), which should return an array of integers representing Node IDs to include or exclude. The filter will evaluate the PHP and filter on the resulting array. It can also (experimental) take a list of node IDs, separated by commas.') . '

'; break; } return $output; @@ -16,6 +17,6 @@ function viewsphpfilter_help($path, $arg) { function viewsphpfilter_views_api() { return ( array( - 'api' => '2.0', + 'api' => '3.0-alpha1', )); } diff --git a/viewsphpfilter.views.inc b/viewsphpfilter.views.inc index 7b300bf..8327303 100644 --- a/viewsphpfilter.views.inc +++ b/viewsphpfilter.views.inc @@ -1,11 +1,12 @@ 'nid', 'title' => t('Node ID PHP handler'), 'title short' => t('PHP filter'), @@ -19,13 +20,3 @@ function viewsphpfilter_views_data_alter(&$data) { ), ); } - -function viewsphpfilter_views_handlers() { - return array( - 'handlers' => array( - 'views_handler_filter_node_nid_php' => array( - 'parent' => 'views_handler_filter', - ), - ), - ); -} diff --git a/viewsphpfilter.views_convert.inc b/viewsphpfilter.views_convert.inc index 5e7ea78..f597f6a 100644 --- a/viewsphpfilter.views_convert.inc +++ b/viewsphpfilter.views_convert.inc @@ -1,5 +1,8 @@