Free Stock ticker bar script for Joomla / Wordpress


#1

few days back i coded a small script to show stock ups and downs ticker , script fetches data from yahoo finance and scrolls the ticker , you can use this script on on Joomla (tested on joomla 1.5) and all versions of wordpress .

How to use the script

[quote=", post:, topic:"]

<?php

function getStockSite($stockLink){

if ($fp = fopen($stockLink, 'r')) {

$content = '';

while ($line = fread($fp, 1024)) {

$content .= $line;

}

}

return $content;

}

function processStockSite($wurl){

$wrss = getStockSite($wurl);

$name = '-';

$price = '';

$diff = '';

if (strlen($wrss)>100){

$spos = 0;

// Get text

$spos = strpos($wrss,':',$spos)+3;

$spos = strpos($wrss,'',$spos);

$epos = strpos($wrss,'

',$spos);

if ($epos>$spos){

$text = substr($wrss,$spos,$epos-$spos);

} else {

$text = '-';

}

$spos = $epos + 10;

// Get company name

$epos = strpos($wrss,'<',$spos);

if ($epos>$spos){

$name = substr($wrss,$spos,$epos-$spos);

}

// Get actual price

$spos = strpos($wrss,'yfs_l10')+strlen('yfs_l10');

$spos = strpos($wrss,'>',$spos)+1;

$epos = strpos($wrss,'<',$spos);

if ($epos>$spos){

$price = substr($wrss,$spos,$epos-$spos);

} else {

$price = '-';

}

// Get direction

$spos = strpos($wrss,'alt',$epos)+strlen('alt')+2;

$epos = strpos($wrss,'"',$spos);

if ($epos>$spos){

$dir = strtolower(substr($wrss,$spos,$epos-$spos));

}

// Get difference

$spos = strpos($wrss,'>',$epos+3)+1;

$epos = strpos($wrss,'<',$spos);

if ($epos>$spos){

$diff = substr($wrss,$spos,$epos-$spos);

}

}

$result['name'] = $name;

$result['value'] = $price;

$result['diff'] = $diff;

$result['direction'] = $dir;

$result['text'] = $text;

return $result;

}

?>

<?

// Get stock data

//$data = processStockSite('ttp://finance.yahoo.com'); // Google

$data = processStockSite('http://finance.yahoo.com/q?s=GOOG'); // Google

?>

<?php echo $data['name']; ?>$

<?php

echo $data['text'];

//echo $data['value'].' ';

//if ($data['direction'] == 'up') echo ' +'.$data['diff].'';

//else echo ' -'.$data['diff'].''; ?>

<?php

$data = processStockSite('http://finance.yahoo.com/q?s=MSFT'); // Microsoft

?><?php echo $data['name']; ?>$

<?php

echo $data['text'];

//echo $data['value'].' ';

//if ($data['direction'] == 'up') echo ' +'.$data['diff].'';

//else echo ' -'.$data['diff'].''; ?>

<?php

$data = processStockSite('http://finance.yahoo.com/q?s=AAPL'); // Apple

echo $data['name'];

echo $data['text'];

$data = processStockSite('http://finance.yahoo.com/q?s=GE'); // GE

echo $data['name'];

echo $data['text'];

$data = processStockSite('http://finance.yahoo.com/q?s=BELFA');//Bel Fuse Inc

echo $data['name'];

echo $data['text'];

$data = processStockSite('http://finance.yahoo.com/q?s=BIOD');//Bio Del

echo $data['name'];

echo $data['text'];

?>

<?php echo $data['name']; ?>$

<?php

echo $data['text'];

//echo $data['value'].' ';

//if ($data['direction'] == 'up') echo ' +'.$data['diff].'';

//else echo ' -'.$data['diff'].''; ?>

[/quote]

For Joomla

Download and install Joomla PHP component "Jumi" from here : http://extensions.joomla.org/extensions/edition/custom-code-in-content/1023

create new "Jumi " module and paste this script and save the module . thats it !

For Wordpress

download this plugin :http://wordpress.org/extend/plugins/exec-php/

and paste the above script , it will work !

you can replace or add stock values i.e http://finance.yahoo.com/q?s=AAPL ( for apple ) with any values by refering to yahoo finance .

Demo

http://universocanario.com/