<commit_before><?php

require_once 'EpiCurl.php';

class Ungadget {

    private $opensocial_version = '0.8';
    private $strip_newlines = true;

    public function transformFromUrl($url) {
        $hdl = $this->getCurlHandleForUrl($url);
        $ec = EpiCurl::getInstance();
        $ec->addCurl($hdl);
        $gadget = $ec->getResult((string) $hdl);
        return $this->transformGadget($gadget['data']);
    }

    public function setOpenSocialVersion($version) {
        $this->opensocial_version = $version;
    }

    public function setStripNewlines($bool) {
        $this->strip_newlines = $bool;
    }

    public function transformGadget($gadget) {
        $xml = new SimpleXMLElement($gadget);

        if (!$xml) throw new Exception('Bad XML');

        $version = $this->opensocial_version;
        if ($version) {
            $opensocial = $xml->xpath('/Module/ModulePrefs/Require[@feature="opensocial-' . $version . '"]');
            if (count($opensocial) == 0)
                throw new Exception('This gadget does not support OpenSocial ' . $version);
        }

        $content = $xml->xpath('/Module/Content[@type="html"]');

        if ($content) {
            $ec = EpiCurl::getInstance();
            $hdls = array();
            foreach(array('js', 'css') as $type) $hdls[$type] = array();
            $content = $content[0];

            /* scripts */
            preg_match_all("/<script[^<>]+src=['\"]([^<>'\"]+)['\"][^<>]*>(.*)<\/script>/i", $content, $scripts);
            $content = str_replace($scripts[0], '', $content);
            foreach ($scripts[1] as $url) {
                $hdl = $this->getCurlHandleForUrl($url);<commit_msg>Support multiple Content blocks<commit_after><?php

require_once 'EpiCurl.php';

class Ungadget {

    private $opensocial_version = '0.8';
    private $strip_newlines = true;

    public function transformFromUrl($url) {
        $hdl = $this->getCurlHandleForUrl($url);
        $ec = EpiCurl::getInstance();
        $ec->addCurl($hdl);
        $gadget = $ec->getResult((string) $hdl);
        return $this->transformGadget($gadget['data']);
    }

    public function setOpenSocialVersion($version) {
        $this->opensocial_version = $version;
    }

    public function setStripNewlines($bool) {
        $this->strip_newlines = $bool;
    }

    public function transformGadget($gadget) {
        $xml = new SimpleXMLElement($gadget);

        if (!$xml) throw new Exception('Bad XML');

        $version = $this->opensocial_version;
        if ($version) {
            $opensocial = $xml->xpath('/Module/ModulePrefs/Require[@feature="opensocial-' . $version . '"]');
            if (count($opensocial) == 0)
                throw new Exception('This gadget does not support OpenSocial ' . $version);
        }

        $contents = $xml->xpath('/Module/Content[@type="html"]');
        $content = '';
        foreach ($contents as $block) {
            $content .= $block;
        }

        if ($content) {
            $ec = EpiCurl::getInstance();

            $hdls = array();
            foreach(array('js', 'css') as $type) $hdls[$type] = array();

            /* scripts */
            preg_match_all("/<script[^<>]+src=['\"]([^<>'\"]+)['\"][^<>]*>(.*)<\/script>/i", $content, $scripts);
            $content = str_replace($scripts[0], '', $content);
            foreach ($scripts[1] as $url) {
                $hdl = $this->getCurlHandleForUrl($url);
{'fraction_non_alphanumeric': 0.18107714701601166, 'fraction_numerical': 0.003202328966521106, 'mean_word_length': 2.481256332320162, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '4853613', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1046, 'n_words': 195}