security updates of unpatched modules

This commit is contained in:
Bachir Soussi Chiadmi
2016-10-25 16:23:00 +02:00
parent 610760bedf
commit f6f7fd575f
133 changed files with 5598 additions and 2574 deletions

View File

@@ -61,6 +61,10 @@ class SearchApiFacetapiAdapter extends FacetapiAdapter {
public function initActiveFilters($query) {
$search_id = $query->getOption('search id');
$index_id = $this->info['instance'];
// Only act on queries from the right index.
if ($index_id != $query->getIndex()->machine_name) {
return;
}
$facets = facetapi_get_enabled_facets($this->info['name']);
$this->fields = array();
@@ -83,13 +87,16 @@ class SearchApiFacetapiAdapter extends FacetapiAdapter {
if (array_search($search_id, $facet_search_ids) === FALSE) {
if (!$default_true) {
continue; // We are only to show facets for explicitly named search ids.
// We are only to show facets for explicitly named search ids.
continue;
}
}
elseif ($default_true) {
continue; // The 'facet_search_ids' in the settings are to be excluded.
// The 'facet_search_ids' in the settings are to be excluded.
continue;
}
$active[$facet['name']] = $search_id;
$facet_key = $facet['name'] . '@' . $this->getSearcher();
$active[$facet_key] = $search_id;
$this->fields[$facet['name']] = array(
'field' => $facet['field'],
'limit' => $options['hard_limit'],

View File

@@ -58,27 +58,36 @@ class SearchApiFacetapiDate extends SearchApiFacetapiTerm implements FacetapiQue
$item = end($active);
$field = $this->facet['field'];
$filter = $this->createRangeFilter($item['value']);
$this->addFacetFilter($query, $field, $filter);
if ($filter) {
$this->addFacetFilter($query, $field, $filter);
}
}
}
/**
* Rewrites the handler-specific date range syntax to the normal facet syntax.
*
* @param $value
* @param string $value
* The user-facing facet value.
*
* @return string
* @return string|null
* A facet to add as a filter, in the format used internally in this module.
* Or NULL if the raw facet in $value is not valid.
*/
protected function createRangeFilter($value) {
// Gets the granularity. Ignore any filters passed directly from the server
// (range or missing). We always create filters starting with a year.
if (!$value || !ctype_digit($value[0])) {
return $value;
// Ignore any filters passed directly from the server (range or missing).
if (!$value || $value == '!' || (!ctype_digit($value[0]) && preg_match('/^[\[(][^ ]+ [^ ]+[])]$/', $value))) {
return $value ? $value : NULL;
}
// Parse into date parts.
$parts = $this->parseRangeFilter($value);
// Return NULL if the date parts are invalid or none were found.
if (empty($parts)) {
return NULL;
}
$parts = explode('-', $value);
$date = new DateTime();
switch (count($parts)) {
case 1:
@@ -140,6 +149,48 @@ class SearchApiFacetapiDate extends SearchApiFacetapiTerm implements FacetapiQue
return "[$lower TO $upper]";
}
/**
* Parses the date range filter value into parts.
*
* @param string $value
* The user-facing facet value.
*
* @return int[]|null
* An array of date parts, or NULL if an invalid value was provided.
*/
protected static function parseRangeFilter($value) {
$parts = explode('-', $value);
foreach ($parts as $i => $part) {
// Invalidate if part is not an integer.
if ($part === '' || !is_numeric($part) || intval($part) != $part) {
return NULL;
}
$parts[$i] = (int) $part;
// Depending on the position, negative numbers or 0 are invalid.
switch ($i) {
case 0:
// Years can contain anything negative values are unlikely, but
// technically possible.
break;
case 1:
case 2:
// Days and months have to be positive.
if ($part <= 0) {
return NULL;
}
break;
default:
// All others can be 0, but not negative.
if ($part < 0) {
return NULL;
}
}
}
return $parts;
}
/**
* Replacement callback for replacing ISO dates with timestamps.
*
@@ -159,10 +210,11 @@ class SearchApiFacetapiDate extends SearchApiFacetapiTerm implements FacetapiQue
public function build() {
$facet = $this->adapter->getFacet($this->facet);
$search_ids = drupal_static('search_api_facetapi_active_facets', array());
if (empty($search_ids[$facet['name']]) || !search_api_current_search($search_ids[$facet['name']])) {
$facet_key = $facet['name'] . '@' . $this->adapter->getSearcher();
if (empty($search_ids[$facet_key]) || !search_api_current_search($search_ids[$facet_key])) {
return array();
}
$search_id = $search_ids[$facet['name']];
$search_id = $search_ids[$facet_key];
$build = array();
$search = search_api_current_search($search_id);
$results = $search[1];

View File

@@ -57,21 +57,27 @@ class SearchApiFacetapiTerm extends FacetapiQueryType implements FacetapiQueryTy
// When the operator is OR, remove parent terms from the active ones if
// children are active. If we don't do this, sending a term and its
// parent will produce the same results as just sending the parent.
if ($settings['flatten'] == '0') {
if (is_callable($this->facet['hierarchy callback']) && !$settings['flatten']) {
// Check the filters in reverse order, to avoid checking parents that
// will afterwards be removed anyways.
foreach (array_reverse(array_keys($active)) as $filter) {
$values = array_keys($active);
$parents = call_user_func($this->facet['hierarchy callback'], $values);
foreach (array_reverse($values) as $filter) {
// Skip this filter if it was already removed, or if it is the
// "missing value" filter ("!").
if (!isset($active[$filter]) || !is_numeric($filter)) {
continue;
}
$parents = taxonomy_get_parents_all($filter);
// The return value of taxonomy_get_parents_all() includes the term
// itself at index 0. Remove that to only get the term's ancestors.
unset($parents[0]);
foreach ($parents as $parent) {
unset($active[$parent->tid]);
// Go through the entire hierarchy of the value and remove all its
// ancestors.
while (!empty($parents[$filter])) {
$ancestor = array_shift($parents[$filter]);
if (isset($active[$ancestor])) {
unset($active[$ancestor]);
if (!empty($parents[$ancestor])) {
$parents[$filter] = array_merge($parents[$filter], $parents[$ancestor]);
}
}
}
}
}
@@ -165,10 +171,11 @@ class SearchApiFacetapiTerm extends FacetapiQueryType implements FacetapiQueryTy
// initActiveFilters) so that we can retrieve it here and get the correct
// current search for this facet.
$search_ids = drupal_static('search_api_facetapi_active_facets', array());
if (empty($search_ids[$facet['name']]) || !search_api_current_search($search_ids[$facet['name']])) {
$facet_key = $facet['name'] . '@' . $this->adapter->getSearcher();
if (empty($search_ids[$facet_key]) || !search_api_current_search($search_ids[$facet_key])) {
return array();
}
$search_id = $search_ids[$facet['name']];
$search_id = $search_ids[$facet_key];
list(, $results) = search_api_current_search($search_id);
$build = array();

View File

@@ -9,9 +9,9 @@ files[] = plugins/facetapi/adapter.inc
files[] = plugins/facetapi/query_type_term.inc
files[] = plugins/facetapi/query_type_date.inc
; Information added by Drupal.org packaging script on 2016-02-26
version = "7.x-1.16+29-dev"
; Information added by Drupal.org packaging script on 2016-07-21
version = "7.x-1.20"
core = "7.x"
project = "search_api"
datestamp = "1456500713"
datestamp = "1469117342"

View File

@@ -5,9 +5,39 @@
* Install, update and uninstall functions for the Search facets module.
*/
/**
* Implements hook_install().
*/
function search_api_facetapi_install() {
variable_set('date_format_search_api_facetapi_' . FACETAPI_DATE_YEAR, 'Y');
variable_set('date_format_search_api_facetapi_' . FACETAPI_DATE_MONTH, 'F Y');
variable_set('date_format_search_api_facetapi_' . FACETAPI_DATE_DAY, 'F j, Y');
variable_set('date_format_search_api_facetapi_' . FACETAPI_DATE_HOUR, 'H:__');
variable_set('date_format_search_api_facetapi_' . FACETAPI_DATE_MINUTE, 'H:i');
variable_set('date_format_search_api_facetapi_' . FACETAPI_DATE_SECOND, 'H:i:S');
}
/**
* Implements hook_uninstall().
*/
function search_api_facetapi_uninstall() {
variable_del('search_api_facets_search_ids');
}
variable_del('date_format_search_api_facetapi_' . FACETAPI_DATE_YEAR);
variable_del('date_format_search_api_facetapi_' . FACETAPI_DATE_MONTH);
variable_del('date_format_search_api_facetapi_' . FACETAPI_DATE_DAY);
variable_del('date_format_search_api_facetapi_' . FACETAPI_DATE_HOUR);
variable_del('date_format_search_api_facetapi_' . FACETAPI_DATE_MINUTE);
variable_del('date_format_search_api_facetapi_' . FACETAPI_DATE_SECOND);
}
/**
* Set up date formats.
*/
function search_api_facetapi_update_7101() {
variable_set('date_format_search_api_facetapi_' . FACETAPI_DATE_YEAR, 'Y');
variable_set('date_format_search_api_facetapi_' . FACETAPI_DATE_MONTH, 'F Y');
variable_set('date_format_search_api_facetapi_' . FACETAPI_DATE_DAY, 'F j, Y');
variable_set('date_format_search_api_facetapi_' . FACETAPI_DATE_HOUR, 'H:__');
variable_set('date_format_search_api_facetapi_' . FACETAPI_DATE_MINUTE, 'H:i');
variable_set('date_format_search_api_facetapi_' . FACETAPI_DATE_SECOND, 'H:i:S');
}

View File

@@ -211,6 +211,58 @@ function search_api_facetapi_search_api_query_alter($query) {
}
}
/**
* Implements hook_date_formats().
*/
function search_api_facetapi_date_formats() {
return array(
array(
'type' => 'search_api_facetapi_' . FACETAPI_DATE_YEAR,
'format' => 'Y',
'locales' => array(),
),
array(
'type' => 'search_api_facetapi_' . FACETAPI_DATE_MONTH,
'format' => 'F Y',
'locales' => array(),
),
array(
'type' => 'search_api_facetapi_' . FACETAPI_DATE_DAY,
'format' => 'F j, Y',
'locales' => array(),
),
array(
'type' => 'search_api_facetapi_' . FACETAPI_DATE_HOUR,
'format' => 'H:__',
'locales' => array(),
),
array(
'type' => 'search_api_facetapi_' . FACETAPI_DATE_MINUTE,
'format' => 'H:i',
'locales' => array(),
),
array(
'type' => 'search_api_facetapi_' . FACETAPI_DATE_SECOND,
'format' => 'H:i:s',
'locales' => array(),
),
);
}
/**
* Implements hook_date_format_types().
*/
function search_api_facetapi_date_format_types() {
return array(
'search_api_facetapi_' . FACETAPI_DATE_YEAR => t('Search facets - Years'),
'search_api_facetapi_' . FACETAPI_DATE_MONTH => t('Search facets - Months'),
'search_api_facetapi_' . FACETAPI_DATE_DAY => t('Search facets - Days'),
'search_api_facetapi_' . FACETAPI_DATE_HOUR => t('Search facets - Hours'),
'search_api_facetapi_' . FACETAPI_DATE_MINUTE => t('Search facets - Minutes'),
'search_api_facetapi_' . FACETAPI_DATE_SECOND => t('Search facets - Seconds'),
);
}
/**
* Menu callback for the facet settings page.
*/
@@ -532,16 +584,12 @@ function search_api_facetapi_map_date(array $values, array $options = array()) {
continue;
}
// For years, the URL value is already the label.
if ($granularity == FACETAPI_DATE_YEAR) {
$map[$value] = $value;
continue;
}
// Otherwise, parse the timestamp from the known format and format it as a
// label.
$format = search_api_facetapi_date_get_granularity_format($granularity);
$date = DateTime::createFromFormat($format, $value);
// Use the "!" modifier to make the date parsing independent of the current
// date/time. (See #2678856.)
$date = DateTime::createFromFormat('!' . $format, $value);
if (!$date) {
continue;
}
@@ -568,17 +616,16 @@ function search_api_facetapi_map_date(array $values, array $options = array()) {
*/
function search_api_facetapi_format_timestamp($timestamp, $precision = FACETAPI_DATE_YEAR) {
$formats = array(
FACETAPI_DATE_YEAR => 'Y',
FACETAPI_DATE_MONTH => 'F Y',
FACETAPI_DATE_DAY => 'F j, Y',
FACETAPI_DATE_HOUR => 'H:__',
FACETAPI_DATE_MINUTE => 'H:i',
FACETAPI_DATE_SECOND => 'H:i:s',
FACETAPI_DATE_YEAR,
FACETAPI_DATE_MONTH,
FACETAPI_DATE_DAY,
FACETAPI_DATE_HOUR,
FACETAPI_DATE_MINUTE,
FACETAPI_DATE_SECOND,
);
if (!isset($formats[$precision])) {
if (!in_array($precision, $formats)) {
$precision = FACETAPI_DATE_YEAR;
}
return format_date($timestamp, 'custom', $formats[$precision]);
return format_date($timestamp, 'search_api_facetapi_' . $precision);
}

View File

@@ -247,6 +247,31 @@ class SearchApiViewsFacetsBlockDisplay extends views_plugin_display_block {
),
);
// Override the $variables['#path'] if facetapi_pretty_paths is enabled.
if (module_exists('facetapi_pretty_paths')) {
// Get the appropriate facet adapter.
$adapter = facetapi_adapter_load('search_api@' . $index->machine_name);
// Get the URL processor and check if it uses pretty paths.
$urlProcessor = $adapter->getUrlProcessor();
if ($urlProcessor instanceof FacetapiUrlProcessorPrettyPaths) {
// Retrieve the pretty path alias from the URL processor.
$facet = facetapi_facet_load($facet_field, 'search_api@' . $index->machine_name);
$values = array(trim($term['filter'], '"'));
// Get the pretty path for the facet and remove the current search's
// base path from it.
$base_path_current = $urlProcessor->getBasePath();
$pretty_path = $urlProcessor->getFacetPath($facet, $values, FALSE);
$pretty_path = str_replace($base_path_current, '', $pretty_path);
// Set the new, pretty path for the facet and remove the "f" query
// parameter.
$variables['path'] = $variables['path'] . $pretty_path;
unset($variables['options']['query']['f']);
}
}
// Themes the link, adds row to facets.
$facets[] = array(
'class' => array('leaf'),

View File

@@ -67,17 +67,6 @@ abstract class SearchApiViewsHandlerFilterEntity extends SearchApiViewsHandlerFi
return $operators;
}
/**
* {@inheritdoc}
*/
public function option_definition() {
$options = parent::option_definition();
$options['expose']['multiple']['default'] = TRUE;
return $options;
}
/**
* {@inheritdoc}
*/

View File

@@ -27,6 +27,7 @@ class SearchApiViewsHandlerFilterTaxonomyTerm extends SearchApiViewsHandlerFilte
$options['type'] = array('default' => !empty($this->definition['vocabulary']) ? 'textfield' : 'select');
$options['hierarchy'] = array('default' => 0);
$options['expose']['contains']['reduce'] = array('default' => FALSE);
$options['error_message'] = array('default' => TRUE, 'bool' => TRUE);
return $options;
@@ -72,13 +73,13 @@ class SearchApiViewsHandlerFilterTaxonomyTerm extends SearchApiViewsHandlerFilte
}
else {
if ($vocabulary && !empty($this->options['hierarchy'])) {
$tree = taxonomy_get_tree($vocabulary->vid);
$tree = taxonomy_get_tree($vocabulary->vid, 0, NULL, TRUE);
$options = array();
if ($tree) {
foreach ($tree as $term) {
$choice = new stdClass();
$choice->option = array($term->tid => str_repeat('-', $term->depth) . $term->name);
$choice->option = array($term->tid => str_repeat('-', $term->depth) . check_plain(entity_label('taxonomy_term', $term)));
$options[] = $choice;
}
}
@@ -97,8 +98,15 @@ class SearchApiViewsHandlerFilterTaxonomyTerm extends SearchApiViewsHandlerFilte
$query->condition('tv.machine_name', $vocabulary->machine_name);
}
$result = $query->execute();
$tids = array();
foreach ($result as $term) {
$options[$term->tid] = $term->name;
$tids[] = $term->tid;
}
$terms = taxonomy_term_load_multiple($tids);
foreach ($terms as $term) {
$options[$term->tid] = check_plain(entity_label('taxonomy_term', $term));
}
}
@@ -229,6 +237,14 @@ class SearchApiViewsHandlerFilterTaxonomyTerm extends SearchApiViewsHandlerFilte
parent::exposed_validate($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function expose_options() {
parent::expose_options();
$this->options['expose']['reduce'] = FALSE;
}
/**
* {@inheritdoc}
*/
@@ -282,15 +298,23 @@ class SearchApiViewsHandlerFilterTaxonomyTerm extends SearchApiViewsHandlerFilte
*/
public function expose_form(&$form, &$form_state) {
parent::expose_form($form, $form_state);
if ($this->options['type'] != 'select') {
unset($form['expose']['reduce']);
if ($this->options['type'] == 'select') {
$form['expose']['reduce'] = array(
'#type' => 'checkbox',
'#title' => t('Limit list to selected items'),
'#description' => t('If checked, the only items presented to the user will be the ones selected here.'),
'#default_value' => $this->options['expose']['reduce'],
);
}
else {
$form['error_message'] = array(
'#type' => 'checkbox',
'#title' => t('Display error message'),
'#description' => t('Display an error message if one of the entered terms could not be found.'),
'#default_value' => $this->options['error_message'],
);
}
$form['error_message'] = array(
'#type' => 'checkbox',
'#title' => t('Display error message'),
'#description' => t('Display an error message if one of the entered terms could not be found.'),
'#default_value' => !empty($this->options['error_message']),
);
}
/**

View File

@@ -344,13 +344,15 @@ class SearchApiViewsQuery extends views_plugin_query {
// FALSE.
$skip_result_count = $this->query->getOption('skip result count', TRUE);
if ($skip_result_count) {
$skip_result_count = !$this->pager->use_count_query() && empty($view->get_total_rows);
$skip_result_count = !$this->pager || (!$this->pager->use_count_query() && empty($view->get_total_rows));
$this->query->setOption('skip result count', $skip_result_count);
}
try {
// Trigger pager pre_execute().
$this->pager->pre_execute($this->query);
if ($this->pager) {
$this->pager->pre_execute($this->query);
}
// Views passes sometimes NULL and sometimes the integer 0 for "All" in a
// pager. If set to 0 items, a string "0" is passed. Therefore, we unset
@@ -385,7 +387,9 @@ class SearchApiViewsQuery extends views_plugin_query {
$view->execute_time = microtime(TRUE) - $start;
// Trigger pager post_execute().
$this->pager->post_execute($view->result);
if ($this->pager) {
$this->pager->post_execute($view->result);
}
}
catch (Exception $e) {
$this->errors[] = $e->getMessage();
@@ -444,7 +448,7 @@ class SearchApiViewsQuery extends views_plugin_query {
// Gather any fields from the search results.
if (!empty($result['fields'])) {
$row['_entity_properties'] += $result['fields'];
$row['_entity_properties'] += search_api_get_sanitized_field_values($result['fields']);
}
// Check whether we need to extract any properties from the result item.

View File

@@ -27,9 +27,9 @@ files[] = includes/handler_sort.inc
files[] = includes/plugin_cache.inc
files[] = includes/query.inc
; Information added by Drupal.org packaging script on 2016-02-26
version = "7.x-1.16+29-dev"
; Information added by Drupal.org packaging script on 2016-07-21
version = "7.x-1.20"
core = "7.x"
project = "search_api"
datestamp = "1456500713"
datestamp = "1469117342"