The widget makes it easy to embed PGBuild into your CMS. The widget is embedded via an iframe and the widget communicates with the CMS via an connector class.
The widget and PGBuild does not manage/store project settings all required configuration is requested via the connector class, when the widget is displayed or when a compilation is started.
To embed the widget use and an iframe:
<iframe src="widget/widget.php?uid=10&project=20" width="540" height="280" frameborder="0" style="overflow:hidden"/>
It is possible to append several parameters to the url
uid, is a unique id you may use to identify the user or session. The uid is passed to the connector class which use the uid in subsequent calls to DB of cms system.
project, is the id of a project in the cms system. This value is passed to the connector which uses it to fetch project data.
Styling of the widget is done via /config/widget.css.
Configuration of the widget is done via /config/widget_config.php. It is possible to disable buttons and other behaviour. It is also here that you link the connector class to the widget.
localization is done by creating a file in the folder /localization. Default is uk.php. To change the language of the widget your specify you language in config/widget-config.php
Your connector class must implement the following methods, see and use the class in/connectors/sample/widget_connector.php as template.
function getProjects($uid)
Called by the widget when the project selector box is filled. Return an array where keys are project id's and values are project titles. $uid is passed from the url that loads the widget.
function getProjectConfig($uid,$idProject)
Called by the widget to get the configuration array used to control the compilation. See the sample projects in /connector/sample/projects for documentation.
function setPGBId($idProject,$pgbid)
Is called when a new project is uploaded to build.phonegap.com for the first time. $pgbid holds the id of the app on build.phonegap.com. You should store this id internally in your project data and pass it in the project config when getProjectConfig is called subsequently. It this is done the app will be updated on build.phonegap.com.
function allowWidget($uid)
The PGBuild widget lives outside your cms and don't known anything about user login or sessions. Any body who knows the location of PGBuild on your server may call and start builds via the widget.
To prevent this senario the widget calls allowWidget and gives you an opportunity to check if it is ok. Call functions in your own cms system to check if a user is logged in.