Snippet: cwsoft-anynews

dimlaz

Hello,

Can please someone help since I am a beginner here.

I have two pages that contain news posts, the one of these news posts are the Latest news, which I want to display the titles and a short description on my homepage.

iI use the following code:
<?php
                   $config = array(
                   'section_id' => 8,
                   'sort_order' => 2,
                   'display_mode' => 2,   
                     );
                     echo getNewsItems($config);
                     ?>
The result is that it displayes the news from both news categories, it wont display only the Latest News category, it seems that the section_id, group_id does not work.

Can someone please help.

Thanks

cwsoft

#101
Hello,

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

Updates since last release:
- added Czech and Russian language file (thanks to forum members dana and owk444)
- updated truncate function to latest available version (thanks to dana for the hint)
- implemented more flexible parameter handling via new function getNewsItems()
- added option to invoke cwsoft-anynews via a custom Droplet (requested by owk444)

Since Version 2.8.0 the new function getNewsItems() is included, providing a more flexible configuration via a configuration array. This allows you to specifiy ONLY the parameters you want to change, without taking care of position and order of other possible parameters. To ensure backward compatibility, the function displayNewsItems() will work as before, but was marked "deprecated" in favour of the new and more flexible getNewsItems() function. It's recommended to use the latter function for all your new projects. See README for details.

Anynews Droplet:
Since Anynews v2.8.0 droplet code is included, allowing you to create your own Anynews Droplet usable in WYSIWYG editor or your template by pasting the following three code lines into the Droplet code form.

if (! file_exists(WB_PATH . '/modules/cwsoft-anynews/droplet/cwsoft-anynews-droplet.php')) return;
include(WB_PATH . '/modules/cwsoft-anynews/droplet/cwsoft-anynews-droplet.php');
return $output;


The Anynews Droplet supports all Anynews parameters (except the rarely used parameter 'custom_placeholder'). For details about the Droplet function see documentation at GitHub.

Cheers cwsoft

cwsoft

@owk444: Thanks for the Russian langauge file. Uploaded it to GitHub repository, so it will be issued with the next release.

Cheers

owk444

Thank you for droplet code! It works fine!

Description in the file translated. File attached.

cwsoft

#98
Hi,

Quote from: danaI think I have figured out where the problem is.
Great. Would be good if you could test the latest version available at GitHub and report any possible issues, as I intend to release the updated truncate version with the next Anynews version.

Quote from: owk444Here is Russian translation.
Thank you very much. Could you please also translate the module description stored in variable $module_description of the RU.php file? I will upload your language file to GitHub, once translation is complete.

Quote from: owk444No, my idea is to make a droplet, which calls displayNewsItems(), and possibility for the user to include [[cwsoft-anynews]] to wysiwyg for placing news on the some page.
Good idea, never thought about it.

As Anynews outputs the processed template directly to the screen, one would need a small change in the Anynews code to serve Anynews output as Droplet. Will most likely add a Anynews Droplet with the next Anynews release to achieve the same without "messing" with the WebsiteBaker output buffer system :wink:

Meanwhile you may want to test this quick & dirty solution (most likely conflicts with other droplets on same page):

1. go to WebsiteBaker backend / Admin-Tools / Droplets
2. press the "Add Droplet" button
3. enter the droplet name displayNewsItems and a description
4. enter the following code to the Droplet and save the result
5. invoke [[displayNewsItems]] from your WYSIWYG section

Anynews droplet code (quick & dirty):

// include cwsoft-anynews code
require_once(WB_PATH . '/modules/cwsoft-anynews/include.php');

// execute Anynews
ob_start();
displayNewsItems(
   $group_id = 0,
   $max_news_items = 10,
   $max_news_length = -1,
   $display_mode = 4,
   $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
);
$output = ob_get_contents();
ob_end_clean();

// return Anynews output
return $output;


Cheers

owk444

No, my idea is to make a droplet, which calls displayNewsItems(), and possibility for the user to include [[cwsoft-anynews]] to wysiwyg for placing news on the some page.

dana

Quote from: owk444 on February 08, 2013, 09:05:23 AM
Great module, but I want the anynews droplet for display latest news on specific wysiwyg pages, not only on "code" pages. Any ideas? I think it must be very simple droplet, but I not php programmer. :-(

I don't think I quite understand your question. You can add another section to your website so there can be both wysiwyg and code sections.

Quote from: cwsoft on February 06, 2013, 07:32:08 PM
@dana
First, I recommend NOT to modify the template files shipped with Anynews. Better create a copy of the original template ("display_mode_2.htt" --> "display_mode_5.htt") and modify the copy (remember to adapt $display_mode to the number of your template).

The actual truncate implementation was done by the WebsiteBaker community, but never fully tested for all possible use cases (e.g. multibyte encoding, malformed HTML/XML ...). Basic idea was not to cut HTML tags and single words. My initial implementation was to strip off tags and truncate plain text, which is much easier but less comfortable :wink:

Could you please check the following in your code:
a) enter PLAIN text into WB News short news filed: "this is some text, just to test"
b) set $max_news_length = 10 --> results in: "this..."
c) set $max_news_length = 11 --> results in: "this is..."

*snip*

I think I have figured out where the problem is. I have used the Lorem droplet for the news for testing purposes. So when I add a plain text, it works okay. :)

[url=http://www.dana-svedova.cz]Webdesign by Dana[/url]

owk444

Here is Russian translation.

Great module, but I want the anynews droplet for display latest news on specific wysiwyg pages, not only on "code" pages. Any ideas? I think it must be very simple droplet, but I not php programmer. :-(

cwsoft

#94
@dana: I replaced the Anynews truncate function with the latest available PHPCake version available and pushed it to GitHub. Maybe you want to give it a try.

Bear in mind that the GitHub ZIP archive needs to be unzipped and zipped without any parent folder to work with WebsiteBaker installer. For details see README at GitHub. If you install the new version, remember to backup your customized templates first, otherwise they will be overwritten.

Cheers

cwsoft

#93
@dana
First, I recommend NOT to modify the template files shipped with Anynews. Better create a copy of the original template ("display_mode_2.htt" --> "display_mode_5.htt") and modify the copy (remember to adapt $display_mode to the number of your template).

The actual truncate implementation was done by the WebsiteBaker community, but never fully tested for all possible use cases (e.g. multibyte encoding, malformed HTML/XML ...). Basic idea was not to cut HTML tags and single words. My initial implementation was to strip off tags and truncate plain text, which is much easier but less comfortable :wink:

Could you please check the following in your code:
a) enter PLAIN text into WB News short news filed: "this is some text, just to test"
b) set $max_news_length = 10 --> results in: "this..."
c) set $max_news_length = 11 --> results in: "this is..."

If I find some free time, I will have a look and maybe rework the truncate function or use the simple plain text filters provided by the Twig template lib.

If you need this feature urgent, try the following workaround:
a) set $max_news_length = -1 (to switch off truncating by Anynews)
b) do the truncation in your customized Anynews template (adapt slice(0,20) and line below to your needs)


<div class="mod_anynews">
{% if newsItems %}
<ul>
{% for news in newsItems %}
<li>
<a href="{{ news.LINK }}">
<strong>{{ news.POSTED_WHEN }} | {{ news.TITLE }}</strong><br />
{{ news.CONTENT_SHORT | slice(0,20) }}
{% if news.CONTENT_SHORT | length > 20 %}
...
{% endif %}
</a>
</li>
{% endfor %}
</ul>

{% else %}
{{ lang.TXT_NO_NEWS }}
{% endif %}
</div>


Cheers

dana

Quote from: cwsoft on February 04, 2013, 06:49:13 PM
The parameter $display_mode = 2; will only show the news TITLE in a list view and not the news text. Hence the parameter $max_news_length = XX; is not effective for this display mode. Set display mode to 1 and try again.

If you run into the same issue with display_mode = 1, please try to add the parameter $strip_tags = false to your Anynews function call. See Anynews parameter description at GitHub for details.

If the above proposals don't work for you, please report back in the forum so we can fix your issue.

Cheers cwsoft

I probably should have posted also my display_mode = 2 template, as I have edited it to suit my needs. :)

<div class="mod_anynews">

{% if newsItems %}
<ul>
{% for news in newsItems %}
<li><a href="{{ news.LINK }}"><strong>{{ news.POSTED_WHEN }} | {{ news.TITLE }}</strong><br />{{ news.CONTENT_SHORT}}</a></li>
{% endfor %}
</ul>

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

</div>


When I set display_mode to 1, the entire short news is posted, regardless of the length. $strip_tags = false did not help either. :(
[url=http://www.dana-svedova.cz]Webdesign by Dana[/url]

cwsoft

#91
Hi,

Quote from: danaHere is a Czech translation
Great, thank you very much, uploaded the Czech file to the GitHub repository. As I released Anynews 2.7.0 just yesterday, I will wait at least until WB 2.8.4 gets released before I publish a new Anynews version :wink:

Quote from: danaAlso, for some reason the $max_news_length is not working for me.
The parameter $display_mode = 2; will only show the news TITLE in a list view and not the news text. Hence the parameter $max_news_length = XX; is not effective for this display mode. Set display mode to 1 and try again.

If you run into the same issue with display_mode = 1, please try to add the parameter $strip_tags = false to your Anynews function call. See Anynews parameter description at GitHub for details.

If the above proposals don't work for you, please report back in the forum so we can fix your issue.

Cheers cwsoft

dana

Also, for some reason the $max_news_length is not working for me. I have this in my template:
Quote<?php
        if (function_exists('displayNewsItems')) {
          displayNewsItems(
            $group_id = 0,
            $max_news_items = 3,
            $max_news_length = 40,
            $display_mode = 2,
            $lang_id = 'AUTO'
          ) ;
        }
      ?>

But this displays the whole short story. When I set it to 10, it displays '...'. Any help is appreciated! :)
[url=http://www.dana-svedova.cz]Webdesign by Dana[/url]

dana

Here is a Czech translation:
<?php
/**
 * Code snippet: cwsoft-anynews
 *
 * This code snippets grabs news entries from the WebsiteBaker news
 * module and displays them on any page you want by invoking the function
 * displayNewsItems() via a page of type code or the index.php
 * file of the template.
 *
 * This file contains the English language output.
 * 
 * LICENSE: GNU General Public License 3.0
 * 
 * @platform    CMS WebsiteBaker 2.8.x
 * @package     cwsoft-anynews
 * @author      cwsoft (http://cwsoft.de)
 * @copyright   cwsoft
 * @license     http://www.gnu.org/licenses/gpl-3.0.html
*/

// Czech module description
$module_description 'Tento modul cwsoft-anynews umožňuje zobrazovat vaše aktuality ze systému WebsiteBaker na jakémkoliv místě. Funkci můžete použít v sekci Code na jakékoliv stránce nebo ve vaší šabloně v souboru index.php. Detaily viz <a href="https://github.com/cwsoft/wb-cwsoft-anynews#readme" target="_blank">GitHub</a>.';

// initialize global $LANG variable as array if needed
global $LANG;
if (! isset(
$LANG) || (isset($LANG) && ! is_array($LANG))) {
$LANG = array();
}

$LANG['ANYNEWS'][0] = array(
// text outputs for the frontend
'TXT_HEADER'             => 'Aktuality',
'TXT_READMORE'           => 'číst více',
'TXT_NO_NEWS'            => 'Nejsou k dispozici žádné aktuality.',
'TXT_NEWS'               => 'Novinky',
'TXT_NUMBER_OF_COMMENTS' => 'Počet komentářů',

// date/time format: (9:12 PM, 12/31/2012)
'DATE_FORMAT'            => 'H:i, j.n.Y'
);
[url=http://www.dana-svedova.cz]Webdesign by Dana[/url]

firefoxfx

thanks cwsoft, i copied the order from the read me and that did the trick.

cwsoft

#87
@firefoxfx

Your function parameter order seems weird. Can you please update your Anynews function parameter to match order and parameters shown in the Anynews README.

PHP is not Python and you need take care about order and number of parameters passed by. Guess your call mixes up "not_older_than" (third last parameter) with "sort_by = 1", hiding news older than 1 day.

Just a guess, so give it try.

Cheers cwsoft


firefoxfx

First off all thank for the hard work, i love this module.

I'm building a new mulitlanguage website with wb 2.8.3 rev 1638 and anynews 2.6.0 and the problem that i have is when i post a news item it shows up in anynews but only for that day. So when i'm posting a news item on 27-01-2013 and i check it back at 28-01-2013 it displays that there is no news available yet. I hope someone can help me because its driving me nuts.

Here is my template index config:

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


Anynews template config:

<div class="mod_anynews">
<h2>{{ lang.TXT_HEADER }}</h2>

{% for news in newsItems %}
<p>
<strong>{{ news.TITLE }} ({{ news.POSTED_WHEN }})</strong>
</p>

{{ news.CONTENT_SHORT}}

{% if news.CONTENT_LONG %}
<a href="{{ news.LINK }}">{{ lang.TXT_READMORE }}</a>
{% endif %}
<hr />

{% else %}
{{ lang.TXT_NO_NEWS }}
{% endfor %}

</div>


Thanks for the help

cwsoft

#85
For your information.

GitHub recently dropped support for managed downloads. Up to now I offered WebsiteBaker ready installation packages of my modules via the Repository downloads sections, which is no longer available.

It is still possible to download an archive of the latest master branch using GitHubs "ZIP button" or download older "taged" module versions via GitHub Tags section. However those archives are dynamically created by GitHub including the repository folder itself, leading to invalid "WebsiteBaker installation zip files".

As workaround, just download the latest module version from the WebsiteBaker Add-on page, or download the GitHub archive, unzip it locally and rezip it without the parent folder to make it a installable WebsiteBaker archive yourself.

Cheers

badknight

Quote from: ruebenwurzel on October 25, 2012, 08:07:46 PM
Woow,

that was easy. Sometimes one thinks to complicated.

Thanks marmot, it works like a charm.

Matthias

read the documentation from "strip_tags" strip_tags
QuoteThis parameter should not contain whitespace. strip_tags() sees a tag as a case-insensitive string between < and the first whitespace or >. It means that strip_tags("<br/>", "<br>") returns an empty string.


Ich würde gern die Welt verändern, doch Gott gibt mir den Quellcode nicht...

ruebenwurzel

Woow,

that was easy. Sometimes one thinks to complicated.

Thanks marmot, it works like a charm.

Matthias

marmot

Hi,

Quote from: ruebenwurzel on October 25, 2012, 10:51:29 AM
So it seems that the "<br />" Tag is striped althought it is allowed.
just allow the "normal form" of the tag: displayNewsItems(1,5,-1,5,'AUTO',true,'<a><br>')

regards

ruebenwurzel

Hello,

have a small problem with the paramater "allowed tags". I use the following call:

<?php
displayNewsItems
(1,5,-1,5,'AUTO',true,'<a><br />')
?>


The template is:

{% for news in newsItems %}
<a href="{{ news.LINK }}"><strong>{{ news.TITLE }}</strong></a><br />
{{ news.CONTENT_SHORT}}<br /><br />
{% endfor %}


The short content is:

<p>Sa. 15.12.2012, 16.00 Uhr<br />
Amtshauskeller Frdbg.<br />
Eintritt frei</p>


So I expect in the source code:
Sa. 15.12.2012, 16.00 Uhr<br />
Amtshauskeller Frdbg.<br />
Eintritt frei


But the result is:
Sa. 15.12.2012, 16.00 Uhr
Amtshauskeller Frdbg.
Eintritt frei


So it seems that the "<br />" Tag is striped althought it is allowed.

Matthias

cwsoft

@all: I finally renamed this thread into: "Snippet: cwsoft-anynews" and added all background information and details to the very first post in this thread.

Cheers

Bug

Good to read the whole story,

Nice to see people making stuff better,

I myself am at 90% of loading al sorts of extra's into a newsmodule, i will send you a versiosn asap, maybe you will find some inspiration to expand the anynews with some of those fields,

For instance i am adding a flexible anchorlinktext so that each item can have a 'read more about this and that' link in stead of all having 'read more', i have added two fields, one for the normal link from the page to the long item, one for the anynews,
I also added an extra short message field so that the anynewsmessage can differ from the normal short, i changed ( the old) anynews to be able to work with either {SHORT} or { SHORT2},

it would be great to see news, anynews, bakery and wysiwyg evolve a bit

cwsoft

#78
Hi,

@Bug: Thanks for taking the time to answer my questions.
The questions I raised are the ones I asked myself before deciding to go for the module name changes. Reviewing your answers to my three questions, you basically came to the same conclusion. There is no direct consequence for users e.g. issues with backward incompatible changes etc., which would have been a no go for me.

What made me a bit "angry" was your offending way of asking for the reason of the name change instead of formulating your question in a more polite and neutral way (without words like stupid) as you demanded for yourself in one of your last posts quoted below. Similar to your answer, I do not change module names just for fun and without considering possible side effects for users and customers beforehand.

Quote from: Bug on September 01, 2012, 04:28:18 PM
Dear stefek,
... redirecting me to google kinda pisses me off as it suggests you think i am choosing the easy way and whitout thinking just putting in nonsense questions, this kind of behaviour here does not do much good to the reputation of the whole community.

What justifies the name change:
I took over responsibility for my modules Anynews, Addon-File-Editor and Postits in February this year, after maintenance by previous forum members has stagnated for about 1.5 years and "modified" module versions with adaptions for latest WebsiteBaker or jQuery versions, and/or backwards incompatible changes (e.g. Anynews versions with changed function parameters) were spread around via the forum.

As a consequence, I decided in Februar 2012, to "fork" my own modules at GitHub to give them a new home with a public repository for better code and feature request tracking and easier possibilities for contributions (via GitHub fork/pull mechanism etc.), instead of the very user unfriendly way of searching the forum for "patches" and "latest versions". With the first new releases, I increased the major module version number to the next higher integer number to make the "fork" and the new start of maintenance support "visible". At this point in time I thought increasing the major version number would be sufficient.

Quote from: argosA name change takes place most of the times in case of forking. AnyNews is a well known and long lasting module, so a name change should have a real purpose. If this version differs very much from the previous ones, you could see it as a fork, leaving regular AnyNews as it is.
Since February 2012, I added around 46'000 and removed 31'000 code lines from Anynews (including Twig, header changes etc.).

The list below gives a brief overview of the "new features" added since February:
- updated jQuery file inclusion to work with newer WB versions
- added new jQuery slider plugin: "Flexslider"
- made jQuery Plugins customizable without touching external plugin files
- moved all hardcoded Anynews output to template files
- fixed broken sort by comments feature added by another forum member
- added option to filter news not only by group but also by: page, section, and post id
- added option to filter news by page language
- introduced the much more flexible template parser Twig
- updated all templates to Twig
- reworked the entire README

The name change is finally a result of all the work I put into the "forked module" since February 2012, plus some branding with my domain cwsoft.de, plus the fact that "outdated" Anynews versions (not supporting WB 2.8.x) are listed at AMASP without having control of updating the content as my request for a new AMASP account was refused, while receiving funny PMs or E-mails at the same time asking me to update those outdated modules.
Apart from that, two Anynews versions are listed at the actual WB Module repository - both with the same module name, but one for WB 2.7, the other for WB 2.8.x series only. All this is from my point of view sub-optimimal and adds confusion.

The sum of all that made me finally believe that a name change (including my branding cwsoft) is well justified. At the end it is the decision of the module author (which it's me) to choose an appropriate module name :wink:

Quote from: ArgosPLEASE NOTE: Please delete any possible existing previous Anynews module via the WebsiteBaker backend BEFORE installing the new version, as the database names have changed.
Uups, this statement was copied over from the announcement posts of the "cwsoft-postits" and "cwsoft-addon-file-editor modules". Anynews is a code snippet and does not add or change any database settings. However one should delete a previous installed Anynews module in order not to have two versions of it :wink:

Quote from: Bugfor less advanced/experienced wb-users: unclearity if this is a totally new version, just an update or a new module possibly resulting in a chaotic maze of moduleversions and variations
I think the release of modules and patches via the forum is much more chaotic than the way I started at GitHub, as all my code changes can easily be traced online (and reverted if needed). However, I do hope that some of the actual issues will sort out once the brand new WebsiteBaker repository will be officially released and the "old module repository" is shut down. Think the new repository will only list newer modules (from 2.8.x onwards).

At the time the new repository is available I would have asked for splitting the Postits and Anynews threads at my initial GitHub announcement post and to create seperate threads with the new name "cwsoft-module-name" :wink:

My final words on this topic.

Cheers