+ Antworten
Ergebnis 1 bis 2 von 2

Thema: conten beispiel plugin geht nicht

  1. #1
    Verbringt hier viel Zeit
    Registriert seit
    12.05.2005
    Beiträge
    541
    Bedankte sich
    29
    Erhielt 84 Danksagungen
    in 83 Beiträgen

    Standard conten beispiel plugin geht nicht

    Ich hab von der site

    http://docs.joomla.org/Make_changes_...using_a_plugin

    folgendes Beispielplugin geladen

    PHP-Code:
    <?php
    /**
     * @copyright   Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
     * @license             GNU/GPL, see LICENSE.php
     */

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

    jimport'joomla.plugin.plugin' );

    class 
    plgContentModifyArticle extends JPlugin
    {

            
    /**
             * Constructor
             *
             * For php4 compatability we must not use the __constructor as a constructor for plugins
             * because func_get_args ( void ) returns a copy of all passed arguments NOT references.
             * This causes problems with cross-referencing necessary for the observer design pattern.
             *
             * @param object $subject The object to observe
             * @param object $params  The object that holds the plugin parameters
             * @since 1.5
             */
            
    function plgContentModifyArticle ( &$subject$params )
            {
                    
    parent::__construct$subject$params );
            }

            
    /**
             * Example before save content method
             *
             * Method is called right before content is saved into the database.
             * Article object is passed by reference, so any changes will be saved!
             * NOTE:  Returning false will abort the save with an error.
             *      You can set the error by calling $article->setError($message)
             *
             * @param       object          A JTableContent object
             * @param       bool            If the content is just about to be created
             * @return      bool            If false, abort the save
             */
           
    function onBeforeContentSave( &$article$isNew )
            {
                    global 
    $mainframe;
                    
    $newText '<p>This is my new text to add to the article.</p>';
                    
    $user =& JFactory::getUser(); // get the user
                    
    if ($user->usertype == 'Author') {
                            if (
    $article->fulltext) {
                                    if (
    strpos($article->fulltext$newText) == 0) {
                                            
    $article->fulltext .= $newText;
                                    }
                            }
                            else {
                                    if (
    strpos($article->introtext$newText) == 0) {
                                            
    $article->introtext .= $newText;
                                    }
                            }
                    }
                    return 
    true;
            }

    }
    ?>
    die xml Datei Dazu

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <install version="1.5" type="plugin" group="content">
    <name>Modify Edited Articles</name>
    <creationDate>January 2009</creationDate>
    <author>Joomla Doc Team</author>
    <authorEmail>myemail@myemail.com</authorEmail>
    <authorUrl>http://joomlacode.org</authorUrl>
    <copyright>Copyright (c) 2009</copyright>
    <license>GPL</license>
    <version>1.0.0</version>
    <description>Example plugin for Joomla! wiki.</description>
    <files>
       <filename plugin="modifyarticle">modifyarticle.php</filename>
    </files>
    </install>
    Wenn ich jetzt einen Artikel aufrufe und danach speichere sollte doch an sich

    This is my new text to add to the article.

    am Ende eines Artikels stehen. Geht aber nicht
    Geändert von Pherfinion (22.08.2010 um 17:26 Uhr)

  2. #2
    Verbringt hier viel Zeit
    Registriert seit
    12.05.2005
    Beiträge
    541
    Bedankte sich
    29
    Erhielt 84 Danksagungen
    in 83 Beiträgen

    Standard geht so $mainframe->registerEvent( 'onBeforeContentSave', 'modArticle' );

    <?php
    /**
    * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
    * @license GNU/GPL, see LICENSE.php
    */

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

    jimport( 'joomla.plugin.plugin' );


    class plgContentModifyArticle extends JPlugin
    {
    function plgContentModifyArticle (& $subject) {
    parent::__construct($subject);
    }
    }

    $mainframe->registerEvent( 'onBeforeContentSave', 'modArticle' );

    function modArticle( &$article, $isNew )
    {
    global $mainframe;
    $newText = '<p>This is my new text to add to the article.</p>';
    $user =& JFactory::getUser(); // get the user
    if ($user->usertype == 'Author') {
    if ($article->fulltext) {
    if (strpos($article->fulltext, $newText) == 0) {
    $article->fulltext .= $newText;
    }
    }
    else {
    if (strpos($article->introtext, $newText) == 0) {
    $article->introtext .= $newText;
    }
    }
    }
    //$article->fulltext .= $newText;
    return true;
    }


    ?>

+ Antworten

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein