<commit_before><?php
namespace wcf\system\box;
use wcf\data\paid\subscription\user\PaidSubscriptionUserList;
use wcf\system\cache\builder\PaidSubscriptionCacheBuilder;
use wcf\system\request\LinkHandler;
use wcf\system\WCF;

/**
 * Box for paid subscriptions.
 *
 * @author	<NAME>
 * @copyright	2001-2017 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\Box
 * @since	3.0
 */
class PaidSubscriptionsBoxController extends AbstractBoxController {
	/**
	 * @inheritDoc
	 */
	protected static $supportedPositions = ['contentTop', 'contentBottom', 'sidebarLeft', 'sidebarRight'];
	
	/**
	 * @inheritDoc
	 */
	public function getLink() {
		return LinkHandler::getInstance()->getLink('PaidSubscriptionList');
	}
	
	/**
	 * @inheritDoc
	 */
	public function hasLink() {
		return true;
	}
	
	/**
	 * @inheritDoc
	 */
	protected function loadContent() {
		if (WCF::getUser()->userID && MODULE_PAID_SUBSCRIPTION) {
			// get available subscriptions
			$subscriptions = PaidSubscriptionCacheBuilder::getInstance()->getData();
			
			// get purchased subscriptions
			$userSubscriptionList = new PaidSubscriptionUserList();
			$userSubscriptionList->getConditionBuilder()->add('userID = ?', [WCF::getUser()->userID]);
			$userSubscriptionList->getConditionBuilder()->add('isActive = ?', [1]);
			$userSubscriptionList->readObjects();
			
			// remove purchased subscriptions
			foreach ($userSubscriptionList as $userSubscription) {
				if (isset($subscriptions[$userSubscription->subscriptionID])) {
					$userSubscription->setSubscription($subscriptions[$userSubscription->subscriptionID]);
					unset($subscriptions[$userSubscription->subscriptionID]);
				}
			}
			// remove excluded subscriptions
			foreach ($userSubscriptionList as $userSubscription) {
				if ($userSubscription->getSubscription()->excludedSubscriptionIDs) {
					foreach (explode(',', $userSubscription->getSubscription()->excludedSubscriptionIDs) as $subscriptionID) {
						if (isset($subscriptions[$subscriptionID])) unset($subscriptions[$subscriptionID]);
					}
				}
			}
			
			if (!empty($subscriptions)) {
				if ($this->getBox()->position == 'contentTop' || $this->getBox()->position == 'contentBottom') {
					$templateName = 'boxPaidSubscriptions';
				}
				else {
					$templateName = 'boxPaidSubscriptionsSidebar';
				}
				
				$this->content = WCF::getTPL()->fetch($templateName, 'wcf', ['subscriptions' => $subscriptions], true);
			}
		}
	}
}
<commit_msg>Hide paid subscription boxes for non-activated users<commit_after><?php
namespace wcf\system\box;
use wcf\data\paid\subscription\user\PaidSubscriptionUserList;
use wcf\system\cache\builder\PaidSubscriptionCacheBuilder;
use wcf\system\request\LinkHandler;
use wcf\system\WCF;

/**
 * Box for paid subscriptions.
 *
 * @author	<NAME>
 * @copyright	2001-2017 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\Box
 * @since	3.0
 */
class PaidSubscriptionsBoxController extends AbstractBoxController {
	/**
	 * @inheritDoc
	 */
	protected static $supportedPositions = ['contentTop', 'contentBottom', 'sidebarLeft', 'sidebarRight'];
	
	/**
	 * @inheritDoc
	 */
	public function getLink() {
		return LinkHandler::getInstance()->getLink('PaidSubscriptionList');
	}
	
	/**
	 * @inheritDoc
	 */
	public function hasLink() {
		return true;
	}
	
	/**
	 * @inheritDoc
	 */
	protected function loadContent() {
		if (WCF::getUser()->userID && WCF::getUser()->activationCode == 0 && MODULE_PAID_SUBSCRIPTION) {
			// get available subscriptions
			$subscriptions = PaidSubscriptionCacheBuilder::getInstance()->getData();
			
			// get purchased subscriptions
			$userSubscriptionList = new PaidSubscriptionUserList();
			$userSubscriptionList->getConditionBuilder()->add('userID = ?', [WCF::getUser()->userID]);
			$userSubscriptionList->getConditionBuilder()->add('isActive = ?', [1]);
			$userSubscriptionList->readObjects();
			
			// remove purchased subscriptions
			foreach ($userSubscriptionList as $userSubscription) {
				if (isset($subscriptions[$userSubscription->subscriptionID])) {
					$userSubscription->setSubscription($subscriptions[$userSubscription->subscriptionID]);
					unset($subscriptions[$userSubscription->subscriptionID]);
				}
			}
			// remove excluded subscriptions
			foreach ($userSubscriptionList as $userSubscription) {
				if ($userSubscription->getSubscription()->excludedSubscriptionIDs) {
					foreach (explode(',', $userSubscription->getSubscription()->excludedSubscriptionIDs) as $subscriptionID) {
						if (isset($subscriptions[$subscriptionID])) unset($subscriptions[$subscriptionID]);
					}
				}
			}
			
			if (!empty($subscriptions)) {
				if ($this->getBox()->position == 'contentTop' || $this->getBox()->position == 'contentBottom') {
					$templateName = 'boxPaidSubscriptions';
				}
				else {
					$templateName = 'boxPaidSubscriptionsSidebar';
				}
				
				$this->content = WCF::getTPL()->fetch($templateName, 'wcf', ['subscriptions' => $subscriptions], true);
			}
		}
	}
}

{'fraction_non_alphanumeric': 0.1482128982128982, 'fraction_numerical': 0.004467754467754468, 'mean_word_length': 4.702104097452935, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 56, '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': '379002', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1507, 'n_words': 258}