<commit_before><?php

require_once 'CRM/Core/Page.php';

class CRM_Speakcivi_Page_Speakcivi extends CRM_Core_Page {

  public $optIn = 0;

  public $groupId = 0;

  public $defaultCampaignTypeId = 0;

  public $locale = '';

  public $countryLangMapping = array();

  public $country = '';

  public $countryId = 0;

  public $postalCode = '';

  public $campaignObj;

  public $campaign = array();

  public $campaignId = 0;

  public $customFields = array();

  public $newContact = false;

  public $addJoinActivity = false;

  public $genderMaleValue = 0;

  public $genderFemaleValue = 0;

  public $genderUnspecifiedValue = 0;

  /** @var bool Determine whether confirmation block with links have to be included in content of confirmation email. */
  public $confirmationBlock = true;

  private $apiAddressGet = 'api.Address.get';

  private $apiAddressCreate = 'api.Address.create';

  private $apiGroupContactGet = 'api.GroupContact.get';

  private $apiGroupContactCreate = 'api.GroupContact.create';

  function run() {

    $param = json_decode(file_get_contents('php://input'));
    CRM_Speakcivi_Tools_Hooks::setParams($param);

    if (!$param) {
      die ("missing POST PARAM");
    }

    $this->setDefaults();
    $this->setCountry($param);

    $notSendConfirmationToThoseCountries = array(
      'FR',
      'GB',
      'IT',
      'UK',
    );
    if (in_array($this->country, $notSendConfirmationToThoseCountries)) {
      $this->optIn = 0;
    }

    $this->campaignObj = new CRM_Speakcivi_Logic_Campaign();
    $this->campaign = $this->campaignObj->getCampaign($param->external_id);
    $this->campaign = $this->campaignObj->setCampaign($param->external_id, $this->campaign, $param);
    if ($this->campaignObj->isValidCampaign($this->campaign)) {
      $this->campaignId = $this->campaign['id'];
      $this->campaignObj->customFields = $this->campaignObj->getCustomFields($this->campaignId);
      $this->locale = $this->campaignObj->getLanguage();
    } else {
      header('HTTP/1.1 503 Men at work');
      return;
    }

    switch ($param->action_type) {
      case 'petition':
        $this->petition($param);
        break;

      case 'share':
        $this->addActivity($param, 'share');
        break;

      case 'tweet':
        $this->addActivity($param, 'Tweet');
        break;

      case 'speakout':
        $this->addActivity($param, 'Email');
        break;

      case 'donate':
        $this->donate($param);
        break;

      default:
    }

  }


  /**
   *  Setting up default values for parameters.
   */
  function setDefaults() {
    $this->optIn = CRM_Core_BAO_Setting::getItem('Speakcivi API Preferences', 'opt_in');
    $this->groupId = CRM_Core_BAO_Setting::getItem('Speakcivi API Preferences', 'group_id');
    $this->defaultCampaignTypeId = CRM_Core_OptionGroup::getValue('campaign_type', 'Petitions', 'name', 'String', 'value');<commit_msg>Add middle step method for handling params<commit_after><?php

require_once 'CRM/Core/Page.php';

class CRM_Speakcivi_Page_Speakcivi extends CRM_Core_Page {

  public $optIn = 0;

  public $groupId = 0;

  public $defaultCampaignTypeId = 0;

  public $locale = '';

  public $countryLangMapping = array();

  public $country = '';

  public $countryId = 0;

  public $postalCode = '';

  public $campaignObj;

  public $campaign = array();

  public $campaignId = 0;

  public $customFields = array();

  public $newContact = false;

  public $addJoinActivity = false;

  public $genderMaleValue = 0;

  public $genderFemaleValue = 0;

  public $genderUnspecifiedValue = 0;

  /** @var bool Determine whether confirmation block with links have to be included in content of confirmation email. */
  public $confirmationBlock = true;

  private $apiAddressGet = 'api.Address.get';

  private $apiAddressCreate = 'api.Address.create';

  private $apiGroupContactGet = 'api.GroupContact.get';

  private $apiGroupContactCreate = 'api.GroupContact.create';

  function run() {
    $param = json_decode(file_get_contents('php://input'));
    CRM_Speakcivi_Tools_Hooks::setParams($param);
    if (!$param) {
      die ("missing POST PARAM");
    }
    $this->runParam($param);
  }

  public function runParam($param) {
    CRM_Speakcivi_Tools_Hooks::setParams($param);
    $this->setDefaults();
    $this->setCountry($param);

    $notSendConfirmationToThoseCountries = array(
      'FR',
      'GB',
      'IT',
      'UK',
    );
    if (in_array($this->country, $notSendConfirmationToThoseCountries)) {
      $this->optIn = 0;
    }

    $this->campaignObj = new CRM_Speakcivi_Logic_Campaign();
    $this->campaign = $this->campaignObj->getCampaign($param->external_id);
    $this->campaign = $this->campaignObj->setCampaign($param->external_id, $this->campaign, $param);
    if ($this->campaignObj->isValidCampaign($this->campaign)) {
      $this->campaignId = $this->campaign['id'];
      $this->campaignObj->customFields = $this->campaignObj->getCustomFields($this->campaignId);
      $this->locale = $this->campaignObj->getLanguage();
    } else {
      header('HTTP/1.1 503 Men at work');
      return;
    }

    switch ($param->action_type) {
      case 'petition':
        $this->petition($param);
        break;

      case 'share':
        $this->addActivity($param, 'share');
        break;

      case 'tweet':
        $this->addActivity($param, 'Tweet');
        break;

      case 'speakout':
        $this->addActivity($param, 'Email');
        break;

      case 'donate':
        $this->donate($param);
        break;

      default:
    }
  }


  /**
   *  Setting up default values for parameters.
   */
  function setDefaults() {
    $this->optIn = CRM_Core_BAO_Setting::getItem('Speakcivi API Preferences', 'opt_in');
    $this->groupId = CRM_Core_BAO_Setting::getItem('Speakcivi API Preferences', 'group_id');
    $this->defaultCampaignTypeId = CRM_Core_OptionGroup::getValue('campaign_type', 'Petitions', 'name', 'String', 'value');
{'fraction_non_alphanumeric': 0.1480859637340497, 'fraction_numerical': 0.0047011417058428475, 'mean_word_length': 3.419139465875371, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 76, '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': '3495136', 'n_tokens_mistral': 1997, 'n_tokens_neox': 1837, 'n_words': 378}