Exemplo n.º 1
0
 /**
  * Renders the display for a normal text-oriented feed.
  *
  * @access public
  * @param mixed $url Either a single feed URL (as a string) or an array of feed URLs (as an array of strings).
  * @param array $options An associative array of options that the function should take into account when rendering the markup. See documentation for data() for details.
  * @return string The HTML markup to display on the page.
  */
 function listing($url, $options = null)
 {
     // Retrieve the data and break out the individual variables (i.e. $title and $permalink are usable)
     if (!$options) {
         $options = array();
     }
     extract(newsblocks::data($url, $options));
     if (!$classname) {
         $classname = 'nb-list';
     }
     // Open a <div> with a class of "block" (which we'll use for styling) and an id of some random value (for targetting via JavaScript)
     $html = '<div class="' . $classname . '" id="' . $id . '">' . "\n";
     // As long as we're supposed to show the title.
     if ($show_title) {
         // Here's the name of the feed, formatted the way we want.
         $html .= '<h3>';
         // Header tag
         $html .= '<img src="' . $favicon . '" width="16" height="16" /> ';
         // Favicon
         if ($permalink) {
             $html .= '<a href="' . $permalink . '">';
         }
         // Link (if available)
         $html .= $title;
         // Title
         if ($permalink) {
             $html .= '</a>';
         }
         // Close link (if available)
         $html .= '</h3>' . "\n";
         // Close header
     }
     // Go through the same thing twice -- once for the primary, and once for the secondary.
     for ($x = 0; $x < 2; $x++) {
         $secondary = $x % 2;
         // If we want the "More" link to stay, put it between the first and second lists.
         if (!$more_move && $secondary) {
             // If we have more than ($items) items in the feed...
             if ($feed->get_item_quantity() > $items) {
                 // Add a little "More" link for people to click on.
                 $html .= '<p class="more"><a href="" class="more" id="m_' . $id . '">' . $more . '</a></p>' . "\n";
             }
         }
         // Start the <ul> list. Automatically set whether this is the shown or hidden part of the list, as well as the direction of the text.
         $html .= '<ul id="' . ($secondary ? 's_' : 'p_') . $id . '" class="' . ($secondary ? 'secondary' : 'primary') . '" style="direction:' . $direction . ';' . ($secondary ? 'display:none;' : '') . '">' . "\n";
         // Ensure that the right lists are being generated for shown/hidden items (as per the "More" link).
         if ($secondary) {
             // Secondary
             $counter_start = $items;
             $counter_length = 0;
         } else {
             // Primary
             $counter_start = 0;
             $counter_length = $items;
         }
         foreach ($feed->get_items($counter_start, $counter_length) as $item) {
             // Set default values to be overridden by newsblocks::has_enclosure().
             $class = '';
             $type = '';
             $new = '';
             // Set some values if the item has an enclosure.
             extract(newsblocks::has_enclosure($item));
             // Compare the timestamp of the feed item with $since (defaults to 24 hours ago).
             if ($item->get_date('U') > $since) {
                 // Let's add a "new" image to the end.
                 $new = NB_NEW_HTML;
             }
             // Create the title attribute
             $title_attr = newsblocks::get_title_attr($item, $length, $date_format);
             // Add each item: item title, linked back to the original posting, with a tooltip containing the description.
             $html .= '<li class="' . $item_classname . ($class != '' ? ' ' . $class : '') . '">';
             // <li> tag.
             $html .= '<a href="' . $item->get_permalink() . '" title="' . $title_attr . '">';
             // <a> tag with a short description in the title attribute.
             $html .= $item->get_title();
             // The title for the link
             $html .= '</a>';
             // Close the </a>
             $html .= ' ' . $new . '</li>' . "\n";
             // Add the "New" image (if necessary), then close the </li>
         }
         // Close out of the primary list
         $html .= '</ul>' . "\n";
     }
     // If we want the "More" link to move, put it at the end of the list.
     if ($more_move) {
         // If we have more than ($items) items in the feed...
         if ($feed->get_item_quantity() > $items) {
             // Add a little "More" link for people to click on.
             $html .= '<p class="more"><a href="" class="more" id="m_' . $id . '">' . $more . '</a></p>' . "\n";
         }
     }
     // Close out of this <div> block.
     $html .= '</div>' . "\n";
     // Return all of the HTML, so that we can display it as we choose or manipulate it further.
     return $html;
 }