Guest User

Data.php

a guest
Feb 16th, 2015
245
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3. * @methods:
  4. * - get[Section]_[ConfigName]($defaultValue = '')
  5. */
  6. class EM_Em0113settings_Helper_Data extends Mage_Core_Helper_Abstract
  7. {
  8. public function __call($name, $args) {
  9. if (method_exists($this, $name))
  10. call_user_func_array(array($this, $name), $args);
  11.  
  12. elseif (preg_match('/^get([^_][a-zA-Z0-9_]+)$/', $name, $m)) {
  13. $segs = explode('_', $m[1]);
  14. foreach ($segs as $i => $seg)
  15. $segs[$i] = strtolower(preg_replace('/([^A-Z])([A-Z])/', '$1_$2', $seg));
  16.  
  17. $value = Mage::getStoreConfig('em0113/'.implode('/', $segs));
  18. if (!$value) $value = @$args[0];
  19. return $value;
  20. }
  21.  
  22. else
  23. call_user_func_array(array($this, $name), $args);
  24. }
  25.  
  26. public function getAllCssConfig() {
  27. $page_bgimage = Mage::getStoreConfig('em0113/general/page_bgfile') ?
  28. 'url(' . Mage::getBaseUrl('media') . 'background/' . Mage::getStoreConfig('em0113/general/page_bgfile') . ')'
  29. : (Mage::getStoreConfig('em0113/general/page_bgimage') ? 'url(../images/stripes/'.Mage::getStoreConfig('em0113/general/page_bgimage').')' : '');
  30. $header_bgimage = Mage::getStoreConfig('em0113/typography/header_bgfile') ?
  31. 'url(' . Mage::getBaseUrl('media') . 'background/' . Mage::getStoreConfig('em0113/typography/header_bgfile') . ')'
  32. : (Mage::getStoreConfig('em0113/typography/header_bgimage') ? 'url(../images/stripes/'.Mage::getStoreConfig('em0113/typography/header_bgimage').')' : '');
  33. $body_bgimage = Mage::getStoreConfig('em0113/typography/body_bgfile') ?
  34. 'url(' . Mage::getBaseUrl('media') . 'background/' . Mage::getStoreConfig('em0113/typography/body_bgfile') . ')'
  35. : (Mage::getStoreConfig('em0113/typography/body_bgimage') ? 'url(../images/stripes/'.Mage::getStoreConfig('em0113/typography/body_bgimage').')' : '');
  36. $footer_bgimage = Mage::getStoreConfig('em0113/typography/footer_bgfile') ?
  37. 'url(' . Mage::getBaseUrl('media') . 'background/' . Mage::getStoreConfig('em0113/typography/footer_bgfile') . ')'
  38. : (Mage::getStoreConfig('em0113/typography/footer_bgimage') ? 'url(../images/stripes/'.Mage::getStoreConfig('em0113/typography/footer_bgimage').')' : '');
  39.  
  40. return array(
  41. 'page_bgcolor' => Mage::getStoreConfig('em0113/general/page_bgcolor'),
  42. 'page_bgimage' => $page_bgimage,
  43. 'page_bgposition' => Mage::getStoreConfig('em0113/general/page_bgposition'),
  44. 'page_bgrepeat' => Mage::getStoreConfig('em0113/general/page_bgrepeat'),
  45.  
  46. 'general_font' => Mage::getStoreConfig('em0113/typography/general_font'),
  47. 'h1_font' => Mage::getStoreConfig('em0113/typography/h1_font'),
  48. 'h2_font' => Mage::getStoreConfig('em0113/typography/h2_font'),
  49. 'h3_font' => Mage::getStoreConfig('em0113/typography/h3_font'),
  50. 'h4_font' => Mage::getStoreConfig('em0113/typography/h4_font'),
  51. 'h5_font' => Mage::getStoreConfig('em0113/typography/h5_font'),
  52. 'h6_font' => Mage::getStoreConfig('em0113/typography/h6_font'),
  53.  
  54. 'box_shadow' => Mage::getStoreConfig('em0113/typography/box_shadow'),
  55. 'rounded_corner' => Mage::getStoreConfig('em0113/typography/rounded_corner'),
  56.  
  57. 'header_bgcolor' => Mage::getStoreConfig('em0113/typography/header_bgcolor'),
  58. 'header_bgcolor2' => Mage::getStoreConfig('em0113/typography/header_bgcolor2'),
  59. 'header_bgposition' => Mage::getStoreConfig('em0113/typography/header_bgposition'),
  60. 'header_bgrepeat' => Mage::getStoreConfig('em0113/typography/header_bgrepeat'),
  61. 'header_text_color' => Mage::getStoreConfig('em0113/typography/header_text_color'),
  62. 'header_text2_color' => Mage::getStoreConfig('em0113/typography/header_text2_color'),
  63. 'header_text3_color' => Mage::getStoreConfig('em0113/typography/header_text3_color'),
  64. 'header_text4_color' => Mage::getStoreConfig('em0113/typography/header_text4_color'),
  65. 'header_text5_color' => Mage::getStoreConfig('em0113/typography/header_text5_color'),
  66. 'header_bgimage' => $header_bgimage,
  67. 'header_line' => Mage::getStoreConfig('em0113/typography/header_line'),
  68.  
  69. 'menu_top_bgcolor' => Mage::getStoreConfig('em0113/typography/menu_top_bgcolor'),
  70. 'menu_top_hover_bgcolor' => Mage::getStoreConfig('em0113/typography/menu_top_hover_bgcolor'),
  71. 'menu_top_text_color' => Mage::getStoreConfig('em0113/typography/menu_top_text_color'),
  72. 'menu_active_text_color' => Mage::getStoreConfig('em0113/typography/menu_active_text_color'),
  73. 'menu_top_font' => Mage::getStoreConfig('em0113/typography/menu_top_font'),
  74. 'menu_drop_bgcolor' => Mage::getStoreConfig('em0113/typography/menu_drop_bgcolor'),
  75. 'menu_drop_hover_bgcolor' => Mage::getStoreConfig('em0113/typography/menu_drop_hover_bgcolor'),
  76. 'menu_drop_text_color' => Mage::getStoreConfig('em0113/typography/menu_drop_text_color'),
  77. 'menu_drop_text2_color' => Mage::getStoreConfig('em0113/typography/menu_drop_text2_color'),
  78. 'menu_drop_text3_color' => Mage::getStoreConfig('em0113/typography/menu_drop_text3_color'),
  79. 'menu_drop_font' => Mage::getStoreConfig('em0113/typography/menu_drop_font'),
  80. 'menu_drop_line' => Mage::getStoreConfig('em0113/typography/menu_drop_line'),
  81.  
  82. 'body_bgcolor1' => Mage::getStoreConfig('em0113/typography/body_bgcolor1'),
  83. 'body_bgcolor2' => Mage::getStoreConfig('em0113/typography/body_bgcolor2'),
  84. 'body_bgcolor3' => Mage::getStoreConfig('em0113/typography/body_bgcolor3'),
  85. 'body_bgcolor4' => Mage::getStoreConfig('em0113/typography/body_bgcolor4'),
  86. 'body_bgcolor5' => Mage::getStoreConfig('em0113/typography/body_bgcolor5'),
  87. 'body_bgposition' => Mage::getStoreConfig('em0113/typography/body_bgposition'),
  88. 'body_bgrepeat' => Mage::getStoreConfig('em0113/typography/body_bgrepeat'),
  89. 'body_bgimage' => $body_bgimage,
  90. 'body_text_color1' => Mage::getStoreConfig('em0113/typography/body_text_color1'),
  91. 'body_text_color2' => Mage::getStoreConfig('em0113/typography/body_text_color2'),
  92. 'body_text_color3' => Mage::getStoreConfig('em0113/typography/body_text_color3'),
  93. 'body_text_color4' => Mage::getStoreConfig('em0113/typography/body_text_color4'),
  94. 'body_text_color5' => Mage::getStoreConfig('em0113/typography/body_text_color5'),
  95. 'body_text_color6' => Mage::getStoreConfig('em0113/typography/body_text_color6'),
  96. 'body_text_color7' => Mage::getStoreConfig('em0113/typography/body_text_color7'),
  97. 'body_link_color' => Mage::getStoreConfig('em0113/typography/body_link_color'),
  98. 'body_line1' => Mage::getStoreConfig('em0113/typography/body_line1'),
  99. 'body_line2' => Mage::getStoreConfig('em0113/typography/body_line2'),
  100. 'body_line3' => Mage::getStoreConfig('em0113/typography/body_line3'),
  101.  
  102. 'footer_bgcolor' => Mage::getStoreConfig('em0113/typography/footer_bgcolor'),
  103. 'footer_bgcolor2' => Mage::getStoreConfig('em0113/typography/footer_bgcolor2'),
  104. 'footer_bgposition' => Mage::getStoreConfig('em0113/typography/footer_bgposition'),
  105. 'footer_bgrepeat' => Mage::getStoreConfig('em0113/typography/footer_bgrepeat'),
  106. 'footer_text_color1' => Mage::getStoreConfig('em0113/typography/footer_text_color1'),
  107. 'footer_text_color2' => Mage::getStoreConfig('em0113/typography/footer_text_color2'),
  108. 'footer_bgimage' => $footer_bgimage,
  109. 'footer_line1' => Mage::getStoreConfig('em0113/typography/footer_line1'),
  110. 'footer_line2' => Mage::getStoreConfig('em0113/typography/footer_line2'),
  111.  
  112. 'button1_bgcolor' => Mage::getStoreConfig('em0113/typography/button1_bgcolor'),
  113. 'button1_color' => Mage::getStoreConfig('em0113/typography/button1_color'),
  114. 'button1_font' => Mage::getStoreConfig('em0113/typography/button1_font'),
  115. 'button2_bgcolor' => Mage::getStoreConfig('em0113/typography/button2_bgcolor'),
  116. 'button2_font' => Mage::getStoreConfig('em0113/typography/button2_font'),
  117. 'button2_color' => Mage::getStoreConfig('em0113/typography/button2_color'),
  118. 'button3_bgcolor' => Mage::getStoreConfig('em0113/typography/button3_bgcolor'),
  119. 'button3_color' => Mage::getStoreConfig('em0113/typography/button3_color'),
  120. 'button3_font' => Mage::getStoreConfig('em0113/typography/button3_font'),
  121. 'button4_bgcolor' => Mage::getStoreConfig('em0113/typography/button4_bgcolor'),
  122. 'button4_color' => Mage::getStoreConfig('em0113/typography/button4_color'),
  123. 'button4_font' => Mage::getStoreConfig('em0113/typography/button4_font'),
  124.  
  125.  
  126. 'additional_css_file' => Mage::getStoreConfig('em0113/typography/additional_css_file'),
  127. );
  128. }
  129.  
  130. public function getImageBackgroundColor() {
  131. $color = Mage::getStoreConfig('em0113/general/image_bgcolor');
  132. if (!$color) $color = '#ffffff';
  133. $color = str_replace('#', '', $color);
  134. if (strlen ($color )==6){
  135. return array(
  136. hexdec(substr($color, 0, 2)),
  137. hexdec(substr($color, 2, 2)),
  138. hexdec(substr($color, 4, 2))
  139. );
  140. }else{
  141. $color = str_replace('rgba(', '', $color);
  142. $color = str_replace(')', '', $color);
  143. $arr = explode(",", $color);
  144. return array(intval($arr[0]),intval($arr[1]),intval($arr[2]));
  145. }
  146. }
  147.  
  148. public function getCategoriesCustom($parent,$curId){
  149. $result = '';
  150. if($parent->getLevel() == 1)
  151. $result = "<option value='0'>".$this->getCatNameCustom($parent)."</option>";
  152. else{
  153. $result = "<option value='".$parent->getId()."' ";
  154.  
  155. if($curId){
  156. if($curId == $parent->getId()) $result .= " selected='selected'";
  157. }
  158. $result .= ">".$this->getCatNameCustom($parent)."</option>";
  159. }
  160.  
  161. try{
  162. $children = $parent->getChildrenCategories();
  163.  
  164. if(count($children) > 0){
  165. foreach($children as $cat){
  166. $result .= $this->getCategoriesCustom($cat,$curId);
  167. }
  168. }
  169. }
  170. catch(Exception $e){
  171. return '';
  172. }
  173. return $result;
  174. }
  175.  
  176. public function getSubCategory($parent,$curId){
  177.  
  178. try{
  179. $children = $parent->getChildrenCategories();
  180.  
  181. }
  182. catch(Exception $e){
  183. return '';
  184. }
  185. return $children;
  186. }
  187. public function insertStaticBlock($dataBlock) {
  188. // insert a block to db if not exists
  189. $block = Mage::getModel('cms/block')->getCollection()->addFieldToFilter('identifier', $dataBlock['identifier'])->getFirstItem();
  190. if (!$block->getId())
  191. $block->setData($dataBlock)->save();
  192. return $block;
  193. }
  194.  
  195. public function insertPage($dataPage) {
  196. $page = Mage::getModel('cms/page')->getCollection()->addFieldToFilter('identifier', $dataPage['identifier'])->getFirstItem();
  197. if (!$page->getId())
  198. $page->setData($dataPage)->save();
  199. return $page;
  200. }
  201.  
  202. // For search by category
  203. public function getCategoriesCustomSearch($parent,$curId){
  204. $result = '';
  205. if($parent->getLevel() == 1){
  206. $result = "<option value='0'>".$this->getCatNameCustom($parent)."</option>";
  207. }
  208. else{
  209. $result = "<option value='".$parent->getId()."' ";
  210.  
  211. if($curId){
  212. if($curId == $parent->getId()) $result .= " selected='selected'";
  213. }
  214. $result .= ">".$this->getCatNameCustom($parent)."</option>";
  215. }
  216.  
  217. try{
  218. $children = $parent->getChildrenCategories();
  219.  
  220. if(count($children) > 0){
  221. foreach($children as $cat){
  222. $result .= $this->getCategoriesCustomSearch($cat,$curId);
  223. }
  224. }
  225. }
  226. catch(Exception $e){
  227. return '';
  228. }
  229. //var_dump($result);
  230. return $result;
  231. }
  232.  
  233. public function getCatNameCustom($category){
  234. $level = $category->getLevel();
  235. $html = '';
  236. for($i = 0;$i < $level;$i++){
  237. $html .= '&mdash;&ndash;';
  238. }
  239. if($level == 1) return $html.' '.$this->__("All Categories");
  240. else return $html.' '.$category->getName();
  241. }
  242.  
  243. public function checkMobilePhp() {
  244. require_once(Mage::getBaseDir('lib') . DS . 'em/Mobile_Detect.php');
  245. $detect = new Mobile_Detect();
  246. $checkmobile = $detect->isMobile();
  247. $checktablet = $detect->isTablet();
  248. if($checkmobile){
  249. if($checktablet){
  250. return false;
  251. }else{
  252. return true;
  253. }
  254.  
  255. }else{
  256. return false;
  257. }
  258. }
  259.  
  260. public function isShowOfferPrice($productPrice){
  261. if(!Mage::registry('current_product'))
  262. return false;
  263. return Mage::registry('current_product')->getId() == $productPrice->getId();
  264. }
  265.  
  266. public function getHomeUrl() {
  267. return array(
  268. "label" => $this->__('Home'),
  269. "title" => $this->__('Home Page'),
  270. "link" => Mage::getUrl('')
  271. );
  272. }
  273.  
  274. public function getIsLoginCustomer(){
  275. if (Mage::getSingleton('customer/session')->isLoggedIn()==0):
  276. return 0;
  277. endif;
  278. return 1;
  279. }
  280.  
  281. public function getActionReview(){
  282. $url = Mage::helper('core/url')->getCurrentUrl();
  283. $url_check = 'wishlist/index/configure';
  284. if(stripos($url,$url_check)){
  285. $id = Mage::registry('current_product')->getId();
  286. return Mage::getUrl('review/product/post/', array('id' => $id,'_secure' => true));
  287. } else {
  288. $url_check2 = 'checkout/cart/configure';
  289. if(stripos($url,$url_check2)){
  290. $id = Mage::getSingleton('catalog/session')->getLastViewedProductId();
  291. return Mage::getUrl('review/product/post/', array('id' => $id,'_secure' => true));
  292. }else{
  293. $productId = Mage::app()->getRequest()->getParam('id', false);
  294. return Mage::getUrl('review/product/post', array('id' => $productId,'_secure' => true));
  295. }
  296. }
  297. }
  298. }
RAW Paste Data