81
irmtfan
Re: How to write an standard module for xoops (div table, pagination , sort, order)
  • 2013/5/13 2:24

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Good.
yes i read that interesting topic before.
I agree to remove that part but anyway it help me a lot to reduce code.
eg: for time i wrote this:
public function log_time()
    {
        return 
$this->userlog->formatTime($this->getVar('log_time'));
    }

so if i need formatted time i use $Obj->log_time() but if i need the timestamp i use $Obj->getVar('log_time')

there are many interesting usage of magic function like this:
http://stackoverflow.com/questions/356128/can-i-extend-a-class-using-more-than-1-class-in-php

But i agree to remove this part from the standard tutorial.
Please contribute more. we really need opinions from experts.




82
irmtfan
Re: The need to keep XOOPS module development in one location
  • 2013/5/12 5:52

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


+100,
As always, I hope all xoops developers could work together in one place.
Also please dont work on your modules in local and commit any pre-alpha (not working) versions of modules to SVN.



83
irmtfan
Re: Error in templates
  • 2013/5/12 4:39

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


If i understand you correctly. you say your file is utf-8 and xoops save it as ansi. 1- you should not have utf-8 or multi-byte characters in themes/templates. It is hard-code. move them to language files and use them like this using smarty.
<{$smarty.const._NO}>
2- "/modules/system/admin.php?Fct=tplsets" only will copy the templates from: modules/MODULE/templates/my_template.html to: themes/THEME/modules/my_template.html It dont do anything else. so it is just useful when a webmaster dont have access to Cpanel and/or ftp. Therefor if you have access to root or Cpanel or FTP you can do it yourself using ftp.



84
irmtfan
Re: Are Xoops form classes ajax friendly?
  • 2013/5/12 4:32

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


In 2.5.6 XoopsForm ajax is not using at all.
Even there are many limitations for module developers in xoops.js and Xoopsform classes.
Quote:

are there some tricks?

I am very basic in js and didnt know JQuery at all so I had to search a lot to find some very needed js functions for my needs in newbb and userlog:
function isOneChecked($name) {
  
// All <input> tags...
  
var chx document.getElementsByName($name);
  for (var 
i=0i<chx.lengthi++) {
    
// If you have more than one checkbox group, also check the name attribute
    // for the one you want as in && chx[i].name == 'choose'
    // Return true from the function on first match of a checked item
    
if (chx[i].type == 'checkbox' && chx[i].checked) {
      return 
true;
    } 
  }
  
// End of the loop, return false
  
return false;
}
// http://stackoverflow.com/questions/2617480/how-to-get-all-elements-which-name-starts-with-some-string
function preventSubmitEmptyInput($prefix) {
    var 
eles = [];
    var 
inputs document.getElementsByTagName("input");
    for(var 
0inputs.lengthi++) {
        if(
inputs[i].name.indexOf($prefix) == 0) {
            
eles.push(inputs[i]);
        }
    }
    for(var 
0eles.lengthi++) {
        if (
eles[i].value =='') {
            
eles[i].setAttribute('name''');
        }
    }
    return 
true;
}
// START irmtfan - improve: add alt, title, id and innerHTML - recognize a IMG tag for src
function ToggleBlock(blockidiconsrc_expandsrc_collapsealt_expandalt_collapseclass_expandclass_collapse)
{
    var 
Img_tag='IMG';
    var 
el=document.getElementById(blockid);
    if (
el.className == class_expand)
    {
        
el.className class_collapse;
        if (
icon.nodeName  == Img_tag) {
            
icon.src src_collapse;
        }
        
icon.altalt_collapse;
        
icon.id findBaseName(src_collapse);
        
SaveCollapsed(blockidtrue);
    }
    else
    {
        
el.className class_expand;
        if (
icon.nodeName == Img_tag) {
            
icon.src src_expand;
        }
        
icon.altalt_expand;
        
icon.id findBaseName(src_expand);
        
SaveCollapsed(blockidfalse);
    }
    
icon.title icon.alt;
    if (
icon.nodeName  != Img_tag){
        
icon.innerHTML=icon.alt// to support IE7&8 use innerHTML istead of textContent
    
}
    
document.getElementById(blockid "text").innerHTML=icon.alt;    
}
// source: http://stackoverflow.com/questions/1991608/find-base-name-in-url-in-javascript
function findBaseName(url) {
    var 
fileName url.substring(url.lastIndexOf('/') + 1);
    var 
dot fileName.lastIndexOf('.');
    return 
dot == -fileName fileName.substring(0dot);
}
// END irmtfan - improve: add alt, title and innerHTML - recognize a IMG tag for src
function SaveCollapsed(objidaddcollapsed)
{
    var 
collapsed GetCookie(toggle_cookie);
    var 
tmp "";
    if (
collapsed != null)
    {
        
collapsed collapsed.split(",");
        for (
i in collapsed)
        {
            if (
collapsed[i] != objid && collapsed[i] != "")
            {
                
tmp tmp collapsed[i];
                
tmp tmp ",";
            }
        }
    }

    if (
addcollapsed)
    {
        
tmp tmp objid;
    }

    
expires = new Date();
    
expires.setTime(expires.getTime() + (1000 86400 365));
    
SetCookie(toggle_cookietmpexpires);
}

function 
SetCookie(namevalueexpires)
{
    if (!
expires)
    {
        
expires = new Date();
    }
    
document.cookie name "=" escape(value) + "; expires=" expires.toGMTString() +  "; path=/";
}

function 
GetCookie(name)
{
    
cookie_name name "=";
    
cookie_length document.cookie.length;
    
cookie_begin 0;
    while (
cookie_begin cookie_length)
    {
        
value_begin cookie_begin cookie_name.length;
        if (
document.cookie.substring(cookie_beginvalue_begin) == cookie_name)
        {
            var 
value_end document.cookie.indexOf (";"value_begin);
            if (
value_end == -1)
            {
                
value_end cookie_length;
            }
            return 
unescape(document.cookie.substring(value_beginvalue_end));
        }
        
cookie_begin document.cookie.indexOf(" "cookie_begin) + 1;
        if (
cookie_begin == 0)
        {
            break;
        }
    }
    return 
null;
}
/**
 * Newbb Javascript Validation functions
 *
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
 * @module             newbb
 * @since           4.3
 * @author          irmtfan
 * @version         $Id$
 */

/**
* Function for validation of xoops forms: prevent user select nothing or disable some options
* @param elName : elements name
* @param elType : element type eg: select, checkbox
* @param prevent: prevent user select nothing: true or false
* @param disablecat: disable categories in forum select box: true or false
* @param elMsg: the message
*/


function validate(elNameelType preventdisablecatelMsg)
{
    var 
0;
    var 
el=document.getElementsByName(elName);
    var 
is_valid true;
    switch (
elType) {
        case 
'checkbox':
            var 
hasChecked false;
            if (
el.length) {
                for (
0el.lengthi++) {
                    if (
el[i].checked == true) {
                        
hasChecked true;
                        break;
                    }
                }
            } else {
                if (
el.checked == true) {
                    
hasChecked true;
                }
            }
            if (!
hasChecked) {
                if (
el.length) {
                    if (
prevent) {el[0].checked true;}
                    
el[0].focus();
                }else{
                    if (
prevent) {el.checked true;}
                    
el.focus();            
                }
                
is_valid false;
            }
            break;
        case 
'select':
            
el el[0];
            if (
disablecat) {
                for (
0el.options.lengthi++ ) {
                    if (
el.options[i].value 0) {
                        
el.options[i].disabled  true;
                        
el.options[i].value '';                        
                    }
                }                
            }
            
            if (
el.value == '') {
                
is_valid false;
                if(
prevent) {
                    for (
0el.options.lengthi++ ) {
                        if (
el.options[i].value != '') {
                            
el.value el.options[i].value;
                            break; 
// loop exit
                        
}
                    }
                }
            }
            break;
    }
    return 
is_valid;
}


As you can see there are very basic and common needs:
1- check if at least one checkbox is selected in a multi-checkbox. It is useful if you want to submit only when one selected.

2- prevent to submit empty input elements. it is very useful when you have many $_GET in the URL and you dont want to end up with a messy URI with some empty arguments like this:
/index.php?id=&time=&select=&cat=&post=234

using the above js function in this URI it remove all empty arguments and only post=234 is remained.
/index.php?post=234


3- toggle (show/hide) very needed just having the ability to change a css class is enough.

4- set and get cookie in browser.

5- prevent user select nothing in multiselect checkbox or select form. It is a common bug in all xoops modules like publisher, news, ... which user can select nothing and break the module from working.

I didnt review 2.6 fully. but there are many limitations in 2.6 too. I hope core team add more useful js functions with document and instruction for general usage of module developers.



85
irmtfan
Re: Making Libraries of functions to be used in many modules? Action Ques? X2 and X3 related..
  • 2013/5/11 5:11

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


AFAIK, if a module follow the standard i wrote in this thread:
https://xoops.org/modules/newbb/viewtopic.php?post_id=353437
It would not be any issue for other modules to use its functions only with one instance:
$MODULE Module::getInstance();

which "Module" is the module dirname with uppercase of the first letter.
for example in userlog (with dirname = "userlog") you just need to have this in any other module:
$Userlog Userlog::getInstance();

then you have access to all functions and handlers and can use it with ease:
$Userlog->getHandler('log')->getCounts($criteria)

the above means you access to table mod_userlog_log so for any other standard module you just need to know the table name suffix.

all functions to work with database like "getCounts" can be found in XoopsObject class. so all modules have a unify interface functions.

even you can delete table rows or drop fields (and damage the userlog module) from any other module using that handler
$Userlog->getHandler('stats')->dropField("time_update");

In 2.6 it turns to a core helper class that makes usage of another module class/functions more simpler for module developers.
I show the way to write that helper for 2.5.5 modules in how to write standard module for xoops tutorial.
so instead of what you propose for a module class (Xoopspoll) we have this:
http://svn.code.sf.net/p/xoops/svn/XoopsModules/publisher/trunk/publisher/class/publisher.php
but you should know:
- one table in a module needs one class extend the XoopsObject Core class to work with its own table.
Im still reading this long topic. I will add my comments.



86
irmtfan
Re: Cannot embed video using iframe
  • 2013/5/11 4:41

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


I think you should use this:
[youtube=640,360]http://www.youtube.com/embed/6YD8Lt7avdU?rel=0%22[/youtube]




87
irmtfan
Re: xoops256 bug (very important): template duplicate issue
  • 2013/5/11 4:33

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


I implement this bug fix in some small websites and the result is amazing. Now i dont need to use Altsys.
I think this bug is solved:
http://sourceforge.net/p/xoops/bugs/1221/
so please somebody refer to this bug comments.
If you see below very old core file, you can find a previous core developer tried to solve this bug a long time ago:
http://svn.code.sf.net/p/xoops/svn/XoopsCore/branches/2.5.x/2.5.6/htdocs/modules/system/include/update.php
but he failed.
I used his code (I could use better codes too) to show you it can be solved.



88
irmtfan
Re: SmartClone 1.10 Beta 1 ready for testing
  • 2013/5/11 4:30

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


I found a temporary solution to run "pre" functions without using eval.
add this to xoops_version.php
// if we are in modulesadmin to install, update or uninstall
if (!empty($_REQUEST['fct']) && $_REQUEST['fct'] == "modulesadmin" && !empty($_REQUEST['module']) && $_REQUEST['module'] == $modversion['dirname']) {
    
$hModule xoops_gethandler('module');
    switch (
$_REQUEST['op']) {
        case 
"install":
            
$module =& $hModule->create();
            
$module->loadInfoAsVar($modversion['dirname']);
            
// Load module specific install script if any
            
$install_script $modversion['onInstall'];
            if (
$install_script && trim($install_script) != '') {
                include_once 
XOOPS_ROOT_PATH '/modules/' $modversion['dirname'] . '/' trim($install_script);
            }
            
$func "xoops_module_pre_install_module";
            break;
        case 
"update":
            
$module =& $hModule->getByDirname($modversion['dirname']);
            
// Save current version for use in the update function
            
$prev_version $module->getVar('version');
            
// Load module specific update script if any
            
$update_script $modversion['onUpdate'];
            if (
$update_script && trim($update_script) != '') {
                include_once 
XOOPS_ROOT_PATH '/modules/' $modversion['dirname'] . '/' trim($update_script);
            }
            
$func "xoops_module_pre_update_module";
            break;
        case 
"uninstall":
            
$module =& $hModule->getByDirname($modversion['dirname']);
            
// Load module specific update script if any
            
$uninstall_script $modversion['onUninstall'];
            if (
$uninstall_script && trim($uninstall_script) != '') {
                include_once 
XOOPS_ROOT_PATH '/modules/' $modversion['dirname'] . '/' trim($uninstall_script);
            }
            
$func "xoops_module_pre_uninstall_module";
            break;
    }
    if (
function_exists($func)) {
        
$result $func($module);
        if (!
$result) {
            
$module->setErrors('<p>' sprintf_AM_SYSTEM_MODULES_FAILED_EXECUTE"<strong>{$func}</strong>") . '</p>');
        } else {
            
$module->setErrors('<p>' sprintf_AM_SYSTEM_MODULES_FAILED_SUCESS"<strong>{$func}</strong>") . '</p>');
        }
    }
}

It is just temporary because it will execute the pre functions whenever user goes to moduelsadmin link:
eg: modules/system/admin.php?fct=modulesadmin&op=update&module=$dirname

Now the wish to clone modules by simple folder renaming is accomplished. without using eval.
even we can update a clone module using the original module. (which is not possible in current SmartClone)
meanwhile we should send a core request to remove dirname from all Oninstall,Onupdate or Onuninstall functions at least in core 2.6
It seems previous core developers had a bad habit to add dirname to all instance of module functions to avoid conflict. But they didnt think while in some core operations like blocks and search functions core will face conflict between modules, in update and install and uninstall it is not needed and now it makes troubles for cloning.



89
irmtfan
Re: XOOPS 2.5.6 Final Release Issues
  • 2013/5/11 2:41

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


@bosco:
It seems you are a well experience user of Xoops, php and mysql and you can solve upgrade issues sooner or later.
but I mainly recommend dont use old upgrade packages. they are not reliable. I always will use the latest full version for upgrade.



90
irmtfan
Re: xHelp don't send some notifications
  • 2013/5/11 2:38

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Xhelp is a very old module.
Trabis did some great attempts to fix bugs but still there are some bugs.
unfortunately we didnt have many developers like Trabis in Xoops. Most developers had been envolved in some useless projects for creating content modules like news, download or gallery.
Xhelp is a big module and needs many time to be bug free.




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



Login

Who's Online

187 user(s) are online (117 user(s) are browsing Support Forums)


Members: 0


Guests: 187


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