home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Plugins / delicious-cached / delicious_cached_pp.php next >
PHP Script  |  2008-02-19  |  6KB  |  169 lines

  1. <?php
  2. /*
  3. Plugin Name: del.icio.us cached++
  4. Plugin URI: http://wordpress.org/extend/plugins/delicious-cached/
  5. Description: Outputs del.icio.us bookmarks. Uses Wordpress built-in MagpieRSS to retrieve and to cache.
  6. Version: 1.3a
  7. Author: Jo├úo Craveiro
  8. Author URI: http://www.jcraveiro.com/
  9. */
  10.  
  11. /*
  12. Arguments:
  13.      $username - Your del.icio.us username
  14.      $count - Maximum number of latest posts to display
  15.      $extended - Whether/how to display or not the Extended field
  16.         (0=no extended ; 1=extended)
  17.      $tags - Number of tags to display per link
  18.         (0=don't show tags ; >=1 = show, at most, 'n' tags)
  19.      $before - Text to append before each item.
  20.      $after - Text to append after each item.
  21.      $beforeExtended - Text to append before each item's extended description.
  22.      $afterExtended - Text to append after each item's extended description.
  23.      $beforeTags - Text to append before each item's tags.
  24.      $betweenTags - Text to separate tags.
  25.      $afterTags - Text to append after each item's extended tags.
  26. */
  27. function delicious_pp(
  28.     $username,
  29.     $count=15,
  30.     $extended=1,
  31.     $tags=0,
  32.     $before='<li>',
  33.     $after='</li>',
  34.     $beforeExtended='<p>',
  35.     $afterExtended='</p>',
  36.     $beforeTags='<p>',
  37.     $betweenTags=' ',
  38.     $afterTags='</p>'
  39.     ) {
  40.     require_once(ABSPATH . WPINC . '/rss-functions.php');
  41.     $feedLocation = "http://del.icio.us/rss/".$username.'/';
  42.  
  43.     $feedContent = @fetch_rss($feedLocation);
  44.     $feedItems = $feedContent->items;
  45.     $output = '';
  46.     
  47.     for ($iter = 0 ; $iter < $count && $iter < sizeOf($feedItems) ; $iter++) {
  48.           // The bookmarked URI
  49.         $linkLink = htmlspecialchars($feedItems[$iter]['about']);
  50.         // The text do display between the <a> and </a> tags
  51.         $linkText = $feedItems[$iter]['title'];
  52.         // Space-separated tags
  53.         $linkTagsRaw = $feedItems[$iter]['dc']['subject'];
  54.           // Link-ified tags, separated by the specified in $betweenTags
  55.         $linkTags = ($tags > 0 && $linkTagsRaw) ?
  56.                     $beforeTags.deliciousTagsMarkup($linkTagsRaw, $username, $tags, $betweenTags).$afterTags :
  57.                     '';
  58.         // Extended description
  59.           $linkExtended=$feedItems[$iter]['description'];
  60.  
  61.           // If extended description is already to be shown or is empty,
  62.           // the link title (TITLE attribute) will be the same as the link text.
  63.           // Otherwise, extended will be the link title.
  64.         if ($extended || !$feedItems[$iter]['description']) {
  65.               $linkTitle = htmlentities($linkText,ENT_QUOTES,get_bloginfo('charset') );
  66.         } else {
  67.               $linkTitle = htmlentities($linkExtended,ENT_QUOTES,get_bloginfo('charset') );
  68.         }
  69.                             
  70.           // Build the markup to display the extended description, except if
  71.           // it is disabled or empty.
  72.         if ($extended && $linkExtended) {
  73.             $linkExtended = $beforeExtended.
  74.                             $linkExtended.
  75.                             $afterExtended;
  76.         } else {
  77.             $linkExtended = '';
  78.         }
  79.  
  80.           // Add this item's markup to the final output
  81.         $output .=  $before."<a href='$linkLink' title='$linkTitle'>$linkText</a>\n".
  82.                         $linkExtended."\n".$linkTags.$after."\n";
  83.     }
  84.     
  85.     echo $output;
  86.  
  87. }
  88.  
  89. // Turn a string of space-separated tags into a string of link-ified tags,
  90. // separated by what the user defines in $betweenTags.
  91. function deliciousTagsMarkup($tagsRaw, $username, $tags, $betweenTags) {
  92.     $result = array();
  93.     $tagsArray = explode(" ", $tagsRaw, $tags);
  94.     for ($i = 0 ; $i < $tags && $i < sizeof($tagsArray) ; $i++) {
  95.         $result[] = "<a href='http://del.icio.us/$username/$tagsArray[$i]' title='$tagsArray[$i] tag'>$tagsArray[$i]</a>";
  96.     }
  97.     return implode($betweenTags,$result);
  98. }
  99.  
  100.  
  101. function widget_deliciouspp_init() {
  102.     if (!function_exists('register_sidebar_widget')) return;
  103.  
  104.     function widget_deliciouspp($args) {
  105.         
  106.         extract($args);
  107.  
  108.         $options = get_option('widget_deliciouspp');
  109.         $title = $options['title'];
  110.         
  111.         echo $before_widget . $before_title . $title . $after_title;
  112.         echo '<ul>';
  113.         delicious_pp(
  114.             $options['username'],
  115.             $options['count'],
  116.             $options['extended'],
  117.             $options['tags'],
  118.             $options['before'],
  119.             $options['after'],
  120.             $options['beforeExtended'],
  121.             $options['afterExtended'],
  122.             $options['beforeTags'],
  123.             $options['betweenTags'],
  124.             $options['afterTags']
  125.             );
  126.         echo '</ul>';
  127.         echo $after_widget;
  128.     }
  129.  
  130.     function widget_deliciouspp_control() {
  131.         $options = get_option('widget_deliciouspp');
  132.         if ( !is_array($options) )
  133.             $options = array(
  134.             'title'=>'del.icio.us',
  135.             'username'=>'',
  136.             'count'=>15,
  137.             'extended'=>1,
  138.             'tags'=>0,
  139.             'before'=>'<li>',
  140.             'after'=>'</li>',
  141.             'beforeExtended'=>'<p>',
  142.             'afterExtended'=>'</p>',
  143.             'beforeTags'=>'<p>',
  144.             'betweenTags'=>', ',
  145.             'afterTags'=>'</p>'
  146.             );
  147.         if ( $_POST['deliciouspp-submit'] ) {
  148.             $options['title'] = strip_tags(stripslashes($_POST['deliciouspp-title']));
  149.             $options['username'] = strip_tags(stripslashes($_POST['deliciouspp-username']));
  150.             // TBD: update other options
  151.             update_option('widget_deliciouspp', $options);
  152.         }
  153.  
  154.         $title = htmlspecialchars($options['title'], ENT_QUOTES);
  155.         $username = htmlspecialchars($options['username'], ENT_QUOTES);
  156.         
  157.         echo '<p style="text-align:right;"><label for="deliciouspp-title">Title: <input style="width: 200px;" id="deliciouspp-title" name="deliciouspp-title" type="text" value="'.$title.'" /></label></p>';
  158.         echo '<p style="text-align:right;"><label for="deliciouspp-username">Username: <input style="width: 200px;" id="deliciouspp-username" name="deliciouspp-username" type="text" value="'.$username.'" /></label></p>';
  159.         echo '<input type="hidden" id="deliciouspp-submit" name="deliciouspp-submit" value="1" />';
  160.     }        
  161.  
  162.     register_sidebar_widget('Delicious Cached++', 'widget_deliciouspp');
  163.     register_widget_control('Delicious Cached++', 'widget_deliciouspp_control', 300, 100);
  164. }
  165.  
  166. add_action('plugins_loaded', 'widget_deliciouspp_init');
  167.  
  168. ?>
  169.