Submit Hack
Written by Ted Tieken
[email protected] or [email protected]
Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
I make no guarantees, warrantees, or anything of the sort about the performance of this hack.
To use this hack, add a link to your user menu that points to:
/index.php?option=content&task=submitnew
Or
/index.php?option=content&task=submitnew_shownp
The only difference is that the first will only show published sections and the second will show both published and unpublished sections.
NOTE: If a section has no categories (and thus you can not add content to it from the frontend) it is not shown. This is intentional.
There are 3 code additions that need to be made in the content display code.
1. in com_content/content.php
2. in com_content/content.php
3. in com_content/content.html.php
STEP 1
1. Add the following cases/code to the switch(task) fn in content.php (line 88 for me)
Code: Select all
/*Added by Ted Tieken August 5, 2004 to allow dynamic choice in which section to submit new content*/
case "submitnew_shownp":
submitnewItem ($access, 1);
break;
case "submitnew":
submitnewItem ($access, 0);
break;
/* End Hack */
STEP 2
2. Add the following function at the end of content.php
Code: Select all
/*********
/* Submit Content Hack
/* created so that a dynamic choice of section is presented
/* dynamic choice of category within the section is given on the second page
/* Written by Ted Tieken [email protected] or [email protected]
/*
*/
function submitnewItem($access, $shownp){
global $database;
if (!($access->canEdit || $access->canEditOwn)) {
mosNotAuth();
return;
}
/*Get list of published section idnumbers*/
$database->setQuery( "SELECT s.id AS `value`"
. "\nFROM #__sections AS s"
. "\nWHERE s.scope='content'"
. "AND s.published='1'"
. "\nORDER BY s.name"
);
$idnums = $database->loadObjectList();
/*get published section names*/
$database->setQuery( "SELECT s.name AS `value`"
. "\nFROM #__sections AS s"
. "\nWHERE s.scope='content'"
. "AND s.published='1'"
. "\nORDER BY s.name"
);
$snames = $database->loadObjectList();
/* put published section names into idnums array*/
$num = count ($idnums);
for ($i = 0; $i < $num; $i++) {
$idnums[$i]->name = $snames[$i]->value;
/* keep a temp so we can add Published and non published info*/
$temp[$i] = $idnums[$i];
}
$idnums[0]->name = "------Published Sections------";
$idnums[0]->value = NULL;
for ($i = 0; $i < $num; $i++) {
$idnums[$i + 1] = $temp[$i];
}
if ($shownp) {
/*Get list of unpublished sections*/
$database->setQuery( "SELECT s.id AS `value`"
. "\nFROM #__sections AS s"
. "\nWHERE s.scope='content'"
. "AND s.published !='1'"
. "\nORDER BY s.name"
);
$npidnums = $database->loadObjectList();
/*get unpublished section names*/
$database->setQuery( "SELECT s.name AS `value`"
. "\nFROM #__sections AS s"
. "\nWHERE s.scope='content'"
. "AND s.published !='1'"
. "\nORDER BY s.name"
);
$npsnames = $database->loadObjectList();
/* put un published section names into npidnums array*/
$num = count ($npidnums);
for ($i = 0; $i < $num; $i++) {
$npidnums[$i]->name = $npsnames[$i]->value;
}
/*Verify that the unpublished sections have categories*/
/*This is necessary because if it doesn't have a category we will get an error in the next step */
/*Get a list of the sections that have categories */
/*Ask, what is the section (parent) of this category and check that it is a number*/
$database->setQuery( "SELECT c.section AS `value`"
. "\nFROM #__categories AS c"
. "\nWHERE c.section + 0 != '0'"
. "\nORDER BY c.section"
);
$npcatsect = $database->loadObjectList();
/*Compare the lists*/
/*after this, if there is a category in the section then the counter array will be other than 0 */
$inum = count($npidnums);
$knum = count($npcatsect);
$areunpub = 0;
for ($i = 0; $i < $inum; $i++){
$counter[$i] = 0;
for ($k = 0; $k < $knum; $k++){
if ($npidnums[$i]->value == $npcatsect[$k]->value) {
$counter[$i]++;
$areunpub++;
}
}
}
/*So we don't end up with an identifier but no sections*/
if ($areunpub) {
$already = count($idnums);
$idnums[$already]->value = NULL;
$idnums[$already++]->name = "";
$idnums[$already]->value = NULL;
$idnums[$already++]->name = "------Unpublished Sections------";
/*Create new array with only the desired fields*/
$nm = 0;
for ($i = 0; $i < $inum; $i++) {
if ($counter[$i]) {
$idnums[$already++] = $npidnums[$i];
}
}
}
}
/* Create the html for our list */
$size = (count($idnums) <= 10 ? count($idnums) : 10);
$slist = mosHTML::selectList( $idnums, 'sectionid', 'class="inputbox" size="' . $size . '"','value', 'name', 'none');
submitnew( $slist, $shownp );
}
/* End Hack */
STEP 3
3. Add this function to the end of content.html.php (that is .HTML.)
Code: Select all
<?php
/***
/* Creates the HTML to allow for dynamic section selection when submitting content from the frontent
/* Code written by Ted Tieken August 5, 2004
/* Inputs: slist - a formated list of sections,
/* shownp - a true/false - if nonpublished sections are shown
/****/
function submitnew ($slist, $shownp) {
?>
<script language="javascript">
<!--
function check( form ) {
if (document.adminForm.sectionid.value == "" || document.adminForm.sectionid.value == "0") {
alert('Please select a section.');
} else {
document.adminForm.submit();
}
}
//-->
</script>
<form name="adminForm">
<input type="hidden" name="option" value="content" />
<input type="hidden" name="task" value="new" />
<table cellpadding="4" cellspacing="0" border="0" width="100%">
<tr>
<td colspan="2">Please select a section in which to add content and press Next.</td>
</tr>
<tr>
<td width="20%" align="left" valign="top">Select a Section:</td>
<td width="80%"> <?php echo $slist;?> </td>
</tr>
<input type="hidden" name="Itemid" value="0" />
<tr>
<td width="20%"></td>
<td width="80%" align="left">
<input type="button" value="Next" onClick="check(this.form);" class="button" />
</td>
</tr>
<?php
if ($shownp) {
echo "<tr></tr>
<tr>
<td colspan="2">NOTE: If a section does not yet have a category it is not shown. If the section in which you would like to add content is not shown, please add a category to that section or contact the site administrator for help.</td>
</tr>";
} else {
echo "<tr></tr>
<tr>
<td colspan="2">NOTE: If a section is not published it is not shown. If the section in which you would like to add content is not shown, please publish it or contact the site administrator for help.</td>
</tr>";
}
?>
</table>
</form>
<?php
}
?>