I have just upgraded to 1.11.4 (From a quote old version and has taken me AGES).
Anyway, I have tested everything and almost all is fine (there was loads of modules to upgrade, loads of out of date code, loads of issues).
However, there is one remaining UDT that breaks the site - when I say breaks, everything works fine, the functionality of the UDT is not lost -it is supposed to display adverts, and it all works as it should.
I can edit and save the UDT.
BUT, as long as the UDT is called in the template, the template will not update - so if I add some code to the template, it will not update unless I remove reference to the UDT.
Annoying thing, is that the UDT does not contain any CMSMS specific functions, but rather it is a big PHP script for displaying adverts (its a script from text-link-ads).
I have no idea where to start looking for issues, just wondering if anyone has any pointers as to what could cause this sort of issue...?
PHP in UDT is breaking CMSMS after upgrade to 1.11.4
Re: PHP in UDT is breaking CMSMS after upgrade to 1.11.4
And the content of that UDT is...?
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Re: PHP in UDT is breaking CMSMS after upgrade to 1.11.4
Thought you might ask that:)
Ill post it, give me 20 min...
Ill post it, give me 20 min...
Re: PHP in UDT is breaking CMSMS after upgrade to 1.11.4
Here is the code (not sure if there is anything in here that I shouldnt be publishing on a public forum though...
Code: Select all
function tla_ads()
{
// Number of seconds before connection to XML times out
// (This can be left the way it is)
$CONNECTION_TIMEOUT = 15;
// Local file to store XML
// This file MUST be writable by web server
// You should create a blank file and CHMOD it to 666
$LOCAL_FILENAME = 'local_25xxxx.xml';
// example methods are BIG-5 ISO for fill list see http://www.php.net/manual/en/function.mb-list-encodings.php
// example with windows encoding $OUTPUTE_DECODING = 'windows-1251';
$OUTPUT_DECODING = false;
// make sure output decoding is an option with iconv existing
$OUTPUT_DECODING = $OUTPUT_DECODING && function_exists('iconv') ? $OUTPUT_DECODING : false;
if (!file_exists($LOCAL_FILENAME)) {
@touch($LOCAL_FILENAME);
@chmod($LOCAL_FILENAME, 0666);
}
if (!file_exists($LOCAL_FILENAME)) {
die("Script error: $LOCAL_FILENAME does not exist. Please create a blank file named $LOCAL_FILENAME.");
}
if (!is_writable($LOCAL_FILENAME)) {
die("Script error: $LOCAL_FILENAME is not writable. Please set write permissions on $LOCAL_FILENAME.");
}
if (filemtime($LOCAL_FILENAME) < (time() - 3600) || filesize($LOCAL_FILENAME) < 3) {
$url = 'http://www.text-link-ads.com/xml.php?k=66UGPY3SOTHR22O40CBZ&l=php-tla-2.0.5';
if (function_exists('json_decode') && is_array(json_decode('{"a":1}', true))) {
$url .= '&f=json';
}
tla_updateLocal($url, $LOCAL_FILENAME, $CONNECTION_TIMEOUT);
}
$xml = tla_getLocal($LOCAL_FILENAME);
$links = tla_decode($xml);
if ($links && is_array($links)) {
echo "\n<ul>\n";
foreach ($links as $link) {
if (isset($link['PostID']) && $link['PostID'] > 0) {
continue;
}
if ($OUTPUT_DECODING) {
$beforeText = ($link['BeforeText'] ? iconv('UTF-8', $OUTPUT_DECODING, $link['BeforeText']) . ' ' : '');
$afterText = ($link['AfterText'] ? ' ' . iconv('UTF-8', $OUTPUT_DECODING, $link['AfterText']) : '');
$text = iconv('UTF-8', $OUTPUT_DECODING, $link['Text']);
} else {
$beforeText = ($link['BeforeText'] ? $link['BeforeText'] . ' ' : '');
$afterText = ($link['AfterText'] ? ' ' . $link['AfterText'] : '');
$text = $link['Text'];
}
echo "<li>" . $beforeText . '<a href="' . $link['URL'] . '">' . $text . '</a>' . $afterText . "</li>\n";
}
echo '</ul>';
}
}
function tla_updateLocal($url, $file, $time_out)
{
@touch($file);
if ($xml = file_get_contents_tla($url, $time_out)) {
if ($handle = fopen($file, 'w')) {
fwrite($handle, $xml);
fclose($handle);
}
}
}
function tla_getLocal($file)
{
if (function_exists('file_get_contents')) {
return file_get_contents($file);
}
$contents = '';
if ($handle = fopen($file, 'r')) {
$contents = fread($handle, filesize($file) + 1);
fclose($handle);
}
return $contents;
}
function file_get_contents_tla($url, $time_out)
{
$result = '';
$urlInfo = parse_url($url);
if ($handle = @fsockopen($urlInfo['host'], 80)) {
if (function_exists('socket_set_timeout')) {
socket_set_timeout($handle, $time_out, 0);
} else if (function_exists('stream_set_timeout')) {
stream_set_timeout($handle, $time_out, 0);
}
fwrite($handle, 'GET ' . $urlInfo['path'] . '?' . $urlInfo['query'] . " HTTP/1.0\r\nHost: " . $urlInfo['host'] . "\r\nConnection: Close\r\n\r\n");
while (!feof($handle)) {
$result .= @fread($handle, 40960);
}
fclose($handle);
} else if (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $time_out);
curl_setopt($ch, CURLOPT_TIMEOUT, $time_out);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
}
$return = '';
$capture = false;
foreach (explode("\n", $result) as $line) {
$char = substr(trim($line), 0, 1);
if ($char == '[' || $char == '<') {
$capture = true;
}
if ($capture) {
$return .= $line . "\n";
}
}
return $return;
}
function tla_decode($str)
{
if (!function_exists('html_entity_decode')) {
function html_entity_decode($string)
{
// replace numeric entities
$string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\1"))', $string);
$string = preg_replace('~&#([0-9]+);~e', 'chr(\1)', $string);
// replace literal entities
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
}
}
if (substr($str, 0, 1) == '[') {
$arr = json_decode($str, true);
foreach ($arr as $i => $a) {
foreach ($a as $k => $v) {
$arr[$i][$k] = tla_decode_str($v);
}
}
return $arr;
}
$out = '';
$retarr = '';
preg_match_all("/<(.*?)>(.*?)</", $str, $out, PREG_SET_ORDER);
$n = 0;
while (isset($out[$n])) {
$retarr[$out[$n][1]][] = tla_decode_str($out[$n][0]);
$n++;
}
if (!$retarr) {
return false;
}
$arr = array();
$count = count($retarr['URL']);
for ($i = 0; $i < $count; $i++) {
$arr[] = array(
'BeforeText' => $retarr['BeforeText'][$i],
'URL' => $retarr['URL'][$i],
'Text' => $retarr['Text'][$i],
'AfterText' => $retarr['AfterText'][$i],
);
}
return $arr;
}
function tla_decode_str($str)
{
$search_ar = array('<', '>', '"');
$replace_ar = array('<', '>', '"');
return str_replace($search_ar, $replace_ar, html_entity_decode(strip_tags($str)));
}
tla_ads();
print ("
</div>
");
Re: PHP in UDT is breaking CMSMS after upgrade to 1.11.4
Havent got a clue what is all happening here, but what does this in the bottom do?If you want to narrow down where the problem is, cut out parts of the code and try if you can work in the template again...
Code: Select all
tla_ads();
print ("
</div>
");
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
Re: PHP in UDT is breaking CMSMS after upgrade to 1.11.4
CMSMS executes your UDT from within the admin area when editing a template,or a content page using that template. I would bet that for some reason your script is failing, and dieing. Probably related to path issues.
I suggest you modify your functions to:
a: use debug_display, debug_to_log, or audit() to output debug information to various places (the screen, a log file, or the cmsms admin log)
b: do not die() but rather return with no output.
I suggest you modify your functions to:
a: use debug_display, debug_to_log, or audit() to output debug information to various places (the screen, a log file, or the cmsms admin log)
b: do not die() but rather return with no output.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Re: PHP in UDT is breaking CMSMS after upgrade to 1.11.4
Rolf-
The first bit actually calls the function (which pulls ads from the publisher server, the second bit is just me closing a div opened at start of udt.
The function is definitely the cause - but I'm struggling to pinpoint issue because I don't really understand the function and this finding it hard to disable parts in order to find the problem.
Calguy, thanks ill try as you suggest.
Thanks to you both guys, ill do some more investigation and come back.
By the way, off topic, but when and where is geek moot this year?
The first bit actually calls the function (which pulls ads from the publisher server, the second bit is just me closing a div opened at start of udt.
The function is definitely the cause - but I'm struggling to pinpoint issue because I don't really understand the function and this finding it hard to disable parts in order to find the problem.
Calguy, thanks ill try as you suggest.
Thanks to you both guys, ill do some more investigation and come back.
By the way, off topic, but when and where is geek moot this year?