Adding a Plugin Directly To The Source Code
This tutorial is for:
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.
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:
The iOS Project
These are the project files that’ll be added to the Source Code.
JSON Data section
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:
This example loads a document from the applications bundle (compiled in Xcode or Eclipse). Note that a localFileName is used instead of a dataURL.
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).
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.
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.
“navBarTitleText”:”MySkylla’s 2nd ebook”,
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.
(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.)
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)
“navBarTitleText”:”MySkylla’s 3rd ebook”,
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:
1 .java class file is needed,
1 layout xml file is needed,
(a total of 2 files)
Just drag and stop these two files to the Source Code.
Step Six: Modify the files you just added:
Replace all instances of ‘BT_appDelegate’ with _appDelegate, in both implementation (.m) file as well as header (.h) files.
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.