function ouwiki_display_page_in_index($indexitem, $subwiki, $cm)
{
    if ($startpage = is_null($indexitem->title)) {
        $title = get_string('startpage', 'ouwiki');
        $output = '<div class="ouw_index_startpage">';
    } else {
        $title = $indexitem->title;
        $output = '';
    }
    $output .= '<a class="ouw_title" href="view.php?' . ouwiki_display_wiki_parameters($indexitem->title, $subwiki, $cm) . '">' . htmlspecialchars($title) . '</a>';
    $lastchange = new StdClass();
    $lastchange->userlink = ouwiki_display_user($indexitem, $cm->course);
    $lastchange->date = ouwiki_recent_span($indexitem->timecreated) . ouwiki_nice_date($indexitem->timecreated) . '</span>';
    $output .= '<div class="ouw_indexinfo">';
    $output .= ' <span class="ouw_lastchange">' . get_string('lastchange', 'ouwiki', $lastchange) . '</span>';
    $output .= '</div>';
    if ($startpage) {
        $output .= '</div>';
    }
    return $output;
}
示例#2
0
        $advice = get_string('diff_someannotations', 'ouwiki');
    }
} else {
    $advice = get_string('advice_diff', 'ouwiki');
}
print '<p class="ouw_advice">' . $advice . ' ' . get_string('returntohistory', 'ouwiki', 'history.php?' . ouwiki_display_wiki_parameters($pagename, $subwiki, $cm)) . '</p>';
// Obtain pluginfile urls.
$pageversion1->xhtml = file_rewrite_pluginfile_urls($pageversion1->xhtml, 'pluginfile.php', $context->id, 'mod_ouwiki', 'content', $pageversion1->versionid);
$pageversion2->xhtml = file_rewrite_pluginfile_urls($pageversion2->xhtml, 'pluginfile.php', $context->id, 'mod_ouwiki', 'content', $pageversion2->versionid);
// Obtain difference between two versions
list($diff1, $diff2) = ouwiki_diff_html($pageversion1->xhtml, $pageversion2->xhtml);
// To make it look like a user object
$pageversion1->id = $pageversion1->userid;
$v1name = ouwiki_display_user($pageversion1, $course->id);
$pageversion2->id = $pageversion2->userid;
$v2name = ouwiki_display_user($pageversion2, $course->id);
// Disply the two versions
$v1 = new StdClass();
$v1->version = get_string('olderversion', 'ouwiki');
$v1->date = userdate($pageversion1->timecreated);
$v1->savedby = get_string('savedby', 'ouwiki', $v1name);
$v1->content = $diff1;
$v1->attachments = $attachdiff1;
$v2 = new StdClass();
$v2->version = get_string('olderversion', 'ouwiki');
$v2->date = userdate($pageversion2->timecreated);
$v2->savedby = get_string('savedby', 'ouwiki', $v2name);
$v2->content = $diff2;
$v2->attachments = $attachdiff2;
echo $ouwikioutput->ouwiki_print_diff($v1, $v2);
// Footer
     $changelink = " <small>(<a href='diff.php?{$pageparams}&amp;v2={$change->versionid}&amp;v1={$change->previousversionid}'>{$strchanges}</a>)</small>";
 } else {
     $changelink = ' <small>(' . get_string('newpage', 'ouwiki') . ')</small>';
 }
 $current = '';
 if ($change->versionid == $change->currentversionid || $newpages) {
     $viewlink = "view.php?{$pageparams}";
     if (!$newpages && !empty($CFG->ouwikienablecurrentpagehighlight)) {
         $current = ' class="current"';
     }
 } else {
     $viewlink = "viewold.php?{$pageparams}&amp;version={$change->versionid}";
 }
 $change->id = $change->userid;
 if ($change->id) {
     $userlink = ouwiki_display_user($change, $course->id);
 } else {
     $userlink = '';
 }
 if ($newpages) {
     $actions = '';
     $page = "<a href='{$viewlink}'>{$page}</a>";
 } else {
     $actions = "<td class='actions'><a href='{$viewlink}'>{$strview}</a>{$changelink}</td>";
 }
 // see bug #3611
 if (!empty($current) && !empty($CFG->ouwikienablecurrentpagehighlight)) {
     // current page so add accessibility stuff
     $accessiblityhide = '<span class="accesshide">' . get_string('currentversionof', 'ouwiki') . '</span>';
     $dummy = $page;
     $page = $accessiblityhide . $dummy;
示例#4
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);
 }
示例#5
0
/**
 * Prints the subwiki selector if user has access to more than one subwiki.
 * Also displays the currently-viewing subwiki.
 *
 * @param object $subwiki Current subwiki object
 * @param object $ouwiki Wiki object
 * @param object $cm Course-module object
 * @param object $context Context for permissions
 * @param object $course Course object
 */
function ouwiki_display_subwiki_selector($subwiki, $ouwiki, $cm, $context, $course, $actionurl = 'view.php')
{
    global $USER, $DB;
    if ($ouwiki->subwikis == OUWIKI_SUBWIKIS_SINGLE) {
        return '';
    }
    $choicefield = '';
    switch ($ouwiki->subwikis) {
        case OUWIKI_SUBWIKIS_GROUPS:
            $groups = groups_get_activity_allowed_groups($cm);
            uasort($groups, create_function('$a,$b', 'return strcasecmp($a->name,$b->name);'));
            $wikifor = htmlspecialchars($groups[$subwiki->groupid]->name);
            // Do they have more than one?
            if (count($groups) > 1) {
                $choicefield = 'group';
                $choices = $groups;
            }
            break;
        case OUWIKI_SUBWIKIS_INDIVIDUAL:
            $user = $DB->get_record('user', array('id' => $subwiki->userid), 'id, firstname, lastname, username');
            $wikifor = ouwiki_display_user($user, $cm->course);
            if (has_capability('mod/ouwiki:viewallindividuals', $context)) {
                // Get list of everybody...
                $choicefield = 'user';
                try {
                    $choices = $DB->get_records_sql('SELECT u.id, u.firstname, u.lastname
                            FROM {ouwiki_subwikis} sw
                            INNER JOIN {user} u ON sw.userid = u.id
                            WHERE sw.wikiid = ?
                            ORDER BY u.lastname, u.firstname', array($ouwiki->id));
                } catch (Exception $e) {
                    ouwiki_dberror($e);
                }
                foreach ($choices as $choice) {
                    $choice->name = fullname($choice);
                }
            } else {
                if (has_capability('mod/ouwiki:viewgroupindividuals', $context)) {
                    $choicefield = 'user';
                    $choices = array();
                    // User allowed to view people in same group
                    $theirgroups = groups_get_all_groups($cm->course, $USER->id, $course->defaultgroupingid);
                    if (!$theirgroups) {
                        $theirgroups = array();
                    }
                    foreach ($theirgroups as $group) {
                        $members = groups_get_members($group->id, 'u.id, u.firstname, u.lastname');
                        foreach ($members as $member) {
                            $member->name = fullname($member);
                            $choices[$member->id] = $member;
                        }
                    }
                } else {
                    // Nope, only yours
                }
            }
            break;
        default:
            ouwiki_error("Unexpected subwikis value: {$ouwiki->subwikis}");
    }
    $out = '<div class="ouw_subwiki"><label for="wikiselect">' . get_string('wikifor', 'ouwiki') . '</label>';
    if ($choicefield && count($choices) > 1) {
        $selectedid = $choicefield == 'user' ? $subwiki->userid : $subwiki->groupid;
        $out .= '<form method="get" action="' . $actionurl . '" class="ouwiki_otherwikis">
            <div><input type="hidden" name="id" value="' . $cm->id . '"/>
            <select name="' . $choicefield . '" id="wikiselect">';
        foreach ($choices as $choice) {
            $selected = $choice->id == $selectedid ? ' selected="selected"' : '';
            $out .= '<option value="' . $choice->id . '"' . $selected . '>' . htmlspecialchars($choice->name) . '</option>';
        }
        $out .= '</select> <input type="submit" value="' . get_string('changebutton', 'ouwiki') . '" /></div></form>';
    } else {
        $out .= $wikifor;
    }
    $out .= '</div>';
    return $out;
}
示例#6
0
$content = null;
$formdata = null;
if ($formdata = $mform->get_data()) {
    if ($content = $formdata->content['text']) {
        // Check if they used the plaintext editor, if so fixup linefeeds
        if (isset($formdata->content['format']) && $formdata->content['format'] != FORMAT_HTML) {
            $content = ouwiki_plain_to_xhtml($content);
        }
        $content = ouwiki_format_xhtml_a_bit($content);
        // Tidy up HTML
    }
}
// new content for section
if ($newsection) {
    $new = new StdClass();
    $new->name = ouwiki_display_user($USER, $course->id);
    $new->date = userdate(time());
    $sectionheader = html_writer::tag('h3', s($newsection)) . html_writer::tag('p', '(' . get_string('createdbyon', 'ouwiki', $new) . ')');
}
// if cancel redirect before going too far
if ($cancel) {
    // Get pageid to unlock.
    $pageversion = ouwiki_get_current_page($subwiki, $pagename);
    if (!empty($pageversion->pageid)) {
        ouwiki_release_lock($pageversion->pageid);
    }
    redirect($returnurl);
    exit;
}
// Get the current page version, creating page if needed
$pageversion = ouwiki_get_current_page($subwiki, $pagename, OUWIKI_GETPAGE_CREATE);
 /**
  * Obtains page html suitable for use in portfolio export.
  * @param object $pageversion Page and version data
  * @param array $attachments Attachments array indexed by versionid
  * @param object $context Moodle context object
  * @param object $ouwiki OU wiki object
  * @param object $subwiki Subwiki object
  * @param object $course Course object
  * @param bool $withannotations If true, includes annotations
  * @param portfolio_format $portfolioformat Portfolio format
  * @param string $plugin the portfolio plugin being used.
  * @return string HTML code
  */
 static function get_page_html($pageversion, $attachments, $context, $ouwiki, $subwiki, $course, $withannotations, portfolio_format $portfolioformat, $plugin)
 {
     global $DB;
     // Format the page body
     $options = portfolio_format_text_options();
     $formattedtext = format_text($pageversion->xhtml, $pageversion->xhtmlformat, $options, $course->id);
     $formattedtext = portfolio_rewrite_pluginfile_urls($formattedtext, $context->id, 'mod_ouwiki', 'content', $pageversion->versionid, $portfolioformat);
     // Get annotations - only if using annotation system. prevents unnecessary db access
     if ($ouwiki->annotation) {
         $annotations = ouwiki_get_annotations($pageversion);
     } else {
         $annotations = array();
     }
     // Convert or remove the annotations
     if ($ouwiki->annotation && count($annotations)) {
         ouwiki_highlight_existing_annotations($formattedtext, $annotations, $withannotations ? 'portfolio' : 'clear');
     }
     // Do overall page, starting with title
     $title = $pageversion->title;
     if ($title === null) {
         $title = get_string('startpage', 'ouwiki');
     }
     $output = html_writer::tag('h2', s($title));
     // Last change info
     $user = (object) array('id' => $pageversion->userid, 'firstname' => $pageversion->firstname, 'lastname' => $pageversion->lastname);
     $lastchange = get_string('lastchange', 'ouwiki', (object) array('date' => userdate($pageversion->timecreated), 'userlink' => ouwiki_display_user($user, $course->id)));
     $output .= html_writer::tag('p', html_writer::tag('small', html_writer::tag('i', $lastchange)));
     // Main text
     $output .= html_writer::tag('div', $formattedtext);
     // Word count
     if ($ouwiki->enablewordcount) {
         $wordcount = get_string('numwords', 'ouwiki', $pageversion->wordcount);
         $output .= html_writer::tag('div', html_writer::empty_tag('br'));
         $output .= html_writer::tag('p', html_writer::tag('small', $wordcount), array('class' => 'ouw_wordcount'));
     }
     // Attachments
     if ($attachments[$pageversion->versionid]) {
         $output .= html_writer::start_tag('div', array('class' => 'attachments'));
         $output .= html_writer::tag('h3', get_string('attachments', 'ouwiki'));
         $output .= html_writer::start_tag('ul');
         foreach ($attachments[$pageversion->versionid] as $file) {
             if ($plugin == 'rtf') {
                 $filename = $file->get_filename();
                 $path = moodle_url::make_pluginfile_url($context->id, 'mod_ouwiki', 'attachment', $pageversion->versionid, '/', $filename, true);
                 $atag = html_writer::tag('a', $filename, array('href' => $path));
             } else {
                 $atag = $portfolioformat->file_output($file);
             }
             $output .= html_writer::tag('li', $atag);
         }
         $output .= html_writer::end_tag('ul');
         $output .= html_writer::end_tag('div');
     }
     return $output;
 }
 /**
  * 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);
 }
/**
 * Displays an array of comments in the order of the array.
 * @param array $comments Array of comment objects
 * @param string $fromphp Page name i.e. 'view' or 'comments'
 * @param string $section Comment section (null for main page)
 * @param string $page Name of page (null for startpage)
 * @param object $subwiki Current subwiki object
 * @param object $cm Course-module object
 * @param bool $candelete If true, user gets delete option for everything not just
 *   their own comments, also gets undelete
 * @return string XHTML for output
 */
function ouwiki_display_comments($comments, $section, $page, $subwiki, $cm, $showdelete = false, $candelete = false)
{
    global $USER;
    $out = '<ul class="ouw_comments">';
    $first = true;
    $strcommenter = get_string('access_commenter', 'ouwiki') . ': ';
    $strdate = get_string('date') . ': ';
    foreach ($comments as $comment) {
        $out .= '<li class="ouw_comment' . ($comment->deleted ? ' ouw_deletedcomment' : '') . ($first ? ' ouw_firstcomment' : '') . '">';
        $first = false;
        $user = new StdClass();
        $user->id = $comment->userid;
        $user->firstname = $comment->firstname;
        $user->lastname = $comment->lastname;
        $out .= '<div class="ouw_commentposter"><span class="accesshide">' . $strcommenter . '</span>' . ouwiki_display_user($user, $cm->course) . '</div>';
        $out .= '<div class="ouw_commentdate"><span class="accesshide">' . $strdate . '</span>' . ouwiki_nice_date($comment->timeposted, false, true) . '</div>';
        if ($comment->section != $section) {
            $out .= '<div class="ouw_commentsection">' . get_string('commentoriginalsection', 'ouwiki', $comment->sectiontitle) . '</div>';
        }
        if ($comment->title !== null) {
            $out .= '<h3 class="ouw_commenttitle">' . htmlspecialchars($comment->title) . '</h3>';
        }
        $out .= '<div class="ouw_commentxhtml">';
        $out .= format_text($comment->xhtml);
        $out .= '</div>';
        if ($showdelete && ($candelete || $USER->id == $comment->userid)) {
            $out .= '<form class="ouw_commentsubmit" action="deletecomment.php" method="post">';
            $out .= ouwiki_display_wiki_parameters($page, $subwiki, $cm, OUWIKI_PARAMS_FORM);
            $out .= '<input type="hidden" name="section" value="' . $section . '" />';
            $out .= '<input type="hidden" name="comment" value="' . $comment->id . '" />';
            $out .= '<input type="hidden" name="delete" value="' . ($comment->deleted ? 0 : 1) . '" />';
            $out .= '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
            $out .= '<input type="submit" value="' . get_string($comment->deleted ? 'commentundelete' : 'commentdelete', 'ouwiki') . '" />';
            $out .= '</form>';
        }
        $out .= '</li>';
    }
    $out .= '</ul>';
    return $out;
}
示例#10
0
 /**
  * Obtains page html suitable for use in portfolio export.
  * @param object $pageversion Page and version data
  * @param array $attachments Attachments array indexed by versionid
  * @param object $context Moodle context object
  * @param object $ouwiki OU wiki object
  * @param object $subwiki Subwiki object
  * @param object $course Course object
  * @param bool $withannotations If true, includes annotations
  * @param portfolio_format $portfolioformat Portfolio format
  * @param string $plugin the portfolio plugin being used.
  * @return string HTML code
  */
 public static function get_page_html($pageversion, $attachments, $context, $ouwiki, $subwiki, $course, $withannotations, portfolio_format $portfolioformat, $plugin)
 {
     global $DB;
     // Format the page body.
     $options = portfolio_format_text_options();
     $options->filter = true;
     $formattedtext = portfolio_rewrite_pluginfile_urls($pageversion->xhtml, $context->id, 'mod_ouwiki', 'content', $pageversion->versionid, $portfolioformat);
     $formattedtext = format_text($formattedtext, $pageversion->xhtmlformat, $options, $course->id);
     // Get annotations - only if using annotation system. prevents unnecessary db access.
     if ($ouwiki->annotation) {
         $annotations = ouwiki_get_annotations($pageversion);
     } else {
         $annotations = array();
     }
     // Convert or remove the annotations.
     if ($ouwiki->annotation && count($annotations)) {
         ouwiki_highlight_existing_annotations($formattedtext, $annotations, $withannotations ? 'portfolio' : 'clear');
     }
     // Do overall page, starting with title.
     $title = $pageversion->title;
     if ($title === '') {
         $title = get_string('startpage', 'ouwiki');
     }
     $output = html_writer::tag('h2', s($title));
     // Last change info.
     $user = new stdClass();
     foreach (explode(',', user_picture::fields()) as $field) {
         if ($field == 'id') {
             $user->id = $pageversion->userid;
         } else {
             $user->{$field} = $pageversion->{$field};
         }
     }
     $lastchange = get_string('lastchange', 'ouwiki', (object) array('date' => userdate($pageversion->timecreated), 'userlink' => ouwiki_display_user($user, $course->id)));
     $output .= html_writer::tag('p', html_writer::tag('small', html_writer::tag('i', $lastchange)));
     // Main text.
     $output .= html_writer::tag('div', $formattedtext);
     // Word count.
     if ($ouwiki->enablewordcount) {
         $wordcount = get_string('numwords', 'ouwiki', $pageversion->wordcount);
         $output .= html_writer::tag('div', html_writer::empty_tag('br'));
         $output .= html_writer::tag('p', html_writer::tag('small', $wordcount), array('class' => 'ouw_wordcount'));
     }
     // Attachments.
     if ($attachments[$pageversion->versionid]) {
         $output .= html_writer::start_tag('div', array('class' => 'attachments'));
         $output .= html_writer::tag('h3', get_string('attachments', 'ouwiki'));
         $output .= html_writer::start_tag('ul');
         foreach ($attachments[$pageversion->versionid] as $file) {
             if ($plugin == 'rtf') {
                 $filename = $file->get_filename();
                 $path = moodle_url::make_pluginfile_url($context->id, 'mod_ouwiki', 'attachment', $pageversion->versionid, '/', $filename, true);
                 $atag = html_writer::tag('a', $filename, array('href' => $path));
             } else {
                 $atag = $portfolioformat->file_output($file);
             }
             $output .= html_writer::tag('li', $atag);
         }
         $output .= html_writer::end_tag('ul');
         $output .= html_writer::end_tag('div');
     }
     // Replace all user links with user name so that you can not access user links from within exported document.
     $output = preg_replace('~<a href="[^"]*/user/view.php[^"]*"\\s*>(.*?)</a>~', '$1', $output);
     return $output;
 }