/** * Registers a custom client control. * * <p>Each control includes a JS file that defines the class that * will handle the control. Additionally, you can attach a server class and * a HTML code.</p> * * @access public * * @param string $tagPrefix The tag prefix for the control, required. * @param mixed $tagName The tag name for the control, required. * @param string $jsFile The relative path to the JS file that * defines the class that will handle the * control, required. * @param string $phpFile The relative/absolute path to the PHP file * that defines the server class that is * associated with the control, optional. * @param string $url The callback URL for the server class, * optional. * @param string $htmlFile The relative/absolute path to the HTML file * that defines the code that is associated * with the control, optional. * * @return string HTML code to register the custom control. * * @static * */ public static function register($tagPrefix = 'xoad', $tagName = null, $jsFile = null, $phpFile = null, $url = null, $htmlFile = null) { if (empty($phpFile) && empty($jsFile)) { return null; } if (XOAD_Utilities::getType($tagName) == 's_array') { $returnValue = ''; foreach ($tagName as $name) { $returnValue .= XOAD_Controls::register($tagPrefix, $name, $jsFile, $phpFile, $url, $htmlFile); } return $returnValue; } if (XOAD_Utilities::getType($tagName) == 'a_array') { $returnValue = ''; foreach ($tagName as $prefix => $name) { $returnValue .= XOAD_Controls::register($prefix, $name, $jsFile, $phpFile, $url, $htmlFile); } return $returnValue; } if (empty($tagPrefix) || empty($tagName)) { return null; } $registerAttribute = $tagName == '@'; $controlName = strtolower($tagPrefix) . ':' . strtolower($tagName); if (!$registerAttribute && in_array($controlName, $GLOBALS['_XOAD_CONTROLS_LIST'])) { return null; } $phpControlName = $tagPrefix . '_Controls_' . $tagName; $jsControlName = $tagPrefix . '.controls.' . $tagName; $includeScript = ''; $returnValue = ''; if (!empty($phpFile)) { require_once XOAD_Controls::getFileName($phpFile); if (empty($url)) { $url = XOAD_Utilities::getRequestUrl(); } $phpObject = new $phpControlName(); XOAD_Client::privateMethods($phpObject, array('getJSCode', 'getHtmlCode')); $returnValue .= XOAD_Client::register($phpControlName, $url) . ';'; } if (!empty($jsFile)) { if (!in_array($jsFile, $GLOBALS['_XOAD_CONTROLS_SCRIPT'])) { $includeScript .= '<script type="text/javascript" src="' . htmlspecialchars($jsFile) . '"></script>'; $GLOBALS['_XOAD_CONTROLS_SCRIPT'][] = $jsFile; } } else { if (isset($phpObject) && method_exists($phpObject, 'getJSCode')) { $returnValue .= $phpObject->getJSCode($jsControlName, $phpControlName); } } $controlHtml = null; if (!empty($htmlFile)) { $controlHtml = @join(null, @file(XOAD_Controls::getFileName($htmlFile))); } else { if (isset($phpObject) && method_exists($phpObject, 'getHtmlCode')) { $controlHtml = $phpObject->getHtmlCode($jsControlName, $phpControlName); } } if (!$registerAttribute) { $returnValue .= 'xoad.controls.list[' . sizeof($GLOBALS['_XOAD_CONTROLS_LIST']) . '] = {'; $returnValue .= 'tagName:' . XOAD_Client::register($controlName); if (!empty($jsFile)) { $returnValue .= ',clientClass:' . XOAD_Client::register($jsControlName); } if (!empty($phpFile)) { $returnValue .= ',serverClass:' . XOAD_Client::register($phpControlName); } if (!empty($controlHtml)) { $returnValue .= ',html:' . XOAD_Client::register($controlHtml); } $returnValue .= '};'; } if (!empty($returnValue)) { $returnValue = '<script type="text/javascript">' . $returnValue . '</script>'; } $returnValue = $includeScript . $returnValue; $GLOBALS['_XOAD_CONTROLS_LIST'][] = $controlName; return $returnValue; }
<?php require_once '../../xoad.php'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:xoad="http://www.xoad.org/controls" xml:lang="en-US"> <head> <title>XOAD Controls</title> <?php echo XOAD_Utilities::header('../..') . "\n"; ?> <?php echo XOAD_Controls::register('xoad', array('Panel', 'PanelTitle', 'PanelContent', 'PanelFade'), 'xoad.controls.panel.js') . "\n"; ?> </head> <body style="font: normal 0.7em tahoma, verdana, arial, serif; margin: 0; padding: 10px;"> <xoad:Panel id="panel1" top="50px" left="10px" style="display: none"> <xoad:PanelTitle>Hi There!</xoad:PanelTitle> <xoad:PanelContent> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam ipsum nunc, sodales a, posuere in, ullamcorper a, massa. Fusce nonummy lectus non tellus. Fusce nonummy elit at nulla. Phasellus tristique est nec felis. Curabitur lacus purus, vestibulum vel, imperdiet ut, placerat a, libero. In a tortor sit amet lorem mollis placerat. Proin sed lectus. Aliquam hendrerit mattis ipsum. Donec iaculis. Vivamus rhoncus. Phasellus metus velit, feugiat eget, feugiat eu, tincidunt sit amet, diam. Vivamus porta quam nec neque porttitor tempus. Fusce lacus. Pellentesque turpis diam, rhoncus ultricies, sagittis id, euismod sed, libero. Duis orci dolor, rutrum id, gravida vitae, viverra quis, neque. Cras commodo consequat diam. Nulla