source: extensions/SmiliesSupport/admin.php @ 23234

Last change on this file since 23234 was 23234, checked in by mistic100, 11 years ago

rewrite admin page
new set from Pidgin

File size: 2.6 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4include_once(SMILIES_PATH.'include/functions.inc.php');
5
6global $conf, $template;
7
8// get available sets
9$sets = array();
10$handle = opendir(SMILIES_DIR);
11while (false !== ($folder = readdir($handle)))
12{ 
13  if ( $folder != '.' && $folder != '..' && is_dir(SMILIES_DIR.$folder) )
14  {
15    if (file_exists(SMILIES_DIR.$folder.'/representant.txt'))
16    {
17      $sets[$folder] = file_get_contents(SMILIES_DIR.$folder.'/representant.txt');
18    }
19    else
20    {
21      $sets[$folder] = get_first_file(SMILIES_DIR.$folder, $conf['smiliessupport']['ext']);
22    }
23  }
24}
25closedir($handle);
26
27
28// save configuration
29if (isset($_POST['submit']))
30{
31  // new configuration
32  $conf['smiliessupport'] = array(
33    'folder' =>       $_POST['folder'],
34    'cols' =>         preg_match('#^([0-9]+)$#', $_POST['cols']) ? $_POST['cols'] : 6,
35    'representant' => $sets[ $_POST['folder'] ],
36  );
37 
38  conf_update_param('smiliessupport', serialize($conf['smiliessupport']));
39  array_push($page['infos'], l10n('Information data registered in database'));
40 
41  // shortcuts file
42  $used = array();
43  $content = null;
44 
45  foreach ($_POST['shortcuts'] as $file => $data)
46  {
47    if (empty($data)) continue;
48   
49    $data = explode(',', stripslashes($data));
50    foreach ($data as $short)
51    {
52      if (array_key_exists($short, $used))
53      {
54        $page['errors'][] = sprintf(
55                              l10n('<i>%s</i>, shortcut &laquo; %s &raquo; already used for <i>%s</i>'),
56                              get_filename_wo_extension($file),
57                              $short,
58                              get_filename_wo_extension($used[ $short ])
59                              );
60      }
61      else
62      {
63        $used[ $short ] = $file;
64        $content.= $short."\t\t".$file."\n";
65      }
66    }
67  }
68
69  if (file_exists(SMILIES_DIR.$_POST['folder'].'/smilies.txt'))
70  {
71    @copy(SMILIES_DIR.$_POST['folder'].'/smilies.txt', SMILIES_DIR.$_POST['folder'].'/smilies.bak');
72  }
73 
74  if (@!file_put_contents(SMILIES_DIR.$_POST['folder'].'/smilies.txt', $content))
75  { 
76    $page['errors'][] = l10n('File/directory read error').' : '.SMILIES_DIR.$_POST['folder'].'/smilies.txt';
77  }
78}
79
80
81// template
82$template->assign(array(
83  'FOLDER' =>       $conf['smiliessupport']['folder'],
84  'COLS' =>         $conf['smiliessupport']['cols'],
85  'SETS' =>         $sets,
86  'SMILIES_PATH' => SMILIES_PATH,
87));
88
89
90$template->set_filename('smiliessupport_conf', dirname(__FILE__).'/template/smiliessupport_admin.tpl');
91$template->assign_var_from_handle('ADMIN_CONTENT', 'smiliessupport_conf');
92
93?>
Note: See TracBrowser for help on using the repository browser.