PageRenderTime 46ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/lazyest-gallery/mass-upload.php

http://cartonbank.googlecode.com/
PHP | 1032 lines | 752 code | 163 blank | 117 comment | 126 complexity | fbaed420eb006069ec3f6d6692ad4a5b MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, LGPL-2.1, AGPL-1.0, LGPL-3.0
  1. <?php
  2. require_once('lazyest-gallery.php');
  3. global $gallery_root;
  4. define('AL_FLM_PAGE', 'admin.php?page=lazyest-gallery/mass-upload.php');
  5. get_artist_id_by_folder_name();
  6. /*
  7. //print_r ($HTTP_POST_VARS);
  8. //print_r ($_POST);
  9. echo '<pre>';
  10. var_dump($_POST);
  11. echo '</pre>';
  12. exit;
  13. */
  14. // Actions ==========================================================
  15. if (isset ($_POST['img_path']))
  16. {
  17. al_write_to_db();
  18. }
  19. al_build_captions_form();
  20. // stop actions ==========================================================
  21. // start functions ==========================================================
  22. function al_build_captions_form(){
  23. global $gallery_root, $gallery_address, $lg_text_domain;
  24. $capdir = $_GET['captions'];
  25. if (strlen($capdir) == 0){
  26. $capdir = $_POST['upload_folder'];
  27. }
  28. $gallery_uri = get_option('lg_gallery_uri');
  29. // Fix for permalinks
  30. if (strlen(get_option('permalink_structure')) != 0){
  31. $gallery_uri = $gallery_uri.'?';
  32. } else {
  33. $gallery_uri = $gallery_uri.'&amp;';
  34. }
  35. // main container div
  36. echo '<div class="wrap">';
  37. // Button: save captions (lazyest-captions.php)
  38. if(isset($_POST['update_captions'])){
  39. al_generate_xml($_POST['directory']);
  40. }
  41. /* ==========
  42. * Upload div
  43. * ========== */
  44. $folder = $gallery_root.$capdir;
  45. // $_POST['upload_folder'];
  46. $allowed_types = explode(' ', trim(strtolower(get_option('lg_fileupload_allowedtypes'))));
  47. if ($_POST['upload']) {
  48. $action = 'upload';
  49. if (!is_writable($folder))
  50. $action = 'not-writable';
  51. switch ($action) {
  52. case 'not-writable':
  53. ?>
  54. <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>
  55. <?php
  56. break;
  57. case 'upload':
  58. $imgalt = basename( (isset($_POST['imgalt'])) ? $_POST['imgalt'] : '' );
  59. $img1_name = (strlen($imgalt)) ? $imgalt : basename( $_FILES['img1']['name'] );
  60. $img1_name = preg_replace('/[^a-z0-9_.]/i', '', $img1_name);
  61. $img1_size = $_POST['img1_size'] ? intval($_POST['img1_size']) : intval($_FILES['img1']['size']);
  62. $img1_type = (strlen($imgalt)) ? $_POST['img1_type'] : $_FILES['img1']['type'];
  63. $pi = pathinfo($img1_name);
  64. $imgtype = strtolower($pi['extension']);
  65. if (in_array($imgtype, $allowed_types) == false)
  66. die(sprintf(__('File %1$s of type %2$s is not allowed.', $lg_text_domain) , $img1_name, $imgtype));
  67. if (strlen($imgalt)) {
  68. $pathtofile = $folder.$imgalt;
  69. $img1 = $_POST['img1'];
  70. } else {
  71. $pathtofile = $folder.$img1_name;
  72. $img1 = $_FILES['img1']['tmp_name'];
  73. }
  74. // makes sure not to upload duplicates, rename duplicates
  75. $i = 1;
  76. $pathtofile2 = $pathtofile;
  77. $tmppathtofile = $pathtofile2;
  78. $img2_name = $img1_name;
  79. while ( file_exists($pathtofile2) ) {
  80. $pos = strpos( strtolower($tmppathtofile), '.' . trim($imgtype) );
  81. $pathtofile_start = substr($tmppathtofile, 0, $pos);
  82. $pathtofile2 = $pathtofile_start.'_'.zeroise($i++, 2).'.'.trim($imgtype);
  83. $img2_name = explode('/', $pathtofile2);
  84. $img2_name = $img2_name[count($img2_name)-1];
  85. }
  86. if (file_exists($pathtofile) && !strlen($imgalt)) {
  87. $i = explode(' ', get_option('lg_fileupload_allowedtypes'));
  88. $i = implode(', ',array_slice($i, 1, count($i)-2));
  89. $moved = move_uploaded_file($img1, $pathtofile2);
  90. if (!$moved) {
  91. $moved = copy($img1, $pathtofile2);
  92. }
  93. if (!$moved) {
  94. die(sprintf(__("Couldn't upload your file to %s.", $lg_text_domain), $pathtofile2));
  95. } else {
  96. chmod($pathtofile2, 0666);
  97. @unlink($img1);
  98. }
  99. //
  100. // duplicate-renaming function contributed by Gary Lawrence Murphy
  101. ?>
  102. <p><strong><?php __('Duplicate File?') ?></strong></p>
  103. <p><b><em><?php printf(__("The filename '%s' already exists!", $lg_text_domain), $img1_name); ?></em></b></p>
  104. <p><?php printf(__("Filename '%1\$s' moved to '%2\$s'", $lg_text_domain), $img1, "$pathtofile2 - $img2_name") ?></p>
  105. <p><?php _e('Confirm or rename:') ?></p>
  106. <form action="<?php echo AL_FLM_PAGE; ?>&amp;captions=<?php echo $capdir; ?>" method="post" enctype="multipart/form-data">
  107. <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo get_option('lg_fileupload_maxk') *1024 ?>" />
  108. <input type="hidden" name="img1_type" value="<?php echo $img1_type;?>" />
  109. <input type="hidden" name="img1_name" value="<?php echo $img2_name;?>" />
  110. <input type="hidden" name="img1_size" value="<?php echo $img1_size;?>" />
  111. <input type="hidden" name="img1" value="<?php echo $pathtofile2;?>" />
  112. <?php _e('Alternate name:') ?><br /><input type="text" name="imgalt" size="30" class="uploadform" value="<?php echo $img2_name;?>" /><br />
  113. <br />
  114. <input type="submit" name="submit" value="<?php _e('Rename', $lg_text_domain) ?>" class="search" />
  115. </form>
  116. <?php
  117. die();
  118. }
  119. if (!strlen($imgalt)) {
  120. @$moved = move_uploaded_file($img1, $pathtofile); //Path to your images directory, chmod the dir to 777
  121. // move_uploaded_file() can fail if open_basedir in PHP.INI doesn't
  122. // include your tmp directory. Try copy instead?
  123. if(!$moved) {
  124. $moved = copy($img1, $pathtofile);
  125. }
  126. // Still couldn't get it. Give up.
  127. if (!$moved) {
  128. die(sprintf(__("Couldn't upload your file to %s.", $lg_text_domain), $pathtofile));
  129. } else {
  130. chmod($pathtofile, 0666);
  131. @unlink($img1);
  132. }
  133. } else {
  134. rename($img1, $pathtofile)
  135. or die(sprintf(__("Couldn't upload your file to %s.", $lg_text_domain), $pathtofile));
  136. }
  137. if ( ereg('image/',$img1_type) )
  138. $piece_of_code = "[[Image:".$capdir.$img1_name."]]";
  139. else
  140. $piece_of_code = "<a href='" . $gallery_address.$capdir.$img1_name . "'>$img1_name</a>";
  141. $piece_of_code = htmlspecialchars( $piece_of_code );
  142. ?>
  143. <div id="message" class="updated fade"><p><?php _e('File uploaded!', $lg_text_domain) ?></p></div>
  144. <p><?php printf(__("Your file <code>%s</code> was uploaded successfully!", $lg_text_domain), $img1_name); ?></p>
  145. <p><?php _e('Here&#8217;s the code to display it in your posts:', $lg_text_domain) ?></p>
  146. <p><code><?php echo $piece_of_code; ?></code></p>
  147. <p>
  148. <strong><?php _e('Image Details') ?></strong>: <br />
  149. <?php _e('Name:'); ?>
  150. <?php echo $img1_name; ?>
  151. <br />
  152. <?php _e('Size:') ?>
  153. <?php echo round($img1_size / 1024, 2); ?> <?php _e('<abbr title="Kilobyte">KB</abbr>', $lg_text_domain) ?><br />
  154. <?php _e('Type:') ?>
  155. <?php echo $img1_type; ?>
  156. </p>
  157. <p><a href="<?php echo AL_FLM_PAGE; ?>&amp;captions=<?php echo $capdir; ?>"><?php _e('Upload another') ?></a></p>
  158. <?php
  159. break;
  160. }
  161. }
  162. /* =================
  163. * End of Upload div
  164. * ================= */
  165. /* ====================
  166. * Confirm deletion div
  167. * ==================== */
  168. if (isset($_POST['yes'])) {
  169. $hirez_to_delete = $gallery_root.$act_current.$capdir.basename($_POST['delete_this']);
  170. $thumb_to_delete = $gallery_root.$act_current.$capdir.get_option('lg_thumb_folder').basename($_POST['delete_this']);
  171. if (!is_dir($hirez_to_delete)) {
  172. if(@unlink($hirez_to_delete)) {
  173. @unlink($thumb_to_delete);
  174. echo '<div id="message" class="updated fade"><p>'. __('File deleted successfully', $lg_text_domain) .'</p></div>';
  175. } else {
  176. 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>';
  177. }
  178. } else {
  179. if(lg_remove_directory($_POST['delete_this'])) {
  180. echo '<div id="message" class="updated fade"><p>'. __('Folder deleted successfully', $lg_text_domain) .'</p></div>';
  181. } else {
  182. 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>';
  183. }
  184. }
  185. /*
  186. if (!is_dir($_POST['delete_this'])) {
  187. if(@unlink($_POST['delete_this'])) {
  188. echo '<div id="message" class="updated fade"><p>'. __('File deleted successfully', $lg_text_domain) .'</p></div>';
  189. } else {
  190. 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>';
  191. }
  192. } else {
  193. if(lg_remove_directory($_POST['delete_this'])) {
  194. echo '<div id="message" class="updated fade"><p>'. __('Folder deleted successfully', $lg_text_domain) .'</p></div>';
  195. } else {
  196. 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>';
  197. }
  198. }
  199. */
  200. // Unsetting informations
  201. unset($_POST);
  202. unset($_GET);
  203. }
  204. if (isset($_POST['no'])) {
  205. echo '<div id="message" class="updated fade"><p>'. __('Nothing Changed', $lg_text_domain) .'</p></div>';
  206. // Unsetting informations
  207. unset($_POST);
  208. unset($_GET);
  209. }
  210. /* =================
  211. * file deletion div
  212. * ================= */
  213. if (isset($_GET['file_to_delete']) &&
  214. !isset($_POST['update_captions']) &&
  215. !isset($_POST['upload']) &&
  216. !isset($_POST['create_new_folder']) &&
  217. !isset($_POST['rename_the_folder']) &&
  218. !isset($_POST['yes']) &&
  219. !isset($_POST['no'])) {
  220. ?>
  221. <div style="padding:10px;">
  222. <div style="text-align:center;padding:0px;color:red;border:1px solid #ff0000;background:#ffdddd">
  223. <?php
  224. _e('You are about to delete', $lg_text_domain);
  225. echo " <code>".basename($_GET['file_to_delete'])."</code><br />";
  226. echo __('Are you sure?', $lg_text_domain)."<br />";
  227. ?>
  228. <form name="delete_image_file" method="post" action="<?php echo AL_FLM_PAGE; ?>&amp;captions=<?php echo $capdir; ?>" style="padding:5px;">
  229. <div class="submit" style="text-align:center">
  230. <input type="submit" name="yes" value="<?php _e('Yes', $lg_text_domain); ?>" style="width:80px;" />
  231. <input type="submit" name="no" value="<?php _e('No', $lg_text_domain); ?>" style="width:80px;" />
  232. <input type="hidden" name="folder" value="<?php echo $_POST['folder']; ?>" />
  233. <input type="hidden" name="delete_this" value="<?php echo $_GET['file_to_delete']; ?>" />
  234. </div>
  235. </form>
  236. <?php
  237. echo "</div>\n</div>";
  238. }
  239. /* =================
  240. * Rename folder div
  241. * ================= */
  242. if (isset($_POST['rename_the_folder'])){
  243. if (strlen($_POST['new_file_name']) > 0){
  244. $oldname = $_POST['actual_folder'];
  245. $newname = $gallery_root.$_POST['new_file_name'];
  246. if (lg_rename_file($oldname, $newname)){
  247. echo '<div id="message" class="updated fade"><p>'. __('Renamed successfully', $lg_text_domain) .'</p></div>';
  248. } else {
  249. echo '<div id="message" class="error fade"><p>'. __('Cannot rename.', $lg_text_domain) .'</p></div>';
  250. }
  251. } else {
  252. echo '<div id="message" class="error fade"><p>'. __('Provide a new name.', $lg_text_domain) .'</p></div>';
  253. }
  254. unset($_POST);
  255. unset($_GET);
  256. }
  257. /* =======================
  258. * New folder creation div
  259. * ======================= */
  260. if (isset($_POST['create_new_folder'])) {
  261. if (strlen($_POST['new_folder_name']) > 0) {
  262. $folder_name = $_POST['actual_folder'].$_POST['new_folder_name'];
  263. $new_folder_path = $gallery_root.$folder_name;
  264. if (lg_make_directory($new_folder_path)) {
  265. echo '<div id="message" class="updated fade"><p>'. __('Folder created successfully', $lg_text_domain) .'</p></div>';
  266. } else {
  267. echo '<div id="message" class="error fade"><p>'. __('Cannot create folder: maybe it already exists or have bad permissions', $lg_text_domain) .'</p></div>';
  268. }
  269. } else {
  270. echo '<div id="message" class="error fade"><p>'. __('Cannot create an empty named folder.', $lg_text_domain) .'</p></div>';
  271. }
  272. unset($_POST);
  273. unset($_GET);
  274. }
  275. $imgfiles = get_imgfiles($capdir);
  276. $act_current = $capdir;
  277. // Provide eventual icons to the image array
  278. if (file_exists($gallery_root.$capdir.substr($capdir, 0, strlen($capdir)-1).".jpg")){
  279. $capdir_icon = substr($capdir, 0, strlen($capdir)-1).".jpg";
  280. $imgfiles[] = $capdir_icon;
  281. } else if (file_exists($gallery_root.$capdir.substr($capdir, 0, strlen($capdir)-1).".jpeg")){
  282. $capdir_icon = substr($capdir, 0, strlen($capdir)-1).".jpeg";
  283. $imgfiles[] = $capdir_icon;
  284. } else if (file_exists($gallery_root.$capdir.substr($capdir, 0, strlen($capdir)-1).".png")){
  285. $capdir_icon = substr($capdir, 0, strlen($capdir)-1).".png";
  286. $imgfiles[] = $capdir_icon;
  287. } else if (file_exists($gallery_root.$capdir.substr($capdir, 0, strlen($capdir)-1).".gif")){
  288. $capdir_icon = substr($capdir, 0, strlen($capdir)-1).".gif";
  289. $imgfiles[] = $capdir_icon;
  290. }
  291. /* =========
  292. * Main Page
  293. * ========= */
  294. echo '<h2>'. __('????????? ? ????????? ?? ????', $lg_text_domain) .'</h2>';
  295. if (strlen($capdir) > 0) {
  296. ?>
  297. <fieldset class="options">
  298. <h3><?php echo sprintf(__('?????? ???????? ? ????? %s', $lg_text_domain), $act_current); ?></h3>
  299. <!-- Shortcuts-->
  300. <div style="padding:5px;display:block;background:#efefef;border:1px solid #ccc;height:20px;">
  301. <a href="<?php echo AL_FLM_PAGE; ?>">&laquo; <?php _e('????? ? ?????? ?????', $lg_text_domain); ?></a>
  302. </div>
  303. <!-- End of Shortcuts-->
  304. <br />
  305. <!-- Tip div -->
  306. <!-- <div style="padding:5px;border:1px solid #3fbd3f;background:#beffbe;color:#088000;">
  307. <?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); ?>
  308. </div> -->
  309. <!-- End of tip div -->
  310. <form name="gallery_captions" method="post" action="<?php echo AL_FLM_PAGE; ?>&amp;captions=<?php echo $capdir; ?>">
  311. <input type="hidden" name="folder" value="<?php echo $act_current ?>"/>
  312. <table summary="thumbs" cellspacing="1" cellpadding="10">
  313. <!-- End of Folder Caption code -->
  314. <?php
  315. if (isset($imgfiles)) {
  316. foreach ($imgfiles as $img) {
  317. // clean_image_caption() function is in lazyest-gallery.php file
  318. // and checks if xml file exists, if not it returns false
  319. // we need a "clean" (with "<" and ">") caption
  320. $caption = clean_image_caption($img, $capdir);
  321. // this will removes HTML tags and used as title argument
  322. $title = ereg_replace("<[^>]*>", "", $caption);
  323. $righturl = str_replace(" ", "%20", $act_current.$img);
  324. echo '<tr><td><a href="'.$gallery_uri.'file='.$righturl.'">';
  325. // If thumbs cache system is enabled
  326. if (get_option('lg_enable_cache') == "TRUE"){
  327. // we check if thumbs exist
  328. if (!file_exists($gallery_root.$act_current.get_option('lg_thumb_folder').$img)) {
  329. // keeping track of subfolders
  330. $img_file_path = explode('/', $img);
  331. $img_index = count($img_file_path)-1;
  332. $img_file = $img_file_path[$img_index];
  333. // If there are subfolders
  334. if ($img_index > 1){
  335. for ($i = 1; $i < count($img_file_path)-1; $i++) {
  336. // set the new "current" directory
  337. $act_current .= $img_file_path[$i]."/";
  338. }
  339. }
  340. // if thumbs do not exist we create them
  341. createCache($act_current, $img, true);
  342. }
  343. // trimming spaces (XHTML Urls)
  344. $righturl = str_replace(" ", "%20", $gallery_address.$act_current.get_option('lg_thumb_folder').$img);
  345. echo '<img src="'.$righturl.'" alt="'.$img.'" title="'. $title . '" />';
  346. echo '<br />&raquo; '.$img;
  347. $size = getimagesize($gallery_root.$act_current.$img);
  348. echo '<br />'.$size[0]."x".$size[1]." px";
  349. ?>
  350. <br /><br /><a href="<?php echo AL_FLM_PAGE ?>&amp;captions=<?php echo str_replace(" ", "%20", $act_current); ?>&amp;file_to_delete=<?php echo $righturl ?>" class="button" style="width:50px;display:block;"><?php _e('Delete', $lg_text_domain); ?></a>
  351. <?
  352. } else { // otherwise
  353. $righturl = str_replace(" ", "%20", get_option('siteurl')."/wp-content/plugins/lazyest-gallery/".basename(__FILE__).".php?file=". $act_current.$img."&amp;thumb=1");
  354. echo "<img src='".$righturl."' alt='".$img."' title='".$title."' />";
  355. }
  356. // this time we need a "rebuilded" (with "" and "") caption
  357. $caption = clean_image_caption($img, $capdir, false);
  358. // this is a dynamic form name construct that we need for the captions system
  359. $form_name = str_replace('.', '_', $img);
  360. $form_name = str_replace(' ', '_', $form_name);
  361. echo '</a></td>';
  362. echo '<td align=right>';
  363. $righturl = str_replace(" ", "%20", $gallery_root.$act_current.$img);
  364. // Inputs
  365. ?>
  366. <form id="ImageUploadToDB" method="post" action="<?php echo AL_FLM_PAGE; ?>&amp;captions=<?php echo $capdir; ?>">
  367. ????????: <input type="text" name="img_title" style="width:95%;"><br />
  368. ????????: <textarea name="img_description" rows="3" cols="20" style="width:95%;"></textarea><br />
  369. ???????? ?????:<input type="text" name="img_tags" style="width:95%;"><br />
  370. ?????????: <?php echo topcategorylist(0);?><br />
  371. <!-- categ<input type="hidden" name="category" value="3" /> -->
  372. <input type="submit" name="submit" value="?????????">
  373. <input type="hidden" name="artist_id" value="<?php echo get_artist_id_by_folder_name();?>" />
  374. <input type="hidden" name="img_path" value="<?php echo $gallery_root.$act_current.$img ?>" />
  375. <br />
  376. </form>
  377. <?php
  378. }
  379. }
  380. ?>
  381. </table>
  382. <!-- <div class="submit">
  383. <input type="hidden" name="directory" value="<?php echo $act_current ?>" />
  384. <input type="submit" name="update_captions" value="<?php _e('Update Folder', $lg_text_domain); ?>" />
  385. </div> -->
  386. </form>
  387. </fieldset>
  388. <!-- Upload section -->
  389. <!-- <fieldset class="dbx-box">
  390. <h3 class="dbx-handle"><?php _e('Upload Image', $lg_text_domain) ?></h3>
  391. <div class="dbx-content">
  392. <?php upload_page($act_current); ?>
  393. </div><br /><br />
  394. </fieldset>
  395. -->
  396. <?php } // Closes the main page if ?>
  397. <!-- Gallery structure section -->
  398. <fieldset class="dbx-box">
  399. <h3 class="dbx-handle"><?php _e('?????? ????? ? ??????????', $lg_text_domain) ?></h3>
  400. <div class="dbx-content">
  401. <?php al_show_gallery_structure(); ?>
  402. </div>
  403. </fieldset>
  404. </div>
  405. <?php
  406. }
  407. function dirsize($path,$top=true)
  408. {
  409. static $total_size=0;
  410. if ($top==true) $total_size=0;
  411. if (is_dir($path)) {
  412. $dir=opendir ($path);
  413. while (($item = readdir($dir)) !== false) {
  414. if ($item=="." || $item=="..") continue;
  415. $full_path="$path/$item";
  416. if (is_file($full_path))
  417. $total_size+=filesize($full_path);
  418. else if (is_dir($full_path))
  419. dirsize($full_path,false);
  420. }
  421. closedir($dir);
  422. return $total_size;
  423. }else
  424. return -1;
  425. }
  426. function count_files($path)
  427. {
  428. if ($handle = opendir($path)) {
  429. while (false !== ($file = readdir($handle))) {
  430. if ($file != "." && $file != "..") {
  431. $file = $path.$file;
  432. if(is_file($file)) $numfile++;
  433. if(is_dir($file)) $numdir++;
  434. };
  435. };
  436. closedir($handle);
  437. };
  438. if ($numfile > 0)
  439. {
  440. return $numfile;
  441. }
  442. else
  443. {
  444. return 0;
  445. }
  446. }
  447. function al_show_gallery_structure(){
  448. global $gallery_root, $lg_text_domain;
  449. echo "<div style='font-family:monospace;background:#efefef;padding:5px;border:1px solid #ccc;'>\n";
  450. echo "<ul>\n";
  451. if (file_exists($gallery_root)){
  452. if ($dir_content = opendir($gallery_root)) {
  453. while ( false !== ($dir = readdir($dir_content)) ) {
  454. if (is_dir($gallery_root.$dir) && !in_array($dir, get_option('lg_excluded_folders')) && $dir!='.' && $dir!='..' ) {
  455. al_show_structure($dir);
  456. }
  457. }
  458. }
  459. }
  460. else {
  461. 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>";
  462. }
  463. echo "</ul>\n";
  464. echo "</div>\n";
  465. }
  466. function al_show_structure($sscurrentdir){
  467. global $excluded_folders, $gallery_root, $lg_text_domain;
  468. if( substr($sscurrentdir, strlen($sscurrentdir)-1 ) != '/'){
  469. $sscurrentdir .= '/';
  470. }
  471. $count_files = count_files($gallery_root.$sscurrentdir);
  472. //$count_size = dirsize($gallery_root.$sscurrentdir,true);
  473. $righturl = urlencode($sscurrentdir);
  474. echo '<li><a href="'. AL_FLM_PAGE .'&amp;captions=' . $righturl . '">' . $sscurrentdir . '</a> ['.$count_files.']';
  475. if ($dir_content = opendir($gallery_root.$sscurrentdir)) {
  476. $dir_list = array();
  477. while ( false !== ($dir = readdir($dir_content)) ) {
  478. if (is_dir($gallery_root.$sscurrentdir.$dir) && !in_array($dir, get_option('lg_excluded_folders')) && $dir!='.' && $dir!='..' ) {
  479. $dir_list[] = $sscurrentdir.$dir;
  480. }
  481. }
  482. if($dir_list != NULL && sizeof($dir_list) > 0) {
  483. echo "<ul>\n";
  484. foreach($dir_list as $subdir) {
  485. al_show_structure($subdir);
  486. }
  487. echo "</ul>\n";
  488. }
  489. }
  490. echo '</li>';
  491. }
  492. function al_generate_xml($capdir){
  493. global $gallery_root;
  494. if (is_writable($gallery_root.$capdir)){
  495. // Gather the image's informations and ID number
  496. $imgfiles = get_imgfiles($capdir);
  497. $images_data = get_image_caption($capdir);
  498. // Check if $capdir ends with the "/" and providing one if not
  499. if (substr($capdir, strlen($capdir)-1, strlen($capdir)) != "/")
  500. $capdir .= "/";
  501. $handle = fopen($gallery_root.$capdir.'captions.xml', 'wb');
  502. fwrite($handle, "<?xml version='1.0' encoding='" . get_option('blog_charset') . "'?>\n");
  503. fwrite($handle, "<data>\n");
  504. // Folder caption; TODO valute htmlentities()
  505. $folder_caption = utf8_encode(str_replace('\\', '', $_POST['folder_caption']));
  506. fwrite($handle, "\t<folder>".$folder_caption."</folder>\n");
  507. // Folder access level
  508. $folder_access = $_POST['folder_minimum_level'];
  509. fwrite($handle, "\t<level>".$folder_access."</level>\n");
  510. if (isset($imgfiles)) {
  511. foreach ($imgfiles as $img) {
  512. // prepare the strings to be written
  513. $form_value = str_replace('.', '_', $img);
  514. $form_value = str_replace(' ', '_', $form_value);
  515. $dirty_caption = utf8_encode($_POST[$form_value]);
  516. $clean_caption = str_replace('\\', '', $dirty_caption);
  517. // write strings
  518. fwrite($handle, "\t<photo id='". $img ."'>\n");
  519. fwrite($handle, "\t\t<caption>". $clean_caption ."</caption>\n");
  520. for ($i = 0; $i < count($images_data); $i++) {
  521. if ($images_data[$i][image] == $img){
  522. $image_number = $images_data[$i][id];
  523. }
  524. }
  525. // If is not setted update the counter and...
  526. if (strlen($image_number) == 0) {
  527. add_option('lg_image_indexing', '0', 'Lazyest Gallery images index to retrive comments');
  528. $image_number = get_option('lg_image_indexing');
  529. $counter = $image_number +1;
  530. update_option('lg_image_indexing', $counter);
  531. }
  532. // ...provide one
  533. fwrite($handle, "\t\t<image>". $image_number ."</image>\n");
  534. fwrite($handle, "\t</photo>\n");
  535. }
  536. }
  537. fwrite($handle, "</data>");
  538. fclose($handle);
  539. @chmod($gallery_root.$capdir.'captions.xml', 0666);
  540. }
  541. else {
  542. return lg_cannot_rw($capdir);
  543. }
  544. }
  545. function get_artist_id_by_folder_name(){
  546. global $wpdb;
  547. $sql = "SELECT `brand_id` FROM `wp_brand_folder` WHERE `folder_name`= '".$_GET['captions']."'";
  548. $artist_ids = $wpdb->get_results("SELECT `brand_id` FROM `wp_brand_folder` WHERE `folder_name`= '".$_GET['captions']."'");
  549. $artist_id = $artist_ids[0]->brand_id;
  550. return $artist_id;
  551. }
  552. function topcategorylist($offset)
  553. {
  554. global $wpdb,$category_data;
  555. $options = "";
  556. $values = $wpdb->get_results("SELECT * FROM `wp_product_categories` WHERE `active`='1' ORDER BY `id` ASC",ARRAY_A);
  557. if($values != null)
  558. {
  559. foreach($values as $option)
  560. {
  561. $category_data[$option['id']] = $option['name'];
  562. if($_GET['catid'] == $option['id'])
  563. {
  564. $selected = "selected='selected'";
  565. }
  566. $options .= "<option $selected value='".$option['id']."'>".$option['name']."</option>\r\n";
  567. $selected = "";
  568. }
  569. }
  570. $concat .= "<select name='category_id'>".$options."</select>\r\n";
  571. return $concat;
  572. }
  573. function al_write_to_db(){
  574. if (isset ($_POST['img_path']))
  575. global $wpdb, $mimetype;
  576. {
  577. $img_title = $_POST['img_title'];
  578. $img_description = $_POST['img_description'];
  579. $img_tags = $_POST['img_tags'];
  580. $category_id = $_POST['category_id'];
  581. $artist_id = $_POST['artist_id'];
  582. $img_path = $_POST['img_path'];
  583. $file_name = basename($img_path);
  584. $basepath = str_replace("/wp-admin", "" , getcwd());
  585. $imagedir = $basepath."/wp-content/plugins/wp-shopping-cart/images/";
  586. $product_images = $basepath."/wp-content/plugins/wp-shopping-cart/product_images/";
  587. $filedir = $basepath."/wp-content/plugins/wp-shopping-cart/files/";
  588. $preview_clips_dir = $basepath."/wp-content/plugins/wp-shopping-cart/preview_clips/";
  589. $image = '';
  590. $height = get_option('product_image_height');
  591. $width = get_option('product_image_width');
  592. // copy and resize files
  593. if(!is_dir($product_images))
  594. {
  595. mkdir($product_images);
  596. }
  597. if(function_exists("getimagesize"))
  598. {
  599. copy($img_path, $product_images.$file_name);
  600. copy($img_path, $imagedir.$file_name);
  601. //$imgsize = getimagesize($product_images.$file_name);
  602. $imgsize = getimagesize($product_images.$file_name);
  603. ///homepages/35/d89900836/htdocs/cb/wp-content/plugins/wp-shopping-cart/product_images/bogorad081gp.jpg
  604. $file_w = $imgsize[0];
  605. $file_h = $imgsize[1];
  606. //ales here we replace slides to that from LG
  607. $chwidth = get_option('lg_pictwidth'); // crop size
  608. $chheight = get_option('lg_pictheight'); // crop size
  609. $thatdir = $product_images; //destination dir
  610. $ifolder = ''; //subfolder for artist
  611. $resample_quality = 100; //image quality
  612. al_create_resized_file($chwidth, $chheight, $thatdir, $ifolder, $file_name, $resample_quality);
  613. //$wm = "/home/www/z58365/cb/wp-content/plugins/wp-shopping-cart/images/watermark.gif";
  614. $wm = $basepath."/wp-content/plugins/lazyest-gallery/watermark.gif";
  615. wtrmark($thatdir.$file_name,$wm);
  616. // ales here we replace thumbs to that from LG
  617. $chwidth = $width; // crop size
  618. $chheight = $height; // crop size
  619. $thatdir = $imagedir; //destination dir
  620. al_create_cropped_file($chwidth, $chheight, $thatdir, $ifolder, $file_name, $resample_quality);
  621. $image = $wpdb->escape($file_name);
  622. // write to database
  623. $timestamp = time();
  624. $sql = "INSERT INTO `wp_product_files` ( `id` , `filename` , `mimetype` , `idhash` , `date` , `width`, `height`) VALUES ( '' , '', '', '', '$timestamp', '', '');";
  625. $wpdb->query($sql);
  626. $fileid_raw = $wpdb->get_results("SELECT `id` FROM `wp_product_files` WHERE `date` = '$timestamp'",ARRAY_A);
  627. $fileid = $fileid_raw[0]['id'];
  628. $idhash = sha1($fileid);
  629. if(copy($img_path,($filedir.$idhash)))
  630. {
  631. $sql = "UPDATE `wp_product_files` SET `filename` = '".$file_name."', `mimetype` = '".$mimetype."', `idhash` = '$idhash', `width` = '$file_w', `height` = '$file_h' WHERE `id` = '$fileid' LIMIT 1";
  632. $wpdb->query($sql);
  633. $insertsql = "INSERT INTO `wp_product_list` ( `id` , `name` , `description` , `additional_description` , `price` , `pnp`, `international_pnp`, `file` , `image` , `category`, `brand`, `quantity_limited`, `quantity`, `special`, `special_price`,`display_frontpage`, `notax` ) VALUES ('', '".$img_title."', '".$img_description."', '".$img_tags."','', '', '', '".$fileid."', '".$file_name."', '".$category_id."', '".$artist_id."', '$quantity_limited','$quantity','$special','$special_price','$display_frontpage','$notax');";
  634. if($wpdb->query($insertsql))
  635. {
  636. $product_id_data = $wpdb->get_results("SELECT LAST_INSERT_ID() AS `id` FROM `wp_product_list` LIMIT 1",ARRAY_A);
  637. $product_id = $product_id_data[0]['id'];
  638. }
  639. $sql = "INSERT INTO `wp_item_category_associations` ( `id` , `product_id` , `category_id` ) VALUES ('', '".$product_id."', '".$category_id."')";
  640. $wpdb->query($sql);
  641. unlink($img_path);
  642. }
  643. }
  644. }
  645. }
  646. function al_create_cropped_file($chwidth, $chheight, $thatdir, $ifolder, $file, $resample_quality = '100') {
  647. // Cropped thumbs creation (contributed by: dodo - http://pure-essence.net)
  648. global $mimetype;
  649. $gallery_root = '';
  650. $img_location = $gallery_root.$thatdir.$file;
  651. // Getting width ([0]) and height ([1]) maybe add options
  652. $size_bits = getimagesize($img_location);
  653. // Creating a resource image
  654. $path = pathinfo($img_location);
  655. switch(strtolower($path["extension"])){
  656. case "jpeg":
  657. case "jpg":
  658. $img = imagecreatefromjpeg($img_location);
  659. $mimetype = "image/jpeg";
  660. break;
  661. case "gif":
  662. $img = imagecreatefromgif($img_location);
  663. $mimetype = "image/gif";
  664. break;
  665. case "png":
  666. $img = imagecreatefrompng($img_location);
  667. $mimetype = "image/png";
  668. break;
  669. default:
  670. break;
  671. }
  672. if($size_bits[0] > $chwidth || $size_bits[1] > $chheight) {
  673. // Resize the image
  674. $resized = imagecreatetruecolor($chwidth, $chheight);
  675. $o_width = $size_bits[0];
  676. $o_height = $size_bits[1];
  677. // if the image is more wide than high
  678. if($o_width > $o_height) {
  679. // landscape image
  680. $out_width = $o_height;
  681. $out_height = $o_height;
  682. $cutoff = round(($o_width - $o_height) / 2);
  683. $out_left = $cutoff;
  684. $out_top = 0;
  685. } else {
  686. $cutoff = round(($o_height - $o_width) / 2);
  687. $out_width = $o_width;
  688. $out_height = $o_width;
  689. $out_left = 0;
  690. $out_top = $cutoff;
  691. }
  692. // Resampling the image
  693. imagecopyresampled ($resized, $img, 0, 0, $out_left, $out_top, $chwidth, $chheight, $out_width, $out_height);
  694. if (is_writable($gallery_root.$thatdir.$ifolder)){
  695. switch(strtolower($path["extension"])){
  696. case "jpeg":
  697. case "jpg":
  698. imagejpeg($resized, $gallery_root.$thatdir.$ifolder.'/'.$file, $resample_quality);
  699. break;
  700. case "gif":
  701. imagegif($resized, $gallery_root.$thatdir.$ifolder.'/'.$file);
  702. break;
  703. case "png":
  704. imagepng($resized, $gallery_root.$thatdir.$ifolder.'/'.$file);
  705. break;
  706. default:
  707. break;
  708. }
  709. } else {
  710. echo "<div class='error'><b>WARNING:</b> Unable to create $ifolder inside $thatdir. <br />";
  711. echo "Check your permissions.</div><br />";
  712. }
  713. imagedestroy($resized);
  714. } else {
  715. switch(strtolower($path["extension"])){
  716. case "jpeg":
  717. case "jpg":
  718. imagejpeg($img, $gallery_root.$thatdir.$ifolder.'/'.$file, $resample_quality);
  719. break;
  720. case "gif":
  721. imagegif($img, $gallery_root.$thatdir.$ifolder.'/'.$file);
  722. break;
  723. case "png":
  724. imagepng($img, $gallery_root.$thatdir.$ifolder.'/'.$file);
  725. break;
  726. default:
  727. break;
  728. }
  729. }
  730. }
  731. function al_create_resized_file($chwidth, $chheight, $thatdir, $ifolder, $file, $thumb, $resample_quality = '100') {
  732. // Default thumbs creation
  733. // global $gallery_root;
  734. $gallery_root = '';
  735. $img_location = $gallery_root.$thatdir.$file;
  736. // Creating a resource image
  737. $path = pathinfo($img_location);
  738. switch(strtolower($path["extension"])){
  739. case "jpeg":
  740. case "jpg":
  741. $img = imagecreatefromjpeg($img_location);
  742. break;
  743. case "gif":
  744. $img = imagecreatefromgif($img_location);
  745. break;
  746. case "png":
  747. $img = imagecreatefrompng($img_location);
  748. break;
  749. default:
  750. break;
  751. }
  752. $xratio = $chheight/(imagesx($img));
  753. $yratio = $chwidth/(imagesy($img));
  754. if($xratio < 1 || $yratio < 1) {
  755. if($xratio < $yratio)
  756. $resized = imagecreatetruecolor($chwidth,floor(imagesy($img)*$xratio));
  757. else
  758. $resized = imagecreatetruecolor(floor(imagesx($img)*$yratio), $chheight);
  759. imagecopyresampled($resized, $img, 0, 0, 0, 0, imagesx($resized)+1,imagesy($resized)+1,imagesx($img),imagesy($img));
  760. if (is_writable($gallery_root.$thatdir.$ifolder)){
  761. switch(strtolower($path["extension"])){
  762. case "jpeg":
  763. case "jpg":
  764. imagejpeg($resized, $gallery_root.$thatdir.$ifolder.'/'.$file, $resample_quality);
  765. break;
  766. case "gif":
  767. imagegif($resized, $gallery_root.$thatdir.$ifolder.'/'.$file);
  768. break;
  769. case "png":
  770. imagepng($resized, $gallery_root.$thatdir.$ifolder.'/'.$file);
  771. break;
  772. default:
  773. break;
  774. }
  775. }
  776. else {
  777. echo "<div class='error'><b>WARNING:</b> Unable to create images inside $ifolder. <br />";
  778. echo "Check your permissions.</div>";
  779. }
  780. imagedestroy($resized);
  781. } else {
  782. switch(strtolower($path["extension"])){
  783. case "jpeg":
  784. case "jpg":
  785. imagejpeg($img, $gallery_root.$thatdir.$ifolder.'/'.$file, $resample_quality);
  786. break;
  787. case "gif":
  788. imagegif($img, $gallery_root.$thatdir.$ifolder.'/'.$file);
  789. break;
  790. case "png":
  791. imagepng($img, $gallery_root.$thatdir.$ifolder.'/'.$file);
  792. break;
  793. default:
  794. break;
  795. }
  796. }
  797. // imagedestroy($img);
  798. }
  799. function wtrmark($sourcefile, $watermarkfile) {
  800. #
  801. # $sourcefile = Filename of the picture to be watermarked.
  802. # $watermarkfile = Filename of the 24-bit PNG watermark file.
  803. #
  804. //$watermarkfile = "watermark.gif";
  805. //Get the resource ids of the pictures
  806. //$watermarkfile_id = imagecreatefrompng($watermarkfile);
  807. $watermarkfile_id = imagecreatefromgif($watermarkfile);
  808. imageAlphaBlending($watermarkfile_id, false);
  809. imageSaveAlpha($watermarkfile_id, true);
  810. $fileType = strtolower(substr($sourcefile, strlen($sourcefile)-3));
  811. switch($fileType) {
  812. case('gif'):
  813. $sourcefile_id = imagecreatefromgif($sourcefile);
  814. break;
  815. case('png'):
  816. $sourcefile_id = imagecreatefrompng($sourcefile);
  817. break;
  818. default:
  819. $sourcefile_id = imagecreatefromjpeg($sourcefile);
  820. }
  821. //Get the sizes of both pix
  822. $sourcefile_width=imageSX($sourcefile_id);
  823. $sourcefile_height=imageSY($sourcefile_id);
  824. $watermarkfile_width=imageSX($watermarkfile_id);
  825. $watermarkfile_height=imageSY($watermarkfile_id);
  826. $dest_x = ( $sourcefile_width / 2 ) - ( $watermarkfile_width / 2 );
  827. $dest_y = ( $sourcefile_height / 2 ) - ( $watermarkfile_height / 2 );
  828. // if a gif, we have to upsample it to a truecolor image
  829. if($fileType == 'gif') {
  830. // create an empty truecolor container
  831. $tempimage = imagecreatetruecolor($sourcefile_width,$sourcefile_height);
  832. // copy the 8-bit gif into the truecolor image
  833. imagecopy($tempimage, $sourcefile_id, 0, 0, 0, 0,
  834. $sourcefile_width, $sourcefile_height);
  835. // copy the source_id int
  836. $sourcefile_id = $tempimage;
  837. }
  838. imagecopy($sourcefile_id, $watermarkfile_id, $dest_x, $dest_y, 0, 0,
  839. $watermarkfile_width, $watermarkfile_height);
  840. //Create a jpeg out of the modified picture
  841. switch($fileType) {
  842. // remember we don't need gif any more, so we use only png or jpeg.
  843. // See the upsaple code immediately above to see how we handle gifs
  844. case('png'):
  845. //header("Content-type: image/png");
  846. imagepng ($sourcefile_id,$sourcefile);
  847. break;
  848. default:
  849. //header("Content-type: image/jpg");
  850. imagejpeg ($sourcefile_id,$sourcefile);
  851. }
  852. imagedestroy($sourcefile_id);
  853. imagedestroy($watermarkfile_id);
  854. }
  855. // end functions ==========================================================
  856. ?>
  857. <pre>
  858. <?php
  859. //htmlspecialchars(print_r(get_alloptions()));
  860. //print_r($_POST);
  861. //print_r($_GET);
  862. ?>
  863. </pre>