Overview

Namespaces

  • None
  • Quform
    • Traduttore_Registry

Classes

  • Quform
  • Quform_Admin_InsertForm
  • Quform_Admin_Page
  • Quform_Admin_Page_Controller
  • Quform_Admin_Page_Dashboard
  • Quform_Admin_Page_Entries
  • Quform_Admin_Page_Entries_Edit
  • Quform_Admin_Page_Entries_List
  • Quform_Admin_Page_Entries_View
  • Quform_Admin_Page_Factory
  • Quform_Admin_Page_Forms_Add
  • Quform_Admin_Page_Forms_Edit
  • Quform_Admin_Page_Forms_List
  • Quform_Admin_Page_Help
  • Quform_Admin_Page_Preview
  • Quform_Admin_Page_Settings
  • Quform_Admin_Page_Tools
  • Quform_Admin_Page_Tools_ExportEntries
  • Quform_Admin_Page_Tools_ExportForm
  • Quform_Admin_Page_Tools_Home
  • Quform_Admin_Page_Tools_ImportForm
  • Quform_Admin_Page_Tools_Migrate
  • Quform_Admin_Page_Tools_Uninstall
  • Quform_Api
  • Quform_Block
  • Quform_Builder
  • Quform_Captcha
  • Quform_ClassLoader
  • Quform_Confirmation
  • Quform_Container
  • Quform_Dashboard_Widget
  • Quform_Dispatcher
  • Quform_Element
  • Quform_Element_Captcha
  • Quform_Element_Checkbox
  • Quform_Element_Column
  • Quform_Element_Container
  • Quform_Element_Container_Iterator
  • Quform_Element_Date
  • Quform_Element_Email
  • Quform_Element_Factory
  • Quform_Element_Field
  • Quform_Element_File
  • Quform_Element_Group
  • Quform_Element_Hidden
  • Quform_Element_Honeypot
  • Quform_Element_Html
  • Quform_Element_Multi
  • Quform_Element_Multiselect
  • Quform_Element_Name
  • Quform_Element_Page
  • Quform_Element_Password
  • Quform_Element_Radio
  • Quform_Element_Recaptcha
  • Quform_Element_Row
  • Quform_Element_Select
  • Quform_Element_Submit
  • Quform_Element_Text
  • Quform_Element_Textarea
  • Quform_Element_Time
  • Quform_Entry_Controller
  • Quform_Entry_Exporter
  • Quform_Entry_List_Settings
  • Quform_Entry_List_Table
  • Quform_Entry_Processor
  • Quform_Entry_UserSearcher
  • Quform_Filter_Abstract
  • Quform_Filter_Alpha
  • Quform_Filter_AlphaNumeric
  • Quform_Filter_Digits
  • Quform_Filter_Regex
  • Quform_Filter_Static
  • Quform_Filter_StripTags
  • Quform_Filter_Trim
  • Quform_Form
  • Quform_Form_Controller
  • Quform_Form_Exporter
  • Quform_Form_Factory
  • Quform_Form_Importer
  • Quform_Form_Iterator
  • Quform_Form_List_Settings
  • Quform_Form_List_Table
  • Quform_Form_Processor
  • Quform_License
  • Quform_Migrator
  • Quform_NonceRefresher
  • Quform_Notification
  • Quform_Notification_Resender
  • Quform_Options
  • Quform_Permissions
  • Quform_Repository
  • Quform_ScriptLoader
  • Quform_Session
  • Quform_Settings
  • Quform_Shortcode
  • Quform_Themes
  • Quform_TokenReplacer
  • Quform_Toolbar
  • Quform_Translations
  • Quform_Updater
  • Quform_Upgrader
  • Quform_Uploader
  • Quform_Validator_Abstract
  • Quform_Validator_Alpha
  • Quform_Validator_AlphaNumeric
  • Quform_Validator_Array
  • Quform_Validator_Captcha
  • Quform_Validator_Date
  • Quform_Validator_Digits
  • Quform_Validator_Duplicate
  • Quform_Validator_Email
  • Quform_Validator_FileUpload
  • Quform_Validator_GreaterThan
  • Quform_Validator_Honeypot
  • Quform_Validator_Identical
  • Quform_Validator_InArray
  • Quform_Validator_Length
  • Quform_Validator_LessThan
  • Quform_Validator_Recaptcha
  • Quform_Validator_Regex
  • Quform_Validator_Required
  • Quform_Validator_Static
  • Quform_Validator_Time
  • Quform_View
  • Quform_ViewFactory
  • Quform_Widget_Form
  • Quform_Widget_Popup

Interfaces

  • Quform_Attachable
  • Quform_Element_Editable
  • Quform_Filter_Interface
  • Quform_Validator_Interface

Constants

  • Quform\Traduttore_Registry\TRANSIENT_KEY_PLUGIN
  • Quform\Traduttore_Registry\TRANSIENT_KEY_THEME

Functions

  • Quform\Traduttore_Registry\add_project
  • Quform\Traduttore_Registry\clean_translations_cache
  • Quform\Traduttore_Registry\get_available_locales
  • Quform\Traduttore_Registry\get_installed_translations
  • Quform\Traduttore_Registry\get_translations
  • Quform\Traduttore_Registry\register_clean_translations_cache
  • Quform\Traduttore_Registry\sanitize_date
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: /**
  4:  * @copyright Copyright (c) 2009-2022 ThemeCatcher (https://www.themecatcher.net)
  5:  */
  6: class Quform_Updater
  7: {
  8:     /**
  9:      * How long to cache the latest version information
 10:      * @var int
 11:      */
 12:     const CACHE_TIME = 43200; // 12 hours
 13: 
 14:     /**
 15:      * @var Quform_Api
 16:      */
 17:     protected $api;
 18: 
 19:     /**
 20:      * @var Quform_License
 21:      */
 22:     protected $license;
 23: 
 24:     public function __construct(Quform_Api $api, Quform_License $license)
 25:     {
 26:         $this->api = $api;
 27:         $this->license = $license;
 28:     }
 29: 
 30:     /**
 31:      * Add the update information to the transient object if an update exists
 32:      *
 33:      * @param  object $transient
 34:      * @return object
 35:      */
 36:     public function setUpdateTransient($transient)
 37:     {
 38:         if (empty($transient) || !is_object($transient)) {
 39:             return $transient;
 40:         }
 41: 
 42:         $latestVersionInfo = $this->getLatestVersionInfo();
 43: 
 44:         if ($latestVersionInfo && version_compare(QUFORM_VERSION, $latestVersionInfo->new_version, '<')) {
 45:             $transient->response[QUFORM_BASENAME] = $latestVersionInfo;
 46:         } else {
 47:             unset($transient->response[QUFORM_BASENAME]);
 48: 
 49:             $transient->no_update[QUFORM_BASENAME] = (object) array(
 50:                 'id' => QUFORM_NAME,
 51:                 'slug' => QUFORM_NAME,
 52:                 'plugin' => QUFORM_BASENAME,
 53:                 'new_version' => QUFORM_VERSION,
 54:                 'url' => 'https://www.quform.com/',
 55:                 'package' => ''
 56:             );
 57:         }
 58: 
 59:         return $transient;
 60:     }
 61: 
 62:     /**
 63:      * Validate the request to check for an update
 64:      */
 65:     protected function validateCheckForUpdateRequest()
 66:     {
 67:         if ( ! current_user_can('quform_settings')) {
 68:             wp_send_json(array(
 69:                 'type'    => 'error',
 70:                 'message' => __('Insufficient permissions', 'quform')
 71:             ));
 72:         }
 73: 
 74:         if ( ! check_ajax_referer('quform_manual_update_check', false, false)) {
 75:             wp_send_json(array(
 76:                 'type'    => 'error',
 77:                 'message' => __('Nonce check failed', 'quform')
 78:             ));
 79:         }
 80:     }
 81: 
 82:     /**
 83:      * Checks the for the latest version information for the Settings page
 84:      */
 85:     public function checkForUpdate()
 86:     {
 87:         $this->validateCheckForUpdateRequest();
 88: 
 89:         delete_site_transient('quform_latest_version_info');
 90:         delete_site_transient('update_plugins');
 91: 
 92:         $latestVersionInfo = $this->getLatestVersionInfo(false);
 93: 
 94:         if ( ! $latestVersionInfo || ! isset($latestVersionInfo->new_version)) {
 95:             wp_send_json(array(
 96:                 'type' => 'error',
 97:                 'message' => __('Could not find an updated version', 'quform')
 98:             ));
 99:         }
100: 
101:         if (version_compare(QUFORM_VERSION, $latestVersionInfo->new_version, '<')) {
102:             wp_send_json(array(
103:                 'type' => 'success',
104:                 'message' => wp_kses(sprintf(
105:                     /* translators: %1$s: the new version, %2$s: open link tag, %3$s: close link tag */
106:                     __('An update to version %1$s is available, %2$svisit the Plugins page%3$s to update.', 'quform'),
107:                     $latestVersionInfo->new_version,
108:                     sprintf('<a href="%s">', esc_url(admin_url('plugins.php'))),
109:                     '</a>'
110:                 ), array('a' => array('href' => array())))
111:             ));
112:         } else {
113:             wp_send_json(array(
114:                 'type' => 'success',
115:                 'message' => __('You are using the latest version.', 'quform')
116:             ));
117:         }
118:     }
119: 
120:     /**
121:      * Get the latest version information
122:      *
123:      * @param   boolean $cache    Whether the information should be fetched from the cache if available
124:      * @return  boolean|StdClass  The version information object or false on failure
125:      */
126:     protected function getLatestVersionInfo($cache = true)
127:     {
128:         $latestVersionInfo = $cache ? get_site_transient('quform_latest_version_info') : false;
129: 
130:         if ( ! $latestVersionInfo) {
131:             // Fetch fresh version info
132:             $response = $this->api->get('/update-check', array(
133:                 'license_key' => $this->license->getKey(),
134:                 'site_url' => Quform::base64UrlEncode(site_url())
135:             ));
136: 
137:             if (is_array($response)) {
138:                 if (isset($response['revoke'])) {
139:                     $this->license->revoke();
140:                     unset($response['revoke']);
141:                 }
142: 
143:                 $latestVersionInfo = (object) $response;
144:                 $latestVersionInfo->slug = QUFORM_NAME;
145:                 $latestVersionInfo->plugin = QUFORM_BASENAME;
146: 
147:                 set_site_transient('quform_latest_version_info', $latestVersionInfo, self::CACHE_TIME);
148:             }
149:         }
150: 
151:         return $latestVersionInfo;
152:     }
153: 
154:     /**
155:      * Get plugin information
156:      *
157:      * @param   boolean         $false   Returned if the method call is not for this action or plugin
158:      * @param   string          $action  The action to perform
159:      * @param   object          $args    The current plugin data
160:      * @return  boolean|object           The plugin information data or the $false argument
161:      */
162:     public function pluginInformation($false, $action, $args)
163:     {
164:         // Do not interfere with other plugins or actions
165:         if ($action != 'plugin_information' || ! isset($args->slug) || $args->slug != QUFORM_NAME) {
166:             return $false;
167:         }
168: 
169:         $response = $this->api->get('/plugin-information', array(
170:             'license_key' => $this->license->getKey(),
171:             'site_url' => Quform::base64UrlEncode(site_url())
172:         ));
173: 
174:         if ( ! is_array($response)) {
175:             return $false;
176:         }
177: 
178:         $response['slug'] = QUFORM_NAME;
179: 
180:         return (object) $response;
181:     }
182: }
183: 
API documentation generated by ApiGen