cache_postimg.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: cache_postimg.php 31464 2012-08-30 08:59:27Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function build_cache_postimg() {
  12. $imgextarray = array('jpg', 'gif', 'png');
  13. $imgdir = array('hrline', 'postbg');
  14. $postimgjs = 'var postimg_type = new Array();';
  15. foreach($imgdir as $perdir) {
  16. $count = 0;
  17. $pdir = DISCUZ_ROOT.'./static/image/'.$perdir;
  18. $postimgdir = dir($pdir);
  19. $postimgjs .= 'postimg_type["'.$perdir.'"]=[';
  20. while($entry = $postimgdir->read()) {
  21. if(in_array(strtolower(fileext($entry)), $imgextarray) && preg_match("/^[\w\-\.\[\]\(\)\<\> &]+$/", substr($entry, 0, strrpos($entry, '.'))) && strlen($entry) < 30 && is_file($pdir.'/'.$entry)) {
  22. $postimg[$perdir][] = array('url' => $entry);
  23. $postimgjs .= ($count ? ',' : '').'"'.$entry.'"';
  24. $count++;
  25. }
  26. }
  27. $postimgjs .='];';
  28. $postimgdir->close();
  29. }
  30. savecache('postimg', $postimg);
  31. $cachedir = DISCUZ_ROOT.'./data/cache/';
  32. if(@$fp = fopen($cachedir.'common_postimg.js', 'w')) {
  33. fwrite($fp, $postimgjs);
  34. fclose($fp);
  35. } else {
  36. exit('Can not write to cache files, please check directory ./data/ and ./data/cache/ .');
  37. }
  38. }
  39. ?>