<commit_before><?php

class CRM_CiviruleTwitter_Action extends CRM_Civiruleshttppost_HttpPostAction {

  protected function alterHttpRequestObject(\Httpful\Request $request, CRM_Civirules_TriggerData_TriggerData $triggerData) {
    $request = parent::alterHttpRequestObject($request, $triggerData);

    $request->contentType('application/x-www-form-urlencoded');

    $params = $this->getActionParameters();
    $twitter_account = new CRM_CiviruleTwitter_BAO_TwitterAccount();
    $twitter_account->id = $params['twitter_account'];
    if (!$twitter_account->find(true)) {
      throw new Exception('Could not find twitter account with id: '.$params['twitter_account']);
    }

    $oauth = new CRM_Civiruleshttppost_Oauth($twitter_account->consumer_key, $twitter_account->consumer_secret, $twitter_account->access_token, $twitter_account->access_secret);
    $request = $oauth->signRequest($request);
    return $request;
  }

  protected function getFullUri(CRM_Civirules_TriggerData_TriggerData $triggerData) {
    return 'https://api.twitter.com/1.1/statuses/update.json';
  }

  protected function getBodyParams(CRM_Civirules_TriggerData_TriggerData $triggerData) {
    $bodyParams = parent::getBodyParams($triggerData);
    $params = $this->getActionParameters();
    $bodyParams['status'] = trim($this->replaceTokens($params['status'], $triggerData->getContactId())).' '.time();
    return $bodyParams;
  }

  protected function getHttpMethod() {
    return 'POST';
  }

  /**
   * Returns a redirect url to extra data input from the user after adding a action
   *
   * Return false if you do not need extra data input
   *
   * @param int $ruleActionId
   * @return bool|string
   * $access public
   */
  public function getExtraDataInputUrl($ruleActionId) {
    return CRM_Utils_System::url('civicrm/civirules/action/form/twitter_action', 'rule_action_id='.$ruleActionId);
  }

  /**
   * Returns a user friendly text explaining the condition params
   * e.g. 'Older than 65'
   *
   * @return string
   * @access public
   */
  public function userFriendlyConditionParams() {
    $params = $this->getActionParameters();
    $account = ts('Unknown');
    $twitter_account = new CRM_CiviruleTwitter_BAO_TwitterAccount();
    $twitter_account->id = $params['twitter_account'];
    if ($twitter_account->find(true)) {
      $account = '@'.$twitter_account->twitter_name.' "'.$twitter_account->description.'"';
    }
    return sprintf('Tweet: "%s" %s', $params['status'], $account);
  }

}<commit_msg>update UI fixes<commit_after><?php

class CRM_CiviruleTwitter_Action extends CRM_Civiruleshttppost_HttpPostAction {

  protected function alterHttpRequestObject(\Httpful\Request $request, CRM_Civirules_TriggerData_TriggerData $triggerData) {
    $request = parent::alterHttpRequestObject($request, $triggerData);

    $request->contentType('application/x-www-form-urlencoded');

    $params = $this->getActionParameters();
    $twitter_account = new CRM_CiviruleTwitter_BAO_TwitterAccount();
    $twitter_account->id = $params['twitter_account'];
    if (!$twitter_account->find(true)) {
      throw new Exception('Could not find twitter account with id: '.$params['twitter_account']);
    }

    $oauth = new CRM_Civiruleshttppost_Oauth($twitter_account->consumer_key, $twitter_account->consumer_secret, $twitter_account->access_token, $twitter_account->access_secret);
    $request = $oauth->signRequest($request);
    return $request;
  }

  protected function getFullUri(CRM_Civirules_TriggerData_TriggerData $triggerData) {
    return 'https://api.twitter.com/1.1/statuses/update.json';
  }

  protected function getBodyParams(CRM_Civirules_TriggerData_TriggerData $triggerData) {
    $bodyParams = parent::getBodyParams($triggerData);
    $params = $this->getActionParameters();
    $bodyParams['status'] = trim($this->replaceTokens($params['status'], $triggerData->getContactId())).' '.time();
    return $bodyParams;
  }

  protected function getHttpMethod() {
    return 'POST';
  }

  /**
   * Returns a redirect url to extra data input from the user after adding a action
   *
   * Return false if you do not need extra data input
   *
   * @param int $ruleActionId
   * @return bool|string
   * $access public
   */
  public function getExtraDataInputUrl($ruleActionId) {
    return CRM_Utils_System::url('civicrm/civirules/action/form/twitter_action', 'rule_action_id='.$ruleActionId);
  }

  /**
   * Returns a user friendly text explaining the condition params
   * e.g. 'Older than 65'
   *
   * @return string
   * @access public
   */
  public function userFriendlyConditionParams() {
    $params = $this->getActionParameters();
    $account = ts('Unknown');
    $twitter_account = new CRM_CiviruleTwitter_BAO_TwitterAccount();
    $twitter_account->id = $params['twitter_account'];
    if ($twitter_account->find(true)) {
      $description = '';
      if ($twitter_account->description) {
        $description = ' "'.$twitter_account->description.'"';
      }
      $account = '@'.$twitter_account->twitter_name.' '.$description;
    }
    return sprintf('Tweet: "%s" %s', $params['status'], $account);
  }

}
{'fraction_non_alphanumeric': 0.13251605370694688, 'fraction_numerical': 0.0015567230978789648, 'mean_word_length': 4.6607929515418505, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 38, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '6862213', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1521, 'n_words': 301}