You will need to make the following files to make a widget.
1. Folder with the widget name and 2 files inside
-1a. widget.php
-1b. config.xml
Step 1
in the config.xml file write out your configurations
1 2 3 4 5 6 7 |
<?xml version="1.0" encoding="ISO-8859-1"?> <Widget> <className>HelloWorld</className> <name>Hello My World!</name> <description>This is my Hellow World</description> <version>1.1.1.1</version> </Widget> |
Step 2
Once you have this done, open up your widget.php
You will need 3 functions in your widget.php class
get_config() – returns a value for the configuration to be displayed
update_config($values)
*NOTE* Do NOT have any ‘echo’ or ‘print’ inside the class as this will be detected before it launches the widget. Echo exclusion is because of formatting purposes.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
<? class HelloWorld { //default content private $content = "<h1>HELLO WORLD!</h1>"; //renders the content function get_content() { //use the property class to get content from db include_once("classes/Property.php"); //name of the property $name = "Widget_HelloWorld_greetings"; //create the property to get information $property = new Property_users($name); //if this property gets the information, show the information out if($propertyInfo = $property->get_property($name)) {return "<h1>".addslashes($propertyInfo)."</h1>";} //if not give a default content else {return $this->content;} } //renders the configuration function get_config() { // the name of the property must follow the conventions Widget_<Classname>_<propertyName> // have the form post and make sure the submit button is named widget_update // make sure there is also a hidden value giving the name of this Class file return "<form id='configForm' method='post'> <input type='hidden' name='class' value='HelloWorld'></input> <select name='Widget_HelloWorld_greetings'> <option value='Hello World!'>Hello World!</option> <option value='Goodbye World!'>Goodbye World!</option> </select> <input type='submit' class='submitBut' name='widget_update' value='Update config'/> </form>"; } //updates the configuration function update_config($values) { //calls on for the database class include_once("classes/Property.php"); $property = new Property_users(); //sets the properties to store them, use a switch statement to store different description based on different properties $property->set_property($values['name'],$values['value'], "The Hellow world property description"); } } ?> |
It is important that you understand the naming convention of your properties names to be
1 |
Widget_<Classname>_<propertyName> |
.
Remember to have a submit button named ‘widget_update’ and a hidden value name class with your class filename inside or else your codes will NOT load.
Step 3
Put your folder with the files inside into the widgets folder and you’re set to go!