Support community for TTG plugins and products.
NOTICE
The Turning Gate's Community has moved to a new home, at https://discourse.theturninggate.net.
This forum is now closed, and exists here as a read-only archive.
You are not logged in.
Pages: 1
Hello,
I am setting the cart now and have an error when I want to put links in the Checkbox.
In the Edit Checkbox area there is a field "text" with an info box. I understand the information like that: using the first item written in the info box creates a text with some kind of button/ link that opens a box with the "external text" (this was already working in my CE3-page; I am replacing it currently). Using the second item written in the info box creates a text with a link to an extra page. I want to use both: first a sentence that opens the box with the "external text" and afterwards a sentence with a link that leads to a pdf (to give the possibility to download or print). My code for this (I think this is according to the info box):
Ich akzeptiere die [[AGB]]. [[Hier=http://peak-prints.com/agb/AGB-PW.pdf]] auch als pdf.
When I update the settings an error message appears, I cannot reset it, only copy the previous state from my computer to the server... What's wrong with my code - or anything else?
error message:
preg_replace() [function.preg-replace]: Compilation failed: missing terminating ] for character class at offset 63|#0 [internal function]: ErrorHandler::handleError(2, 'preg_replace() ...', '/www/htdocs/w00...', 67, Array) #1 /www/htdocs/w00e5401/ttg-be/cart/application/models/Checkbox.php(67): preg_replace('/\[\[AGB]]. [[H...', 'AGB]]. [[Hier', 'Ich akzeptiere ...') #2 /www/htdocs/w00e5401/ttg-be/cart/application/models/Checkbox.php(16): Checkbox->buildTitles() #3 /www/htdocs/w00e5401/ttg-be/cart/application/dao/CheckboxDAO.php(19): Checkbox->__construct(Array) #4 /www/htdocs/w00e5401/ttg-be/framework/dao/GenericDAO.php(80): CheckboxDAO->transformRow(Array) #5 /www/htdocs/w00e5401/ttg-be/cart/application/dao/CheckboxDAO.php(39): GenericDAO->getAllItems(Array) #6 /www/htdocs/w00e5401/ttg-be/cart/application/helpers/ApplicationHelper.php(67): CheckboxDAO->getAllCheckboxes() #7 /www/htdocs/w00e5401/ttg-be/framework/helpers/GenericApplicationHelper.php(28): ApplicationHelper->createConfigManager() #8 /www/htdocs/w00e5401/ttg-be/cart/application/init.php(9): GenericApplicationHelper->getConfigManager() #9 /www/htdocs/w00e5401/ttg-be/framework/init.php(112): include_once('/www/htdocs/w00...') #10 /www/htdocs/w00e5401/ttg-be/cart/index.php(21): require_once('/www/htdocs/w00...') #11 {main}|URL: /ttg-be/cart/index.php
Best regards
Wolfgang
Offline
Hi Wolfgang, that's a pretty interesting error, and quite spectacular in it's effect.
Looking into the code, it looks like my pattern matching for [[tokens]] does not work as it should. With a single [[token]], the correct text of 'token' is found. With two tokens such as '[[one]] something [[two]]', an incorrect token of 'one]] something [[two' is found (i.e. everything between the first [[ to the last ]]), instead of two tokens of 'one' and 'two'.
Anyway, that makes it crash. I'll work on a fix. In the mean time the solution is to only have a maximum of one item in the title in between [[ and ]]. In your case, only [[AGB]] or [[Hier=http://peak-prints.com/agb/AGB-PW.pdf]], not both.
Offline
Thank you for your answer. I will do as you say (and would be glad if a solution is found for using both...).
Best regards
Wolfgang
Offline
Hi Wolfgang, I've worked through a solution. We'll probably update the cart with the fix in a silent release. This is the first time somebody has tried using both a pop-up link and a URL in the title in the two or so years since that code was written.
If you'd like to use the fix before we release it, the code to change is the buildTitles() function in ttg-be/cart/models/Checkbox.php. The new code is:
function buildTitles()
{
if (!isset($this->attributes['title']))
return '';
$title = $this->attributes['title'];
$matches = array();
$textLinks = preg_match_all('/\[\[(.*?)\]\]/i', $title, $matches);
if ($textLinks) {
$plainTitle = $title;
for ($i = 0; $i < count($matches[0]); $i++) {
$full = $matches[0][$i];
$inner = $plainInner = $matches[1][$i];
$preg_inner = str_replace('/', '\/', $inner);
if (($split = CartHelper::splitToKeyValue($inner, '=')) !== false) {
$replace = '<a href="' . $split['value'] . '" onclick="window.open(\'' . $split['value'] . '\'); return false;">' . $split['key'] . '</a>';
$plainInner = $split['key'];
} else {
$replace = '<a href="#" class="' . $this->param() . '">' . $inner . '</a>';
$this->hasExternalText = true;
}
$plainTitle = preg_replace('/\[\[' . $preg_inner . '\]\]/', $plainInner, $plainTitle);
$title = preg_replace('/\[\[' . $preg_inner . '\]\]/', $replace, $title);
}
$this->plainTitle = $plainTitle;
}
else {
$this->plainTitle = $title;
}
if ($this->required()) {
$title .= ' *';
}
$this->title = $title;
}
Offline
The above change will also let you multiple link in the form of [[clickable=http://somewhere.com]], as well as multiple [[popup]] links (all of which would open the same popup text).
Offline
Thanks a lot. I have tested with only one link, it works well. Great!
(just as background: the German requirements for online shops have some requirements such as "terms and conditions have to be readable, printable and able to save/download". Maybe I am too cautious, but I want to be sure to meet the requirements and think with the additional pdf link I can do this...)
Wolfgang
Offline
Pages: 1