Welcome, Guest. Please login or register.

Author Topic: Quiet  (Read 6450 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Quiet
« on: February 02, 2010, 09:12:50 PM »
Quote from: motorollin;541203
It seems a bit quiet round here these days. Where is everyone? Bloodline? Adz? Speel? Gadge? Karlos? Oh wait, Karlos is buried under a great big pile of PHP. ;)


It's worse than that, it's about 50% php and 50% PCRE.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Quiet
« Reply #1 on: February 02, 2010, 10:18:36 PM »
Quote from: motorollin;541236
Sounds bloody ghastly :lol:


Well, at least it's clean conceptually:



The PCRE is in the implementation of process() for the various XXXXRewriter classes above. Some of it is... well, nasty :)
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Quiet
« Reply #2 on: February 02, 2010, 10:35:01 PM »
Quote from: motorollin;541248
There I was thinking you just had a massive list of of str_replace($css_code, $html_code, $aorg_code) ;)

I do*, they are just inside the various MarkupRewriter::process() implementations.

*except they're mostly preg_replace() / preg_replace_callback()

Also, I never tackle anything I can't draw a picture of first :lol:
« Last Edit: February 02, 2010, 10:59:32 PM by Karlos »
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Quiet
« Reply #3 on: February 04, 2010, 12:34:43 AM »
As an actual example, the following class converts the CSS popup menu you get against the post name into a HTML select list that contains the same options.

Code: [Select]
class PostMenuRewriter implements MarkupRewriter {
  public function process($markupText)
  {
    $this->postMenu = array();
    // replace the hidden <div> containing the post menu and get the options
    $markupText = preg_replace_callback(
      '@<!-- post ([0-9]+) popup menu -->.*?<!-- / post [0-9]+ popup menu -->@s',
      array(&$this, 'reworkPostMenu'),
      $markupText
    );
    // replace the inline <script> that binds the menu to the post and replace with options
    $markupText = preg_replace_callback(
      '@<script\s+type=&quot;text/javascript&quot;>\s+vbmenu_register\(&quot;postmenu_([0-9]+)&quot;,\s+true\);\s+</script>@',
      array(&$this, 'insertMenu'),
      $markupText
    );
    $this->postMenu = null;
    return $markupText;
  }

  private function reworkPostMenu($matches)
  {
    // called in pass 1: grab the post menu options and store them by post Id for pass 2
    $postId = $matches[1];
    $markupText=str_replace('rel=&quot;&quot;nofollow&quot;&quot;,'',$matches[0]);
    $matches=array();
    preg_match_all(
      '@<a href=&quot;&quot;(.*?)&quot;\s*>(.*?)</a>@&quot;,
      $markupText,
      $matches
    );
    $content = '<select onchange=&quot;if(this.value!=\'\'){window.location=this.value;}&quot;><option value=&quot;&quot; selected>-- choose action --</option>';
    foreach($matches[1] as $n => $url) {
      $content .= '<option value=&quot;' . $url . '&quot;>' . $matches[2][$n] . '</option>';
    }
    $content .= '</select>';
    $this->postMenu[$postId] = $content;
    return '';
  }

  private function insertMenu($matches)
  {
    // called in pass 2: replace the redundant postmenu_XXX inline script with our select list menu
    $postId = $matches[1];
    return $this->postMenu[$postId];
  }

  private $postMenu = array();
}
« Last Edit: February 04, 2010, 12:50:15 AM by Karlos »
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Quiet
« Reply #4 on: February 04, 2010, 04:04:22 PM »
Quote from: the_leander;541526
Sorry for being away, been rather busy setting up (and now currently going through) a course so as to get my SIA licence.

Passed both my Maths and English preliminary exams today, having a crack at a tougher version of the English one tomorrow for fun as the SIA practical stuff doesn't start till next week. Should be interesting.


Good luck mate!

Quote
I guess it'll mean that I'll be buying in the next curry, eh lads?


:afro:
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Quiet
« Reply #5 on: February 10, 2010, 12:45:16 AM »
Quote from: GadgetMaster;542178
Still alive and kicking.

Gadget.


That's good to know :D
int p; // A