Пример #1
0
function blog_comment_save($name, $website, $text, $date = false)
{
    $base = _blog_comment_base();
    # Sanitize and HTMLize input
    $name = input_sanitize_smarty(strip_tags(trim($name)));
    $website = input_sanitize_smarty(strip_tags(trim($website)));
    $text = trim($text);
    $mail = strip_tags($text);
    $html = input_htmlize(input_sanitize_smarty($text), "\t\t");
    # If they gave a website, show that with their name
    if (preg_match('!^https?://.!', $website)) {
        $link = "<a href=\"{$website}\">{$name}</a>";
    } else {
        $link = $name;
    }
    # Take either the passed date or now
    $date = date($GLOBALS['DATEFORMAT_COMMENT'], $date ? strtotime($date) : time());
    # Save the comment
    file_put_contents("{$base}.comments.html", "\t<li>\n{$html}\t\t<p>&mdash; {$link} &mdash; {$date}</p>\n\t</li>\n\n", FILE_APPEND | LOCK_EX);
    file_put_contents("{$base}.count", '.', FILE_APPEND | LOCK_EX);
    # Email the site owner
    global $FQDN;
    mail($GLOBALS['MAIL'], "New comment!", "Post: http://{$FQDN}{$GLOBALS['URL']}\r\n\r\n" . "Name: {$name}\r\nWebsite: {$website}\r\n\r\n{$mail}\r\n", "From: Bashpress <noreply@{$FQDN}>\r\n");
}
Пример #2
0
function blog_publish_feed($path, $file, $timestamp, $title, $body, $replace_only = false)
{
    global $smarty;
    $permalink = "http://{\$FQDN}{$path}/{$file}";
    $date_published = date("c", $timestamp);
    # Get the DOM of the feed
    $dom = new DOMDocument();
    if (file_exists("{$smarty->template_dir}/.feed.atom")) {
        $dom->load("{$smarty->template_dir}/.feed.atom");
    } else {
        $dom->loadXML(<<<EOD
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
\t<title>{\$TITLE}</title>
\t<link href="http://{\$FQDN}/feed" rel="self"/>
\t<link href="http://{\$FQDN}/" rel="alternate"/>
\t<id>http://{\$FQDN}/feed</id>
\t<updated>2008-09-03T23:17:43-07:00</updated>
\t<author><name>{\$AUTHOR}</name></author>
</feed>
EOD
);
    }
    $feed = $dom->documentElement;
    # Find and remove the entry we're displacing or replacing
    #   In replace_only mode this will return if the entry isn't found
    $index = false;
    $entries = $feed->getElementsByTagName('entry');
    $ii = $entries->length;
    for ($i = 0; $i < $ii; ++$i) {
        $entry = $entries->item($i);
        if ($entry->getElementsByTagName('id')->item(0)->firstChild->nodeValue == $permalink) {
            $index = $i;
            $feed->removeChild($entry);
            $date_updated = date("c");
            break;
        }
    }
    if (false === $index) {
        if ($replace_only) {
            return;
        } else {
            $index = 0;
            if (15 == $entries->length) {
                $feed->removeChild($entries->item(14));
            }
            $date_updated = $date_published;
        }
    }
    # Update the feed properties
    $updated = $feed->getElementsByTagName('updated')->item(0);
    $updated->removeChild($updated->firstChild);
    $updated->appendChild($dom->createTextNode($date_updated));
    # Create the new entry
    $entry = $dom->createElement('entry');
    $entry->appendChild($dom->createElement('title', htmlspecialchars(input_sanitize_smarty($title))));
    $link = $dom->createElement('link');
    $link->setAttribute('href', $permalink);
    $link->setAttribute('rel', "alternate");
    $entry->appendChild($link);
    $entry->appendChild($dom->createElement('id', $permalink));
    $entry->appendChild($dom->createElement('published', $date_published));
    $entry->appendChild($dom->createElement('updated', $date_updated));
    $author = $dom->createElement('author');
    $author->appendChild($dom->createElement('name', "{\$AUTHOR}"));
    $entry->appendChild($author);
    $content = $dom->createElement('content', htmlspecialchars(input_sanitize_smarty($body)));
    $content->setAttribute('type', 'html');
    $entry->appendChild($content);
    # Insert the new entry into the DOM
    if ($entries->length <= $index) {
        $feed->appendChild($entry);
    } else {
        $feed->insertBefore($entry, $entries->item($index));
    }
    # Serialize and save
    file_put_contents("{$smarty->template_dir}/.feed.atom", $dom->saveXML(), LOCK_EX);
}