Happy New Year! While on the street is a holiday, I was engaged in one of the interesting problems (or tasks, as to whom) of my project. Given - a system similar to Google Readers, which receives a certain address from the user and should provide a view (and later, a subscription) of RSS feeds available there. The task is complicated by the fact that it is impossible to require the user to enter the full address of the tape, or even just the address of the site or an arbitrary page - it can be entered in completely different ways, in whole or in part, etc. Themselves tapes on the page can also be more than one, often several formats at once (or even not at all). Therefore, we need to select the latest posts from all available tapes and display to the user so that he will eventually choose one tape that interests him. Let me tell you a secret - yes, this is only the beginning and in subsequent articles we will together build a slightly smaller version of the aggregation system and news readings. But today we will try to solve the first task, without which our “reader” simply cannot work, no matter what further technology is used./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter .
/** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter ./** * URI * * @param String $uri * @return boolean|string * @throw Zend_Uri_Exception */ public static function _validURI($uri) { if (empty($uri)) return false ; else $uri = trim(strtolower(uri)); try { // URI $_uri = Zend_Uri::factory($uri); $res = $_uri->valid($uri); if ($res === true ) { // , URL return $_uri->getUri(); } else return false ; } catch (Zend_Uri_Exception $e) { // ? try { if ( (strpos($uri, 'http://' ) === false ) || (strpos($uri, 'https://' ) === false ) ) { $uri = self::$defailt_rss_scheme . $uri; $_uri = Zend_Uri::factory($uri); if ($_uri->valid($uri)) return $_uri->getUri(); } else // , ? return false ; } catch (Zend_Uri_Exception $e) { return false ; } } } * This source code was highlighted with Source Code Highlighter .
* This source code was highlighted with Source Code Highlighter .
- $ cache = Zend_Cache :: factory ( 'Core' ,
- 'File' ,
- array (
- 'lifetime' => 24 * 3600,
- 'automatic_serialization' => true
- 'caching' => true
- 'cache_id_prefix' => 'preview_feed_' ,
- 'write_control' => true
- 'ignore_user_abort' => true
- ),
- array (
- 'read_control_type' => 'adler32' ,
- 'cache_dir' => '/ tmp / cache'
- ))
- Zend_Feed_Reader :: setCache ($ cache);
- Zend_Feed_Reader :: useHttpConditionalGet ( true );
* This source code was highlighted with Source Code Highlighter .
- $ _url = array (
- 'http://www.cnbc.com/id/19789731/device/rss/rss.xml' ,
- 'http://www.planet-php.net/' ,
- 'ajaxian.com' ,
- 'http://twitter.com/abrdev' ,
- 'http://verens.com/archives/2009/12/28/multiple-file-uploads-using-html5/' );
* This source code was highlighted with Source Code Highlighter .
- // an array of links that are ready for processing (valid URIs)
- $ _links = Array ();
- echo "Checking URL ... <br />" ;
- foreach ($ _url as $ u)
- {
- echo "Original URL:" . $ u. "... <br />" ;
- $ _url = self :: _ validURI ($ u);
- if ($ _url === false ) continue ;
- else
- $ _links [] = $ _url;
- }
* This source code was highlighted with Source Code Highlighter .
- foreach ($ _links as $ fl)
- {
- // try to extract the URL from the specified site
- try
- {
- $ _lhttp = Zend_Uri_Http :: fromString ($ fl);
- if ($ _lhttp-> valid ())
- {
- // check and get the site name
- $ site = $ _lhttp-> getHost ();
- $ _feeds_links [$ site] = Array ();
- }
- else
- // if the check failed, skip
- continue ;
- }
- catch (Zend_Uri_Exception $ e) { continue ; }
* This source code was highlighted with Source Code Highlighter .
- try
- {
- $ _ln = Zend_Feed_Reader :: findFeedLinks ($ fl);
- if (($ _ln instanceOf Zend_Feed_Reader_FeedSet) && (count ($ _ ln)> 0))
- {
- $ tmp = Array ();
- foreach ($ _ln as $ cf)
- {
- // in $ cf we have an object for each feed, Zend_Feed_Reader_FeedSet
- // it inherits from ArrayObject and contains three fields
- // interesting to us: 'href' containing link to feed
- $ tmp [] = $ cf [ 'href' ];
- }
- // since there are duplicate feeds, remove duplicates
- if (! empty ($ tmp))
- {
- $ _feeds_links [$ site] = array_unique ($ tmp);
- }
- }
- else
- {
- // it can be a direct link to FeedURL
- // for this you have to try to download the document
- try
- {
- $ _tmp_feed = Zend_Feed_Reader :: import ($ fl);
- // we do not know in advance which format
- if ($ _tmp_feed instanceOf Zend_Feed_Reader_FeedAbstract)
- {
- // yes, this is a normal feed, it is already in the cache,
- // so just get the address in case of using proxy services
- // Practice has shown that using getFeedLink ()
- // sometimes does not give the desired result, for example for a CNBC feed
- $ _feeds_links [$ site] [] = $ fl;
- continue ;
- }
- else
- throw new Zend_Exception ( 'Bad feed' );
- }
- catch (Zend_Exception $ e)
- {
- //definitely not
- echo "<br /> <b>" . $ fl. "</ b> == Nothing feeds! <br />" ;
- continue ;
- }
- }
- }
- catch (Zend_Exception $ e)
- {
- continue ;
- }
* This source code was highlighted with Source Code Highlighter .
- echo '<br /> <br /> Retriving last feed items ... <br />' ;
- $ _feeds_items = Array (); // posts in feed
- $ _item_per_feed = 10; // How many messages from the tape pull
- foreach ($ _feeds_links as $ _flinks)
- {
- if (count ($ _ flinks)> 0)
- {
- foreach ($ _flinks as $ fl)
- {
- try
- {
- $ _x_feed = Zend_Feed_Reader :: import ($ fl);
- // can be both Atom and RSS,
- // so we check by abstract ancestor class
- if ($ _x_feed instanceOf Zend_Feed_Reader_FeedAbstract)
- {
- $ tmpx = Array ( 'title' => null , 'items' => Array ());
- $ tmpx [ 'title' ] = htmlspecialchars ($ _ x_feed-> getTitle (), ENT_QUOTES);
- $ i = 0;
- foreach ($ _x_feed as $ fitm)
- {
- if ($ i <$ _item_per_feed)
- {
- $ i ++;
- // get the name, link and date (in GMT)
- // GUID - md5 (getId ());
- $ tmpx [ 'items' ] [] = ' <a href="' .$fitm-> getLink (). '"target =" _ blank ">' .htmlspecialchars ($ fitm-> getTitle (), ENT_QUOTES). '</a> at' . $ fitm-> getDateCreated () -> toString (). '<br />' ;
- }
- else break ;
- }
- $ _feeds_items [$ fl] = $ tmpx;
- }
- }
- catch (Zend_Exception $ e) { continue ; }
- }
- }
- }
- // see the result?
- var_dump ($ _ feeds_items);
Source: https://habr.com/ru/post/79879/
All Articles