فهرست منبع

#1063 - bugfix & improvements

RomanL 8 سال پیش
والد
کامیت
452f69389b

+ 32 - 0
modules/boonex/quoteofday/classes/BxQuoteOfDayAlertsResponse.php

@@ -0,0 +1,32 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    QuoteOfTheDay Quote of the Day
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxQuoteOfDayAlertsResponse extends BxBaseModTextAlertsResponse
+{
+    
+    protected $MODULE;
+	protected $_oModule;
+    
+    public function __construct()
+    { 
+        $this->MODULE = 'bx_quoteofday';
+    	$this->_oModule = BxDolModule::getInstance($this->MODULE);
+        parent::__construct();
+    }
+    
+    public function response($oAlert)
+    {
+        if ($oAlert->aExtras['option']=="bx_quoteofday_source" || $oAlert->aExtras['option']=="bx_quoteofday_rss_url" || $oAlert->aExtras['option']=="bx_quoteofday_selection_mode"){
+            $this->_oModule->RemoveQuoteFromCache();
+        }
+    }
+}
+/** @} */

+ 8 - 6
modules/boonex/quoteofday/classes/BxQuoteofdayConfig.php

@@ -1,16 +1,17 @@
 <?php defined('BX_DOL') or die('hack attempt');
 /**
- * Copyright (c) Vendor
- * 
- * @defgroup    Quote of the Day
- * @ingroup     VendorModules
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    QuoteOfTheDay Quote of the Day
+ * @ingroup     UnaModules
  *
  * @{
  */
 
 bx_import('BxDolModuleConfig');
 
-class BxQuoteofdayConfig extends BxDolModuleConfig 
+class BxQuoteOfDayConfig extends BxDolModuleConfig 
 {
 	function __construct($aModule) 
     {
@@ -18,7 +19,8 @@ class BxQuoteofdayConfig extends BxDolModuleConfig
 		$this->CNF = array (
 			'OBJECT_GRID' => 'bx_quoteofday_internal',
 			'CACHEKEY' => 'bx_quoteofday',
-			 // database tables
+			 
+            // database tables
             'TABLE_ENTRIES' => $aModule['db_prefix'] . 'internal',
 			
 			 // database fields

+ 6 - 6
modules/boonex/quoteofday/classes/BxQuoteofdayDb.php

@@ -1,19 +1,19 @@
 <?php defined('BX_DOL') or die('hack attempt');
 /**
- * Copyright (c) Vendor
- * 
- * @defgroup    Quote of the Day module
- * @ingroup     VendorModules
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    QuoteOfTheDay Quote of the Day
+ * @ingroup     UnaModules
  *
  * @{
  */
 
 bx_import('BxDolModuleDb');
 
-class BxQuoteofdayDb extends BxBaseModGeneralDb
+class BxQuoteOfDayDb extends BxBaseModGeneralDb
 {
 	
-	
 	function __construct(&$oConfig) 
     {
 		parent::__construct($oConfig);	

+ 4 - 12
modules/boonex/quoteofday/classes/BxQuoteofdayGridInternal.php

@@ -3,13 +3,13 @@
  * Copyright (c) UNA, Inc - https://una.io
  * MIT License - https://opensource.org/licenses/MIT
  *
- * @defgroup     Quote of the Day module
+ * @defgroup    QuoteOfTheDay Quote of the Day
  * @ingroup     UnaModules
- * 
+ *
  * @{
  */
 
-class BxQuoteofdayGridInternal extends BxTemplGrid
+class BxQuoteOfDayGridInternal extends BxTemplGrid
 {
 	protected $MODULE;
 	protected $_oModule;
@@ -27,13 +27,8 @@ class BxQuoteofdayGridInternal extends BxTemplGrid
         return parent::_getCellDefault ($mixedValue, $sKey, $aField, $aRow);
     }
 	
-	
 	public function performActionAdd()
     {
-		$oCheckAllowedViewValue=$this->_oModule->checkAcl();
-		if ($oCheckAllowedViewValue !== CHECK_ACTION_RESULT_ALLOWED)
-			return "";
-			
 		$sAction = 'add';
 		$oForm = BxDolForm::getObjectInstance('bx_quoteofday','bx_quoteofday_entry_add'); // get form instance for specified form object and display
 		if (!$oForm)
@@ -62,10 +57,6 @@ class BxQuoteofdayGridInternal extends BxTemplGrid
     
 	public function performActionEdit()
     {
-		$oCheckAllowedViewValue=$this->_oModule->checkAcl();
-		if ($oCheckAllowedViewValue !== CHECK_ACTION_RESULT_ALLOWED)
-			return "";
-		
 		$sAction = 'edit';
 		$aIds = bx_get('ids');
 		$iId = $aIds[0];
@@ -101,6 +92,7 @@ class BxQuoteofdayGridInternal extends BxTemplGrid
         $aIds = bx_get('ids');
 		$iId = $aIds[0];
         $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iId);
+        $this->_oModule->RemoveQuoteFromCache();
         $this->_oModule->PutQuoteToCache($aContentInfo["text"]);
         $aRes = array('msg' => _t('_bx_quoteofday_grid_action_title_adm_publish_text'));
         echoJson($aRes);

+ 155 - 63
modules/boonex/quoteofday/classes/BxQuoteofdayModule.php

@@ -1,93 +1,207 @@
 <?php defined('BX_DOL') or die('hack attempt');
 /**
- * Copyright (c) Vendor
- * 
- * @defgroup    Quote of the Day module
- * @ingroup     VendorModules
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    QuoteOfTheDay Quote of the Day
+ * @ingroup     UnaModules
  *
  * @{
  */
+
 define('BX_QOD_SOURCE_INTERNAL', 'internal');
 define('BX_QOD_SOURCE_RSS', 'rss');
 
-bx_import('BxDolModule');
+define('BX_QOD_SELECTION_MODE_BY_RANDOM', 'random');
+define('BX_QOD_SELECTION_MODE_BY_ORDER', 'order');
 
-class BxQuoteofdayModule extends BxBaseModGeneralModule 
+define('BX_QOD_LIFETIME_IN_SECONDS', 86400);
+
+class BxQuoteOfDayModule extends BxBaseModGeneralModule 
 {
     function __construct(&$aModule) 
     {
         parent::__construct($aModule);
     }
 
-	// ====== SERVICE METHODS
+	
+    /**
+     * Service methods
+     */
+    /**
+     * @page service Service Calls
+     * @section bx_quoteofday Quote of the Day
+     * @subsection bx_quoteofday-other Other
+     * @subsubsection bx_quoteofday-get_sources get_sources
+     * 
+     * @code bx_srv('bx_quoteofday', 'get_sources', [...]); @endcode
+     * 
+     * Get list of avaliable sources types for studio settings (rss feed or internal list)
+     * 
+     * @return an array with avaliable sources. 
+     * 
+     * @see BxQuoteOfDayModule::serviceGetSources
+     */
+    /** 
+     * @ref bx_quoteofday-get_sources "get_sources"
+     */
+    
 	public function serviceGetSources()
     {
-		//RL-TO-IMPROVE GET SOURCES FROM DB AND MULTISELECT
         $aResult = array();
         $aChoices = array(BX_QOD_SOURCE_INTERNAL, BX_QOD_SOURCE_RSS);
         foreach($aChoices as $sChoice) 
 		 	$aResult[$sChoice]=_t('_bx_quoteofday_source_'. $sChoice);
         return $aResult;
     }
+    
+    /**
+     * @page service Service Calls
+     * @section bx_quoteofday Quote of the Day
+     * @subsection bx_quoteofday-other Other
+     * @subsubsection bx_quoteofday-get_selection_mode selection_mode
+     * 
+     * @code bx_srv('bx_quoteofday', 'get_selection_mode', [...]); @endcode
+     * 
+     * Get list of avaliable selection mode(randome mode or ordered mode) for studio settings
+     * 
+     * @return an array with selection modes.
+     * 
+     * @see BxQuoteOfDayModule::serviceGetSelectionMode
+     */
+    /** 
+     * @ref bx_quoteofday-get_selection_mode "get_selection_mode"
+     */
+    public function serviceGetSelectionMode()
+    {
+        $aResult = array();
+        $aChoices = array(BX_QOD_SELECTION_MODE_BY_RANDOM, BX_QOD_SELECTION_MODE_BY_ORDER);
+        foreach($aChoices as $sChoice) 
+            $aResult[$sChoice]=_t('_bx_quoteofday_selection_mode_by_'. $sChoice);
+        return $aResult;
+    }
 	
+    
+    /**
+     * @page service Service Calls
+     * @section bx_quoteofday Quote of the Day
+     * @subsection bx_quoteofday-other Other
+     * @subsubsection bx_quoteofday-get_menu_addon_manage_tools get_menu_addon_manage_tools
+     * 
+     * @code bx_srv('bx_quoteofday', 'get_menu_addon_manage_tools', [...]); @endcode
+     * 
+     * Get count of hidden items in internal data for dashbord 
+     * 
+     * @return digit - count of hidden item .
+     * 
+     * @see BxQuoteOfDayModule::serviceGetMenuAddonManageTools
+     */
+    /** 
+     * @ref bx_quoteofday-get_menu_addon_manage_tools "get_menu_addon_manage_tools"
+     */
 	public function serviceGetMenuAddonManageTools()
 	{
 		return $this->_oDb->getHiddenItemsCount();
 	}
 	
-	//##### get current Quote  #####
-	/*public function actionGetQuote()
-    {
-		echo $this->serviceGetQuote();
-	}
-	*/
-	
+    /**
+     * @page service Service Calls
+     * @section bx_quoteofday Quote of the Day
+     * @subsection bx_quoteofday-other Other
+     * @subsubsection bx_quoteofday-get_quote
+     * 
+     * @code bx_srv('bx_quoteofday', 'get_quote', [...]); @endcode
+     * 
+     * Get current Quote of the Day
+     * 
+     * @return string - current Quote of the Day from system cache .
+     * 
+     * @see BxQuoteOfDayModule::serviceGetQuote
+     */
+    /** 
+     * @ref bx_quoteofday-get_quote "get_quote"
+     */
 	public function serviceGetQuote()
     {
-		$oCachObject = $this->_oDb->getDbCacheObject();
-		return $oCachObject->getData($this->_oConfig->CNF['CACHEKEY']);
+		$sTextFromCache = $this->GetQuoteFromCache();
+        if ($sTextFromCache == null || $sTextFromCache == "")
+        {
+            $sTextFromCache = $this->serviceSetQuote();
+        }
+        return  $sTextFromCache;
 	}
 	
-	
-	//##### Set current Quote from cron #####
-	/*public function actionSetQuote()
-    {
-		echo $this->serviceSetQuote();
-	}*/
-	
-	
+    /**
+     * @page service Service Calls
+     * @section bx_quoteofday Quote of the Day
+     * @subsection bx_quoteofday-other Other
+     * @subsubsection bx_quoteofday-set_quote
+     * 
+     * @code bx_srv('bx_quoteofday', 'set_quote', [...]); @endcode
+     * 
+     * Define and store in cache Quote of the Day depend on current module settings
+     * 
+     * @return string - current Quote of the Day from system cache.
+     * 
+     * @see BxQuoteOfDayModule::serviceSetQuote
+     */
+    /** 
+     * @ref bx_quoteofday-set_quote "set_quote"
+     */
 	public function serviceSetQuote()
     {
 		$sRssUrl = getParam('bx_quoteofday_rss_url');
 		$iRssMaxItems = intval(getParam('bx_quoteofday_rss_max_items'));
 		$aSources=explode(',',getParam('bx_quoteofday_source'));
+        $sSelectionType=getParam('bx_quoteofday_selection_mode');
 		
 		$aData=array();
 		
 		//##### Get data from internal set #####
-		if (in_array(BX_QOD_SOURCE_INTERNAL,$aSources))
-		{
+		if (in_array(BX_QOD_SOURCE_INTERNAL,$aSources)) {
 			$aData=array_merge($aData,$this->getInternalData());
 		}
 		
 		//##### Get data from rss #####
 		if (in_array(BX_QOD_SOURCE_RSS,$aSources) && $sRssUrl!="" && $iRssMaxItems>0)
 			$aData = array_merge($aData,$this->getRssData($sRssUrl,$iRssMaxItems));
-		
-		
-		$iDayOfYear = date('z');
-		//$iDayOfYear=rand(1,365);
-		$iIndex = $iDayOfYear % count($aData);
-        $this->PutQuoteToCache($aData[$iIndex]);
+		$iIndex = -1;
+		if ($sSelectionType == BX_QOD_SELECTION_MODE_BY_RANDOM) {
+            $iIndex = rand(0,count($aData)-1);
+        }
+        else {
+            $iDayOfYear = date('z');
+            $iIndex = $iDayOfYear % count($aData);
+        }
+        $sTextToChache = "";
+        if ($iIndex > -1 && count($aData) > 0) {
+            $sTextToChache = $aData[$iIndex];
+            $this->PutQuoteToCache($sTextToChache);
+        }
+        return $sTextToChache;
 	}
     
     
     public function PutQuoteToCache($quoteText)
     {
         $oCachObject = $this->_oDb->getDbCacheObject();
-		$oCachObject->setData($this->_oConfig->CNF['CACHEKEY'],$quoteText);
+		$oCachObject->setData($this->_oConfig->CNF['CACHEKEY'],$quoteText,BX_QOD_LIFETIME_IN_SECONDS);
+    }
+    
+    public function GetQuoteFromCache()
+    {
+        $oCachObject = $this->_oDb->getDbCacheObject();
+		return $oCachObject->getData($this->_oConfig->CNF['CACHEKEY'],BX_QOD_LIFETIME_IN_SECONDS); 
     }
 	
+    
+    public function RemoveQuoteFromCache()
+    {
+        $oCachObject = $this->_oDb->getDbCacheObject();
+		$oCachObject->delData($this->_oConfig->CNF['CACHEKEY']);
+    }
+	
+	
 	private function getInternalData()
     {
 		return $this->_oDb->getData();
@@ -95,32 +209,25 @@ class BxQuoteofdayModule extends BxBaseModGeneralModule
 	
 	private function getRssData($sRssUrl,$iRssMaxItems)
     {
-		$oTmpRv=array();
+		$aTmpRv=array();
 		$oXmlParser = BxDolXmlParser::getInstance();
-        $sXmlContent = file_get_contents($sRssUrl);
-		
+        $sXmlContent = bx_file_get_contents($sRssUrl);
 		$oTmp=$oXmlParser->getTags($sXmlContent, 'description');
-		if (is_array($oTmp))
-		{
+		if (is_array($oTmp)) {
 			$iC=0;
-			while (list($key,$value ) = each($oTmp)) {
+			while (list( ,$oValue) = each($oTmp)) {
 				if ($iC==$iRssMaxItems) break;
-				if (isset($value['value']) && $value['level']==4 && trim(strip_tags($value['value'])) != "")
-				{
-					array_push($oTmpRv,$value['value']);
+				if (isset($oValue['value']) && $oValue['level']==4 && trim(strip_tags($oValue['value'])) != "") {
+					array_push($aTmpRv,$oValue['value']);
 					$iC++;
 				}
 			}
 		}
-		return $oTmpRv;
+		return $aTmpRv;
 	}
 	
 	public function serviceGetQuotesManage()
     {
-		$oCheckAllowedViewValue=$this->checkAcl();
-		if ($oCheckAllowedViewValue !== CHECK_ACTION_RESULT_ALLOWED)
-			return MsgBox($oCheckAllowedViewValue);
-	
 		$this->_oTemplate->addJs('jquery.form.min.js');
 		$oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID']);
 		if(!$oGrid)
@@ -128,21 +235,6 @@ class BxQuoteofdayModule extends BxBaseModGeneralModule
 		return $oGrid->getCode();
 	
     }
-	
-	
-	 /**
-     * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
-     */
-    public function checkAcl ($isPerformAction = false)
-    {
-        // check ACL
-        $aCheck = checkActionModule($this->_iProfileId, 'manage entries', $this->getName(), $isPerformAction);
-        if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
-            return $aCheck[CHECK_ACTION_MESSAGE];
-        return CHECK_ACTION_RESULT_ALLOWED;
-    }
-	 
-	
 }
 
 /** @} */

+ 2 - 2
modules/boonex/quoteofday/classes/BxQuoteofdayStudioPage.php

@@ -3,7 +3,7 @@
  * Copyright (c) UNA, Inc - https://una.io
  * MIT License - https://opensource.org/licenses/MIT
  *
- * @defgroup    Forum Forum
+ * @defgroup    QuoteOfTheDay Quote of the Day
  * @ingroup     UnaModules
  *
  * @{
@@ -11,7 +11,7 @@
 
 define('BX_DOL_STUDIO_MOD_TYPE_QUOTES', 'quotes');
 
-class BxQuoteofdayStudioPage extends BxTemplStudioModule
+class BxQuoteOfDayStudioPage extends BxTemplStudioModule
 {
 	protected $_sModule;
 	protected $_oModule;

+ 6 - 5
modules/boonex/quoteofday/classes/BxQuoteofdayTemplate.php

@@ -1,16 +1,17 @@
 <?php defined('BX_DOL') or die('hack attempt');
 /**
- * Copyright (c) Vendor
- * 
- * @defgroup    Quote of the Day module
- * @ingroup     VendorModules
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    QuoteOfTheDay Quote of the Day
+ * @ingroup     UnaModules
  *
  * @{
  */
 
 bx_import ('BxDolModuleTemplate');
 
-class BxQuoteofdayTemplate extends BxDolModuleTemplate 
+class BxQuoteOfDayTemplate extends BxDolModuleTemplate 
 {    
 	function __construct(&$oConfig, &$oDb) 
     {

+ 5 - 5
modules/boonex/quoteofday/install/config.php

@@ -3,7 +3,7 @@
  * Copyright (c) UNA, Inc - https://una.io
  * MIT License - https://opensource.org/licenses/MIT
  *
- * @defgroup    Quote of the Day
+ * @defgroup    QuoteOfTheDay Quote of the Day
  * @ingroup     UnaModules
  *
  * @{
@@ -18,12 +18,12 @@ $aConfig = array(
     'name' => 'bx_quoteofday',
     'title' => 'Quote of the Day',
     'note' => 'Quote of the Day module.',
-    'version' => '1.0.0',
+    'version' => '1.0.0.DEV',
     'vendor' => 'BoonEx',
 	'help_url' => 'http://feed.una.io/?section={module_name}',
 
     'compatible_with' => array(
-        '9.0.0-RC4'
+        '9.0.x'
     ),
 
     /**
@@ -33,12 +33,12 @@ $aConfig = array(
     'home_uri' => 'quoteofday',
 
     'db_prefix' => 'bx_quoteofday_',
-    'class_prefix' => 'BxQuoteofday',
+    'class_prefix' => 'BxQuoteOfDay',
 
     /**
      * Category for language keys.
      */
-    'language_category' => 'Quoteofday',
+    'language_category' => 'QuoteOfDay',
 
     /**
      * Installation/Uninstallation Section.

+ 2 - 2
modules/boonex/quoteofday/install/installer.php

@@ -3,13 +3,13 @@
  * Copyright (c) UNA, Inc - https://una.io
  * MIT License - https://opensource.org/licenses/MIT
  *
- * @defgroup    Quote of the Day
+ * @defgroup    QuoteOfTheDay Quote of the Day
  * @ingroup     UnaModules
  *
  * @{
  */
 
-class BxQuoteofdayInstaller extends BxBaseModTextInstaller
+class BxQuoteOfDayInstaller extends BxBaseModTextInstaller
 {
     function __construct($aConfig)
     {

+ 3 - 0
modules/boonex/quoteofday/install/langs/en.xml

@@ -26,4 +26,7 @@
 	<string name="_bx_quoteofday_acl_action_manage_entries"><![CDATA[use Quote of the Day management]]></string>
 	<string name="_bx_quoteofday_menu_item_title_system_admt_manage"><![CDATA[Quotes of the day - {addon} hidden]]></string>
 	<string name="_bx_quoteofday_form_entry_input_text_err"><![CDATA[Text field can't be empty]]></string>
+  <string name="_bx_quoteofday_selection_mode"><![CDATA[Quote of the Day selected by]]></string>
+  <string name="_bx_quoteofday_selection_mode_by_order"><![CDATA[By order]]></string>
+  <string name="_bx_quoteofday_selection_mode_by_random"><![CDATA[By random]]></string>
 </resources>

+ 10 - 10
modules/boonex/quoteofday/install/sql/disable.sql

@@ -1,6 +1,7 @@
+SET @sName = 'bx_quoteofday';
 
 -- SETTINGS
-SET @iTypeId = (SELECT `ID` FROM `sys_options_types` WHERE `name` = 'bx_quoteofday' LIMIT 1);
+SET @iTypeId = (SELECT `ID` FROM `sys_options_types` WHERE `name` = @sName LIMIT 1);
 SET @iCategId = (SELECT `ID` FROM `sys_options_categories` WHERE `type_id` = @iTypeId LIMIT 1);
 DELETE FROM `sys_options` WHERE `category_id` = @iCategId;
 DELETE FROM `sys_options_categories` WHERE `type_id` = @iTypeId;
@@ -11,17 +12,16 @@ DELETE FROM `sys_objects_grid` WHERE `object` IN ('bx_quoteofday_internal');
 DELETE FROM `sys_grid_fields` WHERE `object` IN ('bx_quoteofday_internal');
 DELETE FROM `sys_grid_actions` WHERE `object` IN ('bx_quoteofday_internal');
 
--- CRON
-DELETE FROM sys_cron_jobs WHERE `name` in('bxquoteofday');
-
 -- PAGES
-DELETE FROM `sys_objects_page` WHERE `module` = 'bx_quoteofday';
-DELETE FROM `sys_pages_blocks` WHERE `module` = 'bx_quoteofday';
+DELETE FROM `sys_objects_page` WHERE `module` = @sName;
+DELETE FROM `sys_pages_blocks` WHERE `module` = @sName;
 
 -- MENU
-DELETE FROM `sys_menu_items` WHERE `module` = 'bx_quoteofday';
+DELETE FROM `sys_menu_items` WHERE `module` = @sName;
+
+-- ALERTS
+SET @iHandler := (SELECT `id` FROM `sys_alerts_handlers` WHERE `name` = @sName LIMIT 1);
+DELETE FROM `sys_alerts` WHERE `handler_id` = @iHandler;
+DELETE FROM `sys_alerts_handlers` WHERE `id` = @iHandler;
 
--- ACL
-DELETE `sys_acl_actions`, `sys_acl_matrix` FROM `sys_acl_actions`, `sys_acl_matrix` WHERE `sys_acl_matrix`.`IDAction` = `sys_acl_actions`.`ID` AND `sys_acl_actions`.`Module` = 'bx_quoteofday';
-DELETE FROM `sys_acl_actions` WHERE `Module` = 'bx_quoteofday';
 

+ 28 - 47
modules/boonex/quoteofday/install/sql/enable.sql

@@ -1,77 +1,58 @@
--- SETTINGS
+SET @sName = 'bx_quoteofday';
 
+-- SETTINGS
 SET @iTypeOrder = (SELECT IFNULL(MAX(`order`), 0) + 1 FROM `sys_options_types` WHERE `group` = 'modules');
 
-INSERT INTO sys_options_types(`group`, name, caption, icon, `order`) 
-VALUES('modules', 'bx_quoteofday', '_bx_quoteofday_adm_stg_cpt_type', 'bx_quoteofday@modules/boonex/quoteofday/|std-icon.svg', IF(ISNULL(@iTypeOrder), 1, @iTypeOrder + 1));
+INSERT INTO `sys_options_types` (`group`, `name`, `caption`, `icon`, `order`) 
+VALUES('modules', @sName, '_bx_quoteofday_adm_stg_cpt_type', 'bx_quoteofday@modules/boonex/quoteofday/|std-icon.svg', IF(ISNULL(@iTypeOrder), 1, @iTypeOrder + 1));
+
 SET @iTypeId = LAST_INSERT_ID();
 
-INSERT INTO sys_options_categories(`type_id`, name, caption, hidden, `order`) VALUES(@iTypeId,  'bx_quoteofday_general', '_bx_quoteofday_adm_stg_cpt_category_general', 0, 1);
+INSERT INTO `sys_options_categories` (`type_id`, `name`, `caption`, `hidden`, `order`) VALUES(@iTypeId,  'bx_quoteofday_general', '_bx_quoteofday_adm_stg_cpt_category_general', 0, 1);
 SET @iCategoryId = LAST_INSERT_ID();
 
-
-INSERT INTO sys_options(category_id, name, caption, value, type, extra, `check`, check_params, check_error, `order`) VALUES
+INSERT INTO `sys_options` (`category_id`, `name`, `caption`, `value`, `type`, `extra`, `check`, `check_params`, `check_error`, `order`) VALUES
 (@iCategoryId, 'bx_quoteofday_source', '_bx_quoteofday_source', 'internal', 'list', 'a:2:{s:6:"module";s:13:"bx_quoteofday";s:6:"method";s:11:"get_sources";}', '', '', '', 1),
 (@iCategoryId, 'bx_quoteofday_rss_url', '_bx_quoteofday_option_rss_url', '', 'digit', '', '', '', '', 2),
-(@iCategoryId, 'bx_quoteofday_rss_max_items', '_bx_quoteofday_rss_max_items', '5', 'digit', '', '', '', '', 3);
-
+(@iCategoryId, 'bx_quoteofday_rss_max_items', '_bx_quoteofday_rss_max_items', '5', 'digit', '', '', '', '', 3),
+(@iCategoryId, 'bx_quoteofday_selection_mode', '_bx_quoteofday_selection_mode', 'byrandom', 'select', 'a:2:{s:6:"module";s:13:"bx_quoteofday";s:6:"method";s:18:"get_selection_mode";}', '', '', '', 4);
 
 -- GRIDS: moderation tools
-INSERT INTO sys_objects_grid(object, source_type, source, `table`, field_id, field_order, field_active, paginate_url, paginate_per_page, paginate_simple, paginate_get_start, paginate_get_per_page, filter_fields, filter_fields_translatable, filter_mode, sorting_fields, sorting_fields_translatable, visible_for_levels, override_class_name, override_class_file) 
-VALUES('bx_quoteofday_internal', 'Sql', 'SELECT * FROM `bx_quoteofday_internal` WHERE 1 ', 'bx_quoteofday_internal', 'id', 'added', 'status', '', 20, NULL, 'start', '', 'text', '', 'auto', '', '', 2147483647, 'BxQuoteofdayGridInternal', 'modules/boonex/quoteofday/classes/BxQuoteofdayGridInternal.php');
-
+INSERT INTO `sys_objects_grid` (object, `source_type`, `source`, `table`, `field_id`, `field_order`, `field_active`, `paginate_url`, `paginate_per_page`, `paginate_simple`, `paginate_get_start`, `paginate_get_per_page`, `filter_fields`, `filter_fields_translatable`, `filter_mode`, `sorting_fields`, `sorting_fields_translatable`, `visible_for_levels`, `override_class_name`, `override_class_file`) 
+VALUES('bx_quoteofday_internal', 'Sql', 'SELECT * FROM `bx_quoteofday_internal` WHERE 1 ', 'bx_quoteofday_internal', 'id', 'added', 'status', '', 20, NULL, 'start', '', 'text', '', 'auto', '', '', 192, 'BxQuoteOfDayGridInternal', 'modules/boonex/quoteofday/classes/BxQuoteOfDayGridInternal.php');
 
-INSERT INTO sys_grid_fields(object, name, title, width, translatable, chars_limit, params, `order`) VALUES
+INSERT INTO `sys_grid_fields` (`object`, `name`, `title`, `width`, `translatable`, `chars_limit`, `params`, `order`) VALUES
 ('bx_quoteofday_internal', 'checkbox', '_sys_select', '2%', 0, 0, '', 1),
 ('bx_quoteofday_internal', 'switcher', '_bx_quoteofday_grid_column_title_adm_active', '8%', 0, 0, '', 2),
-('bx_quoteofday_internal', 'text', '_bx_quoteofday_grid_column_title_adm_text', '40%', 0, 35, '', 3),
+('bx_quoteofday_internal', 'text', '_bx_quoteofday_grid_column_title_adm_text', '70%', 0, 35, '', 3),
 ('bx_quoteofday_internal', 'actions', '', '20%', 0, 0, '', 5);
 
-
-
-INSERT INTO sys_grid_actions(object, type, name, title, icon, icon_only, confirm, `order`) VALUES
+INSERT INTO `sys_grid_actions` (`object`, `type`, `name`, `title`, `icon`, `icon_only`, `confirm`, `order`) VALUES
 ('bx_quoteofday_internal', 'single', 'edit', '_bx_quoteofday_grid_action_title_adm_edit', 'pencil', 1, 0, 1),
 ('bx_quoteofday_internal', 'single', 'publish', '_bx_quoteofday_grid_action_title_adm_publish', 'quote-right', 1, 0, 3),
 ('bx_quoteofday_internal', 'single', 'delete', '_bx_quoteofday_grid_action_title_adm_delete', 'remove', 1, 1, 2),
 ('bx_quoteofday_internal', 'bulk', 'delete', '_bx_quoteofday_grid_action_title_adm_delete', '', 0, 1, 1),
-('bx_quoteofday_internal', 'independent', 'add', '_bx_quoteofday_grid_action_title_adm_add', 'add', 0, 0, 1);
-
--- CRON
-
-INSERT INTO sys_cron_jobs(`name`, `time`, class, `file`, service_call) VALUES('bx_quoteofday', '0 1 * * *', 'BxQuoteofdayModule', '', 'a:2:{s:6:"module";s:13:"bx_quoteofday";s:6:"method";s:9:"set_quote";}');
+('bx_quoteofday_internal', 'independent', 'add', '_bx_quoteofday_grid_action_title_adm_add', '', 0, 0, 1);
 
 -- PAGE: add block to homepage
 SET @iBlockOrder = (SELECT `order` FROM `sys_pages_blocks` WHERE `object` = 'sys_home' AND `cell_id` = 1 ORDER BY `order` DESC LIMIT 1);
 
-INSERT INTO sys_pages_blocks(object, cell_id, module, title_system, title, designbox_id, visible_for_levels, hidden_on, type, content, deletable, copyable, active, `order`) VALUES('sys_home', 1, 'bx_quoteofday', '', '_bx_quoteofday_page_block_title', 11, 2147483647, '0', 'service', 'a:2:{s:6:"module";s:13:"bx_quoteofday";s:6:"method";s:9:"get_quote";}', 1, 0, 1, IFNULL(@iBlockOrder, 0) + 1);
+INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title_system`, `title`, `designbox_id`, `visible_for_levels`, `hidden_on`, `type`, `content`, `deletable`, `copyable`, `active`, `order`) VALUES('sys_home', 1, @sName, '', '_bx_quoteofday_page_block_title', 11, 2147483647, '0', 'service', 'a:2:{s:6:"module";s:13:"bx_quoteofday";s:6:"method";s:9:"get_quote";}', 1, 1, 1, IFNULL(@iBlockOrder, 0) + 1);
 
 -- PAGE: create entry
+INSERT INTO `sys_objects_page` (`object`, `uri`, `title_system`, `title`, `module`, `cover`, `cover_image`, `layout_id`, `visible_for_levels`, `visible_for_levels_editable`, `url`, `meta_description`, `meta_keywords`, `meta_robots`, `cache_lifetime`, `cache_editable`, `deletable`, `override_class_name`, `override_class_file`) VALUES('bx_quoteofday_manage', 'quoteofday-manage', '_bx_quoteofday_page_title_manage', '_bx_quoteofday_page_title_manage', @sName, 1, 0, 5, 2147483647, 1, 'page.php?i=quoteofday-manage', '', '', '', 0, 1, 0, '', '');
 
-
-INSERT INTO sys_objects_page(object, uri, title_system, title, module, cover, cover_image, layout_id, visible_for_levels, visible_for_levels_editable, url, meta_description, meta_keywords, meta_robots, cache_lifetime, cache_editable, deletable, override_class_name, override_class_file) VALUES('bx_quoteofday_manage', 'quoteofday-manage', '_bx_quoteofday_page_title_manage', '_bx_quoteofday_page_title_manage', 'bx_quoteofday', 1, 0, 5, 2147483647, 1, 'page.php?i=quoteofday-manage', '', '', '', 0, 1, 0, '', '');
-
-INSERT INTO sys_pages_blocks(object, cell_id, module, title_system, title, designbox_id, visible_for_levels, hidden_on, type, content, deletable, copyable, active, `order`) VALUES('bx_quoteofday_manage', 1, 'bx_quoteofday', '_bx_quoteofday_page_block_title_manage', '_bx_quoteofday_page_block_title_manage', 11, 2147483647, '0', 'service', 'a:2:{s:6:"module";s:13:"bx_quoteofday";s:6:"method";s:17:"get_quotes_manage";}', 0, 1, 1, 1);
+INSERT INTO `sys_pages_blocks` (object, `cell_id`, `module`, `title_system`, `title`, `designbox_id`, `visible_for_levels`, `hidden_on`, `type`, `content`, `deletable`, `copyable`, `active`, `order`) VALUES('bx_quoteofday_manage', 1, @sName, '_bx_quoteofday_page_block_title_manage', '_bx_quoteofday_page_block_title_manage', 11, 2147483647, '0', 'service', 'a:2:{s:6:"module";s:13:"bx_quoteofday";s:6:"method";s:17:"get_quotes_manage";}', 0, 1, 1, 1);
 
 -- MENU: dashboard manage tools
 SET @iManageMenuOrder = (SELECT IFNULL(MAX(`order`), 0) FROM `sys_menu_items` WHERE `set_name`='sys_account_dashboard_manage_tools' LIMIT 1);
-INSERT INTO sys_menu_items(set_name, module, name, title_system, title, link, onclick, target, icon, addon, submenu_object, submenu_popup, visible_for_levels, active, copyable, editable, `order`) VALUES('sys_account_dashboard_manage_tools', 'bx_quoteofday', 'quoteofday-manage', '_bx_quoteofday_menu_item_title_system_admt_manage', '_bx_quoteofday_menu_item_title_system_admt_manage', 'page.php?i=quoteofday-manage', '', '_self', '', 'a:2:{s:6:"module";s:13:"bx_quoteofday";s:6:"method";s:27:"get_menu_addon_manage_tools";}', '', 0, 2147483647, 1, 0, 1, 6);
-
--- ACL
-INSERT INTO sys_acl_actions(Module, Name, AdditionalParamName, Title, `Desc`, Countable, DisabledForLevels) VALUES('bx_quoteofday', 'manage entries', NULL, '_bx_quoteofday_acl_action_manage_entries', '', 1, 3);
-
-SET @iIdActionEntryEditAny = LAST_INSERT_ID();
-
-SET @iUnauthenticated = 1;
-SET @iAccount = 2;
-SET @iStandard = 3;
-SET @iUnconfirmed = 4;
-SET @iPending = 5;
-SET @iSuspended = 6;
-SET @iModerator = 7;
-SET @iAdministrator = 8;
-SET @iPremium = 9;
-
-INSERT INTO `sys_acl_matrix` (`IDLevel`, `IDAction`) VALUES
--- manage_entries
-(@iModerator, @iIdActionEntryEditAny),
-(@iAdministrator, @iIdActionEntryEditAny);
+INSERT INTO `sys_menu_items` (`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `addon`, `submenu_object`, `submenu_popup`, `visible_for_levels`, `active`, `copyable`, `editable`, `order`) VALUES('sys_account_dashboard_manage_tools', @sName, 'quoteofday-manage', '_bx_quoteofday_menu_item_title_system_admt_manage', '_bx_quoteofday_menu_item_title_system_admt_manage', 'page.php?i=quoteofday-manage', '', '_self', '', 'a:2:{s:6:"module";s:13:"bx_quoteofday";s:6:"method";s:27:"get_menu_addon_manage_tools";}', '', 0, 2147483647, 1, 0, 1, 6);
+
+-- ALERTS
+INSERT INTO `sys_alerts_handlers` (`name`, `class`, `file`, `service_call`) VALUES 
+(@sName, 'BxQuoteOfDayAlertsResponse', 'modules/boonex/quoteofday/classes/BxQuoteOfDayAlertsResponse.php', '');
+SET @iHandler := LAST_INSERT_ID();
+
+INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
+('system', 'save_setting', @iHandler);
+

+ 17 - 21
modules/boonex/quoteofday/install/sql/install.sql

@@ -1,35 +1,31 @@
+SET @sName = 'bx_quoteofday';
+
 -- TABLE: data
-CREATE TABLE bx_quoteofday_internal (
-  id int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
-  text text NOT NULL,
-  source1 tinyint(4) NOT NULL DEFAULT 0,
-  is_active1 tinyint(4) DEFAULT 0,
-  added int(11) DEFAULT NULL,
-  status enum ('active', 'hidden') DEFAULT 'active',
-  author1 varchar(255) DEFAULT NULL,
-  status_admin enum ('active', 'hidden') DEFAULT 'active',
-  PRIMARY KEY (id),
-  FULLTEXT INDEX title_text (text)
+CREATE TABLE `bx_quoteofday_internal` (
+  `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+  `text` text NOT NULL,
+  `added` int(11) DEFAULT NULL,
+  `status` enum ('active', 'hidden') DEFAULT 'active',
+  `status_admin` enum ('active', 'hidden') DEFAULT 'active',
+  PRIMARY KEY (`id`),
+  FULLTEXT INDEX ttext (`text`)
 )
 ;
 
-
 -- FORMS
-SET @sName = 'bx_quoteofday';
-
-INSERT INTO sys_objects_form(object, module, title, action, form_attrs, submit_name, `table`, `key`, uri, uri_title, params, deletable, active, override_class_name, override_class_file) VALUES(@sName, @sName, '_bx_quoteofday_form_entry', '', 'a:1:{s:7:"enctype";s:19:"multipart/form-data";}', 'do_submit', 'bx_quoteofday_internal', 'id', '', '', '', 0, 1, '', '');
+INSERT INTO `sys_objects_form` (`object`, `module`, `title`, `action`, `form_attrs`, `submit_name`, `table`, `key`, `uri`, `uri_title`, `params`, `deletable`, `active`, `override_class_name`, `override_class_file`) VALUES(@sName, @sName, '_bx_quoteofday_form_entry', '', 'a:1:{s:7:"enctype";s:19:"multipart/form-data";}', 'do_submit', 'bx_quoteofday_internal', 'id', '', '', '', 0, 1, '', '');
 
-INSERT INTO sys_form_displays(display_name, module, object, title, view_mode) VALUES
+INSERT INTO `sys_form_displays` (`display_name`, `module`, `object`, `title`, `view_mode`) VALUES
 ('bx_quoteofday_entry_add', @sName, @sName, '_bx_quoteofday_form_entry_display_add', 0),
 ('bx_quoteofday_entry_edit', @sName, @sName, '_bx_quoteofday_form_entry_display_edit', 0);
 
-INSERT INTO sys_form_inputs(`object`, module, name, value, `values`, checked, type, caption_system, caption, info, `required`, `unique`, collapsed, html, attrs, attrs_tr, attrs_wrapper, checker_func, checker_params, checker_error, db_pass, db_params, editable, deletable) VALUES
+INSERT INTO `sys_form_inputs` (`object`, `module`, `name`, `value`, `values`, `checked`, `type`, `caption_system`, `caption`, `info`, `required`, `unique`, `collapsed`, `html`, `attrs`, `attrs_tr`, `attrs_wrapper`, `checker_func`, `checker_params`, `checker_error`, `db_pass`, `db_params`, `editable`, `deletable`) VALUES
 (@sName, @sName, 'do_submit', '_bx_quoteofday_form_entry_input_do_submit', '', 0, 'submit', '_bx_quoteofday_form_entry_input_sys_do_submit', '', '', 0, 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 (@sName, @sName, 'text', '', '', 0, 'textarea', '_bx_quoteofday_form_entry_input_sys_text', '_bx_quoteofday_form_entry_input_text', '', 1, 0, 0, 2, '', '', '', 'Avail', '', '_bx_quoteofday_form_entry_input_text_err', 'XssHtml', '', 1, 0),
 (@sName, @sName, 'cancel', '_bx_quoteofday_form_entry_input_cancel', '', 0, 'button', '_bx_dev_bp_btn_sys_block_cancel', '', '', 0, 0, 0, 0, 'a:2:{s:7:"onclick";s:45:"$(''.bx-popup-applied:visible'').dolPopupHide()";s:5:"class";s:22:"bx-def-margin-sec-left";}', '', '', 'Avail', '', '', '', '', 0, 0),
 (@sName, @sName, 'controls', '', 'do_submit,cancel', 0, 'input_set', '', '', '', 0, 0, 0, 0, '', '', '', '', '', '', '', '', 0, 0);
 
-INSERT INTO sys_form_display_inputs(display_name, input_name, visible_for_levels, active, `order`) VALUES
+INSERT INTO `sys_form_display_inputs` (`display_name`, `input_name`, `visible_for_levels`, `active`, `order`) VALUES
 ('bx_quoteofday_entry_add', 'text', 2147483647, 1, 1),
 ('bx_quoteofday_entry_add', 'controls', 2147483647, 1, 2),
 ('bx_quoteofday_entry_add', 'do_submit', 2147483647, 1, 3),
@@ -41,12 +37,12 @@ INSERT INTO sys_form_display_inputs(display_name, input_name, visible_for_levels
 
 -- STUDIO: page & widget
 INSERT INTO `sys_std_pages`(`index`, `name`, `header`, `caption`, `icon`) VALUES
-(3, 'bx_quoteofday', '_bx_quoteofday', '_bx_quoteofday', 'bx_quoteofday@modules/boonex/quoteofday/|std-icon.svg');
+(3, @sName, '_bx_quoteofday', '_bx_quoteofday', 'bx_quoteofday@modules/boonex/quoteofday/|std-icon.svg');
 
 SET @iPageId = LAST_INSERT_ID();
 
-INSERT INTO sys_std_widgets(page_id, module, url, click, icon, caption, cnt_notices, cnt_actions, bookmark) 
-VALUES(@iPageId, 'bx_quoteofday', '{url_studio}module.php?name=bx_quoteofday', '', 'bx_quoteofday@modules/boonex/quoteofday/|std-icon.svg', '_bx_quoteofday', '', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:11:"get_actions";s:6:"params";a:0:{}s:5:"class";s:18:"TemplStudioModules";}', 0);
+INSERT INTO `sys_std_widgets` (`page_id`, `module`, `url`, `click`, `icon`, `caption`, `cnt_notices`, `cnt_actions`, `bookmark`) 
+VALUES(@iPageId, @sName, '{url_studio}module.php?name=bx_quoteofday', '', 'bx_quoteofday@modules/boonex/quoteofday/|std-icon.svg', '_bx_quoteofday', '', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:11:"get_actions";s:6:"params";a:0:{}s:5:"class";s:18:"TemplStudioModules";}', 0);
 
 SET @iParentPageId = (SELECT `id` FROM `sys_std_pages` WHERE `name` = 'home');
 SET @iParentPageOrder = (SELECT IFNULL(MAX(`order`), 0) + 1 FROM `sys_std_pages_widgets` WHERE `page_id` = @iParentPageId);

+ 6 - 4
modules/boonex/quoteofday/install/sql/uninstall.sql

@@ -1,15 +1,17 @@
+SET @sName = 'bx_quoteofday';;
+
 -- TABLES
 DROP TABLE IF EXISTS `bx_quoteofday_internal`;
 
 -- FORMS
-DELETE FROM `sys_objects_form` WHERE `module` = 'bx_quoteofday';
-DELETE FROM `sys_form_displays` WHERE `module` = 'bx_quoteofday';
-DELETE FROM `sys_form_inputs` WHERE `module` = 'bx_quoteofday';
+DELETE FROM `sys_objects_form` WHERE `module` = @sName;
+DELETE FROM `sys_form_displays` WHERE `module` = @sName;
+DELETE FROM `sys_form_inputs` WHERE `module` = @sName;
 DELETE FROM `sys_form_display_inputs` WHERE `display_name` IN ('bx_quoteofday_entry_add', 'bx_quoteofday_entry_edit');
 
 -- STUDIO WIDGET
 DELETE FROM `tp`, `tw`, `tpw`
 USING `sys_std_pages` AS `tp`, `sys_std_widgets` AS `tw`, `sys_std_pages_widgets` AS `tpw`
-WHERE `tp`.`id` = `tw`.`page_id` AND `tw`.`id` = `tpw`.`widget_id` AND `tp`.`name` = 'bx_quoteofday';
+WHERE `tp`.`id` = `tw`.`page_id` AND `tw`.`id` = `tpw`.`widget_id` AND `tp`.`name` = @sName;