Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-04-09 10:20:03

rkchlvrs
New Member
Registered: 2010-04-09
Posts: 6
Website

Admin theme creation - can you pull out specific menu items?

Hey,

To begin with, since this is my first post here: hi, nice to meet you, you all look swell. How was your Easter?

The Intro (feel free to skip)
I recently moved from Wordpress to Textpattern, and haven’t regretted it at all. However, whilst considering what platform to move to I came across Habari, and their lovely admin interface. Since I’m a serial procrastinator and have some assignments due soon it seemed a good time to have a crack at porting some of Habari’s features (namely, the dashboard style bar at the top and the keyboard navigation) to Textpattern. It looks like this so far.

The Question
Currently I’m just mucking around with editing Remora’s header() function but I’d like to do more. My question is: is there a way of pulling specific menu items out? I’d quite like to be able to stick some of them (e.g., ‘Write’, ‘Articles’, ‘Comments’ etc.) in the main dropdown, rather than hidden in a submenu. As much as anything once I get keyboard navigation up and running that would reduce keystrokes.

Ta,

Rik

Offline

#2 2010-04-09 10:54:07

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,942
Website GitHub

Re: Admin theme creation - can you pull out specific menu items?

Hi Rik, welcome aboard :-)

Nice work on porting the dashboard stuff over. I’ve had a go at some dashboardy things in the past — with the recent addition of the ‘default screen’, combined with the pluggable_ui() interface and the admin themes it makes it very easy to write something pretty nifty for your users. And it’s going to get better in the next version if I have my way.

is there a way of pulling specific menu items out?

The answer is yes. Depends how good your PHP is!

Off the cuff, you could build your menu structure into a couple of arrays: one is the main menu and the other is your ‘special direct access’ menu. Perhaps like this (untested):

$out[] = '<div id="masthead"><ul id="nav">';
$spout[] = '<ul id="specials">';

foreach ($this->menu as $tab)
{
	$class = ($tab['active']) ? 'tabup active' : 'tabdown inactive';
	$out[] = "<li class='primary {$class}'><a href='?event={$tab['event']}'>{$tab['label']}</a>";
	if (!empty($tab['items']))
	{
		$ctr = 1;
		$total = count($tab['items']);
		foreach ($tab['items'] as $item)
		{
			$class = ($item['active']) ? 'tabup active' : 'tabdown2 inactive';
			if (in_list($item['event'], 'comments, article, list')) {
				$spout[] = "<li {$class}'><a href='?event={$item['event']}'>{$item['label']}</a></li>";
			} else {
				if ($ctr == 1) {
					$out[] = '<ul>';
				}
				$out[] = "<li class='secondary {$class}'><a href='?event={$item['event']}'>{$item['label']}</a></li>";
				if ($ctr == $total) {
					$out[] = '</ul>';
				}
			}
			$ctr++;
		}
	}
	$out[] = '</li>';
	$spout[] = '</ul>';
}

*shrug* Something along those lines should yank out the items in the given list (TXP’s in_list() function is pretty handy!) and treat them separately. Once it’s built up your two arrays you can output them separately afterwards. Without knowing your exact markup requirements or what you’re trying to achieve in terms of visuals, I can’t really help much more than that at the moment. Hope that helps anyway.

Last edited by Bloke (2010-04-09 10:54:33)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2010-04-09 12:28:07

rkchlvrs
New Member
Registered: 2010-04-09
Posts: 6
Website

Re: Admin theme creation - can you pull out specific menu items?

Wow, thanks Stef! My PHP is a little rusty so it might take me a while to work through all of that. I’ll report back when I’ve made some progress (or, more likely, when I get confused).

Very briefly, what is the ‘default screen’ and how does pluggable_ui() work?

Offline

#4 2010-04-09 12:37:58

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,942
Website GitHub

Re: Admin theme creation - can you pull out specific menu items?

rkchlvrs wrote:

Very briefly, what is the ‘default screen’

From 4.2.0+ if you go to Admin->Advanced prefs you can set a tab to be visible to all users by default when they first log in (assuming they have privileges to see it of course). If you write a dashboard plugin on its own tab, it’s an ideal location to direct users to so they can go to a familiar place and you can use that as a springboard to the rest of the admin side. Works very well; works even better in the SVN version (there’s a slight bug in 4.2.0 that means you sometimes see an unstyled admin side on first login).

and how does pluggable_ui() work?

It’s a series of callbacks that allow you to add to or replace certain UI widgets programmatically. Prior to 4.2.0 you had to use one of the other callbacks and either hunt ‘n’ replace for the text you wanted to change before it was output or use jQuery to intercept stuff (which had UI implications as the screen drew.

Now you can target selected widgets directly and alter them/turn them off with a few lines of PHP before anybody is any wiser. I’ve documented the entire list of callbacks on Textbook as reference material.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2010-04-09 13:28:22

rkchlvrs
New Member
Registered: 2010-04-09
Posts: 6
Website

Re: Admin theme creation - can you pull out specific menu items?

Sweet, thanks. Switching off some of the widgets sounds interesting, I’ll look into that. Habari has a rather nice admin side landing page, which could be imitated using a default screen then. Good stuff.

Offline

#6 2010-04-09 17:26:53

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: Admin theme creation - can you pull out specific menu items?

Might be worth checking out jmd_dashboard, although it doesn’t use the newer admin themeing stuff it does do some of the things the Habari Dashboard does like latest entries.


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#7 2010-04-12 21:01:52

rkchlvrs
New Member
Registered: 2010-04-09
Posts: 6
Website

Re: Admin theme creation - can you pull out specific menu items?

@MattD – Thanks Matt, I’ll have a look at that.

@Bloke – Gave up on rearranging the menu items. My PHP isn’t very good, plus the idea of moving things out of ‘Content’ etc felt a bit wrong :p

So, an update: this is what it looks like now. Basic keyboard navigation is there (i.e., I can call the dashboard menu and navigate through it with the arrow keys) but there’s still a way to go. I’ve hit a bit of a roadblock though, I need to be able to assign individual letters to each of the main menus. That is:

Content = C
Presentation = P
Admin = A
Extensions = E

What I’ve got so far is:

foreach ($this->menu as $tab)
{
	$class = ($tab['active']) ? 'selected' : '';
	$out[] = "<li id='{$tab['label']}' class='submenu {$class}'><a class='top' href='?event={$tab['event']}'>{$tab['label']}<span class='hotkey enabled'>OUTPUT OF SPECIFIC LETTER</span></a>";
	if (!empty($tab['items']))
	{
		$name = ($tab['label']);
		$count = 1;				
		$out[] = '<ul class="submenu">';
		foreach ($tab['items'] as $item)
		{
			$class = ($item['active']) ? 'selected' : '';
			$out[] = "<li id='{$name}-{$count}' class='{$class}'><a href='?event={$item['event']}'>{$item['label']}<span class='hotkey enabled'>{$count}</span></a></li>";
			$count++;
		}
		$out[] = '</ul>';
	}
	$out[] = '</li>';			
}

Submenu navigation is sorted with $count but how would I go about assigning each of the main menus a letter, and then call them specifically?

Thanks very much in advance!

Offline

#8 2010-04-12 21:43:32

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,942
Website GitHub

Re: Admin theme creation - can you pull out specific menu items?

rkchlvrs wrote:

how would I go about assigning each of the main menus a letter, and then call them specifically?

Easiest way I can think of (without much thought I hasten to add, so there’s probably a better way) is to pre-populate an array higher up in the code as a sort of lookup table:

$accessKeys = array(
   'C' => 'content',
   'P' => 'presentation',
   'A' => 'admin',
   'E' => 'extensions',
   );

Then all you need to do to find an access key for the current top-level tab inside the loop is:

array_search($tab['event'], $accessKeys);

According to the PHP docs that’ll return the array key (i.e. the access key letter) for the given value — in this case the tab’s event name. Might need a bit of tweaking as that’s untested, but I think it’ll get you somewhere near where you want to be.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB