<?php require_once(dirname(__FILE__).'/init.php'); $TemplateName = Interspire_String::filterAlphaNumOnly($_GET['tpl']); $TemplateColor = Interspire_String::filterAlphaNumExtendedOnly($_GET['color']); // (colors have an underscore) $TemplateImageFile = ISC_BASE_PATH . '/templates/'.$TemplateName . '/Previews/'.$TemplateColor; $CacheTemplateImageFile = ISC_BASE_PATH . '/cache/tplthumbs/'.$TemplateName.'_'.$TemplateColor; $maxwidth = '200'; $maxheight = '200'; $expires = 86400; //60 * 60 * 24; header("", true, 200); header("Pragma: public"); header("Cache-control: public,maxage=" . $expires); header("Expires: " . gmdate("r", time() + $expires)); // check cache first if(file_exists($CacheTemplateImageFile)) { if((strtolower(substr($TemplateImageFile,-4)) == ".jpg" || strtolower(substr($TemplateImageFile,-5)) == ".jpeg")) { // jpeg image header("Content-type: image/jpeg"); }elseif(strtolower(substr($TemplateImageFile,-4)) == ".gif" ) { // gif image header("Content-type: image/gif"); } header("Last-Modified: " . gmdate("r", filemtime($CacheTemplateImageFile))); echo file_get_contents($CacheTemplateImageFile);
private function ChangeTemplate() { GetLib('class.file'); $settings = GetClass('ISC_ADMIN_SETTINGS'); $GLOBALS['ISC_NEW_CFG']['template'] = Interspire_String::filterAlphaNumOnly($_REQUEST['template']); $StylePath = ISC_BASE_PATH . "/templates/" .Interspire_String::filterAlphaNumOnly($_REQUEST['template']) .'/Styles'; $color = isc_strtolower(Interspire_String::filterAlphaNumOnly($_REQUEST['color'])); if(file_exists($StylePath."/".$color.".css")) { $GLOBALS['ISC_NEW_CFG']['SiteColor'] = $color; } if(file_exists(ISC_BASE_PATH . '/templates/'. Interspire_String::filterAlphaNumOnly($_REQUEST['template']) . '/config.php')) { include(ISC_BASE_PATH . '/templates/'.Interspire_String::filterAlphaNumOnly($_REQUEST['template']) . '/config.php'); } if($color != '') { $GLOBALS['ISC_NEW_CFG']['SiteColor'] = $color; } $settings->CommitSettings(); // If we're currently using a logo template, then we need to rebuild it if(GetConfig('UsingTemplateLogo') && GetConfig('UsingLogoEditor')) { if(!$this->BuildLogo('[template]', GetConfig('LogoFields'))) { $GLOBALS['ISC_NEW_CFG'] = array( 'UsingTemplateLogo' => 0, 'UsingLogoEditor' => 0, 'LogoType' => 'text' ); $settings->CommitSettings(); } } // Log this action $GLOBALS['ISC_CLASS_LOG']->LogAdminAction(GetConfig('template'), GetConfig('SiteColor')); FlashMessage(sprintf(GetLang('TemplateSelected'), ucfirst($_REQUEST['template'])), MSG_SUCCESS, 'index.php?ToDo=viewTemplates'); }
/** * If the editor is disabled then we'll see if we need to run * nl2br on the text if it doesn't contain any HTML tags */ public function FormatWYSIWYGHTML($HTML) { if(GetConfig('UseWYSIWYG')) { return $HTML; } else { // We need to sanitise all the line feeds first to 'nl' $HTML = Interspire_String::toUnixLineEndings($HTML); // Now we can use nl2br() $HTML = nl2br($HTML); // But we still need to strip out the new lines as nl2br doesn't really 'replace' the new lines, it just inserts <br />before it $HTML = str_replace("\n", "", $HTML); // Fix up new lines and block level elements. $HTML = preg_replace("#(</?(?:html|head|body|div|p|form|table|thead|tbody|tfoot|tr|td|th|ul|ol|li|div|p|blockquote|cite|hr)[^>]*>)\s*<br />#i", "$1", $HTML); $HTML = preg_replace("#( )+(</?(?:html|head|body|div|p|form|table|thead|tbody|tfoot|tr|td|th|ul|ol|li|div|p|blockquote|cite|hr)[^>]*>)#i", "$2", $HTML); return $HTML; } }
/** * Insert/Update the node with the response record * * Method will insert/update the node with the response record. Its made public so order syncing can you it also * * @access public * @param array $responseData The reponse data from QB * @param array $nodeData The optional node data array. If set then update, else insert * @return int The new or updtaed node ID on success, FALSE on error */ public function syncResponseRecord2Store($responseData, $nodeData=false) { static $_cacheHTTPHost = null; /** * Firstly, don't import if this has a customer type as it is a guest checkout customer */ if ($this->accounting->isCustomerGuestCheckout($responseData) || $this->accounting->isCustomerParent($responseData)) { return false; } /** * Set the fillin email address domain name */ if (is_null($_cacheHTTPHost)) { $parts = parse_url(GetConfig("ShopPath")); if (!$parts || !isset($parts["host"]) || trim($parts["host"]) == '') { if (function_exists("apache_getenv")) { $_cacheHTTPHost = @apache_getenv("HTTP_HOST"); } if (!$_cacheHTTPHost) { $_cacheHTTPHost = @$_SERVER["HTTP_HOST"]; } } else { $_cacheHTTPHost = $parts["host"]; } } if (!is_array($responseData)) { $xargs = func_get_args(); throw new QBException("Invalid arguments when syncing customer record from QB", $xargs); } /** * Check to see if this is a customer short name. Only do this if $nodeData is empty */ if (!is_array($nodeData) && $this->accounting->isCustomerShortName($responseData["Name"])) { $customerParts = $this->accounting->qbCustomerShortName2CustomerNameId($responseData["Name"]); if (is_array($customerParts) && isset($customerParts["customerid"]) && isId($customerParts["customerid"])) { $nodeData = $this->entityAPI->get($customerParts["customerid"]); } } /** * We need to fill in the blanks with our node data if we have one */ if (is_array($nodeData)) { $map = array( "custconfirstname" => "FirstName", "custconlastname" => "LastName", "custconemail" => "Email", "custconphone" => "Phone", "custconcompany" => "CompanyName" ); foreach ($map as $nodeKey => $responseKey) { if (!array_key_exists($responseKey, $responseData) || trim($responseData[$responseKey]) == '') { $responseData[$responseKey] = $nodeData[$nodeKey]; } } } /** * Create a fillin for the email address if it is not set */ if (!array_key_exists("Email", $responseData) || trim($responseData["Email"]) == '' || !is_email_address($responseData["Email"])) { $emailAddress = self::emailPreFixFillin . mt_rand(10000, 99999) . "@" . $_cacheHTTPHost; /** * Else check to see if it is unique */ } else if (!$this->checkEmailIsUnique($responseData["Email"], $nodeData)) { $emailAddress = self::emailPreFixFillin . mt_rand(10000, 99999) . "@" . $_cacheHTTPHost; $this->accounting->logWarning("The QuickBooks customer '" . $responseData["FirstName"] . " " . $responseData["LastName"] . "' has a non-unique email address. Changing their email address to " . $emailAddress); /** * Its all cool */ } else { $emailAddress = $responseData["Email"]; } /** * If the first or last name are 25 chanracters then use the original values. This is because QBWC puts a 25 character * limit on those fields and will cut it off if it is exceeded, so best to be safe than sorry */ if (is_array($nodeData)) { if (strlen($responseData["FirstName"]) == 25) { $this->accounting->logWarning("The QuickBooks customer '" . $responseData["FirstName"] . " " . $responseData["LastName"] . "' has had their first name truncated. Defaulting to the original first name of '" . $nodeData["custconfirstname"] . "'"); $responseData["FirstName"] = $nodeData["custconfirstname"]; } if (strlen($responseData["LastName"]) == 25) { $this->accounting->logWarning("The QuickBooks customer '" . $responseData["FirstName"] . " " . $responseData["LastName"] . "' has had their last name truncated. Defaulting to the original last name of '" . $nodeData["custconlastname"] . "'"); $responseData["LastName"] = $nodeData["custconlastname"]; } } $savedata = array( "custconfirstname" => @$responseData["FirstName"], "custconlastname" => @$responseData["LastName"], "custconemail" => $emailAddress, "custconphone" => @$responseData["Phone"], "custconcompany" => @$responseData["CompanyName"] ); /** * The addresses */ $addresses = array(); foreach (array("BillAddress", "ShipAddress") as $addressType) { if (!array_key_exists($addressType, $responseData) || !is_array($responseData[$addressType])) { continue; } if (trim(@$responseData[$addressType]["Addr1"]) !== '') { /** * Firstly lets check to see if we already have this addressd */ $shipId = ''; if (is_array($nodeData) && isset($nodeData["addresses"]) && is_array($nodeData["addresses"])) { foreach ($nodeData["addresses"] as $address) { if (isc_strtolower(trim($address["shipaddress1"])) == isc_strtolower(trim(@$responseData[$addressType]["Addr1"]))) { $shipId = $address["shipid"]; /** * Now fill in the blanks */ $map = array( "shipaddress1" => "Addr1", "shipaddress2" => "Addr2", "shipcity" => "City", "shipstate" => "State", "shipzip" => "PostalCode", "shipcountry" => "Country" ); foreach ($map as $nodeKey => $responseKey) { if (!array_key_exists($responseKey, $responseData[$addressType]) || trim($responseData[$addressType][$responseKey]) == '') { $responseData[$addressType][$responseKey] = $address[$nodeKey]; } } } } } /** * Find the country and state IDs */ $countryId = $this->getCountryId(@$responseData[$addressType]["Country"], $properCountryName); $stateId = ''; if (isId($countryId) && trim(@$responseData[$addressType]["State"]) !== '') { $responseData[$addressType]["Country"] = $properCountryName; $stateId = $this->getStateId($responseData[$addressType]["State"], $countryId, $properStateName); if (!isId($stateId)) { $stateId = ''; } else if (trim($properStateName) !== '') { $responseData[$addressType]["State"] = $properStateName; } } else { $countryId = ''; } $addresses[] = array( "shipid" => $shipId, "shipfirstname" => @$responseData["FirstName"], "shiplastname" => @$responseData["LastName"], "shipcompany" => @$responseData["CompanyName"], "shipaddress1" => @$responseData[$addressType]["Addr1"], "shipaddress2" => @$responseData[$addressType]["Addr2"], "shipcity" => @$responseData[$addressType]["City"], "shipstate" => @$responseData[$addressType]["State"], "shipzip" => @$responseData[$addressType]["PostalCode"], "shipcountry" => @$responseData[$addressType]["Country"], "shipphone" => @$responseData["Phone"], "shipstateid" => $stateId, "shipcountryid" => $countryId ); /** * Set something to each field if it is NULL as the database can't handle NULL values for this schema */ foreach ($addresses[count($addresses)-1] as $addKey => $addVal) { if (is_null($addVal)) { $addresses[count($addresses)-1][$addKey] = ''; } } } } if (!empty($addresses)) { $savedata["addresses"] = $addresses; } $this->accounting->logDebug("The formatted customer data from QB", array("Savedata" => $savedata, "Response" => $responseData)); /** * Got all the info, now create the database record */ $customerId = false; if (is_array($nodeData) && array_key_exists("customerid", $nodeData) && isId($nodeData["customerid"])) { $savedata["customerid"] = $nodeData["customerid"]; if ($this->entityAPI->edit($savedata, false, true) !== false) { $customerId = $nodeData["customerid"]; } } else { $savedata["password"] = Interspire_String::generateReadablePassword(); $customerId = $this->entityAPI->add($savedata); } if (!isId($customerId)) { throw new QBException("Cannot save customer record with data from QB", array("SaveData" => $savedata, "NodeData" => $nodeData, "DB" => $GLOBALS["ISC_CLASS_DB"]->GetError())); } return $customerId; }
/** * Downloads image from picnik (or can be used for any url, really) and stores it at a file named $destination -- primarily a wrapper for PostToRemoteFileAndGetResponse with built-in file writing and error handling * * @param string $url * @param string $destination (optional) * @return string|bool Returns the filename the image was saved to, or false if anything went wrong */ public function downloadToFile($url, $destination = false, &$errorType = null) { $result = PostToRemoteFileAndGetResponse($url); if (!$destination) { // generate a random name for our downloaded file and store it in cache dir while (true) { // we can name it .tmp because the extension will be corrected after the image type is detected $destination = ISC_CACHE_DIRECTORY . 'picnikimage_' . Interspire_String::generateRandomString(16) . '.tmp'; if (!file_exists($destination)) { break; } } } $fh = fopen($destination, 'wb'); if ($fh) { if (!fwrite($fh, $result)) { fclose($fh); $this->log->LogSystemError('general', 'Failed to write downloaded Picnik image to local file'); $errorType = 1; return false; } fclose($fh); isc_chmod($destination, ISC_WRITEABLE_FILE_PERM); // set the chmod just incase this was a new file } else { $this->log->LogSystemError('general', 'Failed to open local file for saving downloaded Picnik image'); $errorType = 2; return false; } return $destination; }
/** * Fetch the next record from the open CSV file */ public function FetchNextRecord($add_original=false) { // Reached the end of the file if(!$this->FileFP) { return false; } // We've reached the max iterations we'll be doing per page if($this->LastRecord == $this->MaxRecords && $this->MaxRecords > 0) { return false; } $record = @fgetcsv($this->FileFP, 100000, $this->FieldSeparator, $this->FieldEnclosure); if (is_array($record) && GetConfig('CharacterSet') == 'UTF-8' && function_exists('utf8_encode')) { // ISC-583 // if the store is running as utf8, try our best to ensure records read by fgetcsv are utf8 encoded because // database import routines are going to assume stuff is utf8 encoded // note that fgetcsv may have already broken the string beyond repair in regards to the original characters // (since fgetcsv relies on the system locale) but at least we can ensure mysql will not complain when it // is eventually sent as a query foreach ($record as $index => $field) { if (Interspire_String::isUtf8($field)) { continue; } $record[$index] = utf8_encode($field); } } $new_record = $record; if(is_array($record) && isset($this->FieldList)) { $new_record = array(); foreach($this->FieldList as $field => $index) { /** * Custom field check */ if ($field == 'custom' && is_array($index)) { foreach ($index as $fieldId => $fieldIndex) { if (array_key_exists($fieldIndex, $record)) { if (!array_key_exists('custom', $new_record) || !is_array($new_record['custom'])) { $new_record['custom'] = array(); } $new_record['custom'][$fieldId] = trim($record[$fieldIndex]); } } /** * Else normal field */ } else { if (!is_scalar($index)) { // this shouldn't be happening here and is causing a problem with array_key_exists below which only takes scalar values in argument 1 -- I can't trace it back at the moment, only add the check to skip it -GE continue; } if (!array_key_exists($index, $record)) { continue; } $new_record[$field] = trim($record[$index]); } } } if(is_array($new_record) && isset($add_original) && $add_original == true) { $new_record['original_record'] = $record; } // Reached the end of the file if(@feof($this->FileFP) || $record === false) { @fclose($this->FileFP); } ++$this->LastRecord; return $new_record; }
/** * Create a salted customer hash string * * Function will create a salted hash string used for customers * * @access public * @param string $hash The unsalted hash string * @param int $customerId The customer ID * @return string The salted customer hash string on success, FALSE if $hash or $customerID is invalid/empty */ public function generateCustomerHash($hash, $customerId) { if ($hash == '' || !isId($customerId)) { return false; } $salt = 'CustomerID:' . $customerId; return Interspire_String::generateSaltedHash($hash, $salt); }
/** * Generate a random string of characters to a specific length based on the specified selection of characters * * @param int $length * @param string $selection */ public static function randomString($length, $selection = '0123456789abcdefghijklmnopqrstuvwxyz') { return Interspire_String::generateRandomString($length, $selection); }
public function update_simplepay_checkout_module() { if (!ModuleIsConfigured('checkout_paysimple')) { return true; } GetModuleById('checkout', $module, 'checkout_paysimple'); // Check to see if the module hasn't already been updated $value = $module->GetValue('merchantkey'); if (!is_null($value) && trim($value) !== '') { return true; } // OK, it hasn't been updated yet, so do so $keyFile = ISC_BASE_PATH . "/modules/checkout/paysimple/lib/keyHalf.txt"; if (!file_exists($keyFile)) { return true; } if (!is_readable($keyFile)) { $this->SetError('Unable to read the key file ' . GetConfig('AppPath') . '/modules/checkout/paysimple/lib/keyHalf.txt. Please CHMOD it to 646 or 666.'); return false; } $newKey = @file_get_contents(ISC_BASE_PATH . "/modules/checkout/paysimple/lib/keyHalf.txt"); $newKey = trim($newKey); if ($newKey == '') { return true; } // Make sure you get the 'static' part $newKey = Interspire_String::toUnixLineEndings($newKey); $newKey = explode("\n", $newKey); $newKey = $newKey[0]; $module->setMerchantKey($newKey); return true; }