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