<commit_before><?php
/**
 *
 * This file is part of Open Library System.
 * Copyright © 2009, <NAME> a/s,
 * Tempovej 7-11, DK-2750 Ballerup, Denmark. CVR: 15149043
 *
 * Open Library System is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Open Library System is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Open Library System.  If not, see <http://www.gnu.org/licenses/>.
**/

/**
 * \brief
 *
 *
 *
 * need curl_class and memcache_class or memcachedb_class to be defined
 *
**/

require_once('OLS_class_lib/memcache_class.php');
require_once('OLS_class_lib/curl_class.php');

class search_profiles {

  private $profile_cache;		    // cache object
  private $profiles;		        // profiles for $agency
  private $agency_uri;	        // uri of openagency service

  public function __construct($open_agency, $cache_host, $cache_port='', $cache_seconds = 0) {
    if ($cache_host) {
      $this->profile_cache = new cache($cache_host, $cache_port, $cache_seconds);
    }
    $this->agency_uri = $open_agency;
  }

  /**
  * \brief Get a given profile for the agency
  *
  * @param $profile_name       name of profile
  * @param $profile_version    version of profile: 2 or 3
  *
  * @returns profile if found, FALSE otherwise
  **/
  public function get_profile($agency, $profile_name, $profile_version) {
    if ($this->profile_cache) {
      $cache_key = 'PROFILE_' . $agency;
      $this->profiles = $this->profile_cache->get($cache_key);
    }

    if (!$this->profiles) {
      $curl = new curl();
      $curl->set_option(CURLOPT_TIMEOUT, 10);
      $res_xml = $curl->get(sprintf($this->agency_uri, $agency, $profile_version));
      $curl_err = $curl->get_status();
      if ($curl_err['http_code'] < 200 || $curl_err['http_code'] > 299) {<commit_msg>profile_version in cache key<commit_after><?php
/**
 *
 * This file is part of Open Library System.
 * Copyright © 2009, <NAME> a/s,
 * Tempovej 7-11, DK-2750 Ballerup, Denmark. CVR: 15149043
 *
 * Open Library System is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Open Library System is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Open Library System.  If not, see <http://www.gnu.org/licenses/>.
**/

/**
 * \brief
 *
 *
 *
 * need curl_class and memcache_class or memcachedb_class to be defined
 *
**/

require_once('OLS_class_lib/memcache_class.php');
require_once('OLS_class_lib/curl_class.php');

class search_profiles {

  private $profile_cache;		    // cache object
  private $profiles;		        // profiles for $agency
  private $agency_uri;	        // uri of openagency service

  public function __construct($open_agency, $cache_host, $cache_port='', $cache_seconds = 0) {
    if ($cache_host) {
      $this->profile_cache = new cache($cache_host, $cache_port, $cache_seconds);
    }
    $this->agency_uri = $open_agency;
  }

  /**
  * \brief Get a given profile for the agency
  *
  * @param $profile_name       name of profile
  * @param $profile_version    version of profile: 2 or 3
  *
  * @returns profile if found, FALSE otherwise
  **/
  public function get_profile($agency, $profile_name, $profile_version) {
    if ($this->profile_cache) {
      $cache_key = 'PROFILE_' . $agency . '_' . $profile_version;
      $this->profiles = $this->profile_cache->get($cache_key);
    }

    if (!$this->profiles) {
      $curl = new curl();
      $curl->set_option(CURLOPT_TIMEOUT, 10);
      $res_xml = $curl->get(sprintf($this->agency_uri, $agency, $profile_version));
      $curl_err = $curl->get_status();
      if ($curl_err['http_code'] < 200 || $curl_err['http_code'] > 299) {
{'fraction_non_alphanumeric': 0.11570796460176991, 'fraction_numerical': 0.013716814159292035, 'mean_word_length': 3.502988047808765, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '1326069', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1383, 'n_words': 460}