forked from ivanlanin/kateglo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.php
249 lines (223 loc) · 7.88 KB
/
common.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php
/**
* Library of common functions
*/
define(PROCESS_NONE, 0); // mark no process
define(PROCESS_SUCCEED, 1); // mark process succeed
define(PROCESS_FAILED, 2); // mark process failed
/**
* Redirect to a certain URL page
*
* @param $url
*/
function redir($url)
{
header('Location:' . $url);
}
function login($username = null, $status = null, &$auth = null)
{
global $msg, $auth, $is_post;
$welcome = $auth->checkAuth() ? 'login_success' : 'login_welcome';
$welcome = $msg[$welcome];
if ($is_post && !$auth->checkAuth()) $welcome = $msg['login_failed'] . ' ' . $welcome;
$ret .= '<h1>' . $msg['login'] . '</h1>' . LF;
if (!$auth->checkAuth()) $ret .= sprintf('<p>%1$s</p>' . LF, $msg['login_beta']);
$ret .= sprintf('<p>%1$s</p>' . LF, $welcome);
if (!$auth->checkAuth())
{
$form = new form('login_form', null, './?mod=user&action=login');
$form->setup($msg);
$form->addElement('text', 'username', $msg['username']);
$form->addElement('password', 'password', $msg['password']);
$form->addElement('submit', null, $msg['login']);
$form->addRule('username', sprintf($msg['required_alert'], $msg['username']), 'required', null, 'client');
$form->addRule('password', sprintf($msg['required_alert'], $msg['password']), 'required', null, 'client');
$ret .= $form->toHtml();
}
return($ret);
}
/**
* @return Search form HTML
*/
function show_header_old()
{
global $msg, $auth, $db;
global $_GET;
$form = new form('search_form', 'get');
$form->setup($msg);
$form->addElement('text', 'phrase', $msg['enter_phrase'],
array('size' => 15, 'maxlength' => 255));
$form->addElement('select', 'mod', null, array(
'dictionary' => $msg['dictionary'],
'glossary' => $msg['glossary'],
'proverb' => $msg['proverb'],
));
$form->addElement('submit', 'search', $msg['search_button']);
$ret .= $form->begin_form();
$ret .= '<table cellpadding="0" cellspacing="0" width="100%"><tr>' . LF;
// logo
$ret .= '<td width="1%">' . LF;
$ret .= '<a href="./"><img src="images/logo.png" width="32" height="32" border="0" alt="Kateglo" title="Kateglo" /></a>' . LF;
$ret .= '</td>' . LF;
// search form
$template = '<td style="padding-right:2px;">%1$s</td>' . LF;
$ret .= '<td><table cellpadding="0" cellspacing="0"><tr>' . LF;
$ret .= sprintf($template, $form->get_element('search'));
$ret .= sprintf($template, $form->get_element('phrase'));
$ret .= sprintf($template, $msg['search_in']);
$ret .= sprintf($template, $form->get_element('mod'));
$ret .= '</tr></table></td>' . LF;
// navigation
$ret .= '<td align="right">' . LF;
if ($auth->checkAuth())
{
$ret .= sprintf('<strong>%3$s</strong> | <a href="%5$s">%4$s</a> | <a href="%2$s">%1$s</a>' . LF,
$msg['logout'], './?mod=user&action=logout',
$auth->getUsername(),
$msg['change_pwd'], './?mod=user&action=password'
);
}
else
$ret .= sprintf('<a href="%2$s">%1$s</a>' . LF, $msg['login'], './?mod=user&action=login');
$ret .= '</td>' . LF;
$ret .= '</tr></table>' . LF;
$ret .= $form->end_form();
return($ret);
}
/**
* @return Search form HTML
*/
function show_header()
{
global $msg, $auth, $db;
global $_GET;
$mods = array(
'dictionary' => $msg['dictionary'],
'glossary' => $msg['glossary'],
'proverb' => $msg['proverb'],
'abbr' => $msg['abbr'],
);
$navMenu .= sprintf('<a href="./">%1$s</a>', $msg['home']);
foreach ($mods as $key => $mod)
{
$navMenu .=' ';
$navMenu .= sprintf('<a href="./?mod=%1$s">%2$s</a>', $key, $mod);
}
$form = new form('search_form', 'get');
$form->setup($msg);
$form->addElement('text', 'phrase', $msg['enter_phrase'],
array('size' => 20, 'maxlength' => 255));
$form->addElement('select', 'mod', null, $mods);
$form->addElement('submit', 'search', $msg['search_button']);
$ret .= $form->begin_form();
// logo
$ret .= '<div id="header">' . LF;
$ret .= '<table cellpadding="0" cellspacing="0" width="100%"><tr>' . LF;
$ret .= '<td width="1%">' . LF;
$ret .= '<a href="./"><img src="images/kateglo40.png" width="129" height="40" border="0" alt="Kateglo" title="Kateglo" /></a>' . LF;
$ret .= '</td>' . LF;
// search form
$template = '<td style="padding-left:5px;">%1$s</td>' . LF;
$ret .= '<td align="right"><table cellpadding="0" cellspacing="0"><tr>' . LF;
$ret .= sprintf($template, $form->get_element('phrase'));
$ret .= sprintf($template, $msg['search_in']);
$ret .= sprintf($template, $form->get_element('mod'));
$ret .= sprintf($template, $form->get_element('search'));
$ret .= '</tr></table></td>' . LF;
$ret .= '</tr></table>' . LF;
$ret .= '</div>' . LF;
// navigation
$ret .= '<div id="navbar">' . LF;
$ret .= '<table cellpadding="0" cellspacing="0" width="100%"><tr>' . LF;
$ret .= '<td>' . LF;
$ret .= $navMenu;
$ret .= '</td>' . LF;
$ret .= '<td align="right">' . LF;
if ($auth->checkAuth())
{
$ret .= sprintf('%3$s <a href="%5$s">%4$s</a> <a href="%2$s">%1$s</a>' . LF,
$msg['logout'], './?mod=user&action=logout',
$auth->getUsername(),
$msg['change_pwd'], './?mod=user&action=password'
);
}
else
$ret .= sprintf('<a href="%2$s">%1$s</a>' . LF, $msg['login'], './?mod=user&action=login');
$ret .= '</td>' . LF;
$ret .= '</tr></table>' . LF;
$ret .= '</div>' . LF;
$ret .= $form->end_form();
return($ret);
}
/**
* Footer
*/
function show_footer_old()
{
global $msg;
$ret .= sprintf('<div class="container">' .
'<span style="float:right;">' .
'<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/">' .
'<img title="%6$s" alt="%6$s" style="border-width:0" ' .
'src="./images/cc-by-nc-sa.png" />' .
'</a></span>' .
'<a href="%2$s">%3$s</a>' .
' · ' .
'<a href="%7$s">API</a>' .
' · ' .
'<a href="%4$s">%5$s</a>' .
'</div>' . LF,
APP_SHORT,
'./?mod=doc&doc=README.txt',
APP_VERSION,
'./?mod=comment',
$msg['comment_link'],
'CC-BY-NC-SA',
'./api.php'
);
return($ret);
}
/**
* Footer
*/
function show_footer()
{
global $msg;
$ret .= '<div class="footer container">' . LF;
$ret .= sprintf('<p>' .
'<span style="float:right;">' .
'<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/">' .
'<img title="%6$s" alt="%6$s" style="border-width:0" ' .
'src="./images/cc-by-nc-sa.png" />' .
'</a></span>' .
'<a href="%2$s">%3$s</a>' .
' ' .
'<a href="%7$s">API</a>' .
' ' .
'<a href="%4$s">%5$s</a>' .
'</p>' . LF,
APP_SHORT,
'./?mod=doc&doc=README.txt',
APP_VERSION,
'http://bahtera.org/blog/kateglo/',
$msg['comment_link'],
'CC-BY-NC-SA',
'./api.php'
);
$ret .= '</div>' . LF;
return($ret);
}
/**
* External stat
*/
function get_external_stat()
{
// gostats
$ret .= '<!-- GoStats JavaScript Based Code -->';
$ret .= '<script type="text/javascript" src="http://gostats.com/js/counter.js"></script>';
$ret .= '<script type="text/javascript">_gos=\'gostats.com\';_goa=728945;_got=5;_goi=1;_goz=0;_gol=\'web traffic software\';_GoStatsRun();</script>';
$ret .= '<noscript><a target="_blank" title="web traffic software" href="http://gostats.com"><img alt="web traffic software" src="http://gostats.com/bin/count/a_728945/t_5/i_1/counter.png" style="border-width:0" /></a></noscript>';
$ret .= '<!-- End GoStats JavaScript Based Code -->' . LF;
return($ret);
}
?>