Development Based on thinksns2.5 plug-in

Source: Internet
Author: User
1. What is a plug-in? The plug-in is located in the addonsplugins directory? The plug-in extends some functions without modifying any application-core code. It has the ability to enable and disable it .? Thinksns plug-in mechanism is based on Hook, so the hook implemented by each plug-in will be executed once at the specified position. When multiple plug-ins simultaneously implement the same Hook

1. What is a plug-in? The plug-in is located in the/addons/plugins/directory? The plug-in extends some functions without modifying any application-core code. It has the ability to enable and disable it .? Thinksns plug-in mechanism is based on Hook, so the hook implemented by each plug-in will be executed once at the specified position. When multiple plug-ins simultaneously implement the same Hook

I. What is a plug-in?
? The plug-in is located in the/addons/plugins/directory.
? The plug-in extends some functions without modifying any application-core code and has the ability to enable and disable the plug-in.
? Thinksns plug-in mechanism is based on Hook, so the hook implemented by each plug-in will be executed once at the specified position. Multiple plug-ins will also execute in sequence when implementing the same Hook at the same time.

Ii. Development Process
????1: implement the description object of the Addons abstract class of the plug-in.
???? SimpleAddons: Simple plug-in
???? NormalAddons: complex plug-ins
?
??? Create the file name of the plug-in under plug-in/addons/plugins/(HttpReq is used below ).
??? The HttpReq directory structure is as follows:
?????????????? -Hook ??????????? Use hooks collection classes (multiple classes are allowed)
??????????? ? -Lib ???????????? Plug-in package
??????????? -Html ?? Plug-in page
?????????? -HttpReqAddons. class. php
????
??? Create a description file in the HttpReq Directory: HttpReqAddons. class. php
??? Note: This name must be a standard format such as plug-in name + Addons + class. php.
??? The Code is as follows :?

 

?
???? 2: Define the hooks collection class
? Create the HttpReqAddons. class. php class getHooksInfo under/addons/plugins/HttpReq/hook /.

HttpReqHooks class.
???? The Code is as follows:

  The request address for the sns request to obtain data * is as follows: http://whtest.com/index.php?app=home&mod=Widget&act=addonsRequest&addon=HttpReq&hook=get_user_face * @ Author tangw 2013-03-11 **/class HttpReqHooks extends Hooks {/*** obtain user information by user ID * @ author tangw 2013-03-11 * @ return josn object */public function get_user_info () {$ uid = $ _ REQUEST ['uid']; if (empty ($ uid) {$ this-> _ reJson (array ("isflag" => 0, "msg" => "request parameter error");} $ userData = M ('user')-> field ("email, uname ") -> where ("uid = $ uid")-> find (); if ($ userData) {$ this-> _ reJson (array ("isflag" => 1, "data" => $ userData);} e Lse {$ this-> _ reJson (array ("isflag" => 2, "msg" => "this user does not exist "));}} /*** obtain user images by user name ** @ author tangw 2013-03-11 * @ param array ("uname" => "username", "size" => "image size ") * @ return json object */public function get_user_face () {$ username = trim ($ _ REQUEST ['uname']); // username $ size = trim ($ _ REQUEST ['SIZE']); // image size s = small, m = middle, B = big $ size = empty ($ size )? 'M': $ size; if (empty ($ username) {$ this-> _ reJson (array ("isflag" => 0, "msg" => "request parameter error");} $ userData = M ('user')-> field ("uid ") -> where ("uname = '{$ username}'")-> find (); if ($ userData) {$ uid = $ userData ['uid']; // user ID $ uface = getUserFace ($ uid, $ size); // image $ wb_url = SITE_URL. "/index. php? App = home & mod = Space & act = index & uid = ". $ uid; // Weibo address $ data = array ("uid" => $ uid, "face" => $ uface, "wb_url" => $ wb_url ); $ this-> _ reJson (array ("isflag" => 1, "data" => $ data ));} else {$ this-> _ reJson (array ("isflag" => 2, "msg" => "this user does not exist "));}} /***** @ desc: Return json data ** param $ data = array ('title' => 'OK', 'flag' => 1 ); **/private function _ reJson ($ data) {// header ("Content-type: text/html; charset = UTF-8"); $ str_json = json_e Ncode ($ data); exit ("$ str_json") ;}}?>

Plugin call method:

Addons::createAddonShow("HttpReq", "get_user_info", array());Addons::addonsHook("HttpReq", "get_user_info", array());Addons::createAddonUrl("HttpReq", "get_user_info", array());

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.