[r7011]: tags / phpGedView-4.2.4 / phpGedView / module.php Maximize Restore History

Download this file

module.php    290 lines (279 with data), 7.3 kB

  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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<?php
/**
* Module system for adding features to phpGedView.
*
* phpGedView: Genealogy Viewer
* Copyright (C) 2002 to 2011 PGV Development Team. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package PhpGedView
* @subpackage Display
* @version $Id: module.php 7011 2011-01-14 00:29:45Z yalnifj $
* @author Patrick Kellum
*/
define('PGV_SCRIPT_NAME', 'module.php');
require './config.php';
// Simple mod system, based on the older phpnuke/postnuke
define('PGV_MOD_SIMPLE', 1);
// More advanced OO module system
define('PGV_MOD_OO', 2);
// Module system version 2, enhanced security and better output control
define('PGV_MOD_V2', 3);
// Sanitize all input
$mod = safe_REQUEST($_REQUEST, 'mod', PGV_REGEX_MODNAME, '');
$name = safe_REQUEST($_REQUEST, 'name', PGV_REGEX_MODNAME, '');
$pgvaction = safe_REQUEST($_REQUEST, 'pgvaction', PGV_REGEX_MODNAME, '');
$class = safe_REQUEST($_REQUEST, 'class', PGV_REGEX_MODNAME, '');
$method = safe_REQUEST($_REQUEST, 'method', PGV_REGEX_MODNAME, '');
if (empty($mod)) unset($mod);
if (empty($name)) unset($name);
if (empty($pgvaction)) unset($pgvaction);
if (empty($class)) unset($class);
if (empty($method)) unset($method);
if(!isset($mod))
{
// PGV_MOD_NUKE
if (isset($name)) $mod = $name;
else $mod = 'index';
}
if (strpos($mod, '..')!==false || (isset($pgvaction) && strpos($pgvaction, '..')!==false)) {
header('Location: index.php');
print ' ';
exit;
}
if(file_exists('modules/'.$mod.'.php'))
{
$modinfo = parse_ini_file('modules/'.$mod.'.php', true);
}
// v2 modules
elseif(file_exists("modules/{$mod}/pgv_version.php"))
{
$modinfo = parse_ini_file("modules/{$mod}/pgv_version.php", true);
}
else
{
header('Location: index.php');
print ' ';
exit;
}
switch($modinfo['Module']['type'])
{
case PGV_MOD_SIMPLE:
{
if (!isset ($pgvaction))
{
$pgvaction = 'index';
}
if (!file_exists(PGV_ROOT.'modules/'.$mod.'/'.$pgvaction.'.php'))
{
$pgvaction = 'index';
}
require_once PGV_ROOT.'modules/'.$mod.'/'.$pgvaction.'.php';
break;
}
case PGV_MOD_OO:
{
if (!isset ($method))
{
$method = 'main';
}
if (!isset ($class))
{
$class = $mod;
}
require_once PGV_ROOT.'modules/'.$mod.'/'.$class.'.php';
$mod = new $class();
if (!method_exists($mod, $method))
{
$method = 'main';
}
$out = $mod->$method();
if (is_string($out))
{
print $out;
}
break;
}
case PGV_MOD_V2:
{
/*
* Module Security
* 1. Test if module is active.
* 2. Only Admins can view an inactive module.
*/
if((!isset($modinfo['Config']['active']) || $modinfo['Config']['active'] === false) && !PGV_USER_IS_ADMIN)
{
header("Location: {$SERVER_URL}index.php");print ' ';exit;
}
/*
* Class Security
* 1. Remove any directories that might have been passed.
* 2. Test if class file actually exists.
* 3. Ignore any filename that starts with an underscore.
*/
if(isset($class)){$class = basename($class, '.php');}
if(
!isset($class) ||
!file_exists("modules/{$mod}/{$class}.php") ||
$class[0] == '_'
){$class = $mod;}
/*
* Load Language
* 1. Load english language if exists.
* 2. Load current language if exists.
*/
if (file_exists(PGV_ROOT.'modules/'.$mod.'/languages/lang.en.php')) {
require_once PGV_ROOT.'modules/'.$mod.'/languages/lang.en.php';
}
if (file_exists(PGV_ROOT.'modules/'.$mod.'/languages/extra.en.php')) {
require_once PGV_ROOT.'modules/'.$mod.'/languages/extra.en.php';
}
if ($LANGUAGE != 'en') {
if (file_exists(PGV_ROOT.'/modules/'.$mod.'/languages/lang.'.$LANGUAGE.'.php')) {
require_once PGV_ROOT.'modules/'.$mod.'/languages/lang.'.$LANGUAGE.'.php';
}
if (file_exists(PGV_ROOT.'/modules/'.$mod.'/languages/extra.'.$LANGUAGE.'.php')) {
require_once PGV_ROOT.'modules/'.$mod.'/languages/extra.'.$LANGUAGE.'.php';
}
}
/*
* Load & Initialize
* 1. Load the class file.
* 2. Create a module object.
* 3. Initialize the module if needed.
*/
require_once PGV_ROOT.'modules/'.$mod.'/'.$class.'.php';
$mod = new $class();
if(method_exists($mod, 'init')){$mod->init();}
/*
* Method Security
* 1. Test if method actually exists in this object.
* 2. Ignore any method that starts with an underscore.
*/
if(
!isset($method) ||
!method_exists($mod, $method) ||
$method[0] == '_'
){$method = 'main';}
/*
* Execute Method
* 1. Execute the requested method.
* 2. Act upon the result of the method call.
*/
$results = $mod->$method();
switch($results[0])
{
/*
* Action: Display Raw Output
* 'content': Raw content to display on the page.
*/
case 'display':
{
print $results['content'];
break;
}
/*
* Action: Wrap Output In Header & Footer
* 'title' Title of the page. [optional]
* 'head' Additional header content. [optional]
* 'content' Content to display on the page.
*/
case 'wrap':
{
if(!isset($results['title']))
{
if(isset($modinfo['Config']['title'])){$results['title'] = $modinfo['Config']['title'];}
else{$results['title'] = get_gedcom_setting(PGV_GED_ID, 'title');}
}
if(!isset($results['head'])){$results['head'] = '';}
print_header($results['title'], $results['head']);
print $results['content'];
print_footer();
break;
}
/*
* Action: Redirect Browser
* 'url' URL to redirect the browser to.
*/
case 'redirect':
{
// fully qualified url is recomended.
if(!isFileExternal($results['url'])){$results['url'] = "{$SERVER_URL}{$results['url']}";}
header("Location: ".encode_url($results['url'], false));
print ' '; // for some older browsers.
exit;
}
/*
* Action: Exit
*/
case 'exit':
{
exit;
}
/*
* Action: Error
*/
default:
{
print_header($results['title'], $results['head']);
print str_replace('[action]', $results['action'], $pgv_lang['module_error_unknown_action_v2']);
print_footer();
exit;
}
}
break;
}
default:
{
print_header(get_gedcom_setting(PGV_GED_ID, 'title'));
print $pgv_lang['module_error_unknown_type'];
print_footer();
break;
}
}
function mod_print_header($title, $head='', $use_alternate_styles=true)
{
ob_start();
print_header($title, $head, $use_alternate_styles);
$out = ob_get_contents();
ob_end_clean();
return $out;
}
function mod_print_simple_header($title)
{
ob_start();
print_simple_header($title);
$out = ob_get_contents();
ob_end_clean();
return $out;
}
function mod_print_footer()
{
ob_start();
print_footer();
$out = ob_get_contents();
ob_end_clean();
return $out;
}
function mod_print_simple_footer()
{
ob_start();
print_simple_footer();
$out = ob_get_contents();
ob_end_clean();
return $out;
}
?>