Просмотр исходного кода

#31 - redesigned audit block in studio dashboard

Alex Trofimov 12 лет назад
Родитель
Сommit
c4d753ede0

+ 2 - 2
modules/boonex/antispam/classes/BxAntispamModule.php

@@ -30,8 +30,8 @@ class BxAntispamModule extends BxDolModule
     {
         bx_import('BxTemplFunctions');
         $s = _t('_bx_antispam_dnsbl_status',
-             BxTemplFunctions::getInstance()->statusOnOff($this->_oConfig->getAntispamOption('dnsbl_enable')),
-             BxTemplFunctions::getInstance()->statusOnOff($this->_oConfig->getAntispamOption('uridnsbl_enable')),
+             BxTemplFunctions::getInstance()->statusOnOff((bool)$this->_oConfig->getAntispamOption('dnsbl_enable'), true),
+             BxTemplFunctions::getInstance()->statusOnOff((bool)$this->_oConfig->getAntispamOption('uridnsbl_enable'), true),
              mb_strtolower(_t('_bx_antispam_dnsbl_behaviour_login_' . $this->_oConfig->getAntispamOption('dnsbl_behaviour_login'))),
              mb_strtolower(_t('_bx_antispam_dnsbl_behaviour_join_' . $this->_oConfig->getAntispamOption('dnsbl_behaviour_join')))
         );

+ 3 - 1
modules/boonex/english/data/langs/system.xml

@@ -523,6 +523,7 @@
 	<string name="_adm_dbd_btn_update"><![CDATA[Update]]></string>
 	<string name="_adm_dbd_txt_dolphin_n_available"><![CDATA[Dolphin {0} available!]]></string>
 	<string name="_adm_dbd_txt_dolphin_on"><![CDATA[Dolphin U on]]></string>
+	<string name="_adm_dbd_txt_htools_status"><![CDATA[{0} - <b>{1}</b>]]></string>
 	<string name="_adm_dbd_txt_installed"><![CDATA[Installed:]]></string>
 	<string name="_adm_dbd_txt_version"><![CDATA[Version:]]></string>
 	<string name="_adm_dbd_txt_su_database"><![CDATA[Database]]></string>
@@ -1972,7 +1973,8 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_uploader_simple_submit_button"><![CDATA[Upload]]></string>
 	<string name="_sys_uploader_simple_title"><![CDATA[Simple Upload]]></string>
 	<string name="_sys_uploader_upload_canceled"><![CDATA[Too bad. Upload canceled.]]></string>
-	<string name="_sys_edit_profile"><![CDATA[Edit profile]]></string>
+	<string name="_sys_edit_profile"><![CDATA[Edit profile]]></string>    
+	<string name="_sys_warn"><![CDATA[warning]]></string>
 	<string name="_sys_x_days"><![CDATA[{0} days]]></string>
 	<string name="_to"><![CDATA[to]]></string>
 	<string name="_top"><![CDATA[Top]]></string>

+ 42 - 16
studio/classes/BxDolStudioToolsAudit.php

@@ -197,22 +197,35 @@ class BxDolStudioToolsAudit extends BxDol
         <?php
     }
 
-    public function checkRequirements($sType = BX_DOL_AUDIT_FAIL)
+    /**
+     * Check minimal Dolphin requirements
+     * @param $sType - BX_DOL_AUDIT_FAIL, BX_DOL_AUDIT_WARN, BX_DOL_AUDIT_UNDEF or BX_DOL_AUDIT_OK
+     * @param $sFunc - requirementsPHP, requirementsMySQL or requirementsWebServer
+     * @return array of FAIL, WARN, UNDEF or OK items, if array is empty then no specified items are found
+     */
+    public function checkRequirements($sType = BX_DOL_AUDIT_FAIL, $sFunc = 'requirementsPHP')
     {
         $this->setErrorReporting();
 
-        $aRet = array ();
-        $aMessages = array ();
-        $this->requirementsPHP(false, $aMessages);
+        $aRet = array ();        
+        $aMessages = array ();  
+
+        $this->$sFunc(false, $aMessages);
+
         foreach ($aMessages as $sName => $r)
             if ($sType == $r['type'])
-                $aRet[] = "$sName = " . $this->format_output($r['params']['real_val'], isset($this->aPhpSettings[$sName]) ? $this->aPhpSettings[$sName] : '') . " - " . $this->getMsgHTML($sName, $r);
+                $aRet[] = "$sName = " . $this->format_output($r['params']['real_val'], isset($this->aPhpSettings[$sName]) ? $this->aPhpSettings[$sName] : '') . " - " . $this->getMsgHTML($sName, $r);        
 
         $this->restoreErrorReporting();
 
         return $aRet;
     }
 
+    public function typeToTitle ($sType) 
+    {
+        return $this->aType2Title[$sType];
+    }
+
     protected function requirements()
     {
         echo '<h1>' . _t('_sys_audit_header_requirements') . '</h1>';
@@ -269,7 +282,7 @@ class BxDolStudioToolsAudit extends BxDol
         }
     }
 
-    protected function requirementsMySQL()
+    protected function requirementsMySQL($bEcho = true, &$aOutputMessages = null)
     {
         $sMysqlVer = BxDolDb::getInstance()->getServerInfo();
         if (preg_match ('/^(\d+)\.(\d+)\.(\d+)/', $sMysqlVer, $m)) {
@@ -282,17 +295,31 @@ class BxDolStudioToolsAudit extends BxDol
             $aMessage = array('type' => BX_DOL_AUDIT_UNDEF, 'msg' => _t('_sys_audit_msg_value_checking_failed'));
         }
 
-        $s = $this->getBlock(_t('_sys_audit_version'), $sMysqlVer, $this->getMsgHTML(_t('_sys_audit_version'), $aMessage));
-        echo $this->getSection('MySQL', '', $s);
+        if (null !== $aOutputMessages)
+            $aOutputMessages['mysql'] = array($aMessage);
+
+        if ($bEcho) {
+            $s = $this->getBlock(_t('_sys_audit_version'), $sMysqlVer, $this->getMsgHTML(_t('_sys_audit_version'), $aMessage));
+            echo $this->getSection('MySQL', '', $s);
+        }
     }
 
-    protected function requirementsWebServer()
+    protected function requirementsWebServer($bEcho = true, &$aOutputMessages = null)
     {
-        $s = '';
+        $aMessages = array();
         foreach ($this->aRequiredApacheModules as $sName => $sNameCompiledName)
-            $s .= $this->getBlock($sName, '', $this->checkApacheModule($sName, $sNameCompiledName));
+            $aMessages[$sName] = $this->checkApacheModule($sName, $sNameCompiledName);
 
-        echo $this->getSection(_t('_sys_audit_section_webserver'), $_SERVER['SERVER_SOFTWARE'], $s);
+        if (null !== $aOutputMessages)
+            $aOutputMessages = $aMessages;
+
+        if ($bEcho) {
+            $s = '';
+            foreach ($aMessages as $sName => $r) {
+                $s .= $this->getBlock($sName, '', $this->getBlock('', '', $this->getMsgHTML($sName, $r), false));
+            }
+            echo $this->getSection(_t('_sys_audit_section_webserver'), $_SERVER['SERVER_SOFTWARE'], $s);
+        }
     }
 
     protected function requirementsOS()
@@ -522,8 +549,7 @@ class BxDolStudioToolsAudit extends BxDol
             if (!$sApachectlPath)
                 $sApachectlPath = trim(`which /usr/local/apache/bin/apache2ctl`);
             if (!$sApachectlPath) {
-                $aMessage = array('type' => BX_DOL_AUDIT_UNDEF, 'msg' => _t('_sys_audit_msg_apache_module_undef', $sModule));
-                return $this->getBlock($sModule, '', $this->getMsgHTML($sModule, $aMessage));
+                return array('type' => BX_DOL_AUDIT_UNDEF, 'msg' => _t('_sys_audit_msg_apache_module_undef', $sModule));
             }
             $ret = (boolean)`$sApachectlPath -M 2>&1 | grep $sModule`;
             if (!$ret)
@@ -533,8 +559,8 @@ class BxDolStudioToolsAudit extends BxDol
         $aMessage = array('type' => BX_DOL_AUDIT_OK);
         if (!$ret)
             $aMessage = array('type' => BX_DOL_AUDIT_FAIL, 'msg' => _t('_sys_audit_msg_apache_module_fail', $sModule));
-
-        return $this->getBlock('', '', $this->getMsgHTML($sModule, $aMessage), false);
+        
+        return $aMessage;
     }
 
     protected function getPhpAccelerator ()

+ 6 - 1
studio/template/css/dashboard.css

@@ -43,4 +43,9 @@ div.bx-dbd-cache-chart {
 div.bx-dbd-host-tools .bx-btn {
     display: inline-block;
     float: none;
-}
+}
+
+div.bx-dbd-host-tools .bx-dbd-host-tools-item {
+    float: left;
+    width: 50%;
+}

+ 4 - 8
studio/template/dbd_htools.html

@@ -1,11 +1,7 @@
 <div class="bx-dbd-block-content bx-clearfix">
 	<div id="bx-dbd-host-tools" class="bx-dbd-host-tools">
-		<bx_text:_sys_inst_hosting_fails />
-	 	<ul>
-			<bx_repeat:items>
-				<li>__item__</li>
-			</bx_repeat:items>
-		</ul>
-		__styles__
+		<bx_repeat:items>
+			<div class="bx-dbd-host-tools-item bx-def-margin-sec-bottom">__status__ __msg__</div>
+		</bx_repeat:items>
 	</div>
-</div>
+</div>

+ 21 - 8
studio/template/scripts/BxBaseStudioDashboard.php

@@ -113,15 +113,29 @@ class BxBaseStudioDashboard extends BxDolStudioDashboard
 		bx_import('BxDolStudioToolsAudit');
 		$oAudit = new BxDolStudioToolsAudit();
 
-        $aErrors = $oAudit->checkRequirements(BX_DOL_AUDIT_FAIL);
-        $aWarnings = $oAudit->checkRequirements(BX_DOL_AUDIT_WARN);
+        bx_import('BxTemplFunctions');
+        $oFunc = BxTemplFunctions::getInstance();
 
-        $aTmplVarsItems = array();
-        foreach($aErrors as $sError)
-        	$aTmplVarsItems[] = array('item' => $sError);
+        $aCheckRequirements = array (
+            'PHP' => 'requirementsPHP',
+            'MySQL' => 'requirementsMySQL',
+            'Web Server' => 'requirementsWebServer',
+        );
+        
+        $aLevels = array (BX_DOL_AUDIT_FAIL, BX_DOL_AUDIT_WARN, BX_DOL_AUDIT_UNDEF);
 
-        foreach($aWarnings as $sWarning)
-        	$aTmplVarsItems[] = array('item' => $sWarning);
+        $aTmplVarsItems = array();
+        foreach ($aCheckRequirements as $sTitle => $sFunc) {
+            $sStatus = BX_DOL_AUDIT_OK;
+            foreach ($aLevels as $sLevel) { 
+                $a = $oAudit->checkRequirements($sLevel, $sFunc);
+                if (!empty($a)) {
+                    $sStatus = $sLevel;
+                    break;
+                }
+            }
+            $aTmplVarsItems[] = array('status' => $oFunc->statusOnOff($sStatus), 'msg' => _t('_adm_dbd_txt_htools_status', $sTitle, $oAudit->typeToTitle($sStatus)));
+        }
 
 		$aMenu = array(
 			array(
@@ -134,7 +148,6 @@ class BxBaseStudioDashboard extends BxDolStudioDashboard
 
         $sContent = BxDolStudioTemplate::getInstance()->parseHtmlByName('dbd_htools.html', array(
 	    	'bx_repeat:items' => $aTmplVarsItems,
-        	'styles' => $oAudit->generateStyles(true)
 	    ));
 
 		return array('content' => $sContent, 'menu' => $aMenu);

+ 9 - 4
template/scripts/BxBaseFunctions.php

@@ -347,11 +347,16 @@ class BxBaseFunctions extends BxDol implements iBxDolSingleton
         return '<time datetime="' . $sDateUTC . '" data-bx-format="' . getParam($sFormatIdentifier) . '" data-bx-autoformat="' . ($bForceFormat ? 0 : getParam('sys_format_timeago')) . '">' . $sDateUTC . '</time>';
     }
 
-    function statusOnOff ($mixed)
+    function statusOnOff ($mixed, $isMsg = false)
     {
-        if ($mixed)
-            return '<i class="sys-icon circle col-green1"></i> ' . _t('_sys_on');
-        return '<i class="sys-icon circle col-red2"></i> ' . _t('_sys_off');
+        if ((is_bool($mixed) && !$mixed) || (is_string($mixed) && 'fail' == $mixed))
+            return '<i class="sys-icon circle col-red2"></i> ' . ($isMsg ? _t('_sys_off') : '');
+        elseif (is_string($mixed) && 'warn' == $mixed)
+            return '<i class="sys-icon circle col-red3"></i> ' . ($isMsg ? _t('_sys_warn') : '');
+        elseif (is_string($mixed) && 'undef' == $mixed)
+            return '<i class="sys-icon circle col-gray"></i> ' . ($isMsg ? _t('_undefined') : '');
+        else
+            return '<i class="sys-icon circle col-green1"></i> ' . ($isMsg ? _t('_sys_on') : '');
     }
 }