var Cookie = {
_params: {
domain: '',
path: '/',
expires: '',
maxAge: -1,
sameSite: false,
secure: false
},
_lastCookie: '',
setDefaultParams (params) {
this._params = {...this._params, ...params};
},
getDefaultParams () {
return this._params;
},
getLastCookie () {
return this._lastCookie;
},
set (key, value, params={}) {
value = encodeURIComponent(value);
params = {...this._params, ...params};
if (params.expires) {
if (params.expires instanceof Date) {
params.expires = params.expires.toUTCString();
} else if (typeof params.expires === 'string') {
const date = new Date(params.expires);
params.expires = date.toUTCString();
}
}
let cookie = `${key}=${value};`;
cookie += params.path ? ` Path=${params.path};` : '';
cookie += params.domain ? ` Domain=${params.domain};` : '';
cookie += params.expires ? ` Expires=${params.expires};` : '';
cookie += params.maxAge > -1 ? ` Max-Age=${params.maxAge};` : '';
cookie += params.sameSite !== false ? ` SameSite=${params.sameSite};` : '';
cookie += params.secure === true ? ` Secure;` : '';
this._lastCookie = cookie;
document.cookie = cookie;
return true;
},
has (key) {
return this.getAll().hasOwnProperty(key);
},
get (key) {
return this.getAll()[key];
},
getAll () {
const cookies = {};
this.getString().split(';').forEach(val => {
const params = val.split('=').map(el => el.trim());
cookies[params[0]] = params[1];
});
return cookies;
},
getString () {
return document.cookie;
},
delete (key) {
if (!this.has(key)) return false;
return this.set(key, '', { expires: 'Thu, 01 Jan 1970 00:00:01 GMT', maxAge: 0 });
}
};
if (!Cookie.has('key')) {
if (confirm('Are you want to save a cookie?')) {
Cookie.set('key', true, { expires: '2022-12-01T00:00:00' });
}
} else {
if (confirm('Are you want to delete a cookie?')) {
Cookie.delete('key');
}
}
const KEY = 'TIMECOUNTER';
if (!localStorage.getItem(KEY)) {
setTimeout(() => {
yaCounterХХХХХХХХ.reachGoal('TIME');
localStorage.setItem(KEY, KEY);
}, 30000);
}
<dict>
<key>name</key>
<string>Comment</string>
<key>scope</key>
<string>comment</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#808080</string>
</dict>
</dict>
<a href="#" class="my-link">link</a>
.my-link, .my-link:hover {
text-decoration: none;
color: #000;
}
Content-Type: multipart/form-data; boundary=------------------------boundary
Content-Length: 12345
--------------------------boundary\r\n
Content-Disposition: form-data; name="file"; filename="file.csv"\r\n
Content-Type: text/csv\r\n\r\n
ДАННЫЕ\r\n\r
--------------------------boundary--
function request($url, $data, $headers){
$opt = array(
'http' => array(
'method' => 'POST',
'content' => $data,
'header' => $headers
)
);
$context = stream_context_create($opt);
$response = @file_get_contents($url, FALSE, $context);
return $response;
}
$oauth_token='xxx';
$boundary = "7zDUQOAIAE9hEWoV";
$filename = 'data.csv';
$calls = "StaticCall,UserId,DateTime,Price,Currency,PhoneNumber,TalkDuration,HoldDuration,CallMissed,Tag,FirstTimeCaller,URL,CallTrackerURL".PHP_EOL;
$calls .= "1,133591247640966458,1481714026,678.90,RUB,+71234567890,136,17,0,,1,https://test.com/,https://test.com/".PHP_EOL;
$calls .= "1,579124169844706072,1481718066,123.45,RUB,+70987654321,17,23,0,,2,https://test.com/,https://test.com/".PHP_EOL;
$calls .= "1,148059425477661429,1481718126,678.90,RUB,+71234509876,72,11,0,,0,https://test.com/,https://test.com/";
$data = "--------------------------$boundary\x0D\x0A";
$data .= "Content-Disposition: form-data; name=\"file\"; filename=\"$filename\"\x0D\x0A";
$data .= "Content-Type: text/csv\x0D\x0A\x0D\x0A";
$data .= $calls . "\x0A\x0D\x0A";
$data .= "--------------------------$boundary--";
$headers = array();
$headers[] = "Content-Type: multipart/form-data; boundary=------------------------$boundary";
$headers[] = 'Content-Length: '.strlen($data);
$headers = implode(PHP_EOL, $headers);
$url = "https://api-metrika.yandex.ru/management/v1/counter/39764535/offline_conversions/upload_calls?client_id_type=USER_ID&oauth_token=$oauth_token";
$result = request($url, $data, $headers);
var_dump($result);
CURLOPT_POSTFIELDS => $data
CURLOPT_HTTPHEADER => array(
"Content-Type: multipart/form-data; boundary=------------------------$boundary",
"Content-Length: " . strlen($data)
Ведь программисту нужно потратить больше времени, сил и энергии.
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script>
function setOnclick(a) {
a.setAttribute("onclick","popupWin = window.open(this.href,'contacts','width=820px,height=700px,top=50,left=200px,toolbar=0, location=0, directories=0, menubar=0, scrollbars=0, resizable=0, status=0'); popupWin.focus(); return false");
}
function externalLinks() {
var links = document.getElementsByTagName("a");
for (i=0; i<links.length; i++) {
if (links[i].getAttribute("href") && links[i].getAttribute("rel") == "external") {
setOnclick(links[i])
}
}
}
window.onload = externalLinks;
</script>
</head>
<body>
<a rel="external" href='file.html'>ТЫК</a>
</body>
</html>