-
Notifications
You must be signed in to change notification settings - Fork 1
/
lexicon.php
116 lines (97 loc) · 5.37 KB
/
lexicon.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
<!DOCTYPE html>
<html lang="en">
<?php include 'include/variables.php'; ?>
<?php include 'include/head.php'; ?>
<?php include 'include/functions.php'; ?>
<body style='tab-interval:2pt'>
<?php
$arrlength = count($lettersLexicon);
if(isset($_GET["letter"])){
$letter = ltrim($_GET["letter"],'0');
}
?>
<?php
$navPage = $lexicon;
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
$x;
$y;
// set to A if no letter chosen
if(!isset($letter) || $letter == 0){
$letter = 1;
}
// get all the letters in the alphabet for the side menu
for($x = 1; $x < $arrlength; $x++) {
echo "<li";
if($lettersLexicon[$letter-1] == $lettersLexicon[$x-1]){
// active
$y = $x;
echo $active;
}
echo "><a href=\"lexicon.php?letter=".$x."\">".$lettersLexicon[$x-1]."</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 Letter</button>
</p>
<div class="container-fluid">
<!--dictionary entry paragraphs-->
<?php
// get text for relevant letter
$filename = "lexicon/";
if($y < 10){ $filename .= "0"; }
$filename .= $y.".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="09.htm#e1668"
// to
// href="lexicon.php?letter=1#e25"
$regex1 = "/([0-9]+)\.htm(#e[0-9]+)/";
$newText1 = preg_replace($regex1,"lexicon.php?letter=$1$2",$newAudioText);
// add extra span to push text down so that selected word is immediately visible
$regex2 = "/<p class=\"lpLexEntryPara\">/";
$newText2 = preg_replace($regex2,"<p class=\"lpLexEntryPara\"><span class=\"lpLexEntryNameNew\"></span>",$newText1);
// make images responsive
// $regex3 = "/width=\"[0-9]+\" height=\"[0-9]+\"/";
// $newText3 = preg_replace($regex3,"class=\"img-responsive\"",$newText2);
$regex3 = "/<p class=\"lpPicturePara.*(pictures.*jpg).*p>/U";
$newText3 = preg_replace($regex3,"<p><img src=\"$1\" class=\"img-responsive\"/></p>",$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>
</div><!--/.container-->
<?php include 'include/script.php'; ?>
</body>
</html>