Esempio n. 1
0
 /**
  * Populates the ShoppDatabaseObject properties from a db query result object
  *
  * Uses the available data model built from the table schema to
  * automatically set the object properties, taking care to convert
  * special data such as dates and serialized structures.
  *
  * @author Jonathan Davis
  * @since 1.0
  *
  * @param object $data The query results
  * @return void
  **/
 public function populate($data)
 {
     if (empty($data)) {
         return false;
     }
     $properties = get_object_vars($data);
     foreach ((array) $properties as $var => $value) {
         $mapping = empty($this->_map) ? array() : array_flip($this->_map);
         if (!isset($this->_addmap) && !empty($mapping) && !isset($mapping[$var])) {
             continue;
         }
         $property = isset($mapping[$var]) ? $mapping[$var] : $var;
         if (empty($this->_datatypes[$var])) {
             continue;
         }
         // Process the data
         switch ($this->_datatypes[$var]) {
             case 'date':
                 $this->{$property} = sDB::mktime($value);
                 break;
             case 'float':
                 $this->{$property} = (double) $value;
                 break;
             case 'int':
                 $this->{$property} = (int) $value;
                 break;
             case 'string':
                 // If string has been serialized, unserialize it
                 if (sDB::serialized($value)) {
                     $value = @unserialize($value);
                 }
             default:
                 // Anything not needing processing
                 // passes through into the object
                 $this->{$property} = $value;
         }
     }
 }
Esempio n. 2
0
 /**
  * Provides the date the purchase order was created
  *
  * @api `shopp('purchase.date')`
  * @since 1.0
  *
  * @param string        $result  The output
  * @param array         $options The options
  * - **format**: Sets the PHP date formatting to use. Defaults to the WordPress date and time formats
  * @param ShoppPurchase $O       The working object
  * @return string The purchase order date
  **/
 public static function date($result, $options, $O)
 {
     if (empty($options['format'])) {
         $options['format'] = get_option('date_format') . ' ' . get_option('time_format');
     }
     return _d($options['format'], is_int($O->created) ? $O->created : sDB::mktime($O->created));
 }
Esempio n. 3
0
 /**
  * Populates the product with summary data
  *
  * @author Jonathan Davis
  * @since 1.2
  *
  * @return void
  **/
 public function sumloader(&$records, &$data)
 {
     $Summary = new ProductSummary();
     $properties = array_keys($Summary->_datatypes);
     $ignore = array('product', 'modified');
     foreach ($properties as $property) {
         if ($property[0] == '_') {
             continue;
         }
         if (in_array($property, $ignore)) {
             continue;
         }
         switch ($property) {
             case 'ranges':
                 $ranges = explode(',', $data->{$property});
                 $minmax = array('min', 'max');
                 $i = 0;
                 foreach ($minmax as $m) {
                     $range =& $this->{$m};
                     foreach (ProductSummary::$_ranges as $prop) {
                         if (isset($ranges[$i])) {
                             $range[$prop] = (double) $ranges[$i++];
                         }
                     }
                 }
                 break;
             case 'taxed':
                 $taxed = explode(',', $data->{$property});
                 foreach ($taxed as $pricetag) {
                     if (!$pricetag) {
                         continue;
                     }
                     list($m, $name) = explode(' ', $pricetag);
                     if (empty($m)) {
                         continue;
                     }
                     $range =& $this->{$m};
                     $range[$name . '_tax'] = true;
                 }
             default:
                 $this->{$property} = isset($data->{$property}) ? $data->{$property} : false;
         }
         if (isset($this->{$property})) {
             if ('float' == $Summary->_datatypes[$property]) {
                 $this->checksum .= (double) $this->{$property};
             } else {
                 $this->checksum .= $this->{$property};
             }
         }
     }
     $this->checksum = md5($this->checksum);
     if (isset($data->summed)) {
         $this->summed = sDB::mktime($data->summed);
     }
     if (shopp_setting_enabled('inventory') && Shopp::str_true($this->inventory) && $this->stock <= 0) {
         $this->outofstock = true;
     }
 }
Esempio n. 4
0
 /**
  * Load the session from the database
  *
  * @since 1.0
  *
  * @param string $session (optional) A session id to load
  * @return bool True if session data was loaded successfully, false otherwise
  **/
 protected function load($session = false)
 {
     if (empty($session)) {
         $session = $this->session;
     }
     if (empty($session)) {
         return false;
     }
     do_action('shopp_session_load');
     $query = "SELECT * FROM {$this->_table} WHERE session='{$session}'";
     $loaded = sDB::query($query, 'object');
     if (empty($loaded)) {
         // No session found in the database
         if (!empty($this->session)) {
             $this->session(true);
             // Cookie exists, but no session in the database, re-session (new id)
             $this->cook();
             // Ensure leftover session cookies are replaced for security reasons
         }
         return false;
     }
     $this->decrypt($loaded->data);
     if (empty($loaded->data)) {
         return false;
     }
     $this->session = $loaded->session;
     $this->ip = $loaded->ip;
     $this->data = unserialize($loaded->data);
     $this->stash = $loaded->stash;
     $this->created = sDB::mktime($loaded->created);
     $this->modified = sDB::mktime($loaded->modified);
     do_action('shopp_session_loaded');
     return true;
 }