thabenksta
01-06-2005, 01:58 AM
I've been using vbadvanced for a few months, and boy do I love it! However, I've had one pet peeve that's bothered me for while and I decided to take care of it.
The one thing that should be the easiest thing to do in a CMS is add new content, IMO. And you can't just create a new thread every time you need a new page for the site, as that doesn't look professional. Vba CMPS has the ability to add new pages and modules, but IMO is cumbersome and non-intuitive. As most of you know, to add a new page you have to create a template under your style editor, and make that the custom content for the new page. Now this is not difficult, but IMO templates should be used as templates, and not content, and it would be nice to have everything under one admin section. I don't like the idea of filling up my style with content, and you should also be able to separate the template from the content.
So anyway, Here's what I did.
First I added a two fields to both the adv_modules, and adv_pages tables.
alter table adv_pages add content_title TEXT;
alter table adv_pages add content TEXT;
alter table adv_modules add content_title TEXT;
alter table adv_modules add content TEXT;
The idea is that you can have a title and the content, so you can create a template where the two are separate. It will become clearer later down the road.
Next I added a form to edit these fields. I put the next two blocks of code at the bottom of vba_cmps_admin.php.
// ######################## Edit Custom Content ############################
if ($_REQUEST['do'] == 'editcontent')
{
print_form_header('vba_cmps_admin', 'doeditcontent');
$content_title;
$content;
if ($_REQUEST['pageid']) {
$page = $DB_site->query_first("SELECT content_title, content FROM " . TABLE_PREFIX . "adv_pages WHERE pageid = '$_REQUEST[pageid]'");
construct_hidden_code('pageid', $_REQUEST['pageid']);
$content_title = $page['content_title'];
$content = $page['content'];
} elseif ($_REQUEST['modid']) {
$mod = $DB_site->query_first("SELECT content_title, content FROM " . TABLE_PREFIX . "adv_modules WHERE modid = '$_REQUEST[modid]'");
construct_hidden_code('modid', $_REQUEST['modid']);
$content_title = $mod['content_title'];
$content = $mod['content'];
}
print_table_header("Edit Content");
print_textarea_row("Content Title", "content_title", $content_title, "5", "70");
print_textarea_row("Content", "content", $content, "20", "70");
print_submit_row();
}
Then a block for storing in the database
// ######################## Do Edit Custom Content ############################
if ($_POST['do'] == 'doeditcontent')
{
if ($_POST[pageid]) {
$DB_site->query("UPDATE " . TABLE_PREFIX . "adv_pages SET content_title = '$_POST[content_title]',content = '$_POST[content]' WHERE pageid = '$_POST[pageid]'");
update_module_cache();
print_cp_redirect("vba_cmps_admin.php?$session[sessionurl]&do=listpages", 0);
} elseif ($_POST[modid]) {
$DB_site->query("UPDATE " . TABLE_PREFIX . "adv_modules SET content_title = '$_POST[content_title]',content = '$_POST[content]' WHERE modid = '$_POST[modid]'");
update_module_cache();
print_cp_redirect("vba_cmps_admin.php?$session[sessionurl]&do=listmodules", 0);
} else {
print_cp_redirect("vba_cmps_admin.php");
}
}
You'll notice that this will handle both pages and modules, based on whether you pass pageid or modid.
Now I needed a way to get to this form, so I added a button to the module editor.
In vba_cmps_admin.php about line 580, right before the "Active" radio buttons I added this.
print_label_row("Custom Content Editor", "<input type=button onclick=\"javascript:location='vba_cmps_admin.php?do=editcontent&modid=" . $mod['modid'] . "'\" value=\"Edit Content\">");
It doesn't really matter where you put it cause it's just a link to the content editor.
Then I decided it would be more convenient to have a link on the module listing. Around line 94, I change this line...
print_input_row('<span class="smallfont"><strong><a href="vba_cmps_admin.php?do=editmodule&modid=' . $column['modid'] . '">' . $column['title'] . '</a></strong></span>' . iif(!$column['active'], ' <div style="color:red;font-size:9px;font-weight:normal;">(' . $vbphrase['inactive'] . ')</div>') . '<div class="smallfont" style="margin-top:5px">' . $vbphrase['move_to'] . ': ' .
to this
print_input_row('<span class="smallfont"><strong><a href="vba_cmps_admin.php?do=editmodule&modid=' . $column['modid'] . '">' . $column['title'] . '</a> <a href="vba_cmps_admin.php?do=editcontent&modid=' . $column['modid'] . '" alt="Edit Content" title="Edit Content"> </a> </strong></span>' . iif(!$column['active'], ' <div style="color:red;font-size:9px;font-weight:normal;">(' . $vbphrase['inactive'] . ')</div>') . '<div class="smallfont" style="margin-top:5px">' . $vbphrase['move_to'] . ': ' .
which just puts a next to the title that links to the content form.
Then I needed a way to add content to the pages, so I added this at about line 713 to the end of the javascript switch statement.
case 'content':
page = 'vba_cmps_admin.php?do=editcontent&pageid=';
break;
and changed the hash at line 725 from
$diroptions = array(
'edit' => $vbphrase['edit'],
'remove' => $vbphrase['delete']
);
to
$diroptions = array(
'edit' => $vbphrase['edit'],
'remove' => $vbphrase['delete'],
'content' => 'Content'
);
This adds the "Content" option to the drop down on the page listing.
Now that I had the content saving part down all that's left is the output.
So I added the following block at around line 257 of vba_cmps_include_bottom.php...
$content_title = $mods['content_title'];
$content = $mods['content'];
and this around 270...
$content_title = $pages['content_title'];
$content = $pages['content'];
and should end up looking like ...
// Process Active Modules
if (is_array($modules))
{
foreach ($modules AS $mods)
{
if (in_array($mods['modid'], explode(',', $pages['modules'])))
{
$home[$mods['modid']]['displayorder'] = $mods['displayorder'];
$home[$mods['modid']]['column'] = $mods['modcol'];
$getbgrow = getrowcolor();
$content_title = $mods['content_title'];
$content = $mods['content'];
if ($mods['inctype'] == 0)
{
require_once('./modules/' . $mods['filename']);
}
else
{
if ($mods['identifier'] == 'custompage')
{
$content_title = $pages['content_title'];
$content = $pages['content'];
$cusid = $mods['modid'];
if ($pages['template'])
{
eval('$home[$mods[\'modid\']][\'content\'] = "' . fetch_template($pages['template']) . '";');
}
}
else
{
eval('$home[$mods[\'modid\']][\'content\'] = "' . fetch_template('adv_portal_' . $mods['filename']) . '";');
}
}
}
}
}
What this does is sets up the $content_title and $content variables so they could be used in the template. First it sets them up for a module, and then for the page if it's a custom page.
So, what this all does is allows me to setup a template that looks like the following...
<table>
<tr>
<td><b>$content_title</b></td>
</tr>
<tr>
<td>$content</td>
</tr>
</table>
Then I can create a page or module that uses this template and add content to it. Now the benifit is that I can now re-use the same template, and just create new content. All the content is mananged under the CMPS section, and the templates in the template section.
This may seem dumb to some of you, but it makes it easier for me and my co-admins to manage content. I'm not duplicating templates over and again, and I'm not cluttering up my style with content.
BTW: I'm using this on http://ipodstudio.com, as you can see, my module templates are complicated cause of the image border.
I hope someone else will find this useful.
-Ben
The one thing that should be the easiest thing to do in a CMS is add new content, IMO. And you can't just create a new thread every time you need a new page for the site, as that doesn't look professional. Vba CMPS has the ability to add new pages and modules, but IMO is cumbersome and non-intuitive. As most of you know, to add a new page you have to create a template under your style editor, and make that the custom content for the new page. Now this is not difficult, but IMO templates should be used as templates, and not content, and it would be nice to have everything under one admin section. I don't like the idea of filling up my style with content, and you should also be able to separate the template from the content.
So anyway, Here's what I did.
First I added a two fields to both the adv_modules, and adv_pages tables.
alter table adv_pages add content_title TEXT;
alter table adv_pages add content TEXT;
alter table adv_modules add content_title TEXT;
alter table adv_modules add content TEXT;
The idea is that you can have a title and the content, so you can create a template where the two are separate. It will become clearer later down the road.
Next I added a form to edit these fields. I put the next two blocks of code at the bottom of vba_cmps_admin.php.
// ######################## Edit Custom Content ############################
if ($_REQUEST['do'] == 'editcontent')
{
print_form_header('vba_cmps_admin', 'doeditcontent');
$content_title;
$content;
if ($_REQUEST['pageid']) {
$page = $DB_site->query_first("SELECT content_title, content FROM " . TABLE_PREFIX . "adv_pages WHERE pageid = '$_REQUEST[pageid]'");
construct_hidden_code('pageid', $_REQUEST['pageid']);
$content_title = $page['content_title'];
$content = $page['content'];
} elseif ($_REQUEST['modid']) {
$mod = $DB_site->query_first("SELECT content_title, content FROM " . TABLE_PREFIX . "adv_modules WHERE modid = '$_REQUEST[modid]'");
construct_hidden_code('modid', $_REQUEST['modid']);
$content_title = $mod['content_title'];
$content = $mod['content'];
}
print_table_header("Edit Content");
print_textarea_row("Content Title", "content_title", $content_title, "5", "70");
print_textarea_row("Content", "content", $content, "20", "70");
print_submit_row();
}
Then a block for storing in the database
// ######################## Do Edit Custom Content ############################
if ($_POST['do'] == 'doeditcontent')
{
if ($_POST[pageid]) {
$DB_site->query("UPDATE " . TABLE_PREFIX . "adv_pages SET content_title = '$_POST[content_title]',content = '$_POST[content]' WHERE pageid = '$_POST[pageid]'");
update_module_cache();
print_cp_redirect("vba_cmps_admin.php?$session[sessionurl]&do=listpages", 0);
} elseif ($_POST[modid]) {
$DB_site->query("UPDATE " . TABLE_PREFIX . "adv_modules SET content_title = '$_POST[content_title]',content = '$_POST[content]' WHERE modid = '$_POST[modid]'");
update_module_cache();
print_cp_redirect("vba_cmps_admin.php?$session[sessionurl]&do=listmodules", 0);
} else {
print_cp_redirect("vba_cmps_admin.php");
}
}
You'll notice that this will handle both pages and modules, based on whether you pass pageid or modid.
Now I needed a way to get to this form, so I added a button to the module editor.
In vba_cmps_admin.php about line 580, right before the "Active" radio buttons I added this.
print_label_row("Custom Content Editor", "<input type=button onclick=\"javascript:location='vba_cmps_admin.php?do=editcontent&modid=" . $mod['modid'] . "'\" value=\"Edit Content\">");
It doesn't really matter where you put it cause it's just a link to the content editor.
Then I decided it would be more convenient to have a link on the module listing. Around line 94, I change this line...
print_input_row('<span class="smallfont"><strong><a href="vba_cmps_admin.php?do=editmodule&modid=' . $column['modid'] . '">' . $column['title'] . '</a></strong></span>' . iif(!$column['active'], ' <div style="color:red;font-size:9px;font-weight:normal;">(' . $vbphrase['inactive'] . ')</div>') . '<div class="smallfont" style="margin-top:5px">' . $vbphrase['move_to'] . ': ' .
to this
print_input_row('<span class="smallfont"><strong><a href="vba_cmps_admin.php?do=editmodule&modid=' . $column['modid'] . '">' . $column['title'] . '</a> <a href="vba_cmps_admin.php?do=editcontent&modid=' . $column['modid'] . '" alt="Edit Content" title="Edit Content"> </a> </strong></span>' . iif(!$column['active'], ' <div style="color:red;font-size:9px;font-weight:normal;">(' . $vbphrase['inactive'] . ')</div>') . '<div class="smallfont" style="margin-top:5px">' . $vbphrase['move_to'] . ': ' .
which just puts a next to the title that links to the content form.
Then I needed a way to add content to the pages, so I added this at about line 713 to the end of the javascript switch statement.
case 'content':
page = 'vba_cmps_admin.php?do=editcontent&pageid=';
break;
and changed the hash at line 725 from
$diroptions = array(
'edit' => $vbphrase['edit'],
'remove' => $vbphrase['delete']
);
to
$diroptions = array(
'edit' => $vbphrase['edit'],
'remove' => $vbphrase['delete'],
'content' => 'Content'
);
This adds the "Content" option to the drop down on the page listing.
Now that I had the content saving part down all that's left is the output.
So I added the following block at around line 257 of vba_cmps_include_bottom.php...
$content_title = $mods['content_title'];
$content = $mods['content'];
and this around 270...
$content_title = $pages['content_title'];
$content = $pages['content'];
and should end up looking like ...
// Process Active Modules
if (is_array($modules))
{
foreach ($modules AS $mods)
{
if (in_array($mods['modid'], explode(',', $pages['modules'])))
{
$home[$mods['modid']]['displayorder'] = $mods['displayorder'];
$home[$mods['modid']]['column'] = $mods['modcol'];
$getbgrow = getrowcolor();
$content_title = $mods['content_title'];
$content = $mods['content'];
if ($mods['inctype'] == 0)
{
require_once('./modules/' . $mods['filename']);
}
else
{
if ($mods['identifier'] == 'custompage')
{
$content_title = $pages['content_title'];
$content = $pages['content'];
$cusid = $mods['modid'];
if ($pages['template'])
{
eval('$home[$mods[\'modid\']][\'content\'] = "' . fetch_template($pages['template']) . '";');
}
}
else
{
eval('$home[$mods[\'modid\']][\'content\'] = "' . fetch_template('adv_portal_' . $mods['filename']) . '";');
}
}
}
}
}
What this does is sets up the $content_title and $content variables so they could be used in the template. First it sets them up for a module, and then for the page if it's a custom page.
So, what this all does is allows me to setup a template that looks like the following...
<table>
<tr>
<td><b>$content_title</b></td>
</tr>
<tr>
<td>$content</td>
</tr>
</table>
Then I can create a page or module that uses this template and add content to it. Now the benifit is that I can now re-use the same template, and just create new content. All the content is mananged under the CMPS section, and the templates in the template section.
This may seem dumb to some of you, but it makes it easier for me and my co-admins to manage content. I'm not duplicating templates over and again, and I'm not cluttering up my style with content.
BTW: I'm using this on http://ipodstudio.com, as you can see, my module templates are complicated cause of the image border.
I hope someone else will find this useful.
-Ben