<commit_before><?php

namespace alpipego\adaptiveImages;

class AdaptiveImages
{
    public function __construct()
    {
        \add_action('wp_ajax_ai_load_image', [$this, 'ai_flickr_ajax']);
        \add_action('wp_ajax_nopriv_ai_load_image', [$this, 'ai_flickr_ajax']);

        \add_filter('acf/validate_value/name=flickr_url_id', [$this, 'ai_validate_flickr_url_id'], 10, 4);
    }

    function ai_image($id)
    {
        $image = new Image($id);
        return $image->ratio;
    }

    function ai_resize($id, $ratio)
    {
        $resize = new Resize($id);
        return $resize->resizeByRatio($ratio);
    }

    function ai_flickr_test($url)
    {
        $flickr = new Flickr($url);
        return $flickr;
    }

    function ai_flickr($url)
    {
        $flickr = new Flickr($url);
        return $flickr->getImage();
    }

    function ai_admin($value)
    {
        $valid = true;
        $admin = new Admin();
        
        try {
            $admin->idOrUrl($value);
        } catch (Exception $e) {
            $valid = $e->getMessage();
        }
        return $valid;
    }

    function ai_flickr_ajax()
    {
        $flickr = new Flickr($_POST['id']);
        $size = $_POST['containerWidth'] * $_POST['pixelRatio'];
        $availSizesArr = $flickr->getSizes();

        $closest = null;

        foreach ($availSizesArr as $key => $availSizes) {
            $width = (int) $availSizes['width'];
            if ($closest == null || abs($size - $closest) > abs($width - $size)) {
                $closest = $key;
            }
        }

        echo base64_encode($availSizesArr[$closest]['source']);
        wp_die();
    }

    function ai_validate_flickr_url_id($valid, $value, $field, $input)
    {
        $admin = new Admin();

        // bail early if value is already invalid
        if(!$valid) {
            return $valid;
        }
        
        try {
            $admin->idOrUrl($value);
        } catch (Exception $e) {
            $valid = $e->getMessage();
        }
        
        // return
        return $valid;
    }    
}<commit_msg>in the new approach all those public functions are not needed anymore<commit_after><?php

namespace alpipego\adaptiveImages;

class AdaptiveImages
{
    public function __construct()
    {
        \add_action('wp_ajax_ai_load_image', [$this, 'ai_flickr_ajax']);
        \add_action('wp_ajax_nopriv_ai_load_image', [$this, 'ai_flickr_ajax']);

        \add_filter('acf/validate_value/name=ai_url_id', [$this, 'ai_validate_flickr_url_id'], 10, 4);
    }

    function ai_flickr_ajax()
    {
        $flickr = new Flickr($_POST['id']);
        $size = $_POST['containerWidth'] * $_POST['pixelRatio'];
        $availSizesArr = $flickr->getSizes();

        $closest = null;

        foreach ($availSizesArr as $key => $availSizes) {
            $width = (int) $availSizes['width'];
            if ($closest == null || abs($size - $closest) > abs($width - $size)) {
                $closest = $key;
            }
        }

        echo base64_encode($availSizesArr[$closest]['source']);
        wp_die();
    }

    function ai_validate_flickr_url_id($valid, $value, $field, $input)
    {
        $admin = new Admin();

        // bail early if value is already invalid
        if(!$valid) {
            return $valid;
        }
        
        try {
            $admin->idOrUrl($value);
        } catch (Exception $e) {
            $valid = $e->getMessage();
        }
        
        // return
        return $valid;
    }

    
}
{'fraction_non_alphanumeric': 0.14537194775695628, 'fraction_numerical': 0.0028392958546280523, 'mean_word_length': 1.9830651989839119, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, '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': '6673262', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1116, 'n_words': 214}