<commit_before><?php
/**
 * Copyright 2006 - 2011 <NAME> (http://ehough.com)
 * 
 * This file is part of TubePress (http://tubepress.org)
 * 
 * TubePress is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * TubePress 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with TubePress.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

class_exists('org_tubepress_impl_classloader_ClassLoader') || require dirname(__FILE__) . '/../../../impl/classloader/ClassLoader.class.php';
org_tubepress_impl_classloader_ClassLoader::loadClasses(array(
    'org_tubepress_impl_http_clientimpl_commands_AbstractHttpCommand',
    'org_tubepress_impl_http_HttpClientChain',
));

/**
 * Lifted from http://core.trac.wordpress.org/browser/tags/3.0.4/wp-includes/class-http.php
 *
 * HTTP request method uses fopen function to retrieve the url.
 *
 * Does not allow for $context support,
 * but should still be okay, to write the headers, before getting the response. Also requires that
 * 'allow_url_fopen' to be enabled.
 *
 */
class org_tubepress_impl_http_clientimpl_commands_FopenCommand  extends org_tubepress_impl_http_clientimpl_commands_AbstractHttpCommand
{
    const INI_USER_AGENT = 'user_agent';

    /**
     * Send a HTTP request to a URI using fopen().
     *
     * This transport does not support sending of headers and body, therefore should not be used in
     * the instances, where there is a body and headers.
     *
     * @param string $url  URI resource.
     * @param array  $args Optional. Override the defaults.
     *
     * @return array 'headers', 'body', 'cookies' and 'response' keys.
     */
    protected function _doExecute($url, $r)
    {
        $arrURL = parse_url($url);

        if ('http' != $arrURL['scheme'] && 'https' != $arrURL['scheme']) {
            $url = str_replace($arrURL['scheme'], 'http', $url);
        }

        $initialUserAgent = ini_get(self::INI_USER_AGENT);

        if (!empty($r[org_tubepress_impl_http_HttpClientChain::ARGS_HEADERS]) && is_array($r[org_tubepress_impl_http_HttpClientChain::ARGS_HEADERS])) {
            $user_agent_extra_headers = '';
            foreach ($r[org_tubepress_impl_http_HttpClientChain::ARGS_HEADERS] as $header => $value) {
                $user_agent_extra_headers .= "\r\n$header: $value";
            }
            @ini_set(self::INI_USER_AGENT, $r[org_tubepress_impl_http_HttpClientChain::ARGS_HEADERS] . $user_agent_extra_headers);
        } else {
            @ini_set(self::INI_USER_AGENT, $r[org_tubepress_impl_http_HttpClientChain::ARGS_HEADERS]);
        }

        $handle = @fopen($url, 'r');

        if (! $handle) {
            throw new Exception(sprintf('Could not open handle for fopen() to %s'), $url);
        }

        $timeout  = (int) floor($r[org_tubepress_impl_http_HttpClientChain::ARGS_TIMEOUT]);
        $utimeout = $timeout == $r[org_tubepress_impl_http_HttpClientChain::ARGS_TIMEOUT] ? 0 : 1000000 * $r['timeout'] % 1000000;
        stream_set_timeout($handle, $timeout, $utimeout);

        $strResponse = '';
        while (! feof($handle)) {<commit_msg>Fixing bug in fopen HTTP transport<commit_after><?php
/**
 * Copyright 2006 - 2011 <NAME> (http://ehough.com)
 * 
 * This file is part of TubePress (http://tubepress.org)
 * 
 * TubePress is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * TubePress 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with TubePress.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

class_exists('org_tubepress_impl_classloader_ClassLoader') || require dirname(__FILE__) . '/../../../impl/classloader/ClassLoader.class.php';
org_tubepress_impl_classloader_ClassLoader::loadClasses(array(
    'org_tubepress_impl_http_clientimpl_commands_AbstractHttpCommand',
    'org_tubepress_impl_http_HttpClientChain',
));

/**
 * Lifted from http://core.trac.wordpress.org/browser/tags/3.0.4/wp-includes/class-http.php
 *
 * HTTP request method uses fopen function to retrieve the url.
 *
 * Does not allow for $context support,
 * but should still be okay, to write the headers, before getting the response. Also requires that
 * 'allow_url_fopen' to be enabled.
 *
 */
class org_tubepress_impl_http_clientimpl_commands_FopenCommand  extends org_tubepress_impl_http_clientimpl_commands_AbstractHttpCommand
{
    const INI_USER_AGENT = 'user_agent';

    /**
     * Send a HTTP request to a URI using fopen().
     *
     * This transport does not support sending of headers and body, therefore should not be used in
     * the instances, where there is a body and headers.
     *
     * @param string $url  URI resource.
     * @param array  $args Optional. Override the defaults.
     *
     * @return array 'headers', 'body', 'cookies' and 'response' keys.
     */
    protected function _doExecute($url, $r)
    {
        $arrURL = parse_url($url);

        if ('http' != $arrURL['scheme'] && 'https' != $arrURL['scheme']) {
            $url = str_replace($arrURL['scheme'], 'http', $url);
        }

        $initialUserAgent = ini_get(self::INI_USER_AGENT);

        if (!empty($r[org_tubepress_impl_http_HttpClientChain::ARGS_HEADERS]) && is_array($r[org_tubepress_impl_http_HttpClientChain::ARGS_HEADERS])) {
            $user_agent_extra_headers = '';
            foreach ($r[org_tubepress_impl_http_HttpClientChain::ARGS_HEADERS] as $header => $value) {
                $user_agent_extra_headers .= "\r\n$header: $value";
            }
            @ini_set(self::INI_USER_AGENT, $r[org_tubepress_impl_http_HttpClientChain::ARGS_HEADERS] . $user_agent_extra_headers);
        } else {
            @ini_set(self::INI_USER_AGENT, $r[org_tubepress_impl_http_HttpClientChain::ARGS_HEADERS]);
        }

        $handle = @fopen($url, 'r');

        if (! $handle) {
            throw new Exception(sprintf('Could not open handle for fopen() to %s', $url));
        }

        $timeout  = (int) floor($r[org_tubepress_impl_http_HttpClientChain::ARGS_TIMEOUT]);
        $utimeout = $timeout == $r[org_tubepress_impl_http_HttpClientChain::ARGS_TIMEOUT] ? 0 : 1000000 * $r['timeout'] % 1000000;
        stream_set_timeout($handle, $timeout, $utimeout);

        $strResponse = '';
        while (! feof($handle)) {
{'fraction_non_alphanumeric': 0.11383264901599886, 'fraction_numerical': 0.007645476426447685, 'mean_word_length': 3.551546391752577, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1092116', 'n_tokens_mistral': 2240, 'n_tokens_neox': 2141, 'n_words': 571}