Bandit-X.Net  
ID Password
Modules : LatestNews v. 0.5 is Released
Posted by Bandit-X on Jun-16-2008 (2221 reads)

Arabxoops.com is happy to announce the release of Latest News block module.

This module displays the latest news from the news module (1.56) in a block.

Features:
1. Can set the number of articles to display, using one or more columns.
2. Can choose to display the title, author, date, comments link, and other display settings.
3. Can customize image properties in all articles (i.e. width, height, position, borders).
4. Can customize the number of letters to truncate each news item, without cutting off any words midway.

Read More. At XooPS.Org

Rating: 0.00 (0 votes) - Rate this News -


Other articles
Mar-11-2016 - Hello 2016!
Jan-01-2010 - Happy New Year 2010
Nov-13-2009 - Announcement Nov .2009
Jul-26-2008 - LatestNews v. 0.6 is Released
Jun-16-2008 - LatestNews v. 0.5 is Released

The comments are owned by the poster. We aren't responsible for their content.
Poster Thread
Bandit-X
Posted: 2008/7/22 20:34  Updated: 2008/7/22 20:34
Webmaster
Joined: 2006/6/3
From: UsA - MiChIgAn
Posts: 154
 Re: LatestNews v. 0.5 is Released
a fix for that error that appears in this module.

blocks/latestnews.php (what i added has my comment //Bandit-X )
<?php
// ######################################################################
// #                                                                    #
// # Latest News block by Mowaffak ( www.arabxoops.com )                #
// # based on Last Articles Block by Pete Glanz (www.glanz.ru)          #
// #                                                                    #
// ######################################################################
// # Use of this program is goverened by the terms of the GNU General   #
// # Public License (GPL - version 1 or 2) as published by the          #
// # Free Software Foundation (http://www.gnu.org/)                     #
// ######################################################################

function block_latestnews_show($options){
     global $xoopsTpl, $xoopsUser, $xoopsConfig;

    include_once XOOPS_ROOT_PATH.'/modules/news/class/class.newsstory.php';
    include_once XOOPS_ROOT_PATH.'/modules/news/class/class.sfiles.php';
    include_once XOOPS_ROOT_PATH.'/modules/news/class/class.newstopic.php';
    include_once XOOPS_ROOT_PATH.'/modules/news/include/functions.php';
    include_once XOOPS_ROOT_PATH.'/class/tree.php';
include_once XOOPS_ROOT_PATH.'/modules/latestnews/class/class.latestnews.php'; //Bandit-X
    if (file_exists(XOOPS_ROOT_PATH.'/modules/news/language/'.$xoopsConfig['language'].'/main.php')) {
        include_once XOOPS_ROOT_PATH.'/modules/news/language/'.$xoopsConfig['language'].'/main.php';
    }else{
        include_once XOOPS_ROOT_PATH.'/modules/news/language/english/main.php';
    }

$myts =& MyTextSanitizer::getInstance();
$dateformat=news_getmoduleoption('dateformat');
$sfiles = new sFiles();
	if($dateformat == '') {
		$dateformat = 's';
	}

//	$xt = new NewsTopic(); //Bandit-X
    $limit = $options[0];
    $column_count = $options[1];
    $letters = $options[2];
    $imgwidth = $options[3];
    $imgheight = $options[4];
    $border = $options[5];
    $bordercolor = $options[6];
    $block['spec']['columnwidth'] = intval(1/$column_count*100);
    if ($options[7] == 1) {
   	$imgposition = 'right';
    }
    if ($options[7] == 0) {
    $imgposition = 'left';
    }
    $xoopsTpl->assign( 'xoops_module_header' , '<style type="text/css">.itemText {text-align: justify;} .itemBody img { width: '.$imgwidth.'px; height: '.$imgheight.'px; border: '.$border.'px solid #'.$bordercolor.'; margin: 5px; float: '.$imgposition.'}</style>'.$xoopsTpl->get_template_vars("xoops_module_header") );

	$sarray = LatestNewsStory::LatestNewsgetAllPublished($limit, 0, true, 0, 0, true, 'published', false);//Bandit-X
    $scount = count($sarray);
    $k = 0;
    $columns = array();
    if($scount>0)
    {
    	$storieslist=array();
    	foreach ($sarray as $storyid => $thisstory) {
    		$storieslist[]=$thisstory->storyid();
    	}
		$filesperstory = $sfiles->getCountbyStories($storieslist);

	    foreach ($sarray as $key => $thisstory) {
            $storyid = $thisstory->storyid();
	    	$filescount = array_key_exists($thisstory->storyid(),$filesperstory) ? $filesperstory[$thisstory->storyid()] : 0;
            $published = formatTimestamp($thisstory->published(), $dateformat);
            $bodytext = $thisstory->bodytext;
            $news = $thisstory->latestprepare2show($filescount);//Bandit-X
            
            $len = strlen($thisstory->hometext());
            if ($letters < $len && $letters > 0){
                $letters = strrpos(substr($thisstory->hometext(),0,$letters), ' ');
                $news['text'] = xoops_substr($thisstory->hometext(), 0, $letters + 3);
            }

        	$news['news_title'] = $news['title'];

             if(is_object($xoopsUser) && $xoopsUser->isAdmin(-1)){
        	$news['admin'] = '[ <A href="'.XOOPS_URL.'/modules/news/admin/index.php?op=edit&amp;storyid='.$storyid.'">'._EDIT.'</A> | <A href="'.XOOPS_URL.'/modules/news/admin/index.php?op=delete&amp;storyid='.$storyid.'">'._DELETE.'</A> ]';
	}else{
        	$news['admin'] = '';
	}


        if ($options[8] == 1) {
        	$block['topiclink'] = '| <A HREF="'.XOOPS_URL.'/modules/news/topics_directory.php">'._AM_NEWS_TOPICS_DIRECTORY.'</A> ';
        }
       	if ($options[9] == 1) {
        	$block['archivelink'] = '| <A HREF="'.XOOPS_URL.'/modules/news/archive.php">'._NW_NEWSARCHIVES.'</A> ';
        }
        if ($options[10] == 1) {
            if (empty($xoopsUser))
            {
            	$block['submitlink'] = '';
            } else {
                    $block['submitlink'] = '| <A HREF="'.XOOPS_URL.'/modules/news/submit.php">'._NW_SUBMITNEWS.'</A> ';
            }
        }

            $news['poster'] = '';
        	if ($options[11] == 1) {
                $news['poster'] = ''._MB_LATESTNEWS_POSTER.' '.$thisstory->uname().'';
            }
	        $news['posttime'] = '';
             if ($options[12] == 1) {
             $news['posttime'] = ''._ON.' '.$published.'';
	        } 
	        $news['topic_title'] = '';
			if ($options[13] == 1) {
       			$news['topic_title'] = ''.$thisstory->textlink().''._MB_SP.'';
        	}
            $news['read'] = '';
			if ($options[14] == 1) {
                $news['read']= '&nbsp;('.$thisstory->counter.' '._READS.')';
        	}

            $comments = $thisstory->comments();
            if(!empty($bodytext) || $comments>0){
        		$news['more'] = '<A HREF="'.XOOPS_URL.'/modules/news/article.php?storyid='.$storyid.'">'._NW_READMORE.'</a>';
			}else{
        		$news['more'] = '';
			}
			if ($options[15] == 1) {
				if($comments>0){
				//shows 1 comment instead of 1 comm. if comments ==1
				//langugage file modified accordingly
	          		if ( $comments == 1 ) {
						$news['comment'] ='&nbsp;'._NW_ONECOMMENT.'</a>';
	            	} else {
						$news['comment'] ='&nbsp;'.$comments.'&nbsp;'._NW_COMMENTS.'</a>';
					}
				}else{
					$news['comment'] ='&nbsp;'._MB_NO_COMMENT.'</a>';
				}
			}

        $block['morelink'] = '<A HREF="'.XOOPS_URL.'/modules/news/index.php">'._MB_MORE_STORIES.'</A> ';
                    
        $columns[$k][] = $news;
    	$k++;
        	if ($k == $column_count) {
	            $k = 0;
        	}
		}


 	}

unset($story);
$block['columns']  = $columns;
return $block;
}
function b_latestnews_edit($options) {
		$tabletag1='<tr><td>';
		$tabletag2='</td><td>';

		$form = "<table border='0'>";
		$form .= $tabletag1._MB_LATESTNEWS_DISPLAY.$tabletag2;
		$form .= "<input type='text' name='options[]' value='".$options[0]."' size='4'>&nbsp;"._MB_LATESTNEWS."</td></tr>";
        $form .=  $tabletag1._MB_LATESTNEWS_COLUMNS.$tabletag2;
        $form .= "<input type='text' name='options[]' value='".$options[1]."' size='4'>&nbsp;"._MB_LATESTNEWS_COLUMN."</td></tr>";
        $form .=  $tabletag1._MB_LATESTNEWS_TEXTLENGTH.$tabletag2;
        $form .= "<input type='text' name='options[]' value='".$options[2]."' size='4'>&nbsp;"._MB_LATESTNEWS_LETTER."</td></tr>";
        $form .=  $tabletag1._MB_LATESTNEWS_IMGWIDTH.$tabletag2;
        $form .= "<input type='text' name='options[]' value='".$options[3]."' size='4'>&nbsp;"._MB_LATESTNEWS_PIXEL."</td></tr>";
        $form .=  $tabletag1._MB_LATESTNEWS_IMGHEIGHT.$tabletag2;
        $form .= "<input type='text' name='options[]' value='".$options[4]."' size='4'>&nbsp;"._MB_LATESTNEWS_PIXEL."</td></tr>";
        $form .=  $tabletag1._MB_LATESTNEWS_BORDER.$tabletag2;
        $form .= "<input type='text' name='options[]' value='".$options[5]."' size='4'>&nbsp;"._MB_LATESTNEWS_PIXEL."</td></tr>";
        $form .=  $tabletag1._MB_LATESTNEWS_BORDERCOLOR.$tabletag2;
        $form .= "<input type='text' name='options[]' value='".$options[6]."' size='8'></td></tr>";
     	$form .= $tabletag1._MB_LATESTNEWS_IMGPOSITION.$tabletag2;
		$form .= mk_select($options,7);
        $form .= $tabletag1._MB_LATESTNEWS_TOPICLINK.$tabletag2;
		$form .= mk_chkbox($options,8);
		$form .= $tabletag1._MB_LATESTNEWS_ARCHIVELINK.$tabletag2;
		$form .= mk_chkbox($options,9);
		$form .= $tabletag1._MB_LATESTNEWS_SUBMITLINK.$tabletag2;
		$form .= mk_chkbox($options,10);
  		$form .= $tabletag1._MB_LATESTNEWS_POSTEDBY.$tabletag2;
		$form .= mk_chkbox($options,11);
  		$form .= $tabletag1._MB_LATESTNEWS_POSTTIME.$tabletag2;
		$form .= mk_chkbox($options,12);
  		$form .= $tabletag1._MB_LATESTNEWS_TOPICTITLE.$tabletag2;
		$form .= mk_chkbox($options,13);
  		$form .= $tabletag1._MB_LATESTNEWS_READ.$tabletag2;
		$form .= mk_chkbox($options,14);
   		$form .= $tabletag1._MB_LATESTNEWS_COMMENT.$tabletag2;
		$form .= mk_chkbox($options,15);
		$form .= "</table>";
		return $form;
}

function mk_chkbox($options, $number) {
	$chk   = "";
	if ($options[$number] == 1) {
		$chk = " checked='checked'";
	}
	$chkbox = "<input type='radio' name='options[$number]' value='1'".$chk." />&nbsp;"._YES."&nbsp;&nbsp;";
	$chk   = "";
	if ($options[$number] == 0) {
		$chk = " checked='checked'";
	}
	$chkbox .= "<input type='radio' name='options[$number]' value='0'".$chk." />&nbsp;"._NO."</td></tr>";
	RETURN $chkbox;
}

function mk_select($options, $number) {
	$slc   = "";
	if ($options[$number] == 1) {
		$slc = " checked='checked'";
	}
	$select = "<input type='radio' name='options[$number]' value='1'".$slc." />&nbsp;"._LEFT."&nbsp;&nbsp;";
	$slc   = "";
	if ($options[$number] == 0) {
		$slc = " checked='checked'";
	}
	$select .= "<input type='radio' name='options[$number]' value='0'".$slc." />&nbsp;"._RIGHT."</td></tr>";
	RETURN $select;
}
?>


new file
class/class.latestnews.php
<?php
//Bandit-X
//taken from news 1.56 

class LatestNewsStory extends NewsStory{
	
	function LatestNewsStory($id=-1){
		parent::NewsStory($id);
	
	}
		/**
 	* Returns published stories according to some options
 	*/
	function LatestNewsgetAllPublished($limit=0, $start=0, $checkRight=false, $topic=0, $ihome=0, $asobject=true, $order = 'published', $topic_frontpage=false)
	{
		$db =& Database::getInstance();
		$myts =& MyTextSanitizer::getInstance();
		$ret = array();
		$sql = 'SELECT s.*, t.* FROM '.$db->prefix('stories').' s, '. $db->prefix('topics').' t WHERE (s.published > 0 AND s.published <= '.time().') AND (s.expired = 0 OR s.expired > '.time().') AND (s.topicid=t.topic_id) ';
		if ($topic != 0) {
		    if (!is_array($topic)) {
		    	if($checkRight) {
        			$topics = news_MygetItemIds('news_view');
		    		if(!in_array ($topic,$topics)) {
		    			return null;
		    		} else {
		    			$sql .= ' AND s.topicid='.intval($topic).' AND (s.ihome=1 OR s.ihome=0)';
		    		}
		    	} else {
		        	$sql .= ' AND s.topicid='.intval($topic).' AND (s.ihome=1 OR s.ihome=0)';
		        }
		    } else {
				if($checkRight) {
					$topics = news_MygetItemIds('news_view');
		    		$topic = array_intersect($topic,$topics);
		    	}
		    	if(count($topic)>0) {
		        	$sql .= ' AND s.topicid IN ('.implode(',', $topic).')';
		    	} else {
		    		return null;
		    	}
		    }
		} else {
		    if($checkRight) {
		        $topics = news_MygetItemIds('news_view');
		        if(count($topics)>0) {
		        	$topics = implode(',', $topics);
		        	$sql .= ' AND s.topicid IN ('.$topics.')';
		        } else {
		        	return null;
		        }
		    }
			if (intval($ihome) == 0) {
				$sql .= ' AND s.ihome=0';
			}
		}
		if($topic_frontpage) {
			$sql .=' AND t.topic_frontpage=1';
		}
 		$sql .= " ORDER BY s.$order DESC";
		$result = $db->query($sql,intval($limit),intval($start));

		while ( $myrow = $db->fetchArray($result) ) {
			if ($asobject) {
				$ret[] = new LatestNewsStory($myrow);
			} else {
				$ret[$myrow['storyid']] = $myts->htmlSpecialChars($myrow['title']);
			}
		}
		return $ret;
	}
	
	/**
	 * Function used to prepare an article to be showned
	 */
	function latestprepare2show($filescount)
	{
	    include_once XOOPS_ROOT_PATH.'/modules/news/include/functions.php';
	    global $xoopsUser, $xoopsConfig, $xoopsModuleConfig;
	    $myts =& MyTextSanitizer::getInstance();
	    $infotips = news_getmoduleoption('infotips');
	    $story = array();
	    $story['id'] = $this->storyid();
	    $story['poster'] = $this->uname();
	    $story['author_name'] = $this->uname();
	    $story['author_uid'] = $this->uid();
	    if ( $story['poster'] != false ) {
	        $story['poster'] = "<a href='".XOOPS_URL."/userinfo.php?uid=".$this->uid()."'>".$story['poster']."</a>";
	    } else {
			if($xoopsModuleConfig['displayname']!=3) {
				$story['poster'] = $xoopsConfig['anonymous'];
			}
	    }
		if ($xoopsModuleConfig['ratenews']) {
			$story['rating'] = number_format($this->rating(), 2);
			if ($this->votes == 1) {
				$story['votes'] = _NW_ONEVOTE;
			} else {
				$story['votes'] = sprintf(_NW_NUMVOTES,$this->votes);
			}
		}
	    $story['posttimestamp'] = $this->published();
	    $story['posttime'] = formatTimestamp($story['posttimestamp'],news_getmoduleoption('dateformat'));
		$story['topic_description'] = $myts->displayTarea($this->topic_description);

		$auto_summary = '';
		$tmp = '';
		$auto_summary = $this->auto_summary($this->bodytext(),$tmp);

	    $story['text'] = $this->hometext();
		$story['text'] = str_replace('[summary]', $auto_summary, $story['text']);

	    $introcount = strlen($story['text']);
	    $fullcount = strlen($this->bodytext());
	    $totalcount = $introcount + $fullcount;

	    $morelink = '';
	    if ( $fullcount > 1 ) {
	        $morelink .= '<a href="'.XOOPS_URL.'/modules/news/article.php?storyid='.$this->storyid().'';
	        $morelink .= '">'._NW_READMORE.'</a>';
        	$morelink .= ' | '.sprintf(_NW_BYTESMORE,$totalcount);
	        if (XOOPS_COMMENT_APPROVENONE != $xoopsModuleConfig['com_rule']) {
	            $morelink .= ' | ';
	        }
	    }
	    if (XOOPS_COMMENT_APPROVENONE != $xoopsModuleConfig['com_rule']) {
	        $ccount = $this->comments();
	        $morelink .= '<a href="'.XOOPS_URL.'/modules/news/article.php?storyid='.$this->storyid().'';
	        $morelink2 = '<a href="'.XOOPS_URL.'/modules/news/article.php?storyid='.$this->storyid().'';
	        if ( $ccount == 0 ) {
	            $morelink .= '">'._NW_COMMENTS.'</a>';
	        } else {
	            if ( $fullcount < 1 ) {
	                if ( $ccount == 1 ) {
	                    $morelink .= '">'._NW_READMORE.'</a> | '.$morelink2.'">'._NW_ONECOMMENT.'</a>';
	                } else {
	                    $morelink .= '">'._NW_READMORE.'</a> | '.$morelink2.'">';
	                    $morelink .= sprintf(_NW_NUMCOMMENTS, $ccount);
	                    $morelink .= '</a>';
	                }
	            } else {
	                if ( $ccount == 1 ) {
	                    $morelink .= '">'._NW_ONECOMMENT.'</a>';
	                } else {
	                    $morelink .= '">';
	                    $morelink .= sprintf(_NW_NUMCOMMENTS, $ccount);
	                    $morelink .= '</a>';
	                }
	            }
	        }
	    }
	    $story['morelink'] = $morelink;
	    $story['adminlink'] = '';

	    $approveprivilege = 0;
	    if($this->latest_news_is_admin_group()) {
	        $approveprivilege = 1;
	    }

	    if($xoopsModuleConfig['authoredit']==1 && (is_object($xoopsUser) && $xoopsUser->getVar('uid')==$this->uid())) {
	    	$approveprivilege = 1;
	    }
	    if ($approveprivilege) {
	        $story['adminlink'] = $this->adminlink();
	    }
	    $story['mail_link'] = 'mailto:?subject='.sprintf(_NW_INTARTICLE,$xoopsConfig['sitename']).'&amp;body='.sprintf(_NW_INTARTFOUND, $xoopsConfig['sitename']).':  '.XOOPS_URL.'/modules/news/article.php?storyid='.$this->storyid();
	    $story['imglink'] = '';
	    $story['align'] = '';
	    if ( $this->topicdisplay() ) {
	        $story['imglink'] = $this->imglink();
	        $story['align'] = $this->topicalign();
	    }
		if($infotips>0) {
			$story['infotips'] = ' title="'.news_make_infotips($this->hometext()).'"';
		} else {
			$story['infotips'] = '';
		}
	    $story['title'] = "<a href='".XOOPS_URL."/modules/news/article.php?storyid=".$this->storyid()."'".$story['infotips'].">".$this->title()."</a>";

	    $story['hits'] = $this->counter();
		if($filescount>0) {
			$story['files_attached']= true;
			$story['attached_link']="<a href='".XOOPS_URL.'/modules/news/article.php?storyid='.$this->storyid()."' title='"._NW_ATTACHEDLIB."'><img src='".XOOPS_URL.'/modules/news/images/attach.gif'."' title='"._NW_ATTACHEDLIB."'></a>";
		} else {
			$story['files_attached']= false;
			$story['attached_link']='';
		}
	    return $story;
	}
	
	function latest_news_is_admin_group(){
		global $xoopsUser;
		$module_handler =& xoops_gethandler('module');
		$xoopsModule =& $module_handler->getByDirname('news');
		if(is_object($xoopsUser)) {
			if(in_array('1',$xoopsUser->getGroups())) {
				return true;
			} else {
				if($xoopsUser->isAdmin($xoopsModule->mid())) {
					return true;
				} else {
					return false;
				}
			}
		}else{
			return false;
		}
	}
	
}



?>