forked from corneyflorex/TaskBoard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
157 lines (122 loc) · 4.98 KB
/
index.php
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
// Settings
$config_str = <<<SETTINGS
[homepage]
tasks_to_show = 10
[tasks]
lifespan = 1
[database]
dsn = sqlite:tasks.sq3
username =
password =
SETTINGS;
/*
Main app below here.. don't go changing anything!
*/
require("Database.php");
require("Taskboard.php");
require("anonregkit.php");
$config = parse_ini_string($config_str, true);
Database::openDatabase('rw', $config['database']['dsn'], $config['database']['username'], $config['database']['password']);
// Decide what we're trying to do
$uri = isset($_GET['q']) ? $_GET['q'] : '/';
$uri_parts = explode('/', trim($uri, '/'));
// Since pretty muche very part of the site relies on the board, create it now
$board = new Taskboard();
$board->task_lifespan = $config['tasks']['lifespan'];
// Do stuff based on on the URI sent
// FORMAT: index.php?q=/['CASE NAME']
switch($uri_parts[0]){
case 'init':
// Insert test data if requested..
// activate by typing ?q=/init
$board->initDatabase();
$board->createTask('23r34r', 'My first', 'This could be my second.. but blahh', array('first', 'misc'));
$board->createTask('23r34r', 'Poster needed', 'I kinda need a poster making, gotta be x y z', array('graphics', 'first'));
$board->createTask('23r34r', 'Make me music!', 'Please.. I need music', array('music', 'misc'));
$board->createTask('23r34r', 'something', 'something something something something something', array('misc'));
$board->createTask('23r34r', 'website time', 'Website called google.com, itl be a search engine', array('graphics', 'technical'));
echo "Inserted test data\n";
break;
case 'tasks':
// for when ?q=/tasks/[sub_act]
$sub_act = isset($uri_parts[1]) ? $uri_parts[1] : '';
if($sub_act){
switch($uri_parts[1]){
case 'new': // show a form to submit a new task
//mode (what to display in layout.php)
$mode = array('submitForm');
break;
case 'submitnew':
//Only pass though message and title if it is set already
if(!isset($_POST['title'], $_POST['message']) || empty($_POST['title']) || empty($_POST['message'])){
echo "Missing title and/or message \n";
break;
}
//Extract tag to array
$s_tag = isset($_POST['tags']) ? explode(' ', $_POST['tags']) : array();
//Insert password
if( ( isset($_POST['password']) AND $_POST['password']!='' ) OR __getKeyFile()!=''){
$s_pass=__tripCode($_POST['password'].__getKeyFile());
}else{// If user give blank password, generate a new one for them
$newpass = md5(mt_rand());
$s_pass=__tripCode($newpass);
echo "<div style='background-color:white;color:black;'>Your new password is: '<bold>".$newpass."</bold>' keep it safe! </div>
<div style='float:left;padding:10px;background-color:#".substr(md5($s_pass),0,6)."'>".$s_pass."</div>";
}
$board->createTask($s_pass, $_POST['title'], $_POST['message'], $s_tag);
echo "Post submitted!\n";
break;
case 'search':
// If we're posting a search, redirect to the URL search (helps copy/pasting URLs)
if(isset($_POST['tags'])){
$tags = explode(' ', $_POST['tags']);
header('Location: ?q=/tasks/search/'.implode(',', $tags));
echo 'tags'.implode(',', $tags);
exit;
}
if(isset($uri_parts[2])){
$tags = explode(',', $uri_parts[2]);
$mode = array('tasksList');
} else {
$mode = array('tagSearch');
}
if(!empty($tags)){
$tasks = $board->getTasks($tags);
} else {
$tasks = array();
}
break;
case 'delete':
$s_array[0]=$_POST['taskID'];
$s_array[1]=__tripCode($_POST['password'].__getKeyFile());
//print_r($s_array);
$command = 'Delete single task with normal password';
$board->delTaskBy($command,$s_array);
break;
}// //end of: switch($uri_parts[1]){
}// //end of: if($sub_act){
break;// //End of: case 'tasks':
case 'view':
// Browsing/searching the tasks
$mode = array('tasksView'); //mode (what to display in layout.php)
$tasks = $board->getTaskByID($uri_parts[1]); //Retrieve a task entry by id
break;
default:
case 'tags':
// Browsing/searching the tasks
$mode = array('tasksList'); //mode (what to display in layout.php)
if(isset($uri_parts[1])){ //Standard search via "/tags/NAMEOFTAG"
$tags = explode(',', $uri_parts[1]);
}else if(isset($_POST['tags'])){ //OVERRIDE IF SEARCHING FOR TAGS VIA $_POST
$tags = explode(' ', $_POST['tags']);
}else{ //If we are simply in the front page.
$tags = array();
}
$tasks = $board->getTasks($tags);
break;
}
//Display Layout
if(!isset($mode)) $mode = array(); //set default mode (should be error page perhaps)
$top_tags = $board->topTags(10);
require("layout.php");