11 years ago

11 years ago

Tickets General

3215

Writing Plugins

Plugins allow you to extend Tickets without modifying the core code. This means that you can easily distribute extra functionality without requiring users to make any code changes.

Plugins also allow users to upgrade to a new version of Tickets without needing to re-apply code changes.

We have example code foundĀ here.


Plugin Hooks

A plugin hook is an area where your plugin can interact with Tickets.

During sections of processing Tickets will call a plugin hook, this is where your plugin comes alive.

The plugin system allows you to add sections to Tickets that look exactly like the built in functionality.

Below is an example of creating a hook.

//get the plugins class
$plugins 		= &sts\singleton::get('sts\plugins');
//setup a hook
$plugins->add(
	array(
		'plugin_name'	=> 	__CLASS__,
		'task_name'		=> __CLASS__ . 'section_name',
		'section'		=> 'section_name',
		'method'		=> array($this, 'section_name')
	)
);

Plugins are stored in the user/plugins/ folder and can be activated from the settings page.

Section Name Area Example Use Version
loader Runs at the end of loader.php Useful for setting up data after all plugins are loaded. 1.4+
html_header Runs in the HTML head section. Useful for loading in extra CSS or Javascript files. 1.4+
html_header_nav_start Runs in the HTML menu section. Useful for adding extra menu items. 1.4+
html_header_nav_settings Runs in the HTML settings menu section. Useful for adding extra menu items to the settings drop down. 1.4+
plugin_page_header_* Runs before the HTML header in a specific/requested page. Visit /p/examplecsslist/ and plugin_page_header_examplecsslist is called. Visit /p/foo/ and plugin_page_header_foo is called.
This section should be used to set the title of new pages (and other page setup) for logged in users.
1.4+
plugin_page_body_* Runs in the body of a specific/requested page. Visit /p/examplecsslist/ and plugin_page_body_examplecsslist is called. Visit /p/foo/ and plugin_page_body_foo is called.
This section should be used to create HTML in the body of the new page. For logged in users.
1.4+
public_page_header_* Runs before the HTML header in a specific/requested page. Visit /public/examplecsslist/ and public_page_header_examplecsslist is called. Visit /public/foo/ and public_page_header_foo is called.
This section should be used to set the title of new pages (and other page setup). For pages that don't require the user to be logged in.
1.4+
public_page_body_* Runs in the body of a specific/requested page. Visit /p/examplecsslist/ and public_page_body_examplecsslist is called. Visit /p/foo/ and public_page_body_foo is called.
This section should be used to create HTML in the body of the new page. For pages that don't require the user to be logged in.
1.4+
cron_* Runs when a specific cron interval is run. Useful for background processing or tasks that need to happen often.
Hooks include: cron_every_five_minutes, cron_every_hour, cron_every_day, cron_every_week and cron_every_month.
1.4+
download_other_files Runs in /files/download/ when ticket_id isn't set Useful for downloading other files.
Use method download_other_files(&$files) and pass an array of files from the storage class.
1.5+
view_ticket_details_finish Runs in the view ticket page after the ticket details (guest portal included). Useful for displaying extra details about a ticket. 2.2+
view_ticket_user_details_finish Runs in the view ticket page after the users details (guest portal included). Useful for displaying extra details about a user on the ticket page. 2.2+
view_ticket_sidebar_finish Runs in the view ticket page after all sidebar boxes (guest portal included). Useful for adding an extra sidebar box. 2.2+
profile_content_finish Runs after the content on the profile page. Useful for adding extra content boxes on the profile page. 2.2+
auth_logged_in_start Runs when "if logged in" is checked in the system. Useful when using a custom login system. 2.2+
auth_load_start Runs when the logged in user is loaded from the database. Useful when using a custom login system. 2.2+
auth_login_start Runs when a user logs in. Useful when using a custom login system.
An array of the username and password is passed to this hook.
2.2+
auth_logout_start Runs when the user logs out. Useful when using a custom login system. 2.2+
view_user_sidebar_finish Runs on the left side of the view user page. Useful for adding extra information or sidebar widgets. 2.5+
view_user_details_finish Runs in the main content box of the view user page. Useful for adding extra user data. 2.5+
submit_register_form_success_before_create_user Runs after a user has successfully registered but before the account has been created. Useful for validating any extra form fields that have been added. 2.5+
submit_register_form_success_after_create_user Runs after a user has successfully registered and been created. Useful for storing any extra form fields. 2.5+
view_register_sidebar_finish Runs on the left side of the view regsiter page. Useful for adding extra information or sidebar widgets, or explaining extra form fields. 2.5+
view_register_form Runs in the register form Useful for adding extra form fields. 2.5+
view_user_content_finish Runs after all existing user data on the view user page. Useful for adding lists or large amounts of extra user data. 2.5+
view_tickets_content_start Runs above the tickets list. Useful for adding alerts above the main tickets index view page. 2.5+
view_tickets_content_finish Runs below the tickets list. Useful for adding less important information to the tickets index view page. 2.5+
api_default_action Runs when an unknown (custom) api_action is requested. Useful for adding custom API calls. 3.0+ (use api_hook_authenticated_* for 4.1+)
api_unauthenticate_action Runs when an unauthenticated (custom) api_action is requested. Useful for adding custom API calls. 3.1+ (use api_hook_unauthenticated_* for 4.1+)
body_header Runs just after the html body is loaded (for every page). Useful for adding google analytics etc. 3.2+
api_hook_authenticated_* Runs when an authenticated (custom) api_action is requested. Useful for adding custom API calls. 4.1+
api_hook_unauthenticated_* Runs when an unauthenticated (custom) api_action is requested. Useful for adding custom API calls. 4.1+