Welcome, Guest. Please login or register.
Did you miss your activation email?
February 12, 2012, 04:53:06 AM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
149621 Posts in 21098 Topics by 7537 Members
Latest Member: lotte2
* Home Help Search Login Register
Pages: 1 ... 15 16 [17] 18 19 ... 21   Go Down
Print
Author Topic: Code Snippet: Display news items, anywhere  (Read 100201 times)
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4753



« Reply #400 on: December 11, 2009, 02:27:35 PM »

Could you please explain a little further?
Where to see and how to change in the snippet.

I hardcoded a change for myself in the inlcude.php of the snippet and produced a new PLACEHOLDER for the output. It works good for me, but I think there is a better way without changing the snippet files?

Regards,
Stefek
Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
WebBird
Guest
« Reply #401 on: December 11, 2009, 03:55:35 PM »

There are language modules (DE.php, ...) in the languages subfolder of the module. Just open one of your choice and set the array key DATE_FORMAT to the format you wish to use.

There is no parameter.
Logged
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4753



« Reply #402 on: December 11, 2009, 04:57:31 PM »

Thanks Bianka!
Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
Mirens

Offline Offline

Posts: 11


« Reply #403 on: December 12, 2009, 08:19:30 PM »

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!

Code:
<?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.',        
);

?>

Logged
Mirens

Offline Offline

Posts: 11


« Reply #404 on: December 13, 2009, 12:29:08 AM »

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

This is my code
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 Smiley
Sorry for long post but I wanted to bring as more info as I can.
Logged
Mirens

Offline Offline

Posts: 11


« Reply #405 on: December 14, 2009, 12:47:35 AM »

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
Code:
&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
Code:
<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
Code:
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...
Logged
WebBird
Guest
« Reply #406 on: December 14, 2009, 10:42:36 AM »

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)
Logged
Mirens

Offline Offline

Posts: 11


« Reply #407 on: December 14, 2009, 01:57:52 PM »

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
Code:
$str = html_entity_decode( $str ); //first decode
and add this line
Code:
$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.
Logged
hansis

Offline Offline

Posts: 33


« Reply #408 on: December 19, 2009, 11:24:28 AM »

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
Logged
WebBird
Guest
« Reply #409 on: December 20, 2009, 03:40:23 PM »

No. It's not called NextEvents. grin

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

http://www.websitebaker2.org/forum/index.php/topic,15895.msg105131.html#msg105131

See it in action:

http://www.bonsai-nrw.de/cms/
« Last Edit: December 20, 2009, 03:54:35 PM by WebBird » Logged
WebBird
Guest
« Reply #410 on: December 20, 2009, 03:41:12 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. grin
Logged
hansis

Offline Offline

Posts: 33


« Reply #411 on: December 21, 2009, 11:00:12 AM »

recht herzlichen Dank

jetzt spiele ich noch mit CSS Smiley
Logged
dbs
WebsiteBaker Org e.V.

Offline Offline

Posts: 3262


WWW
« Reply #412 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?

dbs
Logged

geasy

Offline Offline

Posts: 31


« Reply #413 on: December 27, 2009, 03:02:54 PM »

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:

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

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

Code:
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?  huh

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

Logged
WebBird
Guest
« Reply #414 on: December 28, 2009, 09:48:38 AM »

@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. grin
Logged
WebBird
Guest
« Reply #415 on: December 28, 2009, 09:57:41 AM »

As soon as I change to eg.

Code:
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:

Code:
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:

Code:
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.)

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.
Logged
WebBird
Guest
« Reply #416 on: December 28, 2009, 03:53:14 PM »

So here's v1.14 for testing. grin

* 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. grin
Logged
geasy

Offline Offline

Posts: 31


« Reply #417 on: December 29, 2009, 11:39:28 AM »

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
Logged
WebBird
Guest
« Reply #418 on: December 29, 2009, 12:52:34 PM »

Hm, maybe they (the $) are not really important, while the position of the param is, anyway. grin
Logged
WebBird
Guest
« Reply #419 on: December 29, 2009, 01:02:52 PM »

I've upgraded AnyNews at AMASP.

http://www.websitebakers.com/pages/code-snippets/listings/anynews.php?lang=EN
Logged
erpe

Offline Offline

Posts: 2077


WWW
« Reply #420 on: January 21, 2010, 03:32:34 PM »

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
Logged

WebBird
Guest
« Reply #421 on: January 21, 2010, 04:05:18 PM »

Uhm, what do you mean saying "registration"?
Logged
erpe

Offline Offline

Posts: 2077


WWW
« Reply #422 on: January 21, 2010, 04:24:44 PM »

mmhh

use the registration function with a droplet login box.

Hope this helps.

rgds

erpe
Logged

WebBird
Guest
« Reply #423 on: January 22, 2010, 11:04:06 AM »

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:

Code:
       // 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();
                }
Logged
erpe

Offline Offline

Posts: 2077


WWW
« Reply #424 on: January 22, 2010, 12:46:04 PM »

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

Any additional idea?

rgds

erpe
Logged

Pages: 1 ... 15 16 [17] 18 19 ... 21   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!