Discuz! Item system item development document

Source: Internet
Author: User
Tags magics naming convention

Discuz! The prop system adopts the prop structure of an independent PHP file. Each prop has a separate PHP file. As a prop running file, you can compile a prop file to create a prop for your own forum. The following describes the relevant mechanisms and development methods.

 

1. Composition of items

Each item consists of a PHP file and an image file.

The PHP file is stored in the include/magic directory of the Forum, and the naming convention is magic_inc _. php file. The image file is stored in the images/magicsdirectory, and its name is unique. gif

Note: The item name is composed of any English letters. The unique identifier of the item is determined when it is added. The identifier is unique and can contain up to three uppercase letters.

There is no need to say that the prop image is a GIF file. The following describes the PHP file writing specifications.

 

2. Details on how to compile a project PHP File

Take a project PHP file (magic_inc_close.php) as an example.

<? PHP

 

// This sectionCodeTo prevent files from being called directly. Each prop file must be added at the beginning.

If (! Defined ('in _ discuz ')){

Exit ('Access denied ');

}

 

// The code that the user clicks to use

If (submitcheck ('usesubmit ')){

// Verify that the information is complete. Here, verify that $ TID (post ID) is filled

If (empty ($ tid )){

Showmessage ('magics _ info_nonexistence ');

}

// Obtain post-related information

$ Thread = getpostinfo ($ tid, 'tid', array ('fid '));

// Verify whether the topic of the post has the permission to use the item.

Checkmagicperm ($ magicperm ['forum'], $ thread ['fid']);

// The Execution Code of the item

$ Db-> query ("Update {$ tablepre} threads set closed = '1', moderated = '1' where tid = '$ tid '");

$ Expiration = $ timestamp + 86400;

 

// Use the prop code

Usemagic ($ magicid, $ magic ['num']);

// Record the use log of the item

Updatemagiclog ($ magicid, '2', '1', '0', $ tid );

// Record the use object of the item (topic here) log

Updatemagicthreadlog ($ tid, $ magicid, $ magic ['identifier'], $ expiration );

// Display item usage information

Showmessage ('magics _ operation_succeed ', 'Magic. php? Action = user ');

 

}

 

// Generate the code for displaying the item Interface

Function showmagic (){

Global $ tid, $ Lang;

Magicshowtype ($ Lang ['option'], 'top ');

Magicshowsetting ($ Lang ['target _ tid'], 'tid', $ tid, 'text ');

Magicshowtype ('', 'bottom ');

}

 

?>

 

The above is the preparation format of a simple item. The red comment section is a required item. Of course, some codes in it can be modified based on different item types, for example, if the statement used to obtain the post information is a user operation, you can change it to user information. We have built some user-defined functions for these operations. With these user-defined functions, you can easily call the information you want to call. Let's talk about these user-defined functions.

 

3. built-in functions of the item System

All custom functions are in the include/magic. func. php file. I will explain these functions one by one.

// Item permission verification function

$ Perms has the groupid or FID sequence with permissions, separated by \ t in the middle

$ ID: FID or groupid to be verified

Checkmagicperm ($ perms, $ id)

 

// Obtain the prop Function

$ Magicid item ID,

$ Magicnum get quantity

$ Weight item weight

$ Totalweight total item weight owned by the user

$ Uid: Get the UID of the prop user

$ Maxmagicsweight maximum weight of the item owned by the user

Getmagic ($ magicid, $ magicnum, $ weight, $ totalweight, $ uid, $ maxmagicsweight)

 

// Query the maximum weight function of a user's item

$ Uid query user uid

$ Magicarray item data array

Getmagicweight ($ uid, $ magicarray)

 

// Query the post information function

$ Id the post or topic PID or tid

$ Type indicates the type of the query. TID indicates the topic PID indicates the post.

$ Array of field data types to be queried by colsarray

Getpostinfo ($ id, $ type, $ colsarray = '')

 

// User information query function

$ Username query Username

$ Array of field data types to be queried by colsarray

Getuserinfo ($ username, $ colsarray = '')

 

// Present the prop Function

$ Username: username of the object to be presented

$ Magicid: Present a prop ID

$ Magicnum: Number of complimentary items per item

$ Totalnum total number of complimentary items

$ Totalprice total price of complimentary items

Givemagic ($ username, $ magicid, $ magicnum, $ totalnum, $ totalprice)

 

// Prop Random Function

$ The probability of odds success, for example, 10 is 10%.

Magicrand ($ odds)

 

// Item marketing item operation function

$ Magicid item ID

$ Marketnum item market item quantity

$ Magicnum item quantity

Marketmagicnum ($ magicid, $ marketnum, $ magicnum)

 

// Prop operation verification function (the user verifies whether the object used by the prop has been operated by the moderator)

$ TID post ID

Magicthreadmod ($ tid)

 

// Function generated on the item Page

Magicshowsetting ($ setname, $ varname, $ value, $ type = 'Radio ', $ width = '000000 ')

Magicshowtips ($ tips, $ title)

Magicshowtype ($ name, $ type = '')

 

// Use functions for items

$ Magicid item ID

$ Totalnum total number of users with items used

$ Num usage

Usemagic ($ magicid, $ totalnum, $ num = 1)

 

 

 

// Use the object log for the item (mainly used when the object topic is used)

$ TID topic tid

$ Magicid item ID

$ Action Action ID

$ Expiration item Validity Period

$ Extra whether to record username 1 is not recorded, 0 is recorded

Updatemagicthreadlog ($ tid, $ magicid, $ action, $ expiration, $ extra = 0)

 

// Prop use Log

$ Magicid item ID

$ Action Action Id 1: Buy 2: Use 3: Gift 4: sale 5: Purchase

$ Amount item operation count

$ Price item operation price

$ Targettid use object tid

$ Targetpid use the object PID

$ Targetuid use object uid

Updatemagiclog ($ magicid, $ action, $ amount, $ price, $ targettid = 0, $ targetpid = 0, $ targetuid = 0)

 

 

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.