<?php /* Plugin Name: delicious2wordpress Plugin URI: http://www.fabiocicerchia.it/projects/delicious2wordpress Description: Import the exported file of delicious bookmarks into a category. Author: Fabio Cicerchia Version: 0.2 Author URI:http://www.fabiocicerchia.it/ */ function d2w_init() { if (empty($_FILES)) { ?> <div class="wrap"> <h2>delicious2wordpress</h2> Upload the exported file of delicious. <form action="" enctype="multipart/form-data" method="post"> <input type="file" name="upload_file" /> <input type="submit" value="Upload & Import" name="Submit"/> </form></div> <?php } else { ?> <div class="wrap"> <h2>delicious2wordpress</h2> <?php if (file_exists($_FILES['upload_file']['tmp_name'])) { d2w_import_bookmarks($_FILES['upload_file']['tmp_name']); } ?></div> <?php } } function d2w_import_bookmarks($file) { $content = file($file); $common_tags = array('delicious', 'bookmarks'); $common_title_prefix = ''; $new_content = array(); echo "<strong>Start grabbing</strong>: \n"; flush(); foreach($content as $id => $element) { if (substr($element, 0, 4) == '<DT>') { $element = trim($element); $url = preg_replace('/.*HREF="([^"]*)".* /', '\1', $element); ob_start(); readfile($url); $c = ob_get_contents(); ob_end_clean(); // GRAB Description Meta preg_match('/(.*name="description".*)/i', $c, $matches); preg_match('/content="([^"]+)"/i', $matches[0], $matches); $description = $matches[1]; // GRAB Keywords Meta preg_match('/(.*name="keywords".*)/i', $c, $matches); preg_match('/content="([^"]+)"/i', $matches[0], $matches); $keywords = explode(',', $matches[1]); // GRAB Title Meta preg_match('/(.*<title>.*)/i', $c, $matches); preg_match('/>([^<]+)</i', $matches[0], $matches); $title = $matches[1]; // GRAB RSS Meta preg_match('/(.*rel="alternate".*)/i', $c, $matches); preg_match('/href="([^"]+)"/i', $matches[0], $matches); $rss = $matches[1]; $new_content[] = array( 'link_name' => $common_title_prefix . preg_replace('/.*>([^<]+)<.* /', '\1', $element), 'link_url' => $url, 'link_description' => $description, 'link_category' => array(), 'link_target' => '_blank', 'link_rel' => '', 'link_image' => '', // grab this from snap.com 'rss_uri' => $rss, 'delicious_last_visit' => preg_replace('/.*LAST_VISIT="([^"]*)".* /', '\1', $element), 'delicious_add_date' => preg_replace('/.*ADD_DATE="([^"]*)".* /', '\1', $element), 'delicious_tags' => array_merge($common_tags, explode(',', preg_replace('/.*TAGS="([^"]*)".* /', '\1', $element))), ); echo ". "; flush(); } } echo "DONE!\n"; d2w_import($new_content); } function d2w_import($content) { $count = 0; echo "\n \n<strong>Importing</strong>: \n"; flush(); for($i = 0; $i < count($content); $i++) { $element = $content[$i]; $_POST['link_url'] = $element['link_url']; $_POST['link_name'] = $element['link_name']; $_POST['link_target'] = '_blank'; $_POST['link_description'] = $element['description']; $_POST['link_visible'] = 'Y'; $_POST['link_rating'] = 0; $_POST['link_rss'] = $element['rss']; $_POST['link_category'] = array(1147); //add_link(); echo ". "; flush(); } echo "DONE!\n"; } function add_option_page() { add_options_page('delicious2wordpress', 'delicious2wordpress', 8, __FILE__, 'd2w_init'); } add_action('admin_menu', 'add_option_page'); ?>
April 10, 2009
delicious2wordpress
Chiunque di voi che voglia importare i suoi bookmark di delicious in wordpress sa...
Sa che cercando in giro per internet non si trova nulla di decente ne di funzionante, e allora la soluzione migliore soluzione è rimboccarsi le maniche e mettersi all'opera... E io vi risparmio il compito di farlo, poichè l'ho fatto al posto vostro
Ed ecco una bozza del plugin per l'importazione dei bookmark. L'unica cosa che dovrete fare è esportare i vostri dati da delicious e darli in pasto al plugin. Il gioco è fatto! Verranno automaticamente inseriti nella categoria che avrete specificato nel file PHP.
Questo è il plugin per wordpress:
Ma questo è solo l'inizio, le modifiche e le funzionalità arriveranno a breve!
Stay tuned!








