/** * Read a page and construct Toc (This is THE constructor) * * @access public * @todo should be able to separate functionalities more */ function construct_toc($page) { $lines = get_source($page); $title = null; $headlines = $includes = $extra = array(); sonots::remove_multilineplugin_lines($lines); foreach ($lines as $linenum => $line) { if (!isset($extra['fromhere'])) { if (preg_match($this->syntax['contents'], $line, $matches)) { $extra['fromhere'] = $linenum; continue; } } if (!isset($extra['readmore'])) { if (preg_match($this->syntax['readmore'], $line, $matches)) { $extra['readmore'] = $linenum; continue; } } if (preg_match($this->syntax['headline'], $line, $matches)) { $depth = strlen($matches[1]); list($string, $anchor) = sonots::make_heading($line); $headlines[$linenum] = new PluginSonotsHeadline($page, $linenum, $depth, $string, $anchor); continue; } if (preg_match($this->syntax['include'], $line, $matches)) { $inclargs = csv_explode(',', $matches[1]); $inclpage = array_shift($inclargs); $inclpage = get_fullname($inclpage, $page); if (!is_page($inclpage)) { continue; } $includes[$linenum] = new PluginSonotsIncludeline($linenum, $inclpage, $inclargs); continue; } if (preg_match($this->syntax['title'], $line, $matches)) { $title = $matches[1]; continue; } } $this->page = $page; $this->title = $title; $this->headlines = $headlines; $this->includes = $includes; $this->extra = $extra; }