/** * 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; }
/** * Loads the feed and displays it * * @return string the prepared html-output */ public function loadData() { require_once class_resourceloader::getInstance()->getCorePathForModule("element_markdown", true) . "/element_markdown/system/parsedown/vendor/autoload.php"; $arrUrl = parse_url($this->arrElementData["char2"]); $objLoader = new class_remoteloader(); $objLoader->setStrProtocolHeader($arrUrl["scheme"] . "://"); $objLoader->setStrHost($arrUrl["host"]); $objLoader->setStrQueryParams($arrUrl["path"]); $objLoader->setIntPort(null); $strFile = $objLoader->getRemoteContent(); $objMarkdown = new Parsedown(); $strParsed = $objMarkdown->text($strFile); return $this->objTemplate->fillTemplate(array("markdown_content" => $strParsed, "markdown_url" => $this->arrElementData["char2"]), $this->objTemplate->readTemplate("/element_markdown/" . $this->arrElementData["char1"], "markdown"), true); }
/** * 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("&", "&", $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; }
/** * Returns a fully set up remoteloader to start querying the package repo * @return class_remoteloader */ private function getRemoteloader() { $objRemoteloader = new class_remoteloader(); $objRemoteloader->setStrHost($this->STR_BROWSE_HOST); $objRemoteloader->setStrProtocolHeader($this->STR_PROTOCOL_HEADER); $objRemoteloader->setIntPort($this->INT_BROWSE_HOST_PORT); return $objRemoteloader; }