├── 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 | * 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 = "
"; 110 | $return .= "
[sm-location data='iframe-map']
"; 111 | $return .= "
[sm-location data='full-address']
"; 112 | $return .= "
"; 113 | $return .= ""; 114 | $return .= "
"; 115 | $return .= "
"; 116 | $return .= "
"; 117 | $return .= "[sm-location data='description']"; 118 | 119 | return apply_filters( 'sm-single-location-default-template', $return ); 120 | 121 | } 122 | 123 | return $return; 124 | } 125 | 126 | /** 127 | * This method applies the template to the content 128 | * 129 | * @since 2.4 130 | */ 131 | function apply_template( $content ) { 132 | 133 | // Return content untouched if not location data 134 | if ( ! $this->template_type || ! $this->template_structure ) { 135 | return $content; 136 | } 137 | 138 | // Return if not in the loop 139 | if ( ! in_the_loop() ) { 140 | return $content; 141 | } 142 | 143 | // Save the location 'description' 144 | $location_description = $content; 145 | 146 | // Send it through the shortcode parser 147 | $content = do_shortcode( $this->template_structure ); 148 | 149 | return $content; 150 | 151 | } 152 | 153 | } 154 | 155 | } 156 | -------------------------------------------------------------------------------- /inc/styles/admin.css: -------------------------------------------------------------------------------- 1 | #simplemap img { 2 | background: none !important; 3 | padding: none !important; 4 | max-width: none !important; 5 | max-height: none !important; 6 | border: none !important; 7 | } 8 | 9 | body.toplevel_page_simplemap-simplemap small, body.simplemap_page_Add-Location small, body.simplemap_page_Manage-Database small, body.simplemap_page_Manage-Categories small, body.simplemap_page_Import-Export small { 10 | color: #777; 11 | } 12 | 13 | select option span.hidden { 14 | display: none !important; 15 | visibility: hidden !important; 16 | } 17 | 18 | .inline-editor { 19 | background: #ffffe0 !important; 20 | } 21 | 22 | .aligncenter { 23 | text-align: center; 24 | } 25 | 26 | .text-red { 27 | color: red; 28 | } 29 | 30 | .button-red { 31 | border-color: #900 !important; 32 | font-weight: bold; 33 | color: #fff !important; 34 | background: #c00 url( ../images/button-red-grad.png ) repeat-x scroll left top; 35 | text-shadow: rgba(0,0,0,0.3) 0 -1px 0; 36 | } 37 | 38 | .button-red:active { 39 | background: #c00 url( ../images/button-red-grad-active.png ) repeat-x scroll left top !important; 40 | } 41 | 42 | span.disabled-text { 43 | font: italic 13px Georgia; 44 | float: right; 45 | color: #555; 46 | } 47 | 48 | span.title, label span.title { 49 | display: inline-block; 50 | width: 5em; 51 | } 52 | 53 | span.title.title_long, label.long span.title.title_long { 54 | width: 10em; 55 | } 56 | 57 | input.fix_width, select.fix_width, textarea.fix_width { 58 | width: 180px; 59 | } 60 | 61 | input.full_width, select.full_width, textarea.full_width { 62 | width: 70%; 63 | } 64 | 65 | .disabled { 66 | color: #999; 67 | } 68 | 69 | span.hidden { 70 | display: none; 71 | } 72 | 73 | span#ala { 74 | padding-left: 10px; 75 | } 76 | 77 | .postbox .sub { 78 | color: rgb(119, 119, 119); 79 | font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; 80 | font-size: 13px; 81 | font-style: italic; 82 | padding: 5px 10px 15px; 83 | margin: 0; 84 | } 85 | 86 | .postbox h3 { 87 | cursor: default !important; 88 | } 89 | 90 | .postbox h3.blue-bg { 91 | color: #fff !important; 92 | text-shadow: 0 1px 0 #000; 93 | background: #fff url( ../images/blue-grad.png ) top left repeat-x; 94 | } 95 | 96 | .postbox .inside.padding-10 { 97 | padding: 10px; 98 | } 99 | 100 | .postbox .inside ul { 101 | margin-left: 25px; 102 | list-style-type: disc; 103 | } 104 | 105 | .postbox .inside #taxonomy-sm-category ul { 106 | list-style-type: none; 107 | } 108 | 109 | .postbox .inside code { 110 | font-size: 14px; 111 | } 112 | 113 | form.inabox { 114 | padding: 10px; 115 | background: #ffffe0; 116 | border: 1px solid #e6db55; 117 | -moz-border-radius: 4px; 118 | -khtml-border-radius: 4px; 119 | -webkit-border-radius: 4px; 120 | border-radius: 4px; 121 | } 122 | 123 | form.inabox label { 124 | font-weight: bold; 125 | } 126 | 127 | label.sm-options-label { 128 | width: 70px; 129 | display: inline-block; 130 | } 131 | 132 | .radio-thumbnail { 133 | float: left; 134 | text-align: center; 135 | margin: 1px; 136 | padding: 10px; 137 | } 138 | 139 | .radio-thumbnail:hover { 140 | margin: 0; 141 | background-color: #eaf2fa; 142 | border: 1px solid #93d8e2; 143 | -moz-border-radius: 4px; 144 | -webkit-border-radius: 4px; 145 | -khtml-border-radius: 4px; 146 | border-radius: 4px; 147 | } 148 | 149 | .radio-thumbnail label { 150 | display: block; 151 | } 152 | 153 | .radio-thumbnail img { 154 | border: 1px solid #999; 155 | } 156 | 157 | .radio-thumbnail-current { 158 | margin: 0; 159 | background-color: #ffffe0; 160 | border: 1px solid #e6db55; 161 | -moz-border-radius: 4px; 162 | -webkit-border-radius: 4px; 163 | -khtml-border-radius: 4px; 164 | border-radius: 4px; 165 | } 166 | 167 | table.server-tests { 168 | border-collapse: collapse; 169 | } 170 | 171 | .donate-text { 172 | float: right; 173 | margin-right: 25px; 174 | } 175 | 176 | table.server-tests td { 177 | padding: 2px; 178 | border: 1px solid #999; 179 | font-size: 0.8em; 180 | } 181 | 182 | .sm-toolbar { 183 | width: 97%; 184 | margin-top: 25px; 185 | } 186 | 187 | .sm-toolbar td { 188 | vertical-align: middle; 189 | padding: 0 10px; 190 | } 191 | 192 | .sm-toolbar td.sm-page-title { 193 | vertical-align: top; 194 | } 195 | 196 | .sm-toolbar td.sm-page-title h2 { 197 | margin: 0; 198 | } 199 | 200 | .sm-toolbar-item { 201 | width: 100px; 202 | text-align: center; 203 | -moz-border-radius: 4px; 204 | -webkit-border-radius: 4px; 205 | -khtml-border-radius: 4px; 206 | border-radius: 4px; 207 | border: 1px solid #f9f9f9; 208 | } 209 | 210 | .sm-toolbar-item:hover { 211 | background-color: #eaf2fa; 212 | border-color: #93d8e2; 213 | } 214 | 215 | .sm-toolbar-item a { 216 | text-decoration: none; 217 | font: bold italic 1.1em Georgia; 218 | } 219 | 220 | .sm-toolbar-item form { 221 | margin: 0; 222 | } 223 | 224 | #sm-location-premium-support h3 { 225 | background: #fff url( ../images/blue-grad.png ) top left repeat-x; 226 | color:#fff; 227 | text-shadow:0 1px 0 #000; 228 | } 229 | 230 | #dragdrop_map_canvas { 231 | width: 267px; 232 | height: 200px; 233 | position: relative; 234 | overflow: hidden; 235 | } 236 | 237 | #latlng_updated.updated, 238 | #latlng_dontforget.error { 239 | color: #666666; 240 | font-style: italic; 241 | font-size: 11px; 242 | } 243 | 244 | body.sm-location_page_simplemap-import-export #wpbody-content #dashboard-widgets .postbox-container.half-width { 245 | width: 49%; 246 | } 247 | 248 | body.sm-location_page_simplemap-import-export #wpbody-content #dashboard-widgets .postbox-container.full-width { 249 | width: 100%; 250 | } 251 | body.sm-location_page_simplemap-import-export #dashboard-widgets .postbox .inside.sm-scroll { 252 | overflow: auto; 253 | height: 750px; 254 | } -------------------------------------------------------------------------------- /simplemap.php: -------------------------------------------------------------------------------- 1 | 'http://simplemap-plugin.com', 140 | 'product_id' => 1, 141 | 'product-slug' => 'sm-premium', 142 | 'plugin_support_page_ids' => array( 143 | 'sm-location_page_simplemap-help', 144 | 'sm-location_page_simplemap', 145 | 'sm-location_page_simplemap-import-export', 146 | 'sm-location', 147 | ), 148 | 'plugin_basename' => plugin_basename( SIMPLEMAP_PATH . '/simplemap.php' ), 149 | 'plugin_slug' => 'simplemap', 150 | 'learn_more_link' => 'http://simplemap-plugin.com/premium-support/', 151 | ); 152 | if ( class_exists( 'FT_Premium_Support_Client' ) && ( ! isset( $simplemap_ps ) || ! is_object( $simplemap_ps ) ) ) { 153 | $simplemap_ps = new FT_Premium_Support_Client( $config ); 154 | } 155 | -------------------------------------------------------------------------------- /classes/admin.php: -------------------------------------------------------------------------------- 1 | get_options(); 28 | 29 | if ( empty( $options['api_key'] ) ) { 30 | ?> 31 |
32 |

33 | ' 38 | . __( 'Enter a key on the General Options page.', 39 | 'simplemap' ) 40 | . ''; ?>

41 |
42 | get_options(); 55 | 56 | add_submenu_page( 'edit.php?post_type=sm-location', 57 | __( 'SimpleMap: General Options', 'simplemap' ), 58 | __( 'General Options', 'simplemap' ), 59 | apply_filters( 'sm-admin-permissions-sm-options', 60 | 'manage_options' ), 'simplemap', array( 61 | &$sm_options, 62 | 'print_page', 63 | ) ); 64 | add_submenu_page( 'edit.php?post_type=sm-location', 65 | __( 'SimpleMap: Import / Export CSV', 'simplemap' ), 66 | __( 'Import / Export CSV', 'simplemap' ), 'publish_posts', 67 | 'simplemap-import-export', array( 68 | &$sm_import_export, 69 | 'print_page', 70 | ) ); 71 | add_submenu_page( 'edit.php?post_type=sm-location', 72 | __( 'SimpleMap: Premium Support', 'simplemap' ), 73 | __( 'Premium Support', 'simplemap' ), 'publish_posts', 74 | 'simplemap-help', array( 75 | &$sm_help, 76 | 'print_page', 77 | ) ); 78 | } 79 | 80 | public function load_admin_scripts() { 81 | // Print admin scripts. 82 | global $current_screen; 83 | 84 | // General options page. 85 | if ( 'toplevel_page_simplemap' === $current_screen->id ) : 86 | /** 87 | * TODO: Currently this loads on toplevel_page_simplemap... but that could change once we redo the menus. 88 | */ 89 | ?> 90 | 155 | div { 276 | display: table-row; 277 | } 278 | /* COL */ 279 | div.location_search div > div { 280 | display: table-cell; 281 | padding: 0% 0% 1% 1%; 282 | } 283 | 284 | div.location_search > div div:first-child { 285 | padding-left: 0px; 286 | } 287 | /* 1 cols */ 288 | div.location_search > div div:first-child:nth-last-child(1), 289 | div.location_search > div div:first-child:nth-last-child(1) ~ div { 290 | width: 100%; 291 | } 292 | /* 2 cols */ 293 | div.location_search > div div:first-child:nth-last-child(2), 294 | div.location_search > div div:first-child:nth-last-child(2) ~ div { 295 | width: 49%; 296 | } 297 | /* 3 cols */ 298 | div.location_search > div div:first-child:nth-last-child(3), 299 | div.location_search > div div:first-child:nth-last-child(3) ~ div { 300 | width: 32%; 301 | } 302 | /* 4 cols */ 303 | div.location_search > div div:first-child:nth-last-child(4), 304 | div.location_search > div div:first-child:nth-last-child(4) ~ div { 305 | width: 24%; 306 | } 307 | /* 5 cols */ 308 | div.location_search > div div:first-child:nth-last-child(5), 309 | div.location_search > div div:first-child:nth-last-child(5) ~ div { 310 | width: 19%; 311 | } 312 | /* 6 cols */ 313 | div.location_search > div div:first-child:nth-last-child(6), 314 | div.location_search > div div:first-child:nth-last-child(6) ~ div { 315 | width: 15%; 316 | } 317 | 318 | /*** Responsive styles ***/ 319 | @media screen and (max-width: 800px) { 320 | div.location_search div > div { 321 | float: left; 322 | padding-left: 0%; 323 | width: 100%!important; 324 | } 325 | div.result div.result_address { 326 | width: 100%; 327 | float: none; 328 | } 329 | div.result div.result_phone { 330 | width: 70%; 331 | min-height: 0.1em; 332 | } 333 | div.result div.result_links { 334 | width: 30%; 335 | } 336 | div.result div.result_name { 337 | margin-bottom: 10px; 338 | } 339 | div.result div.result_phone span.result_phone, 340 | div.result div.result_phone span.result_email, 341 | div.result div.result_phone span.result_fax, 342 | div.result div.result_links div.result_website, 343 | div.result div.result_links div.result_directions { 344 | display: block; 345 | margin: 5px 0; 346 | } 347 | div.result div.sm_category_list, 348 | div.result div.sm_tag_list, 349 | div.result div.sm_day_list, 350 | div.result div.sm_time_list { 351 | margin: 5px 0; 352 | } 353 | } 354 | @media screen and (max-width: 480px) { 355 | div.location_search div#location_search_sm-category_fields label, 356 | div.location_search div#location_search_sm-tag_fields label, 357 | div.location_search div#location_search_sm-day_fields label, 358 | div.location_search div#location_search_sm-time_fields label { 359 | display: block; 360 | float: none; 361 | } 362 | div.result div.result_phone, 363 | div.result div.result_links { 364 | width: 100%; 365 | min-height: 0; 366 | float: none; 367 | text-align: left; 368 | } 369 | } -------------------------------------------------------------------------------- /inc/styles/light.css: -------------------------------------------------------------------------------- 1 | /* 2 | Theme Name: Light 3 | */ 4 | 5 | #simplemap { 6 | border: 1px solid #999; 7 | color: #000; 8 | } 9 | 10 | #simplemap img { 11 | background: none !important; 12 | padding: none !important; 13 | max-width: none !important; 14 | max-height: none !important; 15 | border: none !important; 16 | } 17 | 18 | #simplemap a { 19 | color: #00c; 20 | background: none; 21 | text-decoration: none; 22 | } 23 | 24 | #simplemap a:hover { 25 | background: none; 26 | text-decoration: underline; 27 | } 28 | 29 | #powered_by_simplemap { 30 | font-size: 0.75em; 31 | text-align: right; 32 | color: #999; 33 | } 34 | 35 | #powered_by_simplemap a { 36 | color: #999; 37 | text-decoration: underline; 38 | } 39 | 40 | #powered_by_simplemap a:hover { 41 | text-decoration: none; 42 | } 43 | 44 | #searchForm { 45 | text-align: left; 46 | } 47 | 48 | #searchForm input#addressInput { 49 | width: 250px; 50 | } 51 | 52 | #searchForm input#addressSubmit { 53 | width: auto; 54 | } 55 | 56 | #searchForm select { 57 | width: auto; 58 | } 59 | 60 | #searchForm p { 61 | margin: 10px auto; 62 | } 63 | 64 | #map_search label { 65 | float: left; 66 | } 67 | 68 | #map_search .float_text_left { 69 | float: left; 70 | padding-right: 5px; 71 | } 72 | 73 | #simplemap-updating { 74 | display:none; 75 | background:#fff; 76 | color:#000; 77 | vertical-align:middle; 78 | text-align:center; 79 | } 80 | 81 | #simplemap-updating img { 82 | vertical-align:middle; 83 | text-align:center; 84 | } 85 | 86 | .markertext { 87 | font-size: 0.9em; 88 | line-height: 1.2em; 89 | color: #000; 90 | } 91 | 92 | .markertext .bubble_category { 93 | font-size: 0.6em; 94 | font-style: italic; 95 | } 96 | 97 | .markertext a { 98 | color: #00c; 99 | text-decoration: underline; 100 | } 101 | 102 | .markertext h3 { 103 | margin-top: 0 !important; 104 | margin-bottom: 1em !important; 105 | text-align: left !important; 106 | line-height: 1.2em !important; 107 | } 108 | 109 | .markertext p { 110 | margin-bottom: 1em !important; 111 | } 112 | 113 | .markertext .search-term { 114 | background: #ff6; 115 | } 116 | 117 | div#results { 118 | padding-bottom: 20px; 119 | } 120 | 121 | div.result { 122 | margin: 0; 123 | padding: 15px 5px; 124 | font-size: 0.9em; 125 | line-height: 1.2em; 126 | border-bottom: 1px solid #ccc; 127 | } 128 | 129 | div.result small { 130 | font-size: 0.7em; 131 | color: #999; 132 | } 133 | 134 | div.result:hover { 135 | background: #ebf0f1; 136 | } 137 | 138 | div.result address { 139 | font-style: normal; 140 | } 141 | 142 | div.result h3 { 143 | margin: 0 0 5px; 144 | font-size: 1.5em; 145 | text-transform: none; 146 | } 147 | 148 | div.result img { 149 | border: none; 150 | } 151 | 152 | div.result .search-term { 153 | background: #ff6; 154 | color: #000; 155 | } 156 | 157 | div.result div.result_name { 158 | width: 100%; 159 | } 160 | 161 | div.result div.result_address { 162 | float: left; 163 | width: 40%; 164 | } 165 | 166 | div.result div.result_phone { 167 | float: left; 168 | width: 40%; 169 | min-height: 3em; 170 | } 171 | 172 | div.result div.result_links { 173 | float: left; 174 | display: table-cell; 175 | width: 20%; 176 | text-align: right; 177 | vertical-align: bottom; 178 | } 179 | 180 | div.result div.result_links div { 181 | clear: right; 182 | margin-bottom: 3px; 183 | } 184 | 185 | div.result div.special { 186 | float: right; 187 | height: 20px; 188 | margin: 0; 189 | padding-left: 20px; 190 | line-height: 20px; 191 | text-align: left; 192 | font-style: italic; 193 | background: url( ../images/star.png ) no-repeat left center; 194 | } 195 | 196 | .location_search_title, .location_search_distance_cell, .location_search_taxonomy_cell { 197 | font-weight:bold; 198 | vertical-align:top; 199 | } 200 | 201 | .no-linebreak { 202 | white-space:nowrap; 203 | } 204 | 205 | .sm-single-location-default-template { 206 | padding:3px; 207 | } 208 | 209 | .sm-single-map { 210 | position: relative; 211 | padding-bottom: 90%; 212 | height: 0; 213 | overflow: hidden; 214 | } 215 | 216 | .sm-single-map iframe { 217 | position: absolute; 218 | top:0; 219 | left: 0; 220 | width: 100%; 221 | height: 100%; 222 | } 223 | 224 | .sm-single-location-data { 225 | margin-top: 30px; 226 | } 227 | 228 | .sm-single-location-data-ul { 229 | list-style-type:none; 230 | padding-left:0; 231 | margin-left:0; 232 | } 233 | 234 | .infoBox { 235 | background-color: #fff; 236 | } 237 | 238 | .infoBox:after { 239 | position: relative; 240 | top: 20px; 241 | left: 60px; 242 | border-top: 0px; 243 | border-left: 0px; 244 | padding: 0px; 245 | content: ''; 246 | overflow: hidden; 247 | display: block; 248 | width: 0; 249 | height: 0; 250 | border-left: 20px solid rgba(0, 0, 0, 0); 251 | border-right: 20px solid rgba(0, 0, 0, 0); 252 | border-top: 20px solid #FFF; 253 | } 254 | 255 | .infoBox .markertext ul, 256 | .infoBox .markertext ol { 257 | margin-left: 15px; 258 | } 259 | 260 | div.result div.result_phone span.result_phone, 261 | div.result div.result_phone span.result_email, 262 | div.result div.result_phone span.result_fax { 263 | display: block; 264 | } 265 | 266 | div.location_search { 267 | display: table; 268 | width: 100%; 269 | } 270 | /* HEADER */ 271 | div.location_search div:first-child div { 272 | display: table-header-group; 273 | } 274 | /* ROW */ 275 | div.location_search > div { 276 | display: table-row; 277 | } 278 | /* COL */ 279 | div.location_search div > div { 280 | display: table-cell; 281 | padding: 0% 0% 1% 1%; 282 | } 283 | 284 | div.location_search > div div:first-child { 285 | padding-left: 0px; 286 | } 287 | /* 1 cols */ 288 | div.location_search > div div:first-child:nth-last-child(1), 289 | div.location_search > div div:first-child:nth-last-child(1) ~ div { 290 | width: 100%; 291 | } 292 | /* 2 cols */ 293 | div.location_search > div div:first-child:nth-last-child(2), 294 | div.location_search > div div:first-child:nth-last-child(2) ~ div { 295 | width: 49%; 296 | } 297 | /* 3 cols */ 298 | div.location_search > div div:first-child:nth-last-child(3), 299 | div.location_search > div div:first-child:nth-last-child(3) ~ div { 300 | width: 32%; 301 | } 302 | /* 4 cols */ 303 | div.location_search > div div:first-child:nth-last-child(4), 304 | div.location_search > div div:first-child:nth-last-child(4) ~ div { 305 | width: 24%; 306 | } 307 | /* 5 cols */ 308 | div.location_search > div div:first-child:nth-last-child(5), 309 | div.location_search > div div:first-child:nth-last-child(5) ~ div { 310 | width: 19%; 311 | } 312 | /* 6 cols */ 313 | div.location_search > div div:first-child:nth-last-child(6), 314 | div.location_search > div div:first-child:nth-last-child(6) ~ div { 315 | width: 15%; 316 | } 317 | 318 | /*** Responsive styles ***/ 319 | @media screen and (max-width: 800px) { 320 | div.location_search div > div { 321 | float: left; 322 | padding-left: 0%; 323 | width: 100%!important; 324 | } 325 | div.result div.result_address { 326 | width: 100%; 327 | float: none; 328 | } 329 | div.result div.result_phone { 330 | width: 70%; 331 | min-height: 0.1em; 332 | } 333 | div.result div.result_links { 334 | width: 30%; 335 | } 336 | div.result div.result_name { 337 | margin-bottom: 10px; 338 | } 339 | div.result div.result_phone span.result_phone, 340 | div.result div.result_phone span.result_email, 341 | div.result div.result_phone span.result_fax, 342 | div.result div.result_links div.result_website, 343 | div.result div.result_links div.result_directions { 344 | display: block; 345 | margin: 5px 0; 346 | } 347 | div.result div.sm_category_list, 348 | div.result div.sm_tag_list, 349 | div.result div.sm_day_list, 350 | div.result div.sm_time_list { 351 | margin: 5px 0; 352 | } 353 | } 354 | @media screen and (max-width: 480px) { 355 | div.location_search div#location_search_sm-category_fields label, 356 | div.location_search div#location_search_sm-tag_fields label, 357 | div.location_search div#location_search_sm-day_fields label, 358 | div.location_search div#location_search_sm-time_fields label { 359 | display: block; 360 | float: none; 361 | } 362 | div.result div.result_phone, 363 | div.result div.result_links { 364 | width: 100%; 365 | min-height: 0; 366 | float: none; 367 | text-align: left; 368 | } 369 | } -------------------------------------------------------------------------------- /classes/maps.php: -------------------------------------------------------------------------------- 1 | set_map_atts(); 36 | 37 | // Prints the iframe 38 | if ( isset( $_GET['sm_map_iframe'] ) ) { 39 | add_action( 'template_redirect', array( &$this, 'add_iframe_locations' ), 2 ); 40 | add_action( 'template_redirect', array( &$this, 'generate_iframe' ) ); 41 | } 42 | } 43 | 44 | /** 45 | * This loads all the attributes for the map itself 46 | * 47 | * 'default_lat' 48 | * 'default_lng' 49 | * 'zoom_level' 50 | * 'default_radius' 51 | * 'map_type' 52 | * 'special_text' 53 | * 'default_state' 54 | * 'default_country' 55 | * 'default_language' 56 | * 'default_domain' 57 | * 'map_stylesheet' 58 | * 'units' 59 | * 'autoload' 60 | * 'lock_default_location' 61 | * 'results_limit' 62 | * 'address_format' 63 | * 'powered_by' 64 | * 'enable_permalinks' 65 | * 'permalink_slug' 66 | * 'display_search' 67 | * 'map_pages' 68 | * 'adsense_for_maps' 69 | * 'adsense_pub_id' 70 | * 'adsense_channel_id' 71 | * 'adsense_max_ads' 72 | * 73 | * @since 2.4 74 | */ 75 | function set_map_atts( $atts = array() ) { 76 | 77 | global $simple_map; 78 | $locations = ! empty ( $_GET['location_ids'] ) ? explode( ',', $_GET['location_ids'] ) : array(); 79 | 80 | // Do atts for iframes 81 | if ( isset( $_GET['sm_map_iframe'] ) ) { 82 | // Set atts from GET vars 83 | if ( ! empty( $_GET['api_key'] ) ) { 84 | $atts['api_key'] = $_GET['api_key']; 85 | } 86 | if ( ! empty( $_GET['pan_control'] ) ) { 87 | $atts['panControl'] = $_GET['pan_control']; 88 | } 89 | if ( ! empty( $_GET['zoom_control'] ) ) { 90 | $atts['zoomControl'] = $_GET['zoom_control']; 91 | } 92 | if ( ! empty( $_GET['scale_control'] ) ) { 93 | $atts['scaleControl'] = $_GET['scale_control']; 94 | } 95 | if ( ! empty( $_GET['street_view_control'] ) ) { 96 | $atts['streetViewControl'] = $_GET['street_view_control']; 97 | } 98 | if ( ! empty( $_GET['map_type_control'] ) ) { 99 | $atts['mapTypeControl'] = $_GET['map_type_control']; 100 | } 101 | if ( ! empty( $_GET['map_type'] ) ) { 102 | $atts['mapType'] = $_GET['map_type']; 103 | } 104 | if ( empty( $_GET['default_lat'] ) ) { 105 | $atts['default_lat'] = get_post_meta( $locations[0], 'location_lat', true ); 106 | } 107 | if ( empty( $_GET['default_lng'] ) ) { 108 | $atts['default_lng'] = get_post_meta( $locations[0], 'location_lng', true ); 109 | } 110 | if ( empty( $_GET['zoom_level'] ) ) { 111 | $atts['zoom_level'] = 15; 112 | } 113 | } 114 | 115 | // Default Options 116 | $defaults = $simple_map->get_options(); 117 | 118 | // Overwrite defaults with any vars passed in 119 | $merged_atts = wp_parse_args( $atts, $defaults ); 120 | 121 | // Kick back to property 122 | $this->map_atts = $merged_atts; 123 | 124 | } 125 | 126 | /** 127 | * Adds a location to the map 128 | * 129 | * @since 2.4 130 | */ 131 | function add_location( $location ) { 132 | 133 | // $location can be a post object or a post ID. If its an object, grab the id 134 | if ( is_object( $location ) ) { 135 | $location = $location->ID; 136 | } 137 | 138 | // Build array of important post data 139 | if ( $location_data = get_metadata( 'post', $location ) ) { 140 | $location_array = array( 141 | 'id' => $location, 142 | 'lat' => ! empty( $location_data['location_lat'][0] ) ? $location_data['location_lat'][0] : false, 143 | 'lng' => ! empty( $location_data['location_lng'][0] ) ? $location_data['location_lng'][0] : false 144 | ); 145 | 146 | if ( $location_array['lat'] && $location_array['lng'] ) { 147 | $this->locations[ $location ] = $location_array; 148 | } 149 | } 150 | 151 | } 152 | 153 | /** 154 | * A wrapper for add_location for use when loading an iframe 155 | * 156 | * @since 2.4 157 | */ 158 | function add_iframe_locations() { 159 | 160 | // Add locations from GET string in iframe embed 161 | $locations = ! empty ( $_GET['location_ids'] ) ? explode( ',', $_GET['location_ids'] ) : array(); 162 | foreach ( $locations as $location ) { 163 | $this->add_location( $location ); 164 | } 165 | 166 | } 167 | 168 | /** 169 | * Returns the map code 170 | * 171 | * @since 2.4 172 | */ 173 | function get_map() { 174 | 175 | } 176 | 177 | /** 178 | * Returns the link for the iframe embed 179 | * 180 | * @since 2.4 181 | */ 182 | function get_iframe_embed() { 183 | 184 | $atts = $this->map_atts; 185 | $locations = array_keys( $this->locations ); 186 | 187 | $iframe = ''; 188 | 189 | return $iframe; 190 | 191 | } 192 | 193 | /** 194 | * Generates the actual iframe 195 | * 196 | * @since 1.0 197 | */ 198 | function generate_iframe() { 199 | 200 | if ( ! empty( $_GET['sm_map_iframe'] ) ) { 201 | global $simple_map; 202 | $this->set_map_atts(); 203 | $atts = $this->map_atts; 204 | 205 | wp_enqueue_script( 'jquery' ); 206 | ?> 207 | 208 | 209 | 210 | 217 | 218 | 219 | 220 | 282 | 283 |
284 | 285 | 286 | 287 | false, 17 | 'lng' => false, 18 | 'radius' => false, 19 | 'namequery' => false, 20 | 'query_type' => 'distance', 21 | 'locname' => false, 22 | 'address' => false, 23 | 'city' => false, 24 | 'state' => false, 25 | 'zip' => false, 26 | 'onlyzip' => false, 27 | 'country' => false, 28 | 'limit' => false, 29 | 'pid' => 0, 30 | ); 31 | $input = array_filter( array_intersect_key( $_GET, $defaults ) ) + $defaults; 32 | 33 | $smtaxes = array(); 34 | if ( $taxonomies = get_object_taxonomies( 'sm-location' ) ) { 35 | foreach ( $taxonomies as $key => $tax ) { 36 | $phpsafe = str_replace( '-', '_', $tax ); 37 | $_GET += array( $phpsafe => '' ); 38 | $smtaxes[ $tax ] = $_GET[ $phpsafe ]; 39 | } 40 | } 41 | 42 | // Define my empty strings 43 | $additional_select = $having = $distance_order = ''; 44 | 45 | // We're going to do a hard limit to 5000 for now. 46 | if ( ! $input['limit'] || $input['limit'] > 250 ) { 47 | $limit = "LIMIT 250"; 48 | } else { 49 | $limit = 'LIMIT ' . absint( $input['limit'] ); 50 | } 51 | 52 | $limit = apply_filters( 'sm-xml-search-limit', $limit ); 53 | 54 | // Locations within specific distance or just get them all? 55 | $additional_select = $wpdb->prepare( "( 3959 * ACOS( COS( RADIANS(%s) ) * COS( RADIANS( lat_tbl.meta_value ) ) * COS( RADIANS( lng_tbl.meta_value ) - RADIANS(%s) ) + SIN( RADIANS(%s) ) * SIN( RADIANS( lat_tbl.meta_value ) ) ) ) AS distance", $input['lat'], $input['lng'], $input['lat'] ) . ', '; 56 | $distance_order = 'distance, '; 57 | 58 | if ( $input['radius'] ) { 59 | $input['radius'] = ( $input['radius'] < 1 ) ? 1 : $input['radius']; 60 | $having = $wpdb->prepare( "HAVING distance < %d", $input['radius'] ); 61 | } 62 | 63 | $i = 1; 64 | $taxonomy_join = ''; 65 | foreach ( array_filter( $smtaxes ) as $taxonomy => $tax_value ) { 66 | $term_ids = explode( ',', $tax_value ); 67 | if ( $term_ids[0] == 'OR' ) { 68 | unset( $term_ids[0] ); 69 | if ( empty( $term_ids ) ) { 70 | continue; 71 | } 72 | $search_values = array( "IN (" . vsprintf( '%d' . str_repeat( ',%d', count( $term_ids ) - 1 ), $term_ids ) . ")" ); 73 | } else { 74 | $search_values = array(); 75 | foreach ( $term_ids as $term_id ) { 76 | $search_values[] = sprintf( '= %d', $term_id ); 77 | } 78 | } 79 | foreach ( $search_values as $search_value ) { 80 | $taxonomy_join .= " 81 | INNER JOIN 82 | $wpdb->term_relationships AS term_rel_$i ON posts.ID = term_rel_$i.object_id 83 | INNER JOIN 84 | $wpdb->term_taxonomy AS tax_$i ON 85 | term_rel_$i.term_taxonomy_id = tax_$i.term_taxonomy_id 86 | AND tax_$i.taxonomy = '$taxonomy' 87 | AND tax_$i.term_id $search_value 88 | "; 89 | $i ++; 90 | } 91 | } 92 | 93 | // Locations by name or category name or tag name 94 | $input['locname'] = trim( $input['locname'] ); 95 | if ( ! empty( $input['locname'] ) ) { 96 | $sql_locname_having = $wpdb->prepare( "LOWER( posts.post_title ) LIKE '%s'", '%' . strtolower( $input['locname'] ) . '%' ); 97 | 98 | $sm_terms_by_name = array(); 99 | foreach ( $smtaxes as $smtax => $ids ) { 100 | $sm_terms = get_terms( array( 101 | 'taxonomy' => $smtax, 102 | 'fields' => 'id=>name', 103 | 'name' => $input['locname'], 104 | ) ); 105 | if ( ! empty( $sm_terms ) ) { 106 | $sm_terms_by_name[ $smtax ] = implode( ',', array_map( 'intval', array_keys( $sm_terms ) ) ); 107 | $smtax_slug = str_replace( 'sm-', '', $smtax ); 108 | $taxonomy_join .= " 109 | INNER JOIN 110 | $wpdb->term_relationships AS term_rel_$smtax_slug ON posts.ID = term_rel_$smtax_slug.object_id 111 | INNER JOIN 112 | $wpdb->term_taxonomy AS tax_$smtax_slug ON 113 | term_rel_$smtax_slug.term_taxonomy_id = tax_$smtax_slug.term_taxonomy_id 114 | AND tax_$smtax_slug.taxonomy = '$smtax' 115 | AND tax_$smtax_slug.term_id IN ( {$sm_terms_by_name[ $smtax ]} ) 116 | "; 117 | 118 | $additional_select .= "tax_$smtax_slug.term_id as {$smtax_slug}_term_id, "; 119 | $sql_locname_having .= $wpdb->prepare( " OR {$smtax_slug}_term_id IN ( %s ) ", $sm_terms_by_name[ $smtax ] ); 120 | } 121 | } 122 | 123 | if ( ! empty( $having ) ) { 124 | $having .= " AND ( " . $sql_locname_having . " )"; 125 | } else { 126 | $having = "HAVING " . $sql_locname_having; 127 | } 128 | } 129 | 130 | // Compatibility with WPML 131 | $wpml_join = ""; 132 | if ( defined( 'ICL_SITEPRESS_VERSION' ) ) { 133 | global $sitepress; 134 | 135 | if ( isset( $_GET['wpml'] ) ) { 136 | $wpml_sm_lang = $_GET['wpml']; 137 | } 138 | 139 | if ( isset( $_GET['lang'] ) ) { 140 | $wpml_sm_lang = $_GET['lang']; 141 | } 142 | 143 | if ( isset( $wpml_sm_lang ) ) { 144 | $sitepress->switch_lang( $wpml_sm_lang ); 145 | } 146 | $wpml_join = "INNER JOIN " . $wpdb->prefix . "icl_translations t ON posts.ID = t.element_id AND t.element_type = 'post_sm-location' AND t.language_code = '" . $sitepress->get_current_language() . "'"; 147 | } 148 | 149 | $sql = "SELECT 150 | lat_tbl.meta_value AS lat, 151 | lng_tbl.meta_value AS lng, 152 | $additional_select 153 | posts.ID, 154 | posts.post_content, 155 | posts.post_title 156 | FROM 157 | $wpdb->posts AS posts 158 | $wpml_join 159 | INNER JOIN 160 | $wpdb->postmeta lat_tbl ON lat_tbl.post_id = posts.ID AND lat_tbl.meta_key = 'location_lat' 161 | INNER JOIN 162 | $wpdb->postmeta lng_tbl ON lng_tbl.post_id = posts.ID AND lng_tbl.meta_key = 'location_lng' 163 | $taxonomy_join 164 | WHERE 165 | posts.post_type = 'sm-location' 166 | AND posts.post_status = 'publish' 167 | GROUP BY 168 | posts.ID 169 | $having 170 | ORDER BY " . apply_filters( 'sm-location-sort-order', $distance_order . ' posts.post_name ASC', $input ) . " " . $limit; 171 | 172 | $sql = apply_filters( 'sm-xml-search-locations-sql', $sql ); 173 | 174 | // TODO: Consider using this to generate the marker node attributes in print_xml(). 175 | $location_fields = array( 176 | 'location_address' => 'address', 177 | 'location_address2' => 'address2', 178 | 'location_city' => 'city', 179 | 'location_state' => 'state', 180 | 'location_zip' => 'zip', 181 | 'location_country' => 'country', 182 | 'location_phone' => 'phone', 183 | 'location_fax' => 'fax', 184 | 'location_email' => 'email', 185 | 'location_url' => 'url', 186 | 'location_special' => 'special', 187 | ); 188 | 189 | $location_field_map = apply_filters( 'sm_location_fields', $location_fields ); 190 | 191 | $options = $simple_map->get_options(); 192 | $show_permalink = ! empty( $options['enable_permalinks'] ); 193 | 194 | if ( $locations = $wpdb->get_results( $sql ) ) { 195 | // Start looping through all locations i found in the radius 196 | foreach ( $locations as $key => $value ) { 197 | // Add postmeta data to location 198 | $custom_fields = get_post_custom( $value->ID ); 199 | foreach ( $location_field_map as $key => $field ) { 200 | if ( isset( $custom_fields[ $key ][0] ) ) { 201 | $value->$field = $custom_fields[ $key ][0]; 202 | } else { 203 | $value->$field = ''; 204 | } 205 | } 206 | 207 | $value->postid = $value->ID; 208 | $value->name = apply_filters( 'the_title', $value->post_title ); 209 | 210 | $the_content = trim( $value->post_content ); 211 | if ( ! empty( $the_content ) ) { 212 | $the_content = apply_filters( 'the_content', $the_content ); 213 | } 214 | $value->description = $the_content; 215 | 216 | $value->permalink = ''; 217 | if ( $show_permalink ) { 218 | $value->permalink = get_permalink( $value->ID ); 219 | $value->permalink = apply_filters( 'the_permalink', $value->permalink ); 220 | } 221 | 222 | // List all terms for all taxonomies for this post 223 | $value->taxes = array(); 224 | foreach ( $smtaxes as $taxonomy => $tax_value ) { 225 | $phpsafe_tax = str_replace( '-', '_', $taxonomy ); 226 | $local_tax_names = ''; 227 | 228 | // Get all taxes for this post 229 | if ( $local_taxes = wp_get_object_terms( $value->ID, $taxonomy, array( 'fields' => 'names' ) ) ) { 230 | $local_tax_names = implode( ', ', $local_taxes ); 231 | } 232 | 233 | $value->taxes[ $phpsafe_tax ] = $local_tax_names; 234 | } 235 | } 236 | } else { 237 | // Print empty XML 238 | $locations = array(); 239 | } 240 | 241 | $locations = apply_filters( 'sm-xml-search-locations', $locations ); 242 | $this->print_json( $locations, $smtaxes ); 243 | } 244 | } 245 | 246 | // Prints the JSON output 247 | function print_json( $dataset, $smtaxes ) { 248 | header( 'Status: 200 OK', false, 200 ); 249 | header( 'Content-type: application/json' ); 250 | do_action( 'sm-xml-search-headers' ); 251 | 252 | do_action( 'sm-print-json', $dataset, $smtaxes ); 253 | 254 | echo json_encode( $dataset ); 255 | die(); 256 | } 257 | } 258 | } 259 | -------------------------------------------------------------------------------- /classes/shortcodes.php: -------------------------------------------------------------------------------- 1 | shortcode_tags = $this->get_shortcode_tags(); 35 | 36 | // Register shortcodes with WordPress 37 | add_action( 'init', array( &$this, 'register_shortcodes' ) ); 38 | 39 | } 40 | 41 | /** 42 | * This method loops through all my location shortcodes and registers them. 43 | * 44 | * All shortcode tags actually use the same callback method 45 | * 46 | * @since 2.4 47 | */ 48 | function register_shortcodes() { 49 | 50 | // Register 51 | add_shortcode( 'sm-location', array( &$this, 'do_shortcode' ) ); 52 | 53 | } 54 | 55 | /** 56 | * Builds the array of tags used for location shortcodes 57 | * 58 | * @since 2.4 59 | */ 60 | function get_shortcode_tags() { 61 | 62 | $shortcode_tags = array( 63 | 'address', 64 | 'city', 65 | 'state', 66 | 'zip', 67 | 'country', 68 | 'phone', 69 | 'fax', 70 | 'email', 71 | 'url', 72 | ); 73 | 74 | return apply_filters( 'sm-location-shortcode-tag-array', 75 | $shortcode_tags ); 76 | } 77 | 78 | /** 79 | * Responsible for returning a location address 80 | * 81 | * @since 2.4 82 | */ 83 | function do_shortcode( $args ) { 84 | 85 | global $post, $simple_map; 86 | $options = $simple_map->get_options(); 87 | 88 | // Default args for map itself, not for locations on map 89 | $map_defaults = array( 90 | 'data' => '', 91 | 'before' => '', 92 | 'after' => '', 93 | 'default_lat' => get_post_meta( $post->ID, 'location_lat', 94 | true ), 95 | 'default_lng' => get_post_meta( $post->ID, 'location_lng', 96 | true ), 97 | 'panControl' => false, 98 | 'zoomContorl' => false, 99 | 'scaleControl' => false, 100 | 'streetViewControl' => false, 101 | 'mapTypeContorl' => false, 102 | 'mapTypeId' => 'google.maps.MapTypeId.ROADMAP', 103 | 'format' => 'csv', 104 | ); 105 | 106 | $atts = shortcode_atts( $map_defaults, $args ); 107 | 108 | // If the requested data is description, return the post content 109 | if ( 'description' == $atts['data'] ) { 110 | return $post->post_content; 111 | } 112 | 113 | // If we're looking for the full address, compose that from the options 114 | if ( 'full-address' == $atts['data'] ) { 115 | $postmeta = get_metadata( 'post', $post->ID ); 116 | $address_format = $options['address_format']; 117 | 118 | switch ( $address_format ) { 119 | case 'town province postalcode' : 120 | $full_address = $postmeta['location_address'][0] . ' ' 121 | . $postmeta['location_address2'][0] 122 | . ' ' . $postmeta['location_city'][0] 123 | . $postmeta['location_state'][0] . ' ' 124 | . $postmeta['location_zip'][0]; 125 | break; 126 | 127 | case 'town-province postalcode' : 128 | $full_address = $postmeta['location_address'][0] . ' ' 129 | . $postmeta['location_address2'][0] 130 | . ' ' . $postmeta['location_city'][0] 131 | . '-' . $postmeta['location_state'][0] 132 | . ' ' . $postmeta['location_zip'][0]; 133 | break; 134 | 135 | case 'postalcode town-province' : 136 | $full_address = $postmeta['location_address'][0] . ' ' 137 | . $postmeta['location_address2'][0] 138 | . ' ' . $postmeta['location_zip'][0] 139 | . ' ' . $postmeta['location_city'][0] 140 | . '-' . $postmeta['location_state'][0]; 141 | break; 142 | 143 | case 'postalcode town, province' : 144 | $full_address = $postmeta['location_address'][0] . ' ' 145 | . $postmeta['location_address2'][0] 146 | . ' ' . $postmeta['location_zip'][0] 147 | . ' ' . $postmeta['location_city'][0] 148 | . ', ' . $postmeta['location_state'][0]; 149 | break; 150 | 151 | case 'postalcode town' : 152 | $full_address = $postmeta['location_address'][0] . ' ' 153 | . $postmeta['location_address2'][0] 154 | . ' ' . $postmeta['location_zip'][0] 155 | . ' ' . $postmeta['location_city'][0]; 156 | break; 157 | 158 | case 'town postalcode' : 159 | $full_address = $postmeta['location_address'][0] . ' ' 160 | . $postmeta['location_address2'][0] 161 | . ' ' . $postmeta['location_city'][0] 162 | . ' ' . $postmeta['location_zip'][0]; 163 | break; 164 | 165 | case 'town, province postalcode' : 166 | default : 167 | $full_address = $postmeta['location_address'][0] . ' ' 168 | . $postmeta['location_address2'][0] 169 | . ' ' . $postmeta['location_city'][0] 170 | . ', ' . $postmeta['location_state'][0] 171 | . ' ' . $postmeta['location_zip'][0]; 172 | break; 173 | 174 | } 175 | 176 | return $full_address; 177 | } 178 | 179 | // if the requested data is 'directions' return the link to google maps. 180 | if ( 'directions' == $atts['data'] ) { 181 | return $this->get_directions_link( $post->ID ); 182 | } 183 | 184 | // if the requested data is a map, return the map. 185 | if ( 'iframe-map' == $atts['data'] ) { 186 | 187 | // Args we need to make the map itself - not the locations on the map. 188 | $build_att_array = array( 189 | 'panControl', 190 | 'default_lat', 191 | 'default_lng', 192 | 'zoomControl', 193 | 'scaleControl', 194 | 'streetViewControl', 195 | 'mapTypeControl', 196 | 'mapType', 197 | ); 198 | 199 | // Use the values from $atts[] to popular $r[] 200 | foreach ( $build_att_array as $item ) { 201 | if ( isset( $atts[ $item ] ) ) { 202 | $r[ $item ] = $atts[ $item ]; 203 | } else { 204 | $r[ $item ] = ''; 205 | } 206 | } 207 | 208 | // Determine location IDs 209 | $location_ids = empty( $args['location_ids'] ) 210 | ? array( $post->ID ) 211 | : explode( ',', $args['location_ids'] ); 212 | 213 | // Init the object and return the iframe source 214 | $map = new SM_Map_Factory(); 215 | $map->set_map_atts( $r ); 216 | 217 | // Add Locations 218 | foreach ( $location_ids as $location_id ) { 219 | $map->add_location( $location_id ); 220 | } 221 | 222 | return $map->get_iframe_embed(); 223 | 224 | } 225 | 226 | // If the requested data is a taxonomy 227 | $sm_taxes = $simple_map->get_sm_taxonomies( 'array', '', true, 228 | 'objects' ) ? $simple_map->get_sm_taxonomies( 'array', '', true, 229 | 'objects' ) : array(); 230 | 231 | foreach ( $sm_taxes as $taxonomy ) { 232 | if ( $taxonomy->name == $atts['data'] ) { 233 | // Forward compatible format types 234 | $tax_format = ( in_array( $atts['format'], 235 | array( 'csv' ) ) ) ? $atts['format'] : 'csv'; 236 | if ( $terms = wp_get_object_terms( $post->ID, 237 | $taxonomy->query_var ) 238 | ) { 239 | foreach ( $terms as $termk => $termv ) { 240 | $term_names[] = $termv->name; 241 | } 242 | 243 | } else { 244 | $term_names = array(); 245 | } 246 | 247 | // Forward compatible format types 248 | switch ( $tax_format ) { 249 | case 'csv': 250 | default: 251 | return ! empty( $term_names ) ? $args['before'] 252 | . implode( ', ', 253 | $term_names ) . $args['after'] : ''; 254 | break; 255 | } 256 | } 257 | } 258 | 259 | // Look for postmeta with location_ prepended to it 260 | if ( $value = get_post_meta( absint( $post->ID ), 261 | 'location_' . $atts['data'], true ) 262 | ) { 263 | return str_replace( '%self%', $value, 264 | $atts['before'] . $value . $atts['after'] ); 265 | } 266 | 267 | // Look for postmeta of another type 268 | if ( $value = get_post_meta( absint( $post->ID ), $atts['data'], 269 | true ) 270 | ) { 271 | return str_replace( '%self%', $value, 272 | $atts['before'] . $value . $atts['after'] ); 273 | } 274 | 275 | return false; 276 | } 277 | 278 | /** 279 | * Returns a directions link 280 | * 281 | * @since 2.4 282 | */ 283 | function get_directions_link( $post ) { 284 | global $simple_map; 285 | 286 | $options = $simple_map->get_options(); 287 | $address = $directions_url = ''; 288 | 289 | if ( $pm = get_metadata( 'post', $post ) ) { 290 | 291 | $address .= empty( $pm['location_address'][0] ) ? '' 292 | : $pm['location_address'][0]; 293 | $address .= empty( $pm['location_city'][0] ) ? '' 294 | : ' ' . $pm['location_city'][0]; 295 | $address .= empty( $pm['location_state'][0] ) ? '' 296 | : ' ' . $pm['location_state'][0]; 297 | $address .= empty( $pm['location_zip'][0] ) ? '' 298 | : ' ' . $pm['location_zip'][0]; 299 | $address .= empty( $pm['location_country'][0] ) ? '' 300 | : ' ' . $pm['location_country'][0]; 301 | 302 | $directions_url = 'http://google' . $options['default_domain'] 303 | . '/maps?saddr=&daddr=' 304 | . urlencode( $address ); 305 | 306 | } 307 | 308 | return $directions_url; 309 | 310 | } 311 | 312 | } 313 | 314 | } 315 | -------------------------------------------------------------------------------- /classes/help.php: -------------------------------------------------------------------------------- 1 | get_options(); 14 | 15 | extract( $options ); 16 | 17 | ?> 18 |
19 | 20 | show_toolbar( $sm_page_title ); 26 | ?> 27 | 28 |

| |

29 | 30 |
31 | 32 |
33 | 34 |
35 | 36 |
37 | 38 | 41 | 42 | 43 | 44 |
45 | 46 |

47 | 48 |
49 | 50 |
51 | 52 | 53 | 54 | 55 | 58 | 59 | 60 | 61 | 64 | 65 | 66 | 67 | 70 | 71 | 72 | 73 | 75 | 76 | 77 | 78 | 80 | 81 | 82 | 83 | 86 | 87 | 88 | 89 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 |
56 | [simplemap] 57 |
62 | [simplemap categories=2,5,14 tags=3,6,15] 63 |
68 | [simplemap show_categories_filter=false show_tags_filter=false] 69 |
74 | [simplemap hide_map=true]
79 | [simplemap hide_list=true]
84 | [simplemap default_lat='34.1346702' default_lng='-118.4389877'] 85 |
90 | [simplemap categories=2,5,14 show_tags_filter=false]
', '' ); ?>
102 | 103 |
104 | 105 |
106 | 107 |
108 | 109 |
110 | 111 | 114 | 115 | 116 | 117 |
118 | 119 |

120 | 121 |
122 | 123 |
124 | 125 | 126 | 127 | 128 | 131 | 132 | 133 | 134 | 135 | 138 | 148 | 149 | 150 | 151 | 154 | 155 | 156 | 157 |
129 | 130 |
136 | 137 | 139 | ', '' ); ?> 140 |
141 | ', '' ); ?> 142 |
143 | ', '', '', '' ); ?> 144 |

145 | 146 | 147 |
152 | 153 |
158 | 159 |
160 | 161 |
162 | 163 |
164 | 165 |
166 | 167 | 170 | 171 | 172 | 173 |
174 | 175 |

176 | 177 |
178 | 179 |
180 | 181 | 182 | 183 | 184 | 193 | 194 | 195 | 196 | 199 | 200 | 201 |
185 | 186 |
187 |
    188 |
  1. 189 |
  2. 190 |
191 | 192 |
197 | 198 |
202 |
203 | 204 |
205 | 206 |
207 |
208 | 209 | 210 | 213 | 214 |
215 | 216 |
217 | 218 |
219 | 220 |
221 | 222 | 223 | 224 | 225 | 226 |
227 | 228 |

229 | 230 |
231 | 232 | 237 | 238 |

Premium support is no longer available for SimpleMap.

239 | 240 | 241 | 242 |

%s.", date( "F d, Y", get_ftps_exp_date( $simplemap_ps ) ) ); ?>

243 | 244 |

245 | 246 | 247 | 248 |
249 | 250 |
251 | 252 | 253 | 254 |
255 | 256 |
257 | 258 |
259 | 260 |
261 | 262 |
263 | 264 |
265 | 266 | 271 | -------------------------------------------------------------------------------- /classes/widgets.php: -------------------------------------------------------------------------------- 1 | 'sm_search_widget', 27 | 'description' => __( 'Adds a customizable search widget to your site' ), 28 | ); 29 | parent::__construct( 'sm_search_widget', 'SimpleMap ' . __( 'Search' ), $widget_ops ); 30 | } 31 | 32 | /** 33 | * Build the widget. 34 | * 35 | * @param array $args widget comments 36 | * @param array $instance actual instance of the widget 37 | */ 38 | public function widget( $args, $instance ) { 39 | global $simple_map, $wp_rewrite; 40 | 41 | extract( $args ); 42 | 43 | $options = $simple_map->get_options(); 44 | 45 | $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'] ); 46 | 47 | // Ensures Variables are always Defined 48 | $instance = $this->set_instance( $instance ); 49 | /* 50 | * Most of these variables could be reduced, and use the instance 51 | * array instead. 52 | * 53 | * Same with $this->form method. 54 | */ 55 | // Search Form Options. 56 | $show_name = $instance['show_name']; 57 | $show_address = $instance['show_address']; 58 | $show_city = $instance['show_city']; 59 | $show_state = $instance['show_state']; 60 | $show_zip = $instance['show_zip']; 61 | $show_distance = $instance['show_distance']; 62 | 63 | $default_lat = $instance['default_lat']; 64 | $default_lng = $instance['default_lng']; 65 | $simplemap_page = $instance['simplemap_page']; 66 | 67 | // Set taxonomies to available equivalents. 68 | $show = array(); 69 | $terms = array(); 70 | foreach ( $options['taxonomies'] as $taxonomy => $tax_info ) { 71 | $key = strtolower( $tax_info['plural'] ); 72 | $show[ $taxonomy ] = ! empty( $instance[ 'show_' . $key ] ) ? 1 : 0; 73 | $terms[ $taxonomy ] = ! empty( $instance[ $key ] ) ? $instance[ $key ] : ''; 74 | } 75 | 76 | $available = $terms; 77 | 78 | //TODO update this to modern Widget API code. 79 | echo $before_widget; 80 | if ( $title ) { 81 | echo '' . $before_title . $title . $after_title . ''; // XSS ok. 82 | } 83 | 84 | // Form Field Values. 85 | $name_value = isset( $_REQUEST['location_search_name'] ) ? $_REQUEST['location_search_name'] : ''; 86 | $address_value = isset( $_REQUEST['location_search_address'] ) ? $_REQUEST['location_search_address'] : ''; 87 | $city_value = isset( $_REQUEST['location_search_city'] ) ? $_REQUEST['location_search_city'] : ''; 88 | $state_value = isset( $_REQUEST['location_search_state'] ) ? $_REQUEST['location_search_state'] : ''; 89 | $zip_value = isset( $_REQUEST['location_search_zip'] ) ? $_REQUEST['location_search_zip'] : ''; 90 | $radius_value = isset( $_REQUEST['location_search_distance'] ) ? $_REQUEST['location_search_distance'] : $options['default_radius']; 91 | $limit_value = isset( $_REQUEST['location_search_limit'] ) ? $_REQUEST['location_search_limit'] : $options['results_limit']; 92 | 93 | // Set action based on permalink structure. 94 | if ( ! $wp_rewrite->permalink_structure ) { 95 | $method = 'get'; 96 | $action = site_url(); 97 | } else { 98 | $method = 'post'; 99 | $action = get_permalink( absint( $simplemap_page ) ); 100 | } 101 | 102 | $location_search = ''; // Close map_search div. 199 | 200 | echo $location_search; 201 | 202 | echo $after_widget; 203 | } 204 | 205 | /** 206 | * 207 | * Save settings in backend. 208 | * 209 | * @param array $new_instance 210 | * @param array $old_instance 211 | * 212 | * @return array 213 | */ 214 | public function update( $new_instance, $old_instance ) { 215 | $instance = $this->set_instance( $old_instance ); 216 | $instance = $this->set_instance( $new_instance, $instance ); 217 | 218 | return $instance; 219 | } 220 | 221 | /** 222 | * Defaults 223 | * 224 | * @param array $instance 225 | * 226 | * @return string|void 227 | */ 228 | public function form( $instance ) { 229 | $instance = $this->set_instance( $instance ); 230 | 231 | $title = esc_attr( $instance['title'] ); 232 | $show_name = $instance['show_name']; 233 | $show_address = $instance['show_address']; 234 | $show_city = $instance['show_city']; 235 | $show_state = $instance['show_state']; 236 | $show_zip = $instance['show_zip']; 237 | $show_distance = $instance['show_distance']; 238 | $default_lat = ! empty( $instance['default_lat'] ) ? esc_attr( $instance['default_lat'] ) : 0; 239 | $default_lng = ! empty( $instance['default_lng'] ) ? esc_attr( $instance['default_lng'] ) : 0; 240 | $simplemap_page = $instance['simplemap_page']; 241 | ?> 242 | 243 |

244 | 246 |

247 | 248 |

/> 250 |
252 | 253 | /> 255 |
257 | 258 | /> 260 |
262 | 263 | /> 265 |
267 | 268 | /> 270 |
272 | 273 | /> 275 |
277 | 278 | get_options(); 281 | foreach ( $options['taxonomies'] as $taxonomy => $tax_info ) { 282 | $key = strtolower( $tax_info['plural'] ); 283 | $show_field = 'show_' . $key; 284 | $show = isset( $instance[ $show_field ] ) ? (bool) $instance[ $show_field ] : false; 285 | ?> 286 | /> 288 | 290 |
291 | 292 | 296 | *

297 | *

298 | * 304 | *

305 | * 306 | *

307 | *

308 | */ 309 | ?> 310 |

312 |

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 ) . '
'; 191 | } 192 | 193 | function renew_soon() { 194 | $link = $this->paypal_button ? esc_url( $this->paypal_button ) : 'http://simplemap-plugin.com'; 195 | echo "
" . 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 | . --------------------------------------------------------------------------------