Modules: 10 hacks for the Xoops News module [english version]

Posted by: hervetOn 2006/2/25 9:10:00 9285 reads
Hello,

I have decided to publish a set of modifications (hacks) to apply to the Xoops News module.
That's a kind of FAQ


summary

- How to replace "xx bytes more" with "xx more words"
- How to have a number of articles different in the table you can see at the bottom of each article
- How to use an enhanced editor for registred users and to keep the basic Xoops editor for anonymous users
- How to change the number of meta keywowrds generated by the module
- How to forbid the module to search inside its own comments
- How to have a link to the full article's path
- How to only enable registred users to rank articles
- How to list recent articles in the same category
- How to modifiy the author's list so that it is sorted
- How to do to have your next article's number begining at 1000

To read the full article, follow below:

Bye,
Hervé


First, and before to begin, I'd like to say that you must have a minimum of knowledge before to apply such modifications. I recommend you to backup all the files you are going to modify and don't apply them directly on your website without using a test site (in local for example) How to replace "xx bytes more" with "xx more words" Be careful, you must have a Php version greater than Php 4.3 First edit this file /xoops/modules/news/language/english/main.php search this line :
define("_NW_BYTESMORE","%s bytes more");
and replace it with :
define("_NW_BYTESMORE","%s more words");
Then edit the file /xoops/module/news/class/class.newsstory.php Search for :
$morelink .= ' | '.sprintf(_NW_BYTESMORE,$totalcount);
and replace it with :
$morelink .= ' | '.sprintf(_NW_BYTESMORE,str_word_count($this->bodytext()));
If you want to remove this information from display, remove the following line (in the same file) :
$morelink .= ' | '.sprintf(_NW_BYTESMORE,$totalcount);
How to have a number of articles different in the table you can see at the bottom of each article In the page wich is used to display an article, at the bottom of the page you can display a table wich will list the last published articles. By default, the number of articles is equal to the module's option "Select the number of news items to display on top page". Edit the file /xoops/modules/news/article.php, and search for this line:
$sarray $tmparticle->getAllPublished($xoopsModuleConfig['storyhome'], 0$xoopsModuleConfig['restrictindex']);
replace it with :
$sarray $tmparticle->getAllPublished(100$xoopsModuleConfig['restrictindex']);
10 is the number of articles you want to display in the table (select what you want). How to use an enhanced editor for registred users and to keep the basic Xoops editor for anonymous users How to use an enhanced editor (like kiovi) for registred users and to keep the basic Xoops editor for anonymous users ? In the module's preferences, first select the editor to use (for example kiovi). Then edit the file /xoops/modules/news/include/functions.php Search for this line :
switch(strtolower(getmoduleoption('form_options'))){
and replace it with :
global $xoopsUser;
if(isset(
$xoopsUser) && is_object($xoopsUser)) {
$editor strtolower(getmoduleoption('form_options'));
} else {
$editor 'dhtml';
}

switch(
$editor){
Note, you can select :
$editor 'dhtml'
or
$editor 'textarea'
How to change the number of meta keywowrds generated by the module If you don't enter the meta keywords when you create an article then the module will automatically create them itself form the article's content. Actually the module create 20 keywords. If you want to change this number, edit the file /xoops/modules/news/include/functions.php, Search for this line :
$tmp=array_slice($tmp,0,20); // If you want to change the limit of keywords, change this number from 20 to what you want
In this line, replace 20 with the count of keywords you want to user. How to forbid the module to search inside its own comments By default, when you use the Xoops search, the module will search inside its articles and inside its comments. If you don't want the module to search inside the comments, edit the file /xoops/modules/include/search.inc.php, Search for this line :
$searchincomments=true;
and replace it with :
$searchincomments=false;
How to have a link to the full article's path In the page called artice.php, how to have a link wich will display the full article's path ? you just have, in the template called news_article.html, to use the Smarty variable
<{$topicpath}>
. Position it where you wan to see it. How to only enable registred users to rank articles Edit the file /xoops/modules/news/article.php, search for this line :
if (getmoduleoption('ratenews')) {
and replace it with :
if (getmoduleoption('ratenews') && (isset($xoopsUser) && is_object($xoopsUser))) {
Edit the file /xoops/modules/ratenews.php, search for this line :
// 2) Is the story published ?
and replace it with :
if(!isset($xoopsUser) || !is_object($xoopsUser)) {
redirect_header(XOOPS_URL.'/modules/news/index.php'3_NOPERM);
exit();
}

// 2) Is the story published ?
How to list recent articles in the same category Always about this table that you can find at the bottom of each article in article.php Acutally the module displays the last published articles in all the categories. It's possible to display only the last articles in the current article's category. Open the file /xoops/modules/news/article.php, then search for this line :
$sarray $tmparticle->getAllPublished($xoopsModuleConfig['storyhome'], 0$xoopsModuleConfig['restrictindex']);
and replace it with :
$sarray $tmparticle->getAllPublished($xoopsModuleConfig['storyhome'], 0$xoopsModuleConfig['restrictindex'],$article->topicid());
How to modifiy the author's list so that it is sorted When you edit and when you create an article (and if you have less than 300 users on your webiste), the module shows you a list of users on your site so that you can select the article's author. This list is created by the Xoops kernel but is has 2 drawbacks, firstly, the list is not sorted, secondly the list contains inactive users. Edit the file called /xoops/modules/news/include/storyform.inc.php then search for this line :
$sform->addElement(new XoopsFormSelectUser(_NW_AUTHOR,'author',true$newsauthor),false);
and replace it with :
$seluser = new XoopsFormSelect(_NW_AUTHOR,'author',$newsauthor);
$member_handler =& xoops_gethandler('member');
$tblusers = array();
global 
$xoopsConfig;
$critere=new Criteria('level'0'>');
$critere->setSort('uname');
$tblusers $member_handler->getUserList($critere);
$tblusers[0] = $xoopsConfig['anonymous'];
natcasesort($tblusers);
$seluser->addOptionArray($tblusers);
$sform->addElement($seluser,false);
Note, there is a quicker way to do it but it suppose to modify the Xoops kernel. How to do to have your next article's number begining at 1000 This manipulation is necessary when your site will be present in the Google news. If you have Phpmyadmin, select the table called xoops_stories (replace xoops with the prefix you choosed during the installation), then click on the tab called "Operations", in the bottom of the screen where it is written "Options for this table: ", type the value 999 and validate ! If you can't do it with your version of Phpmyadmin, launch the followin SQL query :
ALTER TABLE `xoops_storiesPACK_KEYS =0 CHECKSUM =0 DELAY_KEY_WRITE =0 AUTO_INCREMENT 999