function clientQueryURLCount($peer) { $mypeer = seeddbGetMyPeer(); $request = 'http://' . $peer->getAddress() . '/yacy/query.html' . '?iam=' . $mypeer->getHash() . '&youare=' . $peer->getHash() . '&key=' . '&object=lurlcount' . '&env=' . '&ttl=0'; $result = splitArray(explode("\n", file_get_contents($request)), '='); return $result['response']; }
function corePeerPing($peer) { $key = rand(0, 10000); $db = new db(OPENHELLOS); if (!$db->addSingle(array('key' => $key, 'Hash' => $peer->getHash()))) { die(ERR_YACY_DB_SAVE); } $host = 'http://' . $peer->getAddress() . '/yacy/hello.html'; $args = "key={$key}&seed=" . MYHASH . "&count=20"; $hello = explode("\n", file_get_contents("{$host}?{$args}")); $arr = splitArray(array_slice($hello, 0, 4)); updatePeer($peer->getHash(), $arr['myversion'], $arr['uptime'], $arr['mytype']); updateFromSeeds(array_slice($hello, 5)); }
function splitArray($array, $sep, $row) { if ($row) { unset($array["uuid"]); } if ($array['exploreAllBiomesProgress']) { $array['exploreAllBiomesProgress'] = splitArray(unserialize($array['exploreAllBiomesProgress']), ", ", false); } $inserts = null; foreach ($array as $value) { if ($inserts != null) { $inserts .= $sep; } $inserts .= $value; } return $inserts; }
function getArrayFromSeed($seed) { switch (substr($seed, 0, 1)) { case 'p': $plainlist = substr($seed, 2); break; // plain text // plain text case 'b': $plainlist = base64_decode(substr($seed, 2)); break; // base64-encoded // base64-encoded default: $plainlist = substr($seed, 2); break; } $plainlist = substr($plainlist, 1, -1); // kill '{' on beginning and '}' at the end $arr = splitArray(explode(',', $plainlist), '='); $r = array(); foreach ($arr as $key => $val) { $r[trim($key)] = trim($val); } return $r; }
<?php function splitArray($data = array(), $size) { if (sizeof($data > 0)) { $sliceArray = []; $i = 0; while (sizeof($data) > 0) { for ($j = 0; $j < $size; $j++) { $sliceArray[$i][$j] = array_shift($data); } $i++; } } return $sliceArray; } $bigArray = []; for ($i = 0; $i < 1000; $i++) { $bigArray[$i] = $i; } $newArray = splitArray($bigArray, 200); print sizeof($newArray); print_r($newArray[4]);
function addHotelRoomRatesNew() { try { $roomrates = new HotelRoomRates(); $roomrates->setValues($_REQUEST); $exRateRecord = $roomrates->getAllRatesForDates($roomrates->dateIn(), $roomrates->dateOut(), $roomrates->hotelRoomTypeId()); $exRateRecord1 = ""; $exRateRecord2 = ""; $arraySplit = array(); $room_rate_ids = array(); $allDatesArray2 = array(); $i = 1; $l = 1; foreach ($exRateRecord as $key => $row) { $in_date = $row['date_in']; $out_date = $row['date_out']; $exRoomControlArr[$i] = $row; $strstartdate = strtotime($in_date); $strenddate = strtotime($out_date); $dayDiff = ($strenddate - $strstartdate) / 86400; $j = 0; while ($j <= $dayDiff) { $nextDay = $strstartdate + $j * 86400; $allDatesArray2[$l] = $nextDay; $j++; $l++; } $room_rate_ids[$i] = $row['room_rate_id']; $i++; } if ($allDatesArray2 != "") { $sizeOfADA = sizeof($allDatesArray2); $strOfInputStart = strtotime($roomrates->dateIn()); $strOfRangeStart = $allDatesArray2[1]; $strOfInputEnd = strtotime($roomrates->dateOut()); $strOfRangeEnd = $allDatesArray2[$sizeOfADA]; $m = 1; $n = 1; $o = 1; if ($strOfInputStart < $strOfRangeStart) { $differenceOf = ($strOfRangeStart - $strOfInputStart) / 86400; $x = 0; $start = $strOfInputStart; while ($x < $differenceOf) { $nxday = $start + $x * 86400; array_push($allDatesArray2, $nxday); $x++; } if ($strOfInputEnd > $strOfRangeEnd) { $y = 1; $differenceOfB = ($strOfInputEnd - $strOfRangeEnd) / 86400; while ($y <= $differenceOfB) { $nxday2 = $strOfRangeEnd + $y * 86400; array_push($allDatesArray2, $nxday2); $y++; } } array_multisort($allDatesArray2); $arraySplit = splitArray($allDatesArray2, $m, $n, $o, $strOfInputStart, $strOfInputEnd); $roomrates->ratesDeleteByRateId($room_rate_ids); if (!addHotelRoomRates($roomrates)) { throw new Exception("Error"); new Exception("Error"); } if (array_key_exists(3, $arraySplit)) { $szOfArray = sizeof($arraySplit[3]); $fDate = date("Y-m-d", $arraySplit[3][1]); $tDate = date("Y-m-d", $arraySplit[3][$szOfArray]); $exRateRecord2 = $row; $exRateRecord2['date_in'] = $fDate; $exRateRecord2['date_out'] = $tDate; if (!addHotelRoomRates($exRateRecord2)) { throw new Exception("Error"); } } } else { if ($strOfInputEnd > $strOfRangeEnd) { $y = 1; $differenceOfB = ($strOfInputEnd - $strOfRangeEnd) / 86400; while ($y <= $differenceOfB) { $nxday2 = $strOfRangeEnd + $y * 86400; array_push($allDatesArray2, $nxday2); $y++; } } array_multisort($allDatesArray2); $arraySplit = splitArray($allDatesArray2, $m, $n, $o, $strOfInputStart, $strOfInputEnd); if (!$roomrates->ratesDeleteByRateId($room_rate_ids)) { throw new Exception("Error"); } if (array_key_exists(1, $arraySplit)) { $szOfArray = sizeof($arraySplit[1]); $fDate = date("Y-m-d", $arraySplit[1][1]); $tDate = date("Y-m-d", $arraySplit[1][$szOfArray]); $exRateRecord1 = $row; $exRateRecord1['date_in'] = $fDate; $exRateRecord1['date_out'] = $tDate; if (!addHotelRoomRates($exRateRecord1)) { throw new Exception("Error"); } if (!addHotelRoomRates($roomrates)) { throw new Exception("Error"); } if (array_key_exists(3, $arraySplit)) { $szOfArray = sizeof($arraySplit[3]); $fDate = date("Y-m-d", $arraySplit[3][1]); $tDate = date("Y-m-d", $arraySplit[3][$szOfArray]); $exRateRecord2 = $row; $exRateRecord2['date_in'] = $fDate; $exRateRecord2['date_out'] = $tDate; if (!addHotelRoomRates($exRateRecord2)) { throw new Exception("Error"); } } } else { $arraySplit = splitArray($allDatesArray2, $m, $n, $o, $strOfInputStart, $strOfInputEnd); if (!$roomrates->ratesDeleteByRateId($room_rate_ids)) { throw new Exception("Error"); } if (!addHotelRoomRates($roomrates)) { throw new Exception("Error"); } if (array_key_exists(3, $arraySplit)) { $szOfArray = sizeof($arraySplit[3]); $fDate = date("Y-m-d", $arraySplit[3][1]); $tDate = date("Y-m-d", $arraySplit[3][$szOfArray]); $exRateRecord2 = $row; $exRateRecord2['date_in'] = $fDate; $exRateRecord2['date_out'] = $tDate; if (!addHotelRoomRates($exRateRecord2)) { throw new Exception("Error"); } } } } } else { if (!addHotelRoomRates($roomrates)) { throw new Exception("Error"); } } $complete = new ProfileCompletion(); $complete->setHotelStepId($_REQUEST['hotel_step_id']); $complete->setHotelStep1(1); $complete->updateProfileCompletionStep('6'); Common::jsonSuccess("Room Rates Added Successfully!"); } catch (Exception $ex) { Common::jsonError("Error"); } }