Thread: [Simplog-devel] modular approach to customizing appearance and behavior
Brought to you by:
f-bomb
From: Jim Hu <ji...@ta...> - 2004-08-29 07:42:21
|
To make customizing the appearance and behavior of different blogs easier (at least for me), I broke up the index.php and header.php files so that they would call different layout options that I'm keeping in a subdirectory called layout. The new index.php is just: ------------------------------------------------------------------------ ---- <?php if(!file_exists("config.php")) { header("Location: install.php"); exit(0); } session_start(); require_once("lib.php"); require_once("class.BlogInfo.php"); require_once("class.BlogEntry.php"); $blogid = $_GET['blogid']; if(!isset($blogid)) { $blogid = 1; #set default blog to see } $blogInfo = new BlogInfo($blogid); include("header.php"); $testindexfile = "layout/index".$blogid.".php"; if (file_exists($testindexfile)){ $indexfile = $testindexfile; }else{ $indexfile = "layout/index0.php"; } include($indexfile); ?> ------------------------------------------------------------------------ ---- The new header.php file is reduced to: <?php header("X-Pingback: $baseurl/api.php\n"); if(!isset($blogInfo)) { $btitle = "Simplog"; } else { $btitle = $blogInfo->getBlogTitle(); $btag = $blogInfo->getBlogTagline(); } if(isLoggedIn()) { $uid = getUID($_SESSION['login']); } $testheaderfile = "layout/header".$blogid.".php"; if (file_exists($testheaderfile)){ $headerfile = $testheaderfile; }else{ $headerfile = "layout/header0.php"; } include($headerfile); if(isLoggedIn()) { show_menu(); } ?> <br> ------------------------------------------------------------------------ ---- inside the layout subdirectory I have a series of files named header0, header1, header11 etc, and index0, index1.... plus the css files. Only header0 and index0 are necessary layout/header0.php is the missing pieces of the original header.php: ------------------------------------------------------------------------ ---- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title><?=$btitle?>: <?=$btag?></title> <script language="javascript" type="text/javascript" src="<?=$baseurl?>/simplog.js"></script> <link rel="alternate" type="text/xml" title="RSS" href="<?=$baseurl?>/rss2.php" /> <link rel="pingback" href="<?=$baseurl?>/api.php" /> <link rel="stylesheet" href="<?=$baseurl?>/layout/simplog.css" type="text/css" /> </head> <body bgcolor=#ffffff marginwidth=0 marginheight=0 leftmargin=0 topmargin=0> <table width=100% border=0 cellspacing=0 cellpadding=5 class=header> <tr> <td align=left><span class=blogname><?=$btitle?></span><br><span class=blogtag><?=$btag?></span></td> </tr> </table> ------------------------------------------------------------------------ ---- The alternate headers are customized to modify appearance (I specify which css to use in each one, so some blogs can share css files), plus to make a blog require user login (which I want for all the blogs I'm using to control other websites), I add <?php if(!isLoggedIn()) { auth(); } ?> to the header. This also makes the headers look different for all the views of the blog - archives, search results, edit pages etc. layout/index0.php is just the missing pieces of the original index.php: ------------------------------------------------------------------------ ---- <table cellpadding=0 cellspacing=0 border=0 width="100%" style="height:90%;"> <tr valign="top"> <td style="border-right:1px solid #999999;padding-right:24px;"> <div style="padding:10px;"> <?php @include("$baseurl/blog.php?blogid=$blogid"); ?> </div> </td> <td align="center" width=150 style="padding-left: 24px;"> <?php include("blocks.php"); ?> </td> </tr> </table> </body> </html> ------------------------------------------------------------------------ ---- Obviously, this allows me to alter the appearance of the individual blog pages, put blocks on the left, add other stuff etc. To a naive user, one could just install and use the defaults. Changing the appearance of different blogs and staying within that look and feel is easier for the slightly more sophisticated user with this approach than by feeding blog content to another page, as internal navigation links don't have to be adjusted at all. Would this be worth including in the next version? Jim |
From: Jason L. B. <ja...@bu...> - 2004-08-29 14:46:37
|
Jim, Now this would have been a good case for 'propose your changes first, get feedback, and make the changes afterwards'. Although your approach does work, I'm not convinced it's the right approach. simplog's current mechanism for this kind of thing, as seen in the first few lines below, is to check for a file (config.php), then create it from a master or template if it does not exist (via install.php process). Although separating index.php and header.php is probably a good thing, what if the 'new blog' creation process was reformulated to do the same thing? 1. Click 'Blog Admin' 2. Click 'Add Blog' 3. On the 'new blog' form, there would be a checkbox for 'Use custom templates' 4. When the user clicks 'Save', we check the value of the checkbox 5. If selected, we create copies of the blog layout and formatting template files, using the blog_id as part of the file name, then show a message to the user with the names of the files they can now customize. How about that approach? -jason Jim Hu wrote: > To make customizing the appearance and behavior of different blogs > easier (at least for me), I broke up the index.php and header.php > files so that they would call different layout options that I'm > keeping in a subdirectory called layout. > > The new index.php is just: > ------------------------------------------------------------------------ > ---- > <?php > if(!file_exists("config.php")) { > header("Location: install.php"); > exit(0); > } > > session_start(); > require_once("lib.php"); > require_once("class.BlogInfo.php"); > require_once("class.BlogEntry.php"); > > $blogid = $_GET['blogid']; > > if(!isset($blogid)) { > $blogid = 1; #set default blog to see > } > $blogInfo = new BlogInfo($blogid); > include("header.php"); > > $testindexfile = "layout/index".$blogid.".php"; > if (file_exists($testindexfile)){ > $indexfile = $testindexfile; > }else{ > $indexfile = "layout/index0.php"; > } > include($indexfile); > ?> > ------------------------------------------------------------------------ > ---- > The new header.php file is reduced to: > > <?php > header("X-Pingback: $baseurl/api.php\n"); > > if(!isset($blogInfo)) { > $btitle = "Simplog"; > } else { > $btitle = $blogInfo->getBlogTitle(); > $btag = $blogInfo->getBlogTagline(); > } > > if(isLoggedIn()) { > $uid = getUID($_SESSION['login']); > } > > $testheaderfile = "layout/header".$blogid.".php"; > if (file_exists($testheaderfile)){ > $headerfile = $testheaderfile; > }else{ > $headerfile = "layout/header0.php"; > } > > include($headerfile); > > if(isLoggedIn()) { > show_menu(); > } > ?> > <br> > ------------------------------------------------------------------------ > ---- > inside the layout subdirectory I have a series of files named > header0, header1, header11 etc, and index0, index1.... plus the css > files. Only header0 and index0 are necessary > layout/header0.php is the missing pieces of the original header.php: > ------------------------------------------------------------------------ > ---- > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> > <html> > <head> > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> > <title><?=$btitle?>: <?=$btag?></title> > > <script language="javascript" type="text/javascript" > src="<?=$baseurl?>/simplog.js"></script> > > <link rel="alternate" type="text/xml" title="RSS" > href="<?=$baseurl?>/rss2.php" /> > <link rel="pingback" href="<?=$baseurl?>/api.php" /> > <link rel="stylesheet" href="<?=$baseurl?>/layout/simplog.css" > type="text/css" /> > </head> > <body bgcolor=#ffffff marginwidth=0 marginheight=0 leftmargin=0 > topmargin=0> > <table width=100% border=0 cellspacing=0 cellpadding=5 class=header> > <tr> > <td align=left><span class=blogname><?=$btitle?></span><br><span > class=blogtag><?=$btag?></span></td> > </tr> > </table> > ------------------------------------------------------------------------ > ---- > The alternate headers are customized to modify appearance (I specify > which css to use in each one, so some blogs can share css files), > plus to make a blog require user login (which I want for all the > blogs I'm using to control other websites), I add > > <?php > if(!isLoggedIn()) { > auth(); > } > ?> > to the header. This also makes the headers look different for all > the views of the blog - archives, search results, edit pages etc. > > layout/index0.php is just the missing pieces of the original index.php: > ------------------------------------------------------------------------ > ---- > > <table cellpadding=0 cellspacing=0 border=0 width="100%" > style="height:90%;"> > <tr valign="top"> > <td style="border-right:1px solid #999999;padding-right:24px;"> > <div style="padding:10px;"> > > <?php @include("$baseurl/blog.php?blogid=$blogid"); ?> > > </div> > </td> > <td align="center" width=150 style="padding-left: 24px;"> > > <?php include("blocks.php"); ?> > > </td> > </tr> > </table> > > </body> > </html> > ------------------------------------------------------------------------ > ---- > Obviously, this allows me to alter the appearance of the individual > blog pages, put blocks on the left, add other stuff etc. > > To a naive user, one could just install and use the defaults. > Changing the appearance of different blogs and staying within that > look and feel is easier for the slightly more sophisticated user with > this approach than by feeding blog content to another page, as > internal navigation links don't have to be adjusted at all. Would > this be worth including in the next version? > > Jim > > > > ------------------------------------------------------- > This SF.Net email is sponsored by BEA Weblogic Workshop > FREE Java Enterprise J2EE developer tools! > Get your free copy of BEA WebLogic Workshop 8.1 today. > http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click > _______________________________________________ > Simplog-devel mailing list > Sim...@li... > https://lists.sourceforge.net/lists/listinfo/simplog-devel > > !DSPAM:4131891c71631195073659! > |
From: Jim Hu <ji...@ta...> - 2004-08-29 22:32:21
|
Jason, I'm a little confused...I'm viewing what I posted as propose first, get=20= feedback...with code to try since I want to make sure that it works (or=20= at least works almost - I found a minor problem with previewing with my=20= altered config). I've been trying all of my tweaks first before=20 posting, just to make sure that they don't crash and burn horribly. =20= This was a pretty trivial change to implement, so I thought I might as=20= well try it. Are you suggesting I should propose the concept without=20 coding it first (even on my own site?! - note that I didn't post this=20 to the bbs, just to the dev listserve for exactly the reason that you=20 allude to) so that others can suggest better ways to do it? I can do=20 that in future if that's better. I had thought that it would be better=20= to have a working example. I'm very new to this developer list=20 culture, so I apologize if this isn't the way it's done. On Aug 29, 2004, at 9:51 AM, Jason L. Buberel wrote: > Jim, > > Now this would have been a good case for 'propose your changes first,=20= > get feedback, and make the changes afterwards'. Although your approach=20= > does work, I'm not convinced it's the right approach. To be honest, I think my approach is a kludge, and the right way would=20= probably add some fields to the blog_list table in the database for the=20= page_template (I'd probably store the path/filename instead of the html=20= itself, as is done for the entry templates) and to indicate whether a=20 login should be required to view the blog. However, I've been trying=20 to avoid making changes to the database schema. I'm also enough of a=20 newbie to try to make changes in a way where I can go back easily if=20 something goes wrong! > > simplog's current mechanism for this kind of thing, as seen in the=20 > first few lines below, is to check for a file (config.php), then=20 > create it from a master or template if it does not exist (via=20 > install.php process).=A0 Note that I am NOT doing this to customize the appearance of the blog=20 entries - I understand how Simplog does that now, and although the=20 template admin script doesn't work on my setup (I've been editing them=20= directly in mySQL), the entry templating is unchanged by my proposal. =20= I'm changing the ability to customize the web page wrapper that lays=20 out the header/menu/entries/edit/admin/blocks/other. As far as I can=20 tell, the release of Simplog doesn't currently include that, and the=20 standard approach is to make a wrapper that calls blog.php or the rss=20 feed to place the content inside a custom layout. I don't see where=20 config.php comes into it.. I may be missing something...but it seems=20 like this is what we tell people on the bbs all the time. The problem with this is - and I was led to think about this by=20 visiting your blog (which is much prettier than anything I've done with=20= Simplog so far) - that you can have your main entry views laid out as=20 you want, but when you search, pick categories, go to archives, or=20 whatever, Simplog runs archive.php, takes its default header, and now=20 your page doesn't look like your other pages...for example, when I go=20 to http://www.buberel.org/myphpblog/jason.php, you have that nice blue=20= margin, black on white header, tasteful grey background etc. But when=20= I click on "Cooking", I get no blue margin, dark grey text on light=20 grey head banner and so on. When I click "back to jason's blog at=20 buberel.com" instead of using the back button on my browser, I'm still=20= in the grey blog version. Looking at your blog makes me hungry, btw! If you ever make it down=20 here to central TX, look me up and I'll take you out for BBQ or=20 Mexican. > Although separating index.php and header.php is probably a good=20 > thing, what if the 'new blog' creation process was reformulated to do=20= > the same thing? > > 1. Click 'Blog Admin' > 2. Click 'Add Blog' > 3. On the 'new blog' form, there would be a checkbox for 'Use custom=20= > templates' > 4. When the user clicks 'Save', we check the value of the checkbox > 5. If selected, we create copies of the blog layout and formatting=20 > template files, using the blog_id as part of the file name, then show=20= > a message to the user with the names of the files they can now=20 > customize. > > How about that approach? That might be a nice way to do it - and would be compatible with the=20 approach I proposed, unless I misunderstand you. However, I think a=20 simpler alternative would be to leave off the checkbox and just create=20= the copies of the files - and tell the users in the help=20 file/documentation/bbs how to customize. The copies are small, so the=20= extra storage is pretty trivial, and if the user doesn't want to=20 customize, it would be transparent that the different blogs are running=20= off different but identical template copies (I have a feeling I could=20 have said that more clearly but I hope you see what I mean...). Jim > > -jason > <snip>= |