Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Using wildcard to target sNews admin ?actionblabla SEF?  (Read 272 times)

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Using wildcard to target sNews admin ?actionblabla SEF?
« on: January 28, 2013, 03:13:22 PM »

Okay, so the title needs some explaining. I ran into this issue a little while ago (and now it's starting to bug me...) when I was asked to create a separate layout for pages and articles which should also work in the admin area. So I did the following in index.php:

Code: [Select]
<!-- PAGES LAYOUT -->
<?php if($_POS == || in_array($categorySEF,explode(',',l('cat_listSEF')))) { ?>
<section id="pages" role="main">
    <?php center(); ?>
</section>
<?php } else { ?>
<!-- ARTICLE LAYOUT -->
<section id="content" role="main">
    <div class="post">
        <?php center(); ?>
    </div>
</section>
<!-- END CONTENT CONTAINER, BEGIN SIDEBAR -->
<aside id="sidebar2">
    blablabla
</aside>

This works as it should in both public and admin views, BUT it does not work in admin when the page url is something like http://domain.tld/?action=admin_article&id=1 and that's something I would like to fix.

The best solution would be to able to use some ?action=* construction in cat_listSEF, but, see, that's where I start to get stuck. Been reading up on wildcards in PHP, however I can't really find a suitable example that I could apply to this scenario.

Suggestions?
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Using wildcard to target sNews admin ?actionblabla SEF?
« Reply #1 on: January 28, 2013, 04:50:25 PM »

The solution I've stuck with for use of multiple templates (or multiple themes based on one template) in 1.6 and 1.7.1 projects has been the Switcherizer2 approach shared by Bob Baker back in 1.6 times.

Essentially, Bob's approach uses conditional filters in the root index.php file to determine which template gets displayed. Have you taken a look at Bob's Switcherizer2 approach? It may provide some useful clues.
« Last Edit: January 29, 2013, 02:49:31 AM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: Using wildcard to target sNews admin ?actionblabla SEF?
« Reply #2 on: January 28, 2013, 06:09:18 PM »

No offense but Bob's switcher has nothing to do with what I'm after.
Essentially it's a 3-column layout which becomes a 2-column layout on public pages (both when logged in as admin and not) and *all* admin pages (including the ?action=admin&blabla pages). Only right now it's 2-column on all admin pages *except* the ?action=admin&blabla pages where it becomes 3-column, which is what I'm trying to fix.
Logged

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: Using wildcard to target sNews admin ?actionblabla SEF?
« Reply #3 on: January 28, 2013, 11:48:24 PM »

Fred, I could have sworn, I helped you out with this at one point. You may want a modified version of the get_uri (and helper) function from here:
http://snewscms.com/forum/index.php/topic,8671.msg67561.html#msg67561 or
http://snewscms.com/forum/index.php/topic,8974.msg64620.html#msg64620 - Pt 3 - Pt4 & 5 shows example usage

Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: Using wildcard to target sNews admin ?actionblabla SEF?
« Reply #4 on: January 29, 2013, 12:11:14 AM »

Hey Jason. Yeah, you did, and it was the first thing I tried for this scenario, and it produced the same result as my current version. Always has. I'll look at the get_uri use examples. Thanks.
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Using wildcard to target sNews admin ?actionblabla SEF?
« Reply #5 on: January 29, 2013, 02:52:41 AM »

No offense but Bob's switcher has nothing to do with what I'm after.
Essentially it's a 3-column layout which becomes a 2-column layout on public pages (both when logged in as admin and not) and *all* admin pages (including the ?action=admin&blabla pages). Only right now it's 2-column on all admin pages *except* the ?action=admin&blabla pages where it becomes 3-column, which is what I'm trying to fix.

No offense taken. When is the 3-column layout used?
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: Using wildcard to target sNews admin ?actionblabla SEF?
« Reply #6 on: January 29, 2013, 10:01:22 AM »

Quote from: Keyrocks
When is the 3-column layout used?

On articles and categories (including Home page), both when logged in as admin and not. The "default" layout has a left hand sidebar and a main container for center(). Then there's (currently) an if-conditional that checks if the page viewed is a Page - both man-made and system-made. If it isn't, e.g the page viewed is an Article or Home, the layout gets a second sidebar.

The problem is that system pages, e.g domain.tld/?action=admin&id=X&etc, gets the second sidebar like articles and Pages. This they shouldn't. Jason's get_uri thing is supposed to solve that... (I haven't been able to get it to work yet, but I'm obviously missing something.)
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: Using wildcard to target sNews admin ?actionblabla SEF?
« Reply #7 on: January 29, 2013, 10:45:48 AM »

Wee-hoo! Got it to work! (Exclamations due to me marvelling at my own brilliance... [sarcasm])
And it works without the use of get_uri too, which simplifies/lightens things.
The key? This:

Quote
<?php if(in_array($categorySEF,explode(',',l('cat_listSEF'))) || in_array($_GET['action'],explode(',',l('cat_listSEF')))) { ?>
<!-- do special case code here -->
<?php } else { ?>
<!-- do normal case code here -->
<?php } ?>

As noted, get_uri isn't needed for this solution but (speaking to Jason here) I wouldn't have understood that without first having tried to implement the get_uri solution, so 1+ karma for that.

One step closer... ;)
Logged

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: Using wildcard to target sNews admin ?actionblabla SEF?
« Reply #8 on: January 29, 2013, 12:38:42 PM »

Awesome work Fred. 

The solution I noted would lead to functions like:
is_admin_page();
is_home_page();
is_page(); etc, etc.

so you could do:
if( is_admin_page() ) {
 // admin code
}
Logged

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: Using wildcard to target sNews admin ?actionblabla SEF?
« Reply #9 on: January 30, 2013, 10:36:46 AM »

Fred, here is the solution I was noting:

Code: [Select]
function is_type( $var ) {
static $arr;
if (!$arr) {
global $url, $categorySEF, $_catID, $_XNAME, $_ID, $_POS;
$arr = array();

// Prep for admin pages
$catList = explode(',', l('cat_listSEF'));
// Add missing admin pages
$catList[] = 'process';
$catList[] = 'editcomment';


if ( $url || isset($_GET['action']) ) {

// Article
if ( $url[2] && $_ID && $_POS == 1 ) {
$arr['article'] = true;
unset( $url[1], $url[0] );

} elseif ( $url[1] && $_ID && $_POS == 1 ) {
$arr['article'] = true;
unset( $url[0] );
}

// Subcategory
if( $url[1] && $_catID && $_XNAME ) {
$arr['subcategory'] = true;
}

// Category
if( $url[0] && $_catID ) {
$arr['category'] = true;
}

// Page
if( $url[0] && $_ID && $_POS == 3 ) {
$arr['page'] = true;
}
if( in_array($url[0], array($catList[0], $catList[1], $catList[2])) ) {
$arr['page'] = true;
}

// Admin
unset( $catList[0], $catList[1], $catList[2] );
if( in_array($categorySEF, $catList) || in_array($_GET['action'], $catList) ) {
$arr['admin'] = true;
}

// 404
if ($categorySEF == '404') {
$arr['404'] = true;
}
}
// Home Page or Page set as Home
if ( empty($arr) ) {
$arr['home'] = true;
}
}
if( isset($arr[$var]) ) {
return true;
}
}

Then some wrapper functions:
Code: [Select]
function is_home() {
return is_type('home');
}
function is_page() {
return is_type('page');
}
function is_category() {
return is_type('category');
}
function is_article() {
return is_type('article');
}
function is_admin() {
return is_type('admin');
}
function is_404() {
return is_type('404');
}

Test code:
Code: [Select]
if( is_home() ) {
echo 'Welcome!';
}
if( is_admin() ) {
echo 'Welcome Admin!';
}
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: Using wildcard to target sNews admin ?actionblabla SEF?
« Reply #10 on: January 30, 2013, 08:53:07 PM »

Thanks Jason, that's a neat solution. Very versatile.
Logged