Exemplo n.º 1
0
 /** 
  * This function will take a single rss <item> array and according to the
  * other attributes will wrap an HTML <div> around the cdata of the rss
  * element specified by 'element_no'.  Some elements have special case
  * issues, these are elements 0(title), 1(link), 2(description), and 
  * 6(enclosure).  The special issues are:
  *	0 - according to parameter $href_title this may or may not be linked
  *		via an HTML <a href> to the rss <link> location.
  *	1 - this is wrapped in both a <div> and <a href> linking to its own
  *		location.
  *	2 - the description may be shortened to	the number of characters 
  *		specified by $summary_length.
  *	6 - this rss element only has attributes which are currently not
  *		dealt with and thus it returns nothing.
  *
  * Other than these special cases a simple <div> wrapper will be 
  * produced and returned.
  *
  * @author Daniel Fowler (www.alephcipher.com)
  *
  * @param array &$rss_item_array an array containing the rss elements of a 
  *		single rss <item> such that the elements can be referenced
  *		in the array by name (e.g. $rss_item_array['description'])
  * @param int $element_no a number between (and including) 0(zero) and 10 
  *		that specifies the element to wrap in a div.  The number
  *		refers to an element as specified by get_element_name_from_no().
  * @param int $summary_length the length as specified by get_safe_summary() that
  *		the description should be shortened too, this is only used if
  *		$element_no refers to the description element.
  * @param bool $href_title true will add an HTML <a href> to the title element
  *		linking to the location given by the <link> element.  False
  *		will not (default).
  * @return string returns the HTML formatted content of rss element.
  * 
  */
 private static function get_element_div_wrapper(&$rss_item_array, $element_no, $summary_length, $href_title = false)
 {
     $element_name = RSSReader::get_element_name_from_no($element_no);
     //echo "PARSING element: " . $element_name . "<br />"; // DEBUG
     // elements with attr's: 9 7 4 6
     // elements with special issues: 0 1 2 6
     $str_to_ret = "";
     switch ($element_no) {
         case 0:
             // title
             if ($href_title) {
                 $str_to_ret = "\t<div class=\"rss_" . $element_name . "\"><a href=\"" . $rss_item_array[RSSReader::get_element_name_from_no(1)] . "\">" . $rss_item_array[$element_name] . "</a></div>\n";
             } else {
                 $str_to_ret = "\t<div class=\"rss_" . $element_name . "\">" . $rss_item_array[$element_name] . "</div>\n";
             }
             break;
         case 1:
             // link
             $str_to_ret = "\t<div class=\"rss_" . $element_name . "\"><a href=\"" . $rss_item_array[$element_name] . "\">" . $rss_item_array[$element_name] . "</a></div>\n";
             break;
         case 2:
             // description
             $str_to_ret .= "\t<div class=\"rss_description\">" . RSSReader::get_safe_summary($rss_item_array[$element_name], $summary_length) . "</div>\n";
             break;
         case 6:
             // enclosure
             // TODO: figure out how to deal with this element
             //$element_list .= "\t<div class=\"rss_enclosure\">" . $rss_item_array[""] . "</div>\n";
             break;
         default:
             // the rest
             $str_to_ret = "\t<div class=\"rss_" . $element_name . "\">" . $rss_item_array[$element_name] . "</div>\n";
             break;
     }
     return $str_to_ret;
 }