2011年3月8日火曜日

XOOPS Cube : ユーザー登録に本名を追加

XOOPS Cube のユーザー登録欄はコアで一番ハック需要があるソースです。今回は新規ユーザー登録時に本名を必須として入力してもらう場合のハック情報を記載します。
なお、ここに記載のハック情報のコアソースは、XOOPS Cube 2.1.8a の物です。

user/templates/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>
  <!-- by bluemooninc -->
  <tr>
    <td class="head"><{$smarty.const._MD_USER_LANG_NAME}></td>
    <td class="<{cycle values="odd,even"}>">
      <{xoops_input type=text name=name value=$actionForm->get('name') size=30 maxlength=60}>
    </td>
  </tr> 
 user/templates/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>
  <!-- by bluemooninc -->
  <tr>
    <td class="head"><{$smarty.const._MD_USER_LANG_NAME}></td>
    <td class="<{cycle values="odd,even"}>">
      <{$registForm->get('name')|xoops_escape}>
    </td>
  </tr>
user/forms/UserRegisterForm.class.php に本名を追加(14行目から記載)
    function prepare()
    {
        parent::prepare();
        //
        // Set form properties
        //
        $this->mFormProperties['uname'] =& new XCube_StringProperty('uname');
        $this->mFormProperties['name'] =& new XCube_StringProperty('name');        // by bluemooninc
        $this->mFormProperties['email'] =& new XCube_StringProperty('email');
        $this->mFormProperties['user_viewemail'] =& new XCube_BoolProperty('user_viewemail');
        $this->mFormProperties['url'] =& new XCube_StringProperty('url');
        $this->mFormProperties['timezone_offset'] =& new XCube_FloatProperty('timezone_offset');
        $this->mFormProperties['pass'] =& new XCube_StringProperty('pass');
        $this->mFormProperties['vpass'] =& new XCube_StringProperty('vpass');
        $this->mFormProperties['user_mailok'] =& new XCube_BoolProperty('user_mailok');
        $this->mFormProperties['agree'] =& new XCube_BoolProperty('agree');

        //
        // Set field properties
        //
        $this->mFieldProperties['uname'] =& new XCube_FieldProperty($this);
        $this->mFieldProperties['uname']->setDependsByArray(array('required', 'maxlength', 'minlength'));
        $this->mFieldProperties['uname']->addMessage('required', _MD_USER_ERROR_REQUIRED, _MD_USER_LANG_UNAME, '25');
        $this->mFieldProperties['uname']->addMessage('maxlength', _MD_USER_ERROR_MAXLENGTH, _MD_USER_LANG_UNAME, min(25,$this->mConfig['maxuname']));
        $this->mFieldProperties['uname']->addMessage('minlength', _MD_USER_ERROR_MINLENGTH, _MD_USER_LANG_UNAME, $this->mConfig['minuname']);
        $this->mFieldProperties['uname']->addVar('maxlength', min(25,$this->mConfig['maxuname']));
        $this->mFieldProperties['uname']->addVar('minlength', $this->mConfig['minuname']);

        // hack start by bluemooninc
        $this->mFieldProperties['name'] =& new XCube_FieldProperty($this);
        $this->mFieldProperties['name']->setDependsByArray(array('required', 'maxlength'));
        $this->mFieldProperties['name']->addMessage('required', _MD_USER_ERROR_REQUIRED, _MD_USER_LANG_NAME, '60');
        $this->mFieldProperties['name']->addMessage('maxlength', _MD_USER_ERROR_MAXLENGTH, _MD_USER_LANG_NAME, '60');
        $this->mFieldProperties['name']->addVar('maxlength', 60);   
        // hack end by bluemooninc

0 件のコメント:

コメントを投稿