images.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <?php
  2. # ***** BEGIN LICENSE BLOCK *****
  3. # This file is part of DotClear.
  4. # Copyright (c) 2004 Olivier Meunier and contributors. All rights
  5. # reserved.
  6. #
  7. # DotClear is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # DotClear is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with DotClear; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. #
  21. # ***** END LICENSE BLOCK *****
  22. require dirname(__FILE__).'/inc/prepend.php';
  23. require_once dirname(__FILE__).'/../inc/classes/class.imgmanager.php';
  24. require_once dirname(__FILE__).'/../inc/libs/lib.image.php';
  25. $auth->check(5);
  26. include dirname(__FILE__).'/inc/connexion.php';
  27. $page_title = __('Manage images');
  28. $img_p = dc_img_root;
  29. $img_p = path::real($img_p);
  30. $p = !empty($_REQUEST['p']) ? $_REQUEST['p'] : '';
  31. $mode = !isset($mode) ? '' : $mode;
  32. $pscript = ($mode == 'popup') ? 'images-popup.php' : 'images.php';
  33. $imgM = new imgmanager($img_p,$p,dc_img_url,$pscript);
  34. $err = '';
  35. # Upload d'image
  36. if (!$imgM->isExclude() && $imgM->isWritable() && !empty($_FILES['up_img']))
  37. {
  38. $tmp_file = $_FILES['up_img']['tmp_name'];
  39. $img_name = $_FILES['up_img']['name'];
  40. $up_dir = $imgM->root.'/'.$imgM->base_path;
  41. if (version_compare(phpversion(),'4.2.0','>=')) {
  42. $upd_error = $_FILES['up_img']['error'];
  43. } else {
  44. $upd_error = 0;
  45. }
  46. if($upd_error != 0)
  47. {
  48. switch ($upd_error) {
  49. case 1:
  50. case 2:
  51. $err .= '<li>'.__('File size exceeds the authorized limit').'</li>';
  52. break;
  53. case 3:
  54. $err .= '<li>'.__('File was only partially uploaded').'</li>';
  55. break;
  56. case 4:
  57. $err .= '<li>'.__('No file').'</li>';
  58. break;
  59. }
  60. }
  61. elseif(@move_uploaded_file($tmp_file,$up_dir.'/'.$img_name))
  62. {
  63. $dest_img = $up_dir.'/'.$img_name;
  64. if(filesize($dest_img) > dc_upload_size)
  65. {
  66. $err .= '<li>'.__('File size exceeds the authorized limit').'</li>';
  67. }
  68. else
  69. {
  70. if(($img_size = @getimagesize($dest_img)) === false)
  71. {
  72. $err .= '<li>'.sprintf(__('The file %s is not an image'),
  73. '<strong>'.$img_name.'</strong>').'</li>';
  74. }
  75. else
  76. {
  77. $max_s = explode('x',dc_max_img_size);
  78. $max_w = (int) $max_s[0];
  79. $max_h = isset($max_s[1]) ? (int) $max_s[1] : 0;
  80. if ($max_w > 0 && $img_size[0] > $max_w)
  81. {
  82. $err .= '<li>'.__('Image is too large').'</li>';
  83. }
  84. elseif ($max_h > 0 && $img_size[1] > $max_h)
  85. {
  86. $err .= '<li>'.__('Image is too large').'</li>';
  87. }
  88. }
  89. }
  90. if ($err != '')
  91. {
  92. unlink($dest_img);
  93. }
  94. else
  95. {
  96. chmod($up_dir.'/'.$img_name,fileperms($up_dir) & ~0111);
  97. # On fait le thumbnail
  98. if (($img_type = images::type($dest_img)) !== false)
  99. {
  100. $tn_file = preg_replace('/^(.*)([.]\\w+)$/','$1.TN__$2',$up_dir.'/'.$img_name);
  101. images::cropImg($dest_img,$tn_file,$img_type,140,140);
  102. }
  103. $msg = __('Image uploaded');
  104. header('Location: '.$pscript.'?p='.$p.'&msg='.rawurlencode($msg));
  105. exit();
  106. }
  107. }
  108. else
  109. {
  110. $err .= '<li>'.__('An error occured while uploading the image').'</li>';
  111. }
  112. }
  113. # Création d'une miniature
  114. if (!$imgM->isExclude() && $imgM->isImg() && isset($_GET['tn']))
  115. {
  116. $type = $imgM->getImgType();
  117. if ($type != 'png' && $type != 'jpeg')
  118. {
  119. $err .= '<li>'.__('Wrong image type').'</li>';
  120. }
  121. elseif (!$imgM->isParentWritable())
  122. {
  123. $err .= '<li>'.__('This folder is not writable.').'</li>';
  124. }
  125. else
  126. {
  127. $img_file = $imgM->root.'/'.$imgM->base_path;
  128. $tn_file = preg_replace('/^(.*)([.]\\w+)$/','$1.TN__$2',$img_file);
  129. if (images::cropImg($img_file,$tn_file,$type,140,140) !== false) {
  130. header('Location: '.$pscript.'?p='.dirname($p));
  131. exit;
  132. }
  133. }
  134. }
  135. # Suppression
  136. if (!$imgM->isExclude() && $imgM->isDeletable() && isset($_GET['del']))
  137. {
  138. if ($imgM->isImg()) {
  139. $img_tn = $imgM->getThumb(NULL,true);
  140. }
  141. if ($imgM->delete() === false) {
  142. $err .= '<li>'.__('Cannot delete.').'</li>';
  143. } else {
  144. if (!empty($img_tn)) {
  145. @unlink($img_tn);
  146. }
  147. header('Location: '.$pscript.'?p='.dirname($p));
  148. exit;
  149. }
  150. }
  151. # Création d'un répertoire
  152. if (!$imgM->isExclude() && $imgM->isWritable() && !empty($_POST['new_dir']))
  153. {
  154. if ($imgM->newDir($_POST['new_dir']) !== false) {
  155. header('Location: '.$pscript.'?p='.$p);
  156. exit;
  157. } else {
  158. $err = '<li>'.__('Cannot create this directory.').'</li>';
  159. }
  160. }
  161. # Affichage
  162. if ($mode == 'popup') {
  163. openPopup($page_title);
  164. echo '<script type="text/javascript" src="js/toolbar.js"></script>';
  165. echo
  166. '<script type="text/javascript">'.
  167. "if (document.getElementById) {
  168. var tbImg = new dcToolBar(window.opener.document.getElementById('p_content'),
  169. window.opener.document.getElementById('p_format'),'images/');
  170. }
  171. </script>";
  172. } else {
  173. # Sous menu
  174. $mySubMenu->addItem(
  175. __('Back to list of entries'),'index.php','images/ico_retour.png',false);
  176. openPage($page_title);
  177. }
  178. echo '<h2>'.$page_title.'</h2>';
  179. if ($err != '')
  180. {
  181. echo '<div class="erreur"><p><strong>'.__('Error(s)').' :</strong></p>'.
  182. '<ul>'.$err.'</ul></div>';
  183. }
  184. echo '<h3>'.__('Your images').'</h3>';
  185. echo '<p>'.$imgM->getNavBar().'</p>';
  186. # Affichage des image
  187. if (!$imgM->isExclude() && $imgM->isDir() && ($f_list = $imgM->getDir()) !== false)
  188. {
  189. $redir_link = ''.$pscript.'?p='.$imgM->base_path;
  190. foreach ($f_list['dirs'] as $k => $v)
  191. {
  192. $action = '';
  193. if ($v['del']) {
  194. $action .= '<a href="'.$redir_link.'/%2$s&amp;del=1" '.
  195. 'onclick="return window.confirm(\''.
  196. addslashes(sprintf(__('Are you sure you want to delete this %s?'),__('directory'))).'\');">'.
  197. '<img src="images/delete.png" alt="'.__('delete').'" '.
  198. 'title="'.__('delete').'"/></a>';
  199. }
  200. $action = '<p class="action">'.$action.'</p>';
  201. $dir_link =
  202. '<div class="imgBrowsedir">'.
  203. '<p class="thumbnail small">'.
  204. '<a href="%1$s">'.
  205. '<img src="images/directory.png" alt="" /></a>'.
  206. '<a href="%1$s">%2$s</a></p>'.
  207. $action.
  208. '</div>';
  209. echo $imgM->listDir($k,$v,$dir_link);
  210. }
  211. foreach ($f_list['files'] as $k => $v)
  212. {
  213. $action = '';
  214. if ($v['del']) {
  215. $action .= '<a href="'.$redir_link.'/%2$s&amp;del=1" '.
  216. 'onclick="return window.confirm(\''.
  217. addslashes(sprintf(__('Are you sure you want to delete this %s?'),__('file'))).'\');">'.
  218. '<img src="images/delete.png" alt="'.__('delete').'" '.
  219. 'title="'.__('delete').'"/></a>';
  220. }
  221. $action = '<p class="action">'.$action.'</p>';
  222. if ($mode != 'popup') {
  223. $img_href = '%1$s';
  224. } else {
  225. $img_href = '%1$s" '.
  226. 'onclick="tbImg.insImg(\'%4$s\'); '.
  227. 'window.close(); return false;';
  228. }
  229. $img_link =
  230. '<div class="imgBrowse">'.
  231. '<p class="thumbnail small">'.
  232. '<br /><a href="'.$img_href.'">%2$s</a>'.
  233. '<br /><br /> <a href="'.$pscript.'?p='.$imgM->base_path.'/%2$s&amp;tn=1">'.
  234. __('Try to create thumbnail').'</a></p>'.
  235. $action.
  236. '</div>';
  237. $img_link_tn =
  238. '<div class="imgBrowse">'.
  239. '<p class="thumbnail small">'.
  240. '<a href="'.$img_href.'"><img src="%3$s" alt="%2$s" /></a>'.
  241. '<a href="'.$img_href.'">%2$s</a></p>'.
  242. $action.
  243. '</div>';
  244. if (!preg_match('/TN__[.]\w+$/',$k))
  245. {
  246. # Thumbnail ?
  247. if (($tn_url = $imgM->getThumb($k)) !== false) {
  248. echo $imgM->listImg($k,$v,$img_link_tn);
  249. } else {
  250. echo $imgM->listImg($k,$v,$img_link);
  251. }
  252. }
  253. }
  254. }
  255. # Formulaire
  256. if ($imgM->isWritable())
  257. {
  258. echo
  259. '<form enctype="multipart/form-data" action="'.$pscript.'" method="post">'.
  260. '<fieldset class="clear"><legend>'.__('Upload an image').'</legend>'.
  261. '<p><label for="up_img">'.
  262. sprintf(__('Choose a file (max size %s)'),files::size(dc_upload_size)).'&nbsp;: </label>'.
  263. '<input name="up_img" id="up_img" type="file" />'.
  264. '<input type="hidden" name="MAX_FILE_SIZE" value="'.dc_upload_size.'" />'.
  265. '<input type="hidden" name="mode" value="'.$mode.'" />'.
  266. '<input type="hidden" name="p" value="'.$p.'" />'.
  267. '&nbsp;<input class="submit" type="submit" value="'.__('send').'" /></p>'.
  268. '</fieldset>'.
  269. '</form>';
  270. echo
  271. '<form action="'.$pscript.'" method="post">'.
  272. '<fieldset><legend>'.__('New directory').'</legend>'.
  273. '<p><label for="new_dir">'.__('Name').' : </label>'.
  274. form::field('new_dir',20,255,'').
  275. '<input type="hidden" name="mode" value="'.$mode.'" />'.
  276. '<input type="hidden" name="p" value="'.$p.'" />'.
  277. '&nbsp;<input class="submit" type="submit" value="'.__('save').'" /></p>'.
  278. '</fieldset>'.
  279. '</form>';
  280. }
  281. if ($mode == 'popup') {
  282. closePopup();
  283. } else {
  284. closePage();
  285. }
  286. ?>