Skip to content

Commit

Permalink
updates to adminer components
Browse files Browse the repository at this point in the history
think i have everything working now.
  • Loading branch information
codingjungle committed Jul 11, 2022
1 parent 4b1b5fa commit 499ba97
Show file tree
Hide file tree
Showing 223 changed files with 48,898 additions and 10,556 deletions.
1,206 changes: 620 additions & 586 deletions dev/css/admin/adminer.css

Large diffs are not rendered by default.

622 changes: 622 additions & 0 deletions dev/css/admin/test.css

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion dev/html/admin/adminer/adminer.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
<div class="ltr js">
{$content|raw}
</div>
</div>
</div>


2 changes: 2 additions & 0 deletions dev/html/admin/adminer/iframe.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<ips:template parameters="$url"/>
<iframe id="toolboxAdminer" width="100%" height="600px" src="{$url}"></iframe>
418 changes: 209 additions & 209 deletions extensions/toolbox/constants/toolbox.php

Large diffs are not rendered by default.

227 changes: 136 additions & 91 deletions modules/admin/settings/adminer.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
<?php

/**
* @brief Adminer Class
* @author -storm_author-
* @copyright -storm_copyright-
* @package IPS Social Suite
* @subpackage Dev Toolbox
* @since 5.0.0
* @version -storm_version-
*/
/**
* @brief Adminer Class
* @author -storm_author-
* @copyright -storm_copyright-
* @package IPS Social Suite
* @subpackage Dev Toolbox
* @since 5.0.0
* @version -storm_version-
*/


namespace IPS\toolbox\modules\admin\settings;

/* To prevent PHP errors (extending class does not exist) revealing path */

use Exception;
use IPS\Http\Url;
use IPS\Output;
use IPS\Theme;
use IPS\toolbox\Application;


use IPS\toolbox\Proxy\Helpers\Request;

use function _p;
use function libxml_use_internal_errors;
use function ob_end_clean;
use function ob_get_clean;
use function ob_start;
use function pathinfo;
use function pq;
use function preg_replace;
use function preg_replace_callback;
use function str_replace;

if (!\defined('\IPS\SUITE_UNIQUE_KEY')) {
Expand All @@ -39,92 +43,133 @@
*/
class _adminer extends \IPS\Dispatcher\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = true;

/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher\Admin::i()->checkAcpPermission('adminer_manage');
parent::execute();
}
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = true;
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission('adminer_manage');
parent::execute();
}

/**
* ...
*
* @return void
*/
protected function manage()
{
if (\IPS\Request::i()->isAjax()) {
$this->adminer();
} else {
ob_start();

require Application::getRootPath(
'toolbox'
) . '/applications/toolbox/sources/Profiler/Adminer/db.php';
$content = ob_get_contents();
try {
ob_end_clean();
} catch (Exception $e) {
}

$content = preg_replace_callback('#<html (.*)#', static function ($m) {
return '<html ' . $m[1] . '<head>';
}, $content);

protected function manage()
{
\IPS\toolbox\Application::addJs(['admin_click'], 'admin');
Application::addCss(['adminer'], 'admin');

ob_start();
require Application::getRootPath(
'toolbox'
) . '/applications/toolbox/sources/Profiler/Adminer/db.php';
$content = ob_get_clean();
try {
ob_end_clean();
} catch (Exception $e) {
$content = preg_replace_callback('#<body (.*)#', static function ($m) {
return '</head><body ' . $m[1];
}, $content);

/* Swap out certain tags that confuse phpQuery */
$content = preg_replace('/<(\/)?(html|head|body)(>| (.+?))/', '<$1temp$2$3', $content);
$content = str_replace('<!DOCTYPE html>', '<hypertemp></hypertemp>', $content);
$content = '<div http-equiv="Content-Type" content="text/html; charset=utf-8"></div><ipscontent id="ipscontent">' . $content . '</ipscontent>';
/* Load phpQuery */
require_once Application::getRootPath('core') . '/system/3rd_party/phpQuery/phpQuery.php';
libxml_use_internal_errors(true);
$phpQuery = \phpQuery::newDocumentHTML($content);
$css = [];
$js = [];
$url = (string)Url::internal('app=toolbox&module=settings&controller=adminer');
/** @var \DOMElement $link */
foreach ($phpQuery->find('link') as $link) {
if ($link->getAttribute('rel') !== 'stylesheet') {
continue;
}
$l = $link->getAttribute('href');
if ($l) {
$css[] = $url . str_replace('?', '&', $l);
pq($link)->remove();
}
/* Swap out certain tags that confuse phpQuery */
$content = preg_replace( '/<(\/)?(html|head|body)(>| (.+?))/', '<$1temp$2$3', $content );
$content = str_replace( '<!DOCTYPE html>', '<tempdoctype></tempdoctype>', $content );

/* Load phpQuery */
require_once Application::getRootPath('core') . '/system/3rd_party/phpQuery/phpQuery.php';
libxml_use_internal_errors(TRUE);
$phpQuery = \phpQuery::newDocumentHTML( $content );
$url = (string) Url::internal('app=toolbox&module=settings&controller=adminer&do=adminer');
/** @var \DOMElement $link */
foreach($phpQuery->find('link') as $link){
$l = $link->getAttribute('href');
if( $l ) {
pq($link)->remove();
}
}
/** @var \DOMElement $script */
foreach ($phpQuery->find('script') as $script) {
$l = $script->getAttribute('src');
if ($l) {
pq($script)->remove();
Output::i()->jsFiles[] = $url . str_replace('?', '&', $l);
} else {
$d = pq($script)->html();
$d = str_replace('?server', $url . '&server', $d);
pq($script)->html($d);
}
$foo = [];
/** @var \DOMElement $script */
foreach($phpQuery->find('script') as $script){
$l = $script->getAttribute('src');
if($l) {
pq($script)->attr('src',$url.str_replace('?','&',$l));
}
else{
$d = pq($script)->html();
$d = str_replace('?server', $url.'&server',$d);
pq($script)->html($d);
}
}
foreach ($phpQuery->find('input') as $script) {
$l = $script->getAttribute('src');
if ($l) {
pq($script)->attr('src', $url . str_replace('?', '&', $l));
}
$url2 = (string) Url::internal('app=toolbox&module=settings&controller=adminer');

foreach($phpQuery->find('a') as $a ){
$a = pq($a);
$ref = $a->attr('href');
if(mb_strpos($ref,'?server=') !== false){
$ref = str_replace('?server',$url2.'&server',$ref);
}
$a->attr('href',$ref);
}
foreach ($phpQuery->find('form') as $form) {
$l = $form->getAttribute('action');
if (!$l) {
pq($form)->attr('action', (string)\IPS\Request::i()->url())
->append('<input type="hidden" name="formSubmitted" value="1">')
->append('<input type="hidden" name="target" value="' . \IPS\Settings::i()->getFromConfGlobal('sql_database') . '">');
}
$return = $phpQuery->htmlOuter();
$return = preg_replace( '/<(\/)?temp(html|head|body)(.*?)>/', '<$1$2$3>', $return );
$return = str_replace( '<tempdoctype></tempdoctype>', '<!DOCTYPE html>', $return );
}

Output::i()->output = Theme::i()->getTemplate('adminer', 'toolbox', 'admin')->adminer($return);
}

protected function adminer(){
ob_start();
require Application::getRootPath(
'toolbox'
) . '/applications/toolbox/sources/Profiler/Adminer/db.php';
$content = ob_get_clean();
try {
ob_end_clean();
} catch (Exception $e) {
$url2 = (string)Url::internal('app=toolbox&module=settings&controller=adminer');

foreach ($phpQuery->find('a') as $a) {
$a = pq($a);
$ref = $a->attr('href');
if (mb_strpos($ref, '?server=') !== false) {
$ref = str_replace('?server', $url2 . '&server', $ref);
}
Output::i()->sendOutput($content);
$a->attr('href', $ref);
}
$return = $phpQuery->find('#' . 'ipscontent')->find('tempbody')->html();

/* Swap back certain tags that confuse phpQuery */
$return = preg_replace('/<(\/)?temp(html|head|body)(.*?)>/', '<$1$2$3>', $return);
$return = str_replace('<hypertemp></hypertemp>', '<!DOCTYPE html>', $return);
Application::addJs(['admin_click'], 'admin');
Application::addCss(['adminer'], 'admin');
Output::i()->output = Theme::i()->getTemplate('adminer', 'toolbox', 'admin')->adminer($return);
}
}
}

protected function adminer()
{
ob_start();

require Application::getRootPath(
'toolbox'
) . '/applications/toolbox/sources/Profiler/Adminer/db.php';
$content = ob_get_contents();
try {
ob_end_clean();
} catch (Exception $e) {
}
Output::i()->sendOutput($content);
}
}
Loading

0 comments on commit 499ba97

Please sign in to comment.