diff --git a/e107_admin/plugin.php b/e107_admin/plugin.php index 3a52e10ce..d6f877e1d 100755 --- a/e107_admin/plugin.php +++ b/e107_admin/plugin.php @@ -422,7 +422,8 @@ class plugin_ui extends e_admin_ui function buildPage() { - $pc = new pluginBuilder; + require_once(e_HANDLER."e_pluginbuilder_class.php"); + $pc = new e_pluginbuilder; $ret = $pc->run(); if(is_array($ret)) @@ -2489,2223 +2490,3 @@ require_once("footer.php"); -/** - * Plugin Admin Generator by CaMer0n. //TODO - Added dummy template and shortcode creation, plus e_search, e_cron, e_xxxxx etc. - */ -class pluginBuilder -{ - - var $fields = array(); - var $table = ''; - var $pluginName = ''; - var $special = array(); - var $tableCount = 0; - var $tableList = array(); - var $createFiles = false; - private $buildTable = false; - private $debug = false; - - function __construct() - { - - if(e_DEBUG == true) - { - $this->debug = true; - } - - $this->special['checkboxes'] = array('title'=> '','type' => null, 'data' => null, 'width'=>'5%', 'thclass' =>'center', 'forced'=> TRUE, 'class'=>'center', 'toggle' => 'e-multiselect', 'fieldpref'=>true); - $this->special['options'] = array( 'title'=> 'LAN_OPTIONS', 'type' => null, 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced'=>TRUE, 'fieldpref'=>true); - - - } - - - function run() - { - - if(!empty($_GET['newplugin'])) - { - $this->pluginName = e107::getParser()->filter($_GET['newplugin'],'file'); - } - - if(!empty($_GET['createFiles'])) - { - $this->createFiles = true; - } - - if(vartrue($_POST['step']) == 4) - { - return $this->step4(); - } - - if(vartrue($_GET['step']) == 3) - { - return $this->step3(); - } - - - - - if(!empty($_GET['newplugin']) && $_GET['step']==2) - { - return $this->step2(); - } - - - - return $this->step1(); - - - } - - - - function step1() - { - - $fl = e107::getFile(); - $frm = e107::getForm(); - $ns = e107::getRender(); - $mes = e107::getMessage(); - $tp = e107::getParser(); - - $newDir = []; - $lanDir = []; - - $plugFolders = $fl->get_dirs(e_PLUGIN); - foreach($plugFolders as $dir) - { - $lanDir[$dir] = $dir; - if(E107_DEBUG_LEVEL == 0 && file_exists(e_PLUGIN.$dir."/admin_config.php")) - { - continue; - } - $newDir[$dir] = $dir; - } - - - $info = EPL_ADLAN_102; - $info .= "
".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_255).$frm->close()." |
- ".$info." |
-
".EPL_ADLAN_108." | -".$frm->open('checkPluginLangs','get',e_SELF."?mode=lans").$frm->select("newplugin",$lanDir, false, 'size=xlarge').$frm->admin_button('step', 2,'other',LAN_GO)." ".$frm->close()." |
- ".EPL_ADLAN_254." |
-
Pasted MySql Dump Here | -".$frm->textarea('mysql','', 10,80)." - eg. | -
".ucfirst(LAN_OPTIONAL)." | |
To generate your ".$this->pluginName."_sql.php table creation file, please select your sql table then click 'Refresh' | -"; - - $text .= $frm->select('build', $tables, null, array('useValues'=>1), "(".LAN_OPTIONAL.")"); - - - // $text .= "Refresh"; - // $text .= $frm->button('step', 3, 'submit', "Continue"); - unset($_GET['step']); - foreach($_GET as $k=>$v) - { - $text .= $frm->hidden($k,$v); - - } - // $text .= $frm->hidden("build_table_url", e_REQUEST_SELF.'?'.$qry, array('id'=>'build-table-url')); - - - $text .= " |
- ".$frm->button('step', 3, 'submit', LAN_CONTINUE)." - |
".$frm->checkbox('addons[]',$v,false,$label)." | "; - $text .= ""; - $text .= " |
". - $frm->text("pluginPrefs[".$i."][index]", '',40,'placeholder='.EPL_ADLAN_129)." | ". - $frm->text("pluginPrefs[".$i."][value]", '',50,'placeholder='.EPL_ADLAN_130)." | ". - $frm->select("pluginPrefs[".$i."][type]", $options, '', 'class=null', EPL_ADLAN_131)." | ". - $frm->text("pluginPrefs[".$i."][help]", '',80,'size=xxlarge&placeholder='.EPL_ADLAN_174)." | ". - "
$key |
- ";
- foreach($val as $type)
- {
- $nm = $key.'-'.$type;
- $name = "xml[$nm]";
- $size = (count($val)==1) ? 'span7 col-md-7' : 'span2 col-md-2';
- $text .= " ".$this->xmlInput($name, $key."-". $type, vartrue($defaults[$nm]))." ";
- }
-
- $text .= " |
".htmlentities($result).""); - } - - - - - - - function form($table,$fieldArray) - { - - $frm = e107::getForm(); - - $modes = array( - "main" => EPL_ADLAN_157, - "cat" => EPL_ADLAN_158, - "other1" => EPL_ADLAN_159, - "other2" => EPL_ADLAN_160, - "other3" => EPL_ADLAN_161, - "other4" => EPL_ADLAN_162, - 'exclude' => EPL_ADLAN_163, - ); - - // echo "TABLE COUNT= ".$this->tableCount ; - - - $this->table = $table."_ui"; - - $c=0; - foreach($modes as $id=>$md) - { - if($tbl = varset($this->tableList[$c], false)) - { - $defaultMode[$tbl] = $id; - $c++; - } - } - - // print_a($defaultMode); - - $text = $frm->hidden($this->table.'[pluginName]', $this->pluginName, 15). - $frm->hidden($this->table.'[table]', $table, 15); - - if($this->tableCount > 1) - { - $text .= "
Mode | -".$frm->select($this->table."[mode]",$modes, $defaultMode[$table], 'required=1&class=null', true)." | -
".EPL_ADLAN_164." | -".EPL_ADLAN_165." | -".EPL_ADLAN_166." | -".EPL_ADLAN_167." | -".EPL_ADLAN_168." | -".EPL_ADLAN_169." | -".EPL_ADLAN_170." | -".EPL_ADLAN_171." | -".EPL_ADLAN_172." | -".EPL_ADLAN_173." | -R/O | - -".EPL_ADLAN_174." | -".EPL_ADLAN_175." | -".EPL_ADLAN_176." | -
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
".$name." | -".$frm->text($this->table."[fields][".$name."][title]", $this->guess($name, $val,'title'),35, 'required=1')." | -".$this->fieldType($name, $val)." | -".$this->fieldData($name, $val)." | -".$frm->text($this->table."[fields][".$name."][width]", $this->guess($name, $val,'width'), 4, 'size=mini')." | -".$frm->checkbox($this->table."[fields][".$name."][batch]", true, $this->guess($name, $val,'batch'))." | -".$frm->checkbox($this->table."[fields][".$name."][filter]", true, $this->guess($name, $val,'filter'))." | -".$frm->checkbox($this->table."[fields][".$name."][inline]", true, $this->guess($name, $val,'inline'))." | -".$frm->checkbox($this->table."[fields][".$name."][validate]", true)." | -".$frm->checkbox($this->table."[fields][".$name."][fieldpref]", true, $this->guess($name, $val,'fieldpref'))." | -".$frm->checkbox($this->table."[fields][".$name."][readonly]", true)." | -".$frm->text($this->table."[fields][".$name."][help]",'', 50,'size=medium')." | -".$frm->text($this->table."[fields][".$name."][readParms]",'', 60,'size=small')." | -".$frm->text($this->table."[fields][".$name."][writeParms]",'', 60,'size=small'). - $frm->hidden($this->table."[fields][".$name."][class]", $this->guess($name, $val,'class')). - $frm->hidden($this->table."[fields][".$name."][thclass]", $this->guess($name, $val,'thclass')). - " | -
".$xmlText.""; - $ret .= "
".$text.""; - - e107::getPlug()->clearCache(); - - return array('caption'=>EPL_ADLAN_253, 'text'=> $ret); - - - } - - - /** - * @param array $fields - * @param string $table - * @param string $type - * @return string - */ - private function buildAdminUIBatchFilter($fields, $table, $type='batch') - { - $text = ''; - - $typeUpper = ucfirst($type); - - $params = ($type === 'batch') ? "\$selected, \$type" : "\$type"; - - foreach($fields as $fld=>$val) - { - if(varset($val['type']) !== 'method') - { - continue; - } - - - - $text .= " - - // Handle ".$type." options as defined in ".str_replace("_ui", "_form_ui", $table)."::".$fld."; 'handle' + action + field + '".$typeUpper."' - // @important \$fields['".$fld."']['".$type."'] must be true for this method to be detected. - // @param \$selected - // @param \$type - function handleList".eHelper::camelize($fld,true).$typeUpper."(".$params.") - { -"; - - if($type === 'filter') - { - $text .= " - \$this->listOrder = '".$fld." ASC'; - "; - - } - else - { - $text .= " - \$ids = implode(',', \$selected);\n"; - - } - -$text .= " - switch(\$type) - { - case 'custom".$type."_1': -"; - -$text .= ($type === 'batch') ? " // do something" : " // return ' ".$fld." != 'something' '; "; - - -$text .= " - e107::getMessage()->addSuccess('Executed custom".$type."_1'); - break; - - case 'custom".$type."_2': -"; - -$text .= ($type === 'batch') ? " // do something" : " // return ' ".$fld." != 'something' '; "; - -$text .= " - e107::getMessage()->addSuccess('Executed custom".$type."_2'); - break; - - } - - - } -"; - } - - - return $text; - - } - - - /** - * @param array $vars - * @return null|string|string[] - */ - private function buildAdminUIFields($vars) - { - $srch = array( - - "\n", - // "),", - " ", - "'forced' => '1'", - "'batch' => '1'", - "'filter' => '1'", - "'batch' => '0'", - "'filter' => '0'", - "'inline' => '1'", - "'validate' => '1'", - "'readonly' => '1'", - // ", 'fieldpref' => '1'", - "'type' => ''", - "'data' => ''", - " array ( )", - ); - - $repl = array( - - "", - // "),\n\t\t", - " ", - "'forced' => true", - "'batch' => true", - "'filter' => true", - "'batch' => false", - "'filter' => false", - "'inline' => true", - "'validate' => true", - "'readonly' => true", - // "", - "'type' => null", - "'data' => null", - "array ()" - ); - - - - foreach($vars['fields'] as $key=>$val) - { - - if(($val['type'] === 'dropdown' || $val['type'] === 'method') && empty($val['filter'])) - { - $vars['fields'][$key]['filter'] = '0'; - } - - if(($val['type'] === 'dropdown' || $val['type'] === 'method') && empty($val['batch'])) - { - $vars['fields'][$key]['batch'] = '0'; - } - - if($val['type'] == 'image' && empty($val['readParms'])) - { - $vars['fields'][$key]['readParms'] = 'thumb=80x80'; // provide a thumbnail preview by default. - } - - if(empty($vars['fields'][$key]['readParms'])) - { - $vars['fields'][$key]['readParms'] = array(); - } - - if(empty($vars['fields'][$key]['writeParms'])) - { - $vars['fields'][$key]['writeParms'] = array(); - } - - - unset($vars['fields'][$key]['fieldpref']); - - } - - $FIELDS = "array (\n"; - - foreach($vars['fields'] as $key=>$val) - { - $FIELDS .= "\t\t\t'".str_pad($key."'",25," ")."=> ".str_replace($srch,$repl,var_export($val,true)).",\n"; - } - - $FIELDS .= "\t\t)"; - - // $FIELDS = var_export($vars['fields'],true); - // $FIELDS = str_replace($srch,$repl,var_export($vars['fields'],true)); - $FIELDS = preg_replace("#('([A-Z0-9_]*?LAN[_A-Z0-9]*)')#","$2",$FIELDS); // remove quotations from LANs. - - - return $FIELDS; - - - - - } - - - - -} \ No newline at end of file diff --git a/e107_handlers/e_pluginbuilder_class.php b/e107_handlers/e_pluginbuilder_class.php new file mode 100644 index 000000000..49e97ad3f --- /dev/null +++ b/e107_handlers/e_pluginbuilder_class.php @@ -0,0 +1,2235 @@ +debug = true; + } + + $this->special['checkboxes'] = array('title'=> '','type' => null, 'data' => null, 'width'=>'5%', 'thclass' =>'center', 'forced'=> TRUE, 'class'=>'center', 'toggle' => 'e-multiselect', 'fieldpref'=>true); + $this->special['options'] = array( 'title'=> 'LAN_OPTIONS', 'type' => null, 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced'=>TRUE, 'fieldpref'=>true); + + + } + + + function run() + { + + if(!empty($_GET['newplugin'])) + { + $this->pluginName = e107::getParser()->filter($_GET['newplugin'],'file'); + } + + if(!empty($_GET['createFiles'])) + { + $this->createFiles = true; + } + + if(vartrue($_POST['step']) == 4) + { + return $this->step4(); + } + + if(vartrue($_GET['step']) == 3) + { + return $this->step3(); + } + + + + + if(!empty($_GET['newplugin']) && $_GET['step']==2) + { + return $this->step2(); + } + + + + return $this->step1(); + + + } + + + + function step1() + { + + $fl = e107::getFile(); + $frm = e107::getForm(); + $ns = e107::getRender(); + $mes = e107::getMessage(); + $tp = e107::getParser(); + + $newDir = []; + $lanDir = []; + + $plugFolders = $fl->get_dirs(e_PLUGIN); + foreach($plugFolders as $dir) + { + $lanDir[$dir] = $dir; + if(E107_DEBUG_LEVEL == 0 && file_exists(e_PLUGIN.$dir."/admin_config.php")) + { + continue; + } + $newDir[$dir] = $dir; + } + + + $info = EPL_ADLAN_102; + $info .= "
".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_255).$frm->close()." |
+ ".$info." |
+
".EPL_ADLAN_108." | +".$frm->open('checkPluginLangs','get',e_SELF."?mode=lans").$frm->select("newplugin",$lanDir, false, 'size=xlarge').$frm->admin_button('step', 2,'other',LAN_GO)." ".$frm->close()." |
+ ".EPL_ADLAN_254." |
+
Pasted MySql Dump Here | +".$frm->textarea('mysql','', 10,80)." + eg. | +
".ucfirst(LAN_OPTIONAL)." | |
To generate your ".$this->pluginName."_sql.php table creation file, please select your sql table then click 'Refresh' | +"; + + $text .= $frm->select('build', $tables, null, array('useValues'=>1), "(".LAN_OPTIONAL.")"); + + + // $text .= "Refresh"; + // $text .= $frm->button('step', 3, 'submit', "Continue"); + unset($_GET['step']); + foreach($_GET as $k=>$v) + { + $text .= $frm->hidden($k,$v); + + } + // $text .= $frm->hidden("build_table_url", e_REQUEST_SELF.'?'.$qry, array('id'=>'build-table-url')); + + + $text .= " |
+ ".$frm->button('step', 3, 'submit', LAN_CONTINUE)." + |
".$frm->checkbox('addons[]',$v,false,$label)." | "; + $text .= ""; + $text .= " |
". + $frm->text("pluginPrefs[".$i."][index]", '',40,'placeholder='.EPL_ADLAN_129)." | ". + $frm->text("pluginPrefs[".$i."][value]", '',50,'placeholder='.EPL_ADLAN_130)." | ". + $frm->select("pluginPrefs[".$i."][type]", $options, '', 'class=null', EPL_ADLAN_131)." | ". + $frm->text("pluginPrefs[".$i."][help]", '',80,'size=xxlarge&placeholder='.EPL_ADLAN_174)." | ". + "
$key |
+ ";
+ foreach($val as $type)
+ {
+ $nm = $key.'-'.$type;
+ $name = "xml[$nm]";
+ $size = (count($val)==1) ? 'span7 col-md-7' : 'span2 col-md-2';
+ $text .= " ".$this->xmlInput($name, $key."-". $type, vartrue($defaults[$nm]))." ";
+ }
+
+ $text .= " |
".htmlentities($result).""); + } + + + + + + + function form($table,$fieldArray) + { + + $frm = e107::getForm(); + + $modes = array( + "main" => EPL_ADLAN_157, + "cat" => EPL_ADLAN_158, + "other1" => EPL_ADLAN_159, + "other2" => EPL_ADLAN_160, + "other3" => EPL_ADLAN_161, + "other4" => EPL_ADLAN_162, + 'exclude' => EPL_ADLAN_163, + ); + + // echo "TABLE COUNT= ".$this->tableCount ; + + + $this->table = $table."_ui"; + + $c=0; + foreach($modes as $id=>$md) + { + if($tbl = varset($this->tableList[$c], false)) + { + $defaultMode[$tbl] = $id; + $c++; + } + } + + // print_a($defaultMode); + + $text = $frm->hidden($this->table.'[pluginName]', $this->pluginName, 15). + $frm->hidden($this->table.'[table]', $table, 15); + + if($this->tableCount > 1) + { + $text .= "
Mode | +".$frm->select($this->table."[mode]",$modes, $defaultMode[$table], 'required=1&class=null', true)." | +
".EPL_ADLAN_164." | +".EPL_ADLAN_165." | +".EPL_ADLAN_166." | +".EPL_ADLAN_167." | +".EPL_ADLAN_168." | +".EPL_ADLAN_169." | +".EPL_ADLAN_170." | +".EPL_ADLAN_171." | +".EPL_ADLAN_172." | +".EPL_ADLAN_173." | +R/O | + +".EPL_ADLAN_174." | +".EPL_ADLAN_175." | +".EPL_ADLAN_176." | +
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
".$name." | +".$frm->text($this->table."[fields][".$name."][title]", $this->guess($name, $val,'title'),35, 'required=1')." | +".$this->fieldType($name, $val)." | +".$this->fieldData($name, $val)." | +".$frm->text($this->table."[fields][".$name."][width]", $this->guess($name, $val,'width'), 4, 'size=mini')." | +".$frm->checkbox($this->table."[fields][".$name."][batch]", 1, $this->guess($name, $val,'batch'))." | +".$frm->checkbox($this->table."[fields][".$name."][filter]", 1, $this->guess($name, $val,'filter'))." | +".$frm->checkbox($this->table."[fields][".$name."][inline]", 1, $this->guess($name, $val,'inline'))." | +".$frm->checkbox($this->table."[fields][".$name."][validate]", 1)." | +".$frm->checkbox($this->table."[fields][".$name."][fieldpref]", 1, $this->guess($name, $val,'fieldpref'))." | +".$frm->checkbox($this->table."[fields][".$name."][readonly]", 1)." | +".$frm->text($this->table."[fields][".$name."][help]",'', 50,'size=medium')." | +".$frm->text($this->table."[fields][".$name."][readParms]",'', 60,'size=small')." | +".$frm->text($this->table."[fields][".$name."][writeParms]",'', 60,'size=small'). + $frm->hidden($this->table."[fields][".$name."][class]", $this->guess($name, $val,'class')). + $frm->hidden($this->table."[fields][".$name."][thclass]", $this->guess($name, $val,'thclass')). + " | +
".$xmlText.""; + $ret .= "
".$text.""; + + e107::getPlug()->clearCache(); + + return array('caption'=>EPL_ADLAN_253, 'text'=> $ret); + + + } + + + /** + * @param array $fields + * @param string $table + * @param string $type + * @return string + */ + private function buildAdminUIBatchFilter($fields, $table, $type=null) + { + $text = ''; + + $typeUpper = ucfirst($type); + + $params = ($type === 'batch') ? "\$selected, \$type" : "\$type"; + + foreach($fields as $fld=>$val) + { + if(varset($val['type']) !== 'method') + { + continue; + } + + + + $text .= " + + // Handle ".$type." options as defined in ".str_replace("_ui", "_form_ui", $table)."::".$fld."; 'handle' + action + field + '".$typeUpper."' + // @important \$fields['".$fld."']['".$type."'] must be true for this method to be detected. + // @param \$selected + // @param \$type + function handleList".eHelper::camelize($fld,true).$typeUpper."(".$params.") + { +"; + + if($type === 'filter') + { + $text .= " + \$this->listOrder = '".$fld." ASC'; + "; + + } + else + { + $text .= " + \$ids = implode(',', \$selected);\n"; + + } + +$text .= " + switch(\$type) + { + case 'custom".$type."_1': +"; + +$text .= ($type === 'batch') ? " // do something" : " // return ' ".$fld." != 'something' '; "; + + +$text .= " + e107::getMessage()->addSuccess('Executed custom".$type."_1'); + break; + + case 'custom".$type."_2': +"; + +$text .= ($type === 'batch') ? " // do something" : " // return ' ".$fld." != 'something' '; "; + +$text .= " + e107::getMessage()->addSuccess('Executed custom".$type."_2'); + break; + + } + + + } +"; + } + + + return $text; + + } + + + /** + * @param array $vars + * @return null|string|string[] + */ + private function buildAdminUIFields($vars) + { + $srch = array( + + "\n", + // "),", + " ", + "'forced' => '1'", + "'batch' => '1'", + "'filter' => '1'", + "'batch' => '0'", + "'filter' => '0'", + "'inline' => '1'", + "'validate' => '1'", + "'readonly' => '1'", + // ", 'fieldpref' => '1'", + "'type' => ''", + "'data' => ''", + " array ( )", + ' ', + ); + + $repl = array( + + "", + // "),\n\t\t", + " ", + "'forced' => true", + "'batch' => true", + "'filter' => true", + "'batch' => false", + "'filter' => false", + "'inline' => true", + "'validate' => true", + "'readonly' => true", + // "", + "'type' => null", + "'data' => null", + "[]", + ' ' + ); + + + + foreach($vars['fields'] as $key=>$val) + { + if(isset($val['type'])) + { + if(($val['type'] === 'dropdown' || $val['type'] === 'method') && empty($val['filter'])) + { + $vars['fields'][$key]['filter'] = '0'; + } + + if(($val['type'] === 'dropdown' || $val['type'] === 'method') && empty($val['batch'])) + { + $vars['fields'][$key]['batch'] = '0'; + } + + if($val['type'] == 'image' && empty($val['readParms'])) + { + $vars['fields'][$key]['readParms'] = 'thumb=80x80'; // provide a thumbnail preview by default. + } + } + if(empty($vars['fields'][$key]['readParms'])) + { + $vars['fields'][$key]['readParms'] = array(); + } + + if(empty($vars['fields'][$key]['writeParms'])) + { + $vars['fields'][$key]['writeParms'] = array(); + } + + + unset($vars['fields'][$key]['fieldpref']); + + } + + $FIELDS = "array (\n"; + + foreach($vars['fields'] as $key=>$val) + { + $FIELDS .= "\t\t\t'".str_pad($key."'",25)."=> ".str_replace($srch,$repl,var_export($val,true)).",\n"; + } + + $FIELDS .= "\t\t)"; + + // $FIELDS = var_export($vars['fields'],true); + // $FIELDS = str_replace($srch,$repl,var_export($vars['fields'],true)); + return preg_replace("#('([A-Z0-9_]*?LAN[_A-Z0-9]*)')#","$2",$FIELDS); // remove quotations from LANs. + + } + + /** + * @param array $post POSTED data from form. + * @param string $pluginFolder + * @param string $pluginTitle + * @return string + */ + public function buildAdminUI($post, $pluginFolder, $pluginTitle) + { + + unset($post['step'], $post['xml'], $post['addons']); + + $tp = e107::getParser(); + + $text = "\n +// Generated e107 Plugin Admin Area + +require_once('../../class2.php'); +if (!getperms('P')) +{ + e107::redirect('admin'); + exit; +} + +// e107::lan('" . $pluginFolder . "',true); + + +class " . $pluginFolder . "_adminArea extends e_admin_dispatcher +{ + + protected \$modes = array( + "; + + + unset($post['newplugin'], $post['mode']); + + foreach($post as $table => $vars) // LOOP Through Tables. + { + if(!empty($vars['mode']) && $vars['mode'] != 'exclude') + { + + $vars['mode'] = $tp->filter($vars['mode']); + + $text .= " + '" . $vars['mode'] . "' => array( + 'controller' => '" . $table . "', + 'path' => null, + 'ui' => '" . str_replace("_ui", "_form_ui", $table) . "', + 'uipath' => null + ), + +"; + } + } // END LOOP + /* + 'cat' => array( + 'controller' => 'faq_cat_ui', + 'path' => null, + 'ui' => 'faq_cat_form_ui', + 'uipath' => null + ) + ); + */ + + $text .= " + ); + + + protected \$adminMenu = array( +"; + foreach($post as $table => $vars) // LOOP Through Tables. + { + if(!empty($vars['mode']) && $vars['mode'] != 'exclude' && !empty($vars['table'])) + { + + $vars['mode'] = $tp->filter($vars['mode']); + $text .= " + '" . $vars['mode'] . "/list' => array('caption'=> LAN_MANAGE, 'perm' => 'P'), + '" . $vars['mode'] . "/create' => array('caption'=> LAN_CREATE, 'perm' => 'P'), +"; + } + } + + if($post['pluginPrefs'][0]['index']) + { + + $text .= " + 'main/prefs' => array('caption'=> LAN_PREFS, 'perm' => 'P'), +"; + } + $text .= " + // 'main/div0' => array('divider'=> true), + // 'main/custom' => array('caption'=> 'Custom Page', 'perm' => 'P'), + + ); + + protected \$adminMenuAliases = array( + 'main/edit' => 'main/list' + ); + + protected \$menuTitle = '" . vartrue($pluginTitle, $pluginFolder) . "'; +} + + + +"; + + + $tableCount = 1; + foreach($post as $table => $vars) // LOOP Through Tables. + { + + if($table == 'pluginPrefs' || $vars['mode'] == 'exclude') + { + continue; + } + + $vars['mode'] = $tp->filter($vars['mode']); + $vars['pluginName'] = $tp->filter($vars['pluginName']); + $vars['table'] = $tp->filter($vars['table']); + $vars['pid'] = $tp->filter($vars['pid']); + + $FIELDS = $this->buildAdminUIFields($vars); + $FIELDPREF = array(); + + foreach($vars['fields'] as $k => $v) + { + + if(isset($v['fieldpref']) && $k != 'checkboxes' && $k != 'options') + { + $FIELDPREF[] = "'" . $k . "'"; + } + } + + $text .= + " + +class " . $table . " extends e_admin_ui +{ + + protected \$pluginTitle = '" . $pluginTitle . "'; + protected \$pluginName = '" . $vars['pluginName'] . "'; + // protected \$eventName = '" . $vars['pluginName'] . "-" . $vars['table'] . "'; // remove comment to enable event triggers in admin. + protected \$table = '" . $vars['table'] . "'; + protected \$pid = '" . $vars['pid'] . "'; + protected \$perPage = 10; + protected \$batchDelete = true; + protected \$batchExport = true; + protected \$batchCopy = true; + + // protected \$sortField = 'somefield_order'; + // protected \$sortParent = 'somefield_parent'; + // protected \$treePrefix = 'somefield_title'; + + // protected \$tabs = array('tab1'=>'Tab 1', 'tab2'=>'Tab 2'); // Use 'tab'=>'tab1' OR 'tab'=>'tab2' in the \$fields below to enable. + + // protected \$listQry = \"SELECT * FROM `#tableName` WHERE field != '' \"; // Example Custom Query. LEFT JOINS allowed. Should be without any Order or Limit. + + protected \$listOrder = '" . $vars['pid'] . " DESC'; + + protected \$fields = " . $FIELDS . "; + + protected \$fieldpref = array(" . implode(", ", $FIELDPREF) . "); + +"; + + + if($post['pluginPrefs'] && ($vars['mode'] == 'main')) + { + $text .= " + // protected \$preftabs = array('General', 'Other' ); + protected \$prefs = array(\n"; + + foreach($post['pluginPrefs'] as $k => $val) + { + if(!empty($val['index'])) + { + $index = $tp->filter($val['index']); + $type = vartrue($val['type'], 'text'); + $help = str_replace("'", '', vartrue($val['help'])); + + $text .= "\t\t\t'" . $index . "'\t\t=> array('title'=> '" . ucfirst($index) . "', 'tab'=>0, 'type'=>'" . $tp->filter($type) . "', 'data' => 'str', 'help'=>'" . $tp->filter($help) . "', 'writeParms' => array()),\n"; + } + + } + + + $text .= "\t\t); \n\n"; + + } + + + $text .= " + public function init() + { + // This code may be removed once plugin development is complete. + if(!e107::isInstalled('" . $vars['pluginName'] . "')) + { + e107::getMessage()->addWarning(\"This plugin is not yet installed. Saving and loading of preference or table data will fail.\"); + } + + // Set drop-down values (if any). +"; + + foreach($vars['fields'] as $k => $v) + { + if(isset($v['type']) && ($v['type'] === 'dropdown')) + { + $text .= "\t\t\t\$this->fields['" . $k . "']['writeParms']['optArray'] = array('" . $k . "_0','" . $k . "_1', '" . $k . "_2'); // Example Drop-down array. \n"; + } + } + + + $text .= " + } + + + // ------- Customize Create -------- + + public function beforeCreate(\$new_data,\$old_data) + { + return \$new_data; + } + + public function afterCreate(\$new_data, \$old_data, \$id) + { + // do something + } + + public function onCreateError(\$new_data, \$old_data) + { + // do something + } + + + // ------- Customize Update -------- + + public function beforeUpdate(\$new_data, \$old_data, \$id) + { + return \$new_data; + } + + public function afterUpdate(\$new_data, \$old_data, \$id) + { + // do something + } + + public function onUpdateError(\$new_data, \$old_data, \$id) + { + // do something + } + + // left-panel help menu area. (replaces e_help.php used in old plugins) + public function renderHelp() + { + \$caption = LAN_HELP; + \$text = 'Some help text'; + + return array('caption'=>\$caption,'text'=> \$text); + + } + + /* + // optional - a custom page. + public function customPage() + { + \$text = 'Hello World!'; + \$otherField = \$this->getController()->getFieldVar('other_field_name'); + return \$text; + + } + +"; + + + $text .= $this->buildAdminUIBatchFilter($vars['fields'], $table, 'batch'); + $text .= $this->buildAdminUIBatchFilter($vars['fields'], $table, 'filter'); + + $text .= " + + + */ + +} + + + +class " . str_replace("_ui", "_form_ui", $table) . " extends e_admin_form_ui +{ +"; + + foreach($vars['fields'] as $fld => $val) + { + if(varset($val['type']) != 'method') + { + continue; + } + + $text .= " + + // Custom Method/Function + function " . $fld . "(\$curVal,\$mode) + { + + + switch(\$mode) + { + case 'read': // List Page + return \$curVal; + break; + + case 'write': // Edit Page + return \$this->text('" . $fld . "',\$curVal, 255, 'size=large'); + break; + + case 'filter': + return array('customfilter_1' => 'Custom Filter 1', 'customfilter_2' => 'Custom Filter 2'); + break; + + case 'batch': + return array('custombatch_1' => 'Custom Batch 1', 'custombatch_2' => 'Custom Batch 2'); + break; + } + + return null; + } +"; + } + + + foreach($post['pluginPrefs'] as $fld => $val) + { + if(varset($val['type']) !== 'method' || empty($val['index'])) + { + continue; + } + + $index = $tp->filter($val['index']); + + $text .= " + + // Custom Method/Function (pref) + function " . $index . "(\$curVal,\$mode) + { + + + switch(\$mode) + { + case 'write': // Edit Page + return \$this->text('" . $index . "',\$curVal, 255, 'size=large'); + break; + + } + + return null; + } +"; + } + + + $text .= " +} + +"; + + $tableCount++; + + } // End LOOP. + + $text .= ' +new ' . $pluginFolder . '_adminArea(); + +require_once(e_ADMIN."auth.php"); +e107::getAdminUI()->runPage(); + +require_once(e_ADMIN."footer.php"); +exit; + +'; + + return $text; + } + + +} diff --git a/e107_plugins/_blank/images/icon_128.png b/e107_plugins/_blank/images/icon_128.png new file mode 100644 index 000000000..10d846a38 Binary files /dev/null and b/e107_plugins/_blank/images/icon_128.png differ diff --git a/e107_plugins/_blank/images/icon_16.png b/e107_plugins/_blank/images/icon_16.png new file mode 100644 index 000000000..42fec2430 Binary files /dev/null and b/e107_plugins/_blank/images/icon_16.png differ diff --git a/e107_plugins/_blank/images/icon_32.png b/e107_plugins/_blank/images/icon_32.png new file mode 100644 index 000000000..0d8df456c Binary files /dev/null and b/e107_plugins/_blank/images/icon_32.png differ diff --git a/e107_tests/tests/unit/UserHandlerTest.php b/e107_tests/tests/unit/UserHandlerTest.php index 80d98e841..f2fd90a48 100644 --- a/e107_tests/tests/unit/UserHandlerTest.php +++ b/e107_tests/tests/unit/UserHandlerTest.php @@ -24,7 +24,7 @@ } catch(Exception $e) { - $this->assertTrue(false, "Couldn't load UserHandler object"); + $this->fail("Couldn't load UserHandler object"); } } diff --git a/e107_tests/tests/unit/e_pluginbuilderTest.php b/e107_tests/tests/unit/e_pluginbuilderTest.php new file mode 100644 index 000000000..76a2f97cc --- /dev/null +++ b/e107_tests/tests/unit/e_pluginbuilderTest.php @@ -0,0 +1,403 @@ +pb = $this->make('e_pluginbuilder'); + } + + catch(Exception $e) + { + $this->fail($e->getMessage()); + } + + $this->posted = array ( + 'xml' => + array ( + 'main-name' => 'Test', + 'main-lang' => '', + 'main-version' => '1.0', + 'main-date' => '2022-12-12', + 'main-compatibility' => '2.0', + 'author-name' => 'admin', + 'author-url' => 'https://e107.org', + 'summary-summary' => 'Test Plugin Creation', + 'description-description' => 'Example of a plugin description', + 'keywords-one' => 'generic', + 'keywords-two' => 'test', + 'keywords-three' => 'unit', + 'category-category' => 'content', + 'copyright-copyright' => 'copyright info', + ), + 'example_ui' => + array ( + 'pluginName' => 'ExamplePlugin', + 'table' => 'example', + 'mode' => 'main', + 'fields' => + array ( + 'checkboxes' => + array ( + 'title' => '', + 'type' => '', + 'data' => '', + 'width' => '5%', + 'thclass' => 'center', + 'forced' => 'value', + 'class' => 'center', + 'toggle' => 'e-multiselect', + 'fieldpref' => 'value', + ), + 'example_id' => + array ( + 'title' => 'LAN_ID', + 'type' => 'number', + 'data' => 'int', + 'width' => '5%', + 'help' => '', + 'readParms' => '', + 'writeParms' => '', + 'class' => 'left', + 'thclass' => 'left', + ), + 'example_icon' => + array ( + 'title' => 'LAN_ICON', + 'type' => 'icon', + 'data' => 'safestr', + 'width' => 'auto', + 'help' => '', + 'readParms' => '', + 'writeParms' => '', + 'class' => 'left', + 'thclass' => 'left', + ), + 'example_type' => + array ( + 'title' => 'LAN_TYPE', + 'type' => 'dropdown', + 'data' => 'safestr', + 'width' => 'auto', + 'batch' => '1', + 'filter' => '1', + 'inline' => '1', + 'fieldpref' => '1', + 'help' => '', + 'readParms' => '', + 'writeParms' => '', + 'class' => 'left', + 'thclass' => 'left', + ), + 'example_name' => + array ( + 'title' => 'LAN_TITLE', + 'type' => 'text', + 'data' => 'safestr', + 'width' => 'auto', + 'inline' => '1', + 'fieldpref' => '1', + 'help' => '', + 'readParms' => '', + 'writeParms' => '', + 'class' => 'left', + 'thclass' => 'left', + ), + 'example_folder' => + array ( + 'title' => 'Folder', + 'type' => 'method', + 'data' => 'safestr', + 'width' => 'auto', + 'help' => '', + 'readParms' => '', + 'writeParms' => '', + 'class' => 'left', + 'thclass' => 'left', + ), + 'example_version' => + array ( + 'title' => 'Version', + 'type' => 'text', + 'data' => 'safestr', + 'width' => 'auto', + 'readonly' => '1', + 'help' => '', + 'readParms' => '', + 'writeParms' => '', + 'class' => 'left', + 'thclass' => 'left', + ), + 'example_author' => + array ( + 'title' => 'LAN_AUTHOR', + 'type' => 'text', + 'data' => 'safestr', + 'width' => 'auto', + 'help' => '', + 'readParms' => '', + 'writeParms' => '', + 'class' => 'left', + 'thclass' => 'left', + ), + 'example_authorURL' => + array ( + 'title' => 'AuthorURL', + 'type' => 'text', + 'data' => 'safestr', + 'width' => 'auto', + 'help' => '', + 'readParms' => '', + 'writeParms' => '', + 'class' => 'left', + 'thclass' => 'left', + ), + 'example_date' => + array ( + 'title' => 'LAN_DATESTAMP', + 'type' => 'datestamp', + 'data' => 'int', + 'width' => 'auto', + 'filter' => '1', + 'fieldpref' => '1', + 'help' => '', + 'readParms' => '', + 'writeParms' => '', + 'class' => 'left', + 'thclass' => 'left', + ), + 'example_compatibility' => + array ( + 'title' => 'Compatibility', + 'type' => 'text', + 'data' => 'safestr', + 'width' => 'auto', + 'help' => '', + 'readParms' => '', + 'writeParms' => '', + 'class' => 'left', + 'thclass' => 'left', + ), + 'example_url' => + array ( + 'title' => 'LAN_URL', + 'type' => 'url', + 'data' => 'safestr', + 'width' => 'auto', + 'inline' => '1', + 'help' => '', + 'readParms' => '', + 'writeParms' => '', + 'class' => 'left', + 'thclass' => 'left', + ), + 'example_media' => + array ( + 'title' => 'Media', + 'type' => 'image', + 'data' => 'str', + 'width' => 'auto', + 'help' => '', + 'readParms' => '', + 'writeParms' => '', + 'class' => 'left', + 'thclass' => 'left', + ), + 'example_class' => + array ( + 'title' => 'LAN_USERCLASS', + 'type' => 'userclass', + 'data' => 'int', + 'width' => 'auto', + 'batch' => '1', + 'filter' => '1', + 'inline' => '1', + 'fieldpref' => '1', + 'help' => '', + 'readParms' => '', + 'writeParms' => '', + 'class' => 'left', + 'thclass' => 'left', + ), + 'options' => + array ( + 'title' => 'LAN_OPTIONS', + 'type' => '', + 'data' => '', + 'width' => '10%', + 'thclass' => 'center last', + 'class' => 'center last', + 'forced' => 'value', + 'fieldpref' => 'value', + ), + ), + 'pid' => 'example_id', + ), + 'pluginPrefs' => + array ( + 0 => + array ( + 'index' => 'active', + 'value' => '1', + 'type' => 'boolean', + 'help' => 'A help tip', + ), + 1 => + array ( + 'index' => '', + 'value' => '', + 'type' => '', + 'help' => '', + ), + 2 => + array ( + 'index' => '', + 'value' => '', + 'type' => '', + 'help' => '', + ), + 3 => + array ( + 'index' => '', + 'value' => '', + 'type' => '', + 'help' => '', + ), + 4 => + array ( + 'index' => '', + 'value' => '', + 'type' => '', + 'help' => '', + ), + 5 => + array ( + 'index' => '', + 'value' => '', + 'type' => '', + 'help' => '', + ), + 6 => + array ( + 'index' => '', + 'value' => '', + 'type' => '', + 'help' => '', + ), + 7 => + array ( + 'index' => '', + 'value' => '', + 'type' => '', + 'help' => '', + ), + 8 => + array ( + 'index' => '', + 'value' => '', + 'type' => '', + 'help' => '', + ), + 9 => + array ( + 'index' => '', + 'value' => '', + 'type' => '', + 'help' => '', + ), + ), + 'newplugin' => 'example', + 'step' => '4', + ); + + } +/* + public function testSpecial() + { + + } + + public function testGuess() + { + + } + + public function testForm() + { + + } + + public function testCreateXml() + { + + }*/ + + public function testBuildAdminUI() + { + $result = $this->pb->buildAdminUI($this->posted, 'pluginfolder', 'PluginTitle'); + $expected = "'example_id' => array ( 'title' => LAN_ID, 'type' => 'number', 'data' => 'int', 'width' => '5%', 'help' => '', 'readParms' => [], 'writeParms' => [], 'class' => 'left', 'thclass' => 'left',)"; + $this->assertStringContainsString($expected, $result); + } +/* + public function testRun() + { + + } + + public function testPluginXml() + { + + } + + public function testXmlInput() + { + + } + + public function testStep4() + { + + } + + public function testStep3() + { + + } + + public function testStep1() + { + + } + + public function testEnterMysql() + { + + } + + public function testFieldType() + { + + } + + public function testFieldData() + { + + } + + public function testPrefs() + { + + }*/ + + +}