phpmyadmin/libraries/classes/Console.php
Maurício Meneghini Fauth 13c0f7bc3c Move classes to PhpMyAdmin namespace
- Move Advisor to PhpMyAdmin namespace
- Move Bookmark to PhpMyAdmin namespace
- Move Charsets to PhpMyAdmin namespace
- Move Config class to PhpMyAdmin namespace
- Move Console class to PhpMyAdmin namespace
- Move Core to PhpMyAdmin namespace
- Move DatabaseInterface to PhpMyAdmin namespace
- Move DbList to PhpMyAdmin namespace
- Move DbQbe to PhpMyAdmin namespace
- Move DbSearch to PhpMyAdmin namespace
- Move DisplayResults to PhpMyAdmin namespace
- Move Encoding to PhpMyAdmin namespace
- Move Error to PhpMyAdmin namespace
- Move ErrorHandler to PhpMyAdmin namespace
- Move File to PhpMyAdmin namespace
- Move Font to PhpMyAdmin namespace
- Move Footer to PhpMyAdmin namespace
- Move Header to PhpMyAdmin namespace
- Move Index to PhpMyAdmin namespace
- Move IndexColumn to PhpMyAdmin namespace
- Move LanguageManager to PhpMyAdmin namespace
- Move Language to PhpMyAdmin namespace
- Move Linter to PhpMyAdmin namespace
- Move ListAbstract to PhpMyAdmin namespace
- Move ListDatabase to PhpMyAdmin namespace

Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
2017-06-28 21:17:18 -03:00

147 lines
3.4 KiB
PHP

<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Used to render the console of PMA's pages
*
* @package PhpMyAdmin
*/
namespace PhpMyAdmin;
use PhpMyAdmin\Bookmark;
use PMA\libraries\Template;
use PMA\libraries\Util;
if (! defined('PHPMYADMIN')) {
exit;
}
/**
* Class used to output the console
*
* @package PhpMyAdmin
*/
class Console
{
/**
* Whether to display anything
*
* @access private
* @var bool
*/
private $_isEnabled;
/**
* Creates a new class instance
*/
public function __construct()
{
$this->_isEnabled = true;
}
/**
* Whether we are servicing an ajax request.
*
* @access private
* @var bool
*/
private $_isAjax;
/**
* Set the ajax flag to indicate whether
* we are servicing an ajax request
*
* @param bool $isAjax Whether we are servicing an ajax request
*
* @return void
*/
public function setAjax($isAjax)
{
$this->_isAjax = (boolean) $isAjax;
}
/**
* Disables the rendering of the footer
*
* @return void
*/
public function disable()
{
$this->_isEnabled = false;
}
/**
* Renders the bookmark content
*
* @access public
* @return string
*/
public static function getBookmarkContent()
{
$cfgBookmark = Bookmark::getParams();
if ($cfgBookmark) {
$bookmarks = Bookmark::getList();
$count_bookmarks = count($bookmarks);
if ($count_bookmarks > 0) {
$welcomeMessage = sprintf(
_ngettext(
'Showing %1$d bookmark (both private and shared)',
'Showing %1$d bookmarks (both private and shared)',
$count_bookmarks
),
$count_bookmarks
);
} else {
$welcomeMessage = __('No bookmarks');
}
unset($count_bookmarks, $private_message, $shared_message);
return Template::get('console/bookmark_content')
->render(
array(
'welcome_message' => $welcomeMessage,
'bookmarks' => $bookmarks,
)
);
}
return '';
}
/**
* Returns the list of JS scripts required by console
*
* @return array list of scripts
*/
public function getScripts()
{
return array('console.js');
}
/**
* Renders the console
*
* @access public
* @return string
*/
public function getDisplay()
{
if ((! $this->_isAjax) && $this->_isEnabled) {
$cfgBookmark = Bookmark::getParams();
$image = Util::getImage('console.png', __('SQL Query Console'));
$_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']);
$bookmarkContent = static::getBookmarkContent();
return Template::get('console/display')
->render(
array(
'cfg_bookmark' => $cfgBookmark,
'image' => $image,
'sql_history' => $_sql_history,
'bookmark_content' => $bookmarkContent,
)
);
}
return '';
}
}