Creating Widgets for Havalite CMS

HavaLite CMS

A new liteweight Content Management System (CMS)

Creating Widgets for Havalite CMS

Widgets

Creating widgets in Havalite CMS is similar or almost the same way by creating plugins, accept we don't need to call the function "add_filter()" in our plugin file, we just use the index.php file of the plugin to activate the widget. This done by using the function "activateWidget()" in which we define:

  1. the name of the plugin widget
  2. the form content of the widget  (without the tag FORM)
  3. the function to call
  4. and how many arguments are needed for this function

Example:

<?php

// in this form we have 3 arguments: id="arg0", id="arg1" and id="arg2"
$input = 'Title<br />
<input type="text" name="w_myWidget_title" id="arg0" class="w_title" />
<textarea name="w_myWidget_textarea" id="arg1" rows="10" class="w_textarea"></textarea>
<p><label><input type="checkbox" name="w_myWidget_smilies" id="arg2" /> Use smilies?</label></p>';

activateWidget('myWidget', $input, 'myWidgetFunction', 3);

// if there is nothing to configure in the index.php file, we can redirect to the widget area and open the that window
widget_redirect('myWidget');

?>

Now we need to handle these 3 arguments with our plugin function but first we need to do all steps that need to be done like the way we created a plugin:

Create a folder in the "plugins" folder of havalite and give it a name same as the plugin or the widget you want to do (e.g. "myWidget") and create the following files in it:

  1. index.php and insert the upper example
  2. myWidget.php (here goes our function myWidgetFunction() or any other name)
  3. info.txt (only important by doing it public)
  4. myWidget.png (only important by doing it public)

open myWidget.php and insert following code:

<?php

function myWidgetFunction($args=''){
    $title = '';
    $text = '';
    $smilies = false;

    if(!empty($args)){
        parse_str($args);
        $title = $arg0; // the input value
        $text = $arg1;  // the content of the textarea
        $smilies = $arg2;  // the checkbox
    }

    $result = '<h2>'.$title.'</h2>';
    if($smilies) $text = smiley($text); // i'm using a function that already exists in havalite, but you can use your own functions as well

    $result .= '<div>'.$text.'</div>';

    return $result;
}

?>

Thats it!

The function myWidgetFunction(); reads the text that have been saved by the user, changes its content and view it in the choosen sidebar.

Download this tutorial to see how it works

comments powered by Disqus

0 Comments

    Leave a Reply

    Contact Info

    Phone: +49 941 26175

    Address: Ayman Teryaki,
    Prüfeninger Str. 48,
    93047 Regensburg, Germany

    Want more info - go to our contact page or visit Google+

    Social

    Stay up to date. Subscribe via RSS, Facebook, Twitter or Email

    Recent Comments