Xoopsモジュール †更新日2012-12-18 (火) 10:35:24
ドメイン変更 †html/mainfile.php // XOOPS Virtual Path (URL) // Virtual path to your main XOOPS directory WITHOUT trailing slash // Example: define('XOOPS_URL', 'http://www2.data-map.net/~okada/xoops'); // define('XOOPS_URL', 'http://manabi.mie-chukyo-u.ac.jp'); define('XOOPS_URL', 'http://manabi.stock-cube.net'); ユーザ自身による新規登録および登録内容変更について項目変更および、カスタムテーブルを作成した場合の追加変更について。 XOOPSにない追加項目をユーザに編集させる †以下で「新規登録の項目追加 」場合、通常の「ユーザメニュー」の「アカウント情報」および「アカウント編集」では追加項目の表示編集ができないため、そのパッチを検討する。 アカウント情報 †3箇所修正 function XoopsUser($id = null) { $this->initVar('uid', XOBJ_DTYPE_INT, null, false); // Edit by JE2ISM $this->initVar('ism_user_tel', XOBJ_DTYPE_TXTBOX, null, true, 30); $this->initVar('ism_user_etc', XOBJ_DTYPE_TXTBOX, null, false, 120); (略) function last_login() { return $this->getVar("last_login"); } //Edit by JE2ISM function ism_user_tel($format="S") { return $this->getVar("ism_user_tel", $format); } function ism_user_etc($format="S") { return $this->getVar("ism_user_etc", $format); } /** * This class has avatar in uploads directory. * @return bool */ (略) * * @param int $id UID of the user * @return mixed reference to the {@link XoopsUser} object, FALSE if failed */ function &get($id) { $ret = false; if (intval($id) > 0) { $sql = 'SELECT * FROM '.$this->db->prefix('users').' WHERE uid='.$id; // Edit By JE2ISM $ism_sql = 'SELECT * FROM ism_users WHERE uid= '.$id; // -------------- if ($result = $this->db->query($sql)) { $numrows = $this->db->getRowsNum($result); if ($numrows == 1) { $user =& new XoopsUser(); $user->assignVars($this->db->fetchArray($result)); // Edit By JE2ISM (User Info) if ($result2 = $this->db->query($ism_sql)){ $numrows2 = $this->db->getRowsNum($result2); if ($numrows2 == 1) { $user->assignVars($this->db->fetchArray($result2)); } } //---------------------- $ret =& $user; } } } return $ret; } テンプレートの変更 互換レンダーシステム »» テンプレートファイル管理 »» テンプレートファイル一覧 user_userinfo.html <!-- Edit By JE2ISM --> <tr valign="top"> <td class="head"><{$smarty.const._ISM_MD_USER_LANG_USER_TEL}></td> <td class="<{cycle values='odd,even'}>"><{$thisUser->getShow('ism_user_tel')}></td> </tr> <tr valign="top"> <td class="head"><{$smarty.const._ISM_MD_USER_LANG_USER_ETC}></td> <td class="<{cycle values='odd,even'}>"><{$thisUser->getShow('ism_user_etc')}></td> </tr> <!-- <tr valign="top"> <td class="head"><{$smarty.const._MD_USER_LANG_USER_ICQ}></td> <td class="<{cycle values='odd,even'}>"><{$thisUser->getShow('user_icq')}></td> </tr> <tr valign="top"> <td class="head"><{$smarty.const._MD_USER_LANG_USER_AIM}></td> <td class="<{cycle values='odd,even'}>"><{$thisUser->getShow('user_aim')}></td> </tr> --> アカウント編集 †picoに読み取らせる2つのファイルを作成 更新内容を入力する画面。更新項目(本名、Emailの公開非公開、パスワードと追加DB上の電話と備考)でテーブル名は「ism_users」。 extend_users_update.php <?php // ユーザ用アカウント更新ページ // // (Ver 0.001) 2008/10/31 // // 別DBにユーザ登録内容を追加した場合XOOPSにあるedituser.phpでは変更できないので // このページで変更する項目をもとテーブル(xoops_users)とあわせて変更を行うための // 項目入力ページ // // $pico_id はDBへの書きこみを行う次のpicoのページpicoのcontent idをpico上に 指定 // // DE JE2ISM // global $xoopsUser; //ブロックの時に必要 $uname = ''; $uid = 0; if(!empty($xoopsUser)) { // ユーザがログインしている // ユーザ名の取得 $uname = $xoopsUser->getVar('uname'); $name = $xoopsUser->getVar('name'); $email = $xoopsUser->getVar('email'); $user_viewemail = $xoopsUser->getVar('user_viewemail'); // ユーザIDの取得 $uid = $xoopsUser->getVar('uid'); // echo "ユーザ $uname <br>"; // echo "ID $uid <br>"; // 追加作製テーブルからデータを抽出 mysql_query("set names ujis"); $sql = "SELECT * FROM ism_users where uid = '$uid'"; $rst = mysql_query($sql); $col = mysql_fetch_array($rst); $ism_user_tel = $col["ism_user_tel"]; $ism_user_etc = $col["ism_user_etc"]; mysql_free_result($rst); $act_path = XOOPS_URL . "/modules/pico/index.php?content_id=" . $pico_id; }else{ echo "Loginしていません <Br>"; exit; } echo "<form action=\"" . $act_path . "\" method=\"post\">"; echo "<div id=\"content\"><div> \n"; echo "<a href=\"" . XOOPS_URL . "/userinfo.php?uid=" . $uid ."\">プロフィール</a> \n"; echo " <span style=\"font-weight:bold;\">»»</span> プロフィールの編集 </div> \n"; echo "<table class=\"outer\" cellspacing=\"1\" width=\"100%\"> \n"; echo "<tr> \n"; echo "<th colspan=\"2\">プロフィールの編集</th> \n"; echo "</tr> \n"; echo "<tr> \n"; echo "<td class=\"head\">ユーザ名</td> \n"; echo "<td class=\"odd\">" . $uname . "</td> \n"; echo "</tr> \n"; echo "<tr> \n"; echo "<td class=\"head\">本名</td> \n"; echo "<td class=\"even\"> \n"; echo " <input name=\"name\" id=\"legacy_xoopsform_name\" type=\"text\" size=\"30\" maxlength=\"60\" value=\"" . $name . "\" /> \n"; echo "</td> \n"; echo "</tr> \n"; echo "<tr> \n"; echo "<td class=\"head\">メールアドレス</td> \n"; echo "<td class=\"odd\"> \n"; echo $email . "<br /> \n"; echo "<label><input name=\"user_viewemail\"id=\"legacy_xoopsform_user_viewemail_1\" type=\"checkbox\" value=\"". $user_viewemail ."\" />このメールアドレスを公開する</label>"; echo "</td> \n"; echo "</tr> \n"; echo "<tr> \n"; echo "<td class=\"head\">電話番号(半角)</td> \n"; echo "<td class=\"even\"> \n"; echo "<input name=\"ism_user_tel\" id=\"legacy_xoopsform_ism_user_tel\" type=\"text\" size=\"20\" maxlength=\"30\" value=\"" . $ism_user_tel . "\" />\n"; echo "</td> \n"; echo "</tr> \n"; echo "<tr> \n"; echo "<td class=\"head\">備考</td> \n"; echo "<td class=\"odd\"> \n"; echo "<input name=\"ism_user_etc\" id=\"legacy_xoopsform_ism_user_etc\" type=\"text\"size=\"60\" maxlength=\"120\" value=\"" . $ism_user_etc ."\" /> \n"; echo "</td> \n"; echo "</tr> \n"; echo "<td class=\"head\">パスワード<br /> \n"; echo "(パスワードを変更する場合のみ記入してください)</td> \n"; echo "<td class=\"even\"> \n"; echo "<input name=\"pass\" id=\"legacy_xoopsform_pass\" type=\"password\" size=\"10\"maxlength=\"32\" value=\"\" /> \n"; echo "<input name=\"vpass\" id=\"legacy_xoopsform_vpass\" type=\"password\" size=\"10\" maxlength=\"32\" value=\"\" / >\n"; echo "</td> \n"; echo "</tr> \n"; echo "<tr> \n"; echo "<td class=\"head\"> </td> \n"; echo "<td class=\"even\"> \n"; echo "<input type=\"submit\" value=\"変更を保存\" /> \n"; echo "</td> \n"; echo "</tr> \n"; echo "</table> \n"; echo "</form> \n"; ?> DBへの書き込みページ extend_users_update2.php <?php // ユーザ用アカウント更新ページ2 // // (Ver 0.001) 2008/10/31 // // 別DBにユーザ登録内容を追加した場合XOOPSにあるedituser.phpでは変更できないので // このページで変更する項目をもとテーブル(xoops_users)とあわせて変更を行うための // 項目を実際にDBに書き込みその後アカウント情報ページに移動するページ // // // // DE JE2ISM // function disp_err($msg){ // $url_ref = XOOPS_URL . "/modules/pico/index.php?content_id= " . $pico_id; $url_ref = $_SERVER['HTTP_REFERER']; echo $msg . "<br> \n"; echo " <a href= \"" . $url_ref ."\"> 戻る </a> <br> \n"; exit; } // main global $xoopsUser; //ブロックの時に必要 include("discharge.php"); $uname = ''; $uid = 0; if(!empty($xoopsUser)) { // ユーザがログインしている // ユーザIDの取得 $uid = $xoopsUser->getVar('uid'); $name = discharge($_POST['name']); // $uname = discharge($_POST['uname']); // $email = discharge($_POST['email']); if(isset($_POST['user_viewemail'])){ $user_viewemail = "1"; } else { $user_viewemail = "0"; } $pass = discharge($_POST['pass']); $vpass = discharge($_POST['vpass']); if($pass != $vpass){ $msg = "入力パスワードと確認用パスワードが一致しません"; disp_err( $msg); } $ism_user_tel = discharge($_POST['ism_user_tel']); if( !ereg("([0-9]+)-([0-9]+)-([0-9]+)" ,$ism_user_tel)){ $msg = $ism_user_tel . " 電話番号の書式が不正です (xxxx-xx-xxxx)"; disp_err( $msg); } if ($ism_user_tel ==""){ $msg = "電話番号は必ず入力してください"; disp_err( $msg); } $ism_user_etc = discharge($_POST['ism_user_etc']); $jump_url = XOOPS_URL . "/userinfo.php?uid=" . $uid; if ($pass =="" ){ $ism_sql=sprintf("UPDATE xoops_users SET name = '%s', user_viewemail = '%s ' WHERE uid = %u", $name, $user_viewemail, $uid); }else{ $pass = md5($pass); $ism_sql=sprintf("UPDATE xoops_users SET name = '%s', user_viewemail = '%s', pass = '%s' WHERE uid = %u", $name, $user_viewemail, $pass, $uid); } // echo "ISM: $ism_sql <br>"; if (!mysql_query($ism_sql)) { print "ユーザ情報(xoopsテーブル)の更新に失敗しました!<BR><BR>"; exit; } $ism_sql=sprintf("UPDATE ism_users SET ism_user_tel = '%s', ism_user_etc = '%s' WHERE uid = %u", $ism_user_tel, $ism_user_etc, $uid); if (!mysql_query($ism_sql)) { print "ユーザ情報(追加テーブル)の更新に失敗しました!<BR><BR>"; exit; } //アカウント情報に強制移動 echo "<SCRIPT type=\"text/JavaScript\">\n"; echo "window.location.replace(\"" . $jump_url ."\");\n"; echo "</SCRIPT>\n"; }else{ echo "Loginしていません <Br>"; exit; } ?> その後、ユーザメニューのアカウント編集でpicoのページ飛べる用に以下のテンプレートを修正 互換レンダーシステム »» テンプレートファイル管理 »» テンプレートファイル一覧 複数のページあるので注意深く探すこと legacy_block_usermenu.html <table cellspacing="0"> <tr> <td id="usermenu"> <a class="menuTop" href="<{$xoops_url}>/user.php"><{$smarty.const._MB_LEGACY_VACNT}></a> <!-- Edit by JE2ISM --> <!-- <a href="<{$xoops_url}>/edituser.php"><{$smarty.const._MB_LEGACY_EACNT}></a> --> <a href="<{$xoops_url}>/modules/pico/index.php?content_id=53"><{$smarty.const._MB_LEGACY_EACNT}></a> XOOPSにない新規登録の項目追加 †新規登録の項目に無い項目を別テーブルを定義してそこにuidをキーにしてユーザの新規登録画面で書き込む。 新規登録の項目変更と同様にXOOPSの「互換レンダーシステム »» テンプレートファイル管理 」からuser_register_form.html とuser_register_confirm.html を変更する。 user_register_form.html <tr> <td class="head"><{$smarty.const._ISM_MD_USER_LANG_USER_TEL}></td> <td class="<{cycle values="odd,even"}>"><{xoops_input size=20 maxlength=30 name=ism_user_tel value=$actionForm->get('ism_user_tel')}></td> </tr> <tr> <td class="head"><{$smarty.const._ISM_MD_USER_LANG_USER_ETC}></td> <td class="<{cycle values="odd,even"}>"><{xoops_input size=60 maxlength=120 name=ism_user_etc value=$actionForm->get('ism_user_etc')}></td> </tr> user_register_confirm.html <tr> <td class="head"><{$smarty.const._ISM_MD_USER_LANG_USER_TEL}></td> <td class="<{cycle values="odd,even"}>"> <{$registForm->get('ism_user_tel')|xoops_escape}> </td> </tr> <tr> <td class="head"><{$smarty.const._ISM_MD_USER_LANG_USER_ETC}></td> <td class="<{cycle values="odd,even"}>"> <{$registForm->get('ism_user_etc')|xoops_escape}> </td> </tr> 同様に、modules/user/language/japanese/main.phpに表示するキーワードを追加 define('_MD_USER_MESSAGE_YOURREGISTERED2', "登録が完了しました。サイト管理者 がアカウントを承認するまでお待ちください。承認完了時にはメールにてお知らせし ます。"); //Edit by JE2ISM define('_ISM_MD_USER_LANG_USER_TEL', "電話番号(半角)"); define('_ISM_MD_USER_LANG_USER_ETC', "備考"); ?> modules/user/forms/UserRegisterEditForm.class.php function prepare() { parent::prepare(); // // Set form properties // (略) //Edit By JE2ISM $this->mFormProperties['ism_user_tel'] =& new XCube_StringProperty('ism_user_tel'); $this->mFormProperties['ism_user_etc'] =& new XCube_StringProperty('ism_user_etc'); (略) // // Set field properties // (略) //Edit By JE2ISM $this->mFieldProperties['ism_user_tel'] =& new XCube_FieldProperty($this); $this->mFieldProperties['ism_user_tel']->setDependsByArray(array('required', 'maxlength', 'mask')); $this->mFieldProperties['ism_user_tel']- >addMessage('maxlength', _MD_USER_ERROR_MAXLENGTH, _ISM_MD_USER_LANG_USER_TEL, '30'); $this->mFieldProperties['ism_user_tel']->addMessage('required', _MD_USER_ERROR_REQUIRED, _ISM_MD_USER_LANG_USER_TEL, '30'); $this->mFieldProperties['ism_user_tel']->addVar('maxlength', 30); $this->mFieldProperties['ism_user_tel']->addMessage('mask', _MD_USER_ERROR_INJURY, _ISM_MD_USER_LANG_USER_TEL); $this->mFieldProperties['ism_user_tel']->addVar('mask', "[\d+-\d+-\d+]"); $this->mFieldProperties['ism_user_etc'] =& new XCube_FieldProperty($this); $this->mFieldProperties['ism_user_etc']- >setDependsByArray(array('maxlength')); $this->mFieldProperties['ism_user_etc']- >addMessage('maxlength', _MD_USER_ERROR_MAXLENGTH, _ISM_MD_USER_LANG_USER_ETC, '30'); $this->mFieldProperties['ism_user_etc']->addVar('maxlength', 120); (略) function update(&$obj) { (略) // Edit by JE2ISM $obj->set('ism_user_tel', $this->get('ism_user_tel')); $obj->set('ism_user_etc', $this->get('ism_user_etc')); エラーメッセージ関係(正規表現) addMessage core/XCube_ActionForm.class.phpに以下のようにあるのでaddMessageの引数は2つでもよいようだ。maxlengthのような場合は何文字か値が第三引数に必要だがrequiredやmaskは必要ないみたい。でももとのXOOPSのファイルは引数を3ついれている。? XCube_ActionForm.class.php * It's possible to add 3 or greater parameters. * These additional parameters are used by XCube_Utils::formatString(). * \code * $field->addMessage('required', "{0:ucFirst} is requred.", "name"); * \endcode * This feature is helpful for automatic ActionForm generators. */ function addMessage($name, $message) { if (func_num_args() >= 2) { $args = func_get_args(); $this->mMessages[$args[0]]['message'] = $args[1]; for ($i = 0; isset($args[$i + 2]); $i++) { $this->mMessages[$args[0]]['args'][$i] = $args[$i + 2]; } } } kernel/user.phpに実際のSQLを発行するルーチンを追加 kernel/user.php function XoopsUser($id = null) { // Edit by JE2ISM $this->initVar('ism_user_tel', XOBJ_DTYPE_TXTBOX, null, false, 30); $this->initVar('ism_user_etc', XOBJ_DTYPE_TXTBOX, null, false, 120); (略) //Edit by JE2ISM function ism_user_tel($format="S") { return $this->getVar("ism_user_tel", $format); } function ism_user_etc($format="S") { return $this->getVar("ism_user_etc", $format); } /** * This class has avatar in uploads directory. * @return bool */ (略) /** * insert a new user in the database * * @param object $user reference to the {@link XoopsUser} object * @param bool $force * @return bool FALSE if failed, TRUE if already present and unchanged or successful */ (略) if (false != $force) { $result = $this->db->queryF($sql); } else { $result = $this->db->query($sql); } if (!$result) { return false; }else{ // Edit By JE2ISM if ($user->isNew()) { include XOOPS_ROOT_PATH.'/ism_page/extend_php/extend_users.php'; } } //------------------- if (empty($uid)) { $uid = $this->db->getInsertId(); } extend_users.phpで追加のSQLを記入 extend_users.php <?php $ism_sql= "SELECT MAX(uid) FROM xoops_users"; $rst = mysql_query($ism_sql); $col = mysql_fetch_array($rst); $ism_uid = $col["MAX(uid)"]; $ism_sql=sprintf("INSERT INTO ism_users (uid, ism_user_tel, ism_user_etc) VALUES (%u, %s, %s)",$ism_uid, $this->db->quoteString ($ism_user_tel), $this->db->quoteString($ism_user_etc)); echo "ISM: $ism_sql <br>"; $result = $this->db->query($ism_sql); if (!$result) { return false; } ?> $this->db->quoteString: /** * Returns escaped string text with single quotes around it to be safely stored in database * * @param string $str unescaped string text * @return string escaped string text with single quotes around */ function quoteString($str) { $str = "'".str_replace('\\"', '"', addslashes($str))."'"; return $str; } が定義されていてaddslashes関数で データベースへの問い合わせなどに際してクォートされるべき 文字の前にバックスラッシュを挿入した文字列を返します。クォート されるべき文字とは、シングルクォート('), ダブルクォート("),バックスラッシュ (\) ,NUL (NULL バイト) です。 その後\"->"にして'で囲む。TELは-が入るのでquoteStringがないと計算されてしまうようだ。 新規登録の項目変更 †ユーザ自身が新規ユーザ登録するときの内容を追加変更する Xoopsの左の管理者メニューから
互換レンダーシステム »» テンプレート管理 »» テンプレートセット一覧 「テンプレート」から「ユーザモジュール(16)」を選択 user_register_form.html とuser_register_confirm.html を変更する user_register_form.htmlは新規登録画面を表示している パラメータはname,user_fromはテーブルxoops_usersから確認する。 user_register_form.html <tr> <td class="head"><{$smarty.const._MD_USER_LANG_NICKNAME}></td> <td class="<{cycle values="odd,even"}>"><{xoops_input maxlength=25 name=uname value=$actionForm->get('uname')}></td> </tr> <!-- Edit By JE2ISM --> <!--以下を本名と居住地を追加 --> <tr> <td class="head"><{$smarty.const._MD_USER_LANG_NAME}></td> <td class="<{cycle values="odd,even"}>"><{xoops_input size=40 maxlength=60 name=name value=$actionForm->get('name')}></td> </tr> <tr> <td class="head"><{$smarty.const._MD_USER_LANG_USER_FROM}></td> <td class="<{cycle values="odd,even"}>"><{xoops_input size=60 maxlength=100 name=user_from value=$actionForm->get('user_from')}></td> </tr> <!-- ============ --> (略) <!-- 以下はURLを削除 --> <!-- <tr> <td class="head"><{$smarty.const._MD_USER_LANG_WEBSITE}></td> <td class="<{* cycle values="odd,even" *}>"><{xoops_input name=url size=30 maxlength=100 value=$actionForm->get('url')}></td> </tr> --> class="<{* cycle values="odd,even" *}>"は奇数、偶数でバックの色を変えているのでSmartyでも<{* *}>でコメントアウトしておく。 user_register_confirm.html は新規登録の確認画面なので確認画面として表示したい内容に変更 user_register_confirm.html <tr> <td class="head"><{$smarty.const._MD_USER_LANG_NICKNAME}></td> <td class="<{cycle values="odd,even"}>"> <{$registForm->get('uname')|xoops_escape}> </td> </tr> <!-- 以下を追加 --> <!-- Edit by JE2ISM --> <tr> <td class="head"><{$smarty.const._MD_USER_LANG_NAME}></td> <td class="<{cycle values="odd,even"}>"> <{$registForm->get('name')|xoops_escape}> </td> </tr> <tr> <td class="head"><{$smarty.const._MD_USER_LANG_USER_FROM}></td> <td class="<{cycle values="odd,even"}>"> <{$registForm->get('user_from')|xoops_escape}> </td> </tr> ソースの変更 †modules/user/forms/UserRegisterEditForm.class.phpはデータベースに登録および入力チェック UserRegisterEditForm.class.php function prepare() { parent::prepare(); // // Set form properties // $this->mFormProperties['uname'] =& new XCube_StringProperty('uname'); //Edit By JE2ISM $this->mFormProperties['name'] =& new XCube_StringProperty('name'); $this->mFormProperties['user_from'] =& new XCube_StringProperty('user_from'); //------------ (略) // // Set field properties // // Edit by JE2ISM $this->mFieldProperties['name'] =& new XCube_FieldProperty($this); //内容をチェックするプロパティを設定。 //required:必須、minlength/maxlength:最大最小桁数、 //max/min:最大最小値 、email:メールアドレス、intrange:数値範囲、 //mask:正規表現、extension:ファイルの拡張子、maxfilesize:最大ファイルサイズ //を意味する。 //正規表現はaddVar('mask', "[\d+-\d+-\d+]")のように"[ ]"でくくるようだ。 //この例は0120-100-100のようなTEL $this->mFieldProperties['name']->setDependsByArray(array('required', 'maxlength')); //maxlength違反したときのメッセージの指定 $this->mFieldProperties['name']->addMessage('maxlength', _MD_USER_ERROR_MAXLENGTH, _MD_USER_LANG_NAME, '60'); $this->mFieldProperties['name']->addMessage('required', _MD_USER_ERROR_REQUIRED, _MD_USER_LANG_NAME, '60'); //maxlengthの値の指定 $this->mFieldProperties['name']->addVar('maxlength', 60); //居住地のチェック $this->mFieldProperties['user_from'] =& new XCube_FieldProperty($this); $this->mFieldProperties['user_from']->setDependsByArray(array('required','maxlength')); $this->mFieldProperties['user_from']->addMessage('maxlength', _MD_USER_ERROR_MAXLENGTH, _MD_USER_LANG_USER_FROM, '100'); $this->mFieldProperties['user_from']->addMessage('required', _MD_USER_ERROR_REQUIRED, _MD_USER_LANG_USER_FROM, '100'); $this->mFieldProperties['user_from']->addVar('maxlength', 100); //------------------ (略) //DBへの登録 function update(&$obj) { // Edit by JE2ISM $obj->set('name', $this->get('name')); $obj->set('user_from', $this->get('user_from')); //------------------ 参考ページ †http://xoopscube.jp/modules/forum/index.php/node/5057 |