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

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

code cleanup

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