Ejemplo n.º 1
0
 function __construct($pth)
 {
     if (!is_example_path($pth) or !is_example_exists($pth)) {
         throw new Exception("Example {$pth} not exists");
     }
     $this->pth = $pth;
     $this->file_id = last(explode('/', $pth));
     $category_path = implode('/', but_last(explode('/', $pth)));
     $this->id = find_position($this->file_id, $category_path);
     $this->category = Category::get($category_path);
 }
Ejemplo n.º 2
0
 public function testIsExamplePathSpecialCases()
 {
     $valid = ['php/100', 'php/hello.md', 'php/hello.html', 'php/h.1l3lo_w.rl2d-.md'];
     $invalid = ['100500', 'php/0', 'php/-1', 'php/0.2', 'php/HeLlo.md', 'php/hello.txt', 'php/привет.md'];
     foreach ($valid as $v) {
         $this->assertTrue(is_example_path($v), 'Testing: ' . $v);
     }
     foreach ($invalid as $v) {
         $this->assertFalse(is_example_path($v), 'Testing: ' . $v);
     }
 }
Ejemplo n.º 3
0
<?php

echo '<div id="usage"><div class="num">';
if (!is_example_path(path())) {
    echo '<a href="' . $data->url() . '" name="example_' . $data->id() . '">';
}
echo '<span>№</span>' . $data->id();
if (!is_example_path(path())) {
    echo '</a>';
}
echo '</div>';
echo '<div class="usage_example">';
echo $data->content();
echo '</div></div>';
?>

Ejemplo n.º 4
0
<?php

if (!path()) {
    draw_page('Поваренная книга программиста', dview('index_content', main_categories()));
} elseif (is_category_path(path()) && is_category_exists(path())) {
    is_need_cache(true);
    $category = new Category(path());
    keywords($category->keywords());
    draw_page($category->getTitle(), dview('one_category', $category));
} elseif (is_example_path(path()) && is_example_exists(path())) {
    is_need_cache(true);
    $example = new Example(path());
    keywords($example->keywords());
    draw_page($example->prop('desc'), view('path_block', ['id' => $example->id()]) . view('one_example', ['data' => $example, 'show_link' => true]));
} else {
    show_404();
}
Ejemplo n.º 5
0
<div id="navigation">
	 <a href='/'>/</a> &rarr;
<?php 
$path = bu::path();
$prefix = '/';
$last = $path[count($path) - 1];
$last_i = count($path) - 1;
foreach ($path as $k => $v) {
    $category_path = trim($prefix . $v, '/');
    if (is_category_path($category_path) && is_category_exists($category_path)) {
        $c = new Category($category_path);
        if ($k == $last_i) {
            echo '<b>' . $c->name() . '</b>' . "\n";
        } else {
            echo '<a href="' . $prefix . $v . '">' . $c->name() . '</a> &rarr;' . "\n";
        }
    } elseif (is_example_path($category_path) && is_example_exists($category_path)) {
        echo '<b>пример #' . $id . '</b>' . "\n";
    }
    $prefix = $prefix . $v . '/';
}
?>
</div>
Ejemplo n.º 6
0
<?php

if (!path()) {
    draw_page('Поваренная книга программиста', dview('index_content', main_categories()));
} elseif (is_category_path(path())) {
    if (Category::isValidPath(path())) {
        is_need_cache(true);
        $category = Category::get(path());
        keywords($category->keywords());
        draw_page($category->getTitle(), dview('one_category', $category));
    } else {
        show_404();
    }
} elseif (is_example_path(path())) {
    if (is_example_exists(path())) {
        is_need_cache(true);
        function example_title($example)
        {
            $cats = array();
            foreach (bu::path() as $v) {
                if (preg_match('/^[0-9]+$/', $v)) {
                    break;
                }
                $cats[] = Category::get($v)->name();
            }
            return 'Пример: ' . implode('/', $cats) . ' #' . $example->id();
        }
        $example = find_example(path());
        keywords($example->keywords());
        draw_page($example->prop('desc'), view('path_block', array('id' => $example->id())) . view('one_example', array('data' => $example, 'show_link' => true)));
    } else {
Ejemplo n.º 7
0
/**
 * Узнать сколько примеров в базе
 */
def('count_examples', function () {
    return trim(`cd data; find * -type f -name '[0-9]*' | wc -l`);
});
/**
 * Из каталога возвращает пути до всех примеров в правильном порядке
 */
def('ordered_exampls', function ($pth) {
    if (!is_category_exists($pth)) {
        throw new Exception("Category {$pth} not exists");
    }
    $PREFIX = data_directory() . '/' . $pth . '/';
    $data = array_filter(glob($PREFIX . '*'), function ($pth) {
        return is_example_path(strip_data_direcotry($pth)) && is_file($pth);
    });
    natsort($data);
    $data = array_values($data);
    $meta_pth = $PREFIX . 'meta.yaml';
    if (file_exists($meta_pth)) {
        $meta = unyaml($meta_pth);
        if (isset($meta['order'])) {
            $t = array_flip($data);
            $order = array_reverse($meta['order']);
            foreach ($order as $v) {
                unset($data[$t[$PREFIX . $v]]);
            }
            foreach ($order as $v) {
                array_unshift($data, $PREFIX . $v);
            }