OSDN Git Service

NP_DragAndDropUploader v1.1
[nucleus-jp/nucleus-plugins.git] / trunk / NP_AuthSister / NP_AuthSister.php
1 <?php\r
2 // vim: tabstop=2:shiftwidth=2
3 \r
4 /**\r
5   * NP_AuthSister ($Revision$)\r
6   * by hsur ( http://blog.cles.jp/np_cles )\r
7   * $Id$\r
8   *\r
9 */\r
10 \r
11 /*\r
12   * Copyright (C) 2008 CLES. All rights reserved.\r
13   *\r
14   * This program is free software; you can redistribute it and/or\r
15   * modify it under the terms of the GNU General Public License\r
16   * as published by the Free Software Foundation; either version 2\r
17   * of the License, or (at your option) any later version.\r
18   * \r
19   * This program is distributed in the hope that it will be useful,\r
20   * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
22   * GNU General Public License for more details.\r
23   * \r
24   * You should have received a copy of the GNU General Public License\r
25   * along with this program; if not, write to the Free Software\r
26   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA\r
27   * \r
28   * In addition, as a special exception, cles( http://blog.cles.jp/np_cles ) gives\r
29   * permission to link the code of this program with those files in the PEAR\r
30   * library that are licensed under the PHP License (or with modified versions\r
31   * of those files that use the same license as those files), and distribute\r
32   * linked combinations including the two. You must obey the GNU General Public\r
33   * License in all respects for all of the code used other than those files in\r
34   * the PEAR library that are licensed under the PHP License. If you modify\r
35   * this file, you may extend this exception to your version of the file,\r
36   * but you are not obligated to do so. If you do not wish to do so, delete\r
37   * this exception statement from your version.\r
38 */\r
39 \r
40 //Font Settings\r
41 define('_AuthSister_font', dirname(__FILE__).'/sharedlibs/auth_sister/ipagp.ttf');\r
42 require_once(dirname(__FILE__).'/sharedlibs/sharedlibs.php');\r
43 require_once('auth_sister/core.php');
44 global $authSister;
45 $authSister = new AuthSister();
46 $authSister->session_start();\r
47 \r
48 class NP_AuthSister extends NucleusPlugin {\r
49 \r
50         function getName() {\r
51                 return 'AuthSister';\r
52         }\r
53         function getAuthor() {\r
54                 return 'hsur';\r
55         }\r
56         function getURL() {\r
57                 return 'http://blog.cles.jp/np_cles/category/31/subcatid/23';\r
58         }\r
59         function getVersion() {\r
60                 return '1.0.0';\r
61         }\r
62         function getMinNucleusVersion() {\r
63                 return 330;\r
64         }\r
65         function getMinNucleusPatchLevel() {\r
66                 return 0;\r
67         }\r
68         function getEventList() {\r
69                 return array ('FormExtra', 'ValidateForm', 'InitSkinParse');\r
70         }\r
71         function getDescription() {\r
72                 return _AuthSister_DESC;\r
73         }\r
74         function supportsFeature($what) {\r
75                 switch ($what) {\r
76                         case 'SqlTablePrefix':\r
77                                 return 1;\r
78                         default:\r
79                                 return 0;\r
80                 }\r
81         }\r
82         function hasAdminArea() {\r
83                 return 1;\r
84         }\r
85         \r
86         function install() {\r
87                 $this->createOption('load', 'load', 'text', 'reiya');\r
88         }\r
89         \r
90         function init() {\r
91                 // include language file for this plugin \r
92                 $language = ereg_replace( '[\\|/]', '', getLanguageName()); \r
93                 if (file_exists($this->getDirectory().'language/'.$language.'.php')) \r
94                         @include_once($this->getDirectory().'language/'.$language.'.php');\r
95                                         \r
96                 global $authSister, $CONF;\r
97                 \r
98                 $authSister->load = $this->getOption('load');\r
99                 $authSister->mes_a = _AuthSister_mes_a;\r
100                 $authSister->mes_b = _AuthSister_mes_b;\r
101                 $authSister->method = _AuthSister_method;\r
102                 $authSister->len_min = _AuthSister_len_min;\r
103                 $authSister->len_max = _AuthSister_len_max;\r
104                 $authSister->outlen = _AuthSister_outlen;\r
105                 $authSister->font = _AuthSister_font;\r
106                 $authSister->basedir = $this->getAdminURL().'../sharedlibs/auth_sister';\r
107                 $authSister->imageurl = $CONF['ActionURL'] . '?action=plugin&name=AuthSister&type=img';
108         }\r
109 \r
110         function _info($msg) {\r
111                 if ($this->getOption('debug') == 'yes') {\r
112                         ACTIONLOG :: add(INFO, 'AuthSister: '.$msg);\r
113                 }\r
114         }\r
115 \r
116         function _warn($msg) {\r
117                 ACTIONLOG :: add(WARNING, 'AuthSister: '.$msg);\r
118         }\r
119         \r
120         function event_InitSkinParse(&$data){
121         }
122         
123         function doSkinVar($skinType, $type = '') {
124                 global $authSister;
125                 switch ($type) {
126                         case '':
127                         case 'header':
128                                 $authSister->header();
129                                 break;
130                         default:
131                                 return 'Unexisting type: ' . $type;
132                 }
133         }
134         
135         function doAction($type){
136                 global $CONF,$manager;
137                 global $authSister;
138                 $aActionsNotToCheck = array(
139                         '',
140                         'img',
141                 );
142                 if (!in_array($type, $aActionsNotToCheck)) {
143                         if (!$manager->checkTicket()) return _ERROR_BADTICKET;
144                 }
145
146                 switch ($type) {
147                         // When no action type is given, assume it's a ping
148                         case '':
149                         case 'img':
150                                 $authSister->show_image('img','png');
151                                 exit;
152                                 break;
153                 }
154         }
155                 \r
156         function event_FormExtra(&$data) {\r
157                 global $manager, $member;\r
158                 global $authSister;
159                 if ($member->isLoggedIn())\r
160                         return;\r
161                 \r
162                 switch ($data['type']) {\r
163                         case 'commentform-notloggedin' :\r
164                         case 'membermailform-notloggedin': \r
165                                 break;\r
166                         default :\r
167                                 return;\r
168                 }\r
169                 \r
170                 $externalauth = array ( 'source' => $this->getName() );\r
171                 $manager->notify('ExternalAuth', array ('externalauth' => &$externalauth));\r
172                 if (isset($externalauth['result']) && $externalauth['result'] == true) return;\r
173                         \r
174                 switch ($data['type']) {\r
175                         case 'membermailform-notloggedin' :\r
176                         case 'commentform-notloggedin' :
177                                 echo $authSister->load();\r
178                                 echo $authSister->insert();                                                     \r
179                                 break;\r
180                 }\r
181         }\r
182 \r
183         function event_ValidateForm(&$data) {\r
184                 global $manager, $member;\r
185                 global $authSister;
186                 if ($member->isLoggedIn())\r
187                         return;\r
188                 \r
189                 $externalauth = array ( 'source' => $this->getName() );\r
190                 $manager->notify('ExternalAuth', array ('externalauth' => &$externalauth));\r
191                 if (isset($externalauth['result']) && $externalauth['result'] == true) return;\r
192                 \r
193                 if ($authSister->auth()) {\r
194                         //echo $authSister->res();\r
195                         session_destroy();
196                 } else {\r
197                         $data['error'] = $authSister->res();\r
198                 }\r
199         }\r
200 }