<commit_before><?php
/**
 * forums_BlockRssMenuAction
 * @package modules.forums.lib.blocks
 */
class forums_BlockRssMenuAction extends website_BlockAction
{
	/**
	 * @see website_BlockAction::execute()
	 *
	 * @param f_mvc_Request $request
	 * @param f_mvc_Response $response
	 * @return String
	 */
	function execute($request, $response)
	{
		if ($this->isInBackoffice())
		{
			return website_BlockView::NONE;
		}
		
		$doc = $this->getDocumentParameter('parentref');
		if ($doc instanceof forums_persistentdocument_post)
		{
			$thread = $doc->getThread();
			$forum = $thread->getForum();
			$topic = null;
			$website = $forum->getWebsite();
		}
		else if ($doc instanceof forums_persistentdocument_thread)
		{
			$thread = $doc;
			$forum = $thread->getForum();
			$topic = null;
			$website = $forum->getWebsite();
		}
		else if ($doc instanceof forums_persistentdocument_forumgroup)
		{
			$thread = null;
			$forum = $doc;
			$topic = null;
			$website = $forum->getWebsite();
		}
		else if ($doc instanceof website_persistentdocument_topic)
		{
			$thread = null;
			$forum = null;
			$topic = $doc;
			$website = f_util_ArrayUtils::firstElement($topic->getDocumentService()->getAncestorsOf($topic, 'modules_website/website'));
		}
		else if ($doc instanceof website_persistentdocument_website)
		{
			$thread = null;
			$forum = null;
			$topic = null;
			$website = $doc;
		}
		
		// Handle forum exclusion.
		if ($forum instanceof forums_persistentdocument_forumgroup && $forum->isExcludedFromRss())
		{
			return website_BlockView::NONE;
		}
		
		// Add RSS feeds.
		$this->addRssFeed($thread, 'false', array('post'));
		$this->addRssFeed($forum, 'false');
		$this->addRssFeed($topic, 'true');
		$this->addRssFeed($website, 'true');
		
		$request->setAttribute('links', $this->links);
		
		return website_BlockView::SUCCESS;
	}
	
	/**
	 * @var String[]
	 */
	private $links = array();
	
	/**
	 * @param f_persistentdocument_PersistentDocument $parent
	 * @param Boolean $recursive
	 * @param String[] $forTypes
	 */
	private function addRssFeed($parent, $recursive, $forTypes = array('post', 'thread'))
	{
		if ($parent !== null)
		{
			$modelName = f_Locale::translate($parent->getPersistentModel()->getDocumentName());
			foreach ($forTypes as $type)
			{
				$title = f_Locale::translate('&modules.forums.frontoffice.' . ucfirst($type) . 's-of-' . $modelName . 'Label;') . ' ' . $parent->getLabelAsHtml();
				$this->getContext()->addRssFeed($title, LinkHelper::getActionUrl('forums', 'ViewFeed', array('parentref' => $parent->getId(), 'docType' => 'post')));<commit_msg>[FIX] Bad RSS link<commit_after><?php
/**
 * forums_BlockRssMenuAction
 * @package modules.forums.lib.blocks
 */
class forums_BlockRssMenuAction extends website_BlockAction
{
	/**
	 * @see website_BlockAction::execute()
	 *
	 * @param f_mvc_Request $request
	 * @param f_mvc_Response $response
	 * @return String
	 */
	function execute($request, $response)
	{
		if ($this->isInBackoffice())
		{
			return website_BlockView::NONE;
		}
		
		$doc = $this->getDocumentParameter('parentref');
		if ($doc instanceof forums_persistentdocument_post)
		{
			$thread = $doc->getThread();
			$forum = $thread->getForum();
			$topic = null;
			$website = $forum->getWebsite();
		}
		else if ($doc instanceof forums_persistentdocument_thread)
		{
			$thread = $doc;
			$forum = $thread->getForum();
			$topic = null;
			$website = $forum->getWebsite();
		}
		else if ($doc instanceof forums_persistentdocument_forumgroup)
		{
			$thread = null;
			$forum = $doc;
			$topic = null;
			$website = $forum->getWebsite();
		}
		else if ($doc instanceof website_persistentdocument_topic)
		{
			$thread = null;
			$forum = null;
			$topic = $doc;
			$website = f_util_ArrayUtils::firstElement($topic->getDocumentService()->getAncestorsOf($topic, 'modules_website/website'));
		}
		else if ($doc instanceof website_persistentdocument_website)
		{
			$thread = null;
			$forum = null;
			$topic = null;
			$website = $doc;
		}
		
		// Handle forum exclusion.
		if ($forum instanceof forums_persistentdocument_forumgroup && $forum->isExcludedFromRss())
		{
			return website_BlockView::NONE;
		}
		
		// Add RSS feeds.
		$this->addRssFeed($thread, 'false', array('post'));
		$this->addRssFeed($forum, 'false');
		$this->addRssFeed($topic, 'true');
		$this->addRssFeed($website, 'true');
		
		$request->setAttribute('links', $this->links);
		
		return website_BlockView::SUCCESS;
	}
	
	/**
	 * @var String[]
	 */
	private $links = array();
	
	/**
	 * @param f_persistentdocument_PersistentDocument $parent
	 * @param Boolean $recursive
	 * @param String[] $forTypes
	 */
	private function addRssFeed($parent, $recursive, $forTypes = array('post', 'thread'))
	{
		if ($parent !== null)
		{
			$modelName = f_Locale::translate($parent->getPersistentModel()->getDocumentName());
			foreach ($forTypes as $type)
			{
				$title = f_Locale::translate('&modules.forums.frontoffice.' . ucfirst($type) . 's-of-' . $modelName . 'Label;') . ' ' . $parent->getLabelAsHtml();
				$this->getContext()->addRssFeed($title, LinkHelper::getActionUrl('forums', 'ViewFeed', array('parentref' => $parent->getId(), 'docType' => $type, 'recursive' => $recursive)));
{'fraction_non_alphanumeric': 0.1683624496064504, 'fraction_numerical': 0.0, 'mean_word_length': 4.246727089627392, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4110368', 'n_tokens_mistral': 2009, 'n_tokens_neox': 1692, 'n_words': 328}