Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-05-26 16:37:27

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Admin-side theming question

Hi,

I’m working on quite an extensive redesign of the admin area of Textpattern (more news soon) but have a question that either the textpattern devs or someone familiar with PHP could answer.

In my new theme’s PHP file, I’ve got the following code to display the head section/navigation…

function header()
  {
    global $txp_user;
    $out[] = '<div id="txp-head" class="clearfix">';
    $out[] = '<p id="mothership"><a href="http://textpattern.com" title="Go to the Textpattern website" target="_blank">Textpattern</a></p>';
    $out[] = '<h1><a href="/" title="Go to your website homepage" target="_blank">'.$GLOBALS["prefs"]["sitename"].'</a></h1>';
    $out[] = '<ul id="txp-nav">';
    foreach ($this->menu as $tab)
    {
      $class = ($tab['active']) ? 'active' : 'inactive';
      $out[] = "<li class='primary {$class}'><a href='?event={$tab['event']}'>{$tab['label']}</a>";
      if (!empty($tab['items']))
      {
        $out[] = '<ul>';
        foreach ($tab['items'] as $item)
        {
          $class = ($item['active']) ? 'active' : 'inactive';
          $out[] = "<li class='secondary {$class}'><a href='?event={$item['event']}'>{$item['label']}</a></li>";
        }
        $out[] = '</ul>';
      }
      $out[] = '</li>';
    }
    if ($txp_user) $out[] = '<li id="txp-logout"><a href="index.php?logout=1" onclick="return verify(\''.gTxt('are_you_sure').'\')">'.gTxt('logout').'</a></li>';
    $out[] = '</ul>';
    $out[] = '</div><div id="txp-body"><div id="txp-content">';
	$out[] = '<p id="messagepane">'.$this->announce($this->message).'</p>';
    return join(n, $out);
  }

Which works fine, but I’ve just discovered that if someone is at the login page it’s still generating the empty <ul> tag for the navigaton menu – which breaks HTML validation. I need a piece of logic that effective says “if logged in display this slab of code…. <ul id=“txp-nav”>blah blah blah</ul>, otherwise don’t”.

Can someone help? I realise this is quite obscure.

Last edited by philwareham (2011-05-26 16:39:19)

Offline

#2 2011-05-26 16:47:20

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

Re: Admin-side theming question

philwareham wrote:

I need a piece of logic that effective says “if logged in display this slab of code….

Try testing the result from is_logged_in() and see if that gets you anywhere.


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 2011-05-26 17:09:30

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Admin-side theming question

Thanks Stef but I don’t know php at all sorry, can you show me how that would fit into my code example above?

Last edited by philwareham (2011-05-26 17:09:44)

Offline

#4 2011-05-26 17:34:28

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

Re: Admin-side theming question

Without testing:

if(is_logged_in()) {
  // Your code that displays the <ul>
} else {
  // Something to display if not logged in.
  // If you don't want to display anything, just omit this } else { portion
}

Last edited by Bloke (2011-05-26 17:34:57)


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 2011-05-26 19:18:53

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Admin-side theming question

Thanks Stef, works perfect!

Here is a sneaky peak of the revamped theme in case you’re interested (still a work in progress mockup)…

Login Page

Write Page

Category Page

Articles Page

…I’ve tried to make it a liquid design as far as possible so it will scale to a minimum 768px wide for iPad (landscape mode). Though I’m still waiting for my iPad2 to be delivered so it’s thoroughly untested on that device. The use of tables in Textpattern’s admin templates restricts how far you can scale and for smaller screens than that I think Oliver Ker’s txpmobile is the way to go.

It will also not be supporting IE7 or below – it won’t necessary be unusable on that browser but since this relies on CSS box-sizing there will be some display glitches on that browser. I may do workarounds for IE7 after initial release if I get enough requests to do so.

Should be ready for beta testing next week if all goes well.

Offline

#6 2011-05-26 20:46:30

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Admin-side theming question

Actually sorry Stef I spoke too soon, it seems using the above code example that after login the nav content does not appear unless you force refresh your browser, Is it cacheing the php once per session and then not reading again unless forced to?

Offline

#7 2011-05-26 21:42:52

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

Re: Admin-side theming question

philwareham wrote:

Is it cacheing the php once per session and then not reading again unless forced to?

Shouldn’t be. Should execute every time. Ummmm, weird. Does Firebug or some other http traffic info give you any clues whether cacheing is involved? I can’t imagine how it could cache the PHP, unless you have some too-darn-clever proxy or cacheing system on your host. You’ev reached the end of my knowledge here. Anyone else?

EDIT: actually, I think I just figured it out. I wonder if is_logged_in() is not being initialised in time, because the cookie isn’t set until after you’ve logged in. Or something.

For info: is_logged_in() checks the TXP cookie to determine logged-in-ness and that probably won’t exist until after you refresh the browser because it sets the cookie partway through the page immediately after logging in — and that occurs after the theme’s header has been rendered to the screen. The only way round it will be to not use is_logged_in(), or use it in conjunction with some other test. Hmmmm.

Last edited by Bloke (2011-05-26 21:46:40)


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

#8 2011-05-27 09:35:57

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Admin-side theming question

I’ve sorted it now I think by using if ($txp_user) as the conditional…

function header()
  {
    global $txp_user;
    $out[] = '<div id="txp-head" class="clearfix">';
    $out[] = '<p id="mothership"><a href="http://textpattern.com" title="Go to the Textpattern website" target="_blank">Textpattern</a></p>';
    $out[] = '<h1><a href="/" title="Go to your website homepage" target="_blank">'.$GLOBALS["prefs"]["sitename"].'</a></h1>';
    if ($txp_user)
    {
      $out[] = '<ul id="txp-nav">';
      foreach ($this->menu as $tab)
      {
        $class = ($tab['active']) ? 'active' : 'inactive';
        $out[] = "<li class='primary {$class}'><a href='?event={$tab['event']}'>{$tab['label']}</a>";
        if (!empty($tab['items']))
        {
          $out[] = '<ul>';
          foreach ($tab['items'] as $item)
          {
            $class = ($item['active']) ? 'active' : 'inactive';
            $out[] = "<li class='secondary {$class}'><a href='?event={$item['event']}'>{$item['label']}</a></li>";
          }
          $out[] = '</ul>';
        }
        $out[] = '</li>';
      }
      $out[] = '<li id="txp-logout"><a href="index.php?logout=1" onclick="return verify(\''.gTxt('are_you_sure').'\')">'.gTxt('logout').'</a></li>';
      $out[] = '</ul>';
    }
    $out[] = '</div>';
    $out[] = '<div id="txp-body">';
    $out[] = '<p id="messagepane">'.$this->announce($this->message).'</p>';
    $out[] = '<div id="txp-content">';
    return join(n, $out);
  }

Seems to work as intended. Of course the login page wll still not validate because of the known footer problem, but at least it’s slightly less broken now (not sure why that patch was not included into v4.4 IMHO, seems like a no-brainer to me).

Offline

Board footer

Powered by FluxBB