четвъртък, 13 декември 2012 г.

How to manually install an App

First of all, we have designed one-click app install feature in Sharetronix 3.0. So, if you want to install an app you just have to go in Administration->Apps and choose the app you want to install, then click on the "Install" button. 
To uninstall an  app you just have to found it in the Apps section in the administration panel and click the "Uninstall" button.

Manual Installation

However, there is no problem to install an app manually. And here i will share with you the steps to do this.

1. Go to our appstore  and choose the app you want to install.

2. Click on the "Download" button in the app's page to get the .zip archive containg the source code of the app.

3. Extract the .zip archive, the extracted files should be located in a folder with the App's name(eg. appname.zip => appname folder).

4. Upload this folder to your web host in the ./apps folder in your Sharetronix directory. eg.
./apps/
   appname
   ...
   anotherappname
   ...

5. Go to ./system/cache_html folder in your Sharetronix directory and delete all files in it.

6. Go to your database management tool and open your sharetronix database to insert installation data for the new plugin.

7. Select the "plugins" table in it and insert a new row.
name - the name of the plugin, it MUST be the same as your plugin folder name (uploaded in ./apps)
is_installed - 1
date_installed - some integer value, eg. 1, eg. 3123123, eg. 12312
installed_by_user_id - enter 1 or your user id in the community

8.Select the "plugins_cache" table and TRUNCATE this table(delete all rows in it).

9. Check if there is a file named "Installer.php" in your app's folder. If there is you should check what database changes it performs and do it manually. Then add these changes in "plugins_tables" table in the database(if the app creates a table you should add this table name in it).

10. That's it. Go to your community URL and refresh the page.

Manual Uninstall

It is the same as installation but, but backwards.

1. Delete your apps folder in ./apps
2. Delete all files in ./system/cache_html
3. Delete your app's row in "plugins" table in the Database
4. Delete all contents in the "plugins_cache" table in the Database
5. Check to see if there is a row with your app name in the "plugins_installed" table in the database.
6. Check to see if there is a row with your app name in the "plugins_tables" table in the database.
7. That's all. Refresh your community URL.



понеделник, 3 декември 2012 г.

Sharetronix Plugin Architecture - Part 2 (Plugin Basics)

Plugin(App) Basics 

In this part i want to take a basic look on the plugin itself and its main structure. Or with other words the files your plugin MUST have in order to be a valud plugin. In the next part (Part 3) we will see some additional files which you can add to your app, but they are not mandatory for a valid plugin.

All the plugins are stored in the ./apps/ folder (take a look on this page for more detailed information). Sample apps folder structure:


./apps/
         plugin_name_1/
         plugin_name_2/
         ...
         plugin_name_X/

Every plugin has its own unique name. So, you can not have two plugins named "mypluginname". Before you  build your plugin make sure it has uniques and recognizable name. You will find out if there are another plugins with that name on Appstore when you try to upload your plugin, there will be an error message if there is such plugin already.


plugin.php


The most important file for a plugin is the plugin.php file it should be located in the root plugin folder, ex. 
/apps/my_plugin/plugin.php 



This file contains the event hadling mechanism for it. 


Here is sample plugin.php file:
  • All events reactions( onPostLoad(), etc ), MUST be placed in a class with the SAME NAME as you plugins folder. So lets say you have ./apps/plugin_name/plugin.php. The class in the plugin.php file should be plugin_name (class plugin_name{}). 
  • Class methods names are the same as the events you want to attach your plugin. So if you want to attach some actions on onPostLoad() event you should have onPostLoad() method in your class in the plugin.php file. 
  • It is NOT mandotory to extend your plugin class with the plugin class but it is recommended. Your plugin will work without this, but the plugin class contains some useful ready to be used methods and variables which you do not have to write again


In Sharetronix there are a number of events which are triggered on some specific cases. Take a look on this event list. For example there is event onPageLoad() which is triggered when the page is loaded so you will have a chance to set some changes on the loaded page before it is loaded. Take a look on Part 1 to see how to change the header. 



  1. <?php
  2.         class myplugin extends plugin
  3.         {
  4.                 public function onPageLoad()
  5.                 {
  6.                         global $C;
  7.                         $this->setDelimiter( ' - ' );
  8.                         $this->setVar( 'page_title', 'hopa tropa' );
  9.                        
  10.                         if( $this->getCurrentController() == 'dashboard' ){
  11.                                 $this->setVar( 'main_content', '2' );
  12.                         }
  13.                 }
  14.                
  15.         }
  16. ?>

Clarification: before a plugin is triggered on a specific event, before that the controller of the page where we are located on this moment is loaded first. This means the controller prepare some data for the view and after that the plugins are triggered and they can change that data(delete/add). 

class plugin{}

This class contains the following properties:


$db2 - link to your database connection.
$network - network class, where a lot of cache functions are stored.
$page - class to read page parameters
$cache - if you want to use the cache
$user - the current user data 

And the following methods 

setVar( $name, $value, $action = 'add', $priority = 0 )

This is a main method, it is used to store data in the template. Take a look on the template view in Part 1. With this method you can store data in the template placeholder({%placeholder_name%}) you want. Example: 

$this->setVar('placeholder_name', 'value'); //where the value is HTML value you want to store in the template. 

The $action parameter by detault is "add", so you will add cont in the template placeholder you want. So, if the controller set the placeholder_name to be "<b>Some Text</b>", and after that you and your plugin set placeholder_name to be "<i>another text</i>", the result in placeholder_name in  the end in the template will be "<b>Some Text</b><i>another text</i>". This is because setVar() action by default is "add" - add information, if you set the action to be "replace" the plugin will replace the controller value. Ex.

$this->setVar('placeholder_name ', '<i>another text</i>', 'replace');

in this case in the placeholder_name in the template will only have "<i>another text</i>", no matter waht the controller(or other plugin has set).
setDelimiter( $value )

This method is very useful when you add some data in the template placeholder where the controller already has stored something else, like the previous example. Example: 

controller sets "<b>Some Text</b>" in the template placeholder_name. 

$this->setVar('placeholder_name ', '<i>another text</i>'); //you add  '<i>another text</i>' in the template 

The result in placeholder_name

<b>Some Text</b><i>another text</i>

but you can use the setDelimiter() method to separate the texts. 

$this->setDelimiter(' && ');
$this->setVar('placeholder_name ', '<i>another text</i>'); //you add  '<i>another text</i>' in the template 

The result in placeholder_name

<b>Some Text</b> && <i>another text</i>
getCurrentController()

Returns the name of the current controller where we are located, eg. dahboard, members, group. 

This is very useful if you want your plugin to be active onPageLoad() event and only in the user profile eg. controller name user.
getCurrentTab()

This is similar to the upper method but it return the current active tab in the controller we are located eg. all, posts, etc. So your app to be active only in a specific tab. 
isMobileRegime()

Returns TRUE or FALSE. If you are in the mobile interface it will returns TRUE, else FALSE. This is very useful when you want to put different content(HTML) in the mobile site. 

manifest.json file 

This is the second mandatory file your plugin should have. Contains the following information: 

{
"plugin_name": "The name of your plugin, must be same as your plugin folder name and class in plugin.php file",
"descr": "Basic description for your plugin.",
"version": "1.0",
"author": "Your name ",
"email": "email@email.com"
}

In the end a valid plugin should contain these two files: 

./apps/app_name/plugin.php 
./apps/app_name/manifest.json

that's all. 

P.S. When your plugin is ready it should be zipped and named like the folder in ./apps/ you want to create. The zip file should contain that folder. eg.

your_plugin_name.zip/
                                      your_plugin_name/
                                                                     plugin.php
                                                                     manifest.json



четвъртък, 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.