source: extensions/SmiliesSupport/admin.php @ 20941

Last change on this file since 20941 was 15110, checked in by mistic100, 13 years ago

fix textarea size
better PHP code for config

File size: 3.9 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4global $conf, $template;
5load_language('plugin.lang', SMILIES_PATH);
6
7if (strpos($conf['smiliessupport'],',') !== false)
8{
9  include(SMILIES_PATH .'maintain.inc.php');
10  plugin_activate();
11}
12
13$conf_smiliessupport = unserialize($conf['smiliessupport']);
14
15// Enregistrement de la configuration
16if (isset($_POST['submit']))
17{
18  // the smilies.txt file is not saved if the directory is changed
19  if (isset($_POST['folder']) AND $_POST['folder'] != $conf_smiliessupport['folder']) 
20  {
21    $not_save_file = true;
22   
23    if (!file_exists(SMILIES_PATH.'smilies/'.$_POST['folder'].'/'.$_POST['representant']))
24    {
25      $handle = opendir(SMILIES_PATH.'smilies/'.$_POST['folder']);
26      $i = 0;
27      while (false !== ($file = readdir($handle)))
28      {
29        if ( $file != '.' AND $file != '..' AND in_array(get_extension($file), array('gif', 'jpg', 'png')) )
30        {
31          $_POST['representant'] = $file;
32          closedir($handle);
33          break;
34        }
35      }
36    }
37  }
38 
39  // new configuration
40  $conf_smiliessupport = array(
41    'folder' => isset($_POST['folder']) ? $_POST['folder'] : 'crystal',
42    'cols' => isset($_POST['cols']) ? $_POST['cols'] : '6',
43    'representant' => isset($_POST['representant']) ? $_POST['representant'] : 'smile.png',
44  );
45  if (empty($_POST['text'])) $_POST['text'] = '';
46   
47  conf_update_param('smiliessupport', serialize($conf_smiliessupport));
48  array_push($page['infos'], l10n('Information data registered in database'));
49 
50  // new definitions file
51  if (!isset($not_save_file)) 
52  {
53    $smilies_file = SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/smilies.txt';     
54
55    if (file_exists($smilies_file)) {
56      @copy($smilies_file, get_filename_wo_extension($smilies_file).'.bak');
57    }
58   
59    if (@!file_put_contents($smilies_file, stripslashes($_POST['text']))) { 
60      array_push($page['errors'], l10n('File/directory read error').' : '.$smilies_file);
61    }
62  }
63}
64
65// check if the representant exists
66if (!file_exists(SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/'.$conf_smiliessupport['representant'])) {
67  array_push($page['errors'], l10n('File/directory read error').' : smilies/'.$conf_smiliessupport['folder'].'/'.$conf_smiliessupport['representant']);
68}
69
70// get available sets
71$sets = array();
72$handle = opendir(SMILIES_PATH.'smilies/');
73while (false !== ($file = readdir($handle)))
74{ 
75  if ( $file != '.' && $file != '..' && is_dir(SMILIES_PATH.'smilies/'.$file) )
76  {
77    $sets[$file] = $file;
78  }
79}
80closedir($handle);
81
82// get available smilies
83$smilies_table = $smilies = array();
84$handle = opendir(SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder']);
85$i = 1;
86while (false !== ($file = readdir($handle)))
87{
88  if ( $file != '.' AND $file != '..' AND in_array(get_extension($file), array('gif', 'jpg', 'png')) )
89  {
90    $smilies[$file] = $file;
91    $smilies_table[] = array(
92      'PATH' => SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/'.$file,
93      'TITLE' => ':'.get_filename_wo_extension($file).':',
94      'TR' => ($i>0 AND $i%$conf_smiliessupport['cols'] == 0) ? '</tr><tr>' : null,
95    );
96    $i++;
97  }
98}
99closedir($handle);
100
101$template->assign(array(
102  'FOLDER' => $conf_smiliessupport['folder'],
103  'COLS' => $conf_smiliessupport['cols'],
104  'REPRESENTANT' => $conf_smiliessupport['representant'],
105  'sets' => $sets,
106  'smiliesfiles' => $smilies_table,
107  'smilies' => $smilies,
108));
109
110// get the content of definitions file
111$smilies_file = SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/smilies.txt';
112if (file_exists($smilies_file))
113{
114  $content_file = file_get_contents($smilies_file);
115  $template->assign(array('CONTENT_FILE' => $content_file));
116}
117 
118$template->assign('SMILIES_PATH', SMILIES_PATH);
119$template->set_filename('smiliessupport_conf', dirname(__FILE__).'/template/smiliessupport_admin.tpl');
120$template->assign_var_from_handle('ADMIN_CONTENT', 'smiliessupport_conf');
121
122?>
Note: See TracBrowser for help on using the repository browser.