Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 2 [3] 4

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

Rui Mendes

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


So your saying that this mod is bad for those using alot of stored data in the database??  I am trying to understand why is it bad compared to why it is good for others and your clients


I never told that Jason, I said "I don't Know" for my site, means I must try if it is fast. Like I said: "I like your ideia".
I can garanty to you, If is efficient with a lots data in database, I'll add this mod to my my website.

If you need help, as always I'm here.

One ideia, added by You or by me, to this mod:
- Making change template automatically by date or event, will be nice.

About my sNews Events, this mod will be perfect.

Logged
Need a Job on Europe. Linkdin - Facebook / Group

Rui Mendes

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

I think about it. I change my mind.

Now I think is good ideia, because in only text. Images can be put in only folder.
So We have

snews.php
.htaccess (can be removed if you use your snews without .htaccess)
folder ->images
readme.htm (instructions)

and about style.css is in table ?
Logged
Need a Job on Europe. Linkdin - Facebook / Group

centered

  • Guest
Re: [WIP] Template Mod v2
« Reply #32 on: February 04, 2008, 11:31:19 PM »

Logged

centered

  • Guest
Re: [WIP] Template Mod v2
« Reply #33 on: February 05, 2008, 01:18:40 AM »

Code: [Select]
function get_tempID() {
$categorySEF = get_id('category');
$catID = retrieve('id','categories','seftitle',$categorySEF);
$articleSEF = get_id('article');
$artID = retrieve('id','articles','seftitle',$articleSEF);
if (!empty($articleSEF)) {
$tempID = retrieve('templateid','tempAssoc','articleid',$artID); }
elseif (!empty($catID)) {
$tempID = retrieve('templateid','tempAssoc','categoryid',$catID); }
elseif (empty($catID)) {
$defaultSEF = ucfirst(strtolower($categorySEF));
$tempID = retrieve('templateid','tempAssoc','name',$defaultSEF); }
elseif (check_category($categorySEF) == true) {
$tempID = retrieve('templateid','tempAssoc','name','Home'); }
return $tempID;
}

// Builds the template from the database and parse the [func] tags
function index() {
// v2
$tempID = get_tempID();
$result = mysql_query("SELECT * FROM ".db('prefix')."templates WHERE id = $tempID LIMIT 1"); //  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() {
// v2
$tempID = get_tempID();
$result = mysql_query("SELECT * FROM ".db('prefix')."templates WHERE id = $tempID"); // WHERE main_temp = 'YES'
while ($r = mysql_fetch_array($result)) {
$style = explode(',',$r['css']);
foreach($style as $style) {
$cssresult = mysql_query("SELECT * 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>';
}}
}}

http://img232.imageshack.us/img232/7136/cattempgy0.jpg
« Last Edit: February 05, 2008, 02:07:01 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 #34 on: February 05, 2008, 01:30:09 AM »

Hello again Jason.

I think your index(); has a IE 7.0 bug (for me is not working). I start see your code.

Quote
function index() {
   $result = mysql_query("SELECT * FROM ".db('prefix')."templates WHERE main_temp = 'YES' LIMIT 1");
...
Logged
Need a Job on Europe. Linkdin - Facebook / Group

centered

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

Logged

Rui Mendes

  • Development,Testing, Support
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1009
  • sNews1.7
    • Comunidade Portuguesa
Re: [WIP] Template Mod v2
« Reply #36 on: February 05, 2008, 10:54:20 AM »

Excellent ideia, your get_tempID, gives me ideia create a newfunction for Gallery
Logged
Need a Job on Europe. Linkdin - Facebook / Group

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • “I'm a self-made man and worships my creator.”
    • p-ahlqvist.com
Re: [WIP] Template Mod v2
« Reply #37 on: February 05, 2008, 10:55:33 AM »

Teasers aren't fair, Jase ;)
Logged
"It's only dead fish that goes with the flow... "
Updated

centered

  • Guest
Re: [WIP] Template Mod v2
« Reply #38 on: February 05, 2008, 12:58:02 PM »

Excellent ideia, your get_tempID, gives me ideia create a newfunction for Gallery

Thanks.  If you have an idea why home or anything in cat_list is not working, let me know.

Teasers aren't fair, Jase ;)

oh but they are!

EDIT ----------------------------------------------

NEW IDEA -
 - Since I have Home, Archive, Contact, and Sitemap in the tempAssoc Table, might as well put Administration and 404 in the table as well, since others may want to utilize thier own Admin and 404 templates.

Db table tempAssoc looks like this:
Fields: id, name, categoryid, catorder, articleid, pageid, templateid
Ex.        1, Home, NULL, NULL, NULL, NULL, 1
   2, catOne, 1, 1, NULL, NULL, NULL, 2
   3, catTwo, 2, 0, NULL, NULL, NULL, 2
   4, artOne, NULL, NULL, 1, NULL, 1
   5, pageOne, NULL, NULL, NULL, 2, 1


Progress:
 - There is still alot of work to do and it is very early to determine anything definitive.
Right now, I can:
 - Create/edit a template and apply it to all pages
 - Create/edit categories and pages and select templates (picture above) (need to work on Pages)
 - Show a new section called Structure to outline the whole site (teaser picture) and choose templates for each.  (still a heavy WIP - no pages and no save button)
 - Other than Home (/) and anything in the admin, The functionality works, but alas flawed

« Last Edit: February 05, 2008, 03:55:51 PM by equilni »
Logged

centered

  • Guest
Re: [WIP] Template Mod v2
« Reply #39 on: February 06, 2008, 12:51:49 AM »

Thanks to codetwist, switching works perfectly!

Code: [Select]
$l['adminSEF'] = array(login,administration,admin_category,admin_article,article_new,extra_new,page_new,categories,articles,extra_contents,pages,settings,files,logout,templates,admin_templates,stylesheets,admin_stylesheets,structure);


} return $l[$variable];
}
/*** END OF SETTINGS & VARIABLES, EDIT BELOW THIS LINE ONLY IF YOU KNOW WHAT YOU'RE DOING ***/
// template editor - new functions

// v2
function getContentKeyData() {
   //
   $strResult = 'unknown';
   $arrResult = array();
   //
   $homeSEF      = s('home_sef');
   $homePageId   = s('display_page');
   //
   //if ( $categorySEF  = getGetParm('category') ) {
   if ( $categorySEF  = get_id('category') ) {
      $categoryId = retrieve('id', 'categories', 'seftitle', $categorySEF);
   }
   else {
      $categorySEF = $homeSEF;
   }
   $categoryId = isset($categoryId) ? $categoryId : 0;
   //if ( $itemSEF = getGetParm('article') ) {
   if ( $itemSEF = get_id('article') ) {
      if ( $itemId = retrieve('id', 'articles', 'seftitle', $itemSEF) ) {
         $itemPosition = retrieve('position', 'articles', 'id', $itemId);
      }
   }
   $itemId = isset($itemId) ? $itemId : 0;
   if ( $categoryId == 0 )  {
      if ( check_category( $categorySEF ) && ($categorySEF != $homeSEF) ) {
         // Dealing with built-in pages - archive, sitemap, contact
         $strResult = 'built-in';
      }
      else {
         if ( $itemId > 0 ){
            // Specific item requested (either page or article)
            if ( $itemPosition > 0 ) {
               if ( $itemPosition == 3 ) {
                  $strResult = 'page';
               }
               elseif ( $itemPosition == 1 ) {
                  $strResult = 'article';
               }
            }
         }
         elseif ( ($categorySEF == $homeSEF) && ($homePageId > 0) ) {
            // Dealing with home replacement page
            $strResult = 'homepage';
         }
         else {
            // Dealing with built-in home
            $strResult = 'home';
         }
      }
   }
   elseif ( $itemId > 0 ) {
      // Dealing with real category
      $strResult = 'article';
   }
   elseif ( $categoryId > 0 ) {
      // Dealing with real category
      $strResult = 'category';
   }
   $arrResult['itemType'] = $strResult;
   switch ( $strResult ) {
      case 'category' :
         $arrResult['itemId'] = $categoryId;
      case 'home' :
      case 'built-in' :
         $arrResult['itemSEF'] = $categorySEF;
         break;
      case 'page' :
      case 'article' :
         $arrResult['itemSEF'] = $itemSEF;
         $arrResult['itemId'] = $itemId;
         break;
      case 'homepage' :
         $arrResult['itemSEF'] = $categorySEF;
         $arrResult['itemId'] = $homePageId;
         break;
      case 'unknown' :
      default :
         break;
   }
   return $arrResult;
}

// v2
function get_tempID() {
$curItem = getContentKeyData();
$itemSEF  = $curItem['itemSEF'];
$artID = retrieve('id','articles','seftitle',$itemSEF);
$catID = retrieve('id','categories','seftitle',$itemSEF);
$list = l('adminSEF'); if (in_array($itemSEF, $list)) { $listed = $itemSEF; }
if (!empty($artID)) {
$tempID = retrieve('templateid','tempAssoc','articleid',$artID); }
elseif (empty($artID) && !empty($catID)) {
$tempID = retrieve('templateid','tempAssoc','categoryid',$catID); }
elseif (empty($artID) && empty($catID) && !empty($listed)) {
$tempID = retrieve('templateid','tempAssoc','name','Administration'); }
elseif (empty($artID) && empty($catID) && empty($listed)) {
$defaultSEF = ucfirst(strtolower($itemSEF));
$tempID = retrieve('templateid','tempAssoc','name',$defaultSEF); }
elseif ($itemSEF = 'home') { $tempID = retrieve('templateid','tempAssoc','name','Home'); }
return $tempID;
}

// Builds the template from the database and parse the [func] tags
function index() {
// v2
$tempID = get_tempID();
$result = mysql_query("SELECT template FROM ".db('prefix')."templates WHERE id = $tempID LIMIT 1"); //  WHERE id = $tempID // 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() {
// v2
$tempID = get_tempID();
$result = mysql_query("SELECT * FROM ".db('prefix')."templates WHERE id = $tempID LIMIT 1"); //  WHERE id = $tempID // WHERE main_temp = 'YES'
while ($r = mysql_fetch_array($result)) {
$style = explode(',',$r['css']);
foreach($style as $style) {
$cssresult = mysql_query("SELECT * 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>';
}}
}}


« Last Edit: February 06, 2008, 12:43:24 PM by equilni »
Logged

centered

  • Guest
Re: [WIP] Template Mod v2
« Reply #40 on: February 06, 2008, 12:43:32 PM »

Alpha Testing ONLY!
Things Break and do not work in alpha versions!!

You can edit or create a new category/article/page and assign a template to it then play around with the site

Structure DOES NOT WORK
http://www.mediafire.com/?ddwzxdfmxrc

To do:
1. Save button in structure
2. Remove pageid from tempAssoc dbTable
3. Filter Template selection from Extras.
4. Add 404 to tempAssoc
5. More testing

Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [WIP] Template Mod v2
« Reply #41 on: February 07, 2008, 07:49:24 AM »

a Little teaser:

http://img225.imageshack.us/img225/1540/selectiondw2.jpg
:o
Am I still dreaming?
Gonna have one more coffee and be back to see.

centered

  • Guest
Re: [WIP] Template Mod v2
« Reply #42 on: February 07, 2008, 10:20:58 AM »

Don't thank me too quickly...
.. but you can drool some more if you like!

http://img230.imageshack.us/img230/2998/blahgm2.jpg

Rui, I may need assistance if you may, I can't get Sven's dream to save anything...

How would you go about saving the above picture?!?!

Code I currently have is
Code: [Select]
function t_select($tempID) {
echo ' <select name = "strucID">';
$tempresult = mysql_query("SELECT * FROM ".db('prefix')."templates ORDER BY id ASC");
while ($t = mysql_fetch_array($tempresult)) {
echo '<option value="'.$t['id'].'"';
if ($t['id'] == $tempID) { echo ' selected="selected"'; }
echo '>'.$t['name'].'</option>';
}
echo '</select>';
}

function structure() {
if (s('enable_editor') == 'on') {
echo html_input('form', '', 'post', '', '', '', '', '', '', '', '', '', 'post', 'index.php?action=process&amp;task=save_structure', '');
echo html_input('fieldset', '', '', '', '', '', '', '', '', '', '', '', '', '', l('structure'));
echo '<h3><strong>'.l('pages').'</strong></h3>';
$query = "SELECT id,name,templateid,categoryid FROM ".db('prefix')."tempAssoc WHERE";
// Default pages and admin
$dquery = $query." id IN(1,2) ORDER BY id";
$dresult = mysql_query($dquery);
while ($d = mysql_fetch_array($dresult)) {
echo '<p>'.$d['name'];
t_select($d['templateid']);
echo '</p>';
}
// User Pages
$pquery = $query." position = 3 ORDER BY id";
$presult = mysql_query($pquery);
while ($p = mysql_fetch_array($presult)) {
echo '<p>'.$p['name'];
t_select($p['templateid']);
echo '</p>';
}
$dquery = $query." id IN(3,4,5) ORDER BY id";
$dresult = mysql_query($dquery);
while ($d = mysql_fetch_array($dresult)) {
echo '<p>'.$d['name'];
t_select($d['templateid']);
echo '</p>';
}
// Categories and Articles
echo '<h3><strong>'.l('articles').'</strong></h3>';
echo '<p name="'.l('home').'">'.l('home');
t_select('Home');
echo '</p>';
$aquery = $query." position = 1 AND categoryid = 0";
$aresult = mysql_query($aquery);
while ($a = mysql_fetch_array($aresult)) {
echo '<p class="subcat">'.$a['name'];
t_select($a['templateid']);
echo '</p>';
}
$cquery = $query." categoryid > 0 AND position = -1 ORDER BY id";
$cresult = mysql_query($cquery);
while ($c = mysql_fetch_array($cresult)) {
echo '<p>'.$c['name'];
t_select($c['templateid']);
echo '</p>';
$artquery = $query." position = 1 AND categoryid = ".$c['categoryid']." ORDER BY id";
$artresult = mysql_query($artquery);
while ($art = mysql_fetch_array($artresult)) {
echo '<p class="subcat">'.$art['name'];
t_select($art['templateid']);
echo '</p>';
}
}
echo html_input('submit', 'save', 'save', l('save'), '', 'button', '', '', '', '', '', '', '', '', '');
echo '</fieldset></form>';
}
}

I have tried putting a name="name" in the paragraph tag where is shows the name: echo '<p>'.$d['name']; Then trying to return the POST value, but there is no value returned.

Also when I change multiple items, the POST data returns 1 item

BREAK IT DOWN FURTHER...
What I have:
Code: [Select]
<form method="post" action="index.php?action=process&amp;task=save_structure" id="post">
<p>itemName-A
   <select name = "strucID">
      <option value="1" selected="selected">Option1</option>
      <option value="2">Option2</option></select>
</p>
<p>itemName-B
   <select name = "strucID">
      <option value="1">Option1</option>
      <option value="2" selected="selected">Option2</option></select>
</p>
.. etc
<input type="submit" name="save" id="save" class="button" value="Save" />
</form>

This has me stumped as to how to return the POST data for each item and it's corresponding name.

When it is done, I would like it to go into the database:
Code: [Select]
mysql_query("UPDATE dbTable SET structureID = '$strucID' WHERE name = '$itemName';");
Everythign in-between is up in the air

« Last Edit: February 07, 2008, 12:09:36 PM by equilni »
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [WIP] Template Mod v2
« Reply #43 on: February 07, 2008, 12:19:59 PM »

Awakened now...
What a challenge, Jason!
This gonna be the ultimate template manager.
I wish I could help you, but,
you know...
yes: you know. ;)
Cheer on.
« Last Edit: February 07, 2008, 12:52:14 PM by Sven »
Logged

centered

  • Guest
Re: [WIP] Template Mod v2
« Reply #44 on: February 07, 2008, 12:29:46 PM »

Awakened now...
What a challenge, Jason!
This gonna be the ultimate template manager.
I wish I could you, but,
you know...
yes: you know. ;)
Cheer on.

Thanks, Actually the filed version of this will be the one everyone wants, that will be version 3 of this mod.  Pretty much it will be how Joost/Codetwist's mods are for multiple layouts, except instead of the template and css in the database, they will be in a templates folder.  Like Bakercad's template switcher, I will be able to get all php files and put them in a select box, then save the selected file to the db and call it up. 

Similar to this mod and bakercad's mod, v3 will have a sitewide checkbox to apply a template to the whole site.  I want to make this 'Structure' work so it can be included in v3. Since it will be a good part of this whole mod
« Last Edit: February 07, 2008, 12:34:09 PM by equilni »
Logged
Pages: 1 2 [3] 4