PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/album_mod/album_functions_otf.php

http://github.com/MightyGorgon/icy_phoenix
PHP | 180 lines | 146 code | 15 blank | 19 comment | 24 complexity | 85b357df532e52f79cfb9017345bb1b7 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. if (!defined('IN_ICYPHOENIX'))
  11. {
  12. die('Hacking attempt');
  13. }
  14. // FUNCTIONS - BEGIN
  15. function pic_upload_to_cat($otf_pic_path, $otf_pic_filename, $otf_pic_extension, $otf_pic_title, $otf_pic_des, $otf_pic_cat, $otf_pic_time)
  16. {
  17. global $db, $user;
  18. $pic_base_path = IP_ROOT_PATH . ALBUM_UPLOAD_PATH;
  19. $pic_extra_path = '';
  20. $upload_path = $pic_base_path . $pic_extra_path;
  21. if (USERS_SUBFOLDERS_ALBUM == true)
  22. {
  23. $pic_extra_path = $user->data['user_id'] . '/';
  24. $upload_path = $pic_base_path . $pic_extra_path;
  25. if (!is_dir($upload_path))
  26. {
  27. $dir_creation = @mkdir($upload_path, 0777);
  28. if ($dir_creation == true)
  29. {
  30. @copy($pic_base_path . 'index.html', $upload_path . 'index.html');
  31. @chmod($upload_path . 'index.html', 0755);
  32. }
  33. else
  34. {
  35. $upload_path = $pic_base_path;
  36. }
  37. }
  38. }
  39. while (file_exists($upload_path . $otf_pic_filename . '.' . $otf_pic_extension))
  40. {
  41. $otf_pic_filename = $otf_pic_filename . '_' . time() . '_' . mt_rand(100000, 999999);
  42. }
  43. $otf_pic_full_filename = $otf_pic_filename . '.' . $otf_pic_extension;
  44. if ($otf_pic_time == '')
  45. {
  46. $otf_pic_time = time();
  47. }
  48. $otf_pic_username = $user->data['username'];
  49. $otf_pic_user_id = $user->data['user_id'];
  50. $otf_pic_user_ip = $user->data['session_ip'];
  51. $move_file = 'rename';
  52. //$move_file = 'copy';
  53. //$move_file = 'move_uploaded_file';
  54. $upload_success = $move_file($otf_pic_path, $upload_path . $otf_pic_full_filename);
  55. if ($upload_success)
  56. {
  57. @chmod($upload_path . $otf_pic_full_filename, 0777);
  58. $sql = "INSERT INTO " . ALBUM_TABLE . " (pic_filename, pic_thumbnail, pic_title, pic_desc, pic_user_id, pic_user_ip, pic_username, pic_time, pic_cat_id, pic_approval)
  59. VALUES ('" . $db->sql_escape($pic_extra_path . $otf_pic_full_filename) . "', '', '" . $db->sql_escape($otf_pic_title) . "', '" . $db->sql_escape($otf_pic_des) . "', '" . $otf_pic_user_id . "', '" . $db->sql_escape($otf_pic_user_ip) . "', '" . $db->sql_escape($otf_pic_username) . "', '" . $otf_pic_time . "', '" . $otf_pic_cat . "', '1')";
  60. $db->sql_return_on_error(true);
  61. $result = $db->sql_query($sql);
  62. $db->sql_return_on_error(false);
  63. if (!$result)
  64. {
  65. return false;
  66. }
  67. }
  68. return true;
  69. }
  70. function get_images_list($path, $gallery_name)
  71. {
  72. $files = array();
  73. $file_names = array();
  74. $i = 0;
  75. if (is_dir($path))
  76. {
  77. if ($dh = opendir($path))
  78. {
  79. while (($file = readdir($dh)) !== false)
  80. {
  81. if (($file == '.') || ($file == '..') || ($file == '.DS_Store'))
  82. {
  83. continue;
  84. }
  85. if(preg_match('/(\.gif$|\.png$|\.jpg|\.jpeg)$/is', $file))
  86. {
  87. $fullpath = $path . '/' . $file;
  88. $fkey = strtolower($file);
  89. while (array_key_exists($fkey, $file_names))
  90. {
  91. $fkey .= ' ';
  92. }
  93. $a = stat($fullpath);
  94. $files[$fkey]['size'] = $a['size'];
  95. if ($a['size'] == 0)
  96. {
  97. $files[$fkey]['sizetext'] = '-';
  98. }
  99. elseif ($a['size'] > 1024)
  100. {
  101. $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . ' Kb';
  102. }
  103. elseif ($a['size'] > 1024 * 1024)
  104. {
  105. $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . ' Mb';
  106. }
  107. else
  108. {
  109. $files[$fkey]['sizetext'] = $a['size'] . ' bytes';
  110. }
  111. $files[$fkey]['name'] = $file;
  112. $files[$fkey]['type'] = filetype($fullpath);
  113. $file_names[$i++] = $fkey;
  114. }
  115. }
  116. closedir($dh);
  117. }
  118. else
  119. {
  120. die ('Cannot open directory: ' . $path);
  121. }
  122. }
  123. else
  124. {
  125. die ('Path is not a directory: ' . $path);
  126. }
  127. sort($file_names, SORT_STRING);
  128. $sortedFiles = array();
  129. $i = 0;
  130. foreach($file_names as $f)
  131. {
  132. $sortedFiles[$i++] = $files[$f];
  133. }
  134. $js_images_list = '';
  135. $js_images_list .= '<script type="text/javascript">' . "\n";
  136. $js_images_list .= 'var ' . $gallery_name . ' = new Array(' . "\n";
  137. foreach ($sortedFiles as $file)
  138. {
  139. // get image sizes
  140. //list($width, $height, $type, $attr) = getimagesize("$path/$file[name]", &$info);
  141. list($width, $height, $type, $attr) = getimagesize($path . '/' . $file['name'], $info);
  142. /*
  143. $width = imagesx($path . '/' . $file['name']);
  144. $height = imagesy($path . '/' . $file['name']);
  145. */
  146. $size = $file['sizetext'];
  147. $iptc = iptcparse($info['APP13']);
  148. // iptc info
  149. $iptc = iptcparse($info['APP13']);
  150. $title = $iptc['2#005'][0];
  151. $description = $iptc['2#120'][0];
  152. $description = str_replace("\r", '<br />', $description);
  153. $description = addslashes($description);
  154. $keywords = $iptc['2#025'][0];
  155. $author = $iptc['2#080'][0];
  156. $copyright = $iptc['2#116'][0];
  157. $js_images_list .= 'new Array(\'' . $path . '/' . $file['name'] . '\', \'' . $width . '\', \'' . $height . '\', \'' . $size . '\', \'' . $title . '\', \'' . $author . '\', \'' . $copyright . '\', \'' . $description . '\'),' . "\n";
  158. }
  159. $js_images_list .= 'new Array(\'\', \'\')' . "\n";
  160. $js_images_list .= ');' . "\n";
  161. $js_images_list .= '</script>' . "\n";
  162. return $js_images_list;
  163. }
  164. // FUNCTIONS - END
  165. ?>