Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 0 additions & 138 deletions administrator/components/com_admin/src/Model/HelpModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@

use Joomla\CMS\Factory;
use Joomla\CMS\Help\Help;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\Filesystem\Folder;
use Joomla\String\StringHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand All @@ -28,14 +25,6 @@
*/
class HelpModel extends BaseDatabaseModel
{
/**
* The search string
*
* @var string
* @since 1.6
*/
protected $help_search = null;

/**
* The page to be viewed
*
Expand All @@ -44,46 +33,6 @@ class HelpModel extends BaseDatabaseModel
*/
protected $page = null;

/**
* The ISO language tag
*
* @var string
* @since 1.6
*/
protected $lang_tag = null;

/**
* Table of contents
*
* @var array
* @since 1.6
*/
protected $toc = [];

/**
* URL for the latest version check
*
* @var string
* @since 1.6
*/
protected $latest_version_check = null;

/**
* Method to get the help search string
*
* @return string Help search string
*
* @since 1.6
*/
public function &getHelpSearch()
{
if (\is_null($this->help_search)) {
$this->help_search = Factory::getApplication()->getInput()->getString('helpsearch');
}

return $this->help_search;
}

/**
* Method to get the page
*
Expand All @@ -99,91 +48,4 @@ public function &getPage()

return $this->page;
}

/**
* Method to get the lang tag
*
* @return string lang iso tag
*
* @since 1.6
*/
public function getLangTag()
{
if (\is_null($this->lang_tag)) {
$this->lang_tag = Factory::getLanguage()->getTag();

if (!is_dir(JPATH_BASE . '/help/' . $this->lang_tag)) {
// Use English as fallback
$this->lang_tag = 'en-GB';
}
}

return $this->lang_tag;
}

/**
* Method to get the table of contents
*
* @return array Table of contents
*/
public function &getToc()
{
if (\count($this->toc)) {
return $this->toc;
}

// Get vars
$lang_tag = $this->getLangTag();
$help_search = $this->getHelpSearch();

// New style - Check for a TOC \JSON file
if (file_exists(JPATH_BASE . '/help/' . $lang_tag . '/toc.json')) {
$data = json_decode(file_get_contents(JPATH_BASE . '/help/' . $lang_tag . '/toc.json'));

// Loop through the data array
foreach ($data as $key => $value) {
$this->toc[$key] = Text::_('COM_ADMIN_HELP_' . $value);
}

// Sort the Table of Contents
asort($this->toc);

return $this->toc;
}

// Get Help files
$files = Folder::files(JPATH_BASE . '/help/' . $lang_tag, '\.xml$|\.html$');

foreach ($files as $file) {
$buffer = file_get_contents(JPATH_BASE . '/help/' . $lang_tag . '/' . $file);

if (!preg_match('#<title>(.*?)</title>#', $buffer, $m)) {
continue;
}

$title = trim($m[1]);

if (!$title) {
continue;
}

// Translate the page title
$title = Text::_($title);

// Strip the extension
$file = preg_replace('#\.xml$|\.html$#', '', $file);

if ($help_search && StringHelper::strpos(StringHelper::strtolower(strip_tags($buffer)), StringHelper::strtolower($help_search)) === false) {
continue;
}

// Add an item in the Table of Contents
$this->toc[$file] = $title;
}

// Sort the Table of Contents
asort($this->toc);

return $this->toc;
}
}
11 changes: 0 additions & 11 deletions administrator/components/com_admin/src/View/Help/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ class HtmlView extends BaseHtmlView
*/
protected $page = null;

/**
* The iso language tag
*
* @var string
* @since 1.6
*/
protected $languageTag = null;

/**
* Table of contents
*
Expand All @@ -73,10 +65,7 @@ public function display($tpl = null): void
{
/** @var HelpModel $model */
$model = $this->getModel();
$this->helpSearch = $model->getHelpSearch();
$this->page = $model->getPage();
$this->toc = $model->getToc();
$this->languageTag = $model->getLangTag();

$this->addToolbar();

Expand Down
56 changes: 24 additions & 32 deletions administrator/components/com_admin/tmpl/help/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,36 @@

defined('_JEXEC') or die;

use Joomla\CMS\Help\Help;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\Component\Admin\Administrator\View\Help\Toc;

/** @var \Joomla\Component\Admin\Administrator\View\Help\HtmlView $this */

/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->getDocument()->getWebAssetManager();
$wa->useScript('com_admin.admin-help');
$wa->useScript('com_admin.admin-help')
->useStyle('com_admin.admin-help');

// Get the HTML for the Table of Contents from a separate file.
include_once 'toc-build.php';

?>
<form action="<?php echo Route::_('index.php?option=com_admin&amp;view=help'); ?>" method="post" name="adminForm" id="adminForm" class="main-card">
<div class="row mt-sm-3">
<div id="sidebar" class="col-md-3">
<button class="btn btn-sm btn-secondary my-2 options-menu d-md-none" type="button" data-bs-toggle="collapse" data-bs-target=".sidebar-nav" aria-controls="help-index" aria-expanded="false">
<span class="icon-align-justify" aria-hidden="true"></span>
<?php echo Text::_('JTOGGLE_SIDEBAR_MENU'); ?>
</button>
<div class="sidebar-nav" id="help-index">
<ul class="nav flex-column">
<li class="item"><?php echo HTMLHelper::_('link', Help::createUrl('Start_Here'), Text::_('COM_ADMIN_START_HERE'), ['target' => 'helpFrame']); ?></li>
<li class="item"><?php echo HTMLHelper::_('link', 'https://help.joomla.org/proxy?keyref=Help4.x:License', Text::_('COM_ADMIN_LICENSE'), ['target' => 'helpFrame']); ?></li>
<li class="item"><?php echo HTMLHelper::_('link', Help::createUrl('Glossary'), Text::_('COM_ADMIN_GLOSSARY'), ['target' => 'helpFrame']); ?></li>
<li class="divider"></li>
<li class="nav-header"><?php echo Text::_('COM_ADMIN_ALPHABETICAL_INDEX'); ?></li>
<?php foreach ($this->toc as $k => $v) : ?>
<li class="item">
<?php $url = Help::createUrl($k); ?>
<?php echo HTMLHelper::_('link', $url, $v, ['target' => 'helpFrame']); ?>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<div class="col-md-9">
<iframe onLoad="var x = getElementById('help-index'); x.classList.remove('show');" name="helpFrame" title="helpFrame" height="2100px" src="<?php echo $this->page; ?>" class="helpFrame table table-bordered"></iframe>
</div>
<div class="d-flex flex-column flex-md-row">
<div id="help-sidebar" class="flex-shrink-0 mt-md-2">
<!-- Left menu -->
<button class="btn btn-sm btn-secondary my-md-2 options-menu d-md-none" type="button" data-bs-toggle="collapse" data-bs-target="#help-index" aria-controls="help-index" aria-expanded="false">
<span class="icon-align-justify" aria-hidden="true"></span>
<?php echo Text::_('JTOGGLE_SIDEBAR_MENU'); ?>
</button>
<nav id="help-index" class="main-nav help-nav sidebar-wrapper">
<h2><?php echo Text::_('COM_ADMIN_HELP_INDEX'); ?></h2>
<ul id="helpmenu" class="help-nav flex-column pt-2">
<?php echo renderHelpMenu(); ?>
</ul>
</nav>
</div>
<div class="flex-grow-1 mt-2">
<!-- Right content -->
<iframe name="helpFrame" title="<?php echo Text::_('COM_ADMIN_HELP_FRAME_TITLE'); ?>" height="2100px" src="" class="helpFrame table table-bordered"></iframe>
</div>
<input class="textarea" type="hidden" name="option" value="com_admin">
</form>
</div>
80 changes: 80 additions & 0 deletions administrator/components/com_admin/tmpl/help/toc-build.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

/**
* @package Joomla.Administrator
* @subpackage com_admin
*
* @copyright (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

use Joomla\CMS\Help\Help;
use Joomla\CMS\Language\Text;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

function renderHelpMenu(): string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a developer can comment better than me but I would not expect to see functions in a tmpl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - I can't remember why I chose not to use the mod_menu code. I will look at that again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remembered: it was setting up the required data that put me off using the mod_menu code. So I propose to leave it as it is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i still dont think its correct to define a function in a tmpl

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. But I am not the developer expert, and I can’t help much now. I have asked in the maintainers team for advice, let’s wait what comes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function should be in the view class. Or better, prepare the data in the view class and just render it in the template.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Points accepted. I will see what I can do. Back in a few days!

{
include __DIR__ . '/toc-src.php';

// Initialise variables used the Help men.
$tocid = 1000;
$toclevel = 1;
$liid = 0;
$firstpass = true;

return buildMenu($menu, $tocid, $toclevel, $liid, $firstpass);
}

function buildMenu(array &$items, int &$tocid, int &$toclevel, int &$liid, bool $firstpass = false): string
{
// don't set a ul on the first pass
if ($firstpass) {
$html = "";
} else {
$tocid += 1;
// Increase the toclevel on entry
$toclevel += 1;
if ($toclevel > 1) {
$collapse = ' mm-collapse';
} else {
$collapse = '';
}
$html = "<ul id=\"collapse{$tocid}\" class=\"collapse-level-1{$collapse}\">\n";
}
foreach ($items as $label => $value) {
$text = Text::_('COM_ADMIN_HELP_' . $label);
$lclabel = strtolower(str_replace('_', '-', $label));
$liid += 1;

if (is_array($value)) {
// This is a folder list item
$icon = "<span class=\"icon-folder icon-fw\" aria-hidden=\"true\"></span>";
$wrap_label = "<span class=\"item-title\">{$text}</span>";
$html .= "<li id=\"li{$liid}\" class=\"item parent item-level-{$toclevel}\">";
$html .= "<a href=\"#\" class=\"has-arrow\">";
$html .= "{$icon}{$wrap_label}</a>\n";
if (!empty($value)) {
// Recursively build sublist.
$html .= buildMenu($value, $tocid, $toclevel, $liid);
}
$html .= "</li>\n";
} else {
// This is an article list item.
$icon = "<span class=\"icon-file-alt icon-fw\" aria-hidden=\"true\"></span>";
// The url is help.joomla.org + $label (the help key).
$url = Help::createUrl($label);
$link = "<a data-id=\"{$lclabel}\" href=\"{$url}\" target=\"helpFrame\">{$icon}{$text}</a>\n";
$html .= "<li class=\"item item-level-{$toclevel}\">{$link}</li>\n";
}
}
// don't set a ul on the first pass
if (!$firstpass) {
$html .= "</ul>\n";
}
// On return decrease the toclevel
$toclevel -= 1;
return $html;
}
Loading