diff --git a/element/bgimage/classes/element.php b/element/bgimage/classes/element.php index f4d6620..2a858fc 100644 --- a/element/bgimage/classes/element.php +++ b/element/bgimage/classes/element.php @@ -84,8 +84,6 @@ class element extends \customcertelement_image\element { * @param \stdClass $user the user we are rendering this for */ public function render($pdf, $preview, $user) { - global $CFG; - // If there is no element data, we have nothing to display. if (empty($this->element->data)) { return; @@ -96,10 +94,8 @@ class element extends \customcertelement_image\element { // Get the image. $fs = get_file_storage(); if ($file = $fs->get_file_by_hash($imageinfo->pathnamehash)) { - $contenthash = $file->get_contenthash(); - $l1 = $contenthash[0] . $contenthash[1]; - $l2 = $contenthash[2] . $contenthash[3]; - $location = $CFG->dataroot . '/filedir' . '/' . $l1 . '/' . $l2 . '/' . $contenthash; + $location = make_request_directory() . '/target'; + $file->copy_content_to($location); // Set the image to the size of the PDF page. $pdf->Image($location, 0, 0, $pdf->getPageWidth(), $pdf->getPageHeight()); diff --git a/element/image/classes/element.php b/element/image/classes/element.php index 4f93d32..5a0eef3 100644 --- a/element/image/classes/element.php +++ b/element/image/classes/element.php @@ -161,8 +161,6 @@ class element extends \mod_customcert\element { * @param \stdClass $user the user we are rendering this for */ public function render($pdf, $preview, $user) { - global $CFG; - // If there is no element data, we have nothing to display. if (empty($this->element->data)) { return; @@ -173,10 +171,8 @@ class element extends \mod_customcert\element { // Get the image. $fs = get_file_storage(); if ($file = $fs->get_file_by_hash($imageinfo->pathnamehash)) { - $contenthash = $file->get_contenthash(); - $l1 = $contenthash[0] . $contenthash[1]; - $l2 = $contenthash[2] . $contenthash[3]; - $location = $CFG->dataroot . '/filedir' . '/' . $l1 . '/' . $l2 . '/' . $contenthash; + $location = make_request_directory() . '/target'; + $file->copy_content_to($location); $pdf->Image($location, $this->element->posx, $this->element->posy, $imageinfo->width, $imageinfo->height); } } diff --git a/element/userpicture/classes/element.php b/element/userpicture/classes/element.php index 9b832d7..efe143f 100644 --- a/element/userpicture/classes/element.php +++ b/element/userpicture/classes/element.php @@ -136,10 +136,8 @@ class element extends \mod_customcert\element { // Show image if we found one. if ($file) { - $contenthash = $file->get_contenthash(); - $l1 = $contenthash[0] . $contenthash[1]; - $l2 = $contenthash[2] . $contenthash[3]; - $location = $CFG->dataroot . '/filedir/' . $l1 . '/' . $l2 . '/' . $contenthash; + $location = make_request_directory() . '/target'; + $file->copy_content_to($location); $pdf->Image($location, $this->element->posx, $this->element->posy, $imageinfo->width, $imageinfo->height); } else if ($preview) { // Can't find an image, but we are in preview mode then display default pic. $location = $CFG->dirroot . '/pix/u/f1.png';