/**
  * This method is called, when the widget should generate it's content.
  * Return the complete content using the methods provided by the base class.
  * Do NOT use the toolkit right here!
  *
  * @return string
  */
 public function getWidgetOutput()
 {
     $strReturn = "";
     //request the xml...
     try {
         $arrUrl = parse_url($this->getFieldValue("feedurl"));
         $objRemoteloader = new class_remoteloader();
         $intPort = isset($arrUrl["port"]) ? $arrUrl["port"] : "";
         if ($intPort == "") {
             if ($arrUrl["scheme"] == "https" ? 443 : 80) {
             }
         }
         $objRemoteloader->setStrHost($arrUrl["host"]);
         $objRemoteloader->setStrQueryParams($arrUrl["path"] . (isset($arrUrl["query"]) ? $arrUrl["query"] : ""));
         $objRemoteloader->setIntPort($intPort);
         $objRemoteloader->setStrProtocolHeader($arrUrl["scheme"] . "://");
         $strContent = $objRemoteloader->getRemoteContent();
     } catch (class_exception $objExeption) {
         $strContent = "";
     }
     if ($strContent != "") {
         $objXmlparser = new class_xml_parser();
         $objXmlparser->loadString($strContent);
         $arrFeed = $objXmlparser->xmlToArray();
         if (count($arrFeed) >= 1) {
             //rss feed
             if (isset($arrFeed["rss"])) {
                 $intCounter = 0;
                 foreach ($arrFeed["rss"][0]["channel"][0]["item"] as $arrOneItem) {
                     $strTitle = isset($arrOneItem["title"][0]["value"]) ? $arrOneItem["title"][0]["value"] : "";
                     $strLink = isset($arrOneItem["link"][0]["value"]) ? $arrOneItem["link"][0]["value"] : "";
                     $strReturn .= $this->widgetText("<a href=\"" . $strLink . "\" target=\"_blank\">" . $strTitle . "</a>");
                     $strReturn .= $this->widgetSeparator();
                     if (++$intCounter >= $this->getFieldValue("posts")) {
                         break;
                     }
                 }
             }
             //atom feed
             if (isset($arrFeed["feed"]) && isset($arrFeed["feed"][0]["entry"])) {
                 $intCounter = 0;
                 foreach ($arrFeed["feed"][0]["entry"] as $arrOneItem) {
                     $strTitle = isset($arrOneItem["title"][0]["value"]) ? $arrOneItem["title"][0]["value"] : "";
                     $strLink = isset($arrOneItem["link"][0]["attributes"]["href"]) ? $arrOneItem["link"][0]["attributes"]["href"] : "";
                     $strReturn .= $this->widgetText("<a href=\"" . $strLink . "\" target=\"_blank\">" . $strTitle . "</a>");
                     $strReturn .= $this->widgetSeparator();
                     if (++$intCounter >= $this->getFieldValue("posts")) {
                         break;
                     }
                 }
             }
         } else {
             $strContent = $this->getLang("rssfeed_errorparsing");
         }
     } else {
         $strReturn .= $this->getLang("rssfeed_errorloading");
     }
     return $strReturn;
 }
 /**
  * @see interface_admin_systemtask::executeTask()
  * @return string
  */
 public function executeTask()
 {
     if (!class_module_system_module::getModuleByName("pages")->rightEdit()) {
         return $this->getLang("commons_error_permissions");
     }
     $strReturn = "";
     $objFilesystem = new class_filesystem();
     $strTarget = $this->getParam("pageimport_file");
     $strError = $this->getParam("pageimport_error");
     $strTopFolderId = $this->getParam("topFolderId");
     $bitReplaceExisting = $this->getParam("pageimport_replace") != "";
     if ($strError != "suffix") {
         if ($strError != "upload") {
             //parse using the kajona xml parser
             $objXML = new class_xml_parser();
             $objXML->loadFile($strTarget);
             $arrXML = $objXML->xmlToArray();
             foreach ($arrXML as $arrOneXml) {
                 foreach ($arrOneXml as $arrNode) {
                     foreach ($arrNode as $strName => $arrSubnode) {
                         if ($strName == "page") {
                             $strReturn .= $this->processSinglePage($arrSubnode[0], $bitReplaceExisting, $strTopFolderId);
                         }
                     }
                 }
             }
             $strReturn = $this->getLang("systemtask_pageimport_success") . $strReturn;
         } else {
             $strReturn .= $this->getLang("systemtask_pageimport_errorupload");
         }
     } else {
         $strReturn .= $this->getLang("systemtask_pageimport_errortype");
     }
     $objFilesystem->fileDelete($strTarget);
     return $strReturn;
 }
 /**
  * Parses the xml-document and sets the internal properties.
  *
  * @param string $strXmlDocument
  * @return void
  */
 private function parseXMLDocument($strXmlDocument)
 {
     $objXml = new class_xml_parser();
     $objXml->loadString($strXmlDocument);
     $arrXml = $objXml->xmlToArray();
     $this->setStrTitle($arrXml["package"]["0"]["title"]["0"]["value"]);
     $this->setStrDescription($arrXml["package"]["0"]["description"]["0"]["value"]);
     $this->setStrVersion($arrXml["package"]["0"]["version"]["0"]["value"]);
     $this->setStrAuthor($arrXml["package"]["0"]["author"]["0"]["value"]);
     if (isset($arrXml["package"]["0"]["target"]["0"]["value"])) {
         $this->setStrTarget($arrXml["package"]["0"]["target"]["0"]["value"]);
     }
     $this->setStrType($arrXml["package"]["0"]["type"]["0"]["value"]);
     $this->setBitProvidesInstaller($arrXml["package"]["0"]["providesInstaller"]["0"]["value"] == "TRUE");
     if (is_array($arrXml["package"]["0"]["requiredModules"])) {
         foreach ($arrXml["package"]["0"]["requiredModules"] as $arrModules) {
             if (!is_array($arrModules)) {
                 continue;
             }
             foreach ($arrModules as $arrTempModule) {
                 if (!is_array($arrTempModule)) {
                     continue;
                 }
                 foreach ($arrTempModule as $arrOneModule) {
                     if (isset($arrOneModule["attributes"]["name"])) {
                         $strModule = $arrOneModule["attributes"]["name"];
                         $strVersion = $arrOneModule["attributes"]["version"];
                         $this->arrRequiredModules[$strModule] = $strVersion;
                     }
                 }
             }
         }
     }
     if (isset($arrXml["package"]["0"]["screenshots"]) && is_array($arrXml["package"]["0"]["screenshots"])) {
         foreach ($arrXml["package"]["0"]["screenshots"] as $arrScreenshots) {
             if (!is_array($arrScreenshots)) {
                 continue;
             }
             foreach ($arrScreenshots as $arrTempImage) {
                 if (!is_array($arrTempImage)) {
                     continue;
                 }
                 foreach ($arrTempImage as $arrOneImage) {
                     if (isset($arrOneImage["attributes"]["path"])) {
                         $strImage = $arrOneImage["attributes"]["path"];
                         if (in_array(uniStrtolower(uniSubstr($strImage, -4)), array(".jpg", ".jpeg", ".gif", ".png"))) {
                             $this->arrScreenshots[] = $strImage;
                         }
                     }
                 }
             }
         }
     }
 }
Пример #4
0
 public function testRssFeed()
 {
     echo "creating news & category..\n";
     $objNews = new class_module_news_news();
     $objNews->setStrTitle("autotest");
     $objNews->setStrIntro("autotest");
     $objNews->setStrText("autotest");
     $this->assertTrue($objNews->updateObjectToDb(), __FILE__ . " save news");
     $objNews2 = new class_module_news_news();
     $objNews2->setStrTitle("autotest2");
     $objNews2->setStrIntro("autotest2");
     $objNews2->setStrText("autotest2");
     $this->assertTrue($objNews2->updateObjectToDb(), __FILE__ . " save news");
     echo "creating category...\n";
     $objCat = new class_module_news_category();
     $objCat->setStrTitle("autotest");
     $this->assertTrue($objCat->updateObjectToDb(), __FILE__ . " save cat");
     $this->flushDBCache();
     echo "adding news to category..\n";
     $objNews->setArrCats(array($objCat->getSystemid()));
     $this->assertTrue($objNews->updateObjectToDb(), __FILE__ . " update news");
     $this->flushDBCache();
     echo "creating feed...\n";
     $objFeed = new class_module_news_feed();
     $objFeed->setStrTitle("testfeed");
     $objFeed->setStrCat($objCat->getSystemid());
     $objFeed->setStrUrlTitle("autotest");
     $objFeed->setStrPage("autotest");
     $objFeed->updateObjectToDb();
     $this->flushDBCache();
     $this->assertEquals(1, count(class_module_news_feed::getNewsList($objFeed->getStrCat())), __FILE__ . " check news for feed");
     $this->assertEquals(1, count(class_module_news_feed::getNewsList($objFeed->getStrCat(), 1)), __FILE__ . " check news for feed");
     echo "generating feed by creating a fake request...\n";
     $objNewsPortalXML = new class_module_news_portal_xml();
     $objNewsPortalXML->setParam("feedTitle", "autotest");
     $strFeed = $objNewsPortalXML->action("newsFeed");
     $this->assertTrue(uniStrpos($strFeed, "<title>autotest</title>") !== false, __FILE__ . " check rss feed");
     echo "parsing feed with xml parser...\n";
     $objXmlParser = new class_xml_parser();
     $objXmlParser->loadString($strFeed);
     $arrFeed = $objXmlParser->xmlToArray();
     $intNrOfNews = count($arrFeed["rss"][0]["channel"][0]["item"]);
     $this->assertEquals(1, $intNrOfNews, __FILE__ . " check items for feed");
     $strTitle = $arrFeed["rss"][0]["channel"][0]["item"][0]["title"][0]["value"];
     $this->assertEquals("autotest", $strTitle, __FILE__ . " check items-title for feed");
     echo "adding news to category..\n";
     $objNews2->setArrCats(array($objCat->getSystemid()));
     $this->assertTrue($objNews2->updateObjectToDb(), __FILE__ . " update news");
     $this->flushDBCache();
     $objNewsPortalXML = new class_module_news_portal_xml();
     $objNewsPortalXML->setParam("feedTitle", "autotest");
     $strFeed = $objNewsPortalXML->action("newsFeed");
     $this->assertTrue(uniStrpos($strFeed, "<title>autotest</title>") !== false, __FILE__ . " check rss feed");
     echo "parsing feed with xml parser...\n";
     $objXmlParser = new class_xml_parser();
     $objXmlParser->loadString($strFeed);
     $arrFeed = $objXmlParser->xmlToArray();
     //var_dump($arrFeed["rss"][0]["channel"][0]["item"]);
     $intNrOfNews = count($arrFeed["rss"][0]["channel"][0]["item"]);
     $this->assertEquals(2, $intNrOfNews, __FILE__ . " check items for feed");
     echo "deleting news & category...\n";
     $this->assertTrue($objNews->deleteObjectFromDatabase(), __FILE__ . " delete news");
     $this->assertTrue($objNews2->deleteObjectFromDatabase(), __FILE__ . " delete news");
     $this->assertTrue($objCat->deleteObjectFromDatabase(), __FILE__ . " delete cat");
     $this->assertTrue($objFeed->deleteObjectFromDatabase(), __FILE__ . " delete feed");
 }
 /**
  * Loads the feed and displays it
  *
  * @return string the prepared html-output
  */
 public function loadData()
 {
     $strReturn = "";
     $strFeed = "";
     try {
         $objRemoteloader = new class_remoteloader();
         if (uniStrtolower(uniSubstr($this->arrElementData["char2"], 0, 8)) == "https://") {
             $objRemoteloader->setStrProtocolHeader("https://");
         }
         $this->arrElementData["char2"] = uniStrReplace("&amp;", "&", $this->arrElementData["char2"]);
         $objRemoteloader->setStrHost(uniStrReplace(array("http://", "https://"), "", $this->arrElementData["char2"]));
         $objRemoteloader->setIntPort(0);
         $strFeed = $objRemoteloader->getRemoteContent();
     } catch (class_exception $objExeption) {
         $strFeed = "";
     }
     $strFeedTemplateID = $this->objTemplate->readTemplate("/element_rssfeed/" . $this->arrElementData["char1"], "rssfeed_feed");
     $strPostTemplateID = $this->objTemplate->readTemplate("/element_rssfeed/" . $this->arrElementData["char1"], "rssfeed_post");
     $strContent = "";
     $arrTemplate = array();
     if (uniStrlen($strFeed) == 0) {
         $strContent = $this->getLang("rssfeed_errorloading");
     } else {
         $objXmlparser = new class_xml_parser();
         $objXmlparser->loadString($strFeed);
         $arrFeed = $objXmlparser->xmlToArray();
         if (count($arrFeed) >= 1) {
             //rss feed
             if (isset($arrFeed["rss"])) {
                 $arrTemplate["feed_title"] = $arrFeed["rss"][0]["channel"][0]["title"][0]["value"];
                 $arrTemplate["feed_link"] = $arrFeed["rss"][0]["channel"][0]["link"][0]["value"];
                 $arrTemplate["feed_description"] = $arrFeed["rss"][0]["channel"][0]["description"][0]["value"];
                 $intCounter = 0;
                 if (isset($arrFeed["rss"][0]["channel"][0]["item"]) && is_array($arrFeed["rss"][0]["channel"][0]["item"])) {
                     foreach ($arrFeed["rss"][0]["channel"][0]["item"] as $arrOneItem) {
                         $strDate = isset($arrOneItem["pubDate"][0]["value"]) ? $arrOneItem["pubDate"][0]["value"] : "";
                         if ($strDate != "") {
                             $intDate = strtotime($strDate);
                             if ($intDate > 0) {
                                 $strDate = timeToString($intDate);
                             }
                         }
                         $arrMessage = array();
                         $arrMessage["post_date"] = $strDate;
                         $arrMessage["post_title"] = isset($arrOneItem["title"][0]["value"]) ? $arrOneItem["title"][0]["value"] : "";
                         $arrMessage["post_description"] = isset($arrOneItem["description"][0]["value"]) ? $arrOneItem["description"][0]["value"] : "";
                         $arrMessage["post_link"] = isset($arrOneItem["link"][0]["value"]) ? $arrOneItem["link"][0]["value"] : "";
                         $strContent .= $this->fillTemplate($arrMessage, $strPostTemplateID);
                         if (++$intCounter >= $this->arrElementData["int1"]) {
                             break;
                         }
                     }
                 } else {
                     $strContent = $this->getLang("rssfeed_noentry");
                 }
             }
             //atom feed
             if (isset($arrFeed["feed"]) && isset($arrFeed["feed"][0]["entry"])) {
                 $arrTemplate["feed_title"] = $arrFeed["feed"][0]["title"][0]["value"];
                 $arrTemplate["feed_link"] = $arrFeed["feed"][0]["link"][0]["attributes"]["href"];
                 $arrTemplate["feed_description"] = $arrFeed["feed"][0]["subtitle"][0]["value"];
                 $intCounter = 0;
                 if (isset($arrFeed["feed"][0]["entry"]) && is_array($arrFeed["feed"][0]["entry"])) {
                     foreach ($arrFeed["feed"][0]["entry"] as $arrOneItem) {
                         $strDate = isset($arrOneItem["updated"][0]["value"]) ? $arrOneItem["updated"][0]["value"] : "";
                         if ($strDate != "") {
                             $intDate = strtotime($strDate);
                             if ($intDate > 0) {
                                 $strDate = timeToString($intDate);
                             }
                         }
                         $arrMessage = array();
                         $arrMessage["post_date"] = $strDate;
                         $arrMessage["post_title"] = isset($arrOneItem["title"][0]["value"]) ? $arrOneItem["title"][0]["value"] : "";
                         $arrMessage["post_description"] = isset($arrOneItem["summary"][0]["value"]) ? $arrOneItem["summary"][0]["value"] : "";
                         $arrMessage["post_link"] = isset($arrOneItem["link"][0]["attributes"]["href"]) ? $arrOneItem["link"][0]["attributes"]["href"] : "";
                         $strContent .= $this->fillTemplate($arrMessage, $strPostTemplateID);
                         if (++$intCounter >= $this->arrElementData["int1"]) {
                             break;
                         }
                     }
                 } else {
                     $strContent = $this->getLang("rssfeed_noentry");
                 }
             }
         } else {
             $strContent = $this->getLang("rssfeed_errorparsing");
         }
     }
     $arrTemplate["feed_content"] = $strContent;
     $strReturn .= $this->fillTemplate($arrTemplate, $strFeedTemplateID);
     return $strReturn;
 }