Closed (duplicate)
Project:
Views (for Drupal 7)
Version:
6.x-2.x-dev
Component:
node data
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
19 Feb 2009 at 11:30 UTC
Updated:
11 Nov 2010 at 20:31 UTC
Hello,
I have a view and I have adjusted the Teaser's properties in a way that it should be trimmed after some characters -E.g. 50- and on words boundaries.
When I enter texts in English language in the body, Views module finds the word boundaries properly and trims it; but when I enter multibyte text in there from another language -Persian in my case- it doesn't trim on word boundaries and trim the text into a zero length string. Seems the module cannot see the Space characters in the text.
Here is the View export:
$view = new view;
$view->name = 'sticky_news';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'field_picture_fid' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
),
'link_to_node' => 1,
'label_type' => 'none',
'format' => 'newspic_linked',
'multiple' => array(
'group' => TRUE,
'multiple_number' => '',
'multiple_from' => '',
'multiple_reversed' => FALSE,
),
'exclude' => 0,
'id' => 'field_picture_fid',
'table' => 'node_data_field_picture',
'field' => 'field_picture_fid',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
'title' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 1,
'max_length' => '50',
'word_boundary' => 0,
'ellipsis' => 1,
'html' => 0,
),
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
'teaser' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 1,
'max_length' => '50',
'word_boundary' => 1,
'ellipsis' => 0,
'html' => 0,
),
'exclude' => 0,
'id' => 'teaser',
'table' => 'node_revisions',
'field' => 'teaser',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
));
$handler->override_option('sorts', array(
'field_order_value' => array(
'order' => 'ASC',
'delta' => -1,
'id' => 'field_order_value',
'table' => 'node_data_field_order',
'field' => 'field_order_value',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
'created' => array(
'order' => 'DESC',
'granularity' => 'second',
'id' => 'created',
'table' => 'node',
'field' => 'created',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'type' => array(
'operator' => 'in',
'value' => array(
'news' => 'news',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
'sticky' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'sticky',
'table' => 'node',
'field' => 'sticky',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
'status' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('items_per_page', 1);
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);
Comments
Comment #1
farzan commentedI tracked the problem; It is not a bug in the Views module; PHP function preg_match does not support multibyte strings properly.
Right now I am looking in PHP manual to find a solution for this.
Comment #2
merlinofchaos commentedBlast! I thought it did. Please let me know if you find a multibyte acceptable solution.
Comment #3
merlinofchaos commentedThis is probably still valid, unfortunately. I don't know of any good multibyte solutions but I"m not real familiar with multibyte, either.
Comment #4
gaurnar commentedfarzan,
if the issue is still actual for you, I've found a working solution. I encountered the problem very similar to yours, except that I'm using Russian (but I think that the exact language is not the case). The source of the problem is in render_trim_text function in handlers/views_handler_field.inc (relatively to Views module root directory).
I suggest changing this part of the function:
To this:
The problem is that the regular expression used in preg_match in the original code does not detect word boundaries correctly on multibyte strings (hope that it will change in PHP 6). My solution is an overkill, so if anyone can suggest a better one - you are welcome.
Comment #5
kla2t commentedsubscribe
Comment #6
rolodmonkey commentedAccording to this link:
http://www.php.net/manual/en/function.preg-match.php#95828
It might be possible to keep the original preg_match, but add '(*UTF8)' to the beginning of the expression. It looks like this might be subtly different from the 'u' modifier.
However, I would suggest extensive testing before rolling this out. You may want to read the section titled 'UTF-8 AND UNICODE PROPERTY SUPPORT' near the top of this page:
http://www.pcre.org/pcre.txt
In the end, it might be necessary to write a wrapper function that tests for different environmental settings, and if they aren't present it would have to check the 'hard' way described in #4 above.
Comment #7
flaviovs commentedShouldn't Views be using truncate_utf8() here?
Comment #8
iamjon commentedplease see #513396: Trim field to a maximum length - Multibyte encodings
marking this as closed
Comment #9
iamjon commentedComment #10
rolodmonkey commented