Skip to content

Commit

Permalink
Merge pull request #915 from josaphatim/fixed-adding-one-feed-url-mul…
Browse files Browse the repository at this point in the history
…tiple-times

Fix adding one feed url multiple times
  • Loading branch information
marclaporte authored Mar 8, 2024
2 parents 83b4980 + 86c0e12 commit 0ba04fd
Showing 1 changed file with 43 additions and 25 deletions.
68 changes: 43 additions & 25 deletions modules/feeds/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,41 +356,45 @@ public function process() {
$found = false;
list($success, $form) = $this->process_form(array('new_feed_name', 'new_feed_address'));
if ($success) {
$connection_test = address_from_url($form['new_feed_address']);
if ($con = @fsockopen($connection_test, 80, $errno, $errstr, 2)) {
$feed = is_news_feed($form['new_feed_address']);
if (!$feed) {
$feed = new Hm_Feed();
$homepage = $feed->get_feed_data($form['new_feed_address']);
if (trim($homepage)) {
list($type, $href) = search_for_feeds($homepage);
if ($type && $href) {
Hm_Msgs::add('Discovered a feed at that address');
$found = true;
if (feed_exists($form['new_feed_address'])) {
Hm_Msgs::add(sprintf('ERRFeed url %s already exists', $form['new_feed_address']));
} else {
$connection_test = address_from_url($form['new_feed_address']);
if ($con = @fsockopen($connection_test, 80, $errno, $errstr, 2)) {
$feed = is_news_feed($form['new_feed_address']);
if (!$feed) {
$feed = new Hm_Feed();
$homepage = $feed->get_feed_data($form['new_feed_address']);
if (trim($homepage)) {
list($type, $href) = search_for_feeds($homepage);
if ($type && $href) {
Hm_Msgs::add('Discovered a feed at that address');
$found = true;
}
else {
Hm_Msgs::add('ERRCould not find an RSS or ATOM feed at that address');
}
}
else {
Hm_Msgs::add('ERRCould not find an RSS or ATOM feed at that address');
Hm_Msgs::add('ERRCould not find a feed at that address');
}
}
else {
Hm_Msgs::add('ERRCould not find a feed at that address');
Hm_Msgs::add('Successfully connected to feed');
$found = true;
if (stristr('<feed', $feed->xml_data)) {
$type = 'application/atom+xml';
}
else {
$type = 'application/rss+xml';
}
$href = $form['new_feed_address'];
}
}
else {
Hm_Msgs::add('Successfully connected to feed');
$found = true;
if (stristr('<feed', $feed->xml_data)) {
$type = 'application/atom+xml';
}
else {
$type = 'application/rss+xml';
}
$href = $form['new_feed_address'];
Hm_Msgs::add(sprintf('ERRCould not add feed: %s', $errstr));
}
}
else {
Hm_Msgs::add(sprintf('ERRCould not add feed: %s', $errstr));
}
}
else {
Hm_Msgs::add('ERRFeed Name and Address are required');
Expand Down Expand Up @@ -1036,3 +1040,17 @@ function feed_memcached_fetch($hmod, $feed_data) {
$key = sprintf('%s%s%s', $feed_data['server'], $feed_data['tls'], $feed_data['port']);
return $hmod->cache->get($key);
}}

/**
* @subpackage feeds/functions
*/
if (!hm_exists('feed_exists')) {
function feed_exists($server) {
$list = Hm_Feed_List::dump();
foreach ($list as $feed) {
if ($feed['server'] == $server) {
return true;
}
}
return false;
}}

0 comments on commit 0ba04fd

Please sign in to comment.