1) It's much more resilient than direct template modding with vQmod
2) It doesn't add loads of extra javascript to the page
3) It's more secure since effects can't be disabled in the browser
The problem I'm having is that the default OpenCart theme (and by extension many custom ones) has javascript with embedded HTML. It really throws a wrench in parsing/saving the template HTML. I've tried using the PHP DOMDocument class and PHP Simple HTML DOM Parser with no luck. Does anyone have experience with any other libraries that might be able to get around the issue?
-Ryan
OPENCART MODULE :
Opencart Compare Link Link your compared product to forum/email
Frontend Link From Admin Dashboard Get link to product , category, manufacturer, information from admin backend.
Copy and DIRECTLY Edit Product the easy way.
Custom Product Sort Full control to product sorting options
Already Sold Product Module, shows total product sold
Code: Select all
$('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
The smart thing would be to get rid of all the embedded script in the templates but that's obviously not an option. I've tried DOMDocument and PHP Simple HTML DOM Parser with no luck (I believe I had the issue with phpQuery also but I'd have to check my old work).
-Ryan
Code: Select all
<script type="text/javascript"><!--
.... javascript code ....
//--></script>
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
Same thing unfortunately. OpenCart already has the tags, in fact.JNeuhoff wrote:What happens if your Javascript code is wrapped up in a HTML comment
I just intercepted the output in response.php before it's echoed out.BTW.: I have been thinking about using the PHP DOM parser for changing tpl-files for quite a while, too. Doing it via VQmod, or even directly with str_replace() calls, is not an elegant way. Picking DOM elemens by their ids and then manipulating them with dom seems to be a better approach. However, there are some tpl-files which contain sections of HTML with some unclosed tags, such as the header.tpl which has an opening <body> tag, but no matching </body>.
Code: Select all
public function output() {
if ($this->output) {
if ($this->level) {
$ouput = $this->compress($this->output, $this->level);
} else {
$ouput = $this->output;
}
if (!headers_sent()) {
foreach ($this->headers as $header) {
header($header, true);
}
}
echo $this->editDom($ouput);
}
}
private function editDom($html) {
libxml_use_internal_errors(true);
$dom = new DOMDocument('1.0','UTF-8');
$dom->loadHTML($html);
// voodoo
$output = $dom->saveHTML();
return $output;
}
-Ryan
I see. Still, would be nice if the tpl files could be manipulated with a DOM parser instead of VQmod for 3rd party extensions. By the time you intercept the output in the response.php all PHP code has already been executed. Also, bear in mind the output could be compressed!rph wrote:JNeuhoff wrote: I just intercepted the output in response.php before it's echoed out.
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
I don't think it's too big a deal. If you wanted to use the controller data you could just edit in something like:JNeuhoff wrote:By the time you intercept the output in the response.php all PHP code has already been executed.
Code: Select all
$template = new Template();
$template->data = $this->data; // Or whatever data you want to pass
$element = $template->fetch('mod/twitter/template/product/product-twitter.tpl');
$this->response->setDomEdit('add_child', 'id', 'tabs', $element);
That's easy enough to move around.Also, bear in mind the output could be compressed!
None of this really matters with the embedded javascript issue though.
-Ryan
Opencart Options Pro, Reward Points For Review, DISQUS Comment Form,
Dolrich Fortich - Freelance web developer
Just to make sure I correctly understood you: You basically want to parse the whole HTML template, do some DOM tree manipulation, and then output the modified DOM tree as the new template HTML. All of this while treating any script-tag as a whole DOM-node (no parsing inside the script tag). Is that correct?None of this really matters with the embedded javascript issue though.
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
The only two things left I know to try are checking out the html5lib on the off-chance that'll work or break down and use a regex.
-Ryan
Can't you just replace all instances of <script ....> and </script> with something like <div><!--start of script--><![CDATA[ and ]]><!--end of script--></div> before loading and parsing the HTML with a DOM parser, and reverse the replacement after the final output has been re-generated?rph wrote:The ultimate issue is the DOMDocument class is parsing embed HTML within a <script> tag which breaks things.
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
-Ryan
Users browsing this forum: No registered users and 16 guests