Example #1
0
 function Parse($rss_url)
 {
     // Load RSS file
     require_once "inc/classes/SimpleHTTP.php";
     $rss_content = SimpleHTTP::getData($rss_url);
     if (SimpleHTTP::getState() != SIMPLEHTTP_STATE_OK) {
         // last op was not ok
         // log
         global $cfg;
         $msgs = SimpleHTTP::getMessages();
         AuditAction($cfg["constants"]["error"], "lastRSS: could not download feed-data from url " . $rss_url . " (" . implode("; ", $msgs) . ")");
         // return false
         return false;
     }
     // result-array
     $result = array();
     // document encoding
     $result['encoding'] = $this->my_preg_match("'encoding=[\\'\"](.*?)[\\'\"]'si", $rss_content);
     // if document codepage is specified, use it
     if ($result['encoding'] != '') {
         $this->rsscp = $result['encoding'];
         // This is used in my_preg_match()
     } else {
         // otherwise use the default codepage
         $this->rsscp = $this->default_cp;
         // This is used in my_preg_match()
     }
     // CHANNEL info
     if (preg_match("'<channel.*?>(.*?)</channel>'si", $rss_content, $out_channel)) {
         foreach ($this->_channeltags as $channeltag) {
             $temp = $this->my_preg_match("'<{$channeltag}.*?>(.*?)</{$channeltag}>'si", $out_channel[1]);
             if ($temp != '') {
                 $result[$channeltag] = $temp;
             }
             // Set only if not empty
         }
     }
     // If date_format is specified and lastBuildDate is valid
     if ($this->date_format != '' && ($timestamp = strtotime($result['lastBuildDate'])) !== -1) {
         // convert lastBuildDate to specified date format
         $result['lastBuildDate'] = date($this->date_format, $timestamp);
     }
     // TEXTINPUT info
     preg_match("'<textinput(|[^>]*[^/])>(.*?)</textinput>'si", $rss_content, $out_textinfo);
     // This a little strange regexp means:
     // Look for tag <textinput> with or without any attributes, but skip truncated version <textinput /> (it's not beginning tag)
     if (isset($out_textinfo[2])) {
         foreach ($this->_textinputtags as $textinputtag) {
             $temp = $this->my_preg_match("'<{$textinputtag}.*?>(.*?)</{$textinputtag}>'si", $out_textinfo[2]);
             if ($temp != '') {
                 $result['textinput_' . $textinputtag] = $temp;
             }
             // Set only if not empty
         }
     }
     // IMAGE info
     preg_match("'<image.*?>(.*?)</image>'si", $rss_content, $out_imageinfo);
     if (isset($out_imageinfo[1])) {
         foreach ($this->_imagetags as $imagetag) {
             $temp = $this->my_preg_match("'<{$imagetag}.*?>(.*?)</{$imagetag}>'si", $out_imageinfo[1]);
             if ($temp != '') {
                 $result['image_' . $imagetag] = $temp;
             }
             // Set only if not empty
         }
     }
     // ITEMS
     preg_match_all("'<item(| .*?)>(.*?)</item>'si", $rss_content, $items);
     $rss_items = $items[2];
     $i = 0;
     $result['items'] = array();
     // create array even if there are no items
     foreach ($rss_items as $rss_item) {
         // If number of items is lower then limit: parse one item
         if ($i < $this->items_limit || $this->items_limit == 0) {
             foreach ($this->_itemtags as $itemtag) {
                 $temp = $this->my_preg_match("'<{$itemtag}.*?>(.*?)</{$itemtag}>'si", $rss_item);
                 if ($temp != '') {
                     $result['items'][$i][$itemtag] = $temp;
                 }
                 // Set only if not empty
             }
             // Strip HTML tags and other bullshit from DESCRIPTION
             if ($this->stripHTML && $result['items'][$i]['description']) {
                 $result['items'][$i]['description'] = strip_tags($this->unhtmlentities(strip_tags($result['items'][$i]['description'])));
             }
             // Strip HTML tags and other bullshit from TITLE
             if ($this->stripHTML && $result['items'][$i]['title']) {
                 $result['items'][$i]['title'] = strip_tags($this->unhtmlentities(strip_tags($result['items'][$i]['title'])));
             }
             // If date_format is specified and pubDate is valid
             if ($this->date_format != '' && ($timestamp = strtotime($result['items'][$i]['pubDate'])) !== -1) {
                 // convert pubDate to specified date format
                 $result['items'][$i]['pubDate'] = date($this->date_format, $timestamp);
             }
             // Item counter
             $i++;
         }
     }
     $result['items_count'] = $i;
     return $result;
 }
 function makeRequest($request, $useAlt = false)
 {
     $refererURI = isset($_SESSION['lastOutBoundURI']) ? $_SESSION['lastOutBoundURI'] : "http://" . $this->mainURL;
     $request = $useAlt ? "http://" . $this->altURL . $request : "http://" . $this->mainURL . $request;
     // require SimpleHTTP
     require_once "inc/classes/SimpleHTTP.php";
     // get data
     $this->htmlPage = SimpleHTTP::getData($request, $refererURI);
     // return
     return SimpleHTTP::getState() == SIMPLEHTTP_STATE_OK;
 }
Example #3
0
function _dir_WgetFile($url, $target_dir)
{
    require_once 'inc/functions/functions.core.tfb.php';
    global $cfg;
    $filename = "";
    $downloadMessages = array();
    if (!empty($url)) {
        $arURL = explode("/", $url);
        $filename = urldecode($arURL[count($arURL) - 1]);
        // get the file name
        $filename = str_replace(array("'", ","), "", $filename);
        $filename = stripslashes($filename);
        // Check to see if url has something like ?passkey=12345
        // If so remove it.
        if (($point = strrpos($filename, "?")) !== false) {
            $filename = substr($filename, 0, $point);
        }
        $ret = strrpos($filename, ".");
        $url = str_replace(" ", "%20", $url);
        // This is to support Sites that pass an id along with the url for downloads.
        $tmpId = tfb_getRequestVar("id");
        if (!empty($tmpId)) {
            $url .= "&id=" . $tmpId;
        }
        // retrieve the file
        require_once "inc/classes/SimpleHTTP.php";
        $content = SimpleHTTP::getData($url);
        if (SimpleHTTP::getState() == SIMPLEHTTP_STATE_OK && strlen($content) > 0) {
            $fileNameBackup = $filename;
            $filename = SimpleHTTP::getFilename();
            if ($filename != "") {
                $filename = _dir_cleanFileName($filename);
            }
            if ($filename == "" || $filename === false) {
                $filename = _dir_cleanFileName($fileNameBackup);
                if ($filename === false || $filename == "") {
                    $filename = _dir_cleanFileName(SimpleHTTP::getRealUrl($url));
                    if ($filename === false || $filename == "") {
                        $filename = _dir_cleanFileName(md5($url . strval(@microtime())));
                        if ($filename === false || $filename == "") {
                            // Error
                            array_push($downloadMessages, "failed to get a valid filename for " . $url);
                        }
                    }
                }
            }
            if (empty($downloadMessages)) {
                // no messages
                // check if content contains html
                if ($cfg['debuglevel'] > 0) {
                    if (strpos($content, "<br />") !== false) {
                        AuditAction($cfg["constants"]["debug"], "download-content contained html : " . htmlentities(addslashes($url), ENT_QUOTES));
                    }
                }
                if (is_file($target_dir . $filename)) {
                    // Error
                    array_push($downloadMessages, "the file " . $filename . " already exists on the server.");
                } else {
                    // write to file
                    $handle = false;
                    $handle = @fopen($target_dir . $filename, "w");
                    if (!$handle) {
                        array_push($downloadMessages, "cannot open " . $target_dir . $filename . " for writing.");
                    } else {
                        $result = @fwrite($handle, $content);
                        @fclose($handle);
                        if ($result === false) {
                            array_push($downloadMessages, "cannot write content to " . $filename . ".");
                        }
                    }
                }
            }
        } else {
            $msgs = SimpleHTTP::getMessages();
            if (count($msgs) > 0) {
                $downloadMessages = array_merge($downloadMessages, $msgs);
            }
        }
        if (empty($downloadMessages)) {
            // no messages
            AuditAction($cfg["constants"]["url_upload"], $filename);
        }
    } else {
        array_push($downloadMessages, "Invalid Url : " . $url);
    }
    if (count($downloadMessages) > 0) {
        AuditAction($cfg["constants"]["error"], $cfg["constants"]["url_upload"] . " :: " . $filename);
        @error("There were Problems", "", "", $downloadMessages);
    }
}