Author Topic: Snippet: cwsoft-anynews  (Read 163058 times)

Offline Argos

  • Posts: 2542
  • Gender: Male
    • Argos Media
Re: Snippet: cwsoft-anynews
« Reply #125 on: June 10, 2013, 01:04:31 PM »
Thanks, but doesn't work. There is no output for the month, only the day.
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

Offline cwsoft

  • Posts: 605
Re: Snippet: cwsoft-anynews
« Reply #126 on: June 10, 2013, 05:56:01 PM »
@marmot: Your code example will work after two small updates:

1. month index needs to be reduced by 1 as date("m") starts with 1 but Twig arrays starts with 0
2. template TIMESTAMP fields are already converted as datestring using settings in language file, this needs to be removed from include.php to allow conversion of the numeric TIMESTAMP in Twig using the date modifier

Changes in template:
Code: [Select]
<div class="mod_anynews">
<h2>{{ lang.TXT_HEADER }}</h2>

{% if newsItems %}
{% set germanmonth = ["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"] %}

<ul>
{% for news in newsItems %}
<li>{{ germanmonth[news.PUBLISHED_WHEN | date("m") - 1] }}
{% endfor %}
</ul>

{% else %}
{{ lang.TXT_NO_NEWS }}
{% endif %}

</div>

Changes in include.php
Remove the date conversion from the inlcude.php to look as follows:

Code: [Select]
'POSTED_WHEN'     => $row['posted_when'],
'PUBLISHED_WHEN'  => $row['published_when'],
'PUBLISHED_UNTIL' => $row['published_until'],
'DATE_FORMAT'     => $LANG['ANYNEWS'][0]['DATE_FORMAT'],

Will most likely change this with a future release. Either by adding new fields like POSTED_WHEN_TS (timestamp) and extra field DATE_FORMAT to ensure backward compatibility with customized templates.

Cheers
« Last Edit: June 10, 2013, 05:59:26 PM by cwsoft »

Offline marmot

  • Posts: 1103
Re: Snippet: cwsoft-anynews
« Reply #127 on: June 10, 2013, 06:37:01 PM »
Hi,

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.
Quote
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  :-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
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

Offline cwsoft

  • Posts: 605
Re: Snippet: cwsoft-anynews
« Reply #128 on: June 10, 2013, 06:56:29 PM »
Hi,

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.

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
« Last Edit: June 10, 2013, 08:01:39 PM by cwsoft »

Offline cwsoft

  • Posts: 605
Re: Snippet: cwsoft-anynews
« Reply #129 on: June 11, 2013, 10:50:24 PM »
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:
Code: [Select]
<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:
Code: [Select]
{{ news.TS_POSTED_WHEN | strftime('%A, %B %Y', ['nl_NL', 'dutch']) | title }}

Cheers
« Last Edit: June 11, 2013, 11:04:47 PM by cwsoft »

Offline Argos

  • Posts: 2542
  • Gender: Male
    • Argos Media
Re: Snippet: cwsoft-anynews
« Reply #130 on: June 14, 2013, 12:48:22 PM »
Thanks cwsoft, that works fine!  :-D
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

Offline Argos

  • Posts: 2542
  • Gender: Male
    • Argos Media
Re: Snippet: cwsoft-anynews
« Reply #131 on: June 14, 2013, 03:15:09 PM »
@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!

Offline cwsoft

  • Posts: 605
cwsoft-anynews v2.9.0
« Reply #132 on: June 18, 2013, 08:18:40 PM »
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
« Last Edit: June 18, 2013, 08:30:58 PM by cwsoft »

Offline Argos

  • Posts: 2542
  • Gender: Male
    • Argos Media
Re: Snippet: cwsoft-anynews
« Reply #133 on: June 19, 2013, 12:01:15 AM »
Thanks for your work!  :-)
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

Offline xoanon

  • Posts: 34
Re: Snippet: cwsoft-anynews
« Reply #134 on: June 19, 2013, 06:44:37 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  );
}

« Last Edit: June 19, 2013, 04:39:58 PM by xoanon »

Offline cwsoft

  • Posts: 605
Re: Snippet: cwsoft-anynews
« Reply #135 on: June 19, 2013, 08:15:51 AM »
@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

Offline Ruud

  • Posts: 3663
  • Gender: Male
  • Do not use PM for help! Please use the forum!
    • Dev4Me - Professional WebsiteBaker Development
Re: Snippet: cwsoft-anynews
« Reply #136 on: June 19, 2013, 10:15:49 AM »
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!

Offline cwsoft

  • Posts: 605
Re: Snippet: cwsoft-anynews
« Reply #137 on: June 19, 2013, 10:55:59 AM »
@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

Offline Ruud

  • Posts: 3663
  • Gender: Male
  • Do not use PM for help! Please use the forum!
    • Dev4Me - Professional WebsiteBaker Development
Re: Snippet: cwsoft-anynews
« Reply #138 on: June 19, 2013, 11:15:59 AM »
Tested on (wamp) PHP 5.2.6 with WB 2.8.3 SP1 (1638)

Code: [Select]
Parse error: syntax error, unexpected T_FUNCTION in {removed}\wb\modules\cwsoft-anynews\include.php on line 107

Offline xoanon

  • Posts: 34
Re: Snippet: cwsoft-anynews
« Reply #139 on: June 19, 2013, 04:42:38 PM »
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);
}));
« Last Edit: June 20, 2013, 12:28:20 AM by xoanon »

Offline Ruud

  • Posts: 3663
  • Gender: Male
  • Do not use PM for help! Please use the forum!
    • Dev4Me - Professional WebsiteBaker Development
Re: Snippet: cwsoft-anynews
« Reply #140 on: June 20, 2013, 01:56:46 PM »
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.

Offline cwsoft

  • Posts: 605
Re: Snippet: cwsoft-anynews
« Reply #141 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.

Offline cwsoft

  • Posts: 605
Re: Snippet: cwsoft-anynews
« Reply #142 on: June 20, 2013, 08:53:22 PM »
@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):

Code: [Select]
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
« Last Edit: June 20, 2013, 08:57:24 PM by cwsoft »

Offline xoanon

  • Posts: 34
Re: Snippet: cwsoft-anynews
« Reply #143 on: June 21, 2013, 03:21:06 AM »
thanks
already changed to the new function  "getNewsItems"

Offline xoanon

  • Posts: 34
Re: Snippet: cwsoft-anynews
« Reply #144 on: June 21, 2013, 03:24:43 AM »
@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?
?

Offline cwsoft

  • Posts: 605
Re: Snippet: cwsoft-anynews
« Reply #145 on: June 21, 2013, 06:09:05 AM »
@xoanon: I changed two files:: "include.php" and "code/anynews_function.php":
https://github.com/cwsoft/wb-cwsoft-anynews/commit/8fd7175324facb2d16c65da08c93865ae8df9c0c

Cheers

Offline xoanon

  • Posts: 34
Re: Snippet: cwsoft-anynews
« Reply #146 on: June 21, 2013, 12:42:49 PM »
ok, thanks,  looks ok for display mode 1,2,3,4
but I tried display=6
with the following
a) HTML section:
Code: [Select]
[[getNewsItems?display_mode=2]]

b) CODE2 section:
Code: [Select]
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)
Code: [Select]
<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
>>>>>
Code: [Select]
[[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
« Last Edit: June 21, 2013, 01:09:10 PM by badknight »

Offline cwsoft

  • Posts: 605
Re: Snippet: cwsoft-anynews
« Reply #147 on: June 21, 2013, 09:21:04 PM »
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
« Last Edit: June 22, 2013, 08:05:04 AM by cwsoft »

Offline cwsoft

  • Posts: 605
cwsoft-anynews v2.9.1 available
« Reply #148 on: June 24, 2013, 07:49:11 PM »
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

Offline svsanchez

  • Posts: 569
Re: Snippet: cwsoft-anynews
« Reply #149 on: July 02, 2013, 01:58:13 AM »
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?