コード例 #1
1
ファイル: Arrays.php プロジェクト: egalink/fastener
 /**
  * Recursive array unique for multiarrays like array_unique PHP function:
  *
  * @param  array $array
  * @return array
  */
 function array_unique_recursive(array $array)
 {
     $result = array_map("serialize", $array);
     $result = array_map("unserialize", array_unique($result));
     foreach ($result as $key => $value) {
         if (is_array($value) === true) {
             $result[$key] = array_unique_recursive($value);
         }
     }
     return $result;
 }
コード例 #2
0
 /**
  * Recorre cada uno de los registros de la colección
  * y recupera unicamente los que tengan todos los datos válidos.
  *
  * @access protected
  * @param  RowCollection $collection
  * @return array
  */
 protected function recuperaValidos(RowCollection $collection)
 {
     $validos = array();
     foreach ($collection->toArray() as $k => $r) {
         $validation = $this->valdarFila($r);
         if ($validation->passes() === true) {
             $validos[] = $r;
         }
     }
     return array_unique_recursive($validos);
 }
コード例 #3
0
ファイル: spam.php プロジェクト: orangeal2o3/pukiwiki-plugin
function array_merge_leaves(&$array1, &$array2, $unique_values = TRUE, $renumber_numeric = TRUE)
{
    $array = array_merge_recursive($array1, $array2);
    // Redundant values (and keys) are vanished
    if ($unique_values) {
        $array = array_unique_recursive($array);
    }
    // All NUMERIC keys are always renumbered from 0
    if ($renumber_numeric) {
        array_renumber_numeric_keys($array);
    }
    return $array;
}
コード例 #4
0
ファイル: spam.php プロジェクト: aterai/pukiwiki-plus-i18n
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 (!isset($sum['quantity'])) {
        $sum['quantity'] = 0;
    }
    // ----------------------------------------
    // Recurse
    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);
            $hosts = array_merge_leaves($hosts, $_progress['hosts'], FALSE);
        }
        // Unique values
        $blocked = array_unique_recursive($blocked);
        $hosts = array_unique_recursive($hosts);
        // Recount $sum['badhost']
        $sum['badhost'] = array_count_leaves($blocked);
        return $progress;
    }
    // ----------------------------------------
    // Area measure
    // 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
    $tmp_pickups = spam_uri_pickup($target, $method);
    $pickups = uri_pickup_normalize($tmp_pickups);
    unset($tmp_pickups);
    $hosts = array();
    foreach ($pickups as $key => $pickup) {
        $hosts[$key] =& $pickup['host'];
    }
    // Return if ...
    if (empty($pickups)) {
        return $progress;
    }
    // ----------------------------------------
    // URI: Bad host <pre-filter> (Separate good/bad hosts from $hosts)
    if ((!$asap || !$is_spam) && isset($method['badhost'])) {
        $list = get_blocklist('pre');
        $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 if ...
    if ($asap && $is_spam) {
        return $progress;
    }
    // Remove blocked from $pickups
    foreach (array_keys($pickups) as $key) {
        if (!isset($hosts[$key])) {
            unset($pickups[$key]);
        }
    }
    // ----------------------------------------
    // 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)
    $hosts = array_unique($hosts);
    if (isset($sum['uniqhost'])) {
        $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'])) {
        $list = get_blocklist('list');
        $blocked = array_merge_leaves($blocked, blocklist_distiller($hosts, array_keys($list), $asap), FALSE);
        foreach ($list as $key => $type) {
            if (!$type) {
                unset($blocked[$key]);
            }
            // Ignore goodhost etc
        }
        unset($list);
        if (!empty($blocked)) {
            $is_spam['badhost'] = TRUE;
        }
    }
    // Return if ...
    //if ($asap && $is_spam) return $progress;
    // ----------------------------------------
    // End
    return $progress;
}
コード例 #5
0
ファイル: ReaderController.php プロジェクト: egalink/fastener
 /**
  * Recorre cada uno de los registros de la colección
  * y recupera unicamente los que tengan todos los datos válidos.
  *
  * @access protected
  * @param  RowCollection $collection
  * @return array
  */
 protected function getValid(RowCollection $collection)
 {
     $validated = array();
     foreach ($collection->toArray() as $k => $r) {
         if ($this->validateSingleRow($r)->passes() === true) {
             $validated[] = $r;
         }
     }
     return array_unique_recursive($validated);
 }
コード例 #6
0
ファイル: EmailController.php プロジェクト: egalink/fastener
 /**
  * Extrae los valores serializados a partir de un arreglo de expresiones
  * serializadas eliminando valores duplicados.
  *
  * @access protected
  * @param  array  $seriales
  * @return array
  */
 protected function unserializeUnique(array $seriales)
 {
     $datos = array();
     foreach ($seriales as $key => $val) {
         if ($array = unserialize($val)) {
             $datos = array_merge($datos, $array);
         }
     }
     return array_unique_recursive($datos);
     // eliminamos valores repetidos.
 }