function atom_perform_matching($atom, $idx, $feedName, $feedLink) { global $config_values, $matched; $atom = array_change_key_case_ext($atom, ARRAY_KEY_LOWERCASE); if (count($atom['feed']) == 0) { return; } if (isset($config_values['Global']['HTMLOutput']) && $config_values['Settings']['Combine Feeds'] == 0) { show_feed_html($idx); } $alt = 'alt'; $htmlList = array(); $items = array_reverse($atom['feed']['entry']); foreach ($items as $item) { if ($filter = get_item_filter()) { $item['title'] = preg_replace($filter, '', $item['title']); } if (preg_match('/\\b(720p|1080p|1080i)\\b/i', $item['title'])) { $item['title'] = preg_replace('/( -)?[_. ]HDTV/', '', $item['title']); } $torHash = ''; $matched = "nomatch"; array_walk($config_values['Favorites'], 'check_for_torrent', array('Obj' => $item, 'URL' => $feedLink)); $client = $config_values['Settings']['Client']; $cache_file = $config_values['Settings']['Cache Dir'] . '/rss_dl_' . filename_encode($item['title']); if (file_exists($cache_file)) { $torHash = get_torHash($cache_file); if ($matched != "match" && $matched != 'cachehit' && file_exists($cache_file)) { $matched = 'downloaded'; _debug("matched: " . $item['title'] . "\n", 1); } } if (isset($config_values['Global']['HTMLOutput'])) { if (!$rsnr) { $rsnr = 1; } else { $rsnr++; } if (strlen($rsnr) <= 1) { $rsnr = 0 . $rsnr; } $id = $idx . $rsnr; $htmlItems = array('item' => $item, 'URL' => $feedLink, 'feedName' => $feedName, 'alt' => $alt, 'torHash' => $torHash, 'matched' => $matched, 'id' => $id); array_push($htmlList, $htmlItems); } if ($alt == 'alt') { $alt = ''; } else { $alt = 'alt'; } } _debug(print_r($htmlList, true)); $htmlList = array_reverse($htmlList, true); foreach ($htmlList as $item) { show_torrent_html($item[item], $item[URL], $item[feedName], $item[alt], $item[torHash], $item[matched], $item[id]); } if (isset($config_values['Global']['HTMLOutput']) && $config_values['Settings']['Combine Feeds'] == 0) { close_feed_html($idx, 0); } unset($item); }
/** * change the case of array-keys * * use: array_change_key_case_ext(array('foo' => 1, 'bar' => 2), ARRAY_KEY_UPPERCASE); * result: array('FOO' => 1, 'BAR' => 2) * * @param array * @param int * @return array */ function array_change_key_case_ext($array, $case = ARRAY_KEY_LOWERCASE) { $newArray = array(); //for more speed define the runtime created functions in the global namespac //get function $function = 'strToUpper'; //default switch ($case) { //first-char-to-lowercase case 25: //maybee lcfirst is not callable if (!function_exists('lcfirst')) { $function = create_function('$input', 'return strToLower($input[0]) . substr($input, 1, (strLen($input) - 1));'); } else { $function = 'lcfirst'; } break; //first-char-to-uppercase //first-char-to-uppercase case 20: $function = 'ucfirst'; break; //lowercase //lowercase case 10: $function = 'strToLower'; } //loop array foreach ($array as $key => $value) { if (is_array($value)) { //$value is an array, handle keys too $newArray[$function($key)] = array_change_key_case_ext($value, $case); } elseif (is_string($key)) { $newArray[$function($key)] = $value; } else { $newArray[$key] = $value; } //$key is not a string } //end loop return $newArray; }