/** * This function builds the page relative to the caption system */ function lg_build_captions_form() { global $gallery_root, $gallery_address, $lg_text_domain; $capdir = $_GET['captions']; // main container div echo '<div class="wrap">'; /* ========== * Upload div * ========== */ $folder = $gallery_root . $capdir; $allowed_types = explode(' ', trim(strtolower(get_option('lg_fileupload_allowedtypes')))); if ($_POST['upload']) { $action = 'upload'; } if (!is_writable($folder)) { $action = 'not-writable'; } switch ($action) { case 'not-writable': ?> <p><?php printf(__("It doesn't look like you can use the file upload feature at this time because the directory you have specified (<code>%s</code>) doesn't appear to be writable by WordPress. Check the permissions on the directory and for typos.", $lg_text_domain), $folder); ?> </p> <?php break; case 'upload': $imgalt = basename(isset($_POST['imgalt']) ? $_POST['imgalt'] : ''); $img1_name = strlen($imgalt) ? $imgalt : basename($_FILES['img1']['name']); $img1_name = preg_replace('/[^a-z0-9_.]/i', '', $img1_name); $img1_size = $_POST['img1_size'] ? intval($_POST['img1_size']) : intval($_FILES['img1']['size']); $img1_type = strlen($imgalt) ? $_POST['img1_type'] : $_FILES['img1']['type']; $pi = pathinfo($img1_name); $imgtype = strtolower($pi['extension']); if (in_array($imgtype, $allowed_types) == false) { die(sprintf(__('File %1$s of type %2$s is not allowed.', $lg_text_domain), $img1_name, $imgtype)); } if (strlen($imgalt)) { $pathtofile = $folder . $imgalt; $img1 = $_POST['img1']; } else { $pathtofile = $folder . $img1_name; $img1 = $_FILES['img1']['tmp_name']; } // makes sure not to upload duplicates, rename duplicates $i = 1; $pathtofile2 = $pathtofile; $tmppathtofile = $pathtofile2; $img2_name = $img1_name; while (file_exists($pathtofile2)) { $pos = strpos(strtolower($tmppathtofile), '.' . trim($imgtype)); $pathtofile_start = substr($tmppathtofile, 0, $pos); $pathtofile2 = $pathtofile_start . '_' . zeroise($i++, 2) . '.' . trim($imgtype); $img2_name = explode('/', $pathtofile2); $img2_name = $img2_name[count($img2_name) - 1]; } if (file_exists($pathtofile) && !strlen($imgalt)) { $i = explode(' ', get_option('lg_fileupload_allowedtypes')); $i = implode(', ', array_slice($i, 1, count($i) - 2)); $moved = move_uploaded_file($img1, $pathtofile2); if (!$moved) { $moved = copy($img1, $pathtofile2); } if (!$moved) { die(sprintf(__("Couldn't upload your file to %s.", $lg_text_domain), $pathtofile2)); } else { chmod($pathtofile2, 0666); @unlink($img1); } // // duplicate-renaming function contributed by Gary Lawrence Murphy ?> <p><strong><?php __('Duplicate File?'); ?> </strong></p> <p><b><em><?php printf(__("The filename '%s' already exists!"), $img1_name); ?> </em></b></p> <p><?php printf(__("Filename '%1\$s' moved to '%2\$s'"), $img1, "{$pathtofile2} - {$img2_name}"); ?> </p> <p><?php _e('Confirm or rename:'); ?> </p> <form action="" method="post" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo get_option('lg_fileupload_maxk') * 1024; ?> " /> <input type="hidden" name="img1_type" value="<?php echo $img1_type; ?> " /> <input type="hidden" name="img1_name" value="<?php echo $img2_name; ?> " /> <input type="hidden" name="img1_size" value="<?php echo $img1_size; ?> " /> <input type="hidden" name="img1" value="<?php echo $pathtofile2; ?> " /> <?php _e('Alternate name:'); ?> <br /><input type="text" name="imgalt" size="30" class="uploadform" value="<?php echo $img2_name; ?> " /><br /> <br /> <input type="submit" name="submit" value="<?php _e('Rename'); ?> " class="search" /> </form> <?php die; } if (!strlen($imgalt)) { @($moved = move_uploaded_file($img1, $pathtofile)); //Path to your images directory, chmod the dir to 777 // move_uploaded_file() can fail if open_basedir in PHP.INI doesn't // include your tmp directory. Try copy instead? if (!$moved) { $moved = copy($img1, $pathtofile); } // Still couldn't get it. Give up. if (!$moved) { die(sprintf(__("Couldn't upload your file to %s.", $lg_text_domain), $pathtofile)); } else { chmod($pathtofile, 0666); @unlink($img1); } } else { rename($img1, $pathtofile) or die(sprintf(__("Couldn't upload your file to %s.", $lg_text_domain), $pathtofile)); } if (ereg('image/', $img1_type)) { $piece_of_code = "[[Image:" . $capdir . $img1_name . "]]"; } else { $piece_of_code = "<a href='" . $gallery_address . $capdir . $img1_name . "'>{$img1_name}</a>"; } $piece_of_code = htmlspecialchars($piece_of_code); ?> <div id="message" class="updated fade"><p><?php _e('File uploaded!', $lg_text_domain); ?> </p></div> <p><?php printf(__("Your file <code>%s</code> was uploaded successfully!", $lg_text_domain), $img1_name); ?> </p> <p><?php _e('Here’s the code to display it in your posts:', $lg_text_domain); ?> </p> <p><code><?php echo $piece_of_code; ?> </code></p> <p> <strong><?php _e('Image Details'); ?> </strong>: <br /> <?php _e('Name:'); ?> <?php echo $img1_name; ?> <br /> <?php _e('Size:'); ?> <?php echo round($img1_size / 1024, 2); ?> <?php _e('<abbr title="Kilobyte">KB</abbr>', $lg_text_domain); ?> <br /> <?php _e('Type:'); ?> <?php echo $img1_type; ?> </p> <p><a href="options-general.php?page=lazyest-gallery/lazyest-admin.php&captions=<?php echo $capdir; ?> "><?php _e('Upload another'); ?> </a></p> <?php break; } /* ================= * End of Upload div * ================= */ /* ================= * Confirmations div * ================= */ if (isset($_POST['yes'])) { if (!is_dir($_POST['delete_this'])) { if (@unlink($_POST['delete_this'])) { echo '<div id="message" class="updated fade"><p>' . __('File deleted successfully', $lg_text_domain) . '</p></div>'; } else { echo '<div id="message" class="error fade"><p>' . __('Cannot delete file, maybe it has already been deleted or have wrong permissions', $lg_text_domain) . '</p></div>'; } } else { if (lg_remove_directory($_POST['delete_this'])) { echo '<div id="message" class="updated fade"><p>' . __('Folder deleted successfully', $lg_text_domain) . '</p></div>'; } else { echo '<div id="message" class="error fade"><p>' . __('Cannot delete folder: maybe it is already empty or have bad permissions', $lg_text_domain) . '</p></div>'; } } // Unsetting informations unset($_POST); unset($_GET); } if (isset($_POST['no'])) { echo '<div id="message" class="updated fade"><p>' . __('Nothing Changed', $lg_text_domain) . '</p></div>'; // Unsetting informations unset($_POST); unset($_GET); } /* ================= * file deletion div * ================= */ if (isset($_GET['file_to_delete']) && !isset($_POST['update_captions']) && !isset($_POST['upload'])) { ?> <div style="padding:10px;"> <div style="text-align:center;padding:0px;color:red;border:1px solid #ff0000;background:#ffdddd"> <?php _e('You are about to delete', $lg_text_domain); echo " <code>" . basename($_GET['file_to_delete']) . "</code><br />"; echo __('Are you sure?', $lg_text_domain) . "<br />"; ?> <form name="delete_image_file" method="post" action="" style="padding:5px;"> <div class="submit" style="text-align:center"> <input type="submit" name="yes" value="<?php _e('Yes', $lg_text_domain); ?> " style="width:80px;" /> <input type="submit" name="no" value="<?php _e('No', $lg_text_domain); ?> " style="width:80px;" /> <input type="hidden" name="delete_this" value="<?php echo $_GET['file_to_delete']; ?> " /> </div> </form> <?php echo "</div>\n</div>"; } $imgfiles = get_imgfiles($capdir); $act_current = $capdir; ?> <fieldset class="options"> <h2><?php echo sprintf(__('Captions page for <code>%s</code>', $lg_text_domain), $act_current); ?> </h2> <!-- Shortcuts--> <div style="padding:5px;display:block;background:#efefef;border:1px solid #ccc;height:20px;"> <a href="options-general.php?page=lazyest-gallery/lazyest-admin.php">« <?php _e('Admin page', $lg_text_domain); ?> </a> </div> <!-- End of Shortcuts--> <br /> <!-- Tip div --> <div style="padding:5px;border:1px solid #3fbd3f;background:#beffbe;color:#088000;"> <?php _e('You can use HTML links but be sure to use "[" and "]" instead of "<" and ">"; something like [a href="somewhere"]Link[/a]', $lg_text_domain); ?> </div> <!-- End of tip div --> <form name="gallery_captions" method="post" action=""> <input type="hidden" name="folder" value="<?php echo $act_current; ?> "/> <table summary="thumbs" cellspacing="1" cellpadding="10"> <tr> <!-- Folder Caption code --> <td colspan='2'><b>» <?php _e("Folder's description:", $lg_text_domain); ?> </b> <?php $foldcap = clean_folder_caption($act_current, false); echo '<input type="text" name="folder_caption" value="' . $foldcap . '" size="80" style="width:98%" />'; ?> <ul> <li>» <a href="?page=lazyest-gallery/lazyest-admin.php&captions=<?php echo $act_current; ?> &file_to_delete=<?php echo $gallery_root . $act_current . get_option('lg_thumb_folder'); ?> " class="delete" style="display:inline;"><?php _e('Empty thumbs cache', $lg_text_domain); ?> </a></li> <li>» <a href="?page=lazyest-gallery/lazyest-admin.php&captions=<?php echo $act_current; ?> &file_to_delete=<?php echo $gallery_root . $act_current . get_option('lg_slide_folder'); ?> " class="delete" style="display:inline;"><?php _e('Empty slides cache', $lg_text_domain); ?> </a></li> </ul> </td> </tr> <tr> <td colspan="2" style="text-algin: left;" ><b>» <?php _e('Minimum level to access this folder:', $lg_text_domain); ?> </b> <select name="folder_minimum_level"> <?php for ($i = 1; $i < 11; $i++) { if ($i == get_minimum_folder_level($act_current)) { $selected = " selected='selected'"; } else { $selected = '0'; } echo "\n\t<option value='{$i}' {$selected}>{$i}</option>"; } ?> </select> <span style="font-size:x-small;text-align:center;padding:2px;color:red;border:1px solid #ff0000;background:#ffdddd"> <?php _e('EXPERIMENTAL: Folder will be still browsable (if full path is known).', $lg_text_domain); ?> </span> </td> </tr> <!-- End of Folder Caption code --> <?php if (isset($imgfiles)) { foreach ($imgfiles as $img) { // clean_image_caption() function is in lazyest-gallery.php file // and checks if xml file exists, if not it returns false // we need a "clean" (with "<" and ">") caption $caption = clean_image_caption($img, $capdir); // this will removes HTML tags and used as title argument $title = ereg_replace("<[^>]*>", "", $caption); $righturl = urlencode($act_current . $img); echo '<tr><td><a href="' . get_option('lg_gallery_uri') . '&file=' . $righturl . '">'; // If thumbs cache system is enabled if (get_option('lg_enable_cache') == "TRUE") { // we check if thumbs exist if (!file_exists($gallery_root . $act_current . get_option('lg_thumb_folder') . $img)) { // keeping track of subfolders $img_file_path = explode('/', $img); $img_index = count($img_file_path) - 1; $img_file = $img_file_path[$img_index]; // If there are subfolders if ($img_index > 1) { for ($i = 1; $i < count($img_file_path) - 1; $i++) { // set the new "current" directory $act_current .= $img_file_path[$i] . "/"; } } // if thumbs do not exist we create them createCache($act_current, $img, true); } // trimming spaces (XHTML Urls) $righturl = str_replace(" ", "%20", $gallery_address . $act_current . get_option('lg_thumb_folder') . $img); echo '<img src="' . $righturl . '" alt="' . $img . '" title="' . $title . '" />'; } else { // otherwise $righturl = str_replace(" ", "%20", get_option('siteurl') . "/wp-content/plugins/lazyest-gallery/lazyest-img.php?file=" . $act_current . $img . "&thumb=1"); echo "<img src=" . $righturl . " alt=" . $img . " title=" . $title . " />"; } // this time we need a "rebuilded" (with "" and "") caption $caption = clean_image_caption($img, $capdir, false); // this is a dynamic form name construct that we need for the captions system $form_name = str_replace('.', '_', $img); $form_name = str_replace(' ', '_', $form_name); echo '</a></td>'; echo '<td>» ' . $img . '<br />'; // Inputs ?> <input type="text" name="<?php echo $form_name; ?> " value="<?php echo $caption; ?> " size="90" style="width:88%" /> <a href="?page=lazyest-gallery/lazyest-admin.php&captions=<?php echo $act_current; ?> &file_to_delete=<?php echo $gallery_root . $act_current . $img; ?> " class="button" style="display:inline;"><?php _e('Delete', $lg_text_domain); ?> </a> <?php } } ?> </table> <div class="submit"> <input type="hidden" name="directory" value="<?php echo $act_current; ?> " /> <input type="submit" name="update_captions" value="<?php _e('Update Folder', $lg_text_domain); ?> " /> </div> </form> </fieldset> <!-- Upload section --> <fieldset class="dbx-box"> <h3 title="click-down and drag to move this box" class="dbx-handle"><?php _e('Upload Image', $lg_text_domain); ?> </h3> <div class="dbx-content"> <?php upload_page($act_current); ?> </div><br /><br /> </fieldset> <!-- Gallery structure section --> <fieldset class="dbx-box"> <h3 title="click-down and drag to move this box" class="dbx-handle"><?php _e('Image Captions', $lg_text_domain); ?> </h3> <div class="dbx-content"> <?php lg_show_gallery_structure(); ?> </div> </fieldset> </div> <?php }
</tr> <tr> <th scope="row"><?php _e('Use folder captions instead of their name:', $lg_text_domain); ?> </th> <td><input type="checkbox" name="use_folder_captions" value="TRUE" <?php if (get_option('lg_use_folder_captions') == "TRUE") { echo "checked='checked'"; } ?> /></td> </tr> </table> <?php lg_show_gallery_structure(); ?> </div> </fieldset> <!-- Advanced Options Section --> <fieldset class="dbx-box"> <h3 title="click-down and drag to move this box" class="dbx-handle"><?php _e('Advanced Options', $lg_text_domain); ?> </h3> <div class="dbx-content"> <table summary="advanced" class="editform" cellpadding="5" cellspacing="2" style="width:100%;vertical-align:top;"> <tr> <th scope="row"><?php _e('Use Cache System for Thumbnails: ', $lg_text_domain);