AddonSDK

From WoWRosterWiKi
(Difference between revisions)
Jump to: navigation, search
Line 548: Line 548:
  
 
==Creating the Search Class==
 
==Creating the Search Class==
 +
===Properties===
 +
* var <span style="color:maroon;">$options</span>
 +
*: Is be used to to add advanced options to the search page
 +
 +
* var <span style="color:maroon;">$result</span>
 +
*: Search arrey
 +
 +
* var <span style="color:maroon;">$result_count</span>
 +
*: Counter for results display
 +
 +
* var <span style="color:maroon;">$link_next</span>
 +
*: Used to create a url to the next page of results
 +
 +
* var <span style="color:maroon;">$link_prev</span>
 +
*: Used to create a url to the previous page of results
 +
 +
* var <span style="color:maroon;">$data</span>
 +
*. An arrey that holds all of the addons data
 +
 +
* var <span style="color:maroon;">$page</span>
 +
*: Counter for page number
 +
 +
* var <span style="color:maroon;">$limit</span>
 +
*. Counter for the number of results that can be displayed per page
 +
 +
* var <span style="color:maroon;">$sql_query</span>
 +
*:
 +
* var <span style="color:maroon;">$the_query</span>
 +
 +
* var <span style="color:maroon;">$url_query</span>
 +
*: Urlencoded query
 +
 +
* var <span style="color:maroon;">$item['results_header']</span>
 +
*. When this variable is used it will add a header above each result with in that addon search
 +
 +
* var <span style="color:maroon;">$item['html']</span>
 +
*. When used this variable allows you to display your own formated html code which over rides any predefined search display
 +
 +
* var <span style="color:maroon;">$item['author']</span>
 +
*: Used to display the author of a post/update/upload
 +
 +
* var <span style="color:maroon;">$item['date']</span>
 +
*. var that will print the date
 +
 +
* var <span style="color:maroon;">$item['url']</span>
 +
*: Variable used to create a makelink() to the results addons home page
 +
 +
* var <span style="color:maroon;">$result['title']</span>
 +
*. Displays the title of the addon
 +
 +
* var <span style="color:maroon;">$result['short_text']</span>
 +
*. Used to give a short description of the result
 +
 +
* var <span style="color:maroon;">$result['more_text']</span>
 +
*: Used to create a secondary link per result
 +
 +
* var <span style="color:maroon;">$result['footer']</span>
 +
*. If desired allows each addon result to have a custom footer
 +
 +
* var <span style="color:maroon;">$result['results_footer']</span>
 +
*. Used to create a footer for the addon results overall footer
 +
 +
 +
 +
===Example File===
 +
Here is an example of an AddOn install file<br>
 +
From the "Keys" AddOn
 +
 +
You can find more examples in the addons/ folder in roster
 +
<php><?php
 +
 +
class news_search
 +
{
 +
var $options;
 +
var $result = array();
 +
var $result_count = 0;
 +
var $link_next;
 +
var $link_prev;
 +
var $data = array(); // Addon data
 +
 +
 +
function search( $search , $url_search , $limit=10 , $page=0 )
 +
{
 +
global $roster;
 +
 +
$first = $page*$limit;
 +
 +
$q = "SELECT `news`.`news_id`, `news`.`author`, `news`.`title`, `news`.`content`, `news`.`html`, "
 +
. "DATE_FORMAT(  DATE_ADD(`news`.`date`, INTERVAL " . $roster->config['localtimeoffset'] . " HOUR ), '" . $roster->locale->act['timeformat'] . "' ) AS 'date_format', "
 +
. "COUNT(`comments`.`comment_id`) comm_count "
 +
. "FROM `" . $roster->db->table('news','news') . "` news "
 +
. "LEFT JOIN `" . $roster->db->table('comments','news') . "` comments USING (`news_id`) "
 +
. "WHERE `news`.`news_id` LIKE '%$search%' "
 +
. "OR `news`.`author` LIKE '%$search%' "
 +
. "OR `news`.`date` LIKE '%$search%' "
 +
. "OR `news`.`title` LIKE '%$search%' "
 +
. "OR `news`.`content` LIKE '%$search%' "
 +
. "GROUP BY `news`.`news_id` "
 +
. "LIMIT $first," . ($limit+1) .";";
 +
 +
$result = $roster->db->query($q);
 +
$nrows = $roster->db->num_rows($result);
 +
 +
$x = ($limit > $nrows) ? $nrows : $limit;
 +
if( $nrows > 0 )
 +
{
 +
while( $x > 0 )
 +
{
 +
list($news_id, $author, $title, $content, $html, $date, $comments) = $roster->db->fetch($result);
 +
 +
$item['author'] = $author;
 +
$item['date'] = $date;
 +
$item['title'] = $title;
 +
$item['url'] = makelink('util-news-comment&amp;id=' . $news_id);
 +
 +
if( $html == '1' && $this->data['config']['news_html'] >= 0 )
 +
{
 +
$content = $content;
 +
}
 +
else
 +
{
 +
$content = htmlentities($content);
 +
}
 +
$content = nl2br($content);
 +
 +
$array = explode(' ',$content,101);
 +
if( isset($array[100]) )
 +
{
 +
unset($array[100]);
 +
$item['more_text'] = true;
 +
}
 +
else
 +
{
 +
$item['more_text'] = false;
 +
}
 +
$item['short_text'] = implode(' ',$array);
 +
 +
$item['footer'] = ($comments == 0?'No':$comments) . ' comment' . ($comments == 1?'':'s');
 +
 +
$this->add_result($item);
 +
unset($item);
 +
$x--;
 +
}
 +
}
 +
 +
if( $page > 0 )
 +
{
 +
$this->link_prev = '<a href="' . makelink('search&amp;page=' . ($page-1) . '&amp;search=' . $url_search . '&amp;s_addon=' . $this->data['basename']) . '"><strong>' . $roster->locale->act['search_previous_matches'] . $this->data['basename'] . '</strong></a>';
 +
}
 +
if( $nrows > $limit )
 +
{
 +
$this->link_next = '<a href="' . makelink('search&amp;page=' . ($page+1) . '&amp;search=' . $url_search . '&amp;s_addon=' . $this->data['basename']) . '"><strong> ' . $roster->locale->act['search_next_matches'] . $this->data['basename'] . '</strong></a>';
 +
}
 +
}
 +
 +
function add_result( $resultarray )
 +
{
 +
$this->result[$this->result_count++] = $resultarray;
 +
}
 +
}
 +
</php>
  
  

Revision as of 07:31, 12 August 2007

WR.net

Important note: When you edit this page, you agree to release your contribution into the public domain.
If you do not want this or can not do this because of license restrictions, please do not edit.

Contents


WoWRoster v1.8.0b AddOn Development

Readme Updated: 22:25, 25 July 2007 (PDT)

This document is being revised as 1.8 goes through development
Keep checking back for changes and additions

Changes


Info and Download

You can view the open source project at http://www.wowroster.net

For corrections and/or suggestions - http://www.wowroster.net


Thanks to: http://www.wowroster.com
And Everyone involved in the project.


Download the Roster AddOnSDK



Certified WoWRoster AddOn

Certified WoWRoster AddOn

AddOns that conform to our Coding Standards and the basic outline described within this document, will be given a "AddOn Framework Standards Compliant" stamp of approval.


Requirements for Approval


Basics of an AddOn

The following are required to run the WoWRoster back-end and to be able to run any AddOns
>Roster Requirements<

The AddOn system is designed so that you can mod the roster base without having to change the base code as it could change a lot between versions.
Hopefully with this system we will be closer to having a drop-in module system without having to mod a lot of the base files each time.

We will be constantly refining the system as we go along.
So with each new version of Roster, some AddOns may break (not work in the new WoWRoster)

Tools clipart.png Important:

DO NOT use php short tags in your php files
This is also stated in the WoWRoster Coding Standards
NO! <?  ?>
YES <?php  ?>
NO! <?=$var; ?>
YES <?php echo $var; ?>
Use the "long tags" as the short ones can break web servers with short_tags set to "off"


Changes Since 1.7.3


AddOn Framework

Features

  1. Uses output buffering, which means all the output is stored in a variable that is sent to the browser
  2. Do not have to include Roster's conf.php
  3. Do not have to include/declare $roster object
  4. Do not have to connect to Roster's database
  5. Do not have to include your inc/conf.php
  6. AddOn files: inc/conf.php, style.css, inc/update_hook.php, and locale files are OPTIONAL!
    Even additional locale files are optional, enUS.php is the default locale, and is required if you have locale files


What it does

  1. Includes all Roster config variables for you to use ($roster->config)
  2. Includes all Roster SQL functions for your use ($roster->db)
  3. Includes all Roster and AddOn language variables for you ($roster->locale->wordings, $roster->locale->act)
  4. Includes all Roster css styles
  5. The Roster header, footer, and menu are included to your files.
    These can be disabled if needed, more below...

Best of all, this is transparent to you!


AddOn Directory Structure

Here is an example of an AddOn's directory structure

roster/
|_ addons/
   |_ addonname/
      |_ admin/
      |  |_ index.php
      |  |_ other.php
      |
      |_ char/
      |  |_ index.php
      |  |_ other.php
      |
      |_ guild/
      |  |_ index.php
      |  |_ other.php
      |
      |_ inc/
      |  |_ conf.php
      |  |_ functions.php
      |  |_ install.def.php
      |  |_ search.inc
      |  |_ update_hook.php
      |
      |_ locale/
      |  |_ deDE.php
      |  |_ enUS.php
      |  |_ esES.php
      |  |_ frFR.php
      |
      |_ realm/
      |  |_ index.php
      |  |_ other.php
      |
      |_ index.php
      |_ somefile.php
      |_ util.php


admin Folder

The admin folder houses files for the Roster CP
Normally you'll never need files here because the Config API can handle most configuration needs

If you do need a custom config interface, this is where you make it

Info.png Note: The File parameter is optional

This will normally grab your AddOn's config data from the 'roster_addon_config' table in the database and display the options using the Config API

If you need your own file, you need only to place index.php in addons/addonname/admin/

You can also have the best of both worlds
For example, the Members List and Character Info AddOns use both the Config API and custom files


char Folder

Files for use in the Character scope
Data for the requested character is passed to the AddOn
If member= is not specified or if this member does not exist, an error message will display

member= can be either the member id number, or name@realm text

Accessing other files in the char scope is easy
addons/addonname/addonname/char/file.php is accessed like this:


guild Folder

Files for use in the Guild scope
Data for the requested guild is passed to the AddOn
If guild= is not specified, the default guild/realm name set in Roster CP will show
If the guild does not exist or if there is no data for this guild, an error message will display

guild= can be either the guild id number, or name@realm text

Accessing other files in the guild scope is easy
addons/addonname/guild/file.php is accessed like this:


inc Folder

This folder houses special files not meant for direct access by the AddOn Framework
These files are conf.php, install.def.php, search.inc, and update_hook.php
You can also use this folder for lib, library, and/or functions files

Place any files here that you do not or should not be accessed directly by the AddOn Framework


locale Folder

Where locale translation files go
See below for more info Locale Files


realm Folder

Files for use in the Realm scope
Data for the requested realm is passed to the AddOn
If realm= is not specified, the default realm name set in Roster CP will show
If the realm does not exist or if there is no data for this realm, an error message will display

realm= can be text

Accessing other files in the realm scope is easy
addons/addonname/realm/file.php is accessed like this:


Other Files and the util Scope

Files not in these folders are considered under the util scope
This scope is not restricted if there is no guild or character information and can be accessed before data is in the database

Accessing other files in the util scope is easy
addons/addonname/file.php is accessed like this:


Required Files

There are a few files that you must have


Linking to AddOns

You can link to any file in the root AddOn folder

The url to access each page is simple

Info.png Note: "file" is optional

The values explained


Creating the Installer

This installer requires a similar install file definition as DragonFly CMS, with some important exceptions:

You should create a file called inc/install.def.php with in it a class that is named identical to your AddOn's install directory name.
This name will be referred to as your AddOn's basename.


Properties

$credits = array(
	array(	"name"=>	"Name",
		"info"=>	"Some Info"),
	array(	"name"=>	"Another Name",
		"info"=>	"More Info"),
);


Methods

Info.png Note: You should supply your own file to be called for upgrades of a Roster 1.7.x AddOn since Roster 1.8 cannot detect these AddOns.


Adding Queries

Queries are added to the install using the $installer methods.


Creating/Editing Menu Entries

There are 3 separate functions for this.
Note the title should be unique per AddOn.


Example File

Here is an example of an AddOn install file
From the "Keys" AddOn

You can find more examples in the addons/ folder in roster

<?php
/**
 * WoWRoster.net WoWRoster
 *
 * LICENSE: Licensed under the Creative Commons
 *          "Attribution-NonCommercial-ShareAlike 2.5" license
 *
 * @copyright  2002-2007 WoWRoster.net
 * @license    http://creativecommons.org/licenses/by-nc-sa/2.5   Creative Commons "Attribution-NonCommercial-ShareAlike 2.5"
 * @version    SVN: $Id: install.def.php 897 2007-05-06 00:35:11Z Zanix $
 * @link       http://www.wowroster.net
 * @package    InstanceKeys
 * @subpackage Installer
*/
 
if ( !defined('ROSTER_INSTALLED') )
{
    exit('Detected invalid access to this file!');
}
 
/**
 * Installer Instance Keys Addon
 *
 * @package    InstanceKeys
 * @subpackage Installer
 */
class keys
{
	var $active = true;
	var $icon = 'inv_misc_key_06';
 
	var $upgrades = array(); // There are no previous versions to upgrade from
 
	var $version = '1.8.0.0';
 
	var $fullname = 'Instance Keys';
	var $description = 'Lists Azeroth Dungeon keys for Members';
	var $credits = array(
	array(	"name"=>	"WoWRoster Dev Team",
			"info"=>	"Original Author")
	);
 
 
	/**
	 * Install Function
	 *
	 * @return bool
	 */
	function install()
	{
		global $installer;
 
		// Master and menu entries
		$installer->add_config("'1','startpage','keys_conf','display','master'");
		$installer->add_config("'110','keys_conf',NULL,'blockframe','menu'");
 
		$installer->add_config("'1010','colorcmp','#00ff00','color','keys_conf'");
		$installer->add_config("'1020','colorcur','#ffd700','color','keys_conf'");
		$installer->add_config("'1030','colorno','#ff0000','color','keys_conf'");
 
		$installer->add_menu_button('keys','guild');
		return true;
	}
 
	/**
	 * Upgrade Function
	 *
	 * @param string $oldversion
	 * @return bool
	 */
	function upgrade($oldversion)
	{
		// Nothing to upgrade from yet
		return false;
	}
 
	/**
	 * Un-Install Function
	 *
	 * @return bool
	 */
	function uninstall()
	{
		global $installer;
 
		$installer->remove_all_config();
 
		$installer->remove_menu_button('keys');
		return true;
	}
}


Creating the Search Class

Properties


Example File

Here is an example of an AddOn install file
From the "Keys" AddOn

You can find more examples in the addons/ folder in roster

<?php
 
class news_search
{
	var $options;
	var $result = array();
	var $result_count = 0;
	var $link_next;
	var $link_prev;
	var $data = array();	// Addon data
 
 
	function search( $search , $url_search , $limit=10 , $page=0 )
	{
		global $roster;
 
		$first = $page*$limit;
 
		$q = "SELECT `news`.`news_id`, `news`.`author`, `news`.`title`, `news`.`content`, `news`.`html`, "
			. "DATE_FORMAT(  DATE_ADD(`news`.`date`, INTERVAL " . $roster->config['localtimeoffset'] . " HOUR ), '" . $roster->locale->act['timeformat'] . "' ) AS 'date_format', "
			. "COUNT(`comments`.`comment_id`) comm_count "
			. "FROM `" . $roster->db->table('news','news') . "` news "
			. "LEFT JOIN `" . $roster->db->table('comments','news') . "` comments USING (`news_id`) "
			. "WHERE `news`.`news_id` LIKE '%$search%' "
			. "OR `news`.`author` LIKE '%$search%' "
			. "OR `news`.`date` LIKE '%$search%' "
			. "OR `news`.`title` LIKE '%$search%' "
			. "OR `news`.`content` LIKE '%$search%' "
			. "GROUP BY `news`.`news_id` "
			. "LIMIT $first," . ($limit+1) .";";
 
		$result = $roster->db->query($q);
		$nrows = $roster->db->num_rows($result);
 
		$x = ($limit > $nrows) ? $nrows : $limit;
		if( $nrows > 0 )
		{
			while( $x > 0 )
			{
				list($news_id, $author, $title, $content, $html, $date, $comments) = $roster->db->fetch($result);
 
				$item['author'] = $author;
				$item['date'] = $date;
				$item['title'] = $title;
				$item['url'] = makelink('util-news-comment&amp;id=' . $news_id);
 
				if( $html == '1' && $this->data['config']['news_html'] >= 0 )
				{
					$content = $content;
				}
				else
				{
					$content = htmlentities($content);
				}
				$content = nl2br($content);
 
				$array = explode(' ',$content,101);
				if( isset($array[100]) )
				{
					unset($array[100]);
					$item['more_text'] = true;
				}
				else
				{
					$item['more_text'] = false;
				}
				$item['short_text'] = implode(' ',$array);
 
				$item['footer'] = ($comments == 0?'No':$comments) . ' comment' . ($comments == 1?'':'s');
 
				$this->add_result($item);
				unset($item);
				$x--;
			}
		}
 
		if( $page > 0 )
		{
			$this->link_prev = '<a href="' . makelink('search&amp;page=' . ($page-1) . '&amp;search=' . $url_search . '&amp;s_addon=' . $this->data['basename']) . '"><strong>' . $roster->locale->act['search_previous_matches'] . $this->data['basename'] . '</strong></a>';
		}
		if( $nrows > $limit )
		{
			$this->link_next = '<a href="' . makelink('search&amp;page=' . ($page+1) . '&amp;search=' . $url_search . '&amp;s_addon=' . $this->data['basename']) . '"><strong> ' . $roster->locale->act['search_next_matches'] . $this->data['basename'] . '</strong></a>';
		}
	}
 
	function add_result( $resultarray )
	{
		$this->result[$this->result_count++] = $resultarray;
	}
}


Roster Config API

This is the current functionality of the Roster Config API.
There are two classes of form types:

Items of the page, pageframe, and pagehide class contain option blocks.
Items of the blockframe or blockhide class contain options.


Menu Bar Items


Options Blocks


Options


AddOn Config Function File

addons/addonname/admin/config.func.php


Locale Files

These are used in translating any text in your AddOn if you want to support multi-langages.
As you can see in the example below, we have a file for deDE which is the German language, enUS which is the English language, frFR for French, and esES for Spanish.

Roster currently supports deDE, enUS, frFR, and esES, these are taken out of character profiler based on what region of WOW they are using.

The folder structure for locale files is as follows:

roster/
|_ addons/
   |_ addonname/
      |_ locale/
         |_ deDE.php
         |_ enUS.php
         |_ esES.php
         |_ frFR.php

When using locale files, it is absolutely necessary to ALWAYS have enUS.php
The AddOn Framework will default to this file if a locale is not found for a specific locale

Example:


Using Locale Strings

When using these them in your script you can use something similar to this

$header_title = $roster->locale->wordings['locale_key']['some_key'];

or

$header_title = $roster->locale->act['some_key'];

The first example is to get a specific locale value
The second is a reference to the current locale set in Roster

Remember that Roster's locale files are already added, so you only have to add the stuff that is custom to your AddOn.

So if you need to check to make sure we have don't already have a translation, you can open the files in the "localization/" directory to see the default words that you don't have to duplicate.

Duplication may cause errors in the main Roster code, if you duplicate a main Roster locale variable, you will incur the wrath of the WoWRoster.net Dev Team


Example File

Example from the PvPLog Roster AddOn
addons/questlist/locale/deDE.php

<?php
/**
 * WoWRoster.net WoWRoster
 *
 * LICENSE: Licensed under the Creative Commons
 *          "Attribution-NonCommercial-ShareAlike 2.5" license
 *
 * @copyright  2002-2007 WoWRoster.net
 * @license    http://creativecommons.org/licenses/by-nc-sa/2.5   Creative Commons "Attribution-NonCommercial-ShareAlike 2.5"
 * @version    SVN: $Id: deDE.php 899 2007-05-06 10:16:36Z Zanix $
 * @link       http://www.wowroster.net
*/
 
$lang['bglog']='BG &Uuml;bersicht';
$lang['pvplog']='PvP &Uuml;bersicht';
$lang['duellog']='Duell &Uuml;bersicht';
$lang['duelsummary']='Duell Summary';
 
$lang['totalwins']='Gewinne total';
$lang['totallosses']='Verluste total';
$lang['totaloverall']='Gesamt';
$lang['win_average']='Durchschnittliche Level Differenz (Gewinne)';
$lang['loss_average']='Durchschnittliche Level Differenz  (Verluste)';
 
// These need to be EXACTLY what PvPLog stores them as
$lang['alterac_valley']='Alteractal';
$lang['arathi_basin']='Arathibecken';
$lang['warsong_gulch']='Kriegshymnenschlucht';
 
$lang['world_pvp']='Welt-PvP';
$lang['versus_guilds']='Gegengilden';
$lang['versus_players']='Gegenspieler';
$lang['bestsub']='Beste Subzone';
$lang['worstsub']='Schlechteste Subzone';
$lang['killedmost']='Am meisten get&ouml;tet';
$lang['killedmostby']='Am meisten get&ouml;tet durch';
$lang['gkilledmost']='Am meisten get&ouml;tete Spieler der Gilde';
$lang['gkilledmostby']='Am meister get&ouml;tet durch Spieler der Gilde';
 
$lang['wins']='Gewinne';
$lang['losses']='Verluste';
$lang['overall']='Gesamt';
$lang['best_zone']='Beste Zone';
$lang['worst_zone']='Schlechteste Zone';
$lang['most_killed']='Meisten get&ouml;tet';
$lang['most_killed_by']='Meisten get&ouml;tet durch';
$lang['leveldiff']='LevelDiff';
$lang['bg']='Schlachtfeld';
$lang['kills']='Kills';
 
// guildpvp strings
$lang['guildwins'] = 'Wins by Guild';
$lang['guildlosses'] = 'Losses by Guild';
$lang['enemywins'] = 'Wins by Enemy';
$lang['enemylosses'] = 'Losses by Enemy';
$lang['purgewins'] = 'Guild Member Kills';
$lang['purgelosses'] = 'Guild Member Deaths';
$lang['purgeavewins'] = 'Best Win/Level-Diff Average';
$lang['purgeavelosses'] = 'Best Loss/Level-Diff Average';
$lang['pvpratio'] = 'Solo Win/Loss Ratios';
$lang['playerinfo'] = 'Player Info';
$lang['kill_lost_hist']='Kill/Loss history for %1$s (%2$s %3$s) of %4$s';
$lang['kill_lost_hist_guild'] = 'Kill/Loss history for Guild &quot;%1$s&quot;';
$lang['solo_win_loss'] = 'Solo Win/Loss Ratios (Level differences -7 to +7 counted)';
$lang['guildinfo'] = 'Guild Info';
 
$lang['admin']['pvpconfig'] = "PvPLog Config|Configure PvPLog main options";
$lang['admin']['minPvPLogver'] = "Min PvPLog version|Minimum PvPLog Version zum Upload";


CSS Styles

CSS style from the MembersList AddOn

/**
 * WoWRoster.net WoWRoster
 *
 * LICENSE: Licensed under the Creative Commons
 *          "Attribution-NonCommercial-ShareAlike 2.5" license
 *
 * @copyright  2002-2007 WoWRoster.net
 * @license    http://creativecommons.org/licenses/by-nc-sa/2.5   Creative Commons "Attribution-NonCommercial-ShareAlike 2.5"
 * @version    SVN: $Id: style.css 942 2007-05-20 04:50:02Z Zanix $
 * @link       http://www.wowroster.net
 * @package    MembersList
*/
 
.membersRowColor1 {
	background-color:#1F1E1D;
}
 
.membersRowColor2 {
	background-color:#2E2D2B;
}
 
.membersRowAltColor1 {
	background-color:#1F1E3D;
}
 
.membersRowAltColor2 {
	background-color:#2E2D4B;
}

I assume you know what css is...


AddOn Update Hook

The update hook is a file that ties into the lua upload process
You can specify any additional lua files you may you need

There are a few hook modes that an AddOn can make use of


Properties

The following variables are required in the update hook class


Methods

	function addonUpdate($data)
	{
		$this->data = $data;
	}

The following methods are reserved for update hooks
Descriptions for these methods are above and are not required

These function fairly simmilar

You can add other methods or properties as you wish, but be warned that Roster may implement more update hook methods in future versions


Example Update Hook File

This is an example update hook file
Look at memberslist and pvplog (example of additional lua file upload and processing) for more complex examples

<?php
/**
 * WoWRoster.net WoWRoster
 *
 * LICENSE: Licensed under the Creative Commons
 *          "Attribution-NonCommercial-ShareAlike 2.5" license
 *
 * @copyright  2002-2007 WoWRoster.net
 * @license    http://creativecommons.org/licenses/by-nc-sa/2.5   Creative Commons "Attribution-NonCommercial-ShareAlike 2.5"
 * @version    SVN: $Id: update_hook.php 899 2007-05-06 10:16:36Z Zanix $
 * @link       http://www.wowroster.net
 * @package    AddOnName
*/
 
if ( !defined('ROSTER_INSTALLED') )
{
    exit('Detected invalid access to this file!');
}
 
/**
 * Addon Update class
 * This MUST be the same name as the addon basename
 */
class addonUpdate
{
	var $messages = '';	// Update messages
	var $data = array();	// Addon config data automatically pulled from the addon_config table
	var $files = array();
 
 
	/**
	 * Class instantiation
	 * The name of this function MUST be the same name as the class name
	 *
	 * @param array $data	| Addon data
	 * @return recipe
	 */
	function addonUpdate($data)
	{
		$this->data = $data;
	}
 
	/**
	 * Resets addon messages
	 */
	function reset_messages()
	{
		$this->messages = '';
	}
 
 
	function update()
	{
		global $roster;
 
		$this->messages .= "<span class=\"green\">This is a non CP hook</span><br />\n";
 
		return true;
	}
 
	function guild_pre( $data )
	{
		global $roster;
 
		$this->messages .= "<span class=\"green\">This is a guild_pre hook</span><br />\n";
 
		return true;
	}
 
	function guild( $data , $memberid )
	{
		global $roster;
 
		$this->messages .= "<span class=\"yellow\">This is a guild hook</span><br />\n";
 
		return true;
	}
 
	function guild_post( $data )
	{
		global $roster;
 
		$this->messages .= "<span class=\"red\">This is a guild_post hook</span><br />\n";
 
		return true;
	}
 
	function char_pre( $data )
	{
		global $roster;
 
		$this->messages .= "<span class=\"green\">This is a char_pre hook</span><br />\n";
 
		return true;
 
	}
 
	function char( $data , $memberid )
	{
		global $roster;
 
		$this->messages .= "<span class=\"yellow\">This is a char hook</span><br />\n";
 
		return true;
	}
 
	function char_post( $data )
	{
		global $roster;
 
		$this->messages .= "<span class=\"red\">This is a char_post hook</span><br />\n";
 
		return true;
	}
}


Variable Calls

These are added to index.php for some additional support

If you add these into index.php you can turn off the header, footer and menu on the page, by default these are always on.

$roster->output['show_header'] = false;  // Turn off roster header
$roster->output['show_menu'] = false;    // Turn off roster menu
$roster->output['show_footer'] = false;  // Turn off roster footer 

$roster->output['show_menu'] can accept a string or an array of button listings to display
When building an addon, you can build your own button listing that only displays on your addon pages
Pass a string for only one set of buttons, or pass an array for multiple sets of buttons

$roster->output['show_menu'] = 'main';  // Display the main button listing
$roster->output['show_menu'] = array('main','char');  // Display the main and char button listing 

$roster->output['html_head'] = 'string';

Accepts any string needing to be in the html header for your addon, such as javascript inclusion
roster_header.tpl will pick this variable up and place its contents in the header

$roster->output['body_attr'] = 'string';

Accepts any string needing to be in the <body> tag in roster_header.tpl

$roster->output['body_onload'] = 'string';

Accepts any string needing to be in <body onload=""> in roster_header.tpl


Any output needed, just print or echo it
Roster uses php's output buffering to capture all print or echo commands
Then it echos the output where needed


Variables and Functions for AddOns

There are many variables, functions, and classes available for Addons to use


Variables

This is a list of variables that are available for your Addons

All variables are available whether during update hooks or in the framework


Functions

This is a list of functions that are available for your Addons

/**
 * Starts or ends fancy bodering containers
 *
 * @param string $style What bordering style to use
 * @param string $mode ( start | end )
 * @param string $header_text Place text in a styled header
 * @param string $hwidth Set a fixed width for the box
 * @return string
 */
function border( $style , $mode , $header_text=null , $width='' )

/**
* Highlight certain keywords in a SQL query
*
* @param string $sql Query string
* @return string Highlighted string
*/
function sql_highlight( $sql )

/**
 * Clean replacement for die(), outputs a message with debugging info if needed and ends output
 *
 * @param string $text Text to display on error page
 * @param string $title Title to place on web page
 * @param string $file Filename to display
 * @param string $line Line in file to display
 * @param string $sql Any SQL text to display
 */
function die_quietly( $text='', $title='', $file='', $line='', $sql='' )

/**
 * Draw a message box with the specified border color, then die cleanly
 *
 * @param string $message | The message to display inside the box
 * @param string $title | The box title (default = 'Message')
 * @param string $style | The border style (default = sred)
 */
function roster_die( $message , $title = 'Message' , $style = 'sred' )

/**
 * This will remove HTML tags, javascript sections and white space
 * It will also convert some common HTML entities to their text equivalent
 *
 * @param string $file
 */
function stripAllHtml($string)

/**
 * This will check if the given Filename is an image
 *
 * @param imagefile $file
 * @return mixed The extentsion if the filetype is an image, false if it is not
 */
function check_if_image( $imagefilename )

/**
 * Recursively escape $array
 *
 * @param array $array The array to escape
 * @return array The same array, escaped
 */
function escape_array( $array )

/**
 * Recursively escape $array
 *
 * @param array $array
 *	The array to escape
 * @return array
 *	The same array, escaped
 */
function stripslash_array( $array )

/**
 * Converts a datetime field into a readable date
 *
 * @param string $datetime datetime field data in DB
 * @param string $offset Offset in hours to calcuate time returned
 * @return string formatted date string
 */
function readbleDate( $datetime , $offset=null )

/**
 * Gets a file's extention passed as a string
 *
 * @param string $filename
 * @return string
 */
function get_file_ext( $filename )

/**
 * Converts seconds to a string delimited by time values
 * Will show d,h,m,s
 *
 * @param string $seconds
 * @return string
 */
function seconds_to_time( $seconds )

/**
 * Check to see if an addon is active or not
 *
 * @param string $name | Addon basename
 * @return bool
 */
function active_addon( $name )

/**
 * Handles retrieving the contents of a URL using multiple methods
 *
 * @param string $url	| URL to retrieve
 * @param int $timeout	| Timeout
 * @return mixed		| False on error, contents on success
 */
function urlgrabber( $url , $timeout = 5 )

/**
 * Debugging function dumps arrays/object formatted
 * Do Not call this, call aprint()
 *
 * @param array $arr
 * @param int $tab
 * @return string
 */
function aprint( $arr , $prefix='' )

/**
 * Helper function that returns the localized gem color in english
 *
 * @param string $socket_color
 * @return string $color
 */
function socketColorEn( $socket_color, $locale )


Roster Authorization

Like those nifty log-in boxes in Roster CP?
Now you can easily add one to your addon!

This checks if the user has admin access

// ----[ Check log-in ]-------------------------------------
$roster_login = new RosterLogin();
 
// Disallow viewing of the page
if( $roster_login->getAuthorized() < 3 )
{
	include_once (ROSTER_BASE . 'roster_header.tpl');
	$roster_menu = new RosterMenu;
	print $roster_menu->makeMenu('main');
 
	print
	'<span class="title_text">Some Title</span><br />'.
	$roster_login->getMessage().
	$roster_login->getLoginForm();
 
	include_once (ROSTER_BASE . 'roster_footer.tpl');
	exit();
}
else
{
	// continue with addon processing
}
// ----[ End Check log-in ]--------------------------------- 


Addon Credits

Link = http://[www.someurl.net]/roster/?p=credits (SEO: http://[www.someurl.net]/roster/credits.html)
To get credits on the main credit page, set the $credits array in the AddOn's inc/install.def.php file

var $credits = array(
	array(	"name"=>	"Author Name",
		"info"=>	"Extra Info"),
);

Replace the following

(Use <br> for line breaks)

You can add multiple arrays inside the main one to add more credits
(Try not to add too many, we don't wanna clutter the credits page now do we?)


Tooltips

/**
 * Makes a tootip and places it into the tooltip array
 *
 * @param string $var
 * @param string $content
 */
function setTooltip( $var , $content )

Creates a js variable for use with overlib
Instead of outputting text in the html, you can create a js variable that holds this instead

/**
 * Easy all in one function to make overlib tooltips
 * Creates a string for insertion into any html tag that has "onmouseover" and "onmouseout" events
 *
 * @param string $tooltip | Tooltip as a string (delimited by "\n" character)
 * @param string $caption | (optional) Text to set as a true OverLib caption
 * @param string $caption_color | (optional) Color for the caption
 * Default is 'ffffff' - white
 * @param bool $mode| (optional) Options 0=colorize,1=clean,2=pass through
 * Default 0 (colorize)
 * @param string $locale | Locale so color parser can work correctly
 * Only needed when $colorize is true
 * Default is $roster_conf['roster_lang']
 * @param string $extra_parameters | (optional) Extra OverLib parameters you wish to pass
 * @return unknown
 */
function makeOverlib( $tooltip , $caption='' , $caption_color='' , $mode=0 , $locale='' , $extra_parameters='' )

Returns this string for use in any html tag that supports onmouseover and onmouseout events

onmouseover="return overlib(overlib_'.$num_of_tips.$caption.$extra_parameters.');" onmouseout="return nd();"

For more info about makeOverlib() and its supporting functions, look at functions.lib.php


Message Boxes

Functions to draw message boxes

/**
 * Draw a message box with the specified border color.
 *
 * @param string $message | The message to display inside the box
 * @param string $title | The box title
 * @param string $style | The border style
 * @param string $width | Set a fixed width
 * @return string $html | The HTML for the messagebox
 */
function messagebox( $message , $title='Message' , $style='sgray' , $width='' )

/**
 * Draw a 300x550px scrolling messagebox with the specified border color.
 *
 * @param string $message | The message to display inside the box
 * @param string $title | The box title
 * @param string $style | The border style
 * @param string $width | Initial width with unit
 * @param string $height | Initial height with unit
 * @return string $html | The HTML for the messagebox
 */
function scrollbox($message, $title = 'Message', $style = 'sgray', $width = '550px', $height = '300px')

/**
 * Draw a message box with the specified border color.
 *
 * @param string $message | The message to display inside the box
 * @param string $title | The box title
 * @param string $style | The border style
 * @param boolean $open | True if initially open
 * @param string $width | Initial width with unit
 * @return string $html | The HTML for the messagebox
 */
function messageboxtoggle($message, $title = 'Message', $style = 'sgray', $open = false, $width = '550px')

/**
 * Draw a 300x550px scrolling messagebox with the specified border color.
 *
 * @param string $messages | The message to display inside the box
 * @param string $title | The box title
 * @param string $style | The border style
 * @param string $width | Initial width with unit
 * @param string $height | Initial height with unit
 * @return string $html | The HTML for the messagebox
 */
function scrollboxtoggle($message, $title = 'Message', $style = 'sgray', $open = false, $width = '550px', $height = '300px')
Personal tools
Namespaces
Variants
Actions
WoWRoster
Preview Roster
Navigation
Toolbox