Adding social bookmarks to sNews CMS
filed under: sNews CMS / Hacks & Mods
updated january 30th, 2009, please read this entry for update instructions and the updated zip file.
Here's a quick hack for your sNews CMS, no doubt you've seen all the various social bookmarking icons below so many blog posts, tutorials, & articles these days, with this simple hack you can do the same to your sNews CMS articles.
This method isn't extremely complicated, and it doesn't have an admin interface, but if you're using sNews for your CMS, you probably don't mind getting your hands a little dirty. We will put most of the logic into a separate file to minimize any hacking (and potential screwing up) of the snews.php file...
So let's get started, the first thing we want to do is create the new php file to store all your social bookmark logic. I named mine social.php. OK, now we want to create our variables, with most all social bookmarks, you have two key variables, the article title, and the article url. There are others (such as description and tags, I use them with ma.gnolia), but those require modifying the mysql queries, I don't want to get into that with this tutorial. So, we will set up these two variables like so:
<?php //social.php - contains the logic for the social bookmarking mod for sNews CMS //grabs the url to the article $social_url = urlencode(_SITE.$uri."/".$r['asef']); //grabs the title of the article $social_title = urlencode($title);
Now let's set some styles:
//put your div container style here $container_style = "clear: both; padding: 2px; text-align: left;"; //put your image styles here $img_style = "vertical-align: middle; padding: 0; margin: 2px;";
Lastly we need to insert the links, I have added 3 of the most popular here. If you want to add more, simply add another link and change the image & bookmarking url. Make sure you change the image path if you don't use "/images/social/" folder. Here are the images used in this tutorial:
Save these images into the folder /images/social
// add your links here echo <<<HTML <div style="$container_style"> <a rel="nofollow" title="stumbleupon" href="http://www.stumbleupon.com/submit?url=$social_url&title=$social_title"><img src="/images/social/stumbleupon.png" alt="stumbleupon" style="$img_style" /></a> <a rel="nofollow" title="reddit" href="http://reddit.com/submit?url=$social_url&title=$social_title"><img src="/images/social/reddit.png" alt="reddit" style="$img_style" /></a> <a rel="nofollow" title="digg" href="http://digg.com/submit?phase=2&url=$social_url∓title=$social_title"><img src="/images/social/digg.png" alt="digg" style="$img_style" /></a> </div> HTML; ?>
That's it for that file, so save that as social.php and upload it to your server public html root. Now backup snews.php and open it up and find the function articles(). I used the "infoline" setting to decide whether or not I wanted to show the social bookmarks, so you may want to change that, but I found this works well, as I only use the "infoline" on my articles. So you'll want to find the two instances of the following line;
if ($infoline == true) {
and add the following code below it;
include('social.php');
Now upload snews.php and you should see your bookmark links under each article that use the infoline. This zip file contains the example social.php, the images, and the INSTALL.txt for your snews.php file. Enjoy!
updated january 30th, 2009, please read this entry for update instructions and the updated zip file.
15 comments
Add a new comment »Categories
Recent Entries
Recent Comments
- Dede (I checked it today in a shop. GT2 had some troubles with six ...)
- Matt (Bintang, You need to re-direct the url, try ...)
- jesth (Ohh.. why didn't I think of that, thanks alot.)
- Matt (Dede, I don't have Gran Turismo 2, any of the 2nd+ generation ...)
- Matt (Jesth, Just change the if condition, instead of looking for ...)
- jesth (Hi (again) Was wondering, is it possible to make it ...)
- Bintang Sembilan (Matt, thanks for your modd. I have apply it to my ...)
- Dede (Hello there. Can you check something for me? I want to buy ...)
- Matt (I think it's a driver issue Terrence, or it was a driver issue. ...)
Popular Entries
- Light-weight related articles mod for sNews 1.7 (4.5/5)
- Image / math hybrid captcha version 2, vastly improved (4.42/5)
- 1024x600 netbook wallpapers of Evangeline Lilly (4.4/5)
- Compact archives for sNews 1.7 (4.4/5)
- sNews Ajax Polls mod now available (4.38/5)
- Pretty date and comments bars in sNews CMS (4.35/5)
- Page caching mod for sNews 1.7 (4.33/5)
- Gravatar mod for sNews 1.7 (4.29/5)
- An improved tag cloud for sNews 1.7 (4.29/5)
Dec 21st, 2008 at 12:07 pm
Nice mod there man. I'll try it tomorrow and return with results.
thanks
Dec 22nd, 2008 at 7:18 am
Cool, sounds good, please don't hesitate to ask any questions if needed, or let me know if I goofed anything too.
Dec 24th, 2008 at 6:50 pm
Matt, this is the _output_ I get in local testing:
//grabs the url to the article $social_url = urlencode(_SITE.$uri."/".$r['asef']); //grabs the title of the article $social_title = urlencode($title); // add your links here echo <<stumbleupon reddit digg HTML;
(I removed the image references while testing)
Naturally I'm using a really modified setup, but seeing as the code gets printed well enough, I'd guess this would be a strip_tags issue? I'll try work around it, just thought I'd mention it.
Happy holidays!
Dec 24th, 2008 at 10:07 pm
Hi Fred,
That's odd, so it's simply printing the code out as text? Let me know what you figure out.If you get stuck, use the contact form to drop me an email and I'll email you back.
Happy holidays to you as well!
--Matt
Dec 25th, 2008 at 4:20 pm
Matt, the solution is really simple -- I should've seen it from the start and then it wouldn't have been a problem. I had no opening/closing php tags in the social.php file...
You could add a note in the tut that **if** people use the social bookmark function from an external file, make sure that it begins with ... Then even dimwits like me will get it right. The mod and tut are great.
Cheers!
Dec 25th, 2008 at 8:18 pm
Thanks Fred, that makes sense, I will add the opening and closing php tags in the tutorial now.
I'm glad you liked the mod.
Jun 18th, 2009 at 2:12 am
1 minute Mod! Greta one Matt!
Aug 26th, 2009 at 7:41 pm
How I can add another social bookmark/share this, like twitter and facebook?
Where I can find the social bookmark's images?
Thank you. :)
Aug 26th, 2009 at 8:11 pm
Hi Adhi,
Each social network has it's sharing link, as seen above, at the least you need to pass the url of the article, (and most accept the title as well). Those are contained in the $social_url and $social_title variables in my mod.
For example, facebook's sharing link uses sharer.php and passes the variables as u(the url) and t(the title), aka you'd add this to the boomarks div;
And then for twitter;
As for the icons, each service usually has a default icon, (i.e. http://www.facebook.com/share_partners.php or http://twitter.com/favicon.ico - download them and convert them to .png or whatever, but you can find all kinds of great free sets just by googling.
Nov 20th, 2009 at 1:36 pm
hi matt you know you deploy your social bookmarks mod but it happens that gives me a very big space after the article to show social bookmarks could help me? my page is www.kudaiarg.com thanks Excuse my English
Nov 20th, 2009 at 1:45 pm
Hi Armando,
I just had a look at http://www.kudaiarg.com, and it looks OK to me. I don't see the large space in Firefox, using FireBug I only see 2px padding around the containing div?
Can you take a screenshot and post the link?
Nov 20th, 2009 at 2:05 pm
thanks matt. See http://kudaiarg.com/portal/los-40-principales/ There are narrow space is the first article and the second that's all categories
Nov 20th, 2009 at 2:16 pm
Armando,
It appears that you have a div after the sidebarright, it's class="claer".. I'm guessing that should be class="clear"? maybe that would help?
Actually, if it's breaking the layout, you probably don't want that div there at all...
Jan 25th, 2010 at 9:56 am
Done... Thinking of adding more to it though... perhaps.
Jan 25th, 2010 at 10:18 am
Yeah, I ended up just dropping it and sticking the "AddThis" button, it's nice and compact and has access to the myriad services people use.