Joomla!1.5的plug-in开发札记(一)
来源:互联网 发布:画设计图的软件手机 编辑:程序博客网 时间:2024/05/22 13:56
Joomla!1.5中的plug-in是事件驱动的,我看了楼主的帖子,发现你还是用的旧模式编写的。现在的Joomla!都是各种类协调工作的。要实现plug-in必须明白plug-in的分类,目前joomla!的plug-in分为八类:
<?xml version="1.0" encoding="utf-8"?>
<install version="1.5" type="plugin" group="user">
<name>User - Example</name>
<author>Joomla! Project</author>
<creationDate>November 2005</creationDate>
<copyright>Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
<authorEmail>admin@joomla.org</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>1.0</version>
<description>An example user synchronisation plugin</description>
<files>
<filename plugin="example">example.php</filename>
</files>
<params/>
</install>
注意这句<install version="1.5" type="plugin" group="user">,其中type表明安装包为plug-in
group ="user"表明此plug-in为关于user的.接着注意这句<filename plugin="example">example.php</filename>,其中 plugin="example"非常重要,这个属性的值一定要跟包含plugin类的文件名相同。其他的我就不解释了。下面看example.php:
<?php
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();
jimport('joomla.plugin.plugin');
class plgUserExample extends JPlugin {
function plgUserExample(& $subject, $config)
{
parent::__construct($subject, $config);
}
// Method is called before user data is stored in the database
function onBeforeStoreUser($user, $isnew)
{
global $mainframe;
}
//Method is called after user data is stored in the database
function onAfterStoreUser($user, $isnew, $succes, $msg)
{
global $mainframe;
// convert the user parameters passed to the event
// to a format the external application
$args = array();
$args['username'] = $user['username'];
$args['email'] = $user['email'];
$args['fullname'] = $user['name'];
$args['password'] = $user['password'];
if ($isnew)
{
// Call a function in the external app to create the user
// ThirdPartyApp::createUser($user['id'], $args);
}
else
{
// Call a function in the external app to update the user
// ThirdPartyApp::updateUser($user['id'], $args);
}
}
// Method is called before user data is deleted from the database
function onBeforeDeleteUser($user)
{
global $mainframe;
}
//Method is called after user data is deleted from the database
function onAfterDeleteUser($user, $succes, $msg)
{
global $mainframe;
// only the $user['id'] exists and carries valid information
// Call a function in the external app to delete the user
// ThirdPartyApp::deleteUser($user['id']);
}
//This method should handle any login logic and report back to the subject
function onLoginUser($user, $options)
{
// Initialize variables
$success = false;
// Here you would do whatever you need for a login routine with the credentials
//
// Remember, this is not the authentication routine as that is done separately.
// The most common use of this routine would be logging the user into a third party
// application.
//
// In this example the boolean variable $success would be set to true
// if the login routine succeeds
// ThirdPartyApp::loginUser($user['username'], $user['password']);
return $success;
}
/**
* This method should handle any logout logic and report back to the subject
*
* @access public
* @param array holds the user data
* @return boolean True on success
* @since 1.5
*/
function onLogoutUser($user)
{
// Initialize variables
$success = false;
// Here you would do whatever you need for a logout routine with the credentials
//
// In this example the boolean variable $success would be set to true
// if the logout routine succeeds
// ThirdPartyApp::loginUser($user['username'], $user['password']);
return $success;
}
}
具体的可以看注释。因为时间的关系。我下次再分析源文件。见谅!
- authentication
- content
- editors
- editors-xtd
- search
- system
- user
- xmlrpc
<?xml version="1.0" encoding="utf-8"?>
<install version="1.5" type="plugin" group="user">
<name>User - Example</name>
<author>Joomla! Project</author>
<creationDate>November 2005</creationDate>
<copyright>Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
<authorEmail>admin@joomla.org</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>1.0</version>
<description>An example user synchronisation plugin</description>
<files>
<filename plugin="example">example.php</filename>
</files>
<params/>
</install>
注意这句<install version="1.5" type="plugin" group="user">,其中type表明安装包为plug-in
group ="user"表明此plug-in为关于user的.接着注意这句<filename plugin="example">example.php</filename>,其中 plugin="example"非常重要,这个属性的值一定要跟包含plugin类的文件名相同。其他的我就不解释了。下面看example.php:
<?php
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();
jimport('joomla.plugin.plugin');
class plgUserExample extends JPlugin {
function plgUserExample(& $subject, $config)
{
parent::__construct($subject, $config);
}
// Method is called before user data is stored in the database
function onBeforeStoreUser($user, $isnew)
{
global $mainframe;
}
//Method is called after user data is stored in the database
function onAfterStoreUser($user, $isnew, $succes, $msg)
{
global $mainframe;
// convert the user parameters passed to the event
// to a format the external application
$args = array();
$args['username'] = $user['username'];
$args['email'] = $user['email'];
$args['fullname'] = $user['name'];
$args['password'] = $user['password'];
if ($isnew)
{
// Call a function in the external app to create the user
// ThirdPartyApp::createUser($user['id'], $args);
}
else
{
// Call a function in the external app to update the user
// ThirdPartyApp::updateUser($user['id'], $args);
}
}
// Method is called before user data is deleted from the database
function onBeforeDeleteUser($user)
{
global $mainframe;
}
//Method is called after user data is deleted from the database
function onAfterDeleteUser($user, $succes, $msg)
{
global $mainframe;
// only the $user['id'] exists and carries valid information
// Call a function in the external app to delete the user
// ThirdPartyApp::deleteUser($user['id']);
}
//This method should handle any login logic and report back to the subject
function onLoginUser($user, $options)
{
// Initialize variables
$success = false;
// Here you would do whatever you need for a login routine with the credentials
//
// Remember, this is not the authentication routine as that is done separately.
// The most common use of this routine would be logging the user into a third party
// application.
//
// In this example the boolean variable $success would be set to true
// if the login routine succeeds
// ThirdPartyApp::loginUser($user['username'], $user['password']);
return $success;
}
/**
* This method should handle any logout logic and report back to the subject
*
* @access public
* @param array holds the user data
* @return boolean True on success
* @since 1.5
*/
function onLogoutUser($user)
{
// Initialize variables
$success = false;
// Here you would do whatever you need for a logout routine with the credentials
//
// In this example the boolean variable $success would be set to true
// if the logout routine succeeds
// ThirdPartyApp::loginUser($user['username'], $user['password']);
return $success;
}
}
具体的可以看注释。因为时间的关系。我下次再分析源文件。见谅!
- Joomla!1.5的plug-in开发札记(一)
- Joomla!1.5 MVC学习札记(一)-----命名约定
- Nagios plug-in开发
- 前端开发札记(一)
- Eclipse 开发plug-in 引用其它项目时 导出plug-in的方法
- 3ds Max插件开发(二)官网上的Sample utility plug-in
- eclipse plug-in 的开发-- Rich Client 教程
- joomla的使用(一)
- 第四章 Joomla!扩展开发--前端开发(一)
- 开发Joomla的顺序
- Eclipse Plug-in的资料
- Joomla 1.5架构(一) 架构概述
- plug-in app 的重构和java中功能选项的移除指南(一)
- joomla组件开发(一)Developing a Basic Component
- 用Eclipse & plug-in开发j2ee
- Photoshop插件开发之Listener Plug-in
- 前台开发,Chrome常用plug-in
- 《银行的秘密》读书札记(一)
- 微软推出更新的搜索服务 向谷歌发起挑战
- Autoruns v9.12
- Hiew v7.50
- 微软高管“暗会”Facebook CEO 增大收购系数
- FACEBOOK到底是么鬼东西?
- Joomla!1.5的plug-in开发札记(一)
- 在运用面向对象分析设计的基础上利用中间件技术构建SOA构架实现多元化可扩展的Workflow引擎组
- [CampusSource和GearMaster开发]开发并不顺利
- 鲍尔默:微软发展来自对八个核心领域持续投资 (作者:三张 | 出处:网易科技 )
- 初识Firebug 全文 — firebug的使用
- ACE菜鸟的问题
- 时间单位换算表
- DBF导入SqlServer
- 如何用英语表达“忽悠”?