Automad = $Automad; $this->InPage = $InPage; } /** * Run all required post-process steps. * * @param string $output * @return string the final output */ public function process(string $output): string { $output = $this->createExtensionAssetTags($output); $output = $this->addMetaTags($output); $output = $this->obfuscateEmails($output); $output = $this->resizeImages($output); $output = Blocks::injectAssets($output); $output = $this->addCacheBustingTimestamps($output); $output = URLProcessor::resolveUrls($output, 'absoluteUrlToRoot'); $output = $this->InPage->createUI($output); return $output; } /** * Find all locally hosted assests and append a timestamp in order to avoid serving outdated files. * * @param string $str * @return string the processed output */ private function addCacheBustingTimestamps(string $str): string { $extensions = implode('|', FileUtils::allowedFileTypes()); return preg_replace_callback( '#(?<=")/[/\w\-\.]+\.(?:' . $extensions . ')(?=")#is', function ($matches) { $file = AM_BASE_DIR . $matches[0]; if (strpos($file, AM_DIR_CACHE . '/') !== false || !is_readable($file)) { return $matches[0]; } return $matches[0] . '?m=' . filemtime($file); }, $str ); } /** * Add meta tags to the head of $str. * * @param string $str * @return string The meta tag */ private function addMetaTags(string $str): string { $meta = ''; if (AM_FEED_ENABLED) { $sitename = $this->Automad->Shared->get(Fields::SITENAME); $meta .= ''; } return str_replace('', '' . $meta, $str); } /** * Create the HTML tags for each file in the asset collection and prepend them to the closing tag. * * @param string $str * @return string The processed string */ private function createExtensionAssetTags(string $str): string { $assets = AssetCollection::get(); Debug::log($assets, 'Assets'); $html = ''; if (isset($assets['.css'])) { foreach ($assets['.css'] as $file) { $html .= ''; Debug::log($file, 'Created tag for'); } } if (isset($assets['.js'])) { foreach ($assets['.js'] as $file) { $html .= ''; Debug::log($file, 'Created tag for'); } } // Prepend all items ($html) to the closing tag. return str_replace('', $html . '', $str); } /** * Obfuscate all stand-alone eMail addresses matched in $str. * Addresses in links are ignored. * * @param string $str * @return string The processed string */ private function obfuscateEmails(string $str): string { $regexEmail = '[\w\.\+\-]+@[\w\-\.]+\.[a-zA-Z]{2,}'; // The following regex matches all email links or just an email address. // That way it is possible to separate email addresses // within tags from stand-alone ones. $regex = '/(]*href="mailto.+?<\/a>|(?P' . $regexEmail . '))/is'; return preg_replace_callback($regex, function ($matches) { // Only stand-alone addresses are obfuscated. if (!empty($matches['email'])) { Debug::log($matches['email'], 'Obfuscating'); $html = ""; $html .= strrev($matches['email']); $html .= '‎'; return $html; } else { Debug::log($matches[0], 'Ignoring'); return $matches[0]; } }, $str); } /** * Resize any image in the output in case it has a specified size as query string like * for example "/shared/image.jpg?200x200". * * @param string $str * @return string The processed string */ private function resizeImages(string $str): string { return preg_replace_callback( '/(\/[\w\.\-\/]+(?:jpg|jpeg|gif|png|webp))\?(\d+)x(\d+)/is', function ($match) { $file = AM_BASE_DIR . $match[1]; if (is_readable($file)) { $image = new Image($file, floatval($match[2]), floatval($match[3]), true); return $image->file; } return $match[0]; }, $str ); } } __halt_compiler();----SIGNATURE:----p1lxN5zgshPlKSP9hIZX+19bWD8Dp/9MK0qhzudHcR69CrtzOnSAz7TtqhlyHLnZ/hzAolIwxK/1EUtzlpgtSFkMj+UpENDszJZo6Z9BWeVmRu2M7plIjPA+OXBLKC+kx0lK4ZWWl2nCUmf0VVX1OZboPYU4eH/XlCC0BQbtR+KIVMwZJVx7UGyDweisU720RY8aez/Z+SyN1CVMNhuD12oPZYd/Yk1Aj70rkH4g/LG9YeuK0gi1n7G3/jCbuJAz6nSjwcvaVC1CVUsxC1av/2ROBQ8BmIYkS3iG0jkjXF3iiIJDzjZ3VbPWzv2M57nxCBZgMb9UxxeoSGeKC9DD8wkXyI9/cIgJFv4rXOxdLwmg53WBB3kkgYsV3MzuWQYUZJv2oEZ8F5bFZ4Qkc0Hg4SqHcD8m7dO9G3NnvpCAoT25wV1spsXs2eofQ0HRyYMZ0pkC26n5R/Bni2a5oMe7ZRPQjefMI/H0OILDpMPMiEPTYvltCJnp2CXtqIk6zmpKHRJrj1vw9Kv+pEsPUL15eLDgx4jEsU1IjTw4JcM1BX3El07QCrMtPGVSAHStDod4rwy7G9+e22bZgPEAoJQmSzVwIkzHsOapQy1SuCNkZe52rfHPtoGT2U3woanU5Z9OfIr4IE+APQP6K1JbDeKqBnhd0uAzNuXf76c/jCIV2Cw=----ATTACHMENT:----NzI1Mzg2OTc3ODY2MjUyNiA2Nzc5MDE3MDAzMDQ3MDAyIDUxMzg2NjI2NzU2MjQ2NjQ=