コード例 #1
0
function get_toc($post_id, $is_tutorial)
{
    /** 
     * This loop will show all the root maps, then when it
     * detects the root map that we're currently in (via the 
     * hierarchy), it will display all the submaps for that page
     * etc.
     **/
    $args_two = array("post_type" => "page", "post_parent" => $post_id, "orderby" => "menu_order", "order" => "ASC", "posts_per_page" => -1);
    $query_two = new WP_Query($args_two);
    if ($query_two->have_posts()) {
        ob_start();
        ?>
  	<div style="overflow:hidden;" page-id="<?php 
        echo $post_id;
        ?>
" class="closed">
  	<ul class="toc-list">
  		<?php 
        while ($query_two->have_posts()) {
            $query_two->the_post();
            ?>
		  <li page-id="<?php 
            echo get_the_ID();
            ?>
" class="toc-item">
		  	<?php 
            $children = get_pages('child_of=' . get_the_ID());
            $subsections = easydita_knowledge_portal_get_subsections();
            echo "<div class='toc-head' onclick='openCloseSubtoc(this)'>";
            if (count($children) != 0) {
                echo '<i class="plusminus-icon plus"> </i>';
                ?>
				<a href="<?php 
                echo the_permalink();
                ?>
" onclick="event.stopPropagation();"><?php 
                echo get_the_title();
                ?>
</a>
				</div>
				<?php 
                echo get_toc(get_the_ID(), $is_tutorial);
            } else {
                if ($is_tutorial && count($subsections) != 0) {
                    echo '<i class="plusminus-icon plus"> </i>';
                    ?>
				<a href="<?php 
                    echo the_permalink();
                    ?>
" onclick="event.stopPropagation();"><?php 
                    echo get_the_title();
                    ?>
</a>
				</div>
				<?php 
                    echo show_subsections_in_toc(get_the_ID(), $subsections);
                } else {
                    ?>
				<a href="<?php 
                    echo the_permalink();
                    ?>
"><?php 
                    echo get_the_title();
                    ?>
</a>
				</div>
				<?php 
                }
            }
            ?>
		  </li>
		  <?php 
        }
        ?>
</ul>
	</div><?php 
        return ob_get_clean();
    }
}
コード例 #2
0
        // put_cache_json(MANUAL_CACHE_TOC_FILE, $book, $manual_id);
    } elseif (array_key_exists(MANUAL_SOURCE_BOOK_FILE, $cache_update)) {
        if (!MANUAL_DEBUG_NO_HTTP_REQUEST) {
            // debug('book url', GITHUB_RAW_URL.MANUAL_SOURCE_BOOK_FILE);
            $book = get_content_from_github(GITHUB_RAW_URL . MANUAL_SOURCE_BOOK_FILE);
        } else {
            $book = file_get_contents('book_github.yaml');
        }
        $book = Spyc::YAMLLoadString($book);
        put_cache_json(MANUAL_CACHE_TOC_FILE, $book, $manual_id);
    } else {
        $book = get_cache_json(MANUAL_CACHE_TOC_FILE, $manual_id);
    }
    // debug('book', $book);
    // TODO: first read the book_toc from the cache
    $book_toc = get_toc($book['toc']);
    // debug('book_toc', $book_toc);
    $book_files = get_book_files($book_toc, $cache);
    // debug('book_files', $book_files);
    put_cache_json(MANUAL_CACHE_SECTION_FILE, $book_files, $manual_id);
    $book_language = get_language($book_toc, $cache);
    // debug('book_language', $book_language);
    put_cache_json(MANUAL_CACHE_LANGUAGE_FILE, $book_language, $manual_id);
    downlad_files($book_files, $manual_id, $cache);
    $book_toc_html = array();
    foreach (array_keys($book_language) as $item) {
        $book_toc_html[$item] = get_toc_html($book_toc, $manual_id, $item);
    }
    // debug('book_toc_html', $book_toc_html);
    put_cache_json(MANUAL_CACHE_TOC_HTML_FILE, $book_toc_html, $manual_id);
}