<commit_before><?php

  class calendar {

    //Public API access
    public $authUrl;

    //OAuth 2.0 Service

    private $key = '<KEY>';

    private $client_id_service = '324105369659-0af7mss9isb5vdgnpvi3f0h60jhv0nru.apps.googleusercontent.com';

    private $service_account_name_service = '324105369659-0af7mss9isb5vdgnpvi3f0h60jhv0nru<EMAIL>';

    private $key_file_location = '/rsrcs/Intervenants_Agenda-6289a260f638.p12';

    //OAuth 2.0 Application

    private $key_file_content;

    private $client_id_application = '324105369659-7uud1ll9q08nfeitu7d1qjstes1n2n8r.apps.googleusercontent.com';

    private $service_account_name_application = '324105369659-<EMAIL>';

    private $client_secret = '<KEY>';

    private $redirect_uri = 'http://crm.klambard.si.ivsdev.net/?/Crm/Client/oauth2callback//';

    private $token_data;

    private $client;

    private $service;

    private $authentification_type;

    /**
     * Constructor
     *
     * @param string $authentification_type (default: oauth2.0_service [oauth2.0_application, public_server])
     */
    function __construct($authentification_type = 'oauth2.0_service') {
      require_once 'Google/Client.php';
      require_once 'Google/Service/Calendar.php';

      $this->authentification_type = $authentification_type;

      $this->client = new Google_Client();
      $this->client->setApplicationName("Intervenant_Calendar");
      $this->service = new Google_Service_Calendar($this->client);

      if($this->authentification_type == 'oauth2.0_service' && (!strlen($this->client_id_service) || !strlen($this->service_account_name_service) || !strlen($this->key_file_location))) return missingServiceAccountDetailsWarning();
      if($this->authentification_type == 'oauth2.0_application' && (!strlen($this->client_id_application) || !strlen($this->service_account_name_application) || !strlen($this->redirect_uri))) return missingServiceAccountDetailsWarning();

      if($this->authentification_type == 'public_server') $this->client->setDeveloperKey($this->key);

      if($this->authentification_type == 'oauth2.0_service') {
        if(isset($_SESSION['service_google_token'])) {
          $this->client->setAccessToken($_SESSION['service_google_token']);
        }

        $this->key_file_content = file_get_contents(ROOT_PATH.$this->key_file_location);
        $cred                   = new Google_Auth_AssertionCredentials($this->service_account_name_service, array('https://www.googleapis.com/auth/calendar'), $this->key_file_content);
        $this->client->setAssertionCredentials($cred);

        if($this->client->getAuth()->isAccessTokenExpired()) {
          $this->client->getAuth()->refreshTokenWithAssertion($cred);
        }

        $_SESSION['service_google_token'] = $this->client->getAccessToken();
      }

      if($this->authentification_type == 'oauth2.0_application') {
        $this->client->setClientId($this->client_id_application);
        $this->client->setClientSecret($this->client_secret);
        $this->client->setRedirectUri($this->redirect_uri);
        $this->client->setScopes('https://www.googleapis.com/auth/calendar');
        $this->client->setAccessType('offline');

        if(isset($_SESSION['code_oauth2_google']) && $_SESSION['code_oauth2_google'] != "/Client/oauth2callback//") {
          $this->client->authenticate($_SESSION['code_oauth2_google']);
          $_SESSION['application_google_token'] = $this->client->getAccessToken();
          unset($_SESSION['code_oauth2_google']);
        }

        if(isset($_SESSION['application_google_token']) && $_SESSION['application_google_token']) {<commit_msg>add xml config for google calendar api<commit_after><?php

  class calendar {

    //Public API access
    public $authUrl;
    private $token_data;
    private $client;
    private $service;
    private $authentification_type;

    /**
     * Constructor
     *
     * @param string $authentification_type (default: oauth2.0_service [oauth2.0_application, public_server])
     */
    function __construct($authentification_type = 'oauth2.0_service') {
      require_once 'Google/Client.php';
      require_once 'Google/Service/Calendar.php';

      $this->authentification_type = $authentification_type;

      $this->client = new Google_Client();
      $this->client->setApplicationName("Intervenant_Calendar");
      $this->service = new Google_Service_Calendar($this->client);

      if($this->authentification_type == 'oauth2.0_service' && (!strlen(yks::$get->config->google->calendar->oauth->service['client_id']) || !strlen(yks::$get->config->google->calendar->oauth->service['email_address']) || !strlen(yks::$get->config->google->calendar->oauth->service['key_file']))) return missingServiceAccountDetailsWarning();
      if($this->authentification_type == 'oauth2.0_application' && (!strlen(yks::$get->config->google->calendar->oauth->application['client_id']) || !strlen(yks::$get->config->google->calendar->oauth->application['email_address']) || !strlen(yks::$get->config->google->calendar->oauth->application['redirect_uri']))) return missingServiceAccountDetailsWarning();

      if($this->authentification_type == 'public_server') $this->client->setDeveloperKey(yks::$get->config->google->calendar->public['key']);

      if($this->authentification_type == 'oauth2.0_service') {
        if(isset($_SESSION['service_google_token'])) {
          $this->client->setAccessToken($_SESSION['service_google_token']);
        }
//DebugBreak("1@172.19.21.55");
        $key_file_content = file_get_contents(ROOT_PATH.yks::$get->config->google->calendar->oauth->service['key_file']);
        $cred                   = new Google_Auth_AssertionCredentials(
          yks::$get->config->google->calendar->oauth->service['email_address'],
          array('https://www.googleapis.com/auth/calendar'),
          $key_file_content
        );
        $this->client->setAssertionCredentials($cred);

        if($this->client->getAuth()->isAccessTokenExpired()) {
          $this->client->getAuth()->refreshTokenWithAssertion($cred);
        }

        $_SESSION['service_google_token'] = $this->client->getAccessToken();
      }

      if($this->authentification_type == 'oauth2.0_application') {
        $this->client->setClientId(yks::$get->config->google->calendar->oauth->application['client_id']);
        $this->client->setClientSecret(yks::$get->config->google->calendar->oauth->application['client_secret']);
        $this->client->setRedirectUri(yks::$get->config->google->calendar->oauth->application['redirect_uri']);
        $this->client->setScopes('https://www.googleapis.com/auth/calendar');
        $this->client->setAccessType('offline');

        if(isset($_SESSION['code_oauth2_google']) && $_SESSION['code_oauth2_google'] != "/Client/oauth2callback//") {
          $this->client->authenticate($_SESSION['code_oauth2_google']);
          $_SESSION['application_google_token'] = $this->client->getAccessToken();
          unset($_SESSION['code_oauth2_google']);
        }

        if(isset($_SESSION['application_google_token']) && $_SESSION['application_google_token']) {
{'fraction_non_alphanumeric': 0.16418956814357824, 'fraction_numerical': 0.019770050476724622, 'mean_word_length': 4.379336349924586, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 158, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 1}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6576494', 'n_tokens_mistral': 2211, 'n_tokens_neox': 2156, 'n_words': 218}