Example #1
0
 /**
  * Создаём из пути объект-категории
  */
 public function __construct($path)
 {
     if (!is_category_exists($path)) {
         throw new Exception("Path not exists {$path}");
     }
     $this->_path = $path;
     $parent_path = preg_replace('@/[^/]+$@', '', $path);
     if ($parent_path != $path && $parent_path) {
         $this->parent = new Category($parent_path);
     }
 }
Example #2
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();
}
Example #3
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>
Example #4
0
 public function testIsCategoryExistsRaiseException()
 {
     $this->expectException(Exception::class);
     is_category_exists('php/рашндир');
 }
Example #5
0
    } else {
        return $href;
    }
    return '<a href="' . $href . '">' . $name . '</a>';
});
/**
 * Узнать сколько примеров в базе
 */
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) {