1. Tạo một thư mục tên helloworld dưới thư mục ./modules
2. Tạo một tập tin setup.php dưới thư mục vừa tạo
3. Xây dựng kịch bản xử lý quá trình cài đặt module:
- Tạo truy vấn, đăng ký module với hệ thống
- Tạo truy vấn xây dựng bảng `helloworld` trong CSDL
<?php
function _helloworld_install($action, $page = '') {
global $_SWIFT, $__LANG;
if ($action == "getpages") {
return "1";
}
else if ($action == "buildpage") {
$_SWIFT["query"]["create"]["helloworld"]="
CREATE TABLE ".TABLE_PREFIX."helloworld (
helloworld_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
helloworld_text VARCHAR(255) NOT NULL DEFAULT '',
PRIMARY KEY (helloworld_id)
);";
//Tell Esupport about the module.
$_SWIFT["query"]["insert"]["settings"][0]= "
INSERT INTO `".TABLE_PREFIX."settings`
(`section`, `vkey`, `data`)
VALUES('registeredmodules', '".MODULE_HELLOWORLD."', '1')";
}
}
?>4. Xây dựng kịch bản xử lý quá trình gỡ bỏ module:
<?php
function _helloworld_uninstall() {
global $_SWIFT;
$_SWIFT["query"]["drop"]["helloworld"]="DROP TABLE `".TABLE_PREFIX."helloworld;";
//Tell Esupport We are removing the module.
$_SWIFT["query"]["delete"]["settings"][0]= "
DELETE FROM `".TABLE_PREFIX."settings` WHERE `section` = 'registeredmodules' AND `vkey` = '".MODULE_HELLOWORLD."';";
}
?>5. Tìm trong tập tin config/config.php các dòng:
<?php
define("MODULE_PURCHASE", "purchase");
define("MODULE_SERVERS", "servers");
?>6. Thêm vào ngay sau 2 dòng trên đoạn mã:
<?php
define("MODULE_HELLOWORLD","helloworld");
?>7. Tìm trong tập tin config/config.php các dòng:
<?php
$_MODULES[MODULE_PURCHASE] =
dirname(__FILE__)."/../modules/purchase/purchase.php";
$_MODULES[MODULE_SERVERS] =
dirname(__FILE__)."/../modules/servers/purchase.php";
?>8. Thêm vào ngay sau 2 dòng trên đoạn mã:
<?php
$_MODULES[MODULE_MLS] =
dirname(__FILE__)."/../modules/helloworld/helloworld.php";
?>Đến bước này thì các module đã được đăng ký với hệ thống. Tuy nhiên, để module làm được cái gì đó, chúng ta phải viết hàm xử lý các sự kiện.
9. Tạo tập tin modules/helloworld/helloworld.php với nội dung như sau:
<?php
if (!defined("INSWIFT")) {
trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}
class helloworld {
/*
* đăng ký các thao tác với hệ thống
*/
function helloworld() {
global $_SWIFT, $events;
$events->registerEventModuleSWIFT(MODULE_HELLOWORLD, $this);
// Staff panel
$events->registerEvent(EVENT_STAFF, MODULE_HELLOWORLD, "hello1");
$events->registerEvent(EVENT_STAFF, MODULE_HELLOWORLD, "hello2");
$eventaction = $events->eventdata["eventaction"];
}
function _helloworld() {
}
/*
* các thao tác xử lý
*/
function _eventcallback($eventtype, $eventaction) {
// các biến toàn cục của hệ thống
global
$_SWIFT, $interface, $template,
$departments, $staffauth, $module, $grid, $xml,
$staff, $settings, $dbCore, $events,
$session, $loginshare, $cookie, $errormessage,
$infomessage, $permissions, $mimelist;
// bắt sự kiện 1
if ($eventtype == EVENT_STAFF && ($eventaction == "hello1")) {
require_once ("./modules/helloworld/hello1.php");
return true;
// bắt sự kiện 2
} else if ($eventtype == EVENT_STAFF && ($eventaction == "hello2")) {
require_once ("./modules/helloworld/hello2.php");
return true;
}
// không có sự kiện nào thích hợp
return false;
}
}
?>Đến đây, module của chúng ta đã biết cách xử lý 2 sự kiện. Bây giờ, chúng ta sẽ đi xây dựng kịch bản chi tiết cho 2 sự kiện đó.
10. Tạo tập tin modules/helloworld/hello1.php với nội dung
<?php
$template->loadLanguageSection("helloworld");
$interface->staffHeader("helloworld&gt; hello1", 0);
$interface->staffNavBar('<a href="index.php?_m=helloworld&_a=hello1"
title="hello1">hello1</a>', "", 0);
// printInfoBox($infomessage);
// printErrorBox($errormessage);
echo "Helloworld1!";
$template->assign("backurl", "index.php?_m=helloworld&_a=hello1");
$interface->staffFooter();
?>Đến bước này, khi chúng ta thực hiện yêu cầu ?_m=helloworld&_a=hello1, module sẽ gọi đoạn mã trên để thực hiện kịch bản mà chúng ta đã xây dựng.
Lặp lại từ đầu bước 10 để xây dựng kịch bản cho sự kiện hello2.
11. Mở tập tin locale/en-us/en-us.php
12. Tìm dòng
<?php
$_SWIFT["staffmenu"] = array (
?>13. Thêm vào cuối mảng này phần tử:
<?php
10 => array ('Rights', 90, MODULE_HELLOWORLD, 3, 'hw_entab'),
?>Đây là tab mới trong staff panel của chúng ta.
14. Tìm tiếp theo trong tập tin này dòng sau:
<?php
$_SWIFT["stafflinks"] = array (
?>15. Thêm vào cuối mảng này các phần tử:
<?php
10 => array (
0 => array ('Hello1', "index.php?_m=helloworld&_a=hello1", false, true),
1 => array ('Hello21', "index.php?_m=helloworld&_a=hello2", true, true),
2 => array ('Hello2', "index.php?_m=helloworld&_a=hello2", true, false),
),
?>Đây là các sub-tab items trong staff panel của chúng ta. Menu của chúng ta có mã số là 10, cho nên chúng ta phải thay đổi cấp trên của hello1 và hello2 trong đoạn mã
16. Tìm trong tập tin modules/helloworld/hello1.php đoạn mã sau:
<?php
$interface->staffHeader("helloworld&gt; hello1", 0);
$interface->staffNavBar('<a href="index.php?_m=helloworld&_a=hello1"
title="hello1">hello1</a>', "", 0);
?>Chú ý chuỗi: , 0);, thay thành , 10);. Lúc này, chúng ta cần xóa bộ đệm của hệ thống: thực hiện yêu cầu đến:
http://OurWebsite.com/staff/index.php?_ca=rebuildcache
Thoát ra và sau đó đăng nhập lại vào Staff Panel. (Nếu như tab của panel không có thay đổi gì, thử xóa bộ đệm của trình duyệt web).
Để tạo tab mới trong Admin panel, thực hiện tương tự như từ bước 11, nhưng SWIFT_AREA lúc này sẽ là SWIFT_ADMIN
<?php
if (SWIFT_AREA == SWIFT_ADMIN)
?>modules/core/admin_settings.php (cần thêm một số dòng dữ liệu vào CSDL).
17. Mở tập tin includes/widgets/widgets.php, ở đây, chúng ta tìm thấy tất cả các widgets và các quyền hạn ràng buộc của nó. Tiếp theo, chúng ta sẽ thêm vào một widget rất căn bản.
18. Tìm đoạn mã:
<?php
/**
* ###############################################
* !! DO NOT EDIT ANYTHING BELOW THIS POINT !!
* ###############################################
*/
?>19. Thêm vào phía trước nó đoạn mã sau:
<?php
// ======= HELLOWORLD =======
if ($module->isRegistered(MODULE_HELLOWORLD)) {
$_widgets[$index]["icon"] = $_SWIFT["themepath"]."helloworld.gif";
$_widgets[$index]["title"] = "Helloworld";
$_widgets[$index]["description"] = "Hello world!";
$_widgets[$index]["link"] = "index.php?_m=helloworld&_a=view";
$index++;
}
?>20. Tùy biến: đừng quên đặt vào thư mục theme tập tin helloworld.gif của bạn. Hay là tập tin nào khác cũng được, tùy theo khai báo widget của chúng ta:
<?php
$_widgets[$index]["icon"] = $_SWIFT["themepath"]."helloworld.gif";
?>21. Chúng ta có thể không gắn cứng tiêu đề và mô tả widget nhờ chức năng đa ngôn ngữ của hệ thống:
<?php
$_widgets[$index]["title"] = $_SWIFT["language"]["helloworld"];
$_widgets[$index]["description"] = $_SWIFT["language"]["desc_helloworld"];
?>Bây giờ, chúng ta phải xử lý sự kiện mà chúng ta đã gán trong liên kết ("index.php?_m=helloworld&_a=view")
22. Mở tập tin modules/helloword/helloworld.php
23. Trong hàm
<?php
function helloworld() {
?>Thêm vào sau các sự kiện trong Stafff panel đoạn mã sau:
<?php
// Support Center
$events->registerEvent(EVENT_CLIENT, MODULE_HELLOWORLD, "view");
?>24. Trong hàm
<?php
function _eventcallback($eventtype, $eventaction)
?>25. Thêm vào cuối các mệnh đề so sánh, mệnh đề của chúng ta:
<?php
else if ($eventtype == EVENT_CLIENT && ($eventaction == "view")) {
require_once ("./modules/helloworld/view.php");
return true;
}
?>26. Tạo tập tin modules/helloworld/view.php với nội dung sau:
<?php
if (!defined("INSWIFT")) {
trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}
echo $template->displayTemplate("header");
echo "Hello world";
$template->assign("backurl", "index.php");
echo $template->displayTemplate("footer");
?>Để có thêm các thông tin về các chức năng nâng cao về xử lý giao diện, xem qua các module đã xây dựng sẵn.
Comments
Xao qua!
"Hiện đang có 12 thành viên và 503 khách trực tuyến." Xạo qua!
hum, kha hay day
He nho cac anh cac chi, xin cac anh chi chi giao them, em moi 13 tuoi thui
Em da co bang A, B, C, TOEFL, TOEIC. (Dang ne day chu!)
Em mun trau doi kha nang noi tieng Anh cua minh
Rat mong cac anh chi chap nhan dua em nho xiu nay
Post new comment