1
tatane
smarty
  • 2012/7/30 12:19

  • tatane

  • Just can't stay away

  • Posts: 649

  • Since: 2008/5/6 1


Hello
I am looking for smaty in the news module displays the number of comments of an article. I looked in the storm Newsitem.html and it appears that the number of posted comments is managed from story.morelink. Only this smarty is the edit line. Have you any idea?

Resized Image


thank you

2
irmtfan
Re: smarty
  • 2012/7/31 5:40

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


sorry tatane but it is not easy because even the latest news 1.67 have many many hardcodes more than any other module. newbb is far more better or may be the best one i see.
These hardcodes make it hard to change, add features and customize the needs.

for doing this you should see the below and struggle with codes to define new smarty variables for your needs:
in news/class/class.newsstory.php
$morelink '';
        if ( 
$fullcount ) {
            
$morelink .= '.XOOPS_URL.'/modules/news/article.php?storyid='.$this->storyid().'';
            
$morelink .= '">'._NW_READMORE.'';
            
$morelink .= ' | '.sprintf(_NW_BYTESMORE,$totalcount);
            if (
XOOPS_COMMENT_APPROVENONE != $xoopsModuleConfig['com_rule']) {
                
$morelink .= ' | ';
            }
        }
        if (
XOOPS_COMMENT_APPROVENONE != $xoopsModuleConfig['com_rule']) {
            
$ccount $this->comments();
            
$morelink .= '.XOOPS_URL.'/modules/news/article.php?storyid='.$this->storyid().'';
            
$morelink2 '.XOOPS_URL.'/modules/news/article.php?storyid='.$this->storyid().'';
            if ( 
$ccount == ) {
                
$morelink .= '">'._NW_COMMENTS.'';
            } else {
                if ( 
$fullcount ) {
                    if ( 
$ccount == ) {
                        
$morelink .= '">'._NW_READMORE.' | '.$morelink2.'">'._NW_ONECOMMENT.'';
                    } else {
                        
$morelink .= '">'._NW_READMORE.' | '.$morelink2.'">';
                        
$morelink .= sprintf(_NW_NUMCOMMENTS$ccount);
                        
$morelink .= '';
                    }
                } else {
                    if ( 
$ccount == ) {
                        
$morelink .= '">'._NW_ONECOMMENT.'';
                    } else {
                        
$morelink .= '">';
                        
$morelink .= sprintf(_NW_NUMCOMMENTS$ccount);
                        
$morelink .= '';
                    }
                }
            }
        }
        
$story['morelink'] = $morelink;

you can see it is completely hardcoded. many html codes and values are assigned to just one smart variable "morelink"

3
luciorota
Re: smarty
  • 2012/7/31 8:29

  • luciorota

  • Module Developer

  • Posts: 216

  • Since: 2007/4/20


A small tip
It possible, but not easy, use a regular expression to extract a value using some Smarty variable modifiers like regex_replace.

Here a small exemple:
<{$story.morelink|regex_replace:"/XOOPS_URL/modules/news/article.php?storyid=/":""}>


more info here: http://www.smarty.net/docs/en/language.modifier.regex.replace.tpl

Here you can find a useful tool http://www.weitz.de/regex-coach/ to test your regular expression


4
tatane
Re: smarty
  • 2012/7/31 8:33

  • tatane

  • Just can't stay away

  • Posts: 649

  • Since: 2008/5/6 1


pity that the function has not been separated during the creation of the class

5
irmtfan
Re: smarty
  • 2012/7/31 10:00

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


dont be unhappy my friend.
fortunately, today i had time for you and it just take one hour to show you how you can remove at least this one hardcode.

1- in news/language/YOUR_LANG/main.php change the following:
// START hacked by irmtfan
define('_NW_ONECOMMENT',"comment");
// END hacked by irmtfan

define('_NW_BYTESMORE',"%s bytes more");
// START hacked by irmtfan
define('_NW_NUMCOMMENTS',"comments");
// END hacked by irmtfan


2- in news/class/class.newsstory.php change the following:
$morelink '';
        if ( 
$fullcount ) {
            
$morelink .= '.XOOPS_URL.'/modules/news/article.php?storyid='.$this->storyid().'';
            
$morelink .= '">'._NW_READMORE.'';
            
$morelink .= ' | '.sprintf(_NW_BYTESMORE,$totalcount);
            if (
XOOPS_COMMENT_APPROVENONE != $xoopsModuleConfig['com_rule']) {
                
$morelink .= ' | ';
            }
        }
        if (
XOOPS_COMMENT_APPROVENONE != $xoopsModuleConfig['com_rule']) {
            
$ccount $this->comments();
            
$morelink .= '.XOOPS_URL.'/modules/news/article.php?storyid='.$this->storyid().'';
            
$morelink2 '.XOOPS_URL.'/modules/news/article.php?storyid='.$this->storyid().'';
            if ( 
$ccount == ) {
                
$morelink .= '">'._NW_COMMENTS.'';
            } else {
                if ( 
$fullcount ) {
                    
// START hacked by irmtfan
                    //if ( $ccount == 1 ) {
                    //    $morelink .= '">'._NW_READMORE.' | '.$morelink2.'">'._NW_ONECOMMENT.'';
                    //} else {
                          
$morelink .= '">'._NW_READMORE.' | '.$morelink2.'">';
                    
//    $morelink .= sprintf(_NW_NUMCOMMENTS, $ccount);
                          
$morelink .= '';
                    
//}
                
} else {
                    
//if ( $ccount == 1 ) {
                    //    $morelink .= '">'._NW_ONECOMMENT.'';
                    //} else {
                        
$morelink .= '">';
                    
//    $morelink .= sprintf(_NW_NUMCOMMENTS, $ccount);
                        
$morelink .= '';
                    
//}
                    // END hacked by irmtfan
                    
                
}
            }
        }
           
// START hacked by irmtfan
        
$story['numcomments'] = $ccount;
           
// END hacked by irmtfan
        
$story['morelink'] = $morelink;


3- then in news/templates/news_item.html change the following:

        itemPermaLink"><{$story.morelink}> <{if $story.numcomments gt 0}> <{$story.numcomments}> <{if $story.numcomments gt 1}> <{$smarty.const._NW_NUMCOMMENTS}> <{else}> <{$smarty.const._NW_ONECOMMENT}> <{/if}> <{/if}>
        


you can see the right way of doing that. One smarty variable should only used for one php variable.

Edit:
by the way, english language is weak in this point because it needs to add a "s" to make a countable word plural (1 comment and 2 comments) . in persian we dont have this obstacle! (comment=nazar and comments=nazar)

IMO the best way for localize it for languages like english is adding a "s" suffix that can be used in such a situation. eg:
for english:
define("_COUNT_SUFFIX","s");

for persian:
define("_COUNT_SUFFIX","");

6
luciorota
Re: smarty
  • 2012/7/31 11:08

  • luciorota

  • Module Developer

  • Posts: 216

  • Since: 2007/4/20


try this code in "news_item.html" template

<{$story.morelink|regex_replace:'/$/':''|regex_replace:'/^/':''}>

7
playsome
Re: smarty
  • 2012/7/31 12:54

  • playsome

  • Not too shy to talk

  • Posts: 197

  • Since: 2009/4/15


I think this is something that needs to be addressed, I think no HTML elements or CSS should be hardcoded into module php files, it kind of defeats the purpose of using templates surely?

As a fairly experienced xoops user (templates side of things), I often have to edit and modify templates for various projects, for example right now I am modifying templates for extcal to make them cleaner and to use divs instead of tables (except for month/week calendar view). I have also modified xcgal templates to use divs instead of tables so that I can make them responsive. But having to dig through tons of php code to find some HTML can be annoying and time consuming.

I would also propose that module smarty variables are global (global to the module), example I can only use the smarty variable for xcgal album title in certain templates, I can't use it in the header template for example.

Luckily there is smarty modifiers that can be used for some instances but I think module devs should think about the above two points to make modules easier to customize for the average end user who only knows HTML & CSS.

8
Mamba
Re: smarty
  • 2012/7/31 13:19

  • Mamba

  • Moderator

  • Posts: 11409

  • Since: 2004/4/23


Quote:
I think this is something that needs to be addressed, I think no HTML elements or CSS should be hardcoded into module php files, it kind of defeats the purpose of using templates surely?

You're absolutely correct, and at least for the Core, this is the goal of XOOPS 2.6.0

In case of modules, the module developers have to do the code clean-up themselves.
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

9
tatane
Re: smarty
  • 2012/7/31 13:39

  • tatane

  • Just can't stay away

  • Posts: 649

  • Since: 2008/5/6 1


Quote:

irmtfan wrote:
dont be unhappy my friend.
fortunately, today i had time for you and it just take one hour to show you how you can remove at least this one hardcode.

1- in news/language/YOUR_LANG/main.php change the following:
// START hacked by irmtfan
define('_NW_ONECOMMENT',"comment");
// END hacked by irmtfan

define('_NW_BYTESMORE',"%s bytes more");
// START hacked by irmtfan
define('_NW_NUMCOMMENTS',"comments");
// END hacked by irmtfan


2- in news/class/class.newsstory.php change the following:
$morelink '';
        if ( 
$fullcount ) {
            
$morelink .= '.XOOPS_URL.'/modules/news/article.php?storyid='.$this->storyid().'';
            
$morelink .= '">'._NW_READMORE.'';
            
$morelink .= ' | '.sprintf(_NW_BYTESMORE,$totalcount);
            if (
XOOPS_COMMENT_APPROVENONE != $xoopsModuleConfig['com_rule']) {
                
$morelink .= ' | ';
            }
        }
        if (
XOOPS_COMMENT_APPROVENONE != $xoopsModuleConfig['com_rule']) {
            
$ccount $this->comments();
            
$morelink .= '.XOOPS_URL.'/modules/news/article.php?storyid='.$this->storyid().'';
            
$morelink2 '.XOOPS_URL.'/modules/news/article.php?storyid='.$this->storyid().'';
            if ( 
$ccount == ) {
                
$morelink .= '">'._NW_COMMENTS.'';
            } else {
                if ( 
$fullcount ) {
                    
// START hacked by irmtfan
                    //if ( $ccount == 1 ) {
                    //    $morelink .= '">'._NW_READMORE.' | '.$morelink2.'">'._NW_ONECOMMENT.'';
                    //} else {
                          
$morelink .= '">'._NW_READMORE.' | '.$morelink2.'">';
                    
//    $morelink .= sprintf(_NW_NUMCOMMENTS, $ccount);
                          
$morelink .= '';
                    
//}
                
} else {
                    
//if ( $ccount == 1 ) {
                    //    $morelink .= '">'._NW_ONECOMMENT.'';
                    //} else {
                        
$morelink .= '">';
                    
//    $morelink .= sprintf(_NW_NUMCOMMENTS, $ccount);
                        
$morelink .= '';
                    
//}
                    // END hacked by irmtfan
                    
                
}
            }
        }
           
// START hacked by irmtfan
        
$story['numcomments'] = $ccount;
           
// END hacked by irmtfan
        
$story['morelink'] = $morelink;


3- then in news/templates/news_item.html change the following:

        itemPermaLink"><{$story.morelink}> <{if $story.numcomments gt 0}> <{$story.numcomments}> <{if $story.numcomments gt 1}> <{$smarty.const._NW_NUMCOMMENTS}> <{else}> <{$smarty.const._NW_ONECOMMENT}> <{/if}> <{/if}>
        


you can see the right way of doing that. One smarty variable should only used for one php variable.

Edit:
by the way, english language is weak in this point because it needs to add a "s" to make a countable word plural (1 comment and 2 comments) . in persian we dont have this obstacle! (comment=nazar and comments=nazar)

IMO the best way for localize it for languages like english is adding a "s" suffix that can be used in such a situation. eg:
for english:
define("_COUNT_SUFFIX","s");

for persian:
define("_COUNT_SUFFIX","");


Great would it be possible to put the byte into a smarty too?

10
irmtfan
Re: smarty
  • 2012/8/1 0:47

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Quote:

In case of modules, the module developers have to do the code clean-up themselves.


This is correct for newly created modules.
but there are many orphaned modules like this news, newbb, smartfaq, ... that no body take care about hard codes in them.
IMO XOOPS should catch tight any helping hand in this area like playsome works in templates.

Quote:

or example right now I am modifying templates for extcal to make them cleaner and to use divs instead of tables (except for month/week calendar view). I have also modified xcgal templates to use divs instead of tables so that I can make them responsive. But having to dig through tons of php code to find some HTML can be annoying and time consuming.


Your works are appreciated. I really like to use your templates in my websites.

Mamba:
Now I think creating more branches for non developers like me or playsome is good idea. If for example playsome create a branch for xcgal and extgallery i could see his changes and im curious to see them.

tatane:
cleaning this news module is a waste of time IMO.
we should have a full-featured core content module, then all of us will port our old news to that module and will get rid of these annoying issues.


Login

Who's Online

330 user(s) are online (249 user(s) are browsing Support Forums)


Members: 0


Guests: 330


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