am using joomla .. ,
by runnig the joomla it showing the following error in the link part
and the main error is about the parameter is expecting to a reference.
if i change it , it will not show any links
Warning: Parameter 2 to modChrome_artblock() expected to be a
reference, value given in
D:\xampp\htdocs\Site\templates\a_2\html\modules.php on
line 36
Warning: Parameter 3 to modChrome_artblock() expected to be a
reference, value given in
D:\xampp\htdocs\site\templates\a_2\html\modules.php on
line 36
and the php code on this error is
- <?php
defined('_JEXEC') or die;
if (!defined('_ARTX_FUNCTIONS'))
require_once dirname(__FILE__) . str_replace('/', DIRECTORY_SEPARATOR, '/../functions.php');
function modChrome_artstyle($module, &$params, &$attribs)
{
$style = isset($attribs['artstyle']) ? $attribs['artstyle'] : 'art-nostyle';
$styles = array(
'art-nostyle' => 'modChrome_artnostyle',
'art-block' => 'modChrome_artblock',
'art-article' => 'modChrome_artarticle',
'art-vmenu' => 'modChrome_artvmenu'
);
// moduleclass_sfx support:
// '' or 'suffix' - the default module style: custom suffix will not be added to the module tag
// but will be added to the module elements.
// ' suffix' - adds suffix to the module as well as to the module elements.
// 'art-...' - overwrites the default module style.
// 'suffix art-...' - overwrites the default style and adds suffix to the module and
// to its elements, does not add art-... to the module elements.
$classes = explode(' ', rtrim($params->get('moduleclass_sfx')));
$keys = array_keys($styles);
$art = array();
foreach ($classes as $key => $class) {
if (in_array($class, $keys)) {
$art[] = $class;
$classes[$key] = ' ';
}
}
$classes = str_replace(' ', ' ', rtrim(implode(' ', $classes)));
$style = count($art) ? array_pop($art) : $style;
$params->set('moduleclass_sfx', $classes);
> call_user_func($styles[$style], $module, $params, $attribs);
}
function modChrome_artnostyle($module, &$params, &$attribs)
{
if (!empty ($module->content)) : ?>
<!-- begin nostyle -->
<div class="art-nostyle<?php echo $params->get('moduleclass_sfx'); ?>">
<?php if ($module->showtitle != 0) : ?>
<h3><?php echo $module->title; ?></h3>
<?php endif; ?>
<!-- begin nostyle content -->
<?php echo $module->content; ?>
<!-- end nostyle content -->
</div>
<!-- end nostyle -->
<?php endif;
}
function modChrome_artblock($module, &$params, &$attribs)
{
if (!empty ($module->content))
echo artxBlock(($module->showtitle != 0) ? $module->title : '', $module->content,
$params->get('moduleclass_sfx'));
}
function modChrome_artvmenu($module, &$params, &$attribs)
{
if (!empty ($module->content)) {
if (function_exists('artxVMenuBlock'))
echo artxVMenuBlock(($module->showtitle != 0) ? $module->title : '', $module->content,
$params->get('moduleclass_sfx'));
else
echo artxBlock(($module->showtitle != 0) ? $module->title : '', $module->content,
$params->get('moduleclass_sfx'));
}
}
function modChrome_artarticle($module, &$params, &$attribs)
{
if (!empty ($module->content)) {
$data = array('classes' => $params->get('moduleclass_sfx'), 'content' => $module->content);
if ($module->showtitle != 0)
$data['header-text'] = $module->title;
echo artxPost($data);
}
}
it showing the error
call_user_func($styles[$style], $module, $params, $attribs);
try the following, it will solve your problem
Go to Module -> Advance -> Module Style -> Change "inherited" to corresponding position styles. (e.g: select art-nostyle, art-block et)
in that case you don't have to scale down Php version
*****it should open in joomla administrator, then do the above steps
You can use
function modChrome_artblock($module, $params, $attribs)
instead of
function modChrome_artblock($module, &$params, &$attribs)
Related
I want to generate HTML using PHP based on files in a specific Folder, everything works for the first File but if I add a second File, I just see:
Fatal error: Cannot redeclare getTitle() (previously declared in [path]:3) in [path].php on line 4
I understood the Problem but I don't know how to solve it. This is the PHP-Code of the main File:
foreach (glob("content/blog/*.php") as $file) {
require_once $file;
$index = str_replace("content/blog/", "", str_replace(".php", "", str_replace("img/", "", $file)));
?>
<div class="content">
<h3><?php getTitle() ?><span><?php getPublishedDate() ?></span></h3>
<p><?php getContent() ?></p>
</div>
<?php
$file = null;
}
?>
And this is the PHP-Code in every Blog-File:
<?php
function getTitle() {
echo "Lorem Ipsum 2!";
}
function getPublishedDate() {
echo "When Time has finally come";
}
function getContent() {
echo "<p>Text</p>";
}
?>
I searched for opposites of include, include_once, require or require_once. I also tried Setting the variable back to null before foreach is called again.
Thanks for any help in advance.
Define a class to store the information about one blog post.
// name this file class.blogEntry.php
class blogEntry {
var $title;
var $publishedDate;
var $content;
public function getTitle() {
return $this->title;
}
public function setTitle($title) {
$this->title = $title;
}
public function getPublishedDate() {
return $this->publishedDate;
}
public function setPublishedDate($date) {
$this->publishedDate = $date;
}
public function getContent() {
return $this->content;
}
public function setContent($content) {
$this->content = $content;
}
}
For each blog post create a simple php file to set it's different properties
$entry->setTitle("Lorem Ipsum 2!");
$entry->setPublishedDate("When Time has finally come");
$entry->setContent("<p>Text</p>");
Modify your output to use the class and the class based blog entries
require_once 'class.blogEntry.php';
foreach (glob("content/blog/*.php") as $file) {
$entry = new blogEntry();
require_once $file;
$index = str_replace("content/blog/", "", str_replace(".php", "", str_replace("img/", "", $file)));
?>
<div class="content">
<h3><?php $entry->getTitle() ?><span><?php $entry->getPublishedDate() ?></span></h3>
<p><?php $entry->getContent() ?></p>
</div>
<?php
$file = null;
}
?>
The problem is you have several files, defining the same function getTitle and you are requiring them.
Requiring or including a *.php file is like merging all the code into one single file, which explains the error, because you are requiring n files and in each of them you are defining the same functions.
You can do something like this instead of functions you can use associative array.
<?php
// blog_file_1.php
$prop = array(
'title' => "This is file 1!",
'published_date' => "When Time has finally come",
'content' => "<p>Text</p>"
);
<?php
// blog_file_2.php
$prop = array(
'title' => "This is file 2!",
'published_date' => "When Time has finally come",
'content' => "<p>Text</p>"
);
<?php
// blog.php
foreach (glob("content/blog/*.php") as $file) {
require_once $file;
$index = str_replace("content/blog/", "", str_replace(".php", "", str_replace("img/", "", $file)));
?>
<div class="content">
<h3><?php echo $prop['title'] ?><span><?php echo $prop['published_date'] ?></span></h3>
<p><?php echo $prop['content'] ?></p>
</div>
<?php
$file = null;
}
?>
I'm not sure if this will help you but maybe it will help others that might find this question as it hits what I was looking for. I was looking to exactly this a few days ago and didn't find much for a simple PHP script to generate a blog. I put this together after searching Stack for different functions (Generate gallery with links from a folder, PHP Pagination, Passing Variable from Another PHP File, Sort Files) and put this together.
Code for the main blog page
\\Blog.php
<?php
$directory = "blog/folder/";
$blogfiles = glob($directory . "*.php");
usort($blogfiles, function($file_1, $file_2)
{
$file_1 = filectime($file_1);
$file_2 = filectime($file_2);
if($file_1 == $file_2)
{
return 0;
}
return $file_2 < $file_1 ? 1 : -1;
});
$post_count = 5;
$total_pages = ceil(count($blogfiles)/$post_count);
$page = $_REQUEST['page']; ///make it dyanamic :: page num
$offset = ($page-1)*$post_count;
$files_filter = array_slice($blogfiles, $offset,$post_count);
foreach ($files_filter as $blogfile) {
ob_start();
include "$blogfile";
ob_end_clean();
echo '<div class="blog-post"><a href="'.$blogfile.'"><img src="'.$BLOG_IMG.'"><h1
class="blog-title">' . $BLOG_TITLE . '</h1></a><br><p class="blog-summary">' .
$SUMMARY . '</p></div><hr>', "\n";
}
if($total_pages > 1){
if($page > 1){
echo '<div class="blog-pagination prev-page"><a href="blog.php?page='.($page-
1).'">Prev Page</a></div>';
}
if($page != $total_pages){
echo '<div class="blog-pagination next-page"><a href="blog.php?page='.
($page+1).'">Next Page</a><div class="blog-pagination">';
}
}
?>
Here is a blog post template
\\post1.php
<?php
$DOC_TITLE = "Document Title for browser tab";
$BLOG_TITLE = "Blog Post Title";
$SUMMARY = "Page summary";
$BLOG_IMG = "/Path/to/blog/image.jpg";
require $_SERVER['DOCUMENT_ROOT'] . '/header.php'; //Pre-made HTML header in the root folder - or just replace with HTML header
?>
\\content
<?php
require $_SERVER['DOCUMENT_ROOT'] . '/footer.php'; //Pre-made HTML footer in the root folder - or just replace with HTML footer
?>
Thanks to all of you I have been able to create a variable: $mytitle from the active parent menu item in Joomla 3.
This is my code:
$menu = JFactory::getApplication()->getMenu();
$parent = $menu->getItem( $menu->getActive()->parent_id );
$parentname = $parent->title;
$parentlink = JRoute::_( $parent->link . '&Itemid=' . $parent->id );
$menulevel = $menu->getActive()->level; $activename= $menu->getActive()->title;
$mytitle = ($menulevel == 1)?$activename:$parentname;
echo $mytitle;
This works great but now I need to use it on my submenu item (VMenuBlock). The code is as follows and I cannot seem to figure out how to place the variable so that it works?
function modChrome_vmenu($module, &$params, &$attribs)
{
if (!empty ($module->content)) {
if (function_exists('VMenuBlock'))
echo VMenuBlock(($module->showtitle != 0) ? $module->title : '', $module->content,
$params->get('moduleclass_sfx'));
else
echo Block(($module->showtitle != 0) ? $module->title : '', $module->content,
$params->get('moduleclass_sfx'));
}
}
Any help is appreciated!,
Thanks!
Doug
I am using WPML language, and cant find solution for next thing:
On the Language switcher i want to hide language, lets say for example - "he", if current language is lets say for example "ar", so when we on arabic site we will not see on the selector the Hebrew, and same thing if we on Hebrew, the arabic will not display.
On shorten words: what i want is - if we on arabic site - the hebrew flag will be hidden.
What i tried:
function language_selector_flags(){
$languages = icl_get_languages('skip_missing=0');
if(!empty($languages)){
if(ICL_LANGUAGE_CODE=='en')
{
$order = array('ar'); //Specify your sort order here
}
elseif(ICL_LANGUAGE_CODE=='he')
{
$order = array('en', 'ar'); //Specify your sort order here
}
foreach ($order as $l) {
if (isset($languages[$l])) {
$l = $languages[$l]; //grab this language from the unsorted array that is returned by icl_get_languages()
//Display whatever way you want -- I'm just displaying flags in anchors (CSS: a {float:left; display:block;width:18px;height:12px;margin:0 2px;overflow:hidden;line-height:100px;})
if($l['active']) { $class = "active"; $url=""; } else { $class = ''; $url = 'href="'.$l['url'].'"'; }
echo '<a '.$url.' style="background:url('.$l['country_flag_url'].') no-repeat;" class="flag '.$class.'">';
echo $l['language_code'].'';
}
}
}
}
Its not affect at all the selector.
You can check out the plugin WPML Flag In Menu.
You could use the plugin_wpml_flag_in_menu() function from the plugin (see source code here) and replace:
// Exclude current viewing language
if( $l['language_code'] != ICL_LANGUAGE_CODE )
{
// ...
}
with
// Include only the current language
if( $l['language_code'] == ICL_LANGUAGE_CODE )
{
// ...
}
to show only the current language/flag, if I understand you correctly.
ps: If you need further assistance, you could for exampe show us the output of this debug function for the active language:
function debug_icl_active_language()
{
$languages = icl_get_languages( 'skip_missing=0' );
foreach( (array) $languages as $l )
{
if( $l['active'] )
{
printf( '<pre> Total languages: %d - Active: %s </pre>',
count( $languages ),
print_r( $l, TRUE ) );
}
}
}
i have some useful link for you, please go through it first:
http://wpml.org/forums/topic/hide-language-vs-display-hidden-languages-in-your-profile-not-working/
http://wpml.org/forums/topic/hide-one-language/
http://wpml.org/forums/topic/hiding-active-language-in-menu/
http://wpml.org/forums/topic/language-selector-how-to-hide-one-language/
thanks
function language_selector_flags(){
$languages = icl_get_languages('skip_missing=0');
if(!empty($languages)){
$filter = array();
$filter['ar'] = array( 'he' );
// set your other filters here
$active_language = null;
foreach ($languages as $l)
if($l['active']) {
$active_language = $l['language_code'];
break;
}
$filter = $active_language && isset( $filter[$active_language] ) ? $filter[$active_language] : array();
foreach ($languages as $l) {
//Display whatever way you want -- I'm just displaying flags in anchors (CSS: a {float:left; display:block;width:18px;height:12px;margin:0 2px;overflow:hidden;line-height:100px;})
if( in_array( $l['language_code'], $filter) )
continue;
if($l['active']) { $class = "active"; $url=""; } else { $class = ''; $url = 'href="'.$l['url'].'"'; }
echo '<a '.$url.' class="flag '.$class.'"><img src="', $l['country_flag_url'], '" alt="', esc_attr( $l['language_code'] ), '" /></a>';
}
}
}
EDIT: If I get this right, your client(I assume) doesn't want his customers (Israelis especiay) to know that he offer service also to the arabic speaking cusomers. If it so then you can parse the Accept-Language header and filter the language selector according the result.
I have a similar problem/issue:
On this website: https://neu.member-diving.com/
I have languages I not need in the switcher. I tried the code above, but it nothing changed so far.
So, what I would like to do is, When a client is on the one "german" page, the other german languages in the switcher should not need to be there, only the english one and the actual german one.
Where do I need to put code like
function language_selector_flags(){
$languages = icl_get_languages('skip_missing=0');
if(!empty($languages)){
$filter = array();
$filter['ar'] = array( 'he' );
// set your other filters here
$active_language = null;
foreach ($languages as $l)
if($l['active']) {
$active_language = $l['language_code'];
break;
}
$filter = $active_language && isset( $filter[$active_language] ) ? $filter[$active_language] : array();
foreach ($languages as $l) {
//Display whatever way you want -- I'm just displaying flags in anchors (CSS: a {float:left; display:block;width:18px;height:12px;margin:0 2px;overflow:hidden;line-height:100px;})
if( in_array( $l['language_code'], $filter) )
continue;
if($l['active']) { $class = "active"; $url=""; } else { $class = ''; $url = 'href="'.$l['url'].'"'; }
echo '<a '.$url.' class="flag '.$class.'"><img src="', $l['country_flag_url'], '" alt="', esc_attr( $l['language_code'] ), '" /></a>';
}
}
}
i'm currently trying to modify a module that works almost perfectly for my requirements, but lacks pagination. I can't seem to grasp how i should add the pagination to it; most JPagination examples assume i have access to the query but in this module (which uses JFactory, JmoduleHelper & JModel) i don't see the query in order to add the limits and such.
mod_otmininews.php
//No direct access!
defined('_JEXEC') or die;
// Include the syndicate functions only once
require_once dirname(__FILE__).DS.'helper.php';
$doc = &JFactory::getDocument();
$doc->addStyleSheet(JURI::base().'/modules/mod_otmininews/css/layout.css');
$list = modOtMiniNewsHelper::getList($params);
$moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx'));
require JModuleHelper::getLayoutPath('mod_otmininews', $params->get('layout', 'default'));
helper.php
//No direct access!
defined('_JEXEC') or die;
require_once JPATH_SITE.'/components/com_content/helpers/route.php';
jimport('joomla.application.component.model');
JModel::addIncludePath(JPATH_SITE.'/components/com_content/models');
abstract class modOtMiniNewsHelper
{
public static function getList(&$params)
{
// Get the dbo
$db = JFactory::getDbo();
// Get an instance of the generic articles model
$model = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
// Set application parameters in model
$app = JFactory::getApplication();
$appParams = $app->getParams();
$model->setState('params', $appParams);
// Set the filters based on the module params
$model->setState('list.start', 0);
$model->setState('list.limit', (int) $params->get('count', 3));
$model->setState('filter.published', 1);
// Access filter
$access = !JComponentHelper::getParams('com_content')->get('show_noauth');
$authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
$model->setState('filter.access', $access);
// Category filter
$model->setState('filter.category_id', $params->get('catid', array()));
// User filter
$userId = JFactory::getUser()->get('id');
switch ($params->get('user_id'))
{
case 'by_me':
$model->setState('filter.author_id', (int) $userId);
break;
case 'not_me':
$model->setState('filter.author_id', $userId);
$model->setState('filter.author_id.include', false);
break;
case '0':
break;
default:
$model->setState('filter.author_id', (int) $params->get('user_id'));
break;
}
// Filter by language
$model->setState('filter.language',$app->getLanguageFilter());
// Featured switch
switch ($params->get('show_featured'))
{
case '1':
$model->setState('filter.featured', 'only');
break;
case '0':
$model->setState('filter.featured', 'hide');
break;
default:
$model->setState('filter.featured', 'show');
break;
}
// Set ordering
$order_map = array(
'm_dsc' => 'a.modified DESC, a.created',
'mc_dsc' => 'CASE WHEN (a.modified = '.$db->quote($db->getNullDate()).') THEN a.created ELSE a.modified END',
'c_dsc' => 'a.created',
'p_dsc' => 'a.publish_up',
'h_dsc' => 'a.hits',
);
$ordering = JArrayHelper::getValue($order_map, $params->get('ordering'), 'a.publish_up');
$dir = 'DESC';
$model->setState('list.ordering', $ordering);
$model->setState('list.direction', $dir);
$items = $model->getItems();
foreach ($items as &$item) {
$item->slug = $item->id.':'.$item->alias;
$item->catslug = $item->catid.':'.$item->category_alias;
if ($access || in_array($item->access, $authorised))
{
// We know that user has the privilege to view the article
$item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug));
}
else {
$item->link = JRoute::_('index.php?option=com_user&view=login');
}
//$item->title = htmlspecialchars( $item->title );
$item->content= strip_tags(preg_replace('/<img([^>]+)>/i',"",$item->introtext));
$item->content = substr($item->content, 0, $params->get('introtext_limit'));
preg_match_all('/img.+src="([^"]+)"/i', $item->introtext, $matches);
if(empty($matches[1][0])){
$item->images="";
}else{
$item->images= $matches [1] [0];
}
//Show thumbnails
if($params->get('showthumbnails')==1){
if($item->images == ""){
$item->thumbnail = '<img src="'.$params->get('directory_thumbdefault').'" width="'.$params->get('thumbwidth').'" height="'.$params->get('thumbheight').'" alt="'.$item->title.'" />';
}else{
$item->thumbnail = '<img src="' .$item->images.'" width="'.$params->get('thumbwidth').'" height="'.$params->get('thumbheight').'" alt="'.$item->title.'" />' ; //show images
}
}
$item->created_date = $item->created;
}
return $items;
}
}
All this code creates an array used by
default.php
defined('_JEXEC') or die;
?>
<div class="ot_news">
<div class="ot_news_i">
<?php
$count = 0;
foreach ($list as $item) : ?>
<?php $count++; ?>
<div class="ot_items <?php echo ($params->get('count') == $count)?'last-item':''; ?>">
<!-- Show thumbnails -->
<?php if($params->get('showthumbnails') == 1){?>
<div class="ot_thumbs" style="width:<?php echo $params->get('thumbwidth')?>px; height:<?php echo $params->get('thumbheight')?>px;">
<?php if($params->get('enablelinkthumb') == 1) {?>
<?php echo $item->thumbnail ;?>
<?php } else { ?>
<?php echo $item->thumbnail?>
<?php }?>
</div>
<?php } else { ?>
<?php echo ''; ?>
<?php } ?>
<!-- End -->
<!-- Show Titles -->
<div class="ot_articles">
<?php if($params->get('showtitle') == 1) { ?>
<div class="ot_title">
<?php if($params->get('enablelinktitle') == 1) { ?>
<?php echo $item->title; ?>
<?php }else{?>
<span class="title"><?php echo $item->title; ?></span>
<?php }?>
</div>
<?php } ?>
<!-- Show Created Date -->
<?php
if ($params->get('show_date') == 1) {
echo '<p class="createddate"><span class="ot_date">';
$date = $item->created_date;
echo JHTML::_('date', $date, $params->get( 'date_format' ));
echo '</span></p>';
}
?>
<!-- Show Content -->
<div class="ot_content"><?php echo $item->content; ?></div>
<!-- Show Readmore -->
<?php if($params->get('readmore') == 1) {?>
<div class="ot_readmore"><?php echo JText::_('READMORE') ?></div>
<?php }else {?>
<?php echo ''; ?>
<?php } ?>
</div>
</div>
<div class="spaces"></div>
<?php endforeach; ?>
</div>
</div>
<div class="ot-mini-news"><?php echo JText::_('ABOUT_OT_MINI_NEWS'); ?></div>
that just uses a for each to show the items with their photos links and descriptions.
So as you can see i have seriously no clue where to add the Pagination code, and i suspect they even use some part of it for the display (i saw a getlist function in the helper.php file.
Any help would be much appreciated.
http://docs.joomla.org/Using_JPagination_in_your_component This is a highly useful document for this - even though this is for a module and the wiki page is using it for a component.
$db =& JFactory::getDBO();
$lim = $mainframe->getUserStateFromRequest("$option.limit", 'limit', 14, 'int'); //I guess getUserStateFromRequest is for session or different reasons
$lim0 = JRequest::getVar('limitstart', 0, '', 'int');
$db->setQuery('SELECT SQL_CALC_FOUND_ROWS x, y, z FROM jos_content WHERE x',$lim0, $lim);
$rL=&$db->loadAssocList();
if (empty($rL)) {$jAp->enqueueMessage($db->getErrorMsg(),'error'); return;}
else {
////Here the beauty starts
$db->setQuery('SELECT FOUND_ROWS();'); //no reloading the query! Just asking for total without limit
jimport('joomla.html.pagination');
$pageNav = new JPagination( $db->loadResult(), $lim0, $lim );
foreach($rL as $r) {
//your display code here
}
echo $pageNav->getListFooter( ); //Displays a nice footer
You can see in their code that whilst they do use the db result, that the pagination doesn't 'depend' on the query. Only the results which come from it. So for the $db->loadResult() for example you can just use a php count forumla to see how many rows there are in the array being produced by the module. In your case counting the number of $items.
The foreach command is still as you have it as well. With just the foreach($rL as $r) just corresponding to the existing foreach($items as $item). So the fact you don't have the database query as you see - shouldn't actually be an issue!
So the code you want will be something like:
global $option; //If Joomla 1.5
global $mainframe; //If Joomla 2.5
$option = JRequest::getCmd('option') //If Joomla 2.5
$mainframe = JFactory::getApplication(); //If Joomla 2.5
$lim = $mainframe->getUserStateFromRequest("$option.limit", 'limit', 14, 'int'); //I guess getUserStateFromRequest is for session or different reasons
$lim0 = JRequest::getVar('limitstart', 0, '', 'int');
if (empty($items)) {
$app->enqueueMessage($db->getErrorMsg(),'error');
return;
} else {
jimport('joomla.html.pagination');
$pageNav = new JPagination( count($list), $lim0, $lim );
foreach($list as $item) {
//wrap in your code here that you had in the foreach already
}
echo $pageNav->getListFooter( ); //Displays a nice footer
Make sure you remove one of the top two lines depending on whether you're using Joomla 1.5 or 2.5 but that should work.
I have a code which is completed and I want to add another code inside my completed code.
completed code:
function module( $prefix, $comma_seperated_suffixes ) {
foreach( (array)explode( ",", $comma_seperated_suffixes ) as $suffix ) {
$module_name = $prefix.trim($suffix);
if(count(JModuleHelper::getModules($module_name))) {
module_block($module_name);
}
}
}
I moved count(JModuleHelper::getModules($module_name)) to module function, previously it was in module_block
please dont use tovolt class, I mean simple code without php class
Module count block
i am assuming That I am calling this modules module("top-col-", "1,2,3"); then I have three modules called top-col-1, top-col-2, top-col-3
then my count module will look like this:
$TopCol1 = (int)(count(JModuleHelper::getModules($module_name)) > 0);
$TopCol2 = (int)(count(JModuleHelper::getModules($module_name)) > 0);
$TopCol3 = (int)(count(JModuleHelper::getModules($module_name)) > 0);
above code is will just count for active module (the only way to check active module), If a module is active then its var will be 1 .
and now the time to count active module:
$topColCount = $TopCol1 + $TopCol2 + $TopCol3;
if ($topColCount) : $TopColClass = 'count-' . $topColCount;
endif;
I am counting modules case I want to set a CSS class like this count-1, count-2, count-3 to active modules. and I want that class to be used in module_block.
please keep in mind that, above variable is static cause I made them manually. but if I call function then var need to be change with the function value like if user call module("bottom", "1,2,3"); then its count_modules will be $bottom1, $bottom2, $bottom3 and class will be $bottomClass.
I want to generate count_module using the same code module("bottom", "1,2,3");
Thanks #steve for your help
If I am understanding this correctly, this should help.
tovolt class: (note the new function 'prep_modules' added to this class)
<?php
////////////////// BEGIN CLASS tovolt
class tovolt{
function tovolt() {
//// constructor function - used to setup default variable states, etc. - if this is omitted PHP may have a fit ( depending on version and config )
}
public static $TopColClass = 'default-value';
function code_block( $jdoc_name ) {
?>
<div id="top-col" class="<?php echo self::$TopColClass; ?> columns">
<div class="panel">
<jdoc:include type="modules" name="<?php echo $jdoc_name; ?>" style="html5" />
</div>
</div>
<?php
}
function module( $prefix, $comma_seperated_suffixes ) {
foreach( (array)explode( ",", $comma_seperated_suffixes ) as $suffix ) {
$module_name = $prefix.trim($suffix);
self::code_block( $module_name );
}
}
////////////////// BEGIN NEW FUNCTIONS
function prep_modules( $MODULE_LIST ) {
$READY_MODULES = array();
foreach( (array)$MODULE_LIST as $module_name ) {
$MATCHED_MODULES = JModuleHelper::getModules($module_name);
$matched_count = count( $MATCHED_MODULES );
$matched_list = implode( ',', range( 1, $matched_count ) );
$READY_MODULES[$module_name] = array(
'MODULES' => $MATCHED_MODULES,
'count' => $matched_count,
'list' => $matched_list,
);
}
}
////////////////// END NEW FUNCTIONS
}
////////////////// END CLASS tovolt
?>
content page code - near top: (prepare this page's modules)
////////////////// SOMEWHERE BEFORE THE OUTPUT SECTION, LOAD MODULES FOR THIS PAGE
$READY_MODULES = tovolt::prep_modules( 'top', 'side', 'etc' );
content page code - content output area: ( choose the method that best fits your design )
method 1 - output a single section:
////////////////// DOWN IN THE MODULE OUTPUT SECTION - TO OUTPUT A SINGLE SECTION USE:
$section = 'top';
if( #$READY_MODULES[$section]['count'] > 0 ) {
tovolt::$TopColClass = $section; //// if you need to change: $TopColClass
tovolt::module( $section."-col-", $READY_MODULES[$section]['list'] );
}
method 2 - output all in order of loading:
////////////////// DOWN IN THE MODULE OUTPUT SECTION - TO OUTPUT ALL SECTIONS IN LOADED SEQUENCE USE:
foreach( (array)$READY_MODULES as $section=>$THIS_VAR_IS_NOT_DIRECTLY_REFERENCED ) {
if( #$READY_MODULES[$section]['count'] > 0 ) {
tovolt::$TopColClass = $section; //// if you need to change: $TopColClass
tovolt::module( $section."-col-", $READY_MODULES[$section]['list'] );
}
}
method 3 - arbitrary output:
////////////////// DOWN IN THE MODULE OUTPUT SECTION - TO OUTPUT MULTIPLE SECTIONS IN AN ARBITRARY ORDER:
foreach( array( 'side', 'top' ) as $section ) {
if( #$READY_MODULES[$section]['count'] > 0 ) {
tovolt::$TopColClass = $section; //// if you need to change: $TopColClass
tovolt::module( $section."-col-", $READY_MODULES[$section]['list'] );
}
}