• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Creating the add-on Show Deleted

AndyB

Well-known member
#1
Description:

When a user deletes a post or thread, that is called a soft delete. This allows the administrator to review the soft deleted item to determine if it needs to be restored or physically deleted.

This add-on was created to quickly display soft deleted posts and threads.

Here's an example of what is shown:

pic001.jpg
Requirements:

This add-on only works on XenForo v1.2 and above.

Operation:

To use this add-on you will want to type into your browser the following URL:

http://www.site.com/forums/showdeleted/

I recommend making a bookmark in your browser.

Note:

You can download this add-on from the Resources here:

http://xenforo.com/community/resources/show-deleted.2387/
 
Last edited:

AndyB

Well-known member
#2
This tutorial will show the steps required to create this add-on.

1) Create the directory structure
2) Create the New Route Prefix
3) Create the ShowDeleted.php file #1
4) Create the ShowDeleted.php file #2
5) Create the Code Event Listener
6) Create the Listener.php file
7) Create the DeletionLog.php file
8) Create the andy_showdeleted template
 

AndyB

Well-known member
#3
Create the directory structure:

library
--Andy
----ShowDeleted
------ControllerPublic
--------ShowDeleted.php
----Listener.php
----Model
------DeletionLog.php
----Route
------Prefix
--------ShowDeleted.php
 

AndyB

Well-known member
#5
Create the ShowDeleted.php file #1:

libarary/Andy/ShowDeleted/Route/Prefix/ShowDeleted.php

PHP:
<?php

class Andy_ShowDeleted_Route_Prefix_ShowDeleted implements XenForo_Route_Interface
{
	public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
	{
		return $router->getRouteMatch('Andy_ShowDeleted_ControllerPublic_ShowDeleted', $routePath);
	}
}

?>
 

AndyB

Well-known member
#6
Create the ShowDeleted.php file #2:

library/Andy/ShowDeleted/ControllerPublic/ShowDeleted.php

PHP:
<?php

class Andy_ShowDeleted_ControllerPublic_ShowDeleted extends XenForo_ControllerPublic_Abstract
{	
	protected function _preDispatch($action)
	{
		if (!XenForo_Visitor::getInstance()->isSuperAdmin())
		{
			throw $this->getNoPermissionResponseException();
		}
	} 
	
	public function actionIndex()
	{				
		//########################################
		// get data
		
		// this is fetching $posts from XenForo_Model_DeletionLog 
		// the function getDeletedPosts() is initially not there
		// we extended XenForo_Model_DeletionLog with Andy_ShowDeleted_Model_DeletionLog
		// all Andy_ShowDeleted_Model_DeletionLog functions are now accessible from XenForo_Model_DeletionLog		
		
		// get deleted post_id numbers	
		$posts = $this->getModelFromCache('XenForo_Model_DeletionLog')->getDeletedPosts();
		
		// this is fetching $threads from XenForo_Model_DeletionLog 
		// the function getDeletedThreads() is initially not there
		// we extended XenForo_Model_DeletionLog with Andy_ShowDeleted_Model_DeletionLog
		// all Andy_ShowDeleted_Model_DeletionLog functions are now accessible from XenForo_Model_DeletionLog

		// get deleted thread_id numbers
		$threads = $this->getModelFromCache('XenForo_Model_DeletionLog')->getDeletedThreads();
				
		//########################################
		// display data		
		
		// $viewParams must be an array
		$viewParams = array('posts' => $posts,'threads' => $threads,
		); 
		
		// send to template for display
		return $this->responseView('Andy_ShowDeleted_ViewPublic_ShowDeleted', 'andy_showdeleted', $viewParams);
	}
}

?>
 

AndyB

Well-known member
#7
The above ShowDeleted.php file gets its data from the class XenForo_Model_DeletionLog, which is located in the library/Xenforo/Model/DeletionLog.php file. It needed to be extended because the functions we needed were not there.

How to extend the XenForo_Model_DeletionLog is shown in the following three posts.
 

AndyB

Well-known member
#9
Create the Listener.php file:

PHP:
<?php

class Andy_ShowDeleted_Listener
{
	public static function loadClassModel($class, array &$extend)
	{
		$extend[] = 'Andy_ShowDeleted_Model_DeletionLog';
	}
}

?>
 

AndyB

Well-known member
#10
Create the DeletionLog.php file:

PHP:
<?php

class Andy_ShowDeleted_Model_DeletionLog extends XFCP_Andy_ShowDeleted_Model_DeletionLog
{
	public function getDeletedPosts()
	{
		return $this->_getDb()->fetchAll('
		SELECT content_id AS post_id, delete_username, xf_node.title, delete_reason
		FROM xf_deletion_log
		INNER JOIN xf_post ON xf_post.post_id = xf_deletion_log.content_id
		INNER JOIN xf_thread ON xf_thread.thread_id = xf_post.thread_id
		INNER JOIN xf_node ON xf_node.node_id = xf_thread.node_id
		WHERE content_type = "post"
		ORDER BY content_id DESC
		LIMIT 50');
	}
	
	public function getDeletedThreads()
	{
		return $this->_getDb()->fetchAll('
		SELECT content_id AS thread_id, delete_username, xf_node.title, delete_reason
		FROM xf_deletion_log
		INNER JOIN xf_thread ON xf_thread.thread_id = xf_deletion_log.content_id
		INNER JOIN xf_node ON xf_node.node_id = xf_thread.node_id
		WHERE content_type = "thread"
		ORDER BY content_id DESC
		LIMIT 50');
	}	
}

?>
 

AndyB

Well-known member
#11
Create the andy_showdeleted template:

Code:
Soft deleted posts and threads - Maximum 100 shown

<br /><br />

<table class="dataTable">
<tr class="dataRow">
<th>Number</th>
<th>Deleted By</th>
<th>Forum</th>
<th>Delete Reason</th>
</tr>

<xen:foreach loop="$posts" value="$post">
<tr class="dataRow">
<td><a href="{xen:link posts, $post}" />Post {$post.post_id}</a></td><td>{$post.delete_username}</td><td>{$post.title}</td><td>{$post.delete_reason}</td>
</tr>
</xen:foreach>

<xen:foreach loop="$threads" value="$thread">
<tr class="dataRow">
<td><a href="{xen:link 'threads',  $thread}" />Thread {$thread.thread_id}</a></td><td>{$thread.delete_username}</td><td>{$thread.title}</td><td>{$thread.delete_reason}</td>
</tr>
</xen:foreach>
</table>
 
Last edited: