My Favorites Plugin not Compatible with IE ?

9 posts by 3 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: June 18, 2014   (RSS)

By gregThomas - May 16, 2014

Hi Tom,

Thanks for bringing this to our attention. I was able to replicate the issue on our test server, and we've come up with a solution that will be implemented into the next release. 

The problem is caused by IE's overzealous content caching. The first time you press the button it carries out the AJAX request, the second time you press the button it doesn't carry out the request because it's cached the content from the previous request, and so doesn't contact the server. 

The easiest solution to stop IE doing this is modify the websiteFavourites.js file, which you can find in the cmsAdmin/plugins/websiteFavourites directory. Then make the following changes highlighted in green:

//
function wsf_add(tableOrTag, recordNum, reload) {
  var $           = jQuery; // see: http://docs.jquery.com/Core/jQuery.noConflict
  var addClass    = _wsf_getClassFor(tableOrTag, recordNum, 'add');
  var removeClass = _wsf_getClassFor(tableOrTag, recordNum, 'remove');

  $.ajax({
    cache: false,
    url: '?_wsf_action=add&tableOrTag=' +escape(tableOrTag)+ '&recordNum=' + escape(recordNum),
    success: function(errorMessage){
      if (errorMessage)   { return alert("Error: " + errorMessage); }
      if (reload == true) { return window.location.reload(); }

      $(addClass).hide();
      $(removeClass).show();
      return true;
    }
  });

}

//
function wsf_remove(tableOrTag, recordNum, reload) {
  var $           = jQuery; // see: http://docs.jquery.com/Core/jQuery.noConflict
  var addClass    = _wsf_getClassFor(tableOrTag, recordNum, 'add');
  var removeClass = _wsf_getClassFor(tableOrTag, recordNum, 'remove');

  //
  $.ajax({
    cache: false,
    url: '?_wsf_action=remove&tableOrTag=' +escape(tableOrTag)+ '&recordNum=' + escape(recordNum),
    success: function(errorMessage){
      if (errorMessage)   { return alert("Error: " + errorMessage); }
      if (reload == true) { return window.location.reload(); }

      $(addClass).show();
      $(removeClass).hide();
      return true;
    }
  });
}

// var className = _wsf_getClassFor(tableOrTag, recordNum, action);
function _wsf_getClassFor(tableOrTag, recordNum, action) {
  var className = ".wsf_" + action + '_' + tableOrTag + '_' + recordNum;
  return className;

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Tom - May 17, 2014

That's perfect.

Thanks a lot Greg.

However, one more problem.

I intend to list the newly added favorite to be list first in the my favorite listing viewer.

I have add a new column in the favorite table named num with auto increment and added orderBy num DESC.

But Seems not work

Any idea?

// load matching records
list($favoriteRecords, $favoriteMetaData) = getRecords(array(
'tableName' => 'listings', // update this with your table or tag name
'perPage' => '10',
'where' => " num IN ($favoriteNumsQuery) ",
'loadCreatedBy' => false,
'allowSearch' => false,
'orderBy' => "num DESC",
));

Please advice.

Thanks a lot

By gregThomas - May 19, 2014

Hi Tom,

From your description it sounds like your adding this field directly to the MySQL table/phpMyAdmin as opposed to through CMS Builder? I attempted to manually add a new column to the section via the CMS, but found it wasn't possible. But I have found a solution to be able to sort the list by the date they were added.

First you'll need to add a createdDate column to the _website_favorites section, as it isn't possible to do this via the CMS interface, you'll have to manually add the field to the schema, you can do this by opening /cmsAdmin/data/schema/_website_favorites.ini.php then add the following column:

<?php /* This is a PHP data file */ if (!@$LOADSTRUCT) { die("This is not a program file."); }
return array (
  '_disableAdd' => 1,
  '_disableErase' => 1,
  '_disableModify' => 1,
  'listPageFields' => 'createdBy.username, tableOrTag, recordNum',
  'listPageOrder' => '',
  'listPageSearchFields' => '',
  'menuHidden' => 1,
  'menuName' => 'Website Favorites',
  'menuOrder' => 1400516827,
  'menuType' => 'multi',
  'createdByUserNum' => array(
    'order' => '1',
    'type' => 'textfield',
    'label' => 'User Num',
    'isSystemField' => '1',
    'customColumnType' => 'INT NOT NULL',
  ),
  'createdDate' => array(
    'order' => '2',
    'type' => 'none',
    'label' => 'Created',
    'isSystemField' => '1',
  ),
  'tableOrTag' => array(
    'order' => '2',
    'type' => 'textfield',
    'label' => 'Table Or Tag',
    'isSystemField' => '1',
    'customColumnType' => 'VARCHAR(255) NOT NULL',
  ),
  'recordNum' => array(
    'order' => '3',
    'type' => 'textfield',
    'label' => 'Record Num',
    'isSystemField' => '1',
    'customColumnType' => 'INT NOT NULL',
  ),
  '_tableName' => '_website_favorites',
);

Then you need to modify the websiteFavorites plugin so that it stores a date in this field, on line 121 of /cmsAdmin/plugins/websiteFavorites/websiteFavorites.php add this line:

  // add favorite
  $query  = "INSERT INTO `" .getTableNameWithPrefix($GLOBALS['WSF_TABLENAME']). "` SET\n";
  $query .= "createdByUserNum = '" .mysql_real_escape_string($CURRENT_USER['num']). "',\n";
  $query .= "tableOrTag       = '" .mysql_real_escape_string($tableOrTag). "',\n";
  $query .= "recordNum        = '" .mysql_real_escape_string($recordNum). "',\n";
  $query .= "createdDate      = '" .date('Y-m-d H:i:s'). "'\n";
  mysql_query($query) or dieAsCaller('MySQL Error: '. htmlspecialchars(mysql_error()) . "\n", 0);
  return true;

Now you should be able to sort your favorites by their created date:

// load matching records
list($favoriteRecords, $favoriteMetaData) = getRecords(array(
'tableName' => 'listings', // update this with your table or tag name
'perPage' => '10',
'where' => " num IN ($favoriteNumsQuery) ",
'loadCreatedBy' => false,
'allowSearch' => false,
'orderBy' => "`createdDate` DESC",
));

As this is a custom modification to the websiteFavourites plugin, if you upgrade at a later date the changes will be lost, we also can't provide any support for issues that arise from this change.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Tom - May 20, 2014

Hi Greg,

I think it's almost done.

I can see there is a new column in the table cms_website_favorites named 'createdDate'

And if I click the Add Favorite link,

the date and time of the click would be logged.

However, it seems still not work in the my_favorites.php

// load matching records
list($favoriteRecords, $favoriteMetaData) = getRecords(array(
'tableName' => 'listings', // update this with your table or tag name
'perPage' => '10',
'where' => " num IN ($favoriteNumsQuery) ",
'loadCreatedBy' => false,
'allowSearch' => false,
'orderBy' => "`createdDate` DESC",
));

The sort order sort the createdDate column in the listing table, not the website_favorites table

The listing order in the my_favorites.php now becomes the sort order of createdDate in the cms_listings table

I did try to change this line

'tableName' => 'website_favorites', // update this with your table or tag name

but got error.

Please advice how to amend the code to sort order in cms_website_favorites table, not the cms_listings table.

Actually I know it is simple but I am a php idolt and sorry for trouble again.

Thanks a lot

By Tom - June 3, 2014

Any News?

Thanks

By claire - June 13, 2014

Hi Tim

I'm following up with Greg about this, I'll get back to you soon.

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By gregThomas - June 13, 2014

Hi Tom, 

Sorry, the code I gave you would have listed the items by the createdDate of the listings as opposed to the creation date of the website favorites. Here is some alternative code that will return the users items based on the favorites creation date:

<?php
    require_once "cmsAdmin/lib/viewer_functions.php";

    // get favorite record nums
    $tableOrTag        = mysql_escape('listings');  // update this with your table or tag name
    $currentUserNum    = mysql_escape( @$CURRENT_USER['num'] );

    // load matching records
    list($favoriteRecords, $favoriteMetaData) = getRecords(array(
      'tableName'     => '_website_favorites', // update this with your table or tag name
      'perPage'       => '10',
      'where'         => "`tableOrTag` = '$tableOrTag' AND _website_favorites.`createdByUserNum` = '$currentUserNum' ",
      'loadCreatedBy' => false,
      'leftJoin'      => array('blog' => 'recordNum'),
      'allowSearch'   => false,
      'orderBy'       => '_website_favorites.`createdDate` DESC'
    ));

    showme($favoriteRecords);

So the above code uses a left join to link the contents of the website favorites to the contents of the listings table.

Then I've updated the where statement so that it will search the website favorites table. 

Finally I've updated the orderBy statement so it will order the results by the created date stored in the website favorites table.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gregThomas - June 18, 2014

Hi Tom,

We've just added the I.E. AJAX caching fix to the latest version of the website membership plugin.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com