. */ /** * Compiler main class. */ abstract class Compiler { /** * Widget instance. * * @var Widget */ protected $_widget; /** * Javascript UWA environment. * * @var string */ protected $_environment; /** * Stylesheet. * * @var string */ protected $_stylesheet; /** * Platform Name. * * @var string */ protected $_platform; /** * JavaScript core libraries. * * @var array */ protected $_coreLibraries; /** * Compiler options. * * @var array */ public $options = array(); /** * Constructor. * * @param Widget $widget */ public function __construct($widget) { $this->_widget = $widget; $baseLibraries = array( 'String.js', 'Array.js', 'Element.js', 'Data.js', 'Environment.js', 'Widget.js', 'Utils.js', 'Utils/Client.js', 'Controls/PrefsForm.js' ); $this->_coreLibraries['uwa'] = array_merge( array('UWA.js', 'Drivers/UWA-alone.js', 'Drivers/UWA-legacy.js'), $baseLibraries); $this->_coreLibraries['uwa-mootools'] = array_merge( array('../lib/mootools.js', 'UWA.js', 'Drivers/UWA-mootools.js'), $baseLibraries); } /** * Sets the options. * * @param array $options * @return Compiler Object instance */ public function setOptions($options = array()) { foreach ($options as $k => $v) { $this->options[$k] = $v; } return $this; } /** * Set the UWA javascript environment * * @param string $environment */ public function setEnvironment($environment) { $this->_environment = $environment; } /** * Retrieves the list of the stylesheets used in a widget. * * @return array */ protected function _getStylesheets() { $stylesheets = array(); // Netvibes stylesheets $NVstylesheets = array(Zend_Registry::get('uwaCssDir') . $this->_stylesheet); if (isset($_GET['NVthemeUrl'])) { $NVstylesheets[] = 'http://' . NV_STATIC . $_GET['NVthemeUrl']; } foreach ($NVstylesheets as $stylesheet) { if (Zend_Registry::get('useMergedCss')) { $stylesheet = str_replace('.css', '.css.m.css', $stylesheet); } $stylesheets[] = $stylesheet . '?v=' . Zend_Registry::get('cssVersion'); } // Widget style $style = $this->_widget->getStyle(); if ( !empty($style) ) { $cssBaseUrl = Zend_Registry::get('widgetEndpoint') . '/css'; if (isset($this->options['uwaId'])) { $stylesheets[] = $cssBaseUrl . '/' . urlencode($this->options['uwaId']); } else { $stylesheets[] = $cssBaseUrl . '?uwaUrl=' . urlencode($this->_widget->getUrl()); } } // Widget external stylesheets return array_merge($stylesheets, $this->_widget->getExternalStylesheets()); } /** * Retrieves the list of the JavaScript core libraries used in a widget. * * @param string $name * @return array */ protected function _getCoreLibraries($name = 'uwa') { $javascripts = array(); $coreLibraryName = $this->_widget->getCoreLibrary(); $version = Zend_Registry::get('jsVersion'); if (Zend_Registry::get('useCompressedJs')) { switch ($coreLibraryName) { case 'uwa': $javascripts[] = Zend_Registry::get('uwaJsDir') . 'UWA_' . ucfirst($this->_environment) . '.js?v=' . $version; break; case 'uwa-mootools': $javascripts[] = Zend_Registry::get('uwaJsDir') . 'UWA_' . ucfirst($this->_environment) . '_Mootools.js?v=' . $version; break; default: throw new Exception('CoreLibrary name not known.'); } } else { if (empty($this->_coreLibraries[$coreLibraryName])) { throw new Exception('CoreLibrary name not known.'); } foreach ($this->_coreLibraries[$coreLibraryName] as $js) { $javascripts[] = Zend_Registry::get('uwaJsDir') . $js . '?v=' . $version; } if (isset($this->_environment)) { $javascripts[] = Zend_Registry::get('uwaJsDir') . 'Environments/' . ucfirst($this->_environment) . '.js?v=' . $version; } } return $javascripts; } /** * Retrieves the list of the JavaScript libraries used in a widget (both UWA and specific ones). * * @param string $name * @return array */ protected function _getJavascripts($options = array()) { $javascripts = $this->_getCoreLibraries(); // Widget script $jsBaseUrl = Zend_Registry::get('widgetEndpoint') . '/js'; if (isset($this->options['uwaId'])) { $widgetJs = $jsBaseUrl . '/' . urlencode($this->options['uwaId']); if (isset($options['platform'])) { $widgetJs .= '?platform=' . $options['platform']; } } else { $widgetJs = $jsBaseUrl . '?uwaUrl=' . urlencode($this->_widget->getUrl()); if (isset($options['platform'])) { $widgetJs .= '&platform=' . $options['platform']; } } $javascripts[] = $widgetJs; // Merge with external scripts return array_merge($javascripts, $this->_widget->getExternalScripts()); } /** * Retrieves widget HTML header (moduleHeader) * * @return string */ protected function _getHtmlHeader() { $icon = $this->_widget->getIcon(); if (empty($icon)) { $icon = 'http://' . NV_STATIC . '/modules/uwa/icon.png'; } $html = '
';
$html .= '' . "\n";
$html .= 'powered by netvibes' . "\n";
$html .= '