I'm making a sort of phone book and everything is fine:
Connection and authentification works perfectly
Research goes aswell
I can modify user's attributes
Then my boss asked me to add the Location attribute aka "Bureau" in french but openldap won't retrive it and only it.
Here's the code :
$attributes = array();
$attributes[] = 'givenname';
$attributes[] = 'sn';
$attributes[] = 'samaccountname';
$attributes[] = 'mail';
$attributes[] = 'telephonenumber';
$attributes[] = 'useraccountcontrol';
$attributes[] = 'dn';
$attributes[] = 'location';
/*------------------------------------------------------------------------------*/
if ($ldap_bind) // Si la connexon s'est effectuée
{
// Query sur LDAP
$resultat = ldap_search($ldap_connect, $dn, $search_filter, $attributes) or die('Une erreur est survenue pendant la recherche.');
// Transformation de l'objet LDAP en données explotables
$entries = ldap_get_entries($ldap_connect, $resultat);
But when I var_dump($entries), the location attribute isn't in the array, like if the name attribute was wrong. But according to msdn it's the right attribute correctly spelled.
So now I turn myself to you in hope someone can help on this issue.
In LDAP, if the attribute is not set, it will not be retrieved empty but will not be set in the response entry array.
Retrieve every attribute of the entry and var_dump it to see if it is set.
Related
I´m forking this repo https://github.com/FundacionPesetacoin/Pesetacoin_WooCommerce-Plugin and working fine. But when change the API for catch the price in other Site, not update
I try some differents links of API and make same.
Original code get info of his private API, and I want use other public API.
With original code, API show this info:
{"status" : "success" , "message" : "null", "ptc_btc" : "0.00000083", "btc_usd" : "5070.29", "btc_eur" : "4505.46", "supply" : "138188628.56442260", "ptc_eur" : "0.00373953", "ptc_usd" : "0.00420834" , "date" : "2019-04-13 10:20:07"}
and get "ptc_eur" of API for shows in shoppping cart.
Now I want use the new API of other site https://api.coingecko.com/api/v3/simple/price?ids=reecore&vs_currencies=eur than shows this info:
{"reecore":{"eur":0.0046564}}
I want use only the "eur" data , same the original code use the "ptc_eur" but dont work.
Sorry for my english.
ORIGINAL CODE:
//precio en PesetaCoins
global $woocommerce;
$euros= $woocommerce->cart->total;
$xaxa= "http://nodos.pesetacoin.info/api/api.php";
$data = file_get_contents($xaxa);
$pesetas = json_decode($data, true);
$valor_ptc= $pesetas['ptc_eur'];
$ptc= $euros/$valor_ptc;
$ptc= round($ptc, 2);
//precio en PesetaCoins
$pagos= array();
$metodo= $order->get_payment_method();
$i = -1;
foreach ( $this->account_details as $account ) {
$i++;
$pagos[$i]=
$pagos[$i]= esc_attr( wp_unslash( $account['hash_name'] ) );
}
$cont= rand(0, $i);
if($metodo == "ptc") {
$description= "<span style='font-size:14px'>Para completar el pedido, debe enviar la cantidad <b>".$ptc."</b> de Pesetacoin a la siguiente dirección: <b>";
$description.= $pagos[$cont];
$description.="</b><br>Una vez se reciba la transacción se enviará el pedido.</span>";
echo wpautop(wptexturize($description));
}
}
NEW CODE:
//precio en ReecoreCoins
global $woocommerce;
$euros= $woocommerce->cart->total;
$xaxa= "https://api.coingecko.com/api/v3/simple/price?ids=reecore&vs_currencies=eur";
$data = file_get_contents($xaxa);
$pesetas = json_decode($data, true);
$valor_reex= $pesetas['eur'];
$reex= $euros/$valor_reex;
$reex= round($reex, 2);
//precio en ReecoreCoins
$pagos= array();
$metodo= $order->get_payment_method();
$i = -1;
foreach ( $this->account_details as $account ) {
$i++;
$pagos[$i]=
$pagos[$i]= esc_attr( wp_unslash( $account['hash_name'] ) );
}
$cont= rand(0, $i);
if($metodo == "reex") {
$description= "<span style='font-size:14px'>Para completar el pedido, debe enviar la cantidad <b>".$reex."</b> de Reecorecoin a la siguiente dirección: <b>";
$description.= $pagos[$cont];
$description.="</b><br>Una vez se reciba la transacción se enviará el pedido.</span>";
echo wpautop(wptexturize($description));
}
}
It's because the now Coingecko API return a nested JSON which is simply a JSON file with a fairly big portion of its values being other JSON objects.
Compared with Simple JSON, Nested JSON provides higher clarity in that it decouples objects into different layers, making it easier to maintain.
Using Phrase, keys will be stored by separating levels with a dot.
The new API returns a nested JSON object, where you need two steps to access the desired value:
$valor_reex= $pesetas['reecore']['eur'];
You might want to use ready library for this. Like this one https://github.com/npabisz/coingecko-api.
Install via composer:
composer require npabisz/coingecko-api
And then get your reecore price by:
$client = new \CoinGecko\Client();
$data = $client->Simple->Price->get([
'ids' => 'reecore',
'vs_currencies' => 'eur',
]);
$reecorePrice = $data['reecore']['eur'] ?? null;
I create a PHP script that receive an hooks from WooCommerce, makes PDF with received data and send an e-mail, but I have a problem parsing the JSON data...
This is the JSON:
{"id":128705,"parent_id":0,"number":"128705","order_key":"wc_order_5ae3648deddcd","created_via":"checkout","version":"3.3.5","status":"on-hold","currency":"EUR","date_created":"2018-04-27T19:57:33","date_created_gmt":"2018-04-27T17:57:33","date_modified":"2018-04-27T19:57:34","date_modified_gmt":"2018-04-27T17:57:34","discount_total":"0","discount_tax":"0","shipping_total":"0","shipping_tax":"0","cart_tax":"0","total":"50","total_tax":"0","prices_include_tax":false,"customer_id":7,"customer_ip_address":"79.43.191.213","customer_user_agent":"mozilla\/5.0 (x11; linux x86_64) applewebkit\/537.36 (khtml, like gecko) chrome\/62.0.3202.89 safari\/537.36","customer_note":"","billing":{"first_name":"Nicola","last_name":"Giada","company":"","address_1":"V","address_2":"","city":"CANIC","state":"RA","postcode":"48018","country":"IT","email":"ggggggg#gmail.com","phone":"30002222"},"shipping":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":""},"payment_method":"bacs","payment_method_title":"Bonifico bancario","transaction_id":"","date_paid":null,"date_paid_gmt":null,"date_completed":null,"date_completed_gmt":null,"cart_hash":"dba69b53a4a39c58c83b3e557e818bb7","meta_data":[{"id":1383502,"key":"_billing_data","value":"00\/00\/1990"},{"id":1383503,"key":"_billing_codice_fiscale","value":"GDDLLLL333232"},{"id":1383504,"key":"_billing_socio","value":"Sono gi\u00e0 Socio"},{"id":1383505,"key":"_billing_dati","value":"Acconsento"},{"id":1383506,"key":"billing_data","value":"00\/00\/1990"},{"id":1383507,"key":"billing_codice_fiscale","value":"GDDLLLL333232"},{"id":1383508,"key":"billing_socio","value":"Sono gi\u00e0 Socio"},{"id":1383509,"key":"billing_dati","value":"Acconsento"}],"line_items":[{"id":94,"name":"Object buyed XXXX 2018","product_id":128683,"variation_id":128684,"quantity":1,"tax_class":"","subtotal":"40","subtotal_tax":"0","total":"40","total_tax":"0","taxes":[],"meta_data":[{"id":883,"key":"corso","value":"Object NUED"}],"sku":"","price":40},{"id":95,"name":"SECOND OBJECT","product_id":126454,"variation_id":0,"quantity":1,"tax_class":"","subtotal":"10","subtotal_tax":"0","total":"10","total_tax":"0","taxes":[],"meta_data":[],"sku":"","price":10}],"tax_lines":[],"shipping_lines":[],"fee_lines":[],"coupon_lines":[],"refunds":[]}
And this is the piece of my PHP where I retrieve information from the JSON:
/* Gestione dei dati via JSON */
$year = date('Y'); //Anno validità associativa
$secret = 'xxxxx'; //La chiave per il Webhook generata da Woocommerce
$JSON = file_get_contents('php://input');
$data = json_decode($JSON);
$sig = base64_encode(hash_hmac('sha256', $data, $secret, true));
if ($sig != $header_sig) print 'Firma invalida'; //Controllo la firma di sicurezza. Mettere die invece di print.
$nome = $data->billing->first_name;
$cognome = $data->billing->last_name;
$nato_luogo = '';
$prov = $data->billing->state;
$cap = $data->billing->postcode;
$indirizzo = $data->billing->address_1;
//$indirizzo .= $data->billing->address_2;
$tel = $data->billing->phone;
$email = $data->billing->email;
$data = date('d/m/Y'); //Data sottoscrizione scheda
$residenza = $data->billing->city;
//Valori dentro i meta_data personalizzati
foreach ($data->meta_data as $datum) {
if ($datum->key == "_billing_data") $nato_data = $datum->value;
if ($datum->key == "_billing_codice_fiscale") $CF = $datum->value;
if ($datum->key == "_billing_socio") $checksocio = $datum->value;
}
if($check_socio == 'S\u00ec') print 'Giá socio';
My problem is getting values inside "meta_data", the: foreach isn't working at all.
Thanks.
The error was in naming the variable $data ... TYPO error. Thanks.
I try to get the image that is stored in a folder of my localhost, I do not understand what is the problem, the attribute in JSON IMAGEN get empty,
I need to convert it here..
<?php
/**
* Obtiene todas las metas de la base de datos
*/
const ESTADO = "estado";
const DATOS = "negocios";
const MENSAJE = "mensaje";
const CODIGO_EXITO = 1;
const CODIGO_FALLO = 2;
require '../data/Gastos.php';
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
// Manejar petición GET
$negocios = Gastos::getAllNegocios();
//Definir el tipo de la respuesta
header('Content-Type: application/json');
$imagesPath = '/localhost:8888/htdocs/';
if ($negocios) {
$datos[ESTADO] = CODIGO_EXITO;
foreach($negocios as $meta) {
// Push an entry in the new array, replacing raw image with base64-encoded
$imgFileContents = file_get_contents($imagesPath.'/'.$meta['IMAGEN']);
$datos["negocios"][] = array(
'IDNEGOCIO' => $meta['IDNEGOCIO'],
'NOMBREIMAGEN' => $meta['NOMBREIMAGEN'],
'IMAGEN' => base64_encode($imgFileContents),
'NOMBRENEGOCIO' => $meta['NOMBRENEGOCIO'],
'DESCRIPCION' => $meta['DESCRIPCION'],
);
}
print json_encode($datos,JSON_UNESCAPED_UNICODE);
} else {
print json_encode(array(
ESTADO => CODIGO_FALLO,
MENSAJE => "Ha ocurrido un error"
));
}
}
?>
Get empty in JSON
{"estado":1,"negocios":[{"IDNEGOCIO":"1","NOMBREIMAGEN":"img_1","IMAGEN":"","NOMBRENEGOCIO":"YARYAS","DESCRIPCION":"Descripcion1"},{"IDNEGOCIO":"2","NOMBREIMAGEN":"img_2","IMAGEN":"","NOMBRENEGOCIO":"Skizza","DESCRIPCION":"Descripcion2"}]}
It is the directoy
I think it might be because you're $imagesPath URL is pointing to a directory incorrectly. In most localhost setups "htdocs" is already the default directory when travelling to the localhost server, so assuming its a relative URL it should be something like "http://localhost:8888/fotos/" not "http://localhost:8888/htdocs/fotos/".
Try:
$imagesPath = 'http://localhost:8888/';
I use LiipImagineBundle for re-size my image after upload. I have a error when I tried to upload some Jpeg about HTML encodage.
With jpeg form my camera that's work, but not form my phone camera.
What my browser show only js error and return blank page ?
I didn't understand what is that error.
Full message in french :
L'encodage de caractères du document HTML n'a pas été déclaré. Le document sera affiché avec des caractères incorrects pour certaines configurations de navigateur si le document contient des caractères en dehors de la plage US-ASCII. L'encodage de caractères de la page doit être
déclaré dans le document ou dans le protocole de transfert.
controller Symfony2
private function compressFile($file) {
$path = $file->getWebPath();
$absPath = $file->getAbsolutePath();
$tmpPath = $absPath."tmp";
$filter = "image";
$container = $this->container;
$dataManager = $container->get('liip_imagine.data.manager');
$filterManager = $container->get('liip_imagine.filter.manager');
try {
$image = $dataManager->find($filter, $path);
$response = $filterManager->applyFilter($image, $filter);
//$response = $filterManager->get($this->getRequest(), $filter, $image, $path);
$fileCompressed = $response->getContent();
}
catch (\Exception $e) {
return "error";
}
$f = fopen($tmpPath, 'w');
fwrite($f, $fileCompressed);
fclose($f);
unlink($absPath);
rename($tmpPath, $absPath);
return null;
}
I have found help to create my compress Function here.
I tried to catch some Exception but nothing work.
Someone have a solution ?
Sorry for my English, I am learning it...
It may be a little bit anoying but have you set default_charset to "UTF-8" in your php.ini ?
If you use Apache: Is (AddDefaultCharset UTF-8) present on your httpd.conf ?
In your view: is is présent on between your HTML Header.
Check the encoding of your editor to UTF-8 without BOM if it's not configured yet and save all file you have generated with that correct charset.
If not this may be the origin of that bad behavior.
Have a nice day.
Best Regards
i'm struggling trying to remove the scaped characters from the json response in my CodeIgniter with PhilSturgeon REST Server.
Everything is working OK, but the problem comes with the response, when I access the URL to get the data in json format I get it, but with escaped characters.
Example:
http://localhost/revista_servidor/index.php/api/notas/nota/id/1
Gives me the next response:
[{"id":"1","autor":"Prueba autor","titulo":"Comprobaci\u00f3n de t\u00ed\u00edtulo.","subtitulo":"Comprobaci\u00f3n de subt\u00edtulo.","foto1":"http://link.a.foto/foto1","texto1":"Comprobaci\u00f3n de texto 1.\r\n","pauta1":"1","texto2":"Comprobaci\u00f3n de texto 2.\r\n","foto2":"http://link.a.foto/foto2","pauta2":"1","texto3":"Comprobaci\u00f3n de texto 3.","foto3":"http://link.a.foto/foto3","pauta3":"1","texto4":"Comprobaci\u00f3n de texto 4.","texto5":"Comprobaci\u00f3n de texto 5.","texto6":"Comprobaci\u00f3n de texto 6.","datosweb":"http://link.a.pagina.de.datos/","adelanto":"Comprobaci\u00f3n del texto de adelante","nrorevista":"69"}]
It escapes URLs adding a backslash \ and changing specials characters (ó in this example) with: \u00f3.
I've tried adding stripslashes()but didn't work.
I checked the response in developers tools and it comes as expected: Content-Type: application/json.
How can I fix this encoding problem? I've also checked the configuration files and there seems to be nothing to change for this issue.
I hope someone can point me in the right direction, below is my code:
Controller: /application/controllers/api/notas.php
function nota_get() {
// ID verification.
if ( !$this->get('id') ) {
// NO ID.
$this->response(NULL, 400);
}
$nota = $this->Notas_model->get( $this->get('id') );
if ($nota) {
stripcslashes($this->response($nota, 200));
}
else {
$this->response(NULL, 404);
}
}
Model: /application/models/notas_model.php
function get($id = 0) {
$this->load->database();
if ( $id ) {
$query = $this->db->get_where( 'notas', array('id' => $id) );
}
else {
$query = $this->db->get('notas');
}
return $query->result();
}
I don't know if this matters, but this data will be accessed via javascript in the client side.
Thanks in advance!
Its just the way JSON works, try json_decode function.
e.g:
$json = json_decode($json_string);
$json->autor;
1) You need to be using json_decode() and then urldecode(), instead of stripslashes()
2) Both urldecode() and stripslashes() take a string as an argument, while you are trying to feed into it an object -- which gets "autoreduced" into something that depends on the PHP version... Whatever it is, it's probably not what you are expecting.
In your code:
if ($nota) {
stripcslashes($this->response($nota, 200));
}
you'll need a) save the result of decoding to the same or another variable, b) to loop through your object ( $nota ) and unescape the value in each key-value pair.
Try
...
$cleanObject = array();
if ($nota) {
$decodedObject = json_decode($this->response($nota, 200));
foreach ( $decodedObject as $key => $value ) {
$cleanObject[$key] = urldecode( $value );
}
}
echo "<pre>";
print_r($cleanedObject);
echo "</pre>";
// output
/*
Array
(
[id] => 1
[autor] => Prueba autor
[titulo] => Comprobación de tíítulo.
[subtitulo] => Comprobación de subtítulo.
[foto1] => http://link.a.foto/foto1
[texto1] => Comprobación de texto 1.
[pauta1] => 1
[texto2] => Comprobación de texto 2.
[foto2] => http://link.a.foto/foto2
[pauta2] => 1
[texto3] => Comprobación de texto 3.
[foto3] => http://link.a.foto/foto3
[pauta3] => 1
[texto4] => Comprobación de texto 4.
[texto5] => Comprobación de texto 5.
[texto6] => Comprobación de texto 6.
[datosweb] => http://link.a.pagina.de.datos/
[adelanto] => Comprobación del texto de adelante
[nrorevista] => 69
)
*/
...
Hopefully, this is what you are looking to achieve.
Depending on your further needs, you may have to re-encode the result. Based on javascript you mention, you may then need to convert the result back to JSON:
$unescapedAndJSONencodedObject = json_encode( $cleanObject );