• Resolved zzzbrett

    (@zzzbrett)


    A continuation from this post, a new bug was found with regards to the view external link button on the facebook app, when the permalink contains the app’s name.

    Code in question:

    <?php
    // code to get the url of the orginal post for use in the "show external url view"
    //get the permalink
    $permalink_peices = parse_url(get_permalink());
    //get the app_url and the preceeding slash
    $permalink_app_url = "/".$app_url;
    //remove /appname
    $external_post_permalink = str_replace($permalink_app_url,"","$permalink_peices[path]");
    //re-write the post url using the site url
    $external_site_url_peices = parse_url(get_bloginfo('wpurl'));
    
    //break apart the external site address and get just the "site.com" part
    $external_site_url = $external_site_url_peices[host];
    $exteral_post_url = get_bloginfo('wpurl').$external_post_permalink;
    
    //echo external post url
    echo "<a href='$exteral_post_url' title='View this post on the web at $external_site_url'>View post on $external_site_url</a>";  ?>

    http://wordpress.org/extend/plugins/wpbook/

Viewing 3 replies - 1 through 3 (of 3 total)
  • B.

    (@bandonrandon)

    Brett,

    I think I found a solution to the issue. Add the following function either in you theme/index.php or (recommended) to the theme/config.php

    // check to see if external post link contains the app name and only replace the first instance use this function
    function str_replace_once($needle, $replace, $haystack) {
       // Looks for the first occurence of $needle in $haystack
       // and replaces it with $replace.
       $pos = strpos($haystack, $needle);
       if ($pos === false) {
           // Nothing found
           return $haystack;
       }
       return substr_replace($haystack, $replace, $pos, strlen($needle));
    }

    this function will only replace the first occurence of the variable.

    Next replace:

    $external_post_permalink = str_replace($permalink_app_url,"","$permalink_peices[path]");

    With:
    $external_post_permalink = str_replace_once($permalink_app_url,"",$permalink_peices[path]);

    On both lines 134 and 182

    This will hopefully make it into the next release but should fix your problem if you feel comfortable modifying the code a bit.

    Brandon

    John Eckman

    (@johneckman)

    Thanks Brandon – this will be in 1.3.1 which I’m working on now.

    zzzBrett can you mark this resolved?

    Thread Starter zzzbrett

    (@zzzbrett)

    1.3.1 Works great johneckman!

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘[Plugin: WPBook] View External Link Bug’ is closed to new replies.