#!/usr/bin/php -q load($url); $arrFeeds = array(); foreach ($doc->getElementsByTagName('item') as $node) { $itemRSS = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, ); array_push($arrFeeds, $itemRSS); } // For each item foreach ($arrFeeds as $item) { // For each match filter foreach ($ini_array[regexmatches][matches] as $ex) { checkmatch($item, $ex); } // For each one-time match filter foreach ($ini_array[regexonetimematches][onetimematches] as $key => $ex) { if (checkmatch($item, $ex) == true) { // Remove entry and write matches back to the ini unset($ini_array[regexonetimematches][onetimematches][$key]); write_ini_file($ini_array, $watchdir.$matchesini); } } } // Function to check torrents against filters function checkmatch($item, $ex) { global $watchdir; // If there is a match if (preg_match($ex, $item['title'])) { $torrent = $watchdir.end(explode("/", $item['link'])); // If torrent file doesnt already exists if (!file_exists($torrent)) { // Download the torrent $content = file_get_contents($item['link']); if ($content !== false) { // Write .torrent to file if ($fh = fopen($torrent, 'w')) { fwrite($fh, $content); fclose($fh); } else { write_log_file("Cant write .torrent file! (".$torrent.")"); } // Write log entry write_log_file("Downloaded: ".$item['title']); return true; } else { write_log_file("Cant download torrent! (".$item['link'].")"); } } } } // Function to add entry to log function write_log_file($data) { global $logging; global $watchdir; global $logfile; if($logging == 1){ $fh = fopen($watchdir.$logfile, 'a'); if($fh != false) { fwrite($fh, date('d/m')." - ".$data."\n"); fclose($fh); } else { echo "Cant write to log file! (".$watchdir.$logfile.")"; } } } // Function to modify matches ini file function write_ini_file($assoc_arr, $path) { $content = ""; foreach ($assoc_arr as $key=>$elem) { $content .= "[".$key."]\n"; foreach ($elem as $key2=>$elem2) { if(is_array($elem2)) { for($i=0;$i