• R/O
  • HTTP
  • SSH
  • HTTPS

nucleus-plugins: Commit

Nucleus CMS日本語版用プラグインのうち、日本語版開発者がサポートしているもの


Commit MetaInfo

Revisiondcf042562ea9d82c6310c64edbdebcaddfa62d1f (tree)
Time2008-05-03 18:39:48
Authorhsur <hsur@1ca2...>
Commiterhsur

Log Message

v1.1.0

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@618 1ca29b6e-896d-4ea0-84a5-967f57386b96

Change Summary

Incremental Difference

--- /dev/null
+++ b/trunk/NP_ReCaptchaJP/NP_ReCaptchaJP.php
@@ -0,0 +1,170 @@
1+<?php
2+// vim: tabstop=2:shiftwidth=2
3+
4+/**
5+ * NP_ReCaptchaJP ($Revision: 1.1 $)
6+ * by hsur ( http://blog.cles.jp/np_cles )
7+ * $Id: NP_ReCaptchaJP.php,v 1.1 2008-05-03 09:39:48 hsur Exp $
8+ *
9+*/
10+
11+/*
12+ * Copyright (C) 2007-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+// reCAPTCHA Theme
41+define('NP_RECAPTCHAJP_THEME', 'clean');
42+
43+global $recaptcha_api_server, $recaptcha_api_secure_server, $recaptcha_verify_server;
44+require_once(dirname(__FILE__).'/sharedlibs/sharedlibs.php');
45+require_once('recaptchalib.php');
46+
47+class NP_ReCaptchaJP extends NucleusPlugin {
48+
49+ function getName() {
50+ return 'reCAPTCHAJP';
51+ }
52+ function getAuthor() {
53+ return 'hsur';
54+ }
55+ function getURL() {
56+ return 'http://blog.cles.jp/np_cles/category/31/subcatid/18';
57+ }
58+ function getVersion() {
59+ return '1.1.0';
60+ }
61+ function getMinNucleusVersion() {
62+ return 320;
63+ }
64+ function getMinNucleusPatchLevel() {
65+ return 0;
66+ }
67+ function getEventList() {
68+ return array ('FormExtra', 'ValidateForm', );
69+ }
70+ function getDescription() {
71+ return _RECAPTCHAJP_DESC;
72+ }
73+ function supportsFeature($what) {
74+ switch ($what) {
75+ case 'SqlTablePrefix':
76+ return 1;
77+ default:
78+ return 0;
79+ }
80+ }
81+ function hasAdminArea() {
82+ return 1;
83+ }
84+
85+ function install() {
86+ $this->createOption('publicKey', 'reCAPTCHA Public Key', 'text', '');
87+ $this->createOption('privateKey', 'reCAPTCHA Private Key', 'text', '');
88+ $this->createOption('debug', 'Debug mode ?', 'yesno', 'no');
89+ }
90+
91+ function init() {
92+ // include language file for this plugin
93+ $language = ereg_replace( '[\\|/]', '', getLanguageName());
94+ if (file_exists($this->getDirectory().'language/'.$language.'.php'))
95+ @include_once($this->getDirectory().'language/'.$language.'.php');
96+ }
97+
98+ function _info($msg) {
99+ if ($this->getOption('debug') == 'yes') {
100+ ACTIONLOG :: add(INFO, 'ReCaptchaJP: '.$msg);
101+ }
102+ }
103+
104+ function _warn($msg) {
105+ ACTIONLOG :: add(WARNING, 'ReCaptchaJP: '.$msg);
106+ }
107+
108+ function event_FormExtra(&$data) {
109+ global $manager, $member;
110+ if ($member->isLoggedIn())
111+ return;
112+
113+ switch ($data['type']) {
114+ case 'commentform-notloggedin' :
115+ case 'membermailform-notloggedin':
116+ break;
117+ default :
118+ return;
119+ }
120+
121+ $externalauth = array ( 'source' => $this->getName() );
122+ $manager->notify('ExternalAuth', array ('externalauth' => &$externalauth));
123+ if (isset($externalauth['result']) && $externalauth['result'] == true) return;
124+
125+ $publicKey = $this->getOption('publicKey');
126+ if( ! $publicKey ){
127+ $this->_warn('reCAPTCHA Public Key is not set.');
128+ echo 'reCAPTCHA Public Key is not set.';
129+ return;
130+ }
131+
132+ switch ($data['type']) {
133+ case 'membermailform-notloggedin' :
134+ case 'commentform-notloggedin' :
135+ echo '<style>.recaptchatable td img { margin-top:0px; }</style>';
136+ echo "<script type=\"text/javascript\">\nvar RecaptchaOptions = { theme : '".NP_RECAPTCHAJP_THEME."' };\n</script>";
137+ echo _RECAPTCHAJP_header;
138+ echo recaptcha_get_html($publicKey, $this->error);
139+ break;
140+ }
141+ }
142+
143+ function event_ValidateForm(&$data) {
144+ global $manager, $member;
145+ if ($member->isLoggedIn())
146+ return;
147+
148+ $externalauth = array ( 'source' => $this->getName() );
149+ $manager->notify('ExternalAuth', array ('externalauth' => &$externalauth));
150+ if (isset($externalauth['result']) && $externalauth['result'] == true) return;
151+
152+ $privateKey = $this->getOption('privateKey');
153+
154+ if ($_POST["recaptcha_response_field"]) {
155+ $resp = recaptcha_check_answer ($privateKey,
156+ $_SERVER["REMOTE_ADDR"],
157+ $_POST["recaptcha_challenge_field"],
158+ $_POST["recaptcha_response_field"]);
159+
160+ if ($resp->is_valid) {
161+ // OK
162+ } else {
163+ $data['error'] = _RECAPTCHAJP_failedMessage . '(' . $resp->error . ')';
164+ $this->_info(_RECAPTCHAJP_failedMessage . ' (' . $resp->error . ')' );
165+ }
166+ } else {
167+ $data['error'] = _RECAPTCHAJP_nullMessage;
168+ }
169+ }
170+}
\ No newline at end of file
--- /dev/null
+++ b/trunk/NP_ReCaptchaJP/recaptchajp/help.html
@@ -0,0 +1,11 @@
1+<h3>バージョン履歴</h3>
2+
3+<ul>
4+ <li>Version 1.1.0: (2008/05/03)</li>
5+ <li> [Added] テーマを変更可能にした</li>
6+</ul>
7+
8+<ul>
9+ <li>Version 1.0: (2007/06/19)</li>
10+ <li> [NEW] 新規作成</li>
11+</ul>
--- /dev/null
+++ b/trunk/NP_ReCaptchaJP/recaptchajp/index.php
@@ -0,0 +1,98 @@
1+<?php
2+// vim: tabstop=2:shiftwidth=2
3+
4+/**
5+ * index.php ($Revision: 1.1 $)
6+ *
7+ * by hsur ( http://blog.cles.jp/np_cles )
8+ * $Id: index.php,v 1.1 2008-05-03 09:39:47 hsur Exp $
9+*/
10+
11+/*
12+ * Copyright (C) 2007 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+$strRel = '../../../';
41+include ($strRel.'config.php');
42+include ($DIR_LIBS.'PLUGINADMIN.php');
43+
44+require_once($DIR_PLUGINS . 'sharedlibs/sharedlibs.php');
45+require_once('cles/Feedback.php');
46+
47+if ($blogid) {
48+ $isblogadmin = $member->isBlogAdmin($blogid);
49+} else
50+ $isblogadmin = 0;
51+
52+if (!$member->isLoggedIn()) {
53+ $oPluginAdmin = new PluginAdmin('ReCaptchaJP');
54+ $oPluginAdmin->start();
55+ echo '<p>'._RECAPTCHAJP_needLogin.'</p>';
56+ $oPluginAdmin->end();
57+ exit;
58+}
59+
60+if (!($member->isAdmin() || $isblogadmin)) {
61+ $oPluginAdmin = new PluginAdmin('ReCaptchaJP');
62+ $oPluginAdmin->start();
63+ echo "<p>"._ERROR_DISALLOWED."</p>";
64+ $oPluginAdmin->end();
65+ exit;
66+}
67+
68+if (isset ($_GET['page'])) {
69+ $action = getVar('page');
70+}
71+if (isset ($_POST['page'])) {
72+ $action = postVar('page');
73+}
74+
75+// create the admin area page
76+$oPluginAdmin = new PluginAdmin('ReCaptchaJP');
77+$oPluginAdmin->start();
78+$fb =& new cles_Feedback($oPluginAdmin);
79+
80+// menu
81+echo "<h2>ReCaptchaJP menu</h2>\n";
82+echo "<ul>\n";
83+echo "<li><a href=\"".serverVar('PHP_SELF')."?page=report\"><span style=\"font-weight:bold; color:red\">" . $fb->getMenuStr() . "</span></a></li>\n";
84+echo "</ul>\n";
85+
86+//action
87+switch ($action) {
88+ case 'report' :
89+ $fb->printForm();
90+ break;
91+
92+ default :
93+ break;
94+}
95+
96+echo "<br />";
97+
98+$oPluginAdmin->end();
--- /dev/null
+++ b/trunk/NP_ReCaptchaJP/recaptchajp/language/japanese-euc.php
@@ -0,0 +1,9 @@
1+<?php
2+
3+// plugin description
4+define('_RECAPTCHAJP_DESC', 'reCAPTCHAを使った認証を提供します');
5+define('_RECAPTCHAJP_failedMessage', 'reCAPTCHA認証に失敗しました');
6+define('_RECAPTCHAJP_nullMessage', 'reCAPTCHA認証が入力されていません');
7+define('_RECAPTCHAJP_header', '★下記に2つの英単語をスペースで区切って入力してください<br />');
8+
9+define('_RECAPTCHAJP_needLogin', 'ログインが必要です');
--- /dev/null
+++ b/trunk/NP_ReCaptchaJP/recaptchajp/language/japanese-utf8.php
@@ -0,0 +1,9 @@
1+<?php
2+
3+// plugin description
4+define('_RECAPTCHAJP_DESC', 'reCAPTCHAを使った認証を提供します');
5+define('_RECAPTCHAJP_failedMessage', 'reCAPTCHA認証に失敗しました');
6+define('_RECAPTCHAJP_nullMessage', 'reCAPTCHA認証が入力されていません');
7+define('_RECAPTCHAJP_header', '★下記に2つの英単語をスペースで区切って入力してください<br />');
8+
9+define('_RECAPTCHAJP_needLogin', 'ログインが必要です');
--- /dev/null
+++ b/trunk/NP_ReCaptchaJP/recaptchajp/mkeuc.sh
@@ -0,0 +1,9 @@
1+#!/bin/bash -x
2+
3+FILES=`find . -name '*japanese-utf8*'`
4+
5+for utf8file in $FILES
6+do
7+ eucfile=`echo $utf8file | sed 's/japanese-utf8/japanese-euc/'`
8+ nkf -e -W -d < $utf8file > $eucfile
9+done
--- /dev/null
+++ b/trunk/NP_ReCaptchaJP/sharedlibs/cles/Feedback.php
@@ -0,0 +1,176 @@
1+<?php
2+// vim: tabstop=2:shiftwidth=2
3+
4+/**
5+ * Feedback.php ($Revision: 1.1 $)
6+ *
7+ * by hsur ( http://blog.cles.jp/np_cles )
8+ * $Id: Feedback.php,v 1.1 2008-05-03 09:39:47 hsur Exp $
9+*/
10+
11+/*
12+ * Copyright (C) 2006 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+class cles_Feedback {
41+ var $oPluginAdmin;
42+ function CLES_Feedback(&$pluginAdmin){
43+ $this->oPluginAdmin = $pluginAdmin;
44+ }
45+
46+ function getMenuStr(){
47+ return mb_convert_encoding('動作確認/不具合報告', _CHARSET, 'UTF-8');
48+ }
49+
50+ function printForm($extra = '') {
51+ ob_start();
52+
53+ global $nucleus, $CONF;
54+
55+ echo "<h2>動作確認/不具合報告</h2>";
56+ echo '<p>下記より、作者への動作確認/不具合の報告を行うことができます。</p>';
57+
58+ // js
59+ echo '<script langage="JavaScript">
60+ function selectall(){
61+ var elements = document.getElementsByTagName(\'input\');
62+ for( var i=0; i < elements.length; i++){
63+ var e = elements[i];
64+ if( e.type == \'checkbox\' ){
65+ e.checked = true;
66+ }
67+ }
68+ return false;
69+ }
70+ </script>';
71+
72+ echo "<h3>収集する情報と公開について</h3>";
73+ echo '<p>デフォルトで必要最低限の環境情報(赤字のもの)を開発者のサーバへ送信します。<br />
74+ <span style="font-weight:bold; color:red">差し支えない範囲で環境情報の提供にご協力ください。</span></p>
75+ <p>※ 収集した情報は統計処理、及びプラグインのBugFixのみに利用されます。また統計処理した結果については公表することがあります。</p>';
76+ echo '<p><a href="#" onclick="javascript:selectall();return false;">全て送信する場合はここをクリック</a></p>';
77+
78+ echo "<h3>サイト固有コードについて</h3>";
79+ echo '<p>動作報告の重複を取り除くため、管理画面のURLのmd5を計算したものを送信しています。この情報から管理画面のURLを復元することはできないようになっています。<a href="http://computers.yahoo.co.jp/dict/security/hash/677.html" target="_blank">md5の解説についてはこちらをご覧ください。(Yahoo!コンピュータ用語辞典)</a></p>';
80+
81+ // form
82+ echo '<form method="post" action="http://blog.cles.jp/support/report.php">' . "\n";
83+
84+ // table
85+ echo "<table>\n";
86+ echo "<tr>\n";
87+ echo "<th>項目の説明</th>\n";
88+ echo "<th>送信される値</th>\n";
89+ echo "<th><a href=\"#\" onclick=\"javascript:selectall();return false;\">全て送信する</th>\n";
90+ echo "</tr>\n";
91+
92+ $res = sql_query("show variables like 'version'");
93+ $assoc = mysql_fetch_assoc($res);
94+ $mysqlVersion = $assoc['Value'];
95+
96+ if( function_exists('gd_info') )
97+ $gdinfo = @gd_info();
98+ else
99+ $gdinfo['GD Version'] = 'GD is not supported';
100+
101+ global $CONF;
102+
103+ $this->_printtr('siteid', 'サイトの固有コード', md5(trim($CONF['AdminURL'])));
104+ $this->_printtr('plugin_name', 'プラグイン名', $this->oPluginAdmin->plugin->getName());
105+ $this->_printtr('plugin_version', 'プラグインのバージョン', $this->oPluginAdmin->plugin->getVersion());
106+ $this->_printtr('plugin_info', 'プラグインの情報', $extra, true);
107+ $this->_printtr('nucleus_version', 'Nucleusのバージョン', $nucleus['version'], true);
108+ $this->_printtr('nucleus_charset', 'Nucleusのキャラクタセット', _CHARSET);
109+ $this->_printtr('php_version', 'PHPのバージョン', PHP_VERSION, true);
110+ $this->_printtr('php_sapi', 'PHPの種類', php_sapi_name());
111+ $this->_printtr('php_os', 'OSの種類', PHP_OS, true);
112+ $this->_printtr('php_safemode', 'セーフモードの有無', ini_get('safe_mode') ? 'on' : 'off');
113+ $this->_printtr('php_gd_version', 'GDのバージョン', $gdinfo['GD Version'], true);
114+ $this->_printtr('php_gd_support', 'サポートしているイメージタイプ', implode(',', $this->_supportedImageTypes()) );
115+ $this->_printtr('mysql_version', 'MySQLのバージョン', $mysqlVersion, true);
116+
117+ echo "<tr>\n";
118+ echo "<td>このプラグインは機能しましたか?</td>\n";
119+ echo '<td colsan="2"><input type="radio" name="user_intention" value="ok" />はい <br/> <input type="radio" name="intention" value="ng" />いいえ'."</td>\n";
120+ echo "</tr>\n";
121+
122+ echo "<tr>\n";
123+ 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";
124+ echo '<td colspan="2"><textarea name="user_freetext" rows="10" cols="70"></textarea>'."</td>\n";
125+ echo "</tr>\n";
126+
127+ echo "<tr>\n";
128+ echo "<td>よろしければサイトのURLを教えてください</td>\n";
129+ echo '<td colspan="2"><textarea name="user_url" rows="1" cols="70"></textarea>'."</td>\n";
130+ echo "</tr>\n";
131+
132+ echo "<tr>\n";
133+ echo "<td>リンク集作成の際、リンクをはらせていただけますか?</td>\n";
134+ echo '<td colspan="2"><input type="radio" name="user_disclose" value="yes" />はい <br/> <input type="radio" name="intention" value="no" />いいえ'."</td>\n";
135+ echo "</tr>\n";
136+
137+ echo '<tr><td colspan="3"><div align="right"><input type="submit" name="submit" value="動作確認を送信する" /></div></td></tr>';
138+ echo "</table>\n";
139+ echo "</form>\n";
140+
141+ $contents = ob_get_contents();
142+ ob_end_clean();
143+ echo mb_convert_encoding($contents, _CHARSET, 'UTF-8');
144+ }
145+
146+ function _printtr($name, $desc, $value, $canDisable = false) {
147+ echo "<tr>\n";
148+
149+ if ($canDisable) {
150+ echo "<td>".$desc."</td>\n";
151+ echo "<td>".htmlspecialchars($value)."</td>\n";
152+ echo '<td><input type="checkbox" name="'.htmlspecialchars($name).'" value="'.htmlspecialchars($value).'" /></td>'."\n";
153+ } else {
154+ echo '<td><span style="font-weight:bold; color:red">'.$desc."</span></td>\n";
155+ echo '<td><span style="font-weight:bold; color:red">'.htmlspecialchars($value)."</span></td>\n";
156+ echo '<td><input type="checkbox" name="'.htmlspecialchars($name).'" value="'.htmlspecialchars($value).'" readonly="readonly" checked="checked"/></span></td>'."\n";
157+ }
158+ echo "</tr>\n";
159+ }
160+
161+ function _supportedImageTypes() {
162+ if( !function_exists('gd_info') ) return "";
163+
164+ $aSupportedTypes = array ();
165+ $aPossibleImageTypeBits = array (IMG_GIF => 'GIF', IMG_JPG => 'JPG', IMG_PNG => 'PNG', IMG_WBMP => 'WBMP');
166+
167+ foreach ($aPossibleImageTypeBits as $iImageTypeBits => $sImageTypeString) {
168+ if (imagetypes() & $iImageTypeBits) {
169+ $aSupportedTypes[] = $sImageTypeString;
170+ }
171+ }
172+
173+ return $aSupportedTypes;
174+ }
175+
176+}
--- /dev/null
+++ b/trunk/NP_ReCaptchaJP/sharedlibs/cles/Template.php
@@ -0,0 +1,76 @@
1+<?php
2+// vim: tabstop=2:shiftwidth=2
3+
4+/**
5+ * Template.php ($Revision: 1.1 $)
6+ *
7+ * by hsur ( http://blog.cles.jp/np_cles )
8+ * $Id: Template.php,v 1.1 2008-05-03 09:39:47 hsur Exp $
9+*/
10+
11+/*
12+ * Copyright (C) 2006 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+class cles_Template {
41+ var $defaultLang = 'japanese-utf8';
42+ var $defalutPattern = '#{{(.*?)(\|)?}}#ie';
43+ var $lang;
44+ var $templateDir;
45+
46+ function cles_Template($templateDir) {
47+ global $CONF;
48+ $this->templateDir = $templateDir;
49+ $this->lang = ereg_replace( '[\\|/]', '', getLanguageName());
50+ }
51+
52+ function fetch($name, $dir = null, $suffix = 'html') {
53+ $path = $this->templateDir.'/'.( $dir ? strtolower($dir) . '/' : '' ).strtolower($name).'_'.$this->lang.( $suffix ? '.'.strtolower($suffix) : '' );
54+ if ( ! file_exists($path) ){
55+ $path = $this->templateDir.'/'.( $dir ? strtolower($dir) . '/' : '' ).strtolower($name).'_'.$this->defaultLang.( $suffix ? '.'.strtolower($suffix) : '' );
56+ if ( ! file_exists($path) )
57+ return '';
58+ }
59+
60+ $fsize = filesize($path);
61+ if ($fsize <= 0) return '';
62+
63+ $fd = fopen($path, 'r');
64+ $contents = fread($fd, $fsize);
65+ fclose($fd);
66+ return $contents;
67+ }
68+
69+ function fill($template, $values, $default = null) {
70+ if( $default )
71+ return preg_replace($this->defalutPattern, 'isset($values["$1"]) ? ("$2" ? htmlspecialchars($values["$1"], ENT_QUOTES) : $values["$1"]) : $default', $template);
72+ if( $default === null )
73+ return preg_replace($this->defalutPattern, '("$2") ? htmlspecialchars($values["$1"], ENT_QUOTES) : $values["$1"]', $template);
74+ return preg_replace($this->defalutPattern, 'isset($values["$1"]) ? ("$2" ? htmlspecialchars($values["$1"], ENT_QUOTES) : $values["$1"]) : "{{$1}}" ', $template);
75+ }
76+}
--- /dev/null
+++ b/trunk/NP_ReCaptchaJP/sharedlibs/recaptchalib.php
@@ -0,0 +1,277 @@
1+<?php
2+/*
3+ * This is a PHP library that handles calling reCAPTCHA.
4+ * - Documentation and latest version
5+ * http://recaptcha.net/plugins/php/
6+ * - Get a reCAPTCHA API Key
7+ * http://recaptcha.net/api/getkey
8+ * - Discussion group
9+ * http://groups.google.com/group/recaptcha
10+ *
11+ * Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
12+ * AUTHORS:
13+ * Mike Crawford
14+ * Ben Maurer
15+ *
16+ * Permission is hereby granted, free of charge, to any person obtaining a copy
17+ * of this software and associated documentation files (the "Software"), to deal
18+ * in the Software without restriction, including without limitation the rights
19+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20+ * copies of the Software, and to permit persons to whom the Software is
21+ * furnished to do so, subject to the following conditions:
22+ *
23+ * The above copyright notice and this permission notice shall be included in
24+ * all copies or substantial portions of the Software.
25+ *
26+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32+ * THE SOFTWARE.
33+ */
34+
35+/**
36+ * The reCAPTCHA server URL's
37+ */
38+define("RECAPTCHA_API_SERVER", "http://api.recaptcha.net");
39+define("RECAPTCHA_API_SECURE_SERVER", "https://api-secure.recaptcha.net");
40+define("RECAPTCHA_VERIFY_SERVER", "api-verify.recaptcha.net");
41+
42+/**
43+ * Encodes the given data into a query string format
44+ * @param $data - array of string elements to be encoded
45+ * @return string - encoded request
46+ */
47+function _recaptcha_qsencode ($data) {
48+ $req = "";
49+ foreach ( $data as $key => $value )
50+ $req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
51+
52+ // Cut the last '&'
53+ $req=substr($req,0,strlen($req)-1);
54+ return $req;
55+}
56+
57+
58+
59+/**
60+ * Submits an HTTP POST to a reCAPTCHA server
61+ * @param string $host
62+ * @param string $path
63+ * @param array $data
64+ * @param int port
65+ * @return array response
66+ */
67+function _recaptcha_http_post($host, $path, $data, $port = 80) {
68+
69+ $req = _recaptcha_qsencode ($data);
70+
71+ $http_request = "POST $path HTTP/1.0\r\n";
72+ $http_request .= "Host: $host\r\n";
73+ $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
74+ $http_request .= "Content-Length: " . strlen($req) . "\r\n";
75+ $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
76+ $http_request .= "\r\n";
77+ $http_request .= $req;
78+
79+ $response = '';
80+ if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
81+ die ('Could not open socket');
82+ }
83+
84+ fwrite($fs, $http_request);
85+
86+ while ( !feof($fs) )
87+ $response .= fgets($fs, 1160); // One TCP-IP packet
88+ fclose($fs);
89+ $response = explode("\r\n\r\n", $response, 2);
90+
91+ return $response;
92+}
93+
94+
95+
96+/**
97+ * Gets the challenge HTML (javascript and non-javascript version).
98+ * This is called from the browser, and the resulting reCAPTCHA HTML widget
99+ * is embedded within the HTML form it was called from.
100+ * @param string $pubkey A public key for reCAPTCHA
101+ * @param string $error The error given by reCAPTCHA (optional, default is null)
102+ * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false)
103+
104+ * @return string - The HTML to be embedded in the user's form.
105+ */
106+function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
107+{
108+ if ($pubkey == null || $pubkey == '') {
109+ die ("To use reCAPTCHA you must get an API key from <a href='http://recaptcha.net/api/getkey'>http://recaptcha.net/api/getkey</a>");
110+ }
111+
112+ if ($use_ssl) {
113+ $server = RECAPTCHA_API_SECURE_SERVER;
114+ } else {
115+ $server = RECAPTCHA_API_SERVER;
116+ }
117+
118+ $errorpart = "";
119+ if ($error) {
120+ $errorpart = "&amp;error=" . $error;
121+ }
122+ return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script>
123+
124+ <noscript>
125+ <iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/>
126+ <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
127+ <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
128+ </noscript>';
129+}
130+
131+
132+
133+
134+/**
135+ * A ReCaptchaResponse is returned from recaptcha_check_answer()
136+ */
137+class ReCaptchaResponse {
138+ var $is_valid;
139+ var $error;
140+}
141+
142+
143+/**
144+ * Calls an HTTP POST function to verify if the user's guess was correct
145+ * @param string $privkey
146+ * @param string $remoteip
147+ * @param string $challenge
148+ * @param string $response
149+ * @param array $extra_params an array of extra variables to post to the server
150+ * @return ReCaptchaResponse
151+ */
152+function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
153+{
154+ if ($privkey == null || $privkey == '') {
155+ die ("To use reCAPTCHA you must get an API key from <a href='http://recaptcha.net/api/getkey'>http://recaptcha.net/api/getkey</a>");
156+ }
157+
158+ if ($remoteip == null || $remoteip == '') {
159+ die ("For security reasons, you must pass the remote ip to reCAPTCHA");
160+ }
161+
162+
163+
164+ //discard spam submissions
165+ if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
166+ $recaptcha_response = new ReCaptchaResponse();
167+ $recaptcha_response->is_valid = false;
168+ $recaptcha_response->error = 'incorrect-captcha-sol';
169+ return $recaptcha_response;
170+ }
171+
172+ $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/verify",
173+ array (
174+ 'privatekey' => $privkey,
175+ 'remoteip' => $remoteip,
176+ 'challenge' => $challenge,
177+ 'response' => $response
178+ ) + $extra_params
179+ );
180+
181+ $answers = explode ("\n", $response [1]);
182+ $recaptcha_response = new ReCaptchaResponse();
183+
184+ if (trim ($answers [0]) == 'true') {
185+ $recaptcha_response->is_valid = true;
186+ }
187+ else {
188+ $recaptcha_response->is_valid = false;
189+ $recaptcha_response->error = $answers [1];
190+ }
191+ return $recaptcha_response;
192+
193+}
194+
195+/**
196+ * gets a URL where the user can sign up for reCAPTCHA. If your application
197+ * has a configuration page where you enter a key, you should provide a link
198+ * using this function.
199+ * @param string $domain The domain where the page is hosted
200+ * @param string $appname The name of your application
201+ */
202+function recaptcha_get_signup_url ($domain = null, $appname = null) {
203+ return "http://recaptcha.net/api/getkey?" . _recaptcha_qsencode (array ('domain' => $domain, 'app' => $appname));
204+}
205+
206+function _recaptcha_aes_pad($val) {
207+ $block_size = 16;
208+ $numpad = $block_size - (strlen ($val) % $block_size);
209+ return str_pad($val, strlen ($val) + $numpad, chr($numpad));
210+}
211+
212+/* Mailhide related code */
213+
214+function _recaptcha_aes_encrypt($val,$ky) {
215+ if (! function_exists ("mcrypt_encrypt")) {
216+ die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
217+ }
218+ $mode=MCRYPT_MODE_CBC;
219+ $enc=MCRYPT_RIJNDAEL_128;
220+ $val=_recaptcha_aes_pad($val);
221+ return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
222+}
223+
224+
225+function _recaptcha_mailhide_urlbase64 ($x) {
226+ return strtr(base64_encode ($x), '+/', '-_');
227+}
228+
229+/* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
230+function recaptcha_mailhide_url($pubkey, $privkey, $email) {
231+ if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) {
232+ die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " .
233+ "you can do so at <a href='http://mailhide.recaptcha.net/apikey'>http://mailhide.recaptcha.net/apikey</a>");
234+ }
235+
236+
237+ $ky = pack('H*', $privkey);
238+ $cryptmail = _recaptcha_aes_encrypt ($email, $ky);
239+
240+ return "http://mailhide.recaptcha.net/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
241+}
242+
243+/**
244+ * gets the parts of the email to expose to the user.
245+ * eg, given johndoe@example,com return ["john", "example.com"].
246+ * the email is then displayed as john...@example.com
247+ */
248+function _recaptcha_mailhide_email_parts ($email) {
249+ $arr = preg_split("/@/", $email );
250+
251+ if (strlen ($arr[0]) <= 4) {
252+ $arr[0] = substr ($arr[0], 0, 1);
253+ } else if (strlen ($arr[0]) <= 6) {
254+ $arr[0] = substr ($arr[0], 0, 3);
255+ } else {
256+ $arr[0] = substr ($arr[0], 0, 4);
257+ }
258+ return $arr;
259+}
260+
261+/**
262+ * Gets html to display an email address given a public an private key.
263+ * to get a key, go to:
264+ *
265+ * http://mailhide.recaptcha.net/apikey
266+ */
267+function recaptcha_mailhide_html($pubkey, $privkey, $email) {
268+ $emailparts = _recaptcha_mailhide_email_parts ($email);
269+ $url = recaptcha_mailhide_url ($pubkey, $privkey, $email);
270+
271+ return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) .
272+ "' 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]);
273+
274+}
275+
276+
277+?>
--- /dev/null
+++ b/trunk/NP_ReCaptchaJP/sharedlibs/sharedlibs.php
@@ -0,0 +1,51 @@
1+<?php
2+// vim: tabstop=2:shiftwidth=2
3+
4+/**
5+ * sharedlibs.php ($Revision: 1.1 $)
6+ *
7+ * by hsur ( http://blog.cles.jp/np_cles )
8+ * $Id: sharedlibs.php,v 1.1 2008-05-03 09:39:48 hsur Exp $
9+*/
10+
11+/*
12+ * Copyright (C) 2006 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+if (!defined('NP_SHAREDLIBS_LOADED')) {
41+ if (!defined('PATH_SEPARATOR')) {
42+ if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
43+ define('PATH_SEPARATOR', ';');
44+ } else {
45+ define('PATH_SEPARATOR', ':');
46+ }
47+ }
48+ ini_set('include_path', dirname(__FILE__).PATH_SEPARATOR.ini_get('include_path'));
49+
50+ define('NP_SHAREDLIBS_LOADED', true);
51+}
Show on old repository browser