Permalink
Browse files

Implement isValidFeedUrl API method to check whether an URL is a vali…

…d feed.
  • Loading branch information...
halfdan committed Feb 27, 2013
1 parent 57f4a07 commit 200d9dc7325769533b6252e2a8931ee1f2a1c0b8
Showing with 23 additions and 1 deletion.
  1. +23 −1 API.php
View
24 API.php
@@ -17,7 +17,7 @@
class Piwik_FeedAnnotation_API {
protected static $instance;
-
+
/**
* Gets or creates the FeedAnnotation API singleton.
*/
@@ -30,6 +30,13 @@ static public function getInstance()
return self::$instance;
}
+ /**
+ * Returns all configured feeds for all idSites.
+ * User needs to have admin access to a site.
+ *
+ * @param array $idSites
+ * @return array
+ */
public function getFeeds($idSites = array()) {
if (count($idSites)) {
Piwik::checkUserHasViewAccess($idSites);
@@ -46,4 +53,19 @@ public function getFeeds($idSites = array()) {
return $feeds;
}
+
+ /**
+ * Checks whether the URL returns a parsable feed (RSS/Atom)
+ *
+ * @param $url
+ * @return bool
+ */
+ public function isValidFeedUrl($url) {
+ try {
+ Zend_Feed::import($url);
+ return true;
+ } catch (Zend_Feed_Exception $e) {
+ return false;
+ }
+ }
}

0 comments on commit 200d9dc

Please sign in to comment.