source: extensions/SmiliesSupport/include/events.inc.php @ 26075

Last change on this file since 26075 was 26075, checked in by mistic100, 10 years ago

update for Piwigo 2.6 + many code and logical cleaning

File size: 4.1 KB
Line 
1<?php
2defined('SMILIES_ID') or die('Hacking attempt!');
3
4function smiliessupport_admin_menu($menu) 
5{
6  $menu[] = array(
7    'NAME' => 'Smilies Support',
8    'URL' => SMILIES_ADMIN,
9    );
10  return $menu;
11}
12
13function add_smiliessupport() 
14{
15  global $page, $pwg_loaded_plugins, $template, $conf;
16 
17  if (script_basename() == 'picture') 
18  {
19    $prefilter = 'picture';
20    $textarea_id = 'contentid';
21  }
22  else if (isset($page['section']))
23  {
24    if (
25      script_basename() == 'index' and isset($pwg_loaded_plugins['Comments_on_Albums'])
26      and $page['section'] == 'categories' and isset($page['category'])
27      )
28    {
29      $prefilter = 'comments_on_albums';
30      $textarea_id = 'contentid';
31    }
32    else if ($page['section'] == 'guestbook') 
33    {
34      $prefilter = 'guestbook';
35      $textarea_id = 'contentid';
36    }
37    else if ($page['section'] == 'contact') 
38    {
39      $prefilter = 'contactform';
40      $textarea_id = 'cf_content';
41    }
42  }
43 
44  if (!isset($prefilter))
45  {
46    return;
47  }
48
49  $template->assign(array(
50    'SMILIES_PATH' => SMILIES_PATH,
51    'SMILIES' => array(
52      'textarea_id' => $textarea_id,
53      'representant' => SMILIES_DIR . $conf['smiliessupport']['folder'] . '/' . $conf['smiliessupport']['representant'],
54      'files' => get_smilies(),
55      ),
56    ));
57   
58  $template->set_filename('smiliessupport', realpath(SMILIES_PATH . 'template/smiliessupport_page.tpl'));
59  $template->parse('smiliessupport');
60}
61
62// parse smilies
63function SmiliesParse($str)
64{
65  global $conf;
66 
67  $root_path = get_absolute_root_url();
68  $folder = SMILIES_DIR.$conf['smiliessupport']['folder'].'/';
69  $str = ' '.$str;
70 
71  if ($handle = opendir($folder))
72  {
73    while (false !== ($file = readdir($handle)))
74    { 
75      if ($file != "." && $file != ".." && in_array(get_extension($file), $conf['smiliessupport_ext'])) 
76      {
77        $filename = get_filename_wo_extension($file);
78        $v = ':'.$filename.':'; 
79        $s = '<img src="'.$root_path.$folder.$file.'" alt=":'.$filename.':"/>';
80        $str = str_replace($v, $s, $str);
81      }
82    }
83   
84    closedir($handle);
85  }
86 
87  if (file_exists($folder.'smilies-custom.txt'))
88  {
89    $file = file($folder.'smilies-custom.txt', FILE_IGNORE_NEW_LINES);
90  }
91  else if (file_exists($folder.'smilies.txt'))
92  {
93    $file = file($folder.'smilies.txt', FILE_IGNORE_NEW_LINES);
94  }
95  if (!empty($file))
96  {
97    foreach ($file as $v)
98    {
99      $v = trim($v);
100      if (preg_match('#^([^\s]+)[\s]+(.+)$#', $v, $matches)) 
101      { 
102        $filename = get_filename_wo_extension($matches[2]);
103        $v = '#([^"])'.preg_quote($matches[1],'/').'#';         
104        $t = '$1<img src="'.$root_path.$folder.$matches[2].'" alt=":'.$filename.':"/>';
105        $str = preg_replace($v, $t, $str);
106      }
107    }
108  } 
109 
110  return trim($str);
111}
112
113function smiliessupport_action()
114{
115  if (!isset($_GET['action'])) return;
116  if (strpos($_GET['action'], 'ss_') !== 0) return;
117 
118  global $conf;
119 
120  $folder = SMILIES_DIR . ltrim($_GET['folder'], '/') . '/';
121 
122  if ($_GET['action'] == 'ss_reset')
123  {
124    @unlink($folder.'smilies-custom.txt');
125    $_GET['action'] = 'ss_list';
126  }
127  else if ($_GET['action'] == 'ss_list')
128  {
129    $short = array();
130    if (file_exists($folder.'smilies-custom.txt'))
131    {
132      $file = file($folder.'smilies-custom.txt', FILE_IGNORE_NEW_LINES);
133    }
134    else if (file_exists($folder.'smilies.txt'))
135    {
136      $file = file($folder.'smilies.txt', FILE_IGNORE_NEW_LINES);
137    }
138    if (!empty($file))
139    {
140      foreach ($file as $v)
141      {
142        if (preg_match('#^([^\s]+)[\s]+(.+)$#', trim($v), $matches)) 
143        {
144          $short[ $matches[2] ][] = $matches[1];
145        }
146      }
147    }
148
149    $smilies = array();
150    $handle = opendir($folder);
151    while (false !== ($file = readdir($handle)))
152    {
153      if ( $file != '.' && $file != '..' && in_array(get_extension($file), $conf['smiliessupport_ext']) )
154      {
155        $smilies[$file] = array('title'=>':'.get_filename_wo_extension($file).':', 'file'=>$file, 'short'=>@$short[$file]);
156      }
157    }
158    closedir($handle);
159   
160    echo json_encode(array('path'=>$folder, 'smilies'=>$smilies));
161  }
162 
163  exit;
164}
Note: See TracBrowser for help on using the repository browser.