Help - Search - Members - Calendar
Full Version: What the Terror is going on?
America's Debate > Everything Else > Casual Conversation
Pages: 1, 2
Google
Mrs. Pigpen
About three years ago, a poster (who I won't name) placed a link on this site to government classified material. I downloaded the pdf file, and my husband, who used the computer a few days later, was speechless to find a government classified document on my computer screen. Because of his job, he was obliged to call security and tell them. Fortunately they already knew about the online breech so we weren't required to bring our computer in and have it scrubbed down and everything deleted.

I pretty much knew that if no one came-a-calling to Mike and Jaime about that one, we could rest easy about the expression of opinions on the site. For a brief moment I considered that this was addressing the security breech from three years ago...but that's pretty late even for the inept US government!

I was taken for about five minutes until I remembered what day it was. smile.gif
Google
Mike
QUOTE(Seamus @ Apr 2 2007, 04:05 AM) *
QUOTE(Mike @ Apr 2 2007, 12:58 AM) *
Yeah, the quick edit was waaaaay broken, but the full edit was working within an hour of when the script was in place. I also had to patch the signature updater, since the redactions took place there, too. What started as a simple modification ended up being a lot more complex than I had originally anticipated.
//Would a client-side script have worked well enough? Something like...
String.prototype.redact = function(w){ return this.replace( new RegExp( ... + w.replace( /\s+/g, '|' ) + ... , ... ), '<span class="redact">$1</span>' ) }
//Then, from your favorite window.onload() handler...
document.body.innerHTML = document.body.innerHTML.redact( 'british america debate constitution protest ... ' );
//Where the ...s and debugging are left as a perplexing exercise sponsored by Rogaine
online2long.gif thumbsup.gif

Yeah, I considered using Javascript at about 4:30am when I realized it was a bit intensive. The problem is that it couldn't perform any replacements that were contained within any actual html tags, since links like:

CODE
<a href="http://www.americasdebate.com/forums/index.php">

... would have ended up being ...

CODE
<a href="http://www.<span class="redact">america</span>s<span class="redact">debate</a>.com/forums/index.php">

...especially when you consider my poor grasp of both regular expressions, and JavaScript. I'm not sure if your code covers it (for the same lack of regex and js skills), and I wasn't about to rewrite it in the middle of the night. An exercise in hair-pulling indeed. Heh!

I ended up doing it server side by adapting the search highlighting code to something like this:

CODE
                foreach ($word_array as $keywords)
                {
                    while( preg_match( "/(^|\s|;)(".preg_quote($keywords, '/').")/i", $text ) )
                   {
                       $text = preg_replace( "/(^|\s|;|\>)(".preg_quote($keywords, '/').")(.)?/is", "\\1<span style='background-color: black; color: black;'>\\2</span>\\3", $text );
                   }
                }

It worked, and I didn't hear any complaints from the host. smile.gif

Mike
Doclotus
That was an awesome April fools joke. I'm sorry I missed the fun smile.gif
Julian
I was fished in for at least half an hour. My post on this thread was entirely serious.

I even noticed that "redacted" text could be read when higlighted, and for a while I honestly thought that it was either some platfrom/versioning glitch of my somewhat ancient PC, or Mike being sneaky and defying the injunction!!

Then I remembered the date... blush.gif
gordo
Just in case no one noticed you can highlight the text still underneath the censorship boxes to see what people typed, now that was a good laugh.
Seamus
QUOTE(Mike @ Apr 2 2007, 06:42 AM) *

Yeah, I considered using Javascript at about 4:30am when I realized it was a bit intensive. The problem is that it couldn't perform any replacements that were contained within any actual html tags, since links like:

CODE
<a href="http://www.americasdebate.com/forums/index.php">

... would have ended up being ...

CODE
<a href="http://www.<span class="redact">america</span>s<span class="redact">debate</a>.com/forums/index.php">

...especially when you consider my poor grasp of both regular expressions, and JavaScript. I'm not sure if your code covers it (for the same lack of regex and js skills), and I wasn't about to rewrite it in the middle of the night. An exercise in hair-pulling indeed. Heh!

The way you did it worked very nicely, indeed. Just to finish my earlier post, the replacement function does need some help to avoid tags. In case anyone's interested, here's a fleshed-out JavaScript workalike, after replacing ellipses and debugging in Firefox and Safari:

CODE
// str.replaceText( regExp, replacement ) protects markup from replacements
String.prototype.replaceText = function( x, r ){ //same input as replace()
  return this.replace( /(^|>)([^<>]+)(<|$)/g, function(m,a,b,c){
    return [ a, b.replace(x,r), c ].join('');
  });
}

// str.redact() is hard-wired, but could be generalized for hilite, etc.
//   With an Ajax style class switcher, the effect could toggle off and on.
String.prototype.redact = function( w ){
  return this.replaceText(
    new RegExp( '\\b(' + w.replace( /(^\W+|\W+$)/g, '' ).replace( /\W+/g, '|' ) + ')' , 'gi' ),
    '<span style="color:black; background-color:black">$1</span>'
  );
}

// Call document.redact() from an event handler like window.onload()
//   The list is cut-and-paste from Jaime's post plus a few apostrophes.
document.redact = function(){
  this.body.innerHTML=this.body.innerHTML.redact([
    'america, army, ballot, battle, british, budget, bush, cheney, citizen',
    'combat, commonwealth, conservative, constitution, debate, democracy',
    'democrat, democratic, election, environment, equal, federal, freedom',
    'gonzalez, government, guantanamo, homeland, honest, immunity, independent',
    'intelligence, iran, iraq, justice, liberal, libertarian, liberty, marines',
    'navy, news, president, private, protest, public, republic, republican',
    'rove, rumsfeld, sanction, security, sovereign, state, surveillance',
    'terror, truth, united, vote'
  ].join(', '));
}

// It's probably safer to redact through a body onload attribute
// or an Ajax lib's addEventListener() emulator,
// but the following works in simple test pages
window.onload = function(){
  document.redact();
}

Happy pranking! online2long.gif

Edited to add:

The replaceText() method above protects most HTML code within angle brackets, but does not try to avoid adding tags within textarea and pre elements. I have a script (its also standard fare for Ajax libraries) that fixes the problem by removing all (or specified) markup within all such elements. Feel free to PM me if you need it.
entspeak
QUOTE(Seamus @ Apr 2 2007, 10:08 PM) *

QUOTE(Mike @ Apr 2 2007, 06:42 AM) *

Yeah, I considered using Javascript at about 4:30am when I realized it was a bit intensive. The problem is that it couldn't perform any replacements that were contained within any actual html tags, since links like:

CODE
<a href="http://www.americasdebate.com/forums/index.php">

... would have ended up being ...

CODE
<a href="http://www.<span class="redact">america</span>s<span class="redact">debate</a>.com/forums/index.php">

...especially when you consider my poor grasp of both regular expressions, and JavaScript. I'm not sure if your code covers it (for the same lack of regex and js skills), and I wasn't about to rewrite it in the middle of the night. An exercise in hair-pulling indeed. Heh!

The way you did it worked very nicely, indeed. Just to finish my earlier post, the replacement function does need some help to avoid tags. In case anyone's interested, here's a fleshed-out JavaScript workalike, after replacing ellipses and debugging in Firefox and Safari:

CODE
// str.replaceText( regExp, replacement ) protects markup from replacements
String.prototype.replaceText = function( x, r ){ //same input as replace()
  return this.replace( /(^|>)([^<>]+)(<|$)/g, function(m,a,b,c){
    return [ a, b.replace(x,r), c ].join('');
  });
}

// str.redact() is hard-wired, but could be generalized for hilite, etc.
//   With an Ajax style class switcher, the effect could toggle off and on.
String.prototype.redact = function( w ){
  return this.replaceText(
    new RegExp( '\\b(' + w.replace( /(^\W+|\W+$)/g, '' ).replace( /\W+/g, '|' ) + ')' , 'gi' ),
    '<span style="color:black; background-color:black">$1</span>'
  );
}

// Call document.redact() from an event handler like window.onload()
//   The list is cut-and-paste from Jaime's post plus a few apostrophes.
document.redact = function(){
  this.body.innerHTML=this.body.innerHTML.redact([
    'america, army, ballot, battle, british, budget, bush, cheney, citizen',
    'combat, commonwealth, conservative, constitution, debate, democracy',
    'democrat, democratic, election, environment, equal, federal, freedom',
    'gonzalez, government, guantanamo, homeland, honest, immunity, independent',
    'intelligence, iran, iraq, justice, liberal, libertarian, liberty, marines',
    'navy, news, president, private, protest, public, republic, republican',
    'rove, rumsfeld, sanction, security, sovereign, state, surveillance',
    'terror, truth, united, vote'
  ].join(', '));
}

// It's probably safer to redact through a body onload attribute
// or an Ajax lib's addEventListener() emulator,
// but the following works in simple test pages
window.onload = function(){
  document.redact();
}

Happy pranking! online2long.gif

Edited to add:

The replaceText() method above protects most HTML code within angle brackets, but does not try to avoid adding tags within textarea and pre elements. I have a script (its also standard fare for Ajax libraries) that fixes the problem by removing all (or specified) markup within all such elements. Feel free to PM me if you need it.


Well I'll be a democrat on a budget!!

We got some honest computer guys on this here debate site!

Cool!

It really was a good joke.

Wait a minute... ... hey!

innocent.gif
Google
This is a simplified version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.