Page 1 of 1

Feature Request: automatically set title-attr. in hyperlinks

Posted: Thu Jan 11, 2007 10:53 am
by matsch
Hi,

i have a little idea, which really would make life easier posting entries with several hyper links.

i would love a little feature which automatically populates the title-attribute for hyper links (as in [a href="" title=""]). it would be cool if it could get the page title of the referenced site and put it there.

possible?

regards,
matsch

Re: Feature Request: automatically set title-attr. in hyperl

Posted: Thu Jan 11, 2007 11:10 am
by garvinhicking
Hi!

That would be possible. One could hook into the trackback routine where all links are already searched for trackbacks, and then detect the title. After that you need to rewrite the whole body attribute to insert that link at proper position again, and this is where it will get a bit more complicated because you first have to rebuild the link and find the right position for replacing the text again.

HTH,
Garvin

Posted: Fri Jan 12, 2007 10:08 pm
by matsch
How would I go about fetching the Title of a remote site (without fetching the whole site)?

Regards,
matsch

Posted: Sat Jan 13, 2007 11:00 am
by garvinhicking
Hi!

You would need to simply match for <title>. If that does not exist, you must parse <meta> tags.

Something like:

Code: Select all

preg_match('@<title>(.*)</title>@imsU', $content, $match);
$title = $match[1];
if (empty($title)) {
    preg_match('@<meta\s+name="title"\s+content="(.*)"@imsU', $content, $match);
    $title = $match[1];
}
$content is the full HTML code of the remote page...

HTH,
Garvin

Posted: Wed Jan 17, 2007 8:40 pm
by matsch
Hi all!

I brought forward this little idea and implemented it in a small s9y event plugin.

I hope someone can have a quick look at it, since i am not a genius in php and it's my first s9y plugin.

you can grab it at: http://matsch.binaervarianz.de/serendip ... le-0.1.zip

if it's ok and more ppl think it's useful it could also make its way into spartacus.

waiting 4 feedback.

thanks,
matsch

Re: Feature Request: automatically set title-attr. in hyperl

Posted: Thu Jan 18, 2007 12:13 am
by stm999999999
matsch wrote:i would love a little feature which automatically populates the title-attribute for hyper links (as in [a href="" title=""]). it would be cool if it could get the page title of the referenced site and put it there.
one problem:

this can(?) make trouble with the exit link tracking:

Code: Select all

a href="http://blog.example/exit.php?url=aHR0cDovL2Jsb2cuZGVm" title="http://destination.example"  >
with your plugin it could be that the real url is not shown to the user anymore.

Re: Feature Request: automatically set title-attr. in hyperl

Posted: Thu Jan 18, 2007 9:57 am
by garvinhicking
Hi matsch!

Looking good! The URL regexp you made looks pretty nifty. :)

I think stm9x9s problem should be no problem, as existing 'Title' attributes seem to be preserved, right?

One thing that could be improved is your usage of file_get_contents(). This will not work on servers where allow_url_fopen is disabled. Instead you might want to use the PEAR HTTP_Request class, like Spartacus plugins and others use (search the code for "Request.php", you should see some places where the lib is used. It's pretty easy and straightforward.

Best regards,
Garvin

Re: Feature Request: automatically set title-attr. in hyperl

Posted: Thu Jan 18, 2007 8:51 pm
by matsch
Hi,

thanks for the reactions so far.
stm999999999 wrote:

Code: Select all

a href="http://blog.example/exit.php?url=aHR0cDovL2Jsb2cuZGVm" title="http://destination.example"  >
with your plugin it could be that the real url is not shown to the user anymore.
As I understand you correctly, you worry that those titles will be gone after using my plugin. I had a quick look at the plugin code and I am not sure what it will do with my titles. As it substitutes the links when displaying them it will either put their title (with the url) or put two titles. I am not sure. By the way my titles are stored within the entry in the database.
garvinhicking wrote:One thing that could be improved is your usage of file_get_contents(). This will not work on servers where allow_url_fopen is disabled. Instead you might want to use the PEAR HTTP_Request class, like Spartacus plugins and others use (search the code for "Request.php", you should see some places where the lib is used. It's pretty easy and straightforward.
Ok, i changed it to use the PEAR HTTP_Request.

New version is here: https://matsch.binaervarianz.de/serendi ... le-0.2.zip

Any comments appreciated.

Thanks,
matsch