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

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

[extentions] Smilies Support

  • active for admin in the comments page
  • two new sets of smilies
  • help tip on admin page (needs translation)
File size: 2.9 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->set_filename('smiliessupport_page', dirname(__FILE__).'/smiliessupport_page.tpl');
36        $template->assign(array('REPRESENTANT' => PHPWG_ROOT_PATH.$conf_smiliessupport[0].'/'.$conf_smiliessupport[2]));
37
38        if ($handle = opendir(PHPWG_ROOT_PATH.$conf_smiliessupport[0]))
39        {
40                while (false !== ($file = readdir($handle)))
41                {
42                        $trvalue = '';
43
44                        if ($file != "." && $file != ".." && ( get_extension($file) == "gif" || get_extension($file) == "png"))
45                        {
46                                if (( $cnt > 0 ) && ( $cnt % $conf_smiliessupport[1] == 0 )) {
47                                        $trvalue = '</tr><tr>';
48                                }
49                                $cnt = $cnt + 1;
50                                $template->append('smiliesfiles',
51                                array('PATH' => PHPWG_ROOT_PATH.$conf_smiliessupport[0].'/'.$file,
52                                'TITLE' => ':'.get_filename_wo_extension($file).':',
53                                'TR'=>$trvalue));
54                        }
55                }
56               
57        } else {
58                array_push($page['errors'], l10n('opendir failed : '.PHPWG_ROOT_PATH.$conf_smiliessupport[0].')' ));
59        }
60       
61        return $template->parse('smiliessupport_page', true);
62}
63
64function SmiliesParse($str)
65{
66        global $conf;
67
68        $conf_smiliessupport = explode("," , $conf['smiliessupport']);
69        $def_path = $conf_smiliessupport[0].'/smilies.txt';
70        $accepted_ext = array('gif', 'jpg', 'png');
71       
72        if ($handle = opendir(PHPWG_ROOT_PATH.$conf_smiliessupport[0]))
73        {
74                while (false !== ($file = readdir($handle)))
75                { 
76                        if ($file != "." && $file != ".." && in_array(get_extension($file), $accepted_ext)) {
77                                $v = ':'.get_filename_wo_extension($file).':'; 
78                                $s = '<img src="'.$conf_smiliessupport[0].'/'.$file.'" alt=":'.get_filename_wo_extension($file).':" title=":'.get_filename_wo_extension($file).':"/>';
79                                $str = str_replace($v, $s, $str);
80                        }
81                }
82        }
83       
84        if (file_exists($def_path))
85        {
86                $def = file($def_path);
87                foreach($def as $v)
88                {
89                        $v = trim($v);
90                        if (preg_match('|^([^\t]*)[\t]+(.*)$|',$v,$matches)) { 
91                                $r = '#'.preg_quote($matches[1],'/').'#';                                       
92                                $t = '<img src="'.$conf_smiliessupport[0].'/'.$matches[2].'" alt=":'.get_filename_wo_extension($matches[2]).':" title=":'.get_filename_wo_extension($matches[2]).':"/>';
93                                $str = preg_replace($r, $t, $str);
94                        }
95                }
96        } 
97       
98        return $str;
99}
100
101?>
Note: See TracBrowser for help on using the repository browser.