public
Description: Tracks and maps the diffusion of email forwards, political calls-to-action, and online petitions. It can trace email forwards, map the impact of blogs, and facilitate web-based sign-ups and social networking
Homepage: http://forwardtrack.eyebeamresearch.org
Clone URL: git://github.com/jamiew/forwardtrack.git
forwardtrack / dispatch.php
100644 143 lines (110 sloc) 5.692 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
<?php
 
    require_once(dirname(__FILE__).'/config.inc.php');
    require_once(dirname(__FILE__).'/lib/FT/App.class.php');
    require_once(dirname(__FILE__).'/lib/FT/App/SiteApp.class.php');
    require_once(dirname(__FILE__).'/lib/FT/App/CampaignApp.class.php');
    require_once(dirname(__FILE__).'/lib/FT/App/AdminApp.class.php');
 
    $app_args = array('doc_root' => dirname(__FILE__),
                      'template_dir' => dirname(__FILE__) . '/style/templates',
                      'www_host' => $_SERVER['HTTP_HOST'],
                      'www_root' => "http://{$_SERVER['HTTP_HOST']}" . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/'),
                      /*
'www_root' => ($_SERVER['REQUEST_URI'] == $_SERVER['REDIRECT_URL'])
? "http://{$_SERVER['HTTP_HOST']}" . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/')
: $_SERVER['SCRIPT_NAME'],
*/
                      'path_info' => rtrim($_SERVER['PATH_INFO'], '/'),
                      'cache_dir' => dirname(__FILE__) . 'cache' // This was causing an array index warning
                      );
 
    function remaining(&$path)
    { return array_splice($path, (key($path) + 1)); }
    
    $path = explode('/', trim($_SERVER['PATH_INFO'], '/'));
    
    switch($base = reset($path)) {
    
        case 'admin':
            $app = FT_APP_ADMIN_APP_CLASS; $app = new $app($app_args);
 
            switch($action = next($path)) {
 
                case 'view':
                case 'stats':
                case 'map-data':
                    if($campaign = next($path)) {
                        $app->run(array('action' => $action, 'campaign' => $campaign, 'path' => remaining($path)));
                    } else {
                        end($path);
                        $app->run(array('action' => $action, 'campaign' => null, 'path' => remaining($path)));
                    }
                    break;
                    
                case 'dump':
                case 'edit':
                case 'delete':
                    if($campaign = next($path)) {
                        $app->run(array('action' => $action, 'campaign' => $campaign, 'path' => remaining($path)));
                    } else {
                        $app->throw_error("missing campaign");
                    }
                    break;
                                
                case 'install':
                case 'docs':
                case 'purge':
                case 'new':
                    $app->run(array('action' => $action, 'campaign' => null, 'path' => remaining($path)));
                    break;
                    
                case false:
                    $app->run();
                    break;
 
                default:
                    prev($path);
                    $app->run(array('action' => null, 'campaign' => null, 'path' => remaining($path)));
                    break;
 
            }
 
            break;
            
        case 'campaigns':
 
            if($campaign = next($path)) {
 
                $app = FT_APP_CAMPAIGN_APP_CLASS; $app = new $app($app_args);
 
                switch($action = next($path)) {
                    case 'preview':
                        $app->run(array('action' => $action, 'node' => null, 'campaign' => $campaign, 'path' => remaining($path)));
                        break;
 
                    case 'register':
                    case 'map':
                    case 'map-data':
                        if($node = next($path)) {
                            $app->run(array('action' => $action, 'node' => $node, 'campaign' => $campaign, 'path' => remaining($path)));
                        } else {
                            end($path);
                            $app->run(array('action' => $action, 'node' => null, 'campaign' => $campaign, 'path' => remaining($path)));
                        }
                        break;
                        
                    case 'impact':
                    case 'browse':
                    case 'invite':
                    case 'accept':
                        if($node = next($path)) {
                            $app->run(array('action' => $action, 'node' => $node, 'campaign' => $campaign, 'path' => remaining($path)));
                        } else {
                            $app->throw_error("missing node");
                        }
                        break;
                        
                    case false:
                        $app->run(array('action' => null, 'node' => null, 'campaign' => $campaign, 'path' => remaining($path)));
                        break;
 
                    default:
                        prev($path);
                        $app->run(array('action' => null, 'node' => null, 'campaign' => $campaign, 'path' => remaining($path)));
                        break;
 
                }
                
            } else {
 
                $app = FT_APP_SITE_APP_CLASS; $app = new $app($app_args);
 
                $app->run(array('action' => 'campaigns'));
                break;
            
            }
 
            break;
 
        case false:
            $app = FT_APP_CAMPAIGN_APP_CLASS; $app = new $app($app_args);
 
            $app->run(array('action' => null, 'node' => null, 'campaign' => null, 'path' => remaining($path)));
            break;
 
        default:
            $app = FT_APP_SITE_APP_CLASS; $app = new $app($app_args);
 
            $app->run(array('action' => $base, 'path' => remaining($path)));
            break;
    }
    
?>