mirror of
https://github.com/e107inc/e107.git
synced 2025-08-02 20:57:26 +02:00
Fixes #5092 - Removed example code with error and added new example. Minor cleanup of class.
This commit is contained in:
@@ -15,16 +15,11 @@ class e_pluginbuilder
|
|||||||
var $tableList = array();
|
var $tableList = array();
|
||||||
var $createFiles = false;
|
var $createFiles = false;
|
||||||
private $buildTable = false;
|
private $buildTable = false;
|
||||||
private $debug = false;
|
|
||||||
|
|
||||||
function __construct()
|
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['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);
|
$this->special['options'] = array( 'title'=> 'LAN_OPTIONS', 'type' => null, 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced'=>TRUE, 'fieldpref'=>true);
|
||||||
|
|
||||||
@@ -717,7 +712,7 @@ $content .= '}';
|
|||||||
$info = str_replace('[x]', $this->pluginName."_sql.php", EPL_ADLAN_132);
|
$info = str_replace('[x]', $this->pluginName."_sql.php", EPL_ADLAN_132);
|
||||||
$mes->addInfo($info,'default',true);
|
$mes->addInfo($info,'default',true);
|
||||||
$red = e107::getRedirect();
|
$red = e107::getRedirect();
|
||||||
$red->redirect(e_REQUEST_URL,true);
|
$red->redirect(e_REQUEST_URL);
|
||||||
// $red->redirect(e_SELF."?mode=create&newplugin=".$this->pluginName."&createFiles=1&step=2",true);
|
// $red->redirect(e_SELF."?mode=create&newplugin=".$this->pluginName."&createFiles=1&step=2",true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -894,7 +889,7 @@ $content .= '}';
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$req = ($required == true) ? "&required=1" : "";
|
$req = $required ? "&required=1" : "";
|
||||||
$placeholder = (varset($placeholder)) ? $placeholder : $type;
|
$placeholder = (varset($placeholder)) ? $placeholder : $type;
|
||||||
$pat = !empty($pattern) ? "&pattern=".$pattern : "";
|
$pat = !empty($pattern) ? "&pattern=".$pattern : "";
|
||||||
$sz = !empty($xsize) ? "&size=".$xsize : "";
|
$sz = !empty($xsize) ? "&size=".$xsize : "";
|
||||||
@@ -1067,7 +1062,7 @@ TEMPLATE;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if($this->createFiles == true || !file_exists($path))
|
if($this->createFiles || !file_exists($path))
|
||||||
{
|
{
|
||||||
if(file_put_contents($path,$result) )
|
if(file_put_contents($path,$result) )
|
||||||
{
|
{
|
||||||
@@ -1103,7 +1098,7 @@ TEMPLATE;
|
|||||||
);
|
);
|
||||||
|
|
||||||
// echo "TABLE COUNT= ".$this->tableCount ;
|
// echo "TABLE COUNT= ".$this->tableCount ;
|
||||||
|
$defaultMode = [];
|
||||||
|
|
||||||
$this->table = $table."_ui";
|
$this->table = $table."_ui";
|
||||||
|
|
||||||
@@ -1321,6 +1316,9 @@ TEMPLATE;
|
|||||||
"hidden" => EPL_ADLAN_215
|
"hidden" => EPL_ADLAN_215
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
$array = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// asort($array);
|
// asort($array);
|
||||||
@@ -1334,6 +1332,7 @@ TEMPLATE;
|
|||||||
function guess($data, $val=null,$mode = 'type')
|
function guess($data, $val=null,$mode = 'type')
|
||||||
{
|
{
|
||||||
$tmp = explode("_",$data);
|
$tmp = explode("_",$data);
|
||||||
|
$name = '';
|
||||||
|
|
||||||
if(count($tmp) == 3) // eg Link_page_title
|
if(count($tmp) == 3) // eg Link_page_title
|
||||||
{
|
{
|
||||||
@@ -2063,8 +2062,11 @@ class " . $table . " extends e_admin_ui
|
|||||||
|
|
||||||
$text .= "
|
$text .= "
|
||||||
}
|
}
|
||||||
|
";
|
||||||
|
|
||||||
|
|
||||||
|
$text .= <<<UICODE
|
||||||
|
|
||||||
|
|
||||||
// ------- Customize Create --------
|
// ------- Customize Create --------
|
||||||
|
|
||||||
public function beforeCreate(\$new_data,\$old_data)
|
public function beforeCreate(\$new_data,\$old_data)
|
||||||
@@ -2114,13 +2116,43 @@ class " . $table . " extends e_admin_ui
|
|||||||
// optional - a custom page.
|
// optional - a custom page.
|
||||||
public function customPage()
|
public function customPage()
|
||||||
{
|
{
|
||||||
\$text = 'Hello World!';
|
if(\$this->getPosted('custom-submit')) // after form is submitted.
|
||||||
\$otherField = \$this->getController()->getFieldVar('other_field_name');
|
{
|
||||||
|
e107::getMessage()->addSuccess('Changes made: '. \$this->getPosted('example'));
|
||||||
|
}
|
||||||
|
|
||||||
|
\$this->addTitle('My Custom Title');
|
||||||
|
|
||||||
|
|
||||||
|
\$frm = \$this->getUI();
|
||||||
|
\$text = \$frm->open('my-form', 'post');
|
||||||
|
|
||||||
|
\$tab1 = "<table class='table table-bordered adminform'>
|
||||||
|
<colgroup>
|
||||||
|
<col class='col-label'>
|
||||||
|
<col class='col-control'>
|
||||||
|
</colgroup>
|
||||||
|
<tr>
|
||||||
|
<td>Label ".\$frm->help('A help tip')."</td>
|
||||||
|
<td>".\$frm->text('example', \$this->getPosted('example'), 80, ['size'=>'xlarge'])."</td>
|
||||||
|
</tr>
|
||||||
|
</table>";
|
||||||
|
|
||||||
|
// Display Tab
|
||||||
|
\$text .= \$frm->tabs([
|
||||||
|
'general' => ['caption'=>LAN_GENERAL, 'text' => \$tab1],
|
||||||
|
]);
|
||||||
|
|
||||||
|
\$text .= "<div class='buttons-bar text-center'>".\$frm->button('custom-submit', 'submit', 'submit', LAN_CREATE)."</div>";
|
||||||
|
\$text .= \$frm->close();
|
||||||
|
|
||||||
return \$text;
|
return \$text;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
";
|
UICODE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$text .= $this->buildAdminUIBatchFilter($vars['fields'], $table, 'batch');
|
$text .= $this->buildAdminUIBatchFilter($vars['fields'], $table, 'batch');
|
||||||
@@ -2151,7 +2183,7 @@ class " . str_replace("_ui", "_form_ui", $table) . " extends e_admin_form_ui
|
|||||||
// Custom Method/Function
|
// Custom Method/Function
|
||||||
function " . $fld . "(\$curVal,\$mode)
|
function " . $fld . "(\$curVal,\$mode)
|
||||||
{
|
{
|
||||||
|
\$otherField = \$this->getController()->getFieldVar('other_field_name');
|
||||||
|
|
||||||
switch(\$mode)
|
switch(\$mode)
|
||||||
{
|
{
|
||||||
@@ -2197,6 +2229,7 @@ class " . str_replace("_ui", "_form_ui", $table) . " extends e_admin_form_ui
|
|||||||
switch(\$mode)
|
switch(\$mode)
|
||||||
{
|
{
|
||||||
case 'write': // Edit Page
|
case 'write': // Edit Page
|
||||||
|
|
||||||
return \$this->text('" . $index . "',\$curVal, 255, 'size=large');
|
return \$this->text('" . $index . "',\$curVal, 255, 'size=large');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@@ -347,7 +347,27 @@ class e_pluginbuilderTest extends \Codeception\Test\Unit
|
|||||||
$result = $this->pb->buildAdminUI($this->posted, 'pluginfolder', 'PluginTitle');
|
$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',)";
|
$expected = "'example_id' => array ( 'title' => LAN_ID, 'type' => 'number', 'data' => 'int', 'width' => '5%', 'help' => '', 'readParms' => [], 'writeParms' => [], 'class' => 'left', 'thclass' => 'left',)";
|
||||||
$this->assertStringContainsString($expected, $result);
|
$this->assertStringContainsString($expected, $result);
|
||||||
|
|
||||||
|
// file_put_contents(__DIR__."/testBuild.php", "<?php\n\n".$result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* public function isValidCode($code)
|
||||||
|
{
|
||||||
|
$temp_file = tempnam(sys_get_temp_dir(), 'PHP');
|
||||||
|
file_put_contents($temp_file, $code);
|
||||||
|
$output = shell_exec("php -l $temp_file");
|
||||||
|
unlink($temp_file);
|
||||||
|
|
||||||
|
if (strpos($output, 'No syntax errors detected') === false)
|
||||||
|
{
|
||||||
|
return $output;
|
||||||
|
$this->fail("The code is not valid. Error message: $output");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}*/
|
||||||
/*
|
/*
|
||||||
public function testRun()
|
public function testRun()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user