<commit_before><?php
if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

/**
 * ResourceRegistry3
 *
 * @package     RR3
 * @author      Middleware Team HEAnet
 * @copyright   Copyright (c) 2014, HEAnet Limited (http://www.heanet.ie)
 * @license     MIT http://www.opensource.org/licenses/mit-license.php
 *
 */

/**
 * Dashboard Class
 *
 * @package     RR3
 * @author      <NAME> <<EMAIL>>
 */
class Subscriber extends MY_Controller
{

    public function __construct() {
        parent::__construct();
    }

    private function getSubscriptionsToJson(models\User $subscriptionOwner) {
        /**
         * @var $userSubscriptions models\NotificationList[]
         */
        $userSubscriptions = $subscriptionOwner->getSubscriptions();
        $result = array();

        foreach ($userSubscriptions as $subscription) {
            $provider = $subscription->getProvider();
            $providerId = null;
            $providerEntityId = null;
            if (!empty($provider)) {
                $providerId = $provider->getId();
                $providerEntityId = $provider->getEntityId();
            }
            $federationId = null;
            $federationName = null;
            $federation = $subscription->getFederation();
            if (!empty($federation)) {
                $federationId = $federation->getId();
                $federationName = $federation->getName();
            }
            $isApproved = $subscription->getApproved();
            $isEnabled = $subscription->getEnabled();
            if ($isEnabled && $isApproved) {
                $status = lang('subscisactive');
            } else {
                $status = '';
                if (!$isEnabled) {
                    $status .= lang('subscdisabled') . '; ';
                }
                if (!$isApproved) {
                    $status .= lang('subscnotapproved');
                }
            }
            $result[] = array(
                'id' => $subscription->getId(),
                'delivery' => $subscription->getNotificationType(),
                'type' => $subscription->getType(),
                'langtype' => lang($subscription->getType()),
                'providerid' => $providerId,
                'providername' => $providerEntityId,
                'federationid' => $federationId,
                'federationname' => $federationName,
                'rcptto' => $subscription->getRcpt(),
                'email' => '' . $subscription->getAltEmail() . '',
                'enabled' => '' . $subscription->getEnabled() . '',
                'approved' => '' . $subscription->getApproved() . '',
                'updated' => '' . date('Y-m-d H:i:s', $subscription->getUpdatedAt()->format('U') + jauth::$timeOffset) . '',
                'langstatus' => $status,
                'langprovider' => lang('rr_provider'),
                'langfederation' => lang('rr_federation'),
                'langany' => lang('rr_any')
            );
        }
        return json_encode($result);
    }

    /**
     * @param $username
     * @return \models\User
     * @throws Exception
     */
    private function getSubscriberOwner($username){
        $loggeduser = $this->jauth->getLoggedinUsername();
        $isAdmin = $this->jauth->isAdministrator();
        if ($isAdmin !== true && strcasecmp($username, $loggeduser) != 0) {
            log_message('warning', __METHOD__ . ': User ' . $loggeduser . ' tried to get access to other users subsricriptions:' . $username);
            throw new Exception('permission denied');
        }

        /**
         * @var $subscribtionOwner models\User
         */
        $subscribtionOwner = $this->em->getRepository("models\User")->findOneBy(array('username' => $username));
        if ($subscribtionOwner === null) {
            throw new Exception('not found');
        }
        return $subscribtionOwner;
    }

    public function mysubscriptions($encodeduser = null) {
        if ($encodeduser === null) {
            show_error('not found', 404);
        }
        if (!$this->jauth->isLoggedIn()) {
            redirect('auth/login', 'location');
        }
        $this->load->library('zacl');
        $decodeduser = base64url_decode($encodeduser);

        try {
            $subscribtionOwner = $this->getSubscriberOwner($decodeduser);
        }
        catch(Exception $e){
            show_error(403, $e->getMessage());
        }

        $data = array(
            'encodeduser' => $encodeduser,
            'subscriber' => array(
                'username' => $subscribtionOwner->getUsername(),
                'fullname' => $subscribtionOwner->getFullname(),
                'email' => $subscribtionOwner->getEmail(),
            ),
            'titlepage' => $subscribtionOwner->getUsername(),
            'subtitlepage' => lang('title_usersubscriptions')
        );


        $accessListUsers = $this->zacl->check_acl('', 'read', 'user', '');
        if (!$accessListUsers) {
            $data['breadcrumbs'] = array(
                array('url' => base_url('manage/users/showlist'), 'name' => lang('rr_userslist'), 'type' => 'unavailable'),
                array('url' => base_url('manage/users/show/' . $encodeduser . ''), 'name' => html_escape($subscribtionOwner->getUsername())),
                array('url' => base_url('#'), 'name' => lang('title_usersubscriptions'), 'type' => 'current')
            );
        } else {
            $data['breadcrumbs'] = array(
                array('url' => base_url('manage/users/showlist'), 'name' => lang('rr_userslist')),
                array('url' => base_url('manage/users/show/' . $encodeduser . ''), 'name' => html_escape($subscribtionOwner->getUsername()),),<commit_msg>cleaning<commit_after><?php
if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

/**
 * ResourceRegistry3
 *
 * @package     RR3
 * @author      Middleware Team HEAnet
 * @copyright   Copyright (c) 2014, HEAnet Limited (http://www.heanet.ie)
 * @license     MIT http://www.opensource.org/licenses/mit-license.php
 *
 */

/**
 * Dashboard Class
 *
 * @package     RR3
 * @author      <NAME> <<EMAIL>>
 */
class Subscriber extends MY_Controller
{

    public function __construct() {
        parent::__construct();
    }

    private function getSubscriptionsToJson(models\User $subscriptionOwner) {
        /**
         * @var $userSubscriptions models\NotificationList[]
         */
        $userSubscriptions = $subscriptionOwner->getSubscriptions();
        $result = array();

        foreach ($userSubscriptions as $subscription) {
            $provider = $subscription->getProvider();
            $providerId = null;
            $providerEntityId = null;
            if (!empty($provider)) {
                $providerId = $provider->getId();
                $providerEntityId = $provider->getEntityId();
            }
            $federationId = null;
            $federationName = null;
            $federation = $subscription->getFederation();
            if (!empty($federation)) {
                $federationId = $federation->getId();
                $federationName = $federation->getName();
            }
            $isApproved = $subscription->getApproved();
            $isEnabled = $subscription->getEnabled();
            if ($isEnabled && $isApproved) {
                $status = lang('subscisactive');
            } else {
                $status = '';
                if (!$isEnabled) {
                    $status .= lang('subscdisabled') . '; ';
                }
                if (!$isApproved) {
                    $status .= lang('subscnotapproved');
                }
            }
            $result[] = array(
                'id' => $subscription->getId(),
                'delivery' => $subscription->getNotificationType(),
                'type' => $subscription->getType(),
                'langtype' => lang($subscription->getType()),
                'providerid' => $providerId,
                'providername' => $providerEntityId,
                'federationid' => $federationId,
                'federationname' => $federationName,
                'rcptto' => $subscription->getRcpt(),
                'email' => '' . $subscription->getAltEmail() . '',
                'enabled' => '' . $subscription->getEnabled() . '',
                'approved' => '' . $subscription->getApproved() . '',
                'updated' => '' . date('Y-m-d H:i:s', $subscription->getUpdatedAt()->format('U') + jauth::$timeOffset) . '',
                'langstatus' => $status,
                'langprovider' => lang('rr_provider'),
                'langfederation' => lang('rr_federation'),
                'langany' => lang('rr_any')
            );
        }
        return json_encode($result);
    }

    /**
     * @param $username
     * @return \models\User
     * @throws Exception
     */
    private function getSubscriberOwner($encodedusername = null){
        if($encodedusername === null){
            throw new Exception('missing username');
        }
        $username = base64url_decode($encodedusername);
        $loggeduser = $this->jauth->getLoggedinUsername();
        $isAdmin = $this->jauth->isAdministrator();
        if ($isAdmin !== true && strcasecmp($username, $loggeduser) != 0) {
            log_message('warning', __METHOD__ . ': User ' . $loggeduser . ' tried to get access to other users subsricriptions:' . $username);
            throw new Exception('permission denied');
        }

        /**
         * @var $subscribtionOwner models\User
         */
        $subscribtionOwner = $this->em->getRepository("models\User")->findOneBy(array('username' => $username));
        if ($subscribtionOwner === null) {
            throw new Exception('not found');
        }
        return $subscribtionOwner;
    }

    public function mysubscriptions($encodeduser = null) {
        if (!$this->jauth->isLoggedIn()) {
            redirect('auth/login', 'location');
        }
        $this->load->library('zacl');
        try {
            $subscribtionOwner = $this->getSubscriberOwner($encodeduser);
        }
        catch(Exception $e){
            show_error(403, $e->getMessage());
        }
        $data = array(
            'encodeduser' => $encodeduser,
            'subscriber' => array(
                'username' => $subscribtionOwner->getUsername(),
                'fullname' => $subscribtionOwner->getFullname(),
                'email' => $subscribtionOwner->getEmail(),
            ),
            'titlepage' => $subscribtionOwner->getUsername(),
            'subtitlepage' => lang('title_usersubscriptions')
        );


        $accessListUsers = $this->zacl->check_acl('', 'read', 'user', '');
        $data['breadcrumbs'] = array(
            array('url' => base_url('manage/users/showlist'), 'name' => lang('rr_userslist')),
            array('url' => base_url('manage/users/show/' . $encodeduser . ''), 'name' => html_escape($subscribtionOwner->getUsername()),),
            array('url' => base_url('#'), 'name' => lang('title_usersubscriptions'), 'type' => 'current')
        );
        if (!$accessListUsers) {
            $data['breadcrumbs'] = array(
                array('url' => base_url('manage/users/showlist'), 'name' => lang('rr_userslist'), 'type' => 'unavailable'),
                array('url' => base_url('manage/users/show/' . $encodeduser . ''), 'name' => html_escape($subscribtionOwner->getUsername())),
{'fraction_non_alphanumeric': 0.1613918517223291, 'fraction_numerical': 0.002535408288162266, 'mean_word_length': 2.0142292490118576, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 163, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '5995421', 'n_tokens_mistral': 3204, 'n_tokens_neox': 3081, 'n_words': 533}