public function testNsplit() { $this->assertEquals(nsplit("one"), array("one")); $this->assertEquals(nsplit("\n one\n two\n "), array("one", "two")); $this->assertEquals(nsplit("\n "), array()); $this->assertEquals(nsplit(""), array()); }
function normLatin($string) { $oneLetter = <<<END `İ¡¿ÀàÁáÂâÃãÄäÅåÆæçÇÈèÉéÊêËëÌìÍíÎîÏïÐððÑñÒòÓóÔôÕõöÖØøÙùÚúÛûÜüÝýÞþÿŸāĀĂ 'I!?AaAaAaAaAaAaAacCEeEeEeEeIiIiIiIiDdoNnOoOoOoOooOOoUuUuUuUuYyBbyYaAA 㹥ćĆĈĉĊċčČďĎĐđēĒĔĕėĖęĘĘěĚĜĝğĞĠġģĢĤĥĦħĨĩīĪĪĬĭįĮıĴĵķĶĶĸĹĺļĻĽľĿŀłŁńŃņŅňŇ aaAcCCcCccCdDDdeEEeeEeeEeEGggGGggGHhHhIiiiIIiiIiJjkkKkLllLLlLllLnNnNnN ʼnŊŋŌōŎŏŐőŒœŔŕŗřŘśŚŜŝşŞšŠŢţťŤŦŧŨũūŪŪŬŭůŮŰűųŲŴŵŶŷźŹżŻžŽƠơƯưǼǽȘșȚțəƏΐάΆέΈ nNnOoOoOoOoRrrrRsSSssSsSTttTTtUuuuUUuuUUuuUWwYyzZzZzZOoUuAaSsTteEiaAeE ήΉίΊΰαΑβΒγΓδΔεΕζΖηΗθΘιΙκΚλΛμΜνΝξΞοΟπΠρΡςσΣτΤυΥφΦχΧωΩϊΪϋΫόΌύΎώΏјЈћЋ hHiIyaAbBgGdDeEzZhH88iIkKlLmMnN33oOpPrRssStTyYfFxXwWiIyYoOyYwWjjcC أبتجحدرزسصضطفقكلمنهوي abtghdrzssdtfkklmnhoy ẀẁẂẃẄẅẠạẢảẤấẦầẨẩẪẫẬậẮắẰằẲẳẴẵẶặẸẹẺẻẼẽẾếỀềỂểỄễỆệỈỉỊịỌọỎ WwWwWwAaAaAaAaAaAaAaAaAaAaAaAaEeEeEeEeEeEeEeEeIiIiOoO ỏỐốỒồỔổỖỗỘộỚớỜờỞởỠỡỢợỤụỦủỨứỪừỬửỮữỰựỲỳỴỵỶỷỸỹ–—‘’“”• oOoOoOoOoOoOoOoOoOoOoUuUuUuUuUuUuUuYyYyYyYy--''""- END; $oneLetter = nsplit($oneLetter); $split = function ($_) { return preg_split('/(?<!^)(?!$)/u', $_); }; $n = count($oneLetter) / 2; for ($i = 0; $i < $n; $i++) { $string = strtr($string, array_combine($split($oneLetter[$i * 2]), $split($oneLetter[$i * 2 + 1]))); } $twoLetter = array('خ' => 'kh', 'ذ' => 'th', 'ش' => 'sh', 'ظ' => 'th', 'ع' => 'aa', 'غ' => 'gh', 'ψ' => 'ps', 'Ψ' => 'PS', 'đ' => 'dj', 'Đ' => 'Dj', 'ß' => 'ss', 'ẞ' => 'SS', 'Ä' => 'Ae', 'ä' => 'ae', 'Æ' => 'AE', 'æ' => 'ae', 'Ö' => 'Oe', 'ö' => 'oe', 'Ü' => 'Ue', 'ü' => 'ue', 'Þ' => 'TH', 'þ' => 'th', 'ђ' => 'dj', 'Ђ' => 'Dj', 'љ' => 'lj', 'Љ' => 'Lj', 'њ' => 'nj', 'Њ' => 'Nj', 'џ' => 'dz', 'Џ' => 'Dz', 'ث' => 'th', '…' => '...'); return strtr($string, $twoLetter); }
function getUserAgent($re = null, $seed = null) { $LIST = __DIR__ . '/ua.list.txt'; // if (is_array($seed)) { $seed = json_encode($seed); } if ($seed and is_string($seed . '')) { $seed = rand_from_string($seed . ''); } else { $seed = rand_from_string(microtime(true) . ''); } if (!is_file($LIST)) { goto error; } $list = nsplit(file_get_contents($LIST)); if ($re and is_string($re)) { $list = array_values(array_filter($list, function ($line) use($re) { if (preg_match('~^\\w+$~', $re)) { $re = "~{$re}~i"; } return @preg_match($re, $line); })); } if (!$list) { goto error; } $ua = $list[$seed % count($list)]; if ($ua) { return $ua; } error: trigger_error('INVALID UA', E_USER_WARNING); return null; }
function gocron($file, $dir) { if (!is_dir($dir)) { mkdir($dir); } /* * * * * * | | | | | | | | | +----- Дни недели (0-6), 0 - воскресенье | | | +------- Месяцы (1-12) | | +--------- Дни месяца (1-31) | +----------- Часы (0-23) +------------- Минуты (0-59) */ // * - любое значение // 1 - определенное значение // 1-2 - интервал значений // 1,4 - список значений // */2 - четные значения // 1,2-3,*/4 - mix if (is_file($file)) { $crons = nsplit(template($file)); } else { _log(__FUNCTION__ . ": INVALID CRON! | {$file}", E_USER_ERROR); } $time = func_num_args() > 2 ? func_get_arg(2) : time(); $trigger = function ($cron) use($time) { $format = "iHdnw"; for ($i = 0; $i < strlen($format); $i++) { $t = intval(date($format[$i], $time)); foreach (explode(',', $cron[$i]) as $elem) { if ($elem === '*') { continue 2; } if (is_numeric($elem) and $elem == $t) { continue 2; } if (preg_match('~^(\\d+)-(\\d+)$~', $elem, $match) and intval($match[1]) <= $t and $t <= intval($match[2])) { continue 2; } if (preg_match('~^\\*/(\\d+)$~', $elem, $match) and $t % $match[1] === 0) { continue 2; } } return false; } return true; }; foreach ($crons as $cron) { if (strpos($cron, '#') === 0) { continue; } $cron = preg_split('~\\s+~', $cron, 6); if (count($cron) != 6) { continue; } $exec = array_pop($cron); if (!$trigger($cron)) { continue; } $name = preg_split('~\\s+~', $exec); array_walk($name, function (&$_) { if (is_file($_)) { $_ = basename($_); } if (is_dir(dirname($_))) { $_ = basename($_); } }); $name = implode(' ', $name); $std = sprintf("%s/%s.%s.txt", $dir, time(), substr(str_replace(' ', '-', normEn($name)), 0, 255)); shell_exec($_ = sprintf("nohup bash -c %s >%s 2>&1 &", escapeshellarg($exec), escapeshellarg($std))); _log(__FUNCTION__ . ': ' . $_); } }
public static function collectTop($host, $type, $stamp = -30) { $db = self::$db; if (!in_array($type, array('top_all', 'top_serp', 'kws'))) { return; } // STAMP TO UNIXTIME if (is_numeric($stamp) and intval($stamp) <= 0) { $stamp = strtotime("today " . intval($stamp) . " day"); } elseif (is_numeric($stamp) and intval($stamp) > 0) { $stamp = $stamp; } else { $stamp = strtotime($stamp); } $filter = array(); while ($stamp < time()) { $filter[] = date(SQL_FORMAT_DATE, $stamp); $stamp += 24 * 3600; } // $beans = $db->bean('stat')->setFields($type)->search(array('host' => $host, 'stamp' => $filter)); // $collect = array(); foreach ($beans as $bean) { foreach (nsplit($bean[$type]) as $s) { list($int, $value) = explode(', ', $s, 2); if (!$value or !intval($int)) { continue; } if (!isset($collect[$value])) { $collect[$value] = 0; } $collect[$value] += $int; } } arsort($collect); array_walk($collect, function (&$value, $key) { $value = "{$value}, {$key}"; }); $collect = array_values($collect); $collect = array_slice($collect, 0, 1000); $collect = implode("\n", $collect); return $collect; }