How I got Yii2 guide-ru

As I am Russian language native speaker, Yii2 Russian language guide helps me to understand the framework better.

And for some reasons I need to have it’s offline variant.

But I’ve never seen Yii2.chm or another offline file-type guide-ru.

Besides, this guide must be an actual.

So I wrote the script to get it on GitHub from *.md files (more precisely, web-pages)

(github.com/yiisoft/yii2/tree/master/docs/guide-ru).

You can also do it for another represented language.

The solution consists of several steps.

Sorry for cutted links, I’m not yet allowed to use normal links.

Please correct it by yourself.

  1. First of all you need to modify php.ini file and set

max_execution_time = 120



If you leave the default value (30) you’ll get fatal error

  1. Then I added action to controller, for example, SiteController.

public function actionGetMarkDownDocs()

    {

        return $this->render('getMarkDownDocs');

    }

  1. Then I created views/site/getMarkdownDocs.php view

Here is it’s code:




// getting page with list of .md files

$docSource = file_get_contents('...github.com/yiisoft/yii2/blob/master/docs/guide-ru/');


$files = [];


// getting file names from 'title' attributes

preg_match_all('/title=\"[a-z]+-+.*\.md\"/', $docSource, $files);


$fileNames = [];


foreach($files as $element)

{

    foreach($element as $string)

    {

        $string = substr($string, 7);

        $string = substr($string, 0, -4);

        $fileNames[] = $string;

    }

    

}


$data = '';

foreach($fileNames as $fileName)

{

    // getting each file

    $data = file_get_contents('...github.com/yiisoft/yii2/blob/master/docs/guide-ru/'.$fileName.'.md');

    

    //and put it, where you want

    file_put_contents('c:\docs\\'.$fileName.'.html', $data);

}

Then go to


yoursite/index.php?r=site/get-mark-down-docs

As a result I’ve got 62 saved web pages with guide info by one action.

P.S. Maybe this script is some kind of brutal force, but it works!