Initial commit

This commit is contained in:
Felix Förtsch
2020-10-20 14:39:50 +02:00
commit 648ded8896
1225 changed files with 216511 additions and 0 deletions

View File

@@ -0,0 +1,254 @@
<?php
/**
* Log Viewer
*
* @package Log_Viewer_Admin
* @author Markus Fischbacher <fischbacher.markus@gmail.com>
* @license GPL-2.0+
* @link http://wordpress.org/extend/plugins/log-viewer/
* @copyright 2013 Markus Fischbacher
*/
/**
* Class Log_Viewer_Admin
*
* Main class for admin functionality
*/
class Log_Viewer_Admin
{
/**
* Plugin version ( long with timestamp ).
*
* @since 13.11.10
*
* @var string
*/
const VERSION = '14.05.04-1559';
/**
* Plugin version, used for cache-busting of style and script file references.
*
* @since 13.11.11
*
* @var string
*/
const VERSION_SHORT = '14.05.04';
/**
* Unique identifier for your plugin.
*
* The variable name is used as the text domain when internationalizing strings
* of text. Its value should match the Text Domain file header in the main
* plugin file.
*
* @since 13.11.10
*
* @var string
*/
protected $plugin_slug = 'log-viewer';
/**
* Instance of this class.
*
* @since 13.11.10
*
* @var Log_Viewer_Admin
*/
protected static $instance = null;
/**
* Slug of the plugin screen.
*
* @since 13.11.10
*
* @var string
*/
protected $plugin_screen_hook_suffix = null;
/**
*
*
* @since 13.11.10
*
* @var Files_View_Page
*/
private $_files_view_page = null;
/**
* Initialize the plugin by loading admin scripts & styles and adding a
* settings page and menu.
*
* @since 13.11.10
*/
private function __construct()
{
if( !is_super_admin() ) {
return;
}
// Add menu entries
add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ) );
}
/**
* Return an instance of this class or false on error.
*
* @since 13.11.10
*
* @return bool|Log_Viewer_Admin A single instance of this class.
*/
public static function get_instance()
{
if( !is_super_admin() ) {
return false;
}
// If the single instance hasn't been set, set it now.
if( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Make sure that the file that was requested to edit, is allowed to be edited
*
* Function will die if if you are not allowed to edit the file
*
* ToDo: pasted from wordpress core. other solution?
*
* @since 14.04.21
*
* @param $file
* @param string $allowed_files
*
* @return mixed
*/
public static function validate_file_to_edit( $file, $allowed_files = '' ) {
$code = validate_file( $file, $allowed_files );
if (!$code )
return $file;
switch ( $code ) {
case 1 :
wp_die( __('Sorry, can&#8217;t edit files with &#8220;..&#8221; in the name. If you are trying to edit a file in your WordPress home directory, you can just type the name of the file in.' ));
case 3 :
wp_die( __('Sorry, that file cannot be edited.' ));
}
}
/**
* Wrapper for getting Files View Page
*
* @since 14.04.21
*
* @return Files_View_Page
*/
public function get_Files_View_Page() {
if( $this->_files_view_page === null ) {
/**
* Add a tools page for viewing the log files
*/
require_once 'includes/class-user-options.php';
require_once 'includes/class-files-view-page.php';
$this->_files_view_page = new Files_View_Page( realpath( __DIR__ . DIRECTORY_SEPARATOR . 'views' ) );
}
return $this->_files_view_page;
}
/**
* Register and enqueue admin-specific style sheet.
*
* @since 13.11.10
*
* @return null Return early if no settings page is registered.
*/
public function enqueue_admin_styles()
{
if( !isset( $this->plugin_screen_hook_suffix ) ) {
return;
}
$screen = get_current_screen();
if( $this->plugin_screen_hook_suffix == $screen->id ) {
wp_enqueue_style( $this->plugin_slug . '-admin-styles', plugins_url( 'assets/css/admin.css', __FILE__ ), array(), Log_Viewer_Admin::VERSION );
}
}
/**
* Register and enqueue admin-specific JavaScript.
*
* @since 13.11.10
*
* @return null Return early if no settings page is registered.
*/
public function enqueue_admin_scripts()
{
if( !isset( $this->plugin_screen_hook_suffix ) ) {
return;
}
$screen = get_current_screen();
if( $this->plugin_screen_hook_suffix == $screen->id ) {
wp_enqueue_script( $this->plugin_slug . '-admin-script', plugins_url( 'assets/js/admin.js', __FILE__ ), array( 'jquery' ), Log_Viewer_Admin::VERSION );
}
}
/**
* Register the administration menu for this plugin into the WordPress Dashboard menu.
*
* @since 13.11.10
*/
public function add_plugin_admin_menu()
{
$this->get_Files_View_Page();
}
/**
* Returns an array with filenames relative to WP_CONTENT_DIR
*
* @since 30.11.2013
*
* @return array
*/
public static function getFiles()
{
// TODO - FUTURE - debug.log always 0
$content_dir = realpath( WP_CONTENT_DIR );
$path = $content_dir . DIRECTORY_SEPARATOR . '*.log';
$replace = $content_dir . DIRECTORY_SEPARATOR;
$files = array();
foreach( array_reverse( glob( $path ) ) as $file ) {
$files[] = str_replace( $replace, '', $file );
}
return $files;
}
/**
* Retruns the real path ( WP Content Dir ) of the file
*
* @param $file
*
* @return string
*/
public static function transformFilePath( $file )
{
$path = realpath( WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $file );
return $path;
}
}

View File

@@ -0,0 +1,396 @@
<?php
/**
* Log Viewer
*
* @package Log_Viewer_Admin
* @author Markus Fischbacher <fischbacher.markus@gmail.com>
* @license GPL-2.0+
* @link http://wordpress.org/extend/plugins/log-viewer/
* @copyright 2013 Markus Fischbacher
*/
/**
* Class Files_View_Page
*
* Provides controller functionality for the Files View page
*/
class Files_View_Page
{
/**
* @var string
*/
private static $_KEYS_FILEACTION_SUBMIT = 'fileactions';
/**
* @var string
*/
private static $_KEYS_FILEACTION_ACTION = 'action';
/**
* @var string
*/
private static $_KEYS_FILEACTION_SCROLLTO = 'scrollto';
/**
* @var string
*/
private static $_KEYS_FILEACTION_FILE = 'file';
/**
* @var string
*/
private static $_KEYS_FILEACTIONS_DUMP = 'dump';
/**
* @var string
*/
private static $_KEYS_FILEACTIONS_EMPTY = 'empty';
/**
* @var string
*/
private static $_KEYS_FILEACTIONS_BREAK = 'break';
/**
* @var string
*/
private static $_KEYS_VIEWFIELDS_SUBMIT = 'viewfields';
/**
* @var string
*/
public static $ACTIONS_VIEWOPTIONS_CHANGED = 'ViewOptions_Changed';
/**
* @var bool
*/
private $_currentFile = false;
/**
* The hook name for this page
*
* @var string
*/
public $_hook_name = null;
/**
* @var WP_Screen
*/
protected $_wpScreen;
/**
* The slug name for the parent menu
*
* @see http://codex.wordpress.org/Function_Reference/add_submenu_page#Parameters
*
* @var string
*/
private static $_parent_slug = 'tools.php';
/**
* The text to be displayed in the title tags of the page when the menu is selected
*
* @var string
*/
private $_page_title = 'Files View';
/**
* The text to be used for the menu
*
* @var string
*/
private $_menu_title = 'Log Viewer';
/**
* The capability required for this menu to be displayed to the user.
*
* @see http://codex.wordpress.org/Roles_and_Capabilities
*
* @var string
*/
private $_capability = 'edit_plugins';
/**
* The slug name to refer to this menu by
*
* @var string
*/
private static $_menu_slug = 'log_viewer_files_view';
/**
* Filename for the view template. Prefixed with view_path of class constructor.
*
* @var string
*/
private $_view_file = 'files-view.php';
/**
* Fetches a WP_Screen object for this page.
*
* @see http://codex.wordpress.org/Class_Reference/WP_Screen
*
* @return WP_Screen
*/
public function getWPScreen()
{
if( !$this->_wpScreen ) {
$this->_wpScreen = WP_Screen::get( $this->_hook_name );
}
return $this->_wpScreen;
}
/**
* Returns the admin_url for this page.
*
* @see http://codex.wordpress.org/Function_Reference/admin_url
*
* @return string|void
*/
public static function getPageUrl()
{
$url = admin_url( self::$_parent_slug, 'admin' );
$url .= "?page=" . self::$_menu_slug;
return $url;
}
/**
* Constructor for this class.
*
* @param string $view_path View templates directory
*/
public function __construct( $view_path = '' )
{
$this->_hook_name = add_submenu_page( self::$_parent_slug, $this->_page_title, $this->_menu_title, $this->_capability, self::$_menu_slug, array( $this, 'view_page' ) );
$this->_view_file = realpath( $view_path . DIRECTORY_SEPARATOR . $this->_view_file );
// saves user options on changed settings
add_action( self::$ACTIONS_VIEWOPTIONS_CHANGED, array( 'User_Options', 'updateUserOptions' ) );
}
/**
* Returns current/active filename or false if none active or
* reads file request parameter to set the current file
*
* @return bool|string
*/
public function getCurrentFile()
{
if( false == $this->_currentFile ) {
$files = Log_Viewer_Admin::getFiles();
if( empty( $files ) ) {
return false;
}
if( isset( $_REQUEST['file'] ) ) {
$file = stripslashes( $_REQUEST['file'] );
} else {
$file = $files[0];
}
validate_file_to_edit( $file, $files );
$this->_currentFile = $file;
}
return $this->_currentFile;
}
/**
* Returns content of current file
*
* @return string
*/
public function getCurrentFileContent()
{
if( !$this->getCurrentFile() ) {
return '';
}
if( User_Options::LINEOUTPUTORDER_FILO == User_Options::getLineOutputOrder() ) {
$content = implode( array_reverse( file( Log_Viewer_Admin::transformFilePath( $this->getCurrentFile() ) ) ) );
} else {
$content = file_get_contents( Log_Viewer_Admin::transformFilePath( $this->getCurrentFile() ), false );
}
return $content;
}
/**
* Dumps the given file
* Respects is writeable
*
* @param $file
*
* @return bool|int
*/
private function _dumpFile( $file )
{
if( !is_writable( $file ) ) {
return -1;
}
$result = unlink( $file );
if( true == $result ) {
$this->_currentFile = false;
}
return $result;
}
/**
* Empties the given file
* Respects is writeable
*
* @param $file
*
* @return bool|int
*/
private function _emptyFile( $file )
{
if( !is_writable( $file ) ) {
return -1;
}
$handle = fopen( $file, 'w' );
if( !$handle ) {
return -2;
}
return fclose( $handle );
}
/**
* Appends break string to given file
* respects is writeable
*
* TODO - FUTURE :
* - user defined break string
*
* @param $file
*
* @return bool|int
*/
private function _appendBreak( $file )
{
if( !is_writable( $file ) ) {
return -1;
}
$handle = fopen( $file, 'a' );
if( !$handle ) {
return -2;
}
fwrite( $handle, '------------------------' );
return fclose( $handle );
}
/**
* Handles file actions of page post
*
* TODO - FUTURE :
* - adding update_recently_edited of wp core?
* - reimplementing message handling
*
* @param $fileaction action to handle
* @param $file file to target
*
* @return $this|bool|int
*/
private function _handle_fileaction( $fileaction, $file )
{
$files = Log_Viewer_Admin::getFiles();
validate_file_to_edit( $file, $files );
$realfile = Log_Viewer_Admin::transformFilePath( $file );
switch( $fileaction ) {
case self::$_KEYS_FILEACTIONS_DUMP:
$dumped = $this->_dumpFile( $realfile );
// BUG: better redirect but not working cause already present output
// wp_redirect( $this->getPageUrl() );
//exit();
// Workaround:
unset( $_POST[self::$_KEYS_FILEACTION_ACTION], $_POST[self::$_KEYS_FILEACTION_FILE], $_POST[self::$_KEYS_FILEACTION_SUBMIT], $_POST[self::$_KEYS_FILEACTION_SCROLLTO], $_REQUEST['file'] );
$this->_currentFile = false;
break;
case self::$_KEYS_FILEACTIONS_EMPTY:
$handle = $this->_emptyFile( $realfile );
return $handle;
break;
case self::$_KEYS_FILEACTIONS_BREAK:
$handle = $this->_appendBreak( $realfile );
return $handle;
break;
default:
break;
}
return $this;
}
/**
* Handles page view with post actions and output
* Respects user options
*
* TODO - FUTURE :
* - splitting functionality / event based
*
*/
public function view_page()
{
if( array_key_exists( self::$_KEYS_FILEACTION_SUBMIT, $_POST ) && check_admin_referer( 'actions_nonce', 'actions_nonce' ) ) {
$file = $_POST[self::$_KEYS_FILEACTION_FILE];
$fileaction = $_POST[self::$_KEYS_FILEACTION_ACTION];
$result = $this->_handle_fileaction( $fileaction, $file );
// Bug: Workaround for wp_redirect not working
unset( $file, $fileaction );
}
if( array_key_exists( self::$_KEYS_VIEWFIELDS_SUBMIT, $_POST ) && check_admin_referer( 'viewoptions_nonce', 'viewoptions_nonce' ) ) {
$viewoptions = array(
User_Options::KEYS_AUTOREFRESH => array_key_exists( User_Options::KEYS_AUTOREFRESH, $_POST ) ? 1 : 0,
);
if( array_key_exists( User_Options::KEYS_LINEOUTPUTORDER, $_POST ) ) {
$viewoptions[User_Options::KEYS_LINEOUTPUTORDER] = (int)$_POST[User_Options::KEYS_LINEOUTPUTORDER];
}
do_action( self::$ACTIONS_VIEWOPTIONS_CHANGED, $viewoptions );
}
$files = Log_Viewer_Admin::getFiles();
$showEditSection = true;
if( empty( $files ) ) {
$showEditSection = false;
}
$realfile = Log_Viewer_Admin::transformFilePath( $this->getCurrentFile() );
$writeable = is_writeable( $realfile );
if( isset( $file ) ) {
var_dump( array( $realfile, $writeable ) );
die();
}
if( !$writeable ) {
$action = false;
}
include_once $this->_view_file;
}
}

View File

@@ -0,0 +1,223 @@
<?php
/**
* Log Viewer
*
* @package Log_Viewer_Admin
* @author Markus Fischbacher <fischbacher.markus@gmail.com>
* @license GPL-2.0+
* @link http://wordpress.org/extend/plugins/log-viewer/
* @copyright 2013 Markus Fischbacher
*/
/**
* Class User_Options
*
* Controls storage and access of user options
* After setting new values, update function has to be called to save to database
*
* TODO - FUTURE :
* - user wordpress *_user_setting ? currently problems with cookie/headers_sent
* - cleanup on uninstall ( multisite installations different options tables )
*
* Bugs :
* - User_Options on MU installations stored in each wp_*_options table
*
*/
class User_Options
{
/**
* Unique string to identify option keys ( appends to user id )
*/
const KEYS_IDENTIFIER = '_log-viewer_settings';
/**
* Line output order of files : First-In-First-Out
*/
const LINEOUTPUTORDER_FIFO = 0;
/**
* Line output order of files : First-In-Last-Out
*/
const LINEOUTPUTORDER_FILO = 1;
/**
* Options keys : autorefresh
*/
const KEYS_AUTOREFRESH = 'autorefresh';
/**
* Options keys : interval of autorefresh
*/
const KEYS_AUTOREFRESHINTERVALL = 'arintervall';
/**
* Options keys : order of line output
*/
const KEYS_LINEOUTPUTORDER = 'lineoutputorder';
/**
* Options keys : options version
*/
const KEYS_OPTIONSVERSION = 'version';
/**
* Buffered/current options
*
* @var array|bool
*/
private static $_options = false;
/**
* Default values of options
*
* @var array
*/
private static $_defaultOptions = array(
self::KEYS_AUTOREFRESH => 1, self::KEYS_AUTOREFRESHINTERVALL => 15, self::KEYS_LINEOUTPUTORDER => self::LINEOUTPUTORDER_FIFO, self::KEYS_OPTIONSVERSION => '14.05.04-1559',
);
/**
* Returns value of Autorefresh; 1 if enabled, 0 if disabled
*
* @return int
*/
public static function getAutoRefresh()
{
if( !self::$_options ) {
self::_loadUserOptions();
}
return self::$_options[self::KEYS_AUTOREFRESH];
}
/**
* Sets value of autorefresh; true for enabled, false for disabled
*
* @param bool $enabled
*/
public static function setAutoRefresh( $enabled = true )
{
if( !self::$_options ) {
self::_loadUserOptions();
}
self::$_options[self::KEYS_AUTOREFRESH] = $enabled ? 1 : 0;
}
/**
* Returns interval of autorefresh
*
* @return int
*/
public static function getAutoRefreshIntervall()
{
if( !self::$_options ) {
self::_loadUserOptions();
}
return self::$_options[self::KEYS_AUTOREFRESHINTERVALL];
}
/**
* Returns order of line output
*
* @see Lineoutput constants
*
* @return int
*/
public static function getLineOutputOrder()
{
if( !self::$_options ) {
self::_loadUserOptions();
}
return self::$_options[self::KEYS_LINEOUTPUTORDER];
}
/**
* Handles loading of options out of database
*
* TODO - FUTURE :
* - TODO better management of updated options, currently only overwriting old settings
*/
private static function _loadUserOptions()
{
/*
* usage of user setting functions
* currently problems with headers sent
*
* $us = get_user_setting( 'log-viewer', false );
if( ! $us ) {
set_user_setting( 'log-viewer', self::$_defaultOptions );
$us = get_user_setting( 'log-viewer', false );
}
if( !$us ) {
error_log( 'cant load/set user settings' );
} else {
var_dump( $us );
}
*/
if( !is_user_logged_in() ) {
self::$_options = self::$_defaultOptions;
return;
}
$user = wp_get_current_user();
$key = sprintf( "%s_log-viewer_settings", $user->ID );
$settings = get_option( $key, false );
if( false === $settings ) {
add_option( $key, self::$_defaultOptions );
$settings = self::$_defaultOptions;
} elseif( !is_array( $settings ) || !array_key_exists( self::KEYS_OPTIONSVERSION, $settings ) ) {
update_option( $key, self::$_defaultOptions );
$settings = self::$_defaultOptions;
}
self::$_options = $settings;
}
/**
* Returns array of current values
*
* @return array|bool
*/
public static function toArray()
{
if( !self::$_options ) {
self::_loadUserOptions();
}
return self::$_options;
}
/**
* Saves newOptions to database and sets/caches current options for direct usage
* respects multiuser
*
* @param array $newOptions
*/
public static function updateUserOptions( $newOptions = array() )
{
if( !is_user_logged_in() ) {
return;
}
if( empty( $newOptions ) ) {
$newOptions = self::toArray();
} else {
$newOptions = wp_parse_args( $newOptions, self::toArray() );
}
$user = wp_get_current_user();
$key = sprintf( "%s%s", $user->ID, self::KEYS_IDENTIFIER );
$oldOptions = get_option( $key, false );
if( $newOptions != $oldOptions ) {
update_option( $key, $newOptions );
self::$_options = $newOptions;
}
}
}

View File

@@ -0,0 +1,178 @@
<?php
/**
* Represents the view for the administration dashboard.
*
* This includes the header, options, and other information that should provide
* The User Interface to the end user.
*
* @package log-viewer
* @author Markus Fischbacher <fischbacher.markus@gmail.com>
* @license GPL-2.0+
* @link http://wordpress.org/extend/plugins/log-viewer/
* @copyright 2013 Markus Fischbacher
*/
?>
<div class="wrap">
<h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
<?php // dumped file messages
if( isset( $dumped ) ) {
if( $dumped ) : ?>
<div id="message" class="updated">
<p><?php _e( 'File dumped successfully.' ); ?></p>
</div>
<?php return;
else :
?>
<div id="message" class="error">
<p><?php _e( 'Could not dump file.' ); ?></p>
</div>
<?php endif; // if $dumped
} // isset $dumped
// end - dumped file messages
?>
<?php // emptied/break file messages
if( isset( $handle ) ) {
if( !$handle ) : ?>
<div id="message" class="error">
<p><?php _e( 'Could not update file.' ); ?></p>
</div>
<?php else : ?>
<div id="message" class="updated">
<p><?php _e( 'File updated successfully.' ); ?></p>
</div>
<?php endif;
} // isset $handle
// end - emptied/break file messages
?>
<?php if( !$files ) : ?>
<div id="message" class="updated">
<p><?php _e( 'No files found.' ); ?></p>
</div>
<?php endif; ?>
<?php if( !$writeable ) : ?>
<div id="message" class="updated">
<p><?php _e( sprintf( 'You can not edit file [%s] ( not writeable ).', $this->getCurrentFile() ) ); ?></p>
</div>
<?php endif;
?>
<?php if( $showEditSection ) : ?>
<div class="fileedit-sub">
<?php printf( '%1$s <strong>%2$s</strong>', __( 'Showing' ), str_replace( realpath( ABSPATH ), "", $realfile ) ) ?>
<div class="tablenav top">
<?php if( $writeable ) : ?>
<div class="alignleft">
<form method="post" action="<?php echo $this->getPageUrl(); ?>">
<?php wp_nonce_field( 'actions_nonce', 'actions_nonce' ); ?>
<input type="hidden" value="<?php echo $this->getCurrentFile(); ?>"
name="<?php echo self::$_KEYS_FILEACTION_FILE; ?>" />
<input id="scrollto" type="hidden" value="0"
name="<?php echo self::$_KEYS_FILEACTION_SCROLLTO; ?>">
<select name="<?php echo self::$_KEYS_FILEACTION_ACTION; ?>">
<option selected="selected" value="-1"><?php _e( 'File Actions' ); ?></option>
<option
value="<?php echo self::$_KEYS_FILEACTIONS_DUMP; ?>"><?php _e( 'Dump' ); ?></option>
<option
value="<?php echo self::$_KEYS_FILEACTIONS_EMPTY; ?>"><?php _e( 'Empty' ); ?></option>
<option
value="<?php echo self::$_KEYS_FILEACTIONS_BREAK; ?>"><?php _e( 'Break' ); ?></option>
</select>
<?php submit_button( __( 'Do' ), 'button', self::$_KEYS_FILEACTION_SUBMIT, false ); ?>
</form>
</div>
<?php endif; ?>
<div class="alignright">
<form method="post" action="<?php echo $this->getPageUrl(); ?>">
<?php wp_nonce_field( 'viewoptions_nonce', 'viewoptions_nonce' ); ?>
<input type="hidden" value="<?php echo $this->getCurrentFile(); ?>" name="file2" />
<input
title="Autorefresh page every <?php echo( User_Options::getAutoRefreshIntervall() ); ?> seconds"
type="checkbox" value="1" <?php checked( 1 == User_Options::getAutoRefresh() ); ?>
id="<?php echo User_Options::KEYS_AUTOREFRESH; ?>"
name="<?php echo User_Options::KEYS_AUTOREFRESH; ?>" />
<label
title="Autorefresh page every <?php echo( User_Options::getAutoRefreshIntervall() ); ?> seconds"
for="<?php echo User_Options::KEYS_AUTOREFRESH; ?>">Autorefresh</label>
<select name="<?php echo User_Options::KEYS_LINEOUTPUTORDER; ?>">
<option <?php selected( User_Options::LINEOUTPUTORDER_FIFO == User_Options::getLineOutputOrder() ); ?>
value="<?php echo User_Options::LINEOUTPUTORDER_FIFO; ?>">FIFO
</option>
<option <?php selected( User_Options::LINEOUTPUTORDER_FILO == User_Options::getLineOutputOrder() ); ?>
value="<?php echo User_Options::LINEOUTPUTORDER_FILO; ?>">FILO
</option>
</select>
<?php submit_button( __( 'Apply' ), 'button', self::$_KEYS_VIEWFIELDS_SUBMIT, false ); ?>
</form>
</div>
</div>
<div id="templateside">
<h3>Log Files</h3>
<ul>
<?php foreach( $files as $file ):
if( $file === $this->getCurrentFile() ) {
?>
<li class="highlight">
<?php
} else {
?>
<li>
<?php
}
?>
<a href="<?php printf( "%s&file=%s", $this->getPageUrl(), $file ); ?>">
<?php echo $file; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
<div id="template">
<div>
<?php if( !is_file( $realfile ) ) : ?>
<div id="message" class="error">
<p><?php _e( 'Could not load file.' ); ?></p>
</div>
<?php else : ?>
<textarea id="newcontent" name="newcontent" rows="25" cols="70"
readonly="readonly"><?php echo $this->getCurrentFileContent(); ?></textarea>
<?php endif; ?>
<div>
<h3><?php _e( 'Fileinfo' ); ?></h3>
<dl>
<dt><?php _e( 'Fullpath:' ); ?></dt>
<dd><?php echo $realfile; ?></dd>
<dt><?php _e( 'Last updated: ' ); ?></dt>
<dd><?php echo date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), filemtime( $realfile ) ); ?></dd>
</dl>
</div>
</div>
</div>
</div><!-- fileedit-sub -->
<?php endif; // showEditSection? ?>
<?php if( User_Options::getAutoRefresh() === 1 ) : ?>
<script type="text/javascript">
setTimeout( "window.location.replace(document.URL);", <?php echo ( User_Options::getAutoRefreshIntervall() * 1000 ); ?> );
</script>
<?php endif; ?>
</div>

View File

@@ -0,0 +1,101 @@
<?php
class Log_Viewer_DebugBar_Panel extends Debug_Bar_Panel {
/**
* Filename for the view template. Prefixed with view_path of class constructor.
*
* @var string
*/
private $_view_file = 'debug-bar-panel.php';
/**
* @var bool
*/
private $_currentFile = false;
/**
* Returns current/active filename or false if none active or
* reads file request parameter to set the current file
*
* TODO : move to helper class?
*
* @return bool|string
*/
public function getCurrentFile()
{
if( false == $this->_currentFile ) {
$files = Log_Viewer_Admin::getFiles();
if( empty( $files ) ) {
return false;
}
if( isset( $_REQUEST['file'] ) ) {
$file = stripslashes( $_REQUEST['file'] );
} else {
$file = $files[0];
}
Log_Viewer_Admin::validate_file_to_edit( $file, $files );
$this->_currentFile = $file;
}
return $this->_currentFile;
}
/**
* Returns content of current file
*
* TODO : move to helper class?
*
* @return string
*/
public function getCurrentFileContent()
{
if( !$this->getCurrentFile() ) {
return '';
}
$content = file_get_contents( Log_Viewer_Admin::transformFilePath( $this->getCurrentFile() ), false );
return $content;
}
function __construct( $view_path = '' ) {
parent::Debug_Bar_Panel( 'Log Viewer' );
$this->_view_file = realpath( $view_path . DIRECTORY_SEPARATOR . $this->_view_file );
}
function init() {
return true;
}
function render() {
require_once plugin_dir_path( __DIR__ ) . '/admin/includes/class-files-view-page.php';
$files = Log_Viewer_Admin::getFiles();
$showEditSection = true;
if( empty( $files ) ) {
$showEditSection = false;
}
$realfile = Log_Viewer_Admin::transformFilePath( $this->getCurrentFile() );
$writeable = is_writeable( $realfile );
if( isset( $file ) ) {
var_dump( array( $realfile, $writeable ) );
die();
}
if( !$writeable ) {
$action = false;
}
include $this->_view_file;
}
}

View File

@@ -0,0 +1,19 @@
<?php
class Log_Viewer_DebugBar_Integration
{
/**
* Check and integrate to Debug-Bar Plugin as Panel
*
* @since 14.04.21
*/
public static function integrate_debugbar( $panels ) {
require_once plugin_dir_path( __DIR__ ) . '/admin/class-log-viewer-admin.php';
require_once plugin_dir_path( __DIR__ ) . '/includes/class-dbpanel.php';
$myPanel = new Log_Viewer_DebugBar_Panel( plugin_dir_path( __DIR__ ) . '/views' );
$panels[] = $myPanel;
return $panels;
}
}

View File

@@ -0,0 +1,47 @@
<?php
/**
* @package log-viewer
* @author Markus Fischbacher <fischbacher.markus@gmail.com>
* @license GPL-2.0+
* @link http://wordpress.org/extend/plugins/log-viewer/
* @copyright 2013 Markus Fischbacher
*
* @wordpress-plugin
* Plugin Name: Log Viewer
* Plugin URI: http://wordpress.org/extend/plugins/log-viewer/
* Description: This plugin provides an easy way to view log files directly in the admin panel.
* Version: 14.05.04
* Tag: 14.05.04
* Timestamp: 14.05.04-1559
* Author: Markus Fischbacher
* Author URI: https://plus.google.com/+MarkusFischbacher
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
// If this file is called directly, abort.
if( !defined( 'WPINC' ) ) {
die;
}
if( !defined( 'ENABLE_DEBUGBAR_INTEGRATION' ) ) {
define( 'ENABLE_DEBUGBAR_INTEGRATION', true );
}
if( defined( 'ENABLE_DEBUGBAR_INTEGRATION' ) && ENABLE_DEBUGBAR_INTEGRATION == true ) {
require_once plugin_dir_path( __FILE__ ) . '/includes/class-debugbar-integration.php';
add_filter( 'debug_bar_panels', array( 'Log_Viewer_DebugBar_Integration', 'integrate_debugbar' ) );
}
/*----------------------------------------------------------------------------*
* Dashboard and Administrative Functionality
*----------------------------------------------------------------------------*/
if( is_admin() && ( !defined( 'DOING_AJAX' ) || !DOING_AJAX ) ) {
//lvlog( sprintf( 'loading admin functions ( is_admin = %s )', is_admin()) );
require_once( plugin_dir_path( __FILE__ ) . '/admin/class-log-viewer-admin.php' );
add_action( 'plugins_loaded', array( 'Log_Viewer_Admin', 'get_instance' ) );
}

View File

@@ -0,0 +1,141 @@
=== Log Viewer ===
Tags: debug, log, advanced, admin, development
Contributors: mfisc
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CDNHTJWQEP5S2
Tested up to: 3.9
Requires at least: 3.4
Stable Tag: 14.05.04
Latest Version: 14.05.04-1559
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
This plugin provides an easy way to view *.log files directly in the admin panel.
== Description ==
** FULLY COMPATIBLE WITH MULTISITE INSTALLATIONS **
** The plugin is recommended to use only in development. **
This plugin provides an easy way to view any *.log files directly in admin panel. Also you can perform simple actions like empty the file or deleting it.
To activate Wordpress logging to file you have to set `define( 'WP_DEBUG_LOG', true );` in your wp-config.php file.
In Multisite installations you have to be Super Admin for using this plugin.
Additionally in Singlesite installations you have to have the 'edit_plugins' capability which is by default only granted to admins.
There is an first integration for a panel to the [Debug Bar Plugin](https://wordpress.org/plugins/debug-bar/ "Debug Bar"). The integration could be deactivated by setting ENABLE_DEBUGBAR_INTEGRATION to false in log-viewer.php.
If you're experiencing problems please report through support forum or check FAQ section. If you have suggestions feel free to submit your view.
Log-Viewer is also listed on the excellent [Developer Plugin](http://wordpress.org/extend/plugins/developer/ "WordPress Developer Plugin") which comes directly by the awesome guys at Automattic!
**Known limitations / Bugs:**
* Autorefresh is currently fixed at 15 seconds if enabled - will let you choose custom timing soon
* after an action in files view a wp_redirect should be called but there's already output present so not working. Workaround is to unset all variables.
* User settings stored "manually"; switch to wordpress own *_user_setting functions but currently problems on cookie/header_sent limiting
* User settings stored in wp_options ( thats ok ) but on multisite installations they are stored in each wp_*_options table
**ToDo:**
* Adding Dashboard functionality ( and/or File View in Dashboard menu (WP_NETWORK_ADMIN) )
* Translations ( DE )
* Cleanup on uninstalling
* Message if WP_DEBUG not set ( on activation? )
== Changelog ==
= 14.05.04 =
* Fixed : error calling method static
= 14.04.22 =
* Added first Debug Bar integration
= 14.04.21 =
* nothing changed ( tag for Debug-Bar functionality )
= 13.12.22 =
* rewrite branch merged to trunk
* full Multisite support ( currently only super admin! )
= 13.11.11 =
* rewrite based on the great [WordPress-Plugin-Boilerplate](https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate) of Tom McFarlin
* optimizations for Multisite installations
* securing Singlesite installations
= 13.11.09 =
* moved to PhpStorm for development
* changed build script to Phing
* started complete rewrite for MU optimizations
= 13.6.25 =
* changed version string for better readability
= 2013.05.19 =
* added Display Options above file list
* added Autorefresh Option ( currently fixed at every 15 seconds )
* added FIFO / FILO Option ( FIFO = displays file as is; FILO = displays file reversed )
= 2013.04.02 =
* moved from sublime text to netbeans for development
* modified structure for standard compliance ( Support Topic by nickdaugherty )
= 2012.10.06 =
* added more files ( currently only WP_CONTENT_DIR and *.log )
* added file info
* started revamp of class structure
= 2012.10.01 =
* check if file is writeable; if not cancel actions / display message
* adjusting wp-plugin contents
= 2012.09.30 =
* initial Wordpress.org Plugins commit
* restructured for svn and wp-plugins hosting
* solved problems with wp-plugins site
= 2012.09.29 =
* submit for Wordpress.org approvement
== Installation ==
1. Upload to your plugins folder, usually found at 'wp-content/plugins/'
2. Activate the plugin on the plugins screen
3. You may want to activate WP logging setting WP_DEBUG_LOG to TRUE in your wp-config.php file
4. Navigate to Tools > Log Viewer to show and view log files
== Frequently Asked Questions ==
= I am admin! Why can't i see the Tools > Log Viewer menu entry? =
If your on a Multisite installation you have to be a Super Admin.
If your on a Singlesite installation you additionally have to have the 'edit_plugins' role.
= But i am a Super Admin with super powers and still can't see the Tools > Log Viewer menu entry! =
Pow! Slam! Donk! ... as stated you have to have 'edit_plugins' role. There are Wordpress constants like 'DISALLOW_FILE_EDIT' which deactivates this even for the greatest of the admins.
Have a look at [http://codex.wordpress.org/Roles_and_Capabilities](http://codex.wordpress.org/Roles_and_Capabilities) or do a websearch for 'wordpress.org DISALLOW_FILE_EDIT' and have a talk to your site maintainer.
= How to enable debug.log =
Simply add `define( 'WP_DEBUG_LOG', true );` in your wp-config.php file. This is not recommended on production environments!
= I changed my error_log to something other than WP default =
That's ok ... as long as the file extension is .log and it's located in WP_CONTENT_DIR. Other sources or extensions aren't supported for now.
= Can i show other files? =
Yes you can! As long as they are located in WP_CONTENT_DIR and have a .log extension. Other sources or extensions aren't supported for now.
= In Files View i only get the error message "Could not load file." or "No files found." =
It looks like there isn't a *.log file in WP_CONTENT_DIR. Which could mean there are no errors. Yay!
If there are files, it could be that they are not readable ( check your permissions ) or it's a bug ... Booo!
= I don't see File Actions options =
The options are only displayed if the file is writeable. Check your permissions.
== Upgrade Notice ==
= None yet.
== Screenshots ==
1. Screenshot shows the file view screen ( with MP6 / WordPress > 3.8 )
2. Screenshot shows the file view screen
3. Screenshot shows Debug Bar integration

View File

@@ -0,0 +1,17 @@
<?php
/**
* Fired when the plugin is uninstalled.
*
* @package log-viewer
* @author Markus Fischbacher <fischbacher.markus@gmail.com>
* @license GPL-2.0+
* @link http://wordpress.org/extend/plugins/log-viewer/
* @copyright 2013 Markus Fischbacher
*/
// If uninstall not called from WordPress, then exit
if( !defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* Represents the view for a Debug Bar Panel.
*
* Only showing default debug.log with a link to full page.
*
* @since 14.04.21
*
* @package log-viewer
* @author Markus Fischbacher <fischbacher.markus@gmail.com>
* @license GPL-2.0+
* @link http://wordpress.org/extend/plugins/log-viewer/
* @copyright 2013 Markus Fischbacher
*/
?>
<div class="wrap">
<?php if( $showEditSection ) : ?>
<div class="fileedit-sub">
<div id="templateside">
<?php printf( '%1$s <strong>%2$s</strong>', __( 'Showing' ), str_replace( realpath( ABSPATH ), "", $realfile ) ) ?>
<a class="button-secondary" title="Open full view" href="<?php echo Files_View_Page::getPageUrl(); ?>">Open full view</a>
</div>
<div id="template">
<div>
<?php if( !is_file( $realfile ) ) : ?>
<div id="message" class="error">
<p><?php _e( 'Could not load file.' ); ?></p>
</div>
<?php else : ?>
<textarea id="newcontent" name="newcontent" rows="25" cols="70"
readonly="readonly"><?php echo $this->getCurrentFileContent(); ?></textarea>
<?php endif; ?>
<div>
<h3><?php _e( 'Fileinfo' ); ?></h3>
<dl>
<dt><?php _e( 'Fullpath:' ); ?></dt>
<dd><?php echo $realfile; ?></dd>
<dt><?php _e( 'Last updated: ' ); ?></dt>
<dd><?php echo date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), filemtime( $realfile ) ); ?></dd>
</dl>
</div>
</div>
</div>
</div><!-- fileedit-sub -->
<?php endif; ?>
</div>