1<?php 2/* 3 * e107 website system 4 * 5 * Copyright (C) 2008-2013 e107 Inc (e107.org) 6 * Released under the terms and conditions of the 7 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) 8 * 9 * Plugin administration area 10 * 11 */ 12 13require_once("../class2.php"); 14 15if(!getperms("Z")) 16{ 17 e107::redirect('admin'); 18 exit; 19} 20 21e107::coreLan('plugin', true); 22 23$e_sub_cat = 'plug_manage'; 24 25define('PLUGIN_SHOW_REFRESH', FALSE); 26define('PLUGIN_SCAN_INTERVAL', !empty($_SERVER['E_DEV']) ? 0 : 360); 27define("ADMIN_GITSYNC_ICON", e107::getParser()->toGlyph('fa-refresh', array('size'=>'2x', 'fw'=>1))); 28 29 30global $user_pref; 31/* 32 33if(!deftrue('e_DEBUG_PLUGMANAGER')) 34{ 35 require_once(e_HANDLER.'plugin_class.php'); 36 require_once(e_HANDLER.'file_class.php'); 37 $plugin = new e107plugin; 38 $pman = new pluginManager; 39 40 define("e_PAGETITLE",ADLAN_98." - ".$pman->pagetitle); 41} 42*/ 43 44if(isset($_POST['uninstall_cancel'])) 45{ 46 header("location:".e_SELF); 47 exit; 48} 49 50 51// Experimental rewrite for v2.1.5 ---------------------- 52 53 54 55 56class plugman_adminArea extends e_admin_dispatcher 57{ 58 59 protected $modes = array( 60 61 'installed' => array( 62 'controller' => 'plugin_ui', 63 'path' => null, 64 'ui' => 'plugin_form_ui', 65 'uipath' => null 66 ), 67 'avail' => array( 68 'controller' => 'plugin_ui', 69 'path' => null, 70 'ui' => 'plugin_form_ui', 71 'uipath' => null 72 ), 73 'online' => array( 74 'controller' => 'plugin_online_ui', 75 'path' => null, 76 'ui' => 'plugin_form_online_ui', 77 'uipath' => null 78 ), 79 'create' => array( 80 'controller' => 'plugin_ui', 81 'path' => null, 82 'ui' => 'plugin_form_ui', 83 'uipath' => null 84 ), 85 'lans' => array( 86 'controller' => 'pluginLanguage', 87 'path' => null, 88 'ui' => 'plugin_form_ui', 89 'uipath' => null 90 ), 91 92 ); 93 94 95 protected $adminMenu = array( 96 97 'installed/list' => array('caption'=> EPL_ADLAN_22, 'perm' => 'Z'), 98 'avail/list' => array('caption'=> EPL_ADLAN_23, 'perm' => 'Z'), 99 'online/list' => array('caption'=> EPL_ADLAN_220, 'perm' => 'Z'), 100 'avail/upload' => array('caption'=>EPL_ADLAN_38, 'perm' => '0'), 101 'create/build' => array('caption'=>EPL_ADLAN_114, 'perm' => '0'), 102 103 // 'main/create' => array('caption'=> LAN_CREATE, 'perm' => 'P'), 104 105 // 'main/custom' => array('caption'=> 'Custom Page', 'perm' => 'P') 106 ); 107 108 109 protected $defaultMode = 'installed'; 110 111 112 protected $adminMenuAliases = array( 113 'installed/uninstall' => 'installed/list', 114 'lans/list' => 'create/build' 115 ); 116 117 protected $adminMenuIcon = 'e-plugmanager-24'; 118 119 function init() 120 { 121 122 $mode = $this->getRequest()->getMode(); 123 $action = $this->getRequest()->getAction(); 124 125 if($mode === 'online' && $action === 'download') 126 { 127 define('e_IFRAME', true); 128 } 129 130 if(deftrue('e_DEVELOPER')) 131 { 132 e107::getPlug()->clearCache(); 133 } 134 } 135 136 137 public static function getPluginManagerFields() 138 { 139 140 return array( 141 'checkboxes' => array('title' => '', 'type' => null, 'data' => null, 'width' => '5%', 'thclass' => 'center', 'forced' => '1', 'class' => 'center', 'toggle' => 'e-multiselect',), 142 'plugin_id' => array('title' => LAN_ID, 'data' => 'int', 'width' => '5%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',), 143 'plugin_icon' => array('title' => LAN_ICON, 'type' => 'icon', 'data' => false, "width" => "5%", 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',), 144 'plugin_name' => array('title' => LAN_TITLE, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',), 145 'plugin_version' => array('title' => LAN_VERSION, 'type' => 'text', 'data' => false, 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',), 146 'plugin_date' => array('title' => LAN_RELEASED, 'type' => 'text', 'data' => false, "width" => "8%", 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',), 147 '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',), 148 149 'plugin_author' => array('title' => LAN_AUTHOR, 'type' => 'text', 'data' => false, 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',), 150 "plugin_license" => array("title" => "License", 'nolist'=>false,'data'=>false, "type"=>"text", "width" => "5%", "thclass" => "left"), 151 'plugin_compatible' => array('title' => EPL_ADLAN_13, 'type' => 'method', 'data' => false, 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center',), 152 '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',), 153 154 'plugin_path' => array('title' => LAN_PATH, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',), 155 'plugin_installflag' => array('title' => EPL_ADLAN_22, 'type' => 'boolean', 'data' => 'int', 'width' => 'auto', 'filter' => false, 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'center', 'thclass' => 'center',), 156 'plugin_addons' => array('title' => LAN_ADDONS, 'type' => 'method', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left',), 157 'options' => array('title' => LAN_OPTIONS, 'type' => 'method', 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced' => '1',), 158 ); 159 160 161 } 162 163 164 165 166 protected $menuTitle = ADLAN_98; 167} 168 169 170 171 172 173class plugin_ui extends e_admin_ui 174{ 175 176 protected $pluginTitle = ADLAN_98; 177 protected $pluginName = 'core'; 178 // protected $eventName = 'plugman-plugin'; // remove comment to enable event triggers in admin. 179 protected $table = 'plugin'; 180 protected $pid = 'plugin_id'; 181 protected $perPage = 10; 182 183 protected $batchDelete = false; 184 protected $batchExport = false; 185 protected $batchCopy = false; 186 // protected $sortField = 'somefield_order'; 187 // protected $orderStep = 10; 188 // protected $tabs = array('Tabl 1','Tab 2'); // Use 'tab'=>0 OR 'tab'=>1 in the $fields below to enable. 189 190 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. 191 192 protected $listOrder = 'plugin_path ASC'; 193 194 protected $fields = array(); 195 196 protected $fieldpref = array('plugin_icon', 'plugin_name', 'plugin_version', 'plugin_description', 'plugin_compatible', 'plugin_released','plugin_author', 'plugin_category','plugin_installflag'); 197 198 199 // protected $preftabs = array('General', 'Other' ); 200 protected $prefs = array( 201 ); 202 203 // Ideal way to set field data. 204 205 public function __construct($request, $response, $params = array()) 206 { 207 $this->fields = plugman_adminArea::getPluginManagerFields(); 208 $this->fields['plugin_category']['writeParms']['optArray'] = e107::getPlug()->getCategoryList(); // array('plugin_category_0','plugin_category_1', 'plugin_category_2'); // Example Drop-down array. 209 210 unset($this->fields['plugin_category']['writeParms']['optArray']['menu']); 211 unset($this->fields['plugin_category']['writeParms']['optArray']['about']); 212 213 parent:: __construct($request, $response, $params); 214 215 } 216 217 218 public function init() 219 { 220 221 if(!e_QUERY) 222 { 223 e107::getPlug()->clearCache(); 224 } 225 226 227 if($this->getMode()=== 'avail') 228 { 229 $this->listQry = "SELECT * FROM `#plugin` WHERE plugin_installflag = 0 AND plugin_category != 'menu' "; 230 } 231 232 // Set drop-down values (if any). 233 234 } 235 236 // Modify the list data. 237 public function ListObserver() 238 { 239 parent::ListObserver(); 240 241 $this->setPlugData(); 242 } 243 244 private function setPlugData() 245 { 246 $tree = $this->getTreeModel(); 247 248 $plg = e107::getPlug(); 249 250 /** 251 * @var $id 252 * @var e_model $model 253 */ 254 foreach ($tree->getTree() as $id => $model) 255 { 256 $path = $model->get('plugin_path'); 257 258 $plg->load($path); 259 260 $model->set('plugin_name',$plg->getName()); 261 $model->set('plugin_date',$plg->getDate()); 262 $model->set('plugin_author',$plg->getAuthor()); 263 $model->set('plugin_compatible',$plg->getCompat()); 264 $model->set('plugin_admin_url',$plg->getAdminUrl()); 265 $model->set('plugin_admin_caption', $plg->getAdminCaption()); 266 $model->set('plugin_description',$plg->getDescription()); 267 $model->set('plugin_version_file',$plg->getVersion()); 268 $model->set('plugin_install_required',$plg->getInstallRequired()); 269 $model->set('plugin_icon',$plg->getIcon(32, 'path')); 270 271 } 272 273 } 274 275 276 public function ListAjaxObserver() 277 { 278 279 $this->getTreeModel()->setParam('db_query', $this->_modifyListQry(false, false, 0, false, $this->listQry))->loadBatch(); 280 281 $this->setPlugData(); 282 } 283 284 private function pluginProcessUpload() 285 { 286 if (!$_POST['ac'] == md5(ADMINPWCHANGE)) 287 { 288 exit; 289 } 290 291 $fl = e107::getFile(); 292 $data = $fl->getUploaded(e_TEMP); 293 $mes = e107::getMessage(); 294 295 if(empty($data[0]['error'])) 296 { 297 if($fl->unzipArchive($data[0]['name'],'plugin')) 298 { 299 $mes->addSuccess(EPL_ADLAN_43); 300 } 301 else 302 { 303 $mes->addError(EPL_ADLAN_97); 304 } 305 } 306 307 308 //echo $mes->render(); 309 310 return true; 311 312 } 313 314 315 316 function renderHelp() 317 { 318 $plg = e107::getPlug(); 319 if(!$list = $plg->getUpgradableList()) 320 { 321 return null; 322 } 323 324 325 $text = "<ul class='media-list'>"; 326 foreach($list as $path=>$ver) 327 { 328 $plg->load($path); 329 $url = e_ADMIN."plugin.php?mode=installed&action=upgrade&id=".$path; 330 $text .= "<li class='media'> 331 <div class='media-left'> 332 <a href='".$url."'>".$plg->getIcon(32)."</a> 333 </div><div class='media-body'><a href='".$url."'>".$plg->getName()."</a></div></li>"; 334 335 } 336 $text .= "</ul>"; 337 338 339 340 341 return array('caption'=>EPL_ADLAN_247, 'text'=>$text); 342 343 } 344 345 // Action Pages. 346 347 348 349 350 351 function installPage() 352 { 353 $id = $this->getQuery('path'); 354 355 $text = e107::getPlugin()->install($id); 356 357 // $log = e107::getAdminLog(); 358 359 if ($text === FALSE) 360 { 361 e107::getMessage()->add(EPL_ADLAN_99, E_MESSAGE_ERROR); 362 } 363 else 364 { 365 //$plugin->save_addon_prefs('update'); 366 // $info = $plugin->getinfo($this->id); //FIXME use e107::getPlug(); 367 368 // $name = deftrue($info['plugin_name'],$info['plugin_name']). " v".$info['plugin_version']. "({e_PLUGIN}".$info['plugin_path'].")"; 369 370 // $log->log_event('PLUGMAN_01', $name, E_LOG_INFORMATIVE, ''); 371 372 // make sure ALL plugin/addon pref lists get update and are current 373 e107::getPlug()->clearCache()->buildAddonPrefLists(); 374 375 e107::getMessage()->add($text, E_MESSAGE_SUCCESS); 376 } 377 378 379 $this->redirectAction('list'); 380 } 381 382 383 function buildPage() 384 { 385 $pc = new pluginBuilder; 386 $ret = $pc->run(); 387 388 if(is_array($ret)) 389 { 390 $this->addTitle($ret['caption']); 391 return $ret['text']; 392 } 393 394 return $ret; 395 } 396 397 398 function lanPage() 399 { 400 401 402 403 } 404 405 function uninstallPage() 406 { 407 408 409 $id = $this->getQuery('path'); 410 411 412 if(empty($_POST['uninstall_confirm'])) 413 { 414 415 $plug_vars = e107::getPlug()->load($id)->getMeta(); 416 417 418 419 $name = e107::getPlug()->getName(); 420 $this->addTitle(EPL_ADLAN_63); 421 $this->addTitle($name); 422 423 return $this->pluginConfirmUninstall($plug_vars); 424 } 425 426 $post = e107::getParser()->filter($_POST); 427 428 if(empty($_POST['e-token'])) 429 { 430 return false; 431 } 432 433 // $id = e107::getPlugin 434 435 $text = e107::getPlugin()->uninstall($id, $post); 436 437 438 439 // make sure ALL plugin/addon pref lists get update and are current 440 e107::getPlug()->clearCache()->buildAddonPrefLists(); 441 442 e107::getMessage()->add($text, E_MESSAGE_SUCCESS); 443 $log = e107::getPlugin()->getLog(); 444 e107::getDebug()->log($log); 445 446 $this->redirectAction('list'); 447 } 448 449 450 451 function repairPage() 452 { 453 $id = $this->getQuery('path'); 454 455 if(!is_dir(e_PLUGIN.$id)) 456 { 457 e107::getMessage()->addError("Bad Link"); 458 return false; 459 } 460 461 e107::getSingleton('e107plugin')->refresh($id); 462 e107::getLog()->add('PLUGMAN_04', $id, E_LOG_INFORMATIVE, ''); 463 464 e107::getMessage()->addSuccess("Repair Complete (".$id.")"); // Repair Complete ([x]) 465 466 $this->redirectAction('list'); 467 } 468 469 470 function pullPage() 471 { 472 $id = $this->getQuery('path'); 473 474 if(!e107::isInstalled($id)) 475 { 476 $this->redirectAction('list'); 477 } 478 479 480 $return = e107::getFile()->gitPull($id, 'plugin'); 481 e107::getMessage()->addSuccess($return); 482 e107::getPlugin()->refresh($id); 483 484 $this->redirectAction('list'); 485 } 486 487 488 function upgradePage() 489 { 490 $this->pluginUpgrade(); 491 } 492 493 494 495 function uploadPage() 496 { 497 498 global $plugin; 499 $frm = e107::getForm(); 500 if(!empty($_POST['upload'])) 501 { 502 $this->pluginProcessUpload(); 503 504 $this->redirectAction('list'); 505 } 506 507 508 509 //TODO 'install' checkbox in plugin upload form. (as it is for theme upload) 510 511 /* plugin upload form */ 512 513 if(!is_writable(e_PLUGIN)) 514 { 515 $text = EPL_ADLAN_44; 516 } 517 else 518 { 519 // Get largest allowable file upload 520 require_once(e_HANDLER.'upload_handler.php'); 521 $max_file_size = get_user_max_upload(); 522 523 $text = " 524 <form enctype='multipart/form-data' method='post' action='".e_SELF."?mode=avail&action=upload'> 525 <table class='table adminform'> 526 <colgroup> 527 <col class='col-label' /> 528 <col class='col-control' /> 529 </colgroup> 530 <tr> 531 <td>".EPL_ADLAN_37."</td> 532 <td> 533 <input type='hidden' name='MAX_FILE_SIZE' value='{$max_file_size}' /> 534 <input type='hidden' name='ac' value='".md5(ADMINPWCHANGE)."' /> 535 <input class='tbox' type='file' name='file_userfile[]' size='50' /> 536 </td> 537 </tr> 538 </table> 539 540 <div class='center buttons-bar'>"; 541 $text .= $frm->admin_button('upload', EPL_ADLAN_38, 'submit', EPL_ADLAN_38); 542 543 $text .= " 544 </div> 545 546 </form>\n"; 547 } 548 549 550 return $text; 551 // e107::getRender()->tablerender(ADLAN_98.SEP.EPL_ADLAN_38, $text); 552 553 554 } 555 556 private function pluginUpgrade() 557 { 558 $pref = e107::getPref(); 559 $admin_log = e107::getAdminLog(); 560 $plugin = e107::getPlugin(); 561 562 $sql = e107::getDb(); 563 $mes = e107::getMessage(); 564 565 $id = $this->getQuery('path'); 566 567 $plug = e107::getPlug()->load($id)->getMeta(); 568 569 $text = ''; 570 571 $_path = e_PLUGIN.$id.'/'; 572 if(file_exists($_path.'plugin.xml')) 573 { 574 $plugin->install_plugin_xml($id, 'upgrade'); 575 $text = LAN_UPGRADE_SUCCESSFUL; 576 } 577 else 578 { 579 $eplug_folder = null; 580 $upgrade_alter_tables = null; 581 $upgrade_add_prefs = null; 582 $upgrade_remove_prefs = null; 583 $upgrade_add_array_pref = null; 584 $upgrade_remove_array_pref = null; 585 $eplug_version = null; 586 587 588 589 include(e_PLUGIN.$plug['plugin_path'].'/plugin.php'); 590 591 $text = ''; 592 593 $func = $eplug_folder.'_upgrade'; 594 if (function_exists($func)) 595 { 596 $text .= call_user_func($func); 597 } 598 599 if (is_array($upgrade_alter_tables)) 600 { 601 $result = $plugin->manage_tables('upgrade', $upgrade_alter_tables); 602 if (true !== $result) 603 { 604 //$text .= EPL_ADLAN_9.'<br />'; 605 $mes->addWarning(EPL_ADLAN_9) 606 ->addDebug($result); 607 } 608 else 609 { 610 $text .= EPL_ADLAN_7."<br />"; 611 } 612 } 613 614 if (is_array($upgrade_add_prefs)) 615 { 616 $plugin->manage_prefs('add', $upgrade_add_prefs); 617 $text .= EPL_ADLAN_8.'<br />'; 618 } 619 620 if (is_array($upgrade_remove_prefs)) 621 { 622 $plugin->manage_prefs('remove', $upgrade_remove_prefs); 623 } 624 625 if (is_array($upgrade_add_array_pref)) 626 { 627 foreach($upgrade_add_array_pref as $key => $val) 628 { 629 $plugin->manage_plugin_prefs('add', $key, $eplug_folder, $val); 630 } 631 } 632 633 if (is_array($upgrade_remove_array_pref)) 634 { 635 foreach($upgrade_remove_array_pref as $key => $val) 636 { 637 $plugin->manage_plugin_prefs('remove', $key, $eplug_folder, $val); 638 } 639 } 640 641 $plugin->manage_search('upgrade', $eplug_folder); 642 $plugin->manage_notify('upgrade', $eplug_folder); 643 644 $eplug_addons = $plugin -> getAddons($eplug_folder); 645 646 $info = e107plugin::getPluginRecord($this->id); 647 648 $name = deftrue($info['plugin_name'],$info['plugin_name']). " v".$eplug_version. "({e_PLUGIN}".$info['plugin_path'].")"; 649 650 e107::getLog()->add('PLUGMAN_02', $name, E_LOG_INFORMATIVE, ''); 651 $text .= (isset($eplug_upgrade_done)) ? '<br />'.$eplug_upgrade_done : "<br />".LAN_UPGRADE_SUCCESSFUL; 652 $sql->update('plugin', "plugin_version ='{$eplug_version}', plugin_addons='{$eplug_addons}' WHERE plugin_id='$this->id' "); 653 $pref['plug_installed'][$plug['plugin_path']] = $eplug_version; // Update the version 654 655 e107::getConfig('core')->setPref($pref); 656 $plugin->rebuildUrlConfig(); 657 e107::getConfig('core')->save(); 658 } 659 660 $mes->addSuccess($text); 661 //$plugin->save_addon_prefs('update'); 662 663 // make sure ALL plugin/addon pref lists get update and are current 664 e107::getPlug()->clearCache()->buildAddonPrefLists(); 665 666 // clear infopanel in admin dashboard. 667 e107::getCache()->clear('Infopanel_plugin', true); 668 e107::getSession()->clear('addons-update-status'); 669 e107::getSession()->set('addons-update-checked',false); // set to recheck it. 670 671 $this->redirectAction('list'); 672 } 673 674 675 676 677 private function pluginConfirmUninstall($plug_vars) 678 { 679 global $plugin; 680 681 $frm = e107::getForm(); 682 $tp = e107::getParser(); 683 $mes = e107::getMessage(); 684 685 686 $path = $plug_vars['folder']; 687 // $plug = $plugin->getinfo($this->id); 688 689 if(!e107::isInstalled($path)) 690 { 691 return false; 692 } 693 694 $userclasses = ''; 695 $eufields = ''; 696 if (isset($plug_vars['userClasses'])) 697 { 698 if (isset($plug_vars['userclass']['@attributes'])) 699 { 700 $plug_vars['userclass'][0]['@attributes'] = $plug_vars['userclass']['@attributes']; 701 unset($plug_vars['userclass']['@attributes']); 702 } 703 $spacer = ''; 704 foreach ($plug_vars['userClasses']['class'] as $uc) 705 { 706 $userclasses .= $spacer.$uc['@attributes']['name'].' - '.$uc['@attributes']['description']; 707 $spacer = '<br />'; 708 } 709 } 710 if (isset($plug_vars['extendedFields'])) 711 { 712 if (isset($plug_vars['extendedFields']['@attributes'])) 713 { 714 $plug_vars['extendedField'][0]['@attributes'] = $plug_vars['extendedField']['@attributes']; 715 unset($plug_vars['extendedField']['@attributes']); 716 } 717 $spacer = ''; 718 foreach ($plug_vars['extendedFields']['field'] as $eu) 719 { 720 $eufields .= $spacer.'plugin_'.$plug_vars['folder'].'_'.$eu['@attributes']['name']; 721 $spacer = '<br />'; 722 } 723 } 724 725 if(is_writable(e_PLUGIN.$path)) 726 { 727 $del_text = $frm->select('delete_files','yesno',0); 728 } 729 else 730 { 731 $del_text = " 732 ".EPL_ADLAN_53." 733 <input type='hidden' name='delete_files' value='0' /> 734 "; 735 } 736 737 $text = " 738 <form action='".e_SELF."?".e_QUERY."' method='post'> 739 <fieldset id='core-plugin-confirmUninstall'> 740 <legend>".EPL_ADLAN_54." ".$tp->toHTML($plug_vars['@attributes']['name'], "", "defs,emotes_off, no_make_clickable")."</legend> 741 <table class='table adminform'> 742 <colgroup> 743 <col class='col-label' /> 744 <col class='col-control' /> 745 </colgroup> 746 <tr> 747 <td>".EPL_ADLAN_55."</td> 748 <td>".LAN_YES."</td> 749 </tr>"; 750 751 $opts = array(); 752 753 $opts['delete_tables'] = array( 754 'label' => EPL_ADLAN_57, 755 'helpText' => EPL_ADLAN_58, 756 'itemList' => array(1=>LAN_YES,0=>LAN_NO), 757 'itemDefault' => 1 758 ); 759 760 if ($userclasses) 761 { 762 $opts['delete_userclasses'] = array( 763 'label' => EPL_ADLAN_78, 764 'preview' => $userclasses, 765 'helpText' => EPL_ADLAN_79, 766 'itemList' => array(1=>LAN_YES,0=>LAN_NO), 767 'itemDefault' => 1 768 ); 769 } 770 771 if ($eufields) 772 { 773 $opts['delete_xfields'] = array( 774 'label' => EPL_ADLAN_80, 775 'preview' => $eufields, 776 'helpText' => EPL_ADLAN_79, 777 'itemList' => array(1=>LAN_YES,0=>LAN_NO), 778 'itemDefault' => 0 779 ); 780 } 781 782 $med = e107::getMedia(); 783 $icons = $med->listIcons(e_PLUGIN.$path); 784 785 $iconText = ''; 786 787 if(count($icons)>0) 788 { 789 foreach($icons as $key=>$val) 790 { 791 $iconText .= "<img src='".$tp->replaceConstants($val)."' alt='' />"; 792 } 793 794 $iconText = '<div class="icon-pool-preview">'.$iconText.'</div>'; 795 796 $opts['delete_ipool'] = array( 797 'label' => EPL_ADLAN_231, 798 'preview' => $iconText, 799 'helpText' => EPL_ADLAN_79, 800 'itemList' => array(1=>LAN_YES,0=>LAN_NO), 801 'itemDefault' => 1 802 ); 803 804 805 } 806 807 808 809 if(is_readable(e_PLUGIN.$path."/".$path."_setup.php")) 810 { 811 include_once(e_PLUGIN.$path."/".$path."_setup.php"); 812 813 814 $mes->add("Loading ".e_PLUGIN.$path."/".$path."_setup.php", E_MESSAGE_DEBUG); 815 816 $class_name = $path."_setup"; 817 818 if(class_exists($class_name)) 819 { 820 $obj = new $class_name; 821 if(method_exists($obj,'uninstall_options')) 822 { 823 $arr = call_user_func(array($obj,'uninstall_options'), $this); 824 foreach($arr as $key=>$val) 825 { 826 $newkey = $path."_".$key; 827 $opts[$newkey] = $val; 828 } 829 } 830 } 831 } 832 833 foreach($opts as $key=>$val) 834 { 835 $text .= "<tr>\n<td class='top'>".$tp->toHTML($val['label'],FALSE,'TITLE'); 836 $text .= varset($val['preview']) ? "<div class='indent'>".$val['preview']."</div>" : ""; 837 $text .= "</td>\n<td>".$frm->select($key,$val['itemList'],$val['itemDefault']); 838 $text .= varset($val['helpText']) ? "<div class='field-help'>".$val['helpText']."</div>" : ""; 839 $text .= "</td>\n</tr>\n"; 840 } 841 842 843 $text .="<tr> 844 <td>".EPL_ADLAN_59."</td> 845 <td>{$del_text} 846 <div class='field-help'>".EPL_ADLAN_60."</div> 847 </td> 848 </tr> 849 </table> 850 <div class='buttons-bar center'>"; 851 852 $text .= $frm->admin_button('uninstall_confirm',EPL_ADLAN_3,'submit'); 853 $text .= $frm->admin_button('uninstall_cancel',EPL_ADLAN_62,'cancel'); 854 855 /* 856 $text .= "<input class='btn' type='submit' name='uninstall_confirm' value=\"".EPL_ADLAN_3."\" /> 857 <input class='btn' type='submit' name='uninstall_cancel' value='".EPL_ADLAN_62."' onclick=\"location.href='".e_SELF."'; return false;\"/>"; 858 */ 859 // $frm->admin_button($name, $value, $action = 'submit', $label = '', $options = array()); 860 861 862 863 $text .= "<input type='hidden' name='e-token' value='".e_TOKEN."' /></div> 864 </fieldset> 865 </form> 866 "; 867 868 return $text; 869 // e107::getRender()->tablerender(EPL_ADLAN_63.SEP.$tp->toHTML($plug_vars['@attributes']['name'], "", "defs,emotes_off, no_make_clickable"),$mes->render(). $text); 870 871 } 872 /* 873 // optional - a custom page. 874 public function customPage() 875 { 876 $text = 'Hello World!'; 877 $otherField = $this->getController()->getFieldVar('other_field_name'); 878 return $text; 879 880 } 881 */ 882 883} 884 885 886 887class plugin_form_ui extends e_admin_form_ui 888{ 889 890 891 // Custom Method/Function 892 function plugin_compatible($curVal,$mode) 893 { 894 $frm = e107::getForm(); 895 896 switch($mode) 897 { 898 case 'read': // List Page 899 900 if(intval($curVal) > 1) 901 { 902 return "<span class='label label-warning'>".$curVal."</span>"; 903 } 904 905 return $curVal; 906 break; 907 908 case 'write': // Edit Page 909 return $frm->text('plugin_name',$curVal, 255, 'size=large'); 910 break; 911 912 case 'filter': 913 case 'batch': 914 return array(); 915 break; 916 } 917 } 918 919 920 // Custom Method/Function 921 function plugin_addons($curVal,$mode) 922 { 923 $frm = e107::getForm(); 924 925 switch($mode) 926 { 927 case 'read': // List Page 928 return $curVal; 929 break; 930 931 case 'write': // Edit Page 932 return $frm->text('plugin_addons',$curVal, 255, 'size=large'); 933 break; 934 935 case 'filter': 936 case 'batch': 937 return array(); 938 break; 939 } 940 } 941 942 943 function options($val, $curVal) 944 { 945 946 $tp = e107::getParser(); 947 948 $var = $this->getController()->getListModel()->getData(); 949 950 $mode = $this->getController()->getMode(); 951 952 // e107::getDebug()->log($var); 953 954 $_path = e_PLUGIN . $var['plugin_path'] . '/'; 955 956 if($var['plugin_admin_url'] && $var['plugin_installflag'] == true) 957 { 958 959 $conf_title = !empty($var['plugin_admin_caption']) ? $var['plugin_admin_caption'] : LAN_CONFIGURE . ' ' . $tp->toHTML($var['plugin_name'], "", "defs,emotes_off, no_make_clickable"); 960 $plugin_config_icon = "<a class='btn btn-default' title='{$conf_title}' href='" . $var['plugin_admin_url'] . "' >" . ADMIN_CONFIGURE_ICON . "</a>"; 961 } 962 963 $text = "<div class='btn-group'>"; 964 $text .= vartrue($plugin_config_icon); 965 966 if($var['plugin_install_required'] == true) 967 { 968 969 if($var['plugin_installflag']) 970 { 971 $text .= ($var['plugin_installflag'] ? "<a class='btn btn-default' href=\"" . e_SELF . "?mode=".$mode."&action=uninstall&path={$var['plugin_path']}\" title='" . EPL_ADLAN_1 . "' >" . ADMIN_UNINSTALLPLUGIN_ICON . "</a>" : "<a class='btn' href=\"" . e_SELF . "?install.{$var['plugin_id']}\" title='" . EPL_ADLAN_0 . "' >" . ADMIN_INSTALLPLUGIN_ICON . "</a>"); 972 } 973 else 974 { 975 $text .= "<a class='btn btn-default' href=\"" . e_SELF . "?mode=installed&action=install&path={$var['plugin_path']}\" title='" . EPL_ADLAN_0 . "' >" . ADMIN_INSTALLPLUGIN_ICON . "</a>"; 976 } 977 978 } 979 else 980 { 981 if($var['menuName']) 982 { 983 // $text .= EPL_NOINSTALL . str_replace("..", "", e_PLUGIN . $var['plugin_path']) . "/ " . EPL_DIRECTORY; 984 } 985 else 986 { 987 // $text .= EPL_NOINSTALL_1 . str_replace("..", "", e_PLUGIN . $var['plugin_path']) . "/ " . EPL_DIRECTORY; 988 if($var['plugin_installflag'] == false) 989 { 990 // e107::getDb()->delete('plugin', "plugin_installflag=0 AND (plugin_path='{$var['plugin_path']}' OR plugin_path='{$var['plugin_path']}/' ) "); 991 } 992 } 993 } 994 995 if($var['plugin_version'] != $var['plugin_version_file'] && $var['plugin_installflag']) 996 { 997 $text .= "<a class='btn btn-default' href='" . e_SELF . "?mode=".$mode."&action=upgrade&path={$var['plugin_path']}' title=\"" . EPL_UPGRADE . " v" . $var['plugin_version_file'] . "\" >" . ADMIN_UPGRADEPLUGIN_ICON . "</a>"; 998 } 999 1000 if($var['plugin_installflag'] && e_DEBUG == true) 1001 { 1002 $text .= "<a class='btn btn-default' href='" . e_SELF . "?mode=".$mode."&action=repair&path={$var['plugin_path']}' title='" . LAN_REPAIR_PLUGIN_SETTINGS . "'> " . ADMIN_REPAIRPLUGIN_ICON . "</a>"; 1003 } 1004 1005 if($var['plugin_installflag'] && is_dir($_path . ".git")) 1006 { 1007 $text .= "<a class='plugin-manager btn btn-default' href='" . e_SELF . "?mode=".$mode."&action=pull&path={$var['plugin_path']}' title='" . LAN_SYNC_WITH_GIT_REPO . "'> " . ADMIN_GITSYNC_ICON . "</a>"; 1008 } 1009 1010 1011 $text .= "</div> "; 1012 1013 return $text; 1014 } 1015 1016} 1017 1018 1019 1020 1021 1022 1023 1024class plugin_online_ui extends e_admin_ui 1025{ 1026 1027 protected $pluginTitle = ADLAN_98; 1028 protected $pluginName = 'core'; 1029 // protected $eventName = 'plugman-plugin'; // remove comment to enable event triggers in admin. 1030 protected $table = false; 1031 protected $pid = ''; 1032 protected $perPage = 10; 1033 protected $batchDelete = true; 1034 protected $batchExport = true; 1035 protected $batchCopy = true; 1036 // protected $sortField = 'somefield_order'; 1037 // protected $orderStep = 10; 1038 // protected $tabs = array('Tabl 1','Tab 2'); // Use 'tab'=>0 OR 'tab'=>1 in the $fields below to enable. 1039 1040 // protected $listQry = "SELECT * FROM `#tableName` WHERE field != '' "; // Example Custom Query. LEFT JOINS allowed. Should be without any Order or Limit. 1041 1042 protected $listOrder = ''; 1043 1044 protected $fields = array (); 1045 1046 protected $fieldpref = array('plugin_icon', 'plugin_name', 'plugin_version', 'plugin_license', 'plugin_description', 'plugin_compatible', 'plugin_date','plugin_author', 'plugin_category','plugin_installflag'); 1047 1048 1049 // protected $preftabs = array('General', 'Other' ); 1050 protected $prefs = array( 1051 ); 1052 1053 protected $mp = null; 1054 1055 1056 public function __construct($request, $response, $params = array()) 1057 { 1058 1059 $this->fields = plugman_adminArea::getPluginManagerFields(); 1060 $this->fields['plugin_category']['writeParms']['optArray'] = e107::getPlug()->getCategoryList(); // array('plugin_category_0','plugin_category_1', 'plugin_category_2'); // Example Drop-down array. 1061 $this->fields["plugin_license"]['nolist'] = false; 1062 $this->fields['plugin_category']['inline'] = false; 1063 parent:: __construct($request, $response, $params); 1064 1065 } 1066 1067 1068 public function init() 1069 { 1070 require_once(e_HANDLER.'e_marketplace.php'); 1071 } 1072 1073 function pluginCheck($force=false) 1074 { 1075 if(!PLUGIN_SCAN_INTERVAL) 1076 { 1077 e107::getPlugin()->update_plugins_table('update'); 1078 return; 1079 } 1080 1081 if((time() > vartrue($_SESSION['nextPluginFolderScan'],0)) || $force == true) 1082 { 1083 e107::getPlugin()->update_plugins_table('update'); 1084 } 1085 1086 $_SESSION['nextPluginFolderScan'] = time() + PLUGIN_SCAN_INTERVAL; 1087 //echo "TIME = ".$_SESSION['nextPluginFolderScan']; 1088 1089 } 1090 1091 // Modal Download. 1092 public function downloadPage() 1093 { 1094 1095 $frm = e107::getForm(); 1096 $mes = e107::getMessage(); 1097 $tp = e107::getParser(); 1098 1099 // print_a($_GET); 1100 1101 $string = base64_decode($_GET['src']); 1102 parse_str($string, $data); 1103 1104 if(deftrue('e_DEBUG_MARKETPLACE')) 1105 { 1106 echo "<b>DEBUG MODE ACTIVE (no downloading)</b><br />"; 1107 echo '$_GET[src]: '; 1108 print_a($_GET); 1109 1110 echo 'base64 decoded and parsed as $data:'; 1111 print_a($data); 1112 return false; 1113 } 1114 1115 $pluginFolder = !empty($data['plugin_folder']) ? $tp->filter($data['plugin_folder']) : ''; 1116 $pluginUrl = !empty($data['plugin_url']) ? $tp->filter($data['plugin_url']) : ''; 1117 $pluginID = !empty($data['plugin_id']) ? $tp->filter($data['plugin_id']) : ''; 1118 $pluginMode = !empty($data['plugin_mode']) ? $tp->filter($data['plugin_mode']) : ''; 1119 1120 if(!empty($data['plugin_price'])) 1121 { 1122 e107::getRedirect()->go($pluginUrl); 1123 return true; 1124 } 1125 1126 $mp = $this->getMarketplace(); 1127 // $mp->generateAuthKey($e107SiteUsername, $e107SiteUserpass); 1128 1129 1130 1131 // Server flush useless. It's ajax ready state 4, we can't flush (sadly) before that (at least not for all browsers) 1132 $mes->addSuccess(EPL_ADLAN_94); 1133 1134 if($mp->download($pluginID, $pluginMode, 'plugin')) 1135 { 1136 $this -> pluginCheck(true); // rescan the plugin directory 1137 $text = e107::getPlugin()->install($pluginFolder); 1138 1139 1140 1141 $mes->addInfo($text); 1142 1143 $upgradable = e107::getPlug()->getUpgradableList(); 1144 if(!empty($upgradable[$pluginFolder])) 1145 { 1146 $mes->addSuccess("<a target='_top' href='".e_ADMIN."plugin.php?mode=installed&action=upgrade&id=".$pluginFolder."' class='btn btn-primary'>".LAN_UPDATE."</a>"); 1147 } 1148 1149 echo $mes->render('default', 'success'); 1150 } 1151 else 1152 { 1153 // Unable to continue 1154 echo $mes->addError(EPL_ADLAN_95)->render('default', 'error'); 1155 } 1156 1157 echo $mes->render('default', 'debug'); 1158 return null; 1159 1160 1161 1162 } 1163 1164 public function ListObserver() 1165 { 1166 // parent::ListObserver(); 1167 1168 $this->setPlugData(); 1169 } 1170 1171 1172 1173 /** 1174 * @return e_marketplace|null 1175 */ 1176 public function getMarketplace() 1177 { 1178 if(null === $this->mp) 1179 { 1180 $this->mp = new e_marketplace(); // autodetect the best method 1181 } 1182 1183 return $this->mp; 1184 } 1185 1186 1187 1188 private function compatibilityLabel($val='') 1189 { 1190 $badge = (vartrue($val) > 1.9) ? "<span class='label label-warning'>".EPL_ADLAN_88."</span>" : '1.x'; 1191 return $badge; 1192 } 1193 1194 1195 1196 function options($data) 1197 { 1198 1199 1200 /* 1201 if(!e107::getFile()->hasAuthKey()) 1202 { 1203 // return "<a href='".e_SELF."' class='btn btn-primary e-modal' >Download and Install</a>"; 1204 1205 } 1206 */ 1207 if($data['plugin_installflag']) 1208 { 1209 return null; 1210 } 1211 1212 1213 1214 //$url = e_SELF."?src=".base64_encode($d); 1215 // $url = e_SELF.'?action=download&src='.base64_encode($d);//$url.'&action=download'; 1216 $id = 'plug_'.$data['plugin_id']; 1217 //<button type='button' data-target='{$id}' data-loading='".e_IMAGE."/generic/loading_32.gif' class='btn btn-primary e-ajax middle' value='Download and Install' data-src='".$url."' ><span>Download and Install</span></button> 1218 $modalCaption = (!empty($data['plugin_price'])) ? EPL_ADLAN_92." ".$data['plugin_name']." ".$data['plugin_version'] : EPL_ADLAN_230." ".$data['plugin_name']." ".$data['plugin_version']; 1219 1220 $srcData = array( 1221 'plugin_id' => $data['plugin_id'], 1222 'plugin_folder' => $data['plugin_folder'], 1223 'plugin_price' => $data['plugin_price'], 1224 'plugin_mode' => $data['plugin_mode'], 1225 'plugin_url' => $data['plugin_url'], 1226 ); 1227 1228 1229 $url = $this->getMarketplace()->getDownloadModal('plugin', $srcData); 1230 1231 1232 // $d = http_build_query($srcData,false,'&'); 1233 // $url = e_SELF.'?mode=download&src='.base64_encode($d); 1234 $dicon = '<a title="'.EPL_ADLAN_237.'" class="e-modal btn btn-default btn-secondary" href="'.$url.'" rel="external" data-loading="'.e_IMAGE.'/generic/loading_32.gif" data-cache="false" data-modal-caption="'.$modalCaption.'" target="_blank" >'.ADMIN_INSTALLPLUGIN_ICON.'</a>'; 1235 1236 /* 1237 1238 // DEBUGGER . 1239 $base64 = base64_encode($d); 1240 $tmp = base64_decode($base64); 1241 parse_str($tmp, $data); 1242 1243 // XXX Suhosin has a 512 char limit for $_GET strings. 1244 e107::getDebug()->log($data['plugin_name'].' : '.strlen($base64)."<br />".print_a($data,true)); //FIXME - enable when needed to debug. 1245 */ 1246 1247 // Temporary Pop-up version. 1248 // $dicon = '<a class="e-modal" href="'.$data['plugin_url'].'" rel="external" data-modal-caption="'.$data['plugin_name']." ".$data['plugin_version'].'" target="_blank" ><img class="top" src="'.e_IMAGE_ABS.'icons/download_32.png" alt="" /></a>'; 1249 1250 // $dicon = "<a data-toggle='modal' data-modal-caption=\"Downloading ".$data['plugin_name']." ".$data['plugin_version']."\" href='{$url}' data-cache='false' data-target='#uiModal' title='".$LAN_DOWNLOAD."' ><img class='top' src='".e_IMAGE_ABS."icons/download_32.png' alt='' /></a> "; 1251 1252 return "<div id='{$id}' class='center' > 1253 {$dicon} 1254 </div>"; 1255 } 1256 1257 private function setPlugData() 1258 { 1259 1260 // $this->setTreeModel(); 1261 1262 /* $tree = $this->getTreeModel(); 1263 1264 $plg = e107::getPlug(); 1265 1266 foreach ($tree->getTree() as $id => $model) 1267 { 1268 $path = $model->get('plugin_path'); 1269 1270 $plg->load($path); 1271 1272 $model->set('plugin_name',$plg->getName()); 1273 $model->set('plugin_date',$plg->getDate()); 1274 $model->set('plugin_author',$plg->getAuthor()); 1275 $model->set('plugin_compatible',$plg->getCompat()); 1276 $model->set('plugin_admin_url',$plg->getAdminUrl()); 1277 $model->set('plugin_description',$plg->getDescription()); 1278 $model->set('plugin_version_file',$plg->getVersion()); 1279 $model->set('plugin_install_required',$plg->getInstallRequired()); 1280 $model->set('plugin_icon',$plg->getIcon(32, 'path')); 1281 1282 }*/ 1283 1284 } 1285 1286 1287 public function listPage() 1288 { 1289 1290 1291 global $plugin, $e107SiteUsername, $e107SiteUserpass; 1292 $tp = e107::getParser(); 1293 $frm = $this->getUI(); 1294 1295 $caption = EPL_ADLAN_89; 1296 1297 $e107 = e107::getInstance(); 1298 $xml = e107::getXml(); 1299 $mes = e107::getMessage(); 1300 1301 // $mes->addWarning("Some older plugins may produce unpredictable results."); 1302 // check for cURL 1303 if(!function_exists('curl_init')) 1304 { 1305 $mes->addWarning(EPL_ADLAN_90); 1306 } 1307 1308 //TODO use admin_ui including filter capabilities by sending search queries back to the xml script. 1309 $from = isset($_GET['frm']) ? intval($_GET['frm']) : 0; 1310 $srch = preg_replace('/[^\w]/','', vartrue($_GET['srch'])); 1311 1312 1313 $mp = $this->getMarketplace(); 1314 1315 // auth 1316 $mp->generateAuthKey($e107SiteUsername, $e107SiteUserpass); 1317 1318 // do the request, retrieve and parse data 1319 $xdata = $mp->call('getList', array( 1320 'type' => 'plugin', 1321 'params' => array('limit' => $this->perPage, 'search' => $srch, 'from' => $from) 1322 )); 1323 $total = $xdata['params']['count']; 1324 1325 // OLD BIT OF CODE -------------------------------> 1326 /* 1327 // $file = SITEURLBASE.e_PLUGIN_ABS."release/release.php"; // temporary testing 1328 $file = "http://e107.org/feed?type=plugin&frm=".$from."&srch=".$srch."&limit=10"; 1329 1330 $xml->setOptArrayTags('plugin'); // make sure 'plugin' tag always returns an array 1331 $xdata = $xml->loadXMLfile($file,'advanced'); 1332 1333 $total = $xdata['@attributes']['total']; 1334 1335 echo 'file='.$file; 1336 // print_a($xdata); 1337 1338 $xdata['data'] = $xdata['plugin']; 1339 */ 1340 // OLD BIT OF CODE END -------------------------------> 1341 1342 1343 // print_a($xdata); 1344 1345 $c = 1; 1346 foreach($xdata['data'] as $row) 1347 { 1348 //$row = $r['@attributes']; 1349 1350 // print_a($row); 1351 1352 $badge = $this->compatibilityLabel($row['compatibility']);; 1353 $featured = ($row['featured']== 1) ? " <span class='label label-info'>".EPL_ADLAN_91."</span>" : ''; 1354 $price = (!empty($row['price'])) ? "<span class='label label-primary'>".$row['price']." ".$row['currency']."</span>" : "<span class='label label-success'>".EPL_ADLAN_93."</span>"; 1355 1356 $data[] = array( 1357 'plugin_id' => $row['params']['id'], 1358 'plugin_mode' => $row['params']['mode'], 1359 'plugin_icon' => vartrue($row['icon'],'e-plugins-32'), 1360 'plugin_name' => stripslashes($row['name']), 1361 'plugin_featured' => $featured, 1362 'plugin_sef' => '', 1363 'plugin_folder' => $row['folder'], 1364 'plugin_path' => $row['folder'], 1365 'plugin_date' => vartrue($row['date']), 1366 'plugin_category' => vartrue($row['category'], 'n/a'), 1367 'plugin_author' => vartrue($row['author']), 1368 'plugin_version' => $row['version'], 1369 'plugin_description' => nl2br(vartrue($row['description'])), 1370 'plugin_compatible' => $badge, 1371 1372 'plugin_website' => vartrue($row['authorUrl']), 1373 'plugin_url' => $row['urlView'], 1374 'plugin_notes' => '', 1375 'plugin_price' => $row['price'], 1376 'plugin_license' => $price, 1377 'plugin_installflag' => e107::isInstalled($row['folder']) 1378 ); 1379 1380 $c++; 1381 } 1382 1383 $fieldList = $this->fields; 1384 unset($fieldList['checkboxes']); 1385 1386 $text = " 1387 <form class='form-search form-inline' action='".e_SELF."?".e_QUERY."' id='core-plugin-list-form' method='get'> 1388 <div id='admin-ui-list-filter' class='e-search '>".$frm->search('srch', $srch, 'go').$frm->hidden('mode','online')." 1389 </div> 1390 </form> 1391 1392 <form action='".e_SELF."?".e_QUERY."' id='core-plugin-list-form' method='post'> 1393 <fieldset class='e-filter' id='core-plugin-list'> 1394 <legend class='e-hideme'>".$caption."</legend> 1395 1396 1397 1398 1399 1400 <table id=core-plugin-list' class='table adminlist table-striped'> 1401 ".$frm->colGroup($fieldList,$this->fieldpref). 1402 $frm->thead($fieldList,$this->fieldpref)." 1403 <tbody> 1404 "; 1405 1406 1407 1408 foreach($data as $key=>$val ) 1409 { 1410 // print_a($val); 1411 $text .= "<tr>"; 1412 1413 foreach($this->fields as $v=>$foo) 1414 { 1415 if(!in_array($v,$this->fieldpref) || $v == 'checkboxes' || $v === 'options') 1416 { 1417 continue; 1418 } 1419 1420 $_value = $val[$v]; 1421 if($v == 'plugin_name') $_value .= $val['plugin_featured']; 1422 // echo '<br />v='.$v; 1423 $text .= "<td style='height: 40px' class='".vartrue($this->fields[$v]['class'],'left')."'>".$frm->renderValue($v, $_value, $this->fields[$v], $key)."</td>\n"; 1424 } 1425 $text .= "<td class='center'>".$this->options($val)."</td>"; 1426 $text .= "</tr>"; 1427 1428 } 1429 1430 1431 $text .= " 1432 </tbody> 1433 </table>"; 1434 $text .= " 1435 </fieldset> 1436 </form> 1437 "; 1438 1439 if($total > $this->perPage) 1440 { 1441 $parms = $total.",".$this->perPage.",".$from.",".e_SELF.'?mode=online&action=list&frm=[FROM]'; 1442 1443 if(!empty($srch)) 1444 { 1445 $parms .= '&srch='.$srch; 1446 } 1447 1448 $text .= "<div class='control-group form-inline input-inline' style='text-align:center;margin-top:10px'>".$tp->parseTemplate("{NEXTPREV=$parms}",TRUE)."</div>"; 1449 } 1450 1451 return $text; 1452 1453 } 1454 1455 1456 1457 1458 // ------- Customize Create -------- 1459 1460 public function beforeCreate($new_data,$old_data) 1461 { 1462 return $new_data; 1463 } 1464 1465 public function afterCreate($new_data, $old_data, $id) 1466 { 1467 // do something 1468 } 1469 1470 public function onCreateError($new_data, $old_data) 1471 { 1472 // do something 1473 } 1474 1475 1476 // ------- Customize Update -------- 1477 1478 public function beforeUpdate($new_data, $old_data, $id) 1479 { 1480 return $new_data; 1481 } 1482 1483 public function afterUpdate($new_data, $old_data, $id) 1484 { 1485 // do something 1486 } 1487 1488 public function onUpdateError($new_data, $old_data, $id) 1489 { 1490 // do something 1491 } 1492 1493 1494 /* 1495 // optional - a custom page. 1496 public function customPage() 1497 { 1498 $text = 'Hello World!'; 1499 $otherField = $this->getController()->getFieldVar('other_field_name'); 1500 return $text; 1501 1502 } 1503 */ 1504 1505} 1506 1507 1508 1509class plugin_form_online_ui extends e_admin_form_ui 1510{ 1511 1512 1513 // Custom Method/Function 1514 function plugin_name($curVal,$mode) 1515 { 1516 $frm = e107::getForm(); 1517 1518 switch($mode) 1519 { 1520 case 'read': // List Page 1521 return $curVal; 1522 break; 1523 1524 case 'write': // Edit Page 1525 return $frm->text('plugin_name',$curVal, 255, 'size=large'); 1526 break; 1527 1528 case 'filter': 1529 case 'batch': 1530 return array(); 1531 break; 1532 } 1533 } 1534 1535 1536 // Custom Method/Function 1537 function plugin_addons($curVal,$mode) 1538 { 1539 $frm = e107::getForm(); 1540 1541 switch($mode) 1542 { 1543 case 'read': // List Page 1544 return $curVal; 1545 break; 1546 1547 case 'write': // Edit Page 1548 return $frm->text('plugin_addons',$curVal, 255, 'size=large'); 1549 break; 1550 1551 case 'filter': 1552 case 'batch': 1553 return array(); 1554 break; 1555 } 1556 } 1557 1558 1559 1560 // Custom Method/Function 1561 function plugin_compatible($curVal,$mode) 1562 { 1563 $frm = e107::getForm(); 1564 1565 switch($mode) 1566 { 1567 case 'read': // List Page 1568 1569 if(intval($curVal) > 1) 1570 { 1571 return "<span class='label label-warning'>".$curVal."</span>"; 1572 } 1573 1574 return $curVal; 1575 break; 1576 1577 case 'write': // Edit Page 1578 return $frm->text('plugin_name',$curVal, 255, 'size=large'); 1579 break; 1580 1581 case 'filter': 1582 case 'batch': 1583 return array(); 1584 break; 1585 } 1586 } 1587 1588 1589 function options($data) 1590 { 1591return null; 1592 } 1593 1594} 1595 1596 1597 1598 1599 1600class pluginLanguage extends e_admin_ui 1601{ 1602 1603 private $scriptFiles = array(); 1604 private $lanFiles = array(); 1605 1606 private $lanDefs = array(); 1607 private $scriptDefs = array(); 1608 1609 private $lanDefsData = array(); 1610 private $scriptDefsData = array(); 1611 1612 private $unused = array(); 1613 private $unsure = array(); 1614 1615 private $excludeLans = array('CORE_LC', 'CORE_LC2', 'e_LAN', 'e_LANGUAGE', 'e_LANGUAGEDIR', 'LAN', 'LANGUAGE'); 1616 1617 private $useSimilar = false; 1618 1619 1620 function listPage() 1621 { 1622 if(!empty($_GET['newplugin']) && $_GET['step']==2) 1623 { 1624 $plugin = e107::getParser()->filter($_GET['newplugin'],'file'); 1625 return $this->step2($plugin); 1626 1627 } 1628 1629 } 1630 1631 1632 1633 1634 1635 function step2($path) 1636 { 1637 $this->plugin = $path; 1638 1639 $fl = e107::getFile(); 1640 1641 $files = $fl->get_files(e_PLUGIN.$path.'/languages',null,null,3); 1642 $files2 = $fl->get_files(e_PLUGIN.$path,'\.php|\.sc|\.bb|\.xml','languages',3); 1643 1644 $this->scanLanFile(e_LANGUAGEDIR."English/English.php"); 1645 $this->scanLanFile(e_LANGUAGEDIR."English/admin/lan_admin.php"); 1646 1647 foreach($files as $v) 1648 { 1649 if(strpos($v['path'],'English')!==false OR strpos($v['fname'],'English')!==false) 1650 { 1651 $path = $v['path'].$v['fname']; 1652 $this->lanFiles[] = $path; 1653 1654 $this->scanLanFile($path); 1655 } 1656 } 1657 1658 foreach($files2 as $v) 1659 { 1660 $path = $v['path'].$v['fname']; 1661 $this->scriptFiles[] = $path; 1662 $this->scanScriptFile($path); 1663 } 1664 1665 1666 return $this->renderResults(); 1667 1668 } 1669 1670 1671 function findSimilar($data) 1672 { 1673 $sim = array(); 1674 1675 foreach($this->lanDefsData as $k=>$v) 1676 { 1677 if(empty($v['value'])) 1678 { 1679 continue; 1680 } 1681 1682 if($this->useSimilar == true) 1683 { 1684 similar_text($v['value'], $data['value'], $percentSimilar); 1685 } 1686 else 1687 { 1688 $percentSimilar = 0; 1689 } 1690 1691 if((($v['value'] == $data['value'] || $percentSimilar > 89) && $data['file'] != $v['file'])) 1692 { 1693 if(strpos($v['lan'],'LAN')===false) // Defined constants that don't contain 'LAN'. 1694 { 1695 $v['status'] = 2; 1696 } 1697 else 1698 { 1699 $v['status'] = (in_array($v['lan'],$this->used)) ? 1 : 0; 1700 } 1701 1702 $sim[] = $v; 1703 1704 } 1705 } 1706 1707 1708 1709 return $sim; 1710 1711 } 1712 1713 1714 function renderSimilar($data,$mode='') 1715 { 1716 1717 $sim = $this->findSimilar($data); 1718 1719 1720 if(empty($sim) || ($mode == 'script' && count($sim) < 2)) 1721 { 1722 return; // ADMIN_TRUE_ICON; 1723 } 1724 1725 $text = "<table class='table table-striped table-bordered'> 1726 "; 1727 1728 foreach($sim as $k=>$val) 1729 { 1730 $text .= "<tr> 1731 <td style='width:30%'>".$this->shortPath($val['file'])."</td> 1732 <td style='width:45%'>".$val['lan']."<br /><small>".$val['value']."</small></td> 1733 <td style='width:25%'>".$this->renderStatus($val['status'])."</td> 1734 </tr>"; 1735 1736 } 1737 1738 $text .= "</table>"; 1739 return $text; 1740 1741 } 1742 1743 function renderFilesList($list) 1744 { 1745 $l= array(); 1746 foreach($list as $v) 1747 { 1748 $l[] = $this->shortPath($v,'script'); 1749 1750 1751 } 1752 1753 if(!empty($l)) 1754 { 1755 return implode("<br />",$l); 1756 } 1757 1758 1759 } 1760 1761 function renderStatus($val,$mode='lan') 1762 { 1763 $diz = array( 1764 'lan' => array(0 => 'Unused by '.$this->plugin, 1=>'Used by '.$this->plugin, 2=>'Unsure'), 1765 'script' => array(0=> 'Missing from Language Files', 1=>'Found in Language Files', 3=>"Generic") 1766 ); 1767 1768 1769 1770 if($val ==1) 1771 { 1772 return "<span class='label label-success'>".$diz[$mode][$val]."</span>"; 1773 } 1774 1775 if($val == 2) 1776 { 1777 return "<span class='label label-warning'>".$diz[$mode][$val]."</span>"; 1778 } 1779 1780 return "<span class='label label-important label-danger'>".$diz[$mode][$val]."</span>"; 1781 } 1782 1783 function shortPath($path,$mode='lan') 1784 { 1785 1786 if($path == e_LANGUAGEDIR.'English/English.php') 1787 { 1788 return "<i>Core Frontend Language File</i>"; 1789 } 1790 1791 if($path == e_LANGUAGEDIR.'English/admin/lan_admin.php') 1792 { 1793 return "<i>Core Admin-area Language File</i>"; 1794 } 1795 1796 if($mode == 'script') 1797 { 1798 return str_replace(e_PLUGIN.$this->plugin.'/','',$path); 1799 } 1800 else 1801 { 1802 1803 $text = str_replace(e_PLUGIN.$this->plugin.'/languages/','',$path); 1804 1805 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) 1806 { 1807 return "<span class='text-error e-tip' title='File name should be either English_front.php, English_admin.php or English_global.php'>".$text."</span>"; 1808 } 1809 1810 return $text; 1811 1812 } 1813 1814 } 1815 1816 1817 function renderTable($array,$mode) 1818 { 1819 if(empty($array)) 1820 { 1821 return "<div class='alert alert-info alert-block'>No Matches</div>"; 1822 } 1823 1824 $text2 = ''; 1825 1826 if($mode == 'unsure') 1827 { 1828 $text2 .= "<div class='alert alert-info alert-block'>LAN items in this list have been named incorrectly. They should include 'LAN' in their name. eg. LAN_".strtoupper($this->plugin)."_001</div>"; 1829 1830 } 1831 1832 $text2 .= "<table class='table table-striped table-bordered'> 1833 <tr> 1834 <th>LAN</th> 1835 <th>File</th> 1836 <th>Value</th> 1837 <th>Duplicate or Similar Value</th> 1838 </tr> 1839 "; 1840 1841 foreach($array as $k=>$v) 1842 { 1843 $text2 .= "<tr> 1844 <td style='width:5%'>".$v."</td> 1845 <td>".$this->shortPath($this->lanDefsData[$k]['file'])."</td> 1846 <td style='width:20%'>".$this->lanDefsData[$k]['value']."</td> 1847 <td>".$this->renderSimilar($this->lanDefsData[$k])."</td> 1848 </tr>"; 1849 1850 } 1851 1852 1853 $text2 .= "</table>"; 1854 1855 return $text2; 1856 } 1857 1858 function renderScriptTable() 1859 { 1860 1861 // return print_a($this->scriptDefsData,true); 1862 1863 $text2 = "<table class='table table-striped table-bordered'> 1864 <tr> 1865 <th>id</th> 1866 <th>File</th> 1867 <th>Detected LAN</th> 1868 <th>LAN Value</th> 1869 <th class='right'>Found on Line</th> 1870 <th style='width:10%'>Status</th> 1871 <th>Duplicates / Possible Substitions</th> 1872 </tr> 1873 "; 1874 1875 foreach($this->scriptDefsData as $k=>$v) 1876 { 1877 $status = in_array($v['lan'],$this->lanDefs) ? 1 : 0; 1878 // $lan = $v['lan']; 1879 // $v['value'] = $this->lanDefsRaw[$lan]; 1880 // $sim = $this->findSimilar($v); 1881 1882 $text2 .= "<tr> 1883 <td style='width:5%'>".$k."</td> 1884 <td>".$this->shortPath($v['file'],'script')."</td> 1885 <td >".$v['lan']."</td> 1886 <td ><small>".$this->lanDefsRaw[$v['lan']]."</small></td> 1887 <td class='right'>".$v['line']."</td> 1888 <td>".$this->renderStatus($status,'script')."</td> 1889 <td>".$this->renderSimilar($v,'script')."</td> 1890 </tr>"; 1891 1892 } 1893 1894 1895 $text2 .= "</table>"; 1896 1897 return $text2; 1898 1899 } 1900 1901 1902 function renderResults() 1903 { 1904 $frm = e107::getForm(); 1905 $ns = e107::getRender(); 1906 1907 $this->unused = array_diff($this->lanDefs,$this->scriptDefs); 1908 1909 $this->used = array_intersect($this->lanDefs,$this->scriptDefs); 1910 1911 foreach($this->unused as $k=>$v) 1912 { 1913 if(strpos($v,'LAN')===false) 1914 { 1915 unset($this->unused[$k]); 1916 $this->unsure[$k] = $v; 1917 } 1918 1919 if(strpos($this->lanDefsData[$k]['file'],$this->plugin) === false || in_array($v,$this->excludeLans)) 1920 { 1921 unset($this->unused[$k]); 1922 unset($this->unsure[$k]); 1923 } 1924 1925 1926 } 1927 1928// print_a($this->scriptData); 1929 1930 $used = $this->renderTable($this->used, 'used'); 1931 $unused = $this->renderTable($this->unused,'unused'); 1932 $unsure = $this->renderTable($this->unsure,'unsure'); 1933 1934 1935 // echo $text2; 1936 $tabs = array ( 1937 0 => array('caption'=>EPL_ADLAN_222, 'text'=> $this->renderScriptTable()), 1938 1 => array('caption'=>EPL_ADLAN_223, 'text'=>$used), 1939 2 => array('caption'=>EPL_ADLAN_224, 'text'=>$unused), 1940 3 => array('caption'=>EPL_ADLAN_225, 'text'=>$unsure), 1941 1942 1943 ); 1944 1945 1946 $this->addTitle(ADLAN_98.SEP.EPL_ADLAN_114.SEP.EPL_ADLAN_221.SEP.$this->plugin); 1947 1948 $text = "<div class='center'><a class='btn btn-default' href='".e_ADMIN_ABS."plugin.php?mode=create&action=build'>".LAN_BACK."</a></div>"; 1949 1950 return $frm->tabs($tabs).$text; 1951 1952 //$ns->tablerender(ADLAN_98.SEP.EPL_ADLAN_114.SEP.EPL_ADLAN_221.SEP.$this->plugin, $frm->tabs($tabs)); 1953 1954 } 1955 1956 1957 1958 1959 1960 1961 function scanScriptFile($path) 1962 { 1963 $lines = file($path, FILE_IGNORE_NEW_LINES); 1964 1965 foreach($lines as $ln=>$row) 1966 { 1967 $row = trim($row); 1968 if(substr($row,0,2) == '/*') 1969 { 1970 // $skip =true; ; 1971 1972 } 1973 if(substr($row,0,2) == '*/') 1974 { 1975 // $skip =false; 1976 // continue; 1977 } 1978 1979 if(empty($row) /*|| $skip == true*/ || substr($row,0,5) == '<?php' || substr($row,0,2) == '?>' || substr($row,0,2)=='//') 1980 { 1981 continue; 1982 } 1983 1984 if(preg_match_all("/([\w_]*LAN[\w_]*)/", $row, $match)) 1985 { 1986 foreach($match[1] as $lan) 1987 { 1988 if(!in_array($lan,$this->excludeLans)) 1989 { 1990 $this->scriptDefs[] = $lan; 1991 $this->scriptDefsData[] = array('file'=>$path, 'line'=>$ln, 'lan'=>$lan, 'value'=>$this->lanDefsRaw[$lan]); 1992 // $this->scriptData[$path][$ln] = $row; 1993 } 1994 } 1995 } 1996 } 1997 1998 1999 } 2000 2001 2002 function scanLanFile($path) 2003 { 2004 2005 2006 $data = file_get_contents($path); 2007 2008 if(preg_match_all('/(\/\*[\s\S]*?\*\/)/i',$data, $multiComment)) 2009 { 2010 $data = str_replace($multiComment[1],'',$data); // strip multi-line comments. 2011 } 2012 2013 2014 $type = basename($path); 2015 2016 if(preg_match_all('/^\s*?define\s*?\(\s*?(\'|\")([\w]+)(\'|\")\s*?,\s*?(\'|\")([\s\S]*?)\s*?(\'|\")\s*?\)\s*?;/im',$data,$matches)) 2017 { 2018 $def = $matches[2]; 2019 $values = $matches[5]; 2020 2021 foreach($def as $k=>$d) 2022 { 2023 if($d == 'e_PAGETITLE' || $d == 'PAGE_NAME' || $d =='CORE_LC' && $d =='CORE_LC2') 2024 { 2025 continue; 2026 } 2027 2028 $retloc[$type][$d]= $values[$k]; 2029 $this->lanDefs[] = $d; 2030 $this->lanDefsData[] = array('file'=>$path, 'lan'=>$d, 'value'=>$values[$k]); 2031 $this->lanDefsRaw[$d] = $values[$k]; 2032 } 2033 } 2034 2035 //print_a($this->lanDefsData); 2036 return; 2037 } 2038 2039 2040 2041 2042 2043 2044} 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059//if(deftrue('e_DEBUG_PLUGMANAGER')) 2060{ 2061 new plugman_adminArea(); 2062 require_once(e_ADMIN."auth.php"); 2063 e107::getAdminUI()->runPage(); 2064 require_once(e_ADMIN."footer.php"); 2065 exit; 2066 2067} 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093// -------------------------------------- 2094 2095/* 2096class pluginmanager_form extends e_form 2097{ 2098 2099 var $plug; 2100 var $plug_vars; 2101 2102 //FIXME _ there's a problem with calling this. 2103 function plugin_website($parms, $value, $id, $attributes) 2104 { 2105 return (varset($plugURL, false)) ? "<a href='{$plugURL}' title='{$plugURL}' >".ADMIN_URL_ICON."</a>" : ""; 2106 2107 } 2108 2109 2110 function options($val, $curVal) 2111 { 2112 2113 $tp = e107::getParser(); 2114 2115 $_path = e_PLUGIN.$this->plug['plugin_path'].'/'; 2116 2117 $icon_src = (isset($this->plug_vars['plugin_php']) ? e_PLUGIN : $_path).$this->plug_vars['administration']['icon']; 2118 $plugin_icon = $this->plug_vars['administration']['icon'] ? "<img src='{$icon_src}' alt='' class='icon S32' />" : $tp->toGlyph('e-cat_plugins-32'); 2119 $conf_file = "#"; 2120 $conf_title = ""; 2121 2122 if ($this->plug_vars['administration']['configFile'] && $this->plug['plugin_installflag'] == true) 2123 { 2124 $conf_file = e_PLUGIN. $this->plug['plugin_path'].'/'.$this->plug_vars['administration']['configFile']; 2125 $conf_title = LAN_CONFIGURE.' '.$tp->toHTML($this->plug_vars['@attributes']['name'], "", "defs,emotes_off, no_make_clickable"); 2126 $plugin_icon = "<a title='{$conf_title}' href='{$conf_file}' >".$plugin_icon."</a>"; 2127 $plugin_config_icon = "<a class='btn btn-default' title='{$conf_title}' href='{$conf_file}' >".ADMIN_CONFIGURE_ICON."</a>"; 2128 } 2129 2130 $text = "<div class='btn-group'>"; 2131 2132 $text .= vartrue($plugin_config_icon); 2133 2134 if ($this->plug_vars['@attributes']['installRequired']) 2135 { 2136 2137 if ($this->plug['plugin_installflag']) 2138 { 2139 $text .= ($this->plug['plugin_installflag'] ? "<a class='btn btn-default' href=\"".e_SELF."?uninstall.{$this->plug['plugin_id']}\" title='".EPL_ADLAN_1."' >".ADMIN_UNINSTALLPLUGIN_ICON."</a>" : "<a class='btn' href=\"".e_SELF."?install.{$this->plug['plugin_id']}\" title='".EPL_ADLAN_0."' >".ADMIN_INSTALLPLUGIN_ICON."</a>"); 2140 // $text .= ($this->plug['plugin_installflag'] ? "<button type='button' class='delete' value='no-value' onclick=\"location.href='".e_SELF."?uninstall.{$this->plug['plugin_id']}'\"><span>".EPL_ADLAN_1."</span></button>" : "<button type='button' class='update' value='no-value' onclick=\"location.href='".e_SELF."?install.{$this->plug['plugin_id']}'\"><span>".EPL_ADLAN_0."</span></button>"); 2141 if (e_DEBUG && !vartrue($this->plug_vars['plugin_php'])) 2142 { 2143 // $text .= "<br /><br /><input type='button' class='btn btn-default button' onclick=\"location.href='".e_SELF."?refresh.{$this->plug['plugin_id']}'\" title='".'Refresh plugin settings'."' value='".'Refresh plugin settings'."' /> "; 2144 } 2145 } 2146 else 2147 { 2148 // $text .= "<input type='button' class='btn' onclick=\"location.href='".e_SELF."?install.{$this->plug['plugin_id']}'\" title='".EPL_ADLAN_0."' value='".EPL_ADLAN_0."' />"; 2149 // $text .= "<button type='button' class='update' value='no-value' onclick=\"location.href='".e_SELF."?install.{$this->plug['plugin_id']}'\"><span>".EPL_ADLAN_0."</span></button>"; 2150 $text .= "<a class='btn btn-default' href=\"".e_SELF."?install.{$this->plug['plugin_id']}\" title='".EPL_ADLAN_0."' >".ADMIN_INSTALLPLUGIN_ICON."</a>"; 2151 } 2152 2153 } 2154 else 2155 { 2156 if ($this->plug_vars['menuName']) 2157 { 2158 $text .= EPL_NOINSTALL.str_replace("..", "", e_PLUGIN.$this->plug['plugin_path'])."/ ".EPL_DIRECTORY; 2159 } 2160 else 2161 { 2162 $text .= EPL_NOINSTALL_1.str_replace("..", "", e_PLUGIN.$this->plug['plugin_path'])."/ ".EPL_DIRECTORY; 2163 if($this->plug['plugin_installflag'] == false) 2164 { 2165 e107::getDb()->delete('plugin', "plugin_installflag=0 AND (plugin_path='{$this->plug['plugin_path']}' OR plugin_path='{$this->plug['plugin_path']}/' ) "); 2166 } 2167 } 2168 } 2169 2170 if ($this->plug['plugin_version'] != $this->plug_vars['@attributes']['version'] && $this->plug['plugin_installflag']) 2171 { 2172 // $text .= "<br /><input type='button' class='btn' onclick=\"location.href='".e_SELF."?upgrade.{$this->plug['plugin_id']}'\" title='".EPL_UPGRADE." to v".$this->plug_vars['@attributes']['version']."' value='".EPL_UPGRADE."' />"; 2173 e107::getMessage()->addInfo("<b>".$tp->toHTML($this->plug['plugin_name'],false,'TITLE')."</b> is ready to be upgraded. (see below)"); // TODO LAN 2174 $text .= "<a class='btn btn-default' href='".e_SELF."?upgrade.{$this->plug['plugin_id']}' title=\"".EPL_UPGRADE." v".$this->plug_vars['@attributes']['version']."\" >".ADMIN_UPGRADEPLUGIN_ICON."</a>"; 2175 } 2176 2177 if ($this->plug['plugin_installflag'] && e_DEBUG == true) 2178 { 2179 $text .= "<a class='btn btn-default' href='".e_SELF."?repair.".$this->plug['plugin_id']."' title='".LAN_REPAIR_PLUGIN_SETTINGS."'> ".ADMIN_REPAIRPLUGIN_ICON."</a>"; 2180 } 2181 2182 if($this->plug['plugin_installflag'] && is_dir($_path.".git")) 2183 { 2184 $text .= "<a class='plugin-manager btn btn-default' href='".e_SELF."?pull.".$this->plug['plugin_id']."' title='".LAN_SYNC_WITH_GIT_REPO."'> ".ADMIN_GITSYNC_ICON."</a>"; 2185 } 2186 2187 2188 $text .="</div> "; 2189 2190 return $text; 2191 } 2192 2193 2194 2195} 2196*/ 2197/* 2198require_once("auth.php"); 2199$pman->pluginObserver(); 2200$mes = e107::getMessage(); 2201$frm = e107::getForm();*/ 2202 2203require_once("footer.php"); 2204exit; 2205 2206 2207// FIXME switch to admin UI 2208/* 2209class pluginManager{ 2210 2211 var $plugArray; 2212 var $action; 2213 var $id; 2214 var $frm; 2215 var $fieldpref; 2216 var $titlearray = array(); 2217 var $pagetitle; 2218 2219 2220 var $mp; 2221 2222 protected $pid = 'plugin_id'; 2223 2224 protected $fields = array( 2225 2226 "checkboxes" => array("title" => "", 'type'=>null, "forced"=>TRUE, "width"=>"3%", 'thclass'=>'center','class'=>'center'), 2227 "plugin_icon" => array("title" => EPL_ADLAN_82, "type"=>"icon", "width" => "5%", "thclass" => "middle center",'class'=>'center', "url" => ""), 2228 "plugin_name" => array("title" => EPL_ADLAN_10, 'forced'=>true, "type"=>"text", "width" => "auto", 'class'=>'left', "thclass" => "middle", "url" => ""), 2229 "plugin_version" => array("title" => EPL_ADLAN_11, "type"=>"numeric", "width" => "5%", "thclass" => "middle", "url" => ""), 2230 "plugin_date" => array("title" => LAN_RELEASED, "type"=>"text", "width" => "8%", "thclass" => "middle"), 2231 2232 "plugin_folder" => array("title" => EPL_ADLAN_64, "type"=>"text", "width" => "10%", "thclass" => "middle"), 2233 "plugin_category" => array("title" => LAN_CATEGORY, "type"=>"text", "width" => "auto", "thclass" => "middle"), 2234 "plugin_author" => array("title" => LAN_AUTHOR, "type"=>"text", "width" => "10%", "thclass" => "middle"), 2235 "plugin_license" => array("title" => "License", 'nolist'=>true, "forced"=>true, "type"=>"text", "width" => "5%", "thclass" => "left"), 2236 // "plugin_price" => array("title" => "Price", 'nolist'=>true, "forced"=>true, "type"=>"text", "width" => "5%", "thclass" => "left"), 2237 "plugin_compatible" => array("title" => EPL_ADLAN_13, "type"=>"text", "width" => "5%", "thclass" => "middle"), 2238 "plugin_description" => array("title" => EPL_ADLAN_14, "type"=>"bbarea", "width" => "30%", "thclass" => "middle center", 'readParms' => 'expand=1&truncate=180&bb=1'), 2239 "plugin_compliant" => array("title" => EPL_ADLAN_81, "type"=>"text", "width" => "5%", "thclass" => "middle center", "url" => ""), 2240 // "plugin_release" => array("title" => EPL_ADLAN_81, "type"=>"text", "width" => "5%", "thclass" => "middle center", "url" => ""), 2241 // "plugin_notes" => array("title" => EPL_ADLAN_83, "type"=>"url", "width" => "5%", "thclass" => "middle center", "url" => ""), 2242 2243 "options" => array("title" => LAN_OPTIONS, 'forced'=>TRUE, 'type'=> 'method', "width" => "15%", "thclass" => "right last", 'class'=>'right'), 2244 2245 ); 2246 2247 2248 2249 function __construct() 2250 { 2251 global $user_pref,$admin_log; 2252 2253 $qry = str_replace('XDEBUG_PROFILE', '', e_QUERY); 2254 2255 $tmp = explode('.',$qry); 2256 2257 $this -> action = ($tmp[0]) ? $tmp[0] : "installed"; 2258 $this -> id = !empty($tmp[1]) ? intval($tmp[1]) : ""; 2259 $this -> titlearray = array('installed'=>EPL_ADLAN_22,'avail'=>EPL_ADLAN_23, 'upload'=>EPL_ADLAN_38); 2260 2261 if(isset($_GET['mode'])) 2262 { 2263 $this->action = $_GET['mode']; 2264 } 2265 2266 if($this->action == 'online') 2267 { 2268 // $this->fields["plugin_price"]['nolist'] = false; // = array("title" => "Price", "forced"=>true, "type"=>"text", "width" => "5%", "thclass" => "middle center"); 2269 $this->fields["plugin_license"]['nolist'] = false; 2270 } 2271 2272 $keys = array_keys($this -> titlearray); 2273 $this->pagetitle = (in_array($this->action,$keys)) ? $this -> titlearray[$this->action] : $this -> titlearray['installed']; 2274 2275 2276 2277 } 2278 2279 2280 public function getMarketplace() 2281 { 2282 if(null === $this->mp) 2283 { 2284 require_once(e_HANDLER.'e_marketplace.php'); 2285 $this->mp = new e_marketplace(); // autodetect the best method 2286 } 2287 return $this->mp; 2288 } 2289 2290 2291 2292 function pluginObserver() 2293 { 2294 $tp = e107::getParser(); 2295 2296 global $user_pref,$admin_log; 2297 2298 if (isset($_POST['upload'])) 2299 { 2300 $this -> pluginProcessUpload(); 2301 $this->action = 'avail'; 2302 } 2303 2304 if(isset($_POST['etrigger_ecolumns'])) 2305 { 2306 $user_pref['admin_pluginmanager_columns'] = $tp->filter($_POST['e-columns']); 2307 save_prefs('user'); 2308 } 2309 2310 $user_pref['admin_pluginmanager_columns'] = false; 2311 2312 $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"); 2313 2314 2315 foreach($this->fields as $key=>$val) 2316 { 2317 if(vartrue($val['forced']) && substr($key,0,6)=='plugin') 2318 { 2319 $this->fieldpref[] = $key; 2320 } 2321 } 2322 2323 if($this->action == 'download') 2324 { 2325 $this->pluginDownload(); 2326 return; 2327 2328 } 2329 2330 2331 if($this->action == 'pull' && !empty($this->id)) 2332 { 2333 $info = e107::getPlugin()->getinfo($this->id); 2334 2335 if(!empty($info['plugin_path'])) 2336 { 2337 $return = e107::getFile()->gitPull($info['plugin_path'], 'plugin'); 2338 e107::getMessage()->addSuccess($return); 2339 $this->action = 'refresh'; 2340 } 2341 else 2342 { 2343 $this->action = 'avail'; 2344 } 2345 2346 } 2347 2348 2349 2350 if($this->action == 'avail' || $this->action == 'installed') // Plugin Check is done during upgrade_routine. 2351 { 2352 $this -> pluginCheck(); 2353 } 2354 2355 if($this->action == "uninstall") 2356 { 2357 $this -> pluginUninstall(); 2358 $this -> pluginCheck(true); // forced 2359 } 2360 2361 2362 2363 if($this->action == "repair") 2364 { 2365 $this -> pluginRepair(); 2366 $this->action = 'refresh'; 2367 } 2368 2369 2370 2371 if($this->action == "refresh") 2372 { 2373 $this -> pluginCheck(true); // forced 2374 } 2375 2376 if($this->action == "install" || $this->action == "refresh") 2377 { 2378 $this -> pluginInstall(); 2379 $this -> action = "installed"; 2380 } 2381 2382 if($this->action == 'create') 2383 { 2384 $pc = new pluginBuilder; 2385 return; 2386 2387 } 2388 2389 if($this->action == 'lans') 2390 { 2391 $pc = new pluginLanguage; 2392 return; 2393 2394 } 2395 2396 if($this->action == "upgrade") 2397 { 2398 $this -> pluginUpgrade(); 2399 $this -> action = "installed"; 2400 } 2401 2402 2403 2404 if($this->action == "upload") 2405 { 2406 $this -> pluginUpload(); 2407 } 2408 2409 if($this->action == "online") 2410 { 2411 $text = $this -> pluginOnline(); 2412 $mes = e107::getMessage(); 2413 e107::getRender()->tablerender(ADLAN_98.SEP.$caption, $mes->render(). $text); 2414 return; 2415 } 2416 2417 // print_a($_POST); 2418 2419 if(isset($_POST['install-selected'])) 2420 { 2421 foreach($_POST['multiselect'] as $val) 2422 { 2423 $this -> id = intval($val); 2424 $this -> pluginInstall(); 2425 } 2426 $this -> action = "installed"; 2427 } 2428 2429 if($this->action != 'avail' && varset($this->fields['checkboxes'])) 2430 { 2431 unset($this->fields['checkboxes']); // = FALSE; 2432 } 2433 2434 if($this->action !='upload' && $this->action !='uninstall') 2435 { 2436 $this -> pluginRenderList(); 2437 } 2438 2439 2440 2441 } 2442 2443 2444 private function compatibilityLabel($val='') 2445 { 2446 $badge = (vartrue($val) > 1.9) ? "<span class='label label-warning'>".EPL_ADLAN_88."</span>" : '1.x'; 2447 return $badge; 2448 } 2449 2450 2451 2452 function pluginOnline() 2453 { 2454 global $plugin, $e107SiteUsername, $e107SiteUserpass; 2455 $tp = e107::getParser(); 2456 $frm = e107::getForm(); 2457 2458 $caption = EPL_ADLAN_89; 2459 2460 $e107 = e107::getInstance(); 2461 $xml = e107::getXml(); 2462 $mes = e107::getMessage(); 2463 2464 // $mes->addWarning("Some older plugins may produce unpredictable results."); 2465 // check for cURL 2466 if(!function_exists('curl_init')) 2467 { 2468 $mes->addWarning(EPL_ADLAN_90); 2469 } 2470 2471 //TODO use admin_ui including filter capabilities by sending search queries back to the xml script. 2472 $from = isset($_GET['frm']) ? intval($_GET['frm']) : 0; 2473 $srch = preg_replace('/[^\w]/','', vartrue($_GET['srch'])); 2474 2475 2476 $mp = $this->getMarketplace(); 2477 2478 // auth 2479 $mp->generateAuthKey($e107SiteUsername, $e107SiteUserpass); 2480 2481 // do the request, retrieve and parse data 2482 $xdata = $mp->call('getList', array( 2483 'type' => 'plugin', 2484 'params' => array('limit' => 10, 'search' => $srch, 'from' => $from) 2485 )); 2486 $total = $xdata['params']['count']; 2487 2488 // OLD BIT OF CODE -------------------------------> 2489 2490 // OLD BIT OF CODE END -------------------------------> 2491 2492 2493// print_a($xdata); 2494 2495 $c = 1; 2496 foreach($xdata['data'] as $row) 2497 { 2498 //$row = $r['@attributes']; 2499 2500 // print_a($row); 2501 2502 $badge = $this->compatibilityLabel($row['compatibility']);; 2503 $featured = ($row['featured']== 1) ? " <span class='label label-info'>".EPL_ADLAN_91."</span>" : ''; 2504 $price = (!empty($row['price'])) ? "<span class='label label-primary'>".$row['price']." ".$row['currency']."</span>" : "<span class='label label-success'>".EPL_ADLAN_93."</span>"; 2505 2506 $data[] = array( 2507 'plugin_id' => $row['params']['id'], 2508 'plugin_mode' => $row['params']['mode'], 2509 'plugin_icon' => vartrue($row['icon'],'e-plugins-32'), 2510 'plugin_name' => stripslashes($row['name']), 2511 'plugin_featured' => $featured, 2512 'plugin_sef' => '', 2513 'plugin_folder' => $row['folder'], 2514 'plugin_date' => vartrue($row['date']), 2515 'plugin_category' => vartrue($row['category'], 'n/a'), 2516 'plugin_author' => vartrue($row['author']), 2517 'plugin_version' => $row['version'], 2518 'plugin_description' => nl2br(vartrue($row['description'])), 2519 'plugin_compatible' => $badge, 2520 2521 'plugin_website' => vartrue($row['authorUrl']), 2522 'plugin_url' => $row['urlView'], 2523 'plugin_notes' => '', 2524 'plugin_price' => $row['price'], 2525 'plugin_license' => $price 2526 ); 2527 2528 $c++; 2529 } 2530 2531 $fieldList = $this->fields; 2532 unset($fieldList['checkboxes']); 2533 2534 $text = " 2535 <form class='form-search form-inline' action='".e_SELF."?".e_QUERY."' id='core-plugin-list-form' method='get'> 2536 <div id='admin-ui-list-filter' class='e-search '>".$frm->search('srch', $srch, 'go', $filterName, $filterArray, $filterVal).$frm->hidden('mode','online')." 2537 </div> 2538 </form> 2539 2540 <form action='".e_SELF."?".e_QUERY."' id='core-plugin-list-form' method='post'> 2541 <fieldset class='e-filter' id='core-plugin-list'> 2542 <legend class='e-hideme'>".$caption."</legend> 2543 2544 2545 2546 2547 2548 <table id=core-plugin-list' class='table adminlist table-striped'> 2549 ".$frm->colGroup($fieldList,$this->fieldpref). 2550 $frm->thead($fieldList,$this->fieldpref)." 2551 <tbody> 2552 "; 2553 2554 2555 2556 2557 foreach($data as $key=>$val ) 2558 { 2559 // print_a($val); 2560 $text .= "<tr>"; 2561 2562 foreach($this->fields as $v=>$foo) 2563 { 2564 if(!in_array($v,$this->fieldpref) || $v == 'checkboxes') 2565 { 2566 continue; 2567 } 2568 2569 $_value = $val[$v]; 2570 if($v == 'plugin_name') $_value .= $val['plugin_featured']; 2571 // echo '<br />v='.$v; 2572 $text .= "<td style='height: 40px' class='".vartrue($this->fields[$v]['class'],'left')."'>".$frm->renderValue($v, $_value, $this->fields[$v], $key)."</td>\n"; 2573 } 2574 $text .= "<td class='right'>".$this->options($val)."</td>"; 2575 $text .= "</tr>"; 2576 2577 } 2578 2579 2580 $text .= " 2581 </tbody> 2582 </table>"; 2583 $text .= " 2584 </fieldset> 2585 </form> 2586 "; 2587 2588 if($total > $this->perPage) 2589 { 2590 $parms = $total.",".$this->perPage.",".$from.",".e_SELF.'?mode=online&frm=[FROM]'; 2591 2592 if(!empty($srch)) 2593 { 2594 $parms .= '&srch='.$srch; 2595 } 2596 2597 $text .= "<div class='control-group form-inline input-inline' style='text-align:center;margin-top:10px'>".$tp->parseTemplate("{NEXTPREV=$parms}",TRUE)."</div>"; 2598 } 2599 2600 return $text; 2601 2602 } 2603 2604 2605 2606 function options($data) 2607 { 2608 2609 // print_a($data); 2610 2611 2612 2613 //$url = e_SELF."?src=".base64_encode($d); 2614 // $url = e_SELF.'?action=download&src='.base64_encode($d);//$url.'&action=download'; 2615 $id = 'plug_'.$data['plugin_id']; 2616 //<button type='button' data-target='{$id}' data-loading='".e_IMAGE."/generic/loading_32.gif' class='btn btn-primary e-ajax middle' value='Download and Install' data-src='".$url."' ><span>Download and Install</span></button> 2617 $modalCaption = (!empty($data['plugin_price'])) ? EPL_ADLAN_92." ".$data['plugin_name']." ".$data['plugin_version'] : EPL_ADLAN_230." ".$data['plugin_name']." ".$data['plugin_version']; 2618 2619 $srcData = array( 2620 'plugin_id' => $data['plugin_id'], 2621 'plugin_folder' => $data['plugin_folder'], 2622 'plugin_price' => $data['plugin_price'], 2623 'plugin_mode' => $data['plugin_mode'], 2624 'plugin_url' => $data['plugin_url'], 2625 ); 2626 2627 2628 $d = http_build_query($srcData,false,'&'); 2629 $url = e_SELF.'?mode=download&src='.base64_encode($d); 2630 $dicon = '<a title="'.EPL_ADLAN_237.'" class="e-modal btn btn-default" href="'.$url.'" rel="external" data-loading="'.e_IMAGE.'/generic/loading_32.gif" data-cache="false" data-modal-caption="'.$modalCaption.'" target="_blank" >'.ADMIN_INSTALLPLUGIN_ICON.'</a>'; 2631 2632 2633 2634 // Temporary Pop-up version. 2635 // $dicon = '<a class="e-modal" href="'.$data['plugin_url'].'" rel="external" data-modal-caption="'.$data['plugin_name']." ".$data['plugin_version'].'" target="_blank" ><img class="top" src="'.e_IMAGE_ABS.'icons/download_32.png" alt="" /></a>'; 2636 2637 // $dicon = "<a data-toggle='modal' data-modal-caption=\"Downloading ".$data['plugin_name']." ".$data['plugin_version']."\" href='{$url}' data-cache='false' data-target='#uiModal' title='".$LAN_DOWNLOAD."' ><img class='top' src='".e_IMAGE_ABS."icons/download_32.png' alt='' /></a> "; 2638 2639 return "<div id='{$id}' class='right' > 2640 {$dicon} 2641 </div>"; 2642 } 2643 2644 2645 2646 private function pluginDownload() 2647 { 2648 define('e_IFRAME', true); 2649 $frm = e107::getForm(); 2650 $mes = e107::getMessage(); 2651 $tp = e107::getParser(); 2652 2653 // print_a($_GET); 2654 2655 $string = base64_decode($_GET['src']); 2656 parse_str($string, $data); 2657 2658 if(deftrue('e_DEBUG_MARKETPLACE')) 2659 { 2660 echo "<b>DEBUG MODE ACTIVE (no downloading)</b><br />"; 2661 echo '$_GET[src]: '; 2662 print_a($_GET); 2663 2664 echo 'base64 decoded and parsed as $data:'; 2665 print_a($data); 2666 return false; 2667 } 2668 2669 $pluginFolder = !empty($data['plugin_folder']) ? $tp->filter($data['plugin_folder']) : ''; 2670 $pluginUrl = !empty($data['plugin_url']) ? $tp->filter($data['plugin_url']) : ''; 2671 $pluginID = !empty($data['plugin_id']) ? $tp->filter($data['plugin_id']) : ''; 2672 $pluginMode = !empty($data['plugin_mode']) ? $tp->filter($data['plugin_mode']) : ''; 2673 2674 if(!empty($data['plugin_price'])) 2675 { 2676 e107::getRedirect()->go($pluginUrl); 2677 return true; 2678 } 2679 2680 $mp = $this->getMarketplace(); 2681 // $mp->generateAuthKey($e107SiteUsername, $e107SiteUserpass); 2682 2683 2684 2685 // Server flush useless. It's ajax ready state 4, we can't flush (sadly) before that (at least not for all browsers) 2686 $mes->addSuccess(EPL_ADLAN_94); 2687 2688 if($mp->download($pluginID, $pluginMode, 'plugin')) 2689 { 2690 $this -> pluginCheck(true); // rescan the plugin directory 2691 $text = e107::getPlugin()->install($pluginFolder); 2692 2693 $mes->addInfo($text); 2694 echo $mes->render('default', 'success'); 2695 } 2696 else 2697 { 2698 // Unable to continue 2699 echo $mes->addError(EPL_ADLAN_95)->render('default', 'error'); 2700 } 2701 2702 echo $mes->render('default', 'debug'); 2703 return; 2704 2705 2706 2707 $text ="<iframe src='".$pluginUrl."' style='width:99%; height:500px; border:0px'>Loading...</iframe>"; 2708 // print_a($data); 2709 $text .= $frm->open('upload-url-form','post'); 2710 2711 $text .= "<div class='form-inline' style='padding:20px'>"; 2712 $text .= "<input type='text' name='upload_url' size='255' style='width:70%;height:50px;text-align:center' placeholder='".EPL_ADLAN_96."' />"; 2713 $text .= $frm->admin_button('upload_remote_url',1,'create','Install'); 2714 $text .= "</div>"; 2715 $text .= "</div>\n\n"; 2716 2717 $text .= $frm->close(); 2718 echo $text; 2719 2720 } 2721 2722 2723 function pluginUninstall() 2724 { 2725 2726 if(!isset($_POST['uninstall_confirm'])) 2727 { // $id is already an integer 2728 2729 $this->pluginConfirmUninstall(); 2730 return; 2731 } 2732 2733 $post = e107::getParser()->filter($_POST); 2734 $text = e107::getPlugin()->uninstall($this->id, $post); 2735 $this->show_message($text, E_MESSAGE_SUCCESS); 2736 2737 $this->action = 'installed'; 2738 2739 $log = e107::getPlugin()->getLog(); 2740 e107::getDebug()->log($log); 2741 2742 return; 2743 2744 } 2745 2746 2747 2748 2749 2750 function pluginProcessUpload() 2751 { 2752 if (!$_POST['ac'] == md5(ADMINPWCHANGE)) 2753 { 2754 exit; 2755 } 2756 2757 $fl = e107::getFile(); 2758 $data = $fl->getUploaded(e_TEMP); 2759 $mes = e107::getMessage(); 2760 2761 if(empty($data[0]['error'])) 2762 { 2763 if($fl->unzipArchive($data[0]['name'],'plugin')) 2764 { 2765 $mes->addSuccess(EPL_ADLAN_43); 2766 } 2767 else 2768 { 2769 $mes->addError(EPL_ADLAN_97); 2770 } 2771 } 2772 2773 // $data = process_uploaded_files(e_TEMP); 2774 // print_a($data); 2775 2776 echo $mes->render(); 2777 2778 return true; 2779 2780 2781 } 2782 2783 2784// ----------------------------------------------------------------------------- 2785// TODO FIXME - This needs cleaning: e107::getMessage(), limit the globals, etc. 2786 2787 function pluginInstall() 2788 { 2789 global $plugin; 2790 $text = $plugin->install_plugin($this->id); 2791 2792 $log = e107::getAdminLog(); 2793 2794 2795 2796 if ($text === FALSE) 2797 { // Tidy this up 2798 $this->show_message(EPL_ADLAN_99, E_MESSAGE_ERROR); 2799 } 2800 else 2801 { 2802 $plugin->save_addon_prefs('update'); 2803 $info = $plugin->getinfo($this->id); 2804 2805 $name = deftrue($info['plugin_name'],$info['plugin_name']). " v".$info['plugin_version']. "({e_PLUGIN}".$info['plugin_path'].")"; 2806 2807 $log->log_event('PLUGMAN_01', $name, E_LOG_INFORMATIVE, ''); 2808 2809 $this->show_message($text, E_MESSAGE_SUCCESS); 2810 } 2811 2812 } 2813 2814 2815// ----------------------------------------------------------------------------- 2816 2817 function pluginUpgrade() 2818 { 2819 $pref = e107::getPref(); 2820 $admin_log = e107::getAdminLog(); 2821 $plugin = e107::getPlugin(); 2822 2823 $sql = e107::getDb(); 2824 $mes = e107::getMessage(); 2825 $plug = $plugin->getinfo($this->id); 2826 2827 $text = ''; 2828 2829 $_path = e_PLUGIN.$plug['plugin_path'].'/'; 2830 if(file_exists($_path.'plugin.xml')) 2831 { 2832 $plugin->install_plugin_xml($this->id, 'upgrade'); 2833 } 2834 else 2835 { 2836 $eplug_folder = null; 2837 $upgrade_alter_tables = null; 2838 $upgrade_add_prefs = null; 2839 $upgrade_remove_prefs = null; 2840 $upgrade_add_array_pref = null; 2841 $upgrade_remove_array_pref = null; 2842 $eplug_version = null; 2843 2844 2845 2846 include(e_PLUGIN.$plug['plugin_path'].'/plugin.php'); 2847 2848 $text = ''; 2849 2850 $func = $eplug_folder.'_upgrade'; 2851 if (function_exists($func)) 2852 { 2853 $text .= call_user_func($func); 2854 } 2855 2856 if (is_array($upgrade_alter_tables)) 2857 { 2858 $result = $plugin->manage_tables('upgrade', $upgrade_alter_tables); 2859 if (true !== $result) 2860 { 2861 //$text .= EPL_ADLAN_9.'<br />'; 2862 $mes->addWarning(EPL_ADLAN_9) 2863 ->addDebug($result); 2864 } 2865 else 2866 { 2867 $text .= EPL_ADLAN_7."<br />"; 2868 } 2869 } 2870 2871 if (is_array($upgrade_add_prefs)) 2872 { 2873 $plugin->manage_prefs('add', $upgrade_add_prefs); 2874 $text .= EPL_ADLAN_8.'<br />'; 2875 } 2876 2877 if (is_array($upgrade_remove_prefs)) 2878 { 2879 $plugin->manage_prefs('remove', $upgrade_remove_prefs); 2880 } 2881 2882 if (is_array($upgrade_add_array_pref)) 2883 { 2884 foreach($upgrade_add_array_pref as $key => $val) 2885 { 2886 $plugin->manage_plugin_prefs('add', $key, $eplug_folder, $val); 2887 } 2888 } 2889 2890 if (is_array($upgrade_remove_array_pref)) 2891 { 2892 foreach($upgrade_remove_array_pref as $key => $val) 2893 { 2894 $plugin->manage_plugin_prefs('remove', $key, $eplug_folder, $val); 2895 } 2896 } 2897 2898 $plugin->manage_search('upgrade', $eplug_folder); 2899 $plugin->manage_notify('upgrade', $eplug_folder); 2900 2901 $eplug_addons = $plugin -> getAddons($eplug_folder); 2902 2903 $info = $plugin->getinfo($this->id); 2904 2905 $name = deftrue($info['plugin_name'],$info['plugin_name']). " v".$eplug_version. "({e_PLUGIN}".$info['plugin_path'].")"; 2906 2907 e107::getLog()->add('PLUGMAN_02', $name, E_LOG_INFORMATIVE, ''); 2908 $text .= (isset($eplug_upgrade_done)) ? '<br />'.$eplug_upgrade_done : "<br />".LAN_UPGRADE_SUCCESSFUL; 2909 $sql->update('plugin', "plugin_version ='{$eplug_version}', plugin_addons='{$eplug_addons}' WHERE plugin_id='$this->id' "); 2910 $pref['plug_installed'][$plug['plugin_path']] = $eplug_version; // Update the version 2911 2912 e107::getConfig('core')->setPref($pref); 2913 $plugin->rebuildUrlConfig(); 2914 e107::getConfig('core')->save(); 2915 } 2916 2917 2918 $mes->addSuccess($text); 2919 $plugin->save_addon_prefs('update'); 2920 2921 } 2922 2923 2924// ----------------------------------------------------------------------------- 2925 2926 function pluginRepair() 2927 { 2928 // global $plug; 2929 2930 $plug = e107::getSingleton('e107plugin')->getinfo($this->id); 2931 2932 $_path = e_PLUGIN.$plug['plugin_path'].'/'; 2933 if(file_exists($_path.'plugin.xml')) 2934 { 2935 // $text .= $plugin->install_plugin_xml($this->id, 'refresh'); 2936 e107::getSingleton('e107plugin')->refresh($plug['plugin_path']); 2937 e107::getLog()->add('PLUGMAN_04', $this->id.':'.$plug['plugin_path'], E_LOG_INFORMATIVE, ''); 2938 } 2939 2940 } 2941 2942// ----------------------------------------------------------------------------- 2943 2944 // Check for new plugins, create entry in plugin table ... 2945 function pluginCheck($force=false) 2946 { 2947 global $plugin; 2948 2949 if(!PLUGIN_SCAN_INTERVAL) 2950 { 2951 $plugin->update_plugins_table('update'); 2952 return; 2953 } 2954 2955 if((time() > vartrue($_SESSION['nextPluginFolderScan'],0)) || $force == true) 2956 { 2957 $plugin->update_plugins_table('update'); 2958 } 2959 2960 $_SESSION['nextPluginFolderScan'] = time() + PLUGIN_SCAN_INTERVAL; 2961 //echo "TIME = ".$_SESSION['nextPluginFolderScan']; 2962 2963 } 2964 // ---------------------------------------------------------- 2965 // render plugin information ... 2966 2967 2968// ----------------------------------------------------------------------------- 2969 2970 2971 function pluginUpload() 2972 { 2973 global $plugin; 2974 $frm = e107::getForm(); 2975 2976 //TODO 'install' checkbox in plugin upload form. (as it is for theme upload) 2977 2978 2979 if(!is_writable(e_PLUGIN)) 2980 { 2981 $text = EPL_ADLAN_44; 2982 } 2983 else 2984 { 2985 // Get largest allowable file upload 2986 require_once(e_HANDLER.'upload_handler.php'); 2987 $max_file_size = get_user_max_upload(); 2988 2989 $text = " 2990 <form enctype='multipart/form-data' method='post' action='".e_SELF."'> 2991 <table class='table adminform'> 2992 <colgroup> 2993 <col class='col-label' /> 2994 <col class='col-control' /> 2995 </colgroup> 2996 <tr> 2997 <td>".EPL_ADLAN_37."</td> 2998 <td> 2999 <input type='hidden' name='MAX_FILE_SIZE' value='{$max_file_size}' /> 3000 <input type='hidden' name='ac' value='".md5(ADMINPWCHANGE)."' /> 3001 <input class='tbox' type='file' name='file_userfile[]' size='50' /> 3002 </td> 3003 </tr> 3004 </table> 3005 3006 <div class='center buttons-bar'>"; 3007 $text .= $frm->admin_button('upload', EPL_ADLAN_38, 'submit', EPL_ADLAN_38); 3008 3009 $text .= " 3010 </div> 3011 3012 </form>\n"; 3013 } 3014 3015 e107::getRender()->tablerender(ADLAN_98.SEP.EPL_ADLAN_38, $text); 3016 } 3017 3018// ----------------------------------------------------------------------------- 3019 3020 3021 3022 3023 function pluginRenderList() // Uninstall and Install sorting should be fixed once and for all now ! 3024 { 3025 3026 global $plugin; 3027 $frm = e107::getForm(); 3028 $mes = e107::getMessage(); 3029 3030 if($this->action == "" || $this->action == "installed") 3031 { 3032 $installed = $plugin->getall(1); 3033 3034 $mp = $this->getMarketplace(); 3035 3036 $versions = $mp->getVersionList(); 3037 3038 // print_a($versions); 3039 $caption = EPL_ADLAN_22; 3040 $pluginRenderPlugin = $this->pluginRenderPlugin($installed, $versions); 3041 $button_mode = "uninstall-selected"; 3042 $button_caption = EPL_ADLAN_85; 3043 $button_action = "delete"; 3044 } 3045 if($this->action == "avail") 3046 { 3047 $uninstalled = $plugin->getall(0); 3048 $caption = EPL_ADLAN_23; 3049 $pluginRenderPlugin = $this->pluginRenderPlugin($uninstalled); 3050 $button_mode = "install-selected"; 3051 $button_caption = EPL_ADLAN_84; 3052 $button_action = "update"; 3053 } 3054 3055 $text = " 3056 <form action='".e_SELF."?".e_QUERY."' id='core-plugin-list-form' method='post'> 3057 <fieldset id='core-plugin-list'> 3058 <legend class='e-hideme'>".vartrue($caption)."</legend> 3059 <table class='table adminlist table-striped'> 3060 ".$frm->colGroup($this->fields,$this->fieldpref). 3061 $frm->thead($this->fields,$this->fieldpref)." 3062 <tbody> 3063 "; 3064 3065 if(vartrue($pluginRenderPlugin)) 3066 { 3067 $text .= $pluginRenderPlugin; 3068 } 3069 else 3070 { 3071 $text .= "<tr><td class='center' colspan='".count($this->fields)."'>"; 3072 $text .= str_replace("[x]", "<a href='".e_ADMIN."plugin.php?avail'>".EPL_ADLAN_100."</a>", EPL_ADLAN_101); 3073 $text .= "</td></tr>"; 3074 } 3075 3076 $text .= " 3077 </tbody> 3078 </table>"; 3079 3080 if($this->action == "avail") 3081 { 3082 $text .= " 3083 <div class='buttons-bar center'>".$frm->admin_button($button_mode, $button_caption, $button_action)."</div>"; 3084 } 3085 $text .= " 3086 </fieldset> 3087 </form> 3088 "; 3089 3090 e107::getRender()->tablerender(ADLAN_98.SEP.$caption, $mes->render(). $text); 3091 } 3092 3093 3094// ----------------------------------------------------------------------------- 3095 3096 function pluginRenderPlugin($pluginList, $versions = array()) 3097 { 3098 global $plugin; 3099 3100 if (empty($pluginList)) return ''; 3101 3102 $tp = e107::getParser(); 3103 $frm = e107::getForm(); 3104 3105 $pgf = new pluginmanager_form; 3106 3107 $text = ""; 3108 3109 3110 3111 foreach($pluginList as $plug) 3112 { 3113 e107::loadLanFiles($plug['plugin_path'],'admin'); 3114 3115 if($this->action == "avail") 3116 { 3117 e107::lan($plug['plugin_path'],'global', true); // Load language files. 3118 } 3119 3120 3121 3122 $_path = e_PLUGIN.$plug['plugin_path'].'/'; 3123 3124 $plug_vars = false; 3125 $plugin_config_icon = ""; 3126 3127 3128 3129 if($plugin->parse_plugin($plug['plugin_path'])) 3130 { 3131 $plug_vars = $plugin->plug_vars; 3132 } 3133 3134 3135 3136 if(varset($plug['plugin_category']) == "menu") // Hide "Menu Only" plugins. 3137 { 3138 continue; 3139 } 3140 3141 if($plug_vars) 3142 { 3143 3144 $icon_src = (isset($plug_vars['plugin_php']) ? e_PLUGIN : $_path).$plug_vars['administration']['icon']; 3145 3146 $plugin_icon = $plug_vars['administration']['icon'] ? $icon_src : $tp->toGlyph('e-cat_plugins-32'); 3147 3148 3149 $conf_file = "#"; 3150 $conf_title = ""; 3151 3152 if ($plug_vars['administration']['configFile'] && $plug['plugin_installflag'] == true) 3153 { 3154 $conf_file = e_PLUGIN.$plug['plugin_path'].'/'.$plug_vars['administration']['configFile']; 3155 $conf_title = LAN_CONFIGURE.' '.$tp->toHTML($plug_vars['@attributes']['name'], "", "defs,emotes_off, no_make_clickable"); 3156 // $plugin_icon = "<a title='{$conf_title}' href='{$conf_file}' >".$plugin_icon."</a>"; 3157 $plugin_config_icon = "<a class='btn btn-default' title='{$conf_title}' href='{$conf_file}' >".ADMIN_CONFIGURE_ICON."</a>"; 3158 } 3159 3160 $plugEmail = varset($plug_vars['author']['@attributes']['email'],''); 3161 $plugAuthor = varset($plug_vars['author']['@attributes']['name'],''); 3162 $plugURL = varset($plug_vars['author']['@attributes']['url'],''); 3163 $plugDate = varset($plug_vars['@attributes']['date'],''); 3164 $compatibility = varset($plug_vars['@attributes']['compatibility'],''); 3165 3166 $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") ; 3167 3168 $plugReadme = ""; 3169 if(varset($plug['plugin_installflag'])) 3170 { 3171 $plugName = "<a title='{$conf_title}' href='{$conf_file}' >".$tp->toHTML($plug['plugin_name'], false, "defs,emotes_off, no_make_clickable")."</a>"; 3172 } 3173 else 3174 { 3175 $plugName = $tp->toHTML($plug['plugin_name'], false, "defs,emotes_off, no_make_clickable"); 3176 } 3177 if(varset($plug_vars['readme'])) // 0.7 plugin.php 3178 { 3179 $plugReadme = $plug_vars['readme']; 3180 } 3181 if(varset($plug_vars['readMe'])) // 0.8 plugin.xml 3182 { 3183 $plugReadme = $plug_vars['readMe']; 3184 } 3185 3186 if(!file_exists($plugin_icon)) 3187 { 3188 $plugin_icon = 'e-cat_plugins-32'; // e_IMAGE."admin_images/cat_plugins_32.png"; 3189 } 3190 3191 3192 $data = array( 3193 'plugin_id' => $plug['plugin_id'], 3194 'plugin_icon' => $plugin_icon, 3195 'plugin_name' => $plugName, 3196 'plugin_folder' => $plug['plugin_path'], 3197 'plugin_date' => $plugDate, 3198 'plugin_category' => vartrue($plug['plugin_category']), 3199 'plugin_author' => vartrue($plugAuthor), // vartrue($plugEmail) ? "<a href='mailto:".$plugEmail."' title='".$plugEmail."'>".$plugAuthor."</a>" : vartrue($plugAuthor), 3200 'plugin_version' => $plug['plugin_version'], 3201 'plugin_description' => $description, 3202 'plugin_compatible' => $this->compatibilityLabel($plug_vars['@attributes']['compatibility']), 3203 3204 'plugin_website' => vartrue($plug['authorUrl']), 3205 // 'plugin_url' => vartrue($plugURL), // ; // ? "<a href='{$plugURL}' title='{$plugURL}' >".ADMIN_URL_ICON."</a>" : "", 3206 'plugin_notes' => '' 3207 ); 3208 3209 3210 $pgf->plug_vars = $plug_vars; 3211 $pgf->plug = $plug; 3212 $text .= $pgf->renderTableRow($this->fields, $this->fieldpref, $data, 'plugin_id'); 3213 3214 3215 3216 } 3217 } 3218 return $text; 3219 } 3220 3221 3222// ----------------------------------------------------------------------------- 3223 3224 3225 3226 function pluginConfirmUninstall() 3227 { 3228 global $plugin; 3229 3230 $frm = e107::getForm(); 3231 $tp = e107::getParser(); 3232 $mes = e107::getMessage(); 3233 3234 $plug = $plugin->getinfo($this->id); 3235 3236 if ($plug['plugin_installflag'] == true ) 3237 { 3238 if($plugin->parse_plugin($plug['plugin_path'])) 3239 { 3240 $plug_vars = $plugin->plug_vars; 3241 } 3242 else 3243 { 3244 return FALSE; 3245 } 3246 } 3247 else 3248 { 3249 return FALSE; 3250 } 3251 $userclasses = ''; 3252 $eufields = ''; 3253 if (isset($plug_vars['userClasses'])) 3254 { 3255 if (isset($plug_vars['userclass']['@attributes'])) 3256 { 3257 $plug_vars['userclass'][0]['@attributes'] = $plug_vars['userclass']['@attributes']; 3258 unset($plug_vars['userclass']['@attributes']); 3259 } 3260 $spacer = ''; 3261 foreach ($plug_vars['userClasses']['class'] as $uc) 3262 { 3263 $userclasses .= $spacer.$uc['@attributes']['name'].' - '.$uc['@attributes']['description']; 3264 $spacer = '<br />'; 3265 } 3266 } 3267 if (isset($plug_vars['extendedFields'])) 3268 { 3269 if (isset($plug_vars['extendedFields']['@attributes'])) 3270 { 3271 $plug_vars['extendedField'][0]['@attributes'] = $plug_vars['extendedField']['@attributes']; 3272 unset($plug_vars['extendedField']['@attributes']); 3273 } 3274 $spacer = ''; 3275 foreach ($plug_vars['extendedFields']['field'] as $eu) 3276 { 3277 $eufields .= $spacer.'plugin_'.$plug_vars['folder'].'_'.$eu['@attributes']['name']; 3278 $spacer = '<br />'; 3279 } 3280 } 3281 3282 if(is_writable(e_PLUGIN.$plug['plugin_path'])) 3283 { 3284 $del_text = $frm->select('delete_files','yesno',0); 3285 } 3286 else 3287 { 3288 $del_text = " 3289 ".EPL_ADLAN_53." 3290 <input type='hidden' name='delete_files' value='0' /> 3291 "; 3292 } 3293 3294 $text = " 3295 <form action='".e_SELF."?".e_QUERY."' method='post'> 3296 <fieldset id='core-plugin-confirmUninstall'> 3297 <legend>".EPL_ADLAN_54." ".$tp->toHTML($plug_vars['@attributes']['name'], "", "defs,emotes_off, no_make_clickable")."</legend> 3298 <table class='table adminform'> 3299 <colgroup> 3300 <col class='col-label' /> 3301 <col class='col-control' /> 3302 </colgroup> 3303 <tr> 3304 <td>".EPL_ADLAN_55."</td> 3305 <td>".LAN_YES."</td> 3306 </tr>"; 3307 3308 $opts = array(); 3309 3310 $opts['delete_tables'] = array( 3311 'label' => EPL_ADLAN_57, 3312 'helpText' => EPL_ADLAN_58, 3313 'itemList' => array(1=>LAN_YES,0=>LAN_NO), 3314 'itemDefault' => 1 3315 ); 3316 3317 if ($userclasses) 3318 { 3319 $opts['delete_userclasses'] = array( 3320 'label' => EPL_ADLAN_78, 3321 'preview' => $userclasses, 3322 'helpText' => EPL_ADLAN_79, 3323 'itemList' => array(1=>LAN_YES,0=>LAN_NO), 3324 'itemDefault' => 1 3325 ); 3326 } 3327 3328 if ($eufields) 3329 { 3330 $opts['delete_xfields'] = array( 3331 'label' => EPL_ADLAN_80, 3332 'preview' => $eufields, 3333 'helpText' => EPL_ADLAN_79, 3334 'itemList' => array(1=>LAN_YES,0=>LAN_NO), 3335 'itemDefault' => 0 3336 ); 3337 } 3338 3339 $med = e107::getMedia(); 3340 $icons = $med->listIcons(e_PLUGIN.$plug['plugin_path']); 3341 3342 $iconText = ''; 3343 3344 if(count($icons)>0) 3345 { 3346 foreach($icons as $key=>$val) 3347 { 3348 $iconText .= "<img src='".$tp->replaceConstants($val)."' alt='' />"; 3349 } 3350 3351 $iconText = '<div class="icon-pool-preview">'.$iconText.'</div>'; 3352 3353 $opts['delete_ipool'] = array( 3354 'label' => EPL_ADLAN_231, 3355 'preview' => $iconText, 3356 'helpText' => EPL_ADLAN_79, 3357 'itemList' => array(1=>LAN_YES,0=>LAN_NO), 3358 'itemDefault' => 1 3359 ); 3360 3361 3362 } 3363 3364 3365 3366 if(is_readable(e_PLUGIN.$plug['plugin_path']."/".$plug['plugin_path']."_setup.php")) 3367 { 3368 include_once(e_PLUGIN.$plug['plugin_path']."/".$plug['plugin_path']."_setup.php"); 3369 3370 3371 $mes->add("Loading ".e_PLUGIN.$plug['plugin_path']."/".$plug['plugin_path']."_setup.php", E_MESSAGE_DEBUG); 3372 3373 $class_name = $plug['plugin_path']."_setup"; 3374 3375 if(class_exists($class_name)) 3376 { 3377 $obj = new $class_name; 3378 if(method_exists($obj,'uninstall_options')) 3379 { 3380 $arr = call_user_func(array($obj,'uninstall_options'), $this); 3381 foreach($arr as $key=>$val) 3382 { 3383 $newkey = $plug['plugin_path']."_".$key; 3384 $opts[$newkey] = $val; 3385 } 3386 } 3387 } 3388 } 3389 3390 foreach($opts as $key=>$val) 3391 { 3392 $text .= "<tr>\n<td class='top'>".$tp->toHTML($val['label'],FALSE,'TITLE'); 3393 $text .= varset($val['preview']) ? "<div class='indent'>".$val['preview']."</div>" : ""; 3394 $text .= "</td>\n<td>".$frm->select($key,$val['itemList'],$val['itemDefault']); 3395 $text .= varset($val['helpText']) ? "<div class='field-help'>".$val['helpText']."</div>" : ""; 3396 $text .= "</td>\n</tr>\n"; 3397 } 3398 3399 3400 $text .="<tr> 3401 <td>".EPL_ADLAN_59."</td> 3402 <td>{$del_text} 3403 <div class='field-help'>".EPL_ADLAN_60."</div> 3404 </td> 3405 </tr> 3406 </table> 3407 <div class='buttons-bar center'>"; 3408 3409 $text .= $frm->admin_button('uninstall_confirm',EPL_ADLAN_3,'submit'); 3410 $text .= $frm->admin_button('uninstall_cancel',EPL_ADLAN_62,'cancel'); 3411 3412 3413 // $frm->admin_button($name, $value, $action = 'submit', $label = '', $options = array()); 3414 3415 $text .= "</div> 3416 </fieldset> 3417 </form> 3418 "; 3419 // e107::getRender()->tablerender(EPL_ADLAN_63.SEP.$tp->toHTML($plug_vars['@attributes']['name'], "", "defs,emotes_off, no_make_clickable"),$mes->render(). $text); 3420 3421 } 3422 3423 function show_message($message, $type = E_MESSAGE_INFO, $session = false) 3424 { 3425 // ##### Display comfort --------- 3426 $mes = e107::getMessage(); 3427 $mes->add($message, $type, $session); 3428 } 3429 3430 function pluginMenuOptions() 3431 { 3432 // $e107 = &e107::getInstance(); 3433 3434 $var['installed']['text'] = EPL_ADLAN_22; 3435 $var['installed']['link'] = e_SELF; 3436 3437 $var['avail']['text'] = EPL_ADLAN_23; 3438 $var['avail']['link'] = e_SELF."?avail"; 3439 3440 3441 $var['online']['text'] = EPL_ADLAN_220; 3442 $var['online']['link'] = e_SELF."?mode=online"; 3443 3444 3445 if(E107_DEBUG_LEVEL > 0) 3446 { 3447 $var['upload']['text'] = EPL_ADLAN_38; 3448 $var['upload']['link'] = e_SELF."?mode=upload"; 3449 } 3450 3451 $var['create']['text'] = EPL_ADLAN_114; 3452 $var['create']['link'] = e_SELF."?mode=create"; 3453 3454 3455 3456 3457 3458 $keys = array_keys($var); 3459 3460 $action = (in_array($this->action,$keys)) ? $this->action : "installed"; 3461 3462 if($this->action == 'lans') 3463 { 3464 $action = 'create'; 3465 } 3466 3467 $icon = e107::getParser()->toIcon('e-plugmanager-24'); 3468 $caption = $icon."<span>".ADLAN_98."</span>"; 3469 3470 e107::getNav()->admin($caption, $action, $var); 3471 } 3472 3473 3474 3475 3476 3477} // end of Class. 3478*/ 3479 3480/* 3481function plugin_adminmenu() 3482{ 3483 global $pman; 3484 $pman -> pluginMenuOptions(); 3485}*/ 3486 3487 3488 3489 3490/** 3491 * Plugin Admin Generator by CaMer0n. //TODO - Added dummy template and shortcode creation, plus e_search, e_cron, e_xxxxx etc. 3492 */ 3493class pluginBuilder 3494{ 3495 3496 var $fields = array(); 3497 var $table = ''; 3498 var $pluginName = ''; 3499 var $special = array(); 3500 var $tableCount = 0; 3501 var $tableList = array(); 3502 var $createFiles = false; 3503 private $buildTable = false; 3504 private $debug = false; 3505 3506 function __construct() 3507 { 3508 3509 if(e_DEBUG == true) 3510 { 3511 $this->debug = true; 3512 } 3513 3514 $this->special['checkboxes'] = array('title'=> '','type' => null, 'data' => null, 'width'=>'5%', 'thclass' =>'center', 'forced'=> TRUE, 'class'=>'center', 'toggle' => 'e-multiselect', 'fieldpref'=>true); 3515 $this->special['options'] = array( 'title'=> 'LAN_OPTIONS', 'type' => null, 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced'=>TRUE, 'fieldpref'=>true); 3516 3517 3518 } 3519 3520 3521 function run() 3522 { 3523 3524 if(!empty($_GET['newplugin'])) 3525 { 3526 $this->pluginName = e107::getParser()->filter($_GET['newplugin'],'file'); 3527 } 3528 3529 if(!empty($_GET['createFiles'])) 3530 { 3531 $this->createFiles = true; 3532 } 3533 3534 if(vartrue($_POST['step']) == 4) 3535 { 3536 return $this->step4(); 3537 } 3538 3539 if(vartrue($_GET['step']) == 3) 3540 { 3541 return $this->step3(); 3542 } 3543 3544 3545 3546 3547 if(!empty($_GET['newplugin']) && $_GET['step']==2) 3548 { 3549 return $this->step2(); 3550 } 3551 3552 3553 3554 return $this->step1(); 3555 3556 3557 } 3558 3559 3560 3561 function step1() 3562 { 3563 3564 $fl = e107::getFile(); 3565 $frm = e107::getForm(); 3566 $ns = e107::getRender(); 3567 $mes = e107::getMessage(); 3568 $tp = e107::getParser(); 3569 3570 $plugFolders = $fl->get_dirs(e_PLUGIN); 3571 foreach($plugFolders as $dir) 3572 { 3573 $lanDir[$dir] = $dir; 3574 if(E107_DEBUG_LEVEL == 0 && file_exists(e_PLUGIN.$dir."/admin_config.php")) 3575 { 3576 continue; 3577 } 3578 $newDir[$dir] = $dir; 3579 } 3580 3581 3582 $info = EPL_ADLAN_102; 3583 $info .= "<ul>"; 3584 $info .= "<li>".str_replace(array('[x]', '[b]', '[/b]'), array(e_PLUGIN, '<strong>', '</strong>'), EPL_ADLAN_103)."</li>"; 3585 // $info .= "<li>".EPL_ADLAN_104."</li>"; 3586 $info .= "<li>".str_replace(array('[b]', '[/b]'), array('<strong>', '</strong>'), EPL_ADLAN_105)."</li>"; 3587 $info .= "<li>".EPL_ADLAN_106."</li>"; 3588 $info .= "</ul>"; 3589 3590 // $mes->addInfo($tp->toHTML($info,true)); 3591 3592 $text = $frm->open('createPlugin','get', e_SELF); 3593 $text .= $frm->hidden('action', 'build'); 3594 3595 $text .= "<table class='table adminform'> 3596 <colgroup> 3597 <col class='col-label' /> 3598 <col class='col-control' /> 3599 <col class='col-control' /> 3600 </colgroup> 3601 <tr> 3602 <td>".EPL_ADLAN_107."</td> 3603 <td><div class='input-append form-inline'>".$frm->open('createPlugin','get',e_SELF."?mode=create").$frm->select("newplugin",$newDir, false, 'size=xlarge').$frm->admin_button('step', 2,'other',LAN_GO)."</div> ".$frm->checkbox('createFiles',1,1,EPL_ADLAN_255).$frm->close()."</td> 3604 <td><div class='alert alert-info'>".$info."</div></td> 3605 </tr> 3606 3607 <tr> 3608 <td>".EPL_ADLAN_108."</td> 3609 <td><div class='input-append form-inline'>".$frm->open('checkPluginLangs','get',e_SELF."?mode=lans").$frm->select("newplugin",$lanDir, false, 'size=xlarge').$frm->admin_button('step', 2,'other',LAN_GO)."</div> ".$frm->close()."</td> 3610 <td><div class='alert alert-info'>".EPL_ADLAN_254."</div></td> 3611 </tr>"; 3612 3613 3614 /* NOT a good idea - requires the use of $_POST which would prevent browser 'go Back' navigation. 3615 if(e_DOMAIN == FALSE) // localhost. 3616 { 3617 $text .= "<tr> 3618 <td>Pasted MySql Dump Here</td> 3619 <td>".$frm->textarea('mysql','', 10,80)." 3620 <span class='field-help'>eg. </span></td> 3621 </tr>"; 3622 } 3623 */ 3624 3625 3626 $text .= " 3627 </table> 3628 <div class='buttons-bar center'> 3629 3630 </div>"; 3631 3632 $text .= $frm->close(); 3633 3634 return $text; 3635 3636 // $ns->tablerender(ADLAN_98.SEP.EPL_ADLAN_114, $mes->render() . $text); 3637 3638 3639 3640 // $var['lans']['text'] = EPL_ADLAN_226; 3641 // $var['lans']['link'] = e_SELF."?mode=lans"; 3642 3643 3644 } 3645 3646 3647 function enterMysql() 3648 { 3649 3650 $frm = e107::getForm(); 3651 return "<div>".$frm->textarea('mysql','', 10,80)."</div>"; 3652 3653 } 3654 3655 3656 /** 3657 * @param string $table 3658 * @param string $file 3659 */ 3660 private function buildSQLFile($table, $file) 3661 { 3662 3663 $table = e107::getParser()->filter($table); 3664 3665 e107::getDb()->gen("SHOW CREATE TABLE `#".$table."`"); 3666 $data = e107::getDb()->fetch('num'); 3667 3668 if(!empty($data[1])) 3669 { 3670 $createData = str_replace("`".MPREFIX, '`', $data[1]); 3671 $createData .= ";"; 3672 if(!file_exists($file)/* && empty($this->createFiles)*/) 3673 { 3674 file_put_contents($file,$createData); 3675 } 3676 } 3677 3678 } 3679 3680 3681 3682 3683 function step3() 3684 { 3685 3686 // require_once(e_HANDLER."db_verify_class.php"); 3687 // $dv = new db_verify; 3688 $dv = e107::getSingleton('db_verify', e_HANDLER."db_verify_class.php"); 3689 3690 $frm = e107::getForm(); 3691 $ns = e107::getRender(); 3692 $mes = e107::getMessage(); 3693 $tp = e107::getParser(); 3694 3695 3696 $newplug = $tp->filter($_GET['newplugin'],'file'); 3697 $this->pluginName = $newplug; 3698 3699 $sqlFile = e_PLUGIN.$newplug."/".$newplug."_sql.php"; 3700 3701 if(!empty($_GET['build']) && !file_exists($sqlFile)) 3702 { 3703 $this->buildSQLFile($_GET['build'], $sqlFile); 3704 } 3705 3706 $ret = array(); 3707 3708 if(file_exists($sqlFile)) 3709 { 3710 $data = file_get_contents($sqlFile); 3711 $ret = $dv->getSqlFileTables($data); 3712 } 3713 else 3714 { 3715 e107::getDebug()->log("SQL File Not Found"); 3716 // $this->buildTable = true; 3717 } 3718 3719 $text = $frm->open('newplugin-step3','post', e_SELF.'?mode=create&action=build&newplugin='.$newplug.'&createFiles='.$this->createFiles.'&step=3'); 3720 3721 $text .= "<ul class='nav nav-tabs'>\n"; 3722 $text .= "<li class='active'><a data-toggle='tab' href='#xml'>".EPL_ADLAN_109."</a></li>"; 3723 3724 $this->tableCount = count($ret['tables']); 3725 3726 if(!empty($ret['tables'])) 3727 { 3728 foreach($ret['tables'] as $key=>$table) 3729 { 3730 $label = "Table: ".$table; 3731 $text .= "<li><a data-toggle='tab' href='#".$table."'>".$label."</a></li>"; 3732 $this->tableList[] = $table; 3733 } 3734 } 3735 3736 3737 $text .= "<li><a data-toggle='tab' href='#preferences'>".LAN_PREFS."</a></li>"; 3738 $text .= "<li><a data-toggle='tab' href='#addons'>".LAN_ADDONS."</a></li>"; //TODO LAN 3739 3740 3741 $text .= "</ul>"; 3742 3743 $text .= "<div class='tab-content'>\n"; 3744 3745 $text .= "<div class='tab-pane active' id='xml'>\n"; 3746 $text .= $this->pluginXml(); 3747 $text .= "</div>"; 3748 3749 if(!empty($ret['tables'])) 3750 { 3751 foreach($ret['tables'] as $key=>$table) 3752 { 3753 $text .= "<div class='tab-pane' id='".$table."'>\n"; 3754 $fields = $dv->getFields($ret['data'][$key]); 3755 $text .= $this->form($table,$fields); 3756 $text .= "</div>"; 3757 } 3758 } 3759 3760 3761 3762 3763 $text .= "<div class='tab-pane' id='preferences'>\n"; 3764 $text .= $this->prefs(); 3765 $text .= "</div>"; 3766 3767 3768 $text .= "<div class='tab-pane' id='addons'>\n"; 3769 $text .= $this->addons(); 3770 $text .= "</div>"; 3771 3772 3773 if(empty($ret['tables'])) 3774 { 3775 $text .= $frm->hidden($this->pluginName.'_ui[mode]','main'); 3776 $text .= $frm->hidden($this->pluginName.'_ui[pluginName]', $this->pluginName); 3777 } 3778 3779 $text .= "</div>"; 3780 3781 $text .= " 3782 <div class='buttons-bar center'> 3783 ".$frm->hidden('newplugin', $this->pluginName)." 3784 ".$frm->admin_button('step', 4,'other', LAN_GENERATE)." 3785 </div>"; 3786 3787 $text .= $frm->close(); 3788 3789 $mes->addInfo(EPL_ADLAN_112); 3790 3791 $mes->addInfo(EPL_ADLAN_113); 3792 3793 return array('caption'=>EPL_ADLAN_115, 'text'=> $text); 3794 // $ns->tablerender(ADLAN_98.SEP.EPL_ADLAN_114.SEP., $mes->render() . $text); 3795 } 3796 3797 3798 3799 private function step2() 3800 { 3801 3802 3803 $frm = e107::getForm(); 3804 3805 $tables = e107::getDb()->tables(); 3806 3807 3808 $text = $frm->open('buildTab', 'get', e_REQUEST_SELF); 3809 3810 $text .= "<table class='table adminform'> 3811 <tr><td colspan='2'><h4>".ucfirst(LAN_OPTIONAL)."</h4></td></tr> 3812 3813 <tr> 3814 <td class='col-label'>To generate your <em>".$this->pluginName."_sql.php</em> table creation file, please select your sql table then click 'Refresh'</td> 3815 <td class='form-inline'>"; 3816 3817 $text .= $frm->select('build', $tables, null, array('useValues'=>1), "(".LAN_OPTIONAL.")"); 3818 3819 3820 // $text .= "<a href='#' id='build-table-submit' class='btn btn-success'>Refresh</a>"; 3821 // $text .= $frm->button('step', 3, 'submit', "Continue"); 3822 unset($_GET['step']); 3823 foreach($_GET as $k=>$v) 3824 { 3825 $text .= $frm->hidden($k,$v); 3826 3827 } 3828 // $text .= $frm->hidden("build_table_url", e_REQUEST_SELF.'?'.$qry, array('id'=>'build-table-url')); 3829 3830 3831 $text .= "</td></tr> 3832 <tr><td> </td><td> 3833 ".$frm->button('step', 3, 'submit', LAN_CONTINUE)." 3834 </td></tr></table>"; 3835 3836 $text .= $frm->close(); 3837 3838/* 3839 e107::js('footer-inline',' 3840 3841 $(document).on("click", "#build-table-submit", function(e){ 3842 3843 e.preventDefault(); 3844 3845 $(this).addClass("disabled"); 3846 3847 var url = $("#build-table-url").val(); 3848 var sel = $("#build-table-tbl").val(); 3849 3850 url = url + "&build=" + sel; 3851 3852 window.location.href = url; 3853 3854 return false; 3855 }); 3856 3857 3858 3859 3860 3861 ');*/ 3862 $ns = e107::getRender(); 3863 return array('caption'=>EPL_ADLAN_115, 'text'=>$text); 3864 // $ns->tablerender(ADLAN_98.SEP.EPL_ADLAN_114.SEP.EPL_ADLAN_115, $text); 3865 3866 3867 return $text; 3868 3869 } 3870 3871 3872 3873 3874 3875 private function buildTemplateFile() 3876 { 3877 $dirName = e_PLUGIN.$this->pluginName. "/templates"; 3878 3879 if(!is_dir($dirName)) 3880 { 3881 mkdir($dirName,0755); 3882 } 3883 3884 3885 $file = $dirName. "/".$this->pluginName."_template.php"; 3886 $shortFileName = "templates/".$this->pluginName."_template.php"; 3887 3888 if(file_exists($file) && empty($this->createFiles)) 3889 { 3890 return e107::getParser()->lanVars(EPL_ADLAN_256,$shortFileName); 3891 } 3892 3893 3894$content = <<<TMPL 3895<?php 3896 3897// Template File 3898TMPL; 3899 3900$upperName = strtoupper($this->pluginName); 3901 3902$content .= " 3903// ".$this->pluginName." Template file 3904 3905if (!defined('e107_INIT')) { exit; } 3906 3907 3908\$".$upperName."_TEMPLATE = array(); 3909 3910\$".$upperName."_TEMPLATE['default']['start'] \t= '{SETIMAGE: w=400&h=300}'; 3911 3912\$".$upperName."_TEMPLATE['default']['item'] \t= ''; 3913 3914\$".$upperName."_TEMPLATE['default']['end'] \t= ''; 3915 3916 3917 3918"; 3919 3920 3921 return file_put_contents($file,$content)? LAN_CREATED.': '.$shortFileName : LAN_CREATED_FAILED.': '.$shortFileName; 3922 } 3923 3924 3925 3926 3927 3928 private function buildShortcodesFile() 3929 { 3930 $file = e_PLUGIN.$this->pluginName. "/".$this->pluginName."_shortcodes.php"; 3931 3932$content = <<<TMPL 3933<?php 3934 3935 3936TMPL; 3937 3938$content .= " 3939// ".$this->pluginName." Shortcodes file 3940 3941if (!defined('e107_INIT')) { exit; } 3942 3943class plugin_".$this->pluginName."_".$this->pluginName."_shortcodes extends e_shortcode 3944{ 3945 3946"; 3947 3948 if(!empty($_POST['bullets_ui']['fields'])) 3949 { 3950 foreach($_POST['bullets_ui']['fields'] as $key=>$row) 3951 { 3952 3953 if($key === 'options' || $key === 'checkboxes') 3954 { 3955 continue; 3956 } 3957 3958$content .= " 3959 /** 3960 * {".strtoupper($key)."} 3961 */ 3962 public function sc_".$key."(\$parm=null) 3963 { 3964 3965 return \$this->var['".$key."']; 3966 } 3967 3968 3969"; 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 } 3981 3982 3983 } 3984 3985 3986$content .= '}'; 3987 3988 return file_put_contents($file,$content)? LAN_CREATED.': '.$this->pluginName."_shortcodes.php" : LAN_CREATED_FAILED.': '.$this->pluginName."_shortcodes.php"; 3989 } 3990 3991 3992 private function createAddons($list) 3993 { 3994 3995 $srch = array('_blank','blank'); 3996 $result = array(); 3997 3998 foreach($list as $addon) 3999 { 4000 $addonDest = str_replace("_blank",$this->pluginName,$addon); 4001 $source = e_PLUGIN."_blank/".$addon.".php"; 4002 $destination = e_PLUGIN.$this->pluginName. "/".$addonDest.".php"; 4003 4004 if(file_exists($destination) && empty($this->createFiles)) 4005 { 4006 $result[] = e107::getParser()->lanVars(EPL_ADLAN_256,$addonDest.'.php'); 4007 continue; 4008 } 4009 4010 if($addon === '_blank_template') 4011 { 4012 $result[] = $this->buildTemplateFile(); 4013 continue; 4014 } 4015 4016 if($addon === '_blank_shortcodes') 4017 { 4018 $result[] = $this->buildShortcodesFile(); 4019 continue; 4020 } 4021 4022 if($content = file_get_contents($source)) 4023 { 4024 $content = str_replace($srch, $this->pluginName, $content); 4025 4026 if(file_exists($destination) && empty($this->createFiles)) 4027 { 4028 $result[] = e107::getParser()->lanVars(EPL_ADLAN_256,$addonDest.'.php'); 4029 } 4030 else 4031 { 4032 if(file_put_contents($destination,$content)) 4033 { 4034 $result[] = LAN_CREATED." : ".$addonDest.".php"; 4035 } 4036 } 4037 } 4038 else 4039 { 4040 //$mes->addError("Addon source-file was empty: ".$addon); 4041 } 4042 4043 } 4044 4045 return $result; 4046 } 4047 4048 4049 4050 4051 private function addons() 4052 { 4053 $plg = e107::getPlugin(); 4054 4055 $list = $plg->getAddonsList(); 4056 $frm = e107::getForm(); 4057 $text = "<table class='table table-striped adminlist' >"; 4058 4059 4060 //Todo LANS 4061 $dizOther = array( 4062 '_blank' => "Simple frontend script", 4063 '_blank_setup' => "Create default table data during install, upgrade, uninstall etc", 4064 '_blank_menu' => "Menu item for use in the menu manager.", 4065 '_blank_template' => "Template to allow layout customization by themes.", 4066 '_blank_shortcodes' => "Shortcodes for the template." 4067 ); 4068 4069 array_unshift($list,'_blank', '_blank_setup', '_blank_menu', '_blank_template', '_blank_shortcodes'); 4070 4071 $templateFiles = scandir(e_PLUGIN."_blank"); 4072 4073 4074 4075 //print_a($list); 4076 // $list[] = "_blank"; 4077 // $list[] = "_blank_setup"; 4078 4079 foreach($list as $v) 4080 { 4081 4082 if(!in_array($v.".php", $templateFiles) && $v != '_blank_template' && $v!='_blank_shortcodes') 4083 { 4084 continue; 4085 } 4086 4087 $diz = !empty($dizOther[$v]) ? $dizOther[$v] : $plg->getAddonsDiz($v); 4088 $label = str_replace("_blank", $this->pluginName, $v); 4089 $id = str_replace('_blank', 'blank', $v); 4090 4091 $text .= "<tr>"; 4092 $text .= "<td>".$frm->checkbox('addons[]',$v,false,$label)."</td>"; 4093 $text .= "<td><label for='".$frm->name2id('addons-'.$id)."'>".$diz."</label></td>"; 4094 $text .= "</tr>"; 4095 } 4096 4097 $text .= "</table>"; 4098 4099 return $text; 4100 4101 } 4102 4103 4104 4105 function prefs() 4106 { 4107 $frm = e107::getForm(); 4108 4109 $text = ''; 4110 4111 $options = array( 4112 'text' => EPL_ADLAN_116, 4113 'number' => EPL_ADLAN_117, 4114 'url' => EPL_ADLAN_118, 4115 'textarea' => EPL_ADLAN_119, 4116 'bbarea' => EPL_ADLAN_120, 4117 'boolean' => EPL_ADLAN_121, 4118 "method" => EPL_ADLAN_122, 4119 "image" => EPL_ADLAN_123, 4120 4121 "dropdown" => EPL_ADLAN_124, 4122 "userclass" => EPL_ADLAN_125, 4123 "language" => EPL_ADLAN_126, 4124 4125 "icon" => EPL_ADLAN_127, 4126 4127 "file" => EPL_ADLAN_128, 4128 4129 ); 4130 4131 4132 $text = "<table class='table table-striped'>"; 4133 4134 for ($i=0; $i < 10; $i++) 4135 { 4136 $text .= "<tr><td>". 4137 $frm->text("pluginPrefs[".$i."][index]", '',40,'placeholder='.EPL_ADLAN_129)."</td><td>". 4138 $frm->text("pluginPrefs[".$i."][value]", '',50,'placeholder='.EPL_ADLAN_130)."</td><td>". 4139 $frm->select("pluginPrefs[".$i."][type]", $options, '', 'class=null', EPL_ADLAN_131)."</td><td>". 4140 $frm->text("pluginPrefs[".$i."][help]", '',80,'size=xxlarge&placeholder='.EPL_ADLAN_174)."</td>". 4141 "</tr>"; 4142 } 4143 4144 $text .= "</table>"; 4145 return $text; 4146 } 4147 4148 4149 function pluginXml() 4150 { 4151 4152 4153 //TODO Plugin.xml Form Fields. . 4154 4155 $data = array( 4156 'main' => array('name','lang','version','date', 'compatibility'), 4157 'author' => array('name','url'), 4158 'summary' => array('summary'), 4159 'description' => array('description'), 4160 'keywords' => array('one','two','three'), 4161 'category' => array('category'), 4162 'copyright' => array('copyright'), 4163 // 'adminLinks' => array('url','description','icon','iconSmall','primary'), 4164 // 'sitelinks' => array('url','description','icon','iconSmall') 4165 ); 4166 4167 // Load old plugin.php file if it exists; 4168 $legacyFile = e_PLUGIN.$this->pluginName."/plugin.php"; 4169 if(file_exists($legacyFile)) 4170 { 4171 $eplug_name = $eplug_author = $eplug_url = $eplug_description = ""; 4172 $eplug_tables = array(); 4173 4174 require_once($legacyFile); 4175 $mes = e107::getMessage(); 4176 $mes->addInfo("Loading plugin.php file"); 4177 4178 $defaults = array( 4179 "main-name" => $eplug_name, 4180 "author-name" => $eplug_author, 4181 "author-url" => $eplug_url, 4182 "description-description" => $eplug_description, 4183 "summary-summary" => $eplug_description 4184 ); 4185 4186 if(count($eplug_tables) && !file_exists(e_PLUGIN.$this->pluginName."/".$this->pluginName."_sql.php")) 4187 { 4188 4189 $cont = ''; 4190 foreach($eplug_tables as $tab) 4191 { 4192 if(strpos($tab,"INSERT INTO")!==FALSE) 4193 { 4194 continue; 4195 } 4196 4197 $cont .= "\n".str_replace("\t"," ",$tab); 4198 4199 } 4200 4201 if(file_put_contents(e_PLUGIN.$this->pluginName."/".$this->pluginName."_sql.php",$cont)) 4202 { 4203 $info = str_replace('[x]', $this->pluginName."_sql.php", EPL_ADLAN_132); 4204 $mes->addInfo($info,'default',true); 4205 $red = e107::getRedirect(); 4206 $red->redirect(e_REQUEST_URL,true); 4207 // $red->redirect(e_SELF."?mode=create&newplugin=".$this->pluginName."&createFiles=1&step=2",true); 4208 } 4209 else 4210 { 4211 $msg = str_replace('[x]', $this->pluginName."_sql.php", EPL_ADLAN_133)."<br />"; 4212 $msg .= str_replace(array('[x]','[y]'), array($this->pluginName."_sql.php",$cont), EPL_ADLAN_134); 4213 $mes->addWarning($msg); 4214 } 4215 4216 4217 } 4218 } 4219 4220 $existingXml = e_PLUGIN.$this->pluginName."/plugin.xml"; 4221 if(file_exists($existingXml)) 4222 { 4223 $p = e107::getXml()->loadXMLfile($existingXml,true); 4224 4225 // print_a($p); 4226 $defaults = array( 4227 "main-name" => varset($p['@attributes']['name']), 4228 "main-lang" => varset($p['@attributes']['lan']), 4229 "author-name" => varset($p['author']['@attributes']['name']), 4230 "author-url" => varset($p['author']['@attributes']['url']), 4231 "description-description" => varset($p['description']), 4232 "summary-summary" => varset($p['summary'], $p['description']), 4233 "category-category" => varset($p['category']), 4234 "copyright-copyright" => varset($p['copyright']), 4235 "keywords-one" => varset($p['keywords']['word'][0]), 4236 "keywords-two" => varset($p['keywords']['word'][1]), 4237 "keywords-three" => varset($p['keywords']['word'][2]), 4238 ); 4239 4240 unset($p); 4241 4242 } 4243 4244 $text = "<table class='table adminform'>"; 4245 4246 foreach($data as $key=>$val) 4247 { 4248 $text.= "<tr><td>$key</td><td> 4249 <div class='controls'>"; 4250 foreach($val as $type) 4251 { 4252 $nm = $key.'-'.$type; 4253 $name = "xml[$nm]"; 4254 $size = (count($val)==1) ? 'span7 col-md-7' : 'span2 col-md-2'; 4255 $text .= "<div class='{$size}'>".$this->xmlInput($name, $key."-". $type, vartrue($defaults[$nm]))."</div>"; 4256 } 4257 4258 $text .= "</div></td></tr>"; 4259 4260 4261 } 4262 $text .= "</table>"; 4263 4264 return $text; 4265 } 4266 4267 4268 function xmlInput($name, $info, $default='') 4269 { 4270 $frm = e107::getForm(); 4271 list($cat,$type) = explode("-",$info); 4272 4273 $size = 30; // Textbox size. 4274 $help = ''; 4275 $pattern = ""; 4276 $required = false; 4277 4278 switch ($info) 4279 { 4280 4281 case 'main-name': 4282 $help = EPL_ADLAN_135; 4283 $required = true; 4284 $pattern = "[A-Za-z0-9 -]*"; 4285 $xsize = 'medium'; 4286 break; 4287 4288 case 'main-lang': 4289 $help = EPL_ADLAN_136; 4290 $required = false; 4291 $placeholder= " "; 4292 $pattern = "[A-Z0-9_]*"; 4293 $xsize = 'medium'; 4294 break; 4295 4296 case 'main-date': 4297 $help = EPL_ADLAN_137; 4298 $required = true; 4299 $xsize = 'medium'; 4300 break; 4301 4302 case 'main-version': 4303 $default = '1.0'; 4304 $required = true; 4305 $help = EPL_ADLAN_138; 4306 $pattern = "^[\d]{1,2}\.[\d]{1,2}(\.[\d]{1,2})?$"; 4307 $xsize = 'small'; 4308 break; 4309 4310 case 'main-compatibility': 4311 $default = '2.0'; 4312 $required = true; 4313 $help = EPL_ADLAN_139; 4314 $pattern = "^[\d]{1,2}\.[\d]{1,2}$"; 4315 $xsize = 'small'; 4316 break; 4317 4318 case 'author-name': 4319 $default = (vartrue($default)) ? $default : USERNAME; 4320 $required = true; 4321 $help = EPL_ADLAN_140; 4322 $pattern = "[A-Za-z \.0-9]*"; 4323 $xsize = 'medium'; 4324 break; 4325 4326 case 'author-url': 4327 $required = true; 4328 $help = EPL_ADLAN_141; 4329 // $pattern = "https?://.+"; 4330 $xsize = 'medium'; 4331 break; 4332 4333 //case 'main-installRequired': 4334 // return "Installation required: ".$frm->radio_switch($name,'',LAN_YES, LAN_NO); 4335 //break; 4336 4337 case 'summary-summary': 4338 $help = EPL_ADLAN_142."<br />".EPL_ADLAN_143; 4339 $required = true; 4340 $size = 130; 4341 $placeholder= " "; 4342 $pattern = "[A-Za-z -\.0-9]*"; 4343 $xsize = 'block-level'; 4344 break; 4345 4346 case 'keywords-one': 4347 $type = 'keywordDropDown'; 4348 $required = true; 4349 $help = EPL_ADLAN_144; 4350 break; 4351 4352 case 'keywords-three': 4353 case 'keywords-two': 4354 $help = EPL_ADLAN_144."<br />".EPL_ADLAN_143; 4355 $required = true; 4356 $size = 20; 4357 $placeholder= " "; 4358 $pattern = '^[a-z]*$'; 4359 $xsize = 'medium'; 4360 break; 4361 4362 case 'description-description': 4363 $help = EPL_ADLAN_145."<br />".EPL_ADLAN_143; 4364 $required = true; 4365 $size = 100; 4366 $placeholder = " "; 4367 $pattern = "[A-Za-z -\.0-9]*"; 4368 $xsize = 'block-level'; 4369 break; 4370 4371 4372 case 'category-category': 4373 $help = EPL_ADLAN_146; 4374 $required = true; 4375 $size = 20; 4376 break; 4377 4378 default: 4379 4380 break; 4381 } 4382 4383 $req = ($required == true) ? "&required=1" : ""; 4384 $placeholder = (varset($placeholder)) ? $placeholder : $type; 4385 $pat = ($pattern) ? "&pattern=".$pattern : ""; 4386 $sz = ($xsize) ? "&size=".$xsize : ""; 4387 4388 switch ($type) 4389 { 4390 case 'date': 4391 $text = $frm->datepicker($name, time(), 'format=yyyy-mm-dd&return=string'.$req . $sz); 4392 break; 4393 4394 case 'description': 4395 $text = $frm->textarea($name,$default, 3, 100, $req.$sz); // pattern not supported. 4396 break; 4397 4398 4399 case 'category': 4400 $options = array( 4401 'settings' => EPL_ADLAN_147, 4402 'users' => EPL_ADLAN_148, 4403 'content' => EPL_ADLAN_149, 4404 'tools' => EPL_ADLAN_150, 4405 'manage' => EPL_ADLAN_151, 4406 'misc' => EPL_ADLAN_152, 4407 'menu' => EPL_ADLAN_153, 4408 'about' => EPL_ADLAN_154 4409 ); 4410 4411 $text = $frm->select($name, $options, $default,'required=1&class=form-control', true); 4412 break; 4413 4414 case 'keywordDropDown': 4415 4416 $options = array( 4417 4418 'generic', 4419 'admin', 4420 'messaging', 4421 'enhancement', 4422 'date', 4423 'commerce', 4424 'form', 4425 'gaming', 4426 'intranet', 4427 'multimedia', 4428 'information', 4429 'mail', 4430 'search', 4431 'stats', 4432 'files', 4433 'security', 4434 'generic', 4435 'language' 4436 ); 4437 4438 sort($options); 4439 4440 $text = $frm->select($name, $options, $default,'required=1&class=form-control&useValues=1', true); 4441 4442 4443 break; 4444 4445 4446 default: 4447 $text = $frm->text($name, $default, $size, 'placeholder='.$placeholder . $sz. $req. $pat); 4448 break; 4449 } 4450 4451 4452 $text .= ($help) ? "<span class='field-help'>".$help."</span>" : ""; 4453 return $text; 4454 4455 } 4456 4457 function createXml($data) 4458 { 4459 // print_a($_POST); 4460 $ns = e107::getRender(); 4461 $mes = e107::getMessage(); 4462 $tp = e107::getParser(); 4463 4464 foreach($data as $key=>$val) 4465 { 4466 $key = strtoupper(str_replace("-","_",$key)); 4467 $newArray[$key] = $val; 4468 4469 } 4470 4471 $newArray['DESCRIPTION_DESCRIPTION'] = strip_tags($tp->toHTML($newArray['DESCRIPTION_DESCRIPTION'],true)); 4472 4473 $_POST['pluginPrefs'] = $tp->filter($_POST['pluginPrefs']); 4474 4475 foreach($_POST['pluginPrefs'] as $val) 4476 { 4477 if(vartrue($val['index'])) 4478 { 4479 $id = $val['index']; 4480 $plugPref[$id] = $val['value']; 4481 } 4482 } 4483 4484 // print_a($_POST['pluginPrefs']); 4485 4486 if(count($plugPref)) 4487 { 4488 $xmlPref = "<pluginPrefs>\n"; 4489 foreach($plugPref as $k=>$v) 4490 { 4491 $xmlPref .= " <pref name='".$k."'>".$v."</pref>\n"; 4492 } 4493 4494 $xmlPref .= " </pluginPrefs>"; 4495 $newArray['PLUGINPREFS'] = $xmlPref; 4496 } 4497 4498 // print_a($newArray); 4499 // print_a($this); 4500 4501$template = <<<TEMPLATE 4502<?xml version="1.0" encoding="utf-8"?> 4503<e107Plugin name="{MAIN_NAME}" lan="{MAIN_LANG}" version="{MAIN_VERSION}" date="{MAIN_DATE}" compatibility="{MAIN_COMPATIBILITY}" installRequired="true" > 4504 <author name="{AUTHOR_NAME}" url="{AUTHOR_URL}" /> 4505 <summary lan="">{SUMMARY_SUMMARY}</summary> 4506 <description lan="">{DESCRIPTION_DESCRIPTION}</description> 4507 <keywords> 4508 <word>{KEYWORDS_ONE}</word> 4509 <word>{KEYWORDS_TWO}</word> 4510 <word>{KEYWORDS_THREE}</word> 4511 </keywords> 4512 <category>{CATEGORY_CATEGORY}</category> 4513 <copyright>{COPYRIGHT_COPYRIGHT}</copyright> 4514 <adminLinks> 4515 <link url="admin_config.php" description="{ADMINLINKS_DESCRIPTION}" icon="" iconSmall="" icon128="" primary="true" >LAN_CONFIGURE</link> 4516 </adminLinks> 4517 {PLUGINPREFS} 4518</e107Plugin> 4519TEMPLATE; 4520 4521 4522// pluginPrefs 4523 4524 4525 4526 4527// TODO 4528/* 4529 <siteLinks> 4530 <link url="{e_PLUGIN}_blank/_blank.php" perm="everyone">Blank</link> 4531 </siteLinks> 4532 <pluginPrefs> 4533 <pref name="blank_pref_1">1</pref> 4534 <pref name="blank_pref_2">[more...]</pref> 4535 </pluginPrefs> 4536 <userClasses> 4537 <class name="blank_userclass" description="Blank Userclass Description" /> 4538 </userClasses> 4539 <extendedFields> 4540 <field name="custom" type="EUF_TEXTAREA" default="0" active="true" /> 4541 </extendedFields> 4542*/ 4543 4544 4545 $result = e107::getParser()->simpleParse($template, $newArray); 4546 $path = e_PLUGIN.$this->pluginName."/plugin.xml"; 4547 4548 if(file_exists($path) && empty($this->createFiles)) 4549 { 4550 return htmlentities($result); 4551 } 4552 4553 4554 if($this->createFiles == true || !file_exists($path)) 4555 { 4556 if(file_put_contents($path,$result) ) 4557 { 4558 $mes->addSuccess(EPL_ADLAN_155." ".$path); 4559 } 4560 else { 4561 $mes->addError(EPL_ADLAN_156." ".$path); 4562 } 4563 } 4564 return htmlentities($result); 4565 4566 // $ns->tablerender(LAN_CREATED.": plugin.xml", "<pre style='font-size:80%'>".htmlentities($result)."</pre>"); 4567 } 4568 4569 4570 4571 4572 4573 4574 function form($table,$fieldArray) 4575 { 4576 4577 $frm = e107::getForm(); 4578 4579 $modes = array( 4580 "main"=>EPL_ADLAN_157, 4581 "cat"=>EPL_ADLAN_158, 4582 "other1"=>EPL_ADLAN_159, 4583 "other2"=>EPL_ADLAN_160, 4584 "other3"=>EPL_ADLAN_161, 4585 "other4"=>EPL_ADLAN_162, 4586 'exclude'=>EPL_ADLAN_163, 4587 ); 4588 4589 // echo "TABLE COUNT= ".$this->tableCount ; 4590 4591 4592 $this->table = $table."_ui"; 4593 4594 $c=0; 4595 foreach($modes as $id=>$md) 4596 { 4597 $tbl = $this->tableList[$c]; 4598 $defaultMode[$tbl] = $id; 4599 $c++; 4600 } 4601 4602 // print_a($defaultMode); 4603 4604 $text = $frm->hidden($this->table.'[pluginName]', $this->pluginName, 15). 4605 $frm->hidden($this->table.'[table]', $table, 15); 4606 4607 if($this->tableCount > 1) 4608 { 4609 $text .= "<table class='table adminform'>\n"; 4610 $text .= " 4611 <tr> 4612 <td>Mode</td> 4613 <td>".$frm->select($this->table."[mode]",$modes, $defaultMode[$table], 'required=1&class=null', true)."</td> 4614 </tr> 4615 4616 "; 4617 } 4618 else 4619 { 4620 $text .= $frm->hidden($this->table.'[mode]','main'); 4621 } 4622 4623 $text .= "</table>".$this->special('checkboxes'); 4624 4625 $text .= "<table class='table adminlist'> 4626 <thead> 4627 <tr> 4628 <th>".EPL_ADLAN_164."</th> 4629 <th>".EPL_ADLAN_165."</th> 4630 <th>".EPL_ADLAN_166."</th> 4631 <th>".EPL_ADLAN_167."</th> 4632 <th>".EPL_ADLAN_168."</th> 4633 <th class='center'>".EPL_ADLAN_169."</th> 4634 <th class='center'>".EPL_ADLAN_170."</th> 4635 <th class='center'>".EPL_ADLAN_171."</th> 4636 <th class='center' title='".EPL_ADLAN_177."'>".EPL_ADLAN_172."</th> 4637 <th class='center' title='".EPL_ADLAN_178."'>".EPL_ADLAN_173."</th> 4638 <th class='center' title='".EPL_ADLAN_257."'>R/O</th> 4639 4640 <th>".EPL_ADLAN_174."</th> 4641 <th>".EPL_ADLAN_175."</th> 4642 <th>".EPL_ADLAN_176."</th> 4643 </tr> 4644 </thead> 4645 <tbody> 4646 "; 4647 4648 foreach($fieldArray as $name=>$val) 4649 { 4650 list($tmp,$nameDef) = explode("_",$name,2); 4651 // 'faq_question', 'faq_answer', 'faq_parent', 'faq_datestamp' 4652 $text .= "<tr> 4653 <td>".$name."</td> 4654 <td>".$frm->text($this->table."[fields][".$name."][title]", $this->guess($name, $val,'title'),35, 'required=1')."</td> 4655 <td>".$this->fieldType($name, $val)."</td> 4656 <td>".$this->fieldData($name, $val)."</td> 4657 <td>".$frm->text($this->table."[fields][".$name."][width]", $this->guess($name, $val,'width'), 4, 'size=mini')."</td> 4658 <td class='center'>".$frm->checkbox($this->table."[fields][".$name."][batch]", true, $this->guess($name, $val,'batch'))."</td> 4659 <td class='center'>".$frm->checkbox($this->table."[fields][".$name."][filter]", true, $this->guess($name, $val,'filter'))."</td> 4660 <td class='center'>".$frm->checkbox($this->table."[fields][".$name."][inline]", true, $this->guess($name, $val,'inline'))."</td> 4661 <td class='center'>".$frm->checkbox($this->table."[fields][".$name."][validate]", true)."</td> 4662 <td class='center'>".$frm->checkbox($this->table."[fields][".$name."][fieldpref]", true, $this->guess($name, $val,'fieldpref'))."</td> 4663 <td class='center'>".$frm->checkbox($this->table."[fields][".$name."][readonly]", true)."</td> 4664 <td>".$frm->text($this->table."[fields][".$name."][help]",'', 50,'size=medium')."</td> 4665 <td>".$frm->text($this->table."[fields][".$name."][readParms]",'', 60,'size=small')."</td> 4666 <td>".$frm->text($this->table."[fields][".$name."][writeParms]",'', 60,'size=small'). 4667 $frm->hidden($this->table."[fields][".$name."][class]", $this->guess($name, $val,'class')). 4668 $frm->hidden($this->table."[fields][".$name."][thclass]", $this->guess($name, $val,'thclass')). 4669 "</td> 4670 </tr>"; 4671 4672 } 4673 //'width' => '20%', 'thclass' => 'center', 'batch' => TRUE, 'filter'=>TRUE, 'parms' => 'truncate=30', 'validate' => false, 'help' => 'Enter blank URL here', 'error' => 'please, ener valid URL'), 4674 $text .= "</tbody></table>".$this->special('options'); 4675 4676 4677 return $text; 4678 4679 } 4680 4681 // Checkboxes and Options. 4682 function special($name) 4683 { 4684 $frm = e107::getForm(); 4685 $text = ""; 4686 4687 foreach($this->special[$name] as $key=>$val) 4688 { 4689 $text .= $frm->hidden($this->table."[fields][".$name."][".$key."]", $val); 4690 } 4691 4692 return $text; 4693 4694 } 4695 4696 4697 /** 4698 * @param $name 4699 * @param $val 4700 * @return string 4701 */ 4702 function fieldType($name, $val) 4703 { 4704 $type = strtolower($val['type']); 4705 $frm = e107::getForm(); 4706 4707 if(strtolower($val['default']) == "auto_increment") 4708 { 4709 $key = $this->table."[pid]"; 4710 return "Primary Id".$frm->hidden($key, $name ); // 4711 } 4712 4713 switch ($type) 4714 { 4715 case 'date': 4716 case 'datetime': 4717 case 'time': 4718 case 'timestamp': 4719 $array = array( 4720 'text' => EPL_ADLAN_179, 4721 "hidden" => EPL_ADLAN_180, 4722 "method" => EPL_ADLAN_186, 4723 ); 4724 break; 4725 4726 case 'int': 4727 case 'tinyint': 4728 case 'bigint': 4729 case 'smallint': 4730 case 'mediumint': 4731 $array = array( 4732 "boolean" => EPL_ADLAN_181, 4733 "number" => EPL_ADLAN_182, 4734 "dropdown" => EPL_ADLAN_183, 4735 "userclass" => EPL_ADLAN_184, 4736 "datestamp" => LAN_DATE, 4737 "method" => EPL_ADLAN_186, 4738 "hidden" => EPL_ADLAN_187, 4739 "user" => EPL_ADLAN_188, 4740 ); 4741 break; 4742 4743 case 'decimal': 4744 case 'double': 4745 case 'float': 4746 4747 $array = array( 4748 "number" => EPL_ADLAN_182, 4749 "dropdown" => EPL_ADLAN_190, 4750 "method" => EPL_ADLAN_191, 4751 "hidden" => EPL_ADLAN_192, 4752 ); 4753 break; 4754 4755 case 'varchar': 4756 case 'tinytext': 4757 case 'tinyblob': 4758 $array = array( 4759 'text' => EPL_ADLAN_193, 4760 "url" => EPL_ADLAN_194, 4761 "email" => EPL_ADLAN_195, 4762 "ip" => EPL_ADLAN_196, 4763 "number" => EPL_ADLAN_197, 4764 "password" => EPL_ADLAN_198, 4765 "tags" => EPL_ADLAN_199, 4766 4767 "dropdown" => EPL_ADLAN_200, 4768 "userclass" => EPL_ADLAN_201, 4769 "language" => EPL_ADLAN_202, 4770 4771 "icon" => EPL_ADLAN_203, 4772 "image" => EPL_ADLAN_204, 4773 "file" => EPL_ADLAN_205, 4774 "method" => EPL_ADLAN_206, 4775 4776 "hidden" => EPL_ADLAN_207 4777 ); 4778 break; 4779 4780 case 'enum': 4781 $array = array( 4782 "dropdown" => EPL_ADLAN_200, 4783 "tags" => EPL_ADLAN_211, 4784 "method" => EPL_ADLAN_212, 4785 "hidden" => EPL_ADLAN_215 4786 ); 4787 break; 4788 4789 case 'text': 4790 case 'mediumtext': 4791 case 'longtext': 4792 case 'blob': 4793 case 'mediumblob': 4794 case 'longblob': 4795 $array = array( 4796 'textarea' => EPL_ADLAN_208, 4797 'bbarea' => EPL_ADLAN_209, 4798 'text' => EPL_ADLAN_210, 4799 "tags" => EPL_ADLAN_211, 4800 "method" => EPL_ADLAN_212, 4801 "image" => EPL_ADLAN_213, 4802 "images" => EPL_ADLAN_214, 4803 "hidden" => EPL_ADLAN_215 4804 ); 4805 break; 4806 } 4807 4808 // asort($array); 4809 4810 $fname = $this->table."[fields][".$name."][type]"; 4811 return $frm->select($fname, $array, $this->guess($name, $val),'required=1&class=null', true); 4812 4813 } 4814 4815 // Guess Default Field Type based on name of field. 4816 function guess($data, $val=null,$mode = 'type') 4817 { 4818 $tmp = explode("_",$data); 4819 4820 if(count($tmp) == 3) // eg Link_page_title 4821 { 4822 $name = $tmp[2]; 4823 } 4824 elseif(count($tmp) == 2) // Link_description 4825 { 4826 $name = $tmp[1]; 4827 } 4828 elseif(count($tmp) === 1) 4829 { 4830 $name = $data; 4831 } 4832 4833 $ret['title'] = ucfirst($name); 4834 $ret['width'] = 'auto'; 4835 $ret['class'] = 'left'; 4836 $ret['thclass'] = 'left'; 4837 4838 // echo "<br />name=".$name; 4839 switch ($name) 4840 { 4841 4842 case 'id': 4843 $ret['title'] = 'LAN_ID'; 4844 $ret['type'] = 'boolean'; 4845 $ret['batch'] = false; 4846 $ret['filter'] = false; 4847 $ret['inline'] = false; 4848 $ret['width'] = '5%'; 4849 break; 4850 4851 case 'start': 4852 case 'end': 4853 case 'datestamp': 4854 case 'date': 4855 $ret['title'] = 'LAN_DATESTAMP'; 4856 $ret['type'] = 'datestamp'; 4857 $ret['batch'] = false; 4858 $ret['filter'] = true; 4859 $ret['fieldpref'] = true; 4860 $ret['inline'] = false; 4861 break; 4862 4863 case 'prename': 4864 case 'firstname': 4865 case 'lastname': 4866 case 'company': 4867 case 'city': 4868 $ret['title'] = ucfirst($name); 4869 $ret['type'] = 'text'; 4870 $ret['batch'] = false; 4871 $ret['filter'] = false; 4872 $ret['fieldpref'] = true; 4873 $ret['inline'] = true; 4874 break; 4875 4876 4877 case 'name': 4878 case 'title': 4879 case 'subject': 4880 case 'summary': 4881 $ret['title'] = 'LAN_TITLE'; 4882 $ret['type'] = 'text'; 4883 $ret['batch'] = false; 4884 $ret['filter'] = false; 4885 $ret['fieldpref'] = true; 4886 $ret['inline'] = true; 4887 break; 4888 4889 case 'email': 4890 case 'email2': 4891 $ret['title'] = 'LAN_EMAIL'; 4892 $ret['type'] = 'email'; 4893 $ret['batch'] = false; 4894 $ret['filter'] = false; 4895 $ret['fieldpref'] = false; 4896 $ret['inline'] = true; 4897 break; 4898 4899 4900 case 'ip': 4901 $ret['title'] = 'LAN_IP'; 4902 $ret['type'] = 'ip'; 4903 $ret['batch'] = false; 4904 $ret['filter'] = false; 4905 $ret['fieldpref'] = false; 4906 $ret['inline'] = false; 4907 break; 4908 4909 case 'user': 4910 case 'userid': 4911 case 'author': 4912 $ret['title'] = 'LAN_AUTHOR'; 4913 $ret['type'] = 'user'; 4914 $ret['batch'] = false; 4915 $ret['filter'] = false; 4916 $ret['inline'] = false; 4917 break; 4918 4919 case 'thumb': 4920 case 'thumbnail': 4921 case 'image': 4922 $ret['title'] = 'LAN_IMAGE'; 4923 $ret['type'] = 'image'; 4924 $ret['batch'] = false; 4925 $ret['filter'] = false; 4926 $ret['inline'] = false; 4927 break; 4928 4929 case 'total': 4930 case 'order': 4931 case 'limit': 4932 $ret['title'] = 'LAN_ORDER'; 4933 $ret['type'] = 'number'; 4934 $ret['batch'] = false; 4935 $ret['filter'] = false; 4936 $ret['inline'] = false; 4937 break; 4938 4939 case 'code': 4940 case 'zip': 4941 $ret['title'] = ucfirst($name); 4942 $ret['type'] = 'number'; 4943 $ret['batch'] = false; 4944 $ret['filter'] = false; 4945 $ret['inline'] = true; 4946 break; 4947 4948 case 'state': 4949 case 'country': 4950 case 'category': 4951 $ret['title'] = ($name == 'category') ? 'LAN_CATEGORY' : ucfirst($name); 4952 $ret['type'] = 'dropdown'; 4953 $ret['batch'] = true; 4954 $ret['filter'] = true; 4955 $ret['fieldpref'] = true; 4956 $ret['inline'] = true; 4957 break; 4958 4959 case 'type': 4960 $ret['title'] = 'LAN_TYPE'; 4961 $ret['type'] = 'dropdown'; 4962 $ret['batch'] = true; 4963 $ret['filter'] = true; 4964 $ret['fieldpref'] = true; 4965 $ret['inline'] = true; 4966 break; 4967 4968 case 'icon': 4969 case 'button': 4970 $ret['title'] = 'LAN_ICON'; 4971 $ret['type'] = 'icon'; 4972 $ret['batch'] = false; 4973 $ret['filter'] = false; 4974 $ret['inline'] = false; 4975 break; 4976 4977 case 'website': 4978 case 'url': 4979 case 'homepage': 4980 $ret['title'] = 'LAN_URL'; 4981 $ret['type'] = 'url'; 4982 $ret['batch'] = false; 4983 $ret['filter'] = false; 4984 $ret['inline'] = true; 4985 break; 4986 4987 case 'visibility': 4988 case 'class': 4989 $ret['title'] = 'LAN_USERCLASS'; 4990 $ret['type'] = 'userclass'; 4991 $ret['batch'] = true; 4992 $ret['filter'] = true; 4993 $ret['fieldpref'] = true; 4994 $ret['inline'] = true; 4995 break; 4996 4997 case 'notes': 4998 case 'comment': 4999 case 'comments': 5000 case 'address': 5001 case 'description': 5002 $ret['title'] = ($name == 'description') ? 'LAN_DESCRIPTION' : ucfirst($name); 5003 $ret['type'] = ($val['type'] == 'TEXT') ? 'textarea' : 'text'; 5004 $ret['width'] = '40%'; 5005 $ret['inline'] = false; 5006 break; 5007 5008 default: 5009 $ret['type'] = 'boolean'; 5010 $ret['class'] = 'left'; 5011 $ret['batch'] = false; 5012 $ret['filter'] = false; 5013 $ret['thclass'] = 'left'; 5014 $ret['width'] = 'auto'; 5015 $ret['inline'] = false; 5016 break; 5017 } 5018 5019 return vartrue($ret[$mode]); 5020 5021 } 5022 5023 5024 5025 5026 function fieldData($name, $val) 5027 { 5028 $frm = e107::getForm(); 5029 $type = $val['type']; 5030 5031 $strings = array('time','timestamp','datetime','year','tinyblob','blob', 5032 'mediumblob','longblob','tinytext','mediumtext','longtext','text','date'); 5033 5034 5035 $type = strtolower($type); 5036 5037 if(in_array($type,$strings)) 5038 { 5039 $value = 'str'; 5040 } 5041 elseif($type === 'varchar' || $type === 'char') 5042 { 5043 $value = 'safestr'; 5044 } 5045 elseif($type === 'decimal' || $type === 'float') 5046 { 5047 $value = 'float'; 5048 } 5049 else 5050 { 5051 $value = 'int'; 5052 } 5053 5054 5055 $fname = $this->table."[fields][".$name."][data]"; 5056 5057 return $frm->hidden($fname, $value). "<a href='#' class='e-tip' title='{$type}' >".$value."</a>" ; 5058 5059 } 5060 5061 5062 5063 5064// ******************************** CODE GENERATION AREA ************************************************* 5065 5066 function step4() 5067 { 5068 $tp = e107::getParser(); 5069 $pluginTitle = $tp->filter($_POST['xml']['main-name']); 5070 5071 if($_POST['xml']) 5072 { 5073 $_POST['xml'] = $tp->filter($_POST['xml']); 5074 $xmlText = $this->createXml($_POST['xml']); 5075 } 5076 5077 if(!empty($_POST['addons'])) 5078 { 5079 $_POST['addons'] = $tp->filter($_POST['addons']); 5080 $addonResults = $this->createAddons($_POST['addons']); 5081 } 5082 5083 // e107::getDebug()->log($_POST); 5084 5085 unset($_POST['step'],$_POST['xml'], $_POST['addons']); 5086 $thePlugin = $tp->filter($_POST['newplugin'],'file'); 5087 5088$text = "\n 5089// Generated e107 Plugin Admin Area 5090 5091require_once('../../class2.php'); 5092if (!getperms('P')) 5093{ 5094 e107::redirect('admin'); 5095 exit; 5096} 5097 5098// e107::lan('".$thePlugin."',true); 5099 5100 5101class ".$thePlugin."_adminArea extends e_admin_dispatcher 5102{ 5103 5104 protected \$modes = array( 5105 "; 5106 5107 5108 unset($_POST['newplugin'], $_POST['mode']); 5109 5110 foreach($_POST as $table => $vars) // LOOP Through Tables. 5111 { 5112 if(!empty($vars['mode']) && $vars['mode'] != 'exclude') 5113 { 5114 5115 $vars['mode'] = $tp->filter($vars['mode']); 5116 5117 $text .= " 5118 '".$vars['mode']."' => array( 5119 'controller' => '".$table."', 5120 'path' => null, 5121 'ui' => '".str_replace("_ui", "_form_ui", $table)."', 5122 'uipath' => null 5123 ), 5124 5125"; 5126 } 5127 } // END LOOP 5128/* 5129 'cat' => array( 5130 'controller' => 'faq_cat_ui', 5131 'path' => null, 5132 'ui' => 'faq_cat_form_ui', 5133 'uipath' => null 5134 ) 5135 ); 5136*/ 5137 5138$text .= " 5139 ); 5140 5141 5142 protected \$adminMenu = array( 5143"; 5144 foreach($_POST as $table => $vars) // LOOP Through Tables. 5145 { 5146 if(!empty($vars['mode']) && $vars['mode'] != 'exclude' && !empty($vars['table'])) 5147 { 5148 5149 $vars['mode'] = $tp->filter($vars['mode']); 5150$text .= " 5151 '".$vars['mode']."/list' => array('caption'=> LAN_MANAGE, 'perm' => 'P'), 5152 '".$vars['mode']."/create' => array('caption'=> LAN_CREATE, 'perm' => 'P'), 5153"; 5154} 5155 } 5156 5157if($_POST['pluginPrefs'][0]['index']) 5158{ 5159 5160$text .= " 5161 'main/prefs' => array('caption'=> LAN_PREFS, 'perm' => 'P'), 5162"; 5163} 5164$text .= " 5165 // 'main/div0' => array('divider'=> true), 5166 // 'main/custom' => array('caption'=> 'Custom Page', 'perm' => 'P'), 5167 5168 ); 5169 5170 protected \$adminMenuAliases = array( 5171 'main/edit' => 'main/list' 5172 ); 5173 5174 protected \$menuTitle = '".vartrue($pluginTitle, $tp->filter($vars['pluginName']))."'; 5175} 5176 5177 5178 5179"; 5180 // print_a($_POST); 5181 5182 5183 5184 5185 5186 5187 $tableCount = 1; 5188 foreach($_POST as $table => $vars) // LOOP Through Tables. 5189 { 5190 5191 $vars['mode'] = $tp->filter($vars['mode']); 5192 $vars['pluginName'] = $tp->filter($vars['pluginName']); 5193 $vars['table'] = $tp->filter($vars['table']); 5194 $vars['pid'] = $tp->filter($vars['pid']); 5195 5196 if($table == 'pluginPrefs' || $vars['mode'] == 'exclude') 5197 { 5198 continue; 5199 } 5200 5201 5202 $FIELDS = $this->buildAdminUIFields($vars); 5203 $FIELDPREF = array(); 5204 5205 foreach($vars['fields'] as $k=>$v) 5206 { 5207 5208 if(isset($v['fieldpref']) && $k != 'checkboxes' && $k !='options') 5209 { 5210 $FIELDPREF[] = "'".$k."'"; 5211 } 5212 } 5213 5214$text .= 5215" 5216 5217class ".$table." extends e_admin_ui 5218{ 5219 5220 protected \$pluginTitle = '".$pluginTitle."'; 5221 protected \$pluginName = '".$vars['pluginName']."'; 5222 // protected \$eventName = '".$vars['pluginName']."-".$vars['table']."'; // remove comment to enable event triggers in admin. 5223 protected \$table = '".$vars['table']."'; 5224 protected \$pid = '".$vars['pid']."'; 5225 protected \$perPage = 10; 5226 protected \$batchDelete = true; 5227 protected \$batchExport = true; 5228 protected \$batchCopy = true; 5229 5230 // protected \$sortField = 'somefield_order'; 5231 // protected \$sortParent = 'somefield_parent'; 5232 // protected \$treePrefix = 'somefield_title'; 5233 5234 // protected \$tabs = array('Tabl 1','Tab 2'); // Use 'tab'=>0 OR 'tab'=>1 in the \$fields below to enable. 5235 5236 // protected \$listQry = \"SELECT * FROM `#tableName` WHERE field != '' \"; // Example Custom Query. LEFT JOINS allowed. Should be without any Order or Limit. 5237 5238 protected \$listOrder = '".$vars['pid']." DESC'; 5239 5240 protected \$fields = ".$FIELDS."; 5241 5242 protected \$fieldpref = array(".implode(", ",$FIELDPREF)."); 5243 5244"; 5245 5246 5247if($_POST['pluginPrefs'] && ($vars['mode']=='main')) 5248{ 5249 $text .= " 5250 // protected \$preftabs = array('General', 'Other' ); 5251 protected \$prefs = array(\n"; 5252 5253 foreach($_POST['pluginPrefs'] as $k=>$val) 5254 { 5255 if(!empty($val['index'])) 5256 { 5257 $index = $tp->filter($val['index']); 5258 $type = vartrue($val['type'],'text'); 5259 $help = str_replace("'",'', vartrue($val['help'])); 5260 5261 $text .= "\t\t\t'".$index."'\t\t=> array('title'=> '".ucfirst($index)."', 'tab'=>0, 'type'=>'".$tp->filter($type)."', 'data' => 'str', 'help'=>'".$tp->filter($help)."', 'writeParms' => array()),\n"; 5262 } 5263 5264 } 5265 5266 5267 $text .= "\t\t); \n\n"; 5268 5269} 5270 5271 5272 5273$text .= " 5274 public function init() 5275 { 5276 // This code may be removed once plugin development is complete. 5277 if(!e107::isInstalled('".$vars['pluginName']."')) 5278 { 5279 e107::getMessage()->addWarning(\"This plugin is not yet installed. Saving and loading of preference or table data will fail.\"); 5280 } 5281 5282 // Set drop-down values (if any). 5283"; 5284 5285 foreach($vars['fields'] as $k=>$v) 5286 { 5287 if($v['type'] == 'dropdown') 5288 { 5289 $text .= "\t\t\t\$this->fields['".$k."']['writeParms']['optArray'] = array('".$k."_0','".$k."_1', '".$k."_2'); // Example Drop-down array. \n"; 5290 } 5291 } 5292 5293 5294 5295 5296 5297$text .= " 5298 } 5299 5300 5301 // ------- Customize Create -------- 5302 5303 public function beforeCreate(\$new_data,\$old_data) 5304 { 5305 return \$new_data; 5306 } 5307 5308 public function afterCreate(\$new_data, \$old_data, \$id) 5309 { 5310 // do something 5311 } 5312 5313 public function onCreateError(\$new_data, \$old_data) 5314 { 5315 // do something 5316 } 5317 5318 5319 // ------- Customize Update -------- 5320 5321 public function beforeUpdate(\$new_data, \$old_data, \$id) 5322 { 5323 return \$new_data; 5324 } 5325 5326 public function afterUpdate(\$new_data, \$old_data, \$id) 5327 { 5328 // do something 5329 } 5330 5331 public function onUpdateError(\$new_data, \$old_data, \$id) 5332 { 5333 // do something 5334 } 5335 5336 // left-panel help menu area. (replaces e_help.php used in old plugins) 5337 public function renderHelp() 5338 { 5339 \$caption = LAN_HELP; 5340 \$text = 'Some help text'; 5341 5342 return array('caption'=>\$caption,'text'=> \$text); 5343 5344 } 5345 5346 /* 5347 // optional - a custom page. 5348 public function customPage() 5349 { 5350 \$text = 'Hello World!'; 5351 \$otherField = \$this->getController()->getFieldVar('other_field_name'); 5352 return \$text; 5353 5354 } 5355 5356"; 5357 5358 5359$text .= $this->buildAdminUIBatchFilter($vars['fields'], $table, 'batch'); 5360$text .= $this->buildAdminUIBatchFilter($vars['fields'], $table, 'filter'); 5361 5362$text .= " 5363 5364 5365 */ 5366 5367} 5368 5369 5370 5371class ".str_replace("_ui", "_form_ui", $table)." extends e_admin_form_ui 5372{ 5373"; 5374 5375foreach($vars['fields'] as $fld=>$val) 5376{ 5377 if(varset($val['type']) != 'method') 5378 { 5379 continue; 5380 } 5381 5382$text .= " 5383 5384 // Custom Method/Function 5385 function ".$fld."(\$curVal,\$mode) 5386 { 5387 5388 5389 switch(\$mode) 5390 { 5391 case 'read': // List Page 5392 return \$curVal; 5393 break; 5394 5395 case 'write': // Edit Page 5396 return \$this->text('".$fld."',\$curVal, 255, 'size=large'); 5397 break; 5398 5399 case 'filter': 5400 return array('customfilter_1' => 'Custom Filter 1', 'customfilter_2' => 'Custom Filter 2'); 5401 break; 5402 5403 case 'batch': 5404 return array('custombatch_1' => 'Custom Batch 1', 'custombatch_2' => 'Custom Batch 2'); 5405 break; 5406 } 5407 5408 return null; 5409 } 5410"; 5411} 5412 5413 5414foreach($_POST['pluginPrefs'] as $fld=>$val) 5415{ 5416 if(varset($val['type']) !== 'method' || empty($val['index'])) 5417 { 5418 continue; 5419 } 5420 5421 $index = $tp->filter($val['index']); 5422 5423$text .= " 5424 5425 // Custom Method/Function (pref) 5426 function ".$index."(\$curVal,\$mode) 5427 { 5428 5429 5430 switch(\$mode) 5431 { 5432 case 'write': // Edit Page 5433 return \$this->text('".$index."',\$curVal, 255, 'size=large'); 5434 break; 5435 5436 } 5437 5438 return null; 5439 } 5440"; 5441} 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452$text .= " 5453} 5454 5455"; 5456 5457 $tableCount++; 5458 5459 } // End LOOP. 5460 5461$text .= ' 5462new '.$thePlugin.'_adminArea(); 5463 5464require_once(e_ADMIN."auth.php"); 5465e107::getAdminUI()->runPage(); 5466 5467require_once(e_ADMIN."footer.php"); 5468exit; 5469 5470'; 5471 5472// ******************************** END GENERATION AREA ************************************************* 5473 5474 $ns = e107::getRender(); 5475 $mes = e107::getMessage(); 5476 5477 $generatedFile = e_PLUGIN.$thePlugin."/admin_config.php"; 5478 5479 $startPHP = chr(60)."?php"; 5480 $endPHP = ''; 5481 5482 if(!empty($addonResults)) 5483 { 5484 foreach($addonResults as $v) 5485 { 5486 $mes->addSuccess($v); 5487 } 5488 } 5489 5490 if(file_exists($generatedFile) && empty($this->createFiles)) 5491 { 5492 $message = e107::getParser()->lanVars(EPL_ADLAN_256,"admin_config.php"); 5493 $mes->addSuccess($message); 5494 } 5495 else 5496 { 5497 if(file_put_contents($generatedFile, $startPHP .$text . $endPHP)) 5498 { 5499 $message = str_replace("[x]", "<a class='alert-link' href='".$generatedFile."'>".EPL_ADLAN_216."</a>", EPL_ADLAN_217); 5500 $mes->addSuccess($message); 5501 } 5502 else 5503 { 5504 $mes->addError(str_replace('[x]', $generatedFile, EPL_ADLAN_218)); 5505 } 5506 } 5507 5508 // echo $mes->render(); 5509 5510 $ret = "<h3>plugin.xml</h3>"; 5511 $ret .= "<pre style='font-size:80%'>".$xmlText."</pre>"; 5512 $ret .= "<h3>admin_config.php</h3>"; 5513 $ret .= "<pre style='font-size:80%'>".$text."</pre>"; 5514 5515 e107::getPlug()->clearCache(); 5516 5517 return array('caption'=>EPL_ADLAN_253, 'text'=> $ret); 5518 5519 5520 } 5521 5522 5523 /** 5524 * @param array $fields 5525 * @param string $table 5526 * @param string $type 5527 * @return string 5528 */ 5529 private function buildAdminUIBatchFilter($fields, $table, $type='batch') 5530 { 5531 $text = ''; 5532 5533 $typeUpper = ucfirst($type); 5534 5535 $params = ($type === 'batch') ? "\$selected, \$type" : "\$type"; 5536 5537 foreach($fields as $fld=>$val) 5538 { 5539 if(varset($val['type']) !== 'method') 5540 { 5541 continue; 5542 } 5543 5544 5545 5546 $text .= " 5547 5548 // Handle ".$type." options as defined in ".str_replace("_ui", "_form_ui", $table)."::".$fld."; 'handle' + action + field + '".$typeUpper."' 5549 // @important \$fields['".$fld."']['".$type."'] must be true for this method to be detected. 5550 // @param \$selected 5551 // @param \$type 5552 function handleList".eHelper::camelize($fld,true).$typeUpper."(".$params.") 5553 { 5554"; 5555 5556 if($type === 'filter') 5557 { 5558 $text .= " 5559 \$this->listOrder = '".$fld." ASC'; 5560 "; 5561 5562 } 5563 else 5564 { 5565 $text .= " 5566 \$ids = implode(',', \$selected);\n"; 5567 5568 } 5569 5570$text .= " 5571 switch(\$type) 5572 { 5573 case 'custom".$type."_1': 5574"; 5575 5576$text .= ($type === 'batch') ? " // do something" : " // return ' ".$fld." != 'something' '; "; 5577 5578 5579$text .= " 5580 e107::getMessage()->addSuccess('Executed custom".$type."_1'); 5581 break; 5582 5583 case 'custom".$type."_2': 5584"; 5585 5586$text .= ($type === 'batch') ? " // do something" : " // return ' ".$fld." != 'something' '; "; 5587 5588$text .= " 5589 e107::getMessage()->addSuccess('Executed custom".$type."_2'); 5590 break; 5591 5592 } 5593 5594 5595 } 5596"; 5597 } 5598 5599 5600 return $text; 5601 5602 } 5603 5604 5605 /** 5606 * @param array $vars 5607 * @return null|string|string[] 5608 */ 5609 private function buildAdminUIFields($vars) 5610 { 5611 $srch = array( 5612 5613 "\n", 5614 // "),", 5615 " ", 5616 "'forced' => '1'", 5617 "'batch' => '1'", 5618 "'filter' => '1'", 5619 "'batch' => '0'", 5620 "'filter' => '0'", 5621 "'inline' => '1'", 5622 "'validate' => '1'", 5623 "'readonly' => '1'", 5624 // ", 'fieldpref' => '1'", 5625 "'type' => ''", 5626 "'data' => ''", 5627 " array ( )", 5628 ); 5629 5630 $repl = array( 5631 5632 "", 5633 // "),\n\t\t", 5634 " ", 5635 "'forced' => true", 5636 "'batch' => true", 5637 "'filter' => true", 5638 "'batch' => false", 5639 "'filter' => false", 5640 "'inline' => true", 5641 "'validate' => true", 5642 "'readonly' => true", 5643 // "", 5644 "'type' => null", 5645 "'data' => null", 5646 "array ()" 5647 ); 5648 5649 5650 5651 foreach($vars['fields'] as $key=>$val) 5652 { 5653 5654 if(($val['type'] === 'dropdown' || $val['type'] === 'method') && empty($val['filter'])) 5655 { 5656 $vars['fields'][$key]['filter'] = '0'; 5657 } 5658 5659 if(($val['type'] === 'dropdown' || $val['type'] === 'method') && empty($val['batch'])) 5660 { 5661 $vars['fields'][$key]['batch'] = '0'; 5662 } 5663 5664 if($val['type'] == 'image' && empty($val['readParms'])) 5665 { 5666 $vars['fields'][$key]['readParms'] = 'thumb=80x80'; // provide a thumbnail preview by default. 5667 } 5668 5669 if(empty($vars['fields'][$key]['readParms'])) 5670 { 5671 $vars['fields'][$key]['readParms'] = array(); 5672 } 5673 5674 if(empty($vars['fields'][$key]['writeParms'])) 5675 { 5676 $vars['fields'][$key]['writeParms'] = array(); 5677 } 5678 5679 5680 unset($vars['fields'][$key]['fieldpref']); 5681 5682 } 5683 5684 $FIELDS = "array (\n"; 5685 5686 foreach($vars['fields'] as $key=>$val) 5687 { 5688 $FIELDS .= "\t\t\t'".str_pad($key."'",25," ",STR_PAD_RIGHT)."=> ".str_replace($srch,$repl,var_export($val,true)).",\n"; 5689 } 5690 5691 $FIELDS .= "\t\t)"; 5692 5693 // $FIELDS = var_export($vars['fields'],true); 5694 // $FIELDS = str_replace($srch,$repl,var_export($vars['fields'],true)); 5695 $FIELDS = preg_replace("#('([A-Z0-9_]*?LAN[_A-Z0-9]*)')#","$2",$FIELDS); // remove quotations from LANs. 5696 5697 5698 return $FIELDS; 5699 5700 5701 5702 5703 } 5704 5705 5706 5707 5708}