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

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

update markitup to 1.1.14 (compatible jquery 1.9)
usable on contact form
improve display

File size: 3.2 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', $textarea_id='contentid')
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    'SMILIES_ID' => $textarea_id,
15    'REPRESENTANT' => SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/'.$conf_smiliessupport['representant'],
16    'smiliesfiles' => get_smilies($conf_smiliessupport),
17  ));
18 
19  $template->set_prefilter($prefilter, 'set_smiliessupport_prefilter'); 
20}
21
22function set_smiliessupport_prefilter($content, &$smarty)
23{
24  $search = '#(<div id="guestbookAdd">|<div id="commentAdd">|<div class="contact">)#';
25  $replace = file_get_contents(SMILIES_PATH.'/template/smiliessupport_page.tpl').'$1';
26  return preg_replace($search, $replace, $content);
27}
28
29// return an array with available smilies (name and path) ## must received the unserialized configuration array
30function get_smilies($conf_smiliessupport)
31{
32  $accepted_ext = array('gif', 'jpg', 'png');
33 
34  if ($handle = opendir(SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder']))
35  {
36    $i = 1;
37    while (false !== ($file = readdir($handle)))
38    {
39      if ($file != '.' AND $file != '..' AND in_array(get_extension($file), $accepted_ext))
40      {
41        $smilies[] = array(
42          'PATH' => SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/'.$file,
43          'TITLE' => ':'.get_filename_wo_extension($file).':',
44          'TR' => ($i>0 AND $i%$conf_smiliessupport['cols'] == 0) ? '</tr><tr>' : null,
45        );
46        $i++;
47      }
48    }
49   
50    closedir($handle);
51    return $smilies;
52  } 
53  else 
54  {
55    return false;
56  }
57}
58
59// parse smilies
60function SmiliesParse($str)
61{
62  global $conf;
63
64  $conf_smiliessupport = unserialize($conf['smiliessupport']);
65  $folder = get_absolute_root_url().SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'];
66  $def_path = SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/smilies.txt';
67  $accepted_ext = array('gif', 'jpg', 'png');
68  $str = ' '.$str;
69 
70  if ($handle = opendir(SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder']))
71  {
72    while (false !== ($file = readdir($handle)))
73    { 
74      if ($file != "." && $file != ".." && in_array(get_extension($file), $accepted_ext)) 
75      {
76        $filename = get_filename_wo_extension($file);
77        $v = ':'.$filename.':'; 
78        $s = '<img src="'.$folder.'/'.$file.'" alt=":'.$filename.':"/>';
79        $str = str_replace($v, $s, $str);
80      }
81    }
82   
83    closedir($handle);
84  }
85 
86  if (file_exists($def_path))
87  {
88    $def = file($def_path);
89    foreach($def as $v)
90    {
91      $v = trim($v);
92      if (preg_match('#^([^\t]+)[ \t]+(.+)$#', $v, $matches)) 
93      { 
94        $filename = get_filename_wo_extension($matches[2]);
95        $v = '#([^"])'.preg_quote($matches[1],'/').'#';         
96        $t = '$1<img src="'.$folder.'/'.$matches[2].'" alt=":'.$filename.':"/>';
97        $str = preg_replace($v, $t, $str);
98      }
99    }
100  } 
101 
102  return trim($str);
103}
104
105?>
Note: See TracBrowser for help on using the repository browser.