[marginalia] r539 committed - Update to match Marginalia M 2.0 beta 3 for Moodle 2.0

1 view
Skip to first unread message

margi...@googlecode.com

unread,
May 30, 2012, 6:12:44 PM5/30/12
to marginali...@googlegroups.com
Revision: 539
Author: geof.glass
Date: Wed May 30 15:12:10 2012
Log: Update to match Marginalia M 2.0 beta 3 for Moodle 2.0

http://code.google.com/p/marginalia/source/detail?r=539

Added:
/moodle/trunk/moodle/blocks/marginalia/db/access.php
/moodle/trunk/moodle/blocks/marginalia/help.css
/moodle/trunk/moodle/blocks/marginalia/help.php
/moodle/trunk/moodle/blocks/marginalia/lang/en
/moodle/trunk/moodle/blocks/marginalia/lang/en/block_marginalia.php
/moodle/trunk/moodle/blocks/marginalia/lang/en/help
/moodle/trunk/moodle/blocks/marginalia/lang/en/help/annotate.html
/moodle/trunk/moodle/blocks/marginalia/lang/en/help/annotation_summary.html
/moodle/trunk/moodle/blocks/marginalia/moodle_marginalia.php
Deleted:
/moodle/trunk/moodle/admin
/moodle/trunk/moodle/blocks/marginalia/annotation_globals.php
/moodle/trunk/moodle/blocks/marginalia/lang/en_utf8
/moodle/trunk/moodle/blocks/marginalia/marginalia-strings.js
/moodle/trunk/moodle/blocks/marginalia/tags.css
/moodle/trunk/moodle/blocks/marginalia/tags.js
/moodle/trunk/moodle/blocks/marginalia/tags.php
/moodle/trunk/moodle/help.php
/moodle/trunk/moodle/lib
/moodle/trunk/moodle.orig/admin
/moodle/trunk/moodle18.orig
/moodle/trunk/util
Modified:
/moodle/trunk/LICENSE.txt
/moodle/trunk/moodle/mod/forum/discuss.php
/moodle/trunk/moodle/mod/forum/lib.php
/moodle/trunk/moodle/mod/forum/post.php
/moodle/trunk/moodle.orig/mod/forum/discuss.php
/moodle/trunk/moodle.orig/mod/forum/lib.php
/moodle/trunk/moodle.orig/mod/forum/post.php

=======================================
--- /dev/null
+++ /moodle/trunk/moodle/blocks/marginalia/db/access.php Wed May 30
15:12:10 2012
@@ -0,0 +1,46 @@
+<?php
+//
+// Capability definitions for the marginalia block.
+//
+// The capabilities are loaded into the database table when the block is
+// installed or updated. Whenever the capability definitions are updated,
+// the module version number should be bumped up.
+//
+// The system has four possible values for a capability:
+// CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT, and inherit (not set).
+//
+//
+// CAPABILITY NAMING CONVENTION
+//
+// It is important that capability names are unique. The naming convention
+// for capabilities that are specific to modules and blocks is as follows:
+// [mod/block]/<component_name>:<capabilityname>
+//
+// component_name should be the same as the directory name of the mod or
block.
+//
+// Core moodle capabilities are defined thus:
+// moodle/<capabilityclass>:<capabilityname>
+//
+// Examples: mod/forum:viewpost
+// block/recent_activity:view
+// moodle/site:deleteuser
+//
+// The variable name for the capability definitions array follows the
format
+// $<componenttype>_<component_name>_capabilities
+//
+// For the core capabilities, the variable is $moodle_capabilities.
+
+
+$block_marginalia_capabilities = array(
+ 'block/marginalia:view_all' => array(
+
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_SYSTEM
+ ),
+ 'block/marginalia:fix_notes' => array(
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_SYSTEM
+ ),
+);
+
+?>
=======================================
--- /dev/null
+++ /moodle/trunk/moodle/blocks/marginalia/help.css Wed May 30 15:12:10 2012
@@ -0,0 +1,4 @@
+.region-content {
+ width: 37em;
+ margin: 0 auto;
+}
=======================================
--- /dev/null
+++ /moodle/trunk/moodle/blocks/marginalia/help.php Wed May 30 15:12:10 2012
@@ -0,0 +1,56 @@
+<?
+
+/**
+ * Load up a help page.
+ * Moodle 1.x provided a help functionality that would pop up a window
containing
+ * an HTML help file. In Moodle 2.0 this was dropped in favor of
displaying
+ * tool tip-type help and links back to moodle.org. Unfortunately small
plain text
+ * tooltips are inadequate for Marginalia help. Furthermore, linking back
to
+ * webmarginalia.net introduces more problems than it solves: help pages
would
+ * need to be versioned, old versions would have to be maintained, and the
volume
+ * of requests could be expensive. Including help documentation with the
software
+ * guarantees that it will refer to the correct version.
+ */
+
+require_once(dirname(__FILE__) . '/../../config.php');
+
+// PARAM_STRINGID ensures this is a valid string ID, which should make
+// this safe to use. (Otherwise an attacker could include ../ or the
like).
+$topic = required_param('topic', PARAM_STRINGID);
+$component = required_param('component', PARAM_SAFEDIR);
+$lang = current_language( );
+
+$PAGE->set_url( '/blocks/marginalia/help.php' );
+$PAGE->set_pagelayout( 'popup' );
+$PAGE->set_context( get_context_instance( CONTEXT_SYSTEM ) );
+$PAGE->requires->css( '/blocks/marginalia/help.css' );
+
+echo $OUTPUT->header( );
+
+list( $plugintype, $pluginname ) = normalize_component( $component );
+$location = get_plugin_directory( $plugintype, $pluginname );
+
+// Once something matches, break from the while.
+// Otherwise fall down to the next case.
+do
+{
+ $path = "$location/lang/$lang/help/$topic.html";
+ if ( $location && file_exists( $path ) )
+ {
+ include( $path );
+ break;
+ }
+
+ $path = "$location/lang/en/help/$topic.html";
+ if ( $location && file_exists( $path ) )
+ {
+ include ( $path );
+ break;
+ }
+
+ echo get_string( 'missing_help', 'block_marginalia' );
+}
+while ( false );
+
+echo $OUTPUT->footer( );
+
=======================================
--- /dev/null
+++ /moodle/trunk/moodle/blocks/marginalia/lang/en/block_marginalia.php Wed
May 30 15:12:10 2012
@@ -0,0 +1,127 @@
+<?php // $Id$
+
+$string['pluginname'] = 'Marginalia';
+$string['splash'] = 'This is the annotation margin. See the annotation
drop down at the top of the page for help. Click x to remove this
message.';
+$string['create_margin'] = 'Select text and click here or type Enter to
create a new annotation.';
+$string['summary_link'] = 'Annotation Summary';
+$string['summary_link_title'] = 'Go to your annotation summary';
+$string['sheet_private'] = 'My Private Annotations';
+$string['sheet_none'] = 'Hide Annotations';
+$string['sheet_public'] = 'Shared Annotations';
+$string['summary_title'] = 'Annotation Summary';
+$string['quote_button'] = 'Quote';
+$string['prompt_find'] = 'Find';
+$string['prompt_by'] = 'by';
+$string['search_of_all'] = 'all annotations';
+$string['search_of_self'] = 'annotations of my work';
+$string['search_by_all'] = 'anyone';
+$string['search_by_self'] = 'myself';
+$string['search_by_teachers'] = 'teachers';
+$string['search_by_students'] = 'students';
+$string['search_text'] = 'containing';
+$string['summary_range_error'] =
+ 'You have been directed here because one or more annotations could not'
+ . ' be displayed. This is probably because the annotated text changed.'
+ . ' This summary includes the annotations which could not be shown.';
+$string['prompt_search_desc'] = 'Showing {$a->n} of {$a->m}';
+$string['prompt_section'] = 'Go to {$a->section_type}';
+$string['prompt_row'] = 'Go to {$a->row_type} by {$a->author}';
+$string['private'] = 'private';
+$string['public'] = 'public';
+$string['author'] = 'author';
+$string['teacher'] = 'teacher';
+$string['author+teacher'] = 'both';
+$string['atom_feed'] = 'Atom 1.0 Feed';
+$string['atom_feed_desc'] = 'Subscribe to updates to this page (only
recent public annotations will be included).';
+$string['unknown_course'] = 'unknown course';
+$string['all_discussions'] = 'all discussions';
+$string['discussion_name'] = 'discussion &quot;{$a->name}&quot;';
+$string['forum_name'] = 'forum &quot;{$a->name}&quot;';
+$string['unknown_discussion'] = 'unknown discussion';
+$string['whole_course'] = 'whole course';
+$string['unknown_post'] = 'unknown discussion post';
+$string['post_name'] = 'discussion post "{$a->name}"';
+$string['annotation_help'] = 'creating and using annotations';
+$string['annotate_help_link'] = 'Annotation Help...';
+$string['annotation_summary_help_link'] = 'How to use this page';
+$string['missing_help'] = 'No help for topic.';
+
+/* Summary page */
+$string['containing'] = 'text containing';
+$string['matching'] = 'notes matching';
+$string['annotation_desc_authorsearch'] = 'annotations by {$a->who} of
work by {$a->author} with {$a->match} &quot;{$a->search}&quot; in
{$a->title}';
+$string['annotation_desc_author'] = 'annotations by {$a->who} of work by
{$a->author} in {$a->title}';
+$string['annotation_desc_search'] = 'annotations by {$a->who} with
{$a->match} &quot;{$a->search}&quot; in {$a->title}';
+$string['annotation_desc'] = 'annotations by {$a->who} in {$a->title}';
+$string['tip'] = 'Tip';
+$string['smartcopy_help'] = 'The Smartcopy feature automatically includes
context information'
+ . ' when you copy and paste text from a blog post. To switch it on or
off, press'
+ . ' Shift-Ctrl-S while viewing a discussion forum.';
+$string['source_th'] = 'Source';
+$string['quote_th'] = 'Highlighted Text';
+$string['note_th'] = 'Margin Note';
+$string['user_th'] = 'User';
+$string['anyone'] = 'anyone';
+$string['me'] = 'Me';
+$string['zoom_user_hover'] = 'Click to show only annotations by
{$a->fullname}.';
+$string['zoom_author_hover'] = 'Click to show only annotations of work by
{$a->fullname}.';
+$string['zoom_url_hover'] = 'Click to show only annotations in this
{$a->section_type}.';
+$string['zoom_match_hover'] = 'Click to show only notes matching this
exact text.';
+$string['unzoom_user_hover'] = 'Click to view annotations by anyone.';
+$string['unzoom_author_hover'] = 'Click to view annotations of any
user&#38;s work.';
+$string['unzoom_url_hover'] = 'Click to broaden the search.';
+$string['unzoom_match_hover'] = 'Click to include all occurrences of this
text.';
+$string['smartquote_annotation'] = 'Quote this annotation in a forum
post.';
+
+$string['annotation_summary'] = 'using the annotation summary.';
+$string['annotation_summary_help'] = 'what for?';
+$string['summary_help'] = 'using the annotation summary.';
+$string['summary_help_help'] = 'uh... whats this for?';
+
+$string['summary_sort_document'] = "Show annotations in document order.";
+$string['summary_sort_time'] = "Show most recent annotations first.";
+$string['summary_source_head'] = 'Source';
+$string['summary_quote_head'] = 'Highlighted Text';
+$string['summary_note_head'] = 'Margin Note';
+$string['summary_time_head'] = 'Modified';
+$string['summary_user_head'] = 'User';
+
+/* Edit Keywords Page */
+$string['edit_keywords_link' ] = 'Annotation Tags';
+$string['edit_keywords_title'] = 'Annotation Tags';
+$string['keyword_column'] = 'Tag';
+$string['keyword_desc_column'] = 'Description';
+$string['create_keyword_button'] = 'Create Tag';
+$string['note_replace_legend'] = 'Search and Replace Margin Notes';
+$string['note_replace_old'] = 'Existing note text';
+$string['note_replace_new'] = 'Replacement note text';
+$string['note_replace_button'] = 'Replace Notes';
+$string['note_update_count'] = 'Notes updated: ';
+$string['tag_list_prompt'] = 'You have used the following notes multiple
times. Click on a link to view a summary of annotations with that note.';
+
+/* Strings used in JS front-end */
+$string['js_public_annotation'] = 'This annotation is public.';
+$string['js_private_annotation'] = 'This annotation is private.';
+$string['js_delete_annotation_button'] = 'Delete this annotation.';
+$string['js_annotation_link_button'] = 'Link to another document.';
+$string['js_annotation_link_label'] = 'Select a document to link to.';
+$string['js_delete_annotation_link_button'] = 'Remove this link.';
+$string['js_annotation_expand_edit_button'] = 'Click to display margin
note editor';
+$string['js_annotation_collapse_edit_button'] = 'Click to display margin
note drop-down list';
+$string['js_annotation_quote_button'] = 'Quote this annotation in a
discussion post.';
+$string['js_chars_remaining'] = 'characters remaining';
+$string['js_edit_annotation_click'] = 'Click to edit the text of this
annotation.';
+$string['js_note_user_recent_title'] = 'Note recently modified on: ';
+$string['js_note_user_title'] = 'Note last modified on: ';
+$string['js_delete_tip_button'] = 'Remove this message.';
+
+$string['js_browser_support_of_W3C_range_required_for_annotation_creation']
= 'Your
browser does not support the W3C range standard, so you cannot
create annotations.';
+$string['js_select_text_to_annotate'] = 'You must select some text to
annotate.';
+$string['js_invalid_selection'] = 'Selection range is not valid.';
+$string['js_corrupt_XML_from_service'] = 'An attempt to retrieve
annotations from the server returned corrupt XML data.';
+$string['js_note_too_long'] = 'Please limit your margin note to 250
characters.';
+$string['js_quote_too_long'] = 'The passage you have attempted to
highlight is too long. It may not exceed 1000 characters.';
+$string['js_zero_length_quote'] = 'You must select some text to annotate.';
+$string['js_quote_not_found'] = 'The highlighted passage could not be
found';
+$string['js_create_overlapping_edits'] = 'You may not create overlapping
edits';
+
=======================================
--- /dev/null
+++ /moodle/trunk/moodle/blocks/marginalia/lang/en/help/annotate.html Wed
May 30 15:12:10 2012
@@ -0,0 +1,82 @@
+<h1>How to Use Marginalia Annotations</h1>
+
+<p>The "Marginalia" annotation feature allows you to highlight passages of
text and
+add margin notes to discussion forum posts.</p>
+
+<h2>Showing Annotations</h2>
+
+<p>A drop-down list at the top of the page allows you to choose which
annotations
+to display. If you wish to view and write annotations that only you can
see, select
+<kbd>My Private Annotations</kbd> from the list. If you wish to view and
write
+annotations that can be seen by anyone, select <kbd>Shared
Annotations</kbd>.
+
+<p>Each annotation consists of a passage in the text (highlighted in
+yellow) and an associated note in the right margin. Annotations that have
been
+added since you last viewed the page appear with a red asterisk next to
them.
+Hovering over either a highlighted passage or a margin note will cause
both to
+light up in red, indicating which note goes with which highlight.</p>
+
+<h2>Create an Annotation</h2>
+
+<p>Select a range of text in the content of a post. Then type
+<kbd>Enter</kbd> or click in the right margin a faint outline
+appears when when the mouse pointer is over it). An edit box appears in
the
+margin. Type in any margin note, then click elsewhere on the page or press
+<kbd>Enter</kbd> to save the annotation.</p>
+
+<p>To edit one of your existing annotations, click on the note in the right
+margin. The note will appear in an edit box, and you can make changes just
+as you did when you created the annotation.</p>
+
+<p>If you use the same margin note more than once, Margin can simplify
retyping
+it by autocompleting the margin note as you type. You can accept
Marginalia's
+suggestion, or ignore it and type over it.</p>
+
+<p>URLs pasted in to a margin note are turned into clickable hyperlinks.
(Note:
+this only works for URLs beginning with http and https.)</p>
+
+<h2>Delete an Annotation</h2>
+
+<p>Click the small <kbd>x</kbd> next to the note text in the right
margin.</p>
+
+<h2>Discuss an Annotation</h2>
+
+<p>You may sometimes wish to comment on someone else's annotation, to turn
+one of your annotations into a more fleshed-out forum post, or to quote one
+of your annotations in a post you are writing. To do this, click the
quotes
+(&#10075;&#10076;) next to the annotation. If you
+are already writing a forum post, Marginalia will insert the annotation
+text directly into the text you are
+editing. If not, Marginalia will open a new forum post for you and insert
+the annotation text there.</p>
+
+<h2>Viewing a Summary of Annotations</h2>
+
+<p>It is possible to view a summary of annotations for one or more forum
+discussions. To access it, click the <kbd>summary</kbd> link at the top
+right of the page.</p>
+
+<h2>Missing Annotations</h2>
+
+<p>Under rare circumstances (e.g. if someone edits an existing post), the
+annotation software may be unable to locate the text you highlighted when
you
+created the annotation. In this case, the margin note is still shown, but
+the highlighted passage is not. In Firefox, a red exclamation mark next to
+the note indicates the problem; hovering the mouse over it displays the
+text of the original highlighted passage. You can always see all your
+annotations on the summary page.</p>
+
+<p>Note that annotations cannot be deleted by anyone but you. Even if an
+annotated post or discussion is deleted, the annotations will still be
+available through the summary page.</p>
+
+<h2>Browser Support</h2>
+
+<p>Marginalia works with recent versions of the Firefox, Safari, and
Internet
+Explorer browsers with Javascript enabled. Because of limitations in
Internet
+Explorer, some features work better and faster in the other browsers.</p>
+
+<h2>More Information</h2>
+
+<p>For more information about annotations, see the
+<a href="http://www.geof.net/code/annotation">Marginalia</a> web site.</p>
=======================================
--- /dev/null
+++
/moodle/trunk/moodle/blocks/marginalia/lang/en/help/annotation_summary.html
Wed May 30 15:12:10 2012
@@ -0,0 +1,114 @@
+<h1>The Annotation Summary</h1>
+
+<p>This page allows you to search your annotations, and the annotations
other
+users have chosen to share.</p>
+
+<h2>Result List</h2>
+
+<p>The result table shows four columns:</p>
+
+<ul>
+<li>The thing that was annotated (a forum post), along with its author.
+Clicking on the link allows you to view the entire item.</li>
+<li>The highlighted passage of text.</li>
+<li>The margin note typed by whoever created the annotation.</li>
+<li>The name of the person who created the annotation, along with some
+annotation controls.</li>
+</ul>
+
+<p>If there are many annotations, the results may be split into several
pages.
+To see subsequent result pages click the numbered links below the table of
+results.</p>
+
+<h2>Searching and Filtering</h2>
+
+<p>There are essentially three ways to search and filter your results:</p>
+
+<ol>
+<li>The text search field at the top of the page.</li>
+<li>Triangles (&#9664;) that pop up next to certain parts of the result
when you
+hover over them. Clicking on one of these filters the results to show only
+annotations matching whatever the hand points to (if you hover for long
+enough, help text will explain what clicking would do).</li>
+<li>Links in the search result description. As you filter and search,
there
+is always a description of what you're looking at at the top of the page.
+Parts of the description are displayed as hyperlinks. If you hover over
+one of these links, it will be displayed with a line through it. If you
wait
+for a moment, a tip appears describing what you would
+see if you clicked the link. Generally this broadens the search,
cancelling
+filters applied elsewhere.</li>
+</ol>
+
+<p>You can probably figure these out just by experimenting with them. More
+detailed explanations follow.</p>
+
+<h3>Searching for Text</h3>
+
+<p>You can filter your search results in several ways. First, most
obviously,
+you can type search text in the text entry box at the top of the page, then
+click <kbd>Find</kbd> to find matching annotations.</p>
+
+<p>Ordinarily, the search
+result displays <kbd>with text containing</kbd> (you won't see this unless
you
+first do a text search), indicating that the search
+will look for that text in margin notes, highlighted passages, and the
names
+of the users who created the annotations.</p>
+
+<p>If you want to search for an annotation matching an exact phrase (
+useful if you use the same margin note repeatedly), you can click on
+<kbd>text containing</kbd> (it's displayed as a link) to search only for
+<kbd>notes matching</kbd> instead (and vice versa).</p>
+
+<h3>Filtering by Who Wrote the Annotations</h3>
+
+<p>If you wish to show only annotations by a particular user (such as the
+teacher of a course), hover the mouse over that person's name in the
right-hand
+column. A triangle (&#9664;) appears. If you click on it, the list will
be filtered to
+display only annotations created by that person.</p>
+
+<p>If the annotations are already filtered by a particular user (say
they're
+by Fred), the search description at the top of the page will include a link
+saying that the annotations are by that user (<kbd>by Fred</kbd>).
+Clicking on the link will remove the filter and include annotation by
anyone.</p>
+
+<h3>Filtering by Whose Work Is Annotated</h3>
+
+<p>You may wish to view only annotations of a particular user's work (you
might
+want to see what people have to say about your forum posts, for example).
To
+do this, hover the mouse over the name of the author of the original
document,
+in the left column. A triangle (&#9664;) will appear. Click it to run
the filter.</p>
+
+<p>If the results are filtered this way (to show only annotations of things
+Josephine has written, perhaps), the search description at the top
+will include a link saying this shows annotations of <kbd>work by
Jospehine</kbd>.
+Click on the link to remove the filter.</p>
+
+<h3>Viewing Recent Annotations</h3>
+
+<p>The summary page normally shows annotations in document order - that
is, the order
+of annotations in the summary reflects which highlights occur first in the
annotated
+document. Sometimes it can be used to see recent annotations - for
example, in order
+to keep up with what other users are writing. A link at the bottom of the
page gives
+the option of ordering annotations according to when they were last
modified. If
+you choose this option the result table will also display that time and
date (normally
+it does not in order to prevent clutter).
+
+<h3>Broadening and Narrowing the Search</h3>
+
+<p>Initially, you will likely see only annotations for a particular area -
a
+specific discussion, perhaps. You may wish to include annotation for all
+discussions in the same forum, or all annotations in that course, and so
on.
+Say you're viewing annotations of a discussion named "It's Turtles All the
Way Down"
+in the "Metaphysics" forum. You will see a description at the top of the
page,
+including the text <kbd>in discussion "It's Turtles All the Way
Down"</kbd>,
+with the last part displayed as a hyperlink. If you hover over the link,
it
+will be replaced by the name of the broader category - in this case, it
would
+change to <kbd>in forum "Metaphysics"</kbd>. To view all annotations in
that
+forum, click on the link to broaden the search.</p>
+
+<p>On the other hand, you may wish to narrow your search to include only a
+particular discussion, forum, etc. Notice that the result list has section
+headings. One might look like <kbd>Discussion: It's Turtles All the Way
+Down</kbd>. If you hover over one of these, a triangle (&#9664;)
appears. Clicking on
+it allows you to narrow your search to only annotations in that
section.</p>
+
=======================================
--- /dev/null
+++ /moodle/trunk/moodle/blocks/marginalia/moodle_marginalia.php Wed May 30
15:12:10 2012
@@ -0,0 +1,1020 @@
+<?php
+/*
+ * blocks/marginalia/moodle_marginalia.php
+ *
+ * Marginalia has been developed with funding and support from
+ * BC Campus, Simon Fraser University, and the Government of
+ * Canada, the UNDESA Africa i-Parliaments Action Plan, and
+ * units and individuals within those organizations. Many
+ * thanks to all of them. See CREDITS.html for details.
+ * Copyright (C) 2005-2011 Geoffrey Glass; the United Nations
+ * http://www.geof.net/code/annotation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
+ *
+ * $Id$
+ */
+
+/*
+FOR DEBUGGING:
+Turn off minify for javascript by going to Site Admin > Appearance > AJAX.
+Switch off JS caching and YUI combo loading
+*/
+
+require_once( $CFG->dirroot.'/blocks/marginalia/config.php' );
+require_once( ANNOTATION_DIR.'/marginalia-php/embed.php' );
+require_once( ANNOTATION_DIR.'/annotation_summary_query.php' );
+
+// The smartquote icon symbol(s)
+define( 'AN_SMARTQUOTEICON', '\u275d' ); // \u275b\u275c: enclosed single
qs, 267a: recycle
+
+// The same thing as entities because - and this stuns the hell out of me
every
+// single time - PHP 5 *does not have native unicode support*!!! Geez
guys,
+// I remember reading about unicode in Byte Magazine in what, the 1980s?
+define( 'AN_SMARTQUOTEICON_HTML', '&#10077;' ); //'&#10075;&#10076;' );
+
+// Icon for filtering on the summary page
+define( 'AN_FILTERICON_HTML', '&#9664' ); // '&#9754;' ); //&#9756;
+
+define( 'ANNOTATION_STRINGS', 'block_marginalia' );
+
+define( 'AN_SHEET_PREF', 'annotations.sheet' ); // 'annotations.user' );
+define( 'AN_SHOWANNOTATIONS_PREF', 'annotations.show' );
+define( 'AN_NOTEEDITMODE_PREF', 'annotations.note-edit-mode' );
+define( 'AN_SPLASH_PREF', 'annotations.splash' );
+//define( 'SMARTCOPY_PREF', 'smartcopy' );
+
+define( 'AN_DBTABLE', 'marginalia' );
+define( 'AN_READ_TABLE', 'marginalia_read' );
+
+define( 'AN_SHEET_PRIVATE', 0x1 );
+define( 'AN_SHEET_AUTHOR', 0x2 );
+define( 'AN_SHEET_PUBLIC', 0xffff );
+
+// Object types
+define ( 'AN_OTYPE_POST', 1 );
+define ( 'AN_OTYPE_ANNOTATION', 2 );
+define ( 'AN_OTYPE_DISCUSSION', 3 );
+
+// Needed by several annotation functions - if not set, PHP will throw
errors into the output
+// stream which causes AJAX problems. Doing it this way in case moodle
sets the TZ at some
+// future point. Leading @ suppresses warnings. (Sigh... try..catch
didn't work. PHP is such a mess.)
+// Commented out in hopes Moodle 2.0 has fixed this problem.
+// @date_default_timezone_set( date_default_timezone_get( ) );
+
+/**
+ * A page profile knows the options enabled for a particular page, and
+ * how to emit relevant HTML. Stores page-specific information like post
ID.
+ * Immutable: it should be safe to construct this multiple times for the
same
+ * page and get exactly the same version back.
+ */
+abstract class mia_page_profile
+{
+ protected $url;
+ public $moodlemia;
+
+ public function __construct( $moodlemia, $url )
+ {
+ $this->moodlemia = $moodlemia;
+ $this->url = $moodlemia->relative_url( $url );
+ }
+
+ /**
+ * Note that this returns an actual URL. Moodle's moodle_url class by
default
+ * does not return a URL - it returns an HTML-escaped URL. In my opinion,
+ * this implicit magic is perverse. It may or may not be a convenient
+ * default, but it is surprising and violates the expectation that
something
+ * called a URL would be a URL. It is the case that refurl is also not a
+ * complete URL. In the PHP code the term "refurl" is always used to
+ * refer to such a partial URL.
+ */
+ public abstract function get_refurl( );
+
+ /**
+ * Requires for annotation features
+ */
+ protected function emit_requires_annotate( )
+ {
+ global $PAGE;
+
+ $blockpath = '/blocks/marginalia';
+ $PAGE->requires->css( $blockpath."/marginalia/marginalia.css" );
+ $PAGE->requires->css( $blockpath."/annotation-styles.php" );
+
+ // Scripts are loaded in page header (second parameter is true)
+ // This could slow things down, but for now it's needed at least for
+ // jQuery as js_init is fishy.
+ $anscripts = listMarginaliaJavascript( );
+ for ( $i = 0; $i < count( $anscripts ); ++$i )
+ $PAGE->requires->js( $blockpath.'/marginalia/'.$anscripts[ $i ], true );
+ $PAGE->requires->js( $blockpath.'/marginalia-config.js', true );
+ $PAGE->requires->js( $blockpath.'/MoodleMarginalia.js', true );
+
+
$PAGE->requires->css( "/lib/yui/autocomplete/assets/skins/sam/autocomplete.css"
);
+
//$PAGE->requires->yui2_lib( '/lib/yui/yahoo-dom-event/yahoo-dom-event.js'
);
+ // '/lib/yui/datasource/datasource-min.js',
+ $PAGE->requires->yui2_lib( 'autocomplete' );
+ }
+
+ /**
+ * Requires for quoting
+ */
+ protected function emit_requires_quote( )
+ {
+ global $PAGE;
+
+ $blockpath = '/blocks/marginalia';
+ $PAGE->requires->js( $blockpath.'/smartquote.js', true );
+ }
+
+ /**
+ * Emit JS block
+ * Tried $PAGE->requires_js_init_call, but it implicitly loads a script
+ * in mod/module.js - which for me does not exist, and its parameter
+ * mechanism is way too limited.
+ */
+ public function emit_init_js( $s )
+ {
+ global $PAGE;
+
+ // All this rigamarole with Y is an attempt to make sure this executes
+ // last, after tinyMCE controls are initialized. No such luck. The
+ // code is emitted last, but tinyMCE must set up a timer, then wipe
+ // out message content. Bleargh.
+ echo "<script type='text/javascript'>\n//<![CDATA[\n"
+ ."function moodle_marginalia_init(Y)\n{\n"
+ ."Y.on('domready', function() {"
+ .$s
+ ."});\n"
+ ."}\n" //\n$( document ).ready( moodle_marginalia_init );\n"
+ ."//]]>\n</script>\n";
+ $PAGE->requires->js_init_call( 'moodle_marginalia_init', null);
+ }
+
+ /**
+ * Body JS for annotation margin
+ */
+ public function margin_js( )
+ {
+ global $CFG, $USER, $PAGE, $course;
+
+ $refurl = $this->get_refurl( );
+
+ $canannotate = $this->moodlemia->can_annotate( $refurl );
+
+ // Get all annotation preferences as an associative array and sets them
to defaults
+ // in the database if not already present.
+ $prefs = array(
+ AN_SHEET_PREF => $this->moodlemia->get_pref( AN_SHEET_PREF, 'public' ),
+ AN_SHOWANNOTATIONS_PREF => $this->moodlemia->get_pref(
AN_SHOWANNOTATIONS_PREF, 'false' ),
+ AN_NOTEEDITMODE_PREF => $this->moodlemia->get_pref(
AN_NOTEEDITMODE_PREF, 'freeform' ),
+ AN_SPLASH_PREF => $this->moodlemia->get_pref( AN_SPLASH_PREF, 'true' )
+ );
+
+ $showannotationspref = $prefs[ AN_SHOWANNOTATIONS_PREF ];
+ $showsplashpref = $prefs[ AN_SPLASH_PREF ];
+
+ // Build a string of initial preference values for passing to Marginalia
+ $first = true;
+ $sprefs = '';
+ foreach ( array_keys( $prefs ) as $name )
+ {
+ $value = $prefs[ $name ];
+ if ( $first )
+ $first = false;
+ else
+ $sprefs .= "\n, ";
+ $sprefs .= "'".s( $name )."': '".s( $prefs[ $name ] )."'";
+ }
+ $sprefs = '{ '.$sprefs.' }';;
+
+ // URLs used by drop-down menu handlers
+ $summaryurl =
ANNOTATION_PATH.'/summary.php?user='.(int)$USER->id.'&url='.urlencode(
$refurl );
+ $helpurl =
ANNOTATION_PATH.'/help.php?component=block_marginalia&topic=annotate';
+ $tagsurl = ANNOTATION_PATH.'/tags.php?course='.(int)$course->id;
+
+ $sitecontext = get_context_instance(CONTEXT_SYSTEM);
+ $allowAnyUserPatch = AN_ADMINUPDATE && (
+ has_capability( 'block/marginalia:fix_notes', $sitecontext ) );
+
+ $plugin_handlers = '';
+ foreach ( $this->moodlemia->plugins as $plugin )
+ {
+ $dropdowns = $plugin->dropdown_entries( $refurl );
+ if ( $dropdowns )
+ {
+ foreach ( $dropdowns as $dropdown )
+ $plugin_handlers .= "\n, ".$dropdown->value.': '.$dropdown->action;
+ }
+ }
+
+ // These variable names are prefixed with "s" for "safe" (HTML safe)
+ $swwwroot = s($CFG->wwwroot);
+ $smiapath = s(ANNOTATION_PATH);
+ $suserid = s($USER->id);
+ $srefurl = s($refurl);
+ $slogger = $this->moodlemia->logger &&
$this->moodlemia->logger->is_active() ? 'true' : 'false';
+ $scourseid = (int)$course->id;
+ $sanypatch = $allowAnyUserPatch ? 'true' : 'false';
+ $scanannotate = $canannotate ? 'true' : 'false';
+ $susesmartquote = AN_USESMARTQUOTE ? 'true' : 'false';
+ $ssmartquoteicon = s(AN_SMARTQUOTEICON);
+ $ssessioncookie = 'MoodleSession' . s($CFG->sessioncookie);
+ $ssummaryurl = $summaryurl;
+ $shelpurl = $helpurl;
+ $stagsurl = $tagsurl;
+ $ssplash = 'true' ==
$showsplashpref ? "'".get_string('splash',ANNOTATION_STRINGS)."'" : 'null';
+ $sstrings = $this->moodlemia->strings_js( );
+
+ return <<<SCRIPT
+ var moodleRoot = '$swwwroot';
+ var annotationPath = '$smiapath';
+ var url = '$srefurl';
+ var userId = '$suserid';
+ window.moodleMarginalia = new MoodleMarginalia(
+ annotationPath, url, moodleRoot, userId, $sprefs, {
+ useSmartquote: $susesmartquote,
+ useLog: '$slogger',
+ course: $scourseid,
+ allowAnyUserPatch: $sanypatch,
+ canAnnotate: $scanannotate,
+ smartquoteIcon: '$ssmartquoteicon',
+ sessionCookie: '$ssessioncookie',
+ onKeyCreate: true,
+ handlers: {
+ summary: function() { window.location = '$ssummaryurl'; },
+ help: function() { window.location = '$helpurl'; }
+ /*,tags: function() { window.location = '$stagsurl'; }*/
+ $plugin_handlers}
+ , splash: $ssplash
+ , strings: $sstrings
+ }
+ );
+ window.moodleMarginalia.onload( );
+SCRIPT;
+ }
+
+ /**
+ * Get the current sheet
+ * Should be per profile (or per profile and per course),
+ * but for now the setting is global
+ */
+ function get_sheet( )
+ {
+ return $this->moodlemia->get_sheet( );
+ }
+
+ /**
+ * Show the margin controls.
+ * These are currently in a drop-down menu with the following options:
+ * - which annotation set to show (multiple options)
+ * - link to summary page
+ * - help button
+ */
+ function emit_margin_controls( )
+ {
+ global $USER;
+
+ $refurl = $this->get_refurl( );
+
+ $sheet = $this->get_sheet( );
+ $showannotationspref = $this->moodlemia->get_show_annotations_pref( )
== 'true';
+
+ echo "<div class='discussioncontrols miacontrols clearfix'>";
+ echo "<div class='discussioncontrol nullcontrol'>&#160;</div><div
class='discussioncontrol'>&#160;</div>\n";
+ echo "<select name='ansheet' class='discussioncontrol miacontrol'
id='ansheet'
onchange='window.moodleMarginalia.changeSheet(this,\"".$refurl."\");'>\n";
+
+ $selected = $showannotationspref ? '' : " selected='selected' ";
+ echo " <option $selected value=''>".get_string('sheet_none',
ANNOTATION_STRINGS)."</option>\n";
+
+ if ( ! isguestuser() ) {
+ $selected = ( $showannotationspref && $sheet == AN_SHEET_PRIVATE
) ? "selected='selected' " : '';
+ echo " <option $selected"
+
."value='".$this->moodlemia->sheet_str(AN_SHEET_PRIVATE,null)."'>".get_string('sheet_private',
ANNOTATION_STRINGS)."</option>\n";
+ }
+ // Show item for all users
+ if ( true ) {
+ $selected = ( $showannotationspref && $sheet == AN_SHEET_PUBLIC
) ? "selected='selected' " : '';
+ echo " <option $selected
value='".$this->moodlemia->sheet_str(AN_SHEET_PUBLIC,null)."'>".get_string('sheet_public',
ANNOTATION_STRINGS)."</option>\n";
+ }
+ echo " <option disabled='disabled'>——————————</option>\n";
+ echo " <option
value='summary'>".get_string('summary_link',ANNOTATION_STRINGS)."...</option>\n";
+ // echo " <option
value='tags'>".get_string('edit_keywords_link',ANNOTATION_STRINGS)."...</option>\n";
+
+ foreach ( $this->moodlemia->plugins as $plugin )
+ {
+ $dropdowns = $plugin->dropdown_entries( $refurl );
+ if ( $dropdowns )
+ {
+ foreach ( $dropdowns as $dropdown )
+ echo "<option
value='".$dropdown->value."'>".s($dropdown->name)."</option>\n";
+ }
+ }
+
+ echo " <option
value='help'>".get_string('annotate_help_link',ANNOTATION_STRINGS)."...</option>\n";
+ echo "</select>\n";
+ echo "</div>\n";
+ }
+
+ /**
+ * Emit JS to enable quote publishing
+ */
+ protected function quote_publish_js( )
+ {
+ return "moodleMarginalia.enablePublishQuotes( );\n";
+ }
+
+ /**
+ * Emit JS to enable quote subscribing for a given MCE instance
+ */
+ protected function quote_subscribe_js( $mceid )
+ {
+ return "moodleMarginalia.enableSubscribeQuotes( '".s($mceid)."' );\n";
+ }
+
+
+ public function output_margin( )
+ {
+ $output = html_writer::tag('ol', '<li class="mia_dummyfirst"></li>',
+ array('class'=>'mia_margin'
+ , 'style'=>'float:right;width:15em'
+ , 'title'=>get_string('create_margin', ANNOTATION_STRINGS)));
+ //$output .= html_writer::end_tag('ol');
+ return $output;
+ }
+
+ public function output_quote_button( )
+ {
+ $output =
html_writer::tag( 'button', '<span>'.get_string( 'quote_button',
ANNOTATION_STRINGS ).'</span>',
+ array( 'class'=>'smartquote' ) );
+ //$output .= html_writer::end_tag( 'button' );
+ return $output;
+ }
+
+ /**
+ * Emit require statements for head
+ */
+ public abstract function emit_requires( );
+
+ /**
+ * Emit additional stuff (JS) in the body
+ */
+ public abstract function emit_body( );
+
+ /**
+ * Get the type of object (for annotation creation). Defaults to
+ * null.
+ */
+ public function get_object_type( )
+ { return null; }
+
+ /**
+ * Get the id of an object (for annotation creation). Defaults to null.
+ */
+ public function get_object_id( )
+ { return null; }
+}
+
+class mia_profile_forum_display extends mia_page_profile
+{
+ var $object_type = null;
+ var $object_id = null;
+
+ public function __construct( $moodlemia, $url, $object_id, $object_type )
+ {
+ parent::__construct( $moodlemia, $url );
+ $this->object_type = $object_type;
+ $this->object_id = $object_id;
+ }
+
+ public function get_refurl( )
+ {
+ return $this->url;
+ }
+
+ public function emit_requires( )
+ {
+ $this->emit_requires_annotate( );
+ $this->emit_requires_quote( );
+ $this->moodlemia->emit_plugin_requires( );
+ }
+
+ public function emit_body( )
+ {
+ $s = $this->margin_js( );
+ $s .= $this->quote_publish_js( );
+ $this->emit_init_js( $s );
+ $this->moodlemia->emit_plugin_body( );
+ }
+
+ public function get_object_type( )
+ {
+ return $this->object_type;
+ }
+
+ public function get_object_id( )
+ {
+ return $this->object_id;
+ }
+}
+
+class mia_profile_forum_compose extends mia_page_profile
+{
+ var $replypostid; // id of the post to which this is a reply, or null
+
+ public function __construct( $moodlemia, $url )
+ {
+ parent::__construct( $moodlemia, $url );
+ $this->replypostid = optional_param('reply', 0, PARAM_INT);
+ }
+
+ public function get_refurl( )
+ {
+ return '/mod/forum/permalink.php?p='.(int)$this->replypostid;
+ }
+
+ public function emit_requires( )
+ {
+ $this->emit_requires_annotate( );
+ $this->emit_requires_quote( );
+ $this->moodlemia->emit_plugin_requires( );
+ }
+
+ public function emit_body( )
+ {
+ $s = $this->margin_js( );
+ $s .= $this->quote_publish_js( );
+ $s .= $this->quote_subscribe_js( 'id_message' );
+ $this->emit_init_js( $s );
+ $this->moodlemia->emit_plugin_body( );
+ }
+
+ public function get_object_type( $url )
+ {
+ return AN_OTYPE_POST;
+ }
+
+ public function get_object_id( $url )
+ {
+ throw $this->replypostid;
+ }
+}
+
+/**
+ * A page using JS-only to send explicit Marginalia requests through
Javascript.
+ * I.e., no margin. The summary page is like this. Really this is a bit
of a
+ * hack: clearly these init functions shouldn't be tied so closely to
profiles
+ * for margins.
+ */
+class mia_profile_js extends mia_page_profile
+{
+ var $replypostid; // id of the post to which this is a reply, or null
+
+ public function __construct( $moodlemia )
+ {
+ parent::__construct( $moodlemia, null );
+ }
+
+ public function get_refurl( )
+ {
+ throw "Attempt to call moodle_profile_js::get_refurl";
+ }
+
+ public function emit_requires( )
+ {
+ $this->emit_requires_annotate( );
+ $this->emit_requires_quote( );
+ $this->moodlemia->emit_plugin_requires( );
+ }
+
+ public function emit_body( )
+ {
+ $s = $this->quote_publish_js( );
+ $s .= $this->quote_subscribe_js( 'id_message' );
+ $this->emit_init_js( $s );
+ $this->moodlemia->emit_plugin_body( );
+ }
+
+ public function get_object_type( $url )
+ {
+ throw "Attempt to call moodle_profile_js::get_object_type";
+ }
+
+ public function get_object_id( $url )
+ {
+ throw "Attempt to call moodle_profile_js::get_object_id";
+ }
+}
+
+class moodle_marginalia
+{
+ static $singleton = null;
+ var $logger = null;
+ var $plugins = array( );
+
+ // I would think Moodle might cache the capabilities to make
has_capability fast, but it doesn't.
+ var $viewfullnames = False;
+ var $viewfullnames_set = False;
+
+ var $page_profiles = array( );
+
+ public static function get_instance( )
+ {
+ if ( ! moodle_marginalia::$singleton )
+ moodle_marginalia::$singleton = new moodle_marginalia( );
+ return moodle_marginalia::$singleton;
+ }
+
+ /**
+ * Strip wwwroot from the start of a URL to create a URL relative only
+ * to this instance of moodle. Used internally by Marginalia so that if
+ * Moodle is moved Marginalia will not break.
+ */
+ public static function relative_url( $url )
+ {
+ global $CFG;
+
+ $wwwroot = $CFG->wwwroot;
+
+ return ( substr( $url, 0, strlen( $wwwroot ) ) == $wwwroot )
+ ? substr( $url, strlen( $CFG->wwwroot ) ) : $url;
+ }
+
+ /**
+ * Get the Marginalia profile for a given URL.
+ * Usually this will be for $PAGE->url.
+ */
+ public function get_profile( $url )
+ {
+ if ( preg_match( '/^.*\/mod\/forum\/permalink\.php\?p=(\d+)/', $url,
$matches ) )
+ return new mia_profile_forum_display( $this, $url, (int) $matches[ 1 ],
AN_OTYPE_POST);
+ elseif ( preg_match( '/^.*\/mod\/forum\/discuss\.php\?d=(\d+)/', $url,
$matches ) )
+ return new mia_profile_forum_display( $this, $url, (int) $matches[ 1 ],
AN_OTYPE_DISCUSSION );
+ elseif ( preg_match( '/^.*\/mod\/forum\/post\.php/', $url, $matches ) )
+ return new mia_profile_forum_compose( $this, $url );
+ elseif ( preg_match( '/^.*\/blocks\/marginalia\/summary.php/', $url,
$matches ) )
+ return new mia_profile_js( $this );
+ return null;
+ }
+
+ public function moodle_marginalia( )
+ {
+ global $CFG, $DB;
+
+ // Load up the logger, if available
+ $blocks = $DB->get_records('block');
+ if ( $blocks )
+ {
+ $prefix = 'marginalia_';
+ $prefixlen = strlen( 'marginalia_' );
+ foreach ( $blocks as $block )
+ {
+ if ( substr( $block->name, 0, $prefixlen ) == $prefix )
+ {
+ require_once( $CFG->dirroot.'/blocks/'.$block->name.'/lib.php' );
+ $plugin = new $block->name( );
+ if ( $plugin->is_active( ) )
+ {
+ array_push( $this->plugins, $plugin );
+ if ( $block->name == 'marginalia_log' )
+ $this->logger = $plugin;
+ }
+ }
+ }
+ }
+
+ /*
+ * Profiles for Marginalia functionality on a particular page. Used by
+ * moodle_marginalia to decide which files to include and which
functionality
+ * to activate.
+ *
+ * This could be done by having the page itself set up the
configuration. But
+ * that would require more changes to Moodle core code. Since
Marginalia has
+ * to patch Moodle, it's best to make the patch as small and unchanging
as
+ * possible. Instead the page can simply select a profile. This can
even be
+ * made automatic based on the page URL, which Moodle pages already set.
+ *
+ * What's with PHP's retarded refusal to parse array( new ... )? Why
+ * do people put up with this crap language?
+ */
+ $this->page_profiles[ ] = new mia_profile_forum_display( $this,
+ 'forum_post',
+ '/^.*\/mod\/forum\/permalink\.php\?p=(\d+)/',
+ AN_OTYPE_POST);
+ $this->page_profiles[ ] = new mia_profile_forum_display( $this,
+ 'forum_discussion',
+ '/^.*\/mod\/forum\/discuss\.php\?d=(\d+)/',
+ AN_OTYPE_DISCUSSION );
+ $this->page_profiles[ ] = new mia_profile_forum_compose( $this,
+ 'forum_compose',
+ '/^.*\/mod\/forum\/post\.php/' );
+ }
+
+ function fullname($user)
+ {
+ // must be able to handle null user
+ if ( ! $user )
+ return 'NONE';
+ if ( ! $this->viewfullnames_set )
+ {
+ $context = get_context_instance( CONTEXT_SYSTEM );
+ $this->viewfullnames = has_capability( 'moodle/site:viewfullnames',
$context );
+ $this->viewfullnames_set = True;
+ }
+ return fullname( $user, $this->viewfullnames );
+ }
+
+ function fullname2( $firstname, $lastname )
+ {
+ $u = new object();
+ $u->firstname = $firstname;
+ $u->lastname = $lastname;
+ return $this->fullname($u);
+ }
+
+ function get_host( )
+ {
+ global $CFG;
+ $urlparts = parse_url( $CFG->wwwroot );
+ return $urlparts[ 'host' ];
+ }
+
+ function get_service_path( )
+ {
+ global $CFG;
+ return $CFG->wwwroot . ANNOTATION_PATH . '/annotate.php';
+// return $this->getMoodlePath( ) . ANNOTATE_SERVICE_PATH;
+ }
+
+ function get_keyword_service_path( )
+ {
+ global $CFG;
+ return $CFG->wwwroot . ANNOTATION_PATH . '/keywords.php';
+ }
+
+ /** Get the moodle path - that is, the path to moodle from the root of
the server. Typically this is 'moodle/'.
+ * REQUEST_URI starts with this. */
+ function get_moodle_path( )
+ {
+ global $CFG;
+ $urlparts = parse_url( $CFG->wwwroot );
+ return $urlparts[ 'path' ];
+ }
+
+ /**
+ * Get the server part of the moodle path.
+ * This is the absolute path, with the getMoodlePath( ) portion chopped
off.
+ * Useful, because appending a REQUEST_URI to it produces an absolute
URI. */
+ function get_moodle_server( )
+ {
+ global $CFG;
+ $urlparts = parse_url( $CFG->wwwroot );
+ if ( $urlparts[ 'path' ] == '/' )
+ return $CFG->wwwroot;
+ else
+ return substr( $CFG->wwwroot, 0, strpos( $CFG->wwwroot,
$urlparts[ 'path' ] ) );
+ }
+
+ function get_install_date( )
+ {
+ // Hardcoded because I'm not aware of Moodle recording an install date
anywhere
+ date_default_timezone_set( date_default_timezone_get( ) );
+ return strtotime( '2005-07-20' );
+ }
+
+ function get_feed_tag_uri( )
+ {
+ return "tag:" . $this->get_host() . ',' . date( 'Y-m-d',
$this->get_install_date() ) . ":annotation";
+ }
+
+ /**
+ * get sheet type for sheet string
+ */
+ function sheet_type( $sheet_str )
+ {
+ if ( 'public' == $sheet_str )
+ return AN_SHEET_PUBLIC;
+ elseif ( 'author' == $sheet_str )
+ return AN_SHEET_AUTHOR;
+ else
+ return AN_SHEET_PRIVATE;
+ }
+
+ /**
+ * get sheet string for type and group
+ */
+ function sheet_str( $sheet_type )
+ {
+ if ( AN_SHEET_PUBLIC == $sheet_type )
+ return 'public';
+ elseif ( AN_SHEET_PRIVATE == $sheet_type )
+ return 'private';
+ elseif ( AN_SHEET_AUTHOR == $sheet_type )
+ return 'author';
+ return '';
+ }
+
+ /**
+ * Remember: This the Annotation class does not store Moodle user IDs, so
+ * you must be sure to query for username and quote_author_username if you
+ * want userid and quoteAuthorId set.
+ */
+ function record_to_annotation( $r )
+ {
+ $annotation = new Annotation( );
+
+ $annotation->setAnnotationId( $r->id );
+
+ if ( array_key_exists( 'userid', $r ) )
+ $annotation->setUserId( $r->userid );
+ if ( array_key_exists( 'firstname', $r ) )
+ $annotation->setUserName( $this->fullname2( $r->firstname, $r->lastname
) );
+
+ if ( array_key_exists( 'sheet_type', $r ) )
+ $annotation->setSheet( $this->sheet_str( $r->sheet_type ) );
+ if ( array_key_exists( 'url', $r ) )
+ $annotation->setUrl( $r->url );
+ if ( array_key_exists( 'note', $r ) )
+ $annotation->setNote( $r->note );
+ if ( array_key_exists( 'quote', $r ) )
+ $annotation->setQuote( $r->quote );
+ if ( array_key_exists( 'quote_title', $r ) )
+ $annotation->setQuoteTitle( $r->quote_title );
+ if ( array_key_exists( 'quote_author_id', $r ) )
+ $annotation->setQuoteAuthorId( $r->quote_author_id );
+ elseif ( array_key_exists( 'quote_author', $r ) ) // to support old
mdl_annotation table
+ $annotation->setQuoteAuthorId( $r->quote_author );
+ if ( array_key_exists( 'quote_author_firstname', $r ) )
+ $annotation->setQuoteAuthorName( $this->fullname2(
$r->quote_author_firstname, $r->quote_author_lastname ) );
+ if ( array_key_exists( 'link', $r ) )
+ $annotation->setLink( $r->link );
+ if ( array_key_exists( 'link_title', $r ) )
+ $annotation->setLinkTitle( $r->link_title );
+ if ( array_key_exists( 'created', $r ) )
+ $annotation->setCreated( (int) $r->created );
+ if ( array_key_exists( 'modified', $r ) )
+ $annotation->setModified( (int) $r->modified );
+ if ( array_key_exists( 'lastread', $r ) )
+ $annotation->setLastRead( (int) $r->lastread );
+
+ $start_line = array_key_exists( 'start_line', $r ) ? $r->start_line : 0;
+ $end_line = array_key_exists( 'end_line', $r ) ? $r->end_line : 0;
+ // The second and subsequente lines of the test are to catch cases where
everything is blank,
+ // which can happen if the range is really old and uses the range field
+ if ( array_key_exists( 'start_block', $r ) && $r->start_block !== null
+ && ( ! array_key_exists( 'range', $r )
+ || ( $start_line || $end_line || $r->start_block || $r->end_block ||
$r->start_word || $r->end_word || $r->start_char || $r->end_char ) ) )
+ {
+ $range = new SequenceRange( );
+ $range->setStart( new SequencePoint( $r->start_block, $start_line,
$r->start_word, $r->start_char ) );
+ $range->setEnd( new SequencePoint( $r->end_block, $end_line,
$r->end_word, $r->end_char ) );
+ $annotation->setSequenceRange( $range );
+ }
+ // Older versions used a range string column. Check and translate that
field here:
+ else if ( array_key_exists( 'range', $r ) && $r->range !== null ) {
+ $range = new SequenceRange( );
+ $range->fromString( $r->range );
+ $annotation->setSequenceRange( $range );
+ }
+
+ if ( array_key_exists( 'start_xpath', $r ) && $r->start_xpath !== null
) {
+ $range = new XPathRange( );
+ $range->setStart( new XPathPoint( $r->start_xpath, $start_line,
$r->start_word, $r->start_char ) );
+ $range->setEnd( new XpathPoint( $r->end_xpath, $end_line, $r->end_word,
$r->end_char ) );
+ $annotation->setXPathRange( $range );
+ }
+
+ return $annotation;
+ }
+
+ function annotation_to_record( $annotation )
+ {
+ global $DB;
+
+ $record = new object();
+
+ $id = $annotation->getAnnotationId( );
+ if ( $id )
+ $record->id = $id;
+
+ // Map username to id #
+ $userid = $annotation->getUserId( );
+ $user = $DB->get_record( 'user', array( 'id' => (int) $userid ) );
+ $record->userid = $user ? $user->id : null;
+
+ $sheet = $annotation->getSheet( );
+ $record->sheet_type = $this->sheet_type( $sheet );
+
+ $record->url = addslashes( $annotation->getUrl( ) );
+ $record->note = addslashes( $annotation->getNote( ) );
+ $record->quote = addslashes( $annotation->getQuote( ) );
+ $record->quote_title = addslashes( $annotation->getQuoteTitle( ) );
+
+ // Map author username to id #
+ $userid = $annotation->getQuoteAuthorId( );
+ $user = $DB->get_record( 'user', array( 'id' => (int) $userid ) );
+ $record->quote_author_id = $user ? $user->id : null;
+
+ $record->link = addslashes( $annotation->getLink( ) );
+ $record->link_title = addslashes( $annotation->getLinkTitle( ) );
+ $record->created = $annotation->getCreated( );
+ $record->modified = $annotation->getModified( );
+
+ $sequenceRange = $annotation->getSequenceRange( );
+ $sequenceStart = $sequenceRange->getStart( );
+ $sequenceEnd = $sequenceRange->getEnd( );
+ $xpathRange = $annotation->getXPathRange( );
+ if ( null !== $xpathRange ) {
+ $xpathStart = $xpathRange->getStart( );
+ $xpathEnd = $xpathRange->getEnd( );
+ }
+
+ $record->start_block = addslashes( $sequenceStart->getPaddedPathStr( ) );
+ $record->start_xpath = null === $xpathRange ? null : addslashes(
$xpathStart->getPathStr( ) );
+ $record->start_line = $sequenceStart->getLines( );
+ $record->start_word = $sequenceStart->getWords( ) ?
$sequenceStart->getWords( ) : 0;
+ $record->start_char = $sequenceStart->getChars( );
+
+ $record->end_block = addslashes( $sequenceEnd->getPaddedPathStr( ) );
+ $record->end_xpath = null === $xpathRange ? null : addslashes(
$xpathEnd->getPathStr( ) );
+ $record->end_line = $sequenceEnd->getLines( );
+ $record->end_word = $sequenceEnd->getWords( ) ? $sequenceEnd->getWords(
) : 0;
+ $record->end_char = $sequenceEnd->getChars( );
+ return $record;
+ }
+
+ /**
+ * Get an annotations preference value; if the preference doesn't exist,
create it
+ * so that the Javascript client will have permission to set it later (to
prevent
+ * client creation of random preferences, only existing preferences can
be set)
+ */
+ public function get_pref( $name, $default )
+ {
+ $value = get_user_preferences( $name, null );
+ if ( null == $value ) {
+ $value = $default;
+ set_user_preference( $name, $default );
+ }
+ return $value;
+ }
+
+ /**
+ * Get the sheet whose annotations are to be shown
+ */
+ public function get_sheet( )
+ {
+ return $this->get_pref( AN_SHEET_PREF, 'public' );
+ }
+
+ public function get_show_annotations_pref( )
+ {
+ return $this->get_pref( AN_SHOWANNOTATIONS_PREF, 'false' );
+ }
+
+ /**
+ * Get JS for strings
+ */
+ public function strings_js( )
+ {
+ $mgr = get_string_manager( );
+ $strings = $mgr->load_component_strings( 'block_marginalia',
current_language( ) );
+ if ( ! $strings )
+ $strings = $mgr->load_component_strings( 'block_marginalia', 'en' );
+ $first = True;
+ $s = '';
+ foreach ( $strings as $key => $value )
+ {
+ if ( substr( $key, 0, 3 ) == 'js_' )
+ {
+ // IE will break if there's a trailing comma
+ if ( ! $first )
+ $s .= ",\n";
+ $s .= "'".str_replace('_', ' ', substr($key, 3))."': '".s($value)."'";
+ $first = False;
+ }
+ }
+ return "{\n$s\n}\n";
+ }
+
+ /**
+ * Marginalia init that must be done before head generation
+ */
+ public function emit_plugin_requires( )
+ {
+ foreach ( $this->plugins as $plugin )
+ $plugin->emit_requires( $this );
+ }
+
+ /**
+ * Initialize Marginalia on the page
+ * Emits the require_js to initialize Marginalia.
+ * If necessary, also creates relevant user preferences
+ * (necessary for Marginalia to function correctly).
+ */
+ public function emit_plugin_body( )
+ { }
+
+ /**
+ * Figure out whether annotation is permitted on a given page
+ * Should be refactored - same code is in annotate.php
+ * #geof# should go into a mia_page_profile
+ */
+ function can_annotate( $url )
+ {
+ global $USER;
+
+ if ( isguestuser() or ! isloggedin() )
+ return false;
+ $handler = annotation_summary_query::handler_for_url( $url );
+ if ( ! $handler )
+ return false;
+ $handler->fetch_metadata( );
+ if ( $handler->modulename && $handler->courseid )
+ {
+ $cm = get_coursemodule_from_instance( $handler->modulename,
$handler->modinstanceid, $handler->courseid);
+ if ( $cm )
+ {
+ $modcontext = get_context_instance( CONTEXT_MODULE, $cm->id );
+// if ( has_capability('moodle/legacy:guest', $context, $USER->id,
false ) )
+// return false;
+ if ( ! $handler->capannotate )
+ return false; // annotation of this resource is never permitted
+ else
+ return has_capability($handler->capannotate, $modcontext);
+ }
+ else
+ return false;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Deletes all annotations of a specific user
+ * This is here rather than in the annotation code so that not everything
will have to
+ * include the annotation code.
+ *
+ * @param int $userid
+ * @return boolean
+ */
+ function annotations_delete_user( $userid )
+ {
+ return delete_records( AN_DBTABLE, 'id', $userid );
+ }
+
+ /**
+ * Stub for calling Moodle log function
+ * This started breaking in Moodle 2.0. Frankly I don't see the need for
it,
+ * but I'll maintain calls to this stub instead of deleting them.
+ */
+ function moodle_log( $op, $url, $args=null )
+ {
+ //global $course
+ //add_to_log( $course->id, 'annotation', $op, $url, $args );
+ }
+}
+
+class marginalia_summary_lib
+{
+ /**
+ * Pass in a url with {first} where the first item number should go
+ */
+ static function show_result_pages( $first, $total, $perpage, $url )
+ {
+ // Show the list of result pages
+ if ( $perpage ) //0 => no list, because everything is shown
+ {
***The diff for this file has been truncated for email.***
=======================================
--- /moodle/trunk/moodle/blocks/marginalia/annotation_globals.php Wed May
30 14:29:48 2012
+++ /dev/null
@@ -1,213 +0,0 @@
-<?php
-
-// The smartquote icon symbol(s)
-define( 'AN_SMARTQUOTEICON', '\u275d' ); // \u275b\u275c: enclosed single
qs, 267a: recycle
-
-// The same thing as entities because - and this stuns the hell out of me
every
-// single time - PHP 5 *does not have native unicode support*!!! Geez
guys,
-// I remember reading about unicode in Byte Magazine in what, the 1980s?
-define( 'AN_SMARTQUOTEICON_HTML', '&#10077' ); //'&#10075;&#10076;' );
-
-// Icon for filtering on the summary page
-define( 'AN_FILTERICON_HTML', '&#9754;' ); //&#9756;
-
-define( 'ANNOTATION_STRINGS', 'block_marginalia' );
-
-define( 'AN_USER_PREF', 'annotations.user' );
-define( 'AN_SHOWANNOTATIONS_PREF', 'annotations.show' );
-define( 'AN_NOTEEDITMODE_PREF', 'annotations.note-edit-mode' );
-define( 'AN_SPLASH_PREF', 'annotations.splash' );
-define( 'SMARTCOPY_PREF', 'smartcopy' );
-
-define( 'AN_DBTABLE', 'marginalia' );
-
-define( 'AN_ACCESS_PRIVATE', 0 );
-define( 'AN_ACCESS_AUTHOR', 0x1 );
-define( 'AN_ACCESS_PUBLIC', 0xffff );
-
-// Object types
-define ( 'AN_OTYPE_POST', 1 );
-
-class annotation_globals
-{
- function get_host( )
- {
- global $CFG;
- $urlparts = parse_url( $CFG->wwwroot );
- return $urlparts[ 'host' ];
- }
-
- function get_service_path( )
- {
- global $CFG;
- return $CFG->wwwroot . ANNOTATION_PATH . '/annotate.php';
-// return annotation_globals::getMoodlePath( ) . ANNOTATE_SERVICE_PATH;
- }
-
- FUNCTION get_keyword_service_path( )
- {
- global $CFG;
- return $CFG->wwwroot . ANNOTATION_PATH . '/keywords.php';
- }
-
- /** Get the moodle path - that is, the path to moodle from the root of
the server. Typically this is 'moodle/'.
- * REQUEST_URI starts with this. */
- function get_moodle_path( )
- {
- global $CFG;
- $urlparts = parse_url( $CFG->wwwroot );
- return $urlparts[ 'path' ];
- }
-
- /**
- * Get the sever part of the moodle path.
- * This is the absolute path, with the getMoodlePath( ) portion chopped
off.
- * Useful, because appending a REQUEST_URI to it produces an absolute
URI. */
- function get_moodle_server( )
- {
- global $CFG;
- $urlparts = parse_url( $CFG->wwwroot );
- if ( $urlparts[ 'path' ] == '/' )
- return $CFG->wwwroot;
- else
- return substr( $CFG->wwwroot, 0, strpos( $CFG->wwwroot,
$urlparts[ 'path' ] ) );
- }
-
- function get_install_date( )
- {
- // Hardcoded because I'm not aware of Moodle recording an install date
anywhere
- return strtotime( '2005-07-20' );
- }
-
- function get_feed_tag_uri( )
- {
- return "tag:" . annotation_globals::get_host() . ',' . date( 'Y-m-d',
annotation_globals::get_install_date() ) . ":annotation";
- }
-
- /**
- * Remember: This the Annotation class does not store Moodle user IDs, so
- * you must be sure to query for username and quote_author_username if you
- * want userid and quoteAuthorId set.
- */
- function record_to_annotation( $r )
- {
- $annotation = new Annotation( );
-
- $annotation->setAnnotationId( $r->id );
-
- if ( array_key_exists( 'username', $r ) )
- $annotation->setUserId( $r->username );
- if ( array_key_exists( 'fullname', $r ) )
- $annotation->setUserName( $r->fullname );
-
- if ( array_key_exists( 'access_perms', $r ) )
- {
- if ( $r->access_perms & AN_ACCESS_PUBLIC )
- $annotation->setAccess( 'public' );
- else
- $annotation->setAccess( 'private' );
- }
- if ( array_key_exists( 'url', $r ) )
- $annotation->setUrl( $r->url );
- if ( array_key_exists( 'note', $r ) )
- $annotation->setNote( $r->note );
- if ( array_key_exists( 'quote', $r ) )
- $annotation->setQuote( $r->quote );
- if ( array_key_exists( 'quote_title', $r ) )
- $annotation->setQuoteTitle( $r->quote_title );
- if ( array_key_exists( 'quote_author_username', $r ) )
- $annotation->setQuoteAuthorId( $r->quote_author_username );
- elseif ( array_key_exists( 'quote_author', $r ) ) // to support old
mdl_annotation table
- $annotation->setQuoteAuthorId( $r->quote_author );
- if ( array_key_exists( 'quote_author_fullname', $r ) )
- $annotation->setQuoteAuthorName( $r->quote_author_fullname );
- if ( array_key_exists( 'link', $r ) )
- $annotation->setLink( $r->link );
- if ( array_key_exists( 'link_title', $r ) )
- $annotation->setLinkTitle( $r->link_title );
- if ( array_key_exists( 'created', $r ) )
- $annotation->setCreated( (int) $r->created );
- if ( array_key_exists( 'modified', $r ) )
- $annotation->setModified( (int) $r->modified );
-
- $start_line = array_key_exists( 'start_line', $r ) ? $r->start_line : 0;
- $end_line = array_key_exists( 'end_line', $r ) ? $r->end_line : 0;
- // The second and subsequente lines of the test are to catch cases where
everything is blank,
- // which can happen if the range is really old and uses the range field
- if ( array_key_exists( 'start_block', $r ) && $r->start_block !== null
- && ( ! array_key_exists( 'range', $r )
- || ( $start_line || $end_line || $r->start_block || $r->end_block ||
$r->start_word || $r->end_word || $r->start_char || $r->end_char ) ) )
- {
- $range = new SequenceRange( );
- $range->setStart( new SequencePoint( $r->start_block, $start_line,
$r->start_word, $r->start_char ) );
- $range->setEnd( new SequencePoint( $r->end_block, $end_line,
$r->end_word, $r->end_char ) );
- $annotation->setSequenceRange( $range );
- }
- // Older versions used a range string column. Check and translate that
field here:
- else if ( array_key_exists( 'range', $r ) && $r->range !== null ) {
- $range = new SequenceRange( );
- $range->fromString( $r->range );
- $annotation->setSequenceRange( $range );
- }
-
- if ( array_key_exists( 'start_xpath', $r ) && $r->start_xpath !== null
) {
- $range = new XPathRange( );
- $range->setStart( new XPathPoint( $r->start_xpath, $start_line,
$r->start_word, $r->start_char ) );
- $range->setEnd( new XpathPoint( $r->end_xpath, $end_line, $r->end_word,
$r->end_char ) );
- $annotation->setXPathRange( $range );
- }
-
- return $annotation;
- }
-
- function annotation_to_record( $annotation )
- {
- $id = $annotation->getAnnotationId( );
- if ( $id )
- $record->id = $id;
-
- // Map username to id #
- $username = $annotation->getUserId( );
- $user = get_record( 'user', 'username', $username );
- $record->userid = $user ? $user->id : null;
-
- $access = $annotation->getAccess( );
- $record->access_perms = 'public' == $access ? AN_ACCESS_PUBLIC :
AN_ACCESS_PRIVATE;
- $record->url = addslashes( $annotation->getUrl( ) );
- $record->note = addslashes( $annotation->getNote( ) );
- $record->quote = addslashes( $annotation->getQuote( ) );
- $record->quote_title = addslashes( $annotation->getQuoteTitle( ) );
-
- // Map author username to id #
- $username = $annotation->getQuoteAuthorId( );
- $user = get_record( 'user', 'username', $username );
- $record->quote_author_id = $user ? $user->id : null;
-
- $record->link = addslashes( $annotation->getLink( ) );
- $record->link_title = addslashes( $annotation->getLinkTitle( ) );
- $record->created = $annotation->getCreated( );
- $record->modified = $annotation->getModified( );
-
- $sequenceRange = $annotation->getSequenceRange( );
- $sequenceStart = $sequenceRange->getStart( );
- $sequenceEnd = $sequenceRange->getEnd( );
- $xpathRange = $annotation->getXPathRange( );
- if ( null !== $xpathRange ) {
- $xpathStart = $xpathRange->getStart( );
- $xpathEnd = $xpathRange->getEnd( );
- }
-
- $record->start_block = addslashes( $sequenceStart->getPaddedPathStr( ) );
- $record->start_xpath = null === $xpathRange ? null : addslashes(
$xpathStart->getPathStr( ) );
- $record->start_line = $sequenceStart->getLines( );
- $record->start_word = $sequenceStart->getWords( ) ?
$sequenceStart->getWords( ) : 0;
- $record->start_char = $sequenceStart->getChars( );
-
- $record->end_block = addslashes( $sequenceEnd->getPaddedPathStr( ) );
- $record->end_xpath = null === $xpathRange ? null : addslashes(
$xpathEnd->getPathStr( ) );
- $record->end_line = $sequenceEnd->getLines( );
- $record->end_word = $sequenceEnd->getWords( ) ? $sequenceEnd->getWords(
) : 0;
- $record->end_char = $sequenceEnd->getChars( );
- return $record;
- }
-}
=======================================
--- /moodle/trunk/moodle/blocks/marginalia/marginalia-strings.js Wed May 30
14:29:48 2012
+++ /dev/null
@@ -1,59 +0,0 @@
-
-/*
- * Languages for annotation Javascript
- */
-
-/*
- * Fetch a localized string
- * This is a function so that it can be replaced with another source of
strings if desired
- * (e.g. in a database). The application uses short English-language
strings as keys, so
- * that if the language source is lacking the key can be returned instead.
- */
-function getLocalized( s )
-{
- return LocalizedAnnotationStrings[ s ];
-}
-
-LocalizedAnnotationStrings = {
-
-
- 'public annotation' : 'This annotation is public.',
-
- 'private annotation' : 'This annotation is private.',
-
- 'delete annotation button' : 'Delete this annotation.',
-
- 'annotation link button' : 'Link to another document.',
-
- 'annotation link label' : 'Select a document to link to.',
-
- 'delete annotation link button' : 'Remove this link.',
-
- 'annotation expand edit button' : 'Click to display margin note editor',
-
- 'annotation collapse edit button' : 'Click to display margin note
drop-down list',
-
- 'annotation quote button' : 'Quote this annotation in a discussion post.',
-
-
-
- 'browser support of W3C range required for annotation creation' : 'Your
browser does not support the W3C range standard, so you cannot create
annotations.',
-
- 'select text to annotate' : 'You must select some text to annotate.',
-
- 'invalid selection' : 'Selection range is not valid.',
-
- 'corrupt XML from service' : 'An attempt to retrieve annotations from the
server returned corrupt XML data.',
-
- 'note too long' : 'Please limit your margin note to 250 characters.',
-
- 'quote too long' : 'The passage you have attempted to highlight is too
long. It may not exceed 1000 characters.',
-
- 'zero length quote' : 'You must select some text to annotate.',
-
- 'quote not found' : 'The highlighted passage could not be found',
-
- 'create overlapping edits' : 'You may not create overlapping edits',
-
- 'lang' : 'en'
-};
=======================================
--- /moodle/trunk/moodle/blocks/marginalia/tags.css Fri Dec 12 01:21:03 2008
+++ /dev/null
@@ -1,24 +0,0 @@
-ul#keywords {
- list-style-type: none;
- margin: 1em 2em;
- padding: 0;
-}
-
-ul#keywords li {
- display: inline;
- margin: 0;
- padding: 0;
-}
-
-ul#keywords li + li:before {
- content: ', ';
-}
-
-fieldset {
- margin: 3em 0;
- padding: 1em 1.5ex;
-}
-
-#replace-count-prompt {
- display: none;
-}
=======================================
--- /moodle/trunk/moodle/blocks/marginalia/tags.js Wed Mar 11 11:26:29 2009
+++ /dev/null
@@ -1,82 +0,0 @@
-function keywordsOnload( )
-{
-// var replaceButton = document.getElementById( 'replace' );
-
- window.keywordService = new RestKeywordService( serviceRoot
+ '/keywords.php', true );
- keywordService.init( annotationKeywords );
- refreshKeywords( );
-
- window.annotationService = new RestAnnotationService( serviceRoot
+ '/annotate.php', {
- csrfCookie: 'MoodleSessionTest' } );
-
- addEvent( '#replace input', 'change', _clearReplaceCount );
- addEvent( '#replace input', 'keypress', _keypressReplaceNote );
- addEvent( '#replace button', 'click', _replaceNotes );
-}
-
-function refreshKeywords( )
-{
- var list = document.getElementById( 'keywords' );
- var items = domutil.childrenByTagClass( list, 'li' );
- for ( var i = 0; i < items.length; ++i )
- list.removeChild( items[ i ] );
-
- keywordService.keywords.sort( compareKeywords );
- var keywords = keywordService.keywords;
- var keywordDisplay = document.getElementById( 'keyword-display' );
- keywordDisplay.style.display = keywords.length ? 'block' : 'none';
- for ( var i = 0; i < keywords.length; ++i )
- {
- var keyword = keywords[ i ];
- list.appendChild( domutil.element( 'li', {
- content: domutil.element( 'a', {
- href: summaryRoot + '&q=' + encodeURIComponent( keyword.name ),
- content: keyword.name } )
- } ) );
- }
-}
-
-function compareKeywords( k1, k2 )
-{
- if ( k1.name < k2.name )
- return -1;
- else if ( k1.name > k2.name )
- return 1;
- else
- return 0;
-}
-
-function _keypressReplaceNote( event )
-{
- if ( event.keyCode == 13 )
- {
- event.stopPropagation( );
- _replaceNotes( );
- return false;
- }
- return true;
-}
-
-function _clearReplaceCount( event )
-{
- var prompt = document.getElementById( 'replace-count-prompt' );
- prompt.style.display = 'none';
-}
-
-function _replaceNotes( event )
-{
- var oldNote = document.getElementById( 'old-note' );
- var newNote = document.getElementById( 'new-note' );
- f = function( t ) {
- var prompt = document.getElementById( 'replace-count-prompt' );
- prompt.style.display = 'block';
- var count = document.getElementById( 'replace-count' );
- while ( count.firstChild )
- count.removeChild( count.firstChild );
- count.appendChild( document.createTextNode( t ) );
- keywordService.refresh( refreshKeywords );
- }
- annotationService.bulkUpdate( oldNote.value, newNote.value, f );
-}
-
-
=======================================
--- /moodle/trunk/moodle/blocks/marginalia/tags.php Wed May 30 14:29:48 2012
+++ /dev/null
@@ -1,110 +0,0 @@
-<?php
-
- // summary.php
- // Part of Marginalia annotation for Moodle
- // See www.geof.net/code/annotation/ for full source and documentation.
-
- // Display a summary of all annotations for the current user
-
-require_once( "../../config.php" );
-require_once( 'config.php' );
-require_once( "marginalia-php/MarginaliaHelper.php" );
-require_once( 'marginalia-php/Keyword.php' );
-require_once( 'annotation_globals.php' );
-require_once( 'keywords_db.php' );
-
-global $CFG;
-
-if ($CFG->forcelogin) {
- require_login();
-}
-
-/*
-// Should probably add logging later
-if ($cm = get_coursemodule_from_instance("forum", $forum->id,
$course->id)) {
- add_to_log($course->id, "forum", "view
discussion", "discuss.php?$logparameters", "$discussion->id", $cm->id);
-} else {
- add_to_log($course->id, "forum", "view
discussion", "discuss.php?$logparameters", "$discussion->id");
-}
-
-// Should add preference saving if multiple display modes
-if ($mode) {
- set_user_preference("forum_displaymode", $mode);
-}
-
-$displaymode = get_user_preferences("forum_displaymode",
$CFG->forum_displaymode);
-*/
-
-$urlstring = $_SERVER[ 'REQUEST_URI' ];
-
-if ( $_SERVER[ 'REQUEST_METHOD' ] != 'GET') {
- header( 'HTTP/1.1 405 Method Not Allowed' );
- header( 'Allow: GET' );
-}
-else {
- $errorpage = array_key_exists( 'error', $_GET ) ? $_GET[ 'error' ] : null;
- $courseid = required_param( 'course' );
-
- if (! $course = get_record('course', 'id', $courseid ) )
- error("Course ID $courseid is incorrect - discussion is faulty");
-
- $keywords = annotation_keywords_db::list_keywords( $USER->id );
-
- $meta
- = "<link type='text/css' rel='stylesheet' href='tags.css'/>\n"
- . "<script language='JavaScript' type='text/javascript'
src='marginalia/3rd-party/cssQuery.js'></script>\n"
- . "<script language='JavaScript' type='text/javascript'
src='marginalia/3rd-party/cssQuery-standard.js'></script>\n"
- . "<script language='JavaScript' type='text/javascript'
src='marginalia/3rd-party.js'></script>\n"
- . "<script language='JavaScript' type='text/javascript'
src='marginalia/log.js'></script>\n"
- . "<script language='JavaScript' type='text/javascript'
src='marginalia-config.js'></script>\n"
- . "<script language='JavaScript' type='text/javascript'
src='marginalia/domutil.js'></script>\n"
- . "<script language='JavaScript' type='text/javascript'
src='marginalia/rest-annotate.js'></script>\n"
- . "<script language='JavaScript' type='text/javascript'
src='marginalia/rest-keywords.js'></script>\n"
- . "<script language='JavaScript' type='text/javascript'
src='tags.js'></script>\n"
- . "<script language='Javascript' type='text/javascript'>\n"
- . " var serviceRoot = '".s(ANNOTATION_PATH)."';\n"
- . " var summaryRoot
= 'summary.php?url=".urlencode($CFG->wwwroot.'/course/view.php?id='+$courseid)
- . "&u=".urlencode($USER->username)."&match=exact';\n"
- . " var annotationKeywords = [\n";
- if ( $keywords )
- {
- for ( $i = 0; $i < count( $keywords ); ++$i )
- {
- $keyword = $keywords[ $i ];
- if ( $i > 0 )
- $meta .= ", ";
- $meta .= "new
Keyword('".htmlspecialchars($keyword->name)."', '".htmlspecialchars($keyword->description)."')\n";
- }
- }
- $meta .= "];\n"
- . "addEvent( window, 'load', keywordsOnload );\n"
- . "</script>";
-
- $navtail = get_string( 'edit_keywords_title', ANNOTATION_STRINGS );
- print_header( "$course->shortname: " . get_string( 'edit_keywords_title',
ANNOTATION_STRINGS ),
- $course->fullname, "$navtail", "", $meta, true, "", null);
-
-
- echo "<div id='keyword-display'>\n";
- echo '<p>'.htmlspecialchars(get_string( 'tag_list_prompt',
ANNOTATION_STRINGS ))."</p>\n";
- echo "<ul id='keywords'>\n";
- echo "</ul>\n";
- echo "</div>\n";
-
- echo "<fieldset id='replace'>\n";
- echo "
<legend>".get_string('note_replace_legend',ANNOTATION_STRINGS)."</legend>\n";
- echo " <label
for='old-note'>".get_string('note_replace_old',ANNOTATION_STRINGS).":</label><input
id='old-note' type='text'/>\n";
- echo " <label
for='new-note'>".get_string('note_replace_new',ANNOTATION_STRINGS).":</label><input
id='new-note' type='text'/>\n";
- echo "
<button>".get_string('note_replace_button',ANNOTATION_STRINGS)."</button>\n";
- echo " <p
id='replace-count-prompt'>".get_string('note_update_count',ANNOTATION_STRINGS)."<span
id='replace-count'/></p>\n";
- echo "</fieldset>\n";
-
- print_footer(null);
-
- $logurl = $_SERVER[ 'REQUEST_URI' ];
- $urlparts = parse_url( $logurl );
- $logurl = array_key_exists( 'query', $urlparts ) ? $urlparts[ 'query' ] :
null;
- add_to_log( null, 'annotation', 'summary', 'edit-keywords.php' );
-}
-
-?>
=======================================
--- /moodle/trunk/moodle/help.php Wed Dec 10 16:07:53 2008
+++ /dev/null
@@ -1,216 +0,0 @@
-<?php
-/**
- * help.php - Displays help page.
- *
- * Prints a very simple page and includes
- * page content or a string from elsewhere.
- * Usually this will appear in a popup
- * See {@link helpbutton()} in {@link lib/moodlelib.php}
- *
- * @author Martin Dougiamas
- * @version $Id: help.php,v 1.40.2.3 2008/01/19 21:57:13 mudrd8mz Exp $
- * @package moodlecore
- */
-require_once('config.php');
-
-// Get URL parameters.
-$file = optional_param('file', '', PARAM_PATH);
-$text = optional_param('text', 'No text to display', PARAM_CLEAN);
-$module = optional_param('module', 'moodle', PARAM_ALPHAEXT);
-$forcelang = optional_param('forcelang', '', PARAM_SAFEDIR);
-$skiplocal = optional_param('skiplocal', 0, PARAM_INT); // shall
_local help files be skipped?
-
-// Start the output.
-print_header(get_string('help'));
-print_simple_box_start();
-
-// We look for the help to display in lots of different places, and
-// only display an error at the end if we can't find the help file
-// anywhere. This variable tracks that.
-$helpfound = false;
-
-if (!empty($file)) {
- // The help to display is from a help file.
-
- // Get the list of parent languages.
- if (empty($forcelang)) {
- $langs = array(current_language(),
get_string('parentlanguage'), 'en_utf8'); // Fallback
- } else {
- $langs = array($forcelang, 'en_utf8');
- }
-
- if (!$skiplocal) {
- // _local language packs take precedence with both forced language
and non-forced language settings
- $xlangs = array();
- foreach ($langs as $lang) {
- if (!empty($lang)) {
- $xlangs[] = $lang . '_local';
- $xlangs[] = $lang;
- }
- }
- $langs = $xlangs;
- unset($xlangs);
- }
-
-// Define possible locations for help file similar to locations for
language strings
-// Note: Always retain module directory as before
- $locations = array();
- if ($module == 'moodle') {
- $locations[$CFG->dataroot.'/lang/'] = $file;
- $locations[$CFG->dirroot.'/lang/'] = $file;
- $locations[$CFG->dirroot.'/local/lang/'] = $file;
- } else {
- $modfile = $module.'/'.$file;
- $locations[$CFG->dataroot.'/lang/'] = $modfile;
- $locations[$CFG->dirroot.'/lang/'] = $modfile;
- $locations[$CFG->dirroot.'/local/lang/'] = $modfile;
-
- $rules = places_to_search_for_lang_strings();
- $exceptions = $rules['__exceptions'];
- unset($rules['__exceptions']);
-
- if (!in_array($module, $exceptions)) {
- $dividerpos = strpos($module, '_');
- if ($dividerpos === false) {
- $type = '';
- $plugin = $module;
- } else {
- $type = substr($module, 0, $dividerpos + 1);
- $plugin = substr($module, $dividerpos + 1);
- }
- if (!empty($rules[$type])) {
- foreach ($rules[$type] as $location) {
- $locations[$CFG->dirroot . "/$location/$plugin/lang/"]
= "$plugin/$file";
- }
- }
- }
- }
-
- // Work through the possible languages, starting with the most
specific.
- while (!$helpfound && (list(,$lang) = each($langs)) && !empty($lang)) {
-
- while (!$helpfound && (list($locationprefix,$locationsuffix) =
each($locations))) {
- $filepath = $locationprefix.$lang.'/help/'.$locationsuffix;
-
- // Now, try to include the help text from this file, if we can.
- if (file_exists_and_readable($filepath)) {
- $helpfound = true;
- @include($filepath); // The actual helpfile
-
- // Now, we process some special cases.
- $helpdir = $locationprefix.$lang.'/help';
- if ($module == 'moodle' and ($file == 'index.html' or
$file == 'mods.html')) {
- include_help_for_each_module($file, $langs, $helpdir);
- }
-
- // The remaining horrible hardcoded special cases should
be delegated to modules somehow.
- if ($module == 'moodle' and ($file
== 'resource/types.html')) { // RESOURCES
- include_help_for_each_resource($file, $langs,
$helpdir);
- }
- if ($module == 'moodle' and ($file
== 'assignment/types.html')) { // ASSIGNMENTS
- include_help_for_each_assignment_type();
- }
- }
- }
- reset($locations);
- }
-} else {
- // The help to display was given as an argument to this function.
- echo '<p>'.s($text).'</p>'; // This param was already cleaned
- $helpfound = true;
-}
-
-print_simple_box_end();
-
-// Display an error if necessary.
-if (!$helpfound) {
- notify('Help file "'. $file .'" could not be found!');
-}
-
-// End of page.
-close_window_button();
-echo '<p class="helpindex"><a href="help.php?file=index.html">'.
get_string('helpindex') .'</a></p>';
-
-$CFG->docroot = ''; // We don't want a doc link here
-print_footer('none');
-
-// Utility function
=================================================================
-
-function file_exists_and_readable($filepath) {
- return file_exists($filepath) and is_file($filepath) and
is_readable($filepath);
-}
-
-// Some functions for handling special cases
========================================
-
-function include_help_for_each_module($file, $langs, $helpdir) {
- global $CFG;
-
- if (!$modules = get_records('modules', 'visible', 1)) {
- error('No modules found!!'); // Should never happen
- }
-
- foreach ($modules as $mod) {
- $strmodulename = get_string('modulename', $mod->name);
- $modulebyname[$strmodulename] = $mod;
- }
- ksort($modulebyname, SORT_LOCALE_STRING);
-
- foreach ($modulebyname as $mod) {
- foreach ($langs as $lang) {
- if (empty($lang)) {
- continue;
- }
-
- $filepath = "$helpdir/$mod->name/$file";
-
- // If that does not exist, try a fallback into the module code
folder.
- if (!file_exists($filepath)) {
- $filepath
= "$CFG->dirroot/mod/$mod->name/lang/$lang/help/$mod->name/$file";
- }
-
- if (file_exists_and_readable($filepath)) {
- echo '<hr />';
- @include($filepath); // The actual helpfile
- break; // Out of loop over languages.
- }
- }
- }
-}
-
-function include_help_for_each_resource($file, $langs, $helpdir) {
- global $CFG;
-
- require_once($CFG->dirroot .'/mod/resource/lib.php');
- $typelist = resource_get_types();
- $typelist['label'] = get_string('resourcetypelabel', 'resource');
-
- foreach ($typelist as $type => $name) {
- foreach ($langs as $lang) {
- if (empty($lang)) {
- continue;
- }
-
- $filepath = "$helpdir/resource/type/$type.html";
-
- if (file_exists_and_readable($filepath)) {
- echo '<hr size="1" />';
- @include($filepath); // The actual helpfile
- break; // Out of loop over languages.
- }
- }
- }
-}
-
-function include_help_for_each_assignment_type() {
- global $CFG;
-
- require_once($CFG->dirroot .'/mod/assignment/lib.php');
- $typelist = assignment_types();
-
- foreach ($typelist as $type => $name) {
- echo '<p><b>'.$name.'</b></p>';
- echo get_string('help'.$type, 'assignment');
- echo '<hr size="1" />';
- }
-}
-?>
=======================================
--- /moodle/trunk/LICENSE.txt Thu Aug 9 16:29:32 2007
+++ /moodle/trunk/LICENSE.txt Wed May 30 15:12:10 2012
@@ -1,281 +1,675 @@
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
- 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.) You can apply it to
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
your programs, too.

When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.

For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.

The precise terms and conditions for copying, distribution and
modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange;
or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
this License.

- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free
Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show
w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or
school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
+
=======================================
--- /moodle/trunk/moodle/mod/forum/discuss.php Thu Jun 3 14:44:55 2010
+++ /moodle/trunk/moodle/mod/forum/discuss.php Wed May 30 15:12:10 2012
@@ -1,7 +1,28 @@
-<?php // $Id$
-
-// Displays a post, and all the posts below it.
-// If no post is given, displays all posts in a discussion
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Displays a post, and all the posts below it.
+ * If no post is given, displays all posts in a discussion
+ *
+ * @package mod-forum
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */

require_once('../../config.php');

@@ -12,47 +33,42 @@
$mark = optional_param('mark', '', PARAM_ALPHA); // Used for
tracking read posts if user initiated.
$postid = optional_param('postid', 0, PARAM_INT); // Used for
tracking read posts if user initiated.

- if (!$discussion = get_record('forum_discussions', 'id', $d)) {
- error("Discussion ID was incorrect or no longer exists");
- }
-
- if (!$course = get_record('course', 'id', $discussion->course)) {
- error("Course ID is incorrect - discussion is faulty");
- }
-
- if (!$forum = get_record('forum', 'id', $discussion->forum)) {
- notify("Bad forum ID stored in this discussion");
- }
-
- if (!$cm = get_coursemodule_from_instance('forum', $forum->id,
$course->id)) {
- error('Course Module ID was incorrect');
- }
+ $url = new moodle_url('/mod/forum/discuss.php', array('d'=>$d));
+ if ($parent !== 0) {
+ $url->param('parent', $parent);
+ }
+ $PAGE->set_url($url);
+
+ $discussion = $DB->get_record('forum_discussions', array('id' =>
$d), '*', MUST_EXIST);
+ $course = $DB->get_record('course', array('id' =>
$discussion->course), '*', MUST_EXIST);
+ $forum = $DB->get_record('forum', array('id' =>
$discussion->forum), '*', MUST_EXIST);
+ $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id,
false, MUST_EXIST);

require_course_login($course, true, $cm);

/// Add ajax-related libs
-
require_js(array('yui_yahoo', 'yui_event', 'yui_dom', 'yui_connection', 'yui_json'));
- require_js($CFG->wwwroot . '/mod/forum/rate_ajax.js');
+ $PAGE->requires->yui2_lib('event');
+ $PAGE->requires->yui2_lib('connection');
+ $PAGE->requires->yui2_lib('json');

// move this down fix for MDL-6926
- require_once('lib.php');
-
- // #geof# #marginalia begin
- require_js( array( 'yui_datasource' ) );
- require_once( $CFG->dirroot.'/blocks/marginalia/config.php' );
- require_once( ANNOTATION_DIR.'/marginalia-php/embed.php' );
- require_once( ANNOTATION_DIR.'/annotation_summary_query.php' );
- require_once( ANNOTATION_DIR.'/lib.php' );
- // #geof# #marginalia end
+ require_once($CFG->dirroot.'/mod/forum/lib.php');

$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/forum:viewdiscussion', $modcontext, NULL,
true, 'noviewdiscussionspermission', 'forum');

+ if (!empty($CFG->enablerssfeeds) && !empty($CFG->forum_enablerssfeeds)
&& $forum->rsstype && $forum->rssarticles) {
+ require_once("$CFG->libdir/rsslib.php");
+
+ $rsstitle = format_string($course->shortname, true,
array('context' => get_context_instance(CONTEXT_COURSE,
$course->id))) . ': %fullname%';
+ rss_add_http_header($modcontext, 'mod_forum', $forum, $rsstitle);
+ }
+
if ($forum->type == 'news') {
if (!($USER->id == $discussion->userid || (($discussion->timestart
== 0
|| $discussion->timestart <= time())
&& ($discussion->timeend == 0 || $discussion->timeend >
time())))) {
- error('Discussion ID was incorrect or no longer
exists', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
+
print_error('invaliddiscussionid', 'forum', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
}
}

@@ -63,51 +79,51 @@
require_capability('mod/forum:movediscussions', $modcontext);

if ($forum->type == 'single') {
- error('Cannot move discussion from a simple single discussion
forum', $return);
+ print_error('cannotmovefromsingleforum', 'forum', $return);
}

- if (!$forumto = get_record('forum', 'id', $move)) {
- error('You can\'t move to that forum - it doesn\'t exist!',
$return);
+ if (!$forumto = $DB->get_record('forum', array('id' => $move))) {
+ print_error('cannotmovetonotexist', 'forum', $return);
+ }
+
+ if ($forumto->type == 'single') {
+ print_error('cannotmovetosingleforum', 'forum', $return);
}

if (!$cmto = get_coursemodule_from_instance('forum', $forumto->id,
$course->id)) {
- error('Target forum not found in this course.', $return);
+ print_error('cannotmovetonotfound', 'forum', $return);
}

if (!coursemodule_visible_for_user($cmto)) {
- error('Forum not visible', $return);
+ print_error('cannotmovenotvisible', 'forum', $return);
}

- require_capability('mod/forum:startdiscussion',
- get_context_instance(CONTEXT_MODULE,$cmto->id));
-
- if (!forum_move_attachments($discussion, $forumto->id)) {
- notify("Errors occurred while moving attachment directories -
check your file permissions");
- }
- set_field('forum_discussions', 'forum', $forumto->id, 'id',
$discussion->id);
- set_field('forum_read', 'forumid', $forumto->id, 'discussionid',
$discussion->id);
+ require_capability('mod/forum:startdiscussion',
get_context_instance(CONTEXT_MODULE,$cmto->id));
+
+ if (!forum_move_attachments($discussion, $forum->id,
$forumto->id)) {
+ echo $OUTPUT->notification("Errors occurred while moving
attachment directories - check your file permissions");
+ }
+ $DB->set_field('forum_discussions', 'forum', $forumto->id,
array('id' => $discussion->id));
+ $DB->set_field('forum_read', 'forumid', $forumto->id,
array('discussionid' => $discussion->id));
add_to_log($course->id, 'forum', 'move
discussion', "discuss.php?d=$discussion->id", $discussion->id, $cmto->id);

require_once($CFG->libdir.'/rsslib.php');
- require_once('rsslib.php');
-
- // Delete the RSS files for the 2 forums because we want to force
- // the regeneration of the feeds since the discussions have been
- // moved.
- if (!forum_rss_delete_file($forum) |
| !forum_rss_delete_file($forumto)) {
- error('Could not purge the cached RSS feeds for the source
and/or'.
- 'destination forum(s) - check your file
permissionsforums', $return);
- }
-
- redirect($return.'&amp;moved=-1&amp;sesskey='.sesskey());
+ require_once($CFG->dirroot.'/mod/forum/rsslib.php');
+
+ // Delete the RSS files for the 2 forums to force regeneration of
the feeds
+ forum_rss_delete_file($forum);
+ forum_rss_delete_file($forumto);
+
+ redirect($return.'&moved=-1&sesskey='.sesskey());
}

- $logparameters = "d=$discussion->id";
- if ($parent) {
- $logparameters .= "&amp;parent=$parent";
- }
-
- add_to_log($course->id, 'forum', 'view
discussion', "discuss.php?$logparameters", $discussion->id, $cm->id);
+ // #marginalia begin
+ $moodlemia = moodle_marginalia::get_instance( );
+ $miaprofile = $moodlemia->get_profile( $PAGE->url->out(false) );
+ $miaprofile->emit_requires( $moodlemia );
+ // #marginalia end
+
+ add_to_log($course->id, 'forum', 'view
discussion', "discuss.php?d=$discussion->id", $discussion->id, $cm->id);

unset($SESSION->fromdiscussion);

@@ -127,12 +143,12 @@
}

if (! $post = forum_get_post_full($parent)) {
- error("Discussion no longer
exists", "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
+
print_error("notexists", 'forum', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
}


if (!forum_user_can_view_post($post, $course, $cm, $forum,
$discussion)) {
- error('You do not have permissions to view this
post', "$CFG->wwwroot/mod/forum/view.php?id=$forum->id");
+
print_error('nopermissiontoview', 'forum', "$CFG->wwwroot/mod/forum/view.php?id=$forum->id");
}

if ($mark == 'read' or $mark == 'unread') {
@@ -148,117 +164,134 @@

$searchform = forum_search_form($course);

- $navlinks = array();
- $navlinks[] = array('name' => format_string($discussion->name), 'link'
=> "discuss.php?d=$discussion->id", 'type' => 'title');
- if ($parent != $discussion->firstpost) {
- $navlinks[] = array('name' =>
format_string($post->subject), 'type' => 'title');
+ $forumnode = $PAGE->navigation->find($cm->id,
navigation_node::TYPE_ACTIVITY);
+ if (empty($forumnode)) {
+ $forumnode = $PAGE->navbar;
+ } else {
+ $forumnode->make_active();
+ }
+ $node = $forumnode->add(format_string($discussion->name), new
moodle_url('/mod/forum/discuss.php', array('d'=>$discussion->id)));
+ $node->display = false;
+ if ($node && $post->id != $discussion->firstpost) {
+ $node->add(format_string($post->subject), $PAGE->url);
}

- // #marginalia begin
- // Begin Annotation Code to set $meta
- $marginalia = moodle_marginalia::get_instance( );
- $meta = $marginalia->header_html( );
- // I'm perverting the meta argument here, but I can't figure out how
otherwise
- // to emit a stylesheet link. #geof#
- // #marginalia end
-
- $navigation = build_navigation($navlinks, $cm);
- print_header("$course->shortname: ".format_string($discussion->name),
$course->fullname,
- $navigation, "", $meta, true, $searchform,
navmenu($course, $cm)); // #marginalia
-
- // #marginalia begin
- // relative URL to this resource from the server root (should start
with '/')
- $refurl = "/mod/forum/discuss.php?d=$d";
- echo $marginalia->init_html( $refurl );
- // #marginalia end
+
$PAGE->set_title("$course->shortname: ".format_string($discussion->name));
+ $PAGE->set_heading($course->fullname);
+ $PAGE->set_button($searchform);
+ echo $OUTPUT->header();

/// Check to see if groups are being used in this forum
/// If so, make sure the current person is allowed to see this discussion
/// Also, if we know they should be able to reply, then explicitly set
$canreply for performance reasons

- if (isguestuser() or !isloggedin() or
has_capability('moodle/legacy:guest', $modcontext, NULL, false)) {
- // allow guests and not-logged-in to see the link - they are
prompted to log in after clicking the link
- $canreply = ($forum->type != 'news'); // no reply in news forums
-
- } else {
- $canreply = forum_user_can_post($forum, $discussion, $USER, $cm,
$course, $modcontext);
+ $canreply = forum_user_can_post($forum, $discussion, $USER, $cm,
$course, $modcontext);
+ if (!$canreply and $forum->type !== 'news') {
+ if (isguestuser() or !isloggedin()) {
+ $canreply = true;
+ }
+ if (!is_enrolled($modcontext) and !is_viewing($modcontext)) {
+ // allow guests and not-logged-in to see the link - they are
prompted to log in after clicking the link
+ // normal users with temporary guest access see this link too,
they are asked to enrol instead
+ $canreply = enrol_selfenrol_available($course->id);
+ }
}

/// Print the controls across the top
-
- echo '<table width="100%" class="discussioncontrols"><tr><td>';
+ echo '<div class="discussioncontrols clearfix">';
+
+ if (!empty($CFG->enableportfolios) &&
has_capability('mod/forum:exportdiscussion', $modcontext)) {
+ require_once($CFG->libdir.'/portfoliolib.php');
+ $button = new portfolio_add_button();
+ $button->set_callback_options('forum_portfolio_caller',
array('discussionid' => $discussion->id), '/mod/forum/locallib.php');
+ $button = $button->to_html(PORTFOLIO_ADD_FULL_FORM,
get_string('exportdiscussion', 'mod_forum'));
+ $buttonextraclass = '';
+ if (empty($button)) {
+ // no portfolio plugin available.
+ $button = '&nbsp;';
+ $buttonextraclass = ' noavailable';
+ }
+ echo html_writer::tag('div', $button, array('class'
=> 'discussioncontrol exporttoportfolio'.$buttonextraclass));
+ } else {
+ echo html_writer::tag('div', '&nbsp;',
array('class'=>'discussioncontrol nullcontrol'));
+ }

// groups selector not needed here
-
- echo "</td><td>";
+ echo '<div class="discussioncontrol displaymode">';
forum_print_mode_form($discussion->id, $displaymode);
- echo "</td><td>";
+ echo "</div>";

if ($forum->type != 'single'
&& has_capability('mod/forum:movediscussions',
$modcontext)) {

+ echo '<div class="discussioncontrol movediscussion">';
// Popup menu to move discussions to other forums. The discussion
in a
// single discussion forum can't be moved.
$modinfo = get_fast_modinfo($course);
if (isset($modinfo->instances['forum'])) {
- if ($course->format == 'weeks') {
- $strsection = get_string("week");
- } else {
- $strsection = get_string("topic");
- }
- $section = -1;
$forummenu = array();
+ $sections = get_all_sections($course->id);
+ // Check forum types and eliminate simple discussions.
+ $forumcheck = $DB->get_records('forum', array('course' =>
$course->id),'', 'id, type');
foreach ($modinfo->instances['forum'] as $forumcm) {
if (!$forumcm->uservisible |
| !has_capability('mod/forum:startdiscussion',
get_context_instance(CONTEXT_MODULE,$forumcm->id))) {
continue;
}
-
- if (!empty($forumcm->sectionnum) and $section !=
$forumcm->sectionnum) {
- $forummenu[] = "-------------- $strsection
$forumcm->sectionnum --------------";
- }
$section = $forumcm->sectionnum;
- if ($forumcm->instance != $forum->id) {
- $url
= "discuss.php?d=$discussion->id&amp;move=$forumcm->instance&amp;sesskey=".sesskey();
- $forummenu[$url] = format_string($forumcm->name);
+ $sectionname = get_section_name($course,
$sections[$section]);
+ if (empty($forummenu[$section])) {
+ $forummenu[$section] = array($sectionname => array());
+ }
+ $forumidcompare = $forumcm->instance != $forum->id;
+ $forumtypecheck =
$forumcheck[$forumcm->instance]->type !== 'single';
+ if ($forumidcompare and $forumtypecheck) {
+ $url
= "/mod/forum/discuss.php?d=$discussion->id&move=$forumcm->instance&sesskey=".sesskey();
+ $forummenu[$section][$sectionname][$url] =
format_string($forumcm->name);
}
}
if (!empty($forummenu)) {
- echo "<div style=\"float:right;\">";
- echo popup_form("$CFG->wwwroot/mod/forum/",
$forummenu, "forummenu", "",
-
get_string("movethisdiscussionto", "forum"), "", "", true,'self','',NULL,
- get_string('move'));
+ echo '<div class="movediscussionoption">';
+ $select = new url_select($forummenu, '',
+
array(''=>get_string("movethisdiscussionto", "forum")),
+ 'forummenu', get_string('move'));
+ echo $OUTPUT->render($select);
echo "</div>";
}
}
- }
+ echo "</div>";
+ }
+
// #marginalia begin
- // Annotation controls (help, user dropdown, link to summary page)
- echo "</td>\n<td id='annotation-controls'>";
- $marginalia->show_header_controls( 'forum', $refurl, $USER );
+ // *not* putting JS last, even though that might speed up page load:
+ // more important to minimize patch footprint
+ $miaprofile->emit_body( $moodlemia );
+ $miaprofile->emit_margin_controls( $moodlemia );
// #marginalia end
- echo "</td></tr></table>";
+
+ echo '<div class="clearfloat">&nbsp;</div>';
+ echo "</div>";

if (!empty($forum->blockafter) && !empty($forum->blockperiod)) {
- $a = new object();
+ $a = new stdClass();
$a->blockafter = $forum->blockafter;
$a->blockperiod = get_string('secondstotime'.$forum->blockperiod);
- notify(get_string('thisforumisthrottled','forum',$a));
+ echo
$OUTPUT->notification(get_string('thisforumisthrottled','forum',$a));
}

if ($forum->type == 'qanda'
&& !has_capability('mod/forum:viewqandawithoutposting', $modcontext) &&
!forum_user_has_posted($forum->id,$discussion->id,$USER->id))
{
- notify(get_string('qandanotify','forum'));
+ echo $OUTPUT->notification(get_string('qandanotify','forum'));
}

if ($move == -1 and confirm_sesskey()) {
- notify(get_string('discussionmoved', 'forum',
format_string($forum->name,true)));
+ echo $OUTPUT->notification(get_string('discussionmoved', 'forum',
format_string($forum->name,true)));
}

$canrate = has_capability('mod/forum:rate', $modcontext);
forum_print_discussion($course, $cm, $forum, $discussion, $post,
$displaymode, $canreply, $canrate);

- print_footer($course);
+ echo $OUTPUT->footer();


-?>
+
=======================================
--- /moodle/trunk/moodle/mod/forum/lib.php Thu Jun 3 14:44:55 2010
+++ /moodle/trunk/moodle/mod/forum/lib.php Wed May 30 15:12:10 2012
@@ -1,9 +1,37 @@
-<?php // $Id$
-
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @package mod
+ * @subpackage forum
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/** Include required files */
require_once($CFG->libdir.'/filelib.php');
+require_once($CFG->libdir.'/eventslib.php');
+require_once($CFG->dirroot.'/user/selector/lib.php');
+
// #marginalia begin
+// including this here ensures it is also included for discuss.php
+// and post.php without having to patch them also
require_once( $CFG->dirroot.'/blocks/marginalia/config.php' );
-require_once( ANNOTATION_DIR.'/marginalia-php/marginalia-constants.php' );
require_once( ANNOTATION_DIR.'/lib.php' );
// #marginalia end

@@ -14,6 +42,7 @@
define('FORUM_MODE_THREADED', 2);
define('FORUM_MODE_NESTED', 3);

+define('FORUM_CHOOSESUBSCRIBE', 0);
define('FORUM_FORCESUBSCRIBE', 1);
define('FORUM_INITIALSUBSCRIBE', 2);
define('FORUM_DISALLOWSUBSCRIBE',3);
@@ -22,27 +51,21 @@
define('FORUM_TRACKING_OPTIONAL', 1);
define('FORUM_TRACKING_ON', 2);

-define('FORUM_UNSET_POST_RATING', -999);
-
-define ('FORUM_AGGREGATE_NONE', 0); //no ratings
-define ('FORUM_AGGREGATE_AVG', 1);
-define ('FORUM_AGGREGATE_COUNT', 2);
-define ('FORUM_AGGREGATE_MAX', 3);
-define ('FORUM_AGGREGATE_MIN', 4);
-define ('FORUM_AGGREGATE_SUM', 5);
-
/// STANDARD FUNCTIONS
///////////////////////////////////////////////////////////

/**
* Given an object containing all the necessary data,
- * (defined by the form in mod.html) this function
+ * (defined by the form in mod_form.php) this function
* will create a new instance and return the id number
* of the new instance.
+ *
+ * @global object
+ * @global object
* @param object $forum add forum instance (with magic quotes)
* @return int intance id
*/
-function forum_add_instance($forum) {
- global $CFG;
+function forum_add_instance($forum, $mform) {
+ global $CFG, $DB;

$forum->timemodified = time();

@@ -55,23 +78,32 @@
$forum->assesstimefinish = 0;
}

- if (!$forum->id = insert_record('forum', $forum)) {
- return false;
- }
+ $forum->id = $DB->insert_record('forum', $forum);
+ $modcontext = get_context_instance(CONTEXT_MODULE,
$forum->coursemodule);

if ($forum->type == 'single') { // Create related discussion.
- $discussion = new object();
- $discussion->course = $forum->course;
- $discussion->forum = $forum->id;
- $discussion->name = $forum->name;
- $discussion->intro = $forum->intro;
- $discussion->assessed = $forum->assessed;
- $discussion->format = $forum->type;
- $discussion->mailnow = false;
- $discussion->groupid = -1;
-
- if (! forum_add_discussion($discussion, $discussion->intro)) {
- error('Could not add the discussion for this forum');
+ $discussion = new stdClass();
+ $discussion->course = $forum->course;
+ $discussion->forum = $forum->id;
+ $discussion->name = $forum->name;
+ $discussion->assessed = $forum->assessed;
+ $discussion->message = $forum->intro;
+ $discussion->messageformat = $forum->introformat;
+ $discussion->messagetrust =
trusttext_trusted(get_context_instance(CONTEXT_COURSE, $forum->course));
+ $discussion->mailnow = false;
+ $discussion->groupid = -1;
+
+ $message = '';
+
+ $discussion->id = forum_add_discussion($discussion, null,
$message);
+
+ if ($mform and $draftid =
file_get_submitted_draft_itemid('introeditor')) {
+ // ugly hack - we need to copy the files somehow
+ $discussion = $DB->get_record('forum_discussions',
array('id'=>$discussion->id), '*', MUST_EXIST);
+ $post = $DB->get_record('forum_posts',
array('id'=>$discussion->firstpost), '*', MUST_EXIST);
+
+ $post->message = file_save_draft_area_files($draftid,
$modcontext->id, 'mod_forum', 'post', $post->id, array('subdirs'=>true),
$post->message);
+ $DB->set_field('forum_posts', 'message', $post->message,
array('id'=>$post->id));
}
}

@@ -82,13 +114,12 @@
/// stage. However, because the forum is brand new, we know that there
are
/// no role assignments or overrides in the forum context, so using the
/// course context gives the same list of users.
- $users =
forum_get_potential_subscribers(get_context_instance(CONTEXT_COURSE,
$forum->course), 0, 'u.id, u.email', '');
+ $users = forum_get_potential_subscribers($modcontext, 0, 'u.id,
u.email', '');
foreach ($users as $user) {
forum_subscribe($user->id, $forum->id);
}
}

- $forum = stripslashes_recursive($forum);
forum_grade_item_update($forum);

return $forum->id;
@@ -97,13 +128,15 @@

/**
* Given an object containing all the necessary data,
- * (defined by the form in mod.html) this function
+ * (defined by the form in mod_form.php) this function
* will update an existing instance with new data.
+ *
+ * @global object
* @param object $forum forum instance (with magic quotes)
* @return bool success
*/
-function forum_update_instance($forum) {
- global $USER;
+function forum_update_instance($forum, $mform) {
+ global $DB, $OUTPUT, $USER;

$forum->timemodified = time();
$forum->id = $forum->instance;
@@ -117,7 +150,7 @@
$forum->assesstimefinish = 0;
}

- $oldforum = get_record('forum', 'id', $forum->id);
+ $oldforum = $DB->get_record('forum', array('id'=>$forum->id));

// MDL-3942 - if the aggregation type or scale (i.e. max grade)
changes then recalculate the grades for the entire forum
// if scale changes - do we need to recheck the ratings, if ratings
higher than scale how do we want to respond?
@@ -127,55 +160,62 @@
}

if ($forum->type == 'single') { // Update related discussion and post.
- if (! $discussion = get_record('forum_discussions', 'forum',
$forum->id)) {
- if ($discussions = get_records('forum_discussions', 'forum',
$forum->id, 'timemodified ASC')) {
- notify('Warning! There is more than one discussion in this
forum - using the most recent');
- $discussion = array_pop($discussions);
- } else {
- // try to recover by creating initial discussion -
MDL-16262
- $discussion = new object();
- $discussion->course = $forum->course;
- $discussion->forum = $forum->id;
- $discussion->name = $forum->name;
- $discussion->intro = $forum->intro;
- $discussion->assessed = $forum->assessed;
- $discussion->format = $forum->type;
- $discussion->mailnow = false;
- $discussion->groupid = -1;
-
- forum_add_discussion($discussion, $discussion->intro);
-
- if (! $discussion =
get_record('forum_discussions', 'forum', $forum->id)) {
- error('Could not add the discussion for this forum');
- }
-
+ $discussions = $DB->get_records('forum_discussions',
array('forum'=>$forum->id), 'timemodified ASC');
+ if (!empty($discussions)) {
+ if (count($discussions) > 1) {
+ echo
$OUTPUT->notification(get_string('warnformorepost', 'forum'));
+ }
+ $discussion = array_pop($discussions);
+ } else {
+ // try to recover by creating initial discussion - MDL-16262
+ $discussion = new stdClass();
+ $discussion->course = $forum->course;
+ $discussion->forum = $forum->id;
+ $discussion->name = $forum->name;
+ $discussion->assessed = $forum->assessed;
+ $discussion->message = $forum->intro;
+ $discussion->messageformat = $forum->introformat;
+ $discussion->messagetrust = true;
+ $discussion->mailnow = false;
+ $discussion->groupid = -1;
+
+ $message = '';
+
+ forum_add_discussion($discussion, null, $message);
+
+ if (! $discussion = $DB->get_record('forum_discussions',
array('forum'=>$forum->id))) {
+ print_error('cannotadd', 'forum');
}
}
- if (! $post = get_record('forum_posts', 'id',
$discussion->firstpost)) {
- error('Could not find the first post in this forum
discussion');
+ if (! $post = $DB->get_record('forum_posts',
array('id'=>$discussion->firstpost))) {
+ print_error('cannotfindfirstpost', 'forum');
}

- $post->subject = $forum->name;
- $post->message = $forum->intro;
- $post->modified = $forum->timemodified;
- $post->userid = $USER->id; // MDL-18599, so that current
teacher can take ownership of activities
-
- if (! update_record('forum_posts', ($post))) {
- error('Could not update the first post');
+ $cm = get_coursemodule_from_instance('forum', $forum->id);
+ $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id,
MUST_EXIST);
+
+ if ($mform and $draftid =
file_get_submitted_draft_itemid('introeditor')) {
+ // ugly hack - we need to copy the files somehow
+ $discussion = $DB->get_record('forum_discussions',
array('id'=>$discussion->id), '*', MUST_EXIST);
+ $post = $DB->get_record('forum_posts',
array('id'=>$discussion->firstpost), '*', MUST_EXIST);
+
+ $post->message = file_save_draft_area_files($draftid,
$modcontext->id, 'mod_forum', 'post', $post->id, array('subdirs'=>true),
$post->message);
}

- $discussion->name = $forum->name;
-
- if (! update_record('forum_discussions', ($discussion))) {
- error('Could not update the discussion');
- }
+ $post->subject = $forum->name;
+ $post->message = $forum->intro;
+ $post->messageformat = $forum->introformat;
+ $post->messagetrust = trusttext_trusted($modcontext);
+ $post->modified = $forum->timemodified;
+ $post->userid = $USER->id; // MDL-18599, so that current
teacher can take ownership of activities
+
+ $DB->update_record('forum_posts', $post);
+ $discussion->name = $forum->name;
+ $DB->update_record('forum_discussions', $discussion);
}

- if (!update_record('forum', $forum)) {
- error('Can not update forum');
- }
-
- $forum = stripslashes_recursive($forum);
+ $DB->update_record('forum', $forum);
+
forum_grade_item_update($forum);

return true;
@@ -186,32 +226,47 @@
* Given an ID of an instance of this module,
* this function will permanently delete the instance
* and any data that depends on it.
- * @param int forum instance id
+ *
+ * @global object
+ * @param int $id forum instance id
* @return bool success
*/
function forum_delete_instance($id) {
-
- if (!$forum = get_record('forum', 'id', $id)) {
+ global $DB;
+
+ if (!$forum = $DB->get_record('forum', array('id'=>$id))) {
return false;
}
+ if (!$cm = get_coursemodule_from_instance('forum', $forum->id)) {
+ return false;
+ }
+ if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
+ return false;
+ }
+
+ $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+
+ // now get rid of all files
+ $fs = get_file_storage();
+ $fs->delete_area_files($context->id);

$result = true;

- if ($discussions = get_records('forum_discussions', 'forum',
$forum->id)) {
+ if ($discussions = $DB->get_records('forum_discussions',
array('forum'=>$forum->id))) {
foreach ($discussions as $discussion) {
- if (!forum_delete_discussion($discussion, true)) {
+ if (!forum_delete_discussion($discussion, true, $course, $cm,
$forum)) {
$result = false;
}
}
}

- if (!delete_records('forum_subscriptions', 'forum', $forum->id)) {
+ if (!$DB->delete_records('forum_subscriptions',
array('forum'=>$forum->id))) {
$result = false;
}

forum_tp_delete_read_records(-1, -1, -1, $forum->id);

- if (!delete_records('forum', 'id', $forum->id)) {
+ if (!$DB->delete_records('forum', array('id'=>$forum->id))) {
$result = false;
}

@@ -219,18 +274,122 @@

return $result;
}
+
+
+/**
+ * Indicates API features that the forum supports.
+ *
+ * @uses FEATURE_GROUPS
+ * @uses FEATURE_GROUPINGS
+ * @uses FEATURE_GROUPMEMBERSONLY
+ * @uses FEATURE_MOD_INTRO
+ * @uses FEATURE_COMPLETION_TRACKS_VIEWS
+ * @uses FEATURE_COMPLETION_HAS_RULES
+ * @uses FEATURE_GRADE_HAS_GRADE
+ * @uses FEATURE_GRADE_OUTCOMES
+ * @param string $feature
+ * @return mixed True if yes (some features may use other values)
+ */
+function forum_supports($feature) {
+ switch($feature) {
+ case FEATURE_GROUPS: return true;
+ case FEATURE_GROUPINGS: return true;
+ case FEATURE_GROUPMEMBERSONLY: return true;
+ case FEATURE_MOD_INTRO: return true;
+ case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
+ case FEATURE_COMPLETION_HAS_RULES: return true;
+ case FEATURE_GRADE_HAS_GRADE: return true;
+ case FEATURE_GRADE_OUTCOMES: return true;
+ case FEATURE_RATE: return true;
+ case FEATURE_BACKUP_MOODLE2: return true;
+ case FEATURE_SHOW_DESCRIPTION: return true;
+
+ default: return null;
+ }
+}
+
+
+/**
+ * Obtains the automatic completion state for this forum based on any
conditions
+ * in forum settings.
+ *
+ * @global object
+ * @global object
+ * @param object $course Course
+ * @param object $cm Course-module
+ * @param int $userid User ID
+ * @param bool $type Type of comparison (or/and; can be used as return
value if no conditions)
+ * @return bool True if completed, false if not. (If no conditions, then
return
+ * value depends on comparison type)
+ */
+function forum_get_completion_state($course,$cm,$userid,$type) {
+ global $CFG,$DB;
+
+ // Get forum details
+ if (!($forum=$DB->get_record('forum',array('id'=>$cm->instance)))) {
+ throw new Exception("Can't find forum {$cm->instance}");
+ }
+
+ $result=$type; // Default return value
+
+ $postcountparams=array('userid'=>$userid,'forumid'=>$forum->id);
+ $postcountsql="
+SELECT
+ COUNT(1)
+FROM
+ {forum_posts} fp
+ INNER JOIN {forum_discussions} fd ON fp.discussion=fd.id
+WHERE
+ fp.userid=:userid AND fd.forum=:forumid";
+
+ if ($forum->completiondiscussions) {
+ $value = $forum->completiondiscussions <=
+
$DB->count_records('forum_discussions',array('forum'=>$forum->id,'userid'=>$userid));
+ if ($type == COMPLETION_AND) {
+ $result = $result && $value;
+ } else {
+ $result = $result || $value;
+ }
+ }
+ if ($forum->completionreplies) {
+ $value = $forum->completionreplies <=
+ $DB->get_field_sql( $postcountsql.' AND
fp.parent<>0',$postcountparams);
+ if ($type==COMPLETION_AND) {
+ $result = $result && $value;
+ } else {
+ $result = $result || $value;
+ }
+ }
+ if ($forum->completionposts) {
+ $value = $forum->completionposts <=
$DB->get_field_sql($postcountsql,$postcountparams);
+ if ($type == COMPLETION_AND) {
+ $result = $result && $value;
+ } else {
+ $result = $result || $value;
+ }
+ }
+
+ return $result;
+}


/**
* Function to be run periodically according to the moodle cron
* Finds all posts that have yet to be mailed out, and mails them
* out to all subscribers
+ *
+ * @global object
+ * @global object
+ * @global object
+ * @uses CONTEXT_MODULE
+ * @uses CONTEXT_COURSE
+ * @uses SITEID
+ * @uses FORMAT_PLAIN
* @return void
*/
function forum_cron() {
- global $CFG, $USER;
-
- $cronuser = clone($USER);
+ global $CFG, $USER, $DB;
+
$site = get_site();

// all users that are subscribed to any post that needs sending
@@ -271,7 +430,7 @@

$discussionid = $post->discussion;
if (!isset($discussions[$discussionid])) {
- if ($discussion = get_record('forum_discussions', 'id',
$post->discussion)) {
+ if ($discussion = $DB->get_record('forum_discussions',
array('id'=> $post->discussion))) {
$discussions[$discussionid] = $discussion;
} else {
mtrace('Could not find discussion '.$discussionid);
@@ -281,7 +440,7 @@
}
$forumid = $discussions[$discussionid]->forum;
if (!isset($forums[$forumid])) {
- if ($forum = get_record('forum', 'id', $forumid)) {
+ if ($forum = $DB->get_record('forum', array('id' =>
$forumid))) {
$forums[$forumid] = $forum;
} else {
mtrace('Could not find forum '.$forumid);
@@ -291,7 +450,7 @@
}
$courseid = $forums[$forumid]->course;
if (!isset($courses[$courseid])) {
- if ($course = get_record('course', 'id', $courseid)) {
+ if ($course = $DB->get_record('course', array('id' =>
$courseid))) {
$courses[$courseid] = $course;
} else {
mtrace('Could not find course '.$courseid);
@@ -303,7 +462,7 @@
if ($cm = get_coursemodule_from_instance('forum',
$forumid, $courseid)) {
$coursemodules[$forumid] = $cm;
} else {
- mtrace('Could not course module for forum '.$forumid);
+ mtrace('Could not find course module for
forum '.$forumid);
unset($posts[$pid]);
continue;
}
@@ -313,15 +472,9 @@
// caching subscribed users of each forum
if (!isset($subscribedusers[$forumid])) {
$modcontext = get_context_instance(CONTEXT_MODULE,
$coursemodules[$forumid]->id);
- if ($subusers =
forum_subscribed_users($courses[$courseid], $forums[$forumid], 0,
$modcontext)) {
+ if ($subusers =
forum_subscribed_users($courses[$courseid], $forums[$forumid], 0,
$modcontext, "u.*")) {
foreach ($subusers as $postuser) {
- // do not try to mail users with stopped email
- if ($postuser->emailstop) {
- if (!empty($CFG->forum_logblocked)) {
- add_to_log(SITEID, 'forum', 'mail
blocked', '', '', 0, $postuser->id);
- }
- continue;
- }
+ unset($postuser->description); // not necessary
// this user is subscribed to this forum
$subscribedusers[$forumid][$postuser->id] =
$postuser->id;
// this user is a user we have to process later
@@ -346,7 +499,7 @@
@set_time_limit(120); // terminate if processing of any
account takes longer than 2 minutes

// set this so that the capabilities are cached, and
environment matches receiving user
- $USER = $userto;
+ cron_setup_user($userto);

mtrace('Processing user '.$userto->id);

@@ -354,11 +507,10 @@
$userto->viewfullnames = array();
$userto->canpost = array();
$userto->markposts = array();
- $userto->enrolledin = array();

// reset the caches
foreach ($coursemodules as $forumid=>$unused) {
- $coursemodules[$forumid]->cache = new object();
+ $coursemodules[$forumid]->cache = new stdClass();
$coursemodules[$forumid]->cache->caps = array();
unset($coursemodules[$forumid]->uservisible);
}
@@ -372,31 +524,33 @@
$cm =& $coursemodules[$forum->id];

// Do some checks to see if we can bail out now
+ // Only active enrolled users are in the list of
subscribers
if (!isset($subscribedusers[$forum->id][$userto->id])) {
continue; // user does not subscribe to this forum
}

- // Verify user is enrollend in course - if not do not send
any email
- if (!isset($userto->enrolledin[$course->id])) {
- $userto->enrolledin[$course->id] =
has_capability('moodle/course:view', get_context_instance(CONTEXT_COURSE,
$course->id));
- }
- if (!$userto->enrolledin[$course->id]) {
- // oops - this user should not receive anything from
this course
+ // Don't send email if the forum is Q&A and the user has
not posted
+ // Initial topics are still mailed
+ if ($forum->type == 'qanda'
&& !forum_get_user_posted_time($discussion->id, $userto->id) && $pid !=
$discussion->firstpost) {
+ mtrace('Did not email '.$userto->id.' because user has
not posted in discussion');
continue;
}

// Get info about the sending user
if (array_key_exists($post->userid, $users)) { // we might
know him/her already
$userfrom = $users[$post->userid];
- } else if ($userfrom = get_record('user', 'id',
$post->userid)) {
+ } else if ($userfrom = $DB->get_record('user', array('id'
=> $post->userid))) {
+ unset($userfrom->description); // not necessary
$users[$userfrom->id] = $userfrom; // fetch only once,
we can add it to user list, it will be skipped anyway
} else {
mtrace('Could not find user '.$post->userid);
continue;
}
+
+ //if we want to check that userto and userfrom are not the
same person this is probably the spot to do it

// setup global $COURSE properly - needed for roles and
languages
- course_setup($course); // More environment
+ cron_setup_user($userto, $course);

// Fill caches
if (!isset($userto->viewfullnames[$forum->id])) {
@@ -439,14 +593,12 @@
// Does the user want this post in a digest? If so
postpone it for now.
if ($userto->maildigest > 0) {
// This user wants the mails to be in digest form
- $queue = new object();
+ $queue = new stdClass();
$queue->userid = $userto->id;
$queue->discussionid = $discussion->id;
$queue->postid = $post->id;
$queue->timemodified = $post->created;
- if (!insert_record('forum_queue', $queue)) {
- mtrace("Error: mod/forum/cron.php: Could not queue
for digest mail for id $post->id to user $userto->id ($userto->email) ..
not trying again.");
- }
+ $DB->insert_record('forum_queue', $queue);
continue;
}

@@ -460,30 +612,53 @@
'List-Id: "'.$cleanforumname.'"
<moodleforum'.$forum->id.'@'.$hostname.'>',
'List-Help: '.$CFG->wwwroot.'/mod/forum/view.php?f='.$forum->id,
'Message-ID:
<moodlepost'.$post->id.'@'.$hostname.'>',
- 'In-Reply-To:
<moodlepost'.$post->parent.'@'.$hostname.'>',
- 'References:
<moodlepost'.$post->parent.'@'.$hostname.'>',
'X-Course-Id: '.$course->id,
'X-Course-Name: '.format_string($course->fullname,
true)
);

-
- $postsubject
= "$course->shortname: ".format_string($post->subject,true);
- $posttext = forum_make_mail_text($course, $forum,
$discussion, $post, $userfrom, $userto);
- $posthtml = forum_make_mail_html($course, $forum,
$discussion, $post, $userfrom, $userto);
+ if ($post->parent) { // This post is a reply, so add
headers for threading (see MDL-22551)
+ $userfrom->customheaders[] = 'In-Reply-To:
<moodlepost'.$post->parent.'@'.$hostname.'>';
+ $userfrom->customheaders[] = 'References:
<moodlepost'.$post->parent.'@'.$hostname.'>';
+ }
+
+ $shortname = format_string($course->shortname, true,
array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+
+ $postsubject
= "$shortname: ".format_string($post->subject,true);
+ $posttext = forum_make_mail_text($course, $cm, $forum,
$discussion, $post, $userfrom, $userto);
+ $posthtml = forum_make_mail_html($course, $cm, $forum,
$discussion, $post, $userfrom, $userto);

// Send the post now!

mtrace('Sending ', '');

- if (!$mailresult = email_to_user($userto, $userfrom,
$postsubject, $posttext,
- $posthtml, '', '',
$CFG->forum_replytouser)) {
- mtrace("Error: mod/forum/cron.php: Could not send out
mail for id $post->id to user $userto->id".
+ $eventdata = new stdClass();
+ $eventdata->component = 'mod_forum';
+ $eventdata->name = 'posts';
+ $eventdata->userfrom = $userfrom;
+ $eventdata->userto = $userto;
+ $eventdata->subject = $postsubject;
+ $eventdata->fullmessage = $posttext;
+ $eventdata->fullmessageformat = FORMAT_PLAIN;
+ $eventdata->fullmessagehtml = $posthtml;
+ $eventdata->notification = 1;
+
+ $smallmessagestrings = new stdClass();
+ $smallmessagestrings->user = fullname($userfrom);
+ $smallmessagestrings->forumname
= "$shortname: ".format_string($forum->name,true).": ".$discussion->name;
+ $smallmessagestrings->message = $post->message;
+ //make sure strings are in message recipients language
+ $eventdata->smallmessage =
get_string_manager()->get_string('smallmessage', 'forum',
$smallmessagestrings, $userto->lang);
+
+ $eventdata->contexturl
= "{$CFG->wwwroot}/mod/forum/discuss.php?d={$discussion->id}#p{$post->id}";
+ $eventdata->contexturlname = $discussion->name;
+
+ $mailresult = message_send($eventdata);
+ if (!$mailresult){
+ mtrace("Error: mod/forum/lib.php forum_cron(): Could
not send out mail for id $post->id to user $userto->id".
" ($userto->email) .. not trying again.");
add_to_log($course->id, 'forum', 'mail
error', "discuss.php?d=$discussion->id#p$post->id",

substr(format_string($post->subject,true),0,30), $cm->id, $userto->id);
$errorcount[$post->id]++;
- } else if ($mailresult === 'emailstop') {
- // should not be reached anymore - see check above
} else {
$mailcount[$post->id]++;

@@ -505,7 +680,7 @@
foreach ($posts as $post) {
mtrace($mailcount[$post->id]." users were sent post
$post->id, '$post->subject'");
if ($errorcount[$post->id]) {
- set_field("forum_posts", "mailed", "2", "id", "$post->id");
+ $DB->set_field("forum_posts", "mailed", "2", array("id"
=> "$post->id"));
}
}
}
@@ -515,8 +690,7 @@
unset($mailcount);
unset($errorcount);

- $USER = clone($cronuser);
- course_setup(SITEID);
+ cron_setup_user();

$sitetimezone = $CFG->timezone;

@@ -535,16 +709,16 @@

// Delete any really old ones (normally there shouldn't be any)
$weekago = $timenow - (7 * 24 * 3600);
- delete_records_select('forum_queue', "timemodified < $weekago");
+ $DB->delete_records_select('forum_queue', "timemodified < ?",
array($weekago));
mtrace ('Cleaned old digest records');

if ($CFG->digestmailtimelast < $digesttime and $timenow > $digesttime)
{

mtrace('Sending forum digests: '.userdate($timenow, '',
$sitetimezone));

- $digestposts_rs =
get_recordset_select('forum_queue', "timemodified < $digesttime");
-
- if (!rs_EOF($digestposts_rs)) {
+ $digestposts_rs =
$DB->get_recordset_select('forum_queue', "timemodified < ?",
array($digesttime));
+
+ if ($digestposts_rs->valid()) {

// We have work to do
$usermailcount = 0;
@@ -553,24 +727,18 @@
$discussionposts = array();
$userdiscussions = array();

- while ($digestpost = rs_fetch_next_record($digestposts_rs)) {
+ foreach ($digestposts_rs as $digestpost) {
if (!isset($users[$digestpost->userid])) {
- if ($user = get_record('user', 'id',
$digestpost->userid)) {
+ if ($user = $DB->get_record('user', array('id' =>
$digestpost->userid))) {
$users[$digestpost->userid] = $user;
} else {
continue;
}
}
$postuser = $users[$digestpost->userid];
- if ($postuser->emailstop) {
- if (!empty($CFG->forum_logblocked)) {
- add_to_log(SITEID, 'forum', 'mail
blocked', '', '', 0, $postuser->id);
- }
- continue;
- }

if (!isset($posts[$digestpost->postid])) {
- if ($post = get_record('forum_posts', 'id',
$digestpost->postid)) {
+ if ($post = $DB->get_record('forum_posts', array('id'
=> $digestpost->postid))) {
$posts[$digestpost->postid] = $post;
} else {
continue;
@@ -578,7 +746,7 @@
}
$discussionid = $digestpost->discussionid;
if (!isset($discussions[$discussionid])) {
- if ($discussion =
get_record('forum_discussions', 'id', $discussionid)) {
+ if ($discussion = $DB->get_record('forum_discussions',
array('id' => $discussionid))) {
$discussions[$discussionid] = $discussion;
} else {
continue;
@@ -586,7 +754,7 @@
}
$forumid = $discussions[$discussionid]->forum;
if (!isset($forums[$forumid])) {
- if ($forum = get_record('forum', 'id', $forumid)) {
+ if ($forum = $DB->get_record('forum', array('id' =>
$forumid))) {
$forums[$forumid] = $forum;
} else {
continue;
@@ -595,7 +763,7 @@

$courseid = $forums[$forumid]->course;
if (!isset($courses[$courseid])) {
- if ($course = get_record('course', 'id', $courseid)) {
+ if ($course = $DB->get_record('course', array('id' =>
$courseid))) {
$courses[$courseid] = $course;
} else {
continue;
@@ -612,26 +780,24 @@

$userdiscussions[$digestpost->userid][$digestpost->discussionid] =
$digestpost->discussionid;

$discussionposts[$digestpost->discussionid][$digestpost->postid] =
$digestpost->postid;
}
- rs_close($digestposts_rs); /// Finished iteration, let's close
the resultset
+ $digestposts_rs->close(); /// Finished iteration, let's close
the resultset

// Data collected, start sending out emails to each user
foreach ($userdiscussions as $userid => $thesediscussions) {

@set_time_limit(120); // terminate if processing of any
account takes longer than 2 minutes

- $USER = $cronuser;
- course_setup(SITEID); // reset cron user language, theme
and timezone settings
+ cron_setup_user();

mtrace(get_string('processingdigest', 'forum',
$userid), '... ');

// First of all delete all the queue entries for this user
- delete_records_select('forum_queue', "userid = $userid AND
timemodified < $digesttime");
+ $DB->delete_records_select('forum_queue', "userid = ? AND
timemodified < ?", array($userid, $digesttime));
$userto = $users[$userid];

// Override the language and timezone of the "current"
user, so that
// mail is customised for the receiver.
- $USER = $userto;
- course_setup(SITEID);
+ cron_setup_user($userto);

// init caches
$userto->viewfullnames = array();
@@ -640,7 +806,7 @@

$postsubject = get_string('digestmailsubject', 'forum',
format_string($site->shortname, true));

- $headerdata = new object();
+ $headerdata = new stdClass();
$headerdata->sitename = format_string($site->fullname,
true);
$headerdata->userprefs =
$CFG->wwwroot.'/user/edit.php?id='.$userid.'&amp;course='.$site->id;

@@ -648,9 +814,10 @@
$headerdata->userprefs = '<a target="_blank"
href="'.$headerdata->userprefs.'">'.get_string('digestmailprefs', 'forum').'</a>';

$posthtml = "<head>";
- foreach ($CFG->stylesheets as $stylesheet) {
+/* foreach ($CFG->stylesheets as $stylesheet) {
+ //TODO: MDL-21120
$posthtml .= '<link rel="stylesheet" type="text/css"
href="'.$stylesheet.'" />'."\n";
- }
+ }*/
$posthtml .= "</head>\n<body id=\"email\">\n";
$posthtml .= '<p>'.get_string('digestmailheader', 'forum',
$headerdata).'</p><br /><hr size="1" noshade="noshade" />';

@@ -664,7 +831,7 @@
$cm = $coursemodules[$forum->id];

//override language
- course_setup($course);
+ cron_setup_user($userto, $course);

// Fill caches
if (!isset($userto->viewfullnames[$forum->id])) {
@@ -679,18 +846,19 @@
$strforums = get_string('forums', 'forum');
$canunsubscribe = ! forum_is_forcesubscribed($forum);
$canreply = $userto->canpost[$discussion->id];
+ $shortname = format_string($course->shortname, true,
array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));

$posttext .= "\n \n";

$posttext .= '=====================================================================';
$posttext .= "\n \n";
- $posttext .= "$course->shortname -> $strforums
-> ".format_string($forum->name,true);
+ $posttext .= "$shortname -> $strforums
-> ".format_string($forum->name,true);
if ($discussion->name != $forum->name) {
$posttext .= "
-> ".format_string($discussion->name,true);
}
$posttext .= "\n";

$posthtml .= "<p><font face=\"sans-serif\">".
- "<a target=\"_blank\"
href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>
-> ".
+ "<a target=\"_blank\"
href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$shortname</a> -> ".
"<a target=\"_blank\"
href=\"$CFG->wwwroot/mod/forum/index.php?id=$course->id\">$strforums</a>
-> ".
"<a target=\"_blank\"
href=\"$CFG->wwwroot/mod/forum/view.php?f=$forum->id\">".format_string($forum->name,true)."</a>";
if ($discussion->name == $forum->name) {
@@ -708,7 +876,7 @@

if (array_key_exists($post->userid, $users)) { //
we might know him/her already
$userfrom = $users[$post->userid];
- } else if ($userfrom = get_record('user', 'id',
$post->userid)) {
+ } else if ($userfrom = $DB->get_record('user',
array('id' => $post->userid))) {
$users[$userfrom->id] = $userfrom; // fetch
only once, we can add it to user list, it will be skipped anyway
} else {
mtrace('Could not find user '.$post->userid);
@@ -728,7 +896,7 @@

if ($userto->maildigest == 2) {
// Subjects only
- $by = new object();
+ $by = new stdClass();
$by->name = fullname($userfrom);
$by->date = userdate($post->modified);

$posttext .= "\n".format_string($post->subject,true).' '.get_string("bynameondate", "forum",
$by);
@@ -739,8 +907,8 @@

} else {
// The full treatment
- $posttext .= forum_make_mail_text($course,
$forum, $discussion, $post, $userfrom, $userto, true);
- $posthtml .= forum_make_mail_post($course,
$forum, $discussion, $post, $userfrom, $userto, false, $canreply, true,
false);
+ $posttext .= forum_make_mail_text($course,
$cm, $forum, $discussion, $post, $userfrom, $userto, true);
+ $posthtml .= forum_make_mail_post($course,
$cm, $forum, $discussion, $post, $userfrom, $userto, false, $canreply,
true, false);

// Create an array of postid's for this user to
mark as read.
if (!$CFG->forum_usermarksread) {
@@ -757,18 +925,20 @@
}
$posthtml .= '</body>';

- if ($userto->mailformat != 1) {
+ if (empty($userto->mailformat) || $userto->mailformat !=
1) {
// This user DOESN'T want to receive HTML
$posthtml = '';
}

- if (!$mailresult = email_to_user($userto,
$site->shortname, $postsubject, $posttext, $posthtml,
- '', '',
$CFG->forum_replytouser)) {
+ $attachment = $attachname='';
+ $usetrueaddress = true;
+ //directly email forum digests rather than sending them
via messaging
+ $mailresult = email_to_user($userto, $site->shortname,
$postsubject, $posttext, $posthtml, $attachment, $attachname,
$usetrueaddress, $CFG->forum_replytouser);
+
+ if (!$mailresult) {
mtrace("ERROR!");
echo "Error: mod/forum/cron.php: Could not send out
digest mail to user $userto->id ($userto->email)... not trying again.\n";
add_to_log($course->id, 'forum', 'mail digest
error', '', '', $cm->id, $userto->id);
- } else if ($mailresult === 'emailstop') {
- // should not happen anymore - see check above
} else {
mtrace("success.");
$usermailcount++;
@@ -782,8 +952,7 @@
set_config('digestmailtimelast', $timenow);
}

- $USER = $cronuser;
- course_setup(SITEID); // reset cron user language, theme and timezone
settings
+ cron_setup_user();

if (!empty($usermailcount)) {
mtrace(get_string('digestsentusers', 'forum', $usermailcount));
@@ -807,7 +976,11 @@
/**
* Builds and returns the body of the email notification in plain text.
*
+ * @global object
+ * @global object
+ * @uses CONTEXT_MODULE
* @param object $course
+ * @param object $cm
* @param object $forum
* @param object $discussion
* @param object $post
@@ -816,21 +989,18 @@
* @param boolean $bare
* @return string The email body in plain text format.
*/
-function forum_make_mail_text($course, $forum, $discussion, $post,
$userfrom, $userto, $bare = false) {
+function forum_make_mail_text($course, $cm, $forum, $discussion, $post,
$userfrom, $userto, $bare = false) {
global $CFG, $USER;

+ $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+
if (!isset($userto->viewfullnames[$forum->id])) {
- if (!$cm = get_coursemodule_from_instance('forum', $forum->id,
$course->id)) {
- error('Course Module ID was incorrect');
- }
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
$viewfullnames = has_capability('moodle/site:viewfullnames',
$modcontext, $userto->id);
} else {
$viewfullnames = $userto->viewfullnames[$forum->id];
}

if (!isset($userto->canpost[$discussion->id])) {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
$canreply = forum_user_can_post($forum, $discussion, $userto, $cm,
$course, $modcontext);
} else {
$canreply = $userto->canpost[$discussion->id];
@@ -849,12 +1019,16 @@
$posttext = '';

if (!$bare) {
- $posttext = "$course->shortname -> $strforums
-> ".format_string($forum->name,true);
+ $shortname = format_string($course->shortname, true,
array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+ $posttext = "$shortname -> $strforums
-> ".format_string($forum->name,true);

if ($discussion->name != $forum->name) {
$posttext .= " -> ".format_string($discussion->name,true);
}
}
+
+ // add absolute file links
+ $post->message =
file_rewrite_pluginfile_urls($post->message, 'pluginfile.php',
$modcontext->id, 'mod_forum', 'post', $post->id);


$posttext .= "\n---------------------------------------------------------------------\n";
$posttext .= format_string($post->subject,true);
@@ -863,16 +1037,13 @@
}
$posttext .= "\n".$strbynameondate."\n";

$posttext .= "---------------------------------------------------------------------\n";
- $posttext .= format_text_email(trusttext_strip($post->message),
$post->format);
+ $posttext .= format_text_email($post->message, $post->messageformat);
$posttext .= "\n\n";
- if ($post->attachment) {
- $post->course = $course->id;
- $post->forum = $forum->id;
- $posttext .= forum_print_attachments($post, "text");
- }
+ $posttext .= forum_print_attachments($post, $cm, "text");
+
if (!$bare && $canreply) {

$posttext .= "---------------------------------------------------------------------\n";
- $posttext .= get_string("postmailinfo", "forum",
$course->shortname)."\n";
+ $posttext .= get_string("postmailinfo", "forum", $shortname)."\n";
$posttext .= "$CFG->wwwroot/mod/forum/post.php?reply=$post->id\n";
}
if (!$bare && $canunsubscribe) {
@@ -887,7 +1058,9 @@
/**
* Builds and returns the body of the email notification in html format.
*
+ * @global object
* @param object $course
+ * @param object $cm
* @param object $forum
* @param object $discussion
* @param object $post
@@ -895,7 +1068,7 @@
* @param object $userto
* @return string The email text in HTML format
*/
-function forum_make_mail_html($course, $forum, $discussion, $post,
$userfrom, $userto) {
+function forum_make_mail_html($course, $cm, $forum, $discussion, $post,
$userfrom, $userto) {
global $CFG;

if ($userto->mailformat != 1) { // Needs to be HTML
@@ -903,23 +1076,25 @@
***The diff for this file has been truncated for email.***
=======================================
--- /moodle/trunk/moodle/mod/forum/post.php Thu Jun 3 22:40:10 2010
+++ /moodle/trunk/moodle/mod/forum/post.php Wed May 30 15:12:10 2012
@@ -1,859 +1,893 @@
-<?php // $Id: post.php,v 1.154.2.18 2009/10/13 20:53:57 skodak Exp $
-
-// Edit and save a new post to a discussion
-
- require_once('../../config.php');
- require_once('lib.php');
-
- $reply = optional_param('reply', 0, PARAM_INT);
- $forum = optional_param('forum', 0, PARAM_INT);
- $edit = optional_param('edit', 0, PARAM_INT);
- $delete = optional_param('delete', 0, PARAM_INT);
- $prune = optional_param('prune', 0, PARAM_INT);
- $name = optional_param('name', '', PARAM_CLEAN);
- $confirm = optional_param('confirm', 0, PARAM_INT);
- $groupid = optional_param('groupid', null, PARAM_INT);
-
-
- // #marginalia begin
- $messageinit = optional_param( 'message', 0, PARAM_CLEANHTML );
- // #marginalia end
-
- //these page_params will be passed as hidden variables later in the form.
- $page_params = array('reply'=>$reply, 'forum'=>$forum, 'edit'=>$edit);
-
- $sitecontext = get_context_instance(CONTEXT_SYSTEM);
-
- if (has_capability('moodle/legacy:guest', $sitecontext, NULL, false)) {
-
- $wwwroot = $CFG->wwwroot.'/login/index.php';
- if (!empty($CFG->loginhttps)) {
- $wwwroot = str_replace('http:', 'https:', $wwwroot);
- }
-
- if (!empty($forum)) { // User is starting a new discussion in
a forum
- if (! $forum = get_record('forum', 'id', $forum)) {
- error('The forum number was incorrect');
- }
- } else if (!empty($reply)) { // User is writing a new reply
- if (! $parent = forum_get_post_full($reply)) {
- error('Parent post ID was incorrect');
- }
- if (! $discussion = get_record('forum_discussions', 'id',
$parent->discussion)) {
- error('This post is not part of a discussion!');
- }
- if (! $forum = get_record('forum', 'id', $discussion->forum)) {
- error('The forum number was incorrect');
- }
- }
- if (! $course = get_record('course', 'id', $forum->course)) {
- error('The course number was incorrect');
- }
-
- if (!$cm = get_coursemodule_from_instance('forum', $forum->id,
$course->id)) { // For the logs
- error('Could not get the course module for the forum
instance.');
- } else {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
- }
-
- if (!get_referer()) { // No referer - probably coming in via
email See MDL-9052
- require_login();
- }
-
- $navigation = build_navigation('', $cm);
- print_header($course->shortname, $course->fullname,
$navigation, '' , '', true, "", navmenu($course, $cm));
-
- notice_yesno(get_string('noguestpost', 'forum').'<br /><br
/>'.get_string('liketologin'),
- $wwwroot, get_referer(false));
- print_footer($course);
- exit;
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Edit and save a new post to a discussion
+ *
+ * @package mod-forum
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once('../../config.php');
+require_once('lib.php');
+require_once($CFG->libdir.'/completionlib.php');
+
+$reply = optional_param('reply', 0, PARAM_INT);
+$forum = optional_param('forum', 0, PARAM_INT);
+$edit = optional_param('edit', 0, PARAM_INT);
+$delete = optional_param('delete', 0, PARAM_INT);
+$prune = optional_param('prune', 0, PARAM_INT);
+$name = optional_param('name', '', PARAM_CLEAN);
+$confirm = optional_param('confirm', 0, PARAM_INT);
+$groupid = optional_param('groupid', null, PARAM_INT);
+$messageinit = optional_param('message', '', PARAM_CLEANHTML);
+
+$PAGE->set_url('/mod/forum/post.php', array(
+ 'reply' => $reply,
+ 'forum' => $forum,
+ 'edit' => $edit,
+ 'delete'=> $delete,
+ 'prune' => $prune,
+ 'name' => $name,
+ 'confirm'=>$confirm,
+ 'groupid'=>$groupid,
+ 'messageinit'=>$messageinit
+ ));
+//these page_params will be passed as hidden variables later in the form.
+$page_params = array('reply'=>$reply, 'forum'=>$forum, 'edit'=>$edit);
+
+$sitecontext = get_context_instance(CONTEXT_SYSTEM);
+
+if (!isloggedin() or isguestuser()) {
+
+ if (!isloggedin() and !get_referer()) {
+ // No referer+not logged in - probably coming in via email See
MDL-9052
+ require_login();
+ }
+
+ if (!empty($forum)) { // User is starting a new discussion in a
forum
+ if (! $forum = $DB->get_record('forum', array('id' => $forum))) {
+ print_error('invalidforumid', 'forum');
+ }
+ } else if (!empty($reply)) { // User is writing a new reply
+ if (! $parent = forum_get_post_full($reply)) {
+ print_error('invalidparentpostid', 'forum');
+ }
+ if (! $discussion = $DB->get_record('forum_discussions',
array('id' => $parent->discussion))) {
+ print_error('notpartofdiscussion', 'forum');
+ }
+ if (! $forum = $DB->get_record('forum', array('id' =>
$discussion->forum))) {
+ print_error('invalidforumid');
+ }
+ }
+ if (! $course = $DB->get_record('course', array('id' =>
$forum->course))) {
+ print_error('invalidcourseid');
+ }
+
+ if (!$cm = get_coursemodule_from_instance('forum', $forum->id,
$course->id)) { // For the logs
+ print_error('invalidcoursemodule');
+ } else {
+ $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
}

- require_login(0, false); // Script is useless unless they're logged
in
-
- if (!empty($forum)) { // User is starting a new discussion in a
forum
- if (! $forum = get_record("forum", "id", $forum)) {
- error("The forum number was incorrect ($forum)");
- }
- if (! $course = get_record("course", "id", $forum->course)) {
- error("The course number was incorrect ($forum->course)");
- }
- if (! $cm = get_coursemodule_from_instance("forum", $forum->id,
$course->id)) {
- error("Incorrect course module");
- }
-
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
-
- if (! forum_user_can_post_discussion($forum, $groupid, -1, $cm)) {
- if (has_capability('moodle/legacy:guest', $coursecontext,
NULL, false)) { // User is a guest here!
- $SESSION->wantsurl = $FULLME;
- $SESSION->enrolcancel = $_SERVER['HTTP_REFERER'];
-
redirect($CFG->wwwroot.'/course/enrol.php?id='.$course->id,
get_string('youneedtoenrol'));
- } else {
- print_error('nopostforum', 'forum');
+ $PAGE->set_cm($cm, $course, $forum);
+ $PAGE->set_context($modcontext);
+ $PAGE->set_title($course->shortname);
+ $PAGE->set_heading($course->fullname);
+
+ echo $OUTPUT->header();
+ echo $OUTPUT->confirm(get_string('noguestpost', 'forum').'<br /><br
/>'.get_string('liketologin'), get_login_url(), get_referer(false));
+ echo $OUTPUT->footer();
+ exit;
+}
+
+require_login(0, false); // Script is useless unless they're logged in
+
+if (!empty($forum)) { // User is starting a new discussion in a forum
+ if (! $forum = $DB->get_record("forum", array("id" => $forum))) {
+ print_error('invalidforumid', 'forum');
+ }
+ if (! $course = $DB->get_record("course", array("id" =>
$forum->course))) {
+ print_error('invalidcourseid');
+ }
+ if (! $cm = get_coursemodule_from_instance("forum", $forum->id,
$course->id)) {
+ print_error("invalidcoursemodule");
+ }
+
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+
+ if (! forum_user_can_post_discussion($forum, $groupid, -1, $cm)) {
+ if (!isguestuser()) {
+ if (!is_enrolled($coursecontext)) {
+ if (enrol_selfenrol_available($course->id)) {
+ $SESSION->wantsurl = $FULLME;
+ $SESSION->enrolcancel = $_SERVER['HTTP_REFERER'];
+
redirect($CFG->wwwroot.'/enrol/index.php?id='.$course->id,
get_string('youneedtoenrol'));
+ }
}
}
-
- if (!$cm->visible
and !has_capability('moodle/course:viewhiddenactivities', $coursecontext)) {
- print_error("activityiscurrentlyhidden");
- }
-
- if (isset($_SERVER["HTTP_REFERER"])) {
- $SESSION->fromurl = $_SERVER["HTTP_REFERER"];
- } else {
- $SESSION->fromurl = '';
- }
+ print_error('nopostforum', 'forum');
+ }
+
+ if (!$cm->visible
and !has_capability('moodle/course:viewhiddenactivities', $coursecontext)) {
+ print_error("activityiscurrentlyhidden");
+ }
+
+ if (isset($_SERVER["HTTP_REFERER"])) {
+ $SESSION->fromurl = $_SERVER["HTTP_REFERER"];
+ } else {
+ $SESSION->fromurl = '';
+ }


- // Load up the $post variable.
-
- $post = new object();
- $post->course = $course->id;
- $post->forum = $forum->id;
- $post->discussion = 0; // ie discussion # not defined yet
- $post->parent = 0;
- $post->subject = '';
- $post->userid = $USER->id;
- $post->message = $messageinit ? $messageinit : ''; //
#marginalia
-
- if (isset($groupid)) {
- $post->groupid = $groupid;
- } else {
- $post->groupid = groups_get_activity_group($cm);
- }
-
- forum_set_return();
-
- } else if (!empty($reply)) { // User is writing a new reply
-
- if (! $parent = forum_get_post_full($reply)) {
- error("Parent post ID was incorrect");
- }
- if (! $discussion = get_record("forum_discussions", "id",
$parent->discussion)) {
- error("This post is not part of a discussion!");
- }
- if (! $forum = get_record("forum", "id", $discussion->forum)) {
- error("The forum number was incorrect ($discussion->forum)");
- }
- if (! $course = get_record("course", "id", $discussion->course)) {
- error("The course number was incorrect ($discussion->course)");
- }
- if (! $cm = get_coursemodule_from_instance("forum", $forum->id,
$course->id)) {
- error("Incorrect cm");
- }
-
- // call course_setup to use forced language, MDL-6926
- course_setup($course->id);
-
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
-
- if (! forum_user_can_post($forum, $discussion, $USER, $cm,
$course, $modcontext)) {
- if (has_capability('moodle/legacy:guest', $coursecontext,
NULL, false)) { // User is a guest here!
+ // Load up the $post variable.
+
+ $post = new stdClass();
+ $post->course = $course->id;
+ $post->forum = $forum->id;
+ $post->discussion = 0; // ie discussion # not defined yet
+ $post->parent = 0;
+ $post->subject = '';
+ $post->userid = $USER->id;
+ $post->message = $messageinit;
+ $post->messageformat = editors_get_preferred_format();
+ $post->messagetrust = 0;
+
+ if (isset($groupid)) {
+ $post->groupid = $groupid;
+ } else {
+ $post->groupid = groups_get_activity_group($cm);
+ }
+
+ forum_set_return();
+
+} else if (!empty($reply)) { // User is writing a new reply
+
+ if (! $parent = forum_get_post_full($reply)) {
+ print_error('invalidparentpostid', 'forum');
+ }
+ if (! $discussion = $DB->get_record("forum_discussions", array("id" =>
$parent->discussion))) {
+ print_error('notpartofdiscussion', 'forum');
+ }
+ if (! $forum = $DB->get_record("forum", array("id" =>
$discussion->forum))) {
+ print_error('invalidforumid', 'forum');
+ }
+ if (! $course = $DB->get_record("course", array("id" =>
$discussion->course))) {
+ print_error('invalidcourseid');
+ }
+ if (! $cm = get_coursemodule_from_instance("forum", $forum->id,
$course->id)) {
+ print_error('invalidcoursemodule');
+ }
+
+ // Ensure lang, theme, etc. is set up properly. MDL-6926
+ $PAGE->set_cm($cm, $course, $forum);
+
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+
+ if (! forum_user_can_post($forum, $discussion, $USER, $cm, $course,
$modcontext)) {
+ if (!isguestuser()) {
+ if (!is_enrolled($coursecontext)) { // User is a guest here!
$SESSION->wantsurl = $FULLME;
$SESSION->enrolcancel = $_SERVER['HTTP_REFERER'];
-
redirect($CFG->wwwroot.'/course/enrol.php?id='.$course->id,
get_string('youneedtoenrol'));
- } else {
- print_error('nopostforum', 'forum');
+ redirect($CFG->wwwroot.'/enrol/index.php?id='.$course->id,
get_string('youneedtoenrol'));
}
}
-
- // Make sure user can post here
- if (groupmode($course, $cm) == SEPARATEGROUPS
and !has_capability('moodle/site:accessallgroups', $modcontext)) {
- if ($discussion->groupid == -1) {
+ print_error('nopostforum', 'forum');
+ }
+
+ // Make sure user can post here
+ if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
+ $groupmode = $cm->groupmode;
+ } else {
+ $groupmode = $course->groupmode;
+ }
+ if ($groupmode == SEPARATEGROUPS
and !has_capability('moodle/site:accessallgroups', $modcontext)) {
+ if ($discussion->groupid == -1) {
+ print_error('nopostforum', 'forum');
+ } else {
+ if (!groups_is_member($discussion->groupid)) {
print_error('nopostforum', 'forum');
- } else {
- if (!groups_is_member($discussion->groupid)) {
- print_error('nopostforum', 'forum');
- }
}
}
-
- if (!$cm->visible
and !has_capability('moodle/course:viewhiddenactivities', $coursecontext)) {
- print_error("activityiscurrentlyhidden");
- }
-
- // Load up the $post variable.
-
- $post = new object();
- $post->course = $course->id;
- $post->forum = $forum->id;
- $post->discussion = $parent->discussion;
- $post->parent = $parent->id;
- $post->subject = $parent->subject;
- $post->userid = $USER->id;
- $post->message = $messageinit ? $messageinit : ''; //
#marginalia
-
- $post->groupid = ($discussion->groupid == -1) ? 0 :
$discussion->groupid;
-
- $strre = get_string('re', 'forum');
- if (!(substr($post->subject, 0, strlen($strre)) == $strre)) {
- $post->subject = $strre.' '.$post->subject;
- }
-
- unset($SESSION->fromdiscussion);
-
- } else if (!empty($edit)) { // User is editing their own post
-
- if (! $post = forum_get_post_full($edit)) {
- error("Post ID was incorrect");
- }
- if ($post->parent) {
- if (! $parent = forum_get_post_full($post->parent)) {
- error("Parent post ID was incorrect ($post->parent)");
- }
- }
-
- if (! $discussion = get_record("forum_discussions", "id",
$post->discussion)) {
- error("This post is not part of a discussion! ($edit)");
- }
- if (! $forum = get_record("forum", "id", $discussion->forum)) {
- error("The forum number was incorrect ($discussion->forum)");
- }
- if (! $course = get_record("course", "id", $discussion->course)) {
- error("The course number was incorrect ($discussion->course)");
- }
- if (!$cm = get_coursemodule_from_instance("forum", $forum->id,
$course->id)) {
- error('Could not get the course module for the forum
instance.');
- } else {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
- }
- if (!($forum->type == 'news' && !$post->parent &&
$discussion->timestart > time())) {
- if (((time() - $post->created) > $CFG->maxeditingtime) and
- !has_capability('mod/forum:editanypost',
$modcontext)) {
- error( get_string("maxtimehaspassed", "forum",
format_time($CFG->maxeditingtime)) );
- }
- }
- if (($post->userid <> $USER->id) and
+ }
+
+ if (!$cm->visible
and !has_capability('moodle/course:viewhiddenactivities', $coursecontext)) {
+ print_error("activityiscurrentlyhidden");
+ }
+
+ // Load up the $post variable.
+
+ $post = new stdClass();
+ $post->course = $course->id;
+ $post->forum = $forum->id;
+ $post->discussion = $parent->discussion;
+ $post->parent = $parent->id;
+ $post->subject = $parent->subject;
+ $post->userid = $USER->id;
+ $post->message = $messageinit;
+
+ $post->groupid = ($discussion->groupid == -1) ? 0 :
$discussion->groupid;
+
+ $strre = get_string('re', 'forum');
+ if (!(substr($post->subject, 0, strlen($strre)) == $strre)) {
+ $post->subject = $strre.' '.$post->subject;
+ }
+
+ unset($SESSION->fromdiscussion);
+
+} else if (!empty($edit)) { // User is editing their own post
+
+ if (! $post = forum_get_post_full($edit)) {
+ print_error('invalidpostid', 'forum');
+ }
+ if ($post->parent) {
+ if (! $parent = forum_get_post_full($post->parent)) {
+ print_error('invalidparentpostid', 'forum');
+ }
+ }
+
+ if (! $discussion = $DB->get_record("forum_discussions", array("id" =>
$post->discussion))) {
+ print_error('notpartofdiscussion', 'forum');
+ }
+ if (! $forum = $DB->get_record("forum", array("id" =>
$discussion->forum))) {
+ print_error('invalidforumid', 'forum');
+ }
+ if (! $course = $DB->get_record("course", array("id" =>
$discussion->course))) {
+ print_error('invalidcourseid');
+ }
+ if (!$cm = get_coursemodule_from_instance("forum", $forum->id,
$course->id)) {
+ print_error('invalidcoursemodule');
+ } else {
+ $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ }
+
+ $PAGE->set_cm($cm, $course, $forum);
+
+ if (!($forum->type == 'news' && !$post->parent &&
$discussion->timestart > time())) {
+ if (((time() - $post->created) > $CFG->maxeditingtime) and
!has_capability('mod/forum:editanypost', $modcontext))
{
- error("You can't edit other people's posts!");
- }
+ print_error('maxtimehaspassed', 'forum', '',
format_time($CFG->maxeditingtime));
+ }
+ }
+ if (($post->userid <> $USER->id) and
+ !has_capability('mod/forum:editanypost', $modcontext)) {
+ print_error('cannoteditposts', 'forum');
+ }


- // Load up the $post variable.
- $post->edit = $edit;
- $post->course = $course->id;
- $post->forum = $forum->id;
- $post->groupid = ($discussion->groupid == -1) ? 0 :
$discussion->groupid;
-
- trusttext_prepare_edit($post->message, $post->format,
can_use_html_editor(), $modcontext);
-
- unset($SESSION->fromdiscussion);
+ // Load up the $post variable.
+ $post->edit = $edit;
+ $post->course = $course->id;
+ $post->forum = $forum->id;
+ $post->groupid = ($discussion->groupid == -1) ? 0 :
$discussion->groupid;
+
+ $post = trusttext_pre_edit($post, 'message', $modcontext);
+
+ unset($SESSION->fromdiscussion);


- }else if (!empty($delete)) { // User is deleting a post
-
- if (! $post = forum_get_post_full($delete)) {
- error("Post ID was incorrect");
- }
- if (! $discussion = get_record("forum_discussions", "id",
$post->discussion)) {
- error("This post is not part of a discussion!");
- }
- if (! $forum = get_record("forum", "id", $discussion->forum)) {
- error("The forum number was incorrect ($discussion->forum)");
- }
- if (!$cm = get_coursemodule_from_instance("forum", $forum->id,
$forum->course)) {
- error('Could not get the course module for the forum
instance.');
- }
- if (!$course = get_record('course', 'id', $forum->course)) {
- error('Incorrect course');
- }
-
- require_login($course, false, $cm);
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
-
- if ( !(($post->userid == $USER->id &&
has_capability('mod/forum:deleteownpost', $modcontext))
- || has_capability('mod/forum:deleteanypost',
$modcontext)) ) {
- error("You can't delete this post!");
+}else if (!empty($delete)) { // User is deleting a post
+
+ if (! $post = forum_get_post_full($delete)) {
+ print_error('invalidpostid', 'forum');
+ }
+ if (! $discussion = $DB->get_record("forum_discussions", array("id" =>
$post->discussion))) {
+ print_error('notpartofdiscussion', 'forum');
+ }
+ if (! $forum = $DB->get_record("forum", array("id" =>
$discussion->forum))) {
+ print_error('invalidforumid', 'forum');
+ }
+ if (!$cm = get_coursemodule_from_instance("forum", $forum->id,
$forum->course)) {
+ print_error('invalidcoursemodule');
+ }
+ if (!$course = $DB->get_record('course', array('id' =>
$forum->course))) {
+ print_error('invalidcourseid');
+ }
+
+ require_login($course, false, $cm);
+ $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+
+ if ( !(($post->userid == $USER->id &&
has_capability('mod/forum:deleteownpost', $modcontext))
+ || has_capability('mod/forum:deleteanypost', $modcontext))
) {
+ print_error('cannotdeletepost', 'forum');
+ }
+
+
+ $replycount = forum_count_replies($post);
+
+ if (!empty($confirm) && confirm_sesskey()) { // User has confirmed
the delete
+ //check user capability to delete post.
+ $timepassed = time() - $post->created;
+ if (($timepassed > $CFG->maxeditingtime)
&& !has_capability('mod/forum:deleteanypost', $modcontext)) {
+ print_error("cannotdeletepost", "forum",
+ forum_go_back_to("discuss.php?d=$post->discussion"));
}

-
- $replycount = forum_count_replies($post);
-
- if (!empty($confirm) && confirm_sesskey()) { // User has
confirmed the delete
-
- if ($post->totalscore) {
- notice(get_string("couldnotdeleteratings", "forum"),
-
forum_go_back_to("discuss.php?d=$post->discussion"));
-
- } else if ($replycount
&& !has_capability('mod/forum:deleteanypost', $modcontext)) {
- print_error("couldnotdeletereplies", "forum",
-
forum_go_back_to("discuss.php?d=$post->discussion"));
-
+ if ($post->totalscore) {
+ notice(get_string('couldnotdeleteratings', 'rating'),
+ forum_go_back_to("discuss.php?d=$post->discussion"));
+
+ } else if ($replycount
&& !has_capability('mod/forum:deleteanypost', $modcontext)) {
+ print_error("couldnotdeletereplies", "forum",
+ forum_go_back_to("discuss.php?d=$post->discussion"));
+
+ } else {
+ if (! $post->parent) { // post is a discussion topic as well,
so delete discussion
+ if ($forum->type == 'single') {
+ notice("Sorry, but you are not allowed to delete that
discussion!",
+
forum_go_back_to("discuss.php?d=$post->discussion"));
+ }
+ forum_delete_discussion($discussion, false, $course, $cm,
$forum);
+
+ add_to_log($discussion->course, "forum", "delete
discussion",
+ "view.php?id=$cm->id", "$forum->id", $cm->id);
+
+ redirect("view.php?f=$discussion->forum");
+
+ } else if (forum_delete_post($post,
has_capability('mod/forum:deleteanypost', $modcontext),
+ $course, $cm, $forum)) {
+
+ if ($forum->type == 'single') {
+ // Single discussion forums are an exception. We show
+ // the forum itself since it only has one discussion
+ // thread.
+ $discussionurl = "view.php?f=$forum->id";
+ } else {
+ $discussionurl = "discuss.php?d=$post->discussion";
+ }
+
+ add_to_log($discussion->course, "forum", "delete post",
$discussionurl, "$post->id", $cm->id);
+
+ redirect(forum_go_back_to($discussionurl));
} else {
- if (! $post->parent) { // post is a discussion topic as
well, so delete discussion
- if ($forum->type == 'single') {
- notice("Sorry, but you are not allowed to delete
that discussion!",
-
forum_go_back_to("discuss.php?d=$post->discussion"));
- }
- forum_delete_discussion($discussion);
-
- add_to_log($discussion->course, "forum", "delete
discussion",
- "view.php?id=$cm->id", "$forum->id",
$cm->id);
-
- redirect("view.php?f=$discussion->forum");
-
- } else if (forum_delete_post($post,
has_capability('mod/forum:deleteanypost', $modcontext))) {
-
- if ($forum->type == 'single') {
- // Single discussion forums are an exception. We
show
- // the forum itself since it only has one
discussion
- // thread.
- $discussionurl = "view.php?f=$forum->id";
- } else {
- $discussionurl = "discuss.php?d=$post->discussion";
- }
-
- add_to_log($discussion->course, "forum", "delete
post", $discussionurl, "$post->id", $cm->id);
-
- redirect(forum_go_back_to($discussionurl));
- } else {
- error("An error occurred while deleting record
$post->id");
- }
- }
-
-
- } else { // User just asked to delete something
-
- forum_set_return();
-
- if ($replycount) {
- if (!has_capability('mod/forum:deleteanypost',
$modcontext)) {
- print_error("couldnotdeletereplies", "forum",
-
forum_go_back_to("discuss.php?d=$post->discussion"));
- }
- print_header();
- notice_yesno(get_string("deletesureplural", "forum",
$replycount+1),
- "post.php?delete=$delete&amp;confirm=$delete&amp;sesskey=".sesskey(),
-
$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#p'.$post->id);
-
- forum_print_post($post, $discussion, $forum, $cm, $course,
false, false, false);
-
- if (empty($post->edit)) {
- $forumtracked = forum_tp_is_tracked($forum);
- $posts =
forum_get_all_discussion_posts($discussion->id, "created ASC",
$forumtracked);
- forum_print_posts_nested($course, $cm, $forum,
$discussion, $post, false, false, $forumtracked, $posts);
- }
- } else {
- print_header();
- notice_yesno(get_string("deletesure", "forum",
$replycount),
- "post.php?delete=$delete&amp;confirm=$delete&amp;sesskey=".sesskey(),
-
$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#p'.$post->id);
- forum_print_post($post, $discussion, $forum, $cm, $course,
false, false, false);
- }
-
- }
- print_footer($course);
- die;
-
-
- } else if (!empty($prune)) { // Pruning
-
- if (!$post = forum_get_post_full($prune)) {
- error("Post ID was incorrect");
- }
- if (!$discussion = get_record("forum_discussions", "id",
$post->discussion)) {
- error("This post is not part of a discussion!");
- }
- if (!$forum = get_record("forum", "id", $discussion->forum)) {
- error("The forum number was incorrect ($discussion->forum)");
- }
- if ($forum->type == 'single') {
- error('Discussions from this forum cannot be split');
- }
- if (!$post->parent) {
- error('This is already the first post in the discussion');
- }
- if (!$cm = get_coursemodule_from_instance("forum", $forum->id,
$forum->course)) { // For the logs
- error('Could not get the course module for the forum
instance.');
- } else {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
- }
- if (!has_capability('mod/forum:splitdiscussions', $modcontext)) {
- error("You can't split discussions!");
- }
-
- if (!empty($name) && confirm_sesskey()) { // User has confirmed
the prune
-
- $newdiscussion = new object();
- $newdiscussion->course = $discussion->course;
- $newdiscussion->forum = $discussion->forum;
- $newdiscussion->name = $name;
- $newdiscussion->firstpost = $post->id;
- $newdiscussion->userid = $discussion->userid;
- $newdiscussion->groupid = $discussion->groupid;
- $newdiscussion->assessed = $discussion->assessed;
- $newdiscussion->usermodified = $post->userid;
- $newdiscussion->timestart = $discussion->timestart;
- $newdiscussion->timeend = $discussion->timeend;
-
- if (!$newid = insert_record('forum_discussions',
$newdiscussion)) {
- error('Could not create new discussion');
- }
-
- $newpost = new object();
- $newpost->id = $post->id;
- $newpost->parent = 0;
- $newpost->subject = $name;
-
- if (!update_record("forum_posts", $newpost)) {
- error('Could not update the original post');
- }
-
- forum_change_discussionid($post->id, $newid);
-
- // update last post in each discussion
- forum_discussion_update_last_post($discussion->id);
- forum_discussion_update_last_post($newid);
-
- add_to_log($discussion->course, "forum", "prune post",
- "discuss.php?d=$newid", "$post->id", $cm->id);
-
- redirect(forum_go_back_to("discuss.php?d=$newid"));
-
- } else { // User just asked to prune something
-
- $course = get_record('course', 'id', $forum->course);
-
- $navlinks = array();
- $navlinks[] = array('name' => format_string($post->subject,
true), 'link' => "discuss.php?d=$discussion->id", 'type' => 'title');
- $navlinks[] = array('name' =>
get_string("prune", "forum"), 'link' => '', 'type' => 'title');
- $navigation = build_navigation($navlinks, $cm);
-
print_header_simple(format_string($discussion->name).": ".format_string($post->subject), "",
$navigation, '', "", true, "", navmenu($course, $cm));
-
- print_heading(get_string('pruneheading', 'forum'));
- echo '<center>';
-
- include('prune.html');
-
- forum_print_post($post, $discussion, $forum, $cm, $course,
false, false, false);
- echo '</center>';
- }
- print_footer($course);
- die;
- } else {
- error("No operation specified");
-
- }
-
- if (!isset($coursecontext)) {
- // Has not yet been set by post.php.
- $coursecontext = get_context_instance(CONTEXT_COURSE,
$forum->course);
- }
-
- if (!$cm = get_coursemodule_from_instance('forum', $forum->id,
$course->id)) { // For the logs
- error('Could not get the course module for the forum instance.');
- }
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
-
- // setup course variable to force form language
- // fix for MDL-6926
- course_setup($course->id);
- require_once('post_form.php');
-
- // #marginalia begin
- require_once('../../blocks/marginalia/config.php');
- require_once( ANNOTATION_DIR.'/marginalia-php/embed.php' );
- require_once( ANNOTATION_DIR.'/annotation_summary_query.php' );
- require_once( ANNOTATION_DIR.'/lib.php' );
- // #marginalia end
-
- $mform_post = new mod_forum_post_form('post.php',
array('course'=>$course, 'cm'=>$cm, 'coursecontext'=>$coursecontext, 'modcontext'=>$modcontext, 'forum'=>$forum, 'post'=>$post));
-
- if ($fromform = $mform_post->get_data()) {
-
-
- require_login($course, false, $cm);
-
- if (empty($SESSION->fromurl)) {
- $errordestination
= "$CFG->wwwroot/mod/forum/view.php?f=$forum->id";
- } else {
- $errordestination = $SESSION->fromurl;
+ print_error('errorwhiledelete', 'forum');
+ }
+ }
+
+
+ } else { // User just asked to delete something
+
+ forum_set_return();
+ $PAGE->navbar->add(get_string('delete', 'forum'));
+ $PAGE->set_title($course->shortname);
+ $PAGE->set_heading($course->fullname);
+
+ if ($replycount) {
+ if (!has_capability('mod/forum:deleteanypost', $modcontext)) {
+ print_error("couldnotdeletereplies", "forum",
+ forum_go_back_to("discuss.php?d=$post->discussion"));
+ }
+ echo $OUTPUT->header();
+ echo $OUTPUT->confirm(get_string("deletesureplural", "forum",
$replycount+1),
+ "post.php?delete=$delete&confirm=$delete",
+
$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#p'.$post->id);
+
+ forum_print_post($post, $discussion, $forum, $cm, $course,
false, false, false);
+
+ if (empty($post->edit)) {
+ $forumtracked = forum_tp_is_tracked($forum);
+ $posts =
forum_get_all_discussion_posts($discussion->id, "created ASC",
$forumtracked);
+ forum_print_posts_nested($course, $cm, $forum,
$discussion, $post, false, false, $forumtracked, $posts);
+ }
+ } else {
+ echo $OUTPUT->header();
+ echo $OUTPUT->confirm(get_string("deletesure", "forum",
$replycount),
+ "post.php?delete=$delete&confirm=$delete",
+
$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#p'.$post->id);
+ forum_print_post($post, $discussion, $forum, $cm, $course,
false, false, false);
+ }
+
+ }
+ echo $OUTPUT->footer();
+ die;
+
+
+} else if (!empty($prune)) { // Pruning
+
+ if (!$post = forum_get_post_full($prune)) {
+ print_error('invalidpostid', 'forum');
+ }
+ if (!$discussion = $DB->get_record("forum_discussions", array("id" =>
$post->discussion))) {
+ print_error('notpartofdiscussion', 'forum');
+ }
+ if (!$forum = $DB->get_record("forum", array("id" =>
$discussion->forum))) {
+ print_error('invalidforumid', 'forum');
+ }
+ if ($forum->type == 'single') {
+ print_error('cannotsplit', 'forum');
+ }
+ if (!$post->parent) {
+ print_error('alreadyfirstpost', 'forum');
+ }
+ if (!$cm = get_coursemodule_from_instance("forum", $forum->id,
$forum->course)) { // For the logs
+ print_error('invalidcoursemodule');
+ } else {
+ $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ }
+ if (!has_capability('mod/forum:splitdiscussions', $modcontext)) {
+ print_error('cannotsplit', 'forum');
+ }
+
+ if (!empty($name) && confirm_sesskey()) { // User has confirmed the
prune
+
+ $newdiscussion = new stdClass();
+ $newdiscussion->course = $discussion->course;
+ $newdiscussion->forum = $discussion->forum;
+ $newdiscussion->name = $name;
+ $newdiscussion->firstpost = $post->id;
+ $newdiscussion->userid = $discussion->userid;
+ $newdiscussion->groupid = $discussion->groupid;
+ $newdiscussion->assessed = $discussion->assessed;
+ $newdiscussion->usermodified = $post->userid;
+ $newdiscussion->timestart = $discussion->timestart;
+ $newdiscussion->timeend = $discussion->timeend;
+
+ $newid = $DB->insert_record('forum_discussions', $newdiscussion);
+
+ $newpost = new stdClass();
+ $newpost->id = $post->id;
+ $newpost->parent = 0;
+ $newpost->subject = $name;
+
+ $DB->update_record("forum_posts", $newpost);
+
+ forum_change_discussionid($post->id, $newid);
+
+ // update last post in each discussion
+ forum_discussion_update_last_post($discussion->id);
+ forum_discussion_update_last_post($newid);
+
+ add_to_log($discussion->course, "forum", "prune post",
+ "discuss.php?d=$newid", "$post->id", $cm->id);
+
+ redirect(forum_go_back_to("discuss.php?d=$newid"));
+
+ } else { // User just asked to prune something
+
+ $course = $DB->get_record('course', array('id' => $forum->course));
+
+ $PAGE->set_cm($cm);
+ $PAGE->set_context($modcontext);
+ $PAGE->navbar->add(format_string($post->subject, true), new
moodle_url('/mod/forum/discuss.php', array('d'=>$discussion->id)));
+ $PAGE->navbar->add(get_string("prune", "forum"));
+
$PAGE->set_title(format_string($discussion->name).": ".format_string($post->subject));
+ $PAGE->set_heading($course->fullname);
+ echo $OUTPUT->header();
+ echo $OUTPUT->heading(get_string('pruneheading', 'forum'));
+ echo '<center>';
+
+ include('prune.html');
+
+ forum_print_post($post, $discussion, $forum, $cm, $course, false,
false, false);
+ echo '</center>';
+ }
+ echo $OUTPUT->footer();
+ die;
+} else {
+ print_error('unknowaction');
+
+}
+
+if (!isset($coursecontext)) {
+ // Has not yet been set by post.php.
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $forum->course);
+}
+
+
+// from now on user must be logged on properly
+
+if (!$cm = get_coursemodule_from_instance('forum', $forum->id,
$course->id)) { // For the logs
+ print_error('invalidcoursemodule');
+}
+$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+require_login($course, false, $cm);
+
+if (isguestuser()) {
+ // just in case
+ print_error('noguest');
+}
+
+if (!isset($forum->maxattachments)) { // TODO - delete this once we add a
field to the forum table
+ $forum->maxattachments = 3;
+}
+
+require_once('post_form.php');
+
+$mform_post = new mod_forum_post_form('post.php',
array('course'=>$course, 'cm'=>$cm, 'coursecontext'=>$coursecontext, 'modcontext'=>$modcontext, 'forum'=>$forum, 'post'=>$post));
+
+$draftitemid = file_get_submitted_draft_itemid('attachments');
+file_prepare_draft_area($draftitemid,
$modcontext->id, 'mod_forum', 'attachment',
empty($post->id)?null:$post->id);
+
+//load data into form NOW!
+
+if ($USER->id != $post->userid) { // Not the original author, so add a
message to the end
+ $data->date = userdate($post->modified);
+ if ($post->messageformat == FORMAT_HTML) {
+ $data->name = '<a
href="'.$CFG->wwwroot.'/user/view.php?id='.$USER->id.'&course='.$post->course.'">'.
+ fullname($USER).'</a>';
+ $post->message .= '<p>(<span
class="edited">'.get_string('editedby', 'forum', $data).'</span>)</p>';
+ } else {
+ $data->name = fullname($USER);
+ $post->message .= "\n\n(".get_string('editedby', 'forum',
$data).')';
+ }
+}
+
+if (!empty($parent)) {
+ $heading = get_string("yourreply", "forum");
+} else {
+ if ($forum->type == 'qanda') {
+ $heading = get_string('yournewquestion', 'forum');
+ } else {
+ $heading = get_string('yournewtopic', 'forum');
+ }
+}
+
+if (forum_is_subscribed($USER->id, $forum->id)) {
+ $subscribe = true;
+
+} else if (forum_user_has_posted($forum->id, 0, $USER->id)) {
+ $subscribe = false;
+
+} else {
+ // user not posted yet - use subscription default specified in profile
***The diff for this file has been truncated for email.***
=======================================
--- /moodle/trunk/moodle.orig/mod/forum/discuss.php Thu Mar 5 21:00:59 2009
+++ /moodle/trunk/moodle.orig/mod/forum/discuss.php Wed May 30 15:12:10 2012
@@ -1,7 +1,28 @@
-<?php // $Id$
-
-// Displays a post, and all the posts below it.
-// If no post is given, displays all posts in a discussion
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Displays a post, and all the posts below it.
+ * If no post is given, displays all posts in a discussion
+ *
+ * @package mod-forum
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */

require_once('../../config.php');

@@ -12,39 +33,42 @@
$mark = optional_param('mark', '', PARAM_ALPHA); // Used for
tracking read posts if user initiated.
$postid = optional_param('postid', 0, PARAM_INT); // Used for
tracking read posts if user initiated.

- if (!$discussion = get_record('forum_discussions', 'id', $d)) {
- error("Discussion ID was incorrect or no longer exists");
- }
-
- if (!$course = get_record('course', 'id', $discussion->course)) {
- error("Course ID is incorrect - discussion is faulty");
- }
-
- if (!$forum = get_record('forum', 'id', $discussion->forum)) {
- notify("Bad forum ID stored in this discussion");
- }
-
- if (!$cm = get_coursemodule_from_instance('forum', $forum->id,
$course->id)) {
- error('Course Module ID was incorrect');
- }
+ $url = new moodle_url('/mod/forum/discuss.php', array('d'=>$d));
+ if ($parent !== 0) {
+ $url->param('parent', $parent);
+ }
+ $PAGE->set_url($url);
+
+ $discussion = $DB->get_record('forum_discussions', array('id' =>
$d), '*', MUST_EXIST);
+ $course = $DB->get_record('course', array('id' =>
$discussion->course), '*', MUST_EXIST);
+ $forum = $DB->get_record('forum', array('id' =>
$discussion->forum), '*', MUST_EXIST);
+ $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id,
false, MUST_EXIST);

require_course_login($course, true, $cm);

/// Add ajax-related libs
-
require_js(array('yui_yahoo', 'yui_event', 'yui_dom', 'yui_connection', 'yui_json'));
- require_js($CFG->wwwroot . '/mod/forum/rate_ajax.js');
+ $PAGE->requires->yui2_lib('event');
+ $PAGE->requires->yui2_lib('connection');
+ $PAGE->requires->yui2_lib('json');

// move this down fix for MDL-6926
- require_once('lib.php');
+ require_once($CFG->dirroot.'/mod/forum/lib.php');

$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/forum:viewdiscussion', $modcontext, NULL,
true, 'noviewdiscussionspermission', 'forum');

+ if (!empty($CFG->enablerssfeeds) && !empty($CFG->forum_enablerssfeeds)
&& $forum->rsstype && $forum->rssarticles) {
+ require_once("$CFG->libdir/rsslib.php");
+
+ $rsstitle = format_string($course->shortname, true,
array('context' => get_context_instance(CONTEXT_COURSE,
$course->id))) . ': %fullname%';
+ rss_add_http_header($modcontext, 'mod_forum', $forum, $rsstitle);
+ }
+
if ($forum->type == 'news') {
if (!($USER->id == $discussion->userid || (($discussion->timestart
== 0
|| $discussion->timestart <= time())
&& ($discussion->timeend == 0 || $discussion->timeend >
time())))) {
- error('Discussion ID was incorrect or no longer
exists', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
+
print_error('invaliddiscussionid', 'forum', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
}
}

@@ -55,51 +79,45 @@
require_capability('mod/forum:movediscussions', $modcontext);

if ($forum->type == 'single') {
- error('Cannot move discussion from a simple single discussion
forum', $return);
+ print_error('cannotmovefromsingleforum', 'forum', $return);
}

- if (!$forumto = get_record('forum', 'id', $move)) {
- error('You can\'t move to that forum - it doesn\'t exist!',
$return);
+ if (!$forumto = $DB->get_record('forum', array('id' => $move))) {
+ print_error('cannotmovetonotexist', 'forum', $return);
+ }
+
+ if ($forumto->type == 'single') {
+ print_error('cannotmovetosingleforum', 'forum', $return);
}

if (!$cmto = get_coursemodule_from_instance('forum', $forumto->id,
$course->id)) {
- error('Target forum not found in this course.', $return);
+ print_error('cannotmovetonotfound', 'forum', $return);
}

if (!coursemodule_visible_for_user($cmto)) {
- error('Forum not visible', $return);
+ print_error('cannotmovenotvisible', 'forum', $return);
}

- require_capability('mod/forum:startdiscussion',
- get_context_instance(CONTEXT_MODULE,$cmto->id));
-
- if (!forum_move_attachments($discussion, $forumto->id)) {
- notify("Errors occurred while moving attachment directories -
check your file permissions");
- }
- set_field('forum_discussions', 'forum', $forumto->id, 'id',
$discussion->id);
- set_field('forum_read', 'forumid', $forumto->id, 'discussionid',
$discussion->id);
+ require_capability('mod/forum:startdiscussion',
get_context_instance(CONTEXT_MODULE,$cmto->id));
+
+ if (!forum_move_attachments($discussion, $forum->id,
$forumto->id)) {
+ echo $OUTPUT->notification("Errors occurred while moving
attachment directories - check your file permissions");
+ }
+ $DB->set_field('forum_discussions', 'forum', $forumto->id,
array('id' => $discussion->id));
+ $DB->set_field('forum_read', 'forumid', $forumto->id,
array('discussionid' => $discussion->id));
add_to_log($course->id, 'forum', 'move
discussion', "discuss.php?d=$discussion->id", $discussion->id, $cmto->id);

require_once($CFG->libdir.'/rsslib.php');
- require_once('rsslib.php');
-
- // Delete the RSS files for the 2 forums because we want to force
- // the regeneration of the feeds since the discussions have been
- // moved.
- if (!forum_rss_delete_file($forum) |
| !forum_rss_delete_file($forumto)) {
- error('Could not purge the cached RSS feeds for the source
and/or'.
- 'destination forum(s) - check your file
permissionsforums', $return);
- }
-
- redirect($return.'&amp;moved=-1&amp;sesskey='.sesskey());
+ require_once($CFG->dirroot.'/mod/forum/rsslib.php');
+
+ // Delete the RSS files for the 2 forums to force regeneration of
the feeds
+ forum_rss_delete_file($forum);
+ forum_rss_delete_file($forumto);
+
+ redirect($return.'&moved=-1&sesskey='.sesskey());
}

- $logparameters = "d=$discussion->id";
- if ($parent) {
- $logparameters .= "&amp;parent=$parent";
- }
-
- add_to_log($course->id, 'forum', 'view
discussion', "discuss.php?$logparameters", $discussion->id, $cm->id);
+ add_to_log($course->id, 'forum', 'view
discussion', "discuss.php?d=$discussion->id", $discussion->id, $cm->id);

unset($SESSION->fromdiscussion);

@@ -119,12 +137,12 @@
}

if (! $post = forum_get_post_full($parent)) {
- error("Discussion no longer
exists", "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
+
print_error("notexists", 'forum', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
}


if (!forum_user_can_view_post($post, $course, $cm, $forum,
$discussion)) {
- error('You do not have permissions to view this
post', "$CFG->wwwroot/mod/forum/view.php?id=$forum->id");
+
print_error('nopermissiontoview', 'forum', "$CFG->wwwroot/mod/forum/view.php?id=$forum->id");
}

if ($mark == 'read' or $mark == 'unread') {
@@ -140,99 +158,126 @@

$searchform = forum_search_form($course);

- $navlinks = array();
- $navlinks[] = array('name' => format_string($discussion->name), 'link'
=> "discuss.php?d=$discussion->id", 'type' => 'title');
- if ($parent != $discussion->firstpost) {
- $navlinks[] = array('name' =>
format_string($post->subject), 'type' => 'title');
+ $forumnode = $PAGE->navigation->find($cm->id,
navigation_node::TYPE_ACTIVITY);
+ if (empty($forumnode)) {
+ $forumnode = $PAGE->navbar;
+ } else {
+ $forumnode->make_active();
+ }
+ $node = $forumnode->add(format_string($discussion->name), new
moodle_url('/mod/forum/discuss.php', array('d'=>$discussion->id)));
+ $node->display = false;
+ if ($node && $post->id != $discussion->firstpost) {
+ $node->add(format_string($post->subject), $PAGE->url);
}

- $navigation = build_navigation($navlinks, $cm);
- print_header("$course->shortname: ".format_string($discussion->name),
$course->fullname,
- $navigation, "", "", true, $searchform,
navmenu($course, $cm));
-
+
$PAGE->set_title("$course->shortname: ".format_string($discussion->name));
+ $PAGE->set_heading($course->fullname);
+ $PAGE->set_button($searchform);
+ echo $OUTPUT->header();

/// Check to see if groups are being used in this forum
/// If so, make sure the current person is allowed to see this discussion
/// Also, if we know they should be able to reply, then explicitly set
$canreply for performance reasons

- if (isguestuser() or !isloggedin() or
has_capability('moodle/legacy:guest', $modcontext, NULL, false)) {
- // allow guests and not-logged-in to see the link - they are
prompted to log in after clicking the link
- $canreply = ($forum->type != 'news'); // no reply in news forums
-
- } else {
- $canreply = forum_user_can_post($forum, $discussion, $USER, $cm,
$course, $modcontext);
+ $canreply = forum_user_can_post($forum, $discussion, $USER, $cm,
$course, $modcontext);
+ if (!$canreply and $forum->type !== 'news') {
+ if (isguestuser() or !isloggedin()) {
+ $canreply = true;
+ }
+ if (!is_enrolled($modcontext) and !is_viewing($modcontext)) {
+ // allow guests and not-logged-in to see the link - they are
prompted to log in after clicking the link
+ // normal users with temporary guest access see this link too,
they are asked to enrol instead
+ $canreply = enrol_selfenrol_available($course->id);
+ }
}

/// Print the controls across the top
-
- echo '<table width="100%" class="discussioncontrols"><tr><td>';
+ echo '<div class="discussioncontrols clearfix">';
+
+ if (!empty($CFG->enableportfolios) &&
has_capability('mod/forum:exportdiscussion', $modcontext)) {
+ require_once($CFG->libdir.'/portfoliolib.php');
+ $button = new portfolio_add_button();
+ $button->set_callback_options('forum_portfolio_caller',
array('discussionid' => $discussion->id), '/mod/forum/locallib.php');
+ $button = $button->to_html(PORTFOLIO_ADD_FULL_FORM,
get_string('exportdiscussion', 'mod_forum'));
+ $buttonextraclass = '';
+ if (empty($button)) {
+ // no portfolio plugin available.
+ $button = '&nbsp;';
+ $buttonextraclass = ' noavailable';
+ }
+ echo html_writer::tag('div', $button, array('class'
=> 'discussioncontrol exporttoportfolio'.$buttonextraclass));
+ } else {
+ echo html_writer::tag('div', '&nbsp;',
array('class'=>'discussioncontrol nullcontrol'));
+ }

// groups selector not needed here
-
- echo "</td><td>";
+ echo '<div class="discussioncontrol displaymode">';
forum_print_mode_form($discussion->id, $displaymode);
- echo "</td><td>";
+ echo "</div>";

if ($forum->type != 'single'
&& has_capability('mod/forum:movediscussions',
$modcontext)) {

+ echo '<div class="discussioncontrol movediscussion">';
// Popup menu to move discussions to other forums. The discussion
in a
// single discussion forum can't be moved.
$modinfo = get_fast_modinfo($course);
if (isset($modinfo->instances['forum'])) {
- if ($course->format == 'weeks') {
- $strsection = get_string("week");
- } else {
- $strsection = get_string("topic");
- }
- $section = -1;
$forummenu = array();
+ $sections = get_all_sections($course->id);
+ // Check forum types and eliminate simple discussions.
+ $forumcheck = $DB->get_records('forum', array('course' =>
$course->id),'', 'id, type');
foreach ($modinfo->instances['forum'] as $forumcm) {
if (!$forumcm->uservisible |
| !has_capability('mod/forum:startdiscussion',
get_context_instance(CONTEXT_MODULE,$forumcm->id))) {
continue;
}
-
- if (!empty($forumcm->sectionnum) and $section !=
$forumcm->sectionnum) {
- $forummenu[] = "-------------- $strsection
$forumcm->sectionnum --------------";
- }
$section = $forumcm->sectionnum;
- if ($forumcm->instance != $forum->id) {
- $url
= "discuss.php?d=$discussion->id&amp;move=$forumcm->instance&amp;sesskey=".sesskey();
- $forummenu[$url] = format_string($forumcm->name);
+ $sectionname = get_section_name($course,
$sections[$section]);
+ if (empty($forummenu[$section])) {
+ $forummenu[$section] = array($sectionname => array());
+ }
+ $forumidcompare = $forumcm->instance != $forum->id;
+ $forumtypecheck =
$forumcheck[$forumcm->instance]->type !== 'single';
+ if ($forumidcompare and $forumtypecheck) {
+ $url
= "/mod/forum/discuss.php?d=$discussion->id&move=$forumcm->instance&sesskey=".sesskey();
+ $forummenu[$section][$sectionname][$url] =
format_string($forumcm->name);
}
}
if (!empty($forummenu)) {
- echo "<div style=\"float:right;\">";
- echo popup_form("$CFG->wwwroot/mod/forum/",
$forummenu, "forummenu", "",
-
get_string("movethisdiscussionto", "forum"), "", "", true,'self','',NULL,
- get_string('move'));
+ echo '<div class="movediscussionoption">';
+ $select = new url_select($forummenu, '',
+
array(''=>get_string("movethisdiscussionto", "forum")),
+ 'forummenu', get_string('move'));
+ echo $OUTPUT->render($select);
echo "</div>";
}
}
- }
- echo "</td></tr></table>";
+ echo "</div>";
+ }
+ echo '<div class="clearfloat">&nbsp;</div>';
+ echo "</div>";

if (!empty($forum->blockafter) && !empty($forum->blockperiod)) {
- $a = new object();
+ $a = new stdClass();
$a->blockafter = $forum->blockafter;
$a->blockperiod = get_string('secondstotime'.$forum->blockperiod);
- notify(get_string('thisforumisthrottled','forum',$a));
+ echo
$OUTPUT->notification(get_string('thisforumisthrottled','forum',$a));
}

if ($forum->type == 'qanda'
&& !has_capability('mod/forum:viewqandawithoutposting', $modcontext) &&
!forum_user_has_posted($forum->id,$discussion->id,$USER->id))
{
- notify(get_string('qandanotify','forum'));
+ echo $OUTPUT->notification(get_string('qandanotify','forum'));
}

if ($move == -1 and confirm_sesskey()) {
- notify(get_string('discussionmoved', 'forum',
format_string($forum->name,true)));
+ echo $OUTPUT->notification(get_string('discussionmoved', 'forum',
format_string($forum->name,true)));
}

$canrate = has_capability('mod/forum:rate', $modcontext);
forum_print_discussion($course, $cm, $forum, $discussion, $post,
$displaymode, $canreply, $canrate);

- print_footer($course);
+ echo $OUTPUT->footer();


-?>
+
=======================================
--- /moodle/trunk/moodle.orig/mod/forum/lib.php Thu Jun 3 15:48:59 2010
+++ /moodle/trunk/moodle.orig/mod/forum/lib.php Wed May 30 15:12:10 2012
@@ -1,6 +1,32 @@
-<?php // $Id$
-
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * @package mod
+ * @subpackage forum
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/** Include required files */
require_once($CFG->libdir.'/filelib.php');
+require_once($CFG->libdir.'/eventslib.php');
+require_once($CFG->dirroot.'/user/selector/lib.php');

/// CONSTANTS ///////////////////////////////////////////////////////////

@@ -9,6 +35,7 @@
define('FORUM_MODE_THREADED', 2);
define('FORUM_MODE_NESTED', 3);

+define('FORUM_CHOOSESUBSCRIBE', 0);
define('FORUM_FORCESUBSCRIBE', 1);
define('FORUM_INITIALSUBSCRIBE', 2);
define('FORUM_DISALLOWSUBSCRIBE',3);
@@ -17,27 +44,21 @@
define('FORUM_TRACKING_OPTIONAL', 1);
define('FORUM_TRACKING_ON', 2);

-define('FORUM_UNSET_POST_RATING', -999);
-
-define ('FORUM_AGGREGATE_NONE', 0); //no ratings
-define ('FORUM_AGGREGATE_AVG', 1);
-define ('FORUM_AGGREGATE_COUNT', 2);
-define ('FORUM_AGGREGATE_MAX', 3);
-define ('FORUM_AGGREGATE_MIN', 4);
-define ('FORUM_AGGREGATE_SUM', 5);
-
/// STANDARD FUNCTIONS
///////////////////////////////////////////////////////////

/**
* Given an object containing all the necessary data,
- * (defined by the form in mod.html) this function
+ * (defined by the form in mod_form.php) this function
* will create a new instance and return the id number
* of the new instance.
+ *
+ * @global object
+ * @global object
* @param object $forum add forum instance (with magic quotes)
* @return int intance id
*/
-function forum_add_instance($forum) {
- global $CFG;
+function forum_add_instance($forum, $mform) {
+ global $CFG, $DB;

$forum->timemodified = time();

@@ -50,23 +71,32 @@
$forum->assesstimefinish = 0;
}

- if (!$forum->id = insert_record('forum', $forum)) {
- return false;
- }
+ $forum->id = $DB->insert_record('forum', $forum);
+ $modcontext = get_context_instance(CONTEXT_MODULE,
$forum->coursemodule);

if ($forum->type == 'single') { // Create related discussion.
- $discussion = new object();
- $discussion->course = $forum->course;
- $discussion->forum = $forum->id;
- $discussion->name = $forum->name;
- $discussion->intro = $forum->intro;
- $discussion->assessed = $forum->assessed;
- $discussion->format = $forum->type;
- $discussion->mailnow = false;
- $discussion->groupid = -1;
-
- if (! forum_add_discussion($discussion, $discussion->intro)) {
- error('Could not add the discussion for this forum');
+ $discussion = new stdClass();
+ $discussion->course = $forum->course;
+ $discussion->forum = $forum->id;
+ $discussion->name = $forum->name;
+ $discussion->assessed = $forum->assessed;
+ $discussion->message = $forum->intro;
+ $discussion->messageformat = $forum->introformat;
+ $discussion->messagetrust =
trusttext_trusted(get_context_instance(CONTEXT_COURSE, $forum->course));
+ $discussion->mailnow = false;
+ $discussion->groupid = -1;
+
+ $message = '';
+
+ $discussion->id = forum_add_discussion($discussion, null,
$message);
+
+ if ($mform and $draftid =
file_get_submitted_draft_itemid('introeditor')) {
+ // ugly hack - we need to copy the files somehow
+ $discussion = $DB->get_record('forum_discussions',
array('id'=>$discussion->id), '*', MUST_EXIST);
+ $post = $DB->get_record('forum_posts',
array('id'=>$discussion->firstpost), '*', MUST_EXIST);
+
+ $post->message = file_save_draft_area_files($draftid,
$modcontext->id, 'mod_forum', 'post', $post->id, array('subdirs'=>true),
$post->message);
+ $DB->set_field('forum_posts', 'message', $post->message,
array('id'=>$post->id));
}
}

@@ -77,13 +107,12 @@
/// stage. However, because the forum is brand new, we know that there
are
/// no role assignments or overrides in the forum context, so using the
/// course context gives the same list of users.
- $users =
forum_get_potential_subscribers(get_context_instance(CONTEXT_COURSE,
$forum->course), 0, 'u.id, u.email', '');
+ $users = forum_get_potential_subscribers($modcontext, 0, 'u.id,
u.email', '');
foreach ($users as $user) {
forum_subscribe($user->id, $forum->id);
}
}

- $forum = stripslashes_recursive($forum);
forum_grade_item_update($forum);

return $forum->id;
@@ -92,13 +121,15 @@

/**
* Given an object containing all the necessary data,
- * (defined by the form in mod.html) this function
+ * (defined by the form in mod_form.php) this function
* will update an existing instance with new data.
+ *
+ * @global object
* @param object $forum forum instance (with magic quotes)
* @return bool success
*/
-function forum_update_instance($forum) {
- global $USER;
+function forum_update_instance($forum, $mform) {
+ global $DB, $OUTPUT, $USER;

$forum->timemodified = time();
$forum->id = $forum->instance;
@@ -112,7 +143,7 @@
$forum->assesstimefinish = 0;
}

- $oldforum = get_record('forum', 'id', $forum->id);
+ $oldforum = $DB->get_record('forum', array('id'=>$forum->id));

// MDL-3942 - if the aggregation type or scale (i.e. max grade)
changes then recalculate the grades for the entire forum
// if scale changes - do we need to recheck the ratings, if ratings
higher than scale how do we want to respond?
@@ -122,55 +153,62 @@
}

if ($forum->type == 'single') { // Update related discussion and post.
- if (! $discussion = get_record('forum_discussions', 'forum',
$forum->id)) {
- if ($discussions = get_records('forum_discussions', 'forum',
$forum->id, 'timemodified ASC')) {
- notify('Warning! There is more than one discussion in this
forum - using the most recent');
- $discussion = array_pop($discussions);
- } else {
- // try to recover by creating initial discussion -
MDL-16262
- $discussion = new object();
- $discussion->course = $forum->course;
- $discussion->forum = $forum->id;
- $discussion->name = $forum->name;
- $discussion->intro = $forum->intro;
- $discussion->assessed = $forum->assessed;
- $discussion->format = $forum->type;
- $discussion->mailnow = false;
- $discussion->groupid = -1;
-
- forum_add_discussion($discussion, $discussion->intro);
-
- if (! $discussion =
get_record('forum_discussions', 'forum', $forum->id)) {
- error('Could not add the discussion for this forum');
- }
-
+ $discussions = $DB->get_records('forum_discussions',
array('forum'=>$forum->id), 'timemodified ASC');
+ if (!empty($discussions)) {
+ if (count($discussions) > 1) {
+ echo
$OUTPUT->notification(get_string('warnformorepost', 'forum'));
+ }
+ $discussion = array_pop($discussions);
+ } else {
+ // try to recover by creating initial discussion - MDL-16262
+ $discussion = new stdClass();
+ $discussion->course = $forum->course;
+ $discussion->forum = $forum->id;
+ $discussion->name = $forum->name;
+ $discussion->assessed = $forum->assessed;
+ $discussion->message = $forum->intro;
+ $discussion->messageformat = $forum->introformat;
+ $discussion->messagetrust = true;
+ $discussion->mailnow = false;
+ $discussion->groupid = -1;
+
+ $message = '';
+
+ forum_add_discussion($discussion, null, $message);
+
+ if (! $discussion = $DB->get_record('forum_discussions',
array('forum'=>$forum->id))) {
+ print_error('cannotadd', 'forum');
}
}
- if (! $post = get_record('forum_posts', 'id',
$discussion->firstpost)) {
- error('Could not find the first post in this forum
discussion');
+ if (! $post = $DB->get_record('forum_posts',
array('id'=>$discussion->firstpost))) {
+ print_error('cannotfindfirstpost', 'forum');
}

- $post->subject = $forum->name;
- $post->message = $forum->intro;
- $post->modified = $forum->timemodified;
- $post->userid = $USER->id; // MDL-18599, so that current
teacher can take ownership of activities
-
- if (! update_record('forum_posts', ($post))) {
- error('Could not update the first post');
+ $cm = get_coursemodule_from_instance('forum', $forum->id);
+ $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id,
MUST_EXIST);
+
+ if ($mform and $draftid =
file_get_submitted_draft_itemid('introeditor')) {
+ // ugly hack - we need to copy the files somehow
+ $discussion = $DB->get_record('forum_discussions',
array('id'=>$discussion->id), '*', MUST_EXIST);
+ $post = $DB->get_record('forum_posts',
array('id'=>$discussion->firstpost), '*', MUST_EXIST);
+
+ $post->message = file_save_draft_area_files($draftid,
$modcontext->id, 'mod_forum', 'post', $post->id, array('subdirs'=>true),
$post->message);
}

- $discussion->name = $forum->name;
-
- if (! update_record('forum_discussions', ($discussion))) {
- error('Could not update the discussion');
- }
+ $post->subject = $forum->name;
+ $post->message = $forum->intro;
+ $post->messageformat = $forum->introformat;
+ $post->messagetrust = trusttext_trusted($modcontext);
+ $post->modified = $forum->timemodified;
+ $post->userid = $USER->id; // MDL-18599, so that current
teacher can take ownership of activities
+
+ $DB->update_record('forum_posts', $post);
+ $discussion->name = $forum->name;
+ $DB->update_record('forum_discussions', $discussion);
}

- if (!update_record('forum', $forum)) {
- error('Can not update forum');
- }
-
- $forum = stripslashes_recursive($forum);
+ $DB->update_record('forum', $forum);
+
forum_grade_item_update($forum);

return true;
@@ -181,32 +219,47 @@
* Given an ID of an instance of this module,
* this function will permanently delete the instance
* and any data that depends on it.
- * @param int forum instance id
+ *
+ * @global object
+ * @param int $id forum instance id
* @return bool success
*/
function forum_delete_instance($id) {
-
- if (!$forum = get_record('forum', 'id', $id)) {
+ global $DB;
+
+ if (!$forum = $DB->get_record('forum', array('id'=>$id))) {
return false;
}
+ if (!$cm = get_coursemodule_from_instance('forum', $forum->id)) {
+ return false;
+ }
+ if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
+ return false;
+ }
+
+ $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+
+ // now get rid of all files
+ $fs = get_file_storage();
+ $fs->delete_area_files($context->id);

$result = true;

- if ($discussions = get_records('forum_discussions', 'forum',
$forum->id)) {
+ if ($discussions = $DB->get_records('forum_discussions',
array('forum'=>$forum->id))) {
foreach ($discussions as $discussion) {
- if (!forum_delete_discussion($discussion, true)) {
+ if (!forum_delete_discussion($discussion, true, $course, $cm,
$forum)) {
$result = false;
}
}
}

- if (!delete_records('forum_subscriptions', 'forum', $forum->id)) {
+ if (!$DB->delete_records('forum_subscriptions',
array('forum'=>$forum->id))) {
$result = false;
}

forum_tp_delete_read_records(-1, -1, -1, $forum->id);

- if (!delete_records('forum', 'id', $forum->id)) {
+ if (!$DB->delete_records('forum', array('id'=>$forum->id))) {
$result = false;
}

@@ -214,18 +267,122 @@

return $result;
}
+
+
+/**
+ * Indicates API features that the forum supports.
+ *
+ * @uses FEATURE_GROUPS
+ * @uses FEATURE_GROUPINGS
+ * @uses FEATURE_GROUPMEMBERSONLY
+ * @uses FEATURE_MOD_INTRO
+ * @uses FEATURE_COMPLETION_TRACKS_VIEWS
+ * @uses FEATURE_COMPLETION_HAS_RULES
+ * @uses FEATURE_GRADE_HAS_GRADE
+ * @uses FEATURE_GRADE_OUTCOMES
+ * @param string $feature
+ * @return mixed True if yes (some features may use other values)
+ */
+function forum_supports($feature) {
+ switch($feature) {
+ case FEATURE_GROUPS: return true;
+ case FEATURE_GROUPINGS: return true;
+ case FEATURE_GROUPMEMBERSONLY: return true;
+ case FEATURE_MOD_INTRO: return true;
+ case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
+ case FEATURE_COMPLETION_HAS_RULES: return true;
+ case FEATURE_GRADE_HAS_GRADE: return true;
+ case FEATURE_GRADE_OUTCOMES: return true;
+ case FEATURE_RATE: return true;
+ case FEATURE_BACKUP_MOODLE2: return true;
+ case FEATURE_SHOW_DESCRIPTION: return true;
+
+ default: return null;
+ }
+}
+
+
+/**
+ * Obtains the automatic completion state for this forum based on any
conditions
+ * in forum settings.
+ *
+ * @global object
+ * @global object
+ * @param object $course Course
+ * @param object $cm Course-module
+ * @param int $userid User ID
+ * @param bool $type Type of comparison (or/and; can be used as return
value if no conditions)
+ * @return bool True if completed, false if not. (If no conditions, then
return
+ * value depends on comparison type)
+ */
+function forum_get_completion_state($course,$cm,$userid,$type) {
+ global $CFG,$DB;
+
+ // Get forum details
+ if (!($forum=$DB->get_record('forum',array('id'=>$cm->instance)))) {
+ throw new Exception("Can't find forum {$cm->instance}");
+ }
+
+ $result=$type; // Default return value
+
+ $postcountparams=array('userid'=>$userid,'forumid'=>$forum->id);
+ $postcountsql="
+SELECT
+ COUNT(1)
+FROM
+ {forum_posts} fp
+ INNER JOIN {forum_discussions} fd ON fp.discussion=fd.id
+WHERE
+ fp.userid=:userid AND fd.forum=:forumid";
+
+ if ($forum->completiondiscussions) {
+ $value = $forum->completiondiscussions <=
+
$DB->count_records('forum_discussions',array('forum'=>$forum->id,'userid'=>$userid));
+ if ($type == COMPLETION_AND) {
+ $result = $result && $value;
+ } else {
+ $result = $result || $value;
+ }
+ }
+ if ($forum->completionreplies) {
+ $value = $forum->completionreplies <=
+ $DB->get_field_sql( $postcountsql.' AND
fp.parent<>0',$postcountparams);
+ if ($type==COMPLETION_AND) {
+ $result = $result && $value;
+ } else {
+ $result = $result || $value;
+ }
+ }
+ if ($forum->completionposts) {
+ $value = $forum->completionposts <=
$DB->get_field_sql($postcountsql,$postcountparams);
+ if ($type == COMPLETION_AND) {
+ $result = $result && $value;
+ } else {
+ $result = $result || $value;
+ }
+ }
+
+ return $result;
+}


/**
* Function to be run periodically according to the moodle cron
* Finds all posts that have yet to be mailed out, and mails them
* out to all subscribers
+ *
+ * @global object
+ * @global object
+ * @global object
+ * @uses CONTEXT_MODULE
+ * @uses CONTEXT_COURSE
+ * @uses SITEID
+ * @uses FORMAT_PLAIN
* @return void
*/
function forum_cron() {
- global $CFG, $USER;
-
- $cronuser = clone($USER);
+ global $CFG, $USER, $DB;
+
$site = get_site();

// all users that are subscribed to any post that needs sending
@@ -266,7 +423,7 @@

$discussionid = $post->discussion;
if (!isset($discussions[$discussionid])) {
- if ($discussion = get_record('forum_discussions', 'id',
$post->discussion)) {
+ if ($discussion = $DB->get_record('forum_discussions',
array('id'=> $post->discussion))) {
$discussions[$discussionid] = $discussion;
} else {
mtrace('Could not find discussion '.$discussionid);
@@ -276,7 +433,7 @@
}
$forumid = $discussions[$discussionid]->forum;
if (!isset($forums[$forumid])) {
- if ($forum = get_record('forum', 'id', $forumid)) {
+ if ($forum = $DB->get_record('forum', array('id' =>
$forumid))) {
$forums[$forumid] = $forum;
} else {
mtrace('Could not find forum '.$forumid);
@@ -286,7 +443,7 @@
}
$courseid = $forums[$forumid]->course;
if (!isset($courses[$courseid])) {
- if ($course = get_record('course', 'id', $courseid)) {
+ if ($course = $DB->get_record('course', array('id' =>
$courseid))) {
$courses[$courseid] = $course;
} else {
mtrace('Could not find course '.$courseid);
@@ -298,7 +455,7 @@
if ($cm = get_coursemodule_from_instance('forum',
$forumid, $courseid)) {
$coursemodules[$forumid] = $cm;
} else {
- mtrace('Could not course module for forum '.$forumid);
+ mtrace('Could not find course module for
forum '.$forumid);
unset($posts[$pid]);
continue;
}
@@ -308,15 +465,9 @@
// caching subscribed users of each forum
if (!isset($subscribedusers[$forumid])) {
$modcontext = get_context_instance(CONTEXT_MODULE,
$coursemodules[$forumid]->id);
- if ($subusers =
forum_subscribed_users($courses[$courseid], $forums[$forumid], 0,
$modcontext)) {
+ if ($subusers =
forum_subscribed_users($courses[$courseid], $forums[$forumid], 0,
$modcontext, "u.*")) {
foreach ($subusers as $postuser) {
- // do not try to mail users with stopped email
- if ($postuser->emailstop) {
- if (!empty($CFG->forum_logblocked)) {
- add_to_log(SITEID, 'forum', 'mail
blocked', '', '', 0, $postuser->id);
- }
- continue;
- }
+ unset($postuser->description); // not necessary
// this user is subscribed to this forum
$subscribedusers[$forumid][$postuser->id] =
$postuser->id;
// this user is a user we have to process later
@@ -341,7 +492,7 @@
@set_time_limit(120); // terminate if processing of any
account takes longer than 2 minutes

// set this so that the capabilities are cached, and
environment matches receiving user
- $USER = $userto;
+ cron_setup_user($userto);

mtrace('Processing user '.$userto->id);

@@ -349,11 +500,10 @@
$userto->viewfullnames = array();
$userto->canpost = array();
$userto->markposts = array();
- $userto->enrolledin = array();

// reset the caches
foreach ($coursemodules as $forumid=>$unused) {
- $coursemodules[$forumid]->cache = new object();
+ $coursemodules[$forumid]->cache = new stdClass();
$coursemodules[$forumid]->cache->caps = array();
unset($coursemodules[$forumid]->uservisible);
}
@@ -367,31 +517,33 @@
$cm =& $coursemodules[$forum->id];

// Do some checks to see if we can bail out now
+ // Only active enrolled users are in the list of
subscribers
if (!isset($subscribedusers[$forum->id][$userto->id])) {
continue; // user does not subscribe to this forum
}

- // Verify user is enrollend in course - if not do not send
any email
- if (!isset($userto->enrolledin[$course->id])) {
- $userto->enrolledin[$course->id] =
has_capability('moodle/course:view', get_context_instance(CONTEXT_COURSE,
$course->id));
- }
- if (!$userto->enrolledin[$course->id]) {
- // oops - this user should not receive anything from
this course
+ // Don't send email if the forum is Q&A and the user has
not posted
+ // Initial topics are still mailed
+ if ($forum->type == 'qanda'
&& !forum_get_user_posted_time($discussion->id, $userto->id) && $pid !=
$discussion->firstpost) {
+ mtrace('Did not email '.$userto->id.' because user has
not posted in discussion');
continue;
}

// Get info about the sending user
if (array_key_exists($post->userid, $users)) { // we might
know him/her already
$userfrom = $users[$post->userid];
- } else if ($userfrom = get_record('user', 'id',
$post->userid)) {
+ } else if ($userfrom = $DB->get_record('user', array('id'
=> $post->userid))) {
+ unset($userfrom->description); // not necessary
$users[$userfrom->id] = $userfrom; // fetch only once,
we can add it to user list, it will be skipped anyway
} else {
mtrace('Could not find user '.$post->userid);
continue;
}
+
+ //if we want to check that userto and userfrom are not the
same person this is probably the spot to do it

// setup global $COURSE properly - needed for roles and
languages
- course_setup($course); // More environment
+ cron_setup_user($userto, $course);

// Fill caches
if (!isset($userto->viewfullnames[$forum->id])) {
@@ -434,14 +586,12 @@
// Does the user want this post in a digest? If so
postpone it for now.
if ($userto->maildigest > 0) {
// This user wants the mails to be in digest form
- $queue = new object();
+ $queue = new stdClass();
$queue->userid = $userto->id;
$queue->discussionid = $discussion->id;
$queue->postid = $post->id;
$queue->timemodified = $post->created;
- if (!insert_record('forum_queue', $queue)) {
- mtrace("Error: mod/forum/cron.php: Could not queue
for digest mail for id $post->id to user $userto->id ($userto->email) ..
not trying again.");
- }
+ $DB->insert_record('forum_queue', $queue);
continue;
}

@@ -455,30 +605,53 @@
'List-Id: "'.$cleanforumname.'"
<moodleforum'.$forum->id.'@'.$hostname.'>',
'List-Help: '.$CFG->wwwroot.'/mod/forum/view.php?f='.$forum->id,
'Message-ID:
<moodlepost'.$post->id.'@'.$hostname.'>',
- 'In-Reply-To:
<moodlepost'.$post->parent.'@'.$hostname.'>',
- 'References:
<moodlepost'.$post->parent.'@'.$hostname.'>',
'X-Course-Id: '.$course->id,
'X-Course-Name: '.format_string($course->fullname,
true)
);

-
- $postsubject
= "$course->shortname: ".format_string($post->subject,true);
- $posttext = forum_make_mail_text($course, $forum,
$discussion, $post, $userfrom, $userto);
- $posthtml = forum_make_mail_html($course, $forum,
$discussion, $post, $userfrom, $userto);
+ if ($post->parent) { // This post is a reply, so add
headers for threading (see MDL-22551)
+ $userfrom->customheaders[] = 'In-Reply-To:
<moodlepost'.$post->parent.'@'.$hostname.'>';
+ $userfrom->customheaders[] = 'References:
<moodlepost'.$post->parent.'@'.$hostname.'>';
+ }
+
+ $shortname = format_string($course->shortname, true,
array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+
+ $postsubject
= "$shortname: ".format_string($post->subject,true);
+ $posttext = forum_make_mail_text($course, $cm, $forum,
$discussion, $post, $userfrom, $userto);
+ $posthtml = forum_make_mail_html($course, $cm, $forum,
$discussion, $post, $userfrom, $userto);

// Send the post now!

mtrace('Sending ', '');

- if (!$mailresult = email_to_user($userto, $userfrom,
$postsubject, $posttext,
- $posthtml, '', '',
$CFG->forum_replytouser)) {
- mtrace("Error: mod/forum/cron.php: Could not send out
mail for id $post->id to user $userto->id".
+ $eventdata = new stdClass();
+ $eventdata->component = 'mod_forum';
+ $eventdata->name = 'posts';
+ $eventdata->userfrom = $userfrom;
+ $eventdata->userto = $userto;
+ $eventdata->subject = $postsubject;
+ $eventdata->fullmessage = $posttext;
+ $eventdata->fullmessageformat = FORMAT_PLAIN;
+ $eventdata->fullmessagehtml = $posthtml;
+ $eventdata->notification = 1;
+
+ $smallmessagestrings = new stdClass();
+ $smallmessagestrings->user = fullname($userfrom);
+ $smallmessagestrings->forumname
= "$shortname: ".format_string($forum->name,true).": ".$discussion->name;
+ $smallmessagestrings->message = $post->message;
+ //make sure strings are in message recipients language
+ $eventdata->smallmessage =
get_string_manager()->get_string('smallmessage', 'forum',
$smallmessagestrings, $userto->lang);
+
+ $eventdata->contexturl
= "{$CFG->wwwroot}/mod/forum/discuss.php?d={$discussion->id}#p{$post->id}";
+ $eventdata->contexturlname = $discussion->name;
+
+ $mailresult = message_send($eventdata);
+ if (!$mailresult){
+ mtrace("Error: mod/forum/lib.php forum_cron(): Could
not send out mail for id $post->id to user $userto->id".
" ($userto->email) .. not trying again.");
add_to_log($course->id, 'forum', 'mail
error', "discuss.php?d=$discussion->id#p$post->id",

substr(format_string($post->subject,true),0,30), $cm->id, $userto->id);
$errorcount[$post->id]++;
- } else if ($mailresult === 'emailstop') {
- // should not be reached anymore - see check above
} else {
$mailcount[$post->id]++;

@@ -500,7 +673,7 @@
foreach ($posts as $post) {
mtrace($mailcount[$post->id]." users were sent post
$post->id, '$post->subject'");
if ($errorcount[$post->id]) {
- set_field("forum_posts", "mailed", "2", "id", "$post->id");
+ $DB->set_field("forum_posts", "mailed", "2", array("id"
=> "$post->id"));
}
}
}
@@ -510,8 +683,7 @@
unset($mailcount);
unset($errorcount);

- $USER = clone($cronuser);
- course_setup(SITEID);
+ cron_setup_user();

$sitetimezone = $CFG->timezone;

@@ -530,16 +702,16 @@

// Delete any really old ones (normally there shouldn't be any)
$weekago = $timenow - (7 * 24 * 3600);
- delete_records_select('forum_queue', "timemodified < $weekago");
+ $DB->delete_records_select('forum_queue', "timemodified < ?",
array($weekago));
mtrace ('Cleaned old digest records');

if ($CFG->digestmailtimelast < $digesttime and $timenow > $digesttime)
{

mtrace('Sending forum digests: '.userdate($timenow, '',
$sitetimezone));

- $digestposts_rs =
get_recordset_select('forum_queue', "timemodified < $digesttime");
-
- if (!rs_EOF($digestposts_rs)) {
+ $digestposts_rs =
$DB->get_recordset_select('forum_queue', "timemodified < ?",
array($digesttime));
+
+ if ($digestposts_rs->valid()) {

// We have work to do
$usermailcount = 0;
@@ -548,24 +720,18 @@
$discussionposts = array();
$userdiscussions = array();

- while ($digestpost = rs_fetch_next_record($digestposts_rs)) {
+ foreach ($digestposts_rs as $digestpost) {
if (!isset($users[$digestpost->userid])) {
- if ($user = get_record('user', 'id',
$digestpost->userid)) {
+ if ($user = $DB->get_record('user', array('id' =>
$digestpost->userid))) {
$users[$digestpost->userid] = $user;
} else {
continue;
}
}
$postuser = $users[$digestpost->userid];
- if ($postuser->emailstop) {
- if (!empty($CFG->forum_logblocked)) {
- add_to_log(SITEID, 'forum', 'mail
blocked', '', '', 0, $postuser->id);
- }
- continue;
- }

if (!isset($posts[$digestpost->postid])) {
- if ($post = get_record('forum_posts', 'id',
$digestpost->postid)) {
+ if ($post = $DB->get_record('forum_posts', array('id'
=> $digestpost->postid))) {
$posts[$digestpost->postid] = $post;
} else {
continue;
@@ -573,7 +739,7 @@
}
$discussionid = $digestpost->discussionid;
if (!isset($discussions[$discussionid])) {
- if ($discussion =
get_record('forum_discussions', 'id', $discussionid)) {
+ if ($discussion = $DB->get_record('forum_discussions',
array('id' => $discussionid))) {
$discussions[$discussionid] = $discussion;
} else {
continue;
@@ -581,7 +747,7 @@
}
$forumid = $discussions[$discussionid]->forum;
if (!isset($forums[$forumid])) {
- if ($forum = get_record('forum', 'id', $forumid)) {
+ if ($forum = $DB->get_record('forum', array('id' =>
$forumid))) {
$forums[$forumid] = $forum;
} else {
continue;
@@ -590,7 +756,7 @@

$courseid = $forums[$forumid]->course;
if (!isset($courses[$courseid])) {
- if ($course = get_record('course', 'id', $courseid)) {
+ if ($course = $DB->get_record('course', array('id' =>
$courseid))) {
$courses[$courseid] = $course;
} else {
continue;
@@ -607,26 +773,24 @@

$userdiscussions[$digestpost->userid][$digestpost->discussionid] =
$digestpost->discussionid;

$discussionposts[$digestpost->discussionid][$digestpost->postid] =
$digestpost->postid;
}
- rs_close($digestposts_rs); /// Finished iteration, let's close
the resultset
+ $digestposts_rs->close(); /// Finished iteration, let's close
the resultset

// Data collected, start sending out emails to each user
foreach ($userdiscussions as $userid => $thesediscussions) {

@set_time_limit(120); // terminate if processing of any
account takes longer than 2 minutes

- $USER = $cronuser;
- course_setup(SITEID); // reset cron user language, theme
and timezone settings
+ cron_setup_user();

mtrace(get_string('processingdigest', 'forum',
$userid), '... ');

// First of all delete all the queue entries for this user
- delete_records_select('forum_queue', "userid = $userid AND
timemodified < $digesttime");
+ $DB->delete_records_select('forum_queue', "userid = ? AND
timemodified < ?", array($userid, $digesttime));
$userto = $users[$userid];

// Override the language and timezone of the "current"
user, so that
// mail is customised for the receiver.
- $USER = $userto;
- course_setup(SITEID);
+ cron_setup_user($userto);

// init caches
$userto->viewfullnames = array();
@@ -635,7 +799,7 @@

$postsubject = get_string('digestmailsubject', 'forum',
format_string($site->shortname, true));

- $headerdata = new object();
+ $headerdata = new stdClass();
$headerdata->sitename = format_string($site->fullname,
true);
$headerdata->userprefs =
$CFG->wwwroot.'/user/edit.php?id='.$userid.'&amp;course='.$site->id;

@@ -643,9 +807,10 @@
$headerdata->userprefs = '<a target="_blank"
href="'.$headerdata->userprefs.'">'.get_string('digestmailprefs', 'forum').'</a>';

$posthtml = "<head>";
- foreach ($CFG->stylesheets as $stylesheet) {
+/* foreach ($CFG->stylesheets as $stylesheet) {
+ //TODO: MDL-21120
$posthtml .= '<link rel="stylesheet" type="text/css"
href="'.$stylesheet.'" />'."\n";
- }
+ }*/
$posthtml .= "</head>\n<body id=\"email\">\n";
$posthtml .= '<p>'.get_string('digestmailheader', 'forum',
$headerdata).'</p><br /><hr size="1" noshade="noshade" />';

@@ -659,7 +824,7 @@
$cm = $coursemodules[$forum->id];

//override language
- course_setup($course);
+ cron_setup_user($userto, $course);

// Fill caches
if (!isset($userto->viewfullnames[$forum->id])) {
@@ -674,18 +839,19 @@
$strforums = get_string('forums', 'forum');
$canunsubscribe = ! forum_is_forcesubscribed($forum);
$canreply = $userto->canpost[$discussion->id];
+ $shortname = format_string($course->shortname, true,
array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));

$posttext .= "\n \n";

$posttext .= '=====================================================================';
$posttext .= "\n \n";
- $posttext .= "$course->shortname -> $strforums
-> ".format_string($forum->name,true);
+ $posttext .= "$shortname -> $strforums
-> ".format_string($forum->name,true);
if ($discussion->name != $forum->name) {
$posttext .= "
-> ".format_string($discussion->name,true);
}
$posttext .= "\n";

$posthtml .= "<p><font face=\"sans-serif\">".
- "<a target=\"_blank\"
href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>
-> ".
+ "<a target=\"_blank\"
href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$shortname</a> -> ".
"<a target=\"_blank\"
href=\"$CFG->wwwroot/mod/forum/index.php?id=$course->id\">$strforums</a>
-> ".
"<a target=\"_blank\"
href=\"$CFG->wwwroot/mod/forum/view.php?f=$forum->id\">".format_string($forum->name,true)."</a>";
if ($discussion->name == $forum->name) {
@@ -703,7 +869,7 @@

if (array_key_exists($post->userid, $users)) { //
we might know him/her already
$userfrom = $users[$post->userid];
- } else if ($userfrom = get_record('user', 'id',
$post->userid)) {
+ } else if ($userfrom = $DB->get_record('user',
array('id' => $post->userid))) {
$users[$userfrom->id] = $userfrom; // fetch
only once, we can add it to user list, it will be skipped anyway
} else {
mtrace('Could not find user '.$post->userid);
@@ -723,7 +889,7 @@

if ($userto->maildigest == 2) {
// Subjects only
- $by = new object();
+ $by = new stdClass();
$by->name = fullname($userfrom);
$by->date = userdate($post->modified);

$posttext .= "\n".format_string($post->subject,true).' '.get_string("bynameondate", "forum",
$by);
@@ -734,8 +900,8 @@

} else {
// The full treatment
- $posttext .= forum_make_mail_text($course,
$forum, $discussion, $post, $userfrom, $userto, true);
- $posthtml .= forum_make_mail_post($course,
$forum, $discussion, $post, $userfrom, $userto, false, $canreply, true,
false);
+ $posttext .= forum_make_mail_text($course,
$cm, $forum, $discussion, $post, $userfrom, $userto, true);
+ $posthtml .= forum_make_mail_post($course,
$cm, $forum, $discussion, $post, $userfrom, $userto, false, $canreply,
true, false);

// Create an array of postid's for this user to
mark as read.
if (!$CFG->forum_usermarksread) {
@@ -752,18 +918,20 @@
}
$posthtml .= '</body>';

- if ($userto->mailformat != 1) {
+ if (empty($userto->mailformat) || $userto->mailformat !=
1) {
// This user DOESN'T want to receive HTML
$posthtml = '';
}

- if (!$mailresult = email_to_user($userto,
$site->shortname, $postsubject, $posttext, $posthtml,
- '', '',
$CFG->forum_replytouser)) {
+ $attachment = $attachname='';
+ $usetrueaddress = true;
+ //directly email forum digests rather than sending them
via messaging
+ $mailresult = email_to_user($userto, $site->shortname,
$postsubject, $posttext, $posthtml, $attachment, $attachname,
$usetrueaddress, $CFG->forum_replytouser);
+
+ if (!$mailresult) {
mtrace("ERROR!");
echo "Error: mod/forum/cron.php: Could not send out
digest mail to user $userto->id ($userto->email)... not trying again.\n";
add_to_log($course->id, 'forum', 'mail digest
error', '', '', $cm->id, $userto->id);
- } else if ($mailresult === 'emailstop') {
- // should not happen anymore - see check above
} else {
mtrace("success.");
$usermailcount++;
@@ -777,8 +945,7 @@
set_config('digestmailtimelast', $timenow);
}

- $USER = $cronuser;
- course_setup(SITEID); // reset cron user language, theme and timezone
settings
+ cron_setup_user();

if (!empty($usermailcount)) {
mtrace(get_string('digestsentusers', 'forum', $usermailcount));
@@ -802,7 +969,11 @@
/**
* Builds and returns the body of the email notification in plain text.
*
+ * @global object
+ * @global object
+ * @uses CONTEXT_MODULE
* @param object $course
+ * @param object $cm
* @param object $forum
* @param object $discussion
* @param object $post
@@ -811,21 +982,18 @@
* @param boolean $bare
* @return string The email body in plain text format.
*/
-function forum_make_mail_text($course, $forum, $discussion, $post,
$userfrom, $userto, $bare = false) {
+function forum_make_mail_text($course, $cm, $forum, $discussion, $post,
$userfrom, $userto, $bare = false) {
global $CFG, $USER;

+ $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+
if (!isset($userto->viewfullnames[$forum->id])) {
- if (!$cm = get_coursemodule_from_instance('forum', $forum->id,
$course->id)) {
- error('Course Module ID was incorrect');
- }
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
$viewfullnames = has_capability('moodle/site:viewfullnames',
$modcontext, $userto->id);
} else {
$viewfullnames = $userto->viewfullnames[$forum->id];
}

if (!isset($userto->canpost[$discussion->id])) {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
$canreply = forum_user_can_post($forum, $discussion, $userto, $cm,
$course, $modcontext);
} else {
$canreply = $userto->canpost[$discussion->id];
@@ -844,12 +1012,16 @@
$posttext = '';

if (!$bare) {
- $posttext = "$course->shortname -> $strforums
-> ".format_string($forum->name,true);
+ $shortname = format_string($course->shortname, true,
array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
+ $posttext = "$shortname -> $strforums
-> ".format_string($forum->name,true);

if ($discussion->name != $forum->name) {
$posttext .= " -> ".format_string($discussion->name,true);
}
}
+
+ // add absolute file links
+ $post->message =
file_rewrite_pluginfile_urls($post->message, 'pluginfile.php',
$modcontext->id, 'mod_forum', 'post', $post->id);


$posttext .= "\n---------------------------------------------------------------------\n";
$posttext .= format_string($post->subject,true);
@@ -858,16 +1030,13 @@
}
$posttext .= "\n".$strbynameondate."\n";

$posttext .= "---------------------------------------------------------------------\n";
- $posttext .= format_text_email(trusttext_strip($post->message),
$post->format);
+ $posttext .= format_text_email($post->message, $post->messageformat);
$posttext .= "\n\n";
- if ($post->attachment) {
- $post->course = $course->id;
- $post->forum = $forum->id;
- $posttext .= forum_print_attachments($post, "text");
- }
+ $posttext .= forum_print_attachments($post, $cm, "text");
+
if (!$bare && $canreply) {

$posttext .= "---------------------------------------------------------------------\n";
- $posttext .= get_string("postmailinfo", "forum",
$course->shortname)."\n";
+ $posttext .= get_string("postmailinfo", "forum", $shortname)."\n";
$posttext .= "$CFG->wwwroot/mod/forum/post.php?reply=$post->id\n";
}
if (!$bare && $canunsubscribe) {
@@ -882,7 +1051,9 @@
/**
* Builds and returns the body of the email notification in html format.
*
+ * @global object
* @param object $course
+ * @param object $cm
* @param object $forum
* @param object $discussion
* @param object $post
@@ -890,7 +1061,7 @@
* @param object $userto
* @return string The email text in HTML format
*/
-function forum_make_mail_html($course, $forum, $discussion, $post,
$userfrom, $userto) {
+function forum_make_mail_html($course, $cm, $forum, $discussion, $post,
$userfrom, $userto) {
global $CFG;

if ($userto->mailformat != 1) { // Needs to be HTML
@@ -898,23 +1069,25 @@
}

if (!isset($userto->canpost[$discussion->id])) {
- $canreply = forum_user_can_post($forum, $discussion, $userto);
+ $canreply = forum_user_can_post($forum, $discussion, $userto, $cm,
$course);
} else {
***The diff for this file has been truncated for email.***
=======================================
--- /moodle/trunk/moodle.orig/mod/forum/post.php Thu Jun 3 15:48:59 2010
+++ /moodle/trunk/moodle.orig/mod/forum/post.php Wed May 30 15:12:10 2012
@@ -1,791 +1,878 @@
-<?php // $Id: post.php,v 1.154.2.18 2009/10/13 20:53:57 skodak Exp $
-
-// Edit and save a new post to a discussion
-
- require_once('../../config.php');
- require_once('lib.php');
-
- $reply = optional_param('reply', 0, PARAM_INT);
- $forum = optional_param('forum', 0, PARAM_INT);
- $edit = optional_param('edit', 0, PARAM_INT);
- $delete = optional_param('delete', 0, PARAM_INT);
- $prune = optional_param('prune', 0, PARAM_INT);
- $name = optional_param('name', '', PARAM_CLEAN);
- $confirm = optional_param('confirm', 0, PARAM_INT);
- $groupid = optional_param('groupid', null, PARAM_INT);
-
-
- //these page_params will be passed as hidden variables later in the
form.
- $page_params = array('reply'=>$reply, 'forum'=>$forum, 'edit'=>$edit);
-
- $sitecontext = get_context_instance(CONTEXT_SYSTEM);
-
- if (has_capability('moodle/legacy:guest', $sitecontext, NULL, false)) {
-
- $wwwroot = $CFG->wwwroot.'/login/index.php';
- if (!empty($CFG->loginhttps)) {
- $wwwroot = str_replace('http:', 'https:', $wwwroot);
- }
-
- if (!empty($forum)) { // User is starting a new discussion in
a forum
- if (! $forum = get_record('forum', 'id', $forum)) {
- error('The forum number was incorrect');
- }
- } else if (!empty($reply)) { // User is writing a new reply
- if (! $parent = forum_get_post_full($reply)) {
- error('Parent post ID was incorrect');
- }
- if (! $discussion = get_record('forum_discussions', 'id',
$parent->discussion)) {
- error('This post is not part of a discussion!');
- }
- if (! $forum = get_record('forum', 'id', $discussion->forum)) {
- error('The forum number was incorrect');
- }
- }
- if (! $course = get_record('course', 'id', $forum->course)) {
- error('The course number was incorrect');
- }
-
- if (!$cm = get_coursemodule_from_instance('forum', $forum->id,
$course->id)) { // For the logs
- error('Could not get the course module for the forum
instance.');
- } else {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
- }
-
- if (!get_referer()) { // No referer - probably coming in via
email See MDL-9052
- require_login();
- }
-
- $navigation = build_navigation('', $cm);
- print_header($course->shortname, $course->fullname,
$navigation, '' , '', true, "", navmenu($course, $cm));
-
- notice_yesno(get_string('noguestpost', 'forum').'<br /><br
/>'.get_string('liketologin'),
- $wwwroot, get_referer(false));
- print_footer($course);
- exit;
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Edit and save a new post to a discussion
+ *
+ * @package mod-forum
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once('../../config.php');
+require_once('lib.php');
+require_once($CFG->libdir.'/completionlib.php');
+
+$reply = optional_param('reply', 0, PARAM_INT);
+$forum = optional_param('forum', 0, PARAM_INT);
+$edit = optional_param('edit', 0, PARAM_INT);
+$delete = optional_param('delete', 0, PARAM_INT);
+$prune = optional_param('prune', 0, PARAM_INT);
+$name = optional_param('name', '', PARAM_CLEAN);
+$confirm = optional_param('confirm', 0, PARAM_INT);
+$groupid = optional_param('groupid', null, PARAM_INT);
+
+$PAGE->set_url('/mod/forum/post.php', array(
+ 'reply' => $reply,
+ 'forum' => $forum,
+ 'edit' => $edit,
+ 'delete'=> $delete,
+ 'prune' => $prune,
+ 'name' => $name,
+ 'confirm'=>$confirm,
+ 'groupid'=>$groupid,
+ ));
+//these page_params will be passed as hidden variables later in the form.
+$page_params = array('reply'=>$reply, 'forum'=>$forum, 'edit'=>$edit);
+
+$sitecontext = get_context_instance(CONTEXT_SYSTEM);
+
+if (!isloggedin() or isguestuser()) {
+
+ if (!isloggedin() and !get_referer()) {
+ // No referer+not logged in - probably coming in via email See
MDL-9052
+ require_login();
+ }
+
+ if (!empty($forum)) { // User is starting a new discussion in a
forum
+ if (! $forum = $DB->get_record('forum', array('id' => $forum))) {
+ print_error('invalidforumid', 'forum');
+ }
+ } else if (!empty($reply)) { // User is writing a new reply
+ if (! $parent = forum_get_post_full($reply)) {
+ print_error('invalidparentpostid', 'forum');
+ }
+ if (! $discussion = $DB->get_record('forum_discussions',
array('id' => $parent->discussion))) {
+ print_error('notpartofdiscussion', 'forum');
+ }
+ if (! $forum = $DB->get_record('forum', array('id' =>
$discussion->forum))) {
+ print_error('invalidforumid');
+ }
+ }
+ if (! $course = $DB->get_record('course', array('id' =>
$forum->course))) {
+ print_error('invalidcourseid');
+ }
+
+ if (!$cm = get_coursemodule_from_instance('forum', $forum->id,
$course->id)) { // For the logs
+ print_error('invalidcoursemodule');
+ } else {
+ $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
}

- require_login(0, false); // Script is useless unless they're logged
in
-
- if (!empty($forum)) { // User is starting a new discussion in a
forum
- if (! $forum = get_record("forum", "id", $forum)) {
- error("The forum number was incorrect ($forum)");
- }
- if (! $course = get_record("course", "id", $forum->course)) {
- error("The course number was incorrect ($forum->course)");
- }
- if (! $cm = get_coursemodule_from_instance("forum", $forum->id,
$course->id)) {
- error("Incorrect course module");
- }
-
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
-
- if (! forum_user_can_post_discussion($forum, $groupid, -1, $cm)) {
- if (has_capability('moodle/legacy:guest', $coursecontext,
NULL, false)) { // User is a guest here!
- $SESSION->wantsurl = $FULLME;
- $SESSION->enrolcancel = $_SERVER['HTTP_REFERER'];
-
redirect($CFG->wwwroot.'/course/enrol.php?id='.$course->id,
get_string('youneedtoenrol'));
- } else {
- print_error('nopostforum', 'forum');
+ $PAGE->set_cm($cm, $course, $forum);
+ $PAGE->set_context($modcontext);
+ $PAGE->set_title($course->shortname);
+ $PAGE->set_heading($course->fullname);
+
+ echo $OUTPUT->header();
+ echo $OUTPUT->confirm(get_string('noguestpost', 'forum').'<br /><br
/>'.get_string('liketologin'), get_login_url(), get_referer(false));
+ echo $OUTPUT->footer();
+ exit;
+}
+
+require_login(0, false); // Script is useless unless they're logged in
+
+if (!empty($forum)) { // User is starting a new discussion in a forum
+ if (! $forum = $DB->get_record("forum", array("id" => $forum))) {
+ print_error('invalidforumid', 'forum');
+ }
+ if (! $course = $DB->get_record("course", array("id" =>
$forum->course))) {
+ print_error('invalidcourseid');
+ }
+ if (! $cm = get_coursemodule_from_instance("forum", $forum->id,
$course->id)) {
+ print_error("invalidcoursemodule");
+ }
+
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+
+ if (! forum_user_can_post_discussion($forum, $groupid, -1, $cm)) {
+ if (!isguestuser()) {
+ if (!is_enrolled($coursecontext)) {
+ if (enrol_selfenrol_available($course->id)) {
+ $SESSION->wantsurl = $FULLME;
+ $SESSION->enrolcancel = $_SERVER['HTTP_REFERER'];
+
redirect($CFG->wwwroot.'/enrol/index.php?id='.$course->id,
get_string('youneedtoenrol'));
+ }
}
}
-
- if (!$cm->visible
and !has_capability('moodle/course:viewhiddenactivities', $coursecontext)) {
- print_error("activityiscurrentlyhidden");
- }
-
- if (isset($_SERVER["HTTP_REFERER"])) {
- $SESSION->fromurl = $_SERVER["HTTP_REFERER"];
- } else {
- $SESSION->fromurl = '';
- }
+ print_error('nopostforum', 'forum');
+ }
+
+ if (!$cm->visible
and !has_capability('moodle/course:viewhiddenactivities', $coursecontext)) {
+ print_error("activityiscurrentlyhidden");
+ }
+
+ if (isset($_SERVER["HTTP_REFERER"])) {
+ $SESSION->fromurl = $_SERVER["HTTP_REFERER"];
+ } else {
+ $SESSION->fromurl = '';
+ }


- // Load up the $post variable.
-
- $post = new object();
- $post->course = $course->id;
- $post->forum = $forum->id;
- $post->discussion = 0; // ie discussion # not defined yet
- $post->parent = 0;
- $post->subject = '';
- $post->userid = $USER->id;
- $post->message = '';
-
- if (isset($groupid)) {
- $post->groupid = $groupid;
- } else {
- $post->groupid = groups_get_activity_group($cm);
- }
-
- forum_set_return();
-
- } else if (!empty($reply)) { // User is writing a new reply
-
- if (! $parent = forum_get_post_full($reply)) {
- error("Parent post ID was incorrect");
- }
- if (! $discussion = get_record("forum_discussions", "id",
$parent->discussion)) {
- error("This post is not part of a discussion!");
- }
- if (! $forum = get_record("forum", "id", $discussion->forum)) {
- error("The forum number was incorrect ($discussion->forum)");
- }
- if (! $course = get_record("course", "id", $discussion->course)) {
- error("The course number was incorrect ($discussion->course)");
- }
- if (! $cm = get_coursemodule_from_instance("forum", $forum->id,
$course->id)) {
- error("Incorrect cm");
- }
-
- // call course_setup to use forced language, MDL-6926
- course_setup($course->id);
-
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
-
- if (! forum_user_can_post($forum, $discussion, $USER, $cm,
$course, $modcontext)) {
- if (has_capability('moodle/legacy:guest', $coursecontext,
NULL, false)) { // User is a guest here!
+ // Load up the $post variable.
+
+ $post = new stdClass();
+ $post->course = $course->id;
+ $post->forum = $forum->id;
+ $post->discussion = 0; // ie discussion # not defined yet
+ $post->parent = 0;
+ $post->subject = '';
+ $post->userid = $USER->id;
+ $post->message = '';
+ $post->messageformat = editors_get_preferred_format();
+ $post->messagetrust = 0;
+
+ if (isset($groupid)) {
+ $post->groupid = $groupid;
+ } else {
+ $post->groupid = groups_get_activity_group($cm);
+ }
+
+ forum_set_return();
+
+} else if (!empty($reply)) { // User is writing a new reply
+
+ if (! $parent = forum_get_post_full($reply)) {
+ print_error('invalidparentpostid', 'forum');
+ }
+ if (! $discussion = $DB->get_record("forum_discussions", array("id" =>
$parent->discussion))) {
+ print_error('notpartofdiscussion', 'forum');
+ }
+ if (! $forum = $DB->get_record("forum", array("id" =>
$discussion->forum))) {
+ print_error('invalidforumid', 'forum');
+ }
+ if (! $course = $DB->get_record("course", array("id" =>
$discussion->course))) {
+ print_error('invalidcourseid');
+ }
+ if (! $cm = get_coursemodule_from_instance("forum", $forum->id,
$course->id)) {
+ print_error('invalidcoursemodule');
+ }
+
+ // Ensure lang, theme, etc. is set up properly. MDL-6926
+ $PAGE->set_cm($cm, $course, $forum);
+
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+
+ if (! forum_user_can_post($forum, $discussion, $USER, $cm, $course,
$modcontext)) {
+ if (!isguestuser()) {
+ if (!is_enrolled($coursecontext)) { // User is a guest here!
$SESSION->wantsurl = $FULLME;
$SESSION->enrolcancel = $_SERVER['HTTP_REFERER'];
-
redirect($CFG->wwwroot.'/course/enrol.php?id='.$course->id,
get_string('youneedtoenrol'));
- } else {
- print_error('nopostforum', 'forum');
+ redirect($CFG->wwwroot.'/enrol/index.php?id='.$course->id,
get_string('youneedtoenrol'));
}
}
-
- // Make sure user can post here
- if (groupmode($course, $cm) == SEPARATEGROUPS
and !has_capability('moodle/site:accessallgroups', $modcontext)) {
- if ($discussion->groupid == -1) {
+ print_error('nopostforum', 'forum');
+ }
+
+ // Make sure user can post here
+ if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
+ $groupmode = $cm->groupmode;
+ } else {
+ $groupmode = $course->groupmode;
+ }
+ if ($groupmode == SEPARATEGROUPS
and !has_capability('moodle/site:accessallgroups', $modcontext)) {
+ if ($discussion->groupid == -1) {
+ print_error('nopostforum', 'forum');
+ } else {
+ if (!groups_is_member($discussion->groupid)) {
print_error('nopostforum', 'forum');
- } else {
- if (!groups_is_member($discussion->groupid)) {
- print_error('nopostforum', 'forum');
- }
}
}
-
- if (!$cm->visible
and !has_capability('moodle/course:viewhiddenactivities', $coursecontext)) {
- print_error("activityiscurrentlyhidden");
- }
-
- // Load up the $post variable.
-
- $post = new object();
- $post->course = $course->id;
- $post->forum = $forum->id;
- $post->discussion = $parent->discussion;
- $post->parent = $parent->id;
- $post->subject = $parent->subject;
- $post->userid = $USER->id;
- $post->message = '';
-
- $post->groupid = ($discussion->groupid == -1) ? 0 :
$discussion->groupid;
-
- $strre = get_string('re', 'forum');
- if (!(substr($post->subject, 0, strlen($strre)) == $strre)) {
- $post->subject = $strre.' '.$post->subject;
- }
-
- unset($SESSION->fromdiscussion);
-
- } else if (!empty($edit)) { // User is editing their own post
-
- if (! $post = forum_get_post_full($edit)) {
- error("Post ID was incorrect");
- }
- if ($post->parent) {
- if (! $parent = forum_get_post_full($post->parent)) {
- error("Parent post ID was incorrect ($post->parent)");
- }
- }
-
- if (! $discussion = get_record("forum_discussions", "id",
$post->discussion)) {
- error("This post is not part of a discussion! ($edit)");
- }
- if (! $forum = get_record("forum", "id", $discussion->forum)) {
- error("The forum number was incorrect ($discussion->forum)");
- }
- if (! $course = get_record("course", "id", $discussion->course)) {
- error("The course number was incorrect ($discussion->course)");
- }
- if (!$cm = get_coursemodule_from_instance("forum", $forum->id,
$course->id)) {
- error('Could not get the course module for the forum
instance.');
- } else {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
- }
- if (!($forum->type == 'news' && !$post->parent &&
$discussion->timestart > time())) {
- if (((time() - $post->created) > $CFG->maxeditingtime) and
- !has_capability('mod/forum:editanypost',
$modcontext)) {
- error( get_string("maxtimehaspassed", "forum",
format_time($CFG->maxeditingtime)) );
- }
- }
- if (($post->userid <> $USER->id) and
+ }
+
+ if (!$cm->visible
and !has_capability('moodle/course:viewhiddenactivities', $coursecontext)) {
+ print_error("activityiscurrentlyhidden");
+ }
+
+ // Load up the $post variable.
+
+ $post = new stdClass();
+ $post->course = $course->id;
+ $post->forum = $forum->id;
+ $post->discussion = $parent->discussion;
+ $post->parent = $parent->id;
+ $post->subject = $parent->subject;
+ $post->userid = $USER->id;
+ $post->message = '';
+
+ $post->groupid = ($discussion->groupid == -1) ? 0 :
$discussion->groupid;
+
+ $strre = get_string('re', 'forum');
+ if (!(substr($post->subject, 0, strlen($strre)) == $strre)) {
+ $post->subject = $strre.' '.$post->subject;
+ }
+
+ unset($SESSION->fromdiscussion);
+
+} else if (!empty($edit)) { // User is editing their own post
+
+ if (! $post = forum_get_post_full($edit)) {
+ print_error('invalidpostid', 'forum');
+ }
+ if ($post->parent) {
+ if (! $parent = forum_get_post_full($post->parent)) {
+ print_error('invalidparentpostid', 'forum');
+ }
+ }
+
+ if (! $discussion = $DB->get_record("forum_discussions", array("id" =>
$post->discussion))) {
+ print_error('notpartofdiscussion', 'forum');
+ }
+ if (! $forum = $DB->get_record("forum", array("id" =>
$discussion->forum))) {
+ print_error('invalidforumid', 'forum');
+ }
+ if (! $course = $DB->get_record("course", array("id" =>
$discussion->course))) {
+ print_error('invalidcourseid');
+ }
+ if (!$cm = get_coursemodule_from_instance("forum", $forum->id,
$course->id)) {
+ print_error('invalidcoursemodule');
+ } else {
+ $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ }
+
+ $PAGE->set_cm($cm, $course, $forum);
+
+ if (!($forum->type == 'news' && !$post->parent &&
$discussion->timestart > time())) {
+ if (((time() - $post->created) > $CFG->maxeditingtime) and
!has_capability('mod/forum:editanypost', $modcontext))
{
- error("You can't edit other people's posts!");
- }
+ print_error('maxtimehaspassed', 'forum', '',
format_time($CFG->maxeditingtime));
+ }
+ }
+ if (($post->userid <> $USER->id) and
+ !has_capability('mod/forum:editanypost', $modcontext)) {
+ print_error('cannoteditposts', 'forum');
+ }


- // Load up the $post variable.
- $post->edit = $edit;
- $post->course = $course->id;
- $post->forum = $forum->id;
- $post->groupid = ($discussion->groupid == -1) ? 0 :
$discussion->groupid;
-
- trusttext_prepare_edit($post->message, $post->format,
can_use_html_editor(), $modcontext);
-
- unset($SESSION->fromdiscussion);
+ // Load up the $post variable.
+ $post->edit = $edit;
+ $post->course = $course->id;
+ $post->forum = $forum->id;
+ $post->groupid = ($discussion->groupid == -1) ? 0 :
$discussion->groupid;
+
+ $post = trusttext_pre_edit($post, 'message', $modcontext);
+
+ unset($SESSION->fromdiscussion);


- }else if (!empty($delete)) { // User is deleting a post
-
- if (! $post = forum_get_post_full($delete)) {
- error("Post ID was incorrect");
- }
- if (! $discussion = get_record("forum_discussions", "id",
$post->discussion)) {
- error("This post is not part of a discussion!");
- }
- if (! $forum = get_record("forum", "id", $discussion->forum)) {
- error("The forum number was incorrect ($discussion->forum)");
- }
- if (!$cm = get_coursemodule_from_instance("forum", $forum->id,
$forum->course)) {
- error('Could not get the course module for the forum
instance.');
- }
- if (!$course = get_record('course', 'id', $forum->course)) {
- error('Incorrect course');
- }
-
- require_login($course, false, $cm);
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
-
- if ( !(($post->userid == $USER->id &&
has_capability('mod/forum:deleteownpost', $modcontext))
- || has_capability('mod/forum:deleteanypost',
$modcontext)) ) {
- error("You can't delete this post!");
+}else if (!empty($delete)) { // User is deleting a post
+
+ if (! $post = forum_get_post_full($delete)) {
+ print_error('invalidpostid', 'forum');
+ }
+ if (! $discussion = $DB->get_record("forum_discussions", array("id" =>
$post->discussion))) {
+ print_error('notpartofdiscussion', 'forum');
+ }
+ if (! $forum = $DB->get_record("forum", array("id" =>
$discussion->forum))) {
+ print_error('invalidforumid', 'forum');
+ }
+ if (!$cm = get_coursemodule_from_instance("forum", $forum->id,
$forum->course)) {
+ print_error('invalidcoursemodule');
+ }
+ if (!$course = $DB->get_record('course', array('id' =>
$forum->course))) {
+ print_error('invalidcourseid');
+ }
+
+ require_login($course, false, $cm);
+ $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+
+ if ( !(($post->userid == $USER->id &&
has_capability('mod/forum:deleteownpost', $modcontext))
+ || has_capability('mod/forum:deleteanypost', $modcontext))
) {
+ print_error('cannotdeletepost', 'forum');
+ }
+
+
+ $replycount = forum_count_replies($post);
+
+ if (!empty($confirm) && confirm_sesskey()) { // User has confirmed
the delete
+ //check user capability to delete post.
+ $timepassed = time() - $post->created;
+ if (($timepassed > $CFG->maxeditingtime)
&& !has_capability('mod/forum:deleteanypost', $modcontext)) {
+ print_error("cannotdeletepost", "forum",
+ forum_go_back_to("discuss.php?d=$post->discussion"));
}

-
- $replycount = forum_count_replies($post);
-
- if (!empty($confirm) && confirm_sesskey()) { // User has
confirmed the delete
-
- if ($post->totalscore) {
- notice(get_string("couldnotdeleteratings", "forum"),
-
forum_go_back_to("discuss.php?d=$post->discussion"));
-
- } else if ($replycount
&& !has_capability('mod/forum:deleteanypost', $modcontext)) {
- print_error("couldnotdeletereplies", "forum",
-
forum_go_back_to("discuss.php?d=$post->discussion"));
-
+ if ($post->totalscore) {
+ notice(get_string('couldnotdeleteratings', 'rating'),
+ forum_go_back_to("discuss.php?d=$post->discussion"));
+
+ } else if ($replycount
&& !has_capability('mod/forum:deleteanypost', $modcontext)) {
+ print_error("couldnotdeletereplies", "forum",
+ forum_go_back_to("discuss.php?d=$post->discussion"));
+
+ } else {
+ if (! $post->parent) { // post is a discussion topic as well,
so delete discussion
+ if ($forum->type == 'single') {
+ notice("Sorry, but you are not allowed to delete that
discussion!",
+
forum_go_back_to("discuss.php?d=$post->discussion"));
+ }
+ forum_delete_discussion($discussion, false, $course, $cm,
$forum);
+
+ add_to_log($discussion->course, "forum", "delete
discussion",
+ "view.php?id=$cm->id", "$forum->id", $cm->id);
+
+ redirect("view.php?f=$discussion->forum");
+
+ } else if (forum_delete_post($post,
has_capability('mod/forum:deleteanypost', $modcontext),
+ $course, $cm, $forum)) {
+
+ if ($forum->type == 'single') {
+ // Single discussion forums are an exception. We show
+ // the forum itself since it only has one discussion
+ // thread.
+ $discussionurl = "view.php?f=$forum->id";
+ } else {
+ $discussionurl = "discuss.php?d=$post->discussion";
+ }
+
+ add_to_log($discussion->course, "forum", "delete post",
$discussionurl, "$post->id", $cm->id);
+
+ redirect(forum_go_back_to($discussionurl));
} else {
- if (! $post->parent) { // post is a discussion topic as
well, so delete discussion
- if ($forum->type == 'single') {
- notice("Sorry, but you are not allowed to delete
that discussion!",
-
forum_go_back_to("discuss.php?d=$post->discussion"));
- }
- forum_delete_discussion($discussion);
-
- add_to_log($discussion->course, "forum", "delete
discussion",
- "view.php?id=$cm->id", "$forum->id",
$cm->id);
-
- redirect("view.php?f=$discussion->forum");
-
- } else if (forum_delete_post($post,
has_capability('mod/forum:deleteanypost', $modcontext))) {
-
- if ($forum->type == 'single') {
- // Single discussion forums are an exception. We
show
- // the forum itself since it only has one
discussion
- // thread.
- $discussionurl = "view.php?f=$forum->id";
- } else {
- $discussionurl = "discuss.php?d=$post->discussion";
- }
-
- add_to_log($discussion->course, "forum", "delete
post", $discussionurl, "$post->id", $cm->id);
-
- redirect(forum_go_back_to($discussionurl));
- } else {
- error("An error occurred while deleting record
$post->id");
- }
- }
-
-
- } else { // User just asked to delete something
-
- forum_set_return();
-
- if ($replycount) {
- if (!has_capability('mod/forum:deleteanypost',
$modcontext)) {
- print_error("couldnotdeletereplies", "forum",
-
forum_go_back_to("discuss.php?d=$post->discussion"));
- }
- print_header();
- notice_yesno(get_string("deletesureplural", "forum",
$replycount+1),
- "post.php?delete=$delete&amp;confirm=$delete&amp;sesskey=".sesskey(),
-
$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#p'.$post->id);
-
- forum_print_post($post, $discussion, $forum, $cm, $course,
false, false, false);
-
- if (empty($post->edit)) {
- $forumtracked = forum_tp_is_tracked($forum);
- $posts =
forum_get_all_discussion_posts($discussion->id, "created ASC",
$forumtracked);
- forum_print_posts_nested($course, $cm, $forum,
$discussion, $post, false, false, $forumtracked, $posts);
- }
- } else {
- print_header();
- notice_yesno(get_string("deletesure", "forum",
$replycount),
- "post.php?delete=$delete&amp;confirm=$delete&amp;sesskey=".sesskey(),
-
$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#p'.$post->id);
- forum_print_post($post, $discussion, $forum, $cm, $course,
false, false, false);
- }
-
- }
- print_footer($course);
- die;
-
-
- } else if (!empty($prune)) { // Pruning
-
- if (!$post = forum_get_post_full($prune)) {
- error("Post ID was incorrect");
- }
- if (!$discussion = get_record("forum_discussions", "id",
$post->discussion)) {
- error("This post is not part of a discussion!");
- }
- if (!$forum = get_record("forum", "id", $discussion->forum)) {
- error("The forum number was incorrect ($discussion->forum)");
- }
- if ($forum->type == 'single') {
- error('Discussions from this forum cannot be split');
- }
- if (!$post->parent) {
- error('This is already the first post in the discussion');
- }
- if (!$cm = get_coursemodule_from_instance("forum", $forum->id,
$forum->course)) { // For the logs
- error('Could not get the course module for the forum
instance.');
- } else {
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
- }
- if (!has_capability('mod/forum:splitdiscussions', $modcontext)) {
- error("You can't split discussions!");
- }
-
- if (!empty($name) && confirm_sesskey()) { // User has confirmed
the prune
-
- $newdiscussion = new object();
- $newdiscussion->course = $discussion->course;
- $newdiscussion->forum = $discussion->forum;
- $newdiscussion->name = $name;
- $newdiscussion->firstpost = $post->id;
- $newdiscussion->userid = $discussion->userid;
- $newdiscussion->groupid = $discussion->groupid;
- $newdiscussion->assessed = $discussion->assessed;
- $newdiscussion->usermodified = $post->userid;
- $newdiscussion->timestart = $discussion->timestart;
- $newdiscussion->timeend = $discussion->timeend;
-
- if (!$newid = insert_record('forum_discussions',
$newdiscussion)) {
- error('Could not create new discussion');
- }
-
- $newpost = new object();
- $newpost->id = $post->id;
- $newpost->parent = 0;
- $newpost->subject = $name;
-
- if (!update_record("forum_posts", $newpost)) {
- error('Could not update the original post');
- }
-
- forum_change_discussionid($post->id, $newid);
-
- // update last post in each discussion
- forum_discussion_update_last_post($discussion->id);
- forum_discussion_update_last_post($newid);
-
- add_to_log($discussion->course, "forum", "prune post",
- "discuss.php?d=$newid", "$post->id", $cm->id);
-
- redirect(forum_go_back_to("discuss.php?d=$newid"));
-
- } else { // User just asked to prune something
-
- $course = get_record('course', 'id', $forum->course);
-
- $navlinks = array();
- $navlinks[] = array('name' => format_string($post->subject,
true), 'link' => "discuss.php?d=$discussion->id", 'type' => 'title');
- $navlinks[] = array('name' =>
get_string("prune", "forum"), 'link' => '', 'type' => 'title');
- $navigation = build_navigation($navlinks, $cm);
-
print_header_simple(format_string($discussion->name).": ".format_string($post->subject), "",
$navigation, '', "", true, "", navmenu($course, $cm));
-
- print_heading(get_string('pruneheading', 'forum'));
- echo '<center>';
-
- include('prune.html');
-
- forum_print_post($post, $discussion, $forum, $cm, $course,
false, false, false);
- echo '</center>';
- }
- print_footer($course);
- die;
- } else {
- error("No operation specified");
-
- }
-
- if (!isset($coursecontext)) {
- // Has not yet been set by post.php.
- $coursecontext = get_context_instance(CONTEXT_COURSE,
$forum->course);
- }
-
- if (!$cm = get_coursemodule_from_instance('forum', $forum->id,
$course->id)) { // For the logs
- error('Could not get the course module for the forum instance.');
- }
- $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
-
- // setup course variable to force form language
- // fix for MDL-6926
- course_setup($course->id);
- require_once('post_form.php');
-
- $mform_post = new mod_forum_post_form('post.php',
array('course'=>$course, 'cm'=>$cm, 'coursecontext'=>$coursecontext, 'modcontext'=>$modcontext, 'forum'=>$forum, 'post'=>$post));
-
- if ($fromform = $mform_post->get_data()) {
-
-
- require_login($course, false, $cm);
-
- if (empty($SESSION->fromurl)) {
- $errordestination
= "$CFG->wwwroot/mod/forum/view.php?f=$forum->id";
- } else {
- $errordestination = $SESSION->fromurl;
+ print_error('errorwhiledelete', 'forum');
+ }
+ }
+
+
+ } else { // User just asked to delete something
+
+ forum_set_return();
+ $PAGE->navbar->add(get_string('delete', 'forum'));
+ $PAGE->set_title($course->shortname);
+ $PAGE->set_heading($course->fullname);
+
+ if ($replycount) {
+ if (!has_capability('mod/forum:deleteanypost', $modcontext)) {
+ print_error("couldnotdeletereplies", "forum",
+ forum_go_back_to("discuss.php?d=$post->discussion"));
+ }
+ echo $OUTPUT->header();
+ echo $OUTPUT->confirm(get_string("deletesureplural", "forum",
$replycount+1),
+ "post.php?delete=$delete&confirm=$delete",
+
$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#p'.$post->id);
+
+ forum_print_post($post, $discussion, $forum, $cm, $course,
false, false, false);
+
+ if (empty($post->edit)) {
+ $forumtracked = forum_tp_is_tracked($forum);
+ $posts =
forum_get_all_discussion_posts($discussion->id, "created ASC",
$forumtracked);
+ forum_print_posts_nested($course, $cm, $forum,
$discussion, $post, false, false, $forumtracked, $posts);
+ }
+ } else {
+ echo $OUTPUT->header();
+ echo $OUTPUT->confirm(get_string("deletesure", "forum",
$replycount),
+ "post.php?delete=$delete&confirm=$delete",
+
$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#p'.$post->id);
+ forum_print_post($post, $discussion, $forum, $cm, $course,
false, false, false);
+ }
+
+ }
+ echo $OUTPUT->footer();
+ die;
+
+
+} else if (!empty($prune)) { // Pruning
+
+ if (!$post = forum_get_post_full($prune)) {
+ print_error('invalidpostid', 'forum');
+ }
+ if (!$discussion = $DB->get_record("forum_discussions", array("id" =>
$post->discussion))) {
+ print_error('notpartofdiscussion', 'forum');
+ }
+ if (!$forum = $DB->get_record("forum", array("id" =>
$discussion->forum))) {
+ print_error('invalidforumid', 'forum');
+ }
+ if ($forum->type == 'single') {
+ print_error('cannotsplit', 'forum');
+ }
+ if (!$post->parent) {
+ print_error('alreadyfirstpost', 'forum');
+ }
+ if (!$cm = get_coursemodule_from_instance("forum", $forum->id,
$forum->course)) { // For the logs
+ print_error('invalidcoursemodule');
+ } else {
+ $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ }
+ if (!has_capability('mod/forum:splitdiscussions', $modcontext)) {
+ print_error('cannotsplit', 'forum');
+ }
+
+ if (!empty($name) && confirm_sesskey()) { // User has confirmed the
prune
+
+ $newdiscussion = new stdClass();
+ $newdiscussion->course = $discussion->course;
+ $newdiscussion->forum = $discussion->forum;
+ $newdiscussion->name = $name;
+ $newdiscussion->firstpost = $post->id;
+ $newdiscussion->userid = $discussion->userid;
+ $newdiscussion->groupid = $discussion->groupid;
+ $newdiscussion->assessed = $discussion->assessed;
+ $newdiscussion->usermodified = $post->userid;
+ $newdiscussion->timestart = $discussion->timestart;
+ $newdiscussion->timeend = $discussion->timeend;
+
+ $newid = $DB->insert_record('forum_discussions', $newdiscussion);
+
+ $newpost = new stdClass();
+ $newpost->id = $post->id;
+ $newpost->parent = 0;
+ $newpost->subject = $name;
+
+ $DB->update_record("forum_posts", $newpost);
+
+ forum_change_discussionid($post->id, $newid);
+
+ // update last post in each discussion
+ forum_discussion_update_last_post($discussion->id);
+ forum_discussion_update_last_post($newid);
+
+ add_to_log($discussion->course, "forum", "prune post",
+ "discuss.php?d=$newid", "$post->id", $cm->id);
+
+ redirect(forum_go_back_to("discuss.php?d=$newid"));
+
+ } else { // User just asked to prune something
+
+ $course = $DB->get_record('course', array('id' => $forum->course));
+
+ $PAGE->set_cm($cm);
+ $PAGE->set_context($modcontext);
+ $PAGE->navbar->add(format_string($post->subject, true), new
moodle_url('/mod/forum/discuss.php', array('d'=>$discussion->id)));
+ $PAGE->navbar->add(get_string("prune", "forum"));
+
$PAGE->set_title(format_string($discussion->name).": ".format_string($post->subject));
+ $PAGE->set_heading($course->fullname);
+ echo $OUTPUT->header();
+ echo $OUTPUT->heading(get_string('pruneheading', 'forum'));
+ echo '<center>';
+
+ include('prune.html');
+
+ forum_print_post($post, $discussion, $forum, $cm, $course, false,
false, false);
+ echo '</center>';
+ }
+ echo $OUTPUT->footer();
+ die;
+} else {
+ print_error('unknowaction');
+
+}
+
+if (!isset($coursecontext)) {
+ // Has not yet been set by post.php.
+ $coursecontext = get_context_instance(CONTEXT_COURSE, $forum->course);
+}
+
+
+// from now on user must be logged on properly
+
+if (!$cm = get_coursemodule_from_instance('forum', $forum->id,
$course->id)) { // For the logs
+ print_error('invalidcoursemodule');
+}
+$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+require_login($course, false, $cm);
+
+if (isguestuser()) {
+ // just in case
+ print_error('noguest');
+}
+
+if (!isset($forum->maxattachments)) { // TODO - delete this once we add a
field to the forum table
+ $forum->maxattachments = 3;
+}
+
+require_once('post_form.php');
+
+$mform_post = new mod_forum_post_form('post.php',
array('course'=>$course, 'cm'=>$cm, 'coursecontext'=>$coursecontext, 'modcontext'=>$modcontext, 'forum'=>$forum, 'post'=>$post));
+
+$draftitemid = file_get_submitted_draft_itemid('attachments');
+file_prepare_draft_area($draftitemid,
$modcontext->id, 'mod_forum', 'attachment',
empty($post->id)?null:$post->id);
+
+//load data into form NOW!
+
+if ($USER->id != $post->userid) { // Not the original author, so add a
message to the end
+ $data->date = userdate($post->modified);
+ if ($post->messageformat == FORMAT_HTML) {
+ $data->name = '<a
href="'.$CFG->wwwroot.'/user/view.php?id='.$USER->id.'&course='.$post->course.'">'.
+ fullname($USER).'</a>';
+ $post->message .= '<p>(<span
class="edited">'.get_string('editedby', 'forum', $data).'</span>)</p>';
+ } else {
+ $data->name = fullname($USER);
+ $post->message .= "\n\n(".get_string('editedby', 'forum',
$data).')';
+ }
+}
+
+if (!empty($parent)) {
+ $heading = get_string("yourreply", "forum");
+} else {
+ if ($forum->type == 'qanda') {
+ $heading = get_string('yournewquestion', 'forum');
+ } else {
+ $heading = get_string('yournewtopic', 'forum');
+ }
+}
+
+if (forum_is_subscribed($USER->id, $forum->id)) {
+ $subscribe = true;
+
+} else if (forum_user_has_posted($forum->id, 0, $USER->id)) {
+ $subscribe = false;
+
+} else {
+ // user not posted yet - use subscription default specified in profile
+ $subscribe = !empty($USER->autosubscribe);
+}
+
+$draftid_editor = file_get_submitted_draft_itemid('message');
+$currenttext = file_prepare_draft_area($draftid_editor,
$modcontext->id, 'mod_forum', 'post', empty($post->id) ? null : $post->id,
array('subdirs'=>true), $post->message);
+$mform_post->set_data(array( 'attachments'=>$draftitemid,
+ 'general'=>$heading,
+ 'subject'=>$post->subject,
+ 'message'=>array(
+ 'text'=>$currenttext,
+ 'format'=>empty($post->messageformat) ?
editors_get_preferred_format() :
$post->messageformat,
+ 'itemid'=>$draftid_editor
+ ),
***The diff for this file has been truncated for email.***
Reply all
Reply to author
Forward
0 new messages