source: extensions/SmiliesSupport/smiliessupport.inc.php @ 9789

Last change on this file since 9789 was 9789, checked in by mistic100, 13 years ago

[extentions] Smilies Support

File size: 3.0 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4function set_smiliessupport_page()
5{
6        global $template, $lang, $pwg_loaded_plugins;
7
8        if (!isset($pwg_loaded_plugins['bbcode_bar'])) {
9                $lang['Comment'] .= SmiliesTable();
10        }
11}
12
13function SmiliesTable($new_conf=null)
14{
15        global $conf, $template, $page;
16
17        // this is for live update on admin page
18        if (empty($new_conf)) {
19                $conf_smiliessupport = explode("," , $conf['smiliessupport']);
20        } else {
21                $conf_smiliessupport = $new_conf;
22        }
23
24        // edit field has a different id
25        if (
26                (isset($_GET['action']) AND $_GET['action'] == 'edit_comment') 
27                OR (isset($page['body_id']) AND $page['body_id'] == 'theCommentsPage')
28        ) {
29                $template->assign('form_name', 'editComment');
30        } else {
31                $template->assign('form_name', 'addComment');
32        }
33
34        $cnt = 1;
35        $template->assign('SMILIES_PATH', SMILIES_PATH);
36        $template->set_filename('smiliessupport_page', dirname(__FILE__).'/template/smiliessupport_page.tpl');
37        $template->assign(array('REPRESENTANT' => PHPWG_ROOT_PATH.$conf_smiliessupport[0].'/'.$conf_smiliessupport[2]));
38
39        if ($handle = opendir(PHPWG_ROOT_PATH.$conf_smiliessupport[0]))
40        {
41                while (false !== ($file = readdir($handle)))
42                {
43                        $trvalue = '';
44
45                        if ($file != "." && $file != ".." && ( get_extension($file) == "gif" || get_extension($file) == "png"))
46                        {
47                                if (( $cnt > 0 ) && ( $cnt % $conf_smiliessupport[1] == 0 )) {
48                                        $trvalue = '</tr><tr>';
49                                }
50                                $cnt = $cnt + 1;
51                                $template->append('smiliesfiles',
52                                array('PATH' => PHPWG_ROOT_PATH.$conf_smiliessupport[0].'/'.$file,
53                                'TITLE' => ':'.get_filename_wo_extension($file).':',
54                                'TR'=>$trvalue));
55                        }
56                }
57               
58        } else {
59                array_push($page['errors'], l10n('opendir failed : '.PHPWG_ROOT_PATH.$conf_smiliessupport[0].')' ));
60        }
61       
62        return $template->parse('smiliessupport_page', true);
63}
64
65function SmiliesParse($str)
66{
67        global $conf;
68
69        $conf_smiliessupport = explode("," , $conf['smiliessupport']);
70        $def_path = $conf_smiliessupport[0].'/smilies.txt';
71        $accepted_ext = array('gif', 'jpg', 'png');
72       
73        if ($handle = opendir(PHPWG_ROOT_PATH.$conf_smiliessupport[0]))
74        {
75                while (false !== ($file = readdir($handle)))
76                { 
77                        if ($file != "." && $file != ".." && in_array(get_extension($file), $accepted_ext)) {
78                                $v = ':'.get_filename_wo_extension($file).':'; 
79                                $s = '<img src="'.$conf_smiliessupport[0].'/'.$file.'" alt=":'.get_filename_wo_extension($file).':" title=":'.get_filename_wo_extension($file).':"/>';
80                                $str = str_replace($v, $s, $str);
81                        }
82                }
83        }
84       
85        if (file_exists($def_path))
86        {
87                $def = file($def_path);
88                foreach($def as $v)
89                {
90                        $v = trim($v);
91                        if (preg_match('|^([^\t]*)[\t]+(.*)$|',$v,$matches)) { 
92                                $r = '#'.preg_quote($matches[1],'/').'#';                                       
93                                $t = '<img src="'.$conf_smiliessupport[0].'/'.$matches[2].'" alt=":'.get_filename_wo_extension($matches[2]).':" title=":'.get_filename_wo_extension($matches[2]).':"/>';
94                                $str = preg_replace($r, $t, $str);
95                        }
96                }
97        } 
98       
99        return $str;
100}
101
102?>
Note: See TracBrowser for help on using the repository browser.