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