Discuz! X5.0 开发技术文档 新增插件接口
鏂板绯荤粺鍑芥暟DISCUZ_PLUGIN()
X5.0 涓柊澧炰簡 DISCUZ_PLUGIN() 鍑芥暟锛屼唬鏇跨被浼尖/source/plugin/xxx鈥濈洰褰曠殑鍐欐硶锛屼緥濡傦細
- require_once DISCUZ_PLUGIN('xxx').'/index.php';
鎻愮ず锛氬鏋滄偍鐨勬彃浠惰鍚屾椂鍏煎 Discuz!岬 鎮ㄥ繀椤讳娇鐢ㄦ鍑芥暟锛屼絾鏄紝娑夊強鍓嶇璋冪敤鐨勮矾寰勫啓娉曟槸 URI 鐨勪竴閮ㄥ垎锛岃岄潪鍚庡彴鐩綍鏂囦欢璋冪敤锛屾棤闇淇敼銆
DISCUZ_TEMPLATE()X5.0 涓柊澧炰簡 DISCUZ_TEMPLATE() 鍑芥暟锛屼唬鏇跨被浼尖/template/xxx鈥濈洰褰曠殑鍐欐硶锛屼緥濡傦細
- $f = DISCUZ_TEMPLATE('xxx').'/data.htm';
鎻愮ず锛氬鏋滄偍鐨勬彃浠惰鍚屾椂鍏煎 Discuz!岬 鎮ㄥ繀椤讳娇鐢ㄦ鍑芥暟锛屼絾鏄紝娑夊強鍓嶇璋冪敤鐨勮矾寰勫啓娉曟槸 URI 鐨勪竴閮ㄥ垎锛岃岄潪鍚庡彴鐩綍鏂囦欢璋冪敤锛屾棤闇淇敼銆
鏂板绯荤粺甯搁噺DISCUZ_DATAX5.0 涓柊澧炰簡 DISCUZ_DATA 甯搁噺锛屼唬鏇跨被浼尖/data鈥濈洰褰曠殑鍐欐硶锛屼緥濡傦細
- $lock = DISCUZ_DATA.'cache/data.php';
鎻愮ず锛氬鏋滄偍鐨勬彃浠惰鍚屾椂鍏煎 Discuz!岬 鎮ㄥ繀椤讳娇鐢ㄦ鍑芥暟銆傜敱浜 Discuz!岬 涓墍鏈夋案涔呮ф枃浠堕兘浼氬瓨鍏ュ璞″瓨鍌紝鍥犳 DISCUZ_DATA 鐩綍绂佹鍐欏叆姘镐箙鏂囦欢锛屽惁鍒欏鏍稿憳鏈夋潈灏嗗簲鐢ㄦ墦鍥炪
DISCUZ_ROOT_STATIC瀵逛簬 Discuz!岬傦紝鐢变簬 /data 鐩綍绂佹鍐欏叆锛屾偍鍙互鎶婃案涔呮枃浠跺啓鍏ュ埌姝ょ洰褰曚腑锛屽畠鏈変互涓嬬壒鎬э細
- 姝ょ洰褰曚笌 DISCUZ_ROOT 鎰忎箟鐩稿悓锛屼絾鍙湁瀛樻斁鐨勯潤鎬佹枃浠讹紙md銆乼xt銆乯s銆乧ss銆乯son銆亁ml銆佸浘鐗囩瓑锛夊彲瀵瑰灞曠ず锛
- 濡備繚瀛樼殑鏂囦欢鍜屽疄闄呬骇鍝佹枃浠跺強璺緞鐩稿悓锛屼笉浼氫骇鐢熻鐩栨晥鏋滐紝涔熶笉浼氬澶栧睍绀猴紱
- 姝ょ洰褰曞崰鐢ㄧ殑绌洪棿灏嗚绠楀埌 Discuz!岬 鐢ㄦ埛鐨勫钩鍙板瓨鍌ㄤ腑锛
鎻愮ず锛氭甯搁噺鍙拡瀵 Discuz!岬 鏈夊疄闄呬綔鐢紝X5.0 寮婧愮増姝ゅ父閲忎笌 DISCUZ_ROOT 鐩哥瓑銆
澶氳瑷Discuz!岬 鍘熺敓鏀寔澶氳瑷鍐呮牳锛屾偍鍙渶鑷畾涔夊璇█ key 骞惰缃 key 瀵瑰簲鐨勮瑷鍖呮枃浠惰矾寰勫嵆鍙
璁剧疆鑷畾涔夎瑷- i18n('set', 'mylang', DISCUZ_ROOT.'./i18n/en');
璁剧疆澶氳瑷 mylang 鐨勮瑷鍖呮枃浠惰矾寰勪负 DISCUZ_ROOT.鈥/i18n/en鈥 鐩綍锛屾敮鎸佹彃浠惰矾寰
璇诲彇璁剧疆鐨勮嚜瀹氫箟璇█鍒楄〃- i18n('get');
鎶婅缃殑璇█ key 璧嬪肩粰 $_G[鈥榗ookie鈥橾[鈥榠18n鈥橾 鍗冲彲瀹炴椂鍒囨崲璇█
鍏朵粬绗笁鏂规彃浠惰嫢瑕佸吋瀹 i18n 瀵瑰簲鐨勮瑷 key锛屽弬鑰冩鑼冧緥 https://gitee.com/Discuz/DiscuzXPluginSample/tree/master/sample/i18n/mylang
鑷畾涔夊悗鍙拌彍鍗杩欐槸 Discuz!岬 涓殑鏂板鍐呭锛屾彃浠舵棤闇娣诲姞 menu 鎵╁睍锛屽嵆鍙疄鐜拌彍鍗曠殑娣诲姞涓庡垹闄
鎮ㄦ墍娣诲姞鐨勮彍鍗曡鍔″繀鍦ㄥ嵏杞芥彃浠跺悗娓呯悊瀹屾瘯
鍑嗗宸ヤ綔濡傛灉鍦ㄩ潪瀹夎銆佸嵏杞借剼鏈腑浣跨敤锛屾渶濂芥槸鍒ゆ柇涓嬫柟娉曟槸鍚﹀瓨鍦
绀轰緥锛
绀轰緥锛
- if(!function_exists('set_admin_menu')){
- include_once libfile('function/plugin');
- }
瀹屾暣绀轰緥锛
- if(!function_exists('set_admin_menu')){
- include_once libfile('function/plugin');
- }
- $menus = array(
- array('渚ц竟鑿滃崟1','plugins?id=1'),
- array('渚ц竟鑿滃崟2','plugins?id=2'),
- );
- set_admin_menu('椤堕儴鑿滃崟鍚嶇О', $menus);
瀹屾暣绀轰緥锛
- if(!function_exists('remove_admin_menu')){
- include_once libfile('function/plugin');
- }
- remove_admin_menu('椤堕儴鑿滃崟鍚嶇О');//鍗曠嫭鍒犻櫎
- remove_admin_menu(array('椤堕儴鑿滃崟鍚嶇О1','椤堕儴鑿滃崟鍚嶇О2'));//鎵归噺鍒犻櫎
杩欐槸 Discuz!岬 涓殑鏂板鍐呭锛屽紑鍙戣呭彲鐩存帴娣诲姞涓涓钩鍙扮鐞嗕腑蹇冿紝鍦ㄨ繖閲岋紝鎮ㄥ彲浠ュ畬鍏ㄨ璁℃暣涓悗鍙扮殑鑿滃崟浠ュ強鐣岄潰銆傚悓鏃跺湪鈥滅珯闀库->鈥滃骞冲彴绠$悊鈥 绔欓暱杩樿兘鑷璋冩暣銆
XML 鏍煎紡瑙勮寖杩欐槸骞冲彴閰嶇疆 XML 鏂囦欢鐨勬ā鏉匡細
- <?xml version="1.0" encoding="ISO-8859-1"?>
- <root>
- <name><![CDATA[鏂板钩鍙癩]></name>
- <title><![CDATA[鏂板钩鍙癩]></title>
- <framecss><![CDATA[xxx.css]]></framecss>
- <pagecss><![CDATA[ccc.css]]></pagecss>
- <logo><![CDATA[<a class="logo"><img src="static/image/admincp/logo.svg"></a>]]></logo>
- <navbar><![CDATA[<form></form>]]></navbar>
- <menu>
- <menuId>涓昏彍鍗1</menuId>
- <sub>
- <subId>action_operation_do1</subId>
- <title>瀛愯彍鍗1</title>
- </sub>
- <sub>
- <subId>action_operation_do2</subId>
- <title>瀛愯彍鍗2</title>
- </sub>
- </menu>
- <menu>
- <menuId>涓昏彍鍗2</menuId>
- <sub>
- <subId>plugin_id:pmod1</subId>
- <title>瀛愯彍鍗3</title>
- </sub>
- <sub>
- <subId>plugin_id:pmod2</subId>
- <title>瀛愯彍鍗4</title>
- </sub>
- </menu>
- <userdef><![CDATA[1]]></userdef>
- </root>
- name锛氬钩鍙板悕绉帮紝鍦ㄥ骞冲彴鍒楄〃涓睍绀虹殑鍚嶇О锛
- title锛氬钩鍙扮綉椤垫爣棰橈紝鏄剧ず鍦ㄦ祻瑙堝櫒鏍囬鏍忎腑鐨勫悕绉帮紱
- logo锛氬乏涓婅 LOGO 鍖哄煙 HTML锛
- navbar锛氬彸渚ф悳绱㈠尯鍩 HTML锛
- framecss锛氭鏋堕〉 CSS锛屽彲鐩存帴鍐 CSS 浠g爜锛屼篃鍙互鍐欐枃浠 URL (.css 缁撳熬)锛
- pagecss锛氬唴瀹归〉 CSS锛岃鍒欏悓 framecss锛
- menu锛氫富鑿滃崟鑺傜偣锛屽涓富鑿滃崟鎸夌収椤哄簭涔﹀啓锛
- menuId锛氳彍鍗 ID銆佸鏄惧悕绉帮紝鍙啓璇█鍖呭悕鎴栦腑鏂囷紱
- sub 瀛愯彍鍗曡妭鐐癸紱
- subId锛氬瓙鑿滃崟 ID锛屾牸寮忊渁ction_operation_do鈥濓紝action銆乷peration銆乨o 涓虹浉搴旈〉闈 GET 鍙傛暟鎷兼帴鐨勫唴瀹癸紝opeartion銆乨o 鍙渷鐣ワ紱濡傛灉鏄烦杞埌鎻掍欢椤甸潰锛屾牸寮忎负 鈥減lugin_id:pmod鈥濓紝id 涓烘彃浠跺敮涓鏍囪瘑绗 ID锛宲mod 涓哄悗鍙版ā鍧楃殑鍙傛暟锛宲mod 鍙渷鐣ワ紱
- title锛氬鏄惧悕绉帮紝鍙啓璇█鍖呭悕鎴栦腑鏂囷紱
- type锛1=鍖哄煙寮濮嬶紝2=鍖哄煙缁撴潫锛
- showMethod锛氭樉绀烘鑿滃崟椤圭殑鏉′欢锛屽璋冩柟娉曪紝绯荤粺鍊间笉寤鸿淇敼銆傛彃浠剁敤 id::method 鏂瑰紡璋冪敤鍏蜂綋鏂规硶锛岀郴缁熶細璋冪敤 plugin/id/ 涓 class platform_id 鐨勯潤鎬佹柟娉 method()锛
- listMethod锛氳彍鍗曟樉绀哄唴瀹圭敱鍏蜂綋鏂规硶杩斿洖锛屾牸寮忓悓 showMethod锛
- subPerms锛氬綋鍓嶈彍鍗曢」鍏宠仈鐨勫叾浠栧瓙鑿滃崟 ID锛屽涓敤閫楀彿鈥,鈥濆垎鍓诧紝 ID 鏍煎紡瑙 subId锛
- $xml = '<?xml version="1.0" encoding="ISO-8859-1"?>
- ...
- ';
- menu::platform_add('test', $xml); // test 涓哄钩鍙版爣璇嗭紝$xml 涓洪厤缃暟鎹
- menu::platform_del('test');// test 涓哄钩鍙版爣璇
寮鍙戣呴渶涔﹀啓涓涓 platform.class.php 鑴氭湰
plugin/myplugin/platform.class.php 瀹屾暣绀轰緥锛
- class platform_myplugin {
- // myplugin:showMethodSample
- public static function showMethodSample() {
- return true;
- }
- // myplugin:listMethodSample
- public static function listMethodSample() {
- return array(
- array('menu_members_edit', 'members_search', 0, '', '', array('members_clean', 'members_repeat')),
- array(cplang('nav_home'), '', 1, 'homestatus'),
- array('menu_maint_doing', 'doing', 0, 'doingstatus'),
- array('menu_maint_share', 'share', 0, 'sharestatus'),
- array(cplang('nav_home'), '', 2, 'homestatus'),
- );
- }
- }
showMethodSample 涓 showMethod 鐨勮寖渚嬶紝杩斿洖 true/false 鍗冲彲锛宼rue 鏃惰彍鍗曢」鏄剧ず
listMethodSample 涓 listMethod 鐨勮寖渚嬶紝杩斿洖鐨勫唴瀹逛細鏇挎崲鎺夌浉搴斾綅缃腑鐨勬暟鎹傚叾涓繑鍥炵殑鏁扮粍涓 XML 涓 sub 涓嬭妭鐐圭殑瀵瑰簲鍏崇郴涓猴細
listMethodSample 涓 listMethod 鐨勮寖渚嬶紝杩斿洖鐨勫唴瀹逛細鏇挎崲鎺夌浉搴斾綅缃腑鐨勬暟鎹傚叾涓繑鍥炵殑鏁扮粍涓 XML 涓 sub 涓嬭妭鐐圭殑瀵瑰簲鍏崇郴涓猴細
0锛歵itle
1锛歴ubId
2锛歵ype
3锛歴howMethod
4锛歭istMethod
5锛歴ubPerms
绗笁鏂圭櫥褰1锛歴ubId
2锛歵ype
3锛歴howMethod
4锛歭istMethod
5锛歴ubPerms
鐢变簬 X5.0 澧炲姞浜嗗叏鏂扮殑璐﹀彿绠$悊绯荤粺锛岄氳繃姝ゅ叏鏂扮殑璐﹀彿骞冲彴锛屽紑鍙戣呭彲寰堟柟渚跨殑寮鍙戝嚭鑷繁鐨勭櫥褰曠郴缁
绗笁鏂圭櫥褰曠被鍥哄畾鐨勬枃浠朵负 /acccount.class.php锛屼緥濡傛彃浠剁洰褰曚负 sample锛岄偅涔堟枃浠朵负 /source/plugin/sample/account.class.php
- class account_sample extends account_base {
- // 涓嶈嚜鍔ㄧ敓鎴愬ご鍍
- public bool $interface_noAutoAvatar = true;
- // 涓嶆敮鎸佺粦瀹
- public bool $interface_noBind = false;
- public function __construct() {
- $this->conf = parent::getConfig('plugin_sample');
- }
- public static function name() {
- return '娴嬭瘯鐧诲綍';
- }
- public static function icon() {
- return '<svg t="1715821283732" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="28056" width="20" height="20"><path d="M840.7 626.2c-33.3 33.3-144 23.5-144 23.5s-9.7-110.7 23.5-144c33.3-33.3 77.3-0.5 77.3 43.2 44.3 0 76.5 44 43.2 77.3zM611.2 560.7c-29.7 0-53.9-24.3-53.9-53.9V245.3c0-29.7 24.3-53.9 53.9-53.9 29.7 0 53.9 24.3 53.9 53.9v261.5c0 29.7-24.3 53.9-53.9 53.9zM226.3 614.7c-29.7 0-53.9-24.3-53.9-53.9V338.5c0-29.7 24.3-53.9 53.9-53.9 29.7 0 53.9 24.3 53.9 53.9v222.2c0.1 29.7-24.2 54-53.9 54zM482.9 551.5c-29.7 0-53.9-24.3-53.9-53.9V121.2c0-29.7 24.3-53.9 53.9-53.9 29.7 0 53.9 24.3 53.9 53.9v376.3c0 29.7-24.2 54-53.9 54zM354.6 571.5c-29.7 0-53.9-24.3-53.9-53.9v-337c0-29.7 24.3-53.9 53.9-53.9 29.7 0 53.9 24.3 53.9 53.9v337c0.1 29.7-24.2 53.9-53.9 53.9zM445.7 960c-67.4 0-130.8-26.2-178.4-73.9-47.7-47.7-73.9-111-73.9-178.4 0-18.2 14.8-33 33-33s33 14.8 33 33c0 102.8 83.6 186.4 186.4 186.4 102.8 0 186.4-83.6 186.4-186.4 0-18.2 14.8-33 33-33s33 14.8 33 33c0 67.4-26.2 130.8-73.9 178.4S513.1 960 445.7 960z" fill="#E95431" p-id="28057"></path></svg>';
- }
- // 閫氱煡鍙戦
- public function notificationAdd($touid, $note, $notestring) {
- }
- // 鐢ㄤ簬鑷姩鐧诲綍锛屽垽鏂槸鍚﹀湪鐜涓
- public function inEnv() {
- return isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'xxx');
- }
- // 鐧诲綍(缁戝畾)璺宠浆
- public function login($referer = '', $op = 0) {
- if(empty($_POST)) {
- echo
- <<<EOF
- <form method="post" action="$_SERVER[PHP_SELF]?method=plugin_sample">
- User:<input name="user"><br />
- Pass:<input name="pass" type="password"><br />
- <input type="submit">
- </form>
- EOF;
- } else {
- $data = array(
- 'test1' => array('pass' => '1', 'uid' => 'sampleUid1'),
- 'test2' => array('pass' => '1', 'uid' => 'sampleUid2'),
- );
- if(!isset($data[$_POST['user']])) {
- echo 'User not found';
- exit;
- }
- if($data[$_POST['user']]['pass' != $_POST['pass']) {
- echo 'Password error';
- exit;
- }
- $callback = $this->conf['callbackUrl'].'&uid='.$data[$_POST['user']]['uid'];
- echo '<a href="'.$callback.'">callback</a>';
- }
- exit;
- }
- // 鐧诲綍鍥炶皟锛/api/account/callback.php?id=sample 浼氳皟鐢ㄦ鏂规硶
- public function getLoginUser() {
- global $_G;
- $account = new account();
- $param = array(
- 'type' => 'plugin_sample',
- 'atype' => parent::getAccountType('sample'),
- 'account' => $_GET['uid'],
- 'bindname' => $_GET['uid'],
- );
- if(!$account->checkUser($param)) {
- if($_G['uid']) {
- $account->userBind($_G['uid'], $param);
- } else {
- $param += array(
- 'username' => $_GET['uid'],
- 'password' => '',
- );
- $msg = $account->userRegister($param);
- if($msg) {
- if($msg == 'profile_username_duplicate' || $msg == 'profile_email_duplicate') {
- dheader('Location: '.$_G['siteurl'].'?index=member&mod=register');
- }
- showmessage($msg);
- }
- }
- } else {
- $account->userLogin();
- }
- dheader('Location: '.$_G['siteurl']);
- }
- // 绠$悊鍚庡彴
- public function admincp() {
- global $_G;
- $conf = $_G['setting']['account_plugin_confs']['sample'];
- if(!submitcheck('submit')) {
- showformheader('account&method=plugin_sample');
- ...
- showformfooter();
- } else {
- ...
- cpmsg('setting_update_succeed', 'action=account&method=plugin_sample', 'succeed');
- }
- }
- }
X5.0 鍏佽閫氳繃鎻掍欢鎷撳睍 DIY 鐨勬ā鍧楋紝鎮ㄩ渶瑕佹妸 DIY 妯″潡鏂囦欢鍐欏埌 /source/plugin/myplugin/block 鐩綍涓嬪嵆鍙紝鐩綍涓枃浠剁殑鍐呭鍚岀郴缁 /source/class/block銆
瀛愭枃浠鐢变簬 X5.0 鐢ㄥ瓙鏂囦欢 /source/child 浠f浛浜嗗師鍏堢殑 /source/include 鐩綍锛屽洜姝ゆ偍鍙互閫氳繃娉ㄥ唽鎺ョ鐨勬柟寮忓畬鍏ㄤ唬鏇夸换浣曚竴涓郴缁熷瓙鏂囦欢鐨勫師濮嬭皟鐢紝鎮ㄩ渶瑕佹妸瀛愭枃浠跺啓鍒 /source/plugin/myplugin/child 鐩綍涓嬨
- <?php
- //childfile:forum/viewthread/postarr
- if(!defined('IN_DISCUZ')) {
- exit('Access Denied');
- }
- ...
鏂囦欢涓坊鍔 //childfile:鈥︹ 鏍煎紡鐨勬敞閲婏紝娉ㄥ唽闇瑕佹帴绠″瓙鏂囦欢銆傛偍鍙互鍦ㄨ嚜宸辨帴绠$殑瀛愭枃浠朵腑锛屽畬鍏ㄤ唬鏇跨郴缁熷師鏈夌殑閫昏緫锛屼篃鍙互缁х画璋冪敤绯荤粺鍘熸湁閫昏緫锛屽苟鍦ㄥ叾涔嬪墠銆佷箣鍚庤皟鐢ㄨ嚜宸辩殑閫昏緫銆
forum/viewthread/postarr 琛ㄧず鎺ョ /source/app/forum/child/viewthread/postarr.php 鏂囦欢銆
global/core/ip 琛ㄧず鎺ョ /source/child/core/ip.php 鏂囦欢銆
鍙嬫儏鎻愮ず锛氱敱浜庡瓙鏂囦欢鎺ョ鐨勭壒娈婃э紝鍚屼竴涓瓙鏂囦欢鏈変笖鍙湁涓涓彃浠舵帴绠°俛dmin/* 绂佹鎺ョ銆
鏃ュ織绯荤粺X5.0 瀵圭郴缁熺殑鏃ュ織杩涜浜嗗叏闈㈢殑浼樺寲鍜屽紑鏀撅紝鎮ㄥ彲浠ユ妸鎻掍欢鐨勬棩蹇楁帴鍏ュ埌姝ゅ锛岀珯闀垮彲浠ュ湪鈥滄搷浣滄棩蹇椻濆缁熶竴鏌ョ湅銆
娣诲姞鏃ュ織鐨勬柟娉曢氳繃浠ヤ笅绯荤粺鍑芥暟
- logger('myplugin_text', $_G['member'], $_G['member']['uid'], array('p' => $text, 't' => $time));
myplugin_text 涓紝myplugin 涓烘彃浠禝D锛宼ext 涓鸿嚜瀹氫箟鏃ュ織绫诲瀷銆傚悗缁弬鏁板彲閰屾儏娣诲姞銆
鏃ュ織鍚庡彴鏂囦欢鍐欏埌 /source/plugin/myplugin/log 鐩綍涓嬶紝鏂囦欢鍚嶅浐瀹氫负 log_鏃ュ織绫诲瀷.php锛屼緥濡備笂渚嬩腑鐨 log_text.php
- <?php
- if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
- exit('Access Denied');
- }
- showtableheader('', 'fixpadding');
- showtablerow('class="header"', array('class="td23"', 'class="td24"', 'class="td23"', 'class="td23"', 'class="td23"'), array(
- cplang('time'),
- 'text',
- cplang('logs_device'),
- ));
- foreach($logs as $k => $logrow) {
- $data = json_decode($logrow['data'], true);
- $device = json_decode($logrow['device'], true);
- showtablerow('', array('class="smallefont"', 'class="smallefont"', 'class="bold"', 'class="smallefont"', 'class="smallefont"'), array(
- dgmdate($logrow['dateline']),
- is_array($data['p']) ? print_r($data['p'], 1) : $data['p'],
- $_G['group']['allowviewip' ? 'ClientIP: '.$device['client_ip'].' <a href="javascript:;"pun" color:rgb(0, 0, 0)">$logrow['id'].')">'.cplang('more').'</a>' : '-',
- ));
- echo showdevice($logrow['id'], $device, 6);
- }
X5.0 鐨勭鐞嗕腑蹇冮椤靛彲閫氳繃灏忕粍浠剁殑鏂瑰紡杩涜鎷撳睍锛岃澧炲姞灏忕粍浠舵偍闇瑕佸皢鑴氭湰鍐欏埌 /source/plugin/myplugin/admin/admin_widget.php 鏂囦欢涓紝鏂囦欢缁撴瀯涓猴細
- <?php
- namespace myplugin;
- if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
- exit('Access Denied');
- }
- class admin_widget {
- public static function widget_a() {
- }
- public static function widget_b_left() {
- }
- ...
- }
adminwidget 绫讳腑鍙互鍐欏涓 鈥渨idget鈥 寮澶寸殑灏忕粍浠舵柟娉曪紝榛樿灏忕粍浠朵綅浜庡彸渚э紝濡傛灉鎯冲啓宸︿晶鐨勫皬缁勪欢锛岃璁╂柟娉曞悕浠 鈥淿left鈥 缁撳熬銆
璁剧疆椤圭粍浠X5.0 涓彲浠ュ畾涔夎嚜宸辩殑璁剧疆椤癸紝瑕佸鍔犺缃」缁勪欢鎮ㄩ渶瑕佸皢鑴氭湰鍐欏埌 /source/plugin/myplugin/admin/component 鐩綍涓紝涓涓枃浠朵竴涓粍浠讹紝姣忎釜鏂囦欢閮戒互 component_ 寮澶村懡鍚嶏紝鏂囦欢缁撴瀯涓猴細
component_a.php
- <?php
- namespace myplugin\admin;
- if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
- exit('Access Denied');
- }
- class component_a {
- var $name = '缁勪欢鍚嶇О';
- // 缂栬緫鏃舵樉绀虹殑鍐呭
- function show(&$var, &$extra) {
- ...
- }
- // 鏁版嵁鎻愪氦鍏ュ彛鍚庤繘琛屾墦鍖
- function serialize($params, &$value) {
- ...
- }
- // 鏁版嵁閲嶆柊缂栬緫鍓嶈繘琛岃В鍖
- function unserialize($params, &$value) {
- ...
- }
- }
瀹氫箟鍚庯紝鎻掍欢浠g爜涓彲鐢ㄤ笅闈㈢殑鍑芥暟杩涜璋冪敤锛
- showcomponent('娴嬭瘯1', 'abc1', 'yellow', 'myplugin:component_a');
琛ㄥ崟鎻愪氦鍚庨渶瑕侀氳繃涓嬮潰鐨勫嚱鏁板缁勪欢鐨勬暟鎹繘琛屽簭鍒楀寲灏佽
- serializecomponent();
X5.0 涓彲浠ヨ嚜瀹氫箟 [media] 鏍囩涓棰戣В鏋愮殑鑴氭锛岃澧炲姞鏂扮殑瑙f瀽鑴氭湰鎮ㄩ渶瑕佸皢鑴氭湰鍐欏埌 /source/plugin/myplugin/media 鐩綍涓紝涓涓枃浠朵竴涓剼鏈紝姣忎釜鏂囦欢閮戒互 media_ 寮澶村懡鍚嶏紝鏂囦欢缁撴瀯涓猴細
media_video.php
- <?php
- namespace myplugin;
- class media_video {
- public static $version = '1.0';
- public static $name = 'name';
- public static $checkurl = ['video.com/'];
- public static function parse($url, $width, $height) {
- if(preg_match('/^https?:\/\/video.com\/(\d+)/i', $url, $matches)) {
- $iframe = 'https://www.video.com/iframe/'.$matches[1];
- $flv = $imgurl = '';
- }
- return [$flv, $iframe, $url, $imgurl];
- }
- }
X5.0 涓彲浠ュ畾涔夎嚜宸辩殑鍒嗙被淇℃伅绫诲瀷锛岃澧炲姞鏂扮殑绫诲瀷鎮ㄩ渶瑕佸皢鑴氭湰鍐欏埌 /source/plugin/myplugin/threadtype 鐩綍涓紝涓涓枃浠朵竴涓被鍨嬶紝姣忎釜鏂囦欢閮戒互 threadtype_ 寮澶村懡鍚嶏紝鏂囦欢缁撴瀯涓猴細
threadtype_a.php
- <?php
- namespace myplugin;
- if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
- exit('Access Denied');
- }
- class threadtype_a {
- var $name = '绫诲瀷鍚嶇О';
- // 缂栬緫鏃舵樉绀虹殑鍐呭
- function show($option, $params) {
- ...
- }
- // 缁撴灉杈撳嚭鏃舵樉绀虹殑鍐呭
- function view($viewtype, $option, $params, $value) {
- ...
- }
- // 鏁版嵁鎻愪氦鍏ュ彛鍚庤繘琛屾墦鍖
- function serialize($params, &$value) {
- ...
- }
- // 鏁版嵁閲嶆柊缂栬緫鍓嶈繘琛岃В鍖
- function unserialize($params, &$value) {
- ...
- }
- }
X5.0 寮曞叆浜嗗叏鏂扮殑JSON缂栬緫鍣紝鍩轰簬 Editor.js 鍐呮牳锛屾槸鍖哄潡椋庢牸(Block-Styled)缂栬緫鍣紝鍏锋湁骞插噣JSON杈撳嚭鐨勫潡鏍峰紡锛屽悓鏃讹紝璁╃紪杈戝櫒鏈夋洿澶氱殑鑷敱鎬у拰鍙墿灞曟с傚潡鏄瀯鎴愭潯鐩殑缁撴瀯鍗曞厓锛屼緥濡傦紝Paragraph锛孒eading锛孖mage锛孷ideo锛孡ist閮芥槸鍧椼傛瘡涓潡鐢辨彃浠惰〃绀猴紝浠ョ儹鎻掓嫈鐨勫舰寮忕伒娲讳负缂栬緫鍣ㄦ墿灞曞姛鑳姐
鍙互閫氳繃鎻掍欢鏂瑰紡涓篔SON缂栬緫鍣ㄦ墿灞曞姛鑳藉尯鍧楋紝鎮ㄩ渶瑕佹妸鍖哄潡鏂囦欢鍐欏埌 /source/plugin/myplugin/editorblock 鐩綍涓嬨
鍖哄潡绫诲浐瀹氫互 editorblock_鑷畾涔夊尯鍧楄嫳鏂囨爣璇.php 鍛藉悕, 濡 editorblock_myBlock.php 锛屾斁鍦 editorblock 鏍圭洰褰曪紝鍖哄潡 js銆乧ss 闈欐佽祫婧愭斁鍏 editorblock/tools/myBlock 鐩綍涓嬨
鐩綍缁撴瀯- editorblock // 鍥哄畾鍛藉悕
- 鈹溾攢鈹 tools // 鍥哄畾鍛藉悕
- 鈹溾攢鈹 myBlock // 鑷畾涔夊尯鍧楄嫳鏂囨爣璇
- 鈹溾攢鈹 myBlock.js // 鑷畾涔夊尯鍧楁牳蹇僯s
- 鈹溾攢鈹 myBlock.css // 鑷畾涔夊尯鍧楁牳蹇僣ss
- 鈹溾攢鈹 editorblock_myBlock.php // 鑷畾涔夊尯鍧楁牳蹇冪被
浠ヤ笅鏄尯鍧楁牳蹇冪被涔﹀啓鑼冧緥锛屽叾涓 getConfig() 銆 getStyle() 銆 getParser() 灏嗘敮鎸佸悗鍙板湪绾跨紪杈戯紝鍗筹紝鐢ㄦ埛鍙互鑷敱瀹氫箟鍖哄潡灞曠ず缁撴瀯涓庢牱寮忋
- class editorblock_myBlock {
- var $version = '1.0.5'; // 鐗堟湰
- var $name = '鑷畾涔夊尯鍧楀悕绉'; // 鍖哄潡鍚嶇О
- var $available = 1; // 榛樿鍚敤鐘舵 0:涓嶅惎鐢 1:鍚敤
- var $columns = 1; // 榛樿鏄惁鏀寔澶氬垪 0:涓嶆敮鎸 1:鏀寔
- var $identifier = 'myBlock'; // 鑷畾涔夊尯鍧楁爣璇
- var $description = '鎻掑叆鑱旂郴鏂瑰紡淇℃伅鍖哄潡锛屽彲鐢ㄤ簬鎻掑叆鐢佃瘽銆佸井淇″彿銆丵Q鍙风瓑锛屾坊鍔犲唴瀹规牸寮忎负锛氱被鍨嬫爣璇(mobile銆亀echat銆乹q)/鑱旂郴浜哄悕绉/鑱旂郴鏂瑰紡(鐢佃瘽銆佸井淇$瓑)'; // 鍖哄潡鎻忚堪
- var $filename = 'myBlock'; // 鍖哄潡鏂囦欢鍚嶏紝涓庤嚜瀹氫箟鍖哄潡鏍囪瘑涓鑷村嵆鍙
- var $copyright = '浜戣'; // 鐗堟潈锛屾樉绀哄湪鍚庡彴JSON鍖哄潡鍒楄〃涓
- var $type = '0'; // 0:鏁版嵁绫诲瀷 1:鍥剧墖绫诲瀷 2:闄勪欢绫诲瀷
- function __construct() {
- }
- // 鍖哄潡 鏁版嵁缁撴瀯 绀轰緥锛屽弬鐓 Editor.js 鍖哄潡鏁版嵁缁撴瀯
- function getParameter() {
- return <<<EOF
- {
- "data": {
- "channelType": "mobile", // mobile銆亀echat銆乹q
- "channelName": "浜戣",
- "messageId": 123456
- },
- "id": "ZT8S70Q34G", // 鍖哄潡id
- "type": "myBlock" // 鍖哄潡绫诲瀷
- }
- EOF;
- }
- /*
- * 鍖哄潡 config 閰嶇疆锛屽弬鐓 Editor.js 鍖哄潡閰嶇疆
- *
- * 缁撴瀯(宸﹂《澶)锛
- * {
- * tools_鑷畾涔夊尯鍧楄嫳鏂囨爣璇: {
- * 鑷畾涔夊尯鍧楄嫳鏂囨爣璇: {
- * ...
- * }
- * }
- * }
- */
- function getConfig() {
- return <<<EOF
- {
- tools_myBlock: {
- myBlock: {
- class: myBlock,
- tunes: ['anchorTune'
- },
- }
- }
- EOF;
- }
- // 灏氭湭鍚敤
- function getI18n() {
- return <<<EOF
- EOF;
- }
- // 鍖哄潡鍦ㄧ紪杈戝櫒涓殑 鏄剧ず鏍峰紡 閰嶇疆
- // CSS鏍峰紡浠g爜閮ㄥ垎蹇呴』涓ユ牸涔﹀啓鍦<style type="text/css">......</style>鍐呴儴銆
- function getStyle() {
- return <<<EOF
- <style type="text/css">
- .ce-block {
- /* margin-bottom: 20px; */
- }
- .ce-block__content,.ce-toolbar__content {
- /* max-width:calc(100% - 50px) */
- margin-left: auto;
- margin-right: auto;
- }
- .ce-myBlock {
- position: relative;
- float: left;
- width: 280px;
- height: auto;
- padding: 15px 10px 15px 20px;
- box-sizing: border-box;
- border: 1px solid #3f9dffa3;
- border-radius: 50px;
- margin: 10px 15px;
- }
- .ce-myBlock dl {
- margin: 0
- }
- .ce-myBlock dl dt {
- width: 50px;
- height: 50px;
- float: left;
- position: relative;
- margin-right: 12px;
- }
- .ce-myBlock dl dt svg {
- width: 100%;
- height: 100%
- }
- .ce-myBlock dl dd {
- float: left;
- position: relative;
- }
- .ce-myBlock dl dd h3 {
- height: 20px;
- line-height: 20px;
- font-size: 14px;
- margin-top: 5px;
- }
- .ce-myBlock dl dd h3 em {
- font-style: normal;
- margin-left: 5px;
- color: #fa5555;
- font-size: 12px;
- }
- .ce-myBlock dl dd p.p1 {
- color: #999;
- }
- .ce-myBlock dl dd p {
- width: 185px;
- height: 20px;
- line-height: 20px;
- margin-top: 5px;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- </style>
- EOF;
- }
- // 鍖哄潡 瑙f瀽妯℃澘 閰嶇疆锛岃В鏋愭ā鏉垮紑鍙戞柟寮忚涓嬫枃
- function getParser($block = array()) {
- global $_G;
- return <<<EOF
- <div class="ce-block ce-block--focused" data-id="{id}" [if tunes.anchorTune.anchor=notnullid="{tunes.anchorTune.anchor}"[/if]>
- <div class="ce-block__content">
- <div class="ce-myBlock ">
- <dl>
- <dt>
- [if data.channelType=mobile
- <svg t="1705559455679" class="icon" viewBox="0 0 1025 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="69723" width="80" height="80"><path d="M511.484254 0.066515C227.987504 0.066515-0.001023 227.399103-0.001023 510.114047c0 282.71392 227.987504 512.917906 511.485277 512.917906 283.461957 0 511.48016-230.203986 511.48016-512.917906C1022.964414 227.399103 794.94621 0.066515 511.484254 0.066515zM762.853281 772.349563l-57.003272 43.768853c-54.072523 16.044418-187.064466 42.271756-352.206644-190.872189-187.063443-252.120135-112.512517-394.946051-84.758406-419.698804l59.904345-42.270732 24.854061 7.306406 100.833523 145.69629-2.901073 23.320125-58.471716 40.803311c-26.28669 21.851681-8.772804 49.541323 10.237155 101.988836 17.543561 30.625508 57.003272 91.816149 83.290985 115.137297 45.297672 37.896098 65.777099 62.684668 96.468099 45.201481l55.505152-39.333844 21.977547 2.871397 105.142665 141.357472L762.853281 772.349563z" fill="#18CC73" p-id="69724"></path></svg>
- [/if
- [if data.channelType=wechat
- <svg t="1705558999833" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="47545" width="80" height="80"><path d="M512 1.896C229.452 1.896 0 229.452 0 512s229.452 510.104 512 510.104S1022.104 794.548 1022.104 512 794.548 1.896 512 1.896z m-91.022 629.57c-26.548 0-49.304-5.688-75.852-11.377l-75.852 37.926 22.756-66.37c-54.993-37.926-87.23-87.23-87.23-147.912 0-104.296 98.607-185.837 218.074-185.837 108.089 0 201.007 64.474 219.97 153.6-7.585 0-13.274-1.896-20.859-1.896-104.296 0-185.837 77.748-185.837 172.563 0 15.17 1.896 30.34 7.585 45.511-7.585 3.793-15.17 3.793-22.755 3.793z m322.37 77.749l17.067 54.992-58.785-34.133c-22.756 5.689-43.615 11.378-66.37 11.378-104.297 0-185.838-70.163-185.838-157.393S530.963 424.77 635.26 424.77c98.608 0 185.837 70.163 185.837 159.29 0 47.407-32.237 91.021-77.748 125.155z" fill="#46BB36" p-id="47546"></path><path d="M318.578 379.26c0 17.066 13.274 30.34 30.34 30.34s30.341-13.274 30.341-30.34-13.274-30.341-30.34-30.341-30.341 13.274-30.341 30.34z m235.14 159.288c0 13.274 11.378 24.652 24.652 24.652 13.274 0 24.652-11.378 24.652-24.652 0-13.274-11.378-24.652-24.652-24.652-13.274-1.896-24.651 9.482-24.651 24.652z m-81.54-159.289c0 17.067 13.274 30.341 30.34 30.341 17.067 0 30.341-13.274 30.341-30.34 0-17.067-13.274-30.341-30.34-30.341-17.067 0-30.341 13.274-30.341 30.34zM675.08 538.55c0 13.273 11.378 24.651 24.652 24.651 13.274 0 24.652-11.378 24.652-24.652 0-13.274-11.378-24.652-24.652-24.652-13.274-1.896-24.652 9.482-24.652 24.652z" fill="#46BB36" p-id="47547"></path></svg>
- [/if
- [if data.channelType=qq
- <svg t="1705559232025" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="57063" width="80" height="80"><path d="M511.500488 512.499512m-511.500488 0a511.500488 511.500488 0 1 0 1023.000976 0 511.500488 511.500488 0 1 0-1023.000976 0Z" fill="#1BC1FA" p-id="57064"></path><path d="M784.234146 572.440976c8.178014 0 16.273108 0.253752 24.282287 0.728288-16.961436-38.434466-42.247742-69.886751-58.977405-90.331785 2.822244-8.482716 11.30496-56.536788-25.443153-90.453666v-2.827239c0-132.850263-96.103149-231.785647-214.822213-231.785647-118.717065 0-214.82521 96.107145-214.825209 231.785647v2.827239c-33.915879 33.915879-25.437159 81.969951-19.782681 90.453666-25.444152 28.265397-73.49223 87.62343-76.320469 155.461182 0 16.961436 2.827239 45.226833 11.305959 56.531794 11.305959 14.133198 39.570357-2.827239 62.186272-48.054073 5.650482 19.788675 19.78368 53.709549 50.876316 93.281905-50.876316 11.302962-65.009514 62.186271-48.049077 90.450669 11.305959 19.788675 39.570357 33.920874 87.624429 33.920874 78.496343 0 115.815899-19.378076 134.378771-35.711126C492.644901 814.680414 490.520976 800.136617 490.520976 785.233171c0-117.522232 131.500581-212.792195 293.71317-212.792195z" fill="#FFFFFF" p-id="57065"></path><path d="M514.925143 819.204995c5.654478 0 11.309955 2.82624 14.132199 5.649483 16.960437 16.960437 53.709549 39.575352 138.50674 39.575352 48.054072 0 76.320468-16.960437 87.625428-33.920874 16.960437-28.264398 2.827239-79.147707-48.054072-90.450669 31.092636-39.572355 45.225834-73.493229 50.881311-93.281905 19.787676 45.226833 50.881311 62.18727 62.186271 48.054073 2.827239-11.30496 5.650482-39.570357 5.650482-56.531794-1.93511-23.223321-8.508691-45.121936-17.337069-65.128398-8.009179-0.475536-16.104273-0.729288-24.282287-0.729287-162.212589 0-293.713171 95.269963-293.71317 212.792195 0 14.903446 2.123926 29.447243 6.147996 43.485533a88.18688 88.18688 0 0 0 4.122973-3.864226c2.827239-2.823243 8.481717-5.649483 14.133198-5.649483z" fill="#FFFFFF" opacity=".4" p-id="57066"></path></svg>
- [/if
- </dt>
- <dd>
- <h3 class="comm" imagentlist="">{data.channelName}<em></em></h3>
- <p class="p1"><em>{data.messageId}</em></p>
- </dd>
- </dl>
- </div>
- </div>
- </div>
- EOF;
- }
- }
浠 Editor.js 缂栬緫鍣ㄥ尯鍧楀紑鍙戞柟寮忓紑鏀惧嵆鍙
鍖哄潡瑙f瀽妯℃澘寮鍙鍙橀噺浣跨敤鏂瑰紡锛歿瀛楁鍚峿 , 澶氬眰绾т娇鐢 . 杩涜杩炴帴, 濡傦細{瀛楁鍚1.瀛楁鍚2.瀛楁鍚3} ;
鍙橀噺浣跨敤鏂瑰紡绀轰緥濡傦細{id} 銆 {type} 銆 {data.alignment} 銆 {data.items.text} ;
鏀寔 [loop] 寰幆锛岀ず渚嬪尯鍧椾唬鐮佸:
鍙橀噺浣跨敤鏂瑰紡绀轰緥濡傦細{id} 銆 {type} 銆 {data.alignment} 銆 {data.items.text} ;
鏀寔 [loop] 寰幆锛岀ず渚嬪尯鍧椾唬鐮佸:
- {
- "data": {
- ...
- "items": [
- {
- "text" : "abc"
- },
- {
- "text" : "def"
- },
- ...
- }
- }
寰幆浣跨敤鏂瑰紡锛
- <ul>
- [loop data.items]
- <li>{text}</li>
- [/loop]
- </ul>
寰幆绱㈠紩锛堟斁鍒板惊鐜綋鍐呴儴锛岃嚜鍔ㄨ鏁帮級锛
- [loopindex
澶氬垪娓叉煋锛堟斁鍒板惊鐜綋鍐呴儴锛屾寚瀹氬瓙鏁版嵁鍧楋紝浠呯敤浜庡鍒楁覆鏌擄級锛
- [column blocks
IF鍒ゆ柇鏂瑰紡锛
- [if data.items=1
- {text}鍧楁暟鎹彉閲 鎴栬 鏅氬瓧绗︿覆
- [/if
URL杞崲缁濆缃戝潃锛
- [url data.file.url
濡傚尯鍧楀墠绔В鏋愰渶瑕乧ss鏍峰紡鏀寔锛屽彲缂栧啓鐙珛鐨 myBlock.css 鏂囦欢锛屽苟浣跨敤 viewthread_postbottom 宓屽叆鐐瑰線椤甸潰涓鍏ヨcss鏂囦欢銆
- class plugin_myplugin_forum extends plugin_myplugin {
- function viewthread_postbottom() {
- $postbottom[0 = '<link rel="stylesheet" type="text/css" href="source/plugin/myplugin/editorblock/tools/myBlock/myBlock.css?'.getglobal('style/verhash').'" />';
- return $postbottom;
- }
- }
閫氳繃鎷撳睍鏀粯锛屽彲浠ヨ搴旂敤鏃犻渶鍋氶澶栬繃澶氱殑寮鍙戝嵆鍙箣闂存帴鍏 Discuz! 绯荤粺鐨勬敮浠樹綋绯汇傜敋鑷宠嚜瀹氫箟涓涓柊鐨勬敮浠橀氶亾銆
鑷畾涔夋敮浠樺叆鍙- payment::enable锛氭槸鍚﹀惎鐢ㄦ敮浠樻湇鍔
- payment::channels锛氳幏鍙栨墍鏈夋敮浠樻笭閬(寰俊鏀粯锛屾敮浠樺疂锛...)锛屽寘鍚湭鍚敤鐨勬敮浠樻笭閬擄紝閫傜敤浜庡畾鍒舵敮浠橀〉闈
- payment::get锛氭牴鎹敮浠樻笭閬撳悕绉帮紝鍒涘缓涓涓敮浠樺疄渚嬪璞★紝閫傜敤浜庢帴鍏ユ柊鐨勬敮浠樻柟寮
- payment::create_order锛氬垱寤轰竴涓敮浠樿鍗
- payment::query_order锛氭敮浠樿鍗曠姸鎬佹煡璇
- payment::finish_order锛氬畬鎴愪竴涓敮浠樿鍗曪紝濡傦細琛ュ崟锛岄噸璇
- payment::retry_callback_order锛氫笟鍔″洖璋冮噸璇
- payment::refund锛氶娆
- payment::refund_status锛氶娆剧姸鎬佹煡璇
- payment::transfer锛氳浆璐
- payment::transfer_status锛氳浆璐︾姸鎬佹煡璇
- payment::channels_add锛氭坊鍔犳敮浠橀氶亾
- payment::channels_delete锛氬垹闄ゆ敮浠橀氶亾
鍦 pay/pay_xxx.php 瀹氫箟鏀粯鍙戣捣鍜屽洖璋冩柟娉
- namespace myplugin;
- // sample 浠呭疄鐜颁簡 pay 鏂规硶锛屾洿澶氬弬瑙 /class/pay
- class pay_test extends \pay_base {
- public function callback($data, $order) {
- ...
- }
- public function pay($order) {
- ...
- }
- }
鍦 admin/payment/payment_xxx.php 涓彲浠ユ坊鍔犲悗鍙拌缃剼鏈
- namespace myplugin\admin;
- class payment_test {
- var $name = 'xxx鏀粯';
- public function admincp() {
- if(!submitcheck('submit')) {
- showformheader('ec&operation=method&id=myplugin:test');
- ......
- showsubmit('submit');
- showtablefooter();
- showformfooter();
- } else {
- ......
- }
- }
- }
X5.0 澧炲姞浜嗗熀浜 oAuth2 鍗忚鐨勫紑鏀 API 鎺ュ彛锛屽紑鍙戣呭彲浠ラ氳繃璁捐 XML 鏂囦欢锛屽嵆鍙鍔 API 鎺ュ彛锛 璇﹁ API Gitee 鏂囨。
鎻掍欢鑼冧緥X5.0 鏂板鎻掍欢鎺ュ彛瀹屾暣鑼冧緥瑙 sample 鎻掍欢