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
Feature Request: automatically set title-attr. in hyperlinks
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: Feature Request: automatically set title-attr. in hyperl
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
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
# 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/
# 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/
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
You would need to simply match for <title>. If that does not exist, you must parse <meta> tags.
Something like:
$content is the full HTML code of the remote page...
HTH,
Garvin
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];
}
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/
# 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/
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
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
-
stm999999999
- Regular
- Posts: 1531
- Joined: Tue Mar 07, 2006 11:25 pm
- Location: Berlin, Germany
- Contact:
Re: Feature Request: automatically set title-attr. in hyperl
one problem: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.
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" >
Ciao, Stephan
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: Feature Request: automatically set title-attr. in hyperl
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
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
# 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/
# 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/
Re: Feature Request: automatically set title-attr. in hyperl
Hi,
thanks for the reactions so far.
New version is here: https://matsch.binaervarianz.de/serendi ... le-0.2.zip
Any comments appreciated.
Thanks,
matsch
thanks for the reactions so far.
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.stm999999999 wrote:with your plugin it could be that the real url is not shown to the user anymore.Code: Select all
a href="http://blog.example/exit.php?url=aHR0cDovL2Jsb2cuZGVm" title="http://destination.example" >
Ok, i changed it to use the PEAR HTTP_Request.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.
New version is here: https://matsch.binaervarianz.de/serendi ... le-0.2.zip
Any comments appreciated.
Thanks,
matsch