Created
February 5, 2011 04:43
-
-
Save cyu/812212 to your computer and use it in GitHub Desktop.
A modified version of Marc Nozell's yadd.php V1.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| # | |
| # A modified version of Marc Nozell's yadd.php V1.0 by Calvin Yu. | |
| # (http://blog.codeeg.com/) | |
| # | |
| # This is yadd.php V1.0 by Marc Nozell (marc@nozell.com) based on | |
| # Stephen Eyre's dailydelicious | |
| # (http://www.dot-totally.co.uk/dailydelicious.txt) | |
| # | |
| # See http://www.nozell.com/blog/ for the latest version of | |
| # 'yet another daily delicious' (yadd.php) | |
| # | |
| # USAGE: | |
| # | |
| # 1) Edit the section below. At the very least use your del.icio.us | |
| # username and password ($del_user/$del_password) | |
| # | |
| # 2) Put there file somewhere on the server where you run WordPress. | |
| # | |
| # 3) Arrange for this page to be hit once a day, say 11:30ish your | |
| # local time. del.icio.us seems to track UTC so depending on which | |
| # timezone you live in, some bookmarks from your yesterday may show | |
| # up. Consider using a simple cronjob that looks like this: | |
| # 30 23 * * * $HOME/bin/yadd.sh | |
| # where yadd.sh looks like this: | |
| # #!/bin/bash | |
| # curl http://www.yoursite.com/yadd.php | |
| # 4) In the morning edit the entry if you wish. I've tried to generate | |
| # pretty HTML so it will be simple to edit the entry. | |
| # | |
| # THINGS TO KEEP IN MIND | |
| # | |
| # Anyone that hits the URL for this script will cause your current | |
| # bookmarks to be dumped into WordPress. Clearly this is not | |
| # desirable. | |
| # | |
| # You have some options. The easiest is to keep this URL 'secret'. | |
| # Name it something unusual and put it in a non-obvious place. | |
| # Remember that if you display your web hit stats, the url will be | |
| # exposed. A better solution to use .htaccess to limit access. If | |
| # you do that remember to update the url wget uses to include the | |
| # username/password, something like this: | |
| # curl http://someuser:somepassword@www.yoursite.com/yadd.php | |
| # | |
| # Enjoy, | |
| # | |
| # -marc | |
| # Configure these: | |
| $wp_path = 'ENTER PATH HERE'; # Absolute path to WP installation, no trailing / | |
| $del_user = 'ENTER USER NAME'; # del.icio.us username | |
| $del_password = 'ENTER PASSWORD'; # del.icio.us username | |
| $del_showlink = true; # Show link to your del.icio.us page? | |
| $del_tag = null; # Filter by del.icio.us tag (optional) | |
| $wp_userid = 1; # 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_posttitle = 'Del.icio.us Bookmarks, For '; # Title for your daily del.icio.us posts | |
| $wp_postname = 'daily-delicious'; # Post name (for permalinks, etc) | |
| $wp_clear_cache = false; # Set this to true if you're using the wp-cache plugin | |
| $wp_tmp_file = '/tmp/delicious_posts.xml'; # On some systems, the delicious results needs | |
| # to be saved locally to a file for processing | |
| # Stop configuring now! | |
| require_once($wp_path . '/wp-config.php'); | |
| function startElement($parser, $name, $attrs) | |
| { | |
| global $content; | |
| if ($name == "POSTS") { | |
| $content = $content . "<p class=\"daily-delicious-header\">For " | |
| . date("l, F j Y") . " --</p>\n<ul class=\"daily-delicious\">\n"; | |
| } | |
| else { | |
| global $empty; | |
| $empty = false; | |
| $content = $content . ' <li><img src="http://images.websnapr.com/?url=' | |
| . htmlspecialchars($attrs['HREF']) | |
| . '" alt="Thumbnail of bookmark"/> <p><a href="' | |
| . htmlspecialchars($attrs['HREF']) | |
| . '" title="' | |
| . htmlspecialchars($attrs['HREF']) | |
| . '">' | |
| . htmlspecialchars($attrs['DESCRIPTION']) | |
| . "</a></p>\n" | |
| . "<p>" . htmlspecialchars($attrs['EXTENDED']) . "</p>"; | |
| if ($attrs['TAG']) { | |
| global $del_tag; | |
| $content = $content . "<div class=\"daily-delicious-tags\">Tag(s): "; | |
| foreach (split(" ", $attrs['TAG']) as $tag) { | |
| if ($tag != $del_tag) { | |
| $content = $content . "<a href=\"http://del.icio.us/popular/" | |
| . htmlspecialchars($tag) | |
| . "\">" | |
| . htmlspecialchars($tag) | |
| . "</a> "; | |
| } | |
| } | |
| $content = $content . "</div>"; | |
| } | |
| $content = $content . "</li>"; | |
| } | |
| } | |
| function endElement($parser, $name) | |
| { | |
| global $content; | |
| if ($name == "POSTS") { | |
| $content = $content . '</ul><p class="daily-delicious-footer">Bookmarks provided by <a href="http://del.icio.us/' . $del_user . '">del.icio.us</a>. Thumbnails courtesy of <a href="http://websnapr.com">WebSnapr</a>'; | |
| } | |
| } | |
| $empty = true; | |
| # 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); | |
| $dt = date("Y-m-d"); | |
| #$dt = '2006-10-21'; | |
| $del_url = "https://$del_user:$del_password@api.del.icio.us/v1/posts/get?dt=$dt"; | |
| if ($del_tag) { | |
| $del_url = "https://$del_user:$del_password@api.del.icio.us/v1/posts/get?dt=$dt&tag=$del_tag"; | |
| } | |
| if (!ini_get('allow_url_fopen')) { | |
| $tempfile = $wp_tmp_file; | |
| $ch = curl_init($del_url); | |
| $fp = fopen($tempfile, 'w'); | |
| curl_setopt($ch, CURLOPT_FILE, $fp); | |
| curl_setopt($ch, CURLOPT_HEADER, 0); | |
| curl_exec($ch); | |
| curl_close($ch); | |
| fclose($fp); | |
| $del_url = $tempfile; | |
| } | |
| $fp = fopen($del_url, "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; | |
| $wp_posttitle = $wp_posttitle . $dt; | |
| # 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) . "', 'publish', '" . $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); | |
| # Clear Cache | |
| if ($wp_clear_cache) { | |
| wp_cache_delete('/'); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment