Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

stevel

Pioneers
  • Posts

    2,821
  • Joined

  • Last visited

Everything posted by stevel

  1. A couple of changes to my PDO-sqlite code above. First, remove self::$db = null; in the store function. Second, in file main/usu5.php, function extractCacheData. In the case for sqlite, change: $row = $result->fetch(); to if (is_object($result)) $row = $result->fetch(); I would recommend this edit no matter what. I am using the 1.1 version of the code, have not looked for anything newer.
  2. Robert, the following seems to work as far as using PDO. Pretty simple, really - the part where the database is created and opened is the major change, most everything else can stay as-is.. The one part I am a bit unsure about is the use of the PDO::quote function as a replacement for sqlte_escape_string. (I may not be using the latest version of your contrib.) This is a replacement for includes/cache_system/sqlite.php <?php /** * * ULTIMATE Seo Urls 5 PRO ( version 1.1 ) * * * @package USU5_PRO * @[member='licensed2kill'] http://www.opensource.org/licenses/gpl-2.0.php GNU Public License * @[member='Link'] http://www.fwrmedia.co.uk * @[member='copyright'] Copyright 2008-2009 FWR Media * @[member='copyright'] Portions Copyright 2005 ( rewrite uri concept ) Bobby Easland * @[member='author'] Robert Fisher, FWR Media, http://www.fwrmedia.co.uk * @lastdev $Author:: Rob $: Author of last commit * @lastmod $Date:: 2011-03-21 12:48:04 +0000 (Mon, 21 Mar 2011) $: Date of last commit * @version $Rev:: 206 $: Revision of last commit * @Id $Id:: sqlite.php 206 2011-03-21 12:48:04Z Rob $: Full Details */ /** * Cache system using a SQLite database * * @package USU5_PRO */ final class Sqlite_Cache_Module implements iCache_System { private static $_singleton = null; private static $sqlite_db_file = null; private static $cache_name; private static $cache_on; public static $db; public $extract_query = "SELECT * FROM usu_cache WHERE cache_name = ':cache_name'"; private $insert_query = "INSERT INTO usu_cache (cache_name, cache_data, cache_date) VALUES (':cache_name', ':cache_data', ':cache_date')"; private $insert = false; /** * Class constructor * @[member='access'] private */ private function __construct() { } // end constructor /** * Returns a singleton instance of the class * * Sets the cache name and checks that the cache directory is writeable * @uses defined() * @uses substr() * @uses md5() * @uses is_readable() * @uses trigger_error() * * @[member='access'] public * @throws - triggers an error of type E_USER_WARNING if a new database cannot be created * @return Sqlite_Cache_Module */ public static function i() { if ( !self::$_singleton instanceof Sqlite_Cache_Module ) { if ( Usu_Main::i()->getVar( 'page_modules', substr( Usu_Main::i()->getVar( 'filename' ), 0, -4 ) ) instanceof aPage_Modules ) { self::$cache_on = ( defined( 'USU5_CACHE_ON' ) && ( USU5_CACHE_ON == 'true' ) ) ? true : false; self::$cache_name = md5( Usu_Main::i()->getVar( 'page_modules', substr( Usu_Main::i() ->getVar( 'filename' ), 0, -4 ) ) ->buildCacheName() ); Usu_Main::i()->setVar( 'cache_name', self::$cache_name ); } else { // No module so we set the cache name as the language id plus the called file self::$cache_name = Usu_Main::i()->getVar( 'languages_id' ) . '_' . substr( Usu_Main::i()->getVar( 'filename' ), 0, -4 ); } self::$sqlite_db_file = Usu_Main::i()->getVar( 'cache_system_path' ) . 'sqlite/usu_cache.db'; self::createDatabase(); self::$_singleton = new self; } return self::$_singleton; } // end method /** * Returns a limited singleton instance of the class specifically for admin * * Allows admin to access a limited version of the class in order to truncate the database * * @[member='access'] public * @return Sqlite_Cache_Module */ public static function admini() { if ( !self::$_singleton instanceof Sqlite_Cache_Module ) { self::$sqlite_db_file = realpath( dirname( __FILE__ ) ) . '/sqlite/usu_cache.db'; self::createDatabase(); self::$_singleton = new self; } return self::$_singleton; } /** * Create the SQLite database if it doesn't already exist * * @uses is_readable() * @uses trigger_error() * * @[member='access'] protected * @throws - triggers an error of type E_USER_WARNING if a new database cannot be created * @return void */ protected static function createDatabase() { if ( !is_readable( self::$sqlite_db_file ) ) { $db_file_handle = @fopen(self::$sqlite_db_file,'a'); if (!$db_file_handle){ tep_db_error ('USU DB Create', 0, $e->getMessage()); } else { fclose($db_file_handle); } } try { self::$db = new PDO('sqlite:' . self::$sqlite_db_file,'','',array(PDO::ATTR_PERSISTENT => true)); } catch (PDOException $e) { tep_db_error('USU DB Open',0,$e->getMessage()); die(); } self::createTables(); } /** * Stores the current cache on the destruction of the Usu_Main class * * @see Usu_Main::__destruct() * @uses serialize() * @uses base64_encode() * @uses gzdeflate() * @uses str_replace() * @uses date() * @uses sqlite_escape_string() * @param array $registry_vars - array of data to cache * * @[member='access'] public * @return void */ public function store( array $registry_vars = array() ) { if ( false !== self::$cache_on ) { if ( false !== $this->insert ) { $data = serialize( $registry_vars ); // Serialize the registry of data $rawdata = base64_encode( gzdeflate( $data ) ); // encode and deflate $targets = array( ':cache_name', ':cache_data', ':cache_date' ); $replacements = array( self::$db->quote( self::$cache_name ), self::$db->quote( $rawdata ), date( "Y-m-d H:i:s" ) ); $query = str_replace( $targets, $replacements, $this->insert_query ); self::$db->query( $query ); self::$db = null; } } } /** * Retrieve the cached data * * If $insert becomes bool true then we insert data when storing, bool false we don't save as the cache already exists * * @see Usu_Main::extractCacheData() * * @[member='access'] public * @return void */ public function retrieve() { if ( false !== self::$cache_on ) { $this->insert = Usu_Main::i()->extractCacheData( self::$cache_name, 'sqlite', $this ); } } /** * Cache garbage clearance * * @uses file_exists() * @uses unlink() * @param bool $file_info * * @[member='access'] public * @return void */ public function gc( $file_info = false ) { if ( file_exists( self::$sqlite_db_file ) ) { self::$db->query( 'DELETE FROM usu_cache' ); self::$db->query( 'VACUUM usu_cache' ); } } /** * Retrieve an instance of SQLiteDatabase * * @[member='access'] public * @return SQLiteDatabase */ public function getDb() { return self::$db; } /** * Create the initial table and fileds for SQLiteDatabase * @[member='access'] private */ private static function createTables() { $create_query = " CREATE TABLE usu_cache ( cache_name, cache_data, cache_date ); CREATE UNIQUE INDEX idx_cache_name ON usu_cache( cache_name );"; self::$db->query( $create_query ); } } // end class
  3. I have been happily using this contribution for a year or so. For various reasons, I am forced to switch to PHP 5.4 from the 5.2 I am currently using. On my host, SQLite 2 is provided in PHP 5.2, but in 5.4 they supply only SQLite 3 with the PDO interface. I searched this topic but so far, I have found only other questions about using PDO and no answers. Has anyone successfully modified the contrib to use SQLite through PDO? If so, how?
  4. I will comment that if your knowledge of PHP is "very limited", then you will encounter no end of frustration maintaining an osCommerce store. I encourage you to learn enough PHP to understand the code.
  5. angel, in my version (1.4), this code fetches the state or zone_id value from the submitted form: if (ACCOUNT_STATE == 'true') { $state = tep_db_prepare_input($HTTP_POST_VARS['state']); if (isset($HTTP_POST_VARS['zone_id'])) { $zone_id = tep_db_prepare_input($HTTP_POST_VARS['zone_id']); } else { $zone_id = -1; // Country-State Selector } } I have not looked at the AJAX version to see what it does.
  6. You'll have to debug the PHP - perhaps the form is not being submitted correctly or the code path when the form is submitted has errors. I generally start out by inserting a "var_dump($_POST);" in the form action code to see what was submitted (this will block the later redirect but that's ok.) I then add various echo or var_dump commands through the code until I understand what went wrong.
  7. What you need to do is change the address format for the US format (which if I recall is format 1 by default.) Unfortunately there is no interface in osC to actually edit these - all you can do is select among the formats defined. The default format spells out the zone name but you want the zone code instead. I have customized my shops and am away from my sources so what I am about to suggest may not work right for you. Open your database in PHPMyAdmin or whatever you use. Select table address_format. Insert a new row. The address_format_id should be the next value, probably 2. For address_format enter: $firstname $lastname$cr$streets$cr$city, $statezone $postcode and for address_summary, enter: US Once you have finished adding the record, go into your osC admin, and select Locations/Taxes > Countries. Find the entry for United Stated and edit it. Change the Address Format to 2 (or whatever the new format ID was in the step above.) Now you will have to enter a new order and see if the address appears correct, oh and you may have to go back in and create a new address book entry as it will have the old code. What I don't remember is if the standard osC code defines $statezone in the tep_format_address function in includes/general.php. I have customized mine to allow for more flexibility as many countries need specialized formats that the default code doesn't support. I have always had in the back of my head the notion of writing an address format contribution with CORRECT formats for all the countries, but it is daunting work to research each country and get the right format. I've done it for maybe 15 countries so far - there are ten times as many. All that should be needed is for variable $statezone to be defined in the function to be the zone code. If it is not there you should be able to figure out how to add it. Let me know if you run into trouble and I'll help you Sunday or later.
  8. I will defer to Robert on this - and will test it on my sites. It may be that search engines are fine - they will simply get the "cookie usage" page if they try to follow a link to a page that requires a session. Of course, you should have such pages listed in robots.txt. On my site, I do not display such links if there is no session.
  9. You don't want to fix it. This is a fundamental way that osCommerce works. You can set the standard configuration option "Force cookie usage" but that will mean that search engines can't see your site. You should have "Prevent Spider Sessions" enabled and keep the includes/spiders.txt file up to date (see my contrib below) to ensure that search engines don't index URLs with the osCsid value.
  10. If you correctly use tep_href_link to form URLs for links, then they should always have the SEO style. You'd have to look at the PHP code to diagnose that - looking at the web site wouldn't help.
  11. Oh, you're using a template system. Well, you'll have to look at the FILENAME_PRODUCT_LISTING_FEATURED file in the includes/modules directory to see what, if any, code you need to change. In general with templates, all the standard add-on instructions go out the window and you have to hunt down where the code is.
  12. The instructions also say that you may not have that code. It is also possible that you have a variant of it. The default 2.2 store uses a simple link for the Buy Now button. Many store owners replace that with a form so that search engines don't follow it. Perhaps you have not done this or have removed the Buy Now button. If you do have a Buy Now button, show us the code for it and we can advise further.
  13. I don't know how you tell customers about shipping now, but most stores compute and display shipping charges on the checkout_shipping page. If you have text on your site that says "Free Shipping!" you need to qualify that as to where you will do free shipping. I don't think the country selection is the place to do it.
  14. That's what I get for trying to remember. Sorry to have led you astray. On the pages where you are using this, there will be code like this: while ($zones_values = tep_db_fetch_array($zones_query)) { $zones_array[] = array('id' => $zones_values['zone_id'], 'text' => $zones_values['zone_name'] . ' (' . $zones_values['zone_code'] . ')'); } At least in this version, this gives you lines such as: New Hampshire (NH) If you just want NH there, then make this: while ($zones_values = tep_db_fetch_array($zones_query)) { $zones_array[] = array('id' => $zones_values['zone_id'], 'text' => $zones_values['zone_code']); } You will have to repeat this in each file where there is a zone dropdown. Be careful as some of them may use different variable names.
  15. No, not those routines. Maybe the routine I am thinking of is in html_output.php. It is the one that creates a dropdown list of zone names. You would replace the call to tep_get_zone_name with one to tep_get_zone_code.
  16. No - I would change the routine in includes/functions/general.php that creates the zones dropdown list (I don't have the code handy so I forget exactly what it is called) to insert the zone code rather than name.
  17. Robert, I just wanted to let you know that the contrib is working fine for me now - thanks to your pointing out my error. Very slick, and much easier to add than Chemo's old script. May I suggest that in the instructions or maybe first post here you add a link to the googlefeeder contrib with your changes? That contrib has been updated since then without your edits. And speaking of that - having to change to wget means that the script is "open" to the web. Previously, I had the feed scripts under admin, which was password-protected. I didn't like the idea of putting my admin password in the crontab entry, so I created a separate folder for the feed scripts with their own password and specified that in the wget command.
  18. DOH! I see what I did wrong. I saw the include of DIR_WS_CLASSES.'languages.php' and thought that's where it went. Makes more sense now - thanks.
  19. Robert, Here is the code in application_top.php // set the language if (!tep_session_is_registered('language') || isset($_GET['language'])) { if (!tep_session_is_registered('language')) { tep_session_register('language'); tep_session_register('languages_id'); } /** * ULTIMATE Seo Urls 5 PRO by FWR Media */ Usu_Main::i()->setVar( 'languages_id', $languages_id ) ->setVar( 'request_type', $request_type ) ->setVar( 'session_started', $session_started ) ->setVar( 'sid', $SID ) ->setVar( 'language', $language ) ->setVar( 'filename', $PHP_SELF ) ->initiate( ( isset( $lng ) && ( $lng instanceof language ) ) ? $lng : array(), $languages_id, $language ); The call to establish USU is done only if 'language' is not registered or if there is a GET parameter 'language' (when someone changes the language). If the store owner is already looking at the site when this code is added, they will already have a session going with 'language' set. Therefore, this call will not be made as long as their session remains active. Perhaps I don't fully understand the way PHP classes work here, but I don't see another path that would call initiate.
  20. Robert, I have installed this fine-looking add-on (to a 2.2 site without previous SEO code) and, while I don't have it working quite yet, I have discovered two installation guide issues and a feature request. (I'm confident I can figure out the problems I'm having - if not, I'll ask here.) 1. The order of the eight edits is very nice, with each update in order so that the store isn't broken if you do them one at a time. Almost. Edits 7 and 8 should be in the other order - so that admin/includes/functions/general.php is updated to add the function before admin/categories.php is updated to use it. 2. A few pages back a user wrote that the add-on "suddenly started working", and you said that the user must have done something. Well, yes and no. The call to activate the contrib in application_top.php is made only if the "language" session variable is not registered. If the user had a browser session open and had been in the store recently, the language is established in the session so the SEO code is skipped until someone, who doesn't already have an active session, comes in. This might take a while in some stores. (It did for me, anyway.) The instructions should suggest closing all browser windows and then opening again to go to the site. This will clear the session cookie and establish a new session, triggering the activation. Now the feature request - I would strongly suggest that the initial mode NOT be to have SEO URLs enabled, requiring the webmaster to turn them on. This would also give them the chance to look at the options and adjust if needed. In my case, I was getting 500 server errors (for reasons yet to be determined) until I turned the option off. I'd also like to see some sort of "test" mode that is enabled only for the store owner, again so they can try it out and perhaps make adjustments. I will hack this in myself so I can debug the problems I'm having, but I think it would be very friendly. I envision a session variable that can be set with a GET parameter or perhaps visiting a special page. You may have other thoughts.
  21. You need to know what "user agent" string the spider supplies when making the http request. It would, ideally, have some part of it that can be used to identify it as a bot. If the UA string includes "bot/" or "/bot" that would do the trick. If it doesn't fit the pattern of any of the existing strings, then figure out what would identify it (without a false positive on a legitimate browser) and add the string to the spiders.txt file. If your search engine supplies a generic UA or one that matches that of a browser, you can't.
  22. Sorry, I know this is late, but this forum keeps dropping my subscriptions. Some web hosts simply do not allow a script to change file protections. I do not know what "forbiden.php" does on your store.
  23. Sorry, no idea. I have not looked at 2.3 other than to realize it was more work than I was willing to go into for my heavily customized 2.2 stores.
  24. My advice is to use version 1.4.1. I know a lot of people are using the Ajax version but it also seems to give people the most trouble.
  25. A security risk? No more than any other PC. The thing to look at is if this "user" went around your site adding items to a cart. How many pages did it visit at this time? Do you see a session ID in all the URLs or maybe just one or two? Remember that the purpose of spiders.txt is NOT to prevent bots from visiting your site - it's to keep session IDs out of search engine indexes and to prevent them from doing things that require a session.
×
×
  • Create New...