From 458d5adba93e77b21b2961382452ba61cd7736fa Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 2 Nov 2017 19:44:48 -0700 Subject: [PATCH] Issue #2837 Plugin Builder enhancements and fixes. --- e107_admin/plugin.php | 185 ++++++++++++++++---- e107_languages/English/admin/lan_plugin.php | 4 +- 2 files changed, 155 insertions(+), 34 deletions(-) diff --git a/e107_admin/plugin.php b/e107_admin/plugin.php index 00d7a3bc2..73947c28b 100644 --- a/e107_admin/plugin.php +++ b/e107_admin/plugin.php @@ -3541,7 +3541,7 @@ class pluginBuilder ".EPL_ADLAN_107." -
".$frm->open('createPlugin','get',e_SELF."?mode=create").$frm->select("newplugin",$newDir, false, 'size=xlarge').$frm->admin_button('step', 2,'other',LAN_GO)."
".$frm->checkbox('createFiles',1,1,EPL_ADLAN_232).$frm->close()." +
".$frm->open('createPlugin','get',e_SELF."?mode=create").$frm->select("newplugin",$newDir, false, 'size=xlarge').$frm->admin_button('step', 2,'other',LAN_GO)."
".$frm->checkbox('createFiles',1,1,EPL_ADLAN_255).$frm->close()."
".$info."
@@ -3610,7 +3610,7 @@ class pluginBuilder { $createData = str_replace("`".MPREFIX, '`', $data[1]); $createData .= ";"; - if(!file_exists($file)) + if(!file_exists($file) && empty($this->createFiles)) { file_put_contents($file,$createData); } @@ -3813,7 +3813,121 @@ class pluginBuilder + private function buildTemplateFile() + { + $dirName = e_PLUGIN.$this->pluginName. "/templates"; + if(!is_dir($dirName)) + { + mkdir($dirName,0755); + } + + + $file = $dirName. "/".$this->pluginName."_template.php"; + $shortFileName = "templates/".$this->pluginName."_template.php"; + + if(file_exists($file) && empty($this->createFiles)) + { + return e107::getParser()->lanVars(EPL_ADLAN_256,$shortFileName); + } + + +$content = <<pluginName); + +$content .= " +// ".$this->pluginName." Template file + +if (!defined('e107_INIT')) { exit; } + + +\$".$upperName."_TEMPLATE = array(); + +\$".$upperName."_TEMPLATE['default']['start'] \t= '{SETIMAGE: w=400&h=300}'; + +\$".$upperName."_TEMPLATE['default']['item'] \t= ''; + +\$".$upperName."_TEMPLATE['default']['end'] \t= ''; + + + +"; + + + return file_put_contents($file,$content)? LAN_CREATED.': '.$shortFileName : LAN_CREATED_FAILED.': '.$shortFileName; + } + + + + + + private function buildShortcodesFile() + { + $file = e_PLUGIN.$this->pluginName. "/".$this->pluginName."_shortcodes.php"; + +$content = <<pluginName." Shortcodes file + +if (!defined('e107_INIT')) { exit; } + +class plugin_".$this->pluginName."_shortcodes extends e_shortcode +{ + +"; + + if(!empty($_POST['bullets_ui']['fields'])) + { + foreach($_POST['bullets_ui']['fields'] as $key=>$row) + { + + if($key === 'options' || $key === 'checkboxes') + { + continue; + } + +$content .= " + /** + * {".strtoupper($key)."} + */ + public function sc_".$key."(\$parm=null) + { + + return \$this->var['".$key."']; + } + + +"; + + + + + + + + + + + } + + + } + + + + + return file_put_contents($file,$content)? LAN_CREATED.': '.$this->pluginName."_shortcodes.php" : LAN_CREATED_FAILED.': '.$this->pluginName."_shortcodes.php"; + } private function createAddons($list) @@ -3828,9 +3942,21 @@ class pluginBuilder $source = e_PLUGIN."_blank/".$addon.".php"; $destination = e_PLUGIN.$this->pluginName. "/".$addonDest.".php"; - if(file_exists($destination)) + if(file_exists($destination) && empty($this->createFiles)) { - $result[] = "Skipped (already exists) : ".$addonDest; + $result[] = e107::getParser()->lanVars(EPL_ADLAN_256,$addonDest.'.php'); + continue; + } + + if($addon === '_blank_template') + { + $result[] = $this->buildTemplateFile(); + continue; + } + + if($addon === '_blank_shortcodes') + { + $result[] = $this->buildShortcodesFile(); continue; } @@ -3838,16 +3964,16 @@ class pluginBuilder { $content = str_replace($srch, $this->pluginName, $content); - if(!file_exists($destination)) + if(file_exists($destination) && empty($this->createFiles)) { - if(file_put_contents($destination,$content)) - { - $result[] = LAN_CREATED." : ".$addonDest; - } + $result[] = e107::getParser()->lanVars(EPL_ADLAN_256,$addonDest.'.php'); } else { - $result[] = "Skipped (already exists) : ".$addonDest; + if(file_put_contents($destination,$content)) + { + $result[] = LAN_CREATED." : ".$addonDest.".php"; + } } } else @@ -3876,10 +4002,12 @@ class pluginBuilder $dizOther = array( '_blank' => "Simple frontend script", '_blank_setup' => "Create default table data during install, upgrade, uninstall etc", - '_blank_menu' => "Menu item for use in the menu manager." + '_blank_menu' => "Menu item for use in the menu manager.", + '_blank_template' => "Template to allow layout customization by themes.", + '_blank_shortcodes' => "Shortcodes for the template." ); - array_unshift($list,'_blank', '_blank_setup', '_blank_menu'); + array_unshift($list,'_blank', '_blank_setup', '_blank_menu', '_blank_template', '_blank_shortcodes'); $templateFiles = scandir(e_PLUGIN."_blank"); @@ -3892,7 +4020,7 @@ class pluginBuilder foreach($list as $v) { - if(!in_array($v.".php", $templateFiles)) + if(!in_array($v.".php", $templateFiles) && $v != '_blank_template' && $v!='_blank_shortcodes') { continue; } @@ -4358,7 +4486,12 @@ TEMPLATE; $result = e107::getParser()->simpleParse($template, $newArray); $path = e_PLUGIN.$this->pluginName."/plugin.xml"; - + if(file_exists($path) && empty($this->createFiles)) + { + return htmlentities($result); + } + + if($this->createFiles == true) { if(file_put_contents($path,$result) ) @@ -5259,7 +5392,12 @@ exit; } } - if($this->createFiles == true) + if(file_exists($generatedFile) && empty($this->createFiles)) + { + $message = e107::getParser()->lanVars(EPL_ADLAN_256,"admin_config.php"); + $mes->addSuccess($message); + } + else { if(file_put_contents($generatedFile, $startPHP .$text . $endPHP)) { @@ -5271,15 +5409,7 @@ exit; $mes->addError(str_replace('[x]', $generatedFile, EPL_ADLAN_218)); } } - else - { - $mes->addSuccess(EPL_ADLAN_219); - } - - - - // echo $mes->render(); $ret = "

plugin.xml

"; @@ -5288,16 +5418,7 @@ exit; $ret .= "
".$text."
"; return array('caption'=>EPL_ADLAN_253, 'text'=> $ret); - - // $text =$ns->tablerender(ADLAN_98.SEP.EPL_ADLAN_114.SEP." plugin.xml", "
".$xmlText."
", 'default', true); - - - - $text .= $ns->tablerender("admin_config.php", "
".$text."
"); - - // - return; } } diff --git a/e107_languages/English/admin/lan_plugin.php b/e107_languages/English/admin/lan_plugin.php index 50483d437..7cdced0f0 100644 --- a/e107_languages/English/admin/lan_plugin.php +++ b/e107_languages/English/admin/lan_plugin.php @@ -309,7 +309,7 @@ define("LAN_UNINSTALL_FAIL", "Unable to uninstall!"); define("LAN_PLUGIN_IS_USED", "[x] plugin is used by:"); define("EPL_ADLAN_254", "This will check your plugin's language files for errors and common or duplicate LAN definitions. "); +define("EPL_ADLAN_255", "Overwrite Files"); +define("EPL_ADLAN_256", "Skipped [x] (already exists)"); - -?> \ No newline at end of file