예제 #1
0
파일: download.php 프로젝트: rboyatt/mahara
/**
 * Check if the image is embedded in an artefact of type:
 *     comment, annotation, annotationfeedback, blog, textbox, editnote, text.
 * Please check first that the fileid is of type ArtefactTypeImage and that the download
 * is called with the embedded flag set.
 *
 * @param int $fileid the id of the file to check.
 * @param array $includeresourcetypes an array of extra artefact types to include in the check.
 * @param array $excluderesourcetypes an array of artefact types to exclude from the check.
 * @return boolean TRUE the image is visible; FALSE the image is not visible.
 */
function check_is_embedded_image_visible($fileid, $includeresourcetypes = null, $excluderesourcetypes = null)
{
    $isvisible = false;
    // Check for resource types a file may be embeded in.
    $resourcetypes = array('comment', 'annotation', 'annotationfeedback', 'blog', 'textbox', 'editnote', 'text');
    if (!empty($includeresourcetypes)) {
        if (!is_array($includeresourcetypes)) {
            $includeresourcetypes = array($includeresourcetypes);
        }
        $resourcetypes = array_merge($defaultresourcetypes, $includeresourcetypes);
    }
    if (!empty($excluderesourcetypes)) {
        if (!is_array($excluderesourcetypes)) {
            $excluderesourcetypes = array($excluderesourcetypes);
        }
        $resourcetypes = array_diff($resourcetypes, $excluderesourcetypes);
    }
    foreach ($resourcetypes as $resourcetype) {
        $resourceid = param_integer($resourcetype, null);
        if ($resourceid) {
            $isvisible = EmbeddedImage::can_see_embedded_image($fileid, $resourcetype, $resourceid);
        }
        if ($isvisible) {
            break;
        }
    }
    return $isvisible;
}