~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/ecosystem/workspace/ecosystem/uwa-server-original/server/lib/Exposition/Compiler/Desktop/W3c.php

  • Committer: parra
  • Date: 2010-03-15 02:39:02 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1433
merged gelee at svn

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Copyright Netvibes 2006-2009.
 
4
 * This file is part of Exposition PHP Lib.
 
5
 * 
 
6
 * Exposition PHP Lib is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU Lesser General Public License as published by
 
8
 * the Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 * 
 
11
 * Exposition PHP Lib is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU Lesser General Public License for more details.
 
15
 * 
 
16
 * You should have received a copy of the GNU Lesser General Public License
 
17
 * along with Exposition PHP Lib.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
 
 
21
require_once 'Compiler/Desktop.php';
 
22
 
 
23
/**
 
24
 * Apple Dashboard Widgets Compiler.
 
25
 */
 
26
abstract class Compiler_Desktop_W3c extends Compiler_Desktop
 
27
{
 
28
 
 
29
    /**
 
30
     * Extension.
 
31
     *
 
32
     * @var string
 
33
     */
 
34
    protected $_extension = 'zip';
 
35
 
 
36
    /**
 
37
     * Mime Type.
 
38
     *
 
39
     * @var string
 
40
     */
 
41
    protected $_mimeType = 'application/zip';
 
42
 
 
43
    public function getHtml()
 
44
    {
 
45
        $l = array();
 
46
 
 
47
        $l[] = '<?xml version="1.0" encoding="utf-8"?>';
 
48
        $l[] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"' .
 
49
            ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
 
50
        $l[] = '<html xmlns="http://www.w3.org/1999/xhtml">';
 
51
        $l[] = '<head>';
 
52
        $l[] = '<title>' . $this->_widget->getTitle() . '</title>';
 
53
        $l[] = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>';
 
54
 
 
55
        foreach ($this->_getStylesheets() as $stylesheet) {
 
56
            $l[] = '<link rel="stylesheet" type="text/css" href="' . htmlspecialchars($stylesheet) . '"/>';
 
57
        }
 
58
 
 
59
        $l[] = '</head>';
 
60
        $l[] = '<body>';
 
61
 
 
62
        $l[] = $this->_getHtmlBody();
 
63
 
 
64
        $l[] = $this->_getJavascriptConstants();
 
65
 
 
66
        $javascripts = $this->_getJavascripts( array('platform' => $this->_platform) );
 
67
 
 
68
        foreach ($javascripts as $script) {
 
69
            $l[] = "<script type='text/javascript' src='" . htmlspecialchars($script) . "' charset='utf-8'/>";
 
70
        }
 
71
 
 
72
        $l[] = '<script type="text/javascript">';
 
73
        $l[] = $this->_getScript();
 
74
        $l[] = '</script>';
 
75
 
 
76
        if (isset($this->options['appendBody'])) {
 
77
            $l[] = $this->options['appendBody'];
 
78
        }
 
79
 
 
80
        $l[] = '</body>';
 
81
        $l[] = '</html>';
 
82
 
 
83
        return implode("\n", $l);
 
84
    }
 
85
 
 
86
    private function _getHtmlBody()
 
87
    {
 
88
        $l = array();
 
89
 
 
90
        $l[] = '<div class="module" id="wrapper">';
 
91
        $l[] =   $this->_getHtmlHeader();
 
92
        $l[] =   '<div id="contentWrapper">';
 
93
        $l[] =     '<div class="moduleContent" id="moduleContent">';
 
94
        $l[] =       $this->_widget->getBody();
 
95
        $l[] =     '</div>';
 
96
        $l[] =     $this->_getHtmlStatus();
 
97
        $l[] =   '</div>';
 
98
        $l[] =   '<div class="moduleFooter" id="moduleFooter"></div>';
 
99
        $l[] = '</div>';
 
100
 
 
101
        return implode("\n", $l);
 
102
    }
 
103
 
 
104
    private function _getScript()
 
105
    {
 
106
        $l = array();
 
107
 
 
108
        $proxies = array(
 
109
            'ajax' => Zend_Registry::get('proxyEndpoint') . '/ajax',
 
110
            'feed' => Zend_Registry::get('proxyEndpoint') . '/feed'
 
111
        );
 
112
 
 
113
        $l[] = sprintf('UWA.proxies = %s;', Zend_Json::encode($proxies));
 
114
 
 
115
        $l[] = "var id = window.widget ? widget.identifier : Math.round(Math.random() * 1000);";
 
116
        $l[] = "Environments[id] = new UWA.Environment();";
 
117
        $l[] = "Widgets[id] = Environments[id].getModule();";
 
118
        $l[] = "UWA.script(Widgets[id]);";
 
119
        $l[] = "Environments[id].launchModule();";
 
120
 
 
121
        return implode("\n", $l);
 
122
    }
 
123
 
 
124
    public function getFileName()
 
125
    {
 
126
        $filename = $this->getNormalizedTitle();
 
127
        if (!empty($filename)) {
 
128
            return $filename . '.' . $this->_extension;
 
129
        } else {
 
130
            return 'Widget' . '.' . $this->_extension;
 
131
        }
 
132
    }
 
133
 
 
134
    public function getNormalizedTitle()
 
135
    {
 
136
        return $this->_widget->getTitle();
 
137
    }
 
138
 
 
139
    public function getFileMimeType()
 
140
    {
 
141
        return $this->_mimeType;
 
142
    }
 
143
 
 
144
    /*** ABSTRACT FUNCTIONS ***/
 
145
 
 
146
    abstract protected function _getXmlManifest();
 
147
 
 
148
}