3 Extension Name: Feed Publisher
4 Extension Url: http://tools.assembla.com/vanilla_feed_publisher/
5 Description: Handles feed publishing. Based on CrudeRSS, RSS2 and ATOM.
7 Author: Christophe Gragnic, Dan Richman (CrudeRSS), Mark O'Sullivan (RSS2, ATOM)
8 Author Url: http://www.fasterdisco.com/photo/44_78_b.jpg
10 if (!defined('IN_VANILLA')) exit();
12 // language strings, see the 'translations' directory
13 $Context->SetDefinition(
16 $Context->SetDefinition(
17 "FP_feedLinkToolTip_discussion",
18 "Subscribe to the feed of this discussion");
19 $Context->SetDefinition(
20 "FP_feedLinkToolTip_search",
21 "Subscribe to the feed of this search");
22 $Context->SetDefinition(
25 $Context->SetDefinition(
28 $Context->SetDefinition(
29 "FailedFeedAuthenticationTitle",
30 "Failed Authentication");
31 $Context->SetDefinition(
32 "FailedFeedAuthenticationText",
33 "Feeds for this forum require user authentication.");
34 // end language strings
37 ////////////////////////
39 // grab the config items
40 include( $Configuration[ 'EXTENSIONS_PATH' ] . 'FeedPublisher/config.php' );
41 // incorporate them in the Vanilla ones with our 'fp_' namespace
42 if ( is_array( $fp_conf ) AND !empty( $fp_conf ) )
44 foreach( $fp_conf as $k => $v )
45 $Context->Configuration
[ 'fp_'.$k ] = $v;
49 // this will tell us if we browse the forum or if a feed has to be rendered
50 // ( $FeedType == '' ) means normal browsing
51 $FeedType = ForceIncomingString( 'Feed', '' );
53 // sanitize the feed type: only let the published ones through
54 if ( ! in_array( $FeedType, $Context->Configuration
[ 'fp_PublishedTypes' ] ) )
57 // only process Feed Publisher on some pages and if the feed type is correct
58 // quick note: list of php files in Vanilla root is
59 // account.php categories.php comments.php extension.php index.php
60 // people.php post.php search.php settings.php termsofservice.php
61 $processed_pages = array( 'index.php', 'search.php', 'comments.php' );
62 $GoodPage = in_array( $Context->SelfUrl
, $processed_pages );
64 in_array( $FeedType, $Context->Configuration
[ 'fp_PublishedTypes' ] )
66 if ( $GoodPage AND $GoodFeedType )
68 // first some common stuff, then we'll act according to the requested page
69 if ( $FeedType == '' )
71 include( $Configuration[ 'EXTENSIONS_PATH' ] . 'FeedPublisher/global_functions.php' );
75 include( $Configuration[ "EXTENSIONS_PATH" ] . "FeedPublisher/functions.php" );
77 // Make sure that page is not redirected if the user is not signed in
78 // and this is not a public forum
80 $Context->Session
->UserID
== 0
81 && ! $Configuration[ "PUBLIC_BROWSING" ]
84 // Temporarily make the PUBLIC_BROWSING enabled,
85 // but make sure to validate this user
86 $Configuration[ "PUBLIC_BROWSING" ] = 1;
87 $Context->Configuration
[ 'AUTHENTICATE_USER_FOR_FEED_PUBLISHER' ] = 1;
91 $Context->Configuration
[ 'AUTHENTICATE_USER_FOR_FEED_PUBLISHER' ] = 0;
94 // if we don't want to exit after the display of the feed,
95 // we display it after cleaning the buffer, after PageEnd's Render
96 if ( ! $Context->Configuration
[ 'fp_ExitAfterFeed' ] )
98 $Context->AddToDelegate(
101 'CleanBufferAndDisplayFeed' );
105 // act here according to the requested page
106 if ( $Context->SelfUrl
== "index.php" )
108 // see if we browse the forum or if a feed must be rendered
109 // ( $FeedType == '' ) means normal browsing
110 if ( $FeedType == '' )
112 // include user configuration about categories, that's all
113 $cat_conf = 'FeedPublisher/categories_config.php';
114 include( $Configuration[ 'EXTENSIONS_PATH' ] . $cat_conf );
118 // REMOVED DUE TO PROBLEMS
119 // Use manual generic search feed without keywords instead.
122 elseif ( $Context->SelfUrl
== "search.php" )
124 // grab the search params in the url
125 $SearchType = ForceIncomingString( "Type", "" );
126 $SearchID = ForceIncomingInt( "SearchID", 0);
128 // if no search type in the url but we found an 'id'
129 // grab the search type from the 'id'
130 if ( $SearchType == "" && $SearchID > 0 )
133 = $Context->ObjectFactory
->NewContextObject( $Context, "SearchManager" );
134 $Search = $SearchManager->GetSearchById( $SearchID );
135 if ( $Search ) $SearchType = $Search->Type
;
138 // now see if we browse the forum or if a feed must be rendered
139 // ( $FeedType == '' ) means normal browsing
140 if ( $FeedType == '' )
142 // add feed links in the Vanilla panel and in the html head
143 // no links are set for User searches
144 if ( $SearchType == 'Topics' ||
$SearchType == 'Comments' )
146 foreach ( $Context->Configuration
[ 'fp_PublishedTypes' ] as $PublishedType )
148 $LinksProperties[ 'FeedType' ] = $PublishedType ;
149 $LinksProperties[ 'PageType' ] = 'search';
150 AddLinks( $Context, $Head, $Panel, $LinksProperties );
156 if ( $SearchType == "Topics" )
158 // Make sure that the first comment is also grabbed from the search
159 $Context->AddToDelegate(
161 "PostGetDiscussionBuilder",
162 "DiscussionManager_GetFirstCommentForFeeds" );
164 // Attach to the PostLoadData Delegate of the SearchForm control
165 function SearchForm_InjectFeedToTopicSearch( $SearchForm )
169 if ( $SearchForm->Context
->WarningCollector
->Count() == 0 )
171 AuthenticateUserForFP( $SearchForm->Context
);
173 // Make sure that some channel properties are defined
174 $SearchForm->Context
->PageTitle
175 = ForceIncomingString( "Categories", "" );
176 $SearchForm->Context
->GetKeywords
177 = ForceIncomingString( "Keywords", "" );
178 $SearchForm->Context
->GetAuthUserName
179 = ForceIncomingString( "AuthUsername", "" );
181 // Loop through the data
184 $Properties = array();
185 while ( $DataSet = $SearchForm->Context
->Database
->GetRow( $SearchForm->Data
) )
187 if ( $Counter < $SearchForm->Context
->Configuration
[ "SEARCH_RESULTS_PER_PAGE" ] )
189 $Properties[ "Title" ]
190 = FormatHtmlStringInline( ForceString( $DataSet[ "Name" ], "" ) );
191 $Properties[ "Link" ]
193 $SearchForm->Context
->Configuration
,
197 ForceInt( $DataSet[ "DiscussionID" ], 0 ) );
198 $Properties[ "Published" ]
199 = FixDateForFP( $FeedType, @$DataSet[ "DateCreated" ] );
200 $Properties[ "Updated" ]
201 = FixDateForFP( $FeedType, @$DataSet[ "DateLastActive" ]);
202 $Properties[ "AuthorName" ]
203 = FormatHtmlStringInline(
204 ForceString($DataSet[ "AuthUsername" ], ""));
205 $Properties[ "AuthorUrl" ]
207 $SearchForm->Context
->Configuration
,
211 ForceInt($DataSet[ "AuthUserID" ],
214 // Format the comment according to the defined
215 // formatter for that comment
218 @$DataSet[ "FormatType" ],
219 $SearchForm->Context
->Configuration
[ "DEFAULT_FORMAT_TYPE" ] );
222 @$DataSet[ "Body" ], '...' );
223 $Properties[ "Content" ]
224 = $SearchForm->Context
->FormatString(
228 FORMAT_STRING_FOR_DISPLAY
);
229 $Properties[ "Summary" ]
230 = FormatStringForFeedSummary( @$DataSet[ "Body" ], $FeedType);
232 $Feed .= ReturnFeedItem( $Properties, $FeedType );
237 $Feed = ReturnWrappedFeedForSearch( $SearchForm->Context
, $Feed, $FeedType );
239 if ( $SearchForm->Context
->Configuration
[ 'fp_ExitAfterFeed' ] )
241 // Set the content type to xml and dump the feed
242 header("Content-type: text/xml\n");
245 // When all finished, unload the context object and stop
246 $SearchForm->Context
->Unload();
251 // store the feed in the context object
252 $SearchForm->Context
->Feed
= $Feed;
257 $Context->AddToDelegate(
260 "SearchForm_InjectFeedToTopicSearch" );
262 elseif ( $SearchType == "Comments" )
264 // Attach to the PostLoadData Delegate of the SearchForm control
265 function SearchForm_InjectFeedToCommentSearch( $SearchForm )
269 if ($SearchForm->Context
->WarningCollector
->Count() == 0)
271 AuthenticateUserForFP( $SearchForm->Context
);
273 // Make sure that some channel properties are defined
274 $SearchForm->Context
->PageTitle
275 = ForceIncomingString( "Categories", "" );
276 $SearchForm->Context
->GetKeywords
277 = ForceIncomingString( "Keywords", "" );
278 $SearchForm->Context
->GetAuthUserName
279 = ForceIncomingString( "AuthUsername", "" );
281 // Loop through the data
284 $Properties = array();
285 $Comment = $SearchForm->Context
->ObjectFactory
->NewContextObject( $SearchForm->Context
, "Comment" );
286 while ( $Row = $SearchForm->Context
->Database
->GetRow( $SearchForm->Data
) )
289 $Comment->GetPropertiesFromDataSet( $Row, $SearchForm->Context
->Session
->UserID
);
291 if ( $Counter < $SearchForm->Context
->Configuration
["SEARCH_RESULTS_PER_PAGE" ] )
293 $Properties[ "Title" ]
294 = FormatHtmlStringInline( ForceString( $Comment->Discussion
, "" ) );
295 $Properties[ "Link" ]
297 $SearchForm->Context
->Configuration
,
301 $Comment->DiscussionID
,
303 "Focus=" . $Comment->CommentID
304 ."#Comment_" . $Comment->CommentID
);
305 $Properties[ "Published" ]
306 = FixDateForFP( $FeedType, @$Row[ "DateCreated" ] );
307 $Properties[ "Updated" ]
308 = FixDateForFP( $FeedType, @$Row[ "DateEdited" ] );
309 $Properties[ "AuthorName" ]
310 = $Comment->AuthUsername
;
311 $Properties[ "AuthorUrl" ]
313 $SearchForm->Context
->Configuration
,
317 $Comment->AuthUserID
);
319 // Format the comment according to the defined
320 // formatter for that comment
321 $Properties[ "Content" ]
322 = $SearchForm->Context
->FormatString(
325 $Comment->FormatType
,
326 FORMAT_STRING_FOR_DISPLAY
);
327 $Properties[ "Summary" ]
328 = FormatStringForFeedSummary( @$Row[ "Body" ], $FeedType );
330 $Feed .= ReturnFeedItem( $Properties, $FeedType );
335 $Feed = ReturnWrappedFeedForSearch( $SearchForm->Context
, $Feed, $FeedType );
337 if ( $SearchForm->Context
->Configuration
[ 'fp_ExitAfterFeed' ] )
339 // Set the content type to xml and dump the feed
340 header("Content-type: text/xml\n");
343 // When all finished, unload the context object and stop
344 $SearchForm->Context
->Unload();
349 // store the feed in the context object
350 $SearchForm->Context
->Feed
= $Feed;
355 $Context->AddToDelegate(
358 "SearchForm_InjectFeedToCommentSearch");
362 elseif ( $Context->SelfUrl
== "comments.php" )
364 // see if we browse the forum or if a feed must be rendered
365 // ( $FeedType == '' ) means normal browsing
366 if ( $FeedType == '' )
368 // add feed links in the Vanilla panel and in the html head
369 foreach ( $Context->Configuration
[ 'fp_PublishedTypes' ] as $PublishedType )
371 $LinksProperties[ 'FeedType' ] = $PublishedType ;
372 $LinksProperties[ 'PageType' ] = 'discussion';
373 AddLinks( $Context, $Head, $Panel, $LinksProperties );
378 // Attach to the Constructor Delegate of the CommentGrid control
379 function CommentGrid_InjectFeed( $CommentGrid )
383 if ( $CommentGrid->Context
->WarningCollector
->Count() == 0 )
385 AuthenticateUserForFP( $CommentGrid->Context
);
387 // Make sure that some channel properties are defined
388 $CommentGrid->Context
->PageTitle
389 = $CommentGrid->Discussion
->Name
;
391 // Loop through the data
393 $Properties = array();
395 = CalculateNumberOfPages(
396 $CommentGrid->CommentDataCount
,
397 $CommentGrid->Context
->Configuration
[ 'COMMENTS_PER_PAGE' ] );
399 = $CommentGrid->Context
->ObjectFactory
->NewContextObject(
400 $CommentGrid->Context
,
403 while ( $CurrentPage <= $PageCount )
405 $CommentGrid->CommentData
= $CommentManager->GetCommentList(
406 $CommentGrid->Context
->Configuration
[ 'COMMENTS_PER_PAGE' ],
408 $CommentGrid->Discussion
->DiscussionID
);
410 = $CommentGrid->Context
->ObjectFactory
->NewContextObject(
411 $CommentGrid->Context
,
413 while ( $Row = $CommentGrid->Context
->Database
->GetRow( $CommentGrid->CommentData
) )
416 $Comment->GetPropertiesFromDataSet( $Row, $CommentGrid->Context
->Session
->UserID
);
418 $Properties[ "Title" ]
419 = FormatHtmlStringInline( ForceString( $CommentGrid->Discussion
->Name
, "" ) );
420 $Properties[ "Link" ]
422 $CommentGrid->Context
->Configuration
,
426 $Comment->DiscussionID
,
428 "Focus=" . $Comment->CommentID
429 ."#Comment_" . $Comment->CommentID
);
430 $Properties[ "Published" ]
431 = FixDateForFP( $FeedType, @$Row[ "DateCreated" ] );
432 $Properties[ "Updated" ]
433 = FixDateForFP( $FeedType, @$Row[ "DateEdited" ] );
434 $Properties[ "AuthorName" ]
435 = $Comment->AuthUsername
;
436 $Properties[ "AuthorUrl" ]
438 $CommentGrid->Context
->Configuration
,
442 $Comment->AuthUserID
);
444 // Format the comment according to the defined
445 // formatter for that comment
446 $Properties[ "Content" ]
447 = $CommentGrid->Context
->FormatString(
450 $Comment->FormatType
,
451 FORMAT_STRING_FOR_DISPLAY
);
452 $Properties[ "Summary" ]
453 = FormatStringForFeedSummary( @$Row[ "Body" ] );
455 $Feed .= ReturnFeedItem( $Properties, $FeedType );
460 $Feed = ReturnWrappedFeed( $CommentGrid->Context
, $Feed, $FeedType );
462 if ( $CommentGrid->Context
->Configuration
[ 'fp_ExitAfterFeed' ] )
464 // Set the content type to xml and dump the feed
465 header("Content-type: text/xml\n");
468 // When all finished, unload the context object and stop
469 $CommentGrid->Context
->Unload();
474 // store the feed in the context object
475 $CommentGrid->Context
->Feed
= $Feed;
480 $Context->AddToDelegate(
483 "CommentGrid_InjectFeed" );