1<?php 2/** 3 * Copyright (c) 2021. ComboStrap, Inc. and its affiliates. All Rights Reserved. 4 * 5 * This source code is licensed under the GPL license found in the 6 * COPYING file in the root directory of this source tree. 7 * 8 * @license GPL 3 (https://www.gnu.org/licenses/gpl-3.0.en.html) 9 * @author ComboStrap <support@combostrap.com> 10 * 11 */ 12 13namespace ComboStrap; 14 15 16class Site 17{ 18 19 const CONF_SITE_ISO_COUNTRY = "siteIsoCountry"; 20 const STRAP_TEMPLATE_NAME = "strap"; 21 22 const SVG_LOGO_IDS = array( 23 ':wiki:logo.svg', 24 ':logo.svg' 25 ); 26 27 const PNG_LOGO_IDS = array( 28 ':logo.png', 29 ':wiki:logo.png', 30 ':favicon-32×32.png', 31 ':favicon-16×16.png', 32 ':apple-touch-icon.png', 33 ':android-chrome-192x192.png' 34 ); 35 36 37 /** 38 * @return string|null the html img tag or null 39 */ 40 public static function getLogoImgHtmlTag($tagAttributes = null) 41 { 42 $logoIds = self::getLogoIds(); 43 foreach ($logoIds as $logoId) { 44 $mediaLink = MediaLink::createMediaLinkFromNonQualifiedPath($logoId, null, $tagAttributes); 45 $mediaLink->setLazyLoad(false); 46 if ($mediaLink->exists()) { 47 return $mediaLink->renderMediaTag(); 48 } 49 } 50 return null; 51 } 52 53 private static function getLogoIds() 54 { 55 return PluginUtility::mergeAttributes(self::PNG_LOGO_IDS,self::SVG_LOGO_IDS); 56 } 57 58 59 /** 60 * @return string|null 61 */ 62 public static function getLogoUrlAsSvg() 63 { 64 65 66 $url = null; 67 foreach (self::SVG_LOGO_IDS as $svgLogo) { 68 69 $svgLogoFN = mediaFN($svgLogo); 70 71 if (file_exists($svgLogoFN)) { 72 $url = ml($svgLogo, '', true, '', true); 73 break; 74 }; 75 } 76 return $url; 77 } 78 79 public static function getLogoUrlAsPng() 80 { 81 82 $url = null; 83 foreach (self::PNG_LOGO_IDS as $svgLogo) { 84 85 $svgLogoFN = mediaFN($svgLogo); 86 87 if (file_exists($svgLogoFN)) { 88 $url = ml($svgLogo, '', true, '', true); 89 break; 90 }; 91 } 92 return $url; 93 } 94 95 /** 96 * https://www.dokuwiki.org/config:title 97 * @return mixed 98 */ 99 public static function getTitle() 100 { 101 global $conf; 102 return $conf['title']; 103 } 104 105 /** 106 * @param string $sep - the separator - generally ("-") but not always 107 * @return string 108 * 109 * Locale always canonicalizes to upper case. 110 */ 111 public static function getLocale($sep = "-") 112 { 113 114 $locale = null; 115 116 $lang = self::getLang(); 117 if ($lang != null) { 118 $country = self::getCountry(); 119 if ($country != null) { 120 $locale = strtolower($lang) . $sep . strtoupper($country); 121 } 122 } 123 124 return $locale; 125 } 126 127 /** 128 * 129 * ISO 3166 alpha-2 country code 130 * 131 */ 132 public static function getCountry() 133 { 134 $country = PluginUtility::getConfValue(self::CONF_SITE_ISO_COUNTRY); 135 if (!empty($country)) { 136 if (!StringUtility::match($country, "[a-zA-Z]{2}")) { 137 LogUtility::msg("The country configuration value ($country) does not have two letters (ISO 3166 alpha-2 country code)", LogUtility::LVL_MSG_ERROR, "country"); 138 } 139 return $country; 140 } else { 141 return null; 142 } 143 144 } 145 146 /** 147 * @return mixed|null 148 * Wrapper around https://www.dokuwiki.org/config:lang 149 */ 150 private static function getLang() 151 { 152 153 global $conf; 154 $locale = $conf['lang']; 155 return ($locale ? $locale : null); 156 } 157 158 public static function getUrl() 159 { 160 161 /** 162 * In a {@link PluginUtility::isDevOrTest()} dev environment, 163 * don't set the 164 * https://www.dokuwiki.org/config:baseurl 165 * to be able to test the metadata / social integration 166 * via a tunnel 167 */ 168 169 return DOKU_URL; 170 171 } 172 173 public static function getTag() 174 { 175 global $conf; 176 $tag = $conf['tag']; 177 return ($tag ? $tag : null); 178 } 179 180 /** 181 * @return string - the name of the sidebar page 182 */ 183 public static function getSidebarName() 184 { 185 global $conf; 186 return $conf["sidebar"]; 187 } 188 189 public static function setTemplate($template) 190 { 191 global $conf; 192 $conf['template'] = $template; 193 } 194 195 public static function setRenderingCacheOn() 196 { 197 // ensure the value is not -1, which disables caching 198 // https://www.dokuwiki.org/config:cachetime 199 global $conf; 200 $conf['cachetime'] = 60 * 60; 201 } 202 203 public static function debugIsOn() 204 { 205 global $conf; 206 return $conf['allowdebug']; 207 } 208 209 public static function setTemplateToStrap() 210 { 211 global $conf; 212 $conf['template'] = 'strap'; 213 } 214 215 public static function setTemplateToDefault() 216 { 217 global $conf; 218 $conf['template'] = 'dokuwiki'; 219 } 220 221 public static function setCacheDefault() 222 { 223 // The value is -1, which disables caching 224 // https://www.dokuwiki.org/config:cachetime 225 global $conf; 226 $conf['cachetime'] = -1; 227 } 228 229 public static function useHeadingAsTitle() 230 { 231 // https://www.dokuwiki.org/config:useheading 232 global $conf; 233 $conf['useheading'] = 1; 234 } 235 236 public static function useHeadingDefault() 237 { 238 // https://www.dokuwiki.org/config:useheading 239 global $conf; 240 $conf['useheading'] = 0; 241 } 242 243 public static function getTemplate() 244 { 245 global $conf; 246 return $conf['template']; 247 248 } 249 250 public static function isStrapTemplate() 251 { 252 global $conf; 253 return $conf['template'] == self::STRAP_TEMPLATE_NAME; 254 } 255 256 public static function getAjaxUrl() 257 { 258 return self::getUrl() . "lib/exe/ajax.php"; 259 } 260 261 public static function getPageDirectory() 262 { 263 global $conf; 264 return $conf['datadir']; 265 } 266 267 public static function disableHeadingSectionEditing() 268 { 269 global $conf; 270 $conf['maxseclevel'] = 0; 271 } 272 273 public static function setBreadCrumbOn() 274 { 275 global $conf; 276 $conf['youarehere'] = 1; 277 } 278 279 280} 281