forked from X-Genesis-Qhulut/alpha
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwow_alpha_books.php
217 lines (172 loc) · 4.8 KB
/
wow_alpha_books.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
209
210
211
212
213
214
215
216
217
<?php
/*
Author: X'Genesis Qhulut <[email protected]>
Date: August 2022
See LICENSE for license details.
*/
// BOOKS (page_text)
function simulateBookPage ($row, $page = 0)
{
echo "<p><div class='simulate_box page_text'>\n";
if ($page)
boxTitle ("Page $page");
echo "<p>";
echo nl2br_http (fixQuestText ($row ['text']));
endDiv ('simulate_box page_text');
}
function showTextDetails ()
{
global $id, $item, $items;
$page = 0;
// to avoid loops
$shown = array ();
// boxTitle ($items [$item]);
// for each page ...
while ($id)
{
$row = dbQueryOneParam ("SELECT * FROM ".PAGE_TEXT." WHERE entry = ?", array ('i', &$id));
if (!$row)
break;
$page++;
simulateBookPage ($row, $page);
$shown [$id] = true;
$id = $row ['next_page'];
// avoid endless loops
if (array_key_exists ($id, $shown))
break;
} // end of while each page
} // end of showTextDetails
function showText ()
{
global $id, $item, $items;
$name = $items [$item];
pageContent (false, 'Page', $name , 'books', function ($info)
{
middleSection (false, function ($info)
{
showTextDetails ();
});
}
, PAGE_TEXT);
} // end of showText
function bookTopLeft ($row)
{
global $id, $item, $items;
showOneThing (PAGE_TEXT, 'entry', $id, "", "", array (),
array ('entry', 'next_page'));
} // end of bookTopLeft
function bookTopMiddle ($row)
{
global $id, $item, $items;
boxTitle ('In-game view');
simulateBookPage ($row);
} // end of bookTopMiddle
function bookRelatedItem ($row)
{
global $id, $item, $items;
$page_text = PAGE_TEXT;
$item_template = ITEM_TEMPLATE;
// find the page chains
$pages = array ();
$results = dbQuery ("SELECT entry, next_page FROM $page_text");
while ($chainRow = dbFetch ($results))
$pages [$chainRow ['next_page']] = $chainRow ['entry'];
dbFree ($results);
// now we can work back until we find the start of the chain
$doneThis = array ();
do
{
if (!array_key_exists ($id, $pages))
break; // no previous, this must be the start of the chain
$prevPage = $pages [$id];
if (array_key_exists ($id, $doneThis))
break; // doing the same one again, give up
$doneThis [$id] = true;
$id = $prevPage;
} while ($prevPage);
$results = dbQueryParam (
"SELECT T2.entry AS item_key
FROM $page_text AS T1
INNER JOIN $item_template AS T2
ON (T1.entry = T2.page_text)
WHERE T1.entry = ?",
array ('i', &$id));
if (count ($results) > 0)
{
listItems ('Items containing this page', ITEM_TEMPLATE, count ($results), $results,
function ($row) use ($items)
{
listThing ($items, $row ['item_key'], 'show_item');
},
true);
}
else
{
boxTitle ('Items containing this page');
echo "<ul><li>No items containing this page could be found.</ul>";
}
} // end of bookRelatedItem
function bookDetails ($row)
{
global $id;
topSection ($row, function ($row) use ($id)
{
topLeft ($row, 'bookTopLeft');
topMiddle ($row, 'bookTopMiddle');
});
middleSection ($row, function ($row) use ($id)
{
middleDetails ($row, 'bookRelatedItem');
});
bottomSection ($row, function ($row) use ($id)
{
showOneThing (PAGE_TEXT, 'entry', $id, "Database entry for page", "", array ());
});
} // end of bookDetails
function showOneBook ()
{
global $id;
if (($id === false && !repositionSearch()) || !checkID ())
return;
// we need the item info in this function
$row = dbQueryOneParam ("SELECT * FROM ".PAGE_TEXT." WHERE entry = ?", array ('i', &$id));
if (!$row)
{
ShowWarning ("Page $id is not on the database");
return;
}
setTitle ("Book page (entry) $id");
pageContent ($row, 'Page', "Page (entry) $id", 'books', 'bookDetails', PAGE_TEXT);
} // end of showOneBook
function showBooks ()
{
global $where, $params, $maps, $sort_order, $matches;
$sortFields = array (
'entry',
'text',
'next_page',
);
setTitle ('Books listing');
if (!in_array ($sort_order, $sortFields))
$sort_order = 'entry';
$td = function ($s) use (&$row) { tdx ($row [$s]); };
$headings = array ('Entry', 'Text', 'Next Page');
$results = setUpSearch ('Pages', $headings, $sortFields);
if (!$results)
return;
$searchURI = makeSearchURI (true);
$pos = 0;
foreach ($results as $row)
{
$pos++;
echo "<tr>\n";
$id = $row ['entry'];
tdh ("<a href='?action=show_book&id=$id$searchURI&pos=$pos&max=$matches'>$id</a>");
echo "<td>" . nl2br_http (fixQuestText ($row ['text'])) . "</td>\n";
$td ('next_page');
showFilterColumn ($row);
echo "</tr>\n";
}
wrapUpSearch ();
} // end of showBooks
?>