Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2006-09-19 20:09:07

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,515
Website GitHub

Re: smd_random_banner: Random banner image for advertising

Pants. Small snagette. Added the ability to split the text up (easier than I thought) but there’s an implementation problem.

The ‘alt’ column in the database is, for all intents and purposes, a full string of words. In order to check word-for-word there are two options:

1) Use a fulltext search which makes this sooo simple it hurts. Except TXP doesn’t have a fulltext index on that table/column, so this doesn’t work.

2) Use wildcards

Option 2 is what I’m doing now: make up a list of words and stick wildcards round each one, testing them in turn against the alt text/image filename. The problem here is that the computer has no concept of what a “word” is. If your title was “US fly drive deals”, you will get images that had alt text with the following words in them:

russia, belarus, flying, driven, house

and so on….

I tried the SQL “In” clause too but that doesn’t work the way I’d hoped. My guess is, unless somebody points me towards a clever way of doing it, I’ll have to stick with keeping the title/section/category text together for now.

it doesn’t matter how words are formatted in the ‘alt text’ – as the plug-in picks out individual words whether they are separated by hyphens or spaces

Yep, it will appear that way because I stick wildcards around each word in your list (and wildcards around the whole of the title/section/category). You may come unstuck occasionally as mentioned above if you use a short word that is contained inside another word because both will come out BUT, as you found out…

what happens if a word in ‘match_text’ is also found in ‘avoid_text’?

… the saviour is that if it does happen you can “negate” the longer/other word using avoid_text.

When you brought up the idea of match_text, I played with it both ways round and decided it made more sense (and was more flexible) to process match_text first so you can override it with avoid_text if you wish. Looks like I chose correctly. That’s a relief :-)

For some ultimate grooviness, the ability to negate categories / subcats would be genius

That would indeed be rather neat. Wonder if my coding is up to it… time will tell.

Thanks for stress-testing this and throwing ideas about. The plugin’s getting more useful by the minute.

Last edited by Bloke (2006-09-19 20:10:56)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#26 2006-09-19 20:55:02

lukepermsn
Member
From: london
Registered: 2004-07-15
Posts: 57
Website

Re: smd_random_banner: Random banner image for advertising

Well, it seems to be working rather well right now. ‘avoid_text’ is certainly negating anything ‘match_text’ throws up, so all good there. and the whole wildcard issue isn’t really an issue as far as I’m concerned. It appears to be rather a nice bonus that I can have the word ‘Antarctica’ in the alt text – but ‘Antarctic’ will also match there. So good job!

For the sake of completeness, if you really wanted to go the route of fulltext, wouldn’t that simply be a database update on that particular table? i.e.

ALTER TABLE ‘txp_image’ ADD FULLTEXT (‘alt’);

Or am I oversimplifying?

The wildcard route certainly works for reasons described above, certainly for now as I only have a couple of words in each alt tag. I guess one could always use an Anagram Generator to test for unusual cross-references!

So does this mean you’ve solved the hyphen separated word issue in the URL? awesome. I’m just realising the complexity of what is happening each time a page loads up – that the plug-in takes the words from the URL string and cross checks with the entire database of alt text for matching images… pretty wild when you consider i have about 500 images currently loaded.

Thanks for stress-testing this and throwing ideas about. The plugin’s getting more useful by the minute.

You’re absolutely welcome! I’m quite enjoying this process. Thank you for being so ‘into it’…

One more thought for the pot: currently no images display if ‘match_text’ doesn’t throw up anything meaningful. It would be neat is if there was some option for the plug-in to generate a random image anyway. That way random images will always display, switching to more ‘contextual’ random images if something in the URL matches the alt text. Maybe an option called <code>‘spawn’</code>? i.e. <code>spawn=“y”</code> to make the plug-in choose a random image from the assigned category(s) instead of showing nothing?

And finally, finally: I’m currently using two tags on the page to generate two random / contextual images. One side effect of this is that sometimes the plug-in generates the same image twice. Maybe the tag could have a ‘limit’ feature to output more than one image? it would be easy to then use CSS to arrange them as desired…

But all these things in time! good night.

Luke

Last edited by lukepermsn (2006-09-19 21:05:32)


“Absorb what is useful, Discard what is not, Add what is uniquely your own” – Bruce Lee

Offline

#27 2006-09-19 21:40:40

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,515
Website GitHub

Re: smd_random_banner: Random banner image for advertising

lukepermsn wrote:

For the sake of completeness, if you really wanted to go the route of fulltext, wouldn’t that simply be a database update on that particular table? i.e. ALTER TABLE ‘txp_image’ ADD FULLTEXT (‘alt’);

Yup, but the other (currently 8, but maybe more in future) people who use the plugin would find it doesn’t work without making the mod also :-p And my coding is nowhere near good enough to figure out how to do that at install time.

So does this mean you’ve solved the hyphen separated word issue in the URL?

Sort of, by virtue of not doing anything at all ;-) I tried, I failed, but as it happens it’s working as you expect anyway so I’ll start work on the next bit.

I’m just realising the complexity of what is happening each time a page loads up…

Yeah, and even though it’s not really very optimized ‘coz I’m a lazy coder, I think it’s working quick enough so far. One of the benefits of this awesomely lightweight TXP engine, methinx.

One more thought for the pot: currently no images display if ‘match_text’ doesn’t throw up anything meaningful. It would be neat is if there was some option for the plug-in to generate a random image anyway… Maybe an option called <code>‘spawn’</code>?

That could certainly be done. I thought about that issue as I was writing the help file but talked myself out of coding anything by palming the “no image” issue off to the excellent chh_if_data plugin. If my plugin returns nothing at all, chh_if_data can detect it and provide an alternative path for you to do anything else you desire.

But adding the catch-all to this plugin might work. It would mean a 2nd call to the database because, after the first has returned no rows, I’d need to strip out everything except the category attribute (if supplied) and try again. Shouldn’t slow it down too much – after all, it’s an “exceptional” circumstance.

And finally, finally: … Maybe the tag could have a ‘limit’ feature to output more than one image?

Not a problem in principle. May have to delve into providing wraptag and class attributes though, which is a bit of a bind. I suppose with good use of CSS selectors it’s possible to style img and img > img (or something) to get hold of each image separately, but that may leave IE users out in the cold.

Certainly getting more than one image out of the database is a breeze. I’ll experiment with outputting two or more and see how easy it is to manipulate them on the page.

Last edited by Bloke (2006-09-19 21:44:51)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#28 2006-09-20 09:33:49

lukepermsn
Member
From: london
Registered: 2004-07-15
Posts: 57
Website

Re: smd_random_banner: Random banner image for advertising

Cool as.

Unfortunately I’m already using chh_if_data to make the random images appear if another tag doesn’t generate any output! No matter. I can probably get around that. :-) Maybe I can embed chh_if_data inside each other?? I love this conditional statement way of programming :-p

The hyphen separated title issue hasn’t gone away – the plug-in works great on pages that have a single word title or category, like ‘Tibet’ or ‘Africa’ – but pages that have something like ‘Antarctic-Peninsula’ display no images right now, as I guess the plug-in is looking for that string in the alt text. Once again, no matter as I can simply add that string to alt text for now, but it would certainly be nice and slick if the plug-in recognised ‘Antarctic’ and ‘Peninsula’ as two separate words ;-) (no pressure!)

btw – If you want, I’ll email the URL of the site I’m working on, so that you can see the thing in action!

Yeah, CSS selectors would be the way to go for styling image positions. I wouldn’t get too hung up on <code>break</code> and <code>wraptag</code> attributes, as it would be a breeze to simply enclose the tag inside a DIV with a css ID and then call the images like:

<code>#images img { … do something … }</code>

Cheers :D

Last edited by lukepermsn (2006-09-20 10:04:47)


“Absorb what is useful, Discard what is not, Add what is uniquely your own” – Bruce Lee

Offline

#29 2006-09-20 21:56:40

lukepermsn
Member
From: london
Registered: 2004-07-15
Posts: 57
Website

Re: smd_random_banner: Random banner image for advertising

Hi mate, some more feedback for you:

Been using this quite extensively today, and I must say I’m impressed. It’s been a bit of grunt work on my part now to tag around 500 images, but now that (most of them) are correctly tagged, the plug-in works like a dream.

I’ve gotten around the parent / subat issues by simply employing more descriptive tagging, and using ‘<code>avoid_text</code>’ to prevent certain images appearing in certain locations. Similarly I’ve circumvented the whole separating the hyphenated title / category strings into individual words issue by simply putting the whole title or category into some of the alt texts of images I want to appear on those pages. Just looks a bit clunky though! But on the pages themselves, images are randomly rotating on each display as expected.

The only issues I still have with the plug-in as it stands are not being able to generate more than one image and the inability to have it output an image anyway, if <code>match_text</code> doesn’t throw up anything. As I’m using two separate tags, the same image appears sometimes on a page twice! and as described, using <code>chh_if_data</code> isn’t really an option for me for the no image issue.

But, you know what: Now that I’ve added all the relevant titles etc. into the image alt tags, I’ve realized that there is one feature that would make this plug-in killer: and that’s if you could match <code>look_in</code> words with the image categories themselves – as frankly, the majority of the text I have ended up putting in the alt text is a replication of the image’s category and that categories parent, as I have them all arranged by world regions, and then each region is divided into countries.

I realize that this is a good workaround for me right now, to get over the list by category issue above – but the ability to <code>use_category</code> also as a reference for keywords would be killer. Or at least something to ponder over ;-)

Bye for now. L.

Last edited by lukepermsn (2006-09-20 22:00:10)


“Absorb what is useful, Discard what is not, Add what is uniquely your own” – Bruce Lee

Offline

#30 2006-09-28 23:57:01

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,515
Website GitHub

Re: smd_random_banner: Random banner image for advertising

lukepermsn wrote:

The only issues I still have with the plug-in as it stands are not being able to generate more than one image and the inability to have it output an image anyway.

Issues now dealt with in v0.15

Two new parameters: limit="2" (3,4,5… defaults to 1) to generate that many images in one go, and always_display="1" to cause the plugin to try again in the event it finds nowt that matches your criteria. In that situation it ignores any match_text or avoid_text you have supplied and looks in just the given category (if supplied) or the whole image pool if not.

I’ve realized that there is one feature that would make this plug-in killer: and that’s if you could match <code>look_in</code> words with the image categories

{headsmack} why didn’t I think of that. Right, I’m going to climb back in my box and think. Initial thought is that the nomenclature is going to get confusing from hereon in. Multiple uses of the word “category” now to match different things. Urk. Watch this space…


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#31 2006-09-30 13:54:56

lukepermsn
Member
From: london
Registered: 2004-07-15
Posts: 57
Website

Re: smd_random_banner: Random banner image for advertising

genius :-)

<code><backflip /></code>

L.


“Absorb what is useful, Discard what is not, Add what is uniquely your own” – Bruce Lee

Offline

#32 2006-10-06 20:57:39

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 379
Website

Re: smd_random_banner: Random banner image for advertising

Stef,

Great plugin. Thanks for all the great work!

It displays perfectly and the images load really quickly. Unfortunately, the plugin is not generating any links. I am sure I am doing something wrong, but I can’t figure it out.

  • This is my tag: <code>
    <txp:smd_random_banner category=“front-page” linkcaption=“1” />
    </code>
  • Links were added to the caption fields of the images.
  • I am using Textpattern · 4.0.3

I hope you may be able to help me out here. :-)

Speak to you soon (from Japan!),

Kjeld


JapaneseStreets.com – Japanese street fashion (mostly txp)
Old Photos of Japan – Japan between 1860 and 1940 (100% txp)
MeijiShowa – Stock photos of Japan between 1860 and 1940 (100% txp)

Offline

#33 2006-10-17 04:00:09

mercury
Member
Registered: 2006-05-12
Posts: 26

Re: smd_random_banner: Random banner image for advertising

about generating links in v0.15
i suggest to wait for clearing from author

as for me i did the following: (i’m not a coding junkie, so it seems like just temp. solution)
find: <code>smd_rs_out($rs)</code>
change to: <code>smd_rs_out($rs,$linkcaption)</code>
(3 times)

and one more thing:
now, if you leave caption filed blank the link of the images will lead you to site root. if you want to have these images displayed without link (as i think more proper, except content of your image intended to link to your head page), do the following:

find:
<code> if ($linkcaption) { $linkName=trim($row[‘caption’]);
</code>
change to:
<code> $linkName=trim($row[‘caption’]); if ($linkcaption && $linkName) {
</code>

Offline

#34 2006-10-17 07:39:41

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 379
Website

Re: smd_random_banner: Random banner image for advertising

Thanks, mercury! It works as a gem.


JapaneseStreets.com – Japanese street fashion (mostly txp)
Old Photos of Japan – Japan between 1860 and 1940 (100% txp)
MeijiShowa – Stock photos of Japan between 1860 and 1940 (100% txp)

Offline

#35 2006-10-17 22:51:15

mercury
Member
Registered: 2006-05-12
Posts: 26

Re: smd_random_banner: Random banner image for advertising

oh, gosh! the randomness is leaked with 4.0.4 ((

Offline

#36 2006-10-17 23:28:27

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 379
Website

Re: smd_random_banner: Random banner image for advertising

mercury wrote:

oh, gosh! the randomness is leaked with 4.0.4 ((

What do you mean?


JapaneseStreets.com – Japanese street fashion (mostly txp)
Old Photos of Japan – Japan between 1860 and 1940 (100% txp)
MeijiShowa – Stock photos of Japan between 1860 and 1940 (100% txp)

Offline

Board footer

Powered by FluxBB