Digg News

Creating and modifying plugins.
Post Reply
Gagtech
Regular
Posts: 8
Joined: Thu Oct 27, 2005 2:04 am
Contact:

Digg News

Post by Gagtech »

Edited with release:

awesome, well here is the finished script for anyone that wants to use it:

Code: Select all

<?php # $Id: serendipity_plugin_diggednews.php,v1.0 2005/10/30 14:30:30 garvinhicking Exp $

@define('PLUGIN_DIGGEDNEWS_NAME',           'Your Digged News.');
@define('PLUGIN_DIGGEDNEWS_DESC',           'Adds sidebar links to your dugg www.digg.com news.');
@define('PLUGIN_DIGGEDNEWS_USERNAME_NAME',       'Digg.com Username');
@define('PLUGIN_DIGGEDNEWS_USERNAME_DESC',       'Enter your username for the personal dugg news information');
@define('PLUGIN_DIGGEDNEWS_ARTICLES_NAME', 'Number of articles (5,10,15)');
@define('PLUGIN_DIGGEDNEWS_ARTICLES_DESC', 'Enter the number of articles that you want to be displayed at once.');

class serendipity_plugin_diggednews extends serendipity_plugin 
{
    var $title = PLUGIN_DIGGEDNEWS_NAME;

    function introspect(&$propbag)
    {
        $this->title = $this->get_config('title', $this->title);

        $propbag->add('name',          PLUGIN_DIGGEDNEWS_NAME);
        $propbag->add('description',   PLUGIN_DIGGEDNEWS_DESC);
        $propbag->add('stackable',     false);
        $propbag->add('author',        'Will Cormier');
        $propbag->add('version',       '1.0');
        $propbag->add('requirements',  array(
            'serendipity' => '0.8',
            'smarty'      => '2.6.7',
            'php'         => '4.1.0'
        ));
        $propbag->add('configuration', array('title', 'username', 'articles'));
    }

    function introspect_config_item($name, &$propbag) 
    {
        global $serendipity;

        switch($name) 
        {
            case 'title':
                $propbag->add('type',        'string');
                $propbag->add('name',        TITLE);
                $propbag->add('description', TITLE);
                $propbag->add('default',     '');
                break;

            case 'username':
                $propbag->add('type',        'string');
                $propbag->add('name',        PLUGIN_DIGGEDNEWS_USERNAME_NAME);
                $propbag->add('description', PLUGIN_DIGGEDNEWS_USERNAME_DESC);
                $propbag->add('default',     'Gagtech');
                break;

            case 'articles':
                $propbag->add('type',        'string');
                $propbag->add('name',        PLUGIN_DIGGEDNEWS_ARTICLES_NAME);
                $propbag->add('description', PLUGIN_DIGGEDNEWS_ARTICLES_DESC);
                $propbag->add('default',     '5');
                break;

            default:
                    return false;
        }
        return true;
    }

    function generate_content(&$title) 
    {
        global $serendipity;

        $title = $this->get_config('title');
        $path = 'http://digg.com/jsdig/' . $this->get_config('articles') . '/' . $this->get_config('username');

        echo '<script language="JavaScript" src="' . $path . '" type="text/javascript"></script>';
    }
}
/* vim: set sts=4 ts=4 expandtab : */
?>
Enjoy!
Last edited by Gagtech on Mon Oct 31, 2005 2:17 am, edited 1 time in total.
Gagtech
Regular
Posts: 8
Joined: Thu Oct 27, 2005 2:04 am
Contact:

Post by Gagtech »

Ok, I'm almost done, I'm just having troubles with the last bit of code.

What I want to do is pass a variable from the config into a <script> tag and I'm not quite sure how to do it.

This is what I was trying to do:

Code: Select all

$path  = 'http://digg.com/jsdig/' + $this->get_config('articles') + '/' + $this->get_config('username');

	echo '<script language="JavaScript" src=$path type="text/javascript"></script>';
But its not working. It wont see the $path as a variable in the <script>

Anyone know how to fix this? or a work around?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Where exactly do you try to make this variable assignment? Please post your PHP code somewhere so that we can see the context of the plugin.

It is definitely possible to do it, I just need more of your code :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Gagtech
Regular
Posts: 8
Joined: Thu Oct 27, 2005 2:04 am
Contact:

Post by Gagtech »

Here is the whole thing:

Code: Select all

<?php # $Id: serendipity_plugin_diggednews.php,v0.1 2005/10/29 23:22:30 garvinhicking Exp $

@define('PLUGIN_DIGGEDNEWS_NAME',           'Your Digged News.');
@define('PLUGIN_DIGGEDNEWS_DESC',           'Adds sidebar links to your dugg www.digg.com news.');
@define('PLUGIN_DIGGEDNEWS_USERNAME_NAME',       'Digg.com Username');
@define('PLUGIN_DIGGEDNEWS_USERNAME_DESC',       'Enter your username for the personal dugg news information');
@define('PLUGIN_DIGGEDNEWS_ARTICLES_NAME', 'Number of articles (5,10,15)');
@define('PLUGIN_DIGGEDNEWS_ARTICLES_DESC', 'Enter the number of articles that you want to be displayed at once.');
@define('PLUGIN_DIGGEDNEWS_ERROR',          'ERROR: Could not find username.');

class serendipity_plugin_diggednews extends serendipity_plugin {
    var $title = PLUGIN_DIGGEDNEWS_NAME;

    function introspect(&$propbag)
    {
        $this->title = $this->get_config('title', $this->title);

        $propbag->add('name',          PLUGIN_DIGGEDNEWS_NAME);
        $propbag->add('description',   PLUGIN_DIGGEDNEWS_DESC);
        $propbag->add('stackable',     false);
        $propbag->add('author',        'Will Cormier');
        $propbag->add('version',       '0.1');
        $propbag->add('requirements',  array(
            'serendipity' => '0.8',
            'smarty'      => '2.6.7',
            'php'         => '4.1.0'
        ));
        $propbag->add('configuration', array('title', 'username', 'articles'));
    }

    function introspect_config_item($name, &$propbag)
    {
        global $serendipity;

        switch($name) {
            case 'title':
                $propbag->add('type',        'string');
                $propbag->add('name',        TITLE);
                $propbag->add('description', TITLE);
                $propbag->add('default',     '');
                break;

            case 'username':
                $propbag->add('type',        'string');
                $propbag->add('name',        PLUGIN_DIGGEDNEWS_USERNAME_NAME);
                $propbag->add('description', PLUGIN_DIGGEDNEWS_USERNAME_DESC);
                $propbag->add('default',     'Gagtech');
                break;

            case 'articles':
                $propbag->add('type',        'string');
                $propbag->add('name',        PLUGIN_DIGGEDNEWS_ARTICLES_NAME);
                $propbag->add('description', PLUGIN_DIGGEDNEWS_ARTICLES_DESC);
                $propbag->add('default',     '5');
                break;

            default:
                    return false;
        }
        return true;
    }

    function generate_content(&$title) {
        global $serendipity;

        $title = $this->get_config('title');
        $path  = 'http://digg.com/jsdig/' . $this->get_config('articles') . '/' . $this->get_config('username');

	echo '<script language="JavaScript" src="$path" type="text/javascript"></script>';
	
	

    }
}
/* vim: set sts=4 ts=4 expandtab : */
?>
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Okay, your problem is a simple PHP mistake.

Variables within single-quoted Strings are not interpolated. Instead of this:

Code: Select all

        $path  = 'http://digg.com/jsdig/' . $this->get_config('articles') . '/' . $this->get_config('username');

	echo '<script language="JavaScript" src="$path" type="text/javascript"></script>';
[code]

You need to write this:
	
[code]
        $path  = 'http://digg.com/jsdig/' . $this->get_config('articles') . '/' . $this->get_config('username');

	echo "<script language=\"JavaScript\" src=\"$path\" type=\"text/javascript\"></script>";
[code]

or this:

[code]
        $path  = 'http://digg.com/jsdig/' . $this->get_config('articles') . '/' . $this->get_config('username');

	echo '<script language="JavaScript" src="' . $path . '" type="text/javascript"></script>';
[code]

Whatever you prefer :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Gagtech
Regular
Posts: 8
Joined: Thu Oct 27, 2005 2:04 am
Contact:

Post by Gagtech »

awesome, well here is the finished script for anyone that wants to use it:

Code: Select all

<?php # $Id: serendipity_plugin_diggednews.php,v1.0 2005/10/30 14:30:30 garvinhicking Exp $

@define('PLUGIN_DIGGEDNEWS_NAME',           'Your Digged News.');
@define('PLUGIN_DIGGEDNEWS_DESC',           'Adds sidebar links to your dugg www.digg.com news.');
@define('PLUGIN_DIGGEDNEWS_USERNAME_NAME',       'Digg.com Username');
@define('PLUGIN_DIGGEDNEWS_USERNAME_DESC',       'Enter your username for the personal dugg news information');
@define('PLUGIN_DIGGEDNEWS_ARTICLES_NAME', 'Number of articles (5,10,15)');
@define('PLUGIN_DIGGEDNEWS_ARTICLES_DESC', 'Enter the number of articles that you want to be displayed at once.');

class serendipity_plugin_diggednews extends serendipity_plugin 
{
    var $title = PLUGIN_DIGGEDNEWS_NAME;

    function introspect(&$propbag)
    {
        $this->title = $this->get_config('title', $this->title);

        $propbag->add('name',          PLUGIN_DIGGEDNEWS_NAME);
        $propbag->add('description',   PLUGIN_DIGGEDNEWS_DESC);
        $propbag->add('stackable',     false);
        $propbag->add('author',        'Will Cormier');
        $propbag->add('version',       '1.0');
        $propbag->add('requirements',  array(
            'serendipity' => '0.8',
            'smarty'      => '2.6.7',
            'php'         => '4.1.0'
        ));
        $propbag->add('configuration', array('title', 'username', 'articles'));
    }

    function introspect_config_item($name, &$propbag) 
    {
        global $serendipity;

        switch($name) 
        {
            case 'title':
                $propbag->add('type',        'string');
                $propbag->add('name',        TITLE);
                $propbag->add('description', TITLE);
                $propbag->add('default',     '');
                break;

            case 'username':
                $propbag->add('type',        'string');
                $propbag->add('name',        PLUGIN_DIGGEDNEWS_USERNAME_NAME);
                $propbag->add('description', PLUGIN_DIGGEDNEWS_USERNAME_DESC);
                $propbag->add('default',     'Gagtech');
                break;

            case 'articles':
                $propbag->add('type',        'string');
                $propbag->add('name',        PLUGIN_DIGGEDNEWS_ARTICLES_NAME);
                $propbag->add('description', PLUGIN_DIGGEDNEWS_ARTICLES_DESC);
                $propbag->add('default',     '5');
                break;

            default:
                    return false;
        }
        return true;
    }

    function generate_content(&$title) 
    {
        global $serendipity;

        $title = $this->get_config('title');
        $path = 'http://digg.com/jsdig/' . $this->get_config('articles') . '/' . $this->get_config('username');

        echo '<script language="JavaScript" src="' . $path . '" type="text/javascript"></script>';
    }
}
/* vim: set sts=4 ts=4 expandtab : */
?>
Enjoy!
martoq
Regular
Posts: 41
Joined: Thu Mar 10, 2005 5:05 pm

Post by martoq »

Forgive my ignorance but how do you implement this?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Just save that snippet inside a "plugins/serendipity_plugin_diggednews/serendipity_plugin_diggednews.php" and then you can install it from the s9y plugin manager

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
martoq
Regular
Posts: 41
Joined: Thu Mar 10, 2005 5:05 pm

Post by martoq »

Very nice, thanks!
Post Reply