mirror of
https://github.com/e107inc/e107.git
synced 2025-01-17 12:48:24 +01:00
First cut of utility to convert plugin.php to plugin.xml (for McFly to break)
This commit is contained in:
parent
d228585a66
commit
1ddcffcadb
449
e107_files/utilities/pluginxmlgen.php
Normal file
449
e107_files/utilities/pluginxmlgen.php
Normal file
@ -0,0 +1,449 @@
|
||||
<?php
|
||||
/*
|
||||
+ ----------------------------------------------------------------------------+
|
||||
| e107 website system - Converter for plugin.php to plugin.xml
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_files/utilities/pluginxmlgen.php,v $
|
||||
| $Revision: 1.1 $
|
||||
| $Date: 2008-07-01 20:49:50 $
|
||||
| $Author: e107steved $
|
||||
+----------------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/*
|
||||
Doesn't (can't) do everything, but sorts what it can.
|
||||
|
||||
Intended to be run from e107_files/utilities directory.
|
||||
|
||||
Usage: Just browse to this file and follow the prompts.
|
||||
|
||||
*/
|
||||
|
||||
require('../../class2.php');
|
||||
require_once(e_HANDLER."file_class.php");
|
||||
if (!check_class(e_UC_MAINADMIN))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
$fl = new e_file;
|
||||
if ($pluginList = $fl->get_files(e_PLUGIN, "^plugin\.php$", "standard", 1))
|
||||
{
|
||||
sort($pluginList);
|
||||
}
|
||||
foreach ($pluginList as $k => $p)
|
||||
{
|
||||
$pluginList[$k]['shortpath'] = substr(str_replace(e_PLUGIN,"",$p['path']),0,-1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function genFileSelect($name,$fl)
|
||||
{
|
||||
$ret = "<select name='{$name}' class='tbox'>\n<option value=''>----</option>\n";
|
||||
foreach ($fl as $k => $f)
|
||||
{
|
||||
$ret .= "<option value='{$f['shortpath']}'>{$f['shortpath']}</option>\n";
|
||||
}
|
||||
$ret .= "</select>\n";
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
define('TAB_CHAR',chr(9));
|
||||
|
||||
define('LAN_XMLGEN_01','Create a plugin.xml file from a plugin.php file');
|
||||
define('LAN_XMLGEN_02','plugin.xml creation');
|
||||
define('LAN_XMLGEN_03','Convert');
|
||||
define('LAN_XMLGEN_04','Select plugin');
|
||||
define('LAN_XMLGEN_05','No plugin selected - nothing changed');
|
||||
define('LAN_XMLGEN_06','Processing directory: ');
|
||||
define('LAN_XMLGEN_07','Conversion successful');
|
||||
define('LAN_XMLGEN_08','Cannot write to file: ');
|
||||
define('LAN_XMLGEN_09','Cannot open file for writing: ');
|
||||
define('LAN_XMLGEN_10','Cannot read ');
|
||||
define('LAN_XMLGEN_11','Copyright ');
|
||||
define('LAN_XMLGEN_12','URL to check for updates ');
|
||||
define('LAN_XMLGEN_13','(optional)');
|
||||
define('LAN_XMLGEN_14','(Any existing plugin.xml file will be renamed to plugin.bak)');
|
||||
define('LAN_XMLGEN_15','Cannot rename existing plugin.xml to plugin.bak');
|
||||
define('LAN_XMLGEN_16','Cannot delete existing plugin.bak');
|
||||
define('LAN_XMLGEN_17','Installation');
|
||||
define('LAN_XMLGEN_18','Upgrade');
|
||||
define('LAN_XMLGEN_19','Uninstallation');
|
||||
define('LAN_XMLGEN_20','Installation Management');
|
||||
define('LAN_XMLGEN_21','Installation required');
|
||||
define('LAN_XMLGEN_22','(Not used if no installation required)');
|
||||
define('LAN_XMLGEN_23','Yes');
|
||||
define('LAN_XMLGEN_24','No');
|
||||
define('LAN_XMLGEN_25','Type');
|
||||
define('LAN_XMLGEN_26','Function');
|
||||
define('LAN_XMLGEN_27','Class');
|
||||
define('LAN_XMLGEN_28','File name');
|
||||
define('LAN_XMLGEN_29','Function name');
|
||||
define('LAN_XMLGEN_30','When');
|
||||
define('LAN_XMLGEN_31','Pre');
|
||||
define('LAN_XMLGEN_32','Post');
|
||||
define('LAN_XMLGEN_33','Specify file name only - will default to \'.php\' if no extension specified');
|
||||
define('LAN_XMLGEN_34','Class name');
|
||||
define('LAN_XMLGEN_35','If specifying a function, leave the class name blank');
|
||||
define('LAN_XMLGEN_36','');
|
||||
define('LAN_XMLGEN_37','');
|
||||
define('LAN_XMLGEN_38','');
|
||||
|
||||
|
||||
|
||||
$managementOptions = array(
|
||||
'headings' => array('rowname' => ' ', 'when' => LAN_XMLGEN_30, 'type' => LAN_XMLGEN_25, 'file' => LAN_XMLGEN_28, 'class' => LAN_XMLGEN_34, 'function' => LAN_XMLGEN_29),
|
||||
'install' => array('rowname' => LAN_XMLGEN_17, 'when' => TRUE, 'type' => TRUE, 'file' => TRUE, 'class' => TRUE, 'function' => TRUE),
|
||||
'uninstall' => array('rowname' => LAN_XMLGEN_19, 'when' => FALSE, 'type' => TRUE, 'file' => TRUE, 'class' => TRUE, 'function' => TRUE),
|
||||
'upgrade' => array('rowname' => LAN_XMLGEN_18, 'when' => FALSE, 'type' => TRUE, 'file' => TRUE, 'class' => TRUE, 'function' => TRUE),
|
||||
'help' => array('rowname' => ' ', 'when' => ' ', 'type' => ' ', 'file' => LAN_XMLGEN_33, 'class' => LAN_XMLGEN_35, 'function' => ' ')
|
||||
);
|
||||
|
||||
|
||||
$selectOptions = array(
|
||||
'when' => array('pre' => LAN_XMLGEN_31, 'post' => LAN_XMLGEN_32),
|
||||
'type' => array('fileFunction' => LAN_XMLGEN_26, 'classFunction' => LAN_XMLGEN_27)
|
||||
);
|
||||
|
||||
|
||||
function writeTag($tag,$value,$level=1)
|
||||
{
|
||||
if (!$value) return '';
|
||||
return str_repeat(TAB_CHAR,$level)."<{$tag}>{$value}</{$tag}>\n";
|
||||
}
|
||||
|
||||
|
||||
function listPrefs($prefList, $arrayPrefList)
|
||||
{
|
||||
if (!is_array($prefList)) return '';
|
||||
$text = '';
|
||||
foreach ($prefList as $k => $v)
|
||||
{
|
||||
if (is_array($v))
|
||||
{
|
||||
$text .= TAB_CHAR.TAB_CHAR.'<pref name="'.$k.'" type="array">'."\n";
|
||||
foreach ($v as $sk => $sv)
|
||||
{
|
||||
$text .= str_repeat(TAB_CHAR,3).' <key name="'.$sk.'" value="'.$sv.'" />'."\n";
|
||||
}
|
||||
$text .= TAB_CHAR.TAB_CHAR."</pref>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$text .= TAB_CHAR.TAB_CHAR.'<pref name="'.$k.'" value="'.$v.'" />'."\n";
|
||||
}
|
||||
}
|
||||
if (!is_array($arrayPrefList)) return $text;
|
||||
foreach ($arrayPrefList as $k => $v)
|
||||
{
|
||||
$text .= TAB_CHAR.TAB_CHAR.'<array_pref name="'.$k.'" value="'.$v.'" />'."\n";
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function makeXML($pluginDir, $extras=array())
|
||||
{
|
||||
if (substr($pluginDir,-1,1) != '/') $pluginDir .= '/';
|
||||
$sourceFile = $pluginDir.'plugin.php';
|
||||
$destFile = $pluginDir.'plugin.xml';
|
||||
$backFile = $pluginDir.'plugin.bak';
|
||||
$baseFolder = substr($pluginDir,0,-1);
|
||||
echo $baseFolder;
|
||||
$baseFolder = substr($baseFolder,strrpos($baseFolder,'/')+1);
|
||||
// echo "Transcribing from {$sourceFile} to {$destFile}...<br />";
|
||||
$adminText = '';
|
||||
$mainPrefText = '';
|
||||
$manageText = '';
|
||||
$fileText = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n<e107Plugin>\n";
|
||||
|
||||
if (!is_readable($sourceFile))
|
||||
{
|
||||
return LAN_XMLGEN_10.$sourceFile."<br />";
|
||||
}
|
||||
|
||||
include_once($sourceFile);
|
||||
// Transcribe variables
|
||||
$fileText .= writeTag('name',$eplug_name);
|
||||
$fileText .= writeTag('version',$eplug_version);
|
||||
$fileText .= writeTag('author',$eplug_author);
|
||||
$fileText .= writeTag('authorUrl',$eplug_url);
|
||||
$fileText .= writeTag('authorEmail',$eplug_email);
|
||||
$fileText .= writeTag('description',$eplug_description);
|
||||
$fileText .= writeTag('compatibility',$eplug_compatible);
|
||||
$fileText .= writeTag('readMe',$eplug_readme);
|
||||
$fileText .= writeTag('installRequired',$extras['installationrequired'] ? 'true' : 'false');
|
||||
$fileText .= writeTag('folder',$baseFolder);
|
||||
foreach ($extras as $k => $v)
|
||||
{
|
||||
if (in_array($k,array('copyright','update_url'))) $fileText .= writeTag($k,$v);
|
||||
}
|
||||
$baseFolder .= '/';
|
||||
// 'commentID' tags needed
|
||||
$adminText .= writeTag('configfile',$eplug_conffile,2);
|
||||
$adminText .= writeTag('icon',str_replace($baseFolder,'',$eplug_icon),2);
|
||||
$adminText .= writeTag('iconSmall',str_replace($baseFolder,'',$eplug_icon_small),2);
|
||||
$adminText .= writeTag('caption',$eplug_caption,2);
|
||||
$adminText .= writeTag('installDone',$eplug_done,2);
|
||||
$fileText .= writeTag('administration',"\n".$adminText.TAB_CHAR);
|
||||
if (varsettrue($eplug_link) && varsettrue($eplug_link_name) && varsettrue($eplug_link_url))
|
||||
{
|
||||
$fileText .= TAB_CHAR.'<menuLink name="'.$eplug_link_name.'" url="'.str_replace(e_PLUGIN,'',$eplug_link_url).'" />'."\n";
|
||||
}
|
||||
// Could add more menuLink options
|
||||
|
||||
$fileText .= writeTag('mainPrefs',"\n".listPrefs($eplug_prefs, varset($eplug_array_pref,'')).TAB_CHAR);
|
||||
|
||||
// Could add userclasses
|
||||
|
||||
|
||||
// Management section
|
||||
$fileText .= TAB_CHAR."<management>\n";
|
||||
foreach ($extras as $k => $v)
|
||||
{
|
||||
if (in_array($k,array('install','uninstall', 'upgrade')))
|
||||
{
|
||||
$fileText .= TAB_CHAR.TAB_CHAR.'<'.$k;
|
||||
foreach (array('when','type','file','class','function') as $t)
|
||||
{
|
||||
if (isset($v[$t])) $fileText .= ' '.$t.'="'.$v[$t].'"';
|
||||
}
|
||||
$fileText .= ' />'."\n";
|
||||
}
|
||||
}
|
||||
$fileText .= TAB_CHAR."</management>\n";
|
||||
|
||||
|
||||
$fileText .= "</e107Plugin>";
|
||||
|
||||
// All assembled - write file
|
||||
if (is_readable($backFile))
|
||||
{ // Delete any existing backup
|
||||
if (!unlink($backFile))
|
||||
{
|
||||
return LAN_XMLGEN_16;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_readable($destFile))
|
||||
{ // Rename existing plugin.xml
|
||||
if (!rename($destFile,$backFile))
|
||||
{
|
||||
return LAN_XMLGEN_15;
|
||||
}
|
||||
}
|
||||
|
||||
if (($fh = fopen($destFile,'wt')) === FALSE)
|
||||
{
|
||||
return LAN_XMLGEN_09.$destFile."<br />";
|
||||
}
|
||||
if (fwrite($fh,$fileText) == FALSE)
|
||||
{
|
||||
return LAN_XMLGEN_08.$destFile."<br />";
|
||||
}
|
||||
fclose($handle);
|
||||
return LAN_XMLGEN_07; // Return success
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$HEADER = '';
|
||||
$FOOTER = '';
|
||||
require(HEADERF);
|
||||
|
||||
|
||||
$message = '';
|
||||
//========================================================
|
||||
// ACTION
|
||||
//========================================================
|
||||
if (isset($_POST['do_conversion']))
|
||||
{
|
||||
if (varset($_POST['selected_plugin'],FALSE))
|
||||
{
|
||||
$extras['copyright'] = varset($_POST['copyright'],'');
|
||||
$extras['update_url'] = varset($_POST['update_url'],'');
|
||||
$extras['installationrequired'] = varset($_POST['installationrequired'],1);
|
||||
|
||||
|
||||
// Calculate the array of management features
|
||||
foreach ($managementOptions as $k => $v)
|
||||
{
|
||||
if ($k == 'headings') continue;
|
||||
foreach ($v as $r => $s)
|
||||
{
|
||||
$el_name = $k.'_'.$r;
|
||||
if (isset($_POST[$el_name]))
|
||||
{
|
||||
switch ($r)
|
||||
{
|
||||
case 'rowname' : // Shouldn't happen - but allow for it in case
|
||||
case 'help' :
|
||||
break;
|
||||
case 'when' :
|
||||
$extras[$k][$r] = $_POST[$el_name];
|
||||
break;
|
||||
case 'type' :
|
||||
$extras[$k][$r] = $_POST[$el_name];
|
||||
break;
|
||||
case 'file' :
|
||||
$extras[$k][$r] = $_POST[$el_name];
|
||||
if (strtolower(substr($extras[$k][$r],-4)) != '.php') $extras[$k][$r].= '.php';
|
||||
break;
|
||||
case 'function' :
|
||||
case 'class' :
|
||||
$extras[$k][$r] = $_POST[$el_name];
|
||||
// switch ($extras[$k]['type'])
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$message = LAN_XMLGEN_06.e_PLUGIN.$_POST['selected_plugin']."<br />";
|
||||
$message .= makeXML(e_PLUGIN.$_POST['selected_plugin'], $extras);
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = LAN_XMLGEN_05;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//========================================================
|
||||
// FORM
|
||||
//========================================================
|
||||
$text =
|
||||
"<div style='text-align:center; width:700px'>
|
||||
<form method='post' action='".e_SELF."'>
|
||||
<table style='width:95%' class='fborder'>
|
||||
<colgroup>
|
||||
<col style='width:60%' />
|
||||
<col style='width:40%' />
|
||||
</colgroup>";
|
||||
|
||||
if ($message)
|
||||
{
|
||||
$text .= "<tr>
|
||||
<td colspan='2' class='forumheader3' style='text-align:center'>".$message."
|
||||
</td>
|
||||
</tr>";
|
||||
}
|
||||
|
||||
$text .= "<tr>
|
||||
<td colspan='2' class='forumheader3' style='text-align:center'>".LAN_XMLGEN_01."<br /><span class='smallblacktext'>".LAN_XMLGEN_14."</span></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class='forumheader3'>".LAN_XMLGEN_04."</td>
|
||||
<td class='forumheader3'>".genFileSelect('selected_plugin',$pluginList)."
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class='forumheader3'>".LAN_XMLGEN_11."<br /><span class='smallblacktext'>".LAN_XMLGEN_13."</span></td>
|
||||
<td class='forumheader3'>
|
||||
<input class='tbox' type='text' size='60' maxlength='100' name='copyright' value='' />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class='forumheader3'>".LAN_XMLGEN_12."<br /><span class='smallblacktext'>".LAN_XMLGEN_13."</span></td>
|
||||
<td class='forumheader3'>
|
||||
<input class='tbox' type='text' size='60' maxlength='150' name='update_url' value='' />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class='forumheader3'>".LAN_XMLGEN_21."</td>
|
||||
<td class='forumheader3'>
|
||||
<select name='installationrequired'>\n
|
||||
<option value='1' selected='selected'>".LAN_XMLGEN_23."</option>\n
|
||||
<option value='0'>".LAN_XMLGEN_24."</option>\n
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
<tr><td class='forumheader3'>".LAN_XMLGEN_20."<br /><span class='smallblacktext'>".LAN_XMLGEN_22."</span></td><td class='forumheader3'>
|
||||
|
||||
<table>";
|
||||
foreach ($managementOptions as $k => $v)
|
||||
{
|
||||
$text .= "<tr>";
|
||||
foreach ($v as $r => $s)
|
||||
{
|
||||
if ($k == 'headings')
|
||||
{
|
||||
$text .= '<td>'.$s.'</td>';
|
||||
}
|
||||
elseif ($k == 'help')
|
||||
{
|
||||
$text .= "<td><span class='smallblacktext'>".$s.'</span></td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$el_name = $k.'_'.$r;
|
||||
switch ($r)
|
||||
{
|
||||
case 'rowname' :
|
||||
$text .= '<td>'.$s.'</td>';
|
||||
break;
|
||||
case 'when' :
|
||||
case 'type' :
|
||||
if (!$s)
|
||||
{
|
||||
$text .= '<td> </td>';
|
||||
break;
|
||||
}
|
||||
$text .= "<td><select name='{$el_name}' class='tbox'>\n";
|
||||
foreach ($selectOptions[$r] as $o => $t)
|
||||
{
|
||||
$text .= "<option value='{$o}'>{$t}</option>\n";
|
||||
}
|
||||
$text .= "</select>\n</td>";
|
||||
break;
|
||||
case 'file' :
|
||||
case 'function' :
|
||||
case 'class' :
|
||||
$text .= "<td>
|
||||
<input class='tbox' type='text' size='30' maxlength='60' name='{$el_name}' value='' />
|
||||
</td>";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$text .= "</tr>";
|
||||
}
|
||||
|
||||
|
||||
$text .= "</table></td></tr>
|
||||
";
|
||||
|
||||
|
||||
$text .= "
|
||||
<tr>
|
||||
<td class='forumheader3' colspan='3' style='text-align:center'>
|
||||
<input class='button' type='submit' name='do_conversion' value='".LAN_XMLGEN_03."' />
|
||||
</td>
|
||||
</tr>";
|
||||
|
||||
|
||||
$text .= "
|
||||
</table>\n
|
||||
</form>
|
||||
</div><br />";
|
||||
$ns->tablerender(LAN_XMLGEN_02, $text);
|
||||
|
||||
require(FOOTERF);
|
||||
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user