. */ require_once 'Compiler/Desktop/W3c.php'; /** * Apple Dashboard Widgets Compiler. */ final class Compiler_Desktop_Dashboard extends Compiler_Desktop_W3c { /** * Javascript UWA environment. * * @var string */ protected $_environment = 'Dashboard2'; /** * Stylesheet. * * @var string */ protected $_stylesheet = 'uwa-dashboard.css'; /** * Width of the widget. * * @var string */ protected $_width = 358; /** * Height of the widget. * * @var string */ protected $_height = 600; /** * Platform Name. * * @var string */ protected $_platform = 'dashboard'; /** * Extension. * * @var string */ protected $_extension = 'wdgt.zip'; protected function buildArchive() { $dirname = $this->getNormalizedTitle(); $dirname = preg_replace('/[^a-z0-9:;,?.()[]{}=@ _-]/i', '', $dirname) . '.wdgt/'; // Add the widget skeleton to the archive $ressourcesDir = Zend_Registry::get('uwaRessourcesDir'); if (!is_readable($ressourcesDir)) { throw new Exception('UWA ressources directory is not readable.'); } $this->addDirToZip($ressourcesDir . 'dashboard', $dirname); // Replace the default icon if a rich icon is given $richIcon = $this->_widget->getRichIcon(); if (!empty($richIcon) && preg_match('/\\.png$/i', $richIcon)) { $this->addDistantFileToZip($richIcon, $dirname . 'Icon.png'); } $this->_zip->addFromString($dirname . 'index.html', $this->getHtml() ); $this->_zip->addFromString($dirname . 'Info.plist', $this->_getXmlManifest() ); } protected function _getXmlManifest() { $title = $this->_widget->getTitle(); $metas = $this->_widget->getMetas(); $identifier = preg_replace('/[^a-z0-9]/i', '', $this->_widget->getTitle()); $options = array( 'AllowNetworkAccess' => true, 'AllowInternetPlugins' => true, 'MainHTML' => 'index.html', 'Width' => $this->_width, 'Height' => $this->_height, 'CloseBoxInsetX' => 15, 'CloseBoxInsetY' => 5, 'CFBundleIdentifier' => 'com.netvibes.widget.' . $identifier, 'CFBundleDisplayName' => $title, 'CFBundleName' => $title, 'CFBundleVersion' => isset($metas['version']) ? $metas['version'] : '1.0' ); $l = array(); $l[] = ''; $l[] = ''; $l[] = ''; foreach ($options as $key => $value) { $l[] = '' . htmlspecialchars($key) . ''; if (is_bool($value)) { $l[] = $value ? '' : ''; } elseif (is_int($value)) { $l[] = '' . $value . ''; } else { $l[] = '' . htmlspecialchars($value) . ''; } } $l[] = ''; $l[] = ''; return implode("\n", $l); } protected function _getJavascripts($options = array()) { $javascripts = parent::_getJavascripts($options); $javascripts[] = '/System/Library/WidgetResources/AppleClasses/AppleInfoButton.js'; $javascripts[] = '/System/Library/WidgetResources/AppleClasses/AppleAnimator.js'; $javascripts[] = '/System/Library/WidgetResources/AppleClasses/AppleButton.js'; return $javascripts; } }