Plugins and Widgets Development

HavaLite CMS

A new liteweight Content Management System (CMS)

Plugins and Widgets Development

How to develope Plugins and Widgets for Havalite CMS

Plugins in Havalite need always to be set in a specified folder and this folder name must be the same as the plugin name! The plugin folder should have 4 different files:

  1. the plugin file (same name as the folder). Here we add our created function/s by using the function add_filter()
  2. info.txt (infomations about the plugin). We can also use html
  3. index.php (leave empty if no configuration is needed) or (design it as a configuration part of the plugin or to activate widget)
  4. plugin image. (a png image with same name as the plugin, max width/height = 50px)

example:

  1. plugin folder = myPlugin,
  2. plugin name = myPlugin.php,
  3. image name = myPlugin.png,
  4. info file = info.txt,
  5. cofiguration file = index.php

Explanation

When Plugins are registered in the database, they get beside the Plugin-Name and Plugin-Id three different empty values: value1, value2 and value3. Plugin developers can use these values to save data for plugin configurations. In this way our db stays clean when ever we remove or add a plugin. We have also a style column to create a new style for CKEditor which will be added to the styles pulldown menu.

If you offer configuration part to your plugin in index.php, than you can use all functions listed in the file hava_func.php including the functions listed below.

Variables and Functions

$pluginId The Id number of your registered plugin
$hava_plugin_data; Plugin developers can save informations in the database, which can be retrieved from this variable.

$hava_plugin_data returns an array:

  1. id
  2. name
  3. value1
  4. value2
  5. value3
  6. style (make additional styles to CKEditor)

$myPluginName = $hava_plugin_data['name'];

add_filter($func, $pos); Create a function and add it to any of the 5

$func = the name of the function to add
$pos = the position where the function proceed
  1. the_begin (use before printing)
  2. the_head (usage mostly for scripts, styles)
  3. the_content (include additional code at end of the content)
  4. the_sidbar (for meu in the sidebar)
  5. the_footer
add_filter('myPluginFunc', 'the_head');
add_editor_style($pluginId, $style); To offer an easy use of the plugin for the user, we can add a style to CKEditor

{name:'plugin name',element:'a',attributes:{rel:''}}

 

Widgets

activateWidget($name, $input, $func, $args);

If its called within a plugin configuration (index.php of the plugin) a widget will be added to the widgets configuration area

  • $name = the name of the plugin (same as widgets name)
  • $input = need to view some form elements to be filled from the user
  • $func = the function that needs to be called when submitting input informations
  • $args = how many arguments needed for the function

$input = 'Title<br /><input type="text" name="w_'.$val['name'].'_title" id="arg0" class="w_title" /><p><a href="hava_plugin.php?pluginId='.$val['id'].'">Edit Plugin</a></p>';
activateWidget($val['name'], $input, 'callMeFunction', 1);

widget_button($name, $pos = 'right')

To show blog administrator that the plugin can also be configured with a widget, we can add a button with a link to the widget

  • $name = the name of the plugin
  • $pos = right, left, center or none

widget_button($hava_plugin_data['name'], 'none')

   

 

 

  • $p   // id of selected post
  • $s   // search word/phrase
  • $cat   // name of selected category
  • $postCount   // amount of all posts
  • $draftCount   // amount of all drafts
  • $pagesCount   // amount of all static pages
  • $catCount   // amount of all categories
  • $pagesCat   // the category for static pages
  • $imageCount   // amount of all images
  • $swfCount   // amount of all swf
  • $linkCount   // amount of all created links
  • $templateUrl   // the url adresse of the used template
hava_options($opt); Retrieve the value of a single option from Table "options"
$opt is one of the following properties:
  • url   // url of the site
  • title   // title of your blog
  • tagline   // tagline of your blog
  • description   // description of your homepage
  • language   // interface language in the admin area
  • theme   // theme used
  • thumbnail   // size of the thumbnail for images
  • limit_res   // how many posts or images to be viewed
  • page_cat   // which categrory should be for static pages
  • date_time   // date format
  • noteEmail   // on/off - get messages by new comments
  • editorHeight   // The height of CKEditor
  • filterMax   // use GD filters for images that have max height (e.g. 600)
  • post_amount   // the number of posts to be viewed
  • notes   // Sticky Notes text
  • editorConfig   // configuration of the CKEditor
  • yearMonthCat   // on/off - images category get a name according to Year/Month
  • frontPage   // latest post or static page
  • editorStyles   // additional styles which appears in CKEditor styles
  • usersBoard    // whether text or html
  • usersLvl   // Admin can define 5 different levels for registrated persons
  • mobile   // yes/no - change to mobile style if the template got one
  • add_styles   // to differentiate between registered users who write in the dashboard, every name can have his own style (#brd_admin = the style of the admin)
  • error_page   // insert some Text to view when visitors get error page
  • widgets   // name of all widgets, in which sidebar, whether active or not
  • backup   // standard or zipped
  • similar_post   // on/off - views keywords of the current post with a search link for every word
hava_options('url');
hava_all_queries($SQL, $data = array())

returns array

  • $data = should be array with sql values if WHERE statment exists, other wise set ''
hava_single_query($SQL, $data, $col='')

returns single array

  • $data = the sql value if WHERE statment exists, other wise set 'all'
  • $col = column name
saveSqlite($SQL, $data, $insert=false);

Save single query to db.
$data must be array
$insert => set true to retrieve the last inserted id

saveSqlite("INSERT INTO posts (title, text) VALUES (?, ?)", array("New post", "The text of the new post"), true);  // this will insert a new post and returns the last id

hava_num_rows($SQL, $data = array()) Retrieve the amount of rows for any table

hava_num_rows("SELECT * FROM images WHERE images_cat = ?" array('2011'));
table_exists($table)  
column_exists($table, $column, $sql='')  
hava_pages_cat() The name of the category for static pages (or use $pagesCat)

echo hava_pages_cat();
hava_cat_list($def) Sort all categories
hava_img_cat($list) Sort all image categories
hava_gravatar( $email, $s='', $d='', $class=false)

Gravatar image according to mail adresse

  • $s = size of image
  • $d = default image (mm, identicon, monsterid, wavatar, retro or url adresse of an image)

hava_gravatar('myemail@web.com');

validate($email); Validating email. The function is also used by save_comment();

validate('myemail@web.com');
correctUrl($url) Check if url has -> http:// . If not, return the right methode

correctUrl('www.myurl.com');
hava_date($myDate, $formate='') get date formate as set bei the user
  • $myDate   // set the date (2012-08-14 20:30)
  • $formate   // define own formate or leave empty

hava_date('2012-08-14', 'd.M.y');

hava_comments($postId) Returns all comments to the specified post id
hava_comments(3);
   
   
   

 

comments powered by Disqus

2 Comments

  1. Written by: ramzy
    on 03.Sep.2012
    Hello
    Any tutorial for widgets?
  2. Written by: admin
    on 03.Sep.2012
    Hi
    yep see this one here

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