Example #1
0
/**
 * This function builds the xml file where images infos are stored
 * NOTE: $capdir stays for Captions Directory
 */
function lg_generate_xml($capdir)
{
    global $gallery_root;
    if (is_writable($gallery_root . $capdir)) {
        $imgfiles = get_imgfiles($capdir);
        // Check if $capdir ends with the "/" and providing one if not
        if (substr($capdir, strlen($capdir) - 1, strlen($capdir)) != "/") {
            $capdir .= "/";
        }
        $handle = fopen($gallery_root . $capdir . 'captions.xml', 'wb');
        fwrite($handle, "<?xml version='1.0' encoding='" . get_option('blog_charset') . "'?>\n");
        fwrite($handle, "<data>\n");
        // Folder caption
        $folder_caption = str_replace('\\', '', $_POST['folder_caption']);
        fwrite($handle, "\t<folder>" . $folder_caption . "</folder>\n");
        // Folder access level
        $folder_access = $_POST['folder_minimum_level'];
        fwrite($handle, "\t<level>" . $folder_access . "</level>\n");
        if (isset($imgfiles)) {
            foreach ($imgfiles as $img) {
                // prepare the strings to be written
                $form_value = str_replace('.', '_', $img);
                $form_value = str_replace(' ', '_', $form_value);
                $dirty_caption = $_POST[$form_value];
                $clean_caption = str_replace('\\', '', $dirty_caption);
                // write strings
                fwrite($handle, "\t<photo id='" . $img . "'>\n");
                fwrite($handle, "\t\t<caption>" . $clean_caption . "</caption>\n");
                fwrite($handle, "\t</photo>\n");
            }
        }
        fwrite($handle, "</data>");
        fclose($handle);
        @chmod($gallery_root . $capdir . 'captions.xml', 0666);
    } else {
        lg_cannot_rw($capdir);
    }
}
Example #2
0
function al_generate_xml($capdir)
{
    global $gallery_root;
    if (is_writable($gallery_root . $capdir)) {
        // Gather the image's informations and ID number
        $imgfiles = get_imgfiles($capdir);
        $images_data = get_image_caption($capdir);
        // Check if $capdir ends with the "/" and providing one if not
        if (substr($capdir, strlen($capdir) - 1, strlen($capdir)) != "/") {
            $capdir .= "/";
        }
        $handle = fopen($gallery_root . $capdir . 'captions.xml', 'wb');
        fwrite($handle, "<?xml version='1.0' encoding='" . get_option('blog_charset') . "'?>\n");
        fwrite($handle, "<data>\n");
        // Folder caption; TODO valute htmlentities()
        $folder_caption = utf8_encode(str_replace('\\', '', $_POST['folder_caption']));
        fwrite($handle, "\t<folder>" . $folder_caption . "</folder>\n");
        // Folder access level
        $folder_access = $_POST['folder_minimum_level'];
        fwrite($handle, "\t<level>" . $folder_access . "</level>\n");
        if (isset($imgfiles)) {
            foreach ($imgfiles as $img) {
                // prepare the strings to be written
                $form_value = str_replace('.', '_', $img);
                $form_value = str_replace(' ', '_', $form_value);
                $dirty_caption = utf8_encode($_POST[$form_value]);
                $clean_caption = str_replace('\\', '', $dirty_caption);
                // write strings
                fwrite($handle, "\t<photo id='" . $img . "'>\n");
                fwrite($handle, "\t\t<caption>" . $clean_caption . "</caption>\n");
                for ($i = 0; $i < count($images_data); $i++) {
                    if ($images_data[$i][image] == $img) {
                        $image_number = $images_data[$i][id];
                    }
                }
                // If is not setted update the counter and...
                if (strlen($image_number) == 0) {
                    add_option('lg_image_indexing', '0', 'Lazyest Gallery images index to retrive comments');
                    $image_number = get_option('lg_image_indexing');
                    $counter = $image_number + 1;
                    update_option('lg_image_indexing', $counter);
                }
                // ...provide one
                fwrite($handle, "\t\t<image>" . $image_number . "</image>\n");
                fwrite($handle, "\t</photo>\n");
            }
        }
        fwrite($handle, "</data>");
        fclose($handle);
        @chmod($gallery_root . $capdir . 'captions.xml', 0666);
    } else {
        return lg_cannot_rw($capdir);
    }
}