Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Pages: 1 [2] 3

Author Topic: [MOD] The Body ID, for sNews 1.7  (Read 6750 times)

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [MOD] The Body ID, for sNews 1.7
« Reply #15 on: November 17, 2009, 03:27:16 PM »

After having applied the correction,
my core sings:

Quote
Nobody knows the trouble I've seen,
nobody knows,
but Jesus...
and:
Quote
I am just a gigolo
I ain't got nobody...

to tell me the body has vanished.

Yeah! No body.
I prayed the Lord. I called Jesus too.
I went down to have a coffee, a Cognac and a cigar.
Then I called the police: hey officer! I've lost my body.
And now I'm hearing the sirens from the psychiatric hospital...
Sad day.

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: [MOD] The Body ID, for sNews 1.7
« Reply #16 on: November 17, 2009, 03:39:21 PM »

I went down to have a coffee, a Cognac and a cigar... Then I called the police: hey officer! I've lost my body... And now I'm hearing the sirens from the psychiatric hospital... Sad day.

A bod-acious problem indeed. Time for a new body?  :P
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: [MOD] The Body ID, for sNews 1.7
« Reply #17 on: November 17, 2009, 04:58:33 PM »

bah non..., my body worked just fine with the correction... ???
I'll take another look at it. Maybe I had a visit from our friend mr. Zeimer as well... Don't recall seeing him though.... 8)

Oh, wait, I know. Same mistake as equilni did the first time around maybe?
Quote
Usage:
Code: [Select]
<?php bodyID(); ?>

That should of course have been (and I'm blushing with shame here, you can see that, right?)
Quote
<?php echo bodyID(); ?>
Is that what might be the problem?
Anyway, I'll look at the code again.
« Last Edit: November 17, 2009, 05:03:49 PM by Fred K (agentsmith) »
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: [MOD] The Body ID, for sNews 1.7
« Reply #18 on: November 18, 2009, 12:07:53 AM »

I don't get it... this code works fine for me -- checked in Safari, Firefox and Opera, no problems reported. (I've moved the conditionals line just to see if it did anything, but essentially it's the same code as before.)

Code: [Select]
<?php
function bodyID() {
global $categorySEF;
$conditional '<!--[if IE 6]>ie6<![endif]--><!--[if IE 7]>ie7<![endif]--><!--[if IE 8]>ie8<![endif]-->';
$catList explode','l'cat_listSEF' ) );
// sNews does not differentiate between admin pages and public pages 
// A default install would have the first 4 as 'archive,contact,sitemap,login'
unset( $catList[0], $catList[1], $catList[2], $catList[3] );
if ( $categorySEF || ( _ADMIN && $_GET['action'] ) ) {
if ( 
in_array$_GET['action'], $catList ) ||
in_array$categorySEF$catList )  
) {
$bodyID 'administration';
} else $bodyID $categorySEF;
} else $bodyID s('home_sef');
return '<body id="'.$bodyID.'" class="'.$conditional.'">';
}
?>

To use in index.php, do <?php echo bodyID(); ?>

It doesn't work for you, Philippe?
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [MOD] The Body ID, for sNews 1.7
« Reply #19 on: November 18, 2009, 08:22:04 AM »


To use in index.php, do <?php echo bodyID(); ?>

It doesn't work for you, Philippe?
Yes! It works. We gonna make it Fred.

What do you get on your side?
This is how my new body looks (printed from IE8):

a/
Code: [Select]
   $conditional = '<!--[if IE 6]>ie6<![endif]--><!--[if IE 7]>ie7<![endif]--><!--[if IE 8]>ie8<![endif]-->';
   return '<body id="'.$bodyID.'" class="'.$conditional.'">';
Quote
<body id="home" class="<!--[if IE 6]>ie6<![endif]--><!--[if IE 7]>ie7<![endif]--><!--[if IE 8]>ie8<![endif]-->">

b/
Code: [Select]
   $conditional = '<!--[if IE 6]>class="ie6"<![endif]--><!--[if IE 7]>class="ie7"<![endif]--><!--[if IE 8]>class="ie7"<![endif]-->';
   return '<body id="'.$bodyID.'" '.$conditional.'>';
Quote
<body id="home" <!--[if IE 6]>class="ie6"<![endif]--><!--[if IE 7]>class="ie7"<![endif]--><!--[if IE 8]>class="ie8"<![endif]-->">

Solution b/ should work, am I wrong? Neverless, IE8 doesn't apply this comment.  ???
« Last Edit: November 18, 2009, 10:36:54 AM by Sven »
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: [MOD] The Body ID, for sNews 1.7
« Reply #20 on: November 18, 2009, 11:08:12 AM »

yeah, solution b/ might work better although I got some strange result from it in Firefox (but not Safari) while solution a/ worked fine in both, but anyway I don't think that I'll be using this solution at all. Mainly because my ie sheet is usually very small so I think that for me it's easier to just call it for ie users instead of f***ing with the body tag. Generally though solution b/ looks better.
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [MOD] The Body ID, for sNews 1.7
« Reply #21 on: November 18, 2009, 11:45:05 AM »

Yeap.
Found this: http://bastian-allgeier.de/css_browser_selector/
Quote
CSS Browser Selector is a very small php function which empower CSS selectors. It gives you the ability to write specific CSS code for each operating system and each browser.
Code: [Select]
<?php

/*
PHP CSS Browser Selector v0.0.1
Bastian Allgeier (http://bastian-allgeier.de)
http://bastian-allgeier.de/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Credits: This is a php port from Rafael Lima's original Javascript CSS Browser Selector: http://rafael.adm.br/css_browser_selector
*/

function css_browser_selector($ua=null) {
$ua = ($ua) ? strtolower($ua) : strtolower($_SERVER['HTTP_USER_AGENT']);

$g 'gecko';
$w 'webkit';
$s 'safari';
$b = array();

// browser
if(!preg_match('/opera|webtv/i'$ua) && preg_match('/msie\s(\d)/'$ua$array)) {
$b[] = 'ie ie' $array[1];
} else if(strstr($ua'firefox/2')) {
$b[] = $g ' ff2';
} else if(strstr($ua'firefox/3.5')) {
$b[] = $g ' ff3 ff3_5';
} else if(strstr($ua'firefox/3')) {
$b[] = $g ' ff3';
} else if(strstr($ua'gecko/')) {
$b[] = $g;
} else if(preg_match('/opera(\s|\/)(\d+)/'$ua$array)) {
$b[] = 'opera opera' $array[2];
} else if(strstr($ua'konqueror')) {
$b[] = 'konqueror';
} else if(strstr($ua'chrome')) {
$b[] = $w ' ' $s ' chrome';
} else if(strstr($ua'iron')) {
$b[] = $w ' ' $s ' iron';
} else if(strstr($ua'applewebkit/')) {
$b[] = (preg_match('/version\/(\d+)/i'$ua$array)) ? $w ' ' $s ' ' $s $array[1] : $w ' ' $s;
} else if(strstr($ua'mozilla/')) {
$b[] = $g;
}

// platform
if(strstr($ua'j2me')) {
$b[] = 'mobile';
} else if(strstr($ua'iphone')) {
$b[] = 'iphone';
} else if(strstr($ua'ipod')) {
$b[] = 'ipod';
} else if(strstr($ua'mac')) {
$b[] = 'mac';
} else if(strstr($ua'darwin')) {
$b[] = 'mac';
} else if(strstr($ua'webtv')) {
$b[] = 'webtv';
} else if(strstr($ua'win')) {
$b[] = 'win';
} else if(strstr($ua'freebsd')) {
$b[] = 'freebsd';
} else if(strstr($ua'x11') || strstr($ua'linux')) {
$b[] = 'linux';
}

return join(' '$b);

}

?>

Quote
Usage

Include css_browser_selector.php in your app <?php require("css_browser_selector.php"); ?> …and add the following to your html template. <html class="<?php echo css_browser_selector() ?>"> HTML-Output (for your browser):

What I did to make it fails?
1/ uploaded the file @root
2/ called it in my template
Code: [Select]
<?php require("css_browser_selector.php"); ?>
3/ changed the last line into:
Code: [Select]
return '<body id="' . $bodyID .'" class="<?php echo css_browser_selector() ?>">'."\r\n";

and got ouputed by IE8:
Quote
<body id="home" class="<?php echo css_browser_selector() ?>">
;D

Then I found this page: http://rafael.adm.br/css_browser_selector/
With a tiny JS script.
1 (long) line:
Code: [Select]
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',o='opera',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);
which does the job well. (applause the author -Rafael Lima, not me of course- here)

That works real fine.

But I still looking for a PHP trick to maket it in works into the body id function since I might use it and to digg why it fails.

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: [MOD] The Body ID, for sNews 1.7
« Reply #22 on: November 18, 2009, 01:53:48 PM »

Quote from: Sven
3/ changed the last line into:
return '<body id="' . $bodyID .'" class="<?php echo css_browser_selector() ?>">'."\r\n";

The template call looks strange to me -- do you have that in snews.php or index.php? if in snews.php it should be
Quote
return '<body id="' . $bodyID .'" class="'.css_browser_selector().'">';

and then in index.php
Quote
<?php echo bodyID(); ?>

That's how I see it anyway... not sure if it's any good. ;)
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [MOD] The Body ID, for sNews 1.7
« Reply #23 on: November 19, 2009, 09:27:23 AM »

Quote from: Sven
3/ changed the last line into:
return '<body id="' . $bodyID .'" class="<?php echo css_browser_selector() ?>">'."\r\n";

The template call looks strange to me -- do you have that in snews.php or index.php? if in snews.php it should be
Quote
return '<body id="' . $bodyID .'" class="'.css_browser_selector().'">';

and then in index.php
Quote
<?php echo bodyID(); ?>

That's how I see it anyway... not sure if it's any good. ;)
That was it.
The script now works (forgot to remove '."\r\n"; which was after some comments). Stupid me! ::)
Classes are now applied but.
Both scripts (PHP and the JS one) works fine. But there are user-agent based, not vendor based. So there might not work if user agent is disguised.

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: [MOD] The Body ID, for sNews 1.7
« Reply #24 on: March 26, 2011, 05:58:26 PM »

I've been fiddling a bit with "blogazine" designs, just for fun, and find that I need to amend the bodyID function to print article seftitles in full article view, not just categorySEF (or pageSEF for Pages). Problem - if I see it correctly - is that sNews doesn't diiferentiate between Page seftitle and Article seftitle, it's conditional on position. Meaning that every-friggin'-thing I've tried to trick the function into printing article seftitles just plum fails.

Jason, Phil, Anyone? How to? Pretty please?
Much obliged for pointers.

PS. To understand what I'm after, check for example Jason Santa Maria's normal design and compare with his candygrams
Logged

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: [MOD] The Body ID, for sNews 1.7
« Reply #25 on: March 27, 2011, 12:44:31 AM »

I am confused as to what you want 

but I am guessing you need something like this (from way back when...).. UNTESTED!!!!
Code: [Select]
// Truncated version of http://snewscms.com/forum/index.php?topic=8974.msg64620#msg64620
// UNTESTED UNTESTED UNTESTED
function get_uri( $var ) {
static $arr;
if (!$arr) {
global $url, $categorySEF, $_catID, $_XNAME, $_ID, $_POS;
$arr = array();

if ( $url ) {
// PageSEF
if( $url[0] && $_ID && $_POS == 3 ) {
$arr['pageSEF'] = $url[0];
}

// CategorySEF
if( $url[0] && $_catID ) {
$arr['categorySEF'] = $url[0];
}

// SubcatSEF
if( $url[1] && $_catID && $_XNAME ) {
$arr['subcatSEF'] = $url[1];
}

// ArticleSEF
if ( $url[2] && $_ID && $_POS == 1 ) {
$arr['articleSEF'] = $url[2];
} elseif ( $url[1] && $_ID && $_POS == 1 ) {
$arr['articleSEF'] = $url[1];
}
}
// Home Page
if ( empty($arr) ) {
$arr['home'] = 'home';
}
}
return $arr[$var];
}

if( get_uri('articleSEF') ) {
echo get_uri('articleSEF');
}
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: [MOD] The Body ID, for sNews 1.7
« Reply #26 on: March 27, 2011, 01:09:26 AM »

Well, what I want is very simple really. Or maybe it should say "simple". Not sure which.
I want to use the bodyID function, but have it print the seftitle of an article, as body id, when viewing it (the article) rather than the article's parent category sef. Currently the bodyID function prints home, category sef or page sef, never the article sef. To be able to do a true "blogazine" design, I'd need to target an article's body id which should be unique for each article, so using the article sef is the logical way to go. I'll try it with your suggested code (thanks) although I was hoping there might be a simpler way of getting to it. Maybe there isn't.

The bodyID code I'm using is this:

Code: [Select]
// BODY ID FUNCTION
function bodyname() {
global $categorySEF;
$catList = explode(',', l('cat_listSEF'));
// sNews does not differentiate between admin pages and public pages
// A default install would have the first 4 as 'archive,contact,sitemap,login'
unset($catList[0], $catList[1], $catList[2], $catList[3], $catList[4], $catList[5], $catList[6]);
if ( $categorySEF || (_ADMIN && $_GET['action'])) {
if (in_array($_GET['action'], $catList) || in_array($categorySEF, $catList)) {
$id = 'id="administration"';
} else $id = 'id="'.$categorySEF.'"';
} else $id = 'id="'.s('home_sef').'"';
echo $id;
}

Just so it's clear, I have tried various concoctions using $articleSEF as the main ingredient, but without success...
If the term 'blogazine' is confusing, read this Smashing Magazine article for examples.
« Last Edit: March 27, 2011, 01:41:09 AM by Fred K (agentsmith) »
Logged

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: [MOD] The Body ID, for sNews 1.7
« Reply #27 on: March 27, 2011, 04:12:27 AM »

I've read that article and now know where you are heading at.  

To be honest I am not sure why the code I presented wouldn't work.

This is totally untested and off the top of my head, but should work based on prior code:
Code: [Select]
<?php

// Truncated version of http://snewscms.com/forum/index.php?topic=8974.msg64620#msg64620
// UNTESTED UNTESTED UNTESTED
function get_uri$var ) {
static $arr;
if (!$arr) {
global $url$categorySEF$_catID$_XNAME$_ID$_POS;
$arr = array();

if ( $url ) {
// PageSEF
if( $url[0] && $_ID && $_POS == ) {
$arr['pageSEF'] $url[0];
}

// CategorySEF
if( $url[0] && $_catID ) {
$arr['categorySEF'] = $url[0];
}

// SubcatSEF
if( $url[1] && $_catID && $_XNAME ) {
$arr['subcatSEF'] = $url[1];
}

// ArticleSEF
if ( $url[2] && $_ID && $_POS == ) {
$arr['articleSEF'] = $url[2];
} elseif ( $url[1] && $_ID && $_POS == ) {
$arr['articleSEF'] = $url[1];
}

// 404
if ($categorySEF == '404') {
$arr['404'] = '404';
}

// Home Page
if ( empty($arr) ) {
$arr['home'] = 'home';
}
}
return $arr[$var];
}

function bodyID() {
global $categorySEF;

$id '';

// Prep for admin pages
$catList explode(','l('cat_listSEF'));
$catList[] = 'process';
$catList[] = 'editcomment';
unset( $catList[0], $catList[1], $catList[2] );
 
switch(true) {
case( get_uri('pageSEF') ):
$id get_uri('pageSEF');
break;
case( get_uri('categorySEF') ):
$id get_uri('categorySEF');
break;
case( get_uri('subcatSEF') ):
$id get_uri('categorySEF') .'-'get_uri('subcatSEF');
break;
case( get_uri('articleSEF') ):
$id get_uri('articleSEF');
break;
case( get_uri('home') ):
$id get_uri('home');
break;
case( in_array($categorySEF$catList) || in_array($_GET['action'], $catList) ):
$id 'admin';
break;
case( get_uri('404') ):
$id '404';
break;
default:
$id $categorySEF;
break;
}
return 'id="'$id .'"';
}

?>

This should take care of all known content types defined by sNews 1.7, even 404
« Last Edit: March 27, 2011, 04:19:04 AM by nukpana »
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: [MOD] The Body ID, for sNews 1.7
« Reply #28 on: March 27, 2011, 04:05:03 PM »

Thanks. I don't know either why it shouldn't work. My initial reaction was based on that I didn't understand it (that's always the case with me when confronted with complicated blocks of stuff I don't understand), but there was never a case of me not trusting it. Your codes almost always work. ;)

That said, with the code above, articleSEF is still not printed as the body id, instead articles get their parent catSEF as id, so in that respect there's no change from your original improvement. Also I noticed that the cat_list pages get "home" as id. With your original code they got their proper SEF as id.

I don't understand why your code above doesn't print articleSEF as id for articles - judging by the code (which I understand better now) it should work ...

Anyway, those are the results I'm getting. I'll poke a little at the code to see if anything changes.
« Last Edit: March 27, 2011, 04:10:26 PM by Fred K (agentsmith) »
Logged

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: [MOD] The Body ID, for sNews 1.7
« Reply #29 on: March 27, 2011, 05:00:30 PM »

Look at you, making me install sNews..... lol

anyway, I fixed it based on the case statement.. order is important:
Code: [Select]
function get_uri( $var ) {
static $arr;
if (!$arr) {
global $url, $categorySEF, $_catID, $_XNAME, $_ID, $_POS;
$arr = array();

if ( $url ) {
// PageSEF
if( $url[0] && $_ID && $_POS == 3 ) {
$arr['pageSEF'] = $url[0];
}

// CategorySEF
if( $url[0] && $_catID ) {
$arr['categorySEF'] = $url[0];
}

// SubcatSEF
if( $url[1] && $_catID && $_XNAME ) {
$arr['subcatSEF'] = $url[1];
}

// ArticleSEF
if ( $url[2] && $_ID && $_POS == 1 ) {
$arr['articleSEF'] = $url[2];
} elseif ( $url[1] && $_ID && $_POS == 1 ) {
$arr['articleSEF'] = $url[1];
}

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

function bodyID() {
global $categorySEF;

$id = '';

// Prep for admin pages
$catList = explode(',', l('cat_listSEF'));
$catList[] = 'process';
$catList[] = 'editcomment';
unset( $catList[0], $catList[1], $catList[2] );

switch(true) {
case( get_uri('articleSEF') ):
$id = get_uri('articleSEF');
break;
case( get_uri('subcatSEF') ):
$id = get_uri('categorySEF') .'-'. get_uri('subcatSEF');
break;
case( get_uri('categorySEF') ):
$id = get_uri('categorySEF');
break;
case( get_uri('pageSEF') ):
$id = get_uri('pageSEF');
break;
case( in_array($categorySEF, $catList) || in_array($_GET['action'], $catList) ):
$id = 'admin';
break;
case( get_uri('404') ):
$id = '404';
break;
case( $categorySEF ):
$id = $categorySEF;
break;
case( get_uri('home') ):
$id = get_uri('home');
break;
}
return 'id="'. $id .'"';
}

Works on a fresh install, making a subcat, a page, and a article to the subcat, all works as expected, even admin & 404
Logged
Pages: 1 [2] 3