Delete from Frontend

Your code modifications and patches you want to share with others.
Locked
User avatar
silverfish
Joomla! Intern
Joomla! Intern
Posts: 56
Joined: Wed Aug 24, 2005 6:27 am

Delete from Frontend

Post by silverfish » Wed Sep 28, 2005 11:12 pm

I have modified two files and have created a "Trash" button on the front end so users can delete their own articles. If anyone is interested, the hack is posted below:

Open components\com_content\content.php and under this line:

Code: Select all

case 'save':
Add this line:

Code: Select all

// Trash hack
case 'remove':
    removeContent( $id, $sectionid, $option );
    break;
//End Trash hack
Then add this code after the 'SaveContent()" function, around line 1450

Code: Select all

// RemoveContent hack
function removeContent( $id, $sectionid, $option ) {
	global $database;

	$state = '-2';
	$ordering = '0';
	//seperate contentids
	
	$query = "UPDATE #__content"
	. "\n SET state = $state, ordering = $ordering"
	. "\n WHERE id = $id"
	;
	$database->setQuery( $query );
	if ( !$database->query() ) {
		echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
		exit();
	}

	$msg = $total ." Item(s) sent to the Trash";
	$return = mosGetParam( $_POST, 'returntask', '' );
	mosRedirect( 'index.php' );
}

// End Remove Content Hack

Save the file.

Now open includes\HTML_toolbar.php, add this code after the savenew() function. Around line 305.

Code: Select all

/**
	* Write a trash button that will move items to Trash Manager
	*/
	function trash () {
		$image = mosAdminMenus::ImageCheck( 'delete_f2.png', '/administrator/images/', NULL, NULL, 'Trash', 'remove', 1 );
		
			$js = "javascript:if (confirm('Are you sure you want to delete this item?')){ submitbutton('remove');}";
	
		
		?>
		 <td>
			<a class="toolbar" href="<?php echo $js; ?>">
				<?php echo $image; ?></a>
		</td>
		<?php
	}
Save the file.

Now open components\com_content\content.html.php. Add this code after mosToolBar::apply( 'apply_new' );

Code: Select all

// Add Trash button
mosToolBar::trash();
// End Trash Button
Your code should look like this for the toolbar:

Code: Select all

// Toolbar Top
mosToolBar::startTable();
mosToolBar::save();
mosToolBar::apply( 'apply_new' );
// Add Trash button
mosToolBar::trash();
// End Trash Button
mosToolBar::cancel();
mosToolBar::endtable();
Hope this helps people out.

Silver
Last edited by silverfish on Wed Sep 28, 2005 11:35 pm, edited 1 time in total.

User avatar
bijan
Joomla! Intern
Joomla! Intern
Posts: 51
Joined: Mon Aug 22, 2005 4:40 am
Contact:

Re: Delete from Frontend

Post by bijan » Tue Oct 04, 2005 11:34 am

thanks for sharing silverfish, but don't you think it's much better if you made a sort of tar.gz file that ppl could copy and paste over their existing files to see instantly what you did and then go for the details if they need it?

One more thing: users already can delete their own articles, you mean by implementing your work then they can't remove it completely and it only goes to trash?

One more more thing! Now that you modified this part of Joomla, it should be easy for you to remove the right of Authors to remove/change their articles. Because I wana set up a sort of PHP community web site in which users should be able to write articles, then I want the admin to be able to publish it if hel likes (which is already possible with Joomla) but then I don't want them to modify/remove their article after it's published, because it's a very big site with lots of visitors, and if they make any bad modification then my life is gonna be ruined! Of course this is only a request which I don't really mind if you say no to, coz I understand you have your own time and ...

User avatar
Tobias Eigen
Joomla! Intern
Joomla! Intern
Posts: 79
Joined: Thu Aug 18, 2005 4:50 pm
Location: Seattle, Washington USA
Contact:

Re: Delete from Frontend

Post by Tobias Eigen » Thu Oct 05, 2006 9:28 pm

Holy moly - this is terrific!!! Thank you so much for this hack. I very much hope this makes it into a future version of Joomla, just like the very wonderful MyContent component I just installed also.

Cheers,

Tobias
Kabissa - Space for Change in Africa
http://www.kabissa.org

User avatar
Tobias Eigen
Joomla! Intern
Joomla! Intern
Posts: 79
Joined: Thu Aug 18, 2005 4:50 pm
Location: Seattle, Washington USA
Contact:

Re: Delete from Frontend

Post by Tobias Eigen » Mon Oct 30, 2006 10:44 pm

This seems to have stopped working right on Joomla 1.0.11 - at least on my opensef system. Trashcan appears and works as advertised, but weirdly it also moves anything to the trash can when you hit the "save and exit" button. The "apply" button does not have this problem (so you can get around this by "applying" changes and then cancelling).

Any thoughts most welcomed! For now have reverted to pre-hack code.

Cheers,

Tobias
Kabissa - Space for Change in Africa
http://www.kabissa.org

ConseilsWeb
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sun Oct 15, 2006 9:48 pm

Re: Delete from Frontend

Post by ConseilsWeb » Thu Dec 14, 2006 3:57 pm

Tobias Eigen wrote: This seems to have stopped working right on Joomla 1.0.11 - at least on my opensef system. Trashcan appears and works as advertised, but weirdly it also moves anything to the trash can when you hit the "save and exit" button. The "apply" button does not have this problem (so you can get around this by "applying" changes and then cancelling).

Any thoughts most welcomed! For now have reverted to pre-hack code.

Cheers,

Tobias
That's because his installation procedure is wrong.

When he says:

Open components\com_content\content.php and under this line:

Code: Select all

case 'save':


I don't know why he said that, but it's kind of unclear if you're not a programmer. He actualy means after the first "break;" that you encounter. That's basic programming, but I guess you're not a programmer.

Anyways, here's what it should look like ( in 1.0.11 at least ):

Code: Select all

	case 'save':
	case 'apply':
	case 'apply_new':
		mosCache::cleanCache( 'com_content' );
		saveContent( $access, $task );
		break;

	// Trash hack
	case 'remove':
		removeContent( $id, $sectionid, $option );
		break;
	//End Trash hack

	case 'cancel':
		cancelContent( $access );
		break;

User avatar
silverfish
Joomla! Intern
Joomla! Intern
Posts: 56
Joined: Wed Aug 24, 2005 6:27 am

Re: Delete from Frontend

Post by silverfish » Thu Dec 14, 2006 6:12 pm

Thanks ConseilsWeb, That is exactly what I meant...  :-[

I meant after the case statement, at the break, I should have included all of the code within that statement for the non-programmers attempting to use this hack.

Thank you for taking the time to answer this post, its a community and I love it!

Silver

ConseilsWeb
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sun Oct 15, 2006 9:48 pm

Re: Delete from Frontend

Post by ConseilsWeb » Thu Dec 14, 2006 6:19 pm

No problem! I'm glad I can help.

BTW, nice hack! I thank you for it!

User avatar
brunoromulo
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Mon Mar 05, 2007 6:52 pm

Re: Delete from Frontend

Post by brunoromulo » Mon Mar 05, 2007 7:03 pm

hy my friends!!!

I apply this hack, but it is returning an error...

Fatal error: Call to undefined function removeContent() in C:\wamp\www\jauteste\components\com_content\content.php on line 106

HELP ME!!!  =)

thanks

hooo....

line 106 is

104. // Trash hack
105. case 'remove':
106. removeContent( $id, $sectionid, $option );
107. break;
108. //End Trash hack
Last edited by brunoromulo on Mon Mar 05, 2007 7:38 pm, edited 1 time in total.

User avatar
brunoromulo
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Mon Mar 05, 2007 6:52 pm

Re: Delete from Frontend

Post by brunoromulo » Mon Mar 05, 2007 7:52 pm

resolved...

Code: Select all

// RemoveContent hack
function removeContent( $id, $sectionid, $option ) {
global $database;

$state = '-2';
$ordering = '0';
//seperate contentids

$query = "UPDATE #__content"
. "\n SET state = $state, ordering = $ordering"
. "\n WHERE id = $id"
;
$database->setQuery( $query );
if ( !$database->query() ) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
exit();
}

$msg = $total ." Item(s) sent to the Trash";
$return = mosGetParam( $_POST, 'returntask', '' );
mosRedirect( 'index.php' );
}

// End Remove Content Hack
I copy code after the 'SaveContent()" function and returned error. Now move before  the 'SaveContent()' and ok


thanks!

tamathumper
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Nov 12, 2007 6:54 pm

Re: Delete from Frontend

Post by tamathumper » Mon Nov 12, 2007 6:57 pm

Thank you for this!  I'm not aware of any other way to do this without the hack, and it's a shame that it has to *be* a hack...  I'd like to see more options for users to control their own posts from the frontend.  This works perfectly :D

User avatar
jmelton98
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Sun Mar 09, 2008 4:48 pm

Re: Delete from Frontend

Post by jmelton98 » Sun Jul 06, 2008 1:52 am

Does this work for J1.5?

umneymedia
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Wed Aug 27, 2008 12:57 am

Re: Delete from Frontend

Post by umneymedia » Wed Aug 27, 2008 1:02 am

Hey Silverfish
That is awesome!! :D :D
Why this isn't there in the first place is beyond me.
A big Thankyou
Cheers
Tim

wicksy
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Tue Dec 11, 2007 7:51 am

Re: Delete from Frontend

Post by wicksy » Thu Sep 04, 2008 5:32 am

Does anyone know if there is something like that exists for J1.5?

nkitson
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Mon Nov 06, 2006 2:20 pm

Re: Delete from Frontend

Post by nkitson » Sat Sep 06, 2008 1:15 pm

Just to let everybody know that this hack still works in Joomla! 1.0.15 - many thanks to Silverfish for originally posting it.

Anybody got any suggestions as to how I could limit it to just publishers? I have several editors who I wouldn't want to accidentally delete any content item.

Taikonaut
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 213
Joined: Wed Sep 28, 2005 1:52 pm

Re: Delete from Frontend

Post by Taikonaut » Fri Oct 09, 2009 7:37 am

Hi everybody,

did anybody succeed to apply this hack to Joomla 1.5?

Thanks in advance!
Taiko.

User avatar
mark_up
Joomla! Guru
Joomla! Guru
Posts: 849
Joined: Sun Oct 29, 2006 10:51 am
Location: Fiji
Contact:

Re: Delete from Frontend

Post by mark_up » Fri Oct 09, 2009 8:09 am

I highly doubt a Joomla 1.0 hack will work in J1.5 as com_content has been completely rewritten.

You can do most of it with Ninja Content though.
http://twitter.com/mark_up.
Opinions expressed are mine alone and don't necessarily represent the views of any organisation I am associated with.

npolowski
Joomla! Apprentice
Joomla! Apprentice
Posts: 24
Joined: Tue Dec 29, 2009 11:35 pm

Re: Delete from Frontend

Post by npolowski » Tue Dec 29, 2009 11:49 pm

This might be naive on my part - but it seems so obvious to have this option to Joomla authors!

Has anyone found a (free) solution to have a "delete" button on a frontend article page?

chromie
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Thu Jan 08, 2009 2:44 am

Re: Delete from Frontend

Post by chromie » Thu Feb 11, 2010 5:16 am

Seriously now, nobody has a free solution for 1.5?

It seems like an obvious need to me!

User avatar
piotr_cz
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 164
Joined: Mon Mar 30, 2009 11:27 am
Location: Europe
Contact:

Re: Delete from Frontend

Post by piotr_cz » Fri Mar 26, 2010 8:47 am

npolowski wrote:This might be naive on my part - but it seems so obvious to have this option to Joomla authors!

Has anyone found a (free) solution to have a "delete" button on a frontend article page?
Just search trough Joomla Extension Directory.
I'm probably gonna check out Article Deleter Module.

mattfaulds
Joomla! Apprentice
Joomla! Apprentice
Posts: 34
Joined: Tue May 27, 2008 10:12 am

Re: Delete from Frontend

Post by mattfaulds » Tue Dec 14, 2010 9:38 am

Hi

You might be interested to have a look at TD Frontend Delete


Locked

Return to “Core Hacks and Patches”