Пример #1
0
 /**
  * Update or insert a license.
  *
  * @param Wslm_ProductLicense|array $license
  * @return Wslm_ProductLicense
  */
 public function saveLicense($license)
 {
     if (is_array($license)) {
         $license = new Wslm_ProductLicense($license);
     }
     $data = $license->getData();
     //The license object might have some virtual or computed fields that don't exist in the DB.
     //If we try to update/insert those, we'll get an SQL error. So lets filter the data array
     //to ensure only valid fields are included in the query.
     $licenseDbFields = array('license_id', 'license_key', 'product_id', 'product_slug', 'customer_id', 'status', 'issued_on', 'expires_on', 'max_sites');
     $licenseDbFields = apply_filters('wslm_license_db_fields', $licenseDbFields);
     $data = array_intersect_key($data, array_flip($licenseDbFields));
     if (is_numeric($data['expires_on'])) {
         $data['expires_on'] = date('Y-m-d H:i:s', $data['expires_on']);
     }
     if ($license->get('license_id') === null) {
         //wpdb converts null values to "0" which is not what we want.
         //When inserting, we can simply strip them and let the DB fill in the blanks with NULLs.
         $data = array_filter($data, __CLASS__ . '::isNotNull');
         $this->wpdb->insert($this->tablePrefix . 'licenses', $data);
         $license['license_id'] = $this->wpdb->insert_id;
     } else {
         //When updating, we need to check for nulls and treat them differently,
         //so we can't use $wpdb->update here.
         $query = "UPDATE {$this->tablePrefix}licenses SET ";
         $expressions = array();
         foreach ($data as $field => $value) {
             $expressions[] = $field . ' = ' . ($value === null ? 'NULL' : $this->wpdb->prepare('%s', $value));
         }
         $query .= implode(', ', $expressions);
         $query .= ' WHERE license_id = ' . absint($license['license_id']);
         $this->wpdb->query($query);
     }
     return $license;
 }
    /**
     * @param string $status
     * @param string $message
     * @param Wslm_ProductLicense $currentLicense
     */
    private function printLicenseDetails($status, $message = '', $currentLicense = null)
    {
        $currentKey = $this->licenseManager->getLicenseKey();
        $currentToken = $this->licenseManager->getSiteToken();
        ?>
		<p>
			<span class="license-status">
				<label>Status:</label> <?php 
        echo $status;
        ?>
			</span>
		</p>

		<?php 
        if (!empty($currentKey)) {
            ?>
<p><label>License key:</label> <?php 
            echo htmlentities($currentKey);
            ?>
</p><?php 
        }
        if (!empty($currentToken) && $this->tokenDisplayEnabled) {
            ?>
<p><label>Site token:</label> <?php 
            echo htmlentities($currentToken);
            ?>
</p><?php 
        }
        $expiresOn = isset($currentLicense) ? $currentLicense->get('expires_on') : null;
        if ($expiresOn) {
            $formattedDate = date_i18n(get_option('date_format'), strtotime($expiresOn));
            ?>
<p>
				<label>Expires:</label>
				<span title="<?php 
            echo esc_attr($expiresOn);
            ?>
"><?php 
            echo $formattedDate;
            ?>
</span>
			  </p>
			<?php 
        }
        do_action('wslm_license_ui_details-' . $this->slug, $currentKey, $currentToken);
        if (!empty($message)) {
            echo '<p>', $message, '</p>';
        }
    }