Last active
April 24, 2024 13:22
-
-
Save EscApp2/3a57ef626ae4eed1eaeba923cefb664c to your computer and use it in GitHub Desktop.
twinpx delivery yadelivery hack if default city non moscow Если первый город не москва, кнопки выбора интервала и пвз не появляются regex class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
Bitrix\Main\EventManager::getInstance()->addEventHandler( | |
'sale', | |
'OnSaleComponentOrderJsData', | |
'OnSaleComponentOrderJsData_twinpx_yadelivery_hack' | |
); | |
function OnSaleComponentOrderJsData_twinpx_yadelivery_hack(&$arResult,&$arParams) | |
{ | |
if(\Bitrix\Main\Loader::includeModule('twinpx.yadelivery')){ | |
$headStings = \Bitrix\Main\Page\Asset::getInstance()->getStrings(); | |
$class = new regex_class_v4(); | |
$class->beetween('< script#any#>','</ script >'); | |
$class->setUngready(); | |
$ret = $class->exec($headStings); | |
$arResult['JS_DATA']['HEADER_STRINGS'] = $ret; | |
} | |
} | |
Bitrix\Main\EventManager::getInstance()->addEventHandler( | |
'twinpx.yadelivery', | |
'\Twinpx\Yadelivery\TwinpxOffer::OnAfterAdd', | |
'OnSaleOrderSaved_twinpx_yadelivery_save_pvz_id2' | |
); | |
Bitrix\Main\EventManager::getInstance()->addEventHandler( | |
'twinpx.yadelivery', | |
'\Twinpx\Yadelivery\TwinpxOfferTemp::OnAfterAdd', | |
'OnSaleOrderSaved_twinpx_yadelivery_save_pvz_id2' | |
); | |
function OnSaleOrderSaved_twinpx_yadelivery_save_pvz_id2($event) | |
{ | |
$arFields = $event->getParameter('fields'); | |
if($arFields['ORDER_ID'] && $arFields['PVZ_ID']){ | |
$order = $arFields['ORDER_ID']; | |
$PVZ_ID = $arFields['PVZ_ID']; | |
$arDeliveryFull = SaleOrderSavedHelp::getOrderDelivery($order); | |
$arDeliveryId = array_keys( $arDeliveryFull); | |
$deliveryID = reset($arDeliveryId); | |
$arDelivery = TwinpxDelivery::ChechDelivery($deliveryID); | |
if (!empty($arDelivery)) { | |
if($PVZ_ID){ | |
SaleOrderSavedHelp::setPropertyD7($order,"YD_PVZ_ID", $PVZ_ID, true); | |
} | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class regex_class_v4{ | |
public $beetween_parts = array(); | |
public $find = ""; | |
public $find_all_patern = false; | |
public $flags = ""; | |
public function __construct(){ | |
} | |
public function beetween($first, $second, $flags = false){ | |
//$alphabet_pattern = "#[a-zA-ZЁёА-я]#"; | |
$alphabet_pattern = "#[\w]#"; | |
$digital_pattern = "#[\d]#"; | |
$any = "[\S\s]*"; | |
$any_in_line = ".*"; | |
$parts = array(); | |
$ar_parts = $this->_createPattern($first, $flags); | |
$parts[] = $this->_compileParts($ar_parts); | |
$ar_parts = $this->_createPattern($second, $flags); | |
$parts[] = $find = $this->_compileParts($ar_parts); | |
//$comp_find = $this->_compileFind($find); | |
$this->find = "(".$any.")"; //$comp_find; | |
$this->beetween_parts[] = $parts; | |
} | |
public function _createPattern($string, $flags){ | |
//$alphabet_pattern = "#[\w]#"; | |
$special_pattern = "#[".preg_quote('#$%^&*()+=-[]\';,./{}|\":<>?~', '#')."]#"; | |
$space_pattern = "#[\s]#"; | |
$parts = array(); | |
$arString = str_split($string); | |
foreach($arString as $val){ | |
if($this->_isMatch($val, $space_pattern)){ | |
$parts[] = array( | |
"type"=>"space", | |
"value"=>"\s*", | |
); | |
}elseif($this->_isMatch($val, $special_pattern)){ | |
if(in_array($val, array("'",'"'))){ | |
$parts[] = array( | |
"type"=>"special", | |
"value"=>"[\\'|\\\"]", | |
); | |
}else{ | |
$parts[] = array( | |
"type"=>"special", | |
"value"=>"\\".$val, | |
); | |
} | |
}else{ | |
$parts[] = array( | |
"type"=>"symbol", | |
"value"=>$val, | |
); | |
} | |
} | |
return $parts; | |
} | |
public function _compileFind($find){ | |
$string = "([^".$find."]*)"; | |
return $string; | |
} | |
public function _compileParts($ar_parts){ | |
$string = ""; | |
foreach($ar_parts as $part){ | |
$string .= $part["value"]; | |
} | |
return $string; | |
} | |
public function _isMatch($symbol, $pattern, $flags=false){ | |
$matches = array(); | |
preg_match($pattern, $symbol, $matches); | |
if($matches[0]){ | |
return true; | |
} | |
return false; | |
} | |
public function find($find, $flag = false){ | |
$this->find = "(".$find.")"; | |
} | |
public function exec($text = false, $flags = false){ | |
$flags .= $this->flags; | |
if(count($this->beetween_parts)>0 || !empty($this->find)){ | |
$ar_pattern = $ar_pattern_begin = $ar_pattern_end = array(); | |
$beetween_parts = $this->beetween_parts; | |
foreach($beetween_parts as $part){ | |
$ar_pattern_begin[] = $part[0]; | |
} | |
$any = "[\S\s]*"; | |
$ar_pattern[] = implode(".*",$ar_pattern_begin); | |
$ar_pattern[] = $this->find; | |
$beetween_parts = array_reverse($beetween_parts); | |
foreach($beetween_parts as $part){ | |
$ar_pattern_end[] = $part[1]; | |
} | |
$ar_pattern[] = implode(".*",$ar_pattern_end); | |
$pattern = implode("",$ar_pattern); | |
$pattern = str_replace(array("\#any\#"),array($any),$pattern); | |
//if($this->find_all_patern){ | |
// $pattern = "(".$pattern.")"; | |
// } | |
$pattern = "#".$pattern."#"; | |
//$flags = str_replace('m','ms',$flags); | |
$flags = str_replace('g','',$flags); | |
if($flags){ | |
$pattern .= $flags; | |
} | |
$matches = array(); | |
preg_match_all($pattern, $text, $matches); | |
if(count($matches)>0){ | |
if($this->find_all_patern){ | |
return array_merge($matches[0],$matches[1]); | |
}else{ | |
return $matches[1]; | |
} | |
} | |
} | |
return false; | |
} | |
public function setCaseInsensitive(){ | |
$this->flags .= 'i'; | |
} | |
public function setUngready(){ | |
$this->flags .= 'U'; | |
} | |
public function includeBeetween(){ | |
$this->find_all_patern = true; | |
} | |
public function copy(){ | |
} | |
public function clear(){ | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$text = "<script> var = '123' ; as das { ] asd / ||| ||\\\ ''' dasd asd asd </script>"; | |
$class = new regex_class_v4(); | |
$class->beetween('< script>','</script>'); | |
//$class->beetween("var = \"","' ;"); | |
$a = $class->exec($text); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///components/bitrix/sale.order.ajax/.default/order_ajax.js | |
in refreshOrder: function(result) | |
if(result.order.HEADER_STRINGS){ | |
$.each(result.order.HEADER_STRINGS,function(ind,val){ | |
if ( | |
( | |
document.documentElement.textContent || document.documentElement.innerText | |
).indexOf(val) > -1 | |
) { | |
// Do something... | |
}else{ | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.textContent = val; | |
script.className = 'added1'; | |
document.head.appendChild(script); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment