Website blank - solution
Posted: 23 Jan 2011, 21:23
Hi Jan,
It's been a while since I wrote last time on this forum.
I had problem with website going blank almost two years ago and we had a discussion back then. At that time I solved problem by using str_replace.
Now I can offer you solution that probably will resolve this issue for good if you accept it.
I came on idea of using "Simple HTML DOM Parser" (I saw usage of it in some other plug-in).
You can download it from site http://simplehtmldom.sourceforge.net/ and it's licensed under MIT license.
So to short my story in file phocapdfcontent.pdf you include this library
and the you modify code like this
Notice usage of foreach for parsing each link element individually. So preg_replace won't hit any limitation because of to many links on site. In fact it deals with only one link at the time. Of course code can be further modified to avoid using preg_replace at all but I think that this can be solution for good without further modifications. Maybe a good idea would be to make foreach loop for every place where preg_replace is and then leave out big one. This could be option to avoid if/else in loop.
I hope that you can use something of this to solve problem.
It's been a while since I wrote last time on this forum.
I had problem with website going blank almost two years ago and we had a discussion back then. At that time I solved problem by using str_replace.
Now I can offer you solution that probably will resolve this issue for good if you accept it.
I came on idea of using "Simple HTML DOM Parser" (I saw usage of it in some other plug-in).
You can download it from site http://simplehtmldom.sourceforge.net/ and it's licensed under MIT license.
So to short my story in file phocapdfcontent.pdf you include this library
Code: Select all
include_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_phocapdf'.DS.'helpers'.DS.'simple_html_dom.php');
Code: Select all
if ($doctype == 'html') {
$bodySite = JResponse::getBody();
$html = str_get_html($bodySite);
foreach($html->find('a') as $link){
if ($pdfDestination == 'I' || $pdfDestination == 'D') {
// Remome OnClick
if ($sefEnabled == 1) {
$pattern = '/<a(.+)href="(.*)\.pdf\?(.*)"(.+)onclick="(.*)"/Ui';
$replacement = '<a $1href="$2.pdf?format=phocapdf&$3"$4';
$link->outertext = preg_replace($pattern, $replacement, $link);
} else if ($sefEnabled == 2) {
$pattern = '/<a(.+)href="(.*)\.pdf(.*)"(.+)onclick="(.*)"/Ui';
$replacement = '<a $1href="$2.pdf?format=phocapdf$3"$4';
$link->outertext = preg_replace($pattern, $replacement, $link);
} else {
$pattern = '/<a(.+)href="(.*)format=pdf(.*)"(.+)onclick="(.*)"/Ui';
$replacement = '<a $1href="$2format=phocapdf$3"$4';
$link->outertext = preg_replace($pattern, $replacement, $link);
}
} else {
$browser = PhocaPDFHelperBrowser::browserDetection('browser');
if ($sefEnabled == 1) {
$pattern = '/<a(.+)href="(.*)\.pdf\?(.*)"(.+)onclick="(.*)"/Ui';
if ($browser == 'msie7' || $browser == 'msie8') {
$replacement = '<a $1href="$2.pdf?format=phocapdf&$3"$4 target="_blank"';
} else {
$replacement = '<a $1href="$2.pdf?format=phocapdf&$3"$4 onclick="$5"';
}
$link->outertext = preg_replace($pattern, $replacement, $link);
} else if ($sefEnabled == 2) {
$pattern = '/<a(.+)href="(.*)\.pdf(.*)"(.+)onclick="(.*)"/Ui';
if ($browser == 'msie7' || $browser == 'msie8') {
$replacement = '<a $1href="$2.pdf?format=phocapdf$3"$4 target="_blank"';
} else {
$replacement = '<a $1href="$2.pdf?format=phocapdf$3"$4 onclick="$5"';
}
$link->outertext = preg_replace($pattern, $replacement, $link);
} else {
$pattern = '/<a(.+)href="(.*)format=pdf(.*)"(.+)onclick="(.*)"/Ui';
if ($browser == 'msie7' || $browser == 'msie8') {
$replacement = '<a $1href="$2format=phocapdf$3"$4 target="_blank"';
} else {
$replacement = '<a $1href="$2format=phocapdf$3"$4 onclick="$5"';
}
$link->outertext = preg_replace($pattern, $replacement, $link);
}
}
}
$bodySite = $html;
unset($html);
JResponse::setBody($bodySite);
}
I hope that you can use something of this to solve problem.