All designers using XOOPS Cube Legacy 2.2 knows this !

![Creative Commons License](http://i.creativecommons.org/l/by/2.1/jp/88x31.png)
This work is licensed under a [Creative Commons Attribution 2.1 Japan License](http://creativecommons.org/licenses/by/2.1/jp/).

Note that the code is licensed under GPL 2, according to the XOOPS Cube Legacy's License.

----

This post is originally for [XOOPS Themes and Templates Advent Calendar 2012](http://qiita.com/advent-calendar/2012/xoops-themes-templates/participants) in Japanese.

We added and expanded several functions for theme designers and site owners in XOOPS Cube Legacy 2.2.
I'll introduce them from now.

## jQuery and jQuery UI
Recently, many web sites use jQuery and jQuery UI. So XCL 2.2 do, too.
XCL 2.2 loads jQuery and jQuery UI libraries from the latest Google Hosted Libraries(Google Ajax Feed API).

### Version of jQuery
As a default, the latest version of jQuery/jQuery UI is loaded.

### Load the specific version of jQuery/jQuery UI
At Admin menu - legacyRender System - General Setting

You set the version number you want. As a default, '1' is set. This means the largest version number of 1.x is loaded.

* jQuery Core Library
* jQuery UI Library

### Load the local jQuery/jQuery UI file
At Admin menu - legacyRender System - General Setting
Set the library file's URL

* jQuery Core Library
* jQuery UI Library

## To add JavaScript and CSS file/script
Module developers, skilled site owners and designers can add javascript libraries, javascript script and stylesheets into `<{$xoops_module_header}>` by using Legacy_HeaderScript object.
If you are a site owner, you can use preload files to add them.
Especially, addScript() method will add your codes in jQuery's `$(document).ready()`.

```php:html/preload/sample.class.php
<?php
if (!defined('XOOPS_ROOT_PATH')) exit();

class Sample extends XCube_ActionFilter
{
    public function preBlockFilter()
    {
        $this->mRoot->mDelegateManager->add('Site.JQuery.AddFunction',array(&$this, 'addScript'));
    }

    public function addScript(&$jQuery)
    {
        $script = XCube_Root::getSingleton->mContext->getAttribute('headerScript');
        $script->addLibrary('/library/myscript.js');
        $script->addLibrary('http://mysite.example.com/myscript.js', true);
        $script->addStylesheet('/library/mystyle.css');
        $script->addStylesheet('http://mysite.example.com/mystyle.css', true);
        $script->addScript('$(".datepicker").each(function(){$(this).datepicker({dateFormat: "'._JSDATEPICKSTRING.'"});});';');
    }
}
?>
```

## <{xoops_user}> modifier
Smarty's xoops_user modifier has new option "user_name".

```
<{$uid|xoops_user:"user_name"}>
```

This special option call 'Legacy_User.GetUserName' and show its result.
Do you know why we need such option ? In XOOPS, it has 'uname' field and 'name' field for user's name related fields.
For human, 'name' is recognizable but only few users fill this field. On the other hand, 'uname' is unrecognizable but all of users fill this field.
To use the following preload file, site owner can show 'name' field value if the user fills this filed and sho 'uname' field value if the user don't fill 'name' field.

```php:extras/extra_preload/UserName.class.php
<?php
if (!defined('XOOPS_ROOT_PATH')) exit();
class UserName extends XCube_ActionFilter
{
     public function preBlockFilter()
     {
          $this->mRoot->mDelegateManager->add('Legacy_User.GetUserName',array(&$this, 'get'));
     }

     public function get(/*** string ***/ &$userName, /*** int ***/ $uid)
     {
          $handler = xoops_gethandler('member');
          $user = $handler->getUser($uid);
          $name = $user->getShow('name');
          $userName = $name ? $name : $user->getShow('uname');
     }
}
?>
```

## Set meta value in html head.
Add some of meta values in `<head>` by using headerScript.
Use the following preload file.

```php:html/preload/mymeta.class.php
<?php
if (!defined('XOOPS_ROOT_PATH')) exit();

class Mymeta extends XCube_ActionFilter
{
    public function preBlockFilter()
    {
        $this->mRoot->mDelegateManager->add('Site.JQuery.AddFunction',array(&$this, 'addMeta'));
    }

    public function addMeta(&$jQuery)
    {
        $context = XCube_Root::getSingleton()->mContext;
        if($context->mModule != null) {	// The process of module
            $dirname = $context->xoopsModule->getVar('dirname');
        }

        $script = $context->getAttribute('headerScript');
        if($dirname=="news") {
            $script->addMeta('keyword', 'news, info');
            $script->addMeta('description', 'This module is for news and announcement');
        }
        if($dirname=="schedule"){
            $script->addMeta('robots', 'noindex,nofollow');
        }
        if($dirname=="adult") {
            $script->addMeta('rating', 'adult');
        }
        $script->addMeta('author', 'me');
        $script->addMeta('copyright', 'me');
    }
}
?>
```

## Add language definitions
This tips can be applied to XCL 2.1 and 2.2.
If you want to add language definition in theme file, you can set new language definitions.

```php:html/preload/ThemeLang.class.php
<?php
define('THEME_LANG_SAMPLE_1', 'This is sample');
define('THEME_LANG_NEWS', 'Site News');
define('THEME_LANG_USERNAME', 'Your Name');
?>
```

Then, you can write smarty constant in theme/template.

```
<div><{$smarty.const.THEME_LANG_SAMPLE_1}></div>
<div><{$smarty.const.THEME_LANG_NEWS}></div>
<div><{$smarty.const.THEME_LANG_USERNAME}></div>
```