cache_smilies_js.php
2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: cache_smilies_js.php 24968 2011-10-19 09:51:28Z zhengqingpeng $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
function build_cache_smilies_js() {
global $_G;
$fastsmiley = C::t('common_setting')->fetch('fastsmiley', true);
$return_type = 'var smilies_type = new Array();';
$return_array = 'var smilies_array = new Array();var smilies_fast = new Array();';
$spp = $_G['setting']['smcols'] * $_G['setting']['smrows'];
$fpre = '';
foreach(C::t('forum_imagetype')->fetch_all_by_type('smiley', 1) as $type) {
$return_data = array();
$return_datakey = '';
$i = 0;$j = 1;$pre = '';
$return_type .= 'smilies_type[\'_'.$type['typeid'].'\'] = [\''.str_replace('\'', '\\\'', $type['name']).'\', \''.str_replace('\'', '\\\'', $type['directory']).'\'];';
$return_datakey .= 'smilies_array['.$type['typeid'].'] = new Array();';
foreach(C::t('common_smiley')->fetch_all_by_type_code_typeid('smiley', $type['typeid']) as $smiley) {
if($i >= $spp) {
$return_data[$j] = 'smilies_array['.$type['typeid'].']['.$j.'] = ['.$return_data[$j].'];';
$j++;$i = 0;$pre = '';
}
if($size = @getimagesize(DISCUZ_ROOT.'./static/image/smiley/'.$type['directory'].'/'.$smiley['url'])) {
$smiley['code'] = str_replace('\'', '\\\'', $smiley['code']);
$smileyid = $smiley['id'];
$s = smthumb($size, $_G['setting']['smthumb']);
$smiley['w'] = $s['w'];
$smiley['h'] = $s['h'];
$l = smthumb($size);
$smiley['lw'] = $l['w'];
unset($smiley['id'], $smiley['directory']);
$return_data[$j] .= $pre.'[\''.$smileyid.'\', \''.$smiley['code'].'\',\''.str_replace('\'', '\\\'', $smiley['url']).'\',\''.$smiley['w'].'\',\''.$smiley['h'].'\',\''.$smiley['lw'].'\']';
if(is_array($fastsmiley[$type['typeid']]) && in_array($smileyid, $fastsmiley[$type['typeid']])) {
$return_fast .= $fpre.'[\''.$type['typeid'].'\',\''.$j.'\',\''.$i.'\']';
$fpre = ',';
}
$pre = ',';
}
$i++;
}
$return_data[$j] = 'smilies_array['.$type['typeid'].']['.$j.'] = ['.$return_data[$j].'];';
$return_array .= $return_datakey.implode('', $return_data);
}
$cachedir = DISCUZ_ROOT.'./data/cache/';
if(@$fp = fopen($cachedir.'common_smilies_var.js', 'w')) {
fwrite($fp, 'var smthumb = \''.$_G['setting']['smthumb'].'\';'.$return_type.$return_array.'var smilies_fast=['.$return_fast.'];');
fclose($fp);
} else {
exit('Can not write to cache files, please check directory ./data/ and ./data/cache/ .');
}
}
?>