/administrator/components/com_admin/models/help.php

https://github.com/gnomeontherun/joomla-cms · PHP · 154 lines · 81 code · 15 blank · 58 comment · 10 complexity · d907af6a32d69ce6a5a4f292b61388b2 MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Administrator
  4. * @subpackage com_admin
  5. *
  6. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. defined('_JEXEC') or die;
  10. /**
  11. * Admin Component Help Model
  12. *
  13. * @package Joomla.Administrator
  14. * @subpackage com_admin
  15. * @since 1.6
  16. */
  17. class AdminModelHelp extends JModelLegacy
  18. {
  19. /**
  20. * @var string the search string
  21. */
  22. protected $help_search = null;
  23. /**
  24. * @var string the page to be viewed
  25. */
  26. protected $page = null;
  27. /**
  28. * @var string the iso language tag
  29. */
  30. protected $lang_tag = null;
  31. /**
  32. * @var array Table of contents
  33. */
  34. protected $toc = null;
  35. /**
  36. * @var string url for the latest version check
  37. */
  38. protected $latest_version_check = null;
  39. /**
  40. * Method to get the help search string
  41. * @return string Help search string
  42. */
  43. public function &getHelpSearch()
  44. {
  45. if (is_null($this->help_search)) {
  46. $this->help_search = JFactory::getApplication()->input->getString('helpsearch');
  47. }
  48. return $this->help_search;
  49. }
  50. /**
  51. * Method to get the page
  52. * @return string page
  53. */
  54. public function &getPage()
  55. {
  56. if (is_null($this->page))
  57. {
  58. $page = JFactory::getApplication()->input->get('page', 'JHELP_START_HERE');
  59. $this->page = JHelp::createUrl($page);
  60. }
  61. return $this->page;
  62. }
  63. /**
  64. * Method to get the lang tag
  65. *
  66. * @return string lang iso tag
  67. */
  68. public function getLangTag()
  69. {
  70. if (is_null($this->lang_tag))
  71. {
  72. $lang = JFactory::getLanguage();
  73. $this->lang_tag = $lang->getTag();
  74. if (!is_dir(JPATH_BASE . '/help/' . $this->lang_tag))
  75. {
  76. // Use english as fallback
  77. $this->lang_tag = 'en-GB';
  78. }
  79. }
  80. return $this->lang_tag;
  81. }
  82. /**
  83. * Method to get the toc
  84. * @return array Table of contents
  85. */
  86. public function &getToc()
  87. {
  88. if (is_null($this->toc))
  89. {
  90. // Get vars
  91. $lang_tag = $this->getLangTag();
  92. $help_search = $this->getHelpSearch();
  93. // Get Help files
  94. $files = JFolder::files(JPATH_BASE . '/help/' . $lang_tag, '\.xml$|\.html$');
  95. $this->toc = array();
  96. foreach($files as $file)
  97. {
  98. $buffer = file_get_contents(JPATH_BASE . '/help/' . $lang_tag . '/' . $file);
  99. if (preg_match('#<title>(.*?)</title>#', $buffer, $m))
  100. {
  101. $title = trim($m[1]);
  102. if ($title) {
  103. // Translate the page title
  104. $title = JText::_($title);
  105. // strip the extension
  106. $file = preg_replace('#\.xml$|\.html$#', '', $file);
  107. if ($help_search)
  108. {
  109. if (JString::strpos(JString::strtolower(strip_tags($buffer)), JString::strtolower($help_search)) !== false) {
  110. // Add an item in the Table of Contents
  111. $this->toc[$file] = $title;
  112. }
  113. }
  114. else
  115. {
  116. // Add an item in the Table of Contents
  117. $this->toc[$file] = $title;
  118. }
  119. }
  120. }
  121. }
  122. // Sort the Table of Contents
  123. asort($this->toc);
  124. }
  125. return $this->toc;
  126. }
  127. /**
  128. * Method to get the latest version check;
  129. * @return string Latest Version Check URL
  130. */
  131. public function &getLatestVersionCheck()
  132. {
  133. if (!$this->latest_version_check) {
  134. $override = 'http://help.joomla.org/proxy/index.php?option=com_help&keyref=Help{major}{minor}:Joomla_Version_{major}_{minor}_{maintenance}';
  135. $this->latest_version_check = JHelp::createUrl('JVERSION', false, $override);
  136. }
  137. return $this->latest_version_check;
  138. }
  139. }