'PrivacyWire Textformatter', 'summary' => "PrivacyWire Textformatter to render privacy options via shortcode [[privacywire-choose-cookies]]", 'author' => 'blaueQuelle', 'href' => "https://github.com/blaueQuelle/privacywire", 'version' => 10, 'requires' => [ "PHP>=7.2", "ProcessWire>=3.0.110" ], ]; } /** * Formats the given $str reference. * Page and Field context are currently not necessary for the formatter to work. * The formatter can be called via format(&$str) or formatValue(Page $page, Field $field, &$value) * formatValue(Page $page, Field $field, &$value) internally calls format(&$str), so the former does not need to be overwritten. * @param mixed $str * @return void */ public function format(&$str) { // Replace privacywire-choose-cookies with button element $tag_search = $this->open_tag . "privacywire-choose-cookies" . $this->close_tag; if (strpos($str, $tag_search) !== false) { $privacyWire = $this->modules->get("PrivacyWire"); // Multi Language Support $lang = ($this->wire('languages') && !$this->wire('user')->language->isDefault()) ? '__' . $this->wire('user')->language->id : ''; $tag_replace = ""; $str = str_replace($tag_search, $tag_replace, $str); } // Optional: enable PrivacyWire support for embedded media if ($this->video_category && (strpos($str, 'www.youtube.com/embed/') !== false || strpos($str, 'www.youtube-nocookie.com/embed/') !== false || strpos($str, 'player.vimeo.com') !== false)) { if (preg_match_all('/\/is', $str, $matches)) { foreach ($matches[0] as $match) { $new_match = str_replace(' src=', ' data-category="' . $this->video_category . '" data-ask-consent=1 data-src=', $match); $str = str_replace($match, $new_match, $str); } } } } }