/** * Method to get the meta-data * * @return array */ public function getRequestData() { // Compile the meta-data if (empty($this->_meta_data) || !is_array($this->_meta_data)) { $application = JFactory::getApplication(); $input = $application->input; $user = JFactory::getUser(); $uri = JURI::getInstance(); $session = JFactory::getSession(); $config = JFactory::getConfig(); $storeHelper = MageBridgeStoreHelper::getInstance(); $bridge = MageBridgeModelBridge::getInstance(); $app_type = $storeHelper->getAppType(); $app_value = $storeHelper->getAppValue(); $arguments = array('api_session' => $bridge->getApiSession(), 'api_user' => MageBridgeEncryptionHelper::encrypt(MagebridgeModelConfig::load('api_user')), 'api_key' => MageBridgeEncryptionHelper::encrypt(MagebridgeModelConfig::load('api_key')), 'api_url' => JURI::root() . 'component/magebridge/?controller=jsonrpc&task=call', 'app' => $application->getClientId(), 'app_type' => $app_type, 'app_value' => $app_value, 'storeview' => MagebridgeModelConfig::load('storeview'), 'storegroup' => MagebridgeModelConfig::load('storegroup'), 'website' => MagebridgeModelConfig::load('website'), 'customer_group' => MagebridgeModelConfig::load('customer_group'), 'joomla_url' => $bridge->getJoomlaBridgeUrl(), 'joomla_sef_url' => $bridge->getJoomlaBridgeSefUrl(), 'joomla_sef_suffix' => (int) MageBridgeUrlHelper::hasUrlSuffix(), 'joomla_user_email' => $application->isSite() && !empty($user->email) ? $user->email : null, 'joomla_current_url' => $uri->current(), 'modify_url' => MagebridgeModelConfig::load('modify_url'), 'enforce_ssl' => MagebridgeModelConfig::load('enforce_ssl'), 'has_ssl' => (int) $uri->isSSL(), 'payment_urls' => MagebridgeModelConfig::load('payment_urls'), 'enable_messages' => MagebridgeModelConfig::load('enable_messages'), 'joomla_session' => session_id(), 'joomla_conf_caching' => $config->get('caching', 60), 'joomla_conf_lifetime' => $config->get('lifetime', 60) * 60, 'magento_session' => $bridge->getMageSession(), 'magento_persistent_session' => $bridge->getMagentoPersistentSession(), 'magento_user_allowed_save_cookie' => isset($_COOKIE['user_allowed_save_cookie']) ? $_COOKIE['user_allowed_save_cookie'] : null, 'request_uri' => MageBridgeUrlHelper::getRequest(), 'request_id' => md5(JURI::current() . serialize($input->get->getArray())), 'post' => !empty($_POST) ? $_POST : null, 'http_referer' => $bridge->getHttpReferer(), 'http_host' => $uri->toString(array('host')), 'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '', 'remote_addr' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '', 'supportkey' => MagebridgeModelConfig::load('supportkey'), 'debug' => (int) MageBridgeModelDebug::isDebug(), 'debug_level' => MagebridgeModelConfig::load('debug_level'), 'debug_display_errors' => MagebridgeModelConfig::load('debug_display_errors'), 'protocol' => MagebridgeModelConfig::load('protocol'), 'state' => 'initializing', 'ajax' => (int) $bridge->isAjax(), 'disable_css' => MageBridgeHelper::getDisableCss(), 'disable_js' => MageBridgeHelper::getDisableJs()); if (MageBridgeTemplateHelper::isMobile()) { $arguments['theme'] = MagebridgeModelConfig::load('mobile_magento_theme'); } else { $arguments['theme'] = MagebridgeModelConfig::load('magento_theme'); } foreach ($arguments as $name => $value) { if (is_string($value)) { $arguments[$name] = MageBridgeEncryptionHelper::base64_encode($value); } } $this->_meta_data = $arguments; } return $this->_meta_data; }
/** * Event onAfterInitialise */ public function onAfterInitialise() { // Don't do anything if MageBridge is not enabled if ($this->isEnabled() == false) { return false; } // Perform actions on the frontend $application = JFactory::getApplication(); // Check for postlogin-cookie if (isset($_COOKIE['mb_postlogin']) && !empty($_COOKIE['mb_postlogin'])) { // If the user is already logged in, remove the cookie if (JFactory::getUser()->id > 0) { setcookie('mb_postlogin', '', time() - 3600, '/', '.' . JURI::getInstance()->toString(array('host'))); } // Otherwise decrypt the cookie and use it here $data = MageBridgeEncryptionHelper::decrypt($_COOKIE['mb_postlogin']); if (!empty($data)) { $customer_email = $data; } } // Perform a postlogin if needed $post = $application->input->post->getArray(); if (empty($post)) { $postlogin_userevents = $this->params->get('postlogin_userevents', 0) == 1 ? true : false; if (empty($customer_email)) { $customer_email = MageBridgeModelBridge::getInstance()->getSessionData('customer/email'); } if (!empty($customer_email)) { MageBridge::getUser()->postlogin($customer_email, null, $postlogin_userevents); } } }
/** * Event onAfterInitialise * * @access public * @param null * @return null */ public function onAfterInitialise() { // Don't do anything if MageBridge is not enabled if ($this->isEnabled() == false) { return false; } // Perform actions on the frontend $application = JFactory::getApplication(); if ($application->isSite()) { // Import the custom module helper - this is needed to make it possible to flush certain positions if ($this->getParam('override_modulehelper', 1) == 1 && class_exists('JModuleHelper') == false) { $component_path = JPATH_SITE . '/components/com_magebridge/'; if (MageBridgeHelper::isJoomla15()) { @(include_once $component_path . 'rewrite/joomla/application/module/helper.php'); } else { if (MageBridgeHelper::isJoomla16()) { @(include_once $component_path . 'rewrite-16/joomla/application/module/helper.php'); } else { if (MageBridgeHelper::isJoomla17()) { @(include_once $component_path . 'rewrite-17/joomla/application/module/helper.php'); } else { @(include_once $component_path . 'rewrite-25/joomla/application/module/helper.php'); } } } } } // Check for postlogin-cookie if (isset($_COOKIE['mb_postlogin']) && !empty($_COOKIE['mb_postlogin'])) { // If the user is already logged in, remove the cookie if (JFactory::getUser()->id > 0) { setcookie('mb_postlogin', '', time() - 3600, '/', '.' . JURI::getInstance()->toString(array('host'))); } // Otherwise decrypt the cookie and use it here $data = MageBridgeEncryptionHelper::decrypt($_COOKIE['mb_postlogin']); if (!empty($data)) { $customer_email = $data; } } // Perform a postlogin if needed $post = JRequest::get('post'); if (empty($post)) { $postlogin_userevents = $this->getParams()->get('postlogin_userevents', 0) == 1 ? true : false; if (empty($customer_email)) { $customer_email = MageBridgeModelBridge::getInstance()->getMageConfig('customer/email'); } if (!empty($customer_email)) { MageBridge::getUser()->postlogin($customer_email, null, $postlogin_userevents); } } }
/** * Method to make login an user */ public function login() { // Fetch the user-email $user_email = MageBridgeEncryptionHelper::decrypt(JFactory::getApplication()->input->getString('token')); $application = JFactory::getApplication(); // Perform a post-login $rt = MageBridge::getUser()->postlogin($user_email, null, true); // Determine the redirect URL $redirectUrl = base64_decode(JFactory::getApplication()->input->getString('redirect')); if (empty($redirectUrl)) { $redirectUrl = MageBridgeModelBridge::getMagentoUrl(); } // Redirect $application->redirect($redirectUrl); $application->close(); }
private function authenticate($auth) { if (!empty($auth) && !empty($auth['api_user']) && !empty($auth['api_key'])) { $api_user = MageBridgeEncryptionHelper::decrypt($auth['api_user']); $api_key = MageBridgeEncryptionHelper::decrypt($auth['api_key']); if ($api_user != MagebridgeModelConfig::load('api_user')) { MageBridgeModelDebug::getInstance()->error('XML-RPC plugin: API-authentication failed: Username did not match'); } elseif ($api_key != MagebridgeModelConfig::load('api_key')) { MageBridgeModelDebug::getInstance()->error('XML-RPC plugin: API-authentication failed: Key did not match'); } else { MageBridgeModelDebug::getInstance()->notice('XML-RPC plugin: API-authentication succeeded'); return true; } } return false; }
/** * Event onAfterRender * * @access public * @param null * @return null */ public function onAfterRender() { // Don't do anything if MageBridge is not enabled if ($this->isEnabled() == false) { return false; } if (JRequest::getCmd('option') == 'com_zoo') { $body = JResponse::getBody(); // Check for Magento CMS-tags if (preg_match('/\\{\\{([^}]+)\\}\\}/', $body)) { // Get system variables $bridge = MageBridgeModelBridge::getInstance(); // Include the MageBridge register $key = md5(var_export($body, true)) . ':' . JRequest::getCmd('option') . ':' . $row->id; $text = MageBridgeEncryptionHelper::base64_encode($body); // Conditionally load CSS if ($this->getParams()->get('load_css') == 1 || $this->getParams()->get('load_js') == 1) { $bridge->register('headers'); } // Build the bridge $segment_id = $bridge->register('filter', $key, $text); $bridge->build(); // Load CSS if needed if ($this->getParams()->get('load_css') == 1) { $bridge->setHeaders('css'); } // Load JavaScript if needed if ($this->getParams()->get('load_js') == 1) { $bridge->setHeaders('js'); } // Get the result from the bridge $result = $bridge->getSegmentData($segment_id); $result = MageBridgeEncryptionHelper::base64_decode($result); // Only replace the original if the new content exists if (!empty($result)) { $body = $result; } } if (!empty($body)) { JResponse::setBody($body); } } }
/** * Event onContentPrepare * * @param string $context * @param object $row * @param JRegistry $params * @param mixed $page * * @return bool */ public function onContentPrepare($context, $row, $params, $page) { // Do not continue if not enabled if ($this->isEnabled() == false) { return false; } // Check for Magento CMS-tags if (!empty($row->text) && preg_match('/{{([^}]+)}}/', $row->text)) { // Get system variables $bridge = MageBridgeModelBridge::getInstance(); // Include the MageBridge register $option = JFactory::getApplication()->input->getCmd('option'); $key = md5(var_export($row, true)) . ':' . $option; $text = MageBridgeEncryptionHelper::base64_encode($row->text); // Conditionally load CSS if ($this->params->get('load_css') == 1 || $this->params->get('load_js') == 1) { $bridge->register('headers'); } // Build the bridge $segment_id = $bridge->register('filter', $key, $text); $bridge->build(); // Load CSS if needed if ($this->params->get('load_css') == 1) { $bridge->setHeaders('css'); } // Load JavaScript if needed if ($this->params->get('load_js') == 1) { $bridge->setHeaders('js'); } // Get the result from the bridge $result = $bridge->getSegmentData($segment_id); $result = MageBridgeEncryptionHelper::base64_decode($result); // Only replace the original if the new content exists if (!empty($result)) { $row->text = $result; } } }
public function decode($block_data) { $block_data = MageBridgeEncryptionHelper::base64_decode($block_data); return $block_data; }
/** * Event onAfterRender * * @access public * @param null * @return null */ public function onAfterRender() { // Don't do anything if MageBridge is not enabled if ($this->isEnabled() == false) { return false; } if (JFactory::getApplication()->input->getCmd('option') == 'com_zoo') { $body = JResponse::getBody(); // Check for Magento CMS-tags if (preg_match('/\\{\\{([^}]+)\\}\\}/', $body) || preg_match('/\\{mb([^}]+)\\}/', $body)) { // Get system variables $bridge = MageBridgeModelBridge::getInstance(); $register = MageBridgeModelRegister::getInstance(); // Detect the request-tag if (preg_match_all('/\\{mbrequest url="([^\\"]+)"\\}/', $body, $matches)) { foreach ($matches[0] as $matchIndex => $match) { $url = $matches[1][$matchIndex]; MageBridgeUrlHelper::setRequest($url); $body = str_replace($match, '', $body); } } // Detect block-names if (preg_match_all('/\\{mbblock name="([^\\"]+)"\\}/', $body, $matches)) { foreach ($matches[0] as $matchIndex => $match) { $block_name = $matches[1][$matchIndex]; $register->add('block', $block_name); } } // Include the MageBridge register $key = md5(var_export($body, true)) . ':' . JFactory::getApplication()->input->getCmd('option'); $text = MageBridgeEncryptionHelper::base64_encode($body); // Conditionally load CSS if ($this->params->get('load_css') == 1 || $this->params->get('load_js') == 1) { $bridge->register('headers'); } // Build the bridge $segment_id = $bridge->register('filter', $key, $text); $bridge->build(); // Load CSS if needed if ($this->params->get('load_css') == 1) { $bridge->setHeaders('css'); } // Load JavaScript if needed if ($this->params->get('load_js') == 1) { $bridge->setHeaders('js'); } // Get the result from the bridge $result = $bridge->getSegmentData($segment_id); $result = MageBridgeEncryptionHelper::base64_decode($result); // Only replace the original if the new content exists if (!empty($result)) { $body = $result; } // Detect block-names if (preg_match_all('/\\{mbblock name="([^\\"]+)"\\}/', $body, $matches)) { foreach ($matches[0] as $matchIndex => $match) { $block_name = $matches[1][$matchIndex]; $block = $bridge->getBlock($block_name); $body = str_replace($match, $block, $body); } } } if (!empty($body)) { JResponse::setBody($body); } } }
/** * Method for logging out with Magento (Single Sign On) * * @param string $username * @return bool|exit */ public static function doSSOLogout($username = null) { // Abort if the input is not valid if (empty($username)) { return false; } // Get system variables $application = JFactory::getApplication(); $session = JFactory::getSession(); // Determine the application $application_name = $application->isAdmin() ? 'admin' : 'frontend'; // Get the security token $token = method_exists('JSession', 'getFormToken') ? JSession::getFormToken() : JUtility::getToken(); // Set the redirection URL if ($application_name == 'admin') { $redirect = JURI::current(); } else { $redirect = MageBridgeUrlHelper::current(); } // Construct the URL $arguments = array('sso=logout', 'app=' . $application_name, 'redirect=' . base64_encode($redirect), 'userhash=' . MageBridgeEncryptionHelper::encrypt($username), 'token=' . $token); $url = MageBridgeModelBridge::getInstance()->getMagentoBridgeUrl() . '?' . implode('&', $arguments); // Redirect the browser to Magento MageBridgeModelDebug::getInstance()->notice("SSO: Logout of '{$username}' from " . $application_name); $application->redirect($url); return true; }
/** * Redirect a specific URL * * @access private * * @param string $name * @param string $value * @param string $redirect * * @return null */ private function doRedirect($name = '', $value = '', $redirect = null) { if ($this->input->getCmd($name) == $value) { $return = base64_decode($this->input->getString('return')); if (!empty($return)) { $return = MageBridgeEncryptionHelper::base64_encode($return); $redirect .= '/referer/' . $return . '/'; } header('Location: ' . MageBridgeUrlHelper::route($redirect)); exit; } }
public static function filterContent($content) { // Allow to disable this filtering if (MagebridgeModelConfig::load('filter_content') == 0) { return $content; } // Get common variables $bridge = MageBridgeModelBridge::getInstance(); // Convert all remaining Magento links to Joomla! links $content = str_replace($bridge->getMagentoUrl() . 'index.php/', $bridge->getJoomlaBridgeUrl(), $content); $content = str_replace($bridge->getMagentoUrl() . 'magebridge.php/', $bridge->getJoomlaBridgeUrl(), $content); // Implement a very dirty hack because PayPal converts URLs "&" to "and" $current = MageBridgeUrlHelper::current(); if (strstr($current, 'paypal') && strstr($current, 'redirect')) { // Try to find the distorted URLs $matches = array(); if (preg_match_all('/([^\\"\']+)com_magebridgeand([^\\"\']+)/', $content, $matches)) { foreach ($matches[0] as $match) { // Replace the wrong "and" words with "&" again $url = str_replace('com_magebridgeand', 'com_magebridge&', $match); $url = str_replace('rootand', 'root&', $url); // Replace the wrong URL with its correction $content = str_replace($match, $url, $content); } } } // Replace all uenc-URLs from Magento with URLs parsed through JRoute $matches = array(); $replaced = array(); if (preg_match_all('/\\/uenc\\/([a-zA-Z0-9\\-\\_\\,]+)/', $content, $matches)) { foreach ($matches[1] as $match) { // Decode the match $original_url = MageBridgeEncryptionHelper::base64_decode($match); $url = $original_url; $url = MageBridgeUrlHelper::stripUrl($url); // Convert the non-SEF URL to a SEF URL if (preg_match('/^index.php\\?option=com_magebridge/', $url)) { // Parse the URL but do NOT turn it into SEF because of Mage_Core_Controller_Varien_Action::_isUrlInternal() $url = MageBridgeHelper::filterUrl(str_replace('/', urldecode('/'), $url), false); $url = $bridge->getJoomlaBridgeSefUrl($url); } else { if (!preg_match('/^(http|https)/', $url)) { $url = $bridge->getJoomlaBridgeSefUrl($url); } $url = preg_replace('/\\?SID=([a-zA-Z0-9\\-\\_]{12,42})/', '', $url); } // Extra check on HTTPS if (JURI::getInstance()->isSSL() == true) { $url = str_replace('http://', 'https://', $url); } else { $url = str_replace('https://', 'http://', $url); } // Replace the URL in the content if ($original_url != $url && $original_url . '/' != $url && !in_array($match, $replaced)) { MageBridgeModelDebug::getInstance()->notice('Translating uenc-URL from ' . $original_url . ' to ' . $url); $base64_url = MageBridgeEncryptionHelper::base64_encode($url); $content = str_replace($match, $base64_url, $content); $replaced[] = $match; } } } // Match all URLs and filter them $matches = array(); if (preg_match_all('/index.php\\?option=com_magebridge([^\'\\"\\<]+)([\'\\"\\<]{1})/', $content, $matches)) { for ($i = 0; $i < count($matches[0]); $i++) { $oldurl = 'index.php?option=com_magebridge' . $matches[1][$i]; $end = $matches[2][$i]; $newurl = MageBridgeHelper::filterUrl($oldurl); if (!empty($newurl)) { $content = str_replace($oldurl . $end, $newurl . $end, $content); } } } // Clean-up left-overs $content = str_replace('?___SID=U', '', $content); $content = str_replace('?___SID=S', '', $content); $content = preg_replace('/\\?___store=([a-zA-Z0-9]+)/', '', $content); $content = preg_replace('/\\?SID=([a-zA-Z0-9\\-\\_]{12,42})/', '', $content); // Remove double-slashes //$basedir = preg_replace('/^([\/]?)(.*)([\/]?)$/', '\2', JURI::base(true)); //$content = str_replace(JURI::base().$basedir, JURI::base(), $content); $content = str_replace(JURI::base() . '/', JURI::base(), $content); // Adjust wrong media-URLs if (JURI::getInstance()->isSSL() == true) { $non_https = preg_replace('/^https:/', 'http:', $bridge->getMagentoUrl()); $https = preg_replace('/^http:/', 'https:', $bridge->getMagentoUrl()); $content = str_replace($non_https, $https, $content); } // Adjust incorrect URLs with parameters starting with & if (preg_match_all('/(\'|\\")(http|https):\\/\\/([^\\&\\?\'\\"]+)\\&/', $content, $matches)) { foreach ($matches[0] as $index => $match) { $content = str_replace($matches[3][$index] . '&', $matches[3][$index] . '?', $content); } } return $content; }
public static function decrypt($data) { return MageBridgeEncryptionHelper::decrypt($data); }
/** * Helper method to authenticate this API call * * @param array $auth * * @return bool */ private function authenticate($auth) { if (!empty($auth) && !empty($auth['api_user']) && !empty($auth['api_key'])) { $apiUser = MageBridgeEncryptionHelper::decrypt($auth['api_user']); $apiKey = MageBridgeEncryptionHelper::decrypt($auth['api_key']); if ($apiUser != MagebridgeModelConfig::load('api_user')) { $this->debug->error('JSON-RPC: API-authentication failed: Username "' . $apiUser . '" did not match'); } else { if ($apiKey != MagebridgeModelConfig::load('api_key')) { $this->debug->error('JSON-RPC: API-authentication failed: Key "' . $apiKey . '" did not match'); } else { return true; } } } return false; }
public function getHttpReferer() { if (preg_match('/\\/(uenc|referer)\\/([a-zA-Z0-9\\,]+)/', JURI::current(), $match)) { $this->_http_referer = MageBridgeEncryptionHelper::base64_decode($match[2]); // If this is a MageBridge page, use it only if its not a customer-page, or homepage } else { if (preg_match('/\\/customer\\/account\\//', JURI::current()) == false && preg_match('/\\/persistent\\/index/', JURI::current()) == false && preg_match('/\\/checkout\\/cart/', JURI::current()) == false && JURI::current() != MageBridge::getBridge()->getJoomlaBridgeUrl()) { $this->_http_referer = JURI::getInstance()->toString(); } else { if (empty($this->_http_referer)) { $session = JFactory::getSession(); $this->_http_referer = $session->get('magebridge.http_referer'); } } } //if (empty($this->_http_referer) && isset($_SERVER['HTTP_REFERER'])) { // $this->_http_referer = $_SERVER['HTTP_REFERER']; //} return $this->_http_referer; }
/** * Method to load the JavaScript headers * * @param array $headers * @return null */ public function loadJs($headers) { // Dot not load if this is not the right document-class $document = JFactory::getDocument(); if ($document->getType() != 'html') { return false; } // Check whether all scripts are disabled $disable_js = MagebridgeModelConfig::load('disable_js_mage'); if ($disable_js == 'all') { return false; } // Check whether the bridge is offline $offline = MageBridge::getBridge()->isOffline(); if ($offline == true) { return false; } // Initialize the internal array $this->_scripts = array(); // Get system variables $bridge = MageBridge::getBridge(); $html = "<script type=\"text/javascript\">\n" . "//<![CDATA[\n" . "var BLANK_URL = '" . $this->getBaseJsUrl() . "blank.html';\n" . "var BLANK_IMG = '" . $this->getBaseJsUrl() . "spacer.gif';\n" . "//]]>\n" . "</script>\n"; $document->addCustomTag($html); // Load Prototype if ($this->loadPrototype() == true) { $this->_has_prototype = true; } // Loop through all the header-items fetched from Magento if (!empty($headers['items'])) { $jslist = array(); $jstags = array(); foreach ($headers['items'] as $item) { if ($item['type'] == 'skin_js' || $item['type'] == 'js') { if (MageBridgeHelper::jsIsDisabled($item['name']) == true) { continue; } $this->_stylesheets[] = $item['name']; $this->_scripts[] = $item['name']; if (empty($item['name'])) { continue; } // If this is a skin-script, construct the tag but add it later to the HTML-header if ($item['type'] == 'skin_js') { if (!preg_match('/^http/', $item['path'])) { $item['path'] = $bridge->getMagentoUrl() . $item['path']; } $tag = '<script type="text/javascript" src="' . $item['path'] . '"></script>' . "\n"; $jstags[] = $tag; continue; } // If this is a conditional script, construct the tag but add it later to the HTML-header if (!empty($item['if'])) { if (!preg_match('/^http/', $item['path'])) { $item['path'] = $bridge->getMagentoUrl() . $item['path']; } $tag = '<script type="text/javascript" src="' . $item['path'] . '"></script>' . "\n"; $tag = '<!--[if ' . $item['if'] . ' ]>' . "\n" . $tag . '<![endif]-->' . "\n"; $jstags[] = $tag; continue; } // Detect Prototype if (strstr($item['path'], 'prototype') || strstr($item['path'], 'scriptaculous')) { $this->_has_prototype = true; // Load an optimized Prototype/script.acul.us version if (MagebridgeModelConfig::load('use_protoaculous') == 1 || MagebridgeModelConfig::load('use_protoculous') == 1) { $skip_scripts = array('prototype/prototype.js', 'scriptaculous/builder.js', 'scriptaculous/effects.js', 'scriptaculous/dragdrop.js', 'scriptaculous/controls.js', 'scriptaculous/slider.js'); if (in_array($item['name'], $skip_scripts)) { continue; } } // Skip these, if the Google API is already loaded if (MagebridgeModelConfig::load('use_google_api') == 1) { if (preg_match('/prototype.js$/', $item['name'])) { continue; } if (preg_match('/scriptaculous.js$/', $item['name'])) { continue; } } } // Detect jQuery and replace it if (preg_match('/jquery-([0-9]+)\\.([0-9]+)\\.([0-9]+)/', $item['path']) || preg_match('/jquery.js$/', $item['path']) || preg_match('/jquery.min.js$/', $item['path'])) { if (MagebridgeModelConfig::load('replace_jquery') == 1) { MageBridgeTemplateHelper::load('jquery'); continue; } } // Detect the translation script if (strstr($item['name'], 'translate.js')) { $translate = true; } // Load this script through JS merging or not if (MagebridgeModelConfig::load('merge_js') == 1) { $jslist[] = $item['name']; } else { if (MagebridgeModelConfig::load('merge_js') == 2 && !empty($headers['merge_js'])) { // Don't do anything here yet } else { if (!preg_match('/^http/', $item['path'])) { $item['path'] = $bridge->getMagentoUrl() . $item['path']; } $item['path'] = $this->convertUrl($item['path']); $tag = '<script type="text/javascript" src="' . $item['path'] . '"></script>' . "\n"; $jstags[] = $tag; } } } } if (MagebridgeModelConfig::load('merge_js') == 2 && !empty($headers['merge_js'])) { $this->addScript($headers['merge_js']); } else { if (!empty($jslist)) { $this->addScript($this->getBaseJsUrl() . 'index.php?c=auto&f=,' . implode(',', $jslist)); } } if (!empty($jstags)) { foreach ($jstags as $tag) { if (!empty($tag)) { $document->addCustomTag($tag); } } } } // Load some extra JavaScript tags if (isset($headers['custom'])) { foreach ($headers['custom'] as $custom) { $custom = MageBridgeEncryptionHelper::base64_decode($custom); $custom = preg_replace('/Mage.Cookies.domain([^;]+)\\;/m', 'Mage.Cookies.domain = null;', $custom); $document->addCustomTag($custom); } } else { if (isset($translate) && $translate == true) { $html = '<script type="text/javascript">var Translator = new Translate([]);</script>'; $document->addCustomTag($html); } } return; }
/** * Helper-method to get the HTTP Referer to send to Magento * * @return string */ public function getHttpReferer() { // If this is a non-MageBridge page, use it if (JFactory::getApplication()->input->getCmd('option') != 'com_magebridge') { $referer = JURI::getInstance()->toString(); // If the referer is set on the URL, use it also } elseif (preg_match('/\\/(uenc|referer)\\/([a-zA-Z0-9\\,\\_\\-]+)/', JURI::current(), $match)) { $referer = MageBridgeEncryptionHelper::base64_decode($match[2]); // If this is the MageBridge page checkout/cart/updatePost, return to the checkout } else { if (preg_match('/\\/checkout\\/cart\\/([a-zA-Z0-9]+)Post/', JURI::current()) == true) { $referer = MageBridgeUrlHelper::route('checkout/cart'); // If this is a MageBridge page, use it only if its not a customer-page, or homepage } else { if (preg_match('/\\/customer\\/account\\//', JURI::current()) == false && preg_match('/\\/persistent\\/index/', JURI::current()) == false && preg_match('/\\/review\\/product\\/post/', JURI::current()) == false && preg_match('/\\/remove\\/item/', JURI::current()) == false && preg_match('/\\/newsletter\\/subscriber/', JURI::current()) == false && preg_match('/\\/checkout\\/cart/', JURI::current()) == false && $this->isAjax() == false && JURI::current() != $this->getJoomlaBridgeUrl()) { $referer = JURI::getInstance()->toString(); } } } // Load the stored referer from the session if (empty($referer)) { $session = JFactory::getSession(); $referer = $session->get('magebridge.http_referer'); } // Use the default referer if (empty($this->_http_referer)) { if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != JURI::current()) { $referer = $_SERVER['HTTP_REFERER']; } } $this->_http_referer = $referer; return $this->_http_referer; }
/** * Proxy uploads * * @return array */ public function upload() { // Don't do anything outside of the MageBridge component if ($this->app->input->getCmd('option') != 'com_magebridge') { return array(); } // Define some variables $tmpFiles = array(); // Automatically handle file uploads if (!empty($_FILES)) { foreach ($_FILES as $name => $file) { if (empty($file['tmp_name']) || empty($file['name'])) { continue; } // Detect file upload problems $errorMessage = null; switch ($file['error']) { case 1: case 2: $errorMessage = JText::sprintf('Upload of %s exceeded the maximum size [%d]', $file['name'], $file['error']); break; case 3: case 4: case 6: case 7: case 8: $errorMessage = JText::sprintf('Error when uploading file %s [%d]', $file['name'], $file['error']); break; } // @todo: Why re-upload file to Joomla? Why not directly to Magento using tmp file? // Move the uploaded file to the Joomla tmp-directory if (is_readable($file['tmp_name'])) { // Upload the specific file jimport('joomla.filesystem.file'); $tmpFile = $this->getUploadPath() . '/' . $file['name']; JFile::upload($file['tmp_name'], $tmpFile); // Check if the file is there if (!is_file($tmpFile) || !is_readable($tmpFile)) { $errorMessage = JText::sprintf('Unable to read uploaded file %s', $tmpFile); } else { if (!filesize($tmpFile) > 0) { $errorMessage = JText::sprintf('Uploaded file %s is empty', $tmpFile); } else { $file['tmp_name'] = $tmpFile; $tmpFiles[$name] = $file; continue; } } } else { $errorMessage = JText::sprintf('Uploaded file %s is not readable', $file['tmp_name']); } // Handle errors if (!empty($errorMessage)) { // See if we can redirect back to the same old page $request = JFactory::getApplication()->input->getString('request'); if (preg_match('/\\/uenc\\/([a-zA-Z0-9\\,\\-\\_]+)/', $request, $uenc)) { $page = MageBridgeEncryptionHelper::base64_decode($uenc[1]); if (!empty($uenc) && !empty($page)) { // Remove the old file $this->cleanup($tmpFiles); // Redirect to the old page $this->app->redirect($page, $errorMessage, 'error'); $this->app->close(); return array(); } } // If no redirect could be given, do not handle this at all, but just set an error $this->app->enqueueMessage($errorMessage, 'error'); } } } return $tmpFiles; }
/** * Decrypt data after encryption * * @param string $data * @return mixed */ public static function decrypt($data) { // Don't do anything with empty data $data = trim($data); if (empty($data) || is_string($data) == false && is_numeric($data) == false) { return null; } // Detect data that is not encrypted $data = urldecode($data); if (strstr($data, '|=|') == false) { return $data; } $array = explode('|=|', $data); $encrypted = MageBridgeEncryptionHelper::base64_decode($array[0], true); $key = MageBridgeEncryptionHelper::getSaltedKey($array[1]); // PHP 5.5 version if (version_compare(PHP_VERSION, '5.5.0') >= 0) { try { $td = mcrypt_module_open(MCRYPT_CAST_256, '', 'ecb', ''); $iv = substr($key, 0, mcrypt_get_iv_size(MCRYPT_CAST_256, MCRYPT_MODE_CFB)); mcrypt_generic_init($td, $key, $iv); $decrypted = mdecrypt_generic($td, $encrypted); $decrypted = trim($decrypted); return $decrypted; } catch (Exception $e) { Mage::getSingleton('magebridge/debug')->error("Error while decrypting: " . $e->getMessage()); return null; } } else { try { $iv = substr($key, 0, mcrypt_get_iv_size(MCRYPT_CAST_256, MCRYPT_MODE_CFB)); $decrypted = @mcrypt_cfb(MCRYPT_CAST_256, $key, $encrypted, MCRYPT_DECRYPT, $iv); $decrypted = trim($decrypted); return $decrypted; } catch (Exception $e) { Mage::getSingleton('magebridge/debug')->error("Error while decrypting: " . $e->getMessage()); return null; } } }
<?php /** * Joomla! module MageBridge: Newsletter block * * @author Yireo (info@yireo.com) * @package MageBridge * @copyright Copyright 2015 * @license GNU Public License * @link http://www.yireo.com */ // No direct access defined('_JEXEC') or die('Restricted access'); // Import the MageBridge autoloader require_once JPATH_SITE . '/components/com_magebridge/helpers/loader.php'; // Read the parameters $layout = $params->get('layout', 'default'); // Call the helper require_once dirname(__FILE__) . '/helper.php'; $block = modMageBridgeNewsletterHelper::build($params); // Get the current user $user = JFactory::getUser(); // Set the form URL $form_url = MageBridgeUrlHelper::route('newsletter/subscriber/new'); $redirect_url = MageBridgeUrlHelper::route(MageBridgeUrlHelper::getRequest()); $redirect_url = MageBridgeEncryptionHelper::base64_encode($redirect_url); // Require form validation JHTML::_('behavior.formvalidation'); // Include the layout-file require JModuleHelper::getLayoutPath('mod_magebridge_newsletter', $layout);
/** * Method to authenticate an user - called from the "Authentication - MageBridge" plugin * * @param string $username * @param string $password * @param string $application * @return array */ public function authenticate($username = null, $password = null, $application = 'site') { // Encrypt values for transfer through the MageBridge API $username = MageBridgeEncryptionHelper::encrypt($username); $password = MageBridgeEncryptionHelper::encrypt($password); // Construct the API-arguments $arguments = array('username' => $username, 'password' => $password, 'application' => $application, 'disable_events' => 1); // Initalize the needed objects $bridge = MageBridgeModelBridge::getInstance(); $register = MageBridgeModelRegister::getInstance(); // Build the bridge and fetch the result $id = $register->add('authenticate', null, $arguments); $bridge->build(); $data = $register->getDataById($id); return $data; }
/** * Method to display the requested view */ public function display($tpl = null) { // Load the bridge $bridge = MageBridgeModelBridge::getInstance(); // Load the parameters $layout = $this->getLayout(); $params = MageBridgeHelper::getParams(); // Set the request based upon the choosen category $request = $params->get('request', false) ? $params->get('request') : MageBridgeUrlHelper::getRequest(); $prefix = preg_replace('/\\?(.*)/', '', $request); $suffix = preg_replace('/(.*)\\?/', '', $request); // Check if this a non-URL-optimized request if (is_numeric($prefix)) { $request = MageBridgeUrlHelper::getLayoutUrl($layout, $prefix); } else { // Determine the suffix if ($layout == 'product') { $suffix = $bridge->getSessionData('catalog/seo/product_url_suffix'); } else { if ($layout == 'category') { $suffix = $bridge->getSessionData('catalog/seo/category_url_suffix'); } } // Add the suffix, if this is set in the Magento configuration if (!empty($suffix) && !preg_match('/' . $suffix . '$/', $request)) { $request .= $suffix; } } // Add the qty parameter $qty = JFactory::getApplication()->input->getInt('qty'); if (!empty($qty)) { $request .= 'qty/' . $qty . '/'; } // Check for the redirect parameter $redirect = $this->input->getString('redirect'); if ($layout == 'addtocart' && empty($redirect)) { $redirect = 'checkout/cart'; } // Add the redirect parameter if (!empty($redirect)) { $redirect = MageBridgeUrlHelper::route($redirect); if (!empty($redirect)) { $request .= 'uenc/' . MageBridgeEncryptionHelper::base64_encode($redirect) . '/'; } $form_key = MageBridgeModelBridge::getInstance()->getSessionData('form_key'); if (!empty($form_key)) { $request .= 'form_key/' . $form_key; } } // Add the mode (for catalog) $mode = $params->get('mode'); if (!empty($mode)) { $request .= '?mode=' . $mode; } // Set the request in the bridge and wait for the response $this->setRequest($request); // Reuse this request to set the Canonical URL if (MagebridgeModelConfig::load('enable_canonical') == 1) { $uri = MageBridgeUrlHelper::route($request); $document = JFactory::getDocument(); $document->setMetaData('canonical', $uri); } // Set which block to display $this->setBlock('content'); parent::display($tpl); }
public static function decrypt($data) { // Don't do anything with empty data $data = trim($data); if (empty($data) || is_string($data) == false && is_numeric($data) == false) { return null; } // Detect data that is not encrypted if (strstr($data, '|=|') == false) { return $data; } $array = explode('|=|', $data); $encrypted = MageBridgeEncryptionHelper::base64_decode($array[0], true); $key = MageBridgeEncryptionHelper::getSaltKey($array[1]); $iv = substr($key, 0, mcrypt_get_iv_size(MCRYPT_CAST_256, MCRYPT_MODE_CFB)); try { $decrypted = mcrypt_cfb(MCRYPT_CAST_256, $key, $encrypted, MCRYPT_DECRYPT, $iv); $decrypted = trim($decrypted); return $decrypted; } catch (Exception $e) { Mage::getSingleton('magebridge/debug')->error("Error while decrypting: " . $e->getMessage()); return null; } }
public static function decrypt($string) { return MageBridgeEncryptionHelper::decrypt($string); }