<commit_before><?php
// Add the QuantiModo Javascript
add_action('wp_head', 'add_quantimodo');
// The guts of the QuantiModo script
function add_quantimodo()
{
  // Ignore admin, feed, robots or trackbacks
  if ( is_feed() || is_robots() || is_trackback() ){return;}
  $options = get_option('QuantiModo_settings');
  // If options is empty then exit
  if( empty( $options ) ){return;}
  // Check to see if QuantiModo is enabled
  if ( esc_attr( $options['quantimodo_enabled'] ) == "on" ){
    $qmClientId = $options['quantimodo_widget_code'];
    $qmClientSecret = $options['quantimodo_client_secret'];
    $apiHostName = "https://app.quantimo.do";
    $env = $_SERVER["HTTP_REFERER"] ?? getenv('APP_HOST_NAME');
    if(!$env){$env = "https://".$_SERVER["HTTP_HOST"];}
    if(stripos($env, "https://utopia.quantimo.do") === 0 || stripos($env, "https://local.quantimo.do") === 0){
        $apiHostName = "https://utopia.quantimo.do";
    }
    $jsUrl = plugins_url( '/integration.js', __FILE__ );
    $jsText = '<script src="'.$jsUrl.'"></script> <script> window.QuantiModoIntegration.options = {';
    $wpUserId = get_current_user_id();
    if($wpUserId){
        $jsText .= "clientUserId: encodeURIComponent('".$wpUserId."'),";
        $wpUser = wp_get_current_user();
        $jsText .= "clientUser: encodeURIComponent('".json_encode($wpUser->data)."'),";
        $accessToken = get_user_meta($wpUserId, 'qm_access_token', true);
        if(!$accessToken){
            $args = [
                'timeout' => 10,
                'body' => ['clientUser' => $wpUser->data]
            ];
            $url = $apiHostName.'/api/v1/user?qmClientId='.$qmClientId.
                '&clientSecret='.$qmClientSecret.'&clientUserId='.$wpUserId;
            $response = wp_remote_post( $url, $args );
            $body = json_decode($response['body'], false);
            if(isset($body->user)){
                $qmUser = $body->user;
                $jsText .= "qmUser: ".json_encode($qmUser).",";<commit_msg>User request params<commit_after><?php
// Add the QuantiModo Javascript
add_action('wp_head', 'add_quantimodo');
// The guts of the QuantiModo script
function add_quantimodo()
{
  // Ignore admin, feed, robots or trackbacks
  if ( is_feed() || is_robots() || is_trackback() ){return;}
  $options = get_option('QuantiModo_settings');
  // If options is empty then exit
  if( empty( $options ) ){return;}
  // Check to see if QuantiModo is enabled
  if ( esc_attr( $options['quantimodo_enabled'] ) == "on" ){
    $qmClientId = $options['quantimodo_widget_code'];
    $qmClientSecret = $options['quantimodo_client_secret'] ?? null;
    $apiHostName = "https://app.quantimo.do";
    $env = $_SERVER["HTTP_REFERER"] ?? getenv('APP_HOST_NAME');
    if(!$env){$env = "https://".$_SERVER["HTTP_HOST"];}
    if(stripos($env, "https://utopia.quantimo.do") === 0 || stripos($env, "https://local.quantimo.do") === 0){
        $apiHostName = "https://utopia.quantimo.do";
    }
    $jsUrl = plugins_url( '/integration.js', __FILE__ );
    $jsText = '<script src="'.$jsUrl.'"></script> <script> window.QuantiModoIntegration.options = {';
    $wpUserId = get_current_user_id();
    if($wpUserId){
        $jsText .= "clientUserId: encodeURIComponent('".$wpUserId."'),";
        $wpUser = wp_get_current_user();
        $jsText .= "clientUser: encodeURIComponent('".json_encode($wpUser->data)."'),";
        $accessToken = get_user_meta($wpUserId, 'qm_access_token', true);
        if(!$accessToken){
            $args = [
                'timeout' => 10,
                'body' => ['clientUser' => $wpUser->data]
            ];
            $url = $apiHostName.'/api/v1/user?qmClientId='.$qmClientId.'&clientUserId='.$wpUserId;
            if($qmClientSecret){
                $url .= '&clientSecret='.$qmClientSecret;
            }
            $response = wp_remote_post( $url, $args );
            $body = json_decode($response['body'], false);
            if(isset($body->user)){
                $qmUser = $body->user;
                $jsText .= "qmUser: ".json_encode($qmUser).",";
{'fraction_non_alphanumeric': 0.1872695994101745, 'fraction_numerical': 0.002457606291472106, 'mean_word_length': 3.115267947421638, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 10, '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': '6372921', 'n_tokens_mistral': 1363, 'n_tokens_neox': 1355, 'n_words': 234}