Textpattern | PHP Cross Reference | Content Management Systems |
Description: Help subsystem.
1 <?php 2 3 /* 4 * Textpattern Content Management System 5 * https://textpattern.com/ 6 * 7 * Copyright (C) 2020 The Textpattern Development Team 8 * 9 * This file is part of Textpattern. 10 * 11 * Textpattern is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU General Public License 13 * as published by the Free Software Foundation, version 2. 14 * 15 * Textpattern is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with Textpattern. If not, see <https://www.gnu.org/licenses/>. 22 */ 23 24 /** 25 * Help subsystem. 26 * 27 * @since 4.7.0 28 * @package Admin\Help 29 */ 30 31 namespace Textpattern\Module\Help; 32 33 class HelpAdmin 34 { 35 private static $available_steps = array( 36 'pophelp' => false, 37 'dashboard' => false, 38 ); 39 40 private static $textile; 41 protected static $pophelp_xml; 42 protected static $fallback_xml; 43 44 /** 45 * Constructor. 46 */ 47 48 public static function init() 49 { 50 global $step; 51 52 require_privs('help'); 53 54 if ($step && bouncer($step, self::$available_steps)) { 55 self::$step(); 56 } else { 57 self::dashboard(); 58 } 59 } 60 61 62 /** 63 * Load given pophelp.xml file 64 * 65 * Also load fallback file if it's not the same language. 66 * 67 * @param string $lang 68 */ 69 70 private static function pophelp_load($lang) 71 { 72 $file = txpath."/lang/{$lang}_pophelp.xml"; 73 $fallback_file = txpath."/lang/".TEXTPATTERN_DEFAULT_LANG."_pophelp.xml"; 74 75 if (file_exists($fallback_file) && $fallback_file !== $file) { 76 if (empty(self::$fallback_xml)) { 77 self::$fallback_xml = simplexml_load_file($fallback_file, "SimpleXMLElement", LIBXML_NOCDATA); 78 } 79 } 80 81 if (!file_exists($file)) { 82 return false; 83 } 84 85 if (empty(self::$pophelp_xml)) { 86 self::$pophelp_xml = simplexml_load_file($file, "SimpleXMLElement", LIBXML_NOCDATA); 87 } 88 89 return self::$pophelp_xml; 90 } 91 92 /** 93 * Fetch pophelp group keys. 94 * 95 * @param string $group The help topic group to return 96 */ 97 98 public static function pophelp_keys($group) 99 { 100 $xml = self::pophelp_load(TEXTPATTERN_DEFAULT_LANG); 101 $help = $xml ? $xml->xpath("//group[@id='{$group}']/item") : array(); 102 103 $keys = array(); 104 105 foreach ($help as $item) { 106 if ($item->attributes()->id) { 107 $keys[] = (string)$item->attributes()->id; 108 } 109 } 110 111 return $keys; 112 } 113 114 /** 115 * Popup help topic. 116 * 117 * @param string $string The help topic item identifier to return 118 * @param string $lang The language in which to return the topic. Default=current 119 */ 120 121 public static function pophelp($string = '', $lang = null) 122 { 123 global $app_mode; 124 125 $item = empty($string) ? gps('item') : $string; 126 127 if (empty($item) || preg_match('/[^\w]/i', $item)) { 128 exit; 129 } 130 131 $lang_ui = ($lang) ? $lang : get_pref('language_ui', LANG); 132 133 if (!$xml = self::pophelp_load($lang_ui)) { 134 $lang_ui = TEXTPATTERN_DEFAULT_LANG; 135 136 if (!empty(self::$fallback_xml)) { 137 $xml = self::$fallback_xml; 138 } 139 } 140 141 $x = $xml ? $xml->xpath("//item[@id='{$item}']") : array(); 142 $pophelp = $x ? trim($x[0]) : false; 143 144 if (!$pophelp && !empty(self::$fallback_xml)) { 145 $xml = self::$fallback_xml; 146 $x = $xml ? $xml->xpath("//item[@id='{$item}']") : array(); 147 $pophelp = $x ? trim($x[0]) : false; 148 } 149 150 $title = ''; 151 152 if ($pophelp) { 153 $title = txpspecialchars($x[0]->attributes()->title); 154 $format = $x[0]->attributes()->format; 155 156 if ($format == 'textile') { 157 $textile = new \Netcarver\Textile\Parser(); 158 $out = $textile->parse($pophelp).n; 159 } else { 160 $out = $pophelp.n; 161 } 162 } else { 163 // Check if the pophelp item is installed in the DB as a regular string. 164 $exists = \Txp::get('\Textpattern\L10n\Lang')->hasString($item); 165 166 if ($exists) { 167 $out = gTxt($item); 168 } else { 169 $out = gTxt('pophelp_missing', array('{item}' => $item)); 170 } 171 } 172 173 $out = tag($out, 'div', array( 174 'id' => 'pophelp-event', 175 'dir' => 'auto', 176 )); 177 178 if ($app_mode == 'async') { 179 pagetop(''); 180 exit($out); 181 } 182 183 return $out; 184 } 185 186 /** 187 * Stub, awaiting implementation. 188 */ 189 190 public static function dashboard() 191 { 192 pagetop(gTxt('tab_help')); 193 } 194 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
title