No need to declare superglobals global
[infodrom.org/www.zeitungsliste.de] / lib / ajax.inc
1 <?php
2
3 $functions = array('search_check' => array('lib' => 'search.inc',
4                                            'func' => 'ajax_search_check'),
5                    'passwd_check' => array('lib' => 'login.inc',
6                                            'func' => 'ajax_passwd_check'),
7                    'nickname_check' => array('lib' => 'login.inc',
8                                              'func' => 'ajax_nickname_check'),
9                    'tag_add' => array('lib' => 'tags.inc',
10                                       'func' => 'ajax_tag_add'),
11                    'tag_del' => array('lib' => 'tags.inc',
12                                       'func' => 'ajax_tag_del'),
13                    'tag_new' => array('lib' => 'tags.inc',
14                                       'func' => 'ajax_tag_new'),
15                    'tag_exists' => array('lib' => 'tags.inc',
16                                          'func' => 'ajax_tag_exists'),
17                    'bookmark_up' => array('lib' => 'bookmarks.inc',
18                                           'func' => 'ajax_bookmark_up'),
19                    'bookmark_down' => array('lib' => 'bookmarks.inc',
20                                             'func' => 'ajax_bookmark_down'),
21                    'bookmark_del' => array('lib' => 'bookmarks.inc',
22                                            'func' => 'ajax_bookmark_del'),
23                    'bookmark_add' => array('lib' => 'bookmarks.inc',
24                                            'func' => 'ajax_bookmark_add'),
25                    'check_url' => array('lib' => 'functions.inc',
26                                         'func' => 'ajax_check_url'),
27                    'check_email' => array('lib' => 'misc.inc',
28                                           'func' => 'ajax_check_email'),
29                    );
30
31 function dumpinfo()
32 {
33
34   $info = "\$_SERVER = " . var_export($_SERVER, true);
35   $info .= "\n\$_POST = " . var_export($_POST, true);
36   $info .= "\n\$_GET = " . var_export($_GET, true);
37
38   $f = fopen("/tmp/zlist.dump", "w");
39   fwrite($f, $info);
40   fclose($f);
41 }
42
43 function ajax_process()
44 {
45   global $functions;
46
47   dumpinfo();
48
49   if (strlen($_POST['function']) && array_key_exists($_POST['function'], $functions)) {
50       if (array_key_exists('lib', $functions[$_POST['function']]))
51         include_once($functions[$_POST['function']]['lib']);
52       if (array_key_exists('func', $functions[$_POST['function']])) {
53         if (function_exists($functions[$_POST['function']]['func']))
54           return $functions[$_POST['function']]['func']();
55         else
56           return false;
57       }
58   }
59
60   return false;
61 }