<?php
/**
 * @version $Id: AssetPreload.class.php 679 2012-08-20 12:41:35Z hodaka $
 * @package myuploader
 */

if(!defined('XOOPS_ROOT_PATH')) exit();
if(!defined('XOOPS_TRUST_PATH')) die('set XOOPS_TRUST_PATH in mainfile.php');

require_once dirname(dirname(__FILE__)).'/class/MyuploaderUtils.class.php';

$root = XCube_Root::getSingleton();
$root->mDelegateManager->add('Module.myuploader.Event.GetAssetManager','Myuploader_AssetPreload::getManager');
$root->mDelegateManager->add('Legacy_Utils.CreateModule','Myuploader_AssetPreload::getModule');
$root->mDelegateManager->add('Module.myuploader.Event.GetModuleGlobal','Myuploader_AssetPreload::getModuleGlobal');
$root->mDelegateManager->add('Legacy_Utils.CreateBlockProcedure','Myuploader_AssetPreload::getBlock');
unset($root);


/**
 * Myuploader_AssetPreload
 */
class Myuploader_AssetPreload extends XCube_ActionFilter
{
    /**
     * getManager
     *
     * @param   Myuploader_AssetManager  &$obj
     * @param   string  $dirname
     *
     * @return  void
     *
     * @private
     */
    function getManager(&$obj, $dirname)
    {
        require_once dirname(dirname(__FILE__)).'/class/AssetManager.class.php';
        $obj = Myuploader_AssetManager::getInstance($dirname);
    }

    /**
     * getModuleGlobal
     *
     * @param   Myuploader_Global  &$obj
     * @param   dirname  $dirname
     *
     * @return  void
     *
     * @private
     */
    function getModuleGlobal(&$obj, $dirname) {
        require_once dirname(dirname(__FILE__)).'/class/Global.class.php';
        $obj = Myuploader_Global::getInstance($dirname);
    }

    /**
     * getModule
     *
     * @param   Legacy_AbstractModule  &$obj
     * @param   XoopsModule  $module
     *
     * @return  void
     *
     * @private
     */
    function getModule(&$obj, $module)
    {
        $file = XOOPS_ROOT_PATH.'/modules/'.$module->get('dirname').'/mytrustdirname.php';
        if(file_exists($file) && $module->getinfo('package_name') == 'myuploader') {
            require_once dirname(dirname(__FILE__)).'/class/Module.class.php';
            $obj = new Myuploader_Module($module);
        }
    }

    /**
     * getBlock
     *
     * @param   Legacy_AbstractBlockProcedure  &$obj
     * @param   XoopsBlock  $block
     *
     * @return  void
     *
     * @private
    **/
    function getBlock(&$obj, $block)
    {
        $moduleHandler =& Myuploader_Utils::getXoopsHandler('module');
        $module =& $moduleHandler->get($block->get('mid'));
        if(is_object($module) && $module->getinfo('package_name') == 'myuploader') {
            require_once dirname(dirname(__FILE__)).'/blocks/'.$block->get('func_file');
            $className = 'Myuploader_' . substr($block->get('show_func'), 4);
            $obj = new $className($block);

            // assign block header
            Myuploader_Utils::assignBlockHeader($block->get('dirname'));
        }
    }
}

?>