<commit_before><?php
class IPBBridge extends FeedExpander {

	const NAME = 'IPB Bridge';
	const URI = 'https://www.invisionpower.com';
	const DESCRIPTION = 'Returns feeds for forums powered by IPB';
	const MAINTAINER = 'logmanoriginal';
	const PARAMETERS = array(
		array(
			'uri' => array(
				'name' => 'URI',
				'type' => 'text',
				'required' => true,
				'title' => 'Insert forum, subforum or topic URI',
				'exampleValue' => 'https://invisioncommunity.com/forums/forum/499-feedback-and-ideas/'
			),
			'limit' => array(
				'name' => 'Limit',
				'type' => 'number',
				'required' => false,
				'title' => 'Specifies the number of items to return on each request (-1: all)',
				'defaultValue' => 10
			)
		)
	);
	const CACHE_TIMEOUT = 3600;

	// Constants for internal use
	const FORUM_TYPE_LIST_FILTER = '.cForumTopicTable';
	const FORUM_TYPE_TABLE_FILTER = '#forum_table';

	const TOPIC_TYPE_ARTICLE = 'article';
	const TOPIC_TYPE_DIV = 'div.post_block';

	public function getURI(){
		return $this->getInput('uri') ?: parent::getURI();
	}

	public function collectData(){
		// The URI cannot be the mainpage (or anything related)
		switch(parse_url($this->getInput('uri'), PHP_URL_PATH)) {
			case null:
			case '/index.php':
				returnClientError('Provided URI is invalid!');
				break;
			default:
				break;
		}

		// Sanitize the URI (because else it won't work)
		$uri = rtrim($this->getInput('uri'), '/'); // No trailing slashes!

		// Forums might provide feeds, though that's optional *facepalm*
		// Let's check if there is a valid feed available
		$headers = get_headers($uri . '.xml');

		if($headers[0] === 'HTTP/1.1 200 OK') { // Heureka! It's a valid feed!
			return $this->collectExpandableDatas($uri);
		}

		// No valid feed, so do it the hard way
		$html = getSimpleHTMLDOM($uri);

		$limit = $this->getInput('limit');

		// Determine if this is a topic or a forum
		switch(true) {
			case $this->isTopic($html):
				$this->collectTopic($html, $limit);
				break;
			case $this->isForum($html);
				$this->collectForum($html);
				break;
			default:
				returnClientError('Unknown type!');
				break;
		}
	}

	private function isForum($html){
		return !is_null($html->find('div[data-controller*=forums.front.forum.forumPage]', 0))<commit_msg>[IPBBridge] fix: bug in feed detection logic<commit_after><?php
class IPBBridge extends FeedExpander {

	const NAME = 'IPB Bridge';
	const URI = 'https://www.invisionpower.com';
	const DESCRIPTION = 'Returns feeds for forums powered by IPB';
	const MAINTAINER = 'logmanoriginal';
	const PARAMETERS = array(
		array(
			'uri' => array(
				'name' => 'URI',
				'type' => 'text',
				'required' => true,
				'title' => 'Insert forum, subforum or topic URI',
				'exampleValue' => 'https://invisioncommunity.com/forums/forum/499-feedback-and-ideas/'
			),
			'limit' => array(
				'name' => 'Limit',
				'type' => 'number',
				'required' => false,
				'title' => 'Specifies the number of items to return on each request (-1: all)',
				'defaultValue' => 10
			)
		)
	);
	const CACHE_TIMEOUT = 3600;

	// Constants for internal use
	const FORUM_TYPE_LIST_FILTER = '.cForumTopicTable';
	const FORUM_TYPE_TABLE_FILTER = '#forum_table';

	const TOPIC_TYPE_ARTICLE = 'article';
	const TOPIC_TYPE_DIV = 'div.post_block';

	public function getURI(){
		return $this->getInput('uri') ?: parent::getURI();
	}

	public function collectData(){
		// The URI cannot be the mainpage (or anything related)
		switch(parse_url($this->getInput('uri'), PHP_URL_PATH)) {
			case null:
			case '/index.php':
				returnClientError('Provided URI is invalid!');
				break;
			default:
				break;
		}

		// Sanitize the URI (because else it won't work)
		$uri = rtrim($this->getInput('uri'), '/'); // No trailing slashes!

		// Forums might provide feeds, though that's optional *facepalm*
		// Let's check if there is a valid feed available
		$headers = get_headers($uri . '.xml');

		if($headers[0] === 'HTTP/1.1 200 OK') { // Heureka! It's a valid feed!
			return $this->collectExpandableDatas($uri . '.xml');
		}

		// No valid feed, so do it the hard way
		$html = getSimpleHTMLDOM($uri);

		$limit = $this->getInput('limit');

		// Determine if this is a topic or a forum
		switch(true) {
			case $this->isTopic($html):
				$this->collectTopic($html, $limit);
				break;
			case $this->isForum($html);
				$this->collectForum($html);
				break;
			default:
				returnClientError('Unknown type!');
				break;
		}
	}

	private function isForum($html){
		return !is_null($html->find('div[data-controller*=forums.front.forum.forumPage]', 0))
{'fraction_non_alphanumeric': 0.1579520697167756, 'fraction_numerical': 0.007407407407407408, 'mean_word_length': 3.64206268958544, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 3}, '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': '1836936', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1525, 'n_words': 416}