Needs review
Project:
Block Conditional Visibility by URI Query Parameters
Version:
7.x-1.2
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
17 Apr 2014 at 16:38 UTC
Updated:
26 Nov 2017 at 06:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
SolomonGifford commentedI assume you've tried
*=231
That said - I bet the encoding is the issue. If you wants to take a crack at a fix, I can test..or I can address next week sometime (hopefully).
Comment #2
manucuest commentedYes, I tried *=231 also and doesn't work.
I can't help with this issue, sorry.
Thanks a lot.
Comment #3
manucuest commentedI don't have a deep knowledge of Drupal'a API but I'm found a solution for this problem, in my project at least.
The block_query.module file has at line 141 a conditional that evalue querystring parameters for function block_query_block_list_alter(), well this parameters appear empty if the parameter is a array. At the end of this conditional (line 149) I added:
else {
if(!is_array($getkey) and is_array($value)){
$getkeylower = drupal_strtolower($getkey);
$valuelower = drupal_strtolower($value[0]); //This variable take the first value of array
if ($getkeylower != 'q' && !$page_match) {
$page_match = drupal_match_path($getkeylower . '=' . $valuelower, $queries);
}
}
}
Note that $valuelower take the first item of array. This work for me because I need show the block when the URI doesn't have any querystring.
This is a useful module and I hope this code help to improve it.
Thanks a lot.
Comment #4
SolomonGifford commentedCan you provide a patch?
Comment #5
kala4ekPatch provided.
Comment #6
pebosi commentedPatch works for me, thanks!
Comment #7
dangur commentedI believe this solution is more elegant as it does not duplicate code.
Comment #8
linitrex commented#7 is not a general solution. It is a workaround for one of the very simple cases when having single dimension array. One may have not only array but also array of arrays, array of array of arrays etc. The whole function function block_query_block_list_alter(&$blocks) should be replaced I think . Instead of converting _GET to keys/values and cheeking for queries my proposal is to convert the queries and _GET to URL format and then check if the converted _GET string contains the converted queries string.
function block_query_block_list_alter(&$blocks) {
global $theme_key;
// Build an array of terms for each block.
$block_queries = array();
$result = db_query('SELECT module, delta, visibility, queries FROM {block_query}');
foreach ($result as $record) {
$block_queries[$record->module][$record->delta] = $record->queries;
$block_visibility[$record->module][$record->delta] = $record->visibility;
}
foreach ($blocks as $key => $block) {
if (!empty($block_queries[$block->module][$block->delta])) {
// Convert path to lowercase. This allows comparison of the same query
// with different case.
$page_match = FALSE;
$queries = drupal_strtolower($block_queries[$block->module][$block->delta]);
$queries_as_url=str_replace("%3D", "=", urlencode($queries));
$_GET_as_url=http_build_query($_GET);
$page_match=strpos($_GET_as_url,$queries_as_url);
if (!$page_match) {
unset($blocks[$key]);
// When $block->visibility has a value of 0 (BLOCK_VISIBILITY_NOTLISTED),
// the block is displayed on all pages except those listed in
// $block->pages.
//
// When set to 1 (BLOCK_VISIBILITY_LISTED), it is displayed only on those
// pages listed in $block->pages.
$page_match = !($block_visibility[$block->module][$block->delta] xor $page_match);
if (!$page_match) {
unset($blocks[$key]);
}
}
}
}
}