Inheritance: extends CommonDBChild
 /**
  * Print out list recent or popular kb/faq
  *
  * @param $type      type : recent / popular / not published
  *
  * @return nothing (display table)
  **/
 static function showRecentPopular($type)
 {
     global $DB, $CFG_GLPI;
     $faq = !Session::haveRight(self::$rightname, READ);
     if ($type == "recent") {
         $orderby = "ORDER BY `date` DESC";
         $title = __('Recent entries');
     } else {
         if ($type == 'lastupdate') {
             $orderby = "ORDER BY `date_mod` DESC";
             $title = __('Last updated entries');
         } else {
             $orderby = "ORDER BY `view` DESC";
             $title = __('Most popular questions');
         }
     }
     $faq_limit = "";
     $addselect = "";
     // Force all joins for not published to verify no visibility set
     $join = self::addVisibilityJoins(true);
     if (Session::getLoginUserID()) {
         $faq_limit .= "WHERE " . self::addVisibilityRestrict();
     } else {
         // Anonymous access
         if (Session::isMultiEntitiesMode()) {
             $faq_limit .= " WHERE (`glpi_entities_knowbaseitems`.`entities_id` = '0'\n                                   AND `glpi_entities_knowbaseitems`.`is_recursive` = '1')";
         } else {
             $faq_limit .= " WHERE 1";
         }
     }
     // Only published
     $faq_limit .= " AND (`glpi_entities_knowbaseitems`.`entities_id` IS NOT NULL\n                           OR `glpi_knowbaseitems_profiles`.`profiles_id` IS NOT NULL\n                           OR `glpi_groups_knowbaseitems`.`groups_id` IS NOT NULL\n                           OR `glpi_knowbaseitems_users`.`users_id` IS NOT NULL)";
     // Add visibility date
     $faq_limit .= " AND (`glpi_knowbaseitems`.`begin_date` IS NULL\n                           OR `glpi_knowbaseitems`.`begin_date` < NOW())\n                      AND (`glpi_knowbaseitems`.`end_date` IS NULL\n                           OR `glpi_knowbaseitems`.`end_date` > NOW()) ";
     if ($faq) {
         // FAQ
         $faq_limit .= " AND (`glpi_knowbaseitems`.`is_faq` = '1')";
     }
     if (KnowbaseItemTranslation::isKbTranslationActive()) {
         $join .= "LEFT JOIN `glpi_knowbaseitemtranslations`\n                     ON (`glpi_knowbaseitems`.`id` = `glpi_knowbaseitemtranslations`.`knowbaseitems_id`\n                           AND `glpi_knowbaseitemtranslations`.`language` = '" . $_SESSION['glpilanguage'] . "')";
         $addselect .= ", `glpi_knowbaseitemtranslations`.`name` AS transname,\n                          `glpi_knowbaseitemtranslations`.`answer` AS transanswer ";
     }
     $query = "SELECT DISTINCT `glpi_knowbaseitems`.* {$addselect}\n                FROM `glpi_knowbaseitems`\n                {$join}\n                {$faq_limit}\n                {$orderby}\n                LIMIT 10";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     if ($number > 0) {
         echo "<table class='tab_cadrehov'>";
         echo "<tr class='noHover'><th>" . $title . "</th></tr>";
         while ($data = $DB->fetch_assoc($result)) {
             $name = $data['name'];
             if (isset($data['transname']) && !empty($data['transname'])) {
                 $name = $data['transname'];
             }
             echo "<tr class='tab_bg_2'><td class='left'>";
             echo "<a " . ($data['is_faq'] ? " class='pubfaq' title='" . __("This item is part of the FAQ") . "' " : " class='knowbase' ") . " href=\"" . $CFG_GLPI["root_doc"] . "/front/knowbaseitem.form.php?id=" . $data["id"] . "\">" . Html::resume_text($name, 80) . "</a></td></tr>";
         }
         echo "</table>";
     }
 }
This file is part of GLPI.

GLPI is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
 * @brief
 * @since version 0.85
**/
include '../inc/includes.php';
$translation = new KnowbaseItemTranslation();
if (isset($_POST['add'])) {
    $translation->add($_POST);
} else {
    if (isset($_POST['update'])) {
        $translation->update($_POST);
    }
}
Html::back();
 /**
  * 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;
 }