modify a <DIV> element with CURL - php

I know how to provide or modify a field with CURL curl_setopt function and to work with cookies, but what I could not find is how to modify an HTML element with CURL.
For instance, let's say I want to replace the function "submit_device_form" in below code
<div id="bottombuttons">
<table border="0" cellspacing="0" cellpadding="0" style="width:100%;">
<!-- buttons -->
<tr>
<td> </td>
<td class="separatorButton">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Set</td>
<td>Cancel</td>
</tr>
</table>
</td>
</tr>
<!-- fixes the width of the first column -->
<tr>
<td style="padding:0;"><img src="images/spacer.gif" alt="" width="200" height="1" border="0" ></td>
<td style="padding:0;"><img src="images/spacer.gif" alt="" width="360" height="1" border="0" ></td>
</tr>
</table>
</div>
with "submit_MY_form", a new JavaScript function included in my PHP script. How would I go for it?
I looked into the "PHP Simple HTML DOM Parser" library since it provides the setAttribute and removeAttribute functions that would allow me to do that easily, but then I miss the info on how to give it access to the page read wia CURL, so I'm stuck.
Thanks for your help,
Robert

Related

HTML Purifier for webmail

I'm working on small webmail client. For safely embedding html I want to use HTML Purifier (BTW: it's a good idea?).
I checked it with several emails and some problems. One email (from Google) is having something like this:
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="4%">
<td width="92%" style="padding-top:18px; padding-bottom:10px; opacity:0.7">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<td width="30%">
<img style="display:inline-block;" height="26" src="https://www.gstatic.com/local/guides/email/images/photo-impact/googlelogo_light_clr-f040d5d9.png">
<td>
<td width="70%" style="text-align:right">
</td>
</tbody>
</table>
Converts to:
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="4%">
</td><td width="92%" style="padding-top:18px;padding-bottom:10px;opacity:.7;">
</td><td width="30%">
<img style="display:inline-block;" height="26" src="https://www.gstatic.com/local/guides/email/images/photo-impact/googlelogo_light_clr-f040d5d9.png" alt="googlelogo_light_clr-f040d5d9.png">
</td><td>
</td><td width="70%" style="text-align:right;">
</td>
</tr></table>
I don't know why it remove second <table> tag (also it close wrong <td> and removes <tbody>). Is it possible to change HTML Purifier to make it work for those situations?

Convert HTML output to a different structure with PHP DOM

I have a simple HTML file that I need to read some values from and change the structure of for HTML email output. I'm fairly new to scripting/PHP/navigating the DOM, so forgive me if this is a simple question.
Below is the initial output:
<table id="Table_01" width="600" height="547" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2">
<img src="header.jpg" width="600" height="295" border="0" alt="Alt Text 1"></td>
</tr>
<tr>
<td>
<a href="http://url.com/1">
<img src="leftcell_link1.jpg" width="300" height="163" border="0" alt="Alt Text Left"></a></td>
<td>
<a href="http://url.com/2">
<img src="rightcell_link2.jpg" width="300" height="163" border="0" alt="Alt Text Right"></a></td>
</tr>
<tr>
<td colspan="2">
<a href="http://url.com/3">
<img src="body_link3.jpg" width="600" height="89" border="0" alt="Body Alt"></a></td>
</tr>
</table>
Here is the desired output:
<table id="Table_01" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" width="100%">
<img src="header.jpg" border="0" alt="Alt Text 1"></td>
</tr>
<tr>
<td width="50%">
<a href="http://url.com/1" name="link1">
<img src="leftcell_link1.jpg" border="0" alt="Alt Text Left" name="link1"></a></td>
<td width="50%">
<a href="http://url.com/2" name="link2">
<img src="rightcell_link2.jpg" border="0" alt="Alt Text Right" name="link2"></a></td>
</tr>
<tr>
<td colspan="2" width="100%">
<a href="http://url.com/3" name="link3">
<img src="body_link3.jpg" border="0" alt="Body Alt" name="link3"></a></td>
</tr>
</table>
Some things of note
The structure of the input file will not always be the same.
The "td" widths, which are based off a percentage of the width attribute of the child (or grandchild) "img" node compared to the total email width (in this case, 600px).
Attaching the custom "name" attribute to the "a" and "img" tags based off a substring of the image "src" attribute.
Would I be best to deconstruct the entire thing into an array of the required element attributes then reconstruct it in the correct format? Or would it be easier to loop through the DOM and look for the attributes I need then apply them to the parents and delete unnecessary attributes where needed?
And is there any way to handle this all recursively so that I don't need multiple levels of checks based on whether it's at the "td" "a" or "img" level?
You can change what you want with DOMDocument class.
<?php
$doc = new DOMDocument();
$doc->loadHTML('<table id="Table_01" width="600" height="547" border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="2"> <img src="header.jpg" width="600" height="295" border="0" alt="Alt Text 1"></td> </tr> <tr> <td> <img src="leftcell_link1.jpg" width="300" height="163" border="0" alt="Alt Text Left"></td> <td> <img src="rightcell_link2.jpg" width="300" height="163" border="0" alt="Alt Text Right"></td> </tr> <tr> <td colspan="2"> <img src="body_link3.jpg" width="600" height="89" border="0" alt="Body Alt"></td> </tr> </table>');
$tds = $doc->getElementsByTagName('td');
$tds[0]->setAttribute('width', '100%');
$tds[1]->setAttribute('width', '50%');
$tds[2]->setAttribute('width', '100%');
var_dump($doc->saveHTML());
?>
result:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
...
<td colspan="2" width="100%">
...
<td width="50%">
...
<td width="100%">
...
</html>
Please read documentation of this functions:
http://php.net/manual/en/class.domdocument.php

Severity: Warning --> fopen(./upload/ <table cellspacing="0"

I am using file read functionality in one my application.
Sometimes I am getting the exception while opening and closing file because in filename I am getting as HTML string, what do I need to do to protect application or to identify this is not the correct name?
Here is the full stack error.
ERROR - 2017-02-27 06:28:21 --> Severity: Warning --> fopen(./upload/
<table cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td class="titleBorderx" width="30">
<table height="25" cellspacing="2" cellpadding="0" width="25" bgcolor="black">
<tbody>
<tr>
<td id="L_default_x" class="x" valign="middle" align="center">X</td>
</tr>
</tbody>
</table>
</td>
<td class="titleBorder" id="L_default_2">Network Access Message:<span class="TitleDescription"> The page cannot be displayed</span> </td>
</tr>
</tbody>
</table>
<table id="spacer">
<tbody>
<tr>
<td height="10"></td></tr></tbody></table>
<table width="400">
<tbody>
<tr>
<td nowrap="" width="25"></td>
<td width="400"><span class="explain"><id id="L_default_3"><b>Explanation:</b></id></span><id id="L_default_4"> There is a problem with the page you are trying to reach and it cannot be displayed. </id><br><br>
<b><span class="tryThings"><id id="L_default_5"><b>Try the following:</b></id></span></b>
<ul class="TryList">
<li id="L_default_6"><b>Refresh page:</b> Search for the page again by clicking the Refresh button. The timeout may have occurred due to Internet congestion.
</li><li id="L_default_7"><b>Check spelling:</b> Check that you typed the Web page address correctly. The address may have been mistyped.
</li><li id="L_default_8"><b>Access from a link:</b> If there is a link to the page you are looking for, try accessing the page from that link.
</li></ul>
<id id="L_default_9">If you are still not able to view the requested page, try contacting your administrator or Helpdesk.</id> <br><br>
</td>
</tr>
</tbody>
</table>
<table id="spacer"><tbody><tr><td height="15"></td></tr></tbody></table>
<table width="400">
<tbody>
<tr>
<td nowrap="" width="25"></td>
<td width="400" id="L_default_10"><b>Technical Information (for support personnel)</b>
<ul class="adminList">
<li id="L_default_11">Error Code: 502 Proxy Error. The request was rejected by the HTTP filter. Contact your Forefront TMG administrator. (12217)
</li><li id="L_default_12">IP Address: 10.40.0.20
</li><li id="L_default_13">Date: 2/27/2017 6:28:21 AM [GMT]
</li><li id="L_default_14">Server: SYS2019.netsolpk.com
</li><li id="L_default_15">Source: web filter
</li></ul>
</td>
</tr>
</tbody>
</table>
): failed to open stream: File name too long /srv/users/serverpilot/apps/php/public/application/controllers/Readfile.php 159
Your fopen function has a too long string in it. And I also think this cant be valid. You are looking for a file in ./upload/ with the name:
<table cellspacing="0" cellpadding="0&quot...
The name is too long and invalid. I think you pass a variable to the fopen function the content of the variable isn't correct.

selecting/view one row from list

I'm quiet basic user of php & sql and wanted to do a shopping cart system I need your help for this script.
The result is all the list from the table is displayed from the page and i wanted to to have a popup page where if you click one of the product it will display from the popup
If you notice i added an anchor tag as this is the link which leads to a popup page the popup information is still under one page:
`
<table width="800px" border="0" cellpadding="0" cellspacing="7">
<? $result=mysql_query("select * from argentina");
while($row=mysql_fetch_array($result)){ ?>
<tr>
<td align="center" valign="top"><img src="../user/<?=$row["picture"]?>" height="130" /></td>
<td align="right" valign="top" bgcolor="#E0E0E0">
<table width="100%" border="0" cellspacing="0" cellpadding="15">
<tr>
<td width="78%" valign="top"><a class="inline" href="#inline_content"><strong><?=$row["name"]?></strong></a><br />
Variety: <?=$row["variety"]?> <br />
Apellation: <?=$row["apellation"]?> <br />
<td width="22%" valign="top"><?=$row["content"]?><br /><br /><br />
<input type="button" class="button-order" value="Order Now" href="contactus.php" />
//windpoppup
<div style="display:none">
<div id="inline_content" style="padding:10px;background:#fff;">
<p>
//Please provide code here
</div>
</p>
</div></div>
<p></td> </tr><br>
</table><br>
</td></tr><br>
<tr><td colspan="0"></td><? } ?><br>
</table></p>
</pre>
`
Thanks.
I would suggest you take a look at Codeigniter's Cart Class which is already well written. There is not much need to keep reinventing the wheel, but you can do so by reading their core if you wish :)
Cart Class (Obviously, you can do shopping cart with it, lots tutorial available if you do some research

put link on table row or any other way to put link

i have one php code for button creation
for($i=1;$i<=$n;$i++)
{
$row=mysql_fetch_array($result);
if($row['btn_color']==1)
$btbg="side-button5.png";
if($row['btn_color']==2)
$btbg="side-button6.png";
if($row['btn_color']==3)
$btbg="side-button7.png";
if($row['btn_color']==4)
?>
<br>
<table width="200" height="50" border="0" cellpadding="0" cellspacing="0">
<tr>
<td background="images/<?php echo $btbg ; ?>" style="background-repeat:no-repeat"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="66">
<div align="center" class="buttonside">
<p>
<a class="buttonside" href="vpa.php?pgid=<?php echo $row['page_id']; ?>">
<?php echo $row['btn_text']?></p>
</a>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?php
}
?>
this code is working fine but the link is on text, i want to put link on full button(background)
Thanks
To make the button 'linkable', you'll need to wrap the <a> tag around it.
However, you're going to need to change your HTML markup structure - you can't wrap an anchor around a table cell!

Categories