Exemple #1
0
function preText($s, $prefs)
{
    extract($prefs);
    callback_event('pretext');
    if (gps('rss')) {
        include txpath . '/publish/rss.php';
        exit(rss());
    }
    if (gps('atom')) {
        include txpath . '/publish/atom.php';
        exit(atom());
    }
    // set messy variables
    $out = makeOut('id', 's', 'c', 'q', 'pg', 'p', 'month', 'author');
    // some useful vars for taghandlers, plugins
    $out['request_uri'] = preg_replace("|^https?://[^/]+|i", "", serverSet('REQUEST_URI'));
    $out['qs'] = serverSet('QUERY_STRING');
    // IIS fix
    if (!$out['request_uri'] and serverSet('SCRIPT_NAME')) {
        $out['request_uri'] = serverSet('SCRIPT_NAME') . (serverSet('QUERY_STRING') ? '?' . serverSet('QUERY_STRING') : '');
    }
    // another IIS fix
    if (!$out['request_uri'] and serverSet('argv')) {
        $argv = serverSet('argv');
        $out['request_uri'] = @substr($argv[0], strpos($argv[0], ';') + 1);
    }
    // define the useable url, minus any subdirectories.
    // this is pretty fugly, if anyone wants to have a go at it - dean
    $out['subpath'] = $subpath = preg_quote(preg_replace("/https?:\\/\\/.*(\\/.*)/Ui", "\$1", hu), "/");
    $out['req'] = $req = preg_replace("/^{$subpath}/i", "/", $out['request_uri']);
    $is_404 = 0;
    // if messy vars exist, bypass url parsing
    if (!$out['id'] && !$out['s'] && !(txpinterface == 'css') && !(txpinterface == 'admin')) {
        // return clean URL test results for diagnostics
        if (gps('txpcleantest')) {
            exit(show_clean_test($out));
        }
        extract(chopUrl($req));
        //first we sniff out some of the preset url schemes
        if (strlen($u1)) {
            switch ($u1) {
                case 'atom':
                    include txpath . '/publish/atom.php';
                    exit(atom());
                case 'rss':
                    include txpath . '/publish/rss.php';
                    exit(rss());
                    // urldecode(strtolower(urlencode())) looks ugly but is the only way to
                    // make it multibyte-safe without breaking backwards-compatibility
                // urldecode(strtolower(urlencode())) looks ugly but is the only way to
                // make it multibyte-safe without breaking backwards-compatibility
                case urldecode(strtolower(urlencode(gTxt('section')))):
                    $out['s'] = ckEx('section', $u2) ? $u2 : '';
                    $is_404 = empty($out['s']);
                    break;
                case urldecode(strtolower(urlencode(gTxt('category')))):
                    $out['c'] = ckEx('category', $u2) ? $u2 : '';
                    $is_404 = empty($out['c']);
                    break;
                case urldecode(strtolower(urlencode(gTxt('author')))):
                    $out['author'] = !empty($u2) ? $u2 : '';
                    break;
                    // AuthorID gets resolved from Name further down
                // AuthorID gets resolved from Name further down
                case urldecode(strtolower(urlencode(gTxt('file_download')))):
                    $out['s'] = 'file_download';
                    $out['id'] = !empty($u2) ? $u2 : '';
                    break;
                default:
                    // then see if the prefs-defined permlink scheme is usable
                    switch ($permlink_mode) {
                        case 'section_id_title':
                            if (empty($u2)) {
                                $out['s'] = ckEx('section', $u1) ? $u1 : '';
                                $is_404 = empty($out['s']);
                            } else {
                                $rs = lookupByIDSection($u2, $u1);
                                $out['s'] = @$rs['Section'];
                                $out['id'] = @$rs['ID'];
                                $is_404 = (empty($out['s']) or empty($out['id']));
                            }
                            break;
                        case 'year_month_day_title':
                            if (empty($u2)) {
                                $out['s'] = ckEx('section', $u1) ? $u1 : '';
                                $is_404 = empty($out['s']);
                            } elseif (empty($u4)) {
                                $month = "{$u1}-{$u2}";
                                if (!empty($u3)) {
                                    $month .= "-{$u3}";
                                }
                                if (preg_match('/\\d+-\\d+(?:-\\d+)?/', $month)) {
                                    $out['month'] = $month;
                                    $out['s'] = 'default';
                                } else {
                                    $is_404 = 1;
                                }
                            } else {
                                $when = "{$u1}-{$u2}-{$u3}";
                                $rs = lookupByDateTitle($when, $u4);
                                $out['id'] = !empty($rs['ID']) ? $rs['ID'] : '';
                                $out['s'] = !empty($rs['Section']) ? $rs['Section'] : '';
                                $is_404 = (empty($out['s']) or empty($out['id']));
                            }
                            break;
                        case 'section_title':
                            if (empty($u2)) {
                                $out['s'] = ckEx('section', $u1) ? $u1 : '';
                                $is_404 = empty($out['s']);
                            } else {
                                $rs = lookupByTitleSection($u2, $u1);
                                $out['id'] = @$rs['ID'];
                                $out['s'] = @$rs['Section'];
                                $is_404 = (empty($out['s']) or empty($out['id']));
                            }
                            break;
                        case 'title_only':
                            $rs = lookupByTitle($u1);
                            $out['id'] = @$rs['ID'];
                            $out['s'] = empty($rs['Section']) ? ckEx('section', $u1) : $rs['Section'];
                            $is_404 = empty($out['s']);
                            break;
                        case 'id_title':
                            if (is_numeric($u1) && ckExID($u1)) {
                                $rs = lookupByID($u1);
                                $out['id'] = !empty($rs['ID']) ? $rs['ID'] : '';
                                $out['s'] = !empty($rs['Section']) ? $rs['Section'] : '';
                                $is_404 = (empty($out['s']) or empty($out['id']));
                            } else {
                                # We don't want to miss the /section/ pages
                                $out['s'] = ckEx('section', $u1) ? $u1 : '';
                                $is_404 = empty($out['s']);
                            }
                            break;
                    }
            }
        } else {
            $out['s'] = 'default';
        }
    } else {
        // Messy mode, but prevent to get the id for file_downloads
        if ($out['id'] && !$out['s']) {
            $rs = lookupByID($out['id']);
            $out['id'] = !empty($rs['ID']) ? $rs['ID'] : '';
            $out['s'] = !empty($rs['Section']) ? $rs['Section'] : '';
            $is_404 = (empty($out['s']) or empty($out['id']));
        }
    }
    // Resolve AuthorID from Authorname
    if ($out['author']) {
        $name = urldecode(strtolower(urlencode($out['author'])));
        $name = safe_field('name', 'txp_users', "RealName like '" . doSlash($out['author']) . "'");
        if ($name) {
            $out['author'] = $name;
        } else {
            $out['author'] = '';
            $is_404 = true;
        }
    }
    // allow article preview
    if (gps('txpreview') and is_logged_in()) {
        global $nolog;
        $nolog = true;
        $rs = safe_row("ID as id,Section as s", 'textpattern', 'ID = ' . intval(gps('txpreview')) . ' limit 1');
        if ($rs and $is_404) {
            $is_404 = false;
            $out = array_merge($out, $rs);
        }
    }
    // Stats: found or not
    $out['status'] = $is_404 ? '404' : '200';
    $out['pg'] = is_numeric($out['pg']) ? intval($out['pg']) : '';
    $out['id'] = is_numeric($out['id']) ? intval($out['id']) : '';
    if ($out['s'] == 'file_download') {
        // get id of potential filename
        if (!is_numeric($out['id'])) {
            $rs = safe_row("*", "txp_file", "filename='" . doSlash($out['id']) . "' and status = 4");
        } else {
            $rs = safe_row("*", "txp_file", 'id=' . intval($out['id']) . ' and status = 4');
        }
        $out = $rs ? array_merge($out, $rs) : array('s' => 'file_download', 'file_error' => 404);
        return $out;
    }
    if (!$is_404) {
        $out['s'] = empty($out['s']) ? 'default' : $out['s'];
    }
    $s = $out['s'];
    $id = $out['id'];
    // hackish
    global $is_article_list;
    if (empty($id)) {
        $is_article_list = true;
    }
    // by this point we should know the section, so grab its page and css
    $rs = safe_row("page, css", "txp_section", "name = '" . doSlash($s) . "' limit 1");
    $out['page'] = @$rs['page'];
    $out['css'] = @$rs['css'];
    if (is_numeric($id) and !$is_404) {
        $a = safe_row('*, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod', 'textpattern', 'ID=' . intval($id) . (gps('txpreview') ? '' : ' and Status in (4,5)'));
        if ($a) {
            $Posted = $a['Posted'];
            $out['id_keywords'] = $a['Keywords'];
            $out['id_author'] = $a['AuthorID'];
            populateArticleData($a);
            $uExpires = $a['uExpires'];
            if ($uExpires and time() > $uExpires and !$publish_expired_articles) {
                $out['status'] = '410';
            }
            if ($np = getNextPrev($id, $Posted, $s)) {
                $out = array_merge($out, $np);
            }
        }
    }
    $out['path_from_root'] = rhu;
    // these are deprecated as of 1.0
    $out['pfr'] = rhu;
    // leaving them here for plugin compat
    $out['path_to_site'] = $path_to_site;
    $out['permlink_mode'] = $permlink_mode;
    $out['sitename'] = $sitename;
    return $out;
}
Exemple #2
0
function preText($s, $prefs)
{
    extract($prefs);
    callback_event('pretext');
    // Set messy variables.
    $out = makeOut('id', 's', 'c', 'context', 'q', 'm', 'pg', 'p', 'month', 'author');
    if (gps('rss')) {
        $out['feed'] = 'rss';
    }
    if (gps('atom')) {
        $out['feed'] = 'atom';
    }
    // Some useful vars for taghandlers, plugins.
    $out['request_uri'] = preg_replace("|^https?://[^/]+|i", "", serverSet('REQUEST_URI'));
    $out['qs'] = serverSet('QUERY_STRING');
    // IIS fix.
    if (!$out['request_uri'] and serverSet('SCRIPT_NAME')) {
        $out['request_uri'] = serverSet('SCRIPT_NAME') . (serverSet('QUERY_STRING') ? '?' . serverSet('QUERY_STRING') : '');
    }
    // Another IIS fix.
    if (!$out['request_uri'] and serverSet('argv')) {
        $argv = serverSet('argv');
        $out['request_uri'] = @substr($argv[0], strpos($argv[0], ';') + 1);
    }
    // Define the useable url, minus any subdirectories.
    // This is pretty ugly, if anyone wants to have a go at it.
    $out['subpath'] = $subpath = preg_quote(preg_replace("/https?:\\/\\/.*(\\/.*)/Ui", "\$1", hu), "/");
    $out['req'] = $req = preg_replace("/^{$subpath}/i", "/", $out['request_uri']);
    $is_404 = $out['status'] == '404';
    // If messy vars exist, bypass URL parsing.
    if (!$out['id'] && !$out['s'] && !(txpinterface == 'css') && !(txpinterface == 'admin')) {
        // Return clean URL test results for diagnostics.
        if (gps('txpcleantest')) {
            exit(show_clean_test($out));
        }
        extract(chopUrl($req));
        // First we sniff out some of the preset URL schemes.
        if (strlen($u1)) {
            switch ($u1) {
                case 'atom':
                    $out['feed'] = 'atom';
                    break;
                case 'rss':
                    $out['feed'] = 'rss';
                    break;
                    // urldecode(strtolower(urlencode())) looks ugly but is the
                    // only way to make it multibyte-safe without breaking
                    // backwards-compatibility.
                // urldecode(strtolower(urlencode())) looks ugly but is the
                // only way to make it multibyte-safe without breaking
                // backwards-compatibility.
                case urldecode(strtolower(urlencode(gTxt('section')))):
                    $out['s'] = ckEx('section', $u2) ? $u2 : '';
                    $is_404 = empty($out['s']);
                    break;
                case urldecode(strtolower(urlencode(gTxt('category')))):
                    if ($u3) {
                        $out['context'] = validContext($u2);
                        $out['c'] = $u3;
                    } else {
                        $out['context'] = 'article';
                        $out['c'] = $u2;
                    }
                    $out['c'] = ckCat($out['context'], $out['c']) ? $out['c'] : '';
                    $is_404 = empty($out['c']);
                    break;
                case urldecode(strtolower(urlencode(gTxt('author')))):
                    if ($u3) {
                        $out['context'] = validContext($u2);
                        $out['author'] = $u3;
                    } else {
                        $out['context'] = 'article';
                        $out['author'] = $u2;
                    }
                    $out['author'] = !empty($out['author']) ? $out['author'] : '';
                    break;
                    // AuthorID gets resolved from Name further down.
                // AuthorID gets resolved from Name further down.
                case urldecode(strtolower(urlencode(gTxt('file_download')))):
                    $out['s'] = 'file_download';
                    $out['id'] = !empty($u2) ? $u2 : '';
                    $out['filename'] = !empty($u3) ? $u3 : '';
                    break;
                default:
                    // Then see if the prefs-defined permlink scheme is usable.
                    switch ($permlink_mode) {
                        case 'section_id_title':
                            if (empty($u2)) {
                                $out['s'] = ckEx('section', $u1) ? $u1 : '';
                                $is_404 = empty($out['s']);
                            } else {
                                $rs = lookupByIDSection($u2, $u1);
                                $out['s'] = @$rs['Section'];
                                $out['id'] = @$rs['ID'];
                                $is_404 = (empty($out['s']) or empty($out['id']));
                            }
                            break;
                        case 'year_month_day_title':
                            if (empty($u2)) {
                                $out['s'] = ckEx('section', $u1) ? $u1 : '';
                                $is_404 = empty($out['s']);
                            } elseif (empty($u4)) {
                                $month = "{$u1}-{$u2}";
                                if (!empty($u3)) {
                                    $month .= "-{$u3}";
                                }
                                if (preg_match('/\\d+-\\d+(?:-\\d+)?/', $month)) {
                                    $out['month'] = $month;
                                    $out['s'] = 'default';
                                } else {
                                    $is_404 = 1;
                                }
                            } else {
                                $when = "{$u1}-{$u2}-{$u3}";
                                $rs = lookupByDateTitle($when, $u4);
                                $out['id'] = !empty($rs['ID']) ? $rs['ID'] : '';
                                $out['s'] = !empty($rs['Section']) ? $rs['Section'] : '';
                                $is_404 = (empty($out['s']) or empty($out['id']));
                            }
                            break;
                        case 'section_title':
                            if (empty($u2)) {
                                $out['s'] = ckEx('section', $u1) ? $u1 : '';
                                $is_404 = empty($out['s']);
                            } else {
                                $rs = lookupByTitleSection($u2, $u1);
                                $out['id'] = isset($rs['ID']) ? $rs['ID'] : '';
                                $out['s'] = isset($rs['Section']) ? $rs['Section'] : '';
                                $is_404 = (empty($out['s']) or empty($out['id']));
                            }
                            break;
                        case 'title_only':
                            $rs = lookupByTitle($u1);
                            $out['id'] = @$rs['ID'];
                            $out['s'] = empty($rs['Section']) ? ckEx('section', $u1) : $rs['Section'];
                            $is_404 = empty($out['s']);
                            break;
                        case 'id_title':
                            if (is_numeric($u1) && ckExID($u1)) {
                                $rs = lookupByID($u1);
                                $out['id'] = !empty($rs['ID']) ? $rs['ID'] : '';
                                $out['s'] = !empty($rs['Section']) ? $rs['Section'] : '';
                                $is_404 = (empty($out['s']) or empty($out['id']));
                            } else {
                                // We don't want to miss the /section/ pages.
                                $out['s'] = ckEx('section', $u1) ? $u1 : '';
                                $is_404 = empty($out['s']);
                            }
                            break;
                    }
                    if (!$is_404) {
                        $out['context'] = validContext($out['context']);
                    }
                    break;
                    // Prefs-defined permlink scheme case.
            }
        } else {
            $out['s'] = 'default';
            $out['context'] = validContext($out['context']);
        }
    } else {
        // Messy mode, but prevent to get the id for file_downloads.
        $out['context'] = validContext($out['context']);
        if ($out['context'] == 'article' && $out['id'] && $out['s'] != 'file_download') {
            $rs = lookupByID($out['id']);
            $out['id'] = !empty($rs['ID']) ? $rs['ID'] : '';
            $out['s'] = !empty($rs['Section']) ? $rs['Section'] : '';
            $is_404 = (empty($out['s']) or empty($out['id']));
        }
    }
    // Existing category in messy or clean URL?
    if (!empty($out['c'])) {
        if (!ckCat($out['context'], $out['c'])) {
            $is_404 = true;
            $out['c'] = '';
        }
    }
    // Resolve AuthorID from Authorname.
    if ($out['author']) {
        $name = urldecode(strtolower(urlencode($out['author'])));
        $name = safe_field('name', 'txp_users', "RealName LIKE '" . doSlash($out['author']) . "'");
        if ($name) {
            $out['author'] = $name;
        } else {
            $out['author'] = '';
            $is_404 = true;
        }
    }
    // Allow article preview.
    if (gps('txpreview')) {
        doAuth();
        if (!has_privs('article.preview')) {
            txp_status_header('401 Unauthorized');
            exit(hed('401 Unauthorized', 1) . graf(gTxt('restricted_area')));
        }
        global $nolog;
        $nolog = true;
        $rs = safe_row("ID AS id, Section AS s", 'textpattern', "ID = " . intval(gps('txpreview')) . " LIMIT 1");
        if ($rs) {
            $is_404 = false;
            $out = array_merge($out, $rs);
        }
    }
    // Stats: found or not.
    $out['status'] = $is_404 ? '404' : '200';
    $out['pg'] = is_numeric($out['pg']) ? intval($out['pg']) : '';
    $out['id'] = is_numeric($out['id']) ? intval($out['id']) : '';
    if ($out['s'] == 'file_download') {
        if (is_numeric($out['id'])) {
            // Undo the double-encoding workaround for .gz files;
            // @see filedownloadurl().
            if (!empty($out['filename'])) {
                $out['filename'] = preg_replace('/gz&$/i', 'gz', $out['filename']);
            }
            $fn = empty($out['filename']) ? '' : " AND filename = '" . doSlash($out['filename']) . "'";
            $rs = safe_row('*', 'txp_file', "id = " . intval($out['id']) . " AND status = " . STATUS_LIVE . " AND created <= " . now('created') . $fn);
        }
        return !empty($rs) ? array_merge($out, $rs) : array('s' => 'file_download', 'file_error' => 404);
    }
    if (!$is_404) {
        $out['s'] = empty($out['s']) ? 'default' : $out['s'];
    }
    $s = $out['s'];
    $id = $out['id'];
    // Hackish.
    global $is_article_list;
    if (empty($id)) {
        $is_article_list = true;
    }
    // By this point we should know the section, so grab its page and CSS.
    if (txpinterface != 'css') {
        $rs = safe_row("page, css", "txp_section", "name = '" . doSlash($s) . "' LIMIT 1");
        $out['page'] = isset($rs['page']) ? $rs['page'] : '';
        $out['css'] = isset($rs['css']) ? $rs['css'] : '';
    }
    if (is_numeric($id) and !$is_404) {
        $a = safe_row("*, UNIX_TIMESTAMP(Posted) AS uPosted, UNIX_TIMESTAMP(Expires) AS uExpires, UNIX_TIMESTAMP(LastMod) AS uLastMod", 'textpattern', "ID = " . intval($id) . (gps('txpreview') ? '' : " AND Status IN (" . STATUS_LIVE . "," . STATUS_STICKY . ")"));
        if ($a) {
            $out['id_keywords'] = $a['Keywords'];
            $out['id_author'] = $a['AuthorID'];
            populateArticleData($a);
            $uExpires = $a['uExpires'];
            if ($uExpires and time() > $uExpires and !$publish_expired_articles) {
                $out['status'] = '410';
            }
        }
    }
    // These are deprecated as of Textpattern v1.0 - leaving them here for
    // plugin compatibility.
    $out['path_from_root'] = rhu;
    $out['pfr'] = rhu;
    $out['path_to_site'] = $path_to_site;
    $out['permlink_mode'] = $permlink_mode;
    $out['sitename'] = $sitename;
    return $out;
}
Exemple #3
0
function preText($s, $prefs)
{
    extract($prefs);
    callback_event('pretext');
    if (gps('rss')) {
        include txpath . '/publish/rss.php';
        exit(rss());
    }
    if (gps('atom')) {
        include txpath . '/publish/atom.php';
        exit(atom());
    }
    // set messy variables
    $out = makeOut('id', 's', 'c', 'q', 'pg', 'p', 'month', 'author');
    // some useful vars for taghandlers, plugins
    $out['request_uri'] = serverSet('REQUEST_URI');
    $out['qs'] = serverSet('QUERY_STRING');
    // IIS - can someone confirm whether or not this works?
    if (!$out['request_uri'] and $argv = serverSet('argv')) {
        $out['request_uri'] = @substr($argv[0], strpos($argv[0], ';' + 1));
    }
    // define the useable url, minus any subdirectories.
    // this is pretty fugly, if anyone wants to have a go at it - dean
    $out['subpath'] = $subpath = preg_quote(preg_replace("/http:\\/\\/.*(\\/.*)/Ui", "\$1", hu), "/");
    $out['req'] = $req = preg_replace("/^{$subpath}/i", "/", serverSet('REQUEST_URI'));
    $is_404 = 0;
    // if messy vars exist, bypass url parsing
    if (!$out['id'] && !$out['s']) {
        extract(chopUrl($req));
        //first we sniff out some of the preset url schemes
        if (!empty($u1)) {
            switch ($u1) {
                case 'atom':
                    include txpath . '/publish/atom.php';
                    exit(atom());
                case 'rss':
                    include txpath . '/publish/rss.php';
                    exit(rss());
                    // urldecode(strtolower(urlencode())) looks ugly but is the only way to
                    // make it multibyte-safe without breaking backwards-compatibility
                // urldecode(strtolower(urlencode())) looks ugly but is the only way to
                // make it multibyte-safe without breaking backwards-compatibility
                case urldecode(strtolower(urlencode(gTxt('section')))):
                    $out['s'] = ckEx('section', $u2) ? $u2 : '';
                    break;
                case urldecode(strtolower(urlencode(gTxt('category')))):
                    $out['c'] = ckEx('category', $u2) ? $u2 : '';
                    break;
                case urldecode(strtolower(urlencode(gTxt('author')))):
                    $out['author'] = !empty($u2) ? $u2 : '';
                    break;
                    // AuthorID gets resolved from Name further down
                // AuthorID gets resolved from Name further down
                case urldecode(strtolower(urlencode(gTxt('file_download')))):
                    $out['s'] = 'file_download';
                    $out['id'] = !empty($u2) ? $u2 : '';
                    break;
                case 'p':
                    $out['p'] = is_numeric($u2) ? $u2 : '';
                    break;
                default:
                    // then see if the prefs-defined permlink scheme is usable
                    switch ($permlink_mode) {
                        case 'section_id_title':
                            if (empty($u2)) {
                                $out['s'] = ckEx('section', $u1) ? $u1 : '';
                                $is_404 = empty($out['s']);
                            } else {
                                $rs = ckExID($u2);
                                $out['s'] = @$rs['Section'];
                                $out['id'] = @$rs['ID'];
                                $is_404 = (empty($out['s']) or empty($out['id']));
                            }
                            break;
                        case 'year_month_day_title':
                            if (empty($u2)) {
                                $out['s'] = ckEx('section', $u1) ? $u1 : '';
                                $is_404 = empty($out['s']);
                            } elseif (empty($u4)) {
                                $month = "{$u1}-{$u2}";
                                if (!empty($u3)) {
                                    $month .= "-{$u3}";
                                }
                                if (preg_match('/\\d+-\\d+(?:-\\d+)?/', $month)) {
                                    $out['month'] = $month;
                                    $out['s'] = 'default';
                                } else {
                                    $is_404 = 1;
                                }
                            } else {
                                $when = "{$u1}-{$u2}-{$u3}";
                                $rs = lookupByDateTitle($when, $u4);
                                $out['id'] = !empty($rs['ID']) ? $rs['ID'] : '';
                                $out['s'] = !empty($rs['Section']) ? $rs['Section'] : '';
                                $is_404 = (empty($out['s']) or empty($out['id']));
                            }
                            break;
                        case 'section_title':
                            if (empty($u2)) {
                                $out['s'] = ckEx('section', $u1) ? $u1 : '';
                                $is_404 = empty($out['s']);
                            } else {
                                $rs = lookupByTitleSection($u2, $u1);
                                $out['id'] = @$rs['ID'];
                                $out['s'] = @$rs['Section'];
                                $is_404 = (empty($out['s']) or empty($out['id']));
                            }
                            break;
                        case 'title_only':
                            $rs = lookupByTitle($u1);
                            $out['id'] = @$rs['ID'];
                            $out['s'] = empty($rs['Section']) ? ckEx('section', $u1) : $rs['Section'];
                            $is_404 = empty($out['s']);
                            break;
                        case 'id_title':
                            if (is_numeric($u1) && ckExID($u1)) {
                                $rs = lookupByID($u1);
                                $out['id'] = !empty($rs['ID']) ? $rs['ID'] : '';
                                $out['s'] = !empty($rs['Section']) ? $rs['Section'] : '';
                                $is_404 = (empty($out['s']) or empty($out['id']));
                            } else {
                                # We don't want to miss the /section/ pages
                                $out['s'] = ckEx('section', $u1) ? $u1 : '';
                                $is_404 = empty($out['s']);
                            }
                            break;
                    }
            }
        } else {
            $out['s'] = 'default';
        }
    } else {
        // Messy mode, but prevent to get the id for file_downloads
        if ($out['id'] && !$out['s']) {
            $out['s'] = safe_field('section', 'textpattern', "ID='" . doSlash($out['id']) . "'");
        }
    }
    // Resolve AuthorID from Authorname
    if ($out['author']) {
        $out['author'] = safe_field('name', 'txp_users', "RealName like '" . doSlash($out['author']) . "'");
    }
    // Stats: found or not
    $out['status'] = $is_404 ? '404' : '200';
    if ($out['s'] == 'file_download') {
        // get id of potential filename
        if (!is_numeric($out['id'])) {
            $rs = safe_row("*", "txp_file", "filename='" . doSlash($out['id']) . "'");
        } else {
            $rs = safe_row("*", "txp_file", "id='" . intval($out['id']) . "'");
        }
        $out = $rs ? array_merge($out, $rs) : array('s' => 'file_download', 'file_error' => 404);
        return $out;
    }
    if (!$is_404) {
        $out['s'] = empty($out['s']) ? 'default' : $out['s'];
    }
    $s = $out['s'];
    $id = $out['id'];
    // hackish
    if (empty($id)) {
        $GLOBALS['is_article_list'] = true;
    }
    // by this point we should know the section, so grab its page and css
    $rs = safe_row("*", "txp_section", "name = '" . doSlash($s) . "' limit 1");
    $out['page'] = @$rs['page'];
    // Remove the below line if nothing breaks
    // 		$out['css']  = @$rs['css'];
    if (is_numeric($id)) {
        $idrs = safe_row("Posted, AuthorID, Keywords", "textpattern", "ID=" . doSlash($id));
        extract($idrs);
        if ($np = getNextPrev($id, $Posted, $s)) {
            $out = array_merge($out, $np);
        }
        $out['id_keywords'] = $Keywords;
        $out['id_author'] = get_author_name($AuthorID);
    }
    $out['path_from_root'] = $path_from_root;
    // these are deprecated as of 1.0
    $out['pfr'] = $path_from_root;
    // leaving them here for plugin compat
    $out['path_to_site'] = $path_to_site;
    $out['permlink_mode'] = $permlink_mode;
    $out['sitename'] = htmlspecialchars($sitename);
    return $out;
}
Exemple #4
0
function preText($s, $prefs)
{
    extract($prefs);
    if (gps('rss')) {
        include txpath . '/publish/rss.php';
        exit(rss());
    }
    if (gps('atom')) {
        include txpath . '/publish/atom.php';
        exit(atom());
    }
    // set messy variables
    $out = makeOut('id', 's', 'c', 'q', 'pg', 'p', 'month');
    // if messy vars exist, bypass url parsing
    if (!$out['id'] && !$out['s']) {
        // define the useable url, minus any subdirectories.
        // this is pretty fugly, if anyone wants to have a go at it - dean
        $subpath = preg_quote(preg_replace("/http:\\/\\/.*(\\/.*)/Ui", "\$1", hu), "/");
        $req = preg_replace("/^{$subpath}/i", "/", serverSet('REQUEST_URI'));
        extract(chopUrl($req));
        //first we sniff out some of the preset url schemes
        if (!empty($u1)) {
            switch ($u1) {
                case 'atom':
                    include txpath . '/publish/atom.php';
                    exit(atom());
                case 'rss':
                    include txpath . '/publish/rss.php';
                    exit(rss());
                case strtolower(gTxt('section')):
                    $out['s'] = ckEx('section', $u2) ? $u2 : 'default';
                    break;
                case strtolower(gTxt('category')):
                    $out['c'] = ckEx('category', $u2) ? $u2 : '';
                    break;
                case urlencode(strtolower(gTxt('author'))):
                    $author_name = !empty($u2) ? urldecode($u2) : '';
                    $out['author'] = safe_field('name', 'txp_users', "RealName like '{$author_name}'");
                    break;
                case strtolower(gTxt('file_download')):
                    $out['s'] = 'file_download';
                    $out['id'] = !empty($u2) ? $u2 : '';
                    break;
                case 'p':
                    $out['p'] = is_numeric($u2) ? $u2 : '';
                    break;
                default:
                    // then see if the prefs-defined permlink scheme is usable
                    switch ($permlink_mode) {
                        case 'section_id_title':
                            $out['s'] = ckEx('section', $u1) ? $u1 : 'default';
                            $out['id'] = is_numeric($u2) && ckExID($u2) ? $u2 : '';
                            break;
                        case 'year_month_day_title':
                            if (empty($u4)) {
                                $out['month'] = "{$u1}-{$u2}";
                                if (!empty($u3)) {
                                    $out['month'] .= "-{$u3}";
                                }
                                $out['s'] = 'default';
                            } else {
                                $when = date("Y-m-d", strtotime("{$u1}-{$u2}-{$u3}") + $timeoffset);
                                $rs = lookupByDateTitle($when, $u4);
                                $out['id'] = !empty($rs['ID']) ? $rs['ID'] : '';
                                $out['s'] = !empty($rs['Section']) ? $rs['Section'] : '';
                            }
                            break;
                        case 'section_title':
                            $rs = lookupByTitleSection($u2, $u1);
                            $out['id'] = !empty($rs['ID']) ? $rs['ID'] : '';
                            $out['s'] = ckEx('section', $u1) ? $u1 : 'default';
                            break;
                        case 'title_only':
                            $rs = lookupByTitle($u1);
                            $out['id'] = !empty($rs['ID']) ? $rs['ID'] : '';
                            $out['s'] = !empty($rs['Section']) ? $rs['Section'] : ckEx('section', $u1) ? $u1 : 'default';
                            break;
                        case 'id_title':
                            if (is_numeric($u1) && ckExID($u1)) {
                                $rs = lookupByID($u1);
                                $out['id'] = !empty($rs['ID']) ? $rs['ID'] : '';
                                $out['s'] = !empty($rs['Section']) ? $rs['Section'] : 'default';
                            } else {
                                # We don't want to miss the /section/ pages
                                $out['s'] = ckEx('section', $u1) ? $u1 : 'default';
                            }
                            break;
                    }
            }
        } else {
            $out['s'] = 'default';
        }
    } else {
        // Messy mode, but prevent to get the id for file_downloads
        if ($out['id'] && !$out['s']) {
            $out['s'] = safe_field('section', 'textpattern', "ID='" . doSlash($out['id']) . "'");
        }
    }
    if ($out['s'] == 'file_download') {
        // get id of potential filename
        if (!is_numeric($out['id'])) {
            $rs = safe_row("*", "txp_file", "filename='" . $out['id'] . "'");
        } else {
            $rs = safe_row("*", "txp_file", "id='" . $out['id'] . "'");
        }
        $out = $rs ? array_merge($out, $rs) : array('s' => 'file_download', 'file_error' => 404);
        return $out;
    }
    $out['s'] = empty($out['s']) ? 'default' : $out['s'];
    $s = $out['s'];
    $id = $out['id'];
    // hackish
    if (empty($id)) {
        $GLOBALS['is_article_list'] = true;
    }
    // by this point we should know the section, so grab its page and css
    $rs = safe_row("*", "txp_section", "name = '{$s}' limit 1");
    $out['page'] = @$rs['page'];
    $out['css'] = @$rs['css'];
    if (is_numeric($id)) {
        $idrs = safe_row("Posted, AuthorID, Keywords", "textpattern", "ID={$id}");
        extract($idrs);
        if ($np = getNextPrev($id, $Posted, $s)) {
            $out = array_merge($out, $np);
        }
        $out['id_keywords'] = $Keywords;
        $out['id_author'] = get_author_name($AuthorID);
    }
    $out['path_from_root'] = $path_from_root;
    // these are deprecated as of 1.0
    $out['pfr'] = $path_from_root;
    // leaving them here for plugin compat
    $out['path_to_site'] = $path_to_site;
    $out['permlink_mode'] = $permlink_mode;
    $out['sitename'] = htmlspecialchars($sitename);
    return $out;
}
Exemple #5
0
 function l10n_lang_list($atts)
 {
     global $thisarticle, $l10n_language, $is_article_list, $pretext, $prefs;
     extract(lAtts(array('title' => '', 'on404' => '', 'current_class' => 'l10n_current', 'language_class' => 'long', 'list_class' => 'l10n_lang_list', 'show_empty' => '', 'link_current' => '', 'display' => 'native', 'article_list' => $is_article_list), $atts));
     $on404 = !empty($on404);
     # User marked this list as a 404 special lookup list.
     $show_empty = !empty($show_empty);
     $link_current = !empty($link_current);
     $processing404 = $pretext['status'] === '404';
     $list = array();
     static $alangs;
     $slangs = LanguageHandler::get_site_langs();
     $section = empty($pretext['s']) ? '' : $pretext['s'];
     $id = $pretext['id'];
     $url = trim($_SERVER['REQUEST_URI'], '/');
     $parts = chopUrl($url);
     //echo br , "l10n_lang_list(" , var_dump($atts) , ") Section($section) ID($id)" ;
     //echo br , "url = " , $_SERVER['REQUEST_URI'];
     //echo br , "parts = " , var_dump( $parts );
     if ($on404) {
         #
         #	Find the section and id of the faulting article (if possible)...
         #
         if (empty($id)) {
             $id = gps('id');
         }
         # Try out a messy match first
         if (empty($id)) {
             extract($parts);
             //echo br , 'permlink_mode = ' , $prefs['permlink_mode'];
             switch ($prefs['permlink_mode']) {
                 case 'section_id_title':
                     $id = $u1;
                     break;
                 case 'year_month_day_title':
                     $when = "{$u0}-{$u1}-{$u2}";
                     $rs = safe_row("ID,Section", "l10n_master_textpattern", "posted like '" . doSlash($when) . "%' and url_title like '" . doSlash($u3) . "' and Status >= 4 limit 1");
                     $id = !empty($rs['ID']) ? $rs['ID'] : '';
                     break;
                 case 'section_title':
                     $rs = safe_row("ID,Section", 'l10n_master_textpattern', "url_title like '" . doSlash($u1) . "' AND Section='" . doSlash($u0) . "' and Status >= 4 limit 1");
                     $id = @$rs['ID'];
                     break;
                 case 'title_only':
                     $rs = safe_row("ID", 'l10n_master_textpattern', "url_title like '" . doSlash($u0) . "' and Status >= 4 limit 1");
                     $id = @$rs['ID'];
                     break;
                 case 'id_title':
                     $id = $u0;
                     break;
             }
         }
         if (!empty($id) and is_numeric($id)) {
             $article_list = false;
         } else {
             return '';
         }
         #
         #	Make sure we show all alternatives, even if they are in the current language...
         #
         $link_current = true;
     }
     $show_title = !empty($title);
     if (!$article_list) {
         if (!isset($alangs) or !is_array($alangs)) {
             $alangs = ArticleManager::get_alternate_mappings($id, 'nothing', true);
         }
         //echo br , 'alangs = ' , var_dump( $alangs );
         if ($show_title) {
             $show_title = !empty($alangs);
         }
     }
     if ($show_title) {
         $title = tag($title, 'p') . n;
     } else {
         $title = '';
     }
     foreach ($slangs as $lang) {
         $codes = LanguageHandler::compact_code($lang);
         $short = $codes['short'];
         $long = $codes['long'];
         $dir = LanguageHandler::get_lang_direction_markup($lang);
         switch ($display) {
             case 'short':
                 $lname = $short;
                 break;
             case 'long':
                 $lname = $long;
                 break;
             case 'native+':
                 $lname = LanguageHandler::get_native_name_of_lang($lang) . " [{$short}]";
                 break;
             case 'native++':
                 $lname = LanguageHandler::get_native_name_of_lang($lang) . " [{$long}]";
                 break;
             default:
                 $lname = LanguageHandler::get_native_name_of_lang($lang);
                 break;
         }
         if ($article_list) {
             #
             #	No individual ID but we should be able to serve all the languages
             # so use the current url and inject the language component into each one...
             #
             $current = $l10n_language['long'] === $lang;
             $text = tag($lname, 'span', $dir);
             #
             #	Prep the line class...
             #
             $class = 'short' === $language_class ? $short : $lang;
             if ($current) {
                 $class .= ' ' . $current_class;
             }
             $class = ' class="' . $class . '"';
             if (!$current or $link_current) {
                 $uri = rtrim($_SERVER['REQUEST_URI'], '/');
                 if ($processing404) {
                     $uri = '';
                 }
                 $line = '<a href="' . hu . $short . $uri . '">' . $text . '</a>';
             } else {
                 $line = $text;
             }
             $list[] = tag($line, 'li', $class);
         } else {
             #
             #	If a translation exists for that language then we
             # build a valid url to it and make it active in the list, otherwise include it in the
             # list but wihtout the hyper-link.
             #
             #	The active page is marked up with a css class.
             #
             if (array_key_exists($lang, $alangs)) {
                 $record = $alangs[$lang];
                 $lang_rendition_title = $record['title'];
                 $lang_rendition_id = $record['id'];
                 $current = $l10n_language['long'] === $lang;
                 $text = $lname;
                 if ($processing404) {
                     $text = strong($text) . sp . ':' . sp . $lang_rendition_title;
                 }
                 $text = tag($text, 'span', $dir);
                 #
                 #	Prep the line class...
                 #
                 $class = 'short' === $language_class ? $short : $lang;
                 if ($current) {
                     $class .= ' ' . $current_class;
                 }
                 $class = ' class="' . $class . '"';
                 if (!$current or $link_current) {
                     //$line = '<a href="'.hu.$short.$section.'/'.$alangs[$lang].'">'.$text.'</a>';
                     #
                     #	Use messy urls to avoid permlink pattern processing...
                     #
                     $line = '<a href="' . hu . $short . '/?id=' . $lang_rendition_id . '">' . $text . '</a>';
                 } else {
                     $line = $text;
                 }
                 $list[] = tag($line, 'li', $class);
             } else {
                 if ($show_empty) {
                     $list[] = tag($lname, 'li');
                 }
             }
         }
     }
     $list = tag(join("\n\t", $list), 'ul', " class=\"{$list_class}\"");
     return $title . $list;
 }
function cnk_pretext()
{
    global $prefs;
    // only takeover url algorithm when in section_title mode
    if (CNK_FRIENDLY_URLS && $prefs['permlink_mode'] == 'section_title') {
        extract($prefs);
        $out = array();
        // some useful vars for taghandlers, plugins
        $out['request_uri'] = preg_replace("|^https?://[^/]+|i", "", serverSet('REQUEST_URI'));
        $out['qs'] = serverSet('QUERY_STRING');
        // IIS fix
        if (!$out['request_uri'] and serverSet('SCRIPT_NAME')) {
            $out['request_uri'] = serverSet('SCRIPT_NAME') . (serverSet('QUERY_STRING') ? '?' . serverSet('QUERY_STRING') : '');
        }
        // another IIS fix
        if (!$out['request_uri'] and serverSet('argv')) {
            $argv = serverSet('argv');
            $out['request_uri'] = @substr($argv[0], strpos($argv[0], ';') + 1);
        }
        $subpath = preg_quote(preg_replace("/https?:\\/\\/.*(\\/.*)/Ui", "\$1", hu), "/");
        $req = preg_replace("/^{$subpath}/i", "/", $out['request_uri']);
        $url_chunks = explode('/', trim($req, '/'));
        $req = '/' . implode('/', array_slice($url_chunks, -2));
        //echo $req;
        extract(chopUrl($req));
        //first we sniff out some of the preset url schemes
        if (strlen($u1)) {
            switch ($u1) {
                case 'atom':
                    include txpath . '/publish/atom.php';
                    exit(atom());
                case 'rss':
                    include txpath . '/publish/rss.php';
                    exit(rss());
                    // urldecode(strtolower(urlencode())) looks ugly but is the only way to
                    // make it multibyte-safe without breaking backwards-compatibility
                // urldecode(strtolower(urlencode())) looks ugly but is the only way to
                // make it multibyte-safe without breaking backwards-compatibility
                case urldecode(strtolower(urlencode(gTxt('section')))):
                    $out['s'] = ckEx('section', $u2) ? $u2 : '';
                    break;
                case urldecode(strtolower(urlencode(gTxt('category')))):
                    $out['c'] = ckEx('category', $u2) ? $u2 : '';
                    break;
                case urldecode(strtolower(urlencode(gTxt('author')))):
                    $out['author'] = !empty($u2) ? $u2 : '';
                    break;
                    // AuthorID gets resolved from Name further down
                // AuthorID gets resolved from Name further down
                case urldecode(strtolower(urlencode(gTxt('file_download')))):
                    $out['s'] = 'file_download';
                    $out['id'] = !empty($u2) ? $u2 : '';
                    break;
                default:
                    // then see if the prefs-defined permlink scheme is usable
                    switch ($permlink_mode) {
                        /*
                        case 'section_id_title':
                        		if (empty($u2)) 
                        		{
                        				$out['s'] = (ckEx('section',$u1)) ? $u1 : '';
                        		}
                        		else 
                        		{
                        				$rs = lookupByIDSection($u2, $u1);
                        				$out['s'] = @$rs['Section'];
                        				$out['id'] = @$rs['ID'];
                        		}
                        break;
                        
                        case 'year_month_day_title':
                        		if (empty($u2)) 
                        		{
                        				$out['s'] = (ckEx('section',$u1)) ? $u1 : '';
                        		}
                        		elseif (empty($u4))
                        		{
                        				$month = "$u1-$u2";
                        				if (!empty($u3)) $month.= "-$u3";
                        				if (preg_match('/\d+-\d+(?:-\d+)?/', $month)) {
                        						$out['month'] = $month;
                        						$out['s'] = 'default';
                        				}
                        		}
                        		else
                        		{
                        				$when = "$u1-$u2-$u3";
                        				$rs = lookupByDateTitle($when,$u4);
                        				$out['id'] = (!empty($rs['ID'])) ? $rs['ID'] : '';
                        				$out['s'] = (!empty($rs['Section'])) ? $rs['Section'] : '';
                        		}
                        break;
                        */
                        case 'section_title':
                            if (empty($u2)) {
                                $out['s'] = ckEx('section', $u1) ? $u1 : '';
                            } else {
                                // match section/title
                                $rs = lookupByTitleSection($u2, $u1);
                                if (count($rs)) {
                                    $out['id'] = @$rs['ID'];
                                    $out['s'] = @$rs['Section'];
                                } else {
                                    // match parentsection/section
                                    $rs = safe_row("name, lft", 'txp_section', "lower(name) like '" . doSlash($u2) . "' AND lower(parent)='" . doSlash($u1) . "' limit 1");
                                    if (count($rs)) {
                                        // check path TODO: move to function
                                        $rs_path = safe_rows("name", "txp_section", "lft <= " . $rs['lft'] . " and ((rgt-lft) > 1 OR lft = " . $rs['lft'] . ") and name != 'default' order by lft");
                                        $path = '/';
                                        for ($i = 0; $i < count($rs_path); $i++) {
                                            $path .= $rs_path[$i]['name'] . '/';
                                        }
                                        if ($path == '/' . implode('/', $url_chunks) . '/') {
                                            $out['s'] = @$rs['name'];
                                        }
                                    }
                                }
                            }
                            break;
                            /*
                            								case 'title_only':
                            										$rs = lookupByTitle($u1);
                            										$out['id'] = @$rs['ID'];
                            										$out['s'] = (empty($rs['Section']) ? ckEx('section', $u1) : $rs['Section']);
                            								break;
                            
                            								case 'id_title':
                            										if (is_numeric($u1) && ckExID($u1))
                            										{
                            												$rs = lookupByID($u1);
                            												$out['id'] = (!empty($rs['ID'])) ? $rs['ID'] : '';
                            												$out['s'] = (!empty($rs['Section'])) ? $rs['Section'] : '';
                            										}
                            										else
                            										{
                            												# We don't want to miss the /section/ pages
                            												$out['s']= ckEx('section',$u1)? $u1 : '';
                            										}
                            								break; */
                    }
            }
        } else {
            $out['s'] = 'default';
        }
        //print_r($out);
        if (isset($out['id'])) {
            $_GET['id'] = $out['id'];
        }
        if (isset($out['s'])) {
            $_GET['s'] = $out['s'];
        }
    }
}
Exemple #7
0
 function l10n_lang_list($atts)
 {
     global $thisarticle, $l10n_language, $is_article_list, $pretext, $prefs;
     extract(lAtts(array('title' => '', 'on404' => '', 'current_class' => 'l10n_current', 'language_class' => 'long', 'list_class' => 'l10n_lang_list', 'show_empty' => '', 'link_current' => '', 'display' => 'native', 'article_list' => $is_article_list, 'surpress_current' => '', 'empty_title' => '', 'appendslash' => '', 'wraptag' => 'ul', 'break' => 'li', 'hide_langs' => ''), $atts));
     $on404 = !empty($on404);
     # User marked this list as a 404 special lookup list.
     $show_empty = !empty($show_empty);
     $link_current = !empty($link_current);
     $surpress_current = !empty($surpress_current);
     $break = $wraptag == 'select' ? 'option' : $break;
     // Ensure 'option' break tag if select used
     $appendslash = !empty($appendslash);
     $processing404 = $pretext['status'] === '404';
     $messy_urls = $pretext['permlink_mode'] === 'messy';
     $category_list = !empty($pretext['c']);
     $get_style_cat = gps('c');
     $processingcats = $category_list && !$messy_urls && !$get_style_cat;
     # Don't process (localise) category list urls in messy mode.
     $author_list = !empty($pretext['author']);
     $get_style_auth = gps('author');
     $processingauths = $author_list && !$messy_urls && !$get_style_auth;
     # Don't process (localise) author list urls in messy mode.
     $list = array();
     static $alangs;
     $slangs = MLPLanguageHandler::get_site_langs();
     $hide_langs = do_list(trim($hide_langs));
     $slangs = array_diff($slangs, $hide_langs);
     $section = empty($pretext['s']) ? '' : $pretext['s'];
     $id = $pretext['id'];
     $subpath = preg_quote(preg_replace("/https?:\\/\\/.*(\\/.*)/Ui", "\$1", hu), "/");
     $uri = preg_replace("/^{$subpath}/i", "/", serverSet('REQUEST_URI'));
     #$uri = preg_replace("/^$subpath/i" , "/" , rtrim(serverSet('REQUEST_URI'),'/'));
     $parts = chopUrl($uri);
     //echo br , "l10n_lang_list(" , var_dump($atts) , ") Section($section) ID($id)" ;
     //echo br , 'uri = ' , $uri;
     //echo br , "parts = " , var_dump( $parts );
     $name_mappings = array();
     if ($processingcats || $processingauths) {
         # echo br , 'Processing by category or author : ';
         $info = safe_rows_start('name,lang,data', 'txp_lang', "`name` IN ('category','author')");
         if ($info and mysql_num_rows($info) > 0) {
             while ($r = nextRow($info)) {
                 $name_mappings[$r['name']][$r['lang']] = urlencode($r['data']);
             }
         }
         # echo var_dump( $name_mappings ) . br ;
     }
     if ($on404 or $processing404) {
         #
         #	Find the section and id of the faulting article (if possible)...
         #
         if (empty($id)) {
             $id = gps('id');
         }
         # Try out a messy match first
         if (empty($id)) {
             extract($parts);
             //echo br , 'permlink_mode = ' , $prefs['permlink_mode'];
             switch ($prefs['permlink_mode']) {
                 case 'section_id_title':
                     $id = $u1;
                     break;
                 case 'year_month_day_title':
                     $when = "{$u0}-{$u1}-{$u2}";
                     $rs = safe_row("ID,Section", L10N_MASTER_TEXTPATTERN, "posted like '" . doSlash($when) . "%' and url_title like '" . doSlash($u3) . "' and Status >= 4 limit 1");
                     $id = !empty($rs['ID']) ? $rs['ID'] : '';
                     break;
                 case 'section_title':
                     $rs = safe_row("ID,Section", L10N_MASTER_TEXTPATTERN, "url_title like '" . doSlash($u1) . "' AND Section='" . doSlash($u0) . "' and Status >= 4 limit 1");
                     $id = @$rs['ID'];
                     break;
                 case 'title_only':
                     $rs = safe_row('ID', L10N_MASTER_TEXTPATTERN, "url_title like '" . doSlash($u0) . "' and Status >= 4 limit 1");
                     $id = @$rs['ID'];
                     break;
                 case 'id_title':
                     $id = $u0;
                     break;
             }
         }
         if (!empty($id) and is_numeric($id)) {
             $article_list = false;
         } else {
             return '';
         }
         #
         #	Make sure we show all alternatives, even if they are in the current language...
         #
         $link_current = true;
     }
     $show_title = !empty($title);
     if (!$article_list) {
         if (!isset($alangs) or !is_array($alangs)) {
             $alangs = _l10n_get_alternate_mappings($id, 'nothing', true);
         }
         //echo br , 'alangs = ' , var_dump( $alangs );
         if ($show_title) {
             $show_title = !empty($alangs);
         }
     }
     if ($show_title) {
         $title = tag($title, 'p') . n;
     } else {
         $title = '';
     }
     foreach ($slangs as $lang) {
         $codes = MLPLanguageHandler::compact_code($lang);
         $short = $codes['short'];
         $long = $codes['long'];
         $dir = MLPLanguageHandler::get_lang_direction_markup($lang);
         #
         #	Surpress the current item when needed...
         #
         $current = $l10n_language['long'] === $lang;
         if ($current && $surpress_current) {
             continue;
         }
         switch ($display) {
             case 'short':
                 $lname = $short;
                 break;
             case 'long':
                 $lname = $long;
                 break;
             case 'native+':
                 $lname = MLPLanguageHandler::get_native_name_of_lang($lang) . " [{$short}]";
                 break;
             case 'native++':
                 $lname = MLPLanguageHandler::get_native_name_of_lang($lang) . " [{$long}]";
                 break;
             default:
                 $lname = MLPLanguageHandler::get_native_name_of_lang($lang);
                 break;
         }
         if ($article_list) {
             #
             #	No individual ID but we should be able to serve all the languages
             # so use the current url and inject the language component into each one...
             #
             $text = tag($lname, 'span', $dir);
             #
             #	Prep the line class...
             #
             $class = 'short' === $language_class ? $short : $lang;
             if ($current) {
                 $class .= ' ' . $current_class;
             }
             $class = ' class="' . $class . '"';
             if (!$current or $link_current) {
                 #$subpath = preg_quote(preg_replace("/https?:\/\/.*(\/.*)/Ui","$1",hu),"/");
                 #$uri = preg_replace("/^$subpath/i" , "/" , serverSet('REQUEST_URI'));
                 if ($processing404) {
                     $uri = '';
                 }
                 if ($processingcats || $processingauths) {
                     #
                     #	Category lists are a special case. For this to work, we need to
                     # replace the local 'category'/'author' string with it's name in the target language.
                     #
                     #	Not doing the replace results in 404 errors.
                     #
                     $type = $processingcats ? 'category' : 'author';
                     $target_name = $name_mappings[$type][$lang];
                     #echo br . $uri . ' => ' . $lang . ' = ' . $target_name . '(' . urldecode($target_name) . ')';
                     $chunks = explode('/', ltrim($uri, '/'));
                     $chunks[0] = $target_name;
                     $uri = '/' . join('/', $chunks);
                 }
                 if (!$processing404 && $appendslash && $uri == '') {
                     $uri = '/';
                 }
                 if ($break == 'option') {
                     $line = $text;
                     $class .= ' value="' . hu . $short . $uri . '"';
                 } else {
                     $line = '<a href="' . hu . $short . $uri . '">' . $text . '</a>';
                 }
             } else {
                 if ($break == 'option') {
                     $class .= ' selected="selected"';
                 }
                 $line = $text;
             }
             $list[] = tag($line, $break, $class);
         } else {
             #
             #	If a translation exists for that language then we
             # build a valid url to it and make it active in the list, otherwise include it in the
             # list but wihtout the hyper-link.
             #
             #	The active page is marked up with a css class.
             #
             if (array_key_exists($lang, $alangs)) {
                 $record = $alangs[$lang];
                 $lang_rendition_title = $record['Title'];
                 $lang_rendition_id = $record['ID'];
                 $text = $lname;
                 if ($processing404) {
                     $text = strong($text) . sp . ':' . sp . $lang_rendition_title;
                 }
                 $text = tag($text, 'span', $dir);
                 #
                 #	Prep the line class...
                 #
                 $class = 'short' === $language_class ? $short : $lang;
                 if ($current) {
                     $class .= ' ' . $current_class;
                 }
                 $class = ' class="' . $class . '"';
                 if (!$current or $link_current) {
                     $url = permlinkurl($record);
                     $f = hu;
                     $url = str_replace($f, $f . $short . '/', $url);
                     if ($break == 'option') {
                         $line = $text;
                         $class .= ' value="' . $url . '"';
                     } else {
                         $line = '<a href="' . $url . '">' . $text . '</a>';
                     }
                 } else {
                     if ($break == 'option') {
                         $class .= ' selected="selected"';
                     }
                     $line = $text;
                 }
                 $list[] = tag($line, $break, $class);
             } else {
                 if ($show_empty) {
                     $list[] = tag($lname, $break);
                 }
             }
         }
     }
     $selopts = '';
     if (!empty($list)) {
         if ($wraptag == 'select') {
             $selopts .= ' onchange="location.href=this.options[selectedIndex].value"';
         }
         $list = $title . tag(join("\n\t", $list), $wraptag, " class=\"{$list_class}\"" . $selopts);
     } else {
         $list = tag($empty_title, 'p') . n;
     }
     return $list;
 }