function ksort_recursive(&$array) { foreach ($array as &$value) { if (is_array($value)) { ksort_recursive($value); } } return ksort($array); }
function ksort_recursive($arr) { foreach ($arr as $key => $value) { if (is_array($value)) { $arr[$key] = ksort_recursive($value); } } ksort($arr); return $arr; }
function getSyncCache() { if (is_dir(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_user)) { debugLog("StateMachine->getSyncCache: Folder based!"); if (file_exists(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_devid . "_" . $this->_user)) { $content1 = file_get_contents(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_devid . "_" . $this->_user); $content1 = ksort_recursive(unserialize($content1)); } else { $content1 = array(); } $content2 = $this->_readSyncCacheFromFolder(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_user); $content2 = ksort_recursive($content2); if (is_array($res = array_diff_assoc_recursive($content1, $content2))) { debugLog("StateMachine->getSyncCache: array_diff_assoc_recursive result is " . print_r($res, true)); } $this->oldsynccache = $content2; return serialize($content2); } else { if (file_exists(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_devid . "_" . $this->_user)) { debugLog("StateMachine->getSyncCache: File Device User based! (DEPRECIATED SINCE PARALLEL SYNC REQUESTS WILL BREAK FILE CONTENT)"); $content = file_get_contents(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_devid . "_" . $this->_user); $this->oldsynccache = unserialize($content); return $content; } else { if (file_exists(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_devid)) { // just for compatibility to take old cache and apply it for new format debugLog("StateMachine->getSyncCache: File Device based! (DEPRECIATED SINCE MORE THAN ONE USERPROFILE COULD BE CREATED ON SOME DEVICES! i.e. iPhone)"); $content = file_get_contents(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_devid); if (file_put_contents(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_devid . "_" . $this->_user, $content)) { unlink(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_devid); } $this->oldsynccache = unserialize($content); return $content; } else { return false; } } } }
function ksort_recursive(&$array, $sort_flags = SORT_REGULAR) { if (!is_array($array)) { return false; } ksort($array, $sort_flags); foreach ($array as &$arr) { ksort_recursive($arr, $sort_flags); } return true; }