/** * Generate the widget and return it as string * * @return string */ public function generate() { $action = Input::get('actionPSTag'); $tags = Input::get('ps_tags'); $requestUri = Environment::get('requestUri'); $requestUri = Helper::removeRequestTokenFromUri($requestUri); if ($action && $action == 'updateTags') { $this->updateTags($tags); } if ($action && $action == 'removeTags') { $this->removeTags($tags); } $GLOBALS['TL_JAVASCRIPT'][] = $GLOBALS['PS_PUBLIC_PATH'] . 'vendor/mootagify.js|static'; $GLOBALS['TL_CSS'][] = $GLOBALS['PS_PUBLIC_PATH'] . 'css/mootagify-bootstrap.css|static'; $GLOBALS['TL_CSS'][] = $GLOBALS['PS_PUBLIC_PATH'] . 'css/mootagify.css|static'; $options = $this->options ? $this->options : array(); $script = sprintf('<script>' . 'window.addEvent("domready", function(){ var tagify = new mooTagify(document.id("tagWrap_%s"), null ,{ autoSuggest: true, availableOptions: ' . json_encode($options) . ' }); tagify.addEvent("tagsUpdate", function(){ var tags = tagify.getTags(); document.id("ctrl_%s").set("value", tags.join()); new Request({url: "%s&actionPSTag=updateTags"}).get({"ps_tags": tags, "rt": Contao.request_token }); }); tagify.addEvent("tagRemove", function(tag){ var tags = tagify.getTags() var deleted = tag; document.id("ctrl_%s").set("value", tags.join()); new Request({url: "%s&actionPSTag=removeTags"}).get({ "ps_tags": deleted, "rt": Contao.request_token }); }); });' . '</script>', $this->strId, $this->strId, $requestUri, $this->strId, $requestUri); return sprintf('<input type="hidden" id="ctrl_%s" name="%s" value="%s"><div id="tagWrap_%s" class="hide"> <div class="tag-wrapper"></div> <div class="tag-input"> <input type="text" id="listTags" class="tl_text" name="listTags" value="%s" placeholder="%s"> </div> <div class="clear"></div></div>' . $script . '', $this->strId, $this->strName, specialchars($this->varValue), $this->strId, specialchars($this->varValue), $GLOBALS['TL_LANG']['MSC']['TagTextField']['tag']); }
/** * @param $db * @param $doTable * @param $table * @return null|string */ public function setTitle($db, $doTable, $table) { // sorted by priority if (!$doTable) { return null; } $colsForTitle = $this->modules[$doTable]['title']; array_unshift($colsForTitle, 'ps_title'); $colsForTitle = $colsForTitle ? $colsForTitle : array(); // hook for custom title if ($this->modules[$doTable] && is_array($this->modules[$doTable]['setCustomTitle'])) { foreach ($this->modules[$doTable]['setCustomTitle'] as $callable) { $this->import($callable[0]); return $this->{$callable[0]}->{$callable[1]}($table, $db, $colsForTitle, $doTable); } } foreach ($colsForTitle as $title) { if (!$db[$title]) { continue; } $ct = deserialize($db[$title]); // check if value is serialize if (is_array($ct) && !empty($ct)) { $meta = Helper::parseStrForMeta($db[$title]); $db[$title] = $meta; } if ($db[$title] && (is_string($db[$title]) || is_numeric($db[$title]))) { $return = $db[$title]; $return = Controller::replaceInsertTags($return); $return = strip_tags($return); $return = trim($return); return $return; break; } } return null; }