EQdkp Plus Navigation:   Home  |   Forum  |   Wiki  |   Translate  |   Bugtracker  |   WebSVN  |  USVN

Update a plugin

From EQdkp Plus Wiki

Contents

Update a plugin

In 0.7, there'd been many API changes. Here's the howto change existing Plugins to the new platform

Global Changes

  • use $core->config[] instead of $conf_plus
  • use $user->lang[] instead of $plang

package.xml

To use the new extension installer of eqdkp plus, you need to add a new xml file to validate the needed information to the package installer.

See here for more information: http://wiki.eqdkp-plus.com/dev/index.php/Extension_installer#package.xml

Config Changes

Your plugin should no longer have its own config-table. Instead we wrote a config-class, which is able to manage you config. The functions you need are listed and explained below:

  • $core->config_set($config_name, $config_value='', $plugin='') { [...] }
    • $config_name is rather the key (for single value) or the array with key => value format.
    • $config_value is only needed if you pass a string as first param.
    • the last param "$plugin" is needed if you set configs for your own plugin.
  • $settings->get_config($plugin='') { [...] }
    • lets you fetch the whole array of config. (if plugin is specified, only for that plugin)
  • $core->config_del($config_name, $plugin='') { [...] }
    • is what you need if you want to delete ore config value or several ones (config_name can be an array. config_names as values in the array not as key!).
  • $core->config[$plugin][$config_key] = $config_value is the normal way to use the config. To get global config vars you have to omit the [$plugin] part.

To initially set you config you should use $core->set_config($array_with_defauls, '', 'your_plugin_code'); in the pre_install-function.

Library Changes

Init/LibLoader

The libloader.inc.php is not longer required. remove it, the EQDKP-PLUS 0.7 will do the rest

Updater

The Updater need not longer to be implemented in the settings.php. You must remove it, as we introduced a new place for the updates: the Maintenance Mode. Remove the class init "$myclass = new PluginUpdater()" and the "$myclass->OutputHTML()"

You have to remove the "force Database Update" functionality, too. Its removed and handled by the Maintenance Mode.

ArmoryChars Class

the armory chars class now requires $urlreader as a global. If you're using armorychars in an own function, make sure you set the required global. If not, the loader will not work.

Online Update Check

TBA

jQuery Class Changes

I changed the behaviour of the JS Windows. If you used "Dialog_***", p.e. "Dialog_URL", you'll have to change that part.

0.7 uses the new "Dialoge" Class $jquery->Dialog(NAME, WINDOW_HEADER, OPTIONS, TYPE);

TYPE: url, confirm, alert NAME: function Name to be called, p.e. 'fe_portalsettings' means function fe_portalsettings(); WINDOW_HEADER: The Text shown in the Window head OPTIONS: Additional Options

Option Name Description Available for TYPE
url the URL to be opened or redirected (confirm) url, confirm
withid the id of the function p.e. test(withid) confirm, url
custom_js custom JS Code instead of redirect to url confirm
message The message to be shown url, alert, confirm
onclose redirect on window close url
width Width of the window url, alert
height Height of the window url, alert
modal Modal window, true/false url
resize User can resize window, true/false url
draggable User can drag&drop window, true/false url


$my_ajs = 'function fe_portalsettings(moduleid){
'.$jquery->Dialog_URL('ModuleSetting'.rand(), $user->lang['portalplugin_winname'], $this->root_path."admin/portalsettings.php?id='+moduleid+'", '660', '400').'
}';

is now

$jquery->Dialog('fe_portalsettings', $user->lang['portalplugin_winname'], array('url'=>$this->root_path."admin/portalsettings.php?id='+moduleid+'", 'width'=>'660', 'height'=>'400', 'withid'=>'moduleid'));

Plugin-Class Changes

Renamed Class

The Class itself has to be named different now.

class Myplug_plugin_class extends EQdkp_Plugin //before
class Myplug extends plugin_generic //new

Icon settable

You can now define an icon for your plugin.

$this->add_data('icon', $icon); //$icon with root_path | can also be merged to the add_data(array()) call

Path no longer exists

The plugin_path does not need to be specified anylonger. It therefore MUST be the same as the plugin_code!

Log-Actions removed

$this->add_log_action()

is not longer needed because of the global Logging-Class. More information about the logging class: Logging

New functions

function pre_install()

If defined this function will be called before the SQL installation process starts and can be used to prepare SQL statements etc.

function post_install()

If defined this function will be called after the successful SQL installation process and can be used to initialise the plugin after install.

function pre_uninstall()

If defined this function will be called before the SQL uninstallation process and can be used to prepare SQL statements etc.

function post_uninstall()

If defined this function will be called after the successful SQL uninstallation process and can be used to cleanup stuff after uninstallation.

function autorun()

If defined this function will be called on each page load if the plugin is installed.

Menu-Changes

The new menu-array looks like this:

$menu = array(
  'name' => 'plugin_name',
  'icon' => 'plugin_icon', // (may be $this->data['icon'])
  1 => array( //first entry
    //as before
  )
)

Plugin-Manager ($pm) Changes

Changed Hook-System

$pm->hooks became private. You must! not use $pm->hooks directly. Use

public function do_hooks($hook, $params=array(), $recursive=false, $plugin='')

$recursive works as follows: you specify the key of the params array in which the result of the hook_call shall be put. Example:

$my_text = "Anything with [b]bbcodes[/b].";
$my_text = $pm->do_hooks('bbcode_parsing', array('text' => $my_text), 'text');
//could return "Anything with <b>bbcodes</b>."

$pm->check() changed

Arguments have been switched

public function check($plugin_code, $check='not_set', $strict=false) {
   if($check == 'not_set') {
       $check = PLUGIN_INITIALIZED | PLUGIN_INSTALLED;
       $strict = true;
   }

$strict is new and is used if you want to have all given states set. Example:

//'plugin1' has the states PLUGIN_INITIALIZED, PLUGIN_REGISTERED, PLUGIN_INSTALLED
//'plugin2' has the states PLUGIN_INITIALIZED, PLUGIN_REGISTERED
$pm->check('plugin1', (PLUGIN_INITIALIZED | PLUGIN_INSTALLED)); 
//returns true, as expected
$pm->check('plugin2', (PLUGIN_INITIALIZED | PLUGIN_INSTALLED)); 
//returns true, may not be expected, reason: it returns true if ONE of the two given states is checked
$pm->check('plugin2', (PLUGIN_INITIALIZED | PLUGIN_INSTALLED), true);
//return false, plugin does not fulfill both states.

Plugin-Updater Changes

Together with the new Maintenance mode we changed, how the plugin-db-updates work. The version.php file is no longer needed, so you can delete it. The old update-files have to be changed in order to let them work. The header of the new update file should look like this. The filename must be like this: "update_{plugin_path}_{something}.class.php" and the name of the class "update_{plugin_path}_{something}". Here's an example of a raidplan-update.

if ( !defined('EQDKP_INC') ){
    header('HTTP/1.0 404 Not Found');exit;
}
 
include_once($eqdkp_root_path.'maintenance/includes/sql_update_task.class.php');
 
class update_raidplan_500 extends sql_update_task {
  public $author = 'wallenium';
  public $version = '4.2.0'; //new version
  public $name = 'Raidplan 4.2.0 Update'; //name of the update
  public $plugin_path = 'raidplan'; //important!

Next you have to define the __construct() function where you define the sqls.

public function __construct(){
  parent::__construct(); //this line is important!
 
  $this->langs = array(
    'english' => array( //english is necessary
  	'update_raidplan_500' => 'Raidplan update to 5.0.0', //description of the whole update
 	1 => 'The first SQL-Query Description',
        'update_function' => 'Description of the update-function',
     ),
     'german' => array( //other languages are optional
        'update_raidplan_500' => 'Raidplan Update auf 5.0.0',
        1 => 'Die Beschreibung des ersten SQL-Querys',
        'update_function' => 'Beschreibung der Update-Funktion',
     ),
  );
 
  $this->sqls = array(
    1 => "An example SQL-Query would be here",
   );
}

If you need an update-function in the db-update just define the following function. If you dont need a function, dont define it (still in class).

  public function update_function() {
    //here we define our function
    return true/false;
  }
} //dont forget closing the class ;)

It is also possible to not let the task an extension of the sql_update_task class, but then you have to write everything yourself. It's important, that the name of the task remains the same, otherwise the maintenance-mode won't see it as a task for itself.

Menu Changes

User Settings Menu

Usersettings of Plugins are now integrated in the normal Usersettings. Sample User-Settings:

	function gen_settings_menu(){
		global $user, $SID, $eqdkp_root_path;
		if ( $this->pm->check(PLUGIN_INSTALLED, 'raidplan')){
			$admin_menu = array(
				'raidplan' => array(
					'icon'		=> $eqdkp_root_path.'plugins/raidplan/images/adminmenu/rp_icon.png',
					'name'		=> $user->lang['raidplan'],
					'pk_bossguides_accordion'     => array(
						'name'      => 'pk_bossguides_accordion',
						'language'  => 'pk_use_accordion',
						'type'  => 'checkbox',
						'help'      => '',
						'value'	=> 1,
					),
					'pk_bossguides_hide_naxx'     => array(
						'name'      => 'pk_bossguides_hide_naxx',
						'language'  => 'rp_manage',
						'type'  => 'text',
						'size'      => '30',
						'help'      => '',
					),
					'pk_bossguides_hide_malygos'     => array(
						'name'      => 'pk_bossguides_hide_malygos',
						'language'  => 'pk_hide_malygos',
						'type'  => 'checkbox',
						'size'      => '30',
						'help'      => '',
					),
			));
			return $admin_menu;
 
		}
		return;
	}

You can use the syntax for portal-modules or other things using the widget-class.

Admin Menu

There are some minor changes:

Check if you're using the following array keys and change if used: old:

99 => './../../plugins/downloads/images/admin_logo.png',
0 => $user->lang['downloads'],

new:

'icon' => './../../plugins/downloads/images/admin_logo.png',
'name' => $user->lang['downloads'],

The new Admin menu allowes you to add an icon for every single menu entry. Just add

'icon' => 'icon.png'
to the menu item array.

Menu Icons

If you want to use/add own icons to your plugins, use the famfam icons, they're free. http://www.famfamfam.com/lab/icons/silk/

Template Changes

General

Its pretty simple: Eqdkp 0.7 only uses one template folder.

  • Delte all existing template folders except one
  • rename it to "base_template"
  • edit all headers and footers to fit the following sheme:
<!-- INCLUDE ../../../../templates/{TMPL_FOLDERNAME}/page_header.html -->
<!-- INCLUDE ../../../../templates/{TMPL_FOLDERNAME}/page_tail.html -->

If you've got custom templates who needs the own folder, you're allowed to use custom folders as you know it. but if there are no changed template files for your custom template, you need not create an own folder.

Style Sheet (CSS)

In 0.7 we have a new way to add CSS code/files to the Template

$tpl->add_css($your_css);

This code adds css code to the template engine. Just add it and set the code between the <style> tags as variabe

$tpl->css_file($path_to_file);

This code adds a css file link to the header. Just add the path to the css-file.

JavaScript (JS)

In 0.7 we have a new way to add JavaScript code/files to the Template

$tpl->add_js($your_js);

This code adds js code to the template engine. Just add it and set the code between the tags as variabe

$tpl->js_file($path_to_file);

This code adds a javascript file link to the header. Just add the path to the JS-file.

Permission Changes

Permission-IDs

With the 0.7, you have to remove the auth_id from your add_permission-function. New:

// (Admin (a)/User (u), Name, Enables Y/N, Language cariable, array of user-group-ids that should have this permission)
$this->add_permission('a', 'import', 'N', $user->lang['dl_import']);

You can grant rights to Groups by adding the Group-IDs into an array and add it to your function-call:

$this->add_permission('a', 'import', 'N', $user->lang['dl_import'], array(1,2,3));

Pay attention: it doesn't care if the auth_default is Yes or No, the permission will be granted as Yes to the groups in your array!

Default Groups after installation:

  • 1 = Guest-Group, undeletable
  • 2 = Super-Admin, undeletable
  • 3 = Admins, undeletable
  • 4 = Members, undeletable
  • 5 = Officers
  • 6 = Writers

Permission Groups

to be implemented....

Grant permissions to the installing user

All plugin permissions will now be granted automatically to the installing user, so you should delete your own implementations from the plugin base class.

Data Fields Changes

The additional data fields (and their respective functions) introduced by eqDKP Plus 0.6 have been removed. The original data field now supports the following types:

var $valid_data_types = array('id', 'code', 'name', 'installed',
                              'contact', 'path', 'template_path',
                              'version', 'description', 'long_description',
                              'manuallink', 'homepage', 'imageurl',
                              'author'
                             );

Dependency System

Three different types of dependencies are now available to the plugin author to make sure their plugins are used in a system which fullfills some basic requirements. They can be set in your main plugin class as follows:

    $this->add_dependency(array(
      'plus_version'  => '0.7',
      'lib_version'   => '1.0.2',
      'games'         => array('aoc', 'eq', 'lotro', 'vanguard', 'wow'),
      'php_functions' => array('json_encode'),
      )
    );

You can skip each of them resulting in no respective restrictions. Each set dependency will be checked with the default checks. If you want to use custom checks you can implement the following method in your main plugin class:

  function check_dependency($dependency){
    // do checks and return true/false for all dependency types
  }

Breaking a dependency will prohibit the installation of your plugin, and maybe from initialisation in a future version (tba).

With these changes the plus_version data field and the $fwversion field in your plugin class will become obsolete.

Database Changes

Remove table constants

EQdkp no longer defines constants for SQL table names. In 0.6, you could use both: constants OR underscores. EQDKP-PLUS 0.7 will not longer allow constants. Instead, any name prefixed with two underscores will automatically gain the installation's EQdkp prefix.

Delete blocks like this from your <plugin>_plugin_class.php:

global $table_prefix;
if (!defined('WISHLIST_TABLE')) { define('WISHLIST_TABLE', $table_prefix . 'wishlist'); }
if (!defined('WISHLIST_DATA_TABLE')) { define('WISHLIST_DATA_TABLE', $table_prefix . 'wishlist_data'); }

Use the magic string instead of the constants:

// Define installation
// -----------------------------------------------------
$sql = "CREATE TABLE IF NOT EXISTS " . WISHLIST_TABLE . " (

becomes

// Define installation
// -----------------------------------------------------
$sql = "CREATE TABLE IF NOT EXISTS __wishlist (

Better sql Queries

This is completely optional but may clean up your code a bit.

You may have seen some code like this in EQdkp-Plus 0.6.x:

$insert = array(
        'wl_id'     => null,
        'wl_member' => ucfirst($user->data['username']),
        'wl_item'   => $_POST['wishlist_item'],
        'wl_type'   => $_POST['wishlist_type'],
);
 
$sql = INSERT INTO ' . WISHLIST_TABLE . $db->build_query('INSERT', $insert);
$db->query($sql);

The query method now takes an optional second parameter which, if an array, will be passed to build_query() and the results will replace a variable in the query called :params For example, the above lines could be re-written as one statement:

$db->query("INSERT INTO __wishlist :params", array(
        'wl_id'     => null,
        'wl_member' => ucfirst($user->data['username']),
        'wl_item'   => $_POST['wishlist_item'],
        'wl_type'   => $_POST['wishlist_type'],
));

The syntax is very similar for UPDATE queries, and the appropriate value is automatically detected and passed to build_query()

Portal Modules

If your plugin ships a portal module, there've been some changes, too. Instead of using a modules.php file in your plugin's 'portal' folder, you can now easily register your portal modules by calling:

$this->add_portal_module('nextraids');

for each of your modules (in this example it was the "nextraids" module) in your plugin object constructor.

Exchange Modules

You can add own exchange-modules for SOAP. Plase take a look at Plus Exchange for more information about creating an exchange module.

$this->add_exchange_module('shoutbox');

If you want to add an xml-feed, use the following code:

$this->add_exchange_module('shoutbox', true, 'shoutbox.xml');

Security Changes

Clean Input

$db->query("INSERT INTO __wishlist :params", array(
        'wl_id'     => null,
        'wl_member' => ucfirst($user->data['username']),
        'wl_item'   => $in->get('wishlist_item'),
        'wl_type'   => $in->get('wishlist_type'),
));

The $in variable references an instance of the Input class.

Clean Output

Always use "$db->escape()", for every single variable you'd in your sql queries. Here, settings.php forces the GET variable 'id' to be an integer:

$sql = "DELETE FROM " . RAIDPLAN_TABLE . "
        WHERE ( wl_id = " . intval($_GET['id']) . " )
        AND ( wl_member = '" . ucfirst($user->data['username']) . "' )
        LIMIT 1";

But we can have Input do this for us by passing it an integer as the second parameter, its default value if 'id' doesn't exist.

$sql = "DELETE FROM __wishlist
        WHERE ( wl_id = " . $db->escape($in->get('id', 0)) . " )
        AND ( wl_member = '" . $db->escape(ucfirst($user->data['username'])) . "' )
        LIMIT 1";

Cross-Site Scripting (XSS) Protection

Never trust what's being displayed to the user. Always sanitize() any variables being printed.

$tpl->assign_block_vars('raidplan_row', array(
        'ROW_CLASS'     => $eqdkp->switch_row_class(),
        'ITEM'          => sanitize($row['wl_item']),
        'ZONE'          => sanitize($row['wl_zone']),
        'BOSS'          => sanitize($row['wl_boss']),
));

Class and Race changes

In 0.7 we removed the __classes and __races table. All information about classes and races can now be fetched by using the new game-class. The three most used functions are:

get an array of $type: $game->get($type, $lang=false) => $type is e.g. classes, races, etc.; $lang is optional, if not given default language is used. if given: the language must be written as a word (e.g: german, english, french)
$game->get_name($type, $id, $lang=false) => $type is same as above; $id should be clear; $lang is same as above
$game->get_id($type, $name) => $type is same as above, $name is the string for which you want to get the ID. All available languages of the game are searched.

If you need further information about the game-class search this article.

Changed plus functions

changes globals

Global $eqdkp does not exist anymore. Use $core instead.

removed global functions

  • clean_data()

changed global functions

  • System_Message(..) ==> $eqdkp->message(..)
  • ArraySystemMessage(..) ==> $eqdkp->messages(..)
  • sql_highlight(..) ==> $db->sql_highlight(..)

added global functions

  • compareVersion($version1, $version2) - compare two versions, up to 4 digit blocks (p.e. 0.4.2.10)

Changed html.class.php

The pluskernel/include/html.class.php has been deleted in 0.7. Most of the functions have been copied into the library html.class.php (which can be accessed by $html). But all the functions, which follow are NOT in the "new" html.class.php:

All the following functions can be used by using $plus instead of $html:
  • CopyRightYear
  • Copyright
  • createVTable
  • createGraph
  • createpieGraph
  • toggleIcons
  • CreateDynamicIframeJS
  • adminmenu
  • get_php_setting
  • get_curl_setting
  • check_PHP_Function

Changed plus.functions.php

We cleaned up the plus.functions.php, too. All functions which are not listed here, should be available just as in 0.6:

The following functions have been removed and the functionality is little different as before:
In 0.7 you should not use class or race_names as index. Use the ID instead.
There are two functions which are usually needed to manage this.
$game->get_name($type, $id, $lang=false) => $type is e.g. classes, races, etc.; $id should be clear; $lang is optional, if you want to use this: the language must be written as a word (e.g: german, english, french)
$game->get_id($type, $name) => $type is same as above, $name is the string for which you want to get the ID. All available languages of the game are searched.
The two functions which has been removed because of this are:
  • renameClasstoenglish
  • renameRacetoenglish
The following Icon functions have been deleted and can now be found in the game-class. Usage as follows: $game->decorate($type, $params)
  • get_RankIcon => $game->decorate('ranks', array($rank_id))
  • get_RaceIcon => $game->decorate('races', array($race_id))
  • get_ClassIcon => $game->decorate('classes', array($class_id))
  • getEventIcon => $game->decorate('events', array($event_id))
get_class_color_code => changed to $game->get_class_color($class_id) (there are always css-classes defined with the class_colors: class_.$class_id)
This two functions can be called by $game->callFunc($funcname, $params)
  • get_wow_talent_spec
  • showAllvatarWoW_Signatur
This functions are now implemented into the pdh:
  • get_classNamebyMemberName => $pdh->get('member', 'classname', array($member_id))
  • get_RankNamebyMemberName => $pdh->get('member', 'racename', array($member_id))
This functions have been removed completely:
  • get_classImgListmembers
  • get_classNameImgListmembers
  • get_classNameImgViewmembers
  • get_coloredLinkedName
  • get_classColorChecked
get_multi_pools and get_events_for_poolid can now be fetched by:
  • $pdh->get('multidkp', 'id_list', array())
  • $pdh->get('multidkp', 'name', array($multidkp_id))
  • $pdh->get('multidkp', 'event_ids', array($multidkp_id))
check_auth_admin => use $user->check_auth('a_', false) instead

Plus Data Handler

You can also register new modules for our brand new data handler within your plugin object constructors by calling either:

$this->add_pdh_read_module('module_name');

or

$this->add_pdh_write_module('module_name');

whereas module_name is the unique name of your pdh module. The module itself has to be in either /yourplugin/pdh/read/module_name/ or /yourplugin/pdh/write/module_name/ and has to follow the pdh read/write module pattern.