retrieve cookie value in cakephp - cookies

I'm storing a multidimensional array in a cookie.
$this->Cookie->write('Cart',
$products, false, 3600
);
Below is the multidimensional array which I'm storing in the cookie
Array
(
[Cart] => Array
(
[user_id] =>
[product_id] => 92
[quantity] => 1
[date_created] =>
[date_modified] =>
[product_name] => shoes
[price] => 12
)
)
but when i read the cookie, it gives me this output
[{\"Cart\":{\"user_id\":\"\",\"product_id\":\"7\",\"quantity\":\"1\",\"date_created\":\"\",\"date_modified\":\"\",\"product_name\":\"iPhone\",\"price\":\"12\"}}]
below is the code which i'm using to read the cookie
$this->Cookie->read('Cart');
On my local server it works perfectly alright but gives me above mentioned output when I try it on Online server

You could try the following to write
$this->Cookie->write('Cart', serialize($products), false, 3600);
And this to read
unserialize($this->Cookie->read('Cart'));
Your cookie is probably being saved as plain text.

Related

WP_Query meta_query REGEXP

I am pretty much below beginner level for REGEX/REGEXP and have hit a blocking point in a project I am working in, where I am trying to get the ids for posts that match the search criteria , but I want to restrict the search between 2 sub-strings. I am trying to figure out is how to write the REGEXP in the meta_query:
$args = array(
'post_type'=> 'custom',
'order' => 'DESC',
'posts_per_page' => 10,
'paged' => $page,
'meta_query' => array(
array(
'key' => 'key',
'value' => "title*".$search."*_title",
'compare' => 'REGEXP',
)
),
);
And an example of the field in the DB :
a:302:{s:5:"title";s:10:"Test title";s:6:"_title";s:19:"
Unfortunately none of the combinations I tried based on documentation of SQL REGEXP won't return any values and I am trying to understand how I can pull this off and would appreciate any input.
Also would rather stick to WP_Query for now even though an SQL LIKE "%title%{$search}%_title%" works perfectly , so an alternative solution would be how to set the compare to 'LIKE' and parse it '%' since that is not possible out of the box as the % get escaped I believe.

Need help removing canonical rel link from Drupal 8

I need to remove link rel="canonical". I removed it from the Meta Tag Module and I also used a module that's supposed to remove it but it still remains.
I removed all instances in the Meta Tag module and I also used the Disable Link Rel module that's supposed to remove it. It's still there.
I need to remove this link from the head of my site.
You can also do from hook_preprocess_html in the $variables['page']['#attached'] array to be altered.
You have to fist check by printing variables
print '<pre>';print_r($variables['page']['#attached']);die;
After then check and empty the array like this :-
if($variables['page']['#attached']['html_head'][1][1] == 'canonical_url') { $variables['page']['#attached']['html_head'][1][0]['#attributes'] = array(); }
In my case the printed array was like this:-
Array
(
[html_head] => Array
(
[0] => Array
(
[0] => Array
(
[#tag] => meta
[#attributes] => Array
(
[name] => title
[content] => test english 1 | localhost
)
)
[1] => title
)
[1] => Array
(
[0] => Array
(
[#tag] => link
[#attributes] => Array
(
[rel] => canonical
[href] => http://localhost/leadervinu_development/drupal-8.7.3/en/node/51
)
)
[1] => canonical_url
)

How can I generate a PDF file from Amazon Textract output?

I am using Amazon Textract to extract data from a scanned document. Now I want to convert the output to a PDF file. Below is a sample output of Textract:
[1] => Array
(
[BlockType] => LINE
[Confidence] => 99.4744720459
[Text] => Hello
[Geometry] => Array
(
[BoundingBox] => Array
(
[Width] => 0.243866533041
[Height] => 0.0134594505653
[Left] => 0.176409825683
[Top] => 0.0463116429746
)
[Polygon] => Array
(
[0] => Array
(
[X] => 0.176409825683
[Y] => 0.0463116429746
)
[1] => Array
(
[X] => 0.420276373625
[Y] => 0.0463116429746
)
[2] => Array
(
[X] => 0.420276373625
[Y] => 0.0597710944712
)
[3] => Array
(
[X] => 0.176409825683
[Y] => 0.0597710944712
)
)
)
[Id] => 75e8917d-701e-4e26-bade-f00bde9d87db
[Relationships] => Array
(
[0] => Array
(
[Type] => CHILD
[Ids] => Array
(
[0] => 46f44500-4960-4405-99f3-fa43101bc2ca
)
)
)
)
As you can see, the output contains text, height, width and its XY coordinates. How can I place the text with same co-ordinates into a PDF file?
Assuming you can convert the above to JSON, you can use jsPDF or PDFkit to create the PDF. The functionality maps pretty well based upon the limited data you posted, but I have not seen the full structure of Textract as it is still in Beta and I didn't get an invite to the program. Both these projects can use Node to create a server-side solution, but they also work in the Browser.
At the time of this writing, Google Cloud has an OCR component in their Vision - Document Text Detection feature. Unlike Textract, it approaches the task as just reporting what visual elements the document has and creating a comprehensive (and large) data structure that describes what it "sees." Textract, according to Amazon, uses machine learning to organize the data in a more human understandable form that seeks to differentiate the form from the data that constitutes the filled-out part of the form. If you are trying to create a relatively complete PDF, the Google product is well suited. Textract might be too, but I don't know yet.
This repository contains code examples (in Java) showing how you can generate a searchable PDF using AWS Textract. If you are not using Java, you may also deploy it as an AWS Lambda function and then invoke it via the AWS SDK or as a REST API call using AWS API Gateway.
There is a corresponding blog post also available here.

Yii2 MaskedInput / MaskedMoney for Integer Only money storage

In my database I store money as an integer, similar to Stripe. For instance 12.99 is stored as 1299. Basically taking the number and dividing by 100.
I'm trying to incorporate this with Yii2 activeForm, specifically using either the MaskInput or MaskMoney widgets. However, I cannot figure out how to configure either widget so that when the value is "1299" it displays as "12.99". So if a person types in "1200" it displays as "12.00".
This is for a simple frontend solution and not backend so I'm not looking for Yii scenarios or behaviors in this question.
I'm not sure if I understood correctly, but this is the closest I've ever got to what you want.
<?php echo \yii\widgets\MaskedInput::widget([
'name' => 'masked-input',
'clientOptions' => [
'alias' => 'decimal',
'digits' => 2,
'digitsOptional' => false,
'radixPoint' => '.',
'groupSeparator' => ',',
'autoGroup' => true,
'removeMaskOnSubmit' => true,
],
]); ?>
The behaviour of the decimal part is what bothers me, but it works as intended.

Parsing a big json then multiple small jsons

My english is not the best, but I will try to explain what I want. So, we have a big json which has a lot of data, now because the server cant show us all the data at the same time, there will be multiple links to small json inside this big json, like when there are 20 comment on a page, and after that there is a "Show more comments" button. My problem is that I dont know how to do this, how to request the smaller json, the parse it. Another question is how to parse a json which links at the end to another json, something like when requestiong a json from graph api and at the end it has
[paging] => stdClass Object
(
[previous] => https://graph.facebook.com/$group_id$/feed?access_token=$valid_token$&__paging_token=$paging_token$&__previous=1
[next] => https://graph.facebook.com/$group_id$/feed?access_token=$valid_token$&limit=25&until=1375310522&__paging_token=$paging_token$
)
When the link from the [next] is opened, it shows more post from that group, then again at its end there is a next link.
As for the first question, I have a bit longer example from the facebook graph api comments
[comments] => stdClass Object
(
[data] => Array
(
[0] => stdClass Object
(
[id] => 53575265890127
[from] => stdClass Object
(
[name] => Pop Dan
[id] => 10000897827962
)
[message] => Random message
[can_remove] => 1
[created_time] => 2013-08-18T20:01:44+0000
[like_count] => 0
[user_likes] =>
)
... more coments...
[paging] => stdClass Object
(
[cursors] => stdClass Object
(
[after] => NTM1ODIxODE5ODA2NTQ0
[before] => NTM1NzUyNjU2NDgwMTI3
)
next] => https://graph.facebook.com/$group_id$_$post_id$/comments?access_token=$accestoken$&limit=25&after=NTM1ODIxODE5ODA2NTQ0
)
)
There I want to continue parsing the json from the [next] and then print it in the same html page, without any breaks or anything between comments. Thanks ;)
Some of the details depend on the language you are using for querying graph api.
Json returned from graph api can consist of json arrays and json objects. Json objects can further have named value entities
If you are doing it in android then first of all you have to get the inner json object from the response first. you can do it in this way
GraphObject go = response.getGraphObject();
JSONObject jso = go.getInnerJSONObject();
Now to get an object from the json you can use
jso.getJSONObject("object_name");
and to get json array you can use
jso.getJSONArray("array_name")
other languages will have similar interfaces
For general understanding of json refer to this link
Regarding your second question you should understand that next is just another query to the graph node but with different parameters. How the parameters can be set depends on the api but in Android you can pur parameters as follows
Bundle params=r.getParameters();
params.putString("offset", ""+25);
r.setParameters(params);
r is the object of type Request