AntonLV 12 лет назад
Родитель
Сommit
3e978efbc4

+ 6 - 4
install/sql/system.sql

@@ -858,13 +858,16 @@ CREATE TABLE `sys_injections` (
   `name` varchar(128) NOT NULL default '',
   `page_index` int(11) NOT NULL default '0',
   `key` varchar(128) NOT NULL default '',
-  `type` enum('text', 'php') NOT NULL default 'text',
+  `type` enum('text', 'service') NOT NULL default 'text',
   `data` text NOT NULL default '',
   `replace` TINYINT NOT NULL DEFAULT '0',
   `active` TINYINT NOT NULL DEFAULT '1',
   PRIMARY KEY  (`id`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
 
+INSERT INTO `sys_injections`(`name`, `page_index`, `key`, `type`, `data`, `replace`, `active`) VALUES
+('update_cache', 150, 'injection_head', 'service', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:17:"get_cache_updater";s:6:"params";a:0:{}s:5:"class";s:19:"TemplStudioLauncher";}', 0, 1);
+
 -- --------------------------------------------------------
 
 CREATE TABLE `sys_injections_admin` (
@@ -872,14 +875,13 @@ CREATE TABLE `sys_injections_admin` (
   `name` varchar(128) NOT NULL default '',
   `page_index` int(11) NOT NULL default '0',
   `key` varchar(128) NOT NULL default '',
-  `type` enum('text','php') NOT NULL default 'text',
+  `type` enum('text','service') NOT NULL default 'text',
   `data` text NOT NULL,
   `replace` tinyint(4) NOT NULL default '0',
   `active` tinyint(4) NOT NULL default '1',
   PRIMARY KEY (`id`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
 
-
 -- --------------------------------------------------------
 
 
@@ -3265,7 +3267,7 @@ INSERT INTO `sys_std_widgets`(`page_id`, `module`, `url`, `click`, `icon`, `capt
 INSERT INTO `sys_std_pages_widgets`(`page_id`, `widget_id`, `order`) VALUES(@iIdHome, LAST_INSERT_ID(), 2);
 
 INSERT INTO `sys_std_widgets`(`page_id`, `module`, `url`, `click`, `icon`, `caption`, `cnt_notices`, `cnt_actions`) VALUES
-(@iIdDashboard, 'system', '{url_studio}dashboard.php', '', 'wi-dashboard.png', '_adm_wgt_cpt_dashboard', '', '');
+(@iIdDashboard, 'system', '{url_studio}dashboard.php', '', 'wi-dashboard.png', '_adm_wgt_cpt_dashboard', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:18:"get_widget_notices";s:6:"params";a:0:{}s:5:"class";s:20:"TemplStudioDashboard";}', '');
 INSERT INTO `sys_std_pages_widgets`(`page_id`, `widget_id`, `order`) VALUES(@iIdHome, LAST_INSERT_ID(), 3);
 
 

+ 7 - 0
studio/classes/BxDolStudioDashboard.php

@@ -14,6 +14,7 @@ class BxDolStudioDashboard extends BxTemplStudioPage
 {
 	protected $aBlocks;
 	protected $aItemsCache;
+	protected $aItemsHTools;
 
     function __construct()
     {
@@ -34,6 +35,12 @@ class BxDolStudioDashboard extends BxTemplStudioPage
 		    array('name' => 'js')
 		);
 
+		$this->aItemsHTools = array (
+	    	'PHP' => 'requirementsPHP',
+			'MySQL' => 'requirementsMySQL',
+			'Web Server' => 'requirementsWebServer',
+		);
+
         //--- Check actions ---//
         if(($sAction = bx_get('dbd_action')) !== false) {
             $sAction = bx_process_input($sAction);

+ 4 - 0
studio/classes/BxDolStudioLauncher.php

@@ -33,6 +33,10 @@ class BxDolStudioLauncher extends BxTemplStudioWidgets
 
             $aResult = array('code' => 1, 'message' => _t('_adm_err_operation_failed'));
             switch($sAction) {
+				case 'launcher-update-cache':
+					$aResult = $this->updateCache();
+					break;
+
                 case 'launcher-reorder':
                     $sPage = bx_process_input(bx_get('page'));
                     $aItems = bx_process_input(bx_get('items'));

+ 31 - 2
studio/classes/BxDolStudioWidgets.php

@@ -15,15 +15,19 @@ define('BX_DOL_STUDIO_WS_DISABLED', 2);
 
 class BxDolStudioWidgets extends BxTemplStudioPage
 {
+	protected $sCacheKeyNotices = 'std_widgets_notices';
+
     protected $aWidgets;
+    protected $aWidgetsNotices;
 
-    function __construct($mixedPageName)
+    public function __construct($mixedPageName)
     {
         parent::__construct($mixedPageName);
 
         $this->oDb = BxDolStudioWidgetsQuery::getInstance();
 
         $this->aWidgets = array();
+        $this->aWidgetsNotices = array();
 
         if(!$this->bPageMultiple)
             $this->oDb->getWidgets(array('type' => 'by_page_id', 'value' => $this->aPage['id']), $this->aWidgets, false);
@@ -32,12 +36,37 @@ class BxDolStudioWidgets extends BxTemplStudioPage
                 $this->aWidgets[$sPage] = array();
                 $this->oDb->getWidgets(array('type' => 'by_page_id', 'value' => $aPage['id']), $this->aWidgets[$sPage], false);
             }
+
+		//--- Load Cache (Widgets' Notices)
+		$oCache = $this->oDb->getDbCacheObject();
+		$sCacheKey = $this->oDb->genDbCacheKey($this->sCacheKeyNotices);
+		$this->aWidgetsNotices = $oCache->getData($sCacheKey);
     }
 
-    function isEnabled($aWidget)
+    public function isEnabled($aWidget)
     {
         return true;
     }
+
+    public function updateCache()
+    {
+    	$aWidgets = array();
+    	$this->oDb->getWidgets(array('type' => 'all_with_notices'), $aWidgets, false);
+
+    	$aResult = array();
+    	foreach($aWidgets as $aWidget) {
+    		if(BxDolService::isSerializedService($aWidget['cnt_notices'])) {
+				$aService = unserialize($aWidget['cnt_notices']);
+	            $sNotices = BxDolService::call($aService['module'], $aService['method'], array_merge(array($aWidget), $aService['params']), $aService['class']);
+			}
+
+			$aResult[$aWidget['id']] = $sNotices;
+    	}
+
+    	$oCache = $this->oDb->getDbCacheObject();
+    	$sCacheKey = $this->oDb->genDbCacheKey($this->sCacheKeyNotices);
+    	return $oCache->setData($sCacheKey, $aResult);
+    }
 }
 
 /** @} */

+ 5 - 2
studio/classes/BxDolStudioWidgetsQuery.php

@@ -70,17 +70,20 @@ class BxDolStudioWidgetsQuery extends BxDolStudioPageQuery implements iBxDolSing
             case 'by_page_id':
                 $sWhereClause .= $this->prepare("AND `tw2p`.`page_id`=?", $aParams['value']);
                 break;
+            case 'all_with_notices':
+				$sWhereClause .= "AND `tw`.`cnt_notices`<>''";
+            	break;
         }
 
         $aMethod['params'][0] = "SELECT " . ($bReturnCount ? "SQL_CALC_FOUND_ROWS" : "") . "
                 `tw`.`id` AS `id`,
-                `tw`.`page_id` AS `page_id`,
-                `tw`.`module` AS `module`,
+                `tp`.`id` AS `page_id`,
                 `tp`.`index` AS `page_index`,
                 `tp`.`name` AS `page_name`,
                 `tp`.`header` AS `page_header`,
                 `tp`.`caption` AS `page_caption`,
                 `tp`.`icon` AS `page_icon`,
+                `tw`.`module` AS `module`,
                 `tw`.`url` AS `url`,
                 `tw`.`click` AS `click`,
                 `tw`.`icon` AS `icon`,

+ 22 - 3
studio/js/launcher.js

@@ -10,8 +10,9 @@ function BxDolStudioLauncher(oOptions) {
     this.sObjName = oOptions.sObjName == undefined ? 'oBxDolStudioLauncher' : oOptions.sObjName;
     this.sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
     this.iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'fast' : oOptions.iAnimationSpeed;
+    this.bInit = oOptions.bInit == undefined ? true : oOptions.bInit;
 
-    //--- Jitter Settings ---//
+	//--- Jitter Settings ---//
     this.aJitterConf = {
 		item: '.bx-std-widget-icon',
 		elements: '.bx-std-widget-actions,.bx-std-widget-icon-jitter,.bx-std-widget-caption-jitter'
@@ -23,7 +24,13 @@ function BxDolStudioLauncher(oOptions) {
 		placeholder: 'bx-std-widget bx-std-widget-empty'
     };
 
+    if(this.bInit)
+    	this.init();
+}
+
+BxDolStudioLauncher.prototype.init = function() {
     var $this = this;
+
     $(window).bind('resize', function(e) {
 		$this.resize();
 	});
@@ -56,7 +63,19 @@ function BxDolStudioLauncher(oOptions) {
     	if($this._isFavorites())
     		$('.bx-menu-tab-favorite').addClass('bx-menu-tab-active');
     });
-}
+};
+
+BxDolStudioLauncher.prototype.updateCache = function() {
+	var oDate = new Date();
+
+	$.get(
+		this.sActionsUrl,
+		{
+			action: 'launcher-update-cache',
+			_t:oDate.getTime()
+		}
+	);
+};
 
 BxDolStudioLauncher.prototype.resize = function() {
 	$('.bx-std-widgets').each(function() {
@@ -71,7 +90,7 @@ BxDolStudioLauncher.prototype.resize = function() {
 
 		for(var i = 1; i * iWidgetsPerLine <= iWidgetsTotal; i++)
 			oWidget.eq(i * iWidgetsPerLine).addClass('bx-std-widget-nl');
-	})
+	});
 };
 
 BxDolStudioLauncher.prototype.reorder = function(oDraggable) {

+ 1 - 1
studio/template/css/launcher.css

@@ -165,7 +165,7 @@ div.bx-std-widget-icon-jitter img {
 
 div.bx-std-widget-notices {
     position: absolute;
-    top: -3px;
+    top: 0px;
     left: 45px;
     width: 38px;
     height: 27px;

+ 9 - 0
studio/template/launcher_cache_updater.html

@@ -0,0 +1,9 @@
+<script defer type="text/javascript">
+<!--
+var __js_object__ = new BxDolStudioLauncher({
+    sActionUrl: '<bx_url_studio />launcher.php',
+    bInit: false
+});
+__js_object__.updateCache();
+-->
+</script>

+ 36 - 20
studio/template/scripts/BxBaseStudioDashboard.php

@@ -63,24 +63,39 @@ class BxBaseStudioDashboard extends BxDolStudioDashboard
     	return $oPage->getCode();
     }
 
+    public function serviceGetWidgetNotices() {
+    	$iResult = 0;
+
+    	//--- Check Version
+    	$sVersionAvailable = $this->getVersionAvailable();
+    	if($sVersionAvailable !== false)
+    		$iResult += 1;
+
+    	//--- Check Host Requirements
+    	bx_import('BxDolStudioToolsAudit');
+		$oAudit = new BxDolStudioToolsAudit();
+
+    	foreach($this->aItemsHTools as $sTitle => $sFunc) {
+    		$aResult = $oAudit->checkRequirements(BX_DOL_AUDIT_OK, $sFunc);
+			if(empty($aResult))
+				$iResult += 1;
+    	}
+
+    	return $iResult;
+    }
+
 	public function serviceGetBlockVersion()
     {
-    	$bVersionAvailable = false;
-    	$sVersionAvailable = '';
-
-    	$oUpgrader = bx_instance('BxDolUpgrader'); 
-    	$aUpdateInfo = $oUpgrader->getVersionUpdateInfo();
-    	if($oUpgrader->isNewVersionAvailable($aUpdateInfo)) {
-    		$bVersionAvailable = true;
-    		$sVersionAvailable = _t('_adm_dbd_txt_dolphin_n_available', $aUpdateInfo['latest_version']);
-    	}
+    	$sVersionAvailable = $this->getVersionAvailable();
+    	if($sVersionAvailable !== false)
+    		$sVersionAvailable = _t('_adm_dbd_txt_dolphin_n_available', $sVersionAvailable);
 
         $sContent = BxDolStudioTemplate::getInstance()->parseHtmlByName('dbd_versions.html', array(
             'domain' => getParam('site_title'),
             'version' => bx_get_ver(),
             'installed' => bx_time_js(getParam('sys_install_time')),
         	'bx_if:show_version_available' => array(
-        		'condition' => $bVersionAvailable,
+        		'condition' => !empty($sVersionAvailable),
         		'content' => array(
         			'version_available' => $sVersionAvailable
         		)
@@ -170,20 +185,14 @@ class BxBaseStudioDashboard extends BxDolStudioDashboard
 		if(!$bDynamic) {
 			bx_import('BxDolStudioToolsAudit');
 			$oAudit = new BxDolStudioToolsAudit();
-	
+
 	        bx_import('BxTemplFunctions');
 	        $oFunc = BxTemplFunctions::getInstance();
-	
-	        $aCheckRequirements = array (
-	            'PHP' => 'requirementsPHP',
-	            'MySQL' => 'requirementsMySQL',
-	            'Web Server' => 'requirementsWebServer',
-	        );
-	
+
 	        $aLevels = array (BX_DOL_AUDIT_FAIL, BX_DOL_AUDIT_WARN, BX_DOL_AUDIT_UNDEF);
-	
+
 	        $aTmplVarsItems = array();
-	        foreach ($aCheckRequirements as $sTitle => $sFunc) {
+	        foreach ($this->aItemsHTools as $sTitle => $sFunc) {
 	            $sStatus = BX_DOL_AUDIT_OK;
 	            foreach ($aLevels as $sLevel) { 
 	                $a = $oAudit->checkRequirements($sLevel, $sFunc);
@@ -249,6 +258,13 @@ class BxBaseStudioDashboard extends BxDolStudioDashboard
 
 		return array('content' => $sContent, 'menu' => $aMenu);
 	}
+
+    private function getVersionAvailable()
+    {
+    	$oUpgrader = bx_instance('BxDolUpgrader'); 
+    	$aUpdateInfo = $oUpgrader->getVersionUpdateInfo();
+    	return $oUpgrader->isNewVersionAvailable($aUpdateInfo) ? $aUpdateInfo['latest_version'] : false;
+    }
 }
 
 /** @} */

+ 26 - 6
studio/template/scripts/BxBaseStudioLauncher.php

@@ -15,18 +15,20 @@ bx_import('BxDolStudioTemplate');
 
 class BxBaseStudioLauncher extends BxDolStudioLauncher
 {
-    function __construct()
+    public function __construct()
     {
         parent::__construct();
     }
-    function getPageIndex()
+
+    public function getPageIndex()
     {
         if(!is_array($this->aPage || empty($this->aPage)))
             return BX_PAGE_DEFAULT;
 
         return !empty($this->aPage[$this->sPageSelected]) ? $this->aPage[$this->sPageSelected]->getPageIndex() : BX_PAGE_DEFAULT;
     }
-    function getPageJs()
+
+    public function getPageJs()
     {
         $aJs = array(
             'jquery-ui/jquery.ui.core.min.js',
@@ -43,11 +45,13 @@ class BxBaseStudioLauncher extends BxDolStudioLauncher
 
         return $aJs;
     }
-    function getPageJsObject()
+
+    public function getPageJsObject()
     {
         return BX_DOL_STUDIO_LAUNCHER_JS_OBJECT;
     }
-    function getPageCss()
+
+    public function getPageCss()
     {
         $aCss = array('launcher.css');
         foreach($this->aIncludes as $sName => $oInclude)
@@ -55,7 +59,8 @@ class BxBaseStudioLauncher extends BxDolStudioLauncher
 
         return $aCss;
     }
-    function getPageCode($bHidden = false)
+
+    public function getPageCode($bHidden = false)
     {
         if(empty($this->aPage) || !is_array($this->aPage))
             return '';
@@ -70,6 +75,21 @@ class BxBaseStudioLauncher extends BxDolStudioLauncher
             'items' => parent::getPageCode($bHidden)
         ));
     }
+
+	public function serviceGetCacheUpdater()
+	{
+		check_logged();
+		if(!isAdmin())
+    		return '';
+
+		$oTemplate = BxDolStudioTemplate::getInstance();
+		$sContent = $oTemplate->addJs('launcher.js', true);
+		$sContent .= $oTemplate->parseHtmlByName('launcher_cache_updater.html', array(
+    		'js_object' => $this->getPageJsObject()
+    	));
+
+    	return $sContent;
+    }
 }
 
 /** @} */

+ 7 - 5
studio/template/scripts/BxBaseStudioWidgets.php

@@ -12,12 +12,12 @@ bx_import('BxDolStudioWidgets');
 
 class BxBaseStudioWidgets extends BxDolStudioWidgets
 {
-    function __construct($mixedPageName)
+    public function __construct($mixedPageName)
     {
         parent::__construct($mixedPageName);
     }
 
-    function getPageCode($bHidden = false)
+    public function getPageCode($bHidden = false)
     {
         if(empty($this->aPage) || !is_array($this->aPage))
             return BxDolStudioTemplate::getInstance()->displayPageNotFound();
@@ -32,7 +32,7 @@ class BxBaseStudioWidgets extends BxDolStudioWidgets
         return $sContent;
     }
 
-    function getPageWidgets()
+    public function getPageWidgets()
     {
         if(empty($this->aPage) || !is_array($this->aPage))
             return BxDolStudioTemplate::getInstance()->displayPageNotFound();
@@ -108,6 +108,8 @@ class BxBaseStudioWidgets extends BxDolStudioWidgets
             $sIcon = $this->getIcon($aWidget);
             $bIcon = strpos($sIcon, '.') === false;
 
+            $sNotices = !empty($this->aWidgetsNotices[$aWidget['id']]) ? $this->aWidgetsNotices[$aWidget['id']] : '';
+
             $aTmplVars[] = array(
                 'id' => $aWidget['id'],
                 'url' => !empty($aWidget['url']) ? $oTemplate->parseHtmlByContent($aWidget['url'], $aParseVars, array('{', '}')) : 'javascript:void(0)',
@@ -124,9 +126,9 @@ class BxBaseStudioWidgets extends BxDolStudioWidgets
                     )
                 ),
                 'bx_if:show_notice' => array(
-                    'condition' => !empty($aWidget['cnt_notices']),
+                    'condition' => !empty($sNotices),
                     'content' => array(
-                        'content' => $aWidget['cnt_notices']
+                        'content' => $sNotices
                     )
                 ),
                 'bx_if:show_actions' => array(