-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcategories.php
107 lines (90 loc) · 5.13 KB
/
categories.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
<!DOCTYPE html>
<html lang="en">
<!-- This file presents the category data, with main categories listed to the left of in the page sidebar.-->
<?php include 'include/variables.php'; ?>
<?php include 'include/head.php'; ?>
<?php include 'include/functions.php'; ?>
<body style='tab-interval:2pt'>
<?php
if(isset($_GET["category"])){
$originalCategory = $_GET["category"];
$category = $_GET["category"];
}
$navPage=$categories;
include("include/nav.php");
?>
<div class="container-fluid">
<div class="row row-offcanvas row-offcanvas-left">
<div class="col-sm-3 col-md-2 sidebar-offcanvas" id="sidebar" role="navigation">
<ul class="nav nav-sidebar">
<?php
reset($categoryNames);
$keys = array_keys($categoryNames);
$values = array_values($categoryNames);
// set to 1st category if none chosen
if(!isset($category) || $category == 0){
$category = $keys[0];
}
for ($i = 0; $i < sizeof($categoryNames); $i++) {
echo "<li";
if($category >= $keys[$i] && $category < $keys[$i + 1]){
echo $active;
}
echo "><a href=\"categories.php?category=".$keys[$i]."\">".$values[$i]."</a></li>";
}
?>
</ul>
</div><!--/col-sm-3 col-md-2 sidebar-offcanvas-->
<div class="col-sm-9 col-md-10 main">
<!--toggle sidebar button-->
<p class="visible-xs">
<button type="button" class="btn btn-primary btn-xs" data-toggle="offcanvas"><b><</b> Select Category</button>
</p>
<div>
<?php
// get text for relevant category
$filename = "categories/c";
$filename .= $category.".htm";
$text = convert_to(file_get_contents($filename), "UTF-8");
$regex0 = "/\.\.\//";
$newText0 = preg_replace($regex0,"",$text);
$regexAudio = "/\<a href\=\"audio\/([\s\S]*)\.mp3[\s\S]*\>/U";
$replaceAudio = "<audio preload=\"none\" id=\"$1\" src=\"audio/$1.mp3\"></audio><a href=\"#\" onclick=\"document.getElementById('$1').play(); return false\">";
$newAudioText = preg_replace($regexAudio,$replaceAudio,$newText0);
// transform links to type from
// href="c001.htm"
// to
// href="categories.php?category=001"
$regex1 = "/c([0-9]+)\.htm/";
$newText1 = preg_replace($regex1,"categories.php?category=$1",$newAudioText);
// href="../lexicon/22.htm#e3129"
$regex2 = "/lexicon\/([0-9]+)\.htm(#e[0-9]+)/";
$newText2 = preg_replace($regex2,"lexicon.php?letter=$1$2",$newText1);
// make images responsive
$regex3 = "/width=\"[0-9]+\" height=\"[0-9]+\"/";
$newText3 = preg_replace($regex3,"class=\"img-responsive\"",$newText2);
// use this section to get valid HTML, but may be slower
// $domdocument = new DomDocument("1.0", "utf-8");
// $domdocument->preserveWhiteSpace = false;
// $domdocument->loadXML($newText2);
// $body = $domdocument->getElementsByTagName('html')
// ->item(0)
// ->getElementsByTagName('body')
// ->item(0);
// if($body->hasChildNodes()){
// $children = $body->childNodes;
// foreach($children as $child) {
// $entry = $domdocument->saveHTML($child);
// $paragraphText = convert_to($entry, "UTF-8");
// echo $paragraphText;
// }
// }
echo $newText3;
?>
</div>
</div><!--/col-sm-9 col-md-10 main-->
</div><!--/row row-offcanvas row-offcanvas-left-->
</div><!--/container-fluid-->
<?php include 'include/script.php'; ?>
</body>
</html>