$fs = get_file_storage();
if (!($storedfile = $fs->get_file($context->id, 'mod_lightboxgallery', 'gallery_images', '0', '/', $image))) {
    print_error(get_string('errornofile', 'lightboxgallery', $image));
}
if ($editinstance->processing() && confirm_sesskey()) {
    $params = array('context' => $context, 'other' => array('imagename' => $image, 'tab' => $tab));
    $event = \mod_lightboxgallery\event\image_updated::create($params);
    $event->add_record_snapshot('course_modules', $cm);
    $event->add_record_snapshot('course', $course);
    $event->add_record_snapshot('lightboxgallery', $gallery);
    $event->trigger();
    $editinstance->process_form();
    redirect($CFG->wwwroot . '/mod/lightboxgallery/imageedit.php?id=' . $cm->id . '&image=' . $editinstance->image . '&tab=' . $tab);
}
$image = new lightboxgallery_image($storedfile, $gallery, $cm);
$table = new html_table();
$table->width = '*';
if ($editinstance->showthumb) {
    $table->attributes = array('style' => 'margin-left:auto;margin-right:auto;');
    $table->align = array('center', 'center');
    $table->size = array('*', '*');
    $table->data[] = array('<img src="' . $image->get_thumbnail_url() . '" alt="" /><br /><span title="' . $image->get_image_caption() . '">' . $image->get_image_caption() . '</span>', $editinstance->output($image->get_image_caption()));
} else {
    $table->align = array('center');
    $table->size = array('*');
    $table->data[] = array($editinstance->output($image->get_image_caption()));
}
echo $OUTPUT->header();
print_tabs(array($tabs), $tab);
echo html_writer::table($table);
echo $OUTPUT->footer();
/**
 * Returns the path to the cached rss feed contents. Creates/updates the cache if necessary.
 * @global object $CFG
 * @global object $DB
 * @param object $context the context
 * @param array $args the arguments received in the url
 * @return string the full path to the cached RSS feed directory. Null if there is a problem.
 */
function lightboxgallery_rss_get_feed($context, $args)
{
    global $CFG, $DB;
    $config = get_config('lightboxgallery');
    $status = true;
    // Are RSS feeds enabled?
    if (empty($config->enablerssfeeds)) {
        debugging('DISABLED (module configuration)');
        return null;
    }
    $galleryid = clean_param($args[3], PARAM_INT);
    $cm = get_coursemodule_from_instance('lightboxgallery', $galleryid, 0, false, MUST_EXIST);
    if ($cm) {
        $modcontext = context_module::instance($cm->id);
        // Context id from db should match the submitted one.
        if ($context->id != $modcontext->id) {
            return null;
        }
    }
    $gallery = $DB->get_record('lightboxgallery', array('id' => $galleryid), '*', MUST_EXIST);
    $captions = array();
    if ($cobjs = $DB->get_records('lightboxgallery_image_meta', array('metatype' => 'caption', 'gallery' => $gallery->id))) {
        foreach ($cobjs as $cobj) {
            $captions[$cobj->image] = $cobj->description;
        }
    }
    $fs = get_file_storage();
    $storedfiles = $fs->get_area_files($context->id, 'mod_lightboxgallery', 'gallery_images');
    $items = array();
    $counter = 1;
    $articles = '';
    foreach ($storedfiles as $file) {
        $filename = $file->get_filename();
        if ($filename == '.') {
            continue;
        }
        $description = isset($captions[$filename]) ? $captions[$filename] : $filename;
        $image = new lightboxgallery_image($file, $gallery, $cm);
        $item = new stdClass();
        $item->{"media:description"} = $description;
        $articles .= rss_start_tag('item', 2, true);
        $articles .= rss_full_tag('title', 3, false, $filename);
        $articles .= rss_full_tag('link', 3, false, $image->get_image_url());
        $articles .= rss_full_tag('guid', 3, false, 'img' . $counter);
        $articles .= rss_full_tag('media:description', 3, false, $description);
        $articles .= rss_full_tag('media:thumbnail', 3, false, '', array('url' => $image->get_thumbnail_url()));
        $articles .= rss_full_tag('media:content', 3, false, '', array('url' => $image->get_image_url(), 'type' => $file->get_mimetype()));
        $articles .= rss_end_tag('item', 2, true);
    }
    // Get the cache file info.
    $filename = rss_get_file_name($gallery, $sql);
    $cachedfilepath = rss_get_file_full_name('mod_lightboxgallery', $filename);
    // Is the cache out of date?
    $cachedfilelastmodified = 0;
    if (file_exists($cachedfilepath)) {
        $cachedfilelastmodified = filemtime($cachedfilepath);
    }
    // First all rss feeds common headers.
    $header = lightboxgallery_rss_header(format_string($gallery->name, true), $CFG->wwwroot . "/mod/lightboxgallery/view.php?id=" . $cm->id, format_string($gallery->intro, true));
    // Now all rss feeds common footers.
    if (!empty($header) && !empty($articles)) {
        $footer = rss_standard_footer();
    }
    // Now, if everything is ok, concatenate it.
    if (!empty($header) && !empty($articles) && !empty($footer)) {
        $rss = $header . $articles . $footer;
        // Save the XML contents to file.
        $status = rss_save_file('mod_lightboxgallery', $filename, $rss);
    }
    if (!$status) {
        $cachedfilepath = null;
    }
    return $cachedfilepath;
}