WordPress.org

Ready to get started?Download WordPress

Forums

WP-TopBar
[resolved] php and topbar (6 posts)

  1. iformas
    Member
    Posted 1 year ago #

    hi i want to put a php scipt for get a json value with curl, how i can integrate my php script with top bar?

    http://wordpress.org/extend/plugins/wp-topbar/

  2. Bob
    Member
    Plugin Author

    Posted 1 year ago #

    In wp-topbar.php, you can modify the function wptb_inject_specific_TopBar_html_js to add your custom code. You'll need to maintain this as I update the plugin.

  3. iformas
    Member
    Posted 1 year ago #

    im too noob for do it D:
    can you explain it step by step?

    in wp-topbar.php y found this

    wptb::wptb_inject_specific_TopBar_html_js($wptbOptions);

    } // end function wptb_inject_TopBar_html_js

    //=========================================================================
    // Inject specific TopBar HTML-- used also on the admin (debug) pages
    //=========================================================================

    function wptb_inject_specific_TopBar_html_js($wptbOptions) {

    if ( $wptbOptions['enable_topbar'] == 'false' ) { return; }

    global $wp_query;
    $thePostID = $wp_query->post->ID;

    if ( is_home() && ( $wptbOptions['show_homepage'] == "never" ) ) { return; }

    if ( ! ( is_home() && ( $wptbOptions['show_homepage'] == "always" ) ) ) {
    if ( $wptbOptions['include_pages'] == 0 )
    $page_id_found = true;
    else {
    $page_id_found = false;
    if ( $wptbOptions['include_logic'] != 'cat_only' ) { //skip this logic if we are only checking categories
    if ( in_array( $thePostID, explode( ',', $wptbOptions['include_pages'] ) ) )
    $page_id_found = true;
    if ( $wptbOptions['invert_include'] == 'yes' )
    $page_id_found = ! $page_id_found;
    }
    }

    if ( $wptbOptions['include_categories'] == 0 )
    $category_id_found = true;
    else {
    $category_id_found = false;
    if ( $wptbOptions['include_logic'] != 'page_only' ) { //skip this logic if we are only checking pages
    foreach((get_the_category($thePostID)) as $category) {
    if ( in_array( $category->cat_ID, explode( ',', $wptbOptions['include_categories'] ) ) ) {
    $category_id_found = true;
    break;
    }
    }
    if ( $wptbOptions['invert_categories'] == 'yes' )
    $category_id_found = ! $category_id_found;
    }
    }
    // check the logic the user selected if not on debug page

    if ( ! ( isset( $_GET['page'] ) && $_GET['page'] == 'wp-topbar.php') )
    switch ( $wptbOptions['include_logic'] ) {

    case 'page_only':

    if ( ! $page_id_found ) {return;}
    break;

    case 'cat_only':

    if ( ! $category_id_found ) {return;}
    break;

    case 'boolean_and':

    if ( ( ! $page_id_found ) || ( ! $category_id_found ) ) {return;}
    break;

    case 'boolean_or':

    if ( ( ! $page_id_found ) && ( ! $category_id_found ) ) {return;}

    }
    }

    $wptb_cookie = "wptopbar_".COOKIEHASH;

    if ( ( $wptbOptions['allow_close'] == 'yes' ) AND
    ( $wptbOptions['respect_cookie'] == 'always' ) AND
    ( $_COOKIE[$wptb_cookie] == $wptbOptions['cookie_value']) ) {
    echo '<!-- WP-TopBar Valid Cookie Present - not showing TopBar -->
    ';
    return;
    }

    // use javascript to force the HTML to just before body tag if the topbar is at the top of the page
    if ( $wptbOptions['topbar_pos'] == 'header' ) {
    echo '
    ';
    echo "<script type='text/javascript'>";
    echo '
    ';
    echo "jQuery(document).ready(function() {";
    echo "jQuery('body').prepend('";
    }

    echo '<div id="topbar" style="',$wptbOptions['div_css'],'">';

    self::wptb_display_TopBar('visibility:hidden;',$wptbOptions, true);

    echo '</div>';

    if ( $wptbOptions['topbar_pos'] == 'header' )
    echo "');} );
    ";

    if ( $wptbOptions['topbar_pos'] == 'footer' ) {
    echo '
    ';
    echo "<script type='text/javascript'>";

    }

    if ($wptbOptions['respect_cookie'] == 'ignore') { // destroy cookie
    echo '
    ';
    echo 'document.cookie="'.$wptb_cookie.'"'."+'=;expires=Thu, 01-Jan-70 00:00:01 GMT;';";
    }
    if ($wptbOptions['allow_close'] == 'yes') {
    echo '
    ';
    echo 'function close_wptobar() { document.getElementById("wptbheadline").style.visibility = "hidden";';
    if ($wptbOptions['respect_cookie'] == 'always') {

    echo 'var now= new Date();';
    echo 'var expDate = new Date();';
    echo 'expDate.setTime(now.getTime() + 3600000*24*30);';
    echo 'document.cookie="'.$wptb_cookie.'"+"="+escape('.$wptbOptions['cookie_value'].')+";expires="+expDate.toUTCString();';
    }
    echo ' };';
    }

    echo '
    ';
    echo 'jQuery(document).ready(function() {',"jQuery('#wptbheadline').hide().delay(",$wptbOptions['delay_time'],").css('visibility','visible').slideDown(",$wptbOptions['slide_time'],").fadeIn(1000).show('slow');";

    if (($wptbOptions['display_time']+0) != 0) {
    echo "jQuery('#wptbheadline').delay(",$wptbOptions['display_time'],').slideUp(',$wptbOptions['slide_time'],').fadeOut(1000).hide();';
    }
    echo '});
    ';
    echo '</script>';

    } // end function wptb_inject_TopBar_html_js

  4. Bob
    Member
    Plugin Author

    Posted 1 year ago #

    Sorry, I cannot help you as I don't what you are really trying to do.

  5. iformas
    Member
    Posted 1 year ago #

    i want to display a mtgox value ex:

    <?php
    
    //Get MTGOX VALUES
    	$ch = curl_init();
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    	curl_setopt($ch, CURLOPT_USERAGENT, "curl/7.21.3 (x86_64-pc-linux-gnu) libcurl/7.21.3 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18");
    	curl_setopt($ch, CURLOPT_URL, 'https://mtgox.com/code/data/ticker.php');
    	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    	$mtgoxjson = curl_exec($ch);
    	curl_close($ch);
    
    		// Decode from an object to array
    		$output_mtgox = json_decode($mtgoxjson);
    		$output_mtgox_1 = get_object_vars($output_mtgox);
    		$mtgox_array = get_object_vars($output_mtgox_1['ticker']);
    
    		// MTGOX USD
    		$mtgox_last_USD = $mtgox_array['last'];
    		$mtgox_high_USD = $mtgox_array['high'];
    		$mtgox_low_USD = $mtgox_array['low'];
    		$mtgox_avg_USD = $mtgox_array['avg'];
    		$mtgox_vol_USD = $mtgox_array['vol'];
    
    // GCalc	
    
    	function conversor_monedas($moneda_origen,$moneda_destino,$cantidad) {
        $cantidad = urlencode($cantidad);
        $moneda_origen = urlencode($moneda_origen);
        $moneda_destino = urlencode($moneda_destino);
        $url = "http://www.google.com/ig/calculator?hl=en&q=$cantidad$moneda_origen=?$moneda_destino";
        $ch = curl_init();
        $timeout = 0;
        curl_setopt ($ch, CURLOPT_URL, $url);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch,  CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $rawdata = curl_exec($ch);
        curl_close($ch);
        $data = explode('"', $rawdata);
        $data = explode(' ', $data['3']);
        $var = $data['0'];
        return round($var,10);
    	}	
    
     //GCalc 1 USD-CLP
     $currencyCLP = conversor_monedas("USD","CLP",1);
    
     //MTGOX CLP
    $mtgox_last_CLP = ($currencyCLP) * ($mtgox_last_USD);
    $mtgox_high_CLP = ($currencyCLP) * ($mtgox_high_USD);
    $mtgox_low_CLP = ($currencyCLP) * ($mtgox_low_USD);
    $mtgox_avg_CLP = ($currencyCLP) * ($mtgox_avg_USD);
    $mtgox_vol_CLP = ($currencyCLP) * ($mtgox_vol_USD);
    echo round($mtgox_last_CLP,0);
      ?>

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum's parser.]

  6. Bob
    Member
    Plugin Author

    Posted 1 year ago #

    Here is what I would do:

    Create a function from the PHP you have above in wp-topbar.php. Call it mtgox

    In wp-topbar.php, in function wptb_display_TopBar, look for:

    echo '">',$wptbOptions['bar_text'],'<a style="color:',$wptbOptions['link_color'],'; ';

    Change it to:

    echo '">',$wptbOptions['bar_text'],mtgox(),'<a style="color:',$wptbOptions['link_color'],'; ';

    Your Text would be something like: "The last MT.Gox price is "

    You will need to maintain these changes as I fix/update the topbar.

    Of course, your mileage may vary.

    Bob

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags