Extension: Voting
[vanilla-miry.git] / extensions / FeedPublisher / global_functions.php
blob97cfa6f04d0afcb7655dbd72bebd720b5ad0c12a
1 <?php
2 /**
3 * Utility functions used by FeedPublisher (a Vanilla extension).
4 */
6 /**
7 * GetFeedUriForFeed
9 * @param $Configuration
10 * @param $Parameters
12 function GetFeedUriForFeed( &$Configuration, $Parameters )
14 if ( $Configuration[ 'URL_BUILDING_METHOD' ] == 'mod_rewrite' )
15 $Parameters->Remove( 'DiscussionID' );
16 // force page 1 at all times
17 $Parameters->Remove( 'page' );
18 $Parameters->Set( 'page', 1 );
19 // build Uri
20 $Uri = GetRequestUri();
21 $Uri = explode( '?', $Uri );
22 $Uri = $Uri[ 0 ];
23 return $Uri . '?' . $Parameters->GetQueryString();
26 /**
27 * AddLinks
29 * Adds a clickable link to the Vanilla panel
30 * and adds an 'auto-discovery' link in the html head section.
32 * @param $Context
33 * @param $Properties
35 function AddLinks( &$Context, &$Head, &$Panel, $Properties )
37 // prepare parameters for the GetFeedUriForFeed() function
38 $p = $Context->ObjectFactory->NewObject($Context, 'Parameters');
39 $p->DefineCollection( $_GET );
40 $p->Set( 'Feed', $Properties[ 'FeedType' ] );
42 $FeedUrl = GetFeedUriForFeed( $Context->Configuration, $p );
44 // to the panel
45 /////
47 // prepare some strings
48 $ListName = $Context->GetDefinition( 'Feeds' );
49 $ListItem = $Context->GetDefinition( $Properties[ 'FeedType' ] . 'Feed' );
50 $BodyTitle = $Context->GetDefinition(
51 'FP_feedLinkToolTip_' . $Properties[ 'PageType' ] );
53 // add link
54 $Panel->AddList( $ListName, 5 );
55 $Panel->AddListItem(
56 $ListName,
57 $ListItem,
58 $FeedUrl,
59 '',
60 'title="' . $BodyTitle . '" class="'.$Properties[ 'FeedType' ].'"' );
62 // to the html head section
63 /////
65 // quick fix for the MIME type
66 if ( $Properties[ 'FeedType' ] == 'RSS2' )
67 $MIME = 'rss';
68 else $MIME = strtolower( $Properties[ 'FeedType' ] );
70 // prepare title
71 $HeadTitle = $Context->GetDefinition( $Properties[ 'FeedType' ] . 'Feed' );
73 // add link
74 $HeadLink = '<link rel="alternate" ';
75 $HeadLink.= 'type="application/'. $MIME . '+xml" ';
76 $HeadLink.= 'href="' . $FeedUrl . '" ';
77 $HeadLink.= 'title="' . $HeadTitle . '"';
78 $HeadLink.= ' />';
79 $HeadLink = "\n " . $HeadLink . "\n "; // beautiful html source
80 $Head->AddString( $HeadLink );