Exemplo n.º 1
0
/**
 * Make a link to an entry, using the settings for how they should be formed.
 *
 * @param mixed $data
 * @param string $weblog
 * @param string $anchor
 * @param string $parameter
 * @param boolean $para_weblog
 */
function make_filelink($data = "", $weblog = "", $anchor = "comm", $parameter = "", $para_weblog = false)
{
    global $db, $Weblogs, $Current_weblog, $Cfg, $Paths;
    // Set the weblog, if it isn't set already.
    if ($weblog == "") {
        $weblog = $Current_weblog;
    }
    // Set the 'log_url' path, if it isn't set already.
    if (empty($Paths['log_url'])) {
        $Paths['log_url'] = dirname(get_log_url('index')) . "/";
        if ($Paths['log_url'] == "//") {
            $Paths['log_url'] = "/";
        }
    }
    // Set $entry (and $code)
    if (empty($data)) {
        // Using current entry - the db object must exist and be set
        $entry = $db->entry;
        $code = $entry['code'];
    } elseif (is_array($data)) {
        // Using passed/inputed entry
        $entry = $data;
        $code = $entry['code'];
    } elseif (is_numeric($data)) {
        $code = $data;
        // Using the entry with the given $code
        // If it's not the current one, we need to load it
        if (!isset($db) || $code != $db->entry['code']) {
            $fl_db = new db(FALSE);
            $fl_db->read_entry($code);
            $entry = $fl_db->entry;
        } else {
            $entry = $db->entry;
        }
    } else {
        debug('Entry code must be an integer/numeric - no output.');
        return;
    }
    if (!$Weblogs[$weblog]['live_entries']) {
        $filelink = $Paths['pivot_url'] . $Weblogs[$weblog]['entry_path'] . $Weblogs[$weblog]['entry_filename'];
    } else {
        if (isset($Cfg['mod_rewrite']) && $Cfg['mod_rewrite'] != 0 && $entry['date'] != "") {
            // if $entry['date'] is not set, we cant make the non-crufty url,
            // and we fall back to the crufty one..
            switch ($Cfg['mod_rewrite']) {
                // archive/2005/04/20/title_of_entry
                case "1":
                    $name = strlen($entry['title']) > 1 ? $entry['title'] : substr(strip_tags($entry['introduction']), 0, 70);
                    $name = safe_string(trim($name), TRUE);
                    if (strlen($name) > 30) {
                        $name = substr($name, 0, 30);
                    }
                    list($yr, $mo, $da, $ho, $mi) = split("-", $entry['date']);
                    $filelink = $Paths['log_url'] . "/archive/{$yr}/{$mo}/{$da}/" . $name;
                    // Reverted it to original, since suggested fix breaks htaccess mod rewrite
                    // $filelink = $Paths['log_url'] . $Weblogs[$weblog]['archive_path'] . "/$yr/$mo/$da/".$name;
                    break;
                    // archive/2005-04-20/title_of_entry
                // archive/2005-04-20/title_of_entry
                case "2":
                    $name = strlen($entry['title']) > 1 ? $entry['title'] : substr(strip_tags($entry['introduction']), 0, 70);
                    $name = safe_string(trim($name), TRUE);
                    if (strlen($name) > 30) {
                        $name = substr($name, 0, 30);
                    }
                    list($yr, $mo, $da, $ho, $mi) = split("-", $entry['date']);
                    $filelink = $Paths['log_url'] . "/archive/{$yr}-{$mo}-{$da}/" . $name;
                    // Reverted it to original, since suggested fix breaks htaccess mod rewrite
                    // $filelink = $Paths['log_url'] . $Weblogs[$weblog]['archive_path'] . "/$yr-$mo-$da/".$name;
                    break;
                    // entry/1234
                // entry/1234
                case "3":
                    $filelink = $Paths['log_url'] . "/entry/" . $code;
                    break;
                    // entry/1234/title_of_entry
                // entry/1234/title_of_entry
                case "4":
                    $name = strlen($entry['title']) > 1 ? $entry['title'] : substr(strip_tags($entry['introduction']), 0, 70);
                    $name = safe_string(trim($name), TRUE);
                    if (strlen($name) > 30) {
                        $name = substr($name, 0, 30);
                    }
                    $filelink = $Paths['log_url'] . "/entry/" . $code . "/{$name}";
                    break;
            }
        } else {
            $filelink = $Paths['pivot_url'] . "entry.php?id=%1{$parameter}";
        }
    }
    // Add a weblog parameter if asked for, or if multiple weblogs, and the current weblog is not the first one..
    if ($para_weblog || para_weblog_needed($weblog)) {
        if (!$Weblogs[$weblog]['live_entries']) {
            $filelink .= "?w=" . para_weblog($weblog);
        } else {
            if (strpos($filelink, "?") > 0) {
                // if there's already a '?' in the link, we add the parameter using &w=
                $filelink .= "&w=" . para_weblog($weblog);
            } else {
                // else we treat it as an extra 'folder'
                $filelink .= "/" . para_weblog($weblog);
            }
        }
    }
    $filelink = fixPath($filelink);
    $filelink = str_replace("%1", $code, $filelink);
    $filelink = format_date("", $filelink, $entry['title']);
    if ($anchor != "") {
        $filelink .= "#" . $anchor;
    }
    return $filelink;
}
Exemplo n.º 2
0
        $Pivot_Vars['t'] = basename($Weblogs[$Pivot_Vars['w']]['extra_template']);
    } else {
        $Pivot_Vars['t'] = "";
    }
} else {
    $Pivot_Vars['t'] = basename($Pivot_Vars['t']);
}
// If non-crufty URLs (mod_rewrite) is enabled and someone tries to
// access the crufty URL, redirect. (Search engine friendly.)
list($request_script) = explode("?", $_SERVER['REQUEST_URI']);
if ($Cfg['mod_rewrite'] && basename($request_script) == "archive.php" && $Pivot_Vars['c'] != "") {
    $Current_weblog = $Pivot_Vars['w'];
    set_paths_log_url();
    $filelink = $Paths['log_url'] . "category/" . $Pivot_Vars['c'];
    // Handle addition query parameters
    if (para_weblog_needed($Pivot_Vars['w'])) {
        $query = '?w=' . para_weblog($Pivot_Vars['w']) . '&';
    } else {
        $query = '?';
    }
    unset($_GET['c']);
    unset($_GET['w']);
    foreach ($_GET as $key => $value) {
        $query .= $key . '=' . urlencode($value) . '&';
    }
    if ($query != '?') {
        $filelink .= substr($query, 0, -1);
    }
    // Redirect
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: {$filelink}");
Exemplo n.º 3
0
/**
 * Make a link to any given $tag.
 *
 * @param string $tag
 * @param string $template
 * @return string
 */
function tagLink($tag, $template = "")
{
    global $Paths, $Current_weblog, $Cfg;
    $tag = normalizeTag($tag);
    if ($Cfg['mod_rewrite'] == 0 && $Cfg['mod_taglinks'] != 1) {
        $link = $Paths['pivot_url'] . "tags.php?tag=" . urlencode($tag);
        if (para_weblog_needed($Current_weblog)) {
            $link .= "&w=" . para_weblog($Current_weblog);
        }
        if ($template != "") {
            $link .= "&t={$template}";
        }
        return $link;
    } else {
        if ($Cfg['mod_rewrite'] == 0) {
            $link = $Paths['pivot_url'] . "tags.php";
            if (para_weblog_needed($Current_weblog)) {
                $link .= "?w=" . para_weblog($Current_weblog);
                if ($template != "") {
                    $link .= "&t={$template}";
                }
            } else {
                if ($template != "") {
                    $link .= "?t={$template}";
                }
            }
            return $link . "/" . urlencode($tag);
        } else {
            $link = $Paths['log_url'] . "tag";
            if (para_weblog_needed($Current_weblog)) {
                $link .= "/w=" . para_weblog($Current_weblog);
            }
            if ($template != "") {
                $link .= "/t={$template}";
            }
            return $link . "/" . urlencode($tag);
        }
    }
}
Exemplo n.º 4
0
/**
 * Display a small tagcloud.
 *
 * @param integer $amount
 * @param integer $minsize
 * @param integer $maxsize
 * @param string $template
 * @return string
 */
function snippet_tagcloud($amount = 0, $minsize = 0, $maxsize = 0, $template = "")
{
    global $Paths, $Current_weblog, $Cfg;
    if ($minsize == 0) {
        $minsize = 8;
    }
    if ($maxsize == 0) {
        $maxsize = 17;
    }
    if ($amount == 0) {
        $amount = 20;
    }
    $tagcosmos = getTagCosmos($amount, $Current_weblog);
    // This is the factor we need to calculate the EM sizes. $minsize is 1 em,
    // $maxsize will be ($maxsize / $minsize) EM.. Take care if $tagcosmos['maxvalue'] == $tagcosmos['minvalue']
    if ($tagcosmos['maxvalue'] != $tagcosmos['minvalue']) {
        $factor = ($maxsize - $minsize) / ($tagcosmos['maxvalue'] - $tagcosmos['minvalue']) / $minsize;
    } else {
        $factor = 0;
    }
    foreach ($tagcosmos['tags'] as $key => $value) {
        // Calculate the size, depending on value.
        $nSize = sprintf("%0.2f", 1 + ($value - $tagcosmos['minvalue']) * $factor);
        $htmllinks[$key] = sprintf("<a style=\"font-size:%sem;\" href=\"%s\"\r\n\t\t  rel=\"tag\" title=\"%s: %s, %s %s\">%s</a>\n", $nSize, tagLink($key, $template), lang('tags', 'tag'), $key, $value, lang('userbar', 'entries'), $key);
    }
    $output = "<div id='tagcloud' style='font-size: {$minsize}px;'>";
    $output .= implode(" ", $htmllinks);
    if (para_weblog_needed($Current_weblog)) {
        $para .= "?w=" . para_weblog($Current_weblog);
        $para .= $template != "" ? "&amp;t={$template}" : "";
    } else {
        $para = $template != "" ? "?t={$template}" : "";
    }
    if ($Cfg['mod_rewrite'] == 0) {
        $link = $Paths['pivot_url'] . "tags.php";
    } else {
        $link = $Paths['log_url'] . "tags";
    }
    $output .= sprintf('<em>(<a href="%s%s">%s</a>)</em>', $link, $para, lang('general', 'all'));
    $output .= "</div>";
    return $output;
}