Link to this comparison view

development:plugins:event_module [2018/02/26 04:38]
development:plugins:event_module [2018/06/13 23:39] (current) dddd
Line 1: Line 1:
-====== Event Module ====== + 
-The event module allows you to catch events thrown by the application or other plugins, allowing you to be notified and execute anything you want when something happens, like a question being created or a answer being created. + 
-<code php> + 
-qa_register_plugin_module("event", "event-logger-file.php", "class-name", "A Human Readable Module Name"); + 
-</code> + 
- + 
-===== Class Structure ===== + 
-The event class just need one function: **process_event()**This function will be executed every time any event is thrown. + 
-  * __**process_event($event, $userid, $handle, $cookieid, $params)**__     The **$event** parameter is a string defining the type of event that happened - see the list below. The **$userid**, **$handle** and **$cookieid** parameters identify the user that caused the event to take place - some or all may be null if the user is not logged in or does not have an identifying browser cookie. Depending on the event that occurred, the **$params** array may contain additional relevant information. Below is a list of possible values for **$event** and the event that each value describes. You can also use the Event Logger plugin that comes with Q2A to log all events that occur, and then read over these logs to see all elements in **$params**+ 
-    * ''q_post'', ''a_post'' or ''c_post'' when a new question, answer or comment is created. The **$params** array contains full information about the new post, including its ID in **$params['postid']** and textual content in **$params['text']**. + 
-    * ''q_edit'', ''a_edit'' or ''c_edit'' when a question, answer or comment is modified. The **$params** //array// contains information about the post both before and after the change, e.g**$params['content']** and **$params['oldcontent']**+ 
-    * ''a_select'' or ''a_unselect'' when an answer is selected or unselected as the best answer for its questionThe IDs of the answer and its parent question are in **$params['postid']** and **$params['parentid']** respectively. + 
-    * ''q_hide'', ''a_hide'', ''c_hide'', ''q_reshow'', ''a_reshow'' or ''c_reshow'' when a question, answer or comment is hidden or shown again after being hidden. The ID of the question, answer or comment is in **$params['postid']**+ 
-    * ''q_delete'', ''a_delete'', ''c_delete'' when a question, answer or comment is permanently deleted (after being hidden)The ID of the appropriate post is in **$params['postid']**. + 
-    * ''q_claim'', ''a_claim'', ''c_claim'' when an anonymous question, answer or comment is claimed by a user with a matching cookie clicking 'I wrote this'. The ID of the post is in **$params['postid']**+mowang06-13
-    * ''q_move'' when a question is moved to a different category, with more details in **$params**. +
-    * ''a_to_c'' when an answer is converted into a comment, with more details in **$params**. +
-    * ''q_vote_up'', ''q_vote_down'', ''q_vote_nil'', ''a_vote_up'', ''a_vote_down'', ''a_vote_nil'' when a question or answer is upvoted, downvoted or unvoted by a user. The ID of the post is in **$params['postid']**+
-    * ''q_flag'', ''a_flag'', ''c_flag'' when a question, answer or comment is flagged as inappropriate by a userThe ID of the post is in **$params['postid']**. +
-    * ''u_register'' when a new user registers. The email is in **$params['email']** and the privilege level in **$params['level']**+
-    * ''u_login'' and ''u_logout'' when a user logs in or out of Q2A. +
-    * ''u_confirmed'' when a user successfully confirms their email address, given in **$params['email']**. +
-    * ''u_reset'' when a user successfully resets their password, which was emailed to **$params['email']**+
-    * ''u_save'' when a user saves (and has possibly changed) their Q2A account details. +
-    * ''u_password'' when a user sets (and has possibly changed) their Q2A password. +
-    * ''u_edit'' when a user's account details are saved by someone other than the user, i.e. an admin. Note that the $userid and **$handle** parameters to the **process_event()** function identify the user making the changes, not the user who is being changed. Details of the user being changed are in **$params['userid']** and **$params['handle']**+
-    * ''u_level'' when a user's privilege level is changed by a different userSee ''u_edit'' above for how the two users are identifiedThe old and new levels are in **$params['level']** and **$params['oldlevel']**+
-    * ''u_block'' and ''u_unblock'' when a user is blocked or unblocked by another userSee ''u_edit'' above for how the two users are identified. +
-    * ''feedback'' when a message is sent via the Q2A feedback form, with more details in **$params**+
-    * ''search'' when a search is performedThe search query is in **$params['query']** and the start position in **$params['start']**. +
- +
-===== Throwing Events ===== +
-You can also throw events, by using the function **qa_report_event()** which is defined in **qa-base.php**. This is a good way to create interaction between plugins, without having to worry if both plugins are installed. If any of them aren't, the event just will never get thrown and the programmer don't need to check if it's installed+
-To throw an event, just do like the code below: +
-<code php> +
-qa_report_event("u_pm_sent", qa_get_logged_in_userid(), qa_get_logged_in_handle(), qa_cookie_get_create(), array( +
- "param1" => $var1, +
- "param2" => $var2 +
- )); +
-</code> +
-The first param is the name of the event. When catching events, this is gonna be the content of the **$event** var. +
-The second one is the id of the logged user, the third is the handle/username of the user and the third is the cookie. +
-The last is an ''array'' with custom parameters you may want to pass regarding to your eventThey may be how many you want and have the names you want.  +
- +
-[[|Obat Eksim]] [[|Obat Herbal Yang Ampuh Untuk Turunkan Gula Darah]]+