<commit_before><?php
define('DEFAULT_DELIMITER', ',');
define('DEFAULT_URL', 'http://www.google.com/search?q=%s');
define('HELP_TITLE', '...your commands');
define('HELP_TRIGGER', 'help');
define('SHRT_URL', 'http://github.com/xvzf/shrt/tree/master');
define('TITLE', '...because Saft is broken in the WebKit nightlies');
define('USERAGENT', 'Grabbing your shrtcuts. (' . SHRT_URL . '); Allow like Gecko');
define('IS_LOCKED', FALSE);
define('FILE_MATCH', '');

ini_set('user_agent', USERAGENT);

function encode(&$val, $key)
{
    return $val = urlencode($val);
}

function url()
{
    $protocol = array_key_exists('HTTPS', $_SERVER) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
    return $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
}

function show_help()
{
    return isset($_GET['f']) and isset($_GET['c']) and trim($_GET['c']) == HELP_TRIGGER;
}

function title()
{
    if (show_help()) { return HELP_TITLE; }
    return TITLE;
}

function get_file($url) 
{
    if (FILE_MATCH != '')
    {
        if (preg_match(FILE_MATCH, $url) == FALSE)
        {
            die("<p><strong class=\"error\">Warning:</strong> The URL <strong>$url</strong> did not match the required pattern.</p>");
        }
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, USERAGENT);
    $data = curl_exec($ch);
    if(curl_error($ch))
    {
        echo curl_error($ch);
    }
    curl_close($ch);
    return $data;
}

function get_args($arg)
{
    $args = preg_replace('/\s\s+/', ' ', trim($arg));
    preg_match('/^(?<trigger>\w+)(\s+(?<terms>.*))?/', $args, $matches);
    if (!$matches){ return; }
    
    if (!array_key_exists('terms', $matches))
    {
        $matches['terms'] = "";
    }
    $terms = explode(DEFAULT_DELIMITER, $matches['terms']);
    array_walk($terms, 'encode');

	$matches['command'] = $arg;
    $matches['terms'] = $terms;
    return $matches;
}

function get_shrts($file)<commit_msg>Punctuation can now be used in triggers.<commit_after><?php
define('DEFAULT_DELIMITER', ',');
define('DEFAULT_URL', 'http://www.google.com/search?q=%s');
define('HELP_TITLE', '...your commands');
define('HELP_TRIGGER', 'help');
define('SHRT_URL', 'http://github.com/xvzf/shrt/tree/master');
define('TITLE', '...because Saft is broken in the WebKit nightlies');
define('USERAGENT', 'Grabbing your shrtcuts. (' . SHRT_URL . '); Allow like Gecko');
define('IS_LOCKED', FALSE);
define('FILE_MATCH', '');

ini_set('user_agent', USERAGENT);

function encode(&$val, $key)
{
    return $val = urlencode($val);
}

function url()
{
    $protocol = array_key_exists('HTTPS', $_SERVER) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
    return $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
}

function show_help()
{
    return isset($_GET['f']) and isset($_GET['c']) and trim($_GET['c']) == HELP_TRIGGER;
}

function title()
{
    if (show_help()) { return HELP_TITLE; }
    return TITLE;
}

function get_file($url) 
{
    if (FILE_MATCH != '')
    {
        if (preg_match(FILE_MATCH, $url) == FALSE)
        {
            die("<p><strong class=\"error\">Warning:</strong> The URL <strong>$url</strong> did not match the required pattern.</p>");
        }
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, USERAGENT);
    $data = curl_exec($ch);
    if(curl_error($ch))
    {
        echo curl_error($ch);
    }
    curl_close($ch);
    return $data;
}

function get_args($arg)
{
    $args = preg_replace('/\s\s+/', ' ', trim($arg));
    preg_match('/^(?<trigger>(\w|\p{P})+)(\s+(?<terms>.*))?/', $args, $matches);
    if (!$matches){ return; }
    
    if (!array_key_exists('terms', $matches))
    {
        $matches['terms'] = "";
    }
    $terms = explode(DEFAULT_DELIMITER, $matches['terms']);
    array_walk($terms, 'encode');

	$matches['command'] = $arg;
    $matches['terms'] = $terms;
    return $matches;
}

function get_shrts($file)
{'fraction_non_alphanumeric': 0.213617837449053, 'fraction_numerical': 0.0009590026372572524, 'mean_word_length': 3.9964071856287426, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, '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': '151764', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1505, 'n_words': 277}