OSDN Git Service

NP_DragAndDropUploader v1.1
[nucleus-jp/nucleus-plugins.git] / trunk / NP_OpenId / NP_OpenId.php
1 <?php
2 // vim: tabstop=2:shiftwidth=2
3
4 /**
5   * NP_OpenId ($Revision: 1.3 $)
6   * by hsur ( http://blog.cles.jp/np_cles )
7   * $Id: NP_OpenId.php,v 1.3 2008-06-10 14:35:12 hsur Exp $
8   *
9 */
10
11 /*
12   * Copyright (C) 2008 CLES. All rights reserved.
13   *
14   * This program is free software; you can redistribute it and/or
15   * modify it under the terms of the GNU General Public License
16   * as published by the Free Software Foundation; either version 2
17   * of the License, or (at your option) any later version.
18   * 
19   * This program is distributed in the hope that it will be useful,
20   * but WITHOUT ANY WARRANTY; without even the implied warranty of
21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22   * GNU General Public License for more details.
23   * 
24   * You should have received a copy of the GNU General Public License
25   * along with this program; if not, write to the Free Software
26   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
27   * 
28   * In addition, as a special exception, cles( http://blog.cles.jp/np_cles ) gives
29   * permission to link the code of this program with those files in the PEAR
30   * library that are licensed under the PHP License (or with modified versions
31   * of those files that use the same license as those files), and distribute
32   * linked combinations including the two. You must obey the GNU General Public
33   * License in all respects for all of the code used other than those files in
34   * the PEAR library that are licensed under the PHP License. If you modify
35   * this file, you may extend this exception to your version of the file,
36   * but you are not obligated to do so. If you do not wish to do so, delete
37   * this exception statement from your version.
38 */
39
40 // ParanoidHTTPFetcher bug?
41 define('Auth_Yadis_CURL_OVERRIDE', '1');
42
43 // constants
44 define('NP_OPENID_COOKIE', 'EXTAUTH');
45
46 // libs
47 require(dirname(__FILE__).'/sharedlibs/sharedlibs.php');
48 require_once 'cles/Template.php';
49 require_once 'Auth/OpenID/Consumer.php';
50 require_once 'cles/SQLStoreForNucleus.php';
51 require_once 'Auth/OpenID/SReg.php';
52 require_once 'Auth/OpenID/PAPE.php';
53 require_once 'Jsphon.php';
54
55 class NP_OpenId extends NucleusPlugin {
56
57         function getName() {
58                 return 'OpenId';
59         }
60         function getAuthor() {
61                 return 'hsur';
62         }
63         function getURL() {
64                 return 'http://blog.cles.jp/np_cles/category/31/subcatid/21';
65         }
66         function getVersion() {
67                 return '1.1.1';
68         }
69         function getMinNucleusVersion() {
70                 return 330;
71         }
72         function getMinNucleusPatchLevel() {
73                 return 0;
74         }
75         function getEventList() {
76                 return array ('FormExtra', 'ValidateForm', 'PreAddComment', 'PostAddComment', 'PostDeleteComment', 'ExternalAuth', 'Logout', 'LoginSuccess');
77         }
78         function getTableList() {
79                 return array(
80                         sql_table('plugin_openid'),
81                         sql_table('plugin_openid_comment'),
82                         sql_table('plugin_openid_profile'),
83                         sql_table('plugin_openid_assc'),
84                         sql_table('plugin_openid_nonce')
85                 );
86         }
87         function getDescription() {
88                 return '[$Revision: 1.3 $]<br />Adds OpenID authentication to anonymous comment, to prevent robots from spamming.';
89         }
90         function supportsFeature($what) {
91                 switch ($what) {
92                         case 'SqlTablePrefix':
93                                 return 1;
94                         default:
95                                 return 0;
96                 }
97         }
98         function hasAdminArea() {
99                 return 1;
100         }
101         
102         function init() {
103
104 /* 
105                 // For DEBUG
106                 require_once 'Auth/OpenID/FileStore.php';
107                 $store_path = "/tmp/_php_consumer_test";
108                 @mkdir($store_path);
109                 $this->store = new Auth_OpenID_FileStore($store_path);
110 */
111                 // include language file for this plugin 
112                 $language = ereg_replace( '[\\|/]', '', getLanguageName()); 
113                 if (file_exists($this->getDirectory().'language/'.$language.'.php')) 
114                         @ include_once($this->getDirectory().'language/'.$language.'.php');
115                 else
116                         @ include_once($this->getDirectory().'language/english.php');
117
118                 $this->store = new cles_SQLStoreForNucleus();
119                 $this->consumer = new Auth_OpenID_Consumer($this->store);
120                 $this->loggedinUser = null;
121                 $this->comments = array();
122         }
123
124         function install() {
125                 $this->store->createTables();
126                 
127                 sql_query(
128                           'CREATE TABLE IF NOT EXISTS ' . sql_table('plugin_openid') 
129                         . ' ('
130                         . '  cookie varchar(40) NOT NULL default \'\','
131                         . '  identity varchar(255) NOT NULL,'
132                         . '  sreg text NOT NULL default \'\','
133                         . '  ts datetime NOT NULL default \'0000-00-00 00:00:00\','
134                         . '  PRIMARY KEY (cookie)'
135                         . ' );'
136         );
137                 sql_query(
138                           'CREATE TABLE IF NOT EXISTS ' . sql_table('plugin_openid_profile') 
139                         . ' ('
140                         . '  identity varchar(255) NOT NULL,'
141                         . '  nick varchar(255) NOT NULL unique default \'\','
142                         . '  email varchar(255) ,'
143                         . '  sreg text NOT NULL default \'\','
144                         . '  ts datetime NOT NULL default \'0000-00-00 00:00:00\','
145                         . '  PRIMARY KEY (identity)'
146                         . ' );'
147         );
148                 sql_query(
149                           'CREATE TABLE IF NOT EXISTS ' . sql_table('plugin_openid_comment') 
150                         . ' ('
151                         . '  cnumber int(11) NOT NULL,'
152                         . '  citem int(11) NOT NULL,'
153                         . '  identity varchar(255) NOT NULL default \'\','
154                         . '  ts datetime NOT NULL default \'0000-00-00 00:00:00\','
155                         . '  PRIMARY KEY(cnumber), '
156                         . '  INDEX(citem) '
157                         . ' );'
158         );
159                 
160                 global $CONF;
161                 $this->createOption('permitComment', 'Permit comments w/o login?', 'yesno', 'yes', '');
162                 $this->createOption('permitMail', 'Permit mail w/o login?', 'yesno', 'yes', '');
163                 
164                 $this->createOption('CommentFormError', 'Error message (comment)', 'text', 'To submit comment, you need to sign-in to OpenID.', '');
165                 $this->createOption('MemberMailError', 'Error message  (mail form)', 'text', 'To send email, you need to sign-in to OpenID.', '');
166                 
167                 $this->createOption('dropdb', 'Erase  on uninstall?', 'yesno', 'no', '');
168                 $this->createOption('debug', 'Debug mode ?', 'yesno', 'no');
169                 
170                 $this->createOption('enableLinkedWith', 'Enable local account linked with OpenID account ? ', 'yesno', 'no');
171                 $this->createMemberOption('linkedWith', 'Linked with following account', 'text', '');
172         }
173
174         function unInstall() {
175                 sql_query('DROP TABLE '.sql_table('plugin_openid_assc'));
176                 sql_query('DROP TABLE '.sql_table('plugin_openid_nonce'));
177                 
178                 if ($this->getOption('dropdb') == 'yes'){
179                         sql_query('DROP TABLE '.sql_table('plugin_openid'));
180                         sql_query('DROP TABLE '.sql_table('plugin_openid_profile'));
181                         sql_query('DROP TABLE '.sql_table('plugin_openid_comment'));
182                 }
183         }
184         function doAction($type) {
185                 switch ($type) {
186                         case 'verify' :
187                                 if( $this->login() ){
188                                         $this->_info('Authentication success: identity=' . $this->loggedinUser['identity']);
189                                         $url = preg_replace('/action=logout&?/','', requestVar('return_url'));
190                                         $this->_doLoginLocal($this->loggedinUser['identity']);
191                                         $this->_redirect( $url );
192                                 } else {
193                                         $this->_info('Authentication failure');
194                                         return 'Authentication failure';
195                                 }
196                                 break;
197                                 
198                         case 'doauth' :
199                                 return $this->doAuth( requestVar('openid_identifier'), requestVar('return_url') );
200                                 break;
201                                 
202                         case 'rd' :
203                                 $this->logout();
204                                 $this->_redirect( requestVar('url') );
205                                 break;
206                         
207                         case 'updateProfile':
208                                 $aVars = array();
209                                 if( $this->isLoggedin() ){
210                                         $profile = array();
211                                         $aVars['nick'] = requestVar('nick');
212                                         $aVars['email'] = requestVar('email');
213                                         
214                                         $this->_doUpdateProfile($aVars);
215                                         
216                                         $aVars['message'] = NP_OPENID_updateSucceeded;
217                                         $aVars['result'] = 'succeeded';
218                                 } else {
219                                         $aVars['message'] = NP_OPENID_notloggedin;
220                                         $aVars['result'] = 'failure';
221                                 }
222                                 
223                                 // return JSON
224                                 if(_CHARSET != 'UTF-8') mb_convert_variables('UTF-8', _CHARSET, $aVars);
225                                 echo Jsphon::encode($aVars);
226                                 exit;
227                                 //break;
228                         default:
229                                 return 'Unknown action: '.$type;
230                 }
231                 return '';
232         }
233         
234         function doAuth($identifier, $returnUrl){
235                 global $CONF;
236                 if( !$identifier ) return 'Missing OpenID identifier.';
237
238                 $auth_request = $this->consumer->begin($identifier);
239                 if (!$auth_request) {
240                         $this->reason = $auth_request;
241                         return "OpenID identifier is invalid.";
242                 }
243                 $sreg_request = Auth_OpenID_SRegRequest::build(
244                         // Required
245                         array('nickname'),
246                         // Optional
247                         array('fullname', 'email')
248                 );
249                 $auth_request->addExtension($sreg_request);
250                 
251                 $returnTo = $CONF['PluginURL'].'openid/rd.php?action=verify&return_url='.urlencode($returnUrl);                 
252                 $trustRoot = $CONF['IndexURL'];
253                 
254                 if ($auth_request->shouldSendRedirect()) {
255                         $redirect_url = $auth_request->redirectURL($trustRoot, $returnTo);
256
257                         if (Auth_OpenID::isFailure($redirect_url)) {
258                                 return "Could not redirect to server: " . $redirect_url->message;
259                         } else {
260                                 header("Location: ". $redirect_url);
261                                 $this->redirectTo = $redirect_url;
262                         }
263                 } else {
264                         $form_id = 'openid_message';
265                         $form_html = $auth_request->formMarkup($trustRoot, $returnTo,
266                         false, array('id' => $form_id));
267
268                         if (Auth_OpenID::isFailure($form_html)) {
269                                 return "Could not redirect to server: " . $form_html->message;
270                         } else {
271                                 $page_contents = array(
272                                 "<html><head><title>",
273                                 "OpenID transaction in progress",
274                                 "</title></head>",
275                                 "<body onload='document.getElementById(\"".$form_id."\").submit()'>",
276                                 $form_html,
277                                 "</body></html>");
278                                 print implode("\n", $page_contents);
279                                 exit;
280                         }
281                 }
282         }
283         
284         function _doUpdateProfile($profile){
285                 $query = sprintf('REPLACE INTO ' . sql_table('plugin_openid_profile') 
286                                 . ' ( identity, nick, email, ts ) '
287                                 . " values('%s', '%s', '%s', now())",
288                                  mysql_real_escape_string( $this->loggedinUser['identity']  ),
289                                  mysql_real_escape_string( $profile['nick']  ),
290                                  mysql_real_escape_string( $profile['email'] )
291                 );
292                 sql_query($query);
293
294                 $this->loggedinUser['nick'] = $profile['nick'];
295                 $this->loggedinUser['email'] = $profile['email'];
296         }
297         
298         function _doLoginLocal($name){
299                 if( $this->getOption('enableLinkedWith') != 'yes' ) return false;
300                 
301                 $linkedWith = $this->getAllMemberOptions('linkedWith');
302                 ksort($linkedWith, SORT_NUMERIC);
303                 
304                 $localId = -1;
305                 foreach( $linkedWith as $id => $accountList ){
306                         $accounts = explode(",", $accountList);
307                         $accounts = array_map("trim", $accounts);
308                         
309                         foreach( $accounts as $account ){
310                                 if( $account == '*' || $account == $name ){
311                                         $localId = $id;
312                                         break 2;
313                                 }
314                         }
315                 }
316                 if( $localId == -1 ) return false;
317                 
318                 global $manager, $CONF, $member;
319                 $member =& MEMBER::createFromID($localId);
320                 $member->loggedin = 1;
321                 
322                 $member->newCookieKey();
323                 $member->setCookies(0);
324                 if ( isset($CONF['secureCookieKey']) ) {
325                         $member->setCookieKey(md5($member->getCookieKey().$CONF['secureCookieKeyIP']));
326                         $member->write();
327                 }
328                 $manager->notify('LoginSuccess', array('member' => &$member) );
329                 
330                 $this->_info('Login local account :' . $member->getDisplayName() );
331                 ACTIONLOG::add(INFO, 'Login successful for '.$member->getDisplayName().' (sharedpc=0, OpenId)');
332                 return true;
333         }
334         
335         function _info($msg) {
336                 if ($this->getOption('debug') == 'yes') {
337                         ACTIONLOG :: add(INFO, 'OpenId: '.$msg);
338                 }
339         }
340
341         function _warn($msg) {
342                 ACTIONLOG :: add(WARNING, 'OpenId: '.$msg);
343         }
344
345         function _redirect($url){
346                 header('Location: '.$url);
347         }
348         
349         function _generateKey(){
350                 mt_srand( (double) microtime() * 1000000);
351                 return md5(uniqid(mt_rand()));
352         }
353         
354         function isLoggedin(){
355                 global $CONF;
356                 if( $this->loggedinUser['identity'] ) return true;
357                 
358                 $cookie = cookieVar($CONF['CookiePrefix'] . NP_OPENID_AUTH_COOKIE);
359                 if( ! $cookie ) return false;
360                 
361                 $query = sprintf('SELECT a.cookie as cookie, a.identity as identity, a.sreg as sreg, a.ts as ts, p.nick as nick, p.email as email FROM ' . sql_table('plugin_openid') . ' a '
362                                 . ' LEFT OUTER JOIN ' . sql_table('plugin_openid_profile') . ' p ON a.identity = p.identity '
363                                 . " where a.cookie = '%s' and a.ts > date_sub( now(), interval 1 day)"
364                                 , mysql_real_escape_string( trim($cookie) )
365                 );
366                 $res = sql_query($query);
367                 if( @mysql_num_rows($res) > 0) {
368                         $this->loggedinUser = mysql_fetch_assoc($res);
369                         $this->loggedinUser = array_merge($this->loggedinUser, unserialize($this->loggedinUser['sreg']));
370                         return true;
371                 }
372                 return false;
373         }
374         
375         function login(){
376                 global $CONF;
377                 //$return_url = $CONF['PluginURL'].'openid/rd.php?action=verify&return_url='.urlencode(requestVar('return_url'));
378                 $return_url = $CONF['PluginURL'].'openid/rd.php';
379                 $response = $this->consumer->complete( $return_url );
380                 if ($response->status == Auth_OpenID_CANCEL) {
381                         $this->message = 'Verification cancelled.';
382                         return false;
383                 } else if ($response->status == Auth_OpenID_FAILURE) {
384                         $this->message = "OpenID authentication failed: " . $response->message;
385                         $this->reason = $response;
386                         return false;
387                 } else if ($response->status != Auth_OpenID_SUCCESS) {
388                         $this->message = 'Unknown status: ' . $response->status;
389                         return false;
390                 }
391                 
392                 // Auth_OpenID_SUCCESS
393                 
394                 $identity = $response->getDisplayIdentifier();
395                 $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
396                 $sreg = $sreg_resp->contents(); // assoc
397                         
398                 $ts = time();
399                 $cookie = $this->_generateKey();
400                 $query = sprintf('REPLACE INTO ' . sql_table('plugin_openid') 
401                                 . ' ( cookie, identity, sreg, ts ) '
402                                 . " values('%s', '%s', '%s', '%s')",
403                                  mysql_real_escape_string( $cookie ),
404                                  mysql_real_escape_string( $identity ),
405                                  mysql_real_escape_string( serialize($sreg) ),
406                                  mysql_real_escape_string( date("Y/m/d H:i:s", $ts ) )
407                 );
408                 sql_query($query);
409                 
410                 $query = sprintf('SELECT a.cookie as cookie, a.identity as identity, a.sreg as sreg, a.ts as ts, p.nick as nick, p.email as email  FROM ' . sql_table('plugin_openid') . ' a '
411                                 . ' LEFT OUTER JOIN ' . sql_table('plugin_openid_profile') . ' p ON a.identity = p.identity '
412                                 . " where a.cookie = '%s' and a.ts > date_sub( now(), interval 1 day)"
413                                 , mysql_real_escape_string( trim($cookie) )
414                 );
415                 $res = sql_query($query);               
416                 
417                 if( @mysql_num_rows($res) > 0) {
418                         $this->loggedinUser = mysql_fetch_assoc($res);
419                         $this->loggedinUser = array_merge($this->loggedinUser, unserialize($this->loggedinUser['sreg']));
420                         
421                         setcookie($CONF['CookiePrefix'] . NP_OPENID_AUTH_COOKIE , $cookie, 0, $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']);
422                         return true;
423                 }
424                 
425                 return false;
426         }
427                 
428         function logout(){
429                 global $CONF;
430                 $this->loggedinUser = null;
431                 setcookie($CONF['CookiePrefix'] . NP_OPENID_AUTH_COOKIE, '', 0, $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']);
432                 return true;
433         }
434         
435         function event_ExternalAuth(&$data){
436                 if( $data['externalauth']['source'] == $this->getName() ) return;
437         if( isset($data['externalauth']['result']) && $data['externalauth']['result'] == true ){
438             return;
439         }
440                 
441                 if( $this->isLoggedin() ){
442                         $data['externalauth']['result'] = true;
443                         $data['externalauth']['plugin'] = $this->getName();
444                 }
445         }
446
447         function doSkinVar($skinType, $type = "") {
448                 global $CONF, $manager, $member;
449                 if($skinType != 'item') return;
450                 if( $member->isLoggedIn() ) return;
451                 
452                 $externalauth = array ( 'source' => $this->getName() );
453                 $manager->notify('ExternalAuth', array ('externalauth' => &$externalauth));
454                 if (isset($externalauth['result']) && $externalauth['result'] == true) return;
455                 
456                 $te = $this->_getTemplateEngine();
457                 $aVars = array();
458                 $aVars['PluginURL'] = $CONF['PluginURL'];
459                 
460                 $te = $this->_getTemplateEngine();              
461                 if( $this->isLoggedin() ){
462                         // Loggedin
463                         $return_url = $CONF['PluginURL'] . 'openid/rd.php?action=rd&url='
464                                                 . urlencode( 'http://'.serverVar("HTTP_HOST") .serverVar("REQUEST_URI") );                      
465                         $aVars['url'] = $return_url;
466                         $aVars['nick'] = $this->loggedinUser['nick'];
467                         $aVars['email'] = $this->loggedinUser['email'];
468                         $aVars['ts'] = $this->loggedinUser['ts'];
469                         $aVars['identity'] = $this->loggedinUser['identity'];
470                         $aVars['visible'] = $aVars['nick'] ? 'false' : 'true' ;
471                         
472                         $actionUrl = parse_url($CONF['ActionURL']);
473                         $aVars['updateUrl'] = $actionUrl['path'];
474                         
475                         echo $te->fetchAndFill('yui', $aVars, strtolower(__CLASS__));
476                         echo $te->fetchAndFill('loggedin', $aVars, strtolower(__CLASS__));
477                         echo $te->fetchAndFill('form', $aVars, strtolower(__CLASS__));
478                 } else {
479                         // Not loggedin
480                         $aVars['url'] = $CONF['PluginURL'] . 'openid/rd.php?action=doauth&return_url='
481                                                 . urlencode( 'http://'.serverVar("HTTP_HOST") .serverVar("REQUEST_URI") );      
482
483                         echo $te->fetchAndFill('notloggedin', $aVars, strtolower(__CLASS__));
484                 }               
485         }
486         
487         function event_FormExtra(&$data) {
488                 global $CONF, $manager, $member;
489                 if( $member->isLoggedIn() ) return;
490                 
491                 switch ($data['type']) {
492                         case 'commentform-notloggedin' :
493                         case 'membermailform-notloggedin': 
494                         case 'item': 
495                                 break;
496                         default :
497                                 return;
498                 }
499                 
500                 $externalauth = array ( 'source' => $this->getName() );
501                 $manager->notify('ExternalAuth', array ('externalauth' => &$externalauth));
502                 if (isset($externalauth['result']) && $externalauth['result'] == true) return;
503
504                 $this->isLoggedin();
505         }
506
507         function event_ValidateForm(&$data) {
508                 global $manager, $member;
509                 if( $member->isLoggedIn() ) return;
510                 
511                 $externalauth = array ( 'source' => $this->getName() );
512                 $manager->notify('ExternalAuth', array ('externalauth' => &$externalauth));
513                 if (isset($externalauth['result']) && $externalauth['result'] == true) return;
514                 
515                 switch ($data['type']) {
516                         case 'comment' :
517                                 if( (! $this->isLoggedin() ) && $this->getOption('permitComment') == 'no' )
518                                         $data['error'] = $this->getOption('CommentFormError');
519                                 break;
520                         case 'membermail' :
521                                 if( (! $this->isLoggedin() ) && $this->getOption('permitMail') == 'no' )
522                                         $data['error'] = $this->getOption('MemberMailError');
523                                 break;
524                         default :
525                                 return;
526                 }
527         }
528         
529         function event_PreAddComment(&$data) {
530                 global $member;
531                 if( $member->isLoggedIn() ) return;
532                 
533                 if( ! $this->isLoggedin() ) return;
534                 $data['comment']['user'] = $this->loggedinUser['nick'].' [OpenID]';
535         }
536         
537         function event_PostAddComment(&$data) {
538                 global $member;
539                 if( $member->isLoggedIn() ) return;
540                 
541                 if( ! $this->isLoggedin() ) return;
542                 global $itemid;
543                 $query = sprintf('INSERT INTO ' . sql_table('plugin_openid_comment') 
544                                 . '( cnumber, citem, identity, ts ) '
545                                 . "values('%s', '%s', '%s', now() )",
546                                  mysql_real_escape_string( $data['commentid'] ),
547                                  mysql_real_escape_string( intval($itemid) ),
548                                  mysql_real_escape_string( $this->loggedinUser['identity']  )
549                 );
550                 sql_query($query);
551         }
552         
553         function event_PostDeleteComment(&$data) {
554                 $query = sprintf('DELETE FROM ' . sql_table('plugin_openid_comment')
555                                 . " where cnumber = '%s'",
556                                  mysql_real_escape_string( intval($data['commentid']) )
557                 );
558                 sql_query($query);
559         }
560         
561         function event_LoginSuccess(&$data) {
562                 if( $this->isLoggedin() ){
563                         $this->logout();
564                 }
565         }
566         
567         function event_Logout(&$data) {
568                 if( $this->isLoggedin() ){
569                         $this->logout();
570                 }
571         }
572         
573         function doTemplateCommentsVar(&$item, &$comment){
574                 global $member, $CONF;
575                 $itemid = intval($item['itemid']);
576                 if( ! $this->comments[$itemid] ){
577                         $this->comments[$itemid]['cached'] = true;
578                         $query = sprintf('SELECT c.cnumber as cnumber, c.identity as identity, p.nick as nick, p.email as email, p.sreg as sreg FROM ' . sql_table('plugin_openid_comment') . ' c '
579                                         . ' LEFT OUTER JOIN ' . sql_table('plugin_openid_profile') . ' p ON c.identity = p.identity '
580                                         . " WHERE citem = '%s'"
581                                         , mysql_real_escape_string( intval($itemid) )
582                         );
583                         $res = sql_query($query);
584                         $this->comments[$itemid] = array();
585                         while( $a =& mysql_fetch_assoc($res)) {
586                                 $cnumber = $a['cnumber'];
587                                 $this->comments[$itemid][$cnumber] = $a;
588                         }
589                 }
590                 $cnumber = $comment['commentid'];
591                 if( $openIdComment = $this->comments[$itemid][$cnumber] ){
592                         $aVars['identity'] =  $openIdComment['identity'];
593                         $aVars['PluginURL'] =  $CONF['PluginURL'];
594                         
595                         $sreg = unserialize($openIdComment['sreg']);
596                         if( is_array($sreg) )
597                                 $aVars = array_merge($aVars, $sreg);
598                         
599                         $te = $this->_getTemplateEngine();
600                         if ( $member->isLoggedIn() ){
601                                 echo $te->fetchAndFill('admin', $aVars, strtolower(__CLASS__));
602                         } else {
603                                 echo $te->fetchAndFill('user', $aVars, strtolower(__CLASS__));
604                         }
605                 }
606         }
607         
608         function _getTemplateEngine(){
609                 if( ! $this->templateEngine )
610                         $this->templateEngine =& new cles_Template(dirname(__FILE__).'/openid/template');
611                         
612                 $this->templateEngine->defaultLang = 'english';
613                 return $this->templateEngine;
614         }
615         
616 }