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

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

parsing bug fixed, works with theme 'Simple'

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