#!/usr/bin/env php
.
*/
use danog\MadelineProto\API;
use danog\MadelineProto\APIFactory;
use danog\MadelineProto\MTProto;
use danog\MadelineProto\TON\API as TONAPI;
use danog\MadelineProto\TON\APIFactory as TONAPIFactory;
use danog\MadelineProto\TON\Lite;
\chdir($d=__DIR__.'/..');
require 'vendor/autoload.php';
$param = 1;
\danog\MadelineProto\Magic::classExists();
\danog\MadelineProto\Logger::constructor($param);
$logger = \danog\MadelineProto\Logger::$default;
\set_error_handler(['\danog\MadelineProto\Exception', 'ExceptionErrorHandler']);
\danog\MadelineProto\Logger::log('Copying readme...', \danog\MadelineProto\Logger::NOTICE);
\file_put_contents('docs/docs/index.md', '---
title: MadelineProto documentation
description: PHP client/server for the telegram MTProto protocol (a better tg-cli)
image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png
---
'.\str_replace(' $file) {
$layer = "v$layer";
$docs[] = [
'tl_schema' => ['telegram' => $file],
'title' => 'MadelineProto API documentation (layer '.$layer.')',
'description' => 'MadelineProto API documentation (layer '.$layer.')',
'output_dir' => "$d/docs/old_docs/API_docs_".$layer,
'readme' => true,
];
$layer_list .= '[Layer '.$layer.'](API_docs_'.$layer.'/)
';
}
$layer = \array_keys($res);
$layer = \end($layer);
$docs = [
/* [
'tl_schema' => ['td' => "$d/schemas/TL_td.tl"],
'title' => 'MadelineProto API documentation (td-lib)',
'description' => 'MadelineProto API documentation (td-lib)',
'output_dir' => "$d/docs/docs/TD_docs",
'readme' => false,
'td' => true,
],*/
[
'tl_schema' => ['mtproto' => "$d/schemas/TL_mtproto_v1.json"],
'title' => 'MadelineProto API documentation (mtproto)',
'description' => 'MadelineProto API documentation (mtproto)',
'output_dir' => "$d/docs/docs/MTProto_docs",
'readme' => false,
],
[
'tl_schema' => ['telegram' => "$d/schemas/TL_telegram_v$layer.tl", 'calls' => "$d/schemas/TL_calls.tl", 'secret' => "$d/schemas/TL_secret.tl", 'td' => "$d/schemas/TL_td.tl"],
'title' => "MadelineProto API documentation (layer $layer)",
'description' => "MadelineProto API documentation (layer $layer)",
'output_dir' => "$d/docs/docs/API_docs",
'readme' => false,
],
];
$doc = \file_get_contents('docs/docs/docs/USING_METHODS.md');
$doc = \preg_replace('|here \(layer \d+\)|', "here (layer $layer)", $doc);
\file_put_contents('docs/docs/docs/USING_METHODS.md', $doc);
\file_put_contents('docs/old_docs/README.md', '---
title: Documentations of old mtproto layers
description: Documentation of old mtproto layers
---
# Documentation of old mtproto layers
'.$layer_list);
$doc = new \danog\MadelineProto\AnnotationsBuilder(
$logger,
$docs[1],
\dirname(__FILE__).'/../src/danog/MadelineProto/InternalDoc.php',
[
'API' => API::class,
'APIFactory' => APIFactory::class,
'MTProto' => MTProto::class
],
'danog\\MadelineProto'
);
$doc->mkAnnotations();
$ton = [
'tl_schema' => [
'lite_api' => "$d/schemas/TON/lite_api.tl",
'ton_api' => "$d/schemas/TON/ton_api.tl",
//'tonlib_api' => "$d/schemas/TON/tonlib_api.tl",
]
];
$doc = new \danog\MadelineProto\AnnotationsBuilder(
$logger,
$ton,
\dirname(__FILE__).'/../src/danog/MadelineProto/TON/InternalDoc.php',
[
'API' => TONAPI::class,
'APIFactory' => TONAPIFactory::class,
'MTProto' => Lite::class
],
'danog\\MadelineProto\\TON'
);
$doc->mkAnnotations();
foreach ($docs as $settings) {
$doc = new \danog\MadelineProto\DocsBuilder($logger, $settings);
$doc->mkDocs();
}
\chdir(__DIR__.'/..');
$orderedfiles = [];
$order = [
'CREATING_A_CLIENT',
'LOGIN',
'FEATURES',
'REQUIREMENTS',
'INSTALLATION',
'UPDATES',
'SETTINGS',
'SELF',
'EXCEPTIONS',
'FLOOD_WAIT',
'LOGGING',
'CALLS',
'FILES',
'CHAT_INFO',
'DIALOGS',
'INLINE_BUTTONS',
'SECRET_CHATS',
'LUA',
'PROXY',
'ASYNC',
'USING_METHODS',
'CONTRIB',
'TEMPLATES',
];
$index = '';
$files = \glob('docs/docs/docs/*md');
foreach ($files as $file) {
$base = \basename($file, '.md');
if ($base === 'UPDATES_INTERNAL') {
continue;
}
$key = \array_search($base, $order);
if ($key !== false) {
$orderedfiles[$key] = $file;
}
}
\ksort($orderedfiles);
foreach ($orderedfiles as $key => $filename) {
$lines = \explode("\n", \file_get_contents($filename));
while (\end($lines) === '' || \strpos(\end($lines), 'Next')) {
unset($lines[\count($lines) - 1]);
}
if ($lines[0] === '---') {
\array_shift($lines);
while ($lines[0] !== '---') {
\array_shift($lines);
}
\array_shift($lines);
}
\preg_match('|^# (.*)|', $lines[0], $matches);
$title = $matches[1];
$description = $lines[2];
\array_unshift($lines, '---', 'title: '.$title, 'description: '.$description, 'image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png', '---');
if (isset($orderedfiles[$key + 1])) {
$nextfile = 'https://docs.madelineproto.xyz/docs/'.\basename($orderedfiles[$key + 1], '.md').'.html';
$prevfile = $key === 0 ? 'https://docs.madelineproto.xyz' : 'https://docs.madelineproto.xyz/docs/'.\basename($orderedfiles[$key - 1], '.md').'.html';
$lines[\count($lines)] = "\nNext section";
} else {
$lines[\count($lines)] = "\nNext section";
}
\file_put_contents($filename, \implode("\n", $lines));
$file = \file_get_contents($filename);
\preg_match_all('|( *)\* \[(.*)\]\((.*)\)|', $file, $matches);
$file = 'https://docs.madelineproto.xyz/docs/'.\basename($filename, '.md').'.html';
$index .= "* [$title]($file)\n";
if (\basename($filename) !== 'FEATURES.md') {
foreach ($matches[1] as $key => $match) {
$spaces = " $match";
$name = $matches[2][$key];
$url = $matches[3][$key][0] === '#' ? $file.$matches[3][$key] : $matches[3][$key];
$index .= "$spaces* [$name]($url)\n";
if ($name === 'FULL API Documentation with descriptions') {
$spaces .= ' ';
\preg_match_all('|\* (.*)|', \file_get_contents('docs/docs/API_docs/methods/index.md'), $smatches);
foreach ($smatches[1] as $key => $match) {
$match = \str_replace('href="', 'href="https://docs.madelineproto.xyz/API_docs/methods/', $match);
$index .= "$spaces* ".$match."\n";
}
}
}
}
}
$readme = \explode('## ', \file_get_contents('README.md'));
foreach ($readme as &$section) {
if (\explode("\n", $section)[0] === 'Documentation') {
$section = "Documentation\n\n".$index."\n";
}
}
$readme = \implode('## ', $readme);
\file_put_contents('README.md', $readme);
\file_put_contents('docs/docs/index.md', '---
title: MadelineProto documentation
description: PHP client/server for the telegram MTProto protocol (a better tg-cli)
image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png
---
'.$readme);