Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include __DIR__.DIRECTORY_SEPARATOR.'parser1.php';
- /**
- * @param string &$output : The output of a print_r call; this parameter is DESTRUCTIVE, and will be set to the remainder
- * of $output which is not parsed.
- * @return mixed : the first parseable element of $output
- */
- function print_r_reverse($output)
- {
- $expecting = 0; // 0=nothing in particular, 1=array open paren '(', 2=array element or close paren ')'
- $lines = explode("\n", $output);
- $result = null;
- $topArray = null;
- $arrayStack = array();
- $matches = null;
- while (!empty($lines) && $result === null) {
- $line = array_shift($lines);
- $trim = trim($line);
- if ($trim == 'Array') {
- if ($expecting == 0) {
- $topArray = array();
- $expecting = 1;
- } else {
- trigger_error("Unknown array.");
- }
- } else if ($expecting == 1 && $trim == '(') {
- $expecting = 2;
- } else if ($expecting == 2 && preg_match('/^\[(.+?)\] \=\>\s*(.*)$/', $trim, $matches)) // array element
- {
- list ($fullMatch, $key, $element) = $matches;
- if (trim($element) == 'Array') {
- $topArray[$key] = array();
- $newTopArray =& $topArray[$key];
- $arrayStack[] =& $topArray;
- $topArray =& $newTopArray;
- $expecting = 1;
- } else {
- $topArray[$key] = $element;
- }
- } else if ($expecting == 2 && $trim == ')') // end current array
- {
- if (empty($arrayStack)) {
- $result = $topArray;
- } else // pop into parent array
- {
- // safe array pop
- $keys = array_keys($arrayStack);
- $lastKey = array_pop($keys);
- $temp =& $arrayStack[$lastKey];
- unset($arrayStack[$lastKey]);
- $topArray =& $temp;
- }
- } else if (!empty($trim)) {
- $result = $line;
- }
- }
- $output = implode("\n", $lines);
- return $result;
- }
- /**
- * @param string $output : The output of a multiple print_r calls, separated by newlines
- * @return mixed[] : parseable elements of $output
- */
- function print_r_reverse_multiple($output)
- {
- $result = array();
- while (($reverse = print_r_reverse($output)) !== NULL) {
- $result[] = $reverse;
- }
- return $result;
- }
- $data = file_get_contents('stat_04.log'); //@todo выбери файл
- $data = preg_split('~-+\s+\d{4}\-\d{2}\-\d{2}\s+\d{2}:\d{2}:\d{2}\s-+~i', $data);
- $t = strtotime('2015-11-04 03:00:00');
- $i = 0;
- foreach ($data as $k => $v) {
- $array = print_r_reverse($v);
- if (isset($array[1]['eventName']) && $array[1]['eventName'] == 'transaction') {
- $array = $array[1];
- if(empty($array['eventParams']['area'])){
- continue;
- }
- if (in_array($array['eventParams']['area'], ['LobbyScreen.CashShopDialogTypeC', 'GameScreen.CashShopDialogTypeC', 'DressUpScreen.CashShopDialogTypeC', 'GameScreen.PrefailDialog'])) {
- $time = strtotime($array['eventTimestamp']);
- if($time <= $t || 1==1) { //@todo укажи лимит времени
- $array['eventParams']['areaName'] = $array['eventParams']['area'];
- unset($array['eventParams']['area']);
- if(in_array($array['userID'],$a_testers)) {
- continue;
- }
- //Переводим строки в другие типы где необходимо
- array_walk_recursive($array, function (&$item, $key) {
- if (preg_match('~[a-z]+Amount~', $key) && !is_array($item)) {
- $item = intval($item);
- } elseif (in_array($key, ['userLevel', 'lastPlayedMission'])) {
- $item = intval($item);
- } elseif (in_array($key, ['isLastMissionFailed'])) {
- $item = (boolean)$item;
- }
- });
- $i ++;
- $eventData = json_encode($array);
- print_r($array).PHP_EOL;
- print_r($eventData).PHP_EOL;
- //sendTrackCurl($eventData);
- //break;
- // echo "<br>";
- //print_r($array);
- }
- }
- }
- }
- echo $i.PHP_EOL;
- function sendTrackCurl( $postFields = array())
- {
- $method = 'post';
- $url = '//collect4448bttns.deltadna.net/collect/api/39942684505533704996456211014308/';
- $customHeaders = array(
- 'Content-Type: application/json'
- );
- $timeOut = 50000*3;
- try {
- if (strpos($url, 'http') === false) {
- $url = 'http:' . $url;
- }
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_HEADER, 0);
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_NOSIGNAL, 1); //Unix|Linux SIGALRM hack (for timeouts less than 1 sec.)
- curl_setopt($curl, CURLOPT_TIMEOUT_MS, $timeOut);
- curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, $timeOut);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- if (sizeof($customHeaders) > 0) {
- curl_setopt($curl, CURLOPT_HTTPHEADER, $customHeaders);
- }
- curl_setopt($curl, CURLOPT_POST, true);
- if (sizeof($postFields) > 0) {
- curl_setopt($curl, CURLOPT_POSTFIELDS, $postFields);
- }
- $result = curl_exec($curl);
- $curl_errno = curl_errno($curl);
- $curl_error = curl_error($curl);
- curl_close($curl);
- if ($curl_errno > 0) {
- throw new \Exception("cURL error ({$curl_errno}): {$curl_error}");
- }
- print_r('OK').PHP_EOL;
- } catch (\Exception $e) {
- /*$sLog = $e->getMessage() . "\n" . $method . ' ' . $url . "\n" .
- "\n" . json_encode($postFields) . "\n" .
- json_encode($customHeaders) . "\n\n";*/
- print_r($e->getMessage()).PHP_EOL;
- print_r($postFields).PHP_EOL;
- print_r($url).PHP_EOL;
- }
- return $result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement