Example #1
0
 private function sanitize($data)
 {
     if (!isset($data['created']) || !awpcp_is_mysql_date($data['created'])) {
         $data['created'] = awpcp_datetime();
     }
     $data['enabled'] = absint($data['enabled']);
     $data['is_primary'] = absint($data['is_primary']);
     return $data;
 }
Example #2
0
 protected function sanitize($data)
 {
     $sanitized = $data;
     // make sure dates are dates or NULL, MySQL Strict mode does not allow empty strings
     $columns = array('ad_postdate', 'ad_last_updated', 'ad_startdate', 'ad_enddate', 'disabled_date', 'renewed_date', 'verified_at');
     foreach ($columns as $column) {
         $value = trim($sanitized[$column]);
         if (!awpcp_is_mysql_date($value)) {
             // Remove this column. Not a valid date or datetime and
             // WordPress does not handle NULL values very well:
             // http://core.trac.wordpress.org/ticket/15158
             unset($sanitized[$column]);
         } else {
             $sanitized[$column] = $value;
         }
     }
     // make sure values for float columns are float
     $columns = array('ad_fee_paid');
     foreach ($columns as $column) {
         $sanitized[$column] = floatval(trim($sanitized[$column]));
     }
     // make sure values for int/tinyint columns are int
     $columns = array('ad_id', 'adterm_id', 'ad_category_id', 'ad_category_parent_id', 'ad_views', 'disabled', 'is_featured_ad', 'flagged', 'renew_email_sent', 'verified', 'ad_item_price');
     foreach ($columns as $column) {
         $sanitized[$column] = intval(trim($sanitized[$column]));
     }
     return $sanitized;
 }