Sharetronix

Sharetronix App Events

From Sharetronix Developer Documentation
Jump to: navigation, search

onPageLoad()


This event is triggered before a page is being loaded. You can use it to load new data in the page or to prevent loading the page itself if it doesn't meet the plugin requirenments.

*You can use use getCurrentControllerName() method in your plugin to see which controller is loaded

  • You can use use getCurrentTabName() method in your plugin to see which tab is selected
  • If you want to use specific information like user ID of the user when you are on user profile page

you can use $page->params->user and $page->params->group for the group ID.

Example:

 
//page title is located in the 'page_title' template variable, so if we want to add text to it 
//we can use the following example triggered on 'onPageLoad' event
	
class example_plugin extends plugin
{
	public function onPageLoad()
	{ 
		$this->setVar( 'page_title', 'Page Title Example' );
	}
		
}

onPageSubmit()


This event is triggered when a form on a page is submitted(ex. after submitting a contact form). You can check $_POST/$_GET variables in your plugin and if you find not a corrent(for your plugin information) and set 'onPageSubmit_error' error desicription this will be detected and the submit process will be stopped and the error in 'onPageSubmit_error' will be displayed on the screen.

Example: 
class example_plugin extends plugin
{
	public function onPageSubmit()
	{
		$some_check = FALSE;
		//doing some checks
		if( !$some_check ){
			$this->setVar( 'onPageSubmit_error', 'My Error message!' );
		}
	}	
}

onUserSettingsSubmit()


This event is same as 'onPageSubmit' (see it above for more information) but it is triggered only on user settings pages (eg. User change email, change avatar).

Example:

 
class example_plugin extends plugin
{
	public function onUserSettingsSubmit()
	{
		$some_check = FALSE;
		//doing some checks
		if( !$some_check ){
			$this->setVar( 'onUserSettingsSubmit_error', 'My Error message!' );
		}
	}	
}

onAdminSettingsSubmit()


This event is same as 'onPageSubmit' (see it above for more information) but it is triggered only on administration settings pages (eg. Themes, managing apps).

Example:

class example_plugin extends plugin
{
	public function onAdminSettingsSubmit()
	{
		$some_check = FALSE;
		//doing some checks
		if( !$some_check ){
			$this->setVar( 'onAdminSettingsSubmit_error', 'My Error message!' );
		}
	}	
}


onPostLoad( $post_object )


This event is triggered before a single post load (eg. dashboard post). You receive the post object as a parameter, this will ensure that your plugin is receiving all the post data it needs, so you can modify it if you need.

Example:

//this plugin will add the post ID in the post's footer
class example_plugin extends plugin
{
	public function onPostLoad( &$var )
	{
		$this->setVar( 'activity_footer', 'Post ID: '.$var[0]->post_id );			
	}	
}

onPostCommentLoad( $comment_object )


This event is triggered before a single comment load (eg. comment on a dashboard post). You receive the comment object as a parameter, this will ensure that your plugin is receiving all the comment post data it needs, so you can modify it if you need.

Example:

class example_plugin extends plugin
{
	public function onPostCommentLoad( &$var )
	{
		$this->setVar( 'comment_footer', 'Comment ID: '.$var[0]->comment_id );			
	}	
}

onUserFollow( $user_object )


This event is triggered on before following a community member. You receive a user object(followed user) as a parameter, this will ensure that your plugin is receiving all the user data it needs, so you can modify it if you need. Just like the 'onPageSubmit' event you can setup an error message if plugin requirenments are not followed.

Example:

class example_plugin extends plugin
{
	public function onUserFollow( &$var )
	{
		$some_check = FALSE;
		//doing some checks
		if( !$some_check ){
			$this->setVar( 'onUserFollow_error', 'My Error message!' );
		}	
	}	
}

onUserUnfollow( $user_object )


This event is triggered on before unfollowing a community member. It is same as the 'onUserFollow' (click here for more information).

Example:

class example_plugin extends plugin
{
	public function onUserUnfollow( &$var )
	{
		$some_check = FALSE;
		//doing some checks
		if( !$some_check ){
			$this->setVar( 'onUserUnfollow_error', 'My Error message!' );
		}	
	}	
}

onGroupJoin( $group_object )


This event is triggered on before joining a community group. It is acting as the 'onUserFollow' event (click here for more information), but here you are receiving $group_object as a parameter.

Example:

class example_plugin extends plugin
{
	public function onGroupJoin( &$var )
	{
		$some_check = FALSE;
		//doing some checks
		if( !$some_check ){
			$this->setVar( 'onGroupJoin_error', 'My Error message!' );
		}	
	}	
}

onGroupLeave( $group_object )


This event is triggered on before leving a community group. It is as 'onGroupJoin' (click here for more information).

Example:

 
class example_plugin extends plugin
{
	public function onGroupLeave( &$var )
	{
		$some_check = FALSE;
		//doing some checks
		if( !$some_check ){
			$this->setVar( 'onGroupLeave_error', 'My Error message!' );
		}	
	}	
}

onPostSave( $post_object )


This event is triggered on before saving a post, $post_object is sent as parameter.

Example:

class example_plugin extends plugin
{
	public function onPostSave( &$var )
	{
		$some_check = FALSE;
		//doing some checks
		if( !$some_check ){
		        $this->setVar( 'onPostSave_error', 'My Error message!' );
		}	
	}	
}

onPostDelete( $post_object )


This event is triggered on before deleting a post, $post_object is sent as parameter.

Example:

class example_plugin extends plugin
{
	public function onPostDelete( &$var )
	{
		$some_check = FALSE;
		//doing some checks
		if( !$some_check ){
			$this->setVar( 'onPostDelete_error', 'My Error message!' );
		}	
	}	
}

onPostCommentSave( $comment_object )


This event is triggered on before saving a comment, $comment_object is sent as parameter.

Example:

class example_plugin extends plugin
{
	public function onCommentSave( &$var )
	{
		$some_check = FALSE;
		//doing some checks
		if( !$some_check ){
			$this->setVar( 'onPostCommentSave_error', 'My Error message!' );
	        }	
	}	
}

onPostCommentDelete( $comment_object )


This event is triggered on before deleting a comment, $comment_object is sent as parameter.

Example:

class example_plugin extends plugin
{
	public function onCommentDelete( &$var )
	{
		$some_check = FALSE;
		//doing some checks
		if( !$some_check ){
			$this->setVar( 'onCommentDelete_error', 'My Error message!' );
		}	
	}
}

onSingleUserLoad( $user_object )


This event is triggered before a single user load, like a single member on members page. $user_object like a parameter.

Example:

//this will add additional information on the user's block
class example_plugin extends plugin
{
	public function onSingleUserLoad( &$var )
	{
		$this->setVar( 'user_biz_card_more_personal_info', 'User ID: '.$var[0]->id );			
	}	
}

onSingleGroupLoad( $group_object )


This event is triggered before a single group load, like a single group on groups page. $group_object like a parameter.

Example:

 
//this will add additional description in the group's block
class example_plugin extends plugin
{
	public function onSingleGroupLoad( &$var )
	{
		$this->setVar( 'single_group_description', 'Group ID: '.$var[0]->id );			
	}	
}

onPageSetQuery()


This event is triggered when a page needs a query to proceed, for example the dashboard if you go to a custom tab the system will check if there is a query for this tab and will execute it. This event is used on dashboard, user, members, groups, group controllers.

Example:

//this plugin will add a query which will select everything in the posts table when a user goes to 
// http://example.com/dashboard/tab:custom
class example_plugin extends plugin
{
	public function onPageSetQuery()
	{
		if( $this->getCurrentController() == 'dashboard' && $this->getCurrentTab() == 'custom' ){
			return 'SELECT * FROM posts';
		}
	}
}

onPageSetQueryOrder()


This event is triggered with the 'onPageSetQuery' and is optional. With it you could order your query the way you need.

Example:

//this plugin will add a query which will select everything in the posts table when a user goes to 
// http://example.com/dashboard/tab:custom
class example_plugin extends plugin
{
	public function onPageSetQuery()
	{
		if( $this->getCurrentController() == 'dashboard' && $this->getCurrentTab() == 'custom' ){
			return 'SELECT * FROM posts';
		}
	}
		
	public function onPageSetQueryOrder()
	{
		if( $this->getCurrentController() == 'dashboard' && $this->getCurrentTab() == 'custom' ){
			return 'ORDER BY id';
		}
	}
}

onPageSetCountQuery()


This event is triggered on pages when there is pagination (members, groups pages). With this event you could set a count query needed for the pagination

Example:

//this plugin will add a query which will select everything in the posts table when a user goes to 
// http://example.com/members/tab:custom
class example_plugin extends plugin
{
	public function onPageSetCountQuery()
	{
		if( $this->getCurrentController() == 'members' && $this->getCurrentTab() == 'custom' ){
			return 'SELECT COUNT(*) FROM posts';
		}
	}
}
Personal tools
Namespaces

Variants
Actions
STX User guide
STX Developer guide
Sharetronix Sites