* @copyright Copyright (C) 2007-2018 Jonathan M. Cameron, All Rights Reserved * @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL * @link http://joomlacode.org/gf/project/attachments/frs/ */ // Check to ensure this file is included in Joomla! defined('_JEXEC') or die(); /** Define the legacy classes, if necessary */ require_once JPATH_SITE . '/components/com_attachments/legacy/view.php'; /** * View for the help pages * * The goal is to provide a PHP programmatic interface to create a help page * using primarily PHP function calls in the view/template. The styling is * base on styling of Restructured Text documents rendered into HTML using * converion tools such as docutils. * * @package Attachments * @since 3.1 */ class HelpView extends JViewLegacy { /** * Data about each of the document section headers * * Should be initialized in the view or templage to contain an array of * arrays of information about the sections like this: * * $this->sections = Array( 1 => Array( 'id' => 'introduction', * 'code' => 'SECTION_TITLE_1', * 'title' => JText::_('SECTION_TITLE_1'), * ... * ), * * where the 'SECTION_TITLE_1' is the language token for the title of * section 1. */ protected $sections = null; /** * Flag to show codes * */ protected $show_codes = null; /** * Constructor * * @param array $config An optional associative array of configuration settings. */ public function __construct($config = array()) { parent::__construct($config); // Save the plugin type $this->show_codes = JRequest::getCmd('show') == 'codes'; } /** * Add the information about a section to the $sections data * * @param int $sectnum the section number (constant) * @param string $id the section ID string (unique name to be used as anchor target) * @param string $code the language code for this section title * * @return nothing */ protected function saveSectionInfo($sectnum, $id, $code) { $this->sections[$sectnum] = Array('id' => $id, 'code' => $code, 'title' => JText::_($code)); } /** * Construct a tooltip if tooltips are supposed to be shown * * @param string $code Language code for the tooltip * * @return the tooltip to insert in the html */ protected function constructTooltip($code) { $tooltip = ''; if ($this->show_codes) { $tooltip = " title=\"$code\""; } return $tooltip; } /** * Construct the URL with show=codes toggled * * @return the URL */ protected function toggledURL() { $uri = JRequest::getURI(); if ($this->show_codes) { $uri = str_replace('&show=codes', '', $uri); } else { $uri .= '&show=codes'; } return $uri; } /** * Add a link for the specified section * * @param int $sect_num The section number to link to * * @return string an html link for the specified section */ protected function sectionLink($sect_num) { $id = $this->sections[$sect_num]['id']; $title = $this->sections[$sect_num]['title']; return "$title"; } /** * Construct a link * * @param string $url The URL for the link * @param string $label_code The code for the link label * @param string $class The class for the link * * @return string an html link */ protected function link($url, $label_code, $class='') { $label = JText::_($label_code); return "$label"; } /** * Replace a series of items from the html using an array of replacements * * For example: * replace('{TEST}-{NUM}', Array('{TEST}' => 'MyTest', '{NUM}' => '23')) * returns: * MyTest-23 * * @param string $html The original HTML string to be modified * @param array $replacements Array of textual replacments * * @return string the original HTML with the replacements performed */ protected function replace($html, $replacements) { if ( is_array($replacements) ) { foreach ($replacements as $tag => $replace) { $html = str_replace($tag, $replace, $html); } } return $html; } /** * Add a table of contents * * @param string $title_code The language code for the title of the table of contents * @param sting $class The class for the table of contents (default: contents topic) * * @return nothing */ protected function tableOfContents($title_code, $class = 'contents topic') { $title = JText::_($title_code); $tooltip = $this->constructTooltip($title_code); $html = "
$title
\n"; $html .= "$title
\n"; foreach ($text_codes as $text_code) { $text = $this->replace(JText::_($text_code), $replacements); $tooltip = $this->constructTooltip($text_code); $html .= "$text
\n"; } if ( $terminate ) { $html .= "element * * @return nothing */ protected function addParagraph($text_codes, $replacements = null, $pclass = null) { if (!is_array($text_codes)) { $text_codes = Array($text_codes); } $html = ''; foreach ($text_codes as $text_code) { $text = $this->replace(JText::_($text_code), $replacements); $tooltip = $this->constructTooltip($text_code); if ($pclass) { $html .= "
" . $text . "
\n"; } else { $html .= "" . $text . "
\n"; } } echo $html; } /** * Add a preformatted block * * @param string $text The raw string to print literally * @param string $class The class for the HTML block
*
* @return nothing
*/
protected function addPreBlock($text, $class='literal-block')
{
$html = "\n";
$html .= $text . "\n";
$html .= "
\n";
echo $html;
}
/**
* Start an a list (unordered by default)
*
* @param string $type The type of list (defaults to unordered $text
\n"; } if ($terminate) { $html .= "$text
\n"; } if ($terminate) { $html .= "" . JText::_($caption_code) . "
\n"; } $html .= '