Adding Plugins directly to your Source Code bypassing the Control Panel

Adding a Plugin Directly To The Source Code

This tutorial is for:
Buzztouch.com users
Normal Self-hosted users
Self-hosted users that don’t wish to install the plugin onto their server

As more plugins become available a quandary is created for BTv2.0. When you decide to self-host you become an Administrator and now have the ability to add “Normal” Users to your Control Panel. Self-Hosted or Buzztouch.com “Normal” Users don’t have Administrative rights to install plugins to the Control Panel. The Administrator has to decide if and when the plugin is “ready for prime time”. No doubt the average User will certainly conclude the “new” plugin is necessary and ready for prime time long before most Administrators even know about the “new” plugin, much less had the time to evaluate the quality of the plugin.

For plugin developers you’ll find another problem. If you have a “New” plugin you wish to test, perhaps it’s for another developer.

So what could go wrong? Perhaps you remember about the posts on the Forum about someone’s Control Panel being shut down for days on end and it turned out that a bug in a “New” plugin was the cause. Or perhaps you have additional users on your Control Panel and don’t wish for them to use / download the plugin for one of various reasons. The users on your Control Panel just might be a bit unhappy about their apps or the Control Panel being shutdown because you’re testing a “New” plugin. Or perhaps your developer friend might be a bit unhappy to find their “New” plugin was published by another developer before they even release the plugin. They’ve thinking. “WTF??, How did they even get the code to the plugin?” Remember anyone downloading their app’s source code from your Control Panel will also download the “New” plugin’s source code if it’s installed on the Control Panel. Yes, your developer friend/client just might be a bit unhappy with you if it was published by someone that downloaded the plugin from your Control Panel. Unless you have a self-hosted Control Panel just for testing you might then you may have pause about adding the “New” plugin to your Control Panel.

Adding a Screen to your app

Adding a Screen or Action to your app involves adding the code and adding the JSON data to the Config file. Note: You have two Config files for most apps –
1. BT_config.txt, (found in the source code)
2. the Online Config file (found online, by default in your Control Panel)

Usually the code is added by adding the Plugin to the Control Panel and downloading the Plugin code through the Control Panel when you download the app’s source code.

The JSON data is usually added via the Control Panel. The JSON data is used to dynamically create an ‘instance’ (Screen) of the Plugin in the app.

Problem Both the plugin files and the BT_config.txt file are downloaded when you download the source code, however if the Plugin is not on the Control Panel this is not an option.

Solution: Add the plugin files directly to the Source Code, bypassing the Control Panel.

Therefore, the ability to add “New” plugins will become a skill many app developers will need to master.

THE PROCESS

To do so you need to:

Download / Acquire / Develop the “New” plugin

Unzip the plugin

Open up the plugin and look for the readme.txt file

Open up the file and become familiar with the plugins properties

Add the plugin file to your project (source code)

Add the JSON data

Reading the Readme.txt file:

You’ll want to pay attention to these parts in particular:

Project files

The iOS Project

and/or

Android Project

These are the project files that’ll be added to the Source Code.

JSON Data section

JSON Data
————————

Most folks (note: you are not “Most folks”, you are exceptional because you’re reading ‘Adding a Plugin directly to the Source Code’.) use the control panel to configure the JSON data for this plugin but it’s useful to see what it may look like. This example loads a document from a URL:

{
“itemId”:”343434″,
“itemType”:”BT_screen_pptDoc”,
“navBarTitleText”:”PowerPoint Doc”,
“dataURL”:”http://www.mydomain.com/sample.ppt”
}

This example loads a document from the applications bundle (compiled in Xcode or Eclipse). Note that a localFileName is used instead of a dataURL.

{
“itemId”:”343434″,
“itemType”:”BT_screen_pptDoc”,
“navBarTitleText”:”PowerPoint Doc”,
“localFileName”:”sample.ppt”
}

This is the JSON data that you’ll add to the Project_Config file.

For Android there’s only two non-Buzztouch plugins (both by Raveyd) at the time of writing this article. So we’ll go through the process of adding the eBook Plugin to the Source Code.

Let’s take a look at the eBook plugin’s readme.txt file and scroll down to the JSON data section. (Note: I modified the text to simplify this tutorial).

JSON Data.
————————

The online control panel is used to configure the JSON data for this plugin but it’s useful to see what it may look like.

{
“itemId”:”123456001″,
“itemType”:”BT_screen_ebook”,
“navBarTitleText”:”MySkylla’s ebook”,
“dataURL”:”http://www.myskylla.com/ebook.html”
}

THE STEPS

To add this Plugin / Screen to your app requires eight steps:

Step one: Add the item to either:
a. Tabbed Layout (making the screen a home screen), or
b. Add the item to a menu screen.
Read my articles regarding JSON for this step.

Step two: Copy the “New” Plugin’s sample JSON data from the Readme.txt file.

Step three: Go to the Source Code and open up the BT_config.txt file and paste the JSON data where appropriate.

{
“itemId”:”123456002″,
“itemType”:”BT_screen_ebook”,
“navBarTitleText”:”MySkylla’s 2nd ebook”,
“dataURL”:”http://www.myskylla.com/ebooknumber2.html”
}

Note: the itemId is any unique number you wish to use. Yes, you can just make one up, no permission is required from any one. It just has to be unique, as in “not used by another screen”.

Don’t modify the itemType.

Modify the “navBarTitleText”:  Just change “MySkylla’s 2nd ebook” to any text you wish to display in the Nav Bar. For example “My Cool Nav Bar Title” or “Poetry by Fred”.

The eBook plugin is based on the Custom HTML text plugin. It’s supposing that you’ll have the HTML file saved on the server hosting the Control Panel. But since you’re not using the eBook plugin via the Control Panel you have two options.

Option #1:

“localfilename”:”sample.html”
(Note: I haven’t tried using an embedded file with the eBook plugin, so this may not work without a modification to the .xml file and the .java file. I expect it’ll work.)

or,

Option #2:

“dataURL”:”http://www.placeYourUrlInfoHere.html”

For additional eBooks you just modify the JSON data. Just add 1 to the itemId. You may wish to also modify the “navBarTitleText” & the “dataURL”.

Here’s a sample. (Note: the “itemType” remains unchanged)

{
“itemId”:”123456003″,
“itemType”:”BT_screen_ebook”,
“navBarTitleText”:”MySkylla’s 3rd ebook”,
“dataURL”:”http://www.myskylla.com/ebooknumber3.html”
}

Step Four: we need to add Project files to the Source Code.

The readme.txt file states:

For iOS: (Since the eBook plugin is Android only I’ll use the PDF plugin info)

Add the project files to the source code (the plugins directory is suggested).

For Android you’ll find:

Android Project.
————————
1 .java class file is needed,
1 layout xml file is needed,
(a total of 2 files)
BT_screen_ebook.java
screen_ebook.xml

Just drag and stop these two files to the Source Code.

Step Six: Modify the files you just added:

For iOS:

Replace all instances of ‘BT_appDelegate’ with _appDelegate, in both implementation (.m) file as well as header (.h) files.

For Android:

Modify the .java file:

On line 40 you’ll find: package com.buzzTouch;

Change “com.buzzTouch;” to your app’s package name, so for example it would read: package com.MySkylla.appOne;

Step Seven: Compile and run the Project.

Step Eight: Now you’ll have a problem, in that every time you ‘refresh’ your app, you’re going to wipe out any of your changes you’ve made to the BT_config.txt file, because the added JSON data is not in your control panel. To resolve this you can either take the app Offline so that the Config file doesn’t update, or you can point the app’s DataURL to a Config file you publish elsewhere.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s