Recent Topics

Post info when inside a plugin?

Started by on Dec 08, 2005 – Contents updated: Dec 08, 2005

Dec 08, 2005 16:50    

I've no doubt it easy, but I can't seem to get any info about a post when I'm inside a plugin. For example I want the language and author for rendering, but they seem to be hiding from me. The way I've been approaching the issue is to randomly type in strings of stuff until php can deal with it, then see if it makes the author pop out. Not very effective so far... I'll keep poking around and post here if I happen to stumble across the obvious (and hope that someone smart comes along and just blurts it out for me).

EDIT: also the post date, and maybe the initial creation date. I'm trying to make the creative commons plugin work in the phoenix world. To stumble my way through it I use a lot of "pre print_r whatever /pre" and can't seem to find anything other than the current version of "this", which happens to be the licensing info.

Dec 08, 2005 19:24

I'm pretty sure that this ISN'T the right way to do it, but that's never stopped you before right? ;)

PHP

function Render( & $params )
    {
        if( ! parent::Render$params ) )
        { // We cannot render the required format
            return false;
        }
 
        global $Item;
        
        //print_r($Item);

Hope you got to fly in the snow ;)

¥

Dec 08, 2005 19:37

Thanks. I'll give it a go and it'll probably get the job done, but I'll keep poking around for a quality answer to the issue. The creative commons people say you should customimze the text a bit instead of the generic text they provide with their licenses, so I'm thinking "This post is the creative work of (link to all posts by author)preferred_name(/link) and is released under a (link to license) creative commons license(/link)" seems kinda cool.

No flying in snow yet, but I'm just south of Phoenix (the city - not the zip) so snow is kinda hard to come by :( On the brighter side, no one sells snow shovels here :D

Dec 08, 2005 19:43

AFAIK there's no clean way yet.

Probably we should pass the Item as param to the render() method.

Dec 08, 2005 20:13

blueyed wrote:

AFAIK there's no clean way yet.

Probably we should pass the Item as param to the render() method.

Cool, does that make me the "quality answer" then? :p

¥

May 23, 2006 16:10

I am trying to write a basic avatars plugin for the latest CVS code I got today, has this situation changed at all?
[edit] After looking at the test plugin, I saw that $params['User'] was used, however, I get

Code

Line :       $default_image_path = $params['User'] -> get_media_dir()."avatar.png";
 
Fatal error: Call to a member function on a non-object in /home/www/roxxoran/therox/b2evolution/blogs/plugins/_avatar.plugin.php on line 52
[\edit]

2nd edit: It seems that $params['User'] doesn't exist in RenderToHTML() so I'll probably try capture it somewhere in another function, not sure what though

May 24, 2006 23:03

There are different $param arrays for each method/hook. And those objects/params get passed which make sense - or at least they should.. :)

I've just committed the change that "Item" gets added to the params for the Render* methods and through this you should get the item's author then.

If you want to have the current, logged in, user instead, use the $current_User global.

May 25, 2006 12:17

Thanks! I'll post the working plugin once I get the chance to do some coding :)

May 30, 2006 02:42

needs polish, but its there by pure brute force:

PHP

<?php
/**
 *
 * b2evolution - {@link http://b2evolution.net/}
 * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
 * @copyright (c)2003-2005 by orta - {@link http://therox.org/}
 *
 * @package plugins
 */
if( !defined('EVO_MAIN_INIT') ) die'Please, do not access this page directly.' );
 
 
/**
 * @package plugins
 */
class avatar_plugin extends Plugin
{
    var $code 'b2ava';
    var $name 'Avatars';
    var $priority 100;
    var $version '0.1';
    var $author 'orta';
    var $help_url 'http://therox.org/';
    var $apply_rendering 'opt-out';
    var $number_of_installs 1;
    var $short_desc;
    var $long_desc;
 
 
    /**
     * Constructor
     */
    function avatar_plugin()
    {
        $this->short_desc T_('Add avatars to posts');
        $this->long_desc T_('Add avatars to each posts, they are assigned to the ');
    }
 
 
    /**
     * Perform rendering
     *
     * @param array Associative array of parameters
     *                             (Output format, see {@link format_to_output()})
     * @return
      boolean true if we can render something for the required output format
     */
    function RenderItemAsHtml( & $params )
    {
       $item $params['Item'];
        $author $item-> Author;
        $default_image_path '../../media/users/';
        $default_image_path .= $author -> nickname '/';
        $default_image_path .= $author -> nickname;
        $default_image_path .= '.png';
        
        $content '<img src = "' $default_image_path;
        $content .= '" class="rightmargin';
        $content .= '" />'
        $content .= "\n"
        $content .= $params['data'];
        $params['data'] = $content;
 
        return true;
    }
}
 
?>

May 30, 2006 11:01

I may be wrong, but I think that this :-

PHP

function RenderItemAsHtml( & $params )
    {
       $item $params['Item'];
        $author $item-> Author;
        $default_image_path '../../media/users/';
        $default_image_path .= $author -> nickname '/';
        $default_image_path .= $author -> nickname;
        $default_image_path .= '.png';
        
        $content '<img src = "' $default_image_path;
        $content .= '" class="rightmargin';
        $content .= '" />'
        $content .= "\n"
        $content .= $params['data'];
        $params['data'] = $content;
 
        return true;
    }

Should read like this :-

PHP

function RenderItemAsHtml( & $params )
    {
       global $media_url;
 
        $author $params['Item']->Author->login;
        $default_image_path $media_url.'users/'.$author.'/'.$author.'.png';
        
        $content '<img src = "' $default_image_path;
        $content .= '" class="rightmargin';
        $content .= '" />'
        $content .= "\n"
        $content .= $params['data'];
        $params['data'] = $content;
 
        return true;
    }

¥

May 30, 2006 12:55

I like that, I've still got a lot to learn with respect to PHP :)


Form is loading...

Social CMS software – This forum is powered by b2evolution CMS, a complete engine for your website.