Exemplo n.º 1
0
 /**
  * @param String $element
  * @return String
  */
 public static function getSetting($element)
 {
     $xh = new XMLHandler("../Classes/settings.xml");
     return $xh->getValue($element);
 }
Exemplo n.º 2
0
 /**
  * @param String $url
  * @return NewsItem[]
  */
 public static function getNewsList($url, $format)
 {
     //Exception thrown in XMLHandler constructor if url is incorrect
     $xh = new XMLHandler($url);
     $newsList = array();
     if (isset($xh)) {
         $news = $xh->getNodes(BRAFTON_NEWS_LIST_ITEM);
         $exceptionList = array();
         foreach ($news as $n) {
             /* @var $n DomElement */
             $ni = new NewsItem();
             try {
                 //Check if all required nodes exist, throw exception if not!
                 if ($n->getElementsByTagName(BRAFTON_ID)->length == 0) {
                     throw new XMLNodeException("Element " . BRAFTON_ID . " for " . BRAFTON_NEWS_LIST_ITEM);
                 }
                 //set value of BRAFTON_ID here to use in debugging!
                 $ni->id = $n->getElementsByTagName(BRAFTON_ID)->item(0)->textContent;
                 if ($n->getElementsByTagName(BRAFTON_PUBLISH_Date)->length == 0) {
                     throw new XMLNodeException("Element " . BRAFTON_PUBLISH_Date . " for " . BRAFTON_NEWS_LIST_ITEM . " with id: " . $ni->id);
                 }
                 if (!$n->getAttribute(BRAFTON_HREF)) {
                     throw new XMLNodeException("Attribute " . BRAFTON_HREF . " for " . BRAFTON_NEWS_LIST_ITEM . " with id: " . $ni->id);
                 }
                 if ($n->getElementsByTagName(BRAFTON_HEADLINE)->length == 0) {
                     throw new XMLNodeException("Element " . BRAFTON_HEADLINE . " for " . BRAFTON_NEWS_LIST_ITEM . " with id: " . $ni->id);
                 }
                 //Check if date is valid if not throw exception
                 $ni->publishDate = $n->getElementsByTagName(BRAFTON_PUBLISH_Date)->item(0)->textContent;
                 $dateIsValid = date_parse($ni->publishDate);
                 if (!$dateIsValid) {
                     throw new DateParseException("Invalid Date for " . BRAFTON_PUBLISH_Date . "  on " . BRAFTON_NEWS_LIST_ITEM . " with id: " . $ni->id . "<br />\n");
                 }
                 //Set the value of all other required elements
                 $ni->href = $n->getAttribute(BRAFTON_HREF);
                 $ni->headline = $n->getElementsByTagName(BRAFTON_HEADLINE)->item(0)->textContent;
                 $ni->format = $format;
                 //Add to newslist array
                 $newsList[] = $ni;
             } catch (XMLException $e) {
                 $exceptionList[] = $e;
                 //Add exception to a list
             } catch (DateParseException $e) {
                 $exceptionList[] = $e;
             }
         }
         //If exception list contains any exceptions throw a new exception which relays all exceptions to the user
         if (!empty($exceptionList)) {
             echo implode("<br />", $exceptionList) . "<br /><br />";
         }
     }
     return $newsList;
 }