Community @ The Turning Gate

Support community for TTG plugins and products.

NOTICE

The Turning Gate's Community has moved to a new home, at https://discourse.theturninggate.net.

This forum is now closed, and exists here as a read-only archive.

  • New user registrations are disabled.
  • Users cannot create new topics.
  • Users cannot reply to existing topics.

You are not logged in.

#1 2017-07-07 06:45:56

charlie.choc
Member
From: Marietta, GA
Registered: 2014-01-09
Posts: 359
Website

Get image URL (jpg) - Add Social Sharing to Single Image Pages

In ttg_single_bottom I can figure out how the get the URL of the image php file but is there and easy way to get the URL of the actual image itself?

Thanks.

Offline

#2 2017-07-07 08:11:58

Daniel Leu
Moderator
Registered: 2012-10-11
Posts: 1,624
Website

Re: Get image URL (jpg) - Add Social Sharing to Single Image Pages

Unfortunately, the image name or any additional image data are not exposed by the phplugins API. But at least from the page URL, it is easy to derive the image filename and then create the image path.


Daniel Leu | Photography   
DanielLeu.com
My digital playground (eg, Backlight tips&tricks): lab.DanielLeu.com

Offline

#3 2017-07-07 08:22:47

charlie.choc
Member
From: Marietta, GA
Registered: 2014-01-09
Posts: 359
Website

Re: Get image URL (jpg) - Add Social Sharing to Single Image Pages

Thanks. I was hoping I could be lazy and not have to parse everything. ?

Offline

#4 2017-07-07 08:45:18

Daniel Leu
Moderator
Registered: 2012-10-11
Posts: 1,624
Website

Re: Get image URL (jpg) - Add Social Sharing to Single Image Pages

Little coffee break exercise. Might not be the most efficient, but it works:

function ttg_single_bottom( $style, $path) {
   
   $img = substr(strrchr(substr($_SERVER["REQUEST_URI"], 0, strrpos($_SERVER["REQUEST_URI"],"-single.php")), '/'), 1);
   $imgpath = substr($_SERVER["REQUEST_URI"], 0, strrpos($_SERVER["REQUEST_URI"],$img)) . 'photos/' . $img . '.jpg'; 
      
   echo '<a href="'.$imgpath.'">'.$imgpath.'</a>';
}

You are not working on 'share to social media' buttons by chance?


Daniel Leu | Photography   
DanielLeu.com
My digital playground (eg, Backlight tips&tricks): lab.DanielLeu.com

Offline

#5 2017-07-07 08:52:15

charlie.choc
Member
From: Marietta, GA
Registered: 2014-01-09
Posts: 359
Website

Re: Get image URL (jpg) - Add Social Sharing to Single Image Pages

Thanks for the code and, yes I am. I can share the php link to fb and g+ but some need a link to the jpg itself.

Offline

#6 2017-08-12 08:31:17

Daniel Leu
Moderator
Registered: 2012-10-11
Posts: 1,624
Website

Re: Get image URL (jpg) - Add Social Sharing to Single Image Pages

Hey Charlie, would you mind to share your code that you came up with? Thank you!


Daniel Leu | Photography   
DanielLeu.com
My digital playground (eg, Backlight tips&tricks): lab.DanielLeu.com

Offline

#7 2017-08-12 10:06:08

charlie.choc
Member
From: Marietta, GA
Registered: 2014-01-09
Posts: 359
Website

Re: Get image URL (jpg) - Add Social Sharing to Single Image Pages

This is probably a little clunky but it seems to work ok.

function ttg_single_bottom ( $style, $path ) {

    $actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    $img = substr(strrchr(substr($_SERVER["REQUEST_URI"], 0, strrpos($_SERVER["REQUEST_URI"],"-single.php")), '/'), 1);
    $imgpath = substr($_SERVER["REQUEST_URI"], 0, strrpos($_SERVER["REQUEST_URI"],$img)) . 'photos/' . $img . '.jpg';
    $imgfullpath = "https://$_SERVER[HTTP_HOST]$imgpath";

    echo '
        <div id=social-align>
            <a class="icon" target="_blank" href="http://www.facebook.com/sharer/sharer.php?u='.$actual_link.'" title="Share on Facebook">
                <i class="fa fa-facebook-official"  style="color:#3b5998; font-size: 150%;"></i></a>
            <a class="icon" target="_blank" href="http://www.twitter.com/intent/tweet?url='.$actual_link.'" title="Tweet">
                <i class="fa fa-twitter"  style="color:#1da1f2; font-size: 150%;"></i></a>                                 
            <a class="icon" target="_blank" href="https://plus.google.com/share?url='.$actual_link.'" title="Share on Google Plus">
                <i class="fa fa-google-plus-official"  style="color:#dd4b39; font-size: 150%;"></i></a>
            <a class="icon" target="_blank" href="http://pinterest.com/pin/create/button/?url='.$actual_link.'&amp;media='.$imgfullpath.'" title="Share on Pinterest">
                <i class="fa fa-pinterest-p"  style="color:#cb2027; font-size: 150%;" id="social_media_04"></i></a>
            <a class="icon" target="_blank" href="http://stumbleupon.com/submit?url='.$imgfullpath.'" title="Share on Stumbleupon">
                <i class="fa fa-stumbleupon"  style="color:#EB4823; font-size: 150%;" id="social_media_04"></i></a>
            <a class="icon" target="_blank" href="mailto:?subject=An image you might like&body='.$actual_link.'" title="Share via email">
                <i class="fa fa-envelope-o"  style="font-size: 150%;"></i></a>
        </div>
       
       
';
}

Offline

#8 2017-08-12 14:43:13

Daniel Leu
Moderator
Registered: 2012-10-11
Posts: 1,624
Website

Re: Get image URL (jpg) - Add Social Sharing to Single Image Pages

Thank you, Charlie!


Daniel Leu | Photography   
DanielLeu.com
My digital playground (eg, Backlight tips&tricks): lab.DanielLeu.com

Offline

#9 2017-08-13 05:31:42

Daniel Leu
Moderator
Registered: 2012-10-11
Posts: 1,624
Website

Re: Get image URL (jpg) - Add Social Sharing to Single Image Pages

Charlie, there was a missing '/' in the stumbleupon.com link. I fixed it in the code you posted.


Daniel Leu | Photography   
DanielLeu.com
My digital playground (eg, Backlight tips&tricks): lab.DanielLeu.com

Offline

#10 2017-08-13 06:00:51

charlie.choc
Member
From: Marietta, GA
Registered: 2014-01-09
Posts: 359
Website

Re: Get image URL (jpg) - Add Social Sharing to Single Image Pages

Thanks Daniel, I should have caught that.

Offline

#11 2017-08-13 06:27:07

Daniel Leu
Moderator
Registered: 2012-10-11
Posts: 1,624
Website

Re: Get image URL (jpg) - Add Social Sharing to Single Image Pages

charlie.choc wrote:

Thanks Daniel, I should have caught that.

Somehow it works on your site, but didn't on mine.


Daniel Leu | Photography   
DanielLeu.com
My digital playground (eg, Backlight tips&tricks): lab.DanielLeu.com

Offline

#12 2017-08-14 06:58:44

charlie.choc
Member
From: Marietta, GA
Registered: 2014-01-09
Posts: 359
Website

Re: Get image URL (jpg) - Add Social Sharing to Single Image Pages

FWIW, this is the css styling I used:

#social-align
{
    text-align: right;
    float: none;
    padding-right: 24px;
    }
   
#social-align.icon {
    display: inline-block;
    }

Offline

Board footer

Powered by FluxBB