/** * Main Function to display Product Snapshots * * @param mosContent $row * @param JParams $params * @param int $page * @param boolean $published * @return boolean */ function handleProductSnapShot(&$row, &$params, $page = 0, $published = true) { global $mosConfig_absolute_path, $mosConfig_live_site, $database; // load default parameters if (vmIsJoomla('1.5', '>=')) { $db = JFactory::getDBO(); $plugin =& JPluginHelper::getPlugin('content', 'vmproductsnapshots'); $parameters = $plugin->params; } else { $query = "SELECT id,params FROM #__mambots WHERE element = 'vmproductsnapshots' AND folder = 'content'"; $database->setQuery($query); $mambot = $database->loadResult(); $parameters = $mambot->params; } $bot_params = new vmParameters($parameters); $param_defaults = array('id' => '0', 'enabled' => '1', 'showname' => 'y', 'showimage' => 'y', 'showdesc' => 'n', 'showprice' => 'y', 'quantity' => '1', 'showaddtocart' => 'y', 'displaylist' => 'v', 'displayeach' => 'h', 'width' => '100', 'border' => '0', 'style' => '', 'align' => ''); // get settings from admin mambot parameters foreach ($param_defaults as $key => $value) { $param_defaults[$key] = $bot_params->get($key, $value); } $enabled = $param_defaults['enabled']; if (!$published || !$enabled) { $row->text = preg_replace("/{product_snapshot:.+?}/", '', $row->text); return true; } $vm_productsnap_entrytext = $row->text; $vm_productsnap_matches = array(); if (preg_match_all("/{product_snapshot:.+?}/", $vm_productsnap_entrytext, $vm_productsnap_matches, PREG_PATTERN_ORDER) > 0) { foreach ($vm_productsnap_matches[0] as $vm_productsnap_match) { $vm_productsnap_match = str_replace("{product_snapshot:", "", $vm_productsnap_match); $vm_productsnap_match = str_replace("}", "", $vm_productsnap_match); // Get Bot Parameters $vm_productsnap_params = get_prodsnap_params($vm_productsnap_match, $param_defaults); // Get the html $showsnapshot = return_snapshot($vm_productsnap_params); $vm_productsnap_entrytext = preg_replace("/{product_snapshot:.+?}/", $showsnapshot, $vm_productsnap_entrytext, 1); } $row->text = $vm_productsnap_entrytext; } return; }
/** * Function to add a new Shopper into the Shop and Joomla * * @param array $d * @return boolean */ function add(&$d) { global $my, $auth, $mainframe, $mosConfig_absolute_path, $sess, $VM_LANG, $vmLogger, $database, $mosConfig_useractivation; $ps_vendor_id = $_SESSION["ps_vendor_id"]; $hash_secret = "VirtueMartIsCool"; $db = new ps_DB(); $timestamp = time(); if (!$this->validate_add($d)) { return False; } if (empty($my->id)) { $_POST['name'] = vmGet($d, 'first_name', 'First Name') . " " . vmGet($d, 'last_name', 'Last Name'); if (VM_REGISTRATION_TYPE == 'SILENT_REGISTRATION' || VM_REGISTRATION_TYPE == 'NO_REGISTRATION' || VM_REGISTRATION_TYPE == 'OPTIONAL_REGISTRATION' && empty($d['register_account'])) { // Silent Registration, Optional Registration with no account wanted and No Registration // means we need to create a hidden user if (vmIsJoomla('1.5')) { $username_length = 100; } else { $username_length = 25; } $silent_username = substr(str_replace('-', '_', vmGet($d, 'email')), 0, $username_length); $db->query('SELECT username FROM `#__users` WHERE username=\'' . $silent_username . '\''); $i = 0; while ($db->next_record()) { $silent_username = substr_replace($silent_username, $i, strlen($silent_username) - 1); $db->query('SELECT username FROM `#__users` WHERE username=\'' . $silent_username . '\''); $i++; } $_POST['username'] = $d['username'] = $silent_username; $_POST['password'] = $d['password'] = vmGenRandomPassword(); $_POST['password2'] = $_POST['password']; } if (VM_REGISTRATION_TYPE == 'NO_REGISTRATION' || VM_REGISTRATION_TYPE == 'OPTIONAL_REGISTRATION' && empty($d['register_account'])) { // If no user shall be registered into the global user table, we just add the registration info into the vm_user_info table // Make sure that "dummy" entries for non-existing Joomla! users won't ever have the same user_id as a future Joomla! user $db->query("SELECT MIN(user_id)-1 as uid FROM `#__{vm}_user_info`"); $db->next_record(); // Don't allow a user id of zero $uid = $db->f('uid') == 0 ? -1 : $db->f('uid'); } else { // Process the CMS registration if (vmIsJoomla('1.5')) { if (!$this->register_save()) { return false; } } else { if (!$this->saveRegistration()) { return false; } } $db->query("SELECT id FROM #__users WHERE username='******'username'] . "'"); $db->next_record(); $uid = $db->f('id'); } } else { $uid = $my->id; $d['email'] = $_POST['email'] = $my->email; $d['username'] = $_POST['username'] = $my->username; } // Prevent empty USER ID if (empty($uid)) { $vmLogger->crit("Failed to retrieve a valid USER ID when attempting to add a new user"); return false; } if (!empty($auth['user_id'])) { $db->query('SELECT user_id FROM #__{vm}_user_info WHERE user_id=' . $auth['user_id']); $db->next_record(); if ($db->f('user_id')) { return $this->update($d); } } // Get all fields which where shown to the user $userFields = ps_userfield::getUserFields('registration', false, '', true); $skipFields = ps_userfield::getSkipFields(); // Insert billto; // The first 7 fields are FIX and not built dynamically $fields = array('user_info_id' => md5(uniqid($hash_secret)), 'user_id' => $uid, 'address_type' => 'BT', 'address_type_name' => '-default-', 'cdate' => $timestamp, 'mdate' => $timestamp, 'perms' => 'shopper'); foreach ($userFields as $userField) { if (!in_array($userField->name, $skipFields)) { $fields[$userField->name] = ps_userfield::prepareFieldDataSave($userField->type, $userField->name, vmGet($d, $userField->name, strtoupper($userField->name))); // Catch a newsletter registration! if (stristr($userField->params, 'newsletter')) { if (!empty($d[$userField->name])) { require_once CLASSPATH . 'parameters.class.php'; $subscribeTo = new vmParameters($userField->params); $vmLogger->debug('Adding the user to the Newsletter.'); } } } } $fields['user_email'] = $fields['email']; unset($fields['email']); $db->buildQuery('INSERT', '#__{vm}_user_info', $fields); // Run the query now! $db->query(); // Insert vendor relationship $q = "INSERT INTO #__{vm}_auth_user_vendor (user_id,vendor_id)"; $q .= " VALUES "; $q .= "('" . $uid . "','"; $q .= $ps_vendor_id . "') "; $db->query($q); $d['shopper_group_id'] = ''; // Get the ID of the shopper group for this customer if ($d['isValidVATID']) { if (trim($d['__euvatid_field']->params) != '') { $shopper_group = new vmParameters($d['__euvatid_field']->params); $d['shopper_group_id'] = $shopper_group->get('shopper_group_id'); } } if (empty($d['shopper_group_id'])) { $q = "SELECT shopper_group_id from #__{vm}_shopper_group WHERE "; $q .= "`default`='1' "; $db->query($q); if (!$db->num_rows()) { // take the first in the table $q = "SELECT shopper_group_id from #__{vm}_shopper_group"; $db->query($q); } $db->next_record(); $d['shopper_group_id'] = $db->f("shopper_group_id"); } $customer_nr = uniqid(rand()); // Insert Shopper -ShopperGroup - Relationship $q = "INSERT INTO #__{vm}_shopper_vendor_xref "; $q .= "(user_id,vendor_id,shopper_group_id,customer_number) "; $q .= "VALUES ('{$uid}', '{$ps_vendor_id}','" . $d['shopper_group_id'] . "', '{$customer_nr}')"; $db->query($q); // Process the Newsletter subscription if (!empty($subscribeTo) && strtolower(get_class($subscribeTo)) == 'vmparameters') { switch ($subscribeTo->get('newsletter', 'letterman')) { // TODO: case 'ccnewsletter': $db->query("INSERT INTO `#__ccnewsletter_subscribers` ( `name`, `email`, `plainText`, `enabled`, `sdate`) \r\n\t\t\t\t\t\t\tVALUES('" . $d['first_name'] . " " . $d['last_name'] . "','" . $d['email'] . "', '0', '1', NOW())"); // case 'anjel': // case 'anjel': case 'letterman': default: if (file_exists($mosConfig_absolute_path . '/components/com_letterman/letterman.php')) { $db->query("INSERT INTO `#__letterman_subscribers` (`user_id`, `subscriber_name`, `subscriber_email`, `confirmed`, `subscribe_date`)\r\n\t\t\t\t\t\t\t\t\t\tVALUES('{$uid}','" . $d['first_name'] . " " . $d['last_name'] . "','" . $d['email'] . "', '1', NOW())"); } } } if (VM_REGISTRATION_TYPE == 'NO_REGISTRATION' || VM_REGISTRATION_TYPE == 'OPTIONAL_REGISTRATION' && empty($d['register_account'])) { $auth['user_id'] = $uid; $auth['username'] = $d['email']; $_SESSION['auth'] = $auth; } elseif (!$my->id && $mosConfig_useractivation == '0') { // HANDLE LOGIN if (vmIsJoomla('1.5')) { // Username and password must be passed in an array $credentials = array('username' => vmGet($d, 'username'), 'password' => vmGet($d, 'password')); $mainframe->login($credentials); } elseif (class_exists('mambocore') || vmIsJoomla('1.0.13', '>=', false)) { // Login for Mambo 4.6.x and Joomla >= 1.0.13 $mainframe->login($d['username'], $d['password']); } else { // Login for Joomla < 1.0.13 (and Mambo 4.5.2.3) $mainframe->login($d['username'], md5($d['password'])); } // Redirect to the Checkout Page if the cart is not empty if (!empty($_SESSION['cart']['idx'])) { $redirect_to_page = 'checkout.index'; } else { $redirect_to_page = HOMEPAGE; } vmRedirect($sess->url('index.php?page=' . $redirect_to_page, false, false), $VM_LANG->_('REG_COMPLETE')); } if (!empty($my->id) || !empty($auth['user_id'])) { vmRedirect($sess->url('index.php?page=checkout.index', false, false)); } else { $GLOBALS['page'] = 'shop.cart'; $msg = strip_tags($VM_LANG->_('REG_COMPLETE_ACTIVATE', false)); $vmLogger->info($msg); } return true; }