fetch($id); if(!$smileyarray) { cpheader(); cpmsg('smilies_type_nonexistence', '', 'error'); } $smileyarray['smilies'] = array(); foreach(C::t('common_smiley')->fetch_all_by_typeid_type($id, 'smiley') as $smiley) { $smileyarray['smilies'][] = $smiley; } $smileyarray['version'] = strip_tags($_G['setting']['version']); exportdata('Discuz! Smilies', $smileyarray['name'], $smileyarray); } cpheader(); if(!$operation) { if(!submitcheck('smiliessubmit')) { shownav('style', 'smilies_edit'); showsubmenu('nav_smilies', array( array('smilies_type', 'smilies', 1), array('smilies_import', 'smilies&operation=import', 0), )); /*search={"nav_smilies":"action=smilies","smilies_type":"action=smilies"}*/ showtips('smilies_tips_smileytypes'); /*search*/ showformheader('smilies'); showtableheader(); showsubtitle(array('', 'display_order', 'enable', 'smilies_type', 'dir', 'smilies_nums', '')); $smtypes = 0; $dirfilter = array(); foreach(C::t('forum_imagetype')->fetch_all_by_type('smiley') as $type) { $smiliesnum = C::t('common_smiley')->count_by_type_typeid('smiley', $type['typeid']); showtablerow('', array('class="td25"', 'class="td28"'), array( "", "", "", "", "./static/image/smiley/$type[directory]", "$smiliesnum", "$lang[smilies_update] ". "$lang[export] ". "$lang[detail]" )); $dirfilter[] = $type['directory']; $smtypes++; } $smdir = DISCUZ_ROOT.'./static/image/smiley'; $smtypedir = dir($smdir); $dirnum = 0; while($entry = $smtypedir->read()) { if($entry != '.' && $entry != '..' && !in_array($entry, $dirfilter) && preg_match("/^\w+$/", $entry) && strlen($entry) < 30 && is_dir($smdir.'/'.$entry)){ $smiliesdir = dir($smdir.'/'.$entry); $smnums = 0; $smilies = ''; while($subentry = $smiliesdir->read()) { if(in_array(strtolower(fileext($subentry)), $imgextarray) && preg_match("/^[\w\-\.\[\]\(\)\<\> &]+$/", substr($subentry, 0, strrpos($subentry, '.'))) && strlen($subentry) < 30 && is_file($smdir.'/'.$entry.'/'.$subentry)) { $smilies .= ''; $smnums++; } } showtablerow('', array('class="td25"', 'class="td28"'), array( ($lang['add_new']), '', '', '', './static/image/smiley/'.$entry.'', "$smnums", $smilies, '', '' )); $dirnum++; } } if(!$dirnum) { showtablerow('', array('', 'colspan="8"'), array( cplang('add_new'), cplang('smiliesupload_tips') )); } showsubmit('smiliessubmit', 'submit', 'del'); showtablefooter(); showformfooter(); } else { if(is_array($_GET['namenew'])) { foreach($_GET['namenew'] as $id => $val) { $_GET['availablenew'][$id] = $_GET['availablenew'][$id] && $_GET['smiliesnum'][$id] > 0 ? 1 : 0; C::t('forum_imagetype')->update($id, array( 'available' => $_GET['availablenew'][$id], 'name' => dhtmlspecialchars(trim($val)), 'displayorder' => $_GET['displayordernew'][$id] )); } } if($_GET['delete']) { if(C::t('common_smiley')->count_by_type_typeid('smiley', $_GET['delete'])) { cpmsg('smilies_delete_invalid', '', 'error'); } C::t('forum_imagetype')->delete($_GET['delete']); } if(is_array($_GET['newname'])) { foreach($_GET['newname'] as $key => $val) { $val = trim($val); if($val) { $smurl = './static/image/smiley/'.$_GET['newdirectory'][$key]; $smdir = DISCUZ_ROOT.$smurl; if(!is_dir($smdir)) { cpmsg('smilies_directory_invalid', '', 'error', array('smurl' => $smurl)); } $newavailable[$key] = $_GET['newavailable'][$key] && $smnums[$key] > 0 ? 1 : 0; $data = array( 'available' => $_GET['newavailable'][$key], 'name' => dhtmlspecialchars($val), 'type' => 'smiley', 'displayorder' => $_GET['newdisplayorder'][$key], 'directory' => $_GET['newdirectory'][$key], ); $newSmileId = C::t('forum_imagetype')->insert($data, true); $smilies = update_smiles($smdir, $newSmileId, $imgextarray); if($smilies['smilies']) { addsmilies($newSmileId, $smilies['smilies']); updatecache(array('smilies', 'smileycodes', 'smilies_js')); } } } } updatecache(array('smileytypes', 'smilies', 'smileycodes', 'smilies_js')); cpmsg('smilies_edit_succeed', 'action=smilies', 'succeed'); } } elseif($operation == 'edit' && $id) { $type = C::t('forum_imagetype')->fetch($id); $smurl = './static/image/smiley/'.$type['directory']; $smdir = DISCUZ_ROOT.$smurl; if(!is_dir($smdir)) { cpmsg('smilies_directory_invalid', '', 'error', array('smurl' => $smurl)); } $fastsmiley = C::t('common_setting')->fetch('fastsmiley', true); if(!$do) { if(!submitcheck('editsubmit')) { $smiliesperpage = 100; $start_limit = ($page - 1) * $smiliesperpage; $num = C::t('common_smiley')->count_by_type_typeid('smiley', $id); $multipage = multi($num, $smiliesperpage, $page, ADMINSCRIPT.'?action=smilies&operation=edit&id='.$id); $smileynum = 1; $smilies = ''; foreach(C::t('common_smiley')->fetch_all_by_typeid_type($id, 'smiley', $start_limit, $smiliesperpage) as $smiley) { $smilies .= showtablerow('', array('class="td25"', 'class="td28 td24"', 'class="td25"', 'class="td23"', 'class="td23"', 'class="td24"'), array( "", "", "", "30) {this.resized=true; this.height=30;}\" onmouseover=\"if(this.resized) this.style.cursor='pointer';\" onclick=\"if(!this.resized) {return false;} else {window.open(this.src);}\">", $smiley['id'], "", "$smiley[url]" ), TRUE); $imgfilter[] = $smiley[url]; $smileynum ++; } echo << function addsmileycodes(smiliesnum, pre) { smiliesnum = parseInt(smiliesnum); if(smiliesnum > 1) { for(var i = 1; i < smiliesnum; i++) { var prefix = trim($(pre + 'prefix').value); var suffix = trim($(pre + 'suffix').value); var page = parseInt('$page'); var middle = $(pre + 'middle').value == 1 ? $(pre + 'url_' + i).value.substr(0,$(pre + 'url_' + i).value.lastIndexOf('.')) : ($(pre + 'middle').value == 2 ? i + page * 10 : $(pre + 'code_'+ i).attributes['smileyid'].nodeValue); if(!prefix || prefix == '$lang[smilies_prefix]' || !suffix || suffix == '$lang[smilies_suffix]') { alert('$lang[smilies_prefix_tips]'); return; } suffix = !suffix || suffix == '$lang[smilies_suffix]' ? '' : suffix; $(pre + 'code_' + i).value = prefix + middle + suffix; } } } function autoaddsmileycodes(smiliesnum) { smiliesnum = parseInt(smiliesnum); if(smiliesnum > 1) { for(var i = 1; i < smiliesnum; i++) { $('code_' + i).value = '{:' + '$id' + '_' + $('code_'+ i).attributes['smileyid'].nodeValue + ':}'; } } } function clearinput(obj, defaultval) { if(obj.value == defaultval) { obj.value = ''; } } EOT; shownav('style', 'nav_smilies'); showsubmenu(cplang('smilies_edit').' - '.$type['name'], array( array('smilies_type', 'smilies', 0), array('admin', "smilies&operation=edit&id=$id", !$do), array('add', "smilies&operation=edit&do=add&id=$id", $do == 'add') )); showformheader("smilies&operation=edit&id=$id"); showhiddenfields(array('page' => $_GET['page'])); showtableheader('', 'nobottom'); showsubtitle(array('', 'display_order', 'smilies_fast', 'smilies_edit_image', 'smilies_id', 'smilies_edit_code', 'smilies_edit_filename')); echo $smilies; showtablerow('', array('', 'colspan="5"'), array( '', $lang['smilies_edit_add_code'].' + +    ' )); showsubmit('editsubmit', 'submit', 'del', '', $multipage); showtablefooter(); showformfooter(); } else { if($_GET['delete']) { C::t('common_smiley')->delete($_GET['delete']); } $unsfast = array(); if(is_array($_GET['displayorder'])) { foreach($_GET['displayorder'] as $key => $val) { if(!in_array($key, $_GET['fast'])) { $unsfast[] = $key; } $_GET['displayorder'][$key] = intval($_GET['displayorder'][$key]); $_GET['code'][$key] = trim($_GET['code'][$key]); $data = array('displayorder' => $_GET['displayorder'][$key]); if(!empty($_GET['code'][$key])) { $data['code'] = $_GET['code'][$key]; } C::t('common_smiley')->update($key, $data); } } $fastsmiley[$id] = array_diff(array_unique(array_merge((array)$fastsmiley[$id], (array)$_GET['fast'])), $unsfast); C::t('common_setting')->update('fastsmiley', $fastsmiley); updatecache(array('smilies', 'smileycodes', 'smilies_js')); cpmsg('smilies_edit_succeed', "action=smilies&operation=edit&id=$id&page=$_GET[page]", 'succeed'); } } elseif($do == 'add') { if(!submitcheck('editsubmit')) { shownav('style', 'nav_smilies'); showsubmenu(cplang('smilies_edit').' - '.$type[name], array( array('smilies_type', 'smilies', 0), array('admin', "smilies&operation=edit&id=$id", !$do), array('add', "smilies&operation=edit&do=add&id=$id", $do == 'add') )); showtips('smilies_tips'); showtagheader('div', 'addsmilies', TRUE); showtableheader('smilies_add', 'notop fixpadding'); showtablerow('', '', "$lang[smilies_type]:$type[name]"); showtablerow('', '', "$lang[dir]:$smurl $lang[smilies_add_search]"); showtablerow('', '', ''); showtablefooter(); showtagfooter('div'); if($_GET['search']) { $newid = 1; $newimages = ''; $imgfilter = array(); foreach(C::t('common_smiley')->fetch_all_by_typeid_type($id, 'smiley') as $smiley) { $imgfilter[] = $img[url]; } $smiliesdir = dir($smdir); while($entry = $smiliesdir->read()) { if(in_array(strtolower(fileext($entry)), $imgextarray) && !in_array($entry, $imgfilter) && preg_match("/^[\w\-\.\[\]\(\)\<\> &]+$/", substr($entry, 0, strrpos($entry, '.'))) && strlen($entry) < 30 && is_file($smdir.'/'.$entry)) { $newimages .= showtablerow('', array('class="td25"', 'class="td28 td24"', 'class="td23"'), array( "", "", "30) {this.resized=true; this.height=30;}\" onmouseover=\"if(this.resized) this.style.cursor='pointer';\" onclick=\"if(!this.resized) {return false;} else {window.open(this.src);}\">", "$entry" ), TRUE); $newid ++; } } $smiliesdir->close(); ajaxshowheader(); if($newimages) { showformheader("smilies&operation=edit&do=add&id=$id"); showtableheader('smilies_add', 'notop fixpadding'); showsubtitle(array('', 'display_order', 'smilies_edit_image', 'smilies_edit_filename')); echo $newimages; showtablerow('', array('class="td25"', 'colspan="3"'), array( ''.$lang['enable'], '   ' )); showtablefooter(); showformfooter(); } else { showtableheader('smilies_add', 'notop'); showtablerow('', 'class="lineheight"', cplang('smilies_edit_add_tips', array('smurl' => $smurl))); showtablerow('', '', ''); showtablefooter(); } ajaxshowfooter(); } } else { if(is_array($_GET['smilies'])) { addsmilies($id, $_GET['smilies']); } updatecache(array('smilies', 'smileycodes', 'smilies_js')); cpmsg('smilies_edit_succeed', "action=smilies&operation=edit&id=$id", 'succeed'); } } } elseif($operation == 'update' && $id) { if(!($smtype = C::t('forum_imagetype')->fetch($id))) { cpmsg('smilies_type_nonexistence', '', 'error'); } else { $smurl = './static/image/smiley/'.$smtype['directory']; $smdir = DISCUZ_ROOT.$smurl; if(!is_dir($smdir)) { cpmsg('smilies_directory_invalid', '', 'error', array('smurl' => $smurl)); } } $smilies = update_smiles($smdir, $id, $imgextarray); if($smilies['smilies']) { addsmilies($id, $smilies['smilies']); updatecache(array('smilies', 'smileycodes', 'smilies_js')); cpmsg('smilies_update_succeed', "action=smilies", 'succeed', array('smurl' => $smurl, 'num' => $smilies['num'], 'typename' => $smtype['name'])); } else { cpmsg('smilies_update_error', '', 'error', array('smurl' => $smurl)); } } elseif($operation == 'import') { if(!submitcheck('importsubmit')) { shownav('style', 'smilies_edit'); showsubmenu('nav_smilies', array( array('smilies_type', 'smilies', 0), array('smilies_import', 'smilies&operation=import', 1), )); /*search={"nav_smilies":"action=smilies","smilies_import":"action=smilies&operation=import"}*/ showtips('smilies_tips'); /*search*/ showformheader('smilies&operation=import', 'enctype'); showtableheader('smilies_import'); showimportdata(); showsubmit('importsubmit'); showtablefooter(); showformfooter(); } else { require_once libfile('function/importdata'); $renamed = import_smilies(); if($renamed) { cpmsg('smilies_import_succeed_renamed', 'action=smilies', 'succeed'); } else { cpmsg('smilies_import_succeed', 'action=smilies', 'succeed'); } } } function addsmilies($typeid, $smilies = array()) { if(is_array($smilies)) { $ids = array(); foreach($smilies as $smiley) { if($smiley['available']) { $data = array( 'type' => 'smiley', 'displayorder' => $smiley['displayorder'], 'typeid' => $typeid, 'code' => '', 'url' => $smiley['url'], ); $ids[] = C::t('common_smiley')->insert($data, true); } } if($ids) { C::t('common_smiley')->update_code_by_id($ids); } } } function update_smiles($smdir, $id, &$imgextarray) { $num = 0; $smilies = $imgfilter = array(); foreach(C::t('common_smiley')->fetch_all_by_typeid_type($id, 'smiley') as $img) { $imgfilter[] = $img[url]; } $smiliesdir = dir($smdir); while($entry = $smiliesdir->read()) { if(in_array(strtolower(fileext($entry)), $imgextarray) && !in_array($entry, $imgfilter) && preg_match("/^[\w\-\.\[\]\(\)\<\> &]+$/", substr($entry, 0, strrpos($entry, '.'))) && strlen($entry) < 30 && is_file($smdir.'/'.$entry)) { $smilies[] = array('available' => 1, 'displayorder' => 0, 'url' => $entry); $num++; } } $smiliesdir->close(); return array('smilies'=>$smilies, 'num'=>$num); } ?>