Default article as .tmpl
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
Cheers,
Jens
so JensZ you cancel to work on something?
http://www.studmed.dk Portal for doctors and medical students in Denmark
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.
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
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.
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
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
2. Find original line 156:
Insert the following after the above:
3. Comment (or delete) the original lines 169 and 170
4. Find original line 174:
Insert the following after the above:
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,
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:
Btw, thank you Oliver for phpwcms!
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";
Code: Select all
if($val == $article['image']['tmpllist']) $vals= ' selected="selected"';
Code: Select all
elseif($article['image']['tmpllist'] == '' || $article['image']['tmpllist'] == 'default') {
if($val == 'default.tmpl') $vals= ' selected="selected"';
}
Code: Select all
// if($article['image']['tmplfull'] == 'default') $vals= ' selected="selected"';
// echo '<option value="default"'.$vals.'>'.$BL['be_cnt_default']."</option>\n";
Code: Select all
if($val == $article['image']['tmplfull']) $vals= ' selected="selected"';
Code: Select all
elseif($article['image']['tmplfull'] == '' || $article['image']['tmplfull'] == 'default') {
if($val == 'default.tmpl') $vals= ' selected="selected"';
}
Code: Select all
elseif($article['image']['tmpllist'] == '') {
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);
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:
Replace above code with:
In admin.templates.tmpl.php, find:
After add:
In admin.templates.tmpl.php find:
After add:
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:
In article.editsummary.tmpl.php, find:
Replace above with:
At the very end of article.editsummary.tmpl, add the following:
That's it! Hope it works.
Cheers,
Jens[/code]
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" => '' );
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] ---
Code: Select all
if(isset($_POST["template_id"])) {
// read the create or edit template form data
Code: Select all
//--- added by jens [start] --------
$template["tmpllist"] = slweg($_POST["template_tmpllist"]);
$template["tmplfull"] = slweg($_POST["template_tmplfull"]);
//--- added by jens [end] ----------
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>
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] ---
?>
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] ------
Code: Select all
<td><select name="article_cid" id="article_cid" style="width: 325px" class="f11b">
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 -->
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] ---
?>
Cheers,
Jens[/code]
Hi Jensz,
will try it, I'll keep you informed
Thx
Cheers
will try it, I'll keep you informed
Thx
Cheers
1.3 out, testing, testing...
Sponsoring 4 phpwcms Blog and Usermanagement
Sponsoring 4 phpwcms Blog and Usermanagement
can some one summeries the advantage with these changes?
Im not sure if I get it :S
Im not sure if I get it :S
http://www.studmed.dk Portal for doctors and medical students in Denmark
Hi Frold,
To me, this is what seems the essential of JensZ post:
Cheers,
To me, this is what seems the essential of JensZ post:
Sounds like a nice improvement.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.
Cheers,
PhpWCMS Evangelist, -- iRoutier.com Running phpWCMS 1.4.2, r354 -> Great Version!!!!