Merge pull request #91 from andrewnicols/contenthashfix
#89 Copy files to temp directory before accessing
This commit is contained in:
commit
c8d0e0491d
3 changed files with 6 additions and 16 deletions
|
@ -84,8 +84,6 @@ class element extends \customcertelement_image\element {
|
||||||
* @param \stdClass $user the user we are rendering this for
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview, $user) {
|
public function render($pdf, $preview, $user) {
|
||||||
global $CFG;
|
|
||||||
|
|
||||||
// If there is no element data, we have nothing to display.
|
// If there is no element data, we have nothing to display.
|
||||||
if (empty($this->element->data)) {
|
if (empty($this->element->data)) {
|
||||||
return;
|
return;
|
||||||
|
@ -96,10 +94,8 @@ class element extends \customcertelement_image\element {
|
||||||
// Get the image.
|
// Get the image.
|
||||||
$fs = get_file_storage();
|
$fs = get_file_storage();
|
||||||
if ($file = $fs->get_file_by_hash($imageinfo->pathnamehash)) {
|
if ($file = $fs->get_file_by_hash($imageinfo->pathnamehash)) {
|
||||||
$contenthash = $file->get_contenthash();
|
$location = make_request_directory() . '/target';
|
||||||
$l1 = $contenthash[0] . $contenthash[1];
|
$file->copy_content_to($location);
|
||||||
$l2 = $contenthash[2] . $contenthash[3];
|
|
||||||
$location = $CFG->dataroot . '/filedir' . '/' . $l1 . '/' . $l2 . '/' . $contenthash;
|
|
||||||
|
|
||||||
// Set the image to the size of the PDF page.
|
// Set the image to the size of the PDF page.
|
||||||
$pdf->Image($location, 0, 0, $pdf->getPageWidth(), $pdf->getPageHeight());
|
$pdf->Image($location, 0, 0, $pdf->getPageWidth(), $pdf->getPageHeight());
|
||||||
|
|
|
@ -161,8 +161,6 @@ class element extends \mod_customcert\element {
|
||||||
* @param \stdClass $user the user we are rendering this for
|
* @param \stdClass $user the user we are rendering this for
|
||||||
*/
|
*/
|
||||||
public function render($pdf, $preview, $user) {
|
public function render($pdf, $preview, $user) {
|
||||||
global $CFG;
|
|
||||||
|
|
||||||
// If there is no element data, we have nothing to display.
|
// If there is no element data, we have nothing to display.
|
||||||
if (empty($this->element->data)) {
|
if (empty($this->element->data)) {
|
||||||
return;
|
return;
|
||||||
|
@ -173,10 +171,8 @@ class element extends \mod_customcert\element {
|
||||||
// Get the image.
|
// Get the image.
|
||||||
$fs = get_file_storage();
|
$fs = get_file_storage();
|
||||||
if ($file = $fs->get_file_by_hash($imageinfo->pathnamehash)) {
|
if ($file = $fs->get_file_by_hash($imageinfo->pathnamehash)) {
|
||||||
$contenthash = $file->get_contenthash();
|
$location = make_request_directory() . '/target';
|
||||||
$l1 = $contenthash[0] . $contenthash[1];
|
$file->copy_content_to($location);
|
||||||
$l2 = $contenthash[2] . $contenthash[3];
|
|
||||||
$location = $CFG->dataroot . '/filedir' . '/' . $l1 . '/' . $l2 . '/' . $contenthash;
|
|
||||||
$pdf->Image($location, $this->element->posx, $this->element->posy, $imageinfo->width, $imageinfo->height);
|
$pdf->Image($location, $this->element->posx, $this->element->posy, $imageinfo->width, $imageinfo->height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,10 +136,8 @@ class element extends \mod_customcert\element {
|
||||||
|
|
||||||
// Show image if we found one.
|
// Show image if we found one.
|
||||||
if ($file) {
|
if ($file) {
|
||||||
$contenthash = $file->get_contenthash();
|
$location = make_request_directory() . '/target';
|
||||||
$l1 = $contenthash[0] . $contenthash[1];
|
$file->copy_content_to($location);
|
||||||
$l2 = $contenthash[2] . $contenthash[3];
|
|
||||||
$location = $CFG->dataroot . '/filedir/' . $l1 . '/' . $l2 . '/' . $contenthash;
|
|
||||||
$pdf->Image($location, $this->element->posx, $this->element->posy, $imageinfo->width, $imageinfo->height);
|
$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.
|
} 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';
|
$location = $CFG->dirroot . '/pix/u/f1.png';
|
||||||
|
|
Loading…
Reference in a new issue