Helper that generates a machine name using a provided human readable name.
function m60_webloggia_api_curl($method, $params) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $params['url']);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 300);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if (variable_get('m60_webloggia_proxy', 0)) {
curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:9999');
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
}
if ($method == 'GET') {
curl_setopt($ch, CURLOPT_URL, $params['url'] . '?' . $params['request']);
}
elseif ($method == 'POST') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $params['request']);
}
else {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $params['request']);
}
$response = curl_exec($ch);
if(curl_errno($ch)) {
watchdog('webloggia', 'Curl request to the webloggia ends with error: @error', array('@error' => curl_error($ch)), WATCHDOG_CRITICAL);
drupal_set_message(t('Curl request to the webloggia ends with error: @error', array('@error' => curl_error($ch))), 'error');
curl_close($ch);
return FALSE;
}
elseif(substr($response, 0, 5) != "<?xml") {
watchdog('webloggia', 'Response from webloggia is not in the xml format', array(), WATCHDOG_CRITICAL);
drupal_set_message(t('Response from webloggia is not in the xml format', 'error'));
curl_close($ch);
return FALSE;
}
$xml = simplexml_load_string($response);
$json = json_encode($xml);
$data = json_decode($json, TRUE);
return $data;
}
/**
* Helper that generates a machine name using a provided human readable name.
*
* @param string $human_name
* Human readable name.
*
* @return string
* Machine name cleaned-up of any special chars.
*/
function human_to_machine($human_name) {
return strtolower(preg_replace(array(
'/[^a-zA-Z0-9]+/',
'/-+/',
'/^-+/',
'/-+$/',
), array('-', '-', '', ''), $human_name));
}
array_chunk($rows, 2); — Разбивает массив на части (В данном случае по парам)
<?php
if (empty($user->uid)) {
watchdog('anonymous_session', '<pre>@data</pre>', array('@data' => print_r($_SESSION, TRUE)));
}