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 4

Author Topic: [TESTING] Template Mod v2 Multiple Layouts dB driven  (Read 10565 times)

centered

  • Guest
[TESTING] Template Mod v2 Multiple Layouts dB driven
« on: February 03, 2008, 04:22:26 PM »

Now that version 1 is done and can be downloaded here: http://snewscms.com/forum/index.php?topic=6711.0
I can begin working on version 2 for multiple templates. 

My brainstorming here:

1. Add templateid to Articles and Categories dbtables to assign a template to a category or an article/page.
2. Add new field in admin to assing templates to categories and articles/pages
3. Remove default from current template page or change to sitewide template. Sitewide button to regulate adding multiple templates or not.
4. New admin section for multiple layouts (laid out form for #2)???? Unsure
5. For multiple templates - need to add something to show template for home page
      -- Possible solution - add Home/Archives/Contact/Sitemap to database.  Put templates in db, then assign template

???
Somehow give the user a choice for a sitewide template or multiple layouts, or both.  Or just lay it out and let the user decide for each item??


I would like some ideas and feedback.  Thanks!


----------------2.7.08 --- UPDATE-----------------------
Releasing Beta 1 of this project.  Let me know of bugs bugs and all bugs...
http://www.mediafire.com/?2hbnhiboo4c

BUG FIX-
Find:
Code: [Select]
mysql_query("INSERT INTO ".db('prefix')."tempAssoc(name, categoryid, templateid) VALUES('$name', '$catTempID', '$catTemp')");
Replace with:
Code: [Select]
mysql_query("INSERT INTO ".db('prefix')."tempAssoc(name, categoryid, position, templateid) VALUES('$name', '$catTempID', '-1', '$catTemp')");
Find:
Code: [Select]
$cquery = $query." categoryid > 0 AND position = -1 ORDER BY id";Replace:
Code: [Select]
$cquery = $query." categoryid > 0 AND position = -1 ORDER BY catorder,id";
Find case(isset($_POST['add_template'])) replace the add_template and edit_template
Code: [Select]
case(isset($_POST['add_template'])):
// v2
mysql_query("INSERT INTO ".db('prefix')."templates(name, template, css) VALUES('$name', '$template', '$temp_css')");
if ($apply == 'on') {
$tempID = retrieve('id','templates','name',$name);
mysql_query("INSERT INTO ".db('prefix')."tempAssoc(templateid) VALUES('$tempID')");
}
break;
case(isset($_POST['edit_template'])):
// v2
mysql_query("UPDATE ".db('prefix')."templates SET name = '$name', template = '$template', css = '$temp_css' WHERE id = $id LIMIT 1;");
if ($apply == 'on') {
$tempID = retrieve('id','templates','name',$name);
mysql_query("UPDATE ".db('prefix')."tempAssoc SET templateid = '$id'");
}
break;
« Last Edit: February 10, 2008, 03:37:51 PM by equilni »
Logged

maxou

  • Jr. Member
  • **
  • Karma: 5
  • Posts: 81
  • Bug's Finder
Re: [WIP] Template Mod v2
« Reply #1 on: February 03, 2008, 07:17:57 PM »

Hi EQ  :)

I don't understand, with your next mod we can get a template for Categories and Articles.
So there was not a template for all pages but a template for Categories and a template for Articles ?
Logged
Work on XAMPP.

centered

  • Guest
Re: [WIP] Template Mod v2
« Reply #2 on: February 04, 2008, 12:37:20 AM »

Currently there is one template for sNews. 

If you want more, there are other options:

Single layouts:
My template mod that I linked above, which puts the markup and stylesheets in the database and is switchable through the admin.
Bakercad's Template switcher  - one template for whole site - http://snewscms.com/forum/index.php?topic=5330.0

Multiple Layouts for say categories/articles/pages or combinations:
Joost has a multiple layout 'mod' here: http://snewscms.com/forum/index.php?topic=6133.0
Codetwist does too: http://snewscms.com/forum/index.php?topic=5323.0

Joost and codetwist's functions are good but you would have to manually edit the main index file.  This new way, keeps all files in the database and would be selectable within the admin sections. 

Say i want template one for category two, I can select that in the new or edit section.  I can choose template two for category one, but have template three for a certain article within that category. 

With that being said.  I have figured out further functionality... hopefully:
Currently in my mod, the templates have a default checkbox,
v2 will replace that with a sitewide template checkbox.  If the checkbox is unchecked, then it will display the multiple template options.
   -- Home would be under pages and would have the first template automatically.
   -- The user could select a template for a category, the articles would inherit the category template if no other template is selected.

what I have so far...
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: [WIP] Template Mod v2
« Reply #3 on: February 04, 2008, 03:15:41 AM »

Quote from: equilni
Say i want template one for category two, I can select that in the new or edit section.  I can choose template two for category one, but have template three for a certain article within that category. 

With that being said.  I have figured out further functionality... hopefully:
Currently in my mod, the templates have a default checkbox,
v2 will replace that with a sitewide template checkbox.  If the checkbox is unchecked, then it will display the multiple template options.
   -- Home would be under pages and would have the first template automatically.
   -- The user could select a template for a category, the articles would inherit the category template if no other template is selected.
what I have so far...

Keep on stretching your limits there EQ. So... the short form of what you're thinking is... your V2 will work like the V1... ability to insert several templates into the dbase table(s) and then choose which of them each category will use from the Add New or Edit Article or Page panels? If so... that would really be cool. Though, just having the templates in a templates folder would be fine enough.

Which causes me to wonder... could Bakercad's template system be enhanced a bit to do the same thing... without having to put the template stuff into the database through another set of Admin panels? Just a thought... I'll have to pass this by the Baker.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Joost

  • Guest
Re: [WIP] Template Mod v2
« Reply #4 on: February 04, 2008, 03:56:43 AM »

@Jason

Question: Is it because you want to add an online template editor, your so eager to stuff templates in a database?
FYI, if that's the case. I have some experience with CMSMadeSimple. CMSMadeSimple stuffs templates and stylesheets in the database. I find it highly uncomfortable, as there is no highlighter. So most of the time I edited offline, using my favourite editor and pasted it in the textaerea afterwards.
I think files and an upload folder will do.
Logged

centered

  • Guest
Re: [WIP] Template Mod v2
« Reply #5 on: February 04, 2008, 03:58:33 AM »

Doug,
My assumption is yes, you can mix Joost/Codetwist's Multi-layout's mod with Baker's Template Switcher mod.  Remember, Joost/Codetwist mod does everything manually, nothing is noted in the db or the admin section

This mod would take everything and put in the db and the admin like v1, but allow for multiple layouts/templates based on a Joost/Codetwist/myown combination.
Logged

centered

  • Guest
Re: [WIP] Template Mod v2
« Reply #6 on: February 04, 2008, 04:09:08 AM »

@Jason

Question: Is it because you want to add an online template editor, your so eager to stuff templates in a database?
FYI, if that's the case. I have some experience with CMSMadeSimple. CMSMadeSimple stuffs templates and stylesheets in the database. I find it highly uncomfortable, as there is no highlighter. So most of the time I edited offline, using my favourite editor and pasted it in the textaerea afterwards.
I think files and an upload folder will do.

Actually, CMSmadesimple is exactly why I did this mod in the first place.  I have done the same procedure as you Joost, work offline then upload the markup to CMSms. I like having the option to have a secondary layout for a page or two if needed.

This mod, should make it easy to do multitemplates.

*EDIT*
To answer your question, v1 added the template editor to store the template and css in the database.  Less of a need for extra files, or bigger files.  Keeps the bandwidth down.
« Last Edit: February 04, 2008, 04:29:21 AM by equilni »
Logged

Joost

  • Guest
Re: [WIP] Template Mod v2
« Reply #7 on: February 04, 2008, 04:36:43 AM »

I don't see how it will keep the bandwidth down. It will surely consume more cpu resources.
Logged

centered

  • Guest
Re: [WIP] Template Mod v2
« Reply #8 on: February 04, 2008, 04:50:37 AM »

I don't see how it will keep the bandwidth down. It will surely consume more cpu resources.

1 less CSS file and the index file is cut to a single line. 

My template v1 mod is 148kb extracted
Default sNews 1.6 extracted is 340kb
My fresh WP install is 4.2MB
My CMSms folder on a fresh install equaling 14.1MB extracted

I would value the space that the CMS would have, so I can put more content if in terms of images, documents, pdf's etc.

Let me ask: what is better, having more files or more data in the database?

How will keeping the templates in the database consume more CPU resources?
Logged

Joost

  • Guest
Re: [WIP] Template Mod v2
« Reply #9 on: February 04, 2008, 06:29:18 AM »

The 'one line approach' I can understand, it can be done with 'regular' files also.
Let me provide you my second hand knowledge* ;). Done some reading on the subject.

Files, like stylesheets, don't have to be processed. The server simply sends it to the browser (lets forget about packaging, which is the same for any data). This uses more ram and disk space, but doesn't use that much cpu resources.
Processed data consumes more processing time (cpu) and uses less ram and disk space.

So a lot depends on server configuration (hard- and software). A database server will have a powerful processor and relatively little ram, while a file server might have a lot of ram.
Take note that even when a host provides a separate database server, php is still running on the webserver itself.
What's best? Since I am talking from theoretical knowledge and not from life time experience, I cannot say what's the right balance between processed data and files.

Quote from Wikipedia:

Quote
... a File Server is designed primarily to enable the rapid storage and retrieval of data where the heavy computation is provided by the workstations.

* 'theoretical knowledge' sounds better
Logged

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
Re: [WIP] Template Mod v2
« Reply #10 on: February 04, 2008, 10:00:45 AM »

yep, agree with Joost.
Personally, I would register the template location, but not store the template (complete) in db.
Logged
Of all the things I have lost, it is my mind that I miss the most.

centered

  • Guest
Re: [WIP] Template Mod v2
« Reply #11 on: February 04, 2008, 11:35:22 AM »

http://www.sitepoint.com/forums/

Go to this link and do a search.  Tell me how long it takes.  That is consuming CPU resources, because it is searching the db through thousands of records and performing heavy computations, then serving up the pages. 

Is a template not like a article, ONE article that is text with some HTML that is processed once? Can I say that a template is text that has some php that is encoded to be stored and then processed once?

This isn't heavy computations nor massive queries we are talking about here...
Code: [Select]
// Version One
function index() {
$result = mysql_query("SELECT template FROM ".db('prefix')."templates WHERE main_temp = 'YES'");
while ($r = mysql_fetch_array($result)) {
$template = $r['template']; $ins = strpos($template, '[/func]');
    if ($ins > 0) {
        $temp = str_replace('[func]', '|&|', $template);
        $temp = str_replace('[/func]', '|&|', $temp);
$temp = explode('|&|', $temp); $num=count($temp)-1; $i=1;
        while ($i <= $num) {
        $func = explode(':|:',$temp[$i]);
        ob_start();
        $returned = call_user_func_array($func[0],explode(',',$func[1]));
        $temp[$i]= ob_get_clean();
        if (empty($temp[$i])){$temp[$i]=$returned;}
          $i=$i+2;
        } $template = implode($temp);
} echo $template; }}

// Builds the css links from the db
function css_links() {
$result = mysql_query("SELECT css FROM ".db('prefix')."templates WHERE main_temp = 'YES'");
while ($r = mysql_fetch_array($result)) {
$style = explode(',',$r['css']);
foreach($style as $style) {
$cssresult = mysql_query("SELECT name,media FROM ".db('prefix')."css WHERE id = '$style'");
while ($cr = mysql_fetch_array($cssresult)) {
echo '<style type="text/css">@import url("index.php?style='.$cr['name'].'") '.$cr['media'].';</style>';
}}
}}

function snews_startup() {
connect_to_db();
// template editor
$styleid = clean($_GET['style']);
$style = retrieve('name','css','name',$styleid);
if (!empty($style)) {
header("Content-type: text/css");
$css = retrieve('css','css','name',$styleid);
echo $css; break;
}
// template editor end



If files are faster, then why aren't text-databases more popular?  Why doesn't sNews store the articles in text files, and categories as folders?
« Last Edit: February 04, 2008, 11:37:25 AM by equilni »
Logged

Rui Mendes

  • Development,Testing, Support
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1009
  • sNews1.7
    • Comunidade Portuguesa
Re: [WIP] Template Mod v2
« Reply #12 on: February 04, 2008, 11:39:48 AM »

Jason I agree with Joost and Phimoz. (Personally)

But I'm glad you continue this great mod. I think the user is free of choose.
« Last Edit: February 04, 2008, 11:49:22 AM by Rui Mendes »
Logged
Need a Job on Europe. Linkdin - Facebook / Group

centered

  • Guest
Re: [WIP] Template Mod v2
« Reply #13 on: February 04, 2008, 11:43:14 AM »

yep, agree with Joost.
Personally, I would register the template location, but not store the template (complete) in db.

Why? You would do that for an image or Word Documents or PDFs, but a template can be done differently thanks to you!

Let me ask what is the use then of your Function use in article's mod?  That is how this mod is possible!

Let me ask another question, why the reluctancy to store a template or css file in a database?
Logged

Rui Mendes

  • Development,Testing, Support
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1009
  • sNews1.7
    • Comunidade Portuguesa
Re: [WIP] Template Mod v2
« Reply #14 on: February 04, 2008, 11:52:57 AM »

It's a wonderfull ideia put multiple templates in table, and user can switch to template as he wishes (by temporal time). Like Cristmas, Summer etc.

I like your ideia Jason.
Logged
Need a Job on Europe. Linkdin - Facebook / Group
Pages: [1] 2 3 4