2019-03-29 19:13:32 -05:00
< ? php
/*
* e107 website system
*
* Copyright ( C ) 2008 - 2013 e107 Inc ( e107 . org )
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* Administration Area - Emotions Settings & Packs
*
*
*/
2021-01-16 13:32:35 -08:00
require_once ( __DIR__ . '/../class2.php' );
2019-03-29 19:13:32 -05:00
if ( ! getperms ( " F " ))
{
e107 :: redirect ( 'admin' );
exit ;
}
e107 :: coreLan ( 'emoticon' , true );
$e_sub_cat = 'emoticon' ;
e107 :: getConfig ( 'emote' ) -> clearPrefCache ( 'emote' );
require_once ( " auth.php " );
$mes = e107 :: getMessage ();
2020-12-11 14:55:16 -08:00
2019-03-29 19:13:32 -05:00
// Change the active emote pack
if ( isset ( $_POST [ 'active' ]))
{
if ( $pref [ 'smiley_activate' ] != $_POST [ 'smiley_activate' ])
{
2020-12-11 14:55:16 -08:00
$pref [ 'smiley_activate' ] = ( int ) $_POST [ 'smiley_activate' ];
2019-03-29 19:13:32 -05:00
e107 :: getLog () -> add ( $pref [ 'smiley_activate' ] ? 'EMOTE_02' : 'EMOTE_03' , $pref [ 'emotepack' ], E_LOG_INFORMATIVE , '' );
2020-12-22 14:48:28 -08:00
e107 :: getConfig () -> set ( 'smiley_activate' , $pref [ 'smiley_activate' ]) -> save ( true , true , true );
2019-03-29 19:13:32 -05:00
$update = true ;
}
else
{
$mes -> addInfo ( LAN_NO_CHANGE );
}
}
2019-05-27 10:45:35 -07:00
//e107::getRender()->tablerender($caption, $mes->render() . $text);
2019-03-29 19:13:32 -05:00
/* get packs */
2020-12-11 14:55:16 -08:00
2019-03-29 19:13:32 -05:00
$fl = e107 :: getFile ();
$emote = new emotec ;
2020-12-22 14:48:28 -08:00
$one_pack = false ;
2019-03-29 19:13:32 -05:00
$filtered = e107 :: getParser () -> filter ( $_POST );
// Check for pack-related buttons pressed
2020-12-22 14:48:28 -08:00
foreach ( $filtered as $key => $value )
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
if ( strpos ( $key , " subPack_ " ) !== false )
2019-03-29 19:13:32 -05:00
{
$subpack = str_replace ( " subPack_ " , " " , $key );
$emote -> emoteConf ( $subpack );
break ;
}
2020-12-22 14:48:28 -08:00
if ( strpos ( $key , " XMLPack_ " ) !== false )
2019-03-29 19:13:32 -05:00
{
$subpack = str_replace ( " XMLPack_ " , " " , $key );
$emote -> emoteXML ( $subpack );
break ;
}
2020-12-22 14:48:28 -08:00
if ( strpos ( $key , " defPack_ " ) !== false )
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
e107 :: getConfig () -> set ( 'emotepack' , str_replace ( " defPack_ " , " " , $key )) -> save ( true , true , true );
2019-03-29 19:13:32 -05:00
e107 :: getLog () -> add ( 'EMOTE_01' , $pref [ 'emotepack' ], E_LOG_INFORMATIVE , '' );
break ;
}
2020-12-22 14:48:28 -08:00
if ( strpos ( $key , " scanPack_ " ) !== false )
2019-03-29 19:13:32 -05:00
{
$one_pack = str_replace ( " scanPack_ " , " " , $key );
break ;
}
}
2019-05-27 10:45:35 -07:00
// $ns->tablerender($caption, $mes->render() . $text);
2019-03-29 19:13:32 -05:00
$check = $emote -> installCheck ( $one_pack );
2020-12-22 14:48:28 -08:00
if ( $check !== false )
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
$emote -> listPacks ();
2019-03-29 19:13:32 -05:00
}
class emotec
{
2020-12-22 14:48:28 -08:00
var $packArray ; // Stores an array of all available emote packs (as subdirectory names)
2019-03-29 19:13:32 -05:00
2020-03-31 11:56:04 -07:00
function __construct ()
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
2019-03-29 19:13:32 -05:00
/* constructor */
$fl = e107 :: getFile ();
2020-12-22 14:48:28 -08:00
$this -> packArray = $fl -> get_dirs ( e_IMAGE . " emotes " );
2019-03-29 19:13:32 -05:00
2020-12-22 14:48:28 -08:00
if ( isset ( $_POST [ 'sub_conf' ]))
{ // Update stored pack configuration
$this -> saveConf ();
2019-03-29 19:13:32 -05:00
}
}
// List available emote packs
function listPacks ()
{
2020-12-22 14:48:28 -08:00
2019-03-29 19:13:32 -05:00
$pref = e107 :: getPref ();
$frm = e107 :: getForm ();
$fl = e107 :: getFile ();
$ns = e107 :: getRender ();
2020-12-22 14:48:28 -08:00
$mes = e107 :: getMessage ();
2019-03-29 19:13:32 -05:00
$text = "
< ul class = 'nav nav-tabs' >
2021-01-26 15:08:58 -08:00
< li class = 'active' >< a href = '#emoticon-activate' data - toggle = 'tab' data - bs - toggle = 'tab' > " . EMOLAN_1 . " </ a ></ li >
< li >< a href = '#emoticon-packages' data - toggle = 'tab' data - bs - toggle = 'tab' > " . EMOLAN_13 . " </ a ></ li >
2019-03-29 19:13:32 -05:00
</ ul >
< div class = 'tab-content' >
< div class = 'tab-pane active' id = 'emoticon-activate' >
< fieldset >
2020-12-22 14:48:28 -08:00
< form method = 'post' action = '" . e_SELF . "' >
< legend > " . EMOLAN_1 . " </ legend >
2019-03-29 19:13:32 -05:00
< table class = 'table adminform' >
< colgroup >
< col style = 'width:30%' />
< col style = 'width:70%' />
</ colgroup >
< tbody >
< tr >
< td >
2020-12-22 14:48:28 -08:00
" . EMOLAN_4 . " :
2019-03-29 19:13:32 -05:00
</ td >
< td >
< div class = 'auto-toggle-area autocheck' >
2020-12-22 14:48:28 -08:00
" . $frm->checkbox ('smiley_activate', 1, varset( $pref['smiley_activate'] , 0)) . "
2019-03-29 19:13:32 -05:00
</ div >
</ td >
</ tr >
</ tbody >
</ table >
< div class = 'buttons-bar center' >
2020-12-22 14:48:28 -08:00
" . $frm->admin_button ('active', 'active', 'update', LAN_UPDATE) . "
2019-03-29 19:13:32 -05:00
</ div >
< fieldset >
</ form >
</ div >
" ;
$text .= "
< div class = 'tab-pane' id = 'emoticon-packages' >
2020-12-22 14:48:28 -08:00
< form method = 'post' action = '" . e_SELF . "#etabTabContainer=emoticon-packages' >
2019-03-29 19:13:32 -05:00
< fieldset >
2020-12-22 14:48:28 -08:00
< legend > " . EMOLAN_13 . " </ legend >
2019-03-29 19:13:32 -05:00
< table class = 'table adminlist' style = 'margin-top:10px' >
< colgroup >
< col style = 'width:15%' />
< col style = 'width:50%' />
< col style = 'width:10%' />
< col style = 'width:25%' />
</ colgroup >
< thead >
< tr >
2020-12-22 14:48:28 -08:00
< th class = 'center' > " . LAN_NAME . " </ th >
< th class = 'center' > " . EMOLAN_3 . " </ th >
< th class = 'center' > " . LAN_STATUS . " </ th >
< th class = 'center' > " . LAN_OPTIONS . " </ th >
2019-03-29 19:13:32 -05:00
</ tr >
</ thead >
< tbody >
" ;
2020-12-22 14:48:28 -08:00
$reject = '~^emoteconf|\.html$|\.php$|\.txt$' ; // Files to exclude
foreach ( $this -> packArray as $pack )
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
$can_scan = false ;
$emoteArray = $fl -> get_files ( e_IMAGE . 'emotes/' . $pack , $reject );
2019-03-29 19:13:32 -05:00
$text .= "
< tr >
2020-12-22 14:48:28 -08:00
< td > { $pack } </ td >
< td >
2019-03-29 19:13:32 -05:00
" ;
2020-12-22 14:48:28 -08:00
foreach ( $emoteArray as $emote )
2019-03-29 19:13:32 -05:00
{
2020-12-20 11:50:10 -08:00
if ( strpos ( $emote [ 'fname' ], " .pak " ) !== false
2020-12-22 14:48:28 -08:00
|| strpos ( $emote [ 'fname' ], " .xml " ) !== false
|| strpos ( $emote [ 'fname' ], " phpBB " ) !== false )
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
$can_scan = true ; // Allow re-scan of config files
2019-03-29 19:13:32 -05:00
}
//elseif (!strstr($emote['fname'], ".txt") && !strstr($emote['fname'], ".bak") && !strstr($emote['fname'], ".html") && !strstr($emote['fname'], ".php") )
else
{ // Emote file found (might get other non-image files, but shouldn't)
2020-12-22 14:48:28 -08:00
$text .= " <img src=' " . $emote [ 'path' ] . $emote [ 'fname' ] . " ' alt='' /> " ;
2019-03-29 19:13:32 -05:00
}
}
$text .= "
</ td >
2020-12-22 14:48:28 -08:00
< td class = 'center middle' > " . ( $pref['emotepack'] == $pack ? " < span class = 'label label-success' > " . LAN_ACTIVE . " </ span > " : " < button class = 'btn btn-primary' type = 'submit' name = 'defPack_" . $pack . "' value = '" . EMOLAN_11 . "' >< span > " . EMOLAN_11 . " </ span ></ button > " ) . " </ td >
2019-03-29 19:13:32 -05:00
< td > " ;
2020-12-22 14:48:28 -08:00
$text .= $frm -> admin_button ( 'subPack_' . $pack , 'edit' , 'default' , LAN_CONFIGURE );
2019-03-29 19:13:32 -05:00
if ( $can_scan && ( $pack != 'default' ))
{
2020-12-22 14:48:28 -08:00
// $text .= "<button class='btn btn-default submit' type='submit' name='scanPack_".$pack."'><span>".EMOLAN_26."</span></button>";
$text .= $frm -> admin_button ( 'scanPack_' . $pack , 'active' , 'default' , EMOLAN_26 );
2019-03-29 19:13:32 -05:00
}
2020-12-22 14:48:28 -08:00
$text .= $frm -> admin_button ( 'XMLPack_' . $pack , 'submit' , 'default' , EMOLAN_28 );
2019-03-29 19:13:32 -05:00
$text .= "
</ td >
</ tr >
" ;
}
$text .= "
</ tbody >
</ table >
</ fieldset >
</ form >
</ div >
</ div >
" ;
2020-12-22 14:48:28 -08:00
$ns -> tablerender ( EMOLAN_PAGE_TITLE , $mes -> render () . $text );
2019-03-29 19:13:32 -05:00
}
// Configure an individual emote pack
function emoteConf ( $packID )
{
2020-12-22 14:48:28 -08:00
2019-03-29 19:13:32 -05:00
global $e107 , $sysprefs ;
$frm = e107 :: getForm ();
$tp = e107 :: getParser ();
$fl = e107 :: getFile ();
2020-12-22 14:48:28 -08:00
$ns = e107 :: getRender ();
2019-03-29 19:13:32 -05:00
$packID = $tp -> filter ( $packID );
2020-12-22 14:48:28 -08:00
$corea = " emote_ " . $packID ;
2019-03-29 19:13:32 -05:00
2020-12-22 14:48:28 -08:00
$emotecode = $sysprefs -> getArray ( $corea );
$reject = '~^emoteconf|\.html$|\.php$|\.txt$|\.pak$|\.xml|\.phpBB' ; // Files to exclude
$emoteArray = $fl -> get_files ( e_IMAGE . " emotes/ " . $packID , $reject );
2019-03-29 19:13:32 -05:00
$eArray = array ();
2020-12-22 14:48:28 -08:00
foreach ( $emoteArray as $value )
2019-03-29 19:13:32 -05:00
{
$eArray [] = array ( 'path' => $value [ 'path' ], 'fname' => $value [ 'fname' ]);
}
//XXX Not sure if we need to know rhe number of files found - count($eArray) - <div class='info-bar'><strong>Total ".count($eArray)." files found</strong></div>
$text = "
2020-12-22 14:48:28 -08:00
< form method = 'post' action = '" . e_SELF . "#etabTabContainer=emoticon-packages' >
2019-03-29 19:13:32 -05:00
< fieldset id = 'core-emoticon-configure' >
2020-12-22 14:48:28 -08:00
< legend class = 'e-hideme' > " . LAN_EDIT . " </ legend >
< div class = 'info-bar' style = 'padding-bottom:10px' > " . $tp->lanVars (EMOLAN_31, count( $eArray )) . " </ div >
2019-03-29 19:13:32 -05:00
< table class = 'table adminlist' >
< colgroup >
< col style = 'width:20px' />
< col class = 'col-label' />
< col class = 'col-control' />
</ colgroup >
< thead >
< tr >
2020-12-22 14:48:28 -08:00
< th > " . EMOLAN_5 . " </ th >
< th > " . LAN_NAME . " </ th >
< th class = 'last' > " . EMOLAN_6 . " < span class = 'field-help' > ( " . EMOLAN_7 . " ) </ span ></ th >
2019-03-29 19:13:32 -05:00
</ tr >
</ thead >
< tbody >
" ;
2020-12-22 14:48:28 -08:00
foreach ( $eArray as $emote )
2019-03-29 19:13:32 -05:00
{
$ename = $emote [ 'fname' ];
$evalue = str_replace ( " . " , " ! " , $ename );
$file_back = '' ;
$text_back = '' ;
if ( ! isset ( $emotecode [ $evalue ]))
{
2020-12-22 14:48:28 -08:00
$file_back = ' <span class="label label-danger error">' . EMOLAN_37 . '</span>' ;
2019-03-29 19:13:32 -05:00
}
elseif ( ! $emotecode [ $evalue ])
{
2020-12-22 14:48:28 -08:00
$text_back = ' <span class="label label-danger error">' . EMOLAN_38 . '</span>' ;
2019-03-29 19:13:32 -05:00
}
$text .= "
< tr >
2020-12-22 14:48:28 -08:00
< td class = 'center' >< img src = '" . $emote[' path '] . $ename . "' alt = '' /></ td >
< td > " . $ename . " { $file_back } </ td >
2019-03-29 19:13:32 -05:00
< td >
2020-12-22 14:48:28 -08:00
< input class = 'tbox input-text' type = 'text' name = '{$evalue}' value = '" . $tp->toForm(varset($emotecode[$evalue], ' ')) . "' maxlength = '200' /> { $text_back }
2019-03-29 19:13:32 -05:00
</ td >
</ tr >
" ;
}
$text .= "
</ tbody >
</ table >
< div class = 'buttons-bar center' >
< input type = 'hidden' name = 'packID' value = '{$packID}' /> " ;
2020-12-22 14:48:28 -08:00
$text .= $frm -> admin_button ( 'sub_conf' , 'no-value' , 'update' , LAN_SAVE );
$text .= $frm -> admin_button ( 'cancel' , 'no-value' , 'cancel' , LAN_CANCEL );
2019-03-29 19:13:32 -05:00
$text .= "
</ div >
</ fieldset >
</ form > " ;
2020-12-22 14:48:28 -08:00
$ns -> tablerender ( EMOLAN_PAGE_TITLE . SEP . LAN_EDIT . " : ' " . $packID . " ' " , $text );
2019-03-29 19:13:32 -05:00
}
// Generate an XML file - packname.xml in root emoticon directory
2020-12-22 14:48:28 -08:00
function emoteXML ( $packID , $strip_xtn = true )
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
2019-03-29 19:13:32 -05:00
global $sysprefs ;
$mes = e107 :: getMessage ();
$fl = e107 :: getFile ();
$tp = e107 :: getParser ();
$packID = $tp -> filter ( $packID );
2020-12-22 14:48:28 -08:00
$fname = e_IMAGE . " emotes/ " . $packID . " /emoticons.xml " ;
$backname = e_IMAGE . " emotes/ " . $packID . " /emoticons.bak " ;
2019-03-29 19:13:32 -05:00
2020-12-22 14:48:28 -08:00
$corea = " emote_ " . $packID ;
$emotecode = $sysprefs -> getArray ( $corea );
2019-03-29 19:13:32 -05:00
2020-12-22 14:48:28 -08:00
$reject = '~^emoteconf|\.html$|\.php$|\.txt$|\.pak$|\.xml|\.phpBB' ; // Files to exclude
$emoteArray = $fl -> get_files ( e_IMAGE . " emotes/ " . $packID , $reject );
2019-03-29 19:13:32 -05:00
$eArray = array ();
2020-12-22 14:48:28 -08:00
foreach ( $emoteArray as $value )
2019-03-29 19:13:32 -05:00
{
$eArray [] = $value [ 'fname' ];
}
2020-12-22 14:48:28 -08:00
$f_string = " <?xml version= \" 1.0 \" ? " . " > \n <messaging-emoticon-map > \n \n \n " ;
2019-03-29 19:13:32 -05:00
2020-12-22 14:48:28 -08:00
foreach ( $eArray as $emote )
2019-03-29 19:13:32 -05:00
{
// Optionally strip file extension
$evalue = str_replace ( " . " , " ! " , $emote );
2020-12-22 14:48:28 -08:00
if ( $strip_xtn )
{
$ename = substr ( $emote , 0 , strrpos ( $emote , '.' ));
}
2019-03-29 19:13:32 -05:00
$f_string .= " <emoticon file= \" { $ename } \" > \n " ;
2020-12-22 14:48:28 -08:00
foreach ( explode ( ' ' , $tp -> toForm ( $emotecode [ $evalue ])) as $v )
2019-03-29 19:13:32 -05:00
{
2020-12-11 14:55:16 -08:00
if ( trim ( $v ))
{
2020-12-22 14:48:28 -08:00
$f_string .= " \t <string> " . htmlentities ( $v ) . " </string> \n " ;
2020-12-11 14:55:16 -08:00
}
2019-03-29 19:13:32 -05:00
}
$f_string .= " </emoticon> \n " ;
}
$f_string .= " \n </messaging-emoticon-map> \n " ;
2020-12-22 14:48:28 -08:00
if ( is_file ( $backname ))
{
unlink ( $backname );
} // Delete any old backup
2019-03-29 19:13:32 -05:00
2020-12-22 14:48:28 -08:00
if ( is_file ( $fname ))
{
rename ( $fname , $backname );
}
2019-03-29 19:13:32 -05:00
2020-12-22 14:48:28 -08:00
if ( file_put_contents ( $fname , $f_string ) === false )
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
$mes -> addWarning ( '<strong>' . EMOLAN_30 . '</strong>:' . str_replace ( e_IMAGE , e_IMAGE_ABS , $fname ));
2019-03-29 19:13:32 -05:00
}
else
{
2020-12-22 14:48:28 -08:00
$mes -> addSuccess ( '<strong>' . EMOLAN_29 . '</strong>:' . str_replace ( e_IMAGE , e_IMAGE_ABS , $fname ));
2019-03-29 19:13:32 -05:00
}
}
// Save configuration for an emote pack that's been edited
function saveConf ()
{
2020-12-22 14:48:28 -08:00
2019-03-29 19:13:32 -05:00
$sql = e107 :: getDb ();
$tp = e107 :: getParser ();
$packID = $_POST [ 'packID' ];
unset ( $_POST [ 'sub_conf' ], $_POST [ 'packID' ]);
$encoded_emotes = $tp -> toDB ( $_POST );
2020-12-22 14:48:28 -08:00
// $tmp = addslashes(serialize($encoded_emotes));
$tmp = e107 :: serialize ( $encoded_emotes );
2019-03-29 19:13:32 -05:00
2020-12-22 14:48:28 -08:00
if ( $sql -> select ( " core " , " * " , " e107_name='emote_ " . $packID . " ' " ))
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
e107 :: getMessage () -> addAuto ( $sql -> update ( " core " , " `e107_value`=' { $tmp } ' WHERE `e107_name`='emote_ " . $packID . " ' " ), 'update' , LAN_SETSAVED , false , false );
2019-03-29 19:13:32 -05:00
}
else
{
2020-12-22 14:48:28 -08:00
e107 :: getMessage () -> addAuto ( $sql -> insert ( " core " , " 'emote_ " . $packID . " ', ' $tmp ' " ), 'insert' , LAN_SETSAVED , false , false );
2019-03-29 19:13:32 -05:00
}
}
// Identify currently selected emote pack. Read in any new ones
// Return false to disable listing of packs
2020-12-22 14:48:28 -08:00
function installCheck ( $do_one = false )
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
2019-03-29 19:13:32 -05:00
global $e107 ;
2020-12-22 14:48:28 -08:00
$sql = e107 :: getDb ();
2019-03-29 19:13:32 -05:00
$fl = e107 :: getFile ();
$ns = e107 :: getRender ();
$mes = e107 :: getMessage ();
// Pick up a list of emote packs from the database
$pack_local = array ();
2020-12-22 14:48:28 -08:00
if ( $sql -> select ( " core " , " * " , " `e107_name` LIKE 'emote_%' " ))
2019-03-29 19:13:32 -05:00
{
while ( $row = $sql -> fetch ())
2020-12-22 14:48:28 -08:00
{
$pack_local [ substr ( $row [ 'e107_name' ], 6 )] = true ;
}
2019-03-29 19:13:32 -05:00
}
2020-12-22 14:48:28 -08:00
foreach ( $this -> packArray as $value )
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
if ( strpos ( $value , ' ' ) !== false )
{ // Highlight any directory names containing spaces - not allowed
2019-03-29 19:13:32 -05:00
$msg = "
2020-12-22 14:48:28 -08:00
< strong > " . EMOLAN_17 . " </ strong > " . EMOLAN_18 . " :
< div > " . LAN_NAME . " : { $value } </ div >
< div > " . EMOLAN_20 . " : " . e_IMAGE_ABS . " emotes /</ div >
2019-03-29 19:13:32 -05:00
" ;
$mes -> addError ( $msg );
2020-12-22 14:48:28 -08:00
$ns -> tablerender ( EMOLAN_PAGE_TITLE . ' - ' . EMOLAN_21 , $mes -> render ());
return false ;
2019-03-29 19:13:32 -05:00
}
2020-12-22 14:48:28 -08:00
if ( array_key_exists ( $value , $pack_local ))
2019-03-29 19:13:32 -05:00
{
unset ( $pack_local [ $value ]);
}
2020-12-22 14:48:28 -08:00
if (( $do_one == $value ) || ! $do_one && ( ! $sql -> select ( " core " , " * " , " e107_name='emote_ " . $value . " ' " )))
2019-03-29 19:13:32 -05:00
{ // Pack info not in DB, or to be re-scanned
2020-12-22 14:48:28 -08:00
$no_error = true ;
$File_type = EMOLAN_32 . " : " ;
2019-03-29 19:13:32 -05:00
// Array of all files in the directory of the selected emote pack
2020-12-22 14:48:28 -08:00
$fileArray = $fl -> get_files ( e_IMAGE . " emotes/ " . $value ); // We actually want all the files in the directory
2019-03-29 19:13:32 -05:00
$confFile = '' ;
2020-12-22 14:48:28 -08:00
foreach ( $fileArray as $k => $file )
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
if ( strpos ( $file [ 'fname' ], " .xml " ) !== false )
2019-03-29 19:13:32 -05:00
{
$confFile = array ( 'file' => $file [ 'fname' ], 'type' => " xml " );
}
2020-12-22 14:48:28 -08:00
elseif ( strpos ( $file [ 'fname' ], " .pak " ) !== false )
2019-03-29 19:13:32 -05:00
{
$confFile = array ( 'file' => $file [ 'fname' ], 'type' => " pak " );
}
2020-12-22 14:48:28 -08:00
elseif ( strpos ( $file [ 'fname' ], " .php " ) !== false )
2019-03-29 19:13:32 -05:00
{
$confFile = array ( 'file' => $file [ 'fname' ], 'type' => " php " );
}
if ( $confFile )
{
2020-12-22 14:48:28 -08:00
unset ( $fileArray [ $k ]);
break ;
2019-03-29 19:13:32 -05:00
}
}
/* .pak file */
2020-12-22 14:48:28 -08:00
if ( $confFile [ 'type' ] == " pak " )
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
$filename = e_IMAGE . " emotes/ " . $value . " / " . $confFile [ 'file' ];
$pakconf = file ( $filename );
2019-03-29 19:13:32 -05:00
$contentArray = array ();
2020-12-22 14:48:28 -08:00
foreach ( $pakconf as $line )
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
if ( trim ( $line ) && strpos ( $line , " =+ " ) !== false && strpos ( $line , " .txt " ) === false && strpos ( $line , " .html " ) === false && strpos ( $line , " cvs " ) === false )
{
$contentArray [] = $line ;
}
2019-03-29 19:13:32 -05:00
}
$confArray = array ();
2020-12-22 14:48:28 -08:00
foreach ( $contentArray as $pakline )
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
$tmp = explode ( " =+: " , $pakline );
$confIC = str_replace ( " . " , " ! " , $tmp [ 0 ]);
$confArray [ $confIC ] = trim ( $tmp [ 2 ]);
2019-03-29 19:13:32 -05:00
}
// $tmp = addslashes(serialize($confArray));
$tmp = e107 :: serialize ( $confArray );
2020-12-22 14:48:28 -08:00
$File_type = EMOLAN_22 . " : " ;
2019-03-29 19:13:32 -05:00
}
/* end */
/* .xml file */
2020-12-22 14:48:28 -08:00
if ( $confFile [ 'type' ] == " xml " )
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
$filename = e_IMAGE . " emotes/ " . $value . " / " . $confFile [ 'file' ];
2019-03-29 19:13:32 -05:00
$contents = file_get_contents ( $filename );
$confArray = array ();
$xml_type = 0 ;
2020-12-22 14:48:28 -08:00
if (( strpos ( $contents , " <icon> " ) !== false ) && ( strpos ( $contents , " <icondef> " ) !== false ))
{ // xep-0038 format
/* Example :
< icon >
< text >:- ) </ text >
< text >: ) </ text >
< object mime = " image/png " > happy . png </ object >
< object mime = " audio/x-wav " > choir . wav </ object >
</ icon >*/
preg_match_all ( " # \ <icon>(.*?) \ < \ /icon \ >#si " , $contents , $match );
$xml_type = 1 ;
2019-03-29 19:13:32 -05:00
// $match[0] - complete emoticon entry
// $match[1] - match string and object specification
2020-12-22 14:48:28 -08:00
$item_index = 1 ;
2019-03-29 19:13:32 -05:00
}
2020-12-22 14:48:28 -08:00
elseif ( strpos ( $contents , " <emoticon " ) !== false )
{ // "Original" E107 format (as used on KDE, although they may be changing to XEP-0038)
2019-03-29 19:13:32 -05:00
//echo "Decoding standard XML file<br />";
2020-12-22 14:48:28 -08:00
preg_match_all ( " # \ <emoticon file= \" (.*?) \" \ >(.*?) \ < \ /emoticon \ >#si " , $contents , $match );
2019-03-29 19:13:32 -05:00
2020-12-22 14:48:28 -08:00
$xml_type = 2 ;
2019-03-29 19:13:32 -05:00
// $match[0] - complete emoticon entry
// $match[1] - filename (may or may not not have file extension/suffix)
// $match[2] - match string(s) representing emote
2020-12-22 14:48:28 -08:00
$item_index = 2 ;
2019-03-29 19:13:32 -05:00
}
if ( $xml_type )
{
2020-12-22 14:48:28 -08:00
for ( $a = 0 , $aMax = count ( $match [ 0 ]); $a < $aMax ; $a ++ )
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
$e_file = '' ;
switch ( $xml_type )
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
case 1 : // xep-0038
// Pull out a file name (only support first image type) - its in $fmatch[1]
if ( preg_match ( " # \ <object \ s*?mime \ =[ \" \ ']image \ /.*? \ >(.*?) \ < \ /object \ >#si " , $match [ 1 ][ $a ], $fmatch ))
{
$e_file = $fmatch [ 1 ];
2019-03-29 19:13:32 -05:00
// echo "xep-0038 file: ".$e_file."<br />";
2020-12-22 14:48:28 -08:00
// Pull out all match strings - need to pick out any language definitions for posterity
// but currently accept all language strings
preg_match_all ( " # \ <text(?: \ s*? \ >| \ s*?xml \ :lang \ = \" (.*?) \" \ >)(.*?) \ < \ /text \ >#si " , $match [ 1 ][ $a ], $match2 );
// $match2[1] is the languages
// $match2[2] is the match strings
$codet = implode ( " " , $match2 [ 2 ]);
}
break ;
case 2 :
$e_file = $match [ 1 ][ $a ];
// Now pull out all the 'match' strings
preg_match_all ( " # \ <string \ >(.*?) \ < \ /string \ >#si " , $match [ 2 ][ $a ], $match2 );
$codet = implode ( " " , $match2 [ 1 ]);
break ;
2019-03-29 19:13:32 -05:00
}
2020-12-22 14:48:28 -08:00
// $e_file has the emote file name
// $match2 has an array of substitution strings
$file = '' ;
foreach ( $fileArray as $emote )
{ // Check that the file exists
if ( strpos ( $e_file , " . " ) === false )
{ // File extension not specified - accept any file extension for match
if ( strpos ( $emote [ 'fname' ], $e_file . " . " ) === 0 )
{
$file = str_replace ( " . " , " ! " , $emote [ 'fname' ]);
break ;
}
}
else
{ // File extension specified - do simple match
if ( $emote [ 'fname' ] == $e_file )
{
$file = str_replace ( " . " , " ! " , $emote [ 'fname' ]);
break ;
}
}
2019-03-29 19:13:32 -05:00
}
2020-12-22 14:48:28 -08:00
// Only add if the file exists. OK if no definition - might want to be added
if ( $file )
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
$confArray [ $file ] = $codet ;
}
2019-03-29 19:13:32 -05:00
}
}
else
{
2020-12-22 14:48:28 -08:00
//echo "Unsupported XML File Format<br /><br />";
$mes -> addWarning ( EMOLAN_33 );
$no_error = false ;
2019-03-29 19:13:32 -05:00
}
// Save pack info in the database
2020-12-22 14:48:28 -08:00
// $tmp = addslashes(serialize($confArray));
$tmp = e107 :: serialize ( $confArray );
$File_type = EMOLAN_23 . " : " ;
2019-03-29 19:13:32 -05:00
}
2020-12-22 14:48:28 -08:00
if ( $confFile [ 'type' ] == " php " )
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
include_once ( e_IMAGE . " emotes/ " . $value . " / " . $confFile [ 'file' ]);
$File_type = EMOLAN_24 . " : " ;
$tmp = $_emoteconf ; // Use consistent name
2019-03-29 19:13:32 -05:00
}
if ( $no_error )
{
2020-12-22 14:48:28 -08:00
if ( $do_one ) // Assume existing pack
{
$update = array (
'e107_name' => 'emote_' . $value ,
'e107_value' => $tmp ,
'WHERE' => " e107_name = 'emote_ " . $value . " ' "
);
$sql -> update ( " core " , $update );
}
else
{ // Assume new pack
$insert = array (
'e107_name' => 'emote_' . $value ,
'e107_value' => $tmp
);
$sql -> insert ( " core " , $insert );
}
$mes -> addInfo ( " <strong> { $File_type } </strong> ' { $value } ' " );
2019-03-29 19:13:32 -05:00
}
else
{ // Error occurred
2020-12-22 14:48:28 -08:00
$mes -> addError ( EMOLAN_27 . " : ' { $value } ' " );
2019-03-29 19:13:32 -05:00
}
}
}
if ( count ( $pack_local ))
{
2020-12-22 14:48:28 -08:00
foreach ( $pack_local as $p => $d )
2019-03-29 19:13:32 -05:00
{
2020-12-22 14:48:28 -08:00
if ( $p == '0' )
2019-03-29 19:13:32 -05:00
{
$p = '' ;
}
2020-12-22 14:48:28 -08:00
if ( $sql -> delete ( " core " , " `e107_name` = 'emote_ { $p } ' " ))
{
$mes -> addInfo ( EMOLAN_34 . " : " . $p . EMOLAN_35 );
}
2019-03-29 19:13:32 -05:00
}
}
2020-12-22 14:48:28 -08:00
return true ;
2019-03-29 19:13:32 -05:00
}
}
2020-12-22 14:48:28 -08:00
2019-03-29 19:13:32 -05:00
require_once ( " footer.php " );