handling embeds in a feed? jpg image instead?

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
alpay
Regular
Posts: 28
Joined: Thu Sep 18, 2008 1:48 am
Location: New York
Contact:

handling embeds in a feed? jpg image instead?

Post by alpay »

Greetings all... This kinda relates to my recent post I made in the Plugins area of the forum at http://board.s9y.org/viewforum.php?f=4

I started a blog this week, http://blog.LitStudios.com. i'm getting a grip on things... here's my issue though : I typically use an rss reader (on my windows mobile 6 phone) to read blog content. my embedded flv players predictably don't show up in the rss feed, neither does the embedded youtube clip, which I suppose is also an embedded flash player.

I'd like to know if there is currently a way to swap out the embed with a jpg for browsers/readers/devices that won't display the embeds. I'd rather a reader who uses an rss reader see still-image place holders that represent the video to encourage them to click through and see the real content. I don't mind making still images for this purpose, i'm imagining writing a script to grab/crop a screenshot to create the placeholders for rss readers.

I have had trouble getting the Mobile Output markup plugin working, i'm probably doing something stupid. any suggestions?

Thanks is advance!

Alpay Kasal
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: handling embeds in a feed? jpg image instead?

Post by garvinhicking »

Hi!

The technically challenging way is to write your own smarty PHP function that you can call inside the feed*.tpl templates, which does the replacement...

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
alpay
Regular
Posts: 28
Joined: Thu Sep 18, 2008 1:48 am
Location: New York
Contact:

Post by alpay »

thanks for the reply.

I'm not afraid to learn, and have been eager to look into smarty functions ever since I was doing my research on which blog server to go with.

I suppose I'm going to have Serendipity figure out what browser is accessing the blog, and decide which .tpl to use? or is it possible to do the if/then logic in one template? like - if the browser is mobile, use this placeholder instead of the following embed code. because that would be nice and consolidated as I'll probably continue to tweak the bulletproof template in these first few weeks and months. I'd rather edit one template, easier to manage my crazed brain.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

What I would do is to create a config.inc.php file inside your custom template directory, and have some code like:

Code: Select all

<?php
$serendipity['mobile_browser'] = false;

if ($_SERVER['HTTP_USER_AGENT'] == 'blabla explorer') {
 $serendipity['mobile_browser'] = true;
}

$serendipity['smarty']->assign('mobile_browser', $serendipity['mobile_browser']);
This will create a $mobile_browser smarty variable, that is set to TRUE in case of a matching User Agent.

Now let's extend that same file with a custom smarty function that you can later call:

Code: Select all

function smarty_embedreplace($string) {
 global $serendipity;

 if ($serendipity['mobile_browser']) {
   // Get Embed SRC:
   preg_match('@<embed.*src="(.+)".*/>@imsU', $string, $m);
   $embedsrc = $m[1];
   $imgsrc = str_replace('.swf', '.jpg', $embedsrc);
   $string = preg_replace('@<embed.*/>@imsU', '<img src="' . $imgsrc . '" />', $string);
 }
 return $string;
}

$serendipity['smarty']->register_modifier('smarty_embedreplace', 'smarty_embedreplace');
This would actually be a helper function that transforms a raw HTML code's <embed> tags into <img> srcs to the filename of the embed src, but replacing SWF with JPG. Of course you'd have to touch up this function to do what you actually want to achieve.

Now you only need to call that helper function inside your feed*.tpl template files.

Search for

Code: Select all

{$entry.feed_body|@escape}
this holds the usual feed-body. Now you append your smarty function:

Code: Select all

{$entry.feed_body|@smarty_embedreplace|@escape}
And now this should take care of replacing your embed header, and all this depending whether a mobile browser is used or not.

That's just a raw idea I scribbled up, so it might still hold conceptual flaws :(

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
alpay
Regular
Posts: 28
Joined: Thu Sep 18, 2008 1:48 am
Location: New York
Contact:

Post by alpay »

Wow... thanks so much, even though it's "scribbled up", it seems like a thorough explanation of the steps I'll take. thank you, much appreciated

I'll probably get this done this weekend and report back on success or further questions. awesome.

btw, part of the reason I went with serendipity are the quality of these forums, I figured I might need help doing my own mods as I grow. I'm glad I made the right decision.
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Might there already be some logic in the Mobile Output plugin that figures out when the user is getting the blog from his mobile phone? Could cut down on the redundancy.
Judebert
---
Website | Wishlist | PayPal
alpay
Regular
Posts: 28
Joined: Thu Sep 18, 2008 1:48 am
Location: New York
Contact:

Post by alpay »

Yes, that is my hope... you replied to a msg about Spartacus being blocked by aplus.net, my web host. that was part of my process in getting the Mobile Output plugin working.

see http://board.s9y.org/viewtopic.php?t=13806&highlight= for that post if you have a moment. i installed it manually and everything seems ok, i get to adminsiter setting for the plugin via serendipity's admin gui. when i try to look at my blog on my WinMo6 phone (at&t tilt) I get an error. I'm going to further look into it tonight.

I do hope to get that plugin working for me, then maybe do such embed/image switching mods thereafter. together I think it's a pretty complete solution for the mobile rss reading person like myself.
Post Reply