Esempio n. 1
0
$strblogs = get_string('blogs', 'blog');
if ($action === 'delete') {
    if (empty($entry->id)) {
        print_error('wrongentryid', 'blog');
    }
    if (data_submitted() && $confirm && confirm_sesskey()) {
        // Make sure the current user is the author of the blog entry, or has some deleteanyentry capability
        if (!blog_user_can_edit_entry($entry)) {
            print_error('nopermissionstodeleteentry', 'blog');
        } else {
            $entry->delete();
            blog_rss_delete_file($userid);
            redirect($returnurl);
        }
    } else {
        if (blog_user_can_edit_entry($entry)) {
            $optionsyes = array('entryid' => $id, 'action' => 'delete', 'confirm' => 1, 'sesskey' => sesskey(), 'courseid' => $courseid);
            $optionsno = array('userid' => $entry->userid, 'courseid' => $courseid);
            $PAGE->set_title("{$SITE->shortname}: {$strblogs}");
            $PAGE->set_heading($SITE->fullname);
            echo $OUTPUT->header();
            // Output the entry.
            $entry->prepare_render();
            echo $output->render($entry);
            echo '<br />';
            echo $OUTPUT->confirm(get_string('blogdeleteconfirm', 'blog'), new moodle_url('edit.php', $optionsyes), new moodle_url('index.php', $optionsno));
            echo $OUTPUT->footer();
            die;
        }
    }
} else {
Esempio n. 2
0
 /**
  * Prints or returns the HTML for this blog entry.
  *
  * @param bool $return
  * @return string
  */
 public function print_html($return = false)
 {
     global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
     $user = $DB->get_record('user', array('id' => $this->userid));
     $cmttext = '';
     if (!empty($CFG->usecomments) and $CFG->blogusecomments) {
         require_once $CFG->dirroot . '/comment/lib.php';
         // Comments
         $cmt = new stdClass();
         $cmt->context = get_context_instance(CONTEXT_USER, $user->id);
         $cmt->courseid = $PAGE->course->id;
         $cmt->area = 'format_blog';
         $cmt->itemid = $this->id;
         $cmt->showcount = $CFG->blogshowcommentscount;
         $cmt->component = 'blog';
         $comment = new comment($cmt);
         $cmttext = $comment->output(true);
     }
     $this->summary = file_rewrite_pluginfile_urls($this->summary, 'pluginfile.php', SYSCONTEXTID, 'blog', 'post', $this->id);
     $options = array('overflowdiv' => true);
     $template['body'] = format_text($this->summary, $this->summaryformat, $options) . $cmttext;
     $template['title'] = format_string($this->subject);
     $template['userid'] = $user->id;
     $template['author'] = fullname($user);
     $template['created'] = userdate($this->created);
     if ($this->created != $this->lastmodified) {
         $template['lastmod'] = userdate($this->lastmodified);
     }
     $template['publishstate'] = $this->publishstate;
     $stredit = get_string('edit');
     $strdelete = get_string('delete');
     // Check to see if the entry is unassociated with group/course level access
     $unassociatedentry = false;
     if (!empty($CFG->useblogassociations) && ($this->publishstate == 'group' || $this->publishstate == 'course')) {
         if (!$DB->record_exists('blog_association', array('blogid' => $this->id))) {
             $unassociatedentry = true;
         }
     }
     // Start printing of the blog
     $table = new html_table();
     $table->cellspacing = 0;
     $table->attributes['class'] = 'forumpost blog_entry blog' . ($unassociatedentry ? 'draft' : $template['publishstate']);
     $table->attributes['id'] = 'b' . $this->id;
     $table->width = '100%';
     $picturecell = new html_table_cell();
     $picturecell->attributes['class'] = 'picture left';
     $picturecell->text = $OUTPUT->user_picture($user);
     $table->head[] = $picturecell;
     $topiccell = new html_table_cell();
     $topiccell->attributes['class'] = 'topic starter';
     $titlelink = html_writer::link(new moodle_url('/blog/index.php', array('entryid' => $this->id)), $template['title']);
     $topiccell->text = $OUTPUT->container($titlelink, 'subject');
     $topiccell->text .= $OUTPUT->container_start('author');
     $fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $PAGE->course->id)));
     $by = new stdClass();
     $by->name = html_writer::link(new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $PAGE->course->id)), $fullname);
     $by->date = $template['created'];
     $topiccell->text .= get_string('bynameondate', 'forum', $by);
     $topiccell->text .= $OUTPUT->container_end();
     if ($this->uniquehash && $this->content) {
         if ($externalblog = $DB->get_record('blog_external', array('id' => $this->content))) {
             $urlparts = parse_url($externalblog->url);
             $topiccell->text .= $OUTPUT->container(get_string('retrievedfrom', 'blog') . get_string('labelsep', 'langconfig') . html_writer::link($urlparts['scheme'] . '://' . $urlparts['host'], $externalblog->name), 'externalblog');
         }
     }
     $topiccell->header = false;
     $table->head[] = $topiccell;
     // Actual content
     $mainrow = new html_table_row();
     $leftsidecell = new html_table_cell();
     $leftsidecell->attributes['class'] = 'left side';
     $mainrow->cells[] = $leftsidecell;
     $contentcell = new html_table_cell();
     $contentcell->attributes['class'] = 'content';
     $attachedimages = $OUTPUT->container($this->print_attachments(), 'attachments');
     // retrieve associations in case they're needed early
     $blogassociations = $DB->get_records('blog_association', array('blogid' => $this->id));
     // determine text for publish state
     switch ($template['publishstate']) {
         case 'draft':
             $blogtype = get_string('publishtonoone', 'blog');
             break;
         case 'site':
             $blogtype = get_string('publishtosite', 'blog');
             break;
         case 'public':
             $blogtype = get_string('publishtoworld', 'blog');
             break;
         default:
             $blogtype = '';
             break;
     }
     $contentcell->text .= $OUTPUT->container($blogtype, 'audience');
     $contentcell->text .= $template['body'];
     $contentcell->text .= $attachedimages;
     // Uniquehash is used as a link to an external blog
     if (!empty($this->uniquehash)) {
         $contentcell->text .= $OUTPUT->container_start('externalblog');
         $contentcell->text .= html_writer::link($this->uniquehash, get_string('linktooriginalentry', 'blog'));
         $contentcell->text .= $OUTPUT->container_end();
     }
     // Links to tags
     $officialtags = tag_get_tags_csv('post', $this->id, TAG_RETURN_HTML, 'official');
     $defaulttags = tag_get_tags_csv('post', $this->id, TAG_RETURN_HTML, 'default');
     if (!empty($CFG->usetags) && ($officialtags || $defaulttags)) {
         $contentcell->text .= $OUTPUT->container_start('tags');
         if ($officialtags) {
             $contentcell->text .= get_string('tags', 'tag') . ': ' . $OUTPUT->container($officialtags, 'officialblogtags');
             if ($defaulttags) {
                 $contentcell->text .= ', ';
             }
         }
         $contentcell->text .= $defaulttags;
         $contentcell->text .= $OUTPUT->container_end();
     }
     // Add associations
     if (!empty($CFG->useblogassociations) && $blogassociations) {
         $contentcell->text .= $OUTPUT->container_start('tags');
         $assocstr = '';
         $hascourseassocs = false;
         $assoctype = '';
         // First find and show the associated course
         foreach ($blogassociations as $assocrec) {
             $contextrec = $DB->get_record('context', array('id' => $assocrec->contextid));
             if ($contextrec->contextlevel == CONTEXT_COURSE) {
                 $assocurl = new moodle_url('/course/view.php', array('id' => $contextrec->instanceid));
                 $text = $DB->get_field('course', 'shortname', array('id' => $contextrec->instanceid));
                 //TODO: performance!!!!
                 $assocstr .= $OUTPUT->action_icon($assocurl, new pix_icon('i/course', $text), null, array(), true);
                 $hascourseassocs = true;
                 $assoctype = get_string('course');
             }
         }
         // Now show mod association
         foreach ($blogassociations as $assocrec) {
             $contextrec = $DB->get_record('context', array('id' => $assocrec->contextid));
             if ($contextrec->contextlevel == CONTEXT_MODULE) {
                 if ($hascourseassocs) {
                     $assocstr .= ', ';
                     $hascourseassocs = false;
                 }
                 $modinfo = $DB->get_record('course_modules', array('id' => $contextrec->instanceid));
                 $modname = $DB->get_field('modules', 'name', array('id' => $modinfo->module));
                 $assocurl = new moodle_url('/mod/' . $modname . '/view.php', array('id' => $modinfo->id));
                 $text = $DB->get_field($modname, 'name', array('id' => $modinfo->instance));
                 //TODO: performance!!!!
                 $assocstr .= $OUTPUT->action_icon($assocurl, new pix_icon('icon', $text, $modname), null, array(), true);
                 $assocstr .= ', ';
                 $assoctype = get_string('modulename', $modname);
             }
         }
         $assocstr = substr($assocstr, 0, -2);
         $contentcell->text .= get_string('associated', 'blog', $assoctype) . ': ' . $assocstr;
         $contentcell->text .= $OUTPUT->container_end();
     }
     if ($unassociatedentry) {
         $contentcell->text .= $OUTPUT->container(get_string('associationunviewable', 'blog'), 'noticebox');
     }
     /// Commands
     $contentcell->text .= $OUTPUT->container_start('commands');
     if (blog_user_can_edit_entry($this) && empty($this->uniquehash)) {
         $contentcell->text .= html_writer::link(new moodle_url('/blog/edit.php', array('action' => 'edit', 'entryid' => $this->id)), $stredit) . ' | ';
         $contentcell->text .= html_writer::link(new moodle_url('/blog/edit.php', array('action' => 'delete', 'entryid' => $this->id)), $strdelete) . ' | ';
     }
     $contentcell->text .= html_writer::link(new moodle_url('/blog/index.php', array('entryid' => $this->id)), get_string('permalink', 'blog'));
     $contentcell->text .= $OUTPUT->container_end();
     if (isset($template['lastmod'])) {
         $contentcell->text .= '<div style="font-size: 55%;">';
         $contentcell->text .= ' [ ' . get_string('modified') . ': ' . $template['lastmod'] . ' ]';
         $contentcell->text .= '</div>';
     }
     $mainrow->cells[] = $contentcell;
     $table->data = array($mainrow);
     if ($return) {
         return html_writer::table($table);
     } else {
         echo html_writer::table($table);
     }
 }
Esempio n. 3
0
 /**
  * Gets the required data to print the entry
  */
 public function prepare_render()
 {
     global $DB, $CFG, $PAGE;
     $this->renderable = new StdClass();
     $this->renderable->user = $DB->get_record('user', array('id' => $this->userid));
     // Entry comments.
     if (!empty($CFG->usecomments) and $CFG->blogusecomments) {
         require_once $CFG->dirroot . '/comment/lib.php';
         $cmt = new stdClass();
         $cmt->context = context_user::instance($this->userid);
         $cmt->courseid = $PAGE->course->id;
         $cmt->area = 'format_blog';
         $cmt->itemid = $this->id;
         $cmt->showcount = $CFG->blogshowcommentscount;
         $cmt->component = 'blog';
         $this->renderable->comment = new comment($cmt);
     }
     $this->summary = file_rewrite_pluginfile_urls($this->summary, 'pluginfile.php', SYSCONTEXTID, 'blog', 'post', $this->id);
     // External blog link.
     if ($this->uniquehash && $this->content) {
         if ($externalblog = $DB->get_record('blog_external', array('id' => $this->content))) {
             $urlparts = parse_url($externalblog->url);
             $this->renderable->externalblogtext = get_string('retrievedfrom', 'blog') . get_string('labelsep', 'langconfig');
             $this->renderable->externalblogtext .= html_writer::link($urlparts['scheme'] . '://' . $urlparts['host'], $externalblog->name);
         }
     }
     // Retrieve associations.
     $this->renderable->unassociatedentry = false;
     if (!empty($CFG->useblogassociations)) {
         // Adding the entry associations data.
         if ($associations = $associations = $DB->get_records('blog_association', array('blogid' => $this->id))) {
             // Check to see if the entry is unassociated with group/course level access.
             if ($this->publishstate == 'group' || $this->publishstate == 'course') {
                 $this->renderable->unassociatedentry = true;
             }
             foreach ($associations as $key => $assocrec) {
                 if (!($context = context::instance_by_id($assocrec->contextid, IGNORE_MISSING))) {
                     unset($associations[$key]);
                     continue;
                 }
                 // The renderer will need the contextlevel of the association.
                 $associations[$key]->contextlevel = $context->contextlevel;
                 // Course associations.
                 if ($context->contextlevel == CONTEXT_COURSE) {
                     // TODO: performance!!!!
                     $instancename = $DB->get_field('course', 'shortname', array('id' => $context->instanceid));
                     $associations[$key]->url = $assocurl = new moodle_url('/course/view.php', array('id' => $context->instanceid));
                     $associations[$key]->text = $instancename;
                     $associations[$key]->icon = new pix_icon('i/course', $associations[$key]->text);
                 }
                 // Mod associations.
                 if ($context->contextlevel == CONTEXT_MODULE) {
                     // Getting the activity type and the activity instance id.
                     $sql = 'SELECT cm.instance, m.name FROM {course_modules} cm
                               JOIN {modules} m ON m.id = cm.module
                              WHERE cm.id = :cmid';
                     $modinfo = $DB->get_record_sql($sql, array('cmid' => $context->instanceid));
                     // TODO: performance!!!!
                     $instancename = $DB->get_field($modinfo->name, 'name', array('id' => $modinfo->instance));
                     $associations[$key]->type = get_string('modulename', $modinfo->name);
                     $associations[$key]->url = new moodle_url('/mod/' . $modinfo->name . '/view.php', array('id' => $context->instanceid));
                     $associations[$key]->text = $instancename;
                     $associations[$key]->icon = new pix_icon('icon', $associations[$key]->text, $modinfo->name);
                 }
             }
         }
         $this->renderable->blogassociations = $associations;
     }
     // Entry attachments.
     $this->renderable->attachments = $this->get_attachments();
     $this->renderable->usercanedit = blog_user_can_edit_entry($this);
 }