четвъртък, 29 ноември 2012 г.

Sharetronix Plugin Architecture - Part 1 (Overview)

Overview 

I want to provide you some information how the Sharetronix Plugin Architectures works. In this part the focus is how Sharetronix is managing the apps. In the second part i will take a look on the app itself, what is their structure and how they attach to events. 

To summarize Sharetronix plugin architecture i can say that it is events driven and every plugin(app) attach to the event it needs and return the results to this event. Well, that is very basically said.

First of all apps are stored in the ./apps folder. Every app has unique name and contain plugin.php file which handles the events in Sharetronix(more about this in Part 2). 
After an app is installed(automatically through admin panel or manually) in the database table "plugins" is stored information about the plugin installed.  

Sharetronix system has "Plugin Manager" which handles the events in the apps. On every single page event it first checks the "plugins" table in the database and get the installed (active) plugins, after that checks all plugins one by one if there is some one of them to want to interact with the called event. If there is, it stores the result, after all plugins are checked it stores the result(which plugin wants to interct with the event called) in the database table "plugins_cache" so next time the same event occurs will not be needed to check all plugins one by one, the needed plugins are stored in this table and the "Plugins Manager" just gets them.   When "Plugins Manager" has all plugins which wants to interact with the specific event it call them one by one. More about Sharetronix Events you can find here

How to store result in the view 

This is a typical view in Sharetronix


  1. <!DOCTYPE html>
  2. <html lang="{%html_lang_abbrv%}">
  3.         <head>
  4.                 <title>{%page_title%}</title>
  5.                 {%header_data%}
  6.         </head>
  7.         <body class="fixed-header layout-{%header_page_layout%}">
  8.                 <div id="layout-container">
  9.                        
  10.                                 <div id="header">
  11.                                         <div class="header-container">
  12.                                        
  13.                                                 {%logo_data%}
  14.                                                
  15.                                                 <div id="header-content">
  16.                                                
  17.                                                         {%header_content%}
  18.                                                
  19.                                                 </div>
  20.                                                
  21.                                                 <div class="clear"></div>
  22.                                         </div>
  23.                                 </div>
  24.                                
  25.                                 <div id="page-container">


 or view the code in pastebin.

When you see something like {%header_data%} this is sharetornix variable (placeholder) where controller put some data in it(not mandatory, if controller do not put something it will be deleted). 
This data is provided by the controller, of cource the event onPageLoad() calls all plugins. This event is called after the page loads so all the HTML is loaded in the template and every plugin could add some data it needs to it. 

Let's say we are in a plugin which wants to put some more data in the {%header_data%} on Page load (more about it in the next part). This is how the code looks (pastebin)


  1. public function onPageLoad()
  2. {
  3.         $this->setVar( 'header_data', 'Some data' );
  4. }


That's all. If you want to remove all {%header_data%} that controller has setup then (pastebin)


  1. public function onPageLoad()
  2. {
  3.         $this->setVar( 'header_data', 'Some data', 'replace' );
  4. }


just add 'replace' parameter and that's all. Now all {%header_data%} contents will be 'Some data'. 

This is how plugin events works for now. 

Something very useful about the plugins is that they can have its own controllers. Let's say you have a plugin which you will have to enter some data in it and after that this data to be shown on separate page on some event. In this case very useful is to create an own plugin controller. 

Plugin controllers are stored in ./apps/your-plugin-name/controller/controler-name.php 

Store all the data you need in this controller, you can use the Sharetronix template engine(more information here). 

To reach this plugin user should use the address:

http://site.com/plugin/your-plugin-name/controller-name 

of course you can send POST/GET data to this page if you want. 

That's for now. 

P.S. there is html chache mechanism wich caches some of the html content and stores it in the ./system/cache_html folder. Stored content means that this are pure html files and variables like {%header_data%} is replaced with HTML data. 

Sharetronix 3.0.0 is out!

Sharetronix 3.0.0 has been released near a month ago with new design and brand new plugin architecture. Our web site has beend changed, too - new appstore which helps developers to create apps and sell them to Sharetronix users. 

Whats new in Sharetronix 3.0.0 


First of all we redesigned Sharetronix. The new design is clear, sample and just beautiful :)! Download a copy of Sharetronix and install it on your server or visit our demo community to check this out. 

The Sharetronix 3 focus is to provide a clear installation with basic social features which can fit every  public community or business community. You can upgrade your community and add the features you need as apps from our app store. It is growing every day and we are adding new apps in it. Of course third party developers could submit their free or paid apps in there, too. 

Installation of new applications (functionalities) is simple and we made it to be as simple as one click install. To install an app go to Administration->Apps and see a list of apps we have in our appstore. 



There are free apps which you can install simply by clicking the "Install" button. Paid apps appear with "Buy now" button which leads you to our appstore where you can buy this app and aftre visiting you community administration page again the "Buy Now" button will be replaced with "Install" button and you can start installing the app. 
Of course there are some apps which need to make some database changes (tneed their own database tables where can store results) if you are installing such app, after clicking "Install" button you will be redirected to a confirmation page where you can see what changes the app needs to do and if you approve  it the installation will continue.  
To uninstall an app you just have to visit Administration -> Apps again and find the installed app you want to uninstall. When you find it just click on the "Uninstall" button and that's it. 

The second cool thing in Sharetronix 3 is our translation center.  From the upcoming Sharetronix 3.0.1 version our product will come only with english languages.
You can easily manage what languages to install in your community. You know best your members and can just leave the languages you need in your community. 
The language administration is located at Adminitration->Languages 


To install new languages just click the "Install" button and that's all. 
If you do not need any language anymore just click on "Uninstall" button and you're done. 
Language administration will automatically check our translation center and see if there is something new in any of installed languages you have. If there is, you will receive a number notification in the administration menu(see picture above) and an "Upgrade" button will appear on language which has something new added(see picture above).

That's for now, soon i am going to describe the plugin architecture so you can easily start writing plugins.