Html Encode Ionic 2 + API PHP quotes errors - javascript

My api returns a string of html in which I convert to html with php with the function:
[API ENCODE HTML, IF NOT IS RENDERIZE AS STRING ]
$description = html_entity_decode($description)
After this Json_encode
And return this value to the Ionic 2 app.
In which I take this item and show with:
[APP HTML RECEIVE WITH NO TRAITAMENT IN INNERHTML TO SHOW DESCRIPTION]
<div class="item item-text-wrap" [innerHTML]="item.description"></div>
But some items use as a tooltip in the tag:
<span title="Auxiliary content open per click">click</span>
However, some content breaks due to double quotation marks.
title=" table rowspan="2"></table "
How could I add slashs or a rendition of that html inside the title without breaking it by the quotation marks.
I've already tried modifying your content in the API, but I have not yet been able to render this html.
Is there a way to do this by ionic 2? as ?
Is there a way to do it with regex in php to modify the title only?
Thanks for the help, and sorry for my bad english.
Not result any erros;
Test for the response 1:
let description = this.item.descricao;
this.descricao = description.replace(/'/g, '"');

You can replace your "" with ' as shown below using Javascript/TS.
var result = yourString.replace(/'/g, '"');

I changed my API PHP to create a json file, every time updated content with CKeditor, I override file make.json.
When app request my API, he read this file like this:
public function make(){
if(file_exists("web/uploads/make/make.json")){
$make = file_get_contents('web/uploads/make/make.json');
echo ($make);
}else{
return false;
}
die;
}
So, Thank for help me.

Related

I want to display a php code shortcode in JavaScript, how do I do that?

This is my code
enter image description here
<script>
let myDiv = document.createElement("div");
myDiv.classList.add('test');
let my_var = `<?php echo do_shortcode("[elementor-template id="5078"]"); ?>`;
myDiv.innerHTML = my_var;
document.querySelector("#instagram").appendChild(myDiv);
</script>
Actually, it is not possible to do it this way because the script is being fired on the client-side while the PHP interpreter is working on the server-side.
If you are sure that you need to use JS to render some PHP code, I'd suggest sending a request using wp_ajax https://codex.wordpress.org/AJAX_in_Plugins to send a request on a server, and then the server can return any PHP code result that you want. Don't forget that shortcodes may use additional assets that will not be sent as a response.
The best way is to use shortcodes in a native form inside the content or PHP templates. Especially the elementor template where you can create template parts for different places of the website easily.
It's an enclosure problem:
You used nested double quotes in your php – resulting in breaking the echo.
Provided, your <script> tag is in your template php (so your php shortcode could be parsed) try this (replace the shortcode double quotes by single quotes):
<script>
let myDiv = document.createElement("div");
myDiv.classList.add('test');
let my_var = `<?php echo do_shortcode("[elementor-template id='5078']"); ?>`;
myDiv.innerHTML = my_var;
document.querySelector("#instagram").appendChild(myDiv);
</script>

how to put laravel echo function in javascript

How to use echo in strings in javascript datatable
className:'text-center',
data:'stage',
name:'stage',
render: function(data)
{
return '<td class="text-center">{{trans('stage.'' + data.stage + ')}}</td>';
}
error: syntax error, unexpected ''+ data.stage +'' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ')'
I have tried escaping using backlash it still doesnt look right.
<td class="text-center">{{trans('stage.'.$sub->stage)}}</td>
//this is what i want to display if i were to use laravel blade
Blade is rendered before you hit the page. So you cannot do what you're trying to, like this. I would recommend using xDebug to see how this works more consistently
If you want to include a translated variant of text in the variable stage, you either need to fetch some HTML and pass it back rendered, via an ajax request for example
OR
You can write/use a javaScript helper which will translate text for you.
OR (best)
You can write an accessor/getter on stage which will translate it before it's received by your DataTable
This would mean writing the following on the Model where the attribute stage comes from. Please note, prefixed Method name with 'get' and 'Attribute' as the suffix.
public function getStageAttribute()
{
return trans($this->stage);
}
For more information please see https://laravel.com/docs/8.x/eloquent-mutators#defining-an-accessor

Unable to find why base64 image code is invalid

Can anyone tell me why the base64 image code linked in here is invalid? Some kind of issue with the syntax I believe?
My file looks like this:
/9j/4AAQSkZJR..........39b/lRk5HGVz8
I have truncated it (the "...") since the entirety of the file won't fit in the question.
Here is my Javascript Fetch API POST code:
function submitPhoto(){
console.log("name: "+name);
console.log("email: "+email);
console.log("market: "+market);
//console.log("base64: "+b64data);
fetch('http://fanbeauties.com/app/submit-photo.php?pass=MY_PASS', {
method: "POST",
headers: {
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
},
body: '&name='+name+'&email='+email+'&market='+market+'&picture='+b64data
});
};
Yes I believe the syntax is not correct and it may not be a valid image or some parts are removed.
check this link https://jsfiddle.net/casiano/xadvz/
<img src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CDAYFDFj4OmwbY7bDGdBhtrnTQYOigeChUmc1K3QTnAUfEgGFgAWt88hKA6aCRIXhxnQ1yg3BCayK44EWdkUQcBByEQChFXfCB776aQsG0BIlQgQgE8qO26X1h8cEUep8ngRBnOy74E9QgRgEAC8SvOfQkh7FDBDmS43PmGoIiKUUEGkMEC/PJHgxw0xH74yx/3XnaYRJgMB8obxQW6kL9QYEJ0FIFgByfIL7/IQAlvQwEpnAC7DtLNJCKUoO/w45c44GwCXiAFB/OXAATQryUxdN4LfFiwgjCNYg+kYMIEFkCKDs6PKAIJouyGWMS1FSKJOMRB/BoIxYJIUXFUxNwoIkEKPAgCBZSQHQ1A2EWDfDEUVLyADj5AChSIQW6gu10bE/JG2VnCZGfo4R4d0sdQoBAHhPjhIB94v/wRoRKQWGRHgrhGSQJxCS+0pCZbEhAAOw==">
the format should likely began with this: data:image/gif;base64, or just this image/gif;base64, so first section shows image type. in your case it should be image/jpeg and the ;base64, is like defining that its a base64 inline image.
And at the end of the code or just end of anybase64 coded content there should be like == or = but you should not remove it its part of the coded content.
So this is another answer. I post it separately, cause your question is changed.
There is two way to achieve this. First is to use URL-encode and URL-decode. So before you send the base64 string containing your image data u do encode it then on the server side you first echo is to see how it looks. Then you use PHP urldecode to get your string back.
URL decode/encode with javascript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
URL decode/encode in PHP:
http://php.net/manual/en/function.urlencode.php
https://stackoverflow.com/a/4744917/9453736
But the other way which should fit better in this situation is to use the post body when u wanna post something. But as you are already using a library to do that I guess its just the limitation of your library. So try to check if there are other ways to set parameters for POST with that library. Like you are adding the parameters to body but the way you do it (the library) just limits you. so for example you cant use some characters when you do this:
{
body: '&name='+name+'&email='+email+'&market='+market+'&picture='+b64data
{
So in case you failed to find other ways to do the request. Like you can do it with form object with pure javascript and other ways. so in case you failed just go with the first one try to url encode the data.
example of url encode in javascript:
// encodes characters such as ?,=,/,&,:
console.log(encodeURIComponent('?x=шеллы'));
// expected output: "%3Fx%3D%D1%88%D0%B5%D0%BB%D0%BB%D1%8B"
console.log(encodeURIComponent('?x=test'));
// expected output: "%3Fx%3Dtest"
example of urldecode in PHP:
$query = "my=apples&are=green+and+red";
foreach (explode('&', $query) as $chunk) {
$param = explode("=", $chunk);
if ($param) {
printf("La valeur du paramètre \"%s\" est \"%s\"<br/>\n", urldecode($param[0]), urldecode($param[1]));
}
}

Url insertion in ES6 Template literlals

I have a Json file containing many objects and I want to display them using the template literals syntax in ES6. I need to display a set of images but cant passes any URL because it seems to delete the // of the address. Else everything works perfectly.
The problem seems to come from the innerHTML function because when I console log the variable containing the HTML code to be inserted the URL is written perfectly.
I would like to figure out how to fix this and display my images correctly
( the HTML inside the template literal is way longer, I just simplified it for here )
const resultat = document.querySelector('.master-wrapper'); //where the result appear
const html = pokedex.map(pokedex => {
return `
<img src" ${ pokedex.img } "></img> //where the url is inserted
`;
}).join('')
resultat.innerHTML += html;
You are missing the = sign here and because of that the browser renders it as separate attributes removing the slashes.
<img src=" ${ pokedex.img } "></img> //where the url is inserted

How do I select a specific json string from a url for displaying in a webview?

I am getting a json string parameter from my javascript files as follows :
http://local/action/?action=loadFile&params=%7B%22fileChart%22%3A%22url%22%2C%22item%22%3A%7B%22DocId%22%3A%2270078903%22%2C%22Headline%22%3A%22Alert%253A%2520AAPL%253A%2520QA%2520Test%22%2C%22PrimaryTickers%22%3A%22AAPL.O%22%2C%22ArrivalDate%22%3A%222015-04-29T08%3A04%3A40Z%22%2C%22fileType%22%3A%22url%22%2C%22secondaryFileType%22%3A%22pdf%22%2C%22secondaryFileExtension%22%3A%22pdf%22%2C%22curDate%22%3A1435589346483%2C%22Pages%22%3A8%2C%22url%22%3A%22https%253A%252F%252Fuat.citivelocity.com%252Frendition%252Feppublic%252FdocumentService%252FdXNlcl9pZD0mYWN0aW9uPXZpZXc%252FZmlsZV9uYW1lPVZTNkoucGRm%22%2C%22contributor%22%3A%22Citi%20-%20Linkback%20Test%22%7D%7D&requestType=GET&timestamp=1435589346484
I want to display only the url part of the above url, such that I can decode https for the given link and display only the required link in a webview loadurl. In the case of the above link it's : https://uat.citvelocity.com ..etc ,
The current idea I got from searching online is something like this :
webview.loadurl("javascript:(function() { "| "document.getElementByTagName('url')[0].style.display="+";"+"})()"); }
});
But that doesn't work as expected. Am I doing it wrong? Any ideas ?
Since your string is JSON, it's probably a good idea to just parse that JSON into an object so you can just use the objects properties to get whatever you want.
var decoded = decodeURIComponent('http://local/action/?action=loadFile&params=%7B%22fileChart%22%3A%22url%22%2C%22item%22%3A%7B%22DocId%22%3A%2270078903%22%2C%22Headline%22%3A%22Alert%253A%2520AAPL%253A%2520QA%2520Test%22%2C%22PrimaryTickers%22%3A%22AAPL.O%22%2C%22ArrivalDate%22%3A%222015-04-29T08%3A04%3A40Z%22%2C%22fileType%22%3A%22url%22%2C%22secondaryFileType%22%3A%22pdf%22%2C%22secondaryFileExtension%22%3A%22pdf%22%2C%22curDate%22%3A1435589346483%2C%22Pages%22%3A8%2C%22url%22%3A%22https%253A%252F%252Fuat.citivelocity.com%252Frendition%252Feppublic%252FdocumentService%252FdXNlcl9pZD0mYWN0aW9uPXZpZXc%252FZmlsZV9uYW1lPVZTNkoucGRm%22%2C%22contributor%22%3A%22Citi%20-%20Linkback%20Test%22%7D%7D&requestType=GET&timestamp=1435589346484'),
json = JSON.parse(decoded.slice(decoded.indexOf('&params=') + 8, decoded.indexOf('&requestType'))),
url = decodeURIComponent(json.item.url);

Categories

Resources