This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#51 2011-08-20 05:29:37

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

OK, after a couple escape backslashes and adding hexadecimal color support (I'd forgotten colors can go up to FF and not 99) I got the code.

Here's the updated example, and below is the code for just colors:

Code:

$string = preg_replace('#\[colou?r=([a-zA-Z]*|\#[0-9a-fA-F]*)\](.*?)\[/colou?r\]#', "<span style=\"color: $1\">$2</font>", $string); #font colour tag

I also allowed both color and coloUr, for the british.  smile

Right, now a 4 hour hike...  hmm

Offline

 

#52 2011-08-20 08:50:39

gbear605
Scratcher
Registered: 2008-03-06
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

Ok, we should just make a scratchers forum at this rate  tongue


Yeah, I'm mostly inactive.  I check in once in a while though.  If you want to contact me, I have a contact form at my website, http://escratch.org

Offline

 

#53 2011-08-20 15:49:47

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

That's pretty cool! Good stuff!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#54 2011-08-20 15:56:37

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

This is really good and exciting! :3

Offline

 

#55 2011-08-22 05:17:34

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

Great, this is coming along nicely, what I need is a way to grab an image link, work out the width of an image and scale the image down so it does not overflow the comment boundries... I know how to measure the width and shrink it but not how to pull it from the comment...


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#56 2011-08-22 05:51:45

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

sparks wrote:

Great, this is coming along nicely, what I need is a way to grab an image link, work out the width of an image and scale the image down so it does not overflow the comment boundries... I know how to measure the width and shrink it but not how to pull it from the comment...

Easy! Just do some CSS styling. New image replace code:

Code:

$string = preg_replace('#\[img\]([^\[]*?)\[/img\]#', "<img src=\"$1\" style=\"max-width: 500px;\"/>", $string); #img tag

That will keep the image inside 500 pixels. Adjust at your liking.

By the way, when are you going to update the code in the first post?

Offline

 

#57 2011-08-22 05:54:35

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

Good idea, I shall do that now. Erm, could you post your most recent? I don't think you posted it, just a link to a working example!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#58 2011-08-22 05:57:28

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

sparks wrote:

Good idea, I shall do that now. Erm, could you post your most recent? I don't think you posted it, just a link to a working example!

Actually I did, but it's all over the place. A neat version coming up soon, with some updates  smile

Last edited by LS97 (2011-08-22 06:00:16)

Offline

 

#59 2011-08-22 06:07:06

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

Where did mine go?
Also, [quote] doesn't work.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#60 2011-08-22 06:07:44

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

Hardmath123 wrote:

Where did mine go?
Also, [quote] doesn't work.

No, duh  roll
It's not in the code.

Offline

 

#61 2011-08-22 06:10:01

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

Great, I'm in the middle of preparing my own commenting system to take the bbcode system and I'm thinking a neat little addon would be a "contains bbcode?" function as it would allow me to better moderate my site.

What I did with my commenting system which may sound obvious, idk, but works really well is put the commenting box and displayed posts on a single page and php include() it wherever it's needed which means it does not need to be updated everywhere it's used, just once! Then each page simple needs the code

Code:

<?php
$commentName = 'id for this comment';
include("commentspace.php");
?>

and then it's there!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#62 2011-08-22 06:11:24

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

Hardmath, yours is amazing, but it's better suited to live displaying of bbcode to HTML - it wasn't working very well in terms of pulling the html and inserting it anywhere  hmm  It's very impressive, LS97's is simple better suited to this particular application  smile

[offtopic]Is it me or is the advanced topic forum the least moderated of the lot? There are very few moderator posts and I can't count the number of times people have shared emails in posts without them being removed... I guess its because this forum is a relatively responsible one so what little does need moderating is reported anyway...

Last edited by sparks (2011-08-22 06:14:50)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#63 2011-08-22 06:15:36

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

Ah, but I thought PHP could handle that. Can't you get the contents of a <div> element with it? If you can, the problem should be solved.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#64 2011-08-22 06:17:08

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

Hardmath123 wrote:

Ah, but I thought PHP could handle that. Can't you get the contents of a <div> element with it? If you can, the problem should be solved.

It was possible but it was a very inneficient way to do it, adding a hidden div and pulling the content wasn't working without a lot of code to do it...


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#65 2011-08-22 06:20:21

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

I put the code together finally, and also added quote boxes  big_smile

Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>BBCode Comment Example</title>
</head>

<body>
<?php
if(isset($_POST['submit'])){
$string = $_POST['comment'];
$string = str_replace("<","&lt",$string); #'damage' all <'s, removing html and simply displaying as text.
$string = str_replace(">","&gt",$string);

$string = str_replace("
","<br />",$string); #line breaks

$string = preg_replace('#\[img\]([^\[]*?)\[/img\]#', "<img src=\"$1\" style=\"max-width: 500;\"/>", $string); #img tag

$string = preg_replace('#\[url\]([^\[]*?)\[/url\]#', "<a href=\"$1\">$1</a>", $string); #simple url tag
$string = preg_replace('#\[url=([^\[]+?)\](.*?)\[/url\]#', "<a href=\"$1\">$2</a>", $string); #complex url tag

$string = preg_replace('#\[quote\]([^\[]*?)\[/quote\]#', "<table width=\"90%\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\"><tr border=\"1\" style=\"background-color:#EEE; border-color: #888;\"><td>$1</td></tr></table>", $string); #simple quote tag

$string = preg_replace('#\[quote=([^\[]+?)\](.*?)\[/quote\]#', "<table width=\"90%\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\"><tr border=\"1\" style=\"background-color:#EEE; border-color: #888; border-width: 1px;\"><td><strong>$1 wrote:</strong><br />$2</td></tr></table>", $string); #complex quote tag

$string = preg_replace('#\[colou?r=([a-zA-Z]*|\#[0-9a-fA-F]*)\](.*?)\[/colou?r\]#', "<span style=\"color: $1\">$2</font>", $string); #font colour tag

$string = preg_replace('#\[b\](.*?)\[/b\]#ms', "<strong>$1</strong>", $string); #bold
$string = preg_replace('#\[i\](.*?)\[/i\]#ms', "<em>$1</em>", $string); #italics
$string = preg_replace('#\[u\](.*?)\[/u\]#ms', "<span style=\"text-decoration: underline\">$1</span>", $string); #underline

echo "<table width=\"500\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\"><tr>";
echo "<td border=\"2\" width=\"500px\" style=\"background-color:#FFA; border-color: #333;\">";
echo $string;
echo "</td></tr></table>
<br />";
}
?>

<form name = 'comment' action = '<?php echo $_SERVER['REQUEST_URI'] ?>' method = 'post'>
  <textarea name = 'comment' rows = '10' cols = '50'><?php if(isset($string)){ echo $_POST['comment']; }?></textarea>
  <br />
<input type = 'submit' name = 'submit' value = 'comment'>
</form>
</body>
</html>

This is the exact code that's present on the example page  smile

Offline

 

#66 2011-08-22 06:22:33

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

Little problem: quote boxes glitch when used more than once inside each other.

Last edited by LS97 (2011-08-22 06:22:58)

Offline

 

#67 2011-08-22 06:28:44

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

Alright, first post updated!

In my commenting system I was planning to provide uneditable quoting to stop people misquoting - is that a good idea or not?


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#68 2011-08-22 06:31:59

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

Oh! Loving the linebreak addition! My current system couldn't do it!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#69 2011-08-22 06:32:33

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

sparks wrote:

Alright, first post updated!

In my commenting system I was planning to provide uneditable quoting to stop people misquoting - is that a good idea or not?

You mean like [quote=#502056]or something? I don't know... that also means that you can't edit out a long post or something.

Offline

 

#70 2011-08-22 06:43:25

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

LS97 wrote:

sparks wrote:

Alright, first post updated!

In my commenting system I was planning to provide uneditable quoting to stop people misquoting - is that a good idea or not?

You mean like [quote=#502056]or something? I don't know... that also means that you can't edit out a long post or something.

That's true, I may use my newfound javascript knowledge to simple have the same quoting style as here...

Added the system to my commenting! here. Newlines still don't work....


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#71 2011-08-22 06:58:37

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

Glitches I found with this code:

Code:

Let's [i]see[/i], does this [b]work[/b]? [url]wiki.scratch.mit.edu[/url]
[b][url=wiki.scratch.mit.edu]AWESOMEST WIKI I KNOW[/url]!!![/b]

It put a \ before the apostrophe, it linked to http://accidentalgames.com/wiki.scratch.mit.edu rather than checking if it has a supported protocol, and if not, add the HTTP one.

Offline

 

#72 2011-08-22 07:44:16

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

Okay, thanks sci.

I think your image size limiter does not work btw, LS97


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#73 2011-08-22 08:08:44

gbear605
Scratcher
Registered: 2008-03-06
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

I think the reason the forum is so lowly modded, is they trust everyone here, and they know that we would just report posts, plus the newscratchers just don't post here.  Also spammers are going to post in the most popular forum (misc)


Yeah, I'm mostly inactive.  I check in once in a while though.  If you want to contact me, I have a contact form at my website, http://escratch.org

Offline

 

#74 2011-08-22 09:06:41

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

sparks wrote:

Okay, thanks sci.

I think your image size limiter does not work btw, LS97

Could be. I never actually tested that code. And sparks, just to point out a couple flaws on accidentalgames:

on http://www.accidentalgames.com/register.php you wrote at the bottom of the page that "* these details are not displayed on the website. None of the details you have given will be passed on or sold to any third-parties." but passwords don't have asterisks  lol

on http://www.accidentalgames.com/termsAndConditions.php you should add 'your' to the definitions on the first line, since it's used further down.

Otherwise the site's amazing. I'd never actually seen it before!  tongue

Offline

 

#75 2011-08-22 09:21:48

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

Thanks LS97, on our Privacy policy page the password is marked as something not passed on but you're right, it should be *'d on the register page.

I'm glad you like the site though! It took a lot of work  smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

Board footer