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'] = !empty($var['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' => []),\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; } }