Forums | Mahara Community

Developers /
deleting wall post


anonymous profile picture
Account deleted
Posts: 10

23 April 2009, 5:07

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
 * it under the terms of the GNU General Public License as published by
 * 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
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @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

anonymous profile picture
Account deleted
Posts: 228

23 April 2009, 6:12

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

 # tell git that you want to add your new files

git add /patht/to/newfile /path/to/othernewfile

# 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)

git format-patch HEAD~1..HEAD

# 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 [email protected]

 

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

 

23 April 2009, 20:10

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

anonymous profile picture
Account deleted
Posts: 10

24 April 2009, 3:42

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

anonymous profile picture
Account deleted
Posts: 1643

24 April 2009, 18:47

A javascript popup will be good for those with javascript enabled, yes.
Geoff Rowland's profile picture
Posts: 108

05 May 2009, 16:50

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 Frown

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

Selecting the [reply] link gives a page with

Mahara: Invalid Parameter

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

Any ideas?

06 May 2009, 1:44

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

Geoff Rowland's profile picture
Posts: 108

06 May 2009, 2:12

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

Geoff Rowland's profile picture
Posts: 108

06 May 2009, 15:40

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

Now [delete post] works fine. Cheers!

anonymous profile picture
Account deleted
Posts: 117

14 June 2009, 14:49

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