Changeset 23234 for extensions/SmiliesSupport/admin.php
- Timestamp:
- Jun 15, 2013, 6:52:37 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/SmiliesSupport/admin.php
r15110 r23234 2 2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 3 3 4 include_once(SMILIES_PATH.'include/functions.inc.php'); 5 4 6 global $conf, $template; 5 load_language('plugin.lang', SMILIES_PATH);6 7 if (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 configuration16 if (isset($_POST['submit']))17 {18 // the smilies.txt file is not saved if the directory is changed19 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 configuration40 $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 file51 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 exists66 if (!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 7 70 8 // get available sets 71 9 $sets = array(); 72 $handle = opendir(SMILIES_ PATH.'smilies/');73 while (false !== ($f ile= readdir($handle)))10 $handle = opendir(SMILIES_DIR); 11 while (false !== ($folder = readdir($handle))) 74 12 { 75 if ( $f ile != '.' && $file != '..' && is_dir(SMILIES_PATH.'smilies/'.$file) )13 if ( $folder != '.' && $folder != '..' && is_dir(SMILIES_DIR.$folder) ) 76 14 { 77 $sets[$file] = $file; 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 } 78 23 } 79 24 } 80 25 closedir($handle); 81 26 82 // get available smilies 83 $smilies_table = $smilies = array(); 84 $handle = opendir(SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder']); 85 $i = 1; 86 while (false !== ($file = readdir($handle))) 27 28 // save configuration 29 if (isset($_POST['submit'])) 87 30 { 88 if ( $file != '.' AND $file != '..' AND in_array(get_extension($file), array('gif', 'jpg', 'png')) ) 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) 89 46 { 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++; 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 « %s » 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'; 97 77 } 98 78 } 99 closedir($handle);100 79 80 81 // template 101 82 $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, 83 'FOLDER' => $conf['smiliessupport']['folder'], 84 'COLS' => $conf['smiliessupport']['cols'], 85 'SETS' => $sets, 86 'SMILIES_PATH' => SMILIES_PATH, 108 87 )); 109 88 110 // get the content of definitions file 111 $smilies_file = SMILIES_PATH.'smilies/'.$conf_smiliessupport['folder'].'/smilies.txt'; 112 if (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); 89 119 90 $template->set_filename('smiliessupport_conf', dirname(__FILE__).'/template/smiliessupport_admin.tpl'); 120 91 $template->assign_var_from_handle('ADMIN_CONTENT', 'smiliessupport_conf');
Note: See TracChangeset
for help on using the changeset viewer.