Welcome, Guest. Please login or register.
Did you miss your activation email?
February 11, 2012, 05:37:04 AM

Login with username, password and session length
Search:     Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter hier und auf unserer neuen Webseite.
149534 Posts in 21088 Topics by 7529 Members
Latest Member: schwaneb
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Would you like a free comic on your site?  (Read 6254 times)
Fratm

Offline Offline

Posts: 101



« on: December 20, 2006, 12:15:51 AM »

There is a comic I enjoy reading at blaugh.com, they released an API that allows you to have a daily comic on your site, so I wrote a little code that you can insert into a Code page, and it will give you a daily comic, and some navigation to view previous comics.

(SEE CODE BELOW..)

Enjoy!!
« Last Edit: December 20, 2006, 05:58:46 PM by Fratm » Logged
kweitzel
Forum administrator
*****
Offline Offline

Posts: 6817


WWW
« Reply #1 on: December 20, 2006, 07:51:01 AM »

Nice script ... you just forgot to paste the "close" code of the last else-statement. Here is the corrected code (note the last line):

Code:
if (!$number) { $number=0;}
$previous = $_GET['h'] +1;
$next = $_GET['h']-1;
$comic_data = file_get_contents('http://blaugh.com/api/php/1.0/getcomic/'. $_GET['h']);
$comic = unserialize($comic_data);
if ($comic === false) {
         die ('Could not get comic');
        }
echo "<br><bR><br>";
echo "<center>";
echo "<table border='0'>";
echo "<tr>";
echo "<th>". $comic['title'] ."</th>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "<a href=\"". $comic['permalink'] ."\" title=\"". $comic['title'] ."\" >";
echo "<img src=\"". $comic['image_url'] ."\" alt=\"". $comic['title'] ."\" >";
echo "</a>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "<table border=0 width=100%><tr>";
echo "<td><div style='text-align:left'><a href='/?h=". $previous ."' align=left>Previous </a></td>";
if ($next  >= 0) {
echo "<td><div style='text-align: right;'><a href='/?h=". $next ."' align=right> Next </a></td>";
} else {
echo " <td><div style='text-align: right;'>Next</div></td>";
echo "</tr></table>";
echo "</td>";
echo "</tr>";
echo "</table>";
};

[Edit] Ahh ... yes and the previous/next links don't work in your code ..[/Edit]

cheers

Klaus
« Last Edit: December 20, 2006, 07:56:19 AM by kweitzel » Logged

WebsiteBaker Org e.V. - for WebsiteBaker

Fratm

Offline Offline

Posts: 101



« Reply #2 on: December 20, 2006, 05:49:49 PM »

Hmm Working on my site (http://wbtest.adnd.com)

Here is the exact code I used.. maybe I posted my beta code..

(See Code below..)
« Last Edit: December 21, 2006, 03:52:14 PM by Fratm » Logged
kweitzel
Forum administrator
*****
Offline Offline

Posts: 6817


WWW
« Reply #3 on: December 20, 2006, 07:03:56 PM »

maybe you did post a beta ... but still in this code the previous link does not work although the comic is beeing displayed ...

cheers

Klaus
Logged

WebsiteBaker Org e.V. - for WebsiteBaker

Fratm

Offline Offline

Posts: 101



« Reply #4 on: December 20, 2006, 11:43:53 PM »

maybe you did post a beta ... but still in this code the previous link does not work although the comic is beeing displayed ...

cheers

Klaus

The code I posted is exactly what I am using at http://testweb.adnd.com and it works there.. So maybe there is something else going on?

-Steve
Logged
kweitzel
Forum administrator
*****
Offline Offline

Posts: 6817


WWW
« Reply #5 on: December 21, 2006, 09:02:20 AM »

and this is the code I tried ... check out the previous link here:

[Edit: Link removed]

cheers

Klaus
« Last Edit: February 09, 2009, 07:21:18 AM by kweitzel » Logged

WebsiteBaker Org e.V. - for WebsiteBaker

Fratm

Offline Offline

Posts: 101



« Reply #6 on: December 21, 2006, 03:51:29 PM »

I know what's wrong.. And here is the code that fixes it (I hope).

Code:
if (!$number) { $number=0;}
$previous = $_GET['h'] +1;
$next = $_GET['h']-1;
$comic_data = file_get_contents('http://blaugh.com/api/php/1.0/getcomic/'. $_GET['h']);
$comic = unserialize($comic_data);
if ($comic === false) {
         die ('Could not get comic');
        }
echo "<br>";
echo "<center>";
echo "<table border='0'>";
echo "<tr>";
echo "<th>". $comic['title'] ."</th>";
echo "</tr>";


echo "<tr>";
echo "<td>";
echo "<a href=\"". $comic['permalink'] ."\" title=\"". $comic['title'] ."\" >";
echo "<img src=\"". $comic['image_url'] ."\" alt=\"". $comic['title'] ."\" >";
echo "</a>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "<table border=0 width=100%><tr>";
echo "<td><div style='text-align:left'><a href='". $_SERVER['SCRIPT_NAME'] ."?h=". $previous ."' align=left>Previous </a></td>";
if ($next  >= 0) {
echo "<td><div style='text-align: right;'><a href='". $_SERVER['SCRIPT_NAME'] ."?h='". $next ."' align=right> Next </a></td>";
} else {
echo " <td><div style='text-align: right;'>Next</div></td>";
}
echo "</tr></table>";
echo "</td>";
echo "</tr>";
echo "</table>";


The code was assuming 2 things.. 1) that you were calling this up from your first page, and 2) that your first page lived at /  I changed it to get the actual script name that called it, and to use.. should work now.. sorry about the mess ups..

By the way, I run a small wiki, which is not publicly editable, I document my projects in there, and for this one I gave a special thanks to you for your help, I also put a link to your web site..  Thanks =) 

http://www.fratm.com/index.php/Blaugh_php_api_code

-Steve
« Last Edit: December 21, 2006, 04:02:12 PM by Fratm » Logged
kweitzel
Forum administrator
*****
Offline Offline

Posts: 6817


WWW
« Reply #7 on: December 21, 2006, 06:40:03 PM »

yep, that is it working now ... ready for release (Ever thought about a pagetype module for this kind of thing?)

cheers

Klaus
Logged

WebsiteBaker Org e.V. - for WebsiteBaker

Fratm

Offline Offline

Posts: 101



« Reply #8 on: December 21, 2006, 07:48:24 PM »

yep, that is it working now ... ready for release (Ever thought about a pagetype module for this kind of thing?)

cheers

Klaus

Actually, funny that you mentioned it.. I was just thinking about doing that.. Maybe over Xmas break I will write one up.

-Steve
Logged
kweitzel
Forum administrator
*****
Offline Offline

Posts: 6817


WWW
« Reply #9 on: December 21, 2006, 09:02:46 PM »

Maybe design it from the beginning on, so that other comics can be added. A Friend of mine used to manually parse some sites (like dilbert) in Lotus Notes Script smiley

But I take it, those sites could be parsed with curl (But be aware, that not every serverconfiguration supports CURL ... so in the beginning don't limit your Audience ... grin

cheers

Klaus
Logged

WebsiteBaker Org e.V. - for WebsiteBaker

Fratm

Offline Offline

Posts: 101



« Reply #10 on: December 21, 2006, 09:17:38 PM »

Maybe design it from the beginning on, so that other comics can be added. A Friend of mine used to manually parse some sites (like dilbert) in Lotus Notes Script smiley

But I take it, those sites could be parsed with curl (But be aware, that not every serverconfiguration supports CURL ... so in the beginning don't limit your Audience ... grin

cheers

Klaus

Yeah, maybe in version 2 =)  This one is using the Blaugh API at www.blaugh.com.. Here is the first attempt at a module.  (Works on my test page...)

Logged
kweitzel
Forum administrator
*****
Offline Offline

Posts: 6817


WWW
« Reply #11 on: December 22, 2006, 06:54:03 AM »

Just had a go on a XAMP System, does everything it needs to wink

Installation, Page and Deinstalation OK. Will check on a different system (LAMP) later on ...

cheers

Klaus
Logged

WebsiteBaker Org e.V. - for WebsiteBaker

Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!