getModel($modelName)->loadInstance($value, $field); } /** * @param string $modelName * @param mixed $value * @param null|string $field * @param array $tags * @return Ess_M2ePro_Model_Abstract */ public function getCachedObject($modelName, $value, $field = NULL, array $tags = array()) { if (Mage::helper('M2ePro/Magento')->isDeveloper()) { return $this->getObject($modelName,$value,$field); } $cacheKey = strtoupper($modelName.'_data_'.$field.'_'.$value); $cacheData = Mage::helper('M2ePro/Data_Cache')->getValue($cacheKey); if ($cacheData !== false) { return $cacheData; } $tags[] = $modelName; $tags = array_unique($tags); $tags = array_map('strtolower',$tags); $cacheData = $this->getObject($modelName,$value,$field); Mage::helper('M2ePro/Data_Cache')->setValue($cacheKey,$cacheData,$tags,60*60*24); return $cacheData; } // ######################################## public function getCurrentGmtDate($returnTimestamp = false, $format = NULL) { if ($returnTimestamp) { return (int)Mage::getModel('core/date')->gmtTimestamp(); } return Mage::getModel('core/date')->gmtDate($format); } public function getCurrentTimezoneDate($returnTimestamp = false, $format = NULL) { if ($returnTimestamp) { return (int)Mage::getModel('core/date')->timestamp(); } return Mage::getModel('core/date')->date($format); } //----------------------------------------- public function getDate($date, $returnTimestamp = false, $format = NULL) { if (is_numeric($date)) { $result = (int)$date; } else { $result = strtotime($date); } if (is_null($format)) { $format = 'Y-m-d H:i:s'; } $result = date($format, $result); if ($returnTimestamp) { return strtotime($result); } return $result; } //----------------------------------------- public function gmtDateToTimezone($dateGmt, $returnTimestamp = false, $format = NULL) { if ($returnTimestamp) { return (int)Mage::getModel('core/date')->timestamp($dateGmt); } return Mage::getModel('core/date')->date($format,$dateGmt); } public function timezoneDateToGmt($dateTimezone, $returnTimestamp = false, $format = NULL) { if ($returnTimestamp) { return (int)Mage::getModel('core/date')->gmtTimestamp($dateTimezone); } return Mage::getModel('core/date')->gmtDate($format,$dateTimezone); } // ######################################## public function escapeJs($string) { return str_replace(array("\\" , "\n" , "\r" , "\"" , "'"), array("\\\\", "\\n" , "\\r", "\\\"", "\\'"), $string); } public function escapeHtml($data, $allowedTags = null) { if (is_array($data)) { $result = array(); foreach ($data as $item) { $result[] = $this->escapeHtml($item); } } else { // process single item if (strlen($data)) { if (is_array($allowedTags) and !empty($allowedTags)) { $allowed = implode('|', $allowedTags); $result = preg_replace('/<([\/\s\r\n]*)(' . $allowed . ')([\/\s\r\n]*)>/si', '##$1$2$3##', $data); $result = htmlspecialchars($result); $result = preg_replace('/##([\/\s\r\n]*)(' . $allowed . ')([\/\s\r\n]*)##/si', '<$1$2$3>', $result); } else { $result = htmlspecialchars($data); } } else { $result = $data; } } return $result; } // ######################################## public function convertStringToSku($title) { $skuVal = strtolower($title); $skuVal = str_replace(array(" ", ":", ",", ".", "?", "*", "+", "(", ")", "&", "%", "$", "#", "@", "!", '"', "'", ";", "\\", "|", "/", "<", ">"), "-", $skuVal); return $skuVal; } public function stripInvisibleTags($text) { $text = preg_replace( array( // Remove invisible content '/
]*?>.*?<\/head>/siu', '/