Bot onPrepareContent |
Redaktor: Stefan Wajda | |
19.06.2007. | |
Poniżej znajduje się przykład dodatku wykonywanego przy zdarzeniu onPrepareContent (innymi słowy tradycyjny dodatek).
<?php /** * @version $Id $ * @package Joomla! 1.0 * @Copyright © 2000-2005 Open Source Matters, All Rights Reserved * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL * Joomla! is Free Software */ /** ensure this file is being included by a parent file */ defined('_VALID_MOS') or die('Direct Access to this location is not allowed.'); $_PLUGINS->registerFunction( 'onPrepareContent', 'botMosLink' ); /** * Link bot * * Usage: * <code>{moslink id="the_id"}</code> */ function botMosLink( $published, &$row, $mask=0, $page=0 ) { global $mosConfig_absolute_path; if (!$published) { return true; } require_once( $mosConfig_absolute_path . '/includes/domit/xml_saxy_lite_parser.php' ); // define the regular expression for the bot $regex = "#{moslinks*(.*?)}#s"; // perform the replacement $row->text = preg_replace_callback($regex,'botMosLink_replacer',$row->text); return true; } /** * Replaces the matched tags an image * @param array An array of matches (see preg_match_all) * @return string */ function botMosLink_replacer(&$matches) { $attribs = @SAXY_Lite_Parser::parseAttributes( $matches[1]); $id = @$attribs['id']; return '<a href="http://www.pomoc.joomla.pl/' .sefRelToAbs('index.php?option=com_content&task=view&id=' . $id) .'">Link</a>'; } ?> Funkcje wywoływane przez function function_name( int $published, object &$row, int $mask=0, int $page=0 )
Wyzwalacz Wykorzystanie wbudowanej funkcji Możesz się dziwić, po co przekazywany jest argument |
|
Zmieniony ( 19.06.2007. ) |