OSDN Git Service

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@882 1ca29b6e-896d...
[nucleus-jp/nucleus-plugins.git] / NP_UpdatePingServer / trunk / updatepingserver / admin / PlugController.php
1 <?php
2
3 class PlugController
4 {
5         var $admin;
6         
7         function PlugController($plugin_name)
8         {
9                 $adminclass = $plugin_name . '_Management';
10                 $this->admin = new $adminclass($plugin_name);
11                 $this->admin->init();
12                 
13                 if (!$this->admin->getActionDir()) {
14                         $this->admin->error('Action Directory not found.');
15                 }
16         }
17
18         
19         function &getAdmin()
20         {
21                 return $this->admin;
22         }
23
24         
25         function forward($action, $msg = '')
26         {
27                 
28                 $dir = $this->admin->getActionDir();
29                 $fprefix = $this->admin->getActionFilePrefix();
30                 $cprefix = $this->admin->getActionClassPrefix();
31                 $default = $this->admin->getDefaultAction();
32                 
33                 $action = preg_replace("/[^a-z_]+/", "", $action);
34                 $action_file = $dir . $fprefix . $action . ".php";
35                 
36                 if ($action && is_readable($action_file)) {
37                         require_once($action_file);
38                         
39                 } elseif ($default) {
40                         $action_file = $dir . $fprefix . $default . ".php";
41                         if (is_readable($action_file)) {
42                                 $action = $default;
43                                 require_once($action_file);
44                         }
45                 }
46
47                 if (!$action) {
48                         $this->admin->disallow();
49                 }
50
51                 $class = $cprefix . $action;
52                 
53                 if (class_exists($class)) {
54                         $obj = new $class();
55                         
56                         if (method_exists($obj, "execute")) {
57                                 $obj->execute(&$this, $msg);
58                                 
59                         } else {
60                                 $this->admin->error('Method not found.');
61                         }
62                         
63                 } else {
64                         $this->admin->error('Class not found.');
65                         
66                 }
67                 
68         }
69
70
71         function existsAction($action_name)
72         {
73                 $class = $this->admin->getActionClassPrefix() . $action_name;
74                 
75                 if (!class_exists($class)) {
76                         $dir = $this->admin->getActionDir();
77                         $fprefix = $this->admin->getActionFilePrefix();
78                         $action_file = $dir . $fprefix . $action_name . '.php';
79                         if (is_readable($action_file)) {
80                                 require_once($action_file);
81                         }
82                 }
83
84                 return (class_exists($class)) ? true : false;
85         }
86         
87 }
88
89
90 ?>