source: extensions/SmiliesSupport/admin.php @ 14919

Revision 14526, 3.8 KB checked in by mistic100, 8 years ago (diff)

update for 2.4

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['text1']) AND $_POST['text1'] != $conf_smiliessupport['folder']) 
20  {
21    $not_save_file = true;
22   
23    $handle = opendir(SMILIES_PATH.'smilies/'.$_POST['text1']);
24    $i = 0;
25    while (false !== ($file = readdir($handle)))
26    {
27      if ( $file != '.' AND $file != '..' AND in_array(get_extension($file), array('gif', 'jpg', 'png')) )
28      {
29        $_POST['text3'] = $file;
30        closedir($handle);
31        break;
32      }
33    }
34  }
35 
36  // new configuration
37  $conf_smiliessupport = array(
38    'folder' => isset($_POST['text1']) ? $_POST['text1'] : 'crystal',
39    'cols' => isset($_POST['text2']) ? $_POST['text2'] : '6',
40    'representant' => isset($_POST['text3']) ? $_POST['text3'] : 'smile.png',
41  );
42  if (empty($_POST['text'])) $_POST['text'] = ':)    smile.png';
43   
44  conf_update_param('smiliessupport', serialize($conf_smiliessupport));
45  array_push($page['infos'], l10n('Information data registered in database'));
46 
47  // new definitions file
48  if (!isset($not_save_file)) 
49  {
50    $smilies_file = SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/smilies.txt';     
51
52    if (file_exists($smilies_file)) {
53      @copy($smilies_file, get_filename_wo_extension($smilies_file).'.bak');
54    }
55   
56    if (@!file_put_contents($smilies_file, stripslashes($_POST['text']))) { 
57      array_push($page['errors'], l10n('File/directory read error').' : '.$smilies_file);
58    }
59  }
60}
61
62// check if the representant exists
63if (!file_exists(SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/'.$conf_smiliessupport['representant'])) {
64  array_push($page['errors'], l10n('File/directory read error').' : smilies/'.$conf_smiliessupport['folder'].'/'.$conf_smiliessupport['representant']);
65}
66
67// get available sets
68$sets = array();
69$handle = opendir(SMILIES_PATH.'smilies/');
70while (false !== ($file = readdir($handle)))
71{ 
72  if ( $file != '.' && $file != '..' && is_dir(SMILIES_PATH.'smilies/'.$file) )
73  {
74    $sets[$file] = $file;
75  }
76}
77closedir($handle);
78
79// get available smilies
80$smilies_table = $smilies = array();
81$handle = opendir(SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder']);
82$i = 1;
83while (false !== ($file = readdir($handle)))
84{
85  if ( $file != '.' AND $file != '..' AND in_array(get_extension($file), array('gif', 'jpg', 'png')) )
86  {
87    $smilies[$file] = $file;
88    $smilies_table[] = array(
89      'PATH' => SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/'.$file,
90      'TITLE' => ':'.get_filename_wo_extension($file).':',
91      'TR' => ($i>0 AND $i%$conf_smiliessupport['cols'] == 0) ? '</tr><tr>' : null,
92    );
93    $i++;
94  }
95}
96closedir($handle);
97
98$template->assign(array(
99  'TEXT1_VALUE' => $conf_smiliessupport['folder'],
100  'TEXT2_VALUE' => $conf_smiliessupport['cols'],
101  'TEXT3_VALUE' => $conf_smiliessupport['representant'],
102  'sets' => $sets,
103  'smiliesfiles' => $smilies_table,
104  'smilies' => $smilies,
105));
106
107// get the content of definitions file
108$smilies_file = SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/smilies.txt';
109if (file_exists($smilies_file)) {
110  $content_file = file_get_contents($smilies_file);
111  $template->assign(array('CONTENT_FILE' => $content_file));
112}
113 
114$template->assign('SMILIES_PATH', SMILIES_PATH);
115$template->set_filename('smiliessupport_conf', dirname(__FILE__).'/template/smiliessupport_admin.tpl');
116$template->assign_var_from_handle('ADMIN_CONTENT', 'smiliessupport_conf');
117
118?>
Note: See TracBrowser for help on using the repository browser.