source: trunk/Modules/WebCam/WebCam.php

Last change on this file was 927, checked in by chronos, 3 years ago
  • Modified: Updated fixed webcams links.
File size: 3.3 KB
Line 
1<?php
2
3class PageWebcam extends Page
4{
5 function __construct(System $System)
6 {
7 parent::__construct($System);
8 $this->Title = 'Kamera';
9 $this->Description = 'Webová kamera';
10 $this->ParentClass = 'PagePortal';
11 }
12
13 function Show(): string
14 {
15 if (file_exists(ModuleWebCam::Cast($this->System->GetModule('WebCam'))->ImageFileName))
16 {
17 $Output = '<script language="JavaScript">
18 var ImageURL = "'.$this->System->Config['Web']['RootFolder'].'/webcam/'.ModuleWebCam::Cast($this->System->GetModule('WebCam'))->ImageFileName.'";
19
20 // Force an immediate image load
21 var theTimer = setTimeout("reloadImage()", 1);
22
23 function reloadImage()
24 {
25 theDate = new Date();
26 var url = ImageURL;
27 url += "?dummy=";
28 url += theDate.getTime().toString(10);
29 // The above dummy cgi-parameter enforce a bypass of the browser image cache.
30 // Here we actually load the image
31 document.theImage.src = url;
32
33 // Reload the image every defined period
34 theTimer = setTimeout("reloadImage()", '.($this->System->Config['Web']['WebcamRefresh'] * 1000).');
35 }
36 </script>';
37
38 $Output .= '<br /><div align="center"><img name="theImage" src="" idth="640" height="480" alt="Webcam image"><br>Poslední aktualizace: '.
39 date('j.n.Y G:i', filemtime(ModuleWebCam::Cast($this->System->GetModule('WebCam'))->ImageFileName)).
40 '<br>Obnovování po '.$this->System->Config['Web']['WebcamRefresh'].' sekundách</div><br />';
41 } else $Output = '<br />Obrázek nenalezen.<br /><br />';
42
43 $Output .= '<strong>Kamery v okolí:</strong><br />'.
44 '<a href="http://www.mestovsetin.cz/vismo/dokumenty2.asp?id_org=18676&id=480245">Webové kamery ve Vsetíně</a><br />';
45
46 return $Output;
47 }
48}
49
50class ModuleWebCam extends Module
51{
52 public string $ImageFileName = 'webcam.jpg';
53
54 function __construct(System $System)
55 {
56 parent::__construct($System);
57 $this->Name = 'WebCam';
58 $this->Version = '1.0';
59 $this->Creator = 'Chronos';
60 $this->License = 'GNU/GPLv3';
61 $this->Description = 'Web camera image presentetation';
62 }
63
64 function DoStart(): void
65 {
66 $this->System->Pages['webcam'] = 'PageWebcam';
67 }
68
69 function ShowImage(): string
70 {
71 $Output = '';
72 $Output .= '<a href="//www.zdechov.net/kamery/?Id=5"><img alt="Koupaliště" width="140" height="79" src="//www.zdechov.net/images/webcam/webcam5.jpg" /></a>';
73 $Output .= '<a href="//www.zdechov.net/kamery/?Id=1"><img alt="Centrum obce" width="140" height="79" src="//www.zdechov.net/images/webcam/webcam1.jpg" /></a>';
74 $Output .= '<a href="//www.zdechov.net/kamery/?Id=2"><img alt="Střed obce obloha" width="140" height="79" src="//www.zdechov.net/images/webcam/webcam2.jpg" /></a>';
75 $Output .= '<a href="//www.zdechov.net/kamery/?Id=3"><img alt="Skiareál, motokrosová grapa" width="140" height="79" src="//www.zdechov.net/images/webcam/webcam3.jpg" /></a>';
76 $Output .= '<a href="//www.zdechov.net/kamery/?Id=4"><img alt="Fotbalové hřiště" width="140" height="79" src="//www.zdechov.net/images/webcam/webcam4.jpg" /></a>';
77 return $Output;
78 }
79
80 static function Cast(Module $Module): ModuleWebCam
81 {
82 if ($Module instanceof ModuleWebCam)
83 {
84 return $Module;
85 }
86 throw new Exception('Expected ModuleWebCam type but got '.gettype($Module));
87 }
88}
Note: See TracBrowser for help on using the repository browser.