Commit c548067b authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Robert Lyon
Browse files

Bug 1631795: Made image in a wallpost public

When an image is added in a wall post it will be also added
in the artefact_file_embedded so it can be seen by other users
Includes an upgrade to update old posts with embedded images.

behatnotneeded

Change-Id: I42d35e035f8fe8c846ef345709793f4c0f66ca7b
(cherry picked from commit d598dc1b)
parent 66e7c5e4
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -170,7 +170,7 @@ serve_file($path, $title, $file->get('filetype'), $options);

/**
 * Check if the image is embedded in an artefact of type:
 *     comment, annotation, annotationfeedback, blog, textbox, editnote, text.
 *     comment, annotation, annotationfeedback, blog, textbox, editnote, text, wallpost.
 * Please check first that the fileid is of type ArtefactTypeImage and that the download
 * is called with the embedded flag set.
 *
@@ -183,7 +183,7 @@ function check_is_embedded_image_visible($fileid, $includeresourcetypes = null,
    $isvisible = false;
    // Check for resource types a file may be embeded in.
    $resourcetypes = array(
        'comment', 'annotation', 'annotationfeedback', 'blog', 'textbox', 'editnote', 'text', 'introtext'
        'comment', 'annotation', 'annotationfeedback', 'blog', 'textbox', 'editnote', 'text', 'introtext', 'wallpost'
    );
    if (!empty($includeresourcetypes)) {
        if (!is_array($includeresourcetypes)) {
+16 −0
Original line number Diff line number Diff line
@@ -16,5 +16,21 @@ function xmldb_blocktype_wall_upgrade($oldversion=0) {
    if ($oldversion < 2009021801) {
        set_config_plugin('blocktype', 'wall', 'defaultpostsizelimit', 1500); // 1500 characters
    }

    if ($oldversion < 2016101700) {
        $posts = get_records_select_array('blocktype_wall_post',"text LIKE '%artefact/file/download.php%'");
        require_once('embeddedimage.php');

        foreach ($posts as $post) {
            $newtext = EmbeddedImage::prepare_embedded_images($post->text, 'wallpost', $post->id, null, $post->from);
            if ($post->text != $newtext) {
                  $updatedwallpost = new stdClass();
                  $updatedwallpost->id = $post->id;
                  $updatedwallpost->text = $newtext;
                  update_record('blocktype_wall_post', $updatedwallpost, 'id');
            }
        }
    }

    return true;
}
+4 −0
Original line number Diff line number Diff line
@@ -53,6 +53,10 @@ $form = pieform(array(
function deletepost_submit(Pieform $form, $values) {
    global $SESSION, $postid, $goto;
    delete_records('blocktype_wall_post', 'id', $postid);

    require_once('embeddedimage.php');
    EmbeddedImage::remove_embedded_images('wallpost', $postid);

    $SESSION->add_ok_msg(get_string('deletepostsuccess', 'blocktype.wall'));
    redirect($goto);
}
+12 −1
Original line number Diff line number Diff line
@@ -234,7 +234,18 @@ EOF;
            'text'     => $values['text'],
        );

        insert_record('blocktype_wall_post', $record);
        $newid = insert_record('blocktype_wall_post', $record, 'id', true);

        require_once('embeddedimage.php');
        $newtext = EmbeddedImage::prepare_embedded_images($values['text'], 'wallpost', $newid);
        // If there is an embedded image, update the src so users can have visibility
        if ($values['text'] != $newtext) {
              $updatedwallpost = new stdClass();
              $updatedwallpost->id = $newid;
              $updatedwallpost->text = $newtext;
              update_record('blocktype_wall_post', $updatedwallpost, 'id');
        }

        activity_occurred('wallpost', $record, 'blocktype', 'wall');

        $instance = new BlockInstance($values['instance']);
+2 −2
Original line number Diff line number Diff line
@@ -12,5 +12,5 @@
defined('INTERNAL') || die();

$config = new StdClass;
$config->version = 2016011400;
$config->release = '1.1.0';
$config->version = 2016101700;
$config->release = '1.2.0';