Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6051405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:49:02+00:00 2026-05-23T07:49:02+00:00

I am using a wordpress plugin that fetches stock quote feed from Yahoo finance.

  • 0

I am using a wordpress plugin that fetches stock quote feed from Yahoo finance. IT JUST HAPPENS VERY RARELY… OTHERWISE IT DON’T SHOW UP. I randomly get fatal error saying on line 140 … and line 140 is break; i am copying below quote to understand the code. EDIT: NOW I HAVE PUT THE ENTIRE PHP FILE…!!

<?php

/*
Plugin Name: Stock Quotes
Plugin URI: http://www.dagondesign.com/articles/stock-quotes-plugin-for-wordpress/
Description: Displays stock quotes on your website
Author: Dagon Design
Version: 1.0.1
Author URI: http://www.dagondesign.com
*/

$ddsq_version = ‘1.0.1’;

// Setup defaults if options do not exist
add_option(‘ddsq_format’, ‘%NAME%: %LAST% ( %CHANGE% )’);
add_option(‘ddsq_up_color’, ’00BB00′);
add_option(‘ddsq_down_color’, ‘FF0000’);
add_option(‘ddsq_update_time’, ’10’);

function ddsq_add_option_pages() {
if (function_exists(‘add_options_page’)) {
add_options_page(‘Stock Quotes’, ‘DDStockQuotes’, 8, FILE, ‘ddsq_options_page’);
}
}

function ddsq_options_page() {

global $ddsq_version;

if (isset($_POST['set_defaults'])) {
    echo '<div id="message" class="updated fade"><p><strong>';

    update_option('ddsq_format', '<strong>%NAME%</strong> %LAST% [<strong>%CHANGE%</strong>]');
    update_option('ddsq_up_color', '00BB00');
    update_option('ddsq_down_color', 'FF0000');
    update_option('ddsq_update_time', '10');

    echo 'Default Options Loaded!';
    echo '</strong></p></div>';

} else if (isset($_POST['info_update'])) {

    update_option('ddsq_format', (string) $_POST["ddsq_format"]);
    update_option('ddsq_up_color', (string) $_POST["ddsq_up_color"]);
    update_option('ddsq_down_color', (string) $_POST["ddsq_down_color"]);
    update_option('ddsq_update_time', $_POST["ddsq_update_time"]);

    echo 'Configuration Updated!';
    echo '</strong></p></div>';

} ?>

<div class=wrap>

<h2>Stock Quotes v<?php echo $ddsq_version; ?></h2>

<p>For information and updates, please visit:<br />
<a href="http://www.dagondesign.com/articles/stock-quotes-plugin-for-wordpress/">http://www.dagondesign.com/articles/stock-quotes-plugin-for-wordpress/</a></p>


<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
<input type="hidden" name="info_update" id="info_update" value="true" />


<h3>Usage</h3>
<p>There are two ways you can display quotes:</p>
<p><strong>1) In a post or page</strong>
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
[stock MSFT]</p>
<p><strong>2) In a template file</strong>
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;?php echo ddsq_get_quote('MSFT'); ?&gt;</p>


<h3>Options</h3>
<table width="100%" border="0" cellspacing="6" cellpadding="4">

<tr valign="top"><td width="13%">
    <strong>Output Format </strong>
</td><td align="left">
    <input name="ddsq_format" type="text" size="100" value="<?php echo htmlspecialchars(stripslashes(get_option('ddsq_format'))) ?>"/>
    <br />Placeholders for data: <strong>%NAME% %LAST% %CHANGE%</strong>
</td></tr>

<tr valign="top"><td width="13%">
    <strong>Up Color </strong>
</td><td align="left">
    <input name="ddsq_up_color" type="text" size="7" value="<?php echo get_option('ddsq_up_color') ?>"/>
     Color to use for price change when up (leave blank to disable)
</td></tr>

<tr valign="top"><td width="13%">
    <strong>Down Color </strong>
</td><td align="left">
    <input name="ddsq_down_color" type="text" size="7" value="<?php echo get_option('ddsq_down_color') ?>"/>
     Color to use for price change when down (leave blank to disable)
</td></tr>

<tr valign="top"><td width="13%">
    <strong>Update Time </strong>
</td><td align="left">
    <input name="ddsq_update_time" type="text" size="3" value="<?php echo get_option('ddsq_update_time') ?>"/>
    Number of minutes to wait, before fetching updated stock prices
</td></tr>
</table>

<div class="submit">
    <input type="submit" name="set_defaults" value="<?php _e('Load Default Options'); ?> &raquo;" />
    <input type="submit" name="info_update" value="<?php _e('Update options'); ?> &raquo;" />
</div>

</form>
</div><?php

}

function ddsq_get_quote($symb) {

$up_color = trim(get_option('ddsq_up_color'));
$down_color = trim(get_option('ddsq_down_color'));
$quote_format = stripslashes(get_option('ddsq_format'));
$update_time = trim(get_option('ddsq_update_time'));

$update_time = $update_time * 60;
$t_out = '';
$time_diff = '';

// Trying to open local cached file first
$file_path = WP_PLUGIN_DIR . "/" . $symb . ".txt";
if (file_exists($file_path)){
    $time_diff = date('U') - filemtime($file_path);
}

$lf = @fopen($file_path, "r");
if (($lf == FALSE) || ($time_diff >= $update_time)) {
    $url = "http://finance.yahoo.com/d/quotes.csv?s=" . $symb . "&f=sl1c1";
    $fp = @fopen($url, "r");
    if ($fp == FALSE) {
        #$t_out = 'Error opening: ' . htmlspecialchars($url);
        break;
    } else {
        $array = @fgetcsv($fp , 4096 , ', ');
        @fclose($fp);
        $sq_name = $array[0];
        $sq_last = $array[1];
        $sq_change = $array[2];

        $col = NULL;
        if (($sq_change[0] == '-') && ($down_color != '')) {
            $col = $down_color;
        } else if (($sq_change[0] == '+') && ($up_color != '')) {
            $col = $up_color;
        }

        if ($col !== NULL) {
            $sq_change =  '<span style="color: #' . $col . ';">' . $sq_change . '</span>';
        }

        $t_out = $quote_format;
        $t_out = str_replace('%NAME%', $sq_name, $t_out);
        $t_out = str_replace('%LAST%', $sq_last, $t_out);
        $t_out = str_replace('%CHANGE%', $sq_change, $t_out);

        $cache_file = fopen($file_path, "w+");
        fwrite($cache_file, $t_out);
    }
} else {
    fclose($lf);
    $t_out = file_get_contents($file_path);
    if ($t_out == FALSE){
        echo "ERROR opening cache file";
    }
}

return $t_out;

}

function ddsq_process($content) {

$results = array();

preg_match_all("/\[\s?stock\s?(.*)\s?\]/", $content, $results);

$i = 0;
foreach ($results[0] as $r) {

    $content = str_replace($r, ddsq_get_quote($results[1][$i]), $content);
    $i++;
}

return $content;

}

add_filter(‘the_content’, ‘ddsq_process’);
add_action(‘admin_menu’, ‘ddsq_add_option_pages’);

?>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:49:02+00:00Added an answer on May 23, 2026 at 7:49 am

    As far as I can see there is no loop or control structure (like switch), that accepts break; within itself. I guess, that you sometimes call this code within a loop. In this case break; is allowed. But sometimes it’s not. At all break; doesn’t make any sense within an if-block.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a wordpress website (buddypress plugin/themes). I'm using a plugin that requires access
I am using a plugin for wordpress called CMS its a plugin that makes
I'm grabbing a row from the the db in a wordpress plugin using: $ongoing_event
I am using a wordpress plugin that requires the following code in my template:
I have a custom developed WordPress plugin that is using jQuery 1.4 and for
I'm using WordPress plugin Category Page to display the most recent 5 posts from
I made a quiz app using wordpress using a quiz plugin so that, the
I would like to create wordpress plugin that will display quote of the day.
Using Wordpress, i have a plugin that inserts a playable MP3 on the page.
I'm using the anytime.js datepicker library of a WordPress plugin that was custom-developed for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.