91
irmtfan
Re: SmartClone 1.10 Beta 1 ready for testing
  • 2013/5/9 2:51

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


@zyspec:
I dont need to use eval for class and function naming.
I just need to have one reliable and consistent "xoops_module_pre_install_module" function or class and in this function i will change all table names and all class/ function names just like SmartClone do it for any module. (I will use the smartclone class)
In other words "xoops_module_pre_install_module" will be my embedded SmartClone in the module.
Also I think I need to use one more eval for "xoops_module_update_$dirname" to check and do the cloning and let user update the module with ease.

as i said before i dont need to do anything for ""xoops_module_uninstall_$dirname" because Core will drop my tables.

but In my idea with the current clone system the only problem is every clone is one separate module and all class and functions will be cloned. (but in D3 way all clones will use class and functions from the parent)

I still cannot find any reason why Xoops Core developers defined install/update/uninstall functions with dirname?

dirname is not needed because as i said before at one time only one module is Oninstall,Onupdate or Onuninstall.
so one fix function like "xoops_module_pre_install_module" or "xoops_module_update_module" will do the job perfectly.

@Mamba:
I am not good at php but i think we cannot avoid eval with that trick.

Edit: I will update "how to write standard module" tutorial with my new findings:
1- standard module should not have any file name contain the dirname.
a common mistake in all modules is using dirname as a prefix for all templates. It is not needed
so instead of templates/newbb_thread.html we can use templates/module_thread.html or any desired name.

2- standard module should not have any hard-coded dirname in places we can use a variable for it eg:
- block functions:
$modversion['blocks'][$i]['show_func'] = $modversion['dirname'] . "_views_show";
$modversion['blocks'][$i]['edit_func'] = $modversion['dirname'] . "_views_edit";

- table names:
$modversion['tables'][$i] = $modversion['dirname'] . '_log';


- handler table name:
public function __construct(&$db)
    {
        
$this->userlog Userlog::getInstance();
        
parent::__construct($dbUSERLOG_DIRNAME "_log"'UserlogLog'"log_id""log_time");
    }

and any other possible places.



92
irmtfan
Re: Xoops2.5.6 bug (important): block template file will not updated after update the module
  • 2013/5/9 2:25

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Yes this bug really annoy me for ages. I update a module (especially you surely will face it in updating a cloned module) and see blocks templates are not updated. I did everything but only Altsys could update it.
I think i sent some similar bug reports before but nobody found it.
Im sure this is the solution.



93
irmtfan
xoops256 bug (very important): template duplicate issue
  • 2013/5/8 11:38

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


I found a very old and bad bug in "tplfile" table.

if module template type was not "module" (if its type was admin) it will created countless duplicate templates with each update.

you can easily find this bug by updating system module several times then go to phpmyadmin and table "tplfile" and search for tpl_module = system
SELECT FROM PREFIX_tplfile WHERE tpl_module "system"


You can find duplicate rows.

to solve that i change 2 files + version in xoops_version.php
1- xoops256/modules/system/admin/modulesadmin/main.php
2- xoops256/modules/system/include/update.php
3- xoops256/modules/system/xoops_version.php

in xoops_version.php i just change the version from 2.10 to 2.11 to warn user to update system module.

I create a patch for this bug.
www.jadoogaran.org/d/XOOPS256_patch_duplicate_template.zip

also i update persian trunk:
http://svn.code.sf.net/p/xoops/svn//XoopsLanguages/persian/core/trunk/

to implement:
1- upload and overwrite files.
2- go to admin > modules > system > modules > update "system module"
3- clear all caches in admin > modules > system > maintenance

Please test this patch first and then use it with your own risk in running websites.



94
irmtfan
Re: Xoops2.5.6 bug (important): block template file will not updated after update the module
  • 2013/5/8 8:44

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


thanks mamba.
the bug is exist in xoops 26.
This bug will prevent module developers to change the templates files for blocks in clone process.
now they add $dirname as a prefix but it is not needed.
eg: templates/blocks/DIRNAME_counts.html
should be changed to
templates/blocks/block_counts.html
and the above will work perfectly in all clones.

I want to update the how to write standard module tutorial ASAP.



95
irmtfan
Xoops2.5.6 and xoops26 bug (important): block template file will not updated after update the module
  • 2013/5/8 8:13

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


I had this bug for many years. when i update a module and module block template file name had been changed, It will not updated. Only Altsys by GIJ could update the module block template. Finally today i found the bug in core 256 It is a very old bug unsolved for about 7 years. in xoops256/modules/system/admin/modulesadmin/main.php around line 615 one previous core developer forgot to update the tpl_file so you should add the tpl_file like this:
$tplfile_new->setVar('tpl_source'$contenttrue);
                                    
$tplfile_new->setVar('tpl_desc'$block['description'], true);
                                    
$tplfile_new->setVar('tpl_lastmodified'time());
                                    
$tplfile_new->setVar('tpl_lastimported'0);
                                    
$tplfile_new->setVar('tpl_file'$block['template'], true); // irmtfan bug fix:  block template file will not updated after update the module
                                    
if (!$tplfile_handler->insert($tplfile_new)) {
                                        
$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">'.sprintf(_AM_SYSTEM_MODULES_TEMPLATE_UPDATE_ERROR"<strong>".$block['template']."</strong>").'</span>';
                                    } else {
I should test in Xoops26 but i think 26 has not this bug. please somebody send it to bug tracker. Edit: it is bug in xoops26 too. in modules/system/class/module.php around line 682:
$tplfile_new->setVar('tpl_source'$templatetrue);
                            
$tplfile_new->setVar('tpl_desc'$block['description'], true);
                            
$tplfile_new->setVar('tpl_lastmodified'time());
                            
$tplfile_new->setVar('tpl_lastimported'0);
                            
$tplfile_new->setVar('tpl_file'$block['template'], true); // irmtfan bug fix:  block template file will not updated after update the module



96
irmtfan
Re: SmartClone 1.10 Beta 1 ready for testing
  • 2013/5/8 5:43

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


An important note:
You must install "SmartObject" before installing SmartClone.

SmartObject is not in the svn.

Quote:

Any Clone system (module) should evaluate and filter $dirname before cloning.

After more thoughts it seems it is better to be filtered by the XOOPS core before pre install fucnction.
Because core should not allow a bad dirname like 1000 just like a bad user name and ...

Also I repeat, the bad dirname selection for cloned module is not an eval bug. with SmartClone you can create a module with dirname = 1000 and break your website.

I still cannot see any solution other than using eval. It seems namespace cannot help us.
You have to use eval at least one time to manipulate the pre install function or even pre install trigger.
OR
Xoops core should change this line:
$func "xoops_module_pre_install_{$dirname}";


with this:
$func "xoops_module_pre_install_{$dirname}";
        
$func function_exists($func) ? $func "xoops_module_pre_install_module";


because at one time there is just one function and i cannot see any reason to add $dirname to the name of the pre install function.
So these are working good:
function xoops_module_pre_install_module(&$module)
{
}
function 
xoops_module_install_module(&$module)
{
}


And in D3 way you still have to use eval a few times. but in D3 the main module (contain eval) is out of the root.

Uninstall is not an issue because xoops will get the table names from xoops_version.php and you can define them like this.
// Tables created by sql file (without prefix!)
$i 0;
$modversion['tables'][$i] = $modversion['dirname'] . '_log';

$i++;
$modversion['tables'][$i] = $modversion['dirname'] . '_set';

$i++;
$modversion['tables'][$i] = $modversion['dirname'] . '_stats';



97
irmtfan
Re: Xoops 2.5.6 and Xoops 2.6 bug (bad hard-coded query): $member_handler-> getUserList($criteria)
  • 2013/5/8 5:18

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Thank you, Mamba
I enhance the list to show name and uid like this
$uid1- $uname1 ($name1)
$uid2- $uname2 ($name2)

also i add a max = 100 so only the top 100 users will be remained in the list and others will be removed with the first come first go(remove) rule.
// START irmtfan to enhance the getUserList function
    /**
     * get a list of usernames and their IDs
     *
     * @param object $criteria {@link CriteriaElement} object
     * @param bool $force true: get from cache file or database
     * @return array associative array of user-IDs and names
     */
    
public function getUserList($criteria null$force true)
    {
        static 
$user_list;
        if (
is_array($user_list) && !$force) {
            return 
$user_list;
        }
        if (!
class_exists('XoopsLoad')) {
            require_once 
XOOPS_ROOT_PATH '/class/xoopsload.php';
        }
        
XoopsLoad::load('XoopsCache');
        if (!
$user_list XoopsCache::read('user_list')) {
            
$user_list $this->setUserList($criteria);
        } else if(
strpos($criteria->renderWhere(),"uid")) {
            
$user_list $this->setUserList($criteria$user_list);
        }
        return 
$user_list;
    }
    
/**
     * set and get a list of usernames and their IDs
     *
     * @param object $criteria {@link CriteriaElement} object
     * @param array $user_list array($uid1=>"$uid1- $uname1 ($name1)", "$uid2- $uname2 ($name2)");
     * @return array associative array of user-IDs and names
     */
    
public function setUserList($criteria null$user_list = array(), $max 100)
    {
        if (!
class_exists('XoopsLoad')) {
            require_once 
XOOPS_ROOT_PATH '/class/xoopsload.php';
        }
        
XoopsLoad::load('XoopsCache');
        
$users $this->_uHandler->getObjects($criteriatrue);
        
$ret = array();
        foreach (
array_keys($users) as $i) {
            
$ret[$i] = $i "- " $users[$i]->getVar('uname') . " (" $users[$i]->getVar('name') . ")";
        }
        if (!empty(
$user_list)) {
            
$ret array_unique($ret array_slice($user_list,0,$max,true)); // new users will be added to the top! size of user list = new added + $max
        
}
        if(!empty(
$ret)) {
            
XoopsCache::write('user_list'$ret);
        }
        return 
$ret;
    }
    
// END irmtfan to enhance the getUserList function






98
irmtfan
Re: Forum block showing content in right adjacent column.
  • 2013/5/8 5:14

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Yes this issue can be solved by using a css3 truncate style at the end of a table row.
.truncate 
    
white-spacenowrap
    
overflowhidden

.
ellipsis 
    
text-overflowellipsis;  // IE 6+, FF 7+, Op 11+, Saf 1.3+, Chr 1+ 
}


you can see how it works here:

http://mattsnider.com/css-string-truncation-with-ellipsis/



99
irmtfan
Re: Meta tag module "XBS MetaTags" or similar
  • 2013/5/7 11:24

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


1- It is not good way.
Quote:

Put in your .php page this code:

Im afraid this is a hard-code and fix meta addition to all pages because nearly all xoops modules have dynamic pages with query strings like modules/MODULE/page.php?item_id=xxx
So your meta addition will fix the meta for all page.php pages.

2- most proper and good xoops content modules like news, publisher create special metas (keywords and description) for each dynamic page. newbb will create too in viewtopic.php which you can see in this page.
So why you want to add this hard-coded meta?

Finally the last question is: in which module you face this problem? That module is a bad one.



100
irmtfan
Xoops 2.5.6 and Xoops 2.6 bug (bad hard-coded query): $member_handler-> getUserList($criteria)
  • 2013/5/7 10:35

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Title: Xoops 2.5.6 and Xoops 2.6 bug (bad hard-coded query): $member_handler->getUserList($criteria) Text: Today In my running website with +20000 registered users, I recognized one query which has these very bad issues: 1- take many times for executation. 2- run more than once in a page.
[b]0.822133[/b] - SELECT FROM `usersORDER BY uname ASC LIMIT 0200
...

[
b]0.312342[/b] - SELECT FROM `usersORDER BY uname ASC LIMIT 0200
3- "ORDER BY uname ASC LIMIT 0, 200" is a useless query for a website because in a large websites we have many users with !!name, 111, 222 unames. Then i recognized that it comes from the popular "XoopsFormSelectUser" element. If you have this form in a page, It will get a query for the first 200 "uname" fields for every instance of the element in that page.(so 10 elements means 10 bad query ) Of course it is not acceptable for me and i think it is not acceptable for anybody. you can find yourself the "ASC LIMIT 0, 200" which is hard-coded in XOOPS256|Xoops26/class/xoopsform/formselectuser.php:
function XoopsFormSelectUser($caption$name$include_anon false$value null$size 1$multiple false)
    {
        
$limit 200;
        
$select_element = new XoopsFormSelect(''$name$value$size$multiple);
        if (
$include_anon) {
            
$select_element->addOption(0$GLOBALS['xoopsConfig']['anonymous']);
        }
        
$member_handler =& xoops_gethandler('member');
        
$user_count $member_handler->getUserCount();
        
$value is_array($value) ? $value : (empty($value) ? array() : array($value));
        if (
$user_count $limit && count($value) > 0) {
            
$criteria = new CriteriaCompo(new Criteria('uid''(' implode(','$value) . ')''IN'));
        } else {
            
$criteria = new CriteriaCompo();
            
$criteria->setLimit($limit);
        }
        
$criteria->setSort('uname');
        
$criteria->setOrder('ASC');
        
$users $member_handler->getUserList($criteria);
        
$select_element->addOptionArray($users);
        if (
$user_count <= $limit) {
            
$this->XoopsFormElementTray($caption""$name);
            
$this->addElement($select_element);
            return;
        }
At first i decided to change this function But then I found the root of this issue comes from $member_handler->getUserList($criteria) So i went to XOOPS256|Xoops26/kernel/member.php and replace getUserList function:
/**
     * get a list of usernames and their IDs
     *
     * @param CriteriaElement|null $criteria {@link CriteriaElement} object
     * @return array associative array of user-IDs and names
     */
    
function getUserList(CriteriaElement $criteria null)
    {
        
$users $this->_uHandler->getObjects($criteriatrue);
        
$ret = array();
        foreach (
array_keys($users) as $i) {
            
$ret[$i] = $users[$i]->getVar('uname');
        }
        return 
$ret;
    }
with getUserList and setUserList functions:
// START irmtfan to enhance the getUserList function
    /**
     * get a list of usernames and their IDs
     *
     * @param object $criteria {@link CriteriaElement} object
     * @param bool $force true: get from cache file or database
     * @return array associative array of user-IDs and names
     */
    
public function getUserList($criteria null$force true)
    {
        static 
$user_list;
        if (
is_array($user_list) && !$force) {
            return 
$user_list;
        }
        if (!
class_exists('XoopsLoad')) {
            require_once 
XOOPS_ROOT_PATH '/class/xoopsload.php';
        }
        
XoopsLoad::load('XoopsCache');
        if (!
$user_list XoopsCache::read('user_list')) {
            
$user_list $this->setUserList($criteria);
        } else if(
strpos($criteria->renderWhere(),"uid")) {
            
$user_list $this->setUserList($criteria$user_list);
        }
        return 
$user_list;
    }
    
/**
     * set and get a list of usernames and their IDs
     *
     * @param object $criteria {@link CriteriaElement} object
     * @param array $user_list array($uid1=>$uname1, $uid2=>$uname2);
     * @return array associative array of user-IDs and names
     */
    
public function setUserList($criteria null$user_list = array())
    {
        if (!
class_exists('XoopsLoad')) {
            require_once 
XOOPS_ROOT_PATH '/class/xoopsload.php';
        }
        
XoopsLoad::load('XoopsCache');
        
$users $this->_uHandler->getObjects($criteriatrue);
        
$ret = array();
        foreach (
array_keys($users) as $i) {
            
$ret[$i] = $users[$i]->getVar('uname');
        }
        if (!empty(
$user_list)) {
            
$ret array_unique($ret $user_list); // new users will be added to the top!
        
}
        if(!empty(
$ret)) {
            
XoopsCache::write('user_list'$ret);
        }
        return 
$ret;
    }
    
// END irmtfan to enhance the getUserList function
Now I am very happy with this code because: 1- While It has back-ward compatibility, it is compatible with Xoops256 and xoops26 ALPHA versions too. 2- When the list is empty the bad query "ASC LIMIT 0, 200" just run once until webmaster clear xoops caches. (Of course we can change "XoopsFormSelectUser" element function too in the future in core or any developer can extend the class and change that function) 3- IF you add a new member in one "XoopsFormSelectUser" element in a page, it will be added to the list for future usage and it will be added in top of the list 4- It solved all above three issues. ps: please somebody send it to sf.net tracker. I dont know whether bug or feature request is a proper place for it but i prefer the bug tracker.




TopTop
« 1 ... 7 8 9 (10) 11 12 13 ... 284 »



Login

Who's Online

225 user(s) are online (142 user(s) are browsing Support Forums)


Members: 0


Guests: 225


more...

Donat-O-Meter

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

Latest GitHub Commits