'/page/home', ); $config['zarinpal']['merchantId'] = ''; $config['zarinpal']['sandBox'] = false; ?> $daysInMonth[$month - 1]) { $days -= $daysInMonth[$month - 1]; $month++; if ($month == 13) { $year++; if (($year - 1347) % 4 == 0) { $days--; } $month = 1; } } else { break; } } $month = twoDigitNumber($month); $days = twoDigitNumber($days); $output = $format; $output = str_replace("Y", $year, $output); $output = str_replace("m", $month, $output); $output = str_replace("d", $days, $output); return $output; } function generateHash($length = 32) { $characters = '2345679acdefghijkmnpqrstuvwxyz'; $charactersLenght = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLenght - 1)]; } return $randomString; } function generateFileName($length = 32) { $characters = 'acdefghijkmnpqrstuvwxyz'; $charactersLenght = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLenght - 1)]; } return $randomString; } function generateCode($length = 6) { $characters = '23456789'; $charactersLenght = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLenght - 1)]; } return $randomString; } function getTimeInMilliseconds() { return round(microtime(true) * 1000); } function post($field, $default = null) { if (isset($_POST[$field])) { return $_POST[$field]; } return $default; } function getFileFromFormData($field, $default = null) { if (isset($_FILES[$field])) { return $_FILES[$field]; } return $default; } function isJson($string) { json_decode($string); return (json_last_error() == JSON_ERROR_NONE); } function getRawInputParams() { //Make sure that it is a POST request. if (strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0) { failureResult(REQUEST_MUST_BE_POST_EC, REQUEST_MUST_BE_POST); } //Make sure that the content type of the POST request has been set to application/json $contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : ''; if (!strHas($contentType, 'application/json', true)) { failureResult(CONTENT_TYPE_MUST_BE_APPLICATION_JSON_EC, CONTENT_TYPE_MUST_BE_APPLICATION_JSON); } //Receive the RAW post data. $content = trim(file_get_contents("php://input")); //Attempt to decode the incoming RAW post data from JSON. $decoded = json_decode($content); //If json_decode failed, the JSON is invalid. if (json_last_error() != JSON_ERROR_NONE) { failureResult(INVALID_JSON_EC, INVALID_JSON); } return $decoded; } function checkFormDataInputParams() { //Make sure that it is a POST request. if (strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0) { failureResult(REQUEST_MUST_BE_POST_EC, REQUEST_MUST_BE_POST); } //Make sure that the content type of the POST request has been set to multipart/form-data $contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : ''; if (!strHas($contentType, 'multipart/form-data', true)) { failureResult(CONTENT_TYPE_MUST_BE_MULTI_PART_FORM_DATA_EC, CONTENT_TYPE_MUST_BE_MULTI_PART_FORM_DATA); } } function getInputValue($params, $key, $default = null) { if (array_key_exists($key, $params == null ? array() : json_decode(json_encode($params), true))) { return $params->{$key}; } return $default; } function isNullOrEmptyString($str) { return (!isset($str) || trim($str) === ''); } function isMobileNumber($mobileNumber) { if ($mobileNumber == null) return false; return preg_match('/^[0][9]([0-9]){9}+$/', $mobileNumber); } function isValidVerificationCode($activationCode) { if ($activationCode == null) return false; return preg_match('/^[0-9]{4}+$/', $activationCode); } function hasParameters() { foreach (func_get_args() as $param) { if ($param == null) { return false; } } return true; } /*function failureResult($errorCode, $errorMessage, $mustExit = true) { $result = array( RESULT => false, ERROR_CODE => $errorCode, ERROR_MESSAGE => $errorMessage ); echo json_encode($result); if ($mustExit) exit; }*/ function failureResult($errorCode, $errorMessage, $mustExit = true, $responseCode = 200, $extraParams = array()) { if ($responseCode != 200) { http_response_code($responseCode); } $result = array( RESULT => false, ERROR_CODE => $errorCode, ERROR_MESSAGE => $errorMessage, EXTRA_PARAMS => $extraParams ); echo json_encode($result); if ($mustExit) exit; } function successResult($data = null, $mustExit = true) { $result = array( RESULT => true, DATA => $data == null ? array() : array($data) ); echo json_encode($result); if ($mustExit) exit; } function utf8($string) { return urldecode($string); } function checkUser($token) { $user = UserModel::fetchUserByToken($token); if ($user == null) { failureResult(NO_SUCH_USER_EC, NO_SUCH_USER); } if (!$user[COLUMN_IS_VERIFIED]) { failureResult(USER_IS_NOT_VERIFIED_EC, USER_IS_NOT_VERIFIED); } if (!$user[COLUMN_IS_ACTIVE]) { failureResult(USER_IS_NOT_ACTIVE_EC, USER_IS_NOT_ACTIVE); } return $user; } function checkCover($coverId) { $cover = CoverModel::fetchCover($coverId); if ($cover == null) { failureResult(NO_SUCH_COVER_EC, NO_SUCH_COVER); } if (!$cover[COLUMN_IS_ACTIVE]) { failureResult(COVER_IS_NOT_ACTIVE_EC, COVER_IS_NOT_ACTIVE); } return $cover; } function checkNews($newsId) { $news = NewsModel::fetchNews($newsId); if ($news == null) { failureResult(NO_SUCH_NEWS_EC, NO_SUCH_NEWS); } if (!$news[COLUMN_IS_ACTIVE]) { failureResult(NEWS_IS_NOT_ACTIVE_EC, NEWS_IS_NOT_ACTIVE); } return $news; } function checkLineNews($newsId) { $news = LineNewsModel::fetchNews($newsId); if ($news == null) { failureResult(NO_SUCH_NEWS_EC, NO_SUCH_NEWS); } if (!$news[COLUMN_IS_ACTIVE]) { failureResult(NEWS_IS_NOT_ACTIVE_EC, NEWS_IS_NOT_ACTIVE); } return $news; } function isAdmin($token) { $admin = AdminModel::fetchAdminByToken($token); if ($admin == null) { failureResult(ACCESS_DENIED_EC, ACCESS_DENIED); } return $admin; } function checkCounty($countyId) { $county = CountyModel::fetchCounty($countyId); if ($county == null) { failureResult(NO_SUCH_COUNTY_EC, NO_SUCH_COUNTY); } if (!$county[COLUMN_IS_ACTIVE]) { failureResult(COUNTY_IS_NOT_ACTIVE_EC, COUNTY_IS_NOT_ACTIVE); } return $county; } function checkCity($cityId) { $city = CityModel::fetchCity($cityId); if ($city == null) { failureResult(NO_SUCH_CITY_EC, NO_SUCH_CITY); } if (!$city[COLUMN_IS_ACTIVE]) { failureResult(CITY_IS_NOT_ACTIVE_EC, CITY_IS_NOT_ACTIVE); } return $city; } function checkAge($ageId) { $age = AgeModel::fetchAge($ageId); if ($age == null) { failureResult(NO_SUCH_AGE_EC, NO_SUCH_AGE); } if (!$age[COLUMN_IS_ACTIVE]) { failureResult(AGE_IS_NOT_ACTIVE_EC, AGE_IS_NOT_ACTIVE); } return $age; } function checkSurveyTitle($surveyTitleId) { $surveyTitle = PlaceSurveyModel::fetchSurveyTitle($surveyTitleId); if ($surveyTitle == null) { failureResult(NO_SUCH_SURVEY_TITLE_EC, NO_SUCH_SURVEY_TITLE); } if (!$surveyTitle[COLUMN_IS_ACTIVE]) { failureResult(SURVEY_TITLE_IS_NOT_ACTIVE_EC, SURVEY_TITLE_IS_NOT_ACTIVE); } return $surveyTitle; } function checkFoodPlaceLocation($locationId) { $location = FoodPlaceLocationModel::fetchType($locationId); if ($location == null) { failureResult(NO_SUCH_FOOD_PLACE_LOCATION_EC, NO_SUCH_FOOD_PLACE_LOCATION); } if (!$location[COLUMN_IS_ACTIVE]) { failureResult(FOOD_PLACE_LOCATION_IS_NOT_ACTIVE_EC, FOOD_PLACE_LOCATION_IS_NOT_ACTIVE); } return $location; } function checkFoodPlaceType($typeId) { $type = FoodPlaceTypeModel::fetchType($typeId); if ($type == null) { failureResult(NO_SUCH_FOOD_PLACE_TYPE_EC, NO_SUCH_FOOD_PLACE_TYPE); } if (!$type[COLUMN_IS_ACTIVE]) { failureResult(FOOD_PLACE_TYPE_IS_NOT_ACTIVE_EC, FOOD_PLACE_TYPE_IS_NOT_ACTIVE); } return $type; } function checkTourismServiceType($typeId) { $type = TourismServiceTypeModel::fetchType($typeId); if ($type == null) { failureResult(NO_SUCH_TOURISM_SERVICE_PLACE_TYPE_EC, NO_SUCH_TOURISM_SERVICE_PLACE_TYPE); } if (!$type[COLUMN_IS_ACTIVE]) { failureResult(TOURISM_SERVICE_PLACE_TYPE_IS_NOT_ACTIVE_EC, TOURISM_SERVICE_PLACE_TYPE_IS_NOT_ACTIVE); } return $type; } function checkTravelAgencyService($serviceId) { $service = TravelAgencyServiceModel::fetchService($serviceId); if ($service == null) { failureResult(NO_SUCH_TRAVEL_AGENCY_SERVICE_EC, NO_SUCH_TRAVEL_AGENCY_SERVICE); } if (!$service[COLUMN_IS_ACTIVE]) { failureResult(TRAVEL_AGENCY_SERVICE_IS_NOT_ACTIVE_EC, TRAVEL_AGENCY_SERVICE_IS_NOT_ACTIVE); } return $service; } function checkComplexServiceFeature($featureId) { $feature = ComplexServiceFeatureModel::fetchFeature($featureId); if ($feature == null) { failureResult(NO_SUCH_COMPLEX_SERVICE_FEATURE_EC, NO_SUCH_COMPLEX_SERVICE_FEATURE); } if (!$feature[COLUMN_IS_ACTIVE]) { failureResult(COMPLEX_SERVICE_FEATURE_IS_NOT_ACTIVE_EC, COMPLEX_SERVICE_FEATURE_IS_NOT_ACTIVE); } return $feature; } function checkResidentPlaceType($typeId) { $type = ResidentPlaceTypeModel::fetchType($typeId); if ($type == null) { failureResult(NO_SUCH_RESIDENT_PLACE_TYPE_EC, NO_SUCH_RESIDENT_PLACE_TYPE); } if (!$type[COLUMN_IS_ACTIVE]) { failureResult(RESIDENT_PLACE_TYPE_IS_NOT_ACTIVE_EC, RESIDENT_PLACE_TYPE_IS_NOT_ACTIVE); } return $type; } function checkResidentPlaceReserveStatus($reserveStatusId) { $reserveStatus = ResidentPlaceReserveStatusModel::fetchReserveStatus($reserveStatusId); if ($reserveStatus == null) { failureResult(NO_SUCH_RESIDENT_PLACE_RESERVE_STATUS_EC, NO_SUCH_RESIDENT_PLACE_RESERVE_STATUS); } if (!$reserveStatus[COLUMN_IS_ACTIVE]) { failureResult(RESIDENT_PLACE_RESERVE_STATUS_IS_NOT_ACTIVE_EC, RESIDENT_PLACE_RESERVE_STATUS_IS_NOT_ACTIVE); } return $reserveStatus; } function checkResidentPlaceView($viewId) { $view = ResidentPlaceViewModel::fetchView($viewId); if ($view == null) { failureResult(NO_SUCH_RESIDENT_PLACE_VIEW_EC, NO_SUCH_RESIDENT_PLACE_VIEW); } if (!$view[COLUMN_IS_ACTIVE]) { failureResult(RESIDENT_PLACE_VIEW_IS_NOT_ACTIVE_EC, RESIDENT_PLACE_VIEW_IS_NOT_ACTIVE); } return $view; } function checkFoodPlaceView($viewId) { $view = FoodPlaceViewModel::fetchView($viewId); if ($view == null) { failureResult(NO_SUCH_FOOD_PLACE_VIEW_EC, NO_SUCH_FOOD_PLACE_VIEW); } if (!$view[COLUMN_IS_ACTIVE]) { failureResult(FOOD_PLACE_VIEW_IS_NOT_ACTIVE_EC, FOOD_PLACE_VIEW_IS_NOT_ACTIVE); } return $view; } function checkResidentPlaceFeature($featureId) { $feature = ResidentPlaceFeatureModel::fetchFeature($featureId); if ($feature == null) { failureResult(NO_SUCH_RESIDENT_PLACE_FEATURE_EC, NO_SUCH_RESIDENT_PLACE_FEATURE); } if (!$feature[COLUMN_IS_ACTIVE]) { failureResult(RESIDENT_PLACE_FEATURE_IS_NOT_ACTIVE_EC, RESIDENT_PLACE_FEATURE_IS_NOT_ACTIVE); } return $feature; } function checkFoodPlaceMeel($meelId) { if ($meelId != 1 && $meelId != 2 && $meelId != 3) { failureResult(NO_SUCH_FOOD_PLACE_MEEL_EC, NO_SUCH_FOOD_PLACE_MEEL); } } function checkFoodPlaceFeature($featureId) { $feature = FoodPlaceFeatureModel::fetchFeature($featureId); if ($feature == null) { failureResult(NO_SUCH_FOOD_PLACE_FEATURE_EC, NO_SUCH_FOOD_PLACE_FEATURE); } if (!$feature[COLUMN_IS_ACTIVE]) { failureResult(FOOD_PLACE_FEATURE_IS_NOT_ACTIVE_EC, FOOD_PLACE_FEATURE_IS_NOT_ACTIVE); } return $feature; } function checkPlaceType($placeTypeId) { $placeType = PlaceTypeModel::fetchPlaceType($placeTypeId); if ($placeType == null) { failureResult(NO_SUCH_PLACE_TYPE_EC, NO_SUCH_PLACE_TYPE); } if (!$placeType[COLUMN_IS_ACTIVE]) { failureResult(PLACE_TYPE_IS_NOT_ACTIVE_EC, PLACE_TYPE_IS_NOT_ACTIVE); } return $placeType; } function checkSeason($seasonId) { $season = SeasonModel::fetchSeason($seasonId); if ($season == null) { failureResult(NO_SUCH_SEASON_EC, NO_SUCH_SEASON); } if (!$season[COLUMN_IS_ACTIVE]) { failureResult(SEASON_IS_NOT_ACTIVE_EC, SEASON_IS_NOT_ACTIVE); } return $season; } function checkPlace($placeId) { $place = PlaceModel::fetchPlace($placeId); if ($place == null) { failureResult(NO_SUCH_PLACE_EC, NO_SUCH_PLACE); } if (!$place[COLUMN_IS_ACTIVE]) { failureResult(PLACE_IS_NOT_ACTIVE_EC, PLACE_IS_NOT_ACTIVE); } return $place; } function checkResidentPlace($placeId) { $place = ResidentPlaceModel::fetchPlace($placeId); if ($place == null) { failureResult(NO_SUCH_PLACE_EC, NO_SUCH_PLACE); } if (!$place[COLUMN_IS_ACTIVE]) { failureResult(PLACE_IS_NOT_ACTIVE_EC, PLACE_IS_NOT_ACTIVE); } return $place; } function checkFoodPlace($placeId) { $place = FoodPlaceModel::fetchPlace($placeId); if ($place == null) { failureResult(NO_SUCH_PLACE_EC, NO_SUCH_PLACE); } if (!$place[COLUMN_IS_ACTIVE]) { failureResult(PLACE_IS_NOT_ACTIVE_EC, PLACE_IS_NOT_ACTIVE); } return $place; } function checkTourismService($placeId) { $place = TourismServiceModel::fetchPlace($placeId); if ($place == null) { failureResult(NO_SUCH_PLACE_EC, NO_SUCH_PLACE); } if (!$place[COLUMN_IS_ACTIVE]) { failureResult(PLACE_IS_NOT_ACTIVE_EC, PLACE_IS_NOT_ACTIVE); } return $place; } function checkClickableText($clickableTextId) { $clickableText = ClickableTextModel::fetchClickableText($clickableTextId); if ($clickableText == null) { failureResult(NO_SUCH_CLICKABLE_TEXT_EC, NO_SUCH_CLICKABLE_TEXT_EC); } if (!$clickableText[COLUMN_IS_ACTIVE]) { failureResult(PLACE_IS_NOT_ACTIVE_EC, PLACE_IS_NOT_ACTIVE); } return $clickableText; } function checkUserWithId($userId) { $user = UserModel::fetchUserByUserId($userId); if ($user == null) { failureResult(NO_SUCH_USER_EC, NO_SUCH_USER); } if (!$user[COLUMN_IS_VERIFIED]) { failureResult(USER_IS_NOT_VERIFIED_EC, USER_IS_NOT_VERIFIED); } if (!$user[COLUMN_IS_ACTIVE]) { failureResult(USER_IS_NOT_ACTIVE_EC, USER_IS_NOT_ACTIVE); } return $user; } function getDateFromMillis($seconds) { return date("Y-m-d", $seconds / 1000); } function getPlaceDir($photoName) { $fileExtention = pathinfo($photoName, PATHINFO_EXTENSION); $targetFileName = generateFileName(16) . getTimeInMilliseconds(); $targetdir = '/image/place/' . $targetFileName . "." . $fileExtention; return $targetdir; } function getCoverDir($photoName) { $fileExtention = pathinfo($photoName, PATHINFO_EXTENSION); $targetFileName = generateFileName(16) . getTimeInMilliseconds(); $targetdir = '/image/cover/' . $targetFileName . "." . $fileExtention; return $targetdir; } function getNewsDir($photoName) { $fileExtention = pathinfo($photoName, PATHINFO_EXTENSION); $targetFileName = generateFileName(16) . getTimeInMilliseconds(); $targetdir = '/image/news/' . $targetFileName . "." . $fileExtention; return $targetdir; } function getUserImageDir($photoName) { $fileExtention = pathinfo($photoName, PATHINFO_EXTENSION); $targetFileName = generateFileName(16) . getTimeInMilliseconds(); $targetdir = '/image/user/' . $targetFileName . "." . $fileExtention; return $targetdir; } function getPlaceMultimediaDir($placeId, $photoName) { $fileExtention = pathinfo($photoName, PATHINFO_EXTENSION); $targetFileName = generateFileName(16) . getTimeInMilliseconds(); $targetdir = '/image/place/' . $placeId . "_" . $targetFileName . "." . $fileExtention; return $targetdir; } function getPlaceMultimediaVideoDir($placeId, $photoName) { $fileExtention = pathinfo($photoName, PATHINFO_EXTENSION); $targetFileName = generateFileName(16) . getTimeInMilliseconds(); $targetdir = '/video/place/' . $placeId . "_" . $targetFileName . "." . $fileExtention; return $targetdir; } function getPlaceMultimediaVoiceDir($placeId, $photoName) { $fileExtention = pathinfo($photoName, PATHINFO_EXTENSION); $targetFileName = generateFileName(16) . getTimeInMilliseconds(); $targetdir = '/voice/place/' . $placeId . "_" . $targetFileName . "." . $fileExtention; return $targetdir; } function getStateVideoDir($state, $photoName) { $fileExtention = pathinfo($photoName, PATHINFO_EXTENSION); $targetFileName = generateFileName(16) . getTimeInMilliseconds(); $targetdir = '/video/state/' . $state[COLUMN_STATE_ID] . "_" . $targetFileName . "." . $fileExtention; return $targetdir; } function getThumbnailDir($photoDir) { $fileExtention = pathinfo($photoDir, PATHINFO_EXTENSION); $fileName = pathinfo($photoDir, PATHINFO_FILENAME); $fileDirectory = pathinfo($photoDir, PATHINFO_DIRNAME); $targetdir = $fileDirectory . "/tbn_" . $fileName . "." . $fileExtention; return $targetdir; } function getThumbnailDirForVideo($videoDir, $fileExtention) { $fileName = pathinfo($videoDir, PATHINFO_FILENAME); $fileDirectory = pathinfo($videoDir, PATHINFO_DIRNAME); $targetdir = $fileDirectory . "/tbn_" . $fileName . "." . $fileExtention; return $targetdir; } function uploadFile($sourceFile, $targetdir) { $targetDirectory = getcwd() . $targetdir; if (!is_uploaded_file($sourceFile)) { return null; } if (move_uploaded_file($sourceFile, $targetDirectory)) { // file uploaded succeeded return $targetdir; } else { // file upload failed return null; } } function stringStartWith($string, $query) { return substr($string, 0, strlen($query)) === $query; } function haversineGreatCircleDistance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $earthRadius = 6371000) { // convert from degrees to radians $latFrom = deg2rad($latitudeFrom); $lonFrom = deg2rad($longitudeFrom); $latTo = deg2rad($latitudeTo); $lonTo = deg2rad($longitudeTo); $latDelta = $latTo - $latFrom; $lonDelta = $lonTo - $lonFrom; $angle = 2 * asin(sqrt(pow(sin($latDelta / 2), 2) + cos($latFrom) * cos($latTo) * pow(sin($lonDelta / 2), 2))); return $angle * $earthRadius; } function sortBy($field, &$array, $direction = 'asc') { usort($array, function($a, $b) use ($field,$direction) { $a = $a[$field]; $b = $b[$field]; if ($a == $b) { return 0; } return (($direction == 'desc' ? $a > $b : $a < $b)) ? -1 : 1; }); return true; } function persionSortBy($field, &$array, $direction = 'asc') { usort($array, function($a, $b) use ($field) { $a = $a[$field]; $b = $b[$field]; $charOrder = ['آ','ا', 'ب', 'پ', 'ت', 'ث', 'ج', 'چ', 'ح', 'خ', 'د', 'ذ', 'ر', 'ز', 'ژ', 'س', 'ش', 'ص', 'ض', 'ط', 'ظ', 'ع', 'غ', 'ف', 'ق', 'ک', 'گ', 'ل', 'م', 'ن', 'و', 'ه', 'ی']; $a = mb_strtolower($a); $b = mb_strtolower($b); for($i=0;$i $valB) return 1; return -1; } if(mb_strlen($a) == mb_strlen($b)) return 0; if(mb_strlen($a) > mb_strlen($b)) return -1; return 1; }); return true; } function customSort($a, $b) { $charOrder = ['ا', 'ب', 'پ', 'ت', 'ث', 'ج', 'چ', 'ح', 'خ', 'د', 'ذ', 'ر', 'ز', 'ژ', 'س', 'ش', 'ص', 'ض', 'ط', 'ظ', 'ع', 'غ', 'ف', 'ق', 'ک', 'گ', 'ل', 'م', 'ن', 'و', 'ه', 'ی']; $a = mb_strtolower($a); $b = mb_strtolower($b); for ($i = 0; $i < mb_strlen($a) && $i < mb_strlen($b); $i++) { $chA = mb_substr($a, $i, 1); $chB = mb_substr($b, $i, 1); $valA = array_search($chA, $charOrder); $valB = array_search($chB, $charOrder); if ($valA == $valB) continue; if ($valA > $valB) return 1; return -1; } if (mb_strlen($a) == mb_strlen($b)) return 0; if (mb_strlen($a) > mb_strlen($b)) return -1; return 1; } function persianSort($input_arr, $function = "asort") { $converted = $result = array(); $alphabet = array( '$A$' => "۰", '$B$' => "۱", '$C$' => "۲", '$D$' => "۳", '$E$' => "۴", '$F$' => "۵", '$G$' => "۶", '$H$' => "۷", '$I$' => "۸", '$J$' => "۹", '$K$' => "آ", '$L$' => "ا", '$M$' => "أ", '$N$' => "إ", '$O$' => "ؤ", '$P$' => "ئ", '$Q$' => "ء", '$R$' => "ب", '$S$' => "پ", '$T$' => "ت", '$U$' => "ث", '$V$' => "ج", '$W$' => "چ", '$X$' => "ح", '$Y$' => "خ", '$Z$' => "د", '$a$' => "ذ", '$b$' => "ر", '$c$' => "ز", '$d$' => "ژ", '$e$' => "س", '$f$' => "ش", '$g$' => "ص", '$h$' => "ض", '$i$' => "ط", '$j$' => "ظ", '$k$' => "ع", '$l$' => "غ", '$m$' => "ف", '$n$' => "ق", '$o$' => "ک", '$p$' => "گ", '$q$' => "ل", '$r$' => "م", '$s$' => "ن", '$t$' => "و", '$u$' => "ه", '$v$' => "ی", '$w$' => "ي", '$x$' => "ۀ", '$y$' => "ة" ); foreach ($input_arr as $input_key => $input_str) { if (is_string($input_str)) { foreach ($alphabet as $e_letter => $f_letter) { $input_str = str_replace($f_letter, $e_letter, $input_str); } } if (is_array($input_str)) { $input_str = persianSort($input_str, $function); } $converted[$input_key] = $input_str; } $ret = $function($converted); // Run function $converted = is_array($ret) ? $ret : $converted; // Check for function output. Some functions affect input itself and retuen bool... foreach ($converted as $converted_key => $converted_str) { if (is_string($converted_str)) { foreach ($alphabet as $e_letter => $f_letter) { $converted_str = str_replace($e_letter, $f_letter, $converted_str); } } if (is_array($converted_str)) { $converted_str = persianSort($converted_str, $function); } $result[$converted_key] = $converted_str; } return $result; } function ymdOfDays($diference) { $years = ($diference / 365); // days / 365 days $years = floor($years); // Remove all decimals $month = ($diference % 365) / 30.5; // I choose 30.5 for Month (30,31) ;) $month = round($month); // Remove all decimals $days = ($diference % 365) % 30.5; // the rest of days $data = array(); $data['year'] = $years; $data['month'] = $month; $data['day'] = $days; return $data; } function hijri2Greg($day, $month, $year, $string = false) { $day = (int)$day; $month = (int)$month; $year = (int)$year; $jd = intPart((11 * $year + 3) / 30) + 354 * $year + 30 * $month - intPart(($month - 1) / 2) + $day + 1948440 - 385; if ($jd > 2299160) { $l = $jd + 68569; $n = intPart((4 * $l) / 146097); $l = $l - intPart((146097 * $n + 3) / 4); $i = intPart((4000 * ($l + 1)) / 1461001); $l = $l - intPart((1461 * $i) / 4) + 31; $j = intPart((80 * $l) / 2447); $day = $l - intPart((2447 * $j) / 80); $l = intPart($j / 11); $month = $j + 2 - 12 * $l; $year = 100 * ($n - 49) + $i + $l; } else { $j = $jd + 1402; $k = intPart(($j - 1) / 1461); $l = $j - 1461 * $k; $n = intPart(($l - 1) / 365) - intPart($l / 1461); $i = $l - 365 * $n + 30; $j = intPart((80 * $i) / 2447); $day = $i - intPart((2447 * $j) / 80); $i = intPart($j / 11); $month = $j + 2 - 12 * $i; $year = 4 * $k + $n + $i - 4716; } $data = array(); $data['year'] = $year; $data['month'] = $month; $data['day'] = $day; if (!$string) return $date; else return "{$year}{$month}{$day}"; } function intPart($float) { if ($float < -0.0000001) return ceil($float - 0.0000001); else return floor($float + 0.0000001); } function jalali2Greg($day, $month, $year, $string = false) { $g_days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $j_days_in_month = array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29); $jy = (int)($year) - 979; $jm = (int)($month) - 1; $jd = (int)($day) - 1; $j_day_no = 365 * $jy + div($jy, 33) * 8 + div($jy % 33 + 3, 4); for ($i = 0; $i < $jm; ++$i) $j_day_no += $j_days_in_month[$i]; $j_day_no += $jd; $g_day_no = $j_day_no + 79; $gy = 1600 + 400 * div($g_day_no, 146097); /* 146097 = 365*400 + 400/4 - 400/100 + 400/400 */ $g_day_no = $g_day_no % 146097; $leap = true; if ($g_day_no >= 36525) /* 36525 = 365*100 + 100/4 */ { $g_day_no--; $gy += 100 * div($g_day_no, 36524); /* 36524 = 365*100 + 100/4 - 100/100 */ $g_day_no = $g_day_no % 36524; if ($g_day_no >= 365) $g_day_no++; else $leap = false; } $gy += 4 * div($g_day_no, 1461); /* 1461 = 365*4 + 4/4 */ $g_day_no %= 1461; if ($g_day_no >= 366) { $leap = false; $g_day_no--; $gy += div($g_day_no, 365); $g_day_no = $g_day_no % 365; } for ($i = 0; $g_day_no >= $g_days_in_month[$i] + ($i == 1 && $leap); $i++) $g_day_no -= $g_days_in_month[$i] + ($i == 1 && $leap); $gm = $i + 1; $gd = $g_day_no + 1; $data = array(); $data['year'] = $gy; $data['month'] = $gm; $data['day'] = $gd; if (!$string) return $data; else return "{$year}{$month}{$day}"; } function div($a, $b) { return (int)($a / $b); } function hr() { echo '
'; } function generateToken($identifier, $expirationInMilliseconds = 0) { $createdTime = getTimeInMilliseconds(); if ($expirationInMilliseconds == 0) { $expirationInMilliseconds = $createdTime + 3600000; } global $config; // Create token header as a JSON string $header = json_encode(['typ' => 'JWT', 'alg' => 'HS256']); // Create token payload as a JSON string $payload = json_encode(["identifier" => $identifier, "timestamp" => $createdTime, "expiration" => $expirationInMilliseconds, "random" => generateHash(6)]); // Encode Header to Base64Url String $base64UrlHeader = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($header)); // Encode Payload to Base64Url String $base64UrlPayload = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($payload)); // Create Signature Hash $signature = hash_hmac('sha256', $base64UrlHeader . "." . $base64UrlPayload, $config['saltJWT'], true); // Encode Signature to Base64Url String $base64UrlSignature = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($signature)); // Create JWT $jwt = $base64UrlHeader . "." . $base64UrlPayload . "." . $base64UrlSignature; return $jwt; } /** * Get header Authorization * */ function getAuthorizationHeader() { $headers = null; if (isset($_SERVER['Authorization'])) { $headers = trim($_SERVER["Authorization"]); } else if (isset($_SERVER['HTTP_AUTHORIZATION'])) { //Nginx or fast CGI $headers = trim($_SERVER["HTTP_AUTHORIZATION"]); } else if (function_exists('apache_request_headers')) { $requestHeaders = apache_request_headers(); // Server-side fix for bug in old Android versions (a nice side-effect of this fix means we don't care about capitalization for Authorization) $requestHeaders = array_combine(array_map('ucwords', array_keys($requestHeaders)), array_values($requestHeaders)); //print_r($requestHeaders); if (isset($requestHeaders['Authorization'])) { $headers = trim($requestHeaders['Authorization']); } } return $headers; } /** * get access token from header * */ function getBearerToken() { $headers = getAuthorizationHeader(); // HEADER: Get the access token from the header if (!empty($headers)) { if (preg_match('/Bearer\s(\S+)/', $headers, $matches)) { return $matches[1]; } } return null; } function getHeaders() { $requestHeaders = null; if (function_exists('apache_request_headers')) { $requestHeaders = apache_request_headers(); // Server-side fix for bug in old Android versions (a nice side-effect of this fix means we don't care about capitalization for Authorization) $requestHeaders = array_combine(array_map('ucwords', array_keys($requestHeaders)), array_values($requestHeaders)); } return $requestHeaders; } ?>connection = new mysqli($host, $user, $pass, $name); if ($this->connection->connect_error) { echo "Connection failed: " . $this->connection->connect_error; exit; } $this->connection->query("SET NAMES 'utf8'"); } private function safeQuery(&$sql, $data) { foreach ($data as $key => $value) { $value = $this->connection->real_escape_string($value); $value = "'$value'"; $sql = str_replace(":$key", $value, $sql); } return $this->connection->query($sql); } public function first($sql, $data = array()) { $records = $this->query($sql, $data); if ($records == null) { return null; } return $records[0]; } public function modify($sql, $data = array()) { $result = $this->safeQuery($sql, $data); if (!$result) { echo "Query " . $sql . " failed duo to " . mysqli_errno($this->connection); exit; } return $result; } public function insert($sql, $data = array()) { $result = $this->safeQuery($sql, $data); if (!$result) { echo "Query " . $sql . " failed duo to " . mysqli_errno($this->connection); exit; } return $result; } public function query($sql, $data = array()) { $result = $this->safeQuery($sql, $data); if (!$result) { echo "Query " . $sql . " failed duo to " . mysqli_errno($this->connection); exit; } $records = array(); if ($result->num_rows == 0) { return null; } while ($row = $result->fetch_assoc()) { $records[] = $row; } return $records; } public function connection() { return $this->connection; } public function close() { $this->connection->close(); } public function getInsertId(){ return mysqli_insert_id($this->connection); } public function getAffectedRows(){ return mysqli_affected_rows($this->connection); } } ?>