cargar_modulos();
$this->cargar_diccionario();
$this->cargar_perfiles();
$this->pseudomarkdown_patrones = [
"cabecera" => ['/^(\#{1,6})([^\r\n]+)$/m', fn($campos) => '
' . $this->montar_pseudomarkdown($campos[1][0], self::PARRAFO) . ''], "perfil" => ['/^\[{2}perfil\s+([^\]]+)\]{2}/mi', fn($campo) => $this->construir_perfil($campo[1][0])], "parrafo" => ['/^(([^\r\n]+)(\r\n|\n|\r)?)+/m', fn($campos) => ($contenido = trim($campos[0][0])) ? (($tiene_etiqueta = $contenido[0] == '<') ? '' : '
') . $this->montar_pseudomarkdown($contenido, self::PARRAFO) . ($tiene_etiqueta ? '' : '
') : ''] ]; $html = self::string_variables($html, [ "menu" => implode("", array_map(fn($campos) => self::string_variables($this->modulos["elemento_menu_principal"], [ "i18n" => $campos[0], "texto" => $campos[1], "link" => $campos[2], "target" => $campos[3], "icono" => $campos[4] ]), [ ["mapeate_oficial", "Mapeate - Web oficial", "https://mapeate.k3y.pw/", "_self", "mapeate"], ["web_app_oficial", "Mapeate - Aplicación Web oficial", "https://mapeate.k3y.pw/app.html", "_self", "mapeate"], ["mapeate_git", "Mapeate - Git", "https://git.k3y.pw/CaritasSantaCruz/Mapeate", "_blank", "git"], ["caritas_santa_cruz_facebook", "Cáritas Santa Cruz - Facebook", "https://www.facebook.com/santacruzcaritas/", "_blank", "facebook"], ["caritas_santa_cruz_wix", "Cáritas Santa Cruz - Wix", "https://santacruzdecanido.wixsite.com/caritas", "_blank", "wix"], ["caritas_santa_cruz_twitter", "Cáritas Santa Cruz - Twitter", "https://twitter.com/CanidoSantaCruz", "_blank", "twitter"], ["caritas_santa_cruz_fan_web", "Cáritas Santa Cruz - Fan Web", "https://fanwebcaritassantacruz.k3y.pw/", "_blank", "fan_web"] ])), "diccionario" => base64_encode(json_encode($this->diccionario)), "contenido" => $this->montar_pseudomarkdown(file_get_contents(__DIR__ . "/../HTML/contenido.md")) ]); file_put_contents(__DIR__ . "/index.html", $html); echo $html; } private function cargar_modulos(){ $modulos_html = file_get_contents(__DIR__ . "/../HTML/modulos.html"); $this->modulos = []; while(preg_match('/<\!\-{2}\s*\[{2}([^\[\]]+)\]{2}(\s*\-{2}>)?/', $modulos_html, $matches, \PREG_OFFSET_CAPTURE)){ $clave = trim($matches[1][0]); if(preg_match('/<\!\-{2}\s*\[{2}\s*' . $clave . '\s*\]{2}(\s*\-{2}>)?/', $modulos_html = substr($modulos_html, $matches[0][1] + strlen($matches[0][0])), $matches, \PREG_OFFSET_CAPTURE)){ $this->modulos[$clave] = substr($modulos_html, 0, $matches[0][1]); $modulos_html = substr($modulos_html, $matches[0][1] + strlen($matches[0][0])); }; }; } private function cargar_diccionario(){ $i = -1; $this->diccionario = []; foreach(preg_split('/[\r\n]+/', file_get_contents(__DIR__ . "/../HTML/diccionario.md")) as $linea){ if(!$linea) continue; $tipo = $linea[0]; switch($tipo){ case "#": $this->diccionario[++ $i] = [ "crudo" => $crudo = trim(substr($linea, 1)), "clave" => preg_replace('/[^a-z0-9]+/', "_", strtolower($crudo)), "patrones" => [], "links" => [], "descripcion" => [] ]; break; case "-": $this->diccionario[$i]["links"][] = trim(substr($linea, 1)); break; case ">": $patron = preg_split('/\s*\-\s*/', trim(substr($linea, 1))); $this->diccionario[$i]["patrones"][] = [$patron[0], count($patron) > 1 ? $patron[1] : $this->diccionario[$i]["crudo"]]; break; default: $this->diccionario[$i]["descripcion"][] = $linea; break; }; }; } private function cargar_perfiles(){ $clave = null; $this->perfiles = []; foreach(preg_split('/[\r\n]+/', file_get_contents(__DIR__ . "/../HTML/perfiles.md")) as $linea){ if(!$linea) continue; $tipo = $linea[0]; switch($tipo){ case "#": $this->perfiles[$clave = preg_replace('/[^a-z0-9]+/i', "_", ($nombre = trim(substr($linea, 1))))] = [ "nombre" => $nombre, "clave" => $clave, "links" => [], "avatar" => null, "descripcion" => [] ]; break; case "-": $this->perfiles[$clave]["links"][] = trim(substr($linea, 1)); break; case ">": $this->perfiles[$clave]["avatar"] = trim(substr($linea, 1)); break; default: $this->perfiles[$clave]["descripcion"][] = $linea; break; }; }; } public function construir_perfil($clave){ return self::string_variables($this->modulos["elemento_perfil"], [ "clave" => $clave, "nombre" => $this->perfiles[$clave]["nombre"], "avatar" => $this->perfiles[$clave]["avatar"], "descripcion" => implode("", array_map(fn($parrafo) => '' . $parrafo . '
', $this->perfiles[$clave]["descripcion"])), "links" => implode("", array_map(fn($link) => self::string_variables($this->modulos["link_perfil"], [ "link" => $link, "tipo" => $tipo = preg_replace('/[^a-z0-9]+/', "_", preg_replace('/^[^\:]+\:\/{2}([^\/]+)(\/.*)?$/', "$1", $link)), "tipo_nombre" => $tipo ]), $this->perfiles[$clave]["links"])) ]); } public static function string_variables($string, $variables){ return preg_replace_callback('/\{([^\{\}]+)\}/', function($valor) use($variables){ if(isset($variables[$valor[1]])) return $variables[$valor[1]]; return $valor[0]; }, $string); } private function montar_lista($campos){ $lineas = preg_split('/[\r\n]+/', $campos); $html = ''; $niveles = [[0, "ul"]]; $l = 0; foreach($lineas as $linea){ if(!preg_match('/^(\s*)?(\-|[0-9]+\.)?(.*)$/', $linea, $matches)) continue; $separador = strlen($matches[1]); $tipo = $matches[2]; $entrada = $this->montar_pseudomarkdown(trim($matches[3]), self::PARRAFO); if($tipo){ if($niveles[$l][0] == $separador) $html .= ($html ? '' : '<' . ($niveles[$l][1] = $tipo == "-" ? "ul" : "ol") . '>') . '