$textfieldoptions = array('trusttext'=>true, 'subdirs'=>true);
$blogeditform = new blog_edit_form(null, compact('existing', 'sitecontext', 'textfieldoptions', 'id'));
$draftitemid = file_get_submitted_draft_itemid('attachments');
-file_prepare_draft_area($draftitemid, $PAGE->context, 'blog_attachment', empty($id)?null:$id);
+file_prepare_draft_area($draftitemid, $PAGE->context->id, 'blog_attachment', empty($id)?null:$id);
-$draftid_editor = file_get_submitted_draft_itemid('summary');
-$currenttext = file_prepare_draft_area($draftid_editor, $PAGE->context, 'blog_post', empty($id) ? null : $id, array('subdirs'=>true), @$existing->summary);
+$editordraftid = file_get_submitted_draft_itemid('summary');
+$currenttext = file_prepare_draft_area($editordraftid, $PAGE->context->id, 'blog_post', empty($id) ? null : $id, array('subdirs'=>true), @$existing->summary);
+
+$data = array('id'=>$id, 'summary'=>array('text'=>$currenttext, 'format'=>FORMAT_HTML, 'itemid' => $editordraftid));
+$blogeditform->set_data($data); // set defaults
if ($blogeditform->is_cancelled()){
redirect($returnurl);
} else if ($fromform = $blogeditform->get_data()){
- $fromform = file_postupdate_standard_editor($fromform, 'summary', $textfieldoptions, $PAGE->get_context());
//save stuff in db
switch ($action) {
case 'add':
- $blog_entry = new blog_entry($fromform, $blogeditform);
- $blog_entry->add();
+ $blogentry = new blog_entry($fromform, $blogeditform);
+ $blogentry->summary = file_save_draft_area_files($fromform->summary['itemid'], $PAGE->context->id, 'blog_post', $blogentry->id, array('subdirs'=>true), $fromform->summary['text']);
+ $blogentry->add();
break;
case 'edit':
$entry->modid = $modid;
$entry->courseid = $courseid;
$entry->attachments = $draftitemid;
-$entry->summary = array('text' => @$existing->summary, 'format' => empty($existing->summaryformat) ? FORMAT_HTML : $existing->summaryformat, 'itemid' => $draftid_editor);
+$entry->summary = array('text' => @$existing->summary, 'format' => empty($existing->summaryformat) ? FORMAT_HTML : $existing->summaryformat, 'itemid' => $editordraftid);
$entry->summaryformat = (empty($existing->summaryformat)) ? FORMAT_HTML : $existing->summaryformat;
$PAGE->requires->data_for_js('blog_edit_existing', $entry);
$mform =& $this->_form;
- $existing = $this->_customdata['existing'];
- $entryid = $this->_customdata['id'];
- $summaryoptions = $this->_customdata['textfieldoptions'];
-
+ $entryid = $this->_customdata['id'];
$existing = $this->_customdata['existing'];
$sitecontext = $this->_customdata['sitecontext'];
$mform->addElement('header', 'general', get_string('general', 'form'));
$mform->addElement('text', 'subject', get_string('entrytitle', 'blog'), 'size="60"');
- $textfieldoptions = array('trusttext'=>true, 'subdirs'=>true);
- $mform->addElement('editor', 'summary', get_string('entrybody', 'blog'), null, $summaryoptions);
+ $mform->addElement('editor', 'summary', get_string('entrybody', 'blog'), null, array('trusttext'=>true, 'subdirs'=>true, 'maxfiles' => -1));
$mform->setType('subject', PARAM_TEXT);
$mform->addRule('subject', get_string('emptytitle', 'blog'), 'required', null, 'client');
$mform->addElement('format', 'summaryformat', get_string('format'));
- $mform->addElement('filemanager', 'attachments', get_string('attachment', 'forum'));
+ $mform->addElement('filemanager', 'attachment', get_string('attachment', 'forum'));
//disable publishstate options that are not allowed
$publishstates = array();
if (!empty($CFG->useblogassociations)) {
$mform->addElement('header', 'assochdr', get_string('associations', 'blog'));
-
+ $mform->addElement('static', 'assocdescription', '', get_string('assocdescription', 'blog'));
if (has_capability('moodle/site:doanything', get_context_instance(CONTEXT_USER, $USER->id))) {
$courses = get_courses('all', 'visible DESC, fullname ASC');
} else {
}
}
$mform->addElement('select', 'courseassoc', get_string('course'), $coursenames, 'onchange="addCourseAssociations()"');
+ $mform->setAdvanced('courseassoc');
$selectassoc = &$mform->addElement('select', 'modassoc', get_string('managemodules'), $allmodnames);
+ $mform->setAdvanced('modassoc');
$selectassoc->setMultiple(true);
$PAGE->requires->data_for_js('blog_edit_form_modnames', $this->modnames);
}
$this->add_action_buttons();
-
$mform->addElement('hidden', 'action');
$mform->setType('action', PARAM_ACTION);
$mform->setDefault('action', '');
$mform->setType('courseid', PARAM_INT);
$mform->setDefault('courseid', 0);
- $this->set_data($existing);
+ // $this->set_data($existing);
}
function validation($data, $files) {
*/
require_once($CFG->libdir.'/formslib.php');
-
+// TODO remove "Blogging is disabled" text from blog_menu when editing not on
+// DONE put Associations in Advanced items
+// TODO add descriptive text to Associations fieldset
+// TODO forceopen on preferences page
+// TODO Add Blog link under course navigation tree
+// DONE add string for invalidgroupid
+// DONE Restrict groupid entries to entries associated with the course
class blog_edit_external_form extends moodleform {
public function definition() {
global $CFG;
$mform =& $this->_form;
+ $mform->addElement('text', 'url', get_string('url'));
+ $mform->addRule('url', get_string('emptyurl', 'blog'), 'required', null, 'client');
+ $mform->setHelpButton('url', array('url', get_string('url', 'blog'), 'blog'));
+
$mform->addElement('text', 'name', get_string('name'));
// No need to require the name, it gets prefilled with the external blog's site name if empty
// $mform->addRule('name', get_string('emptyname', 'blog'), 'required', null, 'client');
$mform->addElement('textarea', 'description', get_string('description'), array('cols' => 50, 'rows' => 7));
$mform->setHelpButton('description', array('description', get_string('description', 'blog'), 'blog'));
- $mform->addElement('text', 'url', get_string('url'));
- $mform->addRule('url', get_string('emptyurl', 'blog'), 'required', null, 'client');
- $mform->setHelpButton('url', array('url', get_string('url', 'blog'), 'blog'));
-
if (!empty($CFG->usetags)) {
$mform->addElement('text', 'tags', get_string('tags'));
$mform->setHelpButton('tags', array('tags', get_string('tags', 'blog'), 'blog'));
require_once($CFG->dirroot .'/blog/locallib.php');
require_once($CFG->dirroot .'/course/lib.php');
require_once($CFG->dirroot .'/tag/lib.php');
+require_once($CFG->libdir .'/commentlib.php');
$id = optional_param('id', null, PARAM_INT);
$start = optional_param('formstart', 0, PARAM_INT);
$courseid = optional_param('courseid', null, PARAM_INT); // needed for user tabs and course tracking
$search = optional_param('search', null, PARAM_RAW);
+comment::js();
+
$url_params = compact('id', 'start', 'tag', 'userid', 'tagid', 'modid', 'entryid', 'groupid', 'courseid', 'search');
foreach ($url_params as $var => $val) {
if (empty($val)) {
$cm->context = get_context_instance(CONTEXT_MODULE, $modid);
$PAGE->set_cm($cm, $course);
}
-
+
// Case 0: No entry, mod, course or user params: all site entries to be shown (filtered by search and tag/tagid)
if (empty($entryid) && empty($modid) && empty($courseid) && empty($userid)) {
$PAGE->navbar->add($strblogentries, $blog_url);
}
// Case 1: only entryid is requested, ignore all other filters. courseid is used to give more contextual information
+ // TODO Blog entries link has entryid instead of userid
if (!empty($entryid)) {
$sql = 'SELECT u.* FROM {user} u, {post} p WHERE p.id = ? AND p.userid = u.id';
$user = $DB->get_record_sql($sql, array($entryid));
$blogkey = $settingsnav->add(get_string('blogadministration', 'blog'));
$blog = $settingsnav->get($blogkey);
$blog->forceopen = true;
-
+
$blog->add(get_string('preferences', 'blog'), new moodle_url('preferences.php'), navigation_node::TYPE_SETTING);
if ($CFG->useexternalblogs && $CFG->maxexternalblogsperuser > 0) {
$blog->add(get_string('externalblogs', 'blog'), new moodle_url('external.php'), navigation_node::TYPE_SETTING);
/**
* Constructor. If given an id, will fetch the corresponding record from the DB.
*
- * @param mixed $id_or_params A blog entry id if INT, or data for a new entry if array
+ * @param mixed $idorparams A blog entry id if INT, or data for a new entry if array
*/
- public function __construct($id_or_params=null, $form=null) {
- global $DB;
+ public function __construct($idorparams=null, $form=null) {
+ global $DB, $PAGE;
- if (!empty($id_or_params) && !is_array($id_or_params) && !is_object($id_or_params)) {
- $object = $DB->get_record('post', array('id' => $id_or_params));
+ if (!empty($idorparams) && !is_array($idorparams) && !is_object($idorparams)) {
+ $object = $DB->get_record('post', array('id' => $idorparams));
foreach ($object as $var => $val) {
$this->$var = $val;
}
- } else if (!empty($id_or_params) && (is_array($id_or_params) || is_object($id_or_params))) {
- foreach ($id_or_params as $var => $val) {
+ } else if (!empty($idorparams) && (is_array($idorparams) || is_object($idorparams))) {
+ foreach ($idorparams as $var => $val) {
$this->$var = $val;
}
}
*/
public function print_html($return=false) {
- global $USER, $CFG, $COURSE, $DB, $OUTPUT;
+ global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
+
- // Comments
$user = $DB->get_record('user', array('id'=>$this->userid));
+ // Comments
+ $cmt = new stdClass();
+ $cmt->contextid = get_context_instance(CONTEXT_USER, $user->id)->id;
+ $cmt->area = 'format_blog';
+ $cmt->itemid = $this->id;
+ $options->comments = $cmt;
- $template['body'] = format_text($this->summary, $this->format);
+ $template['body'] = format_text($this->summary, $this->format, $options);
$template['title'] = '<a id="b'. s($this->id) .'" />';
//enclose the title in nolink tags so that moodle formatting doesn't autolink the text
$template['title'] .= '<span class="nolink">'. format_string($this->subject) .'</span>';
* @return void
*/
public function edit($params=array(), $form=null) {
- global $CFG, $USER, $DB;
+ global $CFG, $USER, $DB, $PAGE;
$this->form = $form;
foreach ($params as $var => $val) {
$this->$var = $val;
}
+ $this->summary = file_save_draft_area_files($params->summary['itemid'], $PAGE->context->id, 'blog_post', $this->id, array('subdirs'=>true), $params->summary['text']);
+
if (!empty($CFG->useblogassociations)) {
$this->add_associations();
}
* @param int $id
*/
public function __construct($id=null, $type='user') {
+ global $CFG, $DB;
$this->available_types = array('user' => get_string('user'), 'group' => get_string('group'));
if (empty($id)) {
$this->params[] = $course_context->id;
}
}
+
}
}
$string['addnewentry'] = 'Add a new entry';
$string['addnewexternalblog'] = 'New external blog...';
+$string['assocdescription'] = 'If you are writing about a course and/or activity modules, select them here.';
$string['associations'] = 'Associations';
$string['associationunviewable'] = 'This entry cannot be viewed by others until a course is associated with it or the \'Publish To\' field is changed';
$string['backupblogshelp'] = 'If enabled then blogs will be included in SITE automated backups';
$string['groupblogs'] = 'Users can only see blogs for people who share a group';
$string['incorrectblogfilter'] = 'Incorrect blog filter type specified';
$string['intro'] = 'This RSS feed was automatically generated from one or more blogs.';
+$string['invalidgroupid'] = 'Invalid group ID';
$string['invalidurl'] = 'This URL is unreachable';
$string['linktooriginalentry'] = 'Link to original blog entry';
$string['maxexternalblogsperuser'] = 'Maximum number of external blogs per user';
$string['publishtonoone'] = 'Yourself (draft)';
$string['publishtosite'] = 'Anyone on this site';
$string['publishtoworld'] = 'Anyone in the world';
+$string['readfirst'] = 'Read this first';
$string['settingsupdatederror'] = 'An error has occurred, blog preference setting could not be updated';
$string['searchterm'] = 'Search: $a';
$string['siteblog'] = 'Site blog: $a';