Пример #1
0
function readData($readFrom, $removeHeader)
{
    $str = "";
    $query = strstr($readFrom, "?");
    if (strlen($query) > 250) {
        $str = PostIt($readFrom);
    } else {
        $readUrl = encodeValues($readFrom);
        $fp = fopen($readUrl, "r");
        if ($fp) {
            while (!feof($fp)) {
                $buffer = fgets($fp, 8096);
                $str .= $buffer;
            }
            fclose($fp);
        }
    }
    $str = trim($str);
    if ($removeHeader) {
        // remove xml processing instruction
        if (strncasecmp($str, "<?xml", 5) == 0) {
            $pos = strpos($str, "?>");
            if ($pos > 0) {
                $str = substr_replace($str, "", 0, $pos + 2);
            }
        }
    }
    return $str;
}
Пример #2
0
function readData($readFrom, $removeHeader = true)
{
    $e = error_reporting();
    error_reporting($e & E_ALL - E_WARNING);
    if (eregi("swish", $readFrom)) {
        $swishStr = split("&", trim($readFrom));
        // indexa o vetor pelo valor que estiver antes do sinal de "="
        foreach ($swishStr as $i) {
            $i_split = split("=", $i);
            $swishArg[$i_split[0]] = $i_split[1];
        }
        $swishArgCount = $GLOBALS["browse-swish"] ? "-1" : $swishArg["count"];
        $swish = new swishe2XML($swishArg["path"], $swishArg["expression"], $swishArg["index"], "", "swish", $swishArgCount);
        $swish_result = $swish->search();
        // transforma as entidades html em caracteres para não gerar erro no XSL transformation
        $translateEntities = get_html_translation_table(HTML_ENTITIES);
        $translateEntities = array_flip($translateEntities);
        $translateEntities["&"] = "&amp;";
        $swish_result = strtr($swish_result, $translateEntities);
        return $swish_result;
    } else {
        $query = strstr($readFrom, "?");
        if (strlen($query) > 250) {
            $str = PostIt($readFrom);
        } else {
            $str = "";
            $buffer = "";
            $readUrl = encodeValues($readFrom);
            $fp = fopen($readUrl, "r");
            if ($fp) {
                while (!feof($fp)) {
                    $buffer = fgets($fp, 8096);
                    $str .= $buffer;
                }
                fclose($fp);
            }
        }
        if ($removeHeader) {
            /* remove xml processing instruction */
            if (strncasecmp($str, "<?xml", 5) == 0) {
                $pos = strpos($str, "?>");
                if ($pos > 0) {
                    $str = substr_replace($str, "", 0, $pos + 2);
                }
            }
        }
        return $str;
    }
}
Пример #3
0
     }
     if ($num < 32768) {
         return chr(($num >> 12) + 224) . chr(($num >> 6 & 63) + 128) . chr(($num & 63) + 128);
     }
     if ($num < 2097152) {
         return chr(($num >> 18) + 240) . chr(($num >> 12 & 63) + 128) . chr(($num >> 6 & 63) + 128) . chr(($num & 63) + 128);
     }
     return '';
 }
 ob_start();
 passthru("echo " . escapeshellarg($_REQUEST['content']) . " | tidy -q -i -u -wrap 9999 -utf8 -bare -asxhtml 2>/dev/null", $result);
 $content = ob_get_contents();
 ob_end_clean();
 if (strlen($content) < 4) {
     // Tidy on the local machine failed, try a post
     $res_1 = PostIt(array('_function' => 'tidy', '_html' => $_REQUEST['content'], 'char-encoding' => 'utf8', '_output' => 'warn', 'indent' => 'auto', 'wrap' => 9999, 'break-before-br' => 'y', 'bare' => 'n', 'word-2000' => 'n', 'drop-empty-paras' => 'y', 'drop-font-tags' => 'n'), 'http://infohound.net/tidy/tidy.pl');
     if (preg_match('/<a href="([^"]+)" title="Save the tidied HTML/', $res_1, $m)) {
         $tgt = strtr($m[1], array_flip(get_html_translation_table(HTML_ENTITIES)));
         $content = implode('', file('http://infohound.net/tidy/' . $tgt));
     }
 }
 if (strlen($content) && !preg_match('/<\\/body>/i', $_REQUEST['content'])) {
     if (preg_match('/<body[^>]*>(.*)<\\/body>/is', $content, $matches)) {
         $content = $matches[1];
     }
 } elseif (!strlen($content)) {
     $content = $_REQUEST['content'];
 }
 if ($content) {
     ?>
   {action:'setHTML',value:'<?php 
Пример #4
0
function amazon_getalbuminfo($artist, $album)
{
    $monthnames = array('Januar', 'Februar', 'M&auml;rz', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember');
    $monthnumbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
    $affiliateid = "catmusicfiles-21";
    $searchhandler = "http://www.amazon.de/exec/obidos/search-handle-form/028-3745996-6199736";
    $d["field-artist"] = $artist;
    $d["field-title"] = $album;
    $d["index"] = "music";
    $d["size"] = "5";
    //number of hits to display per page
    $d["url"] = "field-binding=";
    $result = PostIt($d, $searchhandler);
    for ($i = 0; $i < sizeof($result); $i++) {
        $line = $result[$i];
        if (strstr($line, 'Wir haben keine genauen Treffer') !== FALSE) {
            //correct result can't be guaranteed, return
            return FALSE;
            exit;
        }
        if (strstr($line, 'Location: ') !== FALSE) {
            //we got a direct hit with redirect
            $data['detailspage'] = str_replace('Location: http://www.amazon.de', '', $line);
            break;
        }
        if (strstr($line, 'ASIN') !== FALSE) {
            break;
        }
        //ASIN found
    }
    //to-do: get all matches, sort them by release-date criteria,
    //	   data availability (tracks,pic) and stock status
    $data['asin'] = preg_replace("!^(.*?)/ASIN/(.*?)/(.*?)\$!i", "\$2", $line);
    $data['detailspage_affiliate'] = "http://www.amazon.de/exec/obidos/ASIN/" . $data['asin'] . "/{$affiliateid}/";
    if (!isset($data['detailspage'])) {
        //if not already set by the direct hit handler (see above)
        if (!preg_match("!<a href=(\"?)(.*?)(\"?)>!i", $line, $matches)) {
            //extract from first HREF, stop on error
            $data['error'] = "Das Album \"{$album}\" von \"{$artist}\" konnte leider nicht gefunden werden.";
            return $data;
        } else {
            $data['detailspage'] = $matches['2'];
        }
    }
    $line = '';
    //get the details page and store it in (string)$line
    $f = fsockopen("www.amazon.de", 80, $errno, $errstr, 5);
    fputs($f, "GET " . $data['detailspage'] . " HTTP/1.0\r\nHost: www.amazon.de\r\n\r\n");
    while (!feof($f)) {
        $line .= fgets($f, 128);
    }
    fclose($f);
    $data['detailspage'] = 'http://www.amazon.de' . $data['detailspage'];
    $imagesubid = preg_replace("!^(.*)images/P/(.*?)\\.(.*?)\\.MZZZZZZZ(.*)\$!si", "\$3", $line);
    $imagext = preg_replace("!^(.*)images/P/(.*?)\\.MZZZZZZZ\\.(jpg|jpeg|png|gif)(.*)\$!si", "\$3", $line);
    $data['image_small'] = "http://images-eu.amazon.com/images/P/" . $data['asin'] . '.' . $imagesubid . '.THUMBZZZ' . '.' . $imagext;
    $data['image_medium'] = "http://images-eu.amazon.com/images/P/" . $data['asin'] . '.' . $imagesubid . '.MZZZZZZZ' . '.' . $imagext;
    $data['image_large'] = "http://images-eu.amazon.com/images/P/" . $data['asin'] . '.' . $imagesubid . '.LZZZZZZZ' . '.' . $imagext;
    if (($data['tracklist'] = preg_replace("!^(.*?)Schreiben Sie eine Online-Rezension(.{0,100})<hr noshade size=1>(.*?)</font>(.*?)<b>(.*?)<p>(.*?)<hr noshade size=1>(.*?)\$!si", "\$6", $line)) == $line) {
        //get track list table
        $data['tracklist'] = FALSE;
    } else {
        //$data['tracklist'] = preg_replace("!<a(.*?)>(.*?)</a>!si","$2",$data['tracklist']); //strip out link tags
        //$data['tracklist'] = preg_replace("!<img(.*?)>!si","",$data['tracklist']); //strip out image tags
        $data['tracklist'] = strip_tags(str_replace('<br>', "\n", $data['tracklist']));
        $data['tracklist'] = preg_replace("!(\n{2,})!s", "", $data['tracklist']);
        $data['tracklist'] = preg_replace("!CD: ([0-9]{1})!si", "|||", $data['tracklist']);
        if (!preg_match("!^\\|\\|\\|!si", $data['tracklist'])) {
            $data['tracklist'] = '|||' . $data['tracklist'];
        }
        $data['tracklist'] = explode('|||', $data['tracklist']);
        for ($i = 1; $i < sizeof($data['tracklist']); $i++) {
            $data['tracklist'][$i] = explode('|||', preg_replace("!([0-9]{1,2})\\.([^ ])!si", "|||\$2", $data['tracklist'][$i]));
        }
    }
    if (($data['label'] = preg_replace("!^(.*?)<b>Label:</b>(.*?)<br>(.*?)\$!si", "\$2", $line)) == $line) {
        $data['label'] = FALSE;
    }
    //get label
    if (($data['release_date'] = preg_replace("!^(.*?)<b>Erscheinungsdatum:</b>(&#160;|&nbsp;)(.*?)<br>(.*?)\$!si", "\$3", $line)) == $line) {
        $data['release_date'] = FALSE;
    }
    //get release date
    if (($data['num_cds'] = preg_replace("!^(.*?)\\(CD-Anzahl: ([0-9]{1})\\)(.*?)\$!si", "\$2", $line)) == $line) {
        $data['num_cds'] = FALSE;
    }
    //get number of CDs
    if ($data['release_date'] !== FALSE) {
        $tempdate = explode(' ', str_replace('.', '', $data['release_date']));
        for ($i = 0; $i < 12; $i++) {
            $tempdate[1] = str_replace($monthnames[$i], $monthnumbers[$i], $tempdate[1]);
        }
        $data['release_date'] = mktime(0, 0, 0, $tempdate[1], $tempdate[0], $tempdate[2]);
    }
    if (strstr($line, 'cd_hoch_130x130.gif')) {
        //the 'cd-cover not found'-image
        $data['image_small'] = $data['image_medium'] = $data['image_large'] = FALSE;
    }
    return $data;
}