Show Deleted v1.1

AndyB

Well-known member
Purpose:

The purpose of this thread is to provide additional information on the Show Deleted v1.1 add-on. To download and install this add-on please visit the following XenForo Resource:

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

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.webp
 
The directory structure with the core files highlighted.

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

PHP:
<?php

class Andy_ShowDeleted_ControllerPublic_ShowDeleted extends XenForo_ControllerPublic_Abstract
{	
	public function actionIndex()
	{	
		// get permissions 
		$permissions = XenForo_Visitor::getInstance()->getPermissions();
		
		// get viewDeleted permission
		$viewDeleted = XenForo_Permission::hasPermission($permissions, "forum", "viewDeleted"); 
		
		// if viewDeleted is false display no permission response
		if (!$viewDeleted) 
		{
			throw $this->getNoPermissionResponseException();
		}
				
		//########################################
		// 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		
		
		// prepare $viewParams for template
		$viewParams = array(
			'posts' => $posts,
			'threads' => $threads,
		); 
		
		// send to template for display
		return $this->responseView('Andy_ShowDeleted_ViewPublic_ShowDeleted', 'andy_showdeleted', $viewParams);
	}
}

?>
 
library/Andy/ShowDeleted/Listener.php

PHP:
<?php

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

?>
 
library/Andy/ShowDeleted/Model/DeletionLog.php

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');
	}	
}

?>
 
library/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);
	}
}

?>
 
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>
 
Back
Top Bottom