Permalink
Browse files

feature(rss): adds functions for adding/removing the RSS link

Deprecates setting the global `$autofeed` var.
  • Loading branch information...
mrclay committed Feb 28, 2016
1 parent 0b310c6 commit ae765e1907b2967991706bb992ceee6b136bccc1
View
@@ -537,8 +537,7 @@ function _elgg_get_entity_time_where_sql($table, $time_created_upper = null,
function elgg_list_entities(array $options = array(), $getter = 'elgg_get_entities',
$viewer = 'elgg_view_entity_list') {
- global $autofeed;
- $autofeed = true;
+ elgg_register_rss_link();
$offset_key = isset($options['offset_key']) ? $options['offset_key'] : 'offset';
@@ -800,8 +799,7 @@ function is_registered_entity_type($type, $subtype = null) {
* @since 1.7.0
*/
function elgg_list_registered_entities(array $options = array()) {
- global $autofeed;
- $autofeed = true;
+ elgg_register_rss_link();
$defaults = array(
'full_view' => false,
View
@@ -503,8 +503,7 @@ function _elgg_prefetch_river_entities(array $river_items) {
* @since 1.8.0
*/
function elgg_list_river(array $options = array()) {
- global $autofeed;
- $autofeed = true;
+ elgg_register_rss_link();
$defaults = array(
'offset' => (int) max(get_input('offset', 0), 0),
View
@@ -583,8 +583,7 @@ function _elgg_views_prepare_head($title) {
);
// RSS feed link
- global $autofeed;
- if (isset($autofeed) && $autofeed == true) {
+ if (_elgg_has_rss_link()) {
$url = current_page_url();
if (substr_count($url,'?')) {
$url .= "&view=rss";
@@ -805,8 +804,7 @@ function elgg_view_entity(\ElggEntity $entity, array $vars = array(), $bypass =
return false;
}
- global $autofeed;
- $autofeed = true;
+ elgg_register_rss_link();
$defaults = array(
'full_view' => true,
@@ -914,8 +912,7 @@ function elgg_view_entity_icon(\ElggEntity $entity, $size = 'medium', $vars = ar
* @return string/false Rendered annotation
*/
function elgg_view_annotation(\ElggAnnotation $annotation, array $vars = array(), $bypass = false, $debug = false) {
- global $autofeed;
- $autofeed = true;
+ elgg_register_rss_link();
$defaults = array(
'full_view' => true,
@@ -1442,6 +1439,38 @@ function elgg_view_icon($name, $vars = array()) {
return elgg_view("output/icon", $vars);
}
+/**
+ * Include the RSS icon link and link element in the head
+ *
+ * @return void
+ */
+function elgg_register_rss_link() {
+ _elgg_services()->config->set('_elgg_autofeed', true);
+}
+
+/**
+ * Remove the RSS icon link and link element from the head
+ *
+ * @return void
+ */
+function elgg_unregister_rss_link() {
+ _elgg_services()->config->set('_elgg_autofeed', false);
+}
+
+/**
+ * Should the RSS view of this URL be linked to?
+ *
+ * @return bool
+ * @access private
+ */
+function _elgg_has_rss_link() {
+ if (isset($GLOBALS['autofeed']) && is_bool($GLOBALS['autofeed'])) {
+ elgg_deprecated_notice('Do not set the global $autofeed. Use elgg_register_rss_link()', '2.1');
+ return $GLOBALS['autofeed'];
+ }
+ return (bool)_elgg_services()->config->getVolatile('_elgg_autofeed');
+}
+
/**
* Displays a user's access collections, using the core/friends/collections view
*
@@ -1537,14 +1566,13 @@ function _elgg_views_amd($hook, $type, $content, $params) {
}
/**
- * Add the rss link to the extras when if needed
+ * Add the RSS link to the extras when if needed
*
* @return void
* @access private
*/
function elgg_views_add_rss_link() {
- global $autofeed;
- if (isset($autofeed) && $autofeed == true) {
+ if (_elgg_has_rss_link()) {
$url = current_page_url();
if (substr_count($url, '?')) {
$url .= "&view=rss";
@@ -66,7 +66,6 @@
$body = elgg_view('custom_index/content', $vars);
// no RSS feed with a "widget" front page
-global $autofeed;
-$autofeed = FALSE;
+elgg_unregister_rss_link();
echo elgg_view_page('', $body);
@@ -2,9 +2,7 @@
$guid = elgg_extract('guid', $vars);
-// We now have RSS on topics
-global $autofeed;
-$autofeed = true;
+elgg_register_rss_link();
elgg_entity_gatekeeper($guid, 'object', 'discussion');
@@ -2,9 +2,7 @@
$guid = elgg_extract('guid', $vars);
-// turn this into a core function
-global $autofeed;
-$autofeed = true;
+elgg_register_rss_link();
elgg_entity_gatekeeper($guid, 'group');
@@ -6,8 +6,7 @@
*/
// Search supports RSS
-global $autofeed;
-$autofeed = true;
+elgg_register_rss_link();
// $search_type == all || entities || trigger plugin hook
$search_type = get_input('search_type', 'all');

0 comments on commit ae765e1

Please sign in to comment.