การเขียน plugin เสริมความสามารถของ CB (Community Builder) ซึ่ง CB เป็น Component ของ Joomla ที่ได้รับความนิยมมาก
ก่อนอื่นต้องเกริ่นก่อนนะครับ บทความนี้ไม่ใช่บทความที่สอน สร้าง plugin ของ core ของ Joomlaสำหรับท่านที่ยังไม่รู้ จัก CB ดูได้ที่เว็บนี้เลยครับ http://www.joomlapolis.com
Plugin ของ Community Builder คืออะไร
มันคือส่วนเสริมความสามารถของ Community Builder ที่จะไเชื่อมกับระบบอื่นๆ หรือ เพิ่มความสามารถของตัวเอง โดยที่ Developer ไม่ต้องไปแก้ไขโค้ด ของโปรแกรม (เป็นแนวคิดในการเขียนโปรแกรมที่ดีมาก Core ของ Joomla เองก็มีระบบนี้ และเขียนได้ง่ายกว่า ผมเลยไม่ได้เขียนเป็นบทความไว้)
จะเขียน Plugin ของ Community Builder ต้องรู้อะไรบ้าง
1.ต้องรู้ว่า ระบบเปิดให้เราเสริมลงไปได้ตรงไหน บ้าง
ดูได้จาก โค้ด
$_PLUGINS->trigger( 'onLoginAuthentication',....
นี่คือรวม trigger
//Community Builder
onBeforeEmailUserForm
onAfterEmailUserForm
onBeforeUserProfileEditDisplay
onAfterUserProfileEditDisplay
onBeforeUserProfileRequest
onBeforeUserProfileDisplay
onAfterUserProfileDisplay
onBeforeDisplayUsersList
onLostPassForm
onBeforeLoginFormDisplay
onBeforeRegisterFormDisplay
onBeforeEmailUser
onBeforeUserAvatarUpdate
onAfterUserAvatarUpdate
onStartUsersList
onAfterUsersListFieldsSql
onBeforeUsersListBuildQuery
onBeforeUsersListQuery
onStartNewPassword
onBeforeUsernameReminder
onAfterUsernameReminder
onBeforeNewPassword
onNewPassword
onBeforeRegisterForm
onStartSaveUserRegistration
onAfterUserRegistrationMailsSent
onBeforeLogin
onLoginAuthentication
onDuringLogin
onBeforeFirstLogin
onDoLoginNow
onAfterLogin
onBeforeLogout
onDoLogoutNow
onAfterLogout
onBeforeUserConfirm
onAfterUserConfirm
onBeforeUserApproval
onAfterUserApproval
onBeforeUserApproval
onBeforeBackendUsersListBuildQuery
onAfterBackendUsersList
onBeforeUserBlocking
onBeforeSyncUser
onAfterSyncUser
onAfterCheckCbDb
onAfterCheckCbFieldsDb
onBeforeFixDb
onAfterFixDb
onBeforeFixFieldsDb
onBeforeUserActive
onUserActive
onBeforeDeleteUser
onAfterDeleteUser
onAfterTabsFetch
onPrepareMenus
onAfterEditATab
onAfterFieldsFetch
onBeforeAddConnection
onAfterAddConnection
onBeforeRemoveConnection
onAfterRemoveConnection
onBeforeDenyConnection
onAfterDenyConnection
onBeforeAcceptConnection
onAfterAcceptConnection
onFieldIcons
onLogChange
onBeforeUserUpdate
onBeforeNewUser
onBeforeUpdateUser
onBeforeUserRegistration
onSaveUserError
onAfterUserUpdate
onAfterNewUser
onAfterUpdateUser
onAfterUserRegistration
onBeforegetFieldRow
//Community Builder Captcha
onGetCaptchaHtmlElements
//Community Builder Subscriptions
onCPayUserStateChange
เช่น
1.mindphp.php สำหรับเก็บคำสั่งการทำงาน
2.mindphp.xml สำหรับเก็บโครงสร้างตัวติดตั้ง
3.index.html ไฟล์ว่างเปล่าไม่ต้องใส่โค้ดใดๆ
เสร็จแล้ว ก็ zip ไฟล์
3.ตัวอย่างรายละเอียดภายในไฟล์ mindphp.xml
<?xml version="1.0" encoding="UTF-8"?>
<cbinstall version="1.0" type="plugin" group="user">
<name>Acc Pal check User status</name>
<author>mindphp</author>
<creationDate>2009-09-28</creationDate>
<copyright>(C) 2005-2009 mindphp.com</copyright>
<license>http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU/GPL version 2</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>www.mindphp.com</authorUrl>
<version>1.0</version>
<description>Provides Check User Status</description>
<files>
<filename plugin="acc_check_status">acc_check_status.php</filename>
<filename>index.html</filename>
</files>
</cbinstall>
ประกาศโค้ดนี้ที่ต้นไฟล์
global $_PLUGINS;
$_PLUGINS->registerFunction( 'TRIGGER', 'FUNCTION', 'CLASS' );
รวมตัวอย่างโค้ด
if ( ! ( defined( '_VALID_CB' ) || defined( '_JEXEC' ) || defined( '_VALID_MOS' ) ) ) { die( 'Direct Access to this location is not allowed.' ); }
global $_PLUGINS;
$_PLUGINS->registerFunction( 'onAfterLogin', 'confirmLogin', 'getconfirmTab' );
class getconfirmTab extends cbTabHandler {
function confirmLogin( $user, $$loggedIn ) {
if ( loggedIn ) {
echo 'Welcome!' . $user->username;
}
}
}
ไฟล์ ตัวอย่างโหลดได้ที่บอร์ด เลยครับ