public function onPurchase($gid = null, $user = null, $status = null) { // Get common records $db = JFactory::getDBO(); // Joomla! 1.5 method if (MageBridgeHelper::isJoomla15()) { // Set the user-type $query = 'SELECT `name` FROM `#__core_acl_aro_groups` WHERE `id`=' . (int) $gid; $db->setQuery($query); $usertype = $db->loadResult(); $query = 'UPDATE `#__users` SET `gid`=' . (int) $gid . ', `usertype`=' . $db->Quote($usertype) . ' WHERE `id`=' . (int) $user->id; $db->setQuery($query); $db->query(); $query = 'UPDATE `#__core_acl_groups_aro_map` SET `group_id`=' . (int) $gid . ' WHERE `aro_id` = (SELECT id FROM `#__core_acl_aro` WHERE value = ' . (int) $user->id . ' LIMIT 1)'; $db->setQuery($query); $db->query(); // Joomla! 1.6 method } else { // See if the user is already listed $query = 'SELECT user_id FROM `#__user_usergroup_map` WHERE `user_id`=' . (int) $user->id . ' AND `group_id`=' . (int) $gid . ' LIMIT 1'; $db->setQuery($query); $result = $db->loadResult(); // Add the user if (empty($result)) { $query = 'INSERT INTO `#__user_usergroup_map` SET `user_id`=' . (int) $user->id . ', `group_id`=' . (int) $gid; $db->setQuery($query); $db->query(); } } return true; }
public function isEnabled() { if (MageBridgeHelper::isJoomla15()) { return false; } return true; }
public function getScript($block, $element, $url = null) { // Set the default AJAX-URL if (empty($url)) { $url = self::getUrl($block); } // Load ProtoType if (MageBridgeTemplateHelper::hasPrototypeJs() == true) { $script = "Event.observe(window,'load',function(){new Ajax.Updater('{$element}','{$url}',{method:'get'});});"; // Load jQuery } else { if (JFactory::getApplication()->get('jquery') == true) { $script = "jQuery(document).ready(function(){\n" . " jQuery('#" . $element . "').load('" . $url . "');" . "});\n"; // Load MooTools (Joomla!) } else { if (MageBridgeHelper::isJoomla15()) { JHTML::_('behavior.mootools'); $script = "window.addEvent('domready', function(){\n" . " var MBajax = new Ajax( '" . $url . "', {onSuccess: function(r){\n" . " \$('" . $element . "').innerHTML = r;\n" . " }});\n" . " MBajax.request();\n" . "});\n"; // Load MooTools (Joomla! 1.6) } else { JHTML::_('behavior.mootools'); $script = "window.addEvent('domready', function(){\n" . " var MBajax = new Request({\n" . " url: '" . $url . "', \n" . " onComplete: function(r){\n" . " \$('" . $element . "').innerHTML = r;\n" . " }\n" . " }).send();\n" . "});\n"; } } } return $script; }
/** * Load the parameters * * @access private * @param null * @return JParameter */ private function getParams() { if (!MageBridgeHelper::isJoomla15()) { return $this->params; } else { $plugin = JPluginHelper::getPlugin('system', 'magebridgeyoo'); $params = new JParameter($plugin->params); return $params; } }
public static function getUsergroupOptions() { if (MageBridgeHelper::isJoomla15()) { $query = 'SELECT `id` AS `value`, `name` AS `text` FROM `#__core_acl_aro_groups` WHERE `parent_id` NOT IN (0, 17, 28)'; } else { $query = 'SELECT `id` AS `value`, `title` AS `text` FROM `#__usergroups` WHERE `parent_id` > 0'; } $db = JFactory::getDBO(); $db->setQuery($query); return $db->loadObjectList(); }
public function ajax($url, $div) { JHTML::_('behavior.mootools'); if (MageBridgeHelper::isJoomla15()) { $script = "<script type=\"text/javascript\">\n" . "window.addEvent('domready', function(){\n" . " var MBajax = new Ajax( '" . $url . "', {onSuccess: function(r){\n" . " \$('" . $div . "').setHTML(r);\n" . " }});\n" . " MBajax.request();\n" . "});\n" . "</script>"; } else { $script = "<script type=\"text/javascript\">\n" . "window.addEvent('domready', function(){\n" . " var MBajax = new Request.HTML({\n" . " method: 'get',\n" . " url: '" . $url . "', \n" . " update: '" . $div . "'\n" . " }).send();\n" . "});\n" . "</script>"; } $document = JFactory::getDocument(); $document->addCustomTag($script); }
/** * Load the parameters * * @access private * @param null * @return JParameter */ private function getParams() { if (MageBridgeHelper::isJoomla15() == false) { return $this->params; } else { jimport('joomla.html.parameter'); $plugin = JPluginHelper::getPlugin('magebridge.newsletter', 'ccnewsletter'); $params = new JParameter($plugin->params); return $params; } }
public function checkCondition($condition = null) { $user = JFactory::getUser(); $condition = (int) $condition; if (!$condition > 0) { return false; } if (MageBridgeHelper::isJoomla15()) { if ($user->get('gid', 0) == $condition) { return true; } } else { if (is_array($user->groups) && in_array($condition, $user->groups)) { return true; } } return false; }
public function getMagentoGroupId($user) { static $rows = null; if (!is_array($rows)) { $db = JFactory::getDBO(); $db->setQuery('SELECT * FROM #__magebridge_usergroups WHERE `published`=1 ORDER BY `ordering`'); $rows = $db->loadObjectList(); } if (!empty($rows)) { if (MageBridgeHelper::isJoomla15()) { $usergroups = isset($user['gid']) ? array($user['gid']) : array(); } else { $usergroups = isset($user['groups']) ? $user['groups'] : array(); } foreach ($rows as $row) { if (in_array($row->joomla_group, $usergroups)) { return $row->magento_group; } } } return null; }
/** * Handle the event that is generated after a customer logs out (bridge-response) * * @param array $arguments * * @return bool */ public function mageCustomerLogoutAfter($arguments = array()) { // Abort if the input is invalid if (empty($arguments) || empty($arguments['customer']['email'])) { return false; } // Joomla! expects more parameters, so we need to fetch those first $customer = $arguments['customer']; $user = $this->getUser()->loadByEmail($customer['email']); $customer['username'] = $customer['email']; $customer['id'] = $user->id; // Add options for our own user-plugin // @todo: options: // - action = core.login.site // - remember = 1 // - return = {URL} // - entry_url = {URL} $options = array('disable_bridge' => true, 'action' => 'core.login.site'); // Call the Joomla! event "onLogoutUser" $eventName = MageBridgeHelper::isJoomla15() ? 'onLogoutUser' : 'onUserLogout'; JPluginHelper::importPlugin('user'); JFactory::getApplication()->triggerEvent($eventName, array($customer, $options)); return true; }
private function getContentPlugins() { static $plugins = null; if (!empty($plugins)) { return $plugins; } // Get system variables $db = JFactory::getDBO(); if (MageBridgeHelper::isJoomla15()) { $query = 'SELECT element FROM #__plugins' . ' WHERE folder="content" AND published >= 1 AND element NOT LIKE "magebridge%" AND element != "emailcloak"' . ' ORDER BY ordering'; } else { $query = 'SELECT element FROM `#__extensions`' . ' WHERE `type` = "plugin" AND `enabled` = 1 AND element NOT LIKE "magebridge%" AND element != "emailcloak"' . ' ORDER BY ordering'; } $db->setQuery($query); $plugins = method_exists($db, 'loadColumn') ? $db->loadColumn() : $db->loadResultArray(); if ($plugins == false) { return false; } return $plugins; }
private function update($extension_name = null) { // Do not continue if the extension name is empty if ($extension_name == null) { JError::raiseWarning('SOME_ERROR_CODE', JText::_('No extension specified')); return false; } // Fetch a list of available packages $packages = MageBridgeUpdateHelper::getPackageList(); foreach ($packages as $package) { if ($package['name'] == $extension_name) { $extension = $package; break; } } // Do not continue if the extension does not appear from the list if ($extension == null) { JError::raiseWarning('SOME_ERROR_CODE', JText::_('Unknown extension')); return false; } // Premature check for the component-directory to be writable if ($extension['type'] == 'component' && JFactory::getConfig()->getValue('ftp_enable') == 0) { if (is_dir(JPATH_ADMINISTRATOR . '/components/' . $extension['name']) && !is_writable(JPATH_ADMINISTRATOR . '/components/' . $extension['name'])) { JError::raiseWarning('SOME_ERROR_CODE', JText::_('Component directory is not writable')); return false; } else { if (!is_dir(JPATH_ADMINISTRATOR . '/components/' . $extension['name']) && !is_writable(JPATH_ADMINISTRATOR . '/components')) { JError::raiseWarning('SOME_ERROR_CODE', JText::_('Components folder is not writable')); return false; } } } // Construct the update URL $extension_uri = $extension['name']; $extension_uri .= MageBridgeHelper::isJoomla15() ? '_j15' : '_j25'; $extension_uri .= '.' . MagebridgeModelConfig::load('update_format'); $extension_url = $this->getUrl($extension_uri); // Either use fopen() or CURL if (ini_get('allow_url_fopen') == 1 && MagebridgeModelConfig::load('update_method') == 'joomla') { $package_file = JInstallerHelper::downloadPackage($extension_url, $extension_uri); } else { $package_file = MageBridgeUpdateHelper::downloadPackage($extension_url, $extension_uri); } // Simple check for the result if ($package_file == false) { JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('Failed to download update for %s', $extension_uri)); return false; } // Check if the downloaded file exists $tmp_path = JFactory::getConfig()->getValue('config.tmp_path'); $package_path = $tmp_path . '/' . $package_file; if (!is_file($package_path)) { JError::raiseWarning('MB', JText::sprintf('File %s does not exist', $package_path)); return false; } // Check if the file is readable if (!is_readable($package_path)) { JError::raiseWarning('MB', JText::sprintf('File %s is not readable', $package_path)); return false; } // Check if the downloaded file is abnormally small (so it might just contain a simple warning-text) if (filesize($package_path) < 128) { $contents = @file_get_contents($package_path); if (empty($contents)) { JError::raiseWarning('MB', JText::sprintf('Valid archive but empty content.')); return false; } else { if (preg_match('/^Restricted/', $contents)) { JError::raiseWarning('MB', JText::sprintf('Not allowed to access updates.')); return false; } } JError::raiseWarning('MB', JText::sprintf('File %s is not a valid archive', $package_path)); return false; } // Now we assume this is an archive, so let's unpack it $package = JInstallerHelper::unpack($package_path); if ($package == false) { JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('Unable to find update for %s on local filesystem', $extension['name'])); return false; } // Quick workaround to prevent Koowa proxying the database if (class_exists('KInput')) { KInput::set('option', 'com_installer', 'get'); } // Call the actual installer to install the package $installer = JInstaller::getInstance(); if ($installer->install($package['dir']) == false) { JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('Failed to install %s', $extension['name'])); return false; } // Get the name of downloaded package if (!is_file($package['packagefile'])) { $package['packagefile'] = JFactory::getConfig()->getValue('config.tmp_path') . '/' . $package['packagefile']; } // Clean up the installation @JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']); // Post install procedure if (isset($extension['post_install_query'])) { $query = trim($extension['post_install_query']); if (!empty($query)) { $db = JFactory::getDBO(); $db->setQuery($query); $db->query(); if ($db->getErrorMsg()) { JError::raiseWarning('MB', JText::sprintf('Post install query failed: %s', $db->getErrorMsg())); return false; } } } return true; }
public static function getPostInstallQuery($type = null, $name = null, $value = null) { if ($type == 'module') { $query = 'UPDATE `#__modules` SET `position`="' . $value . '" WHERE `module`="' . $name . '"'; } else { if (MageBridgeHelper::isJoomla15()) { $query = 'UPDATE `#__plugins` SET `published`="1" WHERE `element`="' . $name . '" AND `folder`="' . $value . '"'; } else { $query = 'UPDATE `#__extensions` SET `enabled`="1" WHERE `type`="plugin" AND `element`="' . $name . '" AND `folder`="' . $value . '"'; } } return $query; }
/** * Method to do all plugin checks * * @package MageBridge * @access public * @param null * @return null */ public function doPluginChecks() { $application = JFactory::getApplication(); $db = JFactory::getDBO(); $plugins = array(array('authentication', 'magebridge', 'Authentication - MageBridge', 'CHECK_PLUGIN_AUTHENTICATION'), array('magento', 'magebridge', 'Magento - MageBridge', 'CHECK_PLUGIN_MAGENTO'), array('magebridge', 'magebridge', 'MageBridge - Core', 'CHECK_PLUGIN_MAGEBRIDGE'), array('user', 'magebridge', 'User - MageBridge', 'CHECK_PLUGIN_USER'), array('system', 'magebridge', 'System - MageBridge', 'CHECK_PLUGIN_SYSTEM'), array('system', 'magebridgepre', 'System - MageBridge Preloader', 'CHECK_PLUGIN_PRELOADER')); foreach ($plugins as $plugin) { $group = $plugin[0]; $name = $plugin[1]; $title = $plugin[2]; $description = $plugin[3]; if (MageBridgeHelper::isJoomla15()) { $result = file_exists(JPATH_SITE . '/plugins/' . $group . '/' . $name . '.php') ? self::CHECK_OK : self::CHECK_ERROR; } else { $result = file_exists(JPATH_SITE . '/plugins/' . $group . '/' . $name . '/' . $name . '.php') ? self::CHECK_OK : self::CHECK_ERROR; } if ($result == self::CHECK_ERROR) { $description = JText::_('CHECK_PLUGIN_NOT_INSTALLED'); $this->addResult('extensions', $title, self::CHECK_ERROR, $description); } else { $pluginObject = JPluginHelper::getPlugin($group, 'magebridge'); if (MageBridgeHelper::isJoomla15()) { $db->setQuery('SELECT id,published AS enabled FROM #__plugins WHERE `element`="magebridge" AND `folder`="' . $group . '" LIMIT 1'); } else { $db->setQuery('SELECT extension_id AS id,enabled FROM #__extensions WHERE `type`="plugin" AND `element`="magebridge" AND `folder`="' . $group . '" LIMIT 1'); } $row = $db->loadObject(); if (empty($row)) { $description = JText::_('CHECK_PLUGIN_NOT_INSTALLED'); $this->addResult('extensions', $title, self::CHECK_ERROR, $description); continue; } $url = 'index.php?option=com_plugins'; if ($row->enabled == 0) { $description = JText::sprintf('CHECK_PLUGIN_DISABLED', $url); $this->addResult('extensions', $title, self::CHECK_ERROR, $description); continue; } $this->addResult('extensions', $plugin[2], (bool) $pluginObject, JText::_('CHECK_PLUGIN_ENABLED')); } } return; }
public static function isDemo() { if (MageBridgeHelper::isJoomla15()) { return false; } $user = JFactory::getUser(); if ($user->authorise('com_magebridge.demo_ro', 'com_magebridge') == true && $user->authorise('com_magebridge.demo_rw', 'com_magebridge') == false) { return true; } return false; }
public function postlogin($user_email = null, $user_id = null, $throw_event = true) { // Check if the arguments are set if (empty($user_email) && $user_id > 0 == false) { return false; } // Check if this is the frontend $application = JFactory::getApplication(); if ($application->isSite() == false) { return false; } // Check if this current request is actually a POST-request $post = JRequest::get('post'); if (!empty($post)) { return false; } // Fetch the current user $user = JFactory::getUser(); // Set the changed-flag $changed = false; // Check whether the Joomla! ID is different if ($user_id > 0 && $user->id != $user_id) { $db = JFactory::getDBO(); $query = "SELECT id FROM #__users WHERE `id` = " . (int) $user_id; $db->setQuery($query); $row = $db->loadObject(); if (!empty($row)) { $user->load($user_id); $changed = true; } } // Double-check whether the Joomla! email is different if (!empty($user_email) && $user->email != $user_email) { $user = $this->loadByEmail($user_email); $changed = true; } // Check whether the Joomla! ID is set, but guest is still 1 if ($user->id > 0 && $user->guest == 1) { $changed = true; } // If there is still no valid user, autocreate it // @note: Removed because this makes things overly complex /*if (!empty($user_email) && empty($user->email)) { $data = array( 'name' => $user_email, 'username' => $user_email, 'email' => $user_email, ); $user = $this->create($data); $changed = true; }*/ // Do not fire the event when using the onepage-checkout if (MageBridgeTemplateHelper::isPage('checkout/onepage') == true && MageBridgeTemplateHelper::isPage('checkout/onepage/success') == false) { $throw_event = false; } if ($changed == true) { MageBridgeModelDebug::getInstance()->notice("Postlogin on user = "******"Firing event " . $eventName); JPluginHelper::importPlugin('user'); JFactory::getApplication()->triggerEvent($eventName, array($user, $options)); } else { // Update the user-session if (!empty($user)) { $this->updateSession($user); } } return true; }
/** * Load the parameters * * @access private * @param null * @return JParameter */ private function getParams() { if (!MageBridgeHelper::isJoomla15()) { return $this->params; } else { jimport('joomla.html.parameter'); $plugin = JPluginHelper::getPlugin('content', 'magebridge'); $params = new JParameter($plugin->params); return $params; } }
public function getFieldMagentoGroup($value = null) { require_once JPATH_COMPONENT . '/elements/customergroup.php'; $fake = null; if (MageBridgeHelper::isJoomla15()) { require_once JPATH_COMPONENT . '/elements/customergroup.php'; $fake = null; return JElementCustomerGroup::fetchElement('magento_group', $value, $fake, ''); } else { require_once JPATH_COMPONENT . '/fields/customergroup.php'; $field = new JFormFieldCustomerGroup(); $field->setName('magento_group'); $field->setValue($value); return $field->getHtmlInput(); } }
public static function getMenuItems($only_authorised = true) { static $items = array(); if (empty($items)) { require_once JPATH_SITE . '/includes/application.php'; $component = JComponentHelper::getComponent('com_magebridge'); $menu = JFactory::getApplication()->getMenu('site'); if (!empty($menu)) { if (MageBridgeHelper::isJoomla15()) { $items = $menu->getItems('componentid', $component->id); } else { $items = $menu->getItems('component_id', $component->id); } } // Remove those menu-items that are not authorised if ($only_authorised && !empty($items)) { foreach ($items as $index => $item) { if (MageBridgeHelper::isJoomla15()) { $access = JFactory::getUser()->guest == 0 ? 1 : 0; $authorised = $menu->authorize($item->id, $access); } else { $authorised = $menu->authorise($item->id); } if ($authorised == false) { unset($items[$index]); } } } } return $items; }
<input type="text" name="host" value="<?php echo $this->config['host']['value']; ?> " size="30" /> </td> <td class="status"> </td> <td class="description"> <span><?php echo JText::_('HOST_DESCRIPTION'); ?> </span> </td> </tr> <?php if (MageBridgeHelper::isJoomla15()) { ?> <tr> <td class="key" valign="top"> <?php echo JText::_('API_type'); ?> </td> <td class="value"> <?php echo $this->fields['api_type']; ?> </td> <td class="status"> </td> <td class="description">
echo $row->username; ?> </td> <td> <?php echo $row->email; ?> </td> <td> <?php echo $row->magento_name; ?> </td> <td> <?php echo MageBridgeHelper::isJoomla15() ? $row->usertype : ''; ?> </td> <td> <?php echo $row->password ? '****' : '[empty]'; ?> </td> <td> <?php echo $row->magento_id; ?> </td> <td align="center"> <?php echo $row->id;
protected function getTemplateOptions() { // Get the template-options if (MageBridgeHelper::isJoomla15()) { require_once JPATH_ADMINISTRATOR . '/components/com_templates/helpers/template.php'; $options = TemplatesHelper::parseXMLTemplateFiles(JPATH_SITE . '/templates'); } else { require_once JPATH_ADMINISTRATOR . '/components/com_templates/helpers/templates.php'; $options = TemplatesHelper::getTemplateOptions(0); } // Construct an empty option $option = new stdClass(); if (MageBridgeHelper::isJoomla15()) { $option->directory = null; $option->name = null; } else { $option->value = null; $option->text = null; } array_unshift($options, $option); // Return the options return $options; }
protected function addCss($file, $path) { if (MageBridgeHelper::isJoomla15()) { JHTML::stylesheet($file, $path); } else { JHTML::stylesheet($path . $file); } }