setLogicalTag(self::TAG); } $max = $tagAttributes->getValue(RelatedTag::MAX_LINKS_CONF); if ($max === NULL) { $max = SiteConfig::getConfValue(RelatedTag::MAX_LINKS_CONF, RelatedTag::MAX_LINKS_CONF_DEFAULT); } $tagAttributes->addClassName("d-print-none"); $html = $tagAttributes->toHtmlEnterTag("div"); $relatedPages = self::getRelatedPagesOrderedByBacklinkCount($page, $max); if (empty($relatedPages)) { $html .= "Plugin " . PluginUtility::PLUGIN_BASE_NAME . " - Component " . syntax_plugin_combo_related::getTag() . ": " . $lang['nothingfound'] . ""; } else { // Dokuwiki debug $html .= ''; } return $html . ''; } /** * @param MarkupPath $page * @param int|null $max * @return array */ public static function getRelatedPagesOrderedByBacklinkCount(MarkupPath $page, ?int $max = null): array { // Call the dokuwiki backlinks function // @require_once(DOKU_INC . 'inc/fulltext.php'); // Backlinks called the indexer, for more info // See: https://www.dokuwiki.org/devel:metadata#metadata_index $backlinks = ft_backlinks($page->getWikiId(), $ignore_perms = false); $related = array(); foreach ($backlinks as $backlink) { $page = array(); $page[RelatedTag::RELATED_PAGE_ID_PROP] = $backlink; $page[RelatedTag::RELATED_BACKLINKS_COUNT_PROP] = sizeof(ft_backlinks($backlink, $ignore_perms = false)); $related[] = $page; } usort($related, function ($a, $b) { return $b[RelatedTag::RELATED_BACKLINKS_COUNT_PROP] - $a[RelatedTag::RELATED_BACKLINKS_COUNT_PROP]; }); if ($max !== null) { if (sizeof($related) > $max) { $related = array_slice($related, 0, $max); $page = array(); $page[RelatedTag::RELATED_PAGE_ID_PROP] = RelatedTag::MORE_PAGE_ID; $related[] = $page; } } return $related; } }