@@ -23,6 +23,22 @@ class JetRails_Cloudflare_Helper_Data extends Mage_Core_Helper_Abstract {
2323 const XPATH_AUTH_ZONE = "cloudflare/configuration/auth_zone " ;
2424 const XPATH_AUTH_TOKEN = "cloudflare/configuration/auth_token " ;
2525
26+ /**
27+ * This method returns the public suffix list either from cache based on
28+ * the user session, or downloads it directly
29+ * @return array[string] Public Suffix List
30+ */
31+ public function refreshPSL () {
32+ $ session = Mage::getSingleton ("core/session " );
33+ $ data = $ session ->getPSL ();
34+ if ( $ data == null ) {
35+ $ psl = Mage::helper ("cloudflare/publicSuffixList " );
36+ $ data = array_values ( $ psl ->getPSL () );
37+ $ session ->setPSL ( $ data );
38+ }
39+ return $ data ;
40+ }
41+
2642 /**
2743 * This method gets the value for the authorization zone and decrypts
2844 * it. It then returns that result to the caller.
@@ -73,13 +89,12 @@ public function getAuthToken () {
7389 */
7490 public function getDomainName () {
7591 $ session = Mage::getSingleton ("core/session " );
92+ $ psl = Mage::helper ("cloudflare/publicSuffixList " );
7693 if ( !empty ( $ session ->getCloudflareSelectedDomain () ) ) {
7794 return $ session ->getCloudflareSelectedDomain ();
7895 }
7996 $ domain = Mage::getBaseUrl ( Mage_Core_Model_Store::URL_TYPE_WEB );
80- $ domain = parse_url ( $ domain ) ["host " ];
81- preg_match ( "/([^.\s]+\.([^.\s]{3,}|[^.\s]{2}\.[^.\s]{2}|[^.\s]{2}))\b$/im " , $ domain , $ matches );
82- return $ matches [ 1 ];
97+ return $ psl ->extract ( $ domain , $ this ->refreshPSL () ) ["root_domain " ];
8398 }
8499
85100 /**
@@ -91,15 +106,15 @@ public function getDomainName () {
91106 * @return array All domains for all stores
92107 */
93108 public function getDomainNames () {
109+ $ psl = Mage::helper ("cloudflare/publicSuffixList " );
94110 $ selection = $ this ->getDomainName ();
95111 $ domains = array ();
112+ $ pslData = $ this ->refreshPSL ();
96113 foreach ( Mage::app ()->getWebsites () as $ website ) {
97114 foreach ( $ website ->getGroups () as $ group ) {
98115 $ stores = $ group ->getStores ();
99116 foreach ( $ stores as $ store ) {
100- $ domain = parse_url ( $ store ->getBaseUrl () ) ["host " ];
101- preg_match ( "/([^.\s]+\.([^.\s]{3,}|[^.\s]{2}\.[^.\s]{2}|[^.\s]{2}))\b$/im " , $ domain , $ matches );
102- $ domain = $ matches [ 1 ];
117+ $ domain = $ psl ->extract ( $ store ->getBaseUrl (), $ pslData ) ["root_domain " ];
103118 array_push ( $ domains , $ domain );
104119 }
105120 }
0 commit comments