コード例 #1
0
ファイル: common.php プロジェクト: nrueckmann/yeager
function createSpecialURLfromShortURL($shortURL)
{
    $siteMgr = new Sites();
    $webRoot = rtrim(ltrim((string) sConfig()->getVar("CONFIG/DIRECTORIES/WEBROOT"), '/'), '/');
    $shortURL = urldecode($shortURL);
    // Remove webroot prefix, if present
    if (strlen($webRoot) && strpos($shortURL, $webRoot) === 0) {
        $shortURL = substr($shortURL, strlen($webRoot . '/'));
    }
    if (strlen($webRoot) && strpos($shortURL, '/' . $webRoot) === 0) {
        $shortURL = substr($shortURL, strlen('/' . $webRoot . '/'));
    }
    $urlArray = explode('/', ltrim(rtrim($shortURL, '/'), '/'));
    $fileMgr = sFileMgr();
    switch (strtolower($urlArray[0])) {
        case 'image':
            $specialType = 'IMG';
        case 'download':
            if (!$specialType) {
                $specialType = 'DOWN';
            }
            // Check for file
            $fileID = $fileMgr->getFileIdByPname($urlArray[1]);
            if ($fileID) {
                $specialURL = '§§LINKTO:' . $specialType . ':' . $fileID . '§§';
                if (count($urlArray) > 2) {
                    array_shift($urlArray);
                    array_shift($urlArray);
                    $specialURL .= '/' . implode('/', $urlArray);
                }
                return $specialURL;
            }
            break;
        default:
            // Check for page
            $siteInfo = $siteMgr->getByPName($urlArray[0]);
            if ($siteInfo) {
                $pageMgr = new PageMgr($siteInfo['ID']);
                $lastElement = $urlArray[count($urlArray) - 1];
                if (substr($lastElement, 0, 1) == ':') {
                    $lastElement = $urlArray[count($urlArray) - 2];
                    $suffix = '/' . $urlArray[count($urlArray) - 1];
                }
                $pName = $lastElement;
                $pageID = $pageMgr->getPageIdByPname($pName);
                if ($pageID) {
                    $specialURL = '§§LINKTO:PAGE:' . $siteInfo['ID'] . ':' . $pageID . '§§' . $suffix;
                    return $specialURL;
                }
            }
            break;
    }
    return false;
}