<?php if (!defined('PmWiki')) exit();
/*
+----------------------------------------------------------------------+
|
| This script inserts links to RSS and Atom feeds in your HTML headers.
| The links are used for "auto discovery" of your feeds.
|
| Place this script in your cookbook/ directory, then use the following
| in your config.php file:
|
|   ## Enable the feedlinks recipe.
|   # $EnableSitewideFeed = 0;  # 0 = Offer feeds by group, default is 1 = for sitewide.
|   # $EnableRssLink = 0;       # 0 = don't write the link, default is 1 = write the link.
|   # $EnableAtomLink = 0;      # 0 = don't write the link, default is 1 = write the link.
|   # $EnablePageLink = 1;      # 1 = write the link, default is 0 = don't write the link.
|   @include_once("$FarmD/cookbook/feedlinks.php");
|
| Make sure your feeds are enabled.  :-)  To enable RSS and Atom feeds,
| use the following in your local/config.php file:
|
|   if ($action == 'rss' || $action == 'atom') {
|     include_once("scripts/feeds.php"); }
| 
| or if you enable PageLink use 
|   include_once("$FarmD/cookbook/pagefeed.php");
|
| You can now use $FeedLinkUrlVariables in config.php to extend the url.
| Set this before you include the feedlinks.php.
| I use par example
|   $FeedLinkUrlVariables = '&setlang=$Lang&FFVersion=8';
|
| This recipe's page:  http://www.pmwiki.org/wiki/Cookbook/FeedLinks
+----------------------------------------------------------------------+
| Copyright 2006 Hagan Fox - http://pmwiki.org/wiki/Profiles/HaganFox
| Version 0.2 extension for pagefeed links and UrlVariables FranzFrese
| This program is free software; you can redistribute it and/or modify
| it under the terms of the GNU General Public License, Version 2, as
| published by the Free Software Foundation.
| http://www.gnu.org/copyleft/gpl.html
| This program is distributed in the hope that it will be useful,
| but WITHOUT ANY WARRANTY; without even the implied warranty of
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
| GNU General Public License for more details.
+----------------------------------------------------------------------+
*/
$RecipeInfo['FeedLinks']['Version'] = '0.2 (2018-02-08)';

SDV($EnableSitewideFeed, TRUE);   # Link to Site/AllRecentChanges,
                                  # otherwise feed is group-specific.
SDV($EnableRssLink, TRUE);
SDV($EnableAtomLink, TRUE);
SDV($EnablePageLink, FALSE);
if ($EnableSitewideFeed == TRUE) {
  $FeedLinkSourcePath = $FeedLinkSourcePath ?: '$[$SiteGroup/AllRecentChanges]';
  $FeedLinkTitleGroup = $FeedLinkTitleGroup ?: '';
  # $FeedLinkType = 'sitewide';
} elseif ($EnablePageLink == TRUE) {
  $FeedLinkTitleGroup = $FeedLinkTitleGroup ?: ' : $Group/$Name -';
} else {
  $FeedLinkSourcePath = $FeedLinkSourcePath ?: '$[$Group/RecentChanges]';
  $FeedLinkTitleGroup = $FeedLinkTitleGroup ?: ' : $[$Group] -';
  # $FeedLinkType = 'bygroup';
}
$FeedLinkUrlVariables = $FeedLinkUrlVariables ?: '';
SDV($FeedLinkNum, 0);
$FeedLinkNum++;
if ($EnableRssLink) {
  $HTMLHeaderFmt['rsslink'.$FeedLinkNum] =
    "<link rel='alternate' title='\$WikiTitle$FeedLinkTitleGroup $[RSS Feed]'
      href='\$ScriptUrl/$FeedLinkSourcePath?action=rss$$FeedLinkUrlVariables'
      type='application/rss+xml' />\n  ";
}
if ($EnableAtomLink) {
  $HTMLHeaderFmt['atomlink'.$FeedLinkNum] =
    "<link rel='alternate' title='\$WikiTitle$FeedLinkTitleGroup $[Atom Feed]'
      href='\$ScriptUrl/$FeedLinkSourcePath?action=atom$FeedLinkUrlVariables'
      type='application/atom+xml' />\n  ";
}
if ($EnablePageLink) {	
  $FeedLinkTitleGroup = $FeedLinkTitleGroup ?: ' : $[$Group] -';
  $HTMLHeaderFmt['pagelink'.$FeedLinkNum] =
    "<link rel='alternate' title='\$WikiTitle$FeedLinkTitleGroup $[RSS Feed]'
      href='\$ScriptUrl/\$Group/\$Name?action=pagefeed$FeedLinkUrlVariables'
      type='application/rss+xml' />\n  ";
}

unset($FeedLinkSourcePath);
unset($FeedLinkTitleGroup);
unset($FeedLinkUrlVariables);