Explorar el Código

Merge branch 'master' of https://github.com/unacms/UNA

AntonLV hace 5 meses
padre
commit
6e04942b4a

+ 9 - 7
inc/classes/BxDolCacheFile.php

@@ -52,17 +52,19 @@ class BxDolCacheFile extends BxDolCache
      */
     function setData($sKey, $mixedData, $iTTL = false)
     {
-        if(file_exists($this->sPath . $sKey) && !is_writable($this->sPath . $sKey))
-           return false;
+        $sFileName = $this->sPath . $sKey;
+        $sFileNameTmp = $this->sPath . '.' . uniqid('', true) . '.tmp';
 
-        if(!($rHandler = fopen($this->sPath . $sKey, 'w')))
+        if(file_exists($sFileName) && !is_writable($sFileName))
            return false;
 
-        fwrite($rHandler, '<?php $mixedData=' . var_export($mixedData, true) . '; ?>');
-        fclose($rHandler);
-        @chmod($this->sPath . $sKey, 0666);
+        $content = '<?php $mixedData=' . var_export($mixedData, true) . '; ?>';
+        if (false === file_put_contents($sFileNameTmp, $content))
+            return false;
+        rename($sFileNameTmp, $sFileName);
+        @chmod($sFileName, 0666);
 
-        if (function_exists('opcache_invalidate')) opcache_invalidate($this->sPath . $sKey);
+        if (function_exists('opcache_invalidate')) opcache_invalidate($sFileName, true);
 
         return true;
     }

+ 9 - 8
inc/classes/BxDolCacheFileHtml.php

@@ -51,18 +51,19 @@ class BxDolCacheFileHtml extends BxDolCacheFile
      */
     function setData($sKey, $mixedData, $iTTL = false)
     {
-        if(file_exists($this->sPath . $sKey) && !is_writable($this->sPath . $sKey))
-           return false;
+        $sFileName = $this->sPath . $sKey;
+        $sFileNameTmp = $this->sPath . '.' . uniqid('', true) . '.tmp';
 
-        if(!($rHandler = fopen($this->sPath . $sKey, 'w')))
+        if(file_exists($sFileName) && !is_writable($sFileName))
            return false;
 
-        fwrite($rHandler, $mixedData);
-        fclose($rHandler);
-        @chmod($this->sPath . $sKey, 0666);
+        if (false === file_put_contents($sFileNameTmp, $mixedData))
+            return false;
+        rename($sFileNameTmp, $sFileName);
+        @chmod($sFileName, 0666);
+
+        if (function_exists('opcache_invalidate')) opcache_invalidate($sFileName, true);
 
-        if (function_exists('opcache_invalidate')) opcache_invalidate($this->sPath . $sKey);
-        
         return true;
     }
 }

+ 140 - 0
inc/classes/BxDolCacheMemcached.php

@@ -0,0 +1,140 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup UnaCore UNA Core
+ * @{
+ */
+
+class BxDolCacheMemcached extends BxDolCache
+{
+    protected $iTTL = 3600;
+    protected $oMemcached = null;
+
+    /**
+     * Constructor
+     */
+    function __construct()
+    {
+        parent::__construct();
+
+        if (class_exists('Memcached')) {
+
+            // Persistent connection
+            $this->oMemcached = new Memcached('una_cache_pool');
+
+            // Avoid adding servers repeatedly
+            if (!count($this->oMemcached->getServerList())) {
+
+                $sHost = getParam('sys_cache_memcache_host');
+                $iPort = (int)getParam('sys_cache_memcache_port');
+
+                if (false === strpos($sHost, ',')) {
+
+                    $this->oMemcached->addServer(
+                        trim($sHost),
+                        $iPort
+                    );
+
+                } else {
+
+                    $aHosts = explode(',', $sHost);
+
+                    if ($aHosts) {
+
+                        $this->oMemcached->setOption(
+                            Memcached::OPT_DISTRIBUTION,
+                            Memcached::DISTRIBUTION_CONSISTENT
+                        );
+
+                        $this->oMemcached->setOption(
+                            Memcached::OPT_LIBKETAMA_COMPATIBLE,
+                            true
+                        );
+
+                        foreach ($aHosts as $s) {
+                            $this->oMemcached->addServer(
+                                trim($s),
+                                $iPort
+                            );
+                        }
+                    } else {
+                        $this->oMemcached = null;
+                    }
+                }
+            }
+
+            // Verify connection
+            if ($this->oMemcached) {
+                $stats = $this->oMemcached->getStats();
+
+                if (empty($stats)) {
+                    $this->oMemcached = null;
+                }
+            }
+        }
+    }
+
+    /**
+     * Get data from cache
+     */
+    function getData($sKey, $iTTL = false)
+    {
+        $mixedData = $this->oMemcached->get($sKey);
+
+        if ($mixedData === false && $this->oMemcached->getResultCode() === Memcached::RES_NOTFOUND) {
+            return null;
+        }
+
+        return $mixedData;
+    }
+
+    /**
+     * Save data to cache
+     */
+    function setData($sKey, $mixedData, $iTTL = false)
+    {
+        return $this->oMemcached->set(
+            $sKey,
+            $mixedData,
+            false === $iTTL ? $this->iTTL : $iTTL
+        );
+    }
+
+    /**
+     * Delete cache item
+     */
+    function delData($sKey)
+    {
+        $this->oMemcached->delete($sKey);
+        return true;
+    }
+
+    /**
+     * Check if Memcached is available
+     */
+    function isAvailable()
+    {
+        return $this->oMemcached !== null;
+    }
+
+    /**
+     * Check if extension is installed
+     */
+    function isInstalled()
+    {
+        return extension_loaded('memcached');
+    }
+
+    /**
+     * Flush all cache
+     * Note: ignores prefix parameter
+     */
+    function removeAllByPrefix($s)
+    {
+        return $this->oMemcached->flush();
+    }
+}
+
+/** @} */

+ 0 - 1
inc/classes/BxDolPushOneSignal.php

@@ -103,7 +103,6 @@ class BxDolPushOneSignal extends BxDolPush
             curl_setopt($oChannel, CURLOPT_SSL_VERIFYPEER, false);
 
         $sResult = curl_exec($oChannel);
-        curl_close($oChannel);
 
         $oResult = @json_decode($sResult, true);
         if(isset($oResult['errors']))

+ 0 - 1
inc/classes/BxDolPushWonderPush.php

@@ -127,7 +127,6 @@ class BxDolPushWonderPush extends BxDolPush
             curl_setopt($oChannel, CURLOPT_SSL_VERIFYPEER, false);
 
         $sResult = curl_exec($oChannel);
-        curl_close($oChannel);
 
         $oResult = @json_decode($sResult, true);
         

+ 1 - 1
inc/classes/BxDolSmsSmsRu.php

@@ -299,7 +299,7 @@ class SMSRU {
 		} else {
 			$error = FALSE;
 		}
-		curl_close($ch);
+
 		if ($error && $this->count_repeat > 0) {
 			$this->count_repeat--;
 			return $this->Request($url, $r_post);

+ 0 - 6
inc/classes/BxDolXmlParser.php

@@ -47,7 +47,6 @@ class BxDolXmlParser extends BxDolFactory implements iBxDolSingleton
         $aValues = $aIndexes = array();
         $rParser = xml_parser_create("UTF-8");
         xml_parse_into_struct($rParser, $sXmlContent, $aValues, $aIndexes);
-        xml_parser_free($rParser);
 
         $sTag = strtoupper($sXmlTag);
         if(!isset($aIndexes[$sTag]))
@@ -69,7 +68,6 @@ class BxDolXmlParser extends BxDolFactory implements iBxDolSingleton
         $aValues = $aIndexes = array();
         $rParser = xml_parser_create("UTF-8");
         xml_parse_into_struct($rParser, $sXmlContent, $aValues, $aIndexes);
-        xml_parser_free($rParser);
 
         /**
          * gets two-dimensional array of attributes.
@@ -98,7 +96,6 @@ class BxDolXmlParser extends BxDolFactory implements iBxDolSingleton
         $aValues = $aIndexes = array();
         $rParser = xml_parser_create("UTF-8");
         xml_parse_into_struct($rParser, $sXmlContent, $aValues, $aIndexes);
-        xml_parser_free($rParser);
 
         //--- Get an array of tags ---//
         if($iXmlTagIndex == -1) {
@@ -138,7 +135,6 @@ class BxDolXmlParser extends BxDolFactory implements iBxDolSingleton
         $aValues = $aIndexes = array();
         $rParser = xml_parser_create("UTF-8");
         xml_parse_into_struct($rParser, $sXmlContent, $aValues, $aIndexes);
-        xml_parser_free($rParser);
 
         $sTag = strtoupper($sXmlTagName);
         $aTagIndexes = isset($aIndexes[$sTag]) ? $aIndexes[$sTag] : array();
@@ -161,7 +157,6 @@ class BxDolXmlParser extends BxDolFactory implements iBxDolSingleton
         $aValues = $aIndexes = array();
         $rParser = xml_parser_create("UTF-8");
         xml_parse_into_struct($rParser, $sXmlContent, $aValues, $aIndexes);
-        xml_parser_free($rParser);
 
         $aTagIndexes = $aIndexes[strtoupper($sXmlTagName)];
         if(count($aTagIndexes) == 0) return $this->getContent();
@@ -182,7 +177,6 @@ class BxDolXmlParser extends BxDolFactory implements iBxDolSingleton
         $aValues = $aIndexes = array();
         $rParser = xml_parser_create("UTF-8");
         xml_parse_into_struct($rParser, $sXmlContent, $aValues, $aIndexes);
-        xml_parser_free($rParser);
 
         $aTagIndexes = $aIndexes[strtoupper($sXmlTagName)];
         $iLastTagIndex = $aTagIndexes[count($aTagIndexes) - 1];

+ 0 - 1
inc/utils.inc.php

@@ -1154,7 +1154,6 @@ function bx_file_get_contents($sFileUrl, $aParams = array(), $sMethod = 'get', $
         if (NULL !== $sHttpCode)
             $sHttpCode = curl_getinfo($rConnect, CURLINFO_HTTP_CODE);
 
-        curl_close($rConnect);
     }
     else {
 

+ 5 - 5
install/sql/system.sql

@@ -612,23 +612,23 @@ SET @iCategoryId = LAST_INSERT_ID();
 
 INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `info`, `value`, `type`, `extra`, `check`, `check_error`, `order`) VALUES
 (@iCategoryId, 'sys_content_cache_enable', '_adm_stg_cpt_option_sys_content_cache_enable', '', 'on', 'checkbox', '', '', '', 5),
-(@iCategoryId, 'sys_content_cache_engine', '_adm_stg_cpt_option_sys_content_cache_engine', '', 'File', 'select', 'File,Memcache,APC,XCache,Redis', '', '', 6),
+(@iCategoryId, 'sys_content_cache_engine', '_adm_stg_cpt_option_sys_content_cache_engine', '', 'File', 'select', 'File,Memcache,Memcached,APC,XCache,Redis', '', '', 6),
 
 (@iCategoryId, 'sys_db_cache_enable', '_adm_stg_cpt_option_sys_db_cache_enable', '', 'on', 'checkbox', '', '', '', 10),
-(@iCategoryId, 'sys_db_cache_engine', '_adm_stg_cpt_option_sys_db_cache_engine', '', 'File', 'select', 'File,Memcache,APC,XCache,Redis', '', '', 11),
+(@iCategoryId, 'sys_db_cache_engine', '_adm_stg_cpt_option_sys_db_cache_engine', '', 'File', 'select', 'File,Memcache,Memcached,APC,XCache,Redis', '', '', 11),
 
 (@iCategoryId, 'sys_cache_memcache_host', '_adm_stg_cpt_option_sys_cache_memcache_host', '', '', 'digit', '', '', '', 20),
 (@iCategoryId, 'sys_cache_memcache_port', '_adm_stg_cpt_option_sys_cache_memcache_port', '', '11211', 'digit', '', '', '', 21),
 (@iCategoryId, 'sys_cache_redis_connection_string', '_adm_stg_cpt_option_sys_cache_redis_connection_string', '_adm_stg_cpt_option_sys_cache_redis_connection_string_info', '', 'digit', '', '', '', 25),
 
 (@iCategoryId, 'sys_page_cache_enable', '_adm_stg_cpt_option_sys_page_cache_enable', '', 'on', 'checkbox', '', '', '', 30),
-(@iCategoryId, 'sys_page_cache_engine', '_adm_stg_cpt_option_sys_page_cache_engine', '', 'File', 'select', 'File,Memcache,APC,XCache,Redis', '', '', 31),
+(@iCategoryId, 'sys_page_cache_engine', '_adm_stg_cpt_option_sys_page_cache_engine', '', 'File', 'select', 'File,Memcache,Memcached,APC,XCache,Redis', '', '', 31),
 
 (@iCategoryId, 'sys_pb_cache_enable', '_adm_stg_cpt_option_sys_pb_cache_enable', '', 'on', 'checkbox', '', '', '', 40),
-(@iCategoryId, 'sys_pb_cache_engine', '_adm_stg_cpt_option_sys_pb_cache_engine', '', 'File', 'select', 'File,Memcache,APC,XCache,Redis', '', '', 41),
+(@iCategoryId, 'sys_pb_cache_engine', '_adm_stg_cpt_option_sys_pb_cache_engine', '', 'File', 'select', 'File,Memcache,Memcached,APC,XCache,Redis', '', '', 41),
 
 (@iCategoryId, 'sys_template_cache_enable', '_adm_stg_cpt_option_sys_template_cache_enable', '', 'on', 'checkbox', '', '', '', 50),
-(@iCategoryId, 'sys_template_cache_engine', '_adm_stg_cpt_option_sys_template_cache_engine', '', 'FileHtml', 'select', 'FileHtml,Memcache,APC,XCache,Redis', '', '', 51),
+(@iCategoryId, 'sys_template_cache_engine', '_adm_stg_cpt_option_sys_template_cache_engine', '', 'FileHtml', 'select', 'FileHtml,Memcache,Memcached,APC,XCache,Redis', '', '', 51),
 (@iCategoryId, 'sys_template_cache_css_enable', '_adm_stg_cpt_option_sys_template_cache_css_enable', '', 'on', 'checkbox', '', '', '', 55),
 (@iCategoryId, 'sys_template_cache_js_enable', '_adm_stg_cpt_option_sys_template_cache_js_enable', '', 'on', 'checkbox', '', '', '', 56),
 (@iCategoryId, 'sys_template_cache_minify_css_enable', '_adm_stg_cpt_option_sys_template_cache_minify_css_enable', '', 'on', 'checkbox', '', '', '', 57),

+ 0 - 2
modules/boonex/drupal_connect/classes/BxDrupalFormLogin.php

@@ -85,8 +85,6 @@ class BxDrupalFormLogin extends BxTemplFormLogin
             }
         }
 
-        curl_close($rCurl);
-
         return $mixedResult;
     }
 }

+ 0 - 2
modules/boonex/elasticsearch/classes/BxElsApi.php

@@ -229,8 +229,6 @@ class BxElsApi extends BxDol
         if (NULL !== $sHttpCode)
             $sHttpCode = curl_getinfo($rConnect, CURLINFO_HTTP_CODE);
 
-        curl_close($rConnect);
-
         return $sResult;
     }
 

+ 1 - 1
modules/boonex/facebook_connect/plugins/graph-sdk/src/Facebook/HttpClients/FacebookCurl.php

@@ -124,6 +124,6 @@ class FacebookCurl
      */
     public function close()
     {
-        curl_close($this->curl);
+        // curl_close($this->curl); // it does nothing since PHP 8.0
     }
 }

+ 0 - 2
modules/boonex/intercom/classes/BxIntercomModule.php

@@ -344,11 +344,9 @@ EOS;
 
         if (false === $sResult) {
             $sError = curl_error ($r);
-            curl_close($r);
             return false;
         }
 
-        curl_close($r);
         return $sResult;
     }
 }

+ 0 - 2
modules/boonex/mailchimp/classes/BxMailchimpModule.php

@@ -328,11 +328,9 @@ class BxMailchimpModule extends BxDolModule
 
         if (false === $sResult) {
             $sError = curl_error ($r);
-            curl_close($r);
             return false;
         }
 
-        curl_close($r);
         return $sResult;
     }
 }

+ 0 - 3
modules/boonex/payment/classes/BxPaymentProviderPayPal.php

@@ -269,13 +269,10 @@ class BxPaymentProviderPayPal extends BxBaseModPaymentProvider implements iBxBas
 		if(!$sResponse) {
 		    $this->log('Validation Data: ' . curl_error($rConnect), '', BX_LOG_ERR);
             $this->log($sResponse, '', BX_LOG_ERR);
-			curl_close($rConnect);
 
 			return array('code' => 5, 'message' => $this->_sLangsPrefix . 'err_cannot_validate');
 		}
 
-		curl_close($rConnect);
-
 		$aResponse = explode("\n", $sResponse);
 
 		$this->log('Validation Response: ', '', BX_LOG_INFO);

+ 1 - 1
modules/boonex/timeline/install/sql/enable.sql

@@ -374,7 +374,7 @@ SET @iCategId = LAST_INSERT_ID();
 
 INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `check`, `check_params`, `check_error`, `extra`, `order`) VALUES
 ('bx_timeline_enable_cache_item', 'on', @iCategId, '_bx_timeline_option_enable_cache_item', 'checkbox', '', '', '', '', 1),
-('bx_timeline_cache_item_engine', 'File', @iCategId, '_bx_timeline_option_cache_item_engine', 'select', '', '', '', 'File,Memcache,APC,XCache', 2),
+('bx_timeline_cache_item_engine', 'File', @iCategId, '_bx_timeline_option_cache_item_engine', 'select', '', '', '', 'FileHtml,Memcache,Memcached,APC,XCache,Redis', 2),
 ('bx_timeline_cache_item_lifetime', '604800', @iCategId, '_bx_timeline_option_cache_item_lifetime', 'digit', '', '', '', '', 3),
 ('bx_timeline_enable_cache_table', '', @iCategId, '_bx_timeline_option_enable_cache_table', 'checkbox', '', '', '', '', 10),
 ('bx_timeline_cache_table_interval', '90', @iCategId, '_bx_timeline_option_cache_table_interval', 'digit', '', '', '', '', 11);

+ 0 - 1
scripts/update_checker.php

@@ -246,7 +246,6 @@ class SQLUpdateChecker {
         $response = curl_exec($ch);
         $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
         $error = curl_error($ch);
-        curl_close($ch);
         
         if ($error) {
             $this->error("CURL error: $error");

+ 0 - 2
scripts/update_gen.php

@@ -253,7 +253,6 @@ class SQLUpdateChecker {
         $response = curl_exec($ch);
         $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
         $error = curl_error($ch);
-        curl_close($ch);
         
         if ($error) {
             $this->error("CURL error: $error");
@@ -300,7 +299,6 @@ class SQLUpdateChecker {
         $response = curl_exec($ch);
         $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
         $error = curl_error($ch);
-        curl_close($ch);
         
         if ($error) {
             $this->error("CURL error: $error");

+ 27 - 0
studio/classes/BxDolStudioToolsAudit.php

@@ -376,6 +376,9 @@ class BxDolStudioToolsAudit extends BxDol
 
         if (!defined('BX_DOL_INSTALL'))
             $this->optimizationScript();
+
+        if (!defined('BX_DOL_INSTALL'))
+            $this->optimizationCache();
     }
 
     protected function optimizationPhp()
@@ -453,6 +456,30 @@ class BxDolStudioToolsAudit extends BxDol
         echo $this->getSection('UNA', '', $s);
     }
 
+    protected function optimizationCache()
+    {
+        $a = explode(',', 'File,APC,Memcache,Memcached,Redis');
+        $s = '';
+        foreach ($a as $sName) {
+
+            $sClass = 'BxDolCache' . $sName;
+            if (class_exists($sClass))
+                $o = new $sClass();
+
+            if ($o && $o->isInstalled() && $o->isAvailable()) {
+                $val = true;
+                $aMessage = array('type' => BX_DOL_AUDIT_OK);
+            } else {
+                $val = false;
+                $aMessage = array('type' => BX_DOL_AUDIT_FAIL);
+            }
+
+            $s .= $this->getBlock($sName, $this->format_output($val, ['type' => 'bool' ]), $this->getMsgHTML($sName, $aMessage));
+        }
+
+        echo $this->getSection('Cache engines', '', $s);
+    }
+
     protected function manualCheck()
     {
         echo '<a name="manual_audit"></a>';