toGlyph('fa-refresh', array('size'=>'2x', 'fw'=>1))); global $user_pref; /* if(!deftrue('e_DEBUG_PLUGMANAGER')) { require_once(e_HANDLER.'plugin_class.php'); require_once(e_HANDLER.'file_class.php'); $plugin = new e107plugin; $pman = new pluginManager; define("e_PAGETITLE",ADLAN_98." - ".$pman->pagetitle); } */ if(isset($_POST['uninstall_cancel'])) { header("location:".e_SELF); exit; } // Experimental rewrite for v2.1.5 ---------------------- class plugman_adminArea extends e_admin_dispatcher { protected $modes = array( 'installed' => array( 'controller' => 'plugin_ui', 'path' => null, 'ui' => 'plugin_form_ui', 'uipath' => null ), 'avail' => array( 'controller' => 'plugin_ui', 'path' => null, 'ui' => 'plugin_form_ui', 'uipath' => null ), 'online' => array( 'controller' => 'plugin_online_ui', 'path' => null, 'ui' => 'plugin_form_ui', 'uipath' => null ), 'create' => array( 'controller' => 'plugin_ui', 'path' => null, 'ui' => 'plugin_form_ui', 'uipath' => null ), ); protected $adminMenu = array( 'installed/list' => array('caption'=> EPL_ADLAN_22, 'perm' => 'Z'), 'avail/list' => array('caption'=> EPL_ADLAN_23, 'perm' => 'Z'), 'online/list' => array('caption'=> EPL_ADLAN_220, 'perm' => 'Z'), 'avail/upload' => array('caption'=>EPL_ADLAN_38, 'perm' => '0'), 'create/build' => array('caption'=>EPL_ADLAN_114, 'perm' => '0'), // 'main/create' => array('caption'=> LAN_CREATE, 'perm' => 'P'), // 'main/custom' => array('caption'=> 'Custom Page', 'perm' => 'P') ); protected $defaultMode = 'installed'; protected $adminMenuAliases = array( 'installed/uninstall' => 'installed/list' ); protected $adminMenuIcon = 'e-plugmanager-24'; function init() { $mode = $this->getRequest()->getMode(); $action = $this->getRequest()->getAction(); if($mode === 'online' && $action === 'download') { define('e_IFRAME', true); } } public static function getPluginManagerFields() { return array( 'checkboxes' => array('title' => '', 'type' => null, 'data' => null, 'width' => '5%', 'thclass' => 'center', 'forced' => '1', 'class' => 'center', 'toggle' => 'e-multiselect',), 'plugin_id' => array('title' => LAN_ID, 'data' => 'int', 'width' => '5%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',), 'plugin_icon' => array('title' => LAN_ICON, 'type' => 'icon', 'data' => false, "width" => "5%", 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',), 'plugin_name' => array('title' => LAN_TITLE, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',), 'plugin_version' => array('title' => LAN_VERSION, 'type' => 'text', 'data' => false, 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',), 'plugin_date' => array('title' => LAN_RELEASED, 'type' => 'text', 'data' => false, "width" => "8%", 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',), 'plugin_category' => array('title' => LAN_CATEGORY, 'type' => 'dropdown', 'data' => 'str', 'width' => 'auto', 'batch' => true, 'filter' => true, 'inline' => true, 'help' => '', 'readParms' => '', 'writeParms' => array(), 'class' => 'left', 'thclass' => 'left',), 'plugin_author' => array('title' => LAN_AUTHOR, 'type' => 'text', 'data' => false, 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',), "plugin_license" => array("title" => "License", 'nolist'=>false,'data'=>false, "type"=>"text", "width" => "5%", "thclass" => "left"), 'plugin_compatible' => array('title' => EPL_ADLAN_13, 'type' => 'method', 'data' => false, 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center',), 'plugin_description' => array('title' => LAN_DESCRIPTION, 'type' => 'textarea', 'data' => false, 'width' => 'auto', 'help' => '', 'readParms' => 'expand=1&truncate=180&bb=1', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',), 'plugin_path' => array('title' => LAN_PATH, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',), 'plugin_installflag' => array('title' => EPL_ADLAN_22, 'type' => 'boolean', 'data' => 'int', 'width' => 'auto', 'filter' => false, 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center',), 'plugin_addons' => array('title' => LAN_ADDONS, 'type' => 'method', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',), 'options' => array('title' => LAN_OPTIONS, 'type' => 'method', 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced' => '1',), ); } protected $menuTitle = ADLAN_98; } class plugin_ui extends e_admin_ui { protected $pluginTitle = ADLAN_98; protected $pluginName = 'core'; // protected $eventName = 'plugman-plugin'; // remove comment to enable event triggers in admin. protected $table = 'plugin'; protected $pid = 'plugin_id'; protected $perPage = 10; protected $batchDelete = false; protected $batchExport = false; protected $batchCopy = false; // protected $sortField = 'somefield_order'; // protected $orderStep = 10; // protected $tabs = array('Tabl 1','Tab 2'); // Use 'tab'=>0 OR 'tab'=>1 in the $fields below to enable. protected $listQry = "SELECT * FROM `#plugin` WHERE plugin_installflag = 1 AND plugin_category != 'menu' "; // Example Custom Query. LEFT JOINS allowed. Should be without any Order or Limit. protected $listOrder = 'plugin_path ASC'; protected $fields = array(); protected $fieldpref = array('plugin_icon', 'plugin_name', 'plugin_version', 'plugin_description', 'plugin_compatible', 'plugin_released','plugin_author', 'plugin_category','plugin_installflag'); // protected $preftabs = array('General', 'Other' ); protected $prefs = array( ); // Ideal way to set field data. public function __construct($request, $response, $params = array()) { $this->fields = plugman_adminArea::getPluginManagerFields(); $this->fields['plugin_category']['writeParms']['optArray'] = e107::getPlug()->getCategoryList(); // array('plugin_category_0','plugin_category_1', 'plugin_category_2'); // Example Drop-down array. unset($this->fields['plugin_category']['writeParms']['optArray']['menu']); unset($this->fields['plugin_category']['writeParms']['optArray']['about']); parent:: __construct($request, $response, $params); } public function init() { if(!e_QUERY) { e107::getPlug()->clearCache(); } if($this->getMode()=== 'avail') { $this->listQry = "SELECT * FROM `#plugin` WHERE plugin_installflag = 0 AND plugin_category != 'menu' "; } // Set drop-down values (if any). } // Modify the list data. public function ListObserver() { parent::ListObserver(); $this->setPlugData(); } private function setPlugData() { $tree = $this->getTreeModel(); $plg = e107::getPlug(); foreach ($tree->getTree() as $id => $model) { $path = $model->get('plugin_path'); $plg->load($path); $model->set('plugin_name',$plg->getName()); $model->set('plugin_date',$plg->getDate()); $model->set('plugin_author',$plg->getAuthor()); $model->set('plugin_compatible',$plg->getCompat()); $model->set('plugin_admin_url',$plg->getAdminUrl()); $model->set('plugin_admin_caption', $plg->getAdminCaption()); $model->set('plugin_description',$plg->getDescription()); $model->set('plugin_version_file',$plg->getVersion()); $model->set('plugin_install_required',$plg->getInstallRequired()); $model->set('plugin_icon',$plg->getIcon(32, 'path')); } } public function ListAjaxObserver() { $this->getTreeModel()->setParam('db_query', $this->_modifyListQry(false, false, 0, false, $this->listQry))->load(); $this->setPlugData(); } private function pluginProcessUpload() { if (!$_POST['ac'] == md5(ADMINPWCHANGE)) { exit; } $fl = e107::getFile(); $data = $fl->getUploaded(e_TEMP); $mes = e107::getMessage(); if(empty($data[0]['error'])) { if($fl->unzipArchive($data[0]['name'],'plugin')) { $mes->addSuccess(EPL_ADLAN_43); } else { $mes->addError(EPL_ADLAN_97); } } //echo $mes->render(); return true; } function renderHelp() { $plg = e107::getPlug(); if(!$list = $plg->getUpgradableList()) { return null; } $text = ""; return array('caption'=>"Updates to be Installed", 'text'=>$text); } // Action Pages. function installPage() { $id = $this->getId(); $text = e107::getPlugin()->install($id); $log = e107::getAdminLog(); if ($text === FALSE) { e107::getMessage()->add(EPL_ADLAN_99, E_MESSAGE_ERROR); } else { //$plugin->save_addon_prefs('update'); // $info = $plugin->getinfo($this->id); //FIXME use e107::getPlug(); // $name = deftrue($info['plugin_name'],$info['plugin_name']). " v".$info['plugin_version']. "({e_PLUGIN}".$info['plugin_path'].")"; // $log->log_event('PLUGMAN_01', $name, E_LOG_INFORMATIVE, ''); e107::getMessage()->add($text, E_MESSAGE_SUCCESS); } $this->redirectAction('list'); } function buildPage() { $pc = new pluginBuilder; $ret = $pc->run(); if(is_array($ret)) { $this->addTitle($ret['caption']); return $ret['text']; } return $ret; } function uninstallPage() { $id = $this->getId(); if(empty($_POST['uninstall_confirm'])) { $plug_vars = e107::getPlug()->load($id)->getMeta(); $name = e107::getPlug()->getName(); $this->addTitle(EPL_ADLAN_63); $this->addTitle($name); return $this->pluginConfirmUninstall($plug_vars); } $post = e107::getParser()->filter($_POST); if(empty($_POST['e-token'])) { return false; } // $id = e107::getPlugin $text = e107::getPlugin()->uninstall($id, $post); e107::getMessage()->add($text, E_MESSAGE_SUCCESS); $log = e107::getPlugin()->getLog(); e107::getDebug()->log($log); $this->redirectAction('list'); } function repairPage() { $id = $this->getId(); if(!e107::isInstalled($id)) { return false; } e107::getSingleton('e107plugin')->refresh($id); e107::getLog()->add('PLUGMAN_04', $id, E_LOG_INFORMATIVE, ''); $this->redirectAction('list'); } function pullPage() { $id = $this->getId(); if(!e107::isInstalled($id)) { $this->redirectAction('list'); } $return = e107::getFile()->gitPull($id, 'plugin'); e107::getMessage()->addSuccess($return); e107::getPlugin()->refresh($id); $this->redirectAction('list'); } function upgradePage() { $this->pluginUpgrade(); } function uploadPage() { global $plugin; $frm = e107::getForm(); if(!empty($_POST['upload'])) { $this->pluginProcessUpload(); $this->redirectAction('list'); } //TODO 'install' checkbox in plugin upload form. (as it is for theme upload) /* plugin upload form */ if(!is_writable(e_PLUGIN)) { $text = EPL_ADLAN_44; } else { // Get largest allowable file upload require_once(e_HANDLER.'upload_handler.php'); $max_file_size = get_user_max_upload(); $text = "
".EPL_ADLAN_37."
"; $text .= $frm->admin_button('upload', EPL_ADLAN_38, 'submit', EPL_ADLAN_38); $text .= "
\n"; } return $text; e107::getRender()->tablerender(ADLAN_98.SEP.EPL_ADLAN_38, $text); } private function pluginUpgrade() { $pref = e107::getPref(); $admin_log = e107::getAdminLog(); $plugin = e107::getPlugin(); $sql = e107::getDb(); $mes = e107::getMessage(); $id = $this->getId(); $plug = e107::getPlug()->load($id)->getMeta(); $text = ''; $_path = e_PLUGIN.$id.'/'; if(file_exists($_path.'plugin.xml')) { $plugin->install_plugin_xml($id, 'upgrade'); } else { $eplug_folder = null; $upgrade_alter_tables = null; $upgrade_add_prefs = null; $upgrade_remove_prefs = null; $upgrade_add_array_pref = null; $upgrade_remove_array_pref = null; $eplug_version = null; include(e_PLUGIN.$plug['plugin_path'].'/plugin.php'); $text = ''; $func = $eplug_folder.'_upgrade'; if (function_exists($func)) { $text .= call_user_func($func); } if (is_array($upgrade_alter_tables)) { $result = $plugin->manage_tables('upgrade', $upgrade_alter_tables); if (true !== $result) { //$text .= EPL_ADLAN_9.'
'; $mes->addWarning(EPL_ADLAN_9) ->addDebug($result); } else { $text .= EPL_ADLAN_7."
"; } } if (is_array($upgrade_add_prefs)) { $plugin->manage_prefs('add', $upgrade_add_prefs); $text .= EPL_ADLAN_8.'
'; } if (is_array($upgrade_remove_prefs)) { $plugin->manage_prefs('remove', $upgrade_remove_prefs); } if (is_array($upgrade_add_array_pref)) { foreach($upgrade_add_array_pref as $key => $val) { $plugin->manage_plugin_prefs('add', $key, $eplug_folder, $val); } } if (is_array($upgrade_remove_array_pref)) { foreach($upgrade_remove_array_pref as $key => $val) { $plugin->manage_plugin_prefs('remove', $key, $eplug_folder, $val); } } $plugin->manage_search('upgrade', $eplug_folder); $plugin->manage_notify('upgrade', $eplug_folder); $eplug_addons = $plugin -> getAddons($eplug_folder); $info = $plugin->getinfo($this->id); $name = deftrue($info['plugin_name'],$info['plugin_name']). " v".$eplug_version. "({e_PLUGIN}".$info['plugin_path'].")"; e107::getLog()->add('PLUGMAN_02', $name, E_LOG_INFORMATIVE, ''); $text .= (isset($eplug_upgrade_done)) ? '
'.$eplug_upgrade_done : "
".LAN_UPGRADE_SUCCESSFUL; $sql->update('plugin', "plugin_version ='{$eplug_version}', plugin_addons='{$eplug_addons}' WHERE plugin_id='$this->id' "); $pref['plug_installed'][$plug['plugin_path']] = $eplug_version; // Update the version e107::getConfig('core')->setPref($pref); $plugin->rebuildUrlConfig(); e107::getConfig('core')->save(); } $mes->addSuccess($text); $plugin->save_addon_prefs('update'); $this->redirectAction('list'); } private function pluginConfirmUninstall($plug_vars) { global $plugin; $frm = e107::getForm(); $tp = e107::getParser(); $mes = e107::getMessage(); $path = $plug_vars['folder']; // $plug = $plugin->getinfo($this->id); if(!e107::isInstalled($path)) { return false; } $userclasses = ''; $eufields = ''; if (isset($plug_vars['userClasses'])) { if (isset($plug_vars['userclass']['@attributes'])) { $plug_vars['userclass'][0]['@attributes'] = $plug_vars['userclass']['@attributes']; unset($plug_vars['userclass']['@attributes']); } $spacer = ''; foreach ($plug_vars['userClasses']['class'] as $uc) { $userclasses .= $spacer.$uc['@attributes']['name'].' - '.$uc['@attributes']['description']; $spacer = '
'; } } if (isset($plug_vars['extendedFields'])) { if (isset($plug_vars['extendedFields']['@attributes'])) { $plug_vars['extendedField'][0]['@attributes'] = $plug_vars['extendedField']['@attributes']; unset($plug_vars['extendedField']['@attributes']); } $spacer = ''; foreach ($plug_vars['extendedFields']['field'] as $eu) { $eufields .= $spacer.'plugin_'.$plug_vars['folder'].'_'.$eu['@attributes']['name']; $spacer = '
'; } } if(is_writable(e_PLUGIN.$path)) { $del_text = $frm->select('delete_files','yesno',0); } else { $del_text = " ".EPL_ADLAN_53." "; } $text = "
".EPL_ADLAN_54." ".$tp->toHtml($plug_vars['@attributes']['name'], "", "defs,emotes_off, no_make_clickable")." "; $opts = array(); $opts['delete_tables'] = array( 'label' => EPL_ADLAN_57, 'helpText' => EPL_ADLAN_58, 'itemList' => array(1=>LAN_YES,0=>LAN_NO), 'itemDefault' => 1 ); if ($userclasses) { $opts['delete_userclasses'] = array( 'label' => EPL_ADLAN_78, 'preview' => $userclasses, 'helpText' => EPL_ADLAN_79, 'itemList' => array(1=>LAN_YES,0=>LAN_NO), 'itemDefault' => 1 ); } if ($eufields) { $opts['delete_xfields'] = array( 'label' => EPL_ADLAN_80, 'preview' => $eufields, 'helpText' => EPL_ADLAN_79, 'itemList' => array(1=>LAN_YES,0=>LAN_NO), 'itemDefault' => 0 ); } $med = e107::getMedia(); $icons = $med->listIcons(e_PLUGIN.$path); $iconText = ''; if(count($icons)>0) { foreach($icons as $key=>$val) { $iconText .= ""; } $iconText = '
'.$iconText.'
'; $opts['delete_ipool'] = array( 'label' => EPL_ADLAN_231, 'preview' => $iconText, 'helpText' => EPL_ADLAN_79, 'itemList' => array(1=>LAN_YES,0=>LAN_NO), 'itemDefault' => 1 ); } if(is_readable(e_PLUGIN.$path."/".$path."_setup.php")) { include_once(e_PLUGIN.$path."/".$path."_setup.php"); $mes->add("Loading ".e_PLUGIN.$path."/".$path."_setup.php", E_MESSAGE_DEBUG); $class_name = $path."_setup"; if(class_exists($class_name)) { $obj = new $class_name; if(method_exists($obj,'uninstall_options')) { $arr = call_user_func(array($obj,'uninstall_options'), $this); foreach($arr as $key=>$val) { $newkey = $path."_".$key; $opts[$newkey] = $val; } } } } foreach($opts as $key=>$val) { $text .= "\n\n\n\n"; } $text .="
".EPL_ADLAN_55." ".LAN_YES."
".$tp->toHTML($val['label'],FALSE,'TITLE'); $text .= varset($val['preview']) ? "
".$val['preview']."
" : ""; $text .= "
".$frm->select($key,$val['itemList'],$val['itemDefault']); $text .= varset($val['helpText']) ? "
".$val['helpText']."
" : ""; $text .= "
".EPL_ADLAN_59." {$del_text}
".EPL_ADLAN_60."
"; $text .= $frm->admin_button('uninstall_confirm',EPL_ADLAN_3,'submit'); $text .= $frm->admin_button('uninstall_cancel',EPL_ADLAN_62,'cancel'); /* $text .= "   "; */ // $frm->admin_button($name, $value, $action = 'submit', $label = '', $options = array()); $text .= "
"; return $text; // e107::getRender()->tablerender(EPL_ADLAN_63.SEP.$tp->toHtml($plug_vars['@attributes']['name'], "", "defs,emotes_off, no_make_clickable"),$mes->render(). $text); } /* // optional - a custom page. public function customPage() { $text = 'Hello World!'; $otherField = $this->getController()->getFieldVar('other_field_name'); return $text; } */ } class plugin_form_ui extends e_admin_form_ui { // Custom Method/Function function plugin_compatible($curVal,$mode) { $frm = e107::getForm(); switch($mode) { case 'read': // List Page if(intval($curVal) > 1) { return "".$curVal.""; } return $curVal; break; case 'write': // Edit Page return $frm->text('plugin_name',$curVal, 255, 'size=large'); break; case 'filter': case 'batch': return array(); break; } } // Custom Method/Function function plugin_addons($curVal,$mode) { $frm = e107::getForm(); switch($mode) { case 'read': // List Page return $curVal; break; case 'write': // Edit Page return $frm->text('plugin_addons',$curVal, 255, 'size=large'); break; case 'filter': case 'batch': return array(); break; } } function options($val, $curVal) { $tp = e107::getParser(); $var = $this->getController()->getListModel()->getData(); $mode = $this->getController()->getMode(); // e107::getDebug()->log($var); $_path = e_PLUGIN . $var['plugin_path'] . '/'; if($var['plugin_admin_url'] && $var['plugin_installflag'] == true) { $conf_title = !empty($var['plugin_admin_caption']) ? $var['plugin_admin_caption'] : LAN_CONFIGURE . ' ' . $tp->toHTML($var['plugin_name'], "", "defs,emotes_off, no_make_clickable"); $plugin_config_icon = "" . ADMIN_CONFIGURE_ICON . ""; } $text = "
"; $text .= vartrue($plugin_config_icon); if($var['plugin_install_required'] == true) { if($var['plugin_installflag']) { $text .= ($var['plugin_installflag'] ? "" . ADMIN_UNINSTALLPLUGIN_ICON . "" : "" . ADMIN_INSTALLPLUGIN_ICON . ""); } else { $text .= "" . ADMIN_INSTALLPLUGIN_ICON . ""; } } else { if($var['menuName']) { // $text .= EPL_NOINSTALL . str_replace("..", "", e_PLUGIN . $var['plugin_path']) . "/ " . EPL_DIRECTORY; } else { // $text .= EPL_NOINSTALL_1 . str_replace("..", "", e_PLUGIN . $var['plugin_path']) . "/ " . EPL_DIRECTORY; if($var['plugin_installflag'] == false) { // e107::getDb()->delete('plugin', "plugin_installflag=0 AND (plugin_path='{$var['plugin_path']}' OR plugin_path='{$var['plugin_path']}/' ) "); } } } if($var['plugin_version'] != $var['plugin_version_file'] && $var['plugin_installflag']) { $text .= "" . ADMIN_UPGRADEPLUGIN_ICON . ""; } if($var['plugin_installflag'] && e_DEBUG == true) { $text .= " " . ADMIN_REPAIRPLUGIN_ICON . ""; } if($var['plugin_installflag'] && is_dir($_path . ".git")) { $text .= " " . ADMIN_GITSYNC_ICON . ""; } $text .= "
"; return $text; } } class plugin_online_ui extends e_admin_ui { protected $pluginTitle = ADLAN_98; protected $pluginName = 'core'; // protected $eventName = 'plugman-plugin'; // remove comment to enable event triggers in admin. protected $table = false; protected $pid = ''; protected $perPage = 10; protected $batchDelete = true; protected $batchExport = true; protected $batchCopy = true; // protected $sortField = 'somefield_order'; // protected $orderStep = 10; // protected $tabs = array('Tabl 1','Tab 2'); // Use 'tab'=>0 OR 'tab'=>1 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 = ''; protected $fields = array (); protected $fieldpref = array('plugin_icon', 'plugin_name', 'plugin_version', 'plugin_license', 'plugin_description', 'plugin_compatible', 'plugin_released','plugin_author', 'plugin_category','plugin_installflag'); // protected $preftabs = array('General', 'Other' ); protected $prefs = array( ); protected $mp = null; public function __construct($request, $response, $params = array()) { $this->fields = plugman_adminArea::getPluginManagerFields(); $this->fields['plugin_category']['writeParms']['optArray'] = e107::getPlug()->getCategoryList(); // array('plugin_category_0','plugin_category_1', 'plugin_category_2'); // Example Drop-down array. $this->fields["plugin_license"]['nolist'] = false; parent:: __construct($request, $response, $params); } public function init() { require_once(e_HANDLER.'e_marketplace.php'); } function pluginCheck($force=false) { if(!PLUGIN_SCAN_INTERVAL) { e107::getPlugin()->update_plugins_table('update'); return; } if((time() > vartrue($_SESSION['nextPluginFolderScan'],0)) || $force == true) { e107::getPlugin()->update_plugins_table('update'); } $_SESSION['nextPluginFolderScan'] = time() + PLUGIN_SCAN_INTERVAL; //echo "TIME = ".$_SESSION['nextPluginFolderScan']; } // Modal Download. public function downloadPage() { $frm = e107::getForm(); $mes = e107::getMessage(); $tp = e107::getParser(); // print_a($_GET); $string = base64_decode($_GET['src']); parse_str($string, $data); if(deftrue('e_DEBUG_MARKETPLACE')) { echo "DEBUG MODE ACTIVE (no downloading)
"; echo '$_GET[src]: '; print_a($_GET); echo 'base64 decoded and parsed as $data:'; print_a($data); return false; } $pluginFolder = !empty($data['plugin_folder']) ? $tp->filter($data['plugin_folder']) : ''; $pluginUrl = !empty($data['plugin_url']) ? $tp->filter($data['plugin_url']) : ''; $pluginID = !empty($data['plugin_id']) ? $tp->filter($data['plugin_id']) : ''; $pluginMode = !empty($data['plugin_mode']) ? $tp->filter($data['plugin_mode']) : ''; if(!empty($data['plugin_price'])) { e107::getRedirect()->go($pluginUrl); return true; } $mp = $this->getMarketplace(); // $mp->generateAuthKey($e107SiteUsername, $e107SiteUserpass); // Server flush useless. It's ajax ready state 4, we can't flush (sadly) before that (at least not for all browsers) $mes->addSuccess(EPL_ADLAN_94); if($mp->download($pluginID, $pluginMode, 'plugin')) { $this -> pluginCheck(true); // rescan the plugin directory $text = e107::getPlugin()->install($pluginFolder); $mes->addInfo($text); echo $mes->render('default', 'success'); } else { // Unable to continue echo $mes->addError(EPL_ADLAN_95)->render('default', 'error'); } echo $mes->render('default', 'debug'); return null; } public function ListObserver() { // parent::ListObserver(); $this->setPlugData(); } /** * @return e_marketplace|null */ public function getMarketplace() { if(null === $this->mp) { $this->mp = new e_marketplace(); // autodetect the best method } return $this->mp; } private function compatibilityLabel($val='') { $badge = (vartrue($val) > 1.9) ? "".EPL_ADLAN_88."" : '1.x'; return $badge; } function options($data) { // print_a($data); /* if(!e107::getFile()->hasAuthKey()) { // return "Download and Install"; } */ if($data['plugin_installflag']) { return null; } //$url = e_SELF."?src=".base64_encode($d); // $url = e_SELF.'?action=download&src='.base64_encode($d);//$url.'&action=download'; $id = 'plug_'.$data['plugin_id']; // $modalCaption = (!empty($data['plugin_price'])) ? EPL_ADLAN_92." ".$data['plugin_name']." ".$data['plugin_version'] : EPL_ADLAN_230." ".$data['plugin_name']." ".$data['plugin_version']; $srcData = array( 'plugin_id' => $data['plugin_id'], 'plugin_folder' => $data['plugin_folder'], 'plugin_price' => $data['plugin_price'], 'plugin_mode' => $data['plugin_mode'], 'plugin_url' => $data['plugin_url'], ); $url = $this->getMarketplace()->getDownloadModal('plugin', $srcData); // $d = http_build_query($srcData,false,'&'); // $url = e_SELF.'?mode=download&src='.base64_encode($d); $dicon = ''.ADMIN_INSTALLPLUGIN_ICON.''; /* // DEBUGGER . $base64 = base64_encode($d); $tmp = base64_decode($base64); parse_str($tmp, $data); // XXX Suhosin has a 512 char limit for $_GET strings. e107::getDebug()->log($data['plugin_name'].' : '.strlen($base64)."
".print_a($data,true)); //FIXME - enable when needed to debug. */ // Temporary Pop-up version. // $dicon = ''; // $dicon = " "; return "
{$dicon}
"; } private function setPlugData() { // $this->setTreeModel(); /* $tree = $this->getTreeModel(); $plg = e107::getPlug(); foreach ($tree->getTree() as $id => $model) { $path = $model->get('plugin_path'); $plg->load($path); $model->set('plugin_name',$plg->getName()); $model->set('plugin_date',$plg->getDate()); $model->set('plugin_author',$plg->getAuthor()); $model->set('plugin_compatible',$plg->getCompat()); $model->set('plugin_admin_url',$plg->getAdminUrl()); $model->set('plugin_description',$plg->getDescription()); $model->set('plugin_version_file',$plg->getVersion()); $model->set('plugin_install_required',$plg->getInstallRequired()); $model->set('plugin_icon',$plg->getIcon(32, 'path')); }*/ } public function listPage() { global $plugin, $e107SiteUsername, $e107SiteUserpass; $tp = e107::getParser(); $frm = $this->getUI(); $caption = EPL_ADLAN_89; $e107 = e107::getInstance(); $xml = e107::getXml(); $mes = e107::getMessage(); // $mes->addWarning("Some older plugins may produce unpredictable results."); // check for cURL if(!function_exists('curl_init')) { $mes->addWarning(EPL_ADLAN_90); } //TODO use admin_ui including filter capabilities by sending search queries back to the xml script. $from = isset($_GET['frm']) ? intval($_GET['frm']) : 0; $srch = preg_replace('/[^\w]/','', vartrue($_GET['srch'])); $mp = $this->getMarketplace(); // auth $mp->generateAuthKey($e107SiteUsername, $e107SiteUserpass); // do the request, retrieve and parse data $xdata = $mp->call('getList', array( 'type' => 'plugin', 'params' => array('limit' => 10, 'search' => $srch, 'from' => $from) )); $total = $xdata['params']['count']; // OLD BIT OF CODE -------------------------------> /* // $file = SITEURLBASE.e_PLUGIN_ABS."release/release.php"; // temporary testing $file = "http://e107.org/feed?type=plugin&frm=".$from."&srch=".$srch."&limit=10"; $xml->setOptArrayTags('plugin'); // make sure 'plugin' tag always returns an array $xdata = $xml->loadXMLfile($file,'advanced'); $total = $xdata['@attributes']['total']; echo 'file='.$file; // print_a($xdata); $xdata['data'] = $xdata['plugin']; */ // OLD BIT OF CODE END -------------------------------> // print_a($xdata); $c = 1; foreach($xdata['data'] as $row) { //$row = $r['@attributes']; // print_a($row); $badge = $this->compatibilityLabel($row['compatibility']);; $featured = ($row['featured']== 1) ? " ".EPL_ADLAN_91."" : ''; $price = (!empty($row['price'])) ? "".$row['price']." ".$row['currency']."" : "".EPL_ADLAN_93.""; $data[] = array( 'plugin_id' => $row['params']['id'], 'plugin_mode' => $row['params']['mode'], 'plugin_icon' => vartrue($row['icon'],'e-plugins-32'), 'plugin_name' => stripslashes($row['name']), 'plugin_featured' => $featured, 'plugin_sef' => '', 'plugin_folder' => $row['folder'], 'plugin_date' => vartrue($row['date']), 'plugin_category' => vartrue($row['category'], 'n/a'), 'plugin_author' => vartrue($row['author']), 'plugin_version' => $row['version'], 'plugin_description' => nl2br(vartrue($row['description'])), 'plugin_compatible' => $badge, 'plugin_website' => vartrue($row['authorUrl']), 'plugin_url' => $row['urlView'], 'plugin_notes' => '', 'plugin_price' => $row['price'], 'plugin_license' => $price, 'plugin_installflag' => e107::isInstalled($row['folder']) ); $c++; } $fieldList = $this->fields; unset($fieldList['checkboxes']); $text = "
".$caption." ".$frm->colGroup($fieldList,$this->fieldpref). $frm->thead($fieldList,$this->fieldpref)." "; foreach($data as $key=>$val ) { // print_a($val); $text .= ""; foreach($this->fields as $v=>$foo) { if(!in_array($v,$this->fieldpref) || $v == 'checkboxes') { continue; } $_value = $val[$v]; if($v == 'plugin_name') $_value .= $val['plugin_featured']; // echo '
v='.$v; $text .= "\n"; } $text .= ""; $text .= ""; } $text .= "
".$frm->renderValue($v, $_value, $this->fields[$v], $key)."".$this->options($val)."
"; $text .= "
"; $amount = 30; if($total > $amount) { $parms = $total.",".$amount.",".$from.",".e_SELF.'?mode=online&action=list&frm=[FROM]'; if(!empty($srch)) { $parms .= '&srch='.$srch; } $text .= "
".$tp->parseTemplate("{NEXTPREV=$parms}",TRUE)."
"; } return $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 } /* // optional - a custom page. public function customPage() { $text = 'Hello World!'; $otherField = $this->getController()->getFieldVar('other_field_name'); return $text; } */ } class plugin_form_online_ui extends e_admin_form_ui { // Custom Method/Function function plugin_name($curVal,$mode) { $frm = e107::getForm(); switch($mode) { case 'read': // List Page return $curVal; break; case 'write': // Edit Page return $frm->text('plugin_name',$curVal, 255, 'size=large'); break; case 'filter': case 'batch': return array(); break; } } // Custom Method/Function function plugin_addons($curVal,$mode) { $frm = e107::getForm(); switch($mode) { case 'read': // List Page return $curVal; break; case 'write': // Edit Page return $frm->text('plugin_addons',$curVal, 255, 'size=large'); break; case 'filter': case 'batch': return array(); break; } } } //if(deftrue('e_DEBUG_PLUGMANAGER')) { new plugman_adminArea(); require_once(e_ADMIN."auth.php"); e107::getAdminUI()->runPage(); require_once(e_ADMIN."footer.php"); exit; } // -------------------------------------- /* class pluginmanager_form extends e_form { var $plug; var $plug_vars; //FIXME _ there's a problem with calling this. function plugin_website($parms, $value, $id, $attributes) { return (varset($plugURL, false)) ? "".ADMIN_URL_ICON."" : ""; } function options($val, $curVal) { $tp = e107::getParser(); $_path = e_PLUGIN.$this->plug['plugin_path'].'/'; $icon_src = (isset($this->plug_vars['plugin_php']) ? e_PLUGIN : $_path).$this->plug_vars['administration']['icon']; $plugin_icon = $this->plug_vars['administration']['icon'] ? "" : $tp->toGlyph('e-cat_plugins-32'); $conf_file = "#"; $conf_title = ""; if ($this->plug_vars['administration']['configFile'] && $this->plug['plugin_installflag'] == true) { $conf_file = e_PLUGIN. $this->plug['plugin_path'].'/'.$this->plug_vars['administration']['configFile']; $conf_title = LAN_CONFIGURE.' '.$tp->toHTML($this->plug_vars['@attributes']['name'], "", "defs,emotes_off, no_make_clickable"); $plugin_icon = "".$plugin_icon.""; $plugin_config_icon = "".ADMIN_CONFIGURE_ICON.""; } $text = "
"; $text .= vartrue($plugin_config_icon); if ($this->plug_vars['@attributes']['installRequired']) { if ($this->plug['plugin_installflag']) { $text .= ($this->plug['plugin_installflag'] ? "plug['plugin_id']}\" title='".EPL_ADLAN_1."' >".ADMIN_UNINSTALLPLUGIN_ICON."" : "plug['plugin_id']}\" title='".EPL_ADLAN_0."' >".ADMIN_INSTALLPLUGIN_ICON.""); // $text .= ($this->plug['plugin_installflag'] ? "" : ""); if (e_DEBUG && !vartrue($this->plug_vars['plugin_php'])) { // $text .= "

plug['plugin_id']}'\" title='".'Refresh plugin settings'."' value='".'Refresh plugin settings'."' /> "; } } else { // $text .= "plug['plugin_id']}'\" title='".EPL_ADLAN_0."' value='".EPL_ADLAN_0."' />"; // $text .= ""; $text .= "plug['plugin_id']}\" title='".EPL_ADLAN_0."' >".ADMIN_INSTALLPLUGIN_ICON.""; } } else { if ($this->plug_vars['menuName']) { $text .= EPL_NOINSTALL.str_replace("..", "", e_PLUGIN.$this->plug['plugin_path'])."/ ".EPL_DIRECTORY; } else { $text .= EPL_NOINSTALL_1.str_replace("..", "", e_PLUGIN.$this->plug['plugin_path'])."/ ".EPL_DIRECTORY; if($this->plug['plugin_installflag'] == false) { e107::getDb()->delete('plugin', "plugin_installflag=0 AND (plugin_path='{$this->plug['plugin_path']}' OR plugin_path='{$this->plug['plugin_path']}/' ) "); } } } if ($this->plug['plugin_version'] != $this->plug_vars['@attributes']['version'] && $this->plug['plugin_installflag']) { // $text .= "
plug['plugin_id']}'\" title='".EPL_UPGRADE." to v".$this->plug_vars['@attributes']['version']."' value='".EPL_UPGRADE."' />"; e107::getMessage()->addInfo("".$tp->toHtml($this->plug['plugin_name'],false,'TITLE')." is ready to be upgraded. (see below)"); // TODO LAN $text .= "plug_vars['@attributes']['version']."\" >".ADMIN_UPGRADEPLUGIN_ICON.""; } if ($this->plug['plugin_installflag'] && e_DEBUG == true) { $text .= " ".ADMIN_REPAIRPLUGIN_ICON.""; } if($this->plug['plugin_installflag'] && is_dir($_path.".git")) { $text .= " ".ADMIN_GITSYNC_ICON.""; } $text .="
"; return $text; } } */ /* require_once("auth.php"); $pman->pluginObserver(); $mes = e107::getMessage(); $frm = e107::getForm();*/ require_once("footer.php"); exit; // FIXME switch to admin UI /* class pluginManager{ var $plugArray; var $action; var $id; var $frm; var $fieldpref; var $titlearray = array(); var $pagetitle; var $mp; protected $pid = 'plugin_id'; protected $fields = array( "checkboxes" => array("title" => "", 'type'=>null, "forced"=>TRUE, "width"=>"3%", 'thclass'=>'center','class'=>'center'), "plugin_icon" => array("title" => EPL_ADLAN_82, "type"=>"icon", "width" => "5%", "thclass" => "middle center",'class'=>'center', "url" => ""), "plugin_name" => array("title" => EPL_ADLAN_10, 'forced'=>true, "type"=>"text", "width" => "auto", 'class'=>'left', "thclass" => "middle", "url" => ""), "plugin_version" => array("title" => EPL_ADLAN_11, "type"=>"numeric", "width" => "5%", "thclass" => "middle", "url" => ""), "plugin_date" => array("title" => LAN_RELEASED, "type"=>"text", "width" => "8%", "thclass" => "middle"), "plugin_folder" => array("title" => EPL_ADLAN_64, "type"=>"text", "width" => "10%", "thclass" => "middle"), "plugin_category" => array("title" => LAN_CATEGORY, "type"=>"text", "width" => "auto", "thclass" => "middle"), "plugin_author" => array("title" => LAN_AUTHOR, "type"=>"text", "width" => "10%", "thclass" => "middle"), "plugin_license" => array("title" => "License", 'nolist'=>true, "forced"=>true, "type"=>"text", "width" => "5%", "thclass" => "left"), // "plugin_price" => array("title" => "Price", 'nolist'=>true, "forced"=>true, "type"=>"text", "width" => "5%", "thclass" => "left"), "plugin_compatible" => array("title" => EPL_ADLAN_13, "type"=>"text", "width" => "5%", "thclass" => "middle"), "plugin_description" => array("title" => EPL_ADLAN_14, "type"=>"bbarea", "width" => "30%", "thclass" => "middle center", 'readParms' => 'expand=1&truncate=180&bb=1'), "plugin_compliant" => array("title" => EPL_ADLAN_81, "type"=>"text", "width" => "5%", "thclass" => "middle center", "url" => ""), // "plugin_release" => array("title" => EPL_ADLAN_81, "type"=>"text", "width" => "5%", "thclass" => "middle center", "url" => ""), // "plugin_notes" => array("title" => EPL_ADLAN_83, "type"=>"url", "width" => "5%", "thclass" => "middle center", "url" => ""), "options" => array("title" => LAN_OPTIONS, 'forced'=>TRUE, 'type'=> 'method', "width" => "15%", "thclass" => "right last", 'class'=>'right'), ); function __construct() { global $user_pref,$admin_log; $qry = str_replace('XDEBUG_PROFILE', '', e_QUERY); $tmp = explode('.',$qry); $this -> action = ($tmp[0]) ? $tmp[0] : "installed"; $this -> id = !empty($tmp[1]) ? intval($tmp[1]) : ""; $this -> titlearray = array('installed'=>EPL_ADLAN_22,'avail'=>EPL_ADLAN_23, 'upload'=>EPL_ADLAN_38); if(isset($_GET['mode'])) { $this->action = $_GET['mode']; } if($this->action == 'online') { // $this->fields["plugin_price"]['nolist'] = false; // = array("title" => "Price", "forced"=>true, "type"=>"text", "width" => "5%", "thclass" => "middle center"); $this->fields["plugin_license"]['nolist'] = false; } $keys = array_keys($this -> titlearray); $this->pagetitle = (in_array($this->action,$keys)) ? $this -> titlearray[$this->action] : $this -> titlearray['installed']; } public function getMarketplace() { if(null === $this->mp) { require_once(e_HANDLER.'e_marketplace.php'); $this->mp = new e_marketplace(); // autodetect the best method } return $this->mp; } function pluginObserver() { $tp = e107::getParser(); global $user_pref,$admin_log; if (isset($_POST['upload'])) { $this -> pluginProcessUpload(); $this->action = 'avail'; } if(isset($_POST['etrigger_ecolumns'])) { $user_pref['admin_pluginmanager_columns'] = $tp->filter($_POST['e-columns']); save_prefs('user'); } $user_pref['admin_pluginmanager_columns'] = false; $this -> fieldpref = (vartrue($user_pref['admin_pluginmanager_columns'])) ? $user_pref['admin_pluginmanager_columns'] : array("plugin_icon","plugin_name","plugin_version","plugin_date","plugin_description","plugin_category","plugin_compatible","plugin_author","plugin_website","plugin_notes"); foreach($this->fields as $key=>$val) { if(vartrue($val['forced']) && substr($key,0,6)=='plugin') { $this->fieldpref[] = $key; } } if($this->action == 'download') { $this->pluginDownload(); return; } if($this->action == 'pull' && !empty($this->id)) { $info = e107::getPlugin()->getinfo($this->id); if(!empty($info['plugin_path'])) { $return = e107::getFile()->gitPull($info['plugin_path'], 'plugin'); e107::getMessage()->addSuccess($return); $this->action = 'refresh'; } else { $this->action = 'avail'; } } if($this->action == 'avail' || $this->action == 'installed') // Plugin Check is done during upgrade_routine. { $this -> pluginCheck(); } if($this->action == "uninstall") { $this -> pluginUninstall(); $this -> pluginCheck(true); // forced } if($this->action == "repair") { $this -> pluginRepair(); $this->action = 'refresh'; } if($this->action == "refresh") { $this -> pluginCheck(true); // forced } if($this->action == "install" || $this->action == "refresh") { $this -> pluginInstall(); $this -> action = "installed"; } if($this->action == 'create') { $pc = new pluginBuilder; return; } if($this->action == 'lans') { $pc = new pluginLanguage; return; } if($this->action == "upgrade") { $this -> pluginUpgrade(); $this -> action = "installed"; } if($this->action == "upload") { $this -> pluginUpload(); } if($this->action == "online") { $text = $this -> pluginOnline(); $mes = e107::getMessage(); e107::getRender()->tablerender(ADLAN_98.SEP.$caption, $mes->render(). $text); return; } // print_a($_POST); if(isset($_POST['install-selected'])) { foreach($_POST['multiselect'] as $val) { $this -> id = intval($val); $this -> pluginInstall(); } $this -> action = "installed"; } if($this->action != 'avail' && varset($this->fields['checkboxes'])) { unset($this->fields['checkboxes']); // = FALSE; } if($this->action !='upload' && $this->action !='uninstall') { $this -> pluginRenderList(); } } private function compatibilityLabel($val='') { $badge = (vartrue($val) > 1.9) ? "".EPL_ADLAN_88."" : '1.x'; return $badge; } function pluginOnline() { global $plugin, $e107SiteUsername, $e107SiteUserpass; $tp = e107::getParser(); $frm = e107::getForm(); $caption = EPL_ADLAN_89; $e107 = e107::getInstance(); $xml = e107::getXml(); $mes = e107::getMessage(); // $mes->addWarning("Some older plugins may produce unpredictable results."); // check for cURL if(!function_exists('curl_init')) { $mes->addWarning(EPL_ADLAN_90); } //TODO use admin_ui including filter capabilities by sending search queries back to the xml script. $from = isset($_GET['frm']) ? intval($_GET['frm']) : 0; $srch = preg_replace('/[^\w]/','', vartrue($_GET['srch'])); $mp = $this->getMarketplace(); // auth $mp->generateAuthKey($e107SiteUsername, $e107SiteUserpass); // do the request, retrieve and parse data $xdata = $mp->call('getList', array( 'type' => 'plugin', 'params' => array('limit' => 10, 'search' => $srch, 'from' => $from) )); $total = $xdata['params']['count']; // OLD BIT OF CODE -------------------------------> // OLD BIT OF CODE END -------------------------------> // print_a($xdata); $c = 1; foreach($xdata['data'] as $row) { //$row = $r['@attributes']; // print_a($row); $badge = $this->compatibilityLabel($row['compatibility']);; $featured = ($row['featured']== 1) ? " ".EPL_ADLAN_91."" : ''; $price = (!empty($row['price'])) ? "".$row['price']." ".$row['currency']."" : "".EPL_ADLAN_93.""; $data[] = array( 'plugin_id' => $row['params']['id'], 'plugin_mode' => $row['params']['mode'], 'plugin_icon' => vartrue($row['icon'],'e-plugins-32'), 'plugin_name' => stripslashes($row['name']), 'plugin_featured' => $featured, 'plugin_sef' => '', 'plugin_folder' => $row['folder'], 'plugin_date' => vartrue($row['date']), 'plugin_category' => vartrue($row['category'], 'n/a'), 'plugin_author' => vartrue($row['author']), 'plugin_version' => $row['version'], 'plugin_description' => nl2br(vartrue($row['description'])), 'plugin_compatible' => $badge, 'plugin_website' => vartrue($row['authorUrl']), 'plugin_url' => $row['urlView'], 'plugin_notes' => '', 'plugin_price' => $row['price'], 'plugin_license' => $price ); $c++; } $fieldList = $this->fields; unset($fieldList['checkboxes']); $text = "
".$caption." ".$frm->colGroup($fieldList,$this->fieldpref). $frm->thead($fieldList,$this->fieldpref)." "; foreach($data as $key=>$val ) { // print_a($val); $text .= ""; foreach($this->fields as $v=>$foo) { if(!in_array($v,$this->fieldpref) || $v == 'checkboxes') { continue; } $_value = $val[$v]; if($v == 'plugin_name') $_value .= $val['plugin_featured']; // echo '
v='.$v; $text .= "\n"; } $text .= ""; $text .= ""; } $text .= "
".$frm->renderValue($v, $_value, $this->fields[$v], $key)."".$this->options($val)."
"; $text .= "
"; $amount = 30; if($total > $amount) { $parms = $total.",".$amount.",".$from.",".e_SELF.'?mode=online&frm=[FROM]'; if(!empty($srch)) { $parms .= '&srch='.$srch; } $text .= "
".$tp->parseTemplate("{NEXTPREV=$parms}",TRUE)."
"; } return $text; } function options($data) { // print_a($data); //$url = e_SELF."?src=".base64_encode($d); // $url = e_SELF.'?action=download&src='.base64_encode($d);//$url.'&action=download'; $id = 'plug_'.$data['plugin_id']; // $modalCaption = (!empty($data['plugin_price'])) ? EPL_ADLAN_92." ".$data['plugin_name']." ".$data['plugin_version'] : EPL_ADLAN_230." ".$data['plugin_name']." ".$data['plugin_version']; $srcData = array( 'plugin_id' => $data['plugin_id'], 'plugin_folder' => $data['plugin_folder'], 'plugin_price' => $data['plugin_price'], 'plugin_mode' => $data['plugin_mode'], 'plugin_url' => $data['plugin_url'], ); $d = http_build_query($srcData,false,'&'); $url = e_SELF.'?mode=download&src='.base64_encode($d); $dicon = ''.ADMIN_INSTALLPLUGIN_ICON.''; // Temporary Pop-up version. // $dicon = ''; // $dicon = " "; return "
{$dicon}
"; } private function pluginDownload() { define('e_IFRAME', true); $frm = e107::getForm(); $mes = e107::getMessage(); $tp = e107::getParser(); // print_a($_GET); $string = base64_decode($_GET['src']); parse_str($string, $data); if(deftrue('e_DEBUG_MARKETPLACE')) { echo "DEBUG MODE ACTIVE (no downloading)
"; echo '$_GET[src]: '; print_a($_GET); echo 'base64 decoded and parsed as $data:'; print_a($data); return false; } $pluginFolder = !empty($data['plugin_folder']) ? $tp->filter($data['plugin_folder']) : ''; $pluginUrl = !empty($data['plugin_url']) ? $tp->filter($data['plugin_url']) : ''; $pluginID = !empty($data['plugin_id']) ? $tp->filter($data['plugin_id']) : ''; $pluginMode = !empty($data['plugin_mode']) ? $tp->filter($data['plugin_mode']) : ''; if(!empty($data['plugin_price'])) { e107::getRedirect()->go($pluginUrl); return true; } $mp = $this->getMarketplace(); // $mp->generateAuthKey($e107SiteUsername, $e107SiteUserpass); // Server flush useless. It's ajax ready state 4, we can't flush (sadly) before that (at least not for all browsers) $mes->addSuccess(EPL_ADLAN_94); if($mp->download($pluginID, $pluginMode, 'plugin')) { $this -> pluginCheck(true); // rescan the plugin directory $text = e107::getPlugin()->install($pluginFolder); $mes->addInfo($text); echo $mes->render('default', 'success'); } else { // Unable to continue echo $mes->addError(EPL_ADLAN_95)->render('default', 'error'); } echo $mes->render('default', 'debug'); return; $text =""; // print_a($data); $text .= $frm->open('upload-url-form','post'); $text .= "
"; $text .= ""; $text .= $frm->admin_button('upload_remote_url',1,'create','Install'); $text .= "
"; $text .= "\n\n"; $text .= $frm->close(); echo $text; } function pluginUninstall() { if(!isset($_POST['uninstall_confirm'])) { // $id is already an integer $this->pluginConfirmUninstall(); return; } $post = e107::getParser()->filter($_POST); $text = e107::getPlugin()->uninstall($this->id, $post); $this->show_message($text, E_MESSAGE_SUCCESS); $this->action = 'installed'; $log = e107::getPlugin()->getLog(); e107::getDebug()->log($log); return; } function pluginProcessUpload() { if (!$_POST['ac'] == md5(ADMINPWCHANGE)) { exit; } $fl = e107::getFile(); $data = $fl->getUploaded(e_TEMP); $mes = e107::getMessage(); if(empty($data[0]['error'])) { if($fl->unzipArchive($data[0]['name'],'plugin')) { $mes->addSuccess(EPL_ADLAN_43); } else { $mes->addError(EPL_ADLAN_97); } } // $data = process_uploaded_files(e_TEMP); // print_a($data); echo $mes->render(); return true; } // ----------------------------------------------------------------------------- // TODO FIXME - This needs cleaning: e107::getMessage(), limit the globals, etc. function pluginInstall() { global $plugin; $text = $plugin->install_plugin($this->id); $log = e107::getAdminLog(); if ($text === FALSE) { // Tidy this up $this->show_message(EPL_ADLAN_99, E_MESSAGE_ERROR); } else { $plugin->save_addon_prefs('update'); $info = $plugin->getinfo($this->id); $name = deftrue($info['plugin_name'],$info['plugin_name']). " v".$info['plugin_version']. "({e_PLUGIN}".$info['plugin_path'].")"; $log->log_event('PLUGMAN_01', $name, E_LOG_INFORMATIVE, ''); $this->show_message($text, E_MESSAGE_SUCCESS); } } // ----------------------------------------------------------------------------- function pluginUpgrade() { $pref = e107::getPref(); $admin_log = e107::getAdminLog(); $plugin = e107::getPlugin(); $sql = e107::getDb(); $mes = e107::getMessage(); $plug = $plugin->getinfo($this->id); $text = ''; $_path = e_PLUGIN.$plug['plugin_path'].'/'; if(file_exists($_path.'plugin.xml')) { $plugin->install_plugin_xml($this->id, 'upgrade'); } else { $eplug_folder = null; $upgrade_alter_tables = null; $upgrade_add_prefs = null; $upgrade_remove_prefs = null; $upgrade_add_array_pref = null; $upgrade_remove_array_pref = null; $eplug_version = null; include(e_PLUGIN.$plug['plugin_path'].'/plugin.php'); $text = ''; $func = $eplug_folder.'_upgrade'; if (function_exists($func)) { $text .= call_user_func($func); } if (is_array($upgrade_alter_tables)) { $result = $plugin->manage_tables('upgrade', $upgrade_alter_tables); if (true !== $result) { //$text .= EPL_ADLAN_9.'
'; $mes->addWarning(EPL_ADLAN_9) ->addDebug($result); } else { $text .= EPL_ADLAN_7."
"; } } if (is_array($upgrade_add_prefs)) { $plugin->manage_prefs('add', $upgrade_add_prefs); $text .= EPL_ADLAN_8.'
'; } if (is_array($upgrade_remove_prefs)) { $plugin->manage_prefs('remove', $upgrade_remove_prefs); } if (is_array($upgrade_add_array_pref)) { foreach($upgrade_add_array_pref as $key => $val) { $plugin->manage_plugin_prefs('add', $key, $eplug_folder, $val); } } if (is_array($upgrade_remove_array_pref)) { foreach($upgrade_remove_array_pref as $key => $val) { $plugin->manage_plugin_prefs('remove', $key, $eplug_folder, $val); } } $plugin->manage_search('upgrade', $eplug_folder); $plugin->manage_notify('upgrade', $eplug_folder); $eplug_addons = $plugin -> getAddons($eplug_folder); $info = $plugin->getinfo($this->id); $name = deftrue($info['plugin_name'],$info['plugin_name']). " v".$eplug_version. "({e_PLUGIN}".$info['plugin_path'].")"; e107::getLog()->add('PLUGMAN_02', $name, E_LOG_INFORMATIVE, ''); $text .= (isset($eplug_upgrade_done)) ? '
'.$eplug_upgrade_done : "
".LAN_UPGRADE_SUCCESSFUL; $sql->update('plugin', "plugin_version ='{$eplug_version}', plugin_addons='{$eplug_addons}' WHERE plugin_id='$this->id' "); $pref['plug_installed'][$plug['plugin_path']] = $eplug_version; // Update the version e107::getConfig('core')->setPref($pref); $plugin->rebuildUrlConfig(); e107::getConfig('core')->save(); } $mes->addSuccess($text); $plugin->save_addon_prefs('update'); } // ----------------------------------------------------------------------------- function pluginRepair() { // global $plug; $plug = e107::getSingleton('e107plugin')->getinfo($this->id); $_path = e_PLUGIN.$plug['plugin_path'].'/'; if(file_exists($_path.'plugin.xml')) { // $text .= $plugin->install_plugin_xml($this->id, 'refresh'); e107::getSingleton('e107plugin')->refresh($plug['plugin_path']); e107::getLog()->add('PLUGMAN_04', $this->id.':'.$plug['plugin_path'], E_LOG_INFORMATIVE, ''); } } // ----------------------------------------------------------------------------- // Check for new plugins, create entry in plugin table ... function pluginCheck($force=false) { global $plugin; if(!PLUGIN_SCAN_INTERVAL) { $plugin->update_plugins_table('update'); return; } if((time() > vartrue($_SESSION['nextPluginFolderScan'],0)) || $force == true) { $plugin->update_plugins_table('update'); } $_SESSION['nextPluginFolderScan'] = time() + PLUGIN_SCAN_INTERVAL; //echo "TIME = ".$_SESSION['nextPluginFolderScan']; } // ---------------------------------------------------------- // render plugin information ... // ----------------------------------------------------------------------------- function pluginUpload() { global $plugin; $frm = e107::getForm(); //TODO 'install' checkbox in plugin upload form. (as it is for theme upload) if(!is_writable(e_PLUGIN)) { $text = EPL_ADLAN_44; } else { // Get largest allowable file upload require_once(e_HANDLER.'upload_handler.php'); $max_file_size = get_user_max_upload(); $text = "
".EPL_ADLAN_37."
"; $text .= $frm->admin_button('upload', EPL_ADLAN_38, 'submit', EPL_ADLAN_38); $text .= "
\n"; } e107::getRender()->tablerender(ADLAN_98.SEP.EPL_ADLAN_38, $text); } // ----------------------------------------------------------------------------- function pluginRenderList() // Uninstall and Install sorting should be fixed once and for all now ! { global $plugin; $frm = e107::getForm(); $mes = e107::getMessage(); if($this->action == "" || $this->action == "installed") { $installed = $plugin->getall(1); $mp = $this->getMarketplace(); $versions = $mp->getVersionList(); // print_a($versions); $caption = EPL_ADLAN_22; $pluginRenderPlugin = $this->pluginRenderPlugin($installed, $versions); $button_mode = "uninstall-selected"; $button_caption = EPL_ADLAN_85; $button_action = "delete"; } if($this->action == "avail") { $uninstalled = $plugin->getall(0); $caption = EPL_ADLAN_23; $pluginRenderPlugin = $this->pluginRenderPlugin($uninstalled); $button_mode = "install-selected"; $button_caption = EPL_ADLAN_84; $button_action = "update"; } $text = "
".vartrue($caption)." ".$frm->colGroup($this->fields,$this->fieldpref). $frm->thead($this->fields,$this->fieldpref)." "; if(vartrue($pluginRenderPlugin)) { $text .= $pluginRenderPlugin; } else { $text .= ""; } $text .= "
"; $text .= str_replace("[x]", "".EPL_ADLAN_100."", EPL_ADLAN_101); $text .= "
"; if($this->action == "avail") { $text .= "
".$frm->admin_button($button_mode, $button_caption, $button_action)."
"; } $text .= "
"; e107::getRender()->tablerender(ADLAN_98.SEP.$caption, $mes->render(). $text); } // ----------------------------------------------------------------------------- function pluginRenderPlugin($pluginList, $versions = array()) { global $plugin; if (empty($pluginList)) return ''; $tp = e107::getParser(); $frm = e107::getForm(); $pgf = new pluginmanager_form; $text = ""; foreach($pluginList as $plug) { e107::loadLanFiles($plug['plugin_path'],'admin'); if($this->action == "avail") { e107::lan($plug['plugin_path'],'global', true); // Load language files. } $_path = e_PLUGIN.$plug['plugin_path'].'/'; $plug_vars = false; $plugin_config_icon = ""; if($plugin->parse_plugin($plug['plugin_path'])) { $plug_vars = $plugin->plug_vars; } if(varset($plug['plugin_category']) == "menu") // Hide "Menu Only" plugins. { continue; } if($plug_vars) { $icon_src = (isset($plug_vars['plugin_php']) ? e_PLUGIN : $_path).$plug_vars['administration']['icon']; $plugin_icon = $plug_vars['administration']['icon'] ? $icon_src : $tp->toGlyph('e-cat_plugins-32'); $conf_file = "#"; $conf_title = ""; if ($plug_vars['administration']['configFile'] && $plug['plugin_installflag'] == true) { $conf_file = e_PLUGIN.$plug['plugin_path'].'/'.$plug_vars['administration']['configFile']; $conf_title = LAN_CONFIGURE.' '.$tp->toHTML($plug_vars['@attributes']['name'], "", "defs,emotes_off, no_make_clickable"); // $plugin_icon = "".$plugin_icon.""; $plugin_config_icon = "".ADMIN_CONFIGURE_ICON.""; } $plugEmail = varset($plug_vars['author']['@attributes']['email'],''); $plugAuthor = varset($plug_vars['author']['@attributes']['name'],''); $plugURL = varset($plug_vars['author']['@attributes']['url'],''); $plugDate = varset($plug_vars['@attributes']['date'],''); $compatibility = varset($plug_vars['@attributes']['compatibility'],''); $description = varset($plug_vars['description']['@attributes']['lang']) ? $tp->toHTML($plug_vars['description']['@attributes']['lang'], false, "defs,emotes_off, no_make_clickable") : $tp->toHTML($plug_vars['description']['@value'], false, "emotes_off, no_make_clickable") ; $plugReadme = ""; if(varset($plug['plugin_installflag'])) { $plugName = "".$tp->toHTML($plug['plugin_name'], false, "defs,emotes_off, no_make_clickable").""; } else { $plugName = $tp->toHTML($plug['plugin_name'], false, "defs,emotes_off, no_make_clickable"); } if(varset($plug_vars['readme'])) // 0.7 plugin.php { $plugReadme = $plug_vars['readme']; } if(varset($plug_vars['readMe'])) // 0.8 plugin.xml { $plugReadme = $plug_vars['readMe']; } if(!file_exists($plugin_icon)) { $plugin_icon = 'e-cat_plugins-32'; // e_IMAGE."admin_images/cat_plugins_32.png"; } $data = array( 'plugin_id' => $plug['plugin_id'], 'plugin_icon' => $plugin_icon, 'plugin_name' => $plugName, 'plugin_folder' => $plug['plugin_path'], 'plugin_date' => $plugDate, 'plugin_category' => vartrue($plug['plugin_category']), 'plugin_author' => vartrue($plugAuthor), // vartrue($plugEmail) ? "".$plugAuthor."" : vartrue($plugAuthor), 'plugin_version' => $plug['plugin_version'], 'plugin_description' => $description, 'plugin_compatible' => $this->compatibilityLabel($plug_vars['@attributes']['compatibility']), 'plugin_website' => vartrue($plug['authorUrl']), // 'plugin_url' => vartrue($plugURL), // ; // ? "".ADMIN_URL_ICON."" : "", 'plugin_notes' => '' ); $pgf->plug_vars = $plug_vars; $pgf->plug = $plug; $text .= $pgf->renderTableRow($this->fields, $this->fieldpref, $data, 'plugin_id'); } } return $text; } // ----------------------------------------------------------------------------- function pluginConfirmUninstall() { global $plugin; $frm = e107::getForm(); $tp = e107::getParser(); $mes = e107::getMessage(); $plug = $plugin->getinfo($this->id); if ($plug['plugin_installflag'] == true ) { if($plugin->parse_plugin($plug['plugin_path'])) { $plug_vars = $plugin->plug_vars; } else { return FALSE; } } else { return FALSE; } $userclasses = ''; $eufields = ''; if (isset($plug_vars['userClasses'])) { if (isset($plug_vars['userclass']['@attributes'])) { $plug_vars['userclass'][0]['@attributes'] = $plug_vars['userclass']['@attributes']; unset($plug_vars['userclass']['@attributes']); } $spacer = ''; foreach ($plug_vars['userClasses']['class'] as $uc) { $userclasses .= $spacer.$uc['@attributes']['name'].' - '.$uc['@attributes']['description']; $spacer = '
'; } } if (isset($plug_vars['extendedFields'])) { if (isset($plug_vars['extendedFields']['@attributes'])) { $plug_vars['extendedField'][0]['@attributes'] = $plug_vars['extendedField']['@attributes']; unset($plug_vars['extendedField']['@attributes']); } $spacer = ''; foreach ($plug_vars['extendedFields']['field'] as $eu) { $eufields .= $spacer.'plugin_'.$plug_vars['folder'].'_'.$eu['@attributes']['name']; $spacer = '
'; } } if(is_writable(e_PLUGIN.$plug['plugin_path'])) { $del_text = $frm->select('delete_files','yesno',0); } else { $del_text = " ".EPL_ADLAN_53." "; } $text = "
".EPL_ADLAN_54." ".$tp->toHtml($plug_vars['@attributes']['name'], "", "defs,emotes_off, no_make_clickable")." "; $opts = array(); $opts['delete_tables'] = array( 'label' => EPL_ADLAN_57, 'helpText' => EPL_ADLAN_58, 'itemList' => array(1=>LAN_YES,0=>LAN_NO), 'itemDefault' => 1 ); if ($userclasses) { $opts['delete_userclasses'] = array( 'label' => EPL_ADLAN_78, 'preview' => $userclasses, 'helpText' => EPL_ADLAN_79, 'itemList' => array(1=>LAN_YES,0=>LAN_NO), 'itemDefault' => 1 ); } if ($eufields) { $opts['delete_xfields'] = array( 'label' => EPL_ADLAN_80, 'preview' => $eufields, 'helpText' => EPL_ADLAN_79, 'itemList' => array(1=>LAN_YES,0=>LAN_NO), 'itemDefault' => 0 ); } $med = e107::getMedia(); $icons = $med->listIcons(e_PLUGIN.$plug['plugin_path']); $iconText = ''; if(count($icons)>0) { foreach($icons as $key=>$val) { $iconText .= ""; } $iconText = '
'.$iconText.'
'; $opts['delete_ipool'] = array( 'label' => EPL_ADLAN_231, 'preview' => $iconText, 'helpText' => EPL_ADLAN_79, 'itemList' => array(1=>LAN_YES,0=>LAN_NO), 'itemDefault' => 1 ); } if(is_readable(e_PLUGIN.$plug['plugin_path']."/".$plug['plugin_path']."_setup.php")) { include_once(e_PLUGIN.$plug['plugin_path']."/".$plug['plugin_path']."_setup.php"); $mes->add("Loading ".e_PLUGIN.$plug['plugin_path']."/".$plug['plugin_path']."_setup.php", E_MESSAGE_DEBUG); $class_name = $plug['plugin_path']."_setup"; if(class_exists($class_name)) { $obj = new $class_name; if(method_exists($obj,'uninstall_options')) { $arr = call_user_func(array($obj,'uninstall_options'), $this); foreach($arr as $key=>$val) { $newkey = $plug['plugin_path']."_".$key; $opts[$newkey] = $val; } } } } foreach($opts as $key=>$val) { $text .= "\n\n\n\n"; } $text .="
".EPL_ADLAN_55." ".LAN_YES."
".$tp->toHTML($val['label'],FALSE,'TITLE'); $text .= varset($val['preview']) ? "
".$val['preview']."
" : ""; $text .= "
".$frm->select($key,$val['itemList'],$val['itemDefault']); $text .= varset($val['helpText']) ? "
".$val['helpText']."
" : ""; $text .= "
".EPL_ADLAN_59." {$del_text}
".EPL_ADLAN_60."
"; $text .= $frm->admin_button('uninstall_confirm',EPL_ADLAN_3,'submit'); $text .= $frm->admin_button('uninstall_cancel',EPL_ADLAN_62,'cancel'); // $frm->admin_button($name, $value, $action = 'submit', $label = '', $options = array()); $text .= "
"; // e107::getRender()->tablerender(EPL_ADLAN_63.SEP.$tp->toHtml($plug_vars['@attributes']['name'], "", "defs,emotes_off, no_make_clickable"),$mes->render(). $text); } function show_message($message, $type = E_MESSAGE_INFO, $session = false) { // ##### Display comfort --------- $mes = e107::getMessage(); $mes->add($message, $type, $session); } function pluginMenuOptions() { // $e107 = &e107::getInstance(); $var['installed']['text'] = EPL_ADLAN_22; $var['installed']['link'] = e_SELF; $var['avail']['text'] = EPL_ADLAN_23; $var['avail']['link'] = e_SELF."?avail"; $var['online']['text'] = EPL_ADLAN_220; $var['online']['link'] = e_SELF."?mode=online"; if(E107_DEBUG_LEVEL > 0) { $var['upload']['text'] = EPL_ADLAN_38; $var['upload']['link'] = e_SELF."?mode=upload"; } $var['create']['text'] = EPL_ADLAN_114; $var['create']['link'] = e_SELF."?mode=create"; $keys = array_keys($var); $action = (in_array($this->action,$keys)) ? $this->action : "installed"; if($this->action == 'lans') { $action = 'create'; } $icon = e107::getParser()->toIcon('e-plugmanager-24'); $caption = $icon."".ADLAN_98.""; e107::getNav()->admin($caption, $action, $var); } } // end of Class. */ /* function plugin_adminmenu() { global $pman; $pman -> pluginMenuOptions(); }*/ class pluginLanguage { private $scriptFiles = array(); private $lanFiles = array(); private $lanDefs = array(); private $scriptDefs = array(); private $lanDefsData = array(); private $scriptDefsData = array(); private $unused = array(); private $unsure = array(); private $excludeLans = array('CORE_LC', 'CORE_LC2', 'e_LAN', 'e_LANGUAGE', 'e_LANGUAGEDIR', 'LAN', 'LANGUAGE'); private $useSimilar = false; function __construct() { if(!empty($_GET['newplugin']) && $_GET['step']==2) { $plugin = e107::getParser()->filter($_GET['newplugin'],'file'); $this->step2($plugin); return false; } // return $this->step1(); } function step2($path) { $this->plugin = $path; $fl = e107::getFile(); $files = $fl->get_files(e_PLUGIN.$path.'/languages',null,null,3); $files2 = $fl->get_files(e_PLUGIN.$path,'\.php|\.sc|\.bb|\.xml','languages',3); $this->scanLanFile(e_LANGUAGEDIR."English/English.php"); $this->scanLanFile(e_LANGUAGEDIR."English/admin/lan_admin.php"); foreach($files as $v) { if(strpos($v['path'],'English')!==false OR strpos($v['fname'],'English')!==false) { $path = $v['path'].$v['fname']; $this->lanFiles[] = $path; $this->scanLanFile($path); } } foreach($files2 as $v) { $path = $v['path'].$v['fname']; $this->scriptFiles[] = $path; $this->scanScriptFile($path); } $this->renderResults(); return true; } function findSimilar($data) { $sim = array(); foreach($this->lanDefsData as $k=>$v) { if(empty($v['value'])) { continue; } if($this->useSimilar == true) { similar_text($v['value'], $data['value'], $percentSimilar); } else { $percentSimilar = 0; } if((($v['value'] == $data['value'] || $percentSimilar > 89) && $data['file'] != $v['file'])) { if(strpos($v['lan'],'LAN')===false) // Defined constants that don't contain 'LAN'. { $v['status'] = 2; } else { $v['status'] = (in_array($v['lan'],$this->used)) ? 1 : 0; } $sim[] = $v; } } return $sim; } function renderSimilar($data,$mode='') { $sim = $this->findSimilar($data); if(empty($sim) || ($mode == 'script' && count($sim) < 2)) { return; // ADMIN_TRUE_ICON; } $text = " "; foreach($sim as $k=>$val) { $text .= ""; } $text .= "
".$this->shortPath($val['file'])." ".$val['lan']."
".$val['value']."
".$this->renderStatus($val['status'])."
"; return $text; } function renderFilesList($list) { $l= array(); foreach($list as $v) { $l[] = $this->shortPath($v,'script'); } if(!empty($l)) { return implode("
",$l); } } function renderStatus($val,$mode='lan') { $diz = array( 'lan' => array(0 => 'Unused by '.$this->plugin, 1=>'Used by '.$this->plugin, 2=>'Unsure'), 'script' => array(0=> 'Missing from Language Files', 1=>'Found in Language Files', 3=>"Generic") ); if($val ==1) { return "".$diz[$mode][$val].""; } if($val == 2) { return "".$diz[$mode][$val].""; } return "".$diz[$mode][$val].""; } function shortPath($path,$mode='lan') { if($path == e_LANGUAGEDIR.'English/English.php') { return "Core Frontend Language File"; } if($path == e_LANGUAGEDIR.'English/admin/lan_admin.php') { return "Core Admin-area Language File"; } if($mode == 'script') { return str_replace(e_PLUGIN.$this->plugin.'/','',$path); } else { $text = str_replace(e_PLUGIN.$this->plugin.'/languages/','',$path); if(strpos($path,'_front.php')===false && strpos($path,'_admin.php')===false && strpos($path,'_global.php')===false && strpos($path,'_menu.php')===false && strpos($path,'_notify.php')===false && strpos($path,'_search.php')===false) { return "".$text.""; } return $text; } } function renderTable($array,$mode) { if(empty($array)) { return "
No Matches
"; } $text2 = ''; if($mode == 'unsure') { $text2 .= "
LAN items in this list have been named incorrectly. They should include 'LAN' in their name. eg. LAN_".strtoupper($this->plugin)."_001
"; } $text2 .= " "; foreach($array as $k=>$v) { $text2 .= ""; } $text2 .= "
LAN File Value Duplicate or Similar Value
".$v." ".$this->shortPath($this->lanDefsData[$k]['file'])." ".$this->lanDefsData[$k]['value']." ".$this->renderSimilar($this->lanDefsData[$k])."
"; return $text2; } function renderScriptTable() { // return print_a($this->scriptDefsData,true); $text2 = " "; foreach($this->scriptDefsData as $k=>$v) { $status = in_array($v['lan'],$this->lanDefs) ? 1 : 0; // $lan = $v['lan']; // $v['value'] = $this->lanDefsRaw[$lan]; // $sim = $this->findSimilar($v); $text2 .= ""; } $text2 .= "
id File Detected LAN LAN Value Found on Line Status Duplicates / Possible Substitions
".$k." ".$this->shortPath($v['file'],'script')." ".$v['lan']." ".$this->lanDefsRaw[$v['lan']]." ".$v['line']." ".$this->renderStatus($status,'script')." ".$this->renderSimilar($v,'script')."
"; return $text2; } function renderResults() { $frm = e107::getForm(); $ns = e107::getRender(); $this->unused = array_diff($this->lanDefs,$this->scriptDefs); $this->used = array_intersect($this->lanDefs,$this->scriptDefs); foreach($this->unused as $k=>$v) { if(strpos($v,'LAN')===false) { unset($this->unused[$k]); $this->unsure[$k] = $v; } if(strpos($this->lanDefsData[$k]['file'],$this->plugin) === false || in_array($v,$this->excludeLans)) { unset($this->unused[$k]); unset($this->unsure[$k]); } } // print_a($this->scriptData); $used = $this->renderTable($this->used, 'used'); $unused = $this->renderTable($this->unused,'unused'); $unsure = $this->renderTable($this->unsure,'unsure'); // echo $text2; $tabs = array ( 0 => array('caption'=>EPL_ADLAN_222, 'text'=> $this->renderScriptTable()), 1 => array('caption'=>EPL_ADLAN_223, 'text'=>$used), 2 => array('caption'=>EPL_ADLAN_224, 'text'=>$unused), 3 => array('caption'=>EPL_ADLAN_225, 'text'=>$unsure), ); $ns->tablerender(ADLAN_98.SEP.EPL_ADLAN_114.SEP.EPL_ADLAN_221.SEP.$this->plugin, $frm->tabs($tabs)); } function scanScriptFile($path) { $lines = file($path, FILE_IGNORE_NEW_LINES); foreach($lines as $ln=>$row) { $row = trim($row); if(substr($row,0,2) == '/*') { // $skip =true; ; } if(substr($row,0,2) == '*/') { // $skip =false; // continue; } if(empty($row) || $skip == true || substr($row,0,5) == '' || substr($row,0,2)=='//') { continue; } if(preg_match_all("/([\w_]*LAN[\w_]*)/", $row, $match)) { foreach($match[1] as $lan) { if(!in_array($lan,$this->excludeLans)) { $this->scriptDefs[] = $lan; $this->scriptDefsData[] = array('file'=>$path, 'line'=>$ln, 'lan'=>$lan, 'value'=>$this->lanDefsRaw[$lan]); // $this->scriptData[$path][$ln] = $row; } } } } } function scanLanFile($path) { $data = file_get_contents($path); if(preg_match_all('/(\/\*[\s\S]*?\*\/)/i',$data, $multiComment)) { $data = str_replace($multiComment[1],'',$data); // strip multi-line comments. } $type = basename($path); if(preg_match_all('/^\s*?define\s*?\(\s*?(\'|\")([\w]+)(\'|\")\s*?,\s*?(\'|\")([\s\S]*?)\s*?(\'|\")\s*?\)\s*?;/im',$data,$matches)) { $def = $matches[2]; $values = $matches[5]; foreach($def as $k=>$d) { if($d == 'e_PAGETITLE' || $d == 'PAGE_NAME' || $d =='CORE_LC' && $d =='CORE_LC2') { continue; } $retloc[$type][$d]= $values[$k]; $this->lanDefs[] = $d; $this->lanDefsData[] = array('file'=>$path, 'lan'=>$d, 'value'=>$values[$k]); $this->lanDefsRaw[$d] = $values[$k]; } } //print_a($this->lanDefsData); return; } } /** * 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(); $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).$frm->admin_button('step', 2,'other',LAN_GO)."
".$frm->checkbox('createFiles',1,1,EPL_ADLAN_232).$frm->close()."
".EPL_ADLAN_108."
".$frm->open('checkPluginLangs','get',e_SELF."?mode=lans").$frm->select("newplugin",$lanDir).$frm->admin_button('step', 2,'other',LAN_GO)."
".$frm->close()."
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','', 10,80)."
"; } /** * @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)) { 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 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)) { $result[] = "Skipped (already exists) : ".$addonDest; continue; } if($content = file_get_contents($source)) { $content = str_replace($srch, $this->pluginName, $content); if(!file_exists($destination)) { if(file_put_contents($destination,$content)) { $result[] = LAN_CREATED." : ".$addonDest; } } else { $result[] = "Skipped (already exists) : ".$addonDest; } } else { //$mes->addError("Addon source-file was empty: ".$addon); } } 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." ); array_unshift($list,'_blank', '_blank_setup', '_blank_menu'); $templateFiles = scandir(e_PLUGIN."_blank"); //print_a($list); // $list[] = "_blank"; // $list[] = "_blank_setup"; foreach($list as $v) { if(!in_array($v.".php", $templateFiles)) { 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']), "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']), "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; $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 = ($pattern) ? "&pattern=".$pattern : ""; $sz = ($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(); 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']); foreach($_POST['pluginPrefs'] as $val) { if(vartrue($val['index'])) { $id = $val['index']; $plugPref[$id] = $val['value']; } } // print_a($_POST['pluginPrefs']); if(count($plugPref)) { $xmlPref = "\n"; foreach($plugPref as $k=>$v) { $xmlPref .= " ".$v."\n"; } $xmlPref .= " "; $newArray['PLUGINPREFS'] = $xmlPref; } // print_a($newArray); // print_a($this); $template = <<