Code Snippet: Display news items, anywhere

erpe0812

Yes, I noticed it yesterday too.
Hope that Aldus will correct this soon.

Thanks for posting.

rgds

erpe

doc

Hi,

the Anynews function call shown in the info section of AMASP seems to be corrupt. Think it has to do with the allowed tags <a>. Think a small bug in the edit dialoge of the module used.
http://www.websitebakers.com/pages/code-snippets/listings/anynews.php

Maybe the missing $ can be added to the README files with the next update.

Regards Doc

erpe0812

Included posted code in include.php of anynews (1.14.) but no effect.
Same error appears.

Any additional idea?

rgds

erpe

WebBird

I tried to reproduce this error, but it works for me. Tested with "All CSS" template. If you have a non-production copy of the site, try to use another template.

You can also try to add this code to include.php:


       // register outside variables
       global $wb, $database;

// AFTER ADD
                if ( ! is_object( $wb ) ) {
                    require_once(WB_PATH.'/framework/class.frontend.php');
                    // Create new frontend object
                   $wb = new frontend();
                }

erpe0812

mmhh

use the registration function with a droplet login box.

Hope this helps.

rgds

erpe

WebBird

Uhm, what do you mean saying "registration"?

erpe0812

Hi Bianka

after registration on a site I get the following parsing error::
Fatal error: Call to undefined method wb::preprocess() in /var/www/web128/html/modules/anynews/include.php on line 194   

WB 2.8
Anynews 1.12

It is curious, that this happens only after registration, the site is running well on all other pages (seems that the page stops while redirectimg, the registration is successful).

Any idea?

rgds

erpe


WebBird

Hm, maybe they (the $) are not really important, while the position of the param is, anyway. :-D

geasy

Wow, cool, herzlichen Dank für's schnelle Anpassen!

That looks perfect to me.

Regarding the missing "$" in my code: I just copied the code from the http://www.websitebakers.com/media/amasp_uploads/anynews_help_en.html. There are no "$" in the code. 
However, many thanks for your help with that!

Claudio

WebBird

So here's v1.14 for testing. :-D

* fix: replaced function to truncate long text with a (hopefully) better one
* added Serbian language file (RS.php) contributed by forum member "Mirens"
* no "read more" link shown if there's no "long text" in the news entry

Note: If you wish the "read more" link to appear in any case, remove the <!-- BEGIN readmore_link_block --> and <!-- END readmore_link_block --> block markers from the template.

I will upload this version to AMASP when I'm sure it works, so please check it out. :-D

[gelöscht durch Administrator]

WebBird

Quote from: geasy on December 27, 2009, 03:02:54 PM
As soon as I change to eg.

if (function_exists('displayNewsItems')) {
   displayNewsItems(display_mode = 1,);
}


it is not working anymore (means there is no news shown on the page anymore).

There are two errors in that code:

1. The parameters are positional. This means you will have to add all parameters _before_ $display_mode, too.
2. You missed the $ in front of display_mode.

See here:


displayNewsItems(
      $group_id = 0,
      $max_news_items = 2,
      $max_news_length = 200,
      $display_mode = 5,
      $lang_id = 'DE',
      $strip_tags = false,
      $allowed_tags = '<p><a><img>',
      $custom_placeholder = false,
      $sort_by = 1,
      $sort_order = 1,
      $not_older_than = 0
  );


So, in your case, the correct code would be:


if (function_exists('displayNewsItems')) {
   displayNewsItems(
      $group_id = 0,
      $max_news_items = 2,
      $max_news_length = 200,
      $display_mode = 1
  );
}


Just use the default values for the params you do not wish to set explicitly. (See docs for defaults.)

Quote from: geasy on December 27, 2009, 03:02:54 PM
2. No long content

Some of my news do not have a long content but the "read more" link is shown in any case. Is there a possibility that the "read more" link is only shown if there is a long content for this particular news?

This is hardcoded in the output template. So there's no simple way to do this at the moment. You could only remove that part from the template, but it will be missing then if there's long content, too.

WebBird

Quote from: dbs on December 21, 2009, 12:39:38 PM
@webbird: auf der bonsai-seite scheint die foldergallery schön sortierbar zu sein.
sind da schon neuerungen in verwendung?

Nö. Von Hand in der Datenbank gefummelt. :-D

geasy

Hi all

Just installed anynews and I'm astonished by all the functionalities includes: Cool! Congratulation to this great module.

Now, I have two little questions regarding this module:

1. Parameters
I have opened a "code section" on one of my pages. If I put in the code:

if (function_exists('displayNewsItems')) {
   displayNewsItems();
}


everything works fine. As soon as I change to eg.

if (function_exists('displayNewsItems')) {
   displayNewsItems(display_mode = 1,);
}


it is not working anymore (means there is no news shown on the page anymore). What am I doing wrong here?  :?

2. No long content

Some of my news do not have a long content but the "read more" link is shown in any case. Is there a possibility that the "read more" link is only shown if there is a long content for this particular news?

Many thanks in advance for your help.

Claudio


dbs

@webbird: auf der bonsai-seite scheint die foldergallery schön sortierbar zu sein.
sind da schon neuerungen in verwendung?

dbs
[url="https://onkel-franky.de"]https://onkel-franky.de[/url]

hansis

recht herzlichen Dank

jetzt spiele ich noch mit CSS :)

WebBird

Quote from: Mirens on December 14, 2009, 01:57:52 PM
But I dont think I can just like that delete some line of the code and everything work.
So please tell me if this what I did is not safe or something.

Well, if it works for you, just leave it. :-D

WebBird

#410
No. It's not called NextEvents. :-D

Edit: You may want to try this droplet. It creates a month calendar and takes/links the events from Event Calendar 1.8c.

https://forum.websitebaker.org/index.php/topic,15895.msg105131.html#msg105131

See it in action:

http://www.bonsai-nrw.de/cms/

hansis

Hello!

I manage my events with module "Event Calendar". At the entry site I want to display the next 3 events.
Is this possible with Any news Item?

thx.
hansi

Mirens

Thank you for your answer, oh... I'm not so familiar with PHP jet, what I manage do to is delete this line from the include.php code

$str = html_entity_decode( $str ); //first decode

and add this line

$out = html_entity_decode( $out );

&nbsp; is now converted in blank space, all lattin characters are there, all cyrilic characters are there all pictures from short story are there.
But I dont think I can just like that delete some line of the code and everything work.
So please tell me if this what I did is not safe or something.

WebBird

Thank you very much for the serbian language file. I will include it with the next release.


You may want to try the truncate() method you can find at

http://209.85.135.132/search?q=cache:byzMdc5_BK8J:https://trac.cakephp.org/ticket/2306+php+truncate+string+html&cd=2&hl=de&ct=clnk&gl=de&client=firefox-a

(Google cache, as the ticket seems to be not available anymore.)

Please note that you will have to edit the truncate()-call, too. (Line 222 ff)

Mirens

Ok, I'm trying to fix this I never used PHP, I saw today the output part of html. When script is using new added code for shortening the long text:
// New code; break at word boundary
html output is displayed like this
&lt;img width=&quot;220&quot; height=&quot;60&quot;
only text is displayed no image because html dont understand this...

When script doesnt shorten the txt i got the code like this and everything is fine
<p><img width="220" height="60"
So... I figured out that decoding is somewhere lost, I searched on google for PHP decode... and added one line of code in script

function wordwrap2( $str, $width = 75, $break = '\n', $cut = true ) {
  $str = html_entity_decode( $str ); //first decode
  $out = wordwrap( $str, $width, $break, $cut ); //now wordwrap
  $out = htmlentities( $out ); //re-encode the entities
// I added
//  $out = html_entity_decode( $out );
// end of my adding
  $out = str_replace( htmlentities( $break ), $break, $out ); //put back the break
  // return the first line
  $temp = explode( $break, $out );
  return $temp[0];
}

?>

Now everything is nice BUT now when there is &nbsp; in html code it is displayed with some strange ascii black and white questionmark. And now I'm stuck again...

Mirens

Hm I maybe have a problem  :| its probably something easy but...

This is my code

$group_id = 0, $max_news_items = 10,$max_news_length = 251, $display_mode = 1, $lang_id = 'AUTO',
$strip_tags = true, $allowed_tags = '<p><a><img>', $custom_placeholder = false,
$sort_by = 1, $sort_order = 1, $not_older_than = 0)

with $max_news_length = 251, whole message is there no nead for cutting even image from short story is there, and everything is nice like on next picture (I put this psichedelic colors for easyer understanding)
Gray color is background color for all the <p> in div anynews.

After that I made a change in $max_news_length = 250 , so the script have to cut the message and make it shorter. I change setting just for 1 character! from 251 to 250.
The image disapear from short story.
Link of that image is counted in that 250 characters (you can see there is no 1 character missing but the half of text), and gray zone iz gone, so I guess <p> disapered somehow.

I take back the maxlength setting to fit the whole short story or put it to -1 and everything is like on picture 1 nice and clean.

Is there some way I can make this to work or I'm just stupid :)
Sorry for long post but I wanted to bring as more info as I can.

Mirens

Hello people, I just downloaded this snippet and made it work like I want. Since I will be using this mostly in Serbia I made language modification because of clients. So here it is... name the file RS.php (Republic of Serbia) our internet domain is .rs and because of our characters save it as UTF-8 or whatever.
Thank you again!


<?php
/**
 * Serbian language file for the code snippet: anynews
 *
 * This code snippets grabs news from the WB news module database
 * 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 Serbian language output.
 * 
 * LICENSE: GNU General Public License 3.0
 * 
 * @author        Christian Sommer
 * @copyright    Christian Sommer (c) 2007-2009
 * @license        http://www.gnu.org/licenses/gpl.html
 * @version        1.00
 * @platform    WebsiteBaker 2.7
*/

// Serbian module description
$module_description    'WebsiteBaker modul za prikazivanje novosti na bilo kojoj stranici vašeg web site-a. Funkcija modula može biti implementirana u sam template ili putem code sekcije. Detalji i pomoć oko korišćenja ovog modula mogu se naći u samom modulu na linku <a href="{WB_URL}/modules/anynews/help/help_en.html" target="_blank">README</a>';

// declare module language array
$LANG = array();

// Tekstualni prikaz izlazne forme modula
$LANG[0] = array(
    
'TXT_HEADER'        => 'Najnovije vesti'
    
'TXT_READMORE'        => 'detaljnije'
    
'TXT_NO_NEWS'        => 'Vesti ne postoje u bazi.',
    
'TXT_NEWS'        => 'Novosti'
    
// English date/time format: (9:12 PM, 10/20/2008)
    
'DATE_FORMAT'        => ' | d.m.Y. - H:i',        
    
'TXT_REQUIREMENTS'    => 'Greška, Anynews možete koristiti samo sa WebsiteBaker verzijom 2.7 ili novijom.',        
);

?>


Stefek

[i]"Gemeinsam schafft man mehr."[/i]

[b][url=http://duden.de/rechtschreibung/gemeinsam#Bedeutung1]gemeinsam[/url][/b]
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden