Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Include loadtab.php in Core
#1
It would be nice, if the loadtab.php (see e.g. in I18N Gallery plugin) could be installed in the admin directory by default.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#2
whats the purpose of it?
- Chris
Thanks for using GetSimple! - Download

Please do not email me directly for help regarding GetSimple. Please post all your questions/problems in the forum!
Reply
#3
It provides the template for displaying the pages on a tab created with the nav-tab action.
Basically a load.php, but with actions pluginname-sidebar and pluginname-sidebar-extra and optionally calling a function based on the item parameter instead of the main function specified on register_plugin.

Currently plugins (e.g. GSGallery, I18N Gallery) copy this file to the admin folder, if it does not exist.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#4
pardon my ignorance, but is nav-tab useless without it?
- Chris
Thanks for using GetSimple! - Download

Please do not email me directly for help regarding GetSimple. Please post all your questions/problems in the forum!
Reply
#5
ccagle8 Wrote:pardon my ignorance, but is nav-tab useless without it?

You could link the navigation tab to a php file in your plugins/your-plugin folder, but
  • you would need about the same code (include common.php, header/footer templates, cookie check, etc.)
  • you might get problems, if common.php or templates depend on being called from the admin folder?
  • you must make sure to ALLOW this file in .htaccess
  • it only works with sitewide cookies
  • it's not nice, if the URL suddenly is /plugins/your-plugin/... instead of /admin/...

There are some other problems with side menus and nav tabs:
  • Only one side menu item can be generated using createSideMenu
  • createNavTab is rather useless as it won't highlight the tab
  • a plugin can't (easily) have side menu items on multiple tabs (minor problem in my opinion)

Instead of loadtab.php some small changes will make tabs and side menus (better) usable - see next post.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#6
OK, here are the suggested changes:

plugin_functions.php / createSideMenu:
replace it with the following (compatible) code:
Code:
function createSideMenu($id, $txt, $action=null, $always=true){
  $current = false;
  if (isset($_GET['id']) && $_GET['id'] == $id && (!$action || isset($_GET[$action]))) {
    $current = true;
  }
  if ($always || $current) {
    echo '<li><a href="load.php?id='.$id.($action ? '&amp;'.$action : '').'" '.($current ? 'class="current"' : '').' >'.$txt.'</a></li>';
  }
}
$action will add an additional request parameter thus allowing multiple side menu items per plugin.
Setting $always to false will only show the menu item, if the page is active ($action should be non-empty)

plugin_functions.php / createNavTab:
Not compatible, but I doubt that anybody uses it.
Code:
function createNavTab($tabname, $id, $txt, $action=null) {
  global $plugin_info;
  $current = false;
  if (basename($_SERVER['PHP_SELF']) == 'load.php') {
    $plugin_id = @$_GET['id'];
    if ($plugin_info[$plugin_id]['page_type'] == $tabname) $current = true;
  }
  echo '<li><a href="load.php?id='.$id.($action ? '&amp;'.$action : '').'" '.($current ? 'class="current"' : '').' >'.$txt.'</a></li>';
}
$tabname is the name of the tab (e.g. "special"), the action for creating side menu items is the name of the tab plus "-sidebar" (e.g. "special-sidebar"), analog to the standard tabs (e.g. "pages-sidebar").
Other parameters like for createSideMenu.

To highlight the tab, add the following to the CSS (or rather add the selector to the already existing rule for highlighting):
Code:
<style type="text/css">
  #load .wrapper .nav li a.current {
    -moz-box-shadow: 2px -2px 2px rgba(0, 0, 0, 0.1);
    background: -moz-linear-gradient(center top , #FFFFFF 3%, #F6F6F6 100%) repeat scroll 0 0 transparent;
    color: #182227;
    font-weight: bold !important;
    text-shadow: 1px 1px 0 #FFFFFF;
  }
</style>

load.php:
Replace the <div id="sidebar"> ... </div> code with:
Code:
<div id="sidebar" >
    <?php
      $res = (@include('template/sidebar-'.$plugin_info[$plugin_id]['page_type'].'.php'));
      if (!$res) {
    ?>
      <ul class="snav">
        <?php exec_action($plugin_info[$plugin_id]['page_type']."-sidebar"); ?>
      </ul>
    <?php
      }
    ?>
  </div>
If the template to include is not found (as is the case for additional tabs), only the tabname-sidebar action is executed.

Attached:
  • loadext.php - the copied and patched load.php for my test
  • i18n_specialpages.php - a test of the changes, using functions createSideMenuExt, createNavTabExt, adding the css rule in a header action and calling loadext.php instead of load.php.
My test plugin also includes a condition to determine which tab should be active before register_plugin.
It creates side menu items in Pages and Plugins and a new tab.

I hope you can include this in 3.1!

Martin
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#7
@ccagle8: will this be included in 3.1?
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#8
it's already in the SVN!
- Chris
Thanks for using GetSimple! - Download

Please do not email me directly for help regarding GetSimple. Please post all your questions/problems in the forum!
Reply
#9
ccagle8 Wrote:it's already in the SVN!
Great. Thanks!
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#10
Checked this topic because http://get-simple.info/forum/topic/2852/...oadtabphp/

ccagle8 Wrote:it's already in the SVN!

I did a checkout just now, but I can't find the code above in the SVN?
Reply
#11
Hi leenm,

mclvek suggested we either add loadtab.php or make the function changes to plugin_function.php and load.php

we have added loadtab.php to the SVN.

Mike.
My Github Repos: Github
Website: DigiMute
Reply
#12
n00dles101 Wrote:Hi leenm,
we have added loadtab.php to the SVN.
That's even better, but how do I create a sidemenu for my plugin then? The createSideMenu function isn't sufficient:
Code:
unction createSideMenu($id,$txt){
    $class=null;
  if (isset($_GET['id']) && $_GET['id'] == $id) {
        $class='class="current"';
    }
    echo '<li><a href="load.php?id='.$id.'" '.$class.' >'.$txt.'</a></li>';
}
It always uses load.php. Also my point in http://get-simple.info/forum/topic/2852/...oadtabphp/ still stands then.

I'd like to have this function working properly. I'm willing to propose improvements, but not if this is working already of course. Maybe I'm not understanding how to use the loadtab functionality with a sidemenu properly?
Reply
#13
n00dles101 Wrote:Hi leenm,

mclvek suggested we either add loadtab.php or make the function changes to plugin_function.php and load.php

we have added loadtab.php to the SVN.

Mike.

Sorry to hear that - I understood that the changes were added, as they provide a much cleaner and better way and allow the plugin developer to easily put his menu items either on an existing tab or a new one.
With just the loadtab.php he has to duplicate the actual code for the adding of menu items in each plugin.

I definitely encourage you to use the other way in the GetSimple core!
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#14
Nothing wrong with including loadtab, provided the following changes will be added also:

in loadtab.php (line 25), add:
Code:
# Set default action
if(!isset($_GET['item'])) $_GET['item'] = $plugin_info[$plugin_id]['load_data'];
(this is even better as my solution here: http://get-simple.info/forum/topic/2852/...oadtabphp/)

change function createSideMenu() to
Code:
function createSideMenu($id,$txt,$pluginid = null){
    $class=null;
    if (isset($_GET['id']) && $_GET['id'] == $id) {
        $class='class="current"';
    } else if ($pluginid && $_GET['item'] == $id) {
        $class='class="current"';
    }
    $url = is_null($pluginid) ? 'load.php?id='.$id : 'loadtab.php?id='.$pluginid.'&item='.$id;
    
    echo '<li><a href="'.$url.'" '.$class.' >'.$txt.'</a></li>';
}
(explanation of extra param $pluginid: When creating a sidemenu for a plugin that is displayed as a new tab with loadtab.php, send the $plugin_id to createSideMenu function.)

Only thing left to fix is styling for the active loadtab tab.
Reply
#15
ok, will have a look at the code and add it to the SVN.
Was under the impression it was one or the other.

sorry for the confusion...

8)
My Github Repos: Github
Website: DigiMute
Reply
#16
n00dles101 Wrote:ok, will have a look at the code and add it to the SVN.
Was under the impression it was one or the other.

sorry for the confusion...

8)

Adding loadtab.php was the first approach, but it has a lot of deficiencies, like still needing additional functions for actually adding menu items in the tab.

With the changes described here
  • you can add multiple side menu items for one plugin (e.g. configure and edit) with the standard createSideMenu
  • you can use the same createSideMenu also for items on a new tab
  • you can have menu items that are only visible if the action is active (like "Edit Page" menu item)
  • you don't need loadtab.php by adding a bit of code to load.php

So above changes are the far better solution than adding loadtab.php.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#17
I've updated the latest SVN version with all of these changes.

Any chance you could do a quick wiki on how plugin writers should use it ??
My Github Repos: Github
Website: DigiMute
Reply
#18
n00dles101 Wrote:Any chance you could do a quick wiki on how plugin writers should use it ??

Finally done!
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#19
Why is loadtab.php still included (in SVN)? That file isn't needed with mvlcek's changes, right?
Reply
#20
@mvlcek, thanks for updating the wiki.

I've moved it into its own page for editing;

http://get-simple.info/wiki/plugins:tabs_menus
My Github Repos: Github
Website: DigiMute
Reply




Users browsing this thread: 1 Guest(s)