Source of file StaticSiteUrlProcessor.php
Size: 2,796 Bytes - Last Modified: 2021-12-23T10:34:50+00:00
/var/www/docs.ssmods.com/process/src/code/StaticSiteUrlProcessor.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 | <?php /** * Interface for building URL processing plug-ins for StaticSiteUrlList. * * The URL processing plugins are used to process the relative URL before it it used for two separate purposes: * * - Generating default URL and Title in the external content browser. * - Building content hierarchy. * * For example, MOSS has a habit of putting unnecessary "/Pages/" elements into the URLs, and adding * .aspx extensions. We don't want to include these in the content heirarchy. * * More sophisticated processing might be done to facilitate importing of less */ interface StaticSiteUrlProcessor { /** * Return a name for the style of URLs to be processed. * * This name will be shown in the CMS when users are configuring the content import. * * @return string The name, in plaintext (no HTML) */ public function getName(); /** * Return an explanation of what processing is done. * * This explanation will be shown in the CMS when users are configuring the content import. * * @return string The description, in plaintext (no HTML) */ public function getDescription(); /** * Return a description for this processor, to be shown in the CMS. * @param string $url The unprocessed URL * @return string The name */ public function processURL($url); } /** * Processor for MOSS URLs */ class StaticSiteURLProcessor_DropExtensions implements StaticSiteUrlProcessor { public function getName() { return "Simple clean-up (recommended)"; } public function getDescription() { return "Drop file extensions and trailing slashes on URLs but otherwise leave them the same"; } public function processURL($url) { if (preg_match('/^([^?]*)\?(.*)$/', $url, $matches)) { $url = $matches[1]; $qs = $matches[2]; if ($url != '/') { $url = preg_replace('#/$#', '', $url); } $url = preg_replace('#\.[^.]*$#', '', $url); return "$url?$qs"; } else { if ($url != '/') { $url = preg_replace('#/$#', '', $url); } $url = preg_replace('#\.[^.]*$#', '', $url); return $url; } } } /** * Processor for MOSS URLs */ class StaticSiteMOSSURLProcessor extends StaticSiteURLProcessor_DropExtensions implements StaticSiteUrlProcessor { public function getName() { return "MOSS-style URLs"; } public function getDescription() { return "Remove '/Pages/' from the URL, and drop extensions"; } public function processURL($url) { $url = str_ireplace('/Pages/', '/', $url); return parent::processURL($url); } } |