From 1ddcffcadb22942e13cf36b7a83366d336997e05 Mon Sep 17 00:00:00 2001 From: e107steved Date: Tue, 1 Jul 2008 20:49:50 +0000 Subject: [PATCH] First cut of utility to convert plugin.php to plugin.xml (for McFly to break) --- e107_files/utilities/pluginxmlgen.php | 449 ++++++++++++++++++++++++++ 1 file changed, 449 insertions(+) create mode 100644 e107_files/utilities/pluginxmlgen.php diff --git a/e107_files/utilities/pluginxmlgen.php b/e107_files/utilities/pluginxmlgen.php new file mode 100644 index 000000000..6f0a98461 --- /dev/null +++ b/e107_files/utilities/pluginxmlgen.php @@ -0,0 +1,449 @@ +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 = "\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}\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.''."\n"; + foreach ($v as $sk => $sv) + { + $text .= str_repeat(TAB_CHAR,3).' '."\n"; + } + $text .= TAB_CHAR.TAB_CHAR."\n"; + } + else + { + $text .= TAB_CHAR.TAB_CHAR.''."\n"; + } + } + if (!is_array($arrayPrefList)) return $text; + foreach ($arrayPrefList as $k => $v) + { + $text .= TAB_CHAR.TAB_CHAR.''."\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}...
"; + $adminText = ''; + $mainPrefText = ''; + $manageText = ''; + $fileText = "\n\n"; + + if (!is_readable($sourceFile)) + { + return LAN_XMLGEN_10.$sourceFile."
"; + } + + 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.''."\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."\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."\n"; + + + $fileText .= "
"; + + // 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."
"; + } + if (fwrite($fh,$fileText) == FALSE) + { + return LAN_XMLGEN_08.$destFile."
"; + } + 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']."
"; + $message .= makeXML(e_PLUGIN.$_POST['selected_plugin'], $extras); + } + else + { + $message = LAN_XMLGEN_05; + } +} + + + +//======================================================== +// FORM +//======================================================== +$text = + "
+
+ + + + + "; + +if ($message) +{ + $text .= " + + "; +} + +$text .= " + + + + + + + + + + + + + + + + + + + + + + + + + + + "; + + + $text .= " + + + "; + + +$text .= " +
".$message." +
".LAN_XMLGEN_01."
".LAN_XMLGEN_14."
".LAN_XMLGEN_04."".genFileSelect('selected_plugin',$pluginList)." +
".LAN_XMLGEN_11."
".LAN_XMLGEN_13."
+ +
".LAN_XMLGEN_12."
".LAN_XMLGEN_13."
+ +
".LAN_XMLGEN_21." + +
".LAN_XMLGEN_20."
".LAN_XMLGEN_22."
+ + "; +foreach ($managementOptions as $k => $v) +{ + $text .= ""; + foreach ($v as $r => $s) + { + if ($k == 'headings') + { + $text .= ''; + } + elseif ($k == 'help') + { + $text .= "'; + } + else + { + $el_name = $k.'_'.$r; + switch ($r) + { + case 'rowname' : + $text .= ''; + break; + case 'when' : + case 'type' : + if (!$s) + { + $text .= ''; + break; + } + $text .= ""; + break; + case 'file' : + case 'function' : + case 'class' : + $text .= ""; + break; + } + } + } + $text .= ""; +} + + +$text .= "
'.$s.'".$s.''.$s.' \n + +
+ +
\n +
+

"; + $ns->tablerender(LAN_XMLGEN_02, $text); + +require(FOOTERF); + + +?>