Check if an item can be translated
It be translated if translation if globally on and item is an instance of CommonDropdown
or CommonTreeDropdown and if translation is enabled for this class
static public canBeTranslated ( CommonGLPI $item ) : true | ||
$item | CommonGLPI | |
Résultat | true | if item can be translated, false otherwise |
/** * Print out (html) show item : question and answer * * @param $options array of options * * @return nothing (display item : question and answer) **/ function showFull($options = array()) { global $DB, $CFG_GLPI; if (!$this->can($this->fields['id'], READ)) { return false; } $linkusers_id = true; // show item : question and answer if (Session::getLoginUserID() === false && $CFG_GLPI["use_public_faq"] || $_SESSION["glpiactiveprofile"]["interface"] == "helpdesk" || !User::canView()) { $linkusers_id = false; } $this->updateCounter(); $knowbaseitemcategories_id = $this->fields["knowbaseitemcategories_id"]; $fullcategoryname = getTreeValueCompleteName("glpi_knowbaseitemcategories", $knowbaseitemcategories_id); $tmp = "<a href='" . $this->getSearchURL() . "?knowbaseitemcategories_id={$knowbaseitemcategories_id}'>" . $fullcategoryname . "</a>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='4'>" . sprintf(__('%1$s: %2$s'), __('Category'), $tmp); echo "</th></tr>"; echo "<tr><td class='left' colspan='4'><h2>" . __('Subject') . "</h2>"; if (KnowbaseItemTranslation::canBeTranslated($this)) { echo KnowbaseItemTranslation::getTranslatedValue($this, 'name'); } else { echo $this->fields["name"]; } echo "</td></tr>"; echo "<tr><td class='left' colspan='4'><h2>" . __('Content') . "</h2>\n"; echo "<div id='kbanswer'>"; if (KnowbaseItemTranslation::canBeTranslated($this)) { $answer = KnowbaseItemTranslation::getTranslatedValue($this, 'answer'); } else { $answer = $this->fields["answer"]; } echo Toolbox::unclean_html_cross_side_scripting_deep($answer); echo "</div>"; echo "</td></tr>"; echo "<tr><th class='tdkb' colspan='2'>"; if ($this->fields["users_id"]) { // Integer because true may be 2 and getUserName return array if ($linkusers_id) { $linkusers_id = 1; } else { $linkusers_id = 0; } printf(__('%1$s: %2$s'), __('Writer'), getUserName($this->fields["users_id"], $linkusers_id)); echo "<br>"; } if ($this->fields["date"]) { //TRANS: %s is the datetime of update printf(__('Created on %s'), Html::convDateTime($this->fields["date"])); echo "<br>"; } if ($this->fields["date_mod"]) { //TRANS: %s is the datetime of update printf(__('Last update on %s'), Html::convDateTime($this->fields["date_mod"])); } echo "</th>"; echo "<th class='tdkb' colspan='2'>"; if ($this->countVisibilities() == 0) { echo "<span class='red'>" . __('Unpublished') . "</span><br>"; } printf(_n('%d view', '%d views', $this->fields["view"]), $this->fields["view"]); echo "<br>"; if ($this->fields["is_faq"]) { _e('This item is part of the FAQ'); } else { _e('This item is not part of the FAQ'); } echo "</th></tr>"; echo "</table>"; return true; }
/** * Get KB answer, with id on titles to set anchors * * @return string */ public function getAnswer() { if (KnowbaseItemTranslation::canBeTranslated($this)) { $answer = KnowbaseItemTranslation::getTranslatedValue($this, 'answer'); } else { $answer = $this->fields["answer"]; } $answer = Toolbox::unclean_html_cross_side_scripting_deep($answer); $callback = function ($matches) { //1 => tag name, 2 => existing attributes, 3 => title contents $tpl = '<%tag%attrs id="%slug"><a href="#%slug">%icon</a>%title</%tag>'; $title = str_replace(['%tag', '%attrs', '%slug', '%title', '%icon'], [$matches[1], $matches[2], Toolbox::slugify($matches[3]), $matches[3], '<svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"/></svg>'], $tpl); return $title; }; $pattern = '|<(h[1-6]{1})(.?[^>])?>(.+)</h[1-6]{1}>|'; $answer = preg_replace_callback($pattern, $callback, $answer); return $answer; }