# Forums | Mahara Community

## Developers / deleting wall post

Posts: 10

23 April 2009, 5:07 AM

Hi

I have code something to add deleting post function to the wall. After some test it's seem to be ok

In blocktype/wall

-create deletepost.php  with this:

<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
* @package    mahara
* @subpackage interaction
* @author     Catalyst IT Ltd
* @copyright  (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/

define('INTERNAL', 1);
define('PUBLIC', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('view.php');
safe_require('blocktype', 'wall');

$instance = param_integer('instance');$return = param_alpha('return');

//validation
$form = pieform(array( 'name' => 'deletepost', 'renderer' => 'div', 'autofocus' => false, 'elements' => array( 'title' => array( 'value' => get_string('deletepostsure', 'blocktype.wall'), ), 'submit' => array( 'type' => 'submitcancel', 'value' => array(get_string('yes'), get_string('no')), 'goto' => get_config('wwwroot').'user/view.php' ), ) )); //smarty function deletepost_submit(Pieform$form, $values) { global$SESSION;
$instance = param_integer('instance'); delete_records('blocktype_wall_post', 'id',$instance);
$SESSION->add_ok_msg(get_string('deletepostsuccess', 'blocktype.wall')); redirect('/user/view.php'); }$smarty = smarty();
$smarty->assign('deleteform',$form);
$smarty->display('blocktype:wall:deletepostwall.tpl'); ?> in lib.php change on line 155 SELECT bwp.instance, bwp.from, bwp.replyto, bwp.private, bwp.postdate, bwp.text,' . db_format_tsfield('postdate') . ', by SELECT bwp.id AS postid, bwp.instance, bwp.from, bwp.replyto, bwp.private, bwp.postdate, bwp.text,' . db_format_tsfield('postdate') . ', in the theme file inlinepost.tpl change line 13 to 22 {*<div class="controls"> {if$ownwall}
[ <a href="{$WWWROOT}blocktype/wall/wall.php?instance={$instanceid}&replyto={$wallpost->id}">{str tag='reply' section='blocktype.wall'}</a> ] {/if} {if$ownwall || $wallpost->from ==$userid}
[ <a href="{$WWWROOT}blocktype/wall/deletepost.php?instance={$instanceid}&return={if $wholewall}wall{else}profile{/if}"> {str tag='delete' section='blocktype.wall'} </a> ] {/if} </div>*} by <div class="controls"> {if$ownwall}
{*[ <a href="{$WWWROOT}blocktype/wall/wall.php?instance={$instanceid}&replyto={$wallpost->id}">{str tag='reply' section='blocktype.wall'}</a> ]*} {/if} {if$ownwall || $wallpost->from ==$userid}
[ <a href="{$WWWROOT}blocktype/wall/deletepost.php?instance={$wallpost->postid}&return={if $wholewall}wall{else}profile{/if}"> {str tag='delete' section='blocktype.wall'} </a> ] {/if} </div> create deletepostwall.tpl {include file="header.tpl"} {include file="sidebar.tpl"} {include file="columnleftstart.tpl"} <h2>{$subheading|escape}</h2>

<div class="message">{$deleteform}</div> {include file="columnleftend.tpl"} {include file="footer.tpl"} and in lang file add:$string['deletepostsure'] = 'Are you sure you want to do this? It cannot be undone.';
\$string['deletepostsuccess'] = 'Post deleted successfully';

I hope i have'nt made error writing this

Maxime Rigo

Posts: 228
##### Re: deleting wall post

23 April 2009, 6:12 AM

Hi Maxime!

That's great that you' ve  written this code. I hope we can merge it soon!

If you're looking into doing Mahara development, it's definitely a good idea to start working with git.  If you make a new git checkout (there are instructions on how to do this on the wiki - http://wiki.mahara.org/Download_Mahara), then you can send us properly formatted git patches, which include your name and everything, which we can then apply to Mahara, and you get your name in the changelog, as well as it making our life much easier :)

Once you've got your hands on a git checkout, do something like this:

# check out a new branch for you to work on, called 'wallpost'

git checkout -b wallpost origin/master

# make all your changes necessary, and test everything

# commit all changes (new files and modified files)

git commit -a

# or specifiy exactly which files to commit

git commit /path/to/modifiedfile path/to/newfile

# type a good commit message in the editor that pops up - a brief summary of what the patch is

# extract the patch in a format you can send to us (this extracts the single last patch but you can also do this for a series of patches for a bigger feature)

# this will print out a file that looks like 0001-your-commit-message.patch

# send the patch to us in an email

git send-email  0001-your-commit-message.patch

# fill in all the necessary questions (you want to send this to dev@mahara.org)

This patch you've posted here is suitably small for it to be a good way for you to get familiar with the process, so it might be a good idea to try this method with it :)

Hope that's clear! (And thanks again for contributing)

Penny

Posts: 12
##### Re: deleting wall post

23 April 2009, 8:10 PM

Here there's the wallpost delete patch by Maxime in a proper formatted way.

I did a small change which fixed the deletion of the own posts on the other walls.

Actually this patch is in a raw state, it would be nice to have a popup window to confirm deletion instead of the actual way.

Salvatore

Posts: 10
##### Re: deleting wall post

24 April 2009, 3:42 AM

Thanks

I  am not really aware about git but i will try to do this quickely.

Salvatore i thinks  too that a popup window will be more user friendly

Posts: 1643
##### Re: deleting wall post

24 April 2009, 6:47 PM

A javascript popup will be good for those with javascript enabled, yes.
Posts: 108
##### Re: deleting wall post

05 May 2009, 4:50 PM

Maxime, Salvatore et al.

Thanks for this really useful functionality!. However, It does not seem to be working for me for Mahara 1.1.3

Selecting the [delete post] link just gives a blank page.

#### Mahara: Invalid Parameter

A required parameter is missing or malformed
Missing parameter 'id' and no default supplied

Any ideas?

Posts: 12
##### Re: deleting wall post

06 May 2009, 1:44 AM

Hi Geoff

I tested the patch on Mahara 1.1.3 and works good, could you provide more info from log?

About the [reply] you're right, it's not implemented and should be hidden as option.

Regards

Posts: 108
##### Re: deleting wall post

06 May 2009, 2:12 AM

Hi Salvatore

Thanks for the prompt reply. As you suggest, I'll comment out the [reply] code for the moment.

Since the delete functionality works on 1.1.3. for you, I suspect I have scrambled the code somewhere (I applied the patches manually). I'll investigate further and get back if I still have problems.

Thanks again

Posts: 108
##### Re: deleting wall post

06 May 2009, 3:40 PM

Yes, I had placed deletepostwall.tpl in the wrong folder .

Now [delete post] works fine. Cheers!

Posts: 117
##### Re: deleting wall post

14 June 2009, 2:49 PM

Thanks for this.  There is only one real issue that I have discovered.  The script doesn't check if the person deleting the post is the owner or original author.  Anybody can delete anyone else's posts if they just enter the url into their browser's address bar.  So, a malicous user could write a script that would go through and delete all the wall posts simply by incrementing the instance by one each time. So, you just need to add a little bit of code to check and make sure that the person has the right to delete the post.
14 results