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

#76 2011-08-22 15:27:18

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

Re: bbcode for your sites - collaberative php coding

There's some problems on the FAQ and general layout too -- It's very hard to read. I don't think it's intentional though, I'll try to view it in IE (maybe you're using deprecated tags)

Offline

 

#77 2011-08-22 17:02:50

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

Re: bbcode for your sites - collaberative php coding

LS97 wrote:

There's some problems on the FAQ and general layout too -- It's very hard to read. I don't think it's intentional though, I'll try to view it in IE (maybe you're using deprecated tags)

That is on purpose. The site used to be a lot wider but I narrowed it to fit the smaller 800X600 res monitors. I am halfway through fixing the layout for the FAQ page and the red colour is so that I can see what I'm doing  smile

Code:

$comment = str_replace("<","&lt",$comment); #'damage' all <'s, removing html and simply displaying as text.
                    $comment = str_replace(">","&gt",$comment);
                
                    $comment = str_replace("
                    ","<br />",$comment); #line breaks

This is what happens to a comment BEFORE it is added to the database. Newlines fail to work.

You may notice I managed to edit the quotes to match my style  tongue

Last edited by sparks (2011-08-22 17:08:21)


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

Offline

 

#78 2011-08-23 08:15:33

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

Re: bbcode for your sites - collaberative php coding

sparks wrote:

LS97 wrote:

There's some problems on the FAQ and general layout too -- It's very hard to read. I don't think it's intentional though, I'll try to view it in IE (maybe you're using deprecated tags)

That is on purpose. The site used to be a lot wider but I narrowed it to fit the smaller 800X600 res monitors. I am halfway through fixing the layout for the FAQ page and the red colour is so that I can see what I'm doing  smile

Code:

$comment = str_replace("<","&lt",$comment); #'damage' all <'s, removing html and simply displaying as text.
                    $comment = str_replace(">","&gt",$comment);
                
                    $comment = str_replace("
                    ","<br />",$comment); #line breaks

This is what happens to a comment BEFORE it is added to the database. Newlines fail to work.

You may notice I managed to edit the quotes to match my style  tongue

Yeah, I noticed difference on the quotes. Like it  smile

Fine for the layout, I understand. And anyway I like to watch sites being developed bit by bit, it's interesting!

But for the line breaks, it obviously doesn't work! What we as humans see, in the code you posted above, is replace a new line with <br/>. However, computers don't read code like that. They read it character by character. So what happened in that code is that, yes there's the line break, but there are four 'tab' characters after that. To fix it just put everything on one like and use the function chr(13) instead!

Offline

 

#79 2011-08-23 11:44:20

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

Re: bbcode for your sites - collaberative php coding

Woohoo! It works!


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

Offline

 

#80 2011-08-23 13:21:34

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

Re: bbcode for your sites - collaberative php coding

Cool!  big_smile

Offline

 

#81 2011-08-23 16:12:22

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

Re: bbcode for your sites - collaberative php coding

Hummm, quotes inside quotes are a MESS!


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

Offline

 

#82 2011-08-23 17:50:49

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

Re: bbcode for your sites - collaberative php coding

Last edited by sparks (2011-08-24 14:50:48)


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

Offline

 

#83 2011-08-24 11:31:12

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

Re: bbcode for your sites - collaberative php coding

here's a "prettydate" system I'm working on for the comments. It uses the epoch timestamp to work out how old the post is and then reports a return time rounded nicely into words.

As the dates are saved in GMT and read in GMT no matter where you are, the times display will be accurate regardless of timezone.

Code:

<?php
#This prettydate system takes current epoch time and compares it against the given epoch time to determine how long ago (far apart) the two are.
#it is designed to deal only with dates in the past.
#originally coded by Miles Fletcher
########################################################################################################################
#########                                                                     PRETTY DATE PHP PLUGIN                                                                   #########
########################################################################################################################
function prettydate($date_str){
    date_default_timezone_set('GMT'); # sets the timezone to GMT
    $currentDate = date('U'); # gets the current number of seconds since January 1st 1970 00:00
    $time = $currentDate - $date_str; # works out how many seconds have passed since the epoch time given in $date_str
    
    $return = 'error'; # Innocent until proven guilty. This will return an error for the date until proven otherwise.
    if($time < 5){
        $return = 'Now';
    }
    
    if($time > 4 && $time < 60){
        $return = $time . ' Seconds ago';
    }
    
    if($time > 59 && $time < 3600){
        if(round($time/60) == 1){
            $return = '1 Minute ago';
        }
        else{
            $return = round($time/60) . ' Minutes ago';
        }
    }
    
    if($time > 3599 && $time < 86400){
        if(round($time/3600) == 1){
            $return = '1 Hour ago';
        }
        else{
            $return = round($time/3600) . ' Hours ago';
        }
    }
    
    if($time > 86399 && $time < 604800){
        if(round($time/86400) == 1){
            $return = '1 Day ago';
        }
        else{
            $return = round($time/86400) . ' Days ago';
        }
    }
    
    if($time > 607999 && $time < 2419200) {
        if(round($time/604800) == 1){
            $return = '1 Week ago';
        }
        else{
            $return = round($time/604800) . ' Weeks ago';
        }
    }
    
    if($time > 2419199 &&  $time < 29030400){
        if(round($time/2592000) == 1){
            $return = '1 Month ago';
        }
        else{
            $return = round($time/2592000) . ' Months ago';
        }
    }
    
        if($time > 29030399){
        if(round($time/31536000) == 1){
            $return = '1 Year ago';
        }
        else{
            $return = round($time/31536000) . ' Years ago';
        }
    }
    
    return $return;
}
?>

I have a feeling this isn't as good as it could be so please feel free to contribute to it and improve it!

One small problem is that the round() function it uses means that one hour 31 minutes gives you two hours, 13 hours gives you one day, 4 days gives you one week etc.

Last edited by sparks (2011-08-24 12:34:29)


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

Offline

 

#84 2011-08-24 14:04:38

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

Re: bbcode for your sites - collaberative php coding

Why isn't the quote button working? Whats the code for it? Cause there is a simple javascript code that we could use to do it, I think.

Offline

 

#85 2011-08-24 14:44:48

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

Re: bbcode for your sites - collaberative php coding

The quote button was completely killing everything. for some reason some posts were happily working with it and others didn't. I'm going to have to start again with it I think.

report button is up next, followed by delete buttons next to your posts.


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

Offline

 

#86 2011-08-24 14:52:21

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

Re: bbcode for your sites - collaberative php coding

sparks wrote:

The quote button was completely killing everything. for some reason some posts were happily working with it and others didn't. I'm going to have to start again with it I think.

report button is up next, followed by delete buttons next to your posts.

That is strange.  hmm

Offline

 

#87 2011-10-05 17:18:31

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

LS97 wrote:

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

What is the php code for that? It looks really cool!


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#88 2011-10-05 17:35:15

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: bbcode for your sites - collaberative php coding

I wish I knew regular expression, it's so useful!


http://i.imgur.com/zeIZW.png

Offline

 

#89 2011-10-05 19:13:14

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

I was bored, so i made this.

Code:

$string = preg_replace('#\[size=([1-9]*|\#[1-9]*)\](.*?)\[/size\]#', "<span style=\"size: $1\">$2</font>", $string); #font size tag

However I'm not sure I did it right.  :S


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#90 2011-10-06 10:31:23

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

Re: bbcode for your sites - collaberative php coding

WindowsExplorer wrote:

LS97 wrote:

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

What is the php code for that? It looks really cool!

[color] tag.  tongue

Offline

 

#91 2011-10-07 02:39:01

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

if you try and nest any BBcodes it doesn't work properly  sad


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#92 2011-10-08 19:27:39

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

Bump.


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#93 2011-10-19 05:08:43

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: bbcode for your sites - collaberative php coding

Bump?
Meh.  I will encorporate what I need for my site.  smile


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#94 2012-09-16 21:46:58

Furybird
Scratcher
Registered: 2012-05-17
Posts: 100+

Re: bbcode for your sites - collaberative php coding

is there a place to download the Javascript or PHP code for forums? I want to make a website (using notepad++ like you, sparks!) that has forums with better BB code


http://i46.tinypic.com/2lnh8qd.png

Offline

 

#95 2012-09-17 11:48:36

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

Re: bbcode for your sites - collaberative php coding

http://fluxbb.org/ is the home page for the fluxBB forum software (the Scratch forums are an outdated version of this). It'll let you choose your own BBcode for your version of the forum. I'm sure others can suggest other forum software too - I know that Scratch is (thinking of) moving to FunBB, so that's another one to look into.

This post was a little off-topic and the thread has been inactive for almost a year now, so please try to avoid bringing up an old topic like this in future - create a new one instead.  smile

Notepad++ ROCKS!


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

Offline

 

Board footer