11
gooberlx
Re: How to put news on index page
  • 2004/8/20 4:34

  • gooberlx

  • Just popping in

  • Posts: 3

  • Since: 2004/8/14


well that could be done....but for some reason that didn't seem to work either, I probably need to set the start page to news....which is not what I want.

Here're my files in their current form:
*remember you'll need to update the news module from the config pages.*

news_block_top.html
<{foreach item=news from=$block.stories}>
  <
div class="itemHead"><span class="itemTitle">
      <
a href="<{$xoops_url}>/modules/news/article.php?storyid=<{$news.id}>"><{$news.title}>a>
  span>div>
  <
div class="itemBody">
    <
class="itemText"><{$news.text}>p>
  div>
  <
div class="itemFoot"><span class="itemPermaLink">
      <
a href="<{$xoops_url}>/modules/news/article.php?storyid=<{$news.id}>"><{$news.comments}>a>
  span>div>
<{/foreach}>


new_top.php
// $Id: news_top.php,v 1.1 2004/01/29 14:45:49 buennagel Exp $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                                                    //
// ------------------------------------------------------------------------- //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //

function b_news_top_show($options) {
    global 
$xoopsDB;
    
$myts =& MyTextSanitizer::getInstance();
    
$block = array();
    
$sql "SELECT storyid, title, hometext, comments, published, expired, counter FROM ".$xoopsDB->prefix("stories")." WHERE published < ".time()." AND published > 0 AND (expired = 0 OR expired > ".time().") ORDER BY ".$options[0]." DESC";
    
$result $xoopsDB->query($sql,$options[1],0);
    while ( 
$myrow $xoopsDB->fetchArray($result) ) {
        
$news = array();
        
$title $myts->makeTboxData4Show($myrow["title"]);
        if ( !
XOOPS_USE_MULTIBYTES ) {
            if (
strlen($myrow['title']) >= $options[2]) {
                
$title $myts->makeTboxData4Show(substr($myrow['title'],0,($options[2] -1)))."...";
            }
        }
        
$news['title'] = $title;
        
$text str_replace("n"""$myrow['hometext']);
        
$news['text'] = $text;
        if( 
$myrow['comments'] != ){
            
$news['comments'] = (string)$myrow['comments']." comment(s). Read More...";
        } else{
            
$news['comments'] = "Post Comment/Read More...";
        }
        
$news['id'] = $myrow['storyid'];
        if ( 
$options[0] == "published" ) {
            
$news['date'] = formatTimestamp($myrow['published'],"s");
        } elseif ( 
$options[0] == "counter" ) {
            
$news['hits'] = $myrow['counter'];
        }
        
$block['stories'][] = $news;
    }
    return 
$block;
}

function 
b_news_top_edit($options) {
    
$form ""._MB_NEWS_ORDER.";
    
$form .= ";
    if ( 
$options[0] == "published" ) {
        
$form .= " selected='selected'";
    }
    
$form .= ">"._MB_NEWS_DATE."n";
    
$form .= ";
    if(
$options[0] == "counter"){
        
$form .= " selected='selected'";
    }
    
$form .= ">"._MB_NEWS_HITS."n";
    
$form .= "n";
    
$form .= " "._MB_NEWS_DISP..$options[1]."' /> "._MB_NEWS_ARTCLS."";
    
$form .= 
"
._MB_NEWS_CHARS..$options[2]."' /> "._MB_NEWS_LENGTH."";


    return 
$form;
}
?>


Image of my start page

12
file2mail
Re: How to put news on index page
  • 2004/10/10 11:09

  • file2mail

  • Just popping in

  • Posts: 27

  • Since: 2004/5/23


gooberlx ... this works .. but the only problem for me, is that i can t get the XOOPS bb code to work ... so all my news items all have [img] this and [url=] that everywhere ..

how can i fix this?

13
file2mail
Re:How to put news on index page
  • 2004/10/14 9:08

  • file2mail

  • Just popping in

  • Posts: 27

  • Since: 2004/5/23


Alright ... so does any one else know how to process the XOOPS BB codes?
i assume it has something to do with the textsanitizer?
anyone???

14
file2mail
Re:How to put news on index page
  • 2004/10/21 10:01

  • file2mail

  • Just popping in

  • Posts: 27

  • Since: 2004/5/23


Hey guys.... so i basically figured it all out for myself...
... i basically remade the Recent News block to look almost exactly like it would if your home page was the news module...

so heres the template for news_block_new.html ... which i edited (a clone) in the Template Manager in the admin ... no need to go edit the actual file and have to update the entire module...
<{foreach item=news from=$block.stories}>
<
div class="item">
  <
div class="itemHead"><span class="itemTitle">
     <
a href="<{$xoops_url}>/modules/news/article.php?storyid=<{$news.id}>"><{$news.title}>a>
  span>div>
  <
div class="itemInfo">
    <
span class="itemPostDate"><{$news.date}>span> (<span class="itemStats"><{$news.hits}> readsspan>)
  div>
  <
div class="itemBody">
    <{
$story.imglink}>
    <
class="itemText"><{$news.text}>p>
  div>
  <
div class="itemFoot"><span class="itemPermaLink">
    <
a href="<{$xoops_url}>/modules/news/article.php?storyid=<{$news.id}>"><{$news.readmore}><{$news.comments}>a>
  span>div>div><br />
<{/foreach}>
<
hr>
<
div style="text-align: right; margin: 10px;"><b><i><a href="<{$xoops_url}>/modules/news/">[Read More News]a>i>b>div>



...and here is my modified modules/news/blocks/news_top.php
// $Id: news_top.php,v 1.1 2004/01/29 14:45:49 buennagel Exp $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //

...................

//  ------------------------------------------------------------------------ //

function b_news_top_show($options) {
    global 
$xoopsDB;
    
$myts =& MyTextSanitizer::getInstance();
    
$block = array();
    
$sql "SELECT storyid, title, [b]hometext, bodytext,[/b] published, expired, counter FROM ".$xoopsDB->prefix("stories")." WHERE published < ".time()." AND published > 0 AND (expired = 0 OR expired > ".time().") ORDER BY ".$options[0]." DESC";
    
$result $xoopsDB->query($sql,$options[1],0);
    while ( 
$myrow $xoopsDB->fetchArray($result) ) {
        
$news = array();
        
$title $myts->makeTboxData4Show($myrow["title"]);
        if ( !
XOOPS_USE_MULTIBYTES ) {
            if (
strlen($myrow['title']) >= $options[2]) {
                
$title $myts->makeTboxData4Show(substr($myrow['title'],0,($options[2] -1)))."...";
            }
        }
        
$news['title'] = $title;
[
b]        $news['text'] = $myts->displayTarea$myrow['hometext'] );
        if( 
$myrow['bodytext'] == "" ) {
            
$news['readmore'] = "";
        } else {
            
$news['readmore'] = "Read More... | ";
        }
        if( 
$myrow['comments'] != ){
            
$news['comments'] = (string)$myrow['comments']." Comment(s)";
        } else{
            
$news['comments'] = "Post Comment";
        }
        
$news['id'] = $myrow['storyid'];
        
$news['date'] = formatTimestamp($myrow['published'],"s");
        
$news['hits'] = $myrow['counter'];

        
$block['stories'][] = $news;
[/
b]    }
    return 
$block;
}

.........................

    return 
$form;
}
?>



... so its not totally complete.. i still have to add the news topic name to prefix the title area of each news post ...
...and a good advantage to this block is that it loads MUCH faster than if i had my start page as the news module... and you can also cache the block for better performance...

...i actually dont really know anything about php ... just clawing my way along ... so any comments/critique on the code is welcomed!

15
martyras
Re:How to put news on index page
  • 2004/11/28 9:26

  • martyras

  • Just popping in

  • Posts: 37

  • Since: 2004/11/1


Found a way through displaying correctly html code images and others. Although the best way is to read the database to see what preferences you've set for html, bbcodes or smilies, this is a start.

In news_top.php.

Change this:
Quote:
$news['text'] = $myts->displayTarea( $myrow['hometext'] );


With this:
Quote:
$html = 1;
$smiley = 1;
$xcodes = 1;
$news['text'] = $myts->makeTareaData4Show($myrow['hometext'],$html,$smiley,$xcodes);


Whoever finds how to display also topic name on the block or how to make it more slick, post it as I think this interests a lot of people.

Happy xooping!

16
file2mail
Re:How to put news on index page
  • 2004/12/10 1:22

  • file2mail

  • Just popping in

  • Posts: 27

  • Since: 2004/5/23


Hey... thanks alot for the suggestion...

... i have also noticed that i made a simple but important mistake earlier... i neglected to add 'comments' to mySQL table grab ... so that the comments thing wasnt working properly...

so here is my updated code for my modified modules/news/blocks/news_top.php:
............

function 
b_news_top_show($options) {
    global 
$xoopsDB;
    
$myts =& MyTextSanitizer::getInstance();
    
$block = array();
            
//should use 'topicid' for implementing News Topics in future
    
$sql "SELECT storyid, title, published, expired, counter, [b]hometext, bodytext, [u]nohtml, nosmiley, comments[/u][/b] FROM ".$xoopsDB->prefix("stories")." WHERE published < ".time()." AND published > 0 AND (expired = 0 OR expired > ".time().") ORDER BY ".$options[0]." DESC";
    
$result $xoopsDB->query($sql,$options[1],0);
    while ( 
$myrow $xoopsDB->fetchArray($result) ) {
        
$news = array();
        
$title $myts->makeTboxData4Show($myrow["title"]);
        if ( !
XOOPS_USE_MULTIBYTES ) {
            if (
strlen($myrow['title']) >= $options[2]) {
                
$title $myts->makeTboxData4Show(substr($myrow['title'],0,($options[2] -1)))."...";
            }
        }
        
$news['title'] = $title;
        [
b][u]$news['text'] = $myts->makeTareaData4Show$myrow['hometext'], !$myrow['nohtml'], !$myrow['nosmiley'], 1);[/u]
        if( 
$myrow['bodytext'] == "" ) {
            
$news['readmore'] = "";
        } else {
            
$news['readmore'] = "Read More... | ";
        }
        [
u]if( $myrow['comments'] == ){
            
$news['comments'] = "Post Comment";
        } else{
            
$news['comments'] = $myrow['comments']." Comment(s)";
        }[/
u]
        
$news['id'] = $myrow['storyid'];
            
$news['date'] = formatTimestamp($myrow['published'],"s");
            
$news['hits'] = $myrow['counter'];
        
$block['stories'][] = $news;
        
$block['numStory'] = $options[1];
    }[/
b]
    return 
$block;
}

.................


It includes the fix for displaying # of comments, and a better way than martyras's to show the html and smileys (where it depends on if you check the NO HTML or NO SMILEY options when creating a new story)
Not bad for someone who doesnt know php huh?

and also... i think a way we would be able to show the news topic in the title is to take the 'topicid' variable and also get data from some other MySQL table that has the topic names in it ... then with that we can show the topic names... but i know even lesser about SQL than php ... which is like less than nothing... someone else who knows more about php and MySQL please help?

17
martyras
Re:How to put news on index page
  • 2004/12/16 19:28

  • martyras

  • Just popping in

  • Posts: 37

  • Since: 2004/11/1


Glad you're back with an update & a fix.

I have also added poster's name and profile link.

In news_top.php changed this:
$sql "SELECT storyid, title, [u]uid[/u], published, expired, counter, hometext, bodytext, nohtml, nosmiley, comments FROM ".$xoopsDB->prefix("stories")." WHERE published < ".time()." AND published > 0 AND (expired = 0 OR expired > ".time().") ORDER BY ".$options[0]." DESC";


In news_top.php added this:
$member_handler =& xoops_gethandler('member');
$member =& $member_handler->getUser($myrow['uid']);
$uname $member->getVar('name','E'); //replace 'name' with 'uname' if you want to display the username instead of realname.
                
$news['postedby'] = $uname;
$news['postedbyid'] = $myrow['uid'];


In news_block_top.html changed this:
[u]<span class="itemPostDate">Posted by <a href="<{$xoops_url}>/userinfo.php?uid=<{$news.postedbyid}>"><{$news.postedby}>aon <{$news.date}>span> (<span class="itemStats"><{$news.hits}> readsspan>)[/u]


Still searching for topicid. Hope we'll find a way.

Login

Who's Online

384 user(s) are online (329 user(s) are browsing Support Forums)


Members: 0


Guests: 384


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits