PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/core/lhgallery/lhswfconverter.php

http://hppg.googlecode.com/
PHP | 178 lines | 119 code | 47 blank | 12 comment | 14 complexity | 01b824177416208546ac52d7543314a0 MD5 | raw file
Possible License(s): GPL-3.0, BSD-3-Clause
  1. <?php
  2. class erLhcoreClassSWFConverter {
  3. public $converter;
  4. private static $instance = null;
  5. function __construct()
  6. {
  7. }
  8. public static function isSWF($file)
  9. {
  10. if ($_FILES[$file]['error'] == 0)
  11. {
  12. try {
  13. list($width, $height, $type, $attr) = getimagesize($_FILES[$file]['tmp_name']);
  14. if ($width > 10 && $height > 10 && $_FILES[$file]['size'] < ((int)erLhcoreClassModelSystemConfig::fetch('max_photo_size')->current_value*1024))
  15. {
  16. return true;
  17. } else
  18. return false;
  19. } catch (Exception $e) {
  20. return false;
  21. }
  22. } else {
  23. return false;
  24. }
  25. }
  26. public static function handleUpload(& $image,$params = array())
  27. {
  28. $photoDir = $params['photo_dir'];
  29. $fileNamePhysic = $params['file_name_physic'];
  30. $config = erConfigClassLhConfig::getInstance();
  31. rename($params['file_upload_path'],$photoDir.'/'.$fileNamePhysic);
  32. chmod($photoDir.'/'.$fileNamePhysic,$config->getSetting( 'site', 'StorageFilePermissions' ));
  33. $image->filesize = filesize($photoDir.'/'.$fileNamePhysic);
  34. $image->total_filesize = $image->filesize;
  35. $image->filepath = $params['photo_dir_photo'];
  36. list($width, $height, $type, $attr) = getimagesize($photoDir.'/'.$fileNamePhysic);
  37. $image->media_type = erLhcoreClassModelGalleryImage::mediaTypeSWF;
  38. $image->pwidth = $width;
  39. $image->pheight = $height;
  40. $image->filename = $fileNamePhysic;
  41. erLhcoreClassModelGalleryPendingConvert::addImage($image->pid);
  42. }
  43. public static function handleUploadLocal(& $image,$params = array())
  44. {
  45. $photoDir = $params['photo_dir'];
  46. $fileNamePhysic = $params['file_name_physic'];
  47. $pathExtracted = $params['post_file_name'];
  48. $album = $params['album'];
  49. $config = erConfigClassLhConfig::getInstance();
  50. $wwwUser = erConfigClassLhConfig::getInstance()->getSetting( 'site', 'default_www_user' );
  51. $wwwUserGroup = erConfigClassLhConfig::getInstance()->getSetting( 'site', 'default_www_group' );
  52. rename($pathExtracted,$photoDir.'/'.$fileNamePhysic);
  53. chown($photoDir.'/'.$fileNamePhysic,$wwwUser);
  54. chgrp($photoDir.'/'.$fileNamePhysic,$wwwUserGroup);
  55. chmod($photoDir.'/'.$fileNamePhysic,$config->getSetting( 'site', 'StorageFilePermissions' ));
  56. $image->filesize = filesize($photoDir.'/'.$fileNamePhysic);
  57. $image->total_filesize = $image->filesize;
  58. $image->filepath = $params['photo_dir_photo'];
  59. list($width, $height, $type, $attr) = getimagesize($photoDir.'/'.$fileNamePhysic);
  60. $image->media_type = erLhcoreClassModelGalleryImage::mediaTypeSWF;
  61. $image->pwidth = $width;
  62. $image->pheight = $height;
  63. $image->hits = 0;
  64. erLhcoreClassModelGalleryPendingConvert::addImage($image->pid);
  65. }
  66. public static function handleUploadBatch(& $image,$params = array())
  67. {
  68. $photoDir = $params['photo_dir'];
  69. $fileNamePhysic = $params['file_name_physic'];
  70. $imagePath = $params['post_file_name'];
  71. $config = erConfigClassLhConfig::getInstance();
  72. $image->filesize = filesize($imagePath);
  73. $image->total_filesize = $image->filesize;
  74. list($width, $height, $type, $attr) = getimagesize($imagePath);
  75. $image->media_type = erLhcoreClassModelGalleryImage::mediaTypeSWF;
  76. $image->pwidth = $width;
  77. $image->pheight = $height;
  78. $image->hits = 0;
  79. erLhcoreClassModelGalleryPendingConvert::addImage($image->pid);
  80. }
  81. public static function isSWFLocal($filePath)
  82. {
  83. try {
  84. list($width, $height, $type, $attr) = getimagesize($filePath);
  85. if ($width > 10 && $height > 10 && filesize($filePath) < ((int)erLhcoreClassModelSystemConfig::fetch('max_photo_size')->current_value*1024))
  86. {
  87. return true;
  88. } else
  89. return false;
  90. } catch (Exception $e) {
  91. return false;
  92. }
  93. }
  94. // Borowed from coppermine gallery
  95. public static function sanitizeFileName($str)
  96. {
  97. static $forbidden_chars;
  98. if (!is_array($forbidden_chars)) {
  99. $mb_utf8_regex = '[\xE1-\xEF][\x80-\xBF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xC2-\xDF][\x80-\xBF]';
  100. if (function_exists('html_entity_decode')) {
  101. $chars = html_entity_decode('$/\\:*?&quot;&#39;&lt;&gt;|` &amp;', ENT_QUOTES, 'UTF-8');
  102. } else {
  103. $chars = str_replace(array('&amp;', '&quot;', '&lt;', '&gt;', '&nbsp;', '&#39;'), array('&', '"', '<', '>', ' ', "'"), $CONFIG['forbiden_fname_char']);
  104. }
  105. preg_match_all("#$mb_utf8_regex".'|[\x00-\x7F]#', $chars, $forbidden_chars);
  106. }
  107. /**
  108. * $str may also come from $_POST, in this case, all &, ", etc will get replaced with entities.
  109. * Replace them back to normal chars so that the str_replace below can work.
  110. */
  111. $str = str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'), $str);;
  112. $return = str_replace($forbidden_chars[0], '-', $str);
  113. $return = str_replace(array(')','('), array('',''), $return);
  114. $return = str_replace(' ', '-', $return);
  115. /**
  116. * Fix the obscure, misdocumented "feature" in Apache that causes the server
  117. * to process the last "valid" extension in the filename (rar exploit): replace all
  118. * dots in the filename except the last one with an underscore.
  119. */
  120. // This could be concatenated into a more efficient string later, keeping it in three
  121. // lines for better readability for now.
  122. $extension = strtolower(ltrim(substr($return,strrpos($return,'.')),'.'));
  123. $filenameWithoutExtension = str_replace('.' . $extension, '', $return);
  124. $return = str_replace('.', '-', $filenameWithoutExtension) .'.' . $extension;
  125. return $return;
  126. }
  127. public static function getExtension($fileName){
  128. return current(end(explode('.',$fileName)));
  129. }
  130. }
  131. ?>