<commit_before><?php
namespace Concrete\Block\ShareThisPage;

use Concrete\Core\Block\BlockController;
use Concrete\Core\Feature\Features;
use Concrete\Core\Feature\UsesFeatureInterface;
use Concrete\Core\Sharing\ShareThisPage\ServiceList;
use Concrete\Core\Sharing\ShareThisPage\Service;
use Database;
use Core;

defined('C5_EXECUTE') or die("Access Denied.");

class Controller extends BlockController implements UsesFeatureInterface
{
    public $helpers = array('form');

    protected $btInterfaceWidth = 400;
    protected $btCacheBlockOutput = true;
    protected $btCacheBlockOutputOnPost = true;
    protected $btCacheBlockOutputForRegisteredUsers = true;
    protected $btInterfaceHeight = 400;
    protected $btTable = 'btShareThisPage';

    protected $services = array();

    public function getBlockTypeDescription()
    {
        return t("Allows users to share this page with social networks.");
    }

    public function getBlockTypeName()
    {
        return t("Share This Page");
    }

    public function getRequiredFeatures(): array
    {
        return [
            Features::SOCIAL
        ];
    }

    public function edit()
    {
        $this->set('selectedServices', $this->getSelectedServices());
        $this->set('availableServices', ServiceList::get());
    }

    public function add()
    {
        $this->edit();
    }

    public function addService($service)
    {
        $ss = Service::getByHandle($service);
        if (is_object($ss)) {
            $this->services[] = $ss;
        }
    }

    protected function getSelectedServices()
    {
        $this->services = array();
        $db = Database::get();
        $services = $db->GetCol('select service from btShareThisPage where bID = ? order by displayOrder asc',
            array($this->bID)
        );
        foreach ($services as $service) {
            $this->addService($service);
        }

        return $this->services;
    }

    public function duplicate($newBlockID)
    {
        $db = Database::get();
        foreach ($this->getSelectedServices() as $service) {
            $db->insert('btShareThisPage', array('bID' => $newBlockID, 'service' => $service->getHandle(), 'displayOrder' => $this->displayOrder));
        }
    }

    public function validate($args)
    {
        $e = Core::make('helper/validation/error');
        if (!isset($args['service']) || empty($args['service'])) {
            $e->add(t('You must choose at least one service.'));
        }

        return $e;
    }

    public function export(\SimpleXMLElement $blockNode)
    {
        $data = $blockNode->addChild('data');<commit_msg>share this page misc. fix<commit_after><?php
namespace Concrete\Block\ShareThisPage;

use Concrete\Core\Block\BlockController;
use Concrete\Core\Feature\Features;
use Concrete\Core\Feature\UsesFeatureInterface;
use Concrete\Core\Sharing\ShareThisPage\ServiceList;
use Concrete\Core\Sharing\ShareThisPage\Service;
use Database;
use Core;

defined('C5_EXECUTE') or die("Access Denied.");

class Controller extends BlockController implements UsesFeatureInterface
{
    public $helpers = array('form');

    protected $btInterfaceWidth = 400;
    protected $btCacheBlockOutput = true;
    protected $btCacheBlockOutputOnPost = true;
    protected $btCacheBlockOutputForRegisteredUsers = true;
    protected $btInterfaceHeight = 400;
    protected $btTable = 'btShareThisPage';

    protected $services = array();

    public function getBlockTypeDescription()
    {
        return t("Allows users to share this page with social networks.");
    }

    public function getBlockTypeName()
    {
        return t("Share This Page");
    }

    public function getRequiredFeatures(): array
    {
        return [
            Features::SOCIAL
        ];
    }

    public function edit()
    {
        $this->set('selectedServices', $this->getSelectedServices());
        $this->set('availableServices', ServiceList::get());
    }

    public function add()
    {
        $this->edit();
    }

    public function addService($service)
    {
        $ss = Service::getByHandle($service);
        if (is_object($ss)) {
            $this->services[] = $ss;
        }
    }

    protected function getSelectedServices()
    {
        $this->services = array();
        $db = Database::get();
        $services = $db->GetCol('select service from btShareThisPage where bID = ? order by displayOrder asc',
            array($this->bID)
        );
        foreach ($services as $service) {
            $this->addService($service);
        }

        return $this->services;
    }

    public function duplicate($newBlockID)
    {
        $db = Database::get();
        $displayOrder = 0;
        foreach ($this->getSelectedServices() as $service) {
            $db->insert('btShareThisPage', array('bID' => $newBlockID, 'service' => $service->getHandle(), 'displayOrder' => $displayOrder));
            $displayOrder++;
        }
    }

    public function validate($args)
    {
        $e = Core::make('helper/validation/error');
        if (!isset($args['service']) || empty($args['service'])) {
            $e->add(t('You must choose at least one service.'));
        }

        return $e;
    }

    public function export(\SimpleXMLElement $blockNode)
    {
        $data = $blockNode->addChild('data');
{'fraction_non_alphanumeric': 0.13157894736842105, 'fraction_numerical': 0.002819548872180451, 'mean_word_length': 2.7657466383581033, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 40, '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': '6605209', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1451, 'n_words': 330}