~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to src/php/HelioviewerClient.php

  • Committer: Keith Hughitt
  • Date: 2012-06-12 20:18:46 UTC
  • Revision ID: keith.hughitt@gmail.com-20120612201846-k3nm2g2sznpfumhc
Added latest movies page

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
 * HelioviewerClient class definition
4
 
 *
5
 
 * An abstract base class representing a generic Helioviewer client instance
6
 
 *
7
 
 * PHP version 5
8
 
 *
9
 
 * @category Application
10
 
 * @package  Helioviewer
11
 
 * @author   Jeff Stys <jeff.stys@nasa.gov>
12
 
 * @author   Keith Hughitt <keith.hughitt@nasa.gov>
13
 
 * @license  http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License 1.1
14
 
 * @link     http://launchpad.net/helioviewer.org
15
 
 */
16
 
/**
17
 
 * HelioviewerClient class definition
18
 
 *
19
 
 * An abstract base class representing a generic Helioviewer client instance
20
 
 *
21
 
 * PHP version 5
22
 
 *
23
 
 * @category Application
24
 
 * @package  Helioviewer
25
 
 * @author   Jeff Stys <jeff.stys@nasa.gov>
26
 
 * @author   Keith Hughitt <keith.hughitt@nasa.gov>
27
 
 * @license  http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License 1.1
28
 
 * @link     http://launchpad.net/helioviewer.org
29
 
 */
30
 
abstract class HelioviewerClient {
31
 
 
 
1
<?php 
 
2
/**
 
3
 * HelioviewerClient class definition
 
4
 * 
 
5
 * An abstract base class representing a generic Helioviewer client instance
 
6
 *
 
7
 * PHP version 5
 
8
 *
 
9
 * @category Application
 
10
 * @package  Helioviewer
 
11
 * @author   Keith Hughitt <keith.hughitt@nasa.gov>
 
12
 * @license  http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License 1.1
 
13
 * @link     http://launchpad.net/helioviewer.org
 
14
 */
 
15
/**
 
16
 * HelioviewerClient class definition
 
17
 * 
 
18
 * An abstract base class representing a generic Helioviewer client instance
 
19
 *
 
20
 * PHP version 5
 
21
 *
 
22
 * @category Application
 
23
 * @package  Helioviewer
 
24
 * @author   Keith Hughitt <keith.hughitt@nasa.gov>
 
25
 * @license  http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License 1.1
 
26
 * @link     http://launchpad.net/helioviewer.org
 
27
 */
 
28
abstract class HelioviewerClient
 
29
{
32
30
    protected $config;
33
31
    protected $urlSettings;
34
32
    protected $compressedJSFile;
35
33
    protected $compressedCSSFile;
36
 
 
 
34
    
37
35
    /**
38
36
     * Initializes an instance of a Helioviewer client
39
37
     */
40
 
    public function __construct($urlSettings, $ini='settings/Config.ini') {
41
 
 
 
38
    public function __construct($urlSettings, $ini="settings/Config.ini")
 
39
    {
42
40
        // Load Server Configuration
43
 
        if ( (!@file_exists($ini)) ||
44
 
             (!$this->config = parse_ini_file($ini)) ) {
45
 
 
46
 
            die('Missing config file!');
 
41
        if ((!file_exists($ini)) || (!$this->config = parse_ini_file($ini))) {
 
42
            die("Missing config file!");
47
43
        }
48
 
 
 
44
        
49
45
        // Settings specified via URL parameters
50
46
        $this->urlSettings = $urlSettings;
51
 
 
 
47
        
52
48
        // Debug support
53
 
        if ( array_key_exists('debug', $this->urlSettings) &&
54
 
             $this->urlSettings['debug'] ) {
55
 
 
56
 
            $this->config['compress_js']
57
 
                = $this->config['compress_css'] = false;
 
49
        if ($this->urlSettings['debug']) {
 
50
            $this->config['compress_js'] = $this->config['compress_css'] = false;
58
51
        }
59
52
 
60
53
        // Print HTML
61
54
        $this->printHTML();
62
55
    }
63
 
 
 
56
    
64
57
    /**
65
58
     * Prints Helioviewer HTML
66
59
     */
67
 
    protected function printHTML() {
68
 
 
 
60
    protected function printHTML()
 
61
    {
69
62
        // Version string
70
 
        $signature = 'rev=' + $this->config['disable_cache'] ?
71
 
            time() : $this->config['build_num'];
 
63
        $signature = "rev=" + $this->config['disable_cache'] ? time() : $this->config['build_num'];
72
64
?>
73
65
<!DOCTYPE html>
74
66
<html lang="en">
81
73
</html>
82
74
<?php
83
75
    }
84
 
 
 
76
    
85
77
    /**
86
78
     * Prints the HTML head section
87
79
     */
93
85
    <meta name="description" content="Helioviewer.org - Solar and heliospheric image visualization tool" />
94
86
    <meta name="keywords" content="Helioviewer, JPEG 2000, JP2, sun, solar, heliosphere, solar physics, viewer, visualization, space, astronomy, SOHO, SDO, STEREO, AIA, HMI, EUVI, COR, EIT, LASCO, SDO, MDI, coronagraph, " />
95
87
    <?php if ($this->config["disable_cache"]) echo "<meta http-equiv=\"Cache-Control\" content=\"No-Cache\" />";?>
96
 
 
 
88
    
97
89
    <link rel="shortcut icon" href="favicon.ico" />
98
 
 
 
90
    
99
91
    <!--OpenGraph Metadata-->
100
92
    <meta property="og:title" content="Helioviewer.org" />
101
93
<?php
102
94
        $this->addOpenGraphTags();
103
 
 
 
95
        
104
96
        // CSS includes
105
97
        $this->loadCSS();
106
98
        $this->loadCustomCSS($signature);
107
 
 
 
99
        
108
100
        // Google Analytics
109
101
        if ($this->config['google_analytics_id']) {
110
102
            $this->loadGoogleAnalytics();
111
103
        }
 
104
        
 
105
        // AddThis
 
106
        if ($this->config['addthis_analytics_id']) {
 
107
            $this->loadAddThis();
 
108
        }
112
109
    }
113
110
 
114
111
    /**
115
112
     * Prints HTML body section
116
113
     */
117
 
    protected function printBody($signature) {
 
114
    protected function printBody($signature)
 
115
    {
118
116
        $this->loadJS();
119
117
        $this->loadCustomJS($signature);
120
118
?>
136
134
    $(function () {
137
135
        <?php
138
136
            printf("settingsJSON = %s;\n", json_encode($this->config));
139
 
 
 
137
            
140
138
            // Compute acceptible zoom values
141
139
            $zoomLevels = array();
142
 
 
 
140
            
143
141
            for($imageScale = $this->config["min_image_scale"]; $imageScale <= $this->config["max_image_scale"]; $imageScale = $imageScale * 2) {
144
142
                $zoomLevels[] = round($imageScale, 8);
145
143
            }
146
 
 
 
144
            
147
145
            printf("\tzoomLevels = %s;\n", json_encode($zoomLevels));
148
146
 
149
147
            // Convert to JSON
151
149
        ?>
152
150
        serverSettings = new Config(settingsJSON).toArray();
153
151
 
154
 
<?php
 
152
    <?php
155
153
    }
156
 
 
 
154
    
157
155
    /**
158
156
     * Adds OpenGraph meta tags
159
157
     */
160
158
    protected function addOpenGraphTags() {
161
159
?>
162
 
    <meta id="fb-og-image" property="og:description" content="Solar and heliospheric image visualization tool." />
163
 
    <meta id="fb-og-image" property="og:image" content="http://helioviewer.org/resources/images/logos/hvlogo1s_transparent.png" />
 
160
    <meta property="og:description" content="Solar and heliospheric image visualization tool." />
 
161
    <meta property="og:image" content="http://helioviewer.org/resources/images/logos/hvlogo1s_transparent.png" />
164
162
<?php
165
163
    }
166
 
 
 
164
    
167
165
    /**
168
166
     * Loads CSS includes
169
167
     */
170
168
    protected function loadCSS()
171
169
    {
172
 
?>
 
170
    ?>
173
171
 
174
172
    <!-- Library CSS -->
175
173
    <link rel="stylesheet" href="lib/yui-2.8.2r1/reset-fonts.css" />
176
 
    <link rel="stylesheet" href="lib/jquery.ui-1.8/css/dot-luv-modified/jquery-ui-1.8.12.custom.css" />
 
174
    <link rel="stylesheet" href="lib/jquery.ui-1.8/css/dot-luv-modified/jquery-ui-1.8.12.custom.css" />  
177
175
<?php
178
176
    }
179
 
 
 
177
    
180
178
    /**
181
179
     * Loads Helioviewer-specific CSS files
182
180
     */
183
181
    protected function loadCustomCSS($signature, $includes=array()) {
184
182
?>
185
183
    <!-- Helioviewer CSS -->
186
 
<?php
 
184
    <?php
187
185
        $css = array_merge(array("helioviewer-base", "zoom-control"), $includes);
188
 
 
 
186
        
189
187
        // CSS
190
188
        if ($this->config["compress_css"]) {
191
189
            echo "<link rel=\"stylesheet\" href=\"build/css/{$this->compressedCSSFile}?$signature\" />\n    ";
195
193
                printf("<link rel=\"stylesheet\" href=\"resources/css/%s.css?$signature\" />\n    ", $file);
196
194
        }
197
195
    }
198
 
 
 
196
    
199
197
    /**
200
198
     * Loads JavaScript includes
201
199
     */
202
200
    protected function loadJS() {
203
 
        if ($this->config["compress_js"]) {
204
 
?>
 
201
    if ($this->config["compress_js"]) {
 
202
    ?>
205
203
<!-- Library JavaScript -->
206
 
<script src="lib/jquery/jquery-1.7.2.min.js" type="text/javascript"></script>
207
 
<script src="lib/jquery-ui/jquery-ui.1.8.18.min.js" type="text/javascript"></script>
 
204
<script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script>
 
205
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js" type="text/javascript"></script>
208
206
<script src="lib/jquery.class/jquery.class.min.js" type="text/javascript"></script>
209
207
<script src="lib/jquery.mousewheel.3.0.6/jquery.mousewheel.min.js" type="text/javascript"></script>
210
208
<script src="lib/date.js/date-en-US.js" type="text/javascript"></script>
211
209
<script src="lib/jquery.qTip2/jquery.qtip.min.js" type="text/javascript"></script>
212
 
<script src="lib/jquery-number-master/jquery.number.min.js" type="text/javascript"></script>
213
210
<?php
214
211
        } else {
215
 
?>
 
212
?>    
216
213
<!-- Library JavaScript -->
217
 
<script src="lib/jquery/jquery-1.7.2.js" type="text/javascript"></script>
218
 
<script src="lib/jquery-ui/jquery-ui.1.8.18.js" type="text/javascript"></script>
 
214
<script src="http://code.jquery.com/jquery-1.7.2.js" type="text/javascript"></script>
 
215
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.js" type="text/javascript"></script>
219
216
<script src="lib/jquery.class/jquery.class.js" type="text/javascript"></script>
220
217
<script src="lib/jquery.mousewheel.3.0.6/jquery.mousewheel.js" type="text/javascript"></script>
221
218
<script src="lib/date.js/date-en-US.js" type="text/javascript"></script>
222
219
<script src="lib/jquery.qTip2/jquery.qtip.js" type="text/javascript"></script>
223
 
<script src="lib/jquery-number-master/jquery.number.js" type="text/javascript"></script>
224
220
<?php
225
221
}
226
222
?>
229
225
<script src="lib/Cookiejar/jquery.cookiejar.pack.js" type="text/javascript"></script>
230
226
<?php
231
227
    }
232
 
 
 
228
    
233
229
    /**
234
230
     * Loads Helioviewer-specific JS files
235
231
     */
236
232
    protected function loadCustomJS($signature, $includes=array()) {
237
233
        echo "\n<!-- Helioviewer JavaScript -->\n";
238
 
 
239
234
        if ($this->config["compress_js"]) {
240
235
            if (!file_exists("build/" . $this->compressedJSFile)) {
241
236
               $error = "<div style='position: absolute; width: 100%; text-align: center; top: 40%; font-size: 14px;'>
242
 
                         <img src='".HV_API_URL."/resources/images/logos/about.png' alt='helioviewer logo'></img><br/>
 
237
                         <img src='resources/images/logos/about.png' alt='helioviewer logo'></img><br>
243
238
                         <b>Configuration:</b> Unable to find compressed JavaScript files.
244
 
                         If you haven't already, use Apache Ant with the included build.xml file to generate
 
239
                         If you haven't already, use Apache Ant with the included build.xml file to generate 
245
240
                         compressed files.</div></body></html>";
246
241
               die($error);
247
242
            }
248
 
 
 
243
        
249
244
            echo "<script src=\"build/{$this->compressedJSFile}?$signature\" type=\"text/javascript\"></script>\n\t";
250
245
        }
251
246
        else {
252
 
            $js = array("Utility/Config.js", "Utility/HelperFunctions.js",
253
 
                        "Tiling/Layer/Layer.js", "Tiling/Layer/TileLoader.js", "Tiling/Layer/TileLayer.js",
254
 
                        "Tiling/Layer/HelioviewerTileLayer.js", "Utility/KeyboardManager.js",
255
 
                        "Tiling/Manager/LayerManager.js", "Tiling/Manager/TileLayerManager.js",
256
 
                        "Tiling/Manager/HelioviewerTileLayerManager.js", "Image/JP2Image.js",
257
 
                        "Viewport/Helper/MouseCoordinates.js", "Viewport/Helper/HelioviewerMouseCoordinates.js",
258
 
                        "Viewport/Helper/SandboxHelper.js", "Viewport/Helper/ViewportMovementHelper.js",
259
 
                        "Viewport/HelioviewerViewport.js", "HelioviewerClient.js", "UI/ZoomControls.js",
260
 
                        "UI/ImageScale.js", "Utility/InputValidator.js", "Utility/SettingsLoader.js",
261
 
                        "Utility/UserSettings.js", "Tiling/Manager/LayerManager.js", "Events/EventManager.js",
262
 
                        "Events/EventType.js", "Events/EventTree.js", "Events/EventFeatureRecognitionMethod.js",
263
 
                        "Events/EventLayerManager.js", "Events/EventMarker.js", "Events/EventLayerManager.js",
264
 
                        "Events/HelioviewerEventLayer.js", "Events/HelioviewerEventLayerManager.js");
 
247
            $js = array("Utility/Config.js", "Utility/HelperFunctions.js", 
 
248
                        "Tiling/Layer/Layer.js", "Tiling/Layer/TileLoader.js", "Tiling/Layer/TileLayer.js", 
 
249
                        "Tiling/Layer/HelioviewerTileLayer.js", "Utility/KeyboardManager.js", "Tiling/Manager/LayerManager.js", 
 
250
                        "Tiling/Manager/TileLayerManager.js", "Tiling/Manager/HelioviewerTileLayerManager.js", 
 
251
                        "Image/JP2Image.js", "Viewport/Helper/MouseCoordinates.js", 
 
252
                        "Viewport/Helper/HelioviewerMouseCoordinates.js", "Viewport/Helper/SandboxHelper.js",
 
253
                        "Viewport/Helper/ViewportMovementHelper.js", "Viewport/HelioviewerViewport.js", 
 
254
                        "HelioviewerClient.js", "UI/ZoomControls.js", "Utility/InputValidator.js",
 
255
                        "Utility/SettingsLoader.js", "Utility/UserSettings.js");
265
256
            foreach(array_merge($js, $includes) as $file)
266
257
                printf("<script src=\"src/js/%s?$signature\" type=\"text/javascript\"></script>\n", $file);
267
258
        }
268
259
    }
269
 
 
 
260
    
270
261
    /**
271
262
     * Loads Google Analytics
272
263
     */
273
 
    protected function loadGoogleAnalytics() {
 
264
    protected function loadGoogleAnalytics()
 
265
    {
274
266
?>
275
267
    <!-- Google Analytics -->
276
268
    <script type="text/javascript">
278
270
        _gaq.push(['_setAccount', '<?php echo $this->config["google_analytics_id"];?>']);
279
271
        _gaq.push(['_trackPageview']);
280
272
        _gaq.push(['_trackPageLoadTime']);
281
 
 
 
273
        
282
274
        (function() {
283
275
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
284
276
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
288
280
 
289
281
<?php
290
282
    }
291
 
 
292
 
}
293
 
?>
 
 
b'\\ No newline at end of file'
 
283
    
 
284
    /**
 
285
     * Loads AddThis support
 
286
     */
 
287
    protected function loadAddThis()
 
288
    {
 
289
?>
 
290
 
 
291
    <!-- AddThis -->
 
292
    <script type="text/javascript">
 
293
        var addthis_config = {
 
294
            data_track_clickback: true,
 
295
            pubid: "<?php echo $this->config['addthis_analytics_id'];?>",
 
296
            data_ga_property: "<?php echo $this->config['google_analytics_id'];?>"
 
297
        };
 
298
    </script>
 
299
    <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#async=1"></script>        
 
300
<?php
 
301
    }
 
302
 
 
303
 
 
304
}
 
 
b'\\ No newline at end of file'