Replaced FeedPublisher by FeedThis: feedthis-1.03.zip
[vanilla-miry.git] / extensions / FeedThis / default.php
blob64fd491743c57e391b1e4437da32959f2f50ae48
1 <?php
2 /*
3 Extension Name: FeedThis
4 Extension Url: http://lussumo.com/addons/index.php?PostBackAction=AddOn&AddOnID=419
5 Description: Publish RSS2/ATOM Feeds of Discussions, Comments, Blogs and Searches.
6 Version: 1.03
7 Author: Andrew Miller (Spode)
8 Author Url: http://www.spodesabode.com
9 */
12 Based on Feed Publisher by Christophe Gragnic which was based on extensions by Dan Richman (CrudeRSS) and Mark O'Sullivan (RSS2, ATOM).
15 if (!defined('IN_VANILLA')) exit();
17 //Get language (change this to whatever language file is available to you)
18 include ($Configuration['EXTENSIONS_PATH'].'FeedThis/languages/english.php');
20 //Include libraries
21 include ($Configuration['EXTENSIONS_PATH'].'FeedThis/library/Function.FeedThis.php');
22 include ($Configuration['EXTENSIONS_PATH'].'FeedThis/library/PostBackControl.FeedThis.php');
24 //Configuration defaults
25 if( !array_key_exists('FT_PANEL_POSITION', $Configuration)) {AddConfigurationSetting($Context, 'FT_PANEL_POSITION', '5');}
26 if( !array_key_exists('FT_FEED_ITEMS', $Configuration)) {AddConfigurationSetting($Context, 'FT_FEED_ITEMS', '25');}
27 if( !array_key_exists('FT_WORD_LIMIT', $Configuration)) {AddConfigurationSetting($Context, 'FT_WORD_LIMIT', '0');}
28 if( !array_key_exists('FT_BLOG_FEED', $Configuration)) {AddConfigurationSetting($Context, 'FT_BLOG_FEED', '1');}
29 if( !array_key_exists('FT_BLOG_FEED_EVERY', $Configuration)) {AddConfigurationSetting($Context, 'FT_BLOG_FEED_EVERY', '0');}
30 if( !array_key_exists('FT_ALLDISCUSSIONS_FEED', $Configuration)) {AddConfigurationSetting($Context, 'FT_ALLDISCUSSIONS_FEED', '1');}
31 if( !array_key_exists('FT_ALLDISCUSSIONS_FEED_EVERY', $Configuration)) {AddConfigurationSetting($Context, 'FT_ALLDISCUSSIONS_FEED_EVERY', '0');}
32 if( !array_key_exists('FT_DISCUSSION_FEED', $Configuration)) {AddConfigurationSetting($Context, 'FT_DISCUSSION_FEED', '1');}
33 if( !array_key_exists('FT_CATEGORY_FEED', $Configuration)) {AddConfigurationSetting($Context, 'FT_CATEGORY_FEED', '1');}
34 if( !array_key_exists('FT_SEARCHRESULTS_FEED', $Configuration)) {AddConfigurationSetting($Context, 'FT_SEARCHRESULTS_FEED', '0');}
35 if( !array_key_exists('FT_USERBLOG_FEED', $Configuration)) {AddConfigurationSetting($Context, 'FT_USERBLOG_FEED', '0');}
36 if( !array_key_exists('FT_USERCOMMENTS_FEED', $Configuration)) {AddConfigurationSetting($Context, 'FT_USERCOMMENTS_FEED', '0');}
37 if( !array_key_exists('FT_NOSIDEBAR', $Configuration)) {AddConfigurationSetting($Context, 'FT_NOSIDEBAR', '0');}
39 //Grab the finetune configuration file
40 include ($Configuration['EXTENSIONS_PATH'].'FeedThis/finetune.php');
42 //Incorporate finetune settings into the Vanilla configuration with our 'fp_' namespace
43 if (is_array($ft_conf) && !empty($ft_conf))
45 foreach ($ft_conf as $key => $value)
47 $Context->Configuration['FT_'.$key] = $value;
49 unset($ft_conf);
52 //Settings panel for Feed Publisher
53 if (($Context->SelfUrl == 'settings.php') && $Context->Session->User->Permission('PERMISSION_CHANGE_APPLICATION_SETTINGS'))
55 $FPForm = $Context->ObjectFactory->NewContextObject($Context, 'FTForm');
56 $Page->AddRenderControl($FPForm, $Configuration["CONTROL_POSITION_BODY_ITEM"]);
57 $ExtensionOptions = $Context->GetDefinition('Extension Options');
58 $Panel->AddList($ExtensionOptions);
59 $Panel->AddListItem($ExtensionOptions, $Context->GetDefinition('FTSettings'), GetUrl($Context->Configuration, 'settings.php', '', '', '', '', 'PostBackAction=FeedThis'));
62 //Is this a feed, or normal browsing?
63 $FeedType = ForceIncomingString ('Feed', '');
65 //If this is a feed, is it one of the configured to be allowed?
66 if (!in_array ($FeedType, $Context->Configuration['FT_PUBLISHED_TYPES']))
68 $FeedType = '';
70 else
72 //Adds ability to search by CategoryID, DiscussionID or AuthUserID for Comment Searches
73 $Context->AddToDelegate("CommentManager", "SearchBuilder_PostWhere", "Search_FeedAddQuery");
75 //Changes the order of Discussion Searches
76 $Context->AddToDelegate("DiscussionManager", "PostGetDiscussionBuilder", "Search_FeedAddQueryDiscussions");
79 //Pages that should be processed.
80 $processed_pages = array( 'index.php', 'search.php', 'comments.php', 'categories.php', 'extension.php', 'account.php');
82 if (in_array ($Context->SelfUrl, $processed_pages))
84 //For non-feed
85 if ($FeedType == '')
87 //display all discussions
88 if (($Context->SelfUrl == "index.php" || $Context->SelfUrl == "categories.php" || $Context->Configuration['FT_ALLDISCUSSIONS_FEED_EVERY']) && !ForceIncomingInt("CategoryID", '') && ($Context->Configuration['FT_ALLDISCUSSIONS_FEED']) || $Context->Configuration['FT_ALLDISCUSSIONS_FEED_EVERY'])
90 unset ($Properties);
91 $Properties['SearchType'] = "Topics";
92 $Properties['ListName'] = $Context->GetDefinition('AllDiscussionsFeed');
93 $Properties['Extra'] = "&FeedTitle=".urlencode($Properties['ListName']);
94 AddLinksForEach($Properties);
96 //display category listing
97 if (($Context->SelfUrl == "index.php" || $Context->SelfUrl == "categories.php") && ($CategoryID = ForceIncomingInt("CategoryID", '')) && $Context->Configuration['FT_CATEGORY_FEED'])
99 unset ($Properties);
100 $Properties['SearchType'] = "Topics";
101 $Properties['ListName'] = $Context->GetDefinition('CategoryFeed');
102 $Properties['Extra'] = "&CategoryID=".$CategoryID."&FeedTitle=".urlencode($Properties['ListName']." (".GetCategoryName($CategoryID).")");
103 AddLinksForEach($Properties);
105 //BlogThis feed
106 if (($Context->SelfUrl == "extension.php" && (ForceIncomingString("PostBackAction", '') == 'Blog') && $Context->Configuration['FT_BLOG_FEED']) || $Context->Configuration['FT_BLOG_FEED_EVERY'])
108 unset ($Properties);
109 //Support for per-user Blog RSS Feed
110 $BlogUser = ForceIncomingString("BlogUser", '');
111 if ($BlogUser)
113 $Extra = " (".GetUserName($BlogUser).")";
114 $BlogUser = "&AuthUserID=".$BlogUser;
117 $Properties['SearchType'] = "Comments";
118 $Properties['ListName'] = $Context->GetDefinition('BlogFeed');
119 $Properties['Extra'] = "&BlogSearch=1".@$BlogUser."&FeedTitle=".urlencode($Properties['ListName'].@$Extra);
120 AddLinksForEach($Properties);
122 if ($Context->SelfUrl == "account.php")
124 $UserID = ForceIncomingString('u', $Context->Session->UserID);
125 $UserManager = $Context->ObjectFactory->NewContextObject($Context, 'UserManager');
126 $User = $UserManager->GetUserById($UserID);
128 //Add user Blog Feed
129 if (array_key_exists('BLOGTHIS', $Configuration) && $Context->Configuration['FT_USERBLOG_FEED'] && ($User->Permission('PERMISSION_CANBLOGTHIS') || $User->Permission('PERMISSION_CANBLOGALL')))
131 unset ($Properties);
132 $Properties['SearchType'] = "Comments";
133 $Properties['ListName'] = $Context->GetDefinition('UserBlogFeed');
134 $Properties['Extra'] = "&BlogSearch=1&AuthUserID=".($UserID)."&FeedTitle=".urlencode($Properties['ListName']." (".GetUserName($UserID).")");
135 AddLinksForEach($Properties);
137 //Add user's Comments
138 if ($Context->Configuration['FT_USERCOMMENTS_FEED'])
140 unset ($Properties);
141 $Properties['SearchType'] = "Comments";
142 $Properties['ListName'] = $Context->GetDefinition('UserCommentsFeed');
143 $Properties['Extra'] = "&AuthUserID=".($UserID)."&FeedTitle=".urlencode($Properties['ListName']." (".GetUserName($UserID).")");
144 AddLinksForEach($Properties);
147 //Discussion comments
148 if ($Context->SelfUrl == "comments.php" && ($DiscussionID = ForceIncomingInt("DiscussionID", '')) && $Context->Configuration['FT_DISCUSSION_FEED'])
150 unset ($Properties);
151 $Properties['SearchType'] = "Comments";
152 $Properties['ListName'] = $Context->GetDefinition('DiscussionFeed');
153 $Properties['Extra'] = "&DiscussionID=".$DiscussionID."&FeedTitle=".urlencode($Properties['ListName']." (".GetDiscussionName($DiscussionID).")");
154 AddLinksForEach($Properties);
156 //Search Results
157 if ($Context->SelfUrl == "search.php" && ForceIncomingString("PostBackAction", '') == 'Search' && $Context->Configuration['FT_SEARCHRESULTS_FEED'])
159 unset ($Properties);
160 $Tag = ForceIncomingString("Tag", '');
161 $Keywords = ForceIncomingString("Keywords", '');
162 $Authusername = ForceIncomingString("AuthUsername", '');
163 $Categories = ForceIncomingString("Categories", '');
164 $Advanced = ForceIncomingInt("Advanced", '');
165 $Type = ForceIncomingString("Type", '');
167 $Extra = "";
169 //Add them to the search string.
170 if ($Tag)
172 $Extra.= "Tag: ".$Tag." ";
173 $Tag = "&Tag=".$Tag;
176 if ($Keywords)
178 $Extra.= "Keywords: ".$Keywords.", ";
179 $Keywords = "&Keywords=".$Keywords;
182 if ($Authusername)
184 $Extra.= "Author: ".$Authusername.", ";
185 $Authusername = "&AuthUsername=".$Authusername;
188 if ($Categories)
190 $Extra.= "Category: ".$Categories.", ";
191 $Categories = "&Categories=".$Categories;
194 if ($Advanced)
196 $Advanced = "&Advanced=".$Advanced;
200 if ($Extra == "")
202 unset($Extra);
204 else
206 $Extra = " (".substr($Extra,0,strlen($Extra)-1).")";
209 $Properties['SearchType'] = $Type;
210 $Properties['ListName'] = $Context->GetDefinition('SearchFeed');
211 $Properties['Extra'] = @$Tag.@$Keywords.@$Authusername.@$Categories.@$Advanced."&FeedTitle=".urlencode($Properties['ListName'].@$Extra);
212 AddLinksForEach($Properties);
215 //For feed
216 else
218 // Make sure that page is not redirected if the user is not signed in and this is not a public forum
219 if ($Context->Session->UserID == 0 && !$Configuration["PUBLIC_BROWSING"])
221 // Temporarily make the PUBLIC_BROWSING enabled, but make sure to validate this user
222 $Configuration[ "PUBLIC_BROWSING" ] = 1;
223 $Context->Configuration['FT_AUTHENTICATE_USER'] = 1;
225 else
227 $Context->Configuration[ 'FT_AUTHENTICATE_USER' ] = 0;
230 //Exit the feed? For compatibility with SimpleCache
231 if (!$Context->Configuration['FT_EXIT_AFTER_FEED'])
233 $Context->AddToDelegate('PageEnd', 'PostRender', 'CleanBufferAndDisplayFeed');
237 //This is where the magic happens. ALL feeds originate from a search.
238 if ($Context->SelfUrl == "search.php" && $FeedType)
240 //Override the number of search results.
241 $Context->Configuration['SEARCH_RESULTS_PER_PAGE'] = $Context->Configuration['FT_FEED_ITEMS']-1;
243 //Get search parameters from the URL
244 $SearchType = ForceIncomingString( "Type", "" );
245 $SearchID = ForceIncomingInt( "SearchID", 0);
247 //If no search type in the url but we found an 'id', so grab the search type from the 'id'
248 if ($SearchType == "" && $SearchID > 0)
250 $SearchManager = $Context->ObjectFactory->NewContextObject($Context, "SearchManager");
251 $Search = $SearchManager->GetSearchById($SearchID);
252 if ($Search)
254 $SearchType = $Search->Type;
258 if ($SearchType == "Topics" || $SearchType == "Discussions")
260 //Think this could be a bug in Vanilla itself - so a work around...
261 $SearchType = "Topics";
263 //Make sure that the first comment is also grabbed from the search
264 $Context->AddToDelegate("DiscussionManager", "PostGetDiscussionBuilder", "DiscussionManager_GetFirstCommentForFeeds" );
266 $Context->AddToDelegate("SearchForm", "PostLoadData", "SearchForm_InjectFeedToTopicSearch");
268 elseif ($SearchType == "Comments")
270 $Context->AddToDelegate ("SearchForm", "PostLoadData", "SearchForm_InjectFeedToCommentSearch");