Jump to Main Content
Content > XOOPS > XOOPS Developer Notes
XOOPS Developer Notes

Notes and documentation for me specifically for writing code on XOOPS. This is NOT an exhaustive list, rather for those things I've done and want to reference. If it's of interest to everyone, then I'll contribute it to the XOOPS site.

These notes are pertinent to most versions of XOOPs, but as of last writing we were at 2.3.3+ (and 2.4.1 has just been released).

XOOPS APIs (by XooFoo)

Common XOOPS Functions

Modules

  • $modnameHandler = &xoops_getmodulehandler($name = null, $module_dir = null, $optional = false)
  • $gperm_handler = &xoops_gethandler('groupperm');
    • $view_globalscope = $gperm_handler->checkRight("perm_title", $id_form, $groups, $mid); ($mid is moduleID)
  • $config_handler =& xoops_gethandler('config');
    • $formulizeConfig =& $config_handler->getConfigsByCat(0, $mid);

Note: common question is about difference between = &function and =& function.

User

  • $xoopsUser->getGroups()
  • $xoopsUser->isAdmin() = $isadmin

Using Group Permissions

PHP Code Needed, e.g.:

$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
$gperm_handler =& xoops_gethandler('groupperm');
$perm = ($gperm_handler->checkRight('news_submit', 0, $groups, $xoopsModule->getVar('mid'))) ? true : false ;
$xoopsTpl->assign('perm', $perm);

Smarty Template:

<{if !$perm}>
If you were <a href="<{$xoops_url}>/user.php">logged in</a> (or a <a href="<{$xoops_url}>/register.php">registered user</a>) you could submit a news article.
<{else}>
<FORM METHOD='LINK' ACTION='<{$xoops_url}>/modules/news/submit.php'>
<INPUT TYPE='submit' VALUE='Add Your News'></FORM>
<{/if}>

XOOPS Forms

There is more to this of course, but here's a short example:

    include_once XOOPS_ROOT_PATH . "/class/xoopsformloader.php";
    $form = new XoopsThemeForm('Form Displayed Title', 'formidname', 'path/file.php');
    $form->addElement(new XoopsFormText(_US_EMAIL, 'email', 25, 255));
    $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
    $form->display();

XOOPSForms (/class/xoopsform/form.php)
ValidationJS doesn't "validate" dropdown type selections that start with "--NONE--" as being null. Or maybe it does. Should I test that further?

Criteria

note, never use CriteriaElement directly (don't remember the citation, but I remember the warning).

Using criteria, e.g.:

$criteria =& new CriteriaCompo();
$criteria->add(new Criteria('categoryid',$categoryid));
$criteria->setSort('weight');
printR($smartsection_item_handler->getObjects($criteria,'categoryid'),"Objects");

Conventions

  • Class - CamelCase
  • Hidden Variables - $_initialLowerCaseWithUnderscore

Notable Variables/Methods

  • $xoopsTpl - class XoopsTpl - used by Smarty Templates. It's what is passed to the template for display. Variables:
  • $xoopsObject - the basic object used
    • initVar (initialize a named variable of the objects variable array)
  • $xoopsDB - for working through the database
  • $xoopsUser - class XoopsUser extends XoopsObject

XOOPS Security/Token Class

In short, create a token either using a form item or HTML:

  • Form: $form->AddElement(new XoopsFormHiddenToken());
  • HTML: $html = $GLOBALS['xoopsSecurity']->getTokenHTML(); (produces, e.g.: <input type='hidden' name='XOOPS_TOKEN_REQUEST' id='XOOPS_TOKEN_REQUEST' value='328ae5a791d23ef46f8d10e11a337ad8' />)

Check in code:

if ($GLOBALS['xoopsSecurity']->check()) {
  // success path
} else {
  // fails path
}


Other Pages
Previous Page xcGallery Checklists: Upgrading, Deploying or Moving a XOOPS Site to Another Server Next Page
 
Comments are solely the opionion of the author and not to be construed as the opinion of anyone else.
Login
User

Pass

Remember me



Lost Password?

Register now!
 

 

 

(c) 2006-2007 - Mark Boyden
Privacy - Legal Stuff - Contacts