This repository was archived by the owner on Nov 12, 2020. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathhelpers.inc.php
More file actions
100 lines (75 loc) · 3.02 KB
/
Copy pathhelpers.inc.php
File metadata and controls
100 lines (75 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
function pluriel($variable) {
$count = (is_array($variable)) ? count($variable) : (int) $variable;
return ($count == 1) ? '' : 's';
}
function echo_form_toggle($task_id, $done, $id_prepend) {
echo '<form class="toggle" method="POST" action="toggle_task.php">';
echo '<input class="checkbox_toggle" type="checkbox" id="'.$id_prepend.$task_id.'"'. (($done) ? ' checked' : '') .'> ';
echo '<input type="hidden" name="task_id" value="'.$task_id.'">';
echo '</form>';
}
function echo_past_tasks($tasks) {
echo '<ul>';
foreach($tasks as $task) {
echo '<li>';
echo_form_toggle($task->id, false, 'undone_past_task_');
echo ' <label for="undone_past_task_'.$task->id.'">';
if($task->category) {
echo '<strong>'. $task->category .'</strong> ';
}
echo $task->title;
echo '</label>';
echo ' <span class="days_behind">'.$task->days_behind.' jour'. pluriel($task->days_behind) .' de retard</span>';
echo '<a class="edit" href="save_task.php?id='.$task->id.'">Éditer</a>';
echo '</li>';
}
echo '</ul>';
}
function echo_coming_tasks($tasks) {
echo '<ul>';
foreach($tasks as $task) {
echo '<li>';
echo_form_toggle($task->id, false, 'coming_task_');
echo ' <label for="coming_task_'.$task->id.'">';
if($task->category) {
echo '<strong>'. $task->category .'</strong> ';
}
echo $task->title;
echo '</label>';
if($task->days_left) {
echo ' <span class="days_left">dans '.$task->days_left.' jour'. pluriel($task->days_left) .'</span>';
}
echo '<a class="edit" href="save_task.php?id='.$task->id.'">Éditer</a>';
echo '</li>';
}
echo '</ul>';
}
function weekly_planner_echo_tasks($tasks) {
echo '<ul>';
foreach($tasks as $task) {
echo '<li>';
echo_form_toggle($task->id, $task->done, 'planner_task_');
echo '<label'. (($task->done) ? ' class="strike"' : '') .' for="planner_task_'.$task->id.'">'.$task->title.'</label>';
echo '<a class="edit" href="save_task.php?id='.$task->id.'">Éditer</a>';
echo '</li>';
}
echo '</ul>';
}
function get_qod() {
try {
$file = file('qod.txt');
if(date('Y-m-d') != trim($file[0])) {
throw new Exception('Quote from cache is not today quote. (please catch this Exception and update the cache)');
}
$qod = $file[1];
} catch(Exception $e) {
$api_url = 'http://quotes.rest/qod';
$json = file_get_contents($api_url);
$data = json_decode($json, true);
$qod = $data['contents']['quotes'][0]['quote'];
file_put_contents('qod.txt', date('Y-m-d'));
file_put_contents('qod.txt', "\r\n" . $qod, FILE_APPEND | LOCK_EX);
}
return $qod;
}