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'] . ": </td>";
$html .= "<td valign=\"top\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
$html .= "<tr>";
$html .= "<td class=\"chatlist\">" . $BL['be_article_forlist'] . ": </td>";
$html .= "<td><img src=\"img/leer.gif\" width=\"10\" height=\"1\"></td>";
$html .= "<td class=\"chatlist\">" . $BL['be_article_forfull'] . ": </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> </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]