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 .= ""; // $mes->addInfo($tp->toHTML($info,true)); $text = $frm->open('createPlugin','get', e_SELF); $text .= $frm->hidden('action', 'build'); $text .= ""; /* NOT a good idea - requires the use of $_POST which would prevent browser 'go Back' navigation. if(e_DOMAIN == FALSE) // localhost. { $text .= ""; } */ $text .= "
".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.
"; $text .= $frm->close(); return $text; // $ns->tablerender(ADLAN_98.SEP.EPL_ADLAN_114, $mes->render() . $text); // $var['lans']['text'] = EPL_ADLAN_226; // $var['lans']['link'] = e_SELF."?mode=lans"; } function enterMysql() { $frm = e107::getForm(); return "
".$frm->textarea('mysql','')."
"; } /** * @param string $table * @param string $file */ private function buildSQLFile($table, $file) { $table = e107::getParser()->filter($table); e107::getDb()->gen("SHOW CREATE TABLE `#".$table."`"); $data = e107::getDb()->fetch('num'); if(!empty($data[1])) { $createData = str_replace("`".MPREFIX, '`', $data[1]); $createData .= ";"; if(!file_exists($file)/* && empty($this->createFiles)*/) { file_put_contents($file,$createData); } } } function step3() { // require_once(e_HANDLER."db_verify_class.php"); // $dv = new db_verify; $dv = e107::getSingleton('db_verify', e_HANDLER."db_verify_class.php"); $frm = e107::getForm(); $ns = e107::getRender(); $mes = e107::getMessage(); $tp = e107::getParser(); $newplug = $tp->filter($_GET['newplugin'],'file'); $this->pluginName = $newplug; $sqlFile = e_PLUGIN.$newplug."/".$newplug."_sql.php"; if(!empty($_GET['build']) && !file_exists($sqlFile)) { $this->buildSQLFile($_GET['build'], $sqlFile); } $ret = array(); if(file_exists($sqlFile)) { $data = file_get_contents($sqlFile); $ret = $dv->getSqlFileTables($data); } else { e107::getDebug()->log("SQL File Not Found"); // $this->buildTable = true; } $text = $frm->open('newplugin-step3','post', e_SELF.'?mode=create&action=build&newplugin='.$newplug.'&createFiles='.$this->createFiles.'&step=3'); $text .= ""; $text .= "
\n"; $text .= "
\n"; $text .= $this->pluginXml(); $text .= "
"; if(!empty($ret['tables'])) { foreach($ret['tables'] as $key=>$table) { $text .= "
\n"; $fields = $dv->getFields($ret['data'][$key]); $text .= $this->form($table,$fields); $text .= "
"; } } $text .= "
\n"; $text .= $this->prefs(); $text .= "
"; $text .= "
\n"; $text .= $this->addons(); $text .= "
"; if(empty($ret['tables'])) { $text .= $frm->hidden($this->pluginName.'_ui[mode]','main'); $text .= $frm->hidden($this->pluginName.'_ui[pluginName]', $this->pluginName); } $text .= "
"; $text .= "
".$frm->hidden('newplugin', $this->pluginName)." ".$frm->admin_button('step', 4,'other', LAN_GENERATE)."
"; $text .= $frm->close(); $mes->addInfo(EPL_ADLAN_112); $mes->addInfo(EPL_ADLAN_113); return array('caption'=>EPL_ADLAN_115, 'text'=> $text); // $ns->tablerender(ADLAN_98.SEP.EPL_ADLAN_114.SEP., $mes->render() . $text); } private function step2() { $frm = e107::getForm(); $tables = e107::getDb()->tables(); $text = $frm->open('buildTab', 'get', e_REQUEST_SELF); $text .= "

".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)."
"; $text .= $frm->close(); /* e107::js('footer-inline',' $(document).on("click", "#build-table-submit", function(e){ e.preventDefault(); $(this).addClass("disabled"); var url = $("#build-table-url").val(); var sel = $("#build-table-tbl").val(); url = url + "&build=" + sel; window.location.href = url; return false; }); ');*/ $ns = e107::getRender(); return array('caption'=>EPL_ADLAN_115, 'text'=>$text); // $ns->tablerender(ADLAN_98.SEP.EPL_ADLAN_114.SEP.EPL_ADLAN_115, $text); return $text; } 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."_".$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."']; } "; } } $content .= '}'; return file_put_contents($file,$content)? LAN_CREATED.': '.$this->pluginName."_shortcodes.php" : LAN_CREATED_FAILED.': '.$this->pluginName."_shortcodes.php"; } private function createAddons($list) { $srch = array('_blank','blank'); $result = array(); foreach($list as $addon) { $addonDest = str_replace("_blank",$this->pluginName,$addon); $source = e_PLUGIN."_blank/".$addon.".php"; $destination = e_PLUGIN.$this->pluginName. "/".$addonDest.".php"; if(file_exists($destination) && empty($this->createFiles)) { $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; } if($content = file_get_contents($source)) { $content = str_replace($srch, $this->pluginName, $content); if(file_exists($destination) && empty($this->createFiles)) { $result[] = e107::getParser()->lanVars(EPL_ADLAN_256,$addonDest.'.php'); } else { if(file_put_contents($destination,$content)) { $result[] = LAN_CREATED." : ".$addonDest.".php"; } } } } return $result; } private function addons() { $plg = e107::getPlugin(); $list = $plg->getAddonsList(); $frm = e107::getForm(); $text = ""; //Todo LANS $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_template' => "Template to allow layout customization by themes.", '_blank_shortcodes' => "Shortcodes for the template." ); array_unshift($list,'_blank', '_blank_setup', '_blank_menu', '_blank_template', '_blank_shortcodes'); $templateFiles = scandir(e_PLUGIN."_blank"); //print_a($list); // $list[] = "_blank"; // $list[] = "_blank_setup"; foreach($list as $v) { if(!in_array($v.".php", $templateFiles) && $v != '_blank_template' && $v!='_blank_shortcodes') { continue; } $diz = !empty($dizOther[$v]) ? $dizOther[$v] : $plg->getAddonsDiz($v); $label = str_replace("_blank", $this->pluginName, $v); $id = str_replace('_blank', 'blank', $v); $text .= ""; $text .= ""; $text .= ""; $text .= ""; } $text .= "
".$frm->checkbox('addons[]',$v,false,$label)."
"; return $text; } function prefs() { $frm = e107::getForm(); $text = ''; $options = array( 'text' => EPL_ADLAN_116, 'number' => EPL_ADLAN_117, 'url' => EPL_ADLAN_118, 'textarea' => EPL_ADLAN_119, 'bbarea' => EPL_ADLAN_120, 'boolean' => EPL_ADLAN_121, "method" => EPL_ADLAN_122, "image" => EPL_ADLAN_123, "dropdown" => EPL_ADLAN_124, "userclass" => EPL_ADLAN_125, "language" => EPL_ADLAN_126, "icon" => EPL_ADLAN_127, "file" => EPL_ADLAN_128, ); $text = ""; for ($i=0; $i < 10; $i++) { $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)."
"; return $text; } function pluginXml() { //TODO Plugin.xml Form Fields. . $data = array( 'main' => array('name','lang','version','date', 'compatibility'), 'author' => array('name','url'), 'summary' => array('summary'), 'description' => array('description'), 'keywords' => array('one','two','three'), 'category' => array('category'), 'copyright' => array('copyright'), // 'adminLinks' => array('url','description','icon','iconSmall','primary'), // 'sitelinks' => array('url','description','icon','iconSmall') ); // Load old plugin.php file if it exists; $legacyFile = e_PLUGIN.$this->pluginName."/plugin.php"; if(file_exists($legacyFile)) { $eplug_name = $eplug_author = $eplug_url = $eplug_description = ""; $eplug_tables = array(); require_once($legacyFile); $mes = e107::getMessage(); $mes->addInfo("Loading plugin.php file"); $defaults = array( "main-name" => $eplug_name, "author-name" => $eplug_author, "author-url" => $eplug_url, "description-description" => $eplug_description, "summary-summary" => $eplug_description ); if(count($eplug_tables) && !file_exists(e_PLUGIN.$this->pluginName."/".$this->pluginName."_sql.php")) { $cont = ''; foreach($eplug_tables as $tab) { if(strpos($tab,"INSERT INTO")!==FALSE) { continue; } $cont .= "\n".str_replace("\t"," ",$tab); } if(file_put_contents(e_PLUGIN.$this->pluginName."/".$this->pluginName."_sql.php",$cont)) { $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_SELF."?mode=create&newplugin=".$this->pluginName."&createFiles=1&step=2",true); } else { $msg = str_replace('[x]', $this->pluginName."_sql.php", EPL_ADLAN_133)."
"; $msg .= str_replace(array('[x]','[y]'), array($this->pluginName."_sql.php",$cont), EPL_ADLAN_134); $mes->addWarning($msg); } } } $existingXml = e_PLUGIN.$this->pluginName."/plugin.xml"; if(file_exists($existingXml)) { $p = e107::getXml()->loadXMLfile($existingXml,true); // print_a($p); $defaults = array( "main-name" => varset($p['@attributes']['name']), "main-lang" => varset($p['@attributes']['lan']), "author-name" => varset($p['author']['@attributes']['name']), "author-url" => varset($p['author']['@attributes']['url']), "description-description" => varset($p['description']), "summary-summary" => varset($p['summary'], $p['description']), "category-category" => varset($p['category']), "copyright-copyright" => varset($p['copyright']), "keywords-one" => varset($p['keywords']['word'][0]), "keywords-two" => varset($p['keywords']['word'][1]), "keywords-three" => varset($p['keywords']['word'][2]), ); unset($p); } $text = ""; foreach($data as $key=>$val) { $text.= ""; } $text .= "
$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 .= "
"; return $text; } function xmlInput($name, $info, $default='') { $frm = e107::getForm(); list($cat,$type) = explode("-",$info); $size = 30; // Textbox size. $help = ''; $pattern = ""; $required = false; switch ($info) { case 'main-name': $help = EPL_ADLAN_135; $required = true; $pattern = "[A-Za-z0-9 -]*"; $xsize = 'medium'; break; case 'main-lang': $help = EPL_ADLAN_136; // $required = false; $placeholder= " "; $pattern = "[A-Z0-9_]*"; $xsize = 'medium'; break; case 'main-date': $help = EPL_ADLAN_137; $required = true; $xsize = 'medium'; break; case 'main-version': $default = '1.0'; $required = true; $help = EPL_ADLAN_138; $pattern = "^[\d]{1,2}\.[\d]{1,2}(\.[\d]{1,2})?$"; $xsize = 'small'; break; case 'main-compatibility': $default = '2.0'; $required = true; $help = EPL_ADLAN_139; $pattern = "^[\d]{1,2}\.[\d]{1,2}$"; $xsize = 'small'; break; case 'author-name': $default = (vartrue($default)) ? $default : USERNAME; $required = true; $help = EPL_ADLAN_140; $pattern = "[A-Za-z \.0-9]*"; $xsize = 'medium'; break; case 'author-url': $required = true; $help = EPL_ADLAN_141; // $pattern = "https?://.+"; $xsize = 'medium'; break; //case 'main-installRequired': // return "Installation required: ".$frm->radio_switch($name,'',LAN_YES, LAN_NO); //break; case 'summary-summary': $help = EPL_ADLAN_142."
".EPL_ADLAN_143; $required = true; $size = 130; $placeholder= " "; $pattern = "[A-Za-z -\.0-9]*"; $xsize = 'block-level'; break; case 'keywords-one': $type = 'keywordDropDown'; $required = true; $help = EPL_ADLAN_144; break; case 'keywords-three': case 'keywords-two': $help = EPL_ADLAN_144."
".EPL_ADLAN_143; $required = true; $size = 20; $placeholder= " "; $pattern = '^[a-z]*$'; $xsize = 'medium'; break; case 'description-description': $help = EPL_ADLAN_145."
".EPL_ADLAN_143; $required = true; $size = 100; $placeholder = " "; $pattern = "[A-Za-z -\.0-9]*"; $xsize = 'block-level'; break; case 'category-category': $help = EPL_ADLAN_146; $required = true; $size = 20; break; default: break; } $req = ($required == true) ? "&required=1" : ""; $placeholder = (varset($placeholder)) ? $placeholder : $type; $pat = !empty($pattern) ? "&pattern=".$pattern : ""; $sz = !empty($xsize) ? "&size=".$xsize : ""; switch ($type) { case 'date': $text = $frm->datepicker($name, time(), 'format=yyyy-mm-dd&return=string'.$req . $sz); break; case 'description': $text = $frm->textarea($name,$default, 3, 100, $req.$sz); // pattern not supported. break; case 'category': $options = array( 'settings' => EPL_ADLAN_147, 'users' => EPL_ADLAN_148, 'content' => EPL_ADLAN_149, 'tools' => EPL_ADLAN_150, 'manage' => EPL_ADLAN_151, 'misc' => EPL_ADLAN_152, 'menu' => EPL_ADLAN_153, 'about' => EPL_ADLAN_154 ); $text = $frm->select($name, $options, $default,'required=1&class=form-control', true); break; case 'keywordDropDown': $options = array( 'generic', 'admin', 'messaging', 'enhancement', 'date', 'commerce', 'form', 'gaming', 'intranet', 'multimedia', 'information', 'mail', 'search', 'stats', 'files', 'security', 'generic', 'language' ); sort($options); $text = $frm->select($name, $options, $default,'required=1&class=form-control&useValues=1', true); break; default: $text = $frm->text($name, $default, $size, 'placeholder='.$placeholder . $sz. $req. $pat); break; } $text .= ($help) ? "".$help."" : ""; return $text; } function createXml($data) { // print_a($_POST); $ns = e107::getRender(); $mes = e107::getMessage(); $tp = e107::getParser(); $newArray = []; foreach($data as $key=>$val) { $key = strtoupper(str_replace("-","_",$key)); $newArray[$key] = $val; } $newArray['DESCRIPTION_DESCRIPTION'] = strip_tags($tp->toHTML($newArray['DESCRIPTION_DESCRIPTION'],true)); $_POST['pluginPrefs'] = $tp->filter($_POST['pluginPrefs']); $plugPref = array(); foreach($_POST['pluginPrefs'] as $val) { if(vartrue($val['index'])) { $id = $val['index']; $plugPref[$id] = $val['value']; } } // print_a($_POST['pluginPrefs']); if(!empty($plugPref)) { $xmlPref = "\n"; foreach($plugPref as $k=>$v) { $xmlPref .= " ".$v."\n"; } $xmlPref .= " "; $newArray['PLUGINPREFS'] = $xmlPref; } // print_a($newArray); // print_a($this); $template = <<