OSDN Git Service

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@881 1ca29b6e-896d...
[nucleus-jp/nucleus-plugins.git] / NP_UpdatePingServer / trunk / updatepingserver / admin / PlugManagement.php
1 <?php
2
3 class PlugManagement
4 {
5         /* PluginAdmin
6          * @var object
7          */
8         var $p_admin;
9         
10         /* Plugin
11          * @var object
12          */
13         var $plugin;
14
15         /* PlugView
16          * @var object
17          */
18         var $view;
19
20         /**
21          * Constructor
22          *  - create admin, plugin, view object.
23          *
24          * Extended classes don't call this automatically
25          *    if those have Constructor
26          *
27          * @param string $plugin_name : Name of Plugin
28          * @return void
29          */
30         function PlugManagement($plugin_name)
31         {
32                 $this->p_admin = new PluginAdmin($plugin_name);
33                 $this->plugin =& $this->p_admin->plugin;
34                 $this->view = new PlugAdminView($this);
35         }
36
37         /**
38          * returns reference of plugin object
39          * @return object
40          */
41         function &getPlugin()
42         {
43                 return $this->plugin;
44         }
45
46         /**
47          * returns reference of view object
48          * @return object
49          */
50         function &getView()
51         {
52                 return $this->view;
53         }
54
55         /**
56          * returns reference of PluginAdmin object
57          * @return object
58          */
59         function &getPluginAdmin()
60         {
61                 return $this->p_admin;
62         }
63
64         /**
65          * Function for not making action files
66          */
67         function doAction($action)
68         {
69                 if (method_exists($this, 'action_'.$action)) {
70                         call_user_func(array(&$this, 'action_'.$action));
71                 } else {
72                         $this->action_overview();
73                 }
74         }
75
76         /***************************************************
77           init, dir/file/class settings (abstract)
78         ****************************************************/
79         function init() {}
80         
81         // directory of action files (abs path)
82         function getActionDir()
83         {
84                 return $this->plugin->getDirectory() . 'actions/';
85         }
86         
87         // directory of template files (abs path)
88         function getTemplateDir()
89         {
90                 return $this->plugin->getDirectory() . 'templates/';
91         }
92         
93         // prefix of action file name
94         //    default action file name is (action).php
95         function getActionFilePrefix() { return '';}
96         
97         // prefix of action class name
98         function getActionClassPrefix()
99         {
100                 return str_replace('np_', '', strtolower(get_class($this->plugin))) . '_';
101         }
102         
103         // default action
104         function getDefaultAction() { return 'overview';}
105
106
107         /**********************************************
108           auth, error and exception
109         **********************************************/
110         /**
111          * display error page with "disallowed" message.
112          */
113         function disallow()
114         {
115                 $this->error(_ERROR_DISALLOWED);
116         }
117
118         /**
119          * display error page. 
120          * @pamam string $msg : message to show
121          */
122         function error($msg)
123         {
124                 $this->p_admin->start();
125
126                 $dir=$this->plugin->getAdminURL();
127                 ?>
128                 <h2>Error!</h2>
129                 <?php           echo htmlspecialchars($msg);
130                 echo "<br />";
131                 echo "<a href='".$dir."index.php' onclick='history.back()'>"._BACK."</a>";
132                 
133                 $this->p_admin->end();
134                 exit;
135         }
136
137
138         /**
139          * authenticate the member
140          * @pamam string $level : permitted authority level
141          * @param number $extra : blogid (This is necessary excluding "Admin". )
142          */
143         function memberAuth($level = 'Admin', $extra = '')
144         {
145                 global $member;
146
147                 switch (strtolower($level)) {
148                 case 'admin':
149                         $member->isAdmin() or $this->disallow();
150                         break;
151                 case 'blogadmin':
152                         if (!$extra) {
153                                 $this->error('Missing 2nd argument ('.__LINE__.')');
154                         }
155                         $member->isBlogAdmin($extra) or $this->disallow();
156                         break;
157                 case 'teammember':
158                         if (!$extra) {
159                                 $this->error('Missing 2nd argument ('.__LINE__.')');
160                         }
161                         $member->isTeamMember($extra) or $this->disallow();
162                         break;
163                 }
164         }
165
166
167         /**********************************************
168           helper functions
169         **********************************************/
170         /**
171          * return popup help link
172          * @pamam string $url : url of popup help file
173          * @param string $anchor
174          */
175         function createPopupHelpLink($url, $anchor)
176         {
177                 $link = '<a href="'.$url.'#'. $anchor . '" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); return help(this.href);">' . '<img src="documentation/icon-help.gif" width="15" height="15" alt="'._HELP_TT.'" /></a>';
178                 return $link;
179         }
180
181
182 }
183
184 class PlugAdminView extends PlugView
185 {
186         var $p_manager;
187
188         function PlugAdminView(&$p_manager)
189         {
190                 $this->p_manager =& $p_manager;
191         }
192         
193         function display($tpl)
194         {
195                 $p_admin =& $this->p_manager->getPluginAdmin();
196                 
197                 $p_admin->start();
198
199                 $file = $this->p_manager->getTemplateDir() . $tpl;
200                 parent::display($file);
201
202                 $p_admin->end();
203         }
204
205 }
206
207
208 ?>