/** * Attempts to match the name of a file to the "clean name" within the name map file. * If no mapping is found, it will clean it to the best of its ability and return * that "cleaner" version of the page name. * * @param string $page Name of the page, potentially with category path. * @param string $lang Language to use. * * @return string Final formatted name. */ function findName($page, $lang = '') { global $nameMap; if (empty($lang)) { $lang = \App\getLanguage(); } $useMap = $nameMap[$lang]; if (array_key_exists($page, $useMap)) { return $useMap[$page]; } $exp = explode('/', $page); $last = array_pop($exp); return str_replace('_', ' ', str_replace('.md', '', $last)); }
/** * @param array $changes * * @return bool */ private function appendFixedVariables(array $changes) { $lang = \App\getLanguage(); $fixed = (include dirname(dirname(__FILE__)) . '/wiki/config/custom_variables.php'); if (empty($fixed[$lang])) { return $changes; } $useFixed = $fixed[$lang]; // If the user requested a language other than english but there // are no entries for that language, try to default to english. if (empty($useFixed) && $lang != BD_DEFAULT_LANGUAGE) { if (empty($fixed[BD_DEFAULT_LANGUAGE])) { return false; } $useFixed = $fixed[BD_DEFAULT_LANGUAGE]; } if (!empty($useFixed)) { return array_merge($changes, $useFixed); } else { return $changes; } }
/** * Custom replacements available on all pages. Establish standard * replacements within the "config/custom_replacements.php" file. * * @return bool */ private function standardReplacements() { $replacements = (include dirname(dirname(__FILE__)) . '/wiki/config/custom_replacements.php'); $lang = \App\getLanguage(); $useArray = $replacements[$lang]; // If the user requested a language other than english but there // are no entries for that language, try to default to english. if (empty($useArray) && $lang != BD_DEFAULT_LANGUAGE) { if (empty($replacements[BD_DEFAULT_LANGUAGE])) { return false; } $useArray = $replacements[BD_DEFAULT_LANGUAGE]; } $keys = array_keys($useArray); $values = array_values($useArray); $this->content = str_replace($keys, $values, $this->content); return true; }
/** * Changes that apply to all possible templates. */ private function getDefaultChanges() { $base = \App\getBaseUrl(); return array('assets' => $base . '/app/views/' . BD_THEME . '/assets', 'wiki_name' => BD_NAME, 'wiki_theme' => BD_THEME, 'wiki_base_url' => $base, 'branding_color' => BD_BRANDING_COLOR, 'page' => $this->page, 'category' => $this->category, 'currentLanguage' => \App\getLanguage(), 'languages' => $this->buildLanguages(), 'query' => '', 'navigation' => $this->structure->getHtml()); }
/** * Builds an array of items that make up the category and page. * * @param string $category * * @return array */ private function buildLinkComponents($category) { $build = array(); $dirs = array_reverse(explode('/', $category)); $lang = \App\getLanguage(); foreach ($dirs as $item) { // We don't care about anything before the language folder. if ($item == $lang) { break; } $build[] = $item; } array_shift($build); return array_reverse($build); }