Ejemplo n.º 1
0
 /**
  * Print the main page content
  *
  * @param object $subwiki For details of user/group and ID so that
  *   we can make links
  * @param object $cm Course-module object (again for making links)
  * @param object $pageversion Data from page and version tables.
  * @param bool $gewgaws A decorator indicator.
  * @param string $page Page type
  * @param int $showwordcount
  * @param bool $hideannotations If true, adds extra class to hide annotations
  * @return string HTML content for page
  */
 public function ouwiki_print_page($subwiki, $cm, $pageversion, $gewgaws = null, $page = 'history', $showwordcount = 0, $hideannotations = false)
 {
     global $CFG, $ouwikiinternalre;
     require_once $CFG->libdir . '/filelib.php';
     $output = '';
     $modcontext = context_module::instance($cm->id);
     $title = $pageversion->title === '' ? get_string('startpage', 'ouwiki') : htmlspecialchars($pageversion->title);
     // Get annotations - only if using annotation system. Prevents unnecessary db access.
     if ($subwiki->annotation) {
         $annotations = ouwiki_get_annotations($pageversion);
     } else {
         $annotations = '';
     }
     // Setup annotations according to the page we are on.
     if ($page == 'view') {
         if ($subwiki->annotation && count($annotations)) {
             $pageversion->xhtml = ouwiki_highlight_existing_annotations($pageversion->xhtml, $annotations, 'view');
         }
     } else {
         if ($page == 'annotate') {
             $pageversion->xhtml = ouwiki_setup_annotation_markers($pageversion->xhtml);
             $pageversion->xhtml = ouwiki_highlight_existing_annotations($pageversion->xhtml, $annotations, 'annotate');
         }
     }
     // Must rewrite plugin urls AFTER doing annotations because they depend on byte position.
     $pageversion->xhtml = file_rewrite_pluginfile_urls($pageversion->xhtml, 'pluginfile.php', $modcontext->id, 'mod_ouwiki', 'content', $pageversion->versionid);
     $pageversion->xhtml = ouwiki_convert_content($pageversion->xhtml, $subwiki, $cm, null, $pageversion->xhtmlformat);
     // Get files here so we have them for the portfolio button addition as well.
     $fs = get_file_storage();
     $files = $fs->get_area_files($modcontext->id, 'mod_ouwiki', 'attachment', $pageversion->versionid, "timemodified", false);
     // Start gathering output.
     $output .= html_writer::start_tag('div', array('class' => 'ouwiki-content' . ($hideannotations ? ' ouwiki-hide-annotations' : '')));
     $output .= $this->get_topheading_section($title, $gewgaws, $pageversion, $annotations, $files);
     // List of recent changes.
     if ($gewgaws && $pageversion->recentversions) {
         $output .= html_writer::start_tag('div', array('class' => 'ouw_recentchanges'));
         $output .= get_string('recentchanges', 'ouwiki') . ': ';
         $output .= html_writer::start_tag('span', array('class' => 'ouw_recentchanges_list'));
         $first = true;
         foreach ($pageversion->recentversions as $recentversion) {
             if ($first) {
                 $first = false;
             } else {
                 $output .= '; ';
             }
             $output .= ouwiki_recent_span($recentversion->timecreated);
             $output .= ouwiki_nice_date($recentversion->timecreated);
             $output .= html_writer::end_tag('span');
             $output .= ' (';
             $recentversion->id = $recentversion->userid;
             // So it looks like a user object.
             $output .= ouwiki_display_user($recentversion, $cm->course, false);
             $output .= ')';
         }
         $output .= '; ';
         $pagestr = '';
         if (strtolower(trim($title)) !== strtolower(get_string('startpage', 'ouwiki'))) {
             $pagestr = '&page=' . $title;
         }
         $output .= html_writer::tag('a', get_string('seedetails', 'ouwiki'), array('href' => $CFG->wwwroot . '/mod/ouwiki/history.php?id=' . $cm->id . $pagestr));
         $output .= html_writer::end_tag('span');
         $output .= html_writer::end_tag('div');
     }
     $output .= $this->get_new_annotations_section($gewgaws, $pageversion, $annotations, $files);
     $output .= html_writer::end_tag('div');
     // Main content of page.
     $output .= html_writer::start_tag('div', array('class' => 'ouw_belowmainhead'));
     $output .= html_writer::start_tag('div', array('class' => 'ouw_topspacer'));
     $output .= html_writer::end_tag('div');
     $output .= $pageversion->xhtml;
     if ($gewgaws) {
         // Add in links around headings.
         $ouwikiinternalre = new stdClass();
         $ouwikiinternalre->pagename = $pageversion->title;
         $ouwikiinternalre->subwiki = $subwiki;
         $ouwikiinternalre->cm = $cm;
         $ouwikiinternalre->annotations = $annotations;
         $ouwikiinternalre->locked = $pageversion->locked;
         $ouwikiinternalre->pageversion = $pageversion;
         $ouwikiinternalre->files = $files;
         $output = preg_replace_callback('|<h([1-9]) id="ouw_s([0-9]+_[0-9]+)">(.*?)(<br\\s*/>)?</h[1-9]>|s', 'ouwiki_internal_re_heading', $output);
     }
     $output .= html_writer::tag('div', '', array('class' => 'clearer'));
     $output .= html_writer::end_tag('div');
     // End of ouw_belowmainhead.
     // Add wordcount.
     if ($showwordcount) {
         $output .= $this->ouwiki_render_wordcount($pageversion->wordcount);
     }
     $output .= html_writer::end_tag('div');
     // End of ouwiki-content.
     // Add attached files.
     $output .= $this->get_attached_files($files, $modcontext, $pageversion);
     // Pages that link to this page.
     if ($gewgaws) {
         $links = ouwiki_get_links_to($pageversion->pageid);
         if (count($links) > 0) {
             $output .= $this->get_links_to($links);
         }
     }
     // Display the orphaned annotations.
     if ($subwiki->annotation && $annotations && $page != 'history') {
         $orphaned = '';
         foreach ($annotations as $annotation) {
             if ($annotation->orphaned) {
                 $orphaned .= $this->ouwiki_print_hidden_annotation($annotation);
             }
         }
         if ($orphaned !== '') {
             $output .= html_writer::start_div('ouw-orphaned-annotations');
             $output .= html_writer::tag('h3', get_string('orphanedannotations', 'ouwiki'));
             $output .= $orphaned;
             $output .= html_writer::end_div();
         } else {
             $output = $output;
         }
     }
     $output .= $this->get_new_buttons_section($gewgaws, $pageversion);
     return array($output, $annotations);
 }
Ejemplo n.º 2
0
 /**
  * Print the main page content
  *
  * @param object $subwiki For details of user/group and ID so that
  *   we can make links
  * @param object $cm Course-module object (again for making links)
  * @param object $pageversion Data from page and version tables.
  * @param bool $hideannotations If true, adds extra class to hide annotations
  * @return string HTML content for page
  */
 public function ouwiki_print_page($subwiki, $cm, $pageversion, $gewgaws = null, $page = 'history', $showwordcount = 0, $hideannotations = false)
 {
     $output = '';
     $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
     global $CFG, $ouwikiinternalre;
     require_once $CFG->libdir . '/filelib.php';
     // Get annotations - only if using annotation system. prevents unnecessary db access
     if ($subwiki->annotation) {
         $annotations = ouwiki_get_annotations($pageversion);
     } else {
         $annotations = '';
     }
     // Title
     $title = $pageversion->title === '' ? get_string('startpage', 'ouwiki') : htmlspecialchars($pageversion->title);
     // setup annotations according to the page we are on
     if ($page == 'view') {
         // create the annotations
         if ($subwiki->annotation && count($annotations)) {
             ouwiki_highlight_existing_annotations(&$pageversion->xhtml, $annotations, 'view');
         }
     } else {
         if ($page == 'annotate') {
             // call function for the annotate page
             ouwiki_setup_annotation_markers(&$pageversion->xhtml);
             ouwiki_highlight_existing_annotations(&$pageversion->xhtml, $annotations, 'annotate');
         }
     }
     // Must rewrite plugin urls AFTER doing annotations because they depend on byte
     // position in unmolested data from db
     $pageversion->xhtml = file_rewrite_pluginfile_urls($pageversion->xhtml, 'pluginfile.php', $modcontext->id, 'mod_ouwiki', 'content', $pageversion->versionid);
     // get files up here so we have them for the portfolio button addition as well
     $fs = get_file_storage();
     $files = $fs->get_area_files($modcontext->id, 'mod_ouwiki', 'attachment', $pageversion->versionid, "timemodified", false);
     $output .= html_writer::start_tag('div', array('class' => 'ouwiki-content' . ($hideannotations ? ' ouwiki-hide-annotations' : '')));
     $output .= html_writer::start_tag('div', array('class' => 'ouw_topheading'));
     $output .= html_writer::start_tag('div', array('class' => 'ouw_heading'));
     $output .= html_writer::tag('h1', format_string($title), array('class' => 'ouw_topheading'));
     if ($gewgaws) {
         $output .= $this->render_heading_bit(1, $pageversion->title, $subwiki, $cm, null, $annotations, $pageversion->locked, $files, $pageversion->pageid);
     } else {
         $output .= html_writer::end_tag('div');
     }
     // List of recent changes
     if ($gewgaws && $pageversion->recentversions) {
         $output .= html_writer::start_tag('div', array('class' => 'ouw_recentchanges'));
         $output .= get_string('recentchanges', 'ouwiki') . ': ';
         $output .= html_writer::start_tag('span', array('class' => 'ouw_recentchanges_list'));
         $first = true;
         foreach ($pageversion->recentversions as $recentversion) {
             if ($first) {
                 $first = false;
             } else {
                 $output .= '; ';
             }
             $output .= ouwiki_recent_span($recentversion->timecreated);
             $output .= ouwiki_nice_date($recentversion->timecreated);
             $output .= html_writer::end_tag('span');
             $output .= ' (';
             $recentversion->id = $recentversion->userid;
             // so it looks like a user object
             $output .= ouwiki_display_user($recentversion, $cm->course, false);
             $output .= ')';
         }
         $output .= '; ';
         $pagestr = '';
         if (strtolower(trim($title)) !== strtolower(get_string('startpage', 'ouwiki'))) {
             $pagestr = '&page=' . $title;
         }
         $output .= html_writer::tag('a', get_string('seedetails', 'ouwiki'), array('href' => $CFG->wwwroot . '/mod/ouwiki/history.php?id=' . $cm->id . $pagestr));
         $output .= html_writer::end_tag('span');
         $output .= html_writer::end_tag('div');
     }
     $output .= html_writer::end_tag('div');
     $output .= html_writer::start_tag('div', array('class' => 'ouw_belowmainhead'));
     // spacer
     $output .= html_writer::start_tag('div', array('class' => 'ouw_topspacer'));
     $output .= html_writer::end_tag('div');
     // Content of page
     $output .= ouwiki_convert_content($pageversion->xhtml, $subwiki, $cm, null, $pageversion->xhtmlformat);
     if ($gewgaws) {
         // Add in links/etc. around headings
         $ouwikiinternalre->pagename = $pageversion->title;
         $ouwikiinternalre->subwiki = $subwiki;
         $ouwikiinternalre->cm = $cm;
         $ouwikiinternalre->annotations = $annotations;
         $ouwikiinternalre->locked = $pageversion->locked;
         $ouwikiinternalre->pageversion = $pageversion;
         $ouwikiinternalre->files = $files;
         $output = preg_replace_callback('|<h([1-9]) id="ouw_s([0-9]+_[0-9]+)">(.*?)(<br\\s*/>)?</h[1-9]>|s', 'ouwiki_internal_re_heading', $output);
     }
     $output .= html_writer::start_tag('div', array('class' => 'clearer'));
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('div');
     // Render wordcount
     if ($showwordcount) {
         $output .= $this->ouwiki_render_wordcount($pageversion->wordcount);
     }
     $output .= html_writer::end_tag('div');
     // attached files
     if ($files) {
         $output .= html_writer::start_tag('div', array('class' => 'ouwiki-post-attachments'));
         $output .= html_writer::tag('h3', get_string('attachments', 'ouwiki'), array('class' => 'ouw_topheading'));
         $output .= html_writer::start_tag('ul');
         foreach ($files as $file) {
             $output .= html_writer::start_tag('li');
             $filename = $file->get_filename();
             $mimetype = $file->get_mimetype();
             $iconimage = html_writer::empty_tag('img', array('src' => $this->output->pix_url(file_mimetype_icon($mimetype)), 'alt' => $mimetype, 'class' => 'icon'));
             $path = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $modcontext->id . '/mod_ouwiki/attachment/' . $pageversion->versionid . '/' . $filename);
             $output .= html_writer::tag('a', $iconimage, array('href' => $path));
             $output .= html_writer::tag('a', s($filename), array('href' => $path));
             $output .= html_writer::end_tag('li');
         }
         $output .= html_writer::end_tag('ul');
         $output .= html_writer::end_tag('div');
     }
     // pages that link to this page
     if ($gewgaws) {
         $links = ouwiki_get_links_to($pageversion->pageid);
         if (count($links) > 0) {
             $output .= html_writer::start_tag('div', array('class' => 'ouw_linkedfrom'));
             $output .= html_writer::tag('h3', get_string(count($links) == 1 ? 'linkedfromsingle' : 'linkedfrom', 'ouwiki'), array('class' => 'ouw_topheading'));
             $output .= html_writer::start_tag('ul');
             $first = true;
             foreach ($links as $link) {
                 $output .= html_writer::start_tag('li');
                 if ($first) {
                     $first = false;
                 } else {
                     $output .= '&#8226; ';
                 }
                 $linktitle = $link->title ? htmlspecialchars($link->title) : get_string('startpage', 'ouwiki');
                 $output .= html_writer::tag('a', $linktitle, array('href' => $CFG->wwwroot . '/mod/ouwiki/view.php?' . ouwiki_display_wiki_parameters($link->title, $subwiki, $cm, OUWIKI_PARAMS_URL)));
                 $output .= html_writer::end_tag('li');
             }
             $output .= html_writer::end_tag('ul');
             $output .= html_writer::end_tag('div');
         }
     }
     // disply the orphaned annotations
     if ($subwiki->annotation && $annotations && $page != 'history') {
         $orphaned = '';
         foreach ($annotations as $annotation) {
             if ($annotation->orphaned) {
                 $orphaned .= $this->ouwiki_print_hidden_annotation($annotation);
             }
         }
         if ($orphaned !== '') {
             $output .= html_writer::tag('h3', get_string('orphanedannotations', 'ouwiki'));
             $output .= $orphaned;
         } else {
             $output = $output;
         }
     }
     return array($output, $annotations);
 }
/**
 * @param object $subwiki For details of user/group and ID so that
 *   we can make links
 * @param object $cm Course-module object (again for making links)
 * @param object $pageversion Data from page and version tables.
 * @return string HTML content for page
 */
function ouwiki_display_page($subwiki, $cm, $pageversion, $gewgaws = false, $page = 'history')
{
    global $CFG;
    // Get comments - only if using per-section comment system. prevents unnecessary db access
    $comments = array();
    if (ouwiki_get_commenting($subwiki->commenting) == OUWIKI_COMMENTS_PERSECTION || ouwiki_get_commenting($subwiki->commenting) == OUWIKI_COMMENTS_BOTH) {
        if ($gewgaws) {
            $comments = ouwiki_get_recent_comments($pageversion->pageid, ouwiki_find_sections($pageversion->xhtml));
        }
    }
    // And params
    $params = ouwiki_display_wiki_parameters($pageversion->title, $subwiki, $cm);
    // Get annotations - only if using annotation comment system. prevents unnecessary db access
    if (ouwiki_get_commenting($subwiki->commenting) == OUWIKI_COMMENTS_ANNOTATION || ouwiki_get_commenting($subwiki->commenting) == OUWIKI_COMMENTS_BOTH) {
        $annotations = ouwiki_get_annotations($pageversion);
    } else {
        $annotations = '';
    }
    // Title
    $title = is_null($pageversion->title) ? get_string('startpage', 'ouwiki') : htmlspecialchars($pageversion->title);
    // setup annotations according to the page we are on
    if ($page == 'view') {
        // create the annotations
        if ((ouwiki_get_commenting($subwiki->commenting) == OUWIKI_COMMENTS_ANNOTATION || ouwiki_get_commenting($subwiki->commenting) == OUWIKI_COMMENTS_BOTH) && count($annotations)) {
            ouwiki_highlight_existing_annotations(&$pageversion->xhtml, $annotations, 'view');
        }
    } elseif ($page == 'annotate') {
        // call function for the annotate page
        ouwiki_setup_annotation_markers(&$pageversion->xhtml);
        ouwiki_highlight_existing_annotations(&$pageversion->xhtml, $annotations, 'annotate');
    }
    $result = '';
    $result .= '<div class="ouwiki_content"><div class="ouw_topheading">';
    $returncomments = true;
    $result .= '<div class="ouw_heading"><h1 id="ouw_topheading">' . $title . '</h1>' . ($gewgaws ? ouwiki_internal_display_heading_bit(1, $pageversion->title, $subwiki, $cm, $comments, null, $annotations, $pageversion->locked, $returncomments) : '</div>');
    // List of recent changes
    if ($gewgaws && $pageversion->recentversions) {
        $result .= '<div class="ouw_recentchanges">' . get_string('recentchanges', 'ouwiki') . ': <span class="ouw_recentchanges_list">';
        $first = true;
        foreach ($pageversion->recentversions as $recentversion) {
            if ($first) {
                $first = false;
            } else {
                $result .= '; ';
            }
            $result .= ouwiki_recent_span($recentversion->timecreated);
            $result .= ouwiki_nice_date($recentversion->timecreated) . '</span> (';
            $recentversion->id = $recentversion->userid;
            // so it looks like a user object
            $result .= ouwiki_display_user($recentversion, $cm->course, false) . ')';
        }
        if (class_exists('ouflags') && ou_get_is_mobile()) {
            $result .= '; </span></div>';
        } else {
            $result .= '; <br/><a class="seedetails" href="history.php?' . $params . '">' . get_string('seedetails', 'ouwiki') . '</a></span></div>';
        }
    }
    $result .= '</div><div class="ouw_belowmainhead">';
    if ($returncomments !== true) {
        $result .= $returncomments;
    }
    $result .= '<div class="ouw_topspacer"></div>';
    // Content of page
    $result .= ouwiki_convert_content($pageversion->xhtml, $subwiki, $cm);
    if ($gewgaws) {
        // Add in links/etc. around headings
        global $ouwiki_internal_re;
        $ouwiki_internal_re->comments = $comments;
        $ouwiki_internal_re->pagename = $pageversion->title;
        $ouwiki_internal_re->subwiki = $subwiki;
        $ouwiki_internal_re->cm = $cm;
        $ouwiki_internal_re->annotations = $annotations;
        $ouwiki_internal_re->locked = $pageversion->locked;
        $result = preg_replace_callback('|<h([1-9]) id="ouw_s([0-9]+_[0-9]+)">(.*?)(<br\\s*/>)?</h[1-9]>|s', 'ouwiki_internal_re_heading_bits', $result);
    }
    $result .= '<div class="clearer"></div></div></div>';
    if ($gewgaws) {
        $links = ouwiki_get_links_to($pageversion->pageid);
        if (count($links) > 0) {
            $result .= '<div class="ouw_linkedfrom"><h3>' . get_string(count($links) == 1 ? 'linkedfromsingle' : 'linkedfrom', 'ouwiki') . '</h3><ul>';
            $first = true;
            foreach ($links as $link) {
                $result .= ' <li>';
                if ($first) {
                    $first = false;
                } else {
                    $result .= '&#8226; ';
                }
                $result .= '<a href="view.php?' . ouwiki_display_wiki_parameters($link->title, $subwiki, $cm) . '">' . ($link->title ? htmlspecialchars($link->title) : get_string('startpage', 'ouwiki')) . '</a></li>';
            }
            $result .= '</ul></div>';
        }
        if ($subwiki->cancomment && (ouwiki_get_commenting($subwiki->commenting) == OUWIKI_COMMENTS_PERSECTION || ouwiki_get_commenting($subwiki->commenting) == OUWIKI_COMMENTS_BOTH)) {
            $result .= '<div id="ouw_ac_formcontainer" style="display:none">' . ouwiki_display_comment_form('view', null, null, $pageversion->title, $subwiki, $cm) . '</div>';
        }
    }
    // disply the orphaned annotations
    if ((ouwiki_get_commenting($subwiki->commenting) == OUWIKI_COMMENTS_ANNOTATION || ouwiki_get_commenting($subwiki->commenting) == OUWIKI_COMMENTS_BOTH) && $annotations && $page != 'history') {
        $orphaned = '';
        foreach ($annotations as $annotation) {
            if ($annotation->orphaned) {
                $orphaned .= ouwiki_setup_hidden_annotation($annotation);
            }
        }
        $result = $orphaned !== '' ? $result . '<h3>' . get_string('orphanedannotations', 'ouwiki') . '</h3>' . $orphaned : $result;
    }
    return array($result, $annotations);
}