src/marknotes/plugins/buttons/erase.php
<?php
/**
 * Add a Erase button to the menu. That button will call the
 * task.listfiles.erase i.e. remove any .epub, .docx, .html, ... files
 * generated by marknotes in the /docs folder
 */
namespace MarkNotes\Plugins\Buttons;

defined('_MARKNOTES') or die('No direct access allowed');

class Erase extends \MarkNotes\Plugins\Button\Plugin
{
	protected static $me = __CLASS__;
	protected static $json_settings = 'plugins.buttons.erase';
	protected static $json_linked = 'plugins.page.html.erase';

	public static function add(&$buttons = array()) : bool
	{
		$buttons['app'][] = self::button(
			array(
				'name' => 'erase',
				'title' => 'settings_erase',
				'default' => 'Remove previous exported files',
				'task' => 'fnPluginTaskListFilesKillExport',
				'id' => 'icon_settings_erase',
				'icon' => 'trash-o'
			)
		);

		return true;
	}

	protected static function canAdd() : bool
	{
		// This button can't be displayed to visitors
		if ($bReturn = parent::canAdd()) {
			$aeSession = \MarkNotes\Session::getInstance();
			$bReturn = boolval($aeSession->get('authenticated', 0));
		}

		return $bReturn;
	}
}
