Exemplo n.º 1
0
function resolveSpecialURL($specialURL)
{
    $siteMgr = new Sites();
    $specialURL = urldecode($specialURL);
    $webRoot = rtrim(ltrim((string) sConfig()->getVar("CONFIG/DIRECTORIES/WEBROOT"), '/'), '/');
    if (strpos($specialURL, $webRoot) === 0) {
        $specialURL = substr($specialURL, strlen($webRoot . '/'));
    }
    if (strpos($specialURL, '/' . $webRoot) === 0) {
        $specialURL = substr($specialURL, strlen('/' . $webRoot . '/'));
    }
    $specialURL = mb_substr($specialURL, 2, mb_strlen($specialURL, 'UTF-8') - 2, 'UTF-8');
    $specialArray = explode(':', $specialURL);
    if (strlen($webRoot) > 0) {
        $webRoot = '/' . $webRoot;
    }
    // For Links
    if ($specialArray[0] == 'LINKTO') {
        switch ($specialArray[1]) {
            case 'PAGE':
                // Try to find nice pagename
                $niceURL = '';
                if ($siteMgr->siteExists((int) $specialArray[2])) {
                    $pageMgr = sPageMgr((int) $specialArray[2]);
                    $parentNodes = $pageMgr->getParents((int) $specialArray[3]);
                    foreach ($parentNodes as $parentNode) {
                        $niceURL = '/' . $parentNode[0]['PNAME'] . $niceURL;
                    }
                    $pagepname = $pageMgr->getPnameByPageId((int) $specialArray[3]);
                    if ($pagepname) {
                        $niceURL .= '/' . $pagepname . '/';
                        return $webRoot . $niceURL;
                    } else {
                        return '';
                    }
                } else {
                    return false;
                }
                break;
            case 'IMG':
            case 'DOWN':
                // Try to find nice image-/downloadname
                $fileData = explode('§§', $specialArray[2]);
                $niceURL = '';
                $filepname = sFileMgr()->getPnameByFileId((int) $fileData[0]);
                if ($specialArray[1] == 'IMG') {
                    $niceURL .= '/image/' . $filepname;
                } else {
                    $niceURL .= '/download/' . $filepname;
                }
                if ($fileData[1]) {
                    $niceURL .= '/' . $fileData[1];
                }
                return $webRoot . $niceURL;
                break;
        }
    }
    return false;
}