-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
208 lines (184 loc) · 5.47 KB
/
functions.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
$long_title_filename = 'long_title.txt';
$cats_filename = 'cats.txt';
$problem_filename = 'problem.txt';
$solution_filename = 'solution.txt';
$facets_filename = 'facets.txt';
$evidence_filename = 'evidence.txt';
$before_img_filename = 'zoom_before';
$after_img_filename = 'zoom_after';
$img_file_extensions = array('png','PNG','gif','GIF','jpg','JPG','jpeg','JPEG'); // allowed image file extensions
$cat_ids = array( "survey" => array("Surveys","surveys"),
"website" => array("Websites","websites"),
"confwebsite" => array("Conference Websites","conference websites"),
"opensource" => array("Open-Source Projects","open-source"));
$facet_ids = array( "m" => array("Motivations","motivations"),
"ls" => array("Learning Style","learning style"),
"atr" => array("Attitude Toward Risk","attitude toward risk"),
"cse" => array("Computer Self-Efficacy","computer self-efficacy"),
"ips" => array("Information Processing Style","information processing"));
$facets = array_keys($facet_ids);
function hasCat($dir, $cat) {
global $cats_filename;
$out = false;
$cats = '';
$cats_path = "{$dir}/{$cats_filename}";
if(file_exists($cats_path)) { $cats = file($cats_path, FILE_IGNORE_NEW_LINES); }
if(in_array($cat, $cats)) { $out = true; }
return $out;
}
function hasFacet($dir, $facet) {
$out = false;
$facets = getFacets($dir);
if(in_array($facet, $facets)) { $out = true; }
return $out;
}
function hasImg($dir, $img_filename) {
global $img_file_extensions;
$out = false;
foreach($img_file_extensions as $i) {
$img_path = "{$dir}/{$img_filename}.{$i}";
if(file_exists($img_path)) { $out = true; break; }
}
return $out;
}
function hasLongTitle($dir) {
global $long_title_filename;
$out = false;
$long_title_path = "{$dir}/{$long_title_filename}";
if(file_exists($long_title_path)) { $out = true; }
return $out;
}
function getProblem($dir) {
global $problem_filename;
$problem = '';
$problem_path = $dir.'/'.$problem_filename;
if(file_exists($problem_path)) { $problem = file_get_contents($problem_path); }
return $problem;
}
function getSolution($dir) {
global $solution_filename;
$solution = '';
$solution_path = $dir.'/'.$solution_filename;
if(file_exists($solution_path)) { $solution = file_get_contents($solution_path); }
return $solution;
}
function getFacets($dir) {
global $facets_filename;
$facets = '';
$facets_path = $dir.'/'.$facets_filename;
if(file_exists($facets_path)) { $facets = file($facets_path, FILE_IGNORE_NEW_LINES); }
return $facets;
}
function getCats($dir) {
global $cats_filename;
$cats = '';
$cats_path = $dir.'/'.$cats_filename;
if(file_exists($cats_path)) { $cats = file($cats_path, FILE_IGNORE_NEW_LINES); }
return $cats;
}
function getEvidence($dir) {
global $evidence_filename;
$evidence = '';
$evidence_path = $dir.'/'.$evidence_filename;
if(file_exists($evidence_path)) { $evidence = file_get_contents($evidence_path); }
return $evidence;
}
function getLongTitle($dir) {
global $long_title_filename;
$long_title = '';
$long_title_path = "{$dir}/{$long_title_filename}";
if(hasLongTitle($dir)) { $long_title = file_get_contents($long_title_path); }
return $long_title;
}
function dirNoSpaces($dir) {
return str_replace(' ', '', $dir);
}
// Return names of all directories in a given category
function getDirs($cat=NULL) {
global $facets;
$newDirs = array();
$dirs = array_filter(glob('*'), 'is_dir');
if($cat!=NULL) {
if(in_array($cat,$facets)) {
$newDirs = getFacetDirs($cat);
} else {
foreach($dirs as $dir) {
if(hasCat($dir, $cat)) {
array_push($newDirs,$dir);
}
}
}
} else { $newDirs = $dirs; }
return $newDirs;
}
function getFacetDirs($facet) {
$newDirs = array();
$dirs = array_filter(glob('*'), 'is_dir');
if($facet!=NULL) {
foreach($dirs as $dir) {
if(hasFacet($dir, $facet)) {
array_push($newDirs,$dir);
}
}
} else { $newDirs = $dirs; }
return $newDirs;
}
function getDesData($cat=NULL) {
$desData = array();
$dirs = getDirs($cat);
foreach($dirs as $dir) {
$long_title = getLongTitle($dir);
$problem = getProblem($dir);
$solution = getSolution($dir);
$facets = getFacets($dir);
$evidence = getEvidence($dir);
$cats = getCats($dir);
$data = [
"dir" => $dir,
"long_title" => $long_title,
"problem" => $problem,
"solution" => $solution,
"facets" => $facets,
"evidence" => $evidence,
"cats" => $cats
];
$desData[$dir] = $data;
}
return $desData;
}
function getLink($thisCat,$selectedCat) {
$catLink = '';
if($thisCat==$selectedCat) {
$catLink = '#';
} else if($thisCat=='confwebsite') {
$catLink = 'conference-checklist.php?confwebsite';
} else {
$catLink = "index.php?{$thisCat}";
}
return $catLink;
}
function getSectionName($sectionId) {
global $cat_ids,$facet_ids;
if (array_key_exists($sectionId,$cat_ids)) {
$array = $cat_ids;
} elseif (array_key_exists($sectionId,$facet_ids)) {
$array = $facet_ids;
}
return $array[$sectionId][1];
}
function getFormattedButtonLink($thisSection,$selectedSection) {
$buttonTitle = getSectionName($thisSection);
$buttonLink = getLink($thisSection,$selectedSection);
$buttonClass = '';
if($thisSection==$selectedSection) {
$buttonClass = 'selected';
}
return "<a href=\"{$buttonLink}\"><div><div class=\"{$buttonClass}\"> {$buttonTitle} </div></div></a>";
}
function getAllButtonClass($currentSection) {
$allButtonClass = '';
if (!$currentSection) $allButtonClass = 'selected';
return $allButtonClass;
}
?>