/**
  * 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);
 }
 /**
  * @see interface_admin_systemtast::executeTask()
  * @return string
  */
 public function executeTask()
 {
     if (!class_module_system_module::getModuleByName("stats")->rightEdit()) {
         return $this->getLang("commons_error_permissions");
     }
     $strReturn = "";
     $objWorker = new class_module_stats_worker();
     //determin the number of ips to lookup
     $arrIpToLookup = $objWorker->getArrayOfIp2cLookups();
     if (count($arrIpToLookup) == 0) {
         return $this->objToolkit->getTextRow($this->getLang("worker_lookup_end"));
     }
     //check, if we did anything before
     if ($this->getParam("totalCount") == "") {
         $this->setParam("totalCount", $objWorker->getNumberOfIp2cLookups());
     }
     $strReturn .= $this->objToolkit->getTextRow($this->getLang("intro_worker_lookupip2c") . $this->getParam("totalCount"));
     //Lookup 10 Ips an load the page again
     for ($intI = 0; $intI < 10; $intI++) {
         if (isset($arrIpToLookup[$intI])) {
             $strIP = $arrIpToLookup[$intI]["stats_ip"];
             try {
                 $objRemoteloader = new class_remoteloader();
                 $objRemoteloader->setStrHost($this->strIp2cServer);
                 $objRemoteloader->setStrQueryParams("/ip2c.php?ip=" . urlencode($strIP) . "&domain=" . urlencode(_webpath_) . "&checksum=" . md5(urldecode(_webpath_) . $strIP));
                 $strCountry = $objRemoteloader->getRemoteContent();
             } catch (class_exception $objExeption) {
                 $strCountry = "n.a.";
             }
             $objWorker->saveIp2CountryRecord($strIP, $strCountry);
         }
     }
     //and Create a small progress-info
     $intTotal = $this->getParam("totalCount");
     $floatOnePercent = 100 / $intTotal;
     //and multiply it with the alredy looked up ips
     $intLookupsDone = ((int) $intTotal - $objWorker->getNumberOfIp2cLookups()) * $floatOnePercent;
     $intLookupsDone = round($intLookupsDone, 2);
     if ($intLookupsDone < 0) {
         $intLookupsDone = 0;
     }
     $this->setStrProgressInformation($strReturn);
     $this->setStrReloadParam("&totalCount=" . $this->getParam("totalCount"));
     return $intLookupsDone;
 }
 /**
  * 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 = "";
     if ($this->getFieldValue("location") == "") {
         return "Please set up a location";
     }
     if (uniStrpos($this->getFieldValue("location"), "GM") !== false) {
         return "This widget changed, please update your location by editing the widget";
     }
     //request the xml...
     try {
         $strFormat = "metric";
         if ($this->getFieldValue("unit") == "f") {
             $strFormat = "imperial";
         }
         $objRemoteloader = new class_remoteloader();
         $objRemoteloader->setStrHost("api.openweathermap.org");
         $objRemoteloader->setStrQueryParams("/data/2.5/forecast/daily?APPID=4bdceecc2927e65c5fb712d1222c5293&q=" . $this->getFieldValue("location") . "&units=" . $strFormat . "&cnt=4");
         $strContent = $objRemoteloader->getRemoteContent();
     } catch (class_exception $objExeption) {
         $strContent = "";
     }
     if ($strContent != "" && json_decode($strContent, true) !== null) {
         $arrResponse = json_decode($strContent, true);
         $strReturn .= $this->widgetText($this->getLang("weather_location_string") . $arrResponse["city"]["name"] . ", " . $arrResponse["city"]["country"]);
         foreach ($arrResponse["list"] as $arrOneForecast) {
             $objDate = new class_date($arrOneForecast["dt"]);
             $strReturn .= "<div>";
             $strReturn .= $this->widgetText("<div style='float: left;'>" . dateToString($objDate, false) . ": " . round($arrOneForecast["temp"]["day"], 1) . "°</div>");
             $strReturn .= $this->widgetText("<img src='http://openweathermap.org/img/w/" . $arrOneForecast["weather"][0]["icon"] . ".png' style='float: right;' />");
             $strReturn .= "</div><div style='clear: both;'></div>";
         }
     } else {
         $strReturn .= $this->getLang("weather_errorloading");
     }
     return $strReturn;
 }
示例#5
0
 /**
  * Does the remote address lookup using the Yahoo! Maps Geocoding API. Returns true if an address was found.
  * For further information please refer to http://developer.yahoo.com/maps/rest/V1/geocode.html
  *
  * @param string $strStreet
  * @param string $strPostalCode
  * @param string $strCity
  * @param string $strCountry
  *
  * @return bool
  */
 private function lookupAddressUsingYahoo($strStreet = "", $strPostalCode = "", $strCity = "", $strCountry = "")
 {
     $bitReturn = false;
     $strHost = "where.yahooapis.com";
     $strApiKey = "YD-9G7bey8_JXxQP6rxl.fBFGgCdNjoDMACQA--";
     //change this
     $strQuery = "/geocode?appid=" . $strApiKey . "&flags=P&q=" . urlencode($strStreet . ", " . $strPostalCode . " " . $strCity . ", " . $strCountry);
     try {
         $objRemoteloader = new class_remoteloader();
         $objRemoteloader->setStrHost($strHost);
         $objRemoteloader->setStrQueryParams($strQuery);
         $strResponse = $objRemoteloader->getRemoteContent();
     } catch (class_exception $objExeption) {
         $bitReturn = false;
         $strResponse = false;
     }
     if ($strResponse != false) {
         $this->strResponseRaw = $strResponse;
         $arrResponse = unserialize($strResponse);
         $arrResponse = $arrResponse["ResultSet"];
         if ($arrResponse["Error"] == 0) {
             $arrResult = $arrResponse["Result"][0];
             //extract response
             $this->strStreet = $arrResult["street"] . " " . $arrResult["house"];
             $this->strPostalCode = $arrResult["postal"];
             $this->strCity = $arrResult["city"];
             $this->strCountryCode = $arrResult["country"];
             $this->strAdministrativeArea = $arrResult["statecode"];
             $this->strSubAdministrativeArea = $arrResult["countycode"];
             $this->floatLatitude = $arrResult["latitude"];
             $this->floatLongitude = $arrResult["longitude"];
             //precision="address"
             //TODO: define standard accuracy values and map responses
             $this->intAccuracy = $arrResult["quality"];
             $bitReturn = true;
         }
     }
     return $bitReturn;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }