$val) { $str[$key] = escape_str($val, $like); } return $str; } else if (is_object($str)) { foreach ($str as $key => $val) { $str->$key = escape_str($val, $like); } return $str; } if (function_exists('mysql_real_escape_string') and is_resource($db)) { $str = mysql_real_escape_string($str, $db); } else { $str = addslashes($str); } if ($like === true) { $str = str_replace(array('%', '_'), array('\\%', '\\_'), $str); } return $str; } //STRIP VALUE function stripslashesFull($input) { if (is_array($input)) { $input = @array_map('stripslashesFull', $input); } elseif (is_object($input)) { $vars = @get_object_vars($input); foreach ($vars as $k => $v) { $input->{$k} = stripslashesFull($v); } } else { $input = @stripslashes($input); } return $input; } //SEND MAIL function commonSendMail($obj) { // // if (IS_LIVE_SERVER != '1') { // $obj->to = ''; // $obj->to = 'lokesh.b@cygnusa.in'; // $obj->cc[] = 'muthuramanr@cygnusa.in'; // $obj->subject = 'HYPER-M :' . $obj->subject; // // } // require_once dirname(__FILE__) . '/phpmailer/PHPMailerAutoload.php'; // require_once dirname(__FILE__) . '/phpmailer/class.phpmailer.php'; // $mail = new PHPMailer; // $obj->replayto = SUPPORT_EMAIL; // if (!isset($obj->from) && $obj->from == '') { // $obj->from = SUPPORT_EMAIL; // } // $mail->isSMTP(); // telling the class to use SMTP // $mail->SMTPAuth = false; // enable SMTP authentication // //$mail->SMTPSecure = 'none'; // sets the prefix to the servier // //$mail->SMTPDebug = 2; // $mail->Host = SMTP_HOST; // sets as the SMTP server // $mail->Port = SMTP_PORT; // set the SMTP port for the server // //$mail->Username = SMTP_USERNAME; // username // //$mail->Password = SMTP_PASSWORD; // password // // $mail->SMTPOptions = array( // // 'ssl' => array( // // 'verify_peer' => false, // // 'verify_peer_name' => false, // // 'allow_self_signed' => true // // ) // // ); // $mail->setFrom($obj->from); //Set who the message is to be sent from // if (isset($obj->FromName)) { // $mail->FromName = $obj->FromName; // } // $mail->addReplyTo($obj->replayto); // //$mail->addAddress($obj->to); // //TO EMAIL // $to_email = ''; // if (isset($obj->to)) { // if (is_array($obj->to)) { // foreach ($obj->to as $res_to) { // $mail->addAddress($res_to); // } // $to_email = @implode(',', $obj->to); // } else if (is_string($obj->to)) { // $mail->addAddress($obj->to); // $to_email = $obj->to; // } // } // //CC EMAIL // $cc_email = ''; // if (isset($obj->cc)) { // if (is_array($obj->cc)) { // foreach ($obj->cc as $res_cc) { // $mail->AddCC($res_cc); // } // $cc_email = @implode(',', $obj->cc); // } else if (is_string($obj->cc)) { // $mail->AddCC($obj->cc); // $cc_email = $obj->cc; // } // } // if (isset($obj->attachment_file)) { // $file_count = count($obj->attachment_file); // for ($x = 0; $x < $file_count; $x++) { // if (!empty($obj->attachment_file[$x])) { // $mail->addAttachment($obj->attachment_file[$x]); // } // } // } // $mail->isHTML(true); // $mail->Subject = $obj->subject; // $contentmail = $obj->message; // $mail->Body = $contentmail; // global $conn; // if (isset($conn)) { // $insert = "INSERT INTO " . TABLE_EMAIL_LOG . " (`to_mail`, `from_mail`, `cc_mail`, `subject`, `is_success`, `created_on`) VALUES ('" . escape_str($to_email) . "','" . escape_str($obj->from) . "','" . escape_str($cc_email) . "','" . escape_str($obj->subject) . "', '0','" . NOW . "' )"; // $insertquery = $conn->executeQuery($insert); // $logid = $conn->lastinsetid(); // } // if (!$mail->send()) { // $headers = "From: " . $obj->from . " \r\n"; // //$headers .= "Reply-To: ".$replayto." \r\n"; // $headers .= "MIME-Version: 1.0\r\n"; // $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; // // @mail(SUPPORT_EMAIL, "Mail delivery report", "FROM : " . $obj->from . ", TO :" . $obj->to . " mail not delivered", $headers); // } else { // if (isset($conn)) { // $conn->executeQuery("UPDATE " . TABLE_EMAIL_LOG . " SET is_success='1' WHERE id='" . $logid . "'"); // } // } } //RESPONSE STATUS function responsestatus($obj) { header("HTTP/1.1 " . $obj->status . " " . $obj->statustext); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS'); header('Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description'); header("Content-Type:application/json"); exit; } //RESPONSE STATUS function quotes_array($str) { return "'" . $str . "'"; } //EXCEL COLUMN FROM NUMBER function getColumnFromNumber($num) { $numeric = $num % 26; $letter = chr(65 + $numeric); $num2 = intval($num / 26); if ($num2 > 0) { return getColumnFromNumber($num2 - 1) . $letter; } else { return $letter; } } function arrSortObjsByKey($key, $order = 'DESC') { return function ($a, $b) use ($key, $order) { // Swap order if necessary if ($order == 'DESC') { list($a, $b) = array($b, $a); } // Check data type if (is_numeric($a->$key)) { return $a->$key - $b->$key; // compare numeric } else { return strnatcasecmp($a->$key, $b->$key); // compare string } }; } // buildBaseString FOR CURL WOOHOO function buildBaseString($baseURI, $method, $params) { $r = array(); ksort($params); foreach ($params as $key => $value) { $r[] = "$key=" . rawurlencode($value); } return $method . "&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r)); } // buildAuthorizationHeader FOR CURL WOOHOO function buildAuthorizationHeader($oauth) { $r = 'Authorization: OAuth '; $values = array(); foreach ($oauth as $key => $value) { $values[] = "$key=\"" . rawurlencode($value) . "\""; } $r .= implode(', ', $values); return $r; } function maskenquiry($var) { if ($var != '' && strlen($var) > 2) { $len = strlen($var) - 2; $var = substr_replace($var, str_repeat("X", $len), 0, $len); } return $var; } //WOOHO /** * JSON encoded API request body parameters. This should be empty string in-case of API HTTP method is GET & DELETE * * @var string $requestBody */ //$requestBody = '{"q" : [{"f" : 1, "d" : 2}], "a" : "something"}'; /** * API HTTP method * * @var string $requestHttpMethod */ //$requestHttpMethod = 'post'; /** * Absolute API endpoint URL. In-case if you are passing query parameter this should be in filled with query parameters as well * * Make sure you configure this endpoint in database, because the endpoint will change for production environment * * @var string $absApiUrl */ //$absApiUrl = 'https:///rest/v3/orders'; /** * This will be shared as part of provisioning the partner * * @var string $clientSecret */ //$clientSecret = 'secret string'; /** * Sorts the parameters according to the ASCII table. * * @param array $params */ function sortParams(array &$params) { ksort($params); foreach ($params as $key => &$value) { $value = is_object($value) ? (array) $value : $value; if (is_array($value)) { sortParams($value); } } } /** * Sort all query parameters in the request according to the parameter name in ASCII table. * * @param string $queryParam * @return string */ function sortQueryParams($queryParam) { $query = explode('&', $queryParam); asort($query, SORT_STRING); return implode('&', $query); } /** * Concat the (request method(upper case), request host, request URL), encoded request parameters and encoded query parameters using & as the separator. * * @param string $absApiUrl * @param string $requestHttpMethod * @param string $requestBody * * @return string */ function getConcatenateBaseString($absApiUrl, $requestHttpMethod, $requestBody) { $baseStrings = []; $baseStrings[] = strtoupper($requestHttpMethod); $url = explode('?', $absApiUrl); $apiUrl = $url[0]; if (isset($url[1])) { $baseStrings[] = rawurlencode($apiUrl . '?' . sortQueryParams($url[1])); } else { $baseStrings[] = rawurlencode($apiUrl); } if ($requestBody) { $jsonDecodedRequestBody = json_decode($requestBody, true); sortParams($jsonDecodedRequestBody); $baseStrings[] = rawurlencode( json_encode($jsonDecodedRequestBody, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ); } return implode('&', $baseStrings); }