Exemplo n.º 1
0
/**
 * Process CMS tags into HTML for archives.
 */
function cms_tag_archive($tag_attr, $tag_default)
{
    global $db, $Cfg, $Paths, $current_date, $Weblogs, $Current_weblog, $diffdate_lastformat, $even_odd;
    $order = get_attr_value('order', $tag_attr);
    if ($order == "firsttolast") {
        $order = "asc";
    } else {
        $order = "desc";
    }
    $countshow = 0;
    $output = "";
    // to force the 'diffdate' to start anew on each (sub)weblog..
    $diffdate_lastformat = "";
    $subweblog = get_attr_value('subweblog', $tag_attr);
    $template = $Paths['templates_path'] . $Weblogs[$Current_weblog]['sub_weblog'][$subweblog]['template'];
    if (file_exists($template) && $Weblogs[$Current_weblog]['sub_weblog'][$subweblog]['template'] != "") {
        $tag_default_orig = implode("", file($template));
    } else {
        debug("cant open file: " . $template);
        debug(" - for weblog " . $Current_weblog . ", subweblog " . $subweblog . " - {$tag_attr}, {$tag_default} - ");
        $tag_default_orig = "";
        //debug_printbacktrace();
    }
    // safety check to prevent recursive weblogs..
    if (preg_match("/\\[\\[weblog:(.*)(:[0-9]*)?\\]\\]/mUi", $tag_default_orig)) {
        $tag_default_orig = "<p>(You can't recursively use [weblogs]!)</p>";
    }
    $show = $Weblogs[$Current_weblog]['sub_weblog'][$subweblog]['num_entries'];
    $cats = $Weblogs[$Current_weblog]['sub_weblog'][$subweblog]['categories'];
    list($start_date, $stop_date) = getdaterange($db->entry['date'], $Weblogs[$Current_weblog]['archive_unit']);
    debug("Archive: start {$start_date}, stop {$stop_date}, entry " . $db->entry['code']);
    $db->disallow_write();
    if ($order == 'asc') {
        $list_entries = $db->getlist_range($start_date, $stop_date, "", $cats, TRUE, "publish");
    } else {
        $list_entries = $db->getlist_range($start_date, $stop_date, "", $cats, FALSE, "publish");
    }
    foreach ($list_entries as $list_entry) {
        $entry = $db->read_entry($list_entry['code']);
        if (!isset($entry['status']) || $entry['status'] == 'publish') {
            // for 'even' and 'odd' messages..
            if ($even_odd == 1) {
                $even_odd = 0;
            } else {
                $even_odd = 1;
            }
            // include an anchor, if it's not set manually with the [[id_anchor]] tag
            if (strpos($tag_default_orig, "[[id_anchor]]") == 0) {
                $entry_html = '<span id="e' . $db->entry['code'] . '"></span>';
            } else {
                $entry_html = "";
            }
            $entry_html .= parse_step4($tag_default_orig);
            $output .= $entry_html;
        }
    }
    return $output;
}
Exemplo n.º 2
0
    reset($Weblogs);
    $Current_weblog = key($Weblogs);
}
// Display the search results.
LoadWeblogLanguage($Weblogs[$Current_weblog]['language']);
$db = new db();
$result = "\n<div class='pivot-search-result'>\n";
$result .= search_result();
$result .= "<!-- Search took " . timetaken() . " seconds -->\n";
$result .= "</div>\n";
unset($db->entry);
// Set the template for the tags page
if (!isset($Pivot_Vars['t']) || empty($Pivot_Vars['t'])) {
    if (isset($Weblogs[$Current_weblog]['extra_template']) && $Weblogs[$Current_weblog]['extra_template'] != "") {
        $template = $Weblogs[$Current_weblog]['extra_template'];
    } else {
        $template = $Weblogs[$Current_weblog]['archive_template'];
    }
} else {
    $template = $Pivot_Vars['t'];
}
$template_html = load_template($template);
$template_html = replace_subweblogs_templates($template_html, $result);
if (!$template_html) {
    piv_error("Template error", "Could not load template file, <i>" . htmlspecialchars($template) . "</i>, because it doesn't exist.");
} else {
    $output = $template_html;
    $output = parse_step4($output);
}
echo $output;
flush();
Exemplo n.º 3
0
function make_default()
{
    global $Weblogs, $Current_weblog, $db, $entry;
    $db = new db();
    $arc_list = "";
    if (file_exists($pivot_dir . "db/ser-archive_overview_cat.php") && file_exists($pivot_dir . "db/ser-archive_overview_cat.php")) {
        $arc_array_cat = load_serialize($pivot_dir . "db/ser-archive_overview_cat.php", TRUE);
        $arc_array_mon = load_serialize($pivot_dir . "db/ser-archive_overview_mon.php", TRUE);
        // if over three three days old.
        if (mktime() - filemtime($pivot_dir . "db/ser-archive_overview_cat.php") > 259200) {
            unlink($pivot_dir . "db/ser-archive_overview_cat.php");
            unlink($pivot_dir . "db/ser-archive_overview_mon.php");
        }
    } else {
        $list_entries = $db->getlist_range("1970-01-01-00-00", "2020-12-31-23-59", "", "", FALSE);
        // iterate through all of the entries, building the arrays for both the
        // per-month and per-category lists..
        foreach ($list_entries as $list_entry) {
            $date = format_date($list_entry['date'], $Weblogs[$Current_weblog]['fulldate_format']);
            $link = make_filelink($list_entry['code']);
            list($ye, $mo) = explode("-", $list_entry['date']);
            if (isset($list_entry['category'])) {
                foreach ($list_entry['category'] as $cat) {
                    $arc_array_cat[$cat][$ye] = 1;
                }
            }
            $arc_array_mon[$ye][$mo] = 1;
        }
        save_serialize($pivot_dir . "db/ser-archive_overview_cat.php", $arc_array_cat, FALSE);
        save_serialize($pivot_dir . "db/ser-archive_overview_mon.php", $arc_array_mon, FALSE);
    }
    $current_cats = find_cats_in_weblog($Current_weblog);
    // build the per-month list
    foreach ($arc_array_mon as $ye => $months) {
        $arc_list .= "<p><b>{$ye}:</b><br />\n";
        ksort($months);
        $temp_arr = array();
        foreach ($months as $mo => $dummy) {
            $temp_arr[] = sprintf("<a href=\"%s/%s/\">%s</a>\n", $ye, $mo, lang('months', -1 + $mo));
        }
        $arc_list .= implode(", ", $temp_arr) . "<br /></p>\n";
    }
    // build the per-category list
    ksort($arc_array_cat);
    if (count($arc_array_cat) > 1) {
        foreach ($arc_array_cat as $cat => $year) {
            if (in_array($cat, $current_cats)) {
                $arc_list .= "<p><b>{$cat}:</b>\n";
                ksort($year);
                $temp_arr = array();
                foreach ($year as $ye => $dummy) {
                    $temp_arr[] = sprintf("<a href=\"%s/%s/\">%s</a>\n", $cat, $ye, $ye);
                }
                $arc_list .= implode(", ", $temp_arr) . "</p>\n";
            }
        }
    }
    // the search template for the current weblog
    if (isset($Weblogs[$Current_weblog]['extra_template']) && $Weblogs[$Current_weblog]['extra_template'] != "") {
        $template_html = load_template($Weblogs[$Current_weblog]['extra_template']);
    } else {
        $template_html = load_template($Weblogs[$Current_weblog]['archive_template']);
    }
    $template_html = replace_subweblogs_templates($template_html, $arc_list);
    $filename = $Weblogs[$Current_weblog]['archive_path'] . make_archive_name();
    if (!$template_html) {
        ErrorOut("Could not load template file: <i>{$template}</i> [does not exist]");
    } else {
        $output = $template_html;
        $output = parse_step4($output);
    }
    echo $output;
    flush();
}
Exemplo n.º 4
0
/**
 * The screen you'll see after submitting an entry. It stores the entry, updates the indices (pivot's
 * content indices, and the search index), rebuilds the frontpage and XML & Atom feeds, and then it
 * displays a list of the latest entries.
 *
 */
function entrysubmit_screen()
{
    global $db, $config_array, $Pivot_Vars, $entry, $Cfg, $Users, $Paths, $Weblogs, $filtered_words;
    // check against unauthorised direct access.
    check_csrf();
    $db = new db();
    $entry = get_entry_from_post();
    if (!$entry['title'] == "" || !$entry['introduction'] == "" || !$entry['user'] == "") {
        // in this part, we remove the entry from the categories in which
        // the current user is not allowed to post entries
        foreach ($entry['category'] as $my_cat) {
            $allowed = explode("|", $Cfg['cat-' . $my_cat]);
            if (in_array($Pivot_Vars['user'], $allowed)) {
                $allowed_cats[] = $my_cat;
            } else {
                $message .= '<br />';
                $message .= sprintf(lang('entries', 'entry_catnopost'), $m_cat);
                debug("not in category: " . $my_cat);
            }
        }
        $entry['category'] = $allowed_cats;
        $db->set_entry($entry);
        if ($db->save_entry(TRUE)) {
            $message = sprintf(lang('entries', 'entry_saved_ok') . $message, '<i>' . trimtext($entry['title'], 25) . '</i>');
        } else {
            $message = sprintf(lang('entries', 'entry_saved_ok'), '<i>' . trimtext($entry['title'], 25) . '</i>');
        }
        // only trigger the ping if it's a new entry..
        if ($entry['code'] == ">" && $entry['status'] == "publish") {
            $ping = TRUE;
        } else {
            $ping = FALSE;
        }
        // only notify if entry is published, and is either new or status changed to publish.
        if ($entry['status'] == "publish") {
            if ($entry['code'] == ">" || $entry['oldstatus'] != "publish") {
                $notified = notify_new('entry', $db->entry);
                $notified = "<br /><br />" . $notified;
            }
        }
        // if the global index as they are made var is set - can continue
        if ('1' == $Cfg['search_index']) {
            /*
            			2004/10/16 =*=*= JM
            			an entry should only be indexed if both are true:
            			 - 'publish'==$entry['status']
            			 - current date is at least equal to $entry['publish_date']
            			I lie, there is another case...
            			it is conceivable that this is a timed publish AND the time has come
            			I will leave this to timed publish routines - if I can find them...
            			-> pvLib ... it's flagged
            and of course, providing that there is at least one
            			category where it would be indexed...
            something else that can't be tested... if the user changes a normal
            			publish to a timed-publish, or puts on hold when it was previously
            			normal. user should reindex in this case
            */
            // check status and date
            if ('publish' == $entry['status'] || 'timed' == $entry['status'] && $entry['publish_date'] <= date('Y-m-d-H-i')) {
                // categories...
                if (can_search_cats(cfg_cat_nosearchindex(), $entry['category'])) {
                    include_once 'modules/module_search.php';
                    update_index($db->entry);
                    debug('update search index: ' . $db->entry['code']);
                }
            }
        }
        // perhaps send a trackback ping.
        if ($Pivot_Vars['tb_url'] != "" && $entry['status'] == "publish") {
            debug("tburl: " . $Pivot_Vars['tb_url']);
            require_once 'includes/send_trackback.php';
            $weblogs = find_weblogs_with_cat($db->entry['category']);
            if (isset($Weblogs[$weblogs[0]])) {
                $my_url = $Paths['host'] . make_filelink($db->entry['code'], $weblogs[0], '');
                $weblog_title = $Weblogs[$weblogs[0]]['name'];
                debug("TRACKBACK ping: {$my_url}");
                $message .= '<br />';
                $message .= sprintf(lang('entries', 'entry_ping_sent'), $Pivot_Vars['tb_url']);
                $tb_urls = explode("\n", $Pivot_Vars['tb_url']);
                // make the contents of what to send with the trackback..
                $tb_contents = parse_step4($entry['introduction']);
                if ($Pivot_Vars['convert_lb'] == 2) {
                    $tb_contents = pivot_textile($tb_contents);
                } else {
                    if ($Pivot_Vars['convert_lb'] == 3 || $Pivot_Vars['convert_lb'] == 4) {
                        $tb_contents = pivot_markdown($tb_contents, $Pivot_Vars['convert_lb']);
                    }
                }
                $tb_contents = trimtext(strip_tags($tb_contents), 255);
                foreach ($tb_urls as $tb_url) {
                    $tb_url = trim($tb_url);
                    if (isurl($tb_url)) {
                        trackback_send($Pivot_Vars['tb_url'], $my_url, $entry['title'], $weblog_title, $tb_contents);
                    }
                }
            }
        }
        // Update the tags for this entry if it's published and remove the old tags if not
        if ($db->entry['status'] == 'publish') {
            writeTags($db->entry['keywords'], $_POST['f_keywords_old'], $db->entry['code']);
        } else {
            deleteTags($_POST['f_keywords_old'], $db->entry['code']);
        }
    }
    generate_pages($db->entry['code'], TRUE, TRUE, TRUE, $ping);
    entries_screen($message . $notified);
}
Exemplo n.º 5
0
/**
 * Displays a commentform if commenting is allowed and
 * remote IP isn't blocked.
 *
 * @param string $template
 * @return string
 */
function snippet_commentform($template = "_sub_commentform.html")
{
    global $Cfg, $db, $Paths, $Weblogs, $Current_weblog;
    // check for entry's allow_comments, blocked IP address or subweblog comments..
    if (isset($db->entry['allow_comments']) && $db->entry['allow_comments'] == 0 || ip_check_block($_SERVER['REMOTE_ADDR'])) {
        // if allow_comments set to 0, or current visitor has his ip blocked, then don't show form
        $output = "";
    } else {
        // else show it
        if (file_exists($Paths['templates_path'] . $template)) {
            $output = "[[include:" . $Paths['templates_path'] . "{$template}]]";
        } else {
            $output = "[[include:" . $Paths['templates_path'] . "commentform.html]]";
        }
        $output = parse_step4($output);
    }
    // append spam key to the comment form
    preg_match('/<input[ ]+type="hidden"[ ]+name="piv_code"[ ]+value="([^"]+)"/', $output, $matches);
    $code = $matches[1];
    $output = preg_replace('/<input[ ]+type="hidden"[ ]+name="piv_code/', '<input type="hidden" name="piv_spkey" value="' . md5($Cfg['server_spam_key'] . $code) . '" />' . "\n" . '<input type="hidden" name="piv_code', $output);
    // prefill the comment form on static (entry) pages
    if (!defined('LIVEPAGE')) {
        $ext = strtolower(getextension($Weblogs[$Current_weblog]['front_filename']));
        if (substr($ext, 0, 3) == "php") {
            // Include "set_output_paths" code?
            $output .= sprintf("<?php echo fill_comment_form(); ?>");
        }
    }
    return $output;
}
Exemplo n.º 6
0
/**
 * piv_error prints an error message, does a debug backtrace print out
 * and exits.
 *
 * On the admin pages it will just display the text on the current page and
 * add the page footer (if endpage is equal to 1). On weblog pages it will use
 * the extra page template for the current weblog.
 *
 * @param string $name
 * @param string $message
 * @param boolean $endpage
 */
function piv_error($name, $message, $endpage = 0)
{
    global $db, $Current_weblog, $Weblogs, $Pivot_Vars;
    if (!isset($db)) {
        $db = new db();
    }
    if (!isset($Current_weblog)) {
        reset($Weblogs);
        if (isset($Pivot_Vars['w'])) {
            $Current_weblog = weblog_from_para($Pivot_Vars['w']);
            if (!$Current_weblog) {
                $Current_weblog = key($Weblogs);
            }
        } else {
            $Current_weblog = key($Weblogs);
        }
    }
    debug_printbacktrace();
    $text = "<div class='pivot-error'>\n<h2>{$name}</h2>\n\n" . "<p>{$message}</p>\n</div>\n";
    if ($endpage == 1 || !defined('LIVEPAGE') && !defined('INWEBLOG')) {
        echo $text;
        PageFooter();
        exit;
    }
    // Use the extra template for the current weblog
    if (isset($Weblogs[$Current_weblog]['extra_template']) && $Weblogs[$Current_weblog]['extra_template'] != "") {
        $template_html = load_template($Weblogs[$Current_weblog]['extra_template']);
    } else {
        $template_html = load_template($Weblogs[$Current_weblog]['archive_template']);
    }
    // Match and replace the [[weblog]] tags for the error output
    $template_html = replace_subweblogs_templates($template_html, $text);
    if (!$template_html) {
        ErrorOut("Could not load template file: <i>{$template}</i> [does not exist]");
    } else {
        $output = $template_html;
        $output = parse_step4($output);
    }
    echo $output;
    flush();
    exit;
}