Page 1 of 1

Digg News

Posted: Sat Oct 29, 2005 10:45 pm
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!

Posted: Sun Oct 30, 2005 4:44 am
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?

Posted: Sun Oct 30, 2005 1:42 pm
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

Posted: Sun Oct 30, 2005 5:16 pm
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 : */
?>

Posted: Sun Oct 30, 2005 7:09 pm
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

Posted: Sun Oct 30, 2005 8:32 pm
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!

Posted: Tue May 02, 2006 5:35 pm
by martoq
Forgive my ignorance but how do you implement this?

Posted: Tue May 02, 2006 6:05 pm
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

Posted: Wed May 03, 2006 2:52 pm
by martoq
Very nice, thanks!