User Tools

Site Tools


en:dev:284:helloworld

This is an old revision of the document!


FIXME This page is not fully translated, yet. Please help completing the translation.
(remove this paragraph once the translation is finished)

Hello Classic World - Project

.. The classic example addon. Here, too, very much will change. In principle, however the previous, old system is is still fully compatible at least for 2.8.4. For this reason also the first description of an addon to the conventional method, however, already with new techniques and, unfortunately, still with many 'old' problems.

:!: Each new development / revision must be based on the general Coding-Standards and Specific Adaption of the PSR-Standards to WB-2.8.4!

Each Addon requires a series of basic files that must be available always. In the following descriptions, these are marked with (required). Although these files must be present, they do not necessarily need to contain additional code. The easiest way is to directly download the sample files presented here and to use and complete them with your own code if desired.

:!: Note: Never rely on an execution of these basic files files of Addons in the 'Global Scope' 1)
Always assume that these files will be called within a function / class method and thus are not, of course, global variables directly available!

The files to install all addons

The files install.php, uninstall.php, and upgrade.php are in principle called and executed automatically at the appropriate actions by the core. You can execute them manually on your own.
In addition, part of the 'basic set' the file info.php and, if database tables are needed, yet the file install-struct.sql.

All files in this section are generally required for any type of Addon (page / snippet / tool).

:!: In order that the control of the core (e.g. automatic installation) will not be interrupted, these files may not contain code that aborts the execution of the script in any way. FIXME (further conditions for these files)

info.php (currently still needed)

In the meantime this file is available only for backward compatibility and only contains a call to import the information from the info.ini file. New or revised features of the core grab immediate priority on the info.ini file. This compatibility feature is expected to be disabled permanently in the future. Existing modules must therefore be changed up to this point to use the new info.ini.

info.php
<?php
/**
 * The new 'info.ini' is mandatory from 2.8.4 !!!
 * This file 'info-php' is for backward compatibility only!!!!!
 * From 2.8.4 new core methods will no longer use the old vars from info.php!
 * It will be removed at least at 1th of July 2015 !!!!
 */
    if (!defined('SYSTEM_RUN')) die('illegal access!');
    $aX = UpgradeHelper::convInfoIni2InfoPhp(__DIR__);
    if ($aX) {
        $sPrefix = array_shift($aX);
        extract($aX, EXTR_PREFIX_ALL, $sPrefix);
    } else {
        $sErrMsg = 'error on converting values from \''.basename(__DIR__).'/info.ini\' '
                 . '('.UpgradeHelper::getError('convInfoIni2InfoPhp').')';
        throw new AppException($sErrMsg);
    }

info.ini (required)

This file contains only information about the current Addon in a nutshell. A changelog or other 'novels' have absolutely no place in this file.
For more detailed information must be provided in various other specialized files in the subdirectory module directory/DOC/ :
DOC/CHANGELOG In chronological order (newest entries at the top) changes to the scripts are entered here. Also, the entry / exit of other developers will be entered at the correct time position. DOC/LICENSE The place for detailed license information and other legal information. DOC/COPYING This file can be used to e.g., to accommodate a copy of the GPL. DOC/README.EN Here is unlimited space for detailed descriptions and instructions. By adapting the file extension, such information may be written in different languages.

:!: Version numbers must only be given in a format that is compatible with the PHP function version_compare().

info.ini
<?php
;
; info file for addon 'Hello World'
; you can remove the comments below if you want.
;
; addon informations
[info]
; type of the addon (can be: page, snippet, tool, template, theme)
type            = "page"
; the directory where the addon should be located (allowed pattern: /[A-Za-z][A-Za-z0-9\-]+/)
directory       = "HelloWorld"
; readable name of the addon
name            = "The new Hello World addon"
; version of the addon
version         = "0.1.0"
; name of the author, if more then one, write as CSV list
author          = "Xaver Hinterhuber, Michaela Mustermann"
; short name of your license
license         = "GNU GPLv.2"
; short version of your terms of license
license_terms   = "--- short version of your license terms ---"
; short description of your addon. Take no more then 2 or 3 lines
; HTMl code is not allowed, but you can use \n for linefeed.
description     = "Kurzbeschreibung des Moduls"

; for whitch platform the addon is usable
[platform]
; brand name of the platform
name            = "WebsiteBaker"
; CSV list with ALL versions the addon ist testet for
versions        = "2.8.4, 2.8.4-SP1"
; minimum needed PHP version
minPhp          = "5.4"

install-struct.sql

:!: This file is only needed if the addon is to get their own database tables!

What is a SQL file structure?

The sample files for Install / Upgrade / Uninstall included the final integration of the SQL file structure.
If the file install-struct.sql is not present, for example, because simply no database tables are required, the code automatically recognizes this and simply proceeds with the individual part.

install-struct.sql
-- --------------------------------------------------------
-- SQL-Import-Struct-File
-- generated with ConvertDump Version 0.2.1
-- WebsiteBaker Edition
-- Creation time: Sat, 22 Nov 2014 08:32:00 +0100
-- --------------------------------------------------------
-- phpMyAdmin SQL Dump
-- version 3.3.2deb1ubuntu1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Erstellungszeit: 22. November 2014 um 07:39
-- Server Version: 5.1.73
-- PHP-Version: 5.3.2-1ubuntu4.28
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Datenbank: `wb284test`
--
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `{TABLE_PREFIX}mod_helloworld_settings`
--
DROP TABLE IF EXISTS `{TABLE_PREFIX}mod_helloworld_settings`;
CREATE TABLE IF NOT EXISTS `{TABLE_PREFIX}mod_helloworld_settings` (
  `instance` INT(11) NOT NULL DEFAULT '0',
  `name` VARCHAR(64){FIELD_COLLATION} NOT NULL DEFAULT '',
  `value` text{FIELD_COLLATION}  NOT NULL,
  PRIMARY KEY (`section_id`, `key`)
){TABLE_ENGINE=MyISAM};
-- --------------------------------------------------------
-- END OF SQL-Import-Struct-File
-- --------------------------------------------------------

install.php (required)

The installation of an Addon basically is done by core methods. Only pure Addon specific things, such as creating new database tables are created by this file.

install.php
<?php
if (! defined('WB_PATH')) { die('Cannot access this file directly'); }
/* -------------------------------------------------------- */
    $oReg = WbAdaptor::getInstance();
// --- process import file to create addons tables ----------------
// --- This code is needed if your addon has own tables -----------
    $oSqlStruct = new SqlImport($oReg->Db, __DIR__.'/install-struct.sql');
    if ($oSqlStruct->doImport(__FILE__)) {
// --- finish process import file ---------------------------------
// --- begin all other this addon related stuff -------------------
 
        /*
         * do some other stuff
         */
 
    } //endif
/* **** END INSTALL ********************************************************* */

FIXME complement to return error messages !!

uninstall.php (erforderlich)

Auch die Deinstallation eines Addons wird größtenteils durch Core-Methoden erledigt. Diese Datei muss eigentlich nur dafür sorgen, dass alles, was außerhalb des Addonverzeichnisses oder in Tabellen, die nicht zum Addon gehören (was nach den Coding-Standards eigentlich strikt verboten ist) angelegt/geändert wurde, rückgängig gemacht wird. Die Tabellen des Addons werden durch den SQL-Importer des Core anhand der install-struct.sql gelöscht. Nach Ausführung dieser uninstall.php Datei löscht der Core dann das komplette Addonverzeichnis und entfernt alle relevanten Einträge zu diesem Modul aus allen Coredateien.
:!: Es ist grundsätzlich nicht möglich, ein Addon zu löschen, wenn es noch auf irgendeiner Seite in Benutzung ist!!

uninstall.php
<?php
if (! defined('WB_PATH')) { die('Cannot access this file directly'); }
/* -------------------------------------------------------- */
    $oReg = WbAdaptor::getInstance();
 
// --- begin all other this addon related stuff -------------------
 
        /*
         * do some other stuff
         */
 
// --- end all other this addon related stuff ---------------------
 
// --- process import file to delete addons tables ----------------
// --- This code is needed if your addon has own tables -----------
    $oSqlStruct = new SqlImport($oReg->Db, __DIR__.'/install-struct.sql');
    $oSqlStruct->doImport(__FILE__);
// --- finish process import file ---------------------------------
/* **** END UNINSTALL ******************************************************* */

FIXME ergänzen um Rückgabe von Fehlermeldungen!!

upgrade.php (erforderlich)

Diese Datei hat die Angewohnheit, dass sie im Laufe der Zeit immer weiter anwachsen kann. Jeder Übergang von einer Version zur nächsten kann erfordern, dass Daten des Addon an neue Bedingungen angepasst werden müssen. Eine der wichtigsten Regeln für diese Datei ist: Es muss möglich sein, von jeder beliebigen Version auf die neueste Version upzudaten.

upgrade.php
<?php
if (! defined('WB_PATH')) { die('Cannot access this file directly'); }
/* -------------------------------------------------------- */
    $oReg = WbAdaptor::getInstance();
// --- process import file to create addons tables ----------------
// --- This code is needed if your addon has own tables -----------
    $oSqlStruct = new SqlImport($oReg->Db, __DIR__.'/install-struct.sql');
    if ($oSqlStruct->doImport(__FILE__)) {
// --- finish process import file ---------------------------------
// --- begin all other this addon related stuff -------------------
 
        /*
         * do some other stuff
         */
 
    } //endif
/* **** END UPGRADE ********************************************************* */

FIXME ergänzen um Rückgabe von Fehlermeldungen!!

Die Dateien eines Addons Type 'page'

Ein sogenanntes 'page'-Addon benötigt derzeit noch eine Reihe von Dateien, über die der Core das Anlegen, Löschen und Verwalten von Addon-Instanzen steuern kann. Diese 'erforderlich'en Dateien sind nicht selbstständig lauffähig und werden ausschließlich vom Core aufgerufen.
Auch für diese Dateien gilt folgende Regel:
:!: Achtung: Verlassen Sie sich niemals darauf, dass die Basis-Dateien eines Addons im 'Global Scope' 2) geladen und ausgeführt werden!! Gehen Sie grundsätzlich immer von der Annahme aus, dass diese Dateien innerhalb einer Funktion/Klassenmethode aufgerufen werden und dadurch selbstverständlich globale Variablen nicht direkt zur Verfügung stehen!
Weshalb wird die page_id in Addons nicht mehr benötigt?
Ein Page-Addon benötigt wenigstens eine Basis-Tabelle in der Datenbank. Die Tabelle muss nach dem Muster: mod_AddonName benannt werden und muss zumindest ein Integer Datenfeld für die SectionId enthalten. Jeder Datensatz in dieser Tabelle verknüpft eine Instanz des Addons mit einer Section. Weitere Datenfelder können z.B. die Grundeinstellungen der jeweiligen Addon-Instanz aufnehmen.

add.php (erforderlich)

add.php
<?php
/**
 * add.php
 *
 * @category     Addon
 * @package      Addon_HelloWorld
 * @copyright    Manuela v.d.Decken <manuela@isteam.de>
 * @author       Manuela v.d.Decken <manuela@isteam.de>
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
 * @version      0.0.1
 * @revision     $Revision: 1 $
 * @lastmodified $Date: 2014-11-30 00:00:00 +0100 (So, 30 Nov 2014) $
 * @since        File available since 30.11.2014
 * @description  defines a new instance of this addon
 */
if (! defined('WB_PATH')) { die('Cannot access this file directly'); }
/* -------------------------------------------------------- */
// --- import needed objects ---------------------------------
    $oReg  = WbAdapter::getInstance();  // get the instance of the active registry
// --- import needed global vars -----------------------------
 
//  here you can set/get basical settings for this instance
    $oAddonReg = new AddonRegistry($oReg, basename(__DIR__), array('instance'=>$oReg->InstanceId));
    $oAddonReg->setEntry('Template', 'MyFirstOwnTemplate');
 
// --- end of file -------------------------------------------

delete.php (erforderlich)

delete.php
<?php
/**
 * add.php
 *
 * @category     Addon
 * @package      Addon_HelloWorld
 * @copyright    Manuela v.d.Decken <manuela@isteam.de>
 * @author       Manuela v.d.Decken <manuela@isteam.de>
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
 * @version      0.0.1
 * @revision     $Revision: 1 $
 * @lastmodified $Date: 2014-11-30 00:00:00 +0100 (So, 30 Nov 2014) $
 * @since        File available since 30.11.2014
 * @description  delete actual instance of this addon
 */
if (! defined('WB_PATH')) { die('Cannot access this file directly'); }
/* -------------------------------------------------------- */
// --- import needed objects ---------------------------------
    $oReg  = WbAdapter::getInstance();  // get the instance of the active registry
// --- import needed global vars -----------------------------
 
// -----------------------------------------------------------
/* ***********************************************************
 *                                                           *
 * put here all additional code to clean up this instance    *
 *                                                           *
 * **********************************************************/    
// --- finaly remove record from table `mod_helloworld_settings` ------
    $sql = 'DELETE FROM `'.$oReg->Db->TablePrefix.'mod_helloworld_settings` '
         . 'WHERE `instance`='.$oReg->InstanceId;
    if (! $oReg->Db->doQuery($sql)) {
        // use string var $sErrorMessage for returning of error messages!
        $sErrorMessage = $oReg->Db->getError();
    }
// --- end of file -------------------------------------------

FIXME … und es geht noch weiter…

1)
'Scope' denotes the visibility and scope of a variable. 'Global Scope' is the area which is also addressed by the superglobal $_GLOBALS [].
2)
mit 'Scope' wird der Sichtbarkeits- und Gültigkeitsbereich einer Variablen bezeichnet. 'Global Scope ist der Bereich, der auch durch die Superglobale $_GLOBALS[] angesprochen wird.
en/dev/284/helloworld.1439675273.txt.gz · Last modified: 15.08.2015 21:47 by mrbaseman