PageRenderTime 33ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/lazyest-gallery/lazyest-filemanager.php

http://cartonbank.googlecode.com/
PHP | 803 lines | 654 code | 85 blank | 64 comment | 98 complexity | ac7f36bca329d08ccc4abd152836702a MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, LGPL-2.1, AGPL-1.0, LGPL-3.0
  1. <?php
  2. /*
  3. * This file handle all captions
  4. * Functions list:
  5. * -TODO-
  6. */
  7. /** This function builds the structure of the gallery inside the main LG admin panel
  8. * TODO:
  9. * - Add a filter here (password or "not to show" option)
  10. * - Add the icon of each folder
  11. */
  12. require_once('lazyest-gallery.php');
  13. global $gallery_root;
  14. function lg_show_gallery_structure(){
  15. global $gallery_root, $lg_text_domain;
  16. echo "<div style='font-family:monospace;background:#efefef;padding:5px;border:1px solid #ccc;'>\n";
  17. echo "<ul>\n";
  18. if (file_exists($gallery_root)){
  19. if ($dir_content = opendir($gallery_root)) {
  20. while ( false !== ($dir = readdir($dir_content)) ) {
  21. if (is_dir($gallery_root.$dir) && !in_array($dir, get_option('lg_excluded_folders')) && $dir!='.' && $dir!='..' ) {
  22. lg_show_structure($dir);
  23. }
  24. }
  25. }
  26. }
  27. else {
  28. echo "<li><div style='border: solid 1px #000; padding: 10px;'><b style='color:#ff0000;'>". __('WARNING', $lg_text_domain) ." </b>: ". __('Specified gallery folder does not exists', $lg_text_domain) ."</div></li>";
  29. }
  30. echo "</ul>\n";
  31. echo "</div>\n";
  32. }
  33. /**
  34. * This function is used from show_gallery_structure() to build nested structures
  35. * NOTE: $sscurrentdir stays for Show Structure current directory
  36. */
  37. function lg_show_structure($sscurrentdir){
  38. global $excluded_folders, $gallery_root, $lg_text_domain;
  39. if( substr($sscurrentdir, strlen($sscurrentdir)-1 ) != '/'){
  40. $sscurrentdir .= '/';
  41. }
  42. $righturl = urlencode($sscurrentdir);
  43. echo '<li><a href="'. LG_FLM_PAGE .'&amp;captions=' . $righturl . '">' . $sscurrentdir . '</a>';
  44. if ($dir_content = opendir($gallery_root.$sscurrentdir)) {
  45. $dir_list = array();
  46. while ( false !== ($dir = readdir($dir_content)) ) {
  47. if (is_dir($gallery_root.$sscurrentdir.$dir) && !in_array($dir, get_option('lg_excluded_folders')) && $dir!='.' && $dir!='..' ) {
  48. $dir_list[] = $sscurrentdir.$dir;
  49. }
  50. }
  51. if($dir_list != NULL && sizeof($dir_list) > 0) {
  52. echo "<ul>\n";
  53. foreach($dir_list as $subdir) {
  54. lg_show_structure($subdir);
  55. }
  56. echo "</ul>\n";
  57. }
  58. }
  59. echo '</li>';
  60. }
  61. /**
  62. * This function builds the page relative to the caption system
  63. */
  64. function lg_build_captions_form(){
  65. global $gallery_root, $gallery_address, $lg_text_domain;
  66. $capdir = $_GET['captions'];
  67. if (strlen($capdir) == 0){
  68. $capdir = $_POST['upload_folder'];
  69. }
  70. $gallery_uri = get_option('lg_gallery_uri');
  71. // Fix for permalinks
  72. if (strlen(get_option('permalink_structure')) != 0){
  73. $gallery_uri = $gallery_uri.'?';
  74. } else {
  75. $gallery_uri = $gallery_uri.'&amp;';
  76. }
  77. // main container div
  78. echo '<div class="wrap">';
  79. // Button: save captions (lazyest-captions.php)
  80. if(isset($_POST['update_captions'])){
  81. lg_generate_xml($_POST['directory']);
  82. }
  83. /* ==========
  84. * Upload div
  85. * ========== */
  86. $folder = $gallery_root.$capdir;
  87. // $_POST['upload_folder'];
  88. $allowed_types = explode(' ', trim(strtolower(get_option('lg_fileupload_allowedtypes'))));
  89. if ($_POST['upload']) {
  90. $action = 'upload';
  91. if (!is_writable($folder))
  92. $action = 'not-writable';
  93. switch ($action) {
  94. case 'not-writable':
  95. ?>
  96. <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>
  97. <?php
  98. break;
  99. case 'upload':
  100. $imgalt = basename( (isset($_POST['imgalt'])) ? $_POST['imgalt'] : '' );
  101. $img1_name = (strlen($imgalt)) ? $imgalt : basename( $_FILES['img1']['name'] );
  102. $img1_name = preg_replace('/[^a-z0-9_.]/i', '', $img1_name);
  103. $img1_size = $_POST['img1_size'] ? intval($_POST['img1_size']) : intval($_FILES['img1']['size']);
  104. $img1_type = (strlen($imgalt)) ? $_POST['img1_type'] : $_FILES['img1']['type'];
  105. $pi = pathinfo($img1_name);
  106. $imgtype = strtolower($pi['extension']);
  107. if (in_array($imgtype, $allowed_types) == false)
  108. die(sprintf(__('File %1$s of type %2$s is not allowed.', $lg_text_domain) , $img1_name, $imgtype));
  109. if (strlen($imgalt)) {
  110. $pathtofile = $folder.$imgalt;
  111. $img1 = $_POST['img1'];
  112. } else {
  113. $pathtofile = $folder.$img1_name;
  114. $img1 = $_FILES['img1']['tmp_name'];
  115. }
  116. // makes sure not to upload duplicates, rename duplicates
  117. $i = 1;
  118. $pathtofile2 = $pathtofile;
  119. $tmppathtofile = $pathtofile2;
  120. $img2_name = $img1_name;
  121. while ( file_exists($pathtofile2) ) {
  122. $pos = strpos( strtolower($tmppathtofile), '.' . trim($imgtype) );
  123. $pathtofile_start = substr($tmppathtofile, 0, $pos);
  124. $pathtofile2 = $pathtofile_start.'_'.zeroise($i++, 2).'.'.trim($imgtype);
  125. $img2_name = explode('/', $pathtofile2);
  126. $img2_name = $img2_name[count($img2_name)-1];
  127. }
  128. if (file_exists($pathtofile) && !strlen($imgalt)) {
  129. $i = explode(' ', get_option('lg_fileupload_allowedtypes'));
  130. $i = implode(', ',array_slice($i, 1, count($i)-2));
  131. $moved = move_uploaded_file($img1, $pathtofile2);
  132. if (!$moved) {
  133. $moved = copy($img1, $pathtofile2);
  134. }
  135. if (!$moved) {
  136. die(sprintf(__("Couldn't upload your file to %s.", $lg_text_domain), $pathtofile2));
  137. } else {
  138. chmod($pathtofile2, 0666);
  139. @unlink($img1);
  140. }
  141. //
  142. // duplicate-renaming function contributed by Gary Lawrence Murphy
  143. ?>
  144. <p><strong><?php __('Duplicate File?') ?></strong></p>
  145. <p><b><em><?php printf(__("The filename '%s' already exists!", $lg_text_domain), $img1_name); ?></em></b></p>
  146. <p><?php printf(__("Filename '%1\$s' moved to '%2\$s'", $lg_text_domain), $img1, "$pathtofile2 - $img2_name") ?></p>
  147. <p><?php _e('Confirm or rename:') ?></p>
  148. <form action="<?php echo LG_FLM_PAGE; ?>" method="post" enctype="multipart/form-data">
  149. <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo get_option('lg_fileupload_maxk') *1024 ?>" />
  150. <input type="hidden" name="img1_type" value="<?php echo $img1_type;?>" />
  151. <input type="hidden" name="img1_name" value="<?php echo $img2_name;?>" />
  152. <input type="hidden" name="img1_size" value="<?php echo $img1_size;?>" />
  153. <input type="hidden" name="img1" value="<?php echo $pathtofile2;?>" />
  154. <?php _e('Alternate name:') ?><br /><input type="text" name="imgalt" size="30" class="uploadform" value="<?php echo $img2_name;?>" /><br />
  155. <br />
  156. <input type="submit" name="submit" value="<?php _e('Rename', $lg_text_domain) ?>" class="search" />
  157. </form>
  158. <?php
  159. die();
  160. }
  161. if (!strlen($imgalt)) {
  162. @$moved = move_uploaded_file($img1, $pathtofile); //Path to your images directory, chmod the dir to 777
  163. // move_uploaded_file() can fail if open_basedir in PHP.INI doesn't
  164. // include your tmp directory. Try copy instead?
  165. if(!$moved) {
  166. $moved = copy($img1, $pathtofile);
  167. }
  168. // Still couldn't get it. Give up.
  169. if (!$moved) {
  170. die(sprintf(__("Couldn't upload your file to %s.", $lg_text_domain), $pathtofile));
  171. } else {
  172. chmod($pathtofile, 0666);
  173. @unlink($img1);
  174. }
  175. } else {
  176. rename($img1, $pathtofile)
  177. or die(sprintf(__("Couldn't upload your file to %s.", $lg_text_domain), $pathtofile));
  178. }
  179. if ( ereg('image/',$img1_type) )
  180. $piece_of_code = "[[Image:".$capdir.$img1_name."]]";
  181. else
  182. $piece_of_code = "<a href='" . $gallery_address.$capdir.$img1_name . "'>$img1_name</a>";
  183. $piece_of_code = htmlspecialchars( $piece_of_code );
  184. ?>
  185. <div id="message" class="updated fade"><p><?php _e('File uploaded!', $lg_text_domain) ?></p></div>
  186. <p><?php printf(__("Your file <code>%s</code> was uploaded successfully!", $lg_text_domain), $img1_name); ?></p>
  187. <p><?php _e('Here&#8217;s the code to display it in your posts:', $lg_text_domain) ?></p>
  188. <p><code><?php echo $piece_of_code; ?></code></p>
  189. <p>
  190. <strong><?php _e('Image Details') ?></strong>: <br />
  191. <?php _e('Name:'); ?>
  192. <?php echo $img1_name; ?>
  193. <br />
  194. <?php _e('Size:') ?>
  195. <?php echo round($img1_size / 1024, 2); ?> <?php _e('<abbr title="Kilobyte">KB</abbr>', $lg_text_domain) ?><br />
  196. <?php _e('Type:') ?>
  197. <?php echo $img1_type; ?>
  198. </p>
  199. <p><a href="<?php echo LG_FLM_PAGE; ?>&amp;captions=<?php echo $capdir; ?>"><?php _e('Upload another') ?></a></p>
  200. <?php
  201. break;
  202. }
  203. }
  204. /* =================
  205. * End of Upload div
  206. * ================= */
  207. /* ====================
  208. * Confirm deletion div
  209. * ==================== */
  210. if (isset($_POST['yes'])) {
  211. if (!is_dir($_POST['delete_this'])) {
  212. if(@unlink($_POST['delete_this'])) {
  213. echo '<div id="message" class="updated fade"><p>'. __('File deleted successfully', $lg_text_domain) .'</p></div>';
  214. } else {
  215. 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>';
  216. }
  217. } else {
  218. if(lg_remove_directory($_POST['delete_this'])) {
  219. echo '<div id="message" class="updated fade"><p>'. __('Folder deleted successfully', $lg_text_domain) .'</p></div>';
  220. } else {
  221. 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>';
  222. }
  223. }
  224. // Unsetting informations
  225. unset($_POST);
  226. unset($_GET);
  227. }
  228. if (isset($_POST['no'])) {
  229. echo '<div id="message" class="updated fade"><p>'. __('Nothing Changed', $lg_text_domain) .'</p></div>';
  230. // Unsetting informations
  231. unset($_POST);
  232. unset($_GET);
  233. }
  234. /* =================
  235. * file deletion div
  236. * ================= */
  237. if (isset($_GET['file_to_delete']) &&
  238. !isset($_POST['update_captions']) &&
  239. !isset($_POST['upload']) &&
  240. !isset($_POST['create_new_folder']) &&
  241. !isset($_POST['rename_the_folder']) &&
  242. !isset($_POST['yes']) &&
  243. !isset($_POST['no'])) {
  244. ?>
  245. <div style="padding:10px;">
  246. <div style="text-align:center;padding:0px;color:red;border:1px solid #ff0000;background:#ffdddd">
  247. <?php
  248. _e('You are about to delete', $lg_text_domain);
  249. echo " <code>".basename($_GET['file_to_delete'])."</code><br />";
  250. echo __('Are you sure?', $lg_text_domain)."<br />";
  251. ?>
  252. <form name="delete_image_file" method="post" action="<?php echo LG_FLM_PAGE; ?>" style="padding:5px;">
  253. <div class="submit" style="text-align:center">
  254. <input type="submit" name="yes" value="<?php _e('Yes', $lg_text_domain); ?>" style="width:80px;" />
  255. <input type="submit" name="no" value="<?php _e('No', $lg_text_domain); ?>" style="width:80px;" />
  256. <input type="hidden" name="folder" value="<?php echo $_POST['folder']; ?>" />
  257. <input type="hidden" name="delete_this" value="<?php echo $_GET['file_to_delete']; ?>" />
  258. </div>
  259. </form>
  260. <?php
  261. echo "</div>\n</div>";
  262. }
  263. /* =================
  264. * Rename folder div
  265. * ================= */
  266. if (isset($_POST['rename_the_folder'])){
  267. if (strlen($_POST['new_file_name']) > 0){
  268. $oldname = $_POST['actual_folder'];
  269. $newname = $gallery_root.$_POST['new_file_name'];
  270. if (lg_rename_file($oldname, $newname)){
  271. echo '<div id="message" class="updated fade"><p>'. __('Renamed successfully', $lg_text_domain) .'</p></div>';
  272. } else {
  273. echo '<div id="message" class="error fade"><p>'. __('Cannot rename.', $lg_text_domain) .'</p></div>';
  274. }
  275. } else {
  276. echo '<div id="message" class="error fade"><p>'. __('Provide a new name.', $lg_text_domain) .'</p></div>';
  277. }
  278. unset($_POST);
  279. unset($_GET);
  280. }
  281. /* =======================
  282. * New folder creation div
  283. * ======================= */
  284. if (isset($_POST['create_new_folder'])) {
  285. if (strlen($_POST['new_folder_name']) > 0) {
  286. $folder_name = $_POST['actual_folder'].$_POST['new_folder_name'];
  287. $new_folder_path = $gallery_root.$folder_name;
  288. if (lg_make_directory($new_folder_path)) {
  289. echo '<div id="message" class="updated fade"><p>'. __('Folder created successfully', $lg_text_domain) .'</p></div>';
  290. } else {
  291. echo '<div id="message" class="error fade"><p>'. __('Cannot create folder: maybe it already exists or have bad permissions', $lg_text_domain) .'</p></div>';
  292. }
  293. } else {
  294. echo '<div id="message" class="error fade"><p>'. __('Cannot create an empty named folder.', $lg_text_domain) .'</p></div>';
  295. }
  296. unset($_POST);
  297. unset($_GET);
  298. }
  299. $imgfiles = get_imgfiles($capdir);
  300. $act_current = $capdir;
  301. // Provide eventual icons to the image array
  302. if (file_exists($gallery_root.$capdir.substr($capdir, 0, strlen($capdir)-1).".jpg")){
  303. $capdir_icon = substr($capdir, 0, strlen($capdir)-1).".jpg";
  304. $imgfiles[] = $capdir_icon;
  305. } else if (file_exists($gallery_root.$capdir.substr($capdir, 0, strlen($capdir)-1).".jpeg")){
  306. $capdir_icon = substr($capdir, 0, strlen($capdir)-1).".jpeg";
  307. $imgfiles[] = $capdir_icon;
  308. } else if (file_exists($gallery_root.$capdir.substr($capdir, 0, strlen($capdir)-1).".png")){
  309. $capdir_icon = substr($capdir, 0, strlen($capdir)-1).".png";
  310. $imgfiles[] = $capdir_icon;
  311. } else if (file_exists($gallery_root.$capdir.substr($capdir, 0, strlen($capdir)-1).".gif")){
  312. $capdir_icon = substr($capdir, 0, strlen($capdir)-1).".gif";
  313. $imgfiles[] = $capdir_icon;
  314. }
  315. /* =========
  316. * Main Page
  317. * ========= */
  318. echo '<h2>'. __('File Manager', $lg_text_domain) .'</h2>';
  319. if (strlen($capdir) > 0) {
  320. ?>
  321. <fieldset class="options">
  322. <h3><?php echo sprintf(__('Captions page for <code>%s</code>', $lg_text_domain), $act_current); ?></h3>
  323. <!-- Shortcuts-->
  324. <div style="padding:5px;display:block;background:#efefef;border:1px solid #ccc;height:20px;">
  325. <a href="<?php echo LG_ADM_PAGE; ?>">&laquo; <?php _e('Admin page', $lg_text_domain); ?></a>
  326. </div>
  327. <!-- End of Shortcuts-->
  328. <br />
  329. <!-- Tip div -->
  330. <div style="padding:5px;border:1px solid #3fbd3f;background:#beffbe;color:#088000;">
  331. <?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); ?>
  332. </div>
  333. <!-- End of tip div -->
  334. <form name="gallery_captions" method="post" action="<?php echo LG_FLM_PAGE; ?>">
  335. <input type="hidden" name="folder" value="<?php echo $act_current ?>"/>
  336. <table summary="thumbs" cellspacing="1" cellpadding="10">
  337. <tr>
  338. <!-- Folder Caption code -->
  339. <td colspan='2'><b>&raquo; <?php _e("Folder's description:", $lg_text_domain); ?></b>
  340. <?php
  341. $foldcap = clean_folder_caption($act_current, false);
  342. echo '<input type="text" name="folder_caption" value="'.$foldcap.'" size="80" style="width:98%" />';
  343. ?>
  344. <ul>
  345. <li>&raquo; <a href="<?php echo LG_FLM_PAGE ?>&amp;captions=<?php echo $act_current; ?>&amp;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>
  346. <li>&raquo; <a href="<?php echo LG_FLM_PAGE ?>&amp;captions=<?php echo $act_current; ?>&amp;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>
  347. <li>&raquo; <a href="<?php echo LG_FLM_PAGE ?>&amp;captions=<?php echo $act_current; ?>&amp;file_to_delete=<?php echo $gallery_root.$act_current ?>" class="delete" style="display:inline;"><?php _e('Erase this folder', $lg_text_domain); ?></a></li>
  348. </ul>
  349. </td>
  350. </tr>
  351. <tr>
  352. <td colspan="2">
  353. <input type="text" size="40" name="new_file_name" value="<?php echo substr($act_current, 0, strlen($act_current) -1); ?>" />
  354. <input type="hidden" name="actual_folder" value="<?php echo $gallery_root.$act_current; ?>" />
  355. <input type="submit" name="rename_the_folder" value="<?php _e('Rename this folder', $lg_text_domain); ?>" class="button" style="display:inline;" />
  356. </td>
  357. </tr>
  358. <tr>
  359. <td colspan="2" style="text-algin: left;" ><b>&raquo; <?php _e('Minimum level to access this folder:', $lg_text_domain); ?></b>
  360. <select name="folder_minimum_level">
  361. <?php
  362. for ($i = 1; $i < 11; $i++) {
  363. if ($i == get_minimum_folder_level($act_current)) {
  364. $selected = " selected='selected'";
  365. } else {
  366. $selected = '';
  367. }
  368. echo "\n\t<option value='$i' $selected>$i</option>";
  369. }
  370. ?>
  371. </select>
  372. <span style="font-size:x-small;text-align:center;padding:2px;color:red;border:1px solid #ff0000;background:#ffdddd">
  373. <?php _e('EXPERIMENTAL: Folder will be still browsable (if full path is known).', $lg_text_domain) ?>
  374. </span>
  375. </td>
  376. </tr>
  377. <!-- End of Folder Caption code -->
  378. <?php
  379. if (isset($imgfiles)) {
  380. foreach ($imgfiles as $img) {
  381. // clean_image_caption() function is in lazyest-gallery.php file
  382. // and checks if xml file exists, if not it returns false
  383. // we need a "clean" (with "<" and ">") caption
  384. $caption = clean_image_caption($img, $capdir);
  385. // this will removes HTML tags and used as title argument
  386. $title = ereg_replace("<[^>]*>", "", $caption);
  387. $righturl = str_replace(" ", "%20", $act_current.$img);
  388. echo '<tr><td><a href="'.$gallery_uri.'file='.$righturl.'">';
  389. // If thumbs cache system is enabled
  390. if (get_option('lg_enable_cache') == "TRUE"){
  391. // we check if thumbs exist
  392. if (!file_exists($gallery_root.$act_current.get_option('lg_thumb_folder').$img)) {
  393. // keeping track of subfolders
  394. $img_file_path = explode('/', $img);
  395. $img_index = count($img_file_path)-1;
  396. $img_file = $img_file_path[$img_index];
  397. // If there are subfolders
  398. if ($img_index > 1){
  399. for ($i = 1; $i < count($img_file_path)-1; $i++) {
  400. // set the new "current" directory
  401. $act_current .= $img_file_path[$i]."/";
  402. }
  403. }
  404. // if thumbs do not exist we create them
  405. createCache($act_current, $img, true);
  406. }
  407. // trimming spaces (XHTML Urls)
  408. $righturl = str_replace(" ", "%20", $gallery_address.$act_current.get_option('lg_thumb_folder').$img);
  409. echo '<img src="'.$righturl.'" alt="'.$img.'" title="'. $title . '" />';
  410. } else { // otherwise
  411. $righturl = str_replace(" ", "%20", get_option('siteurl')."/wp-content/plugins/lazyest-gallery/lazyest-img.php?file=". $act_current.$img."&amp;thumb=1");
  412. echo "<img src='".$righturl."' alt='".$img."' title='".$title."' />";
  413. }
  414. // this time we need a "rebuilded" (with "" and "") caption
  415. $caption = clean_image_caption($img, $capdir, false);
  416. // this is a dynamic form name construct that we need for the captions system
  417. $form_name = str_replace('.', '_', $img);
  418. $form_name = str_replace(' ', '_', $form_name);
  419. echo '</a></td>';
  420. echo '<td>&raquo; '.$img.'<br />';
  421. $righturl = str_replace(" ", "%20", $gallery_root.$act_current.$img);
  422. // Inputs
  423. ?>
  424. <input type="text" name="<?php echo $form_name; ?>" value="<?php echo $caption; ?>" size="90" style="width:88%" />
  425. <a href="<?php echo LG_FLM_PAGE ?>&amp;captions=<?php echo str_replace(" ", "%20", $act_current); ?>&amp;file_to_delete=<?php echo $righturl ?>" class="button" style="display:inline;"><?php _e('Delete', $lg_text_domain); ?></a>
  426. <?php
  427. }
  428. }
  429. ?>
  430. </table>
  431. <div class="submit">
  432. <input type="hidden" name="directory" value="<?php echo $act_current ?>" />
  433. <input type="submit" name="update_captions" value="<?php _e('Update Folder', $lg_text_domain); ?>" />
  434. </div>
  435. </form>
  436. </fieldset>
  437. <!-- Upload section -->
  438. <fieldset class="dbx-box">
  439. <h3 class="dbx-handle"><?php _e('Upload Image', $lg_text_domain) ?></h3>
  440. <div class="dbx-content">
  441. <?php upload_page($act_current); ?>
  442. </div><br /><br />
  443. </fieldset>
  444. <?php } // Closes the main page if ?>
  445. <!-- Gallery structure section -->
  446. <fieldset class="dbx-box">
  447. <h3 class="dbx-handle"><?php _e('Gallery Structure', $lg_text_domain) ?></h3>
  448. <form name="new_folder" method="post" action="<?php echo LG_FLM_PAGE; ?>">
  449. <!-- New folder creation form -->
  450. <input type="text" name="new_folder_name" size="40" style="width:78%;"/>
  451. <?php if (file_exists($gallery_root.$act_current)) { ?>
  452. <input type="hidden" name="actual_folder" value="<?php echo $act_current; ?>"/>
  453. <?php } ?>
  454. <input type="submit" name="create_new_folder" value="<?php _e('New Folder', $lg_text_domain); ?>" style="width:20%"/>
  455. </form>
  456. <div class="dbx-content">
  457. <?php lg_show_gallery_structure(); ?>
  458. </div>
  459. </fieldset>
  460. </div>
  461. <?php
  462. }
  463. /**
  464. * This function builds the xml file where images infos are stored
  465. * NOTE: $capdir stays for Captions Directory
  466. */
  467. function lg_generate_xml($capdir){
  468. global $gallery_root;
  469. if (is_writable($gallery_root.$capdir)){
  470. // Gather the image's informations and ID number
  471. $imgfiles = get_imgfiles($capdir);
  472. $images_data = get_image_caption($capdir);
  473. // Check if $capdir ends with the "/" and providing one if not
  474. if (substr($capdir, strlen($capdir)-1, strlen($capdir)) != "/")
  475. $capdir .= "/";
  476. $handle = fopen($gallery_root.$capdir.'captions.xml', 'wb');
  477. fwrite($handle, "<?xml version='1.0' encoding='" . get_option('blog_charset') . "'?>\n");
  478. fwrite($handle, "<data>\n");
  479. // Folder caption; TODO valute htmlentities()
  480. $folder_caption = utf8_encode(str_replace('\\', '', $_POST['folder_caption']));
  481. fwrite($handle, "\t<folder>".$folder_caption."</folder>\n");
  482. // Folder access level
  483. $folder_access = $_POST['folder_minimum_level'];
  484. fwrite($handle, "\t<level>".$folder_access."</level>\n");
  485. if (isset($imgfiles)) {
  486. foreach ($imgfiles as $img) {
  487. // prepare the strings to be written
  488. $form_value = str_replace('.', '_', $img);
  489. $form_value = str_replace(' ', '_', $form_value);
  490. $dirty_caption = utf8_encode($_POST[$form_value]);
  491. $clean_caption = str_replace('\\', '', $dirty_caption);
  492. // write strings
  493. fwrite($handle, "\t<photo id='". $img ."'>\n");
  494. fwrite($handle, "\t\t<caption>". $clean_caption ."</caption>\n");
  495. for ($i = 0; $i < count($images_data); $i++) {
  496. if ($images_data[$i][image] == $img){
  497. $image_number = $images_data[$i][id];
  498. }
  499. }
  500. // If is not setted update the counter and...
  501. if (strlen($image_number) == 0) {
  502. add_option('lg_image_indexing', '0', 'Lazyest Gallery images index to retrive comments');
  503. $image_number = get_option('lg_image_indexing');
  504. $counter = $image_number +1;
  505. update_option('lg_image_indexing', $counter);
  506. }
  507. // ...provide one
  508. fwrite($handle, "\t\t<image>". $image_number ."</image>\n");
  509. fwrite($handle, "\t</photo>\n");
  510. }
  511. }
  512. fwrite($handle, "</data>");
  513. fclose($handle);
  514. @chmod($gallery_root.$capdir.'captions.xml', 0666);
  515. }
  516. else {
  517. return lg_cannot_rw($capdir);
  518. }
  519. }
  520. function lg_cannot_rw($rwdir){
  521. global $gallery_root;
  522. ?>
  523. <div style='background-color: rgb(207, 235, 247);' id='message' class='error fade'>
  524. <b>WARNING:</b><br />
  525. <p>
  526. Unable to create xml file inside <?php echo $gallery_root.$rwdir; ?> <br />
  527. File permissions are actually set to
  528. <b><?php echo substr(sprintf('%o', fileperms($gallery_root.$rwdir)), -4) ?></b><br />
  529. Try to set them to <b>777</b>
  530. </p>
  531. </div>
  532. <?php
  533. }
  534. // ============= File Manager Utility Functions =============
  535. function lg_clear_directory($path) {
  536. if($dir_handle = opendir($path)) {
  537. while($file = readdir($dir_handle)) {
  538. if(is_dir($path.$file) && $file != "." && $file != ".."){
  539. lg_clear_directory($path.$file.'/');
  540. lg_remove_directory($path.$file.'/');
  541. } else {
  542. if($file == "." || $file == "..") {
  543. continue;
  544. } else {
  545. unlink($path.$file);
  546. }
  547. }
  548. }
  549. closedir($dir_handle);
  550. return true;
  551. // all files deleted
  552. } else {
  553. return false;
  554. // directory doesn't exist
  555. }
  556. }
  557. function lg_remove_directory($path) {
  558. if(lg_clear_directory($path)){
  559. if(rmdir($path)){
  560. return true;
  561. // directory removed
  562. } else {
  563. return false;
  564. // directory couldn't removed
  565. }
  566. } else {
  567. return false;
  568. // no empty directory
  569. }
  570. }
  571. function lg_make_directory($path) {
  572. if (@mkdir($path, 0777)){
  573. return true;
  574. } else {
  575. return false;
  576. }
  577. }
  578. function lg_rename_file($oldname, $newname) {
  579. if (@rename($oldname, $newname)){
  580. return true;
  581. } else {
  582. return false;
  583. }
  584. }
  585. // ================= Write Options Page ================
  586. /* This is the function that will build the form in the editor */
  587. function lg_build_smartlink_form(){
  588. }
  589. /* Adds the gallery browser form in the posts editor */
  590. function lg_add_gallery_browser(){
  591. lg_build_smartlink_form();
  592. }
  593. // =================== Upload functions =================
  594. function upload_page($upload) {
  595. global $gallery_root, $gallery_address, $lg_text_domain;
  596. $folder = $gallery_root.$upload;
  597. if ( !get_option('lg_fileupload_minlevel') )
  598. die (__("You are not allowed to upload files", $lg_text_domain));
  599. $allowed_types = explode(' ', trim(strtolower(get_option('lg_fileupload_allowedtypes'))));
  600. foreach ($allowed_types as $type) {
  601. $type_tags[] = "<code>$type</code>";
  602. }
  603. $i = implode(', ', $type_tags);
  604. ?>
  605. <p><?php printf(__('You can upload files with the extension %1$s as long as they are no larger than %2$s <abbr title="Kilobytes">KB</abbr>.', $lg_text_domain), $i, get_option('lg_fileupload_maxk')); ?></p>
  606. <form action="<?php echo LG_FLM_PAGE; ?>" method="post" enctype="multipart/form-data">
  607. <p>
  608. <label for="img1"><?php _e('File:', $lg_text_domain) ?></label>
  609. <br />
  610. <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo get_option('lg_fileupload_maxk') * 1024 ?>" />
  611. <input type="file" name="img1" id="img1" size="100" />
  612. <input type="hidden" name="upload_folder" value="<?php echo $upload; ?>"/>
  613. </p>
  614. <p><input type="submit" name="upload" class="button" value="<?php _e('Upload File', $lg_text_domain) ?>" /></p>
  615. </form>
  616. <?php
  617. }
  618. // ================ Sobstitution functions ==============
  619. function lg_utf8_encode($txt){
  620. $txt2=str_replace('?','&#1040;',$txt);
  621. $txt2=str_replace('Á','&#1041;',$txt2);
  622. $txt2=str_replace('Â','&#1042;',$txt2);
  623. $txt2=str_replace('?','&#1043;',$txt2);
  624. $txt2=str_replace('Ä','&#1044;',$txt2);
  625. $txt2=str_replace('?','&#1045;',$txt2);
  626. $txt2=str_replace('?','&#1046;',$txt2);
  627. $txt2=str_replace('Ç','&#1047;',$txt2);
  628. $txt2=str_replace('?','&#1048;',$txt2);
  629. $txt2=str_replace('É','&#1049;',$txt2);
  630. $txt2=str_replace('?','&#1050;',$txt2);
  631. $txt2=str_replace('Ë','&#1051;',$txt2);
  632. $txt2=str_replace('?','&#1052;',$txt2);
  633. $txt2=str_replace('Í','&#1053;',$txt2);
  634. $txt2=str_replace('Î','&#1054;',$txt2);
  635. $txt2=str_replace('?','&#1055;',$txt2);
  636. $txt2=str_replace('?','&#1056;',$txt2);
  637. $txt2=str_replace('?','&#1057;',$txt2);
  638. $txt2=str_replace('?','&#1058;',$txt2);
  639. $txt2=str_replace('Ó','&#1059;',$txt2);
  640. $txt2=str_replace('Ô','&#1060;',$txt2);
  641. $txt2=str_replace('?','&#1061;',$txt2);
  642. $txt2=str_replace('Ö','&#1062;',$txt2);
  643. $txt2=str_replace('×','&#1063;',$txt2);
  644. $txt2=str_replace('?','&#1064;',$txt2);
  645. $txt2=str_replace('?','&#1065;',$txt2);
  646. $txt2=str_replace('Ú','&#1066;',$txt2);
  647. $txt2=str_replace('?','&#1067;',$txt2);
  648. $txt2=str_replace('Ü','&#1068;',$txt2);
  649. $txt2=str_replace('Ý','&#1069;',$txt2);
  650. $txt2=str_replace('?','&#1070;',$txt2);
  651. $txt2=str_replace('ß','&#1071;',$txt2);
  652. $txt2=str_replace('?','&#1072;',$txt2);
  653. $txt2=str_replace('á','&#1073;',$txt2);
  654. $txt2=str_replace('â','&#1074;',$txt2);
  655. $txt2=str_replace('?','&#1075;',$txt2);
  656. $txt2=str_replace('ä','&#1076;',$txt2);
  657. $txt2=str_replace('?','&#1077;',$txt2);
  658. $txt2=str_replace('?','&#1078;',$txt2);
  659. $txt2=str_replace('ç','&#1079;',$txt2);
  660. $txt2=str_replace('?','&#1080;',$txt2);
  661. $txt2=str_replace('é','&#1081;',$txt2);
  662. $txt2=str_replace('?','&#1082;',$txt2);
  663. $txt2=str_replace('ë','&#1083;',$txt2);
  664. $txt2=str_replace('?','&#1084;',$txt2);
  665. $txt2=str_replace('í','&#1085;',$txt2);
  666. $txt2=str_replace('î','&#1086;',$txt2);
  667. $txt2=str_replace('?','&#1087;',$txt2);
  668. $txt2=str_replace('?','&#1088;',$txt2);
  669. $txt2=str_replace('?','&#1089;',$txt2);
  670. $txt2=str_replace('?','&#1090;',$txt2);
  671. $txt2=str_replace('ó','&#1091;',$txt2);
  672. $txt2=str_replace('ô','&#1092;',$txt2);
  673. $txt2=str_replace('?','&#1093;',$txt2);
  674. $txt2=str_replace('ö','&#1094;',$txt2);
  675. $txt2=str_replace('÷','&#1095;',$txt2);
  676. $txt2=str_replace('?','&#1096;',$txt2);
  677. $txt2=str_replace('?','&#1097;',$txt2);
  678. $txt2=str_replace('ú','&#1098;',$txt2);
  679. $txt2=str_replace('?','&#1099;',$txt2);
  680. $txt2=str_replace('ü','&#1100;',$txt2);
  681. $txt2=str_replace('ý','&#1101;',$txt2);
  682. $txt2=str_replace('?','&#1102;',$txt2);
  683. $txt2=str_replace('?','&#1103;',$txt2);
  684. return $txt2;
  685. }
  686. ?>