config['loadBootstrap'] = false; $this->config['blurbTitle'] = ''; $this->config['blurbText'] = ''; $this->config['blurbMoreLink'] = ''; // load custom config if needed if (isset($config['PicoUIBlurb.loadBootstrap'])) { $this->config['loadBootstrap'] = $config['PicoUIBlurb.loadBootstrap']; } if (isset($config['PicoUIBlurb.cssClass.blurbTitle'])) { $this->config['blurbTitle'] = $config['PicoUIBlurb.cssClass.blurbTitle']; } if (isset($config['PicoUIBlurb.cssClass.blurbText'])) { $this->config['blurbText'] = $config['PicoUIBlurb.cssClass.blurbText']; } if (isset($config['PicoUIBlurb.cssClass.blurbMoreLink'])) { $this->config['blurbMoreLink'] = $config['PicoUIBlurb.cssClass.blurbMoreLink']; } } /** * Triggered after Pico has prepared the raw file contents for parsing * * @see Pico::parseFileContent() * @see DummyPlugin::onContentParsed() * @param string &$content prepared file contents for parsing * @return void */ public function onContentPrepared(&$content) { // we only do any processing at all if the page contains our tag, so we save time if (strpos($content, '[ui.blurb') !== false) { // below is our comprehensive regex to detect for the full [ui.blurb] tag, // which includes the tag and its attributes, and the [title] and [text] subtags. $config = $this->config; $content = preg_replace_callback( '/\[ui\.blurb((\s+[a-z]+\=[\'\"][^\'\"]*[\'\"])*)\s*\]\s*((\[[a-z]+\][^\[]*\[\/[a-z]+\]\s*)*)\[\/ui\.blurb\s*\]/', function ($matches) use ($config) { // $matches[1] contain the list of attributes // $matches[3] contain the list of subtags preg_match_all('/\s*([a-z]+)\=[\'\"]([^\'\"]*)[\'\"]/', $matches[1], $attributes); preg_match_all('/\[([a-z]+)\]([^\[]*)\[\/([a-z]+)\]\s*/', $matches[3], $subtags); // look for what we want from attributes and subtags $uiblurb = array('href' => '', 'img' => '', 'imgpos' => '', 'title' => '', 'text' => '', 'more' => ''); for ($i = 0; $i < count($attributes[0]); $i++) { $uiblurb[ $attributes[1][$i] ] = $attributes[2][$i]; } for ($i = 0; $i < count($subtags[0]); $i++) { if ($subtags[1][$i] != $subtags[3][$i]) { continue; // closing subtag must match in order to be valid } $uiblurb[ $subtags[1][$i] ] = $subtags[2][$i]; } $result = '
'; if ($uiblurb['imgpos'] != 'right') { $result .= '
'; $result .= ''; $result .= '
'; } $result .= '
'; $result .= ''; $result .= $uiblurb['title']; $result .= ''; $result .= ''; $result .= $uiblurb['text']; $result .= ''; $result .= ''; $result .= $uiblurb['more']; $result .= ''; $result .= '
'; if ($uiblurb['imgpos'] == 'right') { $result .= '
'; $result .= ''; $result .= '
'; } $result .= '
'; return $result; }, $content); } } /** * Triggered after Pico has rendered the page * * @param string &$output contents which will be sent to the user * @return void */ public function onPageRendered(&$output) { // regular pages // add css to end of $output = str_replace('', ($this->buildExtraHeaders() . ''), $output); // add js to end of $output = str_replace('', ($this->buildExtraFooters() . ''), $output); } /** * Add some extra header tags for our styling. */ private function buildExtraHeaders() { $headers = ''; // if set to true, load from bootstrap cdn if ($this->config['loadBootstrap'] === true) { $headers .= PHP_EOL.''; } // now set up blurb css classes $headers .= ' '; return $headers; } /** * Add some extra footer tags we need. */ private function buildExtraFooters() { $footers = ''; // if set to true, load from bootstrap cdn if ($this->config['loadBootstrap'] === true) { $footers .= PHP_EOL.''.PHP_EOL; } return $footers; } }