mirror of
https://github.com/e107inc/e107.git
synced 2025-08-06 14:46:56 +02:00
Tidy up, experimental reading of xep-0038 format emote files
This commit is contained in:
@@ -11,8 +11,8 @@
|
|||||||
| GNU General Public License (http://gnu.org).
|
| GNU General Public License (http://gnu.org).
|
||||||
|
|
|
|
||||||
| $Source: /cvs_backup/e107_0.8/e107_admin/emoticon.php,v $
|
| $Source: /cvs_backup/e107_0.8/e107_admin/emoticon.php,v $
|
||||||
| $Revision: 1.4 $
|
| $Revision: 1.5 $
|
||||||
| $Date: 2007-05-24 21:06:50 $
|
| $Date: 2007-05-29 19:45:38 $
|
||||||
| $Author: e107steved $
|
| $Author: e107steved $
|
||||||
+----------------------------------------------------------------------------+
|
+----------------------------------------------------------------------------+
|
||||||
*/
|
*/
|
||||||
@@ -259,7 +259,7 @@ class emotec
|
|||||||
|
|
||||||
|
|
||||||
// Generate an XML file - packname.xml in root emoticon directory
|
// Generate an XML file - packname.xml in root emoticon directory
|
||||||
function emoteXML($packID)
|
function emoteXML($packID, $strip_xtn = TRUE)
|
||||||
{
|
{
|
||||||
global $fl, $pref, $sysprefs, $tp;
|
global $fl, $pref, $sysprefs, $tp;
|
||||||
|
|
||||||
@@ -289,9 +289,9 @@ class emotec
|
|||||||
|
|
||||||
foreach($eArray as $emote)
|
foreach($eArray as $emote)
|
||||||
{
|
{
|
||||||
// Strip file extension
|
// Optionally strip file extension
|
||||||
$evalue = str_replace(".", "!", $emote);
|
$evalue = str_replace(".", "!", $emote);
|
||||||
$ename = substr($emote,0,strrpos($emote,'.'));
|
if ($strip_xtn) $ename = substr($emote,0,strrpos($emote,'.'));
|
||||||
$f_string .= "<emoticon file=\"{$ename}\">\n";
|
$f_string .= "<emoticon file=\"{$ename}\">\n";
|
||||||
foreach (explode(' ',$tp -> toForm($emotecode[$evalue])) as $v)
|
foreach (explode(' ',$tp -> toForm($emotecode[$evalue])) as $v)
|
||||||
{
|
{
|
||||||
@@ -305,8 +305,14 @@ class emotec
|
|||||||
if (is_file($backname)) unlink($backname); // Delete any old backup
|
if (is_file($backname)) unlink($backname); // Delete any old backup
|
||||||
|
|
||||||
if (is_file($fname)) rename($fname,$backname);
|
if (is_file($fname)) rename($fname,$backname);
|
||||||
file_put_contents($fname,$f_string);
|
if (file_put_contents($fname,$f_string) === FALSE)
|
||||||
echo "<br /><div style='text-align: center;'>".EMOLAN_29."<b>".$fname."</b></div><br />";
|
{
|
||||||
|
echo "<br /><div style='text-align: center;'>".EMOLAN_30."<b>".$fname."</b></div><br />";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo "<br /><div style='text-align: center;'>".EMOLAN_29."<b>".$fname."</b></div><br />";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -345,6 +351,17 @@ class emotec
|
|||||||
function installCheck($do_one = FALSE)
|
function installCheck($do_one = FALSE)
|
||||||
{
|
{
|
||||||
global $sql, $fl;
|
global $sql, $fl;
|
||||||
|
|
||||||
|
// Pick up a list of emote packs from the database
|
||||||
|
$pack_local = array();
|
||||||
|
if ($sql->db_Select("core","*","`e107_name` LIKE 'emote_%'",TRUE))
|
||||||
|
{
|
||||||
|
while ($row = $sql->db_Fetch())
|
||||||
|
{
|
||||||
|
$pack_local[substr($row['e107_name'],6)] = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach($this -> packArray as $value)
|
foreach($this -> packArray as $value)
|
||||||
{
|
{
|
||||||
if(strpos($value,' ')!==FALSE)
|
if(strpos($value,' ')!==FALSE)
|
||||||
@@ -366,6 +383,11 @@ class emotec
|
|||||||
$ns->tablerender(EMOLAN_21, $msg);
|
$ns->tablerender(EMOLAN_21, $msg);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (array_key_exists($value,$pack_local))
|
||||||
|
{
|
||||||
|
unset($pack_local[$value]);
|
||||||
|
}
|
||||||
|
|
||||||
if (($do_one == $value) || !$do_one && (!$sql -> db_Select("core", "*", "e107_name='emote_".$value."' ")))
|
if (($do_one == $value) || !$do_one && (!$sql -> db_Select("core", "*", "e107_name='emote_".$value."' ")))
|
||||||
{ // Pack info not in DB, or to be re-scanned
|
{ // Pack info not in DB, or to be re-scanned
|
||||||
@@ -373,7 +395,8 @@ class emotec
|
|||||||
$File_type = 'Unknown';
|
$File_type = 'Unknown';
|
||||||
// Array of all files in the directory of the selected emote pack
|
// Array of all files in the directory of the selected emote pack
|
||||||
$fileArray = $fl -> get_files(e_IMAGE."emotes/".$value);
|
$fileArray = $fl -> get_files(e_IMAGE."emotes/".$value);
|
||||||
foreach($fileArray as $file)
|
$confFile = '';
|
||||||
|
foreach($fileArray as $k => $file)
|
||||||
{
|
{
|
||||||
if(strstr($file['fname'], ".xml"))
|
if(strstr($file['fname'], ".xml"))
|
||||||
{
|
{
|
||||||
@@ -387,6 +410,11 @@ class emotec
|
|||||||
{
|
{
|
||||||
$confFile = array('file' => $file['fname'], 'type' => "php");
|
$confFile = array('file' => $file['fname'], 'type' => "php");
|
||||||
}
|
}
|
||||||
|
if ($confFile)
|
||||||
|
{
|
||||||
|
unset($fileArray[$k]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* .pak file */
|
/* .pak file */
|
||||||
@@ -416,40 +444,102 @@ class emotec
|
|||||||
{
|
{
|
||||||
$filename = e_IMAGE."emotes/".$value."/".$confFile['file'];
|
$filename = e_IMAGE."emotes/".$value."/".$confFile['file'];
|
||||||
|
|
||||||
$handle = fopen ($filename, "r");
|
// $handle = fopen ($filename, "r");
|
||||||
$contents = fread ($handle, filesize ($filename)); // Get the XML file for the emote pack
|
// $contents = fread ($handle, filesize ($filename)); // Get the XML file for the emote pack
|
||||||
fclose ($handle);
|
// fclose ($handle);
|
||||||
|
$contents = file_get_contents($filename);
|
||||||
preg_match_all("#\<emoticon file=\"(.*?)\"\>(.*?)\<\/emoticon\>#si", $contents, $match);
|
|
||||||
$confArray = array();
|
$confArray = array();
|
||||||
|
$xml_type = 0;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
// $match[0] - complete emoticon entry
|
$xml_type = 1;
|
||||||
// $match[1] - filename (no file extension/suffix)
|
// $match[0] - complete emoticon entry
|
||||||
// $match[2] - match string(s) representing emote
|
// $match[1] - match string and object specification
|
||||||
|
$item_index = 1;
|
||||||
// Now pull out all the 'match' strings
|
}
|
||||||
for($a=0; $a < count($match[2]); $a++)
|
elseif (strpos($contents, "<emoticon") !== FALSE)
|
||||||
|
{ // "Original" E107 format (as used on KDE, although they may be changing to XEP-0038)
|
||||||
|
preg_match_all("#\<emoticon file=\"(.*?)\"\>(.*?)\<\/emoticon\>#si", $contents, $match);
|
||||||
|
|
||||||
|
$xml_type = 2;
|
||||||
|
// $match[0] - complete emoticon entry
|
||||||
|
// $match[1] - filename (may or may not not have file extension/suffix)
|
||||||
|
// $match[2] - match string(s) representing emote
|
||||||
|
$item_index = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($xml_type)
|
||||||
{
|
{
|
||||||
preg_match_all("#\<string\>(.*?)\<\/string\>#si", $match[2][$a], $match2);
|
for($a=0; $a < count($match[0]); $a++)
|
||||||
|
|
||||||
$codet = "";
|
|
||||||
foreach($match2[1] as $code)
|
|
||||||
{
|
{
|
||||||
$codet .= $code." ";
|
$e_file = '';
|
||||||
}
|
switch ($xml_type)
|
||||||
|
|
||||||
$file = '';
|
|
||||||
foreach($fileArray as $emote)
|
|
||||||
{ // Check that the file exists
|
|
||||||
if(strpos($emote['fname'], $match[1][$a].".") === 0)
|
|
||||||
{
|
{
|
||||||
$file = str_replace(".", "!", $emote['fname']);
|
case 1 : // xep-0038
|
||||||
break;
|
// 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];
|
||||||
|
// echo "xep-0038 file: ".$e_file."<br />";
|
||||||
|
// 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;
|
||||||
}
|
}
|
||||||
}
|
// $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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// Only add if the file exists. OK if no definition - might want to be added
|
// Only add if the file exists. OK if no definition - might want to be added
|
||||||
if ($file) $confArray[$file] = $codet;
|
if ($file) $confArray[$file] = $codet;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo "Unsupported XML File Format<br /><br />";
|
||||||
|
$no_error = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Save pack info in the database
|
// Save pack info in the database
|
||||||
$tmp = addslashes(serialize($confArray));
|
$tmp = addslashes(serialize($confArray));
|
||||||
@@ -482,6 +572,14 @@ class emotec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (count($pack_local))
|
||||||
|
{
|
||||||
|
foreach ($pack_local as $p => $d)
|
||||||
|
{
|
||||||
|
echo "Missing files for pack: ".$p." - deleted in database<br />";
|
||||||
|
$sql->db_Delete("core","`e107_name` = 'emote_{$p}'");
|
||||||
|
}
|
||||||
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,8 +4,8 @@
|
|||||||
| e107 website system - Language File.
|
| e107 website system - Language File.
|
||||||
|
|
|
|
||||||
| $Source: /cvs_backup/e107_0.8/e107_languages/English/admin/lan_emoticon.php,v $
|
| $Source: /cvs_backup/e107_0.8/e107_languages/English/admin/lan_emoticon.php,v $
|
||||||
| $Revision: 1.3 $
|
| $Revision: 1.4 $
|
||||||
| $Date: 2007-05-24 21:06:57 $
|
| $Date: 2007-05-29 19:45:44 $
|
||||||
| $Author: e107steved $
|
| $Author: e107steved $
|
||||||
+----------------------------------------------------------------------------+
|
+----------------------------------------------------------------------------+
|
||||||
*/
|
*/
|
||||||
@@ -43,4 +43,5 @@ define("EMOLAN_26", "Re-scan pack");
|
|||||||
define("EMOLAN_27", "Error occurred processing pack: ");
|
define("EMOLAN_27", "Error occurred processing pack: ");
|
||||||
define("EMOLAN_28", "Generate XML");
|
define("EMOLAN_28", "Generate XML");
|
||||||
define("EMOLAN_29", "XML file generated: ");
|
define("EMOLAN_29", "XML file generated: ");
|
||||||
|
define("EMOLAN_30", "Error writing XML file: ");
|
||||||
?>
|
?>
|
Reference in New Issue
Block a user