# - Added Wordpress post status configuration
# - Integratd "Don't post empty lists" patch by Zach Paine (?)
# - Changed Extended field to be printed only when non-empty
# - Added optional tag linking (a bit lower than the rest of configuration).
#
# Configure these:
$wp_path = '/var/www/wordpress'; # Absolute path to WP installation, no trailing /
$del_user = 'myuser'; # del.icio.us username
$del_password = 'mypass'; # del.icio.us username
$del_showlink = true; # Show link to your del.icio.us page?
$wp_userid = 2; # User ID to post in
$wp_catid = 1; # Category to put daily del.icio.us links in
$wp_allowcomments = 'open'; # Allow comments on all links? (open or closed)
$wp_allowpings = 'open'; # Allow pingbacks on all links? (open or closed)
$wp_post_status = 'publish'; # Post status. Use one of the following: 'draft','publish','private'
$wp_posttitle = 'Daily del.icio.us bookmarks'; # Title for your daily del.icio.us posts
$wp_postname = 'delicious'; # Post name (for permalinks, etc)
# Stop configuring now!
require_once($wp_path . '/wp-config.php');
function startElement($parser, $name, $attrs)
{
global $content;
### Configure linking
$tag_link = 'yes'; # Use 'yes' to link to tag pages or 'no' to leave plain text
if ($name == "POSTS") {
$content = $content . 'Shared bookmarks for del.icio.us user '
. $attrs["USER"]
. " on " . $attrs["DT"] . "\n
\n";
}
else {
global $empty;
$empty = false;
# Print the URL
$content = $content . ' - '
. htmlspecialchars($attrs['DESCRIPTION'])
. "";
# Print extended if there is any
if (strlen($attrs['EXTENDED']) > 0) {
$content = $content . ' -- ' . htmlspecialchars($attrs['EXTENDED']);
}
# Print tags
$content = $content . "\n" . 'Tagged as: ';
# Link tags to global tag pages
if ($tag_link == 'yes') {
$tags = explode(' ', htmlspecialchars($attrs['TAG']));
foreach ($tags as $tag) {
$content = $content . '' . $tag . ' ';
}
}
# Don't link tags
else {
$content = $content . htmlspecialchars($attrs['TAG']);
}
$content = $content . "
\n";
}
}
function endElement($parser, $name)
{
global $content;
if ($name == "POSTS") {
$content = $content . "
";
}
}
# Get today, and make timestamp
$today = getdate();
$date = mktime(0,0,0,$today['mon'], $today['mday'], $today['year']);
# Get Dates for Post
$now = current_time('mysql');
$now_gmt = current_time('mysql', 1);
$empty = true;
$dt = date("Y-m-d");
$fp = fopen("http://$del_user:$del_password@del.icio.us/api/posts/get?dt=$dt", "r");
$content = "";
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
if ($empty)
return;
# Build Query
$query = "INSERT INTO $tableposts "
. "(`post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_status`, `comment_status`, `ping_status`, `post_name`, `post_modified`, `post_modified_gmt`) "
. "VALUES "
. "(" . $wp_userid . ", '" . $now . "', '" . $now_gmt . "', '" . addslashes($content) . "', '" . addslashes($wp_posttitle) . "', '$wp_post_status', '" . $wp_allowcomments . "', '" . $wp_allowpings . "', '" . $wp_postname . "', '" . $now . "', '" . $now_gmt . "');";
# Run Query
$wpdb->query($query);
# Get ID for category
$post_ID = $wpdb->get_var("SELECT ID FROM $tableposts ORDER BY ID DESC LIMIT 1");
# Build category query
$query = "INSERT INTO $tablepost2cat "
. "(`post_id`, `category_id`) "
. "VALUES "
. "('" . $post_ID . "', '" . $wp_catid . "');";
# Run Category Query
$wpdb->query($query);
?>