/** * Check input, strip slashes etc. set alert, if input is not ok. * * @return boolean Input ok, true/false */ function checkInput() { global $lng; $lng->loadLanguageModule("feed"); $_POST[$this->getPostVar()] = ilUtil::stripSlashes($_POST[$this->getPostVar()]); // remove safari pseudo protocol if (substr($_POST[$this->getPostVar()], 0, 5) == "feed:") { $_POST[$this->getPostVar()] = "http:" . substr($_POST[$this->getPostVar()], 5); } // add missing http:// if (!is_int(strpos($_POST[$this->getPostVar()], "://"))) { $_POST[$this->getPostVar()] = "http://" . $_POST[$this->getPostVar()]; } // check required if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "") { $this->setAlert($lng->txt("msg_input_is_required")); return false; } // check feed url $url = $_POST[$this->getPostVar()]; include_once "./Services/Feeds/classes/class.ilExternalFeed.php"; $check = ilExternalFeed::_checkUrl($url); // try to determine a feed url, if we failed here if ($check !== true) { $url2 = ilExternalFeed::_determineFeedUrl($url); $check2 = ilExternalFeed::_checkUrl($url2); if ($check2 === true) { $_POST[$this->getPostVar()] = $url2; $check = true; } } // if check failed, output error message if ($check !== true) { $check = str_replace("MagpieRSS:", "", $check); $this->setAlert($lng->txt("feed_no_valid_url") . "<br />" . $check); return false; } return true; }
/** * Determine Feed Url * * @param $a_url URL that */ static function _determineFeedUrl($a_url) { if (!defined('IL_FEED_PROXY_HOST')) { if (ilProxySettings::_getInstance()->isActive()) { define('IL_FEED_PROXY_HOST', ilProxySettings::_getInstance()->getHost()); define('IL_FEED_PROXY_PORT', ilProxySettings::_getInstance()->getPort()); } else { define('IL_FEED_PROXY_HOST', ""); define('IL_FEED_PROXY_PORT', ""); } } $res = @fopen($a_url, "r"); if (!$res) { return ""; } $contents = ''; while (!feof($res)) { $contents .= fread($res, 8192); } fclose($res); return ilExternalFeed::_getRSSLocation($contents, $a_url); }