source: extensions/SmiliesSupport/admin.php @ 22333

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

fix textarea size
better PHP code for config

File size: 3.9 KB
RevLine 
[9683]1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4global $conf, $template;
5load_language('plugin.lang', SMILIES_PATH);
6
[14526]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
[9683]15// Enregistrement de la configuration
16if (isset($_POST['submit']))
17{
[10986]18  // the smilies.txt file is not saved if the directory is changed
[15110]19  if (isset($_POST['folder']) AND $_POST['folder'] != $conf_smiliessupport['folder']) 
[10986]20  {
21    $not_save_file = true;
[14526]22   
[15110]23    if (!file_exists(SMILIES_PATH.'smilies/'.$_POST['folder'].'/'.$_POST['representant']))
[14526]24    {
[15110]25      $handle = opendir(SMILIES_PATH.'smilies/'.$_POST['folder']);
26      $i = 0;
27      while (false !== ($file = readdir($handle)))
[14526]28      {
[15110]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        }
[14526]35      }
36    }
[10986]37  }
38 
39  // new configuration
40  $conf_smiliessupport = array(
[15110]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',
[10986]44  );
[15110]45  if (empty($_POST['text'])) $_POST['text'] = '';
[10986]46   
[14526]47  conf_update_param('smiliessupport', serialize($conf_smiliessupport));
[10986]48  array_push($page['infos'], l10n('Information data registered in database'));
49 
50  // new definitions file
51  if (!isset($not_save_file)) 
52  {
[14526]53    $smilies_file = SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/smilies.txt';     
[9683]54
[10986]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  }
[9683]63}
64
[9966]65// check if the representant exists
[14526]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']);
[9966]68}
69
[14526]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
[9789]101$template->assign(array(
[15110]102  'FOLDER' => $conf_smiliessupport['folder'],
103  'COLS' => $conf_smiliessupport['cols'],
104  'REPRESENTANT' => $conf_smiliessupport['representant'],
[14526]105  'sets' => $sets,
106  'smiliesfiles' => $smilies_table,
107  'smilies' => $smilies,
[9789]108));
[9683]109
[9966]110// get the content of definitions file
[14526]111$smilies_file = SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/smilies.txt';
[15110]112if (file_exists($smilies_file))
113{
[10986]114  $content_file = file_get_contents($smilies_file);
115  $template->assign(array('CONTENT_FILE' => $content_file));
[9683]116}
[10986]117 
[9789]118$template->assign('SMILIES_PATH', SMILIES_PATH);
119$template->set_filename('smiliessupport_conf', dirname(__FILE__).'/template/smiliessupport_admin.tpl');
[9683]120$template->assign_var_from_handle('ADMIN_CONTENT', 'smiliessupport_conf');
121
122?>
Note: See TracBrowser for help on using the repository browser.