Skip to content

Commit

Permalink
MDL-19676 Blog improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasconnault committed Sep 4, 2009
1 parent 5fc6d58 commit cae8370
Show file tree
Hide file tree
Showing 46 changed files with 3,908 additions and 1,126 deletions.
11 changes: 11 additions & 0 deletions admin/cron.php
Expand Up @@ -544,6 +544,17 @@
}
}
}

// Run external blog cron if needed
if ($CFG->useexternalblogs) {
require_once($CFG->dirroot . '/blog/lib.php');
$sql = "SELECT * FROM {blog_external} WHERE timefetched < ? - ? OR timefetched = 0";
$external_blogs = $DB->get_records_sql($sql, array(mktime(), $CFG->externalblogcrontime));

foreach ($external_blogs as $eb) {
blog_fetch_external_entries($eb);
}
}

// cleanup file trash
$fs = get_file_storage();
Expand Down
16 changes: 16 additions & 0 deletions admin/settings/appearance.php
Expand Up @@ -49,6 +49,22 @@
$temp->add(new admin_setting_configtext('calendar_exportsalt', get_string('calendarexportsalt','admin'), get_string('configcalendarexportsalt', 'admin'), random_string(60)));
$ADMIN->add('appearance', $temp);

// blog
$temp = new admin_settingpage('blog', get_string('blog','blog'));
$temp->add(new admin_setting_configcheckbox('useblogassociations', get_string('useblogassociations', 'blog'), get_string('configuseblogassociations','blog'), 1));
$temp->add(new admin_setting_configselect('bloglevel', get_string('bloglevel', 'admin'), get_string('configbloglevel', 'admin'), 4, array(5 => get_string('worldblogs','blog'),
4 => get_string('siteblogs','blog'),
1 => get_string('personalblogs','blog'),
0 => get_string('disableblogs','blog'))));
$temp->add(new admin_setting_configcheckbox('useexternalblogs', get_string('useexternalblogs', 'blog'), get_string('configuseexternalblogs','blog'), 1));
$temp->add(new admin_setting_configselect('externalblogcrontime', get_string('externalblogcrontime', 'blog'), get_string('configexternalblogcrontime', 'blog'), 86400,
array(43200 => get_string('numhours', '', 12),
86400 => get_string('numhours', '', 24),
172800 => get_string('numdays', '', 2),
604800 => get_string('numdays', '', 7))));
$temp->add(new admin_setting_configtext('maxexternalblogsperuser', get_string('maxexternalblogsperuser','blog'), get_string('configmaxexternalblogsperuser', 'blog'), 1));
$ADMIN->add('appearance', $temp);

/* TODO: reimplement editor settings and preferences, editors are now full plugins ;-)
// "htmleditor" settingpage
$ADMIN->add('appearance', new admin_category('htmleditor', get_string('htmleditor', 'admin')));
Expand Down
4 changes: 0 additions & 4 deletions admin/settings/security.php
Expand Up @@ -53,10 +53,6 @@
'firstname' => get_string('firstname'))));
$temp->add(new admin_setting_configcheckbox('extendedusernamechars', get_string('extendedusernamechars', 'admin'), get_string('configextendedusernamechars', 'admin'), 0));
$temp->add(new admin_setting_configtext('sitepolicy', get_string('sitepolicy', 'admin'), get_string('configsitepolicy', 'admin'), '', PARAM_RAW));
$temp->add(new admin_setting_configselect('bloglevel', get_string('bloglevel', 'admin'), get_string('configbloglevel', 'admin'), 4, array(5 => get_string('worldblogs','blog'),
4 => get_string('siteblogs','blog'),
1 => get_string('personalblogs','blog'),
0 => get_string('disableblogs','blog'))));
$temp->add(new admin_setting_configcheckbox('usetags', get_string('usetags','admin'),get_string('configusetags', 'admin'),'1'));
$temp->add(new admin_setting_configcheckbox('keeptagnamecase', get_string('keeptagnamecase','admin'),get_string('configkeeptagnamecase', 'admin'),'1'));

Expand Down
132 changes: 84 additions & 48 deletions backup/backuplib.php
Expand Up @@ -155,9 +155,9 @@ function backup_get_needed_users ($courseid, $includemessages=false, $includeblo

//Now, add blog users if necessary
if ($includeblogs) {
include_once("$CFG->dirroot/blog/lib.php");
//Get users
$blogusers = blog_get_participants();
$blogusers = $DB->get_records_sql("SELECT u.id, u.id FROM {user} u WHERE u.id IN (SELECT DISTINCT userid FROM {post})");

//Add blog users to results
if ($blogusers) {
foreach ($blogusers as $bloguser) {
Expand Down Expand Up @@ -922,54 +922,10 @@ function backup_blogs($bf, $preferences) {
fwrite ($bf, start_tag("BLOGS",2,true));

if ($siteblogs) {
$rs_blogs = $DB->get_recordset('post', array('module'=>'blog', 'courseid'=>0));
$rs_blogs = $DB->get_records('post', array('module'=>'blog', 'courseid'=>0));
/// Iterate over every blog
foreach ($rs_blogs as $blog) {
/// start blog
fwrite($bf, start_tag("BLOG",3,true));
/// blog body
fwrite ($bf,full_tag("ID",4,false,$blog->id));
fwrite ($bf,full_tag("MODULE",4,false,$blog->module));
fwrite ($bf,full_tag("USERID",4,false,$blog->userid));
fwrite ($bf,full_tag("COURSEID",4,false,$blog->courseid));
fwrite ($bf,full_tag("GROUPID",4,false,$blog->groupid));
fwrite ($bf,full_tag("MODULEID",4,false,$blog->moduleid));
fwrite ($bf,full_tag("COURSEMODULEID",4,false,$blog->coursemoduleid));
fwrite ($bf,full_tag("SUBJECT",4,false,$blog->subject));
fwrite ($bf,full_tag("SUMMARY",4,false,$blog->summary));
fwrite ($bf,full_tag("CONTENT",4,false,$blog->content));
fwrite ($bf,full_tag("UNIQUEHASH",4,false,$blog->uniquehash));
fwrite ($bf,full_tag("RATING",4,false,$blog->rating));
fwrite ($bf,full_tag("FORMAT",4,false,$blog->format));
fwrite ($bf,full_tag("ATTACHMENT",4,false,$blog->attachment));
fwrite ($bf,full_tag("PUBLISHSTATE",4,false,$blog->publishstate));
fwrite ($bf,full_tag("LASTMODIFIED",4,false,$blog->lastmodified));
fwrite ($bf,full_tag("CREATED",4,false,$blog->created));
fwrite ($bf,full_tag("USERMODIFIED",4,false,$blog->usermodified));

/// Blog tags
/// Check if we have blog tags to backup
if (!empty($CFG->usetags)) {
if ($tags = tag_get_tags('post', $blog->id)) { //This return them ordered by default
/// Start BLOG_TAGS tag
fwrite ($bf,start_tag("BLOG_TAGS",4,true));
/// Write blog tags fields
foreach ($tags as $tag) {
fwrite ($bf,start_tag("BLOG_TAG",5,true));
fwrite ($bf,full_tag("NAME",6,false,$tag->name));
fwrite ($bf,full_tag("RAWNAME",6,false,$tag->rawname));
fwrite ($bf,end_tag("BLOG_TAG",5,true));
}
/// End BLOG_TAGS tag
fwrite ($bf,end_tag("BLOG_TAGS",4,true));
}
}

/// Blog comments
/// TODO: Blog comments go here (2.0)

/// end blog
fwrite($bf, end_tag("BLOG",3,true));
backup_blog($bf, $blog->id, 3);

/// Do some output
$counter++;
Expand All @@ -990,6 +946,69 @@ function backup_blogs($bf, $preferences) {
return $status;
}


function backup_course_blogs($bf, $preferences) {
global $DB;
fwrite ($bf, start_tag("BLOGS",2,true));

$sql = 'SELECT as.data1 FROM {assignment} a, {assignment_submissions} as WHERE
as.assignment = a.id AND a.assignmenttype = \'blog\' AND a.course = ?';
$records = $DB->get_records_sql($sql, array($preferences->backup_course));
foreach ($records as $rec) {
backup_blog($bf, $rec->data1, 3);
}
fwrite($bf, end_tag("BLOGS",2,true));
}

function backup_blog($bf, $blogid, $level) {
global $DB;
$blog = $DB->get_record('post', array('module'=>'blog', 'id'=>$blogid));

/// start blog
fwrite($bf, start_tag("BLOG",$level,true));
/// blog body
fwrite ($bf,full_tag("ID",$level+1,false,$blog->id));
fwrite ($bf,full_tag("MODULE",$level+1,false,$blog->module));
fwrite ($bf,full_tag("USERID",$level+1,false,$blog->userid));
fwrite ($bf,full_tag("COURSEID",$level+1,false,$blog->courseid));
fwrite ($bf,full_tag("GROUPID",$level+1,false,$blog->groupid));
fwrite ($bf,full_tag("MODULEID",$level+1,false,$blog->moduleid));
fwrite ($bf,full_tag("COURSEMODULEID",$level+1,false,$blog->coursemoduleid));
fwrite ($bf,full_tag("SUBJECT",$level+1,false,$blog->subject));
fwrite ($bf,full_tag("SUMMARY",$level+1,false,$blog->summary));
fwrite ($bf,full_tag("CONTENT",$level+1,false,$blog->content));
fwrite ($bf,full_tag("UNIQUEHASH",$level+1,false,$blog->uniquehash));
fwrite ($bf,full_tag("RATING",$level+1,false,$blog->rating));
fwrite ($bf,full_tag("FORMAT",$level+1,false,$blog->format));
fwrite ($bf,full_tag("ATTACHMENT",$level+1,false,$blog->attachment));
fwrite ($bf,full_tag("PUBLISHSTATE",$level+1,false,$blog->publishstate));
fwrite ($bf,full_tag("LASTMODIFIED",$level+1,false,$blog->lastmodified));
fwrite ($bf,full_tag("CREATED",$level+1,false,$blog->created));
fwrite ($bf,full_tag("USERMODIFIED",$level+1,false,$blog->usermodified));

/// Blog tags
/// Check if we have blog tags to backup
if (!empty($CFG->usetags)) {
if ($tags = tag_get_tags('post', $blog->id)) { //This return them ordered by default
/// Start BLOG_TAGS tag
fwrite ($bf,start_tag("BLOG_TAGS",$level+1,true));
/// Write blog tags fields
foreach ($tags as $tag) {
fwrite ($bf,start_tag("BLOG_TAG",$level+2,true));
fwrite ($bf,full_tag("NAME",$level+3,false,$tag->name));
fwrite ($bf,full_tag("RAWNAME",$level+3,false,$tag->rawname));
fwrite ($bf,end_tag("BLOG_TAG",$level+2,true));
}
/// End BLOG_TAGS tag
fwrite ($bf,end_tag("BLOG_TAGS",$level+1,true));
}
}
/// end blog
fwrite($bf, end_tag("BLOG",$level,true));
}



/**
* Prints course's blocks info (table block_instance)
*/
Expand Down Expand Up @@ -3353,6 +3372,23 @@ function backup_execute(&$preferences, &$errorstr) {
}
}

//Backup course blog assignment data, if any.
if (!defined('BACKUP_SILENTLY')) {
echo '<li>'.get_string("courseblogdata").'</li>';
}
if($status) {
if (!$status = backup_course_blogs($backup_file,$preferences)) {
if (!defined('BACKUP_SILENTLY')) {
notify("An error occurred while backing up the course blog assignment data");
}
else {
$errorstr = "An error occurred while backing up the course blog assignment data";
return false;
}
}
}


//Prints course end
if ($status) {
if (!$status = backup_course_end($backup_file,$preferences)) {
Expand Down
92 changes: 92 additions & 0 deletions blocks/blog_externals/block_blog_externals.php
@@ -0,0 +1,92 @@
<?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/>.


/**
* Block for managing external blogs. This block will appear only on a user's blog page, not
* on any other blog listing page (site, course, module etc). It may be filtered by tag.
*
* @package moodlecore
* @subpackage blog
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once($CFG->dirroot .'/blog/lib.php');

/**
* External Blog Block class
*/
class block_blog_externals extends block_base {

function init() {
global $USER, $DB;

$this->title = get_string('blockexternalstitle', 'blog');
$this->content_type = BLOCK_TYPE_TEXT;
$this->version = 2009101509;

// See if a deletion has been requested
$delete = optional_param('delete_blog_external', false, PARAM_INT);
if ($delete && ($external_blog = $DB->get_record('blog_external', array('id' => $delete)))) {
// Check caps and userid matching $USER->id
if ($external_blog->userid == $USER->id) {
$DB->delete_records('blog_external', array('id' => $delete));
}
}
}

function get_content() {
global $CFG, $USER, $DB, $PAGE, $OUTPUT;

// This block should not appear if $CFG->useexternalblogs is off
if (empty($CFG->bloglevel)) {
$this->content->text = '';
return $this->content;
}

// don't display menu block if block is set at site level, and user is not logged in
if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL && !(isloggedin() && !isguest())) {
$this->content->text = '';
return $this->content;
}

$output = '';

$this->content = new stdClass;
$this->content->footer = '';

$external_blogs = $DB->get_records('blog_external', array('userid' => $USER->id));

$external_blog_url = $CFG->wwwroot.'/blog/external.php?returnurl='.urlencode($PAGE->url->out());

foreach ($external_blogs as $id => $eb) {
$strdelete = get_string('delete') . " $eb->name";

$delete_url = new moodle_url();
$delete_url->param('delete_blog_external', $id);
$deleteicon = '<a href="'.$delete_url->out().'" class="delete">' .
'<img src="'.$OUTPUT->old_icon_url('t/delete').'" alt="'.$strdelete.'" title="'.$strdelete.'" />' .
"</a>\n";
$output .= '<li><a href="'.$external_blog_url.'&amp;id='.$id.'" title="'.$eb->name.'">'.shorten_text($eb->name, 20)."</a>$deleteicon</li>\n";
}

$this->content->text = '<ul class="list">'. $output ."</ul>\n";
$this->content->text .= '<div class="newlink"><a href="'.$external_blog_url.'">'.get_string('addnewexternalblog', 'blog').'</a></div>';
return $this->content;
}
}

0 comments on commit cae8370

Please sign in to comment.