TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

May 17, 2024, 05:03:57 PM

Login with username, password and session length
Members
  • Total Members: 3,886
  • Latest: Grendor
Stats
  • Total Posts: 195,189
  • Total Topics: 21,220
  • Online today: 107
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 109
  • Total: 109

Latest Comic

Started by onicat, August 04, 2008, 01:18:38 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

onicat

Is there a php script to pull the lastest comic from a comicpress website and display it on the front page of a smf/tp website?

I wam wanting to put a comic up on my website. I have it set up on http://akcommunity.com is the test site we are working with, and http://akcommunity.com/Comic is the site for comic.

We have tried the rss feed option. But that pulls ALL. If there was a way to only pull the most recent comic posted that would be cool.

Does any body have any suggestions as to how I could pull the most recent comic from the /Comic site to the akcommunity.com site and display it on the front page?

IchBin

Only if the comic site has given you an RSS feed or something to grab the latest comic with.

onicat

Could you go into more detail on your response please.

IchBin

The comic site has to give you a way to get the information. The way its done today is usually through some time of interface or webservice. RSS feeds provide this information IF, and only if the website you want to pull the information from GIVES you an RSS feed. The RSS feed (a link they give you) can then be added as an RSS type block in TP which will automatically display what they put in the RSS feed.

onicat

Yeah, I understand how the RSS feed function works.  The specifics of the problem I'm trying to surmount are as follows:

I have a SMF+TP community web site, and the community in question is now producing its own webcomic.  So, I installed a subdirectory to the main site that contains a WordPress+ComicPress site that I intend to use to archive and display the comics in a reasonable fashion.  ComicPress does support a RSS feed, but by default the feed pulls ALL of the archived comics, orders them in descending order by date, and then outputs them.  If you use the RSS function of TP to display this feed, you end up with one long post with every single comic displayed in it.

That's nice, but not what I'm after.  All I want is to display the most recent comic at the top of the front page of the TP+SMF site.  I have absolutely no experience with RSS, and only minimal experience with PHP, so I'm here looking for help with this.  After scouring the internet (mostly this site), I've found one mod that supports WordPress blogs as an inline frame, but because its meant to display just a text blog, it naturally only displays text and not the image associated with it.

So, I need some help.  Either I need to create a modified RSS feed for ComicPress that only displays the latest comic, or I need to come up with a PHP block that does the same.  Re-using the PHP from the ComicPress theme just doesn't work because it draws on functions from like a dozen other files, and I can't figure out how to incorporate all that in a PHP block in a manner that works.   I understand the functions its using (it converts the post into a date, then uses the date to look for the image file and display it), but I can't figure out how to bring them together in the right way to make it work.

I understand that this is TinyPortal support and not ComicPress/WordPress support, but does anyone have any suggestions I can try?

JPDeni

The rss feed is usually an xhtml file. I don't have any experience with them exactly, but I know they're in a specific format. The trick is to read the format.

I'm in the process of moving four websites at the moment, but I'll take a look at the code for reading rss and see if I can figure out how to adapt it to just read one entry.

IchBin

Can you show us the RSS feed? You can possibly use a third party RSS feed reader to parse the RSS feed for you, and control the results. Just a couple to look at if you'd like.
http://www.tinyportal.net/index.php?topic=14424

onicat

WordPress uses a PHP script to generate the feed.  The feed itself is here.  This is the code that generates it:

<?php
/**
 * RSS2 Feed Template for displaying RSS2 Posts feed.
 *
 * @package WordPress
 */

header('Content-Type: text/xml; charset=' get_option('blog_charset'), true);
$more 1;

?>

<?php echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'?>

<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
<?php do_action('rss2_ns'); ?>
>

<channel>
<title><?php bloginfo_rss('name'); wp_title_rss(); ?></title>
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
<link><?php bloginfo_rss('url'?></link>
<description><?php bloginfo_rss("description"?></description>
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000'get_lastpostmodified('GMT'), false); ?></pubDate>
<?php the_generator'rss2' ); ?>
<language><?php echo get_option('rss_language'); ?></language>
<?php do_action('rss2_head'); ?>
<?php while( have_posts()) : the_post(); ?>
<item>
<title><?php the_title_rss() ?></title>
<link><?php the_permalink_rss() ?></link>
<comments><?php comments_link(); ?></comments>
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000'get_post_time('Y-m-d H:i:s'true), false); ?></pubDate>
<dc:creator><?php the_author() ?></dc:creator>
<?php the_category_rss() ?>

<guid isPermaLink="false"><?php the_guid(); ?></guid>
<?php if (get_option('rss_use_excerpt')) : ?>
<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<?php else : ?>
<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<?php if ( strlen$post->post_content ) > ) : ?>
<content:encoded><![CDATA[<?php the_content() ?>]]></content:encoded>
<?php else : ?>
<content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]></content:encoded>
<?php endif; ?>
<?php endif; ?>
<wfw:commentRss><?php echo get_post_comments_feed_link(); ?></wfw:commentRss>
<?php rss_enclosure(); ?>
<?php do_action('rss2_item'); ?>
</item>
<?php endwhile; ?>
</channel>
</rss>


Obviously that's drawing on a bunch of functions that are defined in another file.  I can list its contents if you feel like it will help. 

I have the option of writing my own feed.php and using that (via the Feed Wrangler plugin), but I don't know the first thing about how to go about doing that.

Ianedres

O-cat,

There are ways to get daily images from a website besides RSS, if you understand the naming scheme used- keyword being 'daily'.

However, it may violate the owner's copyright and licensing terms should you use something like this script, unless you have some type of agreement with the site. This is a very rudimentary script I wrote years ago while trying to learn php.

<?php

function image_get($comic$divname$imagetype)
{
echo $comic '<br />';

$imagedir 'http://images.ucomics.com/comics/';

$currentyear date("Y");
$currentday date("ymd");

$link $imagedir $divname '/' $currentyear '/' $divname $currentday '.' $imagetype;

echo '<img src="' $link '" \><hr />';
}


// Non-Sequitor
$comic 'Non-Sequitor';
$divname 'nq';
$imagetype 'gif';

image_get($comic$divname$imagetype);

// Nine To Five
$comic '9 To 5';
$divname 'tmntf';
$imagetype 'gif';

image_get($comic$divname$imagetype);
?>

onicat

Copyright has nothing to do with it this time, I own both sites and the images in question.

Your script, as you pointed out, only works for daily updates.  This comic is updated...kinda weekly.  We're still hammering that one down.  =)

I'm working with SimplePie and the Dynamic Drive DHTML script right now, but darned if I can get it to work!

IchBin

Did you look at the link I provided? One of the links on that page http://feed2js.org/index.php?s=build will do exactly what you want I think.

onicat

Tried it.  The HTML block mode didn't like having a <script> in it for some reason.  All it displayed was code.  I think I can do it using SimplePie and an iframe, though.

IchBin

Then don't use an HTML block, use a script block type.

Ianedres

#13
Try this and see if it will work on your server. It does require 'allow_url_fopen' to be set to on in your server's php.ini configuration file. (More info on that)... I think this would work better than trying to build the RSS feed on your one site, and then try to extract the graphic on the other.

This should start at the current date and try to open a file with the naming scheme of 'yyyy-mm-dd' (which is the format the graphic used in original example). Failing that, it will subtract one day at a time, going down through the months. It will limit the search to the previous year...

* Remove the opening and closing php tags if you are copying directly to a php block or article...

I went back and added the option to set the image size, as well as whether it can be linked to the original graphic by clicking on the displayed image (for making a thumbnail).

<?php

// akcommunity.com | Latest Comic Retrieval
// August 06, 2008 | Tim Antley | www.BayouMX.com

// Two variables ($comic_path & $comic_ext) should be set to go
// Other variables can be set by reading comments

// Your php server must have 'allow_url_fopen' on in php.ini config file.
// See http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen for more info on that.

$date getdate();
$year $date['year'];
$month sprintf("%02s"$date['mon']);
$day sprintf("%02s"$date['mday']);

$max_height '743'// set image maximum height
$max_width '800'// set image maximum width

$use_link true// 'true' or 'false' - makes displayed image link to original image (for thumbnailing)
$target '_blank'// link target - '_blank', '_self', etc.

// build the link with padded zeros
function make_link($year$month$day)
{
$comic_path 'akcommunity.com/Comic/comics/'// path to your server and directory with trailing slash /
$comic_ext 'jpg'// image type extension (jpg/gif/tif/bmp)

$link $comic_path sprintf("%04s"$year) . '-' sprintf("%02s"$month) . '-' sprintf("%02s"$day) . '.' $comic_ext;

return $link;
}

// start recursive search by day, then month, and year
for($year $year$year >= ($year 1); $year $year 1)
{
for($month $month$month 0$month $month 1)
{
for($day $day$day 0$day $day 1)
{
$link  make_link($year$month$day);

if(@fopen('http://' $link"r")) // suppress errors
{
if($use_link) echo '<a href="http://' $link '" target="' $target '">';

echo '<img src="http://' $link '" height="' $max_height '" width="' $max_width '" />';

if($use_link) echo '</a>';
return; // image was found - end of script
}
}
$day '31'// reset to day #31 for recursive search
}
$month '12'// reset to month #12 for recursive search

}

// nothing for output if no file was located
?>

JPDeni

#14
Unnecessary post.

onicat

#15
That...is exactly what I'm looking for, Tim!  You, sir, are a gentleman and a scholar.  m(~.~)m  Setting allow_url_fopen wasn't an issue (already taken care of, in fact, for some other software I have installed).  The script works great in a PHP block (I get an image, and it's the correct one), but I'm running into a few odd issues:

First, when used exactly as presented (minus the open/close tags), it makes my right-hand TP column and all other blocks below it disappear.  How do I troubleshoot that?

Second, the link option links directly to the image itself.  That works as you intended, but I would prefer to link it to the comic archive site (http://akcommunity.com/Comic/), that way users can browse the archive if they wish to do so.  I noticed, however, I can't just change the code on the line that sets the $link variable because it would break the image output altogether.  I suppose I could just hard code that url into the line that actually outputs the href statement, though, right?

Third: This one kind of breaks things.  The $max_width and $max_height variables just tell the img statement what to scale things to, which will stretch things out of proportion when the comic sizes differ between postings.  Is there a way to make that dynamically scale?

I really appreciate the help, Tim.  Where do you want your credit?  :laugh:

Ianedres

For your questions:

1) My script simply outputs the <img> tag (and href, if set) to the screen; it does nothing to the other TP-blocks, tables, or anything else. If you are using this in a php article (I know you said a 'php block'), you may need to turn on/off the visual options as such. Other than maybe a CSS issue with margins or padding around the IMG image tag, it should not affect the display that I'm aware of.

2) To change the link to a static destination, just replace:if($use_link) echo '<a href="http://' . $link . '" target="' . $target . '">';
with this:if($use_link) echo '<a href="http://akcommunity.com" target="' . $target . '">';

3) To remove the height/width constraints, change:echo '<img src="http://' . $link . '" height="' . $max_height . '" width="' . $max_width . '" />';
with this:echo '<img src="http://' . $link . '" />';

As far as credit goes, don't worry about it. If you happen to have a links section or a simple way to point to my SMF/TP website (www.BayouMX.com), that would be cool.

Just remember to name the images using the yyyy-mm-dd scheme, and I think it will serve you well.

onicat

Have a look at http://akcommunity.com to see what I'm talking about regarding the disappearing blocks.  There are supposed to be a column down the right side and other content blocks below the comic.  Using your code in a TinyPortal PHP box causes those to disappear.  That's what I'm trying to solve now.  Otherwise it works beautifully.

Ianedres

My big error!  :o

Replace 'die();' with 'return;'...

Will modify my original code...