├── inc
├── images
│ ├── star.png
│ ├── donate.jpg
│ ├── loading.gif
│ ├── red-dot.png
│ ├── black-dot.png
│ ├── blue-dot.png
│ ├── blue-grad.png
│ ├── green-dot.png
│ ├── pink-dot.png
│ ├── teal-dot.png
│ ├── white-dot.png
│ ├── purple-dot.png
│ ├── yellow-dot.png
│ ├── button-red-grad.png
│ ├── map-type-hybrid.jpg
│ ├── map-type-normal.jpg
│ ├── map-type-terrain.jpg
│ ├── map-type-satellite.jpg
│ └── button-red-grad-active.png
└── styles
│ ├── admin.css
│ ├── dark.css
│ └── light.css
├── wpml-config.xml
├── readme.txt
├── classes
├── templates.php
├── admin.php
├── maps.php
├── xml-search.php
├── shortcodes.php
├── help.php
├── widgets.php
├── ft-ps-client.php
└── parsecsv.lib.php
├── simplemap.php
└── GNU-GPL.txt
/inc/images/star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesomemotive/simplemap/HEAD/inc/images/star.png
--------------------------------------------------------------------------------
/inc/images/donate.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesomemotive/simplemap/HEAD/inc/images/donate.jpg
--------------------------------------------------------------------------------
/inc/images/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesomemotive/simplemap/HEAD/inc/images/loading.gif
--------------------------------------------------------------------------------
/inc/images/red-dot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesomemotive/simplemap/HEAD/inc/images/red-dot.png
--------------------------------------------------------------------------------
/inc/images/black-dot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesomemotive/simplemap/HEAD/inc/images/black-dot.png
--------------------------------------------------------------------------------
/inc/images/blue-dot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesomemotive/simplemap/HEAD/inc/images/blue-dot.png
--------------------------------------------------------------------------------
/inc/images/blue-grad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesomemotive/simplemap/HEAD/inc/images/blue-grad.png
--------------------------------------------------------------------------------
/inc/images/green-dot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesomemotive/simplemap/HEAD/inc/images/green-dot.png
--------------------------------------------------------------------------------
/inc/images/pink-dot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesomemotive/simplemap/HEAD/inc/images/pink-dot.png
--------------------------------------------------------------------------------
/inc/images/teal-dot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesomemotive/simplemap/HEAD/inc/images/teal-dot.png
--------------------------------------------------------------------------------
/inc/images/white-dot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesomemotive/simplemap/HEAD/inc/images/white-dot.png
--------------------------------------------------------------------------------
/inc/images/purple-dot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesomemotive/simplemap/HEAD/inc/images/purple-dot.png
--------------------------------------------------------------------------------
/inc/images/yellow-dot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesomemotive/simplemap/HEAD/inc/images/yellow-dot.png
--------------------------------------------------------------------------------
/inc/images/button-red-grad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesomemotive/simplemap/HEAD/inc/images/button-red-grad.png
--------------------------------------------------------------------------------
/inc/images/map-type-hybrid.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesomemotive/simplemap/HEAD/inc/images/map-type-hybrid.jpg
--------------------------------------------------------------------------------
/inc/images/map-type-normal.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesomemotive/simplemap/HEAD/inc/images/map-type-normal.jpg
--------------------------------------------------------------------------------
/inc/images/map-type-terrain.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesomemotive/simplemap/HEAD/inc/images/map-type-terrain.jpg
--------------------------------------------------------------------------------
/inc/images/map-type-satellite.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesomemotive/simplemap/HEAD/inc/images/map-type-satellite.jpg
--------------------------------------------------------------------------------
/inc/images/button-red-grad-active.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/awesomemotive/simplemap/HEAD/inc/images/button-red-grad-active.png
--------------------------------------------------------------------------------
/wpml-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | sm-location
4 |
5 |
6 | sm-category
7 | sm-tag
8 | sm-day
9 | sm-time
10 |
11 |
12 |
--------------------------------------------------------------------------------
/readme.txt:
--------------------------------------------------------------------------------
1 | === SimpleMap Store Locator ===
2 |
3 | Contributors: hallsofmontezuma, fullthrottledevelopment, wpsmort, arnaudbroes
4 | Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=mrtorbert%40gmail%2ecom&item_name=SimpleMap&item_number=Support%20Open%20Source&no_shipping=0&no_note=1&tax=0¤cy_code=USD&lc=US&bn=PP%2dDonationsBF&charset=UTF%2d8
5 | Tags: map, maps, store locator, database, local seo, locations, stores, Google maps, locator
6 | Requires at least: 3.3
7 | Tested up to: 5.3.2
8 | Stable tag: 2.6.1
9 |
10 | Easy to use Store Locator / Local SEO plugin (supports international stores) using Google Maps
11 |
12 | == Description ==
13 |
14 | SimpleMap Local SEO is a *powerful* and *easy-to-use* international store locator plugin. It has an intuitive interface and is completely customizable. Its search features make it easy for your users to find your locations quickly.
15 |
16 | Key features include:
17 |
18 | * Manage locations from any country supported by Google Maps
19 | * Awesome SEO optimizations for your business
20 | * Manage an unlimited number of locations
21 | * Put a Google Map on any page or post that gives instant results to users
22 | * Users can enter a street address, city, state, or zip to search the database
23 | * Customize the appearance of the map and results with your own themes
24 | * Use a familiar interface that fits seamlessly into the WordPress admin area
25 | * Import and export your database as a CSV file
26 | * Quick Edit function allows for real-time updates to the location database
27 | * Make certain locations stand out with a customizable tag (Most Popular, Ten-Year Member, etc.)
28 | * Easy-to-use settings page means you don't need to know any code to customize your map
29 |
30 | See the screenshots for examples of the plugin in action.
31 |
32 | With SimpleMap, you can easily put a store locator on your WordPress site in seconds. Its intuitive interface makes it the easiest plugin of its kind to use, and the clean design means you'll have a classy store locator that fits in perfectly with any WordPress theme.
33 |
34 | == Screenshots ==
35 |
36 | 1. Example of the map and results
37 | 2. Location with an image tag in the description
38 | 3. Location with HTML formatting in the description
39 | 4. General Options page
40 | 5. Managing the database
41 |
42 | == Frequently Asked Questions ==
43 |
44 | FAQs can be found on our [website](http://simplemap-plugin.com/faqs/)
45 |
46 | == Changelog ==
47 |
48 | SimpleMap [Changelog](http://simplemap-plugin.com/changelog/)
49 |
--------------------------------------------------------------------------------
/classes/templates.php:
--------------------------------------------------------------------------------
1 | template_type = $this->set_template_type();
43 |
44 | // Set the specific template for this view
45 | $this->set_active_template();
46 |
47 | // Add the filter
48 | add_filter( 'the_content', array( &$this, 'apply_template' ), 1 );
49 |
50 | }
51 |
52 | /**
53 | * Parses wp_query to determine the template type we are going to use
54 | * As of 2.4, the only opiton is single-location
55 | *
56 | * @since 2.4
57 | */
58 | function set_template_type() {
59 |
60 | global $post;
61 |
62 | // Exit if we're not on a single disply of the location post type
63 | if ( 'sm-location' != $post->post_type || ! is_single() ) {
64 | return false;
65 | }
66 |
67 | return 'single-location';
68 | }
69 |
70 | /**
71 | * Sets the template we will use for the current view based on a cascading set of rules
72 | * If this is a single location view, do the following:
73 | *
74 | *
Check for specific template via post-meta
75 | *
Check for default template
76 | *
77 | *
78 | * @since 2.4
79 | */
80 | function set_active_template() {
81 |
82 | global $post;
83 |
84 | // Switch based on template type
85 | switch ( $this->template_type ) {
86 | case 'single-location' :
87 | default :
88 | // Grab the ID for the specific template for this post if it is present
89 | $template_id = ( get_post_meta( $post->ID, 'sm-location-template', false ) ) ? get_post_meta( $post->ID, 'sm-location-template', false ) : 0;
90 | break;
91 | }
92 |
93 | $this->template_id = $template_id;
94 | $this->template_structure = $this->get_template_structure();
95 | }
96 |
97 | /**
98 | * Returns the actual template structure we're going to use for this object
99 | *
100 | * @since 2.4
101 | */
102 | function get_template_structure() {
103 |
104 | // Grab the post that contains the template strucutre or the hard_coded structure
105 | if ( 0 != $this->template_id ) {
106 | // get post obejct via ID
107 | // return post_content
108 | } else {
109 | $return = "
315 |
316 | '',
338 | 'show_name' => false,
339 | 'show_address' => false,
340 | 'show_city' => false,
341 | 'show_state' => false,
342 | 'show_zip' => false,
343 | 'show_distance' => false,
344 | 'default_lat' => 0,
345 | 'default_lng' => 0,
346 | 'simplemap_page' => 2,
347 | );
348 |
349 | $new_instance = array();
350 | if ( ! empty( $old_instance ) ) {
351 | $new_instance = $old_instance;
352 | }
353 |
354 | foreach ( $default as $key => $default_value ) {
355 | if ( ! empty( $instance[ $key ] ) ) {
356 | switch ( $key ) {
357 | case 'title':
358 | $new_instance[ $key ] = strip_tags( $instance[ $key ] );
359 | break;
360 | case 'default_lat':
361 | $new_instance[ $key ] = (string) $instance[ $key ];
362 | break;
363 | case 'default_lng':
364 | $new_instance[ $key ] = (string) $instance[ $key ];
365 | break;
366 | case 'simplemap_page':
367 | $new_instance[ $key ] = absint( $instance[ $key ] );
368 | break;
369 | default:
370 | $new_instance[ $key ] = true;
371 | }
372 | } else {
373 | $new_instance[ $key ] = $default_value;
374 | }
375 | }
376 |
377 | global $simple_map;
378 | $options = $simple_map->get_options();
379 | // Taxonomies
380 | foreach ( $options['taxonomies'] as $taxonomy => $tax_info ) {
381 | $key = strtolower( $tax_info['plural'] );
382 | $new_instance[ 'show_' . $key ] = 0;
383 | $new_instance[ $key ] = '';
384 |
385 | if ( ! empty( $instance[ 'show_' . $key ] ) ) {
386 | $new_instance[ 'show_' . $key ] = 1;
387 | if ( ! empty( $instance[ $key ] ) ) {
388 | $new_instance[ $key ] = $instance[ $key ];
389 | }
390 | }
391 | }
392 |
393 | return $new_instance;
394 | }
395 | }
396 |
397 | ?>
398 |
--------------------------------------------------------------------------------
/classes/ft-ps-client.php:
--------------------------------------------------------------------------------
1 | server_url = isset( $config['server_url'] ) ? $config['server_url'] : false;
29 | $this->product_id = isset( $config['product_id'] ) ? $config['product_id'] : false;
30 | $this->plugin_support_page_ids = isset( $config['plugin_support_page_ids'] ) ? $config['plugin_support_page_ids'] : false;
31 | $this->plugin_basename = isset( $config['plugin_basename'] ) ? $config['plugin_basename'] : false;
32 | $this->plugin_slug = isset( $config['plugin_slug'] ) ? $config['plugin_slug'] : false;
33 | $this->learn_more_link = isset( $config['learn_more_link'] ) ? $config['learn_more_link'] : false;
34 | $this->confirming_request = isset( $_GET['ft-ps-confirm-request'] ) ? $_GET['ft-ps-confirm-request'] : false;
35 | $this->receiving_sso = isset( $_POST['ft-ps-receiving-sso'] ) ? $_POST['ft-ps-receiving-sso'] : false;
36 | $this->site_url = site_url();
37 |
38 | // Register actions
39 | add_action( 'admin_head', array( &$this, 'init' ) );
40 | add_action( 'init', array( &$this, 'check_premium_upgrades' ) );
41 |
42 | }
43 |
44 | // Checks for premium upgrades
45 | function check_premium_upgrades() {
46 | // Build key
47 | $exp_option_key = '_ftpssu_' . md5( 'ftpssue-' . $this->product_id . '-' . sanitize_title_with_dashes( $this->site_url ) . '-' . sanitize_title_with_dashes( $this->server_url ) );
48 |
49 | // Check server for auto update?
50 | if ( $expires = get_option( $exp_option_key ) ) {
51 |
52 | if ( $expires > strtotime( 'now' ) ) {
53 | $ft_ps_client_auto_update = new FT_Premium_Support_PluginUpdate_Checker( $this->server_url . '?ft-pss-upgrade-request=1&ft-pss-upgrade-request-product-id=' . $this->product_id . '&ft-pss-upgrade-request-site=' . $this->site_url . '&exp=' . $expires, $this->plugin_basename, $this->plugin_slug, 1 );
54 | } else {
55 | delete_option( 'external_updates-' . $this->plugin_slug );
56 | }
57 | }
58 | }
59 |
60 | // Inits the client if we're on the support page or receiving a request from the server
61 | function init() {
62 |
63 | global $current_screen;
64 |
65 | // Return false if we don't have initial config settings and this isn't a request from the host server
66 | if ( ( ! $this->server_url || ! $this->product_id || ! isset( $this->plugin_support_page_ids ) ) && ( ! $this->confirming_request || ! $this->receiving_sso ) ) {
67 | return;
68 | }
69 |
70 | // Fire in the hole!
71 | if ( $this->receiving_sso ) {
72 | $this->receive_sso();
73 | } elseif ( $this->confirming_request ) {
74 | $this->confirm_request();
75 | } elseif ( in_array( $current_screen->id, $this->plugin_support_page_ids ) ) {
76 | $this->init_premium_support();
77 | }
78 | }
79 |
80 | // This function inits premium support process
81 | function init_premium_support() {
82 |
83 | global $current_user;
84 | wp_get_current_user();
85 |
86 | // Check for premium support, sso, and paypal button transients
87 | $status_key = md5( 'ft_premium_support_' . $this->product_id . '_' . sanitize_title_with_dashes( $this->site_url ) . '_' . sanitize_title_with_dashes( $this->server_url ) );
88 | $sso_key = md5( 'ft_premium_sso_' . $current_user->ID . '_' . $this->product_id . '_' . sanitize_title_with_dashes( $this->site_url ) . '_' . sanitize_title_with_dashes( $this->server_url ) );
89 | $paypal_button_key = md5( 'ft_premium_signup_' . $this->product_id . '_' . sanitize_title_with_dashes( $this->site_url ) . '_' . sanitize_title_with_dashes( $this->server_url ) );
90 | $exp_option_key = '_ftpssu_' . md5( 'ftpssue-' . $this->product_id . '-' . sanitize_title_with_dashes( $this->site_url ) . '-' . sanitize_title_with_dashes( $this->server_url ) );
91 |
92 | // If we haven't set the status in the last 24 hours, or we haven't set a SSO for the current user in the last 3 hours, do it now.
93 | if ( false === ( $ps_status = get_transient( $status_key ) ) || false === ( $sso_status = get_transient( $sso_key ) ) ) {
94 |
95 | $body['ft-ps-status-request'] = true;
96 | $body['site'] = urlencode( $this->site_url );
97 | $body['user'] = $current_user->ID;
98 | $body['product'] = $this->product_id;
99 | $body['email'] = urlencode( $current_user->user_email );
100 | $body['nicename'] = urlencode( $current_user->user_nicename );
101 |
102 | // Ping server for response
103 | if ( $request = wp_remote_post( $this->server_url, array( 'body' => $body, 'timeout' => 20 ) ) ) {
104 |
105 | if ( ! is_wp_error( $request ) && isset( $request['response']['code'] ) && 200 == $request['response']['code'] ) {
106 |
107 | // Response found a server, lets see if it hit a script we recognize
108 | $response = json_decode( $request['body'] );
109 |
110 | // Set the paypal button
111 | if ( ! empty( $response->paypal_button->args ) && ! empty( $response->paypal_button->base ) ) {
112 | $this->paypal_button = add_query_arg( get_object_vars( $response->paypal_button->args ), $response->paypal_button->base );
113 | }
114 |
115 | // Set the expired flag
116 | $this->support_expired = isset( $response->support_expired ) ? $response->support_expired : false;
117 |
118 | // Do we have a premium status?
119 | if ( isset( $response->support_status ) && $response->support_status ) {
120 |
121 | // We have a premium support license for this domain / product combination. Set the transient and property
122 | set_transient( $status_key, $response->support_status, 60 * 60 * 24 );
123 | //set_transient( $status_key, $response->support_status, 60 );
124 | $this->ps_status = $response->support_status;
125 |
126 | // Did we get a user sso back as well? Set the property if we did
127 | if ( isset( $response->user_sso ) && '' != $response->user_sso ) {
128 | set_transient( $sso_key, $response->user_sso, 60 * 60 * 2.9 );
129 | //set_transient( $sso_key, $response->user_sso, 60 );
130 | $this->sso_status = $response->user_sso;
131 | }
132 |
133 | // Set an auto update option with expiration date
134 | if ( isset( $response->support_status->exp_date ) && ! empty( $response->support_status->exp_date ) ) {
135 | update_option( $exp_option_key, $response->support_status->exp_date );
136 |
137 | // Check server for auto update?
138 | if ( $this->ps_status ) {
139 | delete_option( 'external_updates-' . $this->plugin_slug );
140 | $ft_ps_client_auto_update = new FT_Premium_Support_PluginUpdate_Checker( $this->server_url . '?ft-pss-premium-request=1&ft-pss-upgrade-request-product-id=' . $this->product_id . '&ft-pss-upgrade-request-site=' . $this->site_url . '&exp=' . $response->support_status->exp_date, SIMPLEMAP_PATH, $this->plugin_slug, 1 );
141 | }
142 |
143 | }
144 |
145 | } else {
146 |
147 | // No premium support so lets delete the keys
148 | delete_option( 'external_updates-' . $this->plugin_slug );
149 | delete_option( $exp_option_key );
150 | }
151 | }
152 | }
153 | } else {
154 |
155 | // Transients exist, therefore permission exists, set properties
156 | $this->ps_status = $ps_status;
157 | $this->sso_status = $sso_status;
158 |
159 | }
160 |
161 | // Check server for auto update?
162 | if ( $this->ps_status ) {
163 | $ft_ps_client_auto_update = new FT_Premium_Support_PluginUpdate_Checker( $this->server_url . '?ft-pss-upgrade-request=1&ft-pss-upgrade-request-product-id=' . $this->product_id . '&ft-pss-upgrade-request-site=' . $this->site_url, $this->plugin_basename, 'simplemap', 1 );
164 | }
165 |
166 | // Maybe Nag Renewal
167 | $this->maybe_trigger_renewal_nag();
168 |
169 | }
170 |
171 | function maybe_trigger_renewal_nag() {
172 | // Has support expired?
173 | if ( ! empty( $this->support_expired ) && ! is_object( $this->support_expired ) ) {
174 | //add_action( 'admin_notices', array( $this, 'support_expired' ) );
175 |
176 | return;
177 | }
178 |
179 | if ( ! empty( $this->ps_status->exp_date ) ) {
180 | $onemonthout = $this->ps_status->exp_date - 2628000;
181 | // If we are within a month of expiration date
182 | if ( $onemonthout <= strtotime( 'now' ) ) {
183 | //add_action( 'admin_notices', array( $this, 'renew_soon' ) );
184 | }
185 | }
186 | }
187 |
188 | function support_expired() {
189 | $link = $this->paypal_button ? esc_url( $this->paypal_button ) : 'http://simplemap-plugin.com';
190 | echo "
" . sprintf( __( "Your license for SimpleMap has expired! You need to renew your license now for continued support and upgrades: Renew my license now." ), $link ) . '
" . sprintf( __( "SimpleMap is expiring soon! You will need to renew your license for continued support and upgrades: Renew my license now." ), $link ) . '
';
196 | }
197 | }
198 | }
199 |
200 | if ( ! class_exists( 'FT_Premium_Support_PluginUpdate_Checker' ) ) :
201 |
202 | /**
203 | * A custom plugin update checker.
204 | *
205 | * @author Janis Elsts
206 | * @copyright 2010
207 | * @version 1.0
208 | * @access public
209 | */
210 | class FT_Premium_Support_PluginUpdate_Checker {
211 |
212 | var $metadataUrl = ''; //The URL of the plugin's metadata file.
213 | var $pluginFile = ''; //Plugin filename relative to the plugins directory.
214 | var $slug = ''; //Plugin slug.
215 | var $checkPeriod = 12; //How often to check for updates (in hours).
216 | var $optionName = ''; //Where to store the update info.
217 |
218 | /**
219 | * Class constructor.
220 | *
221 | * @param string $metadataUrl The URL of the plugin's metadata file.
222 | * @param string $pluginFile Fully qualified path to the main plugin file.
223 | * @param string $slug The plugin's 'slug'. If not specified, the filename part of $pluginFile sans '.php' will be used as the slug.
224 | * @param integer $checkPeriod How often to check for updates (in hours). Defaults to checking every 12 hours. Set to 0 to disable automatic update checks.
225 | * @param string $optionName Where to store book-keeping info about update checks. Defaults to 'external_updates-$slug'.
226 | *
227 | * @return void
228 | */
229 | function __construct( $metadataUrl, $pluginFile, $slug = '', $checkPeriod = 12, $optionName = '' ) {
230 |
231 | $this->metadataUrl = $metadataUrl;
232 | $this->pluginFile = $pluginFile;
233 | $this->checkPeriod = $checkPeriod;
234 | $this->slug = $slug;
235 |
236 | //If no slug is specified, use the name of the main plugin file as the slug.
237 | //For example, 'my-cool-plugin/cool-plugin.php' becomes 'cool-plugin'.
238 | if ( empty( $this->slug ) ) {
239 | $this->slug = basename( $this->pluginFile, '.php' );
240 | }
241 |
242 | if ( empty( $this->optionName ) ) {
243 | $this->optionName = 'external_updates-' . $this->slug;
244 | }
245 |
246 | if ( '' == $optionName ) {
247 | $this->optionName = 'external_updates-' . $this->slug;
248 | } else {
249 | $this->optionName = $optionName;
250 | }
251 |
252 | $this->installHooks();
253 | }
254 |
255 | /**
256 | * Install the hooks required to run periodic update checks and inject update info
257 | * into WP data structures.
258 | *
259 | * @return void
260 | */
261 | function installHooks() {
262 |
263 | //Override requests for plugin information
264 | add_filter( 'plugins_api', array( &$this, 'injectInfo' ), 10, 3 );
265 |
266 | //Insert our update info into the update array maintained by WP
267 | add_filter( 'site_transient_update_plugins', array( &$this, 'injectUpdate' ) ); //WP 3.0+
268 | add_filter( 'transient_update_plugins', array( &$this, 'injectUpdate' ) ); //WP 2.8+
269 |
270 | //Set up the periodic update checks
271 | $cronHook = 'check_plugin_updates-' . $this->slug;
272 |
273 | if ( $this->checkPeriod > 0 ) {
274 |
275 | //Trigger the check via Cron
276 | add_filter( 'cron_schedules', array( &$this, '_addCustomSchedule' ) );
277 |
278 | if ( ! defined( 'WP_INSTALLING' ) && ! wp_next_scheduled( $cronHook ) ) {
279 |
280 | $scheduleName = 'every' . $this->checkPeriod . 'hours';
281 | wp_schedule_event( time(), $scheduleName, $cronHook );
282 |
283 | }
284 | add_action( $cronHook, array( &$this, 'checkForUpdates' ) );
285 |
286 | //In case Cron is disabled or unreliable, we also manually trigger
287 | //the periodic checks while the user is browsing the Dashboard.
288 | add_action( 'admin_init', array( &$this, 'maybeCheckForUpdates' ) );
289 |
290 | } else {
291 | //Periodic checks are disabled.
292 | wp_clear_scheduled_hook( $cronHook );
293 | }
294 | }
295 |
296 | /**
297 | * Add our custom schedule to the array of Cron schedules used by WP.
298 | *
299 | * @param array $schedules
300 | *
301 | * @return array
302 | */
303 | function _addCustomSchedule( $schedules ) {
304 |
305 | if ( $this->checkPeriod && ( $this->checkPeriod > 0 ) ) {
306 | $scheduleName = 'every' . $this->checkPeriod . 'hours';
307 | $schedules[ $scheduleName ] = array(
308 | 'interval' => $this->checkPeriod * 3600,
309 | 'display' => sprintf( 'Every %d hours', $this->checkPeriod ),
310 | );
311 | }
312 |
313 | return $schedules;
314 | }
315 |
316 | /**
317 | * Retrieve plugin info from the configured API endpoint.
318 | *
319 | * @uses wp_remote_get()
320 | *
321 | * @param array $queryArgs Additional query arguments to append to the request. Optional.
322 | *
323 | * @return PluginInfo
324 | */
325 | function requestInfo( $queryArgs = array() ) {
326 | //Query args to append to the URL. Plugins can add their own by using a filter callback (see addQueryArgFilter()).
327 | $queryArgs['installed_version'] = $this->getInstalledVersion();
328 | $queryArgs = apply_filters( 'puc_request_info_query_args-' . $this->slug, $queryArgs );
329 |
330 | //Various options for the wp_remote_get() call. Plugins can filter these, too.
331 | $options = array(
332 | 'timeout' => 10, //seconds
333 | 'headers' => array(
334 | 'Accept' => 'application/json',
335 | ),
336 | );
337 |
338 | $options = apply_filters( 'puc_request_info_options-' . $this->slug, $options );
339 |
340 | //The plugin info should be at 'http://your-api.com/url/here/$slug/info.json'
341 | $url = $this->metadataUrl;
342 | if ( ! empty( $queryArgs ) ) {
343 | $url = add_query_arg( $queryArgs, $url );
344 | }
345 |
346 | $result = wp_remote_get(
347 | $url,
348 | $options
349 | );
350 |
351 | //Try to parse the response
352 | $ft_premium_support_plugin_info = null;
353 | if ( ! is_wp_error( $result ) && isset( $result['response']['code'] ) && ( $result['response']['code'] == 200 ) && ! empty( $result['body'] ) ) {
354 | $ft_premium_support_plugin_info = FT_Premium_Support_PluginInfo::fromJson( $result['body'] );
355 | }
356 |
357 | $ft_premium_support_plugin_info = apply_filters( 'puc_request_info_result-' . $this->slug, $ft_premium_support_plugin_info, $result );
358 |
359 | return $ft_premium_support_plugin_info;
360 | }
361 |
362 | /**
363 | * Retrieve the latest update (if any) from the configured API endpoint.
364 | *
365 | * @uses PluginUpdateChecker::requestInfo()
366 | *
367 | * @return PluginUpdate An instance of PluginUpdate, or NULL when no updates are available.
368 | */
369 | function requestUpdate() {
370 | //For the sake of simplicity, this function just calls requestInfo()
371 | //and transforms the result accordingly.
372 | $ft_premium_support_plugin_info = $this->requestInfo( array( 'checking_for_updates' => '1' ) );
373 |
374 | if ( $ft_premium_support_plugin_info == null ) {
375 | return null;
376 | }
377 |
378 | return FT_Premium_Support_PluginUpdate::fromPluginInfo( $ft_premium_support_plugin_info );
379 | }
380 |
381 | /**
382 | * Get the currently installed version of the plugin.
383 | *
384 | * @return string Version number.
385 | */
386 | function getInstalledVersion() {
387 |
388 | if ( ! function_exists( 'get_plugins' ) ) {
389 | require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
390 | }
391 |
392 | $allPlugins = get_plugins();
393 |
394 | if ( array_key_exists( $this->pluginFile, $allPlugins ) && array_key_exists( 'Version', $allPlugins[ $this->pluginFile ] ) ) {
395 | return $allPlugins[ $this->pluginFile ]['Version'];
396 | } else {
397 | return '';
398 | } //This should never happen.
399 |
400 | }
401 |
402 | /**
403 | * Check for plugin updates.
404 | * The results are stored in the DB option specified in $optionName.
405 | *
406 | * @return void
407 | */
408 | function checkForUpdates() {
409 | $state = get_option( $this->optionName );
410 |
411 | if ( empty( $state ) ) {
412 | $state = new stdClass;
413 | $state->lastCheck = 0;
414 | $state->checkedVersion = '';
415 | $state->update = null;
416 | }
417 |
418 | $state->lastCheck = time();
419 | $state->checkedVersion = $this->getInstalledVersion();
420 | update_option( $this->optionName, $state ); //Save before checking in case something goes wrong
421 |
422 | $state->update = $this->requestUpdate();
423 | update_option( $this->optionName, $state );
424 | }
425 |
426 | /**
427 | * Check for updates only if the configured check interval has already elapsed.
428 | *
429 | * @return void
430 | */
431 | function maybeCheckForUpdates() {
432 |
433 | if ( empty( $this->checkPeriod ) ) {
434 | return;
435 | }
436 |
437 | $state = get_option( $this->optionName );
438 |
439 | $shouldCheck =
440 | empty( $state ) ||
441 | ! isset( $state->lastCheck ) ||
442 | ( ( time() - $state->lastCheck ) >= $this->checkPeriod * 3600 );
443 |
444 | if ( $shouldCheck ) {
445 | $this->checkForUpdates();
446 | }
447 | }
448 |
449 | /**
450 | * Intercept plugins_api() calls that request information about our plugin and
451 | * use the configured API endpoint to satisfy them.
452 | *
453 | * @see plugins_api()
454 | *
455 | * @param mixed $result
456 | * @param string $action
457 | * @param array|object $args
458 | *
459 | * @return mixed
460 | */
461 | function injectInfo( $result, $action = null, $args = null ) {
462 |
463 | $relevant = ( $action == 'plugin_information' ) && isset( $args->slug ) && ( $args->slug == $this->slug );
464 |
465 | if ( ! $relevant ) {
466 | return $result;
467 | }
468 |
469 | $ft_premium_support_plugin_info = $this->requestInfo();
470 |
471 | if ( $ft_premium_support_plugin_info ) {
472 | return $ft_premium_support_plugin_info->toWpFormat();
473 | }
474 |
475 | return $result;
476 | }
477 |
478 | /**
479 | * Insert the latest update (if any) into the update list maintained by WP.
480 | *
481 | * @param array $updates Update list.
482 | *
483 | * @return array Modified update list.
484 | */
485 | function injectUpdate( $updates ) {
486 |
487 | $state = get_option( $this->optionName );
488 |
489 | //Is there an update to insert?
490 | if ( ! empty( $state ) && isset( $state->update ) && ! empty( $state->update ) ) {
491 |
492 | //Only insert updates that are actually newer than the currently installed version.
493 | if ( version_compare( $state->update->version, $this->getInstalledVersion(), '>' ) ) {
494 | $updates->response[ $this->pluginFile ] = $state->update->toWpFormat();
495 | }
496 |
497 | }
498 |
499 | return $updates;
500 | }
501 |
502 | /**
503 | * Register a callback for filtering query arguments.
504 | *
505 | * The callback function should take one argument - an associative array of query arguments.
506 | * It should return a modified array of query arguments.
507 | *
508 | * @uses add_filter() This method is a convenience wrapper for add_filter().
509 | *
510 | * @param callback $callback
511 | *
512 | * @return void
513 | */
514 | function addQueryArgFilter( $callback ) {
515 | add_filter( 'puc_request_info_query_args-' . $this->slug, $callback );
516 | }
517 |
518 | /**
519 | * Register a callback for filtering arguments passed to wp_remote_get().
520 | *
521 | * The callback function should take one argument - an associative array of arguments -
522 | * and return a modified array or arguments. See the WP documentation on wp_remote_get()
523 | * for details on what arguments are available and how they work.
524 | *
525 | * @uses add_filter() This method is a convenience wrapper for add_filter().
526 | *
527 | * @param callback $callback
528 | *
529 | * @return void
530 | */
531 | function addHttpRequestArgFilter( $callback ) {
532 | add_filter( 'puc_request_info_options-' . $this->slug, $callback );
533 | }
534 |
535 | /**
536 | * Register a callback for filtering the plugin info retrieved from the external API.
537 | *
538 | * The callback function should take two arguments. If the plugin info was retrieved
539 | * successfully, the first argument passed will be an instance of PluginInfo. Otherwise,
540 | * it will be NULL. The second argument will be the corresponding return value of
541 | * wp_remote_get (see WP docs for details).
542 | *
543 | * The callback function should return a new or modified instance of PluginInfo or NULL.
544 | *
545 | * @uses add_filter() This method is a convenience wrapper for add_filter().
546 | *
547 | * @param callback $callback
548 | *
549 | * @return void
550 | */
551 | function addResultFilter( $callback ) {
552 | add_filter( 'puc_request_info_result-' . $this->slug, $callback, 10, 2 );
553 | }
554 | }
555 |
556 | endif;
557 |
558 | if ( ! class_exists( 'FT_Premium_Support_PluginInfo' ) ) :
559 |
560 | /**
561 | * A container class for holding and transforming various plugin metadata.
562 | *
563 | * @author Janis Elsts
564 | * @copyright 2010
565 | * @version 1.0
566 | * @access public
567 | */
568 | class FT_Premium_Support_PluginInfo {
569 |
570 | //Most fields map directly to the contents of the plugin's info.json file.
571 | //See the relevant docs for a description of their meaning.
572 | var $name;
573 | var $slug;
574 | var $version;
575 | var $homepage;
576 | var $sections;
577 | var $download_url;
578 |
579 | var $author;
580 | var $author_homepage;
581 |
582 | var $requires;
583 | var $tested;
584 | var $upgrade_notice;
585 |
586 | var $rating;
587 | var $num_ratings;
588 | var $downloaded;
589 | var $last_updated;
590 |
591 | var $id = 0; //The native WP.org API returns numeric plugin IDs, but they're not used for anything.
592 |
593 | /**
594 | * Create a new instance of PluginInfo from JSON-encoded plugin info
595 | * returned by an external update API.
596 | *
597 | * @param string $json Valid JSON string representing plugin info.
598 | *
599 | * @return PluginInfo New instance of PluginInfo, or NULL on error.
600 | */
601 | function fromJson( $json ) {
602 | $apiResponse = json_decode( $json );
603 | if ( empty( $apiResponse ) || ! is_object( $apiResponse ) ) {
604 | return null;
605 | }
606 |
607 | //Very, very basic validation.
608 | $valid = isset( $apiResponse->name ) && ! empty( $apiResponse->name ) && isset( $apiResponse->version ) && ! empty( $apiResponse->version );
609 | if ( ! $valid ) {
610 | return null;
611 | }
612 |
613 | $info = new FT_Premium_Support_PluginInfo();
614 | foreach ( get_object_vars( $apiResponse ) as $key => $value ) {
615 | $info->$key = $value;
616 | }
617 |
618 | return $info;
619 | }
620 |
621 | /**
622 | * Transform plugin info into the format used by the native WordPress.org API
623 | *
624 | * @return object
625 | */
626 | function toWpFormat() {
627 | $info = new stdClass;
628 |
629 | //The custom update API is built so that many fields have the same name and format
630 | //as those returned by the native WordPress.org API. These can be assigned directly.
631 | $sameFormat = array(
632 | 'name',
633 | 'slug',
634 | 'version',
635 | 'requires',
636 | 'tested',
637 | 'rating',
638 | 'upgrade_notice',
639 | 'num_ratings',
640 | 'downloaded',
641 | 'homepage',
642 | 'last_updated',
643 | );
644 |
645 | foreach ( $sameFormat as $field ) {
646 | if ( isset( $this->$field ) ) {
647 | $info->$field = $this->$field;
648 | }
649 | }
650 |
651 | //Other fields need to be renamed and/or transformed.
652 | $info->download_link = $this->download_url;
653 |
654 | if ( ! empty( $this->author_homepage ) ) {
655 | $info->author = sprintf( '%s', $this->author_homepage, $this->author );
656 | } else {
657 | $info->author = $this->author;
658 | }
659 |
660 | if ( is_object( $this->sections ) ) {
661 | $info->sections = get_object_vars( $this->sections );
662 | } elseif ( is_array( $this->sections ) ) {
663 | $info->sections = $this->sections;
664 | } else {
665 | $info->sections = array( 'description' => '' );
666 | }
667 |
668 | return $info;
669 | }
670 | }
671 |
672 | endif;
673 |
674 | if ( ! class_exists( 'FT_Premium_Support_PluginUpdate' ) ):
675 |
676 | /**
677 | * A simple container class for holding information about an available update.
678 | *
679 | * @author Janis Elsts
680 | * @copyright 2010
681 | * @version 1.0
682 | * @access public
683 | */
684 | class FT_Premium_Support_PluginUpdate {
685 |
686 | var $id = 0;
687 | var $slug;
688 | var $version;
689 | var $homepage;
690 | var $download_url;
691 | var $upgrade_notice;
692 |
693 | /**
694 | * Create a new instance of PluginUpdate from its JSON-encoded representation.
695 | *
696 | * @param string $json
697 | *
698 | * @return PluginUpdate
699 | */
700 | function fromJson( $json ) {
701 | //Since update-related information is simply a subset of the full plugin info,
702 | //we can parse the update JSON as if it was a plugin info string, then copy over
703 | //the parts that we care about.
704 | $ft_premium_support_plugin_info = FT_Premium_Support_PluginInfo::fromJson( $json );
705 | if ( $ft_premium_support_plugin_info != null ) {
706 | return FT_Premium_Support_PluginUpdate::fromPluginInfo( $ft_premium_support_plugin_info );
707 | } else {
708 | return null;
709 | }
710 |
711 | }
712 |
713 | /**
714 | * Create a new instance of PluginUpdate based on an instance of PluginInfo.
715 | * Basically, this just copies a subset of fields from one object to another.
716 | *
717 | * @param PluginInfo $info
718 | *
719 | * @return PluginUpdate
720 | */
721 | function fromPluginInfo( $info ) {
722 |
723 | $update = new FT_Premium_Support_PluginUpdate();
724 | $copyFields = array( 'id', 'slug', 'version', 'homepage', 'download_url', 'upgrade_notice' );
725 | foreach ( $copyFields as $field ) {
726 | $update->$field = $info->$field;
727 | }
728 |
729 | return $update;
730 |
731 | }
732 |
733 | /**
734 | * Transform the update into the format used by WordPress native plugin API.
735 | *
736 | * @return object
737 | */
738 | function toWpFormat() {
739 |
740 | $update = new stdClass;
741 |
742 | $update->id = $this->id;
743 | $update->slug = $this->slug;
744 | $update->new_version = $this->version;
745 | $update->url = $this->homepage;
746 | $update->package = $this->download_url;
747 |
748 | if ( ! empty( $this->upgrade_notice ) ) {
749 | $update->upgrade_notice = $this->upgrade_notice;
750 | }
751 |
752 | return $update;
753 |
754 | }
755 |
756 | }
757 |
758 | endif;
759 |
760 | /**
761 | * Checks for premium support
762 | */
763 | function url_has_ftps_for_item( &$ps_object ) {
764 |
765 | if ( is_object( $ps_object ) && $ps_object->ps_status ) {
766 | return true;
767 | }
768 |
769 | return false;
770 |
771 | }
772 |
773 | /**
774 | * Return paypal button
775 | */
776 | function get_ftps_paypal_button( &$ps_object ) {
777 |
778 | if ( is_object( $ps_object ) && isset( $ps_object->paypal_button ) ) {
779 | return $ps_object->paypal_button;
780 | }
781 |
782 | return false;
783 | }
784 |
785 | /**
786 | * Return learn more link
787 | */
788 | function get_ftps_learn_more_link( &$ps_object ) {
789 |
790 | if ( is_object( $ps_object ) && isset( $ps_object->learn_more_link ) ) {
791 | return $ps_object->learn_more_link;
792 | }
793 |
794 | return false;
795 | }
796 |
797 | /**
798 | * Return SSO key
799 | */
800 | function get_ftps_sso_key( &$ps_object ) {
801 |
802 | if ( is_object( $ps_object ) && isset( $ps_object->sso_status ) ) {
803 | return $ps_object->sso_status;
804 | }
805 |
806 | return false;
807 | }
808 |
809 | /**
810 | * Return this site URL that has premium support
811 | */
812 | function get_ftps_site( &$ps_object ) {
813 |
814 | if ( is_object( $ps_object ) && isset( $ps_object->ps_status->site ) ) {
815 | return $ps_object->ps_status->site;
816 | }
817 |
818 | return false;
819 | }
820 |
821 | /**
822 | * Return purchase date
823 | */
824 | function get_ftps_purchase_date( &$ps_object ) {
825 |
826 | if ( is_object( $ps_object ) && isset( $ps_object->ps_status->purchase_date ) ) {
827 | return $ps_object->ps_status->purchase_date;
828 | }
829 |
830 | return false;
831 | }
832 |
833 | /**
834 | * Return expiration date
835 | */
836 | function get_ftps_exp_date( &$ps_object ) {
837 |
838 | if ( is_object( $ps_object ) && isset( $ps_object->ps_status->exp_date ) ) {
839 | return $ps_object->ps_status->exp_date;
840 | }
841 |
842 | return false;
843 | }
844 |
845 | /**
846 | * Return email of person who purchased premium support
847 | */
848 | function get_ftps_email( &$ps_object ) {
849 |
850 | if ( is_object( $ps_object ) && isset( $ps_object->ps_status->email ) ) {
851 | return $ps_object->ps_status->email;
852 | }
853 |
854 | return false;
855 | }
856 |
857 | /**
858 | * Return name of person who purchased premium support
859 | */
860 | function get_ftps_name( &$ps_object ) {
861 |
862 | if ( is_object( $ps_object ) && isset( $ps_object->ps_status->name ) ) {
863 | return $ps_object->ps_status->name;
864 | }
865 |
866 | return false;
867 | }
868 |
--------------------------------------------------------------------------------
/classes/parsecsv.lib.php:
--------------------------------------------------------------------------------
1 | data);
35 | ----------------
36 | # tab delimited, and encoding conversion
37 | $csv = new parseCSV();
38 | $csv->encoding('UTF-16', 'UTF-8');
39 | $csv->delimiter = "\t";
40 | $csv->parse('data.tsv');
41 | print_r($csv->data);
42 | ----------------
43 | # auto-detect delimiter character
44 | $csv = new parseCSV();
45 | $csv->auto('data.csv');
46 | print_r($csv->data);
47 | ----------------
48 | # modify data in a csv file
49 | $csv = new parseCSV();
50 | $csv->sort_by = 'id';
51 | $csv->parse('data.csv');
52 | # "4" is the value of the "id" column of the CSV row
53 | $csv->data[4] = array('firstname' => 'John', 'lastname' => 'Doe', 'email' => 'john@doe.com');
54 | $csv->save();
55 | ----------------
56 | # add row/entry to end of CSV file
57 | # - only recommended when you know the extact sctructure of the file
58 | $csv = new parseCSV();
59 | $csv->save('data.csv', array(array('1986', 'Home', 'Nowhere', '')), true);
60 | ----------------
61 | # convert 2D array to csv data and send headers
62 | # to browser to treat output as a file and download it
63 | $csv = new parseCSV();
64 | $csv->output('movies.csv', $array, array('field 1', 'field 2'), ',');
65 | ----------------
66 | */
67 | /**
68 | * Configuration
69 | * - set these options with $object->var_name = 'value';
70 | */
71 | /**
72 | * Heading
73 | * Use first line/entry as field names
74 | *
75 | * @access public
76 | * @var bool
77 | */
78 | public $heading = true;
79 | /**
80 | * Fields
81 | * Override field names
82 | *
83 | * @access public
84 | * @var array
85 | */
86 | public $fields = array();
87 | /**
88 | * Sort By
89 | * Sort csv by this field
90 | *
91 | * @access public
92 | * @var string
93 | */
94 | public $sort_by = null;
95 | /**
96 | * Sort Reverse
97 | * Reverse the sort function
98 | *
99 | * @access public
100 | * @var bool
101 | */
102 | public $sort_reverse = false;
103 | /**
104 | * Sort Type
105 | * Sort behavior passed to sort methods
106 | *
107 | * regular = SORT_REGULAR
108 | * numeric = SORT_NUMERIC
109 | * string = SORT_STRING
110 | *
111 | * @access public
112 | * @var string
113 | */
114 | public $sort_type = null;
115 | /**
116 | * Delimiter
117 | * Delimiter character
118 | *
119 | * @access public
120 | * @var string
121 | */
122 | public $delimiter = ',';
123 | /**
124 | * Enclosure
125 | * Enclosure character
126 | *
127 | * @access public
128 | * @var string
129 | */
130 | public $enclosure = '"';
131 | /**
132 | * Enclose All
133 | * Force enclosing all columns
134 | *
135 | * @access public
136 | * @var bool
137 | */
138 | public $enclose_all = false;
139 | /**
140 | * Conditions
141 | * Basic SQL-Like conditions for row matching
142 | *
143 | * @access public
144 | * @var string
145 | */
146 | public $conditions = null;
147 | /**
148 | * Offset
149 | * Number of rows to ignore from beginning of data
150 | *
151 | * @access public
152 | * @var int
153 | */
154 | public $offset = null;
155 | /**
156 | * Limit
157 | * Limits the number of returned rows to the specified amount
158 | *
159 | * @access public
160 | * @var int
161 | */
162 | public $limit = null;
163 | /**
164 | * Auto Depth
165 | * Number of rows to analyze when attempting to auto-detect delimiter
166 | *
167 | * @access public
168 | * @var int
169 | */
170 | public $auto_depth = 15;
171 | /**
172 | * Auto Non Charts
173 | * Characters that should be ignored when attempting to auto-detect delimiter
174 | *
175 | * @access public
176 | * @var string
177 | */
178 | public $auto_non_chars = "a-zA-Z0-9\n\r";
179 | /**
180 | * Auto Preferred
181 | * preferred delimiter characters, only used when all filtering method
182 | * returns multiple possible delimiters (happens very rarely)
183 | *
184 | * @access public
185 | * @var string
186 | */
187 | public $auto_preferred = ",;\t.:|";
188 | /**
189 | * Convert Encoding
190 | * Should we convert the csv encoding?
191 | *
192 | * @access public
193 | * @var bool
194 | */
195 | public $convert_encoding = false;
196 | /**
197 | * Input Encoding
198 | * Set the input encoding
199 | *
200 | * @access public
201 | * @var string
202 | */
203 | public $input_encoding = 'ISO-8859-1';
204 | /**
205 | * Output Encoding
206 | * Set the output encoding
207 | *
208 | * @access public
209 | * @var string
210 | */
211 | public $output_encoding = 'ISO-8859-1';
212 | /**
213 | * Linefeed
214 | * Line feed characters used by unparse, save, and output methods
215 | *
216 | * @access public
217 | * @var string
218 | */
219 | public $linefeed = "\r";
220 | /**
221 | * Output Delimiter
222 | * Sets the output delimiter used by the output method
223 | *
224 | * @access public
225 | * @var string
226 | */
227 | public $output_delimiter = ',';
228 | /**
229 | * Output filename
230 | * Sets the output filename
231 | *
232 | * @access public
233 | * @var string
234 | */
235 | public $output_filename = 'data.csv';
236 | /**
237 | * Keep File Data
238 | * keep raw file data in memory after successful parsing (useful for debugging)
239 | *
240 | * @access public
241 | * @var bool
242 | */
243 | public $keep_file_data = false;
244 | /**
245 | * Internal variables
246 | */
247 | /**
248 | * File
249 | * Current Filename
250 | *
251 | * @access public
252 | * @var string
253 | */
254 | public $file;
255 | /**
256 | * File Data
257 | * Current file data
258 | *
259 | * @access public
260 | * @var string
261 | */
262 | public $file_data;
263 | /**
264 | * Error
265 | * Contains the error code if one occured
266 | *
267 | * 0 = No errors found. Everything should be fine :)
268 | * 1 = Hopefully correctable syntax error was found.
269 | * 2 = Enclosure character (double quote by default)
270 | * was found in non-enclosed field. This means
271 | * the file is either corrupt, or does not
272 | * standard CSV formatting. Please validate
273 | * the parsed data yourself.
274 | *
275 | * @access public
276 | * @var int
277 | */
278 | public $error = 0;
279 | /**
280 | * Error Information
281 | * Detailed error information
282 | *
283 | * @access public
284 | * @var array
285 | */
286 | public $error_info = array();
287 | /**
288 | * Titles
289 | * CSV titles if they exists
290 | *
291 | * @access public
292 | * @var array
293 | */
294 | public $titles = array();
295 | /**
296 | * Data
297 | * Two dimensional array of CSV data
298 | *
299 | * @access public
300 | * @var array
301 | */
302 | public $data = array();
303 | /**
304 | * Constructor
305 | * Class constructor
306 | *
307 | * @access public
308 | * @param [string] input The CSV string or a direct filepath
309 | * @param [integer] offset Number of rows to ignore from the beginning of the data
310 | * @param [integer] limit Limits the number of returned rows to specified amount
311 | * @param [string] conditions Basic SQL-like conditions for row matching
312 | */
313 | public function __construct($input = null, $offset = null, $limit = null, $conditions = null, $keep_file_data = null) {
314 | if (!is_null($offset)) {
315 | $this->offset = $offset;
316 | }
317 | if (!is_null($limit)) {
318 | $this->limit = $limit;
319 | }
320 | if (!is_null($conditions)) {
321 | $this->conditions = $conditions;
322 | }
323 | if (!is_null($keep_file_data)) {
324 | $this->keep_file_data = $keep_file_data;
325 | }
326 | if (!empty($input)) {
327 | $this->parse($input);
328 | }
329 | }
330 | // ==============================================
331 | // ----- [ Main Functions ] ---------------------
332 | // ==============================================
333 | /**
334 | * Parse
335 | * Parse a CSV file or string
336 | *
337 | * @access public
338 | * @param [string] input The CSV string or a direct filepath
339 | * @param [integer] offset Number of rows to ignore from the beginning of the data
340 | * @param [integer] limit Limits the number of returned rows to specified amount
341 | * @param [string] conditions Basic SQL-like conditions for row matching
342 | *
343 | * @return [bool]
344 | */
345 | public function parse($input = null, $offset = null, $limit = null, $conditions = null) {
346 | if (is_null($input)) {
347 | $input = $this->file;
348 | }
349 | if (!empty($input)) {
350 | if (!is_null($offset)) {
351 | $this->offset = $offset;
352 | }
353 | if (!is_null($limit)) {
354 | $this->limit = $limit;
355 | }
356 | if (!is_null($conditions)) {
357 | $this->conditions = $conditions;
358 | }
359 | if (is_readable($input)) {
360 | $this->data = $this->parse_file($input);
361 | } else {
362 | $this->file_data = &$input;
363 | $this->data = $this->parse_string();
364 | }
365 | if ($this->data === false) {
366 | return false;
367 | }
368 | }
369 | return true;
370 | }
371 | /**
372 | * Save
373 | * Save changes, or write a new file and/or data
374 | *
375 | * @access public
376 | * @param [string] $file File location to save to
377 | * @param [array] $data 2D array of data
378 | * @param [bool] $append Append current data to end of target CSV, if file exists
379 | * @param [array] $fields Field names
380 | *
381 | * @return [bool]
382 | */
383 | public function save($file = null, $data = array(), $append = false, $fields = array()) {
384 | if (empty($file)) {
385 | $file = &$this->file;
386 | }
387 | $mode = ($append) ? 'at' : 'wt';
388 | $is_php = (preg_match('/\.php$/i', $file)) ? true : false;
389 | return $this->_wfile($file, $this->unparse($data, $fields, $append, $is_php), $mode);
390 | }
391 | /**
392 | * Output
393 | * Generate a CSV based string for output.
394 | *
395 | * @access public
396 | * @param [string] $filename If specified, headers and data will be output directly to browser as a downloable file
397 | * @param [array] $data 2D array with data
398 | * @param [array] $fields Field names
399 | * @param [type] $delimiter delimiter used to separate data
400 | *
401 | * @return [string]
402 | */
403 | public function output($filename = null, $data = array(), $fields = array(), $delimiter = null) {
404 | if (empty($filename)) {
405 | $filename = $this->output_filename;
406 | }
407 | if ($delimiter === null) {
408 | $delimiter = $this->output_delimiter;
409 | }
410 | $data = $this->unparse($data, $fields, null, null, $delimiter);
411 | if (!is_null($filename)) {
412 | header('Content-type: application/csv');
413 | header('Content-Length: ' . strlen($data));
414 | header('Cache-Control: no-cache, must-revalidate');
415 | header('Pragma: no-cache');
416 | header('Expires: 0');
417 | header('Content-Disposition: attachment; filename="' . $filename . '"; modification-date="' . date('r') . '";');
418 | echo $data;
419 | }
420 | return $data;
421 | }
422 | /**
423 | * Encoding
424 | * Convert character encoding
425 | *
426 | * @access public
427 | * @param [string] $input Input character encoding, uses default if left blank
428 | * @param [string] $output Output character encoding, uses default if left blank
429 | */
430 | public function encoding($input = null, $output = null) {
431 | $this->convert_encoding = true;
432 | if (!is_null($input)) {
433 | $this->input_encoding = $input;
434 | }
435 | if (!is_null($output)) {
436 | $this->output_encoding = $output;
437 | }
438 | }
439 | /**
440 | * Auto
441 | * Auto-Detect Delimiter: Find delimiter by analyzing a specific number of
442 | * rows to determine most probable delimiter character
443 | *
444 | * @access public
445 | * @param [string] $file Local CSV file
446 | * @param [bool] $parse True/false parse file directly
447 | * @param [int] $search_depth Number of rows to analyze
448 | * @param [string] $preferred Preferred delimiter characters
449 | * @param [string] $enclosure Enclosure character, default is double quote (").
450 | *
451 | * @return [string]
452 | */
453 | public function auto($file = null, $parse = true, $search_depth = null, $preferred = null, $enclosure = null) {
454 | if (is_null($file)) {
455 | $file = $this->file;
456 | }
457 | if (empty($search_depth)) {
458 | $search_depth = $this->auto_depth;
459 | }
460 | if (is_null($enclosure)) {
461 | $enclosure = $this->enclosure;
462 | }
463 | if (is_null($preferred)) {
464 | $preferred = $this->auto_preferred;
465 | }
466 | if (empty($this->file_data)) {
467 | if ($this->_check_data($file)) {
468 | $data = &$this->file_data;
469 | } else {
470 | return false;
471 | }
472 | } else {
473 | $data = &$this->file_data;
474 | }
475 | $chars = array();
476 | $strlen = strlen($data);
477 | $enclosed = false;
478 | $n = 1;
479 | $to_end = true;
480 | // walk specific depth finding posssible delimiter characters
481 | for ($i = 0; $i < $strlen; $i++) {
482 | $ch = $data{$i};
483 | $nch = (isset($data{$i + 1})) ? $data{$i + 1} : false;
484 | $pch = (isset($data{$i - 1})) ? $data{$i - 1} : false;
485 | // open and closing quotes
486 | if ($ch == $enclosure) {
487 | if (!$enclosed || $nch != $enclosure) {
488 | $enclosed = ($enclosed) ? false : true;
489 | } elseif ($enclosed) {
490 | $i++;
491 | }
492 | // end of row
493 | } elseif (($ch == "\n" && $pch != "\r" || $ch == "\r") && !$enclosed) {
494 | if ($n >= $search_depth) {
495 | $strlen = 0;
496 | $to_end = false;
497 | } else {
498 | $n++;
499 | }
500 | // count character
501 | } elseif (!$enclosed) {
502 | if (!preg_match('/[' . preg_quote($this->auto_non_chars, '/') . ']/i', $ch)) {
503 | if (!isset($chars[$ch][$n])) {
504 | $chars[$ch][$n] = 1;
505 | } else {
506 | $chars[$ch][$n]++;
507 | }
508 | }
509 | }
510 | }
511 | // filtering
512 | $depth = ($to_end) ? $n - 1 : $n;
513 | $filtered = array();
514 | foreach ($chars as $char => $value) {
515 | if ($match = $this->_check_count($char, $value, $depth, $preferred)) {
516 | $filtered[$match] = $char;
517 | }
518 | }
519 | // capture most probable delimiter
520 | ksort($filtered);
521 | $this->delimiter = reset($filtered);
522 | // parse data
523 | if ($parse) {
524 | $this->data = $this->parse_string();
525 | }
526 | return $this->delimiter;
527 | }
528 | // ==============================================
529 | // ----- [ Core Functions ] ---------------------
530 | // ==============================================
531 | /**
532 | * Parse File
533 | * Read file to string and call parse_string()
534 | *
535 | * @access public
536 | *
537 | * @param [string] $file Local CSV file
538 | *
539 | * @return [array|bool]
540 | */
541 | public function parse_file($file = null) {
542 | if (is_null($file)) {
543 | $file = $this->file;
544 | }
545 | if (empty($this->file_data)) {
546 | $this->load_data($file);
547 | }
548 | return (!empty($this->file_data)) ? $this->parse_string() : false;
549 | }
550 | /**
551 | * Parse CSV strings to arrays
552 | *
553 | * @access public
554 | * @param data CSV string
555 | *
556 | * @return 2D array with CSV data, or false on failure
557 | */
558 | public function parse_string($data = null) {
559 | if (empty($data)) {
560 | if ($this->_check_data()) {
561 | $data = &$this->file_data;
562 | } else {
563 | return false;
564 | }
565 | }
566 | $white_spaces = str_replace($this->delimiter, '', " \t\x0B\0");
567 | $rows = array();
568 | $row = array();
569 | $row_count = 0;
570 | $current = '';
571 | $head = (!empty($this->fields)) ? $this->fields : array();
572 | $col = 0;
573 | $enclosed = false;
574 | $was_enclosed = false;
575 | $strlen = strlen($data);
576 | // force the parser to process end of data as a character (false) when
577 | // data does not end with a line feed or carriage return character.
578 | $lch = $data{$strlen - 1};
579 | if ($lch != "\n" && $lch != "\r") {
580 | $strlen++;
581 | }
582 | // walk through each character
583 | for ($i = 0; $i < $strlen; $i++) {
584 | $ch = (isset($data{$i})) ? $data{$i} : false;
585 | $nch = (isset($data{$i + 1})) ? $data{$i + 1} : false;
586 | $pch = (isset($data{$i - 1})) ? $data{$i - 1} : false;
587 | // open/close quotes, and inline quotes
588 | if ($ch == $this->enclosure) {
589 | if (!$enclosed) {
590 | if (ltrim($current, $white_spaces) == '') {
591 | $enclosed = true;
592 | $was_enclosed = true;
593 | } else {
594 | $this->error = 2;
595 | $error_row = count($rows) + 1;
596 | $error_col = $col + 1;
597 | if (!isset($this->error_info[$error_row . '-' . $error_col])) {
598 | $this->error_info[$error_row . '-' . $error_col] = array(
599 | 'type' => 2,
600 | 'info' => 'Syntax error found on row ' . $error_row . '. Non-enclosed fields can not contain double-quotes.',
601 | 'row' => $error_row,
602 | 'field' => $error_col,
603 | 'field_name' => (!empty($head[$col])) ? $head[$col] : null,
604 | );
605 | }
606 | $current .= $ch;
607 | }
608 | } elseif ($nch == $this->enclosure) {
609 | $current .= $ch;
610 | $i++;
611 | } elseif ($nch != $this->delimiter && $nch != "\r" && $nch != "\n") {
612 | for ($x = ($i + 1);isset($data{$x}) && ltrim($data{$x}, $white_spaces) == ''; $x++) {}
613 | if ($data{$x} == $this->delimiter) {
614 | $enclosed = false;
615 | $i = $x;
616 | } else {
617 | if ($this->error < 1) {
618 | $this->error = 1;
619 | }
620 | $error_row = count($rows) + 1;
621 | $error_col = $col + 1;
622 | if (!isset($this->error_info[$error_row . '-' . $error_col])) {
623 | $this->error_info[$error_row . '-' . $error_col] = array(
624 | 'type' => 1,
625 | 'info' =>
626 | 'Syntax error found on row ' . (count($rows) + 1) . '. ' .
627 | 'A single double-quote was found within an enclosed string. ' .
628 | 'Enclosed double-quotes must be escaped with a second double-quote.',
629 | 'row' => count($rows) + 1,
630 | 'field' => $col + 1,
631 | 'field_name' => (!empty($head[$col])) ? $head[$col] : null,
632 | );
633 | }
634 | $current .= $ch;
635 | $enclosed = false;
636 | }
637 | } else {
638 | $enclosed = false;
639 | }
640 | // end of field/row/csv
641 | } elseif (($ch == $this->delimiter || $ch == "\n" || $ch == "\r" || $ch === false) && !$enclosed) {
642 | $key = (!empty($head[$col])) ? $head[$col] : $col;
643 | $row[$key] = ($was_enclosed) ? $current : trim($current);
644 | $current = '';
645 | $was_enclosed = false;
646 | $col++;
647 | // end of row
648 | if ($ch == "\n" || $ch == "\r" || $ch === false) {
649 | if ($this->_validate_offset($row_count) && $this->_validate_row_conditions($row, $this->conditions)) {
650 | if ($this->heading && empty($head)) {
651 | $head = $row;
652 | } elseif (empty($this->fields) || (!empty($this->fields) && (($this->heading && $row_count > 0) || !$this->heading))) {
653 | if (!empty($this->sort_by) && !empty($row[$this->sort_by])) {
654 | if (isset($rows[$row[$this->sort_by]])) {
655 | $rows[$row[$this->sort_by] . '_0'] = &$rows[$row[$this->sort_by]];
656 | unset($rows[$row[$this->sort_by]]);
657 | for ($sn = 1;isset($rows[$row[$this->sort_by] . '_' . $sn]); $sn++) {}
658 | $rows[$row[$this->sort_by] . '_' . $sn] = $row;
659 | } else {
660 | $rows[$row[$this->sort_by]] = $row;
661 | }
662 | } else {
663 | $rows[] = $row;
664 | }
665 | }
666 | }
667 | $row = array();
668 | $col = 0;
669 | $row_count++;
670 | if ($this->sort_by === null && $this->limit !== null && count($rows) == $this->limit) {
671 | $i = $strlen;
672 | }
673 | if ($ch == "\r" && $nch == "\n") {
674 | $i++;
675 | }
676 | }
677 | // append character to current field
678 | } else {
679 | $current .= $ch;
680 | }
681 | }
682 | $this->titles = $head;
683 | if (!empty($this->sort_by)) {
684 | $sort_type = SORT_REGULAR;
685 | if ($this->sort_type == 'numeric') {
686 | $sort_type = SORT_NUMERIC;
687 | } elseif ($this->sort_type == 'string') {
688 | $sort_type = SORT_STRING;
689 | }
690 | ($this->sort_reverse) ? krsort($rows, $sort_type) : ksort($rows, $sort_type);
691 | if ($this->offset !== null || $this->limit !== null) {
692 | $rows = array_slice($rows, ($this->offset === null ? 0 : $this->offset), $this->limit, true);
693 | }
694 | }
695 | if (!$this->keep_file_data) {
696 | $this->file_data = null;
697 | }
698 | return $rows;
699 | }
700 | /**
701 | * Create CSV data from array
702 | *
703 | * @access public
704 | * @param data 2D array with data
705 | * @param fields field names
706 | * @param append if true, field names will not be output
707 | * @param is_php if a php die() call should be put on the first
708 | * line of the file, this is later ignored when read.
709 | * @param delimiter field delimiter to use
710 | *
711 | * @return CSV data (text string)
712 | */
713 | public function unparse($data = array(), $fields = array(), $append = false, $is_php = false, $delimiter = null) {
714 | if (!is_array($data) || empty($data)) {
715 | $data = &$this->data;
716 | }
717 | if (!is_array($fields) || empty($fields)) {
718 | $fields = &$this->titles;
719 | }
720 | if ($delimiter === null) {
721 | $delimiter = $this->delimiter;
722 | }
723 | $string = ($is_php) ? "" . $this->linefeed : '';
724 | $entry = array();
725 | // create heading
726 | if ($this->heading && !$append && !empty($fields)) {
727 | foreach ($fields as $key => $value) {
728 | $entry[] = $this->_enclose_value($value, $delimiter);
729 | }
730 | $string .= implode($delimiter, $entry) . $this->linefeed;
731 | $entry = array();
732 | }
733 | // create data
734 | foreach ($data as $key => $row) {
735 | foreach ($row as $field => $value) {
736 | $entry[] = $this->_enclose_value($value, $delimiter);
737 | }
738 | $string .= implode($delimiter, $entry) . $this->linefeed;
739 | $entry = array();
740 | }
741 | if ($this->convert_encoding) {
742 | $string = iconv($this->input_encoding, $this->output_encoding, $string);
743 | }
744 | return $string;
745 | }
746 | /**
747 | * Load local file or string
748 | *
749 | * @access public
750 | * @param input local CSV file
751 | *
752 | * @return true or false
753 | */
754 | public function load_data($input = null) {
755 | $data = null;
756 | $file = null;
757 | if (is_null($input)) {
758 | $file = $this->file;
759 | } elseif (file_exists($input)) {
760 | $file = $input;
761 | } else {
762 | $data = $input;
763 | }
764 | if (!empty($data) || $data = $this->_rfile($file)) {
765 | if ($this->file != $file) {
766 | $this->file = $file;
767 | }
768 | if (preg_match('/\.php$/i', $file) && preg_match('/<\?.*?\?>(.*)/ims', $data, $strip)) {
769 | $data = ltrim($strip[1]);
770 | }
771 | if ($this->convert_encoding) {
772 | $data = iconv($this->input_encoding, $this->output_encoding, $data);
773 | }
774 | if (substr($data, -1) != "\n") {
775 | $data .= "\n";
776 | }
777 | $this->file_data = &$data;
778 | return true;
779 | }
780 | return false;
781 | }
782 | // ==============================================
783 | // ----- [ Internal Functions ] -----------------
784 | // ==============================================
785 | /**
786 | * Validate a row against specified conditions
787 | *
788 | * @access protected
789 | * @param row array with values from a row
790 | * @param conditions specified conditions that the row must match
791 | *
792 | * @return true of false
793 | */
794 | protected function _validate_row_conditions($row = array(), $conditions = null) {
795 | if (!empty($row)) {
796 | if (!empty($conditions)) {
797 | $conditions = (strpos($conditions, ' OR ') !== false) ? explode(' OR ', $conditions) : array($conditions);
798 | $or = '';
799 | foreach ($conditions as $key => $value) {
800 | if (strpos($value, ' AND ') !== false) {
801 | $value = explode(' AND ', $value);
802 | $and = '';
803 | foreach ($value as $k => $v) {
804 | $and .= $this->_validate_row_condition($row, $v);
805 | }
806 | $or .= (strpos($and, '0') !== false) ? '0' : '1';
807 | } else {
808 | $or .= $this->_validate_row_condition($row, $value);
809 | }
810 | }
811 | return (strpos($or, '1') !== false) ? true : false;
812 | }
813 | return true;
814 | }
815 | return false;
816 | }
817 | /**
818 | * Validate a row against a single condition
819 | *
820 | * @access protected
821 | * @param row array with values from a row
822 | * @param condition specified condition that the row must match
823 | *
824 | * @return true of false
825 | */
826 | protected function _validate_row_condition($row, $condition) {
827 | $operators = array(
828 | '=', 'equals', 'is',
829 | '!=', 'is not',
830 | '<', 'is less than',
831 | '>', 'is greater than',
832 | '<=', 'is less than or equals',
833 | '>=', 'is greater than or equals',
834 | 'contains',
835 | 'does not contain',
836 | );
837 | $operators_regex = array();
838 | foreach ($operators as $value) {
839 | $operators_regex[] = preg_quote($value, '/');
840 | }
841 | $operators_regex = implode('|', $operators_regex);
842 | if (preg_match('/^(.+) (' . $operators_regex . ') (.+)$/i', trim($condition), $capture)) {
843 | $field = $capture[1];
844 | $op = $capture[2];
845 | $value = $capture[3];
846 | if (preg_match('/^([\'\"]{1})(.*)([\'\"]{1})$/i', $value, $capture)) {
847 | if ($capture[1] == $capture[3]) {
848 | $value = $capture[2];
849 | $value = str_replace("\\n", "\n", $value);
850 | $value = str_replace("\\r", "\r", $value);
851 | $value = str_replace("\\t", "\t", $value);
852 | $value = stripslashes($value);
853 | }
854 | }
855 | if (array_key_exists($field, $row)) {
856 | if (($op == '=' || $op == 'equals' || $op == 'is') && $row[$field] == $value) {
857 | return '1';
858 | } elseif (($op == '!=' || $op == 'is not') && $row[$field] != $value) {
859 | return '1';
860 | } elseif (($op == '<' || $op == 'is less than') && $row[$field] < $value) {
861 | return '1';
862 | } elseif (($op == '>' || $op == 'is greater than') && $row[$field] > $value) {
863 | return '1';
864 | } elseif (($op == '<=' || $op == 'is less than or equals') && $row[$field] <= $value) {
865 | return '1';
866 | } elseif (($op == '>=' || $op == 'is greater than or equals') && $row[$field] >= $value) {
867 | return '1';
868 | } elseif ($op == 'contains' && preg_match('/' . preg_quote($value, '/') . '/i', $row[$field])) {
869 | return '1';
870 | } elseif ($op == 'does not contain' && !preg_match('/' . preg_quote($value, '/') . '/i', $row[$field])) {
871 | return '1';
872 | } else {
873 | return '0';
874 | }
875 | }
876 | }
877 | return '1';
878 | }
879 | /**
880 | * Validates if the row is within the offset or not if sorting is disabled
881 | *
882 | * @access protected
883 | * @param current_row the current row number being processed
884 | *
885 | * @return true of false
886 | */
887 | protected function _validate_offset($current_row) {
888 | if ($this->sort_by === null && $this->offset !== null && $current_row < $this->offset) {
889 | return false;
890 | }
891 | return true;
892 | }
893 | /**
894 | * Enclose values if needed
895 | * - only used by unparse()
896 | *
897 | * @access protected
898 | * @param value string to process
899 | *
900 | * @return Processed value
901 | */
902 | protected function _enclose_value($value = null, $delimiter = null) {
903 | if (is_null($delimiter)) {
904 | $delimiter = $this->delimiter;
905 | }
906 | if ($value !== null && $value != '') {
907 | $delimiter_quoted = preg_quote($delimiter, '/');
908 | $enclosure_quoted = preg_quote($this->enclosure, '/');
909 | if (preg_match("/" . $delimiter_quoted . "|" . $enclosure_quoted . "|\n|\r/i", $value) || ($value{0} == ' ' || substr($value, -1) == ' ') || $this->enclose_all) {
910 | $value = str_replace($this->enclosure, $this->enclosure . $this->enclosure, $value);
911 | $value = $this->enclosure . $value . $this->enclosure;
912 | }
913 | }
914 | return $value;
915 | }
916 | /**
917 | * Check file data
918 | *
919 | * @access protected
920 | * @param file local filename
921 | *
922 | * @return true or false
923 | */
924 | protected function _check_data($file = null) {
925 | if (empty($this->file_data)) {
926 | if (is_null($file)) {
927 | $file = $this->file;
928 | }
929 | return $this->load_data($file);
930 | }
931 | return true;
932 | }
933 | /**
934 | * Check if passed info might be delimiter
935 | * Only used by find_delimiter
936 | *
937 | * @access protected
938 | * @param [type] $char [description]
939 | * @param [type] $array [description]
940 | * @param [type] $depth [description]
941 | * @param [type] $preferred [description]
942 | *
943 | * @return special string used for delimiter selection, or false
944 | */
945 | protected function _check_count($char, $array, $depth, $preferred) {
946 | if ($depth == count($array)) {
947 | $first = null;
948 | $equal = null;
949 | $almost = false;
950 | foreach ($array as $key => $value) {
951 | if ($first == null) {
952 | $first = $value;
953 | } elseif ($value == $first && $equal !== false) {
954 | $equal = true;
955 | } elseif ($value == $first + 1 && $equal !== false) {
956 | $equal = true;
957 | $almost = true;
958 | } else {
959 | $equal = false;
960 | }
961 | }
962 | if ($equal) {
963 | $match = ($almost) ? 2 : 1;
964 | $pref = strpos($preferred, $char);
965 | $pref = ($pref !== false) ? str_pad($pref, 3, '0', STR_PAD_LEFT) : '999';
966 | return $pref . $match . '.' . (99999 - str_pad($first, 5, '0', STR_PAD_LEFT));
967 | } else {
968 | return false;
969 | }
970 | }
971 | }
972 | /**
973 | * Read local file
974 | *
975 | * @access protected
976 | * @param file local filename
977 | *
978 | * @return Data from file, or false on failure
979 | */
980 | protected function _rfile($file = null) {
981 | if (is_readable($file)) {
982 | if (!($fh = fopen($file, 'r'))) {
983 | return false;
984 | }
985 | $data = fread($fh, filesize($file));
986 | fclose($fh);
987 | return $data;
988 | }
989 | return false;
990 | }
991 | /**
992 | * Write to local file
993 | *
994 | * @access protected
995 | * @param file local filename
996 | * @param string data to write to file
997 | * @param mode fopen() mode
998 | * @param lock flock() mode
999 | *
1000 | * @return true or false
1001 | */
1002 | protected function _wfile($file, $string = '', $mode = 'wb', $lock = 2) {
1003 | if ($fp = fopen($file, $mode)) {
1004 | flock($fp, $lock);
1005 | $re = fwrite($fp, $string);
1006 | $re2 = fclose($fp);
1007 | if ($re != false && $re2 != false) {
1008 | return true;
1009 | }
1010 | }
1011 | return false;
1012 | }
1013 | }
1014 |
--------------------------------------------------------------------------------
/GNU-GPL.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
--------------------------------------------------------------------------------