joomla erweitern

45
Joomla! erweitern Plugins, Module und Komponenten erstellen Joomla! User Group Fulda Achim Fischer #jugfulda

Upload: joomla-user-group-fulda

Post on 15-Jan-2015

631 views

Category:

Technology


2 download

DESCRIPTION

Joomla! erweitern - Eigene Plugins, Module und Komponenten erstellen" (Achim Fischer)

TRANSCRIPT

Joomla! erweiternPlugins, Module und Komponenten erstellen

Joomla! User Group Fulda

Achim Fischer

#jugfulda

Web-Entwicklung (PHP, RoR, JSP)

Software-Entwicklung (Java, C)

Mobile Geräte (Android, WP7, iOS)

Community Management (italobikes.com)

Joomla! Komponenten: Discussions, Marketplace, Primezilla & Vernissage

www.codingfish.com

Plugins

Module

Komponenten

Joomla!

Worin unterscheiden sich die 3 Typen?

Was sind die jeweiligen Einsatzgebiete?

Plugins

Ereignisgesteuertwie z.B. Datenbank Trigger

Beispiel:Ein Plugin das beim Anlegen eines neuen Benutzers

eine Aktion ausführt

Module

Werden an Modulpositionen des Templates angezeigt.Unterstützen häufig Komponenten

Beispiel:Letzte 10 Einträge im Marktplatz

Komponenten

Werden im Hauptbereich des Templates angezeigtEntsprechen Applikationen

Beispiele:Diskussionsforum

Kleinanzeigenmarkt

Plugins

Plugins

Einklinken in Systemevents

Ändern von Systemfunktionalität ohne ändern von Systemcode

Plugins

bestehen (mindestens) aus

1 XML Datei

1 PHP Datei

Plugins: marketplace.xml

<?xml version="1.0" encoding="utf-8"?>

<extension version="1.6" type="plugin" group="system" method="upgrade">

<name>System - Marketplace</name> <creationDate>June 2011</creationDate> <author>Codingfish (Achim Fischer)</author> <authorEmail>[email protected]</authorEmail> <authorUrl>http://www.codingfish.com</authorUrl> <copyright>All rights reserved.</copyright> <license>GPL 2</license> <version>1.5</version> <description>System Plugin for Codingfish Marketplace</description> <files> <filename plugin="marketplace">marketplace.php</filename> <filename>index.html</filename> </files> <params/> </extension>

Plugins: marketplace.xml

<?xml version="1.0" encoding="utf-8"?>

<extension version="1.6" type="plugin" group="system" method="upgrade">

<name>System - Marketplace</name> <creationDate>June 2011</creationDate> <author>Codingfish (Achim Fischer)</author> <authorEmail>[email protected]</authorEmail> <authorUrl>http://www.codingfish.com</authorUrl> <copyright>All rights reserved.</copyright> <license>GPL 2</license> <version>1.5</version> <description>System Plugin for Codingfish Marketplace</description> <files> <filename plugin="marketplace">marketplace.php</filename> <filename>index.html</filename> </files> <params/> </extension>

Plugins: Gruppen

authenticationcontenteditorseditors-xtdextensionsearchsystemuser

Es gibt 8 Core Groups:

Plugins: Gruppen

Zu beachten:

Nur jeweils 1 Plugin mit demselben Namen pro Gruppe

Es gibt reservierte Namen in den einzelnen Gruppen z.B. cache, debug, legacy, log und remember in system

Plugins: marketplace.php

...

function onUserAfterSave( $user, $isnew, $success, $msg) {

if ( $success) {

if ( $isnew) { // insert

// add a record to #__marketplace_users $db = JFactory::getDBO();

$sql = "INSERT INTO " . $db->nameQuote('#__marketplace_users') . " SET " . $db->nameQuote('id') . " = " . $user['id'] . ", " . "username=\"" . $user['username'] . "\"";

$db->setQuery( $sql); $db->query();

} else { // update

// update the user record in #__marketplace_users $db = JFactory::getDBO();

$sql = "UPDATE " . $db->nameQuote('#__marketplace_users') . " SET " . "username=\"" . $user['username'] . "\" " . "WHERE " . $db->nameQuote('id') . " = " . $user['id'];

$db->setQuery( $sql); $db->query();

}

}

}

...

Plugins: plg_marketplace.zip

marketplace.xml

+

marketplace.php

=

plg_marketplace.zip

Module

Module

bestehen (mindestens) aus

1 XML Datei

1 PHP Datei

Module: mod_marketplace_recentx.xml<?xml version="1.0" encoding="utf-8"?> <extension version="1.6" type="module" client="site" method="upgrade">

<name>Marketplace RecentX</name> <creationDate>June 2011</creationDate> <author>Codingfish (Achim Fischer)</author> <authorEmail>[email protected]</authorEmail> <authorUrl>http://www.codingfish.com</authorUrl> <copyright>All rights reserved.</copyright> <license>GPL 2</license> <version>1.2</version> <description>Module for Codingfish Marketplace. Displays recent X marketplace entries</description>

<files> <filename module="mod_marketplace_recentx">mod_marketplace_recentx.php</filename>

<filename>index.html</filename> </files>

<config>

<fields name="params">

<fieldset name="basic">...

<field name="number" type="text" default="5" label="# of entries to show" description="How many entries do you want to show in the recent x box?" />

... </fieldset>

</fields>

</config> </extension>

Module: mod_marketplace_recentx.php

<?php$_number = $params->get( 'number', 5 );$_length = $params->get( 'length', 25 );$_show_poweredby = $params->get( 'show_poweredby', 1 );$_more = $params->get( 'more', '>' );$_label = $params->get( 'label', 0 );

$db =& JFactory::getDBO();

$posts = null;

if ( $_label == 0) {

$query = 'SELECT e.id AS entryid, e.alias, e.category_id, e.image1 AS image, c.id, c.alias, c.name AS categoryname, e.headline,' . ' CASE WHEN CHAR_LENGTH(e.alias) THEN CONCAT_WS(\':\', e.id, e.alias) ELSE e.id END as eslug,' . ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as cslug,' . ' DATE_FORMAT( e.date_created, "%d.%m.%Y %k:%i") AS createdate' . ' FROM #__marketplace_entries e, #__marketplace_categories c' . ' WHERE e.category_id=c.id AND e.published=1 AND c.published=1' . ' ORDER BY e.date_created DESC LIMIT ' . $_number;

}

...

Module: mod_marketplace_recentx.zip

mod_marketplace_recentx.xml

+

mod_ marketplace_recentx.php

=

mod_ marketplace_recentx.zip

Module: Positionen auf der Website

1.

2.3.

Komponenten

Komponenten:

Werden im Hauptbereich des Templates angezeigt

Entsprechen Applikationen/Programmen

Komponenten:

Frontend

Backend

2 Bereiche

Komponenten

bestehen aus

1 XML Datei (mindestens)

Jeder Menge PHP, SQL, CSS, Javascript, Bilder, ...

Komponenten: marketplace.xml (Auszug)<?xml version="1.0" encoding="utf-8"?> <extension method="upgrade" type="component" version="1.6">

<name>Marketplace</name> <creationDate>October 2011</creationDate> <author>Codingfish (Achim Fischer)</author> <authorEmail>[email protected]</authorEmail> <authorUrl>http://www.codingfish.com</authorUrl> <copyright>All rights reserved</copyright> <license>GPL 2</license> <version>2.2.1</version> <description>Codingfish Marketplace</description> <install> <sql> <file driver="mysql" charset="utf8">install.mysql.utf8.sql</file> <file driver="mysql">install.mysql.sql</file> </sql> </install>

<uninstall> <sql> <file driver="mysql" charset="utf8">uninstall.mysql.sql</file> <file driver="mysql">uninstall.mysql.sql</file> </sql> </uninstall>

<files folder="site"> <folder>assets</folder> <folder>classes</folder> <folder>includes</folder> <folder>language</folder> <folder>models</folder> <folder>views</folder> <filename>index.html</filename> <filename>marketplace.php</filename> <filename>controller.php</filename> <filename>router.php</filename>

</files> ...

Komponenten: install.mysql.utf8.sql (Auszug)

CREATE TABLE IF NOT EXISTS `#__marketplace_users` ( `id` int(11) NOT NULL, `username` varchar(150) DEFAULT '', `status` tinyint(1) NOT NULL DEFAULT '0', `ads` int(11) NOT NULL DEFAULT '0', `moderator` tinyint(1) NOT NULL DEFAULT '0', `blocked` tinyint(1) NOT NULL DEFAULT '0', `firstname` varchar(255) DEFAULT NULL, `lastname` varchar(255) DEFAULT NULL, `company` varchar(255) DEFAULT NULL, `street` varchar(255) DEFAULT NULL, `zipcode` varchar(50) DEFAULT NULL, `city` varchar(255) DEFAULT NULL, `state` varchar(255) DEFAULT NULL, `country` varchar(255) DEFAULT NULL, `phone` varchar(255) DEFAULT NULL, `mobile` varchar(255) DEFAULT NULL, `email` varchar(255) DEFAULT NULL, `website` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), KEY `idx_moderator` (`moderator`)) DEFAULT CHARSET=utf8;

...

Komponenten: marketplace.php

<?php

// Check to ensure this file is included in Joomla! defined('_JEXEC') or die('Restricted Access');

// get the controller require_once(JPATH_COMPONENT.DS.'controller.php');

// instantiate and execute the controller $controller = new MarketplaceController();

$controller->execute(JRequest::getCmd('task', 'display'));

// redirect $controller->redirect();

Komponenten: controller.php

<?php

// Check to ensure this file is included in Joomla! defined('_JEXEC') or die('Restricted Access');

jimport('joomla.application.component.controller');

class MarketplaceController extends JController {

function display() { // Set a default view if none exists if ( ! JRequest::getCmd( 'view' ) ) { JRequest::setVar('view', 'index' ); } // display index parent::display(); }

}

Komponenten: index.php (Index Model, Auszug)class MarketplaceModelIndex extends JModel { ...

function getCategories() {

static $items; if (isset($items)) { return $items; }

$db =& $this->getDBO(); $query = "SELECT c.id, c.parent_id, c.name, c.alias, c.description, c.image, c.show_image, c.published, (select count(*) from ".$db->nameQuote('#__marketplace_entries')." e WHERE e.category_id = c.id AND e.published = '1') AS counter_entries, (select DATE_FORMAT( max(date_created), '%d.%m.%Y') from ".$db->nameQuote('#__marketplace_entries')." e WHERE e.category_id = c.id AND e.published = '1') AS last_entry_date, (select user_id from ".$db->nameQuote('#__marketplace_entries')." e WHERE e.category_id = c.id AND e.published = '1' ORDER BY DATE_CREATED DESC LIMIT 1) AS last_entry_user_id, CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(':', c.id, c.alias) ELSE c.id END as slug FROM ".$db->nameQuote('#__marketplace_categories')." c WHERE c.published='1' ORDER by c.ordering ASC";

$db->setQuery( $query ); $rows = $db->loadObjectList();

$children = array (); if( count( $rows)){ foreach ( $rows as $row) {

... } // class

Komponenten: index.php (Index View)class MarketplaceViewIndex extends JView {

function display() {

$document =& JFactory::getDocument(); $categories =& $this->get('Categories');

$params =& JComponentHelper::getParams('com_marketplace');

$menus = &JSite::getMenu(); $menu = $menus->getActive();

if (is_object( $menu )) {

$menu_params = new JParameter( $menu->params ); $pageTitle = $menu_params->get( 'page_title');

if (!$menu_params->get( 'page_title')) { $params->set( 'page_title', JText::_( 'Categories' ) ); } else { $params->set( 'page_title', $pageTitle ); } } else { $params->set( 'page_title', JText::_( 'Categories' ) ); }

$document->setTitle( $params->get( 'page_title' ) ); $this->assignRef('categories', $categories); $this->assignRef('params', $params); parent::display();

}

...

}

Komponenten: tmpl/default.php (Index Template, Auszug)

foreach ( $this->categories as $category ) : ?>

<tr> <?php if ( $category->show_image == 0) { // don't show category image

if ( $category->parent_id == 0) { // container ?> <td align="center" class="cofiContainer"> <?php } else { ?> <td align="center"> <?php }

echo "&nbsp;"; ?>

</td> <?php

} else {

...

Komponenten: Marketplace

Showtime

JED

Joomla! Extensions Directory

extensions.joomla.org

***************************

Vielen Dank