WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Droplets & Snippets => Topic started by: snark on April 19, 2010, 10:25:33 AM

Title: Share page on social networks - droplets
Post by: snark on April 19, 2010, 10:25:33 AM
I want to incorperate some links to social networks into a website...

something like 
http://www.telegraaf.nl/buitenland/6552847/__Kasteel_Dracula_trouwlocatie__.html?p=16,1 (http://www.telegraaf.nl/buitenland/6552847/__Kasteel_Dracula_trouwlocatie__.html?p=16,1)
(somewhere in the middle there are links to hyves / facebook / delicious etc)

I took the script and put it in and it kinda works but only for the complete website

ofcourse it would be much better if it would make a link to the visited page


therefor I need to display the bowserlink in a page

if the page is http://www.website.com/pages/this-and-that.php

I need to display pages%2Fthis-and-that.php



I tried to alter some droplets but I cannot figure it out...



If some-one can help out here I suppose we can easily make a droplet for each social-network-link




Title: Re: place article on social networks
Post by: crnogorac081 on April 20, 2010, 02:23:26 PM
Hi,

Try section picker, or section picker droplet. That may help.

cheers
Title: Re: place article on social networks
Post by: snark on April 20, 2010, 06:06:59 PM
thank you but you do not have the slightest idea what I am asking 

I will make a better explanation tommorrow
Title: Re: place article on social networks
Post by: crnogorac081 on April 20, 2010, 06:08:52 PM
Or do you mean to have buttons like: post to facebook, post to tweeter, post to digg it, post to delicious.. etc.. ?

Title: Re: place article on social networks
Post by: snark on April 20, 2010, 06:14:27 PM
yes

like: http://www.telegraaf.nl/binnenland/6565317/__Heide_in_brand_bij_Bergen_op_Zoom__.html?sn=binnenland,buitenland

I got the script no problem.. just ripped it from a website... and it works, no worries about that

but it just makes a link to the www.website.com and not to the current page


since all links are somewhat different ( facebook, twitter, linkedin etc) I think it would be best to make a set of droplets from these individual scripts

but as said therefor the current pagelink needs to be put into the script and I just do not know how...

I will post the code to one soc network tomorrow so we can take a look at it


thanks so far

Title: Re: place article on social networks
Post by: snark on April 23, 2010, 08:25:24 PM
this is a sample of what I need to put in as code...

Code: [Select]
<a target="_blank" title="Plaats dit artikel op: Facebook" href="http://www.facebook.com/sharer.php?u=http://website.com/pages/home.php%2F&amp;t=title-of-message"><img alt="Facebook Favicon" width="16" height="16" border="0" src="http://www.website.com/media/icons/facebook.png" /></a>

can anyone tell me how to put in the url of the current page dynamically

Code: [Select]
http://website.com/pages/home.php
that way the soc media icon will produce a link to the page it is clicked from




Title: Re: place article on social networks
Post by: kweitzel on April 23, 2010, 08:36:06 PM
In the DB Tabel pages is a field called link. Make an SQL with the current PAGE_ID, put the result in a variable (e.g. $link) and then build the link with WB_URL and $link ...

cheers

Klaus
Title: Re: place article on social networks
Post by: snark on April 23, 2010, 09:30:47 PM
okay
Code: [Select]
global $database, $admin;
$sql = "SELECT link FROM ".TABLE_PREFIX."pages WHERE `page_id` = '$page_id'";
$results = $database->query($sql);
if ($results && $results->numRows() > 0) {
    $row = $results->fetchRow();
$page = page_link($row['link']);
}

echo $page;

when I turn this into a droplet

Code: [Select]
global $database, $admin;
$sql = "SELECT link FROM ".TABLE_PREFIX."pages WHERE `page_id` = '$page_id'";
$results = $database->query($sql);
if ($results && $results->numRows() > 0) {
    $row = $results->fetchRow();
$page = page_link($row['link']);
}

return $page;

it doesn't work ... any suggestions/ corrections are welcome

Title: Re: Share page on social networks - droplets
Post by: snark on April 26, 2010, 03:08:20 PM
find attached droplets to share your page with social networks

it lets visitors share a link to the page on their favorite social network, leaving the name of the page, the page description + the optional tekst that the visitor can add to the share

for now I did the droplets for:


[gelöscht durch Administrator]
Title: Re: Share page on social networks - droplets
Post by: robin on May 13, 2010, 02:52:45 PM
nice work! excellent idea!
 :-D
Cheers, Robin.
Title: Re: Share page on social networks - droplets
Post by: sky writer on March 16, 2011, 04:32:26 PM
I have used this droplet to Share pages on Facebook for some time, and I like it, except that I can't figure something out.

I have a "Portfolio" page which consists of one NEWS section.  If I click the Share link on a news "post" page, the LINK, "Page_Title" and "PAGE_DESCRIPTION" from the Portfolio page is used, not the News Post Page.  I would like to share the actual page that is being viewed.  Is there a way to change the code to allow for this functionality?

Code: [Select]
//:
//:
global $database, $admin;
$sql = "SELECT link FROM ".TABLE_PREFIX."pages where page_id=".PAGE_ID;
$results = $database->query($sql);
if ($results && $results->numRows() > 0) {
    $row = $results->fetchRow();
$page = page_link($row['link']);
}


return '<h1>&nbsp<a target="_blank" title="facebook: Share This Page With Your Friends" href="http://www.facebook.com/sharer.php?u='.$page.'%2F&amp;t=' .PAGE_TITLE.' - '.PAGE_DESCRIPTION.'"><img alt="Facebook Favicon" width="16" height="16" border="0" src="'.WB_URL.MEDIA_DIRECTORY.'/social/facebook.png" />facebook: Share Page</a></h1>';

Title: Re: Share page on social networks - droplets
Post by: Stefek on March 16, 2011, 04:42:49 PM
Hello,

do you want to have the [SHARE BUTTON] only in the news posts (Long Post)?
Or is this droplet and button used only on another places?

And if only on the News Posts, which data exactly you want to submitt with the button?

Lets assume this is the code you have now:
Code: [Select]
<h1>
<a target="_blank" title="facebook: Share This Page With Your Friends" href="http://www.facebook.com/sharer.php?u='.$page.'%2F&amp;t=' .PAGE_TITLE.' - '.PAGE_DESCRIPTION.'">
<img alt="Facebook Favicon" width="16" height="16" border="0" src="'.WB_URL.MEDIA_DIRECTORY.'/social/facebook.png" />
facebook: Share Page</a>
</h1>

We have some output to be replaced:
$page = this should be the actual URL to the Post, right?
PAGE_TITLE = the actual title of the Post, right?
PAGE_DESCRIPTION = would you like to have the "short description" of the news post or a "substring" of the "full description"?

(note that there is no actual PAGE_DESCRIPTION set for the news items itself)

Regards,
Stefek
Title: Droplet: FaceBook share, for use with NEWS Module and regular pages
Post by: Stefek on March 16, 2011, 06:22:23 PM
Hello Sky Writer,

I created the following one on the fly.

Code: [Select]
<?php
//$icon_url = WB_URL.MEDIA_DIRECTORY.'/facebook.png';
$icon_url "http://profile.ak.fbcdn.net/hprofile-ak-snc4/174597_20531316728_2866555_q.jpg";

$template = <<<_TEMPLATE_END

<span class="facebook-share">
<a target="_blank" title="facebook: Share This Page With Your Friends" href="http://www.facebook.com/sharer.php?u=[LINK]%2F&amp;t=[TITLE] - [TEASER]">
<img alt="Facebook Share" width="16" height="16" border="0" src="
$icon_url" />
facebook: Share Page</a>
</span>

_TEMPLATE_END;


// query for standard pages
$sql "SELECT `link` AS 'link', `page_title` AS 'title', `description` AS 'teaser' FROM `".TABLE_PREFIX."pages` WHERE `page_id` = ".PAGE_ID;

// query for news posts
if(defined('POST_ID')){
$sql "SELECT `link` AS 'link', `title` AS 'title', `content_short` AS 'teaser' FROM `".TABLE_PREFIX."mod_news_posts` WHERE `post_id`=".POST_ID;
}

global 
$database;
$results $database->query($sql);
if (
$results->numRows() > 0) {
    
$row $results->fetchRow();

$placeholder = array(
'[LINK]'  => WB_URL.PAGES_DIRECTORY.$row['link'].PAGE_EXTENSION,
'[TITLE]' => $row['title'],
'[TEASER]'  => $row['teaser'],
);

$ret_val str_replace(array_keys($placeholder), array_values($placeholder), $template);

return (isset(
$ret_val)) ? $ret_val : (TRUE);
This one can be used both: on NEWS Posts and on regular pages.

Note: for regular Pages you will need to fill the Page Description in Page Settings, otherwise you'll get an empty string.
For News Pages the `content_short` field is fetched from DB.

What to do:
replace the $icon_url string in the droplet.
Adjust the "template" between ....

Code: [Select]
$template =<<<_TEMPLATE_END

..... your template

_TEMPLATE_END;
... to your needs.

Should work fine.

Regards,
Stefek
Title: Re: Share page on social networks - droplets
Post by: sky writer on March 16, 2011, 09:08:35 PM
Stefek,
This solution worked absolutely perfectly.  Thank you so much for your time and kindness.
Cheers!
Title: Re: Share page on social networks - droplets
Post by: Stefek on March 16, 2011, 10:01:04 PM
Hello James,

thanks for letting me know, as I myself got no facebook account I couldn't test it.
I'm glad it works.

Regards,
Stefek
Title: Re: Share page on social networks - droplets
Post by: firefoxfx on April 11, 2011, 01:43:13 PM
Hey Stefek,

Thanks for the facebook droplet, it works very good.
Is it also possible to make the same for twitter?

I tried to adjust the code but it doesn't add the news item title to the tweet, only the site name and the page title.

Thanks in advance.

Firefoxfx
Title: Re: Share page on social networks - droplets
Post by: Stefek on April 11, 2011, 02:09:35 PM
Hello,

maybe someone else may help you better, as I do not have any twitter/facebook etc. account.
I don't know the mechanics of those services.
But it should be possible with some small adjustments of the Droplet.

Regards,
Stefek
Title: Re: Share page on social networks - droplets
Post by: dbs on July 02, 2011, 09:39:31 AM
Nice Droplet Stefek,

but in wb2.8.2 or 2.8.1 it seems the content_short will not displayed.

works well, thx.


dbs
Title: Re: Share page on social networks - droplets
Post by: golem on September 22, 2011, 05:44:14 PM
Hi,

unfortuantly it doensn't work on my news-site. I am using WB 2.8.2 Rev. 1506. Is there s.th. to change on this:

Code: [Select]
// query for news posts
if(defined('POST_ID')){
$sql = "SELECT `link` AS 'link', `title` AS 'title', `content_short` AS 'teaser' FROM `".TABLE_PREFIX."mod_news_posts` WHERE `post_id`=".POST_ID;
}

I get the share button, but only my news.php site is visible as link. I tried to use this within my short and my long descrition. Both links go back to my news overview. Even the title is the one of the news site.

Any idea?

Thanks.
Title: Re: Share page on social networks - droplets
Post by: crnogorac081 on September 22, 2011, 06:54:25 PM
Hi,

try to replace `post_id`=".POST_ID; with `post_id`='$post_id'";

cheers
Title: Re: Share page on social networks - droplets
Post by: golem on September 22, 2011, 08:10:44 PM
No, didn't work.

Even when I delete this:

// query for standard pages
$sql   = "SELECT `link` AS 'link', `page_title` AS 'title', `description` AS 'teaser' FROM `".TABLE_PREFIX."pages` WHERE `page_id` = ".PAGE_ID;

// query for news posts
if(defined('post_id')){

   $sql = "SELECT `link` AS 'link', `title` AS 'title', `content_short` AS 'teaser' FROM `".TABLE_PREFIX."mod_news_posts` WHERE `post_id`=".POST_ID;
}

the result is: http://...../pages.php/ with an 404 error

When I change this to `post_id`='$post_id'"; the facebook botton does not appear. ???
Title: Re: Share page on social networks - droplets
Post by: crnogorac081 on September 23, 2011, 07:02:47 PM
wierd,

if you want you can send me a temp admin password on pm to take a look..

cheers
Title: Re: Share page on social networks - droplets
Post by: Bug on October 22, 2011, 05:58:05 PM
Why not just use the free stuff addthis.com offers?
Title: Re: Share page on social networks - droplets
Post by: DarkViper on October 24, 2011, 03:07:46 AM
No, didn't work.
When I change this to `post_id`='$post_id'"; the facebook botton does not appear. ???

$post_id  is a variable from global scope, so inside a droplet you must import( global $post_id; ) it or use $GLOBALS['post_id'].
The constant 'POST_ID' is never available from WB2.8.2. (see post-access files)
Title: Re: Share page on social networks - droplets
Post by: macsmet on September 29, 2013, 02:19:06 PM
Hi there,

i just discovered this topic.
I can't get this to work.
When I make a new droplet (copy/pasting code) from Stefek's code it says the code is invalid.

Anyone else having this?
I know this is an old topic but I am looking for an easy way to use Twitter and Facebook with news.

Thanks!

Greetings,

MacSmet

Title: Re: Share page on social networks - droplets
Post by: dbs on September 29, 2013, 02:57:23 PM
Hi, you mean stefeks colored code?
This forum has changed the codes a little bit.
This:
$sql   = "SELECT `link` AS &#39;link&#39;,
Should looks like this:
$sql   = "SELECT `link` AS 'link',
and so on.
Title: Re: Share page on social networks - droplets
Post by: macsmet on September 29, 2013, 06:57:15 PM
Hi dbs,

Thanks for your reply.
It works now. But it only gives me the website title and page URL.
It doesn't copy the news message into the facebook sharer.
Bummer!

greetings,

MacSmet
Title: Re: Share page on social networks - droplets
Post by: Tez Oner on September 29, 2013, 08:07:23 PM
Hey MacSmet,

Quote
It doesn't copy the news message into the facebook sharer.

Thats been depreciated by FB anyway because of the possibility to spam.

Cheerz,

Tez Oner
Title: Re: Share page on social networks - droplets
Post by: macsmet on September 29, 2013, 08:14:46 PM
Hi Tez,

Thanks, I didn't know that.

greetings,

MacSmet