diff --git a/entirewiki.php b/entirewiki.php index 25fde70..5b7b098 100644 --- a/entirewiki.php +++ b/entirewiki.php @@ -24,9 +24,9 @@ */ require_once(dirname(__FILE__) . '/../../config.php'); -require($CFG->dirroot.'/mod/ouwiki/basicpage.php'); +require($CFG->dirroot . '/mod/ouwiki/basicpage.php'); -$id = required_param('id', PARAM_INT); // Course Module ID +$id = required_param('id', PARAM_INT); // Course Module ID. $pagename = optional_param('page', '', PARAM_TEXT); $filesexist = optional_param('filesexist', 0, PARAM_INT); @@ -38,7 +38,7 @@ throw new moodle_exception('invalidcoursemodule'); } - // Checking course instance + // Checking course instance. $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); if (!$ouwiki = $DB->get_record('ouwiki', array('id' => $cm->instance))) { @@ -54,13 +54,14 @@ $ouwikioutput = $PAGE->get_renderer('mod_ouwiki'); $format = required_param('format', PARAM_ALPHA); -if ($format !== OUWIKI_FORMAT_HTML && $format !== OUWIKI_FORMAT_RTF && $format !== OUWIKI_FORMAT_TEMPLATE) { +if ($format !== OUWIKI_FORMAT_HTML && $format !== OUWIKI_FORMAT_PDF + && $format !== OUWIKI_FORMAT_TEMPLATE && $format !== OUWIKI_FORMAT_HTML_PRINT) { throw new moodle_exception('Unexpected format'); } -// Get basic wiki details for filename -$filename = $course->shortname.'.'.$ouwiki->name; -$filename = preg_replace('/[^A-Za-z0-9.-]/' , '_', $filename); +// Get basic wiki details for filename. +$filename = $course->shortname . '.' . $ouwiki->name; +$filename = preg_replace('/[^A-Za-z0-9.-]/', '_', $filename); $markup = ''; $fs = null; @@ -71,12 +72,31 @@ $files = array(); $fs = get_file_storage(); break; - case OUWIKI_FORMAT_RTF: - require_once($CFG->dirroot.'/local/rtf.php'); - $markup = '

'.get_string('savedat', 'ouwiki', userdate(time())).'


'; + case OUWIKI_FORMAT_HTML_PRINT: + + $urlobjectarray = $PAGE->theme->css_urls($PAGE); + $urlobject = $urlobjectarray[0]; + $cssurl = $urlobject->out(); + + $markup = ''; + $markup .= ''; + $markup .= ''; + $markup .= ''; + $markup .= ''; + + break; + case OUWIKI_FORMAT_PDF: + + $markup = ''; + $css = file_get_contents(dirname(__FILE__) . '/style/pdf.css'); + $markup .= ''; + $markup .= ''; + $markup .= ''; + $markup .= ''; + break; case OUWIKI_FORMAT_HTML: - // Do header + // Do header. echo $ouwikioutput->ouwiki_print_start($ouwiki, $cm, $course, $subwiki, get_string('entirewiki', 'ouwiki'), $context, null, false, true); print '
'; break; @@ -98,30 +118,48 @@ } } + // If tree view specified. -if (($treemode) && ($format == OUWIKI_FORMAT_HTML) ) { +if (($treemode) && ($format == OUWIKI_FORMAT_HTML || $format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT)) { + ouwiki_build_tree($index); // Print out in hierarchical form... - print ''; if ($orphans) { - print '

'.get_string('orphanpages', 'ouwiki').'

'; - print ''; + } + + if ($format == OUWIKI_FORMAT_HTML) { + print $treeoutput; } + + if ($format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT) { + + if ($format == OUWIKI_FORMAT_PDF) { + $treeoutput = replace_image_urls($context, $treeoutput, 0, true); + } + + $markup .= $treeoutput; + } + } else { foreach ($index as $pageinfo) { - if (count($pageinfo->linksfrom)!= 0 || $pageinfo->title === '') { + if (count($pageinfo->linksfrom) != 0 || $pageinfo->title === '') { // Get page details. $pageversion = ouwiki_get_current_page($subwiki, $pageinfo->title); // If the page hasn't really been created yet, skip it. @@ -129,7 +167,16 @@ continue; } - $markup .= get_online_display_content($format, $pageversion, $context, $subwiki, $cm, $index, $fs, $files); + + $output = get_online_display_content($format, $pageversion, $context, $subwiki, $cm, $index, $fs, $files); + + if ($format == OUWIKI_FORMAT_HTML) { + print $output; + } + + if ($format == OUWIKI_FORMAT_PDF || $format == OUWIKI_FORMAT_HTML_PRINT) { + $markup .= $output; + } if ($first) { $first = false; @@ -139,9 +186,9 @@ if ($orphans) { if ($format == OUWIKI_FORMAT_HTML) { - print '

'.get_string('orphanpages', 'ouwiki').'

'; + print '

' . get_string('orphanpages', 'ouwiki') . '

'; } else if ($format != OUWIKI_FORMAT_TEMPLATE) { - $markup .= '

'.get_string('orphanpages', 'ouwiki').'

'; + $markup .= '

' . get_string('orphanpages', 'ouwiki') . '

'; } foreach ($index as $indexitem) { @@ -184,9 +231,28 @@ exit; break; - case OUWIKI_FORMAT_RTF: - $markup .= ''; - rtf_from_html($filename.'.rtf', $markup); + case OUWIKI_FORMAT_HTML_PRINT: + + $markup .= ''; + + echo $markup; + break; + + case OUWIKI_FORMAT_PDF: + $markup .= ''; + + require_once($CFG->libdir . '/pdflib.php'); + + $doc = new pdf; + $doc->setFont('helvetica'); + $doc->setPrintHeader(false); + $doc->setPrintFooter(false); + $doc->AddPage(); + $doc->writeHTML($markup); + $doc->Output(explode('.', $filename)[1] . '.pdf'); + + clean_up($markup); + break; case OUWIKI_FORMAT_HTML: @@ -200,7 +266,7 @@ function get_online_display_content($format, $pageversion, $context, $subwiki, $ if ($format != OUWIKI_FORMAT_TEMPLATE) { $pageversion->xhtml = file_rewrite_pluginfile_urls($pageversion->xhtml, 'pluginfile.php', - $context->id, 'mod_ouwiki', 'content', $pageversion->versionid); + $context->id, 'mod_ouwiki', 'content', $pageversion->versionid); } switch ($format) { @@ -213,25 +279,25 @@ function get_online_display_content($format, $pageversion, $context, $subwiki, $ $markup .= '' . $pageversion->versionid . ''; // Copy images found in content. preg_match_all('##', $pageversion->xhtml, $matches); - if (! empty($matches)) { + if (!empty($matches)) { // Extract the file names from the matches. foreach ($matches[1] as $key => $match) { // Get file name and copy to zip. $match = urldecode($match); // Copy image - on fail swap tag with string. if ($file = $fs->get_file($context->id, 'mod_ouwiki', 'content', - $pageversion->versionid, '/', $match)) { + $pageversion->versionid, '/', $match)) { $files["/$pageversion->versionid/$match/"] = $file; } else { $pageversion->xhtml = str_replace($matches[0][$key], $brokenimagestr, - $pageversion->xhtml); + $pageversion->xhtml); } } } $markup .= '' . htmlspecialchars($pageversion->xhtml) . ''; // Add attachments. if ($attachments = $fs->get_area_files($context->id, 'mod_ouwiki', 'attachment', - $pageversion->versionid, 'itemid', false)) { + $pageversion->versionid, 'itemid', false)) { // We have attachements. $markup .= ''; $attachmentsarray = array(); @@ -245,15 +311,23 @@ function get_online_display_content($format, $pageversion, $context, $subwiki, $ } $markup .= ''; break; - case OUWIKI_FORMAT_RTF: - $markup .= '

' . htmlspecialchars($visibletitle) . '

'; - $markup .= trim($pageversion->xhtml); - $markup .= '


'; + case OUWIKI_FORMAT_PDF || OUWIKI_FORMAT_HTML_PRINT: + + $markup .= '

' . + '' . htmlspecialchars($visibletitle) . '

'; + $markup .= ouwiki_convert_content($pageversion->xhtml, $subwiki, $cm, $index, $pageversion->xhtmlformat); + $markup .= '
'; + + if ($format === OUWIKI_FORMAT_PDF) { + $markup = replace_image_urls($context, $markup, $pageversion->versionid); + } + break; case OUWIKI_FORMAT_HTML: print '

' . - '' . htmlspecialchars($visibletitle) . '

'; + '' . htmlspecialchars($visibletitle) . ''; print ouwiki_convert_content($pageversion->xhtml, $subwiki, $cm, $index, $pageversion->xhtmlformat); print '
'; break; @@ -262,3 +336,65 @@ function get_online_display_content($format, $pageversion, $context, $subwiki, $ return $markup; } + + +/** + * @param $context + * @param $xhtml + * @param $itemid + * @param bool $treemode + * @return mixed + */ +function replace_image_urls($context, $xhtml, $itemid, $treemode = false) { + $content = $xhtml; + preg_match_all('##', $content, $matches); + + $fs = get_file_storage(); + $tmpdir = create_dir(dirname(__FILE__) . '/pdf_images'); + + if (!empty($matches)) { + // Extract the file names from the matches. + + foreach ($matches[1] as $match) { + $urlinfo = pathinfo($match); + $image = urldecode($urlinfo['basename']); + + if ($treemode) { + $tmp = explode('/', $urlinfo['dirname']); + $itemid = $tmp[count($tmp) - 1]; + } + + if (!$file = $fs->get_file($context->id, 'mod_ouwiki', 'content', $itemid, '/', $image)) { + continue; + } + + $filename = $file->get_filename(); + $filepath = "$tmpdir/$filename"; + if (file_exists($filepath) || $file->copy_content_to($filepath)) { + $content = str_replace($match, $filepath, $content); + } + + } + } + return $content; +} + +function create_dir($path) { + if (!file_exists($path)) { + mkdir($path, 0777, true); + } + return $path; +} + +/** + * Removes the temporary local image files used for creating the pdf + * @param $html + */ +function clean_up($html) { + preg_match_all('##', $html, $matches); + if (!empty($matches)) { + foreach ($matches[1] as $filepath) { + unlink($filepath); + } + } +} diff --git a/lang/en/ouwiki.php b/lang/en/ouwiki.php index d1b0617..757d403 100644 --- a/lang/en/ouwiki.php +++ b/lang/en/ouwiki.php @@ -629,5 +629,12 @@ $string['wiki_content_mask'] = 'Replace with fake text of a similar length, retaining HTML tags and [[wiki page]] links'; +$string['tableofcontents'] = 'Table of contents'; +$string['printwiki'] = 'Print Wiki '; +$string['print_pdf_alphabetic'] = 'PDF (Alphabetic)'; +$string['print_pdf_tree_structure'] = 'PDF (Tree)'; +$string['print_html_alphabetic'] = 'HTML (Alphabetic)'; +$string['print_html_tree_structure'] = 'HTML (Tree)'; + $string['savecheck'] = 'Enable save check'; $string['savecheck_desc'] = 'Enable checking of session etc on submitting the edit form.'; diff --git a/locallib.php b/locallib.php index 8589fe9..5768899 100644 --- a/locallib.php +++ b/locallib.php @@ -51,8 +51,9 @@ define('OUWIKI_PARAMS_ARRAY', 3); define('OUWIKI_FORMAT_HTML', 'html'); -define('OUWIKI_FORMAT_RTF', 'rtf'); +define('OUWIKI_FORMAT_PDF', 'pdf'); define('OUWIKI_FORMAT_TEMPLATE', 'template'); +define('OUWIKI_FORMAT_HTML_PRINT', 'print'); // pages define('OUWIKI_GETPAGE_REQUIREVERSION', 0); @@ -151,8 +152,8 @@ function ouwiki_get_subwiki($course, $ouwiki, $cm, $context, $groupid, $userid, switch($ouwiki->subwikis) { case OUWIKI_SUBWIKIS_SINGLE: - $subwiki = $DB->get_record_select('ouwiki_subwikis', 'wikiid = ? AND groupid IS NULL - AND userid IS NULL', array($ouwiki->id)); + // Removed AND groupid IS NULL AND userid IS NULL + $subwiki = $DB->get_record_select('ouwiki_subwikis', 'wikiid = ?', array($ouwiki->id)); if ($subwiki) { ouwiki_set_extra_subwiki_fields($subwiki, $ouwiki, $context); return $subwiki; @@ -186,8 +187,7 @@ function ouwiki_get_subwiki($course, $ouwiki, $cm, $context, $groupid, $userid, $othergroup = !groups_is_member($groupid); // Place get subwiki here to facilitate checking agaimst magic number below. - $subwiki = $DB->get_record_select('ouwiki_subwikis', 'wikiid = ? AND groupid = ? - AND userid IS NULL', array($ouwiki->id, $groupid)); + $subwiki = $DB->get_record_select('ouwiki_subwikis', 'wikiid = ? AND groupid = ?', array($ouwiki->id, $groupid)); if ($othergroup && $cm->groupmode == SEPARATEGROUPS) { // Ignore if in feed, @@ -247,9 +247,9 @@ function ouwiki_get_subwiki($course, $ouwiki, $cm, $context, $groupid, $userid, } } } - // OK now find wiki - $subwiki = $DB->get_record_select('ouwiki_subwikis', 'wikiid = ? AND groupid IS NULL - AND userid = ?', array($ouwiki->id, $userid)); + // OK now find wiki. + // Removed AND groupid IS NULL. + $subwiki = $DB->get_record_select('ouwiki_subwikis', 'wikiid = ? AND userid = ?', array($ouwiki->id, $userid)); if ($subwiki) { ouwiki_set_extra_subwiki_fields($subwiki, $ouwiki, $context, $otheruser, !$otheruser); return $subwiki; @@ -275,9 +275,11 @@ function ouwiki_create_subwiki($ouwiki, $cm, $course, $userid = null, $groupid = $subwiki = new StdClass; $subwiki->wikiid = $ouwiki->id; - $subwiki->userid = $userid; - $subwiki->groupid = $groupid; - $subwiki->magic = ouwiki_generate_magic_number(); + $subwiki->magic = ouwiki_generate_magic_number(); + $subwiki->userid = ($userid) ? $userid : $subwiki->magic; + $subwiki->groupid = ($groupid) ? $groupid : $subwiki->magic; + + // Create Wiki! try { $subwiki->id = $DB->insert_record('ouwiki_subwikis', $subwiki); } catch (Exception $e) { diff --git a/pix/icon.gif b/pix/icon.gif deleted file mode 100644 index c891b20..0000000 Binary files a/pix/icon.gif and /dev/null differ diff --git a/pix/icon.png b/pix/icon.png new file mode 100644 index 0000000..7cd6545 Binary files /dev/null and b/pix/icon.png differ diff --git a/renderer.php b/renderer.php index a227806..80fca09 100644 --- a/renderer.php +++ b/renderer.php @@ -212,8 +212,17 @@ public function get_topheading_section($title, $gewgaws, $pageversion, $annotati $cm = $this->params->cm; $output = html_writer::start_tag('div', array('class' => 'ouw_topheading')); $output .= html_writer::start_tag('div', array('class' => 'ouw_heading')); + $output .= html_writer::tag('h2', format_string($title), array('class' => 'ouw_topheading')); + + // Add table of contents. + global $CFG; + require_once($CFG->dirroot.'/mod/ouwiki/tableofcontents.php'); + $toc = new TableOfContents($pageversion->xhtml); + $output .= $toc->to_html(); + + if ($gewgaws) { $output .= $this->render_heading_bit(1, $pageversion->title, $subwiki, $cm, null, $annotations, $pageversion->locked, $files, @@ -748,7 +757,9 @@ public function ouwiki_get_links() { */ public function ouwiki_get_links_content() { global $USER; + $output = html_writer::start_tag('ul'); + if ($this->params->page == 'wikiindex.php') { $output .= html_writer::start_tag('li', array('id' => 'ouwiki_nav_index')); $output .= html_writer::start_tag('span'); @@ -826,6 +837,56 @@ public function ouwiki_get_links_content() { $output .= html_writer::end_tag('li'); } } + + $params = $this->params; + + $wikiparams = function ($format, $istree = false) use ($params) { + + $subwiki = $params->subwiki; + $cm = $params->cm; + + $url = 'entirewiki.php?'; + $url .= html_entity_decode(ouwiki_display_wiki_parameters('', $subwiki, $cm)); + $url .= sprintf('&format=%s', $format); + + if ($istree) { + $url .= '&type=tree'; + } + return $url; + }; + + // Dropdown for print functions. + $output .= html_writer::start_tag('li', array('id' => 'ouwiki_nav_print')); + $output .= html_writer::start_tag('div', array('class' => 'btn-group')); + + $output .= html_writer::start_tag('button', array('class' => 'btn dropdown-toggle', 'data-toggle' => 'dropdown')); + $output .= get_string('printwiki', 'ouwiki'); + $output .= html_writer::tag('span', '', array('class' => 'caret')); + $output .= html_writer::end_tag('button'); + + $output .= html_writer::start_tag('ul', array('class' => 'dropdown-menu')); + + $output .= html_writer::start_tag('li'); + $output .= html_writer::tag('a', get_string('print_pdf_alphabetic', 'ouwiki'), array('target' => '_blank', 'href' => $wikiparams(OUWIKI_FORMAT_PDF))); + $output .= html_writer::end_tag('li'); + + $output .= html_writer::start_tag('li'); + $output .= html_writer::tag('a', get_string('print_pdf_tree_structure', 'ouwiki'), array('target' => '_blank', 'href' => $wikiparams(OUWIKI_FORMAT_PDF, true))); + $output .= html_writer::end_tag('li'); + + $output .= html_writer::start_tag('li'); + $output .= html_writer::tag('a', get_string('print_html_alphabetic', 'ouwiki'), array('target' => '_blank', 'href' => $wikiparams(OUWIKI_FORMAT_HTML_PRINT))); + $output .= html_writer::end_tag('li'); + + $output .= html_writer::start_tag('li'); + $output .= html_writer::tag('a', get_string('print_html_tree_structure', 'ouwiki'), array('target' => '_blank', 'href' => $wikiparams(OUWIKI_FORMAT_HTML_PRINT, true))); + $output .= html_writer::end_tag('li'); + + $output .= html_writer::end_tag('ul'); + + $output .= html_writer::end_tag('div'); + $output .= html_writer::end_tag('li'); + $output .= html_writer::end_tag('ul'); return array($output, $participationstr); } diff --git a/style/pdf.css b/style/pdf.css new file mode 100644 index 0000000..e69de29 diff --git a/styles.css b/styles.css index 7df94d5..04ff80e 100644 --- a/styles.css +++ b/styles.css @@ -10,7 +10,7 @@ visibility: hidden; } #page-mod-ouwiki-view .ouw_recentchanges { - font-size:0.85em; + font-size:0.7em; color:#636363; margin-top:0.5em; } @@ -58,6 +58,11 @@ #page-mod-ouwiki-contributions th { text-align:left; padding: 5px 12px 5px 4px; + background: #f5f5f5; + border-left: 1px solid #f5f5f5; + border-right: 1px solid #f5f5f5; + border-top:1px solid #f5f5f5; + border-bottom:1px solid #f5f5f5; } .dir-rtl#page-mod-ouwiki-history .ouw_history th, .dir-rtl#page-mod-ouwiki-wikihistory th, @@ -69,6 +74,17 @@ #page-mod-ouwiki-wikihistory td, #page-mod-ouwiki-contributions td { padding: 3px 12px 3px 4px; + border-bottom:1px solid #888; +} +#page-mod-ouwiki-wikihistory td.ouw_rightcol, +#page-mod-ouwiki-contributions td.ouw_rightcol, +#page-mod-ouwiki-history .ouw_history td.ouw_rightcol { + border-right:1px solid #888; +} +#page-mod-ouwiki-wikihistory td.ouw_leftcol, +#page-mod-ouwiki-contributions td.ouw_leftcol, +#page-mod-ouwiki-history .ouw_history td.ouw_leftcol { + border-left:1px solid #888; } #page-mod-ouwiki-history .ouw_history td.check, #page-mod-ouwiki-history .ouw_history td.comparebutton { @@ -159,11 +175,12 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { text-align: left; } -#ouwiki_indexlinks ul { +#ouwiki_indexlinks { margin:0; padding:0; display:inline; } + #ouwiki_indexlinks form, #ouwiki_indexlinks form div { display:inline; @@ -175,7 +192,7 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { width:10em; } -#ouwiki_indexlinks li { +#ouwiki_nav_print, #ouwiki_nav_index, #ouwiki_nav_history, #ouwiki_nav_participation { margin:0 0.5em 0 0; padding:0; list-style-type:none; @@ -184,17 +201,42 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { #ouwiki_noindexlink { height:1em; } -#ouwiki_indexlinks a { - border:1px solid #aaa; - padding:2px; - font-size:84%; + +#ouwiki_indexlinks > ul > li > a, +#ouwiki_indexlinks > ul > li > a:visited, +#ouwiki_indexlinks > ul > li > a:active, +#ouwiki_indexlinks > ul > li > a:link, +#ouwiki_indexlinks > ul > li > a:focus { + padding:6px 12px; + border:1px solid #ccc; + margin-right:5px; + border-radius: 4px; + text-align:center; + font-size:13px; + vertical-align: middle; + background-color:#fff } -#ouwiki_indexlinks span { - border:1px solid black; - padding:2px; - font-size:84%; + +#ouwiki_indexlinks a:hover { + background-color:#f1f1f1; + text-decoration: none; + color:#333; + border:1px solid #bbb; } +/* #ouwiki_indexlinks span { + padding:6px 12px; + margin-right:5px; + border-radius: 4px; + text-align:center; + font-size:13px; + vertical-align: middle; + border:1px solid #ddd; + background-color:#ddd; + font-weight: bold; +} + */ + #page-mod-ouwiki-wikiindex ul.ouw_index, #page-mod-ouwiki-wikiindex ul.ouw_index li, #page-mod-ouwiki-wikiindex ul.ouw_indextree, @@ -213,9 +255,9 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { #page-mod-ouwiki-wikiindex .ouw_title { display:block; font-weight:bold; - background:#dcedff; + background:#f5f5f5; padding:4px 8px 8px; - border-top:1px solid #888; + border:1px solid #888; margin-top:-1px; color: black; } @@ -225,14 +267,14 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { } #page-mod-ouwiki-import .ouw_indexinfo, #page-mod-ouwiki-wikiindex .ouw_indexinfo { - border:1px dotted #888; + border:1px solid #888; border-top:none; padding:4px 8px 6px; font-size:0.8em; color:#888; } #page-mod-ouwiki-wikiindex .ouw_index .ouw_index_startpage .ouw_indexinfo { - border-bottom:1px dotted #888; + border-bottom:1px solid #888; } .ie#page-mod-ouwiki-wikiindex .ouw_index_startpage .ouw_title { border-top:2px solid #888; @@ -298,9 +340,9 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { #page-mod-ouwiki-diff .ouw_diff { background:#f0f0f0; color:#636363; - border-left:1px dotted #888; - border-right:1px dotted #888; - border-bottom:1px dotted #888; + border-left:1px solid #888; + border-right:1px solid #888; + border-bottom:1px solid #888; padding:8px; } #page-mod-ouwiki-diff .ouw_left .ouw_diff, @@ -341,9 +383,35 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { font-weight:normal; font-style:normal; font-size:0.85em; - margin-left:1em; + margin-left:0px; +} + +/* Edited */ +#page-mod-ouwiki-view .ouw_byheading a { + padding:5px 5px; + border:1px solid #ccc; + margin-right:5px; + border-radius: 4px; + text-align:center; + font-size:12px; + vertical-align: middle; + background-color:#fff; + margin-left:0px; + display:inline-block; +} + +.ouw_heading3 a { + margin-left: 0; +} + +#page-mod-ouwiki-view .ouw_byheading a:hover { + background-color:#f1f1f1; + text-decoration: none; + color:#333; + border:1px solid #bbb; } + #page-mod-ouwiki-view .ouw_editsection, #page-mod-ouwiki-view .ouw_annotate, #page-mod-ouwiki-view .ouw_editpage, @@ -372,30 +440,53 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { .ouwiki_content h1, .ouwiki_content h2 { font-size:1.5em; - display:inline; + display:block; + padding:0px; + line-height:150%; } + .ouwiki_content h3, .ouwiki_content h4, +.ouwiki_content h5 { + display:block; + padding:0px; + line-height:150%; + font-weight:bold +} + +.ouwiki_content h3 { + border-bottom:1px solid #888; + padding-bottom:2px; + font-size:1.5em; +} + +.ouwiki_content h4 { + font-size:1.2em; +} + .ouwiki_content h5 { font-size:1em; - display:inline; } + + .ouwiki_content h6 { - font-size:0.85em; - display:inline; + font-size:1em; + display:block; + padding:0px; + line-height:150%; } .ouwiki_content .ouw_heading1, .ouwiki_content .ouw_heading2 { - margin:0.6667em 0 0.3333em 0; + margin:0 0 0.3333em 0; } .ouwiki_content .ouw_heading3, .ouwiki_content .ouw_heading4, .ouwiki_content .ouw_heading5 { - margin:1em 0 0.5em 0; + margin:0 0 0.5em 0; } .ouwiki_content .ouw_heading6 { - margin:1.25em 0 0.625em 0; + margin:0 0 0.625em 0; } .ouwiki_content h1.ouw_fixedheading, @@ -414,20 +505,11 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { } .ouwiki_content h1 { padding-bottom:2px; - border-bottom:1px dotted #888; + border-bottom:1px solid #888; } .ouwiki_content h6.ouw_fixedheading .ouw_headingtext { font-size:0.85em; } -.ouwiki_content h3 { - border-bottom:1px dotted #888; - padding-bottom:2px; -} -.ouwiki_content h5, -.ouwiki_content h6 { - font-weight:normal; - font-style:italic; -} #ouw_ac_formcontainer { margin-top:1.5em; @@ -499,15 +581,16 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { } #page-mod-ouwiki-view .ouw_linkedfrom h3 { margin:0; - font-size:1em; - font-weight:normal; + font-size:1.2em; + font-weight:bold; } + +/* Edited */ #page-mod-ouwiki-view .ouw_linkedfrom ul, #page-mod-ouwiki-view .ouw_linkedfrom li { - margin:0; - padding:0; - list-style-type:none; - display:inline; + font-size:1.2em; + list-style-type:disc; + text-decoration: underline; } #page-mod-ouwiki-wikiindex .ouw_missingpages ul, @@ -570,23 +653,41 @@ a.ouwiki_noshow:link,a.ouwiki_noshow:visited { margin-bottom:2em; } +.ouw_subscribe { + margin-top:2em; + font-size:0.85em; +} +.ouw_subscribe img { + vertical-align:bottom; +} +.ouw_subscribe span { + position:relative; + top:-1px; +} + +/* Edited */ .ouw_belowmainhead { - border:1px dotted #888; + border:none; border-top:none; padding:0px 8px 4px; + margin-top:45px; } .ouw_topspacer { padding-top:4px; } .ouw_topheading { - background:#dcedff; + background:#f5f5f5; padding:4px 8px 8px; - border-top:1px solid #888; + border:1px solid #888; margin-top:1.5em; } .ouw_topheading h2 { border:none; + margin-top:0px; + margin-bottom: 0px; + margin-left:0px; + padding:0px; } @@ -595,6 +696,32 @@ a.ouwiki_noshow:link,a.ouwiki_noshow:visited { list-style-type:none; } +/* Edited */ + +#ouwiki_addnew { + margin-top: 45px; +} + +#ouwiki_addnew ul { + list-style-type: none; + border-top: 1px solid rgb(192, 192, 192); + padding-top: 10px; + margin-left: 0px; +} + + +.ouw_linkedfrom .ouw_topheading { + + background: none; + padding:0px; + border: none; + border-top:1px solid #c0c0c0; +} + + +/* End */ + + #page-mod-ouwiki-entirewiki .ouw_entry h1.ouw_entry_heading { background:#dcedff; padding:4px 8px 8px; @@ -604,7 +731,7 @@ a.ouwiki_noshow:link,a.ouwiki_noshow:visited { margin:0.5em 0 0; } #page-mod-ouwiki-entirewiki .ouw_entry .ouwiki_content { - border:1px dotted #888; + border:1px solid #888; border-top:none; padding:4px 8px; margin-top:0; @@ -707,7 +834,7 @@ a.ouwiki_noshow:link,a.ouwiki_noshow:visited { } #page-mod-ouwiki-annotate #mform1 .fitem .fitemtitle { - padding-right: 15px; + margin-left: -30px; width: 160px; } @@ -878,6 +1005,23 @@ a.ouwiki_noshow:link,a.ouwiki_noshow:visited { font-size: 0.8em; margin-left: 5px; } -.ouw-comparebutton-wrapper { - text-align: right; + +div#ouwiki_indexlinks > ul > li { + display:inline +} + +/* this version seems better */ +ol.toc { + counter-reset: item; + padding: 5px; +} +li.toc_element > ol { + counter-reset: item; +} +li.toc_element { + display: block; } +li.toc_element::before { + content: counters(item, ".") " "; + counter-increment: item; +} \ No newline at end of file diff --git a/tableofcontents.php b/tableofcontents.php new file mode 100644 index 0000000..4fa85c2 --- /dev/null +++ b/tableofcontents.php @@ -0,0 +1,113 @@ +. + +/** + * Version 1.0 + * + * @package mod_ouwiki + * @copyright 2016 The Open University + * @author Joel Tschesche + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class TableOfContents +{ + + private $html = ""; + private $headings = array(); + + public function __construct($html) { + $this->html = $html; + $this->parse_html($html); + $this->set_min_lvl(); + } + + /** + * returns the table of contents as printable html. + */ + public function to_html() { + // No headings => no reason for a table of contents. + if (count($this->headings) < 1) { + return ""; + } + + $output = PHP_EOL . "

" . get_string('tableofcontents', 'ouwiki') . "

" . PHP_EOL; + $lastlvl = 0; + + foreach ($this->headings as $heading) { + + if ($lastlvl == 0) { + $output .= '
    '; + } else if ($heading->lvl > $lastlvl) { + $output .= '
      '; + } else { + $output .= str_repeat('
    ', $lastlvl - $heading->lvl); + $output .= ''; + } + $output .= '
  1. ' . $heading->name . ''; + + $lastlvl = $heading->lvl; + } + $output .= str_repeat('
' . PHP_EOL, $lastlvl); + return $output; + } + + /** + * Sets the minimum level of headings. + * + */ + private function set_min_lvl() { + $lvls = array(); + foreach ($this->headings as $heading) { + $lvls[] = $heading->lvl; + } + $min = empty($lvls) ? 0 : min($lvls); + foreach ($this->headings as $heading) { + $heading->lvl = $heading->lvl - $min + 1; + } + } + + /** + * Parses the html-Code and generates the table of contents. + * + * @param String $html The html-snippet to parse. + */ + private function parse_html($html) { + $dom = new DOMDocument(); + $dom->loadHTML('' . $html); + + // Get all Headings. + $xpath = new DOMXPath($dom); + $query = '//h1 | //h2 | //h3 | //h4 | //h5 | //h6 | //H1 | //H2 | //H3 | //H4 | //H5 | //H6'; + $headings = $xpath->query($query); + + if ($headings->length > 0) { + foreach ($headings as $heading) { + // Get Heading level:
=> 6. + $lvl = substr($heading->tagName, 1); + + $attributes = $heading->attributes; + $id = $attributes->getNamedItem('id')->value; + + $element = new stdClass(); + $element->name = $heading->nodeValue; + $element->id = $id; + // Set the lvl to 3 if lvl < 3, as all headings <= 3 are treated as section headings. + $element->lvl = $lvl < 3 ? 3 : $lvl; + $this->headings[] = $element; + } + } + } +} diff --git a/view.php b/view.php index 9334dad..4a8ede5 100644 --- a/view.php +++ b/view.php @@ -31,6 +31,7 @@ $url = new moodle_url('/mod/ouwiki/view.php', array('id' => $id, 'page' => $pagename)); $PAGE->set_url($url); $PAGE->set_cm($cm); +$PAGE->force_settings_menu(); $context = context_module::instance($cm->id); $PAGE->set_pagelayout('incourse'); @@ -51,6 +52,7 @@ // Check consistency in setting subwikis and group mode $courselink = new moodle_url('/course/view.php?id=', array('id' => $cm->course)); +/* if (($cm->groupmode == 0) && isset($subwiki->groupid)) { throw new moodle_exception("Sub-wikis is set to 'One wiki per group'. Please change Group mode to 'Separate groups' or 'Visible groups'.", 'error', $courselink); @@ -59,7 +61,7 @@ throw new moodle_exception("Sub-wikis is NOT set to 'One wiki per group'. Please change Group mode to 'No groups'.", 'error', $courselink); } - +*/ $locked = ($pageversion) ? $pageversion->locked : false; ouwiki_print_tabs('view', $pagename, $subwiki, $cm, $context, $pageversion ? true : false, $locked);