function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title']); if (is_single()) { echo $before_widget; echo $before_title . $title . $after_title; $sml_fin_graph = esc_url(get_post_meta(get_the_ID(), 'sml_fin_graph', true)); $result_json = sml_fin_get_data(array('dataset_search' => QUANDL_DEFAULT_SEARCH, 'ticker' => $instance['ticker'], 'api_key' => QUANDL_API_KEY, 'start_date' => $instance['start_date'], 'end_date' => $instance['end_date'])); $parsed_data = sml_fin_parse_api($result_json); $graph_file = sml_fin_gen_graph(array('ticker_high' => $parsed_data['ticker_high'], 'ticker_low' => $parsed_data['ticker_low'], 'ticker_dates' => $parsed_data['ticker_dates'], 'ticker_values' => $parsed_data['ticker_values'], 'ticker_name' => $parsed_data['ticker_name'], 'graph_name' => 'widget')); // print widget echo '<img src="' . get_site_url() . '/' . $graph_file . '" alt="Financial Graph" height="250" width="350">'; echo $after_widget; } }
function sml_fin_save_metabox($post_id) { if (isset($_POST['sml_fin_radio'])) { update_post_meta($post_id, 'sml_fin_radio', esc_attr($_POST['sml_fin_radio'])); } if (isset($_POST['sml_fin_quote'])) { update_post_meta($post_id, 'sml_fin_quote', esc_attr($_POST['sml_fin_quote'])); } if (isset($_POST['sml_day_radio'])) { update_post_meta($post_id, 'sml_day_radio', esc_attr($_POST['sml_day_radio'])); } if (isset($_POST['sml_fin_week'])) { update_post_meta($post_id, 'sml_fin_week', esc_attr($_POST['sml_fin_week'])); } if (isset($_POST['sml_fin_day'])) { update_post_meta($post_id, 'sml_fin_day', esc_attr($_POST['sml_fin_day'])); } if (isset($_POST['sml_fin_radio'])) { if ($_POST['sml_fin_radio'] == 'yes') { $result_json = sml_fin_get_data(array('dataset_search' => QUANDL_DEFAULT_SEARCH, 'ticker' => $_POST['sml_fin_quote'], 'api_key' => QUANDL_API_KEY, 'start_date' => '2015-07-25', 'end_date' => '2015-07-30')); $parsed_data = sml_fin_parse_api($result_json); $graph_file = sml_fin_gen_graph(array('ticker_high' => $parsed_data['ticker_high'], 'ticker_low' => $parsed_data['ticker_low'], 'ticker_dates' => $parsed_data['ticker_dates'], 'ticker_values' => $parsed_data['ticker_values'], 'graph_name' => 'metabox')); // var_dump ($graph_file); echo '<img src="' . get_site_url() . '/' . $graph_file . '" alt="Financial Graph" height="250" width="350">'; // die; } } }