|
|
@@ -11,20 +11,17 @@
|
|
|
|
|
|
define('BX_QOD_SOURCE_INTERNAL', 'internal');
|
|
|
define('BX_QOD_SOURCE_RSS', 'rss');
|
|
|
-
|
|
|
define('BX_QOD_SELECTION_MODE_BY_RANDOM', 'random');
|
|
|
define('BX_QOD_SELECTION_MODE_BY_ORDER', 'order');
|
|
|
-
|
|
|
define('BX_QOD_LIFETIME_IN_SECONDS', 86400);
|
|
|
|
|
|
-class BxQuoteOfDayModule extends BxBaseModGeneralModule
|
|
|
+class BxQuoteOfDayModule extends BxDolModule
|
|
|
{
|
|
|
function __construct(&$aModule)
|
|
|
{
|
|
|
parent::__construct($aModule);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Service methods
|
|
|
*/
|
|
|
@@ -45,13 +42,13 @@ class BxQuoteOfDayModule extends BxBaseModGeneralModule
|
|
|
/**
|
|
|
* @ref bx_quoteofday-get_sources "get_sources"
|
|
|
*/
|
|
|
-
|
|
|
public function serviceGetSources()
|
|
|
{
|
|
|
$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;
|
|
|
}
|
|
|
|
|
|
@@ -78,10 +75,10 @@ class BxQuoteOfDayModule extends BxBaseModGeneralModule
|
|
|
$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
|
|
|
@@ -123,11 +120,12 @@ class BxQuoteOfDayModule extends BxBaseModGeneralModule
|
|
|
*/
|
|
|
public function serviceGetQuote()
|
|
|
{
|
|
|
- $sTextFromCache = $this->GetQuoteFromCache();
|
|
|
+ $sTextFromCache = $this->getQuoteFromCache();
|
|
|
if ($sTextFromCache == null || $sTextFromCache == "")
|
|
|
{
|
|
|
- $sTextFromCache = $this->serviceSetQuote();
|
|
|
+ $sTextFromCache = $this->defineAndSetQuote();
|
|
|
}
|
|
|
+
|
|
|
return $sTextFromCache;
|
|
|
}
|
|
|
|
|
|
@@ -135,106 +133,106 @@ class BxQuoteOfDayModule extends BxBaseModGeneralModule
|
|
|
* @page service Service Calls
|
|
|
* @section bx_quoteofday Quote of the Day
|
|
|
* @subsection bx_quoteofday-other Other
|
|
|
- * @subsubsection bx_quoteofday-set_quote
|
|
|
+ * @subsubsection bx_quoteofday-set_quotes_manage
|
|
|
*
|
|
|
- * @code bx_srv('bx_quoteofday', 'set_quote', [...]); @endcode
|
|
|
+ * @code bx_srv('bx_quoteofday', 'set_quotes_manage', [...]); @endcode
|
|
|
*
|
|
|
- * Define and store in cache Quote of the Day depend on current module settings
|
|
|
+ * Return Grid from internal quotes management
|
|
|
*
|
|
|
- * @return string - current Quote of the Day from system cache.
|
|
|
+ * @return string - code of grid quotes management.
|
|
|
*
|
|
|
- * @see BxQuoteOfDayModule::serviceSetQuote
|
|
|
+ * @see BxQuoteOfDayModule::serviceGetQuotesManage
|
|
|
*/
|
|
|
/**
|
|
|
- * @ref bx_quoteofday-set_quote "set_quote"
|
|
|
+ * @ref bx_quoteofday-set_quotes_manage "set_quotes_manage"
|
|
|
*/
|
|
|
- public function serviceSetQuote()
|
|
|
+ public function serviceGetQuotesManage()
|
|
|
+ {
|
|
|
+ $this->_oTemplate->addJs('jquery.form.min.js');
|
|
|
+ $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID']);
|
|
|
+ if(!$oGrid)
|
|
|
+ return '';
|
|
|
+
|
|
|
+ return $oGrid->getCode();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function defineAndSetQuote()
|
|
|
{
|
|
|
$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');
|
|
|
-
|
|
|
+ $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)) {
|
|
|
- $aData=array_merge($aData,$this->getInternalData());
|
|
|
+ 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));
|
|
|
+ if (in_array(BX_QOD_SOURCE_RSS, $aSources) && $sRssUrl != "" && $iRssMaxItems > 0)
|
|
|
+ $aData = array_merge($aData,$this->getRssData($sRssUrl, $iRssMaxItems));
|
|
|
+
|
|
|
$iIndex = -1;
|
|
|
if ($sSelectionType == BX_QOD_SELECTION_MODE_BY_RANDOM) {
|
|
|
- $iIndex = rand(0,count($aData)-1);
|
|
|
+ $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);
|
|
|
+ $this->putQuoteToCache($sTextToChache);
|
|
|
}
|
|
|
+
|
|
|
return $sTextToChache;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public function PutQuoteToCache($quoteText)
|
|
|
+ public function putQuoteToCache($quoteText)
|
|
|
{
|
|
|
$oCachObject = $this->_oDb->getDbCacheObject();
|
|
|
- $oCachObject->setData($this->_oConfig->CNF['CACHEKEY'],$quoteText,BX_QOD_LIFETIME_IN_SECONDS);
|
|
|
+ $oCachObject->setData($this->_oConfig->CNF['CACHEKEY'], $quoteText, BX_QOD_LIFETIME_IN_SECONDS);
|
|
|
}
|
|
|
|
|
|
- public function GetQuoteFromCache()
|
|
|
+ public function getQuoteFromCache()
|
|
|
{
|
|
|
- $oCachObject = $this->_oDb->getDbCacheObject();
|
|
|
- return $oCachObject->getData($this->_oConfig->CNF['CACHEKEY'],BX_QOD_LIFETIME_IN_SECONDS);
|
|
|
+ $oCachObject = $this->_oDb->getDbCacheObject();
|
|
|
+ return $oCachObject->getData($this->_oConfig->CNF['CACHEKEY'], BX_QOD_LIFETIME_IN_SECONDS);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public function RemoveQuoteFromCache()
|
|
|
+ public function removeQuoteFromCache()
|
|
|
{
|
|
|
$oCachObject = $this->_oDb->getDbCacheObject();
|
|
|
$oCachObject->delData($this->_oConfig->CNF['CACHEKEY']);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private function getInternalData()
|
|
|
{
|
|
|
return $this->_oDb->getData();
|
|
|
}
|
|
|
|
|
|
- private function getRssData($sRssUrl,$iRssMaxItems)
|
|
|
+ private function getRssData($sRssUrl, $iRssMaxItems)
|
|
|
{
|
|
|
- $aTmpRv=array();
|
|
|
+ $aTmpRv = array();
|
|
|
$oXmlParser = BxDolXmlParser::getInstance();
|
|
|
$sXmlContent = bx_file_get_contents($sRssUrl);
|
|
|
- $oTmp=$oXmlParser->getTags($sXmlContent, 'description');
|
|
|
- if (is_array($oTmp)) {
|
|
|
- $iC=0;
|
|
|
- while (list( ,$oValue) = each($oTmp)) {
|
|
|
- if ($iC==$iRssMaxItems) break;
|
|
|
- if (isset($oValue['value']) && $oValue['level']==4 && trim(strip_tags($oValue['value'])) != "") {
|
|
|
- array_push($aTmpRv,$oValue['value']);
|
|
|
+ $aTmp=$oXmlParser->getTags($sXmlContent, 'description');
|
|
|
+ if (is_array($aTmp)) {
|
|
|
+ $iC = 0;
|
|
|
+ while (list(, $aValue) = each($aTmp)) {
|
|
|
+ if ($iC == $iRssMaxItems) break;
|
|
|
+ if (isset($aValue['value']) && $aValue['level'] == 4 && trim(strip_tags($aValue['value'])) != "") {
|
|
|
+ array_push($aTmpRv, $aValue['value']);
|
|
|
$iC++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return $aTmpRv;
|
|
|
}
|
|
|
-
|
|
|
- public function serviceGetQuotesManage()
|
|
|
- {
|
|
|
- $this->_oTemplate->addJs('jquery.form.min.js');
|
|
|
- $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID']);
|
|
|
- if(!$oGrid)
|
|
|
- return '';
|
|
|
- return $oGrid->getCode();
|
|
|
-
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
/** @} */
|