Re: Behavior afterFind not filtering data?

2010-07-31 Thread cricket
On Fri, Jul 30, 2010 at 11:03 AM, DragonFlyEye dragonflyey...@gmail.com wrote:
 Ok, the problem appears to be that somewhere in the bowels of
 CakePHP's Models, it doesn't seem to like certain characters and just
 replaces them with ?

 I've discovered this because I'm attempting to run batches through the
 Console. So, I'm only using a Shell script and the Model in question
 and I'm definitely getting ? where I should be getting ™. I've
 verified that my database.php file is using 'encoding'  = 'iso-8859-1'
 and that my core.php shows Configure::write('App.encoding',
 'iso-8859-1'); but neither of these two things is solving the problem.

 Cricket: I've finally convinced people here to get rid of the blasted
 weird characters and replace with HTML entities, but now the battle is
 actually getting that done! Trying to use SQL Server's Import and
 Export utility is at least as unsuccessful so far as doing it the
 CakePHP way and for a variety of reasons, I'd prefer to go CakePHP.


Sorry, can't help if it's a Windows environment. But my inclination
would be to convert everything to UTF-8 using iconv.

And I haven't used SQL-Server in over ten years, so I can't suggest
anything on that end.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Behavior afterFind not filtering data?

2010-07-31 Thread Dr. Loboto
 I've discovered this because I'm attempting to run batches through the
 Console. So, I'm only using a Shell script and the Model in question
 and I'm definitely getting ? where I should be getting ™. I've
 verified that my database.php file is using 'encoding'  = 'iso-8859-1'
 and that my core.php shows Configure::write('App.encoding',
 'iso-8859-1'); but neither of these two things is solving the problem.

There is no ™ sign in iso-8859-1.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Behavior afterFind not filtering data?

2010-07-30 Thread DragonFlyEye
Ok, the problem appears to be that somewhere in the bowels of
CakePHP's Models, it doesn't seem to like certain characters and just
replaces them with ?

I've discovered this because I'm attempting to run batches through the
Console. So, I'm only using a Shell script and the Model in question
and I'm definitely getting ? where I should be getting ™. I've
verified that my database.php file is using 'encoding'  = 'iso-8859-1'
and that my core.php shows Configure::write('App.encoding',
'iso-8859-1'); but neither of these two things is solving the problem.

Cricket: I've finally convinced people here to get rid of the blasted
weird characters and replace with HTML entities, but now the battle is
actually getting that done! Trying to use SQL Server's Import and
Export utility is at least as unsuccessful so far as doing it the
CakePHP way and for a variety of reasons, I'd prefer to go CakePHP.

Thanks to anyone who can help.

On Jul 22, 3:15 pm, DragonFlyEye dragonflyey...@gmail.com wrote:
 Not really. We're talking about thousands of products for a start. And
 I expect to have problems with data entry in the future, like cutting
 and pasting from Word. Plus there is some resistence to changing
 things around here that I've got to slowly overcome. In the meanwhile,
 I have to be able to show progress.

 The result I'm getting is exactly the same as the original query. IOW:
 as though the filtering isn't happening. I've intentionally put errors
 in the code to make sure that the Model that it's being declared in is
 correctly identifying the file, which it is. But even if I put in
 return 'Bupkis', I still get the same response.

 On Jul 22, 2:59 pm, cricket zijn.digi...@gmail.com wrote:

  You haven't said what results you're seeing. Anyway, at a glance, I
  can see one problem.

  Sanitize::clean($results);

  should be:

  $results = Sanitize::clean($results);

  But, wouldn't it be simpler to just write a script that cleans up the
  DB once and forget about it?

  On Thu, Jul 22, 2010 at 2:06 PM, DragonFlyEye dragonflyey...@gmail.com 
  wrote:
   I'm sure I'm missing something silly, but I cannot get this Behavior
   to work. I've got data with a bunch of nasty characters in the
   database that I need to avoid or escape before presenting to the
   browser. Also, it's got a lot of white space at the end of much of the
   data because someone erroneously used the nchar datatype on the MS-SQL
   database I'm working off of. So this Behavior is just to be able to
   get rid of those problems going forward. Right now, I'm using it on
   the afterFind hook, but once I know it works safely I'll apply it to
   the beforeSave hook:

   ?php
   App::import('Sanitize');
   class TrimAndEscapeBehavior extends ModelBehavior {
          var $errors             = array();

          function afterFind($Model, $results, $primary) {
                  $results = $this-cleanText($results);
                  Sanitize::clean($results);
                  return $results;
          }

          /*
          // cleanText:                   Recursive function trims text and 
   removes illegal
   characters.
          // @var mixed $data:    The data to inspect and clean.
          // @data mixed $data:   The cleaned data.
          */
          function cleanText($results) {
                  // If this is an array, send it back through:
                  if(is_array($results)) :
                          foreach($results as $key=$value) :
                                  $results[$key]  = $this-cleanText($value);
                          endforeach;
                  // We have a text node. Trim and escape:
                  else :
                          // replace Trademarks:
                          $results = str_replace(chr(8482), 
   'suptrade;/sup', $results);
                          // Replace Registered Trademarks
                          $results = str_replace(chr(174), 
   'supreg;/sup', $results);
                          // replace Trademarks:
                          $results = str_replace('#8482;', 
   'suptrade;/sup', $results);
                          // Replace Registered Trademarks
                          $results = str_replace('#174;', 
   'supreg;/sup', $results);
                          // Trim content:
                          $results = trim($results);
                          return $results;
                  endif;
          }
   }
   ?

   Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others 
   with their CakePHP related questions.

   You received this message because you are subscribed to the Google Groups 
   CakePHP group.
   To post to this group, send email to cake-php@googlegroups.com
   To unsubscribe from this group, send email to
   cake-php+unsubscr...@googlegroups.com For more options, visit this group 
   athttp://groups.google.com/group/cake-php?hl=en



Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP 

Behavior afterFind not filtering data?

2010-07-22 Thread DragonFlyEye
I'm sure I'm missing something silly, but I cannot get this Behavior
to work. I've got data with a bunch of nasty characters in the
database that I need to avoid or escape before presenting to the
browser. Also, it's got a lot of white space at the end of much of the
data because someone erroneously used the nchar datatype on the MS-SQL
database I'm working off of. So this Behavior is just to be able to
get rid of those problems going forward. Right now, I'm using it on
the afterFind hook, but once I know it works safely I'll apply it to
the beforeSave hook:

?php
App::import('Sanitize');
class TrimAndEscapeBehavior extends ModelBehavior {
var $errors = array();

function afterFind($Model, $results, $primary) {
$results = $this-cleanText($results);
Sanitize::clean($results);
return $results;
}


/*
// cleanText:   Recursive function trims text and 
removes illegal
characters.
// @var mixed $data:The data to inspect and clean.
// @data mixed $data:   The cleaned data.
*/
function cleanText($results) {
// If this is an array, send it back through:
if(is_array($results)) :
foreach($results as $key=$value) :
$results[$key]  = $this-cleanText($value);
endforeach;
// We have a text node. Trim and escape:
else :
// replace Trademarks:
$results = str_replace(chr(8482), 'suptrade;/sup', 
$results);
// Replace Registered Trademarks
$results = str_replace(chr(174), 'supreg;/sup', 
$results);
// replace Trademarks:
$results = str_replace('#8482;', 'suptrade;/sup', 
$results);
// Replace Registered Trademarks
$results = str_replace('#174;', 'supreg;/sup', 
$results);
// Trim content:
$results = trim($results);
return $results;
endif;
}
}
?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Behavior afterFind not filtering data?

2010-07-22 Thread cricket
You haven't said what results you're seeing. Anyway, at a glance, I
can see one problem.

Sanitize::clean($results);

should be:

$results = Sanitize::clean($results);

But, wouldn't it be simpler to just write a script that cleans up the
DB once and forget about it?

On Thu, Jul 22, 2010 at 2:06 PM, DragonFlyEye dragonflyey...@gmail.com wrote:
 I'm sure I'm missing something silly, but I cannot get this Behavior
 to work. I've got data with a bunch of nasty characters in the
 database that I need to avoid or escape before presenting to the
 browser. Also, it's got a lot of white space at the end of much of the
 data because someone erroneously used the nchar datatype on the MS-SQL
 database I'm working off of. So this Behavior is just to be able to
 get rid of those problems going forward. Right now, I'm using it on
 the afterFind hook, but once I know it works safely I'll apply it to
 the beforeSave hook:

 ?php
 App::import('Sanitize');
 class TrimAndEscapeBehavior extends ModelBehavior {
        var $errors             = array();

        function afterFind($Model, $results, $primary) {
                $results = $this-cleanText($results);
                Sanitize::clean($results);
                return $results;
        }


        /*
        // cleanText:                   Recursive function trims text and 
 removes illegal
 characters.
        // @var mixed $data:    The data to inspect and clean.
        // @data mixed $data:   The cleaned data.
        */
        function cleanText($results) {
                // If this is an array, send it back through:
                if(is_array($results)) :
                        foreach($results as $key=$value) :
                                $results[$key]  = $this-cleanText($value);
                        endforeach;
                // We have a text node. Trim and escape:
                else :
                        // replace Trademarks:
                        $results = str_replace(chr(8482), 
 'suptrade;/sup', $results);
                        // Replace Registered Trademarks
                        $results = str_replace(chr(174), 'supreg;/sup', 
 $results);
                        // replace Trademarks:
                        $results = str_replace('#8482;', 
 'suptrade;/sup', $results);
                        // Replace Registered Trademarks
                        $results = str_replace('#174;', 'supreg;/sup', 
 $results);
                        // Trim content:
                        $results = trim($results);
                        return $results;
                endif;
        }
 }
 ?

 Check out the new CakePHP Questions site http://cakeqs.org and help others 
 with their CakePHP related questions.

 You received this message because you are subscribed to the Google Groups 
 CakePHP group.
 To post to this group, send email to cake-php@googlegroups.com
 To unsubscribe from this group, send email to
 cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
 http://groups.google.com/group/cake-php?hl=en


Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Behavior afterFind not filtering data?

2010-07-22 Thread DragonFlyEye
Not really. We're talking about thousands of products for a start. And
I expect to have problems with data entry in the future, like cutting
and pasting from Word. Plus there is some resistence to changing
things around here that I've got to slowly overcome. In the meanwhile,
I have to be able to show progress.

The result I'm getting is exactly the same as the original query. IOW:
as though the filtering isn't happening. I've intentionally put errors
in the code to make sure that the Model that it's being declared in is
correctly identifying the file, which it is. But even if I put in
return 'Bupkis', I still get the same response.

On Jul 22, 2:59 pm, cricket zijn.digi...@gmail.com wrote:
 You haven't said what results you're seeing. Anyway, at a glance, I
 can see one problem.

 Sanitize::clean($results);

 should be:

 $results = Sanitize::clean($results);

 But, wouldn't it be simpler to just write a script that cleans up the
 DB once and forget about it?

 On Thu, Jul 22, 2010 at 2:06 PM, DragonFlyEye dragonflyey...@gmail.com 
 wrote:
  I'm sure I'm missing something silly, but I cannot get this Behavior
  to work. I've got data with a bunch of nasty characters in the
  database that I need to avoid or escape before presenting to the
  browser. Also, it's got a lot of white space at the end of much of the
  data because someone erroneously used the nchar datatype on the MS-SQL
  database I'm working off of. So this Behavior is just to be able to
  get rid of those problems going forward. Right now, I'm using it on
  the afterFind hook, but once I know it works safely I'll apply it to
  the beforeSave hook:

  ?php
  App::import('Sanitize');
  class TrimAndEscapeBehavior extends ModelBehavior {
         var $errors             = array();

         function afterFind($Model, $results, $primary) {
                 $results = $this-cleanText($results);
                 Sanitize::clean($results);
                 return $results;
         }

         /*
         // cleanText:                   Recursive function trims text and 
  removes illegal
  characters.
         // @var mixed $data:    The data to inspect and clean.
         // @data mixed $data:   The cleaned data.
         */
         function cleanText($results) {
                 // If this is an array, send it back through:
                 if(is_array($results)) :
                         foreach($results as $key=$value) :
                                 $results[$key]  = $this-cleanText($value);
                         endforeach;
                 // We have a text node. Trim and escape:
                 else :
                         // replace Trademarks:
                         $results = str_replace(chr(8482), 
  'suptrade;/sup', $results);
                         // Replace Registered Trademarks
                         $results = str_replace(chr(174), 'supreg;/sup', 
  $results);
                         // replace Trademarks:
                         $results = str_replace('#8482;', 
  'suptrade;/sup', $results);
                         // Replace Registered Trademarks
                         $results = str_replace('#174;', 'supreg;/sup', 
  $results);
                         // Trim content:
                         $results = trim($results);
                         return $results;
                 endif;
         }
  }
  ?

  Check out the new CakePHP Questions sitehttp://cakeqs.organd help others 
  with their CakePHP related questions.

  You received this message because you are subscribed to the Google Groups 
  CakePHP group.
  To post to this group, send email to cake-php@googlegroups.com
  To unsubscribe from this group, send email to
  cake-php+unsubscr...@googlegroups.com For more options, visit this group 
  athttp://groups.google.com/group/cake-php?hl=en



Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en