public function testIsCategoryPath() { foreach ($this->valid_categories as $v) { $this->assertTrue(is_category_path($v), 'Testing: ' . $v); } foreach ($this->invalid_categories as $v) { $this->assertFalse(is_category_path($v), 'Testing: ' . $v); } }
<?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(); }
<div id="navigation"> <a href='/'>/</a> → <?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> →' . "\n"; } } elseif (is_example_path($category_path) && is_example_exists($category_path)) { echo '<b>пример #' . $id . '</b>' . "\n"; } $prefix = $prefix . $v . '/'; } ?> </div>
<?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 {
if (!preg_match('/^[0-9]+$/', last($t)) && !preg_match('/^[a-z0-9_.-]+\\.(md|html)$/', last($t))) { return false; } if (!last($t)) { return false; } if (!is_category_path(implode('/', but_last($t)))) { return false; } return true; }); /** * Существует ли эта категория в папке с данными? */ def('is_category_exists', function ($path) { if (!is_category_path($path)) { throw new Exception('Path is not valid: ' . $path); } $path = data_directory() . '/' . $path; if (file_exists($path) && is_dir($path)) { return true; } return false; }); /** * Существует ли пример по данному пути */ def('is_example_exists', function ($path) { if (!is_example_path($path)) { throw new Exception('Path is not valid: ' . $path); }
} } return true; }); def('is_example_path', function ($url) { if (!$url) { return; } $t = explode('/', $url); if (!preg_match('/^[0-9]+$/', last($t))) { return; } if (!last($t)) { return; } if (!is_category_path(implode('/', but_last($t)))) { return; } return true; }); def('is_example_exists', function ($path) { $path = 'data/' . $path; if (file_exists($path) and is_file($path)) { return true; } }); def('find_example', function ($path) { return new Example($path); }); def('find_position', function ($id, $pth) { $i = 0;