config['loadBootstrap'] = false; $this->config['cardPosition'] = 'col-md-4 col-sm-6 col-xs-6'; $this->config['cardTitle'] = ''; $this->config['cardText'] = ''; // load custom config if needed if (isset($config['PicoUICard.loadBootstrap'])) { $this->config['loadBootstrap'] = $config['PicoUICard.loadBootstrap']; } if (isset($config['PicoUICard.cssClass.cardPosition'])) { $this->config['cardPosition'] = $config['PicoUICard.cssClass.cardPosition']; } if (isset($config['PicoUICard.cssClass.cardTitle'])) { $this->config['cardTitle'] = $config['PicoUICard.cssClass.cardTitle']; } if (isset($config['PicoUICard.cssClass.cardText'])) { $this->config['cardText'] = $config['PicoUICard.cssClass.cardText']; } } /** * 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.card') !== false) { // below is our comprehensive regex to detect for the full [ui.card] tag, // which includes the tag and its attributes, and the [title] and [text] subtags. $config = $this->config; $content = preg_replace_callback( '/\[ui\.card((\s+[a-z]+\=[\'\"][^\'\"]*[\'\"])*)\s*\]\s*((\[[a-z]+\][^\[]*\[\/[a-z]+\]\s*)*)\[\/ui\.card\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 $uicard = array('href' => '', 'img' => '', 'title' => '', 'text' => ''); for ($i = 0; $i < count($attributes[0]); $i++) { $uicard[ $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 } $uicard[ $subtags[1][$i] ] = $subtags[2][$i]; } $result = '
'; $result .= ''; $result .= '
'; $result .= '
'; $result .= '
'; $result .= $uicard['title']; $result .= '
'; $result .= '
'; $result .= '
'; $result .= ''; $result .= $uicard['text']; $result .= ''; $result .= '
'; $result .= '
'; return $result; }, $content); // now properly combine continous ui cards into same row div $content = preg_replace('/\<\/div\>\<\!\-\-CLOSE_PICO_UI_CARD\-\-\>\s*\<\!\-\-OPEN_PICO_UI_CARD\-\-\>\
/', "\n\n", $content); // now remove the extra comment tags that acted as our search string $content = preg_replace('/\<\!\-\-(OPEN|CLOSE)_PICO_UI_CARD\-\-\>/', '', $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 $output = str_replace('', ($this->buildExtraHeaders() . ''), $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.''; $headers .= PHP_EOL.''; } // now set up card css classes $headers .= ' '; return $headers; } }