It's late here, too, but i'm a fulltime workaholic...
So here we go:
Line numbers in files depends on the modules version. So you will sometimes get better results when searching for the sample code.
The following modifications has been tested with NewsModule 2.6.1 and 2.8. Line numbers refers to the 2.8 version.
1st of all we need to add some params to the Newsmodule.
This is done in a kind of initial module file. In CMSms it is usually the [Name_of_the_module].module.php.
So open the file modules/News/
News.module.php.
Look for a function called
SetParameters() (near line 54).
Within that function there is an if-loop:
Sample:
Code: Select all
...
global $CMS_VERSION;
$res = version_compare( $CMS_VERSION, '1.1' );
if( $res >= 0 )
{
#
# For 1.1's enhanced security checking, each
# parameter that is passed in a frontend url or
# frontend form needs to be typed here.
#
...
Within that if-loop you just need to insert the following lines to set some additional params to the Newsmodule for the frontend:
Code: Select all
### Added by NaN for NewsMenu: ###
$this->SetParameterType('newsmenu',CLEAN_STRING); // should be int, or boolean
$this->SetParameterType('parent_item',CLEAN_INT); // should be int, or boolean
$this->SetParameterType('active_item',CLEAN_INT); // should be int, or boolean
###
The comments "Added By NaN" are not for ads here but just to mark what code is no default code of the Newsmodule.
Since you need to modify your NewsModule every time you updated it, it could be useful to mark where you made what changes.
Save the file.
Next step is to tell the Newsmodule to show only articles where the newsdate is within the selected year/month.
The modules output is processed either in a function called DoAction() within the initial module file or in a separat default file that will be executed when the module is just called with the {cms_module module="Module_Name"} syntax.
The default file is always called action.default.php. The NewsModule uses the default file method.
So open modules/News/
action.default.php.
Look for the following code (near line 112):
Sample:
Code: Select all
...
$query1 .= "(".$db->IfNull('start_time',$db->DBTimeStamp(1))." < ".$db->DBTimeStamp(time()).") ";
$query2 .= "(".$db->IfNull('start_time',$db->DBTimeStamp(1))." < ".$db->DBTimeStamp(time()).") ";
if (isset($params['showarchive']) && $params['showarchive'] == true) {
$query1 .= " AND (end_time < ".$db->DBTimeStamp(time()).") ";
$query2 .= " AND (end_time < ".$db->DBTimeStamp(time()).") ";
}
...
Put the queries 1 and 2 of the first two lines into an if-loop:
Code: Select all
if($newsmenu == false) # <- if-loop added by NaN for NewsMenu; queries are original code
{
$query1 .= "(".$db->IfNull('start_time',$db->DBTimeStamp(1))." < ".$db->DBTimeStamp(time()).") ";
$query2 .= "(".$db->IfNull('start_time',$db->DBTimeStamp(1))." < ".$db->DBTimeStamp(time()).") ";
}
if (isset($params['showarchive']) && $params['showarchive'] == true) {
$query1 .= " AND (end_time < ".$db->DBTimeStamp(time()).") ";
$query2 .= " AND (end_time < ".$db->DBTimeStamp(time()).") ";
}
Before that code (near line 112) just insert the following one:
Code: Select all
### added by NaN for NewsMenu: ###
$newsmenu = false;
if(isset($params['newsmenu']) && (strtolower($params['newsmenu'])=='true' || $params['newsmenu']==true))
{
$news =& $this->GetModuleInstance('NewsMenu');
if( !$news )
{
return;
}
$parent_item = '';
if(isset($params['parent_item']))
$parent_item = $params['parent_item'];
else if(isset($news->smarty->params[$news->smarty->id.'parent_item']))
{
$parent_item = $params['parent_item'] = $news->smarty->params[$news->smarty->id.'parent_item'];
}
else
{
foreach($_GET as $key=>$val)
{
if(endswith($key,'parent_item'))
{
$parent_item = $params['parent_item'] = $val;
}
}
}
$active_item = '';
if(isset($params['active_item']))
$active_item = $params['active_item'];
else if(isset($news->smarty->params[$news->smarty->id.'active_item']))
{
$active_item = $params['active_item'] = $news->smarty->params[$news->smarty->id.'active_item'];
}
else
{
foreach($_GET as $key=>$val)
{
if(endswith($key,'active_item'))
{
$active_item = $params['active_item'] = $val;
}
}
}
if($parent_item != '')
{
if($parent_item == $active_item)
{
$news_date_min = mktime(0, 0, 0, 1, 1, $parent_item);
$news_date_max = mktime(0, 0, 0, 1, 1, $parent_item+1);
}
else
{
$news_date_min = mktime(0, 0, 0, $active_item, 1, $parent_item);
$news_date_max = mktime(0, 0, 0, $active_item+1, 1, $parent_item);
}
$query1 .= "(".$db->IfNull('start_time',$db->DBTimeStamp(1))." > ".$db->DBTimeStamp($news_date_min)." AND ";
$query1 .= $db->IfNull('start_time',$db->DBTimeStamp(1))." < ".$db->DBTimeStamp($news_date_max).") ";
$query2 .= "(".$db->IfNull('start_time',$db->DBTimeStamp(1))." > ".$db->DBTimeStamp($news_date_min)." AND ";
$query2 .= $db->IfNull('start_time',$db->DBTimeStamp(1))." < ".$db->DBTimeStamp($news_date_max).") ";
$newsmenu=true;
}
}
###
After that we just need to add some params to the details links.
Look for the following uncommented code (near line 350 before and near line 430 after modification):
Sample:
Code: Select all
...
#CreateLink($id, $action, $returnid='', $contents='', $params=array(), $warn_message='', $onlyhref=false, $inline=false, $addttext='', $targetcontentonly=false, $prettyurl='')
...
Before that code insert the following one:
Code: Select all
### Added by NaN for NewsMenu: ###
if (isset($params['parent_item']))
{
$sendtodetail['parent_item'] = $parent_item;
}
if (isset($params['active_item']))
{
$sendtodetail['active_item'] = $active_item;
}
###
The last thing is to call the NewsMenu with the new param we defined in the News.module.php:
I hope that's all.
PS: this only works if NewsMenu and NewsModule are called together.
E.g. call the News within your content and the NewsMenu within your menu area.
I think it would be a better idea to create a plugin or userdefined tag of the NewsMenu instead of a module since it doesn't need any tables etc. But i dunno how to create a plugin with that code since it's indeed late for today.
Greetings from Germany,
NaN.