Page 1 of 1

Hack: Submit content via frontend to any section/category with one menu link

Posted: Mon Sep 19, 2005 1:31 am
by cronlin
This is a nice little hack written by Ted Tieken that will allow you to have one link in your frontend for users to submit content from, in which they can not only select the section but category right there... this is an awesome addition, as it prevents a person from having tons of links for submissions based upon the separate categories... I am running it in joomla 1.0.0 and was using it 4.5.2.3, so it works in both.

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
   
}
?>

Re: Submit content via frontend to any section/category with one menu link

Posted: Fri Sep 23, 2005 7:14 pm
by Ottobufonto
that is cool. loving it...

only doesn't work with SEO /SEF activated... any idea how to fix that?

edit: using Joomla 1.0.1 with 404SEF...

otto

Re: Submit content via frontend to any section/category with one menu link

Posted: Sat Sep 24, 2005 12:27 am
by Ottobufonto
ha - found it...

posted by J Reyven on mamboforge as bug (fix) / workaround to use it with SEF enabled...

to fix SEO/SEF

IN STEP 3 ....

AFTER LINE:

function submitnew ($slist, $shownp) {

ADD:

global $mosConfig_live_site, $Itemid;
$link = sefRelToAbs( 'index.php?option=com_content&task=new&sectionid='. $id .'&cid='. $row->id
.'&Itemid='. $Itemid );

AND LOWER (few lines down) CHANGE:



TO:



this fix just adds the full url to the form address, using Mambo's own SEF method of "sefRelToAbs" function

Re: Submit content via frontend to any section/category with one menu link

Posted: Wed Sep 28, 2005 6:54 pm
by jpipitone
Hey all - great hack! works awesome...

Only thing is, it seems that the string -------Published Sections--------- is being printed twice on screen - I've attached a screen shot - any ideas why?

I'm running IIS 6 with PHP 5.0.5 - would this be the culprit?

Re: Submit content via frontend to any section/category with one menu link

Posted: Wed Sep 28, 2005 11:09 pm
by Ottobufonto
again from mamboforge bug tracker...

to fix double "------Published Sections------" in list....
( actually, this removes it all together) ,
(but the 2nd "Published Sections" line is actually
one of your real categories, renamed!)
to fix... do the following:

IN STEP 2, comment out, ( add the /* before, and */ after the
section of code)

/* $idnums[0]->name = "------Published
Sections------";
$idnums[0]->value = NULL;
for ($i = -1; $i < $num; $i++) {
$idnums[$i + 1] = $temp[$i];
} */

Re: Hack: Submit content via frontend to any section/category with one menu lin

Posted: Mon Jul 17, 2006 6:58 pm
by cronlin
Just out of curiosity, is anyone using this hack for joomla 1.0.10? 

I of course now have the latest version, it's a new website.... and I have followed it exactly (of course after doing it before... I know pretty much what to do) and this is the error that I'm receiving:

Fatal error: Call to undefined function: submitnewitem() in /home/vhosts/battered-but-better.110mb.com/public_html/joomla/components/com_content/content.php on line 127

and what's great about that is that line 127 is completely blank

case 'edit':
editItem( $id, $gid, $access, 0, $task, $Itemid );
break;
<------  Line 127 ------>
case 'new':
editItem( 0, $gid, $access, $sectionid, $task, $Itemid );
break;


This error does not change even after adding the SEO/SEF  fix as shown below.

Then again, for some reason I can't even add new menu links through my administration backend.... I receive this error:

Fatal error: Allowed memory size of 4194304 bytes exhausted (tried to allocate 41 bytes) in /home/vhosts/battered-but-better.110mb.com/public_html/joomla/includes/domit/xml_domit_lite_parser.php on line 324

All that's on line 324 is this:

} //onLoad

/**
* Clears previousSibling, nextSibling, and parentNode references from a node that has been removed
*/
function clearReferences() {
    if ($this->previousSibling != null) {
        unset($this->previousSibling);
        $this->previousSibling = null;
    }
    if ($this->nextSibling != null) {
            unset($this->nextSibling);
        $this->nextSibling = null;
    }
    if ($this->parentNode != null) {
            unset($this->parentNode);
        $this->parentNode = null;
    }
}


I'm so out of practice with joomla and php right now that I'm staring at this like a complete noob! Any ideas would be very helpful... after all, I LOVE this hack.

Re: Hack: Submit content via frontend to any section/category with one menu lin

Posted: Mon Jul 17, 2006 7:21 pm
by Ottobufonto
Funny that you are posting this today...

I opened a new topic under "core hacks adn patches" asking same question...

In my case I don't have errors but I get "You are not authorized to view this resource" when trying to submit content.

Re: Hack: Submit content via frontend to any section/category with one menu link

Posted: Mon Jul 17, 2006 7:36 pm
by cronlin
omg! i had that problem once before, but I can't remember what it took to fix it.  I'll look around and see if I can find the solution to it for you though! :D

Re: Hack: Submit content via frontend to any section/category with one menu lin

Posted: Mon Jul 17, 2006 7:52 pm
by Ottobufonto
that would be cool.

Not sure I can help with your issue. but when looking at my content.php file line 127 is in the next function...
On my system this empty line is line 88.

are you sure you did the mod correctly?

Re: Hack: Submit content via frontend to any section/category with one menu link

Posted: Tue Jul 18, 2006 6:21 am
by cronlin
Ottobufonto wrote:that would be cool.

Not sure I can help with your issue. but when looking at my content.php file line 127 is in the next function...
On my system this empty line is line 88.

are you sure you did the mod correctly?



yep, did the mod correctly... now it's doing something else to me.... i completely re-installed on a new server to see how it worked there.... now it just redirects me to another page of my host's.... weird

Re: Hack: Submit content via frontend to any section/category with one menu lin

Posted: Wed Jul 19, 2006 1:52 pm
by J-bugman
Have you tried this?

http://joomlicious.com/index.php?option ... &Itemid=33

Does the same thing :-) and works in .10

J

Re: Hack: Submit content via frontend to any section/category with one menu lin

Posted: Wed Jul 19, 2006 2:31 pm
by Ottobufonto
thanks for the suggestion..

I had a look at mycontent - and maybe with a bit of layout rework - like moving the actual content submit part above the link list... this might work.

I did however find a hack that solves my orginal "you're not authorized" problem...

http://joomlicious.com/index.php?option ... topic=43.0

what i'd raeally like is a mycontent with an admin backend like ja submit where I can define autosubmit sections.....

Re: Hack: Submit content via frontend to any section/category with one menu lin

Posted: Thu Aug 03, 2006 10:44 pm
by Poor_Knight
Thanks for this info. I took over a site that was using this hack and didn't realize it. Was no good after an upgrade but this thread helped me put it back together again :)

Error logging onto the administration page

Posted: Wed Aug 09, 2006 12:25 pm
by 4bees
Thanks for the tut and all the follow up comments. I have managed to get Joomla installed using the original tutorial and can see the Joomla front page, however when I try to log onto the administration page, it keeps returning to the same login page with an error at the top saying ' You need to login'.

According to the final page of the installation, my login and password were both admin. But they seem to not be working?

Any ideas?  ???

Re: Hack: Submit content via frontend to any section/category with one menu lin

Posted: Wed Aug 09, 2006 12:33 pm
by 4bees
Sorry that last post is in the wrong topic sorry  :-[

Re: Hack: Submit content via frontend to any section/category with one menu lin

Posted: Thu Oct 19, 2006 12:46 am
by mookie_jam
any actualization to this?  :-\

Re: Hack: Submit content via frontend to any section/category with one menu link

Posted: Tue Oct 24, 2006 12:23 am
by cronlin
I can't seem to get this hack to work in Joomla 1.0.11, but I have discovered a nice component that will basically allow the same thing.  It's called My Content, which not only allows the user to submit new content into whichever section/category that is currently available to them, it also shows every content item that they have submitted. If anyone's interested, here's the link : http://extensions.joomla.org/component/ ... Itemid,35/

and I am currently using it on my site with no problems at all.