Joseph L. LeBlanc
homeportfoliojoomlabiocontactblog
articles
guides
tutorials
all
forum
Subscribe in NewsGator Online

Learning Joomla! for the first time? Buy the Joomla! 1.5 Essential training CD-ROM or watch it on Lynda.com.

 

Add To My Yahoo Module and Tutorial PDF Print E-mail

mod_myyahoo.php


This file is included when the module is acutally loaded.

<?php
 
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

With any PHP source code in Mambo, it is necessary to make sure the code is actually running within Mambo. This enhances security.

global $mosConfig_live_site;

This pulls the current site's url from Mambo's configuration file. It will be used below for building a link to the currently selected RSS feed.

$shortmessage = $params->get( 'shortmessage' );
$button = $params->get( 'button' );
$moduleclass_sfx = $params->get( 'moduleclass_sfx', '' );
$feed = $params->get( 'feed', 'RSS 0.91' );

Parameters defined in the XML file and set by the administrator are extracted into appropriate variables.

$feedurl = "";

switch( $feed )
{
    case "RSS 0.91":
    $feedurl = $mosConfig_live_site . '/index2.php?option=com_rss&feed=RSS0.91&no_html=1';
    break;

    case "RSS 1.0":
    $feedurl = $mosConfig_live_site . '/index2.php?option=com_rss&feed=RSS1.0&no_html=1';
    break;

    case "RSS 2.0":
    $feedurl = $mosConfig_live_site . '/index2.php?option=com_rss&feed=RSS2.0&no_html=1';
    break;

    case "Atom":
    $feedurl = $mosConfig_live_site . '/index2.php?option=com_rss&feed=ATOM0.3&no_html=1';
    break;

    default:
    $feedurl = $mosConfig_live_site . '/index2.php?option=com_rss&feed=RSS0.91&no_html=1';
    break;
}

Taking the value of the feed parameter and the site url, an apppropriate link is built. This link will be sent to My Yahoo! when the button is clicked.

$buttoncode = "";

switch( $button )
{
    case "short":
    $buttoncode = '<img src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo6.gif" width="89" height="33" border="0">';
    break;

    case "long":
    $buttoncode = '<img src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif" width="91" height="17" border="0">';
    break;

    default:
    $buttoncode = '<img src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif" width="91" height="17" border="0">';
    break;
}

Based on the chosen button, a link to the correct image on Yahoo's servers is built.

?>

<div class="myyahoo<?php echo $moduleclass_sfx;?>">

A styled 'div' is generated using a custom class.

<?php

if($shortmessage)
{
    echo '<div align="center" class="myyahoo_text'  . $moduleclass_sfx . '">' . $shortmessage . '</div>';
}

When the administrator adds a short message through the appropriate parameter in the backend, it is displayed here.

?>
    <div align="center">
    <a href="<?php echo 'http://add.my.yahoo.com/rss?url=' . $feedurl; ?>">
    <?php echo $buttoncode ?>
    </a>
    </div>
   
A nested 'div' centers the previously built button and the complete Add to My Yahoo! link is generated. When a visitor clicks this link, they are taken to My Yahoo! and guided through adding the newsfeed to their page. If they do not have a Yahoo! account, they will be prompted to create one.

</div>

Finishes the 'div' with an optional styled class.

Download the complete Add to My Yahoo! module here.