1
irmtfan
XoopsLocal functions are exsit for using!
  • 2012/6/16 11:02

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Thanks to previous xoops core developers we already have some functions that available us better localization.
they are located in the class/xoopslocal.php
but unfortunately the current xoops developers (core and module) did not use these functions in their recent releases and it makes big problems.
for example see this topic:
https://xoops.org/modules/newbb/viewtopic.php?topic_id=75201&forum=28&post_id=346896#forumpost346896

Some of the functions in XoopsLocal class just enhanced the same php functions (like number_format and substr) but some of them are xoops functions like the famous formatTimestamp

So i want to ask from all developers to use these functions as much as possible.

Also i have a question about the usage of these functions.
i use them like this:
xoops_load('XoopsLocal');
.....
XoopsLocal::number_format($VAL)

is the above code the only and most efficient way?

Also we need to add some more php functions to XoopsLocal class.
one of the important one is "strtotime" which is used to convert gregorian date string to the number.
we need to have it in Local to enhance it and use other kinds of "input dates strings" like hegira date strings.
so finally all developers should use it like this: XoopsLocal::strtotime($datestring)

thank you for attention.


2
trabis
Re: XoopsLocal functions are exsit for using!
  • 2012/12/5 20:46

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Quote:

irmtfan wrote:
Also i have a question about the usage of these functions.
i use them like this:
xoops_load('XoopsLocal');
.....
XoopsLocal::number_format($VAL)

is the above code the only and most efficient way?

Also we need to add some more php functions to XoopsLocal class.
one of the important one is "strtotime" which is used to convert gregorian date string to the number.
we need to have it in Local to enhance it and use other kinds of "input dates strings" like hegira date strings.
so finally all developers should use it like this: XoopsLocal::strtotime($datestring)


The code works but there is another way.
The class was made to support magic calls. The idea is that you don't have to add strtotime in XoopsLocalAbstract to be able to use a php function.
The catch is that this magic only happens if you instantiate the class like this:
XoopsLoad::load('XoopsLocal');
$local = new XoopsLocal;
echo 
$local->intval(5);


It will output '5' although the intval method is not present in the class.
If you use $local->strtotime($datestring) and you have this method on your localized class it would work just fine.

Personally, I dislike magic calls as they obfuscate the logic/code. I would prefer adding new methods in the abstract class as you suggested.

If you could do me a list of all php functions that require localization please post them here, I'll add them in 2.6.

For easier access, we could use $xoops->local->strtotime($datestring) and avoid some paper work.

3
irmtfan
Re: XoopsLocal functions are exsit for using!
  • 2012/12/6 6:16

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Thank you so much for guiding me to magic call i did not aware of this method.
But the point of this topic is how we can force/guide developers to use XoopsLocal class.
As for a list of requierd php functions i finished my proposal for "xoops 2.6 localization" months ago and i dont have anything to add.
For localizing strtotime php function i also sent a feature request. IMO defining a xoops function for converting date to int is better method. (like Joomla)

4
trabis
Re: XoopsLocal functions are exsit for using!
  • 2012/12/7 0:58

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Quote:

irmtfan wrote:
As for a list of requierd php functions i finished my proposal for "xoops 2.6 localization" months ago and i dont have anything to add.
For localizing strtotime php function i also sent a feature request. IMO defining a xoops function for converting date to int is better method. (like Joomla)


I've been absent for a while and did not have the time to go through the bugs/features on sourceforge. I've read the proposal and I liked it very much. I'll try to implement the proposed features as soon as possible.

5
irmtfan
Re: XoopsLocal functions are exsit for using!
  • 2012/12/8 8:41

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


very good. You knows better how to implement features in the next core.
I think i sent all needed features for localization and customization to sf.net so finding them is easy for developers like you.
the strtotime feature request is this:
https://sourceforge.net/p/xoops/feature-requests/381/
as you can see Joomla used a new function.
function date_strtotime($date)
{
$strtotime strtotime($date);
if (
$strtotime === -|| $strtotime === false)
{
return 
false;
}
else
{
return 
$strtotime;
}
}

maybe it is better to have a new function for input time.


6
trabis
Re: XoopsLocal functions are exsit for using!
  • 2012/12/8 14:21

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


There is no way we can force a developer to use the core strtotime so, it is irrelevant to use it as function or as class method for that propose. I prefer to use XoopsLocal, it is the right place for it. If we do a function, it will just mirror to this class.

That joomla function has nothing to do with localization. It just helps developers with type checking.

Btw, the new sf tracker looks great!

7
irmtfan
Re: XoopsLocal functions are exsit for using!
  • 2012/12/9 3:16

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


You misunderstood me Trabis.
I meant a new function in XoopsLocal class for input time. It is just a new name for better declaration.
for example last core members defined a new function for output time XoopsLocal:formatTimestamp but we could used php date function XoopsLocal:date

Anyway, we could have XoopsLocal:date_strtotime or XoopsLocal:strtotime and it is up to core developers to choose. I dont have any problem with that.

Thank you for your works. I see your recent commits and I know there is a lot of works remained.


Login

Who's Online

212 user(s) are online (121 user(s) are browsing Support Forums)


Members: 0


Guests: 212


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits