Default article as .tmpl

Use GitHub to post feature requests for phpwcms.
JensZ
Posts: 136
Joined: Wed 16. Feb 2005, 12:18
Location: Stockholm, Sweden
Contact:

Post by JensZ »

Ok, my bad. I thought it was a project Oliver started, based on phpwcms. Anyway, the idea of xml for templates and whatever should be considered, as it is a very flexible tool. Flexibility is great, but at the same time it is important to keep the foundation of phpwcms, which is simplicity. A nice plugin architecture wouldn't be bad though, since it is not desirable to make changes to core files as would be needed make the changes suggested in this thread.

Cheers,

Jens
frold
Posts: 2151
Joined: Tue 25. Nov 2003, 22:42

Post by frold »

so JensZ you cancel to work on something?
http://www.studmed.dk Portal for doctors and medical students in Denmark
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

Hi JensZ,

Thanks for reading and responding to this thread. I think the issue that Kosse originally posted (and my thread elsewhere on boards) is a really valid point. In my discussion with a couple of other members of forums....there seems to be some agreement that the ablity to control 'the preselection of list and full article template defaults' ) is for this reason......

namely to keep things simple for the client. :D

So essentially this is something of a usability issue....namely when client creates a new article, the defaults (created and set up by developer) are implemented.

In the words of Kosse:

"The reason? Well, mainly because people who take care of their website always (or many times) forget to choose the template display:"

That is why I, for one, would like to see this implemented. I am guessing that OliG is inundated with work (nothing new) and if anyone in the forums could do a rock solid job of modifications....it would be you. Very much in respect of your grasp of Wcms. So just posting this comment. Not sure if you have the time to devote to this... but this feature, among all the other feature requests I have reviewed (imo) would be number one on my list.

All best,
John :D
TomC
Posts: 3
Joined: Tue 13. Sep 2005, 15:32
Location: Ontario, Canada

Post by TomC »

The following is just one suggestion to consider, but I'm not much of a programmer. This will get rid of the duplicate "Default" item in the template dropdown list (less confusion for end-users), so that only "default.tmpl" is used when creating a new article. Like pSouper previously said, you will still need to touch existing articles to correct the database (unless someone feels like creating some code to one-time globally modify the "article_image" field in the database from Default to default.tmpl). I'm using 1.2.5-DEV.

Open: ~\include\inc_tmpl\article.editsummary.tmpl.php

1. Comment (or delete) the original lines 147-152

Code: Select all

// if($article['image']['tmpllist'] == 'default') {
//     $vals= ' selected="selected"';
// } else {
//     $vals = '';
// }
// echo '<option value="default"'.$vals.'>'.$BL['be_cnt_default']."</option>\n";
2. Find original line 156:

Code: Select all

       if($val == $article['image']['tmpllist']) $vals= ' selected="selected"';
Insert the following after the above:

Code: Select all

       elseif($article['image']['tmpllist'] == '' || $article['image']['tmpllist'] == 'default') {
           if($val == 'default.tmpl') $vals= ' selected="selected"';
       }
3. Comment (or delete) the original lines 169 and 170

Code: Select all

// if($article['image']['tmplfull'] == 'default') $vals= ' selected="selected"';
// echo '<option value="default"'.$vals.'>'.$BL['be_cnt_default']."</option>\n";
4. Find original line 174:

Code: Select all

       if($val == $article['image']['tmplfull']) $vals= ' selected="selected"';
Insert the following after the above:

Code: Select all

       elseif($article['image']['tmplfull'] == '' || $article['image']['tmplfull'] == 'default') {
           if($val == 'default.tmpl') $vals= ' selected="selected"';
       }
Once you are sure that you have touched all your articles, then you don't need to keep checking for the original 'Default' template anymore, so you can shorten the two "elseif" lines....but this is optional. For example,

Code: Select all

       elseif($article['image']['tmpllist'] == '') {
Please note, the one thing that the above changes will still not watch out for is if someone happens to rename one of your .tmpl files once they have been set for some of your articles. So if you went to edit one of your articles afterwards then the article would falsely "appear" to be using whatever template first appears in the template dropdown list. I'm not sure if that scenario is something we should be too concerned about coding for. Should we?

Lastly, if you'd like the templates listed in the dropdown list to appear in alphabetical order, then:

Open: ~\include\inc_lib\general.inc.php

Insert the following line below line 929:

Code: Select all

     natcasesort($fa);
Btw, thank you Oliver for phpwcms!
JensZ
Posts: 136
Joined: Wed 16. Feb 2005, 12:18
Location: Stockholm, Sweden
Contact:

Post by JensZ »

OK, here it is.

This code makes it possible to set default article templates on the page template screen. However, it does not store the default article template in a file (default.tmpl). I suggest you use TomC's post for that. When creating a new article, this enhancement will make sure that article templates default to what is set up in the page template of the article category that the article is created in.

Only two files had to be changed: admin.templates.tmpl.php and article.editsummary.tmpl.php.

In admin.templates.tmpl.php, find:

Code: Select all

$template = array(	"name" => '', "default" => 0, "layout" => '', "css" => '', "htmlhead" => '',
					"jsonload" => '', "headertext" => '', "maintext" => '', "footertext" => '', 
					"lefttext" => '', "righttext" => '', "errortext" => '' );
Replace above code with:

Code: Select all

//--- changed by jens for default article templates [start] ---
$template = array(	"name" => '', "default" => 0, "layout" => '', "css" => '', "htmlhead" => '',
					"jsonload" => '', "headertext" => '', "maintext" => '', "footertext" => '', 
					"lefttext" => '', "righttext" => '', "errortext" => '',
					"tmpllist" => '', "tmplfull" => ''
					);
//--- changed by jens for default article templates [end] ---

In admin.templates.tmpl.php, find:

Code: Select all

if(isset($_POST["template_id"])) {
// read the create or edit template form data
After add:

Code: Select all

//--- added by jens [start] --------
$template["tmpllist"]		= slweg($_POST["template_tmpllist"]);
$template["tmplfull"]		= slweg($_POST["template_tmplfull"]);
//--- added by jens [end] ----------
In admin.templates.tmpl.php find:

Code: Select all

if($opt) {
	echo '<select name="template_layout" class="f11b" id="template_layout" style="width:365px"'.$jsOnChange.'>'."\n";
	echo $opt;
	echo '</select>';
} else {
	echo $BL['be_admin_tmpl_nolayout'].' (<a href="phpwcms.php?do=admin&p=8&s=0">'.$BL['be_admin_page_add'].'</a>)';
}

?></td>
	</tr>


After add:

Code: Select all

<?php  
	//--- php block added by jens 2005-10-11 [start] ---
	$html = "<tr bgcolor=\"#E6EAED\"><td colspan=\"2\"><img src=\"img/leer.gif\" width=\"1\" height=\"8\"></td></tr>";
	$html .= "<tr bgcolor=\"#E6EAED\">";
	$html .= "<td align=\"right\" class=\"chatlist\" valign=\"top\">" . $BL['be_admin_struct_template'] . ":&nbsp;</td>";
	$html .= "<td valign=\"top\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
	$html .= "<tr>";
	$html .= "<td class=\"chatlist\">" . $BL['be_article_forlist'] . ":&nbsp;</td>";
	$html .= "<td><img src=\"img/leer.gif\" width=\"10\" height=\"1\"></td>";
	$html .= "<td class=\"chatlist\">" . $BL['be_article_forfull'] . ":&nbsp;</td>";
	$html .= "</tr>";
	$html .= "<tr><td colspan=\"3\"><img src=\"img/leer.gif\" width=\"1\" height=\"2\"></td></tr>";
	$html .= "<tr>\n";
	$html .= "<td>\n<select name=\"template_tmpllist\" id=\"template_tmpllist\" style=\"width: 215px\" class=\"f11\">";
	
	// templates for article listing
	$tmpllist = get_tmpl_files(PHPWCMS_TEMPLATE.'inc_cntpart/articlesummary/list');
	$vals = ($template['tmpllist'] == 'default' ? ' selected="selected"' : '');
	$html .= '<option value="default"'.$vals.'>'.$BL['be_cnt_default']."</option>\n";
	if(count($tmpllist)) 
	{
		foreach($tmpllist as $val) 
		{
			$vals = '';
			if($val == $template['tmpllist']) $vals= ' selected="selected"';
			$val = htmlspecialchars($val);
			$html .= '<option value="'.$val.'"'.$vals.'>'.$val."</option>\n";
		}
	}
				  
	$html .= "</select>\n</td>\n";
	$html .= "<td>&nbsp;</td>";
	$html .= "<td><select name=\"template_tmplfull\" id=\"template_tmplfull\" style=\"width: 215px\" class=\"f11\">";
	
	// templates for full article
	$tmpllist = get_tmpl_files(PHPWCMS_TEMPLATE.'inc_cntpart/articlesummary/article');
	if($template['tmplfull'] == 'default') $vals= ' selected="selected"';
	$html .= '<option value="default"'.$vals.'>'.$BL['be_cnt_default']."</option>\n";
	if(count($tmpllist)) 
	{
		foreach($tmpllist as $val) 
		{
			$vals = '';
			if($val == $template['tmplfull']) $vals= ' selected="selected"';
			$val = htmlspecialchars($val);
			$html .= '<option value="'.$val.'"'.$vals.'>'.$val."</option>\n";
		}
	}
				  
	$html .= "</select></td>";
	$html .= "</tr></table></td></tr>";
	echo $html;
	//--- php block added by jens 2005-10-11 [end] ---
?>

That is it for admin.templates.tmpl.php. Let's continue with article.editsummary.tmpl.php:

In article.editsummary.tmpl.php, add the following right after the copyright notice:

Code: Select all

//--- added by jens for default article templates [start] ------
$template = array( "name" => '', "default" => 0, "layout" => '', "css" => '', "htmlhead" => '',
					"jsonload" => '', "headertext" => '', "maintext" => '', "footertext" => '', 
					"lefttext" => '', "righttext" => '', "errortext" => '',
					"tmpllist" => '', "tmplfull" => ''
					);
$templates = array();
					
// read the given template datas from db
$sql = "SELECT acat.acat_id, tmpl.template_id, tmpl.template_var FROM ".DB_PREPEND."phpwcms_articlecat acat ";
$sql .= "INNER JOIN ".DB_PREPEND."phpwcms_template tmpl ON acat.acat_template=tmpl.template_id ";
$sql .= "WHERE acat.acat_trash=0 ORDER BY acat.acat_id;";
if($result = mysql_query($sql, $db)) 
{
	while($row = mysql_fetch_assoc($result)) 
	{
		unset($template);
		$template = unserialize($row["template_var"]);
		$template["id"] = $row["template_id"];
		$template["acat_id"] = $row["acat_id"];
		$templates[$template["acat_id"]] = $template;
	}
	mysql_free_result($result);
}
?>

<script language="javascript">
	var tmplListXref = new Array();
	var tmplFullXref = new Array();
	tmplListXref[0] = 'default';
	tmplFullXref[0] = 'default';
	
<?php
foreach($templates as $key => $value)
{
	echo "tmplListXref[".$templates[$key]["acat_id"]."]=".(empty($templates[$key]["tmpllist"]) ? "'default'" : "'".$templates[$key]["tmpllist"]."'").";\n";
	echo "tmplFullXref[".$templates[$key]["acat_id"]."]=".(empty($templates[$key]["tmplfull"]) ? "'default'" : "'".$templates[$key]["tmplfull"]."'").";\n";
}
?>

function changeTmpl(articleTmpl, xref)
{
	var acatObj = document.getElementById("article_cid");
	var obj = document.getElementById(articleTmpl);
	var acatValue = acatObj[acatObj.selectedIndex].value;
	var value = xref[acatValue];
	for(var i = 0; i < obj.length; i++)
	{
		if(value == obj[i].value)
		{
			obj.selectedIndex = i;
			break;
		}
	}
}
</script>
<?php
//--- added by jens for default article templates [end] ------

In article.editsummary.tmpl.php, find:

Code: Select all

<td><select name="article_cid" id="article_cid" style="width: 325px" class="f11b">
Replace above with:

Code: Select all

<td><select name="article_cid" id="article_cid" style="width: 325px" class="f11b" onchange="changeTmpl('article_tmpllist', tmplListXref);changeTmpl('article_tmplfull', tmplFullXref);"><!-- changed by jens -->
At the very end of article.editsummary.tmpl, add the following:

Code: Select all

<?php 
//--- added by jens for default article templates [start] ---
// if the article templates have not been set, use the default
if(empty($article['image']['tmpllist']))
{
?>
<script language="javascript">
	changeTmpl('article_tmpllist', tmplListXref);
</script>
<?php
}
if(empty($article['image']['tmplfull']))
{
?>
<script language="javascript">
	changeTmpl('article_tmplfull', tmplFullXref);
</script>
<?php
}
//--- added by jens for default article templates [end] ---
?>
That's it! Hope it works.


Cheers,

Jens[/code]
User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Post by Kosse »

Hi Jensz,

will try it, I'll keep you informed ;)
Thx

Cheers
frold
Posts: 2151
Joined: Tue 25. Nov 2003, 22:42

Post by frold »

can some one summeries the advantage with these changes?

Im not sure if I get it :S
http://www.studmed.dk Portal for doctors and medical students in Denmark
User avatar
StudioZ
Posts: 802
Joined: Fri 28. May 2004, 19:57
Location: Québec, Canada
Contact:

Post by StudioZ »

Hi Frold,
To me, this is what seems the essential of JensZ post:
When creating a new article, this enhancement will make sure that article templates default to what is set up in the page template of the article category that the article is created in.
Sounds like a nice improvement.
Cheers,
Image
PhpWCMS Evangelist, -- iRoutier.com Running phpWCMS 1.4.2, r354 -> Great Version!!!!
Locked