source: extensions/SmiliesSupport/admin.php @ 28566

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

update for Piwigo 2.6 + many code and logical cleaning

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