YaWK  24.1
Yet another WebKit
clock.php
Go to the documentation of this file.
1 <?php
3 {
4  /**
5  * @details<b>Embed a digital clock on your website.</b>
6  *
7  * <p>The clock shows the current time. (wonder, oh wonder...) You can set the clock's font color,
8  * alignment (left, center or right) as well as a custom css class to design it and put some FX on
9  * if you need to. If you need an analog clock anywhere on your website, this widget does the job.</p>
10  *
11  *
12  * @author Daniel Retzl <[email protected]>
13  * @copyright 2018 Daniel Retzl
14  * @version 1.0.0
15  * @brief Embed a digital real-time clock on your website.
16  */
17  class clock
18  {
19  /** @param object global widget object data */
20  public $widget = '';
21  /** @param string Clock color */
22  public $clockColor = '#f5f5f5';
23  /** @param string Clock alignment */
24  public $clockAlign = 'text-center';
25  /** @param string Clock class */
26  public $clockClass = 'h1';
27 
28  /**
29  * @brief Load all widget settings from database and fill object
30  * @param object $db Database Object
31  * @brief Load all widget settings on object init.
32  */
33  public function __construct($db)
34  {
35  // load this widget settings from db
36  $this->widget = new \YAWK\widget();
38  foreach ($settings as $property => $value) {
39  $this->$property = $value;
40  }
41  }
42 
43  /**
44  * @brief Print all object data
45  * @brief (for development and testing purpose)
46  */
47  public function printObject()
48  {
49  echo "<pre>";
50  print_r($this);
51  echo "</pre>";
52  }
53 
54  /**
55  * @brief Initialize: prepare JS and start the clock
56  * @brief use this method to run the clock
57  */
58  public function init()
59  {
60  $this->loadJavascript();
61  $this->drawClock();
62  }
63 
64  /**
65  * @brief Load required javascript
66  * @brief The engine behind this clock
67  */
68  public function loadJavascript()
69  {
70  echo"<body onload=\"clock();\">
71  <script type=\"text/javascript\">
72  function clock() {
73  var now = new Date();
74  var minute = now.getMinutes();
75  var second= now.getSeconds();
76  var hour = now.getHours();
77  if(minute<10) minute = \"0\" + minute;
78  if(second<10) second= \"0\" + second;
79  if(hour<10) hour=\"0\" + hour;
80  var outStr = hour+':'+minute+':'+second;
81  /* output string without leading zero int
82  * var outStr = now.getHours()+':'+now.getMinutes()+':'+now.getSeconds(); */
83  document.getElementById('clockDiv').innerHTML=outStr;
84  setTimeout('clock()',1000);
85  }
86  clock();
87  </script>";
88  }
89 
90  /**
91  * @brief Draw the clock on screen
92  * @brief This method draws the clock on screen
93  */
94  public function drawClock()
95  {
96  echo"
97  <div class=\"$this->clockAlign\">
98  <div id=\"clockDiv\" class=\"$this->clockClass\" style=\"color:#$this->clockColor\"></div>
99  </div>";
100  }
101  }
102 }
Embed a digital real-time clock on your website.
Definition: clock.php:17
drawClock()
Draw the clock on screen.
Definition: clock.php:93
printObject()
Print all object data.
Definition: clock.php:46
init()
Initialize: prepare JS and start the clock.
Definition: clock.php:57
__construct($db)
Load all widget settings from database and fill object.
Definition: clock.php:32
loadJavascript()
Load required javascript.
Definition: clock.php:67
Widgets are small, useful tools that you can include everywhere in your website.
Definition: widget.php:22
getWidgetSettingsArray($db)
Get widget settings and return it as array.
Definition: widget.php:69
if(isset($_POST['save'])) $settings
$value