config['loadBootstrap'] = false; $this->config['cardRatio'] = '16:9'; $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.cardRatio'])) { $this->config['cardRatio'] = $config['PicoUICard.cardRatio']; } 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']; } // some postprocessing of config list($cardWidth, $cardHeight) = explode(':', $this->config['cardRatio']); $this->config['cardHeightMultiplier'] = max(0.01, min(floatval($cardHeight) / floatval($cardWidth), 10)) * 100; } /** * 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' => '', 'ratio' => '', '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]; } if (!empty($uicard['ratio'])) { list($cardWidth, $cardHeight) = explode(':', $uicard['ratio']); $cardRatio = ' padding-bottom: '.(max(0.01, min(floatval($cardHeight) / floatval($cardWidth), 10)) * 100).'%;'; } else { $cardRatio = ''; // default } $result = '