Snippet: cwsoft-anynews

svsanchez

Hello Cwsoft, thank you for your help, I was finally able to get it to work with the getNewsItems thing instead of the previous one!

cwsoft

#151
Hi,

multilingual output with anynews is a bit tricky, but doable.

First I would switch to the more easy configuration options using getNewsItems shown in the README. The old displayNewsItems function needs to have all parameters in the right order, which is not the case in your example. If you want stick to the old function, follow the instructions for Anynews <2.8 linked in the README (section configuration).

Create one news page with the WB news module for each language you have or create one group for each language. Then call Anynews for each language using  set lang_id = 'LANG' and the group or sectionID for the individual language.

Another option is to organize your URL to include the language flage (e.g. mydomain/EN/news.php). In this case you can try the Anynews flag lang_filter = true and lang_id = 'AUTO' combination to let Anynews choose the language file depending on the URL language fragment.

Cheers

svsanchez

Hello Guys, thank you for this module however I am running into an already mentioned problem and I just can't figure it out, I already read the whole old 'anynews' thread and this one and I don't understand where is my error. I am building a site in 3 languages (EN, ES and RU) and anynews outputs the latest news mixed instead of showing only the EN news when I am in the English version or only the ES news when I am in the Spanish version.

I have the correct structure with en, es and ru folders as parents for their respective versions.

I created a news page under each en, es and ru and posted the news specifically for each language.

I also tried specifying the section_id and the language_filter without luck.

I had installed the Anynews V2.2 and then noticed the cwsoft-Anynews and installed the latest version (2.9.1) but I still have the same mixing of news in different languages problem.

This is how I am calling the news on my template:

<?php displayNewsItems(
/*   $section_id= 26, */
   $group_id = 0,
   $max_news_items = 3,
   $max_news_lenght = 50,
   $display_mode = 2,
   $lang_id = 'AUTO',
   $lang_filter = 'EN',
   $strip_tags = true,
   $allowed_tags = '<p><a><img>',
   $custom_placeholder = false,
   $sort_by = 1,
   $sort_order = 1,
   $not_older_than = 0
   );
?>

What am I doing wrong?

cwsoft

Hello,

cwsoft-anynews v2.9.1 stable is available at GitHub and the WebsiteBaker Add-ons repository.

Updates since last release:
- fixed a regression introduced with v2.9.0 affecting the outdated PHP 5.2.x series

cwsoft

cwsoft

#148
Hi,

if you pass over all default values to the getNewsItems function anyway, you can also stick to the old function :wink:

display_mode = 6 does not work due to an error in your template. The error was already discussed and a solution was provided in this thread. Instead of blind copy and paste of forum code, maybe first try to read through the last posts  :wink:

Hint: the date filter works best with timestamps (TS_PUBLISHED_WHEN). Just look how this is done in the default templates. A list of all variables is shown with display_mode = 99. This and more infos can also be found in the README at GitHub: https://github.com/cwsoft/wb-cwsoft-anynews#readme

Cheers

xoanon

#147
ok, thanks,  looks ok for display mode 1,2,3,4
but I tried display=6
with the following
a) HTML section:

[[getNewsItems?display_mode=2]]


b) CODE2 section:

if (function_exists('getNewsItems')) {
   echo getNewsItems(array(
      'group_id' => 0,
      'max_news_items' => 4,
       'max_news_length' => -1,
    'display_mode' => 6,
       'lang_id' => 'AUTO',
       'strip_tags' => true,
       'allowed_tags' => '<p><a><img>',
       'custom_placeholder' => false,
       'sort_by' => 1,
       'sort_order' => 1,
       'not_older_than' => 0,
       'group_id_type' => 'group_id',
       'lang_filter' => false,
   ));
}


c) display_mode_6.htt    (from an earlier post)

<style type="text/css">
.twig_block {display:block;clear:both;width:100%;margin-bottom:10px;min-height:50px;overflow:auto;}
.twig_date {width:20%;min-width:35px;float:left;}
.twig_date .twig_day {background:#a8d591;color:#333;font-weight:bold;text-align:center;font-size:110%;border-radius:4px 4px 0 0;}
.twig_date .twig_month {background:#5c9d3b;color:#fff;text-align:center;border-radius:0 0 4px 4px;font-size:70%;text-transform:uppercase;}
.twig_title {float:right;width:75%;margin-top:-2px;}
</style>

{% for news in newsItems %}
<div class="twig_block">
   <div class="twig_date">
       <div class="twig_day">{{news.PUBLISHED_WHEN|date('j')}}</div>
       <div class="twig_month">{{news.PUBLISHED_WHEN|date("M")}}</div>
   </div>
   <div class="twig_title"><a href="{{news.LINK}}">{{news.TITLE }}</a></div>
</div>
{% endfor %}


and get the following errors
>>>>>

[[getNewsItems?display_mode=2]]

There was an unknown exception: An exception has been thrown during the rendering of a template ("DateTime::__construct() [datetime.--construct]: Failed to parse time string (10:02, 21/06/2013) at position 7 (2): Unexpected character") in "display_mode_6.htt" at line 38. in line (279) of (/modules/cwsoft-anynews/thirdparty/Twig/Twig/Template.php)

>>>>>.
Am I doing something wrong?

//edit by Badknight:
please use the [code] tag - thanks

cwsoft


xoanon

Quote from: cwsoft on June 20, 2013, 06:32:04 PM
@xoanon, Ruud:
Uups, I implemented the Twig filter via an anonymous function (closure). Unfortunatelly closures where first introduced with PHP 5.3. I replaced the closure with a function call to support the outdated PHP 5.2.x series too.

Would be great if somebody could download and test the latest version from the GitHub master branch.

Please note: To convert a GitHub ZIP archive into a WebsiteBaker version, please follow the steps in the Download section.

Cheers cwsoft

P.S.: I will release cwsoft-anynews v2.9.1 once it was confirmed that the new version fixes the issue.

Hi
can I just replace the "include.php" file or need the whole package?
?

xoanon

thanks
already changed to the new function  "getNewsItems"

cwsoft

#143
@xoanon: I recommend to upgrade to the more flexible getNewsItems function introduced with cwsoft-anynews 2.8.0. The function getNewsItems allows you to configure only the parameters you want to change, making it more easy to read. Your code example would translate into (default parameters omitted):


if (function_exists('getNewsItems')) {
$options = array(
'max_news_items' => 4,
'display_mode' => 2,
);

echo getNewsItems($options);
}


Details about the default parameters can be found at GitHub.

Cheers

cwsoft

@xoanon, Ruud:
Uups, I implemented the Twig filter via an anonymous function (closure). Unfortunatelly closures where first introduced with PHP 5.3. I replaced the closure with a function call to support the outdated PHP 5.2.x series too.

Would be great if somebody could download and test the latest version from the GitHub master branch.

Please note: To convert a GitHub ZIP archive into a WebsiteBaker version, please follow the steps in the Download section.

Cheers cwsoft

P.S.: I will release cwsoft-anynews v2.9.1 once it was confirmed that the new version fixes the issue.

Ruud

Quote from: Ruud on June 19, 2013, 11:15:59 AM
Tested on (wamp) PHP 5.2.6 with WB 2.8.3 SP1 (1638)

Just tested on a live server with PHP 5.4.16 (same WB).
Works without problems there.
[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]

xoanon

#140
Quote from: xoanon on June 19, 2013, 06:44:37 AM
Quote from: Argos on June 19, 2013, 12:01:15 AM
Thanks for your work!  :-)

Great work but a couple of things that happened to me....
>>>  

Just installed version 2.9 of anynews and get the following error
Parse error: syntax error, unexpected T_FUNCTION in /home1/gvaaeu1/public_html/..domain../modules/cwsoft-anynews/include.php on line 107 which is described in the following lines of code...
/**
   Add Twig filter to allow datetime conversion via PHP strftime function
   Example: {{ timestamp | strftime('%A, %B %Y', ['de_DE','german','deu']) }}
   Help on format strings: http://ch1.php.net/manual/en/function.strftime.php */

$twig->addFilter(new Twig_SimpleFilter('strftime', function ($timestamp, $format, $locales) {
setlocale(LC_ALL, $locales);
return strftime($format, $timestamp);
}));

I had to comment out this line to get it to work.
======================================

Also i placed the anynews  section just after the "minislider".... and two things have happened......
a) the  news items have lost the ability to link (not click able0
b) any time the cursor goes over the news item the mini slider pictures- puse... it treats the anynews section as its own ....picture space.... possibly a jquery problem.    
Any ideas?

see       http://sprintforce.com.au                 to verify  my comment

========================================
System info:  PHP 5.2.17, WB 2.83 sp1 (1638)

Anynews code used:
------------------------------

  if (function_exists('displayNewsItems')) {
  echo displayNewsItems(
 $group_id = 0,  
 $max_news_items = 4,      
 $max_news_length = -1,  
 $display_mode = 2,            
 $lang_id = 'AUTO',            
 $strip_tags = true,            
 $allowed_tags = '<p><a><img>',
 $custom_placeholder = false,    
 $sort_by = 1,            
 $sort_order = 1,        
 $not_older_than = 0,      
 $group_id_type = 'group_id',    
 $lang_filter = false  );
}



the additional info requested is:

========================================
System info:  PHP 5.2.17, WB 2.83 sp1 (1638)

Anynews code used:
------------------------------

  if (function_exists('displayNewsItems')) {
  echo displayNewsItems(
 $group_id = 0,  
 $max_news_items = 4,    
 $max_news_length = -1,  
 $display_mode = 2,          
 $lang_id = 'AUTO',          
 $strip_tags = true,          
 $allowed_tags = '<p><a><img>',
 $custom_placeholder = false,  
 $sort_by = 1,            
 $sort_order = 1,      
 $not_older_than = 0,      
 $group_id_type = 'group_id',  
 $lang_filter = false  );
}
>>>>   fixed the problem with the "anynews" clickable-description-links...  <<<
The module "minislider" displayed just above "anynews" is a bit of a strange case... it does not really control the height of the images it displays correctly (via a .js file). So I had to insert a <style> statement in the template to restrict the height rather than allow "minislider" to think that the whole page/section is under its control... so by including the following l-style-lines- the problem is solved

#slider {
   height: 440px;
   overflow: hidden;
}

However the original problem is still there if I remove the comment from this line....
Parse error: syntax error, unexpected T_FUNCTION in /home1/gvaaeu1/public_html/..domain../modules/cwsoft-anynews/include.php on line 107 which is described in the following lines of code...

LINE 107:    $twig->addFilter(new Twig_SimpleFilter('strftime', function ($timestamp, $format, $locales) {
setlocale(LC_ALL, $locales);
return strftime($format, $timestamp);
}));

Ruud

Tested on (wamp) PHP 5.2.6 with WB 2.8.3 SP1 (1638)


Parse error: syntax error, unexpected T_FUNCTION in {removed}\wb\modules\cwsoft-anynews\include.php on line 107
[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]

cwsoft

@Ruud: Same here. At least WB + PHP version is needed to help out. Tested this morning locally on XAMPP with PHP 5.4 and WB 2.8.3 SPx and had no issues at all.

Cheers

Ruud

Same thing happeed to me..
Just installed Anynews on a (almost) clean website, and the website stopped with the same error.
There was no call to the snippet yet!
[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]

cwsoft

@xoanon: Please provide the requested information about your system and post the Anynews function call. Otherwise we can just guess whats going on here.

Infos needed: https://github.com/cwsoft/wb-cwsoft-anynews#questions

Cheers

xoanon

#135
Quote from: Argos on June 19, 2013, 12:01:15 AM
Thanks for your work!  :-)

Great work but a couple of things that happened to me....
>>>  

Just installed version 2.9 of anynews and get the following error
Parse error: syntax error, unexpected T_FUNCTION in /home1/gvaaeu1/public_html/..domain../modules/cwsoft-anynews/include.php on line 107 which is described in the following lines of code...
/**
   Add Twig filter to allow datetime conversion via PHP strftime function
   Example: {{ timestamp | strftime('%A, %B %Y', ['de_DE','german','deu']) }}
   Help on format strings: http://ch1.php.net/manual/en/function.strftime.php */

$twig->addFilter(new Twig_SimpleFilter('strftime', function ($timestamp, $format, $locales) {
setlocale(LC_ALL, $locales);
return strftime($format, $timestamp);
}));

I had to comment out this line to get it to work.
======================================

Also i placed the anynews  section just after the "minislider".... and two things have happened......
a) the  news items have lost the ability to link (not click able0
b) any time the cursor goes over the news item the mini slider pictures- puse... it treats the anynews section as its own ....picture space.... possibly a jquery problem.    
Any ideas?

see       http://sprintforce.com.au                 to verify  my comment

========================================
System info:  PHP 5.2.17, WB 2.83 sp1 (1638)

Anynews code used:
------------------------------

   if (function_exists('displayNewsItems')) {
   echo displayNewsItems(
  $group_id = 0,   
  $max_news_items = 4,     
  $max_news_length = -1,   
  $display_mode = 2,           
  $lang_id = 'AUTO',           
  $strip_tags = true,           
  $allowed_tags = '<p><a><img>',
  $custom_placeholder = false,   
  $sort_by = 1,             
  $sort_order = 1,       
  $not_older_than = 0,       
  $group_id_type = 'group_id',   
  $lang_filter = false  );
}


Argos

Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

cwsoft

#133
Hello,

cwsoft-anynews v2.9.0 stable is available at GitHub and the WebsiteBaker Add-ons repository.

Updates since last release:
- updated droplet to accept quotes around parameters (thanks to Argos for reporting)
- added timestamp placeholders for more flexible date/time conversion in template
- added Twig filter strftime for easy date/time format using locale settings (e.g. Friday, 6 May 2013)
- updated 3rd party packages to latest available version
- removed deprecated function hints from README

cwsoft

Argos

Quote from: cwsoft on May 12, 2013, 08:24:18 AM
@argos: Did removing the quotes around the cwsoft-anynews droplet parameter solve your issues with the droplet call?

Yep, everything works fine and as expected. I use your latest version now by the way, with the locale addition.
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

Argos

Thanks cwsoft, that works fine!  :-D
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

cwsoft

#130
Hi,

added the new Twig filter strftime which allows timestamp conversion via PHP strftime function to the cwsoft-anynews master branch.

Twig strftime filter:
{{ timestamp | strftime('format_string', ['array','with','supported','locals']) }}

Infos: PHP strftime, PHP setlocale

Example usage in template:

<ul>
{% for news in newsItems %}
<li>Dutch long: {{ news.TS_POSTED_WHEN | strftime('%A, %B %Y', ['nl_NL', 'dutch']) }}</li>
<li>Dutch short: {{ news.TS_POSTED_WHEN | strftime('%a, %b %y', ['nl_NL', 'dutch']) }}</li>

<li>German long: {{ news.TS_POSTED_WHEN | strftime('%A, %B %Y', ['de_DE', 'deu']) }}</li>
<li>German short: {{ news.TS_POSTED_WHEN | strftime('%a, %b %y', ['de_DE', 'deu']) }}</li>
{% endfor %}
</ul>


Parsed Anynews output:
  • Dutch long: vrijdag, mei 2013
  • Dutch short: vr, mei 13
  • German long: Freitag, Mai 2013
  • German short: Fr, Mai 13

P.S.: To convert first chars in the Dutch date to upper case, pipe the output of the strftime filter through the Twig title filter:

{{ news.TS_POSTED_WHEN | strftime('%A, %B %Y', ['nl_NL', 'dutch']) | title }}


Cheers

cwsoft

#129
Hi,

Quote from: marmot on June 10, 2013, 06:37:01 PM
Quote from: cwsoft on June 06, 2013, 07:08:59 AM
2. template TIMESTAMP fields are already converted as datestring using settings in language file
I see but tried my "solution" on two different installations and both worked  shocked, although it was not really clever to code like that.
This depends if the PHP DateTime conversion succeeds or fails. Set WB language to English and you will most likely see an error like this: "An exception has been thrown during the rendering of a template ("DateTime::__construct(): Failed to parse time string (5:02 PM, 02/09/2013) at position 5 (P)". This is due to invalid timezone / datetime string settings. Removing the comma from the Anynews EN.php will most likely do the trick for English. However, to be on the safe site, one should use the numeric TIMESTAMP.

I sometimes wish PHP would behave more like Python in some aspects:
Quote from: ZEN of python (http://www.python.org/dev/peps/pep-0020)
Errors should never pass silently. Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.

Quote from: marmot on June 10, 2013, 06:37:01 PM
Quote from: cwsoft on June 06, 2013, 07:08:59 AM
Twig provides a lot of freedom compared to the previously used template. About all requested features since introduction of Twig could be realized by a customized Template, where before people had to hack the Anynews code itself.
so what now, but I guess you will still be a fan of template engines.  :wink:
Sure, Twig still rocks.

Date conversion should be part of the view (template) and not of the model (include.php). So this has nothing to do with Twig, it's just an example of a bad design decission I made some years ago (v0.32 Jan 04 2009 to be precise), which I will fix with the next release :wink:

Cheers

marmot

Hi,

Quote from: cwsoft on June 10, 2013, 05:56:01 PM
1. month index needs to be reduced by 1 as date("m") starts with 1 but Twig arrays starts with 0
ok I missed that completely.
Quote2. template TIMESTAMP fields are already converted as datestring using settings in language file,
I see but tried my "solution" on two different installations and both worked  :-o, although it was not really clever to code like that.

Quote
this needs to be removed from include.php to allow conversion of the numeric TIMESTAMP in Twig using the date modifier
vs
Quote from: cwsoft on June 06, 2013, 07:08:59 AM
Twig provides a lot of freedom compared to the previously used template. About all requested features since introduction of Twig could be realized by a customized Template, where before people had to hack the Anynews code itself.
so what now, but I guess you will still be a fan of template engines.  :wink:

regards