Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
87 changes: 57 additions & 30 deletions administrator/components/com_admin/tmpl/help/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,71 @@

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;

Check failure on line 14 in administrator/components/com_admin/tmpl/help/default.php

View workflow job for this annotation

GitHub Actions / Run PHPstan

Class Joomla\Component\Admin\Administrator\View\Help\Toc referenced with incorrect case: 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->addInlineStyle('
#help-sidebar {
min-width: 18rem;
}
#help-index.main-nav {
inline-size: 18rem;
max-inline-size: 18rem;
}
#help-index ul, #help-index li {
inline-size: 18rem;
max-inline-size: 18rem;
}
#helpmenu .has-arrow .item-title {
margin-inline-end: auto;
}
#helpmenu .has-arrow::after {
display: flex;
}
.closed #helpmenu a:hover {
max-inline-size: 18rem;
}
#help-index.sidebar-wrapper .item-level-2 > a {
padding-inline-start: 1rem;
}
#help-index.sidebar-wrapper .item-level-3 > a {
padding-inline-start: 1.5rem;
}
.help-nav .mm-collapse {
display: none;
}
.help-nav .mm-collapse.mm-show {
display: block;
}
');

// Get the HTML for the Table of Contents from a separate file.
require_once 'toc-build.php';
$tocBuilder = new Toc();

Check failure on line 58 in administrator/components/com_admin/tmpl/help/default.php

View workflow job for this annotation

GitHub Actions / Run PHPstan

Class Joomla\Component\Admin\Administrator\View\Help\Toc referenced with incorrect case: Joomla\Component\Admin\Administrator\View\Help\ToC.
$toc = $tocBuilder->getToc();

?>
<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 class="d-flex flex-column flex-md-row">
<div id="help-sidebar" class="flex-shrink-0">
<!-- Left menu -->
<button class="btn btn-sm btn-secondary my-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>
<h2><?php echo Text::_('COM_ADMIN_HELP_INDEX'); ?></h2>
<div id="help-index" class="main-nav sidebar-wrapper">
<ul id="helpmenu" class="help-nav flex-column">
<?php echo $toc; ?>
</ul>
</div>
</div>
<input class="textarea" type="hidden" name="option" value="com_admin">
</form>
<div class="flex-grow-1 p-3">
<!-- Right content -->
<iframe name="helpFrame" title="helpFrame" height="2100px" src="" class="helpFrame table table-bordered"></iframe>
</div>
</div>
103 changes: 103 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,103 @@
<?php

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

namespace Joomla\Component\Admin\Administrator\View\Help;

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

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

class Toc
{
/**
* The id of each ul submenu - incremented for each.
*
* @var int
*/
protected $tocid = 1000;

/**
* The level of menu / submenu items.
*
* @var int
*/
protected $toclevel = 1;

/**
* The id of each li that contains a sub menu
*
* @var int
*/
protected $liid = 0;

/**
* Method to get the table of contents
*
* @return array Table of contents
*/
public function &getToc()
{
require __DIR__ . '/toc-src.php';
$html = $this->buildMenu($menu, true);
return $html;
}

protected function buildMenu(array $items, $pass = false): string
{
// don't set a ul on the first pass
if ($pass) {
$html = "";
} else {
$this->tocid += 1;
// Increase the toclevel on entry
$this->toclevel += 1;
if ($this->toclevel > 1) {
$collapse = ' mm-collapse';
} else {
$collapse = '';
}
$html = "<ul id=\"collapse{$this->tocid}\" class=\"collapse-level-1{$collapse}\">\n";
}
foreach ($items as $label => $value) {
$text = Text::_('COM_ADMIN_HELP_' . $label);
$lclabel = strtolower(str_replace('_', '-', $label));
$this->liid += 1;
// Numeric keys mean leaf items (not headings)
if (is_array($value)) {
$icon = "<span class=\"icon-folder icon-fw\" aria-hidden=\"true\"></span>";
$wrap_label = "<span class=\"item-title\">{$text}</span>";
$html .= "<li id=\"li{$this->liid}\" class=\"item parent item-level-{$this->toclevel}\">";
$html .= "<a href=\"#\" class=\"has-arrow\">";
$html .= "{$icon}{$wrap_label}</a>\n";
if (!empty($value)) {
$html .= $this->buildMenu($value); // Recursively build sublist
}
$html .= "</li>\n";
} else {
$icon = "<span class=\"icon-file-alt icon-fw\" aria-hidden=\"true\"></span>";
// The label is help.joomla.org 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-{$this->toclevel}\">{$link}</li>\n";
}
}
// don't set a ul on the first pass
if ($pass) {
} else {
$html .= "</ul>\n";
}
// On return decrease the toclevel
$this->toclevel -= 1;
return $html;
}
}
Loading
Loading