1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | function get_first_file($path, $ext=null) |
---|
5 | { |
---|
6 | $path = rtrim($path, '/').'/'; |
---|
7 | $handle = opendir($path); |
---|
8 | |
---|
9 | while ( false !== ($file=readdir($handle)) ) |
---|
10 | { |
---|
11 | if ( $file!='.' && $file!='..' && is_file($path.$file) && (!is_array($ext) || in_array(get_extension($file), $ext)) ) |
---|
12 | { |
---|
13 | closedir($handle); |
---|
14 | return $file; |
---|
15 | } |
---|
16 | } |
---|
17 | |
---|
18 | closedir($handle); |
---|
19 | return null; |
---|
20 | } |
---|
21 | |
---|
22 | function smiliessupport_action() |
---|
23 | { |
---|
24 | if (!isset($_GET['action'])) return; |
---|
25 | if (strpos($_GET['action'], 'ss_') !== 0) return; |
---|
26 | |
---|
27 | global $conf; |
---|
28 | |
---|
29 | $folder = SMILIES_DIR . ltrim($_GET['folder'], '/') . '/'; |
---|
30 | |
---|
31 | if ($_GET['action'] == 'ss_reset') |
---|
32 | { |
---|
33 | @unlink($folder.'smilies-custom.txt'); |
---|
34 | $_GET['action'] = 'ss_list'; |
---|
35 | } |
---|
36 | |
---|
37 | if ($_GET['action'] == 'ss_list') |
---|
38 | { |
---|
39 | $short = array(); |
---|
40 | if (file_exists($folder.'smilies-custom.txt')) |
---|
41 | { |
---|
42 | $file = file($folder.'smilies-custom.txt', FILE_IGNORE_NEW_LINES); |
---|
43 | } |
---|
44 | else if (file_exists($folder.'smilies.txt')) |
---|
45 | { |
---|
46 | $file = file($folder.'smilies.txt', FILE_IGNORE_NEW_LINES); |
---|
47 | } |
---|
48 | if (!empty($file)) |
---|
49 | { |
---|
50 | foreach ($file as $v) |
---|
51 | { |
---|
52 | if (preg_match('#^([^\s]+)[\s]+(.+)$#', trim($v), $matches)) |
---|
53 | { |
---|
54 | $short[ $matches[2] ][] = $matches[1]; |
---|
55 | } |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | $smilies = array(); |
---|
60 | $handle = opendir($folder); |
---|
61 | while (false !== ($file = readdir($handle))) |
---|
62 | { |
---|
63 | if ( $file != '.' && $file != '..' && in_array(get_extension($file), $conf['smiliessupport']['ext']) ) |
---|
64 | { |
---|
65 | $smilies[$file] = array('title'=>':'.get_filename_wo_extension($file).':', 'file'=>$file, 'short'=>@$short[$file]); |
---|
66 | } |
---|
67 | } |
---|
68 | closedir($handle); |
---|
69 | |
---|
70 | echo json_encode(array('path'=>$folder, 'smilies'=>$smilies)); |
---|
71 | } |
---|
72 | |
---|
73 | exit; |
---|
74 | } |
---|
75 | |
---|
76 | ?> |
---|