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

Last change on this file since 20208 was 20208, checked in by mistic100, 11 years ago

compatible with question_mark_in_urls = false

File size: 3.1 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4// add smilies button to the comment field
5function set_smiliessupport($prefilter='picture')
6{
7  global $conf, $template, $page;
8 
9  load_language('plugin.lang', SMILIES_PATH);
10  $conf_smiliessupport = unserialize($conf['smiliessupport']);
11
12  $template->assign(array(
13    'SMILIES_PATH' => SMILIES_PATH,
14    'REPRESENTANT' => SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/'.$conf_smiliessupport['representant'],
15    'smiliesfiles' => get_smilies($conf_smiliessupport),
16  ));
17 
18  $template->set_prefilter($prefilter, 'set_smiliessupport_prefilter'); 
19}
20
21function set_smiliessupport_prefilter($content, &$smarty)
22{
23  $search = '#(<div id="guestbookAdd">|<div id="commentAdd">)#';
24  $replace = file_get_contents(SMILIES_PATH.'/template/smiliessupport_page.tpl').'$1';
25  return preg_replace($search, $replace, $content);
26}
27
28// return an array with available smilies (name and path) ## must received the unserialized configuration array
29function get_smilies($conf_smiliessupport)
30{
31  $accepted_ext = array('gif', 'jpg', 'png');
32 
33  if ($handle = opendir(SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder']))
34  {
35    $i = 1;
36    while (false !== ($file = readdir($handle)))
37    {
38      if ($file != '.' AND $file != '..' AND in_array(get_extension($file), $accepted_ext))
39      {
40        $smilies[] = array(
41          'PATH' => SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/'.$file,
42          'TITLE' => ':'.get_filename_wo_extension($file).':',
43          'TR' => ($i>0 AND $i%$conf_smiliessupport['cols'] == 0) ? '</tr><tr>' : null,
44        );
45        $i++;
46      }
47    }
48   
49    closedir($handle);
50    return $smilies;
51  } 
52  else 
53  {
54    return false;
55  }
56}
57
58// parse smilies
59function SmiliesParse($str)
60{
61  global $conf;
62
63  $conf_smiliessupport = unserialize($conf['smiliessupport']);
64  $folder = get_root_url().SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'];
65  $def_path = SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/smilies.txt';
66  $accepted_ext = array('gif', 'jpg', 'png');
67  $str = ' '.$str;
68 
69  if ($handle = opendir(SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder']))
70  {
71    while (false !== ($file = readdir($handle)))
72    { 
73      if ($file != "." && $file != ".." && in_array(get_extension($file), $accepted_ext)) 
74      {
75        $filename = get_filename_wo_extension($file);
76        $v = ':'.$filename.':'; 
77        $s = '<img src="'.$folder.'/'.$file.'" alt=":'.$filename.':"/>';
78        $str = str_replace($v, $s, $str);
79      }
80    }
81   
82    closedir($handle);
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      { 
93        $filename = get_filename_wo_extension($matches[2]);
94        $v = '#([^"])'.preg_quote($matches[1],'/').'#';         
95        $t = '$1<img src="'.$folder.'/'.$matches[2].'" alt=":'.$filename.':"/>';
96        $str = preg_replace($v, $t, $str);
97      }
98    }
99  } 
100 
101  return trim($str);
102}
103
104?>
Note: See TracBrowser for help on using the repository browser.