Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-05-31 10:39:22

aslsw66
Member
From: Canberra, Australia
Registered: 2004-08-04
Posts: 342
Website

Links, but with images

I’m finally getting around to building my personal site.

I enjoying taking a lot of photos, and use a Flickr Pro (or what used to be called that) as the online storage of all of my best photos.

Here’s what I want to achieve:

  • on the homepage, I want to feature four of my sets from Flickr (just whichever sets take my fancy),
  • I would like a thumbnail from a photo in each set to appear, as a link through to the full set in Flickr,
  • I’m happy to create a local thumbnail within Textpattern for this purpose.

To me, it seems to make sense to use links for this purpose – easy to update, easy to categorise and then pull the last 4 links from this category (or possibly even randomise the links).

What I can’t figure out is how to connect a thumbnail to a link (ie. with a one-to-one relationship).

The link-based plugins don’t seem to achieve this, as they appear to be focussed on one type of content for building links – I really want to build a link from two types of content.

Any ideas?

Offline

#2 2013-05-31 11:33:58

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Links, but with images

How about using the image caption field for this task instead?

Like this:

<txp:images category="flickr" sort="id desc" break="li" limit="4">
	<txp:variable name="flickr-link" value='<txp:image_info type="caption" />' />
	<txp:if_variable name="flickr-link" value="">
		<txp:image width="0" height="0" />
	<txp:else />
		<a href="<txp:variable name='flickr-link' />" title="View on Flickr&hellip;"><txp:image width="0" height="0" /></a>
	</txp:if_variable>
</txp:images>

That code checks whether content is in the caption, and if yes makes a link around the image.

UPDATED to remove escape="" as mentioned later in this thread.

Last edited by philwareham (2013-06-04 14:09:45)

Offline

#3 2013-05-31 11:48:43

aslsw66
Member
From: Canberra, Australia
Registered: 2004-08-04
Posts: 342
Website

Re: Links, but with images

Perfect solution thanks!

Now my devious mind is turning to whether I can ‘pack’ the caption with the name of the set plus a separator and the URL, and then use a plugin to unpack the two items. I’m sure I’ve seen a plugin or two that will achieve that…

Offline

#4 2013-05-31 12:02:37

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Links, but with images

Put the name of the set into the alt field maybe? You can retrieve it with this inside your <txp:images /> tag…

<txp:image_info type="alt" />

Seriously, I’d always try to avoid using any third-party plugins when the core can already give you what you want.

Offline

#5 2013-05-31 12:21:16

aslsw66
Member
From: Canberra, Australia
Registered: 2004-08-04
Posts: 342
Website

Re: Links, but with images

Even better idea. I guess I’ve never really used images as content before, only for the site design.

Agreed on using core functionality before going to plugins.

And thanks again.

Last edited by aslsw66 (2013-05-31 12:21:28)

Offline

#6 2013-06-04 09:28:42

merz1
Member
From: Hamburg
Registered: 2006-05-04
Posts: 994
Website

Re: Links, but with images

Smart. Stored in my TXP Zotero repository. Thanks!

My standard note:

Important: escape="" to not urlencode the target URL. Take care of content because of missing security without urlencoding!

Last edited by merz1 (2013-06-04 09:29:21)


Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML

Offline

#7 2013-06-04 11:40:05

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Links, but with images

escape="" should be set to its default. Unless you are pasting in already HTML encoded URLs, the escaping will not break them. Instead, removing the escaping will generate invalid HTML and cause security vulnerabilities. Never ever turn escaping off if you are running multi-user website.

That said, escape does not prevent XSS attacks when using in src or link attributes. It sanitizes input for HTML, not for HTTP or any other transfer protocol. So it protects you from straight HTML injections, but not from URLs. So, keep in mind that you can not safely use custom_fields or image_info fields, or any other Textpattern tag, in URL query params (by appending the value to a URL) without using a plugin or PHP snippet. But that’s beside the point since the tag is used to return the full URL and not components of it (making it unsafe no matter what, unless you use a off-domain redirection).

Same goes for JavaScript and other content formats you could be using in your templates. Textpattern tags only generate valid and safe content for HTML. For instance, using a Textpattern tag inside a <script></script> block creates nothing but a XSS vulnerability.

Offline

#8 2013-06-04 11:42:28

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Links, but with images

Errm, so what you are saying is:

<txp:variable name="flickr-link" value='<txp:image_info escape="" type="caption" />' />

Should be:

<txp:variable name="flickr-link" value='<txp:image_info type="caption" />' />

Yes?

Offline

#9 2013-06-04 14:08:32

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Links, but with images

philwareham wrote:

Yes?

Yes.

Offline

#10 2013-07-10 15:17:00

merz1
Member
From: Hamburg
Registered: 2006-05-04
Posts: 994
Website

Re: Links, but with images

Documentation: Can we please have Jukkas escape="" warning/description as an important security note for www.textpattern.net/wiki/index.php?title=Attributes_Cross-reference#escape.

I read it three times now but forgot most of it immediately ;)
But the ‘escaping is only safe for HTML’ part seems to be important, isn’t it?

Last edited by merz1 (2013-07-10 15:19:54)


Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML

Offline

Board footer

Powered by FluxBB