<commit_before><?php
/**
 * Minds Subscriptions
 *
 * @version 1
 * @author <NAME>
 */
namespace Minds\Controllers\api\v1;

use Minds\Components\Controller;
use Minds\Core;
use Minds\Helpers;
use Minds\Entities;
use Minds\Interfaces;
use Minds\Api\Factory;

class block extends Controller implements Interfaces\Api, Interfaces\ApiIgnorePam
{
    /**
     * Return a list of your blocked users
     */
    public function get($pages)
    {
        $response = array();

        if (!isset($pages[0])) {
            $pages[0] = "list";
        }

        switch ($pages[0]) {
        case "list":
          $limit = isset($_GET['limit']) ? $_GET['limit'] : 12;
          $offset = isset($_GET['offset']) ? $_GET['offset'] : "";

          $block = $this->di->get('Security\ACL\Block');
          $guids = $block->getBlockList(Core\Session::getLoggedinUser(), $limit, $offset);

          if ($guids) {
              $entities = Core\Entities::get(array('guids'=>$guids));
              $response['entities'] = Api\Factory::exportable($entities);
          }
          break;
        case is_numeric($pages[0]):
          $block = $this->di->get('Security\ACL\Block');
          $response['blocked'] = $block->isBlocked($pages[0]);
          break;
      }



        return Factory::response($response);
    }

    /**
     *
     */
    public function post($pages)
    {
        return Factory::response(array());
    }

    /**
     * Block a user
     */
    public function put($pages)
    {
        Factory::isLoggedIn();

        $target = new Entities\User($pages[0]);

        if (!$target || !$target->guid) {
            return Factory::response([
                'status' => 'error',
                'message' => 'Invalid target'
            ]);
        }

        $block = $this->di->get('Security\ACL\Block');
        $blocked = $block->block($pages[0]);

        if ($blocked) {
            // Unsubscribe self
            Core\Session::getLoggedInUser()->unSubscribe($pages[0]);
            Helpers\Wallet::createTransaction(Core\Session::getLoggedinUser()->guid, -1, $pages[0], 'Unsubscribed');

            // Unsubscribe target
            $target->unSubscribe(Core\Session::getLoggedInUserGuid());
            Helpers\Wallet::createTransaction($pages[0], -1, Core\Session::getLoggedInUserGuid(), 'Unsubscribed');
        }

        return Factory::response(array());
    }

    /**
     * UnBlock a user
     */
    public function delete($pages)
    {
        Factory::isLoggedIn();

        $block = $this->di->get('Security\ACL\Block');
        $block->unBlock($pages[0]);

        return Factory::response(array());<commit_msg>(fix): check subscription status when blocking (#52)<commit_after><?php
/**
 * Minds Subscriptions
 *
 * @version 1
 * @author <NAME>
 */
namespace Minds\Controllers\api\v1;

use Minds\Components\Controller;
use Minds\Core;
use Minds\Helpers;
use Minds\Entities;
use Minds\Interfaces;
use Minds\Api\Factory;

class block extends Controller implements Interfaces\Api, Interfaces\ApiIgnorePam
{
    /**
     * Return a list of your blocked users
     */
    public function get($pages)
    {
        $response = array();

        if (!isset($pages[0])) {
            $pages[0] = "list";
        }

        switch ($pages[0]) {
        case "list":
          $limit = isset($_GET['limit']) ? $_GET['limit'] : 12;
          $offset = isset($_GET['offset']) ? $_GET['offset'] : "";

          $block = $this->di->get('Security\ACL\Block');
          $guids = $block->getBlockList(Core\Session::getLoggedinUser(), $limit, $offset);

          if ($guids) {
              $entities = Core\Entities::get(array('guids'=>$guids));
              $response['entities'] = Api\Factory::exportable($entities);
          }
          break;
        case is_numeric($pages[0]):
          $block = $this->di->get('Security\ACL\Block');
          $response['blocked'] = $block->isBlocked($pages[0]);
          break;
      }



        return Factory::response($response);
    }

    /**
     *
     */
    public function post($pages)
    {
        return Factory::response(array());
    }

    /**
     * Block a user
     */
    public function put($pages)
    {
        Factory::isLoggedIn();

        $target = new Entities\User($pages[0]);

        if (!$target || !$target->guid) {
            return Factory::response([
                'status' => 'error',
                'message' => 'Invalid target'
            ]);
        }

        $block = $this->di->get('Security\ACL\Block');
        $blocked = $block->block($target->guid);

        if ($blocked) {
            // Unsubscribe self
            if (Core\Session::getLoggedInUser()->isSubscribed($target->guid)) {
                Core\Session::getLoggedInUser()->unSubscribe($target->guid);
                Helpers\Wallet::createTransaction(Core\Session::getLoggedinUser()->guid, -1, $pages[0], 'Unsubscribed');
            }

            // Unsubscribe target
            if ($target->isSubscribed(Core\Session::getLoggedInUser()->guid)) {
                $target->unSubscribe(Core\Session::getLoggedInUserGuid());
                Helpers\Wallet::createTransaction($pages[0], -1, Core\Session::getLoggedInUserGuid(), 'Unsubscribed');
            }
        }

        return Factory::response(array());
    }

    /**
     * UnBlock a user
     */
    public function delete($pages)
    {
        Factory::isLoggedIn();

        $block = $this->di->get('Security\ACL\Block');
        $block->unBlock($pages[0]);

        return Factory::response(array());
{'fraction_non_alphanumeric': 0.17012074247612183, 'fraction_numerical': 0.0061272301315552355, 'mean_word_length': 2.1914893617021276, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 49, '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': '1525694', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1628, 'n_words': 281}