Skip to content

Commit

Permalink
Fixes #5092 - Removed example code with error and added new example. …
Browse files Browse the repository at this point in the history
…Minor cleanup of class.
  • Loading branch information
CaMer0n committed Oct 31, 2023
1 parent 187d45d commit fb98771
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 15 deletions.
63 changes: 48 additions & 15 deletions e107_handlers/e_pluginbuilder_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,11 @@ class e_pluginbuilder
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);

Expand Down Expand Up @@ -717,7 +712,7 @@ function pluginXml()
$info = str_replace('[x]', $this->pluginName."_sql.php", EPL_ADLAN_132);
$mes->addInfo($info,'default',true);
$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);
}
else
Expand Down Expand Up @@ -894,7 +889,7 @@ function xmlInput($name, $info, $default='')
break;
}

$req = ($required == true) ? "&required=1" : "";
$req = $required ? "&required=1" : "";
$placeholder = (varset($placeholder)) ? $placeholder : $type;
$pat = !empty($pattern) ? "&pattern=".$pattern : "";
$sz = !empty($xsize) ? "&size=".$xsize : "";
Expand Down Expand Up @@ -1067,7 +1062,7 @@ function createXml($data)
}


if($this->createFiles == true || !file_exists($path))
if($this->createFiles || !file_exists($path))
{
if(file_put_contents($path,$result) )
{
Expand Down Expand Up @@ -1103,7 +1098,7 @@ function form($table,$fieldArray)
);

// echo "TABLE COUNT= ".$this->tableCount ;

$defaultMode = [];

$this->table = $table."_ui";

Expand Down Expand Up @@ -1321,6 +1316,9 @@ function fieldType($name, $val)
"hidden" => EPL_ADLAN_215
);
break;

default:
$array = [];
}

// asort($array);
Expand All @@ -1334,6 +1332,7 @@ function fieldType($name, $val)
function guess($data, $val=null,$mode = 'type')
{
$tmp = explode("_",$data);
$name = '';

if(count($tmp) == 3) // eg Link_page_title
{
Expand Down Expand Up @@ -2063,8 +2062,11 @@ public function init()

$text .= "
}
";


$text .= <<<UICODE
// ------- Customize Create --------
public function beforeCreate(\$new_data,\$old_data)
Expand Down Expand Up @@ -2114,13 +2116,43 @@ public function renderHelp()
// optional - a custom page.
public function customPage()
{
\$text = 'Hello World!';
\$otherField = \$this->getController()->getFieldVar('other_field_name');
if(\$this->getPosted('custom-submit')) // after form is submitted.
{
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;
}
";
UICODE;
$text .= $this->buildAdminUIBatchFilter($vars['fields'], $table, 'batch');
Expand Down Expand Up @@ -2151,7 +2183,7 @@ class " . str_replace("_ui", "_form_ui", $table) . " extends e_admin_form_ui
// Custom Method/Function
function " . $fld . "(\$curVal,\$mode)
{
\$otherField = \$this->getController()->getFieldVar('other_field_name');
switch(\$mode)
{
Expand Down Expand Up @@ -2197,6 +2229,7 @@ function " . $index . "(\$curVal,\$mode)
switch(\$mode)
{
case 'write': // Edit Page
return \$this->text('" . $index . "',\$curVal, 255, 'size=large');
break;
Expand Down
20 changes: 20 additions & 0 deletions e107_tests/tests/unit/e_pluginbuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,27 @@ 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);

// 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()
{
Expand Down

0 comments on commit fb98771

Please sign in to comment.