OSDN Git Service

v1.1.0
authorhsur <hsur@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Sat, 3 May 2008 09:39:48 +0000 (09:39 +0000)
committerhsur <hsur@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Sat, 3 May 2008 09:39:48 +0000 (09:39 +0000)
git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@618 1ca29b6e-896d-4ea0-84a5-967f57386b96

trunk/NP_ReCaptchaJP/NP_ReCaptchaJP.php [new file with mode: 0644]
trunk/NP_ReCaptchaJP/recaptchajp/help.html [new file with mode: 0644]
trunk/NP_ReCaptchaJP/recaptchajp/index.php [new file with mode: 0644]
trunk/NP_ReCaptchaJP/recaptchajp/language/japanese-euc.php [new file with mode: 0644]
trunk/NP_ReCaptchaJP/recaptchajp/language/japanese-utf8.php [new file with mode: 0644]
trunk/NP_ReCaptchaJP/recaptchajp/mkeuc.sh [new file with mode: 0644]
trunk/NP_ReCaptchaJP/sharedlibs/cles/Feedback.php [new file with mode: 0644]
trunk/NP_ReCaptchaJP/sharedlibs/cles/Template.php [new file with mode: 0644]
trunk/NP_ReCaptchaJP/sharedlibs/recaptchalib.php [new file with mode: 0644]
trunk/NP_ReCaptchaJP/sharedlibs/sharedlibs.php [new file with mode: 0644]

diff --git a/trunk/NP_ReCaptchaJP/NP_ReCaptchaJP.php b/trunk/NP_ReCaptchaJP/NP_ReCaptchaJP.php
new file mode 100644 (file)
index 0000000..f84d8af
--- /dev/null
@@ -0,0 +1,170 @@
+<?php
+// vim: tabstop=2:shiftwidth=2
+
+/**
+  * NP_ReCaptchaJP ($Revision: 1.1 $)
+  * by hsur ( http://blog.cles.jp/np_cles )
+  * $Id: NP_ReCaptchaJP.php,v 1.1 2008-05-03 09:39:48 hsur Exp $
+  *
+*/
+
+/*
+  * Copyright (C) 2007-2008 CLES. All rights reserved.
+  *
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  * 
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  * 
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software
+  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+  * 
+  * In addition, as a special exception, cles( http://blog.cles.jp/np_cles ) gives
+  * permission to link the code of this program with those files in the PEAR
+  * library that are licensed under the PHP License (or with modified versions
+  * of those files that use the same license as those files), and distribute
+  * linked combinations including the two. You must obey the GNU General Public
+  * License in all respects for all of the code used other than those files in
+  * the PEAR library that are licensed under the PHP License. If you modify
+  * this file, you may extend this exception to your version of the file,
+  * but you are not obligated to do so. If you do not wish to do so, delete
+  * this exception statement from your version.
+*/
+
+// reCAPTCHA Theme
+define('NP_RECAPTCHAJP_THEME', 'clean');
+
+global $recaptcha_api_server, $recaptcha_api_secure_server, $recaptcha_verify_server;
+require_once(dirname(__FILE__).'/sharedlibs/sharedlibs.php');
+require_once('recaptchalib.php');
+
+class NP_ReCaptchaJP extends NucleusPlugin {
+
+       function getName() {
+               return 'reCAPTCHAJP';
+       }
+       function getAuthor() {
+               return 'hsur';
+       }
+       function getURL() {
+               return 'http://blog.cles.jp/np_cles/category/31/subcatid/18';
+       }
+       function getVersion() {
+               return '1.1.0';
+       }
+       function getMinNucleusVersion() {
+               return 320;
+       }
+       function getMinNucleusPatchLevel() {
+               return 0;
+       }
+       function getEventList() {
+               return array ('FormExtra', 'ValidateForm', );
+       }
+       function getDescription() {
+               return _RECAPTCHAJP_DESC;
+       }
+       function supportsFeature($what) {
+               switch ($what) {
+                       case 'SqlTablePrefix':
+                               return 1;
+                       default:
+                               return 0;
+               }
+       }
+       function hasAdminArea() {
+               return 1;
+       }
+       
+       function install() {
+               $this->createOption('publicKey', 'reCAPTCHA Public Key', 'text', '');
+               $this->createOption('privateKey', 'reCAPTCHA Private Key', 'text', '');
+               $this->createOption('debug', 'Debug mode ?', 'yesno', 'no');
+       }
+       
+       function init() {
+               // include language file for this plugin 
+               $language = ereg_replace( '[\\|/]', '', getLanguageName()); 
+               if (file_exists($this->getDirectory().'language/'.$language.'.php')) 
+                       @include_once($this->getDirectory().'language/'.$language.'.php');
+       }
+
+       function _info($msg) {
+               if ($this->getOption('debug') == 'yes') {
+                       ACTIONLOG :: add(INFO, 'ReCaptchaJP: '.$msg);
+               }
+       }
+
+       function _warn($msg) {
+               ACTIONLOG :: add(WARNING, 'ReCaptchaJP: '.$msg);
+       }
+
+       function event_FormExtra(&$data) {
+               global $manager, $member;
+               if ($member->isLoggedIn())
+                       return;
+               
+               switch ($data['type']) {
+                       case 'commentform-notloggedin' :
+                       case 'membermailform-notloggedin': 
+                               break;
+                       default :
+                               return;
+               }
+               
+               $externalauth = array ( 'source' => $this->getName() );
+               $manager->notify('ExternalAuth', array ('externalauth' => &$externalauth));
+               if (isset($externalauth['result']) && $externalauth['result'] == true) return;
+       
+               $publicKey = $this->getOption('publicKey');
+               if( ! $publicKey ){
+                       $this->_warn('reCAPTCHA Public Key is not set.');
+                       echo 'reCAPTCHA Public Key is not set.';
+                       return;
+               }
+               
+               switch ($data['type']) {
+                       case 'membermailform-notloggedin' :
+                       case 'commentform-notloggedin' :                        
+                               echo '<style>.recaptchatable td img { margin-top:0px; }</style>';
+                               echo "<script type=\"text/javascript\">\nvar RecaptchaOptions = { theme : '".NP_RECAPTCHAJP_THEME."' };\n</script>";
+                               echo _RECAPTCHAJP_header;
+                               echo recaptcha_get_html($publicKey, $this->error);
+                               break;
+               }
+       }
+
+       function event_ValidateForm(&$data) {
+               global $manager, $member;
+               if ($member->isLoggedIn())
+                       return;
+               
+               $externalauth = array ( 'source' => $this->getName() );
+               $manager->notify('ExternalAuth', array ('externalauth' => &$externalauth));
+               if (isset($externalauth['result']) && $externalauth['result'] == true) return;
+               
+               $privateKey = $this->getOption('privateKey');
+               
+               if ($_POST["recaptcha_response_field"]) {
+                       $resp = recaptcha_check_answer ($privateKey,
+                               $_SERVER["REMOTE_ADDR"],
+                               $_POST["recaptcha_challenge_field"],
+                               $_POST["recaptcha_response_field"]);
+                       
+                       if ($resp->is_valid) {
+                               // OK
+                       } else {
+                               $data['error'] = _RECAPTCHAJP_failedMessage . '(' . $resp->error . ')';
+                               $this->_info(_RECAPTCHAJP_failedMessage . ' (' . $resp->error . ')' );
+                       }
+               } else {
+                       $data['error'] = _RECAPTCHAJP_nullMessage;
+               }
+       }
+}
\ No newline at end of file
diff --git a/trunk/NP_ReCaptchaJP/recaptchajp/help.html b/trunk/NP_ReCaptchaJP/recaptchajp/help.html
new file mode 100644 (file)
index 0000000..74b839d
--- /dev/null
@@ -0,0 +1,11 @@
+<h3>バージョン履歴</h3>
+
+<ul>
+       <li>Version 1.1.0: (2008/05/03)</li>
+       <li> [Added] テーマを変更可能にした</li>
+</ul>
+
+<ul>
+       <li>Version 1.0: (2007/06/19)</li>
+       <li> [NEW] 新規作成</li>
+</ul>
diff --git a/trunk/NP_ReCaptchaJP/recaptchajp/index.php b/trunk/NP_ReCaptchaJP/recaptchajp/index.php
new file mode 100644 (file)
index 0000000..46adfc9
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+// vim: tabstop=2:shiftwidth=2
+
+/**
+  * index.php ($Revision: 1.1 $)
+  * 
+  * by hsur ( http://blog.cles.jp/np_cles )
+  * $Id: index.php,v 1.1 2008-05-03 09:39:47 hsur Exp $
+*/
+
+/*
+  * Copyright (C) 2007 CLES. All rights reserved.
+  *
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  * 
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  * 
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software
+  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+  * 
+  * In addition, as a special exception, cles( http://blog.cles.jp/np_cles ) gives
+  * permission to link the code of this program with those files in the PEAR
+  * library that are licensed under the PHP License (or with modified versions
+  * of those files that use the same license as those files), and distribute
+  * linked combinations including the two. You must obey the GNU General Public
+  * License in all respects for all of the code used other than those files in
+  * the PEAR library that are licensed under the PHP License. If you modify
+  * this file, you may extend this exception to your version of the file,
+  * but you are not obligated to do so. If you do not wish to do so, delete
+  * this exception statement from your version.
+*/
+
+$strRel = '../../../';
+include ($strRel.'config.php');
+include ($DIR_LIBS.'PLUGINADMIN.php');
+
+require_once($DIR_PLUGINS . 'sharedlibs/sharedlibs.php');
+require_once('cles/Feedback.php');
+
+if ($blogid) {
+       $isblogadmin = $member->isBlogAdmin($blogid);
+} else
+       $isblogadmin = 0;
+
+if (!$member->isLoggedIn()) {
+       $oPluginAdmin = new PluginAdmin('ReCaptchaJP');
+       $oPluginAdmin->start();
+       echo '<p>'._RECAPTCHAJP_needLogin.'</p>';
+       $oPluginAdmin->end();
+       exit;
+}
+
+if (!($member->isAdmin() || $isblogadmin)) {
+       $oPluginAdmin = new PluginAdmin('ReCaptchaJP');
+       $oPluginAdmin->start();
+       echo "<p>"._ERROR_DISALLOWED."</p>";
+       $oPluginAdmin->end();
+       exit;
+}
+
+if (isset ($_GET['page'])) {
+       $action = getVar('page');
+}
+if (isset ($_POST['page'])) {
+       $action = postVar('page');
+}
+
+// create the admin area page
+$oPluginAdmin = new PluginAdmin('ReCaptchaJP');
+$oPluginAdmin->start();
+$fb =& new cles_Feedback($oPluginAdmin);
+
+// menu
+echo "<h2>ReCaptchaJP menu</h2>\n";
+echo "<ul>\n";
+echo "<li><a href=\"".serverVar('PHP_SELF')."?page=report\"><span style=\"font-weight:bold; color:red\">" . $fb->getMenuStr() . "</span></a></li>\n";
+echo "</ul>\n";
+
+//action
+switch ($action) {
+       case 'report' :
+               $fb->printForm();
+               break;
+
+       default :
+               break;
+}
+
+echo "<br />";
+
+$oPluginAdmin->end();
diff --git a/trunk/NP_ReCaptchaJP/recaptchajp/language/japanese-euc.php b/trunk/NP_ReCaptchaJP/recaptchajp/language/japanese-euc.php
new file mode 100644 (file)
index 0000000..283b77e
--- /dev/null
@@ -0,0 +1,9 @@
+<?php 
+
+// plugin description
+define('_RECAPTCHAJP_DESC', 'reCAPTCHA¤ò»È¤Ã¤¿Ç§¾Ú¤òÄ󶡤·¤Þ¤¹');
+define('_RECAPTCHAJP_failedMessage', 'reCAPTCHAǧ¾Ú¤Ë¼ºÇÔ¤·¤Þ¤·¤¿');           
+define('_RECAPTCHAJP_nullMessage', 'reCAPTCHAǧ¾Ú¤¬ÆþÎϤµ¤ì¤Æ¤¤¤Þ¤»¤ó');               
+define('_RECAPTCHAJP_header', '¡ú²¼µ­¤Ë2¤Ä¤Î±Ññ¸ì¤ò¥¹¥Ú¡¼¥¹¤Ç¶èÀڤäÆÆþÎϤ·¤Æ¤¯¤À¤µ¤¤<br />');
+       
+define('_RECAPTCHAJP_needLogin', '¥í¥°¥¤¥ó¤¬É¬ÍפǤ¹');
diff --git a/trunk/NP_ReCaptchaJP/recaptchajp/language/japanese-utf8.php b/trunk/NP_ReCaptchaJP/recaptchajp/language/japanese-utf8.php
new file mode 100644 (file)
index 0000000..5b4aff8
--- /dev/null
@@ -0,0 +1,9 @@
+<?php 
+
+// plugin description
+define('_RECAPTCHAJP_DESC', 'reCAPTCHAを使った認証を提供します');
+define('_RECAPTCHAJP_failedMessage', 'reCAPTCHA認証に失敗しました');          
+define('_RECAPTCHAJP_nullMessage', 'reCAPTCHA認証が入力されていません');           
+define('_RECAPTCHAJP_header', '★下記に2つの英単語をスペースで区切って入力してください<br />');
+       
+define('_RECAPTCHAJP_needLogin', 'ログインが必要です');
diff --git a/trunk/NP_ReCaptchaJP/recaptchajp/mkeuc.sh b/trunk/NP_ReCaptchaJP/recaptchajp/mkeuc.sh
new file mode 100644 (file)
index 0000000..5f684ef
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/bash -x
+
+FILES=`find . -name '*japanese-utf8*'`
+
+for utf8file in $FILES
+do
+       eucfile=`echo $utf8file | sed 's/japanese-utf8/japanese-euc/'`
+       nkf -e -W -d < $utf8file > $eucfile
+done
diff --git a/trunk/NP_ReCaptchaJP/sharedlibs/cles/Feedback.php b/trunk/NP_ReCaptchaJP/sharedlibs/cles/Feedback.php
new file mode 100644 (file)
index 0000000..5c61048
--- /dev/null
@@ -0,0 +1,176 @@
+<?php
+// vim: tabstop=2:shiftwidth=2
+
+/**
+  * Feedback.php ($Revision: 1.1 $)
+  * 
+  * by hsur ( http://blog.cles.jp/np_cles )
+  * $Id: Feedback.php,v 1.1 2008-05-03 09:39:47 hsur Exp $
+*/
+
+/*
+  * Copyright (C) 2006 CLES. All rights reserved.
+  *
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  * 
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  * 
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software
+  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+  * 
+  * In addition, as a special exception, cles( http://blog.cles.jp/np_cles ) gives
+  * permission to link the code of this program with those files in the PEAR
+  * library that are licensed under the PHP License (or with modified versions
+  * of those files that use the same license as those files), and distribute
+  * linked combinations including the two. You must obey the GNU General Public
+  * License in all respects for all of the code used other than those files in
+  * the PEAR library that are licensed under the PHP License. If you modify
+  * this file, you may extend this exception to your version of the file,
+  * but you are not obligated to do so. If you do not wish to do so, delete
+  * this exception statement from your version.
+*/
+
+class cles_Feedback {
+       var $oPluginAdmin;
+       function CLES_Feedback(&$pluginAdmin){
+               $this->oPluginAdmin = $pluginAdmin;
+       }
+       
+       function getMenuStr(){
+               return mb_convert_encoding('動作確認/不具合報告', _CHARSET, 'UTF-8');
+       }
+       
+       function printForm($extra = '') {
+               ob_start();
+               
+               global $nucleus, $CONF;
+               
+               echo "<h2>動作確認/不具合報告</h2>";
+               echo '<p>下記より、作者への動作確認/不具合の報告を行うことができます。</p>';
+
+               // js
+               echo '<script langage="JavaScript">
+                       function selectall(){
+                               var elements = document.getElementsByTagName(\'input\');
+                               for( var i=0; i < elements.length; i++){
+                                       var e = elements[i];
+                                       if( e.type == \'checkbox\' ){
+                                               e.checked = true;
+                                       }
+                               }
+                               return false;
+                       }
+               </script>';
+               
+               echo "<h3>収集する情報と公開について</h3>";
+               echo '<p>デフォルトで必要最低限の環境情報(赤字のもの)を開発者のサーバへ送信します。<br />
+                                                       <span style="font-weight:bold; color:red">差し支えない範囲で環境情報の提供にご協力ください。</span></p>
+                                                       <p>※ 収集した情報は統計処理、及びプラグインのBugFixのみに利用されます。また統計処理した結果については公表することがあります。</p>';
+               echo '<p><a href="#" onclick="javascript:selectall();return false;">全て送信する場合はここをクリック</a></p>';
+               
+               echo "<h3>サイト固有コードについて</h3>";
+               echo '<p>動作報告の重複を取り除くため、管理画面のURLのmd5を計算したものを送信しています。この情報から管理画面のURLを復元することはできないようになっています。<a href="http://computers.yahoo.co.jp/dict/security/hash/677.html" target="_blank">md5の解説についてはこちらをご覧ください。(Yahoo!コンピュータ用語辞典)</a></p>';
+               
+               // form 
+               echo '<form method="post" action="http://blog.cles.jp/support/report.php">' . "\n";
+
+               // table
+               echo "<table>\n";
+               echo "<tr>\n";
+               echo "<th>項目の説明</th>\n";
+               echo "<th>送信される値</th>\n";
+               echo "<th><a href=\"#\" onclick=\"javascript:selectall();return false;\">全て送信する</th>\n";
+               echo "</tr>\n";
+
+               $res = sql_query("show variables like 'version'");
+               $assoc = mysql_fetch_assoc($res);
+               $mysqlVersion = $assoc['Value'];
+               
+               if( function_exists('gd_info') )
+                       $gdinfo = @gd_info();
+               else
+                       $gdinfo['GD Version'] = 'GD is not supported';
+
+               global $CONF;
+
+               $this->_printtr('siteid', 'サイトの固有コード', md5(trim($CONF['AdminURL'])));
+               $this->_printtr('plugin_name', 'プラグイン名', $this->oPluginAdmin->plugin->getName());
+               $this->_printtr('plugin_version', 'プラグインのバージョン', $this->oPluginAdmin->plugin->getVersion());
+               $this->_printtr('plugin_info', 'プラグインの情報', $extra, true);
+               $this->_printtr('nucleus_version', 'Nucleusのバージョン', $nucleus['version'], true);
+               $this->_printtr('nucleus_charset', 'Nucleusのキャラクタセット', _CHARSET);
+               $this->_printtr('php_version', 'PHPのバージョン', PHP_VERSION, true);
+               $this->_printtr('php_sapi', 'PHPの種類', php_sapi_name());
+               $this->_printtr('php_os', 'OSの種類', PHP_OS, true);
+               $this->_printtr('php_safemode', 'セーフモードの有無', ini_get('safe_mode') ? 'on' : 'off');
+               $this->_printtr('php_gd_version', 'GDのバージョン', $gdinfo['GD Version'], true);
+               $this->_printtr('php_gd_support', 'サポートしているイメージタイプ', implode(',', $this->_supportedImageTypes()) );
+               $this->_printtr('mysql_version', 'MySQLのバージョン', $mysqlVersion, true);
+
+               echo "<tr>\n";
+               echo "<td>このプラグインは機能しましたか?</td>\n";
+               echo '<td colsan="2"><input type="radio" name="user_intention" value="ok" />はい <br/> <input type="radio" name="intention" value="ng" />いいえ'."</td>\n";
+               echo "</tr>\n";
+
+               echo "<tr>\n";
+               echo "<td>不具合の内容をお寄せください<br /><em>必ず回答が必要な質問については、<a href=\"http://japan.nucleuscms.org/bb/\">Nucleusサポートフォーラム</a>もしくは<a href=\"http://blog.cles.jp/np_cles/\">作者ページ</a>でご質問ください。</em></td>\n";
+               echo '<td colspan="2"><textarea name="user_freetext" rows="10" cols="70"></textarea>'."</td>\n";
+               echo "</tr>\n";
+
+               echo "<tr>\n";
+               echo "<td>よろしければサイトのURLを教えてください</td>\n";
+               echo '<td colspan="2"><textarea name="user_url" rows="1" cols="70"></textarea>'."</td>\n";
+               echo "</tr>\n";
+               
+               echo "<tr>\n";
+               echo "<td>リンク集作成の際、リンクをはらせていただけますか?</td>\n";
+               echo '<td colspan="2"><input type="radio" name="user_disclose" value="yes" />はい <br/> <input type="radio" name="intention" value="no" />いいえ'."</td>\n";
+               echo "</tr>\n";
+
+               echo '<tr><td colspan="3"><div align="right"><input type="submit" name="submit" value="動作確認を送信する" /></div></td></tr>';
+               echo "</table>\n";
+               echo "</form>\n";
+               
+               $contents = ob_get_contents();
+               ob_end_clean();
+               echo mb_convert_encoding($contents, _CHARSET, 'UTF-8');
+       }
+       
+       function _printtr($name, $desc, $value, $canDisable = false) {
+               echo "<tr>\n";
+       
+               if ($canDisable) {
+                       echo "<td>".$desc."</td>\n";
+                       echo "<td>".htmlspecialchars($value)."</td>\n";
+                       echo '<td><input type="checkbox" name="'.htmlspecialchars($name).'" value="'.htmlspecialchars($value).'" /></td>'."\n";
+               } else {
+                       echo '<td><span style="font-weight:bold; color:red">'.$desc."</span></td>\n";
+                       echo '<td><span style="font-weight:bold; color:red">'.htmlspecialchars($value)."</span></td>\n";
+                       echo '<td><input type="checkbox" name="'.htmlspecialchars($name).'" value="'.htmlspecialchars($value).'" readonly="readonly" checked="checked"/></span></td>'."\n";
+               }
+               echo "</tr>\n";
+       }
+       
+       function _supportedImageTypes() {
+               if( !function_exists('gd_info') ) return "";
+               
+               $aSupportedTypes = array ();
+               $aPossibleImageTypeBits = array (IMG_GIF => 'GIF', IMG_JPG => 'JPG', IMG_PNG => 'PNG', IMG_WBMP => 'WBMP');
+       
+               foreach ($aPossibleImageTypeBits as $iImageTypeBits => $sImageTypeString) {
+                       if (imagetypes() & $iImageTypeBits) {
+                               $aSupportedTypes[] = $sImageTypeString;
+                       }
+               }
+       
+               return $aSupportedTypes;
+       }
+
+}
diff --git a/trunk/NP_ReCaptchaJP/sharedlibs/cles/Template.php b/trunk/NP_ReCaptchaJP/sharedlibs/cles/Template.php
new file mode 100644 (file)
index 0000000..8334a02
--- /dev/null
@@ -0,0 +1,76 @@
+<?php
+// vim: tabstop=2:shiftwidth=2
+
+/**
+  * Template.php ($Revision: 1.1 $)
+  * 
+  * by hsur ( http://blog.cles.jp/np_cles )
+  * $Id: Template.php,v 1.1 2008-05-03 09:39:47 hsur Exp $
+*/
+
+/*
+  * Copyright (C) 2006 CLES. All rights reserved.
+  *
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  * 
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  * 
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software
+  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+  * 
+  * In addition, as a special exception, cles( http://blog.cles.jp/np_cles ) gives
+  * permission to link the code of this program with those files in the PEAR
+  * library that are licensed under the PHP License (or with modified versions
+  * of those files that use the same license as those files), and distribute
+  * linked combinations including the two. You must obey the GNU General Public
+  * License in all respects for all of the code used other than those files in
+  * the PEAR library that are licensed under the PHP License. If you modify
+  * this file, you may extend this exception to your version of the file,
+  * but you are not obligated to do so. If you do not wish to do so, delete
+  * this exception statement from your version.
+*/
+
+class cles_Template {
+       var $defaultLang = 'japanese-utf8';
+       var $defalutPattern = '#{{(.*?)(\|)?}}#ie';
+       var $lang;
+       var $templateDir;
+
+       function cles_Template($templateDir) {
+               global $CONF;
+               $this->templateDir = $templateDir;
+               $this->lang = ereg_replace( '[\\|/]', '', getLanguageName());
+       }
+
+       function fetch($name, $dir = null, $suffix = 'html') {
+               $path = $this->templateDir.'/'.( $dir ? strtolower($dir) . '/' : '' ).strtolower($name).'_'.$this->lang.( $suffix ? '.'.strtolower($suffix) : '' );
+               if ( ! file_exists($path) ){
+                       $path = $this->templateDir.'/'.( $dir ? strtolower($dir) . '/' : '' ).strtolower($name).'_'.$this->defaultLang.( $suffix ? '.'.strtolower($suffix) : '' );
+                       if ( ! file_exists($path) )
+                               return '';
+               }
+               
+               $fsize = filesize($path);
+               if ($fsize <= 0) return '';
+               
+               $fd = fopen($path, 'r');
+               $contents = fread($fd, $fsize);
+               fclose($fd);
+               return $contents;
+       }
+       
+       function fill($template, $values, $default = null) {
+               if( $default )
+                       return preg_replace($this->defalutPattern, 'isset($values["$1"]) ? ("$2" ? htmlspecialchars($values["$1"], ENT_QUOTES) : $values["$1"]) : $default', $template);
+               if( $default === null )
+                       return preg_replace($this->defalutPattern, '("$2") ? htmlspecialchars($values["$1"], ENT_QUOTES) : $values["$1"]', $template);
+               return preg_replace($this->defalutPattern, 'isset($values["$1"]) ? ("$2" ? htmlspecialchars($values["$1"], ENT_QUOTES) : $values["$1"]) : "{{$1}}" ', $template);
+       }
+}
diff --git a/trunk/NP_ReCaptchaJP/sharedlibs/recaptchalib.php b/trunk/NP_ReCaptchaJP/sharedlibs/recaptchalib.php
new file mode 100644 (file)
index 0000000..897c509
--- /dev/null
@@ -0,0 +1,277 @@
+<?php
+/*
+ * This is a PHP library that handles calling reCAPTCHA.
+ *    - Documentation and latest version
+ *          http://recaptcha.net/plugins/php/
+ *    - Get a reCAPTCHA API Key
+ *          http://recaptcha.net/api/getkey
+ *    - Discussion group
+ *          http://groups.google.com/group/recaptcha
+ *
+ * Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
+ * AUTHORS:
+ *   Mike Crawford
+ *   Ben Maurer
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/**
+ * The reCAPTCHA server URL's
+ */
+define("RECAPTCHA_API_SERVER", "http://api.recaptcha.net");
+define("RECAPTCHA_API_SECURE_SERVER", "https://api-secure.recaptcha.net");
+define("RECAPTCHA_VERIFY_SERVER", "api-verify.recaptcha.net");
+
+/**
+ * Encodes the given data into a query string format
+ * @param $data - array of string elements to be encoded
+ * @return string - encoded request
+ */
+function _recaptcha_qsencode ($data) {
+        $req = "";
+        foreach ( $data as $key => $value )
+                $req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
+
+        // Cut the last '&'
+        $req=substr($req,0,strlen($req)-1);
+        return $req;
+}
+
+
+
+/**
+ * Submits an HTTP POST to a reCAPTCHA server
+ * @param string $host
+ * @param string $path
+ * @param array $data
+ * @param int port
+ * @return array response
+ */
+function _recaptcha_http_post($host, $path, $data, $port = 80) {
+
+        $req = _recaptcha_qsencode ($data);
+
+        $http_request  = "POST $path HTTP/1.0\r\n";
+        $http_request .= "Host: $host\r\n";
+        $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
+        $http_request .= "Content-Length: " . strlen($req) . "\r\n";
+        $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
+        $http_request .= "\r\n";
+        $http_request .= $req;
+
+        $response = '';
+        if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
+                die ('Could not open socket');
+        }
+
+        fwrite($fs, $http_request);
+
+        while ( !feof($fs) )
+                $response .= fgets($fs, 1160); // One TCP-IP packet
+        fclose($fs);
+        $response = explode("\r\n\r\n", $response, 2);
+
+        return $response;
+}
+
+
+
+/**
+ * Gets the challenge HTML (javascript and non-javascript version).
+ * This is called from the browser, and the resulting reCAPTCHA HTML widget
+ * is embedded within the HTML form it was called from.
+ * @param string $pubkey A public key for reCAPTCHA
+ * @param string $error The error given by reCAPTCHA (optional, default is null)
+ * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false)
+
+ * @return string - The HTML to be embedded in the user's form.
+ */
+function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
+{
+       if ($pubkey == null || $pubkey == '') {
+               die ("To use reCAPTCHA you must get an API key from <a href='http://recaptcha.net/api/getkey'>http://recaptcha.net/api/getkey</a>");
+       }
+       
+       if ($use_ssl) {
+                $server = RECAPTCHA_API_SECURE_SERVER;
+        } else {
+                $server = RECAPTCHA_API_SERVER;
+        }
+
+        $errorpart = "";
+        if ($error) {
+           $errorpart = "&amp;error=" . $error;
+        }
+        return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script>
+
+       <noscript>
+               <iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/>
+               <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
+               <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
+       </noscript>';
+}
+
+
+
+
+/**
+ * A ReCaptchaResponse is returned from recaptcha_check_answer()
+ */
+class ReCaptchaResponse {
+        var $is_valid;
+        var $error;
+}
+
+
+/**
+  * Calls an HTTP POST function to verify if the user's guess was correct
+  * @param string $privkey
+  * @param string $remoteip
+  * @param string $challenge
+  * @param string $response
+  * @param array $extra_params an array of extra variables to post to the server
+  * @return ReCaptchaResponse
+  */
+function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
+{
+       if ($privkey == null || $privkey == '') {
+               die ("To use reCAPTCHA you must get an API key from <a href='http://recaptcha.net/api/getkey'>http://recaptcha.net/api/getkey</a>");
+       }
+
+       if ($remoteip == null || $remoteip == '') {
+               die ("For security reasons, you must pass the remote ip to reCAPTCHA");
+       }
+
+       
+       
+        //discard spam submissions
+        if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
+                $recaptcha_response = new ReCaptchaResponse();
+                $recaptcha_response->is_valid = false;
+                $recaptcha_response->error = 'incorrect-captcha-sol';
+                return $recaptcha_response;
+        }
+
+        $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/verify",
+                                          array (
+                                                 'privatekey' => $privkey,
+                                                 'remoteip' => $remoteip,
+                                                 'challenge' => $challenge,
+                                                 'response' => $response
+                                                 ) + $extra_params
+                                          );
+
+        $answers = explode ("\n", $response [1]);
+        $recaptcha_response = new ReCaptchaResponse();
+
+        if (trim ($answers [0]) == 'true') {
+                $recaptcha_response->is_valid = true;
+        }
+        else {
+                $recaptcha_response->is_valid = false;
+                $recaptcha_response->error = $answers [1];
+        }
+        return $recaptcha_response;
+
+}
+
+/**
+ * gets a URL where the user can sign up for reCAPTCHA. If your application
+ * has a configuration page where you enter a key, you should provide a link
+ * using this function.
+ * @param string $domain The domain where the page is hosted
+ * @param string $appname The name of your application
+ */
+function recaptcha_get_signup_url ($domain = null, $appname = null) {
+       return "http://recaptcha.net/api/getkey?" .  _recaptcha_qsencode (array ('domain' => $domain, 'app' => $appname));
+}
+
+function _recaptcha_aes_pad($val) {
+       $block_size = 16;
+       $numpad = $block_size - (strlen ($val) % $block_size);
+       return str_pad($val, strlen ($val) + $numpad, chr($numpad));
+}
+
+/* Mailhide related code */
+
+function _recaptcha_aes_encrypt($val,$ky) {
+       if (! function_exists ("mcrypt_encrypt")) {
+               die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
+       }
+       $mode=MCRYPT_MODE_CBC;   
+       $enc=MCRYPT_RIJNDAEL_128;
+       $val=_recaptcha_aes_pad($val);
+       return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
+}
+
+
+function _recaptcha_mailhide_urlbase64 ($x) {
+       return strtr(base64_encode ($x), '+/', '-_');
+}
+
+/* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
+function recaptcha_mailhide_url($pubkey, $privkey, $email) {
+       if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) {
+               die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " .
+                    "you can do so at <a href='http://mailhide.recaptcha.net/apikey'>http://mailhide.recaptcha.net/apikey</a>");
+       }
+       
+
+       $ky = pack('H*', $privkey);
+       $cryptmail = _recaptcha_aes_encrypt ($email, $ky);
+       
+       return "http://mailhide.recaptcha.net/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
+}
+
+/**
+ * gets the parts of the email to expose to the user.
+ * eg, given johndoe@example,com return ["john", "example.com"].
+ * the email is then displayed as john...@example.com
+ */
+function _recaptcha_mailhide_email_parts ($email) {
+       $arr = preg_split("/@/", $email );
+
+       if (strlen ($arr[0]) <= 4) {
+               $arr[0] = substr ($arr[0], 0, 1);
+       } else if (strlen ($arr[0]) <= 6) {
+               $arr[0] = substr ($arr[0], 0, 3);
+       } else {
+               $arr[0] = substr ($arr[0], 0, 4);
+       }
+       return $arr;
+}
+
+/**
+ * Gets html to display an email address given a public an private key.
+ * to get a key, go to:
+ *
+ * http://mailhide.recaptcha.net/apikey
+ */
+function recaptcha_mailhide_html($pubkey, $privkey, $email) {
+       $emailparts = _recaptcha_mailhide_email_parts ($email);
+       $url = recaptcha_mailhide_url ($pubkey, $privkey, $email);
+       
+       return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) .
+               "' onclick=\"window.open('" . htmlentities ($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities ($emailparts [1]);
+
+}
+
+
+?>
diff --git a/trunk/NP_ReCaptchaJP/sharedlibs/sharedlibs.php b/trunk/NP_ReCaptchaJP/sharedlibs/sharedlibs.php
new file mode 100644 (file)
index 0000000..82bd16e
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+// vim: tabstop=2:shiftwidth=2
+
+/**
+  * sharedlibs.php ($Revision: 1.1 $)
+  * 
+  * by hsur ( http://blog.cles.jp/np_cles )
+  * $Id: sharedlibs.php,v 1.1 2008-05-03 09:39:48 hsur Exp $
+*/
+
+/*
+  * Copyright (C) 2006 CLES. All rights reserved.
+  *
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  * 
+  * This program is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  * GNU General Public License for more details.
+  * 
+  * You should have received a copy of the GNU General Public License
+  * along with this program; if not, write to the Free Software
+  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+  * 
+  * In addition, as a special exception, cles( http://blog.cles.jp/np_cles ) gives
+  * permission to link the code of this program with those files in the PEAR
+  * library that are licensed under the PHP License (or with modified versions
+  * of those files that use the same license as those files), and distribute
+  * linked combinations including the two. You must obey the GNU General Public
+  * License in all respects for all of the code used other than those files in
+  * the PEAR library that are licensed under the PHP License. If you modify
+  * this file, you may extend this exception to your version of the file,
+  * but you are not obligated to do so. If you do not wish to do so, delete
+  * this exception statement from your version.
+*/
+
+if (!defined('NP_SHAREDLIBS_LOADED')) {
+       if (!defined('PATH_SEPARATOR')) {
+               if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
+                       define('PATH_SEPARATOR', ';');
+               } else {
+                       define('PATH_SEPARATOR', ':');
+               }
+       }
+       ini_set('include_path', dirname(__FILE__).PATH_SEPARATOR.ini_get('include_path'));
+
+       define('NP_SHAREDLIBS_LOADED', true);
+}