function check_uri_spam($target = '', $method = array()) { // Return value $progress = array('method' => array(), 'sum' => array(), 'is_spam' => array(), 'blocked' => array(), 'hosts' => array()); // Aliases $sum =& $progress['sum']; $is_spam =& $progress['is_spam']; $progress['method'] =& $method; // Argument $blocked =& $progress['blocked']; $hosts =& $progress['hosts']; $asap = isset($method['asap']); // Init if (!is_array($method) || empty($method)) { $method = check_uri_spam_method(); } foreach (array_keys($method) as $key) { if (!isset($sum[$key])) { $sum[$key] = 0; } } if (is_array($target)) { foreach ($target as $str) { if (!is_string($str)) { continue; } $_progress = check_uri_spam($str, $method); // Recurse // Merge $sum $_sum =& $_progress['sum']; foreach (array_keys($_sum) as $key) { if (!isset($sum[$key])) { $sum[$key] =& $_sum[$key]; } else { $sum[$key] += $_sum[$key]; } } // Merge $is_spam $_is_spam =& $_progress['is_spam']; foreach (array_keys($_is_spam) as $key) { $is_spam[$key] = TRUE; if ($asap) { break; } } if ($asap && $is_spam) { break; } // Merge only $blocked = array_merge_leaves($blocked, $_progress['blocked'], FALSE, FALSE); $hosts = array_merge_leaves($hosts, $_progress['hosts'], FALSE, FALSE); } // Unique values $blocked = array_unique_recursive($blocked); $hosts = array_unique_recursive($hosts); // Renumber numeric keys array_renumber_numeric_keys($blocked); array_renumber_numeric_keys($hosts); // Recount $sum['badhost'] $sum['badhost'] = array_count_leaves($blocked); return $progress; } // Area: There's HTML anchor tag if ((!$asap || !$is_spam) && isset($method['area_anchor'])) { $key = 'area_anchor'; $_asap = isset($method['asap']) ? array('asap' => TRUE) : array(); $result = area_pickup($target, array($key => TRUE) + $_asap); if ($result) { $sum[$key] = $result[$key]; if (isset($method[$key]) && $sum[$key] > $method[$key]) { $is_spam[$key] = TRUE; } } } // Area: There's 'BBCode' linking tag if ((!$asap || !$is_spam) && isset($method['area_bbcode'])) { $key = 'area_bbcode'; $_asap = isset($method['asap']) ? array('asap' => TRUE) : array(); $result = area_pickup($target, array($key => TRUE) + $_asap); if ($result) { $sum[$key] = $result[$key]; if (isset($method[$key]) && $sum[$key] > $method[$key]) { $is_spam[$key] = TRUE; } } } // Return if ... if ($asap && $is_spam) { return $progress; } // URI: Pickup $pickups = uri_pickup_normalize(spam_uri_pickup($target, $method)); // Return if ... if (empty($pickups)) { return $progress; } // URI: Check quantity $sum['quantity'] += count($pickups); // URI quantity if ((!$asap || !$is_spam) && isset($method['quantity']) && $sum['quantity'] > $method['quantity']) { $is_spam['quantity'] = TRUE; } // URI: used inside HTML anchor tag pair if ((!$asap || !$is_spam) && isset($method['uri_anchor'])) { $key = 'uri_anchor'; foreach ($pickups as $pickup) { if (isset($pickup['area'][$key])) { $sum[$key] += $pickup['area'][$key]; if (isset($method[$key]) && $sum[$key] > $method[$key]) { $is_spam[$key] = TRUE; if ($asap && $is_spam) { break; } } if ($asap && $is_spam) { break; } } } } // URI: used inside 'BBCode' pair if ((!$asap || !$is_spam) && isset($method['uri_bbcode'])) { $key = 'uri_bbcode'; foreach ($pickups as $pickup) { if (isset($pickup['area'][$key])) { $sum[$key] += $pickup['area'][$key]; if (isset($method[$key]) && $sum[$key] > $method[$key]) { $is_spam[$key] = TRUE; if ($asap && $is_spam) { break; } } if ($asap && $is_spam) { break; } } } } // URI: Uniqueness (and removing non-uniques) if ((!$asap || !$is_spam) && isset($method['non_uniquri'])) { $uris = array(); foreach (array_keys($pickups) as $key) { $uris[$key] = uri_pickup_implode($pickups[$key]); } $count = count($uris); $uris = array_unique($uris); $sum['non_uniquri'] += $count - count($uris); if ($sum['non_uniquri'] > $method['non_uniquri']) { $is_spam['non_uniquri'] = TRUE; } if (!$asap || !$is_spam) { foreach (array_diff(array_keys($pickups), array_keys($uris)) as $remove) { unset($pickups[$remove]); } } unset($uris); } // Return if ... if ($asap && $is_spam) { return $progress; } // Host: Uniqueness (uniq / non-uniq) foreach ($pickups as $pickup) { $hosts[] =& $pickup['host']; } $hosts = array_unique($hosts); $sum['uniqhost'] += count($hosts); if ((!$asap || !$is_spam) && isset($method['non_uniqhost'])) { $sum['non_uniqhost'] = $sum['quantity'] - $sum['uniqhost']; if ($sum['non_uniqhost'] > $method['non_uniqhost']) { $is_spam['non_uniqhost'] = TRUE; } } // Return if ... if ($asap && $is_spam) { return $progress; } // URI: Bad host (Separate good/bad hosts from $hosts) if ((!$asap || !$is_spam) && isset($method['badhost'])) { // is_badhost() $list = get_blocklist('list'); $blocked = blocklist_distiller($hosts, array_keys($list), $asap); foreach ($list as $key => $type) { if (!$type) { unset($blocked[$key]); } // Ignore goodhost etc } unset($list); if (!empty($blocked)) { $is_spam['badhost'] = TRUE; } } return $progress; }
function spam_uri_pickup($string = '', $method = array()) { if (!is_array($method) || empty($method)) { $method = check_uri_spam_method(); } $string = spam_uri_pickup_preprocess($string, $method); $array = uri_pickup($string); // Area elevation of URIs, for '(especially external)link' intension if (!empty($array)) { $_method = array(); if (isset($method['uri_anchor'])) { $_method['uri_anchor'] =& $method['uri_anchor']; } if (isset($method['uri_bbcode'])) { $_method['uri_bbcode'] =& $method['uri_bbcode']; } $areas = area_pickup($string, $_method, TRUE); if (!empty($areas)) { $area_shadow = array(); foreach (array_keys($array) as $key) { $area_shadow[$key] =& $array[$key]['area']; foreach (array_keys($_method) as $_key) { $area_shadow[$key][$_key] = 0; } } foreach (array_keys($_method) as $_key) { if (isset($areas[$_key])) { area_measure($areas[$_key], $area_shadow, 1, $_key); } } } } // Remove 'offset's for area_measure() foreach (array_keys($array) as $key) { unset($array[$key]['area']['offset']); } return $array; }