boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Auto convert your friend's names into links
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
imeridian



Joined: 12 Feb 2002
Posts: 191

PostPosted: Mon Sep 30, 2002 1:17 am    Post subject: Reply with quote

Hah! $15 is a bargain... I charge $65 an hour with a minimum of a half hour for *Anything* Smile
Back to top
View user's profile Send private message Visit poster's website
Gadget Girl



Joined: 25 Jan 2002
Posts: 305
Location: Virginia

PostPosted: Mon Sep 30, 2002 1:33 am    Post subject: Reply with quote

Hi Indi Smile I remember you from the GM and weren't you on the MT boards~good to see you over here.

Yeah, $15 is a bargin, it's hard when you are first starting out. I guess I can't use that line any more eh?

Sara
Back to top
View user's profile Send private message
imeridian



Joined: 12 Feb 2002
Posts: 191

PostPosted: Mon Sep 30, 2002 1:37 am    Post subject: Reply with quote

I only go to the MT boards to complain about how their script wrecks servers by hanging up... or causing dependencies on perl module versions... and otherwise creating administrative havoc for me... *Grumbles*
Back to top
View user's profile Send private message Visit poster's website
annia



Joined: 09 Apr 2002
Posts: 18

PostPosted: Wed Oct 02, 2002 10:50 am    Post subject: Reply with quote

i think the hack is very easy to install.. :? where is the problem?
Back to top
View user's profile Send private message
Gadget Girl



Joined: 25 Jan 2002
Posts: 305
Location: Virginia

PostPosted: Wed Oct 02, 2002 7:41 pm    Post subject: Reply with quote

*LOL* Indi!

Thanks Annia, I thought it was too~

Smile Sara
Back to top
View user's profile Send private message
annia



Joined: 09 Apr 2002
Posts: 18

PostPosted: Sat Oct 19, 2002 5:31 pm    Post subject: Reply with quote

eeewww.. i just found a bug in this hack.. if you write a link containing your friend's name like

Quote:

<a href="http://www.domain.com/friend/index.html>


it converts it to

Code:
<a href="http://www.domain.com/<a href=http://friend.com>friend</a>/index.html>


u know what I mean?? :( can anyone help with that bug?
Back to top
View user's profile Send private message
Aryana



Joined: 19 Oct 2002
Posts: 18

PostPosted: Sun Oct 20, 2002 12:48 am    Post subject: Reply with quote

Wow, that's really cool annia. Thanks =)

Hm... would that really be a problem? I mean, why would you even have your friend's name in a link other than the auto-link?
Back to top
View user's profile Send private message Visit poster's website
michel v
Site Admin


Joined: 25 Jan 2002
Posts: 799
Location: Corsica

PostPosted: Sun Oct 20, 2002 2:36 am    Post subject: Reply with quote

Annia, that's because your code (and the original smilies code) doesn't check that we're not between < and > before it converts stuff.
That would require regular expressions, and I'm planning on adding that transparently in later versions.

In fact, I'm coding a little script to convert stuff into tags, and that should be a generic script to handle smilies, friends' names, acronyms etc. It's still in the debug stage, as the regex seems to be a bit too greedy at the moment. It does, however, check that we're not between < and > when converting, to avoid disasters.
It might be available as a "filter" for b2 0.x or built-in for 1.x.

It handles data in this form (could read it from a file or a string):
Quote:
"Michel" a href "http://tidakada.com"
":)" img src "b2-img/smilies/smile.jpg"
"CSS" acronym title "Cascading Style Sheets"
...
"text" tag attribute "value"

For example, last line tells it to convert text into <tag attribute="value">text</tag>.
Of course it'd handle exceptions for self-closing tags.
(It's actually a PHP version of this MT/Perl macro.)
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
Aryana



Joined: 19 Oct 2002
Posts: 18

PostPosted: Thu Oct 24, 2002 2:08 am    Post subject: Reply with quote

Cine wrote:
Ish ok. I have tried to install it many times but it won't work.. I just wondered if you could zip the files used, when the code is pasted and send them to me?


It didn't work for me either... and I'm sure I pasted everything correctly. Their names just appear as normal text.

Cine, using another person's files could mess up your B2 because you don't know what else they have changed in their files.
Back to top
View user's profile Send private message Visit poster's website
Gadget Girl



Joined: 25 Jan 2002
Posts: 305
Location: Virginia

PostPosted: Thu Oct 24, 2002 2:55 am    Post subject: Reply with quote

Aryana, I'm sorry you had a problem with the tutorial! I thought I wrote it so it was easy to paste and figure out what went where!

Sara
Back to top
View user's profile Send private message
Aryana



Joined: 19 Oct 2002
Posts: 18

PostPosted: Thu Oct 24, 2002 5:22 am    Post subject: Reply with quote

It's probably a problem with my main index.
Back to top
View user's profile Send private message Visit poster's website
allusion



Joined: 16 Jun 2002
Posts: 73
Location: Houston

PostPosted: Sat Oct 26, 2002 6:55 pm    Post subject: Reply with quote

Michael that would be extremely powerful. Is any of the code in the CVS yet? How far along are you?
Back to top
View user's profile Send private message Visit poster's website AIM Address
michel v
Site Admin


Joined: 25 Jan 2002
Posts: 799
Location: Corsica

PostPosted: Sat Oct 26, 2002 11:37 pm    Post subject: Reply with quote

Not very far.
In fact it works as expected on text that doesn't have html tags in it. Once I put html, it start fucking up, putting little <=""></> strings around.
I'll probably ask help for it on sitepointforums.com, if I don't have it working tomorrow.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
michel v
Site Admin


Joined: 25 Jan 2002
Posts: 799
Location: Corsica

PostPosted: Mon Oct 28, 2002 4:55 am    Post subject: Reply with quote

OK, the code is there:
[php:1:f43f48134a]<?php

$tagifylist = trim('

"AOL" acronym title "America Online"
"API" acronym title "Application Interface"
"CGI" acronym title "Common Gateway Interface"
"CMS" acronym title "Content Management System"
"CSS" acronym title "Cascading Style Sheets"
"DNS" acronym title "Domain Name System"
"DOM" acronym title "Document Object Model"
"DTD" acronym title "Document Type Definition"
"DVD" acronym title "Digital Video Disc"
"FAQ" acronym title "Frequently Asked Questions"
"FOAF" acronym title "Friend of a Friend vocabulary"
"FSF" acronym title "Free Software Foundation"
"GFDL" acronym title "GNU Free Documentation License"
"GPL" acronym title "GNU General Public License"
"HDTV" acronym title "High Definition TeleVision"
"IE" acronym title "Internet Explorer"
"IIRC" acronym title "if I remember correctly"
"IIS" acronym title "Internet Infomation Server"
"JSP" acronym title "Java Server Pages"
"KB" acronym title "kilobytes"
"KDE" acronym title "K Desktop Environment"
"HTML" acronym title "HyperText Markup Language"
"LGPL" acronym title "GNU Lesser General Public License"
"MB" acronym title "megabyte"
"MSDN" acronym title "Microsoft Developer Network"
"MSIE" acronym title "Microsoft Internet Explorer"
"MSN" acronym title "Microsoft Network"
"OPML" acronym title "Outline Processor Markup Language"
"P2P" acronym title "Peer To Peer"
"PBS" acronym title "Public Broadcasting System"
"PDF" acronym title "Portable Document Format"
"PHP" acronym title "PHP Hypertext Processor"
"RDF" acronym title "Resource Description Framework"
"RSS" acronym title "Rich Site Summary"
"SOAP" acronym title "Simple Object Access Protocol"
"SSN" acronym title "Social Security Number"
"URL" acronym title "Uniform Resource Locator"
"VNC" acronym title "Virtual Network Computing"
"W3C" acronym title "World Wide Web Consortium"
"WCAG" acronym title "Web Content Accessibility Guidelines"
"WYSIWYG" acronym title "what you see is what you get"
"XHTML" acronym title "eXtensible HyperText Markup Language"
"XML" acronym title "eXtensible Markup Language"
"XSL" acronym title "eXtensible Stylesheet Language"
"XSLT" acronym title "eXtensible Stylesheet Language Transformation"

');

function tagifythis($text) {
global $tagifylist, $cache_tagifylist;

/* let's build an array of searches and replaces from
$tagifylist so that we don't have to regex match
everything every time we call this function */
if (empty($cache_tagifylist)) {
$tagifylist = explode("\n", $tagifylist);
foreach ($tagifylist as $tag_item) {
preg_match('#^"(.+?)"\s+(\w+)(.*)#', $tag_item, $blah);
$tag_match = $blah[1];
$tag_tag = $blah[2];
$tag_item = $blah[3];
preg_match_all('#\s(\w+)\s+"(.+?)"#', $tag_item, $blah, PREG_SET_ORDER);
$tag_attributes = '';
foreach($blah as $attribute) {
$tag_attributes .= ' '.$attribute[1].'="'.$attribute[2].'"';
}
$tag_match = '#>([^<]{0,})([^a-zA-Z0-9]{1})('
.preg_quote($tag_match)
.')([^a-zA-Z0-9]{1})([^>]{0,})<#';
$tag_replace = '>$1$2<'.$tag_tag.$tag_attributes.'>$3</'.$tag_tag.'>$4$5<';
if (strlen($tag_match)) {
$cache_tagifylist[] = array($tag_match, $tag_replace);
}
}
}

/* let's dance! */
foreach ($cache_tagifylist as $tag_item) {
$match = $tag_item[0];
$replace = $tag_item[1];
$text = '> '.$text.' <';
$text = preg_replace($match, $replace, $text, 1);
$text = substr($text, 1, -1);
}

return($text);
}

?>[/php:1:f43f48134a]

There are three (ok, two and a half) outstanding issues remaining.
1. It won't convert a string that is right between tags, like <i>CSS</i>, but it will convert <i> CSS </i> just fine.
2. On my server at least, it converts only the last match, instead of the first match.
3. I got lazy and forgot to put support for self-closing tags.

Other than that, it just works. You can see it in action on my blog.

The TODO list:
1. Fix the above three issues (number 3 should be quick).
2. Make it so that it won't convert a string into a tag if it's already surrounded by that tag (to avoid double <acronym><acronym> stuff for example, or double <a><a> links).

--
You can apply this function as a filter on your blog, if you are running the CVS version of b2.
It is quite simple, just open your template and paste this anywhere before the loop:
[php:1:f43f48134a]<?php
include('tagifythis.php');
add_filter('the_content', 'tagifythis');
?>[/php:1:f43f48134a]
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
sidcarter



Joined: 18 Sep 2002
Posts: 8

PostPosted: Sun Nov 17, 2002 12:43 pm    Post subject: Bugs Fixed ? Reply with quote

Hi michel,

Have the bugs been fixed ? is the tagifythis.php file in CVS now ?

TIA
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Hacks All times are GMT + 1 Hour
Goto page Previous  1, 2, 3, 4  Next
Page 2 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group